@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,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* maxPerUser gate + prize reveal deadline helper for the checkout pipeline
|
|
3
|
+
* (SB6-C, SB8-A).
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* `enforcePrizePoolCap` was removed in S-SBUNI-RULES (2026-05-13) — the
|
|
6
|
+
* equivalent check now lives in `prizeDrawRule.preflightChecks` in the rule
|
|
7
|
+
* registry and is invoked via `runSyncPreflight`.
|
|
7
8
|
*/
|
|
8
9
|
import { ValidationError } from "../../../../errors";
|
|
9
10
|
import { orderRepository } from "../../../../repositories";
|
|
@@ -80,20 +81,3 @@ export function computePrizeRevealDeadline(product, now = new Date()) {
|
|
|
80
81
|
const candidate = new Date(base.getTime() + days * dayMs);
|
|
81
82
|
return candidate.getTime() < windowEnd.getTime() ? candidate : windowEnd;
|
|
82
83
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Inside the existing checkout transaction, validate the prize-pool cap for
|
|
85
|
-
* each prize-draw line. Caller must pass the fresh product snapshot read
|
|
86
|
-
* within the transaction (so `prizeCurrentEntries` is up-to-date).
|
|
87
|
-
*
|
|
88
|
-
* Throws ValidationError if any item would overflow the pool.
|
|
89
|
-
*/
|
|
90
|
-
export function enforcePrizePoolCap(args) {
|
|
91
|
-
const { productSnapshot, requestedQuantity } = args;
|
|
92
|
-
if (productSnapshot.listingType !== "prize-draw")
|
|
93
|
-
return;
|
|
94
|
-
const max = productSnapshot.prizeMaxEntries ?? 0;
|
|
95
|
-
const current = productSnapshot.prizeCurrentEntries ?? 0;
|
|
96
|
-
if (max > 0 && current + requestedQuantity > max) {
|
|
97
|
-
throw Object.assign(new ValidationError(`Draw is full for "${productSnapshot.title}". ${current}/${max} entries already in.`), { code: "PRIZE_POOL_FULL", productId: productSnapshot.id });
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -29,6 +29,8 @@ export const CONTEXT_LIMITS = {
|
|
|
29
29
|
BLOG_ADDITIONAL_IMAGE_MAX: 5,
|
|
30
30
|
RICH_TEXT_IMAGE_MAX: 20,
|
|
31
31
|
};
|
|
32
|
+
// Contexts that accept both image and PDF (proof documents).
|
|
33
|
+
const IMAGE_OR_PDF_CONTEXTS = ["shipping-proof", "refund-proof"];
|
|
32
34
|
const PDF_ONLY_CONTEXTS = ["invoice", "payout-doc"];
|
|
33
35
|
const IMAGE_ONLY_CONTEXT_TYPES = new Set([
|
|
34
36
|
"store-logo",
|
|
@@ -170,6 +172,7 @@ export function applyMediaContextGuards({ detectedMime, context: ctx, }) {
|
|
|
170
172
|
};
|
|
171
173
|
}
|
|
172
174
|
const isPdfOnlyContext = (c) => PDF_ONLY_CONTEXTS.includes(c.type);
|
|
175
|
+
const isImageOrPdfContext = (c) => IMAGE_OR_PDF_CONTEXTS.includes(c.type);
|
|
173
176
|
const ext = MIME_TO_EXT[detectedMime] ?? "bin";
|
|
174
177
|
if (isPdfOnlyContext(ctx)) {
|
|
175
178
|
if (!isPdf) {
|
|
@@ -182,11 +185,22 @@ export function applyMediaContextGuards({ detectedMime, context: ctx, }) {
|
|
|
182
185
|
}
|
|
183
186
|
return { ok: true, filename: generateMediaFilename(ctx), ext };
|
|
184
187
|
}
|
|
188
|
+
if (isImageOrPdfContext(ctx)) {
|
|
189
|
+
// shipping-proof and refund-proof accept images or PDFs, not video.
|
|
190
|
+
if (isVideo) {
|
|
191
|
+
return {
|
|
192
|
+
ok: false,
|
|
193
|
+
status: 400,
|
|
194
|
+
error: `${ctx.type} must be an image or PDF, not a video`,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return { ok: true, filename: generateMediaFilename(ctx), ext };
|
|
198
|
+
}
|
|
185
199
|
if (isPdf) {
|
|
186
200
|
return {
|
|
187
201
|
ok: false,
|
|
188
202
|
status: 400,
|
|
189
|
-
error: "PDF uploads are only allowed for invoice
|
|
203
|
+
error: "PDF uploads are only allowed for invoice, payout-doc, shipping-proof, or refund-proof contexts",
|
|
190
204
|
details: { context: ctx.type, detected: detectedMime },
|
|
191
205
|
};
|
|
192
206
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ApplyRefundDeductionInput = {
|
|
2
|
+
storeId: string;
|
|
3
|
+
orderId: string;
|
|
4
|
+
refundId: string;
|
|
5
|
+
/** Gross refund amount in paise. */
|
|
6
|
+
refundedAmountInPaise: number;
|
|
7
|
+
/** Platform fee rate (0–1). Defaults to DEFAULT_PLATFORM_FEE_RATE (0.05). */
|
|
8
|
+
platformFeeRate?: number;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
export type ApplyRefundDeductionResult = {
|
|
12
|
+
applied: true;
|
|
13
|
+
payoutId: string;
|
|
14
|
+
netAmount: number;
|
|
15
|
+
} | {
|
|
16
|
+
applied: false;
|
|
17
|
+
reason: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function applyRefundDeductionAction(input: ApplyRefundDeductionInput): Promise<ApplyRefundDeductionResult>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
/**
|
|
3
|
+
* applyRefundDeductionAction — deduct a refund from a seller's pending payout.
|
|
4
|
+
*
|
|
5
|
+
* Called fire-and-forget after processRefundAction succeeds:
|
|
6
|
+
* 1. Locate the most recent pending payout for the order's store.
|
|
7
|
+
* 2. If found and it covers the refunded order, apply the deduction.
|
|
8
|
+
* 3. If no pending payout exists (already settled), return applied:false —
|
|
9
|
+
* the reduced net revenue is automatically reflected in the next payout
|
|
10
|
+
* cycle because the order revenue was never re-added.
|
|
11
|
+
*
|
|
12
|
+
* deductedAmount = refundedAmount × (1 − platformFeeRate).
|
|
13
|
+
* The platform keeps its fee share on every refund.
|
|
14
|
+
*/
|
|
15
|
+
import { payoutRepository } from "../../../../repositories";
|
|
16
|
+
import { ValidationError } from "../../../../errors";
|
|
17
|
+
export async function applyRefundDeductionAction(input) {
|
|
18
|
+
if (input.refundedAmountInPaise <= 0) {
|
|
19
|
+
throw new ValidationError("Refund amount must be positive");
|
|
20
|
+
}
|
|
21
|
+
const feeRate = input.platformFeeRate ?? 0.05;
|
|
22
|
+
const deductedAmount = Math.round(input.refundedAmountInPaise * (1 - feeRate));
|
|
23
|
+
const pending = await payoutRepository.findPendingByStore(input.storeId);
|
|
24
|
+
if (!pending) {
|
|
25
|
+
return { applied: false, reason: "no_pending_payout" };
|
|
26
|
+
}
|
|
27
|
+
if (!pending.orderIds.includes(input.orderId)) {
|
|
28
|
+
return { applied: false, reason: "order_not_in_payout" };
|
|
29
|
+
}
|
|
30
|
+
const updated = await payoutRepository.applyRefundDeduction(pending.id, {
|
|
31
|
+
orderId: input.orderId,
|
|
32
|
+
refundId: input.refundId,
|
|
33
|
+
refundedAmount: input.refundedAmountInPaise,
|
|
34
|
+
deductedAmount,
|
|
35
|
+
reason: input.reason,
|
|
36
|
+
});
|
|
37
|
+
return { applied: true, payoutId: updated.id, netAmount: updated.netAmount ?? updated.amount };
|
|
38
|
+
}
|
|
@@ -31,8 +31,7 @@ export async function listSitemapProducts() {
|
|
|
31
31
|
const rawListingType = data.listingType;
|
|
32
32
|
const listingType = rawListingType === "auction" ||
|
|
33
33
|
rawListingType === "pre-order" ||
|
|
34
|
-
rawListingType === "prize-draw"
|
|
35
|
-
rawListingType === "bundle"
|
|
34
|
+
rawListingType === "prize-draw"
|
|
36
35
|
? rawListingType
|
|
37
36
|
: "standard";
|
|
38
37
|
return {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SB9-H — server actions for triggering an event raffle / assigning a spin
|
|
3
|
+
* prize from a Next.js API route. Builds an ad-hoc JobContext around
|
|
4
|
+
* `getAdminDb()` so the same pure runners used by the Firebase Functions
|
|
5
|
+
* handlers also work in a Vercel lambda (10s cap honoured by raffle pool
|
|
6
|
+
* size).
|
|
7
|
+
*/
|
|
8
|
+
import { type TriggerEventRaffleInput, type TriggerEventRaffleResult } from "../../jobs/core/triggerEventRaffle";
|
|
9
|
+
import { type AssignSpinPrizeInput, type AssignSpinPrizeResult } from "../../jobs/core/assignSpinPrize";
|
|
10
|
+
export declare function triggerEventRaffleAction(input: TriggerEventRaffleInput): Promise<TriggerEventRaffleResult>;
|
|
11
|
+
export declare function assignSpinPrizeAction(input: AssignSpinPrizeInput): Promise<AssignSpinPrizeResult>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SB9-H — server actions for triggering an event raffle / assigning a spin
|
|
3
|
+
* prize from a Next.js API route. Builds an ad-hoc JobContext around
|
|
4
|
+
* `getAdminDb()` so the same pure runners used by the Firebase Functions
|
|
5
|
+
* handlers also work in a Vercel lambda (10s cap honoured by raffle pool
|
|
6
|
+
* size).
|
|
7
|
+
*/
|
|
8
|
+
"use server";
|
|
9
|
+
import { getAdminDb } from "../../../../providers/db-firebase/admin";
|
|
10
|
+
import { runTriggerEventRaffle, } from "../../jobs/core/triggerEventRaffle";
|
|
11
|
+
import { runAssignSpinPrize, } from "../../jobs/core/assignSpinPrize";
|
|
12
|
+
function buildContext(job) {
|
|
13
|
+
const logger = {
|
|
14
|
+
info: (msg, meta) => console.info(`[${job}] ${msg}`, meta ?? {}),
|
|
15
|
+
warn: (msg, meta) => console.warn(`[${job}] ${msg}`, meta ?? {}),
|
|
16
|
+
error: (msg, err, meta) => console.error(`[${job}] ${msg}`, err, meta ?? {}),
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
job,
|
|
20
|
+
db: getAdminDb(),
|
|
21
|
+
logger,
|
|
22
|
+
env: (key) => process.env[key],
|
|
23
|
+
now: new Date(),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function triggerEventRaffleAction(input) {
|
|
27
|
+
return runTriggerEventRaffle(input, buildContext("admin.triggerEventRaffle"));
|
|
28
|
+
}
|
|
29
|
+
export async function assignSpinPrizeAction(input) {
|
|
30
|
+
return runAssignSpinPrize(input, buildContext("user.assignSpinPrize"));
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RefundType } from "../../../../features/orders/schemas";
|
|
2
|
+
export type ProcessRefundInput = {
|
|
3
|
+
orderId: string;
|
|
4
|
+
type: RefundType;
|
|
5
|
+
/** Amount in paise. Must be > 0 and ≤ remaining refundable amount on the order. */
|
|
6
|
+
amountInPaise: number;
|
|
7
|
+
reason: string;
|
|
8
|
+
/** Product/item ids affected (for partial refunds). */
|
|
9
|
+
itemIds?: string[];
|
|
10
|
+
/** Required: caller must explicitly confirm this action is irrevocable. */
|
|
11
|
+
confirmIrrevocable: true;
|
|
12
|
+
/** uid of the user processing the refund (admin / seller). */
|
|
13
|
+
refundedBy: string;
|
|
14
|
+
} & ({
|
|
15
|
+
method: "razorpay";
|
|
16
|
+
/** Razorpay paymentId from the order (order.paymentId). */
|
|
17
|
+
razorpayPaymentId: string;
|
|
18
|
+
manualTransactionId?: never;
|
|
19
|
+
proofDocumentUrl?: never;
|
|
20
|
+
proofDocumentMimeType?: never;
|
|
21
|
+
} | {
|
|
22
|
+
method: "manual";
|
|
23
|
+
razorpayPaymentId?: never;
|
|
24
|
+
manualTransactionId?: string;
|
|
25
|
+
proofDocumentUrl?: string;
|
|
26
|
+
proofDocumentMimeType?: string;
|
|
27
|
+
});
|
|
28
|
+
export declare function processRefundAction(input: ProcessRefundInput): Promise<{
|
|
29
|
+
success: true;
|
|
30
|
+
refundId: string;
|
|
31
|
+
}>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
/**
|
|
3
|
+
* processRefundAction — append a refund event to an order.
|
|
4
|
+
*
|
|
5
|
+
* Supports two paths:
|
|
6
|
+
* - Razorpay: calls the payment provider's `refund()` method, then records
|
|
7
|
+
* the razorpayRefundId on the event.
|
|
8
|
+
* - Manual: no payment-provider call; records manualTransactionId + optional
|
|
9
|
+
* proof document URL.
|
|
10
|
+
*
|
|
11
|
+
* Both paths require `confirmIrrevocable: true` from the caller to prevent
|
|
12
|
+
* accidental use — callers must acknowledge the action is non-reversible.
|
|
13
|
+
*
|
|
14
|
+
* Setting `contestable` to false is a side-effect of `orderRepository.postRefundEvent`.
|
|
15
|
+
*/
|
|
16
|
+
import { randomUUID } from "crypto";
|
|
17
|
+
import { getProviders } from "../../../../contracts/registry";
|
|
18
|
+
import { orderRepository } from "../../../..";
|
|
19
|
+
import { NotFoundError, ValidationError } from "../../../../errors";
|
|
20
|
+
import { applyRefundDeductionAction } from "../payouts/actions";
|
|
21
|
+
export async function processRefundAction(input) {
|
|
22
|
+
const order = await orderRepository.findById(input.orderId);
|
|
23
|
+
if (!order)
|
|
24
|
+
throw new NotFoundError(`Order ${input.orderId} not found`);
|
|
25
|
+
if (input.amountInPaise <= 0)
|
|
26
|
+
throw new ValidationError("Refund amount must be positive");
|
|
27
|
+
if (input.amountInPaise > order.totalPrice) {
|
|
28
|
+
throw new ValidationError("Refund amount exceeds order total");
|
|
29
|
+
}
|
|
30
|
+
// Guard: non-refundable orders (prize draws, bundles).
|
|
31
|
+
if (order.isNonRefundable) {
|
|
32
|
+
throw new ValidationError("This order is marked non-refundable and cannot be refunded.");
|
|
33
|
+
}
|
|
34
|
+
const refundId = randomUUID();
|
|
35
|
+
const now = new Date();
|
|
36
|
+
let razorpayRefundId;
|
|
37
|
+
if (input.method === "razorpay") {
|
|
38
|
+
const payment = getProviders().payment;
|
|
39
|
+
if (!payment)
|
|
40
|
+
throw new ValidationError("Payment provider not configured");
|
|
41
|
+
const result = await payment.refund(input.razorpayPaymentId, input.amountInPaise);
|
|
42
|
+
razorpayRefundId = result.id;
|
|
43
|
+
}
|
|
44
|
+
const isFull = input.amountInPaise >= order.totalPrice;
|
|
45
|
+
const event = {
|
|
46
|
+
refundId,
|
|
47
|
+
type: input.type,
|
|
48
|
+
amount: input.amountInPaise,
|
|
49
|
+
...(input.itemIds?.length ? { itemIds: input.itemIds } : {}),
|
|
50
|
+
reason: input.reason,
|
|
51
|
+
refundedAt: now,
|
|
52
|
+
refundedBy: input.refundedBy,
|
|
53
|
+
...(razorpayRefundId ? { razorpayRefundId } : {}),
|
|
54
|
+
...(input.method === "manual" && input.manualTransactionId
|
|
55
|
+
? { manualTransactionId: input.manualTransactionId }
|
|
56
|
+
: {}),
|
|
57
|
+
...(input.method === "manual" && input.proofDocumentUrl
|
|
58
|
+
? {
|
|
59
|
+
proofDocumentUrl: input.proofDocumentUrl,
|
|
60
|
+
proofDocumentMimeType: input.proofDocumentMimeType,
|
|
61
|
+
}
|
|
62
|
+
: {}),
|
|
63
|
+
};
|
|
64
|
+
await orderRepository.postRefundEvent(input.orderId, event, isFull);
|
|
65
|
+
// Fire-and-forget: deduct from the store's pending payout if one exists.
|
|
66
|
+
// Failure here must not roll back the already-posted refund event.
|
|
67
|
+
if (order.storeId) {
|
|
68
|
+
applyRefundDeductionAction({
|
|
69
|
+
storeId: order.storeId,
|
|
70
|
+
orderId: input.orderId,
|
|
71
|
+
refundId,
|
|
72
|
+
refundedAmountInPaise: input.amountInPaise,
|
|
73
|
+
reason: input.reason,
|
|
74
|
+
}).catch(() => { });
|
|
75
|
+
}
|
|
76
|
+
return { success: true, refundId };
|
|
77
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core: aggregate admin analytics. Returns 12-month order totals + monthly
|
|
3
|
+
* breakdown + top-5 products by revenue.
|
|
4
|
+
*/
|
|
5
|
+
import type { JobContext } from "../runtime/types";
|
|
6
|
+
export interface AdminAnalyticsResult {
|
|
7
|
+
summary: {
|
|
8
|
+
totalOrders: number;
|
|
9
|
+
totalRevenue: number;
|
|
10
|
+
newOrdersThisMonth: number;
|
|
11
|
+
revenueThisMonth: number;
|
|
12
|
+
totalProducts: number;
|
|
13
|
+
publishedProducts: number;
|
|
14
|
+
};
|
|
15
|
+
ordersByMonth: Array<{
|
|
16
|
+
month: string;
|
|
17
|
+
orders: number;
|
|
18
|
+
revenue: number;
|
|
19
|
+
}>;
|
|
20
|
+
topProducts: Array<{
|
|
21
|
+
productId: string;
|
|
22
|
+
title: string;
|
|
23
|
+
revenue: number;
|
|
24
|
+
orders: number;
|
|
25
|
+
mainImage: string;
|
|
26
|
+
}>;
|
|
27
|
+
}
|
|
28
|
+
export declare function runAdminAnalytics(_input: void, ctx: JobContext): Promise<AdminAnalyticsResult>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core: aggregate admin analytics. Returns 12-month order totals + monthly
|
|
3
|
+
* breakdown + top-5 products by revenue.
|
|
4
|
+
*/
|
|
5
|
+
import { orderRepository, productRepository } from "../../../../repositories";
|
|
6
|
+
import { formatMonthYear } from "../../../../utils/date.formatter";
|
|
7
|
+
import { ProductStatusValues } from "../../../../features/products/schemas/firestore";
|
|
8
|
+
function normalizeDate(raw) {
|
|
9
|
+
return raw instanceof Date ? raw : new Date(raw);
|
|
10
|
+
}
|
|
11
|
+
async function loadOrdersSince(isoStart, pageCap) {
|
|
12
|
+
const out = [];
|
|
13
|
+
let page = 1;
|
|
14
|
+
let hasMore = true;
|
|
15
|
+
while (hasMore && page <= pageCap) {
|
|
16
|
+
const result = await orderRepository.listAll({
|
|
17
|
+
filters: `createdAt>=${isoStart}`,
|
|
18
|
+
sorts: "-createdAt",
|
|
19
|
+
page: String(page),
|
|
20
|
+
pageSize: "500",
|
|
21
|
+
});
|
|
22
|
+
out.push(...result.items);
|
|
23
|
+
hasMore = result.hasMore;
|
|
24
|
+
page += 1;
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
export async function runAdminAnalytics(_input, ctx) {
|
|
29
|
+
ctx.logger.info("Admin analytics requested");
|
|
30
|
+
const now = new Date();
|
|
31
|
+
const twelveMonthsAgo = new Date(now.getFullYear() - 1, now.getMonth(), 1).toISOString();
|
|
32
|
+
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1).toISOString();
|
|
33
|
+
const [allTimeTotalsResult, past12, thisMonth, totalProductsResult, publishedProductsResult] = await Promise.all([
|
|
34
|
+
orderRepository.listAll({ page: "1", pageSize: "1" }),
|
|
35
|
+
loadOrdersSince(twelveMonthsAgo, 10),
|
|
36
|
+
loadOrdersSince(monthStart, 10),
|
|
37
|
+
productRepository.list({ page: "1", pageSize: "1" }),
|
|
38
|
+
productRepository.list({
|
|
39
|
+
filters: `status==${ProductStatusValues.PUBLISHED}`,
|
|
40
|
+
page: "1",
|
|
41
|
+
pageSize: "1",
|
|
42
|
+
}, { status: ProductStatusValues.PUBLISHED }),
|
|
43
|
+
]);
|
|
44
|
+
const totalRevenue = past12.reduce((sum, o) => sum + (o.totalPrice ?? 0), 0);
|
|
45
|
+
const newOrdersThisMonth = thisMonth.length;
|
|
46
|
+
const revenueThisMonth = thisMonth.reduce((sum, o) => sum + (o.totalPrice ?? 0), 0);
|
|
47
|
+
const monthMap = new Map();
|
|
48
|
+
for (let i = 11; i >= 0; i--) {
|
|
49
|
+
const d = new Date(now.getFullYear(), now.getMonth() - i, 1);
|
|
50
|
+
const key = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`;
|
|
51
|
+
monthMap.set(key, { month: formatMonthYear(d), orders: 0, revenue: 0 });
|
|
52
|
+
}
|
|
53
|
+
for (const order of past12) {
|
|
54
|
+
const d = normalizeDate(order.createdAt);
|
|
55
|
+
const key = `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`;
|
|
56
|
+
const entry = monthMap.get(key);
|
|
57
|
+
if (entry) {
|
|
58
|
+
entry.orders += 1;
|
|
59
|
+
entry.revenue += order.totalPrice ?? 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const revenueByProduct = new Map();
|
|
63
|
+
for (const order of past12) {
|
|
64
|
+
const existing = revenueByProduct.get(order.productId);
|
|
65
|
+
if (existing) {
|
|
66
|
+
existing.revenue += order.totalPrice ?? 0;
|
|
67
|
+
existing.orders += 1;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
revenueByProduct.set(order.productId, {
|
|
71
|
+
productId: order.productId,
|
|
72
|
+
title: order.productTitle,
|
|
73
|
+
revenue: order.totalPrice ?? 0,
|
|
74
|
+
orders: 1,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const topProducts = Array.from(revenueByProduct.values())
|
|
79
|
+
.sort((a, b) => b.revenue - a.revenue)
|
|
80
|
+
.slice(0, 5);
|
|
81
|
+
const topProductDocs = await Promise.all(topProducts.map((p) => productRepository.findById(p.productId)));
|
|
82
|
+
const topProductsWithImages = topProducts.map((p, i) => ({
|
|
83
|
+
...p,
|
|
84
|
+
mainImage: topProductDocs[i]?.mainImage ?? "",
|
|
85
|
+
}));
|
|
86
|
+
return {
|
|
87
|
+
summary: {
|
|
88
|
+
totalOrders: allTimeTotalsResult.total,
|
|
89
|
+
totalRevenue,
|
|
90
|
+
newOrdersThisMonth,
|
|
91
|
+
revenueThisMonth,
|
|
92
|
+
totalProducts: totalProductsResult.total,
|
|
93
|
+
publishedProducts: publishedProductsResult.total,
|
|
94
|
+
},
|
|
95
|
+
ordersByMonth: Array.from(monthMap.values()),
|
|
96
|
+
topProducts: topProductsWithImages,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core: weighted random selection from an event's `spinPrizes` config using
|
|
3
|
+
* `crypto.randomInt`. Enforces one spin per user.
|
|
4
|
+
*/
|
|
5
|
+
import type { JobContext } from "../runtime/types";
|
|
6
|
+
export interface AssignSpinPrizeInput {
|
|
7
|
+
eventId: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AssignSpinPrizeResult {
|
|
11
|
+
eventId: string;
|
|
12
|
+
userId: string;
|
|
13
|
+
spinPrizeId?: string;
|
|
14
|
+
spinPrizeTitle?: string;
|
|
15
|
+
spinPrizeCouponCode?: string;
|
|
16
|
+
alreadyUsed?: boolean;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function runAssignSpinPrize(input: AssignSpinPrizeInput, ctx: JobContext): Promise<AssignSpinPrizeResult>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core: weighted random selection from an event's `spinPrizes` config using
|
|
3
|
+
* `crypto.randomInt`. Enforces one spin per user.
|
|
4
|
+
*/
|
|
5
|
+
import crypto from "node:crypto";
|
|
6
|
+
const EVENTS_COLLECTION = "events";
|
|
7
|
+
const EVENT_ENTRIES_COLLECTION = "eventEntries";
|
|
8
|
+
const COUPONS_COLLECTION = "coupons";
|
|
9
|
+
export async function runAssignSpinPrize(input, ctx) {
|
|
10
|
+
const { eventId, userId } = input;
|
|
11
|
+
const eventSnap = await ctx.db.collection(EVENTS_COLLECTION).doc(eventId).get();
|
|
12
|
+
if (!eventSnap.exists) {
|
|
13
|
+
return { eventId, userId, reason: "event_not_found" };
|
|
14
|
+
}
|
|
15
|
+
const event = eventSnap.data();
|
|
16
|
+
const prizes = Array.isArray(event.spinPrizes) ? event.spinPrizes : [];
|
|
17
|
+
const totalWeight = prizes.reduce((s, p) => s + (p.weight ?? 0), 0);
|
|
18
|
+
if (totalWeight <= 0) {
|
|
19
|
+
return { eventId, userId, reason: "no_prizes_configured" };
|
|
20
|
+
}
|
|
21
|
+
const entriesSnap = await ctx.db
|
|
22
|
+
.collection(EVENT_ENTRIES_COLLECTION)
|
|
23
|
+
.where("eventId", "==", eventId)
|
|
24
|
+
.where("userId", "==", userId)
|
|
25
|
+
.limit(1)
|
|
26
|
+
.get();
|
|
27
|
+
if (entriesSnap.empty) {
|
|
28
|
+
return { eventId, userId, reason: "entry_not_found" };
|
|
29
|
+
}
|
|
30
|
+
const entryDoc = entriesSnap.docs[0];
|
|
31
|
+
const entry = entryDoc.data();
|
|
32
|
+
if (entry.spinUsed) {
|
|
33
|
+
return {
|
|
34
|
+
eventId,
|
|
35
|
+
userId,
|
|
36
|
+
spinPrizeId: entry.spinPrizeId,
|
|
37
|
+
alreadyUsed: true,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const roll = crypto.randomInt(0, totalWeight);
|
|
41
|
+
let cumulative = 0;
|
|
42
|
+
let pick;
|
|
43
|
+
for (const p of prizes) {
|
|
44
|
+
cumulative += p.weight ?? 0;
|
|
45
|
+
if (roll < cumulative) {
|
|
46
|
+
pick = p;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!pick)
|
|
51
|
+
pick = prizes[prizes.length - 1];
|
|
52
|
+
let spinPrizeCouponCode;
|
|
53
|
+
if (pick.couponId) {
|
|
54
|
+
const coupSnap = await ctx.db
|
|
55
|
+
.collection(COUPONS_COLLECTION)
|
|
56
|
+
.doc(pick.couponId)
|
|
57
|
+
.get();
|
|
58
|
+
if (coupSnap.exists) {
|
|
59
|
+
spinPrizeCouponCode = coupSnap.data().code;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await entryDoc.ref.update({
|
|
63
|
+
spinUsed: true,
|
|
64
|
+
spinPrizeId: pick.id,
|
|
65
|
+
spinWonAt: ctx.now,
|
|
66
|
+
spinPrizeCouponCode: spinPrizeCouponCode ?? null,
|
|
67
|
+
updatedAt: ctx.now,
|
|
68
|
+
});
|
|
69
|
+
ctx.logger.info("Spin prize assigned", {
|
|
70
|
+
eventId,
|
|
71
|
+
userId,
|
|
72
|
+
spinPrizeId: pick.id,
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
eventId,
|
|
76
|
+
userId,
|
|
77
|
+
spinPrizeId: pick.id,
|
|
78
|
+
spinPrizeTitle: pick.title,
|
|
79
|
+
spinPrizeCouponCode,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { bidRepository, notificationRepository, orderRepository, productRepository, } from "../../../../repositories";
|
|
2
|
+
import { ProductStatusValues } from "../../../../features/products/schemas/firestore";
|
|
3
|
+
import { AUCTION_MESSAGES } from "../handlers/messages";
|
|
4
|
+
async function settleAuction(ctx, product) {
|
|
5
|
+
const activeBids = await bidRepository.getActiveByProduct(product.id);
|
|
6
|
+
const batch = ctx.db.batch();
|
|
7
|
+
if (activeBids.length === 0) {
|
|
8
|
+
productRepository.updateStatusInBatch(batch, product.id, ProductStatusValues.OUT_OF_STOCK);
|
|
9
|
+
await batch.commit();
|
|
10
|
+
ctx.logger.info(AUCTION_MESSAGES.NO_BIDS_LOG(product.id));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const [winnerEntry, ...loserEntries] = activeBids;
|
|
14
|
+
bidRepository.markWon(batch, winnerEntry.ref);
|
|
15
|
+
loserEntries.forEach(({ ref }) => bidRepository.markLost(batch, ref));
|
|
16
|
+
const orderRef = orderRepository.createFromAuction(batch, {
|
|
17
|
+
productId: product.id,
|
|
18
|
+
productTitle: product.title,
|
|
19
|
+
userId: winnerEntry.data.userId,
|
|
20
|
+
userName: winnerEntry.data.userName,
|
|
21
|
+
userEmail: winnerEntry.data.userEmail,
|
|
22
|
+
storeId: product.storeId,
|
|
23
|
+
amount: winnerEntry.data.bidAmount,
|
|
24
|
+
currency: winnerEntry.data.currency,
|
|
25
|
+
auctionProductId: product.id,
|
|
26
|
+
});
|
|
27
|
+
productRepository.updateStatusInBatch(batch, product.id, ProductStatusValues.SOLD);
|
|
28
|
+
notificationRepository.createInBatch(batch, {
|
|
29
|
+
userId: winnerEntry.data.userId,
|
|
30
|
+
type: "bid_won",
|
|
31
|
+
priority: "high",
|
|
32
|
+
title: AUCTION_MESSAGES.WON_TITLE,
|
|
33
|
+
message: AUCTION_MESSAGES.WON_MESSAGE(product.title, winnerEntry.data.currency, winnerEntry.data.bidAmount),
|
|
34
|
+
relatedId: product.id,
|
|
35
|
+
relatedType: "product",
|
|
36
|
+
});
|
|
37
|
+
loserEntries.slice(0, 50).forEach(({ data: bid }) => {
|
|
38
|
+
notificationRepository.createInBatch(batch, {
|
|
39
|
+
userId: bid.userId,
|
|
40
|
+
type: "bid_lost",
|
|
41
|
+
priority: "normal",
|
|
42
|
+
title: AUCTION_MESSAGES.LOST_TITLE,
|
|
43
|
+
message: AUCTION_MESSAGES.LOST_MESSAGE(product.title),
|
|
44
|
+
relatedId: product.id,
|
|
45
|
+
relatedType: "product",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
await batch.commit();
|
|
49
|
+
ctx.logger.info(`Settled auction ${product.id}`, {
|
|
50
|
+
winner: winnerEntry.data.userId,
|
|
51
|
+
winningBid: winnerEntry.data.bidAmount,
|
|
52
|
+
losersCount: loserEntries.length,
|
|
53
|
+
orderId: orderRef.id,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export async function runAuctionSettlement(ctx) {
|
|
57
|
+
ctx.logger.info("Starting auction settlement sweep");
|
|
58
|
+
const expired = await productRepository.getExpiredAuctions(ctx.now);
|
|
59
|
+
if (expired.length === 0) {
|
|
60
|
+
ctx.logger.info("No expired auctions found");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
ctx.logger.info(`Found ${expired.length} expired auction(s) to settle`);
|
|
64
|
+
const results = await Promise.allSettled(expired.map(({ data }) => settleAuction(ctx, data)));
|
|
65
|
+
const failed = results.filter((r) => r.status === "rejected");
|
|
66
|
+
if (failed.length > 0) {
|
|
67
|
+
ctx.logger.error(`${failed.length} auction(s) failed to settle`, failed);
|
|
68
|
+
}
|
|
69
|
+
ctx.logger.info(`Settlement complete — ${expired.length - failed.length} succeeded, ${failed.length} failed`);
|
|
70
|
+
}
|