@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,113 @@
1
+ import { z } from "zod";
2
+ import type { OmsReplacementChain } from "../contracts/omsTypes.js";
3
+ import {
4
+ datetimeSchema,
5
+ nullableTextSchema,
6
+ omsFulfillmentStatusSchema,
7
+ omsInventoryStatusSchema,
8
+ omsProviderOpsSlaStatusSchema,
9
+ omsSubscriptionCycleStatusSchema,
10
+ uuidSchema,
11
+ } from "./omsContractBase.js";
12
+ import { omsProviderEvidenceSchema } from "./omsProviderEvidenceSchemas.js";
13
+ export type { OmsReplacementChain } from "../contracts/omsTypes.js";
14
+
15
+ export const omsProviderOpsSlaSchema = z.object({
16
+ status: omsProviderOpsSlaStatusSchema,
17
+ dispatchedAt: datetimeSchema.nullable(),
18
+ deadlineAt: datetimeSchema.nullable(),
19
+ remainingOperationalMinutes: z.number().int().min(0).nullable(),
20
+ }).strict();
21
+
22
+ export const omsFulfillmentTrackingReferenceSchema = z.object({
23
+ providerKind: z.string().min(1),
24
+ trackingNumber: z.string().min(1),
25
+ trackingUrl: nullableTextSchema,
26
+ carrierKind: nullableTextSchema,
27
+ service: nullableTextSchema,
28
+ updatedAt: datetimeSchema.nullable(),
29
+ }).strict();
30
+
31
+ export const omsFulfillmentTimelineEventSchema = z.object({
32
+ eventType: z.string().min(1),
33
+ label: z.string().min(1),
34
+ occurredAt: datetimeSchema.nullable(),
35
+ source: z.enum(["webhook", "reconciliation", "manual", "simulator", "fulfillment", "dispatch", "provider"]),
36
+ }).strict();
37
+
38
+ export const omsSubscriptionContextSchema = z.object({
39
+ subscriptionId: uuidSchema.nullable(),
40
+ subscriptionCycleId: uuidSchema.nullable(),
41
+ subscriptionCycleStatus: omsSubscriptionCycleStatusSchema.nullable(),
42
+ // Operator-facing dates. `nextCycleAt` is `subscriptions.next_cycle_at` (the
43
+ // next CHARGE instant, not a delivery date); `cyclePaidAt` is this cycle's
44
+ // `subscription_cycles.paid_at`. Both nullable: `commerce_orders` has no
45
+ // `paid_at`, so one-time orders carry neither.
46
+ nextCycleAt: datetimeSchema.nullable(),
47
+ cyclePaidAt: datetimeSchema.nullable(),
48
+ });
49
+
50
+ export const omsInventorySummarySchema = z.object({
51
+ status: omsInventoryStatusSchema,
52
+ reservationId: uuidSchema.nullable(),
53
+ reservationStatus: z.enum(["reserved", "released", "consumed", "expired"]).nullable(),
54
+ expiresAt: datetimeSchema.nullable(),
55
+ locationId: uuidSchema.nullable(),
56
+ locationCode: z.string().nullable(),
57
+ });
58
+
59
+ export const omsFulfillmentSummarySchema = z.object({
60
+ fulfillmentOrderId: uuidSchema.nullable(),
61
+ status: omsFulfillmentStatusSchema.nullable(),
62
+ providerKind: nullableTextSchema.default(null),
63
+ latestOperationType: z.string().min(1).nullable(),
64
+ latestOperationAt: datetimeSchema.nullable(),
65
+ providerTrackingId: z.string().min(1).nullable(),
66
+ trackingUrl: nullableTextSchema.default(null),
67
+ carrierKind: nullableTextSchema.default(null),
68
+ service: nullableTextSchema.default(null),
69
+ trackingReferences: z.array(omsFulfillmentTrackingReferenceSchema).default([]),
70
+ trackingTimeline: z.array(omsFulfillmentTimelineEventSchema).default([]),
71
+ providerEvidence: z.array(omsProviderEvidenceSchema).optional().default([]),
72
+ });
73
+
74
+ /**
75
+ * The order's replacement chain, detail-only.
76
+ *
77
+ * ⛔ This is NOT a second fulfilment summary. `fulfillment` stays exactly what W3 collapsed it
78
+ * to - one row, the parcel currently representing the order, with every companion narrowed to
79
+ * that parcel's id. Widening those companions was measured and rejected: the dispatch refs,
80
+ * provider attempts and status evidence of a superseded parcel would then be read by the
81
+ * fulfilment health classifier, the fulfilment debug panel and the customer-step derivation,
82
+ * each of which would answer for the wrong parcel - a dispatch status of `created` for a
83
+ * replacement that has never been dispatched, or a customer step of `delivered` for a parcel
84
+ * that is still `created`.
85
+ *
86
+ * So the superseded parcels carry their own, deliberately small payload: what a support agent
87
+ * needs to answer "where did the first one go?" and to file a carrier claim. Tracking number,
88
+ * carrier, service, the two handover instants, and the parcel's own status.
89
+ */
90
+ export const omsSupersededParcelSchema = z.object({
91
+ fulfillmentOrderId: uuidSchema,
92
+ sequenceNo: z.number().int().min(0),
93
+ status: omsFulfillmentStatusSchema.nullable(),
94
+ replacementReason: nullableTextSchema.default(null),
95
+ handedOverAt: datetimeSchema.nullable(),
96
+ deliveredAt: datetimeSchema.nullable(),
97
+ trackingReferences: z.array(omsFulfillmentTrackingReferenceSchema).default([]),
98
+ }).strict();
99
+
100
+ export const omsReplacementChainSchema = z.object({
101
+ // `sequenceNo` 0 is the ordinary order: one parcel, no replacement, nothing to disclose.
102
+ sequenceNo: z.number().int().min(0),
103
+ replacesFulfillmentOrderId: uuidSchema.nullable(),
104
+ replacementReason: nullableTextSchema.default(null),
105
+ supersededParcels: z.array(omsSupersededParcelSchema).default([]),
106
+ }).strict();
107
+
108
+ export const defaultOmsReplacementChain: OmsReplacementChain = {
109
+ sequenceNo: 0,
110
+ replacesFulfillmentOrderId: null,
111
+ replacementReason: null,
112
+ supersededParcels: [],
113
+ };
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ import type { OmsFulfillmentDebug } from "../contracts/omsTypes.js";
3
+ import { datetimeSchema,nullableTextSchema } from "./omsContractBase.js";
4
+ export type { OmsFulfillmentDebug } from "../contracts/omsTypes.js";
5
+
6
+ export const omsFulfillmentDebugStepSchema = z.object({
7
+ key: z.enum(["payment", "stock", "provider_stock", "fulfillment", "dispatch", "provider", "tracking", "communication"]),
8
+ status: z.enum(["ok", "pending", "missing", "warning", "blocked"]),
9
+ label: z.string().min(1),
10
+ value: nullableTextSchema,
11
+ evidenceAt: datetimeSchema.nullable(),
12
+ details: z.array(z.string()).default([]),
13
+ }).strict();
14
+
15
+ export const omsFulfillmentDebugSchema = z.object({
16
+ summary: z.string().min(1),
17
+ severity: z.enum(["ok", "watch", "action_required"]),
18
+ nextAction: z.enum([
19
+ "wait",
20
+ "create_fulfillment",
21
+ "retry_dispatch",
22
+ "reconcile",
23
+ "review_payment",
24
+ "review_stock",
25
+ "review_provider",
26
+ "contact_support",
27
+ ]),
28
+ blockers: z.array(z.string()).default([]),
29
+ steps: z.array(omsFulfillmentDebugStepSchema).default([]),
30
+ }).strict();
31
+
32
+ export const defaultOmsFulfillmentDebug: OmsFulfillmentDebug = {
33
+ summary: "No fulfillment data.",
34
+ severity: "watch",
35
+ nextAction: "wait",
36
+ blockers: [],
37
+ steps: [],
38
+ };
@@ -0,0 +1,46 @@
1
+ import { z } from "zod";
2
+ import { uuidSchema } from "./omsContractBase.js";
3
+
4
+ export const omsFulfillmentHealthSchema = z.object({
5
+ healthStatus: z.enum(["ok", "needs_attention", "blocked_uncertain", "local_ahead", "provider_ahead", "missing_local_commitment"]),
6
+ attentionReasons: z.array(z.enum([
7
+ "paid_order_missing_fulfillment",
8
+ "paid_order_missing_dispatch_ref",
9
+ "dispatch_submission_stale",
10
+ "dispatch_outcome_uncertain",
11
+ "dispatch_failed",
12
+ "dispatch_created_without_provider_order_id",
13
+ "dispatch_terminal_without_progress",
14
+ "dispatch_status_unknown",
15
+ "provider_exception_after_delivery",
16
+ "provider_exception_after_handover",
17
+ "provider_exception_before_handover",
18
+ "local_status_ahead_of_provider",
19
+ "provider_accepted_local_label_ack_missing",
20
+ "order_paid_outbox_discarded",
21
+ "order_paid_outbox_processed_without_fulfillment",
22
+ "order_paid_outbox_missing",
23
+ ])),
24
+ oldestAgeSeconds: z.number().int().nonnegative().nullable(),
25
+ dispatchRefId: uuidSchema.nullable().optional(),
26
+ dispatchStatus: z.string().nullable().optional(),
27
+ opaqueIds: z.object({
28
+ orderId: uuidSchema,
29
+ fulfillmentOrderId: uuidSchema.nullable(),
30
+ outboxEventId: uuidSchema.nullable(),
31
+ dispatchRefFulfillmentOrderId: uuidSchema.nullable(),
32
+ latestEvidenceFulfillmentOrderId: uuidSchema.nullable(),
33
+ }).strict(),
34
+ }).strict();
35
+
36
+ // The list-row projection of the health snapshot above: the two fields an
37
+ // operator can act on, picked from the same schema so the vocabulary cannot
38
+ // fork. The list path builds it from the provider evidence it already fetches
39
+ // per page and never reads `outbox_events`, so a digest can never carry the
40
+ // three `order_paid_outbox_*` reasons - the builder is told the outbox is
41
+ // unread and answers `paid_order_missing_fulfillment` instead of naming an
42
+ // outbox row it did not look at. The enum stays whole rather than being
43
+ // narrowed here: the omission is a property of the input, not of the contract.
44
+ export const omsFulfillmentHealthDigestSchema = omsFulfillmentHealthSchema
45
+ .pick({ healthStatus: true, attentionReasons: true })
46
+ .strict();
@@ -0,0 +1,165 @@
1
+ import type { OmsReplacementRefusal } from "../contracts/omsTypes.js";
2
+ import { neutralOmsCurrencyPolicy,type OmsCurrencyPolicy } from "../model/omsCurrency.js";
3
+ export type { CommerceOmsHoldPort,CommerceOmsReadPort,OmsReplacementRefusal } from "../contracts/omsTypes.js";
4
+
5
+ /**
6
+ * Every refusal `commerce_oms_request_replacement_shipment` can reach an operator with,
7
+ * as one closed vocabulary shared by the adapter that classifies it and the admin surface
8
+ * that renders a sentence for it. Two lists would drift, and the failure mode of drift is
9
+ * the operator reading advice about a hold when the warehouse is simply out of stock.
10
+ *
11
+ * The first group is the command's own `commerce_oms_replacement_*` names. The second is
12
+ * the reservation vocabulary raised THROUGH it: the command mints a fresh generation via
13
+ * `inventory_reserve_order`, and on a stock authority outside this system that call is the
14
+ * most likely legitimate refusal there is. Those errors never carried the command's prefix,
15
+ * so before this list they matched nothing, degraded to an upstream failure, and the
16
+ * operator was told to check holds that were not there.
17
+ *
18
+ * It stays an allowlist, not a translation table: a reason absent from it degrades to
19
+ * `unspecified_refusal`, so no database text can travel to a response, a log or a screen.
20
+ *
21
+ * ⛔ The exported names deliberately omit the `CommerceOms` prefix every other symbol in
22
+ * this file carries. `src/lib/commerceOmsBoundary.test.ts` forbids that token in production
23
+ * UI files outside a small allowlist, and the admin surface imports these three symbols.
24
+ * Renaming them is the honest way to keep that boundary guard intact; widening its allowlist
25
+ * to admit one more file would weaken the control instead of respecting it.
26
+ */
27
+ export const OMS_REPLACEMENT_COMMAND_REFUSALS = [
28
+ "invalid_input",
29
+ "idempotency_conflict",
30
+ "order_not_found",
31
+ "order_not_replaceable",
32
+ "missing_client",
33
+ "missing_shipping_address",
34
+ "shipping_address_not_found",
35
+ "payment_not_succeeded",
36
+ "subscription_cycle_not_paid",
37
+ "no_parcel_to_replace",
38
+ "undispatched_replacement_exists",
39
+ "missing_order_items",
40
+ "missing_catalog_sku",
41
+ "missing_inventory_reservation",
42
+ "blocked_by_payment_not_succeeded_hold",
43
+ "blocked_by_inventory_review_hold",
44
+ "blocked_by_risk_review_hold",
45
+ "blocked_by_address_review_hold",
46
+ "blocked_by_manual_support_hold",
47
+ ] as const;
48
+
49
+ export const OMS_REPLACEMENT_RESERVATION_REFUSALS = [
50
+ "inventory_external_provider_insufficient_available_stock",
51
+ "inventory_external_provider_stock_stale",
52
+ "inventory_external_provider_stock_missing",
53
+ "inventory_external_provider_sku_not_found",
54
+ "inventory_external_provider_location_missing",
55
+ "inventory_reservation_insufficient_available_stock",
56
+ "inventory_reservation_allocation_incomplete",
57
+ "inventory_reservation_payment_status_not_reservable",
58
+ "inventory_reservation_invalid_quantity",
59
+ ] as const;
60
+
61
+ export const UNSPECIFIED_REPLACEMENT_REFUSAL = "unspecified_refusal";
62
+
63
+ export const OMS_REPLACEMENT_REFUSALS = [
64
+ ...OMS_REPLACEMENT_COMMAND_REFUSALS,
65
+ ...OMS_REPLACEMENT_RESERVATION_REFUSALS,
66
+ UNSPECIFIED_REPLACEMENT_REFUSAL,
67
+ ] as const;
68
+
69
+ /**
70
+ * Reads the refusal a replacement error carries, from any of the shapes a BFF error can
71
+ * legitimately arrive in. Returns null when the text names no refusal this vocabulary
72
+ * knows, which is the honest answer: the operator gets the generic sentence plus the raw
73
+ * detail to hand to the team, never a guess dressed as advice.
74
+ */
75
+ export function readOmsReplacementRefusal(text: string): OmsReplacementRefusal | null {
76
+ const named = /commerce_oms_replacement_([a-z0-9_]+)/.exec(text)?.[1];
77
+ if (named) {
78
+ return (OMS_REPLACEMENT_COMMAND_REFUSALS as readonly string[]).includes(named)
79
+ ? named as OmsReplacementRefusal
80
+ : UNSPECIFIED_REPLACEMENT_REFUSAL;
81
+ }
82
+ // Exact membership only. A transport or permission failure that merely quotes a table
83
+ // name such as `inventory_reservations` must stay an upstream failure, not become a
84
+ // refusal the operator is asked to act on.
85
+ return OMS_REPLACEMENT_RESERVATION_REFUSALS.find((reason) => text.includes(reason)) ?? null;
86
+ }
87
+
88
+ export class CommerceOmsInvalidResponseError extends Error {
89
+ constructor() {
90
+ super("Commerce OMS returned invalid response");
91
+ this.name = "CommerceOmsInvalidResponseError";
92
+ }
93
+ }
94
+
95
+ export class CommerceOmsPersistenceError extends Error {
96
+ readonly details: Record<string, unknown>;
97
+
98
+ constructor(message = "Commerce OMS persistence failed", details: Record<string, unknown> = {}) {
99
+ super(message);
100
+ this.name = "CommerceOmsPersistenceError";
101
+ this.details = details;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * An order row came back from the database in a currency this deployment does
107
+ * not accept. The channel ingest rail is deliberately multi-currency, so such a
108
+ * row can genuinely exist; what it cannot do is reach the read model, whose
109
+ * money nodes are pinned to the platform's accepted set.
110
+ *
111
+ * A subclass rather than a new error family, so it inherits the persistence
112
+ * error's HTTP mapping untouched: this is still an upstream read that could not
113
+ * be served, and the operator-facing status must not move. The gain is entirely
114
+ * diagnostic - the failure now names the orders and the codes instead of
115
+ * surfacing as an anonymous validation error fifteen frames later.
116
+ */
117
+ export class CommerceOmsUnsupportedCurrencyError extends CommerceOmsPersistenceError {
118
+ readonly orderIds: readonly string[];
119
+ readonly currencies: readonly string[];
120
+
121
+ constructor(offenders: ReadonlyArray<{ orderId: string; currency: string }>) {
122
+ const orderIds = offenders.map((offender) => offender.orderId);
123
+ const currencies = [...new Set(offenders.map((offender) => offender.currency))];
124
+ const described = offenders
125
+ .map((offender) => `order ${offender.orderId} has currency ${offender.currency}`)
126
+ .join(", ");
127
+ super(`${described}, not accepted by this deployment`, { orderIds, currencies });
128
+ this.name = "CommerceOmsUnsupportedCurrencyError";
129
+ this.orderIds = orderIds;
130
+ this.currencies = currencies;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Guards the one field of an order row that can break the OMS read.
136
+ *
137
+ * This is deliberately not a schema for the whole row. Of that row's ~22
138
+ * columns exactly one - `currency` - is both able to fail the read model and
139
+ * something the platform holds an opinion about; the rest would cost a new
140
+ * contract surface parsed once per row per page, and would only be coherent if
141
+ * the other cast row kinds on this path were validated too.
142
+ *
143
+ * It also deliberately refuses rather than filtering. Dropping the offending
144
+ * row would keep the page rendering while hiding a real customer order from the
145
+ * operator handling it - a worse failure than a named refusal.
146
+ */
147
+ export function assertOmsOrderRowCurrency(
148
+ rows: ReadonlyArray<{ id: string; currency: string }>,
149
+ currency: OmsCurrencyPolicy = neutralOmsCurrencyPolicy,
150
+ ): void {
151
+ const offenders = rows
152
+ .filter((row) => !currency.accepts(row.currency))
153
+ .map((row) => ({ orderId: row.id, currency: row.currency }));
154
+ if (offenders.length) throw new CommerceOmsUnsupportedCurrencyError(offenders);
155
+ }
156
+
157
+ export class CommerceOmsConflictError extends Error {
158
+ readonly details: Record<string, unknown>;
159
+
160
+ constructor(message = "Commerce OMS conflict", details: Record<string, unknown> = {}) {
161
+ super(message);
162
+ this.name = "CommerceOmsConflictError";
163
+ this.details = details;
164
+ }
165
+ }
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ // OMS read money permits signed adjustments and rejects unknown fields.
3
+ export const commerceMoneySchema = z.object({ amountMinor: z.number().int(), currency: z.string().regex(/^[A-Z]{3}$/) }).strict();
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ import { datetimeSchema,nullableTextSchema } from "./omsContractBase.js";
3
+
4
+ export const omsProviderEvidenceSchema = z.object({
5
+ evidenceType: z.enum(["dispatch_ref", "provider_attempt", "status_evidence"]),
6
+ status: nullableTextSchema,
7
+ providerStatus: nullableTextSchema,
8
+ providerOrderId: nullableTextSchema,
9
+ evidenceKind: nullableTextSchema,
10
+ occurredAt: datetimeSchema.nullable(),
11
+ updatedAt: datetimeSchema.nullable(),
12
+ summary: nullableTextSchema,
13
+ }).strict();
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The quote was valid when read, but the atomic order write could no longer
3
+ * claim its promotion. Callers must re-quote and surface `price_changed`.
4
+ */
5
+ export class CommerceOrderDraftPriceChangedError extends Error {
6
+ readonly details: Record<string, unknown>;
7
+
8
+ constructor(
9
+ message = "Commerce order draft promotion changed",
10
+ details: Record<string, unknown> = {},
11
+ ) {
12
+ super(message);
13
+ this.name = "CommerceOrderDraftPriceChangedError";
14
+ this.details = details;
15
+ }
16
+ }
17
+
18
+ export type CommerceOrderDraftUnsupportedMoneyReason =
19
+ | "line_promotion_unsupported"
20
+ | "net_shipping_unsupported"
21
+ | "zero_payable_unsupported";
22
+
23
+ export class CommerceOrderDraftUnsupportedMoneyError extends Error {
24
+ constructor(readonly reason: CommerceOrderDraftUnsupportedMoneyReason) {
25
+ super(`Commerce order draft money shape is unsupported: ${reason}`);
26
+ this.name = "CommerceOrderDraftUnsupportedMoneyError";
27
+ }
28
+ }
@@ -0,0 +1,131 @@
1
+ import type { OrderPaymentLifecycleState } from "./outboxOrderDraftEmailPorts.js";
2
+
3
+ /**
4
+ * Skip reason meaning "the payer is inside a live payment session right now".
5
+ * Exported because it is the one skip reason a caller must treat as TRANSIENT;
6
+ * every other reason in this module is a settled fact about the order.
7
+ */
8
+ export const PAYMENT_SESSION_ACTIVE = "payment_session_active";
9
+
10
+ const SUCCESSFUL_PAYMENT_STATUSES = new Set(["succeeded", "paid", "captured"]);
11
+ const ACTIVE_PAYMENT_STATUSES = new Set(["pending", "requires_action", "created", "processing"]);
12
+ const FRESH_PAYMENT_ACTIVITY_MS = 15 * 60 * 1000;
13
+
14
+ export function shouldSkipOrderDraftConfirmation(
15
+ state: OrderPaymentLifecycleState | null,
16
+ ): string | null {
17
+ if (state === null) return "order_unavailable";
18
+ if (state.orderStatus !== "draft") return "order_no_longer_draft";
19
+ if (state.hasPayment) return "order_no_longer_draft";
20
+ if (state.paymentStatus && state.paymentStatus !== "not_started") return "order_no_longer_draft";
21
+ return null;
22
+ }
23
+
24
+ /**
25
+ * Eligibility for the checkout-recovery NUDGE only.
26
+ *
27
+ * `payment_session_active` below is a politeness rule: do not remind someone to
28
+ * pay while they are paying. It is correct here and wrong for a decline notice
29
+ * — see {@link shouldSkipPaymentFailedNotice}. A caller acting on this reason
30
+ * must defer rather than drop, because the nudge's emit key is once-per-order.
31
+ */
32
+ export function shouldSkipCheckoutRecovery(
33
+ state: OrderPaymentLifecycleState | null,
34
+ ): string | null {
35
+ if (state === null) return "order_unavailable";
36
+ if (state.orderStatus !== "pending_payment") return "order_not_pending_payment";
37
+ if (state.paymentStatus && SUCCESSFUL_PAYMENT_STATUSES.has(state.paymentStatus)) {
38
+ return "order_already_paid";
39
+ }
40
+ if (
41
+ state.paymentStatus &&
42
+ ACTIVE_PAYMENT_STATUSES.has(state.paymentStatus) &&
43
+ isFreshPaymentActivity(state.paymentUpdatedAt)
44
+ ) {
45
+ return PAYMENT_SESSION_ACTIVE;
46
+ }
47
+ return null;
48
+ }
49
+
50
+ /**
51
+ * Eligibility for an OPERATOR-ISSUED recovery link.
52
+ *
53
+ * Deliberately not {@link shouldSkipCheckoutRecovery}. That gate is written for
54
+ * the cron nudge, and its first rule — leave `pending_payment` and we go quiet —
55
+ * is exactly wrong here. A human looked at the order and decided to send this
56
+ * link, and the orders they send it for are largely the ones that have ALREADY
57
+ * left `pending_payment`: `expired` is the ordinary case, and the redeem rail
58
+ * recreates such an order from its frozen quote when the customer opens the link.
59
+ * Reusing the cron gate would skip those as `order_not_pending_payment`, the
60
+ * operator would have promised an email that never arrives, and nothing anywhere
61
+ * would report a failure. The mint side has already run the full recovery
62
+ * eligibility for this order, so what is left here is only what can have changed
63
+ * between the mint and the send.
64
+ *
65
+ * What still suppresses: the order is gone, or the money is in. Both make the
66
+ * email actively wrong rather than merely late.
67
+ *
68
+ * `payment_session_active` behaves exactly as it does for the nudge, and for the
69
+ * same reason: do not tell someone to finish paying while they are paying. The
70
+ * caller must DEFER on it rather than drop, because a dropped operator link is
71
+ * the silent no-send this whole path is written to prevent.
72
+ */
73
+ export function shouldSkipOperatorCheckoutRecovery(
74
+ state: OrderPaymentLifecycleState | null,
75
+ ): string | null {
76
+ if (state === null) return "order_unavailable";
77
+ if (state.orderStatus === "paid") return "order_already_paid";
78
+ if (state.paymentStatus && SUCCESSFUL_PAYMENT_STATUSES.has(state.paymentStatus)) {
79
+ return "order_already_paid";
80
+ }
81
+ if (
82
+ state.paymentStatus &&
83
+ ACTIVE_PAYMENT_STATUSES.has(state.paymentStatus) &&
84
+ isFreshPaymentActivity(state.paymentUpdatedAt)
85
+ ) {
86
+ return PAYMENT_SESSION_ACTIVE;
87
+ }
88
+ return null;
89
+ }
90
+
91
+ /**
92
+ * Eligibility for a recoverable payment-decline notice.
93
+ *
94
+ * Unlike a checkout reminder, a decline notice must not be suppressed by a live
95
+ * retry. Its producer key is once per order, so a later failed attempt cannot
96
+ * replace a notice that was consumed without sending.
97
+ *
98
+ * Suppress only when the order is unavailable, already paid, or no longer
99
+ * pending payment. The producer's claim delay lets successful retries settle
100
+ * before this lifecycle read; scheduling remains the producer/runtime's duty.
101
+ */
102
+ export function shouldSkipPaymentFailedNotice(
103
+ state: OrderPaymentLifecycleState | null,
104
+ ): string | null {
105
+ if (state === null) return "order_unavailable";
106
+ if (state.orderStatus !== "pending_payment") return "order_not_pending_payment";
107
+ if (state.paymentStatus && SUCCESSFUL_PAYMENT_STATUSES.has(state.paymentStatus)) {
108
+ return "order_already_paid";
109
+ }
110
+ return null;
111
+ }
112
+
113
+ export function shouldSkipCheckoutExpired(
114
+ state: OrderPaymentLifecycleState | null,
115
+ ): string | null {
116
+ if (state === null) return "order_unavailable";
117
+ if (state.orderStatus === "expired") return null;
118
+ // ⛔ The activation sweep writes `cancelled`, never `expired`, so a first
119
+ // subscription abandoned at the 24h window would fail an `expired`-only gate
120
+ // and the buyer would hear nothing at all. Accepted ONLY with the sweep's own
121
+ // marker, so an ordinary cancellation still cannot reach this template.
122
+ if (state.orderStatus === "cancelled" && state.subscriptionActivationAbandoned === true) return null;
123
+ return "order_not_expired";
124
+ }
125
+
126
+ function isFreshPaymentActivity(value: string | null | undefined): boolean {
127
+ if (!value) return false;
128
+ const timestamp = Date.parse(value);
129
+ if (!Number.isFinite(timestamp)) return false;
130
+ return Date.now() - timestamp < FRESH_PAYMENT_ACTIVITY_MS;
131
+ }
@@ -0,0 +1,22 @@
1
+ import type { OrderEmailLineItem } from "./outboxOrderDraftEmailPorts.js";
2
+
3
+ export interface RawLine {
4
+ label: string | null;
5
+ quantity: number;
6
+ lineSubtotalMinor: number | null;
7
+ currency: string | null;
8
+ }
9
+
10
+ export interface OrderEmailLinePresentation<Locale extends string = string> {
11
+ formatMoney(amountMinor: number, currency: string): string;
12
+ genericItemLabel(locale: Locale): string;
13
+ }
14
+
15
+ export function buildItems<Locale extends string>(lines: RawLine[], locale: Locale, presentation: OrderEmailLinePresentation<Locale>): OrderEmailLineItem[] {
16
+ return lines.map((line) => {
17
+ const name = line.label ?? presentation.genericItemLabel(locale);
18
+ const lineTotalLabel = line.lineSubtotalMinor !== null && line.currency !== null
19
+ ? presentation.formatMoney(line.lineSubtotalMinor, line.currency) : "";
20
+ return { name, quantity: line.quantity, lineTotalLabel };
21
+ });
22
+ }
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+
3
+ // Contract for the public order-feedback (post-delivery review) submit BFF.
4
+ // No login: the opaque token from the review-email link is the only credential.
5
+ export const ORDER_FEEDBACK_SUBMIT_RPC_NAME = "submit_order_feedback";
6
+ export const ORDER_FEEDBACK_CHECK_RPC_NAME = "check_order_feedback_token";
7
+
8
+ export const orderFeedbackTokenCheckRequestSchema = z
9
+ .object({ token: z.string().min(1).max(128) })
10
+ .strict();
11
+ export type OrderFeedbackTokenCheckRequest = z.infer<typeof orderFeedbackTokenCheckRequestSchema>;
12
+
13
+ export const orderFeedbackTokenCheckStatusSchema = z.enum([
14
+ "ready",
15
+ "already_submitted",
16
+ "not_found",
17
+ ]);
18
+ export type OrderFeedbackTokenCheckStatus = z.infer<typeof orderFeedbackTokenCheckStatusSchema>;
19
+
20
+ export const orderFeedbackTokenCheckResponseSchema = z
21
+ .object({ status: orderFeedbackTokenCheckStatusSchema })
22
+ .strict();
23
+ export type OrderFeedbackTokenCheckResponse = z.infer<typeof orderFeedbackTokenCheckResponseSchema>;
24
+
25
+ export const orderFeedbackSubmitRequestSchema = z
26
+ .object({
27
+ token: z.string().min(1).max(128),
28
+ rating: z.number().int().min(1).max(5),
29
+ comment: z.string().max(2000).optional(),
30
+ })
31
+ .strict();
32
+
33
+ export type OrderFeedbackSubmitRequest = z.infer<typeof orderFeedbackSubmitRequestSchema>;
34
+
35
+ // The RPC reports outcome without ever exposing the row, so the form can show
36
+ // the right state (submitted / already submitted / unknown token).
37
+ export const orderFeedbackSubmitStatusSchema = z.enum([
38
+ "submitted",
39
+ "already_submitted",
40
+ "not_found",
41
+ ]);
42
+ export type OrderFeedbackSubmitStatus = z.infer<typeof orderFeedbackSubmitStatusSchema>;
43
+
44
+ export const orderFeedbackSubmitResponseSchema = z
45
+ .object({ status: orderFeedbackSubmitStatusSchema })
46
+ .strict();
47
+ export type OrderFeedbackSubmitResponse = z.infer<typeof orderFeedbackSubmitResponseSchema>;