@managesome/eposmatic-toolkit 0.2.403 → 0.2.405
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.
- package/lib/constants/ENUMS.d.ts +5 -2
- package/lib/constants/ENUMS.js +3 -0
- package/lib/helpers/utils/email-helpers.js +10 -0
- package/lib/helpers/utils/specials-helpers.d.ts +17 -0
- package/lib/helpers/utils/specials-helpers.js +136 -0
- package/lib/schemas/types/warehouse-communications.d.ts +1 -0
- package/package.json +1 -1
package/lib/constants/ENUMS.d.ts
CHANGED
|
@@ -601,7 +601,8 @@ export declare const ALL_EMAIL_PROCESSING_PROVIDERS: EMAIL_PROCESSING_PROVIDERS_
|
|
|
601
601
|
export declare enum EMAIL_DOCUMENT_KIND_ENUM {
|
|
602
602
|
RFQ = "RFQ",
|
|
603
603
|
PURCHASE_ORDER = "PURCHASE_ORDER",
|
|
604
|
-
SALE_RFQ = "SALE_RFQ"
|
|
604
|
+
SALE_RFQ = "SALE_RFQ",
|
|
605
|
+
SALE_ORDER = "SALE_ORDER"
|
|
605
606
|
}
|
|
606
607
|
export declare const ALL_EMAIL_DOCUMENT_KINDS: EMAIL_DOCUMENT_KIND_ENUM[];
|
|
607
608
|
export declare enum COMMUNICATION_CHANNEL_ENUM {
|
|
@@ -1201,7 +1202,9 @@ export declare enum EMAIL_TEMPLATES_TYPE_ENUM {
|
|
|
1201
1202
|
SUBSCRIPTION_RENEWED = "SUBSCRIPTION_RENEWED",
|
|
1202
1203
|
WELCOME = "WELCOME",
|
|
1203
1204
|
MARKETING_FORM_SUBMISSION = "MARKETING_FORM_SUBMISSION",
|
|
1204
|
-
EMAIL_TEMPLATE_FOR_RFQ = "EMAIL_TEMPLATE_FOR_RFQ"
|
|
1205
|
+
EMAIL_TEMPLATE_FOR_RFQ = "EMAIL_TEMPLATE_FOR_RFQ",
|
|
1206
|
+
EMAIL_TEMPLATE_FOR_PURCHASE_ORDER = "EMAIL_TEMPLATE_FOR_PURCHASE_ORDER",
|
|
1207
|
+
EMAIL_TEMPLATE_FOR_SALE_ORDER = "EMAIL_TEMPLATE_FOR_SALE_ORDER"
|
|
1205
1208
|
}
|
|
1206
1209
|
export declare enum DISCOUNT_TYPE_ENUM {
|
|
1207
1210
|
SPECIAL = "SPECIAL",
|
package/lib/constants/ENUMS.js
CHANGED
|
@@ -912,6 +912,7 @@ var EMAIL_DOCUMENT_KIND_ENUM;
|
|
|
912
912
|
EMAIL_DOCUMENT_KIND_ENUM["RFQ"] = "RFQ";
|
|
913
913
|
EMAIL_DOCUMENT_KIND_ENUM["PURCHASE_ORDER"] = "PURCHASE_ORDER";
|
|
914
914
|
EMAIL_DOCUMENT_KIND_ENUM["SALE_RFQ"] = "SALE_RFQ";
|
|
915
|
+
EMAIL_DOCUMENT_KIND_ENUM["SALE_ORDER"] = "SALE_ORDER";
|
|
915
916
|
})(EMAIL_DOCUMENT_KIND_ENUM || (exports.EMAIL_DOCUMENT_KIND_ENUM = EMAIL_DOCUMENT_KIND_ENUM = {}));
|
|
916
917
|
exports.ALL_EMAIL_DOCUMENT_KINDS = Object.values(EMAIL_DOCUMENT_KIND_ENUM);
|
|
917
918
|
// ======================>> <<====================== //
|
|
@@ -1928,6 +1929,8 @@ var EMAIL_TEMPLATES_TYPE_ENUM;
|
|
|
1928
1929
|
EMAIL_TEMPLATES_TYPE_ENUM["WELCOME"] = "WELCOME";
|
|
1929
1930
|
EMAIL_TEMPLATES_TYPE_ENUM["MARKETING_FORM_SUBMISSION"] = "MARKETING_FORM_SUBMISSION";
|
|
1930
1931
|
EMAIL_TEMPLATES_TYPE_ENUM["EMAIL_TEMPLATE_FOR_RFQ"] = "EMAIL_TEMPLATE_FOR_RFQ";
|
|
1932
|
+
EMAIL_TEMPLATES_TYPE_ENUM["EMAIL_TEMPLATE_FOR_PURCHASE_ORDER"] = "EMAIL_TEMPLATE_FOR_PURCHASE_ORDER";
|
|
1933
|
+
EMAIL_TEMPLATES_TYPE_ENUM["EMAIL_TEMPLATE_FOR_SALE_ORDER"] = "EMAIL_TEMPLATE_FOR_SALE_ORDER";
|
|
1931
1934
|
})(EMAIL_TEMPLATES_TYPE_ENUM || (exports.EMAIL_TEMPLATES_TYPE_ENUM = EMAIL_TEMPLATES_TYPE_ENUM = {}));
|
|
1932
1935
|
// ======================>> <<====================== //
|
|
1933
1936
|
var DISCOUNT_TYPE_ENUM;
|
|
@@ -89,6 +89,16 @@ const templates = {
|
|
|
89
89
|
alias: 'email-template-for-rfq',
|
|
90
90
|
stream: STREAMS.transactional,
|
|
91
91
|
},
|
|
92
|
+
[constants_1.EMAIL_TEMPLATES_TYPE_ENUM.EMAIL_TEMPLATE_FOR_PURCHASE_ORDER]: {
|
|
93
|
+
id: 45434805,
|
|
94
|
+
alias: 'email-template-for-purchase-order',
|
|
95
|
+
stream: STREAMS.transactional,
|
|
96
|
+
},
|
|
97
|
+
[constants_1.EMAIL_TEMPLATES_TYPE_ENUM.EMAIL_TEMPLATE_FOR_SALE_ORDER]: {
|
|
98
|
+
id: 45447647,
|
|
99
|
+
alias: 'email-template-for-sale-order',
|
|
100
|
+
stream: STREAMS.transactional,
|
|
101
|
+
},
|
|
92
102
|
};
|
|
93
103
|
function getEmailTemplateBody(templateType, to, templateModel) {
|
|
94
104
|
const { id, alias, stream } = templates[templateType];
|
|
@@ -39,4 +39,21 @@ interface IConvertSpecialItemToOrderItem {
|
|
|
39
39
|
existingOrderItem?: IOrderItem;
|
|
40
40
|
}
|
|
41
41
|
export declare function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity, platform, existingOrderItem, }: IConvertSpecialItemToOrderItem): IOrderItem;
|
|
42
|
+
/**
|
|
43
|
+
* Converts an ISpecial into an IItem so it can flow through the standard
|
|
44
|
+
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
45
|
+
*
|
|
46
|
+
* Each `IModifierSpecial` becomes an `IModifier` on the item, and each
|
|
47
|
+
* item within a modifier special becomes an `IModifierOption`.
|
|
48
|
+
*
|
|
49
|
+
* Pricing model (mirrors convertSpecialsToWorkableSpecials):
|
|
50
|
+
* - Special-level price overrides individual item prices (options get null price).
|
|
51
|
+
* - Upsell prices are merged on top.
|
|
52
|
+
* - num_free_items → num_free_options (drawer handles free vs paid).
|
|
53
|
+
* - Item modifiers are pre-filtered by excluded_refs / exclusive_refs.
|
|
54
|
+
*
|
|
55
|
+
* Returns null if the special is inactive, doesn't match platform/tenant,
|
|
56
|
+
* or has no applicable schedule.
|
|
57
|
+
*/
|
|
58
|
+
export declare function convertSpecialToItem(special: ISpecial, itemsMap: Record<string, IItem>, platform: PLATFORMS_ENUM, tenant_id: string): IItem | null;
|
|
42
59
|
export {};
|
|
@@ -10,6 +10,7 @@ exports.getSpecialsDeletedData = getSpecialsDeletedData;
|
|
|
10
10
|
exports.getSpecialWithPrice = getSpecialWithPrice;
|
|
11
11
|
exports.convertSpecialsToWorkableSpecials = convertSpecialsToWorkableSpecials;
|
|
12
12
|
exports.convertSpecialItemToOrderItem = convertSpecialItemToOrderItem;
|
|
13
|
+
exports.convertSpecialToItem = convertSpecialToItem;
|
|
13
14
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
14
15
|
const constants_1 = require("../../constants");
|
|
15
16
|
const store_1 = require("../store");
|
|
@@ -214,3 +215,138 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
|
|
|
214
215
|
orderItem.item_discount_details = item_discount_details;
|
|
215
216
|
return orderItem;
|
|
216
217
|
}
|
|
218
|
+
// ====================================================================================================
|
|
219
|
+
/**
|
|
220
|
+
* Converts an ISpecial into an IItem so it can flow through the standard
|
|
221
|
+
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
222
|
+
*
|
|
223
|
+
* Each `IModifierSpecial` becomes an `IModifier` on the item, and each
|
|
224
|
+
* item within a modifier special becomes an `IModifierOption`.
|
|
225
|
+
*
|
|
226
|
+
* Pricing model (mirrors convertSpecialsToWorkableSpecials):
|
|
227
|
+
* - Special-level price overrides individual item prices (options get null price).
|
|
228
|
+
* - Upsell prices are merged on top.
|
|
229
|
+
* - num_free_items → num_free_options (drawer handles free vs paid).
|
|
230
|
+
* - Item modifiers are pre-filtered by excluded_refs / exclusive_refs.
|
|
231
|
+
*
|
|
232
|
+
* Returns null if the special is inactive, doesn't match platform/tenant,
|
|
233
|
+
* or has no applicable schedule.
|
|
234
|
+
*/
|
|
235
|
+
function convertSpecialToItem(special, itemsMap, platform, tenant_id) {
|
|
236
|
+
// ── Guard: active, tenant, platform ────────────────────────────
|
|
237
|
+
if (!special.active || !special.tenants.includes(tenant_id) || !special.included_platforms.includes(platform)) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
// ── Schedule resolution ────────────────────────────────────────
|
|
241
|
+
const applicableSchedule = (0, platform_catalog_1.findApplicableSchedule)(special.item_special_hours, platform);
|
|
242
|
+
if (applicableSchedule === false)
|
|
243
|
+
return null;
|
|
244
|
+
let price = special.price;
|
|
245
|
+
if (applicableSchedule !== true && applicableSchedule.price) {
|
|
246
|
+
price = applicableSchedule.price;
|
|
247
|
+
}
|
|
248
|
+
let discount_amount = special.discount_amount;
|
|
249
|
+
if (applicableSchedule !== true && applicableSchedule.discount_amount) {
|
|
250
|
+
discount_amount = applicableSchedule.discount_amount;
|
|
251
|
+
}
|
|
252
|
+
// ── Build modifiers from modifier_specials ─────────────────────
|
|
253
|
+
const modifiers = [];
|
|
254
|
+
for (let j = 0; j < special.modifier_specials.length; j++) {
|
|
255
|
+
const modifierSpecial = special.modifier_specials[j];
|
|
256
|
+
const omitItemLevelSchedule = modifierSpecial.omit_items_schedule;
|
|
257
|
+
const modifierSpecialItems = [...modifierSpecial.items];
|
|
258
|
+
modifierSpecialItems.sort((a, b) => a.sort_id - b.sort_id);
|
|
259
|
+
const options = [];
|
|
260
|
+
for (let k = 0; k < modifierSpecialItems.length; k++) {
|
|
261
|
+
const specialItem = modifierSpecialItems[k];
|
|
262
|
+
const catalogItem = itemsMap[specialItem.item_id];
|
|
263
|
+
if (!catalogItem)
|
|
264
|
+
continue;
|
|
265
|
+
const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, omitItemLevelSchedule, true);
|
|
266
|
+
if (!workableItem)
|
|
267
|
+
continue;
|
|
268
|
+
// Determine option price:
|
|
269
|
+
// special has its own price → options carry null price
|
|
270
|
+
// (num_free_options in the drawer handles free-vs-paid)
|
|
271
|
+
// no special price → use item's own price
|
|
272
|
+
// upsell_price is always merged on top
|
|
273
|
+
let optionPrice = special.price != null ? null : workableItem.price;
|
|
274
|
+
if (specialItem.upsell_price != null) {
|
|
275
|
+
optionPrice = (0, platform_num_1.mergePriceObjs)(optionPrice, specialItem.upsell_price);
|
|
276
|
+
}
|
|
277
|
+
// Pre-filter the item's own modifiers using excluded_refs / exclusive_refs
|
|
278
|
+
let itemModifiers = null;
|
|
279
|
+
if (workableItem.modifiers != null && workableItem.modifiers.length > 0) {
|
|
280
|
+
let filtered = workableItem.modifiers;
|
|
281
|
+
if (modifierSpecial.exclusive_refs.length > 0) {
|
|
282
|
+
// Only keep modifiers whose ref is in exclusive_refs
|
|
283
|
+
filtered = filtered.filter((m) => modifierSpecial.exclusive_refs.includes(m.ref));
|
|
284
|
+
}
|
|
285
|
+
else if (modifierSpecial.excluded_refs.length > 0) {
|
|
286
|
+
// Remove modifiers whose ref is in excluded_refs
|
|
287
|
+
filtered = filtered.filter((m) => !modifierSpecial.excluded_refs.includes(m.ref));
|
|
288
|
+
}
|
|
289
|
+
itemModifiers = filtered.length > 0 ? filtered : null;
|
|
290
|
+
}
|
|
291
|
+
options.push({
|
|
292
|
+
_id: `${modifierSpecial._id}_${catalogItem._id}`,
|
|
293
|
+
ref: catalogItem._id,
|
|
294
|
+
name: catalogItem.name,
|
|
295
|
+
active: catalogItem.active,
|
|
296
|
+
sold_out: catalogItem.sold_out,
|
|
297
|
+
sort_id: specialItem.sort_id,
|
|
298
|
+
excluded_platforms: [],
|
|
299
|
+
price: optionPrice,
|
|
300
|
+
modifiers: itemModifiers,
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
if (options.length === 0)
|
|
304
|
+
continue;
|
|
305
|
+
modifiers.push({
|
|
306
|
+
_id: modifierSpecial._id,
|
|
307
|
+
ref: modifierSpecial._id,
|
|
308
|
+
name: modifierSpecial.name,
|
|
309
|
+
description: '',
|
|
310
|
+
active: true,
|
|
311
|
+
sold_out: [],
|
|
312
|
+
sort_id: modifierSpecial.sort_id,
|
|
313
|
+
min_num_options: modifierSpecial.quantity,
|
|
314
|
+
max_num_options: modifierSpecial.quantity,
|
|
315
|
+
num_free_options: modifierSpecial.num_free_items > 0 ? modifierSpecial.num_free_items : null,
|
|
316
|
+
options,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
// ── Assemble the IItem ─────────────────────────────────────────
|
|
320
|
+
const item = {
|
|
321
|
+
_id: special._id,
|
|
322
|
+
brand_id: special.brand_id,
|
|
323
|
+
tenants: special.tenants,
|
|
324
|
+
category_id: constants_1.SPECIALS_CATEGORY_ID,
|
|
325
|
+
included_platforms: special.included_platforms,
|
|
326
|
+
name: special.name,
|
|
327
|
+
hide_name: false,
|
|
328
|
+
description: special.description,
|
|
329
|
+
active: special.active,
|
|
330
|
+
sold_out: special.sold_out,
|
|
331
|
+
sort_id: special.sort_id,
|
|
332
|
+
price,
|
|
333
|
+
discount_amount,
|
|
334
|
+
is_discount_percentage: special.is_discount_percentage,
|
|
335
|
+
caveats: [],
|
|
336
|
+
dietary_preferences: [],
|
|
337
|
+
tax_rate: null,
|
|
338
|
+
keywords: [],
|
|
339
|
+
image_url: special.image_url,
|
|
340
|
+
ingredients: null,
|
|
341
|
+
item_special_hours: null, // already resolved into price / discount_amount
|
|
342
|
+
modifiers: modifiers.length > 0 ? modifiers : null,
|
|
343
|
+
is_featured: false,
|
|
344
|
+
featured_sort_id: 0,
|
|
345
|
+
display_price: null,
|
|
346
|
+
show_starting_from: false,
|
|
347
|
+
use_source_ingredients: false,
|
|
348
|
+
createdAt: special.createdAt,
|
|
349
|
+
updatedAt: special.updatedAt,
|
|
350
|
+
};
|
|
351
|
+
return item;
|
|
352
|
+
}
|
|
@@ -35,6 +35,7 @@ export interface IWarehouseCommunicationMetadata {
|
|
|
35
35
|
line_items: IWarehouseCommunicationLineItem[];
|
|
36
36
|
notes?: string | null;
|
|
37
37
|
action_buttons?: IWarehouseCommunicationActionButton[];
|
|
38
|
+
theme_color?: string | null;
|
|
38
39
|
}
|
|
39
40
|
export interface IWarehouseCommunication {
|
|
40
41
|
_id: string;
|