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

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 (64) hide show
  1. package/dist/{accounts-X4CKM3HL.js → accounts-UHYLCLEY.js} +10 -11
  2. package/dist/{blocks-YWDHEBOK.js → blocks-5IFU25J6.js} +2 -2
  3. package/dist/chunk-2IVEVPMY.js +669 -0
  4. package/dist/{chunk-QGGJ2G6Z.js → chunk-2TWV3SVB.js} +3 -3
  5. package/dist/chunk-2XC5JLBO.js +1931 -0
  6. package/dist/chunk-324WJXNP.js +320 -0
  7. package/dist/chunk-6ELZRNUU.js +116 -0
  8. package/dist/{chunk-YJJHF65I.js → chunk-6WGFA2IV.js} +58 -174
  9. package/dist/{chunk-A4NTSYWV.js → chunk-6XTU2MTP.js} +196 -10
  10. package/dist/{chunk-Q4N55M2Z.js → chunk-7D4GKZOX.js} +66 -3
  11. package/dist/{chunk-GYSGVT6R.js → chunk-7OGCMQXG.js} +9 -9
  12. package/dist/chunk-DHS2CV2M.js +139 -0
  13. package/dist/{chunk-LJFLENFC.js → chunk-E64SG24J.js} +1 -1
  14. package/dist/{chunk-Z3RMMB6S.js → chunk-FJIZGS5Q.js} +45 -15
  15. package/dist/chunk-K34UKWEI.js +298 -0
  16. package/dist/{chunk-LLULPZAJ.js → chunk-LAAL4YGR.js} +4 -4
  17. package/dist/{chunk-CP6BXI6F.js → chunk-LO6WGU5Y.js} +1338 -974
  18. package/dist/{chunk-Y7JZFSTQ.js → chunk-MBIKVRAC.js} +6 -6
  19. package/dist/{chunk-WC5LHBBA.js → chunk-P6UWZ6QQ.js} +1 -1
  20. package/dist/{chunk-6VXHPKGG.js → chunk-PDD2ETVF.js} +8 -8
  21. package/dist/{chunk-6UPUF4ML.js → chunk-UB4I2QKR.js} +1957 -380
  22. package/dist/{chunk-M7A6FR2Z.js → chunk-WHKJGF36.js} +154 -322
  23. package/dist/{chunk-VY64DMQO.js → chunk-XIDLW3EP.js} +190 -21
  24. package/dist/{chunk-IFG4FRW5.js → chunk-YFTLIEWU.js} +1 -1
  25. package/dist/{chunk-JJHHNV46.js → chunk-YNUZRTPH.js} +5 -50
  26. package/dist/{chunk-WO6D3XP3.js → chunk-ZAWES2UD.js} +31 -18
  27. package/dist/{chunk-K6T42YCH.js → chunk-ZZFWMVJO.js} +5 -5
  28. package/dist/{cli-2DFENR62.js → cli-5UNY5G5L.js} +22 -20
  29. package/dist/{cli-YIOVSKOD.js → cli-UYZMVQMR.js} +16 -13
  30. package/dist/cli.js +1 -1
  31. package/dist/{client-repo-PRU3VCQQ.js → client-repo-SE4EKG6W.js} +2 -2
  32. package/dist/create.js +1 -1
  33. package/dist/{fields-2NC7LSYE.js → fields-FTWWMD7N.js} +3 -3
  34. package/dist/grants-LOW6TSWD.js +32 -0
  35. package/dist/invoke-6KVT6WJI.js +41 -0
  36. package/dist/moves-E2HKYCTK.js +41 -0
  37. package/dist/{order-PUWD65BC.js → order-U4KZLLSJ.js} +2 -2
  38. package/dist/{person-WIQQ7ITU.js → person-UHLVBVLR.js} +9 -10
  39. package/dist/plan-on-sale-TJPFCNL7.js +26 -0
  40. package/dist/platform/migrations/0610_waitlists.sql +54 -0
  41. package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
  42. package/dist/platform/migrations/0650_person_links.sql +90 -0
  43. package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
  44. package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
  45. package/dist/platform/sdk/capacity.ts +102 -0
  46. package/dist/platform/sdk/contract.ts +25 -0
  47. package/dist/platform/sdk/manifest.ts +77 -1
  48. package/dist/platform/sdk/sellable.ts +251 -1
  49. package/dist/platform/sdk/states.ts +163 -49
  50. package/dist/{run-RT2HVWMK.js → run-7P4RQALH.js} +2 -2
  51. package/dist/{run-PZUCSDDL.js → run-PO3W5BFA.js} +1 -1
  52. package/dist/{run-Y7T4TVOL.js → run-ZCGFMEZF.js} +2 -2
  53. package/dist/src-CRO35DYY.js +46 -0
  54. package/dist/{src-XTOD7EXW.js → src-I3IJ4NKC.js} +8 -2
  55. package/dist/{visibility-DLGHU4YN.js → visibility-TVXZ67FD.js} +12 -4
  56. package/package.json +2 -2
  57. package/dist/chunk-6GDEDOV7.js +0 -157
  58. package/dist/chunk-O2UIZHND.js +0 -249
  59. package/dist/chunk-R4W5XAUD.js +0 -837
  60. package/dist/chunk-TQFGGSA4.js +0 -748
  61. package/dist/grants-QXMKYMGB.js +0 -32
  62. package/dist/invoke-I3NNNXVL.js +0 -39
  63. package/dist/plan-on-sale-NB774CQL.js +0 -26
  64. package/dist/src-GYS6NBQB.js +0 -44
