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

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-RPRZMLU5.js +43 -0
  3. package/dist/app-upload-YJVEKZC6.js +198 -0
  4. package/dist/{blocks-5IFU25J6.js → blocks-DE4RRWPJ.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-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
  10. package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
  11. package/dist/chunk-EPDTPGZJ.js +330 -0
  12. package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
  13. package/dist/chunk-HCG6T53D.js +61904 -0
  14. package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
  15. package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
  16. package/dist/chunk-KMFMD52Z.js +13276 -0
  17. package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
  18. package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
  19. package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
  20. package/dist/{chunk-MBIKVRAC.js → chunk-QJZGYJVV.js} +823 -44
  21. package/dist/{chunk-PDD2ETVF.js → chunk-QQ3YSL5F.js} +172 -16
  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-NNUCHQ2Y.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,9 +1,14 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ isObject,
4
+ replaceMarked
5
+ } from "./chunk-LX2TTLVY.js";
2
6
  import {
3
7
  MEDIA_CAPTION_MAX_BYTES,
4
8
  mediaProblem,
9
+ slugify,
5
10
  sniffFileType
6
- } from "./chunk-LO6WGU5Y.js";
11
+ } from "./chunk-U72NEGCT.js";
7
12
 
8
13
  // src/courses-import/format.ts
9
14
  var COURSE = "courses.course";
@@ -17,7 +22,6 @@ var LESSON_KEY_RE = /^[a-z0-9-]{1,40}$/;
17
22
  var EMAIL_RE = /^[^\s@,]+@[^\s@,]+\.[^\s@,]+$/;
18
23
  var DATETIME_RE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2}))?$/;
19
24
  var MEDIA = "$media";
20
- var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
21
25
  function parseCsv(text) {
22
26
  const rows = [];
23
27
  let cells = [];
@@ -65,7 +69,6 @@ function srtToVtt(srt) {
65
69
  ${body.trim()}
66
70
  `;
67
71
  }
68
- var slugify = (text) => text.toLowerCase().normalize("NFKD").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 120);
69
72
  function readCoursesFolder(folder) {
70
73
  const problems = [];
71
74
  const videos = /* @__PURE__ */ new Map();
@@ -270,6 +273,7 @@ function readCoursesFolder(folder) {
270
273
  programs
271
274
  });
272
275
  }
276
+ const bundleFiles = /* @__PURE__ */ new Map();
273
277
  for (const [file, text] of [...folder.bundles].sort(([a], [b]) => a.localeCompare(b))) {
274
278
  const path = `bundles/${file}`;
275
279
  const fault = (message) => problems.push({ file: path, message });
@@ -285,6 +289,9 @@ function readCoursesFolder(folder) {
285
289
  continue;
286
290
  }
287
291
  const key = typeof raw.key === "string" ? raw.key : file.replace(/\.json$/i, "");
292
+ if (!KEY_RE.test(key)) fault(`The key "${key}" is not 1 to 100 letters, digits or ._:-`);
293
+ if (bundleFiles.has(key)) fault(`The key "${key}" is ${bundleFiles.get(key)}'s too`);
294
+ bundleFiles.set(key, path);
288
295
  const values = {};
289
296
  for (const name of ["title", "slug", "summary", "price"]) {
290
297
  if (raw[name] !== void 0) values[name] = raw[name];
@@ -408,10 +415,7 @@ function readCoursesFolder(folder) {
408
415
  };
409
416
  }
410
417
  function withMedia(value, id) {
411
- if (Array.isArray(value)) return value.map((v) => withMedia(v, id));
412
- if (!isObject(value)) return value;
413
- if (typeof value[MEDIA] === "string" && Object.keys(value).length === 1) return id(value[MEDIA]);
414
- return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, withMedia(v, id)]));
418
+ return replaceMarked(value, MEDIA, id);
415
419
  }
416
420
 
