@synapsor/spec 0.1.0

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 (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +125 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +67 -0
  6. package/dist/errors.d.ts +6 -0
  7. package/dist/errors.d.ts.map +1 -0
  8. package/dist/errors.js +8 -0
  9. package/dist/index.d.ts +7 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +5 -0
  12. package/dist/load.d.ts +3 -0
  13. package/dist/load.d.ts.map +1 -0
  14. package/dist/load.js +6 -0
  15. package/dist/normalize.d.ts +3 -0
  16. package/dist/normalize.d.ts.map +1 -0
  17. package/dist/normalize.js +16 -0
  18. package/dist/types.d.ts +196 -0
  19. package/dist/types.d.ts.map +1 -0
  20. package/dist/types.js +1 -0
  21. package/dist/validate.d.ts +4 -0
  22. package/dist/validate.d.ts.map +1 -0
  23. package/dist/validate.js +522 -0
  24. package/dist/version.d.ts +3 -0
  25. package/dist/version.d.ts.map +1 -0
  26. package/dist/version.js +2 -0
  27. package/examples/external-action.contract.json +114 -0
  28. package/examples/guarded-writeback.contract.json +171 -0
  29. package/examples/read-only-analytics.contract.json +94 -0
  30. package/examples/support-refund.contract.json +168 -0
  31. package/fixtures/conformance/kept-out-fields/contract.json +47 -0
  32. package/fixtures/conformance/kept-out-fields/expected.redaction.json +11 -0
  33. package/fixtures/conformance/kept-out-fields/scenario.json +9 -0
  34. package/fixtures/conformance/manual-approval/contract.json +66 -0
  35. package/fixtures/conformance/manual-approval/expected.proposal.json +9 -0
  36. package/fixtures/conformance/manual-approval/scenario.json +5 -0
  37. package/fixtures/conformance/proposal-capability/contract.json +101 -0
  38. package/fixtures/conformance/proposal-capability/expected.proposal.json +25 -0
  39. package/fixtures/conformance/proposal-capability/expected.replay.json +14 -0
  40. package/fixtures/conformance/proposal-capability/scenario.json +21 -0
  41. package/fixtures/conformance/read-capability/contract.json +73 -0
  42. package/fixtures/conformance/read-capability/expected.evidence.json +11 -0
  43. package/fixtures/conformance/read-capability/expected.replay.json +13 -0
  44. package/fixtures/conformance/read-capability/scenario.json +19 -0
  45. package/fixtures/invalid/kept-out-visible.contract.json +46 -0
  46. package/fixtures/invalid/model-controlled-tenant.contract.json +45 -0
  47. package/fixtures/valid/basic-read.contract.json +60 -0
  48. package/package.json +37 -0
  49. package/schemas/capability.schema.json +6 -0
  50. package/schemas/context.schema.json +6 -0
  51. package/schemas/envelope-v2.schema.json +20 -0
  52. package/schemas/evidence.schema.json +6 -0
  53. package/schemas/external-action.schema.json +6 -0
  54. package/schemas/policy.schema.json +6 -0
  55. package/schemas/proposal.schema.json +6 -0
  56. package/schemas/receipt.schema.json +6 -0
  57. package/schemas/replay.schema.json +6 -0
  58. package/schemas/synapsor-contract.schema.json +371 -0
  59. package/schemas/workflow.schema.json +6 -0
@@ -0,0 +1,371 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/synapsor-contract.schema.json",
4
+ "title": "Synapsor Contract",
5
+ "type": "object",
6
+ "required": ["spec_version", "kind", "contexts", "capabilities"],
7
+ "additionalProperties": false,
8
+ "patternProperties": {
9
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
10
+ },
11
+ "properties": {
12
+ "spec_version": { "const": "0.1" },
13
+ "kind": { "const": "SynapsorContract" },
14
+ "metadata": {
15
+ "type": "object",
16
+ "additionalProperties": false,
17
+ "patternProperties": {
18
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
19
+ },
20
+ "properties": {
21
+ "name": { "type": "string", "minLength": 1 },
22
+ "description": { "type": "string", "minLength": 1 },
23
+ "version": { "type": "string", "minLength": 1 },
24
+ "tags": { "type": "array", "items": { "type": "string", "minLength": 1 } }
25
+ }
26
+ },
27
+ "resources": {
28
+ "type": "array",
29
+ "items": { "$ref": "#/$defs/resource" }
30
+ },
31
+ "contexts": {
32
+ "type": "array",
33
+ "minItems": 1,
34
+ "items": { "$ref": "#/$defs/context" }
35
+ },
36
+ "capabilities": {
37
+ "type": "array",
38
+ "minItems": 1,
39
+ "items": { "$ref": "#/$defs/capability" }
40
+ },
41
+ "workflows": {
42
+ "type": "array",
43
+ "items": { "$ref": "#/$defs/workflow" }
44
+ },
45
+ "policies": {
46
+ "type": "array",
47
+ "items": { "$ref": "#/$defs/policy" }
48
+ },
49
+ "evidence": {
50
+ "type": "array",
51
+ "items": { "$ref": "#/$defs/evidenceRecord" }
52
+ },
53
+ "proposals": {
54
+ "type": "array",
55
+ "items": { "$ref": "#/$defs/proposalRecord" }
56
+ },
57
+ "receipts": {
58
+ "type": "array",
59
+ "items": { "$ref": "#/$defs/receipt" }
60
+ },
61
+ "replay": {
62
+ "type": "array",
63
+ "items": { "$ref": "#/$defs/replay" }
64
+ },
65
+ "external_actions": {
66
+ "type": "array",
67
+ "items": { "$ref": "#/$defs/externalAction" }
68
+ }
69
+ },
70
+ "$defs": {
71
+ "safeIdentifier": {
72
+ "type": "string",
73
+ "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
74
+ },
75
+ "qualifiedName": {
76
+ "type": "string",
77
+ "pattern": "^[A-Za-z_][A-Za-z0-9_]*\\.[A-Za-z_][A-Za-z0-9_]*$"
78
+ },
79
+ "qualifiedOrSafeName": {
80
+ "type": "string",
81
+ "pattern": "^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)?$"
82
+ },
83
+ "scalar": {
84
+ "type": ["string", "number", "boolean", "null"]
85
+ },
86
+ "extensionAware": {
87
+ "patternProperties": {
88
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
89
+ }
90
+ },
91
+ "resource": {
92
+ "type": "object",
93
+ "required": ["name", "engine", "schema", "table", "primary_key"],
94
+ "additionalProperties": false,
95
+ "patternProperties": {
96
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
97
+ },
98
+ "properties": {
99
+ "name": { "$ref": "#/$defs/qualifiedOrSafeName" },
100
+ "engine": { "enum": ["postgres", "mysql", "synapsor"] },
101
+ "schema": { "$ref": "#/$defs/safeIdentifier" },
102
+ "table": { "$ref": "#/$defs/safeIdentifier" },
103
+ "type": { "enum": ["table", "view", "external_source"] },
104
+ "primary_key": { "$ref": "#/$defs/safeIdentifier" },
105
+ "tenant_key": { "$ref": "#/$defs/safeIdentifier" },
106
+ "conflict_key": { "$ref": "#/$defs/safeIdentifier" },
107
+ "single_tenant_dev": { "type": "boolean" }
108
+ }
109
+ },
110
+ "binding": {
111
+ "type": "object",
112
+ "required": ["name", "source", "key"],
113
+ "additionalProperties": false,
114
+ "patternProperties": {
115
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
116
+ },
117
+ "properties": {
118
+ "name": { "$ref": "#/$defs/safeIdentifier" },
119
+ "source": { "enum": ["session", "environment", "cloud_session", "static_dev", "http_claim"] },
120
+ "key": { "type": "string", "minLength": 1 },
121
+ "required": { "type": "boolean" }
122
+ }
123
+ },
124
+ "context": {
125
+ "type": "object",
126
+ "required": ["name", "bindings"],
127
+ "additionalProperties": false,
128
+ "patternProperties": {
129
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
130
+ },
131
+ "properties": {
132
+ "name": { "$ref": "#/$defs/qualifiedOrSafeName" },
133
+ "description": { "type": "string" },
134
+ "bindings": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/binding" } },
135
+ "tenant_binding": { "$ref": "#/$defs/safeIdentifier" },
136
+ "principal_binding": { "$ref": "#/$defs/safeIdentifier" }
137
+ }
138
+ },
139
+ "arg": {
140
+ "type": "object",
141
+ "required": ["type"],
142
+ "additionalProperties": false,
143
+ "patternProperties": {
144
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
145
+ },
146
+ "properties": {
147
+ "type": { "enum": ["string", "number", "boolean"] },
148
+ "description": { "type": "string" },
149
+ "required": { "type": "boolean" },
150
+ "max_length": { "type": "integer", "minimum": 1 },
151
+ "minimum": { "type": "number" },
152
+ "maximum": { "type": "number" },
153
+ "enum": { "type": "array", "items": { "$ref": "#/$defs/scalar" } }
154
+ }
155
+ },
156
+ "subject": {
157
+ "type": "object",
158
+ "additionalProperties": false,
159
+ "patternProperties": {
160
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
161
+ },
162
+ "properties": {
163
+ "resource": { "$ref": "#/$defs/qualifiedOrSafeName" },
164
+ "schema": { "$ref": "#/$defs/safeIdentifier" },
165
+ "table": { "$ref": "#/$defs/safeIdentifier" },
166
+ "primary_key": { "$ref": "#/$defs/safeIdentifier" },
167
+ "tenant_key": { "$ref": "#/$defs/safeIdentifier" },
168
+ "conflict_key": { "$ref": "#/$defs/safeIdentifier" },
169
+ "single_tenant_dev": { "type": "boolean" }
170
+ }
171
+ },
172
+ "evidenceRequirement": {
173
+ "type": "object",
174
+ "required": ["required"],
175
+ "additionalProperties": false,
176
+ "patternProperties": {
177
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
178
+ },
179
+ "properties": {
180
+ "required": { "type": "boolean" },
181
+ "sources": { "type": "array", "items": { "type": "string", "minLength": 1 } },
182
+ "query_audit": { "type": "boolean" },
183
+ "handle_prefix": { "type": "string" }
184
+ }
185
+ },
186
+ "patchBinding": {
187
+ "type": "object",
188
+ "additionalProperties": false,
189
+ "patternProperties": {
190
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
191
+ },
192
+ "properties": {
193
+ "fixed": { "$ref": "#/$defs/scalar" },
194
+ "from_arg": { "$ref": "#/$defs/safeIdentifier" }
195
+ }
196
+ },
197
+ "proposalAction": {
198
+ "type": "object",
199
+ "required": ["action", "allowed_fields", "patch"],
200
+ "additionalProperties": false,
201
+ "patternProperties": {
202
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
203
+ },
204
+ "properties": {
205
+ "action": { "$ref": "#/$defs/qualifiedOrSafeName" },
206
+ "allowed_fields": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/safeIdentifier" } },
207
+ "patch": { "type": "object", "additionalProperties": { "$ref": "#/$defs/patchBinding" } },
208
+ "conflict_guard": {
209
+ "type": "object",
210
+ "additionalProperties": false,
211
+ "properties": {
212
+ "column": { "$ref": "#/$defs/safeIdentifier" },
213
+ "weak_guard_ack": { "type": "boolean" }
214
+ }
215
+ },
216
+ "approval": {
217
+ "type": "object",
218
+ "additionalProperties": false,
219
+ "properties": {
220
+ "mode": { "enum": ["human", "operator", "policy"] },
221
+ "required_role": { "type": "string" }
222
+ }
223
+ },
224
+ "writeback": {
225
+ "type": "object",
226
+ "required": ["mode"],
227
+ "additionalProperties": false,
228
+ "properties": {
229
+ "mode": { "enum": ["direct_sql", "app_handler", "cloud_worker", "none"] },
230
+ "executor": { "type": "string" },
231
+ "idempotency_key": { "type": "string" }
232
+ }
233
+ }
234
+ }
235
+ },
236
+ "capability": {
237
+ "type": "object",
238
+ "required": ["name", "kind", "context", "subject", "args", "visible_fields"],
239
+ "additionalProperties": false,
240
+ "patternProperties": {
241
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
242
+ },
243
+ "properties": {
244
+ "name": { "$ref": "#/$defs/qualifiedName" },
245
+ "description": { "type": "string" },
246
+ "kind": { "enum": ["read", "proposal", "external_action", "answer_with_evidence"] },
247
+ "context": { "$ref": "#/$defs/qualifiedOrSafeName" },
248
+ "source": { "$ref": "#/$defs/qualifiedOrSafeName" },
249
+ "subject": { "$ref": "#/$defs/subject" },
250
+ "args": { "type": "object", "additionalProperties": { "$ref": "#/$defs/arg" } },
251
+ "lookup": {
252
+ "type": "object",
253
+ "additionalProperties": false,
254
+ "properties": { "id_from_arg": { "$ref": "#/$defs/safeIdentifier" } }
255
+ },
256
+ "visible_fields": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/safeIdentifier" } },
257
+ "kept_out_fields": { "type": "array", "items": { "$ref": "#/$defs/safeIdentifier" } },
258
+ "evidence": { "$ref": "#/$defs/evidenceRequirement" },
259
+ "max_rows": { "type": "integer", "minimum": 1 },
260
+ "proposal": { "$ref": "#/$defs/proposalAction" }
261
+ }
262
+ },
263
+ "workflow": {
264
+ "type": "object",
265
+ "required": ["name", "context", "allowed_capabilities"],
266
+ "additionalProperties": false,
267
+ "patternProperties": {
268
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
269
+ },
270
+ "properties": {
271
+ "name": { "$ref": "#/$defs/qualifiedName" },
272
+ "description": { "type": "string" },
273
+ "context": { "$ref": "#/$defs/qualifiedOrSafeName" },
274
+ "allowed_capabilities": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/qualifiedName" } },
275
+ "required_evidence": { "type": "boolean" },
276
+ "approval": { "type": "object" },
277
+ "settlement": { "type": "object" },
278
+ "replay": { "type": "object" }
279
+ }
280
+ },
281
+ "policy": {
282
+ "type": "object",
283
+ "required": ["name", "kind"],
284
+ "additionalProperties": false,
285
+ "patternProperties": {
286
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
287
+ },
288
+ "properties": {
289
+ "name": { "$ref": "#/$defs/qualifiedOrSafeName" },
290
+ "kind": { "enum": ["approval", "settlement", "scope", "custom"] },
291
+ "mode": { "enum": ["green", "yellow", "red", "manual", "block"] },
292
+ "rules": { "type": "array", "items": { "type": "object" } }
293
+ }
294
+ },
295
+ "evidenceRecord": {
296
+ "type": "object",
297
+ "required": ["handle"],
298
+ "additionalProperties": false,
299
+ "patternProperties": {
300
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
301
+ },
302
+ "properties": {
303
+ "handle": { "type": "string" },
304
+ "capability": { "$ref": "#/$defs/qualifiedName" },
305
+ "query_fingerprint": { "type": "string" },
306
+ "items": { "type": "array", "items": { "type": "object" } }
307
+ }
308
+ },
309
+ "proposalRecord": {
310
+ "type": "object",
311
+ "required": ["id", "capability", "subject", "status"],
312
+ "additionalProperties": false,
313
+ "patternProperties": {
314
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
315
+ },
316
+ "properties": {
317
+ "id": { "type": "string" },
318
+ "capability": { "$ref": "#/$defs/qualifiedName" },
319
+ "subject": { "type": "object" },
320
+ "status": { "enum": ["pending", "approved", "rejected", "canceled", "applied", "conflict", "failed"] },
321
+ "diff": { "type": "object" },
322
+ "evidence_handle": { "type": "string" }
323
+ }
324
+ },
325
+ "receipt": {
326
+ "type": "object",
327
+ "required": ["id", "proposal_id", "status", "source_database_mutated"],
328
+ "additionalProperties": false,
329
+ "patternProperties": {
330
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
331
+ },
332
+ "properties": {
333
+ "id": { "type": "string" },
334
+ "proposal_id": { "type": "string" },
335
+ "status": { "enum": ["applied", "already_applied", "conflict", "failed", "canceled"] },
336
+ "idempotency_key": { "type": "string" },
337
+ "source_database_mutated": { "type": "boolean" },
338
+ "rows_affected": { "type": "integer", "minimum": 0 }
339
+ }
340
+ },
341
+ "replay": {
342
+ "type": "object",
343
+ "required": ["id", "events"],
344
+ "additionalProperties": false,
345
+ "patternProperties": {
346
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
347
+ },
348
+ "properties": {
349
+ "id": { "type": "string" },
350
+ "proposal_id": { "type": "string" },
351
+ "run_id": { "type": "string" },
352
+ "events": { "type": "array", "items": { "type": "object" } }
353
+ }
354
+ },
355
+ "externalAction": {
356
+ "type": "object",
357
+ "required": ["id", "action"],
358
+ "additionalProperties": false,
359
+ "patternProperties": {
360
+ "^x-(cloud|runner|experimental)-[A-Za-z0-9_.-]+$": true
361
+ },
362
+ "properties": {
363
+ "id": { "type": "string" },
364
+ "action": { "$ref": "#/$defs/qualifiedOrSafeName" },
365
+ "handler": { "type": "string" },
366
+ "idempotency_key": { "type": "string" },
367
+ "receipt": { "type": "string" }
368
+ }
369
+ }
370
+ }
371
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://schemas.synapsor.ai/workflow.schema.json",
4
+ "title": "Synapsor Workflow",
5
+ "$ref": "synapsor-contract.schema.json#/$defs/workflow"
6
+ }