@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,40 +1,36 @@
1
1
  #!/usr/bin/env node
2
- import {
3
- createRecord,
4
- updateRecord
5
- } from "./chunk-WHKJGF36.js";
6
- import {
7
- onRecordMove
8
- } from "./chunk-324WJXNP.js";
9
- import {
10
- currencyDecimals
11
- } from "./chunk-6ELZRNUU.js";
12
- import {
13
- notifyStatements
14
- } from "./chunk-ZZFWMVJO.js";
15
2
  import {
16
3
  addLocalDays,
4
+ createRecord,
5
+ currencyDecimals,
6
+ jsonList,
17
7
  loadGeneralSettings,
18
8
  localParts,
19
9
  newId,
10
+ notifyStatements,
11
+ onRecordMove,
12
+ updateRecord,
13
+ viewRow,
20
14
  wallClockToIso
21
- } from "./chunk-2XC5JLBO.js";
15
+ } from "./chunk-KMFMD52Z.js";
22
16
  import {
23
17
  FIELD_TYPE_REGISTRY,
24
- NotFoundError,
25
- ValidationError,
26
18
  formulaFromStorage,
27
19
  orgReader,
28
20
  viewColumnOf,
29
21
  visibleSource
30
- } from "./chunk-6XTU2MTP.js";
22
+ } from "./chunk-KFHKNXGH.js";
31
23
  import {
32
24
  getObject,
33
25
  listObjects
34
- } from "./chunk-YFTLIEWU.js";
26
+ } from "./chunk-RSEWEFAV.js";
35
27
  import {
36
28
  moveOrigins
37
- } from "./chunk-LO6WGU5Y.js";
29
+ } from "./chunk-U72NEGCT.js";
30
+ import {
31
+ NotFoundError,
32
+ ValidationError
33
+ } from "./chunk-RGKJKC5T.js";
38
34
 
39
35
  // ../core/src/orders/grants.ts
40
36
  var CODE_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
@@ -52,8 +48,17 @@ function grantFieldValue(object, row, name) {
52
48
  const type = field.fieldType;
53
49
  return type && FIELD_TYPE_REGISTRY[type] ? FIELD_TYPE_REGISTRY[type].fromStorage(raw) : raw;
54
50
  }
51
+ function idsByObject(rows) {
52
+ const out = /* @__PURE__ */ new Map();
53
+ for (const row of rows) {
54
+ const ids = out.get(row.object_type);
55
+ if (ids) ids.push(row.record_id);
56
+ else out.set(row.object_type, [row.record_id]);
57
+ }
58
+ return out;
59
+ }
55
60
  async function readGrantItem(ctx, item, id) {
56
- return await ctx.db.selectFrom(visibleSource(orgReader(ctx.db), item)).selectAll().where("id", "=", id).executeTakeFirst();
61
+ return viewRow(ctx.db, visibleSource(orgReader(ctx.db), item), id);
57
62
  }
