@managesome/eposmatic-toolkit 0.2.320 → 0.2.322

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.
@@ -214,6 +214,34 @@ function buildOfferCashbackUpdate({ offer, orderDiscountDetails, categories, })
214
214
  // === (for GIFT_CARDS and VOUCHER reward types — post-order) === //
215
215
  // ================================><================================= //
216
216
  function buildOfferRewardUpdate({ offer, orderDiscountDetails, }) {
217
+ const isGiftCardReward = offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.GIFT_CARDS;
218
+ const isVoucherReward = offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.VOUCHER;
219
+ // This helper is intentionally for deferred rewards only.
220
+ // It records redeemed-offer intent while leaving active discount/wallet state unchanged.
221
+ if (!isGiftCardReward && !isVoucherReward) {
222
+ return {
223
+ success: false,
224
+ discountDetails: null,
225
+ errorMessage: 'Offer reward helper supports only GIFT_CARDS and VOUCHER rewards.',
226
+ redeemedOfferId: null,
227
+ };
228
+ }
229
+ if (isGiftCardReward && offer.reward_gift_cards == null) {
230
+ return {
231
+ success: false,
232
+ discountDetails: null,
233
+ errorMessage: 'Gift-card reward data is not available right now.',
234
+ redeemedOfferId: null,
235
+ };
236
+ }
237
+ if (isVoucherReward && offer.reward_voucher == null) {
238
+ return {
239
+ success: false,
240
+ discountDetails: null,
241
+ errorMessage: 'Voucher reward data is not available right now.',
242
+ redeemedOfferId: null,
243
+ };
244
+ }
217
245
  const discountDetails = orderDiscountDetails ?? null;
218
246
  return {
219
247
  success: true,
@@ -23,12 +23,11 @@ interface ICalculateCustomerSpendableVoucherCodes {
23
23
  * Determines whether a voucher-type offer should show "already claimed"
24
24
  * instead of the toolkit's generic "not eligible" message.
25
25
  *
26
- * Returns `true` when the offer itself has been redeemed AND the voucher's
26
+ * Returns `true` when the offer itself has been redeemed AND the offer's
27
27
  * per-customer usage count has been reached.
28
28
  */
29
- export declare function isExhaustedVoucherOffer({ offer, vouchers, customerOfferRedemptionCounts, redeemedOffers, isRedeemed, }: {
29
+ export declare function isExhaustedVoucherOffer({ offer, customerOfferRedemptionCounts, redeemedOffers, isRedeemed, }: {
30
30
  offer: IOffer | null | undefined;
31
- vouchers: IVoucher[] | undefined;
32
31
  customerOfferRedemptionCounts: Record<string, number> | null | undefined;
33
32
  redeemedOffers: IOrder['redeemed_offers'] | null | undefined;
34
33
  isRedeemed: boolean;
@@ -319,10 +319,10 @@ function getOfferRedeemedClaims(redeemedOffers, offerId) {
319
319
  * Determines whether a voucher-type offer should show "already claimed"
320
320
  * instead of the toolkit's generic "not eligible" message.
321
321
  *
322
- * Returns `true` when the offer itself has been redeemed AND the voucher's
322
+ * Returns `true` when the offer itself has been redeemed AND the offer's
323
323
  * per-customer usage count has been reached.
324
324
  */
325
- function isExhaustedVoucherOffer({ offer, vouchers, customerOfferRedemptionCounts, redeemedOffers, isRedeemed, }) {
325
+ function isExhaustedVoucherOffer({ offer, customerOfferRedemptionCounts, redeemedOffers, isRedeemed, }) {
326
326
  if (offer == null ||
327
327
  offer.pathway_to_unlock_type !== constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER ||
328
328
  offer.pathway_to_unlock_type_vouchers == null ||
@@ -333,29 +333,7 @@ function isExhaustedVoucherOffer({ offer, vouchers, customerOfferRedemptionCount
333
333
  if (!isThisOfferRedeemed)
334
334
  return false;
335
335
  const pathwayMaxUsesPerCustomer = offer.pathway_to_unlock_type_vouchers.max_uses_per_customer;
336
- if (pathwayMaxUsesPerCustomer != null &&
337
- (customerOfferRedemptionCounts[offer._id] ?? 0) >= pathwayMaxUsesPerCustomer) {
338
- return true;
339
- }
340
- if (vouchers == null || vouchers.length === 0) {
341
- return false;
342
- }
343
- const vouchersById = new Map();
344
- for (let i = 0; i < vouchers.length; i++) {
345
- vouchersById.set(vouchers[i]._id, vouchers[i]);
346
- }
347
- const voucherIds = offer.pathway_to_unlock_type_vouchers.voucher_ids;
348
- for (let i = 0; i < voucherIds.length; i++) {
349
- const voucherId = voucherIds[i];
350
- const voucher = vouchersById.get(voucherId);
351
- if (voucher?.max_uses_per_customer == null) {
352
- continue;
353
- }
354
- if ((customerOfferRedemptionCounts[voucherId] ?? 0) >= voucher.max_uses_per_customer) {
355
- return true;
356
- }
357
- }
358
- return false;
336
+ return (pathwayMaxUsesPerCustomer != null && (customerOfferRedemptionCounts[offer._id] ?? 0) >= pathwayMaxUsesPerCustomer);
359
337
  }
360
338
  // ================================><================================= //
361
339
  // === findLinkedVoucherOffers === //
@@ -2178,17 +2156,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
2178
2156
  const normalizedMatchedVoucherCode = matchedVoucher?.code.trim().toUpperCase() ?? null;
2179
2157
  const redeemedTimesForOffer = getOfferRedeemedTimes(offer._id);
2180
2158
  const spendableVoucherCount = normalizedMatchedVoucherCode == null ? 0 : (spendableVoucherCodesByCode[normalizedMatchedVoucherCode] ?? 0);
2181
- // Voucher max_uses_per_customer is resource-scoped by voucher id.
2182
- const customerVoucherUsageCount = matchedVoucher == null ? 0 : (customerOfferRedemptionCounts?.[matchedVoucher._id] ?? 0);
2183
- const voucherUsesPerCustomerExhausted = matchedVoucher?.max_uses_per_customer != null &&
2184
- (customerOfferRedemptionCounts == null || customerVoucherUsageCount >= matchedVoucher.max_uses_per_customer);
2185
2159
  const hasVoucherAccess = matchedVoucher != null && (matchedVoucher.is_public || spendableVoucherCount > 0 || redeemedTimesForOffer > 0);
2186
2160
  const amountProgress = getPreUnlockProgressPercentage(orderValue, total_amount || 1);
2187
2161
  if (!hasMatchingVoucher) {
2188
2162
  stats.progress = 0;
2189
2163
  stats.message = `Apply a matching voucher to unlock this offer`;
2190
2164
  }
2191
- else if (!hasVoucherAccess || voucherUsesPerCustomerExhausted) {
2165
+ else if (!hasVoucherAccess) {
2192
2166
  stats.progress = 0;
2193
2167
  stats.message = `⛔️ You are not eligible for this offer ⛔️`;
2194
2168
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.320",
3
+ "version": "0.2.322",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",