@infuro/cms-core 1.0.65 → 1.0.67

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 (36) hide show
  1. package/dist/admin.cjs +97 -24
  2. package/dist/admin.js +97 -24
  3. package/dist/api.cjs +38 -38
  4. package/dist/api.js +5 -5
  5. package/dist/auth.cjs +51 -51
  6. package/dist/auth.js +3 -3
  7. package/dist/{chunk-6DBDJ4VD.js → chunk-2ISSXYBZ.js} +2 -2
  8. package/dist/{chunk-NIRYYJIJ.cjs → chunk-5MZFQRDW.cjs} +73 -55
  9. package/dist/{chunk-MVHDC3XF.js → chunk-5NOZSG6J.js} +22 -11
  10. package/dist/{chunk-YHEITFHR.cjs → chunk-BVLN75LP.cjs} +540 -143
  11. package/dist/{chunk-YEAXE4U2.js → chunk-FLUF2GZH.js} +5 -11
  12. package/dist/{chunk-SANKKGB3.js → chunk-GLLCLRCQ.js} +464 -67
  13. package/dist/{chunk-ACBN6UWZ.js → chunk-NV5IRHI3.js} +26 -8
  14. package/dist/{chunk-J7FMZK66.cjs → chunk-O4AFPDQ4.cjs} +22 -11
  15. package/dist/{chunk-4U6DATGZ.cjs → chunk-OV5TRZET.cjs} +7 -7
  16. package/dist/{chunk-BXAKL2TF.cjs → chunk-PA6YDMFZ.cjs} +5 -11
  17. package/dist/{chunk-RDEVZMO5.js → chunk-RCE5SJBA.js} +2 -2
  18. package/dist/{chunk-KM2I6AFP.cjs → chunk-SS3K7OIM.cjs} +9 -9
  19. package/dist/{chunk-V6EYAC7X.cjs → chunk-WMMZZRDJ.cjs} +15 -15
  20. package/dist/{chunk-NR44CK5E.js → chunk-ZY64VJMS.js} +1 -1
  21. package/dist/{emit-order-notification-trigger-UCKJHDQK.js → emit-order-notification-trigger-EJJZ6XTS.js} +2 -2
  22. package/dist/{emit-order-notification-trigger-DR74TQXN.cjs → emit-order-notification-trigger-ZD5YN3JM.cjs} +4 -4
  23. package/dist/index.cjs +284 -280
  24. package/dist/index.d.cts +14 -1
  25. package/dist/index.d.ts +14 -1
  26. package/dist/index.js +10 -10
  27. package/dist/migrations/1783300000000-CreateOrderAssigneesTable.ts +43 -0
  28. package/dist/{order-assignees-handlers-NPKD64P6.cjs → order-assignees-handlers-KF7RMTV5.cjs} +77 -8
  29. package/dist/{order-assignees-handlers-LKMAGLG6.js → order-assignees-handlers-L3RVKUBS.js} +77 -8
  30. package/dist/{order-completion-otp-handlers-RW5RSXH3.cjs → order-completion-otp-handlers-DZAXK4GQ.cjs} +70 -16
  31. package/dist/{order-completion-otp-handlers-CH22ZRAI.js → order-completion-otp-handlers-HFGCPC4O.js} +69 -15
  32. package/dist/{order-notification-dispatcher-3TXUAJ7L.js → order-notification-dispatcher-ECPFI7CD.js} +2 -2
  33. package/dist/{order-notification-dispatcher-Y7NZAALH.cjs → order-notification-dispatcher-LL7ETKLU.cjs} +7 -7
  34. package/dist/{rbac-debug-db-5R6XFPSV.js → rbac-debug-db-DFZWZ6GV.js} +1 -1
  35. package/dist/{rbac-debug-db-JKK2MCWF.cjs → rbac-debug-db-KWV7D5PQ.cjs} +2 -2
  36. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkH3IVLIPR_cjs = require('./chunk-H3IVLIPR.cjs');
4
- var chunkBXAKL2TF_cjs = require('./chunk-BXAKL2TF.cjs');
4
+ var chunkPA6YDMFZ_cjs = require('./chunk-PA6YDMFZ.cjs');
5
5
  var chunkVM6OVUUM_cjs = require('./chunk-VM6OVUUM.cjs');
