@openlup/platform 0.17.0 → 0.18.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 +96 -0
- package/README.md +284 -6
- package/dist/catalog/activeSkuSelection.d.ts +2 -0
- package/dist/catalog/activeSkuSelection.js +20 -0
- package/dist/catalog/adminBindings.d.ts +72 -0
- package/dist/catalog/adminBindings.js +1 -0
- package/dist/catalog/adminBundleHandler.d.ts +26 -0
- package/dist/catalog/adminBundleHandler.js +111 -0
- package/dist/catalog/adminBundleReadHandler.d.ts +20 -0
- package/dist/catalog/adminBundleReadHandler.js +185 -0
- package/dist/catalog/adminBundleWritePort.d.ts +85 -0
- package/dist/catalog/adminBundleWritePort.js +1 -0
- package/dist/catalog/bundleAvailability.d.ts +63 -0
- package/dist/catalog/bundleAvailability.js +78 -0
- package/dist/catalog/bundleAvailabilityService.d.ts +65 -0
- package/dist/catalog/bundleAvailabilityService.js +89 -0
- package/dist/catalog/bundleBindings.d.ts +33 -0
- package/dist/catalog/bundleBindings.js +1 -0
- package/dist/catalog/bundleCatalogQueries.d.ts +28 -0
- package/dist/catalog/bundleCatalogQueries.js +84 -0
- package/dist/catalog/bundleCatalogReadPort.d.ts +166 -0
- package/dist/catalog/bundleCatalogReadPort.js +36 -0
- package/dist/catalog/bundleCatalogStore.d.ts +3 -0
- package/dist/catalog/bundleCatalogStore.js +152 -0
- package/dist/catalog/bundleRuleCodes.d.ts +41 -0
- package/dist/catalog/bundleRuleCodes.js +110 -0
- package/dist/catalog/bundleRules.d.ts +69 -0
- package/dist/catalog/bundleRules.js +102 -0
- package/dist/catalog/catalogDraftStore.d.ts +4 -0
- package/dist/catalog/catalogDraftStore.js +63 -0
- package/dist/catalog/catalogSkuEnvelope.d.ts +7 -0
- package/dist/catalog/catalogSkuEnvelope.js +142 -0
- package/dist/catalog/catalogSkuEnvelopeMapper.d.ts +38 -0
- package/dist/catalog/catalogSkuEnvelopeMapper.js +88 -0
- package/dist/catalog/contracts/bundleAdmin.d.ts +143 -0
- package/dist/catalog/contracts/bundleAdmin.js +1 -0
- package/dist/catalog/contracts/bundleAvailability.d.ts +61 -0
- package/dist/catalog/contracts/bundleAvailability.js +1 -0
- package/dist/catalog/contracts/bundleRead.d.ts +223 -0
- package/dist/catalog/contracts/bundleRead.js +1 -0
- package/dist/catalog/contracts/draft.d.ts +79 -0
- package/dist/catalog/contracts/draft.js +47 -0
- package/dist/catalog/contracts/foundation.d.ts +78 -0
- package/dist/catalog/contracts/foundation.js +53 -0
- package/dist/catalog/contracts/index.d.ts +14 -0
- package/dist/catalog/contracts/index.js +6 -0
- package/dist/catalog/contracts/lifecycle.d.ts +77 -0
- package/dist/catalog/contracts/lifecycle.js +1 -0
- package/dist/catalog/contracts/productMediaContracts.d.ts +77 -0
- package/dist/catalog/contracts/productMediaContracts.js +149 -0
- package/dist/catalog/contracts/productTypes.d.ts +54 -0
- package/dist/catalog/contracts/productTypes.js +16 -0
- package/dist/catalog/contracts/resolveProductMedia.d.ts +3 -0
- package/dist/catalog/contracts/resolveProductMedia.js +78 -0
- package/dist/catalog/contracts/sellable.d.ts +23 -0
- package/dist/catalog/contracts/sellable.js +1 -0
- package/dist/catalog/draftHandler.d.ts +25 -0
- package/dist/catalog/draftHandler.js +118 -0
- package/dist/catalog/draftPorts.d.ts +18 -0
- package/dist/catalog/draftPorts.js +8 -0
- package/dist/catalog/draftSchemas.d.ts +423 -0
- package/dist/catalog/draftSchemas.js +89 -0
- package/dist/catalog/draftValidation.d.ts +21 -0
- package/dist/catalog/draftValidation.js +125 -0
- package/dist/catalog/foundationSchemas.d.ts +98 -0
- package/dist/catalog/foundationSchemas.js +110 -0
- package/dist/catalog/index.d.ts +43 -0
- package/dist/catalog/index.js +25 -0
- package/dist/catalog/mediaSourcePack.d.ts +51 -0
- package/dist/catalog/mediaSourcePack.js +247 -0
- package/dist/catalog/productTypeSchemas.d.ts +46 -0
- package/dist/catalog/productTypeSchemas.js +72 -0
- package/dist/catalog/publicationPorts.d.ts +42 -0
- package/dist/catalog/publicationPorts.js +1 -0
- package/dist/catalog/readPorts.d.ts +51 -0
- package/dist/catalog/readPorts.js +1 -0
- package/dist/catalog/referenceCatalogHandler.d.ts +7 -0
- package/dist/catalog/referenceCatalogHandler.js +27 -0
- package/dist/catalog/resolvedSkuProjection.d.ts +88 -0
- package/dist/catalog/resolvedSkuProjection.js +60 -0
- package/dist/catalog/sellableBundleHandler.d.ts +46 -0
- package/dist/catalog/sellableBundleHandler.js +84 -0
- package/dist/catalog/sellableSchemas.d.ts +46 -0
- package/dist/catalog/sellableSchemas.js +27 -0
- package/dist/catalog/sql.d.ts +46 -0
- package/dist/catalog/sql.js +13 -0
- package/dist/catalog/validation.d.ts +2 -0
- package/dist/catalog/validation.js +3 -0
- package/dist/communications/contracts/index.d.ts +1 -0
- package/dist/communications/contracts/marketingSync.d.ts +194 -0
- package/dist/communications/contracts/marketingSync.js +1 -0
- package/dist/communications/index.d.ts +1 -0
- package/dist/communications/klaviyo/consentPush.d.ts +51 -0
- package/dist/communications/klaviyo/consentPush.js +19 -0
- package/dist/communications/klaviyo/index.d.ts +110 -0
- package/dist/communications/klaviyo/index.js +860 -0
- package/dist/communications/newsletterIntegrationContracts.d.ts +3 -3
- package/dist/communications/resend/index.d.ts +40 -0
- package/dist/communications/resend/index.js +310 -0
- package/dist/composition/catalogContribution.d.ts +18 -0
- package/dist/composition/catalogContribution.js +21 -0
- package/dist/composition/index.d.ts +1 -0
- package/dist/composition/index.js +1 -0
- package/dist/identity/customerContracts.d.ts +2 -2
- package/dist/inventory/adminInventory.d.ts +13 -0
- package/dist/inventory/adminInventory.js +214 -0
- package/dist/inventory/contracts/forecast.d.ts +86 -0
- package/dist/inventory/contracts/forecast.js +1 -0
- package/dist/inventory/contracts/index.d.ts +4 -0
- package/dist/inventory/contracts/index.js +1 -0
- package/dist/inventory/contracts/inventory.d.ts +157 -0
- package/dist/inventory/contracts/inventory.js +1 -0
- package/dist/inventory/contracts/newPurchaseStock.d.ts +20 -0
- package/dist/inventory/contracts/newPurchaseStock.js +1 -0
- package/dist/inventory/contracts/reservation.d.ts +18 -0
- package/dist/inventory/contracts/reservation.js +1 -0
- package/dist/inventory/forecast.d.ts +24 -0
- package/dist/inventory/forecast.js +200 -0
- package/dist/inventory/index.d.ts +13 -0
- package/dist/inventory/index.js +10 -0
- package/dist/inventory/inventoryHandlers.d.ts +53 -0
- package/dist/inventory/inventoryHandlers.js +151 -0
- package/dist/inventory/newPurchaseStockAvailability.d.ts +47 -0
- package/dist/inventory/newPurchaseStockAvailability.js +75 -0
- package/dist/inventory/ports.d.ts +21 -0
- package/dist/inventory/ports.js +16 -0
- package/dist/inventory/renewalReservation.d.ts +27 -0
- package/dist/inventory/renewalReservation.js +61 -0
- package/dist/inventory/reservationPolicy.d.ts +6 -0
- package/dist/inventory/reservationPolicy.js +19 -0
- package/dist/inventory/schemas.d.ts +137 -0
- package/dist/inventory/schemas.js +112 -0
- package/dist/inventory/sql.d.ts +14 -0
- package/dist/inventory/sql.js +5 -0
- package/dist/inventory/subscriptionForecastCalculation.d.ts +4 -0
- package/dist/inventory/subscriptionForecastCalculation.js +133 -0
- package/dist/pricing/acquisitionFinancialPolicy.d.ts +26 -0
- package/dist/pricing/acquisitionFinancialPolicy.js +1 -0
- package/dist/pricing/acquisitionOfferPricing.d.ts +27 -0
- package/dist/pricing/acquisitionOfferPricing.js +25 -0
- package/dist/pricing/acquisitionOfferPricingHandler.d.ts +20 -0
- package/dist/pricing/acquisitionOfferPricingHandler.js +105 -0
- package/dist/pricing/acquisitionOfferPricingSchemas.d.ts +31 -0
- package/dist/pricing/acquisitionOfferPricingSchemas.js +33 -0
- package/dist/pricing/acquisitionQuoteBinding.d.ts +12 -0
- package/dist/pricing/acquisitionQuoteBinding.js +12 -0
- package/dist/pricing/acquisitionReadiness.d.ts +31 -0
- package/dist/pricing/acquisitionReadiness.js +117 -0
- package/dist/pricing/acquisitionTerms.d.ts +19 -0
- package/dist/pricing/acquisitionTerms.js +126 -0
- package/dist/pricing/acquisitionTermsSchemas.d.ts +59 -0
- package/dist/pricing/acquisitionTermsSchemas.js +42 -0
- package/dist/pricing/catalogFactsProvenance.d.ts +33 -0
- package/dist/pricing/catalogFactsProvenance.js +64 -0
- package/dist/pricing/catalogFactsSchemas.d.ts +45 -0
- package/dist/pricing/catalogFactsSchemas.js +58 -0
- package/dist/pricing/commerceOfferPricing.d.ts +25 -0
- package/dist/pricing/commerceOfferPricing.js +139 -0
- package/dist/pricing/commerceOfferPricingCache.d.ts +10 -0
- package/dist/pricing/commerceOfferPricingCache.js +44 -0
- package/dist/pricing/commerceOfferPricingHandler.d.ts +21 -0
- package/dist/pricing/commerceOfferPricingHandler.js +78 -0
- package/dist/pricing/commercePriceAuthority.d.ts +26 -0
- package/dist/pricing/commercePriceAuthority.js +79 -0
- package/dist/pricing/commercePricingPolicyErrors.d.ts +40 -0
- package/dist/pricing/commercePricingPolicyErrors.js +67 -0
- package/dist/pricing/commerceQuoteBatchHandler.d.ts +37 -0
- package/dist/pricing/commerceQuoteBatchHandler.js +83 -0
- package/dist/pricing/commerceQuoteCatalogReadPort.d.ts +27 -0
- package/dist/pricing/commerceQuoteCatalogReadPort.js +8 -0
- package/dist/pricing/commerceQuoteHandler.d.ts +31 -0
- package/dist/pricing/commerceQuoteHandler.js +110 -0
- package/dist/pricing/commerceQuoteSnapshotExpect.d.ts +9 -0
- package/dist/pricing/commerceQuoteSnapshotExpect.js +22 -0
- package/dist/pricing/contracts/acquisitionTerms.d.ts +32 -0
- package/dist/pricing/contracts/acquisitionTerms.js +2 -0
- package/dist/pricing/contracts/authority.d.ts +27 -0
- package/dist/pricing/contracts/authority.js +1 -0
- package/dist/pricing/contracts/evidence.d.ts +33 -0
- package/dist/pricing/contracts/evidence.js +1 -0
- package/dist/pricing/contracts/index.d.ts +17 -0
- package/dist/pricing/contracts/index.js +7 -0
- package/dist/pricing/contracts/money.d.ts +27 -0
- package/dist/pricing/contracts/money.js +1 -0
- package/dist/pricing/contracts/offer.d.ts +52 -0
- package/dist/pricing/contracts/offer.js +4 -0
- package/dist/pricing/contracts/offerPolicy.d.ts +16 -0
- package/dist/pricing/contracts/offerPolicy.js +5 -0
- package/dist/pricing/contracts/policy.d.ts +22 -0
- package/dist/pricing/contracts/policy.js +3 -0
- package/dist/pricing/contracts/provenance.d.ts +24 -0
- package/dist/pricing/contracts/provenance.js +2 -0
- package/dist/pricing/contracts/quote.d.ts +94 -0
- package/dist/pricing/contracts/quote.js +1 -0
- package/dist/pricing/dbBackedCommerceQuoteHelpers.d.ts +78 -0
- package/dist/pricing/dbBackedCommerceQuoteHelpers.js +146 -0
- package/dist/pricing/dbBackedCommerceQuotePort.d.ts +66 -0
- package/dist/pricing/dbBackedCommerceQuotePort.js +206 -0
- package/dist/pricing/dbBackedCommerceQuoteSnapshotVerifier.d.ts +4 -0
- package/dist/pricing/dbBackedCommerceQuoteSnapshotVerifier.js +25 -0
- package/dist/pricing/index.d.ts +51 -0
- package/dist/pricing/index.js +36 -0
- package/dist/pricing/offerPolicyReadiness.d.ts +21 -0
- package/dist/pricing/offerPolicyReadiness.js +79 -0
- package/dist/pricing/offerPolicySchemas.d.ts +25 -0
- package/dist/pricing/offerPolicySchemas.js +15 -0
- package/dist/pricing/offerPricingSchemas.d.ts +315 -0
- package/dist/pricing/offerPricingSchemas.js +65 -0
- package/dist/pricing/ports.d.ts +13 -0
- package/dist/pricing/ports.js +9 -0
- package/dist/pricing/pricingPolicyToken.d.ts +39 -0
- package/dist/pricing/pricingPolicyToken.js +84 -0
- package/dist/pricing/quoteAcquisitionTerms.d.ts +2 -0
- package/dist/pricing/quoteAcquisitionTerms.js +4 -0
- package/dist/pricing/quoteCodeRejectionDetails.d.ts +20 -0
- package/dist/pricing/quoteCodeRejectionDetails.js +22 -0
- package/dist/pricing/quotePorts.d.ts +30 -0
- package/dist/pricing/quotePorts.js +20 -0
- package/dist/pricing/quotePrimitives.d.ts +13 -0
- package/dist/pricing/quotePrimitives.js +18 -0
- package/dist/pricing/quotePromotionEvidence.d.ts +39 -0
- package/dist/pricing/quotePromotionEvidence.js +73 -0
- package/dist/pricing/quoteSchemas.d.ts +1176 -0
- package/dist/pricing/quoteSchemas.js +196 -0
- package/dist/pricing/subscriptionPricePolicy.d.ts +52 -0
- package/dist/pricing/subscriptionPricePolicy.js +96 -0
- package/dist/pricing/taxProfileGuard.d.ts +2 -0
- package/dist/pricing/taxProfileGuard.js +24 -0
- package/dist/pricing/validation.d.ts +2 -0
- package/dist/pricing/validation.js +3 -0
- package/dist/promotions/adminBindings.d.ts +72 -0
- package/dist/promotions/adminBindings.js +1 -0
- package/dist/promotions/adminPromotionCodesContracts.d.ts +498 -0
- package/dist/promotions/adminPromotionCodesContracts.js +211 -0
- package/dist/promotions/adminPromotionCodesDataPort.d.ts +47 -0
- package/dist/promotions/adminPromotionCodesDataPort.js +1 -0
- package/dist/promotions/adminPromotionCodesHandler.d.ts +14 -0
- package/dist/promotions/adminPromotionCodesHandler.js +194 -0
- package/dist/promotions/adminPromotionsContracts.d.ts +235 -0
- package/dist/promotions/adminPromotionsContracts.js +99 -0
- package/dist/promotions/adminPromotionsDataPort.d.ts +42 -0
- package/dist/promotions/adminPromotionsDataPort.js +1 -0
- package/dist/promotions/adminPromotionsHandler.d.ts +16 -0
- package/dist/promotions/adminPromotionsHandler.js +47 -0
- package/dist/promotions/contracts/index.d.ts +387 -0
- package/dist/promotions/contracts/index.js +1 -0
- package/dist/promotions/index.d.ts +22 -0
- package/dist/promotions/index.js +21 -0
- package/dist/promotions/promoDataPort.d.ts +47 -0
- package/dist/promotions/promoDataPort.js +14 -0
- package/dist/promotions/promotionAcceptanceTelemetry.d.ts +29 -0
- package/dist/promotions/promotionAcceptanceTelemetry.js +45 -0
- package/dist/promotions/promotionBenefitDefinition.d.ts +37 -0
- package/dist/promotions/promotionBenefitDefinition.js +33 -0
- package/dist/promotions/promotionClaimSweepPort.d.ts +14 -0
- package/dist/promotions/promotionClaimSweepPort.js +8 -0
- package/dist/promotions/promotionClaims.d.ts +5 -0
- package/dist/promotions/promotionClaims.js +57 -0
- package/dist/promotions/promotionCodePreview.d.ts +11 -0
- package/dist/promotions/promotionCodePreview.js +154 -0
- package/dist/promotions/promotionCodeQuotePort.d.ts +25 -0
- package/dist/promotions/promotionCodeQuotePort.js +1 -0
- package/dist/promotions/promotionQuoteAcceptance.d.ts +65 -0
- package/dist/promotions/promotionQuoteAcceptance.js +202 -0
- package/dist/promotions/promotionQuoteBinding.d.ts +71 -0
- package/dist/promotions/promotionQuoteBinding.js +85 -0
- package/dist/promotions/quoteAutomaticPromotions.d.ts +24 -0
- package/dist/promotions/quoteAutomaticPromotions.js +36 -0
- package/dist/promotions/quotePromoDiscounts.d.ts +32 -0
- package/dist/promotions/quotePromoDiscounts.js +140 -0
- package/dist/promotions/quotePromotionCodeAdjustments.d.ts +27 -0
- package/dist/promotions/quotePromotionCodeAdjustments.js +223 -0
- package/dist/promotions/quotePromotionV2.d.ts +29 -0
- package/dist/promotions/quotePromotionV2.js +174 -0
- package/dist/promotions/sql.d.ts +14 -0
- package/dist/promotions/sql.js +5 -0
- package/dist/promotions/validation.d.ts +2 -0
- package/dist/promotions/validation.js +3 -0
- package/dist/shipping/addressCanonLookupHandler.d.ts +7 -0
- package/dist/shipping/addressCanonLookupHandler.js +105 -0
- package/dist/shipping/addressCanonical.d.ts +2 -0
- package/dist/shipping/addressCanonical.js +26 -0
- package/dist/shipping/addressPorts.d.ts +39 -0
- package/dist/shipping/addressPorts.js +1 -0
- package/dist/shipping/addressSchemas.d.ts +30 -0
- package/dist/shipping/addressSchemas.js +1 -0
- package/dist/shipping/adminShippingRateHandler.d.ts +4 -0
- package/dist/shipping/adminShippingRateHandler.js +64 -0
- package/dist/shipping/contracts/address.d.ts +144 -0
- package/dist/shipping/contracts/address.js +1 -0
- package/dist/shipping/contracts/delivery.d.ts +110 -0
- package/dist/shipping/contracts/delivery.js +1 -0
- package/dist/shipping/contracts/index.d.ts +3 -0
- package/dist/shipping/contracts/index.js +1 -0
- package/dist/shipping/contracts/shippingRate.d.ts +11 -0
- package/dist/shipping/contracts/shippingRate.js +1 -0
- package/dist/shipping/customerAddressesHandler.d.ts +5 -0
- package/dist/shipping/customerAddressesHandler.js +80 -0
- package/dist/shipping/customerSelfServiceAddressModels.d.ts +27 -0
- package/dist/shipping/customerSelfServiceAddressModels.js +101 -0
- package/dist/shipping/deliverySelectionHandler.d.ts +10 -0
- package/dist/shipping/deliverySelectionHandler.js +77 -0
- package/dist/shipping/deliverySelectionPort.d.ts +8 -0
- package/dist/shipping/deliverySelectionPort.js +1 -0
- package/dist/shipping/deliverySelectionSummary.d.ts +2 -0
- package/dist/shipping/deliverySelectionSummary.js +53 -0
- package/dist/shipping/handlerSchemas.d.ts +21 -0
- package/dist/shipping/handlerSchemas.js +1 -0
- package/dist/shipping/index.d.ts +17 -0
- package/dist/shipping/index.js +8 -0
- package/dist/shipping/pickupPointSearchPort.d.ts +4 -0
- package/dist/shipping/pickupPointSearchPort.js +1 -0
- package/dist/shipping/readDeliverySelectionEvidence.d.ts +2 -0
- package/dist/shipping/readDeliverySelectionEvidence.js +44 -0
- package/dist/shipping/shippingRatePorts.d.ts +52 -0
- package/dist/shipping/shippingRatePorts.js +1 -0
- package/package.json +62 -2
- package/release-gates.json +218 -10
- package/sql/20260807140000_read_parity_catalog.sql +94 -0
- package/sql/20260810120000_storefront_catalog_attributes.sql +51 -0
- package/sql/20260812140000_sellable_bundle_catalog.sql +124 -0
- package/sql/20260812210000_bundle_operator_write_boundary.sql +567 -0
- package/sql/20260814000000_fulfillment_stock_evidence.sql +239 -0
- package/sql/20260815120000_automatic_subscription_renewal.sql +1083 -0
- package/sql/20260817180000_promotion_claim_lifecycle.sql +591 -0
- package/sql/20260817180100_promotion_claim_lifecycle_validation.sql +23 -0
- package/sql/20260827220000_catalog_document_revision_foundation.sql +226 -0
- package/sql/20260827220001_catalog_document_revision_foundation_validate.sql +10 -0
- package/sql/20260908100000_catalog_draft_foundation.sql +217 -0
- package/src/catalog/activeSkuSelection.ts +20 -0
- package/src/catalog/adminBindings.ts +59 -0
- package/src/catalog/adminBundleHandler.ts +165 -0
- package/src/catalog/adminBundleReadHandler.ts +261 -0
- package/src/catalog/adminBundleWritePort.ts +102 -0
- package/src/catalog/bundleAvailability.ts +129 -0
- package/src/catalog/bundleAvailabilityService.ts +171 -0
- package/src/catalog/bundleBindings.ts +29 -0
- package/src/catalog/bundleCatalogQueries.ts +98 -0
- package/src/catalog/bundleCatalogReadPort.ts +177 -0
- package/src/catalog/bundleCatalogStore.ts +269 -0
- package/src/catalog/bundleRuleCodes.ts +134 -0
- package/src/catalog/bundleRules.ts +153 -0
- package/src/catalog/catalogDraftStore.ts +71 -0
- package/src/catalog/catalogSkuEnvelope.ts +214 -0
- package/src/catalog/catalogSkuEnvelopeMapper.ts +160 -0
- package/src/catalog/contracts/bundleAdmin.ts +20 -0
- package/src/catalog/contracts/bundleAvailability.ts +5 -0
- package/src/catalog/contracts/bundleRead.ts +13 -0
- package/src/catalog/contracts/draft.ts +69 -0
- package/src/catalog/contracts/foundation.ts +104 -0
- package/src/catalog/contracts/index.ts +14 -0
- package/src/catalog/contracts/lifecycle.ts +74 -0
- package/src/catalog/contracts/productMediaContracts.ts +170 -0
- package/src/catalog/contracts/productTypes.ts +35 -0
- package/src/catalog/contracts/resolveProductMedia.ts +85 -0
- package/src/catalog/contracts/sellable.ts +12 -0
- package/src/catalog/draftHandler.ts +105 -0
- package/src/catalog/draftPorts.ts +18 -0
- package/src/catalog/draftSchemas.ts +88 -0
- package/src/catalog/draftValidation.ts +100 -0
- package/src/catalog/foundationSchemas.ts +123 -0
- package/src/catalog/index.ts +43 -0
- package/src/catalog/mediaSourcePack.ts +219 -0
- package/src/catalog/productTypeSchemas.ts +70 -0
- package/src/catalog/publicationPorts.ts +44 -0
- package/src/catalog/readPorts.ts +61 -0
- package/src/catalog/referenceCatalogHandler.ts +39 -0
- package/src/catalog/resolvedSkuProjection.ts +76 -0
- package/src/catalog/sellableBundleHandler.ts +133 -0
- package/src/catalog/sellableSchemas.ts +33 -0
- package/src/catalog/sql.ts +14 -0
- package/src/catalog/validation.ts +3 -0
- package/src/communications/contracts/index.ts +1 -0
- package/src/communications/contracts/marketingSync.ts +109 -0
- package/src/communications/index.ts +1 -0
- package/src/communications/klaviyo/consentPush.ts +19 -0
- package/src/communications/klaviyo/index.ts +649 -0
- package/src/communications/resend/index.ts +350 -0
- package/src/composition/catalogContribution.ts +32 -0
- package/src/composition/index.ts +1 -0
- package/src/inventory/adminInventory.ts +251 -0
- package/src/inventory/contracts/forecast.ts +96 -0
- package/src/inventory/contracts/index.ts +18 -0
- package/src/inventory/contracts/inventory.ts +14 -0
- package/src/inventory/contracts/newPurchaseStock.ts +23 -0
- package/src/inventory/contracts/reservation.ts +20 -0
- package/src/inventory/forecast.ts +239 -0
- package/src/inventory/index.ts +21 -0
- package/src/inventory/inventoryHandlers.ts +215 -0
- package/src/inventory/newPurchaseStockAvailability.ts +120 -0
- package/src/inventory/ports.ts +46 -0
- package/src/inventory/renewalReservation.ts +88 -0
- package/src/inventory/reservationPolicy.ts +27 -0
- package/src/inventory/schemas.ts +128 -0
- package/src/inventory/sql.ts +5 -0
- package/src/inventory/subscriptionForecastCalculation.ts +157 -0
- package/src/pricing/acquisitionFinancialPolicy.ts +26 -0
- package/src/pricing/acquisitionOfferPricing.ts +38 -0
- package/src/pricing/acquisitionOfferPricingHandler.ts +157 -0
- package/src/pricing/acquisitionOfferPricingSchemas.ts +35 -0
- package/src/pricing/acquisitionQuoteBinding.ts +12 -0
- package/src/pricing/acquisitionReadiness.ts +148 -0
- package/src/pricing/acquisitionTerms.ts +125 -0
- package/src/pricing/acquisitionTermsSchemas.ts +52 -0
- package/src/pricing/catalogFactsProvenance.ts +102 -0
- package/src/pricing/catalogFactsSchemas.ts +69 -0
- package/src/pricing/commerceOfferPricing.ts +224 -0
- package/src/pricing/commerceOfferPricingCache.ts +53 -0
- package/src/pricing/commerceOfferPricingHandler.ts +137 -0
- package/src/pricing/commercePriceAuthority.ts +104 -0
- package/src/pricing/commercePricingPolicyErrors.ts +88 -0
- package/src/pricing/commerceQuoteBatchHandler.ts +129 -0
- package/src/pricing/commerceQuoteCatalogReadPort.ts +42 -0
- package/src/pricing/commerceQuoteHandler.ts +184 -0
- package/src/pricing/commerceQuoteSnapshotExpect.ts +48 -0
- package/src/pricing/contracts/acquisitionTerms.ts +26 -0
- package/src/pricing/contracts/authority.ts +44 -0
- package/src/pricing/contracts/evidence.ts +25 -0
- package/src/pricing/contracts/index.ts +17 -0
- package/src/pricing/contracts/money.ts +32 -0
- package/src/pricing/contracts/offer.ts +42 -0
- package/src/pricing/contracts/offerPolicy.ts +17 -0
- package/src/pricing/contracts/policy.ts +26 -0
- package/src/pricing/contracts/provenance.ts +19 -0
- package/src/pricing/contracts/quote.ts +106 -0
- package/src/pricing/dbBackedCommerceQuoteHelpers.ts +256 -0
- package/src/pricing/dbBackedCommerceQuotePort.ts +260 -0
- package/src/pricing/dbBackedCommerceQuoteSnapshotVerifier.ts +49 -0
- package/src/pricing/index.ts +52 -0
- package/src/pricing/offerPolicyReadiness.ts +110 -0
- package/src/pricing/offerPolicySchemas.ts +23 -0
- package/src/pricing/offerPricingSchemas.ts +92 -0
- package/src/pricing/ports.ts +17 -0
- package/src/pricing/pricingPolicyToken.ts +119 -0
- package/src/pricing/quoteAcquisitionTerms.ts +10 -0
- package/src/pricing/quoteCodeRejectionDetails.ts +23 -0
- package/src/pricing/quotePorts.ts +58 -0
- package/src/pricing/quotePrimitives.ts +21 -0
- package/src/pricing/quotePromotionEvidence.ts +82 -0
- package/src/pricing/quoteSchemas.ts +230 -0
- package/src/pricing/subscriptionPricePolicy.ts +113 -0
- package/src/pricing/taxProfileGuard.ts +33 -0
- package/src/pricing/validation.ts +3 -0
- package/src/promotions/adminBindings.ts +53 -0
- package/src/promotions/adminPromotionCodesContracts.ts +244 -0
- package/src/promotions/adminPromotionCodesDataPort.ts +56 -0
- package/src/promotions/adminPromotionCodesHandler.ts +254 -0
- package/src/promotions/adminPromotionsContracts.ts +121 -0
- package/src/promotions/adminPromotionsDataPort.ts +48 -0
- package/src/promotions/adminPromotionsHandler.ts +72 -0
- package/src/promotions/contracts/index.ts +387 -0
- package/src/promotions/index.ts +22 -0
- package/src/promotions/promoDataPort.ts +65 -0
- package/src/promotions/promotionAcceptanceTelemetry.ts +73 -0
- package/src/promotions/promotionBenefitDefinition.ts +48 -0
- package/src/promotions/promotionClaimSweepPort.ts +23 -0
- package/src/promotions/promotionClaims.ts +70 -0
- package/src/promotions/promotionCodePreview.ts +183 -0
- package/src/promotions/promotionCodeQuotePort.ts +35 -0
- package/src/promotions/promotionQuoteAcceptance.ts +284 -0
- package/src/promotions/promotionQuoteBinding.ts +158 -0
- package/src/promotions/quoteAutomaticPromotions.ts +58 -0
- package/src/promotions/quotePromoDiscounts.ts +185 -0
- package/src/promotions/quotePromotionCodeAdjustments.ts +277 -0
- package/src/promotions/quotePromotionV2.ts +223 -0
- package/src/promotions/sql.ts +5 -0
- package/src/promotions/validation.ts +3 -0
- package/src/shipping/addressCanonLookupHandler.ts +114 -0
- package/src/shipping/addressCanonical.ts +31 -0
- package/src/shipping/addressPorts.ts +48 -0
- package/src/shipping/addressSchemas.ts +28 -0
- package/src/shipping/adminShippingRateHandler.ts +72 -0
- package/src/shipping/contracts/address.ts +71 -0
- package/src/shipping/contracts/delivery.ts +114 -0
- package/src/shipping/contracts/index.ts +18 -0
- package/src/shipping/contracts/shippingRate.ts +7 -0
- package/src/shipping/customerAddressesHandler.ts +100 -0
- package/src/shipping/customerSelfServiceAddressModels.ts +124 -0
- package/src/shipping/deliverySelectionHandler.ts +94 -0
- package/src/shipping/deliverySelectionPort.ts +10 -0
- package/src/shipping/deliverySelectionSummary.ts +56 -0
- package/src/shipping/handlerSchemas.ts +19 -0
- package/src/shipping/index.ts +23 -0
- package/src/shipping/pickupPointSearchPort.ts +8 -0
- package/src/shipping/readDeliverySelectionEvidence.ts +51 -0
- package/src/shipping/shippingRatePorts.ts +36 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import type {
|
|
3
|
+
PromotionCodeBenefit,
|
|
4
|
+
PromotionCodePreviewRequest,
|
|
5
|
+
PromotionCodePreviewResponse,
|
|
6
|
+
} from "./contracts/index.js";
|
|
7
|
+
import { COMMERCE_CONTRACT_VERSION } from "../pricing/index.js";
|
|
8
|
+
import {
|
|
9
|
+
evaluatePromotionAdjustmentsV2,
|
|
10
|
+
type PromotionAdjustmentCandidate,
|
|
11
|
+
} from "@openlup/core/promo";
|
|
12
|
+
const CROCKFORD_BASE32 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
13
|
+
export const PROMOTION_ENGINE_VERSION = "promotion-engine.v2" as const;
|
|
14
|
+
|
|
15
|
+
export function createPromotionCodePreview({ minimumProductPayableMinor: MINIMUM_PRODUCT_PAYABLE_MINOR }: { minimumProductPayableMinor: number }) {
|
|
16
|
+
function generatePromotionCode(): string {
|
|
17
|
+
const bytes = randomBytes(10);
|
|
18
|
+
let bits = 0;
|
|
19
|
+
let buffer = 0;
|
|
20
|
+
let code = "";
|
|
21
|
+
for (const byte of bytes) {
|
|
22
|
+
buffer = (buffer << 8) | byte;
|
|
23
|
+
bits += 8;
|
|
24
|
+
while (bits >= 5) {
|
|
25
|
+
bits -= 5;
|
|
26
|
+
code += CROCKFORD_BASE32[(buffer >>> bits) & 31];
|
|
27
|
+
buffer &= (1 << bits) - 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return code;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function normalizePromotionCode(code: string): string {
|
|
34
|
+
return code.trim().toUpperCase();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function promotionPreviewProof(input: PromotionCodePreviewRequest, secret: string): string {
|
|
38
|
+
assertPreviewSecret(secret);
|
|
39
|
+
assertSupportedPreviewBenefits(input);
|
|
40
|
+
return createHmac("sha256", secret).update(previewProofPayload(input)).digest("base64url");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function verifyPromotionPreviewProof(
|
|
44
|
+
input: PromotionCodePreviewRequest,
|
|
45
|
+
proof: string,
|
|
46
|
+
secret: string,
|
|
47
|
+
): boolean {
|
|
48
|
+
const expected = promotionPreviewProof(input, secret);
|
|
49
|
+
const expectedBytes = Buffer.from(expected);
|
|
50
|
+
const actualBytes = Buffer.from(proof);
|
|
51
|
+
return expectedBytes.length === actualBytes.length && timingSafeEqual(expectedBytes, actualBytes);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function previewPromotionCode(
|
|
55
|
+
input: PromotionCodePreviewRequest,
|
|
56
|
+
secret: string,
|
|
57
|
+
): PromotionCodePreviewResponse {
|
|
58
|
+
assertSupportedPreviewBenefits(input);
|
|
59
|
+
const eligible = input.context.referenceProductMinor >= input.minimumReferenceMinor;
|
|
60
|
+
const results = (["one_time", "subscription_initial"] as const).map((scope) => {
|
|
61
|
+
const currentProductMinor =
|
|
62
|
+
scope === "one_time"
|
|
63
|
+
? input.context.oneTimeProductMinor
|
|
64
|
+
: input.context.subscriptionProductMinor;
|
|
65
|
+
const candidates = eligible
|
|
66
|
+
? input.benefits
|
|
67
|
+
.map((benefit) => toCandidate(benefit, input.scopes, currentProductMinor))
|
|
68
|
+
.filter((candidate): candidate is PromotionAdjustmentCandidate => candidate !== null)
|
|
69
|
+
: [];
|
|
70
|
+
const result = evaluatePromotionAdjustmentsV2(
|
|
71
|
+
{
|
|
72
|
+
purchaseScope: scope,
|
|
73
|
+
referenceProductMinor: input.context.referenceProductMinor,
|
|
74
|
+
currentProductMinor,
|
|
75
|
+
shippingMinor: input.context.shippingMinor,
|
|
76
|
+
minimumProductPayableMinor: MINIMUM_PRODUCT_PAYABLE_MINOR,
|
|
77
|
+
},
|
|
78
|
+
candidates,
|
|
79
|
+
);
|
|
80
|
+
return {
|
|
81
|
+
scope,
|
|
82
|
+
productPayableMinor: result.productPayableMinor,
|
|
83
|
+
shippingPayableMinor: result.shippingPayableMinor,
|
|
84
|
+
effectiveProductDiscountBps: result.effectiveProductDiscountBps,
|
|
85
|
+
winner: result.adjustments.some((adjustment) => adjustment.source === "code")
|
|
86
|
+
? ("code" as const)
|
|
87
|
+
: ("automatic" as const),
|
|
88
|
+
floorApplied: result.adjustments.some((adjustment) => adjustment.floorApplied),
|
|
89
|
+
adjustments: result.adjustments.map((adjustment) => ({
|
|
90
|
+
lane: adjustment.lane,
|
|
91
|
+
kind: input.promotionEngineVersion === "promotion-engine.v1"
|
|
92
|
+
&& adjustment.promotionId === "preview-product"
|
|
93
|
+
&& input.benefits.some((benefit) => benefit.lane === "product" && benefit.kind === "percentage")
|
|
94
|
+
? ("percentage" as const)
|
|
95
|
+
: adjustment.kind,
|
|
96
|
+
amountOffMinor: adjustment.amountOffMinor,
|
|
97
|
+
beforeMinor: adjustment.beforeMinor,
|
|
98
|
+
afterMinor: adjustment.afterMinor,
|
|
99
|
+
})),
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
contractVersion: COMMERCE_CONTRACT_VERSION,
|
|
104
|
+
promotionEngineVersion: input.promotionEngineVersion,
|
|
105
|
+
previewProof: promotionPreviewProof(input, secret),
|
|
106
|
+
results,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function previewProofPayload(input: PromotionCodePreviewRequest): string {
|
|
111
|
+
return stableJson({
|
|
112
|
+
promotionEngineVersion: input.promotionEngineVersion,
|
|
113
|
+
minimumProductPayableMinor: MINIMUM_PRODUCT_PAYABLE_MINOR,
|
|
114
|
+
minimumReferenceMinor: input.minimumReferenceMinor,
|
|
115
|
+
benefits: input.benefits,
|
|
116
|
+
scopes: input.scopes,
|
|
117
|
+
context: input.context,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function assertPreviewSecret(secret: string): void {
|
|
122
|
+
if (Buffer.byteLength(secret, "utf8") < 32) {
|
|
123
|
+
throw new RangeError("promotion_preview_secret_too_short");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function assertSupportedPreviewBenefits(input: PromotionCodePreviewRequest): void {
|
|
128
|
+
if (input.benefits.some((benefit) => "validationState" in benefit)) {
|
|
129
|
+
throw new RangeError("promotion_preview_unsupported_legacy_value");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function toCandidate(
|
|
134
|
+
benefit: PromotionCodeBenefit,
|
|
135
|
+
scopes: PromotionCodePreviewRequest["scopes"],
|
|
136
|
+
currentProductMinor: number,
|
|
137
|
+
): PromotionAdjustmentCandidate | null {
|
|
138
|
+
const base = {
|
|
139
|
+
promotionId: `preview-${benefit.lane}`,
|
|
140
|
+
codeId: "preview-code",
|
|
141
|
+
source: "code" as const,
|
|
142
|
+
name: "Promotion code preview",
|
|
143
|
+
scopes,
|
|
144
|
+
};
|
|
145
|
+
if ("validationState" in benefit) {
|
|
146
|
+
throw new RangeError("promotion_preview_unsupported_legacy_value");
|
|
147
|
+
}
|
|
148
|
+
if (("valueBps" in benefit && benefit.valueBps === 0)
|
|
149
|
+
|| ("valueMinor" in benefit && benefit.valueMinor === 0)) return null;
|
|
150
|
+
if (benefit.kind === "target_percentage") return { ...base, ...benefit };
|
|
151
|
+
if (benefit.kind === "percentage" && benefit.lane === "product") {
|
|
152
|
+
const valueMinor = benefit.valueBps >= 10_000
|
|
153
|
+
? currentProductMinor
|
|
154
|
+
: Number((BigInt(currentProductMinor) * BigInt(benefit.valueBps)) / 10_000n);
|
|
155
|
+
return {
|
|
156
|
+
...base,
|
|
157
|
+
lane: "product",
|
|
158
|
+
kind: "fixed_amount",
|
|
159
|
+
valueMinor,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (benefit.kind === "percentage" && benefit.lane === "shipping" && benefit.valueBps >= 10_000) {
|
|
163
|
+
return { ...base, lane: "shipping", kind: "free_shipping" };
|
|
164
|
+
}
|
|
165
|
+
if (benefit.kind === "percentage") return { ...base, ...benefit };
|
|
166
|
+
if (benefit.kind === "fixed_amount") return { ...base, ...benefit };
|
|
167
|
+
return { ...base, ...benefit };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function stableJson(value: unknown): string {
|
|
171
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
172
|
+
if (value && typeof value === "object") {
|
|
173
|
+
const record = value as Record<string, unknown>;
|
|
174
|
+
return `{${Object.keys(record)
|
|
175
|
+
.sort()
|
|
176
|
+
.map((key) => `${JSON.stringify(key)}:${stableJson(record[key])}`)
|
|
177
|
+
.join(",")}}`;
|
|
178
|
+
}
|
|
179
|
+
return JSON.stringify(value);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { generatePromotionCode, normalizePromotionCode, promotionPreviewProof, verifyPromotionPreviewProof, previewPromotionCode };
|
|
183
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PromotionAdjustmentCandidate,
|
|
3
|
+
PromotionPurchaseScope,
|
|
4
|
+
} from "@openlup/core/promo";
|
|
5
|
+
import type {
|
|
6
|
+
CommerceCodeRejection,
|
|
7
|
+
CommerceCodeRejectionDetail,
|
|
8
|
+
} from "../pricing/index.js";
|
|
9
|
+
|
|
10
|
+
export type ResolvedPromotionCodeCandidate = PromotionAdjustmentCandidate & {
|
|
11
|
+
codeRevision: number;
|
|
12
|
+
definitionFingerprint: string;
|
|
13
|
+
minimumReferenceMinor: number;
|
|
14
|
+
validTo: string | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export interface ResolvePromotionCodeQuoteInput {
|
|
18
|
+
codes: readonly string[];
|
|
19
|
+
clientId: string | null;
|
|
20
|
+
purchaseScope: PromotionPurchaseScope;
|
|
21
|
+
referenceProductMinor: number;
|
|
22
|
+
atTime: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PromotionCodeQuoteResolution {
|
|
26
|
+
candidates: ResolvedPromotionCodeCandidate[];
|
|
27
|
+
codeRejections: CommerceCodeRejection[];
|
|
28
|
+
/** Additive v2 RPC detail; old RPC fallback returns an empty array. */
|
|
29
|
+
codeRejectionDetails: CommerceCodeRejectionDetail[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Advisory quote read only. Capacity is authoritatively claimed by the order transaction. */
|
|
33
|
+
export interface PromotionCodeQuotePort {
|
|
34
|
+
resolve(input: ResolvePromotionCodeQuoteInput): Promise<PromotionCodeQuoteResolution>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import type { ResolvedAcquisitionTerms } from "../pricing/index.js";
|
|
2
|
+
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import type { CommerceQuote, CommerceQuoteDiscount } from "../pricing/index.js";
|
|
5
|
+
import type { PromotionAcceptanceTelemetry } from "./promotionAcceptanceTelemetry.js";
|
|
6
|
+
import {
|
|
7
|
+
projectPromotionQuoteMoney,
|
|
8
|
+
promotionQuoteMoneySections,
|
|
9
|
+
PROMOTION_QUOTE_MONEY_SECTIONS,
|
|
10
|
+
stableJson,
|
|
11
|
+
type PromotionQuoteMismatchField,
|
|
12
|
+
} from "./promotionQuoteBinding.js";
|
|
13
|
+
export const PROMOTION_ACCEPTANCE_MAX_TTL_MS = 72 * 60 * 60 * 1_000;
|
|
14
|
+
export const PROMOTION_ACCEPTANCE_CLOCK_SKEW_MS = 60_000;
|
|
15
|
+
const payloadSchema = z.object({
|
|
16
|
+
v: z.literal(1),
|
|
17
|
+
kid: z.string().regex(/^[0-9a-f]{16}$/),
|
|
18
|
+
iat: z.number().int().nonnegative(),
|
|
19
|
+
exp: z.number().int().positive(),
|
|
20
|
+
engine: z.literal("promotion-engine.v2"),
|
|
21
|
+
requestBinding: z.string().regex(/^[0-9a-f]{64}$/),
|
|
22
|
+
codeBinding: z.string().regex(/^[0-9a-f]{64}$/),
|
|
23
|
+
quoteBinding: z.string().regex(/^[0-9a-f]{64}$/),
|
|
24
|
+
// Legacy payloads still parse, but their whole-quote binding is rejected.
|
|
25
|
+
// Quote refresh issues a new money-bound token; missing sections report other.
|
|
26
|
+
sectionBindings: z.object(Object.fromEntries(PROMOTION_QUOTE_MONEY_SECTIONS
|
|
27
|
+
.map((section) => [section, z.string().regex(/^[0-9a-f]{64}$/)])) as Record<
|
|
28
|
+
PromotionQuoteMoneySectionKey, z.ZodString>).strict().optional(),
|
|
29
|
+
totalMinor: z.number().int().nonnegative(),
|
|
30
|
+
currency: z.string().length(3),
|
|
31
|
+
}).strict();
|
|
32
|
+
type PromotionQuoteMoneySectionKey = (typeof PROMOTION_QUOTE_MONEY_SECTIONS)[number];
|
|
33
|
+
export interface PromotionAcceptanceKeyring {
|
|
34
|
+
current: string;
|
|
35
|
+
previous?: string | null;
|
|
36
|
+
}
|
|
37
|
+
export type PromotionAcceptanceDiagnostic = {
|
|
38
|
+
accepted: boolean;
|
|
39
|
+
reason: PromotionAcceptanceTelemetry["reason"];
|
|
40
|
+
keySlot: PromotionAcceptanceTelemetry["keySlot"];
|
|
41
|
+
expiryBucket: PromotionAcceptanceTelemetry["expiryBucket"];
|
|
42
|
+
/** Present only on `quote_mismatch`: which money section diverged. */
|
|
43
|
+
mismatchField?: PromotionQuoteMismatchField;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export function createPromotionQuoteAcceptance<Request extends { promoCodes: string[] }>({ projectRequest }: { projectRequest(request: Request): unknown }) {
|
|
47
|
+
function issuePromotionQuoteAcceptance(input: {
|
|
48
|
+
request: Request;
|
|
49
|
+
quote: CommerceQuote;
|
|
50
|
+
acquisitionTerms?: ResolvedAcquisitionTerms;
|
|
51
|
+
keyring: PromotionAcceptanceKeyring;
|
|
52
|
+
now?: Date;
|
|
53
|
+
}): string | null {
|
|
54
|
+
return issuePromotionQuoteAcceptanceWithOutcome(input).token;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function issuePromotionQuoteAcceptanceWithOutcome(input: {
|
|
58
|
+
request: Request;
|
|
59
|
+
quote: CommerceQuote;
|
|
60
|
+
acquisitionTerms?: ResolvedAcquisitionTerms;
|
|
61
|
+
keyring: PromotionAcceptanceKeyring;
|
|
62
|
+
now?: Date;
|
|
63
|
+
}): { token: string | null; diagnostic: PromotionAcceptanceDiagnostic } {
|
|
64
|
+
const evidence = v2Discounts(input.quote);
|
|
65
|
+
if (evidence.length === 0 && !input.acquisitionTerms) return {
|
|
66
|
+
token: null,
|
|
67
|
+
diagnostic: rejected("no_v2_adjustment"),
|
|
68
|
+
};
|
|
69
|
+
assertSecret(input.keyring.current);
|
|
70
|
+
const nowMs = (input.now ?? new Date()).getTime();
|
|
71
|
+
const codeExpiry = Math.min(...evidence.map((discount) =>
|
|
72
|
+
discount.promotionCodeValidTo ? Date.parse(discount.promotionCodeValidTo) : Number.POSITIVE_INFINITY));
|
|
73
|
+
const exp = Math.min(nowMs + PROMOTION_ACCEPTANCE_MAX_TTL_MS, codeExpiry);
|
|
74
|
+
if (!Number.isFinite(exp) || exp <= nowMs) return {
|
|
75
|
+
token: null,
|
|
76
|
+
diagnostic: rejected("ttl_invalid"),
|
|
77
|
+
};
|
|
78
|
+
const payload = payloadSchema.parse({
|
|
79
|
+
v: 1,
|
|
80
|
+
kid: keyId(input.keyring.current),
|
|
81
|
+
iat: nowMs,
|
|
82
|
+
exp,
|
|
83
|
+
engine: "promotion-engine.v2",
|
|
84
|
+
requestBinding: requestBinding(input.request, input.keyring.current),
|
|
85
|
+
codeBinding: codeBinding(input.request.promoCodes, input.keyring.current),
|
|
86
|
+
quoteBinding: quoteBinding(input.quote, input.keyring.current, input.acquisitionTerms),
|
|
87
|
+
sectionBindings: sectionBindings(input.quote, input.keyring.current, input.acquisitionTerms),
|
|
88
|
+
totalMinor: input.quote.totalGross.amountMinor,
|
|
89
|
+
currency: input.quote.totalGross.currency,
|
|
90
|
+
});
|
|
91
|
+
const encoded = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
92
|
+
return {
|
|
93
|
+
token: `${encoded}.${sign(encoded, input.keyring.current)}`,
|
|
94
|
+
diagnostic: {
|
|
95
|
+
accepted: true,
|
|
96
|
+
reason: "issued",
|
|
97
|
+
keySlot: "current",
|
|
98
|
+
expiryBucket: expiryBucket(exp, nowMs),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function verifyPromotionQuoteAcceptance(input: {
|
|
104
|
+
token: string;
|
|
105
|
+
request: Request;
|
|
106
|
+
quote: CommerceQuote;
|
|
107
|
+
acquisitionTerms?: ResolvedAcquisitionTerms;
|
|
108
|
+
expectedTotal: { amountMinor: number; currency: string };
|
|
109
|
+
keyring: PromotionAcceptanceKeyring;
|
|
110
|
+
now?: Date;
|
|
111
|
+
}): boolean {
|
|
112
|
+
return verifyPromotionQuoteAcceptanceWithOutcome(input).accepted;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function verifyPromotionQuoteAcceptanceWithOutcome(input: {
|
|
116
|
+
token: string;
|
|
117
|
+
request: Request;
|
|
118
|
+
quote: CommerceQuote;
|
|
119
|
+
acquisitionTerms?: ResolvedAcquisitionTerms;
|
|
120
|
+
expectedTotal: { amountMinor: number; currency: string };
|
|
121
|
+
keyring: PromotionAcceptanceKeyring;
|
|
122
|
+
now?: Date;
|
|
123
|
+
}): PromotionAcceptanceDiagnostic {
|
|
124
|
+
const verified = verifyEnvelopeWithOutcome(input.token, input.keyring, input.now ?? new Date());
|
|
125
|
+
if (verified.verified === false) return verified.diagnostic;
|
|
126
|
+
const { payload, secret } = verified;
|
|
127
|
+
const base = { keySlot: verified.keySlot, expiryBucket: verified.expiryBucket };
|
|
128
|
+
if (payload.requestBinding !== requestBinding(input.request, secret)) {
|
|
129
|
+
return { accepted: false, reason: "request_mismatch", ...base };
|
|
130
|
+
}
|
|
131
|
+
if (payload.codeBinding !== codeBinding(input.request.promoCodes, secret)) {
|
|
132
|
+
return { accepted: false, reason: "code_mismatch", ...base };
|
|
133
|
+
}
|
|
134
|
+
if (payload.quoteBinding !== quoteBinding(input.quote, secret, input.acquisitionTerms)) {
|
|
135
|
+
const mismatchField = namedMismatchField(payload.sectionBindings, input.quote, secret, input.acquisitionTerms);
|
|
136
|
+
return { accepted: false, reason: "quote_mismatch", mismatchField, ...base };
|
|
137
|
+
}
|
|
138
|
+
if (payload.totalMinor !== input.expectedTotal.amountMinor) {
|
|
139
|
+
return { accepted: false, reason: "total_mismatch", ...base };
|
|
140
|
+
}
|
|
141
|
+
if (payload.currency !== input.expectedTotal.currency) {
|
|
142
|
+
return { accepted: false, reason: "currency_mismatch", ...base };
|
|
143
|
+
}
|
|
144
|
+
if (v2Discounts(input.quote).length === 0 && !input.acquisitionTerms) {
|
|
145
|
+
return { accepted: false, reason: "no_v2_adjustment_in_quote", ...base };
|
|
146
|
+
}
|
|
147
|
+
return { accepted: true, reason: "accepted", ...base };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function verifyEnvelopeWithOutcome(
|
|
151
|
+
token: string,
|
|
152
|
+
keyring: PromotionAcceptanceKeyring,
|
|
153
|
+
now: Date,
|
|
154
|
+
): ({
|
|
155
|
+
verified: true;
|
|
156
|
+
payload: z.infer<typeof payloadSchema>;
|
|
157
|
+
secret: string;
|
|
158
|
+
keySlot: "current" | "previous";
|
|
159
|
+
expiryBucket: PromotionAcceptanceTelemetry["expiryBucket"];
|
|
160
|
+
} | { verified: false; diagnostic: PromotionAcceptanceDiagnostic }) {
|
|
161
|
+
const [encoded, signature, extra] = token.split(".");
|
|
162
|
+
if (!encoded || !signature || extra || encoded.length > 8_192 || signature.length !== 43) {
|
|
163
|
+
return { verified: false, diagnostic: rejected("malformed") };
|
|
164
|
+
}
|
|
165
|
+
let parsed: unknown;
|
|
166
|
+
try {
|
|
167
|
+
parsed = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
|
|
168
|
+
} catch {
|
|
169
|
+
return { verified: false, diagnostic: rejected("malformed") };
|
|
170
|
+
}
|
|
171
|
+
const payload = payloadSchema.safeParse(parsed);
|
|
172
|
+
if (!payload.success) return { verified: false, diagnostic: rejected("malformed") };
|
|
173
|
+
const candidates = [
|
|
174
|
+
{ slot: "current" as const, secret: keyring.current },
|
|
175
|
+
{ slot: "previous" as const, secret: keyring.previous },
|
|
176
|
+
].filter((candidate): candidate is { slot: "current" | "previous"; secret: string } =>
|
|
177
|
+
typeof candidate.secret === "string" && candidate.secret.length >= 32);
|
|
178
|
+
const candidate = candidates.find((value) => keyId(value.secret) === payload.data.kid);
|
|
179
|
+
if (!candidate) return { verified: false, diagnostic: rejected("unknown_key") };
|
|
180
|
+
if (!safeEqual(signature, sign(encoded, candidate.secret))) {
|
|
181
|
+
return { verified: false, diagnostic: rejected("signature_invalid") };
|
|
182
|
+
}
|
|
183
|
+
const nowMs = now.getTime();
|
|
184
|
+
const safeBase = { keySlot: candidate.slot, expiryBucket: expiryBucket(payload.data.exp, nowMs) };
|
|
185
|
+
if (payload.data.exp <= payload.data.iat ||
|
|
186
|
+
payload.data.exp - payload.data.iat > PROMOTION_ACCEPTANCE_MAX_TTL_MS) {
|
|
187
|
+
return { verified: false, diagnostic: { accepted: false, reason: "ttl_invalid", ...safeBase } };
|
|
188
|
+
}
|
|
189
|
+
if (payload.data.iat > nowMs + PROMOTION_ACCEPTANCE_CLOCK_SKEW_MS) {
|
|
190
|
+
return { verified: false, diagnostic: { accepted: false, reason: "not_yet_valid", ...safeBase } };
|
|
191
|
+
}
|
|
192
|
+
if (nowMs >= payload.data.exp) {
|
|
193
|
+
return { verified: false, diagnostic: { accepted: false, reason: "expired", ...safeBase } };
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
verified: true,
|
|
197
|
+
payload: payload.data,
|
|
198
|
+
secret: candidate.secret,
|
|
199
|
+
keySlot: candidate.slot,
|
|
200
|
+
expiryBucket: expiryBucket(payload.data.exp, nowMs),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function rejected(reason: PromotionAcceptanceTelemetry["reason"]): PromotionAcceptanceDiagnostic {
|
|
205
|
+
return { accepted: false, reason, keySlot: "none", expiryBucket: "none" };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function expiryBucket(exp: number, now: number): PromotionAcceptanceTelemetry["expiryBucket"] {
|
|
209
|
+
const remaining = exp - now;
|
|
210
|
+
if (remaining <= 0) return "expired";
|
|
211
|
+
if (remaining < 60 * 60 * 1_000) return "lt_1h";
|
|
212
|
+
if (remaining < 24 * 60 * 60 * 1_000) return "1_24h";
|
|
213
|
+
return "24_72h";
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function v2Discounts(quote: CommerceQuote): CommerceQuoteDiscount[] {
|
|
217
|
+
return quote.discounts.filter((discount) =>
|
|
218
|
+
discount.promotionEngineVersion === "promotion-engine.v2" &&
|
|
219
|
+
discount.reasonCode === "promotion_code_v2");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function requestBinding(request: Request, secret: string): string {
|
|
223
|
+
return hmac(secret, stableJson(projectRequest(request)));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function codeBinding(codes: readonly string[], secret: string): string {
|
|
227
|
+
return hmac(secret, stableJson([...new Set(codes.map((code) => code.trim().toUpperCase()))].sort()));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function quoteBinding(quote: CommerceQuote, secret: string, acquisitionTerms?: ResolvedAcquisitionTerms): string {
|
|
231
|
+
return hmac(secret, stableJson(projectPromotionQuoteMoney(quote, acquisitionTerms)));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function sectionBindings(
|
|
235
|
+
quote: CommerceQuote,
|
|
236
|
+
secret: string,
|
|
237
|
+
acquisitionTerms?: ResolvedAcquisitionTerms,
|
|
238
|
+
): Record<PromotionQuoteMoneySectionKey, string> {
|
|
239
|
+
const sections = promotionQuoteMoneySections(quote, acquisitionTerms);
|
|
240
|
+
return Object.fromEntries(PROMOTION_QUOTE_MONEY_SECTIONS
|
|
241
|
+
.map((section) => [section, hmac(secret, stableJson(sections[section]))])) as Record<
|
|
242
|
+
PromotionQuoteMoneySectionKey, string>;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* The verifier holds only the issuer's HMACs, never the issued quote, so the
|
|
247
|
+
* differing section is found by comparing per-section hashes in a fixed order.
|
|
248
|
+
*/
|
|
249
|
+
function namedMismatchField(
|
|
250
|
+
issued: Record<PromotionQuoteMoneySectionKey, string> | undefined,
|
|
251
|
+
quote: CommerceQuote,
|
|
252
|
+
secret: string,
|
|
253
|
+
acquisitionTerms?: ResolvedAcquisitionTerms,
|
|
254
|
+
): PromotionQuoteMismatchField {
|
|
255
|
+
if (!issued) return "other";
|
|
256
|
+
const verified = sectionBindings(quote, secret, acquisitionTerms);
|
|
257
|
+
return PROMOTION_QUOTE_MONEY_SECTIONS
|
|
258
|
+
.find((section) => issued[section] !== verified[section]) ?? "other";
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function keyId(secret: string): string {
|
|
262
|
+
return createHash("sha256").update(secret).digest("hex").slice(0, 16);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function hmac(secret: string, value: string): string {
|
|
266
|
+
return createHmac("sha256", secret).update(value).digest("hex");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function sign(encoded: string, secret: string): string {
|
|
270
|
+
return createHmac("sha256", secret).update(encoded).digest("base64url");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function safeEqual(left: string, right: string): boolean {
|
|
274
|
+
const a = Buffer.from(left);
|
|
275
|
+
const b = Buffer.from(right);
|
|
276
|
+
return a.length === b.length && timingSafeEqual(a, b);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function assertSecret(secret: string): void {
|
|
280
|
+
if (secret.length < 32) throw new Error("promotion_acceptance_secret_invalid");
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return { issuePromotionQuoteAcceptance, issuePromotionQuoteAcceptanceWithOutcome, verifyPromotionQuoteAcceptance, verifyPromotionQuoteAcceptanceWithOutcome };
|
|
284
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { acquisitionQuoteBinding, type ResolvedAcquisitionTerms } from "../pricing/index.js";
|
|
2
|
+
import type {
|
|
3
|
+
CommerceMoney,
|
|
4
|
+
CommerceQuote,
|
|
5
|
+
CommerceQuoteDiscount,
|
|
6
|
+
} from "../pricing/index.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The canonical money projection an acceptance token binds.
|
|
10
|
+
*
|
|
11
|
+
* ⛔ The token protects **what the customer pays**, never how it was presented
|
|
12
|
+
* or which server-only evidence produced it. Everything outside this projection
|
|
13
|
+
* is deliberately unbound: `label`, `reasonCode`, `customerSemantic`, `code`,
|
|
14
|
+
* `promotionCodeRevision`, `promotionCodeScopes`, `promotionMinimumReferenceMinor`,
|
|
15
|
+
* `promotionCodeValidTo`, `floorApplied`, `context`, `codeRejections`,
|
|
16
|
+
* `codeRejectionDetails`, `pricingComponents` and `catalogFacts`. Those differ
|
|
17
|
+
* legitimately between the two surfaces that share one token — the public quote
|
|
18
|
+
* route signs the contract-parsed public projection while the checkout guard
|
|
19
|
+
* verifies the raw server-authoritative quote, which carries `catalogFacts`
|
|
20
|
+
* (with a per-request `atTime`) that the public projection strips — so binding
|
|
21
|
+
* them turned every strict-path v2 code checkout into a permanent rejection.
|
|
22
|
+
*
|
|
23
|
+
* What stays bound is every amount and every discount identity: change a price,
|
|
24
|
+
* a quantity, a tax split, shipping, a discount amount, which promotion granted
|
|
25
|
+
* it, or what it applies to, and the token stops verifying.
|
|
26
|
+
*/
|
|
27
|
+
export interface PromotionQuoteMoneyLine {
|
|
28
|
+
sku: string;
|
|
29
|
+
quantity: number;
|
|
30
|
+
unitPriceGross: CommerceMoney;
|
|
31
|
+
lineSubtotalGross: CommerceMoney;
|
|
32
|
+
tax: {
|
|
33
|
+
vatRateBps: number;
|
|
34
|
+
netAmount: CommerceMoney;
|
|
35
|
+
vatAmount: CommerceMoney;
|
|
36
|
+
grossAmount: CommerceMoney;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PromotionQuoteMoneyDiscount {
|
|
41
|
+
promotionId: string;
|
|
42
|
+
appliesTo: CommerceQuoteDiscount["appliesTo"];
|
|
43
|
+
amountOffMinor: number;
|
|
44
|
+
promotionCodeId: string | null;
|
|
45
|
+
promotionDefinitionFingerprint: string | null;
|
|
46
|
+
promotionBenefitKind: NonNullable<CommerceQuoteDiscount["promotionBenefitKind"]> | null;
|
|
47
|
+
promotionBenefitValueBps: number | null;
|
|
48
|
+
promotionBenefitValueMinor: number | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface PromotionQuoteMoneyProjection {
|
|
52
|
+
acquisitionTerms?: ResolvedAcquisitionTerms;
|
|
53
|
+
currency: string;
|
|
54
|
+
totalGross: CommerceMoney;
|
|
55
|
+
netTotal: CommerceMoney;
|
|
56
|
+
taxTotal: CommerceMoney;
|
|
57
|
+
subtotalGross: CommerceMoney;
|
|
58
|
+
discountTotalGross: CommerceMoney;
|
|
59
|
+
shippingGross: CommerceMoney | null;
|
|
60
|
+
shippingDiscountGross: CommerceMoney | null;
|
|
61
|
+
lines: PromotionQuoteMoneyLine[];
|
|
62
|
+
discounts: PromotionQuoteMoneyDiscount[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The five sections the token hashes separately so a mismatch can name itself. */
|
|
66
|
+
export const PROMOTION_QUOTE_MONEY_SECTIONS = [
|
|
67
|
+
"lines",
|
|
68
|
+
"discounts",
|
|
69
|
+
"shipping",
|
|
70
|
+
"totals",
|
|
71
|
+
"currency",
|
|
72
|
+
] as const;
|
|
73
|
+
|
|
74
|
+
export type PromotionQuoteMoneySection = (typeof PROMOTION_QUOTE_MONEY_SECTIONS)[number];
|
|
75
|
+
|
|
76
|
+
/** `other` is the honest answer for a token minted before section bindings existed. */
|
|
77
|
+
export const PROMOTION_QUOTE_MISMATCH_FIELDS = [
|
|
78
|
+
...PROMOTION_QUOTE_MONEY_SECTIONS,
|
|
79
|
+
"other",
|
|
80
|
+
] as const;
|
|
81
|
+
|
|
82
|
+
export type PromotionQuoteMismatchField = (typeof PROMOTION_QUOTE_MISMATCH_FIELDS)[number];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Discount order is preserved: the promotion engine emits its lanes
|
|
86
|
+
* deterministically, so a reordering is a real evaluation difference.
|
|
87
|
+
*/
|
|
88
|
+
export function projectPromotionQuoteMoney(quote: CommerceQuote, acquisitionTerms?: ResolvedAcquisitionTerms): PromotionQuoteMoneyProjection {
|
|
89
|
+
return {
|
|
90
|
+
...acquisitionQuoteBinding(acquisitionTerms),
|
|
91
|
+
currency: quote.currency,
|
|
92
|
+
totalGross: quote.totalGross,
|
|
93
|
+
netTotal: quote.netTotal,
|
|
94
|
+
taxTotal: quote.taxTotal,
|
|
95
|
+
subtotalGross: quote.subtotalGross,
|
|
96
|
+
discountTotalGross: quote.discountTotalGross,
|
|
97
|
+
shippingGross: quote.shippingGross ?? null,
|
|
98
|
+
shippingDiscountGross: quote.shippingDiscountGross ?? null,
|
|
99
|
+
lines: quote.lines.map((line) => ({
|
|
100
|
+
sku: line.sku,
|
|
101
|
+
quantity: line.quantity,
|
|
102
|
+
unitPriceGross: line.unitPriceGross,
|
|
103
|
+
lineSubtotalGross: line.lineSubtotalGross,
|
|
104
|
+
tax: {
|
|
105
|
+
vatRateBps: line.tax.vatRateBps,
|
|
106
|
+
netAmount: line.tax.netAmount,
|
|
107
|
+
vatAmount: line.tax.vatAmount,
|
|
108
|
+
grossAmount: line.tax.grossAmount,
|
|
109
|
+
},
|
|
110
|
+
})),
|
|
111
|
+
discounts: quote.discounts.map((discount) => ({
|
|
112
|
+
promotionId: discount.promotionId,
|
|
113
|
+
appliesTo: discount.appliesTo,
|
|
114
|
+
amountOffMinor: discount.amountOffMinor,
|
|
115
|
+
promotionCodeId: discount.promotionCodeId ?? null,
|
|
116
|
+
promotionDefinitionFingerprint: discount.promotionDefinitionFingerprint ?? null,
|
|
117
|
+
promotionBenefitKind: discount.promotionBenefitKind ?? null,
|
|
118
|
+
promotionBenefitValueBps: discount.promotionBenefitValueBps ?? null,
|
|
119
|
+
promotionBenefitValueMinor: discount.promotionBenefitValueMinor ?? null,
|
|
120
|
+
})),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Same projection, partitioned. The union of these five sections is the whole projection. */
|
|
125
|
+
export function promotionQuoteMoneySections(
|
|
126
|
+
quote: CommerceQuote,
|
|
127
|
+
acquisitionTerms?: ResolvedAcquisitionTerms,
|
|
128
|
+
): Record<PromotionQuoteMoneySection, unknown> {
|
|
129
|
+
const money = projectPromotionQuoteMoney(quote, acquisitionTerms);
|
|
130
|
+
return {
|
|
131
|
+
lines: money.lines,
|
|
132
|
+
discounts: money.discounts,
|
|
133
|
+
shipping: {
|
|
134
|
+
shippingGross: money.shippingGross,
|
|
135
|
+
shippingDiscountGross: money.shippingDiscountGross,
|
|
136
|
+
},
|
|
137
|
+
totals: {
|
|
138
|
+
...acquisitionQuoteBinding(money.acquisitionTerms),
|
|
139
|
+
totalGross: money.totalGross,
|
|
140
|
+
netTotal: money.netTotal,
|
|
141
|
+
taxTotal: money.taxTotal,
|
|
142
|
+
subtotalGross: money.subtotalGross,
|
|
143
|
+
discountTotalGross: money.discountTotalGross,
|
|
144
|
+
},
|
|
145
|
+
currency: money.currency,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Key-sorted, `undefined`-dropping JSON. Every acceptance binding hashes this shape. */
|
|
150
|
+
export function stableJson(value: unknown): string {
|
|
151
|
+
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
152
|
+
if (value && typeof value === "object") {
|
|
153
|
+
return `{${Object.entries(value).filter(([, item]) => item !== undefined)
|
|
154
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
155
|
+
.map(([key, item]) => `${JSON.stringify(key)}:${stableJson(item)}`).join(",")}}`;
|
|
156
|
+
}
|
|
157
|
+
return JSON.stringify(value);
|
|
158
|
+
}
|