@managesome/eposmatic-toolkit 0.2.705 → 0.2.707

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.
@@ -989,10 +989,26 @@ function getAutoApplyOfferCandidates({ offersWithStats, suppressedOfferIds, }) {
989
989
  if (!stats.claimable || stats.invalid_offer || !shouldAutoApplyOffer) {
990
990
  continue;
991
991
  }
992
+ // ITEMS / DISCOUNT_ITEMS rewards are claimed manually through the reward
993
+ // drawers and their claimability tracks selected cart items rather than
994
+ // redeemed_offers. No app implements auto-apply for them, and applying via
995
+ // a redeemed_offers patch would leave them permanently claimable, causing
996
+ // the auto-apply effect to loop.
997
+ if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS ||
998
+ offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
999
+ continue;
1000
+ }
992
1001
  if (suppressedOfferIds?.[normalizedOfferId]) {
993
1002
  continue;
994
1003
  }
995
- const claimsIncrement = offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.POINTS
1004
+ // For repeatable POINTS and flat CASHBACK, claimsIncrement covers ALL
1005
+ // remaining claims in a single patch so the next stats snapshot flips
1006
+ // claimable to false. Callers MUST forward claimsIncrement into
1007
+ // buildRedeemedOffersClaimPatch; otherwise redeemed_times advances by 1
1008
+ // per cycle and the auto-apply effect loops until React throws
1009
+ // "Maximum update depth exceeded".
1010
+ const claimsIncrement = offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.POINTS ||
1011
+ (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK && offer.reward_cashback?.is_cashback_percentage !== true)
996
1012
  ? getOfferClaimIncrementFromStats({
997
1013
  stats,
998
1014
  })
@@ -1744,15 +1760,6 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1744
1760
  return true;
1745
1761
  return getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, offerToCheck._id) >= maxUsesPerCustomer;
1746
1762
  };
1747
- const getRemainingOfferUsesForCustomer = (offerToCheck) => {
1748
- const maxUsesPerCustomer = getOfferMaxUsesPerCustomer(offerToCheck);
1749
- if (maxUsesPerCustomer == null)
1750
- return Infinity;
1751
- if (customerOfferRedemptionCounts == null)
1752
- return 0;
1753
- const redeemedByCustomer = getCustomerUsedRedemptionCount(customerOfferRedemptionCounts, offerToCheck._id);
1754
- return Math.max(0, maxUsesPerCustomer - redeemedByCustomer);
1755
- };
1756
1763
  const getOrderValueClaimTimes = (orderValue, minAmount) => {
1757
1764
  const safeRequiredAmount = Math.max(1, minAmount || 1);
1758
1765
  return Math.max(1, Math.floor(orderValue / safeRequiredAmount));
@@ -1788,14 +1795,20 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1788
1795
  if (normalizedUnlockableClaims === 0) {
1789
1796
  return 0;
1790
1797
  }
1791
- return Math.min(normalizedUnlockableClaims, getRemainingOfferUsesForCustomer(offerToCheck));
1798
+ // max_uses_per_customer is a lifetime gate checked separately against
1799
+ // the customer's settled-claim history (wallet USED counter,
1800
+ // isOfferUsesPerCustomerExhausted); it must not shrink the per-order
1801
+ // claim count — max_claims governs the ongoing session only.
1802
+ return normalizedUnlockableClaims;
1792
1803
  };
1793
- const getPathwayMaxRedeemableClaims = ({ offerToCheck, pathwayUnlockableClaims, }) => {
1804
+ const getPathwayMaxRedeemableClaims = (pathwayUnlockableClaims) => {
1794
1805
  const normalizedUnlockableClaims = Math.max(0, pathwayUnlockableClaims);
1795
1806
  if (normalizedUnlockableClaims === 0) {
1796
1807
  return 0;
1797
1808
  }
1798
- return Math.min(normalizedUnlockableClaims, getRemainingOfferUsesForCustomer(offerToCheck));
1809
+ // Same lifetime-vs-session separation as getPointsMaxRedeemableClaims:
1810
+ // max_uses_per_customer only gates on settled-claim history.
1811
+ return normalizedUnlockableClaims;
1799
1812
  };
1800
1813
  const isDiscountSlotOccupiedForOffer = (offerToCheck) => {
1801
1814
  if (order_discount_details == null) {
@@ -1986,11 +1999,15 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1986
1999
  totalOfferItemsSelected,
1987
2000
  applicableQuantity,
1988
2001
  });
1989
- const maxRedeemableClaims = 1;
2002
+ const maxClaimsPerOrder = offer.pathway_to_unlock_type_orders?.max_claims == null
2003
+ ? Infinity
2004
+ : Math.max(1, offer.pathway_to_unlock_type_orders.max_claims);
2005
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, offer.pathway_to_unlock_type_orders?.total_amount);
2006
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder);
1990
2007
  const discountSlotOccupied = isDiscountSlotOccupiedForOffer(offer);
1991
- const isClaimable = redeemedTimes < maxRedeemableClaims && !discountSlotOccupied;
2008
+ const isClaimable = redeemedTimes < totalUnlockableClaims && !discountSlotOccupied;
1992
2009
  stats.redeemed_times = redeemedTimes;
