@mohasinac/appkit 2.6.3 → 2.6.4
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/dist/_internal/server/features/account/data.js +2 -2
- package/dist/_internal/server/features/bundles/data.d.ts +26 -6
- package/dist/_internal/server/features/bundles/data.js +41 -6
- package/dist/_internal/server/features/bundles/index.d.ts +3 -2
- package/dist/_internal/server/features/bundles/index.js +4 -2
- package/dist/_internal/server/features/bundles/metadata.d.ts +20 -0
- package/dist/_internal/server/features/bundles/metadata.js +46 -0
- package/dist/_internal/server/features/bundles/og.d.ts +38 -0
- package/dist/_internal/server/features/bundles/og.js +122 -0
- package/dist/_internal/server/features/checkout/actions.js +192 -133
- package/dist/_internal/server/features/checkout/bundle-expansion.d.ts +57 -0
- package/dist/_internal/server/features/checkout/bundle-expansion.js +70 -0
- package/dist/_internal/server/features/checkout/prize-bundle-gates.d.ts +5 -15
- package/dist/_internal/server/features/checkout/prize-bundle-gates.js +5 -21
- package/dist/_internal/server/features/media/contextGuards.js +15 -1
- package/dist/_internal/server/features/payouts/actions.d.ts +19 -0
- package/dist/_internal/server/features/payouts/actions.js +38 -0
- package/dist/_internal/server/features/products/data.js +1 -2
- package/dist/_internal/server/features/raffle/actions.d.ts +11 -0
- package/dist/_internal/server/features/raffle/actions.js +31 -0
- package/dist/_internal/server/features/refunds/actions.d.ts +31 -0
- package/dist/_internal/server/features/refunds/actions.js +77 -0
- package/dist/_internal/server/jobs/core/adminAnalytics.d.ts +28 -0
- package/dist/_internal/server/jobs/core/adminAnalytics.js +98 -0
- package/dist/_internal/server/jobs/core/assignSpinPrize.d.ts +19 -0
- package/dist/_internal/server/jobs/core/assignSpinPrize.js +81 -0
- package/dist/_internal/server/jobs/core/auctionSettlement.d.ts +2 -0
- package/dist/_internal/server/jobs/core/auctionSettlement.js +70 -0
- package/dist/_internal/server/jobs/core/autoPayoutEligibility.d.ts +2 -0
- package/dist/_internal/server/jobs/core/autoPayoutEligibility.js +109 -0
- package/dist/_internal/server/jobs/core/bundleStockSync.d.ts +10 -0
- package/dist/_internal/server/jobs/core/bundleStockSync.js +71 -0
- package/dist/_internal/server/jobs/core/cartPrune.d.ts +2 -0
- package/dist/_internal/server/jobs/core/cartPrune.js +13 -0
- package/dist/_internal/server/jobs/core/cleanupRtdbEvents.d.ts +2 -0
- package/dist/_internal/server/jobs/core/cleanupRtdbEvents.js +45 -0
- package/dist/_internal/server/jobs/core/countersReconcile.d.ts +2 -0
- package/dist/_internal/server/jobs/core/countersReconcile.js +107 -0
- package/dist/_internal/server/jobs/core/couponExpiry.d.ts +2 -0
- package/dist/_internal/server/jobs/core/couponExpiry.js +13 -0
- package/dist/_internal/server/jobs/core/dailyDataCleanup.d.ts +2 -0
- package/dist/_internal/server/jobs/core/dailyDataCleanup.js +20 -0
- package/dist/_internal/server/jobs/core/index.d.ts +44 -0
- package/dist/_internal/server/jobs/core/index.js +47 -0
- package/dist/_internal/server/jobs/core/listingProcessor.d.ts +30 -0
- package/dist/_internal/server/jobs/core/listingProcessor.js +138 -0
- package/dist/_internal/server/jobs/core/mediaTmpCleanup.d.ts +14 -0
- package/dist/_internal/server/jobs/core/mediaTmpCleanup.js +68 -0
- package/dist/_internal/server/jobs/core/notificationPrune.d.ts +2 -0
- package/dist/_internal/server/jobs/core/notificationPrune.js +13 -0
- package/dist/_internal/server/jobs/core/offerExpiry.d.ts +2 -0
- package/dist/_internal/server/jobs/core/offerExpiry.js +50 -0
- package/dist/_internal/server/jobs/core/onBidPlaced.d.ts +15 -0
- package/dist/_internal/server/jobs/core/onBidPlaced.js +59 -0
- package/dist/_internal/server/jobs/core/onCategoryWrite.d.ts +14 -0
- package/dist/_internal/server/jobs/core/onCategoryWrite.js +134 -0
- package/dist/_internal/server/jobs/core/onOrderCreate.d.ts +18 -0
- package/dist/_internal/server/jobs/core/onOrderCreate.js +78 -0
- package/dist/_internal/server/jobs/core/onOrderStatusChange.d.ts +19 -0
- package/dist/_internal/server/jobs/core/onOrderStatusChange.js +139 -0
- package/dist/_internal/server/jobs/core/onProductStockChange.d.ts +23 -0
- package/dist/_internal/server/jobs/core/onProductStockChange.js +130 -0
- package/dist/_internal/server/jobs/core/onProductWrite.d.ts +12 -0
- package/dist/_internal/server/jobs/core/onProductWrite.js +94 -0
- package/dist/_internal/server/jobs/core/onReviewWrite.d.ts +7 -0
- package/dist/_internal/server/jobs/core/onReviewWrite.js +49 -0
- package/dist/_internal/server/jobs/core/onStoreWrite.d.ts +12 -0
- package/dist/_internal/server/jobs/core/onStoreWrite.js +7 -0
- package/dist/_internal/server/jobs/core/payoutBatch.d.ts +8 -0
- package/dist/_internal/server/jobs/core/payoutBatch.js +102 -0
- package/dist/_internal/server/jobs/core/pendingOrderTimeout.d.ts +2 -0
- package/dist/_internal/server/jobs/core/pendingOrderTimeout.js +27 -0
- package/dist/_internal/server/jobs/core/positionsReconcile.d.ts +7 -0
- package/dist/_internal/server/jobs/core/positionsReconcile.js +87 -0
- package/dist/_internal/server/jobs/core/prizeRevealClose.d.ts +2 -0
- package/dist/_internal/server/jobs/core/prizeRevealClose.js +22 -0
- package/dist/_internal/server/jobs/core/prizeRevealExpiry.d.ts +2 -0
- package/dist/_internal/server/jobs/core/prizeRevealExpiry.js +50 -0
- package/dist/_internal/server/jobs/core/prizeRevealOpen.d.ts +2 -0
- package/dist/_internal/server/jobs/core/prizeRevealOpen.js +56 -0
- package/dist/_internal/server/jobs/core/prizeRevealReminder.d.ts +2 -0
- package/dist/_internal/server/jobs/core/prizeRevealReminder.js +38 -0
- package/dist/_internal/server/jobs/core/productStatsSync.d.ts +8 -0
- package/dist/_internal/server/jobs/core/productStatsSync.js +36 -0
- package/dist/_internal/server/jobs/core/promotions.d.ts +12 -0
- package/dist/_internal/server/jobs/core/promotions.js +43 -0
- package/dist/_internal/server/jobs/core/storeAnalytics.d.ts +30 -0
- package/dist/_internal/server/jobs/core/storeAnalytics.js +109 -0
- package/dist/_internal/server/jobs/core/triggerEventRaffle.d.ts +19 -0
- package/dist/_internal/server/jobs/core/triggerEventRaffle.js +86 -0
- package/dist/_internal/server/jobs/core/weeklyPayoutEligibility.d.ts +6 -0
- package/dist/_internal/server/jobs/core/weeklyPayoutEligibility.js +85 -0
- package/dist/_internal/server/jobs/handlers/adminAnalytics.d.ts +2 -26
- package/dist/_internal/server/jobs/handlers/adminAnalytics.js +2 -98
- package/dist/_internal/server/jobs/handlers/assignSpinPrize.d.ts +1 -22
- package/dist/_internal/server/jobs/handlers/assignSpinPrize.js +2 -86
- package/dist/_internal/server/jobs/handlers/auctionSettlement.js +2 -70
- package/dist/_internal/server/jobs/handlers/autoPayoutEligibility.js +2 -110
- package/dist/_internal/server/jobs/handlers/bundleStockSync.d.ts +0 -16
- package/dist/_internal/server/jobs/handlers/bundleStockSync.js +2 -80
- package/dist/_internal/server/jobs/handlers/cartPrune.js +2 -13
- package/dist/_internal/server/jobs/handlers/cleanupRtdbEvents.js +2 -45
- package/dist/_internal/server/jobs/handlers/countersReconcile.js +2 -109
- package/dist/_internal/server/jobs/handlers/couponExpiry.js +2 -13
- package/dist/_internal/server/jobs/handlers/dailyDataCleanup.js +2 -20
- package/dist/_internal/server/jobs/handlers/listingProcessor.d.ts +3 -28
- package/dist/_internal/server/jobs/handlers/listingProcessor.js +3 -138
- package/dist/_internal/server/jobs/handlers/mediaTmpCleanup.d.ts +0 -12
- package/dist/_internal/server/jobs/handlers/mediaTmpCleanup.js +2 -69
- package/dist/_internal/server/jobs/handlers/notificationPrune.js +2 -13
- package/dist/_internal/server/jobs/handlers/offerExpiry.js +2 -50
- package/dist/_internal/server/jobs/handlers/onBidPlaced.d.ts +1 -10
- package/dist/_internal/server/jobs/handlers/onBidPlaced.js +2 -56
- package/dist/_internal/server/jobs/handlers/onCategoryWrite.d.ts +1 -8
- package/dist/_internal/server/jobs/handlers/onCategoryWrite.js +6 -134
- package/dist/_internal/server/jobs/handlers/onOrderCreate.d.ts +1 -12
- package/dist/_internal/server/jobs/handlers/onOrderCreate.js +2 -76
- package/dist/_internal/server/jobs/handlers/onOrderStatusChange.d.ts +1 -12
- package/dist/_internal/server/jobs/handlers/onOrderStatusChange.js +2 -139
- package/dist/_internal/server/jobs/handlers/onProductStockChange.d.ts +0 -13
- package/dist/_internal/server/jobs/handlers/onProductStockChange.js +7 -134
- package/dist/_internal/server/jobs/handlers/onProductWrite.d.ts +1 -6
- package/dist/_internal/server/jobs/handlers/onProductWrite.js +6 -106
- package/dist/_internal/server/jobs/handlers/onReviewWrite.js +2 -49
- package/dist/_internal/server/jobs/handlers/onStoreWrite.d.ts +1 -8
- package/dist/_internal/server/jobs/handlers/onStoreWrite.js +7 -8
- package/dist/_internal/server/jobs/handlers/payoutBatch.d.ts +0 -9
- package/dist/_internal/server/jobs/handlers/payoutBatch.js +2 -104
- package/dist/_internal/server/jobs/handlers/pendingOrderTimeout.d.ts +0 -6
- package/dist/_internal/server/jobs/handlers/pendingOrderTimeout.js +2 -33
- package/dist/_internal/server/jobs/handlers/positionsReconcile.d.ts +0 -5
- package/dist/_internal/server/jobs/handlers/positionsReconcile.js +2 -87
- package/dist/_internal/server/jobs/handlers/prizeRevealClose.d.ts +0 -7
- package/dist/_internal/server/jobs/handlers/prizeRevealClose.js +2 -29
- package/dist/_internal/server/jobs/handlers/prizeRevealExpiry.d.ts +0 -8
- package/dist/_internal/server/jobs/handlers/prizeRevealExpiry.js +2 -58
- package/dist/_internal/server/jobs/handlers/prizeRevealOpen.d.ts +0 -8
- package/dist/_internal/server/jobs/handlers/prizeRevealOpen.js +2 -65
- package/dist/_internal/server/jobs/handlers/prizeRevealReminder.d.ts +0 -7
- package/dist/_internal/server/jobs/handlers/prizeRevealReminder.js +2 -45
- package/dist/_internal/server/jobs/handlers/productStatsSync.d.ts +0 -6
- package/dist/_internal/server/jobs/handlers/productStatsSync.js +2 -36
- package/dist/_internal/server/jobs/handlers/promotions.d.ts +2 -10
- package/dist/_internal/server/jobs/handlers/promotions.js +2 -43
- package/dist/_internal/server/jobs/handlers/storeAnalytics.d.ts +2 -28
- package/dist/_internal/server/jobs/handlers/storeAnalytics.js +2 -109
- package/dist/_internal/server/jobs/handlers/triggerEventRaffle.d.ts +1 -28
- package/dist/_internal/server/jobs/handlers/triggerEventRaffle.js +2 -94
- package/dist/_internal/server/jobs/handlers/weeklyPayoutEligibility.d.ts +0 -6
- package/dist/_internal/server/jobs/handlers/weeklyPayoutEligibility.js +2 -87
- package/dist/_internal/server/jobs/index.d.ts +1 -0
- package/dist/_internal/server/jobs/index.js +1 -0
- package/dist/_internal/server/jobs/runtime/adapters/firebase.js +21 -0
- package/dist/_internal/shared/actions/action-registry.d.ts +84 -0
- package/dist/_internal/shared/actions/action-registry.js +160 -0
- package/dist/_internal/shared/checkout/rules/_defaults.d.ts +3 -0
- package/dist/_internal/shared/checkout/rules/_defaults.js +22 -0
- package/dist/_internal/shared/checkout/rules/_limits.d.ts +19 -0
- package/dist/_internal/shared/checkout/rules/_limits.js +19 -0
- package/dist/_internal/shared/checkout/rules/_registry.d.ts +44 -0
- package/dist/_internal/shared/checkout/rules/_registry.js +87 -0
- package/dist/_internal/shared/checkout/rules/auction.rule.d.ts +2 -0
- package/dist/_internal/shared/checkout/rules/auction.rule.js +10 -0
- package/dist/_internal/shared/checkout/rules/bundle.rule.d.ts +11 -0
- package/dist/_internal/shared/checkout/rules/bundle.rule.js +6 -0
- package/dist/_internal/shared/checkout/rules/classified.rule.d.ts +9 -0
- package/dist/_internal/shared/checkout/rules/classified.rule.js +9 -0
- package/dist/_internal/shared/checkout/rules/digital-code.rule.d.ts +8 -0
- package/dist/_internal/shared/checkout/rules/digital-code.rule.js +6 -0
- package/dist/_internal/shared/checkout/rules/index.d.ts +12 -0
- package/dist/_internal/shared/checkout/rules/index.js +12 -0
- package/dist/_internal/shared/checkout/rules/live.rule.d.ts +10 -0
- package/dist/_internal/shared/checkout/rules/live.rule.js +6 -0
- package/dist/_internal/shared/checkout/rules/offer.rule.d.ts +2 -0
- package/dist/_internal/shared/checkout/rules/offer.rule.js +9 -0
- package/dist/_internal/shared/checkout/rules/preorder.rule.d.ts +2 -0
- package/dist/_internal/shared/checkout/rules/preorder.rule.js +28 -0
- package/dist/_internal/shared/checkout/rules/prize-draw.rule.d.ts +2 -0
- package/dist/_internal/shared/checkout/rules/prize-draw.rule.js +65 -0
- package/dist/_internal/shared/checkout/rules/standard.rule.d.ts +2 -0
- package/dist/_internal/shared/checkout/rules/standard.rule.js +5 -0
- package/dist/_internal/shared/checkout/rules/types.d.ts +125 -0
- package/dist/_internal/shared/checkout/rules/types.js +13 -0
- package/dist/_internal/shared/features/cart/schema.d.ts +6 -6
- package/dist/_internal/shared/features/categories/bundle-copy.d.ts +123 -0
- package/dist/_internal/shared/features/categories/bundle-copy.js +134 -0
- package/dist/_internal/shared/features/categories/bundle-schemas.d.ts +318 -0
- package/dist/_internal/shared/features/categories/bundle-schemas.js +55 -0
- package/dist/_internal/shared/features/orders/refund-copy.d.ts +36 -0
- package/dist/_internal/shared/features/orders/refund-copy.js +40 -0
- package/dist/_internal/shared/features/orders/schema.d.ts +4 -4
- package/dist/_internal/shared/features/products/schema.d.ts +8 -8
- package/dist/_internal/shared/listing-types/_registry.d.ts +27 -0
- package/dist/_internal/shared/listing-types/_registry.js +8 -0
- package/dist/_internal/shared/listing-types/action-tracker.d.ts +41 -0
- package/dist/_internal/shared/listing-types/action-tracker.js +70 -0
- package/dist/_internal/shared/listing-types/capabilities.js +25 -0
- package/dist/_internal/shared/listing-types/cart-shipping.d.ts +37 -0
- package/dist/_internal/shared/listing-types/cart-shipping.js +46 -0
- package/dist/_internal/shared/listing-types/classified/config.d.ts +7 -0
- package/dist/_internal/shared/listing-types/classified/config.js +8 -0
- package/dist/_internal/shared/listing-types/classified/ctas.d.ts +1 -0
- package/dist/_internal/shared/listing-types/classified/ctas.js +3 -0
- package/dist/_internal/shared/listing-types/classified/og.d.ts +1 -0
- package/dist/_internal/shared/listing-types/classified/og.js +1 -0
- package/dist/_internal/shared/listing-types/classified/schema.d.ts +1 -0
- package/dist/_internal/shared/listing-types/classified/schema.js +1 -0
- package/dist/_internal/shared/listing-types/classified/seed-factory.d.ts +1 -0
- package/dist/_internal/shared/listing-types/classified/seed-factory.js +1 -0
- package/dist/_internal/shared/listing-types/digital-code/config.d.ts +7 -0
- package/dist/_internal/shared/listing-types/digital-code/config.js +8 -0
- package/dist/_internal/shared/listing-types/digital-code/ctas.d.ts +1 -0
- package/dist/_internal/shared/listing-types/digital-code/ctas.js +3 -0
- package/dist/_internal/shared/listing-types/digital-code/og.d.ts +1 -0
- package/dist/_internal/shared/listing-types/digital-code/og.js +1 -0
- package/dist/_internal/shared/listing-types/digital-code/schema.d.ts +1 -0
- package/dist/_internal/shared/listing-types/digital-code/schema.js +1 -0
- package/dist/_internal/shared/listing-types/digital-code/seed-factory.d.ts +1 -0
- package/dist/_internal/shared/listing-types/digital-code/seed-factory.js +1 -0
- package/dist/_internal/shared/listing-types/feature-flags.d.ts +34 -0
- package/dist/_internal/shared/listing-types/feature-flags.js +45 -0
- package/dist/_internal/shared/listing-types/live/config.d.ts +7 -0
- package/dist/_internal/shared/listing-types/live/config.js +8 -0
- package/dist/_internal/shared/listing-types/live/ctas.d.ts +1 -0
- package/dist/_internal/shared/listing-types/live/ctas.js +3 -0
- package/dist/_internal/shared/listing-types/live/og.d.ts +1 -0
- package/dist/_internal/shared/listing-types/live/og.js +1 -0
- package/dist/_internal/shared/listing-types/live/schema.d.ts +1 -0
- package/dist/_internal/shared/listing-types/live/schema.js +1 -0
- package/dist/_internal/shared/listing-types/live/seed-factory.d.ts +1 -0
- package/dist/_internal/shared/listing-types/live/seed-factory.js +1 -0
- package/dist/_internal/shared/media/limits.js +8 -0
- package/dist/client.d.ts +6 -1
- package/dist/client.js +14 -1
- package/dist/configs/next.js +7 -0
- package/dist/constants/api-endpoints.d.ts +6 -0
- package/dist/constants/api-endpoints.js +4 -0
- package/dist/core/hooks/useSyncManager.js +13 -1
- package/dist/core/unit-of-work.d.ts +1 -1
- package/dist/core/unit-of-work.js +2 -2
- package/dist/features/account/actions/address-actions.d.ts +1 -1
- package/dist/features/account/actions/address-actions.js +15 -7
- package/dist/features/account/schemas/firestore.d.ts +8 -43
- package/dist/features/account/schemas/firestore.js +8 -54
- package/dist/features/account/schemas/index.d.ts +6 -6
- package/dist/features/account/server.d.ts +1 -1
- package/dist/features/account/server.js +3 -1
- package/dist/features/addresses/index.d.ts +2 -0
- package/dist/features/addresses/index.js +2 -0
- package/dist/features/addresses/repository/addresses.repository.d.ts +29 -0
- package/dist/features/addresses/repository/addresses.repository.js +157 -0
- package/dist/features/addresses/schemas/firestore.d.ts +53 -0
- package/dist/features/addresses/schemas/firestore.js +68 -0
- package/dist/features/{bundles → addresses}/schemas/index.d.ts +0 -1
- package/dist/features/{bundles → addresses}/schemas/index.js +0 -1
- package/dist/features/addresses/server.d.ts +2 -0
- package/dist/features/addresses/server.js +2 -0
- package/dist/features/admin/components/AdminAllEventEntriesView.js +4 -3
- package/dist/features/admin/components/AdminBidsView.js +4 -3
- package/dist/features/admin/components/AdminBlogView.js +8 -3
- package/dist/features/admin/components/AdminBundleEditorView.d.ts +9 -0
- package/dist/features/admin/components/AdminBundleEditorView.js +209 -0
- package/dist/features/admin/components/AdminBundlesView.d.ts +9 -0
- package/dist/features/admin/components/AdminBundlesView.js +59 -0
- package/dist/features/admin/components/AdminCartsView.js +13 -3
- package/dist/features/admin/components/AdminContactView.js +4 -3
- package/dist/features/admin/components/AdminCouponsView.js +32 -13
- package/dist/features/admin/components/AdminNewsletterView.js +4 -3
- package/dist/features/admin/components/AdminOrdersView.js +15 -7
- package/dist/features/admin/components/AdminPayoutsView.js +4 -3
- package/dist/features/admin/components/AdminProductsView.js +6 -5
- package/dist/features/admin/components/AdminReviewsView.js +5 -4
- package/dist/features/admin/components/AdminStoresView.js +4 -3
- package/dist/features/admin/components/AdminUsersView.js +15 -5
- package/dist/features/admin/components/AdminWishlistsView.js +10 -1
- package/dist/features/admin/components/DataTable.d.ts +5 -1
- package/dist/features/admin/components/DataTable.js +24 -20
- package/dist/features/admin/components/index.d.ts +4 -0
- package/dist/features/admin/components/index.js +3 -0
- package/dist/features/admin/constants/filter-tabs.d.ts +401 -0
- package/dist/features/admin/constants/filter-tabs.js +200 -0
- package/dist/features/admin/hooks/useAdminListingData.d.ts +1 -0
- package/dist/features/admin/hooks/useAdminListingData.js +1 -0
- package/dist/features/admin/schemas/firestore.d.ts +15 -0
- package/dist/features/admin/schemas/firestore.js +18 -0
- package/dist/features/admin/types/product.types.d.ts +2 -2
- package/dist/features/auctions/components/AuctionCard.d.ts +4 -1
- package/dist/features/auctions/components/AuctionCard.js +5 -3
- package/dist/features/auctions/components/AuctionDetailPageView.js +1 -1
- package/dist/features/auctions/components/MarketplaceAuctionCard.d.ts +2 -2
- package/dist/features/auctions/components/PlaceBidFormClient.js +12 -2
- package/dist/features/auctions/schemas/index.d.ts +2 -2
- package/dist/features/auth/index.d.ts +1 -0
- package/dist/features/auth/index.js +1 -0
- package/dist/features/auth/role-predicates.d.ts +16 -0
- package/dist/features/auth/role-predicates.js +15 -0
- package/dist/features/blog/components/BlogFeaturedCard.d.ts +4 -1
- package/dist/features/blog/components/BlogFeaturedCard.js +5 -3
- package/dist/features/cart/actions/cart-actions.d.ts +1 -0
- package/dist/features/cart/actions/cart-actions.js +16 -0
- package/dist/features/cart/components/CartView.d.ts +19 -1
- package/dist/features/cart/components/CartView.js +2 -2
- package/dist/features/cart/components/ShippingPicker.d.ts +13 -0
- package/dist/features/cart/components/ShippingPicker.js +48 -0
- package/dist/features/cart/components/index.d.ts +3 -1
- package/dist/features/cart/components/index.js +1 -0
- package/dist/features/cart/hooks/useCartCount.js +7 -1
- package/dist/features/cart/repository/cart.repository.d.ts +1 -0
- package/dist/features/cart/repository/cart.repository.js +35 -0
- package/dist/features/cart/schemas/firestore.d.ts +27 -2
- package/dist/features/categories/components/BundleAddToCartCta.d.ts +16 -0
- package/dist/features/categories/components/BundleAddToCartCta.js +54 -0
- package/dist/features/categories/components/BundleBuyNowCta.d.ts +8 -0
- package/dist/features/categories/components/BundleBuyNowCta.js +37 -0
- package/dist/features/categories/components/BundleDetailView.d.ts +22 -0
- package/dist/features/categories/components/BundleDetailView.js +31 -0
- package/dist/features/categories/components/BundleDynamicRuleEditor.d.ts +18 -0
- package/dist/features/categories/components/BundleDynamicRuleEditor.js +60 -0
- package/dist/features/categories/components/BundleItemsPicker.d.ts +26 -0
- package/dist/features/categories/components/BundleItemsPicker.js +135 -0
- package/dist/features/categories/components/BundlesListView.d.ts +13 -0
- package/dist/features/categories/components/BundlesListView.js +27 -0
- package/dist/features/categories/components/index.d.ts +12 -0
- package/dist/features/categories/components/index.js +9 -0
- package/dist/features/checkout/actions/checkout-actions.js +10 -3
- package/dist/features/events/components/AdminEventEditorView.js +108 -2
- package/dist/features/events/components/AdminEventsView.js +16 -4
- package/dist/features/events/components/EventCard.d.ts +4 -1
- package/dist/features/events/components/EventCard.js +7 -3
- package/dist/features/events/components/EventRaffleWinnerView.d.ts +21 -0
- package/dist/features/events/components/EventRaffleWinnerView.js +18 -0
- package/dist/features/events/components/SpinWheelView.d.ts +27 -0
- package/dist/features/events/components/SpinWheelView.js +64 -0
- package/dist/features/events/components/index.d.ts +4 -0
- package/dist/features/events/components/index.js +2 -0
- package/dist/features/events/schemas/firestore.d.ts +27 -1
- package/dist/features/events/schemas/firestore.js +7 -0
- package/dist/features/events/types/index.d.ts +27 -1
- package/dist/features/homepage/components/FeaturedBundlesSection.d.ts +16 -0
- package/dist/features/homepage/components/FeaturedBundlesSection.js +24 -0
- package/dist/features/homepage/components/MarketplaceHomepageView.js +4 -1
- package/dist/features/homepage/components/WhatsAppCommunitySection.js +2 -2
- package/dist/features/homepage/lib/section-renderer.d.ts +2 -0
- package/dist/features/homepage/lib/section-renderer.js +5 -5
- package/dist/features/layout/NavbarLayout.d.ts +3 -1
- package/dist/features/layout/NavbarLayout.js +32 -3
- package/dist/features/layout/TitleBarLayout.d.ts +6 -3
- package/dist/features/layout/TitleBarLayout.js +22 -7
- package/dist/features/media/upload/MediaUploadField.d.ts +15 -1
- package/dist/features/media/upload/MediaUploadField.js +22 -1
- package/dist/features/orders/components/MarketplaceOrderCard.js +4 -2
- package/dist/features/orders/components/OrderSiblingPayments.d.ts +8 -0
- package/dist/features/orders/components/OrderSiblingPayments.js +16 -0
- package/dist/features/orders/components/RefundHistoryTable.d.ts +6 -0
- package/dist/features/orders/components/RefundHistoryTable.js +23 -0
- package/dist/features/orders/components/RefundRequestView.d.ts +8 -0
- package/dist/features/orders/components/RefundRequestView.js +42 -0
- package/dist/features/orders/components/index.d.ts +6 -0
- package/dist/features/orders/components/index.js +3 -0
- package/dist/features/orders/index.d.ts +1 -0
- package/dist/features/orders/index.js +2 -0
- package/dist/features/orders/repository/orders.repository.d.ts +20 -1
- package/dist/features/orders/repository/orders.repository.js +30 -1
- package/dist/features/orders/schemas/firestore.d.ts +63 -13
- package/dist/features/orders/schemas/firestore.js +5 -5
- package/dist/features/orders/schemas/index.d.ts +4 -4
- package/dist/features/orders/types/index.d.ts +12 -2
- package/dist/features/orders/utils/bundle-grouping.d.ts +48 -0
- package/dist/features/orders/utils/bundle-grouping.js +54 -0
- package/dist/features/orders/utils/order-splitter.d.ts +9 -10
- package/dist/features/orders/utils/order-splitter.js +24 -30
- package/dist/features/payments/repository/payout.repository.d.ts +17 -1
- package/dist/features/payments/repository/payout.repository.js +47 -0
- package/dist/features/payments/schemas/firestore.d.ts +26 -0
- package/dist/features/pre-orders/components/PreorderCard.d.ts +4 -1
- package/dist/features/pre-orders/components/PreorderCard.js +8 -6
- package/dist/features/products/actions/product-actions.d.ts +1 -1
- package/dist/features/products/actions/product-actions.js +1 -1
- package/dist/features/products/components/CompareOverlay.d.ts +2 -2
- package/dist/features/products/components/CompareOverlay.js +4 -4
- package/dist/features/products/components/InteractiveProductCard.js +7 -12
- package/dist/features/products/components/NonRefundableConsentModal.d.ts +1 -1
- package/dist/features/products/components/NonRefundableConsentModal.js +0 -10
- package/dist/features/products/components/ProductGrid.js +28 -12
- package/dist/features/products/components/ShowGroupSection.js +3 -3
- package/dist/features/products/components/SublistingCarouselSection.js +2 -2
- package/dist/features/products/components/index.d.ts +0 -4
- package/dist/features/products/components/index.js +5 -2
- package/dist/features/products/index.d.ts +1 -1
- package/dist/features/products/index.js +3 -1
- package/dist/features/products/repository/products.repository.js +4 -0
- package/dist/features/products/schemas/catalog-product.d.ts +70 -0
- package/dist/features/products/schemas/catalog-product.js +50 -0
- package/dist/features/products/schemas/firestore.d.ts +110 -2
- package/dist/features/products/schemas/firestore.js +30 -0
- package/dist/features/products/schemas/index.d.ts +8 -8
- package/dist/features/products/types/index.d.ts +1 -1
- package/dist/features/products/utils/listing-type.d.ts +9 -0
- package/dist/features/products/utils/listing-type.js +4 -0
- package/dist/features/promotions/actions/coupon-actions.d.ts +2 -2
- package/dist/features/promotions/actions/coupon-actions.js +1 -1
- package/dist/features/promotions/components/CouponCard.d.ts +28 -10
- package/dist/features/promotions/components/CouponCard.js +116 -14
- package/dist/features/promotions/hooks/useCouponValidate.d.ts +1 -1
- package/dist/features/promotions/repository/coupons.repository.d.ts +1 -1
- package/dist/features/reviews/schemas/index.d.ts +2 -2
- package/dist/features/search/schemas/index.d.ts +2 -2
- package/dist/features/search/types/index.d.ts +2 -2
- package/dist/features/seller/components/SellerAuctionsView.js +4 -5
- package/dist/features/seller/components/SellerBidsView.js +5 -13
- package/dist/features/seller/components/SellerCouponsView.js +31 -67
- package/dist/features/seller/components/SellerOffersView.js +4 -5
- package/dist/features/seller/components/SellerOrdersView.js +4 -5
- package/dist/features/seller/components/SellerPayoutsView.js +4 -5
- package/dist/features/seller/components/SellerProductsView.js +4 -8
- package/dist/features/seller/schemas/index.d.ts +2 -2
- package/dist/features/stores/actions/store-address-actions.d.ts +10 -6
- package/dist/features/stores/actions/store-address-actions.js +8 -7
- package/dist/features/stores/components/InteractiveStoreCard.js +3 -10
- package/dist/features/stores/components/StoreDetailLayoutView.js +20 -5
- package/dist/features/stores/schemas/firestore.d.ts +45 -38
- package/dist/features/stores/schemas/firestore.js +2 -49
- package/dist/features/stores/server.d.ts +0 -1
- package/dist/features/stores/server.js +2 -1
- package/dist/features/wishlist/hooks/useWishlistCount.d.ts +7 -9
- package/dist/features/wishlist/hooks/useWishlistCount.js +67 -86
- package/dist/features/wishlist/types/index.d.ts +1 -1
- package/dist/index.d.ts +50 -9
- package/dist/index.js +57 -11
- package/dist/next/routing/route-map.d.ts +6 -0
- package/dist/next/routing/route-map.js +4 -0
- package/dist/providers/db-firebase/admin.d.ts +6 -2
- package/dist/providers/db-firebase/admin.js +23 -0
- package/dist/repositories/index.d.ts +1 -2
- package/dist/repositories/index.js +5 -2
- package/dist/security/authorization.d.ts +2 -1
- package/dist/security/authorization.js +3 -2
- package/dist/seed/actions/demo-seed-actions.d.ts +1 -1
- package/dist/seed/bids-seed-data.d.ts +2 -2
- package/dist/seed/bids-seed-data.js +77 -2
- package/dist/seed/cart-seed-data.d.ts +10 -10
- package/dist/seed/cart-seed-data.js +15 -15
- package/dist/seed/events-seed-data.js +77 -0
- package/dist/seed/manifest.js +16 -8
- package/dist/seed/orders-seed-data.js +41 -2
- package/dist/seed/payouts-seed-data.js +18 -2
- package/dist/seed/stores-seed-data.js +55 -0
- package/dist/server-entry.d.ts +1 -0
- package/dist/server-entry.js +2 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.js +8 -0
- package/dist/tailwind-utilities.css +1 -1
- package/dist/ui/components/FilterChipGroup.d.ts +39 -0
- package/dist/ui/components/FilterChipGroup.js +15 -0
- package/dist/ui/components/HorizontalScroller.js +32 -7
- package/dist/ui/components/HorizontalScroller.style.css +6 -0
- package/dist/ui/components/SiteLogo.js +1 -1
- package/dist/ui/index.d.ts +2 -0
- package/dist/ui/index.js +2 -0
- package/dist/utils/id-generators.d.ts +11 -0
- package/dist/utils/id-generators.js +16 -0
- package/package.json +1 -1
- package/dist/_internal/shared/features/bundles/config.d.ts +0 -6
- package/dist/_internal/shared/features/bundles/config.js +0 -6
- package/dist/_internal/shared/schema-versions.d.ts +0 -76
- package/dist/_internal/shared/schema-versions.js +0 -82
- package/dist/features/account/migrations.d.ts +0 -2
- package/dist/features/account/migrations.js +0 -10
- package/dist/features/admin/migrations.d.ts +0 -2
- package/dist/features/admin/migrations.js +0 -10
- package/dist/features/auctions/migrations.d.ts +0 -2
- package/dist/features/auctions/migrations.js +0 -10
- package/dist/features/auth/migrations.d.ts +0 -2
- package/dist/features/auth/migrations.js +0 -10
- package/dist/features/blog/migrations.d.ts +0 -2
- package/dist/features/blog/migrations.js +0 -10
- package/dist/features/brands/actions/brand-actions.d.ts +0 -2
- package/dist/features/brands/actions/brand-actions.js +0 -5
- package/dist/features/brands/index.d.ts +0 -3
- package/dist/features/brands/index.js +0 -3
- package/dist/features/brands/migrations.d.ts +0 -2
- package/dist/features/brands/migrations.js +0 -10
- package/dist/features/brands/repository/brands.repository.d.ts +0 -13
- package/dist/features/brands/repository/brands.repository.js +0 -60
- package/dist/features/brands/schemas/index.d.ts +0 -33
- package/dist/features/brands/schemas/index.js +0 -15
- package/dist/features/brands/server.d.ts +0 -7
- package/dist/features/brands/server.js +0 -7
- package/dist/features/bundles/components/AdminBundleEditorView.d.ts +0 -8
- package/dist/features/bundles/components/AdminBundleEditorView.js +0 -7
- package/dist/features/bundles/components/BundleDetailPageView.d.ts +0 -9
- package/dist/features/bundles/components/BundleDetailPageView.js +0 -45
- package/dist/features/bundles/components/BundleForm.d.ts +0 -12
- package/dist/features/bundles/components/BundleForm.js +0 -126
- package/dist/features/bundles/components/BundleItemsPicker.d.ts +0 -9
- package/dist/features/bundles/components/BundleItemsPicker.js +0 -77
- package/dist/features/bundles/components/BundlesByCategoryListing.d.ts +0 -6
- package/dist/features/bundles/components/BundlesByCategoryListing.js +0 -50
- package/dist/features/bundles/components/BundlesListingView.d.ts +0 -17
- package/dist/features/bundles/components/BundlesListingView.js +0 -50
- package/dist/features/bundles/components/FeaturedBundlesSection.d.ts +0 -5
- package/dist/features/bundles/components/FeaturedBundlesSection.js +0 -55
- package/dist/features/bundles/components/SellerBundleCreateView.d.ts +0 -8
- package/dist/features/bundles/components/SellerBundleCreateView.js +0 -7
- package/dist/features/bundles/components/SellerBundleEditView.d.ts +0 -9
- package/dist/features/bundles/components/SellerBundleEditView.js +0 -7
- package/dist/features/bundles/components/index.d.ts +0 -18
- package/dist/features/bundles/components/index.js +0 -9
- package/dist/features/bundles/constants/index.d.ts +0 -32
- package/dist/features/bundles/constants/index.js +0 -35
- package/dist/features/bundles/index.d.ts +0 -2
- package/dist/features/bundles/index.js +0 -2
- package/dist/features/bundles/migrations.d.ts +0 -2
- package/dist/features/bundles/migrations.js +0 -10
- package/dist/features/bundles/repository/bundles.repository.d.ts +0 -36
- package/dist/features/bundles/repository/bundles.repository.js +0 -148
- package/dist/features/bundles/repository/index.d.ts +0 -1
- package/dist/features/bundles/repository/index.js +0 -1
- package/dist/features/bundles/schemas/firestore.d.ts +0 -88
- package/dist/features/bundles/schemas/firestore.js +0 -29
- package/dist/features/bundles/schemas/zod.d.ts +0 -377
- package/dist/features/bundles/schemas/zod.js +0 -71
- package/dist/features/cart/migrations.d.ts +0 -2
- package/dist/features/cart/migrations.js +0 -10
- package/dist/features/categories/migrations.d.ts +0 -2
- package/dist/features/categories/migrations.js +0 -10
- package/dist/features/events/migrations.d.ts +0 -2
- package/dist/features/events/migrations.js +0 -10
- package/dist/features/faq/migrations.d.ts +0 -2
- package/dist/features/faq/migrations.js +0 -10
- package/dist/features/grouped/migrations.d.ts +0 -2
- package/dist/features/grouped/migrations.js +0 -10
- package/dist/features/history/migrations.d.ts +0 -2
- package/dist/features/history/migrations.js +0 -10
- package/dist/features/messages/migrations.d.ts +0 -2
- package/dist/features/messages/migrations.js +0 -10
- package/dist/features/orders/migrations.d.ts +0 -2
- package/dist/features/orders/migrations.js +0 -10
- package/dist/features/payments/migrations.d.ts +0 -2
- package/dist/features/payments/migrations.js +0 -10
- package/dist/features/products/migrations.d.ts +0 -2
- package/dist/features/products/migrations.js +0 -10
- package/dist/features/products/repository/sublisting-categories.repository.d.ts +0 -16
- package/dist/features/products/repository/sublisting-categories.repository.js +0 -126
- package/dist/features/products/schemas/sublisting-categories.d.ts +0 -45
- package/dist/features/products/schemas/sublisting-categories.js +0 -16
- package/dist/features/promotions/migrations.d.ts +0 -2
- package/dist/features/promotions/migrations.js +0 -10
- package/dist/features/reviews/migrations.d.ts +0 -2
- package/dist/features/reviews/migrations.js +0 -10
- package/dist/features/scams/migrations.d.ts +0 -2
- package/dist/features/scams/migrations.js +0 -10
- package/dist/features/seller/migrations.d.ts +0 -2
- package/dist/features/seller/migrations.js +0 -10
- package/dist/features/stores/migrations.d.ts +0 -2
- package/dist/features/stores/migrations.js +0 -10
- package/dist/features/sublisting/migrations.d.ts +0 -2
- package/dist/features/sublisting/migrations.js +0 -10
- package/dist/features/sublisting/schemas/firestore.d.ts +0 -32
- package/dist/features/sublisting/schemas/firestore.js +0 -19
- package/dist/features/support/migrations.d.ts +0 -2
- package/dist/features/support/migrations.js +0 -10
- package/dist/features/wishlist/migrations.d.ts +0 -2
- package/dist/features/wishlist/migrations.js +0 -10
- package/dist/seed/_bundle-constants.d.ts +0 -14
- package/dist/seed/_bundle-constants.js +0 -14
- package/dist/seed/anime-figures-seed-data.d.ts +0 -8
- package/dist/seed/anime-figures-seed-data.js +0 -1033
- package/dist/seed/beyblade-seed-data.d.ts +0 -7
- package/dist/seed/beyblade-seed-data.js +0 -1129
- package/dist/seed/brands-seed-data.d.ts +0 -7
- package/dist/seed/brands-seed-data.js +0 -410
- package/dist/seed/bundles-seed-data.d.ts +0 -13
- package/dist/seed/bundles-seed-data.js +0 -229
- package/dist/seed/cosplay-accessories-seed-data.d.ts +0 -8
- package/dist/seed/cosplay-accessories-seed-data.js +0 -647
- package/dist/seed/hot-wheels-seed-data.d.ts +0 -7
- package/dist/seed/hot-wheels-seed-data.js +0 -1612
- package/dist/seed/letitrip-official-seed-data.d.ts +0 -8
- package/dist/seed/letitrip-official-seed-data.js +0 -399
- package/dist/seed/pokemon-carousel-slides-seed-data.d.ts +0 -8
- package/dist/seed/pokemon-carousel-slides-seed-data.js +0 -322
- package/dist/seed/pokemon-categories-seed-data.d.ts +0 -24
- package/dist/seed/pokemon-categories-seed-data.js +0 -547
- package/dist/seed/pokemon-coupons-seed-data.d.ts +0 -6
- package/dist/seed/pokemon-coupons-seed-data.js +0 -465
- package/dist/seed/pokemon-homepage-sections-seed-data.d.ts +0 -7
- package/dist/seed/pokemon-homepage-sections-seed-data.js +0 -241
- package/dist/seed/pokemon-products-seed-data.d.ts +0 -9
- package/dist/seed/pokemon-products-seed-data.js +0 -1791
- package/dist/seed/pokemon-seed-bundle.d.ts +0 -47
- package/dist/seed/pokemon-seed-bundle.js +0 -71
- package/dist/seed/pokemon-stores-seed-data.d.ts +0 -6
- package/dist/seed/pokemon-stores-seed-data.js +0 -179
- package/dist/seed/pokemon-users-seed-data.d.ts +0 -6
- package/dist/seed/pokemon-users-seed-data.js +0 -521
- package/dist/seed/products-seed-data.d.ts +0 -6
- package/dist/seed/products-seed-data.js +0 -2530
- package/dist/seed/retro-gaming-seed-data.d.ts +0 -8
- package/dist/seed/retro-gaming-seed-data.js +0 -801
- package/dist/seed/server.d.ts +0 -2
- package/dist/seed/server.js +0 -7
- package/dist/seed/sublisting-categories-seed-data.d.ts +0 -7
- package/dist/seed/sublisting-categories-seed-data.js +0 -159
- package/dist/seed/transformers-seed-data.d.ts +0 -7
- package/dist/seed/transformers-seed-data.js +0 -530
|
@@ -1,136 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
* Trigger handler: maintain DFS `position` + `subtreeSize` on every category
|
|
3
|
-
* write. CREATE → insert into parent's subtree + shift later siblings;
|
|
4
|
-
* DELETE → shift back; MOVE → mark `positionDirty` so the nightly reconcile
|
|
5
|
-
* job rebuilds (real-time move would require repositioning an entire subtree).
|
|
6
|
-
*/
|
|
7
|
-
import { FieldValue } from "firebase-admin/firestore";
|
|
8
|
-
import { BATCH_LIMIT } from "./messages";
|
|
9
|
-
const CATEGORIES = "categories";
|
|
10
|
-
async function shiftPositions(ctx, threshold, delta, excludeId) {
|
|
11
|
-
const snap = await ctx.db.collection(CATEGORIES).where("position", ">=", threshold).get();
|
|
12
|
-
const docs = snap.docs.filter((d) => d.id !== excludeId && d.data().position >= threshold);
|
|
13
|
-
if (docs.length === 0)
|
|
14
|
-
return 0;
|
|
15
|
-
for (let i = 0; i < docs.length; i += BATCH_LIMIT) {
|
|
16
|
-
const batch = ctx.db.batch();
|
|
17
|
-
for (const doc of docs.slice(i, i + BATCH_LIMIT)) {
|
|
18
|
-
batch.update(doc.ref, {
|
|
19
|
-
position: doc.data().position + delta,
|
|
20
|
-
updatedAt: new Date(),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
await batch.commit();
|
|
24
|
-
}
|
|
25
|
-
return docs.length;
|
|
26
|
-
}
|
|
27
|
-
async function adjustAncestorSubtreeSize(ctx, ancestorIds, delta) {
|
|
28
|
-
if (ancestorIds.length === 0)
|
|
29
|
-
return;
|
|
30
|
-
for (let i = 0; i < ancestorIds.length; i += BATCH_LIMIT) {
|
|
31
|
-
const batch = ctx.db.batch();
|
|
32
|
-
for (const id of ancestorIds.slice(i, i + BATCH_LIMIT)) {
|
|
33
|
-
batch.update(ctx.db.collection(CATEGORIES).doc(id), {
|
|
34
|
-
subtreeSize: FieldValue.increment(delta),
|
|
35
|
-
updatedAt: new Date(),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
await batch.commit();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async function getMaxPosition(ctx, excludeId) {
|
|
42
|
-
const snap = await ctx.db
|
|
43
|
-
.collection(CATEGORIES)
|
|
44
|
-
.orderBy("position", "desc")
|
|
45
|
-
.limit(excludeId ? 2 : 1)
|
|
46
|
-
.get();
|
|
47
|
-
for (const doc of snap.docs) {
|
|
48
|
-
if (doc.id === excludeId)
|
|
49
|
-
continue;
|
|
50
|
-
return doc.data().position ?? 0;
|
|
51
|
-
}
|
|
52
|
-
return 0;
|
|
53
|
-
}
|
|
1
|
+
import { handleCategoryWrite } from "../core/onCategoryWrite";
|
|
54
2
|
export const onCategoryWriteHandler = async (event, ctx) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const isUpdate = !!before && !!after;
|
|
61
|
-
try {
|
|
62
|
-
if (isCreate) {
|
|
63
|
-
const parentIds = after.parentIds ?? [];
|
|
64
|
-
const parentId = parentIds.length > 0 ? parentIds[parentIds.length - 1] : null;
|
|
65
|
-
let insertPosition;
|
|
66
|
-
if (parentId) {
|
|
67
|
-
const parentSnap = await ctx.db.collection(CATEGORIES).doc(parentId).get();
|
|
68
|
-
if (!parentSnap.exists) {
|
|
69
|
-
ctx.logger.warn("Parent not found, appending at end", { categoryId, parentId });
|
|
70
|
-
insertPosition = (await getMaxPosition(ctx, categoryId)) + 1;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
const p = parentSnap.data();
|
|
74
|
-
const parentPos = p.position ?? 0;
|
|
75
|
-
const parentSize = p.subtreeSize ?? 1;
|
|
76
|
-
insertPosition = parentPos + parentSize;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
insertPosition = (await getMaxPosition(ctx, categoryId)) + 1;
|
|
81
|
-
}
|
|
82
|
-
const shifted = await shiftPositions(ctx, insertPosition, +1, categoryId);
|
|
83
|
-
await ctx.db.collection(CATEGORIES).doc(categoryId).update({
|
|
84
|
-
position: insertPosition,
|
|
85
|
-
subtreeSize: 1,
|
|
86
|
-
updatedAt: new Date(),
|
|
87
|
-
});
|
|
88
|
-
await adjustAncestorSubtreeSize(ctx, parentIds, +1);
|
|
89
|
-
ctx.logger.info("Category created — position assigned", {
|
|
90
|
-
categoryId,
|
|
91
|
-
position: insertPosition,
|
|
92
|
-
parentId,
|
|
93
|
-
shifted,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
else if (isDelete) {
|
|
97
|
-
const deletedPos = before.position ?? 0;
|
|
98
|
-
const deletedSize = before.subtreeSize ?? 1;
|
|
99
|
-
const parentIds = before.parentIds ?? [];
|
|
100
|
-
if (deletedPos === 0) {
|
|
101
|
-
ctx.logger.warn("Deleted category had no position — skipping shift", { categoryId });
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const shifted = await shiftPositions(ctx, deletedPos + deletedSize, -deletedSize);
|
|
105
|
-
await adjustAncestorSubtreeSize(ctx, parentIds, -deletedSize);
|
|
106
|
-
ctx.logger.info("Category deleted — positions shifted", {
|
|
107
|
-
categoryId,
|
|
108
|
-
position: deletedPos,
|
|
109
|
-
subtreeSize: deletedSize,
|
|
110
|
-
shifted,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
else if (isUpdate) {
|
|
114
|
-
const beforeParents = before.parentIds ?? [];
|
|
115
|
-
const afterParents = after.parentIds ?? [];
|
|
116
|
-
const beforeParent = beforeParents[beforeParents.length - 1] ?? null;
|
|
117
|
-
const afterParent = afterParents[afterParents.length - 1] ?? null;
|
|
118
|
-
if (beforeParent !== afterParent) {
|
|
119
|
-
await ctx.db
|
|
120
|
-
.collection(CATEGORIES)
|
|
121
|
-
.doc(categoryId)
|
|
122
|
-
.update({ positionDirty: true, updatedAt: new Date() });
|
|
123
|
-
ctx.logger.warn("Category moved — positionDirty flagged for nightly reconcile", {
|
|
124
|
-
categoryId,
|
|
125
|
-
fromParent: beforeParent,
|
|
126
|
-
toParent: afterParent,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
ctx.logger.error("Position update failed (non-fatal — will heal on next reconcile)", err, {
|
|
133
|
-
categoryId,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
3
|
+
await handleCategoryWrite({
|
|
4
|
+
categoryId: event.params.categoryId,
|
|
5
|
+
before: event.before,
|
|
6
|
+
after: event.after,
|
|
7
|
+
}, ctx);
|
|
136
8
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
1
|
import type { FirestoreTriggerHandler } from "../runtime/types";
|
|
2
|
-
|
|
3
|
-
title?: string;
|
|
4
|
-
name?: string;
|
|
5
|
-
}
|
|
6
|
-
interface NewOrder {
|
|
7
|
-
buyerDisplayName?: string;
|
|
8
|
-
buyerId?: string;
|
|
9
|
-
items?: OrderItem[];
|
|
10
|
-
totalAmount?: number;
|
|
11
|
-
storeId?: string;
|
|
12
|
-
}
|
|
2
|
+
import { type NewOrder } from "../core/onOrderCreate";
|
|
13
3
|
export declare const onOrderCreateHandler: FirestoreTriggerHandler<null, NewOrder>;
|
|
14
|
-
export {};
|
|
@@ -1,83 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { decryptPii } from "../../../../security/index";
|
|
3
|
-
import { sendWhatsAppBusinessMessage, buildPurchaseAnnouncementMessage, } from "../../../../features/whatsapp-bot/server";
|
|
4
|
-
async function sendAnnouncement(ctx, toPhone, message, phoneNumberId, accessToken, label, orderId) {
|
|
5
|
-
try {
|
|
6
|
-
const sent = await sendWhatsAppBusinessMessage({
|
|
7
|
-
toPhone,
|
|
8
|
-
message,
|
|
9
|
-
phoneNumberId,
|
|
10
|
-
accessToken,
|
|
11
|
-
});
|
|
12
|
-
if (sent) {
|
|
13
|
-
ctx.logger.info(`Announcement sent to ${label}`, {
|
|
14
|
-
orderId,
|
|
15
|
-
toPhone: `...${toPhone.slice(-4)}`,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
ctx.logger.error(`Announcement delivery failed for ${label} (non-fatal)`, null, { orderId });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
ctx.logger.error(`Announcement send threw for ${label} (non-fatal)`, err, { orderId });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
import { handleOrderCreate } from "../core/onOrderCreate";
|
|
26
2
|
export const onOrderCreateHandler = async (event, ctx) => {
|
|
27
3
|
const order = event.after;
|
|
28
4
|
if (!order) {
|
|
29
5
|
ctx.logger.error("No snapshot data", null);
|
|
30
6
|
return;
|
|
31
7
|
}
|
|
32
|
-
|
|
33
|
-
const phoneNumberId = ctx.env("WHATSAPP_PHONE_NUMBER_ID") ?? "";
|
|
34
|
-
const accessToken = ctx.env("WHATSAPP_CLOUD_API_TOKEN") ?? "";
|
|
35
|
-
if (!phoneNumberId || !accessToken) {
|
|
36
|
-
ctx.logger.info("WhatsApp Cloud API not configured — skipping announcement", { orderId });
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const items = order.items ?? [];
|
|
40
|
-
const firstItem = items[0];
|
|
41
|
-
const firstItemName = firstItem?.title ?? firstItem?.name ?? "an item";
|
|
42
|
-
const additionalItemCount = Math.max(0, items.length - 1);
|
|
43
|
-
const buyerName = order.buyerDisplayName ?? "A customer";
|
|
44
|
-
const message = buildPurchaseAnnouncementMessage({
|
|
45
|
-
buyerName,
|
|
46
|
-
firstItemName,
|
|
47
|
-
additionalItemCount,
|
|
48
|
-
totalAmount: order.totalAmount ?? 0,
|
|
49
|
-
orderId,
|
|
50
|
-
});
|
|
51
|
-
const adminNumbersRaw = ctx.env("WHATSAPP_ADMIN_NOTIFY_NUMBERS") ?? "";
|
|
52
|
-
const adminNumbers = adminNumbersRaw
|
|
53
|
-
.split(",")
|
|
54
|
-
.map((n) => n.trim().replace(/\D/g, ""))
|
|
55
|
-
.filter(Boolean);
|
|
56
|
-
for (const num of adminNumbers) {
|
|
57
|
-
await sendAnnouncement(ctx, num, message, phoneNumberId, accessToken, "admin", orderId);
|
|
58
|
-
}
|
|
59
|
-
const storeId = order.storeId;
|
|
60
|
-
if (storeId) {
|
|
61
|
-
try {
|
|
62
|
-
const store = await storeRepository.findBySlug(storeId);
|
|
63
|
-
if (store?.ownerId) {
|
|
64
|
-
const owner = await userRepository.findById(store.ownerId);
|
|
65
|
-
const encryptedPhone = owner?.phoneNumber;
|
|
66
|
-
if (encryptedPhone) {
|
|
67
|
-
const ownerPhone = decryptPii(encryptedPhone);
|
|
68
|
-
if (ownerPhone) {
|
|
69
|
-
await sendAnnouncement(ctx, ownerPhone, message, phoneNumberId, accessToken, "store-owner", orderId);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (err) {
|
|
75
|
-
ctx.logger.error("Store owner lookup failed (non-fatal)", err, { orderId, storeId });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
ctx.logger.info(`Order announcement complete`, {
|
|
79
|
-
orderId,
|
|
80
|
-
adminCount: adminNumbers.length,
|
|
81
|
-
storeId: storeId ?? "unknown",
|
|
82
|
-
});
|
|
8
|
+
await handleOrderCreate({ orderId: event.params.orderId, order }, ctx);
|
|
83
9
|
};
|
|
@@ -1,14 +1,3 @@
|
|
|
1
1
|
import type { FirestoreTriggerHandler } from "../runtime/types";
|
|
2
|
-
|
|
3
|
-
type OrderAfter = {
|
|
4
|
-
status: OrderStatus;
|
|
5
|
-
userId: string;
|
|
6
|
-
userEmail: string;
|
|
7
|
-
productTitle: string;
|
|
8
|
-
trackingNumber?: string;
|
|
9
|
-
};
|
|
10
|
-
type OrderBefore = {
|
|
11
|
-
status: OrderStatus;
|
|
12
|
-
};
|
|
2
|
+
import { type OrderAfter, type OrderBefore } from "../core/onOrderStatusChange";
|
|
13
3
|
export declare const onOrderStatusChangeHandler: FirestoreTriggerHandler<OrderBefore, OrderAfter>;
|
|
14
|
-
export {};
|
|
@@ -1,141 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { decryptPii } from "../../../../security/index";
|
|
3
|
-
import { getAdminRealtimeDb } from "../../../../providers/db-firebase";
|
|
4
|
-
import { ORDER_MESSAGES, EMAIL_SUBJECTS, JOB_ERROR_MESSAGES } from "./messages";
|
|
5
|
-
const STATUS_CONFIG = {
|
|
6
|
-
confirmed: {
|
|
7
|
-
type: "order_confirmed",
|
|
8
|
-
title: ORDER_MESSAGES.CONFIRMED_TITLE,
|
|
9
|
-
message: (o) => ORDER_MESSAGES.CONFIRMED_MESSAGE(o.productTitle),
|
|
10
|
-
priority: "normal",
|
|
11
|
-
sendEmail: true,
|
|
12
|
-
},
|
|
13
|
-
shipped: {
|
|
14
|
-
type: "order_shipped",
|
|
15
|
-
title: ORDER_MESSAGES.SHIPPED_TITLE,
|
|
16
|
-
message: (o) => ORDER_MESSAGES.SHIPPED_MESSAGE(o.productTitle, o.trackingNumber),
|
|
17
|
-
priority: "high",
|
|
18
|
-
sendEmail: true,
|
|
19
|
-
},
|
|
20
|
-
delivered: {
|
|
21
|
-
type: "order_delivered",
|
|
22
|
-
title: ORDER_MESSAGES.DELIVERED_TITLE,
|
|
23
|
-
message: (o) => ORDER_MESSAGES.DELIVERED_MESSAGE(o.productTitle),
|
|
24
|
-
priority: "normal",
|
|
25
|
-
sendEmail: true,
|
|
26
|
-
},
|
|
27
|
-
cancelled: {
|
|
28
|
-
type: "order_cancelled",
|
|
29
|
-
title: ORDER_MESSAGES.CANCELLED_TITLE,
|
|
30
|
-
message: (o) => `Your order for "${o.productTitle}" has been cancelled.`,
|
|
31
|
-
priority: "normal",
|
|
32
|
-
sendEmail: false,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
async function sendResendEmail(params) {
|
|
36
|
-
const subject = params.status === "confirmed"
|
|
37
|
-
? EMAIL_SUBJECTS.ORDER_CONFIRMED(params.productTitle)
|
|
38
|
-
: params.status === "shipped"
|
|
39
|
-
? EMAIL_SUBJECTS.ORDER_SHIPPED(params.productTitle)
|
|
40
|
-
: params.status === "delivered"
|
|
41
|
-
? EMAIL_SUBJECTS.ORDER_DELIVERED(params.productTitle)
|
|
42
|
-
: EMAIL_SUBJECTS.ORDER_UPDATE_FALLBACK(params.productTitle);
|
|
43
|
-
const response = await fetch("https://api.resend.com/emails", {
|
|
44
|
-
method: "POST",
|
|
45
|
-
headers: {
|
|
46
|
-
Authorization: `Bearer ${params.apiKey}`,
|
|
47
|
-
"Content-Type": "application/json",
|
|
48
|
-
},
|
|
49
|
-
body: JSON.stringify({
|
|
50
|
-
from: params.fromAddress,
|
|
51
|
-
to: [params.to],
|
|
52
|
-
subject,
|
|
53
|
-
html: `<p>Hi,</p><p>Your order for <strong>${params.productTitle}</strong> is now <strong>${params.status}</strong>.</p>${params.trackingNumber ? `<p>Tracking number: ${params.trackingNumber}</p>` : ""}<p>Thanks,<br/>${params.brandName} Team</p>`,
|
|
54
|
-
}),
|
|
55
|
-
});
|
|
56
|
-
if (!response.ok) {
|
|
57
|
-
const body = await response.text();
|
|
58
|
-
throw new Error(JOB_ERROR_MESSAGES.RESEND_API_ERROR(response.status, body));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
1
|
+
import { handleOrderStatusChange, } from "../core/onOrderStatusChange";
|
|
61
2
|
export const onOrderStatusChangeHandler = async (event, ctx) => {
|
|
62
|
-
|
|
63
|
-
if (!before || !after)
|
|
64
|
-
return;
|
|
65
|
-
if (before.status === after.status)
|
|
66
|
-
return;
|
|
67
|
-
const orderId = event.params.orderId;
|
|
68
|
-
const newStatus = after.status;
|
|
69
|
-
const config = STATUS_CONFIG[newStatus];
|
|
70
|
-
if (!config) {
|
|
71
|
-
ctx.logger.info(`No handler for status transition → ${newStatus}`, { orderId });
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
// Decrypt PII that was encrypted at rest
|
|
75
|
-
const userEmail = decryptPii(after.userEmail);
|
|
76
|
-
try {
|
|
77
|
-
const messageText = config.message({
|
|
78
|
-
productTitle: after.productTitle,
|
|
79
|
-
trackingNumber: after.trackingNumber,
|
|
80
|
-
});
|
|
81
|
-
await notificationRepository.create({
|
|
82
|
-
userId: after.userId,
|
|
83
|
-
type: config.type,
|
|
84
|
-
priority: config.priority,
|
|
85
|
-
title: config.title,
|
|
86
|
-
message: messageText,
|
|
87
|
-
relatedId: orderId,
|
|
88
|
-
relatedType: "order",
|
|
89
|
-
});
|
|
90
|
-
try {
|
|
91
|
-
await getAdminRealtimeDb().ref(`notifications/${after.userId}`).push({
|
|
92
|
-
type: config.type,
|
|
93
|
-
title: config.title,
|
|
94
|
-
message: messageText,
|
|
95
|
-
timestamp: Date.now(),
|
|
96
|
-
read: false,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
catch (rtdbError) {
|
|
100
|
-
ctx.logger.error("Realtime DB push failed (non-fatal)", rtdbError);
|
|
101
|
-
}
|
|
102
|
-
if (config.sendEmail) {
|
|
103
|
-
const apiKey = ctx.env("RESEND_API_KEY") ?? "";
|
|
104
|
-
if (!apiKey) {
|
|
105
|
-
ctx.logger.error(JOB_ERROR_MESSAGES.RESEND_KEY_MISSING, null);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
try {
|
|
109
|
-
const fromAddress = ctx.env("ORDER_EMAIL_FROM") ?? ctx.env("RESEND_FROM_ADDRESS") ?? "";
|
|
110
|
-
const brandName = ctx.env("APPKIT_BRAND_NAME") ?? "";
|
|
111
|
-
if (!fromAddress || !brandName) {
|
|
112
|
-
ctx.logger.error("ORDER_EMAIL_FROM / APPKIT_BRAND_NAME not configured — skipping order status email", null, { orderId });
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
await sendResendEmail({
|
|
116
|
-
to: userEmail,
|
|
117
|
-
status: newStatus,
|
|
118
|
-
orderId,
|
|
119
|
-
productTitle: after.productTitle,
|
|
120
|
-
trackingNumber: after.trackingNumber,
|
|
121
|
-
apiKey,
|
|
122
|
-
fromAddress,
|
|
123
|
-
brandName,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch (emailError) {
|
|
128
|
-
ctx.logger.error("Email send failed (non-fatal)", emailError, { orderId });
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
ctx.logger.info(`Order ${orderId} status → ${newStatus}`, {
|
|
133
|
-
userId: after.userId,
|
|
134
|
-
emailSent: config.sendEmail,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
ctx.logger.error("Error handling order status change", error, { orderId });
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
3
|
+
await handleOrderStatusChange({ orderId: event.params.orderId, before: event.before, after: event.after }, ctx);
|
|
141
4
|
};
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* onProductStockChange — SB-UNI-V Firestore onWrite trigger on products.
|
|
3
|
-
*
|
|
4
|
-
* Fires when any product document is created / updated / deleted. Looks
|
|
5
|
-
* up every bundle category (categoryType:"bundle") that lists the product
|
|
6
|
-
* in `bundleProductIds[]` and recomputes its `bundleStockStatus`. Also
|
|
7
|
-
* updates every grouped listing that lists the product in `productIds[]`
|
|
8
|
-
* — bumps `activeMemberCount` and `visibilityStatus`.
|
|
9
|
-
*
|
|
10
|
-
* Cheap: each affected bundle/group reads its `bundleProductIds.length`
|
|
11
|
-
* member products (≤16 typically). Skips entirely when the product's
|
|
12
|
-
* status didn't transition between "available" and "unavailable".
|
|
13
|
-
*/
|
|
14
1
|
import type { FirestoreTriggerHandler } from "../runtime/types";
|
|
15
2
|
type ProductDoc = Record<string, unknown>;
|
|
16
3
|
export declare const onProductStockChangeHandler: FirestoreTriggerHandler<ProductDoc, ProductDoc>;
|
|
@@ -1,136 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
* onProductStockChange — SB-UNI-V Firestore onWrite trigger on products.
|
|
3
|
-
*
|
|
4
|
-
* Fires when any product document is created / updated / deleted. Looks
|
|
5
|
-
* up every bundle category (categoryType:"bundle") that lists the product
|
|
6
|
-
* in `bundleProductIds[]` and recomputes its `bundleStockStatus`. Also
|
|
7
|
-
* updates every grouped listing that lists the product in `productIds[]`
|
|
8
|
-
* — bumps `activeMemberCount` and `visibilityStatus`.
|
|
9
|
-
*
|
|
10
|
-
* Cheap: each affected bundle/group reads its `bundleProductIds.length`
|
|
11
|
-
* member products (≤16 typically). Skips entirely when the product's
|
|
12
|
-
* status didn't transition between "available" and "unavailable".
|
|
13
|
-
*/
|
|
14
|
-
const CATEGORIES_COLLECTION = "categories";
|
|
15
|
-
const GROUPED_LISTINGS_COLLECTION = "groupedListings";
|
|
16
|
-
const PRODUCT_COLLECTION = "products";
|
|
17
|
-
const UNAVAILABLE_STATUSES = new Set(["sold", "out_of_stock", "discontinued"]);
|
|
18
|
-
const MIN_ACTIVE_DEFAULT = 2;
|
|
19
|
-
function isAvailable(status) {
|
|
20
|
-
if (!status)
|
|
21
|
-
return false;
|
|
22
|
-
return !UNAVAILABLE_STATUSES.has(status);
|
|
23
|
-
}
|
|
24
|
-
async function recomputeBundleStatus(productIds, minActive, ctx) {
|
|
25
|
-
if (productIds.length === 0)
|
|
26
|
-
return "out_of_stock";
|
|
27
|
-
let unavailable = 0;
|
|
28
|
-
for (let i = 0; i < productIds.length; i += 30) {
|
|
29
|
-
const chunk = productIds.slice(i, i + 30);
|
|
30
|
-
const snap = await ctx.db
|
|
31
|
-
.collection(PRODUCT_COLLECTION)
|
|
32
|
-
.where("__name__", "in", chunk)
|
|
33
|
-
.get();
|
|
34
|
-
for (const doc of snap.docs) {
|
|
35
|
-
const status = doc.data().status;
|
|
36
|
-
if (!isAvailable(status))
|
|
37
|
-
unavailable++;
|
|
38
|
-
}
|
|
39
|
-
if (snap.size < chunk.length)
|
|
40
|
-
unavailable += chunk.length - snap.size;
|
|
41
|
-
}
|
|
42
|
-
const active = productIds.length - unavailable;
|
|
43
|
-
if (unavailable === 0)
|
|
44
|
-
return "in_stock";
|
|
45
|
-
if (active < minActive)
|
|
46
|
-
return "out_of_stock";
|
|
47
|
-
return "partial";
|
|
48
|
-
}
|
|
49
|
-
async function syncBundlesForProduct(productId, ctx) {
|
|
50
|
-
const snap = await ctx.db
|
|
51
|
-
.collection(CATEGORIES_COLLECTION)
|
|
52
|
-
.where("categoryType", "==", "bundle")
|
|
53
|
-
.where("bundleProductIds", "array-contains", productId)
|
|
54
|
-
.get();
|
|
55
|
-
let updated = 0;
|
|
56
|
-
for (const bundleDoc of snap.docs) {
|
|
57
|
-
const data = bundleDoc.data();
|
|
58
|
-
const ids = data.bundleProductIds ?? [];
|
|
59
|
-
const minActive = data.minActiveMembers ?? 1;
|
|
60
|
-
const next = await recomputeBundleStatus(ids, minActive, ctx);
|
|
61
|
-
if (next !== data.bundleStockStatus) {
|
|
62
|
-
await bundleDoc.ref.update({
|
|
63
|
-
bundleStockStatus: next,
|
|
64
|
-
bundleQueryResolvedAt: ctx.now,
|
|
65
|
-
updatedAt: ctx.now,
|
|
66
|
-
});
|
|
67
|
-
updated++;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return updated;
|
|
71
|
-
}
|
|
72
|
-
async function syncGroupedListingsForProduct(productId, ctx) {
|
|
73
|
-
const snap = await ctx.db
|
|
74
|
-
.collection(GROUPED_LISTINGS_COLLECTION)
|
|
75
|
-
.where("productIds", "array-contains", productId)
|
|
76
|
-
.get();
|
|
77
|
-
let updated = 0;
|
|
78
|
-
for (const groupDoc of snap.docs) {
|
|
79
|
-
const data = groupDoc.data();
|
|
80
|
-
const productIds = data.productIds ?? [];
|
|
81
|
-
if (productIds.length === 0)
|
|
82
|
-
continue;
|
|
83
|
-
const minActive = data.minActiveMembers ?? MIN_ACTIVE_DEFAULT;
|
|
84
|
-
let activeCount = 0;
|
|
85
|
-
for (let i = 0; i < productIds.length; i += 30) {
|
|
86
|
-
const chunk = productIds.slice(i, i + 30);
|
|
87
|
-
const productSnap = await ctx.db
|
|
88
|
-
.collection(PRODUCT_COLLECTION)
|
|
89
|
-
.where("__name__", "in", chunk)
|
|
90
|
-
.get();
|
|
91
|
-
for (const doc of productSnap.docs) {
|
|
92
|
-
const status = doc.data().status;
|
|
93
|
-
if (isAvailable(status))
|
|
94
|
-
activeCount++;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const nextVisibility = activeCount >= minActive ? "visible" : "hidden";
|
|
98
|
-
if (activeCount !== data.activeMemberCount ||
|
|
99
|
-
nextVisibility !== data.visibilityStatus) {
|
|
100
|
-
await groupDoc.ref.update({
|
|
101
|
-
activeMemberCount: activeCount,
|
|
102
|
-
visibilityStatus: nextVisibility,
|
|
103
|
-
updatedAt: ctx.now,
|
|
104
|
-
});
|
|
105
|
-
updated++;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return updated;
|
|
109
|
-
}
|
|
1
|
+
import { handleProductStockChange } from "../core/onProductStockChange";
|
|
110
2
|
export const onProductStockChangeHandler = async (event, ctx) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const afterAvailable = isAvailable(after?.status);
|
|
118
|
-
const isDelete = !after;
|
|
119
|
-
const stateFlipped = beforeAvailable !== afterAvailable;
|
|
120
|
-
if (!isDelete && !stateFlipped) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
const bundlesUpdated = await syncBundlesForProduct(productId, ctx);
|
|
125
|
-
const groupsUpdated = await syncGroupedListingsForProduct(productId, ctx);
|
|
126
|
-
ctx.logger.info("onProductStockChange synced", {
|
|
127
|
-
productId,
|
|
128
|
-
bundlesUpdated,
|
|
129
|
-
groupsUpdated,
|
|
130
|
-
isDelete,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
catch (err) {
|
|
134
|
-
ctx.logger.error("onProductStockChange sync failed (non-fatal)", err, { productId });
|
|
135
|
-
}
|
|
3
|
+
await handleProductStockChange({
|
|
4
|
+
productId: event.params.productId,
|
|
5
|
+
beforeStatus: event.before?.status ?? null,
|
|
6
|
+
afterStatus: event.after?.status ?? null,
|
|
7
|
+
isDelete: !event.after,
|
|
8
|
+
}, ctx);
|
|
136
9
|
};
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Trigger handler: keep category metrics + store stats in sync when a
|
|
3
|
-
* product document is written. Only published products count.
|
|
4
|
-
*/
|
|
5
1
|
import type { FirestoreTriggerHandler } from "../runtime/types";
|
|
6
|
-
type ProductDoc
|
|
2
|
+
import { type ProductDoc } from "../core/onProductWrite";
|
|
7
3
|
export declare const onProductWriteHandler: FirestoreTriggerHandler<ProductDoc, ProductDoc>;
|
|
8
|
-
export {};
|