@composable-os/sdk 0.1.0-beta.10 → 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 (105) hide show
  1. package/dist/acknowledge.d.ts +38 -0
  2. package/dist/acknowledge.js +30 -0
  3. package/dist/agreements.d.ts +80 -0
  4. package/dist/agreements.js +109 -0
  5. package/dist/allowance.d.ts +47 -5
  6. package/dist/allowance.js +59 -4
  7. package/dist/automation-check.d.ts +6 -1
  8. package/dist/automation-check.js +93 -8
  9. package/dist/automation.d.ts +62 -4
  10. package/dist/automation.js +32 -9
  11. package/dist/behaviour.js +25 -6
  12. package/dist/calendar-entry.d.ts +97 -0
  13. package/dist/calendar-entry.js +180 -0
  14. package/dist/capacity.d.ts +69 -0
  15. package/dist/capacity.js +63 -2
  16. package/dist/checklists.d.ts +41 -0
  17. package/dist/checklists.js +75 -0
  18. package/dist/contract.d.ts +527 -26
  19. package/dist/contract.js +21 -3
  20. package/dist/discount.d.ts +135 -0
  21. package/dist/discount.js +281 -0
  22. package/dist/document.d.ts +2 -1
  23. package/dist/document.js +2 -1
  24. package/dist/field-types.d.ts +1 -1
  25. package/dist/field-types.js +5 -0
  26. package/dist/formula/compile.d.ts +15 -0
  27. package/dist/formula/compile.js +9 -0
  28. package/dist/index.d.ts +17 -0
  29. package/dist/index.js +17 -0
  30. package/dist/intake.d.ts +134 -0
  31. package/dist/intake.js +239 -0
  32. package/dist/journey-signals.d.ts +89 -0
  33. package/dist/journey-signals.js +151 -0
  34. package/dist/manifest.d.ts +1060 -60
  35. package/dist/manifest.js +1111 -61
  36. package/dist/mine.d.ts +45 -0
  37. package/dist/mine.js +119 -0
  38. package/dist/occupies.d.ts +64 -0
  39. package/dist/occupies.js +122 -0
  40. package/dist/questions.d.ts +179 -0
  41. package/dist/questions.js +514 -0
  42. package/dist/recurring.d.ts +33 -4
  43. package/dist/recurring.js +50 -3
  44. package/dist/restricted-fields.d.ts +15 -0
  45. package/dist/restricted-fields.js +97 -0
  46. package/dist/rich-text.d.ts +22 -0
  47. package/dist/rich-text.js +91 -0
  48. package/dist/routine-mail.d.ts +400 -0
  49. package/dist/routine-mail.js +955 -0
  50. package/dist/runtime.d.ts +5 -11
  51. package/dist/runtime.js +21 -11
  52. package/dist/screens.d.ts +3 -0
  53. package/dist/screens.js +74 -0
  54. package/dist/sellable.d.ts +231 -2
  55. package/dist/sellable.js +342 -1
  56. package/dist/slug.d.ts +2 -0
  57. package/dist/slug.js +6 -2
  58. package/dist/staffed.d.ts +178 -0
  59. package/dist/staffed.js +287 -0
  60. package/dist/states.d.ts +74 -4
  61. package/dist/states.js +154 -58
  62. package/dist/stock.d.ts +129 -0
  63. package/dist/stock.js +205 -0
  64. package/dist/team.d.ts +28 -0
  65. package/dist/team.js +52 -0
  66. package/dist/testing.d.ts +22 -1
  67. package/dist/testing.js +47 -5
  68. package/dist/worked-on.d.ts +42 -0
  69. package/dist/worked-on.js +79 -0
  70. package/package.json +9 -1
  71. package/src/acknowledge.ts +100 -0
  72. package/src/agreements.ts +185 -0
  73. package/src/allowance.ts +98 -8
  74. package/src/automation-check.ts +120 -9
  75. package/src/automation.ts +78 -10
  76. package/src/behaviour.ts +26 -6
  77. package/src/calendar-entry.ts +258 -0
  78. package/src/capacity.ts +103 -2
  79. package/src/checklists.ts +118 -0
  80. package/src/contract.ts +514 -27
  81. package/src/discount.ts +408 -0
  82. package/src/document.ts +4 -2
  83. package/src/field-types.ts +5 -0
  84. package/src/formula/compile.ts +10 -0
  85. package/src/index.ts +17 -0
  86. package/src/intake.ts +380 -0
  87. package/src/journey-signals.ts +215 -0
  88. package/src/manifest.ts +1313 -66
  89. package/src/mine.ts +161 -0
  90. package/src/occupies.ts +192 -0
  91. package/src/questions.ts +681 -0
  92. package/src/recurring.ts +90 -9
  93. package/src/restricted-fields.ts +129 -0
  94. package/src/rich-text.ts +112 -0
  95. package/src/routine-mail.ts +1272 -0
  96. package/src/runtime.ts +25 -12
  97. package/src/screens.ts +91 -0
  98. package/src/sellable.ts +595 -1
  99. package/src/slug.ts +7 -2
  100. package/src/staffed.ts +474 -0
  101. package/src/states.ts +220 -64
  102. package/src/stock.ts +332 -0
  103. package/src/team.ts +83 -0
  104. package/src/testing.ts +70 -6
  105. package/src/worked-on.ts +134 -0