6
6
  var chunkXFDIIVZB_cjs = require('./chunk-XFDIIVZB.cjs');
7
7
  var chunkTZEMLHSP_cjs = require('./chunk-TZEMLHSP.cjs');
@@ -239,7 +239,8 @@ async function loadOrderNotificationContexts(orderId, deps) {
239
239
  const contact = {
240
240
  name: metaBuyerName || rawContact.name,
241
241
  email: metaBuyerEmail || metaCheckoutEmail || rawContact.email,
242
- phone: rawContact.phone
242
+ phone: rawContact.phone,
243
+ userId: rawContact.userId ?? null
243
244
  };
244
245
  const currency = String(o.currency ?? "INR");
245
246
  const siteUrl = resolvePublicSiteUrl();
@@ -1524,7 +1525,17 @@ async function loadBoundTemplate(triggerKey, channel, audienceType = "customers"
1524
1525
  enabled: true
1525
1526
  }
1526
1527
  }).catch(() => null);
1527
- if (!template) {
1528
+ let resolvedTemplate = template;
1529
+ if (!resolvedTemplate && (channel === "mobile" || channel === "push")) {
1530
+ resolvedTemplate = await dataSource.getRepository(entityMap.message_templates).findOne({
1531
+ where: {
1532
+ id: templateId,
1533
+ deleted: false,
1534
+ enabled: true
1535
+ }
1536
+ }).catch(() => null);
1537
+ }
1538
+ if (!resolvedTemplate) {
1528
1539
  const defChannel = ORDER_NOTIFICATION_DEFAULTS[channel];
1529
1540
  const def = defChannel ? defChannel[triggerKey] : null;
1530
1541
  if (def) {
@@ -1549,7 +1560,7 @@ async function loadBoundTemplate(triggerKey, channel, audienceType = "customers"
1549
1560
  });
1550
1561
  return null;
1551
1562
  }
1552
- return template;
1563
+ return resolvedTemplate;
1553
1564
  } catch (err) {
1554
1565
  const defChannel = ORDER_NOTIFICATION_DEFAULTS[channel];
1555
1566
  const def = defChannel ? defChannel[triggerKey] : null;
@@ -1632,7 +1643,7 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1632
1643
  template = await loadBoundTemplate(triggerKey, "push", audienceType, dataSource, entityMap);
1633
1644
  }
