[ANN] SafeClient JS Client Library

Yet another client library, this time in JS. I need it for an app I’m working on. The repo is at GitHub - cretz/safeclient.js: JS Client to the SAFE Launcher API. This is an early preview (I have not even published to npm yet). Feel free to peek.

Seems most people are just developing API clients so far which is a needed building block but hopefully we can spread into more apps in the near future. Although I have one or two I am working on, my real apps can’t get going until three more rfcs are implemented.

Questions/feedback welcome.

16 Likes

hmmm - ok - ignorant as i am i just followed your instructions :smiley:

git clone GitHub - cretz/safeclient.js: JS Client to the SAFE Launcher API
cd safeclient.js
npm install
npm run compile

and then

node ./examples/js/simple_read_write.js

this resulted in:

[…]safeclient.js/examples/js/simple_read_write.js:3
const safe = require(‘…/…/lib/src/index’)
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions…js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3

sorry that i didn’t even get further than the second line of code xD … i don’t know anything about JS so …

What version of nodejs are you using?

v0.10.25 …

Way old. Please upgrade.

1 Like

oh - ok! …

edit: uhm - i have to leave now - sorry - i’ll try it later again with a newer version of nodejs! thx!

Many thanks! Can’t wait to dig into this.

Thanks @cretz you are very much appreciated :slight_smile:

1 Like

Man that @cretz amazing effort.- outstanding

1 Like

=) okay yes - v5.9 seems to be slightly ahead of v0.10 :smiley:
funny it worked with the maidsafe-demo-app =)

very very cool @cretz !!!

1 Like

Okay so this is built in node.js then? Is anyone else finding the amount of information they need to learn kind of overwhelming?

Yeah for sure, last year I spend a few months reading up on different technologies/languages nodejs/javascript, python,java. Eventually I found a good advise from an old programmer online. He/she basically said, pick one language,platform and slowly build experience around it over a period of months, years.

It will eventually make learning something else easier and quicker as you have deep programming experience built. So choose one, maybe something that you can use elsewhere e.g. scripting at work.

1 Like

Nice job @cretz. Was just building out a low-level api myself in vanilla javascript (not TypeScript), as I needed it for my separate high-level api I posted previously. I’ll see if I should use this or just complete the one I started, as I’m not far from finishing.

Send me a DM if you ever want to work together on something! :slight_smile:

oooooh publishing this library was evil of you! … i just played with it for an hour to understand how nodejs/js works and how i can use it instead of working on my thesis -.-" …

works like a charm - thank you very much

2 Likes

Published to NPM at safeclient - npm and added integration tests (here and in the Go client) for DNS also which means it has decent coverage.

5 Likes

@cretz, thank you very much for your work! I have been playing around with the library and successfully ran the test application against the safe launcher. I’m pretty new to javascript, and before going through this project was the first time I have ran into ‘arrow functions’ and am having some difficulty in understanding the underscore. From your example you show some code that looks like this, promise.then(_ => {}). Could you or anyone else explain what the underscore means?

1 Like

The underscore is not necessarily defined in the ES6 arrow function spec or anything, it’s just convention for “I know there’s a parameter here and I don’t care about it”. In many cases I could use an empty parameter set. I do them by convention from my FP/ML days.

playing around with this and so far liking it a lot. Thanks for putting it together for us that are just learning some new languages. Its a huge help. I do have one question though, why dont these files show up under the “private files” in the demo app? Now can I put files in a folder called “private” because it doesn’t exist until I create it. I would just like to have some continuity between the two and I’m not sure what I’m missing.

edit: Or is every app segmented into their own “partition” if you will? In which case, can I grant access?

1 Like

The demo app only has files that it has created itself. Maidsafe explicitly chose the design to have non-shared (not to be confused with “private”) files be app-specific. You can spoof yourself as the demo app (same ID, vendor, etc) and you’ll see them. I have asked them below to change how they were doing it w/ the /public stuff:

But it has unfortunately gone unresponded-to. You should be able to use “shared” files to see files across apps, but the demo app does not do this. Unfortunately the differences between public, private, shared, and non-shared are woefully underdocumented.

2 Likes

So does the MEAN stack (MongoDB, Express.js, AngularJS, Node.js) work on the Safe Network?