@sbuilder/cli 0.1.0 → 0.1.1
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 +434 -21
- package/README.vi.md +465 -0
- package/dist/bin/{wb.js → sb.js} +13 -13
- package/dist/bin/{wb.js.map → sb.js.map} +1 -1
- package/dist/src/deploy.js +3 -3
- package/dist/src/dev.js +8 -8
- package/dist/src/init.js +3 -3
- package/dist/src/scaffold.js +10 -10
- package/dist/src/types.js +1 -1
- package/package.json +31 -3
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,43 +1,442 @@
|
|
|
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
|
-
every time you save it. Reads
|
|
10
|
-
|
|
10
|
+
sb dev upload an island's code to your DRAFT version
|
|
11
|
+
every time you save it. Reads sb.json; needs SB_TOKEN.
|
|
12
|
+
sb deploy [--submit] push the version's payload in dependency order.
|
|
11
13
|
--submit then sends it for review.
|
|
12
14
|
```
|
|
13
15
|
|
|
14
16
|
Node 20 or newer. Written in TypeScript, published compiled — an installed copy
|
|
15
17
|
has no dependencies and nothing to build.
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Contents
|
|
22
|
+
|
|
23
|
+
- [What this is, and what it is not](#what-this-is-and-what-it-is-not)
|
|
24
|
+
- [Getting it](#getting-it)
|
|
25
|
+
- [The five-minute path](#the-five-minute-path)
|
|
26
|
+
- [`sb init`](#sb-init--scaffold-an-app-that-runs)
|
|
27
|
+
- [`sb.json`](#sbjson--the-file-dev-and-deploy-read)
|
|
28
|
+
- [`sb dev`](#sb-dev--save-upload-refresh)
|
|
29
|
+
- [`sb deploy`](#sb-deploy--the-whole-payload-in-dependency-order)
|
|
30
|
+
- [Environment variables](#environment-variables)
|
|
31
|
+
- [Refusals, and what they mean](#refusals-and-what-they-mean)
|
|
32
|
+
- [What it deliberately does not do](#what-it-deliberately-does-not-do)
|
|
33
|
+
- [Troubleshooting](#troubleshooting)
|
|
34
|
+
- [Working on the CLI itself](#working-on-the-cli-itself)
|
|
35
|
+
- [License](#license)
|
|
36
|
+
|
|
37
|
+
---
|
|
18
38
|
|
|
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.
|
|
39
|
+
## What this is, and what it is not
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
|
|
41
|
+
`sb` is a **faster path through the same territory, not a different one.**
|
|
42
|
+
Everything it does is an HTTP request you could send yourself with `curl`.
|
|
43
|
+
Nothing on this platform is reachable only through the CLI, and nothing here
|
|
44
|
+
hides a request from you.
|
|
27
45
|
|
|
28
|
-
|
|
46
|
+
What it removes is the mechanical part: writing an app skeleton that already
|
|
47
|
+
speaks OAuth, finding the island-upload endpoint on every save, and pushing a
|
|
48
|
+
version's payload through five separate doors in the one order the platform
|
|
49
|
+
accepts.
|
|
29
50
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
The deep reference is served by your own Store Builder deployment at
|
|
52
|
+
**`/cli-docs`**, alongside **`/app-docs`** (building an app) and
|
|
53
|
+
**`/block-docs`** (blocks and islands). That page is executable documentation —
|
|
54
|
+
its commands are extracted from its own bytes and run against the real binary in
|
|
55
|
+
CI, so it cannot describe a flag the CLI rejects. This README is held to the same
|
|
56
|
+
standard by `tests/readme.test.ts`.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Getting it
|
|
61
|
+
|
|
62
|
+
**`@sbuilder/cli` is not on npm yet.** The publish workflow is complete
|
|
63
|
+
(`.github/workflows/publish-cli.yml`) and waiting on an npm credential, so `npx`
|
|
64
|
+
will not find it. Run it from a checkout instead:
|
|
33
65
|
|
|
34
66
|
```bash
|
|
67
|
+
git clone https://github.com/vuluu2k/web_builder.git
|
|
68
|
+
cd web_builder
|
|
35
69
|
npm ci
|
|
36
70
|
npm run build --workspace cli
|
|
37
|
-
node cli/dist/bin/
|
|
71
|
+
node cli/dist/bin/sb.js --help
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
To get an `sb` command on your `PATH` rather than typing that path each time:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npm run build --workspace cli
|
|
78
|
+
cd cli && npm link
|
|
79
|
+
sb --help
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Everywhere below writes `sb`; `node cli/dist/bin/sb.js` is always the same thing.
|
|
83
|
+
If `sb` reports a command or flag this page does not describe, rebuild — you are
|
|
84
|
+
running an older `dist/` than the source beside it.
|
|
85
|
+
|
|
86
|
+
The build is the only dependency the CLI has. The **scaffold** `sb init` writes
|
|
87
|
+
is deliberately different and stays that way: no dependencies, no build, plain
|
|
88
|
+
ESM — because that is the code you actually run.
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## The five-minute path
|
|
93
|
+
|
|
94
|
+
The whole loop, start to finish. Steps 2 and 3 are yours — see `/app-docs` — and
|
|
95
|
+
everything else is one command.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# 1. A working app on your machine
|
|
99
|
+
sb init my-app --port 4000
|
|
100
|
+
cd my-app
|
|
101
|
+
cp .env.example .env # fill in SB_CLIENT_ID and SB_CLIENT_SECRET
|
|
102
|
+
npm start
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
2. **Create the app** in your organization, and note the `clientId` /
|
|
106
|
+
`clientSecret` it returns. The secret is shown **once**.
|
|
107
|
+
3. **Create a DRAFT version** pointing at your local URLs — embed URL
|
|
108
|
+
`http://localhost:4000/embed`, redirect URI
|
|
109
|
+
`http://localhost:4000/oauth/callback`. **No tunnel is needed:** a draft
|
|
110
|
+
version may point at `http://localhost` and a sandbox install may frame it,
|
|
111
|
+
so the entire development loop runs on your own machine. A tunnel is only for
|
|
112
|
+
checking the public URLs before you submit.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# 4. Write sb.json with the ids you now have (see below), then:
|
|
116
|
+
SB_TOKEN=<your token> sb dev # edit an island, save, refresh
|
|
117
|
+
|
|
118
|
+
# 5. Push the whole payload, and send it for review
|
|
119
|
+
SB_TOKEN=<your token> sb deploy --submit
|
|
120
|
+
```
|
|
121
|
+
|
|
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
|
+
}
|
|
38
251
|
```
|
|
39
252
|
|
|
40
|
-
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## `sb dev` — save, upload, refresh
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
SB_TOKEN=<your token> sb dev
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Watches the `entry` file from `sb.json` and uploads it to the version's `island`
|
|
262
|
+
every time you save. It uploads once immediately on start rather than waiting for
|
|
263
|
+
your first save, then runs until you interrupt it.
|
|
264
|
+
|
|
265
|
+
```
|
|
266
|
+
watching islands/countdown.js — save it and this uploads to version ver_5e6f7a8b.
|
|
267
|
+
This is not hot reload: after each upload, refresh the page.
|
|
268
|
+
uploaded countdown — refresh the page to see it
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
**It is not hot reload, and it will never say it is.** An island's code on a
|
|
272
|
+
rendered page always comes from the platform's object store, so a page cannot be
|
|
273
|
+
pointed at a local dev server and there is no live patching to be had. What the
|
|
274
|
+
command removes is the friction of finding the endpoint: you save, it uploads,
|
|
275
|
+
**you refresh the page.**
|
|
276
|
+
|
|
277
|
+
**It uploads to a draft.** A version that has left draft refuses the write —
|
|
278
|
+
approval pins a payload, and an island swapped after review is code running on
|
|
279
|
+
merchants' pages that nobody looked at.
|
|
280
|
+
|
|
281
|
+
`sb dev` takes no flags. It uploads **one** island — the one named in `sb.json`.
|
|
282
|
+
To push several at once, use `sb deploy` with an `islands` array.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## `sb deploy` — the whole payload, in dependency order
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
SB_TOKEN=<your token> sb deploy
|
|
290
|
+
SB_TOKEN=<your token> sb deploy --submit
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Runs every step your `sb.json` describes, in this order:
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
version fields PUT /api/orgs/{orgId}/apps/{appId}/versions/{versionId}
|
|
297
|
+
blocks PUT .../blocks
|
|
298
|
+
island declarations PUT .../islands
|
|
299
|
+
island "<name>" POST .../islands/module?name=<name> (one per island)
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
**The order is the design.** Declarations come before the modules that fill them,
|
|
303
|
+
because code uploaded for an island the version does not declare is refused
|
|
304
|
+
(`island_not_found`), while a declaration with no code yet is a state the
|
|
305
|
+
platform expects. A failure part-way therefore leaves the *shape* of what you
|
|
306
|
+
intended rather than orphaned bytes.
|
|
307
|
+
|
|
308
|
+
### It is not atomic, and it does not need to be
|
|
309
|
+
|
|
310
|
+
A version's payload is written through five doors and no single call carries it,
|
|
311
|
+
so a tool that sequenced them and called the result atomic would be making a
|
|
312
|
+
promise in the one place you would rely on it. It does not need the promise: **a
|
|
313
|
+
draft is designed to be incoherent between writes.** Both coherence checks run at
|
|
314
|
+
submit, not on the individual writes, so a half-finished deploy is an
|
|
315
|
+
*unfinished* version rather than a damaged one.
|
|
316
|
+
|
|
317
|
+
What the command owes you instead is to say where it stopped:
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
Stopped at: island "countdown"
|
|
321
|
+
|
|
322
|
+
This version is in review or already approved, so its code is frozen.
|
|
323
|
+
Create a new draft version and point sb dev at that one.
|
|
324
|
+
(server: version has left draft)
|
|
325
|
+
|
|
326
|
+
Already applied: version fields, blocks, island declarations
|
|
327
|
+
|
|
328
|
+
This left the version UNFINISHED, not broken — a draft is allowed to be
|
|
329
|
+
partway through, and it simply cannot be submitted until the rest lands.
|
|
330
|
+
Fix the cause and run sb deploy again; every step is safe to repeat.
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Every write is idempotent, so resuming is simply running it again.
|
|
334
|
+
|
|
335
|
+
### Flags
|
|
336
|
+
|
|
337
|
+
| Flag | Effect |
|
|
338
|
+
| --- | --- |
|
|
339
|
+
| `--submit` | After the deploy succeeds, `POST .../submit` — the review gate |
|
|
340
|
+
|
|
341
|
+
`--submit` first checks the `version` block in your `sb.json` for URLs still
|
|
342
|
+
pointing at your own machine, and refuses **before** it calls the server:
|
|
343
|
+
|
|
344
|
+
```
|
|
345
|
+
This version still points at your own machine: embedUrl (http://localhost:3000/embed).
|
|
346
|
+
Review needs public https URLs — the loopback allowance covers development only.
|
|
347
|
+
Update the version to its real addresses, deploy again, then submit.
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
That check is a **courtesy and never the authority.** The server runs the real
|
|
351
|
+
one, and if the two ever disagree the server wins; this exists only to fail
|
|
352
|
+
earlier, with more room to explain than a status code has.
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Environment variables
|
|
357
|
+
|
|
358
|
+
Two are read by the CLI itself:
|
|
359
|
+
|
|
360
|
+
| Variable | Required by | Default |
|
|
361
|
+
| --- | --- | --- |
|
|
362
|
+
| `SB_TOKEN` | `sb dev`, `sb deploy` | none — both stop immediately without it |
|
|
363
|
+
| `SB_API` | `sb dev`, `sb deploy` | `http://localhost:8080` |
|
|
364
|
+
|
|
365
|
+
`SB_TOKEN` is a token for the **organization that owns the app** — the same user
|
|
366
|
+
access token you would put in an `Authorization: Bearer` header against the
|
|
367
|
+
org-scoped routes. It is **not** a `wba_` app token; those belong to an install,
|
|
368
|
+
and an install cannot edit the app it is an install of.
|
|
369
|
+
|
|
370
|
+
Three more are read by the app `sb init` writes, from its own `.env`:
|
|
371
|
+
|
|
372
|
+
| Variable | Read by | What it is |
|
|
373
|
+
| --- | --- | --- |
|
|
374
|
+
| `SB_CLIENT_ID` | the scaffolded `server.js` | Shown when you create the app |
|
|
375
|
+
| `SB_CLIENT_SECRET` | the scaffolded `server.js` | Shown **once**, at creation. Lost means rotate, not hunt |
|
|
376
|
+
| `SB_REDIRECT_URI` | the scaffolded `server.js` | Must match the redirect URI on your version character for character |
|
|
377
|
+
|
|
378
|
+
The scaffolded app also reads `SB_API` and `PORT`.
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## Refusals, and what they mean
|
|
383
|
+
|
|
384
|
+
Every command exits `0` on success and `1` on a refusal it can explain. Anything
|
|
385
|
+
else is a bug in the tool and gets a stack trace, because a scaffolder that
|
|
386
|
+
swallows its own failures is one nobody can report.
|
|
387
|
+
|
|
388
|
+
The server codes the CLI translates, rather than passing through verbatim:
|
|
389
|
+
|
|
390
|
+
| Server code | What `sb` says instead |
|
|
391
|
+
| --- | --- |
|
|
392
|
+
| `not_draft` | This version is in review or already approved, so its code is frozen — create a new draft and point at that one |
|
|
393
|
+
| `island_not_found` | This version does not declare an island by that name; declare it first |
|
|
394
|
+
| `island_module_not_text` | That file is not text. An island module is JavaScript |
|
|
395
|
+
| `island_module_too_large` | That file is too large to upload as an island module |
|
|
396
|
+
| `unauthorized` | Not signed in. Set `SB_TOKEN` to a token for the organization that owns this app |
|
|
397
|
+
| any other `401`/`403` | This token cannot edit that app — check `SB_TOKEN`, and that the app belongs to the organization you named |
|
|
398
|
+
|
|
399
|
+
Each keeps the server's own sentence in `(server: …)` and adds the next action. A
|
|
400
|
+
code the tool has not been taught is printed in the server's words rather than a
|
|
401
|
+
shrug.
|
|
402
|
+
|
|
403
|
+
---
|
|
404
|
+
|
|
405
|
+
## What it deliberately does not do
|
|
406
|
+
|
|
407
|
+
Stated so you can plan around it rather than discover it.
|
|
408
|
+
|
|
409
|
+
- **It does not create the app, the version, or the install.** `sb init` makes no
|
|
410
|
+
network calls. Those steps are yours, by hand or by your own script; the CLI
|
|
411
|
+
starts being useful once those ids exist.
|
|
412
|
+
- **It does not write `sb.json`**, for the same reason.
|
|
413
|
+
- **There is no `sb login`.** `SB_TOKEN` lives in your environment, and the tool
|
|
414
|
+
never stores a credential anywhere.
|
|
415
|
+
- **`sb dev` is not hot reload**, and no future version of it can be while an
|
|
416
|
+
island's code is served from the platform's object store.
|
|
417
|
+
- **`sb deploy` is not atomic**, deliberately.
|
|
418
|
+
- **It is not on npm yet.**
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
## Troubleshooting
|
|
423
|
+
|
|
424
|
+
| Symptom | Cause | Fix |
|
|
425
|
+
| --- | --- | --- |
|
|
426
|
+
| `SB_TOKEN is not set` | `dev`/`deploy` need an org token | `export SB_TOKEN=…`, or prefix the command |
|
|
427
|
+
| `No sb.json here.` | Run from the wrong directory | `cd` to the folder holding `sb.json` |
|
|
428
|
+
| `sb.json is missing "versionId".` | A required key is absent or empty | Add all five required keys |
|
|
429
|
+
| `unknown command: …` | Typo, or a stale `dist/` | `npm run build --workspace cli` |
|
|
430
|
+
| `--port must be a number` | `--port` got a non-positive or non-numeric value | Pass a positive integer |
|
|
431
|
+
| Uploads refused with `not_draft` | The version left draft; approval pins its payload | Create a new draft version and point `sb.json` at it |
|
|
432
|
+
| 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 |
|
|
433
|
+
| `--submit` refused for loopback URLs | `version.embedUrl` / `version.redirectUri` still point at localhost | Set public `https` URLs, `sb deploy` again, then submit |
|
|
434
|
+
| The island changed and the page did not | `sb dev` is not hot reload | Refresh the page |
|
|
435
|
+
| `sb` reports a flag this page does not list | You are running an older `dist/` | Rebuild |
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
## Working on the CLI itself
|
|
41
440
|
|
|
42
441
|
```bash
|
|
43
442
|
npm run typecheck --prefix cli # tsc over bin, src AND tests
|
|
@@ -45,5 +444,19 @@ npm test --prefix cli # builds first, then vitest
|
|
|
45
444
|
```
|
|
46
445
|
|
|
47
446
|
`npm test` builds before it runs, on purpose: the unit suites import `src/`, but
|
|
48
|
-
every test that spawns the command runs `dist/`, so what is proved is what
|
|
49
|
-
|
|
447
|
+
every test that spawns the command runs `dist/`, so what is proved is what ships.
|
|
448
|
+
|
|
449
|
+
Two suites keep the documentation honest rather than trusting it:
|
|
450
|
+
|
|
451
|
+
- `tests/docs.test.ts` extracts the commands and flags from the served
|
|
452
|
+
`/cli-docs` page's own bytes and executes them against the built binary.
|
|
453
|
+
- `tests/readme.test.ts` does the same for **this file** and for
|
|
454
|
+
`README.vi.md`, and additionally holds the two READMEs to each other — same
|
|
455
|
+
commands, same flags, same environment variables, same `sb.json` keys, same
|
|
456
|
+
deploy order. A translation that drifts fails the build.
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## License
|
|
461
|
+
|
|
462
|
+
[MIT](./LICENSE) © Store Builder
|
package/README.vi.md
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
# @sbuilder/cli
|
|
2
|
+
|
|
3
|
+
**`sb`** — tạo khung, chạy và triển khai một app cho nền tảng **Store Builder**.
|
|
4
|
+
|
|
5
|
+
> 🇬🇧 English version: [**README.md**](./README.md)
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
sb init [tên] [--port 3000] tạo khung một app chạy được, đăng ký được, và mở
|
|
9
|
+
ngay trong trang quản trị của merchant
|
|
10
|
+
sb dev tải code của một island lên bản DRAFT mỗi lần bạn
|
|
11
|
+
lưu file. Đọc sb.json; cần SB_TOKEN.
|
|
12
|
+
sb deploy [--submit] đẩy toàn bộ payload của version theo đúng thứ tự
|
|
13
|
+
phụ thuộc. --submit thì gửi luôn đi duyệt.
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Cần Node 20 trở lên. Viết bằng TypeScript, **publish ở dạng đã biên dịch** — bản
|
|
17
|
+
cài về không có dependency nào và không phải build gì cả.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Mục lục
|
|
22
|
+
|
|
23
|
+
- [Nó là gì, và không phải là gì](#nó-là-gì-và-không-phải-là-gì)
|
|
24
|
+
- [Cài đặt](#cài-đặt)
|
|
25
|
+
- [Đường đi năm phút](#đường-đi-năm-phút)
|
|
26
|
+
- [`sb init`](#sb-init--tạo-khung-một-app-chạy-được)
|
|
27
|
+
- [`sb.json`](#sbjson--file-mà-dev-và-deploy-đọc)
|
|
28
|
+
- [`sb dev`](#sb-dev--lưu-tải-lên-refresh)
|
|
29
|
+
- [`sb deploy`](#sb-deploy--toàn-bộ-payload-theo-thứ-tự-phụ-thuộc)
|
|
30
|
+
- [Biến môi trường](#biến-môi-trường)
|
|
31
|
+
- [Các từ chối, và ý nghĩa của chúng](#các-từ-chối-và-ý-nghĩa-của-chúng)
|
|
32
|
+
- [Những gì nó cố tình KHÔNG làm](#những-gì-nó-cố-tình-không-làm)
|
|
33
|
+
- [Xử lý sự cố](#xử-lý-sự-cố)
|
|
34
|
+
- [Phát triển chính CLI này](#phát-triển-chính-cli-này)
|
|
35
|
+
- [Giấy phép](#giấy-phép)
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Nó là gì, và không phải là gì
|
|
40
|
+
|
|
41
|
+
`sb` là **một lối đi nhanh hơn qua cùng một vùng đất, không phải một vùng đất
|
|
42
|
+
khác.** Mọi thứ nó làm đều là một HTTP request mà bạn hoàn toàn có thể tự gửi
|
|
43
|
+
bằng `curl`. Không có gì trên nền tảng này chỉ tiếp cận được qua CLI, và CLI
|
|
44
|
+
không giấu bạn request nào cả.
|
|
45
|
+
|
|
46
|
+
Cái nó bỏ bớt cho bạn là phần cơ học: viết bộ khung app đã biết nói OAuth, đi tìm
|
|
47
|
+
endpoint upload island sau mỗi lần lưu file, và đẩy payload của một version qua
|
|
48
|
+
năm cánh cửa riêng biệt theo đúng một thứ tự mà nền tảng chấp nhận.
|
|
49
|
+
|
|
50
|
+
Tài liệu tham chiếu đầy đủ được chính bản triển khai Store Builder của bạn phục
|
|
51
|
+
vụ tại **`/cli-docs`**, cùng với **`/app-docs`** (xây dựng app) và
|
|
52
|
+
**`/block-docs`** (blocks và islands). Trang đó là tài liệu *chạy được* — các
|
|
53
|
+
lệnh trên trang được trích ra từ chính bytes của nó và chạy thật với binary trong
|
|
54
|
+
CI, nên nó không thể mô tả một flag mà CLI từ chối. File README này bị ràng buộc
|
|
55
|
+
bởi cùng một tiêu chuẩn, qua `tests/readme.test.ts`.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Cài đặt
|
|
60
|
+
|
|
61
|
+
**`@sbuilder/cli` chưa được đưa lên npm.** Workflow publish đã hoàn chỉnh
|
|
62
|
+
(`.github/workflows/publish-cli.yml`) và đang chờ một npm credential, nên `npx`
|
|
63
|
+
sẽ không tìm thấy nó. Hãy chạy từ một bản checkout:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/vuluu2k/web_builder.git
|
|
67
|
+
cd web_builder
|
|
68
|
+
npm ci
|
|
69
|
+
npm run build --workspace cli
|
|
70
|
+
node cli/dist/bin/sb.js --help
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Để có lệnh `sb` nằm sẵn trong `PATH` thay vì phải gõ cả đường dẫn mỗi lần:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npm run build --workspace cli
|
|
77
|
+
cd cli && npm link
|
|
78
|
+
sb --help
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Từ đây trở xuống đều viết là `sb`; `node cli/dist/bin/sb.js` luôn là cùng một
|
|
82
|
+
thứ. Nếu `sb` báo một lệnh hoặc một flag mà trang này không mô tả, hãy build lại
|
|
83
|
+
— bạn đang chạy một `dist/` cũ hơn phần source nằm cạnh nó.
|
|
84
|
+
|
|
85
|
+
Bước build là dependency duy nhất của CLI. **Bộ khung** mà `sb init` sinh ra thì
|
|
86
|
+
cố tình ngược lại và sẽ giữ như vậy: không dependency, không build, ESM thuần —
|
|
87
|
+
vì đó mới là code bạn thật sự chạy.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Đường đi năm phút
|
|
92
|
+
|
|
93
|
+
Toàn bộ vòng lặp, từ đầu đến cuối. Bước 2 và 3 là phần của bạn — xem `/app-docs`
|
|
94
|
+
— còn lại mỗi bước là một câu lệnh.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# 1. Một app chạy được trên máy bạn
|
|
98
|
+
sb init my-app --port 4000
|
|
99
|
+
cd my-app
|
|
100
|
+
cp .env.example .env # điền SB_CLIENT_ID và SB_CLIENT_SECRET
|
|
101
|
+
npm start
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
2. **Tạo app** trong tổ chức của bạn, ghi lại `clientId` / `clientSecret` mà nền
|
|
105
|
+
tảng trả về. Secret chỉ hiện **một lần duy nhất**.
|
|
106
|
+
3. **Tạo một version DRAFT** trỏ vào URL local — embed URL
|
|
107
|
+
`http://localhost:4000/embed`, redirect URI
|
|
108
|
+
`http://localhost:4000/oauth/callback`. **Không cần tunnel:** một version
|
|
109
|
+
draft được phép trỏ vào `http://localhost` và một install sandbox được phép
|
|
110
|
+
nhúng nó, nên toàn bộ vòng lặp phát triển chạy ngay trên máy bạn. Tunnel chỉ
|
|
111
|
+
cần khi bạn muốn kiểm tra các URL public trước lúc gửi duyệt.
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
# 4. Viết sb.json bằng các id vừa có (xem bên dưới), rồi:
|
|
115
|
+
SB_TOKEN=<token của bạn> sb dev # sửa island, lưu, refresh
|
|
116
|
+
|
|
117
|
+
# 5. Đẩy toàn bộ payload, và gửi đi duyệt
|
|
118
|
+
SB_TOKEN=<token của bạn> sb deploy --submit
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## `sb init` — tạo khung một app chạy được
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
sb init my-app
|
|
127
|
+
sb init my-app --port 4000
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Ghi một app chạy được vào `./my-app` và in ra việc cần làm tiếp theo. Nó **không
|
|
131
|
+
gọi mạng một lần nào** — đây là công cụ tạo khung, không phải bước đăng ký. Việc
|
|
132
|
+
tạo app và tạo version vẫn là của bạn.
|
|
133
|
+
|
|
134
|
+
### Nó ghi ra những gì
|
|
135
|
+
|
|
136
|
+
Năm file, và không gì khác:
|
|
137
|
+
|
|
138
|
+
| File | Là gì |
|
|
139
|
+
| --- | --- |
|
|
140
|
+
| `server.js` | Toàn bộ app: phần đổi token ở `/oauth/callback` và trang `/embed` được nhúng, gói trong một file, không dependency |
|
|
141
|
+
| `package.json` | `npm start` chạy `server.js`. **Không dependencies, không devDependencies** — lần `npm install` đầu tiên không nên là thứ đầu tiên hỏng |
|
|
142
|
+
| `.env.example` | `SB_CLIENT_ID`, `SB_CLIENT_SECRET`, `SB_API`, `SB_REDIRECT_URI` và `PORT` |
|
|
143
|
+
| `README.md` | Đúng những bước tiếp theo mà lệnh đã in, phòng khi terminal đã cuộn mất |
|
|
144
|
+
| `.gitignore` | `node_modules` và `.env` |
|
|
145
|
+
|
|
146
|
+
Cố tình **không có blocks, không có islands, không có app data**. Mỗi thứ đó là
|
|
147
|
+
một tính năng thật với hướng dẫn riêng, và không thứ nào cần thiết để lần đầu
|
|
148
|
+
nhìn thấy app hiện ra trong trang quản trị của một merchant.
|
|
149
|
+
|
|
150
|
+
### Về cái tên
|
|
151
|
+
|
|
152
|
+
Tham số được chuẩn hoá thành thứ npm chấp nhận làm tên package: viết thường, mọi
|
|
153
|
+
chuỗi ký tự ngoài `a-z 0-9 . _ -` bị gộp thành một dấu `-`, và cắt bỏ `-_.` ở đầu
|
|
154
|
+
và cuối.
|
|
155
|
+
|
|
156
|
+
| Bạn gõ | Bạn nhận được |
|
|
157
|
+
| --- | --- |
|
|
158
|
+
| `sb init my-app` | `./my-app` |
|
|
159
|
+
| `sb init "My App!"` | `./my-app` |
|
|
160
|
+
| `sb init` | `./my-app` |
|
|
161
|
+
|
|
162
|
+
### Nó từ chối những gì
|
|
163
|
+
|
|
164
|
+
**Không bao giờ ghi đè, và không bao giờ ghi nửa vời.** Toàn bộ tập file được đối
|
|
165
|
+
chiếu với thư mục đích *trước khi* ghi bất cứ thứ gì; chỉ cần một file trùng là
|
|
166
|
+
từ chối tất cả và nêu tên thứ bị trùng:
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
/path/to/my-app already contains package.json, server.js — refusing to overwrite.
|
|
170
|
+
Pick an empty directory, or move those files aside.
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Một bộ khung dở dang còn tệ hơn là không có, vì nó để lại một thư mục *trông như*
|
|
174
|
+
đã khởi tạo mà thực ra chưa. Còn một thư mục **đã tồn tại sẵn** thì hoàn toàn ổn
|
|
175
|
+
— chạy `sb init` trong một bản `git clone` mới tinh là chuyện bình thường, từ
|
|
176
|
+
chối chỉ vì có `.git` là từ chối đúng trường hợp phổ biến nhất.
|
|
177
|
+
|
|
178
|
+
### Flags
|
|
179
|
+
|
|
180
|
+
| Flag | Mặc định | Tác dụng |
|
|
181
|
+
| --- | --- | --- |
|
|
182
|
+
| `--port <n>` | `3000` | Cổng được ghi vào `.env.example`, vào README sinh ra, và vào mọi URL mà lệnh in ra. Giá trị không phải số dương sẽ bị từ chối với `--port must be a number` |
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## `sb.json` — file mà `dev` và `deploy` đọc
|
|
187
|
+
|
|
188
|
+
Cả `sb dev` lẫn `sb deploy` đều đọc `sb.json` từ **thư mục hiện tại**.
|
|
189
|
+
|
|
190
|
+
**`sb init` không ghi file này, và không thể ghi được**: ba trong năm trường bắt
|
|
191
|
+
buộc là các id do nền tảng sinh ra khi bạn tạo app và bản draft của nó — những
|
|
192
|
+
việc chưa xảy ra ở thời điểm `init`. Hãy tự viết một lần khi đã có chúng:
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"orgId": "org_yourorg",
|
|
197
|
+
"appId": "app_1a2b3c4d",
|
|
198
|
+
"versionId": "ver_5e6f7a8b",
|
|
199
|
+
"island": "countdown",
|
|
200
|
+
"entry": "islands/countdown.js"
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Bắt buộc — thiếu một trong năm là cả hai lệnh đều từ chối
|
|
205
|
+
|
|
206
|
+
| Khoá | Là gì |
|
|
207
|
+
| --- | --- |
|
|
208
|
+
| `orgId` | Tổ chức sở hữu app |
|
|
209
|
+
| `appId` | App |
|
|
210
|
+
| `versionId` | Bản **draft** đang được sửa |
|
|
211
|
+
| `island` | Island mà `sb dev` tải code lên |
|
|
212
|
+
| `entry` | File mà `sb dev` theo dõi, tính tương đối với `sb.json` |
|
|
213
|
+
|
|
214
|
+
Thiếu khoá nào sẽ bị gọi tên khoá đó — `sb.json is missing "versionId".` — và
|
|
215
|
+
thiếu hẳn file thì bị từ chối kèm danh sách những gì cần có. `sb deploy` cũng đòi
|
|
216
|
+
đủ năm khoá dù công việc của nó được mô tả bởi các khoá tuỳ chọn bên dưới, nên
|
|
217
|
+
hãy điền đủ ngay cả khi bạn chỉ deploy blocks.
|
|
218
|
+
|
|
219
|
+
### Tuỳ chọn — mỗi khoá tìm thấy trở thành một bước deploy
|
|
220
|
+
|
|
221
|
+
| Khoá | Kiểu | `sb deploy` làm gì với nó |
|
|
222
|
+
| --- | --- | --- |
|
|
223
|
+
| `version` | object | `PUT` làm các trường của version — `scopes`, `embedUrl`, `redirectUri` và phần còn lại |
|
|
224
|
+
| `blocks` | đường dẫn | Manifest của block, `PUT` làm body của `.../blocks` |
|
|
225
|
+
| `islands` | mảng `{name, entry}` | Khai báo mọi `name`, rồi tải lên mọi `entry` |
|
|
226
|
+
|
|
227
|
+
Một `sb.json` chỉ có năm khoá bắt buộc vẫn hợp lệ: `sb dev` chạy được, còn
|
|
228
|
+
`sb deploy` sẽ không tìm thấy bước nào để chạy.
|
|
229
|
+
|
|
230
|
+
Một file đầy đủ hơn:
|
|
231
|
+
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"orgId": "org_yourorg",
|
|
235
|
+
"appId": "app_1a2b3c4d",
|
|
236
|
+
"versionId": "ver_5e6f7a8b",
|
|
237
|
+
"island": "countdown",
|
|
238
|
+
"entry": "islands/countdown.js",
|
|
239
|
+
"version": {
|
|
240
|
+
"scopes": ["products.read", "orders.read"],
|
|
241
|
+
"embedUrl": "https://app.example.com/embed",
|
|
242
|
+
"redirectUri": "https://app.example.com/oauth/callback"
|
|
243
|
+
},
|
|
244
|
+
"blocks": "blocks.json",
|
|
245
|
+
"islands": [
|
|
246
|
+
{ "name": "countdown", "entry": "islands/countdown.js" },
|
|
247
|
+
{ "name": "stock-bar", "entry": "islands/stock-bar.js" }
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## `sb dev` — lưu, tải lên, refresh
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
SB_TOKEN=<token của bạn> sb dev
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Theo dõi file `entry` khai trong `sb.json` và tải nó lên `island` của version mỗi
|
|
261
|
+
lần bạn lưu. Nó tải lên ngay một lần lúc khởi động chứ không chờ lần lưu đầu
|
|
262
|
+
tiên, rồi chạy cho tới khi bạn ngắt.
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
watching islands/countdown.js — save it and this uploads to version ver_5e6f7a8b.
|
|
266
|
+
This is not hot reload: after each upload, refresh the page.
|
|
267
|
+
uploaded countdown — refresh the page to see it
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Đây không phải hot reload, và nó sẽ không bao giờ tự nhận như vậy.** Code của
|
|
271
|
+
một island trên trang đã render luôn đến từ object store của nền tảng, nên không
|
|
272
|
+
thể trỏ một trang vào dev server ở máy bạn, và cũng không có chuyện vá code trực
|
|
273
|
+
tiếp. Cái mà lệnh này bỏ đi là công đoạn đi tìm endpoint: bạn lưu, nó tải lên,
|
|
274
|
+
**bạn refresh trang.**
|
|
275
|
+
|
|
276
|
+
**Nó tải lên một bản draft.** Một version đã rời trạng thái draft sẽ từ chối ghi
|
|
277
|
+
— việc duyệt ghim chặt payload, và một island bị tráo sau khi duyệt là code chạy
|
|
278
|
+
trên trang của merchant mà không ai nhìn qua.
|
|
279
|
+
|
|
280
|
+
`sb dev` không nhận flag nào. Nó tải lên **một** island — cái được đặt tên trong
|
|
281
|
+
`sb.json`. Muốn đẩy nhiều island một lúc thì dùng `sb deploy` với mảng `islands`.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## `sb deploy` — toàn bộ payload, theo thứ tự phụ thuộc
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
SB_TOKEN=<token của bạn> sb deploy
|
|
289
|
+
SB_TOKEN=<token của bạn> sb deploy --submit
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Chạy mọi bước mà `sb.json` mô tả, theo đúng thứ tự này:
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
version fields PUT /api/orgs/{orgId}/apps/{appId}/versions/{versionId}
|
|
296
|
+
blocks PUT .../blocks
|
|
297
|
+
island declarations PUT .../islands
|
|
298
|
+
island "<name>" POST .../islands/module?name=<name> (mỗi island một lần)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**Thứ tự chính là thiết kế.** Phần khai báo đi trước các module lấp vào chúng, vì
|
|
302
|
+
code tải lên cho một island mà version chưa khai báo sẽ bị từ chối
|
|
303
|
+
(`island_not_found`), trong khi một khai báo chưa có code là trạng thái nền tảng
|
|
304
|
+
hoàn toàn chấp nhận. Nhờ vậy một lần dừng giữa chừng để lại đúng *hình dạng* thứ
|
|
305
|
+
bạn định làm, chứ không phải mấy đống bytes mồ côi.
|
|
306
|
+
|
|
307
|
+
### Nó không nguyên tử, và nó không cần phải thế
|
|
308
|
+
|
|
309
|
+
Payload của một version được ghi qua năm cánh cửa, không lời gọi đơn lẻ nào chở
|
|
310
|
+
hết được; một công cụ xâu chuỗi chúng lại rồi tuyên bố kết quả là nguyên tử thì
|
|
311
|
+
đang hứa hẹn đúng ở chỗ mà bạn sẽ tin vào lời hứa đó. Mà nó không cần lời hứa ấy:
|
|
312
|
+
**một bản draft được thiết kế để có thể không nhất quán giữa các lần ghi.** Cả
|
|
313
|
+
hai bước kiểm tra tính nhất quán đều chạy lúc submit chứ không phải ở từng lệnh
|
|
314
|
+
ghi, nên một lần deploy dở dang cho ra một version *chưa xong* chứ không phải một
|
|
315
|
+
version hỏng.
|
|
316
|
+
|
|
317
|
+
Đổi lại, thứ lệnh này nợ bạn là nói rõ nó dừng ở đâu:
|
|
318
|
+
|
|
319
|
+
```
|
|
320
|
+
Stopped at: island "countdown"
|
|
321
|
+
|
|
322
|
+
This version is in review or already approved, so its code is frozen.
|
|
323
|
+
Create a new draft version and point sb dev at that one.
|
|
324
|
+
(server: version has left draft)
|
|
325
|
+
|
|
326
|
+
Already applied: version fields, blocks, island declarations
|
|
327
|
+
|
|
328
|
+
This left the version UNFINISHED, not broken — a draft is allowed to be
|
|
329
|
+
partway through, and it simply cannot be submitted until the rest lands.
|
|
330
|
+
Fix the cause and run sb deploy again; every step is safe to repeat.
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Mọi lệnh ghi đều idempotent, nên "chạy tiếp" đơn giản là chạy lại.
|
|
334
|
+
|
|
335
|
+
### Flags
|
|
336
|
+
|
|
337
|
+
| Flag | Tác dụng |
|
|
338
|
+
| --- | --- |
|
|
339
|
+
| `--submit` | Sau khi deploy thành công thì `POST .../submit` — cổng duyệt |
|
|
340
|
+
|
|
341
|
+
`--submit` trước tiên soi khối `version` trong `sb.json` của bạn xem còn URL nào
|
|
342
|
+
trỏ về máy bạn không, và từ chối **trước khi** gọi server:
|
|
343
|
+
|
|
344
|
+
```
|
|
345
|
+
This version still points at your own machine: embedUrl (http://localhost:3000/embed).
|
|
346
|
+
Review needs public https URLs — the loopback allowance covers development only.
|
|
347
|
+
Update the version to its real addresses, deploy again, then submit.
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Kiểm tra đó là **phép lịch sự, không bao giờ là thẩm quyền.** Server mới chạy bản
|
|
351
|
+
kiểm tra thật, và nếu hai bên có mâu thuẫn thì server thắng; cái này chỉ tồn tại
|
|
352
|
+
để hỏng sớm hơn, với nhiều chỗ giải thích hơn một status code.
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## Biến môi trường
|
|
357
|
+
|
|
358
|
+
Hai biến do chính CLI đọc:
|
|
359
|
+
|
|
360
|
+
| Biến | Lệnh cần nó | Mặc định |
|
|
361
|
+
| --- | --- | --- |
|
|
362
|
+
| `SB_TOKEN` | `sb dev`, `sb deploy` | không có — thiếu là cả hai dừng ngay |
|
|
363
|
+
| `SB_API` | `sb dev`, `sb deploy` | `http://localhost:8080` |
|
|
364
|
+
|
|
365
|
+
`SB_TOKEN` là token của **tổ chức sở hữu app** — đúng cái user access token bạn
|
|
366
|
+
sẽ đặt vào header `Authorization: Bearer` khi gọi các route theo tổ chức. Nó
|
|
367
|
+
**không phải** app token dạng `wba_`; loại đó thuộc về một install, và một install
|
|
368
|
+
không thể sửa chính cái app mà nó là install của.
|
|
369
|
+
|
|
370
|
+
Ba biến còn lại do app mà `sb init` sinh ra tự đọc, từ `.env` của chính nó:
|
|
371
|
+
|
|
372
|
+
| Biến | Ai đọc | Là gì |
|
|
373
|
+
| --- | --- | --- |
|
|
374
|
+
| `SB_CLIENT_ID` | `server.js` được sinh ra | Hiện lên khi bạn tạo app |
|
|
375
|
+
| `SB_CLIENT_SECRET` | `server.js` được sinh ra | Chỉ hiện **một lần** lúc tạo. Mất thì xoay vòng lại, đừng đi tìm |
|
|
376
|
+
| `SB_REDIRECT_URI` | `server.js` được sinh ra | Phải khớp từng ký tự với redirect URI trên version của bạn |
|
|
377
|
+
|
|
378
|
+
App sinh ra cũng đọc `SB_API` và `PORT`.
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## Các từ chối, và ý nghĩa của chúng
|
|
383
|
+
|
|
384
|
+
Mọi lệnh thoát `0` khi thành công và `1` khi từ chối có lý do giải thích được.
|
|
385
|
+
Ngoài hai giá trị đó là bug của chính công cụ, và khi đó nó in stack trace, vì
|
|
386
|
+
một công cụ tạo khung mà nuốt lỗi của chính mình là công cụ không ai báo lỗi
|
|
387
|
+
được.
|
|
388
|
+
|
|
389
|
+
Các mã lỗi từ server mà CLI dịch lại thay vì bê nguyên văn:
|
|
390
|
+
|
|
391
|
+
| Mã từ server | `sb` nói gì thay vào đó |
|
|
392
|
+
| --- | --- |
|
|
393
|
+
| `not_draft` | Version này đang duyệt hoặc đã được duyệt nên code bị đóng băng — tạo bản draft mới và trỏ vào đó |
|
|
394
|
+
| `island_not_found` | Version này không khai báo island tên đó; khai báo trước đã |
|
|
395
|
+
| `island_module_not_text` | File đó không phải text. Một island module là JavaScript |
|
|
396
|
+
| `island_module_too_large` | File đó quá lớn để tải lên làm island module |
|
|
397
|
+
| `unauthorized` | Chưa đăng nhập. Đặt `SB_TOKEN` là token của tổ chức sở hữu app này |
|
|
398
|
+
| mọi `401`/`403` khác | Token này không sửa được app đó — kiểm tra lại `SB_TOKEN`, và kiểm tra app có thuộc tổ chức bạn khai không |
|
|
399
|
+
|
|
400
|
+
Mỗi dòng đều giữ nguyên câu chữ của server trong `(server: …)` rồi thêm việc cần
|
|
401
|
+
làm tiếp. Một mã lỗi công cụ chưa được dạy sẽ được in bằng chính lời của server,
|
|
402
|
+
chứ không phải một cái nhún vai.
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## Những gì nó cố tình KHÔNG làm
|
|
407
|
+
|
|
408
|
+
Nói ra để bạn tính đường trước, thay vì tự phát hiện giữa chừng.
|
|
409
|
+
|
|
410
|
+
- **Nó không tạo app, không tạo version, không tạo install.** `sb init` không gọi
|
|
411
|
+
mạng lần nào. Những bước đó là của bạn, làm tay hoặc bằng script của bạn; CLI
|
|
412
|
+
chỉ bắt đầu có ích khi đã có các id ấy.
|
|
413
|
+
- **Nó không ghi `sb.json`**, cùng lý do trên.
|
|
414
|
+
- **Không có `sb login`.** `SB_TOKEN` nằm trong môi trường của bạn, và công cụ
|
|
415
|
+
không lưu credential ở bất cứ đâu.
|
|
416
|
+
- **`sb dev` không phải hot reload**, và không phiên bản tương lai nào của nó có
|
|
417
|
+
thể là hot reload chừng nào code island còn được phục vụ từ object store của
|
|
418
|
+
nền tảng.
|
|
419
|
+
- **`sb deploy` không nguyên tử**, một cách có chủ đích.
|
|
420
|
+
- **Chưa có trên npm.**
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## Xử lý sự cố
|
|
425
|
+
|
|
426
|
+
| Hiện tượng | Nguyên nhân | Cách xử lý |
|
|
427
|
+
| --- | --- | --- |
|
|
428
|
+
| `SB_TOKEN is not set` | `dev`/`deploy` cần token của tổ chức | `export SB_TOKEN=…`, hoặc đặt ngay trước lệnh |
|
|
429
|
+
| `No sb.json here.` | Chạy sai thư mục | `cd` về đúng thư mục chứa `sb.json` |
|
|
430
|
+
| `sb.json is missing "versionId".` | Thiếu hoặc để rỗng một khoá bắt buộc | Điền đủ cả năm khoá bắt buộc |
|
|
431
|
+
| `unknown command: …` | Gõ nhầm, hoặc `dist/` đã cũ | `npm run build --workspace cli` |
|
|
432
|
+
| `--port must be a number` | `--port` nhận giá trị không phải số dương | Truyền một số nguyên dương |
|
|
433
|
+
| Bị từ chối với `not_draft` | Version đã rời draft; việc duyệt ghim payload lại | Tạo version draft mới và trỏ `sb.json` vào đó |
|
|
434
|
+
| Bị từ chối với `island_not_found` | Version chưa khai báo island đó | Khai báo trước — `sb deploy` với mảng `islands` làm đúng thứ tự này |
|
|
435
|
+
| `--submit` bị từ chối vì URL loopback | `version.embedUrl` / `version.redirectUri` vẫn trỏ localhost | Đặt URL `https` public, `sb deploy` lại, rồi submit |
|
|
436
|
+
| Island đã đổi mà trang không đổi | `sb dev` không phải hot reload | Refresh trang |
|
|
437
|
+
| `sb` báo một flag trang này không liệt kê | Bạn đang chạy `dist/` cũ | Build lại |
|
|
438
|
+
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
## Phát triển chính CLI này
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
npm run typecheck --prefix cli # tsc trên bin, src VÀ tests
|
|
445
|
+
npm test --prefix cli # build trước, rồi vitest
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
`npm test` build trước khi chạy, một cách có chủ đích: các suite unit import
|
|
449
|
+
`src/`, còn mọi test spawn tiến trình đều chạy `dist/`, nên thứ được chứng minh
|
|
450
|
+
đúng là thứ được ship.
|
|
451
|
+
|
|
452
|
+
Hai bộ test giữ cho tài liệu trung thực thay vì tin vào nó:
|
|
453
|
+
|
|
454
|
+
- `tests/docs.test.ts` trích các lệnh và flag từ chính bytes của trang
|
|
455
|
+
`/cli-docs` rồi chạy chúng với binary đã build.
|
|
456
|
+
- `tests/readme.test.ts` làm điều tương tự cho **file này** và cho `README.md`,
|
|
457
|
+
đồng thời ràng hai bản README vào nhau — cùng lệnh, cùng flag, cùng biến môi
|
|
458
|
+
trường, cùng khoá `sb.json`, cùng thứ tự deploy. Một bản dịch trôi lệch sẽ làm
|
|
459
|
+
hỏng build.
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
## Giấy phép
|
|
464
|
+
|
|
465
|
+
[MIT](./LICENSE) © Store Builder
|
package/dist/bin/{wb.js → sb.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* `
|
|
3
|
+
* `sb` — the Store Builder app CLI.
|
|
4
4
|
*
|
|
5
5
|
* Dispatch only: every command's behaviour lives in src/ so it can be tested
|
|
6
6
|
* without spawning a process. This file's whole job is to turn argv into a call
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
import { init, nextSteps, InitError } from '../src/init.js';
|
|
10
10
|
import { readConfig, watchAndUpload, DevError } from '../src/dev.js';
|
|
11
11
|
import { deploy, submit, DeployStopped } from '../src/deploy.js';
|
|
12
|
-
const USAGE = `
|
|
12
|
+
const USAGE = `sb — build an app for Store Builder
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
sb init [name] [--port 3000] scaffold an app that runs, registers, and opens
|
|
15
15
|
inside a merchant's admin
|
|
16
|
-
|
|
16
|
+
sb dev upload an island's code to your DRAFT version
|
|
17
17
|
every time you save it (not hot reload — you
|
|
18
|
-
refresh). Reads
|
|
19
|
-
|
|
18
|
+
refresh). Reads sb.json; needs SB_TOKEN.
|
|
19
|
+
sb deploy [--submit] push the version's payload in dependency order.
|
|
20
20
|
Not one write: if it stops it says where, and
|
|
21
21
|
running it again is safe. --submit then sends
|
|
22
22
|
it for review.
|
|
@@ -52,10 +52,10 @@ async function main(argv) {
|
|
|
52
52
|
if (cmd === 'dev') {
|
|
53
53
|
try {
|
|
54
54
|
const cfg = await readConfig();
|
|
55
|
-
const api = process.env.
|
|
56
|
-
const token = process.env.
|
|
55
|
+
const api = process.env.SB_API ?? 'http://localhost:8080';
|
|
56
|
+
const token = process.env.SB_TOKEN ?? '';
|
|
57
57
|
if (!token) {
|
|
58
|
-
console.error('
|
|
58
|
+
console.error('SB_TOKEN is not set — it needs a token for the organization that owns this app.');
|
|
59
59
|
return 1;
|
|
60
60
|
}
|
|
61
61
|
const w = watchAndUpload({ ...cfg, api, token });
|
|
@@ -77,10 +77,10 @@ async function main(argv) {
|
|
|
77
77
|
if (cmd === 'deploy') {
|
|
78
78
|
try {
|
|
79
79
|
const cfg = await readConfig();
|
|
80
|
-
const api = process.env.
|
|
81
|
-
const token = process.env.
|
|
80
|
+
const api = process.env.SB_API ?? 'http://localhost:8080';
|
|
81
|
+
const token = process.env.SB_TOKEN ?? '';
|
|
82
82
|
if (!token) {
|
|
83
|
-
console.error('
|
|
83
|
+
console.error('SB_TOKEN is not set — it needs a token for the organization that owns this app.');
|
|
84
84
|
return 1;
|
|
85
85
|
}
|
|
86
86
|
console.log(`deploying to version ${cfg.versionId}:`);
|
|
@@ -126,4 +126,4 @@ async function main(argv) {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
process.exitCode = await main(process.argv.slice(2));
|
|
129
|
-
//# sourceMappingURL=
|
|
129
|
+
//# sourceMappingURL=sb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"sb.js","sourceRoot":"","sources":["../../bin/sb.ts"],"names":[],"mappings":"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"}
|
package/dist/src/deploy.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises';
|
|
|
2
2
|
import { resolve, dirname } from 'node:path';
|
|
3
3
|
import { explain, DevError, messageOf } from './dev.js';
|
|
4
4
|
/**
|
|
5
|
-
* `
|
|
5
|
+
* `sb deploy` — push a version's payload, in dependency order.
|
|
6
6
|
*
|
|
7
7
|
* # IT IS NOT ATOMIC, AND IT MUST NOT SAY IT IS
|
|
8
8
|
*
|
|
@@ -159,7 +159,7 @@ export class DeployStopped extends Error {
|
|
|
159
159
|
'',
|
|
160
160
|
'This left the version UNFINISHED, not broken — a draft is allowed to be',
|
|
161
161
|
'partway through, and it simply cannot be submitted until the rest lands.',
|
|
162
|
-
'Fix the cause and run
|
|
162
|
+
'Fix the cause and run sb deploy again; every step is safe to repeat.',
|
|
163
163
|
];
|
|
164
164
|
super(lines.join('\n'));
|
|
165
165
|
this.step = step;
|
|
@@ -199,7 +199,7 @@ export function loopbackURLs(version = {}) {
|
|
|
199
199
|
out.push(`redirectUri (${version.redirectUri})`);
|
|
200
200
|
return out;
|
|
201
201
|
}
|
|
202
|
-
/** `
|
|
202
|
+
/** `sb deploy --submit` — the coherence gate, walked into deliberately. */
|
|
203
203
|
export async function submit({ api, token, cfg }) {
|
|
204
204
|
const stillLocal = loopbackURLs(cfg.version);
|
|
205
205
|
if (stillLocal.length > 0) {
|
package/dist/src/dev.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readFile, stat } from 'node:fs/promises';
|
|
|
2
2
|
import { watch } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
/**
|
|
5
|
-
* `
|
|
5
|
+
* `sb dev` — save, upload, refresh.
|
|
6
6
|
*
|
|
7
7
|
* # IT IS NOT HOT RELOAD, AND IT MUST NEVER SAY IT IS
|
|
8
8
|
*
|
|
@@ -96,7 +96,7 @@ export function explain(status, body) {
|
|
|
96
96
|
switch (code) {
|
|
97
97
|
case 'not_draft':
|
|
98
98
|
return ('This version is in review or already approved, so its code is frozen.\n' +
|
|
99
|
-
'Create a new draft version and point
|
|
99
|
+
'Create a new draft version and point sb dev at that one.\n' +
|
|
100
100
|
`(server: ${message})`);
|
|
101
101
|
case 'island_not_found':
|
|
102
102
|
return ('This version does not declare an island by that name.\n' +
|
|
@@ -107,11 +107,11 @@ export function explain(status, body) {
|
|
|
107
107
|
case 'island_module_too_large':
|
|
108
108
|
return `That file is too large to upload as an island module.\n(server: ${message})`;
|
|
109
109
|
case 'unauthorized':
|
|
110
|
-
return 'Not signed in. Set
|
|
110
|
+
return 'Not signed in. Set SB_TOKEN to a token for the organization that owns this app.';
|
|
111
111
|
default:
|
|
112
112
|
if (status === 401 || status === 403) {
|
|
113
113
|
return ('Refused: this token cannot edit that app.\n' +
|
|
114
|
-
'Check
|
|
114
|
+
'Check SB_TOKEN, and that the app belongs to the organization you named.\n' +
|
|
115
115
|
`(server: ${message})`);
|
|
116
116
|
}
|
|
117
117
|
return message;
|
|
@@ -162,14 +162,14 @@ export function watchAndUpload(opts) {
|
|
|
162
162
|
send,
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
-
/** Reads
|
|
165
|
+
/** Reads sb.json beside the project, which is where `sb dev` gets its ids. */
|
|
166
166
|
export async function readConfig(dir = process.cwd()) {
|
|
167
|
-
const path = resolve(dir, '
|
|
167
|
+
const path = resolve(dir, 'sb.json');
|
|
168
168
|
try {
|
|
169
169
|
await stat(path);
|
|
170
170
|
}
|
|
171
171
|
catch {
|
|
172
|
-
throw new DevError('No
|
|
172
|
+
throw new DevError('No sb.json here. It needs orgId, appId, versionId, island and entry — the ids\n' +
|
|
173
173
|
'come from the app and the DRAFT version you created.');
|
|
174
174
|
}
|
|
175
175
|
// `as` and not a validator: the five checks below ARE the validation, and
|
|
@@ -177,7 +177,7 @@ export async function readConfig(dir = process.cwd()) {
|
|
|
177
177
|
const cfg = JSON.parse(await readFile(path, 'utf8'));
|
|
178
178
|
for (const key of ['orgId', 'appId', 'versionId', 'island', 'entry']) {
|
|
179
179
|
if (!cfg[key])
|
|
180
|
-
throw new DevError(`
|
|
180
|
+
throw new DevError(`sb.json is missing "${key}".`);
|
|
181
181
|
}
|
|
182
182
|
return cfg;
|
|
183
183
|
}
|
package/dist/src/init.js
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync } from 'node:fs';
|
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
4
|
import { files } from './scaffold.js';
|
|
5
5
|
/**
|
|
6
|
-
* `
|
|
6
|
+
* `sb init` — write the scaffold into a directory.
|
|
7
7
|
*
|
|
8
8
|
* # It never overwrites, and it never half-writes
|
|
9
9
|
*
|
|
@@ -39,7 +39,7 @@ export function plan({ name, dir, port = 3000 }) {
|
|
|
39
39
|
export async function init(opts = {}) {
|
|
40
40
|
const { pkgName, target, files: out } = plan(opts);
|
|
41
41
|
// An EXISTING directory is fine as long as it is empty of the things we would
|
|
42
|
-
// write — running `
|
|
42
|
+
// write — running `sb init` inside a fresh git clone is a normal thing to do,
|
|
43
43
|
// and refusing it because `.git` exists would be refusing the common case.
|
|
44
44
|
if (existsSync(target)) {
|
|
45
45
|
const existing = new Set(await readdir(target));
|
|
@@ -69,7 +69,7 @@ export function nextSteps({ name, port = 3000 }) {
|
|
|
69
69
|
'',
|
|
70
70
|
'Next:',
|
|
71
71
|
` cd ${name}`,
|
|
72
|
-
' cp .env.example .env # fill in
|
|
72
|
+
' cp .env.example .env # fill in SB_CLIENT_ID and SB_CLIENT_SECRET',
|
|
73
73
|
' npm start',
|
|
74
74
|
'',
|
|
75
75
|
`Your app runs at http://localhost:${port} — no tunnel needed. A draft version`,
|
package/dist/src/scaffold.js
CHANGED
|
@@ -43,14 +43,14 @@ function server() {
|
|
|
43
43
|
// Both come from the platform when you create the app. CLIENT_SECRET is shown
|
|
44
44
|
// ONCE, at creation; if you lose it, rotate it rather than hunting for it.
|
|
45
45
|
const PORT = Number(process.env.PORT ?? 3000);
|
|
46
|
-
const API = process.env.
|
|
47
|
-
const CLIENT_ID = process.env.
|
|
48
|
-
const CLIENT_SECRET = process.env.
|
|
46
|
+
const API = process.env.SB_API ?? 'http://localhost:8080';
|
|
47
|
+
const CLIENT_ID = process.env.SB_CLIENT_ID ?? '';
|
|
48
|
+
const CLIENT_SECRET = process.env.SB_CLIENT_SECRET ?? '';
|
|
49
49
|
|
|
50
50
|
// This must match the redirect URI registered on your VERSION exactly — the
|
|
51
51
|
// platform compares them character for character, and a mismatch is refused
|
|
52
52
|
// rather than guessed at.
|
|
53
|
-
const REDIRECT_URI = process.env.
|
|
53
|
+
const REDIRECT_URI = process.env.SB_REDIRECT_URI ?? \`http://localhost:\${PORT}/oauth/callback\`;
|
|
54
54
|
|
|
55
55
|
// Tokens live in memory, which is correct for a scaffold and wrong for
|
|
56
56
|
// production: a restart loses them and the merchant has to install again.
|
|
@@ -146,7 +146,7 @@ server.listen(PORT, () => {
|
|
|
146
146
|
console.log(\` oauth callback \${REDIRECT_URI}\`);
|
|
147
147
|
if (!CLIENT_ID || !CLIENT_SECRET) {
|
|
148
148
|
console.log('');
|
|
149
|
-
console.log('
|
|
149
|
+
console.log('SB_CLIENT_ID / SB_CLIENT_SECRET are not set — the install will fail at the token exchange.');
|
|
150
150
|
console.log('Copy .env.example, fill it in, and restart.');
|
|
151
151
|
}
|
|
152
152
|
});
|
|
@@ -155,14 +155,14 @@ server.listen(PORT, () => {
|
|
|
155
155
|
/** The two values the platform gives you, and nothing else. */
|
|
156
156
|
function envExample(port) {
|
|
157
157
|
return `# Both are shown when you create the app. The SECRET is shown once.
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
SB_CLIENT_ID=
|
|
159
|
+
SB_CLIENT_SECRET=
|
|
160
160
|
|
|
161
161
|
# Where the platform's API lives.
|
|
162
|
-
|
|
162
|
+
SB_API=http://localhost:8080
|
|
163
163
|
|
|
164
164
|
# Must match the redirect URI on your version EXACTLY.
|
|
165
|
-
|
|
165
|
+
SB_REDIRECT_URI=http://localhost:${port}/oauth/callback
|
|
166
166
|
|
|
167
167
|
PORT=${port}
|
|
168
168
|
`;
|
|
@@ -180,7 +180,7 @@ completes the OAuth exchange. That is all it does on purpose.
|
|
|
180
180
|
|
|
181
181
|
## Run it
|
|
182
182
|
|
|
183
|
-
cp .env.example .env # fill in
|
|
183
|
+
cp .env.example .env # fill in SB_CLIENT_ID and SB_CLIENT_SECRET
|
|
184
184
|
npm start
|
|
185
185
|
|
|
186
186
|
Your app is on http://localhost:${port}. Nothing else is needed to develop it —
|
package/dist/src/types.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* `dev` translates is the one `deploy` re-throws. Declaring each separately
|
|
7
7
|
* where it is used is how two descriptions of one payload start disagreeing.
|
|
8
8
|
*
|
|
9
|
-
* NOTHING HERE IS VALIDATION. `
|
|
9
|
+
* NOTHING HERE IS VALIDATION. `sb.json` is parsed with `JSON.parse` and these
|
|
10
10
|
* types say what the program EXPECTS, not what it verified — which is why
|
|
11
11
|
* `readConfig` still checks the five required keys at runtime. A type is a
|
|
12
12
|
* claim about our own code; a file on a developer's disk is input.
|
package/package.json
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sbuilder/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Scaffold, run and deploy an app for the Store Builder platform.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sbuilder",
|
|
7
|
+
"store-builder",
|
|
8
|
+
"cli",
|
|
9
|
+
"ecommerce",
|
|
10
|
+
"storefront",
|
|
11
|
+
"app-development",
|
|
12
|
+
"islands",
|
|
13
|
+
"oauth",
|
|
14
|
+
"scaffold"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://github.com/vuluu2k/web_builder/tree/main/cli#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/vuluu2k/web_builder/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/vuluu2k/web_builder.git",
|
|
23
|
+
"directory": "cli"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "Store Builder",
|
|
5
27
|
"type": "module",
|
|
6
28
|
"bin": {
|
|
7
|
-
"
|
|
29
|
+
"sb": "dist/bin/sb.js"
|
|
8
30
|
},
|
|
9
31
|
"files": [
|
|
10
|
-
"dist"
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"README.vi.md",
|
|
35
|
+
"LICENSE"
|
|
11
36
|
],
|
|
12
37
|
"engines": {
|
|
13
38
|
"node": ">=20"
|
|
14
39
|
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
15
43
|
"scripts": {
|
|
16
44
|
"build": "tsc -p tsconfig.build.json",
|
|
17
45
|
"typecheck": "tsc -p tsconfig.json",
|