@infuro/cms-core 1.0.50 → 1.0.52

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 (31) hide show
  1. package/dist/admin.cjs +843 -402
  2. package/dist/admin.d.cts +13 -1
  3. package/dist/admin.d.ts +13 -1
  4. package/dist/admin.js +843 -402
  5. package/dist/api.cjs +35 -35
  6. package/dist/api.js +4 -4
  7. package/dist/auth.cjs +44 -43
  8. package/dist/auth.d.cts +2 -3
  9. package/dist/auth.d.ts +2 -3
  10. package/dist/auth.js +2 -1
  11. package/dist/{chunk-JCMOOPNX.cjs → chunk-3BPD5NGU.cjs} +210 -90
  12. package/dist/chunk-7L6KWI7S.cjs +212 -0
  13. package/dist/{chunk-YV5PK4JW.cjs → chunk-BC22I7C7.cjs} +45 -247
  14. package/dist/{chunk-WRKV6MHB.js → chunk-BNKZNLEX.js} +2 -196
  15. package/dist/{chunk-IPDHT2UV.js → chunk-CTXBYO2J.js} +94 -104
  16. package/dist/{chunk-UUWAUHUW.cjs → chunk-JN4AFHZ4.cjs} +94 -105
  17. package/dist/{chunk-JE22VP6S.js → chunk-MXIWUFBP.js} +1 -1
  18. package/dist/{chunk-LT2WOPKA.js → chunk-UO5Q5RXB.js} +181 -61
  19. package/dist/{chunk-KOTXDSQB.cjs → chunk-UQWZUZ5X.cjs} +1 -1
  20. package/dist/chunk-WUQAOTHA.js +203 -0
  21. package/dist/{emit-order-notification-trigger-6XX7LSC4.js → emit-order-notification-trigger-HZQPPSFB.js} +1 -1
  22. package/dist/{emit-order-notification-trigger-NASG7ZEO.cjs → emit-order-notification-trigger-NR3VN6C6.cjs} +3 -3
  23. package/dist/index.cjs +334 -299
  24. package/dist/index.d.cts +6 -4
  25. package/dist/index.d.ts +6 -4
  26. package/dist/index.js +59 -24
  27. package/dist/middleware.cjs +15 -0
  28. package/dist/middleware.js +2 -0
  29. package/dist/{order-notification-dispatcher-3TA4ETYJ.js → order-notification-dispatcher-AT4IFAGL.js} +2 -2
  30. package/dist/{order-notification-dispatcher-ZEAZ5SHV.cjs → order-notification-dispatcher-YBAWDOIO.cjs} +5 -5
  31. package/package.json +6 -1
@@ -83,6 +83,9 @@ function buildEventOrderTemplateVariables(input) {
83
83
  currency: String(order.currency ?? "INR"),
84
84
  lines: orderLines
85
85
  };
