@openlup/platform 0.26.0 → 0.27.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.
- package/CHANGELOG.md +138 -218
- package/README.md +229 -16
- package/dist/commerce/adapters/managed/commerceOmsControlPlane.d.ts +3 -0
- package/dist/commerce/adapters/managed/commerceOmsControlPlane.js +71 -0
- package/dist/commerce/adapters/managed/commerceOmsMutations.d.ts +10 -0
- package/dist/commerce/adapters/managed/commerceOmsMutations.js +119 -0
- package/dist/commerce/adapters/managed/commerceOmsPort.d.ts +28 -0
- package/dist/commerce/adapters/managed/commerceOmsPort.js +101 -0
- package/dist/commerce/adapters/managed/oms/accounting.d.ts +3 -0
- package/dist/commerce/adapters/managed/oms/accounting.js +13 -0
- package/dist/commerce/adapters/managed/oms/fulfillmentReads.d.ts +17 -0
- package/dist/commerce/adapters/managed/oms/fulfillmentReads.js +81 -0
- package/dist/commerce/adapters/managed/oms/inboundEvents.d.ts +9 -0
- package/dist/commerce/adapters/managed/oms/inboundEvents.js +40 -0
- package/dist/commerce/adapters/managed/oms/outboxEvents.d.ts +2 -0
- package/dist/commerce/adapters/managed/oms/outboxEvents.js +23 -0
- package/dist/commerce/adapters/managed/oms/paymentAttempts.d.ts +3 -0
- package/dist/commerce/adapters/managed/oms/paymentAttempts.js +15 -0
- package/dist/commerce/adapters/managed/oms/queueSelection.d.ts +12 -0
- package/dist/commerce/adapters/managed/oms/queueSelection.js +109 -0
- package/dist/commerce/adapters/managed/oms/readProjections.d.ts +18 -0
- package/dist/commerce/adapters/managed/oms/readProjections.js +13 -0
- package/dist/commerce/adapters/managed/oms/readQueries.d.ts +16 -0
- package/dist/commerce/adapters/managed/oms/readQueries.js +276 -0
- package/dist/commerce/adapters/managed/oms/types.d.ts +2 -0
- package/dist/commerce/adapters/managed/oms/types.js +7 -0
- package/dist/commerce/checkoutCommandSchemas.d.ts +89 -0
- package/dist/commerce/checkoutCommandSchemas.js +70 -0
- package/dist/commerce/checkoutHelpers.d.ts +21 -0
- package/dist/commerce/checkoutHelpers.js +29 -0
- package/dist/commerce/checkoutResumeSchemas.d.ts +158 -0
- package/dist/commerce/checkoutResumeSchemas.js +145 -0
- package/dist/commerce/checkoutSchemas.d.ts +158 -0
- package/dist/commerce/checkoutSchemas.js +161 -0
- package/dist/commerce/commerceReturnsPort.d.ts +97 -0
- package/dist/commerce/commerceReturnsPort.js +39 -0
- package/dist/commerce/configuratorIntentPersistenceSchemas.d.ts +20 -0
- package/dist/commerce/configuratorIntentPersistenceSchemas.js +21 -0
- package/dist/commerce/configuratorIntentSchemas.d.ts +63 -0
- package/dist/commerce/configuratorIntentSchemas.js +43 -0
- package/dist/commerce/contractPrimitives.d.ts +50 -0
- package/dist/commerce/contractPrimitives.js +25 -0
- package/dist/commerce/contracts/availability.d.ts +23 -0
- package/dist/commerce/contracts/availability.js +1 -0
- package/dist/commerce/contracts/fulfillmentRecovery.d.ts +25 -0
- package/dist/commerce/contracts/fulfillmentRecovery.js +1 -0
- package/dist/commerce/contracts/index.d.ts +13 -0
- package/dist/commerce/contracts/index.js +1 -0
- package/dist/commerce/contracts/intent.d.ts +86 -0
- package/dist/commerce/contracts/intent.js +1 -0
- package/dist/commerce/contracts/omsTypes.d.ts +1216 -0
- package/dist/commerce/contracts/omsTypes.js +1 -0
- package/dist/commerce/contracts/order.d.ts +39 -0
- package/dist/commerce/contracts/order.js +1 -0
- package/dist/commerce/contracts/orderMoney.d.ts +52 -0
- package/dist/commerce/contracts/orderMoney.js +1 -0
- package/dist/commerce/contracts/ports.d.ts +113 -0
- package/dist/commerce/contracts/ports.js +1 -0
- package/dist/commerce/contracts/recovery.d.ts +11 -0
- package/dist/commerce/contracts/recovery.js +1 -0
- package/dist/commerce/contracts/runtimePorts.d.ts +196 -0
- package/dist/commerce/contracts/runtimePorts.js +1 -0
- package/dist/commerce/contracts/state.d.ts +26 -0
- package/dist/commerce/contracts/state.js +43 -0
- package/dist/commerce/customerDefaultsSnapshotSchemas.d.ts +51 -0
- package/dist/commerce/customerDefaultsSnapshotSchemas.js +106 -0
- package/dist/commerce/errors.d.ts +18 -0
- package/dist/commerce/errors.js +36 -0
- package/dist/commerce/fulfillmentEligibility.d.ts +6 -0
- package/dist/commerce/fulfillmentEligibility.js +31 -0
- package/dist/commerce/index.d.ts +72 -0
- package/dist/commerce/index.js +67 -0
- package/dist/commerce/model/customerFulfillmentRecovery.d.ts +40 -0
- package/dist/commerce/model/customerFulfillmentRecovery.js +144 -0
- package/dist/commerce/model/fulfillmentCancellationEligibility.d.ts +7 -0
- package/dist/commerce/model/fulfillmentCancellationEligibility.js +9 -0
- package/dist/commerce/model/omsAccountingVisibility.d.ts +12 -0
- package/dist/commerce/model/omsAccountingVisibility.js +118 -0
- package/dist/commerce/model/omsBillingInvoiceBuyer.d.ts +2 -0
- package/dist/commerce/model/omsBillingInvoiceBuyer.js +15 -0
- package/dist/commerce/model/omsCurrency.d.ts +4 -0
- package/dist/commerce/model/omsCurrency.js +5 -0
- package/dist/commerce/model/omsFulfillmentDebug.d.ts +20 -0
- package/dist/commerce/model/omsFulfillmentDebug.js +122 -0
- package/dist/commerce/model/omsFulfillmentSummary.d.ts +16 -0
- package/dist/commerce/model/omsFulfillmentSummary.js +189 -0
- package/dist/commerce/model/omsListTotals.d.ts +13 -0
- package/dist/commerce/model/omsListTotals.js +32 -0
- package/dist/commerce/model/omsOperationalLadder.d.ts +51 -0
- package/dist/commerce/model/omsOperationalLadder.js +158 -0
- package/dist/commerce/model/omsOrderLineMoney.d.ts +4 -0
- package/dist/commerce/model/omsOrderLineMoney.js +25 -0
- package/dist/commerce/model/omsPaymentMethodSummary.d.ts +5 -0
- package/dist/commerce/model/omsPaymentMethodSummary.js +11 -0
- package/dist/commerce/model/omsReadModel.d.ts +43 -0
- package/dist/commerce/model/omsReadModel.js +211 -0
- package/dist/commerce/model/omsReadModelCommunication.d.ts +3 -0
- package/dist/commerce/model/omsReadModelCommunication.js +29 -0
- package/dist/commerce/model/omsReadModelHelpers.d.ts +125 -0
- package/dist/commerce/model/omsReadModelHelpers.js +212 -0
- package/dist/commerce/model/omsReadModelList.d.ts +33 -0
- package/dist/commerce/model/omsReadModelList.js +50 -0
- package/dist/commerce/model/omsReadModelListSummary.d.ts +3 -0
- package/dist/commerce/model/omsReadModelListSummary.js +13 -0
- package/dist/commerce/model/omsReadModelPricing.d.ts +5 -0
- package/dist/commerce/model/omsReadModelPricing.js +36 -0
- package/dist/commerce/model/omsReadModelProjections.d.ts +1 -0
- package/dist/commerce/model/omsReadModelProjections.js +1 -0
- package/dist/commerce/model/omsReadModelRowCore.d.ts +79 -0
- package/dist/commerce/model/omsReadModelRowCore.js +149 -0
- package/dist/commerce/model/omsReadModelRows.d.ts +1 -0
- package/dist/commerce/model/omsReadModelRows.js +6 -0
- package/dist/commerce/offerAvailability.d.ts +18 -0
- package/dist/commerce/offerAvailability.js +53 -0
- package/dist/commerce/offerAvailabilitySchemas.d.ts +43 -0
- package/dist/commerce/offerAvailabilitySchemas.js +42 -0
- package/dist/commerce/offerEvidenceSchemas.d.ts +7 -0
- package/dist/commerce/offerEvidenceSchemas.js +13 -0
- package/dist/commerce/oms/omsContractBase.d.ts +130 -0
- package/dist/commerce/oms/omsContractBase.js +86 -0
- package/dist/commerce/oms/omsContractReadAuxSchemas.d.ts +222 -0
- package/dist/commerce/oms/omsContractReadAuxSchemas.js +123 -0
- package/dist/commerce/oms/omsContractReadSchemas.d.ts +2266 -0
- package/dist/commerce/oms/omsContractReadSchemas.js +277 -0
- package/dist/commerce/oms/omsContractRequests.d.ts +196 -0
- package/dist/commerce/oms/omsContractRequests.js +118 -0
- package/dist/commerce/oms/omsContracts.d.ts +5 -0
- package/dist/commerce/oms/omsContracts.js +4 -0
- package/dist/commerce/oms/omsControlPlane.d.ts +275 -0
- package/dist/commerce/oms/omsControlPlane.js +72 -0
- package/dist/commerce/oms/omsFulfillmentContractSchemas.d.ts +203 -0
- package/dist/commerce/oms/omsFulfillmentContractSchemas.js +94 -0
- package/dist/commerce/oms/omsFulfillmentDebugSchemas.d.ts +69 -0
- package/dist/commerce/oms/omsFulfillmentDebugSchemas.js +33 -0
- package/dist/commerce/oms/omsFulfillmentHealthSchemas.d.ts +67 -0
- package/dist/commerce/oms/omsFulfillmentHealthSchemas.js +44 -0
- package/dist/commerce/oms/omsPorts.d.ts +84 -0
- package/dist/commerce/oms/omsPorts.js +148 -0
- package/dist/commerce/oms/omsPrimitives.d.ts +5 -0
- package/dist/commerce/oms/omsPrimitives.js +3 -0
- package/dist/commerce/oms/omsProviderEvidenceSchemas.d.ts +15 -0
- package/dist/commerce/oms/omsProviderEvidenceSchemas.js +12 -0
- package/dist/commerce/orderDraftErrors.d.ts +13 -0
- package/dist/commerce/orderDraftErrors.js +20 -0
- package/dist/commerce/orderEmailEligibility.d.ts +54 -0
- package/dist/commerce/orderEmailEligibility.js +123 -0
- package/dist/commerce/orderEmailLines.d.ts +12 -0
- package/dist/commerce/orderEmailLines.js +8 -0
- package/dist/commerce/orderFeedbackContracts.d.ts +41 -0
- package/dist/commerce/orderFeedbackContracts.js +33 -0
- package/dist/commerce/orderMoney.d.ts +6 -0
- package/dist/commerce/orderMoney.js +168 -0
- package/dist/commerce/orderReviewContracts.d.ts +475 -0
- package/dist/commerce/orderReviewContracts.js +94 -0
- package/dist/commerce/orderReviewPorts.d.ts +140 -0
- package/dist/commerce/orderReviewPorts.js +1 -0
- package/dist/commerce/outboxDispatchContracts.d.ts +30 -0
- package/dist/commerce/outboxDispatchContracts.js +1 -0
- package/dist/commerce/outboxEventSchemas.d.ts +162 -0
- package/dist/commerce/outboxEventSchemas.js +164 -0
- package/dist/commerce/outboxOrderDraftEmailPorts.d.ts +207 -0
- package/dist/commerce/outboxOrderDraftEmailPorts.js +12 -0
- package/dist/commerce/paymentContinuation.d.ts +4 -0
- package/dist/commerce/paymentContinuation.js +4 -0
- package/dist/commerce/ports.d.ts +8 -0
- package/dist/commerce/ports.js +1 -0
- package/dist/commerce/recoveryDestination.d.ts +3 -0
- package/dist/commerce/recoveryDestination.js +17 -0
- package/dist/commerce/runtimeErrors.d.ts +8 -0
- package/dist/commerce/runtimeErrors.js +16 -0
- package/dist/commerce/salesChannelEnvelope.d.ts +20 -0
- package/dist/commerce/salesChannelEnvelope.js +7 -0
- package/dist/commerce/schemas.d.ts +174 -0
- package/dist/commerce/schemas.js +84 -0
- package/dist/commerce/server/checkoutCompensation.d.ts +21 -0
- package/dist/commerce/server/checkoutCompensation.js +32 -0
- package/dist/commerce/server/checkoutConflictClassifiers.d.ts +17 -0
- package/dist/commerce/server/checkoutConflictClassifiers.js +38 -0
- package/dist/commerce/server/checkoutExpiredRecoveryPolicy.d.ts +38 -0
- package/dist/commerce/server/checkoutExpiredRecoveryPolicy.js +85 -0
- package/dist/commerce/server/checkoutInvoiceBuyerSnapshot.d.ts +22 -0
- package/dist/commerce/server/checkoutInvoiceBuyerSnapshot.js +30 -0
- package/dist/commerce/server/checkoutOfferPolicyPort.d.ts +33 -0
- package/dist/commerce/server/checkoutOfferPolicyPort.js +49 -0
- package/dist/commerce/server/checkoutPaymentContinuationCredential.d.ts +58 -0
- package/dist/commerce/server/checkoutPaymentContinuationCredential.js +154 -0
- package/dist/commerce/server/checkoutQuoteTypes.d.ts +19 -0
- package/dist/commerce/server/checkoutQuoteTypes.js +1 -0
- package/dist/commerce/server/checkoutRecoveryOrderPort.d.ts +42 -0
- package/dist/commerce/server/checkoutRecoveryOrderPort.js +1 -0
- package/dist/commerce/server/checkoutRecoveryToken.d.ts +40 -0
- package/dist/commerce/server/checkoutRecoveryToken.js +26 -0
- package/dist/commerce/server/checkoutRefusalContinuation.d.ts +24 -0
- package/dist/commerce/server/checkoutRefusalContinuation.js +18 -0
- package/dist/commerce/server/checkoutRuntimeTypes.d.ts +81 -0
- package/dist/commerce/server/checkoutRuntimeTypes.js +1 -0
- package/dist/commerce/server/commerceCheckoutCommandExecution.d.ts +60 -0
- package/dist/commerce/server/commerceCheckoutCommandExecution.js +136 -0
- package/dist/commerce/server/commerceCheckoutCompensation.d.ts +26 -0
- package/dist/commerce/server/commerceCheckoutCompensation.js +46 -0
- package/dist/commerce/server/commerceCheckoutContinuationTerms.d.ts +50 -0
- package/dist/commerce/server/commerceCheckoutContinuationTerms.js +66 -0
- package/dist/commerce/server/commerceCheckoutCustomerDefaults.d.ts +18 -0
- package/dist/commerce/server/commerceCheckoutCustomerDefaults.js +17 -0
- package/dist/commerce/server/commerceCheckoutFailureHandler.d.ts +51 -0
- package/dist/commerce/server/commerceCheckoutFailureHandler.js +90 -0
- package/dist/commerce/server/commerceCheckoutHandler.d.ts +213 -0
- package/dist/commerce/server/commerceCheckoutHandler.js +196 -0
- package/dist/commerce/server/commerceCheckoutHandlerAdmission.d.ts +58 -0
- package/dist/commerce/server/commerceCheckoutHandlerAdmission.js +94 -0
- package/dist/commerce/server/commerceCheckoutHandlerHelpers.d.ts +67 -0
- package/dist/commerce/server/commerceCheckoutHandlerHelpers.js +155 -0
- package/dist/commerce/server/commerceCheckoutOrchestrationError.d.ts +9 -0
- package/dist/commerce/server/commerceCheckoutOrchestrationError.js +14 -0
- package/dist/commerce/server/commerceCheckoutPromotionPriceChange.d.ts +47 -0
- package/dist/commerce/server/commerceCheckoutPromotionPriceChange.js +43 -0
- package/dist/commerce/server/commerceCheckoutProviderPayment.d.ts +34 -0
- package/dist/commerce/server/commerceCheckoutProviderPayment.js +37 -0
- package/dist/commerce/server/commerceCheckoutQuoteGuard.d.ts +62 -0
- package/dist/commerce/server/commerceCheckoutQuoteGuard.js +106 -0
- package/dist/commerce/server/commerceCheckoutResume.d.ts +29 -0
- package/dist/commerce/server/commerceCheckoutResume.js +81 -0
- package/dist/commerce/server/commerceCheckoutResumeGuard.d.ts +54 -0
- package/dist/commerce/server/commerceCheckoutResumeGuard.js +138 -0
- package/dist/commerce/server/commerceCheckoutSavedPaymentMethod.d.ts +39 -0
- package/dist/commerce/server/commerceCheckoutSavedPaymentMethod.js +44 -0
- package/dist/commerce/server/commerceCheckoutStartRuntimeFailure.d.ts +7 -0
- package/dist/commerce/server/commerceCheckoutStartRuntimeFailure.js +39 -0
- package/dist/commerce/server/commerceCheckoutTiming.d.ts +8 -0
- package/dist/commerce/server/commerceCheckoutTiming.js +31 -0
- package/dist/commerce/server/commerceDiagnostics.d.ts +6 -0
- package/dist/commerce/server/commerceDiagnostics.js +31 -0
- package/dist/commerce/server/commerceOmsCancelOrderHandler.d.ts +7 -0
- package/dist/commerce/server/commerceOmsCancelOrderHandler.js +22 -0
- package/dist/commerce/server/commerceOmsControlPlaneHandlers.d.ts +18 -0
- package/dist/commerce/server/commerceOmsControlPlaneHandlers.js +60 -0
- package/dist/commerce/server/commerceOmsHandlers.d.ts +47 -0
- package/dist/commerce/server/commerceOmsHandlers.js +176 -0
- package/dist/commerce/server/commerceOmsMarkRefundedHandler.d.ts +7 -0
- package/dist/commerce/server/commerceOmsMarkRefundedHandler.js +19 -0
- package/dist/commerce/server/commerceOrderDraft.d.ts +24 -0
- package/dist/commerce/server/commerceOrderDraft.js +92 -0
- package/dist/commerce/server/commercePaidOrderOrchestration.d.ts +131 -0
- package/dist/commerce/server/commercePaidOrderOrchestration.js +140 -0
- package/dist/commerce/server/commerceProviderAttemptFailure.d.ts +133 -0
- package/dist/commerce/server/commerceProviderAttemptFailure.js +175 -0
- package/dist/commerce/server/commerceReturnsHandlers.d.ts +41 -0
- package/dist/commerce/server/commerceReturnsHandlers.js +100 -0
- package/dist/commerce/server/commerceRuntimePort.d.ts +16 -0
- package/dist/commerce/server/commerceRuntimePort.js +57 -0
- package/dist/commerce/server/commerceRuntimeService.d.ts +98 -0
- package/dist/commerce/server/commerceRuntimeService.js +186 -0
- package/dist/commerce/server/commerceRuntimeStartResponse.d.ts +37 -0
- package/dist/commerce/server/commerceRuntimeStartResponse.js +56 -0
- package/dist/commerce/server/commerceStarterOfferGuard.d.ts +55 -0
- package/dist/commerce/server/commerceStarterOfferGuard.js +128 -0
- package/dist/commerce/server/configuratorIntentPersistence.d.ts +47 -0
- package/dist/commerce/server/configuratorIntentPersistence.js +85 -0
- package/dist/commerce/server/configuratorIntentPersistenceHandler.d.ts +14 -0
- package/dist/commerce/server/configuratorIntentPersistenceHandler.js +42 -0
- package/dist/commerce/server/emailRuntime.d.ts +47 -0
- package/dist/commerce/server/emailRuntime.js +1 -0
- package/dist/commerce/server/handlerSupport.d.ts +68 -0
- package/dist/commerce/server/handlerSupport.js +1 -0
- package/dist/commerce/server/index.d.ts +178 -0
- package/dist/commerce/server/index.js +127 -0
- package/dist/commerce/server/offerAvailability.d.ts +21 -0
- package/dist/commerce/server/offerAvailability.js +163 -0
- package/dist/commerce/server/orderDraftRpcPayload.d.ts +20 -0
- package/dist/commerce/server/orderDraftRpcPayload.js +21 -0
- package/dist/commerce/server/orderFeedbackSubmit.d.ts +20 -0
- package/dist/commerce/server/orderFeedbackSubmit.js +16 -0
- package/dist/commerce/server/orderFeedbackTokenCheck.d.ts +17 -0
- package/dist/commerce/server/orderFeedbackTokenCheck.js +14 -0
- package/dist/commerce/server/orderReviewAdminHandlers.d.ts +47 -0
- package/dist/commerce/server/orderReviewAdminHandlers.js +41 -0
- package/dist/commerce/server/orderReviewHandlers.d.ts +114 -0
- package/dist/commerce/server/orderReviewHandlers.js +42 -0
- package/dist/commerce/server/orderReviewLifecycle.d.ts +10 -0
- package/dist/commerce/server/orderReviewLifecycle.js +121 -0
- package/dist/commerce/server/orderReviewMedia.d.ts +11 -0
- package/dist/commerce/server/orderReviewMedia.js +172 -0
- package/dist/commerce/server/orderReviewRawUploadHandler.d.ts +40 -0
- package/dist/commerce/server/orderReviewRawUploadHandler.js +316 -0
- package/dist/commerce/server/outboxCheckoutExpiredEmailHandler.d.ts +14 -0
- package/dist/commerce/server/outboxCheckoutExpiredEmailHandler.js +57 -0
- package/dist/commerce/server/outboxCheckoutRecoveryEmailHandler.d.ts +13 -0
- package/dist/commerce/server/outboxCheckoutRecoveryEmailHandler.js +150 -0
- package/dist/commerce/server/outboxDispatchRegistry.d.ts +46 -0
- package/dist/commerce/server/outboxDispatchRegistry.js +184 -0
- package/dist/commerce/server/outboxDispatchRegistryComposition.d.ts +6 -0
- package/dist/commerce/server/outboxDispatchRegistryComposition.js +23 -0
- package/dist/commerce/server/outboxOrderDraftEmailHandler.d.ts +14 -0
- package/dist/commerce/server/outboxOrderDraftEmailHandler.js +130 -0
- package/dist/commerce/server/outboxOrderPaidEmailHandler.d.ts +21 -0
- package/dist/commerce/server/outboxOrderPaidEmailHandler.js +93 -0
- package/dist/commerce/server/outboxOrderPaidFulfillmentHandler.d.ts +3 -0
- package/dist/commerce/server/outboxOrderPaidFulfillmentHandler.js +1 -0
- package/dist/commerce/server/outboxOrderPaidFulfillmentPorts.d.ts +3 -0
- package/dist/commerce/server/outboxOrderPaidFulfillmentPorts.js +1 -0
- package/dist/commerce/server/outboxOrderRefundedEmailHandler.d.ts +13 -0
- package/dist/commerce/server/outboxOrderRefundedEmailHandler.js +42 -0
- package/dist/commerce/server/outboxPaymentFailedEmailHandler.d.ts +14 -0
- package/dist/commerce/server/outboxPaymentFailedEmailHandler.js +65 -0
- package/dist/commerce/server/outboxReturnEmailHandlers.d.ts +26 -0
- package/dist/commerce/server/outboxReturnEmailHandlers.js +53 -0
- package/dist/commerce/server/outboxShipmentDeliveredEmailHandler.d.ts +17 -0
- package/dist/commerce/server/outboxShipmentDeliveredEmailHandler.js +52 -0
- package/dist/commerce/server/outboxShipmentDispatchedEmailHandler.d.ts +13 -0
- package/dist/commerce/server/outboxShipmentDispatchedEmailHandler.js +87 -0
- package/dist/commerce/server/outboxShipmentExceptionEmailHandler.d.ts +13 -0
- package/dist/commerce/server/outboxShipmentExceptionEmailHandler.js +46 -0
- package/dist/commerce/server/referenceCheckoutHandler.d.ts +48 -0
- package/dist/commerce/server/referenceCheckoutHandler.js +68 -0
- package/dist/commerce/server/reservationSweepPort.d.ts +31 -0
- package/dist/commerce/server/reservationSweepPort.js +45 -0
- package/dist/commerce/server/starterTermsPort.d.ts +22 -0
- package/dist/commerce/server/starterTermsPort.js +1 -0
- package/dist/commerce/server/supabaseCommerceReturnsPort.d.ts +13 -0
- package/dist/commerce/server/supabaseCommerceReturnsPort.js +56 -0
- package/dist/communications/consentPurposeRegistry.d.ts +1 -1
- package/dist/communications/newsletterIntegrationContracts.d.ts +5 -5
- package/dist/composition/commerceContribution.d.ts +21 -0
- package/dist/composition/commerceContribution.js +27 -0
- package/dist/composition/index.d.ts +1 -0
- package/dist/composition/index.js +1 -0
- package/dist/fulfillment/handlerSchemas.d.ts +41 -41
- package/dist/fulfillment/index.d.ts +1 -1
- package/dist/fulfillment/index.js +1 -1
- package/dist/fulfillment/paidHandoff.d.ts +12 -1
- package/dist/fulfillment/paidHandoff.js +2 -2
- package/dist/fulfillment/providerDispatchWorker.d.ts +4 -4
- package/dist/identity/customerContracts.d.ts +2 -2
- package/dist/inventory/bindings.d.ts +3 -0
- package/dist/inventory/bindings.js +10 -4
- package/dist/inventory/index.d.ts +1 -0
- package/dist/inventory/index.js +1 -0
- package/dist/inventory/managedStockAvailability.d.ts +15 -0
- package/dist/inventory/managedStockAvailability.js +16 -0
- package/dist/inventory/postgresStockAvailability.js +2 -25
- package/dist/inventory/schemas.d.ts +1 -1
- package/dist/inventory/stockReadResponse.d.ts +4 -0
- package/dist/inventory/stockReadResponse.js +27 -0
- package/dist/pricing/browser/index.d.ts +6 -0
- package/dist/pricing/browser/index.js +6 -0
- package/dist/promotions/adminPromotionsContracts.d.ts +2 -2
- package/dist/subscriptions/index.d.ts +3 -2
- package/dist/subscriptions/index.js +3 -2
- package/package.json +22 -2
- package/release-gates.json +63 -8
- package/src/commerce/adapters/managed/commerceOmsControlPlane.ts +80 -0
- package/src/commerce/adapters/managed/commerceOmsMutations.ts +145 -0
- package/src/commerce/adapters/managed/commerceOmsPort.ts +158 -0
- package/src/commerce/adapters/managed/oms/accounting.ts +18 -0
- package/src/commerce/adapters/managed/oms/fulfillmentReads.ts +82 -0
- package/src/commerce/adapters/managed/oms/inboundEvents.ts +45 -0
- package/src/commerce/adapters/managed/oms/outboxEvents.ts +30 -0
- package/src/commerce/adapters/managed/oms/paymentAttempts.ts +19 -0
- package/src/commerce/adapters/managed/oms/queueSelection.ts +132 -0
- package/src/commerce/adapters/managed/oms/readProjections.ts +22 -0
- package/src/commerce/adapters/managed/oms/readQueries.ts +292 -0
- package/src/commerce/adapters/managed/oms/types.ts +9 -0
- package/src/commerce/checkoutCommandSchemas.ts +93 -0
- package/src/commerce/checkoutHelpers.ts +47 -0
- package/src/commerce/checkoutResumeSchemas.ts +164 -0
- package/src/commerce/checkoutSchemas.ts +182 -0
- package/src/commerce/commerceReturnsPort.ts +67 -0
- package/src/commerce/configuratorIntentPersistenceSchemas.ts +26 -0
- package/src/commerce/configuratorIntentSchemas.ts +47 -0
- package/src/commerce/contractPrimitives.ts +30 -0
- package/src/commerce/contracts/availability.ts +21 -0
- package/src/commerce/contracts/fulfillmentRecovery.ts +26 -0
- package/src/commerce/contracts/index.ts +17 -0
- package/src/commerce/contracts/intent.ts +58 -0
- package/src/commerce/contracts/omsTypes.ts +1217 -0
- package/src/commerce/contracts/order.ts +44 -0
- package/src/commerce/contracts/orderMoney.ts +75 -0
- package/src/commerce/contracts/ports.ts +124 -0
- package/src/commerce/contracts/recovery.ts +24 -0
- package/src/commerce/contracts/runtimePorts.ts +201 -0
- package/src/commerce/contracts/state.ts +64 -0
- package/src/commerce/customerDefaultsSnapshotSchemas.ts +117 -0
- package/src/commerce/errors.ts +53 -0
- package/src/commerce/fulfillmentEligibility.ts +32 -0
- package/src/commerce/index.ts +82 -0
- package/src/commerce/model/customerFulfillmentRecovery.ts +185 -0
- package/src/commerce/model/fulfillmentCancellationEligibility.ts +18 -0
- package/src/commerce/model/omsAccountingVisibility.ts +135 -0
- package/src/commerce/model/omsBillingInvoiceBuyer.ts +20 -0
- package/src/commerce/model/omsCurrency.ts +8 -0
- package/src/commerce/model/omsFulfillmentDebug.ts +157 -0
- package/src/commerce/model/omsFulfillmentSummary.ts +225 -0
- package/src/commerce/model/omsListTotals.ts +38 -0
- package/src/commerce/model/omsOperationalLadder.ts +181 -0
- package/src/commerce/model/omsOrderLineMoney.ts +34 -0
- package/src/commerce/model/omsPaymentMethodSummary.ts +19 -0
- package/src/commerce/model/omsReadModel.ts +302 -0
- package/src/commerce/model/omsReadModelCommunication.ts +32 -0
- package/src/commerce/model/omsReadModelHelpers.ts +279 -0
- package/src/commerce/model/omsReadModelList.ts +90 -0
- package/src/commerce/model/omsReadModelListSummary.ts +19 -0
- package/src/commerce/model/omsReadModelPricing.ts +57 -0
- package/src/commerce/model/omsReadModelProjections.ts +1 -0
- package/src/commerce/model/omsReadModelRowCore.ts +193 -0
- package/src/commerce/model/omsReadModelRows.ts +7 -0
- package/src/commerce/offerAvailability.ts +75 -0
- package/src/commerce/offerAvailabilitySchemas.ts +56 -0
- package/src/commerce/offerEvidenceSchemas.ts +17 -0
- package/src/commerce/oms/omsContractBase.ts +92 -0
- package/src/commerce/oms/omsContractReadAuxSchemas.ts +130 -0
- package/src/commerce/oms/omsContractReadSchemas.ts +303 -0
- package/src/commerce/oms/omsContractRequests.ts +143 -0
- package/src/commerce/oms/omsContracts.ts +6 -0
- package/src/commerce/oms/omsControlPlane.ts +85 -0
- package/src/commerce/oms/omsFulfillmentContractSchemas.ts +113 -0
- package/src/commerce/oms/omsFulfillmentDebugSchemas.ts +38 -0
- package/src/commerce/oms/omsFulfillmentHealthSchemas.ts +46 -0
- package/src/commerce/oms/omsPorts.ts +165 -0
- package/src/commerce/oms/omsPrimitives.ts +3 -0
- package/src/commerce/oms/omsProviderEvidenceSchemas.ts +13 -0
- package/src/commerce/orderDraftErrors.ts +28 -0
- package/src/commerce/orderEmailEligibility.ts +131 -0
- package/src/commerce/orderEmailLines.ts +22 -0
- package/src/commerce/orderFeedbackContracts.ts +47 -0
- package/src/commerce/orderMoney.ts +207 -0
- package/src/commerce/orderReviewContracts.ts +124 -0
- package/src/commerce/orderReviewPorts.ts +94 -0
- package/src/commerce/outboxDispatchContracts.ts +30 -0
- package/src/commerce/outboxEventSchemas.ts +230 -0
- package/src/commerce/outboxOrderDraftEmailPorts.ts +241 -0
- package/src/commerce/paymentContinuation.ts +5 -0
- package/src/commerce/ports.ts +7 -0
- package/src/commerce/recoveryDestination.ts +23 -0
- package/src/commerce/runtimeErrors.ts +19 -0
- package/src/commerce/salesChannelEnvelope.ts +28 -0
- package/src/commerce/schemas.ts +104 -0
- package/src/commerce/server/checkoutCompensation.ts +49 -0
- package/src/commerce/server/checkoutConflictClassifiers.ts +53 -0
- package/src/commerce/server/checkoutExpiredRecoveryPolicy.ts +107 -0
- package/src/commerce/server/checkoutInvoiceBuyerSnapshot.ts +36 -0
- package/src/commerce/server/checkoutOfferPolicyPort.ts +60 -0
- package/src/commerce/server/checkoutPaymentContinuationCredential.ts +222 -0
- package/src/commerce/server/checkoutQuoteTypes.ts +9 -0
- package/src/commerce/server/checkoutRecoveryOrderPort.ts +40 -0
- package/src/commerce/server/checkoutRecoveryToken.ts +63 -0
- package/src/commerce/server/checkoutRefusalContinuation.ts +29 -0
- package/src/commerce/server/checkoutRuntimeTypes.ts +26 -0
- package/src/commerce/server/commerceCheckoutCommandExecution.ts +188 -0
- package/src/commerce/server/commerceCheckoutCompensation.ts +66 -0
- package/src/commerce/server/commerceCheckoutContinuationTerms.ts +87 -0
- package/src/commerce/server/commerceCheckoutCustomerDefaults.ts +24 -0
- package/src/commerce/server/commerceCheckoutFailureHandler.ts +144 -0
- package/src/commerce/server/commerceCheckoutHandler.ts +269 -0
- package/src/commerce/server/commerceCheckoutHandlerAdmission.ts +157 -0
- package/src/commerce/server/commerceCheckoutHandlerHelpers.ts +223 -0
- package/src/commerce/server/commerceCheckoutOrchestrationError.ts +15 -0
- package/src/commerce/server/commerceCheckoutPromotionPriceChange.ts +83 -0
- package/src/commerce/server/commerceCheckoutProviderPayment.ts +45 -0
- package/src/commerce/server/commerceCheckoutQuoteGuard.ts +172 -0
- package/src/commerce/server/commerceCheckoutResume.ts +132 -0
- package/src/commerce/server/commerceCheckoutResumeGuard.ts +195 -0
- package/src/commerce/server/commerceCheckoutSavedPaymentMethod.ts +85 -0
- package/src/commerce/server/commerceCheckoutStartRuntimeFailure.ts +59 -0
- package/src/commerce/server/commerceCheckoutTiming.ts +53 -0
- package/src/commerce/server/commerceDiagnostics.ts +37 -0
- package/src/commerce/server/commerceOmsCancelOrderHandler.ts +43 -0
- package/src/commerce/server/commerceOmsControlPlaneHandlers.ts +71 -0
- package/src/commerce/server/commerceOmsHandlers.ts +275 -0
- package/src/commerce/server/commerceOmsMarkRefundedHandler.ts +39 -0
- package/src/commerce/server/commerceOrderDraft.ts +131 -0
- package/src/commerce/server/commercePaidOrderOrchestration.ts +275 -0
- package/src/commerce/server/commerceProviderAttemptFailure.ts +257 -0
- package/src/commerce/server/commerceReturnsHandlers.ts +143 -0
- package/src/commerce/server/commerceRuntimePort.ts +75 -0
- package/src/commerce/server/commerceRuntimeService.ts +229 -0
- package/src/commerce/server/commerceRuntimeStartResponse.ts +76 -0
- package/src/commerce/server/commerceStarterOfferGuard.ts +200 -0
- package/src/commerce/server/configuratorIntentPersistence.ts +161 -0
- package/src/commerce/server/configuratorIntentPersistenceHandler.ts +54 -0
- package/src/commerce/server/emailRuntime.ts +30 -0
- package/src/commerce/server/handlerSupport.ts +22 -0
- package/src/commerce/server/index.ts +181 -0
- package/src/commerce/server/offerAvailability.ts +275 -0
- package/src/commerce/server/orderDraftRpcPayload.ts +39 -0
- package/src/commerce/server/orderFeedbackSubmit.ts +40 -0
- package/src/commerce/server/orderFeedbackTokenCheck.ts +28 -0
- package/src/commerce/server/orderReviewAdminHandlers.ts +43 -0
- package/src/commerce/server/orderReviewHandlers.ts +57 -0
- package/src/commerce/server/orderReviewLifecycle.ts +129 -0
- package/src/commerce/server/orderReviewMedia.ts +170 -0
- package/src/commerce/server/orderReviewRawUploadHandler.ts +300 -0
- package/src/commerce/server/outboxCheckoutExpiredEmailHandler.ts +86 -0
- package/src/commerce/server/outboxCheckoutRecoveryEmailHandler.ts +188 -0
- package/src/commerce/server/outboxDispatchRegistry.ts +269 -0
- package/src/commerce/server/outboxDispatchRegistryComposition.ts +31 -0
- package/src/commerce/server/outboxOrderDraftEmailHandler.ts +162 -0
- package/src/commerce/server/outboxOrderPaidEmailHandler.ts +147 -0
- package/src/commerce/server/outboxOrderPaidFulfillmentHandler.ts +4 -0
- package/src/commerce/server/outboxOrderPaidFulfillmentPorts.ts +3 -0
- package/src/commerce/server/outboxOrderRefundedEmailHandler.ts +58 -0
- package/src/commerce/server/outboxPaymentFailedEmailHandler.ts +99 -0
- package/src/commerce/server/outboxReturnEmailHandlers.ts +92 -0
- package/src/commerce/server/outboxShipmentDeliveredEmailHandler.ts +94 -0
- package/src/commerce/server/outboxShipmentDispatchedEmailHandler.ts +112 -0
- package/src/commerce/server/outboxShipmentExceptionEmailHandler.ts +73 -0
- package/src/commerce/server/referenceCheckoutHandler.ts +87 -0
- package/src/commerce/server/reservationSweepPort.ts +67 -0
- package/src/commerce/server/starterTermsPort.ts +22 -0
- package/src/commerce/server/supabaseCommerceReturnsPort.ts +81 -0
- package/src/composition/commerceContribution.ts +35 -0
- package/src/composition/index.ts +1 -0
- package/src/fulfillment/index.ts +1 -1
- package/src/fulfillment/paidHandoff.ts +2 -2
- package/src/inventory/bindings.ts +12 -4
- package/src/inventory/index.ts +1 -0
- package/src/inventory/managedStockAvailability.ts +23 -0
- package/src/inventory/postgresStockAvailability.ts +2 -21
- package/src/inventory/stockReadResponse.ts +25 -0
- package/src/pricing/browser/index.ts +6 -0
- package/src/subscriptions/index.ts +3 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CommerceFulfillmentEligibilityInput, OmsFulfillmentBlockReason } from "./contracts/state.js";
|
|
2
|
+
|
|
3
|
+
export function evaluateCommerceFulfillmentEligibility(
|
|
4
|
+
input: CommerceFulfillmentEligibilityInput,
|
|
5
|
+
): { allowed: boolean; reason: OmsFulfillmentBlockReason | null } {
|
|
6
|
+
if (input.activeHoldCount > 0) return { allowed: false, reason: "active_hold" };
|
|
7
|
+
if (!input.hasShippingAddress) return { allowed: false, reason: "missing_shipping_address" };
|
|
8
|
+
if (input.riskReviewRequired) return { allowed: false, reason: "risk_review" };
|
|
9
|
+
if (!["paid", "fulfillment_pending", "fulfilled"].includes(input.orderStatus)) {
|
|
10
|
+
return { allowed: false, reason: "order_not_paid" };
|
|
11
|
+
}
|
|
12
|
+
if (input.paymentStatus !== "succeeded") {
|
|
13
|
+
return { allowed: false, reason: "payment_not_succeeded" };
|
|
14
|
+
}
|
|
15
|
+
if (input.orderMode === "subscription_cycle" && input.subscriptionCycleStatus !== "paid") {
|
|
16
|
+
return { allowed: false, reason: "subscription_cycle_not_paid" };
|
|
17
|
+
}
|
|
18
|
+
if (
|
|
19
|
+
input.inventoryReviewRequired ||
|
|
20
|
+
["missing", "released", "expired", "review_required"].includes(input.inventoryStatus ?? "not_checked")
|
|
21
|
+
) {
|
|
22
|
+
return { allowed: false, reason: "inventory_review" };
|
|
23
|
+
}
|
|
24
|
+
return { allowed: true, reason: null };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function mapOmsPaymentStatus(status: string | null): string {
|
|
28
|
+
if (!status) return "not_started";
|
|
29
|
+
if (status === "pending") return "processing";
|
|
30
|
+
if (status === "paid") return "succeeded";
|
|
31
|
+
return status as string;
|
|
32
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export type * from "./contracts/index.js";
|
|
2
|
+
export { createOfferAvailabilitySchemas, offerAvailabilityRequestItems } from "./offerAvailabilitySchemas.js";
|
|
3
|
+
export { hasSubscriptionRecoveryContext, resolveRecoveryDestination } from "./recoveryDestination.js";
|
|
4
|
+
export * from "./errors.js";
|
|
5
|
+
export * from "./orderDraftErrors.js";
|
|
6
|
+
export { buildOrderDeliveryContact, uuidFromOrderRef, messageOf } from "./checkoutHelpers.js";
|
|
7
|
+
export type { OrderDeliveryContactInput } from "./checkoutHelpers.js";
|
|
8
|
+
export { CART_STATUSES, CHECKOUT_STATUSES, ORDER_DRAFT_STATUSES, ORDER_STATUSES, PAYMENT_STATUSES, OMS_FULFILLMENT_BLOCK_REASONS, OMS_INVENTORY_STATUSES } from "./contracts/state.js";
|
|
9
|
+
export { evaluateCommerceFulfillmentEligibility, mapOmsPaymentStatus } from "./fulfillmentEligibility.js";
|
|
10
|
+
export * from "./contractPrimitives.js";
|
|
11
|
+
export { createCommerceSchemas } from "./schemas.js";
|
|
12
|
+
export * from "./checkoutResumeSchemas.js";
|
|
13
|
+
export * from "./customerDefaultsSnapshotSchemas.js";
|
|
14
|
+
export * from "./configuratorIntentSchemas.js";
|
|
15
|
+
export * from "./configuratorIntentPersistenceSchemas.js";
|
|
16
|
+
export { CHECKOUT_CONTRACT_VERSION, ASYNC_CHECKOUT_STATUSES, checkoutKindSchema, checkoutActivationStatusSchema, asyncCheckoutStatusSchema, subscriptionActivationStatusSchema, invoiceBuyerSnapshotAddressCoreSchema, checkoutRequestCoreSchema, createCheckoutResponseSchemas, createCheckoutQuoteSchemas } from "./checkoutSchemas.js";
|
|
17
|
+
export * from "./runtimeErrors.js";
|
|
18
|
+
export type { CreateQuoteOptions, CommerceQuotePort } from "./ports.js";
|
|
19
|
+
export * from "./orderMoney.js";
|
|
20
|
+
export * from "./outboxEventSchemas.js";
|
|
21
|
+
|
|
22
|
+
// M11 K3a OMS runtime surface.
|
|
23
|
+
export * from "./model/omsAccountingVisibility.js";
|
|
24
|
+
export * from "./model/omsBillingInvoiceBuyer.js";
|
|
25
|
+
export * from "./model/omsOrderLineMoney.js";
|
|
26
|
+
export * from "./model/omsPaymentMethodSummary.js";
|
|
27
|
+
export * from "./model/omsReadModelCommunication.js";
|
|
28
|
+
export * from "./model/omsReadModelHelpers.js";
|
|
29
|
+
export * from "./model/omsReadModelList.js";
|
|
30
|
+
export * from "./model/omsReadModelListSummary.js";
|
|
31
|
+
export * from "./model/omsReadModelPricing.js";
|
|
32
|
+
export * from "./model/omsReadModelRows.js";
|
|
33
|
+
export * from "./model/omsFulfillmentDebug.js";
|
|
34
|
+
export * from "./model/omsOperationalLadder.js";
|
|
35
|
+
export * from "./model/omsFulfillmentSummary.js";
|
|
36
|
+
export * from "./model/omsListTotals.js";
|
|
37
|
+
export * from "./model/omsReadModelRowCore.js";
|
|
38
|
+
export * from "./model/fulfillmentCancellationEligibility.js";
|
|
39
|
+
export * from "./oms/omsContractBase.js";
|
|
40
|
+
export * from "./oms/omsContractReadAuxSchemas.js";
|
|
41
|
+
export * from "./oms/omsContractReadSchemas.js";
|
|
42
|
+
export * from "./oms/omsContractRequests.js";
|
|
43
|
+
export * from "./oms/omsContracts.js";
|
|
44
|
+
export * from "./oms/omsFulfillmentContractSchemas.js";
|
|
45
|
+
export * from "./oms/omsFulfillmentDebugSchemas.js";
|
|
46
|
+
export * from "./oms/omsFulfillmentHealthSchemas.js";
|
|
47
|
+
export * from "./oms/omsProviderEvidenceSchemas.js";
|
|
48
|
+
export * from "./oms/omsControlPlane.js";
|
|
49
|
+
export * from "./oms/omsPorts.js";
|
|
50
|
+
export * from "./model/omsReadModelProjections.js";
|
|
51
|
+
export * from "./model/omsCurrency.js";
|
|
52
|
+
import { COMMERCE_CONTRACT_VERSION as contractVersion } from "../pricing/contracts/index.js";
|
|
53
|
+
export const COMMERCE_CONTRACT_VERSION = contractVersion;
|
|
54
|
+
export * from "./model/customerFulfillmentRecovery.js";
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export * from "./commerceReturnsPort.js";
|
|
58
|
+
export * from "./orderReviewContracts.js";
|
|
59
|
+
export type * from "./orderReviewPorts.js";
|
|
60
|
+
export * from "./orderFeedbackContracts.js";
|
|
61
|
+
|
|
62
|
+
// Experimental browser-safe event contracts, projections and ports.
|
|
63
|
+
export * from "./salesChannelEnvelope.js";
|
|
64
|
+
export * from "./orderEmailEligibility.js";
|
|
65
|
+
export * from "./orderEmailLines.js";
|
|
66
|
+
export * from "./outboxDispatchContracts.js";
|
|
67
|
+
export * from "./outboxOrderDraftEmailPorts.js";
|
|
68
|
+
|
|
69
|
+
/** @consumer src/domains/commerce/checkoutCommandContracts.ts */
|
|
70
|
+
export { createCheckoutCommandSchemas, CHECKOUT_COMMAND_V1, REFERENCE_CHECKOUT_V1 } from "./checkoutCommandSchemas.js";
|
|
71
|
+
export type { CheckoutCommandPersistenceResult } from "./checkoutCommandSchemas.js";
|
|
72
|
+
/** @consumer src/domains/commerce/paymentContinuationContracts.ts */
|
|
73
|
+
export { checkoutContinuationJourneyIdSchema, CHECKOUT_PAYMENT_CONTINUATION_TTL_SECONDS } from "./paymentContinuation.js";
|
|
74
|
+
|
|
75
|
+
/** @consumer server/domains/commerce/checkoutOfferPolicyPort.ts */
|
|
76
|
+
export { commerceOfferEvidenceSchema } from "./offerEvidenceSchemas.js";
|
|
77
|
+
export type { CommerceOfferEvidence } from "./offerEvidenceSchemas.js";
|
|
78
|
+
|
|
79
|
+
/** @consumer src/domains/commerce/offerAvailability.ts */
|
|
80
|
+
export { DEFAULT_LOW_STOCK_THRESHOLD, deriveOfferAvailability, defaultOfferAvailability, availabilityBySku, statusForSellableNow, reasonCodeFor } from "./offerAvailability.js";
|
|
81
|
+
/** @consumer src/domains/commerce/offerAvailability.ts */
|
|
82
|
+
export type { DeriveOfferAvailabilityInput } from "./offerAvailability.js";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { CustomerFulfillmentStep } from "@openlup/core/fulfillment";
|
|
2
|
+
import { canonicalStatusToken,customerStepFromSignals,stepForToken } from "@openlup/core/fulfillment";
|
|
3
|
+
import type { ProviderStatusEvidence,ReleasedProviderExceptionHold,ResolvedProviderExceptionRecovery,TimedFulfillmentSignal } from "../contracts/fulfillmentRecovery.js";
|
|
4
|
+
export { stepForToken } from "@openlup/core/fulfillment";
|
|
5
|
+
export type { CustomerFulfillmentStep } from "@openlup/core/fulfillment";
|
|
6
|
+
export type { ProviderStatusEvidence,ReleasedProviderExceptionHold,ResolvedProviderExceptionRecovery,TimedFulfillmentSignal } from "../contracts/fulfillmentRecovery.js";
|
|
7
|
+
|
|
8
|
+
/** Server-only shape read from a released automatic provider-exception hold. */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Finds only database-authored, trigger-created recovery links. The returned IDs
|
|
12
|
+
* stay server-side: the browser receives the resulting Layer C step, never hold
|
|
13
|
+
* metadata or provider evidence identifiers.
|
|
14
|
+
*/
|
|
15
|
+
export function resolveProviderExceptionRecovery(input: {
|
|
16
|
+
automaticHoldSource?: string;
|
|
17
|
+
automaticReleaseSource?: string;
|
|
18
|
+
fulfillmentOrderId: string | null | undefined;
|
|
19
|
+
releasedHolds: ReleasedProviderExceptionHold[];
|
|
20
|
+
statusEvidence: ProviderStatusEvidence[];
|
|
21
|
+
}): ResolvedProviderExceptionRecovery {
|
|
22
|
+
const clearedExceptionEvidenceIds = new Set<string>();
|
|
23
|
+
const recoveryEvidenceIds = new Set<string>();
|
|
24
|
+
const fulfillmentOrderId = text(input.fulfillmentOrderId);
|
|
25
|
+
if (!fulfillmentOrderId) return { clearedExceptionEvidenceIds, recoveryEvidenceIds };
|
|
26
|
+
|
|
27
|
+
const evidenceById = new Map(
|
|
28
|
+
input.statusEvidence
|
|
29
|
+
.map((row) => [text(row.id), row] as const)
|
|
30
|
+
.filter(([id]) => Boolean(id)),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
for (const hold of input.releasedHolds) {
|
|
34
|
+
if (
|
|
35
|
+
hold.status !== "released"
|
|
36
|
+
|| hold.reason !== "fulfillment_exception"
|
|
37
|
+
|| hold.createdBy !== null
|
|
38
|
+
|| hold.releasedBy !== null
|
|
39
|
+
) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const metadata = record(hold.metadata);
|
|
43
|
+
const recovery = record(metadata.autoReleaseEvidence);
|
|
44
|
+
if (
|
|
45
|
+
(!input.automaticHoldSource || metadata.source !== input.automaticHoldSource)
|
|
46
|
+
|| metadata.autoReleased !== true
|
|
47
|
+
|| (!input.automaticReleaseSource || metadata.autoReleaseSource !== input.automaticReleaseSource)
|
|
48
|
+
|| (metadata.autoReleaseProof !== "provider_recovered" && metadata.autoReleaseProof !== "delivered")
|
|
49
|
+
|| recovery.fulfillmentOrderId !== fulfillmentOrderId
|
|
50
|
+
) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const cleared = evidenceById.get(text(recovery.clearedStatusEvidenceId));
|
|
55
|
+
const recovered = evidenceById.get(text(recovery.statusEvidenceId));
|
|
56
|
+
if (!cleared || !recovered || text(cleared.fulfillmentOrderId) !== fulfillmentOrderId || text(recovered.fulfillmentOrderId) !== fulfillmentOrderId) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const clearedStatus = canonicalStatusToken(cleared.providerStatus);
|
|
61
|
+
const recoveryStatus = canonicalStatusToken(recovered.localStatus);
|
|
62
|
+
if (
|
|
63
|
+
canonicalStatusToken(cleared.localStatus) !== "exception"
|
|
64
|
+
|| (clearedStatus !== "suspended" && clearedStatus !== "shipping_failed")
|
|
65
|
+
|| !sameInstant(recovery.clearedOccurredAt, cleared.occurredAt)
|
|
66
|
+
|| !sameInstant(recovery.occurredAt, recovered.occurredAt)
|
|
67
|
+
|| !isStrictlyNewer(recovered.occurredAt, cleared.occurredAt)
|
|
68
|
+
|| canonicalStatusToken(text(recovery.clearedProviderStatus)) !== clearedStatus
|
|
69
|
+
|| canonicalStatusToken(text(recovery.localStatus)) !== recoveryStatus
|
|
70
|
+
|| !isApprovedRecovery(clearedStatus, recoveryStatus, metadata.autoReleaseProof)
|
|
71
|
+
) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const clearedId = text(cleared.id);
|
|
76
|
+
const recoveredId = text(recovered.id);
|
|
77
|
+
if (!clearedId || !recoveredId) continue;
|
|
78
|
+
clearedExceptionEvidenceIds.add(clearedId);
|
|
79
|
+
recoveryEvidenceIds.add(recoveredId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { clearedExceptionEvidenceIds, recoveryEvidenceIds };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The customer step for an order that is terminal BY OUR OWN DECISION
|
|
87
|
+
* (`cancelled` / `refunded`), or `null` when normal rank resolution applies.
|
|
88
|
+
*
|
|
89
|
+
* Rank alone is not enough here: `delivered` (7) outranks `cancelled` (6), so a
|
|
90
|
+
* single provider `DELIVERED` evidence row on an order we cancelled would tell
|
|
91
|
+
* the customer "delivered". Carrier evidence is a fact and stays recorded, but
|
|
92
|
+
* it cannot un-cancel our own order, so the terminal order status wins.
|
|
93
|
+
*
|
|
94
|
+
* This is a ceiling, not a new opinion: `delivered` is the ONLY step ranking
|
|
95
|
+
* above `cancelled`, and the order's own status already contributes `cancelled`
|
|
96
|
+
* to the ranked signals, so every non-delivered outcome is unchanged. The canon's
|
|
97
|
+
* ranks stay untouched — they are shared with OMS health, observability and the
|
|
98
|
+
* admin timeline, where provider-versus-local divergence must remain visible.
|
|
99
|
+
* Single owner of this rule: the customer read model and the browser fallback
|
|
100
|
+
* resolver both call it instead of each keeping a copy.
|
|
101
|
+
*/
|
|
102
|
+
export function customerStepForTerminalOrder(
|
|
103
|
+
orderStatus: string | null | undefined,
|
|
104
|
+
): CustomerFulfillmentStep | null {
|
|
105
|
+
return stepForToken(orderStatus) === "cancelled" ? "cancelled" : null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Resolve rank normally; only a uniquely newer canonical timed exception may cover delivered. */
|
|
109
|
+
export function customerStepFromTimedSignals(
|
|
110
|
+
baseTokens: Array<string | null | undefined>,
|
|
111
|
+
evidence: TimedFulfillmentSignal[],
|
|
112
|
+
recovery?: ResolvedProviderExceptionRecovery,
|
|
113
|
+
): CustomerFulfillmentStep {
|
|
114
|
+
const recovered = recovery?.clearedExceptionEvidenceIds.size;
|
|
115
|
+
const effectiveBaseTokens = recovered
|
|
116
|
+
? baseTokens.filter((token) => stepForToken(token) !== "exception")
|
|
117
|
+
: baseTokens;
|
|
118
|
+
const effectiveEvidence = recovery
|
|
119
|
+
? evidence.filter((signal) => !recovery.clearedExceptionEvidenceIds.has(text(signal.id)))
|
|
120
|
+
: evidence;
|
|
121
|
+
const ranked = customerStepFromSignals([...effectiveBaseTokens, ...effectiveEvidence.map((signal) => signal.token)]);
|
|
122
|
+
if (ranked !== "delivered") return ranked;
|
|
123
|
+
const timedOccurrences = effectiveEvidence
|
|
124
|
+
.map((signal) => ({ step: stepForToken(signal.token), time: validTimestamp(signal.occurredAt) }))
|
|
125
|
+
.filter((signal): signal is { step: CustomerFulfillmentStep | null; time: number } => signal.time !== null);
|
|
126
|
+
const timed = [...new Map(timedOccurrences.map((signal) => [
|
|
127
|
+
`${signal.step ?? "unknown"}:${signal.time}`,
|
|
128
|
+
signal,
|
|
129
|
+
])).values()];
|
|
130
|
+
const latestTime = Math.max(...timed.map((signal) => signal.time));
|
|
131
|
+
const latest = timed.filter((signal) => signal.time === latestTime);
|
|
132
|
+
const deliveryTimes = timed.filter((signal) => signal.step === "delivered").map((signal) => signal.time);
|
|
133
|
+
const latestDeliveryTime = deliveryTimes.length ? Math.max(...deliveryTimes) : null;
|
|
134
|
+
return latest.length === 1 && latest[0].step === "exception"
|
|
135
|
+
&& latestDeliveryTime !== null && latestTime > latestDeliveryTime ? "exception" : ranked;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Keep legacy/provider-only Provider CANCELLED evidence customer-safe. */
|
|
139
|
+
export function customerSafeEvidenceToken(
|
|
140
|
+
localStatus: string | null | undefined,
|
|
141
|
+
providerStatus: string | null | undefined,
|
|
142
|
+
): string | null {
|
|
143
|
+
const local = canonicalStatusToken(localStatus);
|
|
144
|
+
const provider = canonicalStatusToken(providerStatus);
|
|
145
|
+
if (provider === "cancelled" && (local === null || local === "cancelled")) return "exception";
|
|
146
|
+
return local ?? provider;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function validTimestamp(value: string | null | undefined): number | null {
|
|
150
|
+
if (!value || !/(?:[Zz]|[+-]\d{2}:\d{2})$/.test(value)) return null;
|
|
151
|
+
const parsed = Date.parse(value);
|
|
152
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isApprovedRecovery(
|
|
156
|
+
clearedStatus: "suspended" | "shipping_failed",
|
|
157
|
+
recoveryStatus: string | null,
|
|
158
|
+
proof: unknown,
|
|
159
|
+
): boolean {
|
|
160
|
+
if (proof === "delivered") return recoveryStatus === "delivered";
|
|
161
|
+
return clearedStatus === "suspended"
|
|
162
|
+
&& proof === "provider_recovered"
|
|
163
|
+
&& ["provider_received", "picking", "packed", "in_transit"].includes(recoveryStatus ?? "");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function isStrictlyNewer(candidate: string | null | undefined, previous: string | null | undefined): boolean {
|
|
167
|
+
const candidateTime = validTimestamp(candidate);
|
|
168
|
+
const previousTime = validTimestamp(previous);
|
|
169
|
+
return candidateTime !== null && previousTime !== null && candidateTime > previousTime;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function sameInstant(metadataValue: unknown, evidenceValue: string | null | undefined): boolean {
|
|
173
|
+
if (typeof metadataValue !== "string") return false;
|
|
174
|
+
const metadataTime = validTimestamp(metadataValue);
|
|
175
|
+
const evidenceTime = validTimestamp(evidenceValue);
|
|
176
|
+
return metadataTime !== null && evidenceTime !== null && metadataTime === evidenceTime;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function record(value: unknown): Record<string, unknown> {
|
|
180
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function text(value: unknown): string {
|
|
184
|
+
return typeof value === "string" ? value : "";
|
|
185
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OmsOrderDetail } from "../oms/omsContracts.js";
|
|
2
|
+
|
|
3
|
+
export function canCancelFulfillment(
|
|
4
|
+
status: OmsOrderDetail["fulfillmentStatus"],
|
|
5
|
+
providerCancellation: {
|
|
6
|
+
activeHoldCount: number;
|
|
7
|
+
orderMode: "one_time" | "subscription_cycle";
|
|
8
|
+
orderStatus: OmsOrderDetail["status"];
|
|
9
|
+
providerCancellationConfirmed: boolean;
|
|
10
|
+
},
|
|
11
|
+
): boolean {
|
|
12
|
+
if (status === "created" || status === "packed" || status === "label_pending") return true;
|
|
13
|
+
return status === "exception"
|
|
14
|
+
&& providerCancellation.activeHoldCount === 0
|
|
15
|
+
&& providerCancellation.orderMode === "one_time"
|
|
16
|
+
&& (providerCancellation.orderStatus === "paid" || providerCancellation.orderStatus === "fulfillment_pending")
|
|
17
|
+
&& providerCancellation.providerCancellationConfirmed;
|
|
18
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { OmsAccountingRecoveryGuidance } from "../contracts/omsTypes.js";
|
|
2
|
+
import type { OmsAccountingStatus,OmsOrderDetail } from "../oms/omsContracts.js";
|
|
3
|
+
import type { OmsReadModelProjections } from "./omsReadModelProjections.js";
|
|
4
|
+
import type {
|
|
5
|
+
OmsAccountingInvoiceRow,
|
|
6
|
+
OmsAccountingOutboxRow,
|
|
7
|
+
} from "./omsReadModelRows.js";
|
|
8
|
+
export type { OmsAccountingRecoveryGuidance } from "../contracts/omsTypes.js";
|
|
9
|
+
|
|
10
|
+
export function accountingSummary(
|
|
11
|
+
invoice: OmsAccountingInvoiceRow | null,
|
|
12
|
+
outboxRows: OmsAccountingOutboxRow[],
|
|
13
|
+
projections?: OmsReadModelProjections,
|
|
14
|
+
): OmsOrderDetail["accounting"] {
|
|
15
|
+
if (!invoice) {
|
|
16
|
+
return {
|
|
17
|
+
status: "missing",
|
|
18
|
+
invoiceId: null,
|
|
19
|
+
invoiceRef: null,
|
|
20
|
+
providerKind: null,
|
|
21
|
+
providerInvoiceNumber: null,
|
|
22
|
+
fiscalStatus: null,
|
|
23
|
+
outboxStatus: null,
|
|
24
|
+
outboxAttemptCount: null,
|
|
25
|
+
outboxNextAttemptAt: null,
|
|
26
|
+
outboxLastError: null,
|
|
27
|
+
recoveryGuidance: "not_requested",
|
|
28
|
+
updatedAt: null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const outbox = selectAccountingOutbox(invoice.id, outboxRows);
|
|
32
|
+
return {
|
|
33
|
+
status: outbox?.status === "failed" ? "outbox_failed" : normalizeAccountingStatus(invoice.status, projections?.additionalAccountingStatuses),
|
|
34
|
+
invoiceId: invoice.id,
|
|
35
|
+
invoiceRef: invoice.invoice_ref,
|
|
36
|
+
providerKind: invoice.provider_kind,
|
|
37
|
+
providerInvoiceNumber: invoice.provider_invoice_number,
|
|
38
|
+
fiscalStatus: invoice.fiscal_status,
|
|
39
|
+
outboxStatus: outbox?.status ?? null,
|
|
40
|
+
outboxAttemptCount: outbox?.attempt_count ?? null,
|
|
41
|
+
outboxNextAttemptAt: outbox?.next_attempt_at ?? null,
|
|
42
|
+
outboxLastError: sanitizeAccountingLastError(outbox?.last_error),
|
|
43
|
+
recoveryGuidance: accountingRecoveryGuidance(outbox?.status ?? null, invoice.status),
|
|
44
|
+
updatedAt: invoice.updated_at,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function selectAccountingOutbox(
|
|
49
|
+
invoiceId: string,
|
|
50
|
+
outboxRows: OmsAccountingOutboxRow[],
|
|
51
|
+
): OmsAccountingOutboxRow | null {
|
|
52
|
+
return outboxRows
|
|
53
|
+
.filter((row) => row.invoice_id === invoiceId)
|
|
54
|
+
.sort(compareAccountingOutboxRows)[0] ?? null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function compareAccountingOutboxRows(a: OmsAccountingOutboxRow, b: OmsAccountingOutboxRow): number {
|
|
58
|
+
const priority = outboxStatusPriority(a.status) - outboxStatusPriority(b.status);
|
|
59
|
+
if (priority !== 0) return priority;
|
|
60
|
+
const aCreatedAt = timestampOrNull(a.created_at);
|
|
61
|
+
const bCreatedAt = timestampOrNull(b.created_at);
|
|
62
|
+
if (aCreatedAt !== null && bCreatedAt !== null && aCreatedAt !== bCreatedAt) {
|
|
63
|
+
return bCreatedAt - aCreatedAt;
|
|
64
|
+
}
|
|
65
|
+
if (aCreatedAt !== null && bCreatedAt === null) return -1;
|
|
66
|
+
if (aCreatedAt === null && bCreatedAt !== null) return 1;
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function timestampOrNull(value: string | null | undefined): number | null {
|
|
71
|
+
if (!value) return null;
|
|
72
|
+
const timestamp = Date.parse(value);
|
|
73
|
+
return Number.isFinite(timestamp) ? timestamp : null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function outboxStatusPriority(status: string): number {
|
|
77
|
+
if (status === "failed") return 0;
|
|
78
|
+
if (status === "processing") return 1;
|
|
79
|
+
if (status === "pending" || status === "queued") return 2;
|
|
80
|
+
if (status === "succeeded") return 3;
|
|
81
|
+
if (status === "cancelled") return 4;
|
|
82
|
+
return 5;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function accountingRecoveryGuidance(
|
|
86
|
+
outboxStatus: string | null,
|
|
87
|
+
invoiceStatus: string | null = null,
|
|
88
|
+
): OmsAccountingRecoveryGuidance {
|
|
89
|
+
if (outboxStatus === "failed") return "review_and_retry";
|
|
90
|
+
if (outboxStatus === "pending" || outboxStatus === "processing" || outboxStatus === "queued") {
|
|
91
|
+
return "wait_for_retry";
|
|
92
|
+
}
|
|
93
|
+
if (invoiceStatus === "blocked" || invoiceStatus === "rejected") return "review_and_retry";
|
|
94
|
+
if (invoiceStatus === "issued" || invoiceStatus === "accepted" || invoiceStatus === "corrected" || invoiceStatus === "voided") {
|
|
95
|
+
return "none";
|
|
96
|
+
}
|
|
97
|
+
return outboxStatus ? "none" : "not_requested";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function sanitizeAccountingLastError(value: unknown) {
|
|
101
|
+
if (!isRecord(value)) return null;
|
|
102
|
+
const code =
|
|
103
|
+
readSafeText(value, "code", 80) ??
|
|
104
|
+
readSafeText(value, "errorCode", 80) ??
|
|
105
|
+
readSafeText(value, "reason", 80) ??
|
|
106
|
+
readSafeText(value, "type", 80);
|
|
107
|
+
const message =
|
|
108
|
+
readSafeText(value, "operatorMessage", 240) ??
|
|
109
|
+
readSafeText(value, "message", 240);
|
|
110
|
+
const retryable = typeof value.retryable === "boolean" ? value.retryable : null;
|
|
111
|
+
if (!code && !message && retryable === null) return null;
|
|
112
|
+
return { code, message, retryable };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function readSafeText(record: Record<string, unknown>, key: string, maxLength: number): string | null {
|
|
116
|
+
const value = record[key];
|
|
117
|
+
if (typeof value !== "string") return null;
|
|
118
|
+
const normalized = redactSensitiveText(value.trim().replace(/\s+/g, " "));
|
|
119
|
+
return normalized ? normalized.slice(0, maxLength) : null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function redactSensitiveText(value: string): string {
|
|
123
|
+
return value
|
|
124
|
+
.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, "[redacted-email]")
|
|
125
|
+
.replace(/\b(?:bearer|token|secret|api[_-]?key|authorization)\s*[:=]?\s+[A-Za-z0-9._~+/=-]{8,}/gi, "[redacted-secret]");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
129
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function normalizeAccountingStatus(status: string, additional: readonly string[] = []): OmsAccountingStatus {
|
|
133
|
+
const valid: OmsAccountingStatus[] = ["draft", "issue_requested", "blocked", "issued", "accepted", "rejected", "correction_requested", "corrected", "voided"];
|
|
134
|
+
return [...valid, ...additional].includes(status as OmsAccountingStatus) ? (status as OmsAccountingStatus) : "missing";
|
|
135
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OmsOrderDetail } from "../oms/omsContracts.js";
|
|
2
|
+
|
|
3
|
+
export function enrichBillingWithInvoiceBuyer(
|
|
4
|
+
billing: OmsOrderDetail["billingAddress"],
|
|
5
|
+
orderMetadata: Record<string, unknown> | null,
|
|
6
|
+
): OmsOrderDetail["billingAddress"] {
|
|
7
|
+
if (!billing) return billing;
|
|
8
|
+
const snapshot =
|
|
9
|
+
orderMetadata && typeof orderMetadata === "object"
|
|
10
|
+
? (orderMetadata as { invoiceBuyerSnapshot?: unknown }).invoiceBuyerSnapshot
|
|
11
|
+
: null;
|
|
12
|
+
if (!snapshot || typeof snapshot !== "object") return billing;
|
|
13
|
+
const buyer = snapshot as { companyName?: unknown; taxId?: unknown };
|
|
14
|
+
const companyName =
|
|
15
|
+
billing.companyName ?? (typeof buyer.companyName === "string" && buyer.companyName.trim() ? buyer.companyName : null);
|
|
16
|
+
const taxId =
|
|
17
|
+
billing.taxId ?? (typeof buyer.taxId === "string" && buyer.taxId.trim() ? buyer.taxId : null);
|
|
18
|
+
if (companyName === billing.companyName && taxId === billing.taxId) return billing;
|
|
19
|
+
return { ...billing, companyName, taxId };
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OmsCurrencyPolicy } from "../contracts/omsTypes.js";
|
|
2
|
+
export type { OmsCurrencyPolicy } from "../contracts/omsTypes.js";
|
|
3
|
+
/** Settlement policy is supplied by the host; the neutral default checks format only. */
|
|
4
|
+
|
|
5
|
+
export const neutralOmsCurrencyPolicy: OmsCurrencyPolicy = {
|
|
6
|
+
defaultCurrency: "XXX",
|
|
7
|
+
accepts: currency => /^[A-Z]{3}$/.test(currency),
|
|
8
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { OmsFulfillmentProviderStockCurrentRow,OmsInboundProviderEventRow } from "../contracts/omsTypes.js";
|
|
2
|
+
import type { OmsOrderDetail } from "../oms/omsContracts.js";
|
|
3
|
+
import {
|
|
4
|
+
parseTimestampOrZero,
|
|
5
|
+
type OmsProviderAttemptRow,
|
|
6
|
+
type OmsProviderDispatchRefRow,
|
|
7
|
+
type OmsProviderStatusEvidenceRow,
|
|
8
|
+
} from "./omsFulfillmentSummary.js";
|
|
9
|
+
import type { OmsReadModelProjections } from "./omsReadModelProjections.js";
|
|
10
|
+
import type { OmsCommunicationDeliveryRow,OmsInventoryReservationRow } from "./omsReadModelRows.js";
|
|
11
|
+
export type { OmsFulfillmentProviderStockCurrentRow,OmsInboundProviderEventRow } from "../contracts/omsTypes.js";
|
|
12
|
+
|
|
13
|
+
type Debug = OmsOrderDetail["fulfillmentDebug"];
|
|
14
|
+
type Step = Debug["steps"][number];
|
|
15
|
+
|
|
16
|
+
export function buildOmsFulfillmentDebug(input: {
|
|
17
|
+
projections?: OmsReadModelProjections;
|
|
18
|
+
paymentStatus: OmsOrderDetail["paymentStatus"];
|
|
19
|
+
inventory: OmsOrderDetail["inventory"];
|
|
20
|
+
fulfillment: OmsOrderDetail["fulfillment"];
|
|
21
|
+
reservations: OmsInventoryReservationRow[];
|
|
22
|
+
communicationDeliveries: OmsCommunicationDeliveryRow[];
|
|
23
|
+
providerAttempts: OmsProviderAttemptRow[];
|
|
24
|
+
providerDispatchRefs: OmsProviderDispatchRefRow[];
|
|
25
|
+
providerStatusEvidence: OmsProviderStatusEvidenceRow[];
|
|
26
|
+
inboundProviderEvents: OmsInboundProviderEventRow[];
|
|
27
|
+
providerStockCurrent?: OmsFulfillmentProviderStockCurrentRow[];
|
|
28
|
+
}): Debug {
|
|
29
|
+
const latestDispatch = newest(input.providerDispatchRefs, (row) => row.updated_at ?? row.created_at);
|
|
30
|
+
const latestAttempt = newest(input.providerAttempts, (row) => row.created_at);
|
|
31
|
+
const latestProvider = newest(input.providerStatusEvidence, (row) => row.occurred_at ?? row.created_at);
|
|
32
|
+
const latestInbound = newest(input.inboundProviderEvents, (row) => row.processed_at ?? row.created_at);
|
|
33
|
+
const dispatchedMail = latestMail(input.communicationDeliveries, "commerce-shipment-dispatched");
|
|
34
|
+
const providerProblem = latestInbound?.processing_status === "ignored" || latestInbound?.processing_status === "failed" ||
|
|
35
|
+
Boolean(latestDispatch?.error) || Boolean(latestAttempt?.error) || ["failed", "error"].includes(latestAttempt?.status ?? "");
|
|
36
|
+
const shippedWithoutTracking = Boolean(latestProvider && ["shipped", "delivered"].includes(latestProvider.provider_status ?? "")) &&
|
|
37
|
+
input.fulfillment.trackingReferences.length === 0;
|
|
38
|
+
const latestProviderStock = newest(input.providerStockCurrent ?? [], (row) => row.last_synced_at);
|
|
39
|
+
const providerStockStale = latestProviderStock ? Date.parse(latestProviderStock.stale_after) <= Date.now() : false;
|
|
40
|
+
|
|
41
|
+
const steps: Step[] = [
|
|
42
|
+
step("payment", input.paymentStatus === "succeeded" ? "ok" : "blocked", "Payment", input.paymentStatus),
|
|
43
|
+
step("stock", ["reserved", "consumed"].includes(input.inventory.status) ? "ok" : "missing", "Stock", input.inventory.status, {
|
|
44
|
+
details: input.reservations.map((row) => `${row.status}:${row.quantity}`),
|
|
45
|
+
evidenceAt: input.inventory.expiresAt,
|
|
46
|
+
}),
|
|
47
|
+
step(
|
|
48
|
+
"provider_stock",
|
|
49
|
+
providerStockStatus(Boolean(input.projections?.usesExternalStock?.(input.fulfillment.providerKind)), latestProviderStock, providerStockStale),
|
|
50
|
+
"Provider stock",
|
|
51
|
+
latestProviderStock ? `${latestProviderStock.provider_kind}:${latestProviderStock.sku}` : null,
|
|
52
|
+
{
|
|
53
|
+
details: latestProviderStock
|
|
54
|
+
? [
|
|
55
|
+
`forSale ${latestProviderStock.provider_for_sale_quantity}`,
|
|
56
|
+
`total ${latestProviderStock.provider_total_quantity}`,
|
|
57
|
+
`authority ${input.projections?.usesExternalStock?.(input.fulfillment.providerKind) ? "external_stock_master" : "local_atp"}`,
|
|
58
|
+
]
|
|
59
|
+
: [],
|
|
60
|
+
evidenceAt: latestProviderStock?.last_synced_at ?? null,
|
|
61
|
+
},
|
|
62
|
+
),
|
|
63
|
+
step("fulfillment", input.fulfillment.fulfillmentOrderId ? "ok" : "missing", "Fulfillment order", input.fulfillment.status),
|
|
64
|
+
step("dispatch", latestDispatch ? statusFromDispatch(latestDispatch) : "pending", input.projections?.dispatchStepLabel ?? "Provider dispatch", latestDispatch?.status ?? null, {
|
|
65
|
+
details: compact([latestDispatch?.provider_order_id ? `providerOrderId ${latestDispatch.provider_order_id}` : null, latestAttempt?.status ? `attempt ${latestAttempt.status}` : null]),
|
|
66
|
+
evidenceAt: latestDispatch?.updated_at ?? latestDispatch?.created_at ?? null,
|
|
67
|
+
}),
|
|
68
|
+
step("provider", providerProblem ? "warning" : latestProvider ? "ok" : "pending", "Provider evidence", latestProvider?.provider_status ?? latestInbound?.processing_status ?? null, {
|
|
69
|
+
details: compact([latestProvider?.provider_sub_status, latestInbound?.event_type, latestAttempt?.status ? `attempt ${latestAttempt.status}` : null, errorSummary(latestInbound?.error), errorSummary(latestAttempt?.error)]),
|
|
70
|
+
evidenceAt: latestProvider?.occurred_at ?? latestProvider?.created_at ?? latestInbound?.created_at ?? null,
|
|
71
|
+
}),
|
|
72
|
+
step("tracking", shippedWithoutTracking ? "missing" : input.fulfillment.trackingReferences.length > 0 ? "ok" : "pending", "Tracking refs", input.fulfillment.providerTrackingId, {
|
|
73
|
+
details: input.fulfillment.trackingReferences.map((ref) => compact([ref.trackingNumber, ref.carrierKind, ref.service]).join(" / ")),
|
|
74
|
+
evidenceAt: input.fulfillment.trackingReferences[0]?.updatedAt ?? null,
|
|
75
|
+
}),
|
|
76
|
+
step("communication", mailStatus(dispatchedMail), "Customer e-mail", dispatchedMail?.status ?? null, {
|
|
77
|
+
details: dispatchedMail ? compact([dispatchedMail.template_slug, dispatchedMail.last_error_code]) : [],
|
|
78
|
+
evidenceAt: dispatchedMail?.updated_at ?? dispatchedMail?.created_at ?? null,
|
|
79
|
+
}),
|
|
80
|
+
];
|
|
81
|
+
const nextAction = chooseNextAction({ input, latestDispatch, providerProblem, shippedWithoutTracking });
|
|
82
|
+
const blockers = steps.filter((entry) => entry.status === "blocked" || entry.status === "missing" || entry.status === "warning").map((entry) => entry.label);
|
|
83
|
+
return {
|
|
84
|
+
summary: input.projections?.debugSummary?.(nextAction) ?? summaryFor(nextAction),
|
|
85
|
+
severity: blockers.length ? "action_required" : steps.some((entry) => entry.status === "pending") ? "watch" : "ok",
|
|
86
|
+
nextAction,
|
|
87
|
+
blockers,
|
|
88
|
+
steps,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function chooseNextAction(input: {
|
|
93
|
+
input: Parameters<typeof buildOmsFulfillmentDebug>[0];
|
|
94
|
+
latestDispatch: OmsProviderDispatchRefRow | null;
|
|
95
|
+
providerProblem: boolean;
|
|
96
|
+
shippedWithoutTracking: boolean;
|
|
97
|
+
}): Debug["nextAction"] {
|
|
98
|
+
if (input.input.paymentStatus !== "succeeded") return "review_payment";
|
|
99
|
+
if (!["reserved", "consumed"].includes(input.input.inventory.status)) return "review_stock";
|
|
100
|
+
const latestProviderStock = newest(input.input.providerStockCurrent ?? [], (row) => row.last_synced_at);
|
|
101
|
+
if (input.input.projections?.usesExternalStock?.(input.input.fulfillment.providerKind) && !latestProviderStock) return "review_stock";
|
|
102
|
+
if (latestProviderStock && Date.parse(latestProviderStock.stale_after) <= Date.now()) return "review_stock";
|
|
103
|
+
if (!input.input.fulfillment.fulfillmentOrderId) return "create_fulfillment";
|
|
104
|
+
if (input.providerProblem) return "review_provider";
|
|
105
|
+
if (!input.latestDispatch && input.input.projections?.usesExternalStock?.(input.input.fulfillment.providerKind)) return "retry_dispatch";
|
|
106
|
+
if (input.shippedWithoutTracking) return "reconcile";
|
|
107
|
+
return "wait";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function providerStockStatus(
|
|
111
|
+
usesExternalStock: boolean,
|
|
112
|
+
stock: OmsFulfillmentProviderStockCurrentRow | null,
|
|
113
|
+
stale: boolean,
|
|
114
|
+
): Step["status"] {
|
|
115
|
+
if (!usesExternalStock) return "ok";
|
|
116
|
+
if (!stock) return "missing";
|
|
117
|
+
return stale ? "warning" : "ok";
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function step(key: Step["key"], status: Step["status"], label: string, value: string | null | undefined, extra: Partial<Step> = {}): Step {
|
|
121
|
+
return { key, status, label, value: value ?? null, evidenceAt: extra.evidenceAt ?? null, details: extra.details ?? [] };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function statusFromDispatch(row: OmsProviderDispatchRefRow): Step["status"] {
|
|
125
|
+
if (row.error || row.status === "failed") return "warning";
|
|
126
|
+
return row.status ? "ok" : "pending";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function mailStatus(row: OmsCommunicationDeliveryRow | null): Step["status"] {
|
|
130
|
+
if (!row) return "pending";
|
|
131
|
+
if (["bounced", "complained", "missed", "blocked", "delivery_delayed"].includes(row.status)) return "warning";
|
|
132
|
+
if (["sent", "delivered"].includes(row.status)) return "ok";
|
|
133
|
+
return "pending";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function latestMail(rows: OmsCommunicationDeliveryRow[], slug: string): OmsCommunicationDeliveryRow | null {
|
|
137
|
+
return newest(rows.filter((row) => row.template_slug === slug || row.purpose === "shipment_dispatched"), (row) => row.updated_at ?? row.created_at);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function newest<T>(rows: T[], time: (row: T) => string | null | undefined): T | null {
|
|
141
|
+
return [...rows].sort((a, b) => parseTimestampOrZero(time(b)) - parseTimestampOrZero(time(a)))[0] ?? null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function summaryFor(action: Debug["nextAction"]): string {
|
|
145
|
+
return { wait: "Monitor the next event.", create_fulfillment: "Create a fulfillment order.", retry_dispatch: "Review or retry provider dispatch.", reconcile: "Reconcile tracking and status.", review_payment: "Review payment first.", review_stock: "Review stock reservations first.", review_provider: "Review provider evidence.", contact_support: "Contact technical support." }[action];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function errorSummary(value: unknown): string | null {
|
|
149
|
+
if (!value) return null;
|
|
150
|
+
if (typeof value === "string") return value;
|
|
151
|
+
if (typeof value === "object" && "reason" in value && typeof value.reason === "string") return value.reason;
|
|
152
|
+
return "error_present";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function compact(values: Array<string | null | undefined>): string[] {
|
|
156
|
+
return values.filter((value): value is string => Boolean(value && value.trim()));
|
|
157
|
+
}
|