@openlup/platform 0.21.0 → 0.23.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 (349) hide show
  1. package/CHANGELOG.md +432 -146
  2. package/README.md +82 -589
  3. package/dist/composition/composeBundle.d.ts +7 -0
  4. package/dist/composition/composeBundle.js +2 -0
  5. package/dist/composition/fulfillmentContribution.d.ts +21 -0
  6. package/dist/composition/fulfillmentContribution.js +19 -0
  7. package/dist/composition/index.d.ts +1 -0
  8. package/dist/composition/index.js +1 -0
  9. package/dist/fulfillment/adapterConformance.d.ts +3 -0
  10. package/dist/fulfillment/adapterConformance.js +223 -0
  11. package/dist/fulfillment/bindings.d.ts +3 -0
  12. package/dist/fulfillment/bindings.js +29 -0
  13. package/dist/fulfillment/commerceFulfillmentHandlers.d.ts +29 -0
  14. package/dist/fulfillment/commerceFulfillmentHandlers.js +184 -0
  15. package/dist/fulfillment/commerceFulfillmentReadModel.d.ts +86 -0
  16. package/dist/fulfillment/commerceFulfillmentReadModel.js +131 -0
  17. package/dist/fulfillment/contracts/alignment.d.ts +25 -0
  18. package/dist/fulfillment/contracts/alignment.js +1 -0
  19. package/dist/fulfillment/contracts/bindings.d.ts +51 -0
  20. package/dist/fulfillment/contracts/bindings.js +1 -0
  21. package/dist/fulfillment/contracts/capabilities.d.ts +29 -0
  22. package/dist/fulfillment/contracts/capabilities.js +1 -0
  23. package/dist/fulfillment/contracts/conformance.d.ts +95 -0
  24. package/dist/fulfillment/contracts/conformance.js +1 -0
  25. package/dist/fulfillment/contracts/customerAlignment.d.ts +6 -0
  26. package/dist/fulfillment/contracts/customerAlignment.js +1 -0
  27. package/dist/fulfillment/contracts/dispatch.d.ts +143 -0
  28. package/dist/fulfillment/contracts/dispatch.js +1 -0
  29. package/dist/fulfillment/contracts/index.d.ts +18 -0
  30. package/dist/fulfillment/contracts/index.js +1 -0
  31. package/dist/fulfillment/contracts/label.d.ts +35 -0
  32. package/dist/fulfillment/contracts/label.js +1 -0
  33. package/dist/fulfillment/contracts/nativeUnsupported.d.ts +6 -0
  34. package/dist/fulfillment/contracts/nativeUnsupported.js +1 -0
  35. package/dist/fulfillment/contracts/observation.d.ts +72 -0
  36. package/dist/fulfillment/contracts/observation.js +1 -0
  37. package/dist/fulfillment/contracts/operator.d.ts +64 -0
  38. package/dist/fulfillment/contracts/operator.js +1 -0
  39. package/dist/fulfillment/contracts/read.d.ts +110 -0
  40. package/dist/fulfillment/contracts/read.js +1 -0
  41. package/dist/fulfillment/contracts/readback.d.ts +59 -0
  42. package/dist/fulfillment/contracts/readback.js +1 -0
  43. package/dist/fulfillment/contracts/replacement.d.ts +34 -0
  44. package/dist/fulfillment/contracts/replacement.js +1 -0
  45. package/dist/fulfillment/contracts/store.d.ts +89 -0
  46. package/dist/fulfillment/contracts/store.js +1 -0
  47. package/dist/fulfillment/contracts/sync.d.ts +226 -0
  48. package/dist/fulfillment/contracts/sync.js +1 -0
  49. package/dist/fulfillment/currentFulfillmentParcel.d.ts +2 -0
  50. package/dist/fulfillment/currentFulfillmentParcel.js +1 -0
  51. package/dist/fulfillment/delayReadModel.d.ts +11 -0
  52. package/dist/fulfillment/delayReadModel.js +45 -0
  53. package/dist/fulfillment/deliveryAlignmentReadModel.d.ts +4 -0
  54. package/dist/fulfillment/deliveryAlignmentReadModel.js +12 -0
  55. package/dist/fulfillment/dispatchProjection.d.ts +26 -0
  56. package/dist/fulfillment/dispatchProjection.js +107 -0
  57. package/dist/fulfillment/fulfillmentObservationEffects.d.ts +66 -0
  58. package/dist/fulfillment/fulfillmentObservationEffects.js +36 -0
  59. package/dist/fulfillment/handlerSchemas.d.ts +647 -0
  60. package/dist/fulfillment/handlerSchemas.js +213 -0
  61. package/dist/fulfillment/handlerSupport.d.ts +33 -0
  62. package/dist/fulfillment/handlerSupport.js +25 -0
  63. package/dist/fulfillment/index.d.ts +38 -0
  64. package/dist/fulfillment/index.js +37 -0
  65. package/dist/fulfillment/labelLifecycle.d.ts +24 -0
  66. package/dist/fulfillment/labelLifecycle.js +9 -0
  67. package/dist/fulfillment/lowStockEvidenceHandler.d.ts +36 -0
  68. package/dist/fulfillment/lowStockEvidenceHandler.js +46 -0
  69. package/dist/fulfillment/migrations.d.ts +32 -0
  70. package/dist/fulfillment/migrations.js +9 -0
  71. package/dist/fulfillment/nativeUnsupported.d.ts +10 -0
  72. package/dist/fulfillment/nativeUnsupported.js +18 -0
  73. package/dist/fulfillment/normalizedFulfillmentFacts.d.ts +2 -0
  74. package/dist/fulfillment/normalizedFulfillmentFacts.js +1 -0
  75. package/dist/fulfillment/observationProjection.d.ts +32 -0
  76. package/dist/fulfillment/observationProjection.js +90 -0
  77. package/dist/fulfillment/omnipack/capabilities.d.ts +3 -0
  78. package/dist/fulfillment/omnipack/capabilities.js +16 -0
  79. package/dist/fulfillment/omnipack/client.d.ts +39 -0
  80. package/dist/fulfillment/omnipack/client.js +172 -0
  81. package/dist/fulfillment/omnipack/index.d.ts +55 -0
  82. package/dist/fulfillment/omnipack/index.js +408 -0
  83. package/dist/fulfillment/omnipack/mappers.d.ts +79 -0
  84. package/dist/fulfillment/omnipack/mappers.js +199 -0
  85. package/dist/fulfillment/omnipack/observation.d.ts +28 -0
  86. package/dist/fulfillment/omnipack/observation.js +72 -0
  87. package/dist/fulfillment/omnipack/omnipackDispatchPayload.d.ts +36 -0
  88. package/dist/fulfillment/omnipack/omnipackDispatchPayload.js +63 -0
  89. package/dist/fulfillment/omnipack/omnipackOutboundOrderPayload.d.ts +83 -0
  90. package/dist/fulfillment/omnipack/omnipackOutboundOrderPayload.js +113 -0
  91. package/dist/fulfillment/omnipack/omnipackProductPackPayload.d.ts +11 -0
  92. package/dist/fulfillment/omnipack/omnipackProductPackPayload.js +38 -0
  93. package/dist/fulfillment/omnipack/omnipackProductPayload.d.ts +18 -0
  94. package/dist/fulfillment/omnipack/omnipackProductPayload.js +51 -0
  95. package/dist/fulfillment/omnipack/omnipackReconciliationPayload.d.ts +1 -0
  96. package/dist/fulfillment/omnipack/omnipackReconciliationPayload.js +3 -0
  97. package/dist/fulfillment/omnipack/omnipackStatusVocabulary.d.ts +4 -0
  98. package/dist/fulfillment/omnipack/omnipackStatusVocabulary.js +87 -0
  99. package/dist/fulfillment/omnipack/omnipackWebhookPayload.d.ts +9 -0
  100. package/dist/fulfillment/omnipack/omnipackWebhookPayload.js +76 -0
  101. package/dist/fulfillment/omnipack/productSyncMappers.d.ts +18 -0
  102. package/dist/fulfillment/omnipack/productSyncMappers.js +43 -0
  103. package/dist/fulfillment/omnipack/providerError.d.ts +25 -0
  104. package/dist/fulfillment/omnipack/providerError.js +47 -0
  105. package/dist/fulfillment/omnipack/reconciliation.d.ts +15 -0
  106. package/dist/fulfillment/omnipack/reconciliation.js +55 -0
  107. package/dist/fulfillment/omnipack/trackingReferences.d.ts +16 -0
  108. package/dist/fulfillment/omnipack/trackingReferences.js +52 -0
  109. package/dist/fulfillment/paidFulfillmentRecovery.d.ts +67 -0
  110. package/dist/fulfillment/paidFulfillmentRecovery.js +154 -0
  111. package/dist/fulfillment/paidHandoff.d.ts +27 -0
  112. package/dist/fulfillment/paidHandoff.js +86 -0
  113. package/dist/fulfillment/paidHandoffPorts.d.ts +24 -0
  114. package/dist/fulfillment/paidHandoffPorts.js +3 -0
  115. package/dist/fulfillment/postgresDeliveryAlignment.d.ts +4 -0
  116. package/dist/fulfillment/postgresDeliveryAlignment.js +12 -0
  117. package/dist/fulfillment/postgresDispatchStore.d.ts +16 -0
  118. package/dist/fulfillment/postgresDispatchStore.js +44 -0
  119. package/dist/fulfillment/postgresEvidenceReadPort.d.ts +25 -0
  120. package/dist/fulfillment/postgresEvidenceReadPort.js +45 -0
  121. package/dist/fulfillment/postgresPaidFulfillmentRecovery.d.ts +25 -0
  122. package/dist/fulfillment/postgresPaidFulfillmentRecovery.js +26 -0
  123. package/dist/fulfillment/postgresPaidHandoffStore.d.ts +4 -0
  124. package/dist/fulfillment/postgresPaidHandoffStore.js +10 -0
  125. package/dist/fulfillment/postgresShipmentSpine.d.ts +70 -0
  126. package/dist/fulfillment/postgresShipmentSpine.js +246 -0
  127. package/dist/fulfillment/postgresStockSyncPort.d.ts +8 -0
  128. package/dist/fulfillment/postgresStockSyncPort.js +66 -0
  129. package/dist/fulfillment/productReconciliationEvidenceHandler.d.ts +36 -0
  130. package/dist/fulfillment/productReconciliationEvidenceHandler.js +50 -0
  131. package/dist/fulfillment/providerCapabilities.d.ts +9 -0
  132. package/dist/fulfillment/providerCapabilities.js +17 -0
  133. package/dist/fulfillment/providerCommandLedger.d.ts +143 -0
  134. package/dist/fulfillment/providerCommandLedger.js +14 -0
  135. package/dist/fulfillment/providerDispatchAcceptance.d.ts +27 -0
  136. package/dist/fulfillment/providerDispatchAcceptance.js +29 -0
  137. package/dist/fulfillment/providerDispatchError.d.ts +6 -0
  138. package/dist/fulfillment/providerDispatchError.js +5 -0
  139. package/dist/fulfillment/providerDispatchWorker.d.ts +44 -0
  140. package/dist/fulfillment/providerDispatchWorker.js +199 -0
  141. package/dist/fulfillment/providerProductSyncWorker.d.ts +28 -0
  142. package/dist/fulfillment/providerProductSyncWorker.js +122 -0
  143. package/dist/fulfillment/providerReconciliationError.d.ts +9 -0
  144. package/dist/fulfillment/providerReconciliationError.js +17 -0
  145. package/dist/fulfillment/providerReconciliationTerminalSkip.d.ts +2 -0
  146. package/dist/fulfillment/providerReconciliationTerminalSkip.js +6 -0
  147. package/dist/fulfillment/providerReconciliationTimestamp.d.ts +1 -0
  148. package/dist/fulfillment/providerReconciliationTimestamp.js +27 -0
  149. package/dist/fulfillment/providerReconciliationWorker.d.ts +90 -0
  150. package/dist/fulfillment/providerReconciliationWorker.js +207 -0
  151. package/dist/fulfillment/providerStockAvailability.d.ts +13 -0
  152. package/dist/fulfillment/providerStockAvailability.js +51 -0
  153. package/dist/fulfillment/providerStockSyncWorker.d.ts +41 -0
  154. package/dist/fulfillment/providerStockSyncWorker.js +295 -0
  155. package/dist/fulfillment/providerTrackingReferences.d.ts +16 -0
  156. package/dist/fulfillment/providerTrackingReferences.js +23 -0
  157. package/dist/fulfillment/replacementRefusals.d.ts +5 -0
  158. package/dist/fulfillment/replacementRefusals.js +38 -0
  159. package/dist/fulfillment/replacementShipmentHandler.d.ts +5 -0
  160. package/dist/fulfillment/replacementShipmentHandler.js +46 -0
  161. package/dist/fulfillment/schemaCapabilities.d.ts +13 -0
  162. package/dist/fulfillment/schemaCapabilities.js +7 -0
  163. package/dist/fulfillment/shipmentsOverviewHandler.d.ts +16 -0
  164. package/dist/fulfillment/shipmentsOverviewHandler.js +54 -0
  165. package/dist/fulfillment/statusMap.d.ts +2 -0
  166. package/dist/fulfillment/statusMap.js +1 -0
  167. package/dist/fulfillment/trackingProgress.d.ts +1 -0
  168. package/dist/fulfillment/trackingProgress.js +1 -0
  169. package/dist/fulfillment/verifiedIngress.d.ts +79 -0
  170. package/dist/fulfillment/verifiedIngress.js +94 -0
  171. package/dist/invoicing/capabilities.d.ts +11 -0
  172. package/dist/invoicing/capabilities.js +10 -0
  173. package/dist/invoicing/contracts/capabilities.d.ts +40 -0
  174. package/dist/invoicing/contracts/capabilities.js +1 -0
  175. package/dist/invoicing/contracts/companyLookup.d.ts +49 -0
  176. package/dist/invoicing/contracts/companyLookup.js +1 -0
  177. package/dist/invoicing/contracts/delivery.d.ts +74 -0
  178. package/dist/invoicing/contracts/delivery.js +1 -0
  179. package/dist/invoicing/contracts/facts.d.ts +100 -0
  180. package/dist/invoicing/contracts/facts.js +1 -0
  181. package/dist/invoicing/contracts/host.d.ts +246 -0
  182. package/dist/invoicing/contracts/host.js +1 -0
  183. package/dist/invoicing/contracts/index.d.ts +16 -0
  184. package/dist/invoicing/contracts/index.js +1 -0
  185. package/dist/invoicing/contracts/provider.d.ts +126 -0
  186. package/dist/invoicing/contracts/provider.js +1 -0
  187. package/dist/invoicing/contracts/settlement.d.ts +66 -0
  188. package/dist/invoicing/contracts/settlement.js +1 -0
  189. package/dist/invoicing/contracts/store.d.ts +267 -0
  190. package/dist/invoicing/contracts/store.js +1 -0
  191. package/dist/invoicing/index.d.ts +1 -0
  192. package/dist/invoicing/index.js +1 -0
  193. package/dist/payments/stripe/index.d.ts +25 -0
  194. package/dist/payments/stripe/index.js +25 -0
  195. package/dist/payments/tpay/index.d.ts +30 -0
  196. package/dist/payments/tpay/index.js +30 -0
  197. package/dist/subscriptions/automaticRenewal.d.ts +44 -0
  198. package/dist/subscriptions/automaticRenewal.js +81 -0
  199. package/dist/subscriptions/automaticRenewalExecution.d.ts +21 -0
  200. package/dist/subscriptions/automaticRenewalExecution.js +44 -0
  201. package/dist/subscriptions/contracts/commands.d.ts +115 -0
  202. package/dist/subscriptions/contracts/commands.js +1 -0
  203. package/dist/subscriptions/contracts/dunning.d.ts +133 -0
  204. package/dist/subscriptions/contracts/dunning.js +1 -0
  205. package/dist/subscriptions/contracts/index.d.ts +6 -0
  206. package/dist/subscriptions/contracts/index.js +1 -0
  207. package/dist/subscriptions/contracts/messages.d.ts +43 -0
  208. package/dist/subscriptions/contracts/messages.js +1 -0
  209. package/dist/subscriptions/contracts/renewal.d.ts +533 -0
  210. package/dist/subscriptions/contracts/renewal.js +1 -0
  211. package/dist/subscriptions/contracts/stockWait.d.ts +73 -0
  212. package/dist/subscriptions/contracts/stockWait.js +1 -0
  213. package/dist/subscriptions/index.d.ts +39 -0
  214. package/dist/subscriptions/index.js +17 -0
  215. package/dist/subscriptions/paymentOutcomes.d.ts +8 -0
  216. package/dist/subscriptions/paymentOutcomes.js +27 -0
  217. package/dist/subscriptions/postgresRenewalStore.d.ts +20 -0
  218. package/dist/subscriptions/postgresRenewalStore.js +61 -0
  219. package/dist/subscriptions/postgresRetryStore.d.ts +78 -0
  220. package/dist/subscriptions/postgresRetryStore.js +142 -0
  221. package/dist/subscriptions/renewalCycleFailureMechanism.d.ts +34 -0
  222. package/dist/subscriptions/renewalCycleFailureMechanism.js +79 -0
  223. package/dist/subscriptions/renewalCycleMechanism.d.ts +46 -0
  224. package/dist/subscriptions/renewalCycleMechanism.js +157 -0
  225. package/dist/subscriptions/renewalCycleRefusalMechanism.d.ts +41 -0
  226. package/dist/subscriptions/renewalCycleRefusalMechanism.js +160 -0
  227. package/dist/subscriptions/renewalIdentity.d.ts +3 -0
  228. package/dist/subscriptions/renewalIdentity.js +4 -0
  229. package/package.json +37 -2
  230. package/release-gates.json +97 -3
  231. package/sql/20260808210000_fulfillment_shipment_rail.sql +810 -0
  232. package/sql/20260819150000_fulfillment_shipment_sequence.sql +98 -0
  233. package/sql/20261022080000_fulfillment_command_ledger.sql +786 -0
  234. package/sql/20261022090000_fulfillment_delivery_alignment.sql +1106 -0
  235. package/sql/20261022160000_subscription_retry_lifecycle.sql +328 -0
  236. package/sql/20261022165000_fulfillment_stock_evidence_replay_reopen.sql +30 -0
  237. package/src/composition/composeBundle.ts +4 -0
  238. package/src/composition/fulfillmentContribution.ts +28 -0
  239. package/src/composition/index.ts +1 -0
  240. package/src/fulfillment/adapterConformance.ts +195 -0
  241. package/src/fulfillment/bindings.ts +26 -0
  242. package/src/fulfillment/commerceFulfillmentHandlers.ts +263 -0
  243. package/src/fulfillment/commerceFulfillmentReadModel.ts +257 -0
  244. package/src/fulfillment/contracts/alignment.ts +13 -0
  245. package/src/fulfillment/contracts/bindings.ts +30 -0
  246. package/src/fulfillment/contracts/capabilities.ts +15 -0
  247. package/src/fulfillment/contracts/conformance.ts +63 -0
  248. package/src/fulfillment/contracts/customerAlignment.ts +4 -0
  249. package/src/fulfillment/contracts/dispatch.ts +73 -0
  250. package/src/fulfillment/contracts/index.ts +18 -0
  251. package/src/fulfillment/contracts/label.ts +9 -0
  252. package/src/fulfillment/contracts/nativeUnsupported.ts +6 -0
  253. package/src/fulfillment/contracts/observation.ts +26 -0
  254. package/src/fulfillment/contracts/operator.ts +31 -0
  255. package/src/fulfillment/contracts/read.ts +42 -0
  256. package/src/fulfillment/contracts/readback.ts +24 -0
  257. package/src/fulfillment/contracts/replacement.ts +15 -0
  258. package/src/fulfillment/contracts/store.ts +27 -0
  259. package/src/fulfillment/contracts/sync.ts +72 -0
  260. package/src/fulfillment/currentFulfillmentParcel.ts +2 -0
  261. package/src/fulfillment/delayReadModel.ts +60 -0
  262. package/src/fulfillment/deliveryAlignmentReadModel.ts +15 -0
  263. package/src/fulfillment/dispatchProjection.ts +105 -0
  264. package/src/fulfillment/fulfillmentObservationEffects.ts +86 -0
  265. package/src/fulfillment/handlerSchemas.ts +255 -0
  266. package/src/fulfillment/handlerSupport.ts +25 -0
  267. package/src/fulfillment/index.ts +39 -0
  268. package/src/fulfillment/labelLifecycle.ts +11 -0
  269. package/src/fulfillment/lowStockEvidenceHandler.ts +60 -0
  270. package/src/fulfillment/migrations.ts +9 -0
  271. package/src/fulfillment/nativeUnsupported.ts +23 -0
  272. package/src/fulfillment/normalizedFulfillmentFacts.ts +2 -0
  273. package/src/fulfillment/observationProjection.ts +92 -0
  274. package/src/fulfillment/omnipack/capabilities.ts +18 -0
  275. package/src/fulfillment/omnipack/client.ts +270 -0
  276. package/src/fulfillment/omnipack/index.ts +369 -0
  277. package/src/fulfillment/omnipack/mappers.ts +282 -0
  278. package/src/fulfillment/omnipack/observation.ts +79 -0
  279. package/src/fulfillment/omnipack/omnipackDispatchPayload.ts +93 -0
  280. package/src/fulfillment/omnipack/omnipackOutboundOrderPayload.ts +194 -0
  281. package/src/fulfillment/omnipack/omnipackProductPackPayload.ts +47 -0
  282. package/src/fulfillment/omnipack/omnipackProductPayload.ts +67 -0
  283. package/src/fulfillment/omnipack/omnipackReconciliationPayload.ts +7 -0
  284. package/src/fulfillment/omnipack/omnipackStatusVocabulary.ts +103 -0
  285. package/src/fulfillment/omnipack/omnipackWebhookPayload.ts +73 -0
  286. package/src/fulfillment/omnipack/productSyncMappers.ts +74 -0
  287. package/src/fulfillment/omnipack/providerError.ts +64 -0
  288. package/src/fulfillment/omnipack/reconciliation.ts +56 -0
  289. package/src/fulfillment/omnipack/trackingReferences.ts +77 -0
  290. package/src/fulfillment/paidFulfillmentRecovery.ts +252 -0
  291. package/src/fulfillment/paidHandoff.ts +122 -0
  292. package/src/fulfillment/paidHandoffPorts.ts +21 -0
  293. package/src/fulfillment/postgresDeliveryAlignment.ts +14 -0
  294. package/src/fulfillment/postgresDispatchStore.ts +55 -0
  295. package/src/fulfillment/postgresEvidenceReadPort.ts +59 -0
  296. package/src/fulfillment/postgresPaidFulfillmentRecovery.ts +29 -0
  297. package/src/fulfillment/postgresPaidHandoffStore.ts +11 -0
  298. package/src/fulfillment/postgresShipmentSpine.ts +338 -0
  299. package/src/fulfillment/postgresStockSyncPort.ts +68 -0
  300. package/src/fulfillment/productReconciliationEvidenceHandler.ts +64 -0
  301. package/src/fulfillment/providerCapabilities.ts +18 -0
  302. package/src/fulfillment/providerCommandLedger.ts +53 -0
  303. package/src/fulfillment/providerDispatchAcceptance.ts +37 -0
  304. package/src/fulfillment/providerDispatchError.ts +7 -0
  305. package/src/fulfillment/providerDispatchWorker.ts +159 -0
  306. package/src/fulfillment/providerProductSyncWorker.ts +154 -0
  307. package/src/fulfillment/providerReconciliationError.ts +20 -0
  308. package/src/fulfillment/providerReconciliationTerminalSkip.ts +8 -0
  309. package/src/fulfillment/providerReconciliationTimestamp.ts +34 -0
  310. package/src/fulfillment/providerReconciliationWorker.ts +206 -0
  311. package/src/fulfillment/providerStockAvailability.ts +60 -0
  312. package/src/fulfillment/providerStockSyncWorker.ts +318 -0
  313. package/src/fulfillment/providerTrackingReferences.ts +32 -0
  314. package/src/fulfillment/replacementRefusals.ts +43 -0
  315. package/src/fulfillment/replacementShipmentHandler.ts +47 -0
  316. package/src/fulfillment/schemaCapabilities.ts +7 -0
  317. package/src/fulfillment/shipmentsOverviewHandler.ts +73 -0
  318. package/src/fulfillment/statusMap.ts +2 -0
  319. package/src/fulfillment/trackingProgress.ts +1 -0
  320. package/src/fulfillment/verifiedIngress.ts +113 -0
  321. package/src/invoicing/capabilities.ts +9 -0
  322. package/src/invoicing/contracts/capabilities.ts +15 -0
  323. package/src/invoicing/contracts/companyLookup.ts +13 -0
  324. package/src/invoicing/contracts/delivery.ts +24 -0
  325. package/src/invoicing/contracts/facts.ts +60 -0
  326. package/src/invoicing/contracts/host.ts +85 -0
  327. package/src/invoicing/contracts/index.ts +16 -0
  328. package/src/invoicing/contracts/provider.ts +78 -0
  329. package/src/invoicing/contracts/settlement.ts +39 -0
  330. package/src/invoicing/contracts/store.ts +98 -0
  331. package/src/invoicing/index.ts +1 -0
  332. package/src/payments/stripe/index.ts +30 -0
  333. package/src/payments/tpay/index.ts +36 -0
  334. package/src/subscriptions/automaticRenewal.ts +87 -0
  335. package/src/subscriptions/automaticRenewalExecution.ts +39 -0
  336. package/src/subscriptions/contracts/commands.ts +46 -0
  337. package/src/subscriptions/contracts/dunning.ts +48 -0
  338. package/src/subscriptions/contracts/index.ts +6 -0
  339. package/src/subscriptions/contracts/messages.ts +18 -0
  340. package/src/subscriptions/contracts/renewal.ts +325 -0
  341. package/src/subscriptions/contracts/stockWait.ts +34 -0
  342. package/src/subscriptions/index.ts +24 -0
  343. package/src/subscriptions/paymentOutcomes.ts +23 -0
  344. package/src/subscriptions/postgresRenewalStore.ts +76 -0
  345. package/src/subscriptions/postgresRetryStore.ts +174 -0
  346. package/src/subscriptions/renewalCycleFailureMechanism.ts +119 -0
  347. package/src/subscriptions/renewalCycleMechanism.ts +225 -0
  348. package/src/subscriptions/renewalCycleRefusalMechanism.ts +215 -0
  349. package/src/subscriptions/renewalIdentity.ts +5 -0
