@composable-os/sdk 0.0.0-stage → 0.1.0-beta.7

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 (72) hide show
  1. package/LICENSE +109 -0
  2. package/dist/automation-check.d.ts +38 -0
  3. package/dist/automation-check.js +454 -0
  4. package/dist/automation.d.ts +767 -0
  5. package/dist/automation.js +303 -0
  6. package/dist/behaviour.d.ts +3 -0
  7. package/dist/behaviour.js +153 -0
  8. package/dist/capacity.d.ts +51 -0
  9. package/dist/capacity.js +68 -0
  10. package/dist/contract.d.ts +706 -0
  11. package/dist/contract.js +42 -0
  12. package/dist/document.d.ts +165 -0
  13. package/dist/document.js +636 -0
  14. package/dist/field-types.d.ts +11 -0
  15. package/dist/field-types.js +93 -0
  16. package/dist/formula/ast.d.ts +67 -0
  17. package/dist/formula/ast.js +22 -0
  18. package/dist/formula/compile.d.ts +37 -0
  19. package/dist/formula/compile.js +379 -0
  20. package/dist/formula/index.d.ts +3 -0
  21. package/dist/formula/index.js +4 -0
  22. package/dist/formula/parser.d.ts +13 -0
  23. package/dist/formula/parser.js +365 -0
  24. package/dist/index.d.ts +17 -0
  25. package/dist/index.js +21 -0
  26. package/dist/manifest.d.ts +1131 -0
  27. package/dist/manifest.js +1229 -0
  28. package/dist/media.d.ts +9 -0
  29. package/dist/media.js +43 -0
  30. package/dist/permissions.d.ts +17 -0
  31. package/dist/permissions.js +44 -0
  32. package/dist/renamed.d.ts +16 -0
  33. package/dist/renamed.js +59 -0
  34. package/dist/rich-text-fixture.d.ts +121 -0
  35. package/dist/rich-text-fixture.js +67 -0
  36. package/dist/rich-text.d.ts +34 -0
  37. package/dist/rich-text.js +138 -0
  38. package/dist/runtime.d.ts +95 -0
  39. package/dist/runtime.js +312 -0
  40. package/dist/sellable.d.ts +103 -0
  41. package/dist/sellable.js +258 -0
  42. package/dist/slug.d.ts +11 -0
  43. package/dist/slug.js +23 -0
  44. package/dist/states.d.ts +64 -0
  45. package/dist/states.js +101 -0
  46. package/dist/testing.d.ts +151 -0
  47. package/dist/testing.js +670 -0
  48. package/package.json +34 -4
  49. package/src/automation-check.ts +534 -0
  50. package/src/automation.ts +743 -0
  51. package/src/behaviour.ts +215 -0
  52. package/src/capacity.ts +112 -0
  53. package/src/contract.ts +766 -0
  54. package/src/document.ts +788 -0
  55. package/src/field-types.ts +106 -0
  56. package/src/formula/ast.ts +72 -0
  57. package/src/formula/compile.ts +454 -0
  58. package/src/formula/index.ts +4 -0
  59. package/src/formula/parser.ts +417 -0
  60. package/src/index.ts +33 -0
  61. package/src/manifest.ts +1484 -0
  62. package/src/media.ts +46 -0
  63. package/src/permissions.ts +60 -0
  64. package/src/renamed.ts +63 -0
  65. package/src/rich-text-fixture.ts +68 -0
  66. package/src/rich-text.ts +173 -0
  67. package/src/runtime.ts +410 -0
  68. package/src/sellable.ts +396 -0
  69. package/src/slug.ts +25 -0
  70. package/src/states.ts +162 -0
  71. package/src/testing.ts +836 -0
  72. package/README.md +0 -3
