business-as-code 2.1.3 → 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 -5
- package/CHANGELOG.md +53 -0
- package/README.md +2 -0
- package/dist/dollar.d.ts.map +1 -1
- package/dist/dollar.js +2 -2
- package/dist/dollar.js.map +1 -1
- package/dist/entities/organization.d.ts +4 -0
- package/dist/entities/organization.d.ts.map +1 -1
- package/dist/entities/organization.js +27 -18
- package/dist/entities/organization.js.map +1 -1
- package/dist/entities/planning.d.ts +87 -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/{canvas → finance}/types.js.map +1 -1
- package/dist/goals.d.ts +19 -0
- package/dist/goals.d.ts.map +1 -1
- package/dist/goals.js +81 -12
- package/dist/goals.js.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -7
- package/dist/index.js.map +1 -1
- package/dist/kpis.d.ts +19 -0
- package/dist/kpis.d.ts.map +1 -1
- package/dist/kpis.js +71 -6
- package/dist/kpis.js.map +1 -1
- package/dist/metrics.d.ts.map +1 -1
- package/dist/metrics.js +29 -24
- package/dist/metrics.js.map +1 -1
- package/dist/okrs.d.ts +34 -0
- package/dist/okrs.d.ts.map +1 -1
- package/dist/okrs.js +135 -13
- package/dist/okrs.js.map +1 -1
- package/dist/organization.d.ts.map +1 -1
- package/dist/organization.js +11 -11
- package/dist/organization.js.map +1 -1
- package/dist/process.d.ts.map +1 -1
- package/dist/process.js +13 -12
- package/dist/process.js.map +1 -1
- package/dist/product.d.ts.map +1 -1
- package/dist/product.js +9 -9
- package/dist/product.js.map +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +194 -32
- package/dist/queries.js.map +1 -1
- package/dist/roles.d.ts +25 -31
- package/dist/roles.d.ts.map +1 -1
- package/dist/roles.js +37 -10
- package/dist/roles.js.map +1 -1
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.js +13 -12
- package/dist/workflow.js.map +1 -1
- package/package.json +20 -13
- package/src/dollar.ts +5 -2
- package/src/entities/organization.ts +31 -18
- 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
- package/src/goals.ts +78 -12
- package/src/index.ts +48 -18
- package/src/kpis.ts +62 -8
- package/src/metrics.ts +92 -79
- package/src/okrs.ts +120 -20
- package/src/organization.ts +12 -15
- package/src/process.ts +11 -12
- package/src/product.ts +8 -9
- package/src/queries.ts +238 -75
- package/src/roles.ts +62 -61
- package/src/workflow.ts +22 -15
- package/test/business.test.ts +282 -0
- package/test/dollar.test.ts +270 -0
- package/test/entities.test.ts +628 -0
- package/test/financials.test.ts +539 -0
- package/test/goals.test.ts +451 -0
- package/{src → test}/index.test.ts +1 -1
- package/test/kpis.test.ts +440 -0
- package/test/metrics.test.ts +744 -0
- package/test/okrs.test.ts +741 -0
- package/test/organization.test.ts +548 -0
- package/test/process.test.ts +503 -0
- package/test/product.test.ts +430 -0
- package/test/queries.test.ts +556 -0
- package/test/roles.test.ts +546 -0
- package/test/service.test.ts +450 -0
- package/test/types.test.ts +1141 -0
- package/test/vision.test.ts +214 -0
- package/test/workflow.test.ts +501 -0
- package/vitest.config.ts +47 -0
- package/LICENSE +0 -21
- package/dist/canvas/activities.d.ts +0 -19
- package/dist/canvas/activities.d.ts.map +0 -1
- package/dist/canvas/activities.js +0 -20
- package/dist/canvas/activities.js.map +0 -1
- package/dist/canvas/channels.d.ts +0 -20
- package/dist/canvas/channels.d.ts.map +0 -1
- package/dist/canvas/channels.js +0 -21
- package/dist/canvas/channels.js.map +0 -1
- package/dist/canvas/relationships.d.ts +0 -20
- package/dist/canvas/relationships.d.ts.map +0 -1
- package/dist/canvas/relationships.js +0 -21
- package/dist/canvas/relationships.js.map +0 -1
- package/dist/canvas/resources.d.ts +0 -20
- package/dist/canvas/resources.d.ts.map +0 -1
- package/dist/canvas/resources.js +0 -30
- package/dist/canvas/resources.js.map +0 -1
- package/dist/canvas/revenue.d.ts +0 -22
- package/dist/canvas/revenue.d.ts.map +0 -1
- package/dist/canvas/revenue.js +0 -30
- package/dist/canvas/revenue.js.map +0 -1
- package/dist/canvas/segments.d.ts +0 -20
- package/dist/canvas/segments.d.ts.map +0 -1
- package/dist/canvas/segments.js +0 -28
- package/dist/canvas/segments.js.map +0 -1
- package/dist/canvas/types.d.ts +0 -232
- package/dist/canvas/types.d.ts.map +0 -1
- package/dist/canvas/types.js +0 -8
- package/dist/canvas/value.d.ts +0 -20
- package/dist/canvas/value.d.ts.map +0 -1
- package/dist/canvas/value.js +0 -21
- package/dist/canvas/value.js.map +0 -1
- package/src/business.js +0 -108
- package/src/canvas/activities.ts +0 -32
- package/src/canvas/canvas.ts +0 -482
- package/src/canvas/channels.ts +0 -34
- package/src/canvas/costs.ts +0 -43
- package/src/canvas/economics.ts +0 -99
- package/src/canvas/index.ts +0 -206
- package/src/canvas/partnerships.ts +0 -34
- package/src/canvas/projections.ts +0 -141
- package/src/canvas/relationships.ts +0 -34
- package/src/canvas/resources.ts +0 -43
- package/src/canvas/revenue.ts +0 -56
- package/src/canvas/segments.ts +0 -42
- package/src/canvas/types.ts +0 -363
- package/src/canvas/value.ts +0 -34
- package/src/dollar.js +0 -106
- package/src/entities/assets.js +0 -322
- package/src/entities/business.js +0 -369
- package/src/entities/communication.js +0 -254
- package/src/entities/customers.js +0 -988
- package/src/entities/financials.js +0 -931
- package/src/entities/goals.js +0 -799
- package/src/entities/index.js +0 -197
- package/src/entities/legal.js +0 -300
- package/src/entities/market.js +0 -300
- package/src/entities/marketing.js +0 -1156
- package/src/entities/offerings.js +0 -726
- package/src/entities/operations.js +0 -786
- package/src/entities/organization.js +0 -806
- package/src/entities/partnerships.js +0 -299
- package/src/entities/planning.js +0 -270
- package/src/entities/projects.js +0 -348
- package/src/entities/risk.js +0 -292
- package/src/entities/sales.js +0 -1247
- package/src/financials.js +0 -296
- package/src/goals.js +0 -214
- package/src/index.js +0 -131
- package/src/index.test.js +0 -274
- package/src/kpis.js +0 -231
- package/src/metrics.js +0 -324
- package/src/okrs.js +0 -268
- package/src/organization.js +0 -172
- package/src/process.js +0 -240
- package/src/product.js +0 -144
- package/src/queries.js +0 -414
- package/src/roles.js +0 -254
- package/src/service.js +0 -139
- package/src/types.js +0 -4
- package/src/vision.js +0 -67
- package/src/workflow.js +0 -246
- package/tests/canvas.test.ts +0 -842
|
@@ -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 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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,I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AAK,KAAK,SAAS;YAAE,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAA;QACvD,OAAO,MAAM,CAAA;IACf,CAAC;CACF,CAAA;AAED,iEAAiE;AACjE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,WAAqB,KAAK,EAAS,EAAE,CAAC,CAAC;IAC3E,MAAM;IACN,QAAQ;CACT,CAAC,CAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProofPredicate — composable predicates that gate outcome-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,C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GnD,CAAA"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProofPredicate — composable predicates that gate outcome-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 const SchemaMatch = (schema) => ({
|
|
20
|
+
kind: 'schema-match',
|
|
21
|
+
schema,
|
|
22
|
+
});
|
|
23
|
+
export const EvaluatorPass = (opts) => ({
|
|
24
|
+
kind: 'evaluator-pass',
|
|
25
|
+
panelRef: opts.panelRef,
|
|
26
|
+
minScore: opts.minScore,
|
|
27
|
+
});
|
|
28
|
+
export const HumanSign = (opts) => {
|
|
29
|
+
if (opts.when !== undefined) {
|
|
30
|
+
return { kind: 'human-sign', signerRoles: opts.signerRoles, when: opts.when };
|
|
31
|
+
}
|
|
32
|
+
return { kind: 'human-sign', signerRoles: opts.signerRoles };
|
|
33
|
+
};
|
|
34
|
+
export const External = (opts) => ({
|
|
35
|
+
kind: 'external',
|
|
36
|
+
verifier: opts.verifier,
|
|
37
|
+
spec: opts.spec,
|
|
38
|
+
});
|
|
39
|
+
export const LoadBearingPass = (itemSet) => ({
|
|
40
|
+
kind: 'load-bearing-pass',
|
|
41
|
+
itemSet,
|
|
42
|
+
});
|
|
43
|
+
export const OverallFloor = (opts) => ({
|
|
44
|
+
kind: 'overall-floor',
|
|
45
|
+
minPasses: opts.minPasses,
|
|
46
|
+
outOfTotal: opts.outOfTotal,
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* `UnmetRequirementsPass` — sb-n7d's open-blocking gate as a first-class
|
|
50
|
+
* predicate.
|
|
51
|
+
*
|
|
52
|
+
* Passes iff no `severity: 'blocking'` UnmetRequirement is present in the
|
|
53
|
+
* verify-time evaluation context. `severity: 'warning'` items are ignored.
|
|
54
|
+
*
|
|
55
|
+
* When `categories` is supplied, only requirements whose `category` matches
|
|
56
|
+
* one of the listed values are considered (others are ignored regardless of
|
|
57
|
+
* severity). When omitted, ALL categories are inspected.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Any blocking unmet requirement fails the predicate.
|
|
61
|
+
* UnmetRequirementsPass()
|
|
62
|
+
*
|
|
63
|
+
* // Only blocking items in the 'compliance' or 'security' buckets fail.
|
|
64
|
+
* UnmetRequirementsPass({ categories: ['compliance', 'security'] })
|
|
65
|
+
*/
|
|
66
|
+
export const UnmetRequirementsPass = (opts) => {
|
|
67
|
+
if (opts?.categories !== undefined) {
|
|
68
|
+
return { kind: 'unmet-requirements-pass', categories: opts.categories };
|
|
69
|
+
}
|
|
70
|
+
return { kind: 'unmet-requirements-pass' };
|
|
71
|
+
};
|
|
72
|
+
export const AND = (...predicates) => ({
|
|
73
|
+
kind: 'and',
|
|
74
|
+
predicates,
|
|
75
|
+
});
|
|
76
|
+
export const OR = (...predicates) => ({
|
|
77
|
+
kind: 'or',
|
|
78
|
+
predicates,
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=proof-predicate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof-predicate.js","sourceRoot":"","sources":["../../src/finance/proof-predicate.ts"],"names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A;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAgC,EAAkB,EAAE;IACxF,IAAI,IAAI,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;QACnC,OAAO,EAAE,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAA;IACzE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,yBAAyB,EAAE,CAAA;AAC5C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,UAA4B,EAAkB,EAAE,CAAC,CAAC;IACvE,IAAI,EAAE,KAAK;IACX,UAAU;CACX,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,UAA4B,EAAkB,EAAE,CAAC,CAAC;IACtE,IAAI,EAAE,IAAI;IACV,UAAU;CACX,CAAC,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RefundContract — typed refund machinery. The 7-pattern catalog (per startup-builder
|
|
3
|
+
* SERVICES.md) defines the contractual templates a Service can bind to.
|
|
4
|
+
*
|
|
5
|
+
* Stripe's Smart Disputes are consumer-chargeback-shaped; this is B2B SLA-shape.
|
|
6
|
+
*/
|
|
7
|
+
export type RefundContractRef = 'no-charge-if-not-qualified' | 'quality-floor-fail' | 'sla-credit-on-late-delivery' | 'sla-credit-on-late-close' | 'partial-credit-on-partial-delivery' | 'time-bounded-money-back' | 'escalate-to-dispute' | (string & {
|
|
8
|
+
__brand?: 'RefundContractRef';
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Catalog of canonical refund contracts. Consumers reference by id; substrate
|
|
12
|
+
* resolves the contract semantics at settlement time.
|
|
13
|
+
*/
|
|
14
|
+
export declare const RefundContracts: {
|
|
15
|
+
readonly 'no-charge-if-not-qualified': {
|
|
16
|
+
readonly description: "No charge unless EvaluatorPass + downstream verification confirms work delivered.";
|
|
17
|
+
readonly triggersAt: "pre-charge";
|
|
18
|
+
};
|
|
19
|
+
readonly 'quality-floor-fail': {
|
|
20
|
+
readonly description: "Full refund when EvaluatorPanel rejects below quality floor.";
|
|
21
|
+
readonly triggersAt: "post-quality-review";
|
|
22
|
+
};
|
|
23
|
+
readonly 'sla-credit-on-late-delivery': {
|
|
24
|
+
readonly description: "Credit equal to N% of invoice when delivery exceeds OutcomeContract.expiresAt.";
|
|
25
|
+
readonly triggersAt: "on-timeout";
|
|
26
|
+
};
|
|
27
|
+
readonly 'sla-credit-on-late-close': {
|
|
28
|
+
readonly description: "Credit on monthly subscription when SLA target (e.g. close-by-day-5) breached.";
|
|
29
|
+
readonly triggersAt: "sla-breach";
|
|
30
|
+
};
|
|
31
|
+
readonly 'partial-credit-on-partial-delivery': {
|
|
32
|
+
readonly description: "Pro-rata credit when fraction of work-units delivered (e.g. tickets resolved).";
|
|
33
|
+
readonly triggersAt: "post-delivery";
|
|
34
|
+
};
|
|
35
|
+
readonly 'time-bounded-money-back': {
|
|
36
|
+
readonly description: "Full refund within N days of acceptance, no questions asked.";
|
|
37
|
+
readonly triggersAt: "on-customer-request";
|
|
38
|
+
};
|
|
39
|
+
readonly 'escalate-to-dispute': {
|
|
40
|
+
readonly description: "Route to ESCALATED_TO_HUMAN_REVIEW state; manual resolution.";
|
|
41
|
+
readonly triggersAt: "on-customer-dispute";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=refund.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refund.d.ts","sourceRoot":"","sources":["../../src/finance/refund.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,iBAAiB,GACzB,4BAA4B,GAC5B,oBAAoB,GACpB,6BAA6B,GAC7B,0BAA0B,GAC1B,oCAAoC,GACpC,yBAAyB,GACzB,qBAAqB,GACrB,CAAC,MAAM,GAAG;IAAE,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAAE,CAAC,CAAA;AAEhD;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BlB,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RefundContract — typed refund machinery. The 7-pattern catalog (per startup-builder
|
|
3
|
+
* SERVICES.md) defines the contractual templates a Service can bind to.
|
|
4
|
+
*
|
|
5
|
+
* Stripe's Smart Disputes are consumer-chargeback-shaped; this is B2B SLA-shape.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Catalog of canonical refund contracts. Consumers reference by id; substrate
|
|
9
|
+
* resolves the contract semantics at settlement time.
|
|
10
|
+
*/
|
|
11
|
+
export const RefundContracts = {
|
|
12
|
+
'no-charge-if-not-qualified': {
|
|
13
|
+
description: 'No charge unless EvaluatorPass + downstream verification confirms work delivered.',
|
|
14
|
+
triggersAt: 'pre-charge',
|
|
15
|
+
},
|
|
16
|
+
'quality-floor-fail': {
|
|
17
|
+
description: 'Full refund when EvaluatorPanel rejects below quality floor.',
|
|
18
|
+
triggersAt: 'post-quality-review',
|
|
19
|
+
},
|
|
20
|
+
'sla-credit-on-late-delivery': {
|
|
21
|
+
description: 'Credit equal to N% of invoice when delivery exceeds OutcomeContract.expiresAt.',
|
|
22
|
+
triggersAt: 'on-timeout',
|
|
23
|
+
},
|
|
24
|
+
'sla-credit-on-late-close': {
|
|
25
|
+
description: 'Credit on monthly subscription when SLA target (e.g. close-by-day-5) breached.',
|
|
26
|
+
triggersAt: 'sla-breach',
|
|
27
|
+
},
|
|
28
|
+
'partial-credit-on-partial-delivery': {
|
|
29
|
+
description: 'Pro-rata credit when fraction of work-units delivered (e.g. tickets resolved).',
|
|
30
|
+
triggersAt: 'post-delivery',
|
|
31
|
+
},
|
|
32
|
+
'time-bounded-money-back': {
|
|
33
|
+
description: 'Full refund within N days of acceptance, no questions asked.',
|
|
34
|
+
triggersAt: 'on-customer-request',
|
|
35
|
+
},
|
|
36
|
+
'escalate-to-dispute': {
|
|
37
|
+
description: 'Route to ESCALATED_TO_HUMAN_REVIEW state; manual resolution.',
|
|
38
|
+
triggersAt: 'on-customer-dispute',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=refund.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refund.js","sourceRoot":"","sources":["../../src/finance/refund.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,4BAA4B,EAAE;QAC5B,WAAW,EACT,mFAAmF;QACrF,UAAU,EAAE,YAAY;KACzB;IACD,oBAAoB,EAAE;QACpB,WAAW,EAAE,8DAA8D;QAC3E,UAAU,EAAE,qBAAqB;KAClC;IACD,6BAA6B,EAAE;QAC7B,WAAW,EAAE,gFAAgF;QAC7F,UAAU,EAAE,YAAY;KACzB;IACD,0BAA0B,EAAE;QAC1B,WAAW,EAAE,gFAAgF;QAC7F,UAAU,EAAE,YAAY;KACzB;IACD,oCAAoC,EAAE;QACpC,WAAW,EAAE,gFAAgF;QAC7F,UAAU,EAAE,eAAe;KAC5B;IACD,yBAAyB,EAAE;QACzB,WAAW,EAAE,8DAA8D;QAC3E,UAAU,EAAE,qBAAqB;KAClC;IACD,qBAAqB,EAAE;QACrB,WAAW,EAAE,8DAA8D;QAC3E,UAAU,EAAE,qBAAqB;KAClC;CACO,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SLAPolicy — service-level agreement with auto-credit / auto-refund / escalate
|
|
3
|
+
* on breach. The SaS book's "outcome-pricing requires you to stand behind quality"
|
|
4
|
+
* substrate.
|
|
5
|
+
*/
|
|
6
|
+
export interface SLATarget {
|
|
7
|
+
metric: 'latency-ms' | 'accuracy' | 'on-time' | 'completeness' | 'first-contact-resolution' | 'csat' | string;
|
|
8
|
+
/** Threshold value or expression (e.g. 'day-5', 0.95, 1000). */
|
|
9
|
+
threshold: number | string;
|
|
10
|
+
}
|
|
11
|
+
export interface SLAPolicy {
|
|
12
|
+
$id: string;
|
|
13
|
+
$type: 'SLAPolicy';
|
|
14
|
+
serviceRef: string;
|
|
15
|
+
targets: SLATarget[];
|
|
16
|
+
onBreach: {
|
|
17
|
+
/** Percent of charge to credit back (0-100). */
|
|
18
|
+
creditPercent?: number;
|
|
19
|
+
/** Percent of charge to refund (0-100). */
|
|
20
|
+
refundPercent?: number;
|
|
21
|
+
/** Worker (Person/Agent/Role) to escalate to. */
|
|
22
|
+
escalateTo?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=sla.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sla.d.ts","sourceRoot":"","sources":["../../src/finance/sla.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,SAAS;IACxB,MAAM,EACF,YAAY,GACZ,UAAU,GACV,SAAS,GACT,cAAc,GACd,0BAA0B,GAC1B,MAAM,GACN,MAAM,CAAA;IACV,gEAAgE;IAChE,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,WAAW,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,SAAS,EAAE,CAAA;IACpB,QAAQ,EAAE;QACR,gDAAgD;QAChD,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,2CAA2C;QAC3C,aAAa,CAAC,EAAE,MAAM,CAAA;QACtB,iDAAiD;QACjD,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sla.js","sourceRoot":"","sources":["../../src/finance/sla.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core value types — Money, Cost, Budget, SpendControl, CostModel.
|
|
3
|
+
*
|
|
4
|
+
* Money uses bigint in smallest currency unit (cents/satoshis/wei) for precision.
|
|
5
|
+
* Refs use plain string with brand comment; cross-package nominal types deferred.
|
|
6
|
+
*/
|
|
7
|
+
export type FiatCurrency = 'USD' | 'EUR' | 'GBP' | 'JPY' | 'CAD' | 'AUD' | string;
|
|
8
|
+
export type StablecoinCurrency = 'USDC' | 'PYUSD' | 'USDT' | 'USDG' | 'USDSui' | 'CASH' | string;
|
|
9
|
+
export type CryptoCurrency = 'BTC' | 'ETH' | 'SOL';
|
|
10
|
+
export type Currency = FiatCurrency | StablecoinCurrency | CryptoCurrency;
|
|
11
|
+
export interface Money {
|
|
12
|
+
amount: bigint;
|
|
13
|
+
currency: Currency;
|
|
14
|
+
}
|
|
15
|
+
/** Cost incurred by an Action — every cascade Function call captures one. */
|
|
16
|
+
export interface Cost {
|
|
17
|
+
$id: string;
|
|
18
|
+
$type: 'Cost';
|
|
19
|
+
/** Reference to the underlying Action (digital-objects ActionRef shape). */
|
|
20
|
+
actionRef: string;
|
|
21
|
+
amount: Money;
|
|
22
|
+
/** Provider that incurred the cost: 'openai' | 'anthropic' | 'stripe' | ... */
|
|
23
|
+
provider: string;
|
|
24
|
+
category: 'inference' | 'compute' | 'storage' | 'api' | 'human' | 'rail-fee' | 'other';
|
|
25
|
+
/** ISO-8601 timestamp. */
|
|
26
|
+
capturedAt: string;
|
|
27
|
+
}
|
|
28
|
+
/** Where a Budget applies. */
|
|
29
|
+
export type BudgetScope = {
|
|
30
|
+
kind: 'worker';
|
|
31
|
+
ref: string;
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'function';
|
|
34
|
+
ref: string;
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'goal';
|
|
37
|
+
ref: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: 'experiment';
|
|
40
|
+
ref: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'tenant';
|
|
43
|
+
ref: string;
|
|
44
|
+
};
|
|
45
|
+
export interface Budget {
|
|
46
|
+
$id: string;
|
|
47
|
+
$type: 'Budget';
|
|
48
|
+
scope: BudgetScope;
|
|
49
|
+
cap: Money;
|
|
50
|
+
period: 'daily' | 'weekly' | 'monthly' | 'one-time';
|
|
51
|
+
/** ISO-8601 timestamp; absent for one-time budgets. */
|
|
52
|
+
resetAt?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface SpendControl {
|
|
55
|
+
budgetRef: string;
|
|
56
|
+
/** 0-1 fraction of cap — warn when soft threshold crossed. */
|
|
57
|
+
soft?: number;
|
|
58
|
+
/** 0-1 fraction of cap — block/escalate when hard threshold crossed. */
|
|
59
|
+
hard: number;
|
|
60
|
+
onBreach: 'block' | 'escalate' | 'warn';
|
|
61
|
+
/** Worker to escalate to (Person/Agent/Role); ThingRef shape. */
|
|
62
|
+
escalateTo?: string;
|
|
63
|
+
}
|
|
64
|
+
/** Declared cost model on a Function or Service. */
|
|
65
|
+
export interface CostModel {
|
|
66
|
+
/** Per-invocation flat cost (cents in smallest unit). */
|
|
67
|
+
perInvocation?: bigint;
|
|
68
|
+
/** Per-transaction cost (e.g. per-token, per-row). */
|
|
69
|
+
perTx?: bigint;
|
|
70
|
+
/** Per round of agent execution (e.g. per-dev-agent-round). */
|
|
71
|
+
perAgentRound?: bigint;
|
|
72
|
+
/** Per external API call. */
|
|
73
|
+
perApiCall?: bigint;
|
|
74
|
+
/** Per-symbol or per-unit-of-output. */
|
|
75
|
+
perUnit?: bigint;
|
|
76
|
+
/** Hourly rate for human work. */
|
|
77
|
+
perHour?: bigint;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/finance/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,YA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AAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,QAAQ,CAAA;IACf,KAAK,EAAE,WAAW,CAAA;IAClB,GAAG,EAAE,KAAK,CAAA;IACV,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAA;IACnD,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAA;IACvC,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,sDAAsD;IACtD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,+DAA+D;IAC/D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core value types — Money, Cost, Budget, SpendControl, CostModel.
|
|
3
|
+
*
|
|
4
|
+
* Money uses bigint in smallest currency unit (cents/satoshis/wei) for precision.
|
|
5
|
+
* Refs use plain string with brand comment; cross-package nominal types deferred.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|