@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,72 @@
1
+ import type { NormalizedFulfillmentFact } from "@openlup/core/fulfillment";
2
+ import type { CanonicalLocalFulfillmentStatus } from "./index.js";
3
+ import type { FulfillmentRefusal } from "./dispatch.js";
4
+ /** Explicit adopter policy, forwarded through each durable observation projection. */
5
+ export interface FulfillmentObservationCodecs {
6
+ approveReference?(value: string): boolean;
7
+ /** Overrides the query/fragment default; HTTPS, no credentials and URL approval still apply. */
8
+ trackingUrl?(url: string): string | null;
9
+ }
10
+ export interface FulfillmentTrackingReference {
11
+ trackingNumber: string; /** Normalized carrier kind, never a raw provider code. */
12
+ carrierRef: string | null;
13
+ serviceRef: string | null;
14
+ publicUrl: string | null;
15
+ }
16
+ /** Durable normalized envelope. eventKey, not the receivedAt-bearing fact fingerprint, deduplicates retries. */
17
+ export interface FulfillmentObservation {
18
+ fact: NormalizedFulfillmentFact<CanonicalLocalFulfillmentStatus>;
19
+ eventKind: "shipment.accepted" | "order.processing_started" | "order.picked" | "order.shipped" | "order.delivered" | "parcel.exception" | "parcel.cancelled";
20
+ eventKey: string;
21
+ firstReceivedAt: string;
22
+ correlation: {
23
+ orderRef: string | null;
24
+ fulfillmentRef: string | null;
25
+ externalRef: string | null;
26
+ orderNumber: string | null;
27
+ providerFulfillmentRef: string | null;
28
+ parcelRef: string | null;
29
+ };
30
+ trackingRefs: readonly FulfillmentTrackingReference[];
31
+ /** Original provider status tokens; canonical status does not identify an occurrence. */
32
+ providerStatus?: {
33
+ primary: string | null;
34
+ subStatus: string | null;
35
+ };
36
+ diagnostics?: {
37
+ redactedFieldCount?: number;
38
+ admission?: {
39
+ rejectedTrackingRefs: number;
40
+ rejectedTrackingUrls: number;
41
+ };
42
+ refusal?: FulfillmentRefusal;
43
+ stockContention?: {
44
+ sqlState: "55P03";
45
+ phase: "provider_stock_consumed";
46
+ retryable: true;
47
+ };
48
+ annotation?: "recorded" | "failed";
49
+ recoveredPickedReceipt?: {
50
+ receiptRef: string;
51
+ closed: boolean;
52
+ };
53
+ };
54
+ }
55
+ export interface FulfillmentObservationPort {
56
+ /** Authenticate untouched bytes before parsing. Inputs live only during verification. */
57
+ verifyAndNormalize(input: {
58
+ rawBody: Uint8Array;
59
+ headers: Readonly<Record<string, string>>;
60
+ receivedAt: string;
61
+ }): Promise<{
62
+ kind: "verified";
63
+ observation: FulfillmentObservation;
64
+ } | {
65
+ kind: "refused";
66
+ refusal: FulfillmentRefusal;
67
+ diagnostics?: {
68
+ invalidTimestamp?: true;
69
+ rejectedCorrelationRefs?: number;
70
+ };
71
+ }>;
72
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ import type { FulfillmentNativeUnsupported } from './nativeUnsupported.js';
2
+ /** Host transaction inputs. actorUserId and idempotencyKey are required for attribution and replay receipts. */
3
+ interface MutationInput {
4
+ idempotencyKey: string;
5
+ actorUserId: string;
6
+ metadata?: Record<string, unknown>;
7
+ }
8
+ interface ParcelMutationInput extends MutationInput {
9
+ fulfillmentOrderId: string;
10
+ }
11
+ type AdminCommerceFulfillmentCreateRequest = MutationInput & {
12
+ orderId: string;
13
+ };
14
+ type AdminCommerceFulfillmentRecordProviderAttemptRequest = ParcelMutationInput & {
15
+ providerKind: string;
16
+ status: 'recorded' | 'succeeded' | 'failed';
17
+ requestPayload?: Record<string, unknown>;
18
+ responsePayload?: Record<string, unknown>;
19
+ error?: string | null;
20
+ };
21
+ type AdminCommerceFulfillmentRecordLabelRequest = ParcelMutationInput & {
22
+ providerKind: string;
23
+ providerTrackingId: string;
24
+ labelUrl?: string | null;
25
+ deliveryEstimateDays?: number | null;
26
+ rawProviderPayload?: Record<string, unknown>;
27
+ };
28
+ type AdminCommerceFulfillmentHandOffRequest = ParcelMutationInput;
29
+ type AdminCommerceFulfillmentTrackingEventRequest = ParcelMutationInput & {
30
+ status: 'in_transit' | 'delivered' | 'exception';
31
+ providerTrackingId?: string;
32
+ rawEvent?: Record<string, unknown>;
33
+ };
34
+ type AdminCommerceFulfillmentCancelRequest = ParcelMutationInput & {
35
+ reason: string;
36
+ };
37
+ export interface FulfillmentOperatorMutationResult {
38
+ contractVersion: 'commerce.fulfillment.v0';
39
+ fulfillmentOrderId: string;
40
+ orderId: string;
41
+ status: 'created' | 'packed' | 'label_pending' | 'label_created' | 'handed_over' | 'in_transit' | 'delivered' | 'exception' | 'cancelled';
42
+ replayed: boolean;
43
+ }
44
+ export interface FulfillmentOperatorMutationPort {
45
+ createCommerceFulfillmentOrder(request: AdminCommerceFulfillmentCreateRequest & {
46
+ actorUserId: string;
47
+ }): Promise<FulfillmentOperatorMutationResult | FulfillmentNativeUnsupported>;
48
+ recordCommerceFulfillmentProviderAttempt(request: AdminCommerceFulfillmentRecordProviderAttemptRequest & {
49
+ actorUserId: string;
50
+ }): Promise<FulfillmentOperatorMutationResult | FulfillmentNativeUnsupported>;
51
+ recordCommerceFulfillmentLabel(request: AdminCommerceFulfillmentRecordLabelRequest & {
52
+ actorUserId: string;
53
+ }): Promise<FulfillmentOperatorMutationResult | FulfillmentNativeUnsupported>;
54
+ handOffCommerceFulfillmentOrder(request: AdminCommerceFulfillmentHandOffRequest & {
55
+ actorUserId: string;
56
+ }): Promise<FulfillmentOperatorMutationResult | FulfillmentNativeUnsupported>;
57
+ recordCommerceFulfillmentTrackingEvent(request: AdminCommerceFulfillmentTrackingEventRequest & {
58
+ actorUserId: string;
59
+ }): Promise<FulfillmentOperatorMutationResult | FulfillmentNativeUnsupported>;
60
+ cancelCommerceFulfillmentOrder(request: AdminCommerceFulfillmentCancelRequest & {
61
+ actorUserId: string;
62
+ }): Promise<FulfillmentOperatorMutationResult | FulfillmentNativeUnsupported>;
63
+ }
64
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,110 @@
1
+ import type { SubscriptionCycleStatus } from '@openlup/core/subscription';
2
+ import type { PaymentIntentStatus } from '@openlup/core/payment';
3
+ import type { FulfillmentNativeUnsupported } from './nativeUnsupported.js';
4
+ export type FulfillmentOrderStatus = 'draft' | 'pending_payment' | 'paid' | 'failed' | 'expired' | 'fulfillment_pending' | 'cancelled' | 'fulfilled' | 'refunded';
5
+ export type FulfillmentPaymentStatus = 'not_started' | PaymentIntentStatus;
6
+ export interface FulfillmentCommerceOrder {
7
+ id: string;
8
+ orderId: string;
9
+ clientId: string | null;
10
+ status: 'created' | 'packed' | 'label_pending' | 'label_created' | 'handed_over' | 'in_transit' | 'delivered' | 'exception' | 'cancelled';
11
+ providerKind: string | null;
12
+ providerTrackingId: string | null;
13
+ shippingAddress: {
14
+ addressId: string;
15
+ clientId: string;
16
+ label: string | null;
17
+ line1: string;
18
+ line2: string | null;
19
+ city: string;
20
+ postalCode: string;
21
+ country: string;
22
+ };
23
+ lines: {
24
+ id: string | null;
25
+ orderItemId: string;
26
+ skuId: string;
27
+ sku: string;
28
+ title: string | null;
29
+ quantity: number;
30
+ inventoryReservationIds: string[];
31
+ productSnapshot: Record<string, unknown>;
32
+ }[];
33
+ payment: {
34
+ paymentIntentId: string;
35
+ paymentStatus: FulfillmentPaymentStatus;
36
+ providerPaymentId: string | null;
37
+ };
38
+ inventory: {
39
+ status: 'not_checked' | 'reserved' | 'missing' | 'released' | 'expired' | 'consumed' | 'review_required';
40
+ reservationId: string | null;
41
+ reservationStatus: 'reserved' | 'consumed' | 'released' | 'expired' | null;
42
+ expiresAt: string | null;
43
+ locationId: string | null;
44
+ locationCode: string | null;
45
+ };
46
+ omsEligibility: {
47
+ allowed: boolean;
48
+ reason: 'order_not_paid' | 'payment_not_succeeded' | 'subscription_cycle_not_paid' | 'active_hold' | 'missing_shipping_address' | 'inventory_review' | 'risk_review' | null;
49
+ };
50
+ latestOperation: {
51
+ id: string;
52
+ type: 'created' | 'packed' | 'provider_attempt_recorded' | 'label_created' | 'handed_over' | 'tracking_event_recorded' | 'cancelled';
53
+ occurredAt: string;
54
+ actorUserId: string | null;
55
+ payload: Record<string, unknown>;
56
+ } | null;
57
+ createdAt: string;
58
+ updatedAt: string;
59
+ }
60
+ export interface FulfillmentOrdersListRequest {
61
+ page: number;
62
+ pageSize: number;
63
+ status?: FulfillmentCommerceOrder['status'];
64
+ }
65
+ export interface FulfillmentOrderDetailRequest {
66
+ fulfillmentOrderId?: string;
67
+ orderId?: string;
68
+ }
69
+ export interface FulfillmentOrdersListResponse {
70
+ contractVersion: 'commerce.fulfillment.v0';
71
+ orders: FulfillmentCommerceOrder[];
72
+ totalCount: number;
73
+ page: number;
74
+ pageSize: number;
75
+ }
76
+ export interface FulfillmentOrderDetailResponse {
77
+ contractVersion: 'commerce.fulfillment.v0';
78
+ order: FulfillmentCommerceOrder;
79
+ }
80
+ /** Host-owned persisted projections. Payment statuses already come from the payments projection. */
81
+ export interface FulfillmentCommerceReadPort {
82
+ listCommerceFulfillmentOrders(request: FulfillmentOrdersListRequest): Promise<FulfillmentOrdersListResponse | FulfillmentNativeUnsupported>;
83
+ getCommerceFulfillmentOrderDetail(request: FulfillmentOrderDetailRequest): Promise<FulfillmentOrderDetailResponse | null | FulfillmentNativeUnsupported>;
84
+ }
85
+ export interface FulfillmentShipmentsOverviewRequest {
86
+ shippedFilter: 'today' | '7d' | '30d' | 'all';
87
+ }
88
+ /** Bucket rows are opaque host data; native shipment counts cannot replace these buckets. */
89
+ export interface FulfillmentShipmentsOverviewResponse {
90
+ approved: Record<string, unknown>[];
91
+ packing: Record<string, unknown>[];
92
+ shippedToday: number;
93
+ shipped: Record<string, unknown>[];
94
+ }
95
+ export interface FulfillmentShipmentsOverviewPort {
96
+ getShipmentsOverview(request: FulfillmentShipmentsOverviewRequest): Promise<FulfillmentShipmentsOverviewResponse | FulfillmentNativeUnsupported>;
97
+ }
98
+ /** Existing commerce eligibility remains host-owned; the read model only supplies its facts. */
99
+ export interface FulfillmentCommerceReadPolicy {
100
+ evaluateCommerceFulfillmentEligibility(input: {
101
+ orderMode: 'one_time' | 'subscription_cycle';
102
+ orderStatus: FulfillmentOrderStatus;
103
+ paymentStatus: FulfillmentPaymentStatus;
104
+ subscriptionCycleStatus: SubscriptionCycleStatus | null;
105
+ activeHoldCount: number;
106
+ hasShippingAddress: boolean;
107
+ inventoryStatus: FulfillmentCommerceOrder['inventory']['status'];
108
+ }): FulfillmentCommerceOrder['omsEligibility'];
109
+ }
110
+ export type { FulfillmentProgressInput, FulfillmentProgressPresentation } from "@openlup/core/fulfillment";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ import type { FulfillmentObservation } from "./observation.js";
2
+ import type { FulfillmentRefusal } from "./dispatch.js";
3
+ export type FulfillmentReadbackResult = {
4
+ kind: "found";
5
+ externalRef: string;
6
+ createdAt: string | null;
7
+ updatedAt: string | null;
8
+ observation: FulfillmentObservation;
9
+ } | {
10
+ kind: "absent";
11
+ scope: {
12
+ providerRef: string;
13
+ requestKey: string;
14
+ fulfillmentRef: string;
15
+ externalRef: string | null;
16
+ };
17
+ proof: {
18
+ kind: "authoritative_exact_lookup";
19
+ evidenceRef: `evidence:${string}`;
20
+ checkedAt: string;
21
+ };
22
+ } | {
23
+ kind: "unknown";
24
+ refusal: FulfillmentRefusal;
25
+ } | {
26
+ kind: "unsupported";
27
+ refusal: FulfillmentRefusal;
28
+ };
29
+ export interface FulfillmentReadbackPort {
30
+ /** Empty pages and missing local rows cannot certify external absence. */
31
+ read(input: {
32
+ providerRef: string;
33
+ requestKey: string;
34
+ fulfillmentRef: string;
35
+ externalRef: string | null;
36
+ mode: "command" | "parcel";
37
+ }): Promise<FulfillmentReadbackResult>;
38
+ }
39
+ /** Collection observation is separate from authoritative exact lookup. */
40
+ export type FulfillmentReconciliationObservation = FulfillmentReadbackResult | {
41
+ kind: "unmapped";
42
+ externalRef: string | null;
43
+ evidence: Pick<FulfillmentObservation, "correlation" | "eventKey" | "providerStatus" | "diagnostics">;
44
+ };
45
+ export interface FulfillmentObservationPagePort {
46
+ readPage(input: {
47
+ page: number;
48
+ size: number;
49
+ }): Promise<{
50
+ kind: "page";
51
+ rows: readonly FulfillmentReconciliationObservation[];
52
+ } | {
53
+ kind: "page_exhausted";
54
+ } | {
55
+ kind: "failed";
56
+ refusal: FulfillmentRefusal;
57
+ error?: import("./dispatch.js").FulfillmentOperationError;
58
+ }>;
59
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { FulfillmentNativeUnsupported } from './nativeUnsupported.js';
2
+ export interface FulfillmentReplacementRequest {
3
+ idempotencyKey: string;
4
+ actorUserId: string;
5
+ orderId: string;
6
+ reason: 'damaged' | 'lost' | 'returned_undelivered' | 'other';
7
+ metadata?: Record<string, unknown>;
8
+ }
9
+ export interface FulfillmentReplacementResult {
10
+ contractVersion: 'commerce.v0';
11
+ operation: {
12
+ id: string;
13
+ orderId: string;
14
+ type: 'hold_created' | 'hold_released' | 'fulfillment_reviewed' | 'support_note' | 'shipping_address_updated' | 'order_marked_refunded' | 'order_cancelled_manual' | 'replacement_shipment_requested';
15
+ holdId: string | null;
16
+ actorUserId: string | null;
17
+ occurredAt: string;
18
+ payload: Record<string, unknown>;
19
+ };
20
+ replacement: {
21
+ fulfillmentOrderId: string;
22
+ orderId: string;
23
+ sequenceNo: number;
24
+ replacesFulfillmentOrderId: string;
25
+ reason: FulfillmentReplacementRequest['reason'];
26
+ status: string;
27
+ };
28
+ releasedHoldIds: string[];
29
+ replayed: boolean;
30
+ }
31
+ /** Host owns atomic paid/contact/current-parcel/hold/reservation checks and actor-bound fingerprint/replay receipts. No confirmation or dispatch operation exists here. */
32
+ export interface FulfillmentReplacementPort {
33
+ requestReplacementShipment(request: FulfillmentReplacementRequest): Promise<FulfillmentReplacementResult | FulfillmentNativeUnsupported>;
34
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,89 @@
1
+ import type { DispatchEvidence, FulfillmentDispatchRequest, FulfillmentDispatchResult, FulfillmentRefusal } from "./dispatch.js";
2
+ export interface DispatchRecord {
3
+ dispatchRef: string;
4
+ requestKey: string;
5
+ fulfillmentRef: string;
6
+ orderRef: string;
7
+ parcelRef: string | null;
8
+ externalRef: string | null;
9
+ mode: "shadow" | "stage" | "live";
10
+ status: "draft" | "submitting" | "created" | "uncertain" | "failed" | "cancel_requested" | "cancelled";
11
+ evidence: DispatchEvidence;
12
+ replayed: boolean;
13
+ acceptance?: Extract<FulfillmentDispatchResult, {
14
+ kind: "accepted";
15
+ }> | null;
16
+ }
17
+ export interface FulfillmentStorePort {
18
+ read(requestKey: string): Promise<DispatchRecord | null>;
19
+ readCandidate(fulfillmentRef: string): Promise<FulfillmentDispatchRequest | null>;
20
+ prepare(fulfillmentRef: string): Promise<{
21
+ disposition: "ready" | "withheld";
22
+ contactRevision: number | null;
23
+ }>;
24
+ /** Evidence comes from adapter prepare, before any external submission. */
25
+ claim(input: {
26
+ requestKey: string;
27
+ fulfillmentRef: string;
28
+ orderRef: string;
29
+ parcelRef: string | null;
30
+ mode: DispatchRecord["mode"];
31
+ evidence: DispatchEvidence;
32
+ }): Promise<{
33
+ kind: "claimed";
34
+ record: DispatchRecord;
35
+ } | {
36
+ kind: "refused";
37
+ refusal: FulfillmentRefusal;
38
+ }>;
39
+ /** G14: idempotent mapped attempt; persist only prepared, sanitized evidence. */
40
+ recordProviderAttempt(attemptKey: string, fulfillmentRef: string, preparedEvidence: DispatchEvidence, mode: DispatchRecord["mode"], status: "recorded"): Promise<{
41
+ replayed: boolean;
42
+ }>;
43
+ /** Bind submission to the same prepared command fingerprint recorded by claim. */
44
+ begin(input: {
45
+ dispatchRef: string;
46
+ commandFingerprint: string;
47
+ }): Promise<{
48
+ kind: "begun";
49
+ record: DispatchRecord;
50
+ begun: boolean;
51
+ replayed: boolean;
52
+ } | {
53
+ kind: "refused";
54
+ refusal: FulfillmentRefusal;
55
+ }>;
56
+ /** Accepted rescue retains externalRef as uncertain; only acknowledge closes the local acceptance atomically. */
57
+ finalize(input: {
58
+ dispatchRef: string;
59
+ result: FulfillmentDispatchResult;
60
+ }): Promise<DispatchRecord>;
61
+ acknowledge(input: {
62
+ dispatchRef: string;
63
+ acceptance: Extract<FulfillmentDispatchResult, {
64
+ kind: "accepted";
65
+ }>;
66
+ }): Promise<{
67
+ acknowledged: boolean;
68
+ replayed: boolean;
69
+ record: DispatchRecord;
70
+ }>;
71
+ markStaleSubmissionsUncertain(staleBefore: string): Promise<number>;
72
+ }
73
+ export interface FulfillmentPaidHandoffPort {
74
+ ensureObligation(input: {
75
+ requestKey: string;
76
+ orderRef: string;
77
+ paidFactRef: string;
78
+ }): Promise<{
79
+ fulfillmentRef: string;
80
+ replayed: boolean;
81
+ }>;
82
+ acknowledge(input: {
83
+ requestKey: string;
84
+ fulfillmentRef: string;
85
+ }): Promise<{
86
+ acknowledged: boolean;
87
+ replayed: boolean;
88
+ }>;
89
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,226 @@
1
+ import type { FulfillmentRefusal } from "./dispatch.js";
2
+ /** Collection identity never masquerades as a monotonic provider revision. */
3
+ interface SyncIdentity {
4
+ providerRef: string;
5
+ syncRunId: string;
6
+ collectedAt: string;
7
+ sourceRevision: string | null;
8
+ revisionSource: "provider" | "collection" | "unknown";
9
+ }
10
+ export interface StockSnapshot extends SyncIdentity {
11
+ skuRef: string;
12
+ quantityKind: "snapshot";
13
+ totalQuantity: number;
14
+ forSaleQuantity: number;
15
+ reservedOrUnavailableQuantity: number;
16
+ }
17
+ export interface StockMovement extends SyncIdentity {
18
+ skuRef: string;
19
+ quantityKind: "movement";
20
+ quantity: number;
21
+ occurredAt: string | null;
22
+ operationType: string | null;
23
+ documentRef: string | null;
24
+ lotRef: string | null;
25
+ expirationDate: string | null;
26
+ }
27
+ export interface SyncCursor {
28
+ status: "idle" | "running" | "succeeded" | "failed";
29
+ lastStockSyncedAt: string | null;
30
+ lastMovementOccurredAt: string | null;
31
+ /** Sanitized continuation only; no credentials, URLs or arbitrary provider payload. */
32
+ continuation: {
33
+ nextRef: string | null;
34
+ startLocalDate: string | null;
35
+ endLocalDate: string | null;
36
+ };
37
+ /** G15: successful sellable coverage gaps; legacy absent values read as []. */
38
+ coverageGapSkus?: readonly string[];
39
+ refusal: FulfillmentRefusal | null;
40
+ /** Per-entry bounded diagnostics and run evidence in the existing cursor JSON, never raw errors. */
41
+ syncRunId?: string;
42
+ counts?: {
43
+ checked: number;
44
+ updated: number;
45
+ movements: number;
46
+ rejected: number;
47
+ failures: number;
48
+ providerCalls: number;
49
+ readBacks: number;
50
+ };
51
+ items?: readonly {
52
+ kind?: "stock" | "movement";
53
+ itemIndex: number;
54
+ skuRef: string | null;
55
+ status: "recorded" | "failed" | "rejected";
56
+ reason?: string;
57
+ activeReserved?: number;
58
+ sellableNow?: number | null;
59
+ coverageGapQuantity?: number;
60
+ }[];
61
+ alerts?: readonly {
62
+ skuRef: string;
63
+ thresholdKind: Exclude<Threshold, "forecast">;
64
+ severity: "info" | "warning" | "critical";
65
+ providerForSaleQuantity: number;
66
+ localAvailableQuantity: number;
67
+ detectedAt: string;
68
+ activeReserved?: number;
69
+ coverageGapQuantity?: number;
70
+ gapHours?: number;
71
+ thresholdHours?: number;
72
+ }[];
73
+ staleSync?: {
74
+ gapHours: number;
75
+ thresholdHours: number;
76
+ detectedAt: string;
77
+ };
78
+ error?: {
79
+ reason: string;
80
+ providerError?: {
81
+ operation: "get_stock" | "get_stock_movements";
82
+ status: number | null;
83
+ code: string;
84
+ retryable: boolean;
85
+ };
86
+ } | null;
87
+ }
88
+ export interface LocalStock {
89
+ skuRef: string;
90
+ onHand: number;
91
+ reserved: number;
92
+ unavailable: number;
93
+ safetyStock: number;
94
+ }
95
+ type Threshold = "safety_stock" | "reservation_coverage" | "forecast" | "stale_sync";
96
+ type Conflict = "unknown_sku" | "ean_conflict" | "kind_quantity_conflict";
97
+ export interface FulfillmentStockSyncProvider {
98
+ /** Rejected rows carry only their input index and a closed reason, never an unsafe reference. */
99
+ getStock(): Promise<(StockSnapshot | {
100
+ kind: "rejected";
101
+ itemIndex: number;
102
+ reason: "invalid_sku_ref";
103
+ })[]>;
104
+ getStockMovements(input?: {
105
+ startLocalDate?: string;
106
+ endLocalDate?: string;
107
+ size?: number;
108
+ }): Promise<(StockMovement | {
109
+ kind: "rejected";
110
+ itemIndex: number;
111
+ reason: "invalid_sku_ref";
112
+ })[]>;
113
+ }
114
+ export interface FulfillmentStockSyncPort {
115
+ readCursor(): Promise<SyncCursor | null>;
116
+ /** G16: unaggregated lines at the worker clock; quantity retains the four local balances. */
117
+ readLocalInventoryStock(requestedAt: string): Promise<readonly {
118
+ skuRef: string;
119
+ quantity: Pick<LocalStock, "onHand" | "reserved" | "unavailable" | "safetyStock">;
120
+ fulfillable: boolean;
121
+ locationStatus: "active" | "inactive";
122
+ lotStatus: "available" | "quarantined" | "expired" | "recalled" | null;
123
+ expiresAt: string | null;
124
+ }[]>;
125
+ readSkuInventoryClasses(skus: string[]): Promise<Map<string, "sellable" | "packaging" | null>>;
126
+ readActiveReservations(skus: string[], requestedAt: string): Promise<Map<string, number>>;
127
+ recordCursor(input: SyncCursor): Promise<void>;
128
+ recordStockSnapshot(input: {
129
+ requestKey: string;
130
+ snapshot: StockSnapshot;
131
+ local: LocalStock;
132
+ mismatchKind: "none";
133
+ inventoryClass: "sellable" | "packaging" | null;
134
+ }): Promise<{
135
+ replayed: boolean;
136
+ readBack: boolean;
137
+ }>;
138
+ recordProviderStockCurrent(input: {
139
+ requestKey: string;
140
+ snapshot: StockSnapshot;
141
+ inventoryClass: "sellable" | "packaging" | null;
142
+ lastSyncedAt: string;
143
+ staleAfter: string;
144
+ }): Promise<{
145
+ replayed: boolean;
146
+ readBack: boolean;
147
+ }>;
148
+ recordMovement(input: {
149
+ requestKey: string;
150
+ movement: StockMovement;
151
+ }): Promise<{
152
+ replayed: boolean;
153
+ readBack: boolean;
154
+ }>;
155
+ recordLowStockEvidence(input: {
156
+ requestKey: string;
157
+ skuRef: string;
158
+ thresholdKind: Exclude<Threshold, "forecast">;
159
+ severity: "info" | "warning" | "critical";
160
+ providerForSaleQuantity: number;
161
+ localAvailableQuantity: number;
162
+ syncRunId: string;
163
+ }): Promise<{
164
+ replayed: boolean;
165
+ }>;
166
+ resolveLowStockEvidence(input: {
167
+ skuRef: string;
168
+ activeThresholdKinds: Threshold[];
169
+ syncRunId: string;
170
+ }): Promise<{
171
+ resolved: number;
172
+ }>;
173
+ }
174
+ interface ProductPack {
175
+ ean: string;
176
+ quantity: number;
177
+ }
178
+ export interface FulfillmentProductSyncProvider {
179
+ /** null means skipped (no private push metadata), never a newly created local SKU. */
180
+ ensureProduct(sku: string): Promise<{
181
+ replayed: boolean;
182
+ } | null>;
183
+ getProductPacks(sku: string): Promise<ProductPack[]>;
184
+ addProductPack(sku: string, pack: ProductPack): Promise<void>;
185
+ listStockedSkus(): Promise<string[]>;
186
+ }
187
+ export interface FulfillmentProductSyncPort {
188
+ listLocalProductPacks(): Promise<{
189
+ sku: string;
190
+ packs: (ProductPack & {
191
+ kind: "unit" | "collective";
192
+ })[];
193
+ }[]>;
194
+ markPackSynced(input: {
195
+ sku: string;
196
+ ean: string;
197
+ }): Promise<void>;
198
+ upsertPulledPack(input: {
199
+ sku: string;
200
+ ean: string;
201
+ quantity: number;
202
+ kind: "unit" | "collective";
203
+ }): Promise<{
204
+ conflict: "none" | "local_locked_mismatch" | "ean_owned_by_other_sku" | "sku_not_found";
205
+ replayed: boolean;
206
+ }>;
207
+ recordReconciliationEvidence(input: {
208
+ requestKey: string;
209
+ sku: string;
210
+ ean: string | null;
211
+ conflictKind: Conflict;
212
+ providerQuantity: number;
213
+ identity: SyncIdentity;
214
+ refusal: FulfillmentRefusal | null;
215
+ }): Promise<{
216
+ replayed: boolean;
217
+ }>;
218
+ resolveReconciliationEvidence(input: {
219
+ sku: string;
220
+ activeConflictKinds: Conflict[];
221
+ syncRunId: string;
222
+ }): Promise<{
223
+ resolved: number;
224
+ }>;
225
+ }
226
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export { parcelSequenceNo, compareParcelPrecedence, currentParcel, currentParcelFor, currentParcelPerOrder, currentParcelFirst, belongsToParcel, rowsForParcel } from "@openlup/core/fulfillment";
2
+ export type { FulfillmentParcelRow, ParcelAttributedRow } from "@openlup/core/fulfillment";