Baby Dev Questions

I’m not at my laptop but two thoughts:

  • you are accessing a JS resource on a different domain which will I think be being blocked by the CSP. Try with a local copy of that jquery.min.js so you access it the same way as your own JS file.
  • did you look in the browser console (wich should tell you what the problem is)?

Do you mean the jQuery file? Because I copied it into a local js file for exactly that reason in the test above. This should be the case for all my js files, so I don’t know which one you mean

I mean this from your codepen:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js">

You are accessing a file at googleapis.com.

Yeah that doesn’t exist in the test version that’s hosted on SAFE for testing now in the example, it’s just so it can work with codepen for that part

@WhiteOutMashups Tried ‘1 Step Back, 2 Steps Forward’ …

Your page now:

<!DOCTYPE html>
<html>
  <head>
    <title>jQuery API tests</title>
    <script type="text/javascript" src="script.js"></script>
  </head>
<body>
   <button id="auth_button">Authorize</button>
</body>
</html>

Loads the code @DavidMtl has made available here:

https://github.com/DavidMtl/SimpleSafe

And dispenses for the time being with the other libraries.

Now the button has an ‘id’ which corresponds to the one expected by the javascript:

document.getElementById("auth_button")

Like @happybeing said, the browser-console will show you a new token if all goes well :slight_smile:

But then the Launcher already told you so by popping up the request you made of course.

This then will enable you to alter the code step by step and testing each time - to arrive at the page you had in mind yourself?

Uploaded this new page here on the Alpha net:

almost.there.safenet/bigbang.html

A separate link for the JS-file:

almost.there.safenet/script.js

The original page for the other parts of @DavidMtl’s code is still there too:

almost.there.safenet

3 Likes

Oh wow! SimpleSAFE is looks awesome! I’ll get back to my PC and have a try with it.

Exactly what I needed, many thanks you guys!

2 Likes

hmm, couldn’t even get SimpleSAFE working, I looked through the code and couldn’t find any variable called “permission” or anything similar. All of the JSON auth data (app name, id, etc) was filled out correctly in the SimpleSAFE js file.

This is the result of uploading through the Demo App and running on Firefox (also, here’s the safe:// link for it):

Looks like is should read “permissions” not “permission” - you found a bug! :slight_smile:

See api.docs:

permissions    |     List of permissions requested by the app (e.g. SAFE_DRIVE_ACCESS)

https://api.safedev.org/auth/authorize-app.html

1 Like

Never updated my first version of “simple_safe.js” and this is why that one works:

// Create the payload that will be sent with the request
var payload = {
    app: {
        name: "Simple SAFE API example",
        version: "1.0.0",
        vendor:  "your_name",
        id: "your_app_id"
    },
    permissions: ["SAFE_DRIVE_ACCESS"]
};

This line is missing in the Github-version:

    permissions: ["SAFE_DRIVE_ACCESS"]
4 Likes

You’re right, there was a bug in my code. For some reason I removed the permission parameter when I created the github repo. I updated it, it should work now. Here’s the link.

Thanks for spotting it!

EDIT: You beat me to it by 1 min.

5 Likes

Great! Excited to get it working!

Thanks guys I should have remembered that format from the original API.

You guys are great! Dev forum was a great idea

4 Likes

Looks like the perfect time to use SafeEditor for the first time! Adding in a line of code

So your test files are still here:

simple.bigbang.safenet/index.html
simple.bigbang.safenet/simple_safe.js

Noticing ‘json’-elements “name”, “version”, “vendor” and “id” in function “authorize” now being different in “simple_safe.js”, probably helpful for anyone following these steps to repeat this from the sister-forum here:

@WhiteOutMashups wrote

I can change the App name & version just fine, but as soon as I change the vendor to anything but “MaidSafe” then it won’t give SAFE_DRIVE_ACCESS and my public/ & private/ folders or any of my data won’t be available below.

@DavidMtl wrote

I noticed it too. What I understand is that the SafeLauncher use a mix of the App vendor and the App id to create a unique directory structure. You can change the app name and the app version and still access the same data structure. I read somewhere they did it that way to allow an app maker to create multiple apps that uses the same data structure to share data among them.

So when you change the vendor and the id you are effectively creating a whole new data structure with nothing in it.

1 Like

@DavidMtl left another element in your example-html:

<div id="response"></div>

Not used but there are ways to bring the console messages out to the page itself:
stackoverflow.com/questions/6604192/showing-console-errors-and-alerts-in-a-div-inside-the-page

Settling for something simple could be:

var logdiv = document.getElementById("response");
logdiv.innerText = logdiv.innerText + "\n" + this.responseText;

But then one will have to repeat this everywhere the script writes to the console.

1 Like

Thanks very much! Did lots of digging and got it all working last night.

Gonna have more fun with it today!

Very empowering to be able to use the API

I want to make a little tutorial after a bit

3 Likes

How hard do you guys think it would be to make the current SAFE email tutorial into a web page / web app so people could just go to it in the browser instead of the electron desktop software?

Integrating electron’s js codebase into js that could run from a webpage?

Are we expecting to see PUT and other apparently normal REST API options?.. to allow then overwrite on files. I see there is a PUT for register new service, though confused atm why that is not also POST.

I suppose PUT must be a simple compound of DELETE and POST but would be useful to just overwrite files in a single request. If there’s a risk of the DELETE failing perhaps it’s better that devs think to check each step has seen 200 successful.

@WhiteOutMashups

How hard do you guys think it would be to make the current SAFE email tutorial into a web page / web app so people could just go to it in the browser instead of the electron desktop software?

Integrating electron’s js codebase into js that could run from a webpage?

Sounds like s great little learning project for someone :wink:

I would not try to port electron stuff though, that’s a lot more work and not likely to be performant.

Better to simplify by stripping the app down to bare minimum, then enhance the look and feel later. In Beaker, with safe-js, you have access to the low level API so it should be a matter of copying the logic, rewriting anything that relies on electron, and building a new user interface.

2 Likes

@DavidMtl is there a version of SafeEditor that works with the new paradigm (safe-js / beaker 0.3.6-2+)? Really miss being able to edit my SAFE code automatically :,(

I didn’t know I had a user :slight_smile:

There isn’t for now. I was planning on waiting for things (API, permission) to settle a bit before investing more time into it but I’ll see what I can do tonight.

1 Like