@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.
Files changed (81) hide show
  1. package/LICENSE +109 -0
  2. package/dist/allowance.d.ts +198 -0
  3. package/dist/allowance.js +374 -0
  4. package/dist/automation-check.d.ts +38 -0
  5. package/dist/automation-check.js +454 -0
  6. package/dist/automation.d.ts +767 -0
  7. package/dist/automation.js +303 -0
  8. package/dist/behaviour.d.ts +3 -0
  9. package/dist/behaviour.js +153 -0
  10. package/dist/capacity.d.ts +77 -0
  11. package/dist/capacity.js +127 -0
  12. package/dist/contract.d.ts +819 -0
  13. package/dist/contract.js +42 -0
  14. package/dist/document.d.ts +211 -0
  15. package/dist/document.js +726 -0
  16. package/dist/field-types.d.ts +11 -0
  17. package/dist/field-types.js +98 -0
  18. package/dist/formula/ast.d.ts +67 -0
  19. package/dist/formula/ast.js +22 -0
  20. package/dist/formula/compile.d.ts +37 -0
  21. package/dist/formula/compile.js +379 -0
  22. package/dist/formula/index.d.ts +3 -0
  23. package/dist/formula/index.js +4 -0
  24. package/dist/formula/parser.d.ts +13 -0
  25. package/dist/formula/parser.js +365 -0
  26. package/dist/index.d.ts +20 -0
  27. package/dist/index.js +24 -0
  28. package/dist/manifest.d.ts +1596 -0
  29. package/dist/manifest.js +1420 -0
  30. package/dist/media.d.ts +41 -0
  31. package/dist/media.js +90 -0
  32. package/dist/permissions.d.ts +17 -0
  33. package/dist/permissions.js +44 -0
  34. package/dist/recurring.d.ts +114 -0
  35. package/dist/recurring.js +173 -0
  36. package/dist/renamed.d.ts +16 -0
  37. package/dist/renamed.js +59 -0
  38. package/dist/rich-text-fixture.d.ts +121 -0
  39. package/dist/rich-text-fixture.js +67 -0
  40. package/dist/rich-text.d.ts +48 -0
  41. package/dist/rich-text.js +184 -0
  42. package/dist/runtime.d.ts +95 -0
  43. package/dist/runtime.js +312 -0
  44. package/dist/sellable.d.ts +253 -0
  45. package/dist/sellable.js +593 -0
  46. package/dist/slug.d.ts +11 -0
  47. package/dist/slug.js +23 -0
  48. package/dist/states.d.ts +238 -0
  49. package/dist/states.js +315 -0
  50. package/dist/testing.d.ts +151 -0
  51. package/dist/testing.js +679 -0
  52. package/dist/unique.d.ts +20 -0
  53. package/dist/unique.js +58 -0
  54. package/package.json +34 -4
  55. package/src/allowance.ts +522 -0
  56. package/src/automation-check.ts +534 -0
  57. package/src/automation.ts +743 -0
  58. package/src/behaviour.ts +215 -0
  59. package/src/capacity.ts +201 -0
  60. package/src/contract.ts +884 -0
  61. package/src/document.ts +935 -0
  62. package/src/field-types.ts +111 -0
  63. package/src/formula/ast.ts +72 -0
  64. package/src/formula/compile.ts +454 -0
  65. package/src/formula/index.ts +4 -0
  66. package/src/formula/parser.ts +417 -0
  67. package/src/index.ts +36 -0
  68. package/src/manifest.ts +1709 -0
  69. package/src/media.ts +108 -0
  70. package/src/permissions.ts +60 -0
  71. package/src/recurring.ts +321 -0
  72. package/src/renamed.ts +63 -0
  73. package/src/rich-text-fixture.ts +68 -0
  74. package/src/rich-text.ts +221 -0
  75. package/src/runtime.ts +410 -0
  76. package/src/sellable.ts +888 -0
  77. package/src/slug.ts +25 -0
  78. package/src/states.ts +484 -0
  79. package/src/testing.ts +847 -0
  80. package/src/unique.ts +81 -0
  81. package/README.md +0 -3
