@managesome/eposmatic-toolkit 0.2.706 → 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.
@@ -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.706",
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",