1993
- stats.applicable_quantity = applicableQuantity * maxRedeemableClaims;
2010
+ stats.applicable_quantity = applicableQuantity * Math.max(1, totalUnlockableClaims);
1994
2011
  if (isClaimable) {
1995
2012
  totalClaimableOffers.push(offer._id);
1996
2013
  stats.claimable = true;
@@ -1999,7 +2016,7 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
1999
2016
  else {
2000
2017
  stats.claimable = false;
2001
2018
  stats.message =
2002
- redeemedTimes > 0
2019
+ redeemedTimes >= totalUnlockableClaims
2003
2020
  ? `This offer is redeemed ✅`
2004
2021
  : discountSlotOccupied
2005
2022
  ? 'You already have an offer applied to your order.'
@@ -2072,25 +2089,41 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2072
2089
  continue;
2073
2090
  }
2074
2091
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
2075
- const maxClaimsPerOrder = offer.pathway_to_unlock_type_orders?.max_claims == null
2076
- ? Infinity
2077
- : Math.max(1, offer.pathway_to_unlock_type_orders.max_claims);
2078
- const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, offer.pathway_to_unlock_type_orders?.total_amount);
2079
- const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder);
2080
- const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
2081
- offerToCheck: offer,
2082
- pathwayUnlockableClaims: totalUnlockableClaims,
2083
- });
2084
- const isClaimable = redeemedTimes < maxRedeemableClaims;
2085
- stats.redeemed_times = redeemedTimes;
2086
- stats.applicable_quantity = maxRedeemableClaims;
2087
- stats.claimable = isClaimable;
2088
- if (!isClaimable) {
2089
- stats.message = 'This offer is redeemed ✅';
2092
+ if (offer.reward_cashback.is_cashback_percentage === true) {
2093
+ // Percentage cashback scales with the order total and is claimed
2094
+ // once per order; total_amount / max_claims do not apply.
2095
+ const isRedeemed = redeemedTimes > 0;
2096
+ stats.redeemed_times = redeemedTimes;
2097
+ stats.applicable_quantity = 1;
2098
+ stats.claimable = !isRedeemed;
2099
+ if (isRedeemed) {
2100
+ stats.message = 'This offer is redeemed ✅';
2101
+ }
2102
+ else {
2103
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2104
+ totalClaimableOffers.push(offer._id);
2105
+ }
2090
2106
  }
2091
2107
  else {
2092
- stats.message = `🎉 You have unlocked this offer 🎉`;
2093
- totalClaimableOffers.push(offer._id);
2108
+ // Flat cashback repeats per qualifying spend chunk
2109
+ // (every total_amount unlocks one claim), capped by max_claims.
2110
+ const maxClaimsPerOrder = offer.pathway_to_unlock_type_orders?.max_claims == null
2111
+ ? Infinity
2112
+ : Math.max(1, offer.pathway_to_unlock_type_orders.max_claims);
2113
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, offer.pathway_to_unlock_type_orders?.total_amount);
2114
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder);
2115
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims(totalUnlockableClaims);
2116
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
2117
+ stats.redeemed_times = redeemedTimes;
2118
+ stats.applicable_quantity = maxRedeemableClaims;
2119
+ stats.claimable = isClaimable;
2120
+ if (!isClaimable) {
2121
+ stats.message = 'This offer is redeemed ✅';
2122
+ }
2123
+ else {
2124
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2125
+ totalClaimableOffers.push(offer._id);
2126
+ }
2094
2127
  }
2095
2128
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
2096
2129
  }
@@ -2130,9 +2163,14 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2130
2163
  totalOfferItemsSelected,
2131
2164
  applicableQuantity,
2132
2165
  });
2133
- const isClaimable = redeemedTimes < 1;
2166
+ const maxClaimsPerOrder = offer.pathway_to_unlock_type_orders?.max_claims == null
2167
+ ? Infinity
2168
+ : Math.max(1, offer.pathway_to_unlock_type_orders.max_claims);
2169
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, offer.pathway_to_unlock_type_orders?.total_amount);
2170
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder);
2171
+ const isClaimable = redeemedTimes < totalUnlockableClaims;
2134
2172
  stats.redeemed_times = redeemedTimes;
2135
- stats.applicable_quantity = applicableQuantity;
2173
+ stats.applicable_quantity = applicableQuantity * Math.max(1, totalUnlockableClaims);
2136
2174
  if (isClaimable) {
2137
2175
  totalClaimableOffers.push(offer._id);
2138
2176
  stats.claimable = true;
@@ -2339,20 +2377,36 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2339
2377
  continue;
2340
2378
  }
