@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,19 +1,19 @@
1
1
  'use strict';
2
2
 
3
+ var chunkTTOEY7AH_cjs = require('./chunk-TTOEY7AH.cjs');
4
+ var chunkKB7EBYPR_cjs = require('./chunk-KB7EBYPR.cjs');
5
+ var chunkKJB5LBFQ_cjs = require('./chunk-KJB5LBFQ.cjs');
3
6
  var chunk3LQS4ATQ_cjs = require('./chunk-3LQS4ATQ.cjs');
4
- var chunk6MM5OMRL_cjs = require('./chunk-6MM5OMRL.cjs');
5
7
  var chunkJRW3GQD4_cjs = require('./chunk-JRW3GQD4.cjs');
6
8
  var chunkY54WDY2O_cjs = require('./chunk-Y54WDY2O.cjs');
7
9
  var chunkPRXVSSIF_cjs = require('./chunk-PRXVSSIF.cjs');
8
- var chunk747MJJCZ_cjs = require('./chunk-747MJJCZ.cjs');
9
- var chunkOXFC3DAM_cjs = require('./chunk-OXFC3DAM.cjs');
10
10
  var chunk4MNVIGVJ_cjs = require('./chunk-4MNVIGVJ.cjs');
11
11
  var chunkBQQMTQ4C_cjs = require('./chunk-BQQMTQ4C.cjs');
12
12
  var chunkRQCXRCYM_cjs = require('./chunk-RQCXRCYM.cjs');
13
13
  var chunkEYUBL7YH_cjs = require('./chunk-EYUBL7YH.cjs');
14
14
  var chunk3ASNJS2H_cjs = require('./chunk-3ASNJS2H.cjs');
15
- var chunkQXAQ3V7R_cjs = require('./chunk-QXAQ3V7R.cjs');
16
- var chunkLXWF6T7F_cjs = require('./chunk-LXWF6T7F.cjs');
15
+ var chunkFNLF6G2N_cjs = require('./chunk-FNLF6G2N.cjs');
16
+ var chunkLCZZ3S4I_cjs = require('./chunk-LCZZ3S4I.cjs');
17
17
  var chunk4WZNRVEZ_cjs = require('./chunk-4WZNRVEZ.cjs');
18
18
  var chunkWXH3GMCF_cjs = require('./chunk-WXH3GMCF.cjs');
19
19
  var chunkXHPRD45G_cjs = require('./chunk-XHPRD45G.cjs');