1634
1645
  if (!template || !template.body) {
1635
- chunkBXAKL2TF_cjs.notifyLog.skip("PUSH", "no mobile/push template or empty body", {
1646
+ chunkPA6YDMFZ_cjs.notifyLog.skip("PUSH", "no mobile/push template or empty body", {
1636
1647
  triggerKey,
1637
1648
  orderId,
1638
1649
  audienceType,
@@ -1644,7 +1655,7 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1644
1655
  const title = chunkOOTLNH63_cjs.applyTemplateVars(rawTitle, variables);
1645
1656
  const body = chunkOOTLNH63_cjs.applyTemplateVars(template.body, variables);
1646
1657
  if (!entityMap.user_device_tokens) {
1647
- chunkBXAKL2TF_cjs.notifyLog.skip("PUSH", "user_device_tokens entity not registered", {
1658
+ chunkPA6YDMFZ_cjs.notifyLog.skip("PUSH", "user_device_tokens entity not registered", {
1648
1659
  triggerKey,
1649
1660
  orderId,
1650
1661
  audienceType
@@ -1685,7 +1696,7 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1685
1696
  });
1686
1697
  }
1687
1698
  } catch (err) {
1688
- chunkBXAKL2TF_cjs.notifyLog.error("PUSH", "device token query failed", {
1699
+ chunkPA6YDMFZ_cjs.notifyLog.error("PUSH", "device token query failed", {
1689
1700
  triggerKey,
1690
1701
  orderId,
1691
1702
  audienceType,
@@ -1695,17 +1706,17 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1695
1706
  return;
1696
1707
  }
1697
1708
  const tokens = targetTokens.map((t) => t.token?.trim()).filter(Boolean);
1698
- chunkBXAKL2TF_cjs.notifyLog.push("sending", {
1709
+ chunkPA6YDMFZ_cjs.notifyLog.push("sending", {
1699
1710
  triggerKey,
1700
1711
  orderId,
1701
1712
  audienceType,
1702
1713
  targetId,
1703
1714
  title,
1704
1715
  tokenCount: tokens.length,
1705
- tokens: tokens.map((t) => chunkBXAKL2TF_cjs.maskNotifyToken(t))
1716
+ fcmTokens: tokens.map((t) => chunkPA6YDMFZ_cjs.logFcmToken(t))
1706
1717
  });
1707
1718
  if (tokens.length === 0) {
1708
- chunkBXAKL2TF_cjs.notifyLog.skip("PUSH", "no active FCM tokens for target", {
1719
+ chunkPA6YDMFZ_cjs.notifyLog.skip("PUSH", "no active FCM tokens for target", {
1709
1720
  triggerKey,
1710
1721
  orderId,
1711
1722
  audienceType,
@@ -1715,6 +1726,13 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1715
1726
  return;
1716
1727
  }
1717
1728
  for (const token of tokens) {
1729
+ chunkPA6YDMFZ_cjs.notifyLog.push("FCM target", {
1730
+ triggerKey,
1731
+ orderId,
1732
+ audienceType,
1733
+ targetId,
1734
+ fcmToken: chunkPA6YDMFZ_cjs.logFcmToken(token)
1735
+ });
1718
1736
  const res = await sendFcmPushNotification(dataSource, entityMap, {
1719
1737
  token,
1720
1738
  title,
@@ -1725,19 +1743,19 @@ async function sendPushNotificationForTrigger(triggerKey, orderId, audienceType,
1725
1743
  }
1726
1744
  });
1727
1745
  if (res.success) {
1728
- chunkBXAKL2TF_cjs.notifyLog.push("FCM sent", {
1746
+ chunkPA6YDMFZ_cjs.notifyLog.push("FCM sent", {
1729
1747
  triggerKey,
1730
1748
  orderId,
1731
1749
  audienceType,
1732
- token: chunkBXAKL2TF_cjs.maskNotifyToken(token),
1750
+ fcmToken: chunkPA6YDMFZ_cjs.logFcmToken(token),
1733
1751
  messageId: res.messageId ?? null
1734
1752
  });
1735
1753
  } else {
1736
- chunkBXAKL2TF_cjs.notifyLog.error("PUSH", "FCM send failed", {
1754
+ chunkPA6YDMFZ_cjs.notifyLog.error("PUSH", "FCM send failed", {
1737
1755
  triggerKey,
1738
1756
  orderId,
1739
1757
  audienceType,
1740
- token: chunkBXAKL2TF_cjs.maskNotifyToken(token),
1758
+ fcmToken: chunkPA6YDMFZ_cjs.logFcmToken(token),
1741
1759
  error: res.error ?? "unknown"
1742
1760
  });
1743
1761
  }
@@ -1883,11 +1901,11 @@ chunkUSNT2KNT_cjs.__name(formatBodyForEmailHtml, "formatBodyForEmailHtml");
1883
1901
  async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables, contactEmail, dataSource, entityMap, getCms) {
1884
1902
  const template = await loadBoundTemplate(triggerKey, "email", audienceType, dataSource, entityMap);
1885
1903
  if (!template) {
1886
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "no bound/default email template", {
1904
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "no bound/default email template", {
1887
1905
  triggerKey,
1888
1906
  orderId,
1889
1907
  audienceType,
1890
- to: chunkBXAKL2TF_cjs.maskNotifyEmail(contactEmail)
1908
+ to: chunkPA6YDMFZ_cjs.maskNotifyEmail(contactEmail)
1891
1909
  });
1892
1910
  return;
1893
1911
  }
@@ -1925,11 +1943,11 @@ async function sendEmailForTrigger(triggerKey, orderId, audienceType, variables,
1925
1943
  attachInvoice: true
1926
1944
  } : {}
1927
1945
  });
1928
- chunkBXAKL2TF_cjs.notifyLog.email("queued", {
1946
+ chunkPA6YDMFZ_cjs.notifyLog.email("queued", {
1929
1947
  triggerKey,
1930
1948
  audienceType,
1931
1949
  orderId,
1932
- to: chunkBXAKL2TF_cjs.maskNotifyEmail(contactEmail),
1950
+ to: chunkPA6YDMFZ_cjs.maskNotifyEmail(contactEmail),
1933
1951
  subject,
1934
1952
  attachInvoice: shouldAttachInvoice
1935
1953
  });
@@ -1938,16 +1956,16 @@ chunkUSNT2KNT_cjs.__name(sendEmailForTrigger, "sendEmailForTrigger");
1938
1956
  async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dataSource, entityMap, getCms) {
1939
1957
  const template = await loadBoundTemplate(triggerKey, "whatsapp", "customers", dataSource, entityMap);
1940
1958
  if (!template) {
1941
- chunkBXAKL2TF_cjs.notifyLog.skip("WHATSAPP", "no bound/default WhatsApp template", {
1959
+ chunkPA6YDMFZ_cjs.notifyLog.skip("WHATSAPP", "no bound/default WhatsApp template", {
1942
1960
  triggerKey,
1943
1961
  orderId,
1944
- phone: chunkBXAKL2TF_cjs.maskNotifyPhone(phone)
1962
+ phone: chunkPA6YDMFZ_cjs.maskNotifyPhone(phone)
1945
1963
  });
1946
1964
  return;
1947
1965
  }
1948
1966
  const paramOrder = template.providerMeta?.paramOrder ?? [];
1949
1967
  if (paramOrder.length === 0) {
1950
- chunkBXAKL2TF_cjs.notifyLog.skip("WHATSAPP", "template has no paramOrder \u2014 variables may send blank/wrong", {
1968
+ chunkPA6YDMFZ_cjs.notifyLog.skip("WHATSAPP", "template has no paramOrder \u2014 variables may send blank/wrong", {
1951
1969
  triggerKey,
1952
1970
  orderId
1953
1971
  });
@@ -1958,10 +1976,10 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
1958
1976
  name: template.name
1959
1977
  });
1960
1978
  if (!metaTemplateName) {
1961
- chunkBXAKL2TF_cjs.notifyLog.skip("WHATSAPP", "template has no Meta template name", {
1979
+ chunkPA6YDMFZ_cjs.notifyLog.skip("WHATSAPP", "template has no Meta template name", {
1962
1980
  triggerKey,
1963
1981
  orderId,
1964
- phone: chunkBXAKL2TF_cjs.maskNotifyPhone(phone),
1982
+ phone: chunkPA6YDMFZ_cjs.maskNotifyPhone(phone),
1965
1983
  templateId: template.id
1966
1984
  });
1967
1985
  return;
@@ -1976,28 +1994,28 @@ async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dat
1976
1994
  templateParamOrder: paramOrder
1977
1995
  });
1978
1996
  if (!sent) {
1979
- chunkBXAKL2TF_cjs.notifyLog.error("WHATSAPP", "send failed / not queued", {
1997
+ chunkPA6YDMFZ_cjs.notifyLog.error("WHATSAPP", "send failed / not queued", {
1980
1998
  triggerKey,
1981
1999
  orderId,
1982
- phone: chunkBXAKL2TF_cjs.maskNotifyPhone(phone),
2000
+ phone: chunkPA6YDMFZ_cjs.maskNotifyPhone(phone),
1983
2001
  hint: "Register whatsappPlugin() + queuePlugin() in getCms(), or set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID"
1984
2002
  });
1985
2003
  } else {
1986
- chunkBXAKL2TF_cjs.notifyLog.whatsapp("queued/sent", {
2004
+ chunkPA6YDMFZ_cjs.notifyLog.whatsapp("queued/sent", {
1987
2005
  triggerKey,
1988
2006
  orderId,
1989
- phone: chunkBXAKL2TF_cjs.maskNotifyPhone(phone),
2007
+ phone: chunkPA6YDMFZ_cjs.maskNotifyPhone(phone),
1990
2008
  metaTemplateName
1991
2009
  });
1992
2010
  }
1993
2011
  }
1994
2012
  chunkUSNT2KNT_cjs.__name(sendWhatsAppForTrigger, "sendWhatsAppForTrigger");
1995
2013
  async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms) {
1996
- chunkBXAKL2TF_cjs.notifyLog.trigger("dispatcher received", {
2014
+ chunkPA6YDMFZ_cjs.notifyLog.trigger("dispatcher received", {
1997
2015
  triggerKey,
1998
2016
  orderId: payload.orderId,
1999
2017
  orderNumber: payload.orderNumber,
2000
- phone: chunkBXAKL2TF_cjs.maskNotifyPhone(payload.customerPhone),
2018
+ phone: chunkPA6YDMFZ_cjs.maskNotifyPhone(payload.customerPhone),
2001
2019
  vendorId: payload.vendorId ?? null
2002
2020
  });
2003
2021
  const [emailChannelEnabled, whatsappChannelEnabled, pushChannelEnabled] = await Promise.all([
@@ -2005,7 +2023,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2005
2023
  isWhatsappNotificationsEnabled(dataSource, entityMap),
2006
2024
  isPushNotificationsEnabled(dataSource, entityMap)
2007
2025
  ]);
2008
- chunkBXAKL2TF_cjs.notifyLog.trigger("channel switches", {
2026
+ chunkPA6YDMFZ_cjs.notifyLog.trigger("channel switches", {
2009
2027
  triggerKey,
2010
2028
  orderId: payload.orderId,
2011
2029
  email: emailChannelEnabled,
@@ -2013,7 +2031,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2013
2031
  push: pushChannelEnabled
2014
2032
  });
2015
2033
  if (!emailChannelEnabled && !whatsappChannelEnabled && !pushChannelEnabled) {
2016
- chunkBXAKL2TF_cjs.notifyLog.skip("ALL", "Email, WhatsApp, and Mobile Push are disabled in event_notifications", {
2034
+ chunkPA6YDMFZ_cjs.notifyLog.skip("ALL", "Email, WhatsApp, and Mobile Push are disabled in event_notifications", {
2017
2035
  triggerKey,
2018
2036
  orderId: payload.orderId
2019
2037
  });
@@ -2021,7 +2039,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2021
2039
  }
2022
2040
  const triggerEnabled = await isTriggerCatalogEnabled(triggerKey, dataSource, entityMap);
2023
2041
  if (!triggerEnabled) {
2024
- chunkBXAKL2TF_cjs.notifyLog.skip("TRIGGER", "trigger catalog disabled", {
2042
+ chunkPA6YDMFZ_cjs.notifyLog.skip("TRIGGER", "trigger catalog disabled", {
2025
2043
  triggerKey,
2026
2044
  orderId: payload.orderId
2027
2045
  });
@@ -2034,11 +2052,11 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2034
2052
  const variables = mergeTriggerVariables(payload, context?.variables);
2035
2053
  const contactEmail = context?.contact.email?.trim() || "";
2036
2054
  const contactPhone = context?.contact.phone?.trim() || payload.customerPhone?.trim() || "";
2037
- chunkBXAKL2TF_cjs.notifyLog.trigger("recipients resolved", {
2055
+ chunkPA6YDMFZ_cjs.notifyLog.trigger("recipients resolved", {
2038
2056
  triggerKey,
2039
2057
  orderId: payload.orderId,
2040
- contactEmail: chunkBXAKL2TF_cjs.maskNotifyEmail(contactEmail),
2041
- contactPhone: chunkBXAKL2TF_cjs.maskNotifyPhone(contactPhone)
2058
+ contactEmail: chunkPA6YDMFZ_cjs.maskNotifyEmail(contactEmail),
2059
+ contactPhone: chunkPA6YDMFZ_cjs.maskNotifyPhone(contactPhone)
2042
2060
  });
2043
2061
  if (emailChannelEnabled) {
2044
2062
  const [customerEnabled, vendorEnabled, adminEnabled] = await Promise.all([
@@ -2046,7 +2064,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2046
2064
  isAudienceEmailEnabled(dataSource, entityMap, "vendor"),
2047
2065
  isAudienceEmailEnabled(dataSource, entityMap, "admin")
2048
2066
  ]);
2049
- chunkBXAKL2TF_cjs.notifyLog.email("audience switches", {
2067
+ chunkPA6YDMFZ_cjs.notifyLog.email("audience switches", {
2050
2068
  triggerKey,
2051
2069
  orderId: payload.orderId,
2052
2070
  customer: customerEnabled,
@@ -2058,7 +2076,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2058
2076
  if (assigneeEmail) {
2059
2077
  await sendEmailForTrigger(triggerKey, payload.orderId, "customers", variables, assigneeEmail, dataSource, entityMap, getCms);
2060
2078
  } else {
2061
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "order_assigned_assignee has no assignee email", {
2079
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "order_assigned_assignee has no assignee email", {
2062
2080
  triggerKey,
2063
2081
  orderId: payload.orderId
2064
2082
  });
@@ -2066,12 +2084,12 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2066
2084
  } else if (customerEnabled && contactEmail) {
2067
2085
  await sendEmailForTrigger(triggerKey, payload.orderId, "customers", variables, contactEmail, dataSource, entityMap, getCms);
2068
2086
  } else if (!customerEnabled) {
2069
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "customer email audience disabled", {
2087
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "customer email audience disabled", {
2070
2088
  triggerKey,
2071
2089
  orderId: payload.orderId
2072
2090
  });
2073
2091
  } else {
2074
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "no customer email on order contact", {
2092
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "no customer email on order contact", {
2075
2093
  triggerKey,
2076
2094
  orderId: payload.orderId
2077
2095
  });
@@ -2081,7 +2099,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2081
2099
  if (multiVendorSettings.enabled !== "false" && multiVendorSettings.enabled !== "0") {
2082
2100
  const vendorEmails = await getOrderVendorEmails(payload.orderId, payload.vendorId, dataSource, entityMap);
2083
2101
  if (vendorEmails.length === 0) {
2084
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "no vendor emails for order", {
2102
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "no vendor emails for order", {
2085
2103
  triggerKey,
2086
2104
  orderId: payload.orderId,
2087
2105
  vendorId: payload.vendorId ?? null
@@ -2091,7 +2109,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2091
2109
  await sendEmailForTrigger(triggerKey, payload.orderId, "vendors", variables, vEmail, dataSource, entityMap, getCms);
2092
2110
  }
2093
2111
  } else {
2094
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "multi-vendor off \u2014 skip vendor email", {
2112
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "multi-vendor off \u2014 skip vendor email", {
2095
2113
  triggerKey,
2096
2114
  orderId: payload.orderId
2097
2115
  });
@@ -2100,7 +2118,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2100
2118
  if (adminEnabled && triggerKey !== "order_assigned_assignee") {
2101
2119
  const adminEmails = await getAdminRecipientEmails(dataSource, entityMap);
2102
2120
  if (adminEmails.length === 0) {
2103
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "no admin recipient emails", {
2121
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "no admin recipient emails", {
2104
2122
  triggerKey,
2105
2123
  orderId: payload.orderId
2106
2124
  });
@@ -2110,7 +2128,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2110
2128
  }
2111
2129
  }
2112
2130
  } else {
2113
- chunkBXAKL2TF_cjs.notifyLog.skip("EMAIL", "email channel disabled", {
2131
+ chunkPA6YDMFZ_cjs.notifyLog.skip("EMAIL", "email channel disabled", {
2114
2132
  triggerKey,
2115
2133
  orderId: payload.orderId
2116
2134
  });
@@ -2121,23 +2139,23 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2121
2139
  isAudiencePushEnabled(dataSource, entityMap, "vendor"),
2122
2140
  isAudiencePushEnabled(dataSource, entityMap, "admin")
2123
2141
  ]);
2124
- chunkBXAKL2TF_cjs.notifyLog.push("audience switches", {
2142
+ chunkPA6YDMFZ_cjs.notifyLog.push("audience switches", {
2125
2143
  triggerKey,
2126
2144
  orderId: payload.orderId,
2127
2145
  customer: pushCustomerEnabled,
2128
2146
  vendor: pushVendorEnabled,
2129
2147
  admin: pushAdminEnabled
2130
2148
  });
2131
- const targetCustomerId = triggerKey === "order_assigned_assignee" ? context?.order?.assignedUser?.id : context?.order?.customerContactId || context?.order?.contactId || context?.order?.userId || context?.order?.id;
2149
+ const targetCustomerId = triggerKey === "order_assigned_assignee" ? context?.order?.assignedUser?.id : context?.contact?.userId;
2132
2150
  if (pushCustomerEnabled && targetCustomerId) {
2133
2151
  await sendPushNotificationForTrigger(triggerKey, payload.orderId, "customers", String(targetCustomerId), variables, dataSource, entityMap);
2134
2152
  } else if (!pushCustomerEnabled) {
2135
- chunkBXAKL2TF_cjs.notifyLog.skip("PUSH", "customer push audience disabled", {
2153
+ chunkPA6YDMFZ_cjs.notifyLog.skip("PUSH", "customer push audience disabled", {
2136
2154
  triggerKey,
2137
2155
  orderId: payload.orderId
2138
2156
  });
2139
2157
  } else {
2140
- chunkBXAKL2TF_cjs.notifyLog.skip("PUSH", "no customer user/contact id for push", {
2158
+ chunkPA6YDMFZ_cjs.notifyLog.skip("PUSH", "no customer user/contact id for push", {
2141
2159
  triggerKey,
2142
2160
  orderId: payload.orderId
2143
2161
  });
@@ -2145,7 +2163,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2145
2163
  if (pushVendorEnabled && payload.vendorId && triggerKey !== "order_assigned_assignee") {
2146
2164
  await sendPushNotificationForTrigger(triggerKey, payload.orderId, "vendors", String(payload.vendorId), variables, dataSource, entityMap);
2147
2165
  } else if (pushVendorEnabled && triggerKey !== "order_assigned_assignee" && !payload.vendorId) {
2148
- chunkBXAKL2TF_cjs.notifyLog.skip("PUSH", "no vendorId on order \u2014 skip vendor push", {
2166
+ chunkPA6YDMFZ_cjs.notifyLog.skip("PUSH", "no vendorId on order \u2014 skip vendor push", {
2149
2167
  triggerKey,
2150
2168
  orderId: payload.orderId
2151
2169
  });
@@ -2154,7 +2172,7 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2154
2172
  await sendPushNotificationForTrigger(triggerKey, payload.orderId, "admin", "admin", variables, dataSource, entityMap);
2155
2173
  }
2156
2174
  } else {
2157
- chunkBXAKL2TF_cjs.notifyLog.skip("PUSH", "push channel disabled", {
2175
+ chunkPA6YDMFZ_cjs.notifyLog.skip("PUSH", "push channel disabled", {
2158
2176
  triggerKey,
2159
2177
  orderId: payload.orderId
2160
2178
  });
@@ -2164,13 +2182,13 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
2164
2182
  if (targetPhone) {
2165
2183
  await sendWhatsAppForTrigger(triggerKey, payload.orderId, targetPhone, variables, dataSource, entityMap, getCms);
2166
2184
  } else {
2167
- chunkBXAKL2TF_cjs.notifyLog.skip("WHATSAPP", "no recipient phone", {
2185
+ chunkPA6YDMFZ_cjs.notifyLog.skip("WHATSAPP", "no recipient phone", {
2168
2186
  triggerKey,
2169
2187
  orderId: payload.orderId
2170
2188
  });
2171
2189
  }
2172
2190
  } else {
2173
- chunkBXAKL2TF_cjs.notifyLog.skip("WHATSAPP", "WhatsApp channel disabled", {
2191
+ chunkPA6YDMFZ_cjs.notifyLog.skip("WHATSAPP", "WhatsApp channel disabled", {
2174
2192
  triggerKey,
2175
2193
  orderId: payload.orderId
2176
2194
  });
@@ -2185,9 +2203,9 @@ function initWhatsappTriggerDispatcher(deps) {
2185
2203
  const { dataSource, entityMap, getCms } = deps;
2186
2204
  void dataSource.query(`ALTER TYPE "order_notification_bindings_channel_enum" ADD VALUE IF NOT EXISTS 'mobile'`).catch(() => {
2187
2205
  });
2188
- chunkBXAKL2TF_cjs.notificationTriggerEmitter.onAnyTrigger((triggerKey, payload) => {
2206
+ chunkPA6YDMFZ_cjs.notificationTriggerEmitter.onAnyTrigger((triggerKey, payload) => {
2189
2207
  void handleTrigger(triggerKey, payload, dataSource, entityMap, getCms).catch((err) => {
2190
- chunkBXAKL2TF_cjs.notifyLog.error("TRIGGER", "dispatcher handleTrigger failed", {
2208
+ chunkPA6YDMFZ_cjs.notifyLog.error("TRIGGER", "dispatcher handleTrigger failed", {
2191
2209
  triggerKey,
2192
2210
  orderId: payload.orderId,
2193
2211
  error: err instanceof Error ? err.message : String(err),
@@ -2195,7 +2213,7 @@ function initWhatsappTriggerDispatcher(deps) {
2195
2213
  });
2196
2214
  });
2197
2215
  });
2198
- chunkBXAKL2TF_cjs.notifyLog.trigger("dispatcher initialized", {
2216
+ chunkPA6YDMFZ_cjs.notifyLog.trigger("dispatcher initialized", {
2199
2217
  channels: [
2200
2218
  "email",
2201
2219
  "whatsapp",
@@ -2269,7 +2287,7 @@ async function emitOrderNotificationTrigger(dataSource, entityMap, triggerKey, p
2269
2287
  if (settings.whatsapp_enabled !== "false" && settings.whatsapp_enabled !== "0") enabledChannels.push("whatsapp");
2270
2288
  if (settings.sms_enabled !== "false" && settings.sms_enabled !== "0") enabledChannels.push("sms");
2271
2289
  if (settings.push_enabled !== "false" && settings.push_enabled !== "0") enabledChannels.push("push");
2272
- chunkBXAKL2TF_cjs.notificationTriggerEmitter.emitTrigger(triggerKey, payload);
2290
+ chunkPA6YDMFZ_cjs.notificationTriggerEmitter.emitTrigger(triggerKey, payload);
2273
2291
  return {
2274
2292
  ok: true,
2275
2293
  channels: enabledChannels
@@ -190,23 +190,34 @@ function canOnboardVendors(user) {
190
190
  }
191
191
  __name(canOnboardVendors, "canOnboardVendors");
192
192
  function resolveVendorScopeFromSessionUser(user) {
193
- if (!user?.email) return {
194
- type: "deny"
195
- };
196
- if (isPlatformAdministrator(user)) return {
197
- type: "all"
198
- };
193
+ if (!user?.email) {
194
+ console.log("[ORDERS-DEBUG][RESOLVE_VENDOR_SCOPE] No user email -> deny");
195
+ return {
196
+ type: "deny"
197
+ };
198
+ }
199
+ if (isPlatformAdministrator(user)) {
200
+ console.log("[ORDERS-DEBUG][RESOLVE_VENDOR_SCOPE] User is Platform Admin -> all");
201
+ return {
202
+ type: "all"
203
+ };
204
+ }
199
205
  const vendorIds = user.vendorIds ?? [];
200
- if (vendorIds.length === 0) return {
201
- type: "deny"
202
- };
206
+ if (vendorIds.length === 0) {
207
+ console.log("[ORDERS-DEBUG][RESOLVE_VENDOR_SCOPE] User has 0 vendorIds -> deny. User:", user.email);
208
+ return {
209
+ type: "deny"
210
+ };
211
+ }
203
212
  const preferred = user.activeVendorId ?? vendorIds[0];
204
213
  const vendorId = vendorIds.includes(preferred) ? preferred : vendorIds[0];
205
- return {
214
+ const res = {
206
215
  type: "vendor",
207
216
  vendorId,
208
217
  vendorIds
209
218
  };
219
+ console.log("[ORDERS-DEBUG][RESOLVE_VENDOR_SCOPE] User:", user.email, "-> scope:", res);
220
+ return res;
210
221
  }
211
222
  __name(resolveVendorScopeFromSessionUser, "resolveVendorScopeFromSessionUser");
212
223
  function vendorPortalFlagsFromUser(input) {
@@ -612,7 +623,7 @@ async function logEntityAccessDecision(dataSource, context, user, entity, action
612
623
  const id = Number(user.id);
613
624
  if (Number.isFinite(id)) {
614
625
  try {
615
- const { loadDbPermissionsForUser } = await import('./rbac-debug-db-5R6XFPSV.js');
626
+ const { loadDbPermissionsForUser } = await import('./rbac-debug-db-DFZWZ6GV.js');
616
627
  dbPermissions = await loadDbPermissionsForUser(dataSource, id);
617
628
  } catch (e) {
618
629
  dbPermissions = {