@sbuilder/cli 0.3.0 → 0.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"sb.js","sourceRoot":"","sources":["../../bin/sb.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AACH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;eAiBC,CAAC;AAiBhB,SAAS,KAAK,CAAC,IAAc;IAC3B,MAAM,IAAI,GAAS,EAAE,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAChC,CAAC;aAAM,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACrB,CAAC;aAAM,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;YACxC,IAAI,CAAC,IAAI,GAAG,IAAI,C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AM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,615 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { lstat, mkdir, readFile, readdir, realpath, rename, unlink, writeFile, } from 'node:fs/promises';
3
+ import { dirname, join, resolve, sep } from 'node:path';
4
+ import { authedFetch, SB_TOKEN_REFUSED } from './auth.js';
5
+ import { DevError, messageOf } from './dev.js';
6
+ /**
7
+ * `sb code pull` / `sb code push` — a site's Code Dock files as a folder.
8
+ *
9
+ * # THREE VERSIONS OF EVERY FILE, AND THE MANIFEST HOLDS THE THIRD
10
+ *
11
+ * Local, server, and BASE: the content as last pulled or pushed, recorded in
12
+ * `.sb-code.json` as a sha256 beside the server's `updatedAt`. Every decision
13
+ * here is a three-way compare against it. Without a base, "the local file
14
+ * differs from the server" cannot tell a developer's edit from a Code Dock edit,
15
+ * and one of them would be overwritten silently.
16
+ *
17
+ * # THE GUARD IS THE SERVER'S, NOT OURS
18
+ *
19
+ * A push sends `expectedUpdatedAt` = the base's `updatedAt` and the server
20
+ * compares it inside the write (409 `code_file_changed` when stale). A client
21
+ * read-then-write would let two pushes interleave past it.
22
+ *
23
+ * # THE MANIFEST IS WRITTEN AFTER EVERY OPERATION
24
+ *
25
+ * A run that stops halfway is resumed by running it again, and nothing is
26
+ * created twice — because a create that landed is already tracked.
27
+ */
28
+ export const MANIFEST = '.sb-code.json';
29
+ export const SBDK_REFUSED = "Deploy keys (sbdk_…) belong to a developer organization and only reach its apps' version routes; " +
30
+ 'site code is merchant content. Use `sb login`, or set SB_TOKEN to an API key (wbk_…) with ' +
31
+ 'codefiles.write from Settings -> API keys.';
32
+ /** Replaces auth.ts's SB_TOKEN_REFUSED, which recommends a deploy key — wrong advice for site code. */
33
+ export const CODE_UNAUTHORIZED = 'Not signed in, or the token was refused (expired or revoked). Run `sb login`, or set SB_TOKEN ' +
34
+ 'to an API key (wbk_…) with codefiles.read / codefiles.write from Settings -> API keys.';
35
+ export const NO_SITE = 'Which site? Pass --site <id>, or add "siteId" to sb.json. (An API key (wbk_…) in SB_TOKEN implies its site.)';
36
+ /** bin/sb.ts refuses a linked default root: ./code comes from the repo, --dir from you. */
37
+ export const ROOT_LINKED = './code is a symbolic link — pass --dir <path> to sync through it deliberately; nothing was sent.';
38
+ const LANGUAGES = { '.css': 'css', '.js': 'javascript', '.html': 'html' };
39
+ const EXTENSIONS = Object.fromEntries(Object.entries(LANGUAGES).map(([ext, lang]) => [lang, ext]));
40
+ /** A refusal the developer can act on; `sb` prints it and exits 1. */
41
+ export class CodeRefused extends DevError {
42
+ }
43
+ const sha256 = (s) => createHash('sha256').update(s, 'utf8').digest('hex');
44
+ const entryOf = (f, sha) => ({
45
+ id: f.id,
46
+ pageId: f.pageId ?? '',
47
+ name: f.name,
48
+ language: f.language,
49
+ placement: f.placement,
50
+ enabled: f.enabled,
51
+ position: f.position,
52
+ updatedAt: f.updatedAt,
53
+ sha256: sha,
54
+ });
55
+ async function readText(path) {
56
+ try {
57
+ return await readFile(path, 'utf8');
58
+ }
59
+ catch (err) {
60
+ if (err.code === 'ENOENT')
61
+ return undefined;
62
+ throw err;
63
+ }
64
+ }
65
+ async function readManifest(dir) {
66
+ // Committed, so it can be a link — and one to /dev/zero would be read until memory ran out.
67
+ if ((await lstat(join(dir, MANIFEST)).catch(() => undefined))?.isSymbolicLink()) {
68
+ throw new CodeRefused(`${join(dir, MANIFEST)} is a symbolic link — replace it with the file itself; nothing was sent.`);
69
+ }
70
+ const text = await readText(join(dir, MANIFEST));
71
+ if (text === undefined)
72
+ return { siteId: null, files: {} };
73
+ let m;
74
+ try {
75
+ m = JSON.parse(text);
76
+ }
77
+ catch {
78
+ throw new CodeRefused(`${join(dir, MANIFEST)} is not valid JSON — fix it or restore it from git.`);
79
+ }
80
+ const files = m.files ?? {};
81
+ // The manifest is committed, so it is input from anyone with push access: a key
82
+ // that climbs out of the root would make push upload, and pull unlink, that file.
83
+ for (const key of Object.keys(files)) {
84
+ const parts = key.split('/');
85
+ const layout = (parts[0] === 'site' && parts.length >= 2) || (parts[0] === 'pages' && parts.length >= 3);
86
+ if (!safePath(key) || !layout) {
87
+ throw new CodeRefused(`${join(dir, MANIFEST)} tracks "${key}", which is not a path under site/ or pages/<page>/ — ` +
88
+ 'fix or remove that entry; nothing was sent.');
89
+ }
90
+ }
91
+ return { siteId: m.siteId ?? null, files };
92
+ }
93
+ /** Temp file + rename (auth.ts writeAll's shape): a reader never sees half a manifest. */
94
+ async function saveManifest(ctx) {
95
+ const path = join(ctx.dir, MANIFEST);
96
+ const files = {};
97
+ for (const k of Object.keys(ctx.manifest.files).sort())
98
+ files[k] = ctx.manifest.files[k];
99
+ await mkdir(ctx.dir, { recursive: true });
100
+ const tmp = `${path}.${randomBytes(6).toString('hex')}.tmp`;
101
+ await writeFile(tmp, JSON.stringify({ siteId: ctx.manifest.siteId, files }, null, 2) + '\n', {
102
+ flag: 'wx',
103
+ });
104
+ await rename(tmp, path);
105
+ }
106
+ /** sb.json's `siteId` and nothing else: `sb code` must not need the five app keys. */
107
+ async function sbJsonSite(cwd) {
108
+ const text = await readText(resolve(cwd, 'sb.json'));
109
+ if (text === undefined)
110
+ return undefined;
111
+ try {
112
+ const v = JSON.parse(text).siteId;
113
+ return typeof v === 'string' && v ? v : undefined;
114
+ }
115
+ catch {
116
+ throw new CodeRefused('sb.json is not valid JSON.');
117
+ }
118
+ }
119
+ /**
120
+ * Every refusal that needs no server happens here, before the first request — except a
121
+ * linked default ./code, which bin/sb.ts refuses because only it knows --dir was omitted.
122
+ */
123
+ async function open(o) {
124
+ const cred = o.token;
125
+ if (!cred)
126
+ throw new CodeRefused(CODE_UNAUTHORIZED);
127
+ if (typeof cred === 'string' && cred.startsWith('sbdk_'))
128
+ throw new CodeRefused(SBDK_REFUSED);
129
+ const v1 = typeof cred === 'string' && cred.startsWith('wbk_');
130
+ const manifest = await readManifest(o.dir);
131
+ const named = [
132
+ ['--site', o.site],
133
+ ['sb.json siteId', await sbJsonSite(o.cwd ?? process.cwd())],
134
+ [`${MANIFEST} siteId`, manifest.siteId ?? undefined],
135
+ ].filter(([, v]) => v);
136
+ const clash = named.find(([, v]) => v !== named[0][1]);
137
+ if (clash) {
138
+ throw new CodeRefused(`${named[0][0]} is "${named[0][1]}" but ${clash[0]} is "${clash[1]}" — they name different sites. ` +
139
+ 'Fix one of them; nothing was sent.');
140
+ }
141
+ const siteId = named[0]?.[1];
142
+ if (!v1 && !siteId)
143
+ throw new CodeRefused(NO_SITE);
144
+ // A wbk_ key implies its site, so --site / sb.json are not evidence of which one:
145
+ // the manifest keeps whatever it already recorded.
146
+ if (!v1)
147
+ manifest.siteId = siteId;
148
+ const base = v1 ? `${o.api}/api/v1` : `${o.api}/api/sites/${encodeURIComponent(siteId)}`;
149
+ const log = o.log ?? console.log;
150
+ return {
151
+ cred,
152
+ v1,
153
+ files: `${base}/code-files`,
154
+ pages: `${base}/pages`,
155
+ dir: o.dir,
156
+ manifest,
157
+ warn: o.warn ?? log,
158
+ };
159
+ }
160
+ /** One request. A 401 — from SB_TOKEN or after a stored login's renewal — is final. */
161
+ async function send(ctx, url, method, body) {
162
+ let res;
163
+ try {
164
+ res = await authedFetch(url, body === undefined
165
+ ? { method }
166
+ : { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }, ctx.cred);
167
+ }
168
+ catch (err) {
169
+ if (err instanceof DevError)
170
+ throw err.message === SB_TOKEN_REFUSED ? new CodeRefused(CODE_UNAUTHORIZED) : err;
171
+ throw new CodeRefused(`Could not reach ${new URL(url).origin}: ${messageOf(err)}. Check SB_API and try again.`);
172
+ }
173
+ if (res.status === 401)
174
+ throw new CodeRefused(CODE_UNAUTHORIZED);
175
+ return res;
176
+ }
177
+ async function errorOf(res) {
178
+ try {
179
+ return (await res.json()).error ?? `HTTP ${res.status}`;
180
+ }
181
+ catch {
182
+ return `HTTP ${res.status}`;
183
+ }
184
+ }
185
+ async function listFiles(ctx) {
186
+ const res = await send(ctx, ctx.files, 'GET');
187
+ if (res.status === 403) {
188
+ throw new CodeRefused(`this token cannot read code files — it needs codefiles.read (server: ${await errorOf(res)})`);
189
+ }
190
+ if (!res.ok)
191
+ throw new CodeRefused(`listing code files failed (server: ${await errorOf(res)})`);
192
+ return (await res.json()).codeFiles;
193
+ }
194
+ /** The site's pages, or null when the token may not read them (not fatal: see folders). */
195
+ async function listPages(ctx) {
196
+ if (ctx.pagesCache !== undefined)
197
+ return ctx.pagesCache;
198
+ const out = [];
199
+ for (let offset = 0;;) {
200
+ const url = ctx.v1
201
+ ? `${ctx.pages}?${new URLSearchParams({ limit: '200', offset: String(offset) })}`
202
+ : ctx.pages;
203
+ const res = await send(ctx, url, 'GET');
204
+ if (res.status === 403) {
205
+ ctx.warn('this token cannot read pages (it needs pages.read), so page folders it has not seen are named page-<id>');
206
+ return (ctx.pagesCache = null);
207
+ }
208
+ if (!res.ok)
209
+ throw new CodeRefused(`listing pages failed (server: ${await errorOf(res)})`);
210
+ const body = (await res.json());
211
+ out.push(...body.pages);
212
+ offset += body.pages.length;
213
+ if (!ctx.v1 || body.pages.length === 0 || offset >= body.total)
214
+ break;
215
+ }
216
+ return (ctx.pagesCache = out);
217
+ }
218
+ const safeSegment = (s) => s !== '' && s !== '.' && s !== '..' && !/[/\\]/.test(s);
219
+ /** A posix path relative to the root that cannot climb out of it. */
220
+ const safePath = (p) => p.split('/').every(safeSegment);
221
+ /** The real path of `p`, or of its nearest ancestor that exists: pull creates folders as it goes. */
222
+ async function realNearest(p) {
223
+ try {
224
+ return await realpath(p);
225
+ }
226
+ catch (err) {
227
+ if (err.code !== 'ENOENT')
228
+ throw err;
229
+ return realNearest(dirname(p));
230
+ }
231
+ }
232
+ /**
233
+ * safePath checks the string, and a symlink climbs out anyway. code/ is committed,
234
+ * so `site/x.css -> ~/.ssh/id_rsa` would be uploaded by push and overwritten by
235
+ * pull. A file that is a link, or whose folder resolves outside the root, is
236
+ * refused before it is read, written or unlinked.
237
+ */
238
+ async function linkRefusal(dir, path) {
239
+ const abs = join(dir, ...path.split('/'));
240
+ if ((await lstat(abs).catch(() => undefined))?.isSymbolicLink())
241
+ return `${path}: a symbolic link — sb code never reads or writes through one; skipped`;
242
+ const root = await realNearest(dir);
243
+ if (!`${await realNearest(dirname(abs))}${sep}`.startsWith(`${root}${sep}`))
244
+ return `${path}: its folder leads outside ${dir} through a symbolic link; skipped`;
245
+ return undefined;
246
+ }
247
+ /** pageId -> folder, from the manifest: a folder never moves once recorded. */
248
+ function trackedFolders(m) {
249
+ const out = new Map();
250
+ for (const [path, e] of Object.entries(m.files)) {
251
+ const [top, folder] = path.split('/');
252
+ if (top === 'pages' && e.pageId)
253
+ out.set(e.pageId, folder);
254
+ }
255
+ return out;
256
+ }
257
+ /**
258
+ * Names a folder for every page the manifest does not know: homepage `home`,
259
+ * else the slug; empty, unsafe or clashing -> `page-<id>`.
260
+ */
261
+ function nameFolders(pages, tracked) {
262
+ const taken = new Map([...tracked].map(([id, folder]) => [folder, id]));
263
+ const fresh = pages.filter((p) => !tracked.has(p.id));
264
+ const want = (p) => (p.isHomepage ? 'home' : safeSegment(p.slug) ? p.slug : '');
265
+ const count = new Map();
266
+ for (const p of fresh)
267
+ count.set(want(p), (count.get(want(p)) ?? 0) + 1);
268
+ const out = new Map(tracked);
269
+ for (const p of fresh) {
270
+ const w = want(p);
271
+ out.set(p.id, !w || count.get(w) > 1 || taken.has(w) ? `page-${p.id}` : w);
272
+ }
273
+ return out;
274
+ }
275
+ /** Folders for the given page ids, listing pages only when the manifest lacks one. */
276
+ async function foldersFor(ctx, pageIds) {
277
+ const tracked = trackedFolders(ctx.manifest);
278
+ if (pageIds.every((id) => tracked.has(id)))
279
+ return tracked;
280
+ const pages = await listPages(ctx);
281
+ const out = pages ? nameFolders(pages, tracked) : tracked;
282
+ for (const id of pageIds)
283
+ if (!out.has(id))
284
+ out.set(id, `page-${id}`);
285
+ return out;
286
+ }
287
+ /** A wbk_ key implies its site; refuse to sync a manifest from another one (--force overrides). */
288
+ function checkSameSite(ctx, server) {
289
+ const tracked = Object.values(ctx.manifest.files).map((e) => e.id);
290
+ if (!ctx.v1 || tracked.length === 0 || server.length === 0)
291
+ return;
292
+ const ids = new Set(server.map((f) => f.id));
293
+ if (tracked.some((id) => ids.has(id)))
294
+ return;
295
+ throw new CodeRefused(`this key belongs to a different site than ${MANIFEST}: none of its ${tracked.length} tracked files ` +
296
+ "exist on the key's site, so nothing was written. If every tracked file really was replaced on the " +
297
+ 'server, run again with --force.');
298
+ }
299
+ async function writeLocal(dir, path, content) {
300
+ const abs = join(dir, ...path.split('/'));
301
+ await mkdir(dirname(abs), { recursive: true });
302
+ await writeFile(abs, content, 'utf8');
303
+ }
304
+ /**
305
+ * pull: server -> folder, never over a local edit unless --force.
306
+ *
307
+ * @returns the exit code: 1 when anything was kept against the server or refused.
308
+ */
309
+ export async function pull(o) {
310
+ const log = o.log ?? console.log;
311
+ const ctx = await open(o);
312
+ const server = await listFiles(ctx);
313
+ if (!o.force)
314
+ checkSameSite(ctx, server);
315
+ const m = ctx.manifest;
316
+ const pathOf = new Map(Object.entries(m.files).map(([p, e]) => [e.id, p]));
317
+ const folders = await foldersFor(ctx, server.filter((f) => f.pageId && !pathOf.has(f.id)).map((f) => f.pageId));
318
+ const claimed = new Set(server.filter((f) => pathOf.has(f.id)).map((f) => pathOf.get(f.id)));
319
+ const n = { written: 0, kept: 0, removed: 0, pending: 0 };
320
+ let failed = false;
321
+ for (const f of server) {
322
+ // ponytail: a tracked file keeps its path, so a rename in the Code Dock is not mirrored locally.
323
+ let path = pathOf.get(f.id);
324
+ if (!path) {
325
+ // An unnamed file gets a local name; it is tracked by id, so its server name stays empty.
326
+ const name = f.name || `unnamed-${f.id}${EXTENSIONS[f.language] ?? ''}`;
327
+ path = f.pageId ? `pages/${folders.get(f.pageId)}/${name}` : `site/${name}`;
328
+ if (!safePath(path)) {
329
+ ctx.warn(`${f.id} (${JSON.stringify(f.name)}): not a safe file path, skipped`);
330
+ failed = true;
331
+ continue;
332
+ }
333
+ if (claimed.has(path)) {
334
+ ctx.warn(`${path}: two code files map to this path; skipped ${f.id} — rename one in the Code Dock`);
335
+ failed = true;
336
+ continue;
337
+ }
338
+ claimed.add(path);
339
+ }
340
+ const linked = await linkRefusal(o.dir, path);
341
+ if (linked) {
342
+ ctx.warn(linked);
343
+ failed = true;
344
+ continue;
345
+ }
346
+ const base = m.files[path];
347
+ const theirs = sha256(f.content);
348
+ const local = await readText(join(o.dir, ...path.split('/')));
349
+ const mine = local === undefined ? undefined : sha256(local);
350
+ if (mine !== undefined && mine !== theirs && mine !== base?.sha256) {
351
+ // A local edit. The server unchanged since the base: pending, refresh the base's metadata.
352
+ if (base && theirs === base.sha256 && !o.force) {
353
+ m.files[path] = entryOf(f, base.sha256);
354
+ await saveManifest(ctx);
355
+ log(`pending ${path} (local edit — sb code push sends it)`);
356
+ n.pending++;
357
+ continue;
358
+ }
359
+ if (!o.force) {
360
+ ctx.warn(`kept ${path}: edited here AND changed on the server — sb code pull --force overwrites it`);
361
+ n.kept++;
362
+ failed = true;
363
+ continue;
364
+ }
365
+ }
366
+ if (mine !== theirs) {
367
+ await writeLocal(o.dir, path, f.content);
368
+ log(`wrote ${path}`);
369
+ n.written++;
370
+ }
371
+ m.files[path] = entryOf(f, theirs);
372
+ await saveManifest(ctx);
373
+ }
374
+ const live = new Set(server.map((f) => f.id));
375
+ for (const [path, e] of Object.entries(m.files)) {
376
+ if (live.has(e.id))
377
+ continue;
378
+ const linked = await linkRefusal(o.dir, path);
379
+ if (linked) {
380
+ ctx.warn(linked);
381
+ failed = true;
382
+ continue;
383
+ }
384
+ const abs = join(o.dir, ...path.split('/'));
385
+ const local = await readText(abs);
386
+ if (local !== undefined && sha256(local) !== e.sha256 && !o.force) {
387
+ ctx.warn(`kept ${path}: deleted on the server but edited here — sb code push would create it again`);
388
+ n.kept++;
389
+ failed = true;
390
+ }
391
+ else if (local !== undefined) {
392
+ await unlink(abs);
393
+ log(`removed ${path}`);
394
+ n.removed++;
395
+ }
396
+ delete m.files[path];
397
+ await saveManifest(ctx);
398
+ }
399
+ await saveManifest(ctx);
400
+ log(`pull: ${n.written} written, ${n.pending} pending, ${n.kept} kept, ${n.removed} removed`);
401
+ return failed ? 1 : 0;
402
+ }
403
+ /**
404
+ * Every file under site/ and pages/, as posix paths. Dotfiles (.DS_Store) are skipped.
405
+ * A symlink — site/ or pages/ itself included — is listed and never entered, so push
406
+ * refuses it by name.
407
+ */
408
+ async function walk(dir, rel) {
409
+ const abs = join(dir, ...rel.split('/'));
410
+ if ((await lstat(abs).catch(() => undefined))?.isSymbolicLink())
411
+ return [rel];
412
+ let names;
413
+ try {
414
+ names = await readdir(abs, { withFileTypes: true });
415
+ }
416
+ catch (err) {
417
+ if (err.code === 'ENOENT')
418
+ return [];
419
+ throw err;
420
+ }
421
+ const out = [];
422
+ for (const d of names) {
423
+ if (d.name.startsWith('.'))
424
+ continue;
425
+ const p = `${rel}/${d.name}`;
426
+ if (d.isDirectory())
427
+ out.push(...(await walk(dir, p)));
428
+ else if (d.isFile() || d.isSymbolicLink())
429
+ out.push(p);
430
+ }
431
+ return out;
432
+ }
433
+ /** The sentence for a refused write; a 5xx is not a refusal, it stops the run. */
434
+ async function refusal(path, res) {
435
+ let body = {};
436
+ try {
437
+ body = (await res.json());
438
+ }
439
+ catch {
440
+ /* not JSON: something in front of the server answered */
441
+ }
442
+ const server = body.error ?? `HTTP ${res.status}`;
443
+ if (res.status >= 500) {
444
+ throw new CodeRefused(`${path}: the server failed (${server}). Stopped here; everything before it is saved in ${MANIFEST}, ` +
445
+ 'so running sb code push again resumes without repeating it.');
446
+ }
447
+ if (res.status === 409 && body.code === 'code_file_changed') {
448
+ return `${path}: changed in the Code Dock since your pull; run sb code pull, or push --force (server: ${server})`;
449
+ }
450
+ if (res.status === 403)
451
+ return `${path}: this token cannot write code files — it needs codefiles.write (server: ${server})`;
452
+ return `${path}: refused (server: ${server})`;
453
+ }
454
+ /**
455
+ * push: folder -> server. Creates, then updates, then (with --delete) deletes,
456
+ * each guarded by the base's updatedAt unless --force.
457
+ *
458
+ * @returns the exit code: 1 when any file was refused.
459
+ */
460
+ export async function push(o) {
461
+ const log = o.log ?? console.log;
462
+ const ctx = await open(o);
463
+ const m = ctx.manifest;
464
+ if (ctx.v1 && !o.force && Object.keys(m.files).length > 0)
465
+ checkSameSite(ctx, await listFiles(ctx));
466
+ const local = [...(await walk(o.dir, 'site')), ...(await walk(o.dir, 'pages'))];
467
+ const ops = [];
468
+ let failed = false;
469
+ const refuse = (line) => {
470
+ ctx.warn(line);
471
+ failed = true;
472
+ };
473
+ for (const [path, entry] of Object.entries(m.files)) {
474
+ const linked = await linkRefusal(o.dir, path);
475
+ if (linked) {
476
+ refuse(linked);
477
+ continue;
478
+ }
479
+ const content = await readText(join(o.dir, ...path.split('/')));
480
+ if (content === undefined) {
481
+ if (o.delete)
482
+ ops.push({ kind: 'delete', path, entry });
483
+ else
484
+ log(`missing ${path}: tracked but gone locally — kept on the server (sb code push --delete deletes it)`);
485
+ }
486
+ else if (sha256(content) !== entry.sha256) {
487
+ ops.push({ kind: 'update', path, content, entry });
488
+ }
489
+ }
490
+ const tracked = trackedFolders(m);
491
+ const pageOf = new Map([...tracked].map(([id, folder]) => [folder, id]));
492
+ for (const path of local) {
493
+ if (m.files[path])
494
+ continue;
495
+ const linked = await linkRefusal(o.dir, path);
496
+ if (linked) {
497
+ refuse(linked);
498
+ continue;
499
+ }
500
+ const parts = path.split('/');
501
+ const language = LANGUAGES[/\.[^./]*$/.exec(path)?.[0] ?? ''];
502
+ if (!language) {
503
+ refuse(`${path}: unknown extension — a new code file must end in .css, .js or .html`);
504
+ continue;
505
+ }
506
+ let pageId = '';
507
+ let name = parts.slice(1).join('/');
508
+ if (parts[0] === 'pages') {
509
+ if (parts.length < 3) {
510
+ refuse(`${path}: a page file goes in pages/<page>/`);
511
+ continue;
512
+ }
513
+ name = parts.slice(2).join('/');
514
+ if (!pageOf.has(parts[1])) {
515
+ const pages = await listPages(ctx);
516
+ if (!pages) {
517
+ refuse(`${path}: "${parts[1]}" is not a page folder ${MANIFEST} knows, and this token cannot read pages (it needs pages.read)`);
518
+ continue;
519
+ }
520
+ for (const [id, folder] of nameFolders(pages, tracked))
521
+ if (!pageOf.has(folder))
522
+ pageOf.set(folder, id);
523
+ }
524
+ const id = pageOf.get(parts[1]);
525
+ if (!id) {
526
+ refuse(`${path}: no page matches the folder "${parts[1]}" — code is only pushed for pages that exist`);
527
+ continue;
528
+ }
529
+ pageId = id;
530
+ }
531
+ ops.push({
532
+ kind: 'create',
533
+ path,
534
+ content: (await readText(join(o.dir, ...parts))),
535
+ pageId,
536
+ name,
537
+ language,
538
+ });
539
+ }
540
+ const order = { create: 0, update: 1, delete: 2 };
541
+ ops.sort((a, b) => order[a.kind] - order[b.kind] || a.path.localeCompare(b.path));
542
+ if (o.dryRun) {
543
+ for (const op of ops)
544
+ log(`${op.kind.padEnd(8)} ${op.path}`);
545
+ log(`dry run: ${ops.length} planned, nothing sent`);
546
+ return failed ? 1 : 0;
547
+ }
548
+ const guard = (e) => (o.force ? {} : { expectedUpdatedAt: e.updatedAt });
549
+ let done = 0;
550
+ for (const op of ops) {
551
+ if (op.kind === 'create') {
552
+ const res = await send(ctx, ctx.files, 'POST', {
553
+ pageId: op.pageId,
554
+ name: op.name,
555
+ language: op.language,
556
+ content: op.content,
557
+ enabled: true,
558
+ });
559
+ if (!res.ok) {
560
+ refuse(await refusal(op.path, res));
561
+ continue;
562
+ }
563
+ const f = (await res.json()).codeFile;
564
+ m.files[op.path] = entryOf(f, sha256(op.content));
565
+ log(`created ${op.path} (placement ${f.placement}, ${f.enabled ? 'enabled' : 'disabled'}, position ${f.position})`);
566
+ }
567
+ else if (op.kind === 'update') {
568
+ const url = `${ctx.files}/${encodeURIComponent(op.entry.id)}`;
569
+ let meta = op.entry;
570
+ if (o.force) {
571
+ // PUT replaces the row: --force sends the server's CURRENT metadata so the
572
+ // content wins without reverting what the Code Dock changed.
573
+ const cur = await send(ctx, url, 'GET');
574
+ if (!cur.ok) {
575
+ refuse(await refusal(op.path, cur));
576
+ continue;
577
+ }
578
+ const f = (await cur.json()).codeFile;
579
+ meta = { ...f, pageId: f.pageId ?? '' };
580
+ }
581
+ const res = await send(ctx, url, 'PUT', {
582
+ pageId: meta.pageId,
583
+ name: meta.name,
584
+ language: meta.language,
585
+ placement: meta.placement,
586
+ enabled: meta.enabled,
587
+ position: meta.position,
588
+ content: op.content,
589
+ ...guard(op.entry),
590
+ });
591
+ if (!res.ok) {
592
+ refuse(await refusal(op.path, res));
593
+ continue;
594
+ }
595
+ m.files[op.path] = entryOf((await res.json()).codeFile, sha256(op.content));
596
+ log(`updated ${op.path}`);
597
+ }
598
+ else {
599
+ const q = o.force ? '' : `?${new URLSearchParams({ expectedUpdatedAt: op.entry.updatedAt })}`;
600
+ const res = await send(ctx, `${ctx.files}/${encodeURIComponent(op.entry.id)}${q}`, 'DELETE');
601
+ if (!res.ok && res.status !== 404) {
602
+ refuse(await refusal(op.path, res));
603
+ continue;
604
+ }
605
+ delete m.files[op.path];
606
+ log(`deleted ${op.path}`);
607
+ }
608
+ done++;
609
+ await saveManifest(ctx);
610
+ }
611
+ await saveManifest(ctx);
612
+ log(`push: ${done} of ${ops.length} applied`);
613
+ return failed ? 1 : 0;
614
+ }
615
+ //# sourceMappingURL=code.js.map