2341
2379
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
2342
- const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
2343
- offerToCheck: offer,
2344
- pathwayUnlockableClaims: totalUnlockableClaims,
2345
- });
2346
- const isClaimable = redeemedTimes < maxRedeemableClaims;
2347
- stats.redeemed_times = redeemedTimes;
2348
- stats.applicable_quantity = maxRedeemableClaims;
2349
- stats.claimable = isClaimable;
2350
- if (!isClaimable) {
2351
- stats.message = 'This offer is redeemed ✅';
2380
+ if (offer.reward_cashback.is_cashback_percentage === true) {
2381
+ // Percentage cashback scales with the order total and is claimed
2382
+ // once per order; total_amount / max_claims do not apply.
2383
+ const isRedeemed = redeemedTimes > 0;
2384
+ stats.redeemed_times = redeemedTimes;
2385
+ stats.applicable_quantity = 1;
2386
+ stats.claimable = !isRedeemed;
2387
+ if (isRedeemed) {
2388
+ stats.message = 'This offer is redeemed ✅';
2389
+ }
2390
+ else {
2391
+ totalClaimableOffers.push(offer._id);
2392
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2393
+ }
2352
2394
  }
2353
2395
  else {
2354
- totalClaimableOffers.push(offer._id);
2355
- stats.message = `🎉 You have unlocked this offer 🎉`;
2396
+ // Flat cashback repeats per qualifying spend chunk
2397
+ // (every total_amount unlocks one claim), capped by max_claims.
2398
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims(totalUnlockableClaims);
2399
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
2400
+ stats.redeemed_times = redeemedTimes;
2401
+ stats.applicable_quantity = maxRedeemableClaims;
2402
+ stats.claimable = isClaimable;
2403
+ if (!isClaimable) {
2404
+ stats.message = 'This offer is redeemed ✅';
2405
+ }
2406
+ else {
2407
+ totalClaimableOffers.push(offer._id);
2408
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2409
+ }
2356
2410
  }
2357
2411
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
2358
2412
  }
@@ -2596,20 +2650,36 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2596
2650
  continue;
2597
2651
  }
2598
2652
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
2599
- const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
2600
- offerToCheck: offer,
2601
- pathwayUnlockableClaims: totalUnlockableClaims,
2602
- });
2603
- const isClaimable = redeemedTimes < maxRedeemableClaims;
2604
- stats.redeemed_times = redeemedTimes;
2605
- stats.applicable_quantity = maxRedeemableClaims;
2606
- stats.claimable = isClaimable;
2607
- if (!isClaimable) {
2608
- stats.message = 'This offer is redeemed ✅';
2653
+ if (offer.reward_cashback.is_cashback_percentage === true) {
2654
+ // Percentage cashback scales with the order total and is claimed
2655
+ // once per order; total_amount / max_claims do not apply.
2656
+ const isRedeemed = redeemedTimes > 0;
2657
+ stats.redeemed_times = redeemedTimes;
2658
+ stats.applicable_quantity = 1;
2659
+ stats.claimable = !isRedeemed;
2660
+ if (isRedeemed) {
2661
+ stats.message = 'This offer is redeemed ✅';
2662
+ }
2663
+ else {
2664
+ totalClaimableOffers.push(offer._id);
2665
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2666
+ }
2609
2667
  }
2610
2668
  else {
2611
- totalClaimableOffers.push(offer._id);
2612
- stats.message = `🎉 You have unlocked this offer 🎉`;
2669
+ // Flat cashback repeats per qualifying spend chunk
2670
+ // (every total_amount unlocks one claim), capped by max_claims.
2671
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims(totalUnlockableClaims);
2672
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
2673
+ stats.redeemed_times = redeemedTimes;
2674
+ stats.applicable_quantity = maxRedeemableClaims;
2675
+ stats.claimable = isClaimable;
2676
+ if (!isClaimable) {
2677
+ stats.message = 'This offer is redeemed ✅';
2678
+ }
2679
+ else {
2680
+ totalClaimableOffers.push(offer._id);
2681
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2682
+ }
2613
2683
  }
2614
2684
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
2615
2685
  }
@@ -2814,10 +2884,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2814
2884
  totalOfferItemsSelected,
2815
2885
  applicableQuantity,
2816
2886
  });
2817
- const maxRedeemableClaims = 1;
2818
- const isClaimable = redeemedTimes < maxRedeemableClaims;
2887
+ const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
2888
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
2889
+ const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
2890
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
2891
+ const isClaimable = redeemedTimes < totalUnlockableClaims;
2819
2892
  stats.redeemed_times = redeemedTimes;
2820
- stats.applicable_quantity = applicableQuantity * maxRedeemableClaims;
2893
+ stats.applicable_quantity = applicableQuantity * Math.max(1, totalUnlockableClaims);
2821
2894
  stats.claimable = isClaimable;
2822
2895
  if (isClaimable) {
2823
2896
  totalClaimableOffers.push(offer._id);
@@ -2889,24 +2962,41 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2889
2962
  continue;
2890
2963
  }
2891
2964
  const redeemedTimes = getOfferRedeemedTimes(offer._id);