417
421
  export {
@@ -2,80 +2,64 @@
2
2
  import {
3
3
  changeOrder,
4
4
  createOrder,
5
- loadOrderRow
6
- } from "./chunk-6WGFA2IV.js";
7
- import {
8
- createRecord,
9
- updateRecord
10
- } from "./chunk-WHKJGF36.js";
11
- import {
12
- onEveryRecordMove,
13
- onRecordMove
14
- } from "./chunk-324WJXNP.js";
15
- import {
16
5
  creatorFor,
6
+ erasedAddresses,
7
+ loadOrderRow,
17
8
  normaliseCustomerEmail,
18
9
  sameEmailPeople
19
- } from "./chunk-7OGCMQXG.js";
20
- import {
21
- erasedAddresses
22
- } from "./chunk-XIDLW3EP.js";
23
- import {
24
- loadOrderCurrency,
25
- toMinorUnits
26
- } from "./chunk-6ELZRNUU.js";
27
- import {
28
- notifyStatements
29
- } from "./chunk-ZZFWMVJO.js";
10
+ } from "./chunk-2B6YUYZV.js";
30
11
  import {
31
12
  UNREADABLE,
32
13
  assertCreateRules,
33
14
  boundMoment,
15
+ createRecord,
34
16
  guardStatement,
17
+ guestMinorNotice,
18
+ loadOrderCurrency,
35
19
  newId,
20
+ notifyStatements,
21
+ onEveryRecordMove,
22
+ onRecordMove,
36
23
  pathReader,
37
- recordHostChange
38
- } from "./chunk-2XC5JLBO.js";
24
+ recordHostChange,
25
+ sha256Hex,
26
+ toHex,
27
+ toMinorUnits,
28
+ updateRecord,
29
+ viewRow
30
+ } from "./chunk-KMFMD52Z.js";
39
31
  import {
40
- ConfigError,
41
- ConflictError,
42
- NotFoundError,
43
- UnknownOperationError,
44
- ValidationError,
45
32
  isLiveDependant,
46
33
  linkGuardStatement,
47
34
  orgReader,
35
+ placedAs,
48
36
  staffPrincipal,
49
37
  viewColumnOf,
50
38
  visibleSource
51
- } from "./chunk-6XTU2MTP.js";
39
+ } from "./chunk-KFHKNXGH.js";
52
40
  import {
53
41
  getObject,
54
42
  listObjects
55
- } from "./chunk-YFTLIEWU.js";
43
+ } from "./chunk-RSEWEFAV.js";
44
+ import {
45
+ ConfigError,
46
+ ConflictError,
47
+ NotFoundError,
48
+ UnknownOperationError,
49
+ ValidationError
50
+ } from "./chunk-RGKJKC5T.js";
56
51
 
