@composable-os/sdk 0.0.0-stage → 0.1.0-beta.10
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/allowance.d.ts +198 -0
- package/dist/allowance.js +374 -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 +77 -0
- package/dist/capacity.js +127 -0
- package/dist/contract.d.ts +819 -0
- package/dist/contract.js +42 -0
- package/dist/document.d.ts +211 -0
- package/dist/document.js +726 -0
- package/dist/field-types.d.ts +11 -0
- package/dist/field-types.js +98 -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 +20 -0
- package/dist/index.js +24 -0
- package/dist/manifest.d.ts +1596 -0
- package/dist/manifest.js +1420 -0
- package/dist/media.d.ts +41 -0
- package/dist/media.js +90 -0
- package/dist/permissions.d.ts +17 -0
- package/dist/permissions.js +44 -0
- package/dist/recurring.d.ts +114 -0
- package/dist/recurring.js +173 -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 +48 -0
- package/dist/rich-text.js +184 -0
- package/dist/runtime.d.ts +95 -0
- package/dist/runtime.js +312 -0
- package/dist/sellable.d.ts +253 -0
- package/dist/sellable.js +593 -0
- package/dist/slug.d.ts +11 -0
- package/dist/slug.js +23 -0
- package/dist/states.d.ts +238 -0
- package/dist/states.js +315 -0
- package/dist/testing.d.ts +151 -0
- package/dist/testing.js +679 -0
- package/dist/unique.d.ts +20 -0
- package/dist/unique.js +58 -0
- package/package.json +34 -4
- package/src/allowance.ts +522 -0
- package/src/automation-check.ts +534 -0
- package/src/automation.ts +743 -0
- package/src/behaviour.ts +215 -0
- package/src/capacity.ts +201 -0
- package/src/contract.ts +884 -0
- package/src/document.ts +935 -0
- package/src/field-types.ts +111 -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 +36 -0
- package/src/manifest.ts +1709 -0
- package/src/media.ts +108 -0
- package/src/permissions.ts +60 -0
- package/src/recurring.ts +321 -0
- package/src/renamed.ts +63 -0
- package/src/rich-text-fixture.ts +68 -0
- package/src/rich-text.ts +221 -0
- package/src/runtime.ts +410 -0
- package/src/sellable.ts +888 -0
- package/src/slug.ts +25 -0
- package/src/states.ts +484 -0
- package/src/testing.ts +847 -0
- package/src/unique.ts +81 -0
- package/README.md +0 -3
package/dist/contract.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** The contract version this SDK writes. The host accepts this and the previous version. */
|
|
2
|
+
export const CONTRACT_VERSION = 1;
|
|
3
|
+
/** Contract versions a host built with this SDK runs (current and previous, ADR 0005). */
|
|
4
|
+
export const SUPPORTED_CONTRACT_VERSIONS = [CONTRACT_VERSION];
|
|
5
|
+
/**
|
|
6
|
+
* Gatekeepers code can reach as `codemode:<gatekeeper>` host modules (stage 6a, ADR 0050): the
|
|
7
|
+
* only way out to an external service. Calls go through the integration host as the caller,
|
|
8
|
+
* reads are observations and side effects are outbound actions under the approval gate.
|
|
9
|
+
*/
|
|
10
|
+
export const GATEKEEPER_MODULES = [
|
|
11
|
+
"google",
|
|
12
|
+
"microsoft",
|
|
13
|
+
"slack",
|
|
14
|
+
"slack-post",
|
|
15
|
+
"mcp",
|
|
16
|
+
"email",
|
|
17
|
+
"email-send",
|
|
18
|
+
"zoominfo",
|
|
19
|
+
"websearch",
|
|
20
|
+
"webhook",
|
|
21
|
+
// The fake provider: development and tests only (it answers only when turned on).
|
|
22
|
+
"fake",
|
|
23
|
+
];
|
|
24
|
+
/** Host modules an extension can ask for (ADR 0025). There is no HTTP module. */
|
|
25
|
+
export const HOST_MODULES = ["ops", "storage", "log", "ai", ...GATEKEEPER_MODULES];
|
|
26
|
+
/** Risk classes an extension tool may declare (schema and extension risks are host-only). */
|
|
27
|
+
export const TOOL_RISKS = ["read", "write", "bulk-write", "destructive"];
|
|
28
|
+
/** Stage types every stage object distinguishes. */
|
|
29
|
+
export const STAGE_TYPES = ["open", "won", "lost"];
|
|
30
|
+
/** Who may call a tool. `staff` when nothing is declared (ADR 0402). */
|
|
31
|
+
export const TOOL_AUDIENCES = ["staff", "customer", "public"];
|
|
32
|
+
export function defineTool(tool) {
|
|
33
|
+
return tool;
|
|
34
|
+
}
|
|
35
|
+
const EXTENSION = Symbol.for("ops.extension");
|
|
36
|
+
/** The entry point of every extension: `export default defineExtension({ ... })`. */
|
|
37
|
+
export function defineExtension(extension) {
|
|
38
|
+
return { ...extension, [EXTENSION]: true };
|
|
39
|
+
}
|
|
40
|
+
export function isExtension(value) {
|
|
41
|
+
return typeof value === "object" && value !== null && EXTENSION in value;
|
|
42
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/** The most a document may be, in bytes of its JSON, whatever a field declares. */
|
|
2
|
+
export declare const DOCUMENT_MAX_BYTES = 524288;
|
|
3
|
+
/** A field that declares no `maxBytes`. */
|
|
4
|
+
export declare const DOCUMENT_DEFAULT_BYTES = 65536;
|
|
5
|
+
/** The deepest a value may nest (objects and lists), and a schema. */
|
|
6
|
+
export declare const DOCUMENT_MAX_DEPTH = 24;
|
|
7
|
+
/** The most entries any one list may declare. */
|
|
8
|
+
export declare const DOCUMENT_MAX_LIST = 1000;
|
|
9
|
+
/** The longest a text node may declare, and the default when it declares none. */
|
|
10
|
+
export declare const DOCUMENT_MAX_TEXT = 20000;
|
|
11
|
+
export declare const DOCUMENT_DEFAULT_TEXT = 1000;
|
|
12
|
+
/** Faults reported for one value, at most. */
|
|
13
|
+
export declare const DOCUMENT_MAX_ISSUES = 20;
|
|
14
|
+
/** Declared paths (view columns) per field, at most. */
|
|
15
|
+
export declare const DOCUMENT_MAX_PATHS = 12;
|
|
16
|
+
/** Whether `value` is a link of the given kind (a text node's `href`). */
|
|
17
|
+
export declare function isDocumentHref(value: string, kind: "web" | "link"): boolean;
|
|
18
|
+
/** Whether `value` holds markup a `noMarkup` text node refuses. */
|
|
19
|
+
export declare function hasMarkup(value: string): boolean;
|
|
20
|
+
interface NodeBase {
|
|
21
|
+
/** For people and models: what the node holds. */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** In an object's `fields`: the key may be left out. */
|
|
24
|
+
optional?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface DocumentObjectNode extends NodeBase {
|
|
27
|
+
type: "object";
|
|
28
|
+
fields: Record<string, DocumentNode>;
|
|
29
|
+
/**
|
|
30
|
+
* Removed when a customer or the public reads the document. `{ unless: "<key>" }` keeps it when
|
|
31
|
+
* that boolean key of the object is true (a note marked as shown to members).
|
|
32
|
+
*/
|
|
33
|
+
private?: true | {
|
|
34
|
+
unless: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* For holders only (stage 42, ADR 0477): removed when someone outside the org who does not
|
|
38
|
+
* hold access to the record reads the document. `true` or `{ unless }` removes the whole object,
|
|
39
|
+
* as `private` does; `{ keys, unless? }` removes only those keys of it (a lesson's video and
|
|
40
|
+
* notes, while its title stays). `unless` names a boolean key of this object that keeps it (a
|
|
41
|
+
* free preview).
|
|
42
|
+
*/
|
|
43
|
+
holders?: DocumentHolders;
|
|
44
|
+
}
|
|
45
|
+
/** What of an object node is for holders only: see `DocumentObjectNode.holders`. */
|
|
46
|
+
export type DocumentHolders = true | {
|
|
47
|
+
unless: string;
|
|
48
|
+
keys?: undefined;
|
|
49
|
+
} | {
|
|
50
|
+
keys: readonly string[];
|
|
51
|
+
unless?: string;
|
|
52
|
+
};
|
|
53
|
+
/** The kinds of media item (stage 42, ADR 0475). */
|
|
54
|
+
export type DocumentMediaKind = "image" | "video" | "file";
|
|
55
|
+
export interface DocumentArrayNode extends NodeBase {
|
|
56
|
+
type: "array";
|
|
57
|
+
of: DocumentNode;
|
|
58
|
+
max: number;
|
|
59
|
+
min?: number;
|
|
60
|
+
/** A key of the listed objects whose values must differ (labels, level numbers). */
|
|
61
|
+
unique?: string;
|
|
62
|
+
/**
|
|
63
|
+
* With `unique`: the key's values must differ across every list this node holds in the
|
|
64
|
+
* document, not only within one (stage 42: a lesson's key across all sections, since progress
|
|
65
|
+
* is kept by it).
|
|
66
|
+
*/
|
|
67
|
+
uniqueAcross?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface DocumentTextNode extends NodeBase {
|
|
70
|
+
type: "text";
|
|
71
|
+
/** Characters at most. Default 1000. */
|
|
72
|
+
max?: number;
|
|
73
|
+
min?: number;
|
|
74
|
+
/** Newlines allowed. */
|
|
75
|
+
multiline?: boolean;
|
|
76
|
+
/** The only characters allowed, e.g. "0123456789X" for a tempo. */
|
|
77
|
+
chars?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Refuses markup (stage 28, ADR 0440): an HTML tag, closing tag, comment or processing
|
|
80
|
+
* instruction (`<b`, `</`, `<!`, `<?`) and a character reference (`&`, `<`). A lone
|
|
81
|
+
* `<` before a space or a digit is text. Rich text's text is always this.
|
|
82
|
+
*/
|
|
83
|
+
noMarkup?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The text is a link (stage 28, ADR 0440). `web`: an absolute `http:` or `https:` URL.
|
|
86
|
+
* `link`: that, or `mailto:`, `tel:`, a path on the site (`/about`, never `//host`) or an
|
|
87
|
+
* anchor (`#top`). Any other scheme (`javascript:`, `data:`, `vbscript:`) is refused.
|
|
88
|
+
*/
|
|
89
|
+
href?: "web" | "link";
|
|
90
|
+
}
|
|
91
|
+
export interface DocumentNumberNode extends NodeBase {
|
|
92
|
+
type: "number";
|
|
93
|
+
min?: number;
|
|
94
|
+
max?: number;
|
|
95
|
+
integer?: boolean;
|
|
96
|
+
/** Multiples of this from `min` (or 0): 0.5 for an RPE. */
|
|
97
|
+
step?: number;
|
|
98
|
+
}
|
|
99
|
+
export interface DocumentBooleanNode extends NodeBase {
|
|
100
|
+
type: "boolean";
|
|
101
|
+
}
|
|
102
|
+
export interface DocumentChoiceNode extends NodeBase {
|
|
103
|
+
type: "choice";
|
|
104
|
+
options: readonly string[];
|
|
105
|
+
}
|
|
106
|
+
/** The id of a live record of `to`, checked by the host when the document is written. */
|
|
107
|
+
export interface DocumentRefNode extends NodeBase {
|
|
108
|
+
type: "ref";
|
|
109
|
+
to: string;
|
|
110
|
+
/**
|
|
111
|
+
* For a ref to `media` (stage 42, ADR 0475): the kind of item it takes, checked by the host on
|
|
112
|
+
* write; a video must also be ready. Left out, any live item.
|
|
113
|
+
*/
|
|
114
|
+
media?: DocumentMediaKind;
|
|
115
|
+
}
|
|
116
|
+
/** One of several object shapes, told apart by the value of `tag`. */
|
|
117
|
+
export interface DocumentUnionNode extends NodeBase {
|
|
118
|
+
type: "union";
|
|
119
|
+
tag: string;
|
|
120
|
+
variants: Record<string, DocumentObjectNode>;
|
|
121
|
+
}
|
|
122
|
+
/** A named definition of the schema's `defs`. */
|
|
123
|
+
export interface DocumentUseNode extends NodeBase {
|
|
124
|
+
type: "use";
|
|
125
|
+
def: string;
|
|
126
|
+
}
|
|
127
|
+
export type DocumentNode = DocumentObjectNode | DocumentArrayNode | DocumentTextNode | DocumentNumberNode | DocumentBooleanNode | DocumentChoiceNode | DocumentRefNode | DocumentUnionNode | DocumentUseNode;
|
|
128
|
+
export interface DocumentSchema {
|
|
129
|
+
root: DocumentObjectNode;
|
|
130
|
+
defs?: Record<string, DocumentNode>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A value inside the document that the object's rec_* view shows as a column of its own, which
|
|
134
|
+
* lists, filters, sorts and dashboards read like any field: `path` is keys from the root through
|
|
135
|
+
* objects only (`title`, `meta.level`). With `count`, the path names a list and the column is its
|
|
136
|
+
* length.
|
|
137
|
+
*/
|
|
138
|
+
export interface DocumentPathSpec {
|
|
139
|
+
label: string;
|
|
140
|
+
path: string;
|
|
141
|
+
count?: boolean;
|
|
142
|
+
description?: string;
|
|
143
|
+
}
|
|
144
|
+
/** What a declared path reads as: the type of its column. */
|
|
145
|
+
export type DocumentPathType = "text" | "number" | "boolean" | "id";
|
|
146
|
+
/** A fault in a value: where, and what is wrong. */
|
|
147
|
+
export interface DocumentIssue {
|
|
148
|
+
path: (string | number)[];
|
|
149
|
+
message: string;
|
|
150
|
+
}
|
|
151
|
+
export type DocumentResult = {
|
|
152
|
+
ok: true;
|
|
153
|
+
value: unknown;
|
|
154
|
+
bytes: number;
|
|
155
|
+
} | {
|
|
156
|
+
ok: false;
|
|
157
|
+
issues: DocumentIssue[];
|
|
158
|
+
};
|
|
159
|
+
/** Bytes of a value's JSON, as stored. */
|
|
160
|
+
export declare function documentBytes(value: unknown): number;
|
|
161
|
+
/**
|
|
162
|
+
* What is wrong with a declared schema, as `[path, message]` pairs (the path from the schema's
|
|
163
|
+
* own root: `root.fields.weeks.of`). Empty when nothing is. `knownObjects`, when given, holds the
|
|
164
|
+
* objects a `ref` may name.
|
|
165
|
+
*/
|
|
166
|
+
export declare function checkDocumentSchema(schema: unknown, knownObjects?: ReadonlySet<string>): [string, string][];
|
|
167
|
+
/** The node a declared path reaches, or why it reaches none. */
|
|
168
|
+
export declare function documentPathNode(schema: DocumentSchema, spec: Pick<DocumentPathSpec, "path" | "count">): {
|
|
169
|
+
type: DocumentPathType;
|
|
170
|
+
} | string;
|
|
171
|
+
/** The JSON path SQLite reads a declared path with: `$.meta.level`. */
|
|
172
|
+
export declare function documentJsonPath(path: string): string;
|
|
173
|
+
/**
|
|
174
|
+
* Checks `value` against `schema`: every fault, with its path, or the value and its size. A value
|
|
175
|
+
* over `maxBytes` (capped at DOCUMENT_MAX_BYTES) is refused before it is walked.
|
|
176
|
+
*/
|
|
177
|
+
export declare function validateDocument(schema: DocumentSchema, value: unknown, options?: {
|
|
178
|
+
maxBytes?: number;
|
|
179
|
+
}): DocumentResult;
|
|
180
|
+
/** "weeks.0.sessions.2: Required", for messages. */
|
|
181
|
+
export declare function formatDocumentIssue(issue: DocumentIssue): string;
|
|
182
|
+
/** One `ref` of a value: the object it names, the id, where it is, and a media ref's kind. */
|
|
183
|
+
export interface DocumentRef {
|
|
184
|
+
to: string;
|
|
185
|
+
id: string;
|
|
186
|
+
path: (string | number)[];
|
|
187
|
+
media?: DocumentMediaKind;
|
|
188
|
+
}
|
|
189
|
+
/** Every `ref` in a valid value: the object it names, the id, and where it is. */
|
|
190
|
+
export declare function documentRefs(schema: DocumentSchema, value: unknown): DocumentRef[];
|
|
191
|
+
/** Who outside the org may read a part of a document (ADR 0477). */
|
|
192
|
+
export type DocumentReach = "all" | "holders" | "private";
|
|
193
|
+
/**
|
|
194
|
+
* The media items a value names, each with who outside the org reads the part it is in: `all`
|
|
195
|
+
* (anyone who may read the field), `holders` (only a reader who holds access to the record) or
|
|
196
|
+
* `private` (no one outside the org). Read from `redactDocument` itself, so it is exactly what the
|
|
197
|
+
* seam shows. An item named in several parts has the widest reach of them.
|
|
198
|
+
*/
|
|
199
|
+
export declare function documentMediaReach(schema: DocumentSchema, value: unknown, mediaObject?: string): Map<string, DocumentReach>;
|
|
200
|
+
/**
|
|
201
|
+
* The document as someone outside the org may read it: every `private` object removed (from a
|
|
202
|
+
* list, its entry; from an object, its key), unless its `unless` key is true. Unless `holder` is
|
|
203
|
+
* true (the reader holds access to the record, ADR 0477), every `holders` object is removed the
|
|
204
|
+
* same way and every `holders` key of an object dropped, unless its `unless` key is true. A value
|
|
205
|
+
* that does not fit the schema is returned as null: an outsider is never shown what was not
|
|
206
|
+
* checked.
|
|
207
|
+
*/
|
|
208
|
+
export declare function redactDocument(schema: DocumentSchema, value: unknown, options?: {
|
|
209
|
+
holder?: boolean;
|
|
210
|
+
}): unknown;
|
|
211
|
+
export {};
|