@@ -0,0 +1,151 @@
1
+ import { type AutomationEvent, type AutomationTestStep, type NotificationSendInput } from "./automation.ts";
2
+ import { type AiModule, type Extension, type StartedBy } from "./contract.ts";
3
+ import type { ExtensionManifest, ManifestIssue, ValidateOptions } from "./manifest.ts";
4
+ type Values = Record<string, unknown> & {
5
+ id: string;
6
+ };
7
+ type OperationFake = (input: Record<string, unknown>) => unknown;
8
+ export interface TestHostOptions {
9
+ /** Seed records by object name (`organisation`, `example.project`). */
10
+ records?: Record<string, Values[]>;
11
+ /** Fakes for operations the harness does not implement, by name. */
12
+ operations?: Record<string, OperationFake>;
13
+ /** Fakes for the AI module. Default: deterministic stand-ins. */
14
+ ai?: Partial<AiModule>;
15
+ /** Passed to validateManifest. */
16
+ validate?: ValidateOptions;
17
+ /**
18
+ * Users `notification.send` resolves (`{ role: "admin" }`, `managerOf`). Default one admin,
19
+ * `usr_admin`.
20
+ */
21
+ users?: {
22
+ id: string;
23
+ role: "admin" | "member" | "viewer";
24
+ }[];
25
+ /**
26
+ * Fakes for the gatekeepers the extension declares in `permissions.modules`, by name: what a
27
+ * session method returns for `call(connectionId, resource, method, ...args)`. Every call is
28
+ * recorded in `gatekeeperCalls`. A declared gatekeeper with no fake answers `{ status: "pending" }`
29
+ * (a person would approve it), with one connection per declared automation connection.
30
+ */
31
+ gatekeepers?: Record<string, (call: {
32
+ connectionId: string;
33
+ resource: string;
34
+ method: string;
35
+ args: unknown[];
36
+ }) => unknown>;
37
+ }
38
+ /** A call a tool or automation made through `ctx.gatekeeper(name).call(...)`. */
39
+ export interface GatekeeperCall {
40
+ gatekeeper: string;
41
+ connectionId: string;
42
+ resource: string;
43
+ method: string;
44
+ args: unknown[];
45
+ /** The step it was made in (null: outside a step, or a tool). */
46
+ step: string | null;
47
+ }
48
+ /** A notification the in-memory `notification.send` delivered. */
49
+ export interface SentNotification extends Omit<NotificationSendInput, "type" | "dedupeKey"> {
50
+ type: string;
51
+ dedupeKey: string | null;
52
+ /** Resolved, deduplicated recipients. */
53
+ userIds: string[];
54
+ notes: string[];
55
+ /** The step that sent it (null: outside a step). */
56
+ step: string | null;
57
+ }
58
+ export interface AutomationRunOptions {
59
+ /** The trigger record, from the seeded `records`. */
60
+ record?: {
61
+ object: string;
62
+ id: string;
63
+ };
64
+ change?: AutomationEvent["change"];
65
+ period?: string;
66
+ manual?: AutomationEvent["manual"];
67
+ approval?: AutomationEvent["approval"];
68
+ /** waitForEvent payloads by step name. Default null (the wait timed out). */
69
+ events?: Record<string, unknown>;
70
+ runId?: string;
71
+ /** `event.test`. Default false: the run writes to the in-memory store. */
72
+ test?: boolean;
73
+ }
74
+ export interface AutomationRunResult {
75
+ /** False when the declared conditions did not match the trigger record (nothing ran). */
76
+ matched: boolean;
77
+ /** What `run` returned. */
78
+ value: unknown;
79
+ /** Set when `run` threw (a step failed, or an undeclared step name). */
80
+ error: {
81
+ code: string;
82
+ message: string;
83
+ } | null;
84
+ /** Every step in the order it ran; waits carry `skippedMs`. */
85
+ steps: (AutomationTestStep & {
86
+ calls: TestHost["calls"];
87
+ })[];
88
+ /** Record writes the run made (operation, object, the created or changed id). */
89
+ writes: {
90
+ step: string | null;
91
+ operation: string;
92
+ object: string | null;
93
+ id: string | null;
94
+ }[];
95
+ notifications: SentNotification[];
96
+ /** Effects no declaration covers, e.g. "step notifyOwner wrote task (not in its writes)". */
97
+ undeclared: string[];
98
+ }
99
+ /** Thrown into `run` when it uses a step name it did not declare (the host refuses it too). */
100
+ export declare class AutomationStepError extends Error {
101
+ name: string;
102
+ readonly code = "undeclared_step";
103
+ }
104
+ export declare class ExtensionToolError extends Error {
105
+ readonly code: string;
106
+ readonly details?: unknown | undefined;
107
+ name: string;
108
+ constructor(code: string, message: string, details?: unknown | undefined);
109
+ }
110
+ export interface TestHost {
111
+ manifest: ExtensionManifest;
112
+ /** Contract and formula issues (`extension.check` minus typecheck and dry-run reconcile). */
113
+ issues: ManifestIssue[];
114
+ /**
115
+ * Runs a tool like the host does: input and output validated, ctx from in-memory modules.
116
+ * `caller` is who started it (`ctx.caller`, ADR 0436); default the staff user `usr_admin`.
117
+ */
118
+ runTool<T = unknown>(tool: string, input: unknown, options?: {
119
+ caller?: StartedBy;
120
+ }): Promise<T>;
121
+ /** Every codemode:ops call, in order (allowed or refused). */
122
+ calls: {
123
+ operation: string;
124
+ input: unknown;
125
+ allowed: boolean;
126
+ }[];
127
+ logs: {
128
+ level: string;
129
+ message: string;
130
+ data: unknown;
131
+ }[];
132
+ storage: Map<string, unknown>;
133
+ records: Map<string, Map<string, Values>>;
134
+ /** Every notification sent through the in-memory `notification.send`. */
135
+ notifications: SentNotification[];
136
+ /** Every call through a gatekeeper module, in order. */
137
+ gatekeeperCalls: GatekeeperCall[];
138
+ /**
139
+ * Runs automation `name` in memory, start to finish: conditions checked on the trigger
140
+ * record, waits skipped (and recorded), steps held to the declarations.
141
+ */
142
+ runAutomation(name: string, options?: AutomationRunOptions): Promise<AutomationRunResult>;
143
+ /**
144
+ * Publishes a record of a publishable object as a person would (`record.publish`, which no
145
+ * tool may call): its content fields become the next version, which `record.version` reads.
146
+ * Returns the version's number.
147
+ */
148
+ publish(object: string, id: string): number;
149
+ }
150
+ export declare function createTestHost(extension: Extension, options?: TestHostOptions): TestHost;
151
+ export {};