@openlup/platform 0.26.0 → 0.28.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 (603) hide show
  1. package/CHANGELOG.md +305 -327
  2. package/README.md +332 -16
  3. package/dist/account-support/accountReadFacade.d.ts +8 -0
  4. package/dist/account-support/accountReadFacade.js +10 -0
  5. package/dist/account-support/accountReadModels.d.ts +69 -0
  6. package/dist/account-support/accountReadModels.js +272 -0
  7. package/dist/account-support/bindings.d.ts +23 -0
  8. package/dist/account-support/bindings.js +16 -0
  9. package/dist/account-support/contracts/account.d.ts +281 -0
  10. package/dist/account-support/contracts/account.js +1 -0
  11. package/dist/account-support/contracts/capabilities.d.ts +44 -0
  12. package/dist/account-support/contracts/capabilities.js +1 -0
  13. package/dist/account-support/contracts/commands.d.ts +307 -0
  14. package/dist/account-support/contracts/commands.js +1 -0
  15. package/dist/account-support/contracts/customer360.d.ts +154 -0
  16. package/dist/account-support/contracts/customer360.js +1 -0
  17. package/dist/account-support/contracts/index.d.ts +10 -0
  18. package/dist/account-support/contracts/index.js +1 -0
  19. package/dist/account-support/contracts/invoice.d.ts +79 -0
  20. package/dist/account-support/contracts/invoice.js +1 -0
  21. package/dist/account-support/contracts/operator.d.ts +289 -0
  22. package/dist/account-support/contracts/operator.js +1 -0
  23. package/dist/account-support/contribution.d.ts +24 -0
  24. package/dist/account-support/contribution.js +22 -0
  25. package/dist/account-support/customer360.d.ts +106 -0
  26. package/dist/account-support/customer360.js +163 -0
  27. package/dist/account-support/customerAccountReadDiagnostics.d.ts +11 -0
  28. package/dist/account-support/customerAccountReadDiagnostics.js +71 -0
  29. package/dist/account-support/index.d.ts +26 -0
  30. package/dist/account-support/index.js +15 -0
  31. package/dist/account-support/invoiceAccess.d.ts +57 -0
  32. package/dist/account-support/invoiceAccess.js +40 -0
  33. package/dist/account-support/migrations.d.ts +14 -0
  34. package/dist/account-support/migrations.js +7 -0
  35. package/dist/account-support/operatorAuthority.d.ts +67 -0
  36. package/dist/account-support/operatorAuthority.js +379 -0
  37. package/dist/account-support/operatorRecovery.d.ts +66 -0
  38. package/dist/account-support/operatorRecovery.js +129 -0
  39. package/dist/account-support/orderHistory.d.ts +50 -0
  40. package/dist/account-support/orderHistory.js +188 -0
  41. package/dist/account-support/paymentMethodComposition.d.ts +5 -0
  42. package/dist/account-support/paymentMethodComposition.js +4 -0
  43. package/dist/account-support/postgresOperatorAuthority.d.ts +16 -0
  44. package/dist/account-support/postgresOperatorAuthority.js +93 -0
  45. package/dist/account-support/selfService.d.ts +6 -0
  46. package/dist/account-support/selfService.js +81 -0
  47. package/dist/account-support/subscriptionCommandCodec.d.ts +10 -0
  48. package/dist/account-support/subscriptionCommandCodec.js +38 -0
  49. package/dist/catalog/draftSchemas.d.ts +1 -1
  50. package/dist/catalog/foundationSchemas.d.ts +3 -3
  51. package/dist/catalog/resolvedSkuProjection.d.ts +2 -2
  52. package/dist/catalog/sellableSchemas.d.ts +2 -2
  53. package/dist/commerce/adapters/managed/commerceOmsControlPlane.d.ts +3 -0
  54. package/dist/commerce/adapters/managed/commerceOmsControlPlane.js +71 -0
  55. package/dist/commerce/adapters/managed/commerceOmsMutations.d.ts +10 -0
  56. package/dist/commerce/adapters/managed/commerceOmsMutations.js +119 -0
  57. package/dist/commerce/adapters/managed/commerceOmsPort.d.ts +28 -0
  58. package/dist/commerce/adapters/managed/commerceOmsPort.js +101 -0
  59. package/dist/commerce/adapters/managed/oms/accounting.d.ts +3 -0
  60. package/dist/commerce/adapters/managed/oms/accounting.js +13 -0
  61. package/dist/commerce/adapters/managed/oms/fulfillmentReads.d.ts +17 -0
  62. package/dist/commerce/adapters/managed/oms/fulfillmentReads.js +81 -0
  63. package/dist/commerce/adapters/managed/oms/inboundEvents.d.ts +9 -0
  64. package/dist/commerce/adapters/managed/oms/inboundEvents.js +40 -0
  65. package/dist/commerce/adapters/managed/oms/outboxEvents.d.ts +2 -0
  66. package/dist/commerce/adapters/managed/oms/outboxEvents.js +23 -0
  67. package/dist/commerce/adapters/managed/oms/paymentAttempts.d.ts +3 -0
  68. package/dist/commerce/adapters/managed/oms/paymentAttempts.js +15 -0
  69. package/dist/commerce/adapters/managed/oms/queueSelection.d.ts +12 -0
  70. package/dist/commerce/adapters/managed/oms/queueSelection.js +109 -0
  71. package/dist/commerce/adapters/managed/oms/readProjections.d.ts +18 -0
  72. package/dist/commerce/adapters/managed/oms/readProjections.js +13 -0
  73. package/dist/commerce/adapters/managed/oms/readQueries.d.ts +16 -0
  74. package/dist/commerce/adapters/managed/oms/readQueries.js +276 -0
  75. package/dist/commerce/adapters/managed/oms/types.d.ts +2 -0
  76. package/dist/commerce/adapters/managed/oms/types.js +7 -0
  77. package/dist/commerce/checkoutCommandSchemas.d.ts +89 -0
  78. package/dist/commerce/checkoutCommandSchemas.js +70 -0
  79. package/dist/commerce/checkoutHelpers.d.ts +21 -0
  80. package/dist/commerce/checkoutHelpers.js +29 -0
  81. package/dist/commerce/checkoutResumeSchemas.d.ts +158 -0
  82. package/dist/commerce/checkoutResumeSchemas.js +145 -0
  83. package/dist/commerce/checkoutSchemas.d.ts +158 -0
  84. package/dist/commerce/checkoutSchemas.js +161 -0
  85. package/dist/commerce/commerceReturnsPort.d.ts +97 -0
  86. package/dist/commerce/commerceReturnsPort.js +39 -0
  87. package/dist/commerce/configuratorIntentPersistenceSchemas.d.ts +20 -0
  88. package/dist/commerce/configuratorIntentPersistenceSchemas.js +21 -0
  89. package/dist/commerce/configuratorIntentSchemas.d.ts +63 -0
  90. package/dist/commerce/configuratorIntentSchemas.js +43 -0
  91. package/dist/commerce/contractPrimitives.d.ts +50 -0
  92. package/dist/commerce/contractPrimitives.js +25 -0
  93. package/dist/commerce/contracts/availability.d.ts +23 -0
  94. package/dist/commerce/contracts/availability.js +1 -0
  95. package/dist/commerce/contracts/fulfillmentRecovery.d.ts +25 -0
  96. package/dist/commerce/contracts/fulfillmentRecovery.js +1 -0
  97. package/dist/commerce/contracts/index.d.ts +13 -0
  98. package/dist/commerce/contracts/index.js +1 -0
  99. package/dist/commerce/contracts/intent.d.ts +86 -0
  100. package/dist/commerce/contracts/intent.js +1 -0
  101. package/dist/commerce/contracts/omsTypes.d.ts +1216 -0
  102. package/dist/commerce/contracts/omsTypes.js +1 -0
  103. package/dist/commerce/contracts/order.d.ts +39 -0
  104. package/dist/commerce/contracts/order.js +1 -0
  105. package/dist/commerce/contracts/orderMoney.d.ts +52 -0
  106. package/dist/commerce/contracts/orderMoney.js +1 -0
  107. package/dist/commerce/contracts/ports.d.ts +113 -0
  108. package/dist/commerce/contracts/ports.js +1 -0
  109. package/dist/commerce/contracts/recovery.d.ts +11 -0
  110. package/dist/commerce/contracts/recovery.js +1 -0
  111. package/dist/commerce/contracts/runtimePorts.d.ts +196 -0
  112. package/dist/commerce/contracts/runtimePorts.js +1 -0
  113. package/dist/commerce/contracts/state.d.ts +26 -0
  114. package/dist/commerce/contracts/state.js +43 -0
  115. package/dist/commerce/customerDefaultsSnapshotSchemas.d.ts +51 -0
  116. package/dist/commerce/customerDefaultsSnapshotSchemas.js +106 -0
  117. package/dist/commerce/errors.d.ts +18 -0
  118. package/dist/commerce/errors.js +36 -0
  119. package/dist/commerce/fulfillmentEligibility.d.ts +6 -0
  120. package/dist/commerce/fulfillmentEligibility.js +31 -0
  121. package/dist/commerce/index.d.ts +72 -0
  122. package/dist/commerce/index.js +67 -0
  123. package/dist/commerce/model/customerFulfillmentRecovery.d.ts +40 -0
  124. package/dist/commerce/model/customerFulfillmentRecovery.js +144 -0
  125. package/dist/commerce/model/fulfillmentCancellationEligibility.d.ts +7 -0
  126. package/dist/commerce/model/fulfillmentCancellationEligibility.js +9 -0
  127. package/dist/commerce/model/omsAccountingVisibility.d.ts +12 -0
  128. package/dist/commerce/model/omsAccountingVisibility.js +118 -0
  129. package/dist/commerce/model/omsBillingInvoiceBuyer.d.ts +2 -0
  130. package/dist/commerce/model/omsBillingInvoiceBuyer.js +15 -0
  131. package/dist/commerce/model/omsCurrency.d.ts +4 -0
  132. package/dist/commerce/model/omsCurrency.js +5 -0
  133. package/dist/commerce/model/omsFulfillmentDebug.d.ts +20 -0
  134. package/dist/commerce/model/omsFulfillmentDebug.js +122 -0
  135. package/dist/commerce/model/omsFulfillmentSummary.d.ts +16 -0
  136. package/dist/commerce/model/omsFulfillmentSummary.js +189 -0
  137. package/dist/commerce/model/omsListTotals.d.ts +13 -0
  138. package/dist/commerce/model/omsListTotals.js +32 -0
  139. package/dist/commerce/model/omsOperationalLadder.d.ts +51 -0
  140. package/dist/commerce/model/omsOperationalLadder.js +158 -0
  141. package/dist/commerce/model/omsOrderLineMoney.d.ts +4 -0
  142. package/dist/commerce/model/omsOrderLineMoney.js +25 -0
  143. package/dist/commerce/model/omsPaymentMethodSummary.d.ts +5 -0
  144. package/dist/commerce/model/omsPaymentMethodSummary.js +11 -0
  145. package/dist/commerce/model/omsReadModel.d.ts +43 -0
  146. package/dist/commerce/model/omsReadModel.js +211 -0
  147. package/dist/commerce/model/omsReadModelCommunication.d.ts +3 -0
  148. package/dist/commerce/model/omsReadModelCommunication.js +29 -0
  149. package/dist/commerce/model/omsReadModelHelpers.d.ts +125 -0
  150. package/dist/commerce/model/omsReadModelHelpers.js +212 -0
  151. package/dist/commerce/model/omsReadModelList.d.ts +33 -0
  152. package/dist/commerce/model/omsReadModelList.js +50 -0
  153. package/dist/commerce/model/omsReadModelListSummary.d.ts +3 -0
  154. package/dist/commerce/model/omsReadModelListSummary.js +13 -0
  155. package/dist/commerce/model/omsReadModelPricing.d.ts +5 -0
  156. package/dist/commerce/model/omsReadModelPricing.js +36 -0
  157. package/dist/commerce/model/omsReadModelProjections.d.ts +1 -0
  158. package/dist/commerce/model/omsReadModelProjections.js +1 -0
  159. package/dist/commerce/model/omsReadModelRowCore.d.ts +79 -0
  160. package/dist/commerce/model/omsReadModelRowCore.js +149 -0
  161. package/dist/commerce/model/omsReadModelRows.d.ts +1 -0
  162. package/dist/commerce/model/omsReadModelRows.js +6 -0
  163. package/dist/commerce/offerAvailability.d.ts +18 -0
  164. package/dist/commerce/offerAvailability.js +53 -0
  165. package/dist/commerce/offerAvailabilitySchemas.d.ts +43 -0
  166. package/dist/commerce/offerAvailabilitySchemas.js +42 -0
  167. package/dist/commerce/offerEvidenceSchemas.d.ts +7 -0
  168. package/dist/commerce/offerEvidenceSchemas.js +13 -0
  169. package/dist/commerce/oms/omsContractBase.d.ts +130 -0
  170. package/dist/commerce/oms/omsContractBase.js +86 -0
  171. package/dist/commerce/oms/omsContractReadAuxSchemas.d.ts +222 -0
  172. package/dist/commerce/oms/omsContractReadAuxSchemas.js +123 -0
  173. package/dist/commerce/oms/omsContractReadSchemas.d.ts +2266 -0
  174. package/dist/commerce/oms/omsContractReadSchemas.js +277 -0
  175. package/dist/commerce/oms/omsContractRequests.d.ts +196 -0
  176. package/dist/commerce/oms/omsContractRequests.js +118 -0
  177. package/dist/commerce/oms/omsContracts.d.ts +5 -0
  178. package/dist/commerce/oms/omsContracts.js +4 -0
  179. package/dist/commerce/oms/omsControlPlane.d.ts +275 -0
  180. package/dist/commerce/oms/omsControlPlane.js +72 -0
  181. package/dist/commerce/oms/omsFulfillmentContractSchemas.d.ts +203 -0
  182. package/dist/commerce/oms/omsFulfillmentContractSchemas.js +94 -0
  183. package/dist/commerce/oms/omsFulfillmentDebugSchemas.d.ts +69 -0
  184. package/dist/commerce/oms/omsFulfillmentDebugSchemas.js +33 -0
  185. package/dist/commerce/oms/omsFulfillmentHealthSchemas.d.ts +67 -0
  186. package/dist/commerce/oms/omsFulfillmentHealthSchemas.js +44 -0
  187. package/dist/commerce/oms/omsPorts.d.ts +84 -0
  188. package/dist/commerce/oms/omsPorts.js +148 -0
  189. package/dist/commerce/oms/omsPrimitives.d.ts +5 -0
  190. package/dist/commerce/oms/omsPrimitives.js +3 -0
  191. package/dist/commerce/oms/omsProviderEvidenceSchemas.d.ts +15 -0
  192. package/dist/commerce/oms/omsProviderEvidenceSchemas.js +12 -0
  193. package/dist/commerce/orderDraftErrors.d.ts +13 -0
  194. package/dist/commerce/orderDraftErrors.js +20 -0
  195. package/dist/commerce/orderEmailEligibility.d.ts +54 -0
  196. package/dist/commerce/orderEmailEligibility.js +123 -0
  197. package/dist/commerce/orderEmailLines.d.ts +12 -0
  198. package/dist/commerce/orderEmailLines.js +8 -0
  199. package/dist/commerce/orderFeedbackContracts.d.ts +41 -0
  200. package/dist/commerce/orderFeedbackContracts.js +33 -0
  201. package/dist/commerce/orderMoney.d.ts +6 -0
  202. package/dist/commerce/orderMoney.js +168 -0
  203. package/dist/commerce/orderReviewContracts.d.ts +475 -0
  204. package/dist/commerce/orderReviewContracts.js +94 -0
  205. package/dist/commerce/orderReviewPorts.d.ts +140 -0
  206. package/dist/commerce/orderReviewPorts.js +1 -0
  207. package/dist/commerce/outboxDispatchContracts.d.ts +30 -0
  208. package/dist/commerce/outboxDispatchContracts.js +1 -0
  209. package/dist/commerce/outboxEventSchemas.d.ts +162 -0
  210. package/dist/commerce/outboxEventSchemas.js +164 -0
  211. package/dist/commerce/outboxOrderDraftEmailPorts.d.ts +207 -0
  212. package/dist/commerce/outboxOrderDraftEmailPorts.js +12 -0
  213. package/dist/commerce/paymentContinuation.d.ts +4 -0
  214. package/dist/commerce/paymentContinuation.js +4 -0
  215. package/dist/commerce/ports.d.ts +8 -0
  216. package/dist/commerce/ports.js +1 -0
  217. package/dist/commerce/recoveryDestination.d.ts +3 -0
  218. package/dist/commerce/recoveryDestination.js +17 -0
  219. package/dist/commerce/runtimeErrors.d.ts +8 -0
  220. package/dist/commerce/runtimeErrors.js +16 -0
  221. package/dist/commerce/salesChannelEnvelope.d.ts +20 -0
  222. package/dist/commerce/salesChannelEnvelope.js +7 -0
  223. package/dist/commerce/schemas.d.ts +174 -0
  224. package/dist/commerce/schemas.js +84 -0
  225. package/dist/commerce/server/checkoutCompensation.d.ts +21 -0
  226. package/dist/commerce/server/checkoutCompensation.js +32 -0
  227. package/dist/commerce/server/checkoutConflictClassifiers.d.ts +17 -0
  228. package/dist/commerce/server/checkoutConflictClassifiers.js +38 -0
  229. package/dist/commerce/server/checkoutExpiredRecoveryPolicy.d.ts +38 -0
  230. package/dist/commerce/server/checkoutExpiredRecoveryPolicy.js +85 -0
  231. package/dist/commerce/server/checkoutInvoiceBuyerSnapshot.d.ts +22 -0
  232. package/dist/commerce/server/checkoutInvoiceBuyerSnapshot.js +30 -0
  233. package/dist/commerce/server/checkoutOfferPolicyPort.d.ts +33 -0
  234. package/dist/commerce/server/checkoutOfferPolicyPort.js +49 -0
  235. package/dist/commerce/server/checkoutPaymentContinuationCredential.d.ts +58 -0
  236. package/dist/commerce/server/checkoutPaymentContinuationCredential.js +154 -0
  237. package/dist/commerce/server/checkoutQuoteTypes.d.ts +19 -0
  238. package/dist/commerce/server/checkoutQuoteTypes.js +1 -0
  239. package/dist/commerce/server/checkoutRecoveryOrderPort.d.ts +42 -0
  240. package/dist/commerce/server/checkoutRecoveryOrderPort.js +1 -0
  241. package/dist/commerce/server/checkoutRecoveryToken.d.ts +40 -0
  242. package/dist/commerce/server/checkoutRecoveryToken.js +26 -0
  243. package/dist/commerce/server/checkoutRefusalContinuation.d.ts +24 -0
  244. package/dist/commerce/server/checkoutRefusalContinuation.js +18 -0
  245. package/dist/commerce/server/checkoutRuntimeTypes.d.ts +81 -0
  246. package/dist/commerce/server/checkoutRuntimeTypes.js +1 -0
  247. package/dist/commerce/server/commerceCheckoutCommandExecution.d.ts +60 -0
  248. package/dist/commerce/server/commerceCheckoutCommandExecution.js +136 -0
  249. package/dist/commerce/server/commerceCheckoutCompensation.d.ts +26 -0
  250. package/dist/commerce/server/commerceCheckoutCompensation.js +46 -0
  251. package/dist/commerce/server/commerceCheckoutContinuationTerms.d.ts +50 -0
  252. package/dist/commerce/server/commerceCheckoutContinuationTerms.js +66 -0
  253. package/dist/commerce/server/commerceCheckoutCustomerDefaults.d.ts +18 -0
  254. package/dist/commerce/server/commerceCheckoutCustomerDefaults.js +17 -0
  255. package/dist/commerce/server/commerceCheckoutFailureHandler.d.ts +51 -0
  256. package/dist/commerce/server/commerceCheckoutFailureHandler.js +90 -0
  257. package/dist/commerce/server/commerceCheckoutHandler.d.ts +213 -0
  258. package/dist/commerce/server/commerceCheckoutHandler.js +196 -0
  259. package/dist/commerce/server/commerceCheckoutHandlerAdmission.d.ts +58 -0
  260. package/dist/commerce/server/commerceCheckoutHandlerAdmission.js +94 -0
  261. package/dist/commerce/server/commerceCheckoutHandlerHelpers.d.ts +67 -0
  262. package/dist/commerce/server/commerceCheckoutHandlerHelpers.js +155 -0
  263. package/dist/commerce/server/commerceCheckoutOrchestrationError.d.ts +9 -0
  264. package/dist/commerce/server/commerceCheckoutOrchestrationError.js +14 -0
  265. package/dist/commerce/server/commerceCheckoutPromotionPriceChange.d.ts +47 -0
  266. package/dist/commerce/server/commerceCheckoutPromotionPriceChange.js +43 -0
  267. package/dist/commerce/server/commerceCheckoutProviderPayment.d.ts +34 -0
  268. package/dist/commerce/server/commerceCheckoutProviderPayment.js +37 -0
  269. package/dist/commerce/server/commerceCheckoutQuoteGuard.d.ts +62 -0
  270. package/dist/commerce/server/commerceCheckoutQuoteGuard.js +106 -0
  271. package/dist/commerce/server/commerceCheckoutResume.d.ts +29 -0
  272. package/dist/commerce/server/commerceCheckoutResume.js +81 -0
  273. package/dist/commerce/server/commerceCheckoutResumeGuard.d.ts +54 -0
  274. package/dist/commerce/server/commerceCheckoutResumeGuard.js +138 -0
  275. package/dist/commerce/server/commerceCheckoutSavedPaymentMethod.d.ts +39 -0
  276. package/dist/commerce/server/commerceCheckoutSavedPaymentMethod.js +44 -0
  277. package/dist/commerce/server/commerceCheckoutStartRuntimeFailure.d.ts +7 -0
  278. package/dist/commerce/server/commerceCheckoutStartRuntimeFailure.js +39 -0
  279. package/dist/commerce/server/commerceCheckoutTiming.d.ts +8 -0
  280. package/dist/commerce/server/commerceCheckoutTiming.js +31 -0
  281. package/dist/commerce/server/commerceDiagnostics.d.ts +6 -0
  282. package/dist/commerce/server/commerceDiagnostics.js +31 -0
  283. package/dist/commerce/server/commerceOmsCancelOrderHandler.d.ts +7 -0
  284. package/dist/commerce/server/commerceOmsCancelOrderHandler.js +22 -0
  285. package/dist/commerce/server/commerceOmsControlPlaneHandlers.d.ts +18 -0
  286. package/dist/commerce/server/commerceOmsControlPlaneHandlers.js +60 -0
  287. package/dist/commerce/server/commerceOmsHandlers.d.ts +47 -0
  288. package/dist/commerce/server/commerceOmsHandlers.js +176 -0
  289. package/dist/commerce/server/commerceOmsMarkRefundedHandler.d.ts +7 -0
  290. package/dist/commerce/server/commerceOmsMarkRefundedHandler.js +19 -0
  291. package/dist/commerce/server/commerceOrderDraft.d.ts +24 -0
  292. package/dist/commerce/server/commerceOrderDraft.js +92 -0
  293. package/dist/commerce/server/commercePaidOrderOrchestration.d.ts +131 -0
  294. package/dist/commerce/server/commercePaidOrderOrchestration.js +140 -0
  295. package/dist/commerce/server/commerceProviderAttemptFailure.d.ts +133 -0
  296. package/dist/commerce/server/commerceProviderAttemptFailure.js +175 -0
  297. package/dist/commerce/server/commerceReturnsHandlers.d.ts +41 -0
  298. package/dist/commerce/server/commerceReturnsHandlers.js +100 -0
  299. package/dist/commerce/server/commerceRuntimePort.d.ts +16 -0
  300. package/dist/commerce/server/commerceRuntimePort.js +57 -0
  301. package/dist/commerce/server/commerceRuntimeService.d.ts +98 -0
  302. package/dist/commerce/server/commerceRuntimeService.js +186 -0
  303. package/dist/commerce/server/commerceRuntimeStartResponse.d.ts +37 -0
  304. package/dist/commerce/server/commerceRuntimeStartResponse.js +56 -0
  305. package/dist/commerce/server/commerceStarterOfferGuard.d.ts +55 -0
  306. package/dist/commerce/server/commerceStarterOfferGuard.js +128 -0
  307. package/dist/commerce/server/configuratorIntentPersistence.d.ts +47 -0
  308. package/dist/commerce/server/configuratorIntentPersistence.js +85 -0
  309. package/dist/commerce/server/configuratorIntentPersistenceHandler.d.ts +14 -0
  310. package/dist/commerce/server/configuratorIntentPersistenceHandler.js +42 -0
  311. package/dist/commerce/server/emailRuntime.d.ts +47 -0
  312. package/dist/commerce/server/emailRuntime.js +1 -0
  313. package/dist/commerce/server/handlerSupport.d.ts +68 -0
  314. package/dist/commerce/server/handlerSupport.js +1 -0
  315. package/dist/commerce/server/index.d.ts +178 -0
  316. package/dist/commerce/server/index.js +127 -0
  317. package/dist/commerce/server/offerAvailability.d.ts +21 -0
  318. package/dist/commerce/server/offerAvailability.js +163 -0
  319. package/dist/commerce/server/orderDraftRpcPayload.d.ts +20 -0
  320. package/dist/commerce/server/orderDraftRpcPayload.js +21 -0
  321. package/dist/commerce/server/orderFeedbackSubmit.d.ts +20 -0
  322. package/dist/commerce/server/orderFeedbackSubmit.js +16 -0
  323. package/dist/commerce/server/orderFeedbackTokenCheck.d.ts +17 -0
  324. package/dist/commerce/server/orderFeedbackTokenCheck.js +14 -0
  325. package/dist/commerce/server/orderReviewAdminHandlers.d.ts +47 -0
  326. package/dist/commerce/server/orderReviewAdminHandlers.js +41 -0
  327. package/dist/commerce/server/orderReviewHandlers.d.ts +114 -0
  328. package/dist/commerce/server/orderReviewHandlers.js +42 -0
  329. package/dist/commerce/server/orderReviewLifecycle.d.ts +10 -0
  330. package/dist/commerce/server/orderReviewLifecycle.js +121 -0
  331. package/dist/commerce/server/orderReviewMedia.d.ts +11 -0
  332. package/dist/commerce/server/orderReviewMedia.js +172 -0
  333. package/dist/commerce/server/orderReviewRawUploadHandler.d.ts +40 -0
  334. package/dist/commerce/server/orderReviewRawUploadHandler.js +316 -0
  335. package/dist/commerce/server/outboxCheckoutExpiredEmailHandler.d.ts +14 -0
  336. package/dist/commerce/server/outboxCheckoutExpiredEmailHandler.js +57 -0
  337. package/dist/commerce/server/outboxCheckoutRecoveryEmailHandler.d.ts +13 -0
  338. package/dist/commerce/server/outboxCheckoutRecoveryEmailHandler.js +150 -0
  339. package/dist/commerce/server/outboxDispatchRegistry.d.ts +46 -0
  340. package/dist/commerce/server/outboxDispatchRegistry.js +184 -0
  341. package/dist/commerce/server/outboxDispatchRegistryComposition.d.ts +6 -0
  342. package/dist/commerce/server/outboxDispatchRegistryComposition.js +23 -0
  343. package/dist/commerce/server/outboxOrderDraftEmailHandler.d.ts +14 -0
  344. package/dist/commerce/server/outboxOrderDraftEmailHandler.js +130 -0
  345. package/dist/commerce/server/outboxOrderPaidEmailHandler.d.ts +21 -0
  346. package/dist/commerce/server/outboxOrderPaidEmailHandler.js +93 -0
  347. package/dist/commerce/server/outboxOrderPaidFulfillmentHandler.d.ts +3 -0
  348. package/dist/commerce/server/outboxOrderPaidFulfillmentHandler.js +1 -0
  349. package/dist/commerce/server/outboxOrderPaidFulfillmentPorts.d.ts +3 -0
  350. package/dist/commerce/server/outboxOrderPaidFulfillmentPorts.js +1 -0
  351. package/dist/commerce/server/outboxOrderRefundedEmailHandler.d.ts +13 -0
  352. package/dist/commerce/server/outboxOrderRefundedEmailHandler.js +42 -0
  353. package/dist/commerce/server/outboxPaymentFailedEmailHandler.d.ts +14 -0
  354. package/dist/commerce/server/outboxPaymentFailedEmailHandler.js +65 -0
  355. package/dist/commerce/server/outboxReturnEmailHandlers.d.ts +26 -0
  356. package/dist/commerce/server/outboxReturnEmailHandlers.js +53 -0
  357. package/dist/commerce/server/outboxShipmentDeliveredEmailHandler.d.ts +17 -0
  358. package/dist/commerce/server/outboxShipmentDeliveredEmailHandler.js +52 -0
  359. package/dist/commerce/server/outboxShipmentDispatchedEmailHandler.d.ts +13 -0
  360. package/dist/commerce/server/outboxShipmentDispatchedEmailHandler.js +87 -0
  361. package/dist/commerce/server/outboxShipmentExceptionEmailHandler.d.ts +13 -0
  362. package/dist/commerce/server/outboxShipmentExceptionEmailHandler.js +46 -0
  363. package/dist/commerce/server/referenceCheckoutHandler.d.ts +48 -0
  364. package/dist/commerce/server/referenceCheckoutHandler.js +68 -0
  365. package/dist/commerce/server/reservationSweepPort.d.ts +31 -0
  366. package/dist/commerce/server/reservationSweepPort.js +45 -0
  367. package/dist/commerce/server/starterTermsPort.d.ts +22 -0
  368. package/dist/commerce/server/starterTermsPort.js +1 -0
  369. package/dist/commerce/server/supabaseCommerceReturnsPort.d.ts +13 -0
  370. package/dist/commerce/server/supabaseCommerceReturnsPort.js +56 -0
  371. package/dist/communications/consentPurposeRegistry.d.ts +1 -1
  372. package/dist/communications/newsletterIntegrationContracts.d.ts +10 -10
  373. package/dist/composition/accountSupportContribution.d.ts +18 -0
  374. package/dist/composition/accountSupportContribution.js +21 -0
  375. package/dist/composition/commerceContribution.d.ts +21 -0
  376. package/dist/composition/commerceContribution.js +27 -0
  377. package/dist/composition/index.d.ts +2 -0
  378. package/dist/composition/index.js +2 -0
  379. package/dist/fulfillment/handlerSchemas.d.ts +69 -69
  380. package/dist/fulfillment/index.d.ts +1 -1
  381. package/dist/fulfillment/index.js +1 -1
  382. package/dist/fulfillment/paidHandoff.d.ts +12 -1
  383. package/dist/fulfillment/paidHandoff.js +2 -2
  384. package/dist/fulfillment/providerDispatchWorker.d.ts +4 -4
  385. package/dist/identity/customerContracts.d.ts +4 -4
  386. package/dist/inventory/bindings.d.ts +3 -0
  387. package/dist/inventory/bindings.js +10 -4
  388. package/dist/inventory/index.d.ts +1 -0
  389. package/dist/inventory/index.js +1 -0
  390. package/dist/inventory/managedStockAvailability.d.ts +15 -0
  391. package/dist/inventory/managedStockAvailability.js +16 -0
  392. package/dist/inventory/postgresStockAvailability.js +2 -25
  393. package/dist/inventory/schemas.d.ts +1 -1
  394. package/dist/inventory/stockReadResponse.d.ts +4 -0
  395. package/dist/inventory/stockReadResponse.js +27 -0
  396. package/dist/invoicing/snapshot.d.ts +1 -1
  397. package/dist/pricing/acquisitionQuoteBinding.d.ts +1 -1
  398. package/dist/pricing/browser/index.d.ts +6 -0
  399. package/dist/pricing/browser/index.js +6 -0
  400. package/dist/pricing/catalogFactsSchemas.d.ts +1 -1
  401. package/dist/pricing/quotePromotionEvidence.d.ts +1 -1
  402. package/dist/pricing/quoteSchemas.d.ts +56 -56
  403. package/dist/promotions/adminPromotionCodesContracts.d.ts +30 -30
  404. package/dist/promotions/adminPromotionsContracts.d.ts +16 -16
  405. package/dist/subscriptions/index.d.ts +3 -2
  406. package/dist/subscriptions/index.js +3 -2
  407. package/package.json +32 -2
  408. package/release-gates.json +90 -8
  409. package/sql/20261026120000_account_support_operator_authority.sql +693 -0
  410. package/src/account-support/accountReadFacade.ts +15 -0
  411. package/src/account-support/accountReadModels.ts +371 -0
  412. package/src/account-support/bindings.ts +28 -0
  413. package/src/account-support/contracts/account.ts +306 -0
  414. package/src/account-support/contracts/capabilities.ts +30 -0
  415. package/src/account-support/contracts/commands.ts +243 -0
  416. package/src/account-support/contracts/customer360.ts +150 -0
  417. package/src/account-support/contracts/index.ts +141 -0
  418. package/src/account-support/contracts/invoice.ts +44 -0
  419. package/src/account-support/contracts/operator.ts +123 -0
  420. package/src/account-support/contribution.ts +35 -0
  421. package/src/account-support/customer360.ts +268 -0
  422. package/src/account-support/customerAccountReadDiagnostics.ts +83 -0
  423. package/src/account-support/index.ts +72 -0
  424. package/src/account-support/invoiceAccess.ts +63 -0
  425. package/src/account-support/migrations.ts +7 -0
  426. package/src/account-support/operatorAuthority.ts +393 -0
  427. package/src/account-support/operatorRecovery.ts +136 -0
  428. package/src/account-support/orderHistory.ts +309 -0
  429. package/src/account-support/paymentMethodComposition.ts +8 -0
  430. package/src/account-support/postgresOperatorAuthority.ts +92 -0
  431. package/src/account-support/selfService.ts +83 -0
  432. package/src/account-support/subscriptionCommandCodec.ts +48 -0
  433. package/src/commerce/adapters/managed/commerceOmsControlPlane.ts +80 -0
  434. package/src/commerce/adapters/managed/commerceOmsMutations.ts +145 -0
  435. package/src/commerce/adapters/managed/commerceOmsPort.ts +158 -0
  436. package/src/commerce/adapters/managed/oms/accounting.ts +18 -0
  437. package/src/commerce/adapters/managed/oms/fulfillmentReads.ts +82 -0
  438. package/src/commerce/adapters/managed/oms/inboundEvents.ts +45 -0
  439. package/src/commerce/adapters/managed/oms/outboxEvents.ts +30 -0
  440. package/src/commerce/adapters/managed/oms/paymentAttempts.ts +19 -0
  441. package/src/commerce/adapters/managed/oms/queueSelection.ts +132 -0
  442. package/src/commerce/adapters/managed/oms/readProjections.ts +22 -0
  443. package/src/commerce/adapters/managed/oms/readQueries.ts +292 -0
  444. package/src/commerce/adapters/managed/oms/types.ts +9 -0
  445. package/src/commerce/checkoutCommandSchemas.ts +93 -0
  446. package/src/commerce/checkoutHelpers.ts +47 -0
  447. package/src/commerce/checkoutResumeSchemas.ts +164 -0
  448. package/src/commerce/checkoutSchemas.ts +182 -0
  449. package/src/commerce/commerceReturnsPort.ts +67 -0
  450. package/src/commerce/configuratorIntentPersistenceSchemas.ts +26 -0
  451. package/src/commerce/configuratorIntentSchemas.ts +47 -0
  452. package/src/commerce/contractPrimitives.ts +30 -0
  453. package/src/commerce/contracts/availability.ts +21 -0
  454. package/src/commerce/contracts/fulfillmentRecovery.ts +26 -0
  455. package/src/commerce/contracts/index.ts +17 -0
  456. package/src/commerce/contracts/intent.ts +58 -0
  457. package/src/commerce/contracts/omsTypes.ts +1217 -0
  458. package/src/commerce/contracts/order.ts +44 -0
  459. package/src/commerce/contracts/orderMoney.ts +75 -0
  460. package/src/commerce/contracts/ports.ts +124 -0
  461. package/src/commerce/contracts/recovery.ts +24 -0
  462. package/src/commerce/contracts/runtimePorts.ts +201 -0
  463. package/src/commerce/contracts/state.ts +64 -0
  464. package/src/commerce/customerDefaultsSnapshotSchemas.ts +117 -0
  465. package/src/commerce/errors.ts +53 -0
  466. package/src/commerce/fulfillmentEligibility.ts +32 -0
  467. package/src/commerce/index.ts +82 -0
  468. package/src/commerce/model/customerFulfillmentRecovery.ts +185 -0
  469. package/src/commerce/model/fulfillmentCancellationEligibility.ts +18 -0
  470. package/src/commerce/model/omsAccountingVisibility.ts +135 -0
  471. package/src/commerce/model/omsBillingInvoiceBuyer.ts +20 -0
  472. package/src/commerce/model/omsCurrency.ts +8 -0
  473. package/src/commerce/model/omsFulfillmentDebug.ts +157 -0
  474. package/src/commerce/model/omsFulfillmentSummary.ts +225 -0
  475. package/src/commerce/model/omsListTotals.ts +38 -0
  476. package/src/commerce/model/omsOperationalLadder.ts +181 -0
  477. package/src/commerce/model/omsOrderLineMoney.ts +34 -0
  478. package/src/commerce/model/omsPaymentMethodSummary.ts +19 -0
  479. package/src/commerce/model/omsReadModel.ts +302 -0
  480. package/src/commerce/model/omsReadModelCommunication.ts +32 -0
  481. package/src/commerce/model/omsReadModelHelpers.ts +279 -0
  482. package/src/commerce/model/omsReadModelList.ts +90 -0
  483. package/src/commerce/model/omsReadModelListSummary.ts +19 -0
  484. package/src/commerce/model/omsReadModelPricing.ts +57 -0
  485. package/src/commerce/model/omsReadModelProjections.ts +1 -0
  486. package/src/commerce/model/omsReadModelRowCore.ts +193 -0
  487. package/src/commerce/model/omsReadModelRows.ts +7 -0
  488. package/src/commerce/offerAvailability.ts +75 -0
  489. package/src/commerce/offerAvailabilitySchemas.ts +56 -0
  490. package/src/commerce/offerEvidenceSchemas.ts +17 -0
  491. package/src/commerce/oms/omsContractBase.ts +92 -0
  492. package/src/commerce/oms/omsContractReadAuxSchemas.ts +130 -0
  493. package/src/commerce/oms/omsContractReadSchemas.ts +303 -0
  494. package/src/commerce/oms/omsContractRequests.ts +143 -0
  495. package/src/commerce/oms/omsContracts.ts +6 -0
  496. package/src/commerce/oms/omsControlPlane.ts +85 -0
  497. package/src/commerce/oms/omsFulfillmentContractSchemas.ts +113 -0
  498. package/src/commerce/oms/omsFulfillmentDebugSchemas.ts +38 -0
  499. package/src/commerce/oms/omsFulfillmentHealthSchemas.ts +46 -0
  500. package/src/commerce/oms/omsPorts.ts +165 -0
  501. package/src/commerce/oms/omsPrimitives.ts +3 -0
  502. package/src/commerce/oms/omsProviderEvidenceSchemas.ts +13 -0
  503. package/src/commerce/orderDraftErrors.ts +28 -0
  504. package/src/commerce/orderEmailEligibility.ts +131 -0
  505. package/src/commerce/orderEmailLines.ts +22 -0
  506. package/src/commerce/orderFeedbackContracts.ts +47 -0
  507. package/src/commerce/orderMoney.ts +207 -0
  508. package/src/commerce/orderReviewContracts.ts +124 -0
  509. package/src/commerce/orderReviewPorts.ts +94 -0
  510. package/src/commerce/outboxDispatchContracts.ts +30 -0
  511. package/src/commerce/outboxEventSchemas.ts +230 -0
  512. package/src/commerce/outboxOrderDraftEmailPorts.ts +241 -0
  513. package/src/commerce/paymentContinuation.ts +5 -0
  514. package/src/commerce/ports.ts +7 -0
  515. package/src/commerce/recoveryDestination.ts +23 -0
  516. package/src/commerce/runtimeErrors.ts +19 -0
  517. package/src/commerce/salesChannelEnvelope.ts +28 -0
  518. package/src/commerce/schemas.ts +104 -0
  519. package/src/commerce/server/checkoutCompensation.ts +49 -0
  520. package/src/commerce/server/checkoutConflictClassifiers.ts +53 -0
  521. package/src/commerce/server/checkoutExpiredRecoveryPolicy.ts +107 -0
  522. package/src/commerce/server/checkoutInvoiceBuyerSnapshot.ts +36 -0
  523. package/src/commerce/server/checkoutOfferPolicyPort.ts +60 -0
  524. package/src/commerce/server/checkoutPaymentContinuationCredential.ts +222 -0
  525. package/src/commerce/server/checkoutQuoteTypes.ts +9 -0
  526. package/src/commerce/server/checkoutRecoveryOrderPort.ts +40 -0
  527. package/src/commerce/server/checkoutRecoveryToken.ts +63 -0
  528. package/src/commerce/server/checkoutRefusalContinuation.ts +29 -0
  529. package/src/commerce/server/checkoutRuntimeTypes.ts +26 -0
  530. package/src/commerce/server/commerceCheckoutCommandExecution.ts +188 -0
  531. package/src/commerce/server/commerceCheckoutCompensation.ts +66 -0
  532. package/src/commerce/server/commerceCheckoutContinuationTerms.ts +87 -0
  533. package/src/commerce/server/commerceCheckoutCustomerDefaults.ts +24 -0
  534. package/src/commerce/server/commerceCheckoutFailureHandler.ts +144 -0
  535. package/src/commerce/server/commerceCheckoutHandler.ts +269 -0
  536. package/src/commerce/server/commerceCheckoutHandlerAdmission.ts +157 -0
  537. package/src/commerce/server/commerceCheckoutHandlerHelpers.ts +223 -0
  538. package/src/commerce/server/commerceCheckoutOrchestrationError.ts +15 -0
  539. package/src/commerce/server/commerceCheckoutPromotionPriceChange.ts +83 -0
  540. package/src/commerce/server/commerceCheckoutProviderPayment.ts +45 -0
  541. package/src/commerce/server/commerceCheckoutQuoteGuard.ts +172 -0
  542. package/src/commerce/server/commerceCheckoutResume.ts +132 -0
  543. package/src/commerce/server/commerceCheckoutResumeGuard.ts +195 -0
  544. package/src/commerce/server/commerceCheckoutSavedPaymentMethod.ts +85 -0
  545. package/src/commerce/server/commerceCheckoutStartRuntimeFailure.ts +59 -0
  546. package/src/commerce/server/commerceCheckoutTiming.ts +53 -0
  547. package/src/commerce/server/commerceDiagnostics.ts +37 -0
  548. package/src/commerce/server/commerceOmsCancelOrderHandler.ts +43 -0
  549. package/src/commerce/server/commerceOmsControlPlaneHandlers.ts +71 -0
  550. package/src/commerce/server/commerceOmsHandlers.ts +275 -0
  551. package/src/commerce/server/commerceOmsMarkRefundedHandler.ts +39 -0
  552. package/src/commerce/server/commerceOrderDraft.ts +131 -0
  553. package/src/commerce/server/commercePaidOrderOrchestration.ts +275 -0
  554. package/src/commerce/server/commerceProviderAttemptFailure.ts +257 -0
  555. package/src/commerce/server/commerceReturnsHandlers.ts +143 -0
  556. package/src/commerce/server/commerceRuntimePort.ts +75 -0
  557. package/src/commerce/server/commerceRuntimeService.ts +229 -0
  558. package/src/commerce/server/commerceRuntimeStartResponse.ts +76 -0
  559. package/src/commerce/server/commerceStarterOfferGuard.ts +200 -0
  560. package/src/commerce/server/configuratorIntentPersistence.ts +161 -0
  561. package/src/commerce/server/configuratorIntentPersistenceHandler.ts +54 -0
  562. package/src/commerce/server/emailRuntime.ts +30 -0
  563. package/src/commerce/server/handlerSupport.ts +22 -0
  564. package/src/commerce/server/index.ts +181 -0
  565. package/src/commerce/server/offerAvailability.ts +275 -0
  566. package/src/commerce/server/orderDraftRpcPayload.ts +39 -0
  567. package/src/commerce/server/orderFeedbackSubmit.ts +40 -0
  568. package/src/commerce/server/orderFeedbackTokenCheck.ts +28 -0
  569. package/src/commerce/server/orderReviewAdminHandlers.ts +43 -0
  570. package/src/commerce/server/orderReviewHandlers.ts +57 -0
  571. package/src/commerce/server/orderReviewLifecycle.ts +129 -0
  572. package/src/commerce/server/orderReviewMedia.ts +170 -0
  573. package/src/commerce/server/orderReviewRawUploadHandler.ts +300 -0
  574. package/src/commerce/server/outboxCheckoutExpiredEmailHandler.ts +86 -0
  575. package/src/commerce/server/outboxCheckoutRecoveryEmailHandler.ts +188 -0
  576. package/src/commerce/server/outboxDispatchRegistry.ts +269 -0
  577. package/src/commerce/server/outboxDispatchRegistryComposition.ts +31 -0
  578. package/src/commerce/server/outboxOrderDraftEmailHandler.ts +162 -0
  579. package/src/commerce/server/outboxOrderPaidEmailHandler.ts +147 -0
  580. package/src/commerce/server/outboxOrderPaidFulfillmentHandler.ts +4 -0
  581. package/src/commerce/server/outboxOrderPaidFulfillmentPorts.ts +3 -0
  582. package/src/commerce/server/outboxOrderRefundedEmailHandler.ts +58 -0
  583. package/src/commerce/server/outboxPaymentFailedEmailHandler.ts +99 -0
  584. package/src/commerce/server/outboxReturnEmailHandlers.ts +92 -0
  585. package/src/commerce/server/outboxShipmentDeliveredEmailHandler.ts +94 -0
  586. package/src/commerce/server/outboxShipmentDispatchedEmailHandler.ts +112 -0
  587. package/src/commerce/server/outboxShipmentExceptionEmailHandler.ts +73 -0
  588. package/src/commerce/server/referenceCheckoutHandler.ts +87 -0
  589. package/src/commerce/server/reservationSweepPort.ts +67 -0
  590. package/src/commerce/server/starterTermsPort.ts +22 -0
  591. package/src/commerce/server/supabaseCommerceReturnsPort.ts +81 -0
  592. package/src/composition/accountSupportContribution.ts +28 -0
  593. package/src/composition/commerceContribution.ts +35 -0
  594. package/src/composition/index.ts +2 -0
  595. package/src/fulfillment/index.ts +1 -1
  596. package/src/fulfillment/paidHandoff.ts +2 -2
  597. package/src/inventory/bindings.ts +12 -4
  598. package/src/inventory/index.ts +1 -0
  599. package/src/inventory/managedStockAvailability.ts +23 -0
  600. package/src/inventory/postgresStockAvailability.ts +2 -21
  601. package/src/inventory/stockReadResponse.ts +25 -0
  602. package/src/pricing/browser/index.ts +6 -0
  603. package/src/subscriptions/index.ts +3 -2
