Baby Dev Questions

Makes sense, I think there’s many in that boat :stuck_out_tongue:

Everything seems to change so much from one week to the next.

1 Like

@joshuef or anyone else who knows safe-js,

is this still correct, from github?:

In general, is safe-js / SAFE API becoming pretty stable? or are big changes expected in the near future?

Sounds like the Launcher → Authenticator changes could have a big impact on safe-js

As it stands, it’s reasonably stable.

Any launcher/auth changes will of course have an impact, but that’ll be dealt with as that rolls around.

Everything in safe-js has been tested, so that statement is indeed a bit old.

Still though, I’d call it beta until I’ve gotten a much higher level of test coverage and improved the error handling further.

2 Likes

It is very stable and while the changes in the new launcher infrastructure will cause some changes, we’d like to keep the NFS-API of safe-js (from within the browser) very close to what it is now. However, we will very likely restructure the way Low-Level is handled as handing out handlerIds across processes turned out to be a bad idea. So we’ll have to reconsider this part of the API. However, we might be providing a compatibility layer that still acts as the old API while internally using the new safer way of doing things…

3 Likes

I mostly use safe-js,

if you have a second could you give me a little summary of what people would use the low-level API for?

Is it basically the same thing, but for desktop software / apps instead of web apps?

Safe-js also exposes the low-level-api and as said before, we are intending on keeping most things backwards compatible in that area, too.

The low level API gives you more direct access to the network and its resources and it is available for desktop as well as a web apps.

In particular this allows you to have much more fine grained control which kind of Data-Type certain things are stored in - ImmutableData, StructuredData or AppendableData. Thus for example what we are doing in the comments-tutorial requires features of the AppendableData that you can’t access with the NFS emulation, therefore it needs access to the Low-Level-API.

As mentioned in the Auth-RFC, we are intending on merging more of those features directly into the API and offer emulations like NFS on top for convenience, but with handing out App-Keys in the future, there is no preventing anyone from doing low-level-operations anymore anyways, so we decided to embrace it instead.

1 Like

Hey @WhiteOutMashups, I was checking that this morning and I can’t make SafeEditor work on Safe browser because the vendor field is automatically filled by the browser based on the url of the webpage making the request. So there’s no way to impersonate another app.

If I understand correctly the new permission scheme will allow apps to request access to other app’s directories so theoretically we wouldn’t have to impersonate another app for SafeEditor to work so that would be a good news. But it also depends what is the plan for the Safe browser and if they will allow web apps to access to the whole low-level api or just a subset of it. Maybe @joshuef can shed some light on what is the long term plan in term of cross app permission support.

Meanwhile, I wonder if it would be reasonable to allow web pages to fill the app field manually to allow SafeEditor to work. There isn’t many people using the safe browser and the risk of an app doing any harm due to this is rather low. So maybe it would be fine to change this temporarily until the new permission scheme is in place.

EDIT: I forgot, @WhiteOutMashups, I added directories example to safe://simplesafe2.davidmtl if that interest you. You can see the response inside the console.

1 Like

Great stuff! How about if you can make your own directories / files with safeditor so that you can edit those?

Hmm but then I guess you still need the demo app for DNS… Or not? :smiley:

On alpha you can add new files and directories but on Safe browser I would need to create a UI for it since for some reason it doesn’t support the Javascript prompt() function that I use. And as you suspect I would need to also add support for DNS if we want those files to be used for a web site. Also if I want to do things properly I would probably need to add a way to upload multiple files… So I’m basically rewriting the demo app which is not something I have much interest in doing.

So it’s gonna stay that way until the new scheme is implemented and also serve as a friendly reminder that life without cross app data sharing is a sadder one :wink:.

1 Like

Very interesting indeed! Used it and have a few questions,

  • Does it create those files in your /public folder, or anywhere visable besides the console? Looked for them in my demo app but nothing. Probably the permissions barrier eh?
  • Is the directory example just creating empty folders? And same ? as above, can I see them anywhere, demo app etc? Can I use it to create folders with files inside them? or only empty?
  • is this new simplesafe code anywhere? for this v2? I’ll check the orig github now…

just want to know more about how this works so I can put this into mine thanks very very much as always!

They are created within the simplesafe2 app folder, this is the reason why you can’t see them inside the demo app. The demo app only shows files and folder within the demo app folder. Each app has a different root folder, so that’s why SafeEditor needs to impersonate another app in order to access their data.

Yes, the folder created is empty. But then you can create a new file inside it by entering the name of the directory inside the file input box. For example:

  • Create a folder called “test”
  • Create a file called “test/myfile”

Then “myfile” will be located inside the new “test” folder you created.

Just uploaded them in a branch here.

Hope it helps.

1 Like

Great! Thanks for all that.

Another question, what did you use to display the pub/private folders, files, etc in your safeEditor app?

Is there something open source that displays files and folders on a web page?

Looking to embed something into the safe://learnsjs.wom site I’m making

I didn’t use any library, it’s just a bit of javascript and css. It’s this rather inelegant and bulky piece of code here that does it:

In short, here’s how it works:

  • First I get the content of the desired folder, this contains a list of files and directories (line 178-180)
  • Then the div container called subfolder_list will be filled with html links so I need to empty it first (line 183)
  • Then I add a “…/” link to go to the parent folder if we aren’t in the root folder( since there isn’t a parent folder…) (line 185)
  • Line 190-200 creates the “…/” html link and append it to the subfolder_list container (line 200)
  • Then I create another html link for each directory (line 203-229)
  • I do the same for each file (line 234-260)
  • When you press a file link its content is retrieved (line 245-248)
  • When you press a folder link its content is retrieved and the whole process restarts again (line 214-217)
  • The delete button are just normal html button with round corners and a red background.

And that’s it. It might look a bit daunting but it’s rather simple. Take it one piece at the time and feel free to ask if you need help.

4 Likes

Thanks very much for the great write up! That should be great I’m going through it with one of my SAFE-FS team members so that should be more than enough for us thanks very much! Will be great to have a tutorial site for everyone

1 Like

Hey guys me and my team are making some more safe-js examples, and have created this test site: safe://avash1.wom/

Do you guys know what’s best for filling out the Service area? Waiting to hear from them but time difference.

My ID is ‘wom’ so my safe links end up as safe://blahblah.wom/ but how should I fill in the blanks in that webpage? Thanks!

One more question, gonna tag a few people especially @joshuef but is there an option for deleting folders / files with safe-js? @ben @happybeing

See deleteFile / deleteDir in the docs:

2 Likes

I’m trying to use the low level api but run into some problems with structured data and appendable data when I want to save the data after authenticating my app and successfully creating a handleId: http://localhost:8100/structured-data/3 or http://localhost:8100/appendable-data/2 (PUT). I use the same data and settings as described in the API documentation and I also tried with a new account.

{
“errorCode”: -23,
“description”: “CoreError::MutationFailure::MutationError::DataExists”
}

I also tried the POST request and that result in:
{
“errorCode”: -25,
“description”: “CoreError::MutationFailure::MutationError::InvalidSuccessor”
}

I use the Windows launcher and I have the same problem with version 0.9.2 and 0.10.0. I tried in NodeJS and in Postman with the same result…any ideas?

1 Like

…update and read are now working, but saving appendable/structured data still gives the same error.

1 Like

Can you describe exactly the requests you are sending for the scenario failing?
Are you trying to create a new SD or updating an existing one?

2 Likes