Skip to content

Commit 39d2f3e

Browse files
authored
Add JS quickstart examples (#206)
1 parent 668fe2f commit 39d2f3e

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

website/docs/quickstart.md

+51-18
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ $ go get github.com/suborbital/se2-go@latest
8282

8383
<TabItem value = "sdk-js" label = "Using JS">
8484

85-
```js
86-
JS version goes here
85+
```bash
86+
npm install @suborbital/se2-node
8787
```
8888

8989
</TabItem>
@@ -120,7 +120,10 @@ func main() {
120120
<TabItem value = "tenant-js" label = "Using JS">
121121

122122
```js
123-
JS version goes here
123+
import { Suborbital } from "@suborbital/se2-node";
124+
125+
// Here, we've provided the token via the SE2_ENV_TOKEN environment variable.
126+
const suborbital = new Suborbital(process.env.SE2_ENV_TOKEN);
124127
```
125128

126129
</TabItem>
@@ -129,9 +132,7 @@ JS version goes here
129132

130133
## Create a tenant (user)
131134

132-
Suborbital lets an application's users create their own secure, sandboxed plugins, carefully isolated from the core of the system and one another. For this reason, we will create a new tenant, which is a user account with its own plugins inside Suborbital. Our application will then connect the tenant with one of its own internally-maintained users.
133-
134-
To create a tenant, we'll make an `HTTP POST` call:
135+
Suborbital lets an application's users create their own secure, sandboxed plugins, carefully isolated from the core of the system and one another. For this reason, we will create a new tenant, which is a user account with its own plugins inside Suborbital. Our application will then connect the tenant with one of its own internally-maintained users. Typically, you'll want to use your system's unique ID for the user as the name of the tenant.
135136

136137
<Tabs groupId="tenant-creation">
137138

@@ -151,7 +152,8 @@ func main() {
151152
<TabItem value = "tenant-js" label = "Using JS">
152153

153154
```js
154-
JS version goes here
155+
const tenant = "<user ID>";
156+
await suborbital.admin.createTenant({ tenant });
155157
```
156158

157159
</TabItem>
@@ -178,9 +180,9 @@ Authorization: Bearer OUR_ACCESS_KEY
178180

179181
The SE2 plugin editor uses SE2's APIs from either [Go](./how-to/se2-go.md) or [JavaScript/TypeScript](./how-to/se2-js.md) to provide a low-friction environment for your users to write, build, test, and deploy plugins to your SE2 an instance in a single place. Alternatively, the [Builder API](https://reference.suborbital.dev/) can be used programmatically, if that better suits your use case.
180182

181-
### Obtain an editor token
183+
### Obtain a session token
182184

183-
In addition to the `IDENTIFIER` and `ENV_TOKEN`, youll also need to set `NAMESPACE` and `fn` to the name of our namespace (e.g. `default`) and the name of our plugin (e.g. `hello`). Copy the `token` field in the response; this is your editor token.
185+
To grant a user access to modify a plugin, you'll need a session token. A session token is bound to a single plugin, and you'll create new tokens each time a user needs access to a plugin. To obtain a session token:
184186

185187
<Tabs groupId='editor-token'>
186188

@@ -207,7 +209,12 @@ func main() {
207209
<TabItem value = "js" label = "Using JS">
208210

209211
```js
210-
JS version goes here
212+
const params = {
213+
tenant: "<user ID>", // the user this plugin belongs to
214+
namespace: "<namespace>", // the plugin's namespace
215+
name: "<plugin name>", // the name of the plugin
216+
};
217+
const token = await suborbital.admin.createSession(params);
211218
```
212219

213220
</TabItem>
@@ -243,14 +250,10 @@ Configure the URL like so:
243250

244251
- Domain: `https://editor.suborbital.network/`
245252
- Query parameters:
246-
- `builder`: `https://your-builder.example.com`
253+
- `template`: the name of the template you wish to use
247254
- `token`: The [env token you created above](#create-an-environment)
248-
- `ident`: The name of your environment followed by a period, followed by the name of your [tenant](./reference/glossary.md). In the example below, the environment is `dev.suborbital.user1`and the tenant's name is `user1`.
249-
- `namespace`: the name of your namespace if different than “default”
250-
- `fn`: the name of your plugin. In the example below, the plugin name is `hello`.
251-
- `template`: the name of the language you wish to use (Go or JavaScript)
252255

253-
Altogether, it should look something like `https://editor.suborbital.network/?builder=https://your-builder.example.com&ident=dev.suborbital.user1&fn=hello&template=javascript`
256+
Altogether, it should look something like `https://editor.suborbital.network/?template=javascript&token=<session token>`
254257

255258
</TabItem>
256259

@@ -282,16 +285,46 @@ export const run = (input) => {
282285

283286
Once your first plugin has been built and deployed, it can be run with a request to the Execution API.
284287

288+
<Tabs groupId='execute-plugin'>
289+
290+
<TabItem value="go" label="Using Go">
291+
292+
```go
293+
Go version goes here
294+
```
295+
296+
</TabItem>
297+
298+
<TabItem value = "js" label = "Using JS">
299+
300+
```js
301+
const params = {
302+
tenant: "<user ID>", // the user this plugin belongs to
303+
namespace: "<namespace>", // the plugin's namespace
304+
name: "<plugin name>", // the name of the plugin
305+
};
306+
const result = await suborbital.exec.run(params, "my friend!");
307+
console.log(result.result); // hello, my friend!
308+
```
309+
310+
</TabItem>
311+
312+
<TabItem value = "curl" label = "Using cURL">
313+
285314
```bash
286315
export ENV_TOKEN=<your previously generated token>
287316

288317
curl http://local.suborbital.network:8080/com.suborbital.acmeco/default/hello/v1.0.0 \
289318
--header "Authorization: Bearer $ENV_TOKEN" \
290-
-d 'my friend'
319+
-d 'my friend!'
291320

292-
hello, my friend
321+
# hello, my friend!
293322
```
294323

324+
</TabItem>
325+
326+
</Tabs>
327+
295328
## What else can I do?
296329

297330
Now that you've know how to get SE2 extensibility powers into your app, you might want to:

0 commit comments

Comments
 (0)