@@ -0,0 +1,276 @@
1
+ import { buildOmsOrderDetailResponse, buildOmsOrderListResponse } from "../../../model/omsReadModel.js";
2
+ import { paymentStatusForOrder } from "../../../model/omsReadModelHelpers.js";
3
+ import { ORDER_HEADER_MONEY_COLUMNS, ORDER_ITEM_MONEY_COLUMNS } from "../../../orderMoney.js";
4
+ import { omsDeliveryContactResolutionSchema } from "../../../oms/omsContracts.js";
5
+ import { assertOmsOrderRowCurrency, CommerceOmsPersistenceError } from "../../../oms/omsPorts.js";
6
+ import { readAccountingOutbox } from "./accounting.js";
7
+ import { readFulfillmentOrdersByOrderIds, readFulfillmentParcelsByOrderId, readShipmentRefsByOrderId, readShipmentRefsByOrderIds } from "./fulfillmentReads.js";
8
+ import { readOrderPaidOutboxEvents } from "./outboxEvents.js";
9
+ import { readActivePaymentAttempts } from "./paymentAttempts.js";
10
+ import { readQueueSelection } from "./queueSelection.js";
11
+ import { emptyOmsManagedReadProjections } from "./readProjections.js";
12
+ import { distinctIds } from "./types.js";
13
+ // `sales_channels(slug)` is the order's source channel, embedded through the only
14
+ // foreign key between the two tables and mirroring the `inventory_locations(code)`
15
+ // embed on the reservation read below. The channel id itself is deliberately not
16
+ // selected: nothing on this read path addresses a channel by id, only by slug.
17
+ const ORDER_COLUMNS = `id, order_number, client_id, status, mode, ${ORDER_HEADER_MONEY_COLUMNS}, metadata, created_at, updated_at, subscription_id, subscription_cycle_id, shipping_address_id, source_kind, source_order_ref, sales_channels(slug)`;
18
+ const ORDER_ITEM_COLUMNS = `id, order_id, sku_id, quantity, ${ORDER_ITEM_MONEY_COLUMNS}, product_snapshot, variant_snapshot`;
19
+ const ADDRESS_COLUMNS = "id, label, line1, line2, city, postal_code, country, recipient_name, contact_phone, company_name, tax_id, delivery_notes, courier_instructions";
20
+ const INVOICE_COLUMNS = "id, order_id, invoice_ref, status, provider_kind, provider_invoice_number, total_gross_cents, currency, blocked_reason, updated_at";
21
+ const COMMUNICATION_DELIVERY_COLUMNS = "id, purpose, template_slug, trigger_source, trigger_event, aggregate_type, aggregate_id, dedupe_key, status, provider_kind, provider_message_id, scheduled_due_at, expected_send_at, queued_at, first_attempt_at, sent_at, delivered_at, terminal_at, last_error_code, outbox_event_id, platform_job_run_id, email_send_id, metadata, created_at, updated_at";
22
+ export async function listCommerceOmsOrders(client, request, options = {}) {
23
+ const projections = readProjections(options.projections);
24
+ const queue = await readQueueSelection(client, request, { currency: projections.model?.currency, projectResult: projections.projectQueue, matchSchema: projections.queueMatchSchema });
25
+ if (!queue.orderIds.length) {
26
+ return buildOmsOrderListResponse({
27
+ projections: projections.model,
28
+ orders: [],
29
+ paymentIntents: [],
30
+ paymentAttempts: [],
31
+ activeHoldCounts: {},
32
+ summaryCounts: queue.summaryCounts,
33
+ summaryTotals: queue.summaryTotals,
34
+ searchMatches: queue.matches,
35
+ totalCount: queue.totalCount,
36
+ page: request.page,
37
+ pageSize: request.pageSize,
38
+ });
39
+ }
40
+ const ordersResult = await client.query("commerce_orders").select(options.projections?.orderColumns ?? ORDER_COLUMNS).in("id", queue.orderIds);
41
+ if (ordersResult.error)
42
+ throw new CommerceOmsPersistenceError("Commerce OMS order list read failed");
43
+ const rowsById = new Map((ordersResult.data ?? []).map((order) => [order.id, order]));
44
+ const orders = queue.orderIds.map((id) => rowsById.get(id)).filter((order) => Boolean(order));
45
+ if (orders.length !== queue.orderIds.length)
46
+ throw new CommerceOmsPersistenceError("Commerce OMS queue order hydration mismatch");
47
+ // The cast above is the only thing asserting these rows' shape. Currency is
48
+ // the one column that can defeat the read model, so it is checked here where
49
+ // the order id is still in hand, not fifteen frames later inside a money node.
50
+ assertOmsOrderRowCurrency(orders, projections.model?.currency);
51
+ const orderIds = orders.map((order) => order.id);
52
+ const clientIds = distinctIds(orders.map((order) => order.client_id));
53
+ const related = await readListRelations(client, orders, orderIds, clientIds, projections);
54
+ const fulfillmentOrderIds = related.fulfillmentOrders.map((order) => order.id);
55
+ const [fulfillmentOperations, dispatchRefs, statusEvidence, accountingOutbox] = await Promise.all([
56
+ projections.readFulfillmentOperations(client, fulfillmentOrderIds),
57
+ projections.readProviderDispatchRefs(client, fulfillmentOrderIds),
58
+ projections.readProviderStatusEvidence(client, fulfillmentOrderIds),
59
+ readAccountingOutbox(client, related.invoices),
60
+ ]);
61
+ return buildOmsOrderListResponse({
62
+ orders,
63
+ paymentIntents: related.paymentIntents,
64
+ paymentAttempts: related.paymentAttempts,
65
+ activeHoldCounts: countHoldsByOrder(related.activeHolds),
66
+ activeHoldReasons: holdReasonsByOrder(related.activeHolds),
67
+ fulfillmentHealthDigests: projections.buildHealthDigests({ orders, paymentIntents: related.paymentIntents, fulfillmentOrders: related.fulfillmentOrders, dispatchRefs, statusEvidence }),
68
+ customers: related.customers,
69
+ identityExtras: related.identityExtras,
70
+ projections: projections.model,
71
+ orderItems: related.orderItems,
72
+ inventoryReservations: related.reservations,
73
+ fulfillmentOrders: related.fulfillmentOrders,
74
+ fulfillmentOperations,
75
+ shipmentExternalRefs: related.shipmentRefs,
76
+ providerDispatchRefs: dispatchRefs,
77
+ providerStatusEvidence: statusEvidence,
78
+ releasedProviderExceptionHolds: related.releasedProviderExceptionHolds,
79
+ accountingInvoices: related.invoices,
80
+ accountingOutbox,
81
+ subscriptionCycleStatuses: related.subscriptionCycleStatuses,
82
+ summaryCounts: queue.summaryCounts,
83
+ summaryTotals: queue.summaryTotals,
84
+ searchMatches: queue.matches,
85
+ totalCount: queue.totalCount,
86
+ page: request.page,
87
+ pageSize: request.pageSize,
88
+ });
89
+ }
90
+ export async function getCommerceOmsOrderDetail(client, request, options = {}) {
91
+ const orderResult = await client.query("commerce_orders").select(options.projections?.orderColumns ?? ORDER_COLUMNS).eq("id", request.orderId).maybeSingle();
92
+ if (orderResult.error)
93
+ throw new CommerceOmsPersistenceError("Commerce OMS order detail read failed");
94
+ if (!orderResult.data)
95
+ return null;
96
+ return readOrderDetail(client, orderResult.data, options);
97
+ }
98
+ /** Hydrate a bounded selection without repeating its canonical header query. */
99
+ export async function getCommerceOmsOrderDetails(client, orderIds, options = {}) {
100
+ if (orderIds.length === 0)
101
+ return [];
102
+ if (orderIds.length > 25)
103
+ throw new CommerceOmsPersistenceError("Commerce OMS detail batch exceeds 25 orders");
104
+ const result = await client.query("commerce_orders").select(options.projections?.orderColumns ?? ORDER_COLUMNS).in("id", [...new Set(orderIds)]);
105
+ if (result.error)
106
+ throw new CommerceOmsPersistenceError("Commerce OMS order detail read failed");
107
+ const orders = new Map((result.data ?? []).map((order) => [order.id, order]));
108
+ return Promise.all(orderIds.map((id) => {
109
+ const order = orders.get(id);
110
+ return order ? readOrderDetail(client, order, options) : null;
111
+ }));
112
+ }
113
+ async function readOrderDetail(client, order, options) {
114
+ const projections = readProjections(options.projections);
115
+ assertOmsOrderRowCurrency([order], projections.model?.currency);
116
+ const [related, resolutionResult] = await Promise.all([
117
+ readDetailRelations(client, order, projections),
118
+ client.rpc("commerce_oms_resolve_delivery_contact_v1", { p_order_id: order.id }),
119
+ ]);
120
+ if (resolutionResult.error)
121
+ throw new CommerceOmsPersistenceError("Commerce OMS delivery contact resolution failed");
122
+ const contactResolution = omsDeliveryContactResolutionSchema.safeParse(resolutionResult.data);
123
+ if (!contactResolution.success)
124
+ throw new CommerceOmsPersistenceError("Commerce OMS delivery contact resolution was malformed");
125
+ const intent = related.intent;
126
+ // Every parcel, current first. Provider evidence stays keyed on the current
127
+ // parcel; widening it would attribute a sibling's state to the live shipment.
128
+ // Superseded parcels travel as separate support/claim nodes below.
129
+ const parcels = related.parcels;
130
+ const fulfillmentOrder = parcels[0] ?? null;
131
+ const invoice = related.invoice;
132
+ const fulfillmentOrderIds = fulfillmentOrder ? [fulfillmentOrder.id] : [];
133
+ const [attemptsResult, transitionsResult, fulfillmentOperations, providerAttempts, dispatchRefs, statusEvidence, releasedProviderExceptionHolds, outboxResult, orderPaidOutboxResult, communicationResult] = await Promise.all([
134
+ intent ? client.query("commerce_payment_attempts").select("id, status, provider, provider_attempt_id, next_action_kind, updated_at").eq("payment_intent_id", intent.id).order("created_at", { ascending: false }) : emptyRows(),
135
+ intent ? client.query("commerce_payment_state_transitions").select("id, transition_kind, from_status, to_status, reason, occurred_at").eq("payment_intent_id", intent.id).order("occurred_at", { ascending: false }) : emptyRows(),
136
+ projections.readFulfillmentOperations(client, fulfillmentOrderIds),
137
+ projections.readProviderAttempts(client, fulfillmentOrderIds),
138
+ projections.readProviderDispatchRefs(client, fulfillmentOrderIds),
139
+ projections.readProviderStatusEvidence(client, fulfillmentOrderIds),
140
+ projections.readReleasedProviderExceptionHolds(client, [order.id]),
141
+ invoice
142
+ ? client
143
+ .query("accounting_invoice_issue_outbox")
144
+ .select("invoice_id, status, attempt_count, next_attempt_at, last_error, created_at")
145
+ .eq("invoice_id", invoice.id)
146
+ .order("created_at", { ascending: false })
147
+ : emptyRows(),
148
+ readOrderPaidOutboxEvents(client, order.id),
149
+ client
150
+ .query("communication_email_deliveries")
151
+ .select(COMMUNICATION_DELIVERY_COLUMNS)
152
+ .eq("aggregate_type", "commerce_order")
153
+ .eq("aggregate_id", order.id)
154
+ .order("created_at", { ascending: false }),
155
+ ]);
156
+ if ([attemptsResult, transitionsResult, outboxResult, orderPaidOutboxResult, communicationResult].some((result) => result.error))
157
+ throw new CommerceOmsPersistenceError("Commerce OMS detail expansion read failed");
158
+ const inboundProviderEvents = await projections.readInboundEvents(client, { order, dispatchRefs });
159
+ const providerStockCurrent = await projections.readProviderStockCurrent(client, related.orderItems);
160
+ const paymentAttempts = (attemptsResult.data ?? []);
161
+ const fulfillmentHealth = projections.buildHealth({
162
+ order,
163
+ paymentStatus: paymentStatusForOrder(order.id, intent ? [intent] : []),
164
+ fulfillmentOrders: fulfillmentOrder ? [fulfillmentOrder] : [],
165
+ dispatchRefs,
166
+ statusEvidence,
167
+ orderPaidOutboxEvents: (orderPaidOutboxResult.data ?? []),
168
+ });
169
+ return buildOmsOrderDetailResponse({
170
+ order,
171
+ paymentIntent: intent,
172
+ paymentAttempts,
173
+ paymentTransitions: (transitionsResult.data ?? []),
174
+ holds: related.holds,
175
+ operations: related.operations,
176
+ customer: related.customer,
177
+ identityExtras: related.identityExtras,
178
+ projections: projections.model,
179
+ shippingAddress: related.shippingAddress,
180
+ accountingInvoice: invoice,
181
+ accountingOutbox: (outboxResult.data ?? []),
182
+ communicationDeliveries: (communicationResult.data ?? []),
183
+ orderItems: related.orderItems,
184
+ inventoryReservations: related.reservations,
185
+ fulfillmentOrders: fulfillmentOrder ? [fulfillmentOrder] : [],
186
+ supersededFulfillmentOrders: parcels.slice(1),
187
+ fulfillmentOperations,
188
+ shipmentExternalRefs: related.shipmentRefs,
189
+ providerAttempts,
190
+ providerDispatchRefs: dispatchRefs,
191
+ providerStatusEvidence: statusEvidence,
192
+ releasedProviderExceptionHolds,
193
+ fulfillmentHealth,
194
+ inboundProviderEvents,
195
+ providerStockCurrent,
196
+ subscriptionCycleStatus: related.cycleStatus,
197
+ subscriptionCyclePaidAt: related.cyclePaidAt, subscriptionNextCycleAt: related.subscriptionNextCycleAt,
198
+ actionFlags: options.actionFlags,
199
+ deliveryContactResolution: contactResolution.data,
200
+ });
201
+ }
202
+ async function readListRelations(client, orders, orderIds, clientIds, projections) {
203
+ const cycleIds = distinctIds(orders.map((order) => order.subscription_cycle_id ?? null));
204
+ const [intent, hold, releasedProviderExceptionHolds, customer, identityExtras, items, reservations, fulfillment, shipmentRefs, invoice, cycles] = await Promise.all([
205
+ orderIds.length ? client.query("commerce_payment_intents").select("id, order_id, payment_id, status, active_attempt_id, provider_payment_id, updated_at").in("order_id", orderIds) : emptyRows(),
206
+ orderIds.length ? client.query("commerce_order_holds").select("order_id, reason").in("order_id", orderIds).eq("status", "active") : emptyRows(),
207
+ projections.readReleasedProviderExceptionHolds(client, orderIds),
208
+ clientIds.length ? client.query("clients").select("id, email, first_name, last_name, phone, lifecycle_stage").in("id", clientIds) : emptyRows(),
209
+ projections.readIdentity(client, orders, "list"),
210
+ orderIds.length ? client.query("commerce_order_items").select(ORDER_ITEM_COLUMNS).in("order_id", orderIds) : emptyRows(),
211
+ orderIds.length ? client.query("inventory_reservations").select("id, order_id, order_item_id, quantity, status, expires_at, location_id, inventory_locations!inventory_reservations_location_id_fkey(code)").in("order_id", orderIds) : emptyRows(),
212
+ readFulfillmentOrdersByOrderIds(client, orderIds),
213
+ readShipmentRefsByOrderIds(client, orderIds),
214
+ orderIds.length ? client.query("accounting_invoices").select(projections.invoiceColumns ?? INVOICE_COLUMNS).in("order_id", orderIds).is("correction_of_invoice_id", null) : emptyRows(),
215
+ cycleIds.length ? client.query("subscription_cycles").select("id, status").in("id", cycleIds) : emptyRows(),
216
+ ]);
217
+ if (intent.error || hold.error || customer.error || items.error || reservations.error || fulfillment.error || shipmentRefs.error || invoice.error || cycles.error) {
218
+ throw new CommerceOmsPersistenceError("Commerce OMS related list read failed");
219
+ }
220
+ const paymentIntents = (intent.data ?? []);
221
+ const paymentAttempts = await readActivePaymentAttempts(client, paymentIntents);
222
+ return {
223
+ paymentIntents,
224
+ paymentAttempts,
225
+ activeHolds: (hold.data ?? []),
226
+ releasedProviderExceptionHolds,
227
+ customers: (customer.data ?? []),
228
+ identityExtras,
229
+ orderItems: (items.data ?? []),
230
+ reservations: (reservations.data ?? []),
231
+ fulfillmentOrders: (fulfillment.data ?? []),
232
+ shipmentRefs: (shipmentRefs.data ?? []),
233
+ invoices: (invoice.data ?? []).map(projections.mapInvoice),
234
+ subscriptionCycleStatuses: Object.fromEntries((cycles.data ?? []).map((cycle) => [cycle.id, cycle.status])),
235
+ };
236
+ }
237
+ async function readDetailRelations(client, order, projections) {
238
+ const [intent, holds, operations, items, cycle, reservations, fulfillment, shipmentRefs, customer, identityExtras, address, invoice, subscription] = await Promise.all([
239
+ client.query("commerce_payment_intents").select("id, order_id, payment_id, status, active_attempt_id, provider_payment_id, updated_at").eq("order_id", order.id).maybeSingle(),
240
+ client.query("commerce_order_holds").select("id, order_id, status, reason, note, created_at, released_at").eq("order_id", order.id).order("created_at", { ascending: false }),
241
+ client.query("commerce_order_operations").select("id, order_id, operation_type, hold_id, actor_user_id, occurred_at, payload").eq("order_id", order.id).order("occurred_at", { ascending: false }),
242
+ client.query("commerce_order_items").select(ORDER_ITEM_COLUMNS).eq("order_id", order.id),
243
+ order.subscription_cycle_id ? client.query("subscription_cycles").select("status, paid_at").eq("id", order.subscription_cycle_id).maybeSingle() : emptyOne(),
244
+ client.query("inventory_reservations").select("id, order_id, order_item_id, quantity, status, expires_at, location_id, inventory_locations!inventory_reservations_location_id_fkey(code)").eq("order_id", order.id).order("created_at", { ascending: false }),
245
+ readFulfillmentParcelsByOrderId(client, order.id),
246
+ readShipmentRefsByOrderId(client, order.id),
247
+ order.client_id ? client.query("clients").select("id, email, first_name, last_name, phone, lifecycle_stage").eq("id", order.client_id).maybeSingle() : emptyOne(),
248
+ projections.readIdentity(client, [order], "detail"),
249
+ order.shipping_address_id ? client.query("addresses").select(ADDRESS_COLUMNS).eq("id", order.shipping_address_id).maybeSingle() : emptyOne(),
250
+ client.query("accounting_invoices").select(projections.invoiceColumns ?? INVOICE_COLUMNS).eq("order_id", order.id).is("correction_of_invoice_id", null).maybeSingle(),
251
+ order.subscription_id ? client.query("subscriptions").select("next_cycle_at").eq("id", order.subscription_id).maybeSingle() : emptyOne(), // read-only display enrichment (next CHARGE date); deliberately absent from the error check below so a failure degrades to a dash instead of failing the whole detail
252
+ ]);
253
+ if (intent.error || holds.error || operations.error || items.error || cycle.error || reservations.error || fulfillment.error || shipmentRefs.error || customer.error || address.error || invoice.error) {
254
+ throw new CommerceOmsPersistenceError("Commerce OMS related detail read failed");
255
+ }
256
+ return {
257
+ intent: (intent.data ?? null),
258
+ holds: (holds.data ?? []),
259
+ operations: (operations.data ?? []),
260
+ orderItems: (items.data ?? []),
261
+ cycleStatus: (cycle.data?.status ?? null),
262
+ cyclePaidAt: (cycle.data?.paid_at ?? null), subscriptionNextCycleAt: (subscription.data?.next_cycle_at ?? null),
263
+ reservations: (reservations.data ?? []),
264
+ parcels: (fulfillment.data ?? []),
265
+ shipmentRefs: (shipmentRefs.data ?? []),
266
+ customer: (customer.data ?? null),
267
+ identityExtras: identityExtras[order.id],
268
+ shippingAddress: (address.data ?? null),
269
+ invoice: invoice.data ? projections.mapInvoice(invoice.data) : null,
270
+ };
271
+ }
272
+ function countHoldsByOrder(rows) { return rows.reduce((counts, row) => ({ ...counts, [row.order_id]: (counts[row.order_id] ?? 0) + 1 }), {}); }
273
+ function holdReasonsByOrder(rows) { return rows.reduce((reasons, row) => ({ ...reasons, [row.order_id]: [...new Set([...(reasons[row.order_id] ?? []), row.reason])] }), {}); }
274
+ function emptyRows() { return Promise.resolve({ data: [], error: null }); }
275
+ function emptyOne() { return Promise.resolve({ data: null, error: null }); }
276
+ function readProjections(projections) { return { ...emptyOmsManagedReadProjections, ...projections }; }
@@ -0,0 +1,2 @@
1
+ export type { CommerceOmsRpcClient, CommerceOmsStore, ManagedQueryBuilder, ManagedQueryResult, RpcError } from "../../../contracts/omsTypes.js";
2
+ export declare function distinctIds(values: Array<string | null | undefined>): string[];
@@ -0,0 +1,7 @@
1
+ // Every read in this directory fans out to a follow-up query keyed on ids it just
2
+ // collected, so all three needed the same two steps: drop the rows that carry no
3
+ // id, and ask for each id once. `compact` was the wrong name for that - it also
4
+ // de-duplicates, which the trim-only helpers elsewhere deliberately do not.
5
+ export function distinctIds(values) {
6
+ return [...new Set(values.filter((value) => Boolean(value)))];
7
+ }
@@ -0,0 +1,89 @@
1
+ import { z } from "zod";
2
+ export declare const CHECKOUT_COMMAND_V1 = "commerce.checkout_command.v1";
3
+ export declare const REFERENCE_CHECKOUT_V1 = "commerce.reference_checkout.v1";
4
+ export declare function createCheckoutCommandSchemas<IntentStatus extends z.ZodType<string>, AttemptStatus extends z.ZodType<string>>(schemas: {
5
+ sku: z.ZodType<string, string>;
6
+ paymentIntentStatus: IntentStatus;
7
+ paymentAttemptStatus: AttemptStatus;
8
+ }): {
9
+ checkoutCommandV1Schema: z.ZodObject<{
10
+ version: z.ZodLiteral<"commerce.checkout_command.v1">;
11
+ idempotencyKey: z.ZodString;
12
+ mode: z.ZodEnum<{
13
+ one_time: "one_time";
14
+ subscription: "subscription";
15
+ }>;
16
+ lines: z.ZodArray<z.ZodObject<{
17
+ sku: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
18
+ quantity: z.ZodNumber;
19
+ }, z.core.$strict>>;
20
+ customer: z.ZodObject<{
21
+ firstName: z.ZodString;
22
+ lastName: z.ZodString;
23
+ email: z.ZodString;
24
+ phone: z.ZodString;
25
+ }, z.core.$strict>;
26
+ shippingAddress: z.ZodObject<{
27
+ street: z.ZodString;
28
+ postalCode: z.ZodString;
29
+ city: z.ZodString;
30
+ country: z.ZodString;
31
+ }, z.core.$strict>;
32
+ currency: z.ZodString;
33
+ cadenceDays: z.ZodOptional<z.ZodNumber>;
34
+ }, z.core.$strict>;
35
+ referenceCheckoutRequestSchema: z.ZodObject<{
36
+ command: z.ZodObject<{
37
+ version: z.ZodLiteral<"commerce.checkout_command.v1">;
38
+ idempotencyKey: z.ZodString;
39
+ mode: z.ZodEnum<{
40
+ one_time: "one_time";
41
+ subscription: "subscription";
42
+ }>;
43
+ lines: z.ZodArray<z.ZodObject<{
44
+ sku: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
45
+ quantity: z.ZodNumber;
46
+ }, z.core.$strict>>;
47
+ customer: z.ZodObject<{
48
+ firstName: z.ZodString;
49
+ lastName: z.ZodString;
50
+ email: z.ZodString;
51
+ phone: z.ZodString;
52
+ }, z.core.$strict>;
53
+ shippingAddress: z.ZodObject<{
54
+ street: z.ZodString;
55
+ postalCode: z.ZodString;
56
+ city: z.ZodString;
57
+ country: z.ZodString;
58
+ }, z.core.$strict>;
59
+ currency: z.ZodString;
60
+ cadenceDays: z.ZodOptional<z.ZodNumber>;
61
+ }, z.core.$strict>;
62
+ }, z.core.$strict>;
63
+ referenceCheckoutResponseSchema: z.ZodObject<{
64
+ version: z.ZodLiteral<"commerce.reference_checkout.v1">;
65
+ orderId: z.ZodGUID;
66
+ clientId: z.ZodGUID;
67
+ paymentIntentId: z.ZodGUID;
68
+ paymentAttemptId: z.ZodNullable<z.ZodGUID>;
69
+ paymentStatus: IntentStatus;
70
+ paymentAttemptStatus: z.ZodNullable<AttemptStatus>;
71
+ replayed: z.ZodBoolean;
72
+ total: z.ZodObject<{
73
+ amountMinor: z.ZodNumber;
74
+ currency: z.ZodString;
75
+ }, z.core.$strict>;
76
+ }, z.core.$strict>;
77
+ };
78
+ /**
79
+ * The persistence result deliberately carries only IDs already owned by the
80
+ * composed persistence adapter. A subject is optional for a generic checkout.
81
+ */
82
+ export interface CheckoutCommandPersistenceResult {
83
+ idempotencyKey: string;
84
+ clientId: string;
85
+ subjectId: string | null;
86
+ shippingAddressId: string;
87
+ replayed: boolean;
88
+ }
89
+ export type CheckoutCommandV1 = z.output<ReturnType<typeof createCheckoutCommandSchemas>["checkoutCommandV1Schema"]>;
@@ -0,0 +1,70 @@
1
+ import { z } from "zod";
2
+ import { commerceIdempotencyKeySchema } from "./contractPrimitives.js";
3
+ export const CHECKOUT_COMMAND_V1 = "commerce.checkout_command.v1";
4
+ export const REFERENCE_CHECKOUT_V1 = "commerce.reference_checkout.v1";
5
+ const isoCurrencySchema = z.string().regex(/^[A-Z]{3}$/);
6
+ export function createCheckoutCommandSchemas(schemas) {
7
+ const checkoutCommandV1Schema = z
8
+ .object({
9
+ version: z.literal(CHECKOUT_COMMAND_V1),
10
+ idempotencyKey: commerceIdempotencyKeySchema,
11
+ mode: z.enum(["one_time", "subscription"]),
12
+ lines: z.array(z.object({
13
+ sku: schemas.sku,
14
+ quantity: z.number().int().positive().max(99),
15
+ }).strict()).min(1).max(50),
16
+ customer: z.object({
17
+ firstName: z.string().trim().min(1).max(80),
18
+ lastName: z.string().trim().min(1).max(80),
19
+ email: z.string().trim().email().max(160),
20
+ phone: z.string().trim().min(6).max(32),
21
+ }).strict(),
22
+ shippingAddress: z.object({
23
+ street: z.string().trim().min(3).max(160),
24
+ postalCode: z.string().trim().min(3).max(16),
25
+ city: z.string().trim().min(2).max(120),
26
+ country: z.string().trim().regex(/^[A-Z]{2}$/),
27
+ }).strict(),
28
+ currency: isoCurrencySchema,
29
+ cadenceDays: z.number().int().positive().max(120).optional(),
30
+ })
31
+ .strict()
32
+ .superRefine((command, ctx) => {
33
+ if (command.mode === "subscription" && command.cadenceDays === undefined) {
34
+ ctx.addIssue({
35
+ code: z.ZodIssueCode.custom,
36
+ message: "subscription checkout command requires cadenceDays",
37
+ path: ["cadenceDays"],
38
+ });
39
+ }
40
+ if (command.mode === "one_time" && command.cadenceDays !== undefined) {
41
+ ctx.addIssue({
42
+ code: z.ZodIssueCode.custom,
43
+ message: "one-time checkout command does not accept cadenceDays",
44
+ path: ["cadenceDays"],
45
+ });
46
+ }
47
+ });
48
+ /**
49
+ * The local reference-store BFF accepts only the neutral command. Payment
50
+ * provider selection stays inside trusted server composition.
51
+ */
52
+ const referenceCheckoutRequestSchema = z.object({
53
+ command: checkoutCommandV1Schema,
54
+ }).strict();
55
+ const referenceCheckoutResponseSchema = z.object({
56
+ version: z.literal(REFERENCE_CHECKOUT_V1),
57
+ orderId: z.guid(),
58
+ clientId: z.guid(),
59
+ paymentIntentId: z.guid(),
60
+ paymentAttemptId: z.guid().nullable(),
61
+ paymentStatus: schemas.paymentIntentStatus,
62
+ paymentAttemptStatus: schemas.paymentAttemptStatus.nullable(),
63
+ replayed: z.boolean(),
64
+ total: z.object({
65
+ amountMinor: z.number().int().nonnegative(),
66
+ currency: isoCurrencySchema,
67
+ }).strict(),
68
+ }).strict();
69
+ return { checkoutCommandV1Schema, referenceCheckoutRequestSchema, referenceCheckoutResponseSchema };
70
+ }
@@ -0,0 +1,21 @@
1
+ export interface OrderDeliveryContactInput {
2
+ recipientName: string;
3
+ contactEmail: string;
4
+ contactPhone: string;
5
+ line1: string;
6
+ line2?: string | null;
7
+ city: string;
8
+ postalCode: string;
9
+ country: string;
10
+ selectedDelivery?: unknown;
11
+ deliveryInstructions?: string | null;
12
+ courierInstructions?: string | null;
13
+ }
14
+ /**
15
+ * Complete order-owned delivery authority. Profile and address-book rows can
16
+ * keep serving defaults, but fulfillment must not reconstruct an order's
17
+ * recipient from those mutable records after checkout.
18
+ */
19
+ export declare function buildOrderDeliveryContact(input: OrderDeliveryContactInput): Record<string, unknown>;
20
+ export declare function uuidFromOrderRef(orderRef: string): string;
21
+ export declare function messageOf(error: unknown, stage: string): string;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Complete order-owned delivery authority. Profile and address-book rows can
3
+ * keep serving defaults, but fulfillment must not reconstruct an order's
4
+ * recipient from those mutable records after checkout.
5
+ */
6
+ export function buildOrderDeliveryContact(input) {
7
+ return {
8
+ schemaVersion: 1,
9
+ source: "checkout_submission",
10
+ revision: 1,
11
+ recipientName: input.recipientName.trim(),
12
+ contactEmail: input.contactEmail,
13
+ contactPhone: input.contactPhone,
14
+ line1: input.line1,
15
+ line2: input.line2 ?? null,
16
+ city: input.city,
17
+ postalCode: input.postalCode,
18
+ country: input.country,
19
+ selectedDelivery: input.selectedDelivery ?? null,
20
+ deliveryInstructions: input.deliveryInstructions ?? null,
21
+ courierInstructions: input.courierInstructions ?? null,
22
+ };
23
+ }
24
+ export function uuidFromOrderRef(orderRef) {
25
+ return orderRef.replace(/^order_/, "");
26
+ }
27
+ export function messageOf(error, stage) {
28
+ return error instanceof Error ? `${stage}: ${error.message}` : `${stage}: unknown`;
29
+ }
@@ -0,0 +1,158 @@
1
+ import { z } from "zod";
2
+ export declare const CHECKOUT_RESUME_CONTRACT_VERSION = "commerce.checkout_resume.v1";
3
+ export declare const checkoutResumeTokenSchema: z.ZodString;
4
+ export declare const checkoutResumeModeSchema: z.ZodEnum<{
5
+ one_time: "one_time";
6
+ subscription: "subscription";
7
+ }>;
8
+ export declare const checkoutResumeCompletionCoreSchema: z.ZodObject<{
9
+ productSelection: z.ZodDefault<z.ZodBoolean>;
10
+ cadence: z.ZodDefault<z.ZodBoolean>;
11
+ account: z.ZodDefault<z.ZodBoolean>;
12
+ shipping: z.ZodDefault<z.ZodBoolean>;
13
+ billing: z.ZodDefault<z.ZodBoolean>;
14
+ payment: z.ZodDefault<z.ZodBoolean>;
15
+ review: z.ZodDefault<z.ZodBoolean>;
16
+ }, z.core.$strict>;
17
+ export declare function createCheckoutResumeSchemas<Section extends z.ZodType<string>, Redacted extends z.ZodType<string>, Completion extends z.ZodType>(input: {
18
+ sectionSchema: Section;
19
+ redactedFieldSchema: Redacted;
20
+ completionSchema: Completion;
21
+ productSlugSchema: z.ZodType<string, string>;
22
+ skuSchema: z.ZodType<string, string>;
23
+ additionalForbiddenKeys?: readonly string[];
24
+ }): {
25
+ checkoutResumeDraftStateSchema: z.ZodObject<{
26
+ version: z.ZodLiteral<"commerce.checkout_resume.v1">;
27
+ mode: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
28
+ one_time: "one_time";
29
+ subscription: "subscription";
30
+ }>>>;
31
+ cadenceDays: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
32
+ cart: z.ZodDefault<z.ZodObject<{
33
+ items: z.ZodDefault<z.ZodArray<z.ZodObject<{
34
+ sku: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
35
+ productSlug: z.ZodDefault<z.ZodNullable<z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>>;
36
+ variantId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
37
+ quantity: z.ZodNumber;
38
+ }, z.core.$strict>>>;
39
+ }, z.core.$strict>>;
40
+ completion: Completion;
41
+ redactedFields: z.ZodDefault<z.ZodArray<Redacted>>;
42
+ }, z.core.$strict>;
43
+ checkoutResumeUpsertRequestSchema: z.ZodObject<{
44
+ resumeToken: z.ZodOptional<z.ZodString>;
45
+ idempotencyKey: z.ZodOptional<z.ZodString>;
46
+ lastSectionId: Section;
47
+ draftState: z.ZodObject<{
48
+ version: z.ZodLiteral<"commerce.checkout_resume.v1">;
49
+ mode: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
50
+ one_time: "one_time";
51
+ subscription: "subscription";
52
+ }>>>;
53
+ cadenceDays: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
54
+ cart: z.ZodDefault<z.ZodObject<{
55
+ items: z.ZodDefault<z.ZodArray<z.ZodObject<{
56
+ sku: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
57
+ productSlug: z.ZodDefault<z.ZodNullable<z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>>;
58
+ variantId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
59
+ quantity: z.ZodNumber;
60
+ }, z.core.$strict>>>;
61
+ }, z.core.$strict>>;
62
+ completion: Completion;
63
+ redactedFields: z.ZodDefault<z.ZodArray<Redacted>>;
64
+ }, z.core.$strict>;
65
+ ttlMinutes: z.ZodDefault<z.ZodNumber>;
66
+ }, z.core.$strict>;
67
+ checkoutResumeReadRequestSchema: z.ZodObject<{
68
+ resumeToken: z.ZodString;
69
+ }, z.core.$strict>;
70
+ checkoutResumeDraftSchema: z.ZodObject<{
71
+ id: z.ZodGUID;
72
+ contractVersion: z.ZodLiteral<"commerce.checkout_resume.v1">;
73
+ lastSectionId: Section;
74
+ draftState: z.ZodObject<{
75
+ version: z.ZodLiteral<"commerce.checkout_resume.v1">;
76
+ mode: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
77
+ one_time: "one_time";
78
+ subscription: "subscription";
79
+ }>>>;
80
+ cadenceDays: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
81
+ cart: z.ZodDefault<z.ZodObject<{
82
+ items: z.ZodDefault<z.ZodArray<z.ZodObject<{
83
+ sku: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
84
+ productSlug: z.ZodDefault<z.ZodNullable<z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>>;
85
+ variantId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
86
+ quantity: z.ZodNumber;
87
+ }, z.core.$strict>>>;
88
+ }, z.core.$strict>>;
89
+ completion: Completion;
90
+ redactedFields: z.ZodDefault<z.ZodArray<Redacted>>;
91
+ }, z.core.$strict>;
92
+ expiresAt: z.ZodString;
93
+ createdAt: z.ZodString;
94
+ updatedAt: z.ZodString;
95
+ replayed: z.ZodBoolean;
96
+ }, z.core.$strict>;
97
+ checkoutResumeUpsertResponseSchema: z.ZodObject<{
98
+ contractVersion: z.ZodLiteral<"commerce.checkout_resume.v1">;
99
+ resumeToken: z.ZodString;
100
+ draft: z.ZodObject<{
101
+ id: z.ZodGUID;
102
+ contractVersion: z.ZodLiteral<"commerce.checkout_resume.v1">;
103
+ lastSectionId: Section;
104
+ draftState: z.ZodObject<{
105
+ version: z.ZodLiteral<"commerce.checkout_resume.v1">;
106
+ mode: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
107
+ one_time: "one_time";
108
+ subscription: "subscription";
109
+ }>>>;
110
+ cadenceDays: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
111
+ cart: z.ZodDefault<z.ZodObject<{
112
+ items: z.ZodDefault<z.ZodArray<z.ZodObject<{
113
+ sku: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
114
+ productSlug: z.ZodDefault<z.ZodNullable<z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>>;
115
+ variantId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
116
+ quantity: z.ZodNumber;
117
+ }, z.core.$strict>>>;
118
+ }, z.core.$strict>>;
119
+ completion: Completion;
120
+ redactedFields: z.ZodDefault<z.ZodArray<Redacted>>;
121
+ }, z.core.$strict>;
122
+ expiresAt: z.ZodString;
123
+ createdAt: z.ZodString;
124
+ updatedAt: z.ZodString;
125
+ replayed: z.ZodBoolean;
126
+ }, z.core.$strict>;
127
+ }, z.core.$strict>;
128
+ checkoutResumeReadResponseSchema: z.ZodObject<{
129
+ contractVersion: z.ZodLiteral<"commerce.checkout_resume.v1">;
130
+ draft: z.ZodObject<{
131
+ id: z.ZodGUID;
132
+ contractVersion: z.ZodLiteral<"commerce.checkout_resume.v1">;
133
+ lastSectionId: Section;
134
+ draftState: z.ZodObject<{
135
+ version: z.ZodLiteral<"commerce.checkout_resume.v1">;
136
+ mode: z.ZodDefault<z.ZodNullable<z.ZodEnum<{
137
+ one_time: "one_time";
138
+ subscription: "subscription";
139
+ }>>>;
140
+ cadenceDays: z.ZodDefault<z.ZodNullable<z.ZodNumber>>;
141
+ cart: z.ZodDefault<z.ZodObject<{
142
+ items: z.ZodDefault<z.ZodArray<z.ZodObject<{
143
+ sku: z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>;
144
+ productSlug: z.ZodDefault<z.ZodNullable<z.ZodType<string, string, z.core.$ZodTypeInternals<string, string>>>>;
145
+ variantId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
146
+ quantity: z.ZodNumber;
147
+ }, z.core.$strict>>>;
148
+ }, z.core.$strict>>;
149
+ completion: Completion;
150
+ redactedFields: z.ZodDefault<z.ZodArray<Redacted>>;
151
+ }, z.core.$strict>;
152
+ expiresAt: z.ZodString;
153
+ createdAt: z.ZodString;
154
+ updatedAt: z.ZodString;
155
+ replayed: z.ZodBoolean;
156
+ }, z.core.$strict>;
157
+ }, z.core.$strict>;
158
+ };