@infuro/cms-core 1.0.69 → 1.0.71
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/admin.cjs +2834 -2683
- package/dist/admin.js +1593 -1442
- package/dist/api.cjs +41 -41
- package/dist/api.js +8 -8
- package/dist/auth.cjs +51 -51
- package/dist/auth.js +3 -3
- package/dist/{chunk-RBKVMHBH.js → chunk-3LF4RYAJ.js} +353 -23
- package/dist/{chunk-DBBYLSQP.js → chunk-7NQMGB2S.js} +136 -25
- package/dist/{chunk-DWNQTFJ5.js → chunk-CJY2HUJC.js} +19 -19
- package/dist/{chunk-SWSTGV4F.cjs → chunk-CKTRA3Q2.cjs} +9 -9
- package/dist/{chunk-53AMBXMM.js → chunk-ECUGNV2I.js} +1 -57
- package/dist/{chunk-QXAQ3V7R.cjs → chunk-FNLF6G2N.cjs} +7 -7
- package/dist/{chunk-T47VP2ZT.js → chunk-HZZTDM5J.js} +2 -2
- package/dist/{chunk-3XCTGADT.js → chunk-K6JT7BKY.js} +58 -1
- package/dist/{chunk-M5QDJOUP.cjs → chunk-K742UE6S.cjs} +1 -0
- package/dist/{chunk-6MM5OMRL.cjs → chunk-KB7EBYPR.cjs} +0 -58
- package/dist/{chunk-OXFC3DAM.cjs → chunk-KJB5LBFQ.cjs} +59 -0
- package/dist/{chunk-LXWF6T7F.cjs → chunk-LCZZ3S4I.cjs} +19 -19
- package/dist/{chunk-HGR4IA7I.cjs → chunk-NIBEGDD4.cjs} +15 -15
- package/dist/{chunk-D4LR3S77.js → chunk-NQF6H656.js} +1 -1
- package/dist/{chunk-QL44NCZC.cjs → chunk-OP624LWU.cjs} +222 -111
- package/dist/{chunk-MJDNS324.js → chunk-SCE2GIKH.js} +2 -2
- package/dist/{chunk-747MJJCZ.cjs → chunk-TTOEY7AH.cjs} +404 -74
- package/dist/{chunk-WHMIWJL7.js → chunk-W2ZTGLUH.js} +1 -0
- package/dist/{emit-order-notification-trigger-X36V4DOH.cjs → emit-order-notification-trigger-I4HQSTEN.cjs} +4 -4
- package/dist/{emit-order-notification-trigger-XKN2TWVF.js → emit-order-notification-trigger-TBXAZAPS.js} +2 -2
- package/dist/index.cjs +330 -330
- package/dist/index.js +13 -13
- package/dist/{order-assignees-handlers-JEJ5IDID.cjs → order-assignees-handlers-E6PQZP4H.cjs} +22 -3
- package/dist/{order-assignees-handlers-F7WOZHOG.js → order-assignees-handlers-YCT3Q3KC.js} +22 -3
- package/dist/{order-completion-otp-handlers-LNAZTMTS.cjs → order-completion-otp-handlers-2ZKRK5SN.cjs} +10 -10
- package/dist/{order-completion-otp-handlers-FIW7PZ6W.js → order-completion-otp-handlers-KHLZQQJX.js} +4 -4
- package/dist/{order-notification-dispatcher-GG5C4LKZ.cjs → order-notification-dispatcher-37KDVHBM.cjs} +8 -8
- package/dist/{order-notification-dispatcher-FS54ANAV.js → order-notification-dispatcher-Z3MXNF4U.js} +3 -3
- package/dist/{rbac-debug-db-IRKT6G62.js → rbac-debug-db-JK3U5UZK.js} +1 -1
- package/dist/{rbac-debug-db-2ZI3XKA4.cjs → rbac-debug-db-S3D6N6HN.cjs} +2 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { queueWhatsApp } from './chunk-
|
|
2
|
-
import { notifyLog, logFcmToken, maskNotifyEmail, maskNotifyPhone, notificationTriggerEmitter } from './chunk-
|
|
1
|
+
import { queueWhatsApp, queueSms } from './chunk-K6JT7BKY.js';
|
|
2
|
+
import { notifyLog, logFcmToken, maskNotifyEmail, maskNotifyPhone, notificationTriggerEmitter } from './chunk-W2ZTGLUH.js';
|
|
3
3
|
import { applyTemplateVars } from './chunk-ECNYZG6T.js';
|
|
4
4
|
import { sesRegionSupportsSmtp, sesSmtpHost, EmailService, renderLayout } from './chunk-CFUSYGSA.js';
|
|
5
5
|
import { queueEmail } from './chunk-LJ5C4RBF.js';
|
|
@@ -385,7 +385,10 @@ function whatsAppConfigured(config) {
|
|
|
385
385
|
}
|
|
386
386
|
__name(whatsAppConfigured, "whatsAppConfigured");
|
|
387
387
|
function normalizeWhatsAppRecipient(to) {
|
|
388
|
-
|
|
388
|
+
let digits = to.replace(/\D/g, "");
|
|
389
|
+
if (digits.length === 10) {
|
|
390
|
+
digits = `91${digits}`;
|
|
391
|
+
}
|
|
389
392
|
return digits;
|
|
390
393
|
}
|
|
391
394
|
__name(normalizeWhatsAppRecipient, "normalizeWhatsAppRecipient");
|
|
@@ -482,9 +485,8 @@ var WhatsAppService = class {
|
|
|
482
485
|
const { applyTemplateVars: applyTemplateVars2 } = await import('./interpolate-KD37IRF2.js');
|
|
483
486
|
if (body) body = applyTemplateVars2(body, variables);
|
|
484
487
|
if (templateName) {
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
] : [];
|
|
488
|
+
const isHelloWorld = templateName === "hello_world";
|
|
489
|
+
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)) : [];
|
|
488
490
|
logWhatsApp("info", "sending template message", {
|
|
489
491
|
to: maskPhone(to),
|
|
490
492
|
templateName,
|
|
@@ -1427,6 +1429,12 @@ async function isWhatsappNotificationsEnabled(dataSource, entityMap) {
|
|
|
1427
1429
|
return settings.whatsapp_enabled !== "false" && settings.whatsapp_enabled !== "0";
|
|
1428
1430
|
}
|
|
1429
1431
|
__name(isWhatsappNotificationsEnabled, "isWhatsappNotificationsEnabled");
|
|
1432
|
+
async function isSmsNotificationsEnabled(dataSource, entityMap) {
|
|
1433
|
+
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1434
|
+
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1435
|
+
return settings.sms_enabled !== "false" && settings.sms_enabled !== "0";
|
|
1436
|
+
}
|
|
1437
|
+
__name(isSmsNotificationsEnabled, "isSmsNotificationsEnabled");
|
|
1430
1438
|
async function isTriggerCatalogEnabled(triggerKey, dataSource, entityMap) {
|
|
1431
1439
|
if (!entityMap.order_notification_triggers) {
|
|
1432
1440
|
return true;
|
|
@@ -1615,6 +1623,22 @@ async function isAudiencePushEnabled(dataSource, entityMap, audience) {
|
|
|
1615
1623
|
return settings[key] !== "false" && settings[key] !== "0";
|
|
1616
1624
|
}
|
|
1617
1625
|
__name(isAudiencePushEnabled, "isAudiencePushEnabled");
|
|
1626
|
+
async function isAudienceWhatsAppEnabled(dataSource, entityMap, audience) {
|
|
1627
|
+
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1628
|
+
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1629
|
+
if (settings.whatsapp_enabled === "false" || settings.whatsapp_enabled === "0") return false;
|
|
1630
|
+
const key = `whatsapp_${audience}_enabled`;
|
|
1631
|
+
return settings[key] !== "false" && settings[key] !== "0";
|
|
1632
|
+
}
|
|
1633
|
+
__name(isAudienceWhatsAppEnabled, "isAudienceWhatsAppEnabled");
|
|
1634
|
+
async function isAudienceSmsEnabled(dataSource, entityMap, audience) {
|
|
1635
|
+
const settings = await getSettingsGroup(dataSource, entityMap, "event_notifications");
|
|
1636
|
+
if (settings.enabled === "false" || settings.enabled === "0") return false;
|
|
1637
|
+
if (settings.sms_enabled === "false" || settings.sms_enabled === "0") return false;
|
|
1638
|
+
const key = `sms_${audience}_enabled`;
|
|
1639
|
+
return settings[key] !== "false" && settings[key] !== "0";
|
|
1640
|
+
}
|
|
1641
|
+
__name(isAudienceSmsEnabled, "isAudienceSmsEnabled");
|
|
1618
1642
|
async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType, targetId, variables, dataSource, entityMap) {
|
|
1619
1643
|
let template = await loadBoundTemplate(triggerKey, "mobile", audienceType, dataSource, entityMap);
|
|
1620
1644
|
if (!template) {
|
|
@@ -1867,6 +1891,140 @@ async function getAdminRecipientEmails(dataSource, entityMap) {
|
|
|
1867
1891
|
return Array.from(emails).filter((e) => !vendorEmails.has(e.toLowerCase()));
|
|
1868
1892
|
}
|
|
1869
1893
|
__name(getAdminRecipientEmails, "getAdminRecipientEmails");
|
|
1894
|
+
async function getOrderVendorPhones(orderId, orderVendorId, dataSource, entityMap) {
|
|
1895
|
+
const phones = /* @__PURE__ */ new Set();
|
|
1896
|
+
if (!entityMap.vendors) return [];
|
|
1897
|
+
const vendorRepo = dataSource.getRepository(entityMap.vendors);
|
|
1898
|
+
if (orderVendorId) {
|
|
1899
|
+
try {
|
|
1900
|
+
const v = await vendorRepo.findOne({
|
|
1901
|
+
where: {
|
|
1902
|
+
id: orderVendorId
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
if (v) {
|
|
1906
|
+
const row = v;
|
|
1907
|
+
if (row.phone?.trim()) phones.add(row.phone.trim());
|
|
1908
|
+
if (row.supportPhone?.trim()) phones.add(row.supportPhone.trim());
|
|
1909
|
+
if (row.mobile?.trim()) phones.add(row.mobile.trim());
|
|
1910
|
+
}
|
|
1911
|
+
} catch {
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
if (entityMap.order_items) {
|
|
1915
|
+
try {
|
|
1916
|
+
const items = await dataSource.getRepository(entityMap.order_items).find({
|
|
1917
|
+
where: {
|
|
1918
|
+
orderId
|
|
1919
|
+
},
|
|
1920
|
+
relations: [
|
|
1921
|
+
"product"
|
|
1922
|
+
]
|
|
1923
|
+
});
|
|
1924
|
+
for (const item of items) {
|
|
1925
|
+
const row = item;
|
|
1926
|
+
const vId = row.product?.vendorId;
|
|
1927
|
+
if (vId && vId !== orderVendorId) {
|
|
1928
|
+
const v = await vendorRepo.findOne({
|
|
1929
|
+
where: {
|
|
1930
|
+
id: vId
|
|
1931
|
+
}
|
|
1932
|
+
});
|
|
1933
|
+
if (v) {
|
|
1934
|
+
const vRow = v;
|
|
1935
|
+
if (vRow.phone?.trim()) phones.add(vRow.phone.trim());
|
|
1936
|
+
if (vRow.supportPhone?.trim()) phones.add(vRow.supportPhone.trim());
|
|
1937
|
+
if (vRow.mobile?.trim()) phones.add(vRow.mobile.trim());
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
} catch {
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return Array.from(phones);
|
|
1945
|
+
}
|
|
1946
|
+
__name(getOrderVendorPhones, "getOrderVendorPhones");
|
|
1947
|
+
async function getAdminRecipientPhones(dataSource, entityMap) {
|
|
1948
|
+
const phones = /* @__PURE__ */ new Set();
|
|
1949
|
+
const [waSettings, smsSettings, storeSettings, brandSettings] = await Promise.all([
|
|
1950
|
+
getSettingsGroup(dataSource, entityMap, "whatsapp"),
|
|
1951
|
+
getSettingsGroup(dataSource, entityMap, "sms"),
|
|
1952
|
+
getSettingsGroup(dataSource, entityMap, "store"),
|
|
1953
|
+
getSettingsGroup(dataSource, entityMap, "branding")
|
|
1954
|
+
]);
|
|
1955
|
+
const rawRecipients = [
|
|
1956
|
+
waSettings.adminPhone,
|
|
1957
|
+
waSettings.adminMobile,
|
|
1958
|
+
waSettings.salesTeamPhone,
|
|
1959
|
+
waSettings.fulfilmentTeamPhone,
|
|
1960
|
+
waSettings.phone,
|
|
1961
|
+
smsSettings.adminPhone,
|
|
1962
|
+
smsSettings.adminMobile,
|
|
1963
|
+
smsSettings.salesTeamPhone,
|
|
1964
|
+
smsSettings.fulfilmentTeamPhone,
|
|
1965
|
+
smsSettings.phone,
|
|
1966
|
+
storeSettings.phone,
|
|
1967
|
+
storeSettings.supportPhone,
|
|
1968
|
+
brandSettings.phone
|
|
1969
|
+
];
|
|
1970
|
+
for (const raw of rawRecipients) {
|
|
1971
|
+
if (!raw) continue;
|
|
1972
|
+
const parts = String(raw).split(/[,;]/);
|
|
1973
|
+
for (const p of parts) {
|
|
1974
|
+
const trimmed = p.trim();
|
|
1975
|
+
if (trimmed && trimmed.length >= 7) phones.add(trimmed);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
if (entityMap.users) {
|
|
1979
|
+
try {
|
|
1980
|
+
const userRepo = dataSource.getRepository(entityMap.users);
|
|
1981
|
+
const adminUsers = await userRepo.find({
|
|
1982
|
+
where: [
|
|
1983
|
+
{
|
|
1984
|
+
groupId: 1,
|
|
1985
|
+
blocked: false
|
|
1986
|
+
},
|
|
1987
|
+
{
|
|
1988
|
+
adminAccess: true,
|
|
1989
|
+
blocked: false
|
|
1990
|
+
}
|
|
1991
|
+
]
|
|
1992
|
+
});
|
|
1993
|
+
for (const u of adminUsers) {
|
|
1994
|
+
const ph = (u.phone || u.mobile || u.phoneNumber)?.trim();
|
|
1995
|
+
if (ph && ph.length >= 7) {
|
|
1996
|
+
phones.add(ph);
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
} catch {
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
try {
|
|
2003
|
+
const rows = await dataSource.query(`SELECT DISTINCT TRIM(COALESCE(phone, mobile, "phoneNumber", '')) AS phone
|
|
2004
|
+
FROM users
|
|
2005
|
+
WHERE ("groupId" = 1 OR "adminAccess" = true)
|
|
2006
|
+
AND COALESCE(blocked, false) = false
|
|
2007
|
+
AND COALESCE(deleted, false) = false
|
|
2008
|
+
AND "deletedAt" IS NULL`);
|
|
2009
|
+
for (const r of rows) {
|
|
2010
|
+
const ph = r.phone?.trim();
|
|
2011
|
+
if (ph && ph.length >= 7) {
|
|
2012
|
+
phones.add(ph);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
} catch {
|
|
2016
|
+
}
|
|
2017
|
+
const vendorPhones = /* @__PURE__ */ new Set();
|
|
2018
|
+
try {
|
|
2019
|
+
const vRows = await dataSource.query(`SELECT DISTINCT TRIM(COALESCE(phone, "supportPhone", mobile, '')) AS phone FROM vendors WHERE COALESCE(deleted, false) = false`).catch(() => []);
|
|
2020
|
+
for (const r of vRows) {
|
|
2021
|
+
if (r.phone && r.phone.length >= 7) vendorPhones.add(r.phone);
|
|
2022
|
+
}
|
|
2023
|
+
} catch {
|
|
2024
|
+
}
|
|
2025
|
+
return Array.from(phones).filter((p) => !vendorPhones.has(p));
|
|
2026
|
+
}
|
|
2027
|
+
__name(getAdminRecipientPhones, "getAdminRecipientPhones");
|
|
1870
2028
|
function formatBodyForEmailHtml(body) {
|
|
1871
2029
|
if (!body) return "";
|
|
1872
2030
|
if (/^\s*<(html|body|table|section)[\s>]/i.test(body.trim())) {
|
|
@@ -1931,12 +2089,13 @@ async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables,
|
|
|
1931
2089
|
});
|
|
1932
2090
|
}
|
|
1933
2091
|
__name(sendEmailForTrigger, "sendEmailForTrigger");
|
|
1934
|
-
async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dataSource, entityMap, getCms) {
|
|
1935
|
-
const template = await loadBoundTemplate(triggerKey, "whatsapp",
|
|
2092
|
+
async function sendWhatsAppForTrigger(triggerKey, orderId, audienceType, phone, variables, dataSource, entityMap, getCms) {
|
|
2093
|
+
const template = await loadBoundTemplate(triggerKey, "whatsapp", audienceType, dataSource, entityMap);
|
|
1936
2094
|
if (!template) {
|
|
1937
2095
|
notifyLog.skip("WHATSAPP", "no bound/default WhatsApp template", {
|
|
1938
2096
|
triggerKey,
|
|
1939
2097
|
orderId,
|
|
2098
|
+
audienceType,
|
|
1940
2099
|
phone: maskNotifyPhone(phone)
|
|
1941
2100
|
});
|
|
1942
2101
|
return;
|
|
@@ -1945,7 +2104,8 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
|
|
|
1945
2104
|
if (paramOrder.length === 0) {
|
|
1946
2105
|
notifyLog.skip("WHATSAPP", "template has no paramOrder \u2014 variables may send blank/wrong", {
|
|
1947
2106
|
triggerKey,
|
|
1948
|
-
orderId
|
|
2107
|
+
orderId,
|
|
2108
|
+
audienceType
|
|
1949
2109
|
});
|
|
1950
2110
|
}
|
|
1951
2111
|
const cms = await getCms();
|
|
@@ -1957,6 +2117,7 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
|
|
|
1957
2117
|
notifyLog.skip("WHATSAPP", "template has no Meta template name", {
|
|
1958
2118
|
triggerKey,
|
|
1959
2119
|
orderId,
|
|
2120
|
+
audienceType,
|
|
1960
2121
|
phone: maskNotifyPhone(phone),
|
|
1961
2122
|
templateId: template.id
|
|
1962
2123
|
});
|
|
@@ -1975,6 +2136,7 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
|
|
|
1975
2136
|
notifyLog.error("WHATSAPP", "send failed / not queued", {
|
|
1976
2137
|
triggerKey,
|
|
1977
2138
|
orderId,
|
|
2139
|
+
audienceType,
|
|
1978
2140
|
phone: maskNotifyPhone(phone),
|
|
1979
2141
|
hint: "Register whatsappPlugin() + queuePlugin() in getCms(), or set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID"
|
|
1980
2142
|
});
|
|
@@ -1982,12 +2144,40 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
|
|
|
1982
2144
|
notifyLog.whatsapp("queued/sent", {
|
|
1983
2145
|
triggerKey,
|
|
1984
2146
|
orderId,
|
|
2147
|
+
audienceType,
|
|
1985
2148
|
phone: maskNotifyPhone(phone),
|
|
1986
2149
|
metaTemplateName
|
|
1987
2150
|
});
|
|
1988
2151
|
}
|
|
1989
2152
|
}
|
|
1990
2153
|
__name(sendWhatsAppForTrigger, "sendWhatsAppForTrigger");
|
|
2154
|
+
async function sendSmsForTrigger(triggerKey, orderId, audienceType, phone, variables, dataSource, entityMap, getCms) {
|
|
2155
|
+
const template = await loadBoundTemplate(triggerKey, "sms", audienceType, dataSource, entityMap);
|
|
2156
|
+
if (!template || !template.body) {
|
|
2157
|
+
notifyLog.skip("SMS", "no bound/default SMS template", {
|
|
2158
|
+
triggerKey,
|
|
2159
|
+
orderId,
|
|
2160
|
+
audienceType,
|
|
2161
|
+
phone: maskNotifyPhone(phone)
|
|
2162
|
+
});
|
|
2163
|
+
return;
|
|
2164
|
+
}
|
|
2165
|
+
const rawBody = applyTemplateVars(template.body, variables);
|
|
2166
|
+
const cms = await getCms();
|
|
2167
|
+
await queueSms(cms, {
|
|
2168
|
+
to: phone.trim(),
|
|
2169
|
+
body: rawBody,
|
|
2170
|
+
templateKey: template.externalTemplateRef || template.name || triggerKey,
|
|
2171
|
+
variables
|
|
2172
|
+
});
|
|
2173
|
+
notifyLog.sms("queued/sent", {
|
|
2174
|
+
triggerKey,
|
|
2175
|
+
audienceType,
|
|
2176
|
+
orderId,
|
|
2177
|
+
phone: maskNotifyPhone(phone)
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
2180
|
+
__name(sendSmsForTrigger, "sendSmsForTrigger");
|
|
1991
2181
|
async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms) {
|
|
1992
2182
|
notifyLog.trigger("dispatcher received", {
|
|
1993
2183
|
triggerKey,
|
|
@@ -1996,20 +2186,22 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
1996
2186
|
phone: maskNotifyPhone(payload.customerPhone),
|
|
1997
2187
|
vendorId: payload.vendorId ?? null
|
|
1998
2188
|
});
|
|
1999
|
-
const [emailChannelEnabled, whatsappChannelEnabled, pushChannelEnabled] = await Promise.all([
|
|
2189
|
+
const [emailChannelEnabled, whatsappChannelEnabled, pushChannelEnabled, smsChannelEnabled] = await Promise.all([
|
|
2000
2190
|
isEmailNotificationsEnabled(dataSource, entityMap),
|
|
2001
2191
|
isWhatsappNotificationsEnabled(dataSource, entityMap),
|
|
2002
|
-
isPushNotificationsEnabled(dataSource, entityMap)
|
|
2192
|
+
isPushNotificationsEnabled(dataSource, entityMap),
|
|
2193
|
+
isSmsNotificationsEnabled(dataSource, entityMap)
|
|
2003
2194
|
]);
|
|
2004
2195
|
notifyLog.trigger("channel switches", {
|
|
2005
2196
|
triggerKey,
|
|
2006
2197
|
orderId: payload.orderId,
|
|
2007
2198
|
email: emailChannelEnabled,
|
|
2008
2199
|
whatsapp: whatsappChannelEnabled,
|
|
2009
|
-
push: pushChannelEnabled
|
|
2200
|
+
push: pushChannelEnabled,
|
|
2201
|
+
sms: smsChannelEnabled
|
|
2010
2202
|
});
|
|
2011
|
-
if (!emailChannelEnabled && !whatsappChannelEnabled && !pushChannelEnabled) {
|
|
2012
|
-
notifyLog.skip("ALL", "Email, WhatsApp,
|
|
2203
|
+
if (!emailChannelEnabled && !whatsappChannelEnabled && !pushChannelEnabled && !smsChannelEnabled) {
|
|
2204
|
+
notifyLog.skip("ALL", "Email, WhatsApp, Mobile Push, and SMS are disabled in event_notifications", {
|
|
2013
2205
|
triggerKey,
|
|
2014
2206
|
orderId: payload.orderId
|
|
2015
2207
|
});
|
|
@@ -2156,21 +2348,155 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2156
2348
|
});
|
|
2157
2349
|
}
|
|
2158
2350
|
if (whatsappChannelEnabled) {
|
|
2159
|
-
const
|
|
2160
|
-
|
|
2161
|
-
|
|
2351
|
+
const [waCustomerEnabled, waVendorEnabled, waAdminEnabled] = await Promise.all([
|
|
2352
|
+
isAudienceWhatsAppEnabled(dataSource, entityMap, "customer"),
|
|
2353
|
+
isAudienceWhatsAppEnabled(dataSource, entityMap, "vendor"),
|
|
2354
|
+
isAudienceWhatsAppEnabled(dataSource, entityMap, "admin")
|
|
2355
|
+
]);
|
|
2356
|
+
notifyLog.whatsapp("audience switches", {
|
|
2357
|
+
triggerKey,
|
|
2358
|
+
orderId: payload.orderId,
|
|
2359
|
+
customer: waCustomerEnabled,
|
|
2360
|
+
vendor: waVendorEnabled,
|
|
2361
|
+
admin: waAdminEnabled
|
|
2362
|
+
});
|
|
2363
|
+
if (triggerKey === "order_assigned_assignee") {
|
|
2364
|
+
const assigneePhone = context?.order?.assignedUser?.phone?.trim();
|
|
2365
|
+
if (assigneePhone) {
|
|
2366
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "customers", assigneePhone, variables, dataSource, entityMap, getCms);
|
|
2367
|
+
} else {
|
|
2368
|
+
notifyLog.skip("WHATSAPP", "order_assigned_assignee has no assignee phone", {
|
|
2369
|
+
triggerKey,
|
|
2370
|
+
orderId: payload.orderId
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
} else if (waCustomerEnabled && contactPhone) {
|
|
2374
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "customers", contactPhone, variables, dataSource, entityMap, getCms);
|
|
2375
|
+
} else if (!waCustomerEnabled) {
|
|
2376
|
+
notifyLog.skip("WHATSAPP", "customer WhatsApp audience disabled", {
|
|
2377
|
+
triggerKey,
|
|
2378
|
+
orderId: payload.orderId
|
|
2379
|
+
});
|
|
2162
2380
|
} else {
|
|
2163
|
-
notifyLog.skip("WHATSAPP", "no
|
|
2381
|
+
notifyLog.skip("WHATSAPP", "no customer phone on order contact", {
|
|
2164
2382
|
triggerKey,
|
|
2165
2383
|
orderId: payload.orderId
|
|
2166
2384
|
});
|
|
2167
2385
|
}
|
|
2386
|
+
if (waVendorEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2387
|
+
const multiVendorSettings = await getSettingsGroup(dataSource, entityMap, "multi_vendor");
|
|
2388
|
+
if (multiVendorSettings.enabled !== "false" && multiVendorSettings.enabled !== "0") {
|
|
2389
|
+
const vendorPhones = await getOrderVendorPhones(payload.orderId, payload.vendorId, dataSource, entityMap);
|
|
2390
|
+
if (vendorPhones.length === 0) {
|
|
2391
|
+
notifyLog.skip("WHATSAPP", "no vendor phones for order", {
|
|
2392
|
+
triggerKey,
|
|
2393
|
+
orderId: payload.orderId,
|
|
2394
|
+
vendorId: payload.vendorId ?? null
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
for (const vPhone of vendorPhones) {
|
|
2398
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "vendors", vPhone, variables, dataSource, entityMap, getCms);
|
|
2399
|
+
}
|
|
2400
|
+
} else {
|
|
2401
|
+
notifyLog.skip("WHATSAPP", "multi-vendor off \u2014 skip vendor WhatsApp", {
|
|
2402
|
+
triggerKey,
|
|
2403
|
+
orderId: payload.orderId
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
if (waAdminEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2408
|
+
const adminPhones = await getAdminRecipientPhones(dataSource, entityMap);
|
|
2409
|
+
if (adminPhones.length === 0) {
|
|
2410
|
+
notifyLog.skip("WHATSAPP", "no admin recipient phones", {
|
|
2411
|
+
triggerKey,
|
|
2412
|
+
orderId: payload.orderId
|
|
2413
|
+
});
|
|
2414
|
+
}
|
|
2415
|
+
for (const aPhone of adminPhones) {
|
|
2416
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, "admin", aPhone, variables, dataSource, entityMap, getCms);
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2168
2419
|
} else {
|
|
2169
2420
|
notifyLog.skip("WHATSAPP", "WhatsApp channel disabled", {
|
|
2170
2421
|
triggerKey,
|
|
2171
2422
|
orderId: payload.orderId
|
|
2172
2423
|
});
|
|
2173
2424
|
}
|
|
2425
|
+
if (smsChannelEnabled) {
|
|
2426
|
+
const [smsCustomerEnabled, smsVendorEnabled, smsAdminEnabled] = await Promise.all([
|
|
2427
|
+
isAudienceSmsEnabled(dataSource, entityMap, "customer"),
|
|
2428
|
+
isAudienceSmsEnabled(dataSource, entityMap, "vendor"),
|
|
2429
|
+
isAudienceSmsEnabled(dataSource, entityMap, "admin")
|
|
2430
|
+
]);
|
|
2431
|
+
notifyLog.sms("audience switches", {
|
|
2432
|
+
triggerKey,
|
|
2433
|
+
orderId: payload.orderId,
|
|
2434
|
+
customer: smsCustomerEnabled,
|
|
2435
|
+
vendor: smsVendorEnabled,
|
|
2436
|
+
admin: smsAdminEnabled
|
|
2437
|
+
});
|
|
2438
|
+
if (triggerKey === "order_assigned_assignee") {
|
|
2439
|
+
const assigneePhone = context?.order?.assignedUser?.phone?.trim();
|
|
2440
|
+
if (assigneePhone) {
|
|
2441
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "customers", assigneePhone, variables, dataSource, entityMap, getCms);
|
|
2442
|
+
} else {
|
|
2443
|
+
notifyLog.skip("SMS", "order_assigned_assignee has no assignee phone", {
|
|
2444
|
+
triggerKey,
|
|
2445
|
+
orderId: payload.orderId
|
|
2446
|
+
});
|
|
2447
|
+
}
|
|
2448
|
+
} else if (smsCustomerEnabled && contactPhone) {
|
|
2449
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "customers", contactPhone, variables, dataSource, entityMap, getCms);
|
|
2450
|
+
} else if (!smsCustomerEnabled) {
|
|
2451
|
+
notifyLog.skip("SMS", "customer SMS audience disabled", {
|
|
2452
|
+
triggerKey,
|
|
2453
|
+
orderId: payload.orderId
|
|
2454
|
+
});
|
|
2455
|
+
} else {
|
|
2456
|
+
notifyLog.skip("SMS", "no customer phone on order contact", {
|
|
2457
|
+
triggerKey,
|
|
2458
|
+
orderId: payload.orderId
|
|
2459
|
+
});
|
|
2460
|
+
}
|
|
2461
|
+
if (smsVendorEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2462
|
+
const multiVendorSettings = await getSettingsGroup(dataSource, entityMap, "multi_vendor");
|
|
2463
|
+
if (multiVendorSettings.enabled !== "false" && multiVendorSettings.enabled !== "0") {
|
|
2464
|
+
const vendorPhones = await getOrderVendorPhones(payload.orderId, payload.vendorId, dataSource, entityMap);
|
|
2465
|
+
if (vendorPhones.length === 0) {
|
|
2466
|
+
notifyLog.skip("SMS", "no vendor phones for order", {
|
|
2467
|
+
triggerKey,
|
|
2468
|
+
orderId: payload.orderId,
|
|
2469
|
+
vendorId: payload.vendorId ?? null
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
for (const vPhone of vendorPhones) {
|
|
2473
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "vendors", vPhone, variables, dataSource, entityMap, getCms);
|
|
2474
|
+
}
|
|
2475
|
+
} else {
|
|
2476
|
+
notifyLog.skip("SMS", "multi-vendor off \u2014 skip vendor SMS", {
|
|
2477
|
+
triggerKey,
|
|
2478
|
+
orderId: payload.orderId
|
|
2479
|
+
});
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
if (smsAdminEnabled && triggerKey !== "order_assigned_assignee") {
|
|
2483
|
+
const adminPhones = await getAdminRecipientPhones(dataSource, entityMap);
|
|
2484
|
+
if (adminPhones.length === 0) {
|
|
2485
|
+
notifyLog.skip("SMS", "no admin recipient phones", {
|
|
2486
|
+
triggerKey,
|
|
2487
|
+
orderId: payload.orderId
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
for (const aPhone of adminPhones) {
|
|
2491
|
+
await sendSmsForTrigger(triggerKey, payload.orderId, "admin", aPhone, variables, dataSource, entityMap, getCms);
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
} else {
|
|
2495
|
+
notifyLog.skip("SMS", "SMS channel disabled", {
|
|
2496
|
+
triggerKey,
|
|
2497
|
+
orderId: payload.orderId
|
|
2498
|
+
});
|
|
2499
|
+
}
|
|
2174
2500
|
}
|
|
2175
2501
|
__name(handleTrigger, "handleTrigger");
|
|
2176
2502
|
var globalGetCms = null;
|
|
@@ -2181,6 +2507,8 @@ function initWhatsappTriggerDispatcher(deps) {
|
|
|
2181
2507
|
const { dataSource, entityMap, getCms } = deps;
|
|
2182
2508
|
void dataSource.query(`ALTER TYPE "order_notification_bindings_channel_enum" ADD VALUE IF NOT EXISTS 'mobile'`).catch(() => {
|
|
2183
2509
|
});
|
|
2510
|
+
void dataSource.query(`ALTER TYPE "order_notification_bindings_channel_enum" ADD VALUE IF NOT EXISTS 'sms'`).catch(() => {
|
|
2511
|
+
});
|
|
2184
2512
|
notificationTriggerEmitter.onAnyTrigger((triggerKey, payload) => {
|
|
2185
2513
|
void handleTrigger(triggerKey, payload, dataSource, entityMap, getCms).catch((err) => {
|
|
2186
2514
|
notifyLog.error("TRIGGER", "dispatcher handleTrigger failed", {
|
|
@@ -2195,7 +2523,8 @@ function initWhatsappTriggerDispatcher(deps) {
|
|
|
2195
2523
|
channels: [
|
|
2196
2524
|
"email",
|
|
2197
2525
|
"whatsapp",
|
|
2198
|
-
"push"
|
|
2526
|
+
"push",
|
|
2527
|
+
"sms"
|
|
2199
2528
|
]
|
|
2200
2529
|
});
|
|
2201
2530
|
}
|
|
@@ -2212,14 +2541,15 @@ async function resendOrderNotification(triggerKey, orderId, deps) {
|
|
|
2212
2541
|
ok: false,
|
|
2213
2542
|
error: "orders entity missing"
|
|
2214
2543
|
};
|
|
2215
|
-
const [emailEnabled, whatsappEnabled] = await Promise.all([
|
|
2544
|
+
const [emailEnabled, whatsappEnabled, smsEnabled] = await Promise.all([
|
|
2216
2545
|
isEmailNotificationsEnabled(deps.dataSource, deps.entityMap),
|
|
2217
|
-
isWhatsappNotificationsEnabled(deps.dataSource, deps.entityMap)
|
|
2546
|
+
isWhatsappNotificationsEnabled(deps.dataSource, deps.entityMap),
|
|
2547
|
+
isSmsNotificationsEnabled(deps.dataSource, deps.entityMap)
|
|
2218
2548
|
]);
|
|
2219
|
-
if (!emailEnabled && !whatsappEnabled) {
|
|
2549
|
+
if (!emailEnabled && !whatsappEnabled && !smsEnabled) {
|
|
2220
2550
|
return {
|
|
2221
2551
|
ok: false,
|
|
2222
|
-
error: "
|
|
2552
|
+
error: "Email, WhatsApp, and SMS notifications are all disabled"
|
|
2223
2553
|
};
|
|
2224
2554
|
}
|
|
2225
2555
|
const triggerEnabled = await isTriggerCatalogEnabled(triggerKey, deps.dataSource, deps.entityMap);
|