business-as-code 2.3.0 → 2.4.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.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +43 -0
- package/dist/business.d.ts +62 -0
- package/dist/business.d.ts.map +1 -0
- package/dist/business.js +109 -0
- package/dist/business.js.map +1 -0
- package/dist/dollar.d.ts +60 -0
- package/dist/dollar.d.ts.map +1 -0
- package/dist/dollar.js +107 -0
- package/dist/dollar.js.map +1 -0
- package/dist/entities/assets.d.ts +21 -0
- package/dist/entities/assets.d.ts.map +1 -0
- package/dist/entities/assets.js +323 -0
- package/dist/entities/assets.js.map +1 -0
- package/dist/entities/business.d.ts +36 -0
- package/dist/entities/business.d.ts.map +1 -0
- package/dist/entities/business.js +370 -0
- package/dist/entities/business.js.map +1 -0
- package/dist/entities/communication.d.ts +21 -0
- package/dist/entities/communication.d.ts.map +1 -0
- package/dist/entities/communication.js +255 -0
- package/dist/entities/communication.js.map +1 -0
- package/dist/entities/customers.d.ts +58 -0
- package/dist/entities/customers.d.ts.map +1 -0
- package/dist/entities/customers.js +989 -0
- package/dist/entities/customers.js.map +1 -0
- package/dist/entities/financials.d.ts +59 -0
- package/dist/entities/financials.d.ts.map +1 -0
- package/dist/entities/financials.js +932 -0
- package/dist/entities/financials.js.map +1 -0
- package/dist/entities/goals.d.ts +58 -0
- package/dist/entities/goals.d.ts.map +1 -0
- package/dist/entities/goals.js +800 -0
- package/dist/entities/goals.js.map +1 -0
- package/dist/entities/index.d.ts +299 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +198 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/legal.d.ts +21 -0
- package/dist/entities/legal.d.ts.map +1 -0
- package/dist/entities/legal.js +301 -0
- package/dist/entities/legal.js.map +1 -0
- package/dist/entities/market.d.ts +21 -0
- package/dist/entities/market.d.ts.map +1 -0
- package/dist/entities/market.js +301 -0
- package/dist/entities/market.js.map +1 -0
- package/dist/entities/marketing.d.ts +67 -0
- package/dist/entities/marketing.d.ts.map +1 -0
- package/dist/entities/marketing.js +1157 -0
- package/dist/entities/marketing.js.map +1 -0
- package/dist/entities/offerings.d.ts +51 -0
- package/dist/entities/offerings.d.ts.map +1 -0
- package/dist/entities/offerings.js +727 -0
- package/dist/entities/offerings.js.map +1 -0
- package/dist/entities/operations.d.ts +58 -0
- package/dist/entities/operations.d.ts.map +1 -0
- package/dist/entities/operations.js +787 -0
- package/dist/entities/operations.js.map +1 -0
- package/dist/entities/organization.d.ts +61 -0
- package/dist/entities/organization.d.ts.map +1 -0
- package/dist/entities/organization.js +816 -0
- package/dist/entities/organization.js.map +1 -0
- package/dist/entities/partnerships.d.ts +21 -0
- package/dist/entities/partnerships.d.ts.map +1 -0
- package/dist/entities/partnerships.js +300 -0
- package/dist/entities/partnerships.js.map +1 -0
- package/dist/entities/planning.d.ts +87 -0
- package/dist/entities/planning.d.ts.map +1 -0
- package/dist/entities/planning.js +271 -0
- package/dist/entities/planning.js.map +1 -0
- package/dist/entities/projects.d.ts +25 -0
- package/dist/entities/projects.d.ts.map +1 -0
- package/dist/entities/projects.js +349 -0
- package/dist/entities/projects.js.map +1 -0
- package/dist/entities/risk.d.ts +21 -0
- package/dist/entities/risk.d.ts.map +1 -0
- package/dist/entities/risk.js +293 -0
- package/dist/entities/risk.js.map +1 -0
- package/dist/entities/sales.d.ts +72 -0
- package/dist/entities/sales.d.ts.map +1 -0
- package/dist/entities/sales.js +1248 -0
- package/dist/entities/sales.js.map +1 -0
- package/dist/finance/account.d.ts +44 -0
- package/dist/finance/account.d.ts.map +1 -0
- package/dist/finance/account.js +6 -0
- package/dist/finance/account.js.map +1 -0
- package/dist/finance/authority.d.ts +78 -0
- package/dist/finance/authority.d.ts.map +1 -0
- package/dist/finance/authority.js +27 -0
- package/dist/finance/authority.js.map +1 -0
- package/dist/finance/card.d.ts +36 -0
- package/dist/finance/card.d.ts.map +1 -0
- package/dist/finance/card.js +6 -0
- package/dist/finance/card.js.map +1 -0
- package/dist/finance/identity.d.ts +30 -0
- package/dist/finance/identity.d.ts.map +1 -0
- package/dist/finance/identity.js +8 -0
- package/dist/finance/identity.js.map +1 -0
- package/dist/finance/index.d.ts +36 -0
- package/dist/finance/index.d.ts.map +1 -0
- package/dist/finance/index.js +22 -0
- package/dist/finance/index.js.map +1 -0
- package/dist/finance/ledger.d.ts +24 -0
- package/dist/finance/ledger.d.ts.map +1 -0
- package/dist/finance/ledger.js +8 -0
- package/dist/finance/ledger.js.map +1 -0
- package/dist/finance/merchant.d.ts +129 -0
- package/dist/finance/merchant.d.ts.map +1 -0
- package/dist/finance/merchant.js +21 -0
- package/dist/finance/merchant.js.map +1 -0
- package/dist/finance/outcome-contract.d.ts +139 -0
- package/dist/finance/outcome-contract.d.ts.map +1 -0
- package/dist/finance/outcome-contract.js +27 -0
- package/dist/finance/outcome-contract.js.map +1 -0
- package/dist/finance/port.d.ts +121 -0
- package/dist/finance/port.d.ts.map +1 -0
- package/dist/finance/port.js +10 -0
- package/dist/finance/port.js.map +1 -0
- package/dist/finance/pricing.d.ts +154 -0
- package/dist/finance/pricing.d.ts.map +1 -0
- package/dist/finance/pricing.js +79 -0
- package/dist/finance/pricing.js.map +1 -0
- package/dist/finance/proof-predicate.d.ts +92 -0
- package/dist/finance/proof-predicate.d.ts.map +1 -0
- package/dist/finance/proof-predicate.js +80 -0
- package/dist/finance/proof-predicate.js.map +1 -0
- package/dist/finance/refund.d.ts +44 -0
- package/dist/finance/refund.d.ts.map +1 -0
- package/dist/finance/refund.js +41 -0
- package/dist/finance/refund.js.map +1 -0
- package/dist/finance/sla.d.ts +25 -0
- package/dist/finance/sla.d.ts.map +1 -0
- package/dist/finance/sla.js +7 -0
- package/dist/finance/sla.js.map +1 -0
- package/dist/finance/types.d.ts +79 -0
- package/dist/finance/types.d.ts.map +1 -0
- package/dist/finance/types.js +8 -0
- package/dist/finance/types.js.map +1 -0
- package/dist/financials.d.ts +130 -0
- package/dist/financials.d.ts.map +1 -0
- package/dist/financials.js +297 -0
- package/dist/financials.js.map +1 -0
- package/dist/goals.d.ts +106 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +284 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +101 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/dist/kpis.d.ts +137 -0
- package/dist/kpis.d.ts.map +1 -0
- package/dist/kpis.js +297 -0
- package/dist/kpis.js.map +1 -0
- package/dist/metrics.d.ts +448 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +330 -0
- package/dist/metrics.js.map +1 -0
- package/dist/okrs.d.ts +157 -0
- package/dist/okrs.d.ts.map +1 -0
- package/dist/okrs.js +391 -0
- package/dist/okrs.js.map +1 -0
- package/dist/organization.d.ts +585 -0
- package/dist/organization.d.ts.map +1 -0
- package/dist/organization.js +173 -0
- package/dist/organization.js.map +1 -0
- package/dist/process.d.ts +112 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +242 -0
- package/dist/process.js.map +1 -0
- package/dist/product.d.ts +85 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +145 -0
- package/dist/product.js.map +1 -0
- package/dist/queries.d.ts +304 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +577 -0
- package/dist/queries.js.map +1 -0
- package/dist/roles.d.ts +334 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +282 -0
- package/dist/roles.js.map +1 -0
- package/dist/service.d.ts +61 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +140 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +459 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/vision.d.ts +38 -0
- package/dist/vision.d.ts.map +1 -0
- package/dist/vision.js +68 -0
- package/dist/vision.js.map +1 -0
- package/dist/workflow.d.ts +115 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +248 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +8 -4
- package/src/finance/account.ts +48 -0
- package/src/finance/authority.ts +42 -0
- package/src/finance/card.ts +38 -0
- package/src/finance/identity.ts +31 -0
- package/src/finance/index.ts +117 -0
- package/src/finance/ledger.ts +26 -0
- package/src/finance/merchant.ts +127 -0
- package/src/finance/outcome-contract.ts +157 -0
- package/src/finance/port.ts +144 -0
- package/src/finance/pricing.ts +197 -0
- package/src/finance/proof-predicate.ts +106 -0
- package/src/finance/refund.ts +52 -0
- package/src/finance/sla.ts +33 -0
- package/src/finance/types.ts +75 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OutcomeContract — definition-of-done + escrow + release condition.
|
|
3
|
+
* Distinct from OutputContract (technical schema; lives in services-as-software).
|
|
4
|
+
*
|
|
5
|
+
* The predicate is evaluated against the runtime state of a Service invocation;
|
|
6
|
+
* when it passes, escrow releases funds to the seller.
|
|
7
|
+
*/
|
|
8
|
+
import type { OutcomeTier } from './pricing.js';
|
|
9
|
+
import type { Money } from './types.js';
|
|
10
|
+
import type { ProofPredicate } from './proof-predicate.js';
|
|
11
|
+
/**
|
|
12
|
+
* Fields shared by all {@link OutcomeContract} variants.
|
|
13
|
+
*
|
|
14
|
+
* Split from the timeout + amount fields so the discriminated union below can
|
|
15
|
+
* express "exactly one of `expiresAt` / `timeoutDays`" AND "exactly one of
|
|
16
|
+
* `amount` / `tiers`" at the type level.
|
|
17
|
+
*/
|
|
18
|
+
export interface OutcomeContractBase {
|
|
19
|
+
$id: string;
|
|
20
|
+
$type: 'OutcomeContract';
|
|
21
|
+
/** Worker (Person/Agent/Role) that bought the outcome. */
|
|
22
|
+
buyer: string;
|
|
23
|
+
/** Worker (Person/Agent/Role) that sold/delivers the outcome. */
|
|
24
|
+
seller: string;
|
|
25
|
+
/** Service this contract is bound to. */
|
|
26
|
+
serviceRef: string;
|
|
27
|
+
predicate: ProofPredicate;
|
|
28
|
+
/** Account holding escrowed funds until predicate passes. */
|
|
29
|
+
escrowAccountRef?: string;
|
|
30
|
+
onTimeout?: 'auto-cancel' | 'auto-refund' | 'escalate';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Variant carrying an absolute ISO-8601 *timestamp* (e.g.
|
|
34
|
+
* `'2026-05-12T00:00:00Z'`). The runtime treats this as the wall-clock
|
|
35
|
+
* deadline. Carries a single {@link Money} `amount`.
|
|
36
|
+
*/
|
|
37
|
+
export interface OutcomeContractWithExpiresAt extends OutcomeContractBase {
|
|
38
|
+
/**
|
|
39
|
+
* Absolute ISO-8601 timestamp — the contract expires (and `onTimeout` fires)
|
|
40
|
+
* exactly at this instant. For relative durations from contract creation,
|
|
41
|
+
* use {@link OutcomeContractWithTimeoutDays.timeoutDays} instead.
|
|
42
|
+
*/
|
|
43
|
+
expiresAt: string;
|
|
44
|
+
timeoutDays?: never;
|
|
45
|
+
amount: Money;
|
|
46
|
+
tiers?: never;
|
|
47
|
+
selectedTierId?: never;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Variant carrying a relative-duration deadline measured in whole days from
|
|
51
|
+
* contract creation. The runtime computes
|
|
52
|
+
* `expiresAt = createdAt + timeoutDays * 24h`. Carries a single {@link Money}
|
|
53
|
+
* `amount`.
|
|
54
|
+
*/
|
|
55
|
+
export interface OutcomeContractWithTimeoutDays extends OutcomeContractBase {
|
|
56
|
+
/**
|
|
57
|
+
* Whole days from contract creation until expiry. Mutually exclusive with
|
|
58
|
+
* {@link OutcomeContractWithExpiresAt.expiresAt}.
|
|
59
|
+
*/
|
|
60
|
+
timeoutDays: number;
|
|
61
|
+
expiresAt?: never;
|
|
62
|
+
amount: Money;
|
|
63
|
+
tiers?: never;
|
|
64
|
+
selectedTierId?: never;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Variant carrying a multi-tier `OutcomeTier[]` mirror of
|
|
68
|
+
* `Pricing.outcome.tiers`. Used when the Service quotes a tiered price (e.g.
|
|
69
|
+
* S/M/L by feature complexity) and the headline contract figure should be
|
|
70
|
+
* computed lazily from the chosen tier rather than baked at declaration time.
|
|
71
|
+
*
|
|
72
|
+
* At runtime, `Service.invoke` selects a tier based on input characteristics
|
|
73
|
+
* and sets `selectedTierId`; the headline {@link Money} amount is then
|
|
74
|
+
* computed by `tiers.find(t => t.id === selectedTierId)?.amount`.
|
|
75
|
+
*
|
|
76
|
+
* Carries `timeoutDays` (the tiered variant currently couples with relative-
|
|
77
|
+
* duration deadlines; absolute-deadline + tiers can be added later if a
|
|
78
|
+
* catalog Service needs both).
|
|
79
|
+
*/
|
|
80
|
+
export interface OutcomeContractWithTiers extends OutcomeContractBase {
|
|
81
|
+
/**
|
|
82
|
+
* Whole days from contract creation until expiry. Mutually exclusive with
|
|
83
|
+
* {@link OutcomeContractWithExpiresAt.expiresAt}.
|
|
84
|
+
*/
|
|
85
|
+
timeoutDays: number;
|
|
86
|
+
expiresAt?: never;
|
|
87
|
+
/**
|
|
88
|
+
* Mirror of `Pricing.outcome.tiers` — one entry per quoted complexity tier
|
|
89
|
+
* (e.g. S / M / L). The runtime resolves the headline amount from the
|
|
90
|
+
* selected tier at invocation time.
|
|
91
|
+
*/
|
|
92
|
+
tiers: OutcomeTier[];
|
|
93
|
+
/**
|
|
94
|
+
* Tier id selected by the runtime at invocation time (e.g. `'S'`). Omitted
|
|
95
|
+
* at declaration time — `Service.invoke` sets it based on input
|
|
96
|
+
* characteristics, then a lazy getter computes the headline {@link Money}
|
|
97
|
+
* amount as `tiers.find(t => t.id === selectedTierId)?.amount`.
|
|
98
|
+
*/
|
|
99
|
+
selectedTierId?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The runtime computes the headline amount from the selected tier — never
|
|
102
|
+
* declared inline on this variant.
|
|
103
|
+
*/
|
|
104
|
+
amount?: never;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Discriminated union — exactly one of `expiresAt` / `timeoutDays` is required,
|
|
108
|
+
* and exactly one of `amount` / `tiers` is required.
|
|
109
|
+
*
|
|
110
|
+
* Use {@link OutcomeContractWithExpiresAt} for absolute deadlines + a single
|
|
111
|
+
* {@link Money} amount; use {@link OutcomeContractWithTimeoutDays} for
|
|
112
|
+
* relative durations from contract creation + a single {@link Money} amount;
|
|
113
|
+
* use {@link OutcomeContractWithTiers} when the Service quotes a tiered price
|
|
114
|
+
* (S/M/L) and the runtime selects a tier per-invocation.
|
|
115
|
+
*/
|
|
116
|
+
export type OutcomeContract = OutcomeContractWithExpiresAt | OutcomeContractWithTimeoutDays | OutcomeContractWithTiers;
|
|
117
|
+
/**
|
|
118
|
+
* Resolve the headline {@link Money} amount on an {@link OutcomeContract},
|
|
119
|
+
* lazily computing from `tiers[selectedTierId]` for the
|
|
120
|
+
* {@link OutcomeContractWithTiers} variant.
|
|
121
|
+
*
|
|
122
|
+
* Returns `undefined` for the tiers variant when no tier has been selected
|
|
123
|
+
* yet (e.g. pre-invocation, at declaration / publish time).
|
|
124
|
+
*/
|
|
125
|
+
export declare function resolveOutcomeAmount(contract: OutcomeContract): Money | undefined;
|
|
126
|
+
export interface ProofOfResult {
|
|
127
|
+
$id: string;
|
|
128
|
+
$type: 'ProofOfResult';
|
|
129
|
+
contractRef: string;
|
|
130
|
+
/** Worker (Person/Agent/Role) that signed the proof. */
|
|
131
|
+
signedBy: string;
|
|
132
|
+
/** ISO-8601 timestamp. */
|
|
133
|
+
signedAt: string;
|
|
134
|
+
/** Action that produced the verifiable output. */
|
|
135
|
+
outputRef?: string;
|
|
136
|
+
/** Cryptographic signature where applicable. */
|
|
137
|
+
signature?: string;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=outcome-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcome-contract.d.ts","sourceRoot":"","sources":["../../src/finance/outcome-contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH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pB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;OAGG;IACH,MAAM,CAAC,EAAE,KAAK,CAAA;CACf;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GACvB,4BAA4B,GAC5B,8BAA8B,GAC9B,wBAAwB,CAAA;AAE5B;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,KAAK,GAAG,SAAS,CAQjF;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,eAAe,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,wDAAwD;IACxD,QAAQ,EAAE,MAAM,CAAA;IAChB,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OutcomeContract — definition-of-done + escrow + release condition.
|
|
3
|
+
* Distinct from OutputContract (technical schema; lives in services-as-software).
|
|
4
|
+
*
|
|
5
|
+
* The predicate is evaluated against the runtime state of a Service invocation;
|
|
6
|
+
* when it passes, escrow releases funds to the seller.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the headline {@link Money} amount on an {@link OutcomeContract},
|
|
10
|
+
* lazily computing from `tiers[selectedTierId]` for the
|
|
11
|
+
* {@link OutcomeContractWithTiers} variant.
|
|
12
|
+
*
|
|
13
|
+
* Returns `undefined` for the tiers variant when no tier has been selected
|
|
14
|
+
* yet (e.g. pre-invocation, at declaration / publish time).
|
|
15
|
+
*/
|
|
16
|
+
export function resolveOutcomeAmount(contract) {
|
|
17
|
+
if (contract.tiers !== undefined) {
|
|
18
|
+
if (contract.selectedTierId === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
const tier = contract.tiers.find((t) => t.id === contract.selectedTierId);
|
|
21
|
+
if (!tier)
|
|
22
|
+
return undefined;
|
|
23
|
+
return { amount: tier.amount, currency: tier.currency ?? 'USD' };
|
|
24
|
+
}
|
|
25
|
+
return contract.amount;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=outcome-contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outcome-contract.js","sourceRoot":"","sources":["../../src/finance/outcome-contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwHH;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAyB;IAC5D,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QACjC,IAAI,QAAQ,CAAC,cAAc,KAAK,SAAS;YAAE,OAAO,SAAS,CAAA;QAC3D,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,cAAc,CAAC,CAAA;QACzE,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAA;QAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,KAAK,EAAE,CAAA;IAClE,CAAC;IACD,OAAO,QAAQ,CAAC,MAAM,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FinanceProvider — port for adapter implementations (Stripe, Tempo, x402,
|
|
3
|
+
* Privy, Lightspark). Every method is optional and gated by ProviderCapabilities;
|
|
4
|
+
* adapters declare which capabilities they support.
|
|
5
|
+
*
|
|
6
|
+
* Adapter implementations are forthcoming and ship outside the substrate —
|
|
7
|
+
* none are bundled here.
|
|
8
|
+
*/
|
|
9
|
+
import type { Currency, Money, Cost } from './types.js';
|
|
10
|
+
import type { Account, AccountSpec, TransferOpts, TransferResult } from './account.js';
|
|
11
|
+
import type { Card, CardSpec } from './card.js';
|
|
12
|
+
import type { OutcomeContract, ProofOfResult } from './outcome-contract.js';
|
|
13
|
+
import type { StablecoinCurrency } from './types.js';
|
|
14
|
+
import type { MerchantCapable } from './merchant.js';
|
|
15
|
+
export type ProviderRail = 'mpp' | 'spt' | 'x402' | 'streaming' | 'card' | 'wire' | 'ach' | 'lightning' | 'on-chain';
|
|
16
|
+
export interface ProviderCapabilities {
|
|
17
|
+
payments: boolean;
|
|
18
|
+
refunds: boolean;
|
|
19
|
+
issuing: boolean;
|
|
20
|
+
treasury: boolean;
|
|
21
|
+
escrow: boolean;
|
|
22
|
+
subscriptions: boolean;
|
|
23
|
+
metering: boolean;
|
|
24
|
+
/** Platform/Connect product-line provisioning + hosted checkout (see MerchantCapable). */
|
|
25
|
+
merchant: boolean;
|
|
26
|
+
multiCurrency: boolean;
|
|
27
|
+
currencies: Currency[];
|
|
28
|
+
stablecoins: StablecoinCurrency[];
|
|
29
|
+
rails: ProviderRail[];
|
|
30
|
+
}
|
|
31
|
+
export interface ChargeOpts {
|
|
32
|
+
/** Counterparty Worker paying the charge (ThingRef shape). */
|
|
33
|
+
buyer: string;
|
|
34
|
+
amount: Money;
|
|
35
|
+
/** Service or invocation reference for attribution. */
|
|
36
|
+
ref?: string;
|
|
37
|
+
/** Idempotency key for at-most-once semantics. */
|
|
38
|
+
idempotencyKey?: string;
|
|
39
|
+
/** Provider-specific opts; pass-through. */
|
|
40
|
+
providerOpts?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
export interface ChargeResult {
|
|
43
|
+
$id: string;
|
|
44
|
+
$type: 'Charge';
|
|
45
|
+
amount: Money;
|
|
46
|
+
status: 'pending' | 'authorized' | 'captured' | 'failed' | 'refunded';
|
|
47
|
+
/** ISO-8601 timestamp. */
|
|
48
|
+
createdAt: string;
|
|
49
|
+
providerData: {
|
|
50
|
+
provider: string;
|
|
51
|
+
externalId: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface RefundResult {
|
|
55
|
+
$id: string;
|
|
56
|
+
$type: 'Refund';
|
|
57
|
+
chargeId: string;
|
|
58
|
+
amount: Money;
|
|
59
|
+
/** ISO-8601 timestamp. */
|
|
60
|
+
createdAt: string;
|
|
61
|
+
}
|
|
62
|
+
export interface EscrowHandle {
|
|
63
|
+
$id: string;
|
|
64
|
+
contractRef: string;
|
|
65
|
+
state: 'held' | 'released' | 'expired' | 'cancelled';
|
|
66
|
+
providerData: {
|
|
67
|
+
provider: string;
|
|
68
|
+
externalId: string;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface ReleaseResult {
|
|
72
|
+
$id: string;
|
|
73
|
+
escrowHandle: string;
|
|
74
|
+
releasedAt: string;
|
|
75
|
+
/** ISO-8601 timestamp. */
|
|
76
|
+
amount: Money;
|
|
77
|
+
}
|
|
78
|
+
export interface SubscribeOpts {
|
|
79
|
+
buyer: string;
|
|
80
|
+
planRef: string;
|
|
81
|
+
/** Provider-specific opts; pass-through. */
|
|
82
|
+
providerOpts?: Record<string, unknown>;
|
|
83
|
+
}
|
|
84
|
+
export interface Subscription {
|
|
85
|
+
$id: string;
|
|
86
|
+
$type: 'Subscription';
|
|
87
|
+
buyer: string;
|
|
88
|
+
planRef: string;
|
|
89
|
+
state: 'active' | 'paused' | 'cancelled' | 'past-due';
|
|
90
|
+
/** ISO-8601 timestamp. */
|
|
91
|
+
startedAt: string;
|
|
92
|
+
providerData: {
|
|
93
|
+
provider: string;
|
|
94
|
+
externalId: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface MeterEvent {
|
|
98
|
+
/** Subscription or customer this event meters against. */
|
|
99
|
+
subscriptionRef: string;
|
|
100
|
+
event: string;
|
|
101
|
+
quantity: bigint;
|
|
102
|
+
/** ISO-8601 timestamp. */
|
|
103
|
+
occurredAt: string;
|
|
104
|
+
}
|
|
105
|
+
export interface FinanceProvider extends Partial<MerchantCapable> {
|
|
106
|
+
readonly name: string;
|
|
107
|
+
readonly capabilities: ProviderCapabilities;
|
|
108
|
+
charge(opts: ChargeOpts): Promise<ChargeResult>;
|
|
109
|
+
refund(chargeId: string, amount?: Money): Promise<RefundResult>;
|
|
110
|
+
issueCard?(spec: CardSpec): Promise<Card>;
|
|
111
|
+
lockCard?(cardId: string): Promise<void>;
|
|
112
|
+
openAccount?(spec: AccountSpec): Promise<Account>;
|
|
113
|
+
balance?(accountId: string): Promise<Money>;
|
|
114
|
+
transfer?(opts: TransferOpts): Promise<TransferResult>;
|
|
115
|
+
escrow?(contract: OutcomeContract): Promise<EscrowHandle>;
|
|
116
|
+
release?(escrowHandle: string, proof: ProofOfResult): Promise<ReleaseResult>;
|
|
117
|
+
subscribe?(opts: SubscribeOpts): Promise<Subscription>;
|
|
118
|
+
meter?(event: MeterEvent): Promise<void>;
|
|
119
|
+
captureCost?(cost: Omit<Cost, '$id' | '$type'>): Promise<Cost>;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port.d.ts","sourceRoot":"","sources":["../../src/finance/port.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACtF,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAEpD,MAAM,MAAM,YAAY,GACpB,KAAK,GACL,KAAK,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ceProvider — port for adapter implementations (Stripe, Tempo, x402,
|
|
3
|
+
* Privy, Lightspark). Every method is optional and gated by ProviderCapabilities;
|
|
4
|
+
* adapters declare which capabilities they support.
|
|
5
|
+
*
|
|
6
|
+
* Adapter implementations are forthcoming and ship outside the substrate —
|
|
7
|
+
* none are bundled here.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"port.js","sourceRoot":"","sources":["../../src/finance/port.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing — discriminated union with five factory variants.
|
|
3
|
+
*
|
|
4
|
+
* outcome — pay on delivery; tiers by complexity (S/M/L)
|
|
5
|
+
* subscription — recurring plan + optional metered overage
|
|
6
|
+
* perInvocation — flat per-call with included-tier ladder
|
|
7
|
+
* composite — one-time base + metered events
|
|
8
|
+
* percent-of — proportional charge against a realised basis
|
|
9
|
+
* (invoice amount, collected amount, transaction volume)
|
|
10
|
+
* with optional cap / floor
|
|
11
|
+
*
|
|
12
|
+
* Each factory returns a typed Pricing value with discriminator on .kind.
|
|
13
|
+
*/
|
|
14
|
+
import type { Currency, Money } from './types.js';
|
|
15
|
+
import type { SLATarget } from './sla.js';
|
|
16
|
+
export interface OutcomeTier {
|
|
17
|
+
id: string;
|
|
18
|
+
amount: bigint;
|
|
19
|
+
currency?: Currency;
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface PerInvocationTier {
|
|
23
|
+
id: string;
|
|
24
|
+
amount: bigint;
|
|
25
|
+
/** Number of invocations included before per-tier billing applies. */
|
|
26
|
+
includedPerMonth?: number;
|
|
27
|
+
/** Per-invocation overage cost above included. */
|
|
28
|
+
overage?: bigint;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A single metered-billing line item. `description` is genuinely optional —
|
|
32
|
+
* callers may omit it from inline literals AND from the {@link Pricing}
|
|
33
|
+
* factory calls (`Pricing.subscription` / `Pricing.composite`).
|
|
34
|
+
*/
|
|
35
|
+
export interface MeteredEntry {
|
|
36
|
+
event: string;
|
|
37
|
+
amount: bigint;
|
|
38
|
+
description?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Optional one-time base charge on a {@link Pricing.composite} plan. `description`
|
|
42
|
+
* is optional under `exactOptionalPropertyTypes`.
|
|
43
|
+
*/
|
|
44
|
+
export interface CompositeBase {
|
|
45
|
+
id: string;
|
|
46
|
+
amount: bigint;
|
|
47
|
+
description?: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Recurring plan portion of a {@link Pricing.subscription}. Shared between the
|
|
51
|
+
* `Pricing` discriminated union and the {@link Pricing.subscription} factory
|
|
52
|
+
* so the two shapes never drift.
|
|
53
|
+
*/
|
|
54
|
+
export interface SubscriptionPlan {
|
|
55
|
+
id: string;
|
|
56
|
+
amount: bigint;
|
|
57
|
+
currency: Currency;
|
|
58
|
+
interval: 'day' | 'week' | 'month' | 'quarter' | 'year';
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Standard bases the {@link Pricing.percentOf} runtime knows how to resolve
|
|
62
|
+
* at settlement time. Adapters MAY accept arbitrary basis strings for
|
|
63
|
+
* domain-specific metering, but the canonical four cover the common cases:
|
|
64
|
+
*
|
|
65
|
+
* invoice-amount — face value of an outbound invoice
|
|
66
|
+
* collected-amount — funds actually received (post-settlement)
|
|
67
|
+
* transaction-volume — gross payment volume processed
|
|
68
|
+
* <custom string> — provider-defined; must be resolvable in the
|
|
69
|
+
* metering runtime
|
|
70
|
+
*/
|
|
71
|
+
export type PercentOfBasis = 'invoice-amount' | 'collected-amount' | 'transaction-volume' | (string & {});
|
|
72
|
+
export type Pricing = {
|
|
73
|
+
kind: 'outcome';
|
|
74
|
+
tiers: OutcomeTier[];
|
|
75
|
+
sla?: SLATarget;
|
|
76
|
+
} | {
|
|
77
|
+
kind: 'subscription';
|
|
78
|
+
plan: SubscriptionPlan;
|
|
79
|
+
metered?: MeteredEntry[];
|
|
80
|
+
sla?: SLATarget;
|
|
81
|
+
} | {
|
|
82
|
+
kind: 'per-invocation';
|
|
83
|
+
tiers: PerInvocationTier[];
|
|
84
|
+
} | {
|
|
85
|
+
kind: 'composite';
|
|
86
|
+
base: CompositeBase;
|
|
87
|
+
metered: MeteredEntry[];
|
|
88
|
+
} | {
|
|
89
|
+
kind: 'percent-of';
|
|
90
|
+
basis: PercentOfBasis;
|
|
91
|
+
/**
|
|
92
|
+
* Rate in basis points (1/100ths of a percent). Examples: `200` = 2%,
|
|
93
|
+
* `75` = 0.75%, `1000` = 10%.
|
|
94
|
+
*
|
|
95
|
+
* The metering runtime computes the charge as
|
|
96
|
+
* `(realised_basis * rateBasisPoints) / 10000`, then clamps the
|
|
97
|
+
* result by the optional `cap` / `floor` (when present).
|
|
98
|
+
*/
|
|
99
|
+
rateBasisPoints: number;
|
|
100
|
+
/** Optional upper bound on the per-event charge. */
|
|
101
|
+
cap?: Money;
|
|
102
|
+
/** Optional lower bound on the per-event charge. */
|
|
103
|
+
floor?: Money;
|
|
104
|
+
};
|
|
105
|
+
export declare const Pricing: {
|
|
106
|
+
outcome(opts: {
|
|
107
|
+
tiers: OutcomeTier[];
|
|
108
|
+
sla?: SLATarget;
|
|
109
|
+
}): Pricing;
|
|
110
|
+
subscription(opts: {
|
|
111
|
+
plan: SubscriptionPlan;
|
|
112
|
+
metered?: MeteredEntry[];
|
|
113
|
+
sla?: SLATarget;
|
|
114
|
+
}): Pricing;
|
|
115
|
+
perInvocation(opts: {
|
|
116
|
+
tiers: PerInvocationTier[];
|
|
117
|
+
}): Pricing;
|
|
118
|
+
composite(opts: {
|
|
119
|
+
base: CompositeBase;
|
|
120
|
+
metered: MeteredEntry[];
|
|
121
|
+
}): Pricing;
|
|
122
|
+
/**
|
|
123
|
+
* Percent-of-basis pricing — proportional charge against a realised
|
|
124
|
+
* basis (e.g. invoice amount, collected amount, transaction volume).
|
|
125
|
+
*
|
|
126
|
+
* The metering runtime resolves `basis` to a concrete bigint at
|
|
127
|
+
* settlement time, then computes the charge as
|
|
128
|
+
* `(realised_basis * rateBasisPoints) / 10000`, optionally clamped by
|
|
129
|
+
* `cap` / `floor`.
|
|
130
|
+
*
|
|
131
|
+
* @example AR Service: 2% of collected funds
|
|
132
|
+
* ```ts
|
|
133
|
+
* Pricing.percentOf({ basis: 'collected-amount', rateBasisPoints: 200 })
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @example Capped: 0.75% of transaction volume, max $50/event
|
|
137
|
+
* ```ts
|
|
138
|
+
* Pricing.percentOf({
|
|
139
|
+
* basis: 'transaction-volume',
|
|
140
|
+
* rateBasisPoints: 75,
|
|
141
|
+
* cap: { amount: 5000n, currency: 'USD' },
|
|
142
|
+
* })
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
percentOf(opts: {
|
|
146
|
+
basis: PercentOfBasis;
|
|
147
|
+
rateBasisPoints: number;
|
|
148
|
+
cap?: Money;
|
|
149
|
+
floor?: Money;
|
|
150
|
+
}): Pricing;
|
|
151
|
+
};
|
|
152
|
+
/** Convenience: build a Money value from a bigint + currency. */
|
|
153
|
+
export declare const money: (amount: bigint, currency?: Currency) => Money;
|
|
154
|
+
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/finance/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EA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A;CAC3B,GACD;IACE,IAAI,EAAE,WAAW,CAAA;IACjB,IAAI,EAAE,aAAa,CAAA;IACnB,OAAO,EAAE,YAAY,EAAE,CAAA;CACxB,GACD;IACE,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE,cAAc,CAAA;IACrB;;;;;;;OAOG;IACH,eAAe,EAAE,MAAM,CAAA;IACvB,oDAAoD;IACpD,GAAG,CAAC,EAAE,KAAK,CAAA;IACX,oDAAoD;IACpD,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAEL,eAAO,MAAM,OAAO;kBACJ;QAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAAC,GAAG,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,OAAO;uBAO9C;QACjB,IAAI,EAAE,gBAAgB,CAAA;QACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAA;QACxB,GAAG,CAAC,EAAE,SAAS,CAAA;KAChB,GAAG,OAAO;wBAUS;QAAE,KAAK,EAAE,iBAAiB,EAAE,CAAA;KAAE,GAAG,OAAO;oBAI5C;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,OAAO,EAAE,YAAY,EAAE,CAAA;KAAE,GAAG,OAAO;IAI1E;;;;;;;;;;;;;;;;;;;;;;OAsBG;oBACa;QACd,KAAK,EAAE,cAAc,CAAA;QACrB,eAAe,EAAE,MAAM,CAAA;QACvB,GAAG,CAAC,EAAE,KAAK,CAAA;QACX,KAAK,CAAC,EAAE,KAAK,CAAA;KACd,GAAG,OAAO;CAUZ,CAAA;AAED,iEAAiE;AACjE,eAAO,MAAM,KAAK,GAAI,QAAQ,MAAM,EAAE,WAAU,QAAgB,KAAG,KAGjE,CAAA"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pricing — discriminated union with five factory variants.
|
|
3
|
+
*
|
|
4
|
+
* outcome — pay on delivery; tiers by complexity (S/M/L)
|
|
5
|
+
* subscription — recurring plan + optional metered overage
|
|
6
|
+
* perInvocation — flat per-call with included-tier ladder
|
|
7
|
+
* composite — one-time base + metered events
|
|
8
|
+
* percent-of — proportional charge against a realised basis
|
|
9
|
+
* (invoice amount, collected amount, transaction volume)
|
|
10
|
+
* with optional cap / floor
|
|
11
|
+
*
|
|
12
|
+
* Each factory returns a typed Pricing value with discriminator on .kind.
|
|
13
|
+
*/
|
|
14
|
+
export const Pricing = {
|
|
15
|
+
outcome(opts) {
|
|
16
|
+
if (opts.sla !== undefined) {
|
|
17
|
+
return { kind: 'outcome', tiers: opts.tiers, sla: opts.sla };
|
|
18
|
+
}
|
|
19
|
+
return { kind: 'outcome', tiers: opts.tiers };
|
|
20
|
+
},
|
|
21
|
+
subscription(opts) {
|
|
22
|
+
const result = {
|
|
23
|
+
kind: 'subscription',
|
|
24
|
+
plan: opts.plan,
|
|
25
|
+
};
|
|
26
|
+
if (opts.metered !== undefined)
|
|
27
|
+
result.metered = opts.metered;
|
|
28
|
+
if (opts.sla !== undefined)
|
|
29
|
+
result.sla = opts.sla;
|
|
30
|
+
return result;
|
|
31
|
+
},
|
|
32
|
+
perInvocation(opts) {
|
|
33
|
+
return { kind: 'per-invocation', tiers: opts.tiers };
|
|
34
|
+
},
|
|
35
|
+
composite(opts) {
|
|
36
|
+
return { kind: 'composite', base: opts.base, metered: opts.metered };
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Percent-of-basis pricing — proportional charge against a realised
|
|
40
|
+
* basis (e.g. invoice amount, collected amount, transaction volume).
|
|
41
|
+
*
|
|
42
|
+
* The metering runtime resolves `basis` to a concrete bigint at
|
|
43
|
+
* settlement time, then computes the charge as
|
|
44
|
+
* `(realised_basis * rateBasisPoints) / 10000`, optionally clamped by
|
|
45
|
+
* `cap` / `floor`.
|
|
46
|
+
*
|
|
47
|
+
* @example AR Service: 2% of collected funds
|
|
48
|
+
* ```ts
|
|
49
|
+
* Pricing.percentOf({ basis: 'collected-amount', rateBasisPoints: 200 })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Capped: 0.75% of transaction volume, max $50/event
|
|
53
|
+
* ```ts
|
|
54
|
+
* Pricing.percentOf({
|
|
55
|
+
* basis: 'transaction-volume',
|
|
56
|
+
* rateBasisPoints: 75,
|
|
57
|
+
* cap: { amount: 5000n, currency: 'USD' },
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
percentOf(opts) {
|
|
62
|
+
const result = {
|
|
63
|
+
kind: 'percent-of',
|
|
64
|
+
basis: opts.basis,
|
|
65
|
+
rateBasisPoints: opts.rateBasisPoints,
|
|
66
|
+
};
|
|
67
|
+
if (opts.cap !== undefined)
|
|
68
|
+
result.cap = opts.cap;
|
|
69
|
+
if (opts.floor !== undefined)
|
|
70
|
+
result.floor = opts.floor;
|
|
71
|
+
return result;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
/** Convenience: build a Money value from a bigint + currency. */
|
|
75
|
+
export const money = (amount, currency = 'USD') => ({
|
|
76
|
+
amount,
|
|
77
|
+
currency,
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/finance/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA8GH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,OAAO,CAAC,IAA+C;QACrD,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAA;QAC9D,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAA;IAC/C,CAAC;IAED,YAAY,CAAC,IAIZ;QACC,MAAM,MAAM,GAA+C;YACzD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-based settlement.
|
|
3
|
+
*
|
|
4
|
+
* Stripe's MPP Sessions ship escrow but no outcome-predicate-driven release —
|
|
5
|
+
* this module is the gap-filler. SaS's Service.outcomeContract.predicate
|
|
6
|
+
* uses these to express "definition of done."
|
|
7
|
+
*
|
|
8
|
+
* Seven leaf predicates + AND/OR composition:
|
|
9
|
+
* - schema-match : output matches schema
|
|
10
|
+
* - evaluator-pass : EvaluatorPanel approves at threshold
|
|
11
|
+
* - human-sign : human with signerRoles signs
|
|
12
|
+
* - external : external verifier (e.g. github CI + merged) approves
|
|
13
|
+
* - load-bearing-pass : a named subset of rubric items all pass (sb killThreshold)
|
|
14
|
+
* - overall-floor : N of total rubric items pass (sb killThreshold)
|
|
15
|
+
* - unmet-requirements-pass : no `severity: 'blocking'` UnmetRequirements remain
|
|
16
|
+
* (sb-n7d open-blocking gate); when `categories` is
|
|
17
|
+
* supplied, only those categories are checked.
|
|
18
|
+
*/
|
|
19
|
+
export type ProofPredicate = {
|
|
20
|
+
kind: 'schema-match';
|
|
21
|
+
schema: unknown;
|
|
22
|
+
} | {
|
|
23
|
+
kind: 'evaluator-pass';
|
|
24
|
+
panelRef: string | 'self';
|
|
25
|
+
minScore: number | 'all-approved' | 'majority';
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'human-sign';
|
|
28
|
+
signerRoles: string[];
|
|
29
|
+
when?: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'external';
|
|
32
|
+
verifier: string;
|
|
33
|
+
spec: unknown;
|
|
34
|
+
} | {
|
|
35
|
+
kind: 'load-bearing-pass';
|
|
36
|
+
itemSet: string[];
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'overall-floor';
|
|
39
|
+
minPasses: number;
|
|
40
|
+
outOfTotal: number;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'unmet-requirements-pass';
|
|
43
|
+
categories?: string[];
|
|
44
|
+
} | {
|
|
45
|
+
kind: 'and';
|
|
46
|
+
predicates: ProofPredicate[];
|
|
47
|
+
} | {
|
|
48
|
+
kind: 'or';
|
|
49
|
+
predicates: ProofPredicate[];
|
|
50
|
+
};
|
|
51
|
+
export declare const SchemaMatch: (schema: unknown) => ProofPredicate;
|
|
52
|
+
export declare const EvaluatorPass: (opts: {
|
|
53
|
+
panelRef: string | "self";
|
|
54
|
+
minScore: number | "all-approved" | "majority";
|
|
55
|
+
}) => ProofPredicate;
|
|
56
|
+
export declare const HumanSign: (opts: {
|
|
57
|
+
signerRoles: string[];
|
|
58
|
+
when?: string;
|
|
59
|
+
}) => ProofPredicate;
|
|
60
|
+
export declare const External: (opts: {
|
|
61
|
+
verifier: string;
|
|
62
|
+
spec: unknown;
|
|
63
|
+
}) => ProofPredicate;
|
|
64
|
+
export declare const LoadBearingPass: (itemSet: string[]) => ProofPredicate;
|
|
65
|
+
export declare const OverallFloor: (opts: {
|
|
66
|
+
minPasses: number;
|
|
67
|
+
outOfTotal: number;
|
|
68
|
+
}) => ProofPredicate;
|
|
69
|
+
/**
|
|
70
|
+
* `UnmetRequirementsPass` — sb-n7d's open-blocking gate as a first-class
|
|
71
|
+
* predicate.
|
|
72
|
+
*
|
|
73
|
+
* Passes iff no `severity: 'blocking'` UnmetRequirement is present in the
|
|
74
|
+
* verify-time evaluation context. `severity: 'warning'` items are ignored.
|
|
75
|
+
*
|
|
76
|
+
* When `categories` is supplied, only requirements whose `category` matches
|
|
77
|
+
* one of the listed values are considered (others are ignored regardless of
|
|
78
|
+
* severity). When omitted, ALL categories are inspected.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // Any blocking unmet requirement fails the predicate.
|
|
82
|
+
* UnmetRequirementsPass()
|
|
83
|
+
*
|
|
84
|
+
* // Only blocking items in the 'compliance' or 'security' buckets fail.
|
|
85
|
+
* UnmetRequirementsPass({ categories: ['compliance', 'security'] })
|
|
86
|
+
*/
|
|
87
|
+
export declare const UnmetRequirementsPass: (opts?: {
|
|
88
|
+
categories?: string[];
|
|
89
|
+
}) => ProofPredicate;
|
|
90
|
+
export declare const AND: (...predicates: ProofPredicate[]) => ProofPredicate;
|
|
91
|
+
export declare const OR: (...predicates: ProofPredicate[]) => ProofPredicate;
|
|
92
|
+
//# sourceMappingURL=proof-predicate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-predicate.d.ts","sourceRoot":"","sources":["../../src/finance/proof-predicate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACzC;IACE,IAAI,EAAE,gBAAgB,CAAA;IACtB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,QAAQ,EAAE,MAAM,GAAG,cAAc,GAAG,UAAU,CAAA;CAC/C,GACD;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GAChD;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,yBAAyB,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAC1D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,UAAU,EAAE,cAAc,EAAE,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,UAAU,EAAE,cAAc,EAAE,CAAA;CAAE,CAAA;AAEhD,eAAO,MAAM,WAAW,GAAI,QAAQ,OAAO,KAAG,c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