@openlup/platform 0.17.0 → 0.19.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 +143 -0
- package/README.md +299 -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 +21 -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 +173 -0
- package/dist/catalog/bundleCatalogReadPort.js +36 -0
- package/dist/catalog/bundleCatalogStore.d.ts +5 -0
- package/dist/catalog/bundleCatalogStore.js +156 -0
- package/dist/catalog/bundlePriceSelection.d.ts +13 -0
- package/dist/catalog/bundlePriceSelection.js +26 -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 +241 -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/effectiveBundleCatalogQueries.d.ts +8 -0
- package/dist/catalog/effectiveBundleCatalogQueries.js +79 -0
- package/dist/catalog/effectiveBundleCatalogStore.d.ts +4 -0
- package/dist/catalog/effectiveBundleCatalogStore.js +156 -0
- package/dist/catalog/foundationSchemas.d.ts +98 -0
- package/dist/catalog/foundationSchemas.js +110 -0
- package/dist/catalog/index.d.ts +44 -0
- package/dist/catalog/index.js +26 -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 +3 -0
- package/dist/composition/index.js +3 -0
- package/dist/composition/inventoryContribution.d.ts +16 -0
- package/dist/composition/inventoryContribution.js +17 -0
- package/dist/composition/shippingContribution.d.ts +16 -0
- package/dist/composition/shippingContribution.js +17 -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/bindings.d.ts +35 -0
- package/dist/inventory/bindings.js +45 -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 +14 -0
- package/dist/inventory/index.js +11 -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 +28 -0
- package/dist/pricing/commercePriceAuthority.js +140 -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 +35 -0
- package/dist/pricing/commerceQuoteHandler.js +122 -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 +74 -0
- package/dist/pricing/dbBackedCommerceQuotePort.js +223 -0
- package/dist/pricing/dbBackedCommerceQuoteSnapshotVerifier.d.ts +4 -0
- package/dist/pricing/dbBackedCommerceQuoteSnapshotVerifier.js +25 -0
- package/dist/pricing/index.d.ts +52 -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/quoteShippingPromotions.d.ts +20 -0
- package/dist/pricing/quoteShippingPromotions.js +1 -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/commerceQuoteReadPreparation.d.ts +3 -0
- package/dist/promotions/commerceQuoteReadPreparation.js +27 -0
- package/dist/promotions/contracts/index.d.ts +387 -0
- package/dist/promotions/contracts/index.js +1 -0
- package/dist/promotions/index.d.ts +25 -0
- package/dist/promotions/index.js +22 -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 +70 -0
- package/dist/promotions/promotionQuoteAcceptance.js +202 -0
- package/dist/promotions/promotionQuoteBinding.d.ts +73 -0
- package/dist/promotions/promotionQuoteBinding.js +87 -0
- package/dist/promotions/quoteAcquisitionBinding.d.ts +6 -0
- package/dist/promotions/quoteAcquisitionBinding.js +1 -0
- package/dist/promotions/quoteAutomaticPromotions.d.ts +26 -0
- package/dist/promotions/quoteAutomaticPromotions.js +60 -0
- package/dist/promotions/quotePromoDiscounts.d.ts +36 -0
- package/dist/promotions/quotePromoDiscounts.js +146 -0
- package/dist/promotions/quotePromotionCodeAdjustments.d.ts +27 -0
- package/dist/promotions/quotePromotionCodeAdjustments.js +223 -0
- package/dist/promotions/quotePromotionV2.d.ts +30 -0
- package/dist/promotions/quotePromotionV2.js +186 -0
- package/dist/promotions/quoteShippingPolicy.d.ts +23 -0
- package/dist/promotions/quoteShippingPolicy.js +47 -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/bindings.d.ts +57 -0
- package/dist/shipping/bindings.js +46 -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 +4 -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/contracts/threshold.d.ts +22 -0
- package/dist/shipping/contracts/threshold.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 +20 -0
- package/dist/shipping/index.js +10 -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/dist/shipping/thresholdPolicy.d.ts +42 -0
- package/dist/shipping/thresholdPolicy.js +60 -0
- package/package.json +62 -2
- package/release-gates.json +263 -53
- 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 +263 -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 +181 -0
- package/src/catalog/bundleCatalogStore.ts +274 -0
- package/src/catalog/bundlePriceSelection.ts +25 -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/effectiveBundleCatalogQueries.ts +80 -0
- package/src/catalog/effectiveBundleCatalogStore.ts +208 -0
- package/src/catalog/foundationSchemas.ts +123 -0
- package/src/catalog/index.ts +44 -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 +3 -0
- package/src/composition/inventoryContribution.ts +24 -0
- package/src/composition/shippingContribution.ts +24 -0
- package/src/inventory/adminInventory.ts +251 -0
- package/src/inventory/bindings.ts +61 -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 +22 -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 +169 -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 +199 -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 +280 -0
- package/src/pricing/dbBackedCommerceQuoteSnapshotVerifier.ts +49 -0
- package/src/pricing/index.ts +53 -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/quoteShippingPromotions.ts +21 -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/commerceQuoteReadPreparation.ts +29 -0
- package/src/promotions/contracts/index.ts +387 -0
- package/src/promotions/index.ts +25 -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 +291 -0
- package/src/promotions/promotionQuoteBinding.ts +163 -0
- package/src/promotions/quoteAcquisitionBinding.ts +7 -0
- package/src/promotions/quoteAutomaticPromotions.ts +84 -0
- package/src/promotions/quotePromoDiscounts.ts +194 -0
- package/src/promotions/quotePromotionCodeAdjustments.ts +277 -0
- package/src/promotions/quotePromotionV2.ts +239 -0
- package/src/promotions/quoteShippingPolicy.ts +61 -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/bindings.ts +74 -0
- package/src/shipping/contracts/address.ts +71 -0
- package/src/shipping/contracts/delivery.ts +114 -0
- package/src/shipping/contracts/index.ts +19 -0
- package/src/shipping/contracts/shippingRate.ts +7 -0
- package/src/shipping/contracts/threshold.ts +22 -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 +26 -0
- package/src/shipping/pickupPointSearchPort.ts +8 -0
- package/src/shipping/readDeliverySelectionEvidence.ts +51 -0
- package/src/shipping/shippingRatePorts.ts +36 -0
- package/src/shipping/thresholdPolicy.ts +65 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isValidGtin } from "./foundationSchemas.js";
|
|
2
|
+
import type { CatalogDraftPayload } from "./draftSchemas.js";
|
|
3
|
+
import {
|
|
4
|
+
canonicalCatalogOption, validateCatalogQuantity,
|
|
5
|
+
type CatalogDraftIssue, type CatalogProductTypeRegistry,
|
|
6
|
+
} from "./productTypeSchemas.js";
|
|
7
|
+
|
|
8
|
+
export interface CatalogDraftReadiness {
|
|
9
|
+
publication: { status: "incomplete" | "not_assessed"; issues: CatalogDraftIssue[] };
|
|
10
|
+
commercial: { status: "inactive"; issues: CatalogDraftIssue[] };
|
|
11
|
+
}
|
|
12
|
+
export type CatalogDraftValidation =
|
|
13
|
+
| { valid: false; issues: CatalogDraftIssue[] }
|
|
14
|
+
| { valid: true; readiness: CatalogDraftReadiness };
|
|
15
|
+
|
|
16
|
+
/** Supplied facts must be true; absent publish-time facts remain draft readiness issues. */
|
|
17
|
+
export function validateCatalogDraft(payload: CatalogDraftPayload, registry: CatalogProductTypeRegistry): CatalogDraftValidation {
|
|
18
|
+
const issues: CatalogDraftIssue[] = [];
|
|
19
|
+
const publication: CatalogDraftIssue[] = [];
|
|
20
|
+
const commercial: CatalogDraftIssue[] = [];
|
|
21
|
+
const add = (path: string, code: string) => issues.push({ path, code });
|
|
22
|
+
const missing = (path: string, code: string) => publication.push({ path, code });
|
|
23
|
+
const { product, skus } = payload;
|
|
24
|
+
const definition = registry.resolve(product.type);
|
|
25
|
+
if (!definition) return { valid: false, issues: [{ path: "product.type", code: "type_not_installed" }] };
|
|
26
|
+
const dimensions = new Map(definition.dimensions.map((dimension) => [dimension.key, dimension]));
|
|
27
|
+
const netContentKey = definition.dimensions.find((dimension) => dimension.kind === "quantity" && dimension.role === "net_content")?.key;
|
|
28
|
+
if (new Set(product.dimensions).size !== product.dimensions.length) add("product.dimensions", "duplicate_dimension");
|
|
29
|
+
product.dimensions.forEach((key) => { if (!dimensions.has(key)) add(`product.dimensions.${key}`, "dimension_not_installed"); });
|
|
30
|
+
if (product.sharedContent !== undefined) {
|
|
31
|
+
issues.push(...definition.validateContent(product.sharedContent).map((issue) => ({ ...issue, path: `product.sharedContent${issue.path ? `.${issue.path}` : ""}` })));
|
|
32
|
+
} else if (!product.documentRevision) missing("product.sharedContent", "content_missing");
|
|
33
|
+
if (product.documentRevision && product.documentRevision.productId !== product.id) add("product.documentRevision.productId", "foreign_product_reference");
|
|
34
|
+
if (product.primarySkuId && !skus.some((sku) => sku.id === product.primarySkuId)) add("product.primarySkuId", "primary_sku_not_in_product");
|
|
35
|
+
if (!product.primarySkuId) missing("product.primarySkuId", "primary_sku_missing");
|
|
36
|
+
if (!product.slug) missing("product.slug", "slug_missing");
|
|
37
|
+
if (!skus.length) missing("skus", "sku_missing");
|
|
38
|
+
const skuIds = new Set<string>();
|
|
39
|
+
const skuCodes = new Set<string>();
|
|
40
|
+
const combinations = new Set<string>();
|
|
41
|
+
const identifiers = new Set<string>();
|
|
42
|
+
skus.forEach((sku, index) => {
|
|
43
|
+
const path = `skus.${index}`;
|
|
44
|
+
if (sku.productId !== product.id) add(`${path}.productId`, "foreign_product_reference");
|
|
45
|
+
if (skuIds.has(sku.id)) add(`${path}.id`, "duplicate_sku_id");
|
|
46
|
+
skuIds.add(sku.id);
|
|
47
|
+
if (sku.code) {
|
|
48
|
+
if (skuCodes.has(sku.code)) add(`${path}.code`, "duplicate_sku_code");
|
|
49
|
+
skuCodes.add(sku.code);
|
|
50
|
+
} else missing(`${path}.code`, "sku_code_missing");
|
|
51
|
+
const optionKeys = Object.keys(sku.options);
|
|
52
|
+
for (const key of optionKeys) {
|
|
53
|
+
const option = sku.options[key];
|
|
54
|
+
const dimension = dimensions.get(key);
|
|
55
|
+
if (!product.dimensions.includes(key) || !dimension) { add(`${path}.options.${key}`, "dimension_not_declared"); continue; }
|
|
56
|
+
if (dimension.kind !== option.kind) { add(`${path}.options.${key}`, "option_type_invalid"); continue; }
|
|
57
|
+
if (dimension.kind === "choice" && option.kind === "choice" && !dimension.values.includes(option.value)) add(`${path}.options.${key}`, "option_value_invalid");
|
|
58
|
+
if (dimension.kind === "quantity" && option.kind === "quantity"
|
|
59
|
+
&& (option.value.dimension !== dimension.dimension || !dimension.units.includes(option.value.unit)
|
|
60
|
+
|| !validateCatalogQuantity(option.value, definition))) add(`${path}.options.${key}`, "option_quantity_invalid");
|
|
61
|
+
}
|
|
62
|
+
const absent = product.dimensions.filter((key) => !Object.prototype.hasOwnProperty.call(sku.options, key));
|
|
63
|
+
absent.forEach((key) => missing(`${path}.options.${key}`, "option_missing"));
|
|
64
|
+
if (!absent.length && optionKeys.length === product.dimensions.length) {
|
|
65
|
+
const combination = JSON.stringify([...product.dimensions].sort().map((key) => [key, canonicalCatalogOption(sku.options[key])]));
|
|
66
|
+
if (combinations.has(combination)) add(`${path}.options`, "duplicate_option_combination");
|
|
67
|
+
combinations.add(combination);
|
|
68
|
+
}
|
|
69
|
+
if (sku.netContent) {
|
|
70
|
+
if (!validateCatalogQuantity(sku.netContent, definition) || !definition.netContentUnits.includes(sku.netContent.unit)) add(`${path}.netContent`, "net_content_invalid");
|
|
71
|
+
} else missing(`${path}.netContent`, "net_content_missing");
|
|
72
|
+
const netContentOption = netContentKey === undefined ? undefined : sku.options[netContentKey];
|
|
73
|
+
if (netContentOption?.kind === "quantity" && sku.netContent
|
|
74
|
+
&& canonicalCatalogOption(netContentOption) !== canonicalCatalogOption({ kind: "quantity", value: sku.netContent })) add(`${path}.options.${netContentKey}`, "net_content_option_mismatch");
|
|
75
|
+
if (sku.grossMass && (sku.grossMass.dimension !== "mass" || !validateCatalogQuantity(sku.grossMass, definition))) add(`${path}.grossMass`, "gross_mass_invalid");
|
|
76
|
+
(sku.identifiers ?? []).forEach((identifier, identifierIndex) => {
|
|
77
|
+
const at = `${path}.identifiers.${identifierIndex}`;
|
|
78
|
+
// One GTIN is one identity in any 8-, 12-, 13- or 14-digit spelling, whatever its issuer text.
|
|
79
|
+
const gtin = identifier.scheme === "gs1:gtin" && isValidGtin(identifier.value) ? identifier.value.padStart(14, "0") : null;
|
|
80
|
+
const identity = JSON.stringify(gtin === null ? [identifier.scheme, identifier.issuer, identifier.value] : [identifier.scheme, gtin]);
|
|
81
|
+
if (identifiers.has(identity)) add(at, "duplicate_trade_identifier");
|
|
82
|
+
identifiers.add(identity);
|
|
83
|
+
if (identifier.scheme === "gs1:gtin" && gtin === null) add(at, "trade_identifier_invalid");
|
|
84
|
+
if (identifier.scheme !== "gs1:gtin" && identifier.scheme.startsWith("gs1:")) add(at, "trade_identifier_scheme_unsupported");
|
|
85
|
+
// Checked here, not in the wire schema, so a stored revision without a quantity stays readable.
|
|
86
|
+
if (identifier.packagingLevel === "case" ? (identifier.quantity ?? 0) < 2 : (identifier.quantity ?? 1) !== 1) add(`${at}.quantity`, "trade_identifier_quantity_invalid");
|
|
87
|
+
});
|
|
88
|
+
if (!sku.identifiers?.length) commercial.push({ path: `${path}.identifiers`, code: "channel_identity_not_assessed" });
|
|
89
|
+
if (!sku.identifiers?.some((identifier) => identifier.scheme === "gs1:gtin" && identifier.packagingLevel === "unit")) commercial.push({ path: `${path}.identifiers`, code: "unit_trade_identifier_missing" });
|
|
90
|
+
if (!sku.priceRef) commercial.push({ path: `${path}.priceRef`, code: "price_reference_missing" });
|
|
91
|
+
if (!sku.logisticsRef) commercial.push({ path: `${path}.logisticsRef`, code: "logistics_reference_missing" });
|
|
92
|
+
});
|
|
93
|
+
if (issues.length) return { valid: false, issues };
|
|
94
|
+
// Opaque references are not current pricing, stock, logistics or publication proof.
|
|
95
|
+
commercial.push({ path: "skus", code: "commercial_activation_not_assessed" });
|
|
96
|
+
return { valid: true, readiness: {
|
|
97
|
+
publication: { status: publication.length ? "incomplete" : "not_assessed", issues: publication },
|
|
98
|
+
commercial: { status: "inactive", issues: commercial },
|
|
99
|
+
} };
|
|
100
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/** Effective-authority SQL is isolated from the incumbent exported statements. */
|
|
2
|
+
const ANCHORS = `SELECT pe.unit_price_minor FROM public.price_entries pe
|
|
3
|
+
WHERE pe.variant_id = s.id AND pe.price_list_id = %LIST% AND pe.active
|
|
4
|
+
AND pe.min_qty = 1 AND pe.amount_kind = 'gross'
|
|
5
|
+
AND pe.valid_from <= $3::timestamptz AND (pe.valid_to IS NULL OR pe.valid_to > $3::timestamptz)
|
|
6
|
+
AND (pe.mode = $4::text OR (pe.mode = 'any' AND NOT EXISTS (
|
|
7
|
+
SELECT 1 FROM public.price_entries exact WHERE exact.variant_id = s.id
|
|
8
|
+
AND exact.price_list_id = pe.price_list_id AND exact.active AND exact.min_qty = 1
|
|
9
|
+
AND exact.amount_kind = 'gross' AND exact.mode = $4::text
|
|
10
|
+
AND exact.valid_from <= $3::timestamptz AND (exact.valid_to IS NULL OR exact.valid_to > $3::timestamptz))))`;
|
|
11
|
+
const FACTS = `s.status AS sku_status, s.sellable_standalone, s.sellable_in_subscription,
|
|
12
|
+
s.net_weight_g, pr.status AS product_status,
|
|
13
|
+
(pr.primary_sku_id IS NOT NULL AND revision.id IS NOT NULL) AS document_ready,
|
|
14
|
+
COALESCE((SELECT jsonb_agg(jsonb_build_object('issuer', identifier.issuer, 'normalizedValue', identifier.normalized_value,
|
|
15
|
+
'kind', identifier.identifier_kind, 'packKind', identifier.pack_kind, 'packQuantity', identifier.quantity, 'isPrimary', identifier.is_primary))
|
|
16
|
+
FROM public.catalog_sku_identifiers identifier WHERE identifier.catalog_sku_id = s.id), '[]'::jsonb) AS identifiers`;
|
|
17
|
+
const REFERENCE = `(SELECT (array_agg(candidate.unit_price_minor))[1] FROM (${ANCHORS}) candidate)`;
|
|
18
|
+
const COUNT = `(SELECT count(*) FROM (${ANCHORS}) candidate)`;
|
|
19
|
+
export const COMPONENT_SQL = `
|
|
20
|
+
SELECT c.bundle_id, s.sku, s.title, pr.slug AS product_slug, s.id AS variant_id,
|
|
21
|
+
c.quantity, c.is_addon, c.sort_order, ${FACTS},
|
|
22
|
+
${REFERENCE.replace("%LIST%", "$2::uuid")} AS reference_unit_price_minor,
|
|
23
|
+
${COUNT.replace("%LIST%", "$2::uuid")} AS reference_price_count
|
|
24
|
+
FROM public.catalog_bundle_components c
|
|
25
|
+
JOIN public.catalog_skus s ON s.id = c.catalog_sku_id
|
|
26
|
+
JOIN public.catalog_products pr ON pr.id = s.product_id
|
|
27
|
+
LEFT JOIN public.catalog_product_document_revisions revision ON revision.id = pr.current_document_revision_id AND revision.product_id = pr.id
|
|
28
|
+
WHERE c.bundle_id = $1::uuid ORDER BY c.sort_order, s.sku`;
|
|
29
|
+
export const FEED_COMPONENT_SQL = `
|
|
30
|
+
SELECT c.bundle_id, s.sku, s.title, pr.slug AS product_slug, s.id AS variant_id,
|
|
31
|
+
c.quantity, c.is_addon, c.sort_order, ${FACTS},
|
|
32
|
+
${REFERENCE.replace("%LIST%", "selected.price_list_id")} AS reference_unit_price_minor,
|
|
33
|
+
${COUNT.replace("%LIST%", "selected.price_list_id")} AS reference_price_count
|
|
34
|
+
FROM unnest($1::uuid[], $2::uuid[]) AS selected(bundle_id, price_list_id)
|
|
35
|
+
JOIN public.catalog_bundle_components c ON c.bundle_id = selected.bundle_id
|
|
36
|
+
JOIN public.catalog_skus s ON s.id = c.catalog_sku_id
|
|
37
|
+
JOIN public.catalog_products pr ON pr.id = s.product_id
|
|
38
|
+
LEFT JOIN public.catalog_product_document_revisions revision ON revision.id = pr.current_document_revision_id AND revision.product_id = pr.id
|
|
39
|
+
ORDER BY c.bundle_id, c.sort_order, s.sku`;
|
|
40
|
+
export const PRICE_SQL = `
|
|
41
|
+
SELECT p.mode, p.price_list_id, p.target_price_minor, list.currency, p.amount_kind, p.active, p.valid_from, p.valid_to
|
|
42
|
+
FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id
|
|
43
|
+
WHERE p.bundle_id = $1::uuid ORDER BY p.valid_from DESC`;
|
|
44
|
+
export const OWN_LIST_SQL = `
|
|
45
|
+
SELECT list.id, list.currency, list.region_code, p.mode
|
|
46
|
+
FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id
|
|
47
|
+
WHERE p.bundle_id = $1::uuid AND p.active AND p.amount_kind = 'gross'
|
|
48
|
+
AND (p.mode = $2::text OR p.mode = 'any') AND list.status = 'active'
|
|
49
|
+
AND p.valid_from <= $3::timestamptz AND (p.valid_to IS NULL OR p.valid_to > $3::timestamptz)
|
|
50
|
+
AND list.valid_from <= $3::timestamptz AND (list.valid_to IS NULL OR list.valid_to > $3::timestamptz)
|
|
51
|
+
ORDER BY p.valid_from DESC`;
|
|
52
|
+
export const CURRENCY_LIST_SQL = `
|
|
53
|
+
SELECT id, currency, region_code FROM public.price_lists
|
|
54
|
+
WHERE currency = $1::text AND status = 'active' AND ($2::text IS NULL OR region_code = $2::text)
|
|
55
|
+
AND valid_from <= $3::timestamptz AND (valid_to IS NULL OR valid_to > $3::timestamptz)`;
|
|
56
|
+
export const FEED_SQL = `
|
|
57
|
+
SELECT b.id, b.code, b.title, b.fulfillment_mode, p.mode, p.target_price_minor, p.price_list_id, list.currency, list.region_code
|
|
58
|
+
FROM public.catalog_bundles b
|
|
59
|
+
JOIN public.catalog_bundle_prices p ON p.bundle_id = b.id AND p.active
|
|
60
|
+
JOIN public.price_lists list ON list.id = p.price_list_id
|
|
61
|
+
WHERE b.status = 'active' AND p.amount_kind = 'gross' AND p.target_price_minor > 0
|
|
62
|
+
AND list.status = 'active' AND ($1::text IS NULL OR list.currency = $1::text)
|
|
63
|
+
AND ($2::text IS NULL OR list.region_code = $2::text) AND (p.mode = $4::text OR p.mode = 'any')
|
|
64
|
+
AND p.valid_from <= $3::timestamptz AND (p.valid_to IS NULL OR p.valid_to > $3::timestamptz)
|
|
65
|
+
AND list.valid_from <= $3::timestamptz AND (list.valid_to IS NULL OR list.valid_to > $3::timestamptz)
|
|
66
|
+
ORDER BY b.code, p.valid_from DESC`;
|
|
67
|
+
|
|
68
|
+
const SUMMARY_COLUMNS = `b.id, b.code, b.title, b.status, b.fulfillment_mode, b.updated_at,
|
|
69
|
+
b.composition_constraint, b.metadata,
|
|
70
|
+
(SELECT count(*) FROM public.catalog_bundle_components c WHERE c.bundle_id = b.id) AS component_count,
|
|
71
|
+
EXISTS (SELECT 1 FROM public.catalog_bundle_prices p JOIN public.price_lists list ON list.id = p.price_list_id
|
|
72
|
+
WHERE p.bundle_id = b.id AND p.active AND p.amount_kind = 'gross' AND p.target_price_minor > 0
|
|
73
|
+
AND p.mode IN ('one_time', 'any') AND list.status = 'active'
|
|
74
|
+
AND p.valid_from <= CURRENT_TIMESTAMP AND (p.valid_to IS NULL OR p.valid_to > CURRENT_TIMESTAMP)
|
|
75
|
+
AND list.valid_from <= CURRENT_TIMESTAMP AND (list.valid_to IS NULL OR list.valid_to > CURRENT_TIMESTAMP)) AS has_active_target_price`;
|
|
76
|
+
export const DETAIL_SQL = `SELECT ${SUMMARY_COLUMNS} FROM public.catalog_bundles b WHERE b.code = $1`;
|
|
77
|
+
export const LIST_SQL = `SELECT ${SUMMARY_COLUMNS} FROM public.catalog_bundles b
|
|
78
|
+
WHERE ($1::text = 'all' OR b.status = $1::text)
|
|
79
|
+
AND ($2::text IS NULL OR b.code ILIKE '%' || $2 || '%' OR b.title ILIKE '%' || $2 || '%')
|
|
80
|
+
ORDER BY b.code LIMIT $3 OFFSET $4`;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import type { PgQueryExecutor } from "../data/index.js";
|
|
2
|
+
import { assertPrimaryUnitGtinAuthority, type CatalogSkuIdentifier } from "./contracts/foundation.js";
|
|
3
|
+
import { BundleCatalogReadError, type BundleCatalogReadPort, type BundleComponentRow, type BundleSummary, type GetBundleInput } from "./bundleCatalogReadPort.js";
|
|
4
|
+
import { uniqueBundlePrice, selectEffectiveBundleTargetPrice } from "./bundlePriceSelection.js";
|
|
5
|
+
import { COUNT_SQL } from "./bundleCatalogQueries.js";
|
|
6
|
+
import { LIST_SQL, DETAIL_SQL, COMPONENT_SQL, FEED_COMPONENT_SQL, PRICE_SQL, OWN_LIST_SQL, CURRENCY_LIST_SQL, FEED_SQL } from "./effectiveBundleCatalogQueries.js";
|
|
7
|
+
|
|
8
|
+
interface BundleRow {
|
|
9
|
+
id: string;
|
|
10
|
+
code: string;
|
|
11
|
+
title: string;
|
|
12
|
+
status: string;
|
|
13
|
+
fulfillment_mode: string;
|
|
14
|
+
updated_at: string;
|
|
15
|
+
component_count: string | number;
|
|
16
|
+
has_active_target_price: boolean;
|
|
17
|
+
composition_constraint: Record<string, unknown> | null;
|
|
18
|
+
metadata: Record<string, unknown> | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface ComponentRow {
|
|
22
|
+
bundle_id: string;
|
|
23
|
+
sku: string;
|
|
24
|
+
title: string | null;
|
|
25
|
+
product_slug: string;
|
|
26
|
+
variant_id: string;
|
|
27
|
+
quantity: number;
|
|
28
|
+
is_addon: boolean;
|
|
29
|
+
sort_order: number;
|
|
30
|
+
reference_unit_price_minor: number | null;
|
|
31
|
+
reference_price_count: number | string;
|
|
32
|
+
sku_status: string;
|
|
33
|
+
product_status: string;
|
|
34
|
+
net_weight_g: number;
|
|
35
|
+
sellable_standalone: boolean;
|
|
36
|
+
sellable_in_subscription: boolean;
|
|
37
|
+
document_ready: boolean;
|
|
38
|
+
identifiers: CatalogSkuIdentifier[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface PriceRow {
|
|
42
|
+
price_list_id: string;
|
|
43
|
+
mode: string;
|
|
44
|
+
target_price_minor: number;
|
|
45
|
+
currency: string;
|
|
46
|
+
amount_kind: string;
|
|
47
|
+
active: boolean;
|
|
48
|
+
valid_from: string;
|
|
49
|
+
valid_to: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface ActiveBundleRow {
|
|
53
|
+
id: string;
|
|
54
|
+
code: string;
|
|
55
|
+
title: string;
|
|
56
|
+
fulfillment_mode: string;
|
|
57
|
+
mode: string;
|
|
58
|
+
target_price_minor: number;
|
|
59
|
+
price_list_id: string;
|
|
60
|
+
currency: string;
|
|
61
|
+
region_code: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
/** Selected only by the explicit effective-authority option. */
|
|
66
|
+
export function createEffectiveBundleCatalogStore(executor: PgQueryExecutor, incumbent: BundleCatalogReadPort): BundleCatalogReadPort {
|
|
67
|
+
async function rows<T>(sql: string, values: unknown[]): Promise<T[]> {
|
|
68
|
+
const result = await executor.query(sql, values).catch((error: unknown) => {
|
|
69
|
+
throw new BundleCatalogReadError(error instanceof Error ? error.message : String(error));
|
|
70
|
+
});
|
|
71
|
+
return (result.rows ?? []) as unknown as T[];
|
|
72
|
+
}
|
|
73
|
+
async function selectPriceList(bundleId: string, input: GetBundleInput): Promise<{ id: string; currency: string } | null> {
|
|
74
|
+
const atTime = input.atTime ?? new Date().toISOString(), mode = input.mode ?? "one_time";
|
|
75
|
+
const own = input.currency ? [] : await rows<{ id: string; currency: string; region_code: string; mode: string }>(OWN_LIST_SQL, [bundleId, mode, atTime]);
|
|
76
|
+
const chosenPrice = uniqueBundlePrice(own, mode), chosen = chosenPrice ? [chosenPrice] : [];
|
|
77
|
+
const currency = input.currency ?? chosen[0]?.currency;
|
|
78
|
+
if (!currency) return null;
|
|
79
|
+
const candidates = await rows<{ id: string; currency: string }>(CURRENCY_LIST_SQL, [currency, input.regionCode ?? chosen[0]?.region_code ?? null, atTime]);
|
|
80
|
+
if (candidates.length > 1) throw new BundleCatalogReadError("bundle_price_list_ambiguous");
|
|
81
|
+
if (chosen[0] && candidates[0] && chosen[0].id !== candidates[0].id) throw new BundleCatalogReadError("bundle_price_list_changed");
|
|
82
|
+
return candidates[0] ?? null;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
...incumbent,
|
|
86
|
+
async listBundles(input) {
|
|
87
|
+
const filter = [input.status, input.query ?? null];
|
|
88
|
+
const [page, counted] = await Promise.all([
|
|
89
|
+
rows<BundleRow>(LIST_SQL, [...filter, input.limit, input.offset]),
|
|
90
|
+
rows<{ total: string | number }>(COUNT_SQL, filter),
|
|
91
|
+
]);
|
|
92
|
+
return { bundles: page.map(toSummary), total: Number(counted[0]?.total ?? page.length) };
|
|
93
|
+
},
|
|
94
|
+
async getBundle(input) {
|
|
95
|
+
const bundle = (await rows<BundleRow>(DETAIL_SQL, [input.code]))[0];
|
|
96
|
+
if (!bundle) return null;
|
|
97
|
+
const atTime = input.atTime ?? new Date().toISOString();
|
|
98
|
+
const list = await selectPriceList(bundle.id, { ...input, atTime });
|
|
99
|
+
const [componentRows, priceRows] = await Promise.all([
|
|
100
|
+
rows<ComponentRow>(COMPONENT_SQL, [bundle.id, list?.id ?? null, atTime, input.mode ?? "one_time"]).then(rows => rows.map(toComponent)),
|
|
101
|
+
rows<PriceRow>(PRICE_SQL, [bundle.id]),
|
|
102
|
+
]);
|
|
103
|
+
return {
|
|
104
|
+
...toSummary(bundle), compositionConstraint: toConstraint(bundle.composition_constraint), metadata: bundle.metadata ?? {},
|
|
105
|
+
components: componentRows, prices: priceRows.map(toPrice),
|
|
106
|
+
resolvedTargetPrice: selectEffectiveBundleTargetPrice(priceRows.map(row => ({ price: toPrice(row), priceListId: row.price_list_id })),
|
|
107
|
+
{ priceListId: list?.id ?? null, currency: list?.currency ?? null, mode: input.mode ?? "one_time", atTime }),
|
|
108
|
+
resolvedCurrency: list?.currency ?? null, resolvedPriceListId: list?.id ?? null,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
async listActiveBundleCompositions(input = {}) {
|
|
112
|
+
const atTime = input.atTime ?? new Date().toISOString(), mode = input.mode ?? "one_time";
|
|
113
|
+
const feed = await rows<ActiveBundleRow>(FEED_SQL, [input.currency ?? null, input.regionCode ?? null, atTime, mode]);
|
|
114
|
+
const selected = new Map<string, ActiveBundleRow>();
|
|
115
|
+
const listReads = new Map<string, Promise<{ id: string }[]>>();
|
|
116
|
+
for (const row of feed) {
|
|
117
|
+
const same = feed.filter(candidate => candidate.id === row.id);
|
|
118
|
+
const candidate = uniqueBundlePrice(same, mode)!;
|
|
119
|
+
const key = `${row.currency}:${row.region_code}`;
|
|
120
|
+
if (!listReads.has(key)) listReads.set(key, rows<{ id: string }>(CURRENCY_LIST_SQL, [row.currency, row.region_code ?? null, atTime]));
|
|
121
|
+
const lists = await listReads.get(key)!;
|
|
122
|
+
if (lists.length > 1) throw new BundleCatalogReadError("bundle_price_list_ambiguous");
|
|
123
|
+
if (lists[0]?.id !== row.price_list_id) throw new BundleCatalogReadError("bundle_price_list_changed");
|
|
124
|
+
selected.set(row.id, candidate);
|
|
125
|
+
}
|
|
126
|
+
if (!selected.size) return [];
|
|
127
|
+
const chosen = [...selected.values()];
|
|
128
|
+
const source = await rows<ComponentRow>(FEED_COMPONENT_SQL, [chosen.map(row => row.id), chosen.map(row => row.price_list_id), atTime, mode]);
|
|
129
|
+
const byBundle = groupComponents(source);
|
|
130
|
+
const sellable = chosen.filter(row => {
|
|
131
|
+
const components = source.filter(component => component.bundle_id === row.id);
|
|
132
|
+
return components.length > 0 && components.every(component => componentReady(component, mode));
|
|
133
|
+
});
|
|
134
|
+
return sellable.map(row => ({ code: row.code, title: row.title, fulfillmentMode: row.fulfillment_mode,
|
|
135
|
+
currency: row.currency, targetPriceMinor: row.target_price_minor, mode: row.mode, components: byBundle.get(row.id) ?? [] }));
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function groupComponents(rows: readonly ComponentRow[]): Map<string, BundleComponentRow[]> {
|
|
141
|
+
const grouped = new Map<string, BundleComponentRow[]>();
|
|
142
|
+
for (const row of rows) {
|
|
143
|
+
const bucket = grouped.get(row.bundle_id) ?? [];
|
|
144
|
+
bucket.push(toComponent(row));
|
|
145
|
+
grouped.set(row.bundle_id, bucket);
|
|
146
|
+
}
|
|
147
|
+
return grouped;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function toComponent(row: ComponentRow): BundleComponentRow {
|
|
151
|
+
if (Number(row.reference_price_count) > 1) throw new BundleCatalogReadError("bundle_price_ambiguous");
|
|
152
|
+
return {
|
|
153
|
+
sku: row.sku,
|
|
154
|
+
title: row.title ?? null,
|
|
155
|
+
productSlug: row.product_slug,
|
|
156
|
+
variantId: row.variant_id,
|
|
157
|
+
quantity: Number(row.quantity),
|
|
158
|
+
isAddon: row.is_addon === true,
|
|
159
|
+
sortOrder: Number(row.sort_order),
|
|
160
|
+
referenceUnitPriceMinor:
|
|
161
|
+
row.reference_unit_price_minor === null || row.reference_unit_price_minor === undefined
|
|
162
|
+
? null
|
|
163
|
+
: Number(row.reference_unit_price_minor),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function toSummary(row: BundleRow): BundleSummary {
|
|
168
|
+
return {
|
|
169
|
+
code: row.code,
|
|
170
|
+
title: row.title,
|
|
171
|
+
status: row.status,
|
|
172
|
+
fulfillmentMode: row.fulfillment_mode,
|
|
173
|
+
componentCount: Number(row.component_count ?? 0),
|
|
174
|
+
hasActiveTargetPrice: row.has_active_target_price === true,
|
|
175
|
+
updatedAt: row.updated_at,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function toPrice(row: PriceRow) {
|
|
180
|
+
return {
|
|
181
|
+
mode: row.mode,
|
|
182
|
+
targetPriceMinor: Number(row.target_price_minor),
|
|
183
|
+
currency: row.currency,
|
|
184
|
+
amountKind: row.amount_kind,
|
|
185
|
+
active: row.active === true,
|
|
186
|
+
validFrom: row.valid_from,
|
|
187
|
+
validTo: row.valid_to ?? null,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** An empty envelope is stored as `{}`; that is "unconstrained", not a constraint. */
|
|
192
|
+
function toConstraint(value: Record<string, unknown> | null) {
|
|
193
|
+
if (!value || typeof value.kind !== "string" || value.kind.trim() === "") return null;
|
|
194
|
+
return {
|
|
195
|
+
kind: value.kind,
|
|
196
|
+
version: typeof value.version === "number" ? value.version : 0,
|
|
197
|
+
data: (value.data ?? {}) as Record<string, unknown>,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function componentReady(row: ComponentRow, mode: string): boolean {
|
|
202
|
+
try { assertPrimaryUnitGtinAuthority(row.identifiers); } catch { return false; }
|
|
203
|
+
return row.sku_status === "active" && row.product_status === "active" && row.document_ready === true
|
|
204
|
+
&& Number.isSafeInteger(row.net_weight_g) && row.net_weight_g > 0
|
|
205
|
+
&& (mode === "subscription" ? row.sellable_in_subscription : row.sellable_standalone)
|
|
206
|
+
&& row.reference_unit_price_minor !== null && Number.isSafeInteger(Number(row.reference_unit_price_minor))
|
|
207
|
+
&& Number(row.reference_unit_price_minor) > 0;
|
|
208
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from "./validation.js";
|
|
2
|
+
import { CATALOG_FOUNDATION_CONTRACT_VERSION, isValidGtin } from "./contracts/foundation.js";
|
|
3
|
+
export { CATALOG_FOUNDATION_CONTRACT_VERSION, CatalogSkuAuthorityError, isValidGtin, assertPrimaryUnitGtinAuthority, requireCurrentCatalogDocumentAuthority } from "./contracts/foundation.js";
|
|
4
|
+
export type { CatalogDocumentRevisionRef, CatalogSkuIdentifier, CatalogSkuEnvelopeSelector, NeutralSkuEnvelopeV1, CatalogPriceContext, CatalogSkuAuthorityRefusal } from "./contracts/foundation.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Portable, payload-free catalog shape. Document interpretation remains an
|
|
8
|
+
* adopter concern; this module can only carry immutable document references.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const entityIdSchema = z.guid();
|
|
12
|
+
const opaqueReferenceSchema = z.string().trim().min(1).max(240);
|
|
13
|
+
const codeSchema = z.string().trim().min(1).max(160).regex(/^[A-Za-z0-9._:-]+$/);
|
|
14
|
+
const sha256DigestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
|
|
15
|
+
const currencyCodeSchema = z.string().regex(/^[A-Z]{3}$/u);
|
|
16
|
+
|
|
17
|
+
export const catalogFixedPointSchema = z.object({
|
|
18
|
+
/** SKU net content is a physical, positive quantity; signed values need a distinct contract. */
|
|
19
|
+
unscaled: z.number().int().positive().safe(),
|
|
20
|
+
scale: z.number().int().min(0).max(12).safe(),
|
|
21
|
+
unit: z.string().trim().min(1).max(64).regex(/^[A-Z][A-Z0-9_]*$/),
|
|
22
|
+
}).strict();
|
|
23
|
+
|
|
24
|
+
export const catalogDocumentRevisionRefSchema = z.object({
|
|
25
|
+
id: entityIdSchema,
|
|
26
|
+
productId: entityIdSchema,
|
|
27
|
+
revisionNo: z.number().int().positive(),
|
|
28
|
+
schemaId: opaqueReferenceSchema,
|
|
29
|
+
documentRef: opaqueReferenceSchema,
|
|
30
|
+
sourceRef: opaqueReferenceSchema,
|
|
31
|
+
digest: sha256DigestSchema,
|
|
32
|
+
}).strict();
|
|
33
|
+
|
|
34
|
+
export const catalogSkuIdentifierSchema = z.object({
|
|
35
|
+
issuer: opaqueReferenceSchema,
|
|
36
|
+
normalizedValue: z.string().trim().min(1).max(128),
|
|
37
|
+
kind: z.enum(["gtin", "other"]),
|
|
38
|
+
packKind: z.enum(["unit", "collective"]),
|
|
39
|
+
packQuantity: z.number().int().positive(),
|
|
40
|
+
isPrimary: z.boolean(),
|
|
41
|
+
}).strict();
|
|
42
|
+
|
|
43
|
+
/** Stable, payload-free detail selectors shared by both catalog adapters. */
|
|
44
|
+
export const catalogSkuEnvelopeSelectorSchema = z.discriminatedUnion("kind", [
|
|
45
|
+
z.object({
|
|
46
|
+
kind: z.literal("sku_code"),
|
|
47
|
+
skuCode: codeSchema,
|
|
48
|
+
}).strict(),
|
|
49
|
+
z.object({
|
|
50
|
+
kind: z.literal("primary_product_slug"),
|
|
51
|
+
productSlug: codeSchema,
|
|
52
|
+
}).strict(),
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
export const neutralSkuEnvelopeV1Schema = z.object({
|
|
56
|
+
contractVersion: z.literal(CATALOG_FOUNDATION_CONTRACT_VERSION),
|
|
57
|
+
product: z.object({
|
|
58
|
+
id: entityIdSchema,
|
|
59
|
+
slug: codeSchema,
|
|
60
|
+
primarySkuId: entityIdSchema,
|
|
61
|
+
}).strict(),
|
|
62
|
+
sku: z.object({
|
|
63
|
+
id: entityIdSchema,
|
|
64
|
+
productId: entityIdSchema,
|
|
65
|
+
code: codeSchema,
|
|
66
|
+
netContent: catalogFixedPointSchema,
|
|
67
|
+
sellability: z.object({
|
|
68
|
+
status: z.enum(["draft", "active", "archived"]),
|
|
69
|
+
oneTime: z.boolean(),
|
|
70
|
+
subscription: z.boolean(),
|
|
71
|
+
}).strict(),
|
|
72
|
+
/** Structural SKU classification shared by both bundle schemas. */
|
|
73
|
+
isAddon: z.boolean(),
|
|
74
|
+
assetRef: opaqueReferenceSchema.nullable(),
|
|
75
|
+
}).strict(),
|
|
76
|
+
documentRevision: catalogDocumentRevisionRefSchema,
|
|
77
|
+
identifiers: z.array(catalogSkuIdentifierSchema).max(32),
|
|
78
|
+
}).strict().superRefine((envelope, context) => {
|
|
79
|
+
if (envelope.product.id !== envelope.sku.productId) {
|
|
80
|
+
context.addIssue({ code: z.ZodIssueCode.custom, path: ["sku", "productId"], message: "sku must belong to envelope product" });
|
|
81
|
+
}
|
|
82
|
+
if (envelope.product.id !== envelope.documentRevision.productId) {
|
|
83
|
+
context.addIssue({ code: z.ZodIssueCode.custom, path: ["documentRevision", "productId"], message: "document revision must belong to envelope product" });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const seen = new Set<string>();
|
|
87
|
+
let primaryGtinCount = 0;
|
|
88
|
+
envelope.identifiers.forEach((identifier, index) => {
|
|
89
|
+
const identity = `${identifier.issuer}\u0000${identifier.normalizedValue}`;
|
|
90
|
+
if (seen.has(identity)) {
|
|
91
|
+
context.addIssue({ code: z.ZodIssueCode.custom, path: ["identifiers", index], message: "identifier issuer/value pairs must be unique" });
|
|
92
|
+
}
|
|
93
|
+
seen.add(identity);
|
|
94
|
+
if (identifier.packKind === "unit" && identifier.packQuantity !== 1) {
|
|
95
|
+
context.addIssue({ code: z.ZodIssueCode.custom, path: ["identifiers", index, "packQuantity"], message: "unit identifiers require pack quantity 1" });
|
|
96
|
+
}
|
|
97
|
+
if (identifier.packKind === "collective" && identifier.packQuantity <= 1) {
|
|
98
|
+
context.addIssue({ code: z.ZodIssueCode.custom, path: ["identifiers", index, "packQuantity"], message: "collective identifiers require pack quantity above 1" });
|
|
99
|
+
}
|
|
100
|
+
if (identifier.isPrimary) {
|
|
101
|
+
primaryGtinCount += 1;
|
|
102
|
+
if (
|
|
103
|
+
identifier.kind !== "gtin"
|
|
104
|
+
|| identifier.packKind !== "unit"
|
|
105
|
+
|| !isValidGtin(identifier.normalizedValue)
|
|
106
|
+
) {
|
|
107
|
+
context.addIssue({ code: z.ZodIssueCode.custom, path: ["identifiers", index], message: "a primary identifier must be a unit GTIN" });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (primaryGtinCount > 1) {
|
|
112
|
+
context.addIssue({ code: z.ZodIssueCode.custom, path: ["identifiers"], message: "a SKU may have at most one primary GTIN" });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export const catalogPriceContextSchema = z.object({
|
|
117
|
+
priceListId: entityIdSchema,
|
|
118
|
+
regionCode: z.string().regex(/^[A-Z]{2,3}$/u),
|
|
119
|
+
currency: currencyCodeSchema,
|
|
120
|
+
channel: z.string().trim().min(1).max(64).regex(/^[A-Za-z0-9._:-]+$/),
|
|
121
|
+
atTime: z.string().datetime({ offset: true }),
|
|
122
|
+
}).strict();
|
|
123
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export * from "./contracts/index.js";
|
|
2
|
+
export { parseCatalogActiveSkuSelection } from "./activeSkuSelection.js";
|
|
3
|
+
export { createCatalogDraftHandler } from "./draftHandler.js";
|
|
4
|
+
export type { CatalogDraftHandlerDeps, CatalogDraftCommandResult } from "./draftHandler.js";
|
|
5
|
+
export { CatalogDraftStoreError } from "./draftPorts.js";
|
|
6
|
+
export type { CatalogDraftOperator, CatalogDraftStorePort } from "./draftPorts.js";
|
|
7
|
+
export { catalogDraftPayloadSchema, catalogDraftCommandSchema, catalogDraftGetQuerySchema, catalogDraftListQuerySchema, catalogDraftSummarySchema, catalogDraftRecordSchema, catalogDraftPageSchema, catalogDraftRefusalSchema, catalogDraftApplyResultSchema } from "./draftSchemas.js";
|
|
8
|
+
export { validateCatalogDraft } from "./draftValidation.js";
|
|
9
|
+
export type { CatalogDraftReadiness, CatalogDraftValidation } from "./draftValidation.js";
|
|
10
|
+
export { catalogFixedPointSchema, catalogDocumentRevisionRefSchema, catalogSkuIdentifierSchema, catalogSkuEnvelopeSelectorSchema, neutralSkuEnvelopeV1Schema, catalogPriceContextSchema } from "./foundationSchemas.js";
|
|
11
|
+
export { catalogNamespacedKeySchema, catalogDimensionKeySchema, catalogQuantityDimensionSchema, catalogQuantitySchema, catalogOptionValueSchema, catalogProductTypeRefSchema, createCatalogProductTypeRegistry } from "./productTypeSchemas.js";
|
|
12
|
+
export type { SellableCatalogPort, CatalogSkuEnvelopeReadPort, PublicCatalogSkuEnvelopeReadPort, CatalogSkuEnvelopeListQuery, CatalogActiveSkuEnvelopeListQuery, CatalogSkuEnvelopePage } from "./readPorts.js";
|
|
13
|
+
export { createReferenceCatalogItemsHandler } from "./referenceCatalogHandler.js";
|
|
14
|
+
export { RESOLVED_SKU_PROJECTION_VERSION, resolvedSkuProjectionSchema, buildResolvedSkuProjection } from "./resolvedSkuProjection.js";
|
|
15
|
+
export type { ResolvedSkuProjection, ResolvedSkuProjectionInput } from "./resolvedSkuProjection.js";
|
|
16
|
+
export { sellableCatalogItemSchema, sellableCatalogProfileSchema, sellableCatalogListResponseSchema } from "./sellableSchemas.js";
|
|
17
|
+
export { SOURCE_PACK_LIMITS, CatalogMediaSourcePackError, readCatalogMediaSourceManifest, validateCatalogMediaSourcePack, exportCatalogMediaSourcePack, restoreCatalogMediaSourcePack, importCatalogMediaSourcePack } from "./mediaSourcePack.js";
|
|
18
|
+
export type { CatalogMediaSourcePack, CatalogMediaImportOutcome } from "./mediaSourcePack.js";
|
|
19
|
+
export type { CatalogValidationPort, CatalogPublicationReadPort, CatalogPublicationPort, VerifiedCatalogPublisher, CatalogCapabilityDescriptor } from "./publicationPorts.js";
|
|
20
|
+
export { SUPPORTED_BUNDLE_FULFILLMENT_MODES, createBundleWriteRules, evaluateBundleComposition, evaluateBundleFulfillmentMode, evaluateBundleTargetPrice, isEmptyCompositionConstraint, evaluateBundleCompositionConstraint } from "./bundleRules.js";
|
|
21
|
+
export type { BundleCompositionEntry, SupportedBundleFulfillmentMode } from "./bundleRules.js";
|
|
22
|
+
export { BUNDLE_RULE_CODES, BUNDLE_ALLOCATION_RULE_CODE, BUNDLE_RULE_ENFORCEMENT } from "./bundleRuleCodes.js";
|
|
23
|
+
export type { BundleRuleCode, BundleActorKind, BundleWriteOperation, BundleRuleResult } from "./bundleRuleCodes.js";
|
|
24
|
+
export { DEFAULT_BUNDLE_LOW_STOCK_THRESHOLD, BUNDLE_COMPONENT_STOCK_UNKNOWN, BUNDLE_COMPOSITION_EMPTY, createBundleAvailability } from "./bundleAvailability.js";
|
|
25
|
+
export type { BundleAvailabilityComponent, BundleAvailability, DeriveBundleAvailabilityInput } from "./bundleAvailability.js";
|
|
26
|
+
export { BundleCatalogReadError } from "./bundleCatalogReadPort.js";
|
|
27
|
+
export type { BundleListStatusFilter, ListBundlesInput, BundleSummary, ListBundlesResult, BundleComponentRow, BundleTargetPriceRow, BundleDetail, GetBundleInput, ActiveBundleComposition, BundleHistoryEvent, BundleHistoryInput, BundleHistoryResult, BundleCatalogReadPort } from "./bundleCatalogReadPort.js";
|
|
28
|
+
export { createBundleAvailabilityServices, createUnknownOfferAvailabilityPort } from "./bundleAvailabilityService.js";
|
|
29
|
+
export type { BundleAvailabilityServiceDeps, BundleAvailabilityRow, BundleAvailabilityService } from "./bundleAvailabilityService.js";
|
|
30
|
+
export type { BundleWriteResult, BundleCompositionConstraintEnvelope, AdminBundleWritePort } from "./adminBundleWritePort.js";
|
|
31
|
+
export { createAdminBundleHandlers } from "./adminBundleHandler.js";
|
|
32
|
+
export type { AdminBundleHandlerDeps } from "./adminBundleHandler.js";
|
|
33
|
+
export { createAdminBundleReadHandlers } from "./adminBundleReadHandler.js";
|
|
34
|
+
export type { AdminBundleReadHandlerDeps } from "./adminBundleReadHandler.js";
|
|
35
|
+
export { createSellableBundleHandlers, toSellableBundle } from "./sellableBundleHandler.js";
|
|
36
|
+
export type { SellableBundleHandlerDeps } from "./sellableBundleHandler.js";
|
|
37
|
+
export type { BundleStockStatus, BundleStockRequestItem, BundleStockAvailability, BundleStockPort, BundleRuleBindings } from "./bundleBindings.js";
|
|
38
|
+
export type { AuthorizeAdmin, AgentDomainQuerySpec, AgentDomainMutationSpec, BundleMutationKey, BundleQueryKey, BundleResponseSchema, BundleAdminBindings } from "./adminBindings.js";
|
|
39
|
+
export { createPostgresBundleCatalogStore } from "./bundleCatalogStore.js";
|
|
40
|
+
export { BUNDLE_MIGRATIONS, CATALOG_MIGRATIONS } from "./sql.js";
|
|
41
|
+
export { SUMMARY_COLUMNS, LIST_FILTER, LIST_SQL, COUNT_SQL, DETAIL_SQL, REFERENCE_PRICE, COMPONENT_SQL, FEED_COMPONENT_SQL, PRICE_SQL, OWN_LIST_SQL, CURRENCY_LIST_SQL, FEED_SQL, HISTORY_SQL, HISTORY_COUNT_SQL } from "./bundleCatalogQueries.js";
|
|
42
|
+
export { createPostgresCatalogSkuEnvelopeReadPort } from "./catalogSkuEnvelope.js";
|
|
43
|
+
export { createPostgresCatalogDraftStore } from "./catalogDraftStore.js";
|
|
44
|
+
export { selectEffectiveBundleTargetPrice } from "./bundlePriceSelection.js";
|