@@ -1,28 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  applyTransition,
4
- callerOf,
5
4
  onRecordMove
6
- } from "./chunk-R4W5XAUD.js";
7
- import {
8
- recordHostChange
9
- } from "./chunk-6GDEDOV7.js";
10
- import {
11
- paymentsTarget
12
- } from "./chunk-LJFLENFC.js";
5
+ } from "./chunk-324WJXNP.js";
13
6
  import {
14
7
  currencyDecimals,
15
8
  loadOrderCurrency,
16
9
  loadOrderExpiryMinutes,
17
- loadReturnOrigins,
18
10
  toMinorUnits
19
- } from "./chunk-O2UIZHND.js";
11
+ } from "./chunk-6ELZRNUU.js";
20
12
  import {
13
+ callerOf,
21
14
  confirmStatements,
22
15
  newId,
23
16
  queueClaim,
17
+ recordHostChange,
24
18
  releaseStatements
25
- } from "./chunk-TQFGGSA4.js";
19
+ } from "./chunk-2XC5JLBO.js";
26
20
  import {
27
21
  ConfigError,
28
22
  ConflictError,
@@ -30,19 +24,53 @@ import {
30
24
  ValidationError,
31
25
  buyableSource,
32
26
  orgReader,
33
- refreshSchemaRegistry,
34
- scopeOf,
35
- sql,
36
27
  viewColumnOf,
37
28
  visibleSource
38
- } from "./chunk-A4NTSYWV.js";
29
+ } from "./chunk-6XTU2MTP.js";
39
30
  import {
40
- getObject,
41
- listObjects
42
- } from "./chunk-IFG4FRW5.js";
31
+ getObject
32
+ } from "./chunk-YFTLIEWU.js";
43
33
  import {
44
34
  orderObject
45
- } from "./chunk-Q4N55M2Z.js";
35
+ } from "./chunk-7D4GKZOX.js";
36
+
37
+ // ../core/src/orders/sellable.ts
38
+ var GRANTS_PER_ORDER_CEILING = 100;
39
+ var GRANTS_PER_LINE_DEFAULT = 10;
40
+ function lineLimit(sellable, recordMax) {
41
+ const own = recordMax === null ? null : Math.max(Math.floor(recordMax), 0);
42
+ if (!sellable.grants) return own;
43
+ return Math.min(own ?? GRANTS_PER_LINE_DEFAULT, GRANTS_PER_ORDER_CEILING);
44
+ }
45
+ function sellableOf(object) {
46
+ return object.sellable;
47
+ }
48
+ function sellableProblems(sellable, object) {
49
+ const problems = [];
50
+ const field = (name) => object.fields.find((f) => f.name === name);
51
+ const numeric = (name, what) => {
52
+ const f = field(name);
53
+ if (!f?.column) problems.push(`${what} "${name}" is not a single-valued field`);
54
+ else if (f.type !== "number") problems.push(`${what} "${name}" is not a number`);
55
+ };
56
+ const date = (name, what) => {
57
+ const f = field(name);
58
+ if (!f?.column || f.type !== "date" && f.type !== "datetime") {
59
+ problems.push(`${what} "${name}" is not a date field`);
60
+ }
61
+ };
62
+ numeric(sellable.price, "price");
63
+ if (sellable.maxPerOrder) numeric(sellable.maxPerOrder, "maxPerOrder");
64
+ if (sellable.saleWindow?.from) date(sellable.saleWindow.from, "saleWindow.from");
65
+ if (sellable.saleWindow?.until) date(sellable.saleWindow.until, "saleWindow.until");
66
+ if (sellable.deposit) {
67
+ numeric(sellable.deposit.amount, "deposit.amount");
68
+ date(sellable.deposit.balanceDue, "deposit.balanceDue");
69
+ }
70
+ if (sellable.recurring?.trialDays) numeric(sellable.recurring.trialDays, "recurring.trialDays");
71
+ if (!object.titleField) problems.push("a sellable object needs a title field");
72
+ return problems;
73
+ }
46
74
 
47
75
  // ../core/src/orders/holds.ts
48
76
  var ORDER_CLAIM_TYPE = "order";
@@ -195,44 +223,6 @@ var orderOnce = async (ctx, move) => {
195
223
  };
196
224
  onRecordMove("order", orderOnce);
197
225
 