58
63
  async function validFrom(ctx, granted, valid, itemValue) {
59
64
  const zone = (await loadGeneralSettings(ctx.db)).timezone || "UTC";
@@ -161,6 +166,10 @@ async function grant(ctx, orderId, order, from) {
161
166
  continue;
162
167
  }
163
168
  const sources = Object.values(grants.set);
169
+ if (item.sellable?.delivery) {
170
+ const delivery = await ctx.db.selectFrom("core_order_delivery").select("kind").where("line_id", "=", line.id).executeTakeFirst();
171
+ if (!delivery || delivery.kind === "here") continue;
172
+ }
164
173
  const itemRow = sources.some((s) => s.startsWith("item.")) || grants.valid?.days ? await readGrantItem(ctx, item, line.record_id) : void 0;
165
174
  const valid = grants.valid ? await validFrom(
166
175
  ctx,
@@ -190,7 +199,32 @@ async function grant(ctx, orderId, order, from) {
190
199
  values[target] = from2(source);
191
200
  }
192
201
  }
193
- const id = await createRecord(ctx, granted, values, { by: "host", checkReferences: false });
202
+ const copied = {};
203
+ const generated = [];
204
+ for (const [target, source] of Object.entries(grants.set)) {
205
+ if (source === "code") generated.push(target);
206
+ else if (source.startsWith("item.")) {
207
+ const field = source.slice(5);
208
+ copied[target] = [
209
+ { object: line.object_type, id: line.record_id, field, value: values[target] }
210
+ ];
211
+ } else if (source === "line.title" && item.titleField) {
212
+ copied[target] = [
213
+ {
214
+ object: line.object_type,
215
+ id: line.record_id,
216
+ field: item.titleField,
217
+ value: line.title
218
+ }
219
+ ];
220
+ }
221
+ }
222
+ const id = await createRecord(ctx, granted, values, {
223
+ by: "host",
224
+ checkReferences: false,
225
+ copied,
226
+ generated
227
+ });
194
228
  ctx.write(
195
229
  ctx.db.insertInto("core_order_grant").values({
196
230
  object_type: granted.name,
@@ -214,10 +248,7 @@ function grantFor(object) {
214
248
  async function voidGrants(ctx, orderId) {
215
249
  const rows = await ctx.db.selectFrom("core_order_grant").select(["object_type", "record_id"]).where("order_id", "=", orderId).execute();
216
250
  if (!rows.length) return;
217
- const byObject = /* @__PURE__ */ new Map();
218
- for (const row of rows) {
219
- byObject.set(row.object_type, [...byObject.get(row.object_type) ?? [], row.record_id]);
220
- }
251
+ const byObject = idsByObject(rows);
221
252
  for (const [name, ids] of byObject) {
222
253
  const object = getObject(name);
223
254
  const states = object?.states;
@@ -226,7 +257,7 @@ async function voidGrants(ctx, orderId) {
226
257
  const column = field ? viewColumnOf(field) : null;
227
258
  if (!object || !states || !voidState || !column) continue;
228
259
  const finals = new Set(states.moves.filter((m) => m.final).map((m) => m.to));
229
- const current = await ctx.db.selectFrom(visibleSource(orgReader(ctx.db), object)).select(["id", column]).where("id", "in", ids).execute();
260
+ const current = await ctx.db.selectFrom(visibleSource(orgReader(ctx.db), object)).select(["id", column]).where("id", "in", jsonList(ids)).execute();
230
261
  for (const row of current) {
231
262
  const state = row[column];
232
263
  if (typeof state !== "string" || state === voidState || finals.has(state)) continue;
@@ -246,18 +277,15 @@ async function voidGrants(ctx, orderId) {
246
277
  }
247
278
  async function grantsFollowPerson(ctx, orderId, personId) {
248
279
  const rows = await ctx.db.selectFrom("core_order_grant").select(["object_type", "record_id"]).where("order_id", "=", orderId).execute();
249
- const byObject = /* @__PURE__ */ new Map();
250
- for (const row of rows) {
251
- byObject.set(row.object_type, [...byObject.get(row.object_type) ?? [], row.record_id]);
252
- }
280
+ const byObject = idsByObject(rows);
253
281
  for (const [name, ids] of byObject) {
254
282
  const object = getObject(name);
255
283
  const set = grantFor(name)?.set ?? {};
256
284
  const fields = Object.keys(set).filter((field) => set[field] === "order.person");
257
285
  if (!object || !fields.length) continue;
258
- const live = await ctx.db.selectFrom(visibleSource(orgReader(ctx.db), object)).select("id").where("id", "in", ids).execute();
286
+ const live = await ctx.db.selectFrom(visibleSource(orgReader(ctx.db), object)).select("id").where("id", "in", jsonList(ids)).execute();
259
287
  const values = Object.fromEntries(fields.map((field) => [field, personId]));
260
- for (const { id } of live) await updateRecord(ctx, object, id, values, { by: "host" });
288
+ for (const { id } of live) await updateRecord(ctx, object, String(id), values, { by: "host" });
261
289
  }
262
290
  }
263
291
  async function tellStaffOnce(ctx, orderId, title) {
@@ -280,6 +308,10 @@ var orderGrants = async (ctx, move) => {
280
308
  const from = move.from?.id ?? null;
281
309
  const to = move.to.id;
282
310
  if ((to === "paid" || to === "part_paid") && (from === "pending" || from === "expired")) {
311
+ if (from === "pending" && move.after.invoiceId) {
312
+ const before = await ctx.db.selectFrom("core_order_grant").select("order_id").where("order_id", "=", move.id).limit(1).executeTakeFirst();
313
+ if (before) return;
314
+ }
283
315
  await grant(ctx, move.id, move.after, from);
284
316
  return;
285
317
  }