@@ -0,0 +1,100 @@
1
+ /** Frozen host facts; no catalogue, registry or country-policy reread on retry.
2
+ * Carrier: donor providerPorts snapshot and invoiceContracts LocalInvoiceSnapshot;
3
+ * native invoicing_install_facts adds dates/refs/policyVersion and explicit totals.
4
+ */
5
+ export interface InvoiceSeller {
6
+ readonly name: string;
7
+ readonly address: {
8
+ readonly line1: string;
9
+ readonly postalCode: string;
10
+ readonly city: string;
11
+ };
12
+ readonly taxIdentifier: {
13
+ readonly scheme: string;
14
+ readonly value: string;
15
+ };
16
+ readonly registrationIds?: readonly {
17
+ readonly scheme: string;
18
+ readonly value: string;
19
+ }[];
20
+ readonly bankAccount: string | null;
21
+ /** Opaque host routing reference, interpreted only by the selected adapter. */
22
+ readonly routingRef: string | null;
23
+ }
24
+ export interface InvoiceBuyer {
25
+ readonly name: string;
26
+ readonly email: string | null;
27
+ readonly taxIdentifier: {
28
+ readonly scheme: string;
29
+ readonly value: string;
30
+ } | null;
31
+ readonly companyName: string | null;
32
+ readonly address: {
33
+ readonly line1: string | null;
34
+ readonly postalCode: string | null;
35
+ readonly city: string | null;
36
+ readonly country: string | null;
37
+ } | null;
38
+ }
39
+ /** Safe integer minor amounts; taxRateBps is a rate, never a fiscal-support claim.
40
+ * Preserve array order and quantityUnit; no inferred shipping residual or FX.
41
+ */
42
+ export interface InvoiceLine {
43
+ readonly description: string;
44
+ readonly quantity: number;
45
+ readonly quantityUnit?: string;
46
+ readonly unitNetMinor: number;
47
+ readonly unitGrossMinor: number;
48
+ readonly totalNetMinor: number;
49
+ readonly totalTaxMinor: number;
50
+ readonly totalGrossMinor: number;
51
+ readonly taxRateBps: number;
52
+ readonly taxRateLabel?: string;
53
+ readonly positionKind: "item" | "delivery" | null;
54
+ readonly catalogTotalGrossMinor: number | null;
55
+ readonly discountAllocatedMinor: number | null;
56
+ readonly shippingGrossMinor: number | null;
57
+ readonly shippingDiscountMinor: number | null;
58
+ }
59
+ export interface InvoiceFacts {
60
+ readonly factRevision: string;
61
+ readonly policyVersion: string;
62
+ readonly refs: {
63
+ readonly orderId: string;
64
+ readonly orderRef: string;
65
+ readonly invoiceRef: string;
66
+ };
67
+ readonly dates: {
68
+ readonly issueDate: string;
69
+ readonly sellDate: string;
70
+ readonly handedOverAt: string | null;
71
+ readonly paymentCompletedAt: string | null;
72
+ };
73
+ /** Host-defined kind selected through the identifier/tax seam, never guessed. */
74
+ readonly documentKind: string;
75
+ readonly clearanceRequired: boolean;
76
+ readonly currency: string;
77
+ readonly buyer: InvoiceBuyer;
78
+ /** Supplied separately for execution; P8 freezes it at first claim before provider I/O. */
79
+ readonly seller?: InvoiceSeller;
80
+ readonly payment: {
81
+ readonly intentRef: string;
82
+ readonly providerRef: string | null;
83
+ readonly providerPaymentRef: string | null;
84
+ readonly amountMinor: number;
85
+ readonly currency: string;
86
+ readonly localSettlementState: "matched" | "unavailable";
87
+ };
88
+ readonly orderMoney: {
89
+ readonly subtotalMinor: number;
90
+ readonly discountMinor: number;
91
+ readonly shippingMinor: number;
92
+ readonly shippingDiscountMinor: number;
93
+ readonly totalMinor: number;
94
+ } | null;
95
+ readonly lines: readonly InvoiceLine[];
96
+ readonly totalNetMinor: number;
97
+ readonly totalTaxMinor: number;
98
+ readonly totalGrossMinor: number;
99
+ readonly chargedTotalGrossMinor: number;
100
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,246 @@
1
+ import type { InvoiceFacts, InvoiceSeller } from "./facts.js";
2
+ import type { InvoiceDocumentIdentity, InvoiceProof, InvoiceProviderPort, InvoiceUnsupported } from "./provider.js";
3
+ import type { InvoiceArtifactResult, InvoiceClearanceObservation, InvoiceDeliveryPort } from "./delivery.js";
4
+ import type { InvoiceCompanyLookupPort } from "./companyLookup.js";
5
+ import type { InvoiceSettlementPort } from "./settlement.js";
6
+ import type { InvoiceCapabilities } from "./capabilities.js";
7
+ import type { InvoiceStorePort } from "./store.js";
8
+ /** Host facts, fiscal routing, M07 reads, storage, registry, M04 delivery and M12
9
+ * history are required selections. Every missing native capability refuses before
10
+ * any write; an owed duty remains observable. This interface grants no authority.
11
+ */
12
+ export interface InvoiceHostPorts {
13
+ facts: {
14
+ read(orderId: string): Promise<{
15
+ readonly kind: "found";
16
+ readonly facts: InvoiceFacts;
17
+ } | {
18
+ readonly kind: "unknown";
19
+ readonly code: "missing_facts";
20
+ } | InvoiceUnsupported>;
21
+ };
22
+ /** Read the current host seller for the next claim, never per duty. Null orderId
23
+ * means an unscoped claim (including corrections). P8 freezes this seller at
24
+ * first claim; revisionRef feeds the claim wrapper's revision argument.
25
+ */
26
+ seller: {
27
+ read(input: {
28
+ readonly orderId: string | null;
29
+ }): Promise<{
30
+ readonly kind: "found";
31
+ readonly seller: InvoiceSeller;
32
+ readonly revisionRef: string;
33
+ } | {
34
+ readonly kind: "unknown";
35
+ readonly code: "unknown";
36
+ } | InvoiceUnsupported>;
37
+ };
38
+ /** Read-only projection of the final claimed M07 identity, never a refund writer.
39
+ * Missing nullable money is unavailable, never fabricated zero or mismatch.
40
+ */
41
+ money: {
42
+ read(input: {
43
+ readonly intentRef: string;
44
+ readonly providerRef: string;
45
+ readonly providerPaymentRef: string | null;
46
+ readonly expectedMoney: {
47
+ readonly amountMinor: number;
48
+ readonly currency: string;
49
+ };
50
+ }): Promise<{
51
+ readonly kind: "observed";
52
+ readonly status: "succeeded" | "failed" | "pending";
53
+ readonly amountMinor: number | null;
54
+ readonly currency: string | null;
55
+ readonly proof: InvoiceProof;
56
+ } | {
57
+ readonly kind: "absent";
58
+ readonly evidence: InvoiceProof & {
59
+ readonly exact: true;
60
+ readonly complete: true;
61
+ readonly scope: Parameters<InvoiceHostPorts["money"]["read"]>[0];
62
+ };
63
+ } | {
64
+ readonly kind: "unknown" | "unavailable";
65
+ readonly code: "money_unavailable";
66
+ } | InvoiceUnsupported>;
67
+ };
68
+ artifacts: {
69
+ read(input: {
70
+ readonly identity: InvoiceDocumentIdentity;
71
+ readonly kind: "pdf" | "structured_document" | "clearance_receipt";
72
+ }): Promise<InvoiceArtifactResult>;
73
+ /** Ownership must already be authorized; response bytes are not a storage receipt. */
74
+ download(input: {
75
+ readonly identity: InvoiceDocumentIdentity;
76
+ readonly artifactRef: string;
77
+ }): Promise<{
78
+ readonly kind: "downloaded";
79
+ readonly content: Uint8Array;
80
+ readonly contentType: string;
81
+ } | {
82
+ readonly kind: "unknown";
83
+ readonly code: "unknown";
84
+ } | InvoiceUnsupported>;
85
+ persist(input: {
86
+ readonly identity: InvoiceDocumentIdentity;
87
+ readonly kind: "pdf" | "structured_document" | "clearance_receipt";
88
+ readonly content: Uint8Array;
89
+ readonly contentType: string;
90
+ }): Promise<Exclude<InvoiceArtifactResult, {
91
+ kind: "absent";
92
+ }>>;
93
+ };
94
+ /** Host identifier/tax/rounding policy; refs must match the selected descriptor.
95
+ * No jurisdictional default is supplied. Carrier: TaxIdRoutingPort and injected
96
+ * canonical tax safety in accountingProviderSnapshot.
97
+ */
98
+ fiscal: {
99
+ verify(input: {
100
+ readonly facts: InvoiceFacts;
101
+ readonly policies: InvoiceCapabilities["policies"];
102
+ }): Promise<{
103
+ readonly kind: "verified";
104
+ readonly documentKind: string;
105
+ readonly clearanceRequired: boolean;
106
+ readonly proof: InvoiceProof;
107
+ } | {
108
+ readonly kind: "refused";
109
+ readonly code: "blocked" | "money_mismatch";
110
+ } | {
111
+ readonly kind: "unknown";
112
+ readonly code: "unknown";
113
+ } | InvoiceUnsupported>;
114
+ };
115
+ registry: InvoiceCompanyLookupPort;
116
+ delivery: InvoiceDeliveryPort;
117
+ clearance: {
118
+ observe(input: {
119
+ readonly identity: InvoiceDocumentIdentity;
120
+ readonly providerDocumentRef: string;
121
+ }): Promise<{
122
+ readonly kind: "observed";
123
+ readonly observation: InvoiceClearanceObservation;
124
+ } | {
125
+ readonly kind: "unknown";
126
+ readonly code: "unknown";
127
+ } | InvoiceUnsupported>;
128
+ };
129
+ settlement: InvoiceSettlementPort;
130
+ policy: {
131
+ /** Carrier: channelInvoicePolicyGate and the approved explicit operator skip.
132
+ * Suppression receipts have no fabricated document ID. Host persists attribution.
133
+ * Executor decides before installFacts: suppressed orders get no local document.
134
+ * Readback consumers merge recorded receipts with duty readback.
135
+ * Transient read failures return unknown without recording a receipt.
136
+ */
137
+ decide(input: {
138
+ readonly requestKey: string;
139
+ readonly lookup: {
140
+ readonly by: "order";
141
+ readonly orderId: string;
142
+ } | {
143
+ readonly by: "fulfillmentOrder";
144
+ readonly fulfillmentOrderRef: string;
145
+ };
146
+ }): Promise<{
147
+ readonly kind: "issue";
148
+ readonly policyVersion: string;
149
+ } | {
150
+ readonly kind: "policy_suppressed";
151
+ readonly outcome: "channel_issues" | "no_document";
152
+ readonly policyVersion: string;
153
+ readonly requestKey: string;
154
+ } | {
155
+ readonly kind: "operator_skipped";
156
+ readonly outcome: "operator_skip";
157
+ readonly actorRef: string;
158
+ readonly reason: string;
159
+ readonly requestKey: string;
160
+ } | {
161
+ readonly kind: "unknown";
162
+ readonly code: "unknown";
163
+ } | InvoiceUnsupported>;
164
+ receipts(orderId: string): Promise<readonly (Extract<Awaited<ReturnType<InvoiceHostPorts["policy"]["decide"]>>, {
165
+ kind: "policy_suppressed" | "operator_skipped";
166
+ }> & {
167
+ readonly recordedAt: string;
168
+ })[] | {
169
+ readonly kind: "unknown";
170
+ readonly code: "unknown";
171
+ } | InvoiceUnsupported>;
172
+ };
173
+ /** Authenticate and authorize ownership before reading artifacts. Safe projection
174
+ * only: no buyer/seller payload, raw provider errors, signed URL or arbitrary meta.
175
+ * Found is a complete owned projection; incomplete reads return unknown.
176
+ * Carrier: donor document history + customer download ticket owner/lineage.
177
+ */
178
+ accountHistory: {
179
+ read(input: {
180
+ readonly accountRef: string;
181
+ readonly orderId: string;
182
+ }): Promise<{
183
+ readonly kind: "found";
184
+ readonly accountRef: string;
185
+ readonly orderId: string;
186
+ readonly documents: readonly {
187
+ readonly documentRef: string;
188
+ readonly invoiceRef: string;
189
+ readonly parentDocumentRef: string | null;
190
+ readonly role: "original" | "correction" | "replacement";
191
+ readonly status: string;
192
+ readonly issuedAt: string | null;
193
+ readonly clearance: {
194
+ readonly state: InvoiceClearanceObservation["state"];
195
+ readonly reference: string | null;
196
+ } | null;
197
+ readonly documentKind: string | null;
198
+ readonly artifact: "invoice" | "correction";
199
+ readonly providerDocumentNumber: string | null;
200
+ readonly totalGrossMinor: number | null;
201
+ readonly currency: string;
202
+ readonly emailState: "not_requested" | "pending" | "provider_accepted" | "failed";
203
+ readonly isCurrent: boolean;
204
+ readonly createdAt: string;
205
+ readonly downloadAvailable: boolean;
206
+ }[];
207
+ } | {
208
+ readonly kind: "denied";
209
+ } | {
210
+ readonly kind: "unknown";
211
+ readonly code: "unknown";
212
+ } | InvoiceUnsupported>;
213
+ resolveDownload(input: {
214
+ readonly accountRef: string;
215
+ readonly orderId: string;
216
+ readonly documentRef: string;
217
+ }): Promise<{
218
+ readonly kind: "authorized";
219
+ readonly identity: InvoiceDocumentIdentity;
220
+ readonly artifactRef: string;
221
+ readonly fileName: string;
222
+ readonly parentDocumentRef: string | null;
223
+ } | {
224
+ readonly kind: "denied";
225
+ } | {
226
+ readonly kind: "unknown";
227
+ readonly code: "unknown";
228
+ } | InvoiceUnsupported>;
229
+ };
230
+ }
231
+ /** Future service composition inputs only; no constructor, worker or runtime route
232
+ * is supplied in P1. Closures/credentials must never be serialized with options.
233
+ */
234
+ export interface InvoiceServicesOptions {
235
+ readonly enabled?: boolean;
236
+ readonly selection: {
237
+ readonly providerRef: string;
238
+ } | null;
239
+ readonly capability: InvoiceCapabilities | null;
240
+ readonly provider: InvoiceProviderPort | null;
241
+ readonly store: InvoiceStorePort | null;
242
+ readonly host: InvoiceHostPorts;
243
+ readiness(): Promise<{
244
+ readonly kind: "ready";
245
+ } | InvoiceUnsupported>;
246
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ /** @consumer Frozen fact provider and installed declaration consumer. */
2
+ export type { InvoiceFacts, InvoiceLine, InvoiceSeller, InvoiceBuyer } from "./facts.js";
3
+ /** @consumer A4 issue/correction bridge, adapters and operator proof readback. */
4
+ export type { InvoiceIdentity, InvoiceDocumentIdentity, InvoiceWriteResult, InvoiceReadbackResult, InvoiceProviderPort, InvoiceUnsupported, InvoiceDiagnosticCode, InvoiceProof } from "./provider.js";
5
+ /** @consumer Host artifact storage/download binding. */
6
+ export type { InvoiceArtifactResult, InvoiceClearanceObservation } from "./delivery.js";
7
+ /** @consumer Host payout item recorder and resolver. */
8
+ export type { InvoiceSettlementResult, InvoiceSettlementPort, InvoiceSettlementItem } from "./settlement.js";
9
+ /** @consumer Explicit host selection and readInvoiceCapabilities. */
10
+ export type { InvoiceCapabilities } from "./capabilities.js";
11
+ /** @consumer Injected registry adapter (A5). */
12
+ export type { InvoiceCompanyLookupPort } from "./companyLookup.js";
13
+ /** @consumer Managed/native persistence adapter and operator duty readback; no implementation supplied. */
14
+ export type { InvoiceStorePort, InvoiceDutyReadback } from "./store.js";
15
+ /** @consumer Host composition and offline port-fit witnesses. */
16
+ export type { InvoiceHostPorts, InvoiceServicesOptions } from "./host.js";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,126 @@
1
+ import type { InvoiceFacts } from "./facts.js";
2
+ /** Original host key bytes, immutable revision and exact lookup scope travel together.
3
+ * Carrier: providerPorts create options + approved exact-lookup envelope (fit probe).
4
+ */
5
+ export interface InvoiceIdentity {
6
+ readonly providerRef: string;
7
+ readonly requestKey: string;
8
+ /** Persisted create identity from claim, distinct from original host request key. */
9
+ readonly providerCreateIdentity: string;
10
+ readonly factRevision: string;
11
+ readonly orderRef: string;
12
+ readonly invoiceRef: string;
13
+ readonly operation: "issue" | "full_reversal" | "remote_void";
14
+ readonly correctionRef: string | null;
15
+ readonly parentProviderDocumentRef: string | null;
16
+ }
17
+ /** Document rows and donor delivery/history carriers need no issue-duty metadata.
18
+ * @consumer Host artifacts, clearance, delivery and authorized download adapters.
19
+ */
20
+ export interface InvoiceDocumentIdentity {
21
+ readonly providerRef: string;
22
+ readonly documentRef: string;
23
+ readonly providerDocumentRef: string | null;
24
+ readonly orderRef: string;
25
+ readonly invoiceRef: string;
26
+ readonly parentProviderDocumentRef: string | null;
27
+ }
28
+ /** A closed diagnostic allowlist in the neutral contract. Codes only.
29
+ * @consumer A4 bridge and provider/store adapters. */
30
+ export type InvoiceDiagnosticCode = "faulted" | "missing_facts" | "legacy_facts_unproved" | "retryable" | "blocked" | "unsupported" | "unknown" | "absent" | "host_binding_required" | "selection_required" | "disabled" | "identity_mismatch" | "parent_mismatch" | "money_mismatch" | "money_unavailable" | "invalid_artifact" | "uncertain_delivery";
31
+ /** Missing binding or capability: nothing written.
32
+ * @consumer Host and provider adapters. */
33
+ export interface InvoiceUnsupported {
34
+ readonly kind: "unsupported";
35
+ readonly code: "host_binding_required" | "unsupported";
36
+ readonly retryable: false;
37
+ readonly effectMayHaveSucceeded: false;
38
+ }
39
+ /** Evidence references/fingerprints are adapter-filtered; never raw payloads or errors.
40
+ * @consumer Host recorder, operator readback and adapters. */
41
+ export interface InvoiceProof {
42
+ readonly evidenceRef: string;
43
+ readonly fingerprint: string;
44
+ readonly observedAt: string;
45
+ }
46
+ /** Refused proves a definite provider refusal with no effect; post-request adapter
47
+ * or transport faults are unknown, even when no acknowledgement was received.
48
+ */
49
+ export type InvoiceWriteResult = {
50
+ readonly kind: "issued";
51
+ readonly identity: InvoiceIdentity;
52
+ readonly providerDocumentRef: string;
53
+ readonly providerDocumentNumber: string | null;
54
+ readonly proof: InvoiceProof;
55
+ readonly replayed: boolean;
56
+ } | {
57
+ readonly kind: "refused";
58
+ readonly identity: InvoiceIdentity;
59
+ readonly code: Extract<InvoiceDiagnosticCode, "blocked" | "retryable" | "missing_facts" | "identity_mismatch" | "parent_mismatch" | "money_mismatch">;
60
+ readonly retryable: boolean;
61
+ readonly effectMayHaveSucceeded: false;
62
+ } | {
63
+ readonly kind: "unknown";
64
+ readonly identity: InvoiceIdentity;
65
+ readonly code: "unknown";
66
+ readonly effectMayHaveSucceeded: true;
67
+ } | InvoiceUnsupported;
68
+ /** Exact scope is the full identity, including operation, parent and revision.
69
+ * Incomplete/truncated/failed lookup is unknown. Only exact complete absence can
70
+ * authorize another create; found is proof, never a nullable lookup shortcut.
71
+ */
72
+ export type InvoiceReadbackResult = {
73
+ readonly kind: "found";
74
+ readonly identity: InvoiceIdentity;
75
+ readonly providerDocumentRef: string;
76
+ readonly providerDocumentNumber: string | null;
77
+ readonly proof: InvoiceProof;
78
+ } | {
79
+ readonly kind: "absent";
80
+ readonly identity: InvoiceIdentity;
81
+ readonly evidence: InvoiceProof & {
82
+ readonly exact: true;
83
+ readonly complete: true;
84
+ readonly scope: InvoiceIdentity;
85
+ };
86
+ } | {
87
+ readonly kind: "unknown";
88
+ readonly identity: InvoiceIdentity;
89
+ readonly code: "unknown";
90
+ } | InvoiceUnsupported;
91
+ /** Correction bridge: positive immutable BEFORE facts, explicit zero AFTER,
92
+ * stable correctionRef and parent proof. Retry requires exact recovery before I/O.
93
+ * Carrier: donor createFullCorrection options and accountingProviderSnapshot.
94
+ * @consumer A4 conforming correction bridge and issue/readback adapters.
95
+ */
96
+ export interface InvoiceProviderPort {
97
+ issue(input: {
98
+ readonly identity: InvoiceIdentity & {
99
+ readonly operation: "issue";
100
+ readonly correctionRef: null;
101
+ readonly parentProviderDocumentRef: null;
102
+ };
103
+ readonly facts: InvoiceFacts;
104
+ readonly recoveryLookupRequired: boolean;
105
+ }): Promise<InvoiceWriteResult>;
106
+ correct(input: {
107
+ readonly identity: InvoiceIdentity & {
108
+ readonly operation: "full_reversal";
109
+ readonly correctionRef: string;
110
+ readonly parentProviderDocumentRef: string;
111
+ };
112
+ readonly before: InvoiceFacts;
113
+ readonly after: {
114
+ readonly totalNetMinor: 0;
115
+ readonly totalTaxMinor: 0;
116
+ readonly totalGrossMinor: 0;
117
+ };
118
+ readonly reason: string;
119
+ readonly recoveryLookupRequired: boolean;
120
+ }): Promise<InvoiceWriteResult>;
121
+ read(input: InvoiceIdentity): Promise<InvoiceReadbackResult>;
122
+ /** Remote void stays cut; always refuse before I/O, never substitute local void. */
123
+ void(input: InvoiceIdentity & {
124
+ readonly operation: "remote_void";
125
+ }): Promise<InvoiceUnsupported>;
126
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,66 @@
1
+ import type { InvoiceProof, InvoiceUnsupported } from "./provider.js";
2
+ /** One immutable balance item, never unique by batch+payment alone.
3
+ * Carrier: accountingControlContracts settlement + payout balance transaction ID.
4
+ * Null links and bankReceivedAt are facts; settlement is not an invoice gate.
5
+ * @consumer Host payout item recorder.
6
+ */
7
+ export interface InvoiceSettlementItem {
8
+ readonly requestKey: string;
9
+ readonly providerRef: string;
10
+ readonly batchRef: string;
11
+ readonly itemRef: string;
12
+ readonly providerPaymentRef: string;
13
+ readonly paymentIntentRef: string | null;
14
+ readonly paymentRef: string | null;
15
+ readonly invoiceRef: string | null;
16
+ readonly grossMinor: number;
17
+ readonly feeMinor: number;
18
+ readonly netMinor: number;
19
+ readonly currency: string;
20
+ readonly status: "matched" | "unmatched" | "mismatch" | "bank_pending";
21
+ readonly bankReceivedAt: string | null;
22
+ readonly proof: InvoiceProof;
23
+ }
24
+ type ItemScope = Pick<InvoiceSettlementItem, "providerRef" | "batchRef" | "itemRef" | "providerPaymentRef">;
25
+ export type InvoiceSettlementResult = {
26
+ readonly kind: "found";
27
+ readonly scope: ItemScope;
28
+ readonly paymentIntentRef: string | null;
29
+ readonly paymentRef: string | null;
30
+ readonly invoiceRef: string | null;
31
+ readonly proof: InvoiceProof;
32
+ } | {
33
+ readonly kind: "absent";
34
+ readonly scope: ItemScope;
35
+ readonly evidence: InvoiceProof & {
36
+ readonly exact: true;
37
+ readonly complete: true;
38
+ readonly scope: ItemScope;
39
+ };
40
+ } | {
41
+ readonly kind: "recorded";
42
+ readonly itemRef: string;
43
+ readonly settlementItemRef: string;
44
+ readonly replayed: boolean;
45
+ } | {
46
+ readonly kind: "conflict";
47
+ readonly itemRef: string;
48
+ readonly code: "identity_mismatch" | "money_mismatch";
49
+ } | {
50
+ readonly kind: "unknown";
51
+ readonly itemRef: string;
52
+ readonly code: "unknown";
53
+ } | InvoiceUnsupported;
54
+ /** Host recorder/resolver owns richer item identity. Unsupported before any write
55
+ * when a native batch/payment row cannot represent distinct items or nullable links.
56
+ * @consumer Host payout item recorder/resolver.
57
+ */
58
+ export interface InvoiceSettlementPort {
59
+ record(item: InvoiceSettlementItem): Promise<Exclude<InvoiceSettlementResult, {
60
+ kind: "found" | "absent";
61
+ }>>;
62
+ resolve(input: ItemScope): Promise<Exclude<InvoiceSettlementResult, {
63
+ kind: "recorded" | "conflict";
64
+ }>>;
65
+ }
66
+ export {};
@@ -0,0 +1 @@
1
+ export {};