2892
- const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
2893
- const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
2894
- const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
2895
- const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
2896
- const maxRedeemableClaims = getPathwayMaxRedeemableClaims({
2897
- offerToCheck: offer,
2898
- pathwayUnlockableClaims: totalUnlockableClaims,
2899
- });
2900
- const isClaimable = redeemedTimes < maxRedeemableClaims;
2901
- stats.redeemed_times = redeemedTimes;
2902
- stats.applicable_quantity = maxRedeemableClaims;
2903
- stats.claimable = isClaimable;
2904
- if (!isClaimable) {
2905
- stats.message = 'This offer is redeemed ✅';
2965
+ if (offer.reward_cashback.is_cashback_percentage === true) {
2966
+ // Percentage cashback scales with the order total and is claimed
2967
+ // once per order; total_amount / max_claims do not apply.
2968
+ const isRedeemed = redeemedTimes > 0;
2969
+ stats.redeemed_times = redeemedTimes;
2970
+ stats.applicable_quantity = 1;
2971
+ stats.claimable = !isRedeemed;
2972
+ if (isRedeemed) {
2973
+ stats.message = 'This offer is redeemed ✅';
2974
+ }
2975
+ else {
2976
+ totalClaimableOffers.push(offer._id);
2977
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2978
+ }
2906
2979
  }
2907
2980
  else {
2908
- totalClaimableOffers.push(offer._id);
2909
- stats.message = `🎉 You have unlocked this offer 🎉`;
2981
+ // Flat cashback repeats per qualifying spend chunk
2982
+ // (every total_amount unlocks one claim), capped by max_claims
2983
+ // and the voucher inventory available for this order.
2984
+ const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
2985
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
2986
+ const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
2987
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
2988
+ const maxRedeemableClaims = getPathwayMaxRedeemableClaims(totalUnlockableClaims);
2989
+ const isClaimable = redeemedTimes < maxRedeemableClaims;
2990
+ stats.redeemed_times = redeemedTimes;
2991
+ stats.applicable_quantity = maxRedeemableClaims;
2992
+ stats.claimable = isClaimable;
2993
+ if (!isClaimable) {
2994
+ stats.message = 'This offer is redeemed ✅';
2995
+ }
2996
+ else {
2997
+ totalClaimableOffers.push(offer._id);
2998
+ stats.message = `🎉 You have unlocked this offer 🎉`;
2999
+ }
2910
3000
  }
2911
3001
  unlockedOffersApplicableTimes[offer._id] = stats.applicable_quantity;
2912
3002
  }
@@ -2943,9 +3033,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2943
3033
  totalOfferItemsSelected,
2944
3034
  applicableQuantity,
2945
3035
  });
2946
- const isClaimable = redeemedTimes < 1;
3036
+ const maxClaimsPerOrder = max_claims == null ? Infinity : Math.max(1, max_claims);
3037
+ const unlockTimesForAmount = getOrderValueClaimTimes(orderValue, total_amount);
3038
+ const voucherInventoryClaimCap = matchingVoucherContext != null ? Math.max(0, spendableVoucherCount + redeemedTimesForOffer) : Infinity;
3039
+ const totalUnlockableClaims = Math.min(unlockTimesForAmount, maxClaimsPerOrder, voucherInventoryClaimCap);
3040
+ const isClaimable = redeemedTimes < totalUnlockableClaims;
2947
3041
  stats.redeemed_times = redeemedTimes;
2948
- stats.applicable_quantity = applicableQuantity;
3042
+ stats.applicable_quantity = applicableQuantity * Math.max(1, totalUnlockableClaims);
2949
3043
  stats.claimable = isClaimable;
2950
3044
  if (isClaimable) {
2951
3045
  totalClaimableOffers.push(offer._id);
@@ -1,4 +1,24 @@
1
1
  import { IHalfHalfSetup } from '../../schemas';
2
- import { ISimplifiedHalfHalfSetup } from '../types';
2
+ import { ISimplifiedCatalogItem, ISimplifiedHalfHalfSetup } from '../types';
3
3
  export declare function convertHalfHalfSetupToSimplifiedHalfHalfSetup(halfhalfSetup: IHalfHalfSetup, tenantId: string): ISimplifiedHalfHalfSetup;
4
4
  export declare function convertHalfHalfSetupsToSimplifiedHalfHalfSetups(halfhalfSetups: IHalfHalfSetup[], tenantId: string): ISimplifiedHalfHalfSetup[];
5
+ /**
6
+ * Converts an ISimplifiedHalfHalfSetup into an ISimplifiedCatalogItem so it
7
+ * can flow through the standard catalog → drawer → cart pipeline just like a
8
+ * regular simplified catalog item (the simplified counterpart of
9
+ * `convertHalfHalfToItem`).
10
+ *
11
+ * The simplified half-half payload carries only menu-list data — no segments,
12
+ * no constituent items, no upsell and no ref rules — so this is a pure field
13
+ * mapping of what ISimplifiedCatalogItem can represent:
14
+ * - item `price`/`tax_rate` are null (there is no base price on the payload;
15
+ * the per-segment prices come from the constituent items at selection time),
16
+ * - `discount_amount` and `item_special_hours` are converted back from the
17
+ * minified (cents) wire form to the original (dollar) representation used by
18
+ * ISimplifiedCatalogItem (same conversion as `getSimplifiedItemWithPrice`),
19
+ * - no `modifiers` are produced (selection structure isn't part of the
20
+ * simplified setup),
21
+ * - `sort_id` is not part of the payload, so it defaults to 0 (same as
22
+ * `convertHalfHalfToItem`).
23
+ */
24
+ export declare function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup: ISimplifiedHalfHalfSetup): ISimplifiedCatalogItem;
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertHalfHalfSetupToSimplifiedHalfHalfSetup = convertHalfHalfSetupToSimplifiedHalfHalfSetup;
4
4
  exports.convertHalfHalfSetupsToSimplifiedHalfHalfSetups = convertHalfHalfSetupsToSimplifiedHalfHalfSetups;
