@infuro/cms-core 1.0.36 → 1.0.38

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 (29) hide show
  1. package/dist/admin.cjs +459 -496
  2. package/dist/admin.js +459 -496
  3. package/dist/api.cjs +36 -36
  4. package/dist/api.js +4 -4
  5. package/dist/auth.cjs +51 -51
  6. package/dist/auth.js +3 -3
  7. package/dist/{chunk-COBORIJH.cjs → chunk-22FFHLTO.cjs} +39 -56
  8. package/dist/{chunk-X6H5VBQ2.cjs → chunk-E6WVP7BK.cjs} +6 -6
  9. package/dist/{chunk-VMY2S32H.js → chunk-NNQBWDCI.js} +39 -56
  10. package/dist/{chunk-WO2DW4AU.cjs → chunk-OIGCAGH7.cjs} +7 -7
  11. package/dist/{chunk-UF3BYUXY.js → chunk-P7QCLE5W.js} +4 -3
  12. package/dist/{chunk-JS2W7XZ4.js → chunk-PYUXVU75.js} +243 -23
  13. package/dist/{chunk-FG6I64HP.js → chunk-SBRBR3VO.js} +1 -1
  14. package/dist/{chunk-LI2IXVAY.js → chunk-UXMDSNIG.js} +1 -1
  15. package/dist/{chunk-2AEVFOQP.cjs → chunk-VJDUKAJ3.cjs} +310 -90
  16. package/dist/{chunk-KPKFNLQQ.cjs → chunk-WMXPKKXU.cjs} +4 -3
  17. package/dist/index.cjs +260 -260
  18. package/dist/index.d.cts +12 -5
  19. package/dist/index.d.ts +12 -5
  20. package/dist/index.js +8 -8
  21. package/dist/migrations/1775500000000-RssFeedsAndArticles.ts +0 -1
  22. package/dist/migrations/1775700000000-JobSchedules.ts +0 -1
  23. package/dist/migrations/1781260000000-RenameWhatsappTriggerBindingsToOrderNotificationBindings.ts +92 -0
  24. package/dist/migrations/1781270000000-ComboVendorId.ts +58 -0
  25. package/dist/{whatsapp-trigger-dispatcher-ONHXI7UY.cjs → order-notification-dispatcher-RU7BTGGX.cjs} +3 -4
  26. package/dist/{whatsapp-trigger-dispatcher-PWFI4FKP.js → order-notification-dispatcher-XWIJYDGA.js} +1 -2
  27. package/dist/{rbac-debug-db-HWP65A4O.cjs → rbac-debug-db-KHG4FJC3.cjs} +2 -2
  28. package/dist/{rbac-debug-db-QJH3AD34.js → rbac-debug-db-QWHOENBR.js} +1 -1
  29. package/package.json +1 -1
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var chunkCOBORIJH_cjs = require('./chunk-COBORIJH.cjs');
3
+ var chunk22FFHLTO_cjs = require('./chunk-22FFHLTO.cjs');
4
4
  var chunk7NMT3GBR_cjs = require('./chunk-7NMT3GBR.cjs');
5
5
  var chunkPNOKNSG2_cjs = require('./chunk-PNOKNSG2.cjs');
6
6
  var chunkXW5ATPRW_cjs = require('./chunk-XW5ATPRW.cjs');
7
7
  var chunk3DZRIZOD_cjs = require('./chunk-3DZRIZOD.cjs');
8
8
  var chunkSPQFNIYJ_cjs = require('./chunk-SPQFNIYJ.cjs');
9
9
  var chunkXQ3QUHWR_cjs = require('./chunk-XQ3QUHWR.cjs');
10
- var chunkWO2DW4AU_cjs = require('./chunk-WO2DW4AU.cjs');
11
- var chunkKPKFNLQQ_cjs = require('./chunk-KPKFNLQQ.cjs');
10
+ var chunkOIGCAGH7_cjs = require('./chunk-OIGCAGH7.cjs');
11
+ var chunkWMXPKKXU_cjs = require('./chunk-WMXPKKXU.cjs');
12
12
  var chunkD5FBNKQM_cjs = require('./chunk-D5FBNKQM.cjs');
13
13
  var chunkUPLVMVRX_cjs = require('./chunk-UPLVMVRX.cjs');
14
14
  var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
@@ -87,7 +87,7 @@ async function loadUserVendorContext(dataSource, userId, preferredVendorId) {
87
87
  `, [
88
88
  primary.vendorRoleId
89
89
  ]);
90
- vendorEntityPerms = chunkKPKFNLQQ_cjs.permissionRowsToRecord(permRows);
90
+ vendorEntityPerms = chunkWMXPKKXU_cjs.permissionRowsToRecord(permRows);
91
91
  } catch (err) {
92
92
  if (!isMissingVendorRoleSchemaError(err)) throw err;
93
93
  }
@@ -120,7 +120,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
120
120
  ]);
121
121
  const resolvedId = Number(byEmailRows[0]?.id);
122
122
  if (!Number.isFinite(resolvedId)) {
123
- chunkKPKFNLQQ_cjs.logRbac("hydrateVendorSessionUser: unable to resolve numeric user id", {
123
+ chunkWMXPKKXU_cjs.logRbac("hydrateVendorSessionUser: unable to resolve numeric user id", {
124
124
  email: user.email,
125
125
  rawSessionId: user.id ?? null
126
126
  });
@@ -140,7 +140,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
140
140
  const groupName = rows[0]?.groupName ?? user.groupName ?? null;
141
141
  const groupId = rows[0]?.groupId ?? user.groupId ?? void 0;
142
142
  const adminAccess = rows[0]?.adminAccess ?? user.adminAccess;
143
- const isRBACAdmin = user.isRBACAdmin ?? chunkKPKFNLQQ_cjs.isSuperAdmin({
143
+ const isRBACAdmin = user.isRBACAdmin ?? chunkWMXPKKXU_cjs.isSuperAdmin({
144
144
  groupId,
145
145
  groupName,
146
146
  isRBACAdmin: user.isRBACAdmin
@@ -153,7 +153,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
153
153
  };
154
154
  if (multiVendorEnabled) {
155
155
  ctx = await loadUserVendorContext(dataSource, id, user.activeVendorId);
156
- flags = chunkKPKFNLQQ_cjs.vendorPortalFlagsFromUser({
156
+ flags = chunkWMXPKKXU_cjs.vendorPortalFlagsFromUser({
157
157
  email: user.email,
158
158
  isRBACAdmin,
159
159
  groupName,
@@ -188,7 +188,7 @@ async function hydrateVendorSessionUser(dataSource, user) {
188
188
  isVendorPortal: flags.isVendorPortal,
189
189
  isVendorOwner: flags.isVendorOwner
190
190
  };
191
- chunkKPKFNLQQ_cjs.logRbac("hydrateVendorSessionUser", {
191
+ chunkWMXPKKXU_cjs.logRbac("hydrateVendorSessionUser", {
192
192
  email: user.email,
193
193
  userId: id,
194
194
  groupName,
@@ -332,7 +332,7 @@ function repoHasVendorIdColumn(repo) {
332
332
  }
333
333
  chunkUSNT2KNT_cjs.__name(repoHasVendorIdColumn, "repoHasVendorIdColumn");
334
334
  function resourceUsesVendorScope(resource) {
335
- return resource === "vendors" || chunkKPKFNLQQ_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
335
+ return resource === "vendors" || chunkWMXPKKXU_cjs.VENDOR_SCOPED_STORE_ENTITIES.has(resource);
336
336
  }
337
337
  chunkUSNT2KNT_cjs.__name(resourceUsesVendorScope, "resourceUsesVendorScope");
338
338
  function mergeVendorScopeIntoWhere(where, scope, resource) {
@@ -2617,10 +2617,11 @@ async function calculateOrderTotalsFromLines(dataSource, entityMap, lineInputs,
2617
2617
  }
2618
2618
  });
2619
2619
  if (combo) {
2620
- const comboRows = await dataSource.query(`SELECT p."vendorId", ci."productId" as "firstProductId"
2620
+ const comboVendorId = Number(combo.vendorId);
2621
+ const comboRows = await dataSource.query(`SELECT ci."productId" as "firstProductId"
2621
2622
  FROM combo_items ci
2622
2623
  JOIN products p ON p.id = ci."productId"
2623
- WHERE ci."comboId" = $1 AND p.deleted = false AND p."vendorId" IS NOT NULL
2624
+ WHERE ci."comboId" = $1 AND p.deleted = false
2624
2625
  LIMIT 1`, [
2625
2626
  productId
2626
2627
  ]);
@@ -2637,7 +2638,8 @@ async function calculateOrderTotalsFromLines(dataSource, entityMap, lineInputs,
2637
2638
  ...childProduct,
2638
2639
  id: productId,
2639
2640
  price: combo.price,
2640
- name: combo.name
2641
+ name: combo.name,
2642
+ vendorId: Number.isFinite(comboVendorId) && comboVendorId > 0 ? comboVendorId : childProduct.vendorId
2641
2643
  };
2642
2644
  }
