@composable-os/sdk 0.0.0-stage → 0.1.0-beta.8
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.
- package/LICENSE +109 -0
- package/dist/automation-check.d.ts +38 -0
- package/dist/automation-check.js +454 -0
- package/dist/automation.d.ts +767 -0
- package/dist/automation.js +303 -0
- package/dist/behaviour.d.ts +3 -0
- package/dist/behaviour.js +153 -0
- package/dist/capacity.d.ts +51 -0
- package/dist/capacity.js +68 -0
- package/dist/contract.d.ts +706 -0
- package/dist/contract.js +42 -0
- package/dist/document.d.ts +165 -0
- package/dist/document.js +636 -0
- package/dist/field-types.d.ts +11 -0
- package/dist/field-types.js +93 -0
- package/dist/formula/ast.d.ts +67 -0
- package/dist/formula/ast.js +22 -0
- package/dist/formula/compile.d.ts +37 -0
- package/dist/formula/compile.js +379 -0
- package/dist/formula/index.d.ts +3 -0
- package/dist/formula/index.js +4 -0
- package/dist/formula/parser.d.ts +13 -0
- package/dist/formula/parser.js +365 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +21 -0
- package/dist/manifest.d.ts +1131 -0
- package/dist/manifest.js +1229 -0
- package/dist/media.d.ts +9 -0
- package/dist/media.js +43 -0
- package/dist/permissions.d.ts +17 -0
- package/dist/permissions.js +44 -0
- package/dist/renamed.d.ts +16 -0
- package/dist/renamed.js +59 -0
- package/dist/rich-text-fixture.d.ts +121 -0
- package/dist/rich-text-fixture.js +67 -0
- package/dist/rich-text.d.ts +34 -0
- package/dist/rich-text.js +138 -0
- package/dist/runtime.d.ts +95 -0
- package/dist/runtime.js +312 -0
- package/dist/sellable.d.ts +103 -0
- package/dist/sellable.js +258 -0
- package/dist/slug.d.ts +11 -0
- package/dist/slug.js +23 -0
- package/dist/states.d.ts +64 -0
- package/dist/states.js +101 -0
- package/dist/testing.d.ts +151 -0
- package/dist/testing.js +670 -0
- package/package.json +34 -4
- package/src/automation-check.ts +534 -0
- package/src/automation.ts +743 -0
- package/src/behaviour.ts +215 -0
- package/src/capacity.ts +112 -0
- package/src/contract.ts +766 -0
- package/src/document.ts +788 -0
- package/src/field-types.ts +106 -0
- package/src/formula/ast.ts +72 -0
- package/src/formula/compile.ts +454 -0
- package/src/formula/index.ts +4 -0
- package/src/formula/parser.ts +417 -0
- package/src/index.ts +33 -0
- package/src/manifest.ts +1484 -0
- package/src/media.ts +46 -0
- package/src/permissions.ts +60 -0
- package/src/renamed.ts +63 -0
- package/src/rich-text-fixture.ts +68 -0
- package/src/rich-text.ts +173 -0
- package/src/runtime.ts +410 -0
- package/src/sellable.ts +396 -0
- package/src/slug.ts +25 -0
- package/src/states.ts +162 -0
- package/src/testing.ts +836 -0
- package/README.md +0 -3
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { AutomationSpec } from "./automation.ts";
|
|
3
|
+
import type { CapacitySpec } from "./capacity.ts";
|
|
4
|
+
import type { DocumentPathSpec, DocumentSchema } from "./document.ts";
|
|
5
|
+
import type { FieldTypeName } from "./field-types.ts";
|
|
6
|
+
import type { SellableSpec } from "./sellable.ts";
|
|
7
|
+
import type { StatesSpec } from "./states.ts";
|
|
8
|
+
/** The contract version this SDK writes. The host accepts this and the previous version. */
|
|
9
|
+
export declare const CONTRACT_VERSION = 1;
|
|
10
|
+
/** Contract versions a host built with this SDK runs (current and previous, ADR 0005). */
|
|
11
|
+
export declare const SUPPORTED_CONTRACT_VERSIONS: readonly number[];
|
|
12
|
+
/**
|
|
13
|
+
* Gatekeepers code can reach as `codemode:<gatekeeper>` host modules (stage 6a, ADR 0050): the
|
|
14
|
+
* only way out to an external service. Calls go through the integration host as the caller,
|
|
15
|
+
* reads are observations and side effects are outbound actions under the approval gate.
|
|
16
|
+
*/
|
|
17
|
+
export declare const GATEKEEPER_MODULES: readonly ["google", "microsoft", "slack", "slack-post", "mcp", "email", "email-send", "zoominfo", "websearch", "webhook", "fake"];
|
|
18
|
+
export type GatekeeperModuleName = (typeof GATEKEEPER_MODULES)[number];
|
|
19
|
+
/** Host modules an extension can ask for (ADR 0025). There is no HTTP module. */
|
|
20
|
+
export declare const HOST_MODULES: readonly ["ops", "storage", "log", "ai", "google", "microsoft", "slack", "slack-post", "mcp", "email", "email-send", "zoominfo", "websearch", "webhook", "fake"];
|
|
21
|
+
export type HostModuleName = (typeof HOST_MODULES)[number];
|
|
22
|
+
/** Risk classes an extension tool may declare (schema and extension risks are host-only). */
|
|
23
|
+
export declare const TOOL_RISKS: readonly ["read", "write", "bulk-write", "destructive"];
|
|
24
|
+
export type ToolRisk = (typeof TOOL_RISKS)[number];
|
|
25
|
+
interface FieldBase {
|
|
26
|
+
/** Label shown in the UI. */
|
|
27
|
+
label: string;
|
|
28
|
+
/** Help text for people and models. */
|
|
29
|
+
description?: string;
|
|
30
|
+
/** `timeline`: changes post a system activity on the record (ADR 0017). */
|
|
31
|
+
track?: "timeline";
|
|
32
|
+
/** The field's previous name. Without it a missing field is a removal (hidden, kept 30 days). */
|
|
33
|
+
renamedFrom?: string;
|
|
34
|
+
/** Refuse records without a value. */
|
|
35
|
+
required?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Maintained by the host (for example a stage behaviour's won/lost date) or by this
|
|
38
|
+
* extension's own tools and automations, never written by other callers of record operations.
|
|
39
|
+
* Shown, filtered and sorted like any field.
|
|
40
|
+
*/
|
|
41
|
+
readOnly?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The value a new record gets when none is given (ADR 0246): a text, number, boolean, date or
|
|
44
|
+
* select value of the field's type. Fields of your own objects only.
|
|
45
|
+
*/
|
|
46
|
+
default?: string | number | boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Like `default`, but read from one of this extension's settings when the record is created,
|
|
49
|
+
* so admins choose it (a lead's source). Wins over `default` when the setting has a value.
|
|
50
|
+
*/
|
|
51
|
+
defaultSetting?: string;
|
|
52
|
+
}
|
|
53
|
+
export type SelectOption = string | {
|
|
54
|
+
value: string;
|
|
55
|
+
label?: string;
|
|
56
|
+
color?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Fields that must have a value for a record to hold this choice (a stage rule, ADR 0058).
|
|
59
|
+
* Moving a record to it without them is refused by the update operation, naming the field,
|
|
60
|
+
* so a board drag asks for it.
|
|
61
|
+
*/
|
|
62
|
+
requires?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* With `editableOptions`: admins can relabel, recolour and reorder this option but not
|
|
65
|
+
* remove it (the extension's code relies on it).
|
|
66
|
+
*/
|
|
67
|
+
fixed?: boolean;
|
|
68
|
+
};
|
|
69
|
+
export type FieldSpec = (FieldBase & {
|
|
70
|
+
type: "text" | "longText" | "date" | "datetime" | "boolean" | "user" | "email" | "phone" | "url" | "timezone";
|
|
71
|
+
}) | (FieldBase & NumberBounds & {
|
|
72
|
+
type: "number" | "percent";
|
|
73
|
+
}) | (FieldBase & NumberBounds & {
|
|
74
|
+
type: "currency";
|
|
75
|
+
/** ISO 4217 code shown with the value. Default USD. */
|
|
76
|
+
currency?: string;
|
|
77
|
+
}) | (FieldBase & {
|
|
78
|
+
type: "select" | "multiSelect";
|
|
79
|
+
options: readonly SelectOption[];
|
|
80
|
+
/**
|
|
81
|
+
* Admins can edit the options in Settings → Extensions (ADR 0246): add, relabel, recolour,
|
|
82
|
+
* reorder, and remove options not marked `fixed`. The declared options are the defaults.
|
|
83
|
+
*/
|
|
84
|
+
editableOptions?: boolean;
|
|
85
|
+
}) | (FieldBase & {
|
|
86
|
+
type: "relation";
|
|
87
|
+
/** Target object: `person`, `organisation`, `task`, or `<extension>.<object>`. */
|
|
88
|
+
to: string;
|
|
89
|
+
/** Many records (stored as a JSON array of ids). Default one. */
|
|
90
|
+
many?: boolean;
|
|
91
|
+
}) | (Omit<FieldBase, "default" | "defaultSetting" | "track"> & {
|
|
92
|
+
/**
|
|
93
|
+
* One JSON document checked against `schema` on every write, by every actor (ADR 0445).
|
|
94
|
+
* A fault is refused with its path. `maxBytes` (default 65,536, at most 524,288) limits
|
|
95
|
+
* its JSON. `paths` show values inside it as read-only columns of the object's rec_* view,
|
|
96
|
+
* to list, filter, sort and chart by. A `private` object node is removed from what a
|
|
97
|
+
* customer or the public reads.
|
|
98
|
+
*/
|
|
99
|
+
type: "document";
|
|
100
|
+
schema: DocumentSchema;
|
|
101
|
+
maxBytes?: number;
|
|
102
|
+
paths?: Record<string, DocumentPathSpec>;
|
|
103
|
+
}) | (Omit<FieldBase, "default" | "defaultSetting" | "track"> & {
|
|
104
|
+
/**
|
|
105
|
+
* Structured prose (stage 28, ADR 0440): a document with the platform's one schema,
|
|
106
|
+
* `RICH_TEXT_SCHEMA` (paragraphs, headings, lists, quotes, pictures, dividers, embeds,
|
|
107
|
+
* callouts and buttons; bold, italic, code and links). HTML, script and anything the
|
|
108
|
+
* schema does not name are refused on every write. `maxBytes` defaults to 131,072.
|
|
109
|
+
*/
|
|
110
|
+
type: "richText";
|
|
111
|
+
maxBytes?: number;
|
|
112
|
+
}) | (Omit<FieldBase, "default" | "defaultSetting"> & {
|
|
113
|
+
/**
|
|
114
|
+
* A record's address (stage 28, ADR 0442): lowercase letters and digits in words joined
|
|
115
|
+
* by hyphens, at most 120 characters, unique among the object's live records. Left empty
|
|
116
|
+
* on a new record, the host makes one from the title. Name it as `publishable.slug`.
|
|
117
|
+
*/
|
|
118
|
+
type: "slug";
|
|
119
|
+
}) | (Omit<FieldBase, "default" | "defaultSetting" | "track"> & {
|
|
120
|
+
/**
|
|
121
|
+
* A picture from the media library (stage 28, ADR 0444): `{ media, alt, focal? }`, the
|
|
122
|
+
* media item's id (a live one, checked on write), its alt text and the point to keep in
|
|
123
|
+
* view when a client crops it. Published content's pictures are served to the public.
|
|
124
|
+
*/
|
|
125
|
+
type: "image";
|
|
126
|
+
}) | (Omit<FieldBase, "required"> & {
|
|
127
|
+
type: "formula";
|
|
128
|
+
/** An expression over fields of the same record. See the SDK README for the grammar. */
|
|
129
|
+
expression: string;
|
|
130
|
+
});
|
|
131
|
+
/**
|
|
132
|
+
* Bounds of a number field (stage 41): the host refuses a value below `min`, above `max`, or not
|
|
133
|
+
* a multiple of `step` from `min` (or from 0), for every actor, in imports and in the dry run.
|
|
134
|
+
* An RPE is `{ min: 1, max: 10, step: 0.5 }`; a count of reps `{ min: 0, step: 1 }`.
|
|
135
|
+
*/
|
|
136
|
+
export interface NumberBounds {
|
|
137
|
+
min?: number;
|
|
138
|
+
max?: number;
|
|
139
|
+
step?: number;
|
|
140
|
+
}
|
|
141
|
+
export type FieldSpecs = Record<string, FieldSpec>;
|
|
142
|
+
export interface ObjectSpec {
|
|
143
|
+
label: string;
|
|
144
|
+
plural: string;
|
|
145
|
+
/** A lucide icon name, e.g. `folder-kanban`. */
|
|
146
|
+
icon?: string;
|
|
147
|
+
/** The field used as the record's title (a text-like field). */
|
|
148
|
+
titleField: string;
|
|
149
|
+
description?: string;
|
|
150
|
+
/** The object's previous name, when renaming. */
|
|
151
|
+
renamedFrom?: string;
|
|
152
|
+
fields: FieldSpecs;
|
|
153
|
+
/**
|
|
154
|
+
* Where the object is listed: `main` (the sidebar, default), `settings` (set-up records such as
|
|
155
|
+
* pipelines, listed under Settings → Extensions) or `none` (reached from other records only).
|
|
156
|
+
*/
|
|
157
|
+
navigation?: "main" | "settings" | "none";
|
|
158
|
+
/**
|
|
159
|
+
* Indexes on the object's table, each a list of up to 4 own, single-valued, non-formula fields
|
|
160
|
+
* (or `createdAt` / `updatedAt`). They cover live rows only. Declare one for every field the
|
|
161
|
+
* object's hot lists filter or sort by.
|
|
162
|
+
*/
|
|
163
|
+
indexes?: readonly (readonly string[])[];
|
|
164
|
+
/**
|
|
165
|
+
* Relation fields (one record each) whose records also get this object's timeline posts, e.g.
|
|
166
|
+
* `["organisation"]` posts a deal's stage moves on its organisation's timeline too.
|
|
167
|
+
*/
|
|
168
|
+
timelineLinks?: readonly string[];
|
|
169
|
+
/** A pipeline-like stage behaviour (see StagesSpec). */
|
|
170
|
+
stages?: StagesSpec;
|
|
171
|
+
/** A limited number of places, never given out twice (see CapacitySpec, ADR 0430). */
|
|
172
|
+
capacity?: CapacitySpec;
|
|
173
|
+
/** Something that can be bought, and what a paid line grants (see SellableSpec, ADR 0435). */
|
|
174
|
+
sellable?: SellableSpec;
|
|
175
|
+
/** A fixed state machine (see StatesSpec, ADR 0425). An object has stages or states, not both. */
|
|
176
|
+
states?: StatesSpec;
|
|
177
|
+
/**
|
|
178
|
+
* The record's owner: a `user` field of this object (ADR 0246, stage 14). Assignment rules set
|
|
179
|
+
* it when a record is created without one, and stage 14's visibility policies read it.
|
|
180
|
+
*/
|
|
181
|
+
owner?: string;
|
|
182
|
+
/**
|
|
183
|
+
* The object's customer (ADR 0402): whose record it is, and what that customer may read and
|
|
184
|
+
* write, field by field. `field` is a relation to one person. A signed-in customer sees only
|
|
185
|
+
* records where it is their own Person, and of those only the fields in `read`. Fields in
|
|
186
|
+
* `write` (a subset of `read`) are the ones they may set. Left out, the object does not exist
|
|
187
|
+
* for customers. Only shipped extensions and an org's own may declare it; a runtime extension
|
|
188
|
+
* fails `check`.
|
|
189
|
+
*/
|
|
190
|
+
customer?: CustomerSpec;
|
|
191
|
+
/**
|
|
192
|
+
* What the public may read of this object (ADR 0438): the fields in `read`, of the records that
|
|
193
|
+
* meet `when`. Deny by default: left out, the public sees nothing of it, and a record that does
|
|
194
|
+
* not meet `when` is not found. A signed-in customer reads it too, unless the object declares a
|
|
195
|
+
* `customer` (an object declares one or the other). The public reaches it only through a pack's
|
|
196
|
+
* tool open to them (`public.list`, `public.get`). Only shipped extensions and an org's own may
|
|
197
|
+
* declare it.
|
|
198
|
+
*/
|
|
199
|
+
public?: PublicSpec;
|
|
200
|
+
/**
|
|
201
|
+
* What every signed-in customer may read of this object (ADR 0447), whoever's record it is:
|
|
202
|
+
* the fields in `read`, of the records that meet `when` (the shape of `public.when`), or of
|
|
203
|
+
* every live record without it. Beside a `customer` declaration it shares those records with
|
|
204
|
+
* every signed-in customer while each still reads and writes their own as before (a class's
|
|
205
|
+
* sessions beside a client's own); on its own it opens the records to read only (an exercise
|
|
206
|
+
* bank). Never read by the public. Only shipped extensions and an org's own may declare it.
|
|
207
|
+
*/
|
|
208
|
+
signedIn?: SignedInSpec;
|
|
209
|
+
/**
|
|
210
|
+
* What a customer may read of a record that one of their own records points to (ADR 0439):
|
|
211
|
+
* the fields in `read`, of the records that a record of `from` (an object of this extension
|
|
212
|
+
* that declares a `customer`) whose customer is the caller points to through its relation
|
|
213
|
+
* `field`. A ticket's holder reads its event's name, times and venue whatever the event's
|
|
214
|
+
* state. Deny by default: left out, a customer reads nothing of this object through their own
|
|
215
|
+
* records. An object that declares a `customer` cannot declare it; one that declares `public`
|
|
216
|
+
* or `signedIn` can, and a customer then reads both. Only shipped extensions and an org's own
|
|
217
|
+
* may declare it.
|
|
218
|
+
*/
|
|
219
|
+
customerVia?: CustomerViaSpec;
|
|
220
|
+
/**
|
|
221
|
+
* A working copy staff edit and published versions (ADR 0446): `content` names the fields a
|
|
222
|
+
* version keeps. `record.publish` snapshots them as the next version (a person with the
|
|
223
|
+
* publish permission, never an AI actor); `record.versions` and `record.version` read them;
|
|
224
|
+
* `record.restoreVersion` copies one back into the working copy. Editing the working copy
|
|
225
|
+
* never changes a version. Records get read-only `publishedVersion` and `publishedAt`.
|
|
226
|
+
*/
|
|
227
|
+
publishable?: PublishableSpec;
|
|
228
|
+
/** Position in the sidebar among extension objects (lower first). Default 100. */
|
|
229
|
+
navigationOrder?: number;
|
|
230
|
+
/**
|
|
231
|
+
* Groups of fields of which a record must have at least one (ADR 0246): `[["person",
|
|
232
|
+
* "organisation"]]` refuses a lead with neither. Checked by the host on every create and update.
|
|
233
|
+
*/
|
|
234
|
+
requireOneOf?: readonly (readonly string[])[];
|
|
235
|
+
/**
|
|
236
|
+
* Names a record created without a title (ADR 0246): the title of the first of these relation
|
|
237
|
+
* fields that has a value, then `suffix` (a lead is "Ada Lovelace lead"). The title field can
|
|
238
|
+
* then be left blank in the create form.
|
|
239
|
+
*/
|
|
240
|
+
titleDefault?: {
|
|
241
|
+
from: readonly string[];
|
|
242
|
+
suffix?: string;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Records created once, when the object is first installed (default pipelines and stages).
|
|
246
|
+
* Keyed by a seed key (camelCase); a relation value `{ seed: "<key>" }` points at another seed
|
|
247
|
+
* record of the relation's target (one of this extension's objects). Later releases never
|
|
248
|
+
* re-apply seeds, so people can edit or delete seeded records.
|
|
249
|
+
*/
|
|
250
|
+
seed?: Record<string, Record<string, unknown>>;
|
|
251
|
+
}
|
|
252
|
+
/** Stage types every stage object distinguishes. */
|
|
253
|
+
export declare const STAGE_TYPES: readonly ["open", "won", "lost"];
|
|
254
|
+
export type StageType = (typeof STAGE_TYPES)[number];
|
|
255
|
+
/**
|
|
256
|
+
* A stage behaviour (ADR 0100): the object moves through ordered stages (records of another of the
|
|
257
|
+
* extension's objects), optionally grouped (pipelines). The host enforces it in the record
|
|
258
|
+
* operations, so it applies to every actor: people, MCP clients, Code Mode, extensions.
|
|
259
|
+
*
|
|
260
|
+
* - Entering a stage needs the stage's required fields and `requiredByType[type]` to have values;
|
|
261
|
+
* otherwise the write is refused with a structured error naming the missing fields.
|
|
262
|
+
* - `group` must match the stage's group; a record given only a group starts in its first stage.
|
|
263
|
+
* - `probability.field` follows the stage's default probability unless it was set by hand
|
|
264
|
+
* (`probability.overridden` is then true; clearing that flag resets it).
|
|
265
|
+
* - `closedDate` is set on entering a won or lost stage and cleared on reopening; `status` mirrors
|
|
266
|
+
* the stage type.
|
|
267
|
+
* - Every stage change is recorded in stage history (entered and left times) and, when the field
|
|
268
|
+
* is tracked, posted on the timeline as "Moved to <stage>".
|
|
269
|
+
*/
|
|
270
|
+
export interface StagesSpec {
|
|
271
|
+
/** This object's relation field (one) holding its stage. */
|
|
272
|
+
field: string;
|
|
273
|
+
/** Fields of the stage object (the relation's target). */
|
|
274
|
+
stage: {
|
|
275
|
+
/** A select whose option values include `open`, `won` and `lost`. */
|
|
276
|
+
type: string;
|
|
277
|
+
/** A number field ordering stages within their group. */
|
|
278
|
+
order: string;
|
|
279
|
+
/** A multiSelect whose option values are this object's field names. */
|
|
280
|
+
requiredFields?: string;
|
|
281
|
+
/** A number or percent field: the default probability of records in the stage. */
|
|
282
|
+
probability?: string;
|
|
283
|
+
/** A relation field to the group object (e.g. the stage's pipeline). */
|
|
284
|
+
group?: string;
|
|
285
|
+
};
|
|
286
|
+
/** This object's relation field to the group object (e.g. the deal's pipeline). */
|
|
287
|
+
group?: string;
|
|
288
|
+
/** This object's probability (number or percent) and the boolean flag set when it is overridden. */
|
|
289
|
+
probability?: {
|
|
290
|
+
field: string;
|
|
291
|
+
overridden: string;
|
|
292
|
+
};
|
|
293
|
+
/** This object's date field set on entering a won or lost stage, cleared on reopening. */
|
|
294
|
+
closedDate?: string;
|
|
295
|
+
/** This object's select field mirroring the stage type (options open, won, lost). */
|
|
296
|
+
status?: string;
|
|
297
|
+
/** Fields required in every stage of a type, on top of each stage's own required fields. */
|
|
298
|
+
requiredByType?: Partial<Record<StageType, readonly string[]>>;
|
|
299
|
+
/**
|
|
300
|
+
* A text setting of this extension (`settings`) naming the group (by id or title) a record
|
|
301
|
+
* created without a group or stage goes in, e.g. the default pipeline.
|
|
302
|
+
*/
|
|
303
|
+
defaultGroupSetting?: string;
|
|
304
|
+
}
|
|
305
|
+
export type FilterOp = "eq" | "neq" | "lt" | "lte" | "gt" | "gte" | "between" | "in" | "not_in" | "contains" | "not_contains" | "starts_with" | "ends_with" | "is_null" | "is_not_null";
|
|
306
|
+
export type ViewFilter = {
|
|
307
|
+
field: string;
|
|
308
|
+
op: FilterOp;
|
|
309
|
+
value?: unknown;
|
|
310
|
+
} | {
|
|
311
|
+
and: ViewFilter[];
|
|
312
|
+
} | {
|
|
313
|
+
or: ViewFilter[];
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* A saved view shipped with the extension: shared with everyone, read-only, listed in the
|
|
317
|
+
* object's views menu (ADR 0103). A table by default, or a board, calendar or gallery (ADR 0056).
|
|
318
|
+
* Filter values may be relative: `{ $relative: "me" | "today" | "startOfMonth" | … }`.
|
|
319
|
+
*/
|
|
320
|
+
export interface ViewSpec {
|
|
321
|
+
label: string;
|
|
322
|
+
/** Object the view lists: core or `<extension>.<object>`. */
|
|
323
|
+
object: string;
|
|
324
|
+
type?: "table" | "board" | "calendar" | "gallery";
|
|
325
|
+
filter?: ViewFilter;
|
|
326
|
+
sort?: {
|
|
327
|
+
field: string;
|
|
328
|
+
direction?: "asc" | "desc";
|
|
329
|
+
};
|
|
330
|
+
columns?: string[];
|
|
331
|
+
/** board: the single-select or stage relation to group by, and a number field to sum. */
|
|
332
|
+
groupBy?: string;
|
|
333
|
+
sumField?: string;
|
|
334
|
+
/** calendar */
|
|
335
|
+
dateField?: string;
|
|
336
|
+
mode?: "month" | "week" | "agenda";
|
|
337
|
+
/** gallery */
|
|
338
|
+
imageField?: string;
|
|
339
|
+
/** board, calendar, gallery: fields on each card. */
|
|
340
|
+
cardFields?: string[];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* A view on another object's record page (ADR 0058): a tab, or a side panel, listing records of
|
|
344
|
+
* `view.object` whose `view.relation` field points at the record being shown, e.g. the projects
|
|
345
|
+
* of an organisation. The host renders it with its own components; extensions ship no UI.
|
|
346
|
+
*/
|
|
347
|
+
export interface RecordViewSpec {
|
|
348
|
+
label: string;
|
|
349
|
+
/** The record page it appears on: `person`, `organisation`, `task` or `<extension>.<object>`. */
|
|
350
|
+
on: string;
|
|
351
|
+
view: {
|
|
352
|
+
type: "table" | "board" | "calendar" | "gallery";
|
|
353
|
+
/** The object listed. */
|
|
354
|
+
object: string;
|
|
355
|
+
/** The field of `object` that holds the current record's id (a relation, or `linkedRecordId`). */
|
|
356
|
+
relation: string;
|
|
357
|
+
filter?: ViewFilter;
|
|
358
|
+
sort?: {
|
|
359
|
+
field: string;
|
|
360
|
+
direction?: "asc" | "desc";
|
|
361
|
+
};
|
|
362
|
+
/** table: fields shown. */
|
|
363
|
+
columns?: string[];
|
|
364
|
+
/** board: the single-select field to group by, and an optional number field to sum. */
|
|
365
|
+
groupBy?: string;
|
|
366
|
+
sumField?: string;
|
|
367
|
+
/** calendar: the date field, and the starting mode. */
|
|
368
|
+
dateField?: string;
|
|
369
|
+
mode?: "month" | "week" | "agenda";
|
|
370
|
+
/** gallery: an image URL field. */
|
|
371
|
+
imageField?: string;
|
|
372
|
+
/** board, calendar, gallery: fields shown on each card. */
|
|
373
|
+
cardFields?: string[];
|
|
374
|
+
};
|
|
375
|
+
/** Order among the page's tabs or panels (lower first). Default 100. */
|
|
376
|
+
order?: number;
|
|
377
|
+
}
|
|
378
|
+
/** A typed extension setting, edited by admins in Settings → Extensions (ADR 0058). */
|
|
379
|
+
export type SettingSpec = {
|
|
380
|
+
label: string;
|
|
381
|
+
description?: string;
|
|
382
|
+
required?: boolean;
|
|
383
|
+
} & ({
|
|
384
|
+
type: "text";
|
|
385
|
+
default?: string;
|
|
386
|
+
} | {
|
|
387
|
+
type: "number";
|
|
388
|
+
default?: number;
|
|
389
|
+
min?: number;
|
|
390
|
+
max?: number;
|
|
391
|
+
} | {
|
|
392
|
+
type: "boolean";
|
|
393
|
+
default?: boolean;
|
|
394
|
+
} | {
|
|
395
|
+
type: "select";
|
|
396
|
+
options: readonly SelectOption[];
|
|
397
|
+
default?: string;
|
|
398
|
+
});
|
|
399
|
+
export interface OpsModule {
|
|
400
|
+
/** Calls an operation (e.g. `organisation.get`) as this extension, through the gate. */
|
|
401
|
+
call<T = unknown>(operation: string, input?: unknown): Promise<T>;
|
|
402
|
+
}
|
|
403
|
+
export interface StorageModule {
|
|
404
|
+
get<T = unknown>(key: string): Promise<T | null>;
|
|
405
|
+
set(key: string, value: unknown): Promise<void>;
|
|
406
|
+
delete(key: string): Promise<void>;
|
|
407
|
+
list(prefix?: string): Promise<{
|
|
408
|
+
key: string;
|
|
409
|
+
value: unknown;
|
|
410
|
+
}[]>;
|
|
411
|
+
}
|
|
412
|
+
export interface LogModule {
|
|
413
|
+
info(message: string, data?: unknown): void;
|
|
414
|
+
warn(message: string, data?: unknown): void;
|
|
415
|
+
error(message: string, data?: unknown): void;
|
|
416
|
+
}
|
|
417
|
+
export interface AiModule {
|
|
418
|
+
/** Model role `summarise`. */
|
|
419
|
+
summarise(text: string, options?: {
|
|
420
|
+
maxWords?: number;
|
|
421
|
+
}): Promise<string>;
|
|
422
|
+
/** Model role `extract`: fills `fields` (name → description) from text. */
|
|
423
|
+
extract(text: string, fields: Record<string, string>): Promise<Record<string, unknown>>;
|
|
424
|
+
/** Model role `classify`: picks one of `labels`. */
|
|
425
|
+
classify(text: string, labels: string[]): Promise<{
|
|
426
|
+
label: string;
|
|
427
|
+
}>;
|
|
428
|
+
}
|
|
429
|
+
/** A connected gatekeeper (`codemode:<gatekeeper>`), reached through its connections. */
|
|
430
|
+
export interface GatekeeperModule {
|
|
431
|
+
/** Connections of this gatekeeper the caller may use, with their bound resources. */
|
|
432
|
+
connections(): Promise<{
|
|
433
|
+
id: string;
|
|
434
|
+
title: string;
|
|
435
|
+
resources: {
|
|
436
|
+
key: string;
|
|
437
|
+
bindingName: string;
|
|
438
|
+
tsType: string;
|
|
439
|
+
}[];
|
|
440
|
+
}[]>;
|
|
441
|
+
/**
|
|
442
|
+
* Calls a top-level session method of a bound resource. Side effects come back as pending
|
|
443
|
+
* outbound actions (in `pending`) until a person approves them.
|
|
444
|
+
*/
|
|
445
|
+
call(connectionId: string, resource: string, method: string, ...args: unknown[]): Promise<{
|
|
446
|
+
value: unknown;
|
|
447
|
+
pending: unknown[];
|
|
448
|
+
applied: unknown[];
|
|
449
|
+
}>;
|
|
450
|
+
/** The session's TypeScript declarations. */
|
|
451
|
+
types(connectionId: string, resource: string): Promise<string>;
|
|
452
|
+
}
|
|
453
|
+
export interface ExtensionContext {
|
|
454
|
+
extension: {
|
|
455
|
+
id: string;
|
|
456
|
+
version: string;
|
|
457
|
+
};
|
|
458
|
+
ops: OpsModule;
|
|
459
|
+
storage: StorageModule;
|
|
460
|
+
log: LogModule;
|
|
461
|
+
ai: AiModule;
|
|
462
|
+
/** A gatekeeper declared in permissions.modules, e.g. `ctx.gatekeeper("email-send")`. */
|
|
463
|
+
gatekeeper(name: GatekeeperModuleName): GatekeeperModule;
|
|
464
|
+
/** Who started this tool, from the host (ADR 0436). Absent in automations. */
|
|
465
|
+
caller?: StartedBy;
|
|
466
|
+
}
|
|
467
|
+
export interface ToolSpec<In extends z.ZodType = z.ZodType, Out extends z.ZodType = z.ZodType> {
|
|
468
|
+
/** For a model: what it does, when to use it, side effects. At least 20 characters. */
|
|
469
|
+
description: string;
|
|
470
|
+
input: In;
|
|
471
|
+
output: Out;
|
|
472
|
+
/** Default `write`. */
|
|
473
|
+
risk?: ToolRisk;
|
|
474
|
+
/**
|
|
475
|
+
* Shows the tool as a button on the record page of `object` (ADR 0246). The host calls it with
|
|
476
|
+
* the record's id in the `idInput` field. If the output has `open: { object, id }`, the app
|
|
477
|
+
* opens that record afterwards.
|
|
478
|
+
*/
|
|
479
|
+
recordAction?: RecordActionSpec;
|
|
480
|
+
/**
|
|
481
|
+
* Who may call the tool: a non-empty subset of `staff`, `customer`, `public`. Left out, staff
|
|
482
|
+
* only. A tool open to `customer` or `public` must have risk `read` or `write`. Called by a
|
|
483
|
+
* customer, the tool runs as that customer: `ctx.ops` reaches only their own records, through
|
|
484
|
+
* `my.list`, `my.get`, `my.create` and `my.update`. Only shipped extensions and an org's own
|
|
485
|
+
* may open a tool; a runtime extension fails `check` (ADR 0402, ADR 0414).
|
|
486
|
+
*/
|
|
487
|
+
audiences?: readonly ToolAudience[];
|
|
488
|
+
/**
|
|
489
|
+
* Fields this tool may set on a customer's own records beyond the object's `customer.write`,
|
|
490
|
+
* by object: a cancel tool lists `{ "shop.order": ["status"] }`. Never the customer field and
|
|
491
|
+
* never `id`. The host allows exactly these, for calls made by this tool (ADR 0414).
|
|
492
|
+
*/
|
|
493
|
+
customerFields?: Readonly<Record<string, readonly string[]>>;
|
|
494
|
+
/**
|
|
495
|
+
* The permission a staff caller needs, named `<extension id>:<word>` (`ticketing:checkin`), for
|
|
496
|
+
* a role of this extension to hold (`roles`, ADR 0436). Admins and members hold it as they hold
|
|
497
|
+
* any tool (a viewer only when the tool's risk is `read`); a staff account given one of this
|
|
498
|
+
* extension's roles holds it only when the role lists it. Only shipped extensions and an org's
|
|
499
|
+
* own may declare it.
|
|
500
|
+
*/
|
|
501
|
+
permission?: string;
|
|
502
|
+
handler(input: z.output<In>, ctx: ExtensionContext): Promise<z.input<Out>> | z.input<Out>;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* A fixed staff role an extension declares (ADR 0436): a named set of the permissions its tools
|
|
506
|
+
* declare, and the objects of its own whose records the role may read (`record.get` and
|
|
507
|
+
* `record.list`). A human admin gives it to a staff account, which then may do exactly this and
|
|
508
|
+
* nothing else: no other records, no settings, no other operation. The door role of Ticketing:
|
|
509
|
+
* `{ permissions: ["ticketing:checkin"], read: ["ticketing.event", ...] }`. Only shipped
|
|
510
|
+
* extensions and an org's own may declare one.
|
|
511
|
+
*/
|
|
512
|
+
export interface RoleSpec {
|
|
513
|
+
label: string;
|
|
514
|
+
/** What the role is for, shown to the admin who gives it. */
|
|
515
|
+
description: string;
|
|
516
|
+
/** Permissions of this extension's tools (`<id>:<word>`) the role holds. */
|
|
517
|
+
permissions: readonly string[];
|
|
518
|
+
/** Objects of this extension (`<id>.<object>`) whose records the role may read. */
|
|
519
|
+
read: readonly string[];
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Who started a tool (ADR 0436), set by the host from the session it verified and never from the
|
|
523
|
+
* input: a staff user, a signed-in customer or the public. A tool's own operation calls run as
|
|
524
|
+
* the extension (or as the customer, ADR 0414); this is for recording who asked, such as who
|
|
525
|
+
* checked a ticket in. Absent in automations and in a manifest evaluation.
|
|
526
|
+
*/
|
|
527
|
+
export type StartedBy = {
|
|
528
|
+
readonly kind: "staff";
|
|
529
|
+
readonly userId: string;
|
|
530
|
+
readonly name: string;
|
|
531
|
+
} | {
|
|
532
|
+
readonly kind: "customer";
|
|
533
|
+
} | {
|
|
534
|
+
readonly kind: "public";
|
|
535
|
+
};
|
|
536
|
+
/** Who may call a tool. `staff` when nothing is declared (ADR 0402). */
|
|
537
|
+
export declare const TOOL_AUDIENCES: readonly ["staff", "customer", "public"];
|
|
538
|
+
export type ToolAudience = (typeof TOOL_AUDIENCES)[number];
|
|
539
|
+
/**
|
|
540
|
+
* What the public may read of an object (ADR 0438). `when` is a condition on a state (a select
|
|
541
|
+
* field) of the record itself, or, with `via`, of the record one of its relations points to: an
|
|
542
|
+
* event while it is `on_sale`; a ticket type while its event is.
|
|
543
|
+
*/
|
|
544
|
+
export interface PublicSpec {
|
|
545
|
+
read: readonly string[];
|
|
546
|
+
/** Left out, every live record is public (a catalogue item). */
|
|
547
|
+
when?: {
|
|
548
|
+
/** A relation of this object, to another object of this extension: test that record. */
|
|
549
|
+
via?: string;
|
|
550
|
+
/** A select field (of this record, or of the one `via` points to). */
|
|
551
|
+
field: string;
|
|
552
|
+
/** The values for which the record is public. */
|
|
553
|
+
in: readonly string[];
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* What a customer reads of a record their own record points to (ADR 0439): see
|
|
558
|
+
* `ObjectSpec.customerVia`. `from` is `<extension>.<object>`, as a relation's `to` is.
|
|
559
|
+
*/
|
|
560
|
+
export interface CustomerViaSpec {
|
|
561
|
+
/** An object of this extension that declares a `customer` (a ticket). */
|
|
562
|
+
from: string;
|
|
563
|
+
/** A relation of `from` to one record of this object (the ticket's `event`). */
|
|
564
|
+
field: string;
|
|
565
|
+
/** Fields of this object its customer may read. */
|
|
566
|
+
read: readonly string[];
|
|
567
|
+
}
|
|
568
|
+
/** What every signed-in customer may read: see `ObjectSpec.signedIn` (ADR 0447). */
|
|
569
|
+
export interface SignedInSpec {
|
|
570
|
+
read: readonly string[];
|
|
571
|
+
/** Left out, every live record. */
|
|
572
|
+
when?: PublicSpec["when"];
|
|
573
|
+
}
|
|
574
|
+
/** Versions of an object's content: see `ObjectSpec.publishable` (ADR 0446). */
|
|
575
|
+
export interface PublishableSpec {
|
|
576
|
+
/** The fields a version keeps: the content staff edit in the working copy. */
|
|
577
|
+
content: readonly string[];
|
|
578
|
+
/**
|
|
579
|
+
* The record's address (stage 28, ADR 0442): a `slug` field of the object's own, not in
|
|
580
|
+
* `content`. The public reads a record by it (`content.get`); a published record whose slug
|
|
581
|
+
* changes keeps the old one as a redirect. Needed to declare `public`.
|
|
582
|
+
*/
|
|
583
|
+
slug?: string;
|
|
584
|
+
/**
|
|
585
|
+
* The date a reader is shown (stage 28, ADR 0441): a date or datetime field in `content`. Left
|
|
586
|
+
* empty, publishing fills it with the time it goes live, in the working copy and the version.
|
|
587
|
+
* Set, it is kept: an imported post keeps its date.
|
|
588
|
+
*/
|
|
589
|
+
date?: string;
|
|
590
|
+
}
|
|
591
|
+
/** An object's customer: see `ObjectSpec.customer`. */
|
|
592
|
+
export interface CustomerSpec {
|
|
593
|
+
field: string;
|
|
594
|
+
read: readonly string[];
|
|
595
|
+
write: readonly string[];
|
|
596
|
+
}
|
|
597
|
+
/** A tool shown as a button on a record page. */
|
|
598
|
+
export interface RecordActionSpec {
|
|
599
|
+
/** The object whose record pages show the button (`leads.lead`). */
|
|
600
|
+
object: string;
|
|
601
|
+
label: string;
|
|
602
|
+
/** The input field that receives the record id. */
|
|
603
|
+
idInput: string;
|
|
604
|
+
/** A confirmation question shown before running it. */
|
|
605
|
+
confirm?: string;
|
|
606
|
+
/** One choice to ask for first, passed in the `input` field (a disqualify reason). */
|
|
607
|
+
ask?: {
|
|
608
|
+
input: string;
|
|
609
|
+
label: string;
|
|
610
|
+
options: readonly {
|
|
611
|
+
value: string;
|
|
612
|
+
label: string;
|
|
613
|
+
}[];
|
|
614
|
+
};
|
|
615
|
+
/** Hides the button while the record's `field` holds one of `values` (a converted lead). */
|
|
616
|
+
hideWhen?: {
|
|
617
|
+
field: string;
|
|
618
|
+
values: readonly string[];
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
export declare function defineTool<In extends z.ZodType, Out extends z.ZodType>(tool: ToolSpec<In, Out>): ToolSpec<In, Out>;
|
|
622
|
+
/**
|
|
623
|
+
* What the extension may do, approved like OAuth scopes. Its own objects are always readable and
|
|
624
|
+
* writable. `read`/`write` name objects (`organisation`, `other.object`); `write` implies `read`.
|
|
625
|
+
* `operations` lists further operations by exact name (e.g. `task.create`, `search.global`).
|
|
626
|
+
*/
|
|
627
|
+
export interface PermissionsSpec {
|
|
628
|
+
read?: string[];
|
|
629
|
+
write?: string[];
|
|
630
|
+
operations?: string[];
|
|
631
|
+
modules?: HostModuleName[];
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* A dashboard the extension ships (ADR 0103): the same filters and widgets as a dashboard spec
|
|
635
|
+
* (ADR 0057; SQL over rec_* views with named params, a chart mapping, a click-through). It is
|
|
636
|
+
* read-only, listed while the extension is active and copyable; `home: true` makes it everyone's
|
|
637
|
+
* default Home.
|
|
638
|
+
*/
|
|
639
|
+
export interface DashboardDeclaration {
|
|
640
|
+
title: string;
|
|
641
|
+
description?: string;
|
|
642
|
+
home?: boolean;
|
|
643
|
+
filters?: readonly Record<string, unknown>[];
|
|
644
|
+
widgets: readonly WidgetDeclaration[];
|
|
645
|
+
}
|
|
646
|
+
/** A widget of a shipped dashboard; see the host's dashboard spec for every option. */
|
|
647
|
+
export interface WidgetDeclaration {
|
|
648
|
+
id: string;
|
|
649
|
+
type: "kpi" | "bar" | "line" | "donut" | "funnel" | "table" | "leaderboard" | "markdown";
|
|
650
|
+
title: string;
|
|
651
|
+
description?: string;
|
|
652
|
+
sql?: string;
|
|
653
|
+
markdown?: string;
|
|
654
|
+
mapping?: Record<string, unknown>;
|
|
655
|
+
options?: Record<string, unknown>;
|
|
656
|
+
clickThrough?: {
|
|
657
|
+
object: string;
|
|
658
|
+
objectColumn?: string;
|
|
659
|
+
filter?: unknown;
|
|
660
|
+
};
|
|
661
|
+
layout?: {
|
|
662
|
+
w?: number;
|
|
663
|
+
h?: number;
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
export interface ExtensionSpec {
|
|
667
|
+
/** Lowercase letters and digits, starting with a letter: `deals`, `example`. */
|
|
668
|
+
id: string;
|
|
669
|
+
/** Semver, e.g. `1.0.0`. */
|
|
670
|
+
version: string;
|
|
671
|
+
contractVersion: number;
|
|
672
|
+
label?: string;
|
|
673
|
+
description?: string;
|
|
674
|
+
permissions?: PermissionsSpec;
|
|
675
|
+
objects?: Record<string, ObjectSpec>;
|
|
676
|
+
/** Fields added to other objects, keyed by target object (`organisation`, `other.object`). */
|
|
677
|
+
fields?: Record<string, FieldSpecs>;
|
|
678
|
+
views?: Record<string, ViewSpec>;
|
|
679
|
+
/** Dashboards shipped with the extension (ADR 0103). */
|
|
680
|
+
dashboards?: Record<string, DashboardDeclaration>;
|
|
681
|
+
/** Tabs on other objects' record pages (ADR 0058). */
|
|
682
|
+
recordTabs?: Record<string, RecordViewSpec>;
|
|
683
|
+
/** Side panels on other objects' record pages (ADR 0058). */
|
|
684
|
+
recordPanels?: Record<string, RecordViewSpec>;
|
|
685
|
+
/** Typed settings, edited in Settings → Extensions (ADR 0058). */
|
|
686
|
+
settings?: Record<string, SettingSpec>;
|
|
687
|
+
tools?: Record<string, ToolSpec<any, any>>;
|
|
688
|
+
automations?: Record<string, AutomationSpec<any>>;
|
|
689
|
+
/** Fixed staff roles an admin can give to a staff account (ADR 0436). */
|
|
690
|
+
roles?: Record<string, RoleSpec>;
|
|
691
|
+
/**
|
|
692
|
+
* Permissions of this extension's tools (`<id>:<word>`) a human admin may grant to a staff
|
|
693
|
+
* account one by one (ADR 0449), on top of its role: a coach who is a member granted the
|
|
694
|
+
* permission of a tool a member could not otherwise call. Only shipped extensions and an org's
|
|
695
|
+
* own may declare them.
|
|
696
|
+
*/
|
|
697
|
+
grantable?: readonly string[];
|
|
698
|
+
}
|
|
699
|
+
declare const EXTENSION: unique symbol;
|
|
700
|
+
export type Extension<E extends ExtensionSpec = ExtensionSpec> = E & {
|
|
701
|
+
readonly [EXTENSION]: true;
|
|
702
|
+
};
|
|
703
|
+
/** The entry point of every extension: `export default defineExtension({ ... })`. */
|
|
704
|
+
export declare function defineExtension<const E extends ExtensionSpec>(extension: E): Extension<E>;
|
|
705
|
+
export declare function isExtension(value: unknown): value is Extension;
|
|
706
|
+
export type { FieldTypeName };
|