@infuro/cms-core 1.0.66 → 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 (26) hide show
  1. package/dist/admin.cjs +94 -21
  2. package/dist/admin.js +94 -21
  3. package/dist/api.cjs +36 -36
  4. package/dist/api.js +3 -3
  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-MVHDC3XF.js → chunk-5NOZSG6J.js} +22 -11
  9. package/dist/{chunk-QYRXLURF.cjs → chunk-BVLN75LP.cjs} +443 -78
  10. package/dist/{chunk-T33KU5G5.js → chunk-GLLCLRCQ.js} +394 -29
  11. package/dist/{chunk-J7FMZK66.cjs → chunk-O4AFPDQ4.cjs} +22 -11
  12. package/dist/{chunk-4U6DATGZ.cjs → chunk-OV5TRZET.cjs} +7 -7
  13. package/dist/{chunk-KM2I6AFP.cjs → chunk-SS3K7OIM.cjs} +9 -9
  14. package/dist/{chunk-NR44CK5E.js → chunk-ZY64VJMS.js} +1 -1
  15. package/dist/index.cjs +269 -265
  16. package/dist/index.d.cts +14 -1
  17. package/dist/index.d.ts +14 -1
  18. package/dist/index.js +6 -6
  19. package/dist/migrations/1783300000000-CreateOrderAssigneesTable.ts +43 -0
  20. package/dist/{order-assignees-handlers-NPKD64P6.cjs → order-assignees-handlers-KF7RMTV5.cjs} +77 -8
  21. package/dist/{order-assignees-handlers-LKMAGLG6.js → order-assignees-handlers-L3RVKUBS.js} +77 -8
  22. package/dist/{order-completion-otp-handlers-NK65LOLV.cjs → order-completion-otp-handlers-DZAXK4GQ.cjs} +67 -13
  23. package/dist/{order-completion-otp-handlers-LFRHXWK4.js → order-completion-otp-handlers-HFGCPC4O.js} +67 -13
  24. package/dist/{rbac-debug-db-5R6XFPSV.js → rbac-debug-db-DFZWZ6GV.js} +1 -1
  25. package/dist/{rbac-debug-db-JKK2MCWF.cjs → rbac-debug-db-KWV7D5PQ.cjs} +2 -2
  26. package/package.json +1 -1
@@ -12,9 +12,9 @@ var chunkUPLVMVRX_cjs = require('./chunk-UPLVMVRX.cjs');
12
12
  var chunkTZEMLHSP_cjs = require('./chunk-TZEMLHSP.cjs');
13
13
  var chunk3DZRIZOD_cjs = require('./chunk-3DZRIZOD.cjs');
14
14
  var chunkTJ2MIQUT_cjs = require('./chunk-TJ2MIQUT.cjs');
15
- var chunk4U6DATGZ_cjs = require('./chunk-4U6DATGZ.cjs');
15
+ var chunkOV5TRZET_cjs = require('./chunk-OV5TRZET.cjs');
16
16
  var chunkOY2YTBMP_cjs = require('./chunk-OY2YTBMP.cjs');
17
- var chunkJ7FMZK66_cjs = require('./chunk-J7FMZK66.cjs');
17
+ var chunkO4AFPDQ4_cjs = require('./chunk-O4AFPDQ4.cjs');
18
18
  var chunkD5FBNKQM_cjs = require('./chunk-D5FBNKQM.cjs');
19
19
  var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
20
20
  var typeorm = require('typeorm');
