@infuro/cms-core 1.0.73 → 1.0.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/admin.cjs +37 -12
  2. package/dist/admin.js +37 -12
  3. package/dist/api.cjs +37 -37
  4. package/dist/api.js +5 -5
  5. package/dist/{chunk-BQQMTQ4C.cjs → chunk-25T6HP5T.cjs} +2 -2
  6. package/dist/{chunk-TTOEY7AH.cjs → chunk-2JV4EDY3.cjs} +3 -3
  7. package/dist/{chunk-LJ5C4RBF.js → chunk-6TRH3VY7.js} +1 -1
  8. package/dist/{chunk-4MNVIGVJ.cjs → chunk-D3SR6CYU.cjs} +3 -3
  9. package/dist/{chunk-PQJIJ4ZX.js → chunk-DAUBLBTP.js} +1 -1
  10. package/dist/{chunk-HQ3A43HO.cjs → chunk-H4UIIBFD.cjs} +139 -84
  11. package/dist/{chunk-YHVA5NHI.js → chunk-LUSJITTI.js} +43 -6
  12. package/dist/{chunk-4LF5OGBF.js → chunk-OQOO2JMB.js} +96 -41
  13. package/dist/{chunk-HZZTDM5J.js → chunk-R5HLPH6P.js} +1 -1
  14. package/dist/{chunk-3LF4RYAJ.js → chunk-X3IJG25M.js} +1 -1
  15. package/dist/{chunk-2JHGIWH7.cjs → chunk-X5ILLSTD.cjs} +43 -6
  16. package/dist/{chunk-NIBEGDD4.cjs → chunk-ZBSH4GWB.cjs} +1 -1
  17. package/dist/{email-queue-MWP4R67H.js → email-queue-5TOJJT3P.js} +3 -3
  18. package/dist/{email-queue-BJDH2ID7.cjs → email-queue-X2A46VD3.cjs} +7 -7
  19. package/dist/{emit-order-notification-trigger-TBXAZAPS.js → emit-order-notification-trigger-3RAVWKLG.js} +1 -1
  20. package/dist/{emit-order-notification-trigger-I4HQSTEN.cjs → emit-order-notification-trigger-MY3KP7CD.cjs} +3 -3
  21. package/dist/{erp-order-invoice-5O42ZKC5.cjs → erp-order-invoice-23BDWC2H.cjs} +6 -6
  22. package/dist/{erp-order-invoice-JEQKFXG4.js → erp-order-invoice-SEZZUDMW.js} +2 -2
  23. package/dist/generate-local-invoice-pdf-V5FHS23Z.js +3 -0
  24. package/dist/{generate-local-invoice-pdf-2NCA2WBL.cjs → generate-local-invoice-pdf-XYBVKHNP.cjs} +2 -2
  25. package/dist/index.cjs +232 -232
  26. package/dist/index.js +9 -9
  27. package/dist/{order-completion-otp-handlers-KHLZQQJX.js → order-completion-otp-handlers-2WOFSORP.js} +4 -4
  28. package/dist/{order-completion-otp-handlers-2ZKRK5SN.cjs → order-completion-otp-handlers-EWY47XUA.cjs} +6 -6
  29. package/dist/{order-notification-dispatcher-Z3MXNF4U.js → order-notification-dispatcher-COR2ZHM3.js} +4 -4
  30. package/dist/{order-notification-dispatcher-37KDVHBM.cjs → order-notification-dispatcher-KTOAMMSD.cjs} +9 -9
  31. package/package.json +1 -1
  32. package/dist/generate-local-invoice-pdf-XUH6GYEJ.js +0 -3
@@ -2369,6 +2369,41 @@ function wrapText(text, font, size, maxWidth) {
2369
2369
  return lines.slice(0, 4);
2370
2370
  }
2371
2371
  __name(wrapText, "wrapText");