2643
2645
  }
@@ -5193,6 +5195,7 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
5193
5195
  });
5194
5196
  }
5195
5197
  if (resource === "combos") {
5198
+ const scope2 = await resolveScopeById();
5196
5199
  const combo = await repo.findOne({
5197
5200
  where: {
5198
5201
  id: Number(id),
@@ -5203,6 +5206,8 @@ function createCrudByIdHandler(dataSource, entityMap, options) {
5203
5206
  "items.product"
5204
5207
  ]
5205
5208
  });
5209
+ const comboDenied = vendorScopeAccessJson(combo, scope2, resource);
5210
+ if (comboDenied) return comboDenied;
5206
5211
  return combo ? json(combo) : json({
5207
5212
  message: "Not found"
5208
5213
  }, {
@@ -7408,7 +7413,7 @@ function createVendorDashboardHandler(config) {
7408
7413
  if (pe) return pe;
7409
7414
  }
7410
7415
  const user = await getSessionUser();
7411
- if (!user || !chunkKPKFNLQQ_cjs.isVendorPortalUser(user)) {
7416
+ if (!user || !chunkWMXPKKXU_cjs.isVendorPortalUser(user)) {
7412
7417
  return json({
7413
7418
  error: "Forbidden"
7414
7419
  }, {
@@ -9632,7 +9637,7 @@ function createChatHandlers(config) {
9632
9637
  const notifyEmailAgent = await findLlmAgentByScope(dataSource, entityMap, LLM_AGENT_SCOPE_EMAIL_INTENT_CHATBOT, {
9633
9638
  enabledOnly: false
9634
9639
  });
9635
- const emailTool = chunkCOBORIJH_cjs.resolveChatEmailToolSettings(llmSettings, {
9640
+ const emailTool = chunk22FFHLTO_cjs.resolveChatEmailToolSettings(llmSettings, {
9636
9641
  chatbotValidationRules: agentRow?.validationRules ?? null,
9637
9642
  notifyAgent: notifyEmailAgent ? {
9638
9643
  systemInstruction: notifyEmailAgent.systemInstruction,
@@ -9642,7 +9647,7 @@ function createChatHandlers(config) {
9642
9647
  const emailPlugin2 = cms.getPlugin("email");
9643
9648
  const convLeadSent = conv.leadEmailSentAt;
9644
9649
  const chatAgentFn = llm.chatAgent?.bind(llm);
9645
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline check", {
9650
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline check", {
9646
9651
  conversationId,
9647
9652
  enabled: emailTool.enabled,
9648
9653
  intentCount: emailTool.intents.length,
@@ -9656,27 +9661,27 @@ function createChatHandlers(config) {
9656
9661
  mergedPromptIncludesNotify: Boolean(notifyEmailAgent?.systemInstruction?.trim())
9657
9662
  });
9658
9663
  if (!emailTool.enabled) {
9659
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9664
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9660
9665
  conversationId,
9661
9666
  reason: "email_tool_disabled"
9662
9667
  });
9663
9668
  } else if (emailTool.intents.length === 0) {
9664
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9669
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9665
9670
  conversationId,
9666
9671
  reason: "no_intents_configured"
9667
9672
  });
9668
9673
  } else if (!emailPlugin2) {
9669
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9674
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9670
9675
  conversationId,
9671
9676
  reason: "email_plugin_missing"
9672
9677
  });
9673
9678
  } else if (!chatAgentFn) {
9674
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9679
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9675
9680
  conversationId,
9676
9681
  reason: "llm_chat_agent_unavailable"
9677
9682
  });
9678
9683
  } else if (convLeadSent) {
9679
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9684
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9680
9685
  conversationId,
9681
9686
  reason: "lead_email_already_sent",
9682
9687
  leadEmailSentAt: convLeadSent
@@ -9689,7 +9694,7 @@ function createChatHandlers(config) {
9689
9694
  }
9690
9695
  });
9691
9696
  if (!contactRow) {
9692
- console.warn(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9697
+ console.warn(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
9693
9698
  conversationId,
9694
9699
  reason: "contact_not_found",
9695
9700
  contactId
@@ -9697,7 +9702,7 @@ function createChatHandlers(config) {
9697
9702
  } else {
9698
9703
  const c = contactRow;
9699
9704
  try {
9700
- const intent = await chunkCOBORIJH_cjs.detectChatLeadIntent({
9705
+ const intent = await chunk22FFHLTO_cjs.detectChatLeadIntent({
9701
9706
  chatAgent: chatAgentFn
9702
9707
  }, {
9703
9708
  settings: emailTool,
@@ -9711,15 +9716,15 @@ function createChatHandlers(config) {
9711
9716
  model: agentRow?.model?.trim() || notifyEmailAgent?.model?.trim() || void 0
9712
9717
  });
9713
9718
  if (!intent.intent || !intent.emailTo) {
9714
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "no email sent", {
9719
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "no email sent", {
9715
9720
  conversationId,
9716
9721
  reason: intent.intent ? "missing_email_to" : "no_intent_match",
9717
9722
  intentLabel: intent.intentLabel,
9718
9723
  classifierReason: intent.reason
9719
9724
  });
9720
9725
  } else {
9721
- const intentRecipients = chunkCOBORIJH_cjs.parseIntentRecipientEmails(intent.emailTo);
9722
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
9726
+ const intentRecipients = chunk22FFHLTO_cjs.parseIntentRecipientEmails(intent.emailTo);
9727
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
9723
9728
  conversationId,
9724
9729
  intent: intent.intent,
9725
9730
  emailTo: intent.emailTo,
@@ -9728,8 +9733,8 @@ function createChatHandlers(config) {
9728
9733
  });
9729
9734
  const emailSettings = await loadSettingsGroupMap(dataSource, entityMap, "email");
9730
9735
  const brandingSettings = await loadSettingsGroupMap(dataSource, entityMap, "branding");
9731
- const companyDetails = chunkCOBORIJH_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings);
9732
- const leadResult = await chunkCOBORIJH_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
9736
+ const companyDetails = chunk22FFHLTO_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings);
9737
+ const leadResult = await chunk22FFHLTO_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
9733
9738
  contactName: String(c.name ?? "").trim() || "Visitor",
9734
9739
  contactEmail: String(c.email ?? "").trim(),
9735
9740
  contactPhone: c.phone ?? null,
@@ -9737,7 +9742,7 @@ function createChatHandlers(config) {
9737
9742
  latestMessage: message,
9738
9743
  intentCode: intent.intent,
9739
9744
  intentReason: intent.intentLabel || intent.reason,
9740
- transcript: chunkCOBORIJH_cjs.buildTranscriptForLeadEmail(history, message),
9745
+ transcript: chunk22FFHLTO_cjs.buildTranscriptForLeadEmail(history, message),
9741
9746
  companyDetails,
9742
9747
  recipients: intentRecipients.length > 0 ? intentRecipients : void 0
9743
9748
  });
@@ -9745,13 +9750,13 @@ function createChatHandlers(config) {
9745
9750
  await convRepo().update(conversationId, {
9746
9751
  leadEmailSentAt: /* @__PURE__ */ new Date()
9747
9752
  });
9748
- console.info(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
9753
+ console.info(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
9749
9754
  conversationId,
9750
9755
  sent: true,
9751
9756
  recipients: leadResult.recipients
9752
9757
  });
9753
9758
  } else {
9754
- console.warn(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
9759
+ console.warn(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
9755
9760
  conversationId,
9756
9761
  sent: false,
9757
9762
  error: leadResult.error ?? "unknown",
@@ -9760,7 +9765,7 @@ function createChatHandlers(config) {
9760
9765
  }
9761
9766
  }
9762
9767
  } catch (intentErr) {
9763
- console.warn(chunkCOBORIJH_cjs.CHAT_EMAIL_LOG, "pipeline error", {
9768
+ console.warn(chunk22FFHLTO_cjs.CHAT_EMAIL_LOG, "pipeline error", {
9764
9769
  conversationId,
9765
9770
  error: intentErr instanceof Error ? intentErr.message : String(intentErr)
9766
9771
  });
@@ -9777,7 +9782,7 @@ function createChatHandlers(config) {
9777
9782
  });
9778
9783
  if (agentRow && llm.chatAgent) {
9779
9784
  const fromAgent = llmAgentToChatAgentOptions(agentRow);
9780
- const systemPrompt = chunkCOBORIJH_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
9785
+ const systemPrompt = chunk22FFHLTO_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
9781
9786
  const res = await llm.chatAgent({
9782
9787
  ...fromAgent,
9783
9788
  systemPrompt: systemPrompt || void 0,
@@ -9798,7 +9803,7 @@ ${contextParts.join("\n\n")}` : "";
9798
9803
  agentRow.systemInstruction?.trim(),
9799
9804
  ragSystem
9800
9805
  ].filter(Boolean).join("\n\n");
9801
- systemContent = chunkCOBORIJH_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
9806
+ systemContent = chunk22FFHLTO_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
9802
9807
  } else {
9803
9808
  systemContent = ragSystem || defaultSystem;
9804
9809
  }
@@ -11209,7 +11214,7 @@ chunkUSNT2KNT_cjs.__name(findActiveRefundPolicyForVendor, "findActiveRefundPolic
11209
11214
  // src/api/admin-roles-handlers.ts
11210
11215
  function createAdminRolesHandlers(config) {
11211
11216
  const { dataSource, entityMap, json, getSessionUser } = config;
11212
- const baseEntities = chunkKPKFNLQQ_cjs.getPermissionableEntityKeys(entityMap);
11217
+ const baseEntities = chunkWMXPKKXU_cjs.getPermissionableEntityKeys(entityMap);
11213
11218
  const allowEntities = /* @__PURE__ */ new Set([
11214
11219
  ...baseEntities,
11215
11220
  "users"
@@ -11224,7 +11229,7 @@ function createAdminRolesHandlers(config) {
11224
11229
  }, {
11225
11230
  status: 401
11226
11231
  });
11227
- if (!chunkWO2DW4AU_cjs.canManageRoles(u) && !chunkKPKFNLQQ_cjs.canManageVendorRoles(u)) {
11232
+ if (!chunkOIGCAGH7_cjs.canManageRoles(u) && !chunkWMXPKKXU_cjs.canManageVendorRoles(u)) {
11228
11233
  return json({
11229
11234
  error: "Forbidden"
11230
11235
  }, {
@@ -11235,11 +11240,11 @@ function createAdminRolesHandlers(config) {
11235
11240
  }
11236
11241
  chunkUSNT2KNT_cjs.__name(gate, "gate");
11237
11242
  function isVendorRolesOnly(u) {
11238
- return chunkKPKFNLQQ_cjs.canManageVendorRoles(u) && !chunkWO2DW4AU_cjs.canManageRoles(u);
11243
+ return chunkWMXPKKXU_cjs.canManageVendorRoles(u) && !chunkOIGCAGH7_cjs.canManageRoles(u);
11239
11244
  }
11240
11245
  chunkUSNT2KNT_cjs.__name(isVendorRolesOnly, "isVendorRolesOnly");
11241
11246
  const vendorRoleEntities = [
11242
- ...chunkKPKFNLQQ_cjs.VENDOR_STORE_RBAC_ENTITIES,
11247
+ ...chunkWMXPKKXU_cjs.VENDOR_STORE_RBAC_ENTITIES,
11243
11248
  "dashboard",
11244
11249
  "settings"
11245
11250
  ].sort();
@@ -11396,7 +11401,7 @@ function createAdminRolesHandlers(config) {
11396
11401
  }, {
11397
11402
  status: 404
11398
11403
  });
11399
- if (chunkKPKFNLQQ_cjs.isSuperAdminGroupName(g.name) && !chunkKPKFNLQQ_cjs.isSuperAdminGroupName(name)) {
11404
+ if (chunkWMXPKKXU_cjs.isSuperAdminGroupName(g.name) && !chunkWMXPKKXU_cjs.isSuperAdminGroupName(name)) {
11400
11405
  return json({
11401
11406
  error: "Cannot rename the administrator group"
11402
11407
  }, {
@@ -11453,7 +11458,7 @@ function createAdminRolesHandlers(config) {
11453
11458
  }, {
11454
11459
  status: 404
11455
11460
  });
11456
- if (chunkKPKFNLQQ_cjs.isSuperAdminGroupName(g.name)) return json({
11461
+ if (chunkWMXPKKXU_cjs.isSuperAdminGroupName(g.name)) return json({
11457
11462
  error: "Cannot delete the administrator group"
11458
11463
  }, {
11459
11464
  status: 400
@@ -11592,8 +11597,8 @@ async function sendVendorOnboardEmails(input, deps) {
11592
11597
  getSettingsGroup(deps, "branding"),
11593
11598
  getSettingsGroup(deps, "email")
11594
11599
  ]);
11595
- const companyDetails = chunkCOBORIJH_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings);
11596
- const notifyEmails = chunkCOBORIJH_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
11600
+ const companyDetails = chunk22FFHLTO_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings);
11601
+ const notifyEmails = chunk22FFHLTO_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
11597
11602
  const sendToOwner = input.sendToOwner !== false;
11598
11603
  const ownerEmail = input.ownerEmail?.trim() || "";
11599
11604
  const cms = await deps.getCms();
@@ -11621,7 +11626,7 @@ chunkUSNT2KNT_cjs.__name(sendVendorOnboardEmails, "sendVendorOnboardEmails");
11621
11626
 
11622
11627
  // src/lib/seed-vendor-roles.ts
11623
11628
  async function insertRolePermissions(exec, vendorRoleId, permissions) {
11624
- for (const entity of chunkKPKFNLQQ_cjs.VENDOR_RBAC_ENTITIES) {
11629
+ for (const entity of chunkWMXPKKXU_cjs.VENDOR_RBAC_ENTITIES) {
11625
11630
  const flags = permissions[entity];
11626
11631
  if (!flags) continue;
11627
11632
  await exec.query(`
@@ -11652,7 +11657,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
11652
11657
  for (const r of existing) {
11653
11658
  roleIdsByName2[r.name] = Number(r.id);
11654
11659
  if (r.isOwnerRole) ownerRoleId2 = Number(r.id);
11655
- if (r.name === chunkKPKFNLQQ_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
11660
+ if (r.name === chunkWMXPKKXU_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId2 = Number(r.id);
11656
11661
  }
11657
11662
  return {
11658
11663
  roleIdsByName: roleIdsByName2,
@@ -11663,7 +11668,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
11663
11668
  const roleIdsByName = {};
11664
11669
  let ownerRoleId = 0;
11665
11670
  let viewerRoleId = 0;
11666
- for (const def of chunkKPKFNLQQ_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
11671
+ for (const def of chunkWMXPKKXU_cjs.DEFAULT_VENDOR_ROLE_DEFS) {
11667
11672
  const inserted = await exec.query(`
11668
11673
  INSERT INTO "vendor_roles"
11669
11674
  ("vendorId", "name", "description", "isSystem", "isOwnerRole")
@@ -11680,7 +11685,7 @@ async function seedVendorDefaultRoles(em, vendorId) {
11680
11685
  if (!roleId) continue;
11681
11686
  roleIdsByName[def.name] = roleId;
11682
11687
  if (def.isOwnerRole) ownerRoleId = roleId;
11683
- if (def.name === chunkKPKFNLQQ_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
11688
+ if (def.name === chunkWMXPKKXU_cjs.VENDOR_VIEWER_ROLE_NAME) viewerRoleId = roleId;
11684
11689
  await insertRolePermissions(exec, roleId, def.permissions);
11685
11690
  }
11686
11691
  return {
@@ -11701,7 +11706,7 @@ async function backfillVendorUserRoleIds(em, vendorId, seeded) {
11701
11706
  vendorId
11702
11707
  ]);
11703
11708
  }
11704
- const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunkKPKFNLQQ_cjs.VENDOR_VIEWER_ROLE_NAME];
11709
+ const viewerId = seeded.viewerRoleId || seeded.roleIdsByName[chunkWMXPKKXU_cjs.VENDOR_VIEWER_ROLE_NAME];
11705
11710
  if (viewerId) {
11706
11711
  await em.query(`
11707
11712
  UPDATE "vendor_users"
@@ -11727,7 +11732,7 @@ async function getDefaultStaffRoleIdForVendor(em, vendorId) {
11727
11732
  LIMIT 1
11728
11733
  `, [
11729
11734
  vendorId,
11730
- chunkKPKFNLQQ_cjs.VENDOR_VIEWER_ROLE_NAME
11735
+ chunkWMXPKKXU_cjs.VENDOR_VIEWER_ROLE_NAME
11731
11736
  ]);
11732
11737
  const id = rows[0]?.id;
11733
11738
  return id != null ? Number(id) : null;
@@ -11825,7 +11830,7 @@ function createVendorOnboardHandlers(config) {
11825
11830
  }, {
11826
11831
  status: 401
11827
11832
  });
11828
- if (!chunkKPKFNLQQ_cjs.isPlatformAdministrator(u)) return json({
11833
+ if (!chunkWMXPKKXU_cjs.isPlatformAdministrator(u)) return json({
11829
11834
  error: "Forbidden",
11830
11835
  reason: "admin_only"
11831
11836
  }, {
@@ -11835,7 +11840,7 @@ function createVendorOnboardHandlers(config) {
11835
11840
  }
11836
11841
  chunkUSNT2KNT_cjs.__name(gateAdmin, "gateAdmin");
11837
11842
  async function resolveActiveVendorId(u) {
11838
- const scope = chunkKPKFNLQQ_cjs.resolveVendorScopeFromSessionUser(u);
11843
+ const scope = chunkWMXPKKXU_cjs.resolveVendorScopeFromSessionUser(u);
11839
11844
  if (scope.type === "vendor") return scope.vendorId;
11840
11845
  if (scope.type === "all") {
11841
11846
  const id = u.activeVendorId ?? u.vendorIds?.[0];
@@ -11851,7 +11856,7 @@ function createVendorOnboardHandlers(config) {
11851
11856
  }, {
11852
11857
  status: 401
11853
11858
  });
11854
- if (!chunkKPKFNLQQ_cjs.canManageVendorTeam(u)) return json({
11859
+ if (!chunkWMXPKKXU_cjs.canManageVendorTeam(u)) return json({
11855
11860
  error: "Forbidden"
11856
11861
  }, {
11857
11862
  status: 403
@@ -11986,7 +11991,7 @@ function createVendorOnboardHandlers(config) {
11986
11991
  if (dupVendor) throw new Error("VENDOR_SLUG_EXISTS");
11987
11992
  const ownerGroup = await groupRepo.findOne({
11988
11993
  where: {
11989
- name: chunkKPKFNLQQ_cjs.VENDOR_OWNER_GROUP_NAME,
11994
+ name: chunkWMXPKKXU_cjs.VENDOR_OWNER_GROUP_NAME,
11990
11995
  deleted: false
11991
11996
  }
11992
11997
  });
@@ -12368,7 +12373,7 @@ function createVendorOnboardHandlers(config) {
12368
12373
  if (!groupId) {
12369
12374
  const g = await groupRepo.findOne({
12370
12375
  where: {
12371
- name: chunkKPKFNLQQ_cjs.VENDOR_OWNER_GROUP_NAME,
12376
+ name: chunkWMXPKKXU_cjs.VENDOR_OWNER_GROUP_NAME,
12372
12377
  deleted: false
12373
12378
  }
12374
12379
  });
@@ -12678,10 +12683,10 @@ chunkUSNT2KNT_cjs.__name(createVendorOnboardHandlers, "createVendorOnboardHandle
12678
12683
  function createVendorRolesHandlers(config) {
12679
12684
  const { dataSource, entityMap, json, getSessionUser } = config;
12680
12685
  const vendorRoleEntities = [
12681
- ...chunkKPKFNLQQ_cjs.VENDOR_RBAC_ENTITIES
12686
+ ...chunkWMXPKKXU_cjs.VENDOR_RBAC_ENTITIES
12682
12687
  ].sort();
12683
12688
  async function resolveActiveVendorId(u) {
12684
- const scope = chunkKPKFNLQQ_cjs.resolveVendorScopeFromSessionUser(u);
12689
+ const scope = chunkWMXPKKXU_cjs.resolveVendorScopeFromSessionUser(u);
12685
12690
  if (scope.type === "vendor") return scope.vendorId;
12686
12691
  if (scope.type === "all") {
12687
12692
  const id = u.activeVendorId ?? u.vendorIds?.[0];
@@ -12697,7 +12702,7 @@ function createVendorRolesHandlers(config) {
12697
12702
  }, {
12698
12703
  status: 401
12699
12704
  });
12700
- if (!chunkKPKFNLQQ_cjs.canManageVendorRoles(u)) return json({
12705
+ if (!chunkWMXPKKXU_cjs.canManageVendorRoles(u)) return json({
12701
12706
  error: "Forbidden"
12702
12707
  }, {
12703
12708
  status: 403
@@ -20855,6 +20860,8 @@ exports.Combo = class Combo {
20855
20860
  chunkUSNT2KNT_cjs.__name(this, "Combo");
20856
20861
  }
20857
20862
  id;
20863
+ vendorId;
20864
+ vendor;
20858
20865
  name;
20859
20866
  desc;
20860
20867
  eventId;
@@ -20880,6 +20887,19 @@ _ts_decorate63([
20880
20887
  typeorm.PrimaryGeneratedColumn(),
20881
20888
  _ts_metadata63("design:type", Number)
20882
20889
  ], exports.Combo.prototype, "id", void 0);
20890
+ _ts_decorate63([
20891
+ typeorm.Column("int"),
20892
+ _ts_metadata63("design:type", Number)
20893
+ ], exports.Combo.prototype, "vendorId", void 0);
20894
+ _ts_decorate63([
20895
+ typeorm.ManyToOne(() => exports.Vendor, {
20896
+ onDelete: "RESTRICT"
20897
+ }),
20898
+ typeorm.JoinColumn({
20899
+ name: "vendorId"
20900
+ }),
20901
+ _ts_metadata63("design:type", typeof exports.Vendor === "undefined" ? Object : exports.Vendor)
20902
+ ], exports.Combo.prototype, "vendor", void 0);
20883
20903
  _ts_decorate63([
20884
20904
  typeorm.Column({
20885
20905
  type: "varchar"
@@ -21224,12 +21244,18 @@ function _ts_metadata66(k, v) {
21224
21244
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
21225
21245
  }
21226
21246
  chunkUSNT2KNT_cjs.__name(_ts_metadata66, "_ts_metadata");
21227
- exports.WhatsappTriggerBinding = class WhatsappTriggerBinding {
21247
+ var NotificationChannel = /* @__PURE__ */ (function(NotificationChannel2) {
21248
+ NotificationChannel2["WHATSAPP"] = "whatsapp";
21249
+ NotificationChannel2["EMAIL"] = "email";
21250
+ return NotificationChannel2;
21251
+ })({});
21252
+ exports.OrderNotificationBinding = class OrderNotificationBinding {
21228
21253
  static {
21229
- chunkUSNT2KNT_cjs.__name(this, "WhatsappTriggerBinding");
21254
+ chunkUSNT2KNT_cjs.__name(this, "OrderNotificationBinding");
21230
21255
  }
21231
21256
  id;
21232
21257
  triggerKey;
21258
+ channel;
21233
21259
  messageTemplateId;
21234
21260
  enabled;
21235
21261
  createdAt;
@@ -21238,39 +21264,52 @@ exports.WhatsappTriggerBinding = class WhatsappTriggerBinding {
21238
21264
  _ts_decorate66([
21239
21265
  typeorm.PrimaryGeneratedColumn(),
21240
21266
  _ts_metadata66("design:type", Number)
21241
- ], exports.WhatsappTriggerBinding.prototype, "id", void 0);
21267
+ ], exports.OrderNotificationBinding.prototype, "id", void 0);
21242
21268
  _ts_decorate66([
21243
21269
  typeorm.Column({
21244
- type: "varchar",
21245
- unique: true
21270
+ type: "varchar"
21246
21271
  }),
21247
21272
  _ts_metadata66("design:type", String)
21248
- ], exports.WhatsappTriggerBinding.prototype, "triggerKey", void 0);
21273
+ ], exports.OrderNotificationBinding.prototype, "triggerKey", void 0);
21274
+ _ts_decorate66([
21275
+ typeorm.Column({
21276
+ type: "enum",
21277
+ enum: NotificationChannel,
21278
+ default: "whatsapp"
21279
+ }),
21280
+ _ts_metadata66("design:type", String)
21281
+ ], exports.OrderNotificationBinding.prototype, "channel", void 0);
21249
21282
  _ts_decorate66([
21250
21283
  typeorm.Column({
21251
21284
  type: "int",
21252
21285
  nullable: true
21253
21286
  }),
21254
21287
  _ts_metadata66("design:type", Object)
21255
- ], exports.WhatsappTriggerBinding.prototype, "messageTemplateId", void 0);
21288
+ ], exports.OrderNotificationBinding.prototype, "messageTemplateId", void 0);
21256
21289
  _ts_decorate66([
21257
21290
  typeorm.Column({
21258
21291
  type: "boolean",
21259
21292
  default: true
21260
21293
  }),
21261
21294
  _ts_metadata66("design:type", Boolean)
21262
- ], exports.WhatsappTriggerBinding.prototype, "enabled", void 0);
21295
+ ], exports.OrderNotificationBinding.prototype, "enabled", void 0);
21263
21296
  _ts_decorate66([
21264
21297
  typeorm.CreateDateColumn(),
21265
21298
  _ts_metadata66("design:type", typeof Date === "undefined" ? Object : Date)
21266
- ], exports.WhatsappTriggerBinding.prototype, "createdAt", void 0);
21299
+ ], exports.OrderNotificationBinding.prototype, "createdAt", void 0);
21267
21300
  _ts_decorate66([
21268
21301
  typeorm.UpdateDateColumn(),
21269
21302
  _ts_metadata66("design:type", typeof Date === "undefined" ? Object : Date)
21270
- ], exports.WhatsappTriggerBinding.prototype, "updatedAt", void 0);
21271
- exports.WhatsappTriggerBinding = _ts_decorate66([
21272
- typeorm.Entity("whatsapp_trigger_bindings")
21273
- ], exports.WhatsappTriggerBinding);
21303
+ ], exports.OrderNotificationBinding.prototype, "updatedAt", void 0);
21304
+ exports.OrderNotificationBinding = _ts_decorate66([
21305
+ typeorm.Entity("order_notification_bindings"),
21306
+ typeorm.Index([
21307
+ "triggerKey",
21308
+ "channel"
21309
+ ], {
21310
+ unique: true
21311
+ })
21312
+ ], exports.OrderNotificationBinding);
21274
21313
  function _ts_decorate67(decorators, target, key, desc) {
21275
21314
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
21276
21315
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -21420,7 +21459,7 @@ var CMS_ENTITY_MAP = {
21420
21459
  refund_policies: exports.RefundPolicy,
21421
21460
  refund_requests: exports.RefundRequest,
21422
21461
  attendees: exports.Attendee,
21423
- whatsapp_trigger_bindings: exports.WhatsappTriggerBinding,
21462
+ order_notification_bindings: exports.OrderNotificationBinding,
21424
21463
  order_notification_triggers: exports.OrderNotificationTrigger
21425
21464
  };
21426
21465
 
@@ -24523,6 +24562,173 @@ function createWhatsappMessageTemplatesHandlers(config) {
24523
24562
  };
24524
24563
  }
24525
24564
  chunkUSNT2KNT_cjs.__name(createWhatsappMessageTemplatesHandlers, "createWhatsappMessageTemplatesHandlers");
24565
+
24566
+ // src/api/email-message-templates-handlers.ts
24567
+ function slugify2(input) {
24568
+ return input.toLowerCase().trim().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 64) || "template";
24569
+ }
24570
+ chunkUSNT2KNT_cjs.__name(slugify2, "slugify");
24571
+ function createEmailMessageTemplatesHandlers(config) {
24572
+ const { dataSource, entityMap, json, requireAuth, requireEntityPermission } = config;
24573
+ const templateRepo = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(() => dataSource.getRepository(entityMap.message_templates), "templateRepo");
24574
+ async function requireRead(req, entity) {
24575
+ const a = await requireAuth(req);
24576
+ if (a) return a;
24577
+ if (requireEntityPermission) {
24578
+ const pe = await requireEntityPermission(req, entity, "read");
24579
+ if (pe) return pe;
24580
+ }
24581
+ return null;
24582
+ }
24583
+ chunkUSNT2KNT_cjs.__name(requireRead, "requireRead");
24584
+ async function requireUpdate(req, entity) {
24585
+ const a = await requireAuth(req);
24586
+ if (a) return a;
24587
+ if (requireEntityPermission) {
24588
+ const pe = await requireEntityPermission(req, entity, "update");
24589
+ if (pe) return pe;
24590
+ }
24591
+ return null;
24592
+ }
24593
+ chunkUSNT2KNT_cjs.__name(requireUpdate, "requireUpdate");
24594
+ return {
24595
+ async listCached(req) {
24596
+ const err = await requireRead(req, "settings");
24597
+ if (err) return err;
24598
+ try {
24599
+ const rows = await templateRepo().find({
24600
+ where: {
24601
+ channel: "email",
24602
+ deleted: false
24603
+ },
24604
+ order: {
24605
+ name: "ASC"
24606
+ }
24607
+ });
24608
+ return json({
24609
+ items: rows
24610
+ });
24611
+ } catch {
24612
+ return json({
24613
+ error: "Failed to load templates"
24614
+ }, {
24615
+ status: 500
24616
+ });
24617
+ }
24618
+ },
24619
+ async create(req) {
24620
+ const err = await requireUpdate(req, "settings");
24621
+ if (err) return err;
24622
+ let body;
24623
+ try {
24624
+ body = await req.json();
24625
+ } catch {
24626
+ return json({
24627
+ error: "Invalid JSON body"
24628
+ }, {
24629
+ status: 400
24630
+ });
24631
+ }
24632
+ const name = typeof body.name === "string" ? body.name.trim() : "";
24633
+ const subject = typeof body.subject === "string" ? body.subject : "";
24634
+ const bodyText = typeof body.body === "string" ? body.body : "";
24635
+ if (!name) return json({
24636
+ error: "name is required"
24637
+ }, {
24638
+ status: 400
24639
+ });
24640
+ if (!bodyText.trim()) return json({
24641
+ error: "body is required"
24642
+ }, {
24643
+ status: 400
24644
+ });
24645
+ const baseKey = slugify2(name);
24646
+ let templateKey = baseKey;
24647
+ let suffix = 1;
24648
+ while (await templateRepo().findOne({
24649
+ where: {
24650
+ channel: "email",
24651
+ templateKey,
24652
+ deleted: false
24653
+ }
24654
+ })) {
24655
+ suffix += 1;
24656
+ templateKey = `${baseKey}_${suffix}`;
24657
+ }
24658
+ const row = await templateRepo().save(templateRepo().create({
24659
+ channel: "email",
24660
+ templateKey,
24661
+ name,
24662
+ subject,
24663
+ body: bodyText,
24664
+ externalTemplateRef: null,
24665
+ providerMeta: null,
24666
+ enabled: true,
24667
+ deleted: false
24668
+ }));
24669
+ return json({
24670
+ item: row
24671
+ }, {
24672
+ status: 201
24673
+ });
24674
+ },
24675
+ async update(req, id) {
24676
+ const err = await requireUpdate(req, "settings");
24677
+ if (err) return err;
24678
+ const numId = Number(id);
24679
+ if (!Number.isFinite(numId)) return json({
24680
+ error: "Invalid id"
24681
+ }, {
24682
+ status: 400
24683
+ });
24684
+ let body;
24685
+ try {
24686
+ body = await req.json();
24687
+ } catch {
24688
+ return json({
24689
+ error: "Invalid JSON body"
24690
+ }, {
24691
+ status: 400
24692
+ });
24693
+ }
24694
+ const existing = await templateRepo().findOne({
24695
+ where: {
24696
+ id: numId,
24697
+ channel: "email",
24698
+ deleted: false
24699
+ }
24700
+ });
24701
+ if (!existing) return json({
24702
+ error: "Template not found"
24703
+ }, {
24704
+ status: 404
24705
+ });
24706
+ const patch = {
24707
+ updatedAt: /* @__PURE__ */ new Date()
24708
+ };
24709
+ if (typeof body.name === "string" && body.name.trim()) patch.name = body.name.trim();
24710
+ if (typeof body.subject === "string") patch.subject = body.subject;
24711
+ if (typeof body.body === "string") {
24712
+ if (!body.body.trim()) return json({
24713
+ error: "body cannot be empty"
24714
+ }, {
24715
+ status: 400
24716
+ });
24717
+ patch.body = body.body;
24718
+ }
24719
+ await templateRepo().update(numId, patch);
24720
+ const updated = await templateRepo().findOne({
24721
+ where: {
24722
+ id: numId
24723
+ }
24724
+ });
24725
+ return json({
24726
+ item: updated
24727
+ });
24728
+ }
24729
+ };
24730
+ }
24731
+ chunkUSNT2KNT_cjs.__name(createEmailMessageTemplatesHandlers, "createEmailMessageTemplatesHandlers");
24526
24732
  function connectionFromUrl(redisUrl) {
24527
24733
  const u = new URL(redisUrl);
24528
24734
  return {
@@ -24680,16 +24886,16 @@ function whatsappPlugin(config = {}) {
24680
24886
  db = await getWhatsAppSettings?.() ?? {};
24681
24887
  } catch {
24682
24888
  }
24683
- if (!chunkCOBORIJH_cjs.isWhatsAppPluginEnabled(db)) {
24889
+ if (!chunk22FFHLTO_cjs.isWhatsAppPluginEnabled(db)) {
24684
24890
  context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
24685
24891
  return null;
24686
24892
  }
24687
- const merged = chunkCOBORIJH_cjs.mergeWhatsAppConfigLayers(env, db, staticRest);
24688
- if (!getWhatsAppSettings && !chunkCOBORIJH_cjs.whatsAppConfigured(merged)) {
24893
+ const merged = chunk22FFHLTO_cjs.mergeWhatsAppConfigLayers(env, db, staticRest);
24894
+ if (!getWhatsAppSettings && !chunk22FFHLTO_cjs.whatsAppConfigured(merged)) {
24689
24895
  context.logger.warn("WhatsApp plugin skipped: set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID, or pass getWhatsAppSettings");
24690
24896
  return null;
24691
24897
  }
24692
- const svc = new chunkCOBORIJH_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
24898
+ const svc = new chunk22FFHLTO_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
24693
24899
  return {
24694
24900
  send: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((opts) => svc.send(opts), "send")
24695
24901
  };
@@ -24763,7 +24969,7 @@ function createMessageTemplateRowLoader(dataSource, entityMap) {
24763
24969
  chunkUSNT2KNT_cjs.__name(createMessageTemplateRowLoader, "createMessageTemplateRowLoader");
24764
24970
  function registerMessagingQueueProcessors(cms) {
24765
24971
  chunkXW5ATPRW_cjs.registerEmailQueueProcessor(cms);
24766
- chunkCOBORIJH_cjs.registerWhatsAppQueueProcessor(cms);
24972
+ chunk22FFHLTO_cjs.registerWhatsAppQueueProcessor(cms);
24767
24973
  }
24768
24974
  chunkUSNT2KNT_cjs.__name(registerMessagingQueueProcessors, "registerMessagingQueueProcessors");
24769
24975
  async function ensureMessagingPluginsOnCms(base, options) {
@@ -24792,7 +24998,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
24792
24998
  }
24793
24999
  if (!cms.getPlugin("email")) {
24794
25000
  try {
24795
- const instance = await chunkCOBORIJH_cjs.emailPlugin({
25001
+ const instance = await chunk22FFHLTO_cjs.emailPlugin({
24796
25002
  type: "SMTP",
24797
25003
  from: config.SMTP_FROM ?? "no-reply@localhost",
24798
25004
  to: config.SMTP_TO ?? ""
@@ -24833,7 +25039,7 @@ function messagingPlugins(options) {
24833
25039
  const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
24834
25040
  return [
24835
25041
  queuePlugin(),
24836
- chunkCOBORIJH_cjs.emailPlugin({
25042
+ chunk22FFHLTO_cjs.emailPlugin({
24837
25043
  type: "SMTP",
24838
25044
  from: config.SMTP_FROM ?? "no-reply@localhost",
24839
25045
  to: config.SMTP_TO ?? ""
@@ -24880,7 +25086,7 @@ function withLlmKnowledgeEntityFallbacks(base) {
24880
25086
  "rss_feeds",
24881
25087
  "rss_articles",
24882
25088
  "order_notification_triggers",
24883
- "whatsapp_trigger_bindings",
25089
+ "order_notification_bindings",
24884
25090
  "message_templates"
24885
25091
  ];
24886
25092
  const patch = {};
@@ -24967,7 +25173,7 @@ function createCmsApiHandler(config) {
24967
25173
  } : void 0;
24968
25174
  const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
24969
25175
  if (getCms) {
24970
- chunkCOBORIJH_cjs.initWhatsappTriggerDispatcher({
25176
+ chunk22FFHLTO_cjs.initWhatsappTriggerDispatcher({
24971
25177
  dataSource,
24972
25178
  entityMap,
24973
25179
  getCms
@@ -24980,7 +25186,7 @@ function createCmsApiHandler(config) {
24980
25186
  ] : baseCrudResources;
24981
25187
  const requireEntityPermissionEffective = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async (_req, entity, action) => {
24982
25188
  if (!resolveSessionUser) {
24983
- chunkKPKFNLQQ_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
25189
+ chunkWMXPKKXU_cjs.logRbac("requireEntityPermission: getSessionUser not passed \u2014 vendor store APIs may 403", {
24984
25190
  entity,
24985
25191
  action,
24986
25192
  hint: "Pass getSessionUser: auth.getAuthenticatedUser from createCmsAuthBundle()"
@@ -24990,7 +25196,7 @@ function createCmsApiHandler(config) {
24990
25196
  const raw = await resolveSessionUser();
24991
25197
  const u = await hydrateVendorSessionUser(dataSource, raw);
24992
25198
  if (!u?.email) {
24993
- chunkKPKFNLQQ_cjs.logRbac("requireEntityPermission: no session user", {
25199
+ chunkWMXPKKXU_cjs.logRbac("requireEntityPermission: no session user", {
24994
25200
  entity,
24995
25201
  action
24996
25202
  });
@@ -25000,13 +25206,13 @@ function createCmsApiHandler(config) {
25000
25206
  status: 401
25001
25207
  });
25002
25208
  }
25003
- const allowed = chunkWO2DW4AU_cjs.sessionHasEntityAccess(u, entity, action);
25004
- await chunkKPKFNLQQ_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
25209
+ const allowed = chunkOIGCAGH7_cjs.sessionHasEntityAccess(u, entity, action);
25210
+ await chunkWMXPKKXU_cjs.logEntityAccessDecision(dataSource, "cmsApi.requireEntityPermission", u, entity, action, {
25005
25211
  allowed,
25006
25212
  resolvePath: "hydrated_session"
25007
25213
  });
25008
25214
  if (allowed) return null;
25009
- const { reason } = chunkKPKFNLQQ_cjs.explainSessionEntityAccess(u, entity, action);
25215
+ const { reason } = chunkWMXPKKXU_cjs.explainSessionEntityAccess(u, entity, action);
25010
25216
  return config.json({
25011
25217
  error: "Forbidden",
25012
25218
  entity,
@@ -25017,7 +25223,7 @@ function createCmsApiHandler(config) {
25017
25223
  });
25018
25224
  }
25019
25225
  if (userRequireEntityPermission) {
25020
- chunkKPKFNLQQ_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
25226
+ chunkWMXPKKXU_cjs.logRbac("requireEntityPermission: using app callback only (no getSessionUser)", {
25021
25227
  entity,
25022
25228
  action
25023
25229
  });
@@ -25104,10 +25310,10 @@ function createCmsApiHandler(config) {
25104
25310
  getVendorScope: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
25105
25311
  const multiVendorEnabled = await checkMultiVendorEnabled(dataSource);
25106
25312
  if (!multiVendorEnabled) {
25107
- return chunkKPKFNLQQ_cjs.resolveDisabledMultiVendorScope(dataSource);
25313
+ return chunkWMXPKKXU_cjs.resolveDisabledMultiVendorScope(dataSource);
25108
25314
  }
25109
25315
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
25110
- return chunkKPKFNLQQ_cjs.resolveVendorScopeFromSessionUser(u ?? null);
25316
+ return chunkWMXPKKXU_cjs.resolveVendorScopeFromSessionUser(u ?? null);
25111
25317
  }, "getVendorScope"),
25112
25318
  getHydratedSessionUser: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => {
25113
25319
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
@@ -25238,6 +25444,13 @@ function createCmsApiHandler(config) {
25238
25444
  requireEntityPermission: requireEntityPermissionEffective,
25239
25445
  settingsEncryptionKey: settingsConfig?.encryptionKey
25240
25446
  });
25447
+ const emailMessageTemplatesHandlers = createEmailMessageTemplatesHandlers({
25448
+ dataSource,
25449
+ entityMap,
25450
+ json: config.json,
25451
+ requireAuth: config.requireAuth,
25452
+ requireEntityPermission: requireEntityPermissionEffective
25453
+ });
25241
25454
  const chatHandlers = chatConfig ? createChatHandlers(chatConfig) : null;
25242
25455
  const llmAgentKnowledgeMerged = llmAgentKnowledgeConfig ?? (chatConfig ? {
25243
25456
  dataSource: chatConfig.dataSource,
@@ -26210,6 +26423,13 @@ function createCmsApiHandler(config) {
26210
26423
  if (path2[0] === "message-templates" && path2[1] === "whatsapp" && path2.length === 3 && path2[2] !== "sync") {
26211
26424
  if (m === "PATCH") return whatsappMessageTemplatesHandlers.setParamOrder(req, path2[2]);
26212
26425
  }
26426
+ if (path2[0] === "message-templates" && path2[1] === "email" && path2.length === 2) {
26427
+ if (m === "GET") return emailMessageTemplatesHandlers.listCached(req);
26428
+ if (m === "POST") return emailMessageTemplatesHandlers.create(req);
26429
+ }
26430
+ if (path2[0] === "message-templates" && path2[1] === "email" && path2.length === 3) {
26431
+ if (m === "PATCH") return emailMessageTemplatesHandlers.update(req, path2[2]);
26432
+ }
26213
26433
  if (path2[0] === "llm_agents") {
26214
26434
  if (!entityMap.llm_agents) {
26215
26435
  console.error(CMS_API_LOG, "llm_agents route: entity missing after merge", {
@@ -26338,7 +26558,7 @@ function createCmsApiHandler(config) {
26338
26558
  let vendorId = null;
26339
26559
  if (resolveSessionUser) {
26340
26560
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
26341
- const scope = chunkKPKFNLQQ_cjs.resolveVendorScopeFromSessionUser(u ?? null);
26561
+ const scope = chunkWMXPKKXU_cjs.resolveVendorScopeFromSessionUser(u ?? null);
26342
26562
  if (scope.type === "vendor") vendorId = scope.vendorId;
26343
26563
  }
26344
26564
  const result = await validateCoupon(dataSource, entityMap, couponCode, orderLinesNorm, currency, contactId, isAutomatic, discountId ?? void 0, vendorId);
@@ -26418,7 +26638,7 @@ function createCmsApiHandler(config) {
26418
26638
  let vendorId = null;
26419
26639
  if (resolveSessionUser) {
26420
26640
  const u = await hydrateVendorSessionUser(dataSource, await resolveSessionUser());
26421
- const scope = chunkKPKFNLQQ_cjs.resolveVendorScopeFromSessionUser(u ?? null);
26641
+ const scope = chunkWMXPKKXU_cjs.resolveVendorScopeFromSessionUser(u ?? null);
26422
26642
  if (scope.type === "vendor") vendorId = scope.vendorId;
26423
26643
  }
26424
26644
  const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
@@ -26624,7 +26844,7 @@ function createCmsApiHandler(config) {
26624
26844
  status: 400
26625
26845
  });
26626
26846
  }
26627
- const { resendOrderNotification } = await import('./whatsapp-trigger-dispatcher-ONHXI7UY.cjs');
26847
+ const { resendOrderNotification } = await import('./order-notification-dispatcher-RU7BTGGX.cjs');
26628
26848
  const result = await resendOrderNotification(triggerKey, orderId, {
26629
26849
  dataSource,
26630
26850
  entityMap,
@@ -27032,7 +27252,7 @@ function createCmsApiHandler(config) {
27032
27252
  if (resolveSessionUser) {
27033
27253
  const raw = await resolveSessionUser();
27034
27254
  const u = await hydrateVendorSessionUser(dataSource, raw);
27035
- const scope = chunkKPKFNLQQ_cjs.resolveVendorScopeFromSessionUser(u ?? null);
27255
+ const scope = chunkWMXPKKXU_cjs.resolveVendorScopeFromSessionUser(u ?? null);
27036
27256
  if (scope.type === "vendor") {
27037
27257
  scopedVendorIds = scope.vendorIds;
27038
27258
  }