5
+ exports.convertSimplifiedHalfHalfToSimplifiedItem = convertSimplifiedHalfHalfToSimplifiedItem;
5
6
  const minified_catalog_1 = require("./minified-catalog");
7
+ const platform_num_1 = require("./platform-num");
6
8
  function convertHalfHalfSetupToSimplifiedHalfHalfSetup(halfhalfSetup, tenantId) {
7
9
  return {
8
10
  sold_out: halfhalfSetup.sold_out.includes(tenantId) || undefined,
@@ -28,3 +30,51 @@ function convertHalfHalfSetupsToSimplifiedHalfHalfSetups(halfhalfSetups, tenantI
28
30
  }
29
31
  return newHalfHalfSetups;
30
32
  }
33
+ /**
34
+ * Converts an ISimplifiedHalfHalfSetup into an ISimplifiedCatalogItem so it
35
+ * can flow through the standard catalog → drawer → cart pipeline just like a
36
+ * regular simplified catalog item (the simplified counterpart of
37
+ * `convertHalfHalfToItem`).
38
+ *
39
+ * The simplified half-half payload carries only menu-list data — no segments,
40
+ * no constituent items, no upsell and no ref rules — so this is a pure field
41
+ * mapping of what ISimplifiedCatalogItem can represent:
42
+ * - item `price`/`tax_rate` are null (there is no base price on the payload;
43
+ * the per-segment prices come from the constituent items at selection time),
44
+ * - `discount_amount` and `item_special_hours` are converted back from the
45
+ * minified (cents) wire form to the original (dollar) representation used by
46
+ * ISimplifiedCatalogItem (same conversion as `getSimplifiedItemWithPrice`),
47
+ * - no `modifiers` are produced (selection structure isn't part of the
48
+ * simplified setup),
49
+ * - `sort_id` is not part of the payload, so it defaults to 0 (same as
50
+ * `convertHalfHalfToItem`).
51
+ */
52
+ function convertSimplifiedHalfHalfToSimplifiedItem(halfhalfSetup) {
53
+ // Minified (cents) wire values → original dollar representation.
54
+ const discount_amount = (0, platform_num_1.convertPriceObjFromCents)((0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(halfhalfSetup.discount_amount));
55
+ const item_special_hours = (0, platform_num_1.convertSpecialHoursFromCents)((0, minified_catalog_1.convertMinifiedSpecialHoursToOriginalSpecialHours)(halfhalfSetup.item_special_hours));
56
+ return {
57
+ sold_out: halfhalfSetup.sold_out,
58
+ is_discount_percentage: halfhalfSetup.is_discount_percentage,
59
+ discount_amount,
60
+ item_special_hours,
61
+ // No base price / tax on the simplified payload; per-segment prices are
62
+ // resolved from the constituent items at selection time.
63
+ price: null,
64
+ tax_rate: null,
65
+ modifiers: null,
66
+ // sort_id is not part of the simplified payload (mirrors convertHalfHalfToItem).
67
+ sort_id: 0,
68
+ hide_name: false,
69
+ is_featured: false,
70
+ featured_sort_id: 0,
71
+ show_starting_from: false,
72
+ _id: halfhalfSetup._id,
73
+ category_id: halfhalfSetup.category_id,
74
+ name: halfhalfSetup.name,
75
+ included_platforms: halfhalfSetup.included_platforms,
76
+ description: halfhalfSetup.description,
77
+ active: halfhalfSetup.active,
78
+ image_url: halfhalfSetup.image_url,
79
+ };
80
+ }
@@ -1,4 +1,23 @@
1
1
  import { ISpecial } from '../../schemas';
2
- import { ISimplifiedSpecial } from '../types';
2
+ import { ISimplifiedCatalogItem, ISimplifiedSpecial } from '../types';
3
3
  export declare function convertSpecialToSimplifiedSpecial(special: ISpecial, tenantId: string): ISimplifiedSpecial;
4
4
  export declare function convertSpecialsToSimplifiedSpecials(specials: ISpecial[], tenantId: string): ISimplifiedSpecial[];
5
+ /**
6
+ * Converts an ISimplifiedSpecial into an ISimplifiedCatalogItem so it can
7
+ * flow through the standard catalog → drawer → cart pipeline just like a
8
+ * regular simplified catalog item (the simplified counterpart of
9
+ * `convertSpecialToItem`).
10
+ *
11
+ * The simplified special payload carries only menu-list data — the
12
+ * modifier_specials selection structure is dropped — so this is a pure field
13
+ * mapping of what ISimplifiedCatalogItem can represent:
14
+ * - `price` / `discount_amount` / `item_special_hours` / `display_price` are
15
+ * converted back from the minified (cents) wire form to the original
16
+ * (dollar) representation used by ISimplifiedCatalogItem (same conversion
17
+ * as `getSimplifiedItemWithPrice`),
18
+ * - `tax_rate` is null (not part of the special payload, mirrors
19
+ * `convertSpecialToItem`),
20
+ * - no `modifiers` are produced (selection structure isn't part of the
21
+ * simplified setup).
22
+ */
23
+ export declare function convertSimplifiedSpecialToSimplifiedItem(special: ISimplifiedSpecial): ISimplifiedCatalogItem;
@@ -2,7 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.convertSpecialToSimplifiedSpecial = convertSpecialToSimplifiedSpecial;
4
4
  exports.convertSpecialsToSimplifiedSpecials = convertSpecialsToSimplifiedSpecials;
5
+ exports.convertSimplifiedSpecialToSimplifiedItem = convertSimplifiedSpecialToSimplifiedItem;
5
6
  const minified_catalog_1 = require("./minified-catalog");
7
+ const platform_num_1 = require("./platform-num");
8
+ const price_conversion_1 = require("./price-conversion");
6
9
  function convertSpecialToSimplifiedSpecial(special, tenantId) {
7
10
  return {
8
11
  sold_out: special.sold_out.includes(tenantId) || undefined,
@@ -30,3 +33,52 @@ function convertSpecialsToSimplifiedSpecials(specials, tenantId) {
30
33
  }
31
34
  return newSpecials;
32
35
  }
36
+ /**
37
+ * Converts an ISimplifiedSpecial into an ISimplifiedCatalogItem so it can
38
+ * flow through the standard catalog → drawer → cart pipeline just like a
39
+ * regular simplified catalog item (the simplified counterpart of
40
+ * `convertSpecialToItem`).
41
+ *
42
+ * The simplified special payload carries only menu-list data — the
43
+ * modifier_specials selection structure is dropped — so this is a pure field
44
+ * mapping of what ISimplifiedCatalogItem can represent:
45
+ * - `price` / `discount_amount` / `item_special_hours` / `display_price` are
46
+ * converted back from the minified (cents) wire form to the original
47
+ * (dollar) representation used by ISimplifiedCatalogItem (same conversion
48
+ * as `getSimplifiedItemWithPrice`),
49
+ * - `tax_rate` is null (not part of the special payload, mirrors
50
+ * `convertSpecialToItem`),
51
+ * - no `modifiers` are produced (selection structure isn't part of the
52
+ * simplified setup).
53
+ */
54
+ function convertSimplifiedSpecialToSimplifiedItem(special) {
55
+ // Minified (cents) wire values → original dollar representation.
56
+ const price = (0, platform_num_1.convertPriceObjFromCents)((0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(special.price));
57
+ const discount_amount = (0, platform_num_1.convertPriceObjFromCents)((0, minified_catalog_1.convertMinifiedPlatformNumToOriginalPlatformNum)(special.discount_amount));
58
+ const item_special_hours = (0, platform_num_1.convertSpecialHoursFromCents)((0, minified_catalog_1.convertMinifiedSpecialHoursToOriginalSpecialHours)(special.item_special_hours));
59
+ const display_price = special.display_price ? (0, price_conversion_1.convertPriceFromCents)(special.display_price) : undefined;
60
+ return {
61
+ sold_out: special.sold_out,
62
+ is_discount_percentage: special.is_discount_percentage,
63
+ show_starting_from: special.show_starting_from,
64
+ display_price,
65
+ price,
66
+ discount_amount,
67
+ item_special_hours,
68
+ // No tax on the special payload (mirrors convertSpecialToItem); no
69
+ // selection structure on the simplified payload.
70
+ tax_rate: null,
71
+ modifiers: null,
72
+ sort_id: special.sort_id,
73
+ hide_name: false,
74
+ is_featured: false,
75
+ featured_sort_id: 0,
76
+ _id: special._id,
77
+ category_id: special.category_id,
78
+ name: special.name,
79
+ included_platforms: special.included_platforms,
80
+ description: special.description,
81
+ active: special.active,
82
+ image_url: special.image_url,
83
+ };
84
+ }
@@ -82,3 +82,64 @@ describe('convertHalfHalfSetupsToSimplifiedHalfHalfSetups', () => {
82
82
  expect(simplifiedList.map((h) => h._id)).toEqual(['hh-1', 'hh-2']);
83
83
  });
84
84
  });
85
+ function makeSimplifiedHalfHalfSetup(overrides = {}) {
86
+ return {
87
+ _id: 'halfhalf-1',
88
+ category_id: 'category-1',
89
+ name: 'Half & Half',
90
+ included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
91
+ description: 'Two halves combo',
92
+ active: true,
93
+ image_url: 'https://example.com/halfhalf.jpg',
94
+ ...overrides,
95
+ };
96
+ }
97
+ describe('convertSimplifiedHalfHalfToSimplifiedItem', () => {
98
+ it('maps identity fields and nulls out fields not present in the simplified payload', () => {
99
+ const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup());
100
+ expect(item._id).toBe('halfhalf-1');
101
+ expect(item.category_id).toBe('category-1');
102
+ expect(item.name).toBe('Half & Half');
103
+ expect(item.description).toBe('Two halves combo');
104
+ expect(item.active).toBe(true);
105
+ expect(item.image_url).toBe('https://example.com/halfhalf.jpg');
106
+ expect(item.included_platforms).toEqual([constants_1.PLATFORMS_ENUM.POS_WALK_IN]);
107
+ // simplified payload has no segments/items/upsell → no base price or modifiers
108
+ expect(item.price).toBeNull();
109
+ expect(item.tax_rate).toBeNull();
110
+ expect(item.discount_amount).toBeNull();
111
+ expect(item.item_special_hours).toBeNull();
112
+ expect(item.modifiers).toBeNull();
113
+ expect(item.sort_id).toBe(0);
114
+ });
115
+ it('carries sold_out through', () => {
116
+ const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({ sold_out: true }));
117
+ expect(item.sold_out).toBe(true);
118
+ });
119
+ it('converts minified discount_amount back to a dollar IPrice', () => {
120
+ const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({ discount_amount: 300, is_discount_percentage: true }));
121
+ expect(item.discount_amount).toEqual({ BASE_PRICE: 3 });
122
+ expect(item.is_discount_percentage).toBe(true);
123
+ });
124
+ it('converts minified item_special_hours back to original special hours', () => {
125
+ const item = (0, simplified_halfhalf_1.convertSimplifiedHalfHalfToSimplifiedItem)(makeSimplifiedHalfHalfSetup({
126
+ item_special_hours: [
127
+ {
128
+ days_index: [constants_1.DAY_INDEX_ENUM.MON],
129
+ start_time: 60,
130
+ end_time: 120,
131
+ price: 500,
132
+ },
133
+ ],
134
+ }));
135
+ expect(item.item_special_hours).toEqual([
136
+ expect.objectContaining({
137
+ days_index: [constants_1.DAY_INDEX_ENUM.MON],
138
+ start_time: 60,
139
+ end_time: 120,
140
+ price: { BASE_PRICE: 5 },
141
+ discount_amount: null,
142
+ }),
143
+ ]);
144
+ });
145
+ });
@@ -10,76 +10,112 @@ function makeSpecial(overrides = {}) {
10
10
  tenants: ['tenant-1', 'tenant-2'],
11
11
  category_id: 'category-1',
12
12
  included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
13
- image_url: 'https://example.com/special.jpg',
14
- name: 'Pizza Deal',
15
- description: 'Special combo',
13
+ name: 'Combo Special',
14
+ description: 'Special combo deal',
16
15
  active: true,
17
16
  sold_out: ['tenant-2'],
18
- sort_id: 1,
19
- price: { BASE_PRICE: 1500 },
17
+ sort_id: 3,
18
+ image_url: 'https://example.com/special.jpg',
19
+ price: { BASE_PRICE: 1000 },
20
20
  discount_amount: null,
21
21
  is_discount_percentage: false,
22
- display_price: 1200,
23
- show_starting_from: true,
22
+ display_price: null,
23
+ show_starting_from: false,
24
24
  item_special_hours: null,
25
- modifier_specials: [
26
- {
27
- _id: 'ms-1',
28
- name: 'Choose 1',
29
- sort_id: 1,
30
- quantity: 1,
31
- num_free_items: 0,
32
- excluded_refs: [],
33
- exclusive_refs: [],
34
- omit_items_schedule: false,
35
- items: [{ item_id: 'item-1', sort_id: 1, upsell_price: null }],
36
- },
37
- ],
25
+ modifier_specials: [],
38
26
  createdAt: new Date('2024-01-01'),
39
27
  updatedAt: new Date('2024-01-02'),
40
28
  ...overrides,
41
29
  };