@@ -123,7 +123,7 @@ async function loadUserVendorContext(dataSource, userId, preferredVendorId) {
123
123
  `, [
124
124
  primary.vendorRoleId
125
125
  ]);
126
- vendorEntityPerms = chunkJ7FMZK66_cjs.permissionRowsToRecord(permRows);
126
+ vendorEntityPerms = chunkO4AFPDQ4_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
- chunkJ7FMZK66_cjs.logRbac("hydrateVendorSessionUser: unable to resolve numeric user id", {
233
+ chunkO4AFPDQ4_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 ?? chunkJ7FMZK66_cjs.isSuperAdmin({
253
+ const isRBACAdmin = user.isRBACAdmin ?? chunkO4AFPDQ4_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 = chunkJ7FMZK66_cjs.vendorPortalFlagsFromUser({
266
+ flags = chunkO4AFPDQ4_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
- chunkJ7FMZK66_cjs.logRbac("hydrateVendorSessionUser", {
301
+ chunkO4AFPDQ4_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
  chunkUSNT2KNT_cjs.__name(repoHasVendorIdColumn, "repoHasVendorIdColumn");
913
913
  function resourceUsesVendorScope(resource) {
914
- return resource === "vendors" || chunkJ7FMZK66_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
914
+ return resource === "vendors" || chunkO4AFPDQ4_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
915
915
  }
916
916
  chunkUSNT2KNT_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 chunk4U6DATGZ_cjs.ensureCustomerRecord(dataSource, entityMap.customer, {
1404
+ const ensured = await chunkOV5TRZET_cjs.ensureCustomerRecord(dataSource, entityMap.customer, {
1405
1405
  name,
1406
1406
  email,
1407
1407
  phone,
@@ -1684,6 +1684,30 @@ function entityHasSoftDelete(repo) {
1684
1684
  return repo.metadata.columns.some((c) => c.propertyName === "deleted");
1685
1685
  }
1686
1686
  chunkUSNT2KNT_cjs.__name(entityHasSoftDelete, "entityHasSoftDelete");
1687
+ async function recordOrderAssigneeHistory(dataSource, entityMap, orderId, userId, vendorId) {
1688
+ if (!entityMap.order_assignees) return 1;
1689
+ const assigneeRepo = dataSource.getRepository(entityMap.order_assignees);
1690
+ const maxRow = await assigneeRepo.findOne({
1691
+ where: {
1692
+ orderId
1693
+ },
1694
+ order: {
1695
+ sortOrder: "DESC"
1696
+ }
1697
+ });
1698
+ const currentMax = Number(maxRow?.sortOrder ?? 0);
1699
+ const nextSortOrder = currentMax + 1;
1700
+ await assigneeRepo.save({
1701
+ orderId,
1702
+ userId,
1703
+ vendorId,
1704
+ sortOrder: nextSortOrder,
1705
+ assignedAt: /* @__PURE__ */ new Date()
1706
+ });
1707
+ console.log(`[ORDERS-DEBUG][ASSIGNEE_HISTORY] Recorded assignment for order ${orderId}: user ${userId}, vendor ${vendorId}, sortOrder ${nextSortOrder}`);
1708
+ return nextSortOrder;
1709
+ }
1710
+ chunkUSNT2KNT_cjs.__name(recordOrderAssigneeHistory, "recordOrderAssigneeHistory");
1687
1711
  var LIST_QUERY_RESERVED = /* @__PURE__ */ new Set([
1688
1712
  "page",
1689
1713
  "limit",
@@ -3566,10 +3590,38 @@ function createCrudHandler(dataSource, entityMap, options) {
3566
3590
  });
3567
3591
  }
3568
3592
  }
3569
- const qb = repo2.createQueryBuilder("order").leftJoinAndSelect("order.contact", "contact").leftJoinAndSelect("order.items", "items").leftJoinAndSelect("items.product", "product").leftJoinAndSelect("product.collection", "collection").leftJoinAndSelect("order.payments", "payments").leftJoinAndSelect("order.assignedUser", "assignedUser").andWhere("order.deleted = :orderDel", {
3593
+ const qb = repo2.createQueryBuilder("order").leftJoinAndSelect("order.contact", "contact").leftJoinAndSelect("order.items", "items").leftJoinAndSelect("items.product", "product").leftJoinAndSelect("product.collection", "collection").leftJoinAndSelect("order.payments", "payments").leftJoinAndSelect("order.assignedUser", "assignedUser").leftJoinAndSelect("order.vendor", "vendor").andWhere("order.deleted = :orderDel", {
3570
3594
  orderDel: false
3571
3595
  }).orderBy(`order.${sortField2}`, sortOrderOrders).skip(skip).take(limit);
3572
- applyVendorScopeToQueryBuilder(qb, "order", scope);
3596
+ const session = await getHydratedSessionUser?.() ?? null;
3597
+ console.log("[ORDERS-DEBUG][LIST] Querying orders. Session:", {
3598
+ id: session?.id,
3599
+ email: session?.email,
3600
+ role: session?.role,
3601
+ isRBACAdmin: session?.isRBACAdmin,
3602
+ isVendorPortal: session?.isVendorPortal,
3603
+ isVendorOwner: session?.isVendorOwner,
3604
+ isVendorRoleOwner: session?.isVendorRoleOwner,
3605
+ vendorIds: session?.vendorIds,
3606
+ activeVendorId: session?.activeVendorId
3607
+ }, "Scope:", scope);
3608
+ if (scope.type === "deny") {
3609
+ qb.andWhere("1 = 0");
3610
+ } else if (scope.type === "vendor") {
3611
+ const isOwner = Boolean(session?.isVendorOwner || session?.isVendorRoleOwner || session?.isRBACAdmin);
3612
+ console.log("[ORDERS-DEBUG][LIST] Vendor scope applied. isOwner:", isOwner, "vendorId:", scope.vendorId);
3613
+ if (isOwner) {
3614
+ qb.andWhere('(order.vendorId = :vendorScopeId OR order.assignedUserId IN (SELECT vu."userId" FROM vendor_users vu WHERE vu."vendorId" = :vendorScopeId))', {
3615
+ vendorScopeId: scope.vendorId
3616
+ });
3617
+ } else {
3618
+ const teamMemberId = Number(session?.id);
3619
+ console.log("[ORDERS-DEBUG][LIST] Team member scoping to teamMemberId:", teamMemberId);
3620
+ qb.andWhere("order.assignedUserId = :teamMemberId", {
3621
+ teamMemberId
3622
+ });
3623
+ }
3624
+ }
3573
3625
  const vendorIdFilter = searchParams.get("vendorId")?.trim();
3574
3626
  if (vendorIdFilter) {
3575
3627
  const n = Number(vendorIdFilter);
@@ -3622,7 +3674,15 @@ function createCrudHandler(dataSource, entityMap, options) {
3622
3674
  });
3623
3675
  }
3624
3676
  }
3677
+ console.log("[ORDERS-DEBUG][LIST] Executing SQL:", qb.getSql(), "Params:", qb.getParameters());
3625
3678
  const [rows, total2] = await qb.getManyAndCount();
3679
+ console.log("[ORDERS-DEBUG][LIST] Query result: total =", total2, "rows length =", rows.length, "Orders:", rows.map((r) => ({
3680
+ id: r.id,
3681
+ orderNumber: r.orderNumber,
3682
+ vendorId: r.vendorId,
3683
+ assignedUserId: r.assignedUserId,
3684
+ status: r.status
3685
+ })));
3626
3686
  const data2 = await Promise.all(rows.map(async (order) => {
3627
3687
  await autoExpireOrderIfPaymentTimeExceeded(dataSource, entityMap, order);
3628
3688
  const contact = order.contact;
@@ -3666,6 +3726,7 @@ function createCrudHandler(dataSource, entityMap, options) {
3666
3726
  if (orderStatus === "cancelled" && rawPayStatus !== "paid" && rawPayStatus !== "captured" && rawPayStatus !== "refunded") {
3667
3727
  paymentStatus2 = "unpaid";
3668
3728
  }
3729
+ const vendorObj = order.vendor;
3669
3730
  return {
3670
3731
  ...orderWithoutPayments,
3671
3732
  contact: contact ? {
@@ -3679,6 +3740,11 @@ function createCrudHandler(dataSource, entityMap, options) {
3679
3740
  name: assignedUserObj.name || assignedUserObj.email,
3680
3741
  email: assignedUserObj.email
3681
3742
  } : null,
3743
+ vendor: vendorObj ? {
3744
+ id: vendorObj.id,
3745
+ name: vendorObj.name || vendorObj.slug || `Vendor #${vendorObj.id}`,
3746
+ slug: vendorObj.slug
3747
+ } : null,
3682
3748
  itemsSummary,
3683
3749
  paymentStatus: paymentStatus2
3684
3750
  };
@@ -4211,6 +4277,18 @@ function createCrudHandler(dataSource, entityMap, options) {
4211
4277
  isCatalog: true
4212
4278
  });
4213
4279
  }
4280
+ } else if (resource === "orders" && scope.type === "vendor") {
4281
+ const session = await getHydratedSessionUser?.() ?? null;
4282
+ const isOwner = Boolean(session?.isVendorOwner || session?.isVendorRoleOwner || session?.isRBACAdmin);
4283
+ if (!isOwner) {
4284
+ const teamMemberId = Number(session?.id);
4285
+ where = mergeListWhereAnd(where, {
4286
+ vendorId: scope.vendorId,
4287
+ assignedUserId: teamMemberId
4288
+ });
4289
+ } else {
4290
+ where = mergeVendorScopeIntoWhere(where, scope, resource, catalogFlags);
4291
+ }
4214
4292
  } else {
4215
4293
  where = mergeVendorScopeIntoWhere(where, scope, resource, catalogFlags);
4216
4294
  }
@@ -4437,7 +4515,7 @@ function createCrudHandler(dataSource, entityMap, options) {
4437
4515
  });
4438
4516
  }
4439
4517
  }
