@infuro/cms-core 1.0.66 → 1.0.68
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 +214 -32
- package/dist/admin.js +214 -32
- package/dist/api.cjs +45 -42
- package/dist/api.js +12 -9
- package/dist/auth.cjs +51 -51
- package/dist/auth.js +3 -3
- package/dist/{chunk-QYRXLURF.cjs → chunk-22XKONB5.cjs} +640 -145
- package/dist/{chunk-MVHDC3XF.js → chunk-5NOZSG6J.js} +22 -11
- package/dist/{chunk-TU23GJPJ.js → chunk-7JCCPQEF.js} +1 -1
- package/dist/{chunk-WMMZZRDJ.cjs → chunk-GN4LKG4V.cjs} +1 -1
- package/dist/{chunk-KM2I6AFP.cjs → chunk-HBUV73RB.cjs} +9 -9
- package/dist/chunk-IKTBZJHT.js +16 -0
- package/dist/chunk-M5GPOPGX.cjs +49 -0
- package/dist/{chunk-T33KU5G5.js → chunk-MYUGQHU4.js} +548 -53
- package/dist/{chunk-NV5IRHI3.js → chunk-N4LBZXBG.js} +2 -2
- package/dist/{chunk-J7FMZK66.cjs → chunk-O4AFPDQ4.cjs} +22 -11
- package/dist/{chunk-4U6DATGZ.cjs → chunk-OV5TRZET.cjs} +7 -7
- package/dist/chunk-P6S4XFZO.cjs +18 -0
- package/dist/{chunk-RCE5SJBA.js → chunk-SKJH7PX4.js} +1 -1
- package/dist/{chunk-5MZFQRDW.cjs → chunk-SMHQV3WL.cjs} +4 -4
- package/dist/chunk-SUUD7OUG.cjs +455 -0
- package/dist/{chunk-XFDIIVZB.cjs → chunk-UMC7W5G3.cjs} +3 -3
- package/dist/chunk-WKDBMDUX.js +45 -0
- package/dist/{chunk-6DBDJ4VD.js → chunk-Z5G54EGD.js} +2 -2
- package/dist/chunk-Z5OB5QGN.js +465 -0
- package/dist/chunk-ZIT4IP6N.js +445 -0
- package/dist/chunk-ZX5U3VCB.cjs +471 -0
- package/dist/{chunk-NR44CK5E.js → chunk-ZY64VJMS.js} +1 -1
- package/dist/email-queue-3QBQ63F7.js +8 -0
- package/dist/{email-queue-4OY45JIU.cjs → email-queue-K4E4OFI7.cjs} +9 -6
- package/dist/{emit-order-notification-trigger-ZD5YN3JM.cjs → emit-order-notification-trigger-ROASTYQP.cjs} +3 -3
- package/dist/{emit-order-notification-trigger-EJJZ6XTS.js → emit-order-notification-trigger-YUQTPELC.js} +1 -1
- package/dist/{erp-order-invoice-YUSPZ7CE.cjs → erp-order-invoice-AZ5MX2JB.cjs} +8 -5
- package/dist/{erp-order-invoice-H6HCJ7YS.js → erp-order-invoice-XSYHAMBS.js} +4 -1
- package/dist/generate-local-invoice-pdf-BQTCL5MW.cjs +12 -0
- package/dist/generate-local-invoice-pdf-OCFG47SE.js +3 -0
- package/dist/index.cjs +337 -330
- package/dist/index.d.cts +21 -2
- package/dist/index.d.ts +21 -2
- package/dist/index.js +18 -15
- package/dist/invoice-templates-GZ33OENC.js +2 -0
- package/dist/invoice-templates-RB462AQN.cjs +19 -0
- 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-NK65LOLV.cjs → order-completion-otp-handlers-DDQREULW.cjs} +75 -18
- package/dist/{order-completion-otp-handlers-LFRHXWK4.js → order-completion-otp-handlers-NROWBGXN.js} +73 -16
- package/dist/{order-notification-dispatcher-LL7ETKLU.cjs → order-notification-dispatcher-6HCJ6Q75.cjs} +12 -9
- package/dist/{order-notification-dispatcher-ECPFI7CD.js → order-notification-dispatcher-KM2SY7TX.js} +7 -4
- 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/dist/resolve-invoice-asset-url-JEZRENJW.cjs +11 -0
- package/dist/resolve-invoice-asset-url-QZ2FRDHI.js +2 -0
- package/package.json +1 -1
- package/dist/chunk-GLD263KW.cjs +0 -862
- package/dist/chunk-OPJEV44S.js +0 -847
- package/dist/email-queue-HGXB2FIS.js +0 -5
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk7NMT3GBR_cjs = require('./chunk-7NMT3GBR.cjs');
|
|
3
4
|
var chunkWFMVD567_cjs = require('./chunk-WFMVD567.cjs');
|
|
5
|
+
var chunkTJ2MIQUT_cjs = require('./chunk-TJ2MIQUT.cjs');
|
|
4
6
|
var chunkTHL5JDWJ_cjs = require('./chunk-THL5JDWJ.cjs');
|
|
5
7
|
var chunkHY3AXLOI_cjs = require('./chunk-HY3AXLOI.cjs');
|
|
6
|
-
var
|
|
8
|
+
var chunkSMHQV3WL_cjs = require('./chunk-SMHQV3WL.cjs');
|
|
7
9
|
var chunkH3IVLIPR_cjs = require('./chunk-H3IVLIPR.cjs');
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var chunkGLD263KW_cjs = require('./chunk-GLD263KW.cjs');
|
|
10
|
+
var chunkUMC7W5G3_cjs = require('./chunk-UMC7W5G3.cjs');
|
|
11
|
+
var chunkSUUD7OUG_cjs = require('./chunk-SUUD7OUG.cjs');
|
|
11
12
|
var chunkUPLVMVRX_cjs = require('./chunk-UPLVMVRX.cjs');
|
|
12
13
|
var chunkTZEMLHSP_cjs = require('./chunk-TZEMLHSP.cjs');
|
|
13
14
|
var chunk3DZRIZOD_cjs = require('./chunk-3DZRIZOD.cjs');
|
|
14
|
-
var
|
|
15
|
-
var
|
|
15
|
+
var chunkOV5TRZET_cjs = require('./chunk-OV5TRZET.cjs');
|
|
16
|
+
var chunkO4AFPDQ4_cjs = require('./chunk-O4AFPDQ4.cjs');
|
|
16
17
|
var chunkOY2YTBMP_cjs = require('./chunk-OY2YTBMP.cjs');
|
|
17
|
-
var chunkJ7FMZK66_cjs = require('./chunk-J7FMZK66.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-ROASTYQP.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-ROASTYQP.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-ROASTYQP.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-ROASTYQP.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-ROASTYQP.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-ROASTYQP.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-ROASTYQP.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-ROASTYQP.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
|
}, {
|
|
@@ -10275,7 +10536,7 @@ function createFormSubmissionHandler(config) {
|
|
|
10275
10536
|
label: f.label && String(f.label).trim() || `Field ${f.id}`,
|
|
10276
10537
|
value: formatSubmissionFieldValue(data[String(f.id)])
|
|
10277
10538
|
}));
|
|
10278
|
-
await
|
|
10539
|
+
await chunkUMC7W5G3_cjs.queueEmail(cms, {
|
|
10279
10540
|
to,
|
|
10280
10541
|
templateName: "formSubmission",
|
|
10281
10542
|
ctx: {
|
|
@@ -10329,7 +10590,7 @@ function createUsersApiHandlers(config) {
|
|
|
10329
10590
|
try {
|
|
10330
10591
|
const cms = await getCms();
|
|
10331
10592
|
const companyDetails = getCompanyDetails ? await getCompanyDetails() : {};
|
|
10332
|
-
await
|
|
10593
|
+
await chunkUMC7W5G3_cjs.queueEmail(cms, {
|
|
10333
10594
|
to: toEmail,
|
|
10334
10595
|
templateName: "invite",
|
|
10335
10596
|
ctx: {
|
|
@@ -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 = chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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 chunkSMHQV3WL_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(chunkSMHQV3WL_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 = chunkSMHQV3WL_cjs.parseIntentRecipientEmails(intent.emailTo);
|
|
11953
|
+
console.info(chunkSMHQV3WL_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 chunkSMHQV3WL_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: chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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(chunkSMHQV3WL_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 = chunkSMHQV3WL_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 = chunkSMHQV3WL_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 chunkSMHQV3WL_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 chunkSMHQV3WL_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 = chunkSMHQV3WL_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;
|
|
@@ -14047,7 +14308,7 @@ async function sendVendorOnboardEmails(input, deps) {
|
|
|
14047
14308
|
];
|
|
14048
14309
|
const notifyEmails = Array.from(new Set(combined.map((e) => e.trim().toLowerCase()).filter((e) => e && e !== ownerEmailLower && !vendorEmailSet.has(e))));
|
|
14049
14310
|
const cms = await deps.getCms();
|
|
14050
|
-
await
|
|
14311
|
+
await chunkUMC7W5G3_cjs.queueVendorOnboardEmails(cms, {
|
|
14051
14312
|
vendorName: input.vendorName,
|
|
14052
14313
|
vendorSlug: input.vendorSlug,
|
|
14053
14314
|
ownerName: input.ownerName,
|
|
@@ -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,
|
|
@@ -15291,6 +15552,7 @@ function createVendorOnboardHandlers(config) {
|
|
|
15291
15552
|
state: vp?.state ?? null,
|
|
15292
15553
|
postalCode: vp?.postalCode ?? null,
|
|
15293
15554
|
blocked: u?.blocked ?? false,
|
|
15555
|
+
inviteStatus: u?.inviteStatus ?? (u?.password ? "active" : "pending"),
|
|
15294
15556
|
groupName: u?.group?.name ?? null
|
|
15295
15557
|
};
|
|
15296
15558
|
});
|
|
@@ -15494,7 +15756,7 @@ function createVendorOnboardHandlers(config) {
|
|
|
15494
15756
|
if (!groupId) {
|
|
15495
15757
|
const g = await groupRepo.findOne({
|
|
15496
15758
|
where: {
|
|
15497
|
-
name:
|
|
15759
|
+
name: chunkO4AFPDQ4_cjs.VENDOR_GROUP_NAME,
|
|
15498
15760
|
deleted: false
|
|
15499
15761
|
}
|
|
15500
15762
|
}) ?? await groupRepo.findOne({
|
|
@@ -15594,7 +15856,7 @@ function createVendorOnboardHandlers(config) {
|
|
|
15594
15856
|
}
|
|
15595
15857
|
if (entityMap.customer) {
|
|
15596
15858
|
try {
|
|
15597
|
-
await
|
|
15859
|
+
await chunkOV5TRZET_cjs.ensureCustomerForUser(em, entityMap.customer, {
|
|
15598
15860
|
id: newUser.id,
|
|
15599
15861
|
name: userName,
|
|
15600
15862
|
email: userEmail,
|
|
@@ -15764,14 +16026,24 @@ function createVendorOnboardHandlers(config) {
|
|
|
15764
16026
|
});
|
|
15765
16027
|
}
|
|
15766
16028
|
}
|
|
15767
|
-
const
|
|
15768
|
-
|
|
16029
|
+
const hasPassword = !!(user.password && String(user.password).trim());
|
|
16030
|
+
const isPending = user.inviteStatus === "pending" || !hasPassword;
|
|
16031
|
+
if (!isPending) {
|
|
15769
16032
|
return json({
|
|
15770
|
-
error: "
|
|
16033
|
+
error: "User has already accepted the invite"
|
|
15771
16034
|
}, {
|
|
15772
16035
|
status: 400
|
|
15773
16036
|
});
|
|
15774
16037
|
}
|
|
16038
|
+
let token = String(user.inviteToken ?? "").trim();
|
|
16039
|
+
if (!token) {
|
|
16040
|
+
token = newUserInviteToken();
|
|
16041
|
+
await dataSource.getRepository(entityMap.users).update(user.id, {
|
|
16042
|
+
inviteToken: token,
|
|
16043
|
+
inviteStatus: "pending",
|
|
16044
|
+
password: null
|
|
16045
|
+
});
|
|
16046
|
+
}
|
|
15775
16047
|
const inviteLink = buildUserInviteLink(baseUrl, token);
|
|
15776
16048
|
const emailSent = await trySendVendorOnboardEmails({
|
|
15777
16049
|
vendorName,
|
|
@@ -16131,10 +16403,10 @@ chunkUSNT2KNT_cjs.__name(createVendorOnboardHandlers, "createVendorOnboardHandle
|
|
|
16131
16403
|
function createVendorRolesHandlers(config) {
|
|
16132
16404
|
const { dataSource, entityMap, json, getSessionUser } = config;
|
|
16133
16405
|
const vendorRoleEntities = [
|
|
16134
|
-
...
|
|
16406
|
+
...chunkO4AFPDQ4_cjs.VENDOR_RBAC_ENTITIES
|
|
16135
16407
|
].sort();
|
|
16136
16408
|
async function resolveActiveVendorId(u) {
|
|
16137
|
-
const scope =
|
|
16409
|
+
const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u);
|
|
16138
16410
|
if (scope.type === "vendor") return scope.vendorId;
|
|
16139
16411
|
if (scope.type === "all") {
|
|
16140
16412
|
const id = u.activeVendorId ?? u.vendorIds?.[0];
|
|
@@ -16150,7 +16422,7 @@ function createVendorRolesHandlers(config) {
|
|
|
16150
16422
|
}, {
|
|
16151
16423
|
status: 401
|
|
16152
16424
|
});
|
|
16153
|
-
if (!
|
|
16425
|
+
if (!chunkO4AFPDQ4_cjs.canManageVendorRoles(u)) return json({
|
|
16154
16426
|
error: "Forbidden"
|
|
16155
16427
|
}, {
|
|
16156
16428
|
status: 403
|
|
@@ -25145,6 +25417,109 @@ _ts_decorate69([
|
|
|
25145
25417
|
exports.OrderNotificationTrigger = _ts_decorate69([
|
|
25146
25418
|
typeorm.Entity("order_notification_triggers")
|
|
25147
25419
|
], exports.OrderNotificationTrigger);
|
|
25420
|
+
function _ts_decorate70(decorators, target, key, desc) {
|
|
25421
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
25422
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25423
|
+
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;
|
|
25424
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
25425
|
+
}
|
|
25426
|
+
chunkUSNT2KNT_cjs.__name(_ts_decorate70, "_ts_decorate");
|
|
25427
|
+
function _ts_metadata70(k, v) {
|
|
25428
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25429
|
+
}
|
|
25430
|
+
chunkUSNT2KNT_cjs.__name(_ts_metadata70, "_ts_metadata");
|
|
25431
|
+
exports.OrderAssignee = class OrderAssignee {
|
|
25432
|
+
static {
|
|
25433
|
+
chunkUSNT2KNT_cjs.__name(this, "OrderAssignee");
|
|
25434
|
+
}
|
|
25435
|
+
id;
|
|
25436
|
+
orderId;
|
|
25437
|
+
userId;
|
|
25438
|
+
vendorId;
|
|
25439
|
+
sortOrder;
|
|
25440
|
+
assignedAt;
|
|
25441
|
+
createdAt;
|
|
25442
|
+
order;
|
|
25443
|
+
user;
|
|
25444
|
+
vendor;
|
|
25445
|
+
};
|
|
25446
|
+
_ts_decorate70([
|
|
25447
|
+
typeorm.PrimaryGeneratedColumn(),
|
|
25448
|
+
_ts_metadata70("design:type", Number)
|
|
25449
|
+
], exports.OrderAssignee.prototype, "id", void 0);
|
|
25450
|
+
_ts_decorate70([
|
|
25451
|
+
typeorm.Column("int"),
|
|
25452
|
+
_ts_metadata70("design:type", Number)
|
|
25453
|
+
], exports.OrderAssignee.prototype, "orderId", void 0);
|
|
25454
|
+
_ts_decorate70([
|
|
25455
|
+
typeorm.Column("int"),
|
|
25456
|
+
_ts_metadata70("design:type", Number)
|
|
25457
|
+
], exports.OrderAssignee.prototype, "userId", void 0);
|
|
25458
|
+
_ts_decorate70([
|
|
25459
|
+
typeorm.Column("int", {
|
|
25460
|
+
nullable: true
|
|
25461
|
+
}),
|
|
25462
|
+
_ts_metadata70("design:type", Object)
|
|
25463
|
+
], exports.OrderAssignee.prototype, "vendorId", void 0);
|
|
25464
|
+
_ts_decorate70([
|
|
25465
|
+
typeorm.Column("int", {
|
|
25466
|
+
default: 1
|
|
25467
|
+
}),
|
|
25468
|
+
_ts_metadata70("design:type", Number)
|
|
25469
|
+
], exports.OrderAssignee.prototype, "sortOrder", void 0);
|
|
25470
|
+
_ts_decorate70([
|
|
25471
|
+
typeorm.Column({
|
|
25472
|
+
type: "timestamp with time zone",
|
|
25473
|
+
default: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(() => "CURRENT_TIMESTAMP", "default")
|
|
25474
|
+
}),
|
|
25475
|
+
_ts_metadata70("design:type", typeof Date === "undefined" ? Object : Date)
|
|
25476
|
+
], exports.OrderAssignee.prototype, "assignedAt", void 0);
|
|
25477
|
+
_ts_decorate70([
|
|
25478
|
+
typeorm.CreateDateColumn({
|
|
25479
|
+
type: "timestamp with time zone"
|
|
25480
|
+
}),
|
|
25481
|
+
_ts_metadata70("design:type", typeof Date === "undefined" ? Object : Date)
|
|
25482
|
+
], exports.OrderAssignee.prototype, "createdAt", void 0);
|
|
25483
|
+
_ts_decorate70([
|
|
25484
|
+
typeorm.ManyToOne(() => exports.Order, {
|
|
25485
|
+
onDelete: "CASCADE"
|
|
25486
|
+
}),
|
|
25487
|
+
typeorm.JoinColumn({
|
|
25488
|
+
name: "orderId"
|
|
25489
|
+
}),
|
|
25490
|
+
_ts_metadata70("design:type", typeof exports.Order === "undefined" ? Object : exports.Order)
|
|
25491
|
+
], exports.OrderAssignee.prototype, "order", void 0);
|
|
25492
|
+
_ts_decorate70([
|
|
25493
|
+
typeorm.ManyToOne(() => exports.User, {
|
|
25494
|
+
onDelete: "CASCADE"
|
|
25495
|
+
}),
|
|
25496
|
+
typeorm.JoinColumn({
|
|
25497
|
+
name: "userId"
|
|
25498
|
+
}),
|
|
25499
|
+
_ts_metadata70("design:type", typeof exports.User === "undefined" ? Object : exports.User)
|
|
25500
|
+
], exports.OrderAssignee.prototype, "user", void 0);
|
|
25501
|
+
_ts_decorate70([
|
|
25502
|
+
typeorm.ManyToOne(() => exports.Vendor, {
|
|
25503
|
+
nullable: true,
|
|
25504
|
+
onDelete: "SET NULL"
|
|
25505
|
+
}),
|
|
25506
|
+
typeorm.JoinColumn({
|
|
25507
|
+
name: "vendorId"
|
|
25508
|
+
}),
|
|
25509
|
+
_ts_metadata70("design:type", Object)
|
|
25510
|
+
], exports.OrderAssignee.prototype, "vendor", void 0);
|
|
25511
|
+
exports.OrderAssignee = _ts_decorate70([
|
|
25512
|
+
typeorm.Entity("order_assignees"),
|
|
25513
|
+
typeorm.Index("idx_order_assignees_order", [
|
|
25514
|
+
"orderId"
|
|
25515
|
+
]),
|
|
25516
|
+
typeorm.Index("idx_order_assignees_user", [
|
|
25517
|
+
"userId"
|
|
25518
|
+
]),
|
|
25519
|
+
typeorm.Index("idx_order_assignees_vendor", [
|
|
25520
|
+
"vendorId"
|
|
25521
|
+
])
|
|
25522
|
+
], exports.OrderAssignee);
|
|
25148
25523
|
|
|
25149
25524
|
// src/entities/index.ts
|
|
25150
25525
|
var CMS_ENTITY_MAP = {
|
|
@@ -25216,7 +25591,8 @@ var CMS_ENTITY_MAP = {
|
|
|
25216
25591
|
attendees: exports.Attendee,
|
|
25217
25592
|
order_notification_bindings: exports.OrderNotificationBinding,
|
|
25218
25593
|
order_notification_triggers: exports.OrderNotificationTrigger,
|
|
25219
|
-
user_device_tokens: exports.UserDeviceToken
|
|
25594
|
+
user_device_tokens: exports.UserDeviceToken,
|
|
25595
|
+
order_assignees: exports.OrderAssignee
|
|
25220
25596
|
};
|
|
25221
25597
|
|
|
25222
25598
|
// src/plugins/blog-generator/blog-generator-agent-defaults.ts
|
|
@@ -28694,11 +29070,11 @@ function whatsappPlugin(config = {}) {
|
|
|
28694
29070
|
db = await settingsLoader?.() ?? {};
|
|
28695
29071
|
} catch {
|
|
28696
29072
|
}
|
|
28697
|
-
if (!
|
|
29073
|
+
if (!chunkSMHQV3WL_cjs.isWhatsAppPluginEnabled(db)) {
|
|
28698
29074
|
context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
|
|
28699
29075
|
return null;
|
|
28700
29076
|
}
|
|
28701
|
-
const svc = new
|
|
29077
|
+
const svc = new chunkSMHQV3WL_cjs.WhatsAppService(env, staticRest, settingsLoader, getMessageTemplateRow);
|
|
28702
29078
|
return {
|
|
28703
29079
|
send: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((opts) => svc.send(opts), "send")
|
|
28704
29080
|
};
|
|
@@ -28771,7 +29147,7 @@ function createMessageTemplateRowLoader(dataSource, entityMap) {
|
|
|
28771
29147
|
}
|
|
28772
29148
|
chunkUSNT2KNT_cjs.__name(createMessageTemplateRowLoader, "createMessageTemplateRowLoader");
|
|
28773
29149
|
function registerMessagingQueueProcessors(cms, entityMap) {
|
|
28774
|
-
|
|
29150
|
+
chunkUMC7W5G3_cjs.registerEmailQueueProcessor(cms, {
|
|
28775
29151
|
getDataSource: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => cms.dataSource, "getDataSource"),
|
|
28776
29152
|
entityMap
|
|
28777
29153
|
});
|
|
@@ -28804,7 +29180,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
|
|
|
28804
29180
|
}
|
|
28805
29181
|
if (!cms.getPlugin("email")) {
|
|
28806
29182
|
try {
|
|
28807
|
-
const instance = await
|
|
29183
|
+
const instance = await chunkSMHQV3WL_cjs.emailPlugin({
|
|
28808
29184
|
type: "SMTP",
|
|
28809
29185
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
28810
29186
|
to: config.SMTP_TO ?? ""
|
|
@@ -28845,7 +29221,7 @@ function messagingPlugins(options) {
|
|
|
28845
29221
|
const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
|
|
28846
29222
|
return [
|
|
28847
29223
|
queuePlugin(),
|
|
28848
|
-
|
|
29224
|
+
chunkSMHQV3WL_cjs.emailPlugin({
|
|
28849
29225
|
type: "SMTP",
|
|
28850
29226
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
28851
29227
|
to: config.SMTP_TO ?? ""
|
|
@@ -28979,7 +29355,7 @@ function createCmsApiHandler(config) {
|
|
|
28979
29355
|
} : void 0;
|
|
28980
29356
|
const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
|
|
28981
29357
|
if (getCms) {
|
|
28982
|
-
|
|
29358
|
+
chunkSMHQV3WL_cjs.initWhatsappTriggerDispatcher({
|
|
28983
29359
|
dataSource,
|
|
28984
29360
|
entityMap,
|
|
28985
29361
|
getCms
|
|
@@ -28992,7 +29368,7 @@ function createCmsApiHandler(config) {
|
|
|
28992
29368
|
] : baseCrudResources;
|
|
28993
29369
|
const requireEntityPermissionEffective = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async (_req, entity, action) => {
|
|
28994
29370
|
if (!resolveSessionUser) {
|
|
28995
|
-
|
|
29371
|
+
chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
|
|
28996
29372
|
entity,
|
|
28997
29373
|
action,
|
|
28998
29374
|
hint: "Pass getSessionUser: auth.getAuthenticatedUser from createCmsAuthBundle()"
|
|
@@ -29002,7 +29378,7 @@ function createCmsApiHandler(config) {
|
|
|
29002
29378
|
const raw = await resolveSessionUser();
|
|
29003
29379
|
const u = await hydrateVendorSessionUser(dataSource, raw);
|
|
29004
29380
|
if (!u?.email) {
|
|
29005
|
-
|
|
29381
|
+
chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: no session user", {
|
|
29006
29382
|
entity,
|
|
29007
29383
|
action
|
|
29008
29384
|
});
|
|
@@ -29012,13 +29388,13 @@ function createCmsApiHandler(config) {
|
|
|
29012
29388
|
status: 401
|
|
29013
29389
|
});
|
|
29014
29390
|
}
|
|
29015
|
-
const allowed =
|
|
29016
|
-
await
|
|
29391
|
+
const allowed = chunkOV5TRZET_cjs.sessionHasEntityAccess(u, entity, action);
|
|
29392
|
+
await chunkO4AFPDQ4_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
|
|
29017
29393
|
allowed,
|
|
29018
29394
|
resolvePath: "hydrated_session"
|
|
29019
29395
|
});
|
|
29020
29396
|
if (allowed) return null;
|
|
29021
|
-
const { reason } =
|
|
29397
|
+
const { reason } = chunkO4AFPDQ4_cjs.explainSessionEntityAccess(u, entity, action);
|
|
29022
29398
|
return config.json({
|
|
29023
29399
|
error: "Forbidden",
|
|
29024
29400
|
entity,
|
|
@@ -29029,7 +29405,7 @@ function createCmsApiHandler(config) {
|
|
|
29029
29405
|
});
|
|
29030
29406
|
}
|
|
29031
29407
|
if (userRequireEntityPermission) {
|
|
29032
|
-
|
|
29408
|
+
chunkO4AFPDQ4_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
|
|
29033
29409
|
entity,
|
|
29034
29410
|
action
|
|
29035
29411
|
});
|
|
@@ -29072,7 +29448,7 @@ function createCmsApiHandler(config) {
|
|
|
29072
29448
|
companyDetails
|
|
29073
29449
|
};
|
|
29074
29450
|
if (queue) {
|
|
29075
|
-
const { queueEmail: queueEmail2 } = await import('./email-queue-
|
|
29451
|
+
const { queueEmail: queueEmail2 } = await import('./email-queue-K4E4OFI7.cjs');
|
|
29076
29452
|
await queueEmail2(cms, {
|
|
29077
29453
|
to: opts.to,
|
|
29078
29454
|
templateName: "passwordReset",
|
|
@@ -29116,10 +29492,10 @@ function createCmsApiHandler(config) {
|
|
|
29116
29492
|
getVendorScope: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
|
|
29117
29493
|
const multiVendorEnabled = await checkMultiVendorEnabled(dataSource);
|
|
29118
29494
|
if (!multiVendorEnabled) {
|
|
29119
|
-
return
|
|
29495
|
+
return chunkO4AFPDQ4_cjs.resolveDisabledMultiVendorScope(dataSource);
|
|
29120
29496
|
}
|
|
29121
29497
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
29122
|
-
return
|
|
29498
|
+
return chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
29123
29499
|
}, "getVendorScope"),
|
|
29124
29500
|
getHydratedSessionUser: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
|
|
29125
29501
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
@@ -30082,6 +30458,110 @@ function createCmsApiHandler(config) {
|
|
|
30082
30458
|
return socialMediaHandlers.publishBlogToFacebook(req, id);
|
|
30083
30459
|
}
|
|
30084
30460
|
}
|
|
30461
|
+
if (path2[0] === "settings" && path2.length === 2 && path2[1] === "invoice-preview" && m === "GET") {
|
|
30462
|
+
const a = await config.requireAuth(req);
|
|
30463
|
+
if (a) return a;
|
|
30464
|
+
const pe = await requireEntityPermissionEffective(req, "settings", "read");
|
|
30465
|
+
if (pe) return pe;
|
|
30466
|
+
const url = new URL(req.url);
|
|
30467
|
+
const templateParam = url.searchParams.get("template") || "classic";
|
|
30468
|
+
const qrParam = url.searchParams.get("qr");
|
|
30469
|
+
const configRepo = dataSource.getRepository(entityMap.configs);
|
|
30470
|
+
const rows = await configRepo.find({
|
|
30471
|
+
where: {
|
|
30472
|
+
settings: "store",
|
|
30473
|
+
deleted: false
|
|
30474
|
+
}
|
|
30475
|
+
});
|
|
30476
|
+
const storeMap = {};
|
|
30477
|
+
for (const r of rows) {
|
|
30478
|
+
storeMap[r.key] = r.value;
|
|
30479
|
+
}
|
|
30480
|
+
const { normalizeInvoiceTemplateId } = await import('./invoice-templates-RB462AQN.cjs');
|
|
30481
|
+
const { generateLocalInvoicePdf } = await import('./generate-local-invoice-pdf-BQTCL5MW.cjs');
|
|
30482
|
+
const { resolveInvoiceAssetUrl } = await import('./resolve-invoice-asset-url-JEZRENJW.cjs');
|
|
30483
|
+
const templateId = normalizeInvoiceTemplateId(templateParam);
|
|
30484
|
+
const includeQr = qrParam != null ? qrParam === "1" || qrParam === "true" : storeMap.invoice_include_qr === "true";
|
|
30485
|
+
const sampleInput = {
|
|
30486
|
+
templateId,
|
|
30487
|
+
orderNumber: "SAMPLE-10024",
|
|
30488
|
+
orderDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30489
|
+
currency: storeMap.currency || "INR",
|
|
30490
|
+
company: {
|
|
30491
|
+
name: storeMap.companyName || storeMap.invoiceCompanyName || "ETOE Services",
|
|
30492
|
+
supportEmail: storeMap.companyEmail || storeMap.invoiceEmail || "support@example.com",
|
|
30493
|
+
supportPhone: storeMap.companyPhone || storeMap.invoicePhone || "+91 98765 43210",
|
|
30494
|
+
address: storeMap.companyAddress || storeMap.invoiceAddress || "65 Sanjay Nagar B, Kalwar Road, Jhotwara, Jaipur, Rajasthan, 302012, India",
|
|
30495
|
+
logoUrl: resolveInvoiceAssetUrl(storeMap.invoiceLogoUrl || storeMap.companyLogo || storeMap.logo)
|
|
30496
|
+
},
|
|
30497
|
+
customerName: "Sahil Sharma",
|
|
30498
|
+
customerEmail: "sahil@example.com",
|
|
30499
|
+
customerPhone: "+91 98875 51178",
|
|
30500
|
+
billingAddress: {
|
|
30501
|
+
line1: "65 Sanjay Nagar B, Kalwar Road",
|
|
30502
|
+
city: "Jaipur",
|
|
30503
|
+
state: "Rajasthan",
|
|
30504
|
+
postalCode: "302012",
|
|
30505
|
+
country: "India"
|
|
30506
|
+
},
|
|
30507
|
+
shippingAddress: {
|
|
30508
|
+
line1: "65 Sanjay Nagar B, Kalwar Road",
|
|
30509
|
+
city: "Jaipur",
|
|
30510
|
+
state: "Rajasthan",
|
|
30511
|
+
postalCode: "302012",
|
|
30512
|
+
country: "India"
|
|
30513
|
+
},
|
|
30514
|
+
serviceDate: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30515
|
+
timeSlot: "6:00 PM",
|
|
30516
|
+
assignedTo: "Raaj Sharma",
|
|
30517
|
+
qrToken: "sample-track-token-12345",
|
|
30518
|
+
qrData: "https://etoe.in/track/sample-track-token-12345",
|
|
30519
|
+
includeQrCode: includeQr,
|
|
30520
|
+
lineItems: [
|
|
30521
|
+
{
|
|
30522
|
+
name: "Complete Home Deep Cleaning Service",
|
|
30523
|
+
sku: "ETOE-HDC-001",
|
|
30524
|
+
quantity: 1,
|
|
30525
|
+
unitPrice: 3499,
|
|
30526
|
+
tax: 0,
|
|
30527
|
+
total: 3499
|
|
30528
|
+
},
|
|
30529
|
+
{
|
|
30530
|
+
name: "Kitchen & Bathroom Sanitization Add-on",
|
|
30531
|
+
sku: "ETOE-SAN-002",
|
|
30532
|
+
quantity: 1,
|
|
30533
|
+
unitPrice: 999,
|
|
30534
|
+
tax: 0,
|
|
30535
|
+
total: 999
|
|
30536
|
+
}
|
|
30537
|
+
],
|
|
30538
|
+
subtotal: 4498,
|
|
30539
|
+
discount: 499,
|
|
30540
|
+
tax: 0,
|
|
30541
|
+
total: 3999
|
|
30542
|
+
};
|
|
30543
|
+
try {
|
|
30544
|
+
const bytes = await generateLocalInvoicePdf(sampleInput);
|
|
30545
|
+
return new Response(Buffer.from(bytes), {
|
|
30546
|
+
status: 200,
|
|
30547
|
+
headers: {
|
|
30548
|
+
"Content-Type": "application/pdf",
|
|
30549
|
+
"Content-Disposition": `inline; filename="preview-invoice-${templateId}.pdf"`
|
|
30550
|
+
}
|
|
30551
|
+
});
|
|
30552
|
+
} catch (err) {
|
|
30553
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
30554
|
+
console.error("[invoice-preview] failed", {
|
|
30555
|
+
templateId,
|
|
30556
|
+
error: msg
|
|
30557
|
+
});
|
|
30558
|
+
return config.json({
|
|
30559
|
+
error: `Preview generation failed: ${msg}`
|
|
30560
|
+
}, {
|
|
30561
|
+
status: 500
|
|
30562
|
+
});
|
|
30563
|
+
}
|
|
30564
|
+
}
|
|
30085
30565
|
if (path2[0] === "settings" && path2.length === 2 && settingsHandlers) {
|
|
30086
30566
|
const group = path2[1];
|
|
30087
30567
|
const isPublic = group === "multi_vendor" || group === "turnstile" || group === "auth_providers" || settingsConfig?.publicGetGroups?.includes(group);
|
|
@@ -30386,7 +30866,7 @@ function createCmsApiHandler(config) {
|
|
|
30386
30866
|
const pe = await requireEntityPermissionEffective(req, "orders", "read");
|
|
30387
30867
|
if (pe) return pe;
|
|
30388
30868
|
const cms = await getCms();
|
|
30389
|
-
const { streamOrderInvoicePdf: streamOrderInvoicePdf2 } = await import('./erp-order-invoice-
|
|
30869
|
+
const { streamOrderInvoicePdf: streamOrderInvoicePdf2 } = await import('./erp-order-invoice-AZ5MX2JB.cjs');
|
|
30390
30870
|
const oid = Number(path2[1]);
|
|
30391
30871
|
if (!Number.isFinite(oid)) return config.json({
|
|
30392
30872
|
error: "Invalid id"
|
|
@@ -30467,7 +30947,7 @@ function createCmsApiHandler(config) {
|
|
|
30467
30947
|
let vendorId = null;
|
|
30468
30948
|
if (resolveSessionUser) {
|
|
30469
30949
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
30470
|
-
const scope =
|
|
30950
|
+
const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
30471
30951
|
if (scope.type === "vendor") vendorId = scope.vendorId;
|
|
30472
30952
|
}
|
|
30473
30953
|
const result = await validateCoupon(dataSource, entityMap, couponCode, orderLinesNorm, currency, contactId, isAutomatic, discountId ?? void 0, vendorId);
|
|
@@ -30555,7 +31035,7 @@ function createCmsApiHandler(config) {
|
|
|
30555
31035
|
let vendorId = null;
|
|
30556
31036
|
if (resolveSessionUser) {
|
|
30557
31037
|
const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
|
|
30558
|
-
const scope =
|
|
31038
|
+
const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
30559
31039
|
if (scope.type === "vendor") vendorId = scope.vendorId;
|
|
30560
31040
|
}
|
|
30561
31041
|
const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
|
|
@@ -30768,7 +31248,7 @@ function createCmsApiHandler(config) {
|
|
|
30768
31248
|
status: 400
|
|
30769
31249
|
});
|
|
30770
31250
|
}
|
|
30771
|
-
const { resendOrderNotification } = await import('./order-notification-dispatcher-
|
|
31251
|
+
const { resendOrderNotification } = await import('./order-notification-dispatcher-6HCJ6Q75.cjs');
|
|
30772
31252
|
const result = await resendOrderNotification(triggerKey, orderId, {
|
|
30773
31253
|
dataSource,
|
|
30774
31254
|
entityMap,
|
|
@@ -30867,7 +31347,7 @@ function createCmsApiHandler(config) {
|
|
|
30867
31347
|
status: "cancelled"
|
|
30868
31348
|
});
|
|
30869
31349
|
const fireOrderCancelledNotification = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((refundAmount) => {
|
|
30870
|
-
void import('./emit-order-notification-trigger-
|
|
31350
|
+
void import('./emit-order-notification-trigger-ROASTYQP.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
30871
31351
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
30872
31352
|
dataSource,
|
|
30873
31353
|
entityMap
|
|
@@ -31112,8 +31592,8 @@ function createCmsApiHandler(config) {
|
|
|
31112
31592
|
}, {
|
|
31113
31593
|
status: 400
|
|
31114
31594
|
});
|
|
31115
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31116
|
-
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31595
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-DDQREULW.cjs');
|
|
31596
|
+
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
|
|
31117
31597
|
return handlers.getChannels(req, orderId);
|
|
31118
31598
|
}
|
|
31119
31599
|
if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "send" && m === "POST" && getCms) {
|
|
@@ -31127,8 +31607,8 @@ function createCmsApiHandler(config) {
|
|
|
31127
31607
|
}, {
|
|
31128
31608
|
status: 400
|
|
31129
31609
|
});
|
|
31130
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31131
|
-
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31610
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-DDQREULW.cjs');
|
|
31611
|
+
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
|
|
31132
31612
|
return handlers.sendOtp(req, orderId);
|
|
31133
31613
|
}
|
|
31134
31614
|
if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "verify" && m === "POST" && getCms) {
|
|
@@ -31142,8 +31622,8 @@ function createCmsApiHandler(config) {
|
|
|
31142
31622
|
}, {
|
|
31143
31623
|
status: 400
|
|
31144
31624
|
});
|
|
31145
|
-
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-
|
|
31146
|
-
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31625
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-DDQREULW.cjs');
|
|
31626
|
+
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
|
|
31147
31627
|
return handlers.verifyOtp(req, orderId);
|
|
31148
31628
|
}
|
|
31149
31629
|
if (path2[0] === "orders" && path2.length === 3 && path2[2] === "eligible-assignees" && m === "GET") {
|
|
@@ -31157,7 +31637,7 @@ function createCmsApiHandler(config) {
|
|
|
31157
31637
|
}, {
|
|
31158
31638
|
status: 400
|
|
31159
31639
|
});
|
|
31160
|
-
const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-
|
|
31640
|
+
const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-KF7RMTV5.cjs');
|
|
31161
31641
|
const handlers = createOrderAssigneesHandlers(dataSource, entityMap, getHydratedSessionUser);
|
|
31162
31642
|
return handlers.listEligibleAssignees(req, orderId);
|
|
31163
31643
|
}
|
|
@@ -31267,7 +31747,7 @@ function createCmsApiHandler(config) {
|
|
|
31267
31747
|
if (resolveSessionUser) {
|
|
31268
31748
|
const raw = await resolveSessionUser();
|
|
31269
31749
|
const u = await hydrateVendorSessionUser(dataSource, raw);
|
|
31270
|
-
const scope =
|
|
31750
|
+
const scope = chunkO4AFPDQ4_cjs.resolveVendorScopeFromSessionUser(u ?? null);
|
|
31271
31751
|
if (scope.type === "vendor") {
|
|
31272
31752
|
scopedVendorIds = scope.vendorIds;
|
|
31273
31753
|
}
|
|
@@ -31590,12 +32070,12 @@ async function refreshOrderFromErp(cms, dataSource, entityMap, submission, order
|
|
|
31590
32070
|
const r1 = await submission.postErpReadAction("get-order-status", {
|
|
31591
32071
|
platformOrderId: refId
|
|
31592
32072
|
});
|
|
31593
|
-
const d1 = r1.ok ?
|
|
32073
|
+
const d1 = r1.ok ? chunkSUUD7OUG_cjs.unwrapErpReadData(r1.json) : null;
|
|
31594
32074
|
if (d1) {
|
|
31595
32075
|
const mapped = mapErpSaleStatusToOrderStatus(typeof d1.status === "string" ? d1.status : typeof d1.orderStatus === "string" ? d1.orderStatus : typeof d1.state === "string" ? d1.state : void 0);
|
|
31596
32076
|
if (mapped) newStatus = mapped;
|
|
31597
|
-
fulfillment =
|
|
31598
|
-
const refs =
|
|
32077
|
+
fulfillment = chunkSUUD7OUG_cjs.mapErpPayloadToFulfillment(d1);
|
|
32078
|
+
const refs = chunkSUUD7OUG_cjs.extractChildOrderRefsFromSalePayload(d1);
|
|
31599
32079
|
if (refs.length) {
|
|
31600
32080
|
await ensureChildOrdersFromRefs(orderRepo, order, refs, order.contactId, String(order.currency || "INR"));
|
|
31601
32081
|
}
|
|
@@ -31603,16 +32083,16 @@ async function refreshOrderFromErp(cms, dataSource, entityMap, submission, order
|
|
|
31603
32083
|
const r2 = await submission.postErpReadAction("get-fulfillment-status", {
|
|
31604
32084
|
platformOrderId: refId
|
|
31605
32085
|
});
|
|
31606
|
-
const d2 = r2.ok ?
|
|
32086
|
+
const d2 = r2.ok ? chunkSUUD7OUG_cjs.unwrapErpReadData(r2.json) : null;
|
|
31607
32087
|
if (d2) {
|
|
31608
|
-
fulfillment = deepMergeFulfillment(fulfillment,
|
|
32088
|
+
fulfillment = deepMergeFulfillment(fulfillment, chunkSUUD7OUG_cjs.mapErpPayloadToFulfillment(d2));
|
|
31609
32089
|
}
|
|
31610
32090
|
const r3 = await submission.postErpReadAction("get-invoice", {
|
|
31611
32091
|
platformOrderId: refId
|
|
31612
32092
|
});
|
|
31613
|
-
const d3 = r3.ok ?
|
|
32093
|
+
const d3 = r3.ok ? chunkSUUD7OUG_cjs.unwrapErpReadData(r3.json) : null;
|
|
31614
32094
|
if (d3) {
|
|
31615
|
-
invoiceNumber =
|
|
32095
|
+
invoiceNumber = chunkSUUD7OUG_cjs.mapErpPayloadToInvoiceNumber(d3);
|
|
31616
32096
|
invoiceId = pickInvoiceId(d3);
|
|
31617
32097
|
}
|
|
31618
32098
|
const oid = order.id;
|
|
@@ -31648,10 +32128,10 @@ async function refreshOrderFromErp(cms, dataSource, entityMap, submission, order
|
|
|
31648
32128
|
const r = await submission.postErpReadAction("get-return-status", {
|
|
31649
32129
|
platformReturnId
|
|
31650
32130
|
});
|
|
31651
|
-
const d = r.ok ?
|
|
32131
|
+
const d = r.ok ? chunkSUUD7OUG_cjs.unwrapErpReadData(r.json) : null;
|
|
31652
32132
|
if (!d) return;
|
|
31653
32133
|
const mapped = mapErpSaleStatusToOrderStatus(typeof d.status === "string" ? d.status : typeof d.returnStatus === "string" ? d.returnStatus : void 0);
|
|
31654
|
-
const fulfillment =
|
|
32134
|
+
const fulfillment = chunkSUUD7OUG_cjs.mapErpPayloadToFulfillment(d);
|
|
31655
32135
|
const patch = {};
|
|
31656
32136
|
if (fulfillment !== void 0) patch.fulfillment = fulfillment;
|
|
31657
32137
|
const nextMeta = Object.keys(patch).length ? mergeOrderMetadataPatch(meta, patch) : meta;
|
|
@@ -31774,7 +32254,7 @@ function createStorefrontApiHandler(config) {
|
|
|
31774
32254
|
const otpPepper = config.otpPepper;
|
|
31775
32255
|
const defaultPhoneCc = config.defaultPhoneCountryCode;
|
|
31776
32256
|
function fireStorefrontCheckoutNotifications(orderId) {
|
|
31777
|
-
void import('./emit-order-notification-trigger-
|
|
32257
|
+
void import('./emit-order-notification-trigger-ROASTYQP.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
31778
32258
|
fireOrderNotificationTrigger("order_pending", orderId, {
|
|
31779
32259
|
dataSource,
|
|
31780
32260
|
entityMap
|
|
@@ -33458,7 +33938,7 @@ function createStorefrontApiHandler(config) {
|
|
|
33458
33938
|
status: 503
|
|
33459
33939
|
});
|
|
33460
33940
|
const companyDetails = getCompanyDetails ? await getCompanyDetails() : {};
|
|
33461
|
-
await
|
|
33941
|
+
await chunkUMC7W5G3_cjs.queueEmail(cms, {
|
|
33462
33942
|
to: identifier,
|
|
33463
33943
|
templateName: "otp",
|
|
33464
33944
|
ctx: {
|
|
@@ -33656,10 +34136,10 @@ function createStorefrontApiHandler(config) {
|
|
|
33656
34136
|
adminAccess: false
|
|
33657
34137
|
}));
|
|
33658
34138
|
const userId = newUser.id;
|
|
33659
|
-
await
|
|
34139
|
+
await chunkOV5TRZET_cjs.linkUnclaimedContactToUser(dataSource, entityMap.contacts, userId, email);
|
|
33660
34140
|
if (entityMap.customer) {
|
|
33661
34141
|
const phone = typeof b.phone === "string" && b.phone.trim() ? String(b.phone).trim() : null;
|
|
33662
|
-
await
|
|
34142
|
+
await chunkOV5TRZET_cjs.ensureCustomerForUser(dataSource, entityMap.customer, {
|
|
33663
34143
|
id: userId,
|
|
33664
34144
|
name,
|
|
33665
34145
|
email,
|
|
@@ -33683,7 +34163,7 @@ function createStorefrontApiHandler(config) {
|
|
|
33683
34163
|
const companyDetails = getCompanyDetails ? await getCompanyDetails() : {};
|
|
33684
34164
|
const base = (publicSiteUrl || "").replace(/\/$/, "").trim() || "http://localhost:3000";
|
|
33685
34165
|
const verifyEmailUrl = `${base}/verify-email?token=${encodeURIComponent(rawToken)}`;
|
|
33686
|
-
await
|
|
34166
|
+
await chunkUMC7W5G3_cjs.queueEmail(cms, {
|
|
33687
34167
|
to: email,
|
|
33688
34168
|
templateName: "signup",
|
|
33689
34169
|
ctx: {
|
|
@@ -34497,7 +34977,7 @@ function createStorefrontApiHandler(config) {
|
|
|
34497
34977
|
status: 400
|
|
34498
34978
|
});
|
|
34499
34979
|
const cms = await getCms();
|
|
34500
|
-
return
|
|
34980
|
+
return chunkSUUD7OUG_cjs.streamOrderInvoicePdf(cms, dataSource, entityMap, orderId, {
|
|
34501
34981
|
ownerContactId: contact.id
|
|
34502
34982
|
});
|
|
34503
34983
|
}
|
|
@@ -34538,7 +35018,9 @@ function createStorefrontApiHandler(config) {
|
|
|
34538
35018
|
},
|
|
34539
35019
|
relations: [
|
|
34540
35020
|
"items",
|
|
34541
|
-
"items.product"
|
|
35021
|
+
"items.product",
|
|
35022
|
+
"assignedUser",
|
|
35023
|
+
"payments"
|
|
34542
35024
|
]
|
|
34543
35025
|
});
|
|
34544
35026
|
if (!order) return json({
|
|
@@ -34564,7 +35046,9 @@ function createStorefrontApiHandler(config) {
|
|
|
34564
35046
|
},
|
|
34565
35047
|
relations: [
|
|
34566
35048
|
"items",
|
|
34567
|
-
"items.product"
|
|
35049
|
+
"items.product",
|
|
35050
|
+
"assignedUser",
|
|
35051
|
+
"payments"
|
|
34568
35052
|
]
|
|
34569
35053
|
});
|
|
34570
35054
|
}
|
|
@@ -34630,6 +35114,17 @@ function createStorefrontApiHandler(config) {
|
|
|
34630
35114
|
currency: o.currency,
|
|
34631
35115
|
createdAt: o.createdAt,
|
|
34632
35116
|
metadata: o.metadata ?? null,
|
|
35117
|
+
assignedUser: o.assignedUser ? {
|
|
35118
|
+
id: o.assignedUser.id,
|
|
35119
|
+
name: o.assignedUser.name,
|
|
35120
|
+
phone: o.assignedUser.phone
|
|
35121
|
+
} : null,
|
|
35122
|
+
payments: Array.isArray(o.payments) ? o.payments.map((pm) => ({
|
|
35123
|
+
id: pm.id,
|
|
35124
|
+
amount: pm.amount,
|
|
35125
|
+
method: pm.method,
|
|
35126
|
+
status: pm.status
|
|
35127
|
+
})) : [],
|
|
34633
35128
|
items: lines
|
|
34634
35129
|
},
|
|
34635
35130
|
relatedOrders: relatedOrders.map((r) => ({
|
|
@@ -34704,7 +35199,7 @@ function createStorefrontApiHandler(config) {
|
|
|
34704
35199
|
} catch {
|
|
34705
35200
|
}
|
|
34706
35201
|
try {
|
|
34707
|
-
void import('./emit-order-notification-trigger-
|
|
35202
|
+
void import('./emit-order-notification-trigger-ROASTYQP.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
34708
35203
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
34709
35204
|
dataSource,
|
|
34710
35205
|
entityMap
|