42
30
  }
31
+ function makeSimplifiedSpecial(overrides = {}) {
32
+ return {
33
+ _id: 'special-1',
34
+ category_id: 'category-1',
35
+ name: 'Combo Special',
36
+ included_platforms: [constants_1.PLATFORMS_ENUM.POS_WALK_IN],
37
+ description: 'Special combo deal',
38
+ active: true,
39
+ sort_id: 3,
40
+ image_url: 'https://example.com/special.jpg',
41
+ ...overrides,
42
+ };
43
+ }
43
44
  describe('convertSpecialToSimplifiedSpecial', () => {
44
45
  it('drops full-only fields and resolves sold_out per tenant', () => {
45
46
  const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial(), TENANT_ID);
46
47
  expect(simplified._id).toBe('special-1');
47
48
  expect(simplified.category_id).toBe('category-1');
48
- expect(simplified.name).toBe('Pizza Deal');
49
- expect(simplified.description).toBe('Special combo');
50
- expect(simplified.active).toBe(true);
51
- expect(simplified.sort_id).toBe(1);
52
- expect(simplified.image_url).toBe('https://example.com/special.jpg');
49
+ expect(simplified.sort_id).toBe(3);
53
50
  expect(simplified.included_platforms).toEqual([constants_1.PLATFORMS_ENUM.POS_WALK_IN]);
54
- // full-only fields are dropped
55
51
  expect(simplified).not.toHaveProperty('brand_id');
56
52
  expect(simplified).not.toHaveProperty('tenants');
57
53
  expect(simplified).not.toHaveProperty('createdAt');
58
54
  expect(simplified).not.toHaveProperty('updatedAt');
59
- // sold_out resolved to boolean for the requested tenant (omitted when not sold out)
60
- expect(simplified.sold_out).toBeUndefined();
61
- });
62
- it('does not expose modifier_specials', () => {
63
- const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial(), TENANT_ID);
64
55
  expect(simplified).not.toHaveProperty('modifier_specials');
56
+ expect(simplified.sold_out).toBeUndefined();
65
57
  });
