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.
Files changed (213) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +43 -0
  3. package/dist/business.d.ts +62 -0
  4. package/dist/business.d.ts.map +1 -0
  5. package/dist/business.js +109 -0
  6. package/dist/business.js.map +1 -0
  7. package/dist/dollar.d.ts +60 -0
  8. package/dist/dollar.d.ts.map +1 -0
  9. package/dist/dollar.js +107 -0
  10. package/dist/dollar.js.map +1 -0
  11. package/dist/entities/assets.d.ts +21 -0
  12. package/dist/entities/assets.d.ts.map +1 -0
  13. package/dist/entities/assets.js +323 -0
  14. package/dist/entities/assets.js.map +1 -0
  15. package/dist/entities/business.d.ts +36 -0
  16. package/dist/entities/business.d.ts.map +1 -0
  17. package/dist/entities/business.js +370 -0
  18. package/dist/entities/business.js.map +1 -0
  19. package/dist/entities/communication.d.ts +21 -0
  20. package/dist/entities/communication.d.ts.map +1 -0
  21. package/dist/entities/communication.js +255 -0
  22. package/dist/entities/communication.js.map +1 -0
  23. package/dist/entities/customers.d.ts +58 -0
  24. package/dist/entities/customers.d.ts.map +1 -0
  25. package/dist/entities/customers.js +989 -0
  26. package/dist/entities/customers.js.map +1 -0
  27. package/dist/entities/financials.d.ts +59 -0
  28. package/dist/entities/financials.d.ts.map +1 -0
  29. package/dist/entities/financials.js +932 -0
  30. package/dist/entities/financials.js.map +1 -0
  31. package/dist/entities/goals.d.ts +58 -0
  32. package/dist/entities/goals.d.ts.map +1 -0
  33. package/dist/entities/goals.js +800 -0
  34. package/dist/entities/goals.js.map +1 -0
  35. package/dist/entities/index.d.ts +299 -0
  36. package/dist/entities/index.d.ts.map +1 -0
  37. package/dist/entities/index.js +198 -0
  38. package/dist/entities/index.js.map +1 -0
  39. package/dist/entities/legal.d.ts +21 -0
  40. package/dist/entities/legal.d.ts.map +1 -0
  41. package/dist/entities/legal.js +301 -0
  42. package/dist/entities/legal.js.map +1 -0
  43. package/dist/entities/market.d.ts +21 -0
  44. package/dist/entities/market.d.ts.map +1 -0
  45. package/dist/entities/market.js +301 -0
  46. package/dist/entities/market.js.map +1 -0
  47. package/dist/entities/marketing.d.ts +67 -0
  48. package/dist/entities/marketing.d.ts.map +1 -0
  49. package/dist/entities/marketing.js +1157 -0
  50. package/dist/entities/marketing.js.map +1 -0
  51. package/dist/entities/offerings.d.ts +51 -0
  52. package/dist/entities/offerings.d.ts.map +1 -0
  53. package/dist/entities/offerings.js +727 -0
  54. package/dist/entities/offerings.js.map +1 -0
  55. package/dist/entities/operations.d.ts +58 -0
  56. package/dist/entities/operations.d.ts.map +1 -0
  57. package/dist/entities/operations.js +787 -0
  58. package/dist/entities/operations.js.map +1 -0
  59. package/dist/entities/organization.d.ts +61 -0
  60. package/dist/entities/organization.d.ts.map +1 -0
  61. package/dist/entities/organization.js +816 -0
  62. package/dist/entities/organization.js.map +1 -0
  63. package/dist/entities/partnerships.d.ts +21 -0
  64. package/dist/entities/partnerships.d.ts.map +1 -0
  65. package/dist/entities/partnerships.js +300 -0
  66. package/dist/entities/partnerships.js.map +1 -0
  67. package/dist/entities/planning.d.ts +87 -0
  68. package/dist/entities/planning.d.ts.map +1 -0
  69. package/dist/entities/planning.js +271 -0
  70. package/dist/entities/planning.js.map +1 -0
  71. package/dist/entities/projects.d.ts +25 -0
  72. package/dist/entities/projects.d.ts.map +1 -0
  73. package/dist/entities/projects.js +349 -0
  74. package/dist/entities/projects.js.map +1 -0
  75. package/dist/entities/risk.d.ts +21 -0
  76. package/dist/entities/risk.d.ts.map +1 -0
  77. package/dist/entities/risk.js +293 -0
  78. package/dist/entities/risk.js.map +1 -0
  79. package/dist/entities/sales.d.ts +72 -0
  80. package/dist/entities/sales.d.ts.map +1 -0
  81. package/dist/entities/sales.js +1248 -0
  82. package/dist/entities/sales.js.map +1 -0
  83. package/dist/finance/account.d.ts +44 -0
  84. package/dist/finance/account.d.ts.map +1 -0
  85. package/dist/finance/account.js +6 -0
  86. package/dist/finance/account.js.map +1 -0
  87. package/dist/finance/authority.d.ts +78 -0
  88. package/dist/finance/authority.d.ts.map +1 -0
  89. package/dist/finance/authority.js +27 -0
  90. package/dist/finance/authority.js.map +1 -0
  91. package/dist/finance/card.d.ts +36 -0
  92. package/dist/finance/card.d.ts.map +1 -0
  93. package/dist/finance/card.js +6 -0
  94. package/dist/finance/card.js.map +1 -0
  95. package/dist/finance/identity.d.ts +30 -0
  96. package/dist/finance/identity.d.ts.map +1 -0
  97. package/dist/finance/identity.js +8 -0
  98. package/dist/finance/identity.js.map +1 -0
  99. package/dist/finance/index.d.ts +36 -0
  100. package/dist/finance/index.d.ts.map +1 -0
  101. package/dist/finance/index.js +22 -0
  102. package/dist/finance/index.js.map +1 -0
  103. package/dist/finance/ledger.d.ts +24 -0
  104. package/dist/finance/ledger.d.ts.map +1 -0
  105. package/dist/finance/ledger.js +8 -0
  106. package/dist/finance/ledger.js.map +1 -0
  107. package/dist/finance/merchant.d.ts +129 -0
  108. package/dist/finance/merchant.d.ts.map +1 -0
  109. package/dist/finance/merchant.js +21 -0
  110. package/dist/finance/merchant.js.map +1 -0
  111. package/dist/finance/outcome-contract.d.ts +139 -0
  112. package/dist/finance/outcome-contract.d.ts.map +1 -0
  113. package/dist/finance/outcome-contract.js +27 -0
  114. package/dist/finance/outcome-contract.js.map +1 -0
  115. package/dist/finance/port.d.ts +121 -0
  116. package/dist/finance/port.d.ts.map +1 -0
  117. package/dist/finance/port.js +10 -0
  118. package/dist/finance/port.js.map +1 -0
  119. package/dist/finance/pricing.d.ts +154 -0
  120. package/dist/finance/pricing.d.ts.map +1 -0
  121. package/dist/finance/pricing.js +79 -0
  122. package/dist/finance/pricing.js.map +1 -0
  123. package/dist/finance/proof-predicate.d.ts +92 -0
  124. package/dist/finance/proof-predicate.d.ts.map +1 -0
  125. package/dist/finance/proof-predicate.js +80 -0
  126. package/dist/finance/proof-predicate.js.map +1 -0
  127. package/dist/finance/refund.d.ts +44 -0
  128. package/dist/finance/refund.d.ts.map +1 -0
  129. package/dist/finance/refund.js +41 -0
  130. package/dist/finance/refund.js.map +1 -0
  131. package/dist/finance/sla.d.ts +25 -0
  132. package/dist/finance/sla.d.ts.map +1 -0
  133. package/dist/finance/sla.js +7 -0
  134. package/dist/finance/sla.js.map +1 -0
  135. package/dist/finance/types.d.ts +79 -0
  136. package/dist/finance/types.d.ts.map +1 -0
  137. package/dist/finance/types.js +8 -0
  138. package/dist/finance/types.js.map +1 -0
  139. package/dist/financials.d.ts +130 -0
  140. package/dist/financials.d.ts.map +1 -0
  141. package/dist/financials.js +297 -0
  142. package/dist/financials.js.map +1 -0
  143. package/dist/goals.d.ts +106 -0
  144. package/dist/goals.d.ts.map +1 -0
  145. package/dist/goals.js +284 -0
  146. package/dist/goals.js.map +1 -0
  147. package/dist/index.d.ts +101 -0
  148. package/dist/index.d.ts.map +1 -0
  149. package/dist/index.js +144 -0
  150. package/dist/index.js.map +1 -0
  151. package/dist/kpis.d.ts +137 -0
  152. package/dist/kpis.d.ts.map +1 -0
  153. package/dist/kpis.js +297 -0
  154. package/dist/kpis.js.map +1 -0
  155. package/dist/metrics.d.ts +448 -0
  156. package/dist/metrics.d.ts.map +1 -0
  157. package/dist/metrics.js +330 -0
  158. package/dist/metrics.js.map +1 -0
  159. package/dist/okrs.d.ts +157 -0
  160. package/dist/okrs.d.ts.map +1 -0
  161. package/dist/okrs.js +391 -0
  162. package/dist/okrs.js.map +1 -0
  163. package/dist/organization.d.ts +585 -0
  164. package/dist/organization.d.ts.map +1 -0
  165. package/dist/organization.js +173 -0
  166. package/dist/organization.js.map +1 -0
  167. package/dist/process.d.ts +112 -0
  168. package/dist/process.d.ts.map +1 -0
  169. package/dist/process.js +242 -0
  170. package/dist/process.js.map +1 -0
  171. package/dist/product.d.ts +85 -0
  172. package/dist/product.d.ts.map +1 -0
  173. package/dist/product.js +145 -0
  174. package/dist/product.js.map +1 -0
  175. package/dist/queries.d.ts +304 -0
  176. package/dist/queries.d.ts.map +1 -0
  177. package/dist/queries.js +577 -0
  178. package/dist/queries.js.map +1 -0
  179. package/dist/roles.d.ts +334 -0
  180. package/dist/roles.d.ts.map +1 -0
  181. package/dist/roles.js +282 -0
  182. package/dist/roles.js.map +1 -0
  183. package/dist/service.d.ts +61 -0
  184. package/dist/service.d.ts.map +1 -0
  185. package/dist/service.js +140 -0
  186. package/dist/service.js.map +1 -0
  187. package/dist/types.d.ts +459 -0
  188. package/dist/types.d.ts.map +1 -0
  189. package/dist/types.js +5 -0
  190. package/dist/types.js.map +1 -0
  191. package/dist/vision.d.ts +38 -0
  192. package/dist/vision.d.ts.map +1 -0
  193. package/dist/vision.js +68 -0
  194. package/dist/vision.js.map +1 -0
  195. package/dist/workflow.d.ts +115 -0
  196. package/dist/workflow.d.ts.map +1 -0
  197. package/dist/workflow.js +248 -0
  198. package/dist/workflow.js.map +1 -0
  199. package/package.json +8 -4
  200. package/src/finance/account.ts +48 -0
  201. package/src/finance/authority.ts +42 -0
  202. package/src/finance/card.ts +38 -0
  203. package/src/finance/identity.ts +31 -0
  204. package/src/finance/index.ts +117 -0
  205. package/src/finance/ledger.ts +26 -0
  206. package/src/finance/merchant.ts +127 -0
  207. package/src/finance/outcome-contract.ts +157 -0
  208. package/src/finance/port.ts +144 -0
  209. package/src/finance/pricing.ts +197 -0
  210. package/src/finance/proof-predicate.ts +106 -0
  211. package/src/finance/refund.ts +52 -0
  212. package/src/finance/sla.ts +33 -0
  213. package/src/finance/types.ts +75 -0
