@infuro/cms-core 1.0.67 → 1.0.69

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 (150) hide show
  1. package/dist/{OrderTrackPage-W3J6WIG2.js → OrderTrackPage-VBZUVZOU.js} +1 -1
  2. package/dist/{OrderTrackPage-Z6FCJQYY.cjs → OrderTrackPage-VFIXWJOW.cjs} +4 -4
  3. package/dist/admin.cjs +121 -12
  4. package/dist/admin.js +121 -12
  5. package/dist/api.cjs +57 -54
  6. package/dist/api.js +24 -21
  7. package/dist/auth.cjs +62 -62
  8. package/dist/auth.js +6 -6
  9. package/dist/{chunk-XJNNOSJR.js → chunk-2BNVRFUQ.js} +1 -1
  10. package/dist/chunk-2JHGIWH7.cjs +2700 -0
  11. package/dist/{chunk-3DZRIZOD.cjs → chunk-3ASNJS2H.cjs} +3 -3
  12. package/dist/{chunk-7NMT3GBR.cjs → chunk-3LQS4ATQ.cjs} +4 -4
  13. package/dist/{chunk-GWDI752Q.js → chunk-3XCTGADT.js} +1 -1
  14. package/dist/chunk-47G65M5Q.cjs +18 -0
  15. package/dist/{chunk-XFDIIVZB.cjs → chunk-4MNVIGVJ.cjs} +11 -11
  16. package/dist/{chunk-OY2YTBMP.cjs → chunk-4WZNRVEZ.cjs} +3 -3
  17. package/dist/{chunk-OVTOP42W.js → chunk-53AMBXMM.js} +1 -1
  18. package/dist/chunk-5BKT4CS5.js +28 -0
  19. package/dist/chunk-5DSY3GQI.js +16 -0
  20. package/dist/{chunk-AYERBA7I.js → chunk-5NVGWJSY.js} +1 -1
  21. package/dist/{chunk-HF3L2GIT.cjs → chunk-5YMKJ3TH.cjs} +16 -16
  22. package/dist/{chunk-WFMVD567.cjs → chunk-6MM5OMRL.cjs} +11 -11
  23. package/dist/{chunk-5MZFQRDW.cjs → chunk-747MJJCZ.cjs} +147 -147
  24. package/dist/{chunk-SYBOCAWB.js → chunk-7QJI56OL.js} +1 -1
  25. package/dist/{chunk-DBPSJYLZ.js → chunk-BK5XW5XH.js} +1 -1
  26. package/dist/chunk-BQQMTQ4C.cjs +455 -0
  27. package/dist/{chunk-6YOQ7G5O.js → chunk-CFUSYGSA.js} +1 -1
  28. package/dist/{chunk-OOTLNH63.cjs → chunk-CIZZX57T.cjs} +2 -2
  29. package/dist/{chunk-7L6KWI7S.cjs → chunk-CTTV375J.cjs} +13 -13
  30. package/dist/{chunk-ZY64VJMS.js → chunk-D4LR3S77.js} +2 -2
  31. package/dist/{chunk-GLLCLRCQ.js → chunk-DBBYLSQP.js} +179 -49
  32. package/dist/{chunk-5NOZSG6J.js → chunk-DWNQTFJ5.js} +2 -2
  33. package/dist/{chunk-2IAXTKQN.cjs → chunk-DZNWS2MM.cjs} +2 -2
  34. package/dist/chunk-E62LKM6Z.cjs +49 -0
  35. package/dist/{chunk-CRFV5WJK.js → chunk-ECNYZG6T.js} +1 -1
  36. package/dist/{chunk-TZEMLHSP.cjs → chunk-EYUBL7YH.cjs} +7 -7
  37. package/dist/{chunk-WMMZZRDJ.cjs → chunk-HGR4IA7I.cjs} +18 -18
  38. package/dist/{chunk-TJ2MIQUT.cjs → chunk-JRW3GQD4.cjs} +4 -4
  39. package/dist/{chunk-3K5AIEIZ.js → chunk-JYRFSFXH.js} +1 -1
  40. package/dist/chunk-K6RXCLD5.js +45 -0
  41. package/dist/{chunk-TU23GJPJ.js → chunk-LJ5C4RBF.js} +3 -3
  42. package/dist/{chunk-O4AFPDQ4.cjs → chunk-LXWF6T7F.cjs} +33 -33
  43. package/dist/{chunk-EIZKW2PF.js → chunk-LY7CDNC6.js} +1 -1
  44. package/dist/{chunk-PA6YDMFZ.cjs → chunk-M5QDJOUP.cjs} +12 -12
  45. package/dist/{chunk-MQBT33IV.js → chunk-MGT4DJ2D.js} +1 -1
  46. package/dist/{chunk-2ISSXYBZ.js → chunk-MJDNS324.js} +5 -5
  47. package/dist/{chunk-H3IVLIPR.cjs → chunk-OXFC3DAM.cjs} +4 -4
  48. package/dist/chunk-PQJIJ4ZX.js +445 -0
  49. package/dist/{chunk-HY3AXLOI.cjs → chunk-PRXVSSIF.cjs} +13 -13
  50. package/dist/{chunk-TDV6EJHV.js → chunk-PRZOLCFW.js} +2 -2
  51. package/dist/{chunk-BVLN75LP.cjs → chunk-QL44NCZC.cjs} +1221 -1091
  52. package/dist/{chunk-VM6OVUUM.cjs → chunk-QN6PZLAP.cjs} +40 -40
  53. package/dist/{chunk-OV5TRZET.cjs → chunk-QXAQ3V7R.cjs} +27 -27
  54. package/dist/{chunk-NV5IRHI3.js → chunk-RBKVMHBH.js} +9 -9
  55. package/dist/{chunk-UPLVMVRX.cjs → chunk-RQCXRCYM.cjs} +2 -2
  56. package/dist/{chunk-WUQAOTHA.js → chunk-SERRQ736.js} +1 -1
  57. package/dist/{chunk-SS3K7OIM.cjs → chunk-SWSTGV4F.cjs} +81 -81
  58. package/dist/{chunk-RCE5SJBA.js → chunk-T47VP2ZT.js} +3 -3
  59. package/dist/{chunk-FLUF2GZH.js → chunk-WHMIWJL7.js} +1 -1
  60. package/dist/{chunk-JC6DLWTE.js → chunk-WQZ4AH2P.js} +1 -1
  61. package/dist/{chunk-D5FBNKQM.cjs → chunk-WXH3GMCF.cjs} +8 -8
  62. package/dist/chunk-XHPRD45G.cjs +32 -0
  63. package/dist/{chunk-THL5JDWJ.cjs → chunk-Y54WDY2O.cjs} +2 -2
  64. package/dist/{chunk-YRCKEGL2.js → chunk-YDMHG6BA.js} +1 -1
  65. package/dist/chunk-YHVA5NHI.js +2698 -0
  66. package/dist/{chunk-JXF23MPG.js → chunk-ZMIMKNSQ.js} +1 -1
  67. package/dist/cli.cjs +10 -10
  68. package/dist/cli.js +1 -1
  69. package/dist/email-queue-BJDH2ID7.cjs +29 -0
  70. package/dist/email-queue-MWP4R67H.js +8 -0
  71. package/dist/email-service-6JODEMUA.js +3 -0
  72. package/dist/email-service-VA4Q4ZRB.cjs +28 -0
  73. package/dist/emit-order-notification-trigger-X36V4DOH.cjs +16 -0
  74. package/dist/emit-order-notification-trigger-XKN2TWVF.js +3 -0
  75. package/dist/erp-config-enabled-32XTHBBT.cjs +11 -0
  76. package/dist/erp-config-enabled-CASE5YVI.js +2 -0
  77. package/dist/erp-order-invoice-5O42ZKC5.cjs +28 -0
  78. package/dist/erp-order-invoice-JEQKFXG4.js +7 -0
  79. package/dist/{event-order-defaults-DU7V3YND.cjs → event-order-defaults-TR45WAQQ.cjs} +10 -10
  80. package/dist/{event-order-defaults-H4RT7NMR.js → event-order-defaults-VXYO6NHT.js} +2 -2
  81. package/dist/generate-local-invoice-pdf-2NCA2WBL.cjs +12 -0
  82. package/dist/generate-local-invoice-pdf-XUH6GYEJ.js +3 -0
  83. package/dist/hooks.cjs +24 -24
  84. package/dist/hooks.js +2 -2
  85. package/dist/index.cjs +497 -494
  86. package/dist/index.d.cts +7 -1
  87. package/dist/index.d.ts +7 -1
  88. package/dist/index.js +39 -36
  89. package/dist/interpolate-KD37IRF2.js +2 -0
  90. package/dist/interpolate-WP6OSJHN.cjs +11 -0
  91. package/dist/invoice-templates-2ESQ7K4N.cjs +19 -0
  92. package/dist/invoice-templates-3AXTXERZ.js +2 -0
  93. package/dist/middleware.cjs +4 -4
  94. package/dist/middleware.js +2 -2
  95. package/dist/{order-assignees-handlers-L3RVKUBS.js → order-assignees-handlers-F7WOZHOG.js} +1 -1
  96. package/dist/{order-assignees-handlers-KF7RMTV5.cjs → order-assignees-handlers-JEJ5IDID.cjs} +3 -3
  97. package/dist/{order-completion-otp-handlers-HFGCPC4O.js → order-completion-otp-handlers-FIW7PZ6W.js} +12 -9
  98. package/dist/{order-completion-otp-handlers-DZAXK4GQ.cjs → order-completion-otp-handlers-LNAZTMTS.cjs} +25 -22
  99. package/dist/{order-inventory-76V4XIGW.js → order-inventory-R3AU6N4V.js} +2 -2
  100. package/dist/{order-inventory-2MYRKEPC.cjs → order-inventory-UUFPWLBW.cjs} +10 -10
  101. package/dist/order-notification-dispatcher-FS54ANAV.js +13 -0
  102. package/dist/order-notification-dispatcher-GG5C4LKZ.cjs +38 -0
  103. package/dist/paid-order-erp-GRXR2OG6.js +3 -0
  104. package/dist/paid-order-erp-X5QHPI23.cjs +12 -0
  105. package/dist/pg-boss-service-CMW3KQJM.js +2 -0
  106. package/dist/pg-boss-service-GA6ZVD5G.cjs +15 -0
  107. package/dist/{razorpay-U23LGY72.cjs → razorpay-GP2DXVP2.cjs} +2 -2
  108. package/dist/{razorpay-KLO2KNCB.js → razorpay-I3G5LNYH.js} +1 -1
  109. package/dist/{rbac-debug-db-KWV7D5PQ.cjs → rbac-debug-db-2ZI3XKA4.cjs} +4 -4
  110. package/dist/{rbac-debug-db-DFZWZ6GV.js → rbac-debug-db-IRKT6G62.js} +2 -2
  111. package/dist/resolve-invoice-asset-url-64QQUVC3.js +2 -0
  112. package/dist/resolve-invoice-asset-url-J7WAMD26.cjs +11 -0
  113. package/dist/retire-soft-deleted-unique-DZALT537.cjs +15 -0
  114. package/dist/{retire-soft-deleted-unique-NXQIH4BC.js → retire-soft-deleted-unique-F25KZBZK.js} +2 -2
  115. package/dist/sms-defaults-DSO3M26Y.js +2 -0
  116. package/dist/{sms-defaults-KCOPKQBA.cjs → sms-defaults-GDFILHHR.cjs} +5 -5
  117. package/dist/{sms-notification-templates-handlers-SJLO7JGZ.js → sms-notification-templates-handlers-ZGDCVS5Z.js} +1 -1
  118. package/dist/{sms-notification-templates-handlers-YSB3L2PK.cjs → sms-notification-templates-handlers-ZKLKFRFZ.cjs} +3 -3
  119. package/dist/{stripe-VU6OEG2D.cjs → stripe-2APRZHKU.cjs} +2 -2
  120. package/dist/{stripe-4FD27QVJ.js → stripe-7CO2ETTN.js} +1 -1
  121. package/dist/theme.cjs +10 -10
  122. package/dist/theme.js +3 -3
  123. package/dist/vendor-invite-status-45ZCWKCX.js +2 -0
  124. package/dist/{vendor-invite-status-77O7ZQ3U.cjs → vendor-invite-status-AT2E4FUA.cjs} +5 -5
  125. package/package.json +2 -1
  126. package/dist/chunk-GLD263KW.cjs +0 -862
  127. package/dist/chunk-OPJEV44S.js +0 -847
  128. package/dist/chunk-SHUYVCID.js +0 -4
  129. package/dist/chunk-USNT2KNT.cjs +0 -6
  130. package/dist/email-queue-4OY45JIU.cjs +0 -26
  131. package/dist/email-queue-HGXB2FIS.js +0 -5
  132. package/dist/email-service-5O24BSFR.cjs +0 -28
  133. package/dist/email-service-ADDF52PJ.js +0 -3
  134. package/dist/emit-order-notification-trigger-EJJZ6XTS.js +0 -3
  135. package/dist/emit-order-notification-trigger-ZD5YN3JM.cjs +0 -16
  136. package/dist/erp-config-enabled-CUMQ6N2V.cjs +0 -11
  137. package/dist/erp-config-enabled-T37X7T34.js +0 -2
  138. package/dist/erp-order-invoice-H6HCJ7YS.js +0 -4
  139. package/dist/erp-order-invoice-YUSPZ7CE.cjs +0 -25
  140. package/dist/interpolate-WAKPN56R.cjs +0 -11
  141. package/dist/interpolate-WDUWDF3I.js +0 -2
  142. package/dist/order-notification-dispatcher-ECPFI7CD.js +0 -10
  143. package/dist/order-notification-dispatcher-LL7ETKLU.cjs +0 -35
  144. package/dist/paid-order-erp-3USEG6WL.js +0 -3
  145. package/dist/paid-order-erp-FSQ3GSXE.cjs +0 -12
  146. package/dist/pg-boss-service-BDGOKM2T.cjs +0 -15
  147. package/dist/pg-boss-service-WCBJD4JB.js +0 -2
  148. package/dist/retire-soft-deleted-unique-5VXBA5XX.cjs +0 -15
  149. package/dist/sms-defaults-2NL24H57.js +0 -2
  150. package/dist/vendor-invite-status-PWJ3DE76.js +0 -2
