@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,533 @@
1
+ import type { PaymentAttemptStatus, PaymentExecutionBaseInput, PaymentExecutionBaseResult, PaymentProviderCapabilityDescriptor, ProviderAttemptIdentity } from "@openlup/core/payment";
2
+ /** Structural hosted-cycle contracts; native vocabulary is bound by the caller. */
3
+ export type SubscriptionRenewalOutcome = "charged" | "requires_action" | "failed" | "skipped";
4
+ export interface HostedRenewalDue {
5
+ subscriptionId: string;
6
+ nextCycleAt: string;
7
+ providerKind: string;
8
+ providerMethodRef: string | null;
9
+ }
10
+ export interface SubscriptionRenewalChargeResult {
11
+ subscriptionId: string;
12
+ outcome: SubscriptionRenewalOutcome;
13
+ cycleId: string | null;
14
+ cycleNumber: number | null;
15
+ orderId: string | null;
16
+ paymentIntentId: string | null;
17
+ attemptStatus: PaymentAttemptStatus | null;
18
+ replayed: boolean;
19
+ dunningCaseId?: string | null;
20
+ retryAttempt?: number | null;
21
+ applyReplayed?: boolean;
22
+ dunningPropagationFailed?: boolean;
23
+ reason?: string;
24
+ admissionDeferralReference?: string;
25
+ }
26
+ export interface SubscriptionCycleSnapshotResult {
27
+ cycleNumber: number;
28
+ retryAttempt: number;
29
+ providerAttemptSequence: number;
30
+ templateSnapshot: Record<string, unknown>;
31
+ pricingSnapshot: Record<string, unknown>;
32
+ orderSnapshot: Record<string, unknown>;
33
+ }
34
+ export interface SubscriptionCycleOrderInput {
35
+ idempotencyKey: string;
36
+ subscriptionId: string;
37
+ cycleNumber: number;
38
+ scheduledAt: string;
39
+ templateSnapshot: Record<string, unknown>;
40
+ pricingSnapshot: Record<string, unknown>;
41
+ orderSnapshot: Record<string, unknown>;
42
+ }
43
+ export interface SubscriptionCycleOrderResult {
44
+ cycleId: string;
45
+ orderRef: string;
46
+ orderUuid: string;
47
+ paymentRef: string;
48
+ replayed: boolean;
49
+ }
50
+ export interface SubscriptionReservationPreflightResult {
51
+ ok: boolean;
52
+ reason: string | null;
53
+ itemsChecked: number;
54
+ reacquired: number;
55
+ }
56
+ export interface SubscriptionRenewalPersistencePort<M extends string | null | undefined = string | null | undefined> {
57
+ buildCycleSnapshots(input: {
58
+ subscriptionId: string;
59
+ scheduledAt: string;
60
+ }): Promise<SubscriptionCycleSnapshotResult>;
61
+ createCycleOrder(input: SubscriptionCycleOrderInput): Promise<SubscriptionCycleOrderResult>;
62
+ preflightReservation(input: {
63
+ orderId: string;
64
+ now: string;
65
+ }): Promise<SubscriptionReservationPreflightResult>;
66
+ readMandateRecurringModel(providerKind: string, providerMethodRef: string | null): Promise<M>;
67
+ noteRowOutcome(input: {
68
+ subscriptionId: string;
69
+ scheduledAt: string;
70
+ errorKey: string | null;
71
+ }): Promise<void>;
72
+ }
73
+ export type FailurePropagationKind = "off_session_requires_action" | "provider_declined" | "preflight_block";
74
+ export interface FailurePropagationContext {
75
+ kind: FailurePropagationKind;
76
+ executionIdempotencyKey: string;
77
+ providerIdempotencyKey: string;
78
+ providerRequestFingerprint: string;
79
+ paymentIntentId: string;
80
+ cycleId: string;
81
+ subscriptionId: string;
82
+ orderUuid: string;
83
+ providerKind: string;
84
+ failureReason: string;
85
+ failureClassification?: {
86
+ failureClass: string;
87
+ decidedBy: string;
88
+ } | null;
89
+ occurredAt: string;
90
+ attemptAlreadyPrepared?: boolean;
91
+ }
92
+ export interface CycleRetryState {
93
+ retryAttempt: number | null;
94
+ nextRetryAt: string | null;
95
+ rowPresent: boolean;
96
+ }
97
+ export type DunningCaseOpenOutcome = {
98
+ status: "opened";
99
+ caseId: string | null;
100
+ } | {
101
+ status: "rejected";
102
+ reason: string;
103
+ code?: string;
104
+ } | {
105
+ status: "unavailable";
106
+ reason: string;
107
+ };
108
+ export interface CycleChargeFailurePropagationPort {
109
+ recordBlockedPreflightAttempt(input: {
110
+ idempotencyKey: string;
111
+ paymentIntentId: string;
112
+ providerKind: string;
113
+ providerIdempotencyKey: string;
114
+ providerRequestFingerprint: string;
115
+ failureReason: string;
116
+ }): Promise<void>;
117
+ readDurableAttemptInstant(input: {
118
+ paymentIntentId: string;
119
+ attemptIdempotencyKey: string;
120
+ }): Promise<string | null>;
121
+ applyFailedResult(input: {
122
+ idempotencyKey: string;
123
+ paymentIntentId: string;
124
+ occurredAt: string;
125
+ failureReason: string;
126
+ failureClassification: {
127
+ failureClass: string;
128
+ decidedBy: string;
129
+ };
130
+ }): Promise<{
131
+ replayed: boolean;
132
+ }>;
133
+ readCycleRetryState(cycleId: string): Promise<CycleRetryState>;
134
+ openDunningCase(input: {
135
+ idempotencyKey: string;
136
+ cycleId: string;
137
+ subscriptionId: string;
138
+ orderUuid: string;
139
+ paymentIntentId: string;
140
+ retryAttempt: number;
141
+ nextRetryAt: string | null;
142
+ failureReason: string;
143
+ occurredAt: string;
144
+ failureClass: string;
145
+ }): Promise<DunningCaseOpenOutcome>;
146
+ }
147
+ export interface FailurePropagationResult {
148
+ dunningCaseId: string | null;
149
+ retryAttempt: number | null;
150
+ applyReplayed: boolean;
151
+ dunningPropagationFailed: boolean;
152
+ }
153
+ export type RenewalPrepareInput<P extends string> = Parameters<RenewalPreparedAttemptPersistencePort<P, string>["prepareProviderAttempt"]>[0];
154
+ export type RenewalAttemptResult<N extends string> = Awaited<ReturnType<RenewalPreparedAttemptPersistencePort<string, N>["finalizeProviderAttempt"]>>;
155
+ export interface RenewalIntentResult {
156
+ paymentIntentId: string;
157
+ replayed: boolean;
158
+ }
159
+ export interface RenewalPaymentPort<CI, IR extends RenewalIntentResult, P extends string, N extends string> extends RenewalPreparedAttemptPersistencePort<P, N> {
160
+ createIntent(input: CI): Promise<IR>;
161
+ }
162
+ export interface RenewalExecutionPort<I extends PaymentExecutionBaseInput, R extends PaymentExecutionBaseResult> {
163
+ execute(input: I): Promise<R>;
164
+ }
165
+ export interface RenewalDeliveryAdmission {
166
+ allowed: boolean;
167
+ state: string;
168
+ reason: string;
169
+ }
170
+ export type RenewalAllowedAdmission = RenewalDeliveryAdmission & {
171
+ allowed: true;
172
+ };
173
+ export interface RenewalDeliveryClient {
174
+ admitDeliveryAlignment(input: {
175
+ subscriptionId: string;
176
+ scheduledAt: string;
177
+ asOf: string;
178
+ }): Promise<RenewalDeliveryAdmission>;
179
+ }
180
+ export interface RenewalFailureDeps {
181
+ chargeFailurePropagation: CycleChargeFailurePropagationPort;
182
+ now?: () => string;
183
+ }
184
+ export interface RenewalPreflightDeps<CI, IR extends RenewalIntentResult, M extends string | null | undefined> extends RenewalFailureDeps {
185
+ persistence: SubscriptionRenewalPersistencePort<M>;
186
+ paymentPort: {
187
+ createIntent(input: CI): Promise<IR>;
188
+ };
189
+ }
190
+ export interface RenewalCycleDeps<CI, IR extends RenewalIntentResult, P extends string, N extends string, I extends PaymentExecutionBaseInput, R extends PaymentExecutionBaseResult, M extends string | null | undefined> extends RenewalPreflightDeps<CI, IR, M> {
191
+ paymentPort: RenewalPaymentPort<CI, IR, P, N>;
192
+ executionPort: RenewalExecutionPort<I, R>;
193
+ deliveryAlignment: RenewalDeliveryClient;
194
+ capability: PaymentProviderCapabilityDescriptor;
195
+ deliveryAlignmentAdmission?: RenewalAllowedAdmission;
196
+ }
197
+ /** Local references, never a snapshot of the original due/ports or their getters. */
198
+ export interface RenewalExecutionContext<IR extends RenewalIntentResult, M extends string | null | undefined, F extends string> {
199
+ snapshots: SubscriptionCycleSnapshotResult;
200
+ cycleOrder: SubscriptionCycleOrderResult;
201
+ intent: IR;
202
+ totalGrossMinor: number;
203
+ executionIdempotencyKey: string;
204
+ attemptIdentity: ProviderAttemptIdentity;
205
+ providerFlow: F;
206
+ paymentMethodRecurringModel: M | undefined;
207
+ }
208
+ export interface RenewalOutcomeContext {
209
+ executionIdempotencyKey: string;
210
+ attemptIdentity: ProviderAttemptIdentity;
211
+ intent: RenewalIntentResult;
212
+ cycleOrder: Pick<SubscriptionCycleOrderResult, "cycleId" | "orderUuid" | "replayed">;
213
+ snapshots: Pick<SubscriptionCycleSnapshotResult, "cycleNumber">;
214
+ finalizedAttempt: {
215
+ status: PaymentAttemptStatus;
216
+ };
217
+ }
218
+ export interface RenewalReplayContext {
219
+ cycleId: string;
220
+ cycleNumber: number;
221
+ orderId: string;
222
+ paymentIntentId: string;
223
+ executionIdempotencyKey: string;
224
+ providerIdempotencyKey: string;
225
+ providerRequestFingerprint: string;
226
+ providerKind: string;
227
+ }
228
+ /** Durable preparation facts; provider admission belongs to the caller. */
229
+ export interface RenewalPreparedAttemptPrepareInput<P extends string = string> {
230
+ idempotencyKey: string;
231
+ paymentIntentId: string;
232
+ provider: P;
233
+ providerIdempotencyKey: string;
234
+ providerRequestFingerprint: string;
235
+ providerFlow: string;
236
+ paymentMethodRef?: string | null;
237
+ requestPayload: Record<string, unknown>;
238
+ }
239
+ export interface RenewalPreparedAttemptPersistenceResult<N extends string = string> {
240
+ paymentAttemptId: string;
241
+ status: PaymentAttemptStatus;
242
+ replayed: boolean;
243
+ providerAttemptId: string | null;
244
+ providerSessionId: string | null;
245
+ nextActionKind: N | null;
246
+ }
247
+ export interface RenewalPreparedAttemptFinalizeInput<N extends string = string> extends Pick<PaymentExecutionBaseResult, "providerAttemptId" | "providerSessionId" | "attemptStatus" | "requestPayload" | "responsePayload"> {
248
+ idempotencyKey: string;
249
+ paymentIntentId: string;
250
+ paymentAttemptId: string;
251
+ providerIdempotencyKey: string;
252
+ providerRequestFingerprint: string;
253
+ nextActionKind: N | null;
254
+ }
255
+ /** Only persistence capabilities needed by interactive attempt ordering. */
256
+ export interface RenewalPreparedAttemptPersistencePort<P extends string = string, N extends string = string> {
257
+ prepareProviderAttempt(input: RenewalPreparedAttemptPrepareInput<P>): Promise<RenewalPreparedAttemptPersistenceResult<N>>;
258
+ finalizeProviderAttempt(input: RenewalPreparedAttemptFinalizeInput<N>): Promise<RenewalPreparedAttemptPersistenceResult<N>>;
259
+ }
260
+ /** Original text is an identity input; instant is for comparisons only. */
261
+ export interface RenewalSchedule {
262
+ subscriptionId: string;
263
+ scheduledAt: string;
264
+ scheduledInstant: number;
265
+ }
266
+ export interface RenewalIdentity {
267
+ cycleIdempotencyKey: string;
268
+ executionIdempotencyKey: string;
269
+ externalIdempotencyKey: string;
270
+ requestFingerprint: string;
271
+ }
272
+ export type RenewalAdmission = {
273
+ allowed: true;
274
+ state: string;
275
+ reason: string;
276
+ } | {
277
+ allowed: false;
278
+ state: string;
279
+ reason: string;
280
+ deferred: true;
281
+ caseRef?: string;
282
+ } | {
283
+ allowed: false;
284
+ state: string;
285
+ reason: string;
286
+ deferred: false;
287
+ };
288
+ export interface RenewalLine {
289
+ lineOrdinal: number;
290
+ sku: string;
291
+ quantity: number;
292
+ unitAmountMinor: number;
293
+ }
294
+ /** Logical numbering is evidence-bound, never a universal nativeCounter + 1. */
295
+ export type RenewalCycleCorrelation = {
296
+ status: "correlated";
297
+ logicalCycleNumber: number;
298
+ nativeRenewalCounter: number | null;
299
+ activationCycleId: string | null;
300
+ evidenceRef: string;
301
+ } | {
302
+ status: "ambiguous";
303
+ logicalCycleNumber: null;
304
+ nativeRenewalCounter: number | null;
305
+ activationCycleId: string | null;
306
+ reason: string;
307
+ };
308
+ export interface RenewalTemplateSnapshot {
309
+ templateId: string;
310
+ version: number;
311
+ cadenceDays: number;
312
+ lines: readonly RenewalLine[];
313
+ }
314
+ export interface RenewalPricingSnapshot {
315
+ currency: string;
316
+ totalAmountMinor: number;
317
+ shippingAmountMinor: number;
318
+ agreementPolicy: "lock_until_edit";
319
+ proration: "none";
320
+ }
321
+ export interface RenewalOrderSnapshot {
322
+ shippingAddressRef: string | null;
323
+ shippingQuoteRef: string | null;
324
+ acquisitionRef: string | null;
325
+ lines: readonly RenewalLine[];
326
+ }
327
+ export interface RenewalFrozenSnapshot extends RenewalSchedule {
328
+ contractVersion: "platform.subscription.renewal.v1";
329
+ clientId: string;
330
+ frozenRevision: string;
331
+ frozenFingerprint: string;
332
+ cycle: RenewalCycleCorrelation;
333
+ retryAttempt: number;
334
+ externalAttemptSequence: number;
335
+ templateSnapshot: RenewalTemplateSnapshot;
336
+ pricingSnapshot: RenewalPricingSnapshot;
337
+ orderSnapshot: RenewalOrderSnapshot;
338
+ stockSourceKey: string;
339
+ settlementChannelKey: string;
340
+ authorizationRef: string;
341
+ payerAccountRef: string | null;
342
+ unattendedChargeAuthorizedAt: string;
343
+ }
344
+ export interface RenewalDue extends RenewalSchedule {
345
+ clientId: string;
346
+ cadenceDays: number;
347
+ cycle: RenewalCycleCorrelation;
348
+ currency: string;
349
+ stockSourceKey: string;
350
+ settlementChannelKey: string;
351
+ authorizationRef: string;
352
+ payerAccountRef: string | null;
353
+ unattendedChargeAuthorizedAt: string;
354
+ deliveryAdmission: "allowed" | "blocked";
355
+ deliveryBlockReason: string | null;
356
+ }
357
+ export type RenewalOperationState = "claimed" | "reserved" | "attempt_prepared" | "succeeded" | "refused";
358
+ export interface RenewalReadback extends RenewalSchedule {
359
+ contractVersion: "platform.subscription.renewal.v1";
360
+ acquired: boolean;
361
+ replayed: boolean;
362
+ reason: string;
363
+ operationId: string;
364
+ identityKey: string;
365
+ operationFingerprint: string;
366
+ cycle: RenewalCycleCorrelation;
367
+ state: RenewalOperationState;
368
+ claimToken: string;
369
+ claimGeneration: number;
370
+ leaseExpiresAt: string;
371
+ cycleSnapshot: RenewalFrozenSnapshot;
372
+ externalAttemptRef: string | null;
373
+ externalAttemptAcknowledgedAt: string | null;
374
+ terminalOutcome: "succeeded" | "refused" | null;
375
+ terminalReason: string | null;
376
+ terminalAt: string | null;
377
+ reservationId: string | null;
378
+ cycleId: string | null;
379
+ orderId: string | null;
380
+ settlementIntentId: string | null;
381
+ }
382
+ /** M07 verified truth. Nullable money is not positive matching evidence. */
383
+ export interface RenewalPaymentEvidence {
384
+ status: "succeeded" | "failed" | "pending" | "unknown";
385
+ disposition: "observed" | "ambiguous" | "late_positive";
386
+ operationId: string;
387
+ eventKey: string;
388
+ requestFingerprint: string;
389
+ verifiedEvidenceRef: string;
390
+ externalAttemptRef: string | null;
391
+ occurredAt: string | null;
392
+ observedAt: string;
393
+ firstRecordedAt: string;
394
+ amountMinor: number | null;
395
+ currency: string | null;
396
+ reason: string | null;
397
+ }
398
+ /** Payment execution is outside all SQL transactions. */
399
+ export type RenewalTransactionUnits = {
400
+ graph: "native";
401
+ prepare: "cycle_order_items_settlement_reservation_attempt";
402
+ outcome: "settlement_outcome_schedule_counter_reservation";
403
+ recovery: "settlement_cycle_receipt_case_counter";
404
+ } | {
405
+ graph: "managed";
406
+ prepare: "create_cycle_order_then_prepare_attempt";
407
+ failure: "record_attempt_then_apply_result_then_open_case";
408
+ recovery: "authorize_method_then_schedule";
409
+ };
410
+ export interface RenewalReservationResult {
411
+ reserved: boolean;
412
+ replayed: boolean;
413
+ reservationId: string | null;
414
+ status: "held" | "committed" | "consumed" | "released" | "expired" | "refused";
415
+ reason: string | null;
416
+ }
417
+ export interface RenewalPreparedSettlement {
418
+ contractVersion: "platform.subscription.renewal.v1";
419
+ replayed: boolean;
420
+ operationId: string;
421
+ operationFingerprint: string;
422
+ cycleId: string;
423
+ orderId: string;
424
+ settlementIntentId: string;
425
+ state: "attempt_prepared";
426
+ }
427
+ export interface RenewalStorePort {
428
+ readonly transactions: RenewalTransactionUnits;
429
+ listDue(limit: number, asOf: string): Promise<RenewalDue[]>;
430
+ buildCycleSnapshots(input: RenewalSchedule): Promise<RenewalFrozenSnapshot>;
431
+ readMandateEvidence(input: RenewalSchedule): Promise<{
432
+ authorized: boolean;
433
+ authorizationRef: string;
434
+ authorizedAt: string | null;
435
+ }>;
436
+ admitDeliveryAlignment(input: RenewalSchedule & {
437
+ occurredAt: string;
438
+ }): Promise<RenewalAdmission>;
439
+ claimDue(input: {
440
+ snapshot: RenewalFrozenSnapshot;
441
+ workerId: string;
442
+ leaseSeconds?: number;
443
+ now: string;
444
+ }): Promise<RenewalReadback>;
445
+ readRenewal(identityKey: string): Promise<RenewalReadback | null>;
446
+ refuseBeforePayment(input: {
447
+ operationId: string;
448
+ claimToken: string;
449
+ reason: string;
450
+ occurredAt: string;
451
+ }): Promise<RenewalReadback>;
452
+ }
453
+ export interface RenewalSettlementPort {
454
+ prepareRenewal(input: {
455
+ operationId: string;
456
+ claimToken: string;
457
+ now: string;
458
+ }): Promise<RenewalPreparedSettlement>;
459
+ acknowledgeExternalAttempt(input: {
460
+ operationId: string;
461
+ operationFingerprint: string;
462
+ externalAttemptRef: string;
463
+ acknowledgedAt: string;
464
+ }): Promise<RenewalReadback>;
465
+ recordTerminalOutcome(input: {
466
+ operationId: string;
467
+ eventKey: string;
468
+ operationFingerprint: string;
469
+ outcome: "succeeded" | "refused";
470
+ externalRef?: string | null;
471
+ reason?: string | null;
472
+ occurredAt: string;
473
+ }): Promise<RenewalReadback>;
474
+ }
475
+ export interface RenewalExecutionRequest extends RenewalIdentity {
476
+ paymentIntentId: string;
477
+ amountMinor: number;
478
+ currency: string;
479
+ mode: string;
480
+ orderRef: string;
481
+ orderId: string;
482
+ flow: string;
483
+ customerRef: string | null;
484
+ paymentMethodRef: string;
485
+ recurringModel: string | null;
486
+ clientId: string;
487
+ payer: {
488
+ email: string | null;
489
+ name: string | null;
490
+ } | null;
491
+ }
492
+ export interface RenewalPaymentRail {
493
+ execute(input: RenewalExecutionRequest): Promise<{
494
+ status: "succeeded" | "failed" | "requires_action" | "pending" | "unknown";
495
+ externalAttemptRef: string | null;
496
+ failure?: {
497
+ reason: string;
498
+ failureClass: string;
499
+ };
500
+ }>;
501
+ findExternalAttempt(input: {
502
+ settlementIntentId: string;
503
+ }): Promise<string | null>;
504
+ readOutcome(input: {
505
+ externalAttemptRef: string;
506
+ settlementIntentId: string;
507
+ orderId: string;
508
+ subscriptionId: string;
509
+ amountMinor: number;
510
+ currency: string;
511
+ }): Promise<RenewalPaymentEvidence>;
512
+ }
513
+ export type RenewalResult = {
514
+ outcome: "deferred";
515
+ subscriptionId: string;
516
+ scheduledAt: string;
517
+ reason: string;
518
+ caseRef?: string;
519
+ } | {
520
+ outcome: "charged" | "requires_action" | "failed" | "skipped";
521
+ subscriptionId: string;
522
+ cycleId: string | null;
523
+ cycleNumber: number | null;
524
+ orderId: string | null;
525
+ paymentIntentId: string | null;
526
+ attemptStatus: string | null;
527
+ replayed: boolean;
528
+ dunningCaseId?: string | null;
529
+ retryAttempt?: number | null;
530
+ applyReplayed?: boolean;
531
+ dunningPropagationFailed?: boolean;
532
+ reason?: string;
533
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
1
+ import type { RenewalFrozenSnapshot, RenewalReadback, RenewalSchedule } from "./renewal.js";
2
+ export interface StockWaitRecoveryBinding {
3
+ caseId: string | null;
4
+ cycleId: string | null;
5
+ orderId: string | null;
6
+ paymentId: string | null;
7
+ engineIdempotencyKey: string | null;
8
+ }
9
+ export interface StockWaitDeficit {
10
+ skuId: string;
11
+ sku: string;
12
+ displayName: string;
13
+ size: string | null;
14
+ required: number;
15
+ reserved: number;
16
+ available: number;
17
+ missing: number;
18
+ }
19
+ export interface StockWaitCase extends RenewalSchedule {
20
+ caseId: string;
21
+ clientId: string;
22
+ state: "waiting" | "stock_secured" | "resumed" | "closed";
23
+ frozenSnapshot: RenewalFrozenSnapshot;
24
+ frozenFingerprint: string;
25
+ binding: StockWaitRecoveryBinding;
26
+ deficits: readonly StockWaitDeficit[];
27
+ fulfillmentRef: string | null;
28
+ blockReason: string | null;
29
+ openedAt: string;
30
+ checkedAt: string | null;
31
+ selectedAt: string | null;
32
+ securedAt: string | null;
33
+ resumedAt: string | null;
34
+ closedAt: string | null;
35
+ startedNoticeKey: string;
36
+ resumedNoticeKey: string;
37
+ noticeEligible: boolean;
38
+ }
39
+ /** All-line reserve/reacquire and the wait transition share a DB transaction.
40
+ * A shortage rolls back the subtransaction, retaining previous commitments;
41
+ * record the wait outside that failed subtransaction. Technical failure is unknown.
42
+ */
43
+ export interface StockWaitStorePort {
44
+ listCandidates(input: {
45
+ limit: number;
46
+ asOf: string;
47
+ }): Promise<StockWaitCase[]>;
48
+ readFrozenCase(input: StockWaitRecoveryBinding): Promise<StockWaitCase | null>;
49
+ reserveAndTransition(input: {
50
+ caseId: string;
51
+ frozenFingerprint: string;
52
+ now: string;
53
+ }): Promise<StockWaitCase>;
54
+ /** Only elapsed, unprepared, unacknowledged, stock-only refusals may reset.
55
+ * Requires unchanged schedule/fingerprint and no payment artifacts or outcomes.
56
+ * Rotate fencing generation atomically with reacquisition. Never reset ambiguity.
57
+ */
58
+ recoverRefusedSchedule(input: {
59
+ operationId: string;
60
+ caseId: string;
61
+ claimGeneration: number;
62
+ frozenFingerprint: string;
63
+ scheduledAt: string;
64
+ now: string;
65
+ }): Promise<{
66
+ outcome: "recovered";
67
+ operation: RenewalReadback;
68
+ replayed: boolean;
69
+ } | {
70
+ outcome: "refused";
71
+ reason: "not_stock_only" | "external_ownership" | "stale_snapshot" | "lease_active" | "inventory_unavailable";
72
+ }>;
73
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ export { renewalIdentity } from "./renewalIdentity.js";
2
+ export declare const NATIVE_SUBSCRIPTION_CAPABILITIES: Readonly<{
3
+ readonly graph: "native";
4
+ readonly multiCyclePrepaid: Readonly<{
5
+ supported: false;
6
+ refusalCode: "multi_cycle_prepaid_unsupported";
7
+ }>;
8
+ readonly genericBundleCommands: Readonly<{
9
+ supported: false;
10
+ refusalCode: "native_generic_bundle_commands_unsupported";
11
+ }>;
12
+ readonly commandBoundReceipts: Readonly<{
13
+ supported: false;
14
+ refusalCode: "native_command_bound_receipts_unsupported";
15
+ }>;
16
+ readonly preparedAttemptStore: Readonly<{
17
+ supported: false;
18
+ refusalCode: "native_prepared_attempt_store_unsupported";
19
+ }>;
20
+ readonly retryRecovery: "selected";
21
+ readonly stockRecovery: "unavailable";
22
+ readonly deliveryAdmission: "required";
23
+ readonly executorCount: 1;
24
+ readonly defaultEnabled: false;
25
+ }>;
26
+ export { executeRenewalCycle, prepareRenewalAttempt, checkRenewalDeliveryAdmission } from "./renewalCycleMechanism.js";
27
+ export type { RenewalCyclePolicy } from "./renewalCycleMechanism.js";
28
+ export { recordRenewalPreflightBlock, replayRenewalAttempt, declinedRenewalOutcome, requiresActionRenewalOutcome } from "./renewalCycleRefusalMechanism.js";
29
+ export type { RenewalPreflightPolicy, RenewalReplayPolicy, RenewalOutcomePolicy } from "./renewalCycleRefusalMechanism.js";
30
+ export { propagateRenewalFailure } from "./renewalCycleFailureMechanism.js";
31
+ export type { RenewalFailurePolicy } from "./renewalCycleFailureMechanism.js";
32
+ export { runAutomaticSubscriptionRenewals, runOneAutomaticSubscriptionRenewal, correlatedLogicalCycle } from "./automaticRenewal.js";
33
+ export type { AutomaticRenewalRunStatus, AutomaticRenewalRunResult, AutomaticRenewalRunDeps, AutomaticRenewalPolicy } from "./automaticRenewal.js";
34
+ export { createPostgresRenewalStore } from "./postgresRenewalStore.js";
35
+ export type { NativeRenewalCodec, SubscriptionQueryExecutor } from "./postgresRenewalStore.js";
36
+ export { createPostgresRetryStore } from "./postgresRetryStore.js";
37
+ export type { NativeRetryFailure, NativeRetryRequest, NativeRetryPositive, NativeRetryPreparation, NativeRetryRow } from "./postgresRetryStore.js";
38
+ export { createPostgresRetryLifecycleBinding } from "./postgresRetryStore.js";
39
+ export type { NativeRetryLifecycleBinding } from "./postgresRetryStore.js";
@@ -0,0 +1,17 @@
1
+ export { renewalIdentity } from "./renewalIdentity.js";
2
+ export const NATIVE_SUBSCRIPTION_CAPABILITIES = Object.freeze({
3
+ graph: "native",
4
+ multiCyclePrepaid: Object.freeze({ supported: false, refusalCode: "multi_cycle_prepaid_unsupported" }),
5
+ genericBundleCommands: Object.freeze({ supported: false, refusalCode: "native_generic_bundle_commands_unsupported" }),
6
+ commandBoundReceipts: Object.freeze({ supported: false, refusalCode: "native_command_bound_receipts_unsupported" }),
7
+ preparedAttemptStore: Object.freeze({ supported: false, refusalCode: "native_prepared_attempt_store_unsupported" }),
8
+ retryRecovery: "selected", stockRecovery: "unavailable",
9
+ deliveryAdmission: "required", executorCount: 1, defaultEnabled: false,
10
+ });
11
+ export { executeRenewalCycle, prepareRenewalAttempt, checkRenewalDeliveryAdmission } from "./renewalCycleMechanism.js";
12
+ export { recordRenewalPreflightBlock, replayRenewalAttempt, declinedRenewalOutcome, requiresActionRenewalOutcome } from "./renewalCycleRefusalMechanism.js";
13
+ export { propagateRenewalFailure } from "./renewalCycleFailureMechanism.js";
14
+ export { runAutomaticSubscriptionRenewals, runOneAutomaticSubscriptionRenewal, correlatedLogicalCycle } from "./automaticRenewal.js";
15
+ export { createPostgresRenewalStore } from "./postgresRenewalStore.js";
16
+ export { createPostgresRetryStore } from "./postgresRetryStore.js";
17
+ export { createPostgresRetryLifecycleBinding } from "./postgresRetryStore.js";
@@ -0,0 +1,8 @@
1
+ import type { RenewalPaymentRail, RenewalReadback } from "./contracts/renewal.js";
2
+ import type { AutomaticRenewalRunDeps, AutomaticRenewalRunResult } from "./automaticRenewal.js";
3
+ /** H4: only explicit verified matching M07 evidence may become positive local truth. */
4
+ export declare function readAndApplyProviderOutcome(deps: AutomaticRenewalRunDeps, operation: RenewalReadback, prepared: {
5
+ cycleId: string;
6
+ orderId: string;
7
+ settlementIntentId: string;
8
+ }, rail: RenewalPaymentRail, externalAttemptRef: string, occurredAt: string): Promise<AutomaticRenewalRunResult>;