@openlup/platform 0.20.0 → 0.22.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 +272 -278
- package/README.md +195 -6
- package/dist/composition/composeBundle.d.ts +13 -0
- package/dist/composition/composeBundle.js +4 -0
- package/dist/composition/fulfillmentContribution.d.ts +21 -0
- package/dist/composition/fulfillmentContribution.js +19 -0
- package/dist/composition/index.d.ts +1 -0
- package/dist/composition/index.js +2 -0
- package/dist/fulfillment/adapterConformance.d.ts +3 -0
- package/dist/fulfillment/adapterConformance.js +223 -0
- package/dist/fulfillment/bindings.d.ts +3 -0
- package/dist/fulfillment/bindings.js +29 -0
- package/dist/fulfillment/commerceFulfillmentHandlers.d.ts +29 -0
- package/dist/fulfillment/commerceFulfillmentHandlers.js +184 -0
- package/dist/fulfillment/commerceFulfillmentReadModel.d.ts +86 -0
- package/dist/fulfillment/commerceFulfillmentReadModel.js +131 -0
- package/dist/fulfillment/contracts/alignment.d.ts +25 -0
- package/dist/fulfillment/contracts/alignment.js +1 -0
- package/dist/fulfillment/contracts/bindings.d.ts +51 -0
- package/dist/fulfillment/contracts/bindings.js +1 -0
- package/dist/fulfillment/contracts/capabilities.d.ts +29 -0
- package/dist/fulfillment/contracts/capabilities.js +1 -0
- package/dist/fulfillment/contracts/conformance.d.ts +93 -0
- package/dist/fulfillment/contracts/conformance.js +1 -0
- package/dist/fulfillment/contracts/customerAlignment.d.ts +6 -0
- package/dist/fulfillment/contracts/customerAlignment.js +1 -0
- package/dist/fulfillment/contracts/dispatch.d.ts +105 -0
- package/dist/fulfillment/contracts/dispatch.js +1 -0
- package/dist/fulfillment/contracts/index.d.ts +18 -0
- package/dist/fulfillment/contracts/index.js +1 -0
- package/dist/fulfillment/contracts/label.d.ts +35 -0
- package/dist/fulfillment/contracts/label.js +1 -0
- package/dist/fulfillment/contracts/nativeUnsupported.d.ts +6 -0
- package/dist/fulfillment/contracts/nativeUnsupported.js +1 -0
- package/dist/fulfillment/contracts/observation.d.ts +52 -0
- package/dist/fulfillment/contracts/observation.js +1 -0
- package/dist/fulfillment/contracts/operator.d.ts +64 -0
- package/dist/fulfillment/contracts/operator.js +1 -0
- package/dist/fulfillment/contracts/read.d.ts +110 -0
- package/dist/fulfillment/contracts/read.js +1 -0
- package/dist/fulfillment/contracts/readback.d.ts +38 -0
- package/dist/fulfillment/contracts/readback.js +1 -0
- package/dist/fulfillment/contracts/replacement.d.ts +34 -0
- package/dist/fulfillment/contracts/replacement.js +1 -0
- package/dist/fulfillment/contracts/store.d.ts +86 -0
- package/dist/fulfillment/contracts/store.js +1 -0
- package/dist/fulfillment/contracts/sync.d.ts +170 -0
- package/dist/fulfillment/contracts/sync.js +1 -0
- package/dist/fulfillment/currentFulfillmentParcel.d.ts +2 -0
- package/dist/fulfillment/currentFulfillmentParcel.js +1 -0
- package/dist/fulfillment/delayReadModel.d.ts +11 -0
- package/dist/fulfillment/delayReadModel.js +45 -0
- package/dist/fulfillment/deliveryAlignmentReadModel.d.ts +4 -0
- package/dist/fulfillment/deliveryAlignmentReadModel.js +12 -0
- package/dist/fulfillment/dispatchProjection.d.ts +7 -0
- package/dist/fulfillment/dispatchProjection.js +18 -0
- package/dist/fulfillment/fulfillmentObservationEffects.d.ts +66 -0
- package/dist/fulfillment/fulfillmentObservationEffects.js +36 -0
- package/dist/fulfillment/handlerSchemas.d.ts +647 -0
- package/dist/fulfillment/handlerSchemas.js +213 -0
- package/dist/fulfillment/handlerSupport.d.ts +33 -0
- package/dist/fulfillment/handlerSupport.js +25 -0
- package/dist/fulfillment/index.d.ts +37 -0
- package/dist/fulfillment/index.js +37 -0
- package/dist/fulfillment/labelLifecycle.d.ts +24 -0
- package/dist/fulfillment/labelLifecycle.js +9 -0
- package/dist/fulfillment/lowStockEvidenceHandler.d.ts +36 -0
- package/dist/fulfillment/lowStockEvidenceHandler.js +46 -0
- package/dist/fulfillment/migrations.d.ts +27 -0
- package/dist/fulfillment/migrations.js +8 -0
- package/dist/fulfillment/nativeUnsupported.d.ts +10 -0
- package/dist/fulfillment/nativeUnsupported.js +18 -0
- package/dist/fulfillment/normalizedFulfillmentFacts.d.ts +2 -0
- package/dist/fulfillment/normalizedFulfillmentFacts.js +1 -0
- package/dist/fulfillment/observationProjection.d.ts +11 -0
- package/dist/fulfillment/observationProjection.js +37 -0
- package/dist/fulfillment/omnipack/capabilities.d.ts +3 -0
- package/dist/fulfillment/omnipack/capabilities.js +16 -0
- package/dist/fulfillment/omnipack/client.d.ts +37 -0
- package/dist/fulfillment/omnipack/client.js +162 -0
- package/dist/fulfillment/omnipack/index.d.ts +52 -0
- package/dist/fulfillment/omnipack/index.js +349 -0
- package/dist/fulfillment/omnipack/mappers.d.ts +73 -0
- package/dist/fulfillment/omnipack/mappers.js +177 -0
- package/dist/fulfillment/omnipack/observation.d.ts +21 -0
- package/dist/fulfillment/omnipack/observation.js +57 -0
- package/dist/fulfillment/omnipack/omnipackDispatchPayload.d.ts +36 -0
- package/dist/fulfillment/omnipack/omnipackDispatchPayload.js +63 -0
- package/dist/fulfillment/omnipack/omnipackOutboundOrderPayload.d.ts +83 -0
- package/dist/fulfillment/omnipack/omnipackOutboundOrderPayload.js +113 -0
- package/dist/fulfillment/omnipack/omnipackProductPackPayload.d.ts +11 -0
- package/dist/fulfillment/omnipack/omnipackProductPackPayload.js +38 -0
- package/dist/fulfillment/omnipack/omnipackProductPayload.d.ts +18 -0
- package/dist/fulfillment/omnipack/omnipackProductPayload.js +51 -0
- package/dist/fulfillment/omnipack/omnipackReconciliationPayload.d.ts +1 -0
- package/dist/fulfillment/omnipack/omnipackReconciliationPayload.js +3 -0
- package/dist/fulfillment/omnipack/omnipackStatusVocabulary.d.ts +4 -0
- package/dist/fulfillment/omnipack/omnipackStatusVocabulary.js +87 -0
- package/dist/fulfillment/omnipack/omnipackWebhookPayload.d.ts +9 -0
- package/dist/fulfillment/omnipack/omnipackWebhookPayload.js +76 -0
- package/dist/fulfillment/omnipack/productSyncMappers.d.ts +18 -0
- package/dist/fulfillment/omnipack/productSyncMappers.js +43 -0
- package/dist/fulfillment/omnipack/providerError.d.ts +25 -0
- package/dist/fulfillment/omnipack/providerError.js +47 -0
- package/dist/fulfillment/omnipack/trackingReferences.d.ts +16 -0
- package/dist/fulfillment/omnipack/trackingReferences.js +52 -0
- package/dist/fulfillment/paidFulfillmentRecovery.d.ts +67 -0
- package/dist/fulfillment/paidFulfillmentRecovery.js +154 -0
- package/dist/fulfillment/paidHandoff.d.ts +27 -0
- package/dist/fulfillment/paidHandoff.js +86 -0
- package/dist/fulfillment/paidHandoffPorts.d.ts +24 -0
- package/dist/fulfillment/paidHandoffPorts.js +3 -0
- package/dist/fulfillment/postgresDeliveryAlignment.d.ts +4 -0
- package/dist/fulfillment/postgresDeliveryAlignment.js +12 -0
- package/dist/fulfillment/postgresDispatchStore.d.ts +16 -0
- package/dist/fulfillment/postgresDispatchStore.js +44 -0
- package/dist/fulfillment/postgresEvidenceReadPort.d.ts +25 -0
- package/dist/fulfillment/postgresEvidenceReadPort.js +45 -0
- package/dist/fulfillment/postgresPaidFulfillmentRecovery.d.ts +25 -0
- package/dist/fulfillment/postgresPaidFulfillmentRecovery.js +26 -0
- package/dist/fulfillment/postgresPaidHandoffStore.d.ts +4 -0
- package/dist/fulfillment/postgresPaidHandoffStore.js +10 -0
- package/dist/fulfillment/postgresShipmentSpine.d.ts +63 -0
- package/dist/fulfillment/postgresShipmentSpine.js +232 -0
- package/dist/fulfillment/postgresStockSyncPort.d.ts +8 -0
- package/dist/fulfillment/postgresStockSyncPort.js +63 -0
- package/dist/fulfillment/productReconciliationEvidenceHandler.d.ts +36 -0
- package/dist/fulfillment/productReconciliationEvidenceHandler.js +50 -0
- package/dist/fulfillment/providerCapabilities.d.ts +9 -0
- package/dist/fulfillment/providerCapabilities.js +17 -0
- package/dist/fulfillment/providerCommandLedger.d.ts +143 -0
- package/dist/fulfillment/providerCommandLedger.js +14 -0
- package/dist/fulfillment/providerDispatchAcceptance.d.ts +26 -0
- package/dist/fulfillment/providerDispatchAcceptance.js +23 -0
- package/dist/fulfillment/providerDispatchError.d.ts +6 -0
- package/dist/fulfillment/providerDispatchError.js +5 -0
- package/dist/fulfillment/providerDispatchWorker.d.ts +31 -0
- package/dist/fulfillment/providerDispatchWorker.js +172 -0
- package/dist/fulfillment/providerProductSyncWorker.d.ts +28 -0
- package/dist/fulfillment/providerProductSyncWorker.js +122 -0
- package/dist/fulfillment/providerReconciliationError.d.ts +9 -0
- package/dist/fulfillment/providerReconciliationError.js +17 -0
- package/dist/fulfillment/providerReconciliationTerminalSkip.d.ts +2 -0
- package/dist/fulfillment/providerReconciliationTerminalSkip.js +6 -0
- package/dist/fulfillment/providerReconciliationTimestamp.d.ts +1 -0
- package/dist/fulfillment/providerReconciliationTimestamp.js +27 -0
- package/dist/fulfillment/providerReconciliationWorker.d.ts +82 -0
- package/dist/fulfillment/providerReconciliationWorker.js +151 -0
- package/dist/fulfillment/providerStockAvailability.d.ts +13 -0
- package/dist/fulfillment/providerStockAvailability.js +51 -0
- package/dist/fulfillment/providerStockSyncWorker.d.ts +37 -0
- package/dist/fulfillment/providerStockSyncWorker.js +186 -0
- package/dist/fulfillment/providerTrackingReferences.d.ts +15 -0
- package/dist/fulfillment/providerTrackingReferences.js +23 -0
- package/dist/fulfillment/replacementRefusals.d.ts +5 -0
- package/dist/fulfillment/replacementRefusals.js +38 -0
- package/dist/fulfillment/replacementShipmentHandler.d.ts +5 -0
- package/dist/fulfillment/replacementShipmentHandler.js +46 -0
- package/dist/fulfillment/schemaCapabilities.d.ts +13 -0
- package/dist/fulfillment/schemaCapabilities.js +7 -0
- package/dist/fulfillment/shipmentsOverviewHandler.d.ts +16 -0
- package/dist/fulfillment/shipmentsOverviewHandler.js +54 -0
- package/dist/fulfillment/statusMap.d.ts +2 -0
- package/dist/fulfillment/statusMap.js +1 -0
- package/dist/fulfillment/trackingProgress.d.ts +1 -0
- package/dist/fulfillment/trackingProgress.js +1 -0
- package/dist/fulfillment/verifiedIngress.d.ts +52 -0
- package/dist/fulfillment/verifiedIngress.js +66 -0
- package/dist/payments/adapterConformance.d.ts +8 -0
- package/dist/payments/adapterConformance.js +109 -0
- package/dist/payments/bindings.d.ts +3 -0
- package/dist/payments/bindings.js +17 -0
- package/dist/payments/checkoutActivePaymentActionResolver.d.ts +7 -0
- package/dist/payments/checkoutActivePaymentActionResolver.js +77 -0
- package/dist/payments/checkoutRecoveryPaymentResolver.d.ts +8 -0
- package/dist/payments/checkoutRecoveryPaymentResolver.js +87 -0
- package/dist/payments/contracts/adapter.d.ts +113 -0
- package/dist/payments/contracts/adapter.js +1 -0
- package/dist/payments/contracts/conformance.d.ts +155 -0
- package/dist/payments/contracts/conformance.js +1 -0
- package/dist/payments/contracts/evidence.d.ts +157 -0
- package/dist/payments/contracts/evidence.js +1 -0
- package/dist/payments/contracts/index.d.ts +10 -0
- package/dist/payments/contracts/index.js +1 -0
- package/dist/payments/contracts/preparedAttempt.d.ts +69 -0
- package/dist/payments/contracts/preparedAttempt.js +1 -0
- package/dist/payments/contracts/reconciliation.d.ts +303 -0
- package/dist/payments/contracts/reconciliation.js +1 -0
- package/dist/payments/contracts/repair.d.ts +92 -0
- package/dist/payments/contracts/repair.js +1 -0
- package/dist/payments/contracts/truth.d.ts +92 -0
- package/dist/payments/contracts/truth.js +1 -0
- package/dist/payments/eventConformanceRunner.d.ts +12 -0
- package/dist/payments/eventConformanceRunner.js +125 -0
- package/dist/payments/index.d.ts +16 -0
- package/dist/payments/index.js +16 -0
- package/dist/payments/paymentAttemptSilenceWindow.d.ts +10 -0
- package/dist/payments/paymentAttemptSilenceWindow.js +19 -0
- package/dist/payments/paymentMethodLifecycle.d.ts +11 -0
- package/dist/payments/paymentMethodLifecycle.js +37 -0
- package/dist/payments/paymentProviderReconciliationAbsenceReopen.d.ts +7 -0
- package/dist/payments/paymentProviderReconciliationAbsenceReopen.js +100 -0
- package/dist/payments/paymentProviderReconciliationEvidence.d.ts +36 -0
- package/dist/payments/paymentProviderReconciliationEvidence.js +91 -0
- package/dist/payments/paymentProviderReconciliationWorker.d.ts +4 -0
- package/dist/payments/paymentProviderReconciliationWorker.js +245 -0
- package/dist/payments/paymentTruth.d.ts +8 -0
- package/dist/payments/paymentTruth.js +125 -0
- package/dist/payments/paymentVerifyNowHandler.d.ts +27 -0
- package/dist/payments/paymentVerifyNowHandler.js +70 -0
- package/dist/payments/paymentVerifyNowService.d.ts +23 -0
- package/dist/payments/paymentVerifyNowService.js +93 -0
- package/dist/payments/paymentWebhookPostProcessing.d.ts +22 -0
- package/dist/payments/paymentWebhookPostProcessing.js +15 -0
- package/dist/payments/postgresPaymentTruth.d.ts +10 -0
- package/dist/payments/postgresPaymentTruth.js +126 -0
- package/dist/payments/preparedAttempt.d.ts +6 -0
- package/dist/payments/preparedAttempt.js +70 -0
- package/dist/payments/preparedAttemptFinalization.d.ts +5 -0
- package/dist/payments/preparedAttemptFinalization.js +12 -0
- package/dist/payments/schemaCapabilities.d.ts +10 -0
- package/dist/payments/schemaCapabilities.js +10 -0
- package/dist/payments/sql.d.ts +20 -0
- package/dist/payments/sql.js +6 -0
- package/dist/payments/stripe/classifyDecline.d.ts +46 -0
- package/dist/payments/stripe/classifyDecline.js +58 -0
- package/dist/payments/stripe/declineFailureHints.d.ts +46 -0
- package/dist/payments/stripe/declineFailureHints.js +87 -0
- package/dist/payments/stripe/donorContracts.d.ts +120 -0
- package/dist/payments/stripe/donorContracts.js +1 -0
- package/dist/payments/stripe/executionDecline.d.ts +53 -0
- package/dist/payments/stripe/executionDecline.js +107 -0
- package/dist/payments/stripe/index.d.ts +41 -0
- package/dist/payments/stripe/index.js +264 -0
- package/dist/payments/stripe/intentMapper.d.ts +26 -0
- package/dist/payments/stripe/intentMapper.js +51 -0
- package/dist/payments/stripe/methodFacts.d.ts +10 -0
- package/dist/payments/stripe/methodFacts.js +12 -0
- package/dist/payments/stripe/paymentFailureEvidence.d.ts +26 -0
- package/dist/payments/stripe/paymentFailureEvidence.js +33 -0
- package/dist/payments/stripe/stripeFailureEvidence.d.ts +41 -0
- package/dist/payments/stripe/stripeFailureEvidence.js +82 -0
- package/dist/payments/stripe/stripeIntentConfirmationEvidence.d.ts +28 -0
- package/dist/payments/stripe/stripeIntentConfirmationEvidence.js +32 -0
- package/dist/payments/stripe/stripePaymentReconciliationProvider.d.ts +35 -0
- package/dist/payments/stripe/stripePaymentReconciliationProvider.js +222 -0
- package/dist/payments/stripe/stripeRefundEvidence.d.ts +8 -0
- package/dist/payments/stripe/stripeRefundEvidence.js +17 -0
- package/dist/payments/stripe/stripeSandboxPaymentExecutionAdapter.d.ts +45 -0
- package/dist/payments/stripe/stripeSandboxPaymentExecutionAdapter.js +220 -0
- package/dist/payments/stripe/stripeWebhookNormalizer.d.ts +14 -0
- package/dist/payments/stripe/stripeWebhookNormalizer.js +243 -0
- package/dist/payments/stripe/webhookSignature.d.ts +14 -0
- package/dist/payments/stripe/webhookSignature.js +43 -0
- package/dist/payments/tpay/blikRecurringMapper.d.ts +37 -0
- package/dist/payments/tpay/blikRecurringMapper.js +24 -0
- package/dist/payments/tpay/capabilities.d.ts +3 -0
- package/dist/payments/tpay/capabilities.js +18 -0
- package/dist/payments/tpay/classifyDecline.d.ts +46 -0
- package/dist/payments/tpay/classifyDecline.js +58 -0
- package/dist/payments/tpay/declineFailureHints.d.ts +72 -0
- package/dist/payments/tpay/declineFailureHints.js +37 -0
- package/dist/payments/tpay/donorContracts.d.ts +140 -0
- package/dist/payments/tpay/donorContracts.js +1 -0
- package/dist/payments/tpay/index.d.ts +73 -0
- package/dist/payments/tpay/index.js +294 -0
- package/dist/payments/tpay/paymentFailureEvidence.d.ts +26 -0
- package/dist/payments/tpay/paymentFailureEvidence.js +33 -0
- package/dist/payments/tpay/preparedProviderAttempt.d.ts +22 -0
- package/dist/payments/tpay/preparedProviderAttempt.js +24 -0
- package/dist/payments/tpay/providerAttemptFailureDiagnostic.d.ts +3 -0
- package/dist/payments/tpay/providerAttemptFailureDiagnostic.js +95 -0
- package/dist/payments/tpay/tpayCreateTransactionInput.d.ts +25 -0
- package/dist/payments/tpay/tpayCreateTransactionInput.js +128 -0
- package/dist/payments/tpay/tpayDeclineEvidence.d.ts +126 -0
- package/dist/payments/tpay/tpayDeclineEvidence.js +177 -0
- package/dist/payments/tpay/tpayDispatchFailure.d.ts +60 -0
- package/dist/payments/tpay/tpayDispatchFailure.js +121 -0
- package/dist/payments/tpay/tpayFailureEvidence.d.ts +20 -0
- package/dist/payments/tpay/tpayFailureEvidence.js +61 -0
- package/dist/payments/tpay/tpayHttpClient.d.ts +52 -0
- package/dist/payments/tpay/tpayHttpClient.js +185 -0
- package/dist/payments/tpay/tpayHttpFailure.d.ts +57 -0
- package/dist/payments/tpay/tpayHttpFailure.js +143 -0
- package/dist/payments/tpay/tpayPaymentExecutionAdapter.d.ts +20 -0
- package/dist/payments/tpay/tpayPaymentExecutionAdapter.js +249 -0
- package/dist/payments/tpay/tpayPaymentReconciliationProvider.d.ts +5 -0
- package/dist/payments/tpay/tpayPaymentReconciliationProvider.js +244 -0
- package/dist/payments/tpay/tpayTransactionPayload.d.ts +120 -0
- package/dist/payments/tpay/tpayTransactionPayload.js +96 -0
- package/dist/payments/tpay/wallClockTime.d.ts +31 -0
- package/dist/payments/tpay/wallClockTime.js +57 -0
- package/dist/payments/tpay/webhookJwsVerifier.d.ts +17 -0
- package/dist/payments/tpay/webhookJwsVerifier.js +51 -0
- package/dist/payments/tpay/webhookNormalizer.d.ts +54 -0
- package/dist/payments/tpay/webhookNormalizer.js +200 -0
- package/dist/payments/verifiedEvidenceProjection.d.ts +12 -0
- package/dist/payments/verifiedEvidenceProjection.js +166 -0
- package/dist/payments/verifiedIngress.d.ts +119 -0
- package/dist/payments/verifiedIngress.js +220 -0
- package/package.json +37 -2
- package/release-gates.json +105 -3
- package/sql/20260808210000_fulfillment_shipment_rail.sql +810 -0
- package/sql/20260810180000_payment_settlement_rail.sql +574 -0
- package/sql/20260815150000_payment_truth_reconciliation.sql +479 -0
- package/sql/20260819150000_fulfillment_shipment_sequence.sql +98 -0
- package/sql/20260826100000_late_payment_shifts_the_subscription_cycle.sql +215 -0
- package/sql/20261022080000_fulfillment_command_ledger.sql +786 -0
- package/sql/20261022090000_fulfillment_delivery_alignment.sql +1106 -0
- package/src/composition/composeBundle.ts +13 -0
- package/src/composition/fulfillmentContribution.ts +28 -0
- package/src/composition/index.ts +2 -0
- package/src/fulfillment/adapterConformance.ts +195 -0
- package/src/fulfillment/bindings.ts +26 -0
- package/src/fulfillment/commerceFulfillmentHandlers.ts +263 -0
- package/src/fulfillment/commerceFulfillmentReadModel.ts +257 -0
- package/src/fulfillment/contracts/alignment.ts +13 -0
- package/src/fulfillment/contracts/bindings.ts +30 -0
- package/src/fulfillment/contracts/capabilities.ts +15 -0
- package/src/fulfillment/contracts/conformance.ts +61 -0
- package/src/fulfillment/contracts/customerAlignment.ts +4 -0
- package/src/fulfillment/contracts/dispatch.ts +58 -0
- package/src/fulfillment/contracts/index.ts +18 -0
- package/src/fulfillment/contracts/label.ts +9 -0
- package/src/fulfillment/contracts/nativeUnsupported.ts +6 -0
- package/src/fulfillment/contracts/observation.ts +18 -0
- package/src/fulfillment/contracts/operator.ts +31 -0
- package/src/fulfillment/contracts/read.ts +42 -0
- package/src/fulfillment/contracts/readback.ts +11 -0
- package/src/fulfillment/contracts/replacement.ts +15 -0
- package/src/fulfillment/contracts/store.ts +26 -0
- package/src/fulfillment/contracts/sync.ts +61 -0
- package/src/fulfillment/currentFulfillmentParcel.ts +2 -0
- package/src/fulfillment/delayReadModel.ts +60 -0
- package/src/fulfillment/deliveryAlignmentReadModel.ts +15 -0
- package/src/fulfillment/dispatchProjection.ts +20 -0
- package/src/fulfillment/fulfillmentObservationEffects.ts +86 -0
- package/src/fulfillment/handlerSchemas.ts +255 -0
- package/src/fulfillment/handlerSupport.ts +25 -0
- package/src/fulfillment/index.ts +38 -0
- package/src/fulfillment/labelLifecycle.ts +11 -0
- package/src/fulfillment/lowStockEvidenceHandler.ts +60 -0
- package/src/fulfillment/migrations.ts +8 -0
- package/src/fulfillment/nativeUnsupported.ts +23 -0
- package/src/fulfillment/normalizedFulfillmentFacts.ts +2 -0
- package/src/fulfillment/observationProjection.ts +41 -0
- package/src/fulfillment/omnipack/capabilities.ts +18 -0
- package/src/fulfillment/omnipack/client.ts +258 -0
- package/src/fulfillment/omnipack/index.ts +312 -0
- package/src/fulfillment/omnipack/mappers.ts +261 -0
- package/src/fulfillment/omnipack/observation.ts +61 -0
- package/src/fulfillment/omnipack/omnipackDispatchPayload.ts +93 -0
- package/src/fulfillment/omnipack/omnipackOutboundOrderPayload.ts +194 -0
- package/src/fulfillment/omnipack/omnipackProductPackPayload.ts +47 -0
- package/src/fulfillment/omnipack/omnipackProductPayload.ts +67 -0
- package/src/fulfillment/omnipack/omnipackReconciliationPayload.ts +7 -0
- package/src/fulfillment/omnipack/omnipackStatusVocabulary.ts +103 -0
- package/src/fulfillment/omnipack/omnipackWebhookPayload.ts +73 -0
- package/src/fulfillment/omnipack/productSyncMappers.ts +74 -0
- package/src/fulfillment/omnipack/providerError.ts +64 -0
- package/src/fulfillment/omnipack/trackingReferences.ts +77 -0
- package/src/fulfillment/paidFulfillmentRecovery.ts +252 -0
- package/src/fulfillment/paidHandoff.ts +122 -0
- package/src/fulfillment/paidHandoffPorts.ts +21 -0
- package/src/fulfillment/postgresDeliveryAlignment.ts +14 -0
- package/src/fulfillment/postgresDispatchStore.ts +55 -0
- package/src/fulfillment/postgresEvidenceReadPort.ts +59 -0
- package/src/fulfillment/postgresPaidFulfillmentRecovery.ts +29 -0
- package/src/fulfillment/postgresPaidHandoffStore.ts +11 -0
- package/src/fulfillment/postgresShipmentSpine.ts +321 -0
- package/src/fulfillment/postgresStockSyncPort.ts +65 -0
- package/src/fulfillment/productReconciliationEvidenceHandler.ts +64 -0
- package/src/fulfillment/providerCapabilities.ts +18 -0
- package/src/fulfillment/providerCommandLedger.ts +53 -0
- package/src/fulfillment/providerDispatchAcceptance.ts +31 -0
- package/src/fulfillment/providerDispatchError.ts +7 -0
- package/src/fulfillment/providerDispatchWorker.ts +131 -0
- package/src/fulfillment/providerProductSyncWorker.ts +154 -0
- package/src/fulfillment/providerReconciliationError.ts +20 -0
- package/src/fulfillment/providerReconciliationTerminalSkip.ts +8 -0
- package/src/fulfillment/providerReconciliationTimestamp.ts +34 -0
- package/src/fulfillment/providerReconciliationWorker.ts +150 -0
- package/src/fulfillment/providerStockAvailability.ts +60 -0
- package/src/fulfillment/providerStockSyncWorker.ts +222 -0
- package/src/fulfillment/providerTrackingReferences.ts +31 -0
- package/src/fulfillment/replacementRefusals.ts +43 -0
- package/src/fulfillment/replacementShipmentHandler.ts +47 -0
- package/src/fulfillment/schemaCapabilities.ts +7 -0
- package/src/fulfillment/shipmentsOverviewHandler.ts +73 -0
- package/src/fulfillment/statusMap.ts +2 -0
- package/src/fulfillment/trackingProgress.ts +1 -0
- package/src/fulfillment/verifiedIngress.ts +80 -0
- package/src/payments/adapterConformance.ts +118 -0
- package/src/payments/bindings.ts +17 -0
- package/src/payments/checkoutActivePaymentActionResolver.ts +97 -0
- package/src/payments/checkoutRecoveryPaymentResolver.ts +108 -0
- package/src/payments/contracts/adapter.ts +96 -0
- package/src/payments/contracts/conformance.ts +171 -0
- package/src/payments/contracts/evidence.ts +142 -0
- package/src/payments/contracts/index.ts +54 -0
- package/src/payments/contracts/preparedAttempt.ts +86 -0
- package/src/payments/contracts/reconciliation.ts +296 -0
- package/src/payments/contracts/repair.ts +95 -0
- package/src/payments/contracts/truth.ts +108 -0
- package/src/payments/eventConformanceRunner.ts +149 -0
- package/src/payments/index.ts +21 -0
- package/src/payments/paymentAttemptSilenceWindow.ts +26 -0
- package/src/payments/paymentMethodLifecycle.ts +50 -0
- package/src/payments/paymentProviderReconciliationAbsenceReopen.ts +130 -0
- package/src/payments/paymentProviderReconciliationEvidence.ts +117 -0
- package/src/payments/paymentProviderReconciliationWorker.ts +291 -0
- package/src/payments/paymentTruth.ts +131 -0
- package/src/payments/paymentVerifyNowHandler.ts +94 -0
- package/src/payments/paymentVerifyNowService.ts +125 -0
- package/src/payments/paymentWebhookPostProcessing.ts +36 -0
- package/src/payments/postgresPaymentTruth.ts +149 -0
- package/src/payments/preparedAttempt.ts +90 -0
- package/src/payments/preparedAttemptFinalization.ts +13 -0
- package/src/payments/schemaCapabilities.ts +10 -0
- package/src/payments/sql.ts +6 -0
- package/src/payments/stripe/classifyDecline.ts +62 -0
- package/src/payments/stripe/declineFailureHints.ts +89 -0
- package/src/payments/stripe/donorContracts.ts +87 -0
- package/src/payments/stripe/executionDecline.ts +126 -0
- package/src/payments/stripe/index.ts +265 -0
- package/src/payments/stripe/intentMapper.ts +58 -0
- package/src/payments/stripe/methodFacts.ts +21 -0
- package/src/payments/stripe/paymentFailureEvidence.ts +58 -0
- package/src/payments/stripe/stripeFailureEvidence.ts +115 -0
- package/src/payments/stripe/stripeIntentConfirmationEvidence.ts +34 -0
- package/src/payments/stripe/stripePaymentReconciliationProvider.ts +263 -0
- package/src/payments/stripe/stripeRefundEvidence.ts +19 -0
- package/src/payments/stripe/stripeSandboxPaymentExecutionAdapter.ts +283 -0
- package/src/payments/stripe/stripeWebhookNormalizer.ts +277 -0
- package/src/payments/stripe/webhookSignature.ts +55 -0
- package/src/payments/tpay/blikRecurringMapper.ts +42 -0
- package/src/payments/tpay/capabilities.ts +21 -0
- package/src/payments/tpay/classifyDecline.ts +62 -0
- package/src/payments/tpay/declineFailureHints.ts +90 -0
- package/src/payments/tpay/donorContracts.ts +104 -0
- package/src/payments/tpay/index.ts +293 -0
- package/src/payments/tpay/paymentFailureEvidence.ts +58 -0
- package/src/payments/tpay/preparedProviderAttempt.ts +38 -0
- package/src/payments/tpay/providerAttemptFailureDiagnostic.ts +99 -0
- package/src/payments/tpay/tpayCreateTransactionInput.ts +158 -0
- package/src/payments/tpay/tpayDeclineEvidence.ts +233 -0
- package/src/payments/tpay/tpayDispatchFailure.ts +186 -0
- package/src/payments/tpay/tpayFailureEvidence.ts +75 -0
- package/src/payments/tpay/tpayHttpClient.ts +290 -0
- package/src/payments/tpay/tpayHttpFailure.ts +186 -0
- package/src/payments/tpay/tpayPaymentExecutionAdapter.ts +297 -0
- package/src/payments/tpay/tpayPaymentReconciliationProvider.ts +285 -0
- package/src/payments/tpay/tpayTransactionPayload.ts +207 -0
- package/src/payments/tpay/wallClockTime.ts +57 -0
- package/src/payments/tpay/webhookJwsVerifier.ts +82 -0
- package/src/payments/tpay/webhookNormalizer.ts +279 -0
- package/src/payments/verifiedEvidenceProjection.ts +179 -0
- package/src/payments/verifiedIngress.ts +317 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { FulfillmentRefusal } from "./dispatch.js";
|
|
2
|
+
/** Collection identity never masquerades as a monotonic provider revision. */
|
|
3
|
+
interface SyncIdentity {
|
|
4
|
+
providerRef: string;
|
|
5
|
+
syncRunId: string;
|
|
6
|
+
collectedAt: string;
|
|
7
|
+
sourceRevision: string | null;
|
|
8
|
+
revisionSource: "provider" | "collection" | "unknown";
|
|
9
|
+
}
|
|
10
|
+
export interface StockSnapshot extends SyncIdentity {
|
|
11
|
+
skuRef: string;
|
|
12
|
+
quantityKind: "snapshot";
|
|
13
|
+
totalQuantity: number;
|
|
14
|
+
forSaleQuantity: number;
|
|
15
|
+
reservedOrUnavailableQuantity: number;
|
|
16
|
+
}
|
|
17
|
+
export interface StockMovement extends SyncIdentity {
|
|
18
|
+
skuRef: string;
|
|
19
|
+
quantityKind: "movement";
|
|
20
|
+
quantity: number;
|
|
21
|
+
occurredAt: string | null;
|
|
22
|
+
operationType: string | null;
|
|
23
|
+
documentRef: string | null;
|
|
24
|
+
lotRef: string | null;
|
|
25
|
+
expirationDate: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface SyncCursor {
|
|
28
|
+
status: "idle" | "running" | "succeeded" | "failed";
|
|
29
|
+
lastStockSyncedAt: string | null;
|
|
30
|
+
lastMovementOccurredAt: string | null;
|
|
31
|
+
/** Sanitized continuation only; no credentials, URLs or arbitrary provider payload. */
|
|
32
|
+
continuation: {
|
|
33
|
+
nextRef: string | null;
|
|
34
|
+
startLocalDate: string | null;
|
|
35
|
+
endLocalDate: string | null;
|
|
36
|
+
};
|
|
37
|
+
/** G15: successful sellable coverage gaps; legacy absent values read as []. */
|
|
38
|
+
coverageGapSkus?: readonly string[];
|
|
39
|
+
refusal: FulfillmentRefusal | null;
|
|
40
|
+
}
|
|
41
|
+
export interface LocalStock {
|
|
42
|
+
skuRef: string;
|
|
43
|
+
onHand: number;
|
|
44
|
+
reserved: number;
|
|
45
|
+
unavailable: number;
|
|
46
|
+
safetyStock: number;
|
|
47
|
+
}
|
|
48
|
+
type Threshold = "safety_stock" | "reservation_coverage" | "forecast" | "stale_sync";
|
|
49
|
+
type Conflict = "unknown_sku" | "ean_conflict" | "kind_quantity_conflict";
|
|
50
|
+
export interface FulfillmentStockSyncProvider {
|
|
51
|
+
getStock(): Promise<StockSnapshot[]>;
|
|
52
|
+
getStockMovements(input?: {
|
|
53
|
+
startLocalDate?: string;
|
|
54
|
+
endLocalDate?: string;
|
|
55
|
+
size?: number;
|
|
56
|
+
}): Promise<StockMovement[]>;
|
|
57
|
+
}
|
|
58
|
+
export interface FulfillmentStockSyncPort {
|
|
59
|
+
readCursor(): Promise<SyncCursor | null>;
|
|
60
|
+
/** G16: unaggregated lines at the worker clock; quantity retains the four local balances. */
|
|
61
|
+
readLocalInventoryStock(requestedAt: string): Promise<readonly {
|
|
62
|
+
skuRef: string;
|
|
63
|
+
quantity: Pick<LocalStock, "onHand" | "reserved" | "unavailable" | "safetyStock">;
|
|
64
|
+
fulfillable: boolean;
|
|
65
|
+
locationStatus: "active" | "inactive";
|
|
66
|
+
lotStatus: "available" | "quarantined" | "expired" | "recalled" | null;
|
|
67
|
+
expiresAt: string | null;
|
|
68
|
+
}[]>;
|
|
69
|
+
readSkuInventoryClasses(skus: string[]): Promise<Map<string, "sellable" | "packaging" | null>>;
|
|
70
|
+
readActiveReservations(skus: string[], requestedAt: string): Promise<Map<string, number>>;
|
|
71
|
+
recordCursor(input: SyncCursor): Promise<void>;
|
|
72
|
+
recordStockSnapshot(input: {
|
|
73
|
+
requestKey: string;
|
|
74
|
+
snapshot: StockSnapshot;
|
|
75
|
+
local: LocalStock;
|
|
76
|
+
mismatchKind: "none";
|
|
77
|
+
inventoryClass: "sellable" | "packaging" | null;
|
|
78
|
+
}): Promise<{
|
|
79
|
+
replayed: boolean;
|
|
80
|
+
readBack: boolean;
|
|
81
|
+
}>;
|
|
82
|
+
recordProviderStockCurrent(input: {
|
|
83
|
+
requestKey: string;
|
|
84
|
+
snapshot: StockSnapshot;
|
|
85
|
+
inventoryClass: "sellable" | "packaging" | null;
|
|
86
|
+
lastSyncedAt: string;
|
|
87
|
+
staleAfter: string;
|
|
88
|
+
}): Promise<{
|
|
89
|
+
replayed: boolean;
|
|
90
|
+
readBack: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
recordMovement(input: {
|
|
93
|
+
requestKey: string;
|
|
94
|
+
movement: StockMovement;
|
|
95
|
+
}): Promise<{
|
|
96
|
+
replayed: boolean;
|
|
97
|
+
readBack: boolean;
|
|
98
|
+
}>;
|
|
99
|
+
recordLowStockEvidence(input: {
|
|
100
|
+
requestKey: string;
|
|
101
|
+
skuRef: string;
|
|
102
|
+
thresholdKind: Exclude<Threshold, "forecast">;
|
|
103
|
+
severity: "info" | "warning" | "critical";
|
|
104
|
+
providerForSaleQuantity: number;
|
|
105
|
+
localAvailableQuantity: number;
|
|
106
|
+
syncRunId: string;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
replayed: boolean;
|
|
109
|
+
}>;
|
|
110
|
+
resolveLowStockEvidence(input: {
|
|
111
|
+
skuRef: string;
|
|
112
|
+
activeThresholdKinds: Threshold[];
|
|
113
|
+
syncRunId: string;
|
|
114
|
+
}): Promise<{
|
|
115
|
+
resolved: number;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
interface ProductPack {
|
|
119
|
+
ean: string;
|
|
120
|
+
quantity: number;
|
|
121
|
+
}
|
|
122
|
+
export interface FulfillmentProductSyncProvider {
|
|
123
|
+
/** null means skipped (no private push metadata), never a newly created local SKU. */
|
|
124
|
+
ensureProduct(sku: string): Promise<{
|
|
125
|
+
replayed: boolean;
|
|
126
|
+
} | null>;
|
|
127
|
+
getProductPacks(sku: string): Promise<ProductPack[]>;
|
|
128
|
+
addProductPack(sku: string, pack: ProductPack): Promise<void>;
|
|
129
|
+
listStockedSkus(): Promise<string[]>;
|
|
130
|
+
}
|
|
131
|
+
export interface FulfillmentProductSyncPort {
|
|
132
|
+
listLocalProductPacks(): Promise<{
|
|
133
|
+
sku: string;
|
|
134
|
+
packs: (ProductPack & {
|
|
135
|
+
kind: "unit" | "collective";
|
|
136
|
+
})[];
|
|
137
|
+
}[]>;
|
|
138
|
+
markPackSynced(input: {
|
|
139
|
+
sku: string;
|
|
140
|
+
ean: string;
|
|
141
|
+
}): Promise<void>;
|
|
142
|
+
upsertPulledPack(input: {
|
|
143
|
+
sku: string;
|
|
144
|
+
ean: string;
|
|
145
|
+
quantity: number;
|
|
146
|
+
kind: "unit" | "collective";
|
|
147
|
+
}): Promise<{
|
|
148
|
+
conflict: "none" | "local_locked_mismatch" | "ean_owned_by_other_sku" | "sku_not_found";
|
|
149
|
+
replayed: boolean;
|
|
150
|
+
}>;
|
|
151
|
+
recordReconciliationEvidence(input: {
|
|
152
|
+
requestKey: string;
|
|
153
|
+
sku: string;
|
|
154
|
+
ean: string | null;
|
|
155
|
+
conflictKind: Conflict;
|
|
156
|
+
providerQuantity: number;
|
|
157
|
+
identity: SyncIdentity;
|
|
158
|
+
refusal: FulfillmentRefusal | null;
|
|
159
|
+
}): Promise<{
|
|
160
|
+
replayed: boolean;
|
|
161
|
+
}>;
|
|
162
|
+
resolveReconciliationEvidence(input: {
|
|
163
|
+
sku: string;
|
|
164
|
+
activeConflictKinds: Conflict[];
|
|
165
|
+
syncRunId: string;
|
|
166
|
+
}): Promise<{
|
|
167
|
+
resolved: number;
|
|
168
|
+
}>;
|
|
169
|
+
}
|
|
170
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { parcelSequenceNo, compareParcelPrecedence, currentParcel, currentParcelFor, currentParcelPerOrder, currentParcelFirst, belongsToParcel, rowsForParcel } from "@openlup/core/fulfillment";
|
|
2
|
+
export type { FulfillmentParcelRow, ParcelAttributedRow } from "@openlup/core/fulfillment";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { parcelSequenceNo, compareParcelPrecedence, currentParcel, currentParcelFor, currentParcelPerOrder, currentParcelFirst, belongsToParcel, rowsForParcel } from "@openlup/core/fulfillment";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CustomerDeliveryAlignment, FulfillmentCustomerAlignmentRowsReader } from './contracts/customerAlignment.js';
|
|
2
|
+
import type { FulfillmentNativeUnsupported } from './contracts/nativeUnsupported.js';
|
|
3
|
+
export type DeliveryAlignmentRow = Record<string, unknown>;
|
|
4
|
+
export type DeliveryAlignmentRowsReader = FulfillmentCustomerAlignmentRowsReader;
|
|
5
|
+
/**
|
|
6
|
+
* Reads only customer-safe current cases. An aligned case remains current while
|
|
7
|
+
* its aligned schedule is still the subscription's next schedule; once a paid
|
|
8
|
+
* cycle advances `next_cycle_at`, the historical ledger row disappears from UI.
|
|
9
|
+
*/
|
|
10
|
+
export declare function readFulfillmentDelay(readRows: DeliveryAlignmentRowsReader | undefined, nextCycleAtBySubscription: ReadonlyMap<string, string | null>): Promise<Map<string, CustomerDeliveryAlignment> | FulfillmentNativeUnsupported>;
|
|
11
|
+
export declare function mapCurrentDeliveryAlignments(rows: DeliveryAlignmentRow[], nextCycleAtBySubscription: ReadonlyMap<string, string | null>): Map<string, CustomerDeliveryAlignment>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isNativeUnsupported } from './handlerSupport.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads only customer-safe current cases. An aligned case remains current while
|
|
4
|
+
* its aligned schedule is still the subscription's next schedule; once a paid
|
|
5
|
+
* cycle advances `next_cycle_at`, the historical ledger row disappears from UI.
|
|
6
|
+
*/
|
|
7
|
+
export async function readFulfillmentDelay(readRows, nextCycleAtBySubscription) {
|
|
8
|
+
const subscriptionIds = [...nextCycleAtBySubscription.keys()].filter(Boolean);
|
|
9
|
+
if (!readRows || subscriptionIds.length === 0)
|
|
10
|
+
return new Map();
|
|
11
|
+
const rows = await readRows(subscriptionIds);
|
|
12
|
+
if (isNativeUnsupported(rows))
|
|
13
|
+
return rows;
|
|
14
|
+
return mapCurrentDeliveryAlignments(rows, nextCycleAtBySubscription);
|
|
15
|
+
}
|
|
16
|
+
export function mapCurrentDeliveryAlignments(rows, nextCycleAtBySubscription) {
|
|
17
|
+
const result = new Map();
|
|
18
|
+
for (const row of rows) {
|
|
19
|
+
const subscriptionId = text(row.subscription_id);
|
|
20
|
+
if (!subscriptionId || result.has(subscriptionId))
|
|
21
|
+
continue;
|
|
22
|
+
const state = text(row.state);
|
|
23
|
+
if (state === "protected") {
|
|
24
|
+
result.set(subscriptionId, { state });
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (state === "aligned" && sameInstant(nullableText(row.aligned_next_cycle_at), nextCycleAtBySubscription.get(subscriptionId) ?? null)) {
|
|
28
|
+
result.set(subscriptionId, { state });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
function sameInstant(left, right) {
|
|
34
|
+
if (!left || !right)
|
|
35
|
+
return false;
|
|
36
|
+
const leftTime = new Date(left).getTime();
|
|
37
|
+
const rightTime = new Date(right).getTime();
|
|
38
|
+
return Number.isFinite(leftTime) && leftTime === rightTime;
|
|
39
|
+
}
|
|
40
|
+
function text(value) {
|
|
41
|
+
return typeof value === "string" ? value : "";
|
|
42
|
+
}
|
|
43
|
+
function nullableText(value) {
|
|
44
|
+
return typeof value === "string" && value ? value : null;
|
|
45
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DeliveryAlignmentPort } from './contracts/index.js';
|
|
2
|
+
import type { PgExecutor } from './postgresDispatchStore.js';
|
|
3
|
+
/** Server-authorized projection; database browser roles have no direct access. */
|
|
4
|
+
export declare function readDeliveryAlignment(db: PgExecutor, fulfillmentRef: string): ReturnType<DeliveryAlignmentPort['read']>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Server-authorized projection; database browser roles have no direct access. */
|
|
2
|
+
export async function readDeliveryAlignment(db, fulfillmentRef) {
|
|
3
|
+
const result = await db.query(`SELECT alignment.state, alignment.aligned_next_cycle_at
|
|
4
|
+
FROM public.fulfillment_shipments shipment
|
|
5
|
+
LEFT JOIN public.subscription_delivery_alignment_cases alignment ON alignment.predecessor_order_id=shipment.order_id
|
|
6
|
+
WHERE shipment.id=$1::uuid
|
|
7
|
+
ORDER BY (alignment.state IN ('protected','manual_review')) DESC, alignment.created_at ASC LIMIT 1`, [fulfillmentRef]);
|
|
8
|
+
const row = result.rows[0];
|
|
9
|
+
const date = row?.aligned_next_cycle_at;
|
|
10
|
+
return { disposition: row?.state === 'aligned' ? 'aligned' : row?.state === 'protected' ? 'outstanding' : 'manual_review',
|
|
11
|
+
nextCycleAt: date instanceof Date ? date.toISOString() : typeof date === 'string' ? date : null };
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DispatchEvidence, DispatchRecord, FulfillmentDispatchResult } from "./contracts/index.js";
|
|
2
|
+
/** Copy only the durable allowlist, including when an adapter object has extra runtime properties. */
|
|
3
|
+
export declare function dispatchEvidence(evidence: DispatchEvidence): DispatchEvidence;
|
|
4
|
+
export declare function dispatchResult(result: FulfillmentDispatchResult): FulfillmentDispatchResult;
|
|
5
|
+
export declare function acceptedProviderProof(record: DispatchRecord | null): record is DispatchRecord & {
|
|
6
|
+
externalRef: string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Copy only the durable allowlist, including when an adapter object has extra runtime properties. */
|
|
2
|
+
export function dispatchEvidence(evidence) {
|
|
3
|
+
return {
|
|
4
|
+
commandFingerprint: evidence.commandFingerprint,
|
|
5
|
+
contactRevision: { schemaVersion: evidence.contactRevision.schemaVersion, source: evidence.contactRevision.source, revision: evidence.contactRevision.revision },
|
|
6
|
+
providerRef: evidence.providerRef, carrierRef: evidence.carrierRef, serviceRef: evidence.serviceRef,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function dispatchResult(result) {
|
|
10
|
+
switch (result.kind) {
|
|
11
|
+
case "accepted": return { kind: "accepted", externalRef: result.externalRef, providerAttemptKey: result.providerAttemptKey, labelKey: result.labelKey, evidence: dispatchEvidence(result.evidence) };
|
|
12
|
+
case "not_dispatched": return { kind: "not_dispatched", effectMayHaveSucceeded: false, refusal: { reason: result.refusal.reason, phase: result.refusal.phase, retryable: result.refusal.retryable } };
|
|
13
|
+
case "unknown": return { kind: "unknown", effectMayHaveSucceeded: true, refusal: { reason: result.refusal.reason, phase: result.refusal.phase, retryable: result.refusal.retryable } };
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function acceptedProviderProof(record) {
|
|
17
|
+
return Boolean(record?.externalRef && (record.status === "created" || record.status === "uncertain"));
|
|
18
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { FulfillmentObservation } from "./contracts/index.js";
|
|
2
|
+
/** Ledger effects for an already accepted observation; acceptance and retry belong to the caller. */
|
|
3
|
+
interface FulfillmentObservationPort<TrackingStatus> {
|
|
4
|
+
markProviderStockConsumed(input: {
|
|
5
|
+
idempotencyKey: string;
|
|
6
|
+
fulfillmentOrderId: string;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
replayed: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
markHandedOver(input: {
|
|
11
|
+
idempotencyKey: string;
|
|
12
|
+
fulfillmentOrderId: string;
|
|
13
|
+
suppressDispatched: boolean;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
replayed: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
recordTrackingReference(input: {
|
|
18
|
+
idempotencyKey: string;
|
|
19
|
+
orderId: string;
|
|
20
|
+
fulfillmentOrderId: string;
|
|
21
|
+
trackingNumber: string;
|
|
22
|
+
trackingUrl: string | null;
|
|
23
|
+
carrierKind: string | null;
|
|
24
|
+
service: string | null;
|
|
25
|
+
status: TrackingStatus;
|
|
26
|
+
observation: FulfillmentObservation;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
replayed: boolean;
|
|
29
|
+
readBack: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
32
|
+
interface FulfillmentObservationTrackingReference {
|
|
33
|
+
trackingNumber: string;
|
|
34
|
+
trackingUrl?: string | null;
|
|
35
|
+
carrierKind?: string | null;
|
|
36
|
+
service?: string | null;
|
|
37
|
+
}
|
|
38
|
+
interface FulfillmentObservationInput<LocalStatus, TrackingStatus> {
|
|
39
|
+
port: FulfillmentObservationPort<TrackingStatus>;
|
|
40
|
+
localStatus: LocalStatus;
|
|
41
|
+
ids: {
|
|
42
|
+
orderId: string;
|
|
43
|
+
fulfillmentOrderId: string;
|
|
44
|
+
};
|
|
45
|
+
observation: FulfillmentObservation;
|
|
46
|
+
trackingRefs: readonly FulfillmentObservationTrackingReference[];
|
|
47
|
+
stockIdempotencyKey: string;
|
|
48
|
+
handoffIdempotencyKey: string;
|
|
49
|
+
trackingIdempotencyKey: (trackingNumber: string) => string;
|
|
50
|
+
issueAccountingInvoice?: () => Promise<void>;
|
|
51
|
+
onReplayed?: () => void;
|
|
52
|
+
onTrackingRecorded?: (result: {
|
|
53
|
+
replayed: boolean;
|
|
54
|
+
readBack: boolean;
|
|
55
|
+
}) => void;
|
|
56
|
+
}
|
|
57
|
+
/** Pure status decisions/projection; the mechanism owns every effect and await. */
|
|
58
|
+
interface FulfillmentObservationStatusPolicy<LocalStatus, TrackingStatus> {
|
|
59
|
+
consumesStock(status: LocalStatus): boolean;
|
|
60
|
+
handsOver(status: LocalStatus): boolean;
|
|
61
|
+
suppressDispatched(status: LocalStatus): boolean;
|
|
62
|
+
trackingStatus(status: LocalStatus): TrackingStatus;
|
|
63
|
+
}
|
|
64
|
+
/** Stock → durable handover → every tracking reference → optional invoice. No catches or retries. */
|
|
65
|
+
export declare function applyFulfillmentObservationEffects<LocalStatus, TrackingStatus>(input: FulfillmentObservationInput<LocalStatus, TrackingStatus>, policy: FulfillmentObservationStatusPolicy<LocalStatus, TrackingStatus>): Promise<void>;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Stock → durable handover → every tracking reference → optional invoice. No catches or retries. */
|
|
2
|
+
export async function applyFulfillmentObservationEffects(input, policy) {
|
|
3
|
+
const { fulfillmentOrderId, orderId } = input.ids;
|
|
4
|
+
if (policy.consumesStock(input.localStatus)) {
|
|
5
|
+
const consumed = await input.port.markProviderStockConsumed({
|
|
6
|
+
idempotencyKey: input.stockIdempotencyKey,
|
|
7
|
+
fulfillmentOrderId,
|
|
8
|
+
});
|
|
9
|
+
if (consumed.replayed)
|
|
10
|
+
input.onReplayed?.();
|
|
11
|
+
}
|
|
12
|
+
if (!policy.handsOver(input.localStatus))
|
|
13
|
+
return;
|
|
14
|
+
const handoff = await input.port.markHandedOver({
|
|
15
|
+
idempotencyKey: input.handoffIdempotencyKey,
|
|
16
|
+
fulfillmentOrderId,
|
|
17
|
+
suppressDispatched: policy.suppressDispatched(input.localStatus),
|
|
18
|
+
});
|
|
19
|
+
if (handoff.replayed)
|
|
20
|
+
input.onReplayed?.();
|
|
21
|
+
for (const trackingRef of input.trackingRefs) {
|
|
22
|
+
const tracking = await input.port.recordTrackingReference({
|
|
23
|
+
idempotencyKey: input.trackingIdempotencyKey(trackingRef.trackingNumber),
|
|
24
|
+
orderId,
|
|
25
|
+
fulfillmentOrderId,
|
|
26
|
+
trackingNumber: trackingRef.trackingNumber,
|
|
27
|
+
trackingUrl: trackingRef.trackingUrl ?? null,
|
|
28
|
+
carrierKind: trackingRef.carrierKind ?? null,
|
|
29
|
+
service: trackingRef.service ?? null,
|
|
30
|
+
status: policy.trackingStatus(input.localStatus),
|
|
31
|
+
observation: input.observation,
|
|
32
|
+
});
|
|
33
|
+
input.onTrackingRecorded?.(tracking);
|
|
34
|
+
}
|
|
35
|
+
await input.issueAccountingInvoice?.();
|
|
36
|
+
}
|