@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.
- package/dist/admin.cjs +843 -402
- package/dist/admin.d.cts +13 -1
- package/dist/admin.d.ts +13 -1
- package/dist/admin.js +843 -402
- package/dist/api.cjs +35 -35
- package/dist/api.js +4 -4
- package/dist/auth.cjs +44 -43
- package/dist/auth.d.cts +2 -3
- package/dist/auth.d.ts +2 -3
- package/dist/auth.js +2 -1
- package/dist/{chunk-JCMOOPNX.cjs → chunk-3BPD5NGU.cjs} +210 -90
- package/dist/chunk-7L6KWI7S.cjs +212 -0
- package/dist/{chunk-YV5PK4JW.cjs → chunk-BC22I7C7.cjs} +45 -247
- package/dist/{chunk-WRKV6MHB.js → chunk-BNKZNLEX.js} +2 -196
- package/dist/{chunk-IPDHT2UV.js → chunk-CTXBYO2J.js} +94 -104
- package/dist/{chunk-UUWAUHUW.cjs → chunk-JN4AFHZ4.cjs} +94 -105
- package/dist/{chunk-JE22VP6S.js → chunk-MXIWUFBP.js} +1 -1
- package/dist/{chunk-LT2WOPKA.js → chunk-UO5Q5RXB.js} +181 -61
- package/dist/{chunk-KOTXDSQB.cjs → chunk-UQWZUZ5X.cjs} +1 -1
- package/dist/chunk-WUQAOTHA.js +203 -0
- package/dist/{emit-order-notification-trigger-6XX7LSC4.js → emit-order-notification-trigger-HZQPPSFB.js} +1 -1
- package/dist/{emit-order-notification-trigger-NASG7ZEO.cjs → emit-order-notification-trigger-NR3VN6C6.cjs} +3 -3
- package/dist/index.cjs +334 -299
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +59 -24
- package/dist/middleware.cjs +15 -0
- package/dist/middleware.js +2 -0
- package/dist/{order-notification-dispatcher-3TA4ETYJ.js → order-notification-dispatcher-AT4IFAGL.js} +2 -2
- package/dist/{order-notification-dispatcher-ZEAZ5SHV.cjs → order-notification-dispatcher-YBAWDOIO.cjs} +5 -5
- package/package.json +6 -1
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkXQ3QUHWR_cjs = require('./chunk-XQ3QUHWR.cjs');
|
|
3
4
|
var chunkHY3AXLOI_cjs = require('./chunk-HY3AXLOI.cjs');
|
|
4
|
-
var
|
|
5
|
+
var chunkJN4AFHZ4_cjs = require('./chunk-JN4AFHZ4.cjs');
|
|
5
6
|
var chunk7NMT3GBR_cjs = require('./chunk-7NMT3GBR.cjs');
|
|
6
7
|
var chunkV25RDUOU_cjs = require('./chunk-V25RDUOU.cjs');
|
|
7
8
|
var chunkBXYZDMTZ_cjs = require('./chunk-BXYZDMTZ.cjs');
|
|
9
|
+
var chunkUPLVMVRX_cjs = require('./chunk-UPLVMVRX.cjs');
|
|
8
10
|
var chunk3DZRIZOD_cjs = require('./chunk-3DZRIZOD.cjs');
|
|
9
11
|
var chunkTJ2MIQUT_cjs = require('./chunk-TJ2MIQUT.cjs');
|
|
10
|
-
var chunkXQ3QUHWR_cjs = require('./chunk-XQ3QUHWR.cjs');
|
|
11
12
|
var chunk3EOM4V2M_cjs = require('./chunk-3EOM4V2M.cjs');
|
|
12
13
|
var chunkOY2YTBMP_cjs = require('./chunk-OY2YTBMP.cjs');
|
|
13
14
|
var chunk77NUXO6A_cjs = require('./chunk-77NUXO6A.cjs');
|
|
14
15
|
var chunkD5FBNKQM_cjs = require('./chunk-D5FBNKQM.cjs');
|
|
15
|
-
var chunkUPLVMVRX_cjs = require('./chunk-UPLVMVRX.cjs');
|
|
16
16
|
var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
|
|
17
17
|
var typeorm = require('typeorm');
|
|
18
18
|
var countryStateCity = require('country-state-city');
|
|
@@ -2976,46 +2976,51 @@ async function calculateOrderTotalsFromLines(dataSource, entityMap, lineInputs,
|
|
|
2976
2976
|
total
|
|
2977
2977
|
});
|
|
2978
2978
|
}
|
|
2979
|
-
|
|
2979
|
+
const dIds = Array.isArray(discountId) ? discountId.filter((id) => id != null && Number.isFinite(id) && id > 0) : discountId != null && Number.isFinite(discountId) && discountId > 0 ? [
|
|
2980
|
+
discountId
|
|
2981
|
+
] : [];
|
|
2982
|
+
if (dIds.length > 0 && entityMap["discounts"]) {
|
|
2980
2983
|
try {
|
|
2981
2984
|
const discountRepo = dataSource.getRepository(entityMap["discounts"]);
|
|
2982
2985
|
const rulesRepo = entityMap["discount_rules"] ? dataSource.getRepository(entityMap["discount_rules"]) : null;
|
|
2983
|
-
const
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
const discountedAmount = line.subtotal - (line.discount ?? 0);
|
|
3010
|
-
line.tax = discountedAmount * line.taxRate / 100;
|
|
3011
|
-
line.total = discountedAmount + line.tax;
|
|
2986
|
+
for (const dId of dIds) {
|
|
2987
|
+
const discountRow = await discountRepo.findOne({
|
|
2988
|
+
where: withDiscountVendorWhere({
|
|
2989
|
+
id: dId
|
|
2990
|
+
}, vendorId)
|
|
2991
|
+
});
|
|
2992
|
+
if (discountRow) {
|
|
2993
|
+
const flatRules = rulesRepo ? await rulesRepo.find({
|
|
2994
|
+
where: {
|
|
2995
|
+
discountId: dId
|
|
2996
|
+
}
|
|
2997
|
+
}) : [];
|
|
2998
|
+
const discountForEval = {
|
|
2999
|
+
...discountRow,
|
|
3000
|
+
rules: flatRules
|
|
3001
|
+
};
|
|
3002
|
+
const cartLines = lines.filter((l) => l.found && l.productId != null).map((l) => ({
|
|
3003
|
+
productId: l.productId,
|
|
3004
|
+
quantity: l.quantity,
|
|
3005
|
+
unitPrice: l.unitPrice,
|
|
3006
|
+
subtotal: l.subtotal
|
|
3007
|
+
}));
|
|
3008
|
+
const evalResult = evaluateDiscount(discountForEval, cartLines);
|
|
3009
|
+
if (evalResult.conditionsMet) {
|
|
3010
|
+
const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount);
|
|
3011
|
+
orderDiscount += totalDiscountApplied;
|
|
3012
3012
|
}
|
|
3013
|
-
orderDiscount = totalDiscountApplied;
|
|
3014
|
-
orderTotal = lines.reduce((s, l) => s + l.total, 0);
|
|
3015
|
-
orderSubTotal = lines.reduce((s, l) => s + l.subtotal, 0);
|
|
3016
|
-
orderTax = lines.reduce((s, l) => s + l.tax, 0);
|
|
3017
3013
|
}
|
|
3018
3014
|
}
|
|
3015
|
+
for (const line of lines) {
|
|
3016
|
+
if (!line.found || line.taxRate === 0) continue;
|
|
3017
|
+
const discountedAmount = Math.max(0, line.subtotal - (line.discount ?? 0));
|
|
3018
|
+
line.tax = discountedAmount * line.taxRate / 100;
|
|
3019
|
+
line.total = discountedAmount + line.tax;
|
|
3020
|
+
}
|
|
3021
|
+
orderTotal = lines.reduce((s, l) => s + l.total, 0);
|
|
3022
|
+
orderSubTotal = lines.reduce((s, l) => s + l.subtotal, 0);
|
|
3023
|
+
orderTax = lines.reduce((s, l) => s + l.tax, 0);
|
|
3019
3024
|
} catch (err) {
|
|
3020
3025
|
logCrudServerError("discount evaluation failed", {
|
|
3021
3026
|
discountId,
|
|
@@ -5049,7 +5054,7 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
5049
5054
|
await recordDiscountUsage2(dataSource, entityMap, created.id, orderDiscountId, persistBody.contactId, discount);
|
|
5050
5055
|
}
|
|
5051
5056
|
const orderIdForNotify = created.id;
|
|
5052
|
-
void import('./emit-order-notification-trigger-
|
|
5057
|
+
void import('./emit-order-notification-trigger-NR3VN6C6.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
5053
5058
|
fireOrderNotificationTrigger("order_placed", orderIdForNotify, {
|
|
5054
5059
|
dataSource,
|
|
5055
5060
|
entityMap
|
|
@@ -5226,9 +5231,14 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
5226
5231
|
const where = hasDeleted ? {
|
|
5227
5232
|
deleted: false
|
|
5228
5233
|
} : {};
|
|
5229
|
-
|
|
5234
|
+
let data = await repo.find({
|
|
5230
5235
|
where
|
|
5231
5236
|
});
|
|
5237
|
+
const scope = await resolveScope();
|
|
5238
|
+
const flags = await getVendorCatalogCreateFlags(dataSource);
|
|
5239
|
+
if (scope.type !== "all") {
|
|
5240
|
+
data = data.filter((row) => vendorScopeRowAccess(row, scope, resource, flags) === "ok");
|
|
5241
|
+
}
|
|
5232
5242
|
const excludeCols = /* @__PURE__ */ new Set([
|
|
5233
5243
|
"deletedAt",
|
|
5234
5244
|
"deletedBy",
|
|
@@ -10709,7 +10719,7 @@ function createChatHandlers(config) {
|
|
|
10709
10719
|
const notifyEmailAgent = await findLlmAgentByScope(dataSource, entityMap, LLM_AGENT_SCOPE_EMAIL_INTENT_CHATBOT, {
|
|
10710
10720
|
enabledOnly: false
|
|
10711
10721
|
});
|
|
10712
|
-
const emailTool =
|
|
10722
|
+
const emailTool = chunkJN4AFHZ4_cjs.resolveChatEmailToolSettings(llmSettings, {
|
|
10713
10723
|
chatbotValidationRules: agentRow?.validationRules ?? null,
|
|
10714
10724
|
notifyAgent: notifyEmailAgent ? {
|
|
10715
10725
|
systemInstruction: notifyEmailAgent.systemInstruction,
|
|
@@ -10719,7 +10729,7 @@ function createChatHandlers(config) {
|
|
|
10719
10729
|
const emailPlugin2 = cms.getPlugin("email");
|
|
10720
10730
|
const convLeadSent = conv.leadEmailSentAt;
|
|
10721
10731
|
const chatAgentFn = llm.chatAgent?.bind(llm);
|
|
10722
|
-
console.info(
|
|
10732
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline check", {
|
|
10723
10733
|
conversationId,
|
|
10724
10734
|
enabled: emailTool.enabled,
|
|
10725
10735
|
intentCount: emailTool.intents.length,
|
|
@@ -10733,27 +10743,27 @@ function createChatHandlers(config) {
|
|
|
10733
10743
|
mergedPromptIncludesNotify: Boolean(notifyEmailAgent?.systemInstruction?.trim())
|
|
10734
10744
|
});
|
|
10735
10745
|
if (!emailTool.enabled) {
|
|
10736
|
-
console.info(
|
|
10746
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10737
10747
|
conversationId,
|
|
10738
10748
|
reason: "email_tool_disabled"
|
|
10739
10749
|
});
|
|
10740
10750
|
} else if (emailTool.intents.length === 0) {
|
|
10741
|
-
console.info(
|
|
10751
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10742
10752
|
conversationId,
|
|
10743
10753
|
reason: "no_intents_configured"
|
|
10744
10754
|
});
|
|
10745
10755
|
} else if (!emailPlugin2) {
|
|
10746
|
-
console.info(
|
|
10756
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10747
10757
|
conversationId,
|
|
10748
10758
|
reason: "email_plugin_missing"
|
|
10749
10759
|
});
|
|
10750
10760
|
} else if (!chatAgentFn) {
|
|
10751
|
-
console.info(
|
|
10761
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10752
10762
|
conversationId,
|
|
10753
10763
|
reason: "llm_chat_agent_unavailable"
|
|
10754
10764
|
});
|
|
10755
10765
|
} else if (convLeadSent) {
|
|
10756
|
-
console.info(
|
|
10766
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10757
10767
|
conversationId,
|
|
10758
10768
|
reason: "lead_email_already_sent",
|
|
10759
10769
|
leadEmailSentAt: convLeadSent
|
|
@@ -10766,7 +10776,7 @@ function createChatHandlers(config) {
|
|
|
10766
10776
|
}
|
|
10767
10777
|
});
|
|
10768
10778
|
if (!contactRow) {
|
|
10769
|
-
console.warn(
|
|
10779
|
+
console.warn(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline skipped", {
|
|
10770
10780
|
conversationId,
|
|
10771
10781
|
reason: "contact_not_found",
|
|
10772
10782
|
contactId
|
|
@@ -10774,7 +10784,7 @@ function createChatHandlers(config) {
|
|
|
10774
10784
|
} else {
|
|
10775
10785
|
const c = contactRow;
|
|
10776
10786
|
try {
|
|
10777
|
-
const intent = await
|
|
10787
|
+
const intent = await chunkJN4AFHZ4_cjs.detectChatLeadIntent({
|
|
10778
10788
|
chatAgent: chatAgentFn
|
|
10779
10789
|
}, {
|
|
10780
10790
|
settings: emailTool,
|
|
@@ -10788,15 +10798,15 @@ function createChatHandlers(config) {
|
|
|
10788
10798
|
model: agentRow?.model?.trim() || notifyEmailAgent?.model?.trim() || void 0
|
|
10789
10799
|
});
|
|
10790
10800
|
if (!intent.intent || !intent.emailTo) {
|
|
10791
|
-
console.info(
|
|
10801
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "no email sent", {
|
|
10792
10802
|
conversationId,
|
|
10793
10803
|
reason: intent.intent ? "missing_email_to" : "no_intent_match",
|
|
10794
10804
|
intentLabel: intent.intentLabel,
|
|
10795
10805
|
classifierReason: intent.reason
|
|
10796
10806
|
});
|
|
10797
10807
|
} else {
|
|
10798
|
-
const intentRecipients =
|
|
10799
|
-
console.info(
|
|
10808
|
+
const intentRecipients = chunkJN4AFHZ4_cjs.parseIntentRecipientEmails(intent.emailTo);
|
|
10809
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "intent matched \u2014 sending", {
|
|
10800
10810
|
conversationId,
|
|
10801
10811
|
intent: intent.intent,
|
|
10802
10812
|
emailTo: intent.emailTo,
|
|
@@ -10806,7 +10816,7 @@ function createChatHandlers(config) {
|
|
|
10806
10816
|
const emailSettings = await loadSettingsGroupMap(dataSource, entityMap, "email");
|
|
10807
10817
|
const brandingSettings = await loadSettingsGroupMap(dataSource, entityMap, "branding");
|
|
10808
10818
|
const companyDetails = chunkBXYZDMTZ_cjs.mergeEmailLayoutCompanyDetails(brandingSettings, emailSettings);
|
|
10809
|
-
const leadResult = await
|
|
10819
|
+
const leadResult = await chunkJN4AFHZ4_cjs.sendChatLeadEmail(cms, emailSettings, brandingSettings, {
|
|
10810
10820
|
contactName: String(c.name ?? "").trim() || "Visitor",
|
|
10811
10821
|
contactEmail: String(c.email ?? "").trim(),
|
|
10812
10822
|
contactPhone: c.phone ?? null,
|
|
@@ -10814,7 +10824,7 @@ function createChatHandlers(config) {
|
|
|
10814
10824
|
latestMessage: message,
|
|
10815
10825
|
intentCode: intent.intent,
|
|
10816
10826
|
intentReason: intent.intentLabel || intent.reason,
|
|
10817
|
-
transcript:
|
|
10827
|
+
transcript: chunkJN4AFHZ4_cjs.buildTranscriptForLeadEmail(history, message),
|
|
10818
10828
|
companyDetails,
|
|
10819
10829
|
recipients: intentRecipients.length > 0 ? intentRecipients : void 0
|
|
10820
10830
|
});
|
|
@@ -10822,13 +10832,13 @@ function createChatHandlers(config) {
|
|
|
10822
10832
|
await convRepo().update(conversationId, {
|
|
10823
10833
|
leadEmailSentAt: /* @__PURE__ */ new Date()
|
|
10824
10834
|
});
|
|
10825
|
-
console.info(
|
|
10835
|
+
console.info(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "lead email recorded", {
|
|
10826
10836
|
conversationId,
|
|
10827
10837
|
sent: true,
|
|
10828
10838
|
recipients: leadResult.recipients
|
|
10829
10839
|
});
|
|
10830
10840
|
} else {
|
|
10831
|
-
console.warn(
|
|
10841
|
+
console.warn(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "lead email not sent", {
|
|
10832
10842
|
conversationId,
|
|
10833
10843
|
sent: false,
|
|
10834
10844
|
error: leadResult.error ?? "unknown",
|
|
@@ -10837,7 +10847,7 @@ function createChatHandlers(config) {
|
|
|
10837
10847
|
}
|
|
10838
10848
|
}
|
|
10839
10849
|
} catch (intentErr) {
|
|
10840
|
-
console.warn(
|
|
10850
|
+
console.warn(chunkJN4AFHZ4_cjs.CHAT_EMAIL_LOG, "pipeline error", {
|
|
10841
10851
|
conversationId,
|
|
10842
10852
|
error: intentErr instanceof Error ? intentErr.message : String(intentErr)
|
|
10843
10853
|
});
|
|
@@ -10854,7 +10864,7 @@ function createChatHandlers(config) {
|
|
|
10854
10864
|
});
|
|
10855
10865
|
if (agentRow && llm.chatAgent) {
|
|
10856
10866
|
const fromAgent = llmAgentToChatAgentOptions(agentRow);
|
|
10857
|
-
const systemPrompt =
|
|
10867
|
+
const systemPrompt = chunkJN4AFHZ4_cjs.buildChatbotSystemPromptWithEmailTool(fromAgent.systemPrompt, parsedValidation.guardrailsForPrompt, emailTool);
|
|
10858
10868
|
const res = await llm.chatAgent({
|
|
10859
10869
|
...fromAgent,
|
|
10860
10870
|
systemPrompt: systemPrompt || void 0,
|
|
@@ -10875,7 +10885,7 @@ ${contextParts.join("\n\n")}` : "";
|
|
|
10875
10885
|
agentRow.systemInstruction?.trim(),
|
|
10876
10886
|
ragSystem
|
|
10877
10887
|
].filter(Boolean).join("\n\n");
|
|
10878
|
-
systemContent =
|
|
10888
|
+
systemContent = chunkJN4AFHZ4_cjs.buildChatbotSystemPromptWithEmailTool(mergedBase || defaultSystem, parsedValidation.guardrailsForPrompt, emailTool) || defaultSystem;
|
|
10879
10889
|
} else {
|
|
10880
10890
|
systemContent = ragSystem || defaultSystem;
|
|
10881
10891
|
}
|
|
@@ -12091,7 +12101,7 @@ function createDeviceTokensHandlers(config) {
|
|
|
12091
12101
|
const title = body.title?.trim() || "Test Push Notification";
|
|
12092
12102
|
const msgBody = body.body?.trim() || "Firebase Push Notification setup is working!";
|
|
12093
12103
|
if (!token || token === "validate" || token === "validate_only") {
|
|
12094
|
-
const valRes = await
|
|
12104
|
+
const valRes = await validateFcmCredentials(dataSource, entityMap);
|
|
12095
12105
|
if (!valRes.success) {
|
|
12096
12106
|
return json({
|
|
12097
12107
|
success: false,
|
|
@@ -12108,7 +12118,7 @@ function createDeviceTokensHandlers(config) {
|
|
|
12108
12118
|
clientEmail: valRes.clientEmail
|
|
12109
12119
|
});
|
|
12110
12120
|
}
|
|
12111
|
-
const res = await
|
|
12121
|
+
const res = await chunkJN4AFHZ4_cjs.sendFcmPushNotification(dataSource, entityMap, {
|
|
12112
12122
|
token,
|
|
12113
12123
|
title,
|
|
12114
12124
|
body: msgBody,
|
|
@@ -13005,17 +13015,80 @@ async function getSettingsGroup(deps, group) {
|
|
|
13005
13015
|
]));
|
|
13006
13016
|
}
|
|
13007
13017
|
chunkUSNT2KNT_cjs.__name(getSettingsGroup, "getSettingsGroup");
|
|
13018
|
+
async function getSuperAdminEmails(deps) {
|
|
13019
|
+
try {
|
|
13020
|
+
const ds = await deps.getDataSource();
|
|
13021
|
+
if (!deps.entityMap.users) return [];
|
|
13022
|
+
const userRepo = ds.getRepository(deps.entityMap.users);
|
|
13023
|
+
const superAdmins = await userRepo.createQueryBuilder("u").leftJoin("u.group", "g").where("u.deleted = false").andWhere("u.blocked = false").andWhere("(u.groupId = 1 OR LOWER(g.name) IN (:...adminGroupNames) OR u.adminAccess = true)", {
|
|
13024
|
+
adminGroupNames: [
|
|
13025
|
+
"administrator",
|
|
13026
|
+
"admin",
|
|
13027
|
+
"super admin",
|
|
13028
|
+
"superadmin"
|
|
13029
|
+
]
|
|
13030
|
+
}).select([
|
|
13031
|
+
"u.email"
|
|
13032
|
+
]).getMany();
|
|
13033
|
+
return superAdmins.map((u) => String(u.email ?? "").trim().toLowerCase()).filter((e) => Boolean(e));
|
|
13034
|
+
} catch {
|
|
13035
|
+
return [];
|
|
13036
|
+
}
|
|
13037
|
+
}
|
|
13038
|
+
chunkUSNT2KNT_cjs.__name(getSuperAdminEmails, "getSuperAdminEmails");
|
|
13039
|
+
async function getVendorEmails(deps) {
|
|
13040
|
+
const emails = /* @__PURE__ */ new Set();
|
|
13041
|
+
try {
|
|
13042
|
+
const ds = await deps.getDataSource();
|
|
13043
|
+
if (deps.entityMap.vendors) {
|
|
13044
|
+
const vendors = await ds.getRepository(deps.entityMap.vendors).find({
|
|
13045
|
+
where: {
|
|
13046
|
+
deleted: false
|
|
13047
|
+
},
|
|
13048
|
+
select: [
|
|
13049
|
+
"email"
|
|
13050
|
+
]
|
|
13051
|
+
});
|
|
13052
|
+
for (const v of vendors) {
|
|
13053
|
+
const e = String(v.email ?? "").trim().toLowerCase();
|
|
13054
|
+
if (e) emails.add(e);
|
|
13055
|
+
}
|
|
13056
|
+
}
|
|
13057
|
+
if (deps.entityMap.users) {
|
|
13058
|
+
const vendorUsers = await ds.getRepository(deps.entityMap.users).createQueryBuilder("u").leftJoin("u.group", "g").where("u.deleted = false").andWhere("(LOWER(g.name) LIKE :vGroup OR u.groupId = 5)", {
|
|
13059
|
+
vGroup: "%vendor%"
|
|
13060
|
+
}).select([
|
|
13061
|
+
"u.email"
|
|
13062
|
+
]).getMany();
|
|
13063
|
+
for (const u of vendorUsers) {
|
|
13064
|
+
const e = String(u.email ?? "").trim().toLowerCase();
|
|
13065
|
+
if (e) emails.add(e);
|
|
13066
|
+
}
|
|
13067
|
+
}
|
|
13068
|
+
} catch {
|
|
13069
|
+
}
|
|
13070
|
+
return emails;
|
|
13071
|
+
}
|
|
13072
|
+
chunkUSNT2KNT_cjs.__name(getVendorEmails, "getVendorEmails");
|
|
13008
13073
|
async function sendVendorOnboardEmails(input, deps) {
|
|
13009
13074
|
let ownerEmailSent = false;
|
|
13010
13075
|
try {
|
|
13011
|
-
const [branding, emailSettings] = await Promise.all([
|
|
13076
|
+
const [branding, emailSettings, superAdminEmails, vendorEmailSet] = await Promise.all([
|
|
13012
13077
|
getSettingsGroup(deps, "branding"),
|
|
13013
|
-
getSettingsGroup(deps, "email")
|
|
13078
|
+
getSettingsGroup(deps, "email"),
|
|
13079
|
+
getSuperAdminEmails(deps),
|
|
13080
|
+
getVendorEmails(deps)
|
|
13014
13081
|
]);
|
|
13015
13082
|
const companyDetails = chunkBXYZDMTZ_cjs.mergeEmailLayoutCompanyDetails(branding, emailSettings);
|
|
13016
|
-
const
|
|
13017
|
-
const sendToOwner = input.sendToOwner !== false;
|
|
13083
|
+
const configuredNotify = chunkJN4AFHZ4_cjs.parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
|
|
13018
13084
|
const ownerEmail = input.ownerEmail?.trim() || "";
|
|
13085
|
+
const ownerEmailLower = ownerEmail.toLowerCase();
|
|
13086
|
+
const sendToOwner = input.sendToOwner !== false;
|
|
13087
|
+
const combined = [
|
|
13088
|
+
...configuredNotify,
|
|
13089
|
+
...superAdminEmails
|
|
13090
|
+
];
|
|
13091
|
+
const notifyEmails = Array.from(new Set(combined.map((e) => e.trim().toLowerCase()).filter((e) => e && e !== ownerEmailLower && !vendorEmailSet.has(e))));
|
|
13019
13092
|
const cms = await deps.getCms();
|
|
13020
13093
|
await chunkV25RDUOU_cjs.queueVendorOnboardEmails(cms, {
|
|
13021
13094
|
vendorName: input.vendorName,
|
|
@@ -13162,8 +13235,6 @@ async function getDefaultStaffRoleIdForVendor(em, vendorId) {
|
|
|
13162
13235
|
return id != null ? Number(id) : null;
|
|
13163
13236
|
}
|
|
13164
13237
|
chunkUSNT2KNT_cjs.__name(getDefaultStaffRoleIdForVendor, "getDefaultStaffRoleIdForVendor");
|
|
13165
|
-
|
|
13166
|
-
// src/lib/vendor-profile.ts
|
|
13167
13238
|
var VENDOR_REGISTRATION_STATUSES = [
|
|
13168
13239
|
{
|
|
13169
13240
|
value: "pending",
|
|
@@ -13182,6 +13253,30 @@ var VENDOR_REGISTRATION_STATUSES = [
|
|
|
13182
13253
|
label: "Suspended"
|
|
13183
13254
|
}
|
|
13184
13255
|
];
|
|
13256
|
+
(() => {
|
|
13257
|
+
const list = [];
|
|
13258
|
+
const seenCodes = /* @__PURE__ */ new Set();
|
|
13259
|
+
for (const c of countryStateCity.Country.getAllCountries()) {
|
|
13260
|
+
if (!c.phonecode) continue;
|
|
13261
|
+
const rawCode = c.phonecode.replace(/^\+/, "").trim();
|
|
13262
|
+
if (!rawCode) continue;
|
|
13263
|
+
const code = `+${rawCode}`;
|
|
13264
|
+
const key = `${code}-${c.name}`;
|
|
13265
|
+
if (seenCodes.has(key)) continue;
|
|
13266
|
+
seenCodes.add(key);
|
|
13267
|
+
list.push({
|
|
13268
|
+
code,
|
|
13269
|
+
country: c.name,
|
|
13270
|
+
isoCode: c.isoCode,
|
|
13271
|
+
label: `${code} (${c.name})`
|
|
13272
|
+
});
|
|
13273
|
+
}
|
|
13274
|
+
return list.sort((a, b) => {
|
|
13275
|
+
if (a.code === "+91" && b.code !== "+91") return -1;
|
|
13276
|
+
if (b.code === "+91" && a.code !== "+91") return 1;
|
|
13277
|
+
return a.country.localeCompare(b.country);
|
|
13278
|
+
});
|
|
13279
|
+
})();
|
|
13185
13280
|
function trimOrNull(value) {
|
|
13186
13281
|
if (typeof value !== "string") return null;
|
|
13187
13282
|
const trimmed = value.trim();
|
|
@@ -13234,11 +13329,27 @@ function parseVendorPersonProfileFromBody(raw, fallbacks) {
|
|
|
13234
13329
|
};
|
|
13235
13330
|
}
|
|
13236
13331
|
chunkUSNT2KNT_cjs.__name(parseVendorPersonProfileFromBody, "parseVendorPersonProfileFromBody");
|
|
13237
|
-
function
|
|
13238
|
-
|
|
13239
|
-
|
|
13332
|
+
function validateGstin(gstin, options) {
|
|
13333
|
+
const required = options?.required === true;
|
|
13334
|
+
if (!gstin || !gstin.trim()) {
|
|
13335
|
+
if (required) return "GSTIN number is required";
|
|
13336
|
+
return null;
|
|
13337
|
+
}
|
|
13338
|
+
if (!/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/i.test(gstin.trim())) {
|
|
13339
|
+
return "Invalid GSTIN number (15 characters, e.g. 22AAAAA0000A1Z5)";
|
|
13340
|
+
}
|
|
13341
|
+
return null;
|
|
13342
|
+
}
|
|
13343
|
+
chunkUSNT2KNT_cjs.__name(validateGstin, "validateGstin");
|
|
13344
|
+
function validateIndiaTaxIds(gstin, pan, options) {
|
|
13345
|
+
const gstinErr = validateGstin(gstin, {
|
|
13346
|
+
required: options?.requiredGstin
|
|
13347
|
+
});
|
|
13348
|
+
if (gstinErr) return gstinErr;
|
|
13349
|
+
if (options?.requiredPan && (!pan || !pan.trim())) {
|
|
13350
|
+
return "PAN is required";
|
|
13240
13351
|
}
|
|
13241
|
-
if (pan && !/^[A-Z]{5}[0-9]{4}[A-Z]$/i.test(pan)) {
|
|
13352
|
+
if (pan && !/^[A-Z]{5}[0-9]{4}[A-Z]$/i.test(pan.trim())) {
|
|
13242
13353
|
return "Invalid PAN format (e.g. ABCDE1234F)";
|
|
13243
13354
|
}
|
|
13244
13355
|
return null;
|
|
@@ -13246,7 +13357,7 @@ function validateIndiaTaxIds(gstin, pan) {
|
|
|
13246
13357
|
chunkUSNT2KNT_cjs.__name(validateIndiaTaxIds, "validateIndiaTaxIds");
|
|
13247
13358
|
function validateAadhaar(aadhaar) {
|
|
13248
13359
|
if (!aadhaar) return null;
|
|
13249
|
-
if (!/^[0-9]{12}$/.test(aadhaar)) {
|
|
13360
|
+
if (!/^[0-9]{12}$/.test(aadhaar.replace(/\s+/g, ""))) {
|
|
13250
13361
|
return "Invalid Aadhaar number (12 digits)";
|
|
13251
13362
|
}
|
|
13252
13363
|
return null;
|
|
@@ -13254,11 +13365,13 @@ function validateAadhaar(aadhaar) {
|
|
|
13254
13365
|
chunkUSNT2KNT_cjs.__name(validateAadhaar, "validateAadhaar");
|
|
13255
13366
|
function validatePersonKyc(person, options) {
|
|
13256
13367
|
const required = options?.required === true;
|
|
13257
|
-
if (required && !person.aadhaarNo) return "Aadhaar number is required";
|
|
13258
|
-
if (required && !person.panNo) return "PAN is required";
|
|
13368
|
+
if (required && (!person.aadhaarNo || !person.aadhaarNo.trim())) return "Aadhaar number is required";
|
|
13369
|
+
if (required && (!person.panNo || !person.panNo.trim())) return "PAN is required";
|
|
13259
13370
|
const aadhaarErr = validateAadhaar(person.aadhaarNo ?? null);
|
|
13260
13371
|
if (aadhaarErr) return aadhaarErr;
|
|
13261
|
-
const panErr = validateIndiaTaxIds(null, person.panNo ?? null
|
|
13372
|
+
const panErr = validateIndiaTaxIds(null, person.panNo ?? null, {
|
|
13373
|
+
requiredPan: required
|
|
13374
|
+
});
|
|
13262
13375
|
if (panErr) return panErr;
|
|
13263
13376
|
return null;
|
|
13264
13377
|
}
|
|
@@ -13604,7 +13717,9 @@ function createVendorOnboardHandlers(config) {
|
|
|
13604
13717
|
}, {
|
|
13605
13718
|
getDataSource: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => dataSource, "getDataSource"),
|
|
13606
13719
|
entityMap: {
|
|
13607
|
-
configs: entityMap.configs
|
|
13720
|
+
configs: entityMap.configs,
|
|
13721
|
+
users: entityMap.users,
|
|
13722
|
+
vendors: entityMap.vendors
|
|
13608
13723
|
},
|
|
13609
13724
|
getCms
|
|
13610
13725
|
});
|
|
@@ -13730,7 +13845,9 @@ function createVendorOnboardHandlers(config) {
|
|
|
13730
13845
|
const profile = parseVendorProfileFromBody(body.vendor, {
|
|
13731
13846
|
defaultRegistrationStatus: "approved"
|
|
13732
13847
|
});
|
|
13733
|
-
const gstError =
|
|
13848
|
+
const gstError = validateGstin(profile.gstin, {
|
|
13849
|
+
required: true
|
|
13850
|
+
});
|
|
13734
13851
|
if (gstError) return json({
|
|
13735
13852
|
error: gstError
|
|
13736
13853
|
}, {
|
|
@@ -27532,16 +27649,16 @@ function whatsappPlugin(config = {}) {
|
|
|
27532
27649
|
db = await getWhatsAppSettings?.() ?? {};
|
|
27533
27650
|
} catch {
|
|
27534
27651
|
}
|
|
27535
|
-
if (!
|
|
27652
|
+
if (!chunkJN4AFHZ4_cjs.isWhatsAppPluginEnabled(db)) {
|
|
27536
27653
|
context.logger.warn("WhatsApp plugin skipped: disabled in Plugins \u2192 WhatsApp");
|
|
27537
27654
|
return null;
|
|
27538
27655
|
}
|
|
27539
|
-
const merged =
|
|
27540
|
-
if (!getWhatsAppSettings && !
|
|
27656
|
+
const merged = chunkJN4AFHZ4_cjs.mergeWhatsAppConfigLayers(env, db, staticRest);
|
|
27657
|
+
if (!getWhatsAppSettings && !chunkJN4AFHZ4_cjs.whatsAppConfigured(merged)) {
|
|
27541
27658
|
context.logger.warn("WhatsApp plugin skipped: set WHATSAPP_ACCESS_TOKEN and WHATSAPP_PHONE_NUMBER_ID, or pass getWhatsAppSettings");
|
|
27542
27659
|
return null;
|
|
27543
27660
|
}
|
|
27544
|
-
const svc = new
|
|
27661
|
+
const svc = new chunkJN4AFHZ4_cjs.WhatsAppService(env, staticRest, getWhatsAppSettings, getMessageTemplateRow);
|
|
27545
27662
|
return {
|
|
27546
27663
|
send: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((opts) => svc.send(opts), "send")
|
|
27547
27664
|
};
|
|
@@ -27618,7 +27735,7 @@ function registerMessagingQueueProcessors(cms, entityMap) {
|
|
|
27618
27735
|
getDataSource: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async () => cms.dataSource, "getDataSource"),
|
|
27619
27736
|
entityMap
|
|
27620
27737
|
});
|
|
27621
|
-
|
|
27738
|
+
chunkJN4AFHZ4_cjs.registerWhatsAppQueueProcessor(cms);
|
|
27622
27739
|
}
|
|
27623
27740
|
chunkUSNT2KNT_cjs.__name(registerMessagingQueueProcessors, "registerMessagingQueueProcessors");
|
|
27624
27741
|
async function ensureMessagingPluginsOnCms(base, options) {
|
|
@@ -27647,7 +27764,7 @@ async function ensureMessagingPluginsOnCms(base, options) {
|
|
|
27647
27764
|
}
|
|
27648
27765
|
if (!cms.getPlugin("email")) {
|
|
27649
27766
|
try {
|
|
27650
|
-
const instance = await
|
|
27767
|
+
const instance = await chunkJN4AFHZ4_cjs.emailPlugin({
|
|
27651
27768
|
type: "SMTP",
|
|
27652
27769
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
27653
27770
|
to: config.SMTP_TO ?? ""
|
|
@@ -27688,7 +27805,7 @@ function messagingPlugins(options) {
|
|
|
27688
27805
|
const config = options.config ?? (typeof process !== "undefined" ? process.env : {});
|
|
27689
27806
|
return [
|
|
27690
27807
|
queuePlugin(),
|
|
27691
|
-
|
|
27808
|
+
chunkJN4AFHZ4_cjs.emailPlugin({
|
|
27692
27809
|
type: "SMTP",
|
|
27693
27810
|
from: config.SMTP_FROM ?? "no-reply@localhost",
|
|
27694
27811
|
to: config.SMTP_TO ?? ""
|
|
@@ -27822,7 +27939,7 @@ function createCmsApiHandler(config) {
|
|
|
27822
27939
|
} : void 0;
|
|
27823
27940
|
const entityMap = withLlmKnowledgeEntityFallbacks(rawEntityMap);
|
|
27824
27941
|
if (getCms) {
|
|
27825
|
-
|
|
27942
|
+
chunkJN4AFHZ4_cjs.initWhatsappTriggerDispatcher({
|
|
27826
27943
|
dataSource,
|
|
27827
27944
|
entityMap,
|
|
27828
27945
|
getCms
|
|
@@ -29371,7 +29488,10 @@ function createCmsApiHandler(config) {
|
|
|
29371
29488
|
if (pe) return pe;
|
|
29372
29489
|
try {
|
|
29373
29490
|
const body = await req.json();
|
|
29374
|
-
const
|
|
29491
|
+
const discountIdsRaw = Array.isArray(body?.discountIds) ? body.discountIds : body?.discountId ? [
|
|
29492
|
+
body.discountId
|
|
29493
|
+
] : [];
|
|
29494
|
+
const discountIds = discountIdsRaw.map((id) => Number(id)).filter((id) => Number.isFinite(id) && id > 0);
|
|
29375
29495
|
const currency = typeof body?.currency === "string" ? body.currency.trim().toUpperCase() : "INR";
|
|
29376
29496
|
let vendorId = null;
|
|
29377
29497
|
if (resolveSessionUser) {
|
|
@@ -29381,7 +29501,7 @@ function createCmsApiHandler(config) {
|
|
|
29381
29501
|
}
|
|
29382
29502
|
const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
|
|
29383
29503
|
if (orderLinesNorm && orderLinesNorm.length > 0) {
|
|
29384
|
-
const result2 = await calculateOrderTotalsFromLines(dataSource, entityMap, orderLinesNorm, currency,
|
|
29504
|
+
const result2 = await calculateOrderTotalsFromLines(dataSource, entityMap, orderLinesNorm, currency, discountIds.length > 0 ? discountIds : null, vendorId);
|
|
29385
29505
|
return config.json(result2);
|
|
29386
29506
|
}
|
|
29387
29507
|
const itemsSummary = String(body?.itemsSummary ?? "").trim();
|
|
@@ -29394,7 +29514,7 @@ function createCmsApiHandler(config) {
|
|
|
29394
29514
|
lines: []
|
|
29395
29515
|
});
|
|
29396
29516
|
}
|
|
29397
|
-
const result = await calculateOrderTotals(dataSource, entityMap, itemsSummary,
|
|
29517
|
+
const result = await calculateOrderTotals(dataSource, entityMap, itemsSummary, discountIds[0] ?? null, vendorId);
|
|
29398
29518
|
return config.json(result);
|
|
29399
29519
|
} catch (err) {
|
|
29400
29520
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -29582,7 +29702,7 @@ function createCmsApiHandler(config) {
|
|
|
29582
29702
|
status: 400
|
|
29583
29703
|
});
|
|
29584
29704
|
}
|
|
29585
|
-
const { resendOrderNotification } = await import('./order-notification-dispatcher-
|
|
29705
|
+
const { resendOrderNotification } = await import('./order-notification-dispatcher-YBAWDOIO.cjs');
|
|
29586
29706
|
const result = await resendOrderNotification(triggerKey, orderId, {
|
|
29587
29707
|
dataSource,
|
|
29588
29708
|
entityMap,
|
|
@@ -29682,7 +29802,7 @@ function createCmsApiHandler(config) {
|
|
|
29682
29802
|
status: "cancelled"
|
|
29683
29803
|
});
|
|
29684
29804
|
const fireOrderCancelledNotification = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((refundAmount) => {
|
|
29685
|
-
void import('./emit-order-notification-trigger-
|
|
29805
|
+
void import('./emit-order-notification-trigger-NR3VN6C6.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
29686
29806
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
29687
29807
|
dataSource,
|
|
29688
29808
|
entityMap
|
|
@@ -30715,7 +30835,7 @@ function createStorefrontApiHandler(config) {
|
|
|
30715
30835
|
const otpPepper = config.otpPepper;
|
|
30716
30836
|
const defaultPhoneCc = config.defaultPhoneCountryCode;
|
|
30717
30837
|
function fireOrderPlacedNotification(orderId) {
|
|
30718
|
-
void import('./emit-order-notification-trigger-
|
|
30838
|
+
void import('./emit-order-notification-trigger-NR3VN6C6.cjs').then(({ fireOrderNotificationTrigger }) => {
|
|
30719
30839
|
fireOrderNotificationTrigger("order_placed", orderId, {
|
|
30720
30840
|
dataSource,
|
|
30721
30841
|
entityMap
|