@managesome/eposmatic-toolkit 0.2.342 → 0.2.343

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.
@@ -77,6 +77,15 @@ export declare function getRemoveItemFromCartData(data: Partial<IOrder>, payload
77
77
  void_reason?: string;
78
78
  }, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
79
79
  export declare function getUpdatedCartInfoOnInit(data: Partial<IOrder>, order: Partial<IOrder>, courses: ICourse[], platform: PLATFORMS_ENUM | undefined, categories: IOrderCategory[] | undefined, mappedItems: Record<string, IItem>, tenantId: string | undefined, listnerSettings: ICartListnerSettings, offers: IOffer[] | undefined): Partial<IOrder>;
80
+ /**
81
+ * Drop entries from `redeemed_offers` (and any related discount/wallet state)
82
+ * for offers whose `included_platforms` does not contain the supplied platform.
83
+ *
84
+ * Use this when the platform changes outside of `getUpdatedCartInfoOnInit` (for
85
+ * example, on platform switch in a long POS cashier session) to keep
86
+ * platform-incompatible rewards from being silently preserved.
87
+ */
88
+ export declare function pruneInvalidRedeemedOffersForPlatform(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, offers: IOffer[] | undefined, platform: PLATFORMS_ENUM | undefined): Partial<IOrder>;
80
89
  export declare function getChangeCourseForItemData(data: Partial<IOrder>, itemId: string, new_course_id: string, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
81
90
  export declare function getChangeCourseStatusData(data: Partial<IOrder>, course_id: string, called: boolean, courses: ICourse[], listnerSettings: ICartListnerSettings): {
82
91
  dinein_details: {
@@ -166,6 +175,21 @@ export declare function getCartItemsObj({ currentIterationCategories, currentDin
166
175
  export declare function getRemoveOfferFromCartData(data: Partial<IOrder>, offer_id: string, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
167
176
  export declare function getRemoveAllOffersFromCartData(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, offerIds: string[] | undefined): Partial<IOrder>;
168
177
  export declare function getClearVoucherCodeAndOffersFromCartData(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings, offerIds: string[] | undefined): Partial<IOrder>;
178
+ /**
179
+ * Wipe all reward metadata (`redeemed_offers`, `wallet_redemptions`) and any
180
+ * loyalty/voucher fields on `order_discount_details`, then resync the cart.
181
+ *
182
+ * Use this on hard reward-session boundaries — for example, in a POS cashier
183
+ * session when the customer phone changes — where every reward applied for the
184
+ * previous customer must be dropped before the next customer's eligibility is
185
+ * evaluated. Items in the cart are preserved.
186
+ *
187
+ * Unlike `getClearVoucherCodeAndOffersFromCartData`, this also clears
188
+ * `wallet_redemptions.gift_cards` and `wallet_redemptions.cashback_amount`,
189
+ * along with any wallet-cashback `loyalty_discount_*` mirror on
190
+ * `order_discount_details`.
191
+ */
192
+ export declare function getResetRewardStateForNewCustomer(data: Partial<IOrder>, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
169
193
  /**
170
194
  * Calculate the eligible subtotal by excluding items/categories in excluded_refs
171
195
  */
@@ -22,12 +22,14 @@ exports.getUpdateItemsInCartData = getUpdateItemsInCartData;
22
22
  exports.getUpdateCartInfoData = getUpdateCartInfoData;
23
23
  exports.getRemoveItemFromCartData = getRemoveItemFromCartData;
24
24
  exports.getUpdatedCartInfoOnInit = getUpdatedCartInfoOnInit;
25
+ exports.pruneInvalidRedeemedOffersForPlatform = pruneInvalidRedeemedOffersForPlatform;
25
26
  exports.getChangeCourseForItemData = getChangeCourseForItemData;
26
27
  exports.getChangeCourseStatusData = getChangeCourseStatusData;
27
28
  exports.getCartItemsObj = getCartItemsObj;
28
29
  exports.getRemoveOfferFromCartData = getRemoveOfferFromCartData;
29
30
  exports.getRemoveAllOffersFromCartData = getRemoveAllOffersFromCartData;
30
31
  exports.getClearVoucherCodeAndOffersFromCartData = getClearVoucherCodeAndOffersFromCartData;
32
+ exports.getResetRewardStateForNewCustomer = getResetRewardStateForNewCustomer;
31
33
  exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
32
34
  const bson_objectid_1 = __importDefault(require("bson-objectid"));
33
35
  const lodash_1 = require("lodash");
@@ -2308,9 +2310,24 @@ function getUpdatedCartInfoOnInit(data, order, courses, platform, categories, ma
2308
2310
  if (platform == null || data.platform === order.platform || offers == null || offers.length === 0) {
2309
2311
  return orderData;
2310
2312
  }
2311
- const redeemedOfferIds = Object.keys(orderData.redeemed_offers ?? {});
2313
+ return pruneInvalidRedeemedOffersForPlatform(orderData, courses, listnerSettings, offers, platform);
2314
+ }
2315
+ /* =================================><================================= */
2316
+ /**
2317
+ * Drop entries from `redeemed_offers` (and any related discount/wallet state)
2318
+ * for offers whose `included_platforms` does not contain the supplied platform.
2319
+ *
2320
+ * Use this when the platform changes outside of `getUpdatedCartInfoOnInit` (for
2321
+ * example, on platform switch in a long POS cashier session) to keep
2322
+ * platform-incompatible rewards from being silently preserved.
2323
+ */
2324
+ function pruneInvalidRedeemedOffersForPlatform(data, courses, listnerSettings, offers, platform) {
2325
+ if (platform == null || offers == null || offers.length === 0) {
2326
+ return data;
2327
+ }
2328
+ const redeemedOfferIds = Object.keys(data.redeemed_offers ?? {});
2312
2329
  if (redeemedOfferIds.length === 0) {
2313
- return orderData;
2330
+ return data;
2314
2331
  }
2315
2332
  const offersMap = new Map();
2316
2333
  for (let i = 0; i < offers.length; i++) {
@@ -2325,11 +2342,10 @@ function getUpdatedCartInfoOnInit(data, order, courses, platform, categories, ma
2325
2342
  }
2326
2343
  }
2327
2344
  if (invalidRedeemedOfferIds.length === 0) {
2328
- return orderData;
2345
+ return data;
2329
2346
  }
2330
- return getRemoveAllOffersFromCartData(orderData, courses, listnerSettings, invalidRedeemedOfferIds);
2347
+ return getRemoveAllOffersFromCartData(data, courses, listnerSettings, invalidRedeemedOfferIds);
2331
2348
  }
2332
- /* =================================><================================= */
2333
2349
  function getChangeCourseForItemData(data, itemId, new_course_id, courses, listnerSettings) {
2334
2350
  if (data.dinein_details == null)
2335
2351
  return data;
@@ -3095,6 +3111,33 @@ function getClearVoucherCodeAndOffersFromCartData(data, courses, listnerSettings
3095
3111
  }, courses, listnerSettings);
3096
3112
  }
3097
3113
  // ================================><================================= //
3114
+ /**
3115
+ * Wipe all reward metadata (`redeemed_offers`, `wallet_redemptions`) and any
3116
+ * loyalty/voucher fields on `order_discount_details`, then resync the cart.
3117
+ *
3118
+ * Use this on hard reward-session boundaries — for example, in a POS cashier
3119
+ * session when the customer phone changes — where every reward applied for the
3120
+ * previous customer must be dropped before the next customer's eligibility is
3121
+ * evaluated. Items in the cart are preserved.
3122
+ *
3123
+ * Unlike `getClearVoucherCodeAndOffersFromCartData`, this also clears
3124
+ * `wallet_redemptions.gift_cards` and `wallet_redemptions.cashback_amount`,
3125
+ * along with any wallet-cashback `loyalty_discount_*` mirror on
3126
+ * `order_discount_details`.
3127
+ */
3128
+ function getResetRewardStateForNewCustomer(data, courses, listnerSettings) {
3129
+ const orderWithoutOffers = getRemoveAllOffersFromCartData(data, courses, listnerSettings, undefined);
3130
+ const orderDiscountDetailsWithoutVoucher = (0, offers_helpers_1.buildClearVoucherDiscountDetails)(orderWithoutOffers.order_discount_details);
3131
+ const orderDiscountDetails = orderDiscountDetailsWithoutVoucher != null &&
3132
+ orderDiscountDetailsWithoutVoucher.loyalty_discount_id === constants_1.WALLET_CASHBACK_LOYALTY_DISCOUNT_ID
3133
+ ? clearLoyaltyDiscountFields(orderDiscountDetailsWithoutVoucher)
3134
+ : orderDiscountDetailsWithoutVoucher;
3135
+ return getUpdateCartInfoData(orderWithoutOffers, {
3136
+ order_discount_details: orderDiscountDetails,
3137
+ wallet_redemptions: null,
3138
+ }, courses, listnerSettings);
3139
+ }
3140
+ // ================================><================================= //
3098
3141
  /**
3099
3142
  * Calculate the eligible subtotal by excluding items/categories in excluded_refs
3100
3143
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.342",
3
+ "version": "0.2.343",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",