198
- // ../core/src/orders/sellable.ts
199
- var GRANTS_PER_ORDER_CEILING = 100;
200
- var GRANTS_PER_LINE_DEFAULT = 10;
201
- function lineLimit(sellable, recordMax) {
202
- const own = recordMax === null ? null : Math.max(Math.floor(recordMax), 0);
203
- if (!sellable.grants) return own;
204
- return Math.min(own ?? GRANTS_PER_LINE_DEFAULT, GRANTS_PER_ORDER_CEILING);
205
- }
206
- function sellableOf(object) {
207
- return object.sellable;
208
- }
209
- function sellableProblems(sellable, object) {
210
- const problems = [];
211
- const field = (name) => object.fields.find((f) => f.name === name);
212
- const numeric = (name, what) => {
213
- const f = field(name);
214
- if (!f?.column) problems.push(`${what} "${name}" is not a single-valued field`);
215
- else if (f.type !== "number") problems.push(`${what} "${name}" is not a number`);
216
- };
217
- const date = (name, what) => {
218
- const f = field(name);
219
- if (!f?.column || f.type !== "date" && f.type !== "datetime") {
220
- problems.push(`${what} "${name}" is not a date field`);
221
- }
222
- };
223
- numeric(sellable.price, "price");
224
- if (sellable.maxPerOrder) numeric(sellable.maxPerOrder, "maxPerOrder");
225
- if (sellable.saleWindow?.from) date(sellable.saleWindow.from, "saleWindow.from");
226
- if (sellable.saleWindow?.until) date(sellable.saleWindow.until, "saleWindow.until");
227
- if (sellable.deposit) {
228
- numeric(sellable.deposit.amount, "deposit.amount");
229
- date(sellable.deposit.balanceDue, "deposit.balanceDue");
230
- }
231
- if (sellable.recurring?.trialDays) numeric(sellable.recurring.trialDays, "recurring.trialDays");
232
- if (!object.titleField) problems.push("a sellable object needs a title field");
233
- return problems;
234
- }
235
-
236
226
  // ../core/src/orders/orders.ts
237
227
  var ORDER_MAX_LINES = 50;
238
228
  var ORDER_MAX_QUANTITY = 1e3;
