@managesome/eposmatic-toolkit 0.2.755 → 0.2.757

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.
@@ -0,0 +1,10 @@
1
+ export interface ITenantOrderItemInstruction {
2
+ _id: string;
3
+ tenant_id: string;
4
+ item_ids: string[];
5
+ sort_id: number;
6
+ instruction: string;
7
+ is_public: boolean;
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
+ import { VENDOR_TYPE_ENUM } from '../../constants';
1
2
  interface IIncludedCategory {
2
3
  category_id: string | null;
3
4
  excluded_items: string[];
@@ -5,6 +6,8 @@ interface IIncludedCategory {
5
6
  export interface ITenantVendor {
6
7
  _id: string;
7
8
  tenant_id: string;
9
+ ref_id: string | null;
10
+ vendor_type: VENDOR_TYPE_ENUM;
8
11
  uid: string;
9
12
  phone_number: string;
10
13
  email: string | null;
@@ -1,3 +1,4 @@
1
+ import { VENDOR_TYPE_ENUM } from '../../constants';
1
2
  interface IIncludedCategory {
2
3
  category_id: string | null;
3
4
  excluded_items: string[];
@@ -5,6 +6,8 @@ interface IIncludedCategory {
5
6
  export interface IWarehouseVendor {
6
7
  _id: string;
7
8
  warehouse_id: string;
9
+ ref_id: string | null;
10
+ vendor_type: VENDOR_TYPE_ENUM;
8
11
  uid: string;
9
12
  phone_number: string;
10
13
  email: string | null;
@@ -63,9 +63,11 @@ function getSingleOfferStats(options = {}) {
63
63
  return (0, offers_helpers_1.getOffersWithStats)({
64
64
  offers: [offer],
65
65
  customer: {
66
- total_orders: 1,
66
+ total_orders: options.totalOrders ?? 1,
67
+ loyalty_points: options.customerLoyaltyPoints ?? 0,
68
+ voucher_codes: options.customerVoucherCodes,
67
69
  },
68
- vouchers: undefined,
70
+ vouchers: options.vouchers,
69
71
  giftCards: undefined,
70
72
  customerOfferRedemptionCounts: undefined,
71
73
  redeemed_offers: redeemedOffers,
@@ -154,4 +156,601 @@ describe('getOffersWithStats spend qualification', () => {
154
156
  expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}200`);
155
157
  expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
156
158
  });
159
+ it('removes excluded item amounts from the orders spend threshold', () => {
160
+ const categories = [
161
+ {
162
+ category_id: 'category-salads',
163
+ items: [
164
+ {
165
+ _id: 'cart-salad',
166
+ item_id: 'item-salad',
167
+ name: 'Salad',
168
+ quantity: 2,
169
+ subtotal: 1398,
170
+ modifiers: [],
171
+ item_discount_details: null,
172
+ },
173
+ ],
174
+ },
175
+ {
176
+ category_id: 'category-deals',
177
+ items: [
178
+ {
179
+ _id: 'cart-deal',
180
+ item_id: 'item-deal',
181
+ name: 'Deal',
182
+ quantity: 1,
183
+ subtotal: 1799,
184
+ modifiers: [],
185
+ item_discount_details: null,
186
+ },
187
+ ],
188
+ },
189
+ ];
190
+ const offer = makeOrdersDiscountOffer({
191
+ pathway_to_unlock_type_orders: {
192
+ scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
193
+ min_num_of_orders: 0,
194
+ max_num_of_orders: null,
195
+ total_amount: 2500,
196
+ max_amount: null,
197
+ orders_between_unlocks: null,
198
+ max_claims: null,
199
+ max_uses_per_customer: null,
200
+ },
201
+ reward_discount: {
202
+ discount_value: 10,
203
+ is_discount_percentage: true,
204
+ max_discount_amount: null,
205
+ max_discount_percentage: null,
206
+ excluded_refs: ['item-deal'],
207
+ },
208
+ });
209
+ const result = getSingleOfferStats({
210
+ offer,
211
+ categories,
212
+ currentItemsPrice: 3197,
213
+ totalDiscountApplied: 0,
214
+ totalOrders: 0,
215
+ });
216
+ const stats = result.offersWithStats[0].stats;
217
+ expect(stats.claimable).toBe(false);
218
+ // 1398 / 2500 — also guards the zero-minimum orders progress fix
219
+ expect(stats.progress).toBe(56);
220
+ // 2500 - 1398 (deal amount no longer counts toward the threshold)
221
+ expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
222
+ expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
223
+ });
224
+ it('keeps the full cart when excluded refs are not present in the cart', () => {
225
+ const result = getSingleOfferStats({
226
+ categories: makeCategories(1000),
227
+ currentItemsPrice: 1000,
228
+ totalDiscountApplied: 0,
229
+ offer: makeOrdersDiscountOffer({
230
+ reward_discount: {
231
+ discount_value: 20,
232
+ is_discount_percentage: true,
233
+ max_discount_amount: null,
234
+ max_discount_percentage: null,
235
+ excluded_refs: ['item-not-in-cart'],
236
+ },
237
+ }),
238
+ });
239
+ const stats = result.offersWithStats[0].stats;
240
+ expect(stats.claimable).toBe(true);
241
+ expect(stats.progress).toBe(100);
242
+ expect(result.totalClaimableOffers).toContain(OFFER_ID);
243
+ });
244
+ it('removes an entirely excluded category from the orders spend threshold', () => {
245
+ const categories = [
246
+ {
247
+ category_id: 'category-salads',
248
+ items: [
249
+ {
250
+ _id: 'cart-salad',
251
+ item_id: 'item-salad',
252
+ name: 'Salad',
253
+ quantity: 1,
254
+ subtotal: 500,
255
+ modifiers: [],
256
+ item_discount_details: null,
257
+ },
258
+ ],
259
+ },
260
+ {
261
+ category_id: 'category-deals',
262
+ items: [
263
+ {
264
+ _id: 'cart-deal',
265
+ item_id: 'item-deal',
266
+ name: 'Deal',
267
+ quantity: 1,
268
+ subtotal: 500,
269
+ modifiers: [],
270
+ item_discount_details: null,
271
+ },
272
+ ],
273
+ },
274
+ ];
275
+ const offer = makeOrdersDiscountOffer({
276
+ reward_discount: {
277
+ discount_value: 20,
278
+ is_discount_percentage: true,
279
+ max_discount_amount: null,
280
+ max_discount_percentage: null,
281
+ excluded_refs: ['category-deals'],
282
+ },
283
+ });
284
+ const result = getSingleOfferStats({
285
+ offer,
286
+ categories,
287
+ currentItemsPrice: 1000,
288
+ totalDiscountApplied: 0,
289
+ });
290
+ const stats = result.offersWithStats[0].stats;
291
+ expect(stats.claimable).toBe(false);
292
+ // 1000 - 500 excludes the whole category
293
+ expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}500`);
294
+ expect(result.totalClaimableOffers).not.toContain(OFFER_ID);
295
+ });
296
+ it('still adds back the applied offer discount when excluded items are present', () => {
297
+ const categories = [
298
+ {
299
+ category_id: 'category-salads',
300
+ items: [
301
+ {
302
+ _id: 'cart-salad',
303
+ item_id: 'item-salad',
304
+ name: 'Salad',
305
+ quantity: 1,
306
+ subtotal: 2600,
307
+ modifiers: [],
308
+ item_discount_details: null,
309
+ },
310
+ ],
311
+ },
312
+ {
313
+ category_id: 'category-deals',
314
+ items: [
315
+ {
316
+ _id: 'cart-deal',
317
+ item_id: 'item-deal',
318
+ name: 'Deal',
319
+ quantity: 1,
320
+ subtotal: 1000,
321
+ modifiers: [],
322
+ item_discount_details: null,
323
+ },
324
+ ],
325
+ },
326
+ ];
327
+ const offer = makeOrdersDiscountOffer({
328
+ pathway_to_unlock_type_orders: {
329
+ scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
330
+ min_num_of_orders: 0,
331
+ max_num_of_orders: null,
332
+ total_amount: 2500,
333
+ max_amount: null,
334
+ orders_between_unlocks: null,
335
+ max_claims: null,
336
+ max_uses_per_customer: null,
337
+ },
338
+ reward_discount: {
339
+ discount_value: 10,
340
+ is_discount_percentage: true,
341
+ max_discount_amount: null,
342
+ max_discount_percentage: null,
343
+ excluded_refs: ['item-deal'],
344
+ },
345
+ });
346
+ const result = getSingleOfferStats({
347
+ offer,
348
+ categories,
349
+ currentItemsPrice: 3600,
350
+ totalDiscountApplied: 260,
351
+ redeemedOffers: { [OFFER_ID]: 1 },
352
+ orderDiscountDetails: {
353
+ loyalty_discount_id: OFFER_ID,
354
+ loyalty_discount_name: 'Spend threshold discount',
355
+ loyalty_discount: 260,
356
+ is_loyalty_discount_percentage: false,
357
+ total_discount: 260,
358
+ },
359
+ });
360
+ const stats = result.offersWithStats[0].stats;
361
+ expect(stats.redeemed_times).toBe(1);
362
+ expect(stats.message).toContain('redeemed');
363
+ expect(result.unlockedOffersApplicableTimes[OFFER_ID]).toBe(1);
364
+ });
365
+ it('applies discount-items and cashback exclusion refs to the spend threshold', () => {
366
+ const categories = [
367
+ {
368
+ category_id: 'category-salads',
369
+ items: [
370
+ {
371
+ _id: 'cart-salad',
372
+ item_id: 'item-salad',
373
+ name: 'Salad',
374
+ quantity: 2,
375
+ subtotal: 1398,
376
+ modifiers: [],
377
+ item_discount_details: null,
378
+ },
379
+ ],
380
+ },
381
+ {
382
+ category_id: 'category-deals',
383
+ items: [
384
+ {
385
+ _id: 'cart-deal',
386
+ item_id: 'item-deal',
387
+ name: 'Deal',
388
+ quantity: 1,
389
+ subtotal: 1799,
390
+ modifiers: [],
391
+ item_discount_details: null,
392
+ },
393
+ ],
394
+ },
395
+ ];
396
+ const ordersThreshold = {
397
+ scope: constants_1.PATHWAY_TO_UNLOCK_TYPE_ORDERS_SCOPE_ENUM.OVERALL,
398
+ min_num_of_orders: 0,
399
+ max_num_of_orders: null,
400
+ total_amount: 2500,
401
+ max_amount: null,
402
+ orders_between_unlocks: null,
403
+ max_claims: null,
404
+ max_uses_per_customer: null,
405
+ };
406
+ const discountItemsResult = getSingleOfferStats({
407
+ offer: makeOrdersDiscountOffer({
408
+ pathway_to_unlock_type_orders: ordersThreshold,
409
+ reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS,
410
+ reward_discount: null,
411
+ reward_discount_items: {
412
+ num_of_items: 1,
413
+ excluded_refs: ['item-deal'],
414
+ exclusive_refs: [],
415
+ item_ids: ['item-salad'],
416
+ discount_value: 10,
417
+ is_discount_percentage: true,
418
+ allocation: null,
419
+ },
420
+ }),
421
+ categories,
422
+ currentItemsPrice: 3197,
423
+ totalDiscountApplied: 0,
424
+ });
425
+ expect(discountItemsResult.offersWithStats[0].stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
426
+ const cashbackResult = getSingleOfferStats({
427
+ offer: makeOrdersDiscountOffer({
428
+ pathway_to_unlock_type_orders: ordersThreshold,
429
+ reward_type: constants_1.OFFER_REWARD_TYPE_ENUM.CASHBACK,
430
+ reward_discount: null,
431
+ reward_cashback: {
432
+ cashback_value: 10,
433
+ is_cashback_percentage: true,
434
+ max_cashback_amount: null,
435
+ excluded_refs: ['item-deal'],
436
+ },
437
+ }),
438
+ categories,
439
+ currentItemsPrice: 3197,
440
+ totalDiscountApplied: 0,
441
+ });
442
+ expect(cashbackResult.offersWithStats[0].stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
443
+ });
444
+ it('reduces the spend threshold for the points pathway', () => {
445
+ const categories = [
446
+ {
447
+ category_id: 'category-salads',
448
+ items: [
449
+ {
450
+ _id: 'cart-salad',
451
+ item_id: 'item-salad',
452
+ name: 'Salad',
453
+ quantity: 2,
454
+ subtotal: 1398,
455
+ modifiers: [],
456
+ item_discount_details: null,
457
+ },
458
+ ],
459
+ },
460
+ {
461
+ category_id: 'category-deals',
462
+ items: [
463
+ {
464
+ _id: 'cart-deal',
465
+ item_id: 'item-deal',
466
+ name: 'Deal',
467
+ quantity: 1,
468
+ subtotal: 1799,
469
+ modifiers: [],
470
+ item_discount_details: null,
471
+ },
472
+ ],
473
+ },
474
+ ];
475
+ const offer = makeOrdersDiscountOffer({
476
+ pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
477
+ pathway_to_unlock_type_orders: null,
478
+ pathway_to_unlock_type_points: {
479
+ num_of_points: 1000,
480
+ total_amount: 2500,
481
+ max_uses_per_customer: null,
482
+ max_claims: null,
483
+ },
484
+ reward_discount: {
485
+ discount_value: 10,
486
+ is_discount_percentage: true,
487
+ max_discount_amount: null,
488
+ max_discount_percentage: null,
489
+ excluded_refs: ['item-deal'],
490
+ },
491
+ });
492
+ const result = getSingleOfferStats({
493
+ offer,
494
+ categories,
495
+ currentItemsPrice: 3197,
496
+ totalDiscountApplied: 0,
497
+ customerLoyaltyPoints: 1000,
498
+ });
499
+ const stats = result.offersWithStats[0].stats;
500
+ expect(stats.claimable).toBe(false);
501
+ expect(stats.progress).toBe(56); // 1398 / 2500
502
+ // 2500 - 1398 — the deal no longer counts toward the threshold
503
+ expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
504
+ });
505
+ it('reduces the spend threshold for the voucher pathway', () => {
506
+ const categories = [
507
+ {
508
+ category_id: 'category-salads',
509
+ items: [
510
+ {
511
+ _id: 'cart-salad',
512
+ item_id: 'item-salad',
513
+ name: 'Salad',
514
+ quantity: 2,
515
+ subtotal: 1398,
516
+ modifiers: [],
517
+ item_discount_details: null,
518
+ },
519
+ ],
520
+ },
521
+ {
522
+ category_id: 'category-deals',
523
+ items: [
524
+ {
525
+ _id: 'cart-deal',
526
+ item_id: 'item-deal',
527
+ name: 'Deal',
528
+ quantity: 1,
529
+ subtotal: 1799,
530
+ modifiers: [],
531
+ item_discount_details: null,
532
+ },
533
+ ],
534
+ },
535
+ ];
536
+ const voucher = {
537
+ _id: 'voucher-party',
538
+ code: 'PARTY10',
539
+ active: true,
540
+ max_uses: 100,
541
+ used_count: 0,
542
+ max_uses_per_customer: null,
543
+ expire_at: null,
544
+ };
545
+ const offer = makeOrdersDiscountOffer({
546
+ pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER,
547
+ pathway_to_unlock_type_orders: null,
548
+ pathway_to_unlock_type_vouchers: {
549
+ total_amount: 2500,
550
+ max_amount: null,
551
+ max_uses_per_customer: null,
552
+ max_claims: null,
553
+ voucher_ids: ['voucher-party'],
554
+ },
555
+ reward_discount: {
556
+ discount_value: 10,
557
+ is_discount_percentage: true,
558
+ max_discount_amount: null,
559
+ max_discount_percentage: null,
560
+ excluded_refs: ['item-deal'],
561
+ },
562
+ });
563
+ const result = getSingleOfferStats({
564
+ offer,
565
+ categories,
566
+ currentItemsPrice: 3197,
567
+ totalDiscountApplied: 0,
568
+ vouchers: [voucher],
569
+ customerVoucherCodes: { PARTY10: 1 },
570
+ });
571
+ const stats = result.offersWithStats[0].stats;
572
+ expect(stats.claimable).toBe(false);
573
+ expect(stats.progress).toBe(56); // 1398 / 2500
574
+ // 2500 - 1398 — the deal no longer counts toward the threshold
575
+ expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
576
+ });
577
+ it('does not let a zero items minimum mask the amount progress', () => {
578
+ const categories = [
579
+ {
580
+ category_id: 'category-salads',
581
+ items: [
582
+ {
583
+ _id: 'cart-salad',
584
+ item_id: 'item-salad',
585
+ name: 'Salad',
586
+ quantity: 2,
587
+ subtotal: 1398,
588
+ modifiers: [],
589
+ item_discount_details: null,
590
+ },
591
+ ],
592
+ },
593
+ {
594
+ category_id: 'category-deals',
595
+ items: [
596
+ {
597
+ _id: 'cart-deal',
598
+ item_id: 'item-deal',
599
+ name: 'Deal',
600
+ quantity: 1,
601
+ subtotal: 1799,
602
+ modifiers: [],
603
+ item_discount_details: null,
604
+ },
605
+ ],
606
+ },
607
+ ];
608
+ const offer = makeOrdersDiscountOffer({
609
+ pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS,
610
+ pathway_to_unlock_type_orders: null,
611
+ pathway_to_unlock_type_items: {
612
+ num_of_items: 0,
613
+ max_uses_per_customer: null,
614
+ max_claims: null,
615
+ min_same_item_quantity: null,
616
+ max_same_item_quantity: null,
617
+ total_amount: 5000,
618
+ excluded_refs: [],
619
+ exclusive_refs: [],
620
+ item_ids: ['item-not-in-cart'],
621
+ category_ids: [],
622
+ },
623
+ });
624
+ const result = getSingleOfferStats({
625
+ offer,
626
+ categories,
627
+ currentItemsPrice: 3197,
628
+ totalDiscountApplied: 0,
629
+ });
630
+ const stats = result.offersWithStats[0].stats;
631
+ expect(stats.claimable).toBe(false);
632
+ // 3197 / 5000 — the satisfied zero minimum must count as 100%, not 0%
633
+ expect(stats.progress).toBe(64);
634
+ expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1803`);
635
+ });
636
+ it('removes excluded item amounts from the items pathway spend threshold', () => {
637
+ const categories = [
638
+ {
639
+ category_id: 'category-salads',
640
+ items: [
641
+ {
642
+ _id: 'cart-salad',
643
+ item_id: 'item-salad',
644
+ name: 'Salad',
645
+ quantity: 2,
646
+ subtotal: 1398,
647
+ modifiers: [],
648
+ item_discount_details: null,
649
+ },
650
+ ],
651
+ },
652
+ {
653
+ category_id: 'category-deals',
654
+ items: [
655
+ {
656
+ _id: 'cart-deal',
657
+ item_id: 'item-deal',
658
+ name: 'Deal',
659
+ quantity: 1,
660
+ subtotal: 1799,
661
+ modifiers: [],
662
+ item_discount_details: null,
663
+ },
664
+ ],
665
+ },
666
+ ];
667
+ const offer = makeOrdersDiscountOffer({
668
+ pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.ITEMS,
669
+ pathway_to_unlock_type_orders: null,
670
+ pathway_to_unlock_type_items: {
671
+ num_of_items: 1,
672
+ max_uses_per_customer: null,
673
+ max_claims: null,
674
+ min_same_item_quantity: null,
675
+ max_same_item_quantity: null,
676
+ total_amount: 2500,
677
+ excluded_refs: [],
678
+ exclusive_refs: [],
679
+ item_ids: ['item-salad'],
680
+ category_ids: [],
681
+ },
682
+ reward_discount: {
683
+ discount_value: 10,
684
+ is_discount_percentage: true,
685
+ max_discount_amount: null,
686
+ max_discount_percentage: null,
687
+ excluded_refs: ['item-deal'],
688
+ },
689
+ });
690
+ const result = getSingleOfferStats({
691
+ offer,
692
+ categories,
693
+ currentItemsPrice: 3197,
694
+ totalDiscountApplied: 0,
695
+ });
696
+ const stats = result.offersWithStats[0].stats;
697
+ // Without the exclusion the 3197 cart would satisfy the 2500 threshold
698
+ expect(stats.claimable).toBe(false);
699
+ expect(stats.progress).toBe(56); // 1398 / 2500
700
+ expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1102`);
701
+ });
702
+ it('does not let a zero points minimum mask the amount progress', () => {
703
+ const categories = [
704
+ {
705
+ category_id: 'category-salads',
706
+ items: [
707
+ {
708
+ _id: 'cart-salad',
709
+ item_id: 'item-salad',
710
+ name: 'Salad',
711
+ quantity: 2,
712
+ subtotal: 1398,
713
+ modifiers: [],
714
+ item_discount_details: null,
715
+ },
716
+ ],
717
+ },
718
+ {
719
+ category_id: 'category-deals',
720
+ items: [
721
+ {
722
+ _id: 'cart-deal',
723
+ item_id: 'item-deal',
724
+ name: 'Deal',
725
+ quantity: 1,
726
+ subtotal: 1799,
727
+ modifiers: [],
728
+ item_discount_details: null,
729
+ },
730
+ ],
731
+ },
732
+ ];
733
+ const offer = makeOrdersDiscountOffer({
734
+ pathway_to_unlock_type: constants_1.PATHWAY_TO_UNLOCK_TYPE_ENUM.POINTS,
735
+ pathway_to_unlock_type_orders: null,
736
+ pathway_to_unlock_type_points: {
737
+ num_of_points: 0,
738
+ total_amount: 5000,
739
+ max_uses_per_customer: null,
740
+ max_claims: null,
741
+ },
742
+ });
743
+ const result = getSingleOfferStats({
744
+ offer,
745
+ categories,
746
+ currentItemsPrice: 3197,
747
+ totalDiscountApplied: 0,
748
+ customerLoyaltyPoints: 0,
749
+ });
750
+ const stats = result.offersWithStats[0].stats;
751
+ expect(stats.claimable).toBe(false);
752
+ // 3197 / 5000 — points balance must not zero out the amount progress
753
+ expect(stats.progress).toBe(64);
754
+ expect(stats.message).toContain(`${constants_1.CURRENCY_SYMBOL_ENUM.$}1803`);
755
+ });
157
756
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.755",
3
+ "version": "0.2.757",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",