@infuro/cms-core 1.0.65 → 1.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin.cjs +97 -24
- package/dist/admin.js +97 -24
- package/dist/api.cjs +38 -38
- package/dist/api.js +5 -5
- package/dist/auth.cjs +51 -51
- package/dist/auth.js +3 -3
- package/dist/{chunk-6DBDJ4VD.js → chunk-2ISSXYBZ.js} +2 -2
- package/dist/{chunk-NIRYYJIJ.cjs → chunk-5MZFQRDW.cjs} +73 -55
- package/dist/{chunk-MVHDC3XF.js → chunk-5NOZSG6J.js} +22 -11
- package/dist/{chunk-YHEITFHR.cjs → chunk-BVLN75LP.cjs} +540 -143
- package/dist/{chunk-YEAXE4U2.js → chunk-FLUF2GZH.js} +5 -11
- package/dist/{chunk-SANKKGB3.js → chunk-GLLCLRCQ.js} +464 -67
- package/dist/{chunk-ACBN6UWZ.js → chunk-NV5IRHI3.js} +26 -8
- package/dist/{chunk-J7FMZK66.cjs → chunk-O4AFPDQ4.cjs} +22 -11
- package/dist/{chunk-4U6DATGZ.cjs → chunk-OV5TRZET.cjs} +7 -7
- package/dist/{chunk-BXAKL2TF.cjs → chunk-PA6YDMFZ.cjs} +5 -11
- package/dist/{chunk-RDEVZMO5.js → chunk-RCE5SJBA.js} +2 -2
- package/dist/{chunk-KM2I6AFP.cjs → chunk-SS3K7OIM.cjs} +9 -9
- package/dist/{chunk-V6EYAC7X.cjs → chunk-WMMZZRDJ.cjs} +15 -15
- package/dist/{chunk-NR44CK5E.js → chunk-ZY64VJMS.js} +1 -1
- package/dist/{emit-order-notification-trigger-UCKJHDQK.js → emit-order-notification-trigger-EJJZ6XTS.js} +2 -2
- package/dist/{emit-order-notification-trigger-DR74TQXN.cjs → emit-order-notification-trigger-ZD5YN3JM.cjs} +4 -4
- package/dist/index.cjs +284 -280
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +10 -10
- package/dist/migrations/1783300000000-CreateOrderAssigneesTable.ts +43 -0
- package/dist/{order-assignees-handlers-NPKD64P6.cjs → order-assignees-handlers-KF7RMTV5.cjs} +77 -8
- package/dist/{order-assignees-handlers-LKMAGLG6.js → order-assignees-handlers-L3RVKUBS.js} +77 -8
- package/dist/{order-completion-otp-handlers-RW5RSXH3.cjs → order-completion-otp-handlers-DZAXK4GQ.cjs} +70 -16
- package/dist/{order-completion-otp-handlers-CH22ZRAI.js → order-completion-otp-handlers-HFGCPC4O.js} +69 -15
- package/dist/{order-notification-dispatcher-3TXUAJ7L.js → order-notification-dispatcher-ECPFI7CD.js} +2 -2
- package/dist/{order-notification-dispatcher-Y7NZAALH.cjs → order-notification-dispatcher-LL7ETKLU.cjs} +7 -7
- package/dist/{rbac-debug-db-5R6XFPSV.js → rbac-debug-db-DFZWZ6GV.js} +1 -1
- package/dist/{rbac-debug-db-JKK2MCWF.cjs → rbac-debug-db-KWV7D5PQ.cjs} +2 -2
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var chunkWFMVD567_cjs = require('./chunk-WFMVD567.cjs');
|
|
4
4
|
var chunkTHL5JDWJ_cjs = require('./chunk-THL5JDWJ.cjs');
|
|
5
5
|
var chunkHY3AXLOI_cjs = require('./chunk-HY3AXLOI.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunk5MZFQRDW_cjs = require('./chunk-5MZFQRDW.cjs');
|
|
7
7
|
var chunkH3IVLIPR_cjs = require('./chunk-H3IVLIPR.cjs');
|
|
8
8
|
var chunk7NMT3GBR_cjs = require('./chunk-7NMT3GBR.cjs');
|
|
9
9
|
var chunkXFDIIVZB_cjs = require('./chunk-XFDIIVZB.cjs');
|
|
@@ -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
|
|
15
|
+
var chunkOV5TRZET_cjs = require('./chunk-OV5TRZET.cjs');
|
|
16
16
|
var chunkOY2YTBMP_cjs = require('./chunk-OY2YTBMP.cjs');
|
|
17
|
-
var
|
|
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 =
|
|
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
|
-
|
|
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 ??
|
|
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 =
|
|
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
|
-
|
|
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" ||
|
|
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
|
|
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
|
-
|
|
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
|
|
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,
|
|
@@ -5239,7 +5323,7 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
5239
5323
|
const orderIdForNotify = created.id;
|
|
5240
5324
|
const finalCreatedStatus = String(created.status ?? createdStatus ?? "pending").toLowerCase();
|
|
5241
5325
|
const initialPayStatus = String(persistBody.paymentStatus ?? body.paymentStatus ?? "unpaid").toLowerCase();
|
|
5242
|
-
void import('./emit-order-notification-trigger-
|
|
5326
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
5243
5327
|
if (finalCreatedStatus === "pending") {
|
|
5244
5328
|
if (initialPayStatus === "failed") {
|
|
5245
5329
|
fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
|
|
@@ -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
|
-
|
|
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)
|
|
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"
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
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
|
-
|
|
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
|
|
6283
|
+
error: "Cannot start processing without assigning a vendor or teammate. Please assign first."
|
|
6077
6284
|
}, {
|
|
6078
6285
|
status: 400
|
|
6079
6286
|
});
|
|
@@ -6319,7 +6526,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6319
6526
|
const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
|
|
6320
6527
|
const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
|
|
6321
6528
|
if (assigneeUpdated) {
|
|
6322
|
-
void import('./emit-order-notification-trigger-
|
|
6529
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
6323
6530
|
fireOrderNotificationTrigger("order_assigned", updatedOrder.id, {
|
|
6324
6531
|
dataSource,
|
|
6325
6532
|
entityMap
|
|
@@ -6336,7 +6543,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6336
6543
|
const payments = Array.isArray(updatedOrder.payments) ? updatedOrder.payments : [];
|
|
6337
6544
|
const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
|
|
6338
6545
|
const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
|
|
6339
|
-
void import('./emit-order-notification-trigger-
|
|
6546
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
6340
6547
|
if (newStatus === "pending") {
|
|
6341
6548
|
if (curPayStatus === "failed") {
|
|
6342
6549
|
fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
7164
|
+
error: "Cannot start processing without assigning a vendor or teammate. Please assign first."
|
|
6904
7165
|
}, {
|
|
6905
7166
|
status: 400
|
|
6906
7167
|
});
|
|
@@ -6990,7 +7251,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6990
7251
|
});
|
|
6991
7252
|
}
|
|
6992
7253
|
if (ordStatus === "pending" || ordStatus === "confirmed") {
|
|
6993
|
-
void import('./emit-order-notification-trigger-
|
|
7254
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
6994
7255
|
fireOrderNotificationTrigger("order_placed", pOrder, {
|
|
6995
7256
|
dataSource,
|
|
6996
7257
|
entityMap
|
|
@@ -7004,7 +7265,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
7004
7265
|
}
|
|
7005
7266
|
}
|
|
7006
7267
|
} else if (newPayStatus === "failed") {
|
|
7007
|
-
void import('./emit-order-notification-trigger-
|
|
7268
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
7008
7269
|
fireOrderNotificationTrigger("payment_failed", pOrder, {
|
|
7009
7270
|
dataSource,
|
|
7010
7271
|
entityMap
|
|
@@ -7012,7 +7273,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
7012
7273
|
}).catch(() => {
|
|
7013
7274
|
});
|
|
7014
7275
|
} else if (newPayStatus === "refunded") {
|
|
7015
|
-
void import('./emit-order-notification-trigger-
|
|
7276
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
7016
7277
|
fireOrderNotificationTrigger("payment_refund_initiated", pOrder, {
|
|
7017
7278
|
dataSource,
|
|
7018
7279
|
entityMap
|
|
@@ -7139,7 +7400,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
7139
7400
|
const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
|
|
7140
7401
|
const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
|
|
7141
7402
|
if (assigneeUpdated) {
|
|
7142
|
-
void import('./emit-order-notification-trigger-
|
|
7403
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
7143
7404
|
fireOrderNotificationTrigger("order_assigned", ord.id, {
|
|
7144
7405
|
dataSource,
|
|
7145
7406
|
entityMap
|
|
@@ -7156,7 +7417,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
7156
7417
|
const payments = Array.isArray(ord.payments) ? ord.payments : [];
|
|
7157
7418
|
const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
|
|
7158
7419
|
const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
|
|
7159
|
-
void import('./emit-order-notification-trigger-
|
|
7420
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
7160
7421
|
if (newStatus === "pending") {
|
|
7161
7422
|
if (curPayStatus === "failed") {
|
|
7162
7423
|
fireOrderNotificationTrigger("payment_failed", ord.id, {
|
|
@@ -7853,7 +8114,7 @@ function createInviteAcceptHandler(config) {
|
|
|
7853
8114
|
}
|
|
7854
8115
|
const { userId, email, vendorId } = validation.target;
|
|
7855
8116
|
if (entityMap.contacts) {
|
|
7856
|
-
await
|
|
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 || !
|
|
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
|
|
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
|
|
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),
|
|
@@ -11602,7 +11863,7 @@ function createChatHandlers(config) {
|
|
|
11602
11863
|
const notifyEmailAgent = await findLlmAgentByScope(dataSource, entityMap, LLM_AGENT_SCOPE_EMAIL_INTENT_CHATBOT, {
|
|
11603
11864
|
enabledOnly: false
|
|
11604
11865
|
});
|
|
11605
|
-
const emailTool =
|
|
11866
|
+
const emailTool = chunk5MZFQRDW_cjs.resolveChatEmailToolSettings(llmSettings, {
|
|
11606
11867
|
chatbotValidationRules: agentRow?.validationRules ?? null,
|
|
11607
11868
|
notifyAgent: notifyEmailAgent ? {
|
|
11608
11869
|
systemInstruction: notifyEmailAgent.systemInstruction,
|
|
@@ -11612,7 +11873,7 @@ function createChatHandlers(config) {
|
|
|
11612
11873
|
const emailPlugin2 = cms.getPlugin("email");
|
|
11613
11874
|
const convLeadSent = conv.leadEmailSentAt;
|
|
11614
11875
|
const chatAgentFn = llm.chatAgent?.bind(llm);
|
|
11615
|
-
console.info(
|
|
11876
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline check", {
|
|
11616
11877
|
conversationId,
|
|
11617
11878
|
enabled: emailTool.enabled,
|
|
11618
11879
|
intentCount: emailTool.intents.length,
|
|
@@ -11626,27 +11887,27 @@ function createChatHandlers(config) {
|
|
|
11626
11887
|
mergedPromptIncludesNotify: Boolean(notifyEmailAgent?.systemInstruction?.trim())
|
|
11627
11888
|
});
|
|
11628
11889
|
if (!emailTool.enabled) {
|
|
11629
|
-
console.info(
|
|
11890
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
11630
11891
|
conversationId,
|
|
11631
11892
|
reason: "email_tool_disabled"
|
|
11632
11893
|
});
|
|
11633
11894
|
} else if (emailTool.intents.length === 0) {
|
|
11634
|
-
console.info(
|
|
11895
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
11635
11896
|
conversationId,
|
|
11636
11897
|
reason: "no_intents_configured"
|
|
11637
11898
|
});
|
|
11638
11899
|
} else if (!emailPlugin2) {
|
|
11639
|
-
console.info(
|
|
11900
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
11640
11901
|
conversationId,
|
|
11641
11902
|
reason: "email_plugin_missing"
|
|
11642
11903
|
});
|
|
11643
11904
|
} else if (!chatAgentFn) {
|
|
11644
|
-
console.info(
|
|
11905
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
11645
11906
|
conversationId,
|
|
11646
11907
|
reason: "llm_chat_agent_unavailable"
|
|
11647
11908
|
});
|
|
11648
11909
|
} else if (convLeadSent) {
|
|
11649
|
-
console.info(
|
|
11910
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
11650
11911
|
conversationId,
|
|
11651
11912
|
reason: "lead_email_already_sent",
|
|
11652
11913
|
leadEmailSentAt: convLeadSent
|
|
@@ -11659,7 +11920,7 @@ function createChatHandlers(config) {
|
|
|
11659
11920
|
}
|
|
11660
11921
|
});
|
|
11661
11922
|
if (!contactRow) {
|
|
11662
|
-
console.warn(
|
|
11923
|
+
console.warn(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
11663
11924
|
conversationId,
|
|
11664
11925
|
reason: "contact_not_found",
|
|
11665
11926
|
contactId
|
|
@@ -11667,7 +11928,7 @@ function createChatHandlers(config) {
|
|
|
11667
11928
|
} else {
|
|
11668
11929
|
const c = contactRow;
|
|
11669
11930
|
try {
|
|
11670
|
-
const intent = await
|
|
11931
|
+
const intent = await chunk5MZFQRDW_cjs.detectChatLeadIntent({
|
|
11671
11932
|
chatAgent: chatAgentFn
|
|
11672
11933
|
}, {
|
|
11673
11934
|
settings: emailTool,
|
|
@@ -11681,15 +11942,15 @@ function createChatHandlers(config) {
|
|
|
11681
11942
|
model: agentRow?.model?.trim() || notifyEmailAgent?.model?.trim() || void 0
|
|
11682
11943
|
});
|
|
11683
11944
|
if (!intent.intent || !intent.emailTo) {
|
|
11684
|
-
console.info(
|
|
11945
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "no email sent", {
|
|
11685
11946
|
conversationId,
|
|
11686
11947
|
reason: intent.intent ? "missing_email_to" : "no_intent_match",
|
|
11687
11948
|
intentLabel: intent.intentLabel,
|
|
11688
11949
|
classifierReason: intent.reason
|
|
11689
11950
|
});
|
|
11690
11951
|
} else {
|
|
11691
|
-
const intentRecipients =
|
|
11692
|
-
console.info(
|
|
11952
|
+
const intentRecipients = chunk5MZFQRDW_cjs.parseIntentRecipientEmails(intent.emailTo);
|
|
11953
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
|
|
11693
11954
|
conversationId,
|
|
11694
11955
|
intent: intent.intent,
|
|
11695
11956
|
emailTo: intent.emailTo,
|
|
@@ -11700,7 +11961,7 @@ function createChatHandlers(config) {
|
|
|
11700
11961
|
const brandingSettings = await loadSettingsGroupMap(dataSource, entityMap, "branding");
|
|
11701
11962
|
const storeSettings = await loadSettingsGroupMap(dataSource, entityMap, "store");
|
|
11702
11963
|
const companyDetails = chunkTZEMLHSP_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings, storeSettings);
|
|
11703
|
-
const leadResult = await
|
|
11964
|
+
const leadResult = await chunk5MZFQRDW_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
|
|
11704
11965
|
contactName: String(c.name ?? "").trim() || "Visitor",
|
|
11705
11966
|
contactEmail: String(c.email ?? "").trim(),
|
|
11706
11967
|
contactPhone: c.phone ?? null,
|
|
@@ -11708,7 +11969,7 @@ function createChatHandlers(config) {
|
|
|
11708
11969
|
latestMessage: message,
|
|
11709
11970
|
intentCode: intent.intent,
|
|
11710
11971
|
intentReason: intent.intentLabel || intent.reason,
|
|
11711
|
-
transcript:
|
|
11972
|
+
transcript: chunk5MZFQRDW_cjs.buildTranscriptForLeadEmail(history, message),
|
|
11712
11973
|
companyDetails,
|
|
11713
11974
|
recipients: intentRecipients.length > 0 ? intentRecipients : void 0
|
|
11714
11975
|
});
|
|
@@ -11716,13 +11977,13 @@ function createChatHandlers(config) {
|
|
|
11716
11977
|
await convRepo().update(conversationId, {
|
|
11717
11978
|
leadEmailSentAt: /* @__PURE__ */ new Date()
|
|
11718
11979
|
});
|
|
11719
|
-
console.info(
|
|
11980
|
+
console.info(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
|
|
11720
11981
|
conversationId,
|
|
11721
11982
|
sent: true,
|
|
11722
11983
|
recipients: leadResult.recipients
|
|
11723
11984
|
});
|
|
11724
11985
|
} else {
|
|
11725
|
-
console.warn(
|
|
11986
|
+
console.warn(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
|
|
11726
11987
|
conversationId,
|
|
11727
11988
|
sent: false,
|
|
11728
11989
|
error: leadResult.error ?? "unknown",
|
|
@@ -11731,7 +11992,7 @@ function createChatHandlers(config) {
|
|
|
11731
11992
|
}
|
|
11732
11993
|
}
|
|
11733
11994
|
} catch (intentErr) {
|
|
11734
|
-
console.warn(
|
|
11995
|
+
console.warn(chunk5MZFQRDW_cjs.CHAT_EMAIL_LOG, "pipeline error", {
|
|
11735
11996
|
conversationId,
|
|
11736
11997
|
error: intentErr instanceof Error ? intentErr.message : String(intentErr)
|
|
11737
11998
|
});
|
|
@@ -11748,7 +12009,7 @@ function createChatHandlers(config) {
|
|
|
11748
12009
|
});
|
|
11749
12010
|
if (agentRow && llm.chatAgent) {
|
|
11750
12011
|
const fromAgent = llmAgentToChatAgentOptions(agentRow);
|
|
11751
|
-
const systemPrompt =
|
|
12012
|
+
const systemPrompt = chunk5MZFQRDW_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
|
|
11752
12013
|
const res = await llm.chatAgent({
|
|
11753
12014
|
...fromAgent,
|
|
11754
12015
|
systemPrompt: systemPrompt || void 0,
|
|
@@ -11769,7 +12030,7 @@ ${contextParts.join("\n\n")}` : "";
|
|
|
11769
12030
|
agentRow.systemInstruction?.trim(),
|
|
11770
12031
|
ragSystem
|
|
11771
12032
|
].filter(Boolean).join("\n\n");
|
|
11772
|
-
systemContent =
|
|
12033
|
+
systemContent = chunk5MZFQRDW_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
|
|
11773
12034
|
} else {
|
|
11774
12035
|
systemContent = ragSystem || defaultSystem;
|
|
11775
12036
|
}
|
|
@@ -13024,7 +13285,7 @@ function createDeviceTokensHandlers(config) {
|
|
|
13024
13285
|
const title = body.title?.trim() || "Test Push Notification";
|
|
13025
13286
|
const msgBody = body.body?.trim() || "Firebase Push Notification setup is working!";
|
|
13026
13287
|
if (!token || token === "validate" || token === "validate_only") {
|
|
13027
|
-
const valRes = await
|
|
13288
|
+
const valRes = await chunk5MZFQRDW_cjs.validateFcmCredentials(dataSource, entityMap);
|
|
13028
13289
|
if (!valRes.success) {
|
|
13029
13290
|
return json({
|
|
13030
13291
|
success: false,
|
|
@@ -13041,7 +13302,7 @@ function createDeviceTokensHandlers(config) {
|
|
|
13041
13302
|
clientEmail: valRes.clientEmail
|
|
13042
13303
|
});
|
|
13043
13304
|
}
|
|
13044
|
-
const res = await
|
|
13305
|
+
const res = await chunk5MZFQRDW_cjs.sendFcmPushNotification(dataSource, entityMap, {
|
|
13045
13306
|
token,
|
|
13046
13307
|
title,
|
|
13047
13308
|
body: msgBody,
|
|
@@ -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 =
|
|
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 (!
|
|
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
|
|
13885
|
+
return chunkO4AFPDQ4_cjs.canManageVendorRoles(u) && !chunkOV5TRZET_cjs.canManageRoles(u);
|
|
13625
13886
|
}
|
|
13626
13887
|
chunkUSNT2KNT_cjs.__name(isVendorRolesOnly, "isVendorRolesOnly");
|
|
13627
13888
|
const vendorRoleEntities = [
|
|
13628
|
-
...
|
|
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 (
|
|
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 (
|
|
14103
|
+
if (chunkO4AFPDQ4_cjs.isSuperAdminGroupName(g.name)) return json({
|
|
13843
14104
|
error: "Cannot delete the administrator group"
|
|
13844
14105
|
}, {
|
|
13845
14106
|
status: 400
|
|
@@ -14037,7 +14298,7 @@ async function sendVendorOnboardEmails(input, deps) {
|
|
|
14037
14298
|
getVendorEmails(deps)
|
|
14038
14299
|
]);
|
|
14039
14300
|
const companyDetails = chunkTZEMLHSP_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings, storeSettings);
|
|
14040
|
-
const configuredNotify =
|
|
14301
|
+
const configuredNotify = chunk5MZFQRDW_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
|
|
14041
14302
|
const ownerEmail = input.ownerEmail?.trim() || "";
|
|
14042
14303
|
const ownerEmailLower = ownerEmail.toLowerCase();
|
|
14043
14304
|
const sendToOwner = input.sendToOwner !== false;
|
|
@@ -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
|
|
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 ===
|
|
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
|
|
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 ===
|
|
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[
|
|
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
|
-
|
|
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 (!
|
|
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 =
|
|
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 (!
|
|
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 (!
|
|
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:
|
|
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:
|
|
15136
|
+
name: chunkO4AFPDQ4_cjs.VENDOR_GROUP_NAME,
|
|
14876
15137
|
deleted: false
|
|
14877
15138
|
}));
|
|
14878
15139
|
ownerGroup = await groupRepo.findOne({
|
|
14879
15140
|
where: {
|
|
14880
|
-
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
|
|
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:
|
|
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
|
|
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
|
-
...
|
|
16395
|
+
...chunkO4AFPDQ4_cjs.VENDOR_RBAC_ENTITIES
|
|
16135
16396
|
].sort();
|
|
16136
16397
|
async function resolveActiveVendorId(u) {
|
|
16137
|
-
const scope =
|
|
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 (!
|
|
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
|
|
@@ -28324,7 +28689,7 @@ function slugify2(input) {
|
|
|
28324
28689
|
return input.toLowerCase().trim().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 64) || "template";
|
|
28325
28690
|
}
|
|
28326
28691
|
chunkUSNT2KNT_cjs.__name(slugify2, "slugify");
|
|
28327
|
-
function
|
|
28692
|
+
function createTextMessageTemplatesHandlers(config, channel) {
|
|
28328
28693
|
const { dataSource, entityMap, json, requireAuth, requireEntityPermission } = config;
|
|
28329
28694
|
const templateRepo = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(() => dataSource.getRepository(entityMap.message_templates), "templateRepo");
|
|
28330
28695
|
async function requireRead(req, entity) {
|
|
@@ -28347,6 +28712,10 @@ function createEmailMessageTemplatesHandlers(config) {
|
|
|
28347
28712
|
return null;
|
|
28348
28713
|
}
|
|
28349
28714
|
chunkUSNT2KNT_cjs.__name(requireUpdate, "requireUpdate");
|
|
28715
|
+
function isLegacyPushTemplate(row) {
|
|
28716
|
+
return row.channel === "email" && typeof row.name === "string" && row.name.includes("_push_");
|
|
28717
|
+
}
|
|
28718
|
+
chunkUSNT2KNT_cjs.__name(isLegacyPushTemplate, "isLegacyPushTemplate");
|
|
28350
28719
|
return {
|
|
28351
28720
|
async listCached(req) {
|
|
28352
28721
|
const err = await requireRead(req, "settings");
|
|
@@ -28354,15 +28723,19 @@ function createEmailMessageTemplatesHandlers(config) {
|
|
|
28354
28723
|
try {
|
|
28355
28724
|
const rows = await templateRepo().find({
|
|
28356
28725
|
where: {
|
|
28357
|
-
channel: "email",
|
|
28358
28726
|
deleted: false
|
|
28359
28727
|
},
|
|
28360
28728
|
order: {
|
|
28361
28729
|
name: "ASC"
|
|
28362
28730
|
}
|
|
28363
28731
|
});
|
|
28732
|
+
const items = rows.filter((row) => {
|
|
28733
|
+
const r = row;
|
|
28734
|
+
if (channel === "email") return r.channel === "email" && !isLegacyPushTemplate(r);
|
|
28735
|
+
return r.channel === "mobile" || isLegacyPushTemplate(r);
|
|
28736
|
+
});
|
|
28364
28737
|
return json({
|
|
28365
|
-
items
|
|
28738
|
+
items
|
|
28366
28739
|
});
|
|
28367
28740
|
} catch {
|
|
28368
28741
|
return json({
|
|
@@ -28403,7 +28776,7 @@ function createEmailMessageTemplatesHandlers(config) {
|
|
|
28403
28776
|
let suffix = 1;
|
|
28404
28777
|
while (await templateRepo().findOne({
|
|
28405
28778
|
where: {
|
|
28406
|
-
channel
|
|
28779
|
+
channel,
|
|
28407
28780
|
templateKey,
|
|
28408
28781
|
deleted: false
|
|
28409
28782
|
}
|
|
@@ -28412,7 +28785,7 @@ function createEmailMessageTemplatesHandlers(config) {
|
|
|
28412
28785
|
templateKey = `${baseKey}_${suffix}`;
|
|
28413
28786
|
}
|
|
28414
28787
|
const row = await templateRepo().save(templateRepo().create({
|
|
28415
|
-
channel
|
|
28788
|
+
channel,
|
|
28416
28789
|
templateKey,
|
|
28417
28790
|
name,
|
|
28418
28791
|
subject,
|
|
@@ -28450,7 +28823,6 @@ function createEmailMessageTemplatesHandlers(config) {
|
|
|
28450
28823
|
const existing = await templateRepo().findOne({
|
|
28451
28824
|
where: {
|
|
28452
28825
|
id: numId,
|
|
28453
|
-
channel: "email",
|
|
28454
28826
|
deleted: false
|
|
28455
28827
|
}
|
|
28456
28828
|
});
|
|
@@ -28459,9 +28831,25 @@ function createEmailMessageTemplatesHandlers(config) {
|
|
|
28459
28831
|
}, {
|
|
28460
28832
|
status: 404
|
|
28461
28833
|
});
|
|
28834
|
+
const row = existing;
|
|
28835
|
+
if (channel === "email" && row.channel !== "email") {
|
|
28836
|
+
return json({
|
|
28837
|
+
error: "Template not found"
|
|
28838
|
+
}, {
|
|
28839
|
+
status: 404
|
|
28840
|
+
});
|
|
28841
|
+
}
|
|
28842
|
+
if (channel === "mobile" && row.channel !== "mobile" && !isLegacyPushTemplate(row)) {
|
|
28843
|
+
return json({
|
|
28844
|
+
error: "Template not found"
|
|
28845
|
+
}, {
|
|
28846
|
+
status: 404
|
|
28847
|
+
});
|
|
28848
|
+
}
|
|
28462
28849
|
const patch = {
|
|
28463
28850
|
updatedAt: /* @__PURE__ */ new Date()
|
|
28464
28851
|
};
|
|
28852
|
+
if (channel === "mobile") patch.channel = "mobile";
|
|
28465
28853
|
if (typeof body.name === "string" && body.name.trim()) patch.name = body.name.trim();
|
|
28466
28854
|
if (typeof body.subject === "string") patch.subject = body.subject;
|
|
28467
28855
|
if (typeof body.body === "string") {
|
|
@@ -28484,7 +28872,15 @@ function createEmailMessageTemplatesHandlers(config) {
|
|
|
28484
28872
|
}
|
|
28485
28873
|
};
|
|
28486
28874
|
}
|
|
28875
|
+
chunkUSNT2KNT_cjs.__name(createTextMessageTemplatesHandlers, "createTextMessageTemplatesHandlers");
|
|
28876
|
+
function createEmailMessageTemplatesHandlers(config) {
|
|
28877
|
+
return createTextMessageTemplatesHandlers(config, "email");
|
|
28878
|
+
}
|
|
28487
28879
|
chunkUSNT2KNT_cjs.__name(createEmailMessageTemplatesHandlers, "createEmailMessageTemplatesHandlers");
|
|
28880
|
+
function createMobileMessageTemplatesHandlers(config) {
|
|
28881
|
+
return createTextMessageTemplatesHandlers(config, "mobile");
|
|
28882
|
+
}
|
|
28883
|
+
chunkUSNT2KNT_cjs.__name(createMobileMessageTemplatesHandlers, "createMobileMessageTemplatesHandlers");
|
|
28488
28884
|
function connectionFromUrl(redisUrl) {
|
|
28489
28885
|
const u = new URL(redisUrl);
|
|
28490
28886
|
return {
|
|
@@ -28663,11 +29059,11 @@ function whatsappPlugin(config = {}) {
|
|
|
28663
29059
|
db = await settingsLoader?.() ?? {};
|
|
28664
29060
|
} catch {
|
|
28665
29061
|
}
|
|
28666
|
-
if (!
|
|
29062
|
+
if (!chunk5MZFQRDW_cjs.isWhatsAppPluginEnabled(db)) {
|
|
28667
29063
|
context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
|
|
28668
29064
|
return null;
|
|
28669
29065
|
}
|
|
28670
|
-
const svc = new
|
|
29066
|
+
const svc = new chunk5MZFQRDW_cjs.WhatsAppService(env, staticRest, settingsLoader, getMessageTemplateRow);
|
|
28671
29067
|
return {
|
|
28672
29068
|
send: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((opts) => svc.send(opts), "send")
|
|
28673
29069
|
};
|
|
@@ -28773,7 +29169,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
|
|
|
28773
29169
|
}
|
|
28774
29170
|
if (!cms.getPlugin("email")) {
|
|
28775
29171
|
try {
|
|
28776
|
-
const instance = await
|
|
29172
|
+
const instance = await chunk5MZFQRDW_cjs.emailPlugin({
|
|
28777
29173
|
type: "SMTP",
|
|
28778
29174
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
28779
29175
|
to: config.SMTP_TO ?? ""
|
|
@@ -28814,7 +29210,7 @@ function messagingPlugins(options) {
|
|
|
28814
29210
|
const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
|
|
28815
29211
|
return [
|
|
28816
29212
|
queuePlugin(),
|
|
28817
|
-
|
|
29213
|
+
chunk5MZFQRDW_cjs.emailPlugin({
|
|
28818
29214
|
type: "SMTP",
|
|
28819
29215
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
28820
29216
|
to: config.SMTP_TO ?? ""
|
|
@@ -28948,7 +29344,7 @@ function createCmsApiHandler(config) {
|
|
|
28948
29344
|
} : void 0;
|
|
28949
29345
|
const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
|
|
28950
29346
|
if (getCms) {
|
|
28951
|
-
|
|
29347
|
+
chunk5MZFQRDW_cjs.initWhatsappTriggerDispatcher({
|
|
28952
29348
|
dataSource,
|
|
28953
29349
|
entityMap,
|
|
28954
29350
|
getCms
|
|
@@ -28961,7 +29357,7 @@ function createCmsApiHandler(config) {
|
|
|
28961
29357
|
] : baseCrudResources;
|
|
28962
29358
|
const requireEntityPermissionEffective = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async (_req, entity, action) => {
|
|
28963
29359
|
if (!resolveSessionUser) {
|
|
28964
|
-
|
|
29360
|
+
chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
|
|
28965
29361
|
entity,
|
|
28966
29362
|
action,
|
|
28967
29363
|
hint: "Pass getSessionUser: auth.getAuthenticatedUser from createCmsAuthBundle()"
|
|
@@ -28971,7 +29367,7 @@ function createCmsApiHandler(config) {
|
|
|
28971
29367
|
const raw = await resolveSessionUser();
|
|
28972
29368
|
const u = await hydrateVendorSessionUser(dataSource, raw);
|
|
28973
29369
|
if (!u?.email) {
|
|
28974
|
-
|
|
29370
|
+
chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: no session user", {
|
|
28975
29371
|
entity,
|
|
28976
29372
|
action
|
|
28977
29373
|
});
|
|
@@ -28981,13 +29377,13 @@ function createCmsApiHandler(config) {
|
|
|
28981
29377
|
status: 401
|
|
28982
29378
|
});
|
|
28983
29379
|
}
|
|
28984
|
-
const allowed =
|
|
28985
|
-
await
|
|
29380
|
+
const allowed = chunkOV5TRZET_cjs.sessionHasEntityAccess(u, entity, action);
|
|
29381
|
+
await chunkO4AFPDQ4_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
|
|
28986
29382
|
allowed,
|
|
28987
29383
|
resolvePath: "hydrated_session"
|
|
28988
29384
|
});
|
|
28989
29385
|
if (allowed) return null;
|
|
28990
|
-
const { reason } =
|
|
29386
|
+
const { reason } = chunkO4AFPDQ4_cjs.explainSessionEntityAccess(u, entity, action);
|
|
28991
29387
|
return config.json({
|
|
28992
29388
|
error: "Forbidden",
|
|
28993
29389
|
entity,
|
|
@@ -28998,7 +29394,7 @@ function createCmsApiHandler(config) {
|
|
|
28998
29394
|
});
|
|
28999
29395
|
}
|
|
29000
29396
|
if (userRequireEntityPermission) {
|
|
29001
|
-
|
|
29397
|
+
chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
|
|
29002
29398
|
entity,
|
|
29003
29399
|
action
|
|
29004
29400
|
});
|
|
@@ -29085,10 +29481,10 @@ function createCmsApiHandler(config) {
|
|
|
29085
29481
|
getVendorScope: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
|
|
29086
29482
|
const multiVendorEnabled = await checkMultiVendorEnabled(dataSource);
|
|
29087
29483
|
if (!multiVendorEnabled) {
|
|
29088
|
-
return
|
|
29484
|
+
return chunkO4AFPDQ4_cjs.resolveDisabledMultiVendorScope(dataSource);
|
|
29089
29485
|
}
|
|
29090
29486
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
29091
|
-
return
|
|
29487
|
+
return chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
29092
29488
|
}, "getVendorScope"),
|
|
29093
29489
|
getHydratedSessionUser: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
|
|
29094
29490
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
@@ -29244,6 +29640,13 @@ function createCmsApiHandler(config) {
|
|
|
29244
29640
|
requireAuth: config.requireAuth,
|
|
29245
29641
|
requireEntityPermission: requireEntityPermissionEffective
|
|
29246
29642
|
});
|
|
29643
|
+
const mobileMessageTemplatesHandlers = createMobileMessageTemplatesHandlers({
|
|
29644
|
+
dataSource,
|
|
29645
|
+
entityMap,
|
|
29646
|
+
json: config.json,
|
|
29647
|
+
requireAuth: config.requireAuth,
|
|
29648
|
+
requireEntityPermission: requireEntityPermissionEffective
|
|
29649
|
+
});
|
|
29247
29650
|
const deviceTokensHandlers = createDeviceTokensHandlers({
|
|
29248
29651
|
dataSource,
|
|
29249
29652
|
entityMap,
|
|
@@ -30278,9 +30681,16 @@ function createCmsApiHandler(config) {
|
|
|
30278
30681
|
if (m === "GET") return emailMessageTemplatesHandlers.listCached(req);
|
|
30279
30682
|
if (m === "POST") return emailMessageTemplatesHandlers.create(req);
|
|
30280
30683
|
}
|
|
30281
|
-
if (isMsgTemplatesRoute &&
|
|
30684
|
+
if (isMsgTemplatesRoute && path2[1] === "mobile" && path2.length === 2) {
|
|
30685
|
+
if (m === "GET") return mobileMessageTemplatesHandlers.listCached(req);
|
|
30686
|
+
if (m === "POST") return mobileMessageTemplatesHandlers.create(req);
|
|
30687
|
+
}
|
|
30688
|
+
if (isMsgTemplatesRoute && (path2[1] === "email" || path2.length === 2) && path2.length === 3 && path2[1] !== "mobile") {
|
|
30282
30689
|
if (m === "PATCH") return emailMessageTemplatesHandlers.update(req, path2[2]);
|
|
30283
30690
|
}
|
|
30691
|
+
if (isMsgTemplatesRoute && path2[1] === "mobile" && path2.length === 3) {
|
|
30692
|
+
if (m === "PATCH") return mobileMessageTemplatesHandlers.update(req, path2[2]);
|
|
30693
|
+
}
|
|
30284
30694
|
if (path2[0] === "llm_agents") {
|
|
30285
30695
|
if (!entityMap.llm_agents) {
|
|
30286
30696
|
console.error(CMS_API_LOG, "llm_agents route: entity missing after merge", {
|
|
@@ -30422,7 +30832,7 @@ function createCmsApiHandler(config) {
|
|
|
30422
30832
|
let vendorId = null;
|
|
30423
30833
|
if (resolveSessionUser) {
|
|
30424
30834
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
30425
|
-
const scope =
|
|
30835
|
+
const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
30426
30836
|
if (scope.type === "vendor") vendorId = scope.vendorId;
|
|
30427
30837
|
}
|
|
30428
30838
|
const result = await validateCoupon(dataSource, entityMap, couponCode, orderLinesNorm, currency, contactId, isAutomatic, discountId ?? void 0, vendorId);
|
|
@@ -30510,7 +30920,7 @@ function createCmsApiHandler(config) {
|
|
|
30510
30920
|
let vendorId = null;
|
|
30511
30921
|
if (resolveSessionUser) {
|
|
30512
30922
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
30513
|
-
const scope =
|
|
30923
|
+
const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
30514
30924
|
if (scope.type === "vendor") vendorId = scope.vendorId;
|
|
30515
30925
|
}
|
|
30516
30926
|
const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
|
|
@@ -30723,7 +31133,7 @@ function createCmsApiHandler(config) {
|
|
|
30723
31133
|
status: 400
|
|
30724
31134
|
});
|
|
30725
31135
|
}
|
|
30726
|
-
const { resendOrderNotification } = await import('./order-notification-dispatcher-
|
|
31136
|
+
const { resendOrderNotification } = await import('./order-notification-dispatcher-LL7ETKLU.cjs');
|
|
30727
31137
|
const result = await resendOrderNotification(triggerKey, orderId, {
|
|
30728
31138
|
dataSource,
|
|
30729
31139
|
entityMap,
|
|
@@ -30822,7 +31232,7 @@ function createCmsApiHandler(config) {
|
|
|
30822
31232
|
status: "cancelled"
|
|
30823
31233
|
});
|
|
30824
31234
|
const fireOrderCancelledNotification = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((refundAmount) => {
|
|
30825
|
-
void import('./emit-order-notification-trigger-
|
|
31235
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
30826
31236
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
30827
31237
|
dataSource,
|
|
30828
31238
|
entityMap
|
|
@@ -31067,8 +31477,8 @@ function createCmsApiHandler(config) {
|
|
|
31067
31477
|
}, {
|
|
31068
31478
|
status: 400
|
|
31069
31479
|
});
|
|
31070
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31071
|
-
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);
|
|
31072
31482
|
return handlers.getChannels(req, orderId);
|
|
31073
31483
|
}
|
|
31074
31484
|
if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "send" && m === "POST" && getCms) {
|
|
@@ -31082,8 +31492,8 @@ function createCmsApiHandler(config) {
|
|
|
31082
31492
|
}, {
|
|
31083
31493
|
status: 400
|
|
31084
31494
|
});
|
|
31085
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31086
|
-
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);
|
|
31087
31497
|
return handlers.sendOtp(req, orderId);
|
|
31088
31498
|
}
|
|
31089
31499
|
if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "verify" && m === "POST" && getCms) {
|
|
@@ -31097,8 +31507,8 @@ function createCmsApiHandler(config) {
|
|
|
31097
31507
|
}, {
|
|
31098
31508
|
status: 400
|
|
31099
31509
|
});
|
|
31100
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31101
|
-
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);
|
|
31102
31512
|
return handlers.verifyOtp(req, orderId);
|
|
31103
31513
|
}
|
|
31104
31514
|
if (path2[0] === "orders" && path2.length === 3 && path2[2] === "eligible-assignees" && m === "GET") {
|
|
@@ -31112,7 +31522,7 @@ function createCmsApiHandler(config) {
|
|
|
31112
31522
|
}, {
|
|
31113
31523
|
status: 400
|
|
31114
31524
|
});
|
|
31115
|
-
const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-
|
|
31525
|
+
const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-KF7RMTV5.cjs');
|
|
31116
31526
|
const handlers = createOrderAssigneesHandlers(dataSource, entityMap, getHydratedSessionUser);
|
|
31117
31527
|
return handlers.listEligibleAssignees(req, orderId);
|
|
31118
31528
|
}
|
|
@@ -31222,7 +31632,7 @@ function createCmsApiHandler(config) {
|
|
|
31222
31632
|
if (resolveSessionUser) {
|
|
31223
31633
|
const raw = await resolveSessionUser();
|
|
31224
31634
|
const u = await hydrateVendorSessionUser(dataSource, raw);
|
|
31225
|
-
const scope =
|
|
31635
|
+
const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
31226
31636
|
if (scope.type === "vendor") {
|
|
31227
31637
|
scopedVendorIds = scope.vendorIds;
|
|
31228
31638
|
}
|
|
@@ -31728,32 +32138,17 @@ function createStorefrontApiHandler(config) {
|
|
|
31728
32138
|
const otpFlags = config.otpFlags;
|
|
31729
32139
|
const otpPepper = config.otpPepper;
|
|
31730
32140
|
const defaultPhoneCc = config.defaultPhoneCountryCode;
|
|
31731
|
-
function
|
|
31732
|
-
void import('./emit-order-notification-trigger-
|
|
31733
|
-
fireOrderNotificationTrigger("
|
|
32141
|
+
function fireStorefrontCheckoutNotifications(orderId) {
|
|
32142
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
32143
|
+
fireOrderNotificationTrigger("order_pending", orderId, {
|
|
31734
32144
|
dataSource,
|
|
31735
32145
|
entityMap
|
|
31736
32146
|
}, {
|
|
31737
32147
|
source: "storefront"
|
|
31738
32148
|
});
|
|
31739
|
-
if (isPaid) {
|
|
31740
|
-
fireOrderNotificationTrigger("payment_success", orderId, {
|
|
31741
|
-
dataSource,
|
|
31742
|
-
entityMap
|
|
31743
|
-
}, {
|
|
31744
|
-
source: "storefront"
|
|
31745
|
-
});
|
|
31746
|
-
} else {
|
|
31747
|
-
fireOrderNotificationTrigger("payment_failed", orderId, {
|
|
31748
|
-
dataSource,
|
|
31749
|
-
entityMap
|
|
31750
|
-
}, {
|
|
31751
|
-
source: "storefront"
|
|
31752
|
-
});
|
|
31753
|
-
}
|
|
31754
32149
|
}).catch((err) => console.error("[notification-triggers] import failed", err));
|
|
31755
32150
|
}
|
|
31756
|
-
chunkUSNT2KNT_cjs.__name(
|
|
32151
|
+
chunkUSNT2KNT_cjs.__name(fireStorefrontCheckoutNotifications, "fireStorefrontCheckoutNotifications");
|
|
31757
32152
|
const otpAllowPhoneLogin = config.otpAllowPhoneLogin !== false;
|
|
31758
32153
|
function otpOff(key) {
|
|
31759
32154
|
return !otpFlags || otpFlags[key] !== true;
|
|
@@ -33626,10 +34021,10 @@ function createStorefrontApiHandler(config) {
|
|
|
33626
34021
|
adminAccess: false
|
|
33627
34022
|
}));
|
|
33628
34023
|
const userId = newUser.id;
|
|
33629
|
-
await
|
|
34024
|
+
await chunkOV5TRZET_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
|
|
33630
34025
|
if (entityMap.customer) {
|
|
33631
34026
|
const phone = typeof b.phone === "string" && b.phone.trim() ? String(b.phone).trim() : null;
|
|
33632
|
-
await
|
|
34027
|
+
await chunkOV5TRZET_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
|
|
33633
34028
|
id: userId,
|
|
33634
34029
|
name,
|
|
33635
34030
|
email,
|
|
@@ -34250,6 +34645,7 @@ function createStorefrontApiHandler(config) {
|
|
|
34250
34645
|
}));
|
|
34251
34646
|
}
|
|
34252
34647
|
await linkOrderContactToVendors(contactId, vendorRes.vendorIds);
|
|
34648
|
+
fireStorefrontCheckoutNotifications(oid);
|
|
34253
34649
|
return json({
|
|
34254
34650
|
orderId: oid,
|
|
34255
34651
|
orderNumber: ord.orderNumber,
|
|
@@ -34330,6 +34726,7 @@ function createStorefrontApiHandler(config) {
|
|
|
34330
34726
|
cartId: cart.id
|
|
34331
34727
|
});
|
|
34332
34728
|
await cartRepo().delete(cart.id);
|
|
34729
|
+
fireStorefrontCheckoutNotifications(oid);
|
|
34333
34730
|
return json({
|
|
34334
34731
|
orderId: oid,
|
|
34335
34732
|
orderNumber: ord.orderNumber,
|
|
@@ -34672,7 +35069,7 @@ function createStorefrontApiHandler(config) {
|
|
|
34672
35069
|
} catch {
|
|
34673
35070
|
}
|
|
34674
35071
|
try {
|
|
34675
|
-
void import('./emit-order-notification-trigger-
|
|
35072
|
+
void import('./emit-order-notification-trigger-ZD5YN3JM.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
34676
35073
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
34677
35074
|
dataSource,
|
|
34678
35075
|
entityMap
|