2372
+ function wrapLinesToWidth(lines, font, size, maxWidth) {
2373
+ const result = [];
2374
+ for (const rawLine of lines) {
2375
+ if (!rawLine || !rawLine.trim()) continue;
2376
+ const words = winAnsiSafe(rawLine).split(/\s+/).filter(Boolean);
2377
+ if (!words.length) continue;
2378
+ let current = "";
2379
+ for (let word of words) {
2380
+ while (font.widthOfTextAtSize(word, size) > maxWidth) {
2381
+ let cut = word.length - 1;
2382
+ while (cut > 0 && font.widthOfTextAtSize(word.slice(0, cut), size) > maxWidth) {
2383
+ cut--;
2384
+ }
2385
+ if (cut <= 0) cut = 1;
2386
+ const head = word.slice(0, cut);
2387
+ if (current) {
2388
+ result.push(current);
2389
+ current = "";
2390
+ }
2391
+ result.push(head);
2392
+ word = word.slice(cut);
2393
+ }
2394
+ const candidate = current ? `${current} ${word}` : word;
2395
+ if (font.widthOfTextAtSize(candidate, size) <= maxWidth) {
2396
+ current = candidate;
2397
+ } else {
2398
+ if (current) result.push(current);
2399
+ current = word;
2400
+ }
2401
+ }
2402
+ if (current) result.push(current);
2403
+ }
2404
+ return result;
2405
+ }
2406
+ __name(wrapLinesToWidth, "wrapLinesToWidth");
2372
2407
  async function tryEmbedLogo(doc, logoUrl, maxW, maxH) {
2373
2408
  const url = String(logoUrl ?? "").trim();
2374
2409
  if (!url || !/^https?:\/\//i.test(url)) return null;
@@ -2532,21 +2567,23 @@ async function generateLocalInvoicePdf(input) {
2532
2567
  drawText(page, "Bill to", margin, y, fontBold, 10, theme.accent);
2533
2568
  drawText(page, "Ship to", margin + colW + 16, y, fontBold, 10, theme.accent);
2534
2569
  y -= 14;
2535
- const bill = [
2570
+ const billRaw = [
2536
2571
  input.customerName,
2537
2572
  input.customerEmail || "",
2538
2573
  input.customerPhone || "",
2539
2574
  ...addrLines(input.billingAddress)
2540
2575
  ].filter(Boolean);
2541
- const ship = addrLines(input.shippingAddress).length ? [
2576
+ const shipRaw = addrLines(input.shippingAddress).length ? [
2542
2577
  input.customerName,
2543
2578
  ...addrLines(input.shippingAddress)
2544
- ] : bill;
2545
- const rows = Math.max(bill.length, ship.length, 1);
2579
+ ] : billRaw;
2580
+ const billLines = wrapLinesToWidth(billRaw, font, 9, colW);
2581
+ const shipLines = wrapLinesToWidth(shipRaw, font, 9, colW);
2582
+ const rows = Math.max(billLines.length, shipLines.length, 1);
2546
2583
  for (let i = 0; i < rows; i++) {
2547
2584
  ensureSpace(14);
2548
- if (bill[i]) drawText(page, bill[i], margin, y, font, 9, theme.text);
2549
- if (ship[i]) drawText(page, ship[i], margin + colW + 16, y, font, 9, theme.text);
2585
+ if (billLines[i]) drawText(page, billLines[i], margin, y, font, 9, theme.text);
2586
+ if (shipLines[i]) drawText(page, shipLines[i], margin + colW + 16, y, font, 9, theme.text);
2550
2587
  y -= 12;
2551
2588
  }
2552
2589
  y -= 12;
@@ -1,12 +1,12 @@
1
- import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool, validateFcmCredentials, sendFcmPushNotification, parseEmailRecipientsFromConfig, isWhatsAppPluginEnabled, WhatsAppService, emailPlugin, initWhatsappTriggerDispatcher } from './chunk-3LF4RYAJ.js';
1
+ import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool, validateFcmCredentials, sendFcmPushNotification, parseEmailRecipientsFromConfig, isWhatsAppPluginEnabled, WhatsAppService, emailPlugin, initWhatsappTriggerDispatcher } from './chunk-X3IJG25M.js';
2
2
  import { normalizePhoneE164, generateNumericOtp, createOtpChallenge, verifyAndConsumeOtpChallenge } from './chunk-ECUGNV2I.js';
3
3
  import { registerWhatsAppQueueProcessor, queueSms } from './chunk-K6JT7BKY.js';
4
4
  import { inviteStatusForActivation } from './chunk-ZMIMKNSQ.js';
5
5
  import { EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS, EVENT_ORDER_TEMPLATE_KEY, EVENT_ORDER_TEMPLATE_VARIABLES } from './chunk-5NVGWJSY.js';
6
6
  import { JOB_RUNNER_QUEUE } from './chunk-2BNVRFUQ.js';
7
7
  import { validateInventoryForConfirmedOrderLines, orderStatusHoldsStock, reconcileOrderInventoryBetweenSnapshots, orderInventorySnapshotFromRow, validateInventoryForOrderBecomingConfirmed } from './chunk-JYRFSFXH.js';
8
- import { queueEmail, queueVendorOnboardEmails, registerEmailQueueProcessor } from './chunk-LJ5C4RBF.js';
9
- import { unwrapErpReadData, mapErpPayloadToFulfillment, extractChildOrderRefsFromSalePayload, mapErpPayloadToInvoiceNumber, streamOrderInvoicePdf } from './chunk-PQJIJ4ZX.js';
8
+ import { queueEmail, queueVendorOnboardEmails, registerEmailQueueProcessor } from './chunk-6TRH3VY7.js';
9
+ import { unwrapErpReadData, mapErpPayloadToFulfillment, extractChildOrderRefsFromSalePayload, mapErpPayloadToInvoiceNumber, streamOrderInvoicePdf } from './chunk-DAUBLBTP.js';
10
10
  import { isErpIntegrationEnabled } from './chunk-WQZ4AH2P.js';
11
11
  import { mergeEmailLayoutCompanyDetails } from './chunk-YDMHG6BA.js';
12
12
  import { getSmsTemplateDefault, SMS_MESSAGE_TEMPLATE_DEFAULTS } from './chunk-MGT4DJ2D.js';
@@ -3586,6 +3586,15 @@ function createCrudHandler(dataSource, entityMap, options) {
3586
3586
  if (resource === "discounts") {
3587
3587
  const scope = await resolveScope();
3588
3588
  const repo2 = dataSource.getRepository(entity);
3589
+ try {
3590
+ await repo2.createQueryBuilder().update(entity).set({
3591
+ status: "INACTIVE"
3592
+ }).where("status = :activeStatus AND validUntil IS NOT NULL AND validUntil < :currentDate", {
3593
+ activeStatus: "ACTIVE",
3594
+ currentDate: /* @__PURE__ */ new Date()
3595
+ }).execute();
3596
+ } catch {
3597
+ }
3589
3598
  const allowedSort = [
3590
3599
  "id",
3591
3600
  "name",
@@ -3900,9 +3909,14 @@ function createCrudHandler(dataSource, entityMap, options) {
3900
3909
  ...orderWithoutPayments,
3901
3910
  contact: contact ? {
3902
3911
  id: contact.id,
3903
- name: contact.name,
3904
- email: contact.email,
3905
- phone: contact.phone
3912
+ name: order.metadata?.customerName || contact.name,
3913
+ email: order.metadata?.customerEmail || contact.email,
3914
+ phone: order.metadata?.customerPhone || contact.phone
3915
+ } : order.metadata?.customerName || order.metadata?.customerEmail ? {
3916
+ id: 0,
3917
+ name: order.metadata?.customerName || "Customer",
3918
+ email: order.metadata?.customerEmail || "",
3919
+ phone: order.metadata?.customerPhone || null
3906
3920
  } : null,
3907
3921
  assignedUser: assignedUserObj ? {
3908
3922
  id: assignedUserObj.id,
@@ -4066,6 +4080,8 @@ function createCrudHandler(dataSource, entityMap, options) {
4066
4080
  const contact = row.contact;
4067
4081
  return {
4068
4082
  ...row,
4083
+ contactId: contact?.id ?? row.contactId ?? null,
4084
+ customerId: customer?.id ?? row.customerId ?? null,
4069
4085
  name: customer?.name ?? contact?.name ?? null,
4070
4086
  email: customer?.email ?? contact?.email ?? null,
4071
4087
  phone: customer?.phone ?? contact?.phone ?? null,
@@ -5211,6 +5227,15 @@ function createCrudHandler(dataSource, entityMap, options) {
5211
5227
  deleted: false
5212
5228
  }
5213
5229
  });
5230
+ if (contact && emailRaw && contact.email?.toLowerCase() !== emailRaw.toLowerCase()) {
5231
+ const contactByEmail = await contactRepo.findOne({
5232
+ where: {
5233
+ email: emailRaw,
5234
+ deleted: false
5235
+ }
5236
+ });
5237
+ contact = contactByEmail ?? null;
5238
+ }
5214
5239
  }
5215
5240
  if (!contact) {
5216
5241
  if (!emailRaw) {
@@ -5228,16 +5253,15 @@ function createCrudHandler(dataSource, entityMap, options) {
5228
5253
  });
5229
5254
  }
5230
5255
  if (!contact) {
5231
- const nameRaw2 = String(body["contact.name"] ?? "").trim();
5256
+ const nameRaw = String(body["contact.name"] ?? "").trim();
5232
5257
  const phoneRaw2 = body["contact.phone"];
5233
5258
  contact = await contactRepo.save(contactRepo.create({
5234
- name: nameRaw2 || emailRaw.split("@")[0] || "Customer",
5259
+ name: nameRaw || emailRaw.split("@")[0] || "Customer",
5235
5260
  email: emailRaw,
5236
5261
  phone: phoneRaw2 == null || phoneRaw2 === "" ? null : String(phoneRaw2),
5237
5262
  type: "customer"
5238
5263
  }));
5239
5264
  }
5240
- const nameRaw = String(body["contact.name"] ?? contact.name ?? "").trim();
5241
5265
  const phoneRaw = body["contact.phone"] ?? contact.phone;
5242
5266
  const emailForVc = (emailRaw || String(contact.email ?? "")).trim().toLowerCase();
5243
5267
  const phoneToSave = phoneRaw == null || phoneRaw === "" ? null : String(phoneRaw).trim();
@@ -5247,6 +5271,13 @@ function createCrudHandler(dataSource, entityMap, options) {
5247
5271
  });
5248
5272
  contact.phone = phoneToSave;
5249
5273
  }
5274
+ const nameToSave = String(body["contact.name"] ?? "").trim();
5275
+ if (nameToSave && contact.name !== nameToSave) {
5276
+ await contactRepo.update(contact.id, {
5277
+ name: nameToSave
5278
+ });
5279
+ contact.name = nameToSave;
5280
+ }
5250
5281
  const vendorIdForCustomer = resolveVendorIdForContactCheck(scopeCreate, persistBody);
5251
5282
  const orderLinesForVendors = normalizeOrderLinesInput(body.orderLines);
5252
5283
  const vendorIdsForVc = [];
@@ -5258,33 +5289,36 @@ function createCrudHandler(dataSource, entityMap, options) {
5258
5289
  if (!Number.isFinite(pid)) continue;
5259
5290
  const product = await productRepoForVc.findOne({
5260
5291
  where: {
5261
- id: pid
5292
+ id: pid,
5293
+ deleted: false
5262
5294
  }
5263
5295
  });
5264
- const pVid = Number(product?.vendorId);
5265
- if (Number.isFinite(pVid) && pVid > 0) vendorIdsForVc.push(pVid);
5296
+ const vId = Number(product?.vendorId);
5297
+ if (Number.isFinite(vId) && vId > 0 && !vendorIdsForVc.includes(vId)) {
5298
+ vendorIdsForVc.push(vId);
5299
+ }
5266
5300
  }
5267
5301
  }
5268
5302
  if (vendorIdsForVc.length > 0 && emailForVc) {
5269
- await ensureVendorCustomersForOrder(dataSource, entityMap, vendorIdsForVc, contact.id, {
5270
- name: nameRaw || emailForVc.split("@")[0] || "Customer",
5303
+ await ensureVendorCustomersForOrder(dataSource, entityMap, vendorIdsForVc, Number(contact.id), {
5304
+ name: contact.name ?? "Customer",
5271
5305
  email: emailForVc,
5272
- phone: phoneRaw == null || phoneRaw === "" ? null : String(phoneRaw)
5306
+ phone: phoneToSave
5273
5307
  });
5274
5308
  }
5275
- const accountCustomerId = Number(body.accountCustomerId);
5276
- if (entityMap.customer_contacts && Number.isFinite(accountCustomerId) && accountCustomerId > 0) {
5309
+ const accountCustomerIdRaw = Number(body.accountCustomerId);
5310
+ if (Number.isFinite(accountCustomerIdRaw) && accountCustomerIdRaw > 0 && entityMap.customer_contacts) {
5277
5311
  const ccRepo = dataSource.getRepository(entityMap.customer_contacts);
5278
- const orderContactId = contact.id;
5279
- const existingLink = await ccRepo.findOne({
5312
+ const orderContactId = Number(contact.id);
5313
+ const existingCc = await ccRepo.findOne({
5280
5314
  where: {
5281
- customerId: accountCustomerId,
5315
+ customerId: accountCustomerIdRaw,
5282
5316
  contactId: orderContactId
5283
5317
  }
5284
5318
  });
5285
- if (!existingLink) {
5319
+ if (!existingCc) {
5286
5320
  await ccRepo.save(ccRepo.create({
5287
- customerId: accountCustomerId,
5321
+ customerId: accountCustomerIdRaw,
5288
5322
  contactId: orderContactId
5289
5323
  }));
5290
5324
  }
@@ -5293,6 +5327,13 @@ function createCrudHandler(dataSource, entityMap, options) {
5293
5327
  persistBody.contactId = contact.id;
5294
5328
  persistBody.orderNumber = `ORD00${randomPart}`;
5295
5329
  persistBody.qrToken = crypto2.randomBytes(16).toString("hex");
5330
+ const metaSnapshot = typeof persistBody.metadata === "object" && persistBody.metadata !== null ? persistBody.metadata : {};
5331
+ persistBody.metadata = {
5332
+ ...metaSnapshot,
5333
+ customerName: metaSnapshot.customerName || nameToSave || contact.name || void 0,
5334
+ customerEmail: metaSnapshot.customerEmail || emailForVc || contact.email || void 0,
5335
+ customerPhone: metaSnapshot.customerPhone || phoneToSave || contact.phone || void 0
5336
+ };
5296
5337
  }
5297
5338
  if (resource === "orders" && persistBody.assignedUserId) {
5298
5339
  const assignCheck = await validateAssigneeOrderPermission(dataSource, entityMap, Number(persistBody.assignedUserId));
@@ -5518,7 +5559,7 @@ function createCrudHandler(dataSource, entityMap, options) {
5518
5559
  const orderIdForNotify = created.id;
5519
5560
  const finalCreatedStatus = String(created.status ?? createdStatus ?? "pending").toLowerCase();
5520
5561
  const initialPayStatus = String(persistBody.paymentStatus ?? body.paymentStatus ?? "unpaid").toLowerCase();
5521
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
5562
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
5522
5563
  if (finalCreatedStatus === "pending") {
5523
5564
  if (initialPayStatus === "failed") {
5524
5565
  fireOrderNotificationTrigger("payment_failed", orderIdForNotify, {
@@ -6040,8 +6081,22 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6040
6081
  id: "ASC"
6041
6082
  }
6042
6083
  });
6084
+ const orderMeta = order?.metadata;
6085
+ const ordContact = order?.contact;
6086
+ const mappedContact = ordContact ? {
6087
+ ...ordContact,
6088
+ name: orderMeta?.customerName || ordContact.name,
6089
+ email: orderMeta?.customerEmail || ordContact.email,
6090
+ phone: orderMeta?.customerPhone || ordContact.phone
6091
+ } : orderMeta?.customerName || orderMeta?.customerEmail ? {
6092
+ id: 0,
6093
+ name: orderMeta?.customerName || "Customer",
6094
+ email: orderMeta?.customerEmail || "",
6095
+ phone: orderMeta?.customerPhone || null
6096
+ } : null;
6043
6097
  return json({
6044
6098
  ...order,
6099
+ contact: mappedContact,
6045
6100
  relatedOrders
6046
6101
  });
6047
6102
  }
@@ -6739,7 +6794,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6739
6794
  const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
6740
6795
  const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
6741
6796
  if (assigneeUpdated) {
6742
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
6797
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
6743
6798
  fireOrderNotificationTrigger("order_assigned", updatedOrder.id, {
6744
6799
  dataSource,
6745
6800
  entityMap
@@ -6756,7 +6811,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
6756
6811
  const payments = Array.isArray(updatedOrder.payments) ? updatedOrder.payments : [];
6757
6812
  const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
6758
6813
  const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
6759
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
6814
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
6760
6815
  if (newStatus === "pending") {
6761
6816
  if (curPayStatus === "failed") {
6762
6817
  fireOrderNotificationTrigger("payment_failed", updatedOrder.id, {
@@ -7475,7 +7530,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7475
7530
  });
7476
7531
  }
7477
7532
  if (ordStatus === "pending" || ordStatus === "confirmed") {
7478
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
7533
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
7479
7534
  fireOrderNotificationTrigger("order_placed", pOrder, {
7480
7535
  dataSource,
7481
7536
  entityMap
@@ -7489,7 +7544,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7489
7544
  }
7490
7545
  }
7491
7546
  } else if (newPayStatus === "failed") {
7492
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
7547
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
7493
7548
  fireOrderNotificationTrigger("payment_failed", pOrder, {
7494
7549
  dataSource,
7495
7550
  entityMap
@@ -7497,7 +7552,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7497
7552
  }).catch(() => {
7498
7553
  });
7499
7554
  } else if (newPayStatus === "refunded") {
7500
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
7555
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
7501
7556
  fireOrderNotificationTrigger("payment_refund_initiated", pOrder, {
7502
7557
  dataSource,
7503
7558
  entityMap
@@ -7624,7 +7679,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7624
7679
  const paymentUpdated = Boolean(rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null);
7625
7680
  const assigneeUpdated = Boolean(rawBody && typeof rawBody === "object" && "assignedUserId" in rawBody && rawBody.assignedUserId !== void 0 && Number(rawBody.assignedUserId) > 0 && Number(rawBody.assignedUserId) !== Number(existingOrderRow?.assignedUserId));
7626
7681
  if (assigneeUpdated) {
7627
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
7682
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
7628
7683
  fireOrderNotificationTrigger("order_assigned", ord.id, {
7629
7684
  dataSource,
7630
7685
  entityMap
@@ -7641,7 +7696,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
7641
7696
  const payments = Array.isArray(ord.payments) ? ord.payments : [];
7642
7697
  const bodyPayStatus = rawBody && typeof rawBody === "object" && rawBody.paymentStatus != null ? String(rawBody.paymentStatus).toLowerCase() : null;
7643
7698
  const curPayStatus = bodyPayStatus || String(payments[0]?.status || "unpaid").toLowerCase();
7644
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
7699
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
7645
7700
  if (newStatus === "pending") {
7646
7701
  if (curPayStatus === "failed") {
7647
7702
  fireOrderNotificationTrigger("payment_failed", ord.id, {
@@ -30041,7 +30096,7 @@ function createCmsApiHandler(config) {
30041
30096
  companyDetails
30042
30097
  };
30043
30098
  if (queue) {
30044
- const { queueEmail: queueEmail2 } = await import('./email-queue-MWP4R67H.js');
30099
+ const { queueEmail: queueEmail2 } = await import('./email-queue-5TOJJT3P.js');
30045
30100
  await queueEmail2(cms, {
30046
30101
  to: opts.to,
30047
30102
  templateName: "passwordReset",
@@ -31080,7 +31135,7 @@ function createCmsApiHandler(config) {
31080
31135
  storeMap[r.key] = r.value;
31081
31136
  }
31082
31137
  const { normalizeInvoiceTemplateId } = await import('./invoice-templates-3AXTXERZ.js');
31083
- const { generateLocalInvoicePdf } = await import('./generate-local-invoice-pdf-XUH6GYEJ.js');
31138
+ const { generateLocalInvoicePdf } = await import('./generate-local-invoice-pdf-V5FHS23Z.js');
31084
31139
  const { resolveInvoiceAssetUrl } = await import('./resolve-invoice-asset-url-64QQUVC3.js');
31085
31140
  const templateId = normalizeInvoiceTemplateId(templateParam);
31086
31141
  const includeQr = qrParam != null ? qrParam === "1" || qrParam === "true" : storeMap.invoice_include_qr === "true";
@@ -31468,7 +31523,7 @@ function createCmsApiHandler(config) {
31468
31523
  const pe = await requireEntityPermissionEffective(req, "orders", "read");
31469
31524
  if (pe) return pe;
31470
31525
  const cms = await getCms();
31471
- const { streamOrderInvoicePdf: streamOrderInvoicePdf2 } = await import('./erp-order-invoice-JEQKFXG4.js');
31526
+ const { streamOrderInvoicePdf: streamOrderInvoicePdf2 } = await import('./erp-order-invoice-SEZZUDMW.js');
31472
31527
  const oid = Number(path2[1]);
31473
31528
  if (!Number.isFinite(oid)) return config.json({
31474
31529
  error: "Invalid id"
@@ -31554,7 +31609,7 @@ function createCmsApiHandler(config) {
31554
31609
  }
31555
31610
  const result = await validateCoupon(dataSource, entityMap, couponCode, orderLinesNorm, currency, contactId, isAutomatic, discountId ?? void 0, vendorId);
31556
31611
  return config.json(result, {
31557
- status: result.valid ? 200 : 400
31612
+ status: 200
31558
31613
  });
31559
31614
  } catch (err) {
31560
31615
  const message = err instanceof Error ? err.message : String(err);
@@ -31850,7 +31905,7 @@ function createCmsApiHandler(config) {
31850
31905
  status: 400
31851
31906
  });
31852
31907
  }
31853
- const { resendOrderNotification } = await import('./order-notification-dispatcher-Z3MXNF4U.js');
31908
+ const { resendOrderNotification } = await import('./order-notification-dispatcher-COR2ZHM3.js');
31854
31909
  const result = await resendOrderNotification(triggerKey, orderId, {
31855
31910
  dataSource,
31856
31911
  entityMap,
@@ -32107,7 +32162,7 @@ function createCmsApiHandler(config) {
32107
32162
  console.error("[cancel-order] refund_request save failed", err);
32108
32163
  }
32109
32164
  }
32110
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
32165
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
32111
32166
  fireOrderNotificationTrigger("order_cancelled", orderId, {
32112
32167
  dataSource,
32113
32168
  entityMap
@@ -32142,7 +32197,7 @@ function createCmsApiHandler(config) {
32142
32197
  }, {
32143
32198
  status: 400
32144
32199
  });
32145
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-KHLZQQJX.js');
32200
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-2WOFSORP.js');
32146
32201
  const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
32147
32202
  return handlers.getChannels(req, orderId);
32148
32203
  }
@@ -32157,7 +32212,7 @@ function createCmsApiHandler(config) {
32157
32212
  }, {
32158
32213
  status: 400
32159
32214
  });
32160
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-KHLZQQJX.js');
32215
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-2WOFSORP.js');
32161
32216
  const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
32162
32217
  return handlers.sendOtp(req, orderId);
32163
32218
  }
@@ -32172,7 +32227,7 @@ function createCmsApiHandler(config) {
32172
32227
  }, {
32173
32228
  status: 400
32174
32229
  });
32175
- const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-KHLZQQJX.js');
32230
+ const { createOrderCompletionOtpHandlers } = await import('./order-completion-otp-handlers-2WOFSORP.js');
32176
32231
  const handlers = createOrderCompletionOtpHandlers(dataSource, entityMap, getCms, getHydratedSessionUser);
32177
32232
  return handlers.verifyOtp(req, orderId);
32178
32233
  }
@@ -32811,7 +32866,7 @@ function createStorefrontApiHandler(config) {
32811
32866
  const otpPepper = config.otpPepper;
32812
32867
  const defaultPhoneCc = config.defaultPhoneCountryCode;
32813
32868
  function fireStorefrontCheckoutNotifications(orderId) {
32814
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
32869
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
32815
32870
  fireOrderNotificationTrigger("order_pending", orderId, {
32816
32871
  dataSource,
32817
32872
  entityMap
@@ -35756,7 +35811,7 @@ function createStorefrontApiHandler(config) {
35756
35811
  } catch {
35757
35812
  }
35758
35813
  try {
35759
- void import('./emit-order-notification-trigger-TBXAZAPS.js').then(({ fireOrderNotificationTrigger }) => {
35814
+ void import('./emit-order-notification-trigger-3RAVWKLG.js').then(({ fireOrderNotificationTrigger }) => {
35760
35815
  fireOrderNotificationTrigger("order_cancelled", orderId, {
35761
35816
  dataSource,
35762
35817
  entityMap
@@ -94,7 +94,7 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
94
94
  orderId
95
95
  });
96
96
  try {
97
- const { dispatchOrderNotificationDirectly } = await import('./order-notification-dispatcher-Z3MXNF4U.js');
97
+ const { dispatchOrderNotificationDirectly } = await import('./order-notification-dispatcher-COR2ZHM3.js');
98
98
  await dispatchOrderNotificationDirectly(triggerKey, triggerPayload, deps.dataSource, deps.entityMap);
99
99
  } catch (err) {
100
100
  notifyLog.error("TRIGGER", "direct dispatch failed", {
@@ -2,7 +2,7 @@ import { queueWhatsApp, queueSms } from './chunk-K6JT7BKY.js';
2
2
  import { notifyLog, logFcmToken, maskNotifyEmail, maskNotifyPhone, notificationTriggerEmitter } from './chunk-W2ZTGLUH.js';
3
3
  import { applyTemplateVars } from './chunk-ECNYZG6T.js';
4
4
  import { sesRegionSupportsSmtp, sesSmtpHost, EmailService, renderLayout } from './chunk-CFUSYGSA.js';
5
- import { queueEmail } from './chunk-LJ5C4RBF.js';
5
+ import { queueEmail } from './chunk-6TRH3VY7.js';
6
6
  import { mergeEmailLayoutCompanyDetails } from './chunk-YDMHG6BA.js';
7
7
  import { __name } from './chunk-5BKT4CS5.js';
8
8
  import * as crypto from 'crypto';
@@ -2371,6 +2371,41 @@ function wrapText(text, font, size, maxWidth) {
2371
2371
  return lines.slice(0, 4);
2372
2372
  }
2373
2373
  chunkXHPRD45G_cjs.__name(wrapText, "wrapText");
2374
+ function wrapLinesToWidth(lines, font, size, maxWidth) {
2375
+ const result = [];
2376
+ for (const rawLine of lines) {
2377
+ if (!rawLine || !rawLine.trim()) continue;
2378
+ const words = winAnsiSafe(rawLine).split(/\s+/).filter(Boolean);
2379
+ if (!words.length) continue;
2380
+ let current = "";
2381
+ for (let word of words) {
2382
+ while (font.widthOfTextAtSize(word, size) > maxWidth) {
2383
+ let cut = word.length - 1;
2384
+ while (cut > 0 && font.widthOfTextAtSize(word.slice(0, cut), size) > maxWidth) {
2385
+ cut--;
2386
+ }
2387
+ if (cut <= 0) cut = 1;
2388
+ const head = word.slice(0, cut);
2389
+ if (current) {
2390
+ result.push(current);
2391
+ current = "";
2392
+ }
2393
+ result.push(head);
2394
+ word = word.slice(cut);
2395
+ }
2396
+ const candidate = current ? `${current} ${word}` : word;
2397
+ if (font.widthOfTextAtSize(candidate, size) <= maxWidth) {
2398
+ current = candidate;
2399
+ } else {
2400
+ if (current) result.push(current);
2401
+ current = word;
2402
+ }
2403
+ }
2404
+ if (current) result.push(current);
2405
+ }
2406
+ return result;
2407
+ }
2408
+ chunkXHPRD45G_cjs.__name(wrapLinesToWidth, "wrapLinesToWidth");
2374
2409
  async function tryEmbedLogo(doc, logoUrl, maxW, maxH) {
2375
2410
  const url = String(logoUrl ?? "").trim();
2376
2411
  if (!url || !/^https?:\/\//i.test(url)) return null;
@@ -2534,21 +2569,23 @@ async function generateLocalInvoicePdf(input) {
2534
2569
  drawText(page, "Bill to", margin, y, fontBold, 10, theme.accent);
2535
2570
  drawText(page, "Ship to", margin + colW + 16, y, fontBold, 10, theme.accent);
2536
2571
  y -= 14;
2537
- const bill = [
2572
+ const billRaw = [
2538
2573
  input.customerName,
2539
2574
  input.customerEmail || "",
2540
2575
  input.customerPhone || "",
2541
2576
  ...addrLines(input.billingAddress)
2542
2577
  ].filter(Boolean);
2543
- const ship = addrLines(input.shippingAddress).length ? [
2578
+ const shipRaw = addrLines(input.shippingAddress).length ? [
2544
2579
  input.customerName,
2545
2580
  ...addrLines(input.shippingAddress)
2546
- ] : bill;
2547
- const rows = Math.max(bill.length, ship.length, 1);
2581
+ ] : billRaw;
2582
+ const billLines = wrapLinesToWidth(billRaw, font, 9, colW);
2583
+ const shipLines = wrapLinesToWidth(shipRaw, font, 9, colW);
2584
+ const rows = Math.max(billLines.length, shipLines.length, 1);
2548
2585
  for (let i = 0; i < rows; i++) {
2549
2586
  ensureSpace(14);
2550
- if (bill[i]) drawText(page, bill[i], margin, y, font, 9, theme.text);
2551
- if (ship[i]) drawText(page, ship[i], margin + colW + 16, y, font, 9, theme.text);
2587
+ if (billLines[i]) drawText(page, billLines[i], margin, y, font, 9, theme.text);
2588
+ if (shipLines[i]) drawText(page, shipLines[i], margin + colW + 16, y, font, 9, theme.text);
2552
2589
  y -= 12;
2553
2590
  }
2554
2591
  y -= 12;
@@ -96,7 +96,7 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
96
96
  orderId
97
97
  });
98
98
  try {
99
- const { dispatchOrderNotificationDirectly } = await import('./order-notification-dispatcher-37KDVHBM.cjs');
99
+ const { dispatchOrderNotificationDirectly } = await import('./order-notification-dispatcher-KTOAMMSD.cjs');
100
100
  await dispatchOrderNotificationDirectly(triggerKey, triggerPayload, deps.dataSource, deps.entityMap);
101
101
  } catch (err) {
102
102
  chunkK742UE6S_cjs.notifyLog.error("TRIGGER", "direct dispatch failed", {
@@ -1,7 +1,7 @@
1
- export { queueEmail, queueOrderPlacedEmails, queueVendorOnboardEmails, registerEmailQueueProcessor } from './chunk-LJ5C4RBF.js';
2
- import './chunk-PQJIJ4ZX.js';
1
+ export { queueEmail, queueOrderPlacedEmails, queueVendorOnboardEmails, registerEmailQueueProcessor } from './chunk-6TRH3VY7.js';
2
+ import './chunk-DAUBLBTP.js';
3
3
  import './chunk-WQZ4AH2P.js';
4
- import './chunk-YHVA5NHI.js';
4
+ import './chunk-LUSJITTI.js';
5
5
  import './chunk-K6RXCLD5.js';
6
6
  import './chunk-5DSY3GQI.js';
7
7
  import './chunk-YDMHG6BA.js';
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var chunk4MNVIGVJ_cjs = require('./chunk-4MNVIGVJ.cjs');
4
- require('./chunk-BQQMTQ4C.cjs');
3
+ var chunkD3SR6CYU_cjs = require('./chunk-D3SR6CYU.cjs');
4
+ require('./chunk-25T6HP5T.cjs');
5
5
  require('./chunk-RQCXRCYM.cjs');
6
- require('./chunk-2JHGIWH7.cjs');
6
+ require('./chunk-X5ILLSTD.cjs');
7
7
  require('./chunk-E62LKM6Z.cjs');
8
8
  require('./chunk-47G65M5Q.cjs');
9
9
  require('./chunk-EYUBL7YH.cjs');
@@ -13,17 +13,17 @@ require('./chunk-XHPRD45G.cjs');
13
13
 
14
14
  Object.defineProperty(exports, "queueEmail", {
15
15
  enumerable: true,
16
- get: function () { return chunk4MNVIGVJ_cjs.queueEmail; }
16
+ get: function () { return chunkD3SR6CYU_cjs.queueEmail; }
17
17
  });
18
18
  Object.defineProperty(exports, "queueOrderPlacedEmails", {
19
19
  enumerable: true,
20
- get: function () { return chunk4MNVIGVJ_cjs.queueOrderPlacedEmails; }
20
+ get: function () { return chunkD3SR6CYU_cjs.queueOrderPlacedEmails; }
21
21
  });
22
22
  Object.defineProperty(exports, "queueVendorOnboardEmails", {
23
23
  enumerable: true,
24
- get: function () { return chunk4MNVIGVJ_cjs.queueVendorOnboardEmails; }
24
+ get: function () { return chunkD3SR6CYU_cjs.queueVendorOnboardEmails; }
25
25
  });
26
26
  Object.defineProperty(exports, "registerEmailQueueProcessor", {
27
27
  enumerable: true,
28
- get: function () { return chunk4MNVIGVJ_cjs.registerEmailQueueProcessor; }
28
+ get: function () { return chunkD3SR6CYU_cjs.registerEmailQueueProcessor; }
29
29
  });
@@ -1,3 +1,3 @@
1
- export { emitOrderNotificationTrigger, fireOrderNotificationTrigger } from './chunk-HZZTDM5J.js';
1
+ export { emitOrderNotificationTrigger, fireOrderNotificationTrigger } from './chunk-R5HLPH6P.js';
2
2
  import './chunk-W2ZTGLUH.js';
3
3
  import './chunk-5BKT4CS5.js';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkNIBEGDD4_cjs = require('./chunk-NIBEGDD4.cjs');
3
+ var chunkZBSH4GWB_cjs = require('./chunk-ZBSH4GWB.cjs');
4
4
  require('./chunk-K742UE6S.cjs');
5
5
  require('./chunk-XHPRD45G.cjs');
6
6
 
@@ -8,9 +8,9 @@ require('./chunk-XHPRD45G.cjs');
8
8
 
9
9
  Object.defineProperty(exports, "emitOrderNotificationTrigger", {
10
10
  enumerable: true,
11
- get: function () { return chunkNIBEGDD4_cjs.emitOrderNotificationTrigger; }
11
+ get: function () { return chunkZBSH4GWB_cjs.emitOrderNotificationTrigger; }
12
12
  });
13
13
  Object.defineProperty(exports, "fireOrderNotificationTrigger", {
14
14
  enumerable: true,
15
- get: function () { return chunkNIBEGDD4_cjs.fireOrderNotificationTrigger; }
15
+ get: function () { return chunkZBSH4GWB_cjs.fireOrderNotificationTrigger; }
16
16
  });
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkBQQMTQ4C_cjs = require('./chunk-BQQMTQ4C.cjs');
3
+ var chunk25T6HP5T_cjs = require('./chunk-25T6HP5T.cjs');
4
4
  require('./chunk-RQCXRCYM.cjs');
5
- require('./chunk-2JHGIWH7.cjs');
5
+ require('./chunk-X5ILLSTD.cjs');
6
6
  require('./chunk-E62LKM6Z.cjs');
7
7
  require('./chunk-47G65M5Q.cjs');
8
8
  require('./chunk-EYUBL7YH.cjs');
@@ -12,17 +12,17 @@ require('./chunk-XHPRD45G.cjs');
12
12
 
13
13
  Object.defineProperty(exports, "ORDER_INVOICE_EMAIL_ELIGIBLE_STATUSES", {
14
14
  enumerable: true,
15
- get: function () { return chunkBQQMTQ4C_cjs.ORDER_INVOICE_EMAIL_ELIGIBLE_STATUSES; }
15
+ get: function () { return chunk25T6HP5T_cjs.ORDER_INVOICE_EMAIL_ELIGIBLE_STATUSES; }
16
16
  });
17
17
  Object.defineProperty(exports, "isOrderEligibleForInvoiceEmail", {
18
18
  enumerable: true,
19
- get: function () { return chunkBQQMTQ4C_cjs.isOrderEligibleForInvoiceEmail; }
19
+ get: function () { return chunk25T6HP5T_cjs.isOrderEligibleForInvoiceEmail; }
20
20
  });
21
21
  Object.defineProperty(exports, "resolveOrderInvoicePdfBytes", {
22
22
  enumerable: true,
23
- get: function () { return chunkBQQMTQ4C_cjs.resolveOrderInvoicePdfBytes; }
23
+ get: function () { return chunk25T6HP5T_cjs.resolveOrderInvoicePdfBytes; }
24
24
  });
25
25
  Object.defineProperty(exports, "streamOrderInvoicePdf", {
26
26
  enumerable: true,
27
- get: function () { return chunkBQQMTQ4C_cjs.streamOrderInvoicePdf; }
27
+ get: function () { return chunk25T6HP5T_cjs.streamOrderInvoicePdf; }
28
28
  });