@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,533 @@
|
|
|
1
|
+
import type { PaymentAttemptStatus, PaymentExecutionBaseInput, PaymentExecutionBaseResult, PaymentProviderCapabilityDescriptor, ProviderAttemptIdentity } from "@openlup/core/payment";
|
|
2
|
+
/** Structural hosted-cycle contracts; native vocabulary is bound by the caller. */
|
|
3
|
+
export type SubscriptionRenewalOutcome = "charged" | "requires_action" | "failed" | "skipped";
|
|
4
|
+
export interface HostedRenewalDue {
|
|
5
|
+
subscriptionId: string;
|
|
6
|
+
nextCycleAt: string;
|
|
7
|
+
providerKind: string;
|
|
8
|
+
providerMethodRef: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface SubscriptionRenewalChargeResult {
|
|
11
|
+
subscriptionId: string;
|
|
12
|
+
outcome: SubscriptionRenewalOutcome;
|
|
13
|
+
cycleId: string | null;
|
|
14
|
+
cycleNumber: number | null;
|
|
15
|
+
orderId: string | null;
|
|
16
|
+
paymentIntentId: string | null;
|
|
17
|
+
attemptStatus: PaymentAttemptStatus | null;
|
|
18
|
+
replayed: boolean;
|
|
19
|
+
dunningCaseId?: string | null;
|
|
20
|
+
retryAttempt?: number | null;
|
|
21
|
+
applyReplayed?: boolean;
|
|
22
|
+
dunningPropagationFailed?: boolean;
|
|
23
|
+
reason?: string;
|
|
24
|
+
admissionDeferralReference?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SubscriptionCycleSnapshotResult {
|
|
27
|
+
cycleNumber: number;
|
|
28
|
+
retryAttempt: number;
|
|
29
|
+
providerAttemptSequence: number;
|
|
30
|
+
templateSnapshot: Record<string, unknown>;
|
|
31
|
+
pricingSnapshot: Record<string, unknown>;
|
|
32
|
+
orderSnapshot: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
export interface SubscriptionCycleOrderInput {
|
|
35
|
+
idempotencyKey: string;
|
|
36
|
+
subscriptionId: string;
|
|
37
|
+
cycleNumber: number;
|
|
38
|
+
scheduledAt: string;
|
|
39
|
+
templateSnapshot: Record<string, unknown>;
|
|
40
|
+
pricingSnapshot: Record<string, unknown>;
|
|
41
|
+
orderSnapshot: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
export interface SubscriptionCycleOrderResult {
|
|
44
|
+
cycleId: string;
|
|
45
|
+
orderRef: string;
|
|
46
|
+
orderUuid: string;
|
|
47
|
+
paymentRef: string;
|
|
48
|
+
replayed: boolean;
|
|
49
|
+
}
|
|
50
|
+
export interface SubscriptionReservationPreflightResult {
|
|
51
|
+
ok: boolean;
|
|
52
|
+
reason: string | null;
|
|
53
|
+
itemsChecked: number;
|
|
54
|
+
reacquired: number;
|
|
55
|
+
}
|
|
56
|
+
export interface SubscriptionRenewalPersistencePort<M extends string | null | undefined = string | null | undefined> {
|
|
57
|
+
buildCycleSnapshots(input: {
|
|
58
|
+
subscriptionId: string;
|
|
59
|
+
scheduledAt: string;
|
|
60
|
+
}): Promise<SubscriptionCycleSnapshotResult>;
|
|
61
|
+
createCycleOrder(input: SubscriptionCycleOrderInput): Promise<SubscriptionCycleOrderResult>;
|
|
62
|
+
preflightReservation(input: {
|
|
63
|
+
orderId: string;
|
|
64
|
+
now: string;
|
|
65
|
+
}): Promise<SubscriptionReservationPreflightResult>;
|
|
66
|
+
readMandateRecurringModel(providerKind: string, providerMethodRef: string | null): Promise<M>;
|
|
67
|
+
noteRowOutcome(input: {
|
|
68
|
+
subscriptionId: string;
|
|
69
|
+
scheduledAt: string;
|
|
70
|
+
errorKey: string | null;
|
|
71
|
+
}): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
export type FailurePropagationKind = "off_session_requires_action" | "provider_declined" | "preflight_block";
|
|
74
|
+
export interface FailurePropagationContext {
|
|
75
|
+
kind: FailurePropagationKind;
|
|
76
|
+
executionIdempotencyKey: string;
|
|
77
|
+
providerIdempotencyKey: string;
|
|
78
|
+
providerRequestFingerprint: string;
|
|
79
|
+
paymentIntentId: string;
|
|
80
|
+
cycleId: string;
|
|
81
|
+
subscriptionId: string;
|
|
82
|
+
orderUuid: string;
|
|
83
|
+
providerKind: string;
|
|
84
|
+
failureReason: string;
|
|
85
|
+
failureClassification?: {
|
|
86
|
+
failureClass: string;
|
|
87
|
+
decidedBy: string;
|
|
88
|
+
} | null;
|
|
89
|
+
occurredAt: string;
|
|
90
|
+
attemptAlreadyPrepared?: boolean;
|
|
91
|
+
}
|
|
92
|
+
export interface CycleRetryState {
|
|
93
|
+
retryAttempt: number | null;
|
|
94
|
+
nextRetryAt: string | null;
|
|
95
|
+
rowPresent: boolean;
|
|
96
|
+
}
|
|
97
|
+
export type DunningCaseOpenOutcome = {
|
|
98
|
+
status: "opened";
|
|
99
|
+
caseId: string | null;
|
|
100
|
+
} | {
|
|
101
|
+
status: "rejected";
|
|
102
|
+
reason: string;
|
|
103
|
+
code?: string;
|
|
104
|
+
} | {
|
|
105
|
+
status: "unavailable";
|
|
106
|
+
reason: string;
|
|
107
|
+
};
|
|
108
|
+
export interface CycleChargeFailurePropagationPort {
|
|
109
|
+
recordBlockedPreflightAttempt(input: {
|
|
110
|
+
idempotencyKey: string;
|
|
111
|
+
paymentIntentId: string;
|
|
112
|
+
providerKind: string;
|
|
113
|
+
providerIdempotencyKey: string;
|
|
114
|
+
providerRequestFingerprint: string;
|
|
115
|
+
failureReason: string;
|
|
116
|
+
}): Promise<void>;
|
|
117
|
+
readDurableAttemptInstant(input: {
|
|
118
|
+
paymentIntentId: string;
|
|
119
|
+
attemptIdempotencyKey: string;
|
|
120
|
+
}): Promise<string | null>;
|
|
121
|
+
applyFailedResult(input: {
|
|
122
|
+
idempotencyKey: string;
|
|
123
|
+
paymentIntentId: string;
|
|
124
|
+
occurredAt: string;
|
|
125
|
+
failureReason: string;
|
|
126
|
+
failureClassification: {
|
|
127
|
+
failureClass: string;
|
|
128
|
+
decidedBy: string;
|
|
129
|
+
};
|
|
130
|
+
}): Promise<{
|
|
131
|
+
replayed: boolean;
|
|
132
|
+
}>;
|
|
133
|
+
readCycleRetryState(cycleId: string): Promise<CycleRetryState>;
|
|
134
|
+
openDunningCase(input: {
|
|
135
|
+
idempotencyKey: string;
|
|
136
|
+
cycleId: string;
|
|
137
|
+
subscriptionId: string;
|
|
138
|
+
orderUuid: string;
|
|
139
|
+
paymentIntentId: string;
|
|
140
|
+
retryAttempt: number;
|
|
141
|
+
nextRetryAt: string | null;
|
|
142
|
+
failureReason: string;
|
|
143
|
+
occurredAt: string;
|
|
144
|
+
failureClass: string;
|
|
145
|
+
}): Promise<DunningCaseOpenOutcome>;
|
|
146
|
+
}
|
|
147
|
+
export interface FailurePropagationResult {
|
|
148
|
+
dunningCaseId: string | null;
|
|
149
|
+
retryAttempt: number | null;
|
|
150
|
+
applyReplayed: boolean;
|
|
151
|
+
dunningPropagationFailed: boolean;
|
|
152
|
+
}
|
|
153
|
+
export type RenewalPrepareInput<P extends string> = Parameters<RenewalPreparedAttemptPersistencePort<P, string>["prepareProviderAttempt"]>[0];
|
|
154
|
+
export type RenewalAttemptResult<N extends string> = Awaited<ReturnType<RenewalPreparedAttemptPersistencePort<string, N>["finalizeProviderAttempt"]>>;
|
|
155
|
+
export interface RenewalIntentResult {
|
|
156
|
+
paymentIntentId: string;
|
|
157
|
+
replayed: boolean;
|
|
158
|
+
}
|
|
159
|
+
export interface RenewalPaymentPort<CI, IR extends RenewalIntentResult, P extends string, N extends string> extends RenewalPreparedAttemptPersistencePort<P, N> {
|
|
160
|
+
createIntent(input: CI): Promise<IR>;
|
|
161
|
+
}
|
|
162
|
+
export interface RenewalExecutionPort<I extends PaymentExecutionBaseInput, R extends PaymentExecutionBaseResult> {
|
|
163
|
+
execute(input: I): Promise<R>;
|
|
164
|
+
}
|
|
165
|
+
export interface RenewalDeliveryAdmission {
|
|
166
|
+
allowed: boolean;
|
|
167
|
+
state: string;
|
|
168
|
+
reason: string;
|
|
169
|
+
}
|
|
170
|
+
export type RenewalAllowedAdmission = RenewalDeliveryAdmission & {
|
|
171
|
+
allowed: true;
|
|
172
|
+
};
|
|
173
|
+
export interface RenewalDeliveryClient {
|
|
174
|
+
admitDeliveryAlignment(input: {
|
|
175
|
+
subscriptionId: string;
|
|
176
|
+
scheduledAt: string;
|
|
177
|
+
asOf: string;
|
|
178
|
+
}): Promise<RenewalDeliveryAdmission>;
|
|
179
|
+
}
|
|
180
|
+
export interface RenewalFailureDeps {
|
|
181
|
+
chargeFailurePropagation: CycleChargeFailurePropagationPort;
|
|
182
|
+
now?: () => string;
|
|
183
|
+
}
|
|
184
|
+
export interface RenewalPreflightDeps<CI, IR extends RenewalIntentResult, M extends string | null | undefined> extends RenewalFailureDeps {
|
|
185
|
+
persistence: SubscriptionRenewalPersistencePort<M>;
|
|
186
|
+
paymentPort: {
|
|
187
|
+
createIntent(input: CI): Promise<IR>;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export interface RenewalCycleDeps<CI, IR extends RenewalIntentResult, P extends string, N extends string, I extends PaymentExecutionBaseInput, R extends PaymentExecutionBaseResult, M extends string | null | undefined> extends RenewalPreflightDeps<CI, IR, M> {
|
|
191
|
+
paymentPort: RenewalPaymentPort<CI, IR, P, N>;
|
|
192
|
+
executionPort: RenewalExecutionPort<I, R>;
|
|
193
|
+
deliveryAlignment: RenewalDeliveryClient;
|
|
194
|
+
capability: PaymentProviderCapabilityDescriptor;
|
|
195
|
+
deliveryAlignmentAdmission?: RenewalAllowedAdmission;
|
|
196
|
+
}
|
|
197
|
+
/** Local references, never a snapshot of the original due/ports or their getters. */
|
|
198
|
+
export interface RenewalExecutionContext<IR extends RenewalIntentResult, M extends string | null | undefined, F extends string> {
|
|
199
|
+
snapshots: SubscriptionCycleSnapshotResult;
|
|
200
|
+
cycleOrder: SubscriptionCycleOrderResult;
|
|
201
|
+
intent: IR;
|
|
202
|
+
totalGrossMinor: number;
|
|
203
|
+
executionIdempotencyKey: string;
|
|
204
|
+
attemptIdentity: ProviderAttemptIdentity;
|
|
205
|
+
providerFlow: F;
|
|
206
|
+
paymentMethodRecurringModel: M | undefined;
|
|
207
|
+
}
|
|
208
|
+
export interface RenewalOutcomeContext {
|
|
209
|
+
executionIdempotencyKey: string;
|
|
210
|
+
attemptIdentity: ProviderAttemptIdentity;
|
|
211
|
+
intent: RenewalIntentResult;
|
|
212
|
+
cycleOrder: Pick<SubscriptionCycleOrderResult, "cycleId" | "orderUuid" | "replayed">;
|
|
213
|
+
snapshots: Pick<SubscriptionCycleSnapshotResult, "cycleNumber">;
|
|
214
|
+
finalizedAttempt: {
|
|
215
|
+
status: PaymentAttemptStatus;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
export interface RenewalReplayContext {
|
|
219
|
+
cycleId: string;
|
|
220
|
+
cycleNumber: number;
|
|
221
|
+
orderId: string;
|
|
222
|
+
paymentIntentId: string;
|
|
223
|
+
executionIdempotencyKey: string;
|
|
224
|
+
providerIdempotencyKey: string;
|
|
225
|
+
providerRequestFingerprint: string;
|
|
226
|
+
providerKind: string;
|
|
227
|
+
}
|
|
228
|
+
/** Durable preparation facts; provider admission belongs to the caller. */
|
|
229
|
+
export interface RenewalPreparedAttemptPrepareInput<P extends string = string> {
|
|
230
|
+
idempotencyKey: string;
|
|
231
|
+
paymentIntentId: string;
|
|
232
|
+
provider: P;
|
|
233
|
+
providerIdempotencyKey: string;
|
|
234
|
+
providerRequestFingerprint: string;
|
|
235
|
+
providerFlow: string;
|
|
236
|
+
paymentMethodRef?: string | null;
|
|
237
|
+
requestPayload: Record<string, unknown>;
|
|
238
|
+
}
|
|
239
|
+
export interface RenewalPreparedAttemptPersistenceResult<N extends string = string> {
|
|
240
|
+
paymentAttemptId: string;
|
|
241
|
+
status: PaymentAttemptStatus;
|
|
242
|
+
replayed: boolean;
|
|
243
|
+
providerAttemptId: string | null;
|
|
244
|
+
providerSessionId: string | null;
|
|
245
|
+
nextActionKind: N | null;
|
|
246
|
+
}
|
|
247
|
+
export interface RenewalPreparedAttemptFinalizeInput<N extends string = string> extends Pick<PaymentExecutionBaseResult, "providerAttemptId" | "providerSessionId" | "attemptStatus" | "requestPayload" | "responsePayload"> {
|
|
248
|
+
idempotencyKey: string;
|
|
249
|
+
paymentIntentId: string;
|
|
250
|
+
paymentAttemptId: string;
|
|
251
|
+
providerIdempotencyKey: string;
|
|
252
|
+
providerRequestFingerprint: string;
|
|
253
|
+
nextActionKind: N | null;
|
|
254
|
+
}
|
|
255
|
+
/** Only persistence capabilities needed by interactive attempt ordering. */
|
|
256
|
+
export interface RenewalPreparedAttemptPersistencePort<P extends string = string, N extends string = string> {
|
|
257
|
+
prepareProviderAttempt(input: RenewalPreparedAttemptPrepareInput<P>): Promise<RenewalPreparedAttemptPersistenceResult<N>>;
|
|
258
|
+
finalizeProviderAttempt(input: RenewalPreparedAttemptFinalizeInput<N>): Promise<RenewalPreparedAttemptPersistenceResult<N>>;
|
|
259
|
+
}
|
|
260
|
+
/** Original text is an identity input; instant is for comparisons only. */
|
|
261
|
+
export interface RenewalSchedule {
|
|
262
|
+
subscriptionId: string;
|
|
263
|
+
scheduledAt: string;
|
|
264
|
+
scheduledInstant: number;
|
|
265
|
+
}
|
|
266
|
+
export interface RenewalIdentity {
|
|
267
|
+
cycleIdempotencyKey: string;
|
|
268
|
+
executionIdempotencyKey: string;
|
|
269
|
+
externalIdempotencyKey: string;
|
|
270
|
+
requestFingerprint: string;
|
|
271
|
+
}
|
|
272
|
+
export type RenewalAdmission = {
|
|
273
|
+
allowed: true;
|
|
274
|
+
state: string;
|
|
275
|
+
reason: string;
|
|
276
|
+
} | {
|
|
277
|
+
allowed: false;
|
|
278
|
+
state: string;
|
|
279
|
+
reason: string;
|
|
280
|
+
deferred: true;
|
|
281
|
+
caseRef?: string;
|
|
282
|
+
} | {
|
|
283
|
+
allowed: false;
|
|
284
|
+
state: string;
|
|
285
|
+
reason: string;
|
|
286
|
+
deferred: false;
|
|
287
|
+
};
|
|
288
|
+
export interface RenewalLine {
|
|
289
|
+
lineOrdinal: number;
|
|
290
|
+
sku: string;
|
|
291
|
+
quantity: number;
|
|
292
|
+
unitAmountMinor: number;
|
|
293
|
+
}
|
|
294
|
+
/** Logical numbering is evidence-bound, never a universal nativeCounter + 1. */
|
|
295
|
+
export type RenewalCycleCorrelation = {
|
|
296
|
+
status: "correlated";
|
|
297
|
+
logicalCycleNumber: number;
|
|
298
|
+
nativeRenewalCounter: number | null;
|
|
299
|
+
activationCycleId: string | null;
|
|
300
|
+
evidenceRef: string;
|
|
301
|
+
} | {
|
|
302
|
+
status: "ambiguous";
|
|
303
|
+
logicalCycleNumber: null;
|
|
304
|
+
nativeRenewalCounter: number | null;
|
|
305
|
+
activationCycleId: string | null;
|
|
306
|
+
reason: string;
|
|
307
|
+
};
|
|
308
|
+
export interface RenewalTemplateSnapshot {
|
|
309
|
+
templateId: string;
|
|
310
|
+
version: number;
|
|
311
|
+
cadenceDays: number;
|
|
312
|
+
lines: readonly RenewalLine[];
|
|
313
|
+
}
|
|
314
|
+
export interface RenewalPricingSnapshot {
|
|
315
|
+
currency: string;
|
|
316
|
+
totalAmountMinor: number;
|
|
317
|
+
shippingAmountMinor: number;
|
|
318
|
+
agreementPolicy: "lock_until_edit";
|
|
319
|
+
proration: "none";
|
|
320
|
+
}
|
|
321
|
+
export interface RenewalOrderSnapshot {
|
|
322
|
+
shippingAddressRef: string | null;
|
|
323
|
+
shippingQuoteRef: string | null;
|
|
324
|
+
acquisitionRef: string | null;
|
|
325
|
+
lines: readonly RenewalLine[];
|
|
326
|
+
}
|
|
327
|
+
export interface RenewalFrozenSnapshot extends RenewalSchedule {
|
|
328
|
+
contractVersion: "platform.subscription.renewal.v1";
|
|
329
|
+
clientId: string;
|
|
330
|
+
frozenRevision: string;
|
|
331
|
+
frozenFingerprint: string;
|
|
332
|
+
cycle: RenewalCycleCorrelation;
|
|
333
|
+
retryAttempt: number;
|
|
334
|
+
externalAttemptSequence: number;
|
|
335
|
+
templateSnapshot: RenewalTemplateSnapshot;
|
|
336
|
+
pricingSnapshot: RenewalPricingSnapshot;
|
|
337
|
+
orderSnapshot: RenewalOrderSnapshot;
|
|
338
|
+
stockSourceKey: string;
|
|
339
|
+
settlementChannelKey: string;
|
|
340
|
+
authorizationRef: string;
|
|
341
|
+
payerAccountRef: string | null;
|
|
342
|
+
unattendedChargeAuthorizedAt: string;
|
|
343
|
+
}
|
|
344
|
+
export interface RenewalDue extends RenewalSchedule {
|
|
345
|
+
clientId: string;
|
|
346
|
+
cadenceDays: number;
|
|
347
|
+
cycle: RenewalCycleCorrelation;
|
|
348
|
+
currency: string;
|
|
349
|
+
stockSourceKey: string;
|
|
350
|
+
settlementChannelKey: string;
|
|
351
|
+
authorizationRef: string;
|
|
352
|
+
payerAccountRef: string | null;
|
|
353
|
+
unattendedChargeAuthorizedAt: string;
|
|
354
|
+
deliveryAdmission: "allowed" | "blocked";
|
|
355
|
+
deliveryBlockReason: string | null;
|
|
356
|
+
}
|
|
357
|
+
export type RenewalOperationState = "claimed" | "reserved" | "attempt_prepared" | "succeeded" | "refused";
|
|
358
|
+
export interface RenewalReadback extends RenewalSchedule {
|
|
359
|
+
contractVersion: "platform.subscription.renewal.v1";
|
|
360
|
+
acquired: boolean;
|
|
361
|
+
replayed: boolean;
|
|
362
|
+
reason: string;
|
|
363
|
+
operationId: string;
|
|
364
|
+
identityKey: string;
|
|
365
|
+
operationFingerprint: string;
|
|
366
|
+
cycle: RenewalCycleCorrelation;
|
|
367
|
+
state: RenewalOperationState;
|
|
368
|
+
claimToken: string;
|
|
369
|
+
claimGeneration: number;
|
|
370
|
+
leaseExpiresAt: string;
|
|
371
|
+
cycleSnapshot: RenewalFrozenSnapshot;
|
|
372
|
+
externalAttemptRef: string | null;
|
|
373
|
+
externalAttemptAcknowledgedAt: string | null;
|
|
374
|
+
terminalOutcome: "succeeded" | "refused" | null;
|
|
375
|
+
terminalReason: string | null;
|
|
376
|
+
terminalAt: string | null;
|
|
377
|
+
reservationId: string | null;
|
|
378
|
+
cycleId: string | null;
|
|
379
|
+
orderId: string | null;
|
|
380
|
+
settlementIntentId: string | null;
|
|
381
|
+
}
|
|
382
|
+
/** M07 verified truth. Nullable money is not positive matching evidence. */
|
|
383
|
+
export interface RenewalPaymentEvidence {
|
|
384
|
+
status: "succeeded" | "failed" | "pending" | "unknown";
|
|
385
|
+
disposition: "observed" | "ambiguous" | "late_positive";
|
|
386
|
+
operationId: string;
|
|
387
|
+
eventKey: string;
|
|
388
|
+
requestFingerprint: string;
|
|
389
|
+
verifiedEvidenceRef: string;
|
|
390
|
+
externalAttemptRef: string | null;
|
|
391
|
+
occurredAt: string | null;
|
|
392
|
+
observedAt: string;
|
|
393
|
+
firstRecordedAt: string;
|
|
394
|
+
amountMinor: number | null;
|
|
395
|
+
currency: string | null;
|
|
396
|
+
reason: string | null;
|
|
397
|
+
}
|
|
398
|
+
/** Payment execution is outside all SQL transactions. */
|
|
399
|
+
export type RenewalTransactionUnits = {
|
|
400
|
+
graph: "native";
|
|
401
|
+
prepare: "cycle_order_items_settlement_reservation_attempt";
|
|
402
|
+
outcome: "settlement_outcome_schedule_counter_reservation";
|
|
403
|
+
recovery: "settlement_cycle_receipt_case_counter";
|
|
404
|
+
} | {
|
|
405
|
+
graph: "managed";
|
|
406
|
+
prepare: "create_cycle_order_then_prepare_attempt";
|
|
407
|
+
failure: "record_attempt_then_apply_result_then_open_case";
|
|
408
|
+
recovery: "authorize_method_then_schedule";
|
|
409
|
+
};
|
|
410
|
+
export interface RenewalReservationResult {
|
|
411
|
+
reserved: boolean;
|
|
412
|
+
replayed: boolean;
|
|
413
|
+
reservationId: string | null;
|
|
414
|
+
status: "held" | "committed" | "consumed" | "released" | "expired" | "refused";
|
|
415
|
+
reason: string | null;
|
|
416
|
+
}
|
|
417
|
+
export interface RenewalPreparedSettlement {
|
|
418
|
+
contractVersion: "platform.subscription.renewal.v1";
|
|
419
|
+
replayed: boolean;
|
|
420
|
+
operationId: string;
|
|
421
|
+
operationFingerprint: string;
|
|
422
|
+
cycleId: string;
|
|
423
|
+
orderId: string;
|
|
424
|
+
settlementIntentId: string;
|
|
425
|
+
state: "attempt_prepared";
|
|
426
|
+
}
|
|
427
|
+
export interface RenewalStorePort {
|
|
428
|
+
readonly transactions: RenewalTransactionUnits;
|
|
429
|
+
listDue(limit: number, asOf: string): Promise<RenewalDue[]>;
|
|
430
|
+
buildCycleSnapshots(input: RenewalSchedule): Promise<RenewalFrozenSnapshot>;
|
|
431
|
+
readMandateEvidence(input: RenewalSchedule): Promise<{
|
|
432
|
+
authorized: boolean;
|
|
433
|
+
authorizationRef: string;
|
|
434
|
+
authorizedAt: string | null;
|
|
435
|
+
}>;
|
|
436
|
+
admitDeliveryAlignment(input: RenewalSchedule & {
|
|
437
|
+
occurredAt: string;
|
|
438
|
+
}): Promise<RenewalAdmission>;
|
|
439
|
+
claimDue(input: {
|
|
440
|
+
snapshot: RenewalFrozenSnapshot;
|
|
441
|
+
workerId: string;
|
|
442
|
+
leaseSeconds?: number;
|
|
443
|
+
now: string;
|
|
444
|
+
}): Promise<RenewalReadback>;
|
|
445
|
+
readRenewal(identityKey: string): Promise<RenewalReadback | null>;
|
|
446
|
+
refuseBeforePayment(input: {
|
|
447
|
+
operationId: string;
|
|
448
|
+
claimToken: string;
|
|
449
|
+
reason: string;
|
|
450
|
+
occurredAt: string;
|
|
451
|
+
}): Promise<RenewalReadback>;
|
|
452
|
+
}
|
|
453
|
+
export interface RenewalSettlementPort {
|
|
454
|
+
prepareRenewal(input: {
|
|
455
|
+
operationId: string;
|
|
456
|
+
claimToken: string;
|
|
457
|
+
now: string;
|
|
458
|
+
}): Promise<RenewalPreparedSettlement>;
|
|
459
|
+
acknowledgeExternalAttempt(input: {
|
|
460
|
+
operationId: string;
|
|
461
|
+
operationFingerprint: string;
|
|
462
|
+
externalAttemptRef: string;
|
|
463
|
+
acknowledgedAt: string;
|
|
464
|
+
}): Promise<RenewalReadback>;
|
|
465
|
+
recordTerminalOutcome(input: {
|
|
466
|
+
operationId: string;
|
|
467
|
+
eventKey: string;
|
|
468
|
+
operationFingerprint: string;
|
|
469
|
+
outcome: "succeeded" | "refused";
|
|
470
|
+
externalRef?: string | null;
|
|
471
|
+
reason?: string | null;
|
|
472
|
+
occurredAt: string;
|
|
473
|
+
}): Promise<RenewalReadback>;
|
|
474
|
+
}
|
|
475
|
+
export interface RenewalExecutionRequest extends RenewalIdentity {
|
|
476
|
+
paymentIntentId: string;
|
|
477
|
+
amountMinor: number;
|
|
478
|
+
currency: string;
|
|
479
|
+
mode: string;
|
|
480
|
+
orderRef: string;
|
|
481
|
+
orderId: string;
|
|
482
|
+
flow: string;
|
|
483
|
+
customerRef: string | null;
|
|
484
|
+
paymentMethodRef: string;
|
|
485
|
+
recurringModel: string | null;
|
|
486
|
+
clientId: string;
|
|
487
|
+
payer: {
|
|
488
|
+
email: string | null;
|
|
489
|
+
name: string | null;
|
|
490
|
+
} | null;
|
|
491
|
+
}
|
|
492
|
+
export interface RenewalPaymentRail {
|
|
493
|
+
execute(input: RenewalExecutionRequest): Promise<{
|
|
494
|
+
status: "succeeded" | "failed" | "requires_action" | "pending" | "unknown";
|
|
495
|
+
externalAttemptRef: string | null;
|
|
496
|
+
failure?: {
|
|
497
|
+
reason: string;
|
|
498
|
+
failureClass: string;
|
|
499
|
+
};
|
|
500
|
+
}>;
|
|
501
|
+
findExternalAttempt(input: {
|
|
502
|
+
settlementIntentId: string;
|
|
503
|
+
}): Promise<string | null>;
|
|
504
|
+
readOutcome(input: {
|
|
505
|
+
externalAttemptRef: string;
|
|
506
|
+
settlementIntentId: string;
|
|
507
|
+
orderId: string;
|
|
508
|
+
subscriptionId: string;
|
|
509
|
+
amountMinor: number;
|
|
510
|
+
currency: string;
|
|
511
|
+
}): Promise<RenewalPaymentEvidence>;
|
|
512
|
+
}
|
|
513
|
+
export type RenewalResult = {
|
|
514
|
+
outcome: "deferred";
|
|
515
|
+
subscriptionId: string;
|
|
516
|
+
scheduledAt: string;
|
|
517
|
+
reason: string;
|
|
518
|
+
caseRef?: string;
|
|
519
|
+
} | {
|
|
520
|
+
outcome: "charged" | "requires_action" | "failed" | "skipped";
|
|
521
|
+
subscriptionId: string;
|
|
522
|
+
cycleId: string | null;
|
|
523
|
+
cycleNumber: number | null;
|
|
524
|
+
orderId: string | null;
|
|
525
|
+
paymentIntentId: string | null;
|
|
526
|
+
attemptStatus: string | null;
|
|
527
|
+
replayed: boolean;
|
|
528
|
+
dunningCaseId?: string | null;
|
|
529
|
+
retryAttempt?: number | null;
|
|
530
|
+
applyReplayed?: boolean;
|
|
531
|
+
dunningPropagationFailed?: boolean;
|
|
532
|
+
reason?: string;
|
|
533
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { RenewalFrozenSnapshot, RenewalReadback, RenewalSchedule } from "./renewal.js";
|
|
2
|
+
export interface StockWaitRecoveryBinding {
|
|
3
|
+
caseId: string | null;
|
|
4
|
+
cycleId: string | null;
|
|
5
|
+
orderId: string | null;
|
|
6
|
+
paymentId: string | null;
|
|
7
|
+
engineIdempotencyKey: string | null;
|
|
8
|
+
}
|
|
9
|
+
export interface StockWaitDeficit {
|
|
10
|
+
skuId: string;
|
|
11
|
+
sku: string;
|
|
12
|
+
displayName: string;
|
|
13
|
+
size: string | null;
|
|
14
|
+
required: number;
|
|
15
|
+
reserved: number;
|
|
16
|
+
available: number;
|
|
17
|
+
missing: number;
|
|
18
|
+
}
|
|
19
|
+
export interface StockWaitCase extends RenewalSchedule {
|
|
20
|
+
caseId: string;
|
|
21
|
+
clientId: string;
|
|
22
|
+
state: "waiting" | "stock_secured" | "resumed" | "closed";
|
|
23
|
+
frozenSnapshot: RenewalFrozenSnapshot;
|
|
24
|
+
frozenFingerprint: string;
|
|
25
|
+
binding: StockWaitRecoveryBinding;
|
|
26
|
+
deficits: readonly StockWaitDeficit[];
|
|
27
|
+
fulfillmentRef: string | null;
|
|
28
|
+
blockReason: string | null;
|
|
29
|
+
openedAt: string;
|
|
30
|
+
checkedAt: string | null;
|
|
31
|
+
selectedAt: string | null;
|
|
32
|
+
securedAt: string | null;
|
|
33
|
+
resumedAt: string | null;
|
|
34
|
+
closedAt: string | null;
|
|
35
|
+
startedNoticeKey: string;
|
|
36
|
+
resumedNoticeKey: string;
|
|
37
|
+
noticeEligible: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** All-line reserve/reacquire and the wait transition share a DB transaction.
|
|
40
|
+
* A shortage rolls back the subtransaction, retaining previous commitments;
|
|
41
|
+
* record the wait outside that failed subtransaction. Technical failure is unknown.
|
|
42
|
+
*/
|
|
43
|
+
export interface StockWaitStorePort {
|
|
44
|
+
listCandidates(input: {
|
|
45
|
+
limit: number;
|
|
46
|
+
asOf: string;
|
|
47
|
+
}): Promise<StockWaitCase[]>;
|
|
48
|
+
readFrozenCase(input: StockWaitRecoveryBinding): Promise<StockWaitCase | null>;
|
|
49
|
+
reserveAndTransition(input: {
|
|
50
|
+
caseId: string;
|
|
51
|
+
frozenFingerprint: string;
|
|
52
|
+
now: string;
|
|
53
|
+
}): Promise<StockWaitCase>;
|
|
54
|
+
/** Only elapsed, unprepared, unacknowledged, stock-only refusals may reset.
|
|
55
|
+
* Requires unchanged schedule/fingerprint and no payment artifacts or outcomes.
|
|
56
|
+
* Rotate fencing generation atomically with reacquisition. Never reset ambiguity.
|
|
57
|
+
*/
|
|
58
|
+
recoverRefusedSchedule(input: {
|
|
59
|
+
operationId: string;
|
|
60
|
+
caseId: string;
|
|
61
|
+
claimGeneration: number;
|
|
62
|
+
frozenFingerprint: string;
|
|
63
|
+
scheduledAt: string;
|
|
64
|
+
now: string;
|
|
65
|
+
}): Promise<{
|
|
66
|
+
outcome: "recovered";
|
|
67
|
+
operation: RenewalReadback;
|
|
68
|
+
replayed: boolean;
|
|
69
|
+
} | {
|
|
70
|
+
outcome: "refused";
|
|
71
|
+
reason: "not_stock_only" | "external_ownership" | "stale_snapshot" | "lease_active" | "inventory_unavailable";
|
|
72
|
+
}>;
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export { renewalIdentity } from "./renewalIdentity.js";
|
|
2
|
+
export declare const NATIVE_SUBSCRIPTION_CAPABILITIES: Readonly<{
|
|
3
|
+
readonly graph: "native";
|
|
4
|
+
readonly multiCyclePrepaid: Readonly<{
|
|
5
|
+
supported: false;
|
|
6
|
+
refusalCode: "multi_cycle_prepaid_unsupported";
|
|
7
|
+
}>;
|
|
8
|
+
readonly genericBundleCommands: Readonly<{
|
|
9
|
+
supported: false;
|
|
10
|
+
refusalCode: "native_generic_bundle_commands_unsupported";
|
|
11
|
+
}>;
|
|
12
|
+
readonly commandBoundReceipts: Readonly<{
|
|
13
|
+
supported: false;
|
|
14
|
+
refusalCode: "native_command_bound_receipts_unsupported";
|
|
15
|
+
}>;
|
|
16
|
+
readonly preparedAttemptStore: Readonly<{
|
|
17
|
+
supported: false;
|
|
18
|
+
refusalCode: "native_prepared_attempt_store_unsupported";
|
|
19
|
+
}>;
|
|
20
|
+
readonly retryRecovery: "selected";
|
|
21
|
+
readonly stockRecovery: "unavailable";
|
|
22
|
+
readonly deliveryAdmission: "required";
|
|
23
|
+
readonly executorCount: 1;
|
|
24
|
+
readonly defaultEnabled: false;
|
|
25
|
+
}>;
|
|
26
|
+
export { executeRenewalCycle, prepareRenewalAttempt, checkRenewalDeliveryAdmission } from "./renewalCycleMechanism.js";
|
|
27
|
+
export type { RenewalCyclePolicy } from "./renewalCycleMechanism.js";
|
|
28
|
+
export { recordRenewalPreflightBlock, replayRenewalAttempt, declinedRenewalOutcome, requiresActionRenewalOutcome } from "./renewalCycleRefusalMechanism.js";
|
|
29
|
+
export type { RenewalPreflightPolicy, RenewalReplayPolicy, RenewalOutcomePolicy } from "./renewalCycleRefusalMechanism.js";
|
|
30
|
+
export { propagateRenewalFailure } from "./renewalCycleFailureMechanism.js";
|
|
31
|
+
export type { RenewalFailurePolicy } from "./renewalCycleFailureMechanism.js";
|
|
32
|
+
export { runAutomaticSubscriptionRenewals, runOneAutomaticSubscriptionRenewal, correlatedLogicalCycle } from "./automaticRenewal.js";
|
|
33
|
+
export type { AutomaticRenewalRunStatus, AutomaticRenewalRunResult, AutomaticRenewalRunDeps, AutomaticRenewalPolicy } from "./automaticRenewal.js";
|
|
34
|
+
export { createPostgresRenewalStore } from "./postgresRenewalStore.js";
|
|
35
|
+
export type { NativeRenewalCodec, SubscriptionQueryExecutor } from "./postgresRenewalStore.js";
|
|
36
|
+
export { createPostgresRetryStore } from "./postgresRetryStore.js";
|
|
37
|
+
export type { NativeRetryFailure, NativeRetryRequest, NativeRetryPositive, NativeRetryPreparation, NativeRetryRow } from "./postgresRetryStore.js";
|
|
38
|
+
export { createPostgresRetryLifecycleBinding } from "./postgresRetryStore.js";
|
|
39
|
+
export type { NativeRetryLifecycleBinding } from "./postgresRetryStore.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { renewalIdentity } from "./renewalIdentity.js";
|
|
2
|
+
export const NATIVE_SUBSCRIPTION_CAPABILITIES = Object.freeze({
|
|
3
|
+
graph: "native",
|
|
4
|
+
multiCyclePrepaid: Object.freeze({ supported: false, refusalCode: "multi_cycle_prepaid_unsupported" }),
|
|
5
|
+
genericBundleCommands: Object.freeze({ supported: false, refusalCode: "native_generic_bundle_commands_unsupported" }),
|
|
6
|
+
commandBoundReceipts: Object.freeze({ supported: false, refusalCode: "native_command_bound_receipts_unsupported" }),
|
|
7
|
+
preparedAttemptStore: Object.freeze({ supported: false, refusalCode: "native_prepared_attempt_store_unsupported" }),
|
|
8
|
+
retryRecovery: "selected", stockRecovery: "unavailable",
|
|
9
|
+
deliveryAdmission: "required", executorCount: 1, defaultEnabled: false,
|
|
10
|
+
});
|
|
11
|
+
export { executeRenewalCycle, prepareRenewalAttempt, checkRenewalDeliveryAdmission } from "./renewalCycleMechanism.js";
|
|
12
|
+
export { recordRenewalPreflightBlock, replayRenewalAttempt, declinedRenewalOutcome, requiresActionRenewalOutcome } from "./renewalCycleRefusalMechanism.js";
|
|
13
|
+
export { propagateRenewalFailure } from "./renewalCycleFailureMechanism.js";
|
|
14
|
+
export { runAutomaticSubscriptionRenewals, runOneAutomaticSubscriptionRenewal, correlatedLogicalCycle } from "./automaticRenewal.js";
|
|
15
|
+
export { createPostgresRenewalStore } from "./postgresRenewalStore.js";
|
|
16
|
+
export { createPostgresRetryStore } from "./postgresRetryStore.js";
|
|
17
|
+
export { createPostgresRetryLifecycleBinding } from "./postgresRetryStore.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RenewalPaymentRail, RenewalReadback } from "./contracts/renewal.js";
|
|
2
|
+
import type { AutomaticRenewalRunDeps, AutomaticRenewalRunResult } from "./automaticRenewal.js";
|
|
3
|
+
/** H4: only explicit verified matching M07 evidence may become positive local truth. */
|
|
4
|
+
export declare function readAndApplyProviderOutcome(deps: AutomaticRenewalRunDeps, operation: RenewalReadback, prepared: {
|
|
5
|
+
cycleId: string;
|
|
6
|
+
orderId: string;
|
|
7
|
+
settlementIntentId: string;
|
|
8
|
+
}, rail: RenewalPaymentRail, externalAttemptRef: string, occurredAt: string): Promise<AutomaticRenewalRunResult>;
|