@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,114 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "metadata": {
5
+ "name": "support external action intent",
6
+ "description": "Create an app-owned action intent without model-facing commit authority.",
7
+ "version": "0.1.0"
8
+ },
9
+ "resources": [
10
+ {
11
+ "name": "support_tickets",
12
+ "engine": "postgres",
13
+ "schema": "public",
14
+ "table": "tickets",
15
+ "type": "table",
16
+ "primary_key": "id",
17
+ "tenant_key": "tenant_id",
18
+ "conflict_key": "updated_at"
19
+ }
20
+ ],
21
+ "contexts": [
22
+ {
23
+ "name": "support_operator",
24
+ "bindings": [
25
+ {
26
+ "name": "tenant_id",
27
+ "source": "environment",
28
+ "key": "SYNAPSOR_TENANT_ID",
29
+ "required": true
30
+ },
31
+ {
32
+ "name": "principal",
33
+ "source": "environment",
34
+ "key": "SYNAPSOR_PRINCIPAL",
35
+ "required": true
36
+ }
37
+ ],
38
+ "tenant_binding": "tenant_id",
39
+ "principal_binding": "principal"
40
+ }
41
+ ],
42
+ "capabilities": [
43
+ {
44
+ "name": "support.propose_ticket_reply",
45
+ "kind": "proposal",
46
+ "context": "support_operator",
47
+ "source": "support_postgres",
48
+ "subject": {
49
+ "resource": "support_tickets"
50
+ },
51
+ "args": {
52
+ "ticket_id": {
53
+ "type": "string",
54
+ "required": true,
55
+ "max_length": 128
56
+ },
57
+ "reply_body": {
58
+ "type": "string",
59
+ "required": true,
60
+ "max_length": 2000
61
+ }
62
+ },
63
+ "lookup": {
64
+ "id_from_arg": "ticket_id"
65
+ },
66
+ "visible_fields": [
67
+ "id",
68
+ "tenant_id",
69
+ "customer_id",
70
+ "status",
71
+ "subject",
72
+ "updated_at"
73
+ ],
74
+ "kept_out_fields": [
75
+ "private_staff_notes"
76
+ ],
77
+ "evidence": {
78
+ "required": true,
79
+ "query_audit": true
80
+ },
81
+ "max_rows": 1,
82
+ "proposal": {
83
+ "action": "support.create_ticket_reply",
84
+ "allowed_fields": [
85
+ "reply_body"
86
+ ],
87
+ "patch": {
88
+ "reply_body": {
89
+ "from_arg": "reply_body"
90
+ }
91
+ },
92
+ "conflict_guard": {
93
+ "column": "updated_at"
94
+ },
95
+ "approval": {
96
+ "mode": "human",
97
+ "required_role": "support_lead"
98
+ },
99
+ "writeback": {
100
+ "mode": "app_handler",
101
+ "executor": "support_reply_handler"
102
+ }
103
+ }
104
+ }
105
+ ],
106
+ "external_actions": [
107
+ {
108
+ "id": "intent_ticket_reply",
109
+ "action": "support.create_ticket_reply",
110
+ "handler": "support_reply_handler",
111
+ "idempotency_key": "proposal_id"
112
+ }
113
+ ]
114
+ }
@@ -0,0 +1,171 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "metadata": {
5
+ "name": "billing guarded invoice writeback",
6
+ "description": "Read one invoice and create a review-required late-fee waiver proposal.",
7
+ "version": "0.1.0"
8
+ },
9
+ "resources": [
10
+ {
11
+ "name": "billing_invoices",
12
+ "engine": "postgres",
13
+ "schema": "public",
14
+ "table": "invoices",
15
+ "type": "table",
16
+ "primary_key": "id",
17
+ "tenant_key": "tenant_id",
18
+ "conflict_key": "updated_at"
19
+ }
20
+ ],
21
+ "contexts": [
22
+ {
23
+ "name": "local_operator",
24
+ "bindings": [
25
+ {
26
+ "name": "tenant_id",
27
+ "source": "environment",
28
+ "key": "SYNAPSOR_TENANT_ID",
29
+ "required": true
30
+ },
31
+ {
32
+ "name": "principal",
33
+ "source": "environment",
34
+ "key": "SYNAPSOR_PRINCIPAL",
35
+ "required": true
36
+ }
37
+ ],
38
+ "tenant_binding": "tenant_id",
39
+ "principal_binding": "principal"
40
+ }
41
+ ],
42
+ "capabilities": [
43
+ {
44
+ "name": "billing.inspect_invoice",
45
+ "kind": "read",
46
+ "context": "local_operator",
47
+ "source": "local_postgres",
48
+ "subject": {
49
+ "resource": "billing_invoices"
50
+ },
51
+ "args": {
52
+ "invoice_id": {
53
+ "type": "string",
54
+ "required": true,
55
+ "max_length": 128
56
+ }
57
+ },
58
+ "lookup": {
59
+ "id_from_arg": "invoice_id"
60
+ },
61
+ "visible_fields": [
62
+ "id",
63
+ "tenant_id",
64
+ "customer_id",
65
+ "status",
66
+ "balance_cents",
67
+ "late_fee_cents",
68
+ "waiver_reason",
69
+ "updated_at"
70
+ ],
71
+ "kept_out_fields": [
72
+ "internal_risk_score",
73
+ "card_token"
74
+ ],
75
+ "evidence": {
76
+ "required": true,
77
+ "query_audit": true
78
+ },
79
+ "max_rows": 1
80
+ },
81
+ {
82
+ "name": "billing.propose_late_fee_waiver",
83
+ "kind": "proposal",
84
+ "context": "local_operator",
85
+ "source": "local_postgres",
86
+ "subject": {
87
+ "resource": "billing_invoices"
88
+ },
89
+ "args": {
90
+ "invoice_id": {
91
+ "type": "string",
92
+ "required": true,
93
+ "max_length": 128
94
+ },
95
+ "waiver_reason": {
96
+ "type": "string",
97
+ "required": true,
98
+ "max_length": 500
99
+ }
100
+ },
101
+ "lookup": {
102
+ "id_from_arg": "invoice_id"
103
+ },
104
+ "visible_fields": [
105
+ "id",
106
+ "tenant_id",
107
+ "customer_id",
108
+ "status",
109
+ "balance_cents",
110
+ "late_fee_cents",
111
+ "waiver_reason",
112
+ "updated_at"
113
+ ],
114
+ "kept_out_fields": [
115
+ "internal_risk_score",
116
+ "card_token"
117
+ ],
118
+ "evidence": {
119
+ "required": true,
120
+ "query_audit": true
121
+ },
122
+ "max_rows": 1,
123
+ "proposal": {
124
+ "action": "billing.waive_late_fee",
125
+ "allowed_fields": [
126
+ "late_fee_cents",
127
+ "waiver_reason"
128
+ ],
129
+ "patch": {
130
+ "late_fee_cents": {
131
+ "fixed": 0
132
+ },
133
+ "waiver_reason": {
134
+ "from_arg": "waiver_reason"
135
+ }
136
+ },
137
+ "conflict_guard": {
138
+ "column": "updated_at"
139
+ },
140
+ "approval": {
141
+ "mode": "human",
142
+ "required_role": "billing_lead"
143
+ },
144
+ "writeback": {
145
+ "mode": "direct_sql"
146
+ }
147
+ }
148
+ }
149
+ ],
150
+ "workflows": [
151
+ {
152
+ "name": "billing.late_fee_review",
153
+ "context": "local_operator",
154
+ "allowed_capabilities": [
155
+ "billing.inspect_invoice",
156
+ "billing.propose_late_fee_waiver"
157
+ ],
158
+ "required_evidence": true,
159
+ "approval": {
160
+ "required": true,
161
+ "role": "billing_lead"
162
+ },
163
+ "settlement": {
164
+ "mode": "manual"
165
+ },
166
+ "replay": {
167
+ "checkpoint": "proposal_only"
168
+ }
169
+ }
170
+ ]
171
+ }
@@ -0,0 +1,94 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "metadata": {
5
+ "name": "read only customer analytics",
6
+ "description": "Expose scoped customer reads without model-facing SQL.",
7
+ "version": "0.1.0"
8
+ },
9
+ "resources": [
10
+ {
11
+ "name": "analytics_customers",
12
+ "engine": "mysql",
13
+ "schema": "app",
14
+ "table": "customers",
15
+ "type": "view",
16
+ "primary_key": "id",
17
+ "tenant_key": "tenant_id",
18
+ "conflict_key": "updated_at"
19
+ }
20
+ ],
21
+ "contexts": [
22
+ {
23
+ "name": "tenant_session",
24
+ "bindings": [
25
+ {
26
+ "name": "tenant_id",
27
+ "source": "session",
28
+ "key": "tenant_id",
29
+ "required": true
30
+ },
31
+ {
32
+ "name": "principal",
33
+ "source": "session",
34
+ "key": "principal",
35
+ "required": true
36
+ }
37
+ ],
38
+ "tenant_binding": "tenant_id",
39
+ "principal_binding": "principal"
40
+ }
41
+ ],
42
+ "capabilities": [
43
+ {
44
+ "name": "analytics.inspect_customer",
45
+ "kind": "read",
46
+ "context": "tenant_session",
47
+ "source": "analytics_mysql",
48
+ "subject": {
49
+ "resource": "analytics_customers"
50
+ },
51
+ "args": {
52
+ "customer_id": {
53
+ "type": "string",
54
+ "required": true,
55
+ "max_length": 128
56
+ }
57
+ },
58
+ "lookup": {
59
+ "id_from_arg": "customer_id"
60
+ },
61
+ "visible_fields": [
62
+ "id",
63
+ "tenant_id",
64
+ "name",
65
+ "plan",
66
+ "created_at",
67
+ "updated_at"
68
+ ],
69
+ "kept_out_fields": [
70
+ "email",
71
+ "phone",
72
+ "billing_notes"
73
+ ],
74
+ "evidence": {
75
+ "required": true,
76
+ "query_audit": true
77
+ },
78
+ "max_rows": 1
79
+ }
80
+ ],
81
+ "workflows": [
82
+ {
83
+ "name": "analytics.customer_lookup",
84
+ "context": "tenant_session",
85
+ "allowed_capabilities": [
86
+ "analytics.inspect_customer"
87
+ ],
88
+ "required_evidence": true,
89
+ "replay": {
90
+ "checkpoint": "every_step"
91
+ }
92
+ }
93
+ ]
94
+ }
@@ -0,0 +1,168 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "metadata": {
5
+ "name": "support refund request",
6
+ "description": "Support workflow with read evidence and a review-required refund proposal.",
7
+ "version": "0.1.0"
8
+ },
9
+ "resources": [
10
+ {
11
+ "name": "support_orders",
12
+ "engine": "postgres",
13
+ "schema": "public",
14
+ "table": "orders",
15
+ "type": "table",
16
+ "primary_key": "id",
17
+ "tenant_key": "tenant_id",
18
+ "conflict_key": "updated_at"
19
+ }
20
+ ],
21
+ "contexts": [
22
+ {
23
+ "name": "support_agent_context",
24
+ "bindings": [
25
+ {
26
+ "name": "tenant_id",
27
+ "source": "session",
28
+ "key": "tenant_id",
29
+ "required": true
30
+ },
31
+ {
32
+ "name": "principal",
33
+ "source": "session",
34
+ "key": "principal",
35
+ "required": true
36
+ }
37
+ ],
38
+ "tenant_binding": "tenant_id",
39
+ "principal_binding": "principal"
40
+ }
41
+ ],
42
+ "capabilities": [
43
+ {
44
+ "name": "support.inspect_order",
45
+ "kind": "read",
46
+ "context": "support_agent_context",
47
+ "source": "support_postgres",
48
+ "subject": {
49
+ "resource": "support_orders"
50
+ },
51
+ "args": {
52
+ "order_id": {
53
+ "type": "string",
54
+ "required": true,
55
+ "max_length": 128
56
+ }
57
+ },
58
+ "lookup": {
59
+ "id_from_arg": "order_id"
60
+ },
61
+ "visible_fields": [
62
+ "id",
63
+ "tenant_id",
64
+ "customer_id",
65
+ "status",
66
+ "amount_cents",
67
+ "updated_at"
68
+ ],
69
+ "kept_out_fields": [
70
+ "payment_token",
71
+ "internal_fraud_score"
72
+ ],
73
+ "evidence": {
74
+ "required": true,
75
+ "query_audit": true
76
+ },
77
+ "max_rows": 1
78
+ },
79
+ {
80
+ "name": "support.propose_refund_review",
81
+ "kind": "proposal",
82
+ "context": "support_agent_context",
83
+ "source": "support_postgres",
84
+ "subject": {
85
+ "resource": "support_orders"
86
+ },
87
+ "args": {
88
+ "order_id": {
89
+ "type": "string",
90
+ "required": true,
91
+ "max_length": 128
92
+ },
93
+ "refund_note": {
94
+ "type": "string",
95
+ "required": true,
96
+ "max_length": 500
97
+ }
98
+ },
99
+ "lookup": {
100
+ "id_from_arg": "order_id"
101
+ },
102
+ "visible_fields": [
103
+ "id",
104
+ "tenant_id",
105
+ "customer_id",
106
+ "status",
107
+ "amount_cents",
108
+ "refund_note",
109
+ "updated_at"
110
+ ],
111
+ "kept_out_fields": [
112
+ "payment_token",
113
+ "internal_fraud_score"
114
+ ],
115
+ "evidence": {
116
+ "required": true,
117
+ "query_audit": true
118
+ },
119
+ "max_rows": 1,
120
+ "proposal": {
121
+ "action": "support.mark_refund_for_review",
122
+ "allowed_fields": [
123
+ "status",
124
+ "refund_note"
125
+ ],
126
+ "patch": {
127
+ "status": {
128
+ "fixed": "refund_review"
129
+ },
130
+ "refund_note": {
131
+ "from_arg": "refund_note"
132
+ }
133
+ },
134
+ "conflict_guard": {
135
+ "column": "updated_at"
136
+ },
137
+ "approval": {
138
+ "mode": "human",
139
+ "required_role": "support_lead"
140
+ },
141
+ "writeback": {
142
+ "mode": "direct_sql"
143
+ }
144
+ }
145
+ }
146
+ ],
147
+ "workflows": [
148
+ {
149
+ "name": "support.refund_request",
150
+ "context": "support_agent_context",
151
+ "allowed_capabilities": [
152
+ "support.inspect_order",
153
+ "support.propose_refund_review"
154
+ ],
155
+ "required_evidence": true,
156
+ "approval": {
157
+ "required": true,
158
+ "role": "support_lead"
159
+ },
160
+ "settlement": {
161
+ "mode": "manual"
162
+ },
163
+ "replay": {
164
+ "checkpoint": "proposal_only"
165
+ }
166
+ }
167
+ ]
168
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "contexts": [
5
+ {
6
+ "name": "local_operator",
7
+ "bindings": [
8
+ {
9
+ "name": "tenant_id",
10
+ "source": "environment",
11
+ "key": "SYNAPSOR_TENANT_ID"
12
+ }
13
+ ],
14
+ "tenant_binding": "tenant_id"
15
+ }
16
+ ],
17
+ "capabilities": [
18
+ {
19
+ "name": "billing.inspect_invoice",
20
+ "kind": "read",
21
+ "context": "local_operator",
22
+ "subject": {
23
+ "schema": "public",
24
+ "table": "invoices",
25
+ "primary_key": "id",
26
+ "tenant_key": "tenant_id"
27
+ },
28
+ "args": {
29
+ "invoice_id": {
30
+ "type": "string"
31
+ }
32
+ },
33
+ "lookup": {
34
+ "id_from_arg": "invoice_id"
35
+ },
36
+ "visible_fields": [
37
+ "id",
38
+ "tenant_id",
39
+ "late_fee_cents"
40
+ ],
41
+ "kept_out_fields": [
42
+ "card_token",
43
+ "internal_risk_score"
44
+ ]
45
+ }
46
+ ]
47
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "visible": {
3
+ "id": "INV-3001",
4
+ "tenant_id": "acme",
5
+ "late_fee_cents": 5500
6
+ },
7
+ "redacted_fields": [
8
+ "card_token",
9
+ "internal_risk_score"
10
+ ]
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "source_row": {
3
+ "id": "INV-3001",
4
+ "tenant_id": "acme",
5
+ "late_fee_cents": 5500,
6
+ "card_token": "tok_should_not_leak",
7
+ "internal_risk_score": 91
8
+ }
9
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "spec_version": "0.1",
3
+ "kind": "SynapsorContract",
4
+ "contexts": [
5
+ {
6
+ "name": "local_operator",
7
+ "bindings": [
8
+ {
9
+ "name": "tenant_id",
10
+ "source": "environment",
11
+ "key": "SYNAPSOR_TENANT_ID"
12
+ }
13
+ ],
14
+ "tenant_binding": "tenant_id"
15
+ }
16
+ ],
17
+ "capabilities": [
18
+ {
19
+ "name": "billing.propose_late_fee_waiver",
20
+ "kind": "proposal",
21
+ "context": "local_operator",
22
+ "subject": {
23
+ "schema": "public",
24
+ "table": "invoices",
25
+ "primary_key": "id",
26
+ "tenant_key": "tenant_id",
27
+ "conflict_key": "updated_at"
28
+ },
29
+ "args": {
30
+ "invoice_id": {
31
+ "type": "string"
32
+ }
33
+ },
34
+ "lookup": {
35
+ "id_from_arg": "invoice_id"
36
+ },
37
+ "visible_fields": [
38
+ "id",
39
+ "tenant_id",
40
+ "late_fee_cents",
41
+ "updated_at"
42
+ ],
43
+ "proposal": {
44
+ "action": "billing.waive_late_fee",
45
+ "allowed_fields": [
46
+ "late_fee_cents"
47
+ ],
48
+ "patch": {
49
+ "late_fee_cents": {
50
+ "fixed": 0
51
+ }
52
+ },
53
+ "conflict_guard": {
54
+ "column": "updated_at"
55
+ },
56
+ "approval": {
57
+ "mode": "human",
58
+ "required_role": "billing_lead"
59
+ },
60
+ "writeback": {
61
+ "mode": "direct_sql"
62
+ }
63
+ }
64
+ }
65
+ ]
66
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "wrp_INV_3001_late_fee_waiver",
3
+ "capability": "billing.propose_late_fee_waiver",
4
+ "subject": {
5
+ "id": "INV-3001",
6
+ "tenant_id": "acme"
7
+ },
8
+ "status": "approved"
9
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "proposal_id": "wrp_INV_3001_late_fee_waiver",
3
+ "operator": "billing_lead@example.com",
4
+ "decision": "approved"
5
+ }