@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.
Files changed (37) hide show
  1. package/dist/admin.cjs +2834 -2683
  2. package/dist/admin.js +1593 -1442
  3. package/dist/api.cjs +41 -41
  4. package/dist/api.js +8 -8
  5. package/dist/auth.cjs +51 -51
  6. package/dist/auth.js +3 -3
  7. package/dist/{chunk-RBKVMHBH.js → chunk-3LF4RYAJ.js} +353 -23
  8. package/dist/{chunk-DBBYLSQP.js → chunk-7NQMGB2S.js} +136 -25
  9. package/dist/{chunk-DWNQTFJ5.js → chunk-CJY2HUJC.js} +19 -19
  10. package/dist/{chunk-SWSTGV4F.cjs → chunk-CKTRA3Q2.cjs} +9 -9
  11. package/dist/{chunk-53AMBXMM.js → chunk-ECUGNV2I.js} +1 -57
  12. package/dist/{chunk-QXAQ3V7R.cjs → chunk-FNLF6G2N.cjs} +7 -7
  13. package/dist/{chunk-T47VP2ZT.js → chunk-HZZTDM5J.js} +2 -2
  14. package/dist/{chunk-3XCTGADT.js → chunk-K6JT7BKY.js} +58 -1
  15. package/dist/{chunk-M5QDJOUP.cjs → chunk-K742UE6S.cjs} +1 -0
  16. package/dist/{chunk-6MM5OMRL.cjs → chunk-KB7EBYPR.cjs} +0 -58
  17. package/dist/{chunk-OXFC3DAM.cjs → chunk-KJB5LBFQ.cjs} +59 -0
  18. package/dist/{chunk-LXWF6T7F.cjs → chunk-LCZZ3S4I.cjs} +19 -19
  19. package/dist/{chunk-HGR4IA7I.cjs → chunk-NIBEGDD4.cjs} +15 -15
  20. package/dist/{chunk-D4LR3S77.js → chunk-NQF6H656.js} +1 -1
  21. package/dist/{chunk-QL44NCZC.cjs → chunk-OP624LWU.cjs} +222 -111
  22. package/dist/{chunk-MJDNS324.js → chunk-SCE2GIKH.js} +2 -2
  23. package/dist/{chunk-747MJJCZ.cjs → chunk-TTOEY7AH.cjs} +404 -74
  24. package/dist/{chunk-WHMIWJL7.js → chunk-W2ZTGLUH.js} +1 -0
  25. package/dist/{emit-order-notification-trigger-X36V4DOH.cjs → emit-order-notification-trigger-I4HQSTEN.cjs} +4 -4
  26. package/dist/{emit-order-notification-trigger-XKN2TWVF.js → emit-order-notification-trigger-TBXAZAPS.js} +2 -2
  27. package/dist/index.cjs +330 -330
  28. package/dist/index.js +13 -13
  29. package/dist/{order-assignees-handlers-JEJ5IDID.cjs → order-assignees-handlers-E6PQZP4H.cjs} +22 -3
  30. package/dist/{order-assignees-handlers-F7WOZHOG.js → order-assignees-handlers-YCT3Q3KC.js} +22 -3
  31. package/dist/{order-completion-otp-handlers-LNAZTMTS.cjs → order-completion-otp-handlers-2ZKRK5SN.cjs} +10 -10
  32. package/dist/{order-completion-otp-handlers-FIW7PZ6W.js → order-completion-otp-handlers-KHLZQQJX.js} +4 -4
  33. package/dist/{order-notification-dispatcher-GG5C4LKZ.cjs → order-notification-dispatcher-37KDVHBM.cjs} +8 -8
  34. package/dist/{order-notification-dispatcher-FS54ANAV.js → order-notification-dispatcher-Z3MXNF4U.js} +3 -3
  35. package/dist/{rbac-debug-db-IRKT6G62.js → rbac-debug-db-JK3U5UZK.js} +1 -1
  36. package/dist/{rbac-debug-db-2ZI3XKA4.cjs → rbac-debug-db-S3D6N6HN.cjs} +2 -2
  37. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkOXFC3DAM_cjs = require('./chunk-OXFC3DAM.cjs');
