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.
Files changed (235) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/CHANGELOG.md +53 -0
  3. package/README.md +2 -0
  4. package/dist/dollar.d.ts.map +1 -1
  5. package/dist/dollar.js +2 -2
  6. package/dist/dollar.js.map +1 -1
  7. package/dist/entities/organization.d.ts +4 -0
  8. package/dist/entities/organization.d.ts.map +1 -1
  9. package/dist/entities/organization.js +27 -18
  10. package/dist/entities/organization.js.map +1 -1
  11. package/dist/entities/planning.d.ts +87 -0
  12. package/dist/finance/account.d.ts +44 -0
  13. package/dist/finance/account.d.ts.map +1 -0
  14. package/dist/finance/account.js +6 -0
  15. package/dist/finance/account.js.map +1 -0
  16. package/dist/finance/authority.d.ts +78 -0
  17. package/dist/finance/authority.d.ts.map +1 -0
  18. package/dist/finance/authority.js +27 -0
  19. package/dist/finance/authority.js.map +1 -0
  20. package/dist/finance/card.d.ts +36 -0
  21. package/dist/finance/card.d.ts.map +1 -0
  22. package/dist/finance/card.js +6 -0
  23. package/dist/finance/card.js.map +1 -0
  24. package/dist/finance/identity.d.ts +30 -0
  25. package/dist/finance/identity.d.ts.map +1 -0
  26. package/dist/finance/identity.js +8 -0
  27. package/dist/finance/identity.js.map +1 -0
  28. package/dist/finance/index.d.ts +36 -0
  29. package/dist/finance/index.d.ts.map +1 -0
  30. package/dist/finance/index.js +22 -0
  31. package/dist/finance/index.js.map +1 -0
  32. package/dist/finance/ledger.d.ts +24 -0
  33. package/dist/finance/ledger.d.ts.map +1 -0
  34. package/dist/finance/ledger.js +8 -0
  35. package/dist/finance/ledger.js.map +1 -0
  36. package/dist/finance/merchant.d.ts +129 -0
  37. package/dist/finance/merchant.d.ts.map +1 -0
  38. package/dist/finance/merchant.js +21 -0
  39. package/dist/finance/merchant.js.map +1 -0
  40. package/dist/finance/outcome-contract.d.ts +139 -0
  41. package/dist/finance/outcome-contract.d.ts.map +1 -0
  42. package/dist/finance/outcome-contract.js +27 -0
  43. package/dist/finance/outcome-contract.js.map +1 -0
  44. package/dist/finance/port.d.ts +121 -0
  45. package/dist/finance/port.d.ts.map +1 -0
  46. package/dist/finance/port.js +10 -0
  47. package/dist/finance/port.js.map +1 -0
  48. package/dist/finance/pricing.d.ts +154 -0
  49. package/dist/finance/pricing.d.ts.map +1 -0
  50. package/dist/finance/pricing.js +79 -0
  51. package/dist/finance/pricing.js.map +1 -0
  52. package/dist/finance/proof-predicate.d.ts +92 -0
  53. package/dist/finance/proof-predicate.d.ts.map +1 -0
  54. package/dist/finance/proof-predicate.js +80 -0
  55. package/dist/finance/proof-predicate.js.map +1 -0
  56. package/dist/finance/refund.d.ts +44 -0
  57. package/dist/finance/refund.d.ts.map +1 -0
  58. package/dist/finance/refund.js +41 -0
  59. package/dist/finance/refund.js.map +1 -0
  60. package/dist/finance/sla.d.ts +25 -0
  61. package/dist/finance/sla.d.ts.map +1 -0
  62. package/dist/finance/sla.js +7 -0
  63. package/dist/finance/sla.js.map +1 -0
  64. package/dist/finance/types.d.ts +79 -0
  65. package/dist/finance/types.d.ts.map +1 -0
  66. package/dist/finance/types.js +8 -0
  67. package/dist/{canvas → finance}/types.js.map +1 -1
  68. package/dist/goals.d.ts +19 -0
  69. package/dist/goals.d.ts.map +1 -1
  70. package/dist/goals.js +81 -12
  71. package/dist/goals.js.map +1 -1
  72. package/dist/index.d.ts +12 -8
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +19 -7
  75. package/dist/index.js.map +1 -1
  76. package/dist/kpis.d.ts +19 -0
  77. package/dist/kpis.d.ts.map +1 -1
  78. package/dist/kpis.js +71 -6
  79. package/dist/kpis.js.map +1 -1
  80. package/dist/metrics.d.ts.map +1 -1
  81. package/dist/metrics.js +29 -24
  82. package/dist/metrics.js.map +1 -1
  83. package/dist/okrs.d.ts +34 -0
  84. package/dist/okrs.d.ts.map +1 -1
  85. package/dist/okrs.js +135 -13
  86. package/dist/okrs.js.map +1 -1
  87. package/dist/organization.d.ts.map +1 -1
  88. package/dist/organization.js +11 -11
  89. package/dist/organization.js.map +1 -1
  90. package/dist/process.d.ts.map +1 -1
  91. package/dist/process.js +13 -12
  92. package/dist/process.js.map +1 -1
  93. package/dist/product.d.ts.map +1 -1
  94. package/dist/product.js +9 -9
  95. package/dist/product.js.map +1 -1
  96. package/dist/queries.d.ts.map +1 -1
  97. package/dist/queries.js +194 -32
  98. package/dist/queries.js.map +1 -1
  99. package/dist/roles.d.ts +25 -31
  100. package/dist/roles.d.ts.map +1 -1
  101. package/dist/roles.js +37 -10
  102. package/dist/roles.js.map +1 -1
  103. package/dist/workflow.d.ts.map +1 -1
  104. package/dist/workflow.js +13 -12
  105. package/dist/workflow.js.map +1 -1
  106. package/package.json +20 -13
  107. package/src/dollar.ts +5 -2
  108. package/src/entities/organization.ts +31 -18
  109. package/src/finance/account.ts +48 -0
  110. package/src/finance/authority.ts +42 -0
  111. package/src/finance/card.ts +38 -0
  112. package/src/finance/identity.ts +31 -0
  113. package/src/finance/index.ts +117 -0
  114. package/src/finance/ledger.ts +26 -0
  115. package/src/finance/merchant.ts +127 -0
  116. package/src/finance/outcome-contract.ts +157 -0
  117. package/src/finance/port.ts +144 -0
  118. package/src/finance/pricing.ts +197 -0
  119. package/src/finance/proof-predicate.ts +106 -0
  120. package/src/finance/refund.ts +52 -0
  121. package/src/finance/sla.ts +33 -0
  122. package/src/finance/types.ts +75 -0
  123. package/src/goals.ts +78 -12
  124. package/src/index.ts +48 -18
  125. package/src/kpis.ts +62 -8
  126. package/src/metrics.ts +92 -79
  127. package/src/okrs.ts +120 -20
  128. package/src/organization.ts +12 -15
  129. package/src/process.ts +11 -12
  130. package/src/product.ts +8 -9
  131. package/src/queries.ts +238 -75
  132. package/src/roles.ts +62 -61
  133. package/src/workflow.ts +22 -15
  134. package/test/business.test.ts +282 -0
  135. package/test/dollar.test.ts +270 -0
  136. package/test/entities.test.ts +628 -0
  137. package/test/financials.test.ts +539 -0
  138. package/test/goals.test.ts +451 -0
  139. package/{src → test}/index.test.ts +1 -1
  140. package/test/kpis.test.ts +440 -0
  141. package/test/metrics.test.ts +744 -0
  142. package/test/okrs.test.ts +741 -0
  143. package/test/organization.test.ts +548 -0
  144. package/test/process.test.ts +503 -0
  145. package/test/product.test.ts +430 -0
  146. package/test/queries.test.ts +556 -0
  147. package/test/roles.test.ts +546 -0
  148. package/test/service.test.ts +450 -0
  149. package/test/types.test.ts +1141 -0
  150. package/test/vision.test.ts +214 -0
  151. package/test/workflow.test.ts +501 -0
  152. package/vitest.config.ts +47 -0
  153. package/LICENSE +0 -21
  154. package/dist/canvas/activities.d.ts +0 -19
  155. package/dist/canvas/activities.d.ts.map +0 -1
  156. package/dist/canvas/activities.js +0 -20
  157. package/dist/canvas/activities.js.map +0 -1
  158. package/dist/canvas/channels.d.ts +0 -20
  159. package/dist/canvas/channels.d.ts.map +0 -1
  160. package/dist/canvas/channels.js +0 -21
  161. package/dist/canvas/channels.js.map +0 -1
  162. package/dist/canvas/relationships.d.ts +0 -20
  163. package/dist/canvas/relationships.d.ts.map +0 -1
  164. package/dist/canvas/relationships.js +0 -21
  165. package/dist/canvas/relationships.js.map +0 -1
  166. package/dist/canvas/resources.d.ts +0 -20
  167. package/dist/canvas/resources.d.ts.map +0 -1
  168. package/dist/canvas/resources.js +0 -30
  169. package/dist/canvas/resources.js.map +0 -1
  170. package/dist/canvas/revenue.d.ts +0 -22
  171. package/dist/canvas/revenue.d.ts.map +0 -1
  172. package/dist/canvas/revenue.js +0 -30
  173. package/dist/canvas/revenue.js.map +0 -1
  174. package/dist/canvas/segments.d.ts +0 -20
  175. package/dist/canvas/segments.d.ts.map +0 -1
  176. package/dist/canvas/segments.js +0 -28
  177. package/dist/canvas/segments.js.map +0 -1
  178. package/dist/canvas/types.d.ts +0 -232
  179. package/dist/canvas/types.d.ts.map +0 -1
  180. package/dist/canvas/types.js +0 -8
  181. package/dist/canvas/value.d.ts +0 -20
  182. package/dist/canvas/value.d.ts.map +0 -1
  183. package/dist/canvas/value.js +0 -21
  184. package/dist/canvas/value.js.map +0 -1
  185. package/src/business.js +0 -108
  186. package/src/canvas/activities.ts +0 -32
  187. package/src/canvas/canvas.ts +0 -482
  188. package/src/canvas/channels.ts +0 -34
  189. package/src/canvas/costs.ts +0 -43
  190. package/src/canvas/economics.ts +0 -99
  191. package/src/canvas/index.ts +0 -206
  192. package/src/canvas/partnerships.ts +0 -34
  193. package/src/canvas/projections.ts +0 -141
  194. package/src/canvas/relationships.ts +0 -34
  195. package/src/canvas/resources.ts +0 -43
  196. package/src/canvas/revenue.ts +0 -56
  197. package/src/canvas/segments.ts +0 -42
  198. package/src/canvas/types.ts +0 -363
  199. package/src/canvas/value.ts +0 -34
  200. package/src/dollar.js +0 -106
  201. package/src/entities/assets.js +0 -322
  202. package/src/entities/business.js +0 -369
  203. package/src/entities/communication.js +0 -254
  204. package/src/entities/customers.js +0 -988
  205. package/src/entities/financials.js +0 -931
  206. package/src/entities/goals.js +0 -799
  207. package/src/entities/index.js +0 -197
  208. package/src/entities/legal.js +0 -300
  209. package/src/entities/market.js +0 -300
  210. package/src/entities/marketing.js +0 -1156
  211. package/src/entities/offerings.js +0 -726
  212. package/src/entities/operations.js +0 -786
  213. package/src/entities/organization.js +0 -806
  214. package/src/entities/partnerships.js +0 -299
  215. package/src/entities/planning.js +0 -270
  216. package/src/entities/projects.js +0 -348
  217. package/src/entities/risk.js +0 -292
  218. package/src/entities/sales.js +0 -1247
  219. package/src/financials.js +0 -296
  220. package/src/goals.js +0 -214
  221. package/src/index.js +0 -131
  222. package/src/index.test.js +0 -274
  223. package/src/kpis.js +0 -231
  224. package/src/metrics.js +0 -324
  225. package/src/okrs.js +0 -268
  226. package/src/organization.js +0 -172
  227. package/src/process.js +0 -240
  228. package/src/product.js +0 -144
  229. package/src/queries.js +0 -414
  230. package/src/roles.js +0 -254
  231. package/src/service.js +0 -139
  232. package/src/types.js +0 -4
  233. package/src/vision.js +0 -67
  234. package/src/workflow.js +0 -246
  235. package/tests/canvas.test.ts +0 -842
