@openlup/platform 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +432 -146
- package/README.md +82 -589
- package/dist/composition/composeBundle.d.ts +7 -0
- package/dist/composition/composeBundle.js +2 -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 +1 -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 +95 -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 +143 -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 +72 -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 +59 -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 +89 -0
- package/dist/fulfillment/contracts/store.js +1 -0
- package/dist/fulfillment/contracts/sync.d.ts +226 -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 +26 -0
- package/dist/fulfillment/dispatchProjection.js +107 -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 +38 -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 +32 -0
- package/dist/fulfillment/migrations.js +9 -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 +32 -0
- package/dist/fulfillment/observationProjection.js +90 -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 +39 -0
- package/dist/fulfillment/omnipack/client.js +172 -0
- package/dist/fulfillment/omnipack/index.d.ts +55 -0
- package/dist/fulfillment/omnipack/index.js +408 -0
- package/dist/fulfillment/omnipack/mappers.d.ts +79 -0
- package/dist/fulfillment/omnipack/mappers.js +199 -0
- package/dist/fulfillment/omnipack/observation.d.ts +28 -0
- package/dist/fulfillment/omnipack/observation.js +72 -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/reconciliation.d.ts +15 -0
- package/dist/fulfillment/omnipack/reconciliation.js +55 -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 +70 -0
- package/dist/fulfillment/postgresShipmentSpine.js +246 -0
- package/dist/fulfillment/postgresStockSyncPort.d.ts +8 -0
- package/dist/fulfillment/postgresStockSyncPort.js +66 -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 +27 -0
- package/dist/fulfillment/providerDispatchAcceptance.js +29 -0
- package/dist/fulfillment/providerDispatchError.d.ts +6 -0
- package/dist/fulfillment/providerDispatchError.js +5 -0
- package/dist/fulfillment/providerDispatchWorker.d.ts +44 -0
- package/dist/fulfillment/providerDispatchWorker.js +199 -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 +90 -0
- package/dist/fulfillment/providerReconciliationWorker.js +207 -0
- package/dist/fulfillment/providerStockAvailability.d.ts +13 -0
- package/dist/fulfillment/providerStockAvailability.js +51 -0
- package/dist/fulfillment/providerStockSyncWorker.d.ts +41 -0
- package/dist/fulfillment/providerStockSyncWorker.js +295 -0
- package/dist/fulfillment/providerTrackingReferences.d.ts +16 -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 +79 -0
- package/dist/fulfillment/verifiedIngress.js +94 -0
- package/dist/invoicing/capabilities.d.ts +11 -0
- package/dist/invoicing/capabilities.js +10 -0
- package/dist/invoicing/contracts/capabilities.d.ts +40 -0
- package/dist/invoicing/contracts/capabilities.js +1 -0
- package/dist/invoicing/contracts/companyLookup.d.ts +49 -0
- package/dist/invoicing/contracts/companyLookup.js +1 -0
- package/dist/invoicing/contracts/delivery.d.ts +74 -0
- package/dist/invoicing/contracts/delivery.js +1 -0
- package/dist/invoicing/contracts/facts.d.ts +100 -0
- package/dist/invoicing/contracts/facts.js +1 -0
- package/dist/invoicing/contracts/host.d.ts +246 -0
- package/dist/invoicing/contracts/host.js +1 -0
- package/dist/invoicing/contracts/index.d.ts +16 -0
- package/dist/invoicing/contracts/index.js +1 -0
- package/dist/invoicing/contracts/provider.d.ts +126 -0
- package/dist/invoicing/contracts/provider.js +1 -0
- package/dist/invoicing/contracts/settlement.d.ts +66 -0
- package/dist/invoicing/contracts/settlement.js +1 -0
- package/dist/invoicing/contracts/store.d.ts +267 -0
- package/dist/invoicing/contracts/store.js +1 -0
- package/dist/invoicing/index.d.ts +1 -0
- package/dist/invoicing/index.js +1 -0
- package/dist/payments/stripe/index.d.ts +25 -0
- package/dist/payments/stripe/index.js +25 -0
- package/dist/payments/tpay/index.d.ts +30 -0
- package/dist/payments/tpay/index.js +30 -0
- package/dist/subscriptions/automaticRenewal.d.ts +44 -0
- package/dist/subscriptions/automaticRenewal.js +81 -0
- package/dist/subscriptions/automaticRenewalExecution.d.ts +21 -0
- package/dist/subscriptions/automaticRenewalExecution.js +44 -0
- package/dist/subscriptions/contracts/commands.d.ts +115 -0
- package/dist/subscriptions/contracts/commands.js +1 -0
- package/dist/subscriptions/contracts/dunning.d.ts +133 -0
- package/dist/subscriptions/contracts/dunning.js +1 -0
- package/dist/subscriptions/contracts/index.d.ts +6 -0
- package/dist/subscriptions/contracts/index.js +1 -0
- package/dist/subscriptions/contracts/messages.d.ts +43 -0
- package/dist/subscriptions/contracts/messages.js +1 -0
- package/dist/subscriptions/contracts/renewal.d.ts +533 -0
- package/dist/subscriptions/contracts/renewal.js +1 -0
- package/dist/subscriptions/contracts/stockWait.d.ts +73 -0
- package/dist/subscriptions/contracts/stockWait.js +1 -0
- package/dist/subscriptions/index.d.ts +39 -0
- package/dist/subscriptions/index.js +17 -0
- package/dist/subscriptions/paymentOutcomes.d.ts +8 -0
- package/dist/subscriptions/paymentOutcomes.js +27 -0
- package/dist/subscriptions/postgresRenewalStore.d.ts +20 -0
- package/dist/subscriptions/postgresRenewalStore.js +61 -0
- package/dist/subscriptions/postgresRetryStore.d.ts +78 -0
- package/dist/subscriptions/postgresRetryStore.js +142 -0
- package/dist/subscriptions/renewalCycleFailureMechanism.d.ts +34 -0
- package/dist/subscriptions/renewalCycleFailureMechanism.js +79 -0
- package/dist/subscriptions/renewalCycleMechanism.d.ts +46 -0
- package/dist/subscriptions/renewalCycleMechanism.js +157 -0
- package/dist/subscriptions/renewalCycleRefusalMechanism.d.ts +41 -0
- package/dist/subscriptions/renewalCycleRefusalMechanism.js +160 -0
- package/dist/subscriptions/renewalIdentity.d.ts +3 -0
- package/dist/subscriptions/renewalIdentity.js +4 -0
- package/package.json +37 -2
- package/release-gates.json +97 -3
- package/sql/20260808210000_fulfillment_shipment_rail.sql +810 -0
- package/sql/20260819150000_fulfillment_shipment_sequence.sql +98 -0
- package/sql/20261022080000_fulfillment_command_ledger.sql +786 -0
- package/sql/20261022090000_fulfillment_delivery_alignment.sql +1106 -0
- package/sql/20261022160000_subscription_retry_lifecycle.sql +328 -0
- package/sql/20261022165000_fulfillment_stock_evidence_replay_reopen.sql +30 -0
- package/src/composition/composeBundle.ts +4 -0
- package/src/composition/fulfillmentContribution.ts +28 -0
- package/src/composition/index.ts +1 -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 +63 -0
- package/src/fulfillment/contracts/customerAlignment.ts +4 -0
- package/src/fulfillment/contracts/dispatch.ts +73 -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 +26 -0
- package/src/fulfillment/contracts/operator.ts +31 -0
- package/src/fulfillment/contracts/read.ts +42 -0
- package/src/fulfillment/contracts/readback.ts +24 -0
- package/src/fulfillment/contracts/replacement.ts +15 -0
- package/src/fulfillment/contracts/store.ts +27 -0
- package/src/fulfillment/contracts/sync.ts +72 -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 +105 -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 +39 -0
- package/src/fulfillment/labelLifecycle.ts +11 -0
- package/src/fulfillment/lowStockEvidenceHandler.ts +60 -0
- package/src/fulfillment/migrations.ts +9 -0
- package/src/fulfillment/nativeUnsupported.ts +23 -0
- package/src/fulfillment/normalizedFulfillmentFacts.ts +2 -0
- package/src/fulfillment/observationProjection.ts +92 -0
- package/src/fulfillment/omnipack/capabilities.ts +18 -0
- package/src/fulfillment/omnipack/client.ts +270 -0
- package/src/fulfillment/omnipack/index.ts +369 -0
- package/src/fulfillment/omnipack/mappers.ts +282 -0
- package/src/fulfillment/omnipack/observation.ts +79 -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/reconciliation.ts +56 -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 +338 -0
- package/src/fulfillment/postgresStockSyncPort.ts +68 -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 +37 -0
- package/src/fulfillment/providerDispatchError.ts +7 -0
- package/src/fulfillment/providerDispatchWorker.ts +159 -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 +206 -0
- package/src/fulfillment/providerStockAvailability.ts +60 -0
- package/src/fulfillment/providerStockSyncWorker.ts +318 -0
- package/src/fulfillment/providerTrackingReferences.ts +32 -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 +113 -0
- package/src/invoicing/capabilities.ts +9 -0
- package/src/invoicing/contracts/capabilities.ts +15 -0
- package/src/invoicing/contracts/companyLookup.ts +13 -0
- package/src/invoicing/contracts/delivery.ts +24 -0
- package/src/invoicing/contracts/facts.ts +60 -0
- package/src/invoicing/contracts/host.ts +85 -0
- package/src/invoicing/contracts/index.ts +16 -0
- package/src/invoicing/contracts/provider.ts +78 -0
- package/src/invoicing/contracts/settlement.ts +39 -0
- package/src/invoicing/contracts/store.ts +98 -0
- package/src/invoicing/index.ts +1 -0
- package/src/payments/stripe/index.ts +30 -0
- package/src/payments/tpay/index.ts +36 -0
- package/src/subscriptions/automaticRenewal.ts +87 -0
- package/src/subscriptions/automaticRenewalExecution.ts +39 -0
- package/src/subscriptions/contracts/commands.ts +46 -0
- package/src/subscriptions/contracts/dunning.ts +48 -0
- package/src/subscriptions/contracts/index.ts +6 -0
- package/src/subscriptions/contracts/messages.ts +18 -0
- package/src/subscriptions/contracts/renewal.ts +325 -0
- package/src/subscriptions/contracts/stockWait.ts +34 -0
- package/src/subscriptions/index.ts +24 -0
- package/src/subscriptions/paymentOutcomes.ts +23 -0
- package/src/subscriptions/postgresRenewalStore.ts +76 -0
- package/src/subscriptions/postgresRetryStore.ts +174 -0
- package/src/subscriptions/renewalCycleFailureMechanism.ts +119 -0
- package/src/subscriptions/renewalCycleMechanism.ts +225 -0
- package/src/subscriptions/renewalCycleRefusalMechanism.ts +215 -0
- package/src/subscriptions/renewalIdentity.ts +5 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { PaymentAttemptStatus, PaymentExecutionProviderDecline, ProviderAttemptIdentity } from "@openlup/core/payment";
|
|
2
|
+
import type {
|
|
3
|
+
HostedRenewalDue, SubscriptionRenewalChargeResult, SubscriptionCycleSnapshotResult,
|
|
4
|
+
SubscriptionCycleOrderResult, RenewalIntentResult, RenewalPreflightDeps,
|
|
5
|
+
RenewalFailureDeps, RenewalOutcomeContext, RenewalReplayContext, FailurePropagationResult,
|
|
6
|
+
} from "./contracts/renewal.js";
|
|
7
|
+
import { propagateRenewalFailure, type RenewalFailurePolicy } from "./renewalCycleFailureMechanism.js";
|
|
8
|
+
|
|
9
|
+
export interface RenewalPreflightPolicy<D extends HostedRenewalDue, CI, IR extends RenewalIntentResult> {
|
|
10
|
+
isOperatorOnly(reason: string): boolean;
|
|
11
|
+
logOperatorBlock(fields: { subscriptionId: string; providerKind: string; reason: string }): void;
|
|
12
|
+
readTotal(snapshot: Record<string, unknown>): number | null;
|
|
13
|
+
cycleKey(due: D): string;
|
|
14
|
+
executionKey(cycleKey: string, retry: number, sequence: number): string;
|
|
15
|
+
intentInput(due: D, key: string, snapshots: SubscriptionCycleSnapshotResult, order: SubscriptionCycleOrderResult, total: number, reason: string): CI;
|
|
16
|
+
identity(due: D, key: string, intent: IR, order: SubscriptionCycleOrderResult, total: number): ProviderAttemptIdentity;
|
|
17
|
+
normalizedProvider(provider: string): string;
|
|
18
|
+
failed(due: D, cycleId: string | null, cycleNumber: number | null, orderId: string | null, intentId: string | null, reason: string, propagation?: FailurePropagationResult): SubscriptionRenewalChargeResult;
|
|
19
|
+
invalidTotalsReason: string;
|
|
20
|
+
defaultNow(): string;
|
|
21
|
+
failure: RenewalFailurePolicy;
|
|
22
|
+
}
|
|
23
|
+
export interface RenewalOutcomePolicy {
|
|
24
|
+
declineReason(decline: PaymentExecutionProviderDecline): string;
|
|
25
|
+
classifyDecline(decline: PaymentExecutionProviderDecline): { failureClass: string; decidedBy: string };
|
|
26
|
+
scaReason: string;
|
|
27
|
+
defaultNow(): string;
|
|
28
|
+
failure: RenewalFailurePolicy;
|
|
29
|
+
}
|
|
30
|
+
export interface RenewalReplayPolicy extends Pick<RenewalOutcomePolicy, "scaReason" | "defaultNow" | "failure"> {
|
|
31
|
+
unacknowledgedReason(status: PaymentAttemptStatus): string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Alternate preflight owns its full order/intent/failure chain, without reservation or dispatch. */
|
|
35
|
+
export async function recordRenewalPreflightBlock<D extends HostedRenewalDue, CI,
|
|
36
|
+
IR extends RenewalIntentResult, M extends string | null | undefined>(
|
|
37
|
+
deps: RenewalPreflightDeps<CI, IR, M>, due: D, reason: string,
|
|
38
|
+
policy: RenewalPreflightPolicy<D, CI, IR>,
|
|
39
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
40
|
+
if (policy.isOperatorOnly(reason)) {
|
|
41
|
+
policy.logOperatorBlock({ subscriptionId: due.subscriptionId, providerKind: due.providerKind, reason });
|
|
42
|
+
return policy.failed(due, null, null, null, null, reason);
|
|
43
|
+
}
|
|
44
|
+
const snapshots = await deps.persistence.buildCycleSnapshots({
|
|
45
|
+
subscriptionId: due.subscriptionId,
|
|
46
|
+
scheduledAt: due.nextCycleAt,
|
|
47
|
+
});
|
|
48
|
+
const totalGrossMinor = policy.readTotal(snapshots.orderSnapshot);
|
|
49
|
+
if (totalGrossMinor === null) {
|
|
50
|
+
return policy.failed(due, null, snapshots.cycleNumber, null, null, policy.invalidTotalsReason);
|
|
51
|
+
}
|
|
52
|
+
const cycleKey = policy.cycleKey(due);
|
|
53
|
+
const cycleOrder = await deps.persistence.createCycleOrder({
|
|
54
|
+
idempotencyKey: cycleKey,
|
|
55
|
+
subscriptionId: due.subscriptionId,
|
|
56
|
+
cycleNumber: snapshots.cycleNumber,
|
|
57
|
+
scheduledAt: due.nextCycleAt,
|
|
58
|
+
templateSnapshot: snapshots.templateSnapshot,
|
|
59
|
+
pricingSnapshot: snapshots.pricingSnapshot,
|
|
60
|
+
orderSnapshot: snapshots.orderSnapshot,
|
|
61
|
+
});
|
|
62
|
+
const intent = await deps.paymentPort.createIntent(policy.intentInput(due, cycleKey, snapshots, cycleOrder, totalGrossMinor, reason));
|
|
63
|
+
const executionKey = policy.executionKey(
|
|
64
|
+
cycleKey, snapshots.retryAttempt, snapshots.providerAttemptSequence,
|
|
65
|
+
);
|
|
66
|
+
const attempt = policy.identity(due, executionKey, intent, cycleOrder, totalGrossMinor);
|
|
67
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
68
|
+
kind: "preflight_block",
|
|
69
|
+
executionIdempotencyKey: executionKey,
|
|
70
|
+
providerIdempotencyKey: attempt.providerIdempotencyKey,
|
|
71
|
+
providerRequestFingerprint: attempt.providerRequestFingerprint,
|
|
72
|
+
paymentIntentId: intent.paymentIntentId,
|
|
73
|
+
cycleId: cycleOrder.cycleId,
|
|
74
|
+
subscriptionId: due.subscriptionId,
|
|
75
|
+
orderUuid: cycleOrder.orderUuid,
|
|
76
|
+
providerKind: policy.normalizedProvider(due.providerKind),
|
|
77
|
+
failureReason: reason,
|
|
78
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
79
|
+
}, policy.failure);
|
|
80
|
+
return policy.failed(
|
|
81
|
+
due,
|
|
82
|
+
cycleOrder.cycleId,
|
|
83
|
+
snapshots.cycleNumber,
|
|
84
|
+
cycleOrder.orderUuid,
|
|
85
|
+
intent.paymentIntentId,
|
|
86
|
+
reason,
|
|
87
|
+
propagation,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function declinedRenewalOutcome<D extends HostedRenewalDue>(
|
|
92
|
+
deps: RenewalFailureDeps, due: D, context: RenewalOutcomeContext & { decline: PaymentExecutionProviderDecline }, policy: RenewalOutcomePolicy,
|
|
93
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
94
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
95
|
+
kind: "provider_declined",
|
|
96
|
+
executionIdempotencyKey: context.executionIdempotencyKey,
|
|
97
|
+
providerIdempotencyKey: context.attemptIdentity.providerIdempotencyKey,
|
|
98
|
+
providerRequestFingerprint: context.attemptIdentity.providerRequestFingerprint,
|
|
99
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
100
|
+
cycleId: context.cycleOrder.cycleId,
|
|
101
|
+
subscriptionId: due.subscriptionId,
|
|
102
|
+
orderUuid: context.cycleOrder.orderUuid,
|
|
103
|
+
providerKind: due.providerKind,
|
|
104
|
+
failureReason: policy.declineReason(context.decline),
|
|
105
|
+
failureClassification: policy.classifyDecline(context.decline),
|
|
106
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
107
|
+
attemptAlreadyPrepared: true,
|
|
108
|
+
}, policy.failure);
|
|
109
|
+
return {
|
|
110
|
+
subscriptionId: due.subscriptionId,
|
|
111
|
+
outcome: "failed",
|
|
112
|
+
cycleId: context.cycleOrder.cycleId,
|
|
113
|
+
cycleNumber: context.snapshots.cycleNumber,
|
|
114
|
+
orderId: context.cycleOrder.orderUuid,
|
|
115
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
116
|
+
attemptStatus: "failed",
|
|
117
|
+
replayed: context.cycleOrder.replayed || context.intent.replayed,
|
|
118
|
+
dunningCaseId: propagation.dunningCaseId,
|
|
119
|
+
retryAttempt: propagation.retryAttempt,
|
|
120
|
+
applyReplayed: propagation.applyReplayed,
|
|
121
|
+
dunningPropagationFailed: propagation.dunningPropagationFailed,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export async function requiresActionRenewalOutcome<D extends HostedRenewalDue>(
|
|
125
|
+
deps: RenewalFailureDeps, due: D, context: RenewalOutcomeContext, policy: RenewalOutcomePolicy,
|
|
126
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
127
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
128
|
+
kind: "off_session_requires_action",
|
|
129
|
+
executionIdempotencyKey: context.executionIdempotencyKey,
|
|
130
|
+
providerIdempotencyKey: context.attemptIdentity.providerIdempotencyKey,
|
|
131
|
+
providerRequestFingerprint: context.attemptIdentity.providerRequestFingerprint,
|
|
132
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
133
|
+
cycleId: context.cycleOrder.cycleId,
|
|
134
|
+
subscriptionId: due.subscriptionId,
|
|
135
|
+
orderUuid: context.cycleOrder.orderUuid,
|
|
136
|
+
providerKind: due.providerKind,
|
|
137
|
+
failureReason: policy.scaReason,
|
|
138
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
139
|
+
attemptAlreadyPrepared: true,
|
|
140
|
+
}, policy.failure);
|
|
141
|
+
return {
|
|
142
|
+
subscriptionId: due.subscriptionId,
|
|
143
|
+
outcome: "requires_action",
|
|
144
|
+
cycleId: context.cycleOrder.cycleId,
|
|
145
|
+
cycleNumber: context.snapshots.cycleNumber,
|
|
146
|
+
orderId: context.cycleOrder.orderUuid,
|
|
147
|
+
paymentIntentId: context.intent.paymentIntentId,
|
|
148
|
+
attemptStatus: context.finalizedAttempt.status,
|
|
149
|
+
replayed: context.cycleOrder.replayed || context.intent.replayed,
|
|
150
|
+
dunningCaseId: propagation.dunningCaseId,
|
|
151
|
+
retryAttempt: propagation.retryAttempt,
|
|
152
|
+
applyReplayed: propagation.applyReplayed,
|
|
153
|
+
dunningPropagationFailed: propagation.dunningPropagationFailed,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function replayRenewalAttempt<D extends HostedRenewalDue>(
|
|
158
|
+
deps: RenewalFailureDeps, due: D, ctx: RenewalReplayContext,
|
|
159
|
+
status: PaymentAttemptStatus, policy: RenewalReplayPolicy,
|
|
160
|
+
): Promise<SubscriptionRenewalChargeResult> {
|
|
161
|
+
if (status === "requires_action") {
|
|
162
|
+
const propagation = await propagateRenewalFailure(deps.chargeFailurePropagation, {
|
|
163
|
+
kind: "off_session_requires_action",
|
|
164
|
+
executionIdempotencyKey: ctx.executionIdempotencyKey,
|
|
165
|
+
providerIdempotencyKey: ctx.providerIdempotencyKey,
|
|
166
|
+
providerRequestFingerprint: ctx.providerRequestFingerprint,
|
|
167
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
168
|
+
cycleId: ctx.cycleId,
|
|
169
|
+
subscriptionId: due.subscriptionId,
|
|
170
|
+
orderUuid: ctx.orderId,
|
|
171
|
+
providerKind: ctx.providerKind,
|
|
172
|
+
failureReason: policy.scaReason,
|
|
173
|
+
occurredAt: (deps.now ?? policy.defaultNow)(),
|
|
174
|
+
attemptAlreadyPrepared: true,
|
|
175
|
+
}, policy.failure);
|
|
176
|
+
return {
|
|
177
|
+
subscriptionId: due.subscriptionId,
|
|
178
|
+
outcome: "requires_action",
|
|
179
|
+
cycleId: ctx.cycleId,
|
|
180
|
+
cycleNumber: ctx.cycleNumber,
|
|
181
|
+
orderId: ctx.orderId,
|
|
182
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
183
|
+
attemptStatus: status,
|
|
184
|
+
replayed: true,
|
|
185
|
+
dunningCaseId: propagation.dunningCaseId,
|
|
186
|
+
retryAttempt: propagation.retryAttempt,
|
|
187
|
+
applyReplayed: propagation.applyReplayed,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (status === "sent_to_provider" || status === "processing") {
|
|
191
|
+
return {
|
|
192
|
+
subscriptionId: due.subscriptionId,
|
|
193
|
+
outcome: "charged",
|
|
194
|
+
cycleId: ctx.cycleId,
|
|
195
|
+
cycleNumber: ctx.cycleNumber,
|
|
196
|
+
orderId: ctx.orderId,
|
|
197
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
198
|
+
attemptStatus: status,
|
|
199
|
+
replayed: true,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
subscriptionId: due.subscriptionId,
|
|
204
|
+
outcome: "failed",
|
|
205
|
+
cycleId: ctx.cycleId,
|
|
206
|
+
cycleNumber: ctx.cycleNumber,
|
|
207
|
+
orderId: ctx.orderId,
|
|
208
|
+
paymentIntentId: ctx.paymentIntentId,
|
|
209
|
+
attemptStatus: status,
|
|
210
|
+
replayed: true,
|
|
211
|
+
dunningCaseId: null,
|
|
212
|
+
retryAttempt: null,
|
|
213
|
+
reason: policy.unacknowledgedReason(status),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RenewalIdentity, RenewalSchedule } from "./contracts/renewal.js";
|
|
2
|
+
/** The host's existing dialect owns every byte; no normalization or new prefix. */
|
|
3
|
+
export function renewalIdentity(schedule: RenewalSchedule, keys: (schedule: RenewalSchedule) => RenewalIdentity): RenewalIdentity {
|
|
4
|
+
return keys(schedule);
|
|
5
|
+
}
|