4
- var chunkM5QDJOUP_cjs = require('./chunk-M5QDJOUP.cjs');
3
+ var chunkKJB5LBFQ_cjs = require('./chunk-KJB5LBFQ.cjs');
4
+ var chunkK742UE6S_cjs = require('./chunk-K742UE6S.cjs');
5
5
  var chunkCIZZX57T_cjs = require('./chunk-CIZZX57T.cjs');
6
6
  var chunkQN6PZLAP_cjs = require('./chunk-QN6PZLAP.cjs');
7
7
  var chunk4MNVIGVJ_cjs = require('./chunk-4MNVIGVJ.cjs');
@@ -407,7 +407,10 @@ function whatsAppConfigured(config) {
407
407
  }
408
408
  chunkXHPRD45G_cjs.__name(whatsAppConfigured, "whatsAppConfigured");
409
409
  function normalizeWhatsAppRecipient(to) {
410
- const digits = to.replace(/\D/g, "");
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");
@@ -504,9 +507,8 @@ var WhatsAppService = class {
504
507
  const { applyTemplateVars: applyTemplateVars2 } = await import('./interpolate-WP6OSJHN.cjs');
505
508
  if (body) body = applyTemplateVars2(body, variables);
506
509
  if (templateName) {
507
- const paramValues = opts.templateParamOrder?.length ? opts.templateParamOrder.map((key) => String(variables[key] ?? "").slice(0, 1024)) : Object.keys(variables).length ? Object.values(variables) : body ? [
508
- body
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,
@@ -1449,6 +1451,12 @@ async function isWhatsappNotificationsEnabled(dataSource, entityMap) {
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;
@@ -1637,13 +1645,29 @@ async function isAudiencePushEnabled(dataSource, entityMap, audience) {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("PUSH", "no mobile/push template or empty body", {
1670
+ chunkK742UE6S_cjs.notifyLog.skip("PUSH", "no mobile/push template or empty body", {
1647
1671
  triggerKey,
1648
1672
  orderId,
1649
1673
  audienceType,
@@ -1655,7 +1679,7 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1655
1679
  const title = chunkCIZZX57T_cjs.applyTemplateVars(rawTitle, variables);
1656
1680
  const body = chunkCIZZX57T_cjs.applyTemplateVars(template.body, variables);
1657
1681
  if (!entityMap.user_device_tokens) {
1658
- chunkM5QDJOUP_cjs.notifyLog.skip("PUSH", "user_device_tokens entity not registered", {
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
- chunkM5QDJOUP_cjs.notifyLog.error("PUSH", "device token query failed", {
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
- chunkM5QDJOUP_cjs.notifyLog.push("sending", {
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) => chunkM5QDJOUP_cjs.logFcmToken(t))
1740
+ fcmTokens: tokens.map((t) => chunkK742UE6S_cjs.logFcmToken(t))
1717
1741
  });
1718
1742
  if (tokens.length === 0) {
1719
- chunkM5QDJOUP_cjs.notifyLog.skip("PUSH", "no active FCM tokens for target", {
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
- chunkM5QDJOUP_cjs.notifyLog.push("FCM target", {
1753
+ chunkK742UE6S_cjs.notifyLog.push("FCM target", {
1730
1754
  triggerKey,
1731
1755
  orderId,
1732
1756
  audienceType,
1733
1757
  targetId,
1734
- fcmToken: chunkM5QDJOUP_cjs.logFcmToken(token)
1758
+ fcmToken: chunkK742UE6S_cjs.logFcmToken(token)
1735
1759
  });
1736
1760
  const res = await sendFcmPushNotification(dataSource, entityMap, {
1737
1761
  token,
@@ -1743,19 +1767,19 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1743
1767
  }
1744
1768
  });
1745
1769
  if (res.success) {
1746
- chunkM5QDJOUP_cjs.notifyLog.push("FCM sent", {
1770
+ chunkK742UE6S_cjs.notifyLog.push("FCM sent", {
1747
1771
  triggerKey,
1748
1772
  orderId,
1749
1773
  audienceType,
1750
- fcmToken: chunkM5QDJOUP_cjs.logFcmToken(token),
1774
+ fcmToken: chunkK742UE6S_cjs.logFcmToken(token),
1751
1775
  messageId: res.messageId ?? null
1752
1776
  });
1753
1777
  } else {
1754
- chunkM5QDJOUP_cjs.notifyLog.error("PUSH", "FCM send failed", {
1778
+ chunkK742UE6S_cjs.notifyLog.error("PUSH", "FCM send failed", {
1755
1779
  triggerKey,
1756
1780
  orderId,
1757
1781
  audienceType,
1758
- fcmToken: chunkM5QDJOUP_cjs.logFcmToken(token),
1782
+ fcmToken: chunkK742UE6S_cjs.logFcmToken(token),
1759
1783
  error: res.error ?? "unknown"
1760
1784
  });
1761
1785
  }
@@ -1889,6 +1913,140 @@ async function getAdminRecipientEmails(dataSource, entityMap) {
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())) {
@@ -1901,11 +2059,11 @@ 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
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "no bound/default email template", {
2062
+ chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "no bound/default email template", {
1905
2063
  triggerKey,
1906
2064
  orderId,
1907
2065
  audienceType,
1908
- to: chunkM5QDJOUP_cjs.maskNotifyEmail(contactEmail)
2066
+ to: chunkK742UE6S_cjs.maskNotifyEmail(contactEmail)
1909
2067
  });
1910
2068
  return;
1911
2069
  }
@@ -1943,31 +2101,33 @@ async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables,
1943
2101
  attachInvoice: true
1944
2102
  } : {}
1945
2103
  });
1946
- chunkM5QDJOUP_cjs.notifyLog.email("queued", {
2104
+ chunkK742UE6S_cjs.notifyLog.email("queued", {
1947
2105
  triggerKey,
1948
2106
  audienceType,
1949
2107
  orderId,
1950
- to: chunkM5QDJOUP_cjs.maskNotifyEmail(contactEmail),
2108
+ to: chunkK742UE6S_cjs.maskNotifyEmail(contactEmail),
1951
2109
  subject,
1952
2110
  attachInvoice: shouldAttachInvoice
1953
2111
  });
1954
2112
  }
1955
2113
  chunkXHPRD45G_cjs.__name(sendEmailForTrigger, "sendEmailForTrigger");
1956
- async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dataSource, entityMap, getCms) {
1957
- const template = await loadBoundTemplate(triggerKey, "whatsapp", "customers", dataSource, entityMap);
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
- chunkM5QDJOUP_cjs.notifyLog.skip("WHATSAPP", "no bound/default WhatsApp template", {
2117
+ chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "no bound/default WhatsApp template", {
1960
2118
  triggerKey,
1961
2119
  orderId,
1962
- phone: chunkM5QDJOUP_cjs.maskNotifyPhone(phone)
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
- chunkM5QDJOUP_cjs.notifyLog.skip("WHATSAPP", "template has no paramOrder \u2014 variables may send blank/wrong", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("WHATSAPP", "template has no Meta template name", {
2139
+ chunkK742UE6S_cjs.notifyLog.skip("WHATSAPP", "template has no Meta template name", {
1980
2140
  triggerKey,
1981
2141
  orderId,
1982
- phone: chunkM5QDJOUP_cjs.maskNotifyPhone(phone),
2142
+ audienceType,
2143
+ phone: chunkK742UE6S_cjs.maskNotifyPhone(phone),
1983
2144
  templateId: template.id
1984
2145
  });
1985
2146
  return;
1986
2147
  }
1987
- const sent = await chunkOXFC3DAM_cjs.queueWhatsApp(cms, {
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
- chunkM5QDJOUP_cjs.notifyLog.error("WHATSAPP", "send failed / not queued", {
2158
+ chunkK742UE6S_cjs.notifyLog.error("WHATSAPP", "send failed / not queued", {
1998
2159
  triggerKey,
1999
2160
  orderId,
2000
- phone: chunkM5QDJOUP_cjs.maskNotifyPhone(phone),
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
- chunkM5QDJOUP_cjs.notifyLog.whatsapp("queued/sent", {
2166
+ chunkK742UE6S_cjs.notifyLog.whatsapp("queued/sent", {
2005
2167
  triggerKey,
2006
2168
  orderId,
2007
- phone: chunkM5QDJOUP_cjs.maskNotifyPhone(phone),
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
- chunkM5QDJOUP_cjs.notifyLog.trigger("dispatcher received", {
2204
+ chunkK742UE6S_cjs.notifyLog.trigger("dispatcher received", {
2015
2205
  triggerKey,
2016
2206
  orderId: payload.orderId,
2017
2207
  orderNumber: payload.orderNumber,
2018
- phone: chunkM5QDJOUP_cjs.maskNotifyPhone(payload.customerPhone),
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
- chunkM5QDJOUP_cjs.notifyLog.trigger("channel switches", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("ALL", "Email, WhatsApp, and Mobile Push are disabled in event_notifications", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("TRIGGER", "trigger catalog disabled", {
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
- chunkM5QDJOUP_cjs.notifyLog.trigger("recipients resolved", {
2247
+ chunkK742UE6S_cjs.notifyLog.trigger("recipients resolved", {
2056
2248
  triggerKey,
2057
2249
  orderId: payload.orderId,
2058
- contactEmail: chunkM5QDJOUP_cjs.maskNotifyEmail(contactEmail),
2059
- contactPhone: chunkM5QDJOUP_cjs.maskNotifyPhone(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
- chunkM5QDJOUP_cjs.notifyLog.email("audience switches", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "order_assigned_assignee has no assignee email", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "customer email audience disabled", {
2279
+ chunkK742UE6S_cjs.notifyLog.skip("EMAIL", "customer email audience disabled", {
2088
2280
  triggerKey,
2089
2281
  orderId: payload.orderId
2090
2282
  });
2091
2283
  } else {
2092
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "no customer email on order contact", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "no vendor emails for order", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "multi-vendor off \u2014 skip vendor email", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "no admin recipient emails", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("EMAIL", "email channel disabled", {
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
- chunkM5QDJOUP_cjs.notifyLog.push("audience switches", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("PUSH", "customer push audience disabled", {
2345
+ chunkK742UE6S_cjs.notifyLog.skip("PUSH", "customer push audience disabled", {
2154
2346
  triggerKey,
2155
2347
  orderId: payload.orderId
2156
2348
  });
2157
2349
  } else {
2158
- chunkM5QDJOUP_cjs.notifyLog.skip("PUSH", "no customer user/contact id for push", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("PUSH", "no vendorId on order \u2014 skip vendor push", {
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,23 +2364,157 @@ 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
- chunkM5QDJOUP_cjs.notifyLog.skip("PUSH", "push channel disabled", {
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 targetPhone = triggerKey === "order_assigned_assignee" ? context?.order?.assignedUser?.phone?.trim() : contactPhone;
2182
- if (targetPhone) {
2183
- await sendWhatsAppForTrigger(triggerKey, payload.orderId, targetPhone, variables, dataSource, entityMap, getCms);
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
- chunkM5QDJOUP_cjs.notifyLog.skip("WHATSAPP", "no recipient phone", {
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
- chunkM5QDJOUP_cjs.notifyLog.skip("WHATSAPP", "WhatsApp channel disabled", {
2517
+ chunkK742UE6S_cjs.notifyLog.skip("SMS", "SMS channel disabled", {
2192
2518
  triggerKey,
2193
2519
  orderId: payload.orderId
2194
2520
  });
@@ -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
- chunkM5QDJOUP_cjs.notificationTriggerEmitter.onAnyTrigger((triggerKey, payload) => {
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
- chunkM5QDJOUP_cjs.notifyLog.error("TRIGGER", "dispatcher handleTrigger failed", {
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,11 +2541,12 @@ function initWhatsappTriggerDispatcher(deps) {
2213
2541
  });
2214
2542
  });
2215
2543
  });
2216
- chunkM5QDJOUP_cjs.notifyLog.trigger("dispatcher initialized", {
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
  }
@@ -2234,14 +2563,15 @@ async function resendOrderNotification(triggerKey, orderId, deps) {
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: "Both Email and WhatsApp notifications are disabled"
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);
@@ -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
- chunkM5QDJOUP_cjs.notificationTriggerEmitter.emitTrigger(triggerKey, payload);
2620
+ chunkK742UE6S_cjs.notificationTriggerEmitter.emitTrigger(triggerKey, payload);
2291
2621
  return {
2292
2622
  ok: true,
2293
2623
  channels: enabledChannels