@@ -1,4 +1,4 @@
1
- import { __name } from './chunk-SHUYVCID.js';
1
+ import { __name } from './chunk-5BKT4CS5.js';
2
2
 
3
3
  // src/plugins/erp/erp-log.ts
4
4
  var ERP_LOG = "[webcore:erp]";
@@ -1,4 +1,4 @@
1
- import { __name } from './chunk-SHUYVCID.js';
1
+ import { __name } from './chunk-5BKT4CS5.js';
2
2
 
3
3
  // src/lib/retire-soft-deleted-unique.ts
4
4
  async function retireSoftDeletedUniqueValue(repo, column, value) {
@@ -0,0 +1,455 @@
1
+ 'use strict';
2
+
3
+ var chunkRQCXRCYM_cjs = require('./chunk-RQCXRCYM.cjs');
4
+ var chunk2JHGIWH7_cjs = require('./chunk-2JHGIWH7.cjs');
5
+ var chunkE62LKM6Z_cjs = require('./chunk-E62LKM6Z.cjs');
6
+ var chunk47G65M5Q_cjs = require('./chunk-47G65M5Q.cjs');
7
+ var chunkEYUBL7YH_cjs = require('./chunk-EYUBL7YH.cjs');
8
+ var chunkXHPRD45G_cjs = require('./chunk-XHPRD45G.cjs');
9
+
10
+ // src/plugins/erp/erp-response-map.ts
11
+ function pickString(o, keys) {
12
+ for (const k of keys) {
13
+ const v = o[k];
14
+ if (typeof v === "string" && v.trim()) return v.trim();
15
+ }
16
+ return void 0;
17
+ }
18
+ chunkXHPRD45G_cjs.__name(pickString, "pickString");
19
+ function unwrapErpReadData(json) {
20
+ if (!json || typeof json !== "object") return null;
21
+ const o = json;
22
+ const d = o.data;
23
+ if (d && typeof d === "object" && !Array.isArray(d)) return d;
24
+ return o;
25
+ }
26
+ chunkXHPRD45G_cjs.__name(unwrapErpReadData, "unwrapErpReadData");
27
+ function firstObject(data, keys) {
28
+ for (const k of keys) {
29
+ const v = data[k];
30
+ if (v && typeof v === "object" && !Array.isArray(v)) return v;
31
+ }
32
+ return null;
33
+ }
34
+ chunkXHPRD45G_cjs.__name(firstObject, "firstObject");
35
+ function extractEvents(src) {
36
+ const timeline = src.timeline ?? src.events ?? src.history ?? src.trackingEvents;
37
+ if (!Array.isArray(timeline) || !timeline.length) return void 0;
38
+ const events = [];
39
+ for (const row of timeline) {
40
+ if (!row || typeof row !== "object") continue;
41
+ const r = row;
42
+ const at = pickString(r, [
43
+ "at",
44
+ "timestamp",
45
+ "date",
46
+ "occurredAt"
47
+ ]) ?? (r.at instanceof Date ? r.at.toISOString() : void 0);
48
+ const label = pickString(r, [
49
+ "label",
50
+ "status",
51
+ "title",
52
+ "message",
53
+ "description"
54
+ ]);
55
+ const detail = pickString(r, [
56
+ "detail",
57
+ "notes",
58
+ "description"
59
+ ]);
60
+ if (at || label || detail) events.push({
61
+ at,
62
+ label,
63
+ detail
64
+ });
65
+ }
66
+ return events.length ? events : void 0;
67
+ }
68
+ chunkXHPRD45G_cjs.__name(extractEvents, "extractEvents");
69
+ function mapErpPayloadToFulfillment(data) {
70
+ const nested = firstObject(data, [
71
+ "fulfillment",
72
+ "packaging",
73
+ "shipment",
74
+ "shipping",
75
+ "delivery"
76
+ ]);
77
+ const src = nested || data;
78
+ const status = pickString(src, [
79
+ "status",
80
+ "fulfillmentStatus",
81
+ "state",
82
+ "label",
83
+ "packagingStatus"
84
+ ]);
85
+ const trackingId = pickString(src, [
86
+ "trackingId",
87
+ "tracking_id",
88
+ "trackingNumber",
89
+ "awb",
90
+ "trackingUrl"
91
+ ]);
92
+ const events = extractEvents(src);
93
+ if (!status && !trackingId && !(events && events.length)) return void 0;
94
+ return {
95
+ status,
96
+ trackingId,
97
+ events
98
+ };
99
+ }
100
+ chunkXHPRD45G_cjs.__name(mapErpPayloadToFulfillment, "mapErpPayloadToFulfillment");
101
+ function mapErpPayloadToInvoiceNumber(data) {
102
+ const nested = firstObject(data, [
103
+ "invoice",
104
+ "latestInvoice",
105
+ "postedInvoice"
106
+ ]);
107
+ const src = nested || data;
108
+ return pickString(src, [
109
+ "invoiceNumber",
110
+ "invoice_number",
111
+ "number",
112
+ "name",
113
+ "id"
114
+ ]);
115
+ }
116
+ chunkXHPRD45G_cjs.__name(mapErpPayloadToInvoiceNumber, "mapErpPayloadToInvoiceNumber");
117
+ function extractChildOrderRefsFromSalePayload(data) {
118
+ const lists = [
119
+ data.returns,
120
+ data.returnOrders,
121
+ data.relatedReturns,
122
+ data.childOrders,
123
+ data.children
124
+ ];
125
+ const seen = /* @__PURE__ */ new Set();
126
+ const out = [];
127
+ for (const list of lists) {
128
+ if (!Array.isArray(list)) continue;
129
+ for (const item of list) {
130
+ if (!item || typeof item !== "object") continue;
131
+ const o = item;
132
+ const ref = pickString(o, [
133
+ "platformReturnId",
134
+ "platform_return_id",
135
+ "refId",
136
+ "ref_id"
137
+ ]) ?? (typeof o.id === "string" ? o.id : void 0);
138
+ if (!ref || seen.has(ref)) continue;
139
+ seen.add(ref);
140
+ const t = (pickString(o, [
141
+ "kind",
142
+ "type",
143
+ "orderKind"
144
+ ]) || "").toLowerCase();
145
+ const orderKind = /replac/.test(t) ? "replacement" : "return";
146
+ out.push({
147
+ ref,
148
+ orderKind
149
+ });
150
+ }
151
+ }
152
+ return out;
153
+ }
154
+ chunkXHPRD45G_cjs.__name(extractChildOrderRefsFromSalePayload, "extractChildOrderRefsFromSalePayload");
155
+
156
+ // src/lib/invoice/build-local-invoice-for-order.ts
157
+ async function loadSettingsGroup(ds, entityMap, group) {
158
+ if (!entityMap.configs) return {};
159
+ const rows = await ds.getRepository(entityMap.configs).find({
160
+ where: {
161
+ settings: group,
162
+ deleted: false
163
+ }
164
+ });
165
+ return Object.fromEntries(rows.map((r) => [
166
+ r.key,
167
+ String(r.value ?? "")
168
+ ]));
169
+ }
170
+ chunkXHPRD45G_cjs.__name(loadSettingsGroup, "loadSettingsGroup");
171
+ function addrFromRow(row) {
172
+ if (!row || typeof row !== "object") return null;
173
+ const a = row;
174
+ return {
175
+ line1: String(a.line1 ?? "").trim() || void 0,
176
+ line2: a.line2 != null ? String(a.line2).trim() || null : null,
177
+ city: String(a.city ?? "").trim() || void 0,
178
+ state: String(a.state ?? "").trim() || void 0,
179
+ postalCode: String(a.postalCode ?? "").trim() || void 0,
180
+ country: String(a.country ?? "").trim() || void 0
181
+ };
182
+ }
183
+ chunkXHPRD45G_cjs.__name(addrFromRow, "addrFromRow");
184
+ async function buildLocalInvoicePdfForOrder(ds, entityMap, orderId) {
185
+ if (!entityMap.orders || !entityMap.order_items) {
186
+ return {
187
+ error: "Orders not configured",
188
+ status: 503
189
+ };
190
+ }
191
+ const orderRepo = ds.getRepository(entityMap.orders);
192
+ let order = null;
193
+ try {
194
+ order = await orderRepo.findOne({
195
+ where: {
196
+ id: orderId,
197
+ deleted: false
198
+ },
199
+ relations: [
200
+ "contact",
201
+ "billingAddress",
202
+ "shippingAddress",
203
+ "items",
204
+ "items.product",
205
+ "assignedUser"
206
+ ]
207
+ });
208
+ } catch {
209
+ try {
210
+ order = await orderRepo.findOne({
211
+ where: {
212
+ id: orderId,
213
+ deleted: false
214
+ },
215
+ relations: [
216
+ "contact",
217
+ "billingAddress",
218
+ "shippingAddress",
219
+ "items",
220
+ "assignedUser"
221
+ ]
222
+ });
223
+ } catch {
224
+ order = await orderRepo.findOne({
225
+ where: {
226
+ id: orderId,
227
+ deleted: false
228
+ },
229
+ relations: [
230
+ "contact",
231
+ "billingAddress",
232
+ "shippingAddress",
233
+ "items"
234
+ ]
235
+ });
236
+ }
237
+ }
238
+ if (!order) return {
239
+ error: "Not found",
240
+ status: 404
241
+ };
242
+ const o = order;
243
+ const kind = o.orderKind || "sale";
244
+ if (kind !== "sale") return {
245
+ error: "Invoice only for sale orders",
246
+ status: 400
247
+ };
248
+ const [store, branding, email] = await Promise.all([
249
+ loadSettingsGroup(ds, entityMap, "store"),
250
+ loadSettingsGroup(ds, entityMap, "branding"),
251
+ loadSettingsGroup(ds, entityMap, "email")
252
+ ]);
253
+ const companyDetails = chunkEYUBL7YH_cjs.mergeEmailLayoutCompanyDetails(branding, email, store);
254
+ const fromBranding = chunkEYUBL7YH_cjs.getCompanyDetailsFromSettings(branding);
255
+ const rawLogo = store.invoiceLogoUrl || store.companyLogo || store.logo || companyDetails.logoUrl || fromBranding.logoUrl || null;
256
+ const logoUrl = chunk47G65M5Q_cjs.resolveInvoiceAssetUrl(rawLogo);
257
+ const companyName = store.companyName || store.invoiceCompanyName || store.name || companyDetails.companyName || fromBranding.companyName || "Store";
258
+ const supportEmail = store.companyEmail || store.invoiceEmail || store.email || companyDetails.supportEmail || fromBranding.supportEmail;
259
+ const supportPhone = store.companyPhone || store.invoicePhone || store.phone || companyDetails.supportPhone;
260
+ const address = store.companyAddress || store.invoiceAddress || store.address;
261
+ const lineItems = (o.items ?? []).map((it) => {
262
+ const name = it.product?.name && String(it.product.name).trim() || `Product #${it.productId ?? ""}`;
263
+ return {
264
+ name,
265
+ quantity: Math.max(0, Math.floor(Number(it.quantity) || 0)),
266
+ unitPrice: Number(it.unitPrice) || 0,
267
+ tax: Number(it.tax) || 0,
268
+ total: Number(it.total) || 0,
269
+ sku: it.product?.sku ?? null
270
+ };
271
+ });
272
+ const rawMeta = o.metadata || {};
273
+ const serviceDate = rawMeta.serviceDate || rawMeta.bookingDate || rawMeta.date || null;
274
+ const timeSlot = rawMeta.timeSlot || rawMeta.slot || rawMeta.time || null;
275
+ const assignedTo = o.assignedUser?.name || null;
276
+ const qrToken = o.qrToken || null;
277
+ const baseUrl = process.env.NEXTAUTH_URL || process.env.PUBLIC_APP_URL || "";
278
+ const qrData = qrToken ? baseUrl ? `${baseUrl.replace(/\/$/, "")}/track/${qrToken}` : `/track/${qrToken}` : String(o.orderNumber || orderId);
279
+ const includeQrCode = store.invoice_include_qr === "true" || store.invoiceIncludeQr === "true";
280
+ const bytes = await chunk2JHGIWH7_cjs.generateLocalInvoicePdf({
281
+ templateId: chunkE62LKM6Z_cjs.normalizeInvoiceTemplateId(store.invoiceTemplate),
282
+ orderNumber: String(o.orderNumber || orderId),
283
+ orderDate: o.createdAt || /* @__PURE__ */ new Date(),
284
+ serviceDate,
285
+ timeSlot,
286
+ assignedTo,
287
+ qrToken,
288
+ qrData,
289
+ includeQrCode,
290
+ currency: String(o.currency || store.currency || "INR"),
291
+ customerName: String(o.contact?.name ?? "").trim() || "Customer",
292
+ customerEmail: o.contact?.email ?? null,
293
+ customerPhone: o.contact?.phone ?? null,
294
+ billingAddress: addrFromRow(o.billingAddress),
295
+ shippingAddress: addrFromRow(o.shippingAddress),
296
+ lineItems,
297
+ subtotal: Number(o.subtotal) || 0,
298
+ tax: Number(o.tax) || 0,
299
+ discount: Number(o.discount) || 0,
300
+ total: Number(o.total) || 0,
301
+ company: {
302
+ name: companyName,
303
+ logoUrl,
304
+ supportEmail,
305
+ supportPhone,
306
+ address
307
+ }
308
+ });
309
+ return {
310
+ bytes,
311
+ filename: `invoice-${String(o.orderNumber || orderId).replace(/[^\w.-]+/g, "_")}.pdf`
312
+ };
313
+ }
314
+ chunkXHPRD45G_cjs.__name(buildLocalInvoicePdfForOrder, "buildLocalInvoicePdfForOrder");
315
+
316
+ // src/plugins/erp/erp-order-invoice.ts
317
+ function pickInvoiceId(data) {
318
+ const nested = data.invoice && typeof data.invoice === "object" && !Array.isArray(data.invoice) ? data.invoice : null;
319
+ const src = nested || data;
320
+ for (const k of [
321
+ "invoiceId",
322
+ "invoice_id",
323
+ "id"
324
+ ]) {
325
+ const v = src[k];
326
+ if (typeof v === "string" && v.trim()) return v.trim();
327
+ }
328
+ return void 0;
329
+ }
330
+ chunkXHPRD45G_cjs.__name(pickInvoiceId, "pickInvoiceId");
331
+ function jsonErr(msg, status) {
332
+ return new Response(JSON.stringify({
333
+ error: msg
334
+ }), {
335
+ status,
336
+ headers: {
337
+ "Content-Type": "application/json"
338
+ }
339
+ });
340
+ }
341
+ chunkXHPRD45G_cjs.__name(jsonErr, "jsonErr");
342
+ var ORDER_INVOICE_EMAIL_ELIGIBLE_STATUSES = /* @__PURE__ */ new Set([
343
+ "pending",
344
+ "placed",
345
+ "confirmed",
346
+ "processing",
347
+ "completed"
348
+ ]);
349
+ function isOrderEligibleForInvoiceEmail(status, orderKind) {
350
+ const kind = (orderKind || "sale").trim().toLowerCase();
351
+ if (kind !== "sale") return false;
352
+ return ORDER_INVOICE_EMAIL_ELIGIBLE_STATUSES.has(String(status ?? "").trim().toLowerCase());
353
+ }
354
+ chunkXHPRD45G_cjs.__name(isOrderEligibleForInvoiceEmail, "isOrderEligibleForInvoiceEmail");
355
+ async function resolveOrderInvoicePdfBytes(cms, dataSource, entityMap, orderId, options = {}) {
356
+ try {
357
+ const orderRepo = dataSource.getRepository(entityMap.orders);
358
+ const order = await orderRepo.findOne({
359
+ where: {
360
+ id: orderId,
361
+ deleted: false
362
+ }
363
+ });
364
+ if (!order) return {
365
+ error: "Not found",
366
+ status: 404
367
+ };
368
+ const kind = order.orderKind || "sale";
369
+ if (kind !== "sale") return {
370
+ error: "Invoice only for sale orders",
371
+ status: 400
372
+ };
373
+ if (options.ownerContactId != null && order.contactId !== options.ownerContactId) {
374
+ return {
375
+ error: "Not found",
376
+ status: 404
377
+ };
378
+ }
379
+ const on = await chunkRQCXRCYM_cjs.isErpIntegrationEnabled(cms, dataSource, entityMap);
380
+ const erp = cms.getPlugin("erp");
381
+ if (on && erp?.submission) {
382
+ const meta = order.metadata && typeof order.metadata === "object" && !Array.isArray(order.metadata) ? order.metadata : {};
383
+ const inv = meta.invoice && typeof meta.invoice === "object" && !Array.isArray(meta.invoice) ? meta.invoice : {};
384
+ let invoiceId = typeof inv.invoiceId === "string" ? inv.invoiceId.trim() : "";
385
+ if (!invoiceId) {
386
+ const refId = String(order.orderNumber || "");
387
+ try {
388
+ const r = await erp.submission.postErpReadAction("get-invoice", {
389
+ platformOrderId: refId
390
+ });
391
+ const d = r.ok ? unwrapErpReadData(r.json) : null;
392
+ invoiceId = d ? pickInvoiceId(d) || "" : "";
393
+ } catch {
394
+ invoiceId = "";
395
+ }
396
+ }
397
+ if (invoiceId) {
398
+ const pdf = await erp.submission.fetchInvoicePdf(invoiceId);
399
+ if (pdf.ok && pdf.buffer) {
400
+ return {
401
+ bytes: new Uint8Array(pdf.buffer),
402
+ filename: `order-invoice-${orderId}.pdf`,
403
+ contentType: pdf.contentType || "application/pdf",
404
+ source: "erp"
405
+ };
406
+ }
407
+ }
408
+ }
409
+ const local = await buildLocalInvoicePdfForOrder(dataSource, entityMap, orderId);
410
+ if ("error" in local) return {
411
+ error: local.error,
412
+ status: local.status
413
+ };
414
+ return {
415
+ bytes: local.bytes,
416
+ filename: local.filename.startsWith("invoice-") ? local.filename.replace(/^invoice-/, "order-invoice-") : local.filename,
417
+ contentType: "application/pdf",
418
+ source: "local"
419
+ };
420
+ } catch (err) {
421
+ const msg = err instanceof Error ? err.message : String(err);
422
+ console.error("[invoice] resolveOrderInvoicePdfBytes failed", {
423
+ orderId,
424
+ error: msg
425
+ });
426
+ return {
427
+ error: `Invoice failed: ${msg}`,
428
+ status: 500
429
+ };
430
+ }
431
+ }
432
+ chunkXHPRD45G_cjs.__name(resolveOrderInvoicePdfBytes, "resolveOrderInvoicePdfBytes");
433
+ async function streamOrderInvoicePdf(cms, dataSource, entityMap, orderId, options) {
434
+ const resolved = await resolveOrderInvoicePdfBytes(cms, dataSource, entityMap, orderId, options);
435
+ if ("error" in resolved) return jsonErr(resolved.error, resolved.status);
436
+ return new Response(Buffer.from(resolved.bytes), {
437
+ status: 200,
438
+ headers: {
439
+ "Content-Type": resolved.contentType,
440
+ "Content-Disposition": `attachment; filename="${resolved.filename}"`,
441
+ "X-Invoice-Source": resolved.source
442
+ }
443
+ });
444
+ }
445
+ chunkXHPRD45G_cjs.__name(streamOrderInvoicePdf, "streamOrderInvoicePdf");
446
+
447
+ exports.ORDER_INVOICE_EMAIL_ELIGIBLE_STATUSES = ORDER_INVOICE_EMAIL_ELIGIBLE_STATUSES;
448
+ exports.buildLocalInvoicePdfForOrder = buildLocalInvoicePdfForOrder;
449
+ exports.extractChildOrderRefsFromSalePayload = extractChildOrderRefsFromSalePayload;
450
+ exports.isOrderEligibleForInvoiceEmail = isOrderEligibleForInvoiceEmail;
451
+ exports.mapErpPayloadToFulfillment = mapErpPayloadToFulfillment;
452
+ exports.mapErpPayloadToInvoiceNumber = mapErpPayloadToInvoiceNumber;
453
+ exports.resolveOrderInvoicePdfBytes = resolveOrderInvoicePdfBytes;
454
+ exports.streamOrderInvoicePdf = streamOrderInvoicePdf;
455
+ exports.unwrapErpReadData = unwrapErpReadData;
@@ -1,4 +1,4 @@
1
- import { __name } from './chunk-SHUYVCID.js';
1
+ import { __name } from './chunk-5BKT4CS5.js';
2
2
  import { SESClient, SendRawEmailCommand, SendEmailCommand } from '@aws-sdk/client-ses';
3
3
  import { createRequire } from 'module';
4
4
  import nodemailer from 'nodemailer';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
3
+ var chunkXHPRD45G_cjs = require('./chunk-XHPRD45G.cjs');
4
4
 
5
5
  // src/message-templates/interpolate.ts
6
6
  function applyTemplateVars(template, variables) {
@@ -13,6 +13,6 @@ function applyTemplateVars(template, variables) {
13
13
  }
14
14
  return out;
15
15
  }
16
- chunkUSNT2KNT_cjs.__name(applyTemplateVars, "applyTemplateVars");
16
+ chunkXHPRD45G_cjs.__name(applyTemplateVars, "applyTemplateVars");
17
17
 
18
18
  exports.applyTemplateVars = applyTemplateVars;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
3
+ var chunkXHPRD45G_cjs = require('./chunk-XHPRD45G.cjs');
4
4
 
5
5
  // src/auth/auth-debug.ts
6
6
  var LOG_PREFIX = "[cms-auth]";
@@ -8,25 +8,25 @@ function isAuthDebugEnabled() {
8
8
  const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
9
9
  return v === "1" || v === "true" || v === "yes";
10
10
  }
11
- chunkUSNT2KNT_cjs.__name(isAuthDebugEnabled, "isAuthDebugEnabled");
11
+ chunkXHPRD45G_cjs.__name(isAuthDebugEnabled, "isAuthDebugEnabled");
12
12
  function isAuthDebugClientEnabled() {
13
13
  if (typeof window === "undefined") return false;
14
14
  const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
15
15
  return v === "1" || v === "true" || v === "yes";
16
16
  }
17
- chunkUSNT2KNT_cjs.__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
17
+ chunkXHPRD45G_cjs.__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
18
18
  function logAuth(message, data) {
19
19
  if (!isAuthDebugEnabled()) return;
20
20
  if (data) console.info(LOG_PREFIX, message, data);
21
21
  else console.info(LOG_PREFIX, message);
22
22
  }
23
- chunkUSNT2KNT_cjs.__name(logAuth, "logAuth");
23
+ chunkXHPRD45G_cjs.__name(logAuth, "logAuth");
24
24
  function logAuthClient(message, data) {
25
25
  if (!isAuthDebugClientEnabled()) return;
26
26
  if (data) console.info(LOG_PREFIX, message, data);
27
27
  else console.info(LOG_PREFIX, message);
28
28
  }
29
- chunkUSNT2KNT_cjs.__name(logAuthClient, "logAuthClient");
29
+ chunkXHPRD45G_cjs.__name(logAuthClient, "logAuthClient");
30
30
  function summarizeSessionUserForLog(user) {
31
31
  if (!user || typeof user !== "object") return {
32
32
  present: false
@@ -42,7 +42,7 @@ function summarizeSessionUserForLog(user) {
42
42
  groupName: u.groupName ?? null
43
43
  };
44
44
  }
45
- chunkUSNT2KNT_cjs.__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
45
+ chunkXHPRD45G_cjs.__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
46
46
  function nextAuthCookieDebugInfo() {
47
47
  const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
48
48
  const isHttps = nextAuthUrl.startsWith("https");
@@ -54,7 +54,7 @@ function nextAuthCookieDebugInfo() {
54
54
  nodeEnv: process.env.NODE_ENV ?? "(unset)"
55
55
  };
56
56
  }
57
- chunkUSNT2KNT_cjs.__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
57
+ chunkXHPRD45G_cjs.__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
58
58
 
59
59
  // src/auth/middleware.ts
60
60
  var defaultPublicApiMethods = {
@@ -97,7 +97,7 @@ function legacyGetSessionToken(request) {
97
97
  const regular = request.cookies.get("next-auth.session-token")?.value;
98
98
  return secure ?? regular;
99
99
  }
100
- chunkUSNT2KNT_cjs.__name(legacyGetSessionToken, "legacyGetSessionToken");
100
+ chunkXHPRD45G_cjs.__name(legacyGetSessionToken, "legacyGetSessionToken");
101
101
  function sessionCookiePresence(request) {
102
102
  const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
103
103
  const regular = request.cookies.get("next-auth.session-token")?.value;
@@ -109,14 +109,14 @@ function sessionCookiePresence(request) {
109
109
  resolved: Boolean(secure ?? regular ?? hasChunked)
110
110
  };
111
111
  }
112
- chunkUSNT2KNT_cjs.__name(sessionCookiePresence, "sessionCookiePresence");
112
+ chunkXHPRD45G_cjs.__name(sessionCookiePresence, "sessionCookiePresence");
113
113
  function isPublicMethod(pathname, method, publicApiMethods) {
114
114
  for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
115
115
  if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
116
116
  }
117
117
  return false;
118
118
  }
119
- chunkUSNT2KNT_cjs.__name(isPublicMethod, "isPublicMethod");
119
+ chunkXHPRD45G_cjs.__name(isPublicMethod, "isPublicMethod");
120
120
  async function hasValidSession(request, secret, legacyGetToken) {
121
121
  const presence = sessionCookiePresence(request);
122
122
  if (presence.resolved || presence.hasChunkedToken) return true;
@@ -133,7 +133,7 @@ async function hasValidSession(request, secret, legacyGetToken) {
133
133
  }
134
134
  return Boolean(legacyGetToken(request));
135
135
  }
136
- chunkUSNT2KNT_cjs.__name(hasValidSession, "hasValidSession");
136
+ chunkXHPRD45G_cjs.__name(hasValidSession, "hasValidSession");
137
137
  function createCmsMiddleware(config = {}) {
138
138
  const { publicAdminPaths = [
139
139
  "/admin/signin",
@@ -141,7 +141,7 @@ function createCmsMiddleware(config = {}) {
141
141
  "/admin/reset-password",
142
142
  "/admin/invite"
143
143
  ], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
144
- return /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async function cmsMiddleware(request) {
144
+ return /* @__PURE__ */ chunkXHPRD45G_cjs.__name(async function cmsMiddleware(request) {
145
145
  const pathname = request.nextUrl.pathname;
146
146
  const method = request.method;
147
147
  if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
@@ -200,7 +200,7 @@ function createCmsMiddleware(config = {}) {
200
200
  };
201
201
  }, "cmsMiddleware");
202
202
  }
203
- chunkUSNT2KNT_cjs.__name(createCmsMiddleware, "createCmsMiddleware");
203
+ chunkXHPRD45G_cjs.__name(createCmsMiddleware, "createCmsMiddleware");
204
204
 
205
205
  exports.createCmsMiddleware = createCmsMiddleware;
206
206
  exports.defaultPublicApiMethods = defaultPublicApiMethods;
@@ -1,5 +1,5 @@
1
- import { explainSessionEntityAccess, isVendorPortalUser, logRbac } from './chunk-5NOZSG6J.js';
2
- import { __name } from './chunk-SHUYVCID.js';
1
+ import { explainSessionEntityAccess, isVendorPortalUser, logRbac } from './chunk-DWNQTFJ5.js';
2
+ import { __name } from './chunk-5BKT4CS5.js';
3
3
  import { IsNull } from 'typeorm';
4
4
 
5
5
  async function linkUnclaimedContactToUser(dataSource, contactsEntity, userId, email) {