@infuro/cms-core 1.0.56 → 1.0.58

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  var chunkXQ3QUHWR_cjs = require('./chunk-XQ3QUHWR.cjs');
4
4
  var chunkHY3AXLOI_cjs = require('./chunk-HY3AXLOI.cjs');
5
- var chunkJN4AFHZ4_cjs = require('./chunk-JN4AFHZ4.cjs');
5
+ var chunkHXLC56ZK_cjs = require('./chunk-HXLC56ZK.cjs');
6
6
  var chunk7NMT3GBR_cjs = require('./chunk-7NMT3GBR.cjs');
7
7
  var chunkV25RDUOU_cjs = require('./chunk-V25RDUOU.cjs');
8
8
  var chunkBXYZDMTZ_cjs = require('./chunk-BXYZDMTZ.cjs');
@@ -10798,7 +10798,7 @@ function createChatHandlers(config) {
10798
10798
  const notifyEmailAgent = await findLlmAgentByScope(dataSource, entityMap, LLM_AGENT_SCOPE_EMAIL_INTENT_CHATBOT, {
10799
10799
  enabledOnly: false
10800
10800
  });
10801
- const emailTool = chunkJN4AFHZ4_cjs.resolveChatEmailToolSettings(llmSettings, {
10801
+ const emailTool = chunkHXLC56ZK_cjs.resolveChatEmailToolSettings(llmSettings, {
10802
10802
  chatbotValidationRules: agentRow?.validationRules ?? null,
10803
10803
  notifyAgent: notifyEmailAgent ? {
10804
10804
  systemInstruction: notifyEmailAgent.systemInstruction,
@@ -10808,7 +10808,7 @@ function createChatHandlers(config) {
10808
10808
  const emailPlugin2 = cms.getPlugin("email");
10809
10809
  const convLeadSent = conv.leadEmailSentAt;
10810
10810
  const chatAgentFn = llm.chatAgent?.bind(llm);
10811
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline check", {
10811
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline check", {
10812
10812
  conversationId,
10813
10813
  enabled: emailTool.enabled,
10814
10814
  intentCount: emailTool.intents.length,
@@ -10822,27 +10822,27 @@ function createChatHandlers(config) {
10822
10822
  mergedPromptIncludesNotify: Boolean(notifyEmailAgent?.systemInstruction?.trim())
10823
10823
  });
10824
10824
  if (!emailTool.enabled) {
10825
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10825
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10826
10826
  conversationId,
10827
10827
  reason: "email_tool_disabled"
10828
10828
  });
10829
10829
  } else if (emailTool.intents.length === 0) {
10830
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10830
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10831
10831
  conversationId,
10832
10832
  reason: "no_intents_configured"
10833
10833
  });
10834
10834
  } else if (!emailPlugin2) {
10835
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10835
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10836
10836
  conversationId,
10837
10837
  reason: "email_plugin_missing"
10838
10838
  });
10839
10839
  } else if (!chatAgentFn) {
10840
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10840
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10841
10841
  conversationId,
10842
10842
  reason: "llm_chat_agent_unavailable"
10843
10843
  });
10844
10844
  } else if (convLeadSent) {
10845
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10845
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10846
10846
  conversationId,
10847
10847
  reason: "lead_email_already_sent",
10848
10848
  leadEmailSentAt: convLeadSent
@@ -10855,7 +10855,7 @@ function createChatHandlers(config) {
10855
10855
  }
10856
10856
  });
