@composable-os/cli 0.1.0-beta.11 → 0.1.0-beta.14

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.
Files changed (166) hide show
  1. package/dist/{accounts-UHYLCLEY.js → accounts-GOCNY6WI.js} +17 -13
  2. package/dist/app-OSPZHKOI.js +43 -0
  3. package/dist/app-upload-LH4PXKI4.js +198 -0
  4. package/dist/{blocks-5IFU25J6.js → blocks-6DZIP47W.js} +207 -25
  5. package/dist/{chunk-XIDLW3EP.js → chunk-2B6YUYZV.js} +23499 -11766
  6. package/dist/{run-7P4RQALH.js → chunk-2CCHB37H.js} +9 -146
  7. package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
  8. package/dist/{chunk-DHS2CV2M.js → chunk-5D7BDF4Y.js} +15 -13
  9. package/dist/{chunk-MBIKVRAC.js → chunk-5YDYQM6V.js} +830 -47
  10. package/dist/{chunk-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
  11. package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
  12. package/dist/chunk-EPDTPGZJ.js +330 -0
  13. package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
  14. package/dist/chunk-HCG6T53D.js +61904 -0
  15. package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
  16. package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
  17. package/dist/chunk-KMFMD52Z.js +13276 -0
  18. package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
  19. package/dist/{chunk-PDD2ETVF.js → chunk-O37YUZ52.js} +172 -16
  20. package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
  21. package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
  22. package/dist/chunk-RGKJKC5T.js +876 -0
  23. package/dist/{chunk-YFTLIEWU.js → chunk-RSEWEFAV.js} +12 -2
  24. package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
  25. package/dist/{chunk-LO6WGU5Y.js → chunk-U72NEGCT.js} +8089 -3464
  26. package/dist/{chunk-P6UWZ6QQ.js → chunk-Z4IKF23A.js} +11 -7
  27. package/dist/{chunk-2IVEVPMY.js → chunk-Z7OVQ6BC.js} +105 -61
  28. package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
  29. package/dist/{cli-5UNY5G5L.js → cli-OKQHHSOE.js} +17 -25
  30. package/dist/{cli-UYZMVQMR.js → cli-VYSD2S4Z.js} +227 -81
  31. package/dist/cli.js +5 -5
  32. package/dist/{client-repo-SE4EKG6W.js → client-repo-MPCPTXLF.js} +7 -5
  33. package/dist/create.js +5 -5
  34. package/dist/{fields-FTWWMD7N.js → fields-GTHE6TTS.js} +27 -3
  35. package/dist/gateway-DPPEQZT4.js +25 -0
  36. package/dist/grants-6JY4XZO7.js +27 -0
  37. package/dist/invoke-MRONRZ5Q.js +33 -0
  38. package/dist/moves-UAUCMWL5.js +36 -0
  39. package/dist/{order-U4KZLLSJ.js → order-RKLGT74L.js} +2 -2
  40. package/dist/{person-UHLVBVLR.js → person-YOZTFV4Q.js} +11 -10
  41. package/dist/plan-on-sale-H4F26YIN.js +26 -0
  42. package/dist/platform/migrations/0730_practitioners.sql +79 -0
  43. package/dist/platform/migrations/0750_routine_mail.sql +98 -0
  44. package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
  45. package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
  46. package/dist/platform/migrations/0811_staff_time.sql +109 -0
  47. package/dist/platform/migrations/0812_staff_offers.sql +112 -0
  48. package/dist/platform/migrations/0813_pay_periods.sql +241 -0
  49. package/dist/platform/migrations/0814_staff_feed.sql +47 -0
  50. package/dist/platform/migrations/0815_checklists.sql +237 -0
  51. package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
  52. package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
  53. package/dist/platform/migrations/0850_agreements.sql +271 -0
  54. package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
  55. package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
  56. package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
  57. package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
  58. package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
  59. package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
  60. package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
  61. package/dist/platform/migrations/0910_routine_messages.sql +99 -0
  62. package/dist/platform/migrations/0911_texts.sql +60 -0
  63. package/dist/platform/migrations/0913_contact_consent.sql +93 -0
  64. package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
  65. package/dist/platform/migrations/0930_stock_movements.sql +95 -0
  66. package/dist/platform/migrations/0931_stock_low.sql +25 -0
  67. package/dist/platform/migrations/0932_order_delivery.sql +78 -0
  68. package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
  69. package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
  70. package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
  71. package/dist/platform/migrations/0953_discount_uses.sql +183 -0
  72. package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
  73. package/dist/platform/migrations/0970_published_text.sql +59 -0
  74. package/dist/platform/migrations/0971_publish_acks.sql +68 -0
  75. package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
  76. package/dist/platform/migrations/1010_intake_links.sql +148 -0
  77. package/dist/platform/migrations/1030_invoices.sql +747 -0
  78. package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
  79. package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
  80. package/dist/platform/migrations/1090_staff_hours.sql +43 -0
  81. package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
  82. package/dist/platform/migrations/1092_client_guard.sql +26 -0
  83. package/dist/platform/migrations/1095_thing_time.sql +70 -0
  84. package/dist/platform/migrations/1130_devices.sql +162 -0
  85. package/dist/platform/migrations/1135_person_codes.sql +88 -0
  86. package/dist/platform/migrations/1150_finance_periods.sql +316 -0
  87. package/dist/platform/migrations/1151_payouts.sql +202 -0
  88. package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
  89. package/dist/platform/migrations/1170_journeys.sql +318 -0
  90. package/dist/platform/migrations/1171_person_birthday.sql +52 -0
  91. package/dist/platform/migrations/1175_person_signals.sql +29 -0
  92. package/dist/platform/migrations/1190_restricted_values.sql +25 -0
  93. package/dist/platform/migrations/1230_note_levels.sql +113 -0
  94. package/dist/platform/migrations/1231_person_carers.sql +33 -0
  95. package/dist/platform/migrations/1232_note_kinds.sql +122 -0
  96. package/dist/platform/migrations/1270_time_entries.sql +145 -0
  97. package/dist/platform/migrations/1271_leave.sql +249 -0
  98. package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
  99. package/dist/platform/migrations/1330_accounting.sql +260 -0
  100. package/dist/platform/migrations/1350_customer_feed.sql +24 -0
  101. package/dist/platform/migrations/1390_locations.sql +77 -0
  102. package/dist/platform/migrations/1410_outside_copy.sql +213 -0
  103. package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
  104. package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
  105. package/dist/platform/sdk/acknowledge.ts +100 -0
  106. package/dist/platform/sdk/agreements.ts +185 -0
  107. package/dist/platform/sdk/allowance.ts +98 -8
  108. package/dist/platform/sdk/automation-check.ts +120 -9
  109. package/dist/platform/sdk/automation.ts +78 -10
  110. package/dist/platform/sdk/behaviour.ts +26 -6
  111. package/dist/platform/sdk/calendar-entry.ts +258 -0
  112. package/dist/platform/sdk/capacity.ts +1 -2
  113. package/dist/platform/sdk/checklists.ts +118 -0
  114. package/dist/platform/sdk/contract.ts +489 -27
  115. package/dist/platform/sdk/discount.ts +408 -0
  116. package/dist/platform/sdk/document.ts +4 -2
  117. package/dist/platform/sdk/field-types.ts +5 -0
  118. package/dist/platform/sdk/formula/compile.ts +10 -0
  119. package/dist/platform/sdk/index.ts +17 -0
  120. package/dist/platform/sdk/intake.ts +380 -0
  121. package/dist/platform/sdk/journey-signals.ts +215 -0
  122. package/dist/platform/sdk/manifest.ts +1236 -65
  123. package/dist/platform/sdk/mine.ts +161 -0
  124. package/dist/platform/sdk/occupies.ts +192 -0
  125. package/dist/platform/sdk/questions.ts +681 -0
  126. package/dist/platform/sdk/recurring.ts +90 -9
  127. package/dist/platform/sdk/restricted-fields.ts +129 -0
  128. package/dist/platform/sdk/rich-text.ts +112 -0
  129. package/dist/platform/sdk/routine-mail.ts +1272 -0
  130. package/dist/platform/sdk/runtime.ts +25 -12
  131. package/dist/platform/sdk/screens.ts +91 -0
  132. package/dist/platform/sdk/sellable.ts +344 -0
  133. package/dist/platform/sdk/slug.ts +7 -2
  134. package/dist/platform/sdk/staffed.ts +474 -0
  135. package/dist/platform/sdk/states.ts +68 -26
  136. package/dist/platform/sdk/stock.ts +332 -0
  137. package/dist/platform/sdk/team.ts +83 -0
  138. package/dist/platform/sdk/testing.ts +70 -6
  139. package/dist/platform/sdk/worked-on.ts +134 -0
  140. package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
  141. package/dist/run-7ID64RA6.js +65 -0
  142. package/dist/run-FH7OGGTV.js +131 -0
  143. package/dist/run-OYZIAP6M.js +3363 -0
  144. package/dist/{run-ZCGFMEZF.js → run-QOFRRSZV.js} +41 -60
  145. package/dist/{run-PO3W5BFA.js → run-TJAEWR5U.js} +21 -51
  146. package/dist/{src-I3IJ4NKC.js → src-52VERUPK.js} +306 -4
  147. package/dist/src-PHRELWN5.js +40 -0
  148. package/dist/{visibility-TVXZ67FD.js → visibility-SZCINPP4.js} +21 -4
  149. package/package.json +2 -2
  150. package/dist/chunk-2TWV3SVB.js +0 -349
  151. package/dist/chunk-2XC5JLBO.js +0 -1931
  152. package/dist/chunk-324WJXNP.js +0 -320
  153. package/dist/chunk-6ELZRNUU.js +0 -116
  154. package/dist/chunk-6WGFA2IV.js +0 -643
  155. package/dist/chunk-7CQGMVDO.js +0 -63
  156. package/dist/chunk-7OGCMQXG.js +0 -284
  157. package/dist/chunk-FJIZGS5Q.js +0 -698
  158. package/dist/chunk-UB4I2QKR.js +0 -31575
  159. package/dist/chunk-WHKJGF36.js +0 -2418
  160. package/dist/chunk-YNUZRTPH.js +0 -182
  161. package/dist/chunk-ZZFWMVJO.js +0 -704
  162. package/dist/grants-LOW6TSWD.js +0 -32
  163. package/dist/invoke-6KVT6WJI.js +0 -41
  164. package/dist/moves-E2HKYCTK.js +0 -41
  165. package/dist/plan-on-sale-TJPFCNL7.js +0 -26
  166. package/dist/src-CRO35DYY.js +0 -46
@@ -1,10 +1,80 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // src/import-door/host.ts
4
+ async function readBody(response) {
5
+ return response.json().catch((error) => {
6
+ if (response.ok) throw error;
7
+ return {};
8
+ });
9
+ }
10
+ async function readError(response) {
11
+ const body = await response.json().catch(() => ({}));
12
+ return body.error?.message ?? `HTTP ${response.status}`;
13
+ }
14
+ function sessionHost(base, headers, fetcher = fetch, outside = fetcher) {
15
+ return {
16
+ async call(name, input) {
17
+ const response = await fetcher(`${base}/api/v1/op/${encodeURIComponent(name)}`, {
18
+ method: "POST",
19
+ headers: {
20
+ "content-type": "application/json",
21
+ "idempotency-key": crypto.randomUUID(),
22
+ ...await headers()
23
+ },
24
+ body: JSON.stringify(input)
25
+ });
26
+ const body = await readBody(response);
27
+ if (!response.ok || body.error) {
28
+ throw Object.assign(new Error(body.error?.message ?? `${name}: HTTP ${response.status}`), {
29
+ code: body.error?.code,
30
+ details: body.error?.details
31
+ });
32
+ }
33
+ return body.data;
34
+ },
35
+ async upload(bytes, name) {
36
+ const response = await fetcher(`${base}/api/v1/media?${new URLSearchParams({ name })}`, {
37
+ method: "POST",
38
+ headers: { "content-type": "application/octet-stream", ...await headers() },
39
+ body: new Uint8Array(bytes)
40
+ });
41
+ const body = await readBody(response);
42
+ if (!response.ok || !body.data) {
43
+ throw new Error(`${name}: ${body.error?.message ?? `HTTP ${response.status}`}`);
44
+ }
45
+ return body.data;
46
+ },
47
+ async uploadCaption(id, language, label, vtt) {
48
+ const query = new URLSearchParams({ language, label });
49
+ const response = await fetcher(
50
+ `${base}/api/v1/media/${encodeURIComponent(id)}/captions?${query}`,
51
+ {
52
+ method: "POST",
53
+ headers: { "content-type": "text/vtt", ...await headers() },
54
+ body: new Uint8Array(vtt)
55
+ }
56
+ );
57
+ if (!response.ok) throw new Error(`captions (${language}): ${await readError(response)}`);
58
+ },
59
+ send: (url, init) => outside(url, init)
60
+ };
61
+ }
62
+
3
63
  // src/import-door/sign-in.ts
4
64
  import { execFile } from "node:child_process";
5
65
  import { createServer } from "node:http";
6
66
  import { hostname } from "node:os";
7
67
 
68
+ // ../client/src/agreements.ts
69
+ var SIGNATURE_LIMITS = {
70
+ strokes: 30,
71
+ points: 5e3,
72
+ bytes: 32768,
73
+ /** The least ink, in box units, the host takes as a signature (not a dot or a tap). */
74
+ minLength: 120
75
+ };
76
+ var BYTES_BUDGET = SIGNATURE_LIMITS.bytes - 256;
77
+
8
78
  // ../client/src/binding.ts
9
79
  var SESSION_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
10
80
 
@@ -42,7 +112,11 @@ async function post(fetcher, url, body, headers = {}) {
42
112
  } catch (error) {
43
113
  throw new NetworkError("Could not reach the host to sign in", error);
44
114
  }
45
- const parsed = JSON.parse(await response.text());
115
+ let parsed = {};
116
+ try {
117
+ parsed = JSON.parse(await response.text());
118
+ } catch {
119
+ }
46
120
  if (response.status === 200 && parsed.data) return parsed.data;
47
121
  throw new ApiError(
48
122
  parsed.error?.code ?? "internal",
@@ -90,12 +164,18 @@ function tokenSession(options) {
90
164
  /**
91
165
  * Signs in with the emailed code and keeps the device session the host answers with. A wrong,
92
166
  * used or expired code throws `forbidden` (`invalid_code`). No cookie is involved.
167
+ *
168
+ * A customer signing in again in place (a sensitive act asked for a recent sign-in) names the
169
+ * device session it replaces by its refresh token (`replaces`): once the new sign-in has
170
+ * worked, the host ends that one, so it does not live on beside it. A wrong code ends nothing.
93
171
  */
94
172
  async signInWithCode(email, code, deviceName, audience = "customer") {
173
+ const previous = audience === "customer" ? await options.store.load() : null;
95
174
  const signedIn = await post(fetcher, `${base}/api/v1/auth/${audience}/sign-in`, {
96
175
  email,
97
176
  code,
98
- deviceName
177
+ deviceName,
178
+ ...previous?.refreshToken ? { replaces: previous.refreshToken } : {}
99
179
  });
100
180
  const { account: _account, ...tokens } = signedIn;
101
181
  await options.store.save(tokens);
@@ -273,6 +353,28 @@ async function signInForRun(host, email, io, label) {
273
353
  back.close();
274
354
  }
275
355
  }
356
+ function hostOf(flag, io) {
357
+ const host = flag?.replace(/\/+$/, "");
358
+ if (!host || !/^https?:\/\//.test(host)) {
359
+ io.err("--host is the host's address, e.g. https://admin.example.com");
360
+ return null;
361
+ }
362
+ return host;
363
+ }
364
+ async function withRunSession(host, email, io, label, work) {
365
+ let session;
366
+ try {
367
+ session = await signInForRun(host, email, io, label);
368
+ } catch (error) {
369
+ io.err(`Could not sign in: ${error.message}`);
370
+ return 1;
371
+ }
372
+ try {
373
+ return await work(sessionHost(host, () => session.headers()));
374
+ } finally {
375
+ await session.signOut();
376
+ }
377
+ }
276
378
  function confirmer(io, yes) {
277
379
  return async (summary) => {
278
380
  if (yes) return true;
@@ -285,63 +387,80 @@ function confirmer(io, yes) {
285
387
  };
286
388
  }
287
389
 
288
- // src/import-door/host.ts
289
- async function readError(response) {
290
- const body = await response.json().catch(() => ({}));
291
- return body.error?.message ?? `HTTP ${response.status}`;
390
+ // src/import-door/records.ts
391
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
392
+ function replaceMarked(value, marker, id) {
393
+ if (Array.isArray(value)) return value.map((v) => replaceMarked(v, marker, id));
394
+ if (!isObject(value)) return value;
395
+ if (typeof value[marker] === "string" && Object.keys(value).length === 1)
396
+ return id(value[marker]);
397
+ return Object.fromEntries(
398
+ Object.entries(value).map(([k, v]) => [k, replaceMarked(v, marker, id)])
399
+ );
292
400
  }
293
- function sessionHost(base, headers, fetcher = fetch, outside = fetcher) {
294
- return {
295
- async call(name, input) {
296
- const response = await fetcher(`${base}/api/v1/op/${encodeURIComponent(name)}`, {
297
- method: "POST",
298
- headers: {
299
- "content-type": "application/json",
300
- "idempotency-key": crypto.randomUUID(),
301
- ...await headers()
302
- },
303
- body: JSON.stringify(input)
304
- });
305
- const body = await response.json();
306
- if (!response.ok || body.error) {
307
- throw Object.assign(new Error(body.error?.message ?? `${name}: HTTP ${response.status}`), {
308
- code: body.error?.code,
309
- details: body.error?.details
310
- });
311
- }
312
- return body.data;
313
- },
314
- async upload(bytes, name) {
315
- const response = await fetcher(`${base}/api/v1/media?${new URLSearchParams({ name })}`, {
316
- method: "POST",
317
- headers: { "content-type": "application/octet-stream", ...await headers() },
318
- body: new Uint8Array(bytes)
319
- });
320
- const body = await response.json();
321
- if (!response.ok || !body.data) {
322
- throw new Error(`${name}: ${body.error?.message ?? `HTTP ${response.status}`}`);
323
- }
324
- return body.data;
325
- },
326
- async uploadCaption(id, language, label, vtt) {
327
- const query = new URLSearchParams({ language, label });
328
- const response = await fetcher(
329
- `${base}/api/v1/media/${encodeURIComponent(id)}/captions?${query}`,
330
- {
331
- method: "POST",
332
- headers: { "content-type": "text/vtt", ...await headers() },
333
- body: new Uint8Array(vtt)
334
- }
335
- );
336
- if (!response.ok) throw new Error(`captions (${language}): ${await readError(response)}`);
337
- },
338
- send: (url, init) => outside(url, init)
339
- };
401
+ var IMPORT_BATCH = 25;
402
+ var chunks = (list, size) => Array.from(
403
+ { length: Math.ceil(list.length / size) },
404
+ (_, i) => list.slice(i * size, (i + 1) * size)
405
+ );
406
+ async function sha256(value) {
407
+ const bytes = typeof value === "string" ? new TextEncoder().encode(value) : value;
408
+ const digest = await crypto.subtle.digest("SHA-256", new Uint8Array(bytes));
409
+ return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
410
+ }
411
+ async function importRecords(host, object, records, options) {
412
+ const out = [];
413
+ for (const part of chunks(records, IMPORT_BATCH)) {
414
+ const answer = await host.call("record.import", {
415
+ object,
416
+ records: part.map(({ key, values }) => ({ key, values })),
417
+ dryRun: options.dryRun,
418
+ checkReferences: options.checkReferences
419
+ });
420
+ for (const result of answer.results) {
421
+ const file = part.find((r) => r.key === result.key)?.file ?? null;
422
+ out.push({ ...result, object, file });
423
+ }
424
+ }
425
+ return out;
426
+ }
427
+ async function knownByHash(host, hashes) {
428
+ const known = /* @__PURE__ */ new Map();
429
+ for (const part of chunks([...new Set(hashes)], 200)) {
430
+ if (!part.length) continue;
431
+ const found = await host.call("media.findByHash", { sha256: part });
432
+ for (const item of found.items) known.set(item.sha256, item);
433
+ }
434
+ return known;
435
+ }
436
+ function outcomeLines(records, dryRun) {
437
+ const lines = [];
438
+ const by = (outcome) => records.filter((r) => r.outcome === outcome);
439
+ const verb = dryRun ? "would be" : "were";
440
+ for (const outcome of ["created", "updated", "unchanged"]) {
441
+ const list = by(outcome);
442
+ if (list.length) {
443
+ lines.push(`${list.length} record(s) ${outcome === "unchanged" ? "are" : verb} ${outcome}.`);
444
+ }
445
+ }
446
+ const conflicts = by("conflict");
447
+ if (conflicts.length) {
448
+ lines.push(`${conflicts.length} conflict(s), left as they are:`);
449
+ for (const c of conflicts) lines.push(` ${c.file ?? c.key}: ${c.problems.join("; ")}`);
450
+ }
451
+ return lines;
340
452
  }
341
453
 
342
454
  export {
343
- LOOPBACK_PATH,
455
+ sessionHost,
344
456
  signInForRun,
457
+ hostOf,
458
+ withRunSession,
345
459
  confirmer,
346
- sessionHost
460
+ isObject,
461
+ replaceMarked,
462
+ sha256,
463
+ importRecords,
464
+ knownByHash,
465
+ outcomeLines
347
466
  };
@@ -43,7 +43,7 @@ import {
43
43
  withDeploymentVar,
44
44
  workersDevHostname,
45
45
  writeDeploymentState
46
- } from "./chunk-DU6OIFOU.js";
46
+ } from "./chunk-3OGDWKJ3.js";
47
47
  import {
48
48
  PROVIDER_INFO,
49
49
  ROLE_PRESETS,
@@ -53,10 +53,12 @@ import {
53
53
  import {
54
54
  DEFAULT_PRODUCT,
55
55
  products
56
- } from "./chunk-2ABSVMGB.js";
56
+ } from "./chunk-SMJZIK2O.js";
57
57
  import {
58
- PRODUCT_LABEL_VAR
59
- } from "./chunk-6UWRT4VM.js";
58
+ LOCATION_HINTS,
59
+ PRODUCT_LABEL_VAR,
60
+ isLocationHint
61
+ } from "./chunk-ZJSFX4RD.js";
60
62
 
61
63
  // src/io.ts
62
64
  import { createInterface } from "node:readline/promises";
@@ -143,7 +145,22 @@ A client repo (stage 24)
143
145
  copy a block from the release; show its upstream changes
144
146
  (--accept: record them as merged by hand)
145
147
  (cos add with no block lists them, with their skins)
146
- cos client generate in a client repo: each app's typed client, again
148
+ cos client generate in a client repo: each app's typed client, again (and
149
+ the mobile app's brand.ts from product.ts)
150
+ cos app check the mobile app before a store build: ids, icon, listing,
151
+ nothing bought in the app, "Delete my account", no key
152
+ file in the repo (stage 63, docs/app-publishing.md)
153
+ cos app credentials [--check --for ios|android|record]
154
+ the app workflow's secrets and how a person sets each;
155
+ never a value (--check: fail on any one missing)
156
+ cos app build-info [--env <name>] [--json]
157
+ the next build number (the host's records) and the API
158
+ version of the app's generated client
159
+ cos app record [--env <name>] --platform ios,android --build <n> [--commit <sha>]
160
+ record the builds a run sent to the testing tracks
161
+ cos app upload --platform android [--env <name>] --file <app.aab> [--listing] [--draft]
162
+ the Android build to the store's internal testing track;
163
+ nothing is released to the public
147
164
  cos content import <folder> --host <url> [--email <you>] [--dry-run] [--publish] [--yes]
148
165
  load posts and their pictures into the host as you,
149
166
  signed in for the run (by code with --email, else in the
@@ -169,6 +186,17 @@ A client repo (stage 24)
169
186
  cos subscriptions offers report --host <url> [--status taken] [--out <file.csv>]
170
187
  who has taken their offer and when they are charged from,
171
188
  so you end exactly those old subscriptions
189
+ cos programs import <folder> --host <url> [--email <you>] [--dry-run]
190
+ load exercises, class types, programs in the pack's
191
+ shorthand and past training (sessions and their sets), as
192
+ you; checks everything first, a re-run makes nothing
193
+ twice, an edit since is kept; what it brings in starts no
194
+ automation and sends no message (docs/importing.md)
195
+ cos rostering import <roster.csv> --host <url> [--email <you>] [--apply]
196
+ duties and who works them (weekly patterns, one-off
197
+ shifts); the host checks every date for someone on two
198
+ shifts at once and names it; a dry run unless --apply;
199
+ staff are invited first, never made (docs/importing.md)
172
200
 
173
201
  Installing a product with no client repo
174
202
  cos install [options] install, or repair an existing install (idempotent)
@@ -195,6 +223,11 @@ Options
195
223
  --hostname <h> "workers.dev" (default) or a hostname on one of your zones
196
224
  --zone <name> the zone of a custom hostname (default: inferred from it)
197
225
  --identity <i> better-auth (default) or cloudflare-access
226
+ --location <hint> a location hint for the D1 database and R2 buckets a first install
227
+ creates: none (default), or ${Object.keys(LOCATION_HINTS).join(", ")}
228
+ (oc is Oceania). A preference Cloudflare follows where it can, not a
229
+ guarantee; KV, queues and Vectorize take none. An existing install is
230
+ never moved (docs/deploying.md "Where data is stored")
198
231
  --gatekeepers <list> optional gatekeeper Workers to install, e.g. google,email-send
199
232
  --ai <on|off> in-app AI: Workers AI and the demo-records Vectorize index (default on,
200
233
  or COS_AI). Off: AI features say "AI is not configured". Upgrades keep
@@ -262,7 +295,11 @@ function parseArgs(argv) {
262
295
  "dry-run",
263
296
  "publish",
264
297
  "invite",
265
- "reissue"
298
+ "reissue",
299
+ "apply",
300
+ "check",
301
+ "listing",
302
+ "draft"
266
303
  ].includes(key);
267
304
  let value = true;
268
305
  if (takesValue) {
@@ -280,6 +317,7 @@ var CliError = class extends Error {
280
317
  };
281
318
  var PACKS_VAR = "COS_PACKS";
282
319
  var CUSTOMER_SECRET = "CUSTOMER_AUTH_SECRET";
320
+ var DESK_SECRET = "DESK_SECRET";
283
321
  var ORG_EXTENSIONS_VAR = "COS_ORG_EXTENSIONS";
284
322
  function str(flags, key) {
285
323
  const value = flags[key];
@@ -448,11 +486,25 @@ function aiChoice(flags, env) {
448
486
  if (value === "off" || value === "false") return false;
449
487
  throw new CliError("--ai is on or off");
450
488
  }
489
+ function locationChoice(flags) {
490
+ const value = str(flags, "location")?.trim().toLowerCase();
491
+ if (value === void 0 || value === "") return void 0;
492
+ if (value === "none" || isLocationHint(value)) return value;
493
+ throw new CliError(
494
+ `--location is none or a location hint: ${Object.keys(LOCATION_HINTS).join(", ")}`
495
+ );
496
+ }
497
+ function describeLocation(hint) {
498
+ return hint ? `${hint} (${LOCATION_HINTS[hint]})` : "none";
499
+ }
451
500
  function randomSecret() {
452
501
  return toHex(crypto.getRandomValues(new Uint8Array(32)));
453
502
  }
454
503
  var FAKE_PROVIDER_VAR = "PAYMENTS_FAKE_PROVIDER";
455
504
  var FAKE_SECRET = "FAKE_WEBHOOK_SECRET";
505
+ function fakeProviderOn(vars) {
506
+ return vars?.[FAKE_PROVIDER_VAR] === "true" || vars?.TEXT_PROVIDER === "fake";
507
+ }
456
508
  function generateFakePaymentsSecrets(manifest, gatekeepers, vars, secrets, stored, redactor) {
457
509
  for (const name of gatekeepers) {
458
510
  const worker = manifest.workers.find((w) => w.name === name);
@@ -461,7 +513,7 @@ function generateFakePaymentsSecrets(manifest, gatekeepers, vars, secrets, store
461
513
  const { [FAKE_SECRET]: _plain, ...rest } = vars[name];
462
514
  vars[name] = rest;
463
515
  }
464
- if (vars[name]?.[FAKE_PROVIDER_VAR] !== "true") continue;
516
+ if (!fakeProviderOn(vars[name])) continue;
465
517
  if (stored.get(name)?.includes(FAKE_SECRET) || secrets[name]?.[FAKE_SECRET]) continue;
466
518
  const secret = randomSecret();
467
519
  redactor.add(secret);
@@ -554,6 +606,24 @@ async function install(flags, deps) {
554
606
  if (identity !== "better-auth" && identity !== "cloudflare-access") {
555
607
  throw new CliError("--identity is better-auth or cloudflare-access");
556
608
  }
609
+ const locationFlag = locationChoice(flags);
610
+ let locationHint = previous?.locationHint;
611
+ if (!previous) {
612
+ let choice = locationFlag;
613
+ if (choice === void 0 && io.interactive && !flags.yes) {
614
+ choice = await choose(
615
+ io,
616
+ "Data location hint for the new database and file bucket (a preference Cloudflare follows where it can, not a guarantee; oc is Oceania):",
617
+ ["none", ...Object.keys(LOCATION_HINTS)],
618
+ "none"
619
+ );
620
+ }
621
+ locationHint = choice === void 0 || choice === "none" ? void 0 : choice;
622
+ } else if (locationFlag !== void 0 && (locationFlag === "none" ? void 0 : locationFlag) !== previous.locationHint) {
623
+ io.out(
624
+ `Location: this host exists, made with location hint ${describeLocation(previous.locationHint)}. Its database and file buckets stay where Cloudflare put them: a setting cannot move them (moving one is an export into a new install). --location ${locationFlag} changes nothing here.`
625
+ );
626
+ }
557
627
  const optional = manifest.workers.filter((w) => w.optional);
558
628
  const requested = (str(flags, "gatekeepers") ?? "").split(",").map((g) => g.trim()).filter(Boolean).map(
559
629
  (g) => g.startsWith(s.product.names.gatekeeperPrefix) ? g : `${s.product.names.gatekeeperPrefix}${g}`
@@ -585,6 +655,12 @@ async function install(flags, deps) {
585
655
  deps.redactor.add(appSecrets.BETTER_AUTH_SECRET);
586
656
  }
587
657
  appSecrets.BETTER_AUTH_URL ??= `https://${hostname}`;
658
+ if (hostnameMode === "custom" && !appSet.includes(DESK_SECRET) && !appSecrets[DESK_SECRET]) {
659
+ let secret = randomSecret();
660
+ while (secret === appSecrets.BETTER_AUTH_SECRET) secret = randomSecret();
661
+ appSecrets[DESK_SECRET] = secret;
662
+ deps.redactor.add(secret);
663
+ }
588
664
  const customerAuthUrl = str(flags, "customer-auth-url");
589
665
  if (customerAuthUrl !== void 0) {
590
666
  if (!/^https?:\/\/[^/]+$/.test(customerAuthUrl)) {
@@ -695,6 +771,11 @@ async function install(flags, deps) {
695
771
  Installing ${s.product.label} ${version} into account ${s.accountId} at https://${hostname}`
696
772
  );
697
773
  if (!ai) io.out("In-app AI is off (--ai off): no Workers AI or Vectorize bindings.");
774
+ if (!previous && locationHint) {
775
+ io.out(
776
+ `Location hint: ${describeLocation(locationHint)}, sent when the D1 database and R2 buckets are created. Cloudflare follows it where it can; it is not a guarantee of where data is kept, and KV, queues, Vectorize and logs take no hint.`
777
+ );
778
+ }
698
779
  io.out("Resources:");
699
780
  const resources = {
700
781
  ...previous?.resources ?? {},
@@ -703,7 +784,8 @@ Installing ${s.product.label} ${version} into account ${s.accountId} at https://
703
784
  s.accountId,
704
785
  neededResources(manifest, gatekeepers, { ai }),
705
786
  (l) => io.out(l),
706
- previous?.resourceNames ?? names?.resources
787
+ previous?.resourceNames ?? names?.resources,
788
+ { locationHint }
707
789
  )
708
790
  };
709
791
  const base = {
@@ -724,6 +806,7 @@ Installing ${s.product.label} ${version} into account ${s.accountId} at https://
724
806
  ...previous?.resourceNames ? { resourceNames: previous.resourceNames } : names && Object.keys(names.resources).length ? { resourceNames: names.resources } : {},
725
807
  vars,
726
808
  ...sendEmail && Object.keys(sendEmail).length ? { sendEmail } : {},
809
+ ...locationHint ? { locationHint } : {},
727
810
  resources,
728
811
  bundleDigest: digest,
729
812
  installedAt: previous?.installedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
@@ -840,6 +923,12 @@ async function upgrade(flags, deps) {
840
923
  const { io } = deps;
841
924
  const s = await session(flags, deps);
842
925
  const { databaseId, state: found } = await locate(s, flags);
926
+ const locationFlag = locationChoice(flags);
927
+ if (locationFlag !== void 0) {
928
+ io.out(
929
+ `Location: an upgrade never changes where data is stored. This host was made with location hint ${describeLocation(found.locationHint)}; its database and file buckets stay where they are (moving one is an export into a new install). --location changes nothing.`
930
+ );
931
+ }
843
932
  const channel = found.channel;
844
933
  const target = str(flags, "version") ?? await latestVersion(s, channel);
845
934
  if (compareVersions(target, found.version) <= 0) {
@@ -1012,6 +1101,9 @@ async function status(flags, deps) {
1012
1101
  io.out(
1013
1102
  ` sign-in: ${state.identityProvider}; gatekeepers: ${state.gatekeepers.join(", ") || "none"}; AI: ${state.ai === false ? "off" : "on"}`
1014
1103
  );
1104
+ io.out(
1105
+ ` location hint at install: ${describeLocation(state.locationHint)} (a preference, not a guarantee)`
1106
+ );
1015
1107
  io.out(
1016
1108
  newer.length ? ` available: ${newer.map((r) => r.version).join(", ")} (run \`cos upgrade\`)` : " up to date"
1017
1109
  );
@@ -1082,7 +1174,7 @@ async function uninstall(flags, deps) {
1082
1174
  async function ext(argv, deps) {
1083
1175
  let runExt;
1084
1176
  try {
1085
- ({ runExt } = await import("./cli-UYZMVQMR.js"));
1177
+ ({ runExt } = await import("./cli-VYSD2S4Z.js"));
1086
1178
  return await runExt(argv, deps.io);
1087
1179
  } catch (error) {
1088
1180
  if (error.code === "ERR_MODULE_NOT_FOUND") {
@@ -1096,7 +1188,7 @@ async function ext(argv, deps) {
1096
1188
  }
1097
1189
  async function client(argv, deps) {
1098
1190
  if (argv[0] === "generate" && !argv.includes("--out")) {
1099
- const repo = await import("./client-repo-SE4EKG6W.js");
1191
+ const repo = await import("./client-repo-MPCPTXLF.js");
1100
1192
  const parsed = parseArgs(["client", ...argv.slice(1)]);
1101
1193
  const dir = str(parsed.flags, "dir") ?? process.cwd();
1102
1194
  if (repo.isClientRepo(dir)) {
@@ -1110,7 +1202,7 @@ async function client(argv, deps) {
1110
1202
  }
1111
1203
  }
1112
1204
  try {
1113
- const { runClient } = await import("./cli-5UNY5G5L.js");
1205
+ const { runClient } = await import("./cli-OKQHHSOE.js");
1114
1206
  return await runClient(argv, deps.io);
1115
1207
  } catch (error) {
1116
1208
  if (error.code === "ERR_MODULE_NOT_FOUND") {
@@ -1138,7 +1230,7 @@ async function content(argv, deps) {
1138
1230
  deps.io.err(error.message);
1139
1231
  return 2;
1140
1232
  }
1141
- const { contentImport } = await import("./run-PO3W5BFA.js");
1233
+ const { contentImport } = await import("./run-TJAEWR5U.js");
1142
1234
  try {
1143
1235
  return await contentImport(
1144
1236
  positional,
@@ -1176,7 +1268,7 @@ async function courses(argv, deps) {
1176
1268
  deps.io.err("--wait is minutes, a whole number");
1177
1269
  return 2;
1178
1270
  }
1179
- const { coursesImport } = await import("./run-7P4RQALH.js");
1271
+ const { coursesImport } = await import("./run-FH7OGGTV.js");
1180
1272
  try {
1181
1273
  return await coursesImport(
1182
1274
  positional,
@@ -1195,8 +1287,68 @@ async function courses(argv, deps) {
1195
1287
  return 1;
1196
1288
  }
1197
1289
  }
1290
+ async function programsCommand(argv, deps) {
1291
+ const { PROGRAMS_USAGE, programsImport } = await import("./run-OYZIAP6M.js");
1292
+ if (argv[0] !== "import") {
1293
+ deps.io.err(PROGRAMS_USAGE);
1294
+ return 2;
1295
+ }
1296
+ const rest = argv.slice(1);
1297
+ const positional = rest[0] && !rest[0].startsWith("-") ? [rest[0]] : [];
1298
+ let parsed;
1299
+ try {
1300
+ parsed = parseArgs(["import", ...rest.slice(positional.length)]);
1301
+ } catch (error) {
1302
+ deps.io.err(error.message);
1303
+ return 2;
1304
+ }
1305
+ try {
1306
+ return await programsImport(
1307
+ positional,
1308
+ {
1309
+ ...str(parsed.flags, "host") ? { host: str(parsed.flags, "host") } : {},
1310
+ ...str(parsed.flags, "email") ? { email: str(parsed.flags, "email") } : {},
1311
+ dryRun: Boolean(parsed.flags["dry-run"])
1312
+ },
1313
+ deps.io
1314
+ );
1315
+ } catch (error) {
1316
+ deps.io.err(`Error: ${error.message}`);
1317
+ return 1;
1318
+ }
1319
+ }
1320
+ async function rostering(argv, deps) {
1321
+ const { ROSTER_USAGE, rosteringImport } = await import("./run-7ID64RA6.js");
1322
+ if (argv[0] !== "import") {
1323
+ deps.io.err(ROSTER_USAGE);
1324
+ return 2;
1325
+ }
1326
+ const rest = argv.slice(1);
1327
+ const positional = rest[0] && !rest[0].startsWith("-") ? [rest[0]] : [];
1328
+ let parsed;
1329
+ try {
1330
+ parsed = parseArgs(["import", ...rest.slice(positional.length)]);
1331
+ } catch (error) {
1332
+ deps.io.err(error.message);
1333
+ return 2;
1334
+ }
1335
+ try {
1336
+ return await rosteringImport(
1337
+ positional,
1338
+ {
1339
+ ...str(parsed.flags, "host") ? { host: str(parsed.flags, "host") } : {},
1340
+ ...str(parsed.flags, "email") ? { email: str(parsed.flags, "email") } : {},
1341
+ apply: Boolean(parsed.flags.apply)
1342
+ },
1343
+ deps.io
1344
+ );
1345
+ } catch (error) {
1346
+ deps.io.err(`Error: ${error.message}`);
1347
+ return 1;
1348
+ }
1349
+ }
1198
1350
  async function subscriptions(argv, deps) {
1199
- const { OFFERS_USAGE, offersImport, offersReport } = await import("./run-ZCGFMEZF.js");
1351
+ const { OFFERS_USAGE, offersImport, offersReport } = await import("./run-QOFRRSZV.js");
1200
1352
  if (argv[0] !== "offers" || argv[1] !== "import" && argv[1] !== "report") {
1201
1353
  deps.io.err(OFFERS_USAGE);
1202
1354
  return 2;
@@ -1243,8 +1395,11 @@ async function runCli(argv, input) {
1243
1395
  if (argv[0] === "content") return content(argv.slice(1), deps);
1244
1396
  if (argv[0] === "courses") return courses(argv.slice(1), deps);
1245
1397
  if (argv[0] === "subscriptions") return subscriptions(argv.slice(1), deps);
1398
+ if (argv[0] === "rostering") return rostering(argv.slice(1), deps);
1399
+ if (argv[0] === "programs") return programsCommand(argv.slice(1), deps);
1246
1400
  if (argv[0] === "ext") return ext(argv.slice(1), deps);
1247
1401
  if (argv[0] === "client") return client(argv.slice(1), deps);
1402
+ if (argv[0] === "app") return (await import("./app-OSPZHKOI.js")).runApp(argv.slice(1), deps);
1248
1403
  const positional = ["create", "add", "diff"].includes(argv[0] ?? "") && argv[1] && !argv[1].startsWith("-") ? [argv[1]] : [];
1249
1404
  let parsed;
1250
1405
  try {
@@ -1257,8 +1412,8 @@ async function runCli(argv, input) {
1257
1412
  deps.io.out(HELP);
1258
1413
  return argv.length ? 0 : 2;
1259
1414
  }
1260
- const repo = await import("./client-repo-SE4EKG6W.js");
1261
- const blocks = await import("./blocks-5IFU25J6.js");
1415
+ const repo = await import("./client-repo-MPCPTXLF.js");
1416
+ const blocks = await import("./blocks-6DZIP47W.js");
1262
1417
  const commands = {
1263
1418
  install,
1264
1419
  // In a client repo (its product.ts is a client product), `cos upgrade` moves the repo to a
@@ -1291,6 +1446,7 @@ ${HELP}`);
1291
1446
  export {
1292
1447
  Redactor,
1293
1448
  terminalIo,
1449
+ parseArgs,
1294
1450
  CliError,
1295
1451
  str,
1296
1452
  releaseSource,
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  VerificationError,
4
4
  releaseAssetNames
5
- } from "./chunk-DU6OIFOU.js";
5
+ } from "./chunk-3OGDWKJ3.js";
6
6
 
7
7
  // src/gh.ts
8
8
  import { execFile } from "node:child_process";