57
- // ../core/src/orders/guests.ts
58
- var hex = (bytes) => [...new Uint8Array(bytes)].map((b) => b.toString(16).padStart(2, "0")).join("");
59
- function newOrderToken() {
60
- return hex(crypto.getRandomValues(new Uint8Array(32)).buffer);
61
- }
62
- var ORDER_TOKEN = /^[0-9a-f]{64}$/;
63
- async function hashOrderToken(token) {
64
- return hex(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(token)));
65
- }
66
- async function orderForToken(db, id, token, now) {
67
- if (!ORDER_TOKEN.test(token)) return null;
68
- const hash = await hashOrderToken(token);
69
- const row = await db.selectFrom("core_order").selectAll().where((eb) => eb.or([eb("access_hash", "=", hash), eb("email_link_hash", "=", hash)])).executeTakeFirst();
70
- if (!row || row.id !== id) return null;
71
- if (row.access_until !== null && row.access_until <= now) return null;
72
- return row;
73
- }
74
- async function resolveBuyer(ctx, address) {
52
+ // ../core/src/customers/address-person.ts
53
+ var ADDRESS_REFUSED = "That email address cannot be used";
54
+ async function usableAddress(ctx, address) {
75
55
  const email = normaliseCustomerEmail(address);
76
- const refused = () => new ValidationError("That email address cannot be used", { field: "email" });
56
+ const refused = () => new ValidationError(ADDRESS_REFUSED, { field: "email" });
77
57
  if (!email) throw refused();
78
58
  if ((await erasedAddresses(ctx.db, [email])).size > 0) throw refused();
59
+ return email;
60
+ }
61
+ async function personForAddress(ctx, address, options) {
62
+ const email = await usableAddress(ctx, address);
79
63
  const matches = await sameEmailPeople(ctx.db, email);
80
64
  if (matches.length === 1) return { email, personId: matches[0], created: false };
81
65
  if (matches.length > 1) {
@@ -84,10 +68,10 @@ async function resolveBuyer(ctx, address) {
84
68
  {
85
69
  to: [{ role: "admin" }],
86
70
  type: "system.message",
87
- title: "An order was placed with an address several people have",
88
- body: `${matches.length} people have ${email}. The order belongs to none of them yet: merge them, then set the order's person.`,
71
+ title: options.several.title,
72
+ body: options.several.body(matches.length, email),
89
73
  link: { kind: "record", object: "person", id: matches[0] },
90
- dedupeKey: `order.several_people:${email}`,
74
+ dedupeKey: options.several.dedupeKey,
91
75
  source: { actor: "system" }
92
76
  },
93
77
  ctx.now
@@ -96,20 +80,51 @@ async function resolveBuyer(ctx, address) {
96
80
  return { email, personId: null, created: false };
97
81
  }
98
82
  const creator = await creatorFor(ctx.db, email);
99
- if (!creator) throw new ConfigError("There is no admin to create the buyer's Person for");
100
- const { personCreate } = await import("./person-UHLVBVLR.js");
83
+ if (!creator) throw new ConfigError("There is no admin to create the Person for");
84
+ const { personCreate } = await import("./person-YOZTFV4Q.js");
101
85
  const asCreator = Object.create(ctx, {
102
86
  user: { value: creator },
103
87
  actor: { value: "automation" },
104
88
  principal: { value: staffPrincipal(creator) },
105
- // The Person is the host's to create for the order: not the guest's write.
89
+ // The Person is the host's to create for the caller: not the caller's write.
106
90
  recordChange: { value: (change) => recordHostChange(ctx, change) }
107
91
  });
108
- const input = personCreate.input.parse({ emails: [{ email, primary: true }] });
92
+ const { displayName, phone } = options.create ?? {};
93
+ const input = personCreate.input.parse({
94
+ emails: [{ email, primary: true }],
95
+ ...displayName ? { displayName } : {},
96
+ ...phone ? { phones: [{ number: phone, primary: true }] } : {}
97
+ });
109
98
  const person = await personCreate.handler(input, asCreator);
110
99
  return { email, personId: person.id, created: true };
111
100
  }
112
101
 
102
+ // ../core/src/orders/guests.ts
103
+ function newOrderToken() {
104
+ return toHex(crypto.getRandomValues(new Uint8Array(32)));
105
+ }
106
+ var ORDER_TOKEN = /^[0-9a-f]{64}$/;
107
+ function hashOrderToken(token) {
108
+ return sha256Hex(token);
109
+ }
110
+ async function orderForToken(db, id, token, now) {
111
+ if (!ORDER_TOKEN.test(token)) return null;
112
+ const hash = await hashOrderToken(token);
113
+ const row = await db.selectFrom("core_order").selectAll().where((eb) => eb.or([eb("access_hash", "=", hash), eb("email_link_hash", "=", hash)])).executeTakeFirst();
114
+ if (!row || row.id !== id) return null;
115
+ if (row.access_until !== null && row.access_until <= now) return null;
116
+ return row;
117
+ }
118
+ async function resolveBuyer(ctx, address) {
119
+ return personForAddress(ctx, address, {
120
+ several: {
121
+ title: "An order was placed with an address several people have",
122
+ body: (count, email) => `${count} people have ${email}. The order belongs to none of them yet: merge them, then set the order's person.`,
123
+ dedupeKey: `order.several_people:${normaliseCustomerEmail(address) ?? address}`
124
+ }
125
+ });
126
+ }
127
+
113
128
  // ../core/src/orders/moves.ts
114
129
  function movesOf(object) {
115
130
  return object?.sellable?.moves;
@@ -307,6 +322,7 @@ async function startHeld(ctx, input) {
307
322
  quantity: 1,
308
323
  unitPrice,
309
324
  total: unitPrice,
325
+ discount: 0,
310
326
  deposit: null
311
327
  };
312
328
  const started = await createOrder(ctx, {
@@ -314,12 +330,16 @@ async function startHeld(ctx, input) {
314
330
  priced: [line],
315
331
  lines: [{ object: object.name, id: recordId, quantity: 1 }],
316
332
  personId: payer,
333
+ // Who it is for: the booking's Person (a child a guardian buys for), not only who pays.
334
+ participantId: holder,
317
335
  email,
318
- placedAs: caller.kind,
336
+ placedAs: placedAs(caller),
319
337
  pay: "full",
320
- accessHash: token ? await hashOrderToken(token) : null
338
+ accessHash: token ? await hashOrderToken(token) : null,
339
+ agreements: input.agreements,
340
+ code: input.code
321
341
  });
322
- return { row: started.row, lines: started.lines, recordId, token };
342
+ return { ...started, recordId, token };
323
343
  }
324
344
  var movingNow = /* @__PURE__ */ new WeakMap();
325
345
  async function whileMoving(ctx, id, run) {
@@ -338,7 +358,7 @@ async function whileMoving(ctx, id, run) {
338
358
  }
339
359
  var isMoving = (ctx, id) => movingNow.get(ctx.write)?.has(id) === true;
340
360
  async function storedValues(ctx, object, id) {
341
- const row = await ctx.db.selectFrom(visibleSource(orgReader(ctx.db), object)).selectAll().where("id", "=", id).executeTakeFirst();
361
+ const row = await viewRow(ctx.db, visibleSource(orgReader(ctx.db), object), id);
342
362
  if (!row) return null;
343
363
  const values = {};
344
364
  for (const field of object.fields) {
@@ -530,6 +550,8 @@ var orderMoves = async (outer, move) => {
530
550
  const to = move.to.id;
531
551
  const paid = to === "paid" || to === "part_paid";
532
552
  if (!paid && to !== "expired" && to !== "cancelled") return;
553
+ if (from === "paid") return;
554
+ const later = from === "part_paid";
533
555
  const lines = await ctx.db.selectFrom("core_order_line").select(["object_type", "record_id", "title"]).where("order_id", "=", move.id).execute();
534
556
  for (const line of lines) {
535
557
  const object = getObject(line.object_type);
@@ -546,6 +568,7 @@ var orderMoves = async (outer, move) => {
546
568
  { order: move.id, rule: "held_gone" }
547
569
  );
548
570
  }
571
+ if (later && state === moves.paid) continue;
549
572
  if (state === moves.held && values) {
550
573
  const ownerField = object.customer?.field;
551
574
  let personId = null;
@@ -567,6 +590,7 @@ var orderMoves = async (outer, move) => {
567
590
  }
568
591
  personId = buyer.personId;
569
592
  made = buyer.created;
593
+ if (personId && !made) await guestMinorNotice(ctx, { orderId: move.id }, personId);
570
594
  if (personId) {
571
595
  ctx.write(
572
596
  ctx.db.updateTable("core_order").set({ person_id: personId }).where("id", "=", move.id).where("person_id", "is", null)
@@ -603,6 +627,23 @@ var orderMoves = async (outer, move) => {
603
627
  }
604
628
  }
605
629
  };
630
+ async function movedRecords(ctx, orderId) {
631
+ const lines = await ctx.db.selectFrom("core_order_line").select(["object_type", "record_id"]).where("order_id", "=", orderId).execute();
632
+ const out = [];
633
+ for (const line of lines) {
634
+ const object = getObject(line.object_type);
635
+ const moves = movesOf(object);
636
+ const field = object?.states?.field;
637
+ if (!object || !moves || !field) continue;
638
+ const values = await storedValues(ctx, object, line.record_id);
639
+ out.push({
640
+ object: line.object_type,
641
+ recordId: line.record_id,
642
+ paid: values?.[field] === moves.paid
643
+ });
644
+ }
645
+ return out;
646
+ }
606
647
  async function movesFollowPerson(ctx, orderId, personId) {
607
648
  const order = await loadOrderRow(ctx.db, orderId);
608
649
  if (order.state !== "paid") return;
@@ -652,6 +693,8 @@ onRecordMove("order", orderMoves);
652
693
  onEveryRecordMove(recordMoves);
653
694
 
654
695
  export {
696
+ usableAddress,
697
+ personForAddress,
655
698
  newOrderToken,
656
699
  ORDER_TOKEN,
657
700
  hashOrderToken,
@@ -665,5 +708,6 @@ export {
665
708
  UNSETTLED_RELEASES,
666
709
  unsettledGuests,
667
710
  releaseUnsettledGuest,
711
+ movedRecords,
668
712
  movesFollowPerson
669
713
  };
@@ -3,6 +3,17 @@
3
3
  // ../product/src/index.ts
4
4
  var NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
5
5
  var PREFIX = /^[a-z0-9]+(-[a-z0-9]+)*-$/;
6
+ var LOCATION_HINTS = {
7
+ wnam: "Western North America",
8
+ enam: "Eastern North America",
9
+ weur: "Western Europe",
10
+ eeur: "Eastern Europe",
11
+ apac: "Asia-Pacific",
12
+ oc: "Oceania"
13
+ };
14
+ function isLocationHint(value) {
15
+ return typeof value === "string" && Object.hasOwn(LOCATION_HINTS, value);
16
+ }
6
17
  function defineProduct(definition) {
7
18
  const fail = (what) => {
8
19
  throw new Error(`product ${JSON.stringify(definition.id)}: ${what}`);
@@ -24,6 +35,134 @@ function defineProduct(definition) {
24
35
  if (!/^https:\/\//.test(definition.billingUrl)) fail("billingUrl must be an https:// URL");
25
36
  return definition;
26
37
  }
38
+ function mobileRole(entry) {
39
+ return typeof entry === "string" ? { role: entry, grants: [] } : { role: entry.role, grants: [...entry.grants ?? []] };
40
+ }
41
+ var IOS_ID = /^[A-Za-z][A-Za-z0-9-]*(\.[A-Za-z][A-Za-z0-9-]*)+$/;
42
+ var ANDROID_ID = /^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+$/;
43
+ var HEX_COLOUR = /^#[0-9a-fA-F]{6}$/;
44
+ var SCHEME = /^[a-z][a-z0-9+.-]*$/;
45
+ var APP_VERSION = /^\d+\.\d+\.\d+$/;
46
+ var APP_NAME_MAX = 30;
47
+ var MIN_TEXT_CONTRAST = 4.5;
48
+ function contrastRatio(a, b) {
49
+ const luminance = (hex) => {
50
+ const [r, g, b2] = [1, 3, 5].map((i) => {
51
+ const c = Number.parseInt(hex.slice(i, i + 2), 16) / 255;
52
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
53
+ });
54
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b2;
55
+ };
56
+ const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
57
+ return (hi + 0.05) / (lo + 0.05);
58
+ }
59
+ function appBuild(product2, environment) {
60
+ if (!product2.mobile) throw new Error(`product ${product2.id} has no mobile app`);
61
+ const envs = environmentNames(product2);
62
+ if (envs.length && (!environment || !envs.includes(environment))) {
63
+ throw new Error(
64
+ `product ${product2.id}: name the app's environment (${envs.join(", ")}), as COS_ENV or --env${environment ? `; it has no ${environment}` : ""}`
65
+ );
66
+ }
67
+ if (!envs.length && environment && environment !== LIVE_ENVIRONMENT) {
68
+ throw new Error(
69
+ `product ${product2.id} declares no environments, so there is no ${environment}`
70
+ );
71
+ }
72
+ const env = envs.length ? product2.environments?.[environment] : void 0;
73
+ const live = !envs.length || environment === LIVE_ENVIRONMENT;
74
+ const app = product2.mobile.app;
75
+ const own = env?.mobile?.app;
76
+ const web = clientWeb(product2, envs.length ? environment : void 0);
77
+ return {
78
+ environment: envs.length ? environment : LIVE_ENVIRONMENT,
79
+ name: own?.name ?? app?.name ?? product2.label,
80
+ slug: live ? product2.id : `${product2.id}-${environment}`,
81
+ scheme: env?.mobile?.scheme ?? product2.mobile.scheme ?? product2.id,
82
+ version: app?.version ?? "1.0.0",
83
+ hostUrl: env?.hostname ? `https://${env.hostname}` : null,
84
+ websiteUrl: web?.hostname ? `https://${web.hostname}/account` : null,
85
+ store: app ? {
86
+ ids: own?.ids ?? app.ids,
87
+ icon: own?.icon ?? app.icon,
88
+ splash: own?.splash ?? app.splash,
89
+ colours: app.colours,
90
+ listing: own?.listing ?? app.listing,
91
+ purchases: app.purchases
92
+ } : null
93
+ };
94
+ }
95
+ function mobileAppProblem(definition) {
96
+ const app = definition.mobile?.app;
97
+ const envs = environmentNames(definition);
98
+ for (const env of envs) {
99
+ if (definition.environments?.[env]?.mobile?.app && !app) {
100
+ return `environments.${env}.mobile.app changes mobile.app, which product.ts does not give`;
101
+ }
102
+ }
103
+ if (!app) return null;
104
+ if (!app.name?.trim() || app.name.length > APP_NAME_MAX) {
105
+ return `mobile.app.name must be 1 to ${APP_NAME_MAX} characters`;
106
+ }
107
+ if (!APP_VERSION.test(app.version ?? "")) return "mobile.app.version must be x.y.z (digits only)";
108
+ if (app.purchases !== "none") {
109
+ return 'mobile.app.purchases must be "none": nothing is bought in the app (ADR 0490); buying stays on the website';
110
+ }
111
+ for (const key of ["primary", "background", "text"]) {
112
+ if (!HEX_COLOUR.test(app.colours?.[key] ?? "")) {
113
+ return `mobile.app.colours.${key} must be a colour as #rrggbb`;
114
+ }
115
+ }
116
+ const ratio = contrastRatio(app.colours.text, app.colours.background);
117
+ if (ratio < MIN_TEXT_CONTRAST) {
118
+ return `mobile.app.colours.text is not readable on the background: contrast ${ratio.toFixed(2)}, at least ${MIN_TEXT_CONTRAST} is needed`;
119
+ }
120
+ const builds = (envs.length ? envs : [void 0]).map((env) => ({
121
+ where: env ? `environment ${env}` : "the app",
122
+ build: appBuild(definition, env)
123
+ }));
124
+ const seen = { ios: /* @__PURE__ */ new Map(), android: /* @__PURE__ */ new Map() };
125
+ const schemes = /* @__PURE__ */ new Map();
126
+ for (const { where, build } of builds) {
127
+ const store = build.store;
128
+ if (!store.icon?.trim() || !store.splash?.image?.trim() || !store.listing?.trim()) {
129
+ return `${where}: mobile.app needs icon, splash.image and listing (paths in the repo)`;
130
+ }
131
+ if (!HEX_COLOUR.test(store.splash.background ?? "")) {
132
+ return `${where}: mobile.app.splash.background must be a colour as #rrggbb`;
133
+ }
134
+ if (build.name.length > APP_NAME_MAX) {
135
+ return `${where}: the app's name must be at most ${APP_NAME_MAX} characters`;
136
+ }
137
+ if (!IOS_ID.test(store.ids?.ios ?? "")) {
138
+ return `${where}: the iPhone app's id ${JSON.stringify(store.ids?.ios)} is not reverse-domain (com.example.app)`;
139
+ }
140
+ if (!ANDROID_ID.test(store.ids?.android ?? "")) {
141
+ return `${where}: the Android app's id ${JSON.stringify(store.ids?.android)} is not reverse-domain with letters, digits and underscores (com.example.app)`;
142
+ }
143
+ if (!SCHEME.test(build.scheme))
144
+ return `${where}: the app's scheme ${build.scheme} is not a URL scheme`;
145
+ for (const platform of ["ios", "android"]) {
146
+ const other2 = seen[platform].get(store.ids[platform]);
147
+ if (other2) return `${other2} and ${where} have the same ${platform} id ${store.ids[platform]}`;
148
+ seen[platform].set(store.ids[platform], where);
149
+ }
150
+ const other = schemes.get(build.scheme);
151
+ if (other) return `${other} and ${where} have the same scheme ${build.scheme}`;
152
+ schemes.set(build.scheme, where);
153
+ }
154
+ return null;
155
+ }
156
+ function clientLocation(product2, environment) {
157
+ const own = environment ? product2.environments?.[environment]?.location : void 0;
158
+ if (own === "none") return void 0;
159
+ return own ?? product2.location;
160
+ }
161
+ function turnsOnFakeProvider(settings) {
162
+ if (settings.payments?.PAYMENTS_FAKE_PROVIDER === true) return "the fake payment provider";
163
+ if (settings.text?.TEXT_PROVIDER === "fake") return "the fake text provider";
164
+ return null;
165
+ }
27
166
  function isLiveEnvironment(product2, environment) {
28
167
  if (environment === void 0 || environment === LIVE_ENVIRONMENT) return true;
29
168
  return product2.environments?.[environment]?.live !== false;
@@ -116,7 +255,9 @@ function defineClientProduct(definition) {
116
255
  for (const pack of definition.packs) if (!NAME.test(pack)) fail(`pack ${pack} is not an id`);
117
256
  if (new Set(definition.packs).size !== definition.packs.length) fail("a pack is listed twice");
118
257
  if (definition.web && !NAME.test(definition.web.worker)) fail("web.worker must be a Worker name");
119
- for (const role of definition.mobile?.roles ?? []) {
258
+ const seenRoles = /* @__PURE__ */ new Set();
259
+ for (const entry of definition.mobile?.roles ?? []) {
260
+ const { role, grants } = mobileRole(entry);
120
261
  const [pack, local] = role.split(".");
121
262
  if (!pack || !local || role.split(".").length !== 2) {
122
263
  fail(`mobile.roles: ${role} is not <pack>.<role>`);
@@ -124,6 +265,19 @@ function defineClientProduct(definition) {
124
265
  if (!definition.packs.includes(pack)) {
125
266
  fail(`mobile.roles: ${role} is a role of ${pack}, which packs does not list`);
126
267
  }
268
+ if (seenRoles.has(role)) fail(`mobile.roles: ${role} is listed twice`);
269
+ seenRoles.add(role);
270
+ for (const grant of grants) {
271
+ const [grantPack, name] = grant.split(":");
272
+ if (!grantPack || !name || grant.split(":").length !== 2) {
273
+ fail(`mobile.roles: ${role}'s grant ${grant} is not <pack>:<permission>`);
274
+ }
275
+ if (!definition.packs.includes(grantPack)) {
276
+ fail(
277
+ `mobile.roles: ${role}'s grant ${grant} is of ${grantPack}, which packs does not list`
278
+ );
279
+ }
280
+ }
127
281
  }
128
282
  const names = clientNames(definition);
129
283
  for (const key of ["app", "runner", "database"]) {
@@ -136,14 +290,26 @@ function defineClientProduct(definition) {
136
290
  if (definition.web && [names.app, names.runner].includes(definition.web.worker)) {
137
291
  fail("web.worker is one of the host's Workers");
138
292
  }
293
+ const hints = Object.keys(LOCATION_HINTS).join(", ");
294
+ if (definition.location !== void 0 && !isLocationHint(definition.location)) {
295
+ fail(`location is a location hint (${hints})`);
296
+ }
297
+ for (const [env, settings] of Object.entries(definition.environments ?? {})) {
298
+ if (settings.location !== void 0 && settings.location !== "none" && !isLocationHint(settings.location)) {
299
+ fail(`environments.${env}.location is none or a location hint (${hints})`);
300
+ }
301
+ }
302
+ const appProblem = mobileAppProblem(definition);
303
+ if (appProblem) fail(appProblem);
139
304
  if (definition.environments?.[LIVE_ENVIRONMENT]?.live === false) {
140
305
  fail("the live environment cannot be marked live: false");
141
306
  }
142
307
  const deployments = environmentNames(definition);
143
308
  for (const env of deployments.length ? deployments : [void 0]) {
144
- if (gatekeeperSettings(definition, env).payments?.PAYMENTS_FAKE_PROVIDER === true && isLiveEnvironment(definition, env)) {
309
+ const fake = turnsOnFakeProvider(gatekeeperSettings(definition, env));
310
+ if (fake && isLiveEnvironment(definition, env)) {
145
311
  fail(
146
- `${env ? `environment ${env}` : "the product"} is live and turns on the fake payment provider: only an environment marked live: false may`
312
+ `${env ? `environment ${env}` : "the product"} is live and turns on ${fake}: only an environment marked live: false may`
147
313
  );
148
314
  }
149
315
  }
@@ -205,6 +371,12 @@ var product = defineProduct({
205
371
  });
206
372
 
207
373
  export {
374
+ LOCATION_HINTS,
375
+ isLocationHint,
376
+ mobileRole,
377
+ contrastRatio,
378
+ appBuild,
379
+ clientLocation,
208
380
  isLiveEnvironment,
209
381
  gatekeeperSettings,
210
382
  LIVE_ENVIRONMENT,
@@ -2,31 +2,23 @@
2
2
  import {
3
3
  productContract,
4
4
  renderClient
5
- } from "./chunk-LAAL4YGR.js";
6
- import "./chunk-UB4I2QKR.js";
7
- import "./chunk-DHS2CV2M.js";
8
- import "./chunk-K34UKWEI.js";
9
- import "./chunk-2IVEVPMY.js";
10
- import "./chunk-6WGFA2IV.js";
11
- import "./chunk-WHKJGF36.js";
12
- import "./chunk-324WJXNP.js";
13
- import "./chunk-7OGCMQXG.js";
14
- import "./chunk-XIDLW3EP.js";
15
- import "./chunk-FJIZGS5Q.js";
16
- import "./chunk-ZAWES2UD.js";
17
- import "./chunk-E64SG24J.js";
18
- import "./chunk-YNUZRTPH.js";
19
- import "./chunk-6ELZRNUU.js";
20
- import "./chunk-2TWV3SVB.js";
21
- import "./chunk-ZZFWMVJO.js";
22
- import "./chunk-2XC5JLBO.js";
23
- import "./chunk-DU6OIFOU.js";
5
+ } from "./chunk-HAYF4G5V.js";
6
+ import "./chunk-HCG6T53D.js";
7
+ import "./chunk-6CM3WZG5.js";
8
+ import "./chunk-JX4IFWNT.js";
9
+ import "./chunk-5D7BDF4Y.js";
10
+ import "./chunk-Z7OVQ6BC.js";
11
+ import "./chunk-2B6YUYZV.js";
12
+ import "./chunk-KMFMD52Z.js";
13
+ import "./chunk-3OGDWKJ3.js";
24
14
  import "./chunk-KGHA67HG.js";
25
- import "./chunk-6UWRT4VM.js";
26
- import "./chunk-6XTU2MTP.js";
27
- import "./chunk-YFTLIEWU.js";
28
- import "./chunk-7D4GKZOX.js";
29
- import "./chunk-LO6WGU5Y.js";
15
+ import "./chunk-ZJSFX4RD.js";
16
+ import "./chunk-KFHKNXGH.js";
17
+ import "./chunk-RSEWEFAV.js";
18
+ import "./chunk-CIBJGB5H.js";
19
+ import "./chunk-U72NEGCT.js";
20
+ import "./chunk-Q6Y45DY6.js";
21
+ import "./chunk-RGKJKC5T.js";
30
22
  import "./chunk-5KSXSK7Y.js";
31
23
 
32
24
  // ../client-gen/src/node/cli.ts
@@ -100,7 +92,7 @@ async function runClient(argv, io) {
100
92
  io.err("--out <dir> is required");
101
93
  return 2;
102
94
  }
103
- const { products, DEFAULT_PRODUCT } = await import("./products-2H5DR232.js");
95
+ const { products, DEFAULT_PRODUCT } = await import("./products-GCQLSZ3U.js");
104
96
  const id = parsed.product ?? DEFAULT_PRODUCT;
105
97
  const product = products[id];
106
98
  if (!product) {