@sbuilder/cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +469 -26
- package/README.vi.md +494 -0
- package/dist/bin/{wb.js → sb.js} +44 -13
- package/dist/bin/sb.js.map +1 -0
- package/dist/src/auth.js +173 -0
- package/dist/src/auth.js.map +1 -0
- package/dist/src/deploy.js +10 -9
- package/dist/src/deploy.js.map +1 -1
- package/dist/src/dev.js +11 -11
- package/dist/src/dev.js.map +1 -1
- package/dist/src/init.js +3 -3
- package/dist/src/login.js +119 -0
- package/dist/src/login.js.map +1 -0
- package/dist/src/scaffold.js +10 -10
- package/dist/src/types.js +1 -1
- package/package.json +31 -3
- package/dist/bin/wb.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Store Builder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,49 +1,492 @@
|
|
|
1
1
|
# @sbuilder/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**`sb`** — scaffold, run and deploy an app for the **Store Builder** platform.
|
|
4
|
+
|
|
5
|
+
> 🇻🇳 Bản tiếng Việt: [**README.vi.md**](./README.vi.md)
|
|
4
6
|
|
|
5
7
|
```
|
|
6
|
-
|
|
8
|
+
sb init [name] [--port 3000] scaffold an app that runs, registers, and opens
|
|
7
9
|
inside a merchant's admin
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
sb login sign in through the browser; stores a credential
|
|
11
|
+
that renews itself
|
|
12
|
+
sb logout sign this machine out and forget that credential
|
|
13
|
+
sb dev upload an island's code to your DRAFT version
|
|
14
|
+
every time you save it. Reads sb.json; needs
|
|
15
|
+
sb login (or SB_TOKEN).
|
|
16
|
+
sb deploy [--submit] push the version's payload in dependency order.
|
|
11
17
|
--submit then sends it for review.
|
|
12
18
|
```
|
|
13
19
|
|
|
14
20
|
Node 20 or newer. Written in TypeScript, published compiled — an installed copy
|
|
15
21
|
has no dependencies and nothing to build.
|
|
16
22
|
|
|
17
|
-
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Contents
|
|
26
|
+
|
|
27
|
+
- [What this is, and what it is not](#what-this-is-and-what-it-is-not)
|
|
28
|
+
- [Getting it](#getting-it)
|
|
29
|
+
- [The five-minute path](#the-five-minute-path)
|
|
30
|
+
- [`sb init`](#sb-init--scaffold-an-app-that-runs)
|
|
31
|
+
- [`sb.json`](#sbjson--the-file-dev-and-deploy-read)
|
|
32
|
+
- [`sb login` / `sb logout`](#sb-login--sb-logout--sign-in-through-the-browser)
|
|
33
|
+
- [`sb dev`](#sb-dev--save-upload-refresh)
|
|
34
|
+
- [`sb deploy`](#sb-deploy--the-whole-payload-in-dependency-order)
|
|
35
|
+
- [Environment variables](#environment-variables)
|
|
36
|
+
- [Refusals, and what they mean](#refusals-and-what-they-mean)
|
|
37
|
+
- [What it deliberately does not do](#what-it-deliberately-does-not-do)
|
|
38
|
+
- [Troubleshooting](#troubleshooting)
|
|
39
|
+
- [License](#license)
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## What this is, and what it is not
|
|
44
|
+
|
|
45
|
+
`sb` is a **faster path through the same territory, not a different one.**
|
|
46
|
+
Everything it does is an HTTP request you could send yourself with `curl`.
|
|
47
|
+
Nothing on this platform is reachable only through the CLI, and nothing here
|
|
48
|
+
hides a request from you.
|
|
49
|
+
|
|
50
|
+
What it removes is the mechanical part: writing an app skeleton that already
|
|
51
|
+
speaks OAuth, finding the island-upload endpoint on every save, and pushing a
|
|
52
|
+
version's payload through five separate doors in the one order the platform
|
|
53
|
+
accepts.
|
|
54
|
+
|
|
55
|
+
The deep reference is served by your own Store Builder deployment at
|
|
56
|
+
**`/cli-docs`**, alongside **`/app-docs`** (building an app) and
|
|
57
|
+
**`/block-docs`** (blocks and islands). That page is executable documentation —
|
|
58
|
+
its commands are extracted from its own bytes and run against the real binary in
|
|
59
|
+
CI, so it cannot describe a flag the CLI rejects. This README is held to the same
|
|
60
|
+
standard by `tests/readme.test.ts`.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Getting it
|
|
65
|
+
|
|
66
|
+
Nothing to install:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npx @sbuilder/cli --help
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or put it on your `PATH` for good:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install -g @sbuilder/cli
|
|
76
|
+
sb --help
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Node 20 or newer. The package ships compiled, so an installed copy has no
|
|
80
|
+
dependencies and nothing to build.
|
|
81
|
+
|
|
82
|
+
The scaffold `sb init` writes is deliberately the same way: no dependencies, no
|
|
83
|
+
build, plain ESM — because that is the code you actually run.
|
|
18
84
|
|
|
19
|
-
|
|
20
|
-
`/cli-docs` page of your Store Builder deployment** — the same place as
|
|
21
|
-
`/app-docs` (building an app) and `/block-docs` (blocks and islands). That page
|
|
22
|
-
is the one this repository tests against: its commands are extracted from its own
|
|
23
|
-
bytes and run against `bin/wb.js`, so it cannot document a flag the CLI rejects.
|
|
85
|
+
> Working on the CLI itself, rather than using it? [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
24
86
|
|
|
25
|
-
|
|
26
|
-
documents that disagree by next month, and only one of them is checked.
|
|
87
|
+
---
|
|
27
88
|
|
|
28
|
-
##
|
|
89
|
+
## The five-minute path
|
|
29
90
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Run it from a checkout instead — from the repository root:
|
|
91
|
+
The whole loop, start to finish. Steps 2 and 3 are yours — see `/app-docs` — and
|
|
92
|
+
everything else is one command.
|
|
33
93
|
|
|
34
94
|
```bash
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
95
|
+
# 1. A working app on your machine
|
|
96
|
+
sb init my-app --port 4000
|
|
97
|
+
cd my-app
|
|
98
|
+
cp .env.example .env # fill in SB_CLIENT_ID and SB_CLIENT_SECRET
|
|
99
|
+
npm start
|
|
38
100
|
```
|
|
39
101
|
|
|
40
|
-
|
|
102
|
+
2. **Create the app** in your organization, and note the `clientId` /
|
|
103
|
+
`clientSecret` it returns. The secret is shown **once**.
|
|
104
|
+
3. **Create a DRAFT version** pointing at your local URLs — embed URL
|
|
105
|
+
`http://localhost:4000/embed`, redirect URI
|
|
106
|
+
`http://localhost:4000/oauth/callback`. **No tunnel is needed:** a draft
|
|
107
|
+
version may point at `http://localhost` and a sandbox install may frame it,
|
|
108
|
+
so the entire development loop runs on your own machine. A tunnel is only for
|
|
109
|
+
checking the public URLs before you submit.
|
|
41
110
|
|
|
42
111
|
```bash
|
|
43
|
-
|
|
44
|
-
|
|
112
|
+
# 4. Sign in once (prints a code you type in the browser)
|
|
113
|
+
sb login
|
|
114
|
+
|
|
115
|
+
# 5. Write sb.json with the ids you now have (see below), then:
|
|
116
|
+
sb dev # edit an island, save, refresh
|
|
117
|
+
|
|
118
|
+
# 6. Push the whole payload, and send it for review
|
|
119
|
+
sb deploy --submit
|
|
45
120
|
```
|
|
46
121
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## `sb init` — scaffold an app that runs
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
sb init my-app
|
|
128
|
+
sb init my-app --port 4000
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Writes a working app into `./my-app` and prints what to do next. It makes **no
|
|
132
|
+
network calls at all** — it is a scaffolder, not a registration step. Creating
|
|
133
|
+
the app and creating a version are still yours to do.
|
|
134
|
+
|
|
135
|
+
### What it writes
|
|
136
|
+
|
|
137
|
+
Five files, and nothing else:
|
|
138
|
+
|
|
139
|
+
| File | What it is |
|
|
140
|
+
| --- | --- |
|
|
141
|
+
| `server.js` | The whole app: the `/oauth/callback` token exchange and the framed `/embed` page, in one file with no dependencies |
|
|
142
|
+
| `package.json` | `npm start` runs `server.js`. **No dependencies and no devDependencies** — the first `npm install` should not be the first thing that can fail |
|
|
143
|
+
| `.env.example` | `SB_CLIENT_ID`, `SB_CLIENT_SECRET`, `SB_API`, `SB_REDIRECT_URI` and `PORT` |
|
|
144
|
+
| `README.md` | The same next steps the command prints, for when the terminal has scrolled |
|
|
145
|
+
| `.gitignore` | `node_modules` and `.env` |
|
|
146
|
+
|
|
147
|
+
There are deliberately **no blocks, no islands and no app data**. Each is a real
|
|
148
|
+
feature with its own guide, and none is needed to watch an app appear inside a
|
|
149
|
+
merchant's admin for the first time.
|
|
150
|
+
|
|
151
|
+
### The name
|
|
152
|
+
|
|
153
|
+
The argument is normalised into something npm accepts as a package name:
|
|
154
|
+
lower-cased, any run of characters outside `a-z 0-9 . _ -` collapsed to a single
|
|
155
|
+
`-`, and leading/trailing `-_.` trimmed.
|
|
156
|
+
|
|
157
|
+
| You type | You get |
|
|
158
|
+
| --- | --- |
|
|
159
|
+
| `sb init my-app` | `./my-app` |
|
|
160
|
+
| `sb init "My App!"` | `./my-app` |
|
|
161
|
+
| `sb init` | `./my-app` |
|
|
162
|
+
|
|
163
|
+
### What it refuses
|
|
164
|
+
|
|
165
|
+
**It never overwrites, and it never half-writes.** The whole file set is checked
|
|
166
|
+
against the target directory before anything is written; a single collision
|
|
167
|
+
refuses the lot and names what clashed:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
/path/to/my-app already contains package.json, server.js — refusing to overwrite.
|
|
171
|
+
Pick an empty directory, or move those files aside.
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
A partial scaffold is worse than none, because it leaves a directory that looks
|
|
175
|
+
initialised and is not. An *existing* directory is otherwise fine — running
|
|
176
|
+
`sb init` inside a fresh `git clone` is normal, and refusing it because `.git`
|
|
177
|
+
exists would refuse the common case.
|
|
178
|
+
|
|
179
|
+
### Flags
|
|
180
|
+
|
|
181
|
+
| Flag | Default | Effect |
|
|
182
|
+
| --- | --- | --- |
|
|
183
|
+
| `--port <n>` | `3000` | The port baked into `.env.example`, the generated README and every URL the command prints. A value that is not a positive number is refused with `--port must be a number` |
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## `sb.json` — the file `dev` and `deploy` read
|
|
188
|
+
|
|
189
|
+
Both `sb dev` and `sb deploy` read an `sb.json` from the **current directory**.
|
|
190
|
+
|
|
191
|
+
**`sb init` does not write it, and it cannot**: three of its five required fields
|
|
192
|
+
are ids the platform mints when you create the app and its draft version, which
|
|
193
|
+
has not happened yet at `init` time. Write it by hand once you have them:
|
|
194
|
+
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"orgId": "org_yourorg",
|
|
198
|
+
"appId": "app_1a2b3c4d",
|
|
199
|
+
"versionId": "ver_5e6f7a8b",
|
|
200
|
+
"island": "countdown",
|
|
201
|
+
"entry": "islands/countdown.js"
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Required — both commands refuse without all five
|
|
206
|
+
|
|
207
|
+
| Key | What it is |
|
|
208
|
+
| --- | --- |
|
|
209
|
+
| `orgId` | The organization that owns the app |
|
|
210
|
+
| `appId` | The app |
|
|
211
|
+
| `versionId` | The **draft** version being edited |
|
|
212
|
+
| `island` | The island `sb dev` uploads to |
|
|
213
|
+
| `entry` | The file `sb dev` watches, relative to `sb.json` |
|
|
214
|
+
|
|
215
|
+
A missing key is refused by name — `sb.json is missing "versionId".` — and a
|
|
216
|
+
missing file is refused with the list of what it needs. `sb deploy` requires all
|
|
217
|
+
five even though its own work is described by the optional keys below, so fill
|
|
218
|
+
them in even if you are only deploying blocks.
|
|
219
|
+
|
|
220
|
+
### Optional — each one found becomes a deploy step
|
|
221
|
+
|
|
222
|
+
| Key | Type | What `sb deploy` does with it |
|
|
223
|
+
| --- | --- | --- |
|
|
224
|
+
| `version` | object | `PUT` as the version's fields — `scopes`, `embedUrl`, `redirectUri` and the rest |
|
|
225
|
+
| `blocks` | path | The block manifest, `PUT` as the body of `.../blocks` |
|
|
226
|
+
| `islands` | array of `{name, entry}` | Declares every `name`, then uploads every `entry` |
|
|
227
|
+
|
|
228
|
+
An `sb.json` with only the five required keys is valid: `sb dev` works, and
|
|
229
|
+
`sb deploy` finds no steps to run.
|
|
230
|
+
|
|
231
|
+
A fuller one:
|
|
232
|
+
|
|
233
|
+
```json
|
|
234
|
+
{
|
|
235
|
+
"orgId": "org_yourorg",
|
|
236
|
+
"appId": "app_1a2b3c4d",
|
|
237
|
+
"versionId": "ver_5e6f7a8b",
|
|
238
|
+
"island": "countdown",
|
|
239
|
+
"entry": "islands/countdown.js",
|
|
240
|
+
"version": {
|
|
241
|
+
"scopes": ["products.read", "orders.read"],
|
|
242
|
+
"embedUrl": "https://app.example.com/embed",
|
|
243
|
+
"redirectUri": "https://app.example.com/oauth/callback"
|
|
244
|
+
},
|
|
245
|
+
"blocks": "blocks.json",
|
|
246
|
+
"islands": [
|
|
247
|
+
{ "name": "countdown", "entry": "islands/countdown.js" },
|
|
248
|
+
{ "name": "stock-bar", "entry": "islands/stock-bar.js" }
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## `sb login` / `sb logout` — sign in through the browser
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
sb login
|
|
259
|
+
sb logout
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
`sb login` signs the CLI in **through the editor in your browser**, so it works
|
|
263
|
+
for an account that signs in with Google or GitHub and has no password. It
|
|
264
|
+
never asks for a password:
|
|
265
|
+
|
|
266
|
+
1. It prints an address — the editor's `/device` page — and an 8-character code
|
|
267
|
+
such as `BCDF-GHJK`.
|
|
268
|
+
2. Open that page in a browser where you are signed in (sign in first if you
|
|
269
|
+
are not), **type the code**, check that the page shows the same code and the
|
|
270
|
+
`sb-cli` client, and approve.
|
|
271
|
+
3. The CLI, which has been polling, receives a credential and stores it.
|
|
272
|
+
|
|
273
|
+
The code is **typed, never put in a link**: a link that pre-filled it would let
|
|
274
|
+
someone send you their own code to approve. It expires after 10 minutes, and
|
|
275
|
+
can be approved once. Denying it in the browser stops the CLI with
|
|
276
|
+
`The sign-in was denied in the browser. Nothing was stored.`
|
|
277
|
+
|
|
278
|
+
**What is stored.** An access token and a refresh token, per API address (so a
|
|
279
|
+
local and a production sign-in coexist), in
|
|
280
|
+
`${XDG_CONFIG_HOME:-~/.config}/sb/credentials.json`, created readable by you
|
|
281
|
+
only (mode `0600`). `sb login` is a separate signed-in device on your account,
|
|
282
|
+
listed with your other sessions; signing out everywhere ends it too.
|
|
283
|
+
|
|
284
|
+
**It renews itself.** When the server refuses the access token, `sb dev` and
|
|
285
|
+
`sb deploy` rotate the pair once, save it, and retry the request. Two `sb`
|
|
286
|
+
processes renewing at the same moment take turns through a lock file beside
|
|
287
|
+
the credentials, and the second one adopts the pair the first one saved — a
|
|
288
|
+
refresh token presented twice would end the session. If the renewal itself is
|
|
289
|
+
refused, the entry is deleted and the CLI says to run `sb login` again.
|
|
290
|
+
|
|
291
|
+
`sb logout` revokes this device's session on the server and deletes its entry
|
|
292
|
+
from the file. Your other devices stay signed in.
|
|
293
|
+
|
|
294
|
+
`SB_TOKEN`, when set, **takes precedence** over the stored credential — see
|
|
295
|
+
[Environment variables](#environment-variables).
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## `sb dev` — save, upload, refresh
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
SB_TOKEN=<your token> sb dev
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Watches the `entry` file from `sb.json` and uploads it to the version's `island`
|
|
306
|
+
every time you save. It uploads once immediately on start rather than waiting for
|
|
307
|
+
your first save, then runs until you interrupt it.
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
watching islands/countdown.js — save it and this uploads to version ver_5e6f7a8b.
|
|
311
|
+
This is not hot reload: after each upload, refresh the page.
|
|
312
|
+
uploaded countdown — refresh the page to see it
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**It is not hot reload, and it will never say it is.** An island's code on a
|
|
316
|
+
rendered page always comes from the platform's object store, so a page cannot be
|
|
317
|
+
pointed at a local dev server and there is no live patching to be had. What the
|
|
318
|
+
command removes is the friction of finding the endpoint: you save, it uploads,
|
|
319
|
+
**you refresh the page.**
|
|
320
|
+
|
|
321
|
+
**It uploads to a draft.** A version that has left draft refuses the write —
|
|
322
|
+
approval pins a payload, and an island swapped after review is code running on
|
|
323
|
+
merchants' pages that nobody looked at.
|
|
324
|
+
|
|
325
|
+
`sb dev` takes no flags. It uploads **one** island — the one named in `sb.json`.
|
|
326
|
+
To push several at once, use `sb deploy` with an `islands` array.
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## `sb deploy` — the whole payload, in dependency order
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
SB_TOKEN=<your token> sb deploy
|
|
334
|
+
SB_TOKEN=<your token> sb deploy --submit
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Runs every step your `sb.json` describes, in this order:
|
|
338
|
+
|
|
339
|
+
```
|
|
340
|
+
version fields PUT /api/orgs/{orgId}/apps/{appId}/versions/{versionId}
|
|
341
|
+
blocks PUT .../blocks
|
|
342
|
+
island declarations PUT .../islands
|
|
343
|
+
island "<name>" POST .../islands/module?name=<name> (one per island)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**The order is the design.** Declarations come before the modules that fill them,
|
|
347
|
+
because code uploaded for an island the version does not declare is refused
|
|
348
|
+
(`island_not_found`), while a declaration with no code yet is a state the
|
|
349
|
+
platform expects. A failure part-way therefore leaves the *shape* of what you
|
|
350
|
+
intended rather than orphaned bytes.
|
|
351
|
+
|
|
352
|
+
### It is not atomic, and it does not need to be
|
|
353
|
+
|
|
354
|
+
A version's payload is written through five doors and no single call carries it,
|
|
355
|
+
so a tool that sequenced them and called the result atomic would be making a
|
|
356
|
+
promise in the one place you would rely on it. It does not need the promise: **a
|
|
357
|
+
draft is designed to be incoherent between writes.** Both coherence checks run at
|
|
358
|
+
submit, not on the individual writes, so a half-finished deploy is an
|
|
359
|
+
*unfinished* version rather than a damaged one.
|
|
360
|
+
|
|
361
|
+
What the command owes you instead is to say where it stopped:
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
Stopped at: island "countdown"
|
|
365
|
+
|
|
366
|
+
This version is in review or already approved, so its code is frozen.
|
|
367
|
+
Create a new draft version and point sb dev at that one.
|
|
368
|
+
(server: version has left draft)
|
|
369
|
+
|
|
370
|
+
Already applied: version fields, blocks, island declarations
|
|
371
|
+
|
|
372
|
+
This left the version UNFINISHED, not broken — a draft is allowed to be
|
|
373
|
+
partway through, and it simply cannot be submitted until the rest lands.
|
|
374
|
+
Fix the cause and run sb deploy again; every step is safe to repeat.
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Every write is idempotent, so resuming is simply running it again.
|
|
378
|
+
|
|
379
|
+
### Flags
|
|
380
|
+
|
|
381
|
+
| Flag | Effect |
|
|
382
|
+
| --- | --- |
|
|
383
|
+
| `--submit` | After the deploy succeeds, `POST .../submit` — the review gate |
|
|
384
|
+
|
|
385
|
+
`--submit` first checks the `version` block in your `sb.json` for URLs still
|
|
386
|
+
pointing at your own machine, and refuses **before** it calls the server:
|
|
387
|
+
|
|
388
|
+
```
|
|
389
|
+
This version still points at your own machine: embedUrl (http://localhost:3000/embed).
|
|
390
|
+
Review needs public https URLs — the loopback allowance covers development only.
|
|
391
|
+
Update the version to its real addresses, deploy again, then submit.
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
That check is a **courtesy and never the authority.** The server runs the real
|
|
395
|
+
one, and if the two ever disagree the server wins; this exists only to fail
|
|
396
|
+
earlier, with more room to explain than a status code has.
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Environment variables
|
|
401
|
+
|
|
402
|
+
Two are read by the CLI itself:
|
|
403
|
+
|
|
404
|
+
| Variable | Required by | Default |
|
|
405
|
+
| --- | --- | --- |
|
|
406
|
+
| `SB_TOKEN` | `sb dev`, `sb deploy` — optional | none — the `sb login` credential is used; with neither, both stop and name `sb login` |
|
|
407
|
+
| `SB_API` | every command but `sb init` | `http://localhost:8080` |
|
|
408
|
+
|
|
409
|
+
`SB_TOKEN` **overrides** the stored `sb login` credential when set. It is a
|
|
410
|
+
token for the **organization that owns the app** — the same user access token
|
|
411
|
+
you would put in an `Authorization: Bearer` header against the org-scoped
|
|
412
|
+
routes. It is **not** a `wba_` app token; those belong to an install, and an
|
|
413
|
+
install cannot edit the app it is an install of.
|
|
414
|
+
|
|
415
|
+
A pasted token cannot renew itself. When the server refuses it, the CLI says
|
|
416
|
+
`SB_TOKEN was refused: it has expired or been revoked` and points you at
|
|
417
|
+
`sb login` — it never tries to refresh it.
|
|
418
|
+
|
|
419
|
+
Three more are read by the app `sb init` writes, from its own `.env`:
|
|
420
|
+
|
|
421
|
+
| Variable | Read by | What it is |
|
|
422
|
+
| --- | --- | --- |
|
|
423
|
+
| `SB_CLIENT_ID` | the scaffolded `server.js` | Shown when you create the app |
|
|
424
|
+
| `SB_CLIENT_SECRET` | the scaffolded `server.js` | Shown **once**, at creation. Lost means rotate, not hunt |
|
|
425
|
+
| `SB_REDIRECT_URI` | the scaffolded `server.js` | Must match the redirect URI on your version character for character |
|
|
426
|
+
|
|
427
|
+
The scaffolded app also reads `SB_API` and `PORT`.
|
|
428
|
+
|
|
429
|
+
---
|
|
430
|
+
|
|
431
|
+
## Refusals, and what they mean
|
|
432
|
+
|
|
433
|
+
Every command exits `0` on success and `1` on a refusal it can explain. Anything
|
|
434
|
+
else is a bug in the tool and gets a stack trace, because a scaffolder that
|
|
435
|
+
swallows its own failures is one nobody can report.
|
|
436
|
+
|
|
437
|
+
The server codes the CLI translates, rather than passing through verbatim:
|
|
438
|
+
|
|
439
|
+
| Server code | What `sb` says instead |
|
|
440
|
+
| --- | --- |
|
|
441
|
+
| `not_draft` | This version is in review or already approved, so its code is frozen — create a new draft and point at that one |
|
|
442
|
+
| `island_not_found` | This version does not declare an island by that name; declare it first |
|
|
443
|
+
| `island_module_not_text` | That file is not text. An island module is JavaScript |
|
|
444
|
+
| `island_module_too_large` | That file is too large to upload as an island module |
|
|
445
|
+
| `unauthorized` | Not signed in. Run `sb login`, or set `SB_TOKEN` to a token for the organization that owns this app |
|
|
446
|
+
| any other `401`/`403` | This token cannot edit that app — check who you are signed in as (`sb login` / `SB_TOKEN`), and that the app belongs to the organization you named |
|
|
447
|
+
|
|
448
|
+
Each keeps the server's own sentence in `(server: …)` and adds the next action. A
|
|
449
|
+
code the tool has not been taught is printed in the server's words rather than a
|
|
450
|
+
shrug.
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
## What it deliberately does not do
|
|
455
|
+
|
|
456
|
+
Stated so you can plan around it rather than discover it.
|
|
457
|
+
|
|
458
|
+
- **It does not create the app, the version, or the install.** `sb init` makes no
|
|
459
|
+
network calls. Those steps are yours, by hand or by your own script; the CLI
|
|
460
|
+
starts being useful once those ids exist.
|
|
461
|
+
- **It does not write `sb.json`**, for the same reason.
|
|
462
|
+
- **It never asks for a password.** `sb login` signs in through the browser,
|
|
463
|
+
and the only thing it stores is the credential file described above.
|
|
464
|
+
- **`sb dev` is not hot reload**, and no future version of it can be while an
|
|
465
|
+
island's code is served from the platform's object store.
|
|
466
|
+
- **`sb deploy` is not atomic**, deliberately.
|
|
467
|
+
- **It is not on npm yet.**
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## Troubleshooting
|
|
472
|
+
|
|
473
|
+
| Symptom | Cause | Fix |
|
|
474
|
+
| --- | --- | --- |
|
|
475
|
+
| `Not signed in. Run sb login …` | `dev`/`deploy` have no credential | `sb login`, or set `SB_TOKEN` |
|
|
476
|
+
| `Your sb login has expired or was revoked.` | The stored session ended (signed out everywhere, or it lapsed) | `sb login` again |
|
|
477
|
+
| `SB_TOKEN was refused: …` | The pasted token expired or was revoked | `sb login`, or a fresh token |
|
|
478
|
+
| `No sb.json here.` | Run from the wrong directory | `cd` to the folder holding `sb.json` |
|
|
479
|
+
| `sb.json is missing "versionId".` | A required key is absent or empty | Add all five required keys |
|
|
480
|
+
| `unknown command: …` | Typo, or a stale `dist/` | `npm run build --workspace cli` |
|
|
481
|
+
| `--port must be a number` | `--port` got a non-positive or non-numeric value | Pass a positive integer |
|
|
482
|
+
| Uploads refused with `not_draft` | The version left draft; approval pins its payload | Create a new draft version and point `sb.json` at it |
|
|
483
|
+
| Uploads refused with `island_not_found` | The version does not declare that island | Declare it first — `sb deploy` with an `islands` array does this in the right order |
|
|
484
|
+
| `--submit` refused for loopback URLs | `version.embedUrl` / `version.redirectUri` still point at localhost | Set public `https` URLs, `sb deploy` again, then submit |
|
|
485
|
+
| The island changed and the page did not | `sb dev` is not hot reload | Refresh the page |
|
|
486
|
+
| `sb` reports a flag this page does not list | You are running an older `dist/` | Rebuild |
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## License
|
|
491
|
+
|
|
492
|
+
[MIT](./LICENSE) © Store Builder
|