4440
- const savedCustomer = await chunk4U6DATGZ_cjs.ensureCustomerRecord(dataSource, entityMap["customer"], {
4518
+ const savedCustomer = await chunkOV5TRZET_cjs.ensureCustomerRecord(dataSource, entityMap["customer"], {
4441
4519
  name,
4442
4520
  email,
4443
4521
  phone,
@@ -5175,6 +5253,12 @@ function createCrudHandler(dataSource, entityMap, options) {
5175
5253
  shippingAddressId: savedShipping?.id ?? null
5176
5254
  });
5177
5255
  }
5256
+ if (persistBody.assignedUserId) {
5257
+ const initAssignee = Number(persistBody.assignedUserId);
5258
+ if (Number.isFinite(initAssignee) && initAssignee > 0) {
5259
+ await recordOrderAssigneeHistory(dataSource, entityMap, created.id, initAssignee, Number(created.vendorId) || null);
5260
+ }
5261
+ }
5178
5262
  const reloadedOrder = await repo.findOne({
5179
5263
  where: {
5180
5264
  id: created.id,
@@ -5494,7 +5578,16 @@ function createCrudHandler(dataSource, entityMap, options) {
5494
5578
  const scope = await resolveScope();
5495
5579
  const flags = await getVendorCatalogCreateFlags(dataSource);
5496
5580
  if (scope.type !== "all") {
5497
- data = data.filter((row) => vendorScopeRowAccess(row, scope, resource, flags) === "ok");
5581
+ const session = await getHydratedSessionUser?.() ?? null;
5582
+ const isOwner = Boolean(session?.isVendorOwner || session?.isVendorRoleOwner || session?.isRBACAdmin);
5583
+ const teamMemberId = Number(session?.id);
5584
+ data = data.filter((row) => {
5585
+ if (vendorScopeRowAccess(row, scope, resource, flags) !== "ok") return false;
5586
+ if (resource === "orders" && scope.type === "vendor" && !isOwner) {
5587
+ return Number(row?.assignedUserId) === teamMemberId;
5588
+ }
5589
+ return true;
5590
+ });
5498
5591
  }
5499
5592
  const excludeCols = /* @__PURE__ */ new Set([
5500
5593
  "deletedAt",
@@ -5532,6 +5625,51 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
5532
5625
  type: "all"
5533
5626
  }));
5534
5627
  async function vendorScopeAccessJson(row, scope, resource) {
5628
+ if (!row) return json({
5629
+ message: "Not found"
5630
+ }, {
5631
+ status: 404
5632
+ });
5633
+ if (resource === "orders" && scope.type === "vendor") {
5634
+ const rowVendorId = Number(row?.vendorId);
5635
+ let orderBelongsToVendorScope = rowVendorId === scope.vendorId;
5636
+ if (!orderBelongsToVendorScope) {
5637
+ const aId = Number(row?.assignedUserId);
5638
+ if (Number.isFinite(aId) && aId > 0 && entityMap["vendor_users"]) {
5639
+ const vuRepo = dataSource.getRepository(entityMap["vendor_users"]);
5640
+ const isTeamMember = await vuRepo.count({
5641
+ where: {
5642
+ vendorId: scope.vendorId,
5643
+ userId: aId
5644
+ }
5645
+ });
5646
+ if (isTeamMember > 0) {
5647
+ orderBelongsToVendorScope = true;
5648
+ }
5649
+ }
5650
+ }
5651
+ if (!orderBelongsToVendorScope) {
5652
+ return json({
5653
+ error: "Forbidden"
5654
+ }, {
5655
+ status: 403
5656
+ });
5657
+ }
5658
+ const session = await getHydratedSessionUser?.() ?? null;
5659
+ const isOwner = Boolean(session?.isVendorOwner || session?.isVendorRoleOwner || session?.isRBACAdmin);
5660
+ if (!isOwner) {
5661
+ const sessionUserId = Number(session?.id);
5662
+ const orderAssignee = Number(row?.assignedUserId);
5663
+ if (!Number.isFinite(orderAssignee) || orderAssignee !== sessionUserId) {
5664
+ return json({
5665
+ error: "Forbidden: You can only access orders assigned directly to you"
5666
+ }, {
5667
+ status: 403
5668
+ });
5669
+ }
5670
+ }
5671
+ return null;
5672
+ }
5535
5673
  const flags = await getVendorCatalogCreateFlags(dataSource);
5536
5674
  const access = vendorScopeRowAccess(row, scope, resource, flags);
5537
5675
  if (access === "ok") return null;
@@ -5656,6 +5794,17 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
5656
5794
  }
5657
5795
  if (resource === "orders") {
5658
5796
  const scope2 = await resolveScopeById();
5797
+ const session = await getHydratedSessionUser?.() ?? null;
5798
+ console.log("[ORDERS-DEBUG][GET_BY_ID] Fetching order id:", id, "Scope:", scope2, "Session:", {
5799
+ id: session?.id,
5800
+ email: session?.email,
5801
+ role: session?.role,
5802
+ isRBACAdmin: session?.isRBACAdmin,
5803
+ isVendorOwner: session?.isVendorOwner,
5804
+ isVendorRoleOwner: session?.isVendorRoleOwner,
5805
+ activeVendorId: session?.activeVendorId,
5806
+ vendorIds: session?.vendorIds
5807
+ });
5659
5808
  const order = await repo.findOne({
5660
5809
  where: {
5661
5810
  id: Number(id)
@@ -5668,14 +5817,26 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
5668
5817
  "items.product",
5669
5818
  "items.product.collection",
5670
5819
  "payments",
5671
- "assignedUser"
5820
+ "assignedUser",
5821
+ "vendor"
5672
5822
  ]
5673
5823
  });
5824
+ console.log("[ORDERS-DEBUG][GET_BY_ID] Order found in DB:", order ? {
5825
+ id: order.id,
5826
+ orderNumber: order.orderNumber,
5827
+ vendorId: order.vendorId,
5828
+ assignedUserId: order.assignedUserId,
5829
+ status: order.status
5830
+ } : null);
5674
5831
  if (order) {
5675
5832
  await autoExpireOrderIfPaymentTimeExceeded(dataSource, entityMap, order);
5676
5833
  }
5677
5834
  const orderDenied = await vendorScopeAccessJson(order, scope2, resource);
5678
- if (orderDenied) return orderDenied;
5835
+ if (orderDenied) {
5836
+ console.log("[ORDERS-DEBUG][GET_BY_ID] Access DENIED for order id:", id);
5837
+ return orderDenied;
5838
+ }
5839
+ console.log("[ORDERS-DEBUG][GET_BY_ID] Access GRANTED for order id:", id);
5679
5840
  const relatedOrders = await repo.find({
5680
5841
  where: {
5681
5842
  parentOrderId: Number(id)
@@ -6059,21 +6220,67 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6059
6220
  lines: []
6060
6221
  } : await calculateOrderTotalsFromLines(dataSource, entityMap, orderLinesNorm, effectiveCurrency, putDiscountId, Number.isFinite(putOrderVendorId) ? putOrderVendorId : null);
6061
6222
  const scalarUpdate = pickColumnUpdates(repo, rawBody);
6062
- if (rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0) {
6063
- const aId = Number(rawBody.assignedUserId);
6064
- if (Number.isFinite(aId) && aId > 0) {
6065
- scalarUpdate.assignedUserId = aId;
6066
- scalarUpdate.assignedAt = /* @__PURE__ */ new Date();
6067
- } else {
6068
- scalarUpdate.assignedUserId = null;
6069
- scalarUpdate.assignedAt = null;
6223
+ if (rawBody && typeof rawBody === "object") {
6224
+ if (scopePutEarly.type === "all" && "vendorId" in rawBody && rawBody.vendorId !== void 0) {
6225
+ const vId = Number(rawBody.vendorId);
6226
+ if (Number.isFinite(vId) && vId > 0) {
6227
+ scalarUpdate.vendorId = vId;
6228
+ }
6229
+ }
6230
+ if ("assignedUserId" in rawBody && rawBody.assignedUserId !== void 0) {
6231
+ const aId = Number(rawBody.assignedUserId);
6232
+ if (Number.isFinite(aId) && aId > 0) {
6233
+ if (scopePutEarly.type === "vendor" && entityMap.vendor_users) {
6234
+ const vuRepo = dataSource.getRepository(entityMap.vendor_users);
6235
+ const vuLink = await vuRepo.findOne({
6236
+ where: {
6237
+ vendorId: scopePutEarly.vendorId,
6238
+ userId: aId
6239
+ }
6240
+ });
6241
+ if (!vuLink) {
6242
+ return json({
6243
+ error: "Cannot assign order to a user outside your vendor team."
6244
+ }, {
6245
+ status: 403
6246
+ });
6247
+ }
6248
+ scalarUpdate.vendorId = scopePutEarly.vendorId;
6249
+ } else if (scopePutEarly.type === "all" && entityMap.vendor_users) {
6250
+ if (entityMap.vendors) {
6251
+ const activeVu = await dataSource.query(`SELECT vu."vendorId"
6252
+ FROM vendor_users vu
6253
+ JOIN vendors v ON v.id = vu."vendorId"
6254
+ WHERE vu."userId" = $1 AND v.deleted = false
6255
+ ORDER BY vu.id DESC
6256
+ LIMIT 1`, [
6257
+ aId
6258
+ ]);
6259
+ if (activeVu.length > 0 && activeVu[0].vendorId) {
6260
+ scalarUpdate.vendorId = Number(activeVu[0].vendorId);
6261
+ }
6262
+ }
6263
+ }
6264
+ const prevAssigned = Number(existingOrderRow?.assignedUserId);
6265
+ const prevVendor = Number(existingOrderRow?.vendorId);
6266
+ const targetVendor = Number.isFinite(Number(scalarUpdate.vendorId)) ? Number(scalarUpdate.vendorId) : Number(existingOrderRow?.vendorId) || null;
6267
+ if (aId !== prevAssigned || targetVendor && targetVendor !== prevVendor) {
6268
+ await recordOrderAssigneeHistory(dataSource, entityMap, numericId, aId, targetVendor);
6269
+ }
6270
+ scalarUpdate.assignedUserId = aId;
6271
+ scalarUpdate.assignedAt = /* @__PURE__ */ new Date();
6272
+ } else {
6273
+ scalarUpdate.assignedUserId = null;
6274
+ scalarUpdate.assignedAt = null;
6275
+ }
6070
6276
  }
6071
6277
  }
6072
6278
  if (scalarUpdate.status === "processing") {
6073
6279
  const effectiveAssignee = scalarUpdate.assignedUserId !== void 0 ? scalarUpdate.assignedUserId : existingOrderRow?.assignedUserId ?? null;
6074
- if (!effectiveAssignee) {
6280
+ const effectiveVendor = scalarUpdate.vendorId !== void 0 ? Number(scalarUpdate.vendorId) : Number(existingOrderRow?.vendorId);
6281
+ if (!effectiveAssignee && (!Number.isFinite(effectiveVendor) || effectiveVendor <= 0)) {
6075
6282
  return json({
6076
- error: "Cannot start processing without assigning a teammate. Please assign a teammate first."
6283
+ error: "Cannot start processing without assigning a vendor or teammate. Please assign first."
6077
6284
  }, {
6078
6285
  status: 400
6079
6286
  });
@@ -6490,7 +6697,9 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6490
6697
  }
6491
6698
  const updatePayload = rawBody && typeof rawBody === "object" ? pickColumnUpdates(repo, rawBody) : {};
6492
6699
  if (resourceUsesVendorScope(resource)) {
6493
- delete updatePayload.vendorId;
6700
+ if (!(resource === "orders" && scopePut.type === "all")) {
6701
+ delete updatePayload.vendorId;
6702
+ }
6494
6703
  }
6495
6704
  if (resource === "contacts" && "type" in updatePayload) {
6496
6705
  const t = updatePayload.type;
@@ -6886,9 +7095,59 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6886
7095
  }
6887
7096
  }
6888
7097
  if (resource === "orders" && orderInvPrev && rawBody && typeof rawBody === "object") {
7098
+ console.log("[ORDERS-DEBUG][UPDATE] PUT /api/orders/" + numericId, "Scope:", scopePut, "rawBody:", rawBody, "existingOrder:", {
7099
+ id: existingOrderRow?.id,
7100
+ vendorId: existingOrderRow?.vendorId,
7101
+ assignedUserId: existingOrderRow?.assignedUserId,
7102
+ status: existingOrderRow?.status
7103
+ });
7104
+ if (scopePut.type === "all" && "vendorId" in rawBody && rawBody.vendorId !== void 0) {
7105
+ const vId = Number(rawBody.vendorId);
7106
+ if (Number.isFinite(vId) && vId > 0) {
7107
+ updatePayload.vendorId = vId;
7108
+ }
7109
+ }
6889
7110
  if ("assignedUserId" in rawBody && rawBody.assignedUserId !== void 0) {
6890
7111
  const aId = Number(rawBody.assignedUserId);
7112
+ console.log("[ORDERS-DEBUG][UPDATE] Updating assignedUserId to:", aId);
6891
7113
  if (Number.isFinite(aId) && aId > 0) {
7114
+ if (scopePut.type === "vendor" && entityMap.vendor_users) {
7115
+ const vuRepo = dataSource.getRepository(entityMap.vendor_users);
7116
+ const vuLink = await vuRepo.findOne({
7117
+ where: {
7118
+ vendorId: scopePut.vendorId,
7119
+ userId: aId
7120
+ }
7121
+ });
7122
+ if (!vuLink) {
7123
+ return json({
7124
+ error: "Cannot assign order to a user outside your vendor team."
7125
+ }, {
7126
+ status: 403
7127
+ });
7128
+ }
7129
+ updatePayload.vendorId = scopePut.vendorId;
7130
+ } else if (scopePut.type === "all" && entityMap.vendor_users) {
7131
+ if (entityMap.vendors) {
7132
+ const activeVu = await dataSource.query(`SELECT vu."vendorId"
7133
+ FROM vendor_users vu
7134
+ JOIN vendors v ON v.id = vu."vendorId"
7135
+ WHERE vu."userId" = $1 AND v.deleted = false
7136
+ ORDER BY vu.id DESC
7137
+ LIMIT 1`, [
7138
+ aId
7139
+ ]);
7140
+ if (activeVu.length > 0 && activeVu[0].vendorId) {
7141
+ updatePayload.vendorId = Number(activeVu[0].vendorId);
7142
+ }
7143
+ }
7144
+ }
7145
+ const prevAssigned = Number(existingOrderRow?.assignedUserId);
7146
+ const prevVendor = Number(existingOrderRow?.vendorId);
7147
+ const targetVendor = Number.isFinite(Number(updatePayload.vendorId)) ? Number(updatePayload.vendorId) : Number(existingOrderRow?.vendorId) || null;
7148
+ if (aId !== prevAssigned || targetVendor && targetVendor !== prevVendor) {
7149
+ await recordOrderAssigneeHistory(dataSource, entityMap, numericId, aId, targetVendor);
7150
+ }
6892
7151
  updatePayload.assignedUserId = aId;
6893
7152
  updatePayload.assignedAt = /* @__PURE__ */ new Date();
6894
7153
  } else {
@@ -6896,11 +7155,13 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6896
7155
  updatePayload.assignedAt = null;
6897
7156
  }
6898
7157
  }
7158
+ console.log("[ORDERS-DEBUG][UPDATE] Final updatePayload for order:", updatePayload);
6899
7159
  if (updatePayload.status === "processing") {
6900
7160
  const effectiveAssignee = updatePayload.assignedUserId !== void 0 ? updatePayload.assignedUserId : existingOrderRow?.assignedUserId ?? null;
6901
- if (!effectiveAssignee) {
7161
+ const effectiveVendor = updatePayload.vendorId !== void 0 ? Number(updatePayload.vendorId) : Number(existingOrderRow?.vendorId);
7162
+ if (!effectiveAssignee && (!Number.isFinite(effectiveVendor) || effectiveVendor <= 0)) {
6902
7163
  return json({
6903
- error: "Cannot start processing without assigning a teammate. Please assign a teammate first."
7164
+ error: "Cannot start processing without assigning a vendor or teammate. Please assign first."
6904
7165
  }, {
6905
7166
  status: 400
6906
7167
  });
@@ -7853,7 +8114,7 @@ function createInviteAcceptHandler(config) {
7853
8114
  }
7854
8115
  const { userId, email, vendorId } = validation.target;
7855
8116
  if (entityMap.contacts) {
7856
- await chunk4U6DATGZ_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
8117
+ await chunkOV5TRZET_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
7857
8118
  }
7858
8119
  if (beforeActivate) await beforeActivate(email, userId);
7859
8120
  const hashedPassword = await hashPassword(password);
@@ -8946,7 +9207,7 @@ function createVendorDashboardHandler(config) {
8946
9207
  if (pe) return pe;
8947
9208
  }
8948
9209
  const user = await getSessionUser();
8949
- if (!user || !chunkJ7FMZK66_cjs.isVendorPortalUser(user)) {
9210
+ if (!user || !chunkO4AFPDQ4_cjs.isVendorPortalUser(user)) {
8950
9211
  return json({
8951
9212
  error: "Forbidden"
8952
9213
  }, {
@@ -10508,11 +10769,11 @@ function createUsersApiHandlers(config) {
10508
10769
  adminAccess
10509
10770
  }));
10510
10771
  if (entityMap.contacts) {
10511
- await chunk4U6DATGZ_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, newUser.id, newUser.email);
10772
+ await chunkOV5TRZET_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, newUser.id, newUser.email);
10512
10773
  }
10513
10774
  if (entityMap.customer) {
10514
10775
  const phone = typeof body.phone === "string" && body.phone.trim() ? body.phone.trim() : null;
10515
- await chunk4U6DATGZ_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
10776
+ await chunkOV5TRZET_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
10516
10777
  id: newUser.id,
10517
10778
  name: String(newUser.name ?? body.name),
10518
10779
  email: String(newUser.email),
@@ -13595,7 +13856,7 @@ chunkUSNT2KNT_cjs.__name(findActiveRefundPolicyForVendor, "findActiveRefundPolic
13595
13856
  // src/api/admin-roles-handlers.ts
13596
13857
  function createAdminRolesHandlers(config) {
13597
13858
  const { dataSource, entityMap, json, getSessionUser } = config;
13598
- const baseEntities = chunkJ7FMZK66_cjs.getPermissionableEntityKeys(entityMap);
13859
+ const baseEntities = chunkO4AFPDQ4_cjs.getPermissionableEntityKeys(entityMap);
13599
13860
  const allowEntities = /* @__PURE__ */ new Set([
13600
13861
  ...baseEntities,
13601
13862
  "users"
@@ -13610,7 +13871,7 @@ function createAdminRolesHandlers(config) {
13610
13871
  }, {
13611
13872
  status: 401
13612
13873
  });
13613
- if (!chunk4U6DATGZ_cjs.canManageRoles(u) && !chunkJ7FMZK66_cjs.canManageVendorRoles(u)) {
13874
+ if (!chunkOV5TRZET_cjs.canManageRoles(u) && !chunkO4AFPDQ4_cjs.canManageVendorRoles(u)) {
13614
13875
  return json({
13615
13876
  error: "Forbidden"
13616
13877
  }, {
@@ -13621,11 +13882,11 @@ function createAdminRolesHandlers(config) {
13621
13882
  }
13622
13883
  chunkUSNT2KNT_cjs.__name(gate, "gate");
13623
13884
  function isVendorRolesOnly(u) {
13624
- return chunkJ7FMZK66_cjs.canManageVendorRoles(u) && !chunk4U6DATGZ_cjs.canManageRoles(u);
13885
+ return chunkO4AFPDQ4_cjs.canManageVendorRoles(u) && !chunkOV5TRZET_cjs.canManageRoles(u);
13625
13886
  }
13626
13887
  chunkUSNT2KNT_cjs.__name(isVendorRolesOnly, "isVendorRolesOnly");
13627
13888
  const vendorRoleEntities = [
13628
- ...chunkJ7FMZK66_cjs.VENDOR_STORE_RBAC_ENTITIES,
13889
+ ...chunkO4AFPDQ4_cjs.VENDOR_STORE_RBAC_ENTITIES,
13629
13890
  "dashboard",
13630
13891
  "settings"
13631
13892
  ].sort();
@@ -13782,7 +14043,7 @@ function createAdminRolesHandlers(config) {
13782
14043
  }, {
13783
14044
  status: 404
13784
14045
  });
13785
- if (chunkJ7FMZK66_cjs.isSuperAdminGroupName(g.name) && !chunkJ7FMZK66_cjs.isSuperAdminGroupName(name)) {
14046
+ if (chunkO4AFPDQ4_cjs.isSuperAdminGroupName(g.name) && !chunkO4AFPDQ4_cjs.isSuperAdminGroupName(name)) {
13786
14047
  return json({
13787
14048
  error: "Cannot rename the administrator group"
13788
14049
  }, {
@@ -13839,7 +14100,7 @@ function createAdminRolesHandlers(config) {
13839
14100
  }, {
13840
14101
  status: 404
13841
14102
  });
13842
- if (chunkJ7FMZK66_cjs.isSuperAdminGroupName(g.name)) return json({
14103
+ if (chunkO4AFPDQ4_cjs.isSuperAdminGroupName(g.name)) return json({
13843
14104
  error: "Cannot delete the administrator group"
13844
14105
  }, {
13845
14106
  status: 400
@@ -14071,7 +14332,7 @@ chunkUSNT2KNT_cjs.__name(sendVendorOnboardEmails, "sendVendorOnboardEmails");
14071
14332
 
14072
14333
  // src/lib/seed-vendor-roles.ts
14073
14334
  async function insertRolePermissions(exec, vendorRoleId, permissions) {
14074
- for (const entity of chunkJ7FMZK66_cjs.VENDOR_RBAC_ENTITIES) {
14335
+ for (const entity of chunkO4AFPDQ4_cjs.VENDOR_RBAC_ENTITIES) {
14075
14336
  const flags = permissions[entity];
14076
14337
  if (!flags) continue;
14077
14338
  await exec.query(`
@@ -14102,7 +14363,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
14102
14363
  for (const r of existing) {
14103
14364
  roleIdsByName2[r.name] = Number(r.id);
14104
14365
  if (r.isOwnerRole) ownerRoleId2 = Number(r.id);
14105
- if (r.name === chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
14366
+ if (r.name === chunkO4AFPDQ4_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
14106
14367
  }
14107
14368
  return {
14108
14369
  roleIdsByName: roleIdsByName2,
@@ -14113,7 +14374,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
14113
14374
  const roleIdsByName = {};
14114
14375
  let ownerRoleId = 0;
14115
14376
  let viewerRoleId = 0;
14116
- for (const def of chunkJ7FMZK66_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
14377
+ for (const def of chunkO4AFPDQ4_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
14117
14378
  const inserted = await exec.query(`
14118
14379
  INSERT INTO "vendor_roles"
14119
14380
  ("vendorId", "name", "description", "isSystem", "isOwnerRole")
@@ -14130,7 +14391,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
14130
14391
  if (!roleId) continue;
14131
14392
  roleIdsByName[def.name] = roleId;
14132
14393
  if (def.isOwnerRole) ownerRoleId = roleId;
14133
- if (def.name === chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
14394
+ if (def.name === chunkO4AFPDQ4_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
14134
14395
  await insertRolePermissions(exec, roleId, def.permissions);
14135
14396
  }
14136
14397
  return {
@@ -14160,7 +14421,7 @@ async function backfillVendorUserRoleIds(em, vendorId, seeded) {
14160
14421
  vendorId
14161
14422
  ]);
14162
14423
  }
14163
- const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME];
14424
+ const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunkO4AFPDQ4_cjs.VENDOR_VIEWER_ROLE_NAME];
14164
14425
  if (viewerId) {
14165
14426
  await em.query(`
14166
14427
  UPDATE "vendor_users"
@@ -14186,7 +14447,7 @@ async function getDefaultStaffRoleIdForVendor(em, vendorId) {
14186
14447
  LIMIT 1
14187
14448
  `, [
14188
14449
  vendorId,
14189
- chunkJ7FMZK66_cjs.VENDOR_VIEWER_ROLE_NAME
14450
+ chunkO4AFPDQ4_cjs.VENDOR_VIEWER_ROLE_NAME
14190
14451
  ]);
14191
14452
  const id = rows[0]?.id;
14192
14453
  return id != null ? Number(id) : null;
@@ -14547,7 +14808,7 @@ function createVendorOnboardHandlers(config) {
14547
14808
  }, {
14548
14809
  status: 401
14549
14810
  });
14550
- if (!chunkJ7FMZK66_cjs.isPlatformAdministrator(u)) return json({
14811
+ if (!chunkO4AFPDQ4_cjs.isPlatformAdministrator(u)) return json({
14551
14812
  error: "Forbidden",
14552
14813
  reason: "admin_only"
14553
14814
  }, {
@@ -14557,7 +14818,7 @@ function createVendorOnboardHandlers(config) {
14557
14818
  }
14558
14819
  chunkUSNT2KNT_cjs.__name(gateAdmin, "gateAdmin");
14559
14820
  async function resolveActiveVendorId(u) {
14560
- const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u);
14821
+ const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u);
14561
14822
  const candidates = [];
14562
14823
  if (scope.type === "vendor") candidates.push(scope.vendorId);
14563
14824
  if (scope.type === "all" || scope.type === "vendor") {
@@ -14611,7 +14872,7 @@ function createVendorOnboardHandlers(config) {
14611
14872
  }, {
14612
14873
  status: 401
14613
14874
  });
14614
- if (!chunkJ7FMZK66_cjs.isVendorPortalUser(u) && !chunkJ7FMZK66_cjs.isPlatformAdministrator(u)) {
14875
+ if (!chunkO4AFPDQ4_cjs.isVendorPortalUser(u) && !chunkO4AFPDQ4_cjs.isPlatformAdministrator(u)) {
14615
14876
  return json({
14616
14877
  error: "Forbidden"
14617
14878
  }, {
@@ -14639,7 +14900,7 @@ function createVendorOnboardHandlers(config) {
14639
14900
  }, {
14640
14901
  status: 401
14641
14902
  });
14642
- if (!chunkJ7FMZK66_cjs.canManageVendorTeam(u)) return json({
14903
+ if (!chunkO4AFPDQ4_cjs.canManageVendorTeam(u)) return json({
14643
14904
  error: "Forbidden"
14644
14905
  }, {
14645
14906
  status: 403
@@ -14857,7 +15118,7 @@ function createVendorOnboardHandlers(config) {
14857
15118
  await chunkOY2YTBMP_cjs.retireSoftDeletedUniqueValue(vendorRepo, "slug", slug);
14858
15119
  let ownerGroup = await groupRepo.findOne({
14859
15120
  where: {
14860
- name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
15121
+ name: chunkO4AFPDQ4_cjs.VENDOR_GROUP_NAME,
14861
15122
  deleted: false
14862
15123
  }
14863
15124
  });
@@ -14872,12 +15133,12 @@ function createVendorOnboardHandlers(config) {
14872
15133
  if (!ownerGroup) {
14873
15134
  try {
14874
15135
  await groupRepo.save(groupRepo.create({
14875
- name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
15136
+ name: chunkO4AFPDQ4_cjs.VENDOR_GROUP_NAME,
14876
15137
  deleted: false
14877
15138
  }));
14878
15139
  ownerGroup = await groupRepo.findOne({
14879
15140
  where: {
14880
- name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
15141
+ name: chunkO4AFPDQ4_cjs.VENDOR_GROUP_NAME,
14881
15142
  deleted: false
14882
15143
  }
14883
15144
  });
@@ -14994,7 +15255,7 @@ function createVendorOnboardHandlers(config) {
14994
15255
  }
14995
15256
  if (entityMap.customer) {
14996
15257
  try {
14997
- await chunk4U6DATGZ_cjs.ensureCustomerForUser(em, entityMap.customer, {
15258
+ await chunkOV5TRZET_cjs.ensureCustomerForUser(em, entityMap.customer, {
14998
15259
  id: newUser.id,
14999
15260
  name: userName,
15000
15261
  email: userEmail,
@@ -15494,7 +15755,7 @@ function createVendorOnboardHandlers(config) {
15494
15755
  if (!groupId) {
15495
15756
  const g = await groupRepo.findOne({
15496
15757
  where: {
15497
- name: chunkJ7FMZK66_cjs.VENDOR_GROUP_NAME,
15758
+ name: chunkO4AFPDQ4_cjs.VENDOR_GROUP_NAME,
15498
15759
  deleted: false
15499
15760
  }
15500
15761
  }) ?? await groupRepo.findOne({
@@ -15594,7 +15855,7 @@ function createVendorOnboardHandlers(config) {
15594
15855
  }
15595
15856
  if (entityMap.customer) {
15596
15857
  try {
15597
- await chunk4U6DATGZ_cjs.ensureCustomerForUser(em, entityMap.customer, {
15858
+ await chunkOV5TRZET_cjs.ensureCustomerForUser(em, entityMap.customer, {
15598
15859
  id: newUser.id,
15599
15860
  name: userName,
15600
15861
  email: userEmail,
@@ -16131,10 +16392,10 @@ chunkUSNT2KNT_cjs.__name(createVendorOnboardHandlers, "createVendorOnboardHandle
16131
16392
  function createVendorRolesHandlers(config) {
16132
16393
  const { dataSource, entityMap, json, getSessionUser } = config;
16133
16394
  const vendorRoleEntities = [
16134
- ...chunkJ7FMZK66_cjs.VENDOR_RBAC_ENTITIES
16395
+ ...chunkO4AFPDQ4_cjs.VENDOR_RBAC_ENTITIES
16135
16396
  ].sort();
16136
16397
  async function resolveActiveVendorId(u) {
16137
- const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u);
16398
+ const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u);
16138
16399
  if (scope.type === "vendor") return scope.vendorId;
16139
16400
  if (scope.type === "all") {
16140
16401
  const id = u.activeVendorId ?? u.vendorIds?.[0];
@@ -16150,7 +16411,7 @@ function createVendorRolesHandlers(config) {
16150
16411
  }, {
16151
16412
  status: 401
16152
16413
  });
16153
- if (!chunkJ7FMZK66_cjs.canManageVendorRoles(u)) return json({
16414
+ if (!chunkO4AFPDQ4_cjs.canManageVendorRoles(u)) return json({
16154
16415
  error: "Forbidden"
16155
16416
  }, {
16156
16417
  status: 403
@@ -25145,6 +25406,109 @@ _ts_decorate69([
25145
25406
  exports.OrderNotificationTrigger = _ts_decorate69([
25146
25407
  typeorm.Entity("order_notification_triggers")
25147
25408
  ], exports.OrderNotificationTrigger);
25409
+ function _ts_decorate70(decorators, target, key, desc) {
25410
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
25411
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25412
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
25413
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
25414
+ }
25415
+ chunkUSNT2KNT_cjs.__name(_ts_decorate70, "_ts_decorate");
25416
+ function _ts_metadata70(k, v) {
25417
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25418
+ }
25419
+ chunkUSNT2KNT_cjs.__name(_ts_metadata70, "_ts_metadata");
25420
+ exports.OrderAssignee = class OrderAssignee {
25421
+ static {
25422
+ chunkUSNT2KNT_cjs.__name(this, "OrderAssignee");
25423
+ }
25424
+ id;
25425
+ orderId;
25426
+ userId;
25427
+ vendorId;
25428
+ sortOrder;
25429
+ assignedAt;
25430
+ createdAt;
25431
+ order;
25432
+ user;
25433
+ vendor;
25434
+ };
25435
+ _ts_decorate70([
25436
+ typeorm.PrimaryGeneratedColumn(),
25437
+ _ts_metadata70("design:type", Number)
25438
+ ], exports.OrderAssignee.prototype, "id", void 0);
25439
+ _ts_decorate70([
25440
+ typeorm.Column("int"),
25441
+ _ts_metadata70("design:type", Number)
25442
+ ], exports.OrderAssignee.prototype, "orderId", void 0);
25443
+ _ts_decorate70([
25444
+ typeorm.Column("int"),
25445
+ _ts_metadata70("design:type", Number)
25446
+ ], exports.OrderAssignee.prototype, "userId", void 0);
25447
+ _ts_decorate70([
25448
+ typeorm.Column("int", {
25449
+ nullable: true
25450
+ }),
25451
+ _ts_metadata70("design:type", Object)
25452
+ ], exports.OrderAssignee.prototype, "vendorId", void 0);
25453
+ _ts_decorate70([
25454
+ typeorm.Column("int", {
25455
+ default: 1
25456
+ }),
25457
+ _ts_metadata70("design:type", Number)
25458
+ ], exports.OrderAssignee.prototype, "sortOrder", void 0);
25459
+ _ts_decorate70([
25460
+ typeorm.Column({
25461
+ type: "timestamp with time zone",
25462
+ default: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(() => "CURRENT_TIMESTAMP", "default")
25463
+ }),
25464
+ _ts_metadata70("design:type", typeof Date === "undefined" ? Object : Date)
25465
+ ], exports.OrderAssignee.prototype, "assignedAt", void 0);
25466
+ _ts_decorate70([
25467
+ typeorm.CreateDateColumn({
25468
+ type: "timestamp with time zone"
25469
+ }),
25470
+ _ts_metadata70("design:type", typeof Date === "undefined" ? Object : Date)
25471
+ ], exports.OrderAssignee.prototype, "createdAt", void 0);
25472
+ _ts_decorate70([
25473
+ typeorm.ManyToOne(() => exports.Order, {
25474
+ onDelete: "CASCADE"
25475
+ }),
25476
+ typeorm.JoinColumn({
25477
+ name: "orderId"
25478
+ }),
25479
+ _ts_metadata70("design:type", typeof exports.Order === "undefined" ? Object : exports.Order)
25480
+ ], exports.OrderAssignee.prototype, "order", void 0);
25481
+ _ts_decorate70([
25482
+ typeorm.ManyToOne(() => exports.User, {
25483
+ onDelete: "CASCADE"
25484
+ }),
25485
+ typeorm.JoinColumn({
25486
+ name: "userId"
25487
+ }),
25488
+ _ts_metadata70("design:type", typeof exports.User === "undefined" ? Object : exports.User)
25489
+ ], exports.OrderAssignee.prototype, "user", void 0);
25490
+ _ts_decorate70([
25491
+ typeorm.ManyToOne(() => exports.Vendor, {
25492
+ nullable: true,
25493
+ onDelete: "SET NULL"
25494
+ }),
25495
+ typeorm.JoinColumn({
25496
+ name: "vendorId"
25497
+ }),
25498
+ _ts_metadata70("design:type", Object)
25499
+ ], exports.OrderAssignee.prototype, "vendor", void 0);
25500
+ exports.OrderAssignee = _ts_decorate70([
25501
+ typeorm.Entity("order_assignees"),
25502
+ typeorm.Index("idx_order_assignees_order", [
25503
+ "orderId"
25504
+ ]),
25505
+ typeorm.Index("idx_order_assignees_user", [
25506
+ "userId"
25507
+ ]),
25508
+ typeorm.Index("idx_order_assignees_vendor", [
25509
+ "vendorId"
25510
+ ])
25511
+ ], exports.OrderAssignee);
25148
25512
 
25149
25513
  // src/entities/index.ts
25150
25514
  var CMS_ENTITY_MAP = {
@@ -25216,7 +25580,8 @@ var CMS_ENTITY_MAP = {
25216
25580
  attendees: exports.Attendee,
25217
25581
  order_notification_bindings: exports.OrderNotificationBinding,
25218
25582
  order_notification_triggers: exports.OrderNotificationTrigger,
25219
- user_device_tokens: exports.UserDeviceToken
25583
+ user_device_tokens: exports.UserDeviceToken,
25584
+ order_assignees: exports.OrderAssignee
25220
25585
  };
25221
25586
 
25222
25587
  // src/plugins/blog-generator/blog-generator-agent-defaults.ts
@@ -28992,7 +29357,7 @@ function createCmsApiHandler(config) {
28992
29357
  ] : baseCrudResources;
28993
29358
  const requireEntityPermissionEffective = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async (_req, entity, action) => {
28994
29359
  if (!resolveSessionUser) {
28995
- chunkJ7FMZK66_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
29360
+ chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
28996
29361
  entity,
28997
29362
  action,
28998
29363
  hint: "Pass getSessionUser: auth.getAuthenticatedUser from createCmsAuthBundle()"
@@ -29002,7 +29367,7 @@ function createCmsApiHandler(config) {
29002
29367
  const raw = await resolveSessionUser();
29003
29368
  const u = await hydrateVendorSessionUser(dataSource, raw);
29004
29369
  if (!u?.email) {
29005
- chunkJ7FMZK66_cjs.logRbac("requireEntityPermission: no session user", {
29370
+ chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: no session user", {
29006
29371
  entity,
29007
29372
  action
29008
29373
  });
@@ -29012,13 +29377,13 @@ function createCmsApiHandler(config) {
29012
29377
  status: 401
29013
29378
  });
29014
29379
  }
29015
- const allowed = chunk4U6DATGZ_cjs.sessionHasEntityAccess(u, entity, action);
29016
- await chunkJ7FMZK66_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
29380
+ const allowed = chunkOV5TRZET_cjs.sessionHasEntityAccess(u, entity, action);
29381
+ await chunkO4AFPDQ4_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
29017
29382
  allowed,
29018
29383
  resolvePath: "hydrated_session"
29019
29384
  });
29020
29385
  if (allowed) return null;
29021
- const { reason } = chunkJ7FMZK66_cjs.explainSessionEntityAccess(u, entity, action);
29386
+ const { reason } = chunkO4AFPDQ4_cjs.explainSessionEntityAccess(u, entity, action);
29022
29387
  return config.json({
29023
29388
  error: "Forbidden",
29024
29389
  entity,
@@ -29029,7 +29394,7 @@ function createCmsApiHandler(config) {
29029
29394
  });
29030
29395
  }
29031
29396
  if (userRequireEntityPermission) {
29032
- chunkJ7FMZK66_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
29397
+ chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
29033
29398
  entity,
29034
29399
  action
29035
29400
  });
@@ -29116,10 +29481,10 @@ function createCmsApiHandler(config) {
29116
29481
  getVendorScope: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
29117
29482
  const multiVendorEnabled = await checkMultiVendorEnabled(dataSource);
29118
29483
  if (!multiVendorEnabled) {
29119
- return chunkJ7FMZK66_cjs.resolveDisabledMultiVendorScope(dataSource);
29484
+ return chunkO4AFPDQ4_cjs.resolveDisabledMultiVendorScope(dataSource);
29120
29485
  }
29121
29486
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
29122
- return chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29487
+ return chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
29123
29488
  }, "getVendorScope"),
29124
29489
  getHydratedSessionUser: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
29125
29490
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
@@ -30467,7 +30832,7 @@ function createCmsApiHandler(config) {
30467
30832
  let vendorId = null;
30468
30833
  if (resolveSessionUser) {
30469
30834
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
30470
- const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
30835
+ const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
30471
30836
  if (scope.type === "vendor") vendorId = scope.vendorId;
30472
30837
  }
30473
30838
  const result = await validateCoupon(dataSource, entityMap, couponCode, orderLinesNorm, currency, contactId, isAutomatic, discountId ?? void 0, vendorId);
@@ -30555,7 +30920,7 @@ function createCmsApiHandler(config) {
30555
30920
  let vendorId = null;
30556
30921
  if (resolveSessionUser) {
30557
30922
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
30558
- const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
30923
+ const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
30559
30924
  if (scope.type === "vendor") vendorId = scope.vendorId;
30560
30925
  }
30561
30926
  const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
@@ -31112,8 +31477,8 @@ function createCmsApiHandler(config) {
31112
31477
  }, {
31113
31478
  status: 400
31114
31479
  });
31115
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-NK65LOLV.cjs');
31116
- const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
31480
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-DZAXK4GQ.cjs');
31481
+ const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
31117
31482
  return handlers.getChannels(req, orderId);
31118
31483
  }
31119
31484
  if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "send" && m === "POST" && getCms) {
@@ -31127,8 +31492,8 @@ function createCmsApiHandler(config) {
31127
31492
  }, {
31128
31493
  status: 400
31129
31494
  });
31130
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-NK65LOLV.cjs');
31131
- const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
31495
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-DZAXK4GQ.cjs');
31496
+ const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
31132
31497
  return handlers.sendOtp(req, orderId);
31133
31498
  }
31134
31499
  if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "verify" && m === "POST" && getCms) {
@@ -31142,8 +31507,8 @@ function createCmsApiHandler(config) {
31142
31507
  }, {
31143
31508
  status: 400
31144
31509
  });
31145
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-NK65LOLV.cjs');
31146
- const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
31510
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-DZAXK4GQ.cjs');
31511
+ const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
31147
31512
  return handlers.verifyOtp(req, orderId);
31148
31513
  }
31149
31514
  if (path2[0] === "orders" && path2.length === 3 && path2[2] === "eligible-assignees" && m === "GET") {
@@ -31157,7 +31522,7 @@ function createCmsApiHandler(config) {
31157
31522
  }, {
31158
31523
  status: 400
31159
31524
  });
31160
- const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-NPKD64P6.cjs');
31525
+ const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-KF7RMTV5.cjs');
31161
31526
  const handlers = createOrderAssigneesHandlers(dataSource, entityMap, getHydratedSessionUser);
31162
31527
  return handlers.listEligibleAssignees(req, orderId);
31163
31528
  }
@@ -31267,7 +31632,7 @@ function createCmsApiHandler(config) {
31267
31632
  if (resolveSessionUser) {
31268
31633
  const raw = await resolveSessionUser();
31269
31634
  const u = await hydrateVendorSessionUser(dataSource, raw);
31270
- const scope = chunkJ7FMZK66_cjs.resolveVendorScopeFromSessionUser(u ?? null);
31635
+ const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
31271
31636
  if (scope.type === "vendor") {
31272
31637
  scopedVendorIds = scope.vendorIds;
31273
31638
  }
@@ -33656,10 +34021,10 @@ function createStorefrontApiHandler(config) {
33656
34021
  adminAccess: false
33657
34022
  }));
33658
34023
  const userId = newUser.id;
33659
- await chunk4U6DATGZ_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
34024
+ await chunkOV5TRZET_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
33660
34025
  if (entityMap.customer) {
33661
34026
  const phone = typeof b.phone === "string" && b.phone.trim() ? String(b.phone).trim() : null;
33662
- await chunk4U6DATGZ_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
34027
+ await chunkOV5TRZET_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
33663
34028
  id: userId,
33664
34029
  name,
33665
34030
  email,