66
- it('minifies price and discount_amount', () => {
67
- const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial({
68
- price: { BASE_PRICE: 1500, [constants_1.PLATFORMS_ENUM.POS_WALK_IN]: 1500 },
69
- discount_amount: { BASE_PRICE: 300 },
70
- }), TENANT_ID);
71
- expect(simplified.price).toBe(1500);
58
+ it('minifies setup prices', () => {
59
+ const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial({ price: { BASE_PRICE: 1200 }, discount_amount: { BASE_PRICE: 300 } }), TENANT_ID);
60
+ expect(simplified.price).toBe(1200);
72
61
  expect(simplified.discount_amount).toBe(300);
73
62
  });
74
- it('handles a special sold out for the tenant', () => {
75
- const simplified = (0, simplified_specials_1.convertSpecialToSimplifiedSpecial)(makeSpecial({ sold_out: ['tenant-1'] }), TENANT_ID);
76
- expect(simplified.sold_out).toBe(true);
77
- });
78
63
  });
79
64
  describe('convertSpecialsToSimplifiedSpecials', () => {
80
65
  it('maps every special', () => {
81
- const simplifiedList = (0, simplified_specials_1.convertSpecialsToSimplifiedSpecials)([makeSpecial({ _id: 'special-1' }), makeSpecial({ _id: 'special-2' })], TENANT_ID);
66
+ const simplifiedList = (0, simplified_specials_1.convertSpecialsToSimplifiedSpecials)([makeSpecial({ _id: 'sp-1' }), makeSpecial({ _id: 'sp-2' })], TENANT_ID);
82
67
  expect(simplifiedList).toHaveLength(2);
83
- expect(simplifiedList.map((s) => s._id)).toEqual(['special-1', 'special-2']);
68
+ expect(simplifiedList.map((s) => s._id)).toEqual(['sp-1', 'sp-2']);
69
+ });
70
+ });
71
+ describe('convertSimplifiedSpecialToSimplifiedItem', () => {
72
+ it('maps identity fields, tax_rate/modifiers null and carries sort_id', () => {
73
+ const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial());
74
+ expect(item._id).toBe('special-1');
75
+ expect(item.category_id).toBe('category-1');
76
+ expect(item.name).toBe('Combo Special');
77
+ expect(item.description).toBe('Special combo deal');
78
+ expect(item.active).toBe(true);
79
+ expect(item.image_url).toBe('https://example.com/special.jpg');
80
+ expect(item.included_platforms).toEqual([constants_1.PLATFORMS_ENUM.POS_WALK_IN]);
81
+ expect(item.sort_id).toBe(3);
82
+ // no modifier_specials on the simplified payload → no modifiers / tax
83
+ expect(item.modifiers).toBeNull();
84
+ expect(item.tax_rate).toBeNull();
85
+ });
86
+ it('carries sold_out through', () => {
87
+ const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ sold_out: true }));
88
+ expect(item.sold_out).toBe(true);
89
+ });
90
+ it('converts minified price/discount_amount back to dollar IPrice', () => {
91
+ const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ price: 1200, discount_amount: 300, is_discount_percentage: true }));
92
+ expect(item.price).toEqual({ BASE_PRICE: 12 });
93
+ expect(item.discount_amount).toEqual({ BASE_PRICE: 3 });
94
+ expect(item.is_discount_percentage).toBe(true);
95
+ });
96
+ it('converts minified display_price from cents to dollars', () => {
97
+ const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({ display_price: 1250 }));
98
+ expect(item.display_price).toBe(12.5);
99
+ });
100
+ it('converts minified item_special_hours back to original special hours', () => {
101
+ const item = (0, simplified_specials_1.convertSimplifiedSpecialToSimplifiedItem)(makeSimplifiedSpecial({
102
+ item_special_hours: [
103
+ {
104
+ days_index: [constants_1.DAY_INDEX_ENUM.MON],
105
+ start_time: 60,
106
+ end_time: 120,
107
+ price: 500,
108
+ },
109
+ ],
110
+ }));
111
+ expect(item.item_special_hours).toEqual([
112
+ expect.objectContaining({
113
+ days_index: [constants_1.DAY_INDEX_ENUM.MON],
114
+ start_time: 60,
115
+ end_time: 120,
116
+ price: { BASE_PRICE: 5 },
117
+ discount_amount: null,
118
+ }),
119
+ ]);
84
120
  });
85
121
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.705",
3
+ "version": "0.2.707",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",