@@ -0,0 +1,36 @@
1
+ /**
2
+ * business-as-code/finance — the outcome-contract economic substrate.
3
+ *
4
+ * Source of truth for the economic primitives of the agentic economy:
5
+ * Money/Cost/Budget value types, Account/Card/Ledger/Identity payment types,
6
+ * Pricing, OutcomeContract, ProofPredicate, SLAPolicy, RefundContract,
7
+ * AuthorityBoundary, and the FinanceProvider/Merchant ports.
8
+ *
9
+ * Finance is foundational here because it is the core of the default OKRs
10
+ * (Revenue / Growth / Profit). `services-as-software` and `digital-tools`
11
+ * consume these primitives directly from here.
12
+ *
13
+ * Importable via the `business-as-code/finance` subpath export.
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ export type { FiatCurrency, StablecoinCurrency, CryptoCurrency, Currency, Money, Cost, Budget, BudgetScope, SpendControl, CostModel, } from './types.js';
18
+ export type { Account, AccountSpec, TransferOpts, TransferResult } from './account.js';
19
+ export type { Card, CardSpec } from './card.js';
20
+ export type { LedgerEntry, LedgerLine } from './ledger.js';
21
+ export type { AgentIdentity, AgentMerchant } from './identity.js';
22
+ export type { ProofPredicate } from './proof-predicate.js';
23
+ export { SchemaMatch, EvaluatorPass, HumanSign, External, LoadBearingPass, OverallFloor, UnmetRequirementsPass, AND, OR, } from './proof-predicate.js';
24
+ export type { OutcomeContract, OutcomeContractBase, OutcomeContractWithExpiresAt, OutcomeContractWithTimeoutDays, OutcomeContractWithTiers, ProofOfResult, } from './outcome-contract.js';
25
+ export { resolveOutcomeAmount } from './outcome-contract.js';
26
+ export type { SLAPolicy, SLATarget } from './sla.js';
27
+ export type { RefundContractRef } from './refund.js';
28
+ export { RefundContracts } from './refund.js';
29
+ export type { AuthorityBoundaryRef } from './authority.js';
30
+ export { AuthorityBoundaries } from './authority.js';
31
+ export type { OutcomeTier, PerInvocationTier, MeteredEntry, CompositeBase, SubscriptionPlan, PercentOfBasis, } from './pricing.js';
32
+ export { Pricing, money } from './pricing.js';
33
+ export type { Pricing as PricingValue } from './pricing.js';
34
+ export type { FinanceProvider, ProviderCapabilities, ProviderRail, ChargeOpts, ChargeResult, RefundResult, EscrowHandle, ReleaseResult, SubscribeOpts, Subscription, MeterEvent, } from './port.js';
35
+ export type { MerchantCapable, PriceInterval, ProvisionProductOpts, ProvisionedProduct, CheckoutOpts, CheckoutSession, PayoutOpts, PayoutResult, } from './merchant.js';
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/finance/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,MAAM,EACN,WAAW,EACX,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAA;AAGnB,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAGtF,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAG/C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG1D,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAGjE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,GAAG,EACH,EAAE,GACH,MAAM,sBAAsB,CAAA;AAG7B,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,4BAA4B,EAC5B,8BAA8B,EAC9B,wBAAwB,EACxB,aAAa,GACd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAG5D,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpD,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,YAAY,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAGpD,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAC7C,YAAY,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAA;AAG3D,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,aAAa,EACb,YAAY,EACZ,UAAU,GACX,MAAM,WAAW,CAAA;AAGlB,YAAY,EACV,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,YAAY,GACb,MAAM,eAAe,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * business-as-code/finance — the outcome-contract economic substrate.
3
+ *
4
+ * Source of truth for the economic primitives of the agentic economy:
5
+ * Money/Cost/Budget value types, Account/Card/Ledger/Identity payment types,
6
+ * Pricing, OutcomeContract, ProofPredicate, SLAPolicy, RefundContract,
7
+ * AuthorityBoundary, and the FinanceProvider/Merchant ports.
8
+ *
9
+ * Finance is foundational here because it is the core of the default OKRs
10
+ * (Revenue / Growth / Profit). `services-as-software` and `digital-tools`
11
+ * consume these primitives directly from here.
12
+ *
13
+ * Importable via the `business-as-code/finance` subpath export.
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ export { SchemaMatch, EvaluatorPass, HumanSign, External, LoadBearingPass, OverallFloor, UnmetRequirementsPass, AND, OR, } from './proof-predicate.js';
18
+ export { resolveOutcomeAmount } from './outcome-contract.js';
19
+ export { RefundContracts } from './refund.js';
20
+ export { AuthorityBoundaries } from './authority.js';
21
+ export { Pricing, money } from './pricing.js';
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/finance/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA8BH,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EACT,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,qBAAqB,EACrB,GAAG,EACH,EAAE,GACH,MAAM,sBAAsB,CAAA;AAW7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAO5D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAI7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAWpD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * LedgerEntry — double-entry record. Every entry IS an Action under the SVO substrate.
3
+ *
4
+ * Invariant: per-currency, sum(debits.amount) === sum(credits.amount).
5
+ * The ledger is append-only; reversals are new entries with opposite sign.
6
+ */
7
+ import type { Money } from './types.js';
8
+ export interface LedgerEntry {
9
+ $id: string;
10
+ $type: 'LedgerEntry';
11
+ /** Reference to the underlying Action (digital-objects ActionRef shape). */
12
+ actionRef: string;
13
+ debits: LedgerLine[];
14
+ credits: LedgerLine[];
15
+ /** Optional human-readable memo. */
16
+ memo?: string;
17
+ /** ISO-8601 timestamp. */
18
+ postedAt: string;
19
+ }
20
+ export interface LedgerLine {
21
+ accountRef: string;
22
+ amount: Money;
23
+ }
24
+ //# sourceMappingURL=ledger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/finance/ledger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,aAAa,CAAA;IACpB,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,UAAU,EAAE,CAAA;IACpB,OAAO,EAAE,UAAU,EAAE,CAAA;IACrB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,KAAK,CAAA;CACd"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * LedgerEntry — double-entry record. Every entry IS an Action under the SVO substrate.
3
+ *
4
+ * Invariant: per-currency, sum(debits.amount) === sum(credits.amount).
5
+ * The ledger is append-only; reversals are new entries with opposite sign.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/finance/ledger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Merchant provisioning — the platform/Connect half of the FinanceProvider
3
+ * port: turn a priced Offer into a sellable product-line under a holdco, and
4
+ * mint a checkout for it.
5
+ *
6
+ * Motivation (added by explore.startups.studio B4, issue #222): the substrate
7
+ * `FinanceProvider` port modeled CHARGING (`charge`/`refund`/`subscribe`) but
8
+ * not the upstream provisioning a hosted-checkout flow needs:
9
+ * 1. provision a Product + Price under a platform account (Stripe Connect:
10
+ * one platform / holdco, many product-lines), keyed to a caller-supplied
11
+ * durable id (NOT a name — names are mutable),
12
+ * 2. open a hosted Checkout session that returns a redirectable URL,
13
+ * 3. report a payout against the platform balance.
14
+ *
15
+ * Stripe ships all three; the gap was only that the port did not EXPRESS them,
16
+ * so a consumer had to reach past the port into raw Stripe. These types close
17
+ * that gap so the consumer wires through the port (Stripe / Tempo / x402 are
18
+ * interchangeable behind it).
19
+ */
20
+ import type { Money } from './types.js';
21
+ import type { Pricing } from './pricing.js';
22
+ /** How a provisioned Price recurs — mirrors Stripe `price.recurring.interval`. */
23
+ export type PriceInterval = 'day' | 'week' | 'month' | 'quarter' | 'year';
24
+ /**
25
+ * Provision a per-product-line Product + Price under the platform/holdco
26
+ * account. `merchantRef` is the caller's DURABLE key for the product-line
27
+ * (e.g. a Startup Id) — adapters MUST round-trip it as provider metadata so a
28
+ * re-provision is idempotent on it, NOT on the (mutable) display name.
29
+ */
30
+ export interface ProvisionProductOpts {
31
+ /** Caller's durable product-line key (e.g. Startup Id). The idempotency anchor. */
32
+ merchantRef: string;
33
+ /** Display name for the product (mutable; never used as the key). */
34
+ name: string;
35
+ /** Optional product description. */
36
+ description?: string;
37
+ /** The unit price of the representative tier. */
38
+ price: Money;
39
+ /** Recurring interval; omit for a one-time price. */
40
+ interval?: PriceInterval;
41
+ /** The full authored Pricing architecture (carried as provider metadata for audit). */
42
+ pricing?: Pricing;
43
+ /** Idempotency key for at-most-once provisioning. */
44
+ idempotencyKey?: string;
45
+ /** Provider-specific opts; pass-through. */
46
+ providerOpts?: Record<string, unknown>;
47
+ }
48
+ export interface ProvisionedProduct {
49
+ $id: string;
50
+ $type: 'Product';
51
+ /** Echoed durable product-line key. */
52
+ merchantRef: string;
53
+ /** Provider product + price ids. */
54
+ providerData: {
55
+ provider: string;
56
+ productId: string;
57
+ priceId: string;
58
+ };
59
+ }
60
+ /** Open a hosted-checkout session for a provisioned Price. */
61
+ export interface CheckoutOpts {
62
+ /** The provider price id (from {@link ProvisionedProduct}). */
63
+ priceId: string;
64
+ /** Caller's durable product-line key — round-tripped onto the resulting payment. */
65
+ merchantRef: string;
66
+ /** Quantity of the price to purchase (default 1). */
67
+ quantity?: number;
68
+ /** Where the provider redirects on success (may carry a `{CHECKOUT_SESSION_ID}` template). */
69
+ successUrl: string;
70
+ /** Where the provider redirects on cancel. */
71
+ cancelUrl: string;
72
+ /** Mode of the session: one-time payment vs. recurring subscription. */
73
+ mode?: 'payment' | 'subscription';
74
+ /** Arbitrary metadata to attach to the session + resulting payment (e.g. correlation ids). */
75
+ metadata?: Record<string, string>;
76
+ /** Idempotency key for at-most-once session creation. */
77
+ idempotencyKey?: string;
78
+ /** Provider-specific opts; pass-through. */
79
+ providerOpts?: Record<string, unknown>;
80
+ }
81
+ export interface CheckoutSession {
82
+ $id: string;
83
+ $type: 'CheckoutSession';
84
+ /** The redirectable hosted-checkout URL the buyer is sent to. */
85
+ url: string;
86
+ /** Caller's durable product-line key. */
87
+ merchantRef: string;
88
+ status: 'open' | 'complete' | 'expired';
89
+ providerData: {
90
+ provider: string;
91
+ externalId: string;
92
+ };
93
+ }
94
+ export interface PayoutOpts {
95
+ /** Amount to pay out from the platform balance. */
96
+ amount: Money;
97
+ /** The connected/destination account ref receiving the payout. */
98
+ destinationRef: string;
99
+ /** Idempotency key for at-most-once payout. */
100
+ idempotencyKey?: string;
101
+ providerOpts?: Record<string, unknown>;
102
+ }
103
+ export interface PayoutResult {
104
+ $id: string;
105
+ $type: 'Payout';
106
+ amount: Money;
107
+ destinationRef: string;
108
+ status: 'pending' | 'paid' | 'failed';
109
+ /** ISO-8601 timestamp. */
110
+ createdAt: string;
111
+ providerData: {
112
+ provider: string;
113
+ externalId: string;
114
+ };
115
+ }
116
+ /**
117
+ * The merchant/platform-provisioning capability set. A FinanceProvider MAY
118
+ * implement these (gated by {@link ProviderCapabilities.merchant}); a
119
+ * charge-only adapter omits them.
120
+ */
121
+ export interface MerchantCapable {
122
+ /** Provision (idempotently, on `merchantRef`) a Product + Price under the platform/holdco. */
123
+ provisionProduct(opts: ProvisionProductOpts): Promise<ProvisionedProduct>;
124
+ /** Open a hosted-checkout session for a provisioned price; returns a redirectable URL. */
125
+ createCheckoutSession(opts: CheckoutOpts): Promise<CheckoutSession>;
126
+ /** Report a payout against the platform balance to a destination account. */
127
+ payout?(opts: PayoutOpts): Promise<PayoutResult>;
128
+ }
129
+ //# sourceMappingURL=merchant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merchant.d.ts","sourceRoot":"","sources":["../../src/finance/merchant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C,kFAAkF;AAClF,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAA;AAEzE;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,mFAAmF;IACnF,WAAW,EAAE,MAAM,CAAA;IACnB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAA;IACZ,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iDAAiD;IACjD,KAAK,EAAE,KAAK,CAAA;IACZ,qDAAqD;IACrD,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,uFAAuF;IACvF,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACvC;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,SAAS,CAAA;IAChB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAA;IACnB,oCAAoC;IACpC,YAAY,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;CACvE;AAED,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IA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E,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAA;IACrC,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAA;CACvD;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,8FAA8F;IAC9F,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACzE,0FAA0F;IAC1F,qBAAqB,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;IACnE,6EAA6E;IAC7E,MAAM,CAAC,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;CACjD"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Merchant provisioning — the platform/Connect half of the FinanceProvider
3
+ * port: turn a priced Offer into a sellable product-line under a holdco, and
4
+ * mint a checkout for it.
5
+ *
6
+ * Motivation (added by explore.startups.studio B4, issue #222): the substrate
7
+ * `FinanceProvider` port modeled CHARGING (`charge`/`refund`/`subscribe`) but
8
+ * not the upstream provisioning a hosted-checkout flow needs:
9
+ * 1. provision a Product + Price under a platform account (Stripe Connect:
10
+ * one platform / holdco, many product-lines), keyed to a caller-supplied
11
+ * durable id (NOT a name — names are mutable),
12
+ * 2. open a hosted Checkout session that returns a redirectable URL,
13
+ * 3. report a payout against the platform balance.
14
+ *
15
+ * Stripe ships all three; the gap was only that the port did not EXPRESS them,
16
+ * so a consumer had to reach past the port into raw Stripe. These types close
17
+ * that gap so the consumer wires through the port (Stripe / Tempo / x402 are
18
+ * interchangeable behind it).
19
+ */
20
+ export {};
21
+ //# sourceMappingURL=merchant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merchant.js","sourceRoot":"","sources":["../../src/finance/merchant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG"}
@@ -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,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM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B,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,GACL,MAAM,GACN,WAAW,GACX,MAAM,GACN,MAAM,GACN,KAAK,GACL,WAAW,GACX,UAAU,CAAA;AAEd,MAAM,WAAW,oBAAoB;IACn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BAAoB,CAAA;IAG3C,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IAC/C,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IAG/D,SAAS,CAAC,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzC,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAGxC,WAAW,CAAC,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACjD,OAAO,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3C,QAAQ,CAAC,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAGtD,MAAM,CAAC,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACzD,OAAO,CAAC,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAG5E,SAAS,CAAC,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IACtD,KAAK,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAGxC,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC/D"}
@@ -0,0 +1,10 @@
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
+ 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"}