@@ -296,7 +286,7 @@ async function readable(db, principal, object, id) {
296
286
  async function priceLines(db, lines, currency, now = (/* @__PURE__ */ new Date()).toISOString(), buyer, options = {}) {
297
287
  const reader = orgReader(db);
298
288
  const seen = /* @__PURE__ */ new Set();
299
- const priced2 = [];
289
+ const priced = [];
300
290
  let granting = 0;
301
291
  for (const [index, line] of lines.entries()) {
302
292
  const key = `${line.object}\0${line.id}`;
@@ -309,6 +299,9 @@ async function priceLines(db, lines, currency, now = (/* @__PURE__ */ new Date()
309
299
  if (!object || !sellable || sellableProblems(sellable, object).length) {
310
300
  refuseLine("not_for_sale", index, "This cannot be bought");
311
301
  }
302
+ if (sellable.moves) {
303
+ refuseLine("not_for_sale", index, "This is bought when it is made, not added to an order");
304
+ }
312
305
  if (Boolean(sellable.recurring) !== Boolean(options.plans)) {
313
306
  refuseLine(
314
307
  "not_for_sale",
@@ -383,7 +376,7 @@ async function priceLines(db, lines, currency, now = (/* @__PURE__ */ new Date()
383
376
  const title = object.titleField ? read(object.titleField) : null;
384
377
  const trial = sellable.recurring?.trialDays ? read(sellable.recurring.trialDays) : null;
385
378
  const onceFlag = sellable.onePerPerson ? read(sellable.onePerPerson) : null;
386
- priced2.push({
379
+ priced.push({
387
380
  ...onceFlag === 1 || onceFlag === true ? { once: true } : {},
388
381
  ...sellable.recurring ? {
389
382
  recurring: {
@@ -402,7 +395,7 @@ async function priceLines(db, lines, currency, now = (/* @__PURE__ */ new Date()
402
395
  deposit
403
396
  });
404
397
  }
405
- return priced2;
398
+ return priced;
406
399
  }
407
400
  async function createOrder(ctx, input) {
408
401
  if (!input.lines.length) throw new ValidationError("An order needs at least one line");
@@ -418,7 +411,7 @@ async function createOrder(ctx, input) {
418
411
  if (!currency) {
419
412
  throw new ConfigError("No currency is set for orders yet, so nothing can be sold");
420
413
  }
421
- const lines = await priceLines(ctx.db, input.lines, currency, ctx.now, callerOf(ctx));
414
+ const lines = input.priced ? [...input.priced] : await priceLines(ctx.db, input.lines, currency, ctx.now, callerOf(ctx));
422
415
  const total = lines.reduce((sum, line) => sum + line.total, 0);
423
416
  if (total <= 0) {
424
417
  throw new ValidationError("An order with nothing to pay cannot be started", { rule: "total" });
@@ -446,7 +439,7 @@ async function createOrder(ctx, input) {
446
439
  }
447
440
  }
448
441
  const minutes = await loadOrderExpiryMinutes(ctx.db);
449
- const id = newId("order");
442
+ const id = input.id ?? newId("order");
450
443
  const row = {
451
444
  id,
452
445
  person_id: input.personId,
@@ -633,112 +626,9 @@ function requireState(row, states, what) {
633
626
  }
634
627
  }
635
628
 
636
- // ../core/src/orders/subscription-setup.ts
637
- async function subscriptionSetup(db) {
638
- let target = null;
639
- try {
640
- target = await paymentsTarget(db);
641
- } catch (error) {
642
- if (!(error instanceof ConfigError)) throw error;
643
- }
644
- return {
645
- returnOrigins: [...await loadReturnOrigins(db)],
646
- currency: await loadOrderCurrency(db),
647
- target
648
- };
649
- }
650
- function setupComplete(setup) {
651
- return setup.returnOrigins.length > 0 && setup.currency !== null && setup.target !== null;
652
- }
653
-
654
- // ../core/src/customers/plan-on-sale.ts
655
- var PUBLIC = Object.freeze({ kind: "public" });
656
- var PLANS_LOOKED_AT = 50;
657
- var PLAN_ON_SALE_MEMO_MS = 6e4;
658
- var memo = null;
659
- function forgetPlanOnSale() {
660
- memo = null;
661
- }
662
- async function findPlanOnSale(db, now = (/* @__PURE__ */ new Date()).toISOString(), options = {}) {
663
- const at = Date.now();
664
- if (options.memo && memo && at - memo.at < PLAN_ON_SALE_MEMO_MS) return memo.value;
665
- let value;
666
- try {
667
- value = await compute(db, now);
668
- } catch (error) {
669
- value = { state: "unknown", reason: error instanceof Error ? error.message : String(error) };
670
- }
671
- memo = { at, value };
672
- return value;
673
- }
674
- async function hasPlanOnSale(db, now = (/* @__PURE__ */ new Date()).toISOString()) {
675
- return (await findPlanOnSale(db, now)).state === "on_sale";
676
- }
677
- async function compute(db, now) {
678
- const setup = await subscriptionSetup(db);
679
- if (!setupComplete(setup)) return { state: "none" };
680
- await refreshSchemaRegistry(db);
681
- let unanswered = false;
682
- for (const object of listObjects()) {
683
- const sellable = sellableOf(object);
684
- if (!sellable?.recurring || sellableProblems(sellable, object).length) continue;
685
- const scope = scopeOf(PUBLIC, object, false);
686
- if (scope.kind !== "public") continue;
687
- let source;
688
- try {
689
- source = buyableSource({ principal: PUBLIC }, object);
690
- } catch {
691
- continue;
692
- }
693
- const readable2 = new Set(scope.columns);
694
- const columnOf = (name) => {
695
- const field = name ? object.fields.find((f) => f.name === name) : void 0;
696
- const column2 = field ? viewColumnOf(field) : null;
697
- return column2 && readable2.has(column2) ? column2 : null;
698
- };
699
- let query = db.selectFrom(source).select("id");
700
- const price = columnOf(sellable.price);
701
- if (price) query = query.where(sql.ref(price), ">", 0);
702
- const day = now.slice(0, 10);
703
- const from = columnOf(sellable.saleWindow?.from);
704
- if (from) {
705
- query = query.where(
706
- (eb) => eb.or([eb(sql.ref(from), "is", null), eb(sql.ref(from), "<=", now)])
707
- );
708
- }
709
- const until = columnOf(sellable.saleWindow?.until);
710
- if (until) {
711
- query = query.where(
712
- (eb) => eb.or([eb(sql.ref(until), "is", null), eb(sql.ref(until), ">=", day)])
713
- );
714
- }
715
- const rows = await query.orderBy("id").limit(PLANS_LOOKED_AT + 1).execute();
716
- for (const { id } of rows.slice(0, PLANS_LOOKED_AT)) {
717
- const found = await priced(db, object, id, setup.currency, now);
718
- if (found) return { state: "on_sale", plan: found };
719
- }
720
- if (rows.length > PLANS_LOOKED_AT) unanswered = true;
721
- }
722
- return unanswered ? { state: "unknown", reason: `more than ${PLANS_LOOKED_AT} plans to look at` } : { state: "none" };
723
- }
724
- async function priced(db, object, id, currency, now) {
725
- try {
726
- const [line] = await priceLines(
727
- db,
728
- [{ object: object.name, id, quantity: 1 }],
729
- currency,
730
- now,
731
- PUBLIC,
732
- { plans: true }
733
- );
734
- return line?.recurring && line.unitPrice > 0 ? { object: object.name, id, title: line.title } : null;
735
- } catch (error) {
736
- if (error instanceof ValidationError) return null;
737
- throw error;
738
- }
739
- }
740
-
741
629
  export {
630
+ sellableOf,
631
+ sellableProblems,
742
632
  ORDER_MAX_LINES,
743
633
  ORDER_MAX_QUANTITY,
744
634
  orderSnapshot,
@@ -749,11 +639,5 @@ export {
749
639
  formatMoney,
750
640
  chargeFor,
751
641
  overdueOrders,
752
- requireState,
753
- subscriptionSetup,
754
- PLANS_LOOKED_AT,
755
- PLAN_ON_SALE_MEMO_MS,
756
- forgetPlanOnSale,
757
- findPlanOnSale,
758
- hasPlanOnSale
642
+ requireState
759
643
  };
@@ -3,11 +3,12 @@ import {
3
3
  CORE_OBJECTS,
4
4
  getObject,
5
5
  isCoreObject,
6
+ listObjects,
6
7
  setExtensionObjects
7
- } from "./chunk-IFG4FRW5.js";
8
+ } from "./chunk-YFTLIEWU.js";
8
9
  import {
9
10
  BASE_TABLES
10
- } from "./chunk-Q4N55M2Z.js";
11
+ } from "./chunk-7D4GKZOX.js";
11
12
  import {
12
13
  EXTENSION_ID_RE,
13
14
  FIELD_NAME_RE,
@@ -26,7 +27,7 @@ import {
26
27
  onStep,
27
28
  spendsOnList,
28
29
  validateDocument
29
- } from "./chunk-CP6BXI6F.js";
30
+ } from "./chunk-LO6WGU5Y.js";
30
31
 
31
32
  // ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/util/object-utils.js
32
33
  function isUndefined(obj) {
@@ -8881,6 +8882,18 @@ function parseParameter(param) {
8881
8882
  return parseValueExpression(param);
8882
8883
  }
8883
8884
 
8885
+ // ../../node_modules/.pnpm/kysely@0.29.8/node_modules/kysely/dist/query-compiler/compiled-query.js
8886
+ var CompiledQuery = freeze({
8887
+ raw(sql2, parameters = []) {
8888
+ return freeze({
8889
+ sql: sql2,
8890
+ query: RawNode.createWithSql(sql2),
8891
+ parameters: freeze(parameters),
8892
+ queryId: createQueryId()
8893
+ });
8894
+ }
8895
+ });
8896
+
8884
8897
  // ../core/src/extensions/naming.ts
8885
8898
  var IDENT_RE = /^[a-z][a-z0-9_]{0,120}$/;
8886
8899
  function ident(name) {
@@ -9063,6 +9076,7 @@ var RunsOnApprovalError = class extends OperationError {
9063
9076
  uses;
9064
9077
  name = "RunsOnApprovalError";
9065
9078
  };
9079
+ var TRY_LATER = "Too many places are being held for payment just now: try again shortly";
9066
9080
  var RateLimitedError = class extends OperationError {
9067
9081
  name = "RateLimitedError";
9068
9082
  constructor(message, details) {
@@ -9188,6 +9202,33 @@ function toOperationError(error) {
9188
9202
  { rule: "capacity", reason: "claim_live" }
9189
9203
  );
9190
9204
  }
9205
+ if (message.includes("core_moved_meanwhile")) {
9206
+ return new ConflictError(
9207
+ "What this is for changed while it was being made (it may have been cancelled), so nothing was changed. Look again.",
9208
+ { rule: "state_closed", reason: "moved_meanwhile" }
9209
+ );
9210
+ }
9211
+ if (message.includes("core_holds_capped")) {
9212
+ return new RateLimitedError(TRY_LATER, { rule: "try_later" });
9213
+ }
9214
+ if (message.includes("core_waitlist_not_full")) {
9215
+ return new ConflictError("A place came free meanwhile: claim it instead of waiting.", {
9216
+ rule: "waitlist",
9217
+ reason: "not_full"
9218
+ });
9219
+ }
9220
+ if (message.includes("core_person_link_not_live")) {
9221
+ return new OperationError("not_found", "Not found", { object: "person" });
9222
+ }
9223
+ if (message.includes("core_person_link_reverse")) {
9224
+ return new ConflictError(
9225
+ "The other way round is already linked: a child cannot also be their guardian's guardian.",
9226
+ { rule: "person_link_reverse" }
9227
+ );
9228
+ }
9229
+ if (message.includes("UNIQUE constraint failed: core_person_link")) {
9230
+ return new ConflictError("These two are already linked.", { rule: "person_link" });
9231
+ }
9191
9232
  if (message.includes("UNIQUE constraint failed: core_recurrence_occurrence")) {
9192
9233
  return new ConflictError(
9193
9234
  "Another run made these records at the same moment. Nothing was changed.",
@@ -10076,12 +10117,24 @@ function claimsDefinition(object, own) {
10076
10117
  if (!declared) return {};
10077
10118
  const on = own.find((f) => f.localName === declared.on);
10078
10119
  if (!on?.definition.to) return {};
10120
+ const waitlist = declared.waitlist;
10121
+ const named = (local) => local === void 0 ? void 0 : own.find((f) => f.localName === local)?.name ?? local;
10079
10122
  return {
10080
10123
  claims: {
10081
10124
  on: on.name,
10082
10125
  object: on.definition.to,
10083
10126
  held: [...declared.held ?? []],
10084
- confirmed: [...declared.confirmed ?? []]
10127
+ confirmed: [...declared.confirmed ?? []],
10128
+ ...waitlist ? {
10129
+ waitlist: {
10130
+ state: waitlist.state,
10131
+ promote: waitlist.promote,
10132
+ until: waitlist.until,
10133
+ promotedAt: named(waitlist.promotedAt),
10134
+ passedOverAt: named(waitlist.passedOverAt),
10135
+ passedOverReason: named(waitlist.passedOverReason)
10136
+ }
10137
+ } : {}
10085
10138
  }
10086
10139
  };
10087
10140
  }
@@ -10146,6 +10199,21 @@ function sellableDefinition(object, own) {
10146
10199
  }
10147
10200
  } : {},
10148
10201
  ...declared.onePerPerson ? { onePerPerson: nameOf(declared.onePerPerson) } : {},
10202
+ // Paths (`class.classType.dropInPrice`) stay as declared: the host's path reader names each
10203
+ // part as the declaring extension's (ADR 0505); a field of the object is named here.
10204
+ ...declared.moves ? {
10205
+ moves: {
10206
+ held: declared.moves.held,
10207
+ paid: declared.moves.paid,
10208
+ expired: declared.moves.expired,
10209
+ refund: [...declared.moves.refund ?? []],
10210
+ ...declared.moves.price ? { price: { ...declared.moves.price } } : {},
10211
+ ...declared.moves.title ? { title: declared.moves.title } : {},
10212
+ ...declared.moves.order ? { order: nameOf(declared.moves.order) } : {},
10213
+ ...declared.moves.guest ? { guest: true } : {},
10214
+ ...declared.moves.holdCap ? { holdCap: { ...declared.moves.holdCap } } : {}
10215
+ }
10216
+ } : {},
10149
10217
  ...declared.tax ? {
10150
10218
  tax: {
10151
10219
  code: declared.tax.code,
@@ -10169,6 +10237,12 @@ function sellableDefinition(object, own) {
10169
10237
  recurring: {
10170
10238
  interval: declared.recurring.interval,
10171
10239
  trialDays: opt(declared.recurring.trialDays),
10240
+ ...declared.recurring.pause ? {
10241
+ pause: {
10242
+ minDays: opt(declared.recurring.pause.minDays),
10243
+ maxDays: opt(declared.recurring.pause.maxDays)
10244
+ }
10245
+ } : {},
10172
10246
  ...declared.recurring.grants ? {
10173
10247
  grants: {
10174
10248
  ...declared.recurring.grants,
@@ -10479,7 +10553,8 @@ var PERMISSIONS = [
10479
10553
  "settings:manage",
10480
10554
  "orders:refund",
10481
10555
  "records:publish",
10482
- "subscriptions:manage"
10556
+ "subscriptions:manage",
10557
+ "people:link"
10483
10558
  ];
10484
10559
  var ROLE_PERMISSIONS = {
10485
10560
  viewer: ["records:read"],
@@ -10492,7 +10567,8 @@ function roleHasPermission(role, permission) {
10492
10567
  var GRANTABLE_PERMISSIONS = [
10493
10568
  "records:publish",
10494
10569
  "orders:refund",
10495
- "subscriptions:manage"
10570
+ "subscriptions:manage",
10571
+ "people:link"
10496
10572
  ];
10497
10573
  function holdsPermission(user, grants, permission) {
10498
10574
  return roleHasPermission(user.role, permission) || GRANTABLE_PERMISSIONS.includes(permission) && (grants ?? []).includes(permission);
@@ -10514,6 +10590,99 @@ function viewColumnOf(field) {
10514
10590
  return match?.[1] ?? null;
10515
10591
  }
10516
10592
 
10593
+ // ../core/src/visibility/guardians.ts
10594
+ var GUARDIAN_LINK = "guardian";
10595
+ function guardianProblems(object) {
10596
+ const declared = object.customer?.guardians;
10597
+ if (!declared || !object.customer) return [];
10598
+ const problems = [];
10599
+ if (object.name === "person") {
10600
+ problems.push("a Person's own record cannot open to their guardians");
10601
+ }
10602
+ if (declared.madeBy !== void 0) {
10603
+ const name = declared.madeBy;
10604
+ const field = object.fields.find((f) => f.name === name);
10605
+ if (!field?.column || field.fieldType !== "relation" || field.options?.to !== "person" || field.options.many) {
10606
+ problems.push(`customer.guardians.madeBy "${name}" must be a relation to one person`);
10607
+ } else if (!field.readOnly) {
10608
+ problems.push(`customer.guardians.madeBy "${name}" must be read-only: the host sets it`);
10609
+ }
10610
+ if (name === object.customer.field) {
10611
+ problems.push("customer.guardians.madeBy cannot be the customer field");
10612
+ }
10613
+ if (object.customer.write.includes(name)) {
10614
+ problems.push(
10615
+ `customer.guardians.madeBy "${name}" is set by the host: customer.write may not list it`
10616
+ );
10617
+ }
10618
+ }
10619
+ return problems;
10620
+ }
10621
+ function dependantsSql(personId) {
10622
+ return sql`SELECT l.dependant_id FROM core_person_link l JOIN core_person d ON d.id = l.dependant_id AND d.deleted_at IS NULL JOIN core_person g ON g.id = l.guardian_id AND g.deleted_at IS NULL WHERE l.guardian_id = ${personId} AND l.kind = ${GUARDIAN_LINK} AND l.ended_at IS NULL`;
10623
+ }
10624
+ function ownersWhere(column, personId, dependants) {
10625
+ const own = sql`${sql.ref(column)} = ${personId}`;
10626
+ return dependants ? sql`(${own} OR ${sql.ref(column)} IN (${dependantsSql(personId)}))` : own;
10627
+ }
10628
+ async function isLiveDependant(db, guardianId, personId) {
10629
+ if (guardianId === personId) return false;
10630
+ const { rows } = await sql`SELECT 1 AS one WHERE ${personId} IN (${dependantsSql(guardianId)})`.execute(db);
10631
+ return rows.length > 0;
10632
+ }
10633
+ function linkGuardStatement(guardianId, dependantId) {
10634
+ return CompiledQuery.raw(
10635
+ "INSERT INTO core_person_link_guard (guardian_id, dependant_id) VALUES (?, ?)",
10636
+ [guardianId, dependantId]
10637
+ );
10638
+ }
10639
+ async function familyOf(reader) {
10640
+ const principal = reader.principal;
10641
+ if (principal.kind !== "customer") return { self: null, dependants: [], guardians: [] };
10642
+ const me = principal.personId;
10643
+ const own = await sql`SELECT display_name AS name FROM core_person WHERE id = ${me} AND deleted_at IS NULL`.execute(
10644
+ reader.db
10645
+ );
10646
+ const dependants = await sql`SELECT p.id AS id, p.display_name AS name FROM core_person p WHERE p.id IN (${dependantsSql(me)}) ORDER BY p.display_name, p.id`.execute(
10647
+ reader.db
10648
+ );
10649
+ const guardians = await sql`SELECT p.id AS id, p.display_name AS name FROM core_person_link l JOIN core_person p ON p.id = l.guardian_id AND p.deleted_at IS NULL JOIN core_person me ON me.id = l.dependant_id AND me.deleted_at IS NULL WHERE l.dependant_id = ${me} AND l.kind = ${GUARDIAN_LINK} AND l.ended_at IS NULL ORDER BY p.display_name, p.id`.execute(
10650
+ reader.db
10651
+ );
10652
+ const shown = (rows) => rows.map((row) => ({ personId: String(row.id), name: String(row.name) }));
10653
+ return {
10654
+ self: { personId: me, name: String(own.rows[0]?.name ?? "") },
10655
+ dependants: shown(dependants.rows),
10656
+ guardians: shown(guardians.rows)
10657
+ };
10658
+ }
10659
+ async function recordsMadeFor(db, guardianId, dependantId) {
10660
+ const out = [];
10661
+ for (const object of listObjects()) {
10662
+ const declared = object.customer;
10663
+ const madeBy = declared?.guardians?.madeBy;
10664
+ if (!declared || !madeBy) continue;
10665
+ const owner = object.fields.find((f) => f.name === declared.field);
10666
+ const maker = object.fields.find((f) => f.name === madeBy);
10667
+ const ownerColumn = owner ? viewColumnOf(owner) : null;
10668
+ const makerColumn = maker ? viewColumnOf(maker) : null;
10669
+ if (!ownerColumn || !makerColumn) continue;
10670
+ const { rows } = await sql`SELECT count(*) AS n FROM ${sql.table(object.source)} WHERE ${sql.ref(ownerColumn)} = ${dependantId} AND ${sql.ref(makerColumn)} = ${guardianId}`.execute(
10671
+ db
10672
+ );
10673
+ const count = Number(rows[0]?.n ?? 0);
10674
+ if (count) out.push({ object: object.name, label: object.plural ?? object.label, count });
10675
+ }
10676
+ return out;
10677
+ }
10678
+ async function sharedEmailWarning(db, guardianId, dependantId) {
10679
+ const { rows } = await sql`SELECT DISTINCT e.email AS shared FROM core_person_emails e WHERE e.person_id = ${dependantId} AND (e.email IN (SELECT g.email FROM core_person_emails g WHERE g.person_id = ${guardianId}) OR e.email IN (SELECT c.email FROM core_customer c WHERE c.person_id IS NULL OR c.person_id != ${dependantId}))`.execute(
10680
+ db
10681
+ );
10682
+ if (!rows.length) return null;
10683
+ return `The child's record has an email that is also the parent's or another account's (${rows.map((r) => r.shared).join(", ")}). Signing in with it would open that account as the child's: give the child their own address or none.`;
10684
+ }
10685
+
10517
10686
  // ../core/src/visibility/public.ts
10518
10687
  function publicProblems(object) {
10519
10688
  const problems = readProblems(object, "public");
@@ -10686,6 +10855,7 @@ function customerProblems(object) {
10686
10855
  problems.push(`customer.write lists "${name}", which customer.read does not`);
10687
10856
  }
10688
10857
  }
10858
+ problems.push(...guardianProblems(object));
10689
10859
  return problems;
10690
10860
  }
10691
10861
  function customerScope(object, personId) {
@@ -10708,6 +10878,8 @@ function customerScope(object, personId) {
10708
10878
  columns,
10709
10879
  writable: new Set(declared.write),
10710
10880
  declaration: declared,
10881
+ dependants: declared.guardians !== void 0,
10882
+ dependantsWrite: declared.guardians?.write === true,
10711
10883
  ...shared ? { shared } : {}
10712
10884
  };
10713
10885
  }
@@ -10787,7 +10959,12 @@ function resolveLink(object, declared) {
10787
10959
  if (!from.customer.read.includes(declared.field)) {
10788
10960
  return `customerVia.field "${declared.field}" must be one the customer of ${from.name} may read`;
10789
10961
  }
10790
- return { source: from.source, pointer: pointer.column, owner: owner.column };
10962
+ return {
10963
+ source: from.source,
10964
+ pointer: pointer.column,
10965
+ owner: owner.column,
10966
+ dependants: from.customer.guardians !== void 0
10967
+ };
10791
10968
  }
10792
10969
  function customerViaScope(object, personId) {
10793
10970
  const declared = object.customerVia;
@@ -10887,14 +11064,15 @@ function buyableSource(ctx, object) {
10887
11064
  }
10888
11065
  function reachedWhere(scope) {
10889
11066
  const { link } = scope;
10890
- return sql`id IN (SELECT ${sql.ref(link.pointer)} FROM ${sql.table(link.source)} WHERE ${sql.ref(link.owner)} = ${scope.personId} AND ${sql.ref(link.pointer)} IS NOT NULL)`;
11067
+ const owners = ownersWhere(link.owner, scope.personId, link.dependants);
11068
+ return sql`id IN (SELECT ${sql.ref(link.pointer)} FROM ${sql.table(link.source)} WHERE ${owners} AND ${sql.ref(link.pointer)} IS NOT NULL)`;
10891
11069
  }
10892
11070
  function sourceOf(scope, definition, name) {
10893
11071
  switch (scope.kind) {
10894
11072
  case "all":
10895
11073
  return sql`${sql.table(definition.source)}`.as(name);
10896
11074
  case "customer": {
10897
- const own = sql`${sql.ref(scope.column)} = ${scope.personId}`;
11075
+ const own = ownersWhere(scope.column, scope.personId, scope.dependants);
10898
11076
  if (!scope.shared) {
10899
11077
  const columns2 = sql.join(scope.columns.map((column) => sql.ref(column)));
10900
11078
  return sql`(SELECT ${columns2} FROM ${sql.table(definition.source)} WHERE ${own})`.as(
@@ -10955,7 +11133,7 @@ function ownedSource(ctx, object, alias) {
10955
11133
  case "all":
10956
11134
  return sql`${sql.table(object.source)}`.as(name);
10957
11135
  case "customer":
10958
- return sql`(SELECT id FROM ${sql.table(object.source)} WHERE ${sql.ref(scope.column)} = ${scope.personId})`.as(
11136
+ return sql`(SELECT id, ${sql.ref(scope.column)} AS owner FROM ${sql.table(object.source)} WHERE ${ownersWhere(scope.column, scope.personId, scope.dependantsWrite)})`.as(
10959
11137
  name
10960
11138
  );
10961
11139
  default:
@@ -11027,6 +11205,7 @@ export {
11027
11205
  DynamicTableBuilder,
11028
11206
  parseTable,
11029
11207
  sql,
11208
+ CompiledQuery,
11030
11209
  OperationError,
11031
11210
  UnknownOperationError,
11032
11211
  ValidationError,
@@ -11076,6 +11255,13 @@ export {
11076
11255
  grantableScopes,
11077
11256
  staffPrincipal,
11078
11257
  ALL_ACTORS,
11258
+ GUARDIAN_LINK,
11259
+ guardianProblems,
11260
+ isLiveDependant,
11261
+ linkGuardStatement,
11262
+ familyOf,
11263
+ recordsMadeFor,
11264
+ sharedEmailWarning,
11079
11265
  publicProblems,
11080
11266
  signedInProblems,
11081
11267
  customerProblems,