10857
10857
  if (!contactRow) {
10858
- console.warn(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10858
+ console.warn(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
10859
10859
  conversationId,
10860
10860
  reason: "contact_not_found",
10861
10861
  contactId
@@ -10863,7 +10863,7 @@ function createChatHandlers(config) {
10863
10863
  } else {
10864
10864
  const c = contactRow;
10865
10865
  try {
10866
- const intent = await chunkJN4AFHZ4_cjs.detectChatLeadIntent({
10866
+ const intent = await chunkHXLC56ZK_cjs.detectChatLeadIntent({
10867
10867
  chatAgent: chatAgentFn
10868
10868
  }, {
10869
10869
  settings: emailTool,
@@ -10877,15 +10877,15 @@ function createChatHandlers(config) {
10877
10877
  model: agentRow?.model?.trim() || notifyEmailAgent?.model?.trim() || void 0
10878
10878
  });
10879
10879
  if (!intent.intent || !intent.emailTo) {
10880
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "no email sent", {
10880
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "no email sent", {
10881
10881
  conversationId,
10882
10882
  reason: intent.intent ? "missing_email_to" : "no_intent_match",
10883
10883
  intentLabel: intent.intentLabel,
10884
10884
  classifierReason: intent.reason
10885
10885
  });
10886
10886
  } else {
10887
- const intentRecipients = chunkJN4AFHZ4_cjs.parseIntentRecipientEmails(intent.emailTo);
10888
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
10887
+ const intentRecipients = chunkHXLC56ZK_cjs.parseIntentRecipientEmails(intent.emailTo);
10888
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
10889
10889
  conversationId,
10890
10890
  intent: intent.intent,
10891
10891
  emailTo: intent.emailTo,
@@ -10895,7 +10895,7 @@ function createChatHandlers(config) {
10895
10895
  const emailSettings = await loadSettingsGroupMap(dataSource, entityMap, "email");
10896
10896
  const brandingSettings = await loadSettingsGroupMap(dataSource, entityMap, "branding");
10897
10897
  const companyDetails = chunkBXYZDMTZ_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings);
10898
- const leadResult = await chunkJN4AFHZ4_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
10898
+ const leadResult = await chunkHXLC56ZK_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
10899
10899
  contactName: String(c.name ?? "").trim() || "Visitor",
10900
10900
  contactEmail: String(c.email ?? "").trim(),
10901
10901
  contactPhone: c.phone ?? null,
@@ -10903,7 +10903,7 @@ function createChatHandlers(config) {
10903
10903
  latestMessage: message,
10904
10904
  intentCode: intent.intent,
10905
10905
  intentReason: intent.intentLabel || intent.reason,
10906
- transcript: chunkJN4AFHZ4_cjs.buildTranscriptForLeadEmail(history, message),
10906
+ transcript: chunkHXLC56ZK_cjs.buildTranscriptForLeadEmail(history, message),
10907
10907
  companyDetails,
10908
10908
  recipients: intentRecipients.length > 0 ? intentRecipients : void 0
10909
10909
  });
@@ -10911,13 +10911,13 @@ function createChatHandlers(config) {
10911
10911
  await convRepo().update(conversationId, {
10912
10912
  leadEmailSentAt: /* @__PURE__ */ new Date()
10913
10913
  });
10914
- console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
10914
+ console.info(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
10915
10915
  conversationId,
10916
10916
  sent: true,
10917
10917
  recipients: leadResult.recipients
10918
10918
  });
10919
10919
  } else {
10920
- console.warn(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
10920
+ console.warn(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
10921
10921
  conversationId,
10922
10922
  sent: false,
10923
10923
  error: leadResult.error ?? "unknown",
@@ -10926,7 +10926,7 @@ function createChatHandlers(config) {
10926
10926
  }
10927
10927
  }
10928
10928
  } catch (intentErr) {
10929
- console.warn(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline error", {
10929
+ console.warn(chunkHXLC56ZK_cjs.CHAT_EMAIL_LOG, "pipeline error", {
10930
10930
  conversationId,
10931
10931
  error: intentErr instanceof Error ? intentErr.message : String(intentErr)
10932
10932
  });
@@ -10943,7 +10943,7 @@ function createChatHandlers(config) {
10943
10943
  });
10944
10944
  if (agentRow && llm.chatAgent) {
10945
10945
  const fromAgent = llmAgentToChatAgentOptions(agentRow);
10946
- const systemPrompt = chunkJN4AFHZ4_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
10946
+ const systemPrompt = chunkHXLC56ZK_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
10947
10947
  const res = await llm.chatAgent({
10948
10948
  ...fromAgent,
10949
10949
  systemPrompt: systemPrompt || void 0,
@@ -10964,7 +10964,7 @@ ${contextParts.join("\n\n")}` : "";
10964
10964
  agentRow.systemInstruction?.trim(),
10965
10965
  ragSystem
10966
10966
  ].filter(Boolean).join("\n\n");
10967
- systemContent = chunkJN4AFHZ4_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
10967
+ systemContent = chunkHXLC56ZK_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
10968
10968
  } else {
10969
10969
  systemContent = ragSystem || defaultSystem;
10970
10970
  }
@@ -12066,8 +12066,11 @@ exports.UserDeviceToken = class UserDeviceToken {
12066
12066
  chunkUSNT2KNT_cjs.__name(this, "UserDeviceToken");
12067
12067
  }
12068
12068
  id;
12069
+ /** Staff/vendor app store. Null for customer/marketplace tokens (membership is `vendor_customers`). */
12069
12070
  vendorId;
12071
+ vendor;
12070
12072
  userId;
12073
+ user;
12071
12074
  token;
12072
12075
  platform;
12073
12076
  deviceId;
@@ -12083,18 +12086,38 @@ _ts_decorate2([
12083
12086
  ], exports.UserDeviceToken.prototype, "id", void 0);
12084
12087
  _ts_decorate2([
12085
12088
  typeorm.Column({
12086
- type: "uuid",
12087
- name: "vendor_id"
12089
+ type: "integer",
12090
+ name: "vendor_id",
12091
+ nullable: true
12088
12092
  }),
12089
- _ts_metadata2("design:type", String)
12093
+ _ts_metadata2("design:type", Object)
12090
12094
  ], exports.UserDeviceToken.prototype, "vendorId", void 0);
12095
+ _ts_decorate2([
12096
+ typeorm.ManyToOne("Vendor", {
12097
+ onDelete: "CASCADE",
12098
+ nullable: true
12099
+ }),
12100
+ typeorm.JoinColumn({
12101
+ name: "vendor_id"
12102
+ }),
12103
+ _ts_metadata2("design:type", Object)
12104
+ ], exports.UserDeviceToken.prototype, "vendor", void 0);
12091
12105
  _ts_decorate2([
12092
12106
  typeorm.Column({
12093
- type: "uuid",
12107
+ type: "integer",
12094
12108
  name: "user_id"
12095
12109
  }),
12096
- _ts_metadata2("design:type", String)
12110
+ _ts_metadata2("design:type", Number)
12097
12111
  ], exports.UserDeviceToken.prototype, "userId", void 0);
12112
+ _ts_decorate2([
12113
+ typeorm.ManyToOne("User", {
12114
+ onDelete: "CASCADE"
12115
+ }),
12116
+ typeorm.JoinColumn({
12117
+ name: "user_id"
12118
+ }),
12119
+ _ts_metadata2("design:type", Object)
12120
+ ], exports.UserDeviceToken.prototype, "user", void 0);
12098
12121
  _ts_decorate2([
12099
12122
  typeorm.Column({
12100
12123
  type: "text"
@@ -12169,6 +12192,22 @@ exports.UserDeviceToken = _ts_decorate2([
12169
12192
  ], exports.UserDeviceToken);
12170
12193
 
12171
12194
  // src/api/device-tokens-handlers.ts
12195
+ function parseRequiredPositiveInt(value, field) {
12196
+ const n = parseInt(String(value ?? "").trim(), 10);
12197
+ if (!Number.isFinite(n) || n <= 0) {
12198
+ return {
12199
+ error: `${field} must be a positive integer`
12200
+ };
12201
+ }
12202
+ return n;
12203
+ }
12204
+ chunkUSNT2KNT_cjs.__name(parseRequiredPositiveInt, "parseRequiredPositiveInt");
12205
+ function parseOptionalVendorId(value) {
12206
+ if (value == null) return null;
12207
+ if (typeof value === "string" && value.trim() === "") return null;
12208
+ return parseRequiredPositiveInt(value, "vendor_id");
12209
+ }
12210
+ chunkUSNT2KNT_cjs.__name(parseOptionalVendorId, "parseOptionalVendorId");
12172
12211
  function createDeviceTokensHandlers(config) {
12173
12212
  const { dataSource, entityMap, json } = config;
12174
12213
  return /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async function handleDeviceTokensApi(req, pathSegments) {
@@ -12180,7 +12219,7 @@ function createDeviceTokensHandlers(config) {
12180
12219
  const title = body.title?.trim() || "Test Push Notification";
12181
12220
  const msgBody = body.body?.trim() || "Firebase Push Notification setup is working!";
12182
12221
  if (!token || token === "validate" || token === "validate_only") {
12183
- const valRes = await validateFcmCredentials(dataSource, entityMap);
12222
+ const valRes = await chunkHXLC56ZK_cjs.validateFcmCredentials(dataSource, entityMap);
12184
12223
  if (!valRes.success) {
12185
12224
  return json({
12186
12225
  success: false,
@@ -12197,7 +12236,7 @@ function createDeviceTokensHandlers(config) {
12197
12236
  clientEmail: valRes.clientEmail
12198
12237
  });
12199
12238
  }
12200
- const res = await chunkJN4AFHZ4_cjs.sendFcmPushNotification(dataSource, entityMap, {
12239
+ const res = await chunkHXLC56ZK_cjs.sendFcmPushNotification(dataSource, entityMap, {
12201
12240
  token,
12202
12241
  title,
12203
12242
  body: msgBody,
@@ -12240,18 +12279,28 @@ function createDeviceTokensHandlers(config) {
12240
12279
  if (method === "POST") {
12241
12280
  try {
12242
12281
  const body = await req.json().catch(() => ({}));
12243
- const vendorId = body.vendor_id?.trim();
12244
- const userId = body.user_id?.trim();
12282
+ const vendorParsed = parseOptionalVendorId(body.vendor_id);
12283
+ const userParsed = parseRequiredPositiveInt(body.user_id, "user_id");
12245
12284
  const token = body.token?.trim();
12246
12285
  const platformRaw = body.platform?.trim().toLowerCase();
12247
- if (!vendorId || !userId || !token || !platformRaw) {
12286
+ if (vendorParsed !== null && typeof vendorParsed === "object") {
12287
+ return json({
12288
+ success: false,
12289
+ error: vendorParsed.error
12290
+ }, {
12291
+ status: 400
12292
+ });
12293
+ }
12294
+ if (typeof userParsed === "object" || !token || !platformRaw) {
12248
12295
  return json({
12249
12296
  success: false,
12250
- error: "vendor_id, user_id, token, and platform (android|ios) are required"
12297
+ error: (typeof userParsed === "object" ? userParsed.error : null) || "user_id, token, and platform (android|ios) are required"
12251
12298
  }, {
12252
12299
  status: 400
12253
12300
  });
12254
12301
  }
12302
+ const vendorId = vendorParsed;
12303
+ const userId = userParsed;
12255
12304
  if (platformRaw !== "android" && platformRaw !== "ios") {
12256
12305
  return json({
12257
12306
  success: false,
@@ -12317,13 +12366,35 @@ function createDeviceTokensHandlers(config) {
12317
12366
  if (method === "GET") {
12318
12367
  try {
12319
12368
  const url = new URL(req.url);
12320
- const userId = url.searchParams.get("userId")?.trim();
12321
- const vendorId = url.searchParams.get("vendorId")?.trim();
12369
+ const userIdRaw = url.searchParams.get("userId")?.trim();
12370
+ const vendorIdRaw = url.searchParams.get("vendorId")?.trim();
12322
12371
  const whereCondition = {
12323
12372
  isActive: true
12324
12373
  };
12325
- if (userId) whereCondition.userId = userId;
12326
- if (vendorId) whereCondition.vendorId = vendorId;
12374
+ if (userIdRaw) {
12375
+ const userId = parseRequiredPositiveInt(userIdRaw, "userId");
12376
+ if (typeof userId === "object") {
12377
+ return json({
12378
+ success: false,
12379
+ error: userId.error
12380
+ }, {
12381
+ status: 400
12382
+ });
12383
+ }
12384
+ whereCondition.userId = userId;
12385
+ }
12386
+ if (vendorIdRaw) {
12387
+ const vendorId = parseRequiredPositiveInt(vendorIdRaw, "vendorId");
12388
+ if (typeof vendorId === "object") {
12389
+ return json({
12390
+ success: false,
12391
+ error: vendorId.error
12392
+ }, {
12393
+ status: 400
12394
+ });
12395
+ }
12396
+ whereCondition.vendorId = vendorId;
12397
+ }
12327
12398
  const tokens = await tokenRepo.find({
12328
12399
  where: whereCondition,
12329
12400
  order: {
@@ -12350,16 +12421,17 @@ function createDeviceTokensHandlers(config) {
12350
12421
  if (method === "DELETE") {
12351
12422
  try {
12352
12423
  const body = await req.json().catch(() => ({}));
12353
- const userId = body.user_id?.trim();
12424
+ const userParsed = parseRequiredPositiveInt(body.user_id, "user_id");
12354
12425
  const token = body.token?.trim();
12355
- if (!userId || !token) {
12426
+ if (typeof userParsed === "object" || !token) {
12356
12427
  return json({
12357
12428
  success: false,
12358
- error: "user_id and token are required to deactivate"
12429
+ error: (typeof userParsed === "object" ? userParsed.error : null) || "user_id and token are required to deactivate"
12359
12430
  }, {
12360
12431
  status: 400
12361
12432
  });
12362
12433
  }
12434
+ const userId = userParsed;
12363
12435
  await tokenRepo.update({
12364
12436
  userId,
12365
12437
  token
@@ -13159,7 +13231,7 @@ async function sendVendorOnboardEmails(input, deps) {
13159
13231
  getVendorEmails(deps)
13160
13232
  ]);
13161
13233
  const companyDetails = chunkBXYZDMTZ_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings);
13162
- const configuredNotify = chunkJN4AFHZ4_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
13234
+ const configuredNotify = chunkHXLC56ZK_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
13163
13235
  const ownerEmail = input.ownerEmail?.trim() || "";
13164
13236
  const ownerEmailLower = ownerEmail.toLowerCase();
13165
13237
  const sendToOwner = input.sendToOwner !== false;
@@ -27728,16 +27800,16 @@ function whatsappPlugin(config = {}) {
27728
27800
  db = await getWhatsAppSettings?.() ?? {};
27729
27801
  } catch {
27730
27802
  }
27731
- if (!chunkJN4AFHZ4_cjs.isWhatsAppPluginEnabled(db)) {
27803
+ if (!chunkHXLC56ZK_cjs.isWhatsAppPluginEnabled(db)) {
27732
27804
  context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
27733
27805
  return null;
27734
27806
  }
27735
- const merged = chunkJN4AFHZ4_cjs.mergeWhatsAppConfigLayers(env, db, staticRest);
27736
- if (!getWhatsAppSettings && !chunkJN4AFHZ4_cjs.whatsAppConfigured(merged)) {
27807
+ const merged = chunkHXLC56ZK_cjs.mergeWhatsAppConfigLayers(env, db, staticRest);
27808
+ if (!getWhatsAppSettings && !chunkHXLC56ZK_cjs.whatsAppConfigured(merged)) {
27737
27809
  context.logger.warn("WhatsApp plugin skipped: set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID, or pass getWhatsAppSettings");
27738
27810
  return null;
27739
27811
  }
27740
- const svc = new chunkJN4AFHZ4_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
27812
+ const svc = new chunkHXLC56ZK_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
27741
27813
  return {
27742
27814
  send: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((opts) => svc.send(opts), "send")
27743
27815
  };
@@ -27814,7 +27886,7 @@ function registerMessagingQueueProcessors(cms, entityMap) {
27814
27886
  getDataSource: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => cms.dataSource, "getDataSource"),
27815
27887
  entityMap
27816
27888
  });
27817
- chunkJN4AFHZ4_cjs.registerWhatsAppQueueProcessor(cms);
27889
+ chunkHXLC56ZK_cjs.registerWhatsAppQueueProcessor(cms);
27818
27890
  }
27819
27891
  chunkUSNT2KNT_cjs.__name(registerMessagingQueueProcessors, "registerMessagingQueueProcessors");
27820
27892
  async function ensureMessagingPluginsOnCms(base, options) {
@@ -27843,7 +27915,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
27843
27915
  }
27844
27916
  if (!cms.getPlugin("email")) {
27845
27917
  try {
27846
- const instance = await chunkJN4AFHZ4_cjs.emailPlugin({
27918
+ const instance = await chunkHXLC56ZK_cjs.emailPlugin({
27847
27919
  type: "SMTP",
27848
27920
  from: config.SMTP_FROM ?? "no-reply@localhost",
27849
27921
  to: config.SMTP_TO ?? ""
@@ -27884,7 +27956,7 @@ function messagingPlugins(options) {
27884
27956
  const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
27885
27957
  return [
27886
27958
  queuePlugin(),
27887
- chunkJN4AFHZ4_cjs.emailPlugin({
27959
+ chunkHXLC56ZK_cjs.emailPlugin({
27888
27960
  type: "SMTP",
27889
27961
  from: config.SMTP_FROM ?? "no-reply@localhost",
27890
27962
  to: config.SMTP_TO ?? ""
@@ -28018,7 +28090,7 @@ function createCmsApiHandler(config) {
28018
28090
  } : void 0;
28019
28091
  const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
28020
28092
  if (getCms) {
28021
- chunkJN4AFHZ4_cjs.initWhatsappTriggerDispatcher({
28093
+ chunkHXLC56ZK_cjs.initWhatsappTriggerDispatcher({
28022
28094
  dataSource,
28023
28095
  entityMap,
28024
28096
  getCms
@@ -29781,7 +29853,7 @@ function createCmsApiHandler(config) {
29781
29853
  status: 400
29782
29854
  });
29783
29855
  }
29784
- const { resendOrderNotification } = await import('./order-notification-dispatcher-YBAWDOIO.cjs');
29856
+ const { resendOrderNotification } = await import('./order-notification-dispatcher-2FCZFZUD.cjs');
29785
29857
  const result = await resendOrderNotification(triggerKey, orderId, {
29786
29858
  dataSource,
29787
29859
  entityMap,
@@ -1331,7 +1331,7 @@ function renderEmail(templateName, ctx, options) {
1331
1331
  chunkUSNT2KNT_cjs.__name(renderEmail, "renderEmail");
1332
1332
 
1333
1333
  // src/plugins/email/email-service.ts
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)));
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-HXLC56ZK.cjs', document.baseURI).href)));
1335
1335
  var MailComposer = require2("nodemailer/lib/mail-composer");
1336
1336
  var SES_REGIONS_WITHOUT_SMTP = /* @__PURE__ */ new Set([
1337
1337
  "af-south-1",
@@ -2194,6 +2194,48 @@ async function sendFcmPushNotification(dataSource, entityMap, msg) {
2194
2194
  }
2195
2195
  }
2196
2196
  chunkUSNT2KNT_cjs.__name(sendFcmPushNotification, "sendFcmPushNotification");
2197
+ async function validateFcmCredentials(dataSource, entityMap) {
2198
+ try {
2199
+ const pushSettings = await getSettingsGroup(dataSource, entityMap, "push");
2200
+ let projectId = pushSettings.firebase_project_id?.trim();
2201
+ let clientEmail = pushSettings.firebase_client_email?.trim();
2202
+ let privateKey = pushSettings.firebase_private_key?.trim();
2203
+ if (pushSettings.firebase_service_account_json?.trim()) {
2204
+ try {
2205
+ const parsed = JSON.parse(pushSettings.firebase_service_account_json.trim());
2206
+ if (parsed.project_id) projectId = parsed.project_id;
2207
+ if (parsed.client_email) clientEmail = parsed.client_email;
2208
+ if (parsed.private_key) privateKey = parsed.private_key;
2209
+ } catch {
2210
+ }
2211
+ }
2212
+ if (!projectId || !clientEmail || !privateKey) {
2213
+ return {
2214
+ success: false,
2215
+ error: "Firebase Service Account JSON / credentials are not configured in settings"
2216
+ };
2217
+ }
2218
+ const token = await getGoogleAccessToken(clientEmail, privateKey);
2219
+ if (!token) {
2220
+ return {
2221
+ success: false,
2222
+ error: "Failed to obtain Google OAuth access token"
2223
+ };
2224
+ }
2225
+ return {
2226
+ success: true,
2227
+ projectId,
2228
+ clientEmail
2229
+ };
2230
+ } catch (err) {
2231
+ const msg = err instanceof Error ? err.message : "Credential validation failed";
2232
+ return {
2233
+ success: false,
2234
+ error: msg
2235
+ };
2236
+ }
2237
+ }
2238
+ chunkUSNT2KNT_cjs.__name(validateFcmCredentials, "validateFcmCredentials");
2197
2239
 
2198
2240
  // src/lib/order-notification-dispatcher.ts
2199
2241
  var initialized = false;
@@ -2876,4 +2918,5 @@ exports.resolveChatEmailToolSettings = resolveChatEmailToolSettings;
2876
2918
  exports.sendChatLeadEmail = sendChatLeadEmail;
2877
2919
  exports.sendFcmPushNotification = sendFcmPushNotification;
2878
2920
  exports.serializeEmailRecipients = serializeEmailRecipients;
2921
+ exports.validateFcmCredentials = validateFcmCredentials;
2879
2922
  exports.whatsAppConfigured = whatsAppConfigured;
@@ -2168,6 +2168,48 @@ async function sendFcmPushNotification(dataSource, entityMap, msg) {
2168
2168
  }
2169
2169
  }
2170
2170
  __name(sendFcmPushNotification, "sendFcmPushNotification");
2171
+ async function validateFcmCredentials(dataSource, entityMap) {
2172
+ try {
2173
+ const pushSettings = await getSettingsGroup(dataSource, entityMap, "push");
2174
+ let projectId = pushSettings.firebase_project_id?.trim();
2175
+ let clientEmail = pushSettings.firebase_client_email?.trim();
2176
+ let privateKey = pushSettings.firebase_private_key?.trim();
2177
+ if (pushSettings.firebase_service_account_json?.trim()) {
2178
+ try {
2179
+ const parsed = JSON.parse(pushSettings.firebase_service_account_json.trim());
2180
+ if (parsed.project_id) projectId = parsed.project_id;
2181
+ if (parsed.client_email) clientEmail = parsed.client_email;
2182
+ if (parsed.private_key) privateKey = parsed.private_key;
2183
+ } catch {
2184
+ }
2185
+ }
2186
+ if (!projectId || !clientEmail || !privateKey) {
2187
+ return {
2188
+ success: false,
2189
+ error: "Firebase Service Account JSON / credentials are not configured in settings"
2190
+ };
2191
+ }
2192
+ const token = await getGoogleAccessToken(clientEmail, privateKey);
2193
+ if (!token) {
2194
+ return {
2195
+ success: false,
2196
+ error: "Failed to obtain Google OAuth access token"
2197
+ };
2198
+ }
2199
+ return {
2200
+ success: true,
2201
+ projectId,
2202
+ clientEmail
2203
+ };
2204
+ } catch (err) {
2205
+ const msg = err instanceof Error ? err.message : "Credential validation failed";
2206
+ return {
2207
+ success: false,
2208
+ error: msg
2209
+ };
2210
+ }
2211
+ }
2212
+ __name(validateFcmCredentials, "validateFcmCredentials");
2171
2213
 
2172
2214
  // src/lib/order-notification-dispatcher.ts
2173
2215
  var initialized = false;
@@ -2825,4 +2867,4 @@ async function resendOrderNotification(triggerKey, orderId, deps) {
2825
2867
  }
2826
2868
  __name(resendOrderNotification, "resendOrderNotification");
2827
2869
 
2828
- export { CHAT_EMAIL_LOG, EmailService, WhatsAppService, buildChatbotSystemPromptWithEmailTool, buildEventOrderTemplateVariables, buildTranscriptForLeadEmail, detectChatLeadIntent, emailPlugin, emailTemplates, getSettingsGroup, initWhatsappTriggerDispatcher, isWhatsAppPluginEnabled, joinRecipientsForSend, mergeWhatsAppConfigLayers, parseEmailRecipientsFromConfig, parseIntentRecipientEmails, queueWhatsApp, registerWhatsAppQueueProcessor, renderEmail, renderLayout, resendOrderNotification, resolveChatEmailToolSettings, sendChatLeadEmail, sendFcmPushNotification, serializeEmailRecipients, whatsAppConfigured };
2870
+ export { CHAT_EMAIL_LOG, EmailService, WhatsAppService, buildChatbotSystemPromptWithEmailTool, buildEventOrderTemplateVariables, buildTranscriptForLeadEmail, detectChatLeadIntent, emailPlugin, emailTemplates, getSettingsGroup, initWhatsappTriggerDispatcher, isWhatsAppPluginEnabled, joinRecipientsForSend, mergeWhatsAppConfigLayers, parseEmailRecipientsFromConfig, parseIntentRecipientEmails, queueWhatsApp, registerWhatsAppQueueProcessor, renderEmail, renderLayout, resendOrderNotification, resolveChatEmailToolSettings, sendChatLeadEmail, sendFcmPushNotification, serializeEmailRecipients, validateFcmCredentials, whatsAppConfigured };