@@ -0,0 +1,400 @@
1
+ import { z } from "zod";
2
+ /** The host module that sends routine mail, in an automation of a shipped pack only. */
3
+ export declare const ROUTINE_MAIL_MODULE = "routine-mail";
4
+ /** A kind may be about the host's own orders: the buyer's own address. */
5
+ export declare const ROUTINE_ABOUT_ORDER = "order";
6
+ /** What a routine email may read of an order (the host's own columns), by type. */
7
+ export declare const ROUTINE_ORDER_FIELDS: {
8
+ readonly total: "number";
9
+ readonly paid: "number";
10
+ readonly balance: "number";
11
+ readonly currency: "text";
12
+ readonly balanceDueAt: "datetime";
13
+ readonly state: "text";
14
+ };
15
+ /** The host fills this one: the name of the member a guardian's email is about. */
16
+ export declare const ROUTINE_MEMBER_SLOT = "member";
17
+ /** Most routine emails one recipient gets in a rolling day before the rest wait for a person. */
18
+ export declare const ROUTINE_DAILY_CAP = 20;
19
+ /** The channels a routine message goes on (ADR 0670). Email is every kind's. */
20
+ export declare const ROUTINE_CHANNELS: readonly ["email", "text", "push"];
21
+ export type RoutineChannel = (typeof ROUTINE_CHANNELS)[number];
22
+ /**
23
+ * What a kind is for, as far as consent goes (stage 30): `account` (about something the person
24
+ * has or did) or `follow_up` (Reviews' ask, a welcome). Never `news_and_offers`: a routine kind is
25
+ * not promotional.
26
+ */
27
+ export declare const ROUTINE_PURPOSES: readonly ["account", "follow_up"];
28
+ export type RoutinePurpose = (typeof ROUTINE_PURPOSES)[number];
29
+ /**
30
+ * A personal link (ADR 0723): the route on the business's site a form-link slot opens, and the
31
+ * query parameter its token travels in. The client web app's form page serves it.
32
+ */
33
+ export declare const PERSONAL_LINK_PATH = "/form";
34
+ export declare const PERSONAL_LINK_PARAM = "t";
35
+ /** How long a personal link stays good unless the slot says (decision 4: a week). */
36
+ export declare const PERSONAL_LINK_DAYS = 7;
37
+ /** The longest a personal link may stay good. */
38
+ export declare const PERSONAL_LINK_MAX_DAYS = 30;
39
+ /** Most receipts (ADR 0724) one mailbox is sent in a rolling day: the fourth is not sent. */
40
+ export declare const RECEIPT_DAILY_CAP = 3;
41
+ /** The longest business name a text begins with: a longer one is cut to this (ADR 0670). */
42
+ export declare const TEXT_SENDER_MAX = 30;
43
+ /** What every text ends with, added by the host. */
44
+ export declare const TEXT_STOP_LINE = "Reply STOP to stop";
45
+ /** A text is at most two segments, the name and the stop line counted in. */
46
+ export declare const TEXT_MAX_SEGMENTS = 2;
47
+ /** A push's title and body, at most (it shows on a locked screen). */
48
+ export declare const PUSH_TITLE_MAX = 60;
49
+ export declare const PUSH_BODY_MAX = 140;
50
+ /** A slot the host fills from the record: a field, or a path through relations (`class.title`). */
51
+ export interface RoutineFieldSlot {
52
+ field: string;
53
+ /** How it is written. Default `text` (one line, checked: no link, no address, no markup). */
54
+ format?: "text" | "datetime" | "time" | "date" | "money" | "count";
55
+ /** For a time: the path to the time zone field it is read in. */
56
+ zone?: string;
57
+ /** For money: the path to the currency (an order's own `currency`). */
58
+ currency?: string;
59
+ /** For a date or a time: include the year. */
60
+ year?: boolean;
61
+ /** For text: the longest value that is routine (default 120, at most 300). */
62
+ max?: number;
63
+ /** May be empty: only inside an optional part (`[...]`), which is left out when it is. */
64
+ optional?: boolean;
65
+ /**
66
+ * Private (health, pay, a note): never in a push's words, which show on a locked screen
67
+ * (ADR 0670). Email and text may carry it.
68
+ */
69
+ private?: boolean;
70
+ }
71
+ export type RoutineSlotSpec = RoutineFieldSlot
72
+ /** The pack passes one of these keys; the email says the declared words. */
73
+ | {
74
+ choice: Record<string, string>;
75
+ guardian?: Record<string, string>;
76
+ }
77
+ /** The pack passes a moment (ISO); the host writes it like a datetime field. */
78
+ | {
79
+ at: true;
80
+ zone?: string;
81
+ year?: boolean;
82
+ optional?: boolean;
83
+ }
84
+ /** The pack passes a whole number from 0 to `max`. */
85
+ | {
86
+ count: {
87
+ max: number;
88
+ };
89
+ }
90
+ /** The pack passes true or false; false leaves out the optional part it is in. */
91
+ | {
92
+ flag: true;
93
+ }
94
+ /**
95
+ * A link to one of this extension's text settings, used only when it is on the business's own
96
+ * site (Settings → Routine email); otherwise its optional part is left out. `withId` adds the
97
+ * record's id as that query parameter.
98
+ */
99
+ | {
100
+ link: string;
101
+ withId?: string;
102
+ }
103
+ /**
104
+ * A personal link (ADR 0723, the form-link slot): the host makes, while preparing each email, a
105
+ * link for the record's own Person to answer one form, about this record, once, and writes its
106
+ * address on the business's site here. `object` is a form object's registry name
107
+ * (`forms.form`); `setting` one of this extension's text settings, a person's to change
108
+ * (`personApproves`), holding the form's address. The link stays good `days` days (default 7,
109
+ * at most 30). With `once`, a Person who was sent a link to that form in the last `once` days,
110
+ * about any other record, is not sent this email at all (decision 4: once a month). A kind with
111
+ * one goes by email only, never to the record's Person when they have a live guardian (the
112
+ * guardian is sent it instead), and the email is not sent when no link can be made.
113
+ */
114
+ | {
115
+ formLink: {
116
+ object: string;
117
+ setting: string;
118
+ days?: number;
119
+ once?: number;
120
+ };
121
+ }
122
+ /**
123
+ * The business's name (ADR 0724), which the host fills from Settings → Routine email (the name
124
+ * a human admin gave, the one texts begin with): never anything a pack or a sender wrote. Left
125
+ * unset there, the email is held for a person.
126
+ */
127
+ | {
128
+ business: true;
129
+ }
130
+ /** One line per record of `object` whose `via` is this record (a buyer's tickets). */
131
+ | {
132
+ each: {
133
+ object: string;
134
+ via: string;
135
+ where?: {
136
+ field: string;
137
+ in: readonly string[];
138
+ };
139
+ distinct?: string;
140
+ max: number;
141
+ line: string;
142
+ slots: Record<string, RoutineFieldSlot>;
143
+ };
144
+ };
145
+ /** An "add to calendar" event, every value read by the host from the record. */
146
+ export interface RoutineCalendarSpec {
147
+ /** A relation of the record whose id is the event's id (a moved booking's old one). */
148
+ uid?: string;
149
+ start: string;
150
+ end?: string;
151
+ title: string;
152
+ location?: string;
153
+ /** A link slot for the event's link. */
154
+ link?: string;
155
+ cancelled?: boolean;
156
+ /** A change: the file carries a later sequence, so a calendar replaces the event. */
157
+ update?: boolean;
158
+ /** A flag slot: the event is attached only when the pack passes true. */
159
+ if?: string;
160
+ }
161
+ /** A push notification's words: a title and one line, with the same slots (ADR 0670). */
162
+ export interface RoutinePushWords {
163
+ title: string;
164
+ body: string;
165
+ }
166
+ export interface RoutineMessageSpec {
167
+ subject: string;
168
+ /** Lines of words with `{slot}` and optional parts `[...]`. */
169
+ text: string;
170
+ /**
171
+ * A text message's words, one line (ADR 0670): the host puts the business's name first and
172
+ * "Reply STOP to stop" last, and the whole must fit two segments with every slot at its longest.
173
+ */
174
+ textMessage?: string;
175
+ /** A push's words: a title of at most 60 characters and a body of at most 140, slots filled. */
176
+ push?: RoutinePushWords;
177
+ /**
178
+ * What a guardian of the member is sent instead (ADR 0540); `{member}` is the member's name. A
179
+ * guardian is texted or pushed only when their own words for that channel are declared.
180
+ */
181
+ guardian?: {
182
+ subject: string;
183
+ text: string;
184
+ textMessage?: string;
185
+ push?: RoutinePushWords;
186
+ };
187
+ calendar?: RoutineCalendarSpec | readonly RoutineCalendarSpec[];
188
+ }
189
+ export interface RoutineMailSpec {
190
+ /** For admins: "Booking confirmations". */
191
+ label: string;
192
+ /** For admins: when it is sent and to whom. */
193
+ description: string;
194
+ /** An object of this extension (`booking`), or `order`. */
195
+ about: string;
196
+ /** Sent unless an admin turns it off (default true). */
197
+ on?: boolean;
198
+ /**
199
+ * Whether its email must always go (ADR 0670): a person may turn an optional kind's email off,
200
+ * never an essential one's (text and push of any kind can be turned off). Default true for
201
+ * `account`, false for `follow_up`, which is never essential.
202
+ */
203
+ essential?: boolean;
204
+ /** What it is for (default `account`). */
205
+ purpose?: RoutinePurpose;
206
+ /**
207
+ * May go during quiet hours, but only when waiting for them to end would make it late (its
208
+ * `until` moment is before they end): a class cancelled at short notice (ADR 0676).
209
+ */
210
+ urgent?: boolean;
211
+ /** A datetime path of the record (`class.startsAt`): a text or push not sent by then is dropped. */
212
+ until?: string;
213
+ /** The channels it may go on (default email only); text and push need their words. */
214
+ channels?: readonly RoutineChannel[];
215
+ /** The app screen a push opens, with the record's id: one the pack's native blocks declare. */
216
+ open?: {
217
+ screen: string;
218
+ };
219
+ /**
220
+ * A receipt (ADR 0724): about one of this extension's intake submissions, sent to whoever sent
221
+ * it (their own sign-in address when signed in, else the address they typed, which may be one
222
+ * only the public stands behind), at most three a day to one mailbox. Its words show only the
223
+ * form's own fields (slots through the submission's form), never anything the sender typed.
224
+ */
225
+ receipt?: boolean;
226
+ slots?: Record<string, RoutineSlotSpec>;
227
+ messages: Record<string, RoutineMessageSpec>;
228
+ }
229
+ /** What `ctx.routineMail.send` takes. */
230
+ export interface RoutineSendInput {
231
+ /** A kind this extension declares (`confirmation`). */
232
+ kind: string;
233
+ /** The record it is about: the host decides who it goes to from it. */
234
+ record: string;
235
+ /** One of the kind's messages (default its only one). */
236
+ message?: string;
237
+ /** Values of the slots the pack may fill: choices, moments, counts and flags. */
238
+ values?: Record<string, string | number | boolean>;
239
+ }
240
+ /** What it answers: how many emails went, waited for a person, or were not sent. */
241
+ export interface RoutineSendResult {
242
+ /** Sent on their own. */
243
+ sent: number;
244
+ /** Waiting for a person (over the daily cap, a value that is not routine, the policy). */
245
+ held: number;
246
+ /** The kind is turned off: nothing was sent or queued. */
247
+ off: boolean;
248
+ /** Nobody to send it to (no address, an unpaid hold, a test run). */
249
+ none: boolean;
250
+ }
251
+ export interface RoutineMailModule {
252
+ send(input: RoutineSendInput): Promise<RoutineSendResult>;
253
+ }
254
+ export type RoutineFieldSlotManifest = RoutineFieldSlot;
255
+ export type RoutineSlotManifest = RoutineSlotSpec;
256
+ export type RoutineCalendarManifest = RoutineCalendarSpec;
257
+ export interface RoutineMessageManifest {
258
+ subject: string;
259
+ text: string;
260
+ textMessage?: string | undefined;
261
+ push?: RoutinePushWords | undefined;
262
+ guardian?: {
263
+ subject: string;
264
+ text: string;
265
+ textMessage?: string | undefined;
266
+ push?: RoutinePushWords | undefined;
267
+ } | undefined;
268
+ calendar?: RoutineCalendarSpec | readonly RoutineCalendarSpec[] | undefined;
269
+ }
270
+ export interface RoutineMailKindManifest {
271
+ label: string;
272
+ description: string;
273
+ about: string;
274
+ on?: boolean | undefined;
275
+ essential?: boolean | undefined;
276
+ purpose?: RoutinePurpose | undefined;
277
+ urgent?: boolean | undefined;
278
+ until?: string | undefined;
279
+ channels?: readonly RoutineChannel[] | undefined;
280
+ open?: {
281
+ screen: string;
282
+ } | undefined;
283
+ receipt?: boolean | undefined;
284
+ slots: Record<string, RoutineSlotSpec>;
285
+ messages: Record<string, RoutineMessageManifest>;
286
+ }
287
+ export declare const routineMailManifestSchema: z.ZodType<Record<string, RoutineMailKindManifest>>;
288
+ /** The channels a kind may go on: email, and what it declares. */
289
+ export declare function channelsOf(kind: Pick<RoutineMailKindManifest, "channels">): RoutineChannel[];
290
+ /** Whether a person may not turn the kind's email off (decision 9; follow-ups never are). */
291
+ export declare function essentialOf(kind: Pick<RoutineMailKindManifest, "essential" | "purpose">): boolean;
292
+ /** A kind's messages' calendar events, as a list. */
293
+ export declare function calendarsOf(message: RoutineMessageManifest): RoutineCalendarManifest[];
294
+ type Piece = {
295
+ text: string;
296
+ } | {
297
+ slot: string;
298
+ };
299
+ type Part = Piece | {
300
+ optional: Piece[];
301
+ };
302
+ export interface ParsedTemplate {
303
+ lines: Part[][];
304
+ /** Every slot the template names. */
305
+ slots: Set<string>;
306
+ /** Slots named only inside optional parts. */
307
+ optionalOnly: Set<string>;
308
+ error: string | null;
309
+ }
310
+ /** Parses a template; `error` says what is wrong with it (the manifest check reports it). */
311
+ export declare function parseTemplate(template: string): ParsedTemplate;
312
+ /** The literal words of a template (what the pack wrote, not the slots). */
313
+ export declare function literalText(parsed: ParsedTemplate): string;
314
+ /**
315
+ * Renders a template. A slot with no value (null or undefined) empties its optional part; outside
316
+ * one it is written as nothing (the host holds such a send for a person). A line that had words
317
+ * and is left with none is dropped.
318
+ */
319
+ export declare function renderTemplate(template: string | ParsedTemplate, values: Readonly<Record<string, string | null | undefined>>): string;
320
+ /**
321
+ * Why `value` cannot go into a routine email, or null when it can: one line of at most `max`
322
+ * characters, no hidden, blank-looking or direction-changing characters, nothing that is or
323
+ * becomes a link or an address (look-alike dots and spelled-out ones included), no markup, no
324
+ * phone number and nothing asking the reader to call or text one. A member's name, a class's
325
+ * title and a cancellation's reason are checked with it. A legitimate title with a phone number
326
+ * in it is held for a person: that is the intended outcome.
327
+ */
328
+ export declare function unroutineText(value: string, max: number): string | null;
329
+ /** Why the words a pack declares cannot be routine, or null (a link only through a link slot). */
330
+ export declare function unroutineWords(words: string): string | null;
331
+ /** A moment as a member reads it, in a zone (ADR 0460): "Monday 7 December at 06:00 (Europe/London time)". */
332
+ export declare function formatMoment(iso: string, zone: string | null, as: "datetime" | "time" | "date", year?: boolean): string | null;
333
+ /** An amount in minor units: "12.50 AUD". */
334
+ export declare function formatMoney(minor: number, currency: string): string | null;
335
+ /** How a text is sent: its encoding, its length in that encoding's units, and its segments. */
336
+ export declare function textSegments(value: string): {
337
+ encoding: "gsm" | "ucs2";
338
+ units: number;
339
+ segments: number;
340
+ };
341
+ /**
342
+ * A text in the plainest characters that say the same (a dash for an en dash, straight quotes,
343
+ * a space for a no-break space), so one typographic character does not double its cost.
344
+ */
345
+ export declare function textForm(value: string): string;
346
+ /** A text as it is sent: the business's name first, the words, and the stop line last. */
347
+ export declare function wrapText(sender: string, words: string): string;
348
+ /** A form-link slot's declaration. */
349
+ export interface FormLinkSlotSpec {
350
+ object: string;
351
+ setting: string;
352
+ days?: number;
353
+ once?: number;
354
+ }
355
+ /** The kind's form-link slots, by name (at most one is allowed). */
356
+ export declare function formLinkSlotsOf(kind: Pick<RoutineMailKindManifest, "slots">): [string, FormLinkSlotSpec][];
357
+ /** The longest link a text may carry: a longer one fails its row at the host (ADR 0670). */
358
+ export declare const TEXT_LINK_MAX = 120;
359
+ interface CheckFieldManifest {
360
+ type: string;
361
+ to?: string | undefined;
362
+ readOnly?: boolean | undefined;
363
+ }
364
+ interface CheckManifest {
365
+ id: string;
366
+ objects: Record<string, {
367
+ fields: Record<string, CheckFieldManifest>;
368
+ customer?: {
369
+ field: string;
370
+ } | undefined;
371
+ intake?: {
372
+ role: string;
373
+ form?: string;
374
+ } | undefined;
375
+ }>;
376
+ settings: Record<string, {
377
+ type: string;
378
+ personApproves?: boolean | undefined;
379
+ }>;
380
+ permissions: {
381
+ modules: readonly string[];
382
+ };
383
+ routineMail?: Record<string, RoutineMailKindManifest> | undefined;
384
+ }
385
+ /**
386
+ * The type of the field at `path` from `object` (a local object name, or `order`), walking only
387
+ * relations to this extension's own objects; or why it cannot be read.
388
+ */
389
+ export declare function routinePathType(manifest: CheckManifest, object: string, fieldPath: string): {
390
+ type: string;
391
+ to?: string;
392
+ } | {
393
+ problem: string;
394
+ };
395
+ /** Contract issues in an extension's routine mail. */
396
+ export declare function routineMailIssues(manifest: CheckManifest): {
397
+ path: string;
398
+ message: string;
399
+ }[];
400
+ export {};