86
+ const qrToken = order.qrToken?.trim() || order.orderNumber?.trim() || "";
87
+ const fallbackQrUrl = qrToken ? `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrToken)}` : "";
88
+ const fallbackTicketQr = fallbackQrUrl ? `<img src="${fallbackQrUrl}" alt="Ticket QR Code" width="200" height="200" style="display:block;margin:12px 0;border:1px solid #e5e7eb;border-radius:8px;" />` : "";
86
89
  return {
87
90
  eventName: event.name ?? productNames ?? "",
88
91
  vendorName: vendorName.trim(),
@@ -99,6 +102,8 @@ function buildEventOrderTemplateVariables(input) {
99
102
  trackUrl,
100
103
  invoiceNumber,
101
104
  invoiceUrl,
105
+ ticketQr: fallbackTicketQr,
106
+ qrImageUrl: fallbackQrUrl,
102
107
  orderDetails: formatOrderDetailsText(orderDetailsPayload),
103
108
  orderDetailsHtml: formatOrderDetailsHtml(orderDetailsPayload)
104
109
  };
@@ -1326,7 +1331,7 @@ function renderEmail(templateName, ctx, options) {
1326
1331
  chunkUSNT2KNT_cjs.__name(renderEmail, "renderEmail");
1327
1332
 
1328
1333
  // src/plugins/email/email-service.ts
1329
- var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-UUWAUHUW.cjs', document.baseURI).href)));
1334
+ var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-JN4AFHZ4.cjs', document.baseURI).href)));
1330
1335
  var MailComposer = require2("nodemailer/lib/mail-composer");
1331
1336
  var SES_REGIONS_WITHOUT_SMTP = /* @__PURE__ */ new Set([
1332
1337
  "af-south-1",
@@ -2125,72 +2130,27 @@ async function getGoogleAccessToken(clientEmail, privateKey) {
2125
2130
  return tokenData.access_token;
2126
2131
  }
2127
2132
  chunkUSNT2KNT_cjs.__name(getGoogleAccessToken, "getGoogleAccessToken");
2128
- async function resolveFcmServiceAccount(dataSource, entityMap) {
2129
- const pushSettings = await getSettingsGroup(dataSource, entityMap, "push");
2130
- let projectId = pushSettings.firebase_project_id?.trim();
2131
- let clientEmail = pushSettings.firebase_client_email?.trim();
2132
- let privateKey = pushSettings.firebase_private_key?.trim();
2133
- if (pushSettings.firebase_service_account_json?.trim()) {
2134
- try {
2135
- const parsed = JSON.parse(pushSettings.firebase_service_account_json.trim());
2136
- if (parsed.project_id) projectId = parsed.project_id;
2137
- if (parsed.client_email) clientEmail = parsed.client_email;
2138
- if (parsed.private_key) privateKey = parsed.private_key;
2139
- } catch {
2140
- }
2141
- }
2142
- if (!projectId || !clientEmail || !privateKey) {
2143
- return {
2144
- ok: false,
2145
- error: "Firebase Service Account JSON / credentials are not configured"
2146
- };
2147
- }
2148
- return {
2149
- ok: true,
2150
- account: {
2151
- projectId,
2152
- clientEmail,
2153
- privateKey
2154
- }
2155
- };
2156
- }
2157
- chunkUSNT2KNT_cjs.__name(resolveFcmServiceAccount, "resolveFcmServiceAccount");
2158
- async function validateFcmCredentials(dataSource, entityMap) {
2159
- try {
2160
- const resolved = await resolveFcmServiceAccount(dataSource, entityMap);
2161
- if (!resolved.ok) {
2162
- return {
2163
- success: false,
2164
- error: resolved.error
2165
- };
2166
- }
2167
- const { projectId, clientEmail, privateKey } = resolved.account;
2168
- await getGoogleAccessToken(clientEmail, privateKey);
2169
- return {
2170
- success: true,
2171
- projectId,
2172
- clientEmail
2173
- };
2174
- } catch (err) {
2175
- const errorMsg = err instanceof Error ? err.message : "Unknown credential validation error";
2176
- console.error("[fcm-push] Exception in validateFcmCredentials", errorMsg);
2177
- return {
2178
- success: false,
2179
- error: errorMsg
2180
- };
2181
- }
2182
- }
2183
- chunkUSNT2KNT_cjs.__name(validateFcmCredentials, "validateFcmCredentials");
2184
2133
  async function sendFcmPushNotification(dataSource, entityMap, msg) {
2185
2134
  try {
2186
- const resolved = await resolveFcmServiceAccount(dataSource, entityMap);
2187
- if (!resolved.ok) {
2135
+ const pushSettings = await getSettingsGroup(dataSource, entityMap, "push");
2136
+ let projectId = pushSettings.firebase_project_id?.trim();
2137
+ let clientEmail = pushSettings.firebase_client_email?.trim();
2138
+ let privateKey = pushSettings.firebase_private_key?.trim();
2139
+ if (pushSettings.firebase_service_account_json?.trim()) {
2140
+ try {
2141
+ const parsed = JSON.parse(pushSettings.firebase_service_account_json.trim());
2142
+ if (parsed.project_id) projectId = parsed.project_id;
2143
+ if (parsed.client_email) clientEmail = parsed.client_email;
2144
+ if (parsed.private_key) privateKey = parsed.private_key;
2145
+ } catch {
2146
+ }
2147
+ }
2148
+ if (!projectId || !clientEmail || !privateKey) {
2188
2149
  return {
2189
2150
  success: false,
2190
- error: resolved.error
2151
+ error: "Firebase Service Account JSON / credentials are not configured"
2191
2152
  };
2192
2153
  }
2193
- const { projectId, clientEmail, privateKey } = resolved.account;
2194
2154
  const accessToken = await getGoogleAccessToken(clientEmail, privateKey);
2195
2155
  const fcmEndpoint = `https://fcm.googleapis.com/v1/projects/${projectId}/messages:send`;
2196
2156
  const fcmPayload = {
@@ -2301,59 +2261,69 @@ async function loadBoundTemplate(triggerKey, channel, audienceType = "customers"
2301
2261
  console.warn("[order-notifications] order_notification_bindings or message_templates missing from entityMap");
2302
2262
  return null;
2303
2263
  }
2304
- const bindingRepo = dataSource.getRepository(entityMap.order_notification_bindings);
2305
- let binding = await bindingRepo.findOne({
2306
- where: {
2307
- triggerKey,
2308
- channel,
2309
- type: audienceType,
2310
- enabled: true
2311
- }
2312
- });
2313
- if (!binding && audienceType === "customers") {
2314
- binding = await bindingRepo.findOne({
2264
+ try {
2265
+ const bindingRepo = dataSource.getRepository(entityMap.order_notification_bindings);
2266
+ let binding = await bindingRepo.findOne({
2315
2267
  where: {
2316
2268
  triggerKey,
2317
2269
  channel,
2270
+ type: audienceType,
2318
2271
  enabled: true
2319
2272
  }
2320
- });
2321
- }
2322
- if (!binding) {
2323
- console.warn("[order-notifications] no order_notification_bindings row", {
2324
- triggerKey,
2325
- channel,
2326
- audienceType
2327
- });
2328
- return null;
2329
- }
2330
- const templateId = binding.messageTemplateId;
2331
- if (templateId == null) {
2332
- console.warn("[order-notifications] binding exists but no template selected", {
2333
- triggerKey,
2334
- channel,
2335
- audienceType
2336
- });
2337
- return null;
2338
- }
2339
- const template = await dataSource.getRepository(entityMap.message_templates).findOne({
2340
- where: {
2341
- id: templateId,
2342
- channel,
2343
- deleted: false,
2344
- enabled: true
2273
+ }).catch(() => null);
2274
+ if (!binding && audienceType === "customers") {
2275
+ binding = await bindingRepo.findOne({
2276
+ where: {
2277
+ triggerKey,
2278
+ channel,
2279
+ enabled: true
2280
+ }
2281
+ }).catch(() => null);
2345
2282
  }
2346
- });
2347
- if (!template) {
2348
- console.warn("[order-notifications] bound template not found or disabled", {
2283
+ if (!binding) {
2284
+ console.warn("[order-notifications] no order_notification_bindings row", {
2285
+ triggerKey,
2286
+ channel,
2287
+ audienceType
2288
+ });
2289
+ return null;
2290
+ }
2291
+ const templateId = binding.messageTemplateId;
2292
+ if (templateId == null) {
2293
+ console.warn("[order-notifications] binding exists but no template selected", {
2294
+ triggerKey,
2295
+ channel,
2296
+ audienceType
2297
+ });
2298
+ return null;
2299
+ }
2300
+ const template = await dataSource.getRepository(entityMap.message_templates).findOne({
2301
+ where: {
2302
+ id: templateId,
2303
+ channel,
2304
+ deleted: false,
2305
+ enabled: true
2306
+ }
2307
+ }).catch(() => null);
2308
+ if (!template) {
2309
+ console.warn("[order-notifications] bound template not found or disabled", {
2310
+ triggerKey,
2311
+ channel,
2312
+ audienceType,
2313
+ templateId
2314
+ });
2315
+ return null;
2316
+ }
2317
+ return template;
2318
+ } catch (err) {
2319
+ console.warn("[order-notifications] loadBoundTemplate query failed", {
2349
2320
  triggerKey,
2350
2321
  channel,
2351
2322
  audienceType,
2352
- templateId
2323
+ error: err instanceof Error ? err.message : String(err)
2353
2324
  });
2354
2325
  return null;
2355
2326
  }
2356
- return template;
2357
2327
  }
2358
2328
  chunkUSNT2KNT_cjs.__name(loadBoundTemplate, "loadBoundTemplate");
2359
2329
  function mergeTriggerVariables(payload, rich) {
@@ -2370,9 +2340,11 @@ function mergeTriggerVariables(payload, rich) {
2370
2340
  refundAmount: String(payload.refundAmount)
2371
2341
  } : {}
2372
2342
  };
2343
+ const extraVars = payload.extraVariables ?? {};
2373
2344
  return {
2374
2345
  ...basic,
2375
- ...rich ?? {}
2346
+ ...rich ?? {},
2347
+ ...extraVars
2376
2348
  };
2377
2349
  }
2378
2350
  chunkUSNT2KNT_cjs.__name(mergeTriggerVariables, "mergeTriggerVariables");
@@ -2568,7 +2540,23 @@ async function getAdminRecipientEmails(dataSource, entityMap) {
2568
2540
  }
2569
2541
  } catch {
2570
2542
  }
2571
- return Array.from(emails);
2543
+ const vendorEmails = /* @__PURE__ */ new Set();
2544
+ try {
2545
+ const vRows = await dataSource.query(`SELECT DISTINCT LOWER(TRIM(email)) AS email FROM vendors WHERE COALESCE(deleted, false) = false AND email IS NOT NULL AND TRIM(email) != ''`).catch(() => []);
2546
+ for (const r of vRows) {
2547
+ if (r.email) vendorEmails.add(r.email.toLowerCase());
2548
+ }
2549
+ const vuRows = await dataSource.query(`SELECT DISTINCT LOWER(TRIM(u.email)) AS email
2550
+ FROM users u
2551
+ LEFT JOIN user_groups g ON g.id = u."groupId"
2552
+ WHERE COALESCE(u.deleted, false) = false
2553
+ AND (LOWER(g.name) LIKE '%vendor%' OR u."groupId" = 5)`).catch(() => []);
2554
+ for (const r of vuRows) {
2555
+ if (r.email) vendorEmails.add(r.email.toLowerCase());
2556
+ }
2557
+ } catch {
2558
+ }
2559
+ return Array.from(emails).filter((e) => !vendorEmails.has(e.toLowerCase()));
2572
2560
  }
2573
2561
  chunkUSNT2KNT_cjs.__name(getAdminRecipientEmails, "getAdminRecipientEmails");
2574
2562
  function formatBodyForEmailHtml(body) {
@@ -2802,6 +2790,8 @@ function initWhatsappTriggerDispatcher(deps) {
2802
2790
  if (initialized) return;
2803
2791
  initialized = true;
2804
2792
  const { dataSource, entityMap, getCms } = deps;
2793
+ void dataSource.query(`ALTER TYPE "order_notification_bindings_channel_enum" ADD VALUE IF NOT EXISTS 'mobile'`).catch(() => {
2794
+ });
2805
2795
  chunkUCKN4BBY_cjs.notificationTriggerEmitter.onAnyTrigger((triggerKey, payload) => {
2806
2796
  void handleTrigger(triggerKey, payload, dataSource, entityMap, getCms).catch((err) => {
2807
2797
  console.error("[order-notifications]", triggerKey, err);
@@ -2886,5 +2876,4 @@ exports.resolveChatEmailToolSettings = resolveChatEmailToolSettings;
2886
2876
  exports.sendChatLeadEmail = sendChatLeadEmail;
2887
2877
  exports.sendFcmPushNotification = sendFcmPushNotification;
2888
2878
  exports.serializeEmailRecipients = serializeEmailRecipients;
2889
- exports.validateFcmCredentials = validateFcmCredentials;
2890
2879
  exports.whatsAppConfigured = whatsAppConfigured;
@@ -59,7 +59,7 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
59
59
  total: fo.total ?? 0,
60
60
  currency: String(fo.currency ?? "INR"),
61
61
  vendorId: fo.vendorId ?? null,
62
- ...extra?.extraVariables ?? {},
62
+ extraVariables: extra?.extraVariables,
63
63
  ...extra?.refundAmount != null ? {
64
64
  refundAmount: extra.refundAmount
65
65
  } : {}