@@ -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,165 @@
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
+ export interface DocumentArrayNode extends NodeBase {
38
+ type: "array";
39
+ of: DocumentNode;
40
+ max: number;
41
+ min?: number;
42
+ /** A key of the listed objects whose values must differ (labels, level numbers). */
43
+ unique?: string;
44
+ }
45
+ export interface DocumentTextNode extends NodeBase {
46
+ type: "text";
47
+ /** Characters at most. Default 1000. */
48
+ max?: number;
49
+ min?: number;
50
+ /** Newlines allowed. */
51
+ multiline?: boolean;
52
+ /** The only characters allowed, e.g. "0123456789X" for a tempo. */
53
+ chars?: string;
54
+ /**
55
+ * Refuses markup (stage 28, ADR 0440): an HTML tag, closing tag, comment or processing
56
+ * instruction (`<b`, `</`, `<!`, `<?`) and a character reference (`&amp;`, `&#60;`). A lone
57
+ * `<` before a space or a digit is text. Rich text's text is always this.
58
+ */
59
+ noMarkup?: boolean;
60
+ /**
61
+ * The text is a link (stage 28, ADR 0440). `web`: an absolute `http:` or `https:` URL.
62
+ * `link`: that, or `mailto:`, `tel:`, a path on the site (`/about`, never `//host`) or an
63
+ * anchor (`#top`). Any other scheme (`javascript:`, `data:`, `vbscript:`) is refused.
64
+ */
65
+ href?: "web" | "link";
66
+ }
67
+ export interface DocumentNumberNode extends NodeBase {
68
+ type: "number";
69
+ min?: number;
70
+ max?: number;
71
+ integer?: boolean;
72
+ /** Multiples of this from `min` (or 0): 0.5 for an RPE. */
73
+ step?: number;
74
+ }
75
+ export interface DocumentBooleanNode extends NodeBase {
76
+ type: "boolean";
77
+ }
78
+ export interface DocumentChoiceNode extends NodeBase {
79
+ type: "choice";
80
+ options: readonly string[];
81
+ }
82
+ /** The id of a live record of `to`, checked by the host when the document is written. */
83
+ export interface DocumentRefNode extends NodeBase {
84
+ type: "ref";
85
+ to: string;
86
+ }
87
+ /** One of several object shapes, told apart by the value of `tag`. */
88
+ export interface DocumentUnionNode extends NodeBase {
89
+ type: "union";
90
+ tag: string;
91
+ variants: Record<string, DocumentObjectNode>;
92
+ }
93
+ /** A named definition of the schema's `defs`. */
94
+ export interface DocumentUseNode extends NodeBase {
95
+ type: "use";
96
+ def: string;
97
+ }
98
+ export type DocumentNode = DocumentObjectNode | DocumentArrayNode | DocumentTextNode | DocumentNumberNode | DocumentBooleanNode | DocumentChoiceNode | DocumentRefNode | DocumentUnionNode | DocumentUseNode;
99
+ export interface DocumentSchema {
100
+ root: DocumentObjectNode;
101
+ defs?: Record<string, DocumentNode>;
102
+ }
103
+ /**
104
+ * A value inside the document that the object's rec_* view shows as a column of its own, which
105
+ * lists, filters, sorts and dashboards read like any field: `path` is keys from the root through
106
+ * objects only (`title`, `meta.level`). With `count`, the path names a list and the column is its
107
+ * length.
108
+ */
109
+ export interface DocumentPathSpec {
110
+ label: string;
111
+ path: string;
112
+ count?: boolean;
113
+ description?: string;
114
+ }
115
+ /** What a declared path reads as: the type of its column. */
116
+ export type DocumentPathType = "text" | "number" | "boolean" | "id";
117
+ /** A fault in a value: where, and what is wrong. */
118
+ export interface DocumentIssue {
119
+ path: (string | number)[];
120
+ message: string;
121
+ }
122
+ export type DocumentResult = {
123
+ ok: true;
124
+ value: unknown;
125
+ bytes: number;
126
+ } | {
127
+ ok: false;
128
+ issues: DocumentIssue[];
129
+ };
130
+ /** Bytes of a value's JSON, as stored. */
131
+ export declare function documentBytes(value: unknown): number;
132
+ /**
133
+ * What is wrong with a declared schema, as `[path, message]` pairs (the path from the schema's
134
+ * own root: `root.fields.weeks.of`). Empty when nothing is. `knownObjects`, when given, holds the
135
+ * objects a `ref` may name.
136
+ */
137
+ export declare function checkDocumentSchema(schema: unknown, knownObjects?: ReadonlySet<string>): [string, string][];
138
+ /** The node a declared path reaches, or why it reaches none. */
139
+ export declare function documentPathNode(schema: DocumentSchema, spec: Pick<DocumentPathSpec, "path" | "count">): {
140
+ type: DocumentPathType;
141
+ } | string;
142
+ /** The JSON path SQLite reads a declared path with: `$.meta.level`. */
143
+ export declare function documentJsonPath(path: string): string;
144
+ /**
145
+ * Checks `value` against `schema`: every fault, with its path, or the value and its size. A value
146
+ * over `maxBytes` (capped at DOCUMENT_MAX_BYTES) is refused before it is walked.
147
+ */
148
+ export declare function validateDocument(schema: DocumentSchema, value: unknown, options?: {
149
+ maxBytes?: number;
150
+ }): DocumentResult;
151
+ /** "weeks.0.sessions.2: Required", for messages. */
152
+ export declare function formatDocumentIssue(issue: DocumentIssue): string;
153
+ /** Every `ref` in a valid value: the object it names, the id, and where it is. */
154
+ export declare function documentRefs(schema: DocumentSchema, value: unknown): {
155
+ to: string;
156
+ id: string;
157
+ path: (string | number)[];
158
+ }[];
159
+ /**
160
+ * The document as someone outside the org may read it: every `private` object removed (from a
161
+ * list, its entry; from an object, its key), unless its `unless` key is true. A value that does
162
+ * not fit the schema is returned as null: an outsider is never shown what was not checked.
163
+ */
164
+ export declare function redactDocument(schema: DocumentSchema, value: unknown): unknown;
165
+ export {};