@infuro/cms-core 1.0.60 → 1.0.62
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 +4179 -2665
- package/dist/admin.js +2990 -1476
- package/dist/api.cjs +41 -37
- package/dist/api.js +9 -5
- package/dist/{chunk-URN7GS23.js → chunk-6LV36PCL.js} +199 -1059
- package/dist/{chunk-O2642WVS.js → chunk-6XAVZE4I.js} +17 -3
- package/dist/{chunk-BXYZDMTZ.cjs → chunk-AXMP2U43.cjs} +3 -94
- package/dist/{chunk-T3HPSF7K.js → chunk-AYWDQFJZ.js} +3 -0
- package/dist/chunk-CTIEAHQL.cjs +96 -0
- package/dist/chunk-GWDI752Q.js +83 -0
- package/dist/chunk-GZGFNVTK.js +886 -0
- package/dist/chunk-H3IVLIPR.cjs +86 -0
- package/dist/{chunk-2KUCQVAQ.js → chunk-HMLVPIJR.js} +2 -91
- package/dist/{chunk-V25RDUOU.cjs → chunk-LRD4CGOG.cjs} +38 -4
- package/dist/{chunk-73WVHINE.cjs → chunk-LVQSG25Y.cjs} +18 -4
- package/dist/chunk-NMYGQWHV.js +93 -0
- package/dist/chunk-OVTOP42W.js +199 -0
- package/dist/{chunk-BSLNXKV2.cjs → chunk-QA5C477U.cjs} +927 -351
- package/dist/{chunk-JAEUYYGA.js → chunk-R6Q67HAS.js} +876 -291
- package/dist/{chunk-YSYX4GUD.cjs → chunk-TWTISTZB.cjs} +210 -1080
- package/dist/{chunk-77I3KS7V.cjs → chunk-UEE4PTTB.cjs} +3 -0
- package/dist/chunk-WFMVD567.cjs +209 -0
- package/dist/{chunk-L3525VXI.js → chunk-YW7EF7K7.js} +36 -2
- package/dist/chunk-ZPAPCGCR.cjs +899 -0
- package/dist/{email-queue-OI2HSCGE.js → email-queue-65PQAG4C.js} +3 -2
- package/dist/{email-queue-6NJY6HNM.cjs → email-queue-J7DXYNCE.cjs} +7 -6
- package/dist/email-service-F7HA4X63.js +3 -0
- package/dist/email-service-RDOTY3CO.cjs +28 -0
- package/dist/{emit-order-notification-trigger-TNEZOYEE.cjs → emit-order-notification-trigger-K7URAZHJ.cjs} +4 -4
- package/dist/{emit-order-notification-trigger-CZU3V2WE.js → emit-order-notification-trigger-MD7EBODC.js} +2 -2
- package/dist/{erp-order-invoice-EYYNR526.cjs → erp-order-invoice-C5GZCOBM.cjs} +6 -5
- package/dist/{erp-order-invoice-3GXDE443.js → erp-order-invoice-MYFCXOCY.js} +2 -1
- package/dist/index.cjs +638 -346
- package/dist/index.d.cts +53 -19
- package/dist/index.d.ts +53 -19
- package/dist/index.js +350 -58
- package/dist/migrations/1783000000000-AddOrderPendingProcessingCompletedTriggers.ts +56 -0
- package/dist/migrations/1783100000000-AddSmsToOrderNotificationBindingsChannelEnum.ts +17 -0
- package/dist/migrations/1783200000000-AddOrderAssigneeColumns.ts +30 -0
- package/dist/order-assignees-handlers-LKMAGLG6.js +150 -0
- package/dist/order-assignees-handlers-NPKD64P6.cjs +152 -0
- package/dist/order-completion-otp-handlers-3NTOGEA5.js +361 -0
- package/dist/order-completion-otp-handlers-4EOLYLAP.cjs +363 -0
- package/dist/order-notification-dispatcher-IYMOS4VY.js +10 -0
- package/dist/order-notification-dispatcher-X2XM5VUY.cjs +35 -0
- package/dist/sms-notification-templates-handlers-SJLO7JGZ.js +47 -0
- package/dist/sms-notification-templates-handlers-YSB3L2PK.cjs +49 -0
- package/package.json +1 -1
- package/dist/order-notification-dispatcher-KJVGLK5E.cjs +0 -24
- package/dist/order-notification-dispatcher-ZSFKEYMP.js +0 -7
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkWFMVD567_cjs = require('./chunk-WFMVD567.cjs');
|
|
3
4
|
var chunkXQ3QUHWR_cjs = require('./chunk-XQ3QUHWR.cjs');
|
|
4
5
|
var chunkHY3AXLOI_cjs = require('./chunk-HY3AXLOI.cjs');
|
|
5
|
-
var
|
|
6
|
+
var chunkTWTISTZB_cjs = require('./chunk-TWTISTZB.cjs');
|
|
7
|
+
var chunkH3IVLIPR_cjs = require('./chunk-H3IVLIPR.cjs');
|
|
6
8
|
var chunk7NMT3GBR_cjs = require('./chunk-7NMT3GBR.cjs');
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
+
var chunkLRD4CGOG_cjs = require('./chunk-LRD4CGOG.cjs');
|
|
10
|
+
var chunkAXMP2U43_cjs = require('./chunk-AXMP2U43.cjs');
|
|
9
11
|
var chunkUPLVMVRX_cjs = require('./chunk-UPLVMVRX.cjs');
|
|
12
|
+
var chunkCTIEAHQL_cjs = require('./chunk-CTIEAHQL.cjs');
|
|
10
13
|
var chunk3DZRIZOD_cjs = require('./chunk-3DZRIZOD.cjs');
|
|
11
14
|
var chunkTJ2MIQUT_cjs = require('./chunk-TJ2MIQUT.cjs');
|
|
12
15
|
var chunk4U6DATGZ_cjs = require('./chunk-4U6DATGZ.cjs');
|
|
@@ -1526,9 +1529,15 @@ async function autoExpireOrderIfPaymentTimeExceeded(dataSource, entityMap, order
|
|
|
1526
1529
|
if (status !== "pending") return order;
|
|
1527
1530
|
const meta = typeof order.metadata === "object" && order.metadata ? order.metadata : {};
|
|
1528
1531
|
const expiresAtStr = meta.paymentExpiresAt ? String(meta.paymentExpiresAt) : null;
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
+
let isExpired = false;
|
|
1533
|
+
if (expiresAtStr) {
|
|
1534
|
+
const expiresMs = new Date(expiresAtStr).getTime();
|
|
1535
|
+
if (!Number.isNaN(expiresMs) && Date.now() > expiresMs) isExpired = true;
|
|
1536
|
+
} else if (order.createdAt) {
|
|
1537
|
+
const createdMs = new Date(order.createdAt).getTime();
|
|
1538
|
+
if (!Number.isNaN(createdMs) && Date.now() - createdMs > 10 * 60 * 1e3) isExpired = true;
|
|
1539
|
+
}
|
|
1540
|
+
if (!isExpired) return order;
|
|
1532
1541
|
try {
|
|
1533
1542
|
const orderId = Number(order.id);
|
|
1534
1543
|
if (orderId && entityMap.orders) {
|
|
@@ -3557,7 +3566,7 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
3557
3566
|
});
|
|
3558
3567
|
}
|
|
3559
3568
|
}
|
|
3560
|
-
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").andWhere("order.deleted = :orderDel", {
|
|
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", {
|
|
3561
3570
|
orderDel: false
|
|
3562
3571
|
}).orderBy(`order.${sortField2}`, sortOrderOrders).skip(skip).take(limit);
|
|
3563
3572
|
applyVendorScopeToQueryBuilder(qb, "order", scope);
|
|
@@ -3615,7 +3624,9 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
3615
3624
|
}
|
|
3616
3625
|
const [rows, total2] = await qb.getManyAndCount();
|
|
3617
3626
|
const data2 = await Promise.all(rows.map(async (order) => {
|
|
3627
|
+
await autoExpireOrderIfPaymentTimeExceeded(dataSource, entityMap, order);
|
|
3618
3628
|
const contact = order.contact;
|
|
3629
|
+
const assignedUserObj = order.assignedUser;
|
|
3619
3630
|
const items = order.items ?? [];
|
|
3620
3631
|
const orderPayments = order.payments ?? [];
|
|
3621
3632
|
const parts = [];
|
|
@@ -3663,6 +3674,11 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
3663
3674
|
email: contact.email,
|
|
3664
3675
|
phone: contact.phone
|
|
3665
3676
|
} : null,
|
|
3677
|
+
assignedUser: assignedUserObj ? {
|
|
3678
|
+
id: assignedUserObj.id,
|
|
3679
|
+
name: assignedUserObj.name || assignedUserObj.email,
|
|
3680
|
+
email: assignedUserObj.email
|
|
3681
|
+
} : null,
|
|
3666
3682
|
itemsSummary,
|
|
3667
3683
|
paymentStatus: paymentStatus2
|
|
3668
3684
|
};
|
|
@@ -3856,14 +3872,14 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
3856
3872
|
if (Number.isFinite(n)) productWhere[key] = n;
|
|
3857
3873
|
}
|
|
3858
3874
|
}
|
|
3859
|
-
const
|
|
3860
|
-
if (
|
|
3861
|
-
const ids =
|
|
3875
|
+
const idsParam2 = searchParams.get("ids")?.trim();
|
|
3876
|
+
if (idsParam2) {
|
|
3877
|
+
const ids = idsParam2.split(",").map((s) => Number(s.trim())).filter((n) => Number.isFinite(n) && n > 0);
|
|
3862
3878
|
productWhere.id = ids.length > 0 ? typeorm.In(ids) : -1;
|
|
3863
3879
|
} else {
|
|
3864
|
-
const
|
|
3865
|
-
if (
|
|
3866
|
-
const excludeIds =
|
|
3880
|
+
const excludeIdsParam2 = searchParams.get("excludeIds")?.trim();
|
|
3881
|
+
if (excludeIdsParam2) {
|
|
3882
|
+
const excludeIds = excludeIdsParam2.split(",").map((s) => Number(s.trim())).filter((n) => Number.isFinite(n) && n > 0);
|
|
3867
3883
|
if (excludeIds.length > 0) productWhere.id = typeorm.Not(typeorm.In(excludeIds));
|
|
3868
3884
|
}
|
|
3869
3885
|
}
|
|
@@ -4140,6 +4156,24 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
4140
4156
|
}
|
|
4141
4157
|
}
|
|
4142
4158
|
where = mergeDeletedFalseWhere(repo, where);
|
|
4159
|
+
const idsParam = searchParams.get("ids")?.trim();
|
|
4160
|
+
if (idsParam && columnNames.has("id")) {
|
|
4161
|
+
const idList = idsParam.split(",").map((s) => Number(s.trim())).filter((n) => Number.isFinite(n) && n > 0);
|
|
4162
|
+
if (idList.length > 0) {
|
|
4163
|
+
where = mergeListWhereAnd(where, {
|
|
4164
|
+
id: typeorm.In(idList)
|
|
4165
|
+
});
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
const excludeIdsParam = searchParams.get("excludeIds")?.trim();
|
|
4169
|
+
if (excludeIdsParam && columnNames.has("id")) {
|
|
4170
|
+
const excludeIdList = excludeIdsParam.split(",").map((s) => Number(s.trim())).filter((n) => Number.isFinite(n) && n > 0);
|
|
4171
|
+
if (excludeIdList.length > 0) {
|
|
4172
|
+
where = mergeListWhereAnd(where, {
|
|
4173
|
+
id: typeorm.Not(typeorm.In(excludeIdList))
|
|
4174
|
+
});
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4143
4177
|
if (resourceUsesVendorScope(resource)) {
|
|
4144
4178
|
const scope = await resolveScope();
|
|
4145
4179
|
const catalogFlags = await getVendorCatalogCreateFlags(dataSource);
|
|
@@ -5181,18 +5215,99 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
5181
5215
|
}
|
|
5182
5216
|
await recordDiscountUsage2(dataSource, entityMap, created.id, orderDiscountId, persistBody.contactId, discount);
|
|
5183
5217
|
}
|
|
5218
|
+
if (entityMap["payments"]) {
|
|
5219
|
+
try {
|
|
5220
|
+
const paymentRepo = dataSource.getRepository(entityMap["payments"]);
|
|
5221
|
+
const initialPayStatus2 = String(persistBody.paymentStatus ?? body.paymentStatus ?? "unpaid").toLowerCase();
|
|
5222
|
+
const isPaid = initialPayStatus2 === "paid" || initialPayStatus2 === "captured";
|
|
5223
|
+
const vId = Number(orderVendorId ?? created?.vendorId ?? 1);
|
|
5224
|
+
const cId = persistBody.contactId ? Number(persistBody.contactId) : null;
|
|
5225
|
+
await paymentRepo.save(paymentRepo.create({
|
|
5226
|
+
vendorId: vId,
|
|
5227
|
+
contactId: cId,
|
|
5228
|
+
orderId: created.id,
|
|
5229
|
+
status: initialPayStatus2,
|
|
5230
|
+
amount: Number(total ?? persistBody.total ?? 0),
|
|
5231
|
+
currency: orderCurrency ?? persistBody.currency ?? "INR",
|
|
5232
|
+
paidAt: isPaid ? /* @__PURE__ */ new Date() : null,
|
|
5233
|
+
method: String(body.paymentMethod ?? "manual")
|
|
5234
|
+
}));
|
|
5235
|
+
} catch (payErr) {
|
|
5236
|
+
console.error("[crud] failed to create initial payment for order", payErr);
|
|
5237
|
+
}
|
|
5238
|
+
}
|
|
5184
5239
|
const orderIdForNotify = created.id;
|
|
5185
|
-
const
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
5240
|
+
const finalCreatedStatus = String(created.status ?? createdStatus ?? "pending").toLowerCase();
|
|
5241
|
+
const initialPayStatus = String(persistBody.paymentStatus ?? body.paymentStatus ?? "unpaid").toLowerCase();
|
|
5242
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
5243
|
+
if (finalCreatedStatus === "pending") {
|
|
5244
|
+
if (initialPayStatus === "failed") {
|
|
5245
|
+
fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
|
|
5246
|
+
dataSource,
|
|
5247
|
+
entityMap
|
|
5248
|
+
});
|
|
5249
|
+
} else {
|
|
5250
|
+
fireOrderNotificationTrigger("order_pending", orderIdForNotify, {
|
|
5251
|
+
dataSource,
|
|
5252
|
+
entityMap
|
|
5253
|
+
});
|
|
5254
|
+
}
|
|
5255
|
+
} else if (finalCreatedStatus === "confirmed") {
|
|
5256
|
+
fireOrderNotificationTrigger("order_placed", orderIdForNotify, {
|
|
5257
|
+
dataSource,
|
|
5258
|
+
entityMap
|
|
5259
|
+
});
|
|
5260
|
+
if (initialPayStatus === "paid" || initialPayStatus === "captured") {
|
|
5261
|
+
fireOrderNotificationTrigger("payment_success", orderIdForNotify, {
|
|
5262
|
+
dataSource,
|
|
5263
|
+
entityMap
|
|
5264
|
+
});
|
|
5265
|
+
} else if (initialPayStatus === "failed") {
|
|
5266
|
+
fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
|
|
5267
|
+
dataSource,
|
|
5268
|
+
entityMap
|
|
5269
|
+
});
|
|
5270
|
+
}
|
|
5271
|
+
} else if (finalCreatedStatus === "processing") {
|
|
5272
|
+
fireOrderNotificationTrigger("order_processing", orderIdForNotify, {
|
|
5193
5273
|
dataSource,
|
|
5194
5274
|
entityMap
|
|
5195
5275
|
});
|
|
5276
|
+
if (initialPayStatus === "failed") {
|
|
5277
|
+
fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
|
|
5278
|
+
dataSource,
|
|
5279
|
+
entityMap
|
|
5280
|
+
});
|
|
5281
|
+
}
|
|
5282
|
+
} else if (finalCreatedStatus === "completed") {
|
|
5283
|
+
fireOrderNotificationTrigger("order_completed", orderIdForNotify, {
|
|
5284
|
+
dataSource,
|
|
5285
|
+
entityMap
|
|
5286
|
+
});
|
|
5287
|
+
if (initialPayStatus === "failed") {
|
|
5288
|
+
fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
|
|
5289
|
+
dataSource,
|
|
5290
|
+
entityMap
|
|
5291
|
+
});
|
|
5292
|
+
}
|
|
5293
|
+
} else if (finalCreatedStatus === "cancelled") {
|
|
5294
|
+
if (initialPayStatus === "failed") {
|
|
5295
|
+
fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
|
|
5296
|
+
dataSource,
|
|
5297
|
+
entityMap
|
|
5298
|
+
});
|
|
5299
|
+
} else {
|
|
5300
|
+
fireOrderNotificationTrigger("order_cancelled", orderIdForNotify, {
|
|
5301
|
+
dataSource,
|
|
5302
|
+
entityMap
|
|
5303
|
+
});
|
|
5304
|
+
if (initialPayStatus === "paid" || initialPayStatus === "refunded") {
|
|
5305
|
+
fireOrderNotificationTrigger("payment_refund_initiated", orderIdForNotify, {
|
|
5306
|
+
dataSource,
|
|
5307
|
+
entityMap
|
|
5308
|
+
});
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5196
5311
|
}
|
|
5197
5312
|
});
|
|
5198
5313
|
}
|
|
@@ -5543,8 +5658,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
5543
5658
|
const scope2 = await resolveScopeById();
|
|
5544
5659
|
const order = await repo.findOne({
|
|
5545
5660
|
where: {
|
|
5546
|
-
id: Number(id)
|
|
5547
|
-
deleted: false
|
|
5661
|
+
id: Number(id)
|
|
5548
5662
|
},
|
|
5549
5663
|
relations: [
|
|
5550
5664
|
"contact",
|
|
@@ -5553,7 +5667,8 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
5553
5667
|
"items",
|
|
5554
5668
|
"items.product",
|
|
5555
5669
|
"items.product.collection",
|
|
5556
|
-
"payments"
|
|
5670
|
+
"payments",
|
|
5671
|
+
"assignedUser"
|
|
5557
5672
|
]
|
|
5558
5673
|
});
|
|
5559
5674
|
if (order) {
|
|
@@ -5563,8 +5678,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
5563
5678
|
if (orderDenied) return orderDenied;
|
|
5564
5679
|
const relatedOrders = await repo.find({
|
|
5565
5680
|
where: {
|
|
5566
|
-
parentOrderId: Number(id)
|
|
5567
|
-
deleted: false
|
|
5681
|
+
parentOrderId: Number(id)
|
|
5568
5682
|
},
|
|
5569
5683
|
order: {
|
|
5570
5684
|
id: "ASC"
|
|
@@ -5943,6 +6057,36 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
5943
6057
|
lines: []
|
|
5944
6058
|
} : await calculateOrderTotalsFromLines(dataSource, entityMap, orderLinesNorm, effectiveCurrency, putDiscountId, Number.isFinite(putOrderVendorId) ? putOrderVendorId : null);
|
|
5945
6059
|
const scalarUpdate = pickColumnUpdates(repo, rawBody);
|
|
6060
|
+
if (rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0) {
|
|
6061
|
+
const aId = Number(rawBody.assignedUserId);
|
|
6062
|
+
if (Number.isFinite(aId) && aId > 0) {
|
|
6063
|
+
scalarUpdate.assignedUserId = aId;
|
|
6064
|
+
scalarUpdate.assignedAt = /* @__PURE__ */ new Date();
|
|
6065
|
+
if (!scalarUpdate.status && (orderInvPrev?.status === "confirmed" || orderInvPrev?.status === "pending")) {
|
|
6066
|
+
scalarUpdate.status = "processing";
|
|
6067
|
+
}
|
|
6068
|
+
} else {
|
|
6069
|
+
scalarUpdate.assignedUserId = null;
|
|
6070
|
+
scalarUpdate.assignedAt = null;
|
|
6071
|
+
}
|
|
6072
|
+
}
|
|
6073
|
+
if (scalarUpdate.status === "processing") {
|
|
6074
|
+
const effectiveAssignee = scalarUpdate.assignedUserId !== void 0 ? scalarUpdate.assignedUserId : orderInvPrev?.assignedUserId;
|
|
6075
|
+
if (!effectiveAssignee) {
|
|
6076
|
+
return json({
|
|
6077
|
+
error: "Cannot start processing without assigning a teammate. Please assign a teammate first."
|
|
6078
|
+
}, {
|
|
6079
|
+
status: 400
|
|
6080
|
+
});
|
|
6081
|
+
}
|
|
6082
|
+
}
|
|
6083
|
+
if (scalarUpdate.status === "completed" && orderInvPrev?.status !== "completed" && !rawBody?.__internalBypassOtp) {
|
|
6084
|
+
return json({
|
|
6085
|
+
error: "Direct completion is disabled. Please complete the order via the customer OTP verification flow."
|
|
6086
|
+
}, {
|
|
6087
|
+
status: 400
|
|
6088
|
+
});
|
|
6089
|
+
}
|
|
5946
6090
|
const nextStatus = typeof scalarUpdate.status === "string" && scalarUpdate.status ? String(scalarUpdate.status) : orderInvPrev?.status ?? "pending";
|
|
5947
6091
|
if (chunkHY3AXLOI_cjs.orderStatusHoldsStock(nextStatus) && lines.length > 0) {
|
|
5948
6092
|
const verr = await chunkHY3AXLOI_cjs.validateInventoryForOrderBecomingConfirmed(dataSource, entityMap, orderInvPrev, lines.filter((l) => l.found && l.productId != null).map((l) => ({
|
|
@@ -6130,6 +6274,128 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6130
6274
|
}
|
|
6131
6275
|
}
|
|
6132
6276
|
}
|
|
6277
|
+
if (rawBody && entityMap["payments"]) {
|
|
6278
|
+
try {
|
|
6279
|
+
const bodyPayStatusRaw = rawBody.paymentStatus;
|
|
6280
|
+
if (bodyPayStatusRaw != null && typeof bodyPayStatusRaw === "string") {
|
|
6281
|
+
const payStatus = bodyPayStatusRaw.trim().toLowerCase();
|
|
6282
|
+
const paymentRepo = dataSource.getRepository(entityMap["payments"]);
|
|
6283
|
+
const existingPay = await paymentRepo.findOne({
|
|
6284
|
+
where: {
|
|
6285
|
+
orderId: numericId
|
|
6286
|
+
},
|
|
6287
|
+
order: {
|
|
6288
|
+
id: "DESC"
|
|
6289
|
+
}
|
|
6290
|
+
});
|
|
6291
|
+
const isPaid = payStatus === "paid" || payStatus === "captured";
|
|
6292
|
+
if (existingPay) {
|
|
6293
|
+
await paymentRepo.update(existingPay.id, {
|
|
6294
|
+
status: payStatus,
|
|
6295
|
+
paidAt: isPaid && !existingPay.paidAt ? /* @__PURE__ */ new Date() : existingPay.paidAt
|
|
6296
|
+
});
|
|
6297
|
+
} else {
|
|
6298
|
+
const orderRow = updatedOrder;
|
|
6299
|
+
const orderTotal = Number(orderRow?.total ?? 0);
|
|
6300
|
+
const orderCurrency = String(orderRow?.currency ?? "INR");
|
|
6301
|
+
const vId = Number(orderRow?.vendorId ?? 1);
|
|
6302
|
+
const cId = orderRow?.contactId ? Number(orderRow.contactId) : null;
|
|
6303
|
+
await paymentRepo.save(paymentRepo.create({
|
|
6304
|
+
vendorId: vId,
|
|
6305
|
+
contactId: cId,
|
|
6306
|
+
orderId: numericId,
|
|
6307
|
+
status: payStatus,
|
|
6308
|
+
amount: orderTotal,
|
|
6309
|
+
currency: orderCurrency,
|
|
6310
|
+
paidAt: isPaid ? /* @__PURE__ */ new Date() : null,
|
|
6311
|
+
method: "manual"
|
|
6312
|
+
}));
|
|
6313
|
+
}
|
|
6314
|
+
}
|
|
6315
|
+
} catch (payErr) {
|
|
6316
|
+
console.error("[crud] failed to update/create payment on order update", payErr);
|
|
6317
|
+
}
|
|
6318
|
+
}
|
|
6319
|
+
const statusUpdated = Boolean(scalarUpdate.status || rawBody.status);
|
|
6320
|
+
const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
|
|
6321
|
+
if (statusUpdated || paymentUpdated) {
|
|
6322
|
+
const newStatus = scalarUpdate.status ? String(scalarUpdate.status).toLowerCase() : rawBody.status ? String(rawBody.status).toLowerCase() : String(updatedOrder.status || "pending").toLowerCase();
|
|
6323
|
+
const payments = Array.isArray(updatedOrder.payments) ? updatedOrder.payments : [];
|
|
6324
|
+
const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
|
|
6325
|
+
const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
|
|
6326
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
6327
|
+
if (newStatus === "pending") {
|
|
6328
|
+
if (curPayStatus === "failed") {
|
|
6329
|
+
fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
|
|
6330
|
+
dataSource,
|
|
6331
|
+
entityMap
|
|
6332
|
+
});
|
|
6333
|
+
} else {
|
|
6334
|
+
fireOrderNotificationTrigger("order_pending", updatedOrder.id, {
|
|
6335
|
+
dataSource,
|
|
6336
|
+
entityMap
|
|
6337
|
+
});
|
|
6338
|
+
}
|
|
6339
|
+
} else if (newStatus === "confirmed") {
|
|
6340
|
+
fireOrderNotificationTrigger("order_placed", updatedOrder.id, {
|
|
6341
|
+
dataSource,
|
|
6342
|
+
entityMap
|
|
6343
|
+
});
|
|
6344
|
+
if (curPayStatus === "paid" || curPayStatus === "captured") {
|
|
6345
|
+
fireOrderNotificationTrigger("payment_success", updatedOrder.id, {
|
|
6346
|
+
dataSource,
|
|
6347
|
+
entityMap
|
|
6348
|
+
});
|
|
6349
|
+
} else if (curPayStatus === "failed") {
|
|
6350
|
+
fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
|
|
6351
|
+
dataSource,
|
|
6352
|
+
entityMap
|
|
6353
|
+
});
|
|
6354
|
+
}
|
|
6355
|
+
} else if (newStatus === "processing") {
|
|
6356
|
+
fireOrderNotificationTrigger("order_processing", updatedOrder.id, {
|
|
6357
|
+
dataSource,
|
|
6358
|
+
entityMap
|
|
6359
|
+
});
|
|
6360
|
+
if (curPayStatus === "failed") {
|
|
6361
|
+
fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
|
|
6362
|
+
dataSource,
|
|
6363
|
+
entityMap
|
|
6364
|
+
});
|
|
6365
|
+
}
|
|
6366
|
+
} else if (newStatus === "completed") {
|
|
6367
|
+
fireOrderNotificationTrigger("order_completed", updatedOrder.id, {
|
|
6368
|
+
dataSource,
|
|
6369
|
+
entityMap
|
|
6370
|
+
});
|
|
6371
|
+
if (curPayStatus === "failed") {
|
|
6372
|
+
fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
|
|
6373
|
+
dataSource,
|
|
6374
|
+
entityMap
|
|
6375
|
+
});
|
|
6376
|
+
}
|
|
6377
|
+
} else if (newStatus === "cancelled") {
|
|
6378
|
+
if (curPayStatus === "failed") {
|
|
6379
|
+
fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
|
|
6380
|
+
dataSource,
|
|
6381
|
+
entityMap
|
|
6382
|
+
});
|
|
6383
|
+
} else {
|
|
6384
|
+
fireOrderNotificationTrigger("order_cancelled", updatedOrder.id, {
|
|
6385
|
+
dataSource,
|
|
6386
|
+
entityMap
|
|
6387
|
+
});
|
|
6388
|
+
if (curPayStatus === "paid" || curPayStatus === "refunded") {
|
|
6389
|
+
fireOrderNotificationTrigger("payment_refund_initiated", updatedOrder.id, {
|
|
6390
|
+
dataSource,
|
|
6391
|
+
entityMap
|
|
6392
|
+
});
|
|
6393
|
+
}
|
|
6394
|
+
}
|
|
6395
|
+
}
|
|
6396
|
+
}).catch(() => {
|
|
6397
|
+
});
|
|
6398
|
+
}
|
|
6133
6399
|
return json(updatedOrder);
|
|
6134
6400
|
}
|
|
6135
6401
|
}
|
|
@@ -6606,7 +6872,37 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6606
6872
|
if (k in merged) updatePayload[k] = merged[k];
|
|
6607
6873
|
}
|
|
6608
6874
|
}
|
|
6609
|
-
if (resource === "orders" && orderInvPrev) {
|
|
6875
|
+
if (resource === "orders" && orderInvPrev && rawBody && typeof rawBody === "object") {
|
|
6876
|
+
if ("assignedUserId" in rawBody && rawBody.assignedUserId !== void 0) {
|
|
6877
|
+
const aId = Number(rawBody.assignedUserId);
|
|
6878
|
+
if (Number.isFinite(aId) && aId > 0) {
|
|
6879
|
+
updatePayload.assignedUserId = aId;
|
|
6880
|
+
updatePayload.assignedAt = /* @__PURE__ */ new Date();
|
|
6881
|
+
if (!updatePayload.status && (orderInvPrev.status === "confirmed" || orderInvPrev.status === "pending")) {
|
|
6882
|
+
updatePayload.status = "processing";
|
|
6883
|
+
}
|
|
6884
|
+
} else {
|
|
6885
|
+
updatePayload.assignedUserId = null;
|
|
6886
|
+
updatePayload.assignedAt = null;
|
|
6887
|
+
}
|
|
6888
|
+
}
|
|
6889
|
+
if (updatePayload.status === "processing") {
|
|
6890
|
+
const effectiveAssignee = updatePayload.assignedUserId !== void 0 ? updatePayload.assignedUserId : orderInvPrev?.assignedUserId;
|
|
6891
|
+
if (!effectiveAssignee) {
|
|
6892
|
+
return json({
|
|
6893
|
+
error: "Cannot start processing without assigning a teammate. Please assign a teammate first."
|
|
6894
|
+
}, {
|
|
6895
|
+
status: 400
|
|
6896
|
+
});
|
|
6897
|
+
}
|
|
6898
|
+
}
|
|
6899
|
+
if (updatePayload.status === "completed" && orderInvPrev.status !== "completed" && !rawBody.__internalBypassOtp) {
|
|
6900
|
+
return json({
|
|
6901
|
+
error: "Direct completion is disabled. Please complete the order via the customer OTP verification flow."
|
|
6902
|
+
}, {
|
|
6903
|
+
status: 400
|
|
6904
|
+
});
|
|
6905
|
+
}
|
|
6610
6906
|
const nextSt = typeof updatePayload.status === "string" && updatePayload.status ? String(updatePayload.status) : orderInvPrev.status;
|
|
6611
6907
|
if (chunkHY3AXLOI_cjs.orderStatusHoldsStock(nextSt) && orderInvPrev.lines.length > 0) {
|
|
6612
6908
|
const verr = await chunkHY3AXLOI_cjs.validateInventoryForOrderBecomingConfirmed(dataSource, entityMap, orderInvPrev, orderInvPrev.lines);
|
|
@@ -6671,24 +6967,43 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6671
6967
|
if (pOrder && Number.isFinite(pOrder)) {
|
|
6672
6968
|
if (newPayStatus === "paid" || newPayStatus === "captured") {
|
|
6673
6969
|
if (entityMap.orders) {
|
|
6674
|
-
|
|
6675
|
-
|
|
6970
|
+
const ordRepo = dataSource.getRepository(entityMap.orders);
|
|
6971
|
+
const currentOrd = await ordRepo.findOne({
|
|
6972
|
+
where: {
|
|
6973
|
+
id: pOrder
|
|
6974
|
+
}
|
|
6676
6975
|
});
|
|
6976
|
+
const ordStatus = String(currentOrd?.status || "pending").toLowerCase();
|
|
6977
|
+
if (ordStatus === "pending") {
|
|
6978
|
+
await ordRepo.update(pOrder, {
|
|
6979
|
+
status: "confirmed"
|
|
6980
|
+
});
|
|
6981
|
+
}
|
|
6982
|
+
if (ordStatus === "pending" || ordStatus === "confirmed") {
|
|
6983
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
6984
|
+
fireOrderNotificationTrigger("order_placed", pOrder, {
|
|
6985
|
+
dataSource,
|
|
6986
|
+
entityMap
|
|
6987
|
+
});
|
|
6988
|
+
fireOrderNotificationTrigger("payment_success", pOrder, {
|
|
6989
|
+
dataSource,
|
|
6990
|
+
entityMap
|
|
6991
|
+
});
|
|
6992
|
+
}).catch(() => {
|
|
6993
|
+
});
|
|
6994
|
+
}
|
|
6677
6995
|
}
|
|
6678
|
-
|
|
6679
|
-
|
|
6680
|
-
|
|
6681
|
-
entityMap
|
|
6682
|
-
});
|
|
6683
|
-
fireOrderNotificationTrigger("payment_success", pOrder, {
|
|
6996
|
+
} else if (newPayStatus === "failed") {
|
|
6997
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
6998
|
+
fireOrderNotificationTrigger("payment_failed", pOrder, {
|
|
6684
6999
|
dataSource,
|
|
6685
7000
|
entityMap
|
|
6686
7001
|
});
|
|
6687
7002
|
}).catch(() => {
|
|
6688
7003
|
});
|
|
6689
|
-
} else if (newPayStatus === "
|
|
6690
|
-
void import('./emit-order-notification-trigger-
|
|
6691
|
-
fireOrderNotificationTrigger("
|
|
7004
|
+
} else if (newPayStatus === "refunded") {
|
|
7005
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
7006
|
+
fireOrderNotificationTrigger("payment_refund_initiated", pOrder, {
|
|
6692
7007
|
dataSource,
|
|
6693
7008
|
entityMap
|
|
6694
7009
|
});
|
|
@@ -6708,6 +7023,52 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6708
7023
|
throw err;
|
|
6709
7024
|
}
|
|
6710
7025
|
}
|
|
7026
|
+
if (resource === "orders" && rawBody && entityMap["payments"]) {
|
|
7027
|
+
try {
|
|
7028
|
+
const bodyPayStatusRaw = rawBody.paymentStatus;
|
|
7029
|
+
if (bodyPayStatusRaw != null && typeof bodyPayStatusRaw === "string") {
|
|
7030
|
+
const payStatus = bodyPayStatusRaw.trim().toLowerCase();
|
|
7031
|
+
const paymentRepo = dataSource.getRepository(entityMap["payments"]);
|
|
7032
|
+
const existingPay = await paymentRepo.findOne({
|
|
7033
|
+
where: {
|
|
7034
|
+
orderId: numericId
|
|
7035
|
+
},
|
|
7036
|
+
order: {
|
|
7037
|
+
id: "DESC"
|
|
7038
|
+
}
|
|
7039
|
+
});
|
|
7040
|
+
const isPaid = payStatus === "paid" || payStatus === "captured";
|
|
7041
|
+
if (existingPay) {
|
|
7042
|
+
await paymentRepo.update(existingPay.id, {
|
|
7043
|
+
status: payStatus,
|
|
7044
|
+
paidAt: isPaid && !existingPay.paidAt ? /* @__PURE__ */ new Date() : existingPay.paidAt
|
|
7045
|
+
});
|
|
7046
|
+
} else {
|
|
7047
|
+
const orderRow = await repo.findOne({
|
|
7048
|
+
where: {
|
|
7049
|
+
id: numericId
|
|
7050
|
+
}
|
|
7051
|
+
});
|
|
7052
|
+
const orderTotal = Number(orderRow?.total ?? 0);
|
|
7053
|
+
const orderCurrency = String(orderRow?.currency ?? "INR");
|
|
7054
|
+
const vId = Number(orderRow?.vendorId ?? 1);
|
|
7055
|
+
const cId = orderRow?.contactId ? Number(orderRow.contactId) : null;
|
|
7056
|
+
await paymentRepo.save(paymentRepo.create({
|
|
7057
|
+
vendorId: vId,
|
|
7058
|
+
contactId: cId,
|
|
7059
|
+
orderId: numericId,
|
|
7060
|
+
status: payStatus,
|
|
7061
|
+
amount: orderTotal,
|
|
7062
|
+
currency: orderCurrency,
|
|
7063
|
+
paidAt: isPaid ? /* @__PURE__ */ new Date() : null,
|
|
7064
|
+
method: "manual"
|
|
7065
|
+
}));
|
|
7066
|
+
}
|
|
7067
|
+
}
|
|
7068
|
+
} catch (payErr) {
|
|
7069
|
+
console.error("[crud] failed to update/create payment on order update", payErr);
|
|
7070
|
+
}
|
|
7071
|
+
}
|
|
6711
7072
|
if (resource === "orders" && rawBody && entityMap["order_addresses"]) {
|
|
6712
7073
|
const addressRawScalar = String(rawBody["contact.address"] ?? "").trim();
|
|
6713
7074
|
if (addressRawScalar) {
|
|
@@ -6746,17 +7107,105 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
|
|
|
6746
7107
|
}
|
|
6747
7108
|
let updated = resource === "orders" ? await repo.findOne({
|
|
6748
7109
|
where: {
|
|
6749
|
-
id: numericId
|
|
6750
|
-
deleted: false
|
|
7110
|
+
id: numericId
|
|
6751
7111
|
},
|
|
6752
7112
|
relations: [
|
|
6753
|
-
"
|
|
7113
|
+
"contact",
|
|
7114
|
+
"billingAddress",
|
|
7115
|
+
"shippingAddress",
|
|
7116
|
+
"items",
|
|
7117
|
+
"items.product",
|
|
7118
|
+
"items.product.collection",
|
|
7119
|
+
"payments"
|
|
6754
7120
|
]
|
|
6755
7121
|
}) : await repo.findOne({
|
|
6756
7122
|
where: {
|
|
6757
7123
|
id: numericId
|
|
6758
7124
|
}
|
|
6759
7125
|
});
|
|
7126
|
+
if (resource === "orders" && updated) {
|
|
7127
|
+
const ord = updated;
|
|
7128
|
+
const statusUpdated = Boolean(updatePayload.status);
|
|
7129
|
+
const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
|
|
7130
|
+
if (statusUpdated || paymentUpdated) {
|
|
7131
|
+
const newStatus = updatePayload.status ? String(updatePayload.status).toLowerCase() : String(ord.status || "pending").toLowerCase();
|
|
7132
|
+
const payments = Array.isArray(ord.payments) ? ord.payments : [];
|
|
7133
|
+
const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
|
|
7134
|
+
const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
|
|
7135
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
7136
|
+
if (newStatus === "pending") {
|
|
7137
|
+
if (curPayStatus === "failed") {
|
|
7138
|
+
fireOrderNotificationTrigger("payment_failed", ord.id, {
|
|
7139
|
+
dataSource,
|
|
7140
|
+
entityMap
|
|
7141
|
+
});
|
|
7142
|
+
} else {
|
|
7143
|
+
fireOrderNotificationTrigger("order_pending", ord.id, {
|
|
7144
|
+
dataSource,
|
|
7145
|
+
entityMap
|
|
7146
|
+
});
|
|
7147
|
+
}
|
|
7148
|
+
} else if (newStatus === "confirmed") {
|
|
7149
|
+
fireOrderNotificationTrigger("order_placed", ord.id, {
|
|
7150
|
+
dataSource,
|
|
7151
|
+
entityMap
|
|
7152
|
+
});
|
|
7153
|
+
if (curPayStatus === "paid" || curPayStatus === "captured") {
|
|
7154
|
+
fireOrderNotificationTrigger("payment_success", ord.id, {
|
|
7155
|
+
dataSource,
|
|
7156
|
+
entityMap
|
|
7157
|
+
});
|
|
7158
|
+
} else if (curPayStatus === "failed") {
|
|
7159
|
+
fireOrderNotificationTrigger("payment_failed", ord.id, {
|
|
7160
|
+
dataSource,
|
|
7161
|
+
entityMap
|
|
7162
|
+
});
|
|
7163
|
+
}
|
|
7164
|
+
} else if (newStatus === "processing") {
|
|
7165
|
+
fireOrderNotificationTrigger("order_processing", ord.id, {
|
|
7166
|
+
dataSource,
|
|
7167
|
+
entityMap
|
|
7168
|
+
});
|
|
7169
|
+
if (curPayStatus === "failed") {
|
|
7170
|
+
fireOrderNotificationTrigger("payment_failed", ord.id, {
|
|
7171
|
+
dataSource,
|
|
7172
|
+
entityMap
|
|
7173
|
+
});
|
|
7174
|
+
}
|
|
7175
|
+
} else if (newStatus === "completed") {
|
|
7176
|
+
fireOrderNotificationTrigger("order_completed", ord.id, {
|
|
7177
|
+
dataSource,
|
|
7178
|
+
entityMap
|
|
7179
|
+
});
|
|
7180
|
+
if (curPayStatus === "failed") {
|
|
7181
|
+
fireOrderNotificationTrigger("payment_failed", ord.id, {
|
|
7182
|
+
dataSource,
|
|
7183
|
+
entityMap
|
|
7184
|
+
});
|
|
7185
|
+
}
|
|
7186
|
+
} else if (newStatus === "cancelled") {
|
|
7187
|
+
if (curPayStatus === "failed") {
|
|
7188
|
+
fireOrderNotificationTrigger("payment_failed", ord.id, {
|
|
7189
|
+
dataSource,
|
|
7190
|
+
entityMap
|
|
7191
|
+
});
|
|
7192
|
+
} else {
|
|
7193
|
+
fireOrderNotificationTrigger("order_cancelled", ord.id, {
|
|
7194
|
+
dataSource,
|
|
7195
|
+
entityMap
|
|
7196
|
+
});
|
|
7197
|
+
if (curPayStatus === "paid" || curPayStatus === "refunded") {
|
|
7198
|
+
fireOrderNotificationTrigger("payment_refund_initiated", ord.id, {
|
|
7199
|
+
dataSource,
|
|
7200
|
+
entityMap
|
|
7201
|
+
});
|
|
7202
|
+
}
|
|
7203
|
+
}
|
|
7204
|
+
}
|
|
7205
|
+
}).catch(() => {
|
|
7206
|
+
});
|
|
7207
|
+
}
|
|
7208
|
+
}
|
|
6760
7209
|
if (resource === "orders" && orderInvPrev && updated) {
|
|
6761
7210
|
const invErr = await chunkHY3AXLOI_cjs.reconcileOrderInventoryBetweenSnapshots(dataSource, entityMap, orderInvPrev, chunkHY3AXLOI_cjs.orderInventorySnapshotFromRow(updated));
|
|
6762
7211
|
if (invErr) return json({
|
|
@@ -8820,25 +9269,79 @@ function createUploadHandler(config) {
|
|
|
8820
9269
|
"application/x-zip-compressed"
|
|
8821
9270
|
];
|
|
8822
9271
|
return /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async function POST(req) {
|
|
9272
|
+
const reqId = `req-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
9273
|
+
console.info("[upload] POST /api/upload start", {
|
|
9274
|
+
reqId,
|
|
9275
|
+
method: req.method,
|
|
9276
|
+
contentType: req.headers.get("content-type"),
|
|
9277
|
+
contentLength: req.headers.get("content-length"),
|
|
9278
|
+
hasStorageConfig: storage != null
|
|
9279
|
+
});
|
|
8823
9280
|
const authErr = await requireAuth(req);
|
|
8824
|
-
if (authErr)
|
|
9281
|
+
if (authErr) {
|
|
9282
|
+
console.error("[upload] auth failed", {
|
|
9283
|
+
reqId,
|
|
9284
|
+
status: authErr.status
|
|
9285
|
+
});
|
|
9286
|
+
return authErr;
|
|
9287
|
+
}
|
|
9288
|
+
console.info("[upload] auth ok", {
|
|
9289
|
+
reqId
|
|
9290
|
+
});
|
|
8825
9291
|
if (requireEntityPermission) {
|
|
8826
9292
|
const pe = await requireEntityPermission(req, "upload", "create");
|
|
8827
|
-
if (pe)
|
|
9293
|
+
if (pe) {
|
|
9294
|
+
console.error("[upload] permission denied", {
|
|
9295
|
+
reqId,
|
|
9296
|
+
status: pe.status
|
|
9297
|
+
});
|
|
9298
|
+
return pe;
|
|
9299
|
+
}
|
|
9300
|
+
console.info("[upload] permission ok", {
|
|
9301
|
+
reqId,
|
|
9302
|
+
entity: "upload",
|
|
9303
|
+
action: "create"
|
|
9304
|
+
});
|
|
8828
9305
|
}
|
|
8829
9306
|
try {
|
|
9307
|
+
console.info("[upload] parsing formData", {
|
|
9308
|
+
reqId
|
|
9309
|
+
});
|
|
8830
9310
|
const formData = await req.formData();
|
|
8831
9311
|
const file = formData.get("file");
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
9312
|
+
console.info("[upload] formData parsed", {
|
|
9313
|
+
reqId,
|
|
9314
|
+
hasFile: Boolean(file),
|
|
9315
|
+
fileName: file?.name ?? null,
|
|
9316
|
+
fileType: file?.type ?? null,
|
|
9317
|
+
fileSize: file?.size ?? null,
|
|
9318
|
+
formKeys: [
|
|
9319
|
+
...formData.keys()
|
|
9320
|
+
]
|
|
8841
9321
|
});
|
|
9322
|
+
if (!file) {
|
|
9323
|
+
console.error("[upload] no file in formData", {
|
|
9324
|
+
reqId
|
|
9325
|
+
});
|
|
9326
|
+
return json({
|
|
9327
|
+
error: "No file uploaded"
|
|
9328
|
+
}, {
|
|
9329
|
+
status: 400
|
|
9330
|
+
});
|
|
9331
|
+
}
|
|
9332
|
+
if (!allowed.includes(file.type)) {
|
|
9333
|
+
console.error("[upload] file type not allowed", {
|
|
9334
|
+
reqId,
|
|
9335
|
+
fileType: file.type,
|
|
9336
|
+
fileName: file.name,
|
|
9337
|
+
allowed
|
|
9338
|
+
});
|
|
9339
|
+
return json({
|
|
9340
|
+
error: "File type not allowed"
|
|
9341
|
+
}, {
|
|
9342
|
+
status: 400
|
|
9343
|
+
});
|
|
9344
|
+
}
|
|
8842
9345
|
const defaultMax = 10 * 1024 * 1024;
|
|
8843
9346
|
const maxZipBytes = 80 * 1024 * 1024;
|
|
8844
9347
|
const maxVideoBytes = 100 * 1024 * 1024;
|
|
@@ -8846,25 +9349,51 @@ function createUploadHandler(config) {
|
|
|
8846
9349
|
const isZip = file.type === "application/zip" || file.type === "application/x-zip-compressed";
|
|
8847
9350
|
const isVideo = file.type === "video/mp4" || file.type === "video/webm" || file.type === "video/quicktime";
|
|
8848
9351
|
const effectiveMax = isZip ? Math.max(baseMax, maxZipBytes) : isVideo ? Math.max(baseMax, maxVideoBytes) : baseMax;
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
9352
|
+
console.info("[upload] size check", {
|
|
9353
|
+
reqId,
|
|
9354
|
+
fileSize: file.size,
|
|
9355
|
+
effectiveMax,
|
|
9356
|
+
isZip,
|
|
9357
|
+
isVideo,
|
|
9358
|
+
isImage: file.type.startsWith("image/")
|
|
8853
9359
|
});
|
|
9360
|
+
if (file.size > effectiveMax) {
|
|
9361
|
+
console.error("[upload] file too large", {
|
|
9362
|
+
reqId,
|
|
9363
|
+
fileSize: file.size,
|
|
9364
|
+
effectiveMax,
|
|
9365
|
+
fileName: file.name
|
|
9366
|
+
});
|
|
9367
|
+
return json({
|
|
9368
|
+
error: "File size exceeds limit"
|
|
9369
|
+
}, {
|
|
9370
|
+
status: 400
|
|
9371
|
+
});
|
|
9372
|
+
}
|
|
8854
9373
|
const parentRaw = formData.get("parentId");
|
|
8855
9374
|
let parentId = null;
|
|
8856
9375
|
if (parentRaw != null && String(parentRaw).trim() !== "") {
|
|
8857
9376
|
const n = Number(parentRaw);
|
|
8858
|
-
if (!Number.isFinite(n))
|
|
8859
|
-
error
|
|
8860
|
-
|
|
8861
|
-
|
|
8862
|
-
|
|
9377
|
+
if (!Number.isFinite(n)) {
|
|
9378
|
+
console.error("[upload] invalid parentId", {
|
|
9379
|
+
reqId,
|
|
9380
|
+
parentRaw
|
|
9381
|
+
});
|
|
9382
|
+
return json({
|
|
9383
|
+
error: "Invalid parentId"
|
|
9384
|
+
}, {
|
|
9385
|
+
status: 400
|
|
9386
|
+
});
|
|
9387
|
+
}
|
|
8863
9388
|
parentId = n;
|
|
8864
9389
|
}
|
|
8865
9390
|
let folder = "";
|
|
8866
9391
|
if (parentId != null) {
|
|
8867
9392
|
if (!dataSource || !entityMap?.media) {
|
|
9393
|
+
console.error("[upload] missing dataSource/entityMap for folder upload", {
|
|
9394
|
+
reqId,
|
|
9395
|
+
parentId
|
|
9396
|
+
});
|
|
8868
9397
|
return json({
|
|
8869
9398
|
error: "Upload handler needs dataSource and entityMap for folder uploads"
|
|
8870
9399
|
}, {
|
|
@@ -8878,6 +9407,12 @@ function createUploadHandler(config) {
|
|
|
8878
9407
|
}
|
|
8879
9408
|
});
|
|
8880
9409
|
if (!p || p.kind !== "folder") {
|
|
9410
|
+
console.error("[upload] parent is not a folder", {
|
|
9411
|
+
reqId,
|
|
9412
|
+
parentId,
|
|
9413
|
+
found: Boolean(p),
|
|
9414
|
+
kind: p ? p.kind : null
|
|
9415
|
+
});
|
|
8881
9416
|
return json({
|
|
8882
9417
|
error: "parent must be a folder"
|
|
8883
9418
|
}, {
|
|
@@ -8885,25 +9420,90 @@ function createUploadHandler(config) {
|
|
|
8885
9420
|
});
|
|
8886
9421
|
}
|
|
8887
9422
|
folder = await relativePathFromMediaParentId(dataSource, entityMap, parentId);
|
|
9423
|
+
console.info("[upload] resolved folder from parentId", {
|
|
9424
|
+
reqId,
|
|
9425
|
+
parentId,
|
|
9426
|
+
folder
|
|
9427
|
+
});
|
|
8888
9428
|
} else {
|
|
8889
9429
|
const folderRawLegacy = formData.get("folder") ?? formData.get("folderPath");
|
|
8890
9430
|
if (folderRawLegacy && typeof folderRawLegacy === "string" && folderRawLegacy.trim()) {
|
|
8891
9431
|
folder = sanitizeMediaFolderPath(folderRawLegacy);
|
|
9432
|
+
console.info("[upload] resolved folder from legacy field", {
|
|
9433
|
+
reqId,
|
|
9434
|
+
folder
|
|
9435
|
+
});
|
|
8892
9436
|
}
|
|
8893
9437
|
}
|
|
9438
|
+
console.info("[upload] reading file into buffer", {
|
|
9439
|
+
reqId,
|
|
9440
|
+
fileName: file.name,
|
|
9441
|
+
fileType: file.type,
|
|
9442
|
+
fileSize: file.size
|
|
9443
|
+
});
|
|
8894
9444
|
const buffer = Buffer.from(await file.arrayBuffer());
|
|
8895
9445
|
const fileName = `${Date.now()}-${file.name}`;
|
|
8896
9446
|
const contentType = file.type || "application/octet-stream";
|
|
8897
9447
|
const relativeUnderUploads = folder ? `${folder}/${fileName}` : fileName;
|
|
9448
|
+
const storageKey = `uploads/${relativeUnderUploads}`;
|
|
9449
|
+
console.info("[upload] S3/storage key prepared", {
|
|
9450
|
+
reqId,
|
|
9451
|
+
originalFileName: file.name,
|
|
9452
|
+
stampedFileName: fileName,
|
|
9453
|
+
folder: folder || "(root)",
|
|
9454
|
+
relativeUnderUploads,
|
|
9455
|
+
storageKey,
|
|
9456
|
+
contentType,
|
|
9457
|
+
bytes: buffer.length
|
|
9458
|
+
});
|
|
8898
9459
|
const raw = typeof storage === "function" ? storage() : storage;
|
|
9460
|
+
console.info("[upload] resolving storage service", {
|
|
9461
|
+
reqId,
|
|
9462
|
+
storageKey,
|
|
9463
|
+
storageIsFunction: typeof storage === "function",
|
|
9464
|
+
rawIsPromise: raw instanceof Promise,
|
|
9465
|
+
rawIsNullish: raw == null
|
|
9466
|
+
});
|
|
8899
9467
|
const storageService = raw instanceof Promise ? await raw : raw;
|
|
9468
|
+
console.info("[upload] storage service resolved", {
|
|
9469
|
+
reqId,
|
|
9470
|
+
storageKey,
|
|
9471
|
+
hasStorageService: Boolean(storageService)
|
|
9472
|
+
});
|
|
8900
9473
|
if (storageService) {
|
|
8901
|
-
|
|
9474
|
+
console.info("[upload] calling storage.upload", {
|
|
9475
|
+
reqId,
|
|
9476
|
+
storageKey,
|
|
9477
|
+
contentType,
|
|
9478
|
+
bytes: buffer.length
|
|
9479
|
+
});
|
|
9480
|
+
const uploadStarted = Date.now();
|
|
9481
|
+
let fileUrl;
|
|
9482
|
+
try {
|
|
9483
|
+
fileUrl = await storageService.upload(buffer, storageKey, contentType);
|
|
9484
|
+
} catch (storageErr) {
|
|
9485
|
+
console.error("[upload] storage.upload threw", {
|
|
9486
|
+
reqId,
|
|
9487
|
+
storageKey,
|
|
9488
|
+
contentType,
|
|
9489
|
+
bytes: buffer.length,
|
|
9490
|
+
ms: Date.now() - uploadStarted,
|
|
9491
|
+
error: storageErr instanceof Error ? storageErr.message : String(storageErr),
|
|
9492
|
+
name: storageErr instanceof Error ? storageErr.name : void 0,
|
|
9493
|
+
stack: storageErr instanceof Error ? storageErr.stack : void 0,
|
|
9494
|
+
code: storageErr && typeof storageErr === "object" && ("Code" in storageErr || "code" in storageErr) ? storageErr.Code ?? storageErr.code : void 0,
|
|
9495
|
+
metadata: storageErr && typeof storageErr === "object" && "$metadata" in storageErr ? storageErr.$metadata : void 0
|
|
9496
|
+
});
|
|
9497
|
+
throw storageErr;
|
|
9498
|
+
}
|
|
8902
9499
|
console.info("[upload] stored via storage plugin", {
|
|
8903
|
-
|
|
9500
|
+
reqId,
|
|
9501
|
+
key: storageKey,
|
|
9502
|
+
fullS3KeyHint: storageKey,
|
|
8904
9503
|
contentType,
|
|
8905
9504
|
bytes: buffer.length,
|
|
8906
|
-
fileUrl
|
|
9505
|
+
fileUrl,
|
|
9506
|
+
ms: Date.now() - uploadStarted
|
|
8907
9507
|
});
|
|
8908
9508
|
return json({
|
|
8909
9509
|
filePath: fileUrl,
|
|
@@ -8911,8 +9511,10 @@ function createUploadHandler(config) {
|
|
|
8911
9511
|
});
|
|
8912
9512
|
}
|
|
8913
9513
|
console.warn("[upload] no storage plugin \u2014 writing local disk (broken on most deploys)", {
|
|
9514
|
+
reqId,
|
|
8914
9515
|
localUploadDir,
|
|
8915
|
-
key: relativeUnderUploads
|
|
9516
|
+
key: relativeUnderUploads,
|
|
9517
|
+
storageKey
|
|
8916
9518
|
});
|
|
8917
9519
|
const fs2 = await import('fs/promises');
|
|
8918
9520
|
const path2 = await import('path');
|
|
@@ -8923,6 +9525,12 @@ function createUploadHandler(config) {
|
|
|
8923
9525
|
});
|
|
8924
9526
|
await fs2.writeFile(filePath, buffer);
|
|
8925
9527
|
const urlRel = `${localUploadDir.replace(/^\/+/, "").replace(/\\/g, "/")}/${relativeUnderUploads.replace(/\\/g, "/")}`;
|
|
9528
|
+
console.info("[upload] local write ok", {
|
|
9529
|
+
reqId,
|
|
9530
|
+
diskPath: filePath,
|
|
9531
|
+
filePath: `/${urlRel}`,
|
|
9532
|
+
key: relativeUnderUploads
|
|
9533
|
+
});
|
|
8926
9534
|
return json({
|
|
8927
9535
|
filePath: `/${urlRel}`,
|
|
8928
9536
|
parentId
|
|
@@ -8931,11 +9539,13 @@ function createUploadHandler(config) {
|
|
|
8931
9539
|
const message = err instanceof Error ? err.message : String(err);
|
|
8932
9540
|
const awsMeta = err && typeof err === "object" && "$metadata" in err ? err.$metadata : void 0;
|
|
8933
9541
|
console.error("[upload] File upload failed", {
|
|
9542
|
+
reqId,
|
|
8934
9543
|
error: message,
|
|
8935
9544
|
stack: err instanceof Error ? err.stack : void 0,
|
|
8936
9545
|
name: err instanceof Error ? err.name : void 0,
|
|
8937
9546
|
code: err && typeof err === "object" && ("Code" in err || "code" in err) ? err.Code ?? err.code : void 0,
|
|
8938
|
-
metadata: awsMeta
|
|
9547
|
+
metadata: awsMeta,
|
|
9548
|
+
raw: err instanceof Error ? void 0 : String(err)
|
|
8939
9549
|
});
|
|
8940
9550
|
if (/Failed to parse body as FormData/i.test(message)) {
|
|
8941
9551
|
return json({
|
|
@@ -9272,13 +9882,43 @@ function createFormSaveHandlers(config) {
|
|
|
9272
9882
|
}
|
|
9273
9883
|
}
|
|
9274
9884
|
if (Object.keys(formRow).length > 0) await formRepo().update(formId, formRow);
|
|
9275
|
-
|
|
9276
|
-
formId
|
|
9277
|
-
});
|
|
9885
|
+
const incomingFieldIds = /* @__PURE__ */ new Set();
|
|
9278
9886
|
for (let i = 0; i < fields.length; i++) {
|
|
9279
|
-
const
|
|
9887
|
+
const f = fields[i];
|
|
9888
|
+
const fieldId = f.id != null && Number.isFinite(Number(f.id)) && Number(f.id) > 0 ? Number(f.id) : null;
|
|
9889
|
+
const row = normalizeFieldRow(f, formId);
|
|
9280
9890
|
row.order = i + 1;
|
|
9281
|
-
|
|
9891
|
+
if (fieldId) {
|
|
9892
|
+
const existingField = await fieldRepo().findOne({
|
|
9893
|
+
where: {
|
|
9894
|
+
id: fieldId,
|
|
9895
|
+
formId
|
|
9896
|
+
}
|
|
9897
|
+
});
|
|
9898
|
+
if (existingField) {
|
|
9899
|
+
incomingFieldIds.add(fieldId);
|
|
9900
|
+
await fieldRepo().update({
|
|
9901
|
+
id: fieldId,
|
|
9902
|
+
formId
|
|
9903
|
+
}, row);
|
|
9904
|
+
continue;
|
|
9905
|
+
}
|
|
9906
|
+
}
|
|
9907
|
+
const created = await fieldRepo().save(fieldRepo().create(row));
|
|
9908
|
+
if (created?.id) incomingFieldIds.add(created.id);
|
|
9909
|
+
}
|
|
9910
|
+
const allCurrentFields = await fieldRepo().find({
|
|
9911
|
+
where: {
|
|
9912
|
+
formId
|
|
9913
|
+
}
|
|
9914
|
+
});
|
|
9915
|
+
for (const existingField of allCurrentFields) {
|
|
9916
|
+
if (!incomingFieldIds.has(existingField.id)) {
|
|
9917
|
+
await fieldRepo().delete({
|
|
9918
|
+
id: existingField.id,
|
|
9919
|
+
formId
|
|
9920
|
+
});
|
|
9921
|
+
}
|
|
9282
9922
|
}
|
|
9283
9923
|
const saved = await formRepo().findOne({
|
|
9284
9924
|
where: {
|
|
@@ -9432,7 +10072,7 @@ function createFormSubmissionListHandler(config) {
|
|
|
9432
10072
|
const limit = Math.min(100, Number(searchParams.get("limit")) || 10);
|
|
9433
10073
|
const skip = (page - 1) * limit;
|
|
9434
10074
|
const sortField = searchParams.get("sortField") || "createdAt";
|
|
9435
|
-
const sortOrder = searchParams.get("sortOrder") === "
|
|
10075
|
+
const sortOrder = searchParams.get("sortOrder") === "asc" ? "ASC" : "DESC";
|
|
9436
10076
|
const [data, total] = await repo.findAndCount({
|
|
9437
10077
|
skip,
|
|
9438
10078
|
take: limit,
|
|
@@ -9611,7 +10251,7 @@ function createFormSubmissionHandler(config) {
|
|
|
9611
10251
|
label: f.label && String(f.label).trim() || `Field ${f.id}`,
|
|
9612
10252
|
value: formatSubmissionFieldValue(data[String(f.id)])
|
|
9613
10253
|
}));
|
|
9614
|
-
await
|
|
10254
|
+
await chunkLRD4CGOG_cjs.queueEmail(cms, {
|
|
9615
10255
|
to,
|
|
9616
10256
|
templateName: "formSubmission",
|
|
9617
10257
|
ctx: {
|
|
@@ -9665,7 +10305,7 @@ function createUsersApiHandlers(config) {
|
|
|
9665
10305
|
try {
|
|
9666
10306
|
const cms = await getCms();
|
|
9667
10307
|
const companyDetails = getCompanyDetails ? await getCompanyDetails() : {};
|
|
9668
|
-
await
|
|
10308
|
+
await chunkLRD4CGOG_cjs.queueEmail(cms, {
|
|
9669
10309
|
to: toEmail,
|
|
9670
10310
|
templateName: "invite",
|
|
9671
10311
|
ctx: {
|
|
@@ -10938,7 +11578,7 @@ function createChatHandlers(config) {
|
|
|
10938
11578
|
const notifyEmailAgent = await findLlmAgentByScope(dataSource, entityMap, LLM_AGENT_SCOPE_EMAIL_INTENT_CHATBOT, {
|
|
10939
11579
|
enabledOnly: false
|
|
10940
11580
|
});
|
|
10941
|
-
const emailTool =
|
|
11581
|
+
const emailTool = chunkTWTISTZB_cjs.resolveChatEmailToolSettings(llmSettings, {
|
|
10942
11582
|
chatbotValidationRules: agentRow?.validationRules ?? null,
|
|
10943
11583
|
notifyAgent: notifyEmailAgent ? {
|
|
10944
11584
|
systemInstruction: notifyEmailAgent.systemInstruction,
|
|
@@ -10948,7 +11588,7 @@ function createChatHandlers(config) {
|
|
|
10948
11588
|
const emailPlugin2 = cms.getPlugin("email");
|
|
10949
11589
|
const convLeadSent = conv.leadEmailSentAt;
|
|
10950
11590
|
const chatAgentFn = llm.chatAgent?.bind(llm);
|
|
10951
|
-
console.info(
|
|
11591
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline check", {
|
|
10952
11592
|
conversationId,
|
|
10953
11593
|
enabled: emailTool.enabled,
|
|
10954
11594
|
intentCount: emailTool.intents.length,
|
|
@@ -10962,27 +11602,27 @@ function createChatHandlers(config) {
|
|
|
10962
11602
|
mergedPromptIncludesNotify: Boolean(notifyEmailAgent?.systemInstruction?.trim())
|
|
10963
11603
|
});
|
|
10964
11604
|
if (!emailTool.enabled) {
|
|
10965
|
-
console.info(
|
|
11605
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10966
11606
|
conversationId,
|
|
10967
11607
|
reason: "email_tool_disabled"
|
|
10968
11608
|
});
|
|
10969
11609
|
} else if (emailTool.intents.length === 0) {
|
|
10970
|
-
console.info(
|
|
11610
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10971
11611
|
conversationId,
|
|
10972
11612
|
reason: "no_intents_configured"
|
|
10973
11613
|
});
|
|
10974
11614
|
} else if (!emailPlugin2) {
|
|
10975
|
-
console.info(
|
|
11615
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10976
11616
|
conversationId,
|
|
10977
11617
|
reason: "email_plugin_missing"
|
|
10978
11618
|
});
|
|
10979
11619
|
} else if (!chatAgentFn) {
|
|
10980
|
-
console.info(
|
|
11620
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10981
11621
|
conversationId,
|
|
10982
11622
|
reason: "llm_chat_agent_unavailable"
|
|
10983
11623
|
});
|
|
10984
11624
|
} else if (convLeadSent) {
|
|
10985
|
-
console.info(
|
|
11625
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10986
11626
|
conversationId,
|
|
10987
11627
|
reason: "lead_email_already_sent",
|
|
10988
11628
|
leadEmailSentAt: convLeadSent
|
|
@@ -10995,7 +11635,7 @@ function createChatHandlers(config) {
|
|
|
10995
11635
|
}
|
|
10996
11636
|
});
|
|
10997
11637
|
if (!contactRow) {
|
|
10998
|
-
console.warn(
|
|
11638
|
+
console.warn(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10999
11639
|
conversationId,
|
|
11000
11640
|
reason: "contact_not_found",
|
|
11001
11641
|
contactId
|
|
@@ -11003,7 +11643,7 @@ function createChatHandlers(config) {
|
|
|
11003
11643
|
} else {
|
|
11004
11644
|
const c = contactRow;
|
|
11005
11645
|
try {
|
|
11006
|
-
const intent = await
|
|
11646
|
+
const intent = await chunkTWTISTZB_cjs.detectChatLeadIntent({
|
|
11007
11647
|
chatAgent: chatAgentFn
|
|
11008
11648
|
}, {
|
|
11009
11649
|
settings: emailTool,
|
|
@@ -11017,15 +11657,15 @@ function createChatHandlers(config) {
|
|
|
11017
11657
|
model: agentRow?.model?.trim() || notifyEmailAgent?.model?.trim() || void 0
|
|
11018
11658
|
});
|
|
11019
11659
|
if (!intent.intent || !intent.emailTo) {
|
|
11020
|
-
console.info(
|
|
11660
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "no email sent", {
|
|
11021
11661
|
conversationId,
|
|
11022
11662
|
reason: intent.intent ? "missing_email_to" : "no_intent_match",
|
|
11023
11663
|
intentLabel: intent.intentLabel,
|
|
11024
11664
|
classifierReason: intent.reason
|
|
11025
11665
|
});
|
|
11026
11666
|
} else {
|
|
11027
|
-
const intentRecipients =
|
|
11028
|
-
console.info(
|
|
11667
|
+
const intentRecipients = chunkTWTISTZB_cjs.parseIntentRecipientEmails(intent.emailTo);
|
|
11668
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
|
|
11029
11669
|
conversationId,
|
|
11030
11670
|
intent: intent.intent,
|
|
11031
11671
|
emailTo: intent.emailTo,
|
|
@@ -11034,8 +11674,8 @@ function createChatHandlers(config) {
|
|
|
11034
11674
|
});
|
|
11035
11675
|
const emailSettings = await loadSettingsGroupMap(dataSource, entityMap, "email");
|
|
11036
11676
|
const brandingSettings = await loadSettingsGroupMap(dataSource, entityMap, "branding");
|
|
11037
|
-
const companyDetails =
|
|
11038
|
-
const leadResult = await
|
|
11677
|
+
const companyDetails = chunkCTIEAHQL_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings);
|
|
11678
|
+
const leadResult = await chunkTWTISTZB_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
|
|
11039
11679
|
contactName: String(c.name ?? "").trim() || "Visitor",
|
|
11040
11680
|
contactEmail: String(c.email ?? "").trim(),
|
|
11041
11681
|
contactPhone: c.phone ?? null,
|
|
@@ -11043,7 +11683,7 @@ function createChatHandlers(config) {
|
|
|
11043
11683
|
latestMessage: message,
|
|
11044
11684
|
intentCode: intent.intent,
|
|
11045
11685
|
intentReason: intent.intentLabel || intent.reason,
|
|
11046
|
-
transcript:
|
|
11686
|
+
transcript: chunkTWTISTZB_cjs.buildTranscriptForLeadEmail(history, message),
|
|
11047
11687
|
companyDetails,
|
|
11048
11688
|
recipients: intentRecipients.length > 0 ? intentRecipients : void 0
|
|
11049
11689
|
});
|
|
@@ -11051,13 +11691,13 @@ function createChatHandlers(config) {
|
|
|
11051
11691
|
await convRepo().update(conversationId, {
|
|
11052
11692
|
leadEmailSentAt: /* @__PURE__ */ new Date()
|
|
11053
11693
|
});
|
|
11054
|
-
console.info(
|
|
11694
|
+
console.info(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
|
|
11055
11695
|
conversationId,
|
|
11056
11696
|
sent: true,
|
|
11057
11697
|
recipients: leadResult.recipients
|
|
11058
11698
|
});
|
|
11059
11699
|
} else {
|
|
11060
|
-
console.warn(
|
|
11700
|
+
console.warn(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
|
|
11061
11701
|
conversationId,
|
|
11062
11702
|
sent: false,
|
|
11063
11703
|
error: leadResult.error ?? "unknown",
|
|
@@ -11066,7 +11706,7 @@ function createChatHandlers(config) {
|
|
|
11066
11706
|
}
|
|
11067
11707
|
}
|
|
11068
11708
|
} catch (intentErr) {
|
|
11069
|
-
console.warn(
|
|
11709
|
+
console.warn(chunkTWTISTZB_cjs.CHAT_EMAIL_LOG, "pipeline error", {
|
|
11070
11710
|
conversationId,
|
|
11071
11711
|
error: intentErr instanceof Error ? intentErr.message : String(intentErr)
|
|
11072
11712
|
});
|
|
@@ -11083,7 +11723,7 @@ function createChatHandlers(config) {
|
|
|
11083
11723
|
});
|
|
11084
11724
|
if (agentRow && llm.chatAgent) {
|
|
11085
11725
|
const fromAgent = llmAgentToChatAgentOptions(agentRow);
|
|
11086
|
-
const systemPrompt =
|
|
11726
|
+
const systemPrompt = chunkTWTISTZB_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
|
|
11087
11727
|
const res = await llm.chatAgent({
|
|
11088
11728
|
...fromAgent,
|
|
11089
11729
|
systemPrompt: systemPrompt || void 0,
|
|
@@ -11104,7 +11744,7 @@ ${contextParts.join("\n\n")}` : "";
|
|
|
11104
11744
|
agentRow.systemInstruction?.trim(),
|
|
11105
11745
|
ragSystem
|
|
11106
11746
|
].filter(Boolean).join("\n\n");
|
|
11107
|
-
systemContent =
|
|
11747
|
+
systemContent = chunkTWTISTZB_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
|
|
11108
11748
|
} else {
|
|
11109
11749
|
systemContent = ragSystem || defaultSystem;
|
|
11110
11750
|
}
|
|
@@ -12359,7 +12999,7 @@ function createDeviceTokensHandlers(config) {
|
|
|
12359
12999
|
const title = body.title?.trim() || "Test Push Notification";
|
|
12360
13000
|
const msgBody = body.body?.trim() || "Firebase Push Notification setup is working!";
|
|
12361
13001
|
if (!token || token === "validate" || token === "validate_only") {
|
|
12362
|
-
const valRes = await
|
|
13002
|
+
const valRes = await chunkTWTISTZB_cjs.validateFcmCredentials(dataSource, entityMap);
|
|
12363
13003
|
if (!valRes.success) {
|
|
12364
13004
|
return json({
|
|
12365
13005
|
success: false,
|
|
@@ -12376,7 +13016,7 @@ function createDeviceTokensHandlers(config) {
|
|
|
12376
13016
|
clientEmail: valRes.clientEmail
|
|
12377
13017
|
});
|
|
12378
13018
|
}
|
|
12379
|
-
const res = await
|
|
13019
|
+
const res = await chunkTWTISTZB_cjs.sendFcmPushNotification(dataSource, entityMap, {
|
|
12380
13020
|
token,
|
|
12381
13021
|
title,
|
|
12382
13022
|
body: msgBody,
|
|
@@ -13370,8 +14010,8 @@ async function sendVendorOnboardEmails(input, deps) {
|
|
|
13370
14010
|
getSuperAdminEmails(deps),
|
|
13371
14011
|
getVendorEmails(deps)
|
|
13372
14012
|
]);
|
|
13373
|
-
const companyDetails =
|
|
13374
|
-
const configuredNotify =
|
|
14013
|
+
const companyDetails = chunkCTIEAHQL_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings);
|
|
14014
|
+
const configuredNotify = chunkTWTISTZB_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
|
|
13375
14015
|
const ownerEmail = input.ownerEmail?.trim() || "";
|
|
13376
14016
|
const ownerEmailLower = ownerEmail.toLowerCase();
|
|
13377
14017
|
const sendToOwner = input.sendToOwner !== false;
|
|
@@ -13381,7 +14021,7 @@ async function sendVendorOnboardEmails(input, deps) {
|
|
|
13381
14021
|
];
|
|
13382
14022
|
const notifyEmails = Array.from(new Set(combined.map((e) => e.trim().toLowerCase()).filter((e) => e && e !== ownerEmailLower && !vendorEmailSet.has(e))));
|
|
13383
14023
|
const cms = await deps.getCms();
|
|
13384
|
-
await
|
|
14024
|
+
await chunkLRD4CGOG_cjs.queueVendorOnboardEmails(cms, {
|
|
13385
14025
|
vendorName: input.vendorName,
|
|
13386
14026
|
vendorSlug: input.vendorSlug,
|
|
13387
14027
|
ownerName: input.ownerName,
|
|
@@ -18047,6 +18687,9 @@ exports.Order = class Order {
|
|
|
18047
18687
|
customerContact;
|
|
18048
18688
|
billingAddress;
|
|
18049
18689
|
shippingAddress;
|
|
18690
|
+
assignedUserId;
|
|
18691
|
+
assignedAt;
|
|
18692
|
+
assignedUser;
|
|
18050
18693
|
items;
|
|
18051
18694
|
payments;
|
|
18052
18695
|
};
|
|
@@ -18259,6 +18902,29 @@ _ts_decorate21([
|
|
|
18259
18902
|
}),
|
|
18260
18903
|
_ts_metadata21("design:type", Object)
|
|
18261
18904
|
], exports.Order.prototype, "shippingAddress", void 0);
|
|
18905
|
+
_ts_decorate21([
|
|
18906
|
+
typeorm.Column("int", {
|
|
18907
|
+
nullable: true
|
|
18908
|
+
}),
|
|
18909
|
+
_ts_metadata21("design:type", Object)
|
|
18910
|
+
], exports.Order.prototype, "assignedUserId", void 0);
|
|
18911
|
+
_ts_decorate21([
|
|
18912
|
+
typeorm.Column({
|
|
18913
|
+
type: "timestamp",
|
|
18914
|
+
nullable: true
|
|
18915
|
+
}),
|
|
18916
|
+
_ts_metadata21("design:type", Object)
|
|
18917
|
+
], exports.Order.prototype, "assignedAt", void 0);
|
|
18918
|
+
_ts_decorate21([
|
|
18919
|
+
typeorm.ManyToOne(() => exports.User, {
|
|
18920
|
+
nullable: true,
|
|
18921
|
+
onDelete: "SET NULL"
|
|
18922
|
+
}),
|
|
18923
|
+
typeorm.JoinColumn({
|
|
18924
|
+
name: "assignedUserId"
|
|
18925
|
+
}),
|
|
18926
|
+
_ts_metadata21("design:type", Object)
|
|
18927
|
+
], exports.Order.prototype, "assignedUser", void 0);
|
|
18262
18928
|
_ts_decorate21([
|
|
18263
18929
|
typeorm.OneToMany("OrderItem", "order"),
|
|
18264
18930
|
_ts_metadata21("design:type", Array)
|
|
@@ -24290,6 +24956,7 @@ var NotificationChannel = /* @__PURE__ */ (function(NotificationChannel2) {
|
|
|
24290
24956
|
NotificationChannel2["WHATSAPP"] = "whatsapp";
|
|
24291
24957
|
NotificationChannel2["EMAIL"] = "email";
|
|
24292
24958
|
NotificationChannel2["MOBILE"] = "mobile";
|
|
24959
|
+
NotificationChannel2["SMS"] = "sms";
|
|
24293
24960
|
return NotificationChannel2;
|
|
24294
24961
|
})({});
|
|
24295
24962
|
var NotificationAudienceType = /* @__PURE__ */ (function(NotificationAudienceType2) {
|
|
@@ -27944,21 +28611,37 @@ function whatsappPlugin(config = {}) {
|
|
|
27944
28611
|
async init(context) {
|
|
27945
28612
|
const env = context.config;
|
|
27946
28613
|
const { getWhatsAppSettings, getMessageTemplateRow, ...staticRest } = config;
|
|
28614
|
+
let settingsLoader = getWhatsAppSettings;
|
|
28615
|
+
if (!settingsLoader && context.dataSource) {
|
|
28616
|
+
settingsLoader = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
|
|
28617
|
+
try {
|
|
28618
|
+
const ds = context.dataSource;
|
|
28619
|
+
const repo = ds.getRepository("configs");
|
|
28620
|
+
const rows = await repo.find({
|
|
28621
|
+
where: {
|
|
28622
|
+
settings: "whatsapp",
|
|
28623
|
+
deleted: false
|
|
28624
|
+
}
|
|
28625
|
+
});
|
|
28626
|
+
return Object.fromEntries(rows.map((r) => [
|
|
28627
|
+
r.key,
|
|
28628
|
+
r.value
|
|
28629
|
+
]));
|
|
28630
|
+
} catch {
|
|
28631
|
+
return {};
|
|
28632
|
+
}
|
|
28633
|
+
}, "settingsLoader");
|
|
28634
|
+
}
|
|
27947
28635
|
let db = {};
|
|
27948
28636
|
try {
|
|
27949
|
-
db = await
|
|
28637
|
+
db = await settingsLoader?.() ?? {};
|
|
27950
28638
|
} catch {
|
|
27951
28639
|
}
|
|
27952
|
-
if (!
|
|
28640
|
+
if (!chunkTWTISTZB_cjs.isWhatsAppPluginEnabled(db)) {
|
|
27953
28641
|
context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
|
|
27954
28642
|
return null;
|
|
27955
28643
|
}
|
|
27956
|
-
const
|
|
27957
|
-
if (!getWhatsAppSettings && !chunkYSYX4GUD_cjs.whatsAppConfigured(merged)) {
|
|
27958
|
-
context.logger.warn("WhatsApp plugin skipped: set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID, or pass getWhatsAppSettings");
|
|
27959
|
-
return null;
|
|
27960
|
-
}
|
|
27961
|
-
const svc = new chunkYSYX4GUD_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
|
|
28644
|
+
const svc = new chunkTWTISTZB_cjs.WhatsAppService(env, staticRest, settingsLoader, getMessageTemplateRow);
|
|
27962
28645
|
return {
|
|
27963
28646
|
send: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((opts) => svc.send(opts), "send")
|
|
27964
28647
|
};
|
|
@@ -28031,11 +28714,11 @@ function createMessageTemplateRowLoader(dataSource, entityMap) {
|
|
|
28031
28714
|
}
|
|
28032
28715
|
chunkUSNT2KNT_cjs.__name(createMessageTemplateRowLoader, "createMessageTemplateRowLoader");
|
|
28033
28716
|
function registerMessagingQueueProcessors(cms, entityMap) {
|
|
28034
|
-
|
|
28717
|
+
chunkLRD4CGOG_cjs.registerEmailQueueProcessor(cms, {
|
|
28035
28718
|
getDataSource: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => cms.dataSource, "getDataSource"),
|
|
28036
28719
|
entityMap
|
|
28037
28720
|
});
|
|
28038
|
-
|
|
28721
|
+
chunkH3IVLIPR_cjs.registerWhatsAppQueueProcessor(cms);
|
|
28039
28722
|
}
|
|
28040
28723
|
chunkUSNT2KNT_cjs.__name(registerMessagingQueueProcessors, "registerMessagingQueueProcessors");
|
|
28041
28724
|
async function ensureMessagingPluginsOnCms(base, options) {
|
|
@@ -28064,7 +28747,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
|
|
|
28064
28747
|
}
|
|
28065
28748
|
if (!cms.getPlugin("email")) {
|
|
28066
28749
|
try {
|
|
28067
|
-
const instance = await
|
|
28750
|
+
const instance = await chunkTWTISTZB_cjs.emailPlugin({
|
|
28068
28751
|
type: "SMTP",
|
|
28069
28752
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
28070
28753
|
to: config.SMTP_TO ?? ""
|
|
@@ -28105,7 +28788,7 @@ function messagingPlugins(options) {
|
|
|
28105
28788
|
const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
|
|
28106
28789
|
return [
|
|
28107
28790
|
queuePlugin(),
|
|
28108
|
-
|
|
28791
|
+
chunkTWTISTZB_cjs.emailPlugin({
|
|
28109
28792
|
type: "SMTP",
|
|
28110
28793
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
28111
28794
|
to: config.SMTP_TO ?? ""
|
|
@@ -28239,7 +28922,7 @@ function createCmsApiHandler(config) {
|
|
|
28239
28922
|
} : void 0;
|
|
28240
28923
|
const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
|
|
28241
28924
|
if (getCms) {
|
|
28242
|
-
|
|
28925
|
+
chunkTWTISTZB_cjs.initWhatsappTriggerDispatcher({
|
|
28243
28926
|
dataSource,
|
|
28244
28927
|
entityMap,
|
|
28245
28928
|
getCms
|
|
@@ -28332,7 +29015,7 @@ function createCmsApiHandler(config) {
|
|
|
28332
29015
|
companyDetails
|
|
28333
29016
|
};
|
|
28334
29017
|
if (queue) {
|
|
28335
|
-
const { queueEmail: queueEmail2 } = await import('./email-queue-
|
|
29018
|
+
const { queueEmail: queueEmail2 } = await import('./email-queue-J7DXYNCE.cjs');
|
|
28336
29019
|
await queueEmail2(cms, {
|
|
28337
29020
|
to: opts.to,
|
|
28338
29021
|
templateName: "passwordReset",
|
|
@@ -29632,7 +30315,7 @@ function createCmsApiHandler(config) {
|
|
|
29632
30315
|
const pe = await requireEntityPermissionEffective(req, "orders", "read");
|
|
29633
30316
|
if (pe) return pe;
|
|
29634
30317
|
const cms = await getCms();
|
|
29635
|
-
const { streamOrderInvoicePdf: streamOrderInvoicePdf2 } = await import('./erp-order-invoice-
|
|
30318
|
+
const { streamOrderInvoicePdf: streamOrderInvoicePdf2 } = await import('./erp-order-invoice-C5GZCOBM.cjs');
|
|
29636
30319
|
const oid = Number(path2[1]);
|
|
29637
30320
|
if (!Number.isFinite(oid)) return config.json({
|
|
29638
30321
|
error: "Invalid id"
|
|
@@ -29781,6 +30464,11 @@ function createCmsApiHandler(config) {
|
|
|
29781
30464
|
});
|
|
29782
30465
|
}
|
|
29783
30466
|
}
|
|
30467
|
+
if (path2[0] === "sms-notification-templates" && path2.length === 1 && m === "GET") {
|
|
30468
|
+
const { createSmsNotificationTemplatesHandlers } = await import('./sms-notification-templates-handlers-YSB3L2PK.cjs');
|
|
30469
|
+
const handlers = createSmsNotificationTemplatesHandlers(dataSource, entityMap);
|
|
30470
|
+
return handlers.GET(req);
|
|
30471
|
+
}
|
|
29784
30472
|
if (path2[0] === "orders" && path2[1] === "calculate" && path2.length === 2 && m === "POST") {
|
|
29785
30473
|
const a = await config.requireAuth(req);
|
|
29786
30474
|
if (a) return a;
|
|
@@ -30009,7 +30697,7 @@ function createCmsApiHandler(config) {
|
|
|
30009
30697
|
status: 400
|
|
30010
30698
|
});
|
|
30011
30699
|
}
|
|
30012
|
-
const { resendOrderNotification } = await import('./order-notification-dispatcher-
|
|
30700
|
+
const { resendOrderNotification } = await import('./order-notification-dispatcher-X2XM5VUY.cjs');
|
|
30013
30701
|
const result = await resendOrderNotification(triggerKey, orderId, {
|
|
30014
30702
|
dataSource,
|
|
30015
30703
|
entityMap,
|
|
@@ -30108,25 +30796,20 @@ function createCmsApiHandler(config) {
|
|
|
30108
30796
|
status: "cancelled"
|
|
30109
30797
|
});
|
|
30110
30798
|
const fireOrderCancelledNotification = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((refundAmount) => {
|
|
30111
|
-
void import('./emit-order-notification-trigger-
|
|
30799
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
30112
30800
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
30113
30801
|
dataSource,
|
|
30114
30802
|
entityMap
|
|
30115
30803
|
}, refundAmount != null && refundAmount > 0 ? {
|
|
30116
30804
|
refundAmount
|
|
30117
30805
|
} : void 0);
|
|
30118
|
-
if (paymentStatus === "paid" || paymentStatus === "captured") {
|
|
30806
|
+
if (paymentStatus === "paid" || paymentStatus === "captured" || paymentStatus === "refunded") {
|
|
30119
30807
|
fireOrderNotificationTrigger("payment_refund_initiated", orderId, {
|
|
30120
30808
|
dataSource,
|
|
30121
30809
|
entityMap
|
|
30122
30810
|
}, refundAmount != null && refundAmount > 0 ? {
|
|
30123
30811
|
refundAmount
|
|
30124
30812
|
} : void 0);
|
|
30125
|
-
} else {
|
|
30126
|
-
fireOrderNotificationTrigger("payment_failed", orderId, {
|
|
30127
|
-
dataSource,
|
|
30128
|
-
entityMap
|
|
30129
|
-
});
|
|
30130
30813
|
}
|
|
30131
30814
|
});
|
|
30132
30815
|
}, "fireOrderCancelledNotification");
|
|
@@ -30347,6 +31030,66 @@ function createCmsApiHandler(config) {
|
|
|
30347
31030
|
finalRefund: 0
|
|
30348
31031
|
});
|
|
30349
31032
|
}
|
|
31033
|
+
if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "channels" && m === "GET" && getCms) {
|
|
31034
|
+
const a = await config.requireAuth(req);
|
|
31035
|
+
if (a) return a;
|
|
31036
|
+
const pe = await requireEntityPermissionEffective(req, "orders", "read");
|
|
31037
|
+
if (pe) return pe;
|
|
31038
|
+
const orderId = Number(path2[1]);
|
|
31039
|
+
if (!Number.isFinite(orderId)) return config.json({
|
|
31040
|
+
error: "Invalid order ID"
|
|
31041
|
+
}, {
|
|
31042
|
+
status: 400
|
|
31043
|
+
});
|
|
31044
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-4EOLYLAP.cjs');
|
|
31045
|
+
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31046
|
+
return handlers.getChannels(req, orderId);
|
|
31047
|
+
}
|
|
31048
|
+
if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "send" && m === "POST" && getCms) {
|
|
31049
|
+
const a = await config.requireAuth(req);
|
|
31050
|
+
if (a) return a;
|
|
31051
|
+
const pe = await requireEntityPermissionEffective(req, "orders", "update");
|
|
31052
|
+
if (pe) return pe;
|
|
31053
|
+
const orderId = Number(path2[1]);
|
|
31054
|
+
if (!Number.isFinite(orderId)) return config.json({
|
|
31055
|
+
error: "Invalid order ID"
|
|
31056
|
+
}, {
|
|
31057
|
+
status: 400
|
|
31058
|
+
});
|
|
31059
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-4EOLYLAP.cjs');
|
|
31060
|
+
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31061
|
+
return handlers.sendOtp(req, orderId);
|
|
31062
|
+
}
|
|
31063
|
+
if (path2[0] === "orders" && path2.length === 4 && path2[2] === "completion-otp" && path2[3] === "verify" && m === "POST" && getCms) {
|
|
31064
|
+
const a = await config.requireAuth(req);
|
|
31065
|
+
if (a) return a;
|
|
31066
|
+
const pe = await requireEntityPermissionEffective(req, "orders", "update");
|
|
31067
|
+
if (pe) return pe;
|
|
31068
|
+
const orderId = Number(path2[1]);
|
|
31069
|
+
if (!Number.isFinite(orderId)) return config.json({
|
|
31070
|
+
error: "Invalid order ID"
|
|
31071
|
+
}, {
|
|
31072
|
+
status: 400
|
|
31073
|
+
});
|
|
31074
|
+
const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-4EOLYLAP.cjs');
|
|
31075
|
+
const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms);
|
|
31076
|
+
return handlers.verifyOtp(req, orderId);
|
|
31077
|
+
}
|
|
31078
|
+
if (path2[0] === "orders" && path2.length === 3 && path2[2] === "eligible-assignees" && m === "GET") {
|
|
31079
|
+
const a = await config.requireAuth(req);
|
|
31080
|
+
if (a) return a;
|
|
31081
|
+
const pe = await requireEntityPermissionEffective(req, "orders", "read");
|
|
31082
|
+
if (pe) return pe;
|
|
31083
|
+
const orderId = Number(path2[1]);
|
|
31084
|
+
if (!Number.isFinite(orderId)) return config.json({
|
|
31085
|
+
error: "Invalid order ID"
|
|
31086
|
+
}, {
|
|
31087
|
+
status: 400
|
|
31088
|
+
});
|
|
31089
|
+
const { createOrderAssigneesHandlers } = await import('./order-assignees-handlers-NPKD64P6.cjs');
|
|
31090
|
+
const handlers = createOrderAssigneesHandlers(dataSource, entityMap, getHydratedSessionUser);
|
|
31091
|
+
return handlers.listEligibleAssignees(req, orderId);
|
|
31092
|
+
}
|
|
30350
31093
|
if (path2[0] === "refund-policies") {
|
|
30351
31094
|
if (path2.length === 1) {
|
|
30352
31095
|
if (m === "GET") {
|
|
@@ -30776,12 +31519,12 @@ async function refreshOrderFromErp(cms, dataSource, entityMap, submission, order
|
|
|
30776
31519
|
const r1 = await submission.postErpReadAction("get-order-status", {
|
|
30777
31520
|
platformOrderId: refId
|
|
30778
31521
|
});
|
|
30779
|
-
const d1 = r1.ok ?
|
|
31522
|
+
const d1 = r1.ok ? chunkAXMP2U43_cjs.unwrapErpReadData(r1.json) : null;
|
|
30780
31523
|
if (d1) {
|
|
30781
31524
|
const mapped = mapErpSaleStatusToOrderStatus(typeof d1.status === "string" ? d1.status : typeof d1.orderStatus === "string" ? d1.orderStatus : typeof d1.state === "string" ? d1.state : void 0);
|
|
30782
31525
|
if (mapped) newStatus = mapped;
|
|
30783
|
-
fulfillment =
|
|
30784
|
-
const refs =
|
|
31526
|
+
fulfillment = chunkAXMP2U43_cjs.mapErpPayloadToFulfillment(d1);
|
|
31527
|
+
const refs = chunkAXMP2U43_cjs.extractChildOrderRefsFromSalePayload(d1);
|
|
30785
31528
|
if (refs.length) {
|
|
30786
31529
|
await ensureChildOrdersFromRefs(orderRepo, order, refs, order.contactId, String(order.currency || "INR"));
|
|
30787
31530
|
}
|
|
@@ -30789,16 +31532,16 @@ async function refreshOrderFromErp(cms, dataSource, entityMap, submission, order
|
|
|
30789
31532
|
const r2 = await submission.postErpReadAction("get-fulfillment-status", {
|
|
30790
31533
|
platformOrderId: refId
|
|
30791
31534
|
});
|
|
30792
|
-
const d2 = r2.ok ?
|
|
31535
|
+
const d2 = r2.ok ? chunkAXMP2U43_cjs.unwrapErpReadData(r2.json) : null;
|
|
30793
31536
|
if (d2) {
|
|
30794
|
-
fulfillment = deepMergeFulfillment(fulfillment,
|
|
31537
|
+
fulfillment = deepMergeFulfillment(fulfillment, chunkAXMP2U43_cjs.mapErpPayloadToFulfillment(d2));
|
|
30795
31538
|
}
|
|
30796
31539
|
const r3 = await submission.postErpReadAction("get-invoice", {
|
|
30797
31540
|
platformOrderId: refId
|
|
30798
31541
|
});
|
|
30799
|
-
const d3 = r3.ok ?
|
|
31542
|
+
const d3 = r3.ok ? chunkAXMP2U43_cjs.unwrapErpReadData(r3.json) : null;
|
|
30800
31543
|
if (d3) {
|
|
30801
|
-
invoiceNumber =
|
|
31544
|
+
invoiceNumber = chunkAXMP2U43_cjs.mapErpPayloadToInvoiceNumber(d3);
|
|
30802
31545
|
invoiceId = pickInvoiceId(d3);
|
|
30803
31546
|
}
|
|
30804
31547
|
const oid = order.id;
|
|
@@ -30834,10 +31577,10 @@ async function refreshOrderFromErp(cms, dataSource, entityMap, submission, order
|
|
|
30834
31577
|
const r = await submission.postErpReadAction("get-return-status", {
|
|
30835
31578
|
platformReturnId
|
|
30836
31579
|
});
|
|
30837
|
-
const d = r.ok ?
|
|
31580
|
+
const d = r.ok ? chunkAXMP2U43_cjs.unwrapErpReadData(r.json) : null;
|
|
30838
31581
|
if (!d) return;
|
|
30839
31582
|
const mapped = mapErpSaleStatusToOrderStatus(typeof d.status === "string" ? d.status : typeof d.returnStatus === "string" ? d.returnStatus : void 0);
|
|
30840
|
-
const fulfillment =
|
|
31583
|
+
const fulfillment = chunkAXMP2U43_cjs.mapErpPayloadToFulfillment(d);
|
|
30841
31584
|
const patch = {};
|
|
30842
31585
|
if (fulfillment !== void 0) patch.fulfillment = fulfillment;
|
|
30843
31586
|
const nextMeta = Object.keys(patch).length ? mergeOrderMetadataPatch(meta, patch) : meta;
|
|
@@ -30863,63 +31606,6 @@ async function tryRefreshOrderFromErpForStorefront(cms, dataSource, entityMap, o
|
|
|
30863
31606
|
}
|
|
30864
31607
|
chunkUSNT2KNT_cjs.__name(tryRefreshOrderFromErpForStorefront, "tryRefreshOrderFromErpForStorefront");
|
|
30865
31608
|
|
|
30866
|
-
// src/plugins/sms/sms-queue.ts
|
|
30867
|
-
var SMS_QUEUE_NAME = "sms";
|
|
30868
|
-
function registerSmsQueueProcessor(cms) {
|
|
30869
|
-
const queue = cms.getPlugin("queue");
|
|
30870
|
-
const sms = cms.getPlugin("sms");
|
|
30871
|
-
if (!queue || !sms || typeof sms.send !== "function") return;
|
|
30872
|
-
queue.registerProcessor(SMS_QUEUE_NAME, async (data) => {
|
|
30873
|
-
const payload = data;
|
|
30874
|
-
if (!payload.to) return;
|
|
30875
|
-
if (payload.templateKey?.trim()) {
|
|
30876
|
-
await sms.send({
|
|
30877
|
-
to: payload.to,
|
|
30878
|
-
templateKey: payload.templateKey.trim(),
|
|
30879
|
-
variables: payload.variables,
|
|
30880
|
-
otpCode: payload.otpCode
|
|
30881
|
-
});
|
|
30882
|
-
return;
|
|
30883
|
-
}
|
|
30884
|
-
if (!payload.body?.trim()) return;
|
|
30885
|
-
await sms.send({
|
|
30886
|
-
to: payload.to,
|
|
30887
|
-
body: payload.body,
|
|
30888
|
-
otpCode: payload.otpCode,
|
|
30889
|
-
variables: payload.variables
|
|
30890
|
-
});
|
|
30891
|
-
});
|
|
30892
|
-
}
|
|
30893
|
-
chunkUSNT2KNT_cjs.__name(registerSmsQueueProcessor, "registerSmsQueueProcessor");
|
|
30894
|
-
async function queueSms(cms, payload) {
|
|
30895
|
-
const queue = cms.getPlugin("queue");
|
|
30896
|
-
const sms = cms.getPlugin("sms");
|
|
30897
|
-
if (queue) {
|
|
30898
|
-
await queue.add(SMS_QUEUE_NAME, payload);
|
|
30899
|
-
return;
|
|
30900
|
-
}
|
|
30901
|
-
if (sms && typeof sms.send === "function") {
|
|
30902
|
-
if (payload.templateKey?.trim()) {
|
|
30903
|
-
await sms.send({
|
|
30904
|
-
to: payload.to,
|
|
30905
|
-
templateKey: payload.templateKey.trim(),
|
|
30906
|
-
variables: payload.variables,
|
|
30907
|
-
otpCode: payload.otpCode
|
|
30908
|
-
});
|
|
30909
|
-
return;
|
|
30910
|
-
}
|
|
30911
|
-
if (payload.body?.trim()) {
|
|
30912
|
-
await sms.send({
|
|
30913
|
-
to: payload.to,
|
|
30914
|
-
body: payload.body,
|
|
30915
|
-
otpCode: payload.otpCode,
|
|
30916
|
-
variables: payload.variables
|
|
30917
|
-
});
|
|
30918
|
-
}
|
|
30919
|
-
}
|
|
30920
|
-
}
|
|
30921
|
-
chunkUSNT2KNT_cjs.__name(queueSms, "queueSms");
|
|
30922
|
-
|
|
30923
31609
|
// src/lib/storefront-product-pricing.ts
|
|
30924
31610
|
function eventPricingFromRow(row) {
|
|
30925
31611
|
const defaultCurrency = normalizeCurrencyCode(String(row?.defaultCurrency ?? "INR")) || "INR";
|
|
@@ -30988,143 +31674,6 @@ async function buildPricesForSupportedCurrencies(dataSource, entityMap, basePric
|
|
|
30988
31674
|
return rows;
|
|
30989
31675
|
}
|
|
30990
31676
|
chunkUSNT2KNT_cjs.__name(buildPricesForSupportedCurrencies, "buildPricesForSupportedCurrencies");
|
|
30991
|
-
var OTP_TTL_MS = 10 * 60 * 1e3;
|
|
30992
|
-
var MAX_SENDS_PER_HOUR = 5;
|
|
30993
|
-
var MAX_VERIFY_ATTEMPTS = 8;
|
|
30994
|
-
function getPepper(explicit) {
|
|
30995
|
-
return (explicit || process.env.OTP_PEPPER || process.env.NEXTAUTH_SECRET || "dev-otp-pepper").trim();
|
|
30996
|
-
}
|
|
30997
|
-
chunkUSNT2KNT_cjs.__name(getPepper, "getPepper");
|
|
30998
|
-
function hashOtpCode(code, purpose, identifier, pepper) {
|
|
30999
|
-
return crypto2.createHmac("sha256", getPepper(pepper)).update(`${purpose}|${identifier}|${code}`).digest("hex");
|
|
31000
|
-
}
|
|
31001
|
-
chunkUSNT2KNT_cjs.__name(hashOtpCode, "hashOtpCode");
|
|
31002
|
-
function verifyOtpCodeHash(code, storedHash, purpose, identifier, pepper) {
|
|
31003
|
-
const h = hashOtpCode(code, purpose, identifier, pepper);
|
|
31004
|
-
try {
|
|
31005
|
-
return crypto2.timingSafeEqual(Buffer.from(h, "utf8"), Buffer.from(storedHash, "utf8"));
|
|
31006
|
-
} catch {
|
|
31007
|
-
return false;
|
|
31008
|
-
}
|
|
31009
|
-
}
|
|
31010
|
-
chunkUSNT2KNT_cjs.__name(verifyOtpCodeHash, "verifyOtpCodeHash");
|
|
31011
|
-
function generateNumericOtp(length = 6) {
|
|
31012
|
-
const max = 10 ** length;
|
|
31013
|
-
return crypto2.randomInt(0, max).toString().padStart(length, "0");
|
|
31014
|
-
}
|
|
31015
|
-
chunkUSNT2KNT_cjs.__name(generateNumericOtp, "generateNumericOtp");
|
|
31016
|
-
function normalizePhoneE164(raw, defaultCountryCode) {
|
|
31017
|
-
const t = raw.trim();
|
|
31018
|
-
const digitsOnly = t.replace(/\D/g, "");
|
|
31019
|
-
if (digitsOnly.length < 10) return null;
|
|
31020
|
-
if (t.startsWith("+")) return `+${digitsOnly}`;
|
|
31021
|
-
const cc = (defaultCountryCode || process.env.DEFAULT_PHONE_COUNTRY_CODE || "91").replace(/\D/g, "");
|
|
31022
|
-
if (digitsOnly.length > 10) return `+${digitsOnly}`;
|
|
31023
|
-
return `+${cc}${digitsOnly}`;
|
|
31024
|
-
}
|
|
31025
|
-
chunkUSNT2KNT_cjs.__name(normalizePhoneE164, "normalizePhoneE164");
|
|
31026
|
-
async function countRecentOtpSends(dataSource, entityMap, purpose, identifier, since) {
|
|
31027
|
-
const repo = dataSource.getRepository(entityMap.otp_challenges);
|
|
31028
|
-
return repo.count({
|
|
31029
|
-
where: {
|
|
31030
|
-
purpose,
|
|
31031
|
-
identifier,
|
|
31032
|
-
createdAt: typeorm.MoreThan(since)
|
|
31033
|
-
}
|
|
31034
|
-
});
|
|
31035
|
-
}
|
|
31036
|
-
chunkUSNT2KNT_cjs.__name(countRecentOtpSends, "countRecentOtpSends");
|
|
31037
|
-
async function createOtpChallenge(dataSource, entityMap, input) {
|
|
31038
|
-
const { purpose, channel, identifier, code, pepper } = input;
|
|
31039
|
-
const since = new Date(Date.now() - 60 * 60 * 1e3);
|
|
31040
|
-
const recent = await countRecentOtpSends(dataSource, entityMap, purpose, identifier, since);
|
|
31041
|
-
if (recent >= MAX_SENDS_PER_HOUR) {
|
|
31042
|
-
return {
|
|
31043
|
-
ok: false,
|
|
31044
|
-
error: "Too many codes sent. Try again later.",
|
|
31045
|
-
status: 429
|
|
31046
|
-
};
|
|
31047
|
-
}
|
|
31048
|
-
const repo = dataSource.getRepository(entityMap.otp_challenges);
|
|
31049
|
-
await repo.delete({
|
|
31050
|
-
purpose,
|
|
31051
|
-
identifier,
|
|
31052
|
-
consumedAt: typeorm.IsNull()
|
|
31053
|
-
});
|
|
31054
|
-
const expiresAt = new Date(Date.now() + OTP_TTL_MS);
|
|
31055
|
-
const codeHash = hashOtpCode(code, purpose, identifier, pepper);
|
|
31056
|
-
await repo.save(repo.create({
|
|
31057
|
-
purpose,
|
|
31058
|
-
channel,
|
|
31059
|
-
identifier,
|
|
31060
|
-
codeHash,
|
|
31061
|
-
expiresAt,
|
|
31062
|
-
attempts: 0,
|
|
31063
|
-
consumedAt: null
|
|
31064
|
-
}));
|
|
31065
|
-
return {
|
|
31066
|
-
ok: true
|
|
31067
|
-
};
|
|
31068
|
-
}
|
|
31069
|
-
chunkUSNT2KNT_cjs.__name(createOtpChallenge, "createOtpChallenge");
|
|
31070
|
-
async function verifyAndConsumeOtpChallenge(dataSource, entityMap, input) {
|
|
31071
|
-
const { purpose, identifier, code, pepper } = input;
|
|
31072
|
-
const repo = dataSource.getRepository(entityMap.otp_challenges);
|
|
31073
|
-
const row = await repo.findOne({
|
|
31074
|
-
where: {
|
|
31075
|
-
purpose,
|
|
31076
|
-
identifier,
|
|
31077
|
-
consumedAt: typeorm.IsNull()
|
|
31078
|
-
},
|
|
31079
|
-
order: {
|
|
31080
|
-
id: "DESC"
|
|
31081
|
-
}
|
|
31082
|
-
});
|
|
31083
|
-
if (!row) {
|
|
31084
|
-
return {
|
|
31085
|
-
ok: false,
|
|
31086
|
-
error: "Invalid or expired code",
|
|
31087
|
-
status: 400
|
|
31088
|
-
};
|
|
31089
|
-
}
|
|
31090
|
-
const r = row;
|
|
31091
|
-
if (new Date(r.expiresAt) < /* @__PURE__ */ new Date()) {
|
|
31092
|
-
await repo.delete(row.id);
|
|
31093
|
-
return {
|
|
31094
|
-
ok: false,
|
|
31095
|
-
error: "Invalid or expired code",
|
|
31096
|
-
status: 400
|
|
31097
|
-
};
|
|
31098
|
-
}
|
|
31099
|
-
const attempts = r.attempts || 0;
|
|
31100
|
-
if (attempts >= MAX_VERIFY_ATTEMPTS) {
|
|
31101
|
-
await repo.delete(row.id);
|
|
31102
|
-
return {
|
|
31103
|
-
ok: false,
|
|
31104
|
-
error: "Too many attempts",
|
|
31105
|
-
status: 400
|
|
31106
|
-
};
|
|
31107
|
-
}
|
|
31108
|
-
const valid = verifyOtpCodeHash(code, r.codeHash, purpose, identifier, pepper);
|
|
31109
|
-
if (!valid) {
|
|
31110
|
-
await repo.update(row.id, {
|
|
31111
|
-
attempts: attempts + 1
|
|
31112
|
-
});
|
|
31113
|
-
return {
|
|
31114
|
-
ok: false,
|
|
31115
|
-
error: "Invalid or expired code",
|
|
31116
|
-
status: 400
|
|
31117
|
-
};
|
|
31118
|
-
}
|
|
31119
|
-
await repo.update(row.id, {
|
|
31120
|
-
consumedAt: /* @__PURE__ */ new Date(),
|
|
31121
|
-
attempts: attempts + 1
|
|
31122
|
-
});
|
|
31123
|
-
return {
|
|
31124
|
-
ok: true
|
|
31125
|
-
};
|
|
31126
|
-
}
|
|
31127
|
-
chunkUSNT2KNT_cjs.__name(verifyAndConsumeOtpChallenge, "verifyAndConsumeOtpChallenge");
|
|
31128
31677
|
|
|
31129
31678
|
// src/api/storefront-handlers.ts
|
|
31130
31679
|
var GUEST_COOKIE = "guest_id";
|
|
@@ -31154,7 +31703,7 @@ function createStorefrontApiHandler(config) {
|
|
|
31154
31703
|
const otpPepper = config.otpPepper;
|
|
31155
31704
|
const defaultPhoneCc = config.defaultPhoneCountryCode;
|
|
31156
31705
|
function fireOrderPlacedNotification(orderId, isPaid) {
|
|
31157
|
-
void import('./emit-order-notification-trigger-
|
|
31706
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
31158
31707
|
fireOrderNotificationTrigger("order_placed", orderId, {
|
|
31159
31708
|
dataSource,
|
|
31160
31709
|
entityMap
|
|
@@ -31204,7 +31753,7 @@ function createStorefrontApiHandler(config) {
|
|
|
31204
31753
|
const meta = it.metadata && typeof it.metadata === "object" && !Array.isArray(it.metadata) ? it.metadata : {};
|
|
31205
31754
|
const fromMeta = Number(meta.comboId ?? meta.combo_id);
|
|
31206
31755
|
if (Number.isInteger(fromMeta) && fromMeta > 0) return fromMeta;
|
|
31207
|
-
if (meta.isCombo === true || meta.type === "combo" || meta.lineType === "combo") {
|
|
31756
|
+
if (meta.isCombo === true || meta.type === "combo" || meta.lineType === "combo" || meta.lineKind === "combo" || meta.itemType === "combo") {
|
|
31208
31757
|
const pid = Number(it.productId);
|
|
31209
31758
|
if (Number.isInteger(pid) && pid > 0) return pid;
|
|
31210
31759
|
}
|
|
@@ -31225,9 +31774,21 @@ function createStorefrontApiHandler(config) {
|
|
|
31225
31774
|
},
|
|
31226
31775
|
select: [
|
|
31227
31776
|
"id",
|
|
31228
|
-
"vendorId"
|
|
31777
|
+
"vendorId",
|
|
31778
|
+
"eventId"
|
|
31229
31779
|
]
|
|
31230
31780
|
});
|
|
31781
|
+
const comboEventId = Number(combo?.eventId);
|
|
31782
|
+
if (Number.isInteger(comboEventId) && comboEventId > 0 && entityMap.events) {
|
|
31783
|
+
const evRows = await dataSource.query(`SELECT "vendorId" FROM events WHERE id = $1 AND deleted = false LIMIT 1`, [
|
|
31784
|
+
comboEventId
|
|
31785
|
+
]);
|
|
31786
|
+
const evVid = Number(evRows[0]?.vendorId);
|
|
31787
|
+
if (Number.isInteger(evVid) && evVid > 0) {
|
|
31788
|
+
comboVendorCache.set(comboId, evVid);
|
|
31789
|
+
return evVid;
|
|
31790
|
+
}
|
|
31791
|
+
}
|
|
31231
31792
|
const vid = Number(combo?.vendorId);
|
|
31232
31793
|
if (Number.isInteger(vid) && vid > 0) {
|
|
31233
31794
|
comboVendorCache.set(comboId, vid);
|
|
@@ -31247,9 +31808,30 @@ function createStorefrontApiHandler(config) {
|
|
|
31247
31808
|
}
|
|
31248
31809
|
const p = it.product;
|
|
31249
31810
|
if (!p || p.deleted || p.status !== "available") continue;
|
|
31250
|
-
|
|
31811
|
+
let vid = Number(p.vendorId);
|
|
31812
|
+
if (!Number.isInteger(vid) || vid <= 0) {
|
|
31813
|
+
const prodId = Number(p.id);
|
|
31814
|
+
if (Number.isInteger(prodId) && prodId > 0 && entityMap.event_products) {
|
|
31815
|
+
const epRows = await dataSource.query(`SELECT e."vendorId" FROM event_products ep
|
|
31816
|
+
JOIN events e ON e.id = ep."eventId"
|
|
31817
|
+
WHERE ep."productId" = $1 AND e.deleted = false LIMIT 1`, [
|
|
31818
|
+
prodId
|
|
31819
|
+
]);
|
|
31820
|
+
const evVid = Number(epRows[0]?.vendorId);
|
|
31821
|
+
if (Number.isInteger(evVid) && evVid > 0) vid = evVid;
|
|
31822
|
+
}
|
|
31823
|
+
}
|
|
31251
31824
|
if (Number.isInteger(vid) && vid > 0) vendorIds.add(vid);
|
|
31252
31825
|
}
|
|
31826
|
+
if (vendorIds.size > 1) {
|
|
31827
|
+
const nonDefault = [
|
|
31828
|
+
...vendorIds
|
|
31829
|
+
].filter((id) => id !== 1);
|
|
31830
|
+
if (nonDefault.length === 1) {
|
|
31831
|
+
vendorIds.clear();
|
|
31832
|
+
vendorIds.add(nonDefault[0]);
|
|
31833
|
+
}
|
|
31834
|
+
}
|
|
31253
31835
|
if (vendorIds.size === 0) return {
|
|
31254
31836
|
error: "Cart has no valid products",
|
|
31255
31837
|
status: 400
|
|
@@ -32710,7 +33292,7 @@ function createStorefrontApiHandler(config) {
|
|
|
32710
33292
|
status: 403
|
|
32711
33293
|
});
|
|
32712
33294
|
}
|
|
32713
|
-
const p = normalizePhoneE164(phoneIn, defaultPhoneCc);
|
|
33295
|
+
const p = chunkWFMVD567_cjs.normalizePhoneE164(phoneIn, defaultPhoneCc);
|
|
32714
33296
|
if (!p) return json({
|
|
32715
33297
|
error: "Invalid phone"
|
|
32716
33298
|
}, {
|
|
@@ -32763,7 +33345,7 @@ function createStorefrontApiHandler(config) {
|
|
|
32763
33345
|
}, {
|
|
32764
33346
|
status: 401
|
|
32765
33347
|
});
|
|
32766
|
-
const p = normalizePhoneE164(phoneIn, defaultPhoneCc);
|
|
33348
|
+
const p = chunkWFMVD567_cjs.normalizePhoneE164(phoneIn, defaultPhoneCc);
|
|
32767
33349
|
if (!p) return json({
|
|
32768
33350
|
error: "Valid phone required"
|
|
32769
33351
|
}, {
|
|
@@ -32787,8 +33369,8 @@ function createStorefrontApiHandler(config) {
|
|
|
32787
33369
|
});
|
|
32788
33370
|
}
|
|
32789
33371
|
}
|
|
32790
|
-
const code = generateNumericOtp(6);
|
|
32791
|
-
const created = await createOtpChallenge(dataSource, entityMap, {
|
|
33372
|
+
const code = chunkWFMVD567_cjs.generateNumericOtp(6);
|
|
33373
|
+
const created = await chunkWFMVD567_cjs.createOtpChallenge(dataSource, entityMap, {
|
|
32792
33374
|
purpose,
|
|
32793
33375
|
channel,
|
|
32794
33376
|
identifier,
|
|
@@ -32814,7 +33396,7 @@ function createStorefrontApiHandler(config) {
|
|
|
32814
33396
|
status: 503
|
|
32815
33397
|
});
|
|
32816
33398
|
const companyDetails = getCompanyDetails ? await getCompanyDetails() : {};
|
|
32817
|
-
await
|
|
33399
|
+
await chunkLRD4CGOG_cjs.queueEmail(cms, {
|
|
32818
33400
|
to: identifier,
|
|
32819
33401
|
templateName: "otp",
|
|
32820
33402
|
ctx: {
|
|
@@ -32829,7 +33411,7 @@ function createStorefrontApiHandler(config) {
|
|
|
32829
33411
|
status: 503
|
|
32830
33412
|
});
|
|
32831
33413
|
const templateKey = purpose === "verify_phone" ? "auth.otp_verify_phone" : "auth.otp_login";
|
|
32832
|
-
await queueSms(cms, {
|
|
33414
|
+
await chunkWFMVD567_cjs.queueSms(cms, {
|
|
32833
33415
|
to: identifier,
|
|
32834
33416
|
templateKey,
|
|
32835
33417
|
variables: {
|
|
@@ -32862,7 +33444,7 @@ function createStorefrontApiHandler(config) {
|
|
|
32862
33444
|
}, {
|
|
32863
33445
|
status: 400
|
|
32864
33446
|
});
|
|
32865
|
-
const v = await verifyAndConsumeOtpChallenge(dataSource, entityMap, {
|
|
33447
|
+
const v = await chunkWFMVD567_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
|
|
32866
33448
|
purpose: "verify_email",
|
|
32867
33449
|
identifier: email,
|
|
32868
33450
|
code,
|
|
@@ -32912,13 +33494,13 @@ function createStorefrontApiHandler(config) {
|
|
|
32912
33494
|
const b = await req.json().catch(() => ({}));
|
|
32913
33495
|
const phoneRaw = typeof b.phone === "string" ? b.phone.trim() : "";
|
|
32914
33496
|
const code = typeof b.code === "string" ? b.code.trim() : "";
|
|
32915
|
-
const phone = normalizePhoneE164(phoneRaw, defaultPhoneCc);
|
|
33497
|
+
const phone = chunkWFMVD567_cjs.normalizePhoneE164(phoneRaw, defaultPhoneCc);
|
|
32916
33498
|
if (!phone || !code) return json({
|
|
32917
33499
|
error: "phone and code required"
|
|
32918
33500
|
}, {
|
|
32919
33501
|
status: 400
|
|
32920
33502
|
});
|
|
32921
|
-
const v = await verifyAndConsumeOtpChallenge(dataSource, entityMap, {
|
|
33503
|
+
const v = await chunkWFMVD567_cjs.verifyAndConsumeOtpChallenge(dataSource, entityMap, {
|
|
32922
33504
|
purpose: "verify_phone",
|
|
32923
33505
|
identifier: phone,
|
|
32924
33506
|
code,
|
|
@@ -33039,7 +33621,7 @@ function createStorefrontApiHandler(config) {
|
|
|
33039
33621
|
const companyDetails = getCompanyDetails ? await getCompanyDetails() : {};
|
|
33040
33622
|
const base = (publicSiteUrl || "").replace(/\/$/, "").trim() || "http://localhost:3000";
|
|
33041
33623
|
const verifyEmailUrl = `${base}/verify-email?token=${encodeURIComponent(rawToken)}`;
|
|
33042
|
-
await
|
|
33624
|
+
await chunkLRD4CGOG_cjs.queueEmail(cms, {
|
|
33043
33625
|
to: email,
|
|
33044
33626
|
templateName: "signup",
|
|
33045
33627
|
ctx: {
|
|
@@ -33333,7 +33915,10 @@ function createStorefrontApiHandler(config) {
|
|
|
33333
33915
|
});
|
|
33334
33916
|
if (existing) {
|
|
33335
33917
|
await cartItemRepo().update(existing.id, {
|
|
33336
|
-
quantity:
|
|
33918
|
+
quantity: gi.quantity,
|
|
33919
|
+
...gi.metadata ? {
|
|
33920
|
+
metadata: gi.metadata
|
|
33921
|
+
} : {}
|
|
33337
33922
|
});
|
|
33338
33923
|
} else {
|
|
33339
33924
|
await cartItemRepo().save(cartItemRepo().create({
|
|
@@ -33848,7 +34433,7 @@ function createStorefrontApiHandler(config) {
|
|
|
33848
34433
|
status: 400
|
|
33849
34434
|
});
|
|
33850
34435
|
const cms = await getCms();
|
|
33851
|
-
return
|
|
34436
|
+
return chunkAXMP2U43_cjs.streamOrderInvoicePdf(cms, dataSource, entityMap, orderId, {
|
|
33852
34437
|
ownerContactId: contact.id
|
|
33853
34438
|
});
|
|
33854
34439
|
}
|
|
@@ -34055,7 +34640,7 @@ function createStorefrontApiHandler(config) {
|
|
|
34055
34640
|
} catch {
|
|
34056
34641
|
}
|
|
34057
34642
|
try {
|
|
34058
|
-
void import('./emit-order-notification-trigger-
|
|
34643
|
+
void import('./emit-order-notification-trigger-K7URAZHJ.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
34059
34644
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
34060
34645
|
dataSource,
|
|
34061
34646
|
entityMap
|
|
@@ -34129,7 +34714,6 @@ exports.completeUserInviteAccept = completeUserInviteAccept;
|
|
|
34129
34714
|
exports.consumeAppliedDiscountUsages = consumeAppliedDiscountUsages;
|
|
34130
34715
|
exports.contactIsVendorCustomer = contactIsVendorCustomer;
|
|
34131
34716
|
exports.countDiscountOrdersForContact = countDiscountOrdersForContact;
|
|
34132
|
-
exports.countRecentOtpSends = countRecentOtpSends;
|
|
34133
34717
|
exports.createAnalyticsHandlers = createAnalyticsHandlers;
|
|
34134
34718
|
exports.createBlogBySlugHandler = createBlogBySlugHandler;
|
|
34135
34719
|
exports.createChangePasswordHandler = createChangePasswordHandler;
|
|
@@ -34148,7 +34732,6 @@ exports.createJobScheduleHandlers = createJobScheduleHandlers;
|
|
|
34148
34732
|
exports.createLlmAgentKnowledgeHandlers = createLlmAgentKnowledgeHandlers;
|
|
34149
34733
|
exports.createMediaZipExtractHandler = createMediaZipExtractHandler;
|
|
34150
34734
|
exports.createMessageTemplateRowLoader = createMessageTemplateRowLoader;
|
|
34151
|
-
exports.createOtpChallenge = createOtpChallenge;
|
|
34152
34735
|
exports.createSetPasswordHandler = createSetPasswordHandler;
|
|
34153
34736
|
exports.createSettingsApiHandlers = createSettingsApiHandlers;
|
|
34154
34737
|
exports.createSocialMediaHandlers = createSocialMediaHandlers;
|
|
@@ -34171,13 +34754,11 @@ exports.findActiveRefundPolicyForVendor = findActiveRefundPolicyForVendor;
|
|
|
34171
34754
|
exports.findUserByInviteToken = findUserByInviteToken;
|
|
34172
34755
|
exports.findVendorByInviteToken = findVendorByInviteToken;
|
|
34173
34756
|
exports.formatTierRange = formatTierRange;
|
|
34174
|
-
exports.generateNumericOtp = generateNumericOtp;
|
|
34175
34757
|
exports.getPublicSettingsGroup = getPublicSettingsGroup;
|
|
34176
34758
|
exports.getRequireEventApproval = getRequireEventApproval;
|
|
34177
34759
|
exports.getRequireProductApproval = getRequireProductApproval;
|
|
34178
34760
|
exports.getRssArticleSummaryFromItem = getRssArticleSummaryFromItem;
|
|
34179
34761
|
exports.getVendorCatalogCreateFlags = getVendorCatalogCreateFlags;
|
|
34180
|
-
exports.hashOtpCode = hashOtpCode;
|
|
34181
34762
|
exports.hydrateVendorSessionUser = hydrateVendorSessionUser;
|
|
34182
34763
|
exports.invalidateEventsCache = invalidateEventsCache;
|
|
34183
34764
|
exports.invalidateMultiVendorCache = invalidateMultiVendorCache;
|
|
@@ -34198,7 +34779,6 @@ exports.metaPostPageFeed = metaPostPageFeed;
|
|
|
34198
34779
|
exports.metaPostPagePhoto = metaPostPagePhoto;
|
|
34199
34780
|
exports.metaResolvePageAccessToken = metaResolvePageAccessToken;
|
|
34200
34781
|
exports.newUserInviteToken = newUserInviteToken;
|
|
34201
|
-
exports.normalizePhoneE164 = normalizePhoneE164;
|
|
34202
34782
|
exports.normalizeRefundTiers = normalizeRefundTiers;
|
|
34203
34783
|
exports.overlayCmsPlugins = overlayCmsPlugins;
|
|
34204
34784
|
exports.parseBlogGeneratorAgentContent = parseBlogGeneratorAgentContent;
|
|
@@ -34209,11 +34789,9 @@ exports.pgBossScheduleNameForId = pgBossScheduleNameForId;
|
|
|
34209
34789
|
exports.queueErpCreateContactIfEnabled = queueErpCreateContactIfEnabled;
|
|
34210
34790
|
exports.queueJobScheduleNow = queueJobScheduleNow;
|
|
34211
34791
|
exports.queuePlugin = queuePlugin;
|
|
34212
|
-
exports.queueSms = queueSms;
|
|
34213
34792
|
exports.recordDiscountUsage = recordDiscountUsage;
|
|
34214
34793
|
exports.registerJobRunnerWorker = registerJobRunnerWorker;
|
|
34215
34794
|
exports.registerMessagingQueueProcessors = registerMessagingQueueProcessors;
|
|
34216
|
-
exports.registerSmsQueueProcessor = registerSmsQueueProcessor;
|
|
34217
34795
|
exports.relativePathFromMediaParentId = relativePathFromMediaParentId;
|
|
34218
34796
|
exports.resolveBlogCategoryIdByName = resolveBlogCategoryIdByName;
|
|
34219
34797
|
exports.resolveSettingsEncryptionKey = resolveSettingsEncryptionKey;
|
|
@@ -34228,7 +34806,5 @@ exports.validateRefundTiers = validateRefundTiers;
|
|
|
34228
34806
|
exports.validateScheduleInput = validateScheduleInput;
|
|
34229
34807
|
exports.validateUserMessageAgainstAgentRules = validateUserMessageAgainstAgentRules;
|
|
34230
34808
|
exports.validateUserMessageAgainstStructuredRules = validateUserMessageAgainstStructuredRules;
|
|
34231
|
-
exports.verifyAndConsumeOtpChallenge = verifyAndConsumeOtpChallenge;
|
|
34232
|
-
exports.verifyOtpCodeHash = verifyOtpCodeHash;
|
|
34233
34809
|
exports.whatsappPlugin = whatsappPlugin;
|
|
34234
34810
|
exports.wrapGetCmsWithMessaging = wrapGetCmsWithMessaging;
|