@infuro/cms-core 1.0.68 → 1.0.70
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/dist/{OrderTrackPage-W3J6WIG2.js → OrderTrackPage-VBZUVZOU.js} +1 -1
- package/dist/{OrderTrackPage-Z6FCJQYY.cjs → OrderTrackPage-VFIXWJOW.cjs} +4 -4
- package/dist/admin.cjs +2831 -2680
- package/dist/admin.js +1590 -1439
- package/dist/api.cjs +57 -57
- package/dist/api.js +24 -24
- package/dist/auth.cjs +62 -62
- package/dist/auth.js +6 -6
- package/dist/{chunk-XJNNOSJR.js → chunk-2BNVRFUQ.js} +1 -1
- package/dist/chunk-2JHGIWH7.cjs +2700 -0
- package/dist/{chunk-3DZRIZOD.cjs → chunk-3ASNJS2H.cjs} +3 -3
- package/dist/{chunk-N4LBZXBG.js → chunk-3LF4RYAJ.js} +360 -30
- package/dist/{chunk-7NMT3GBR.cjs → chunk-3LQS4ATQ.cjs} +4 -4
- package/dist/{chunk-P6S4XFZO.cjs → chunk-47G65M5Q.cjs} +2 -2
- package/dist/{chunk-UMC7W5G3.cjs → chunk-4MNVIGVJ.cjs} +11 -11
- package/dist/{chunk-OY2YTBMP.cjs → chunk-4WZNRVEZ.cjs} +3 -3
- package/dist/chunk-5BKT4CS5.js +28 -0
- package/dist/{chunk-IKTBZJHT.js → chunk-5DSY3GQI.js} +1 -1
- package/dist/{chunk-AYERBA7I.js → chunk-5NVGWJSY.js} +1 -1
- package/dist/{chunk-HF3L2GIT.cjs → chunk-5YMKJ3TH.cjs} +16 -16
- package/dist/{chunk-MYUGQHU4.js → chunk-7NQMGB2S.js} +162 -51
- package/dist/{chunk-SYBOCAWB.js → chunk-7QJI56OL.js} +1 -1
- package/dist/{chunk-DBPSJYLZ.js → chunk-BK5XW5XH.js} +1 -1
- package/dist/{chunk-SUUD7OUG.cjs → chunk-BQQMTQ4C.cjs} +27 -27
- package/dist/{chunk-6YOQ7G5O.js → chunk-CFUSYGSA.js} +1 -1
- package/dist/{chunk-OOTLNH63.cjs → chunk-CIZZX57T.cjs} +2 -2
- package/dist/{chunk-5NOZSG6J.js → chunk-CJY2HUJC.js} +20 -20
- package/dist/{chunk-HBUV73RB.cjs → chunk-CKTRA3Q2.cjs} +81 -81
- package/dist/{chunk-7L6KWI7S.cjs → chunk-CTTV375J.cjs} +13 -13
- package/dist/{chunk-2IAXTKQN.cjs → chunk-DZNWS2MM.cjs} +2 -2
- package/dist/{chunk-M5GPOPGX.cjs → chunk-E62LKM6Z.cjs} +2 -2
- package/dist/{chunk-CRFV5WJK.js → chunk-ECNYZG6T.js} +1 -1
- package/dist/{chunk-OVTOP42W.js → chunk-ECUGNV2I.js} +2 -58
- package/dist/{chunk-TZEMLHSP.cjs → chunk-EYUBL7YH.cjs} +7 -7
- package/dist/{chunk-OV5TRZET.cjs → chunk-FNLF6G2N.cjs} +27 -27
- package/dist/{chunk-SKJH7PX4.js → chunk-HZZTDM5J.js} +3 -3
- package/dist/{chunk-TJ2MIQUT.cjs → chunk-JRW3GQD4.cjs} +4 -4
- package/dist/{chunk-3K5AIEIZ.js → chunk-JYRFSFXH.js} +1 -1
- package/dist/{chunk-GWDI752Q.js → chunk-K6JT7BKY.js} +59 -2
- package/dist/{chunk-WKDBMDUX.js → chunk-K6RXCLD5.js} +1 -1
- package/dist/{chunk-PA6YDMFZ.cjs → chunk-K742UE6S.cjs} +13 -12
- package/dist/{chunk-WFMVD567.cjs → chunk-KB7EBYPR.cjs} +9 -67
- package/dist/{chunk-H3IVLIPR.cjs → chunk-KJB5LBFQ.cjs} +63 -4
- package/dist/{chunk-O4AFPDQ4.cjs → chunk-LCZZ3S4I.cjs} +49 -49
- package/dist/{chunk-7JCCPQEF.js → chunk-LJ5C4RBF.js} +3 -3
- package/dist/{chunk-EIZKW2PF.js → chunk-LY7CDNC6.js} +1 -1
- package/dist/{chunk-MQBT33IV.js → chunk-MGT4DJ2D.js} +1 -1
- package/dist/{chunk-GN4LKG4V.cjs → chunk-NIBEGDD4.cjs} +18 -18
- package/dist/{chunk-ZY64VJMS.js → chunk-NQF6H656.js} +2 -2
- package/dist/{chunk-22XKONB5.cjs → chunk-OP624LWU.cjs} +1204 -1093
- package/dist/{chunk-ZIT4IP6N.js → chunk-PQJIJ4ZX.js} +6 -6
- package/dist/{chunk-HY3AXLOI.cjs → chunk-PRXVSSIF.cjs} +13 -13
- package/dist/{chunk-TDV6EJHV.js → chunk-PRZOLCFW.js} +2 -2
- package/dist/{chunk-VM6OVUUM.cjs → chunk-QN6PZLAP.cjs} +40 -40
- package/dist/{chunk-UPLVMVRX.cjs → chunk-RQCXRCYM.cjs} +2 -2
- package/dist/{chunk-Z5G54EGD.js → chunk-SCE2GIKH.js} +5 -5
- package/dist/{chunk-WUQAOTHA.js → chunk-SERRQ736.js} +1 -1
- package/dist/{chunk-SMHQV3WL.cjs → chunk-TTOEY7AH.cjs} +496 -166
- package/dist/{chunk-FLUF2GZH.js → chunk-W2ZTGLUH.js} +2 -1
- package/dist/{chunk-JC6DLWTE.js → chunk-WQZ4AH2P.js} +1 -1
- package/dist/{chunk-D5FBNKQM.cjs → chunk-WXH3GMCF.cjs} +8 -8
- package/dist/chunk-XHPRD45G.cjs +32 -0
- package/dist/{chunk-THL5JDWJ.cjs → chunk-Y54WDY2O.cjs} +2 -2
- package/dist/{chunk-YRCKEGL2.js → chunk-YDMHG6BA.js} +1 -1
- package/dist/chunk-YHVA5NHI.js +2698 -0
- package/dist/{chunk-JXF23MPG.js → chunk-ZMIMKNSQ.js} +1 -1
- package/dist/cli.cjs +10 -10
- package/dist/cli.js +1 -1
- package/dist/email-queue-BJDH2ID7.cjs +29 -0
- package/dist/email-queue-MWP4R67H.js +8 -0
- package/dist/email-service-6JODEMUA.js +3 -0
- package/dist/email-service-VA4Q4ZRB.cjs +28 -0
- package/dist/emit-order-notification-trigger-I4HQSTEN.cjs +16 -0
- package/dist/emit-order-notification-trigger-TBXAZAPS.js +3 -0
- package/dist/erp-config-enabled-32XTHBBT.cjs +11 -0
- package/dist/erp-config-enabled-CASE5YVI.js +2 -0
- package/dist/erp-order-invoice-5O42ZKC5.cjs +28 -0
- package/dist/erp-order-invoice-JEQKFXG4.js +7 -0
- package/dist/{event-order-defaults-DU7V3YND.cjs → event-order-defaults-TR45WAQQ.cjs} +10 -10
- package/dist/{event-order-defaults-H4RT7NMR.js → event-order-defaults-VXYO6NHT.js} +2 -2
- package/dist/generate-local-invoice-pdf-2NCA2WBL.cjs +12 -0
- package/dist/generate-local-invoice-pdf-XUH6GYEJ.js +3 -0
- package/dist/hooks.cjs +24 -24
- package/dist/hooks.js +2 -2
- package/dist/index.cjs +504 -504
- package/dist/index.js +39 -39
- package/dist/interpolate-KD37IRF2.js +2 -0
- package/dist/interpolate-WP6OSJHN.cjs +11 -0
- package/dist/{invoice-templates-RB462AQN.cjs → invoice-templates-2ESQ7K4N.cjs} +5 -5
- package/dist/invoice-templates-3AXTXERZ.js +2 -0
- package/dist/middleware.cjs +4 -4
- package/dist/middleware.js +2 -2
- package/dist/{order-assignees-handlers-KF7RMTV5.cjs → order-assignees-handlers-E6PQZP4H.cjs} +25 -6
- package/dist/{order-assignees-handlers-L3RVKUBS.js → order-assignees-handlers-YCT3Q3KC.js} +23 -4
- package/dist/{order-completion-otp-handlers-DDQREULW.cjs → order-completion-otp-handlers-2ZKRK5SN.cjs} +25 -25
- package/dist/{order-completion-otp-handlers-NROWBGXN.js → order-completion-otp-handlers-KHLZQQJX.js} +12 -12
- package/dist/{order-inventory-76V4XIGW.js → order-inventory-R3AU6N4V.js} +2 -2
- package/dist/{order-inventory-2MYRKEPC.cjs → order-inventory-UUFPWLBW.cjs} +10 -10
- package/dist/order-notification-dispatcher-37KDVHBM.cjs +38 -0
- package/dist/order-notification-dispatcher-Z3MXNF4U.js +13 -0
- package/dist/paid-order-erp-GRXR2OG6.js +3 -0
- package/dist/paid-order-erp-X5QHPI23.cjs +12 -0
- package/dist/pg-boss-service-CMW3KQJM.js +2 -0
- package/dist/pg-boss-service-GA6ZVD5G.cjs +15 -0
- package/dist/{razorpay-U23LGY72.cjs → razorpay-GP2DXVP2.cjs} +2 -2
- package/dist/{razorpay-KLO2KNCB.js → razorpay-I3G5LNYH.js} +1 -1
- package/dist/{rbac-debug-db-DFZWZ6GV.js → rbac-debug-db-JK3U5UZK.js} +2 -2
- package/dist/{rbac-debug-db-KWV7D5PQ.cjs → rbac-debug-db-S3D6N6HN.cjs} +4 -4
- package/dist/resolve-invoice-asset-url-64QQUVC3.js +2 -0
- package/dist/resolve-invoice-asset-url-J7WAMD26.cjs +11 -0
- package/dist/retire-soft-deleted-unique-DZALT537.cjs +15 -0
- package/dist/{retire-soft-deleted-unique-NXQIH4BC.js → retire-soft-deleted-unique-F25KZBZK.js} +2 -2
- package/dist/sms-defaults-DSO3M26Y.js +2 -0
- package/dist/{sms-defaults-KCOPKQBA.cjs → sms-defaults-GDFILHHR.cjs} +5 -5
- package/dist/{sms-notification-templates-handlers-SJLO7JGZ.js → sms-notification-templates-handlers-ZGDCVS5Z.js} +1 -1
- package/dist/{sms-notification-templates-handlers-YSB3L2PK.cjs → sms-notification-templates-handlers-ZKLKFRFZ.cjs} +3 -3
- package/dist/{stripe-VU6OEG2D.cjs → stripe-2APRZHKU.cjs} +2 -2
- package/dist/{stripe-4FD27QVJ.js → stripe-7CO2ETTN.js} +1 -1
- package/dist/theme.cjs +10 -10
- package/dist/theme.js +3 -3
- package/dist/vendor-invite-status-45ZCWKCX.js +2 -0
- package/dist/{vendor-invite-status-77O7ZQ3U.cjs → vendor-invite-status-AT2E4FUA.cjs} +5 -5
- package/package.json +2 -1
- package/dist/chunk-SHUYVCID.js +0 -4
- package/dist/chunk-USNT2KNT.cjs +0 -6
- package/dist/chunk-Z5OB5QGN.js +0 -465
- package/dist/chunk-ZX5U3VCB.cjs +0 -471
- package/dist/email-queue-3QBQ63F7.js +0 -8
- package/dist/email-queue-K4E4OFI7.cjs +0 -29
- package/dist/email-service-5O24BSFR.cjs +0 -28
- package/dist/email-service-ADDF52PJ.js +0 -3
- package/dist/emit-order-notification-trigger-ROASTYQP.cjs +0 -16
- package/dist/emit-order-notification-trigger-YUQTPELC.js +0 -3
- package/dist/erp-config-enabled-CUMQ6N2V.cjs +0 -11
- package/dist/erp-config-enabled-T37X7T34.js +0 -2
- package/dist/erp-order-invoice-AZ5MX2JB.cjs +0 -28
- package/dist/erp-order-invoice-XSYHAMBS.js +0 -7
- package/dist/generate-local-invoice-pdf-BQTCL5MW.cjs +0 -12
- package/dist/generate-local-invoice-pdf-OCFG47SE.js +0 -3
- package/dist/interpolate-WAKPN56R.cjs +0 -11
- package/dist/interpolate-WDUWDF3I.js +0 -2
- package/dist/invoice-templates-GZ33OENC.js +0 -2
- package/dist/order-notification-dispatcher-6HCJ6Q75.cjs +0 -38
- package/dist/order-notification-dispatcher-KM2SY7TX.js +0 -13
- package/dist/paid-order-erp-3USEG6WL.js +0 -3
- package/dist/paid-order-erp-FSQ3GSXE.cjs +0 -12
- package/dist/pg-boss-service-BDGOKM2T.cjs +0 -15
- package/dist/pg-boss-service-WCBJD4JB.js +0 -2
- package/dist/resolve-invoice-asset-url-JEZRENJW.cjs +0 -11
- package/dist/resolve-invoice-asset-url-QZ2FRDHI.js +0 -2
- package/dist/retire-soft-deleted-unique-5VXBA5XX.cjs +0 -15
- package/dist/sms-defaults-2NL24H57.js +0 -2
- package/dist/vendor-invite-status-PWJ3DE76.js +0 -2
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
3
|
+
var chunkKJB5LBFQ_cjs = require('./chunk-KJB5LBFQ.cjs');
|
|
4
|
+
var chunkK742UE6S_cjs = require('./chunk-K742UE6S.cjs');
|
|
5
|
+
var chunkCIZZX57T_cjs = require('./chunk-CIZZX57T.cjs');
|
|
6
|
+
var chunkQN6PZLAP_cjs = require('./chunk-QN6PZLAP.cjs');
|
|
7
|
+
var chunk4MNVIGVJ_cjs = require('./chunk-4MNVIGVJ.cjs');
|
|
8
|
+
var chunkEYUBL7YH_cjs = require('./chunk-EYUBL7YH.cjs');
|
|
9
|
+
var chunkXHPRD45G_cjs = require('./chunk-XHPRD45G.cjs');
|
|
10
10
|
var crypto = require('crypto');
|
|
11
11
|
|
|
12
12
|
function _interopNamespace(e) {
|
|
@@ -39,7 +39,7 @@ function resolvePublicSiteUrl() {
|
|
|
39
39
|
}
|
|
40
40
|
return "";
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
chunkXHPRD45G_cjs.__name(resolvePublicSiteUrl, "resolvePublicSiteUrl");
|
|
43
43
|
function buildOrderTrackUrl(qrToken, siteUrl, orderNumber) {
|
|
44
44
|
const token = qrToken?.trim() || orderNumber?.trim();
|
|
45
45
|
if (!token) return "";
|
|
@@ -47,7 +47,7 @@ function buildOrderTrackUrl(qrToken, siteUrl, orderNumber) {
|
|
|
47
47
|
if (!base) return `/track/${token}`;
|
|
48
48
|
return `${base}/track/${token}`;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
chunkXHPRD45G_cjs.__name(buildOrderTrackUrl, "buildOrderTrackUrl");
|
|
51
51
|
function formatOrderDetailsText(input) {
|
|
52
52
|
const { orderNumber, total, currency, lines } = input;
|
|
53
53
|
const header = `Order: ${orderNumber}
|
|
@@ -59,13 +59,13 @@ Total: ${total} ${currency}`;
|
|
|
59
59
|
Items:
|
|
60
60
|
${items}`;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
chunkXHPRD45G_cjs.__name(formatOrderDetailsText, "formatOrderDetailsText");
|
|
63
63
|
function formatOrderDetailsHtml(input) {
|
|
64
64
|
const text = formatOrderDetailsText(input);
|
|
65
65
|
const escaped = text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
66
66
|
return `<pre style="font-family:inherit;white-space:pre-wrap;margin:0">${escaped}</pre>`;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
chunkXHPRD45G_cjs.__name(formatOrderDetailsHtml, "formatOrderDetailsHtml");
|
|
69
69
|
function buildEventOrderTemplateVariables(input) {
|
|
70
70
|
const { event, order, contact, productNames, vendorName = "", orderLines = [], siteUrl } = input;
|
|
71
71
|
const trackUrl = buildOrderTrackUrl(order.qrToken, siteUrl, order.orderNumber);
|
|
@@ -103,7 +103,7 @@ function buildEventOrderTemplateVariables(input) {
|
|
|
103
103
|
orderDetailsHtml: formatOrderDetailsHtml(orderDetailsPayload)
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
chunkXHPRD45G_cjs.__name(buildEventOrderTemplateVariables, "buildEventOrderTemplateVariables");
|
|
107
107
|
function formatEventDate(d) {
|
|
108
108
|
if (!d) return "";
|
|
109
109
|
try {
|
|
@@ -115,7 +115,7 @@ function formatEventDate(d) {
|
|
|
115
115
|
return String(d);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
chunkXHPRD45G_cjs.__name(formatEventDate, "formatEventDate");
|
|
119
119
|
|
|
120
120
|
// src/lib/order-notification-context.ts
|
|
121
121
|
async function loadOrderLines(dataSource, entityMap, orderId, currency) {
|
|
@@ -142,7 +142,7 @@ async function loadOrderLines(dataSource, entityMap, orderId, currency) {
|
|
|
142
142
|
};
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
chunkXHPRD45G_cjs.__name(loadOrderLines, "loadOrderLines");
|
|
146
146
|
async function loadPrimaryEvent(dataSource, entityMap, itemRows) {
|
|
147
147
|
if (!entityMap.event_products || !entityMap.events) {
|
|
148
148
|
return {
|
|
@@ -195,7 +195,7 @@ async function loadPrimaryEvent(dataSource, entityMap, itemRows) {
|
|
|
195
195
|
productNames: first.productNames
|
|
196
196
|
};
|
|
197
197
|
}
|
|
198
|
-
|
|
198
|
+
chunkXHPRD45G_cjs.__name(loadPrimaryEvent, "loadPrimaryEvent");
|
|
199
199
|
async function isFeatureGroupEnabled(dataSource, entityMap, group) {
|
|
200
200
|
if (!entityMap.configs) return true;
|
|
201
201
|
try {
|
|
@@ -214,7 +214,7 @@ async function isFeatureGroupEnabled(dataSource, entityMap, group) {
|
|
|
214
214
|
return true;
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
|
|
217
|
+
chunkXHPRD45G_cjs.__name(isFeatureGroupEnabled, "isFeatureGroupEnabled");
|
|
218
218
|
async function loadOrderNotificationContexts(orderId, deps) {
|
|
219
219
|
if (!deps.entityMap.orders) return null;
|
|
220
220
|
const order = await deps.dataSource.getRepository(deps.entityMap.orders).findOne({
|
|
@@ -358,7 +358,7 @@ async function loadOrderNotificationContexts(orderId, deps) {
|
|
|
358
358
|
variables
|
|
359
359
|
};
|
|
360
360
|
}
|
|
361
|
-
|
|
361
|
+
chunkXHPRD45G_cjs.__name(loadOrderNotificationContexts, "loadOrderNotificationContexts");
|
|
362
362
|
function formatScheduleDate(val) {
|
|
363
363
|
if (!val || typeof val !== "string" && !(val instanceof Date)) return "";
|
|
364
364
|
const str = String(val).trim();
|
|
@@ -368,14 +368,14 @@ function formatScheduleDate(val) {
|
|
|
368
368
|
dateStyle: "medium"
|
|
369
369
|
});
|
|
370
370
|
}
|
|
371
|
-
|
|
371
|
+
chunkXHPRD45G_cjs.__name(formatScheduleDate, "formatScheduleDate");
|
|
372
372
|
|
|
373
373
|
// src/plugins/whatsapp/whatsapp-service.ts
|
|
374
374
|
function norm(v) {
|
|
375
375
|
const t = v?.trim();
|
|
376
376
|
return t || void 0;
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
chunkXHPRD45G_cjs.__name(norm, "norm");
|
|
379
379
|
function pick(plugin, db, env, ...keys) {
|
|
380
380
|
for (const key of keys) {
|
|
381
381
|
const pk = key;
|
|
@@ -388,7 +388,7 @@ function pick(plugin, db, env, ...keys) {
|
|
|
388
388
|
}
|
|
389
389
|
return void 0;
|
|
390
390
|
}
|
|
391
|
-
|
|
391
|
+
chunkXHPRD45G_cjs.__name(pick, "pick");
|
|
392
392
|
function mergeWhatsAppConfigLayers(env, db, plugin) {
|
|
393
393
|
return {
|
|
394
394
|
accessToken: pick(plugin, db, env, "accessToken", "WHATSAPP_ACCESS_TOKEN"),
|
|
@@ -396,21 +396,24 @@ function mergeWhatsAppConfigLayers(env, db, plugin) {
|
|
|
396
396
|
apiVersion: pick(plugin, db, env, "apiVersion", "WHATSAPP_API_VERSION") ?? "v21.0"
|
|
397
397
|
};
|
|
398
398
|
}
|
|
399
|
-
|
|
399
|
+
chunkXHPRD45G_cjs.__name(mergeWhatsAppConfigLayers, "mergeWhatsAppConfigLayers");
|
|
400
400
|
function isWhatsAppPluginEnabled(db) {
|
|
401
401
|
const v = (db.enabled ?? "true").toLowerCase();
|
|
402
402
|
return v !== "false" && v !== "0";
|
|
403
403
|
}
|
|
404
|
-
|
|
404
|
+
chunkXHPRD45G_cjs.__name(isWhatsAppPluginEnabled, "isWhatsAppPluginEnabled");
|
|
405
405
|
function whatsAppConfigured(config) {
|
|
406
406
|
return Boolean(config.accessToken?.trim() && config.phoneNumberId?.trim());
|
|
407
407
|
}
|
|
408
|
-
|
|
408
|
+
chunkXHPRD45G_cjs.__name(whatsAppConfigured, "whatsAppConfigured");
|
|
409
409
|
function normalizeWhatsAppRecipient(to) {
|
|
410
|
-
|
|
410
|
+
let digits = to.replace(/\D/g, "");
|
|
411
|
+
if (digits.length === 10) {
|
|
412
|
+
digits = `91${digits}`;
|
|
413
|
+
}
|
|
411
414
|
return digits;
|
|
412
415
|
}
|
|
413
|
-
|
|
416
|
+
chunkXHPRD45G_cjs.__name(normalizeWhatsAppRecipient, "normalizeWhatsAppRecipient");
|
|
414
417
|
function resolveMetaWhatsAppTemplateName(opts) {
|
|
415
418
|
const ref = opts.externalTemplateRef?.trim();
|
|
416
419
|
const rowName = opts.name?.trim();
|
|
@@ -418,22 +421,22 @@ function resolveMetaWhatsAppTemplateName(opts) {
|
|
|
418
421
|
if (rowName) return rowName;
|
|
419
422
|
return ref || void 0;
|
|
420
423
|
}
|
|
421
|
-
|
|
424
|
+
chunkXHPRD45G_cjs.__name(resolveMetaWhatsAppTemplateName, "resolveMetaWhatsAppTemplateName");
|
|
422
425
|
function maskPhone(digits) {
|
|
423
426
|
if (digits.length <= 4) return "****";
|
|
424
427
|
return `${"*".repeat(Math.max(0, digits.length - 4))}${digits.slice(-4)}`;
|
|
425
428
|
}
|
|
426
|
-
|
|
429
|
+
chunkXHPRD45G_cjs.__name(maskPhone, "maskPhone");
|
|
427
430
|
function logWhatsApp(level, message, extra) {
|
|
428
431
|
const line = extra ? `${message} ${JSON.stringify(extra)}` : message;
|
|
429
432
|
if (level === "info") console.log(`[whatsapp] ${line}`);
|
|
430
433
|
else if (level === "warn") console.warn(`[whatsapp] ${line}`);
|
|
431
434
|
else console.error(`[whatsapp] ${line}`);
|
|
432
435
|
}
|
|
433
|
-
|
|
436
|
+
chunkXHPRD45G_cjs.__name(logWhatsApp, "logWhatsApp");
|
|
434
437
|
var WhatsAppService = class {
|
|
435
438
|
static {
|
|
436
|
-
|
|
439
|
+
chunkXHPRD45G_cjs.__name(this, "WhatsAppService");
|
|
437
440
|
}
|
|
438
441
|
getWhatsAppSettings;
|
|
439
442
|
config;
|
|
@@ -477,7 +480,7 @@ var WhatsAppService = class {
|
|
|
477
480
|
let body = opts.body?.trim() ?? "";
|
|
478
481
|
const variables = opts.variables ?? {};
|
|
479
482
|
if (opts.templateKey?.trim() && this.getMessageTemplateRow) {
|
|
480
|
-
const { resolveEventOrderTemplate, EVENT_ORDER_TEMPLATE_KEY } = await import('./event-order-defaults-
|
|
483
|
+
const { resolveEventOrderTemplate, EVENT_ORDER_TEMPLATE_KEY } = await import('./event-order-defaults-TR45WAQQ.cjs');
|
|
481
484
|
if (opts.templateKey.trim() === EVENT_ORDER_TEMPLATE_KEY) {
|
|
482
485
|
const resolved = await resolveEventOrderTemplate("whatsapp", async (ch, key) => {
|
|
483
486
|
const row = await this.getMessageTemplateRow(ch, key);
|
|
@@ -501,12 +504,11 @@ var WhatsAppService = class {
|
|
|
501
504
|
}
|
|
502
505
|
}
|
|
503
506
|
}
|
|
504
|
-
const { applyTemplateVars: applyTemplateVars2 } = await import('./interpolate-
|
|
507
|
+
const { applyTemplateVars: applyTemplateVars2 } = await import('./interpolate-WP6OSJHN.cjs');
|
|
505
508
|
if (body) body = applyTemplateVars2(body, variables);
|
|
506
509
|
if (templateName) {
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
] : [];
|
|
510
|
+
const isHelloWorld = templateName === "hello_world";
|
|
511
|
+
const paramValues = isHelloWorld ? [] : opts.templateParamOrder?.length ? opts.templateParamOrder.map((key) => String(variables[key] ?? "").replace(/[\r\n\t]+/g, " ").replace(/\s{4,}/g, " ").trim().slice(0, 1024)) : [];
|
|
510
512
|
logWhatsApp("info", "sending template message", {
|
|
511
513
|
to: maskPhone(to),
|
|
512
514
|
templateName,
|
|
@@ -629,16 +631,16 @@ function parseEmailRecipientsFromConfig(raw) {
|
|
|
629
631
|
}
|
|
630
632
|
return trimmed.split(/[,;]+/).map((s) => s.trim()).filter(Boolean);
|
|
631
633
|
}
|
|
632
|
-
|
|
634
|
+
chunkXHPRD45G_cjs.__name(parseEmailRecipientsFromConfig, "parseEmailRecipientsFromConfig");
|
|
633
635
|
function serializeEmailRecipients(emails) {
|
|
634
636
|
return JSON.stringify(emails);
|
|
635
637
|
}
|
|
636
|
-
|
|
638
|
+
chunkXHPRD45G_cjs.__name(serializeEmailRecipients, "serializeEmailRecipients");
|
|
637
639
|
function joinRecipientsForSend(emails) {
|
|
638
640
|
if (!emails.length) return null;
|
|
639
641
|
return emails.join(", ");
|
|
640
642
|
}
|
|
641
|
-
|
|
643
|
+
chunkXHPRD45G_cjs.__name(joinRecipientsForSend, "joinRecipientsForSend");
|
|
642
644
|
|
|
643
645
|
// src/plugins/llm/chat-email-intent.ts
|
|
644
646
|
var NONE_INTENT = "NONE";
|
|
@@ -650,11 +652,11 @@ function logChatEmail(step, data) {
|
|
|
650
652
|
console.info(CHAT_EMAIL_LOG, step);
|
|
651
653
|
}
|
|
652
654
|
}
|
|
653
|
-
|
|
655
|
+
chunkXHPRD45G_cjs.__name(logChatEmail, "logChatEmail");
|
|
654
656
|
function normalizeIntentKey(raw) {
|
|
655
657
|
return raw.trim().toUpperCase().replace(/[^A-Z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
656
658
|
}
|
|
657
|
-
|
|
659
|
+
chunkXHPRD45G_cjs.__name(normalizeIntentKey, "normalizeIntentKey");
|
|
658
660
|
function parseIntentsJson(raw) {
|
|
659
661
|
if (!raw?.trim()) return null;
|
|
660
662
|
try {
|
|
@@ -679,7 +681,7 @@ function parseIntentsJson(raw) {
|
|
|
679
681
|
return null;
|
|
680
682
|
}
|
|
681
683
|
}
|
|
682
|
-
|
|
684
|
+
chunkXHPRD45G_cjs.__name(parseIntentsJson, "parseIntentsJson");
|
|
683
685
|
function dedupeIntents(intents) {
|
|
684
686
|
const seen = /* @__PURE__ */ new Set();
|
|
685
687
|
const out = [];
|
|
@@ -695,7 +697,7 @@ function dedupeIntents(intents) {
|
|
|
695
697
|
}
|
|
696
698
|
return out;
|
|
697
699
|
}
|
|
698
|
-
|
|
700
|
+
chunkXHPRD45G_cjs.__name(dedupeIntents, "dedupeIntents");
|
|
699
701
|
function parseChatEmailToolSettings(map) {
|
|
700
702
|
const fromJson = parseIntentsJson(map.emailIntents);
|
|
701
703
|
const intents = dedupeIntents(fromJson ?? []);
|
|
@@ -717,7 +719,7 @@ ${legacyNegative}`);
|
|
|
717
719
|
toolPrompt: map.emailToolPrompt ?? ""
|
|
718
720
|
};
|
|
719
721
|
}
|
|
720
|
-
|
|
722
|
+
chunkXHPRD45G_cjs.__name(parseChatEmailToolSettings, "parseChatEmailToolSettings");
|
|
721
723
|
var EMAIL_TOOL_VALIDATION_KEY = "emailTool";
|
|
722
724
|
function parseEmailToolObject(raw) {
|
|
723
725
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
@@ -735,7 +737,7 @@ function parseEmailToolObject(raw) {
|
|
|
735
737
|
intents
|
|
736
738
|
};
|
|
737
739
|
}
|
|
738
|
-
|
|
740
|
+
chunkXHPRD45G_cjs.__name(parseEmailToolObject, "parseEmailToolObject");
|
|
739
741
|
function parseEmailToolFromAgentValidationRules(validationRulesText) {
|
|
740
742
|
const raw = validationRulesText?.trim();
|
|
741
743
|
if (!raw) return null;
|
|
@@ -748,7 +750,7 @@ function parseEmailToolFromAgentValidationRules(validationRulesText) {
|
|
|
748
750
|
return null;
|
|
749
751
|
}
|
|
750
752
|
}
|
|
751
|
-
|
|
753
|
+
chunkXHPRD45G_cjs.__name(parseEmailToolFromAgentValidationRules, "parseEmailToolFromAgentValidationRules");
|
|
752
754
|
function resolveChatEmailToolSettings(configMap, sources) {
|
|
753
755
|
const fromConfig = parseChatEmailToolSettings(configMap);
|
|
754
756
|
const resolved = typeof sources === "string" || sources == null ? {
|
|
@@ -772,17 +774,17 @@ function resolveChatEmailToolSettings(configMap, sources) {
|
|
|
772
774
|
toolPrompt
|
|
773
775
|
};
|
|
774
776
|
}
|
|
775
|
-
|
|
777
|
+
chunkXHPRD45G_cjs.__name(resolveChatEmailToolSettings, "resolveChatEmailToolSettings");
|
|
776
778
|
function intentByKey(intents, key) {
|
|
777
779
|
if (!key) return null;
|
|
778
780
|
const norm2 = normalizeIntentKey(key);
|
|
779
781
|
return intents.find((i) => i.intent === norm2) ?? null;
|
|
780
782
|
}
|
|
781
|
-
|
|
783
|
+
chunkXHPRD45G_cjs.__name(intentByKey, "intentByKey");
|
|
782
784
|
function buildIntentTableForPrompt(intents) {
|
|
783
785
|
return intents.map((i) => `- ${i.intent}: ${i.description} \u2192 notify ${i.emailTo}`).join("\n");
|
|
784
786
|
}
|
|
785
|
-
|
|
787
|
+
chunkXHPRD45G_cjs.__name(buildIntentTableForPrompt, "buildIntentTableForPrompt");
|
|
786
788
|
function buildIntentClassifierSystem(config, agentClassifierInstructions) {
|
|
787
789
|
const table = buildIntentTableForPrompt(config.intents);
|
|
788
790
|
const extra = [
|
|
@@ -806,7 +808,7 @@ Reply with ONLY valid JSON, no markdown:
|
|
|
806
808
|
{"intent":"INTENT_KEY","reason":"short explanation"}
|
|
807
809
|
Use "${NONE_INTENT}" when no intent applies.`;
|
|
808
810
|
}
|
|
809
|
-
|
|
811
|
+
chunkXHPRD45G_cjs.__name(buildIntentClassifierSystem, "buildIntentClassifierSystem");
|
|
810
812
|
function buildChatEmailAgentContext(settings) {
|
|
811
813
|
if (!settings.enabled) return "";
|
|
812
814
|
const classifier = settings.classifierInstructions.trim();
|
|
@@ -826,7 +828,7 @@ ${classifier}`);
|
|
|
826
828
|
${extra}`);
|
|
827
829
|
return parts.join("\n\n");
|
|
828
830
|
}
|
|
829
|
-
|
|
831
|
+
chunkXHPRD45G_cjs.__name(buildChatEmailAgentContext, "buildChatEmailAgentContext");
|
|
830
832
|
function buildChatbotSystemPromptWithEmailTool(baseSystemInstruction, guardrailsForPrompt, emailSettings) {
|
|
831
833
|
let prompt = (baseSystemInstruction ?? "").trim();
|
|
832
834
|
const guard = guardrailsForPrompt?.trim();
|
|
@@ -843,7 +845,7 @@ function buildChatbotSystemPromptWithEmailTool(baseSystemInstruction, guardrails
|
|
|
843
845
|
}
|
|
844
846
|
return prompt;
|
|
845
847
|
}
|
|
846
|
-
|
|
848
|
+
chunkXHPRD45G_cjs.__name(buildChatbotSystemPromptWithEmailTool, "buildChatbotSystemPromptWithEmailTool");
|
|
847
849
|
function formatTranscript(history, latestMessage, maxChars = 4e3) {
|
|
848
850
|
const lines = [];
|
|
849
851
|
for (const m of history) {
|
|
@@ -858,12 +860,12 @@ function formatTranscript(history, latestMessage, maxChars = 4e3) {
|
|
|
858
860
|
if (text.length > maxChars) text = text.slice(-maxChars);
|
|
859
861
|
return text;
|
|
860
862
|
}
|
|
861
|
-
|
|
863
|
+
chunkXHPRD45G_cjs.__name(formatTranscript, "formatTranscript");
|
|
862
864
|
function parseIntentJson(raw, intents) {
|
|
863
865
|
const trimmed = raw.trim();
|
|
864
866
|
const fence = trimmed.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
865
867
|
const candidate = (fence?.[1] ?? trimmed).trim();
|
|
866
|
-
const tryParse = /* @__PURE__ */
|
|
868
|
+
const tryParse = /* @__PURE__ */ chunkXHPRD45G_cjs.__name((s) => {
|
|
867
869
|
const o = JSON.parse(s);
|
|
868
870
|
let intentRaw = null;
|
|
869
871
|
if (typeof o.intent === "string") intentRaw = o.intent;
|
|
@@ -888,7 +890,7 @@ function parseIntentJson(raw, intents) {
|
|
|
888
890
|
}
|
|
889
891
|
}
|
|
890
892
|
}
|
|
891
|
-
|
|
893
|
+
chunkXHPRD45G_cjs.__name(parseIntentJson, "parseIntentJson");
|
|
892
894
|
async function detectChatLeadIntent(llm, params) {
|
|
893
895
|
if (!params.settings.intents.length) {
|
|
894
896
|
logChatEmail("classify skipped", {
|
|
@@ -995,15 +997,15 @@ Pick the single best intent for the visitor's latest message.`;
|
|
|
995
997
|
emailTo: matched.emailTo
|
|
996
998
|
};
|
|
997
999
|
}
|
|
998
|
-
|
|
1000
|
+
chunkXHPRD45G_cjs.__name(detectChatLeadIntent, "detectChatLeadIntent");
|
|
999
1001
|
function buildTranscriptForLeadEmail(history, latestMessage) {
|
|
1000
1002
|
return formatTranscript(history, latestMessage);
|
|
1001
1003
|
}
|
|
1002
|
-
|
|
1004
|
+
chunkXHPRD45G_cjs.__name(buildTranscriptForLeadEmail, "buildTranscriptForLeadEmail");
|
|
1003
1005
|
function parseIntentRecipientEmails(emailTo) {
|
|
1004
1006
|
return emailTo.split(/[,;]+/).map((s) => s.trim()).filter((s) => s.length > 0 && s.includes("@"));
|
|
1005
1007
|
}
|
|
1006
|
-
|
|
1008
|
+
chunkXHPRD45G_cjs.__name(parseIntentRecipientEmails, "parseIntentRecipientEmails");
|
|
1007
1009
|
|
|
1008
1010
|
// src/plugins/email/chat-lead-email.ts
|
|
1009
1011
|
function resolveLeadRecipients(emailPlugin2, emailSettings) {
|
|
@@ -1015,7 +1017,7 @@ function resolveLeadRecipients(emailPlugin2, emailSettings) {
|
|
|
1015
1017
|
];
|
|
1016
1018
|
return [];
|
|
1017
1019
|
}
|
|
1018
|
-
|
|
1020
|
+
chunkXHPRD45G_cjs.__name(resolveLeadRecipients, "resolveLeadRecipients");
|
|
1019
1021
|
async function sendChatLeadEmail(cms, emailSettings, brandingSettings, input) {
|
|
1020
1022
|
console.info(CHAT_EMAIL_LOG, "send start", {
|
|
1021
1023
|
conversationId: input.conversationId,
|
|
@@ -1053,14 +1055,14 @@ async function sendChatLeadEmail(cms, emailSettings, brandingSettings, input) {
|
|
|
1053
1055
|
recipients,
|
|
1054
1056
|
source: input.recipients?.length ? "intent_email_to" : "crm_or_smtp_fallback"
|
|
1055
1057
|
});
|
|
1056
|
-
const companyDetails =
|
|
1058
|
+
const companyDetails = chunkEYUBL7YH_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings);
|
|
1057
1059
|
const ctx = {
|
|
1058
1060
|
...input,
|
|
1059
1061
|
companyDetails: input.companyDetails ?? companyDetails
|
|
1060
1062
|
};
|
|
1061
1063
|
let anySent = false;
|
|
1062
1064
|
for (const to of recipients) {
|
|
1063
|
-
await
|
|
1065
|
+
await chunk4MNVIGVJ_cjs.queueEmail(cms, {
|
|
1064
1066
|
to,
|
|
1065
1067
|
templateName: "chatLead",
|
|
1066
1068
|
ctx
|
|
@@ -1082,7 +1084,7 @@ async function sendChatLeadEmail(cms, emailSettings, brandingSettings, input) {
|
|
|
1082
1084
|
recipients
|
|
1083
1085
|
};
|
|
1084
1086
|
}
|
|
1085
|
-
|
|
1087
|
+
chunkXHPRD45G_cjs.__name(sendChatLeadEmail, "sendChatLeadEmail");
|
|
1086
1088
|
|
|
1087
1089
|
// src/plugins/email/index.ts
|
|
1088
1090
|
var EMAIL_TYPES = [
|
|
@@ -1095,13 +1097,13 @@ function normalizeEmailType(raw, fallback) {
|
|
|
1095
1097
|
const v = String(raw ?? fallback).trim().toUpperCase();
|
|
1096
1098
|
return EMAIL_TYPES.includes(v) ? v : fallback;
|
|
1097
1099
|
}
|
|
1098
|
-
|
|
1100
|
+
chunkXHPRD45G_cjs.__name(normalizeEmailType, "normalizeEmailType");
|
|
1099
1101
|
function isLocalSmtpHost(host) {
|
|
1100
1102
|
if (!host) return false;
|
|
1101
1103
|
const h = host.trim().toLowerCase();
|
|
1102
1104
|
return h === "localhost" || h === "127.0.0.1" || h === "::1";
|
|
1103
1105
|
}
|
|
1104
|
-
|
|
1106
|
+
chunkXHPRD45G_cjs.__name(isLocalSmtpHost, "isLocalSmtpHost");
|
|
1105
1107
|
function emailPlugin(config) {
|
|
1106
1108
|
return {
|
|
1107
1109
|
name: "email",
|
|
@@ -1135,7 +1137,7 @@ function emailPlugin(config) {
|
|
|
1135
1137
|
context.logger.warn("Email plugin skipped: AWS SES requires AWS_SES_REGION or AWS_REGION");
|
|
1136
1138
|
return void 0;
|
|
1137
1139
|
}
|
|
1138
|
-
if (type === "AWS" && merged.region && merged.user && merged.password && !
|
|
1140
|
+
if (type === "AWS" && merged.region && merged.user && merged.password && !chunkQN6PZLAP_cjs.sesRegionSupportsSmtp(merged.region)) {
|
|
1139
1141
|
context.logger.warn(`Email plugin: region ${merged.region} has no SES SMTP endpoint (ENOTFOUND). Set AWS_SES_REGION=ap-south-1 and create SMTP credentials in that SES region.`);
|
|
1140
1142
|
}
|
|
1141
1143
|
if (type === "AWS" && !(merged.user && merged.password || merged.accessKeyId && merged.secretAccessKey)) {
|
|
@@ -1150,22 +1152,22 @@ function emailPlugin(config) {
|
|
|
1150
1152
|
context.logger.warn("Email plugin skipped: SMTP_TYPE=SMTP requires SMTP_HOST (or use SMTP_TYPE=AWS with AWS_REGION and SES SMTP credentials)");
|
|
1151
1153
|
return void 0;
|
|
1152
1154
|
}
|
|
1153
|
-
const resolvedHost = type === "AWS" && merged.region ? merged.host ||
|
|
1155
|
+
const resolvedHost = type === "AWS" && merged.region ? merged.host || chunkQN6PZLAP_cjs.sesSmtpHost(merged.region) : merged.host;
|
|
1154
1156
|
context.logger.info("Email plugin initialized", {
|
|
1155
1157
|
type,
|
|
1156
1158
|
host: resolvedHost,
|
|
1157
1159
|
region: merged.region
|
|
1158
1160
|
});
|
|
1159
|
-
return new
|
|
1161
|
+
return new chunkQN6PZLAP_cjs.EmailService(merged);
|
|
1160
1162
|
}
|
|
1161
1163
|
};
|
|
1162
1164
|
}
|
|
1163
|
-
|
|
1165
|
+
chunkXHPRD45G_cjs.__name(emailPlugin, "emailPlugin");
|
|
1164
1166
|
function base64UrlEncode(str) {
|
|
1165
1167
|
const buf = typeof str === "string" ? Buffer.from(str, "utf8") : str;
|
|
1166
1168
|
return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1167
1169
|
}
|
|
1168
|
-
|
|
1170
|
+
chunkXHPRD45G_cjs.__name(base64UrlEncode, "base64UrlEncode");
|
|
1169
1171
|
async function getGoogleAccessToken(clientEmail, privateKey) {
|
|
1170
1172
|
const now = Math.floor(Date.now() / 1e3);
|
|
1171
1173
|
const header = {
|
|
@@ -1207,7 +1209,7 @@ async function getGoogleAccessToken(clientEmail, privateKey) {
|
|
|
1207
1209
|
}
|
|
1208
1210
|
return tokenData.access_token;
|
|
1209
1211
|
}
|
|
1210
|
-
|
|
1212
|
+
chunkXHPRD45G_cjs.__name(getGoogleAccessToken, "getGoogleAccessToken");
|
|
1211
1213
|
async function sendFcmPushNotification(dataSource, entityMap, msg) {
|
|
1212
1214
|
try {
|
|
1213
1215
|
const pushSettings = await getSettingsGroup(dataSource, entityMap, "push");
|
|
@@ -1271,7 +1273,7 @@ async function sendFcmPushNotification(dataSource, entityMap, msg) {
|
|
|
1271
1273
|
};
|
|
1272
1274
|
}
|
|
1273
1275
|
}
|
|
1274
|
-
|
|
1276
|
+
chunkXHPRD45G_cjs.__name(sendFcmPushNotification, "sendFcmPushNotification");
|
|
1275
1277
|
async function validateFcmCredentials(dataSource, entityMap) {
|
|
1276
1278
|
try {
|
|
1277
1279
|
const pushSettings = await getSettingsGroup(dataSource, entityMap, "push");
|
|
@@ -1313,7 +1315,7 @@ async function validateFcmCredentials(dataSource, entityMap) {
|
|
|
1313
1315
|
};
|
|
1314
1316
|
}
|
|
1315
1317
|
}
|
|
1316
|
-
|
|
1318
|
+
chunkXHPRD45G_cjs.__name(validateFcmCredentials, "validateFcmCredentials");
|
|
1317
1319
|
|
|
1318
1320
|
// src/lib/order-notification-defaults.ts
|
|
1319
1321
|
var ORDER_NOTIFICATION_DEFAULTS = {
|
|
@@ -1436,19 +1438,25 @@ async function getSettingsGroup(dataSource, entityMap, group) {
|
|
|
1436
1438
|
r.value
|
|
1437
1439
|
]));
|
|
1438
1440
|
}
|
|
1439
|
-
|
|
1441
|
+
chunkXHPRD45G_cjs.__name(getSettingsGroup, "getSettingsGroup");
|
|
1440
1442
|
async function isEmailNotificationsEnabled(dataSource, entityMap) {
|
|
1441
1443
|
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1442
1444
|
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1443
1445
|
return settings.email_enabled !== "false" && settings.email_enabled !== "0";
|
|
1444
1446
|
}
|
|
1445
|
-
|
|
1447
|
+
chunkXHPRD45G_cjs.__name(isEmailNotificationsEnabled, "isEmailNotificationsEnabled");
|
|
1446
1448
|
async function isWhatsappNotificationsEnabled(dataSource, entityMap) {
|
|
1447
1449
|
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1448
1450
|
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1449
1451
|
return settings.whatsapp_enabled !== "false" && settings.whatsapp_enabled !== "0";
|
|
1450
1452
|
}
|
|
1451
|
-
|
|
1453
|
+
chunkXHPRD45G_cjs.__name(isWhatsappNotificationsEnabled, "isWhatsappNotificationsEnabled");
|
|
1454
|
+
async function isSmsNotificationsEnabled(dataSource, entityMap) {
|
|
1455
|
+
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1456
|
+
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1457
|
+
return settings.sms_enabled !== "false" && settings.sms_enabled !== "0";
|
|
1458
|
+
}
|
|
1459
|
+
chunkXHPRD45G_cjs.__name(isSmsNotificationsEnabled, "isSmsNotificationsEnabled");
|
|
1452
1460
|
async function isTriggerCatalogEnabled(triggerKey, dataSource, entityMap) {
|
|
1453
1461
|
if (!entityMap.order_notification_triggers) {
|
|
1454
1462
|
return true;
|
|
@@ -1467,7 +1475,7 @@ async function isTriggerCatalogEnabled(triggerKey, dataSource, entityMap) {
|
|
|
1467
1475
|
return true;
|
|
1468
1476
|
}
|
|
1469
1477
|
}
|
|
1470
|
-
|
|
1478
|
+
chunkXHPRD45G_cjs.__name(isTriggerCatalogEnabled, "isTriggerCatalogEnabled");
|
|
1471
1479
|
async function loadBoundTemplate(triggerKey, channel, audienceType = "customers", dataSource, entityMap) {
|
|
1472
1480
|
if (!entityMap.order_notification_bindings || !entityMap.message_templates) {
|
|
1473
1481
|
console.warn("[order-notifications] order_notification_bindings or message_templates missing from entityMap");
|
|
@@ -1587,7 +1595,7 @@ async function loadBoundTemplate(triggerKey, channel, audienceType = "customers"
|
|
|
1587
1595
|
return null;
|
|
1588
1596
|
}
|
|
1589
1597
|
}
|
|
1590
|
-
|
|
1598
|
+
chunkXHPRD45G_cjs.__name(loadBoundTemplate, "loadBoundTemplate");
|
|
1591
1599
|
function mergeTriggerVariables(payload, rich) {
|
|
1592
1600
|
const basic = {
|
|
1593
1601
|
orderId: String(payload.orderId ?? ""),
|
|
@@ -1614,7 +1622,7 @@ function mergeTriggerVariables(payload, rich) {
|
|
|
1614
1622
|
...extraVars
|
|
1615
1623
|
};
|
|
1616
1624
|
}
|
|
1617
|
-
|
|
1625
|
+
chunkXHPRD45G_cjs.__name(mergeTriggerVariables, "mergeTriggerVariables");
|
|
1618
1626
|
async function isAudienceEmailEnabled(dataSource, entityMap, audience) {
|
|
1619
1627
|
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1620
1628
|
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
@@ -1622,13 +1630,13 @@ async function isAudienceEmailEnabled(dataSource, entityMap, audience) {
|
|
|
1622
1630
|
const key = `email_${audience}_enabled`;
|
|
1623
1631
|
return settings[key] !== "false" && settings[key] !== "0";
|
|
1624
1632
|
}
|
|
1625
|
-
|
|
1633
|
+
chunkXHPRD45G_cjs.__name(isAudienceEmailEnabled, "isAudienceEmailEnabled");
|
|
1626
1634
|
async function isPushNotificationsEnabled(dataSource, entityMap) {
|
|
1627
1635
|
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1628
1636
|
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1629
1637
|
return settings.push_enabled !== "false" && settings.push_enabled !== "0";
|
|
1630
1638
|
}
|
|
1631
|
-
|
|
1639
|
+
chunkXHPRD45G_cjs.__name(isPushNotificationsEnabled, "isPushNotificationsEnabled");
|
|
1632
1640
|
async function isAudiencePushEnabled(dataSource, entityMap, audience) {
|
|
1633
1641
|
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1634
1642
|
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
@@ -1636,14 +1644,30 @@ async function isAudiencePushEnabled(dataSource, entityMap, audience) {
|
|
|
1636
1644
|
const key = `push_${audience}_enabled`;
|
|
1637
1645
|
return settings[key] !== "false" && settings[key] !== "0";
|
|
1638
1646
|
}
|
|
1639
|
-
|
|
1647
|
+
chunkXHPRD45G_cjs.__name(isAudiencePushEnabled, "isAudiencePushEnabled");
|
|
1648
|
+
async function isAudienceWhatsAppEnabled(dataSource, entityMap, audience) {
|
|
1649
|
+
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1650
|
+
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1651
|
+
if (settings.whatsapp_enabled === "false" || settings.whatsapp_enabled === "0") return false;
|
|
1652
|
+
const key = `whatsapp_${audience}_enabled`;
|
|
1653
|
+
return settings[key] !== "false" && settings[key] !== "0";
|
|
1654
|
+
}
|
|
1655
|
+
chunkXHPRD45G_cjs.__name(isAudienceWhatsAppEnabled, "isAudienceWhatsAppEnabled");
|
|
1656
|
+
async function isAudienceSmsEnabled(dataSource, entityMap, audience) {
|
|
1657
|
+
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1658
|
+
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1659
|
+
if (settings.sms_enabled === "false" || settings.sms_enabled === "0") return false;
|
|
1660
|
+
const key = `sms_${audience}_enabled`;
|
|
1661
|
+
return settings[key] !== "false" && settings[key] !== "0";
|
|
1662
|
+
}
|
|
1663
|
+
chunkXHPRD45G_cjs.__name(isAudienceSmsEnabled, "isAudienceSmsEnabled");
|
|
1640
1664
|
async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType, targetId, variables, dataSource, entityMap) {
|
|
1641
1665
|
let template = await loadBoundTemplate(triggerKey, "mobile", audienceType, dataSource, entityMap);
|
|
1642
1666
|
if (!template) {
|
|
1643
1667
|
template = await loadBoundTemplate(triggerKey, "push", audienceType, dataSource, entityMap);
|
|
1644
1668
|
}
|
|
1645
1669
|
if (!template || !template.body) {
|
|
1646
|
-
|
|
1670
|
+
chunkK742UE6S_cjs.notifyLog.skip("PUSH", "no mobile/push template or empty body", {
|
|
1647
1671
|
triggerKey,
|
|
1648
1672
|
orderId,
|
|
1649
1673
|
audienceType,
|
|
@@ -1652,10 +1676,10 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
|
|
|
1652
1676
|
return;
|
|
1653
1677
|
}
|
|
1654
1678
|
const rawTitle = template.subject?.trim() || "Order Notification";
|
|
1655
|
-
const title =
|
|
1656
|
-
const body =
|
|
1679
|
+
const title = chunkCIZZX57T_cjs.applyTemplateVars(rawTitle, variables);
|
|
1680
|
+
const body = chunkCIZZX57T_cjs.applyTemplateVars(template.body, variables);
|
|
1657
1681
|
if (!entityMap.user_device_tokens) {
|
|
1658
|
-
|
|
1682
|
+
chunkK742UE6S_cjs.notifyLog.skip("PUSH", "user_device_tokens entity not registered", {
|
|
1659
1683
|
triggerKey,
|
|
1660
1684
|
orderId,
|
|
1661
1685
|
audienceType
|
|
@@ -1696,7 +1720,7 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
|
|
|
1696
1720
|
});
|
|
1697
1721
|
}
|
|
1698
1722
|
} catch (err) {
|
|
1699
|
-
|
|
1723
|
+
chunkK742UE6S_cjs.notifyLog.error("PUSH", "device token query failed", {
|
|
1700
1724
|
triggerKey,
|
|
1701
1725
|
orderId,
|
|
1702
1726
|
audienceType,
|
|
@@ -1706,17 +1730,17 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
|
|
|
1706
1730
|
return;
|
|
1707
1731
|
}
|
|
1708
1732
|
const tokens = targetTokens.map((t) => t.token?.trim()).filter(Boolean);
|
|
1709
|
-
|
|
1733
|
+
chunkK742UE6S_cjs.notifyLog.push("sending", {
|
|
1710
1734
|
triggerKey,
|
|
1711
1735
|
orderId,
|
|
1712
1736
|
audienceType,
|
|
1713
1737
|
targetId,
|
|
1714
1738
|
title,
|
|
1715
1739
|
tokenCount: tokens.length,
|
|
1716
|
-
fcmTokens: tokens.map((t) =>
|
|
1740
|
+
fcmTokens: tokens.map((t) => chunkK742UE6S_cjs.logFcmToken(t))
|
|
1717
1741
|
});
|
|
1718
1742
|
if (tokens.length === 0) {
|
|
1719
|
-
|
|
1743
|
+
chunkK742UE6S_cjs.notifyLog.skip("PUSH", "no active FCM tokens for target", {
|
|
1720
1744
|
triggerKey,
|
|
1721
1745
|
orderId,
|
|
1722
1746
|
audienceType,
|
|
@@ -1726,12 +1750,12 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
|
|
|
1726
1750
|
return;
|
|
1727
1751
|
}
|
|
1728
1752
|
for (const token of tokens) {
|
|
1729
|
-
|
|
1753
|
+
chunkK742UE6S_cjs.notifyLog.push("FCM target", {
|
|
1730
1754
|
triggerKey,
|
|
1731
1755
|
orderId,
|
|
1732
1756
|
audienceType,
|
|
1733
1757
|
targetId,
|
|
1734
|
-
fcmToken:
|
|
1758
|
+
fcmToken: chunkK742UE6S_cjs.logFcmToken(token)
|
|
1735
1759
|
});
|
|
1736
1760
|
const res = await sendFcmPushNotification(dataSource, entityMap, {
|
|
1737
1761
|
token,
|
|
@@ -1743,25 +1767,25 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
|
|
|
1743
1767
|
}
|
|
1744
1768
|
});
|
|
1745
1769
|
if (res.success) {
|
|
1746
|
-
|
|
1770
|
+
chunkK742UE6S_cjs.notifyLog.push("FCM sent", {
|
|
1747
1771
|
triggerKey,
|
|
1748
1772
|
orderId,
|
|
1749
1773
|
audienceType,
|
|
1750
|
-
fcmToken:
|
|
1774
|
+
fcmToken: chunkK742UE6S_cjs.logFcmToken(token),
|
|
1751
1775
|
messageId: res.messageId ?? null
|
|
1752
1776
|
});
|
|
1753
1777
|
} else {
|
|
1754
|
-
|
|
1778
|
+
chunkK742UE6S_cjs.notifyLog.error("PUSH", "FCM send failed", {
|
|
1755
1779
|
triggerKey,
|
|
1756
1780
|
orderId,
|
|
1757
1781
|
audienceType,
|
|
1758
|
-
fcmToken:
|
|
1782
|
+
fcmToken: chunkK742UE6S_cjs.logFcmToken(token),
|
|
1759
1783
|
error: res.error ?? "unknown"
|
|
1760
1784
|
});
|
|
1761
1785
|
}
|
|
1762
1786
|
}
|
|
1763
1787
|
}
|
|
1764
|
-
|
|
1788
|
+
chunkXHPRD45G_cjs.__name(sendPushNotificationForTrigger, "sendPushNotificationForTrigger");
|
|
1765
1789
|
async function getOrderVendorEmails(orderId, orderVendorId, dataSource, entityMap) {
|
|
1766
1790
|
const emails = /* @__PURE__ */ new Set();
|
|
1767
1791
|
if (!entityMap.vendors) return [];
|
|
@@ -1812,7 +1836,7 @@ async function getOrderVendorEmails(orderId, orderVendorId, dataSource, entityMa
|
|
|
1812
1836
|
}
|
|
1813
1837
|
return Array.from(emails);
|
|
1814
1838
|
}
|
|
1815
|
-
|
|
1839
|
+
chunkXHPRD45G_cjs.__name(getOrderVendorEmails, "getOrderVendorEmails");
|
|
1816
1840
|
async function getAdminRecipientEmails(dataSource, entityMap) {
|
|
1817
1841
|
const emails = /* @__PURE__ */ new Set();
|
|
1818
1842
|
const emailSettings = await getSettingsGroup(dataSource, entityMap, "email");
|
|
@@ -1888,7 +1912,141 @@ async function getAdminRecipientEmails(dataSource, entityMap) {
|
|
|
1888
1912
|
}
|
|
1889
1913
|
return Array.from(emails).filter((e) => !vendorEmails.has(e.toLowerCase()));
|
|
1890
1914
|
}
|
|
1891
|
-
|
|
1915
|
+
chunkXHPRD45G_cjs.__name(getAdminRecipientEmails, "getAdminRecipientEmails");
|
|
1916
|
+
async function getOrderVendorPhones(orderId, orderVendorId, dataSource, entityMap) {
|
|
1917
|
+
const phones = /* @__PURE__ */ new Set();
|
|
1918
|
+
if (!entityMap.vendors) return [];
|
|
1919
|
+
const vendorRepo = dataSource.getRepository(entityMap.vendors);
|
|
1920
|
+
if (orderVendorId) {
|
|
1921
|
+
try {
|
|
1922
|
+
const v = await vendorRepo.findOne({
|
|
1923
|
+
where: {
|
|
1924
|
+
id: orderVendorId
|
|
1925
|
+
}
|
|
1926
|
+
});
|
|
1927
|
+
if (v) {
|
|
1928
|
+
const row = v;
|
|
1929
|
+
if (row.phone?.trim()) phones.add(row.phone.trim());
|
|
1930
|
+
if (row.supportPhone?.trim()) phones.add(row.supportPhone.trim());
|
|
1931
|
+
if (row.mobile?.trim()) phones.add(row.mobile.trim());
|
|
1932
|
+
}
|
|
1933
|
+
} catch {
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
if (entityMap.order_items) {
|
|
1937
|
+
try {
|
|
1938
|
+
const items = await dataSource.getRepository(entityMap.order_items).find({
|
|
1939
|
+
where: {
|
|
1940
|
+
orderId
|
|
1941
|
+
},
|
|
1942
|
+
relations: [
|
|
1943
|
+
"product"
|
|
1944
|
+
]
|
|
1945
|
+
});
|
|
1946
|
+
for (const item of items) {
|
|
1947
|
+
const row = item;
|
|
1948
|
+
const vId = row.product?.vendorId;
|
|
1949
|
+
if (vId && vId !== orderVendorId) {
|
|
1950
|
+
const v = await vendorRepo.findOne({
|
|
1951
|
+
where: {
|
|
1952
|
+
id: vId
|
|
1953
|
+
}
|
|
1954
|
+
});
|
|
1955
|
+
if (v) {
|
|
1956
|
+
const vRow = v;
|
|
1957
|
+
if (vRow.phone?.trim()) phones.add(vRow.phone.trim());
|
|
1958
|
+
if (vRow.supportPhone?.trim()) phones.add(vRow.supportPhone.trim());
|
|
1959
|
+
if (vRow.mobile?.trim()) phones.add(vRow.mobile.trim());
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
} catch {
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return Array.from(phones);
|
|
1967
|
+
}
|
|
1968
|
+
chunkXHPRD45G_cjs.__name(getOrderVendorPhones, "getOrderVendorPhones");
|
|
1969
|
+
async function getAdminRecipientPhones(dataSource, entityMap) {
|
|
1970
|
+
const phones = /* @__PURE__ */ new Set();
|
|
1971
|
+
const [waSettings, smsSettings, storeSettings, brandSettings] = await Promise.all([
|
|
1972
|
+
getSettingsGroup(dataSource, entityMap, "whatsapp"),
|
|
1973
|
+
getSettingsGroup(dataSource, entityMap, "sms"),
|
|
1974
|
+
getSettingsGroup(dataSource, entityMap, "store"),
|
|
1975
|
+
getSettingsGroup(dataSource, entityMap, "branding")
|
|
1976
|
+
]);
|
|
1977
|
+
const rawRecipients = [
|
|
1978
|
+
waSettings.adminPhone,
|
|
1979
|
+
waSettings.adminMobile,
|
|
1980
|
+
waSettings.salesTeamPhone,
|
|
1981
|
+
waSettings.fulfilmentTeamPhone,
|
|
1982
|
+
waSettings.phone,
|
|
1983
|
+
smsSettings.adminPhone,
|
|
1984
|
+
smsSettings.adminMobile,
|
|
1985
|
+
smsSettings.salesTeamPhone,
|
|
1986
|
+
smsSettings.fulfilmentTeamPhone,
|
|
1987
|
+
smsSettings.phone,
|
|
1988
|
+
storeSettings.phone,
|
|
1989
|
+
storeSettings.supportPhone,
|
|
1990
|
+
brandSettings.phone
|
|
1991
|
+
];
|
|
1992
|
+
for (const raw of rawRecipients) {
|
|
1993
|
+
if (!raw) continue;
|
|
1994
|
+
const parts = String(raw).split(/[,;]/);
|
|
1995
|
+
for (const p of parts) {
|
|
1996
|
+
const trimmed = p.trim();
|
|
1997
|
+
if (trimmed && trimmed.length >= 7) phones.add(trimmed);
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
if (entityMap.users) {
|
|
2001
|
+
try {
|
|
2002
|
+
const userRepo = dataSource.getRepository(entityMap.users);
|
|
2003
|
+
const adminUsers = await userRepo.find({
|
|
2004
|
+
where: [
|
|
2005
|
+
{
|
|
2006
|
+
groupId: 1,
|
|
2007
|
+
blocked: false
|
|
2008
|
+
},
|
|
2009
|
+
{
|
|
2010
|
+
adminAccess: true,
|
|
2011
|
+
blocked: false
|
|
2012
|
+
}
|
|
2013
|
+
]
|
|
2014
|
+
});
|
|
2015
|
+
for (const u of adminUsers) {
|
|
2016
|
+
const ph = (u.phone || u.mobile || u.phoneNumber)?.trim();
|
|
2017
|
+
if (ph && ph.length >= 7) {
|
|
2018
|
+
phones.add(ph);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
} catch {
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
try {
|
|
2025
|
+
const rows = await dataSource.query(`SELECT DISTINCT TRIM(COALESCE(phone, mobile, "phoneNumber", '')) AS phone
|
|
2026
|
+
FROM users
|
|
2027
|
+
WHERE ("groupId" = 1 OR "adminAccess" = true)
|
|
2028
|
+
AND COALESCE(blocked, false) = false
|
|
2029
|
+
AND COALESCE(deleted, false) = false
|
|
2030
|
+
AND "deletedAt" IS NULL`);
|
|
2031
|
+
for (const r of rows) {
|
|
2032
|
+
const ph = r.phone?.trim();
|
|
2033
|
+
if (ph && ph.length >= 7) {
|
|
2034
|
+
phones.add(ph);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
} catch {
|
|
2038
|
+
}
|
|
2039
|
+
const vendorPhones = /* @__PURE__ */ new Set();
|
|
2040
|
+
try {
|
|
2041
|
+
const vRows = await dataSource.query(`SELECT DISTINCT TRIM(COALESCE(phone, "supportPhone", mobile, '')) AS phone FROM vendors WHERE COALESCE(deleted, false) = false`).catch(() => []);
|
|
2042
|
+
for (const r of vRows) {
|
|
2043
|
+
if (r.phone && r.phone.length >= 7) vendorPhones.add(r.phone);
|
|
2044
|
+
}
|
|
2045
|
+
} catch {
|
|
2046
|
+
}
|
|
2047
|
+
return Array.from(phones).filter((p) => !vendorPhones.has(p));
|
|
2048
|
+
}
|
|
2049
|
+
chunkXHPRD45G_cjs.__name(getAdminRecipientPhones, "getAdminRecipientPhones");
|
|
1892
2050
|
function formatBodyForEmailHtml(body) {
|
|
1893
2051
|
if (!body) return "";
|
|
1894
2052
|
if (/^\s*<(html|body|table|section)[\s>]/i.test(body.trim())) {
|
|
@@ -1897,15 +2055,15 @@ function formatBodyForEmailHtml(body) {
|
|
|
1897
2055
|
const withBreaks = body.replace(/\r\n/g, "\n").replace(/\n/g, "<br />");
|
|
1898
2056
|
return `<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; font-size: 15px; line-height: 1.6; color: #1f2937;">${withBreaks}</div>`;
|
|
1899
2057
|
}
|
|
1900
|
-
|
|
2058
|
+
chunkXHPRD45G_cjs.__name(formatBodyForEmailHtml, "formatBodyForEmailHtml");
|
|
1901
2059
|
async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables, contactEmail, dataSource, entityMap, getCms) {
|
|
1902
2060
|
const template = await loadBoundTemplate(triggerKey, "email", audienceType, dataSource, entityMap);
|
|
1903
2061
|
if (!template) {
|
|
1904
|
-
|
|
2062
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "no bound/default email template", {
|
|
1905
2063
|
triggerKey,
|
|
1906
2064
|
orderId,
|
|
1907
2065
|
audienceType,
|
|
1908
|
-
to:
|
|
2066
|
+
to: chunkK742UE6S_cjs.maskNotifyEmail(contactEmail)
|
|
1909
2067
|
});
|
|
1910
2068
|
return;
|
|
1911
2069
|
}
|
|
@@ -1914,7 +2072,7 @@ async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables,
|
|
|
1914
2072
|
getSettingsGroup(dataSource, entityMap, "email"),
|
|
1915
2073
|
getSettingsGroup(dataSource, entityMap, "store")
|
|
1916
2074
|
]);
|
|
1917
|
-
const companyDetails =
|
|
2075
|
+
const companyDetails = chunkEYUBL7YH_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings, storeSettings);
|
|
1918
2076
|
const templateContent = (template.body ?? "") + (template.subject ?? "");
|
|
1919
2077
|
const shouldAttachInvoice = /\{\{\s*(invoiceAttachment|invoicePdf|invoice|attachInvoice)\s*\}\}/i.test(templateContent);
|
|
1920
2078
|
const cleanVariables = {
|
|
@@ -1925,15 +2083,15 @@ async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables,
|
|
|
1925
2083
|
attachInvoice: "",
|
|
1926
2084
|
invoiceUrl: ""
|
|
1927
2085
|
};
|
|
1928
|
-
const subject =
|
|
1929
|
-
const rawBody =
|
|
2086
|
+
const subject = chunkCIZZX57T_cjs.applyTemplateVars(template.subject ?? "Order update", cleanVariables);
|
|
2087
|
+
const rawBody = chunkCIZZX57T_cjs.applyTemplateVars(template.body, cleanVariables);
|
|
1930
2088
|
const bodyHtml = formatBodyForEmailHtml(rawBody);
|
|
1931
|
-
const html =
|
|
2089
|
+
const html = chunkQN6PZLAP_cjs.renderLayout({
|
|
1932
2090
|
bodyHtml,
|
|
1933
2091
|
companyDetails
|
|
1934
2092
|
});
|
|
1935
2093
|
const cms = await getCms();
|
|
1936
|
-
await
|
|
2094
|
+
await chunk4MNVIGVJ_cjs.queueEmail(cms, {
|
|
1937
2095
|
to: contactEmail,
|
|
1938
2096
|
subject,
|
|
1939
2097
|
html,
|
|
@@ -1943,31 +2101,33 @@ async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables,
|
|
|
1943
2101
|
attachInvoice: true
|
|
1944
2102
|
} : {}
|
|
1945
2103
|
});
|
|
1946
|
-
|
|
2104
|
+
chunkK742UE6S_cjs.notifyLog.email("queued", {
|
|
1947
2105
|
triggerKey,
|
|
1948
2106
|
audienceType,
|
|
1949
2107
|
orderId,
|
|
1950
|
-
to:
|
|
2108
|
+
to: chunkK742UE6S_cjs.maskNotifyEmail(contactEmail),
|
|
1951
2109
|
subject,
|
|
1952
2110
|
attachInvoice: shouldAttachInvoice
|
|
1953
2111
|
});
|
|
1954
2112
|
}
|
|
1955
|
-
|
|
1956
|
-
async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dataSource, entityMap, getCms) {
|
|
1957
|
-
const template = await loadBoundTemplate(triggerKey, "whatsapp",
|
|
2113
|
+
chunkXHPRD45G_cjs.__name(sendEmailForTrigger, "sendEmailForTrigger");
|
|
2114
|
+
async function sendWhatsAppForTrigger(triggerKey, orderId, audienceType, phone, variables, dataSource, entityMap, getCms) {
|
|
2115
|
+
const template = await loadBoundTemplate(triggerKey, "whatsapp", audienceType, dataSource, entityMap);
|
|
1958
2116
|
if (!template) {
|
|
1959
|
-
|
|
2117
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "no bound/default WhatsApp template", {
|
|
1960
2118
|
triggerKey,
|
|
1961
2119
|
orderId,
|
|
1962
|
-
|
|
2120
|
+
audienceType,
|
|
2121
|
+
phone: chunkK742UE6S_cjs.maskNotifyPhone(phone)
|
|
1963
2122
|
});
|
|
1964
2123
|
return;
|
|
1965
2124
|
}
|
|
1966
2125
|
const paramOrder = template.providerMeta?.paramOrder ?? [];
|
|
1967
2126
|
if (paramOrder.length === 0) {
|
|
1968
|
-
|
|
2127
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "template has no paramOrder \u2014 variables may send blank/wrong", {
|
|
1969
2128
|
triggerKey,
|
|
1970
|
-
orderId
|
|
2129
|
+
orderId,
|
|
2130
|
+
audienceType
|
|
1971
2131
|
});
|
|
1972
2132
|
}
|
|
1973
2133
|
const cms = await getCms();
|
|
@@ -1976,15 +2136,16 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
|
|
|
1976
2136
|
name: template.name
|
|
1977
2137
|
});
|
|
1978
2138
|
if (!metaTemplateName) {
|
|
1979
|
-
|
|
2139
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "template has no Meta template name", {
|
|
1980
2140
|
triggerKey,
|
|
1981
2141
|
orderId,
|
|
1982
|
-
|
|
2142
|
+
audienceType,
|
|
2143
|
+
phone: chunkK742UE6S_cjs.maskNotifyPhone(phone),
|
|
1983
2144
|
templateId: template.id
|
|
1984
2145
|
});
|
|
1985
2146
|
return;
|
|
1986
2147
|
}
|
|
1987
|
-
const sent = await
|
|
2148
|
+
const sent = await chunkKJB5LBFQ_cjs.queueWhatsApp(cms, {
|
|
1988
2149
|
to: phone.trim(),
|
|
1989
2150
|
templateKey: triggerKey,
|
|
1990
2151
|
externalTemplateRef: metaTemplateName,
|
|
@@ -1994,44 +2155,75 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
|
|
|
1994
2155
|
templateParamOrder: paramOrder
|
|
1995
2156
|
});
|
|
1996
2157
|
if (!sent) {
|
|
1997
|
-
|
|
2158
|
+
chunkK742UE6S_cjs.notifyLog.error("WHATSAPP", "send failed / not queued", {
|
|
1998
2159
|
triggerKey,
|
|
1999
2160
|
orderId,
|
|
2000
|
-
|
|
2161
|
+
audienceType,
|
|
2162
|
+
phone: chunkK742UE6S_cjs.maskNotifyPhone(phone),
|
|
2001
2163
|
hint: "Register whatsappPlugin() + queuePlugin() in getCms(), or set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID"
|
|
2002
2164
|
});
|
|
2003
2165
|
} else {
|
|
2004
|
-
|
|
2166
|
+
chunkK742UE6S_cjs.notifyLog.whatsapp("queued/sent", {
|
|
2005
2167
|
triggerKey,
|
|
2006
2168
|
orderId,
|
|
2007
|
-
|
|
2169
|
+
audienceType,
|
|
2170
|
+
phone: chunkK742UE6S_cjs.maskNotifyPhone(phone),
|
|
2008
2171
|
metaTemplateName
|
|
2009
2172
|
});
|
|
2010
2173
|
}
|
|
2011
2174
|
}
|
|
2012
|
-
|
|
2175
|
+
chunkXHPRD45G_cjs.__name(sendWhatsAppForTrigger, "sendWhatsAppForTrigger");
|
|
2176
|
+
async function sendSmsForTrigger(triggerKey, orderId, audienceType, phone, variables, dataSource, entityMap, getCms) {
|
|
2177
|
+
const template = await loadBoundTemplate(triggerKey, "sms", audienceType, dataSource, entityMap);
|
|
2178
|
+
if (!template || !template.body) {
|
|
2179
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "no bound/default SMS template", {
|
|
2180
|
+
triggerKey,
|
|
2181
|
+
orderId,
|
|
2182
|
+
audienceType,
|
|
2183
|
+
phone: chunkK742UE6S_cjs.maskNotifyPhone(phone)
|
|
2184
|
+
});
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2187
|
+
const rawBody = chunkCIZZX57T_cjs.applyTemplateVars(template.body, variables);
|
|
2188
|
+
const cms = await getCms();
|
|
2189
|
+
await chunkKJB5LBFQ_cjs.queueSms(cms, {
|
|
2190
|
+
to: phone.trim(),
|
|
2191
|
+
body: rawBody,
|
|
2192
|
+
templateKey: template.externalTemplateRef || template.name || triggerKey,
|
|
2193
|
+
variables
|
|
2194
|
+
});
|
|
2195
|
+
chunkK742UE6S_cjs.notifyLog.sms("queued/sent", {
|
|
2196
|
+
triggerKey,
|
|
2197
|
+
audienceType,
|
|
2198
|
+
orderId,
|
|
2199
|
+
phone: chunkK742UE6S_cjs.maskNotifyPhone(phone)
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
chunkXHPRD45G_cjs.__name(sendSmsForTrigger, "sendSmsForTrigger");
|
|
2013
2203
|
async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms) {
|
|
2014
|
-
|
|
2204
|
+
chunkK742UE6S_cjs.notifyLog.trigger("dispatcher received", {
|
|
2015
2205
|
triggerKey,
|
|
2016
2206
|
orderId: payload.orderId,
|
|
2017
2207
|
orderNumber: payload.orderNumber,
|
|
2018
|
-
phone:
|
|
2208
|
+
phone: chunkK742UE6S_cjs.maskNotifyPhone(payload.customerPhone),
|
|
2019
2209
|
vendorId: payload.vendorId ?? null
|
|
2020
2210
|
});
|
|
2021
|
-
const [emailChannelEnabled, whatsappChannelEnabled, pushChannelEnabled] = await Promise.all([
|
|
2211
|
+
const [emailChannelEnabled, whatsappChannelEnabled, pushChannelEnabled, smsChannelEnabled] = await Promise.all([
|
|
2022
2212
|
isEmailNotificationsEnabled(dataSource, entityMap),
|
|
2023
2213
|
isWhatsappNotificationsEnabled(dataSource, entityMap),
|
|
2024
|
-
isPushNotificationsEnabled(dataSource, entityMap)
|
|
2214
|
+
isPushNotificationsEnabled(dataSource, entityMap),
|
|
2215
|
+
isSmsNotificationsEnabled(dataSource, entityMap)
|
|
2025
2216
|
]);
|
|
2026
|
-
|
|
2217
|
+
chunkK742UE6S_cjs.notifyLog.trigger("channel switches", {
|
|
2027
2218
|
triggerKey,
|
|
2028
2219
|
orderId: payload.orderId,
|
|
2029
2220
|
email: emailChannelEnabled,
|
|
2030
2221
|
whatsapp: whatsappChannelEnabled,
|
|
2031
|
-
push: pushChannelEnabled
|
|
2222
|
+
push: pushChannelEnabled,
|
|
2223
|
+
sms: smsChannelEnabled
|
|
2032
2224
|
});
|
|
2033
|
-
if (!emailChannelEnabled && !whatsappChannelEnabled && !pushChannelEnabled) {
|
|
2034
|
-
|
|
2225
|
+
if (!emailChannelEnabled && !whatsappChannelEnabled && !pushChannelEnabled && !smsChannelEnabled) {
|
|
2226
|
+
chunkK742UE6S_cjs.notifyLog.skip("ALL", "Email, WhatsApp, Mobile Push, and SMS are disabled in event_notifications", {
|
|
2035
2227
|
triggerKey,
|
|
2036
2228
|
orderId: payload.orderId
|
|
2037
2229
|
});
|
|
@@ -2039,7 +2231,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2039
2231
|
}
|
|
2040
2232
|
const triggerEnabled = await isTriggerCatalogEnabled(triggerKey, dataSource, entityMap);
|
|
2041
2233
|
if (!triggerEnabled) {
|
|
2042
|
-
|
|
2234
|
+
chunkK742UE6S_cjs.notifyLog.skip("TRIGGER", "trigger catalog disabled", {
|
|
2043
2235
|
triggerKey,
|
|
2044
2236
|
orderId: payload.orderId
|
|
2045
2237
|
});
|
|
@@ -2052,11 +2244,11 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2052
2244
|
const variables = mergeTriggerVariables(payload, context?.variables);
|
|
2053
2245
|
const contactEmail = context?.contact.email?.trim() || "";
|
|
2054
2246
|
const contactPhone = context?.contact.phone?.trim() || payload.customerPhone?.trim() || "";
|
|
2055
|
-
|
|
2247
|
+
chunkK742UE6S_cjs.notifyLog.trigger("recipients resolved", {
|
|
2056
2248
|
triggerKey,
|
|
2057
2249
|
orderId: payload.orderId,
|
|
2058
|
-
contactEmail:
|
|
2059
|
-
contactPhone:
|
|
2250
|
+
contactEmail: chunkK742UE6S_cjs.maskNotifyEmail(contactEmail),
|
|
2251
|
+
contactPhone: chunkK742UE6S_cjs.maskNotifyPhone(contactPhone)
|
|
2060
2252
|
});
|
|
2061
2253
|
if (emailChannelEnabled) {
|
|
2062
2254
|
const [customerEnabled, vendorEnabled, adminEnabled] = await Promise.all([
|
|
@@ -2064,7 +2256,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2064
2256
|
isAudienceEmailEnabled(dataSource, entityMap, "vendor"),
|
|
2065
2257
|
isAudienceEmailEnabled(dataSource, entityMap, "admin")
|
|
2066
2258
|
]);
|
|
2067
|
-
|
|
2259
|
+
chunkK742UE6S_cjs.notifyLog.email("audience switches", {
|
|
2068
2260
|
triggerKey,
|
|
2069
2261
|
orderId: payload.orderId,
|
|
2070
2262
|
customer: customerEnabled,
|
|
@@ -2076,7 +2268,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2076
2268
|
if (assigneeEmail) {
|
|
2077
2269
|
await sendEmailForTrigger(triggerKey, payload.orderId, "customers", variables, assigneeEmail, dataSource, entityMap, getCms);
|
|
2078
2270
|
} else {
|
|
2079
|
-
|
|
2271
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "order_assigned_assignee has no assignee email", {
|
|
2080
2272
|
triggerKey,
|
|
2081
2273
|
orderId: payload.orderId
|
|
2082
2274
|
});
|
|
@@ -2084,12 +2276,12 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2084
2276
|
} else if (customerEnabled && contactEmail) {
|
|
2085
2277
|
await sendEmailForTrigger(triggerKey, payload.orderId, "customers", variables, contactEmail, dataSource, entityMap, getCms);
|
|
2086
2278
|
} else if (!customerEnabled) {
|
|
2087
|
-
|
|
2279
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "customer email audience disabled", {
|
|
2088
2280
|
triggerKey,
|
|
2089
2281
|
orderId: payload.orderId
|
|
2090
2282
|
});
|
|
2091
2283
|
} else {
|
|
2092
|
-
|
|
2284
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "no customer email on order contact", {
|
|
2093
2285
|
triggerKey,
|
|
2094
2286
|
orderId: payload.orderId
|
|
2095
2287
|
});
|
|
@@ -2099,7 +2291,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2099
2291
|
if (multiVendorSettings.enabled !== "false" && multiVendorSettings.enabled !== "0") {
|
|
2100
2292
|
const vendorEmails = await getOrderVendorEmails(payload.orderId, payload.vendorId, dataSource, entityMap);
|
|
2101
2293
|
if (vendorEmails.length === 0) {
|
|
2102
|
-
|
|
2294
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "no vendor emails for order", {
|
|
2103
2295
|
triggerKey,
|
|
2104
2296
|
orderId: payload.orderId,
|
|
2105
2297
|
vendorId: payload.vendorId ?? null
|
|
@@ -2109,7 +2301,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2109
2301
|
await sendEmailForTrigger(triggerKey, payload.orderId, "vendors", variables, vEmail, dataSource, entityMap, getCms);
|
|
2110
2302
|
}
|
|
2111
2303
|
} else {
|
|
2112
|
-
|
|
2304
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "multi-vendor off \u2014 skip vendor email", {
|
|
2113
2305
|
triggerKey,
|
|
2114
2306
|
orderId: payload.orderId
|
|
2115
2307
|
});
|
|
@@ -2118,7 +2310,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2118
2310
|
if (adminEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2119
2311
|
const adminEmails = await getAdminRecipientEmails(dataSource, entityMap);
|
|
2120
2312
|
if (adminEmails.length === 0) {
|
|
2121
|
-
|
|
2313
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "no admin recipient emails", {
|
|
2122
2314
|
triggerKey,
|
|
2123
2315
|
orderId: payload.orderId
|
|
2124
2316
|
});
|
|
@@ -2128,7 +2320,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2128
2320
|
}
|
|
2129
2321
|
}
|
|
2130
2322
|
} else {
|
|
2131
|
-
|
|
2323
|
+
chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "email channel disabled", {
|
|
2132
2324
|
triggerKey,
|
|
2133
2325
|
orderId: payload.orderId
|
|
2134
2326
|
});
|
|
@@ -2139,7 +2331,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2139
2331
|
isAudiencePushEnabled(dataSource, entityMap, "vendor"),
|
|
2140
2332
|
isAudiencePushEnabled(dataSource, entityMap, "admin")
|
|
2141
2333
|
]);
|
|
2142
|
-
|
|
2334
|
+
chunkK742UE6S_cjs.notifyLog.push("audience switches", {
|
|
2143
2335
|
triggerKey,
|
|
2144
2336
|
orderId: payload.orderId,
|
|
2145
2337
|
customer: pushCustomerEnabled,
|
|
@@ -2150,12 +2342,12 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2150
2342
|
if (pushCustomerEnabled && targetCustomerId) {
|
|
2151
2343
|
await sendPushNotificationForTrigger(triggerKey, payload.orderId, "customers", String(targetCustomerId), variables, dataSource, entityMap);
|
|
2152
2344
|
} else if (!pushCustomerEnabled) {
|
|
2153
|
-
|
|
2345
|
+
chunkK742UE6S_cjs.notifyLog.skip("PUSH", "customer push audience disabled", {
|
|
2154
2346
|
triggerKey,
|
|
2155
2347
|
orderId: payload.orderId
|
|
2156
2348
|
});
|
|
2157
2349
|
} else {
|
|
2158
|
-
|
|
2350
|
+
chunkK742UE6S_cjs.notifyLog.skip("PUSH", "no customer user/contact id for push", {
|
|
2159
2351
|
triggerKey,
|
|
2160
2352
|
orderId: payload.orderId
|
|
2161
2353
|
});
|
|
@@ -2163,7 +2355,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2163
2355
|
if (pushVendorEnabled && payload.vendorId && triggerKey !== "order_assigned_assignee") {
|
|
2164
2356
|
await sendPushNotificationForTrigger(triggerKey, payload.orderId, "vendors", String(payload.vendorId), variables, dataSource, entityMap);
|
|
2165
2357
|
} else if (pushVendorEnabled && triggerKey !== "order_assigned_assignee" && !payload.vendorId) {
|
|
2166
|
-
|
|
2358
|
+
chunkK742UE6S_cjs.notifyLog.skip("PUSH", "no vendorId on order \u2014 skip vendor push", {
|
|
2167
2359
|
triggerKey,
|
|
2168
2360
|
orderId: payload.orderId
|
|
2169
2361
|
});
|
|
@@ -2172,29 +2364,163 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2172
2364
|
await sendPushNotificationForTrigger(triggerKey, payload.orderId, "admin", "admin", variables, dataSource, entityMap);
|
|
2173
2365
|
}
|
|
2174
2366
|
} else {
|
|
2175
|
-
|
|
2367
|
+
chunkK742UE6S_cjs.notifyLog.skip("PUSH", "push channel disabled", {
|
|
2176
2368
|
triggerKey,
|
|
2177
2369
|
orderId: payload.orderId
|
|
2178
2370
|
});
|
|
2179
2371
|
}
|
|
2180
2372
|
if (whatsappChannelEnabled) {
|
|
2181
|
-
const
|
|
2182
|
-
|
|
2183
|
-
|
|
2373
|
+
const [waCustomerEnabled, waVendorEnabled, waAdminEnabled] = await Promise.all([
|
|
2374
|
+
isAudienceWhatsAppEnabled(dataSource, entityMap, "customer"),
|
|
2375
|
+
isAudienceWhatsAppEnabled(dataSource, entityMap, "vendor"),
|
|
2376
|
+
isAudienceWhatsAppEnabled(dataSource, entityMap, "admin")
|
|
2377
|
+
]);
|
|
2378
|
+
chunkK742UE6S_cjs.notifyLog.whatsapp("audience switches", {
|
|
2379
|
+
triggerKey,
|
|
2380
|
+
orderId: payload.orderId,
|
|
2381
|
+
customer: waCustomerEnabled,
|
|
2382
|
+
vendor: waVendorEnabled,
|
|
2383
|
+
admin: waAdminEnabled
|
|
2384
|
+
});
|
|
2385
|
+
if (triggerKey === "order_assigned_assignee") {
|
|
2386
|
+
const assigneePhone = context?.order?.assignedUser?.phone?.trim();
|
|
2387
|
+
if (assigneePhone) {
|
|
2388
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "customers", assigneePhone, variables, dataSource, entityMap, getCms);
|
|
2389
|
+
} else {
|
|
2390
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "order_assigned_assignee has no assignee phone", {
|
|
2391
|
+
triggerKey,
|
|
2392
|
+
orderId: payload.orderId
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2395
|
+
} else if (waCustomerEnabled && contactPhone) {
|
|
2396
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "customers", contactPhone, variables, dataSource, entityMap, getCms);
|
|
2397
|
+
} else if (!waCustomerEnabled) {
|
|
2398
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "customer WhatsApp audience disabled", {
|
|
2399
|
+
triggerKey,
|
|
2400
|
+
orderId: payload.orderId
|
|
2401
|
+
});
|
|
2184
2402
|
} else {
|
|
2185
|
-
|
|
2403
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "no customer phone on order contact", {
|
|
2186
2404
|
triggerKey,
|
|
2187
2405
|
orderId: payload.orderId
|
|
2188
2406
|
});
|
|
2189
2407
|
}
|
|
2408
|
+
if (waVendorEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2409
|
+
const multiVendorSettings = await getSettingsGroup(dataSource, entityMap, "multi_vendor");
|
|
2410
|
+
if (multiVendorSettings.enabled !== "false" && multiVendorSettings.enabled !== "0") {
|
|
2411
|
+
const vendorPhones = await getOrderVendorPhones(payload.orderId, payload.vendorId, dataSource, entityMap);
|
|
2412
|
+
if (vendorPhones.length === 0) {
|
|
2413
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "no vendor phones for order", {
|
|
2414
|
+
triggerKey,
|
|
2415
|
+
orderId: payload.orderId,
|
|
2416
|
+
vendorId: payload.vendorId ?? null
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
for (const vPhone of vendorPhones) {
|
|
2420
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "vendors", vPhone, variables, dataSource, entityMap, getCms);
|
|
2421
|
+
}
|
|
2422
|
+
} else {
|
|
2423
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "multi-vendor off \u2014 skip vendor WhatsApp", {
|
|
2424
|
+
triggerKey,
|
|
2425
|
+
orderId: payload.orderId
|
|
2426
|
+
});
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
if (waAdminEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2430
|
+
const adminPhones = await getAdminRecipientPhones(dataSource, entityMap);
|
|
2431
|
+
if (adminPhones.length === 0) {
|
|
2432
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "no admin recipient phones", {
|
|
2433
|
+
triggerKey,
|
|
2434
|
+
orderId: payload.orderId
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
2437
|
+
for (const aPhone of adminPhones) {
|
|
2438
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "admin", aPhone, variables, dataSource, entityMap, getCms);
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
} else {
|
|
2442
|
+
chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "WhatsApp channel disabled", {
|
|
2443
|
+
triggerKey,
|
|
2444
|
+
orderId: payload.orderId
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
if (smsChannelEnabled) {
|
|
2448
|
+
const [smsCustomerEnabled, smsVendorEnabled, smsAdminEnabled] = await Promise.all([
|
|
2449
|
+
isAudienceSmsEnabled(dataSource, entityMap, "customer"),
|
|
2450
|
+
isAudienceSmsEnabled(dataSource, entityMap, "vendor"),
|
|
2451
|
+
isAudienceSmsEnabled(dataSource, entityMap, "admin")
|
|
2452
|
+
]);
|
|
2453
|
+
chunkK742UE6S_cjs.notifyLog.sms("audience switches", {
|
|
2454
|
+
triggerKey,
|
|
2455
|
+
orderId: payload.orderId,
|
|
2456
|
+
customer: smsCustomerEnabled,
|
|
2457
|
+
vendor: smsVendorEnabled,
|
|
2458
|
+
admin: smsAdminEnabled
|
|
2459
|
+
});
|
|
2460
|
+
if (triggerKey === "order_assigned_assignee") {
|
|
2461
|
+
const assigneePhone = context?.order?.assignedUser?.phone?.trim();
|
|
2462
|
+
if (assigneePhone) {
|
|
2463
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "customers", assigneePhone, variables, dataSource, entityMap, getCms);
|
|
2464
|
+
} else {
|
|
2465
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "order_assigned_assignee has no assignee phone", {
|
|
2466
|
+
triggerKey,
|
|
2467
|
+
orderId: payload.orderId
|
|
2468
|
+
});
|
|
2469
|
+
}
|
|
2470
|
+
} else if (smsCustomerEnabled && contactPhone) {
|
|
2471
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "customers", contactPhone, variables, dataSource, entityMap, getCms);
|
|
2472
|
+
} else if (!smsCustomerEnabled) {
|
|
2473
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "customer SMS audience disabled", {
|
|
2474
|
+
triggerKey,
|
|
2475
|
+
orderId: payload.orderId
|
|
2476
|
+
});
|
|
2477
|
+
} else {
|
|
2478
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "no customer phone on order contact", {
|
|
2479
|
+
triggerKey,
|
|
2480
|
+
orderId: payload.orderId
|
|
2481
|
+
});
|
|
2482
|
+
}
|
|
2483
|
+
if (smsVendorEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2484
|
+
const multiVendorSettings = await getSettingsGroup(dataSource, entityMap, "multi_vendor");
|
|
2485
|
+
if (multiVendorSettings.enabled !== "false" && multiVendorSettings.enabled !== "0") {
|
|
2486
|
+
const vendorPhones = await getOrderVendorPhones(payload.orderId, payload.vendorId, dataSource, entityMap);
|
|
2487
|
+
if (vendorPhones.length === 0) {
|
|
2488
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "no vendor phones for order", {
|
|
2489
|
+
triggerKey,
|
|
2490
|
+
orderId: payload.orderId,
|
|
2491
|
+
vendorId: payload.vendorId ?? null
|
|
2492
|
+
});
|
|
2493
|
+
}
|
|
2494
|
+
for (const vPhone of vendorPhones) {
|
|
2495
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "vendors", vPhone, variables, dataSource, entityMap, getCms);
|
|
2496
|
+
}
|
|
2497
|
+
} else {
|
|
2498
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "multi-vendor off \u2014 skip vendor SMS", {
|
|
2499
|
+
triggerKey,
|
|
2500
|
+
orderId: payload.orderId
|
|
2501
|
+
});
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
if (smsAdminEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2505
|
+
const adminPhones = await getAdminRecipientPhones(dataSource, entityMap);
|
|
2506
|
+
if (adminPhones.length === 0) {
|
|
2507
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "no admin recipient phones", {
|
|
2508
|
+
triggerKey,
|
|
2509
|
+
orderId: payload.orderId
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
for (const aPhone of adminPhones) {
|
|
2513
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "admin", aPhone, variables, dataSource, entityMap, getCms);
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2190
2516
|
} else {
|
|
2191
|
-
|
|
2517
|
+
chunkK742UE6S_cjs.notifyLog.skip("SMS", "SMS channel disabled", {
|
|
2192
2518
|
triggerKey,
|
|
2193
2519
|
orderId: payload.orderId
|
|
2194
2520
|
});
|
|
2195
2521
|
}
|
|
2196
2522
|
}
|
|
2197
|
-
|
|
2523
|
+
chunkXHPRD45G_cjs.__name(handleTrigger, "handleTrigger");
|
|
2198
2524
|
var globalGetCms = null;
|
|
2199
2525
|
function initWhatsappTriggerDispatcher(deps) {
|
|
2200
2526
|
if (deps?.getCms) globalGetCms = deps.getCms;
|
|
@@ -2203,9 +2529,11 @@ function initWhatsappTriggerDispatcher(deps) {
|
|
|
2203
2529
|
const { dataSource, entityMap, getCms } = deps;
|
|
2204
2530
|
void dataSource.query(`ALTER TYPE "order_notification_bindings_channel_enum" ADD VALUE IF NOT EXISTS 'mobile'`).catch(() => {
|
|
2205
2531
|
});
|
|
2206
|
-
|
|
2532
|
+
void dataSource.query(`ALTER TYPE "order_notification_bindings_channel_enum" ADD VALUE IF NOT EXISTS 'sms'`).catch(() => {
|
|
2533
|
+
});
|
|
2534
|
+
chunkK742UE6S_cjs.notificationTriggerEmitter.onAnyTrigger((triggerKey, payload) => {
|
|
2207
2535
|
void handleTrigger(triggerKey, payload, dataSource, entityMap, getCms).catch((err) => {
|
|
2208
|
-
|
|
2536
|
+
chunkK742UE6S_cjs.notifyLog.error("TRIGGER", "dispatcher handleTrigger failed", {
|
|
2209
2537
|
triggerKey,
|
|
2210
2538
|
orderId: payload.orderId,
|
|
2211
2539
|
error: err instanceof Error ? err.message : String(err),
|
|
@@ -2213,35 +2541,37 @@ function initWhatsappTriggerDispatcher(deps) {
|
|
|
2213
2541
|
});
|
|
2214
2542
|
});
|
|
2215
2543
|
});
|
|
2216
|
-
|
|
2544
|
+
chunkK742UE6S_cjs.notifyLog.trigger("dispatcher initialized", {
|
|
2217
2545
|
channels: [
|
|
2218
2546
|
"email",
|
|
2219
2547
|
"whatsapp",
|
|
2220
|
-
"push"
|
|
2548
|
+
"push",
|
|
2549
|
+
"sms"
|
|
2221
2550
|
]
|
|
2222
2551
|
});
|
|
2223
2552
|
}
|
|
2224
|
-
|
|
2553
|
+
chunkXHPRD45G_cjs.__name(initWhatsappTriggerDispatcher, "initWhatsappTriggerDispatcher");
|
|
2225
2554
|
async function dispatchOrderNotificationDirectly(triggerKey, payload, dataSource, entityMap, getCms) {
|
|
2226
2555
|
const cmsResolver = getCms ?? globalGetCms ?? (async () => ({
|
|
2227
|
-
getPlugin: /* @__PURE__ */
|
|
2556
|
+
getPlugin: /* @__PURE__ */ chunkXHPRD45G_cjs.__name(() => null, "getPlugin")
|
|
2228
2557
|
}));
|
|
2229
2558
|
await handleTrigger(triggerKey, payload, dataSource, entityMap, cmsResolver);
|
|
2230
2559
|
}
|
|
2231
|
-
|
|
2560
|
+
chunkXHPRD45G_cjs.__name(dispatchOrderNotificationDirectly, "dispatchOrderNotificationDirectly");
|
|
2232
2561
|
async function resendOrderNotification(triggerKey, orderId, deps) {
|
|
2233
2562
|
if (!deps.entityMap.orders) return {
|
|
2234
2563
|
ok: false,
|
|
2235
2564
|
error: "orders entity missing"
|
|
2236
2565
|
};
|
|
2237
|
-
const [emailEnabled, whatsappEnabled] = await Promise.all([
|
|
2566
|
+
const [emailEnabled, whatsappEnabled, smsEnabled] = await Promise.all([
|
|
2238
2567
|
isEmailNotificationsEnabled(deps.dataSource, deps.entityMap),
|
|
2239
|
-
isWhatsappNotificationsEnabled(deps.dataSource, deps.entityMap)
|
|
2568
|
+
isWhatsappNotificationsEnabled(deps.dataSource, deps.entityMap),
|
|
2569
|
+
isSmsNotificationsEnabled(deps.dataSource, deps.entityMap)
|
|
2240
2570
|
]);
|
|
2241
|
-
if (!emailEnabled && !whatsappEnabled) {
|
|
2571
|
+
if (!emailEnabled && !whatsappEnabled && !smsEnabled) {
|
|
2242
2572
|
return {
|
|
2243
2573
|
ok: false,
|
|
2244
|
-
error: "
|
|
2574
|
+
error: "Email, WhatsApp, and SMS notifications are all disabled"
|
|
2245
2575
|
};
|
|
2246
2576
|
}
|
|
2247
2577
|
const triggerEnabled = await isTriggerCatalogEnabled(triggerKey, deps.dataSource, deps.entityMap);
|
|
@@ -2278,7 +2608,7 @@ async function resendOrderNotification(triggerKey, orderId, deps) {
|
|
|
2278
2608
|
ok: true
|
|
2279
2609
|
};
|
|
2280
2610
|
}
|
|
2281
|
-
|
|
2611
|
+
chunkXHPRD45G_cjs.__name(resendOrderNotification, "resendOrderNotification");
|
|
2282
2612
|
async function emitOrderNotificationTrigger(dataSource, entityMap, triggerKey, payload) {
|
|
2283
2613
|
try {
|
|
2284
2614
|
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
@@ -2287,7 +2617,7 @@ async function emitOrderNotificationTrigger(dataSource, entityMap, triggerKey, p
|
|
|
2287
2617
|
if (settings.whatsapp_enabled !== "false" && settings.whatsapp_enabled !== "0") enabledChannels.push("whatsapp");
|
|
2288
2618
|
if (settings.sms_enabled !== "false" && settings.sms_enabled !== "0") enabledChannels.push("sms");
|
|
2289
2619
|
if (settings.push_enabled !== "false" && settings.push_enabled !== "0") enabledChannels.push("push");
|
|
2290
|
-
|
|
2620
|
+
chunkK742UE6S_cjs.notificationTriggerEmitter.emitTrigger(triggerKey, payload);
|
|
2291
2621
|
return {
|
|
2292
2622
|
ok: true,
|
|
2293
2623
|
channels: enabledChannels
|
|
@@ -2299,7 +2629,7 @@ async function emitOrderNotificationTrigger(dataSource, entityMap, triggerKey, p
|
|
|
2299
2629
|
};
|
|
2300
2630
|
}
|
|
2301
2631
|
}
|
|
2302
|
-
|
|
2632
|
+
chunkXHPRD45G_cjs.__name(emitOrderNotificationTrigger, "emitOrderNotificationTrigger");
|
|
2303
2633
|
|
|
2304
2634
|
exports.CHAT_EMAIL_LOG = CHAT_EMAIL_LOG;
|
|
2305
2635
|
exports.WhatsAppService = WhatsAppService;
|