@@ -123,7 +123,7 @@ async function loadUserVendorContext(dataSource, userId, preferredVendorId) {
123
123
  `, [
124
124
  primary.vendorRoleId
125
125
  ]);
126
- vendorEntityPerms = chunkLXWF6T7F_cjs.permissionRowsToRecord(permRows);
126
+ vendorEntityPerms = chunkLCZZ3S4I_cjs.permissionRowsToRecord(permRows);
127
127
  } catch (err) {
128
128
  if (!isMissingVendorRoleSchemaError(err)) throw err;
129
129
  }
@@ -230,7 +230,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
230
230
  ]);
231
231
  const resolvedId = Number(byEmailRows[0]?.id);
232
232
  if (!Number.isFinite(resolvedId)) {
233
- chunkLXWF6T7F_cjs.logRbac("hydrateVendorSessionUser: unable to resolve numeric user id", {
233
+ chunkLCZZ3S4I_cjs.logRbac("hydrateVendorSessionUser: unable to resolve numeric user id", {
234
234
  email: user.email,
235
235
  rawSessionId: user.id ?? null
236
236
  });
@@ -250,7 +250,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
250
250
  const groupName = rows[0]?.groupName ?? user.groupName ?? null;
251
251
  const groupId = rows[0]?.groupId ?? user.groupId ?? void 0;
252
252
  const adminAccess = rows[0]?.adminAccess ?? user.adminAccess;
253
- const isRBACAdmin = user.isRBACAdmin ?? chunkLXWF6T7F_cjs.isSuperAdmin({
253
+ const isRBACAdmin = user.isRBACAdmin ?? chunkLCZZ3S4I_cjs.isSuperAdmin({
254
254
  groupId,
255
255
  groupName,
256
256
  isRBACAdmin: user.isRBACAdmin
@@ -263,7 +263,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
263
263
  };
264
264
  if (multiVendorEnabled) {
265
265
  ctx = await loadUserVendorContext(dataSource, id, user.activeVendorId);
266
- flags = chunkLXWF6T7F_cjs.vendorPortalFlagsFromUser({
266
+ flags = chunkLCZZ3S4I_cjs.vendorPortalFlagsFromUser({
267
267
  email: user.email,
268
268
  isRBACAdmin,
269
269
  groupName,
@@ -298,7 +298,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
298
298
  isVendorPortal: flags.isVendorPortal,
299
299
  isVendorOwner: flags.isVendorOwner
300
300
  };
301
- chunkLXWF6T7F_cjs.logRbac("hydrateVendorSessionUser", {
301
+ chunkLCZZ3S4I_cjs.logRbac("hydrateVendorSessionUser", {
302
302
  email: user.email,
303
303
  userId: id,
304
304
  groupName,
@@ -911,7 +911,7 @@ function repoHasVendorIdColumn(repo) {
911
911
  }
912
912
  chunkXHPRD45G_cjs.__name(repoHasVendorIdColumn, "repoHasVendorIdColumn");
913
913
  function resourceUsesVendorScope(resource) {
914
- return resource === "vendors" || chunkLXWF6T7F_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
914
+ return resource === "vendors" || chunkLCZZ3S4I_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
915
915
  }
916
916
  chunkXHPRD45G_cjs.__name(resourceUsesVendorScope, "resourceUsesVendorScope");
917
917
  function mergeWhereClause(where, extra) {
@@ -1401,7 +1401,7 @@ async function ensureVendorCustomersForOrder(dataSource, entityMap, vendorIds, c
1401
1401
  }
1402
1402
  let customerId = null;
1403
1403
  if (entityMap.customer) {
1404
- const ensured = await chunkQXAQ3V7R_cjs.ensureCustomerRecord(dataSource, entityMap.customer, {
1404
+ const ensured = await chunkFNLF6G2N_cjs.ensureCustomerRecord(dataSource, entityMap.customer, {
1405
1405
  name,
1406
1406
  email,
1407
1407
  phone,
@@ -1708,6 +1708,82 @@ async function recordOrderAssigneeHistory(dataSource, entityMap, orderId, userId
1708
1708
  return nextSortOrder;
1709
1709
  }
1710
1710
  chunkXHPRD45G_cjs.__name(recordOrderAssigneeHistory, "recordOrderAssigneeHistory");
1711
+ async function validateAssigneeOrderPermission(dataSource, entityMap, userId) {
1712
+ if (!Number.isFinite(userId) || userId <= 0) return {
1713
+ valid: true
1714
+ };
1715
+ if (entityMap.users) {
1716
+ const uRepo = dataSource.getRepository(entityMap.users);
1717
+ const u = await uRepo.findOne({
1718
+ where: {
1719
+ id: userId,
1720
+ deleted: false
1721
+ },
1722
+ relations: [
1723
+ "group"
1724
+ ]
1725
+ });
1726
+ if (!u) {
1727
+ return {
1728
+ valid: false,
1729
+ error: "Assignee user not found."
1730
+ };
1731
+ }
1732
+ const userRow = u;
1733
+ if (userRow.adminAccess) {
1734
+ return {
1735
+ valid: true
1736
+ };
1737
+ }
1738
+ if (userRow.group?.name && userRow.group.name.toLowerCase() === "customer") {
1739
+ return {
1740
+ valid: false,
1741
+ error: "Customer accounts cannot be assigned to orders."
1742
+ };
1743
+ }
1744
+ }
1745
+ if (entityMap.vendor_users) {
1746
+ const vuRepo = dataSource.getRepository(entityMap.vendor_users);
1747
+ const vuLinks = await vuRepo.find({
1748
+ where: {
1749
+ userId
1750
+ },
1751
+ relations: [
1752
+ "vendorRole",
1753
+ "vendorRole.permissions"
1754
+ ]
1755
+ });
1756
+ if (vuLinks && vuLinks.length > 0) {
1757
+ let anyRoleHasAccess = false;
1758
+ for (const vu of vuLinks) {
1759
+ const r = vu.vendorRole;
1760
+ if (r) {
1761
+ if (r.isOwnerRole) {
1762
+ anyRoleHasAccess = true;
1763
+ break;
1764
+ }
1765
+ if (Array.isArray(r.permissions)) {
1766
+ const orderPerm = r.permissions.find((p) => String(p?.entity).toLowerCase() === "orders");
1767
+ if (orderPerm && orderPerm.canRead) {
1768
+ anyRoleHasAccess = true;
1769
+ break;
1770
+ }
1771
+ }
1772
+ }
1773
+ }
1774
+ if (!anyRoleHasAccess) {
1775
+ return {
1776
+ valid: false,
1777
+ error: "Cannot assign order: This team member does not have permission to access orders. Please grant order access in Roles & Permissions."
1778
+ };
1779
+ }
1780
+ }
1781
+ }
1782
+ return {
1783
+ valid: true
1784
+ };
1785
+ }
1786
+ chunkXHPRD45G_cjs.__name(validateAssigneeOrderPermission, "validateAssigneeOrderPermission");
1711
1787
  var LIST_QUERY_RESERVED = /* @__PURE__ */ new Set([
1712
1788
  "page",
1713
1789
  "limit",
@@ -4515,7 +4591,7 @@ function createCrudHandler(dataSource, entityMap, options) {
4515
4591
  });
4516
4592
  }
4517
4593
  }
4518
- const savedCustomer = await chunkQXAQ3V7R_cjs.ensureCustomerRecord(dataSource, entityMap["customer"], {
4594
+ const savedCustomer = await chunkFNLF6G2N_cjs.ensureCustomerRecord(dataSource, entityMap["customer"], {
4519
4595
  name,
4520
4596
  email,
4521
4597
  phone,
@@ -5122,6 +5198,16 @@ function createCrudHandler(dataSource, entityMap, options) {
5122
5198
  persistBody.orderNumber = `ORD00${randomPart}`;
5123
5199
  persistBody.qrToken = crypto2__default.default.randomBytes(16).toString("hex");
5124
5200
  }
5201
+ if (resource === "orders" && persistBody.assignedUserId) {
5202
+ const assignCheck = await validateAssigneeOrderPermission(dataSource, entityMap, Number(persistBody.assignedUserId));
5203
+ if (!assignCheck.valid) {
5204
+ return json({
5205
+ error: assignCheck.error ?? "Invalid order assignee"
5206
+ }, {
5207
+ status: 400
5208
+ });
5209
+ }
5210
+ }
5125
5211
  await retireSoftDeletedUniquesFromBody(repo, persistBody);
5126
5212
  created = await repo.save(repo.create(persistBody));
5127
5213
  if (resource === "orders") {
@@ -5323,7 +5409,7 @@ function createCrudHandler(dataSource, entityMap, options) {
5323
5409
  const orderIdForNotify = created.id;
5324
5410
  const finalCreatedStatus = String(created.status ?? createdStatus ?? "pending").toLowerCase();
5325
5411
  const initialPayStatus = String(persistBody.paymentStatus ?? body.paymentStatus ?? "unpaid").toLowerCase();
5326
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
5412
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
5327
5413
  if (finalCreatedStatus === "pending") {
5328
5414
  if (initialPayStatus === "failed") {
5329
5415
  fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
@@ -6230,6 +6316,14 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6230
6316
  if ("assignedUserId" in rawBody && rawBody.assignedUserId !== void 0) {
6231
6317
  const aId = Number(rawBody.assignedUserId);
6232
6318
  if (Number.isFinite(aId) && aId > 0) {
6319
+ const assignCheck = await validateAssigneeOrderPermission(dataSource, entityMap, aId);
6320
+ if (!assignCheck.valid) {
6321
+ return json({
6322
+ error: assignCheck.error ?? "Invalid order assignee"
6323
+ }, {
6324
+ status: 400
6325
+ });
6326
+ }
6233
6327
  if (scopePutEarly.type === "vendor" && entityMap.vendor_users) {
6234
6328
  const vuRepo = dataSource.getRepository(entityMap.vendor_users);
6235
6329
  const vuLink = await vuRepo.findOne({
@@ -6526,7 +6620,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6526
6620
  const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
6527
6621
  const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
6528
6622
  if (assigneeUpdated) {
6529
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
6623
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
6530
6624
  fireOrderNotificationTrigger("order_assigned", updatedOrder.id, {
6531
6625
  dataSource,
6532
6626
  entityMap
@@ -6543,7 +6637,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6543
6637
  const payments = Array.isArray(updatedOrder.payments) ? updatedOrder.payments : [];
6544
6638
  const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
6545
6639
  const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
6546
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
6640
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
6547
6641
  if (newStatus === "pending") {
6548
6642
  if (curPayStatus === "failed") {
6549
6643
  fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
@@ -7111,6 +7205,14 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7111
7205
  const aId = Number(rawBody.assignedUserId);
7112
7206
  console.log("[ORDERS-DEBUG][UPDATE] Updating assignedUserId to:", aId);
7113
7207
  if (Number.isFinite(aId) && aId > 0) {
7208
+ const assignCheck = await validateAssigneeOrderPermission(dataSource, entityMap, aId);
7209
+ if (!assignCheck.valid) {
7210
+ return json({
7211
+ error: assignCheck.error ?? "Invalid order assignee"
7212
+ }, {
7213
+ status: 400
7214
+ });
7215
+ }
7114
7216
  if (scopePut.type === "vendor" && entityMap.vendor_users) {
7115
7217
  const vuRepo = dataSource.getRepository(entityMap.vendor_users);
7116
7218
  const vuLink = await vuRepo.findOne({
@@ -7251,7 +7353,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7251
7353
  });
7252
7354
  }
7253
7355
  if (ordStatus === "pending" || ordStatus === "confirmed") {
7254
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
7356
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
7255
7357
  fireOrderNotificationTrigger("order_placed", pOrder, {
7256
7358
  dataSource,
7257
7359
  entityMap
@@ -7265,7 +7367,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7265
7367
  }
7266
7368
  }
7267
7369
  } else if (newPayStatus === "failed") {
7268
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
7370
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
7269
7371
  fireOrderNotificationTrigger("payment_failed", pOrder, {
7270
7372
  dataSource,
7271
7373
  entityMap
@@ -7273,7 +7375,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7273
7375
  }).catch(() => {
7274
7376
  });
7275
7377
  } else if (newPayStatus === "refunded") {
7276
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
7378
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
7277
7379
  fireOrderNotificationTrigger("payment_refund_initiated", pOrder, {
7278
7380
  dataSource,
7279
7381
  entityMap
@@ -7400,7 +7502,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7400
7502
  const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
7401
7503
  const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
7402
7504
  if (assigneeUpdated) {
7403
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
7505
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
7404
7506
  fireOrderNotificationTrigger("order_assigned", ord.id, {
7405
7507
  dataSource,
7406
7508
  entityMap
@@ -7417,7 +7519,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7417
7519
  const payments = Array.isArray(ord.payments) ? ord.payments : [];
7418
7520
  const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
7419
7521
  const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
7420
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
7522
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
7421
7523
  if (newStatus === "pending") {
7422
7524
  if (curPayStatus === "failed") {
7423
7525
  fireOrderNotificationTrigger("payment_failed", ord.id, {
@@ -8114,7 +8216,7 @@ function createInviteAcceptHandler(config) {
8114
8216
  }
8115
8217
  const { userId, email, vendorId } = validation.target;
8116
8218
  if (entityMap.contacts) {
8117
- await chunkQXAQ3V7R_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
8219
+ await chunkFNLF6G2N_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
8118
8220
  }
8119
8221
  if (beforeActivate) await beforeActivate(email, userId);
8120
8222
  const hashedPassword = await hashPassword(password);
@@ -9207,7 +9309,7 @@ function createVendorDashboardHandler(config) {
9207
9309
  if (pe) return pe;
9208
9310
  }
9209
9311
  const user = await getSessionUser();
9210
- if (!user || !chunkLXWF6T7F_cjs.isVendorPortalUser(user)) {
9312
+ if (!user || !chunkLCZZ3S4I_cjs.isVendorPortalUser(user)) {
9211
9313
  return json({
9212
9314
  error: "Forbidden"
9213
9315
  }, {
@@ -10769,11 +10871,11 @@ function createUsersApiHandlers(config) {
10769
10871
  adminAccess
10770
10872
  }));
10771
10873
  if (entityMap.contacts) {
10772
- await chunkQXAQ3V7R_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, newUser.id, newUser.email);
10874
+ await chunkFNLF6G2N_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, newUser.id, newUser.email);
10773
10875
  }
10774
10876
  if (entityMap.customer) {
10775
10877
  const phone = typeof body.phone === "string" && body.phone.trim() ? body.phone.trim() : null;
10776
- await chunkQXAQ3V7R_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
10878
+ await chunkFNLF6G2N_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
10777
10879
  id: newUser.id,
10778
10880
  name: String(newUser.name ?? body.name),
10779
10881
  email: String(newUser.email),
@@ -11863,7 +11965,7 @@ function createChatHandlers(config) {
11863
11965
  const notifyEmailAgent = await findLlmAgentByScope(dataSource, entityMap, LLM_AGENT_SCOPE_EMAIL_INTENT_CHATBOT, {
11864
11966
  enabledOnly: false
11865
11967
  });
11866
- const emailTool = chunk747MJJCZ_cjs.resolveChatEmailToolSettings(llmSettings, {
11968
+ const emailTool = chunkTTOEY7AH_cjs.resolveChatEmailToolSettings(llmSettings, {
11867
11969
  chatbotValidationRules: agentRow?.validationRules ?? null,
11868
11970
  notifyAgent: notifyEmailAgent ? {
11869
11971
  systemInstruction: notifyEmailAgent.systemInstruction,
@@ -11873,7 +11975,7 @@ function createChatHandlers(config) {
11873
11975
  const emailPlugin2 = cms.getPlugin("email");
11874
11976
  const convLeadSent = conv.leadEmailSentAt;
11875
11977
  const chatAgentFn = llm.chatAgent?.bind(llm);
11876
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline check", {
11978
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline check", {
11877
11979
  conversationId,
11878
11980
  enabled: emailTool.enabled,
11879
11981
  intentCount: emailTool.intents.length,
@@ -11887,27 +11989,27 @@ function createChatHandlers(config) {
11887
11989
  mergedPromptIncludesNotify: Boolean(notifyEmailAgent?.systemInstruction?.trim())
11888
11990
  });
11889
11991
  if (!emailTool.enabled) {
11890
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11992
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11891
11993
  conversationId,
11892
11994
  reason: "email_tool_disabled"
11893
11995
  });
11894
11996
  } else if (emailTool.intents.length === 0) {
11895
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11997
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11896
11998
  conversationId,
11897
11999
  reason: "no_intents_configured"
11898
12000
  });
11899
12001
  } else if (!emailPlugin2) {
11900
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
12002
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11901
12003
  conversationId,
11902
12004
  reason: "email_plugin_missing"
11903
12005
  });
11904
12006
  } else if (!chatAgentFn) {
11905
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
12007
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11906
12008
  conversationId,
11907
12009
  reason: "llm_chat_agent_unavailable"
11908
12010
  });
11909
12011
  } else if (convLeadSent) {
11910
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
12012
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11911
12013
  conversationId,
11912
12014
  reason: "lead_email_already_sent",
11913
12015
  leadEmailSentAt: convLeadSent
@@ -11920,7 +12022,7 @@ function createChatHandlers(config) {
11920
12022
  }
11921
12023
  });
11922
12024
  if (!contactRow) {
11923
- console.warn(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
12025
+ console.warn(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
11924
12026
  conversationId,
11925
12027
  reason: "contact_not_found",
11926
12028
  contactId
@@ -11928,7 +12030,7 @@ function createChatHandlers(config) {
11928
12030
  } else {
11929
12031
  const c = contactRow;
11930
12032
  try {
11931
- const intent = await chunk747MJJCZ_cjs.detectChatLeadIntent({
12033
+ const intent = await chunkTTOEY7AH_cjs.detectChatLeadIntent({
11932
12034
  chatAgent: chatAgentFn
11933
12035
  }, {
11934
12036
  settings: emailTool,
@@ -11942,15 +12044,15 @@ function createChatHandlers(config) {
11942
12044
  model: agentRow?.model?.trim() || notifyEmailAgent?.model?.trim() || void 0
11943
12045
  });
11944
12046
  if (!intent.intent || !intent.emailTo) {
11945
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "no email sent", {
12047
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "no email sent", {
11946
12048
  conversationId,
11947
12049
  reason: intent.intent ? "missing_email_to" : "no_intent_match",
11948
12050
  intentLabel: intent.intentLabel,
11949
12051
  classifierReason: intent.reason
11950
12052
  });
11951
12053
  } else {
11952
- const intentRecipients = chunk747MJJCZ_cjs.parseIntentRecipientEmails(intent.emailTo);
11953
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
12054
+ const intentRecipients = chunkTTOEY7AH_cjs.parseIntentRecipientEmails(intent.emailTo);
12055
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
11954
12056
  conversationId,
11955
12057
  intent: intent.intent,
11956
12058
  emailTo: intent.emailTo,
@@ -11961,7 +12063,7 @@ function createChatHandlers(config) {
11961
12063
  const brandingSettings = await loadSettingsGroupMap(dataSource, entityMap, "branding");
11962
12064
  const storeSettings = await loadSettingsGroupMap(dataSource, entityMap, "store");
11963
12065
  const companyDetails = chunkEYUBL7YH_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings, storeSettings);
11964
- const leadResult = await chunk747MJJCZ_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
12066
+ const leadResult = await chunkTTOEY7AH_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
11965
12067
  contactName: String(c.name ?? "").trim() || "Visitor",
11966
12068
  contactEmail: String(c.email ?? "").trim(),
11967
12069
  contactPhone: c.phone ?? null,
@@ -11969,7 +12071,7 @@ function createChatHandlers(config) {
11969
12071
  latestMessage: message,
11970
12072
  intentCode: intent.intent,
11971
12073
  intentReason: intent.intentLabel || intent.reason,
11972
- transcript: chunk747MJJCZ_cjs.buildTranscriptForLeadEmail(history, message),
12074
+ transcript: chunkTTOEY7AH_cjs.buildTranscriptForLeadEmail(history, message),
11973
12075
  companyDetails,
11974
12076
  recipients: intentRecipients.length > 0 ? intentRecipients : void 0
11975
12077
  });
@@ -11977,13 +12079,13 @@ function createChatHandlers(config) {
11977
12079
  await convRepo().update(conversationId, {
11978
12080
  leadEmailSentAt: /* @__PURE__ */ new Date()
11979
12081
  });
11980
- console.info(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
12082
+ console.info(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
11981
12083
  conversationId,
11982
12084
  sent: true,
11983
12085
  recipients: leadResult.recipients
11984
12086
  });
11985
12087
  } else {
11986
- console.warn(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
12088
+ console.warn(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
11987
12089
  conversationId,
11988
12090
  sent: false,
11989
12091
  error: leadResult.error ?? "unknown",
@@ -11992,7 +12094,7 @@ function createChatHandlers(config) {
11992
12094
  }
11993
12095
  }
11994
12096
  } catch (intentErr) {
11995
- console.warn(chunk747MJJCZ_cjs.CHAT_EMAIL_LOG, "pipeline error", {
12097
+ console.warn(chunkTTOEY7AH_cjs.CHAT_EMAIL_LOG, "pipeline error", {
11996
12098
  conversationId,
11997
12099
  error: intentErr instanceof Error ? intentErr.message : String(intentErr)
11998
12100
  });
@@ -12009,7 +12111,7 @@ function createChatHandlers(config) {
12009
12111
  });
12010
12112
  if (agentRow && llm.chatAgent) {
12011
12113
  const fromAgent = llmAgentToChatAgentOptions(agentRow);
12012
- const systemPrompt = chunk747MJJCZ_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
12114
+ const systemPrompt = chunkTTOEY7AH_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
12013
12115
  const res = await llm.chatAgent({
12014
12116
  ...fromAgent,
12015
12117
  systemPrompt: systemPrompt || void 0,
@@ -12030,7 +12132,7 @@ ${contextParts.join("\n\n")}` : "";
12030
12132
  agentRow.systemInstruction?.trim(),
12031
12133
  ragSystem
12032
12134
  ].filter(Boolean).join("\n\n");