@@ -0,0 +1,197 @@
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
+
15
+ import type { Currency, Money } from './types.js'
16
+ import type { SLATarget } from './sla.js'
17
+
18
+ export interface OutcomeTier {
19
+ id: string
20
+ amount: bigint
21
+ currency?: Currency
22
+ description?: string
23
+ }
24
+
25
+ export interface PerInvocationTier {
26
+ id: string
27
+ amount: bigint
28
+ /** Number of invocations included before per-tier billing applies. */
29
+ includedPerMonth?: number
30
+ /** Per-invocation overage cost above included. */
31
+ overage?: bigint
32
+ }
33
+
34
+ /**
35
+ * A single metered-billing line item. `description` is genuinely optional —
36
+ * callers may omit it from inline literals AND from the {@link Pricing}
37
+ * factory calls (`Pricing.subscription` / `Pricing.composite`).
38
+ */
39
+ export interface MeteredEntry {
40
+ event: string
41
+ amount: bigint
42
+ description?: string
43
+ }
44
+
45
+ /**
46
+ * Optional one-time base charge on a {@link Pricing.composite} plan. `description`
47
+ * is optional under `exactOptionalPropertyTypes`.
48
+ */
49
+ export interface CompositeBase {
50
+ id: string
51
+ amount: bigint
52
+ description?: string
53
+ }
54
+
55
+ /**
56
+ * Recurring plan portion of a {@link Pricing.subscription}. Shared between the
57
+ * `Pricing` discriminated union and the {@link Pricing.subscription} factory
58
+ * so the two shapes never drift.
59
+ */
60
+ export interface SubscriptionPlan {
61
+ id: string
62
+ amount: bigint
63
+ currency: Currency
64
+ interval: 'day' | 'week' | 'month' | 'quarter' | 'year'
65
+ }
66
+
67
+ /**
68
+ * Standard bases the {@link Pricing.percentOf} runtime knows how to resolve
69
+ * at settlement time. Adapters MAY accept arbitrary basis strings for
70
+ * domain-specific metering, but the canonical four cover the common cases:
71
+ *
72
+ * invoice-amount — face value of an outbound invoice
73
+ * collected-amount — funds actually received (post-settlement)
74
+ * transaction-volume — gross payment volume processed
75
+ * <custom string> — provider-defined; must be resolvable in the
76
+ * metering runtime
77
+ */
78
+ export type PercentOfBasis =
79
+ | 'invoice-amount'
80
+ | 'collected-amount'
81
+ | 'transaction-volume'
82
+ | (string & {})
83
+
84
+ export type Pricing =
85
+ | {
86
+ kind: 'outcome'
87
+ tiers: OutcomeTier[]
88
+ sla?: SLATarget
89
+ }
90
+ | {
91
+ kind: 'subscription'
92
+ plan: SubscriptionPlan
93
+ metered?: MeteredEntry[]
94
+ sla?: SLATarget
95
+ }
96
+ | {
97
+ kind: 'per-invocation'
98
+ tiers: PerInvocationTier[]
99
+ }
100
+ | {
101
+ kind: 'composite'
102
+ base: CompositeBase
103
+ metered: MeteredEntry[]
104
+ }
105
+ | {
106
+ kind: 'percent-of'
107
+ basis: PercentOfBasis
108
+ /**
109
+ * Rate in basis points (1/100ths of a percent). Examples: `200` = 2%,
110
+ * `75` = 0.75%, `1000` = 10%.
111
+ *
112
+ * The metering runtime computes the charge as
113
+ * `(realised_basis * rateBasisPoints) / 10000`, then clamps the
114
+ * result by the optional `cap` / `floor` (when present).
115
+ */
116
+ rateBasisPoints: number
117
+ /** Optional upper bound on the per-event charge. */
118
+ cap?: Money
119
+ /** Optional lower bound on the per-event charge. */
120
+ floor?: Money
121
+ }
122
+
123
+ export const Pricing = {
124
+ outcome(opts: { tiers: OutcomeTier[]; sla?: SLATarget }): Pricing {
125
+ if (opts.sla !== undefined) {
126
+ return { kind: 'outcome', tiers: opts.tiers, sla: opts.sla }
127
+ }
128
+ return { kind: 'outcome', tiers: opts.tiers }
129
+ },
130
+
131
+ subscription(opts: {
132
+ plan: SubscriptionPlan
133
+ metered?: MeteredEntry[]
134
+ sla?: SLATarget
135
+ }): Pricing {
136
+ const result: Extract<Pricing, { kind: 'subscription' }> = {
137
+ kind: 'subscription',
138
+ plan: opts.plan,
139
+ }
140
+ if (opts.metered !== undefined) result.metered = opts.metered
141
+ if (opts.sla !== undefined) result.sla = opts.sla
142
+ return result
143
+ },
144
+
145
+ perInvocation(opts: { tiers: PerInvocationTier[] }): Pricing {
146
+ return { kind: 'per-invocation', tiers: opts.tiers }
147
+ },
148
+
149
+ composite(opts: { base: CompositeBase; metered: MeteredEntry[] }): Pricing {
150
+ return { kind: 'composite', base: opts.base, metered: opts.metered }
151
+ },
152
+
153
+ /**
154
+ * Percent-of-basis pricing — proportional charge against a realised
155
+ * basis (e.g. invoice amount, collected amount, transaction volume).
156
+ *
157
+ * The metering runtime resolves `basis` to a concrete bigint at
158
+ * settlement time, then computes the charge as
159
+ * `(realised_basis * rateBasisPoints) / 10000`, optionally clamped by
160
+ * `cap` / `floor`.
161
+ *
162
+ * @example AR Service: 2% of collected funds
163
+ * ```ts
164
+ * Pricing.percentOf({ basis: 'collected-amount', rateBasisPoints: 200 })
165
+ * ```
166
+ *
167
+ * @example Capped: 0.75% of transaction volume, max $50/event
168
+ * ```ts
169
+ * Pricing.percentOf({
170
+ * basis: 'transaction-volume',
171
+ * rateBasisPoints: 75,
172
+ * cap: { amount: 5000n, currency: 'USD' },
173
+ * })
174
+ * ```
175
+ */
176
+ percentOf(opts: {
177
+ basis: PercentOfBasis
178
+ rateBasisPoints: number
179
+ cap?: Money
180
+ floor?: Money
181
+ }): Pricing {
182
+ const result: Extract<Pricing, { kind: 'percent-of' }> = {
183
+ kind: 'percent-of',
184
+ basis: opts.basis,
185
+ rateBasisPoints: opts.rateBasisPoints,
186
+ }
187
+ if (opts.cap !== undefined) result.cap = opts.cap
188
+ if (opts.floor !== undefined) result.floor = opts.floor
189
+ return result
190
+ },
191
+ }
192
+
193
+ /** Convenience: build a Money value from a bigint + currency. */
194
+ export const money = (amount: bigint, currency: Currency = 'USD'): Money => ({
195
+ amount,
196
+ currency,
197
+ })
@@ -0,0 +1,106 @@
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
+
20
+ export type ProofPredicate =
21
+ | { kind: 'schema-match'; schema: unknown }
22
+ | {
23
+ kind: 'evaluator-pass'
24
+ panelRef: string | 'self'
25
+ minScore: number | 'all-approved' | 'majority'
26
+ }
27
+ | { kind: 'human-sign'; signerRoles: string[]; when?: string }
28
+ | { kind: 'external'; verifier: string; spec: unknown }
29
+ | { kind: 'load-bearing-pass'; itemSet: string[] }
30
+ | { kind: 'overall-floor'; minPasses: number; outOfTotal: number }
31
+ | { kind: 'unmet-requirements-pass'; categories?: string[] }
32
+ | { kind: 'and'; predicates: ProofPredicate[] }
33
+ | { kind: 'or'; predicates: ProofPredicate[] }
34
+
35
+ export const SchemaMatch = (schema: unknown): ProofPredicate => ({
36
+ kind: 'schema-match',
37
+ schema,
38
+ })
39
+
40
+ export const EvaluatorPass = (opts: {
41
+ panelRef: string | 'self'
42
+ minScore: number | 'all-approved' | 'majority'
43
+ }): ProofPredicate => ({
44
+ kind: 'evaluator-pass',
45
+ panelRef: opts.panelRef,
46
+ minScore: opts.minScore,
47
+ })
48
+
49
+ export const HumanSign = (opts: { signerRoles: string[]; when?: string }): ProofPredicate => {
50
+ if (opts.when !== undefined) {
51
+ return { kind: 'human-sign', signerRoles: opts.signerRoles, when: opts.when }
52
+ }
53
+ return { kind: 'human-sign', signerRoles: opts.signerRoles }
54
+ }
55
+
56
+ export const External = (opts: { verifier: string; spec: unknown }): ProofPredicate => ({
57
+ kind: 'external',
58
+ verifier: opts.verifier,
59
+ spec: opts.spec,
60
+ })
61
+
62
+ export const LoadBearingPass = (itemSet: string[]): ProofPredicate => ({
63
+ kind: 'load-bearing-pass',
64
+ itemSet,
65
+ })
66
+
67
+ export const OverallFloor = (opts: { minPasses: number; outOfTotal: number }): ProofPredicate => ({
68
+ kind: 'overall-floor',
69
+ minPasses: opts.minPasses,
70
+ outOfTotal: opts.outOfTotal,
71
+ })
72
+
73
+ /**
74
+ * `UnmetRequirementsPass` — sb-n7d's open-blocking gate as a first-class
75
+ * predicate.
76
+ *
77
+ * Passes iff no `severity: 'blocking'` UnmetRequirement is present in the
78
+ * verify-time evaluation context. `severity: 'warning'` items are ignored.
79
+ *
80
+ * When `categories` is supplied, only requirements whose `category` matches
81
+ * one of the listed values are considered (others are ignored regardless of
82
+ * severity). When omitted, ALL categories are inspected.
83
+ *
84
+ * @example
85
+ * // Any blocking unmet requirement fails the predicate.
86
+ * UnmetRequirementsPass()
87
+ *
88
+ * // Only blocking items in the 'compliance' or 'security' buckets fail.
89
+ * UnmetRequirementsPass({ categories: ['compliance', 'security'] })
90
+ */
91
+ export const UnmetRequirementsPass = (opts?: { categories?: string[] }): ProofPredicate => {
92
+ if (opts?.categories !== undefined) {
93
+ return { kind: 'unmet-requirements-pass', categories: opts.categories }
94
+ }
95
+ return { kind: 'unmet-requirements-pass' }
96
+ }
97
+
98
+ export const AND = (...predicates: ProofPredicate[]): ProofPredicate => ({
99
+ kind: 'and',
100
+ predicates,
101
+ })
102
+
103
+ export const OR = (...predicates: ProofPredicate[]): ProofPredicate => ({
104
+ kind: 'or',
105
+ predicates,
106
+ })
@@ -0,0 +1,52 @@
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
+ export type RefundContractRef =
9
+ | 'no-charge-if-not-qualified'
10
+ | 'quality-floor-fail'
11
+ | 'sla-credit-on-late-delivery'
12
+ | 'sla-credit-on-late-close'
13
+ | 'partial-credit-on-partial-delivery'
14
+ | 'time-bounded-money-back'
15
+ | 'escalate-to-dispute'
16
+ | (string & { __brand?: 'RefundContractRef' })
17
+
18
+ /**
19
+ * Catalog of canonical refund contracts. Consumers reference by id; substrate
20
+ * resolves the contract semantics at settlement time.
21
+ */
22
+ export const RefundContracts = {
23
+ 'no-charge-if-not-qualified': {
24
+ description:
25
+ 'No charge unless EvaluatorPass + downstream verification confirms work delivered.',
26
+ triggersAt: 'pre-charge',
27
+ },
28
+ 'quality-floor-fail': {
29
+ description: 'Full refund when EvaluatorPanel rejects below quality floor.',
30
+ triggersAt: 'post-quality-review',
31
+ },
32
+ 'sla-credit-on-late-delivery': {
33
+ description: 'Credit equal to N% of invoice when delivery exceeds OutcomeContract.expiresAt.',
34
+ triggersAt: 'on-timeout',
35
+ },
36
+ 'sla-credit-on-late-close': {
37
+ description: 'Credit on monthly subscription when SLA target (e.g. close-by-day-5) breached.',
38
+ triggersAt: 'sla-breach',
39
+ },
40
+ 'partial-credit-on-partial-delivery': {
41
+ description: 'Pro-rata credit when fraction of work-units delivered (e.g. tickets resolved).',
42
+ triggersAt: 'post-delivery',
43
+ },
44
+ 'time-bounded-money-back': {
45
+ description: 'Full refund within N days of acceptance, no questions asked.',
46
+ triggersAt: 'on-customer-request',
47
+ },
48
+ 'escalate-to-dispute': {
49
+ description: 'Route to ESCALATED_TO_HUMAN_REVIEW state; manual resolution.',
50
+ triggersAt: 'on-customer-dispute',
51
+ },
52
+ } as const
@@ -0,0 +1,33 @@
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
+
7
+ export interface SLATarget {
8
+ metric:
9
+ | 'latency-ms'
10
+ | 'accuracy'
11
+ | 'on-time'
12
+ | 'completeness'
13
+ | 'first-contact-resolution'
14
+ | 'csat'
15
+ | string
16
+ /** Threshold value or expression (e.g. 'day-5', 0.95, 1000). */
17
+ threshold: number | string
18
+ }
19
+
20
+ export interface SLAPolicy {
21
+ $id: string
22
+ $type: 'SLAPolicy'
23
+ serviceRef: string
24
+ targets: SLATarget[]
25
+ onBreach: {
26
+ /** Percent of charge to credit back (0-100). */
27
+ creditPercent?: number
28
+ /** Percent of charge to refund (0-100). */
29
+ refundPercent?: number
30
+ /** Worker (Person/Agent/Role) to escalate to. */
31
+ escalateTo?: string
32
+ }
33
+ }
@@ -0,0 +1,75 @@
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
+
8
+ export type FiatCurrency = 'USD' | 'EUR' | 'GBP' | 'JPY' | 'CAD' | 'AUD' | string
9
+ export type StablecoinCurrency = 'USDC' | 'PYUSD' | 'USDT' | 'USDG' | 'USDSui' | 'CASH' | string
10
+ export type CryptoCurrency = 'BTC' | 'ETH' | 'SOL'
11
+ export type Currency = FiatCurrency | StablecoinCurrency | CryptoCurrency
12
+
13
+ export interface Money {
14
+ amount: bigint
15
+ currency: Currency
16
+ }
17
+
18
+ /** Cost incurred by an Action — every cascade Function call captures one. */
19
+ export interface Cost {
20
+ $id: string
21
+ $type: 'Cost'
22
+ /** Reference to the underlying Action (digital-objects ActionRef shape). */
23
+ actionRef: string
24
+ amount: Money
25
+ /** Provider that incurred the cost: 'openai' | 'anthropic' | 'stripe' | ... */
26
+ provider: string
27
+ category: 'inference' | 'compute' | 'storage' | 'api' | 'human' | 'rail-fee' | 'other'
28
+ /** ISO-8601 timestamp. */
29
+ capturedAt: string
30
+ }
31
+
32
+ /** Where a Budget applies. */
33
+ export type BudgetScope =
34
+ | { kind: 'worker'; ref: string }
35
+ | { kind: 'function'; ref: string }
36
+ | { kind: 'goal'; ref: string }
37
+ | { kind: 'experiment'; ref: string }
38
+ | { kind: 'tenant'; ref: string }
39
+
40
+ export interface Budget {
41
+ $id: string
42
+ $type: 'Budget'
43
+ scope: BudgetScope
44
+ cap: Money
45
+ period: 'daily' | 'weekly' | 'monthly' | 'one-time'
46
+ /** ISO-8601 timestamp; absent for one-time budgets. */
47
+ resetAt?: string
48
+ }
49
+
50
+ export interface SpendControl {
51
+ budgetRef: string
52
+ /** 0-1 fraction of cap — warn when soft threshold crossed. */
53
+ soft?: number
54
+ /** 0-1 fraction of cap — block/escalate when hard threshold crossed. */
55
+ hard: number
56
+ onBreach: 'block' | 'escalate' | 'warn'
57
+ /** Worker to escalate to (Person/Agent/Role); ThingRef shape. */
58
+ escalateTo?: string
59
+ }
60
+
61
+ /** Declared cost model on a Function or Service. */
62
+ export interface CostModel {
63
+ /** Per-invocation flat cost (cents in smallest unit). */
64
+ perInvocation?: bigint
65
+ /** Per-transaction cost (e.g. per-token, per-row). */
66
+ perTx?: bigint
67
+ /** Per round of agent execution (e.g. per-dev-agent-round). */
68
+ perAgentRound?: bigint
69
+ /** Per external API call. */
70
+ perApiCall?: bigint
71
+ /** Per-symbol or per-unit-of-output. */
72
+ perUnit?: bigint
73
+ /** Hourly rate for human work. */
74
+ perHour?: bigint
75
+ }