12033
- systemContent = chunk747MJJCZ_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
12135
+ systemContent = chunkTTOEY7AH_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
12034
12136
  } else {
12035
12137
  systemContent = ragSystem || defaultSystem;
12036
12138
  }
@@ -13285,7 +13387,7 @@ function createDeviceTokensHandlers(config) {
13285
13387
  const title = body.title?.trim() || "Test Push Notification";
13286
13388
  const msgBody = body.body?.trim() || "Firebase Push Notification setup is working!";
13287
13389
  if (!token || token === "validate" || token === "validate_only") {
13288
- const valRes = await chunk747MJJCZ_cjs.validateFcmCredentials(dataSource, entityMap);
13390
+ const valRes = await chunkTTOEY7AH_cjs.validateFcmCredentials(dataSource, entityMap);
13289
13391
  if (!valRes.success) {
13290
13392
  return json({
13291
13393
  success: false,
@@ -13302,7 +13404,7 @@ function createDeviceTokensHandlers(config) {
13302
13404
  clientEmail: valRes.clientEmail
13303
13405
  });
13304
13406
  }
13305
- const res = await chunk747MJJCZ_cjs.sendFcmPushNotification(dataSource, entityMap, {
13407
+ const res = await chunkTTOEY7AH_cjs.sendFcmPushNotification(dataSource, entityMap, {
13306
13408
  token,
13307
13409
  title,
13308
13410
  body: msgBody,
@@ -13856,7 +13958,7 @@ chunkXHPRD45G_cjs.__name(findActiveRefundPolicyForVendor, "findActiveRefundPolic
13856
13958
  // src/api/admin-roles-handlers.ts
13857
13959
  function createAdminRolesHandlers(config) {
13858
13960
  const { dataSource, entityMap, json, getSessionUser } = config;
13859
- const baseEntities = chunkLXWF6T7F_cjs.getPermissionableEntityKeys(entityMap);
13961
+ const baseEntities = chunkLCZZ3S4I_cjs.getPermissionableEntityKeys(entityMap);
13860
13962
  const allowEntities = /* @__PURE__ */ new Set([
13861
13963
  ...baseEntities,
13862
13964
  "users"
@@ -13871,7 +13973,7 @@ function createAdminRolesHandlers(config) {
13871
13973
  }, {
13872
13974
  status: 401
13873
13975
  });
13874
- if (!chunkQXAQ3V7R_cjs.canManageRoles(u) && !chunkLXWF6T7F_cjs.canManageVendorRoles(u)) {
13976
+ if (!chunkFNLF6G2N_cjs.canManageRoles(u) && !chunkLCZZ3S4I_cjs.canManageVendorRoles(u)) {
13875
13977
  return json({
13876
13978
  error: "Forbidden"
13877
13979
  }, {
@@ -13882,11 +13984,11 @@ function createAdminRolesHandlers(config) {
13882
13984
  }
13883
13985
  chunkXHPRD45G_cjs.__name(gate, "gate");
13884
13986
  function isVendorRolesOnly(u) {
13885
- return chunkLXWF6T7F_cjs.canManageVendorRoles(u) && !chunkQXAQ3V7R_cjs.canManageRoles(u);
13987
+ return chunkLCZZ3S4I_cjs.canManageVendorRoles(u) && !chunkFNLF6G2N_cjs.canManageRoles(u);
13886
13988
  }
13887
13989
  chunkXHPRD45G_cjs.__name(isVendorRolesOnly, "isVendorRolesOnly");
13888
13990
  const vendorRoleEntities = [
13889
- ...chunkLXWF6T7F_cjs.VENDOR_STORE_RBAC_ENTITIES,
13991
+ ...chunkLCZZ3S4I_cjs.VENDOR_STORE_RBAC_ENTITIES,
13890
13992
  "dashboard",
13891
13993
  "settings"
13892
13994
  ].sort();
@@ -14043,7 +14145,7 @@ function createAdminRolesHandlers(config) {
14043
14145
  }, {
14044
14146
  status: 404
14045
14147
  });
14046
- if (chunkLXWF6T7F_cjs.isSuperAdminGroupName(g.name) && !chunkLXWF6T7F_cjs.isSuperAdminGroupName(name)) {
14148
+ if (chunkLCZZ3S4I_cjs.isSuperAdminGroupName(g.name) && !chunkLCZZ3S4I_cjs.isSuperAdminGroupName(name)) {
14047
14149
  return json({
14048
14150
  error: "Cannot rename the administrator group"
14049
14151
  }, {
@@ -14100,7 +14202,7 @@ function createAdminRolesHandlers(config) {
14100
14202
  }, {
14101
14203
  status: 404
14102
14204
  });
14103
- if (chunkLXWF6T7F_cjs.isSuperAdminGroupName(g.name)) return json({
14205
+ if (chunkLCZZ3S4I_cjs.isSuperAdminGroupName(g.name)) return json({
14104
14206
  error: "Cannot delete the administrator group"
14105
14207
  }, {
14106
14208
  status: 400
@@ -14298,7 +14400,7 @@ async function sendVendorOnboardEmails(input, deps) {
14298
14400
  getVendorEmails(deps)
14299
14401
  ]);
14300
14402
  const companyDetails = chunkEYUBL7YH_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings, storeSettings);
14301
- const configuredNotify = chunk747MJJCZ_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
14403
+ const configuredNotify = chunkTTOEY7AH_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
14302
14404
  const ownerEmail = input.ownerEmail?.trim() || "";
14303
14405
  const ownerEmailLower = ownerEmail.toLowerCase();
14304
14406
  const sendToOwner = input.sendToOwner !== false;
@@ -14332,7 +14434,7 @@ chunkXHPRD45G_cjs.__name(sendVendorOnboardEmails, "sendVendorOnboardEmails");
14332
14434
 
14333
14435
  // src/lib/seed-vendor-roles.ts
14334
14436
  async function insertRolePermissions(exec, vendorRoleId, permissions) {
14335
- for (const entity of chunkLXWF6T7F_cjs.VENDOR_RBAC_ENTITIES) {
14437
+ for (const entity of chunkLCZZ3S4I_cjs.VENDOR_RBAC_ENTITIES) {
14336
14438
  const flags = permissions[entity];
14337
14439
  if (!flags) continue;
14338
14440
  await exec.query(`
@@ -14363,7 +14465,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
14363
14465
  for (const r of existing) {
14364
14466
  roleIdsByName2[r.name] = Number(r.id);
14365
14467
  if (r.isOwnerRole) ownerRoleId2 = Number(r.id);
14366
- if (r.name === chunkLXWF6T7F_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
14468
+ if (r.name === chunkLCZZ3S4I_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
14367
14469
  }
14368
14470
  return {
14369
14471
  roleIdsByName: roleIdsByName2,
@@ -14374,7 +14476,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
14374
14476
  const roleIdsByName = {};
14375
14477
  let ownerRoleId = 0;
14376
14478
  let viewerRoleId = 0;
14377
- for (const def of chunkLXWF6T7F_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
14479
+ for (const def of chunkLCZZ3S4I_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
14378
14480
  const inserted = await exec.query(`
14379
14481
  INSERT INTO "vendor_roles"
14380
14482
  ("vendorId", "name", "description", "isSystem", "isOwnerRole")
@@ -14391,7 +14493,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
14391
14493
  if (!roleId) continue;
14392
14494
  roleIdsByName[def.name] = roleId;
14393
14495
  if (def.isOwnerRole) ownerRoleId = roleId;
14394
- if (def.name === chunkLXWF6T7F_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
14496
+ if (def.name === chunkLCZZ3S4I_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
14395
14497
  await insertRolePermissions(exec, roleId, def.permissions);
14396
14498
  }
14397
14499
  return {
@@ -14421,7 +14523,7 @@ async function backfillVendorUserRoleIds(em, vendorId, seeded) {
14421
14523
  vendorId
14422
14524
  ]);
14423
14525
  }
14424
- const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunkLXWF6T7F_cjs.VENDOR_VIEWER_ROLE_NAME];
14526
+ const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunkLCZZ3S4I_cjs.VENDOR_VIEWER_ROLE_NAME];
14425
14527
  if (viewerId) {
14426
14528
  await em.query(`
14427
14529
  UPDATE "vendor_users"
@@ -14447,7 +14549,7 @@ async function getDefaultStaffRoleIdForVendor(em, vendorId) {
14447
14549
  LIMIT 1
14448
14550
  `, [
14449
14551
  vendorId,
14450
- chunkLXWF6T7F_cjs.VENDOR_VIEWER_ROLE_NAME
14552
+ chunkLCZZ3S4I_cjs.VENDOR_VIEWER_ROLE_NAME
14451
14553
  ]);
14452
14554
  const id = rows[0]?.id;
14453
14555
  return id != null ? Number(id) : null;
@@ -14808,7 +14910,7 @@ function createVendorOnboardHandlers(config) {
14808
14910
  }, {
14809
14911
  status: 401
14810
14912
  });
14811
- if (!chunkLXWF6T7F_cjs.isPlatformAdministrator(u)) return json({
14913
+ if (!chunkLCZZ3S4I_cjs.isPlatformAdministrator(u)) return json({
14812
14914
  error: "Forbidden",
14813
14915
  reason: "admin_only"
14814
14916
  }, {
@@ -14818,7 +14920,7 @@ function createVendorOnboardHandlers(config) {
14818
14920
  }
14819
14921
  chunkXHPRD45G_cjs.__name(gateAdmin, "gateAdmin");
14820
14922
  async function resolveActiveVendorId(u) {
14821
- const scope = chunkLXWF6T7F_cjs.resolveVendorScopeFromSessionUser(u);
14923
+ const scope = chunkLCZZ3S4I_cjs.resolveVendorScopeFromSessionUser(u);
14822
14924
  const candidates = [];
14823
14925
  if (scope.type === "vendor") candidates.push(scope.vendorId);
14824
14926
  if (scope.type === "all" || scope.type === "vendor") {
@@ -14872,7 +14974,7 @@ function createVendorOnboardHandlers(config) {
14872
14974
  }, {
14873
14975
  status: 401
14874
14976
  });
14875
- if (!chunkLXWF6T7F_cjs.isVendorPortalUser(u) && !chunkLXWF6T7F_cjs.isPlatformAdministrator(u)) {
14977
+ if (!chunkLCZZ3S4I_cjs.isVendorPortalUser(u) && !chunkLCZZ3S4I_cjs.isPlatformAdministrator(u)) {
14876
14978
  return json({
14877
14979
  error: "Forbidden"
14878
14980
  }, {
@@ -14900,7 +15002,7 @@ function createVendorOnboardHandlers(config) {
14900
15002
  }, {
14901
15003
  status: 401
14902
15004
  });
14903
- if (!chunkLXWF6T7F_cjs.canManageVendorTeam(u)) return json({
15005
+ if (!chunkLCZZ3S4I_cjs.canManageVendorTeam(u)) return json({
14904
15006
  error: "Forbidden"
14905
15007
  }, {
14906
15008
  status: 403
@@ -15118,7 +15220,7 @@ function createVendorOnboardHandlers(config) {
15118
15220
  await chunk4WZNRVEZ_cjs.retireSoftDeletedUniqueValue(vendorRepo, "slug", slug);
15119
15221
  let ownerGroup = await groupRepo.findOne({
15120
15222
  where: {
15121
- name: chunkLXWF6T7F_cjs.VENDOR_GROUP_NAME,
15223
+ name: chunkLCZZ3S4I_cjs.VENDOR_GROUP_NAME,
15122
15224
  deleted: false
15123
15225
  }
15124
15226
  });
@@ -15133,12 +15235,12 @@ function createVendorOnboardHandlers(config) {
15133
15235
  if (!ownerGroup) {
15134
15236
  try {
15135
15237
  await groupRepo.save(groupRepo.create({
15136
- name: chunkLXWF6T7F_cjs.VENDOR_GROUP_NAME,
15238
+ name: chunkLCZZ3S4I_cjs.VENDOR_GROUP_NAME,
15137
15239
  deleted: false
15138
15240
  }));
15139
15241
  ownerGroup = await groupRepo.findOne({
15140
15242
  where: {
15141
- name: chunkLXWF6T7F_cjs.VENDOR_GROUP_NAME,
15243
+ name: chunkLCZZ3S4I_cjs.VENDOR_GROUP_NAME,
15142
15244
  deleted: false
15143
15245
  }
15144
15246
  });
@@ -15255,7 +15357,7 @@ function createVendorOnboardHandlers(config) {
15255
15357
  }
15256
15358
  if (entityMap.customer) {
15257
15359
  try {
15258
- await chunkQXAQ3V7R_cjs.ensureCustomerForUser(em, entityMap.customer, {
15360
+ await chunkFNLF6G2N_cjs.ensureCustomerForUser(em, entityMap.customer, {
15259
15361
  id: newUser.id,
15260
15362
  name: userName,
15261
15363
  email: userEmail,
@@ -15756,7 +15858,7 @@ function createVendorOnboardHandlers(config) {
15756
15858
  if (!groupId) {
15757
15859
  const g = await groupRepo.findOne({
15758
15860
  where: {
15759
- name: chunkLXWF6T7F_cjs.VENDOR_GROUP_NAME,
15861
+ name: chunkLCZZ3S4I_cjs.VENDOR_GROUP_NAME,
15760
15862
  deleted: false
15761
15863
  }
15762
15864
  }) ?? await groupRepo.findOne({
@@ -15856,7 +15958,7 @@ function createVendorOnboardHandlers(config) {
15856
15958
  }
15857
15959
  if (entityMap.customer) {
15858
15960
  try {
15859
- await chunkQXAQ3V7R_cjs.ensureCustomerForUser(em, entityMap.customer, {
15961
+ await chunkFNLF6G2N_cjs.ensureCustomerForUser(em, entityMap.customer, {
15860
15962
  id: newUser.id,
15861
15963
  name: userName,
15862
15964
  email: userEmail,
@@ -16403,10 +16505,10 @@ chunkXHPRD45G_cjs.__name(createVendorOnboardHandlers, "createVendorOnboardHandle
16403
16505
  function createVendorRolesHandlers(config) {
16404
16506
  const { dataSource, entityMap, json, getSessionUser } = config;
16405
16507
  const vendorRoleEntities = [
16406
- ...chunkLXWF6T7F_cjs.VENDOR_RBAC_ENTITIES
16508
+ ...chunkLCZZ3S4I_cjs.VENDOR_RBAC_ENTITIES
16407
16509
  ].sort();
16408
16510
  async function resolveActiveVendorId(u) {
16409
- const scope = chunkLXWF6T7F_cjs.resolveVendorScopeFromSessionUser(u);
16511
+ const scope = chunkLCZZ3S4I_cjs.resolveVendorScopeFromSessionUser(u);
16410
16512
  if (scope.type === "vendor") return scope.vendorId;
16411
16513
  if (scope.type === "all") {
16412
16514
  const id = u.activeVendorId ?? u.vendorIds?.[0];
@@ -16422,7 +16524,7 @@ function createVendorRolesHandlers(config) {
16422
16524
  }, {
16423
16525
  status: 401
16424
16526
  });
16425
- if (!chunkLXWF6T7F_cjs.canManageVendorRoles(u)) return json({
16527
+ if (!chunkLCZZ3S4I_cjs.canManageVendorRoles(u)) return json({
16426
16528
  error: "Forbidden"
16427
16529
  }, {
16428
16530
  status: 403
@@ -29046,6 +29148,7 @@ function whatsappPlugin(config = {}) {
29046
29148
  const { getWhatsAppSettings, getMessageTemplateRow, ...staticRest } = config;
29047
29149
  let settingsLoader = getWhatsAppSettings;
29048
29150
  if (!settingsLoader && context.dataSource) {
29151
+ const encKey = resolveSettingsEncryptionKey(env);
29049
29152
  settingsLoader = /* @__PURE__ */ chunkXHPRD45G_cjs.__name(async () => {
29050
29153
  try {
29051
29154
  const ds = context.dataSource;
@@ -29056,10 +29159,18 @@ function whatsappPlugin(config = {}) {
29056
29159
  deleted: false
29057
29160
  }
29058
29161
  });
29059
- return Object.fromEntries(rows.map((r) => [
29060
- r.key,
29061
- r.value
29062
- ]));
29162
+ const result = {};
29163
+ for (const r of rows) {
29164
+ let val = String(r.value ?? "");
29165
+ if (r.encrypted && encKey) {
29166
+ try {
29167
+ val = simpleDecrypt(val, encKey);
29168
+ } catch {
29169
+ }
29170
+ }
29171
+ result[r.key] = val;
29172
+ }
29173
+ return result;
29063
29174
  } catch {
29064
29175
  return {};
29065
29176
  }
@@ -29070,11 +29181,11 @@ function whatsappPlugin(config = {}) {
29070
29181
  db = await settingsLoader?.() ?? {};
29071
29182
  } catch {
29072
29183
  }
29073
- if (!chunk747MJJCZ_cjs.isWhatsAppPluginEnabled(db)) {
29184
+ if (!chunkTTOEY7AH_cjs.isWhatsAppPluginEnabled(db)) {
29074
29185
  context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
29075
29186
  return null;
29076
29187
  }
29077
- const svc = new chunk747MJJCZ_cjs.WhatsAppService(env, staticRest, settingsLoader, getMessageTemplateRow);
29188
+ const svc = new chunkTTOEY7AH_cjs.WhatsAppService(env, staticRest, settingsLoader, getMessageTemplateRow);
29078
29189
  return {
29079
29190
  send: /* @__PURE__ */ chunkXHPRD45G_cjs.__name((opts) => svc.send(opts), "send")
29080
29191
  };
@@ -29151,7 +29262,7 @@ function registerMessagingQueueProcessors(cms, entityMap) {
29151
29262
  getDataSource: /* @__PURE__ */ chunkXHPRD45G_cjs.__name(async () => cms.dataSource, "getDataSource"),
29152
29263
  entityMap
29153
29264
  });
29154
- chunkOXFC3DAM_cjs.registerWhatsAppQueueProcessor(cms);
29265
+ chunkKJB5LBFQ_cjs.registerWhatsAppQueueProcessor(cms);
29155
29266
  }
29156
29267
  chunkXHPRD45G_cjs.__name(registerMessagingQueueProcessors, "registerMessagingQueueProcessors");
29157
29268
  async function ensureMessagingPluginsOnCms(base, options) {
@@ -29180,7 +29291,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
29180
29291
  }
29181
29292
  if (!cms.getPlugin("email")) {
29182
29293
  try {
29183
- const instance = await chunk747MJJCZ_cjs.emailPlugin({
29294
+ const instance = await chunkTTOEY7AH_cjs.emailPlugin({
29184
29295
  type: "SMTP",
29185
29296
  from: config.SMTP_FROM ?? "no-reply@localhost",
29186
29297
  to: config.SMTP_TO ?? ""
@@ -29221,7 +29332,7 @@ function messagingPlugins(options) {
29221
29332
  const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
29222
29333
  return [
29223
29334
  queuePlugin(),
29224
- chunk747MJJCZ_cjs.emailPlugin({
29335
+ chunkTTOEY7AH_cjs.emailPlugin({
29225
29336
  type: "SMTP",
29226
29337
  from: config.SMTP_FROM ?? "no-reply@localhost",
29227
29338
  to: config.SMTP_TO ?? ""
@@ -29355,7 +29466,7 @@ function createCmsApiHandler(config) {
29355
29466
  } : void 0;
29356
29467
  const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
29357
29468
  if (getCms) {
29358
- chunk747MJJCZ_cjs.initWhatsappTriggerDispatcher({
29469
+ chunkTTOEY7AH_cjs.initWhatsappTriggerDispatcher({
29359
29470
  dataSource,
29360
29471
  entityMap,
29361
29472
  getCms
@@ -29368,7 +29479,7 @@ function createCmsApiHandler(config) {
29368
29479
  ] : baseCrudResources;
29369
29480
  const requireEntityPermissionEffective = /* @__PURE__ */ chunkXHPRD45G_cjs.__name(async (_req, entity, action) => {
29370
29481
  if (!resolveSessionUser) {
29371
- chunkLXWF6T7F_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
29482
+ chunkLCZZ3S4I_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
29372
29483
  entity,
29373
29484
  action,
29374
29485
  hint: "Pass getSessionUser: auth.getAuthenticatedUser from createCmsAuthBundle()"
@@ -29378,7 +29489,7 @@ function createCmsApiHandler(config) {
29378
29489
  const raw = await resolveSessionUser();
29379
29490
  const u = await hydrateVendorSessionUser(dataSource, raw);
29380
29491
  if (!u?.email) {
29381
- chunkLXWF6T7F_cjs.logRbac("requireEntityPermission: no session user", {
29492
+ chunkLCZZ3S4I_cjs.logRbac("requireEntityPermission: no session user", {
29382
29493
  entity,
29383
29494
  action
29384
29495
  });
@@ -29388,13 +29499,13 @@ function createCmsApiHandler(config) {
29388
29499
  status: 401
29389
29500
  });
29390
29501
  }
29391
- const allowed = chunkQXAQ3V7R_cjs.sessionHasEntityAccess(u, entity, action);
29392
- await chunkLXWF6T7F_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
29502
+ const allowed = chunkFNLF6G2N_cjs.sessionHasEntityAccess(u, entity, action);
29503
+ await chunkLCZZ3S4I_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
29393
29504
  allowed,
29394
29505
  resolvePath: "hydrated_session"
29395
29506
  });
29396
29507
  if (allowed) return null;
29397
- const { reason } = chunkLXWF6T7F_cjs.explainSessionEntityAccess(u, entity, action);
29508
+ const { reason } = chunkLCZZ3S4I_cjs.explainSessionEntityAccess(u, entity, action);
29398
29509
  return config.json({
29399
29510
  error: "Forbidden",
29400
29511
  entity,
@@ -29405,7 +29516,7 @@ function createCmsApiHandler(config) {
29405
29516
  });
29406
29517
  }
29407
29518
  if (userRequireEntityPermission) {
29408
- chunkLXWF6T7F_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
29519
+ chunkLCZZ3S4I_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
29409
29520
  entity,
29410
29521
  action
29411
29522
  });
@@ -29492,10 +29603,10 @@ function createCmsApiHandler(config) {
29492
29603
  getVendorScope: /* @__PURE__ */ chunkXHPRD45G_cjs.__name(async () => {
29493
29604
  const multiVendorEnabled = await checkMultiVendorEnabled(dataSource);
29494
29605
  if (!multiVendorEnabled) {
29495
- return chunkLXWF6T7F_cjs.resolveDisabledMultiVendorScope(dataSource);
29606
+ return chunkLCZZ3S4I_cjs.resolveDisabledMultiVendorScope(dataSource);
29496
29607
  }
29497
29608
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
29498
- return chunkLXWF6T7F_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29609
+ return chunkLCZZ3S4I_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29499
29610
  }, "getVendorScope"),
29500
29611
  getHydratedSessionUser: /* @__PURE__ */ chunkXHPRD45G_cjs.__name(async () => {
29501
29612
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
@@ -30947,7 +31058,7 @@ function createCmsApiHandler(config) {
30947
31058
  let vendorId = null;
30948
31059
  if (resolveSessionUser) {
30949
31060
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
30950
- const scope = chunkLXWF6T7F_cjs.resolveVendorScopeFromSessionUser(u ?? null);
31061
+ const scope = chunkLCZZ3S4I_cjs.resolveVendorScopeFromSessionUser(u ?? null);
30951
31062
  if (scope.type === "vendor") vendorId = scope.vendorId;
30952
31063
  }
30953
31064
  const result = await validateCoupon(dataSource, entityMap, couponCode, orderLinesNorm, currency, contactId, isAutomatic, discountId ?? void 0, vendorId);
@@ -31035,7 +31146,7 @@ function createCmsApiHandler(config) {
31035
31146
  let vendorId = null;
31036
31147
  if (resolveSessionUser) {
31037
31148
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
31038
- const scope = chunkLXWF6T7F_cjs.resolveVendorScopeFromSessionUser(u ?? null);
31149
+ const scope = chunkLCZZ3S4I_cjs.resolveVendorScopeFromSessionUser(u ?? null);
31039
31150
  if (scope.type === "vendor") vendorId = scope.vendorId;
31040
31151
  }
31041
31152
  const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
@@ -31248,7 +31359,7 @@ function createCmsApiHandler(config) {
31248
31359
  status: 400
31249
31360
  });
31250
31361
  }
31251
- const { resendOrderNotification } = await import('./order-notification-dispatcher-GG5C4LKZ.cjs');
31362
+ const { resendOrderNotification } = await import('./order-notification-dispatcher-37KDVHBM.cjs');
31252
31363
  const result = await resendOrderNotification(triggerKey, orderId, {
31253
31364
  dataSource,
31254
31365
  entityMap,
@@ -31347,7 +31458,7 @@ function createCmsApiHandler(config) {
31347
31458
  status: "cancelled"
31348
31459
  });
31349
31460
  const fireOrderCancelledNotification = /* @__PURE__ */ chunkXHPRD45G_cjs.__name((refundAmount) => {
31350
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
31461
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
31351
31462
  fireOrderNotificationTrigger("order_cancelled", orderId, {
31352
31463
  dataSource,
31353
31464
  entityMap
@@ -31592,7 +31703,7 @@ function createCmsApiHandler(config) {
31592
31703
  }, {
31593
31704
  status: 400
31594
31705
  });
31595
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-LNAZTMTS.cjs');
31706
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-2ZKRK5SN.cjs');
31596
31707
  const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
31597
31708
  return handlers.getChannels(req, orderId);
31598
31709
  }
@@ -31607,7 +31718,7 @@ function createCmsApiHandler(config) {
31607
31718
  }, {
31608
31719
  status: 400
31609
31720
  });
31610
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-LNAZTMTS.cjs');
31721
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-2ZKRK5SN.cjs');
31611
31722
  const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
31612
31723
  return handlers.sendOtp(req, orderId);
31613
31724
  }
@@ -31622,7 +31733,7 @@ function createCmsApiHandler(config) {
31622
31733
  }, {
31623
31734
  status: 400
31624
31735
  });
31625
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-LNAZTMTS.cjs');
31736
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-2ZKRK5SN.cjs');
31626
31737
  const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
31627
31738
  return handlers.verifyOtp(req, orderId);
31628
31739
  }
@@ -31637,7 +31748,7 @@ function createCmsApiHandler(config) {
31637
31748
  }, {
31638
31749
  status: 400
31639
31750
  });
31640
- const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-JEJ5IDID.cjs');
31751
+ const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-E6PQZP4H.cjs');
31641
31752
  const handlers = createOrderAssigneesHandlers(dataSource, entityMap, getHydratedSessionUser);
31642
31753
  return handlers.listEligibleAssignees(req, orderId);
31643
31754
  }
@@ -31747,7 +31858,7 @@ function createCmsApiHandler(config) {
31747
31858
  if (resolveSessionUser) {
31748
31859
  const raw = await resolveSessionUser();
31749
31860
  const u = await hydrateVendorSessionUser(dataSource, raw);
31750
- const scope = chunkLXWF6T7F_cjs.resolveVendorScopeFromSessionUser(u ?? null);
31861
+ const scope = chunkLCZZ3S4I_cjs.resolveVendorScopeFromSessionUser(u ?? null);
31751
31862
  if (scope.type === "vendor") {
31752
31863
  scopedVendorIds = scope.vendorIds;
31753
31864
  }
@@ -32254,7 +32365,7 @@ function createStorefrontApiHandler(config) {
32254
32365
  const otpPepper = config.otpPepper;
32255
32366
  const defaultPhoneCc = config.defaultPhoneCountryCode;
32256
32367
  function fireStorefrontCheckoutNotifications(orderId) {
32257
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
32368
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
32258
32369
  fireOrderNotificationTrigger("order_pending", orderId, {
32259
32370
  dataSource,
32260
32371
  entityMap
@@ -33834,7 +33945,7 @@ function createStorefrontApiHandler(config) {
33834
33945
  status: 403
33835
33946
  });
33836
33947
  }
33837
- const p = chunk6MM5OMRL_cjs.normalizePhoneE164(phoneIn, defaultPhoneCc);
33948
+ const p = chunkKB7EBYPR_cjs.normalizePhoneE164(phoneIn, defaultPhoneCc);
33838
33949
  if (!p) return json({
33839
33950
  error: "Invalid phone"
33840
33951
  }, {
@@ -33887,7 +33998,7 @@ function createStorefrontApiHandler(config) {
33887
33998
  }, {
33888
33999
  status: 401
33889
34000
  });
33890
- const p = chunk6MM5OMRL_cjs.normalizePhoneE164(phoneIn, defaultPhoneCc);
34001
+ const p = chunkKB7EBYPR_cjs.normalizePhoneE164(phoneIn, defaultPhoneCc);
33891
34002
  if (!p) return json({
33892
34003
  error: "Valid phone required"
33893
34004
  }, {
@@ -33911,8 +34022,8 @@ function createStorefrontApiHandler(config) {
33911
34022
  });
33912
34023
  }
33913
34024
  }
33914
- const code = chunk6MM5OMRL_cjs.generateNumericOtp(6);
33915
- const created = await chunk6MM5OMRL_cjs.createOtpChallenge(dataSource, entityMap, {
34025
+ const code = chunkKB7EBYPR_cjs.generateNumericOtp(6);
34026
+ const created = await chunkKB7EBYPR_cjs.createOtpChallenge(dataSource, entityMap, {
33916
34027
  purpose,
33917
34028
  channel,
33918
34029
  identifier,
@@ -33953,7 +34064,7 @@ function createStorefrontApiHandler(config) {
33953
34064
  status: 503
33954
34065
  });
33955
34066
  const templateKey = purpose === "verify_phone" ? "auth.otp_verify_phone" : "auth.otp_login";
33956
- await chunk6MM5OMRL_cjs.queueSms(cms, {
34067
+ await chunkKJB5LBFQ_cjs.queueSms(cms, {
33957
34068
  to: identifier,
33958
34069
  templateKey,
33959
34070
  variables: {
@@ -33986,7 +34097,7 @@ function createStorefrontApiHandler(config) {
33986
34097
  }, {
33987
34098
  status: 400
33988
34099
  });
33989
- const v = await chunk6MM5OMRL_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
34100
+ const v = await chunkKB7EBYPR_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
33990
34101
  purpose: "verify_email",
33991
34102
  identifier: email,
33992
34103
  code,
@@ -34036,13 +34147,13 @@ function createStorefrontApiHandler(config) {
34036
34147
  const b = await req.json().catch(() => ({}));
34037
34148
  const phoneRaw = typeof b.phone === "string" ? b.phone.trim() : "";
34038
34149
  const code = typeof b.code === "string" ? b.code.trim() : "";
34039
- const phone = chunk6MM5OMRL_cjs.normalizePhoneE164(phoneRaw, defaultPhoneCc);
34150
+ const phone = chunkKB7EBYPR_cjs.normalizePhoneE164(phoneRaw, defaultPhoneCc);
34040
34151
  if (!phone || !code) return json({
34041
34152
  error: "phone and code required"
34042
34153
  }, {
34043
34154
  status: 400
34044
34155
  });
34045
- const v = await chunk6MM5OMRL_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
34156
+ const v = await chunkKB7EBYPR_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
34046
34157
  purpose: "verify_phone",
34047
34158
  identifier: phone,
34048
34159
  code,
@@ -34136,10 +34247,10 @@ function createStorefrontApiHandler(config) {
34136
34247
  adminAccess: false
34137
34248
  }));
34138
34249
  const userId = newUser.id;
34139
- await chunkQXAQ3V7R_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
34250
+ await chunkFNLF6G2N_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
34140
34251
  if (entityMap.customer) {
34141
34252
  const phone = typeof b.phone === "string" && b.phone.trim() ? String(b.phone).trim() : null;
34142
- await chunkQXAQ3V7R_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
34253
+ await chunkFNLF6G2N_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
34143
34254
  id: userId,
34144
34255
  name,
34145
34256
  email,
@@ -35199,7 +35310,7 @@ function createStorefrontApiHandler(config) {
35199
35310
  } catch {
35200
35311
  }
35201
35312
  try {
35202
- void import('./emit-order-notification-trigger-X36V4DOH.cjs').then(({ fireOrderNotificationTrigger }) => {
35313
+ void import('./emit-order-notification-trigger-I4HQSTEN.cjs').then(({ fireOrderNotificationTrigger }) => {
35203
35314
  fireOrderNotificationTrigger("order_cancelled", orderId, {
35204
35315
  dataSource,
35205
35316
  entityMap