@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,16 +1,16 @@
|
|
|
1
|
+
import { JOB_RUNNER_QUEUE } from './chunk-GO7PPYNU.js';
|
|
1
2
|
import { validateInventoryForConfirmedOrderLines, orderStatusHoldsStock, reconcileOrderInventoryBetweenSnapshots, orderInventorySnapshotFromRow, validateInventoryForOrderBecomingConfirmed } from './chunk-3K5AIEIZ.js';
|
|
2
|
-
import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool,
|
|
3
|
+
import { resolveChatEmailToolSettings, CHAT_EMAIL_LOG, detectChatLeadIntent, parseIntentRecipientEmails, sendChatLeadEmail, buildTranscriptForLeadEmail, buildChatbotSystemPromptWithEmailTool, sendFcmPushNotification, parseEmailRecipientsFromConfig, isWhatsAppPluginEnabled, mergeWhatsAppConfigLayers, whatsAppConfigured, WhatsAppService, registerWhatsAppQueueProcessor, emailPlugin, initWhatsappTriggerDispatcher } from './chunk-CTXBYO2J.js';
|
|
3
4
|
import { inviteStatusForActivation } from './chunk-JXF23MPG.js';
|
|
4
5
|
import { queueEmail, queueVendorOnboardEmails, registerEmailQueueProcessor } from './chunk-L3525VXI.js';
|
|
5
6
|
import { mergeEmailLayoutCompanyDetails, unwrapErpReadData, mapErpPayloadToFulfillment, extractChildOrderRefsFromSalePayload, mapErpPayloadToInvoiceNumber, streamOrderInvoicePdf } from './chunk-2KUCQVAQ.js';
|
|
7
|
+
import { isErpIntegrationEnabled } from './chunk-JC6DLWTE.js';
|
|
6
8
|
import { getSmsTemplateDefault, SMS_MESSAGE_TEMPLATE_DEFAULTS } from './chunk-MQBT33IV.js';
|
|
7
9
|
import { EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS, EVENT_ORDER_TEMPLATE_KEY, EVENT_ORDER_TEMPLATE_VARIABLES } from './chunk-AYERBA7I.js';
|
|
8
|
-
import { JOB_RUNNER_QUEUE } from './chunk-GO7PPYNU.js';
|
|
9
10
|
import { ensureCustomerRecord, linkUnclaimedContactToUser, ensureCustomerForUser, canManageRoles, sessionHasEntityAccess } from './chunk-RK5ETF2I.js';
|
|
10
11
|
import { retireSoftDeletedUniqueValue, activeUniqueValueExists } from './chunk-DBPSJYLZ.js';
|
|
11
12
|
import { permissionRowsToRecord, logRbac, isSuperAdmin, vendorPortalFlagsFromUser, VENDOR_SCOPED_STORE_ENTITIES, isVendorPortalUser, getPermissionableEntityKeys, VENDOR_STORE_RBAC_ENTITIES, isSuperAdminGroupName, VENDOR_RBAC_ENTITIES, VENDOR_VIEWER_ROLE_NAME, DEFAULT_VENDOR_ROLE_DEFS, VENDOR_GROUP_NAME, resolveVendorScopeFromSessionUser, canManageVendorRoles, isPlatformAdministrator, canManageVendorTeam, resolveDisabledMultiVendorScope, logEntityAccessDecision, explainSessionEntityAccess } from './chunk-JIWUVQ6B.js';
|
|
12
13
|
import { queueErp } from './chunk-SYBOCAWB.js';
|
|
13
|
-
import { isErpIntegrationEnabled } from './chunk-JC6DLWTE.js';
|
|
14
14
|
import { __name } from './chunk-SHUYVCID.js';
|
|
15
15
|
import { PrimaryGeneratedColumn, Column, Entity, CreateDateColumn, UpdateDateColumn, Unique, ManyToOne, JoinColumn, OneToMany, Index, ManyToMany, JoinTable, In, ILike, Between, MoreThanOrEqual, LessThanOrEqual, Not, MoreThan, IsNull } from 'typeorm';
|
|
16
16
|
import { Country, State, City } from 'country-state-city';
|
|
@@ -2966,46 +2966,51 @@ async function calculateOrderTotalsFromLines(dataSource, entityMap, lineInputs,
|
|
|
2966
2966
|
total
|
|
2967
2967
|
});
|
|
2968
2968
|
}
|
|
2969
|
-
|
|
2969
|
+
const dIds = Array.isArray(discountId) ? discountId.filter((id) => id != null && Number.isFinite(id) && id > 0) : discountId != null && Number.isFinite(discountId) && discountId > 0 ? [
|
|
2970
|
+
discountId
|
|
2971
|
+
] : [];
|
|
2972
|
+
if (dIds.length > 0 && entityMap["discounts"]) {
|
|
2970
2973
|
try {
|
|
2971
2974
|
const discountRepo = dataSource.getRepository(entityMap["discounts"]);
|
|
2972
2975
|
const rulesRepo = entityMap["discount_rules"] ? dataSource.getRepository(entityMap["discount_rules"]) : null;
|
|
2973
|
-
const
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
const discountedAmount = line.subtotal - (line.discount ?? 0);
|
|
3000
|
-
line.tax = discountedAmount * line.taxRate / 100;
|
|
3001
|
-
line.total = discountedAmount + line.tax;
|
|
2976
|
+
for (const dId of dIds) {
|
|
2977
|
+
const discountRow = await discountRepo.findOne({
|
|
2978
|
+
where: withDiscountVendorWhere({
|
|
2979
|
+
id: dId
|
|
2980
|
+
}, vendorId)
|
|
2981
|
+
});
|
|
2982
|
+
if (discountRow) {
|
|
2983
|
+
const flatRules = rulesRepo ? await rulesRepo.find({
|
|
2984
|
+
where: {
|
|
2985
|
+
discountId: dId
|
|
2986
|
+
}
|
|
2987
|
+
}) : [];
|
|
2988
|
+
const discountForEval = {
|
|
2989
|
+
...discountRow,
|
|
2990
|
+
rules: flatRules
|
|
2991
|
+
};
|
|
2992
|
+
const cartLines = lines.filter((l) => l.found && l.productId != null).map((l) => ({
|
|
2993
|
+
productId: l.productId,
|
|
2994
|
+
quantity: l.quantity,
|
|
2995
|
+
unitPrice: l.unitPrice,
|
|
2996
|
+
subtotal: l.subtotal
|
|
2997
|
+
}));
|
|
2998
|
+
const evalResult = evaluateDiscount(discountForEval, cartLines);
|
|
2999
|
+
if (evalResult.conditionsMet) {
|
|
3000
|
+
const totalDiscountApplied = applyDiscountToOrderLines(lines, evalResult, discountRow.maxDiscountAmount);
|
|
3001
|
+
orderDiscount += totalDiscountApplied;
|
|
3002
3002
|
}
|
|
3003
|
-
orderDiscount = totalDiscountApplied;
|
|
3004
|
-
orderTotal = lines.reduce((s, l) => s + l.total, 0);
|
|
3005
|
-
orderSubTotal = lines.reduce((s, l) => s + l.subtotal, 0);
|
|
3006
|
-
orderTax = lines.reduce((s, l) => s + l.tax, 0);
|
|
3007
3003
|
}
|
|
3008
3004
|
}
|
|
3005
|
+
for (const line of lines) {
|
|
3006
|
+
if (!line.found || line.taxRate === 0) continue;
|
|
3007
|
+
const discountedAmount = Math.max(0, line.subtotal - (line.discount ?? 0));
|
|
3008
|
+
line.tax = discountedAmount * line.taxRate / 100;
|
|
3009
|
+
line.total = discountedAmount + line.tax;
|
|
3010
|
+
}
|
|
3011
|
+
orderTotal = lines.reduce((s, l) => s + l.total, 0);
|
|
3012
|
+
orderSubTotal = lines.reduce((s, l) => s + l.subtotal, 0);
|
|
3013
|
+
orderTax = lines.reduce((s, l) => s + l.tax, 0);
|
|
3009
3014
|
} catch (err) {
|
|
3010
3015
|
logCrudServerError("discount evaluation failed", {
|
|
3011
3016
|
discountId,
|
|
@@ -5039,7 +5044,7 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
5039
5044
|
await recordDiscountUsage2(dataSource, entityMap, created.id, orderDiscountId, persistBody.contactId, discount);
|
|
5040
5045
|
}
|
|
5041
5046
|
const orderIdForNotify = created.id;
|
|
5042
|
-
void import('./emit-order-notification-trigger-
|
|
5047
|
+
void import('./emit-order-notification-trigger-HZQPPSFB.js').then(({ fireOrderNotificationTrigger }) => {
|
|
5043
5048
|
fireOrderNotificationTrigger("order_placed", orderIdForNotify, {
|
|
5044
5049
|
dataSource,
|
|
5045
5050
|
entityMap
|
|
@@ -5216,9 +5221,14 @@ function createCrudHandler(dataSource, entityMap, options) {
|
|
|
5216
5221
|
const where = hasDeleted ? {
|
|
5217
5222
|
deleted: false
|
|
5218
5223
|
} : {};
|
|
5219
|
-
|
|
5224
|
+
let data = await repo.find({
|
|
5220
5225
|
where
|
|
5221
5226
|
});
|
|
5227
|
+
const scope = await resolveScope();
|
|
5228
|
+
const flags = await getVendorCatalogCreateFlags(dataSource);
|
|
5229
|
+
if (scope.type !== "all") {
|
|
5230
|
+
data = data.filter((row) => vendorScopeRowAccess(row, scope, resource, flags) === "ok");
|
|
5231
|
+
}
|
|
5222
5232
|
const excludeCols = /* @__PURE__ */ new Set([
|
|
5223
5233
|
"deletedAt",
|
|
5224
5234
|
"deletedBy",
|
|
@@ -12995,17 +13005,80 @@ async function getSettingsGroup(deps, group) {
|
|
|
12995
13005
|
]));
|
|
12996
13006
|
}
|
|
12997
13007
|
__name(getSettingsGroup, "getSettingsGroup");
|
|
13008
|
+
async function getSuperAdminEmails(deps) {
|
|
13009
|
+
try {
|
|
13010
|
+
const ds = await deps.getDataSource();
|
|
13011
|
+
if (!deps.entityMap.users) return [];
|
|
13012
|
+
const userRepo = ds.getRepository(deps.entityMap.users);
|
|
13013
|
+
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)", {
|
|
13014
|
+
adminGroupNames: [
|
|
13015
|
+
"administrator",
|
|
13016
|
+
"admin",
|
|
13017
|
+
"super admin",
|
|
13018
|
+
"superadmin"
|
|
13019
|
+
]
|
|
13020
|
+
}).select([
|
|
13021
|
+
"u.email"
|
|
13022
|
+
]).getMany();
|
|
13023
|
+
return superAdmins.map((u) => String(u.email ?? "").trim().toLowerCase()).filter((e) => Boolean(e));
|
|
13024
|
+
} catch {
|
|
13025
|
+
return [];
|
|
13026
|
+
}
|
|
13027
|
+
}
|
|
13028
|
+
__name(getSuperAdminEmails, "getSuperAdminEmails");
|
|
13029
|
+
async function getVendorEmails(deps) {
|
|
13030
|
+
const emails = /* @__PURE__ */ new Set();
|
|
13031
|
+
try {
|
|
13032
|
+
const ds = await deps.getDataSource();
|
|
13033
|
+
if (deps.entityMap.vendors) {
|
|
13034
|
+
const vendors = await ds.getRepository(deps.entityMap.vendors).find({
|
|
13035
|
+
where: {
|
|
13036
|
+
deleted: false
|
|
13037
|
+
},
|
|
13038
|
+
select: [
|
|
13039
|
+
"email"
|
|
13040
|
+
]
|
|
13041
|
+
});
|
|
13042
|
+
for (const v of vendors) {
|
|
13043
|
+
const e = String(v.email ?? "").trim().toLowerCase();
|
|
13044
|
+
if (e) emails.add(e);
|
|
13045
|
+
}
|
|
13046
|
+
}
|
|
13047
|
+
if (deps.entityMap.users) {
|
|
13048
|
+
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)", {
|
|
13049
|
+
vGroup: "%vendor%"
|
|
13050
|
+
}).select([
|
|
13051
|
+
"u.email"
|
|
13052
|
+
]).getMany();
|
|
13053
|
+
for (const u of vendorUsers) {
|
|
13054
|
+
const e = String(u.email ?? "").trim().toLowerCase();
|
|
13055
|
+
if (e) emails.add(e);
|
|
13056
|
+
}
|
|
13057
|
+
}
|
|
13058
|
+
} catch {
|
|
13059
|
+
}
|
|
13060
|
+
return emails;
|
|
13061
|
+
}
|
|
13062
|
+
__name(getVendorEmails, "getVendorEmails");
|
|
12998
13063
|
async function sendVendorOnboardEmails(input, deps) {
|
|
12999
13064
|
let ownerEmailSent = false;
|
|
13000
13065
|
try {
|
|
13001
|
-
const [branding, emailSettings] = await Promise.all([
|
|
13066
|
+
const [branding, emailSettings, superAdminEmails, vendorEmailSet] = await Promise.all([
|
|
13002
13067
|
getSettingsGroup(deps, "branding"),
|
|
13003
|
-
getSettingsGroup(deps, "email")
|
|
13068
|
+
getSettingsGroup(deps, "email"),
|
|
13069
|
+
getSuperAdminEmails(deps),
|
|
13070
|
+
getVendorEmails(deps)
|
|
13004
13071
|
]);
|
|
13005
13072
|
const companyDetails = mergeEmailLayoutCompanyDetails(branding, emailSettings);
|
|
13006
|
-
const
|
|
13007
|
-
const sendToOwner = input.sendToOwner !== false;
|
|
13073
|
+
const configuredNotify = parseEmailRecipientsFromConfig(emailSettings.salesTeamEmails ?? emailSettings.salesTeamEmail);
|
|
13008
13074
|
const ownerEmail = input.ownerEmail?.trim() || "";
|
|
13075
|
+
const ownerEmailLower = ownerEmail.toLowerCase();
|
|
13076
|
+
const sendToOwner = input.sendToOwner !== false;
|
|
13077
|
+
const combined = [
|
|
13078
|
+
...configuredNotify,
|
|
13079
|
+
...superAdminEmails
|
|
13080
|
+
];
|
|
13081
|
+
const notifyEmails = Array.from(new Set(combined.map((e) => e.trim().toLowerCase()).filter((e) => e && e !== ownerEmailLower && !vendorEmailSet.has(e))));
|
|
13009
13082
|
const cms = await deps.getCms();
|
|
13010
13083
|
await queueVendorOnboardEmails(cms, {
|
|
13011
13084
|
vendorName: input.vendorName,
|
|
@@ -13152,8 +13225,6 @@ async function getDefaultStaffRoleIdForVendor(em, vendorId) {
|
|
|
13152
13225
|
return id != null ? Number(id) : null;
|
|
13153
13226
|
}
|
|
13154
13227
|
__name(getDefaultStaffRoleIdForVendor, "getDefaultStaffRoleIdForVendor");
|
|
13155
|
-
|
|
13156
|
-
// src/lib/vendor-profile.ts
|
|
13157
13228
|
var VENDOR_REGISTRATION_STATUSES = [
|
|
13158
13229
|
{
|
|
13159
13230
|
value: "pending",
|
|
@@ -13172,6 +13243,30 @@ var VENDOR_REGISTRATION_STATUSES = [
|
|
|
13172
13243
|
label: "Suspended"
|
|
13173
13244
|
}
|
|
13174
13245
|
];
|
|
13246
|
+
(() => {
|
|
13247
|
+
const list = [];
|
|
13248
|
+
const seenCodes = /* @__PURE__ */ new Set();
|
|
13249
|
+
for (const c of Country.getAllCountries()) {
|
|
13250
|
+
if (!c.phonecode) continue;
|
|
13251
|
+
const rawCode = c.phonecode.replace(/^\+/, "").trim();
|
|
13252
|
+
if (!rawCode) continue;
|
|
13253
|
+
const code = `+${rawCode}`;
|
|
13254
|
+
const key = `${code}-${c.name}`;
|
|
13255
|
+
if (seenCodes.has(key)) continue;
|
|
13256
|
+
seenCodes.add(key);
|
|
13257
|
+
list.push({
|
|
13258
|
+
code,
|
|
13259
|
+
country: c.name,
|
|
13260
|
+
isoCode: c.isoCode,
|
|
13261
|
+
label: `${code} (${c.name})`
|
|
13262
|
+
});
|
|
13263
|
+
}
|
|
13264
|
+
return list.sort((a, b) => {
|
|
13265
|
+
if (a.code === "+91" && b.code !== "+91") return -1;
|
|
13266
|
+
if (b.code === "+91" && a.code !== "+91") return 1;
|
|
13267
|
+
return a.country.localeCompare(b.country);
|
|
13268
|
+
});
|
|
13269
|
+
})();
|
|
13175
13270
|
function trimOrNull(value) {
|
|
13176
13271
|
if (typeof value !== "string") return null;
|
|
13177
13272
|
const trimmed = value.trim();
|
|
@@ -13224,11 +13319,27 @@ function parseVendorPersonProfileFromBody(raw, fallbacks) {
|
|
|
13224
13319
|
};
|
|
13225
13320
|
}
|
|
13226
13321
|
__name(parseVendorPersonProfileFromBody, "parseVendorPersonProfileFromBody");
|
|
13227
|
-
function
|
|
13228
|
-
|
|
13229
|
-
|
|
13322
|
+
function validateGstin(gstin, options) {
|
|
13323
|
+
const required = options?.required === true;
|
|
13324
|
+
if (!gstin || !gstin.trim()) {
|
|
13325
|
+
if (required) return "GSTIN number is required";
|
|
13326
|
+
return null;
|
|
13327
|
+
}
|
|
13328
|
+
if (!/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/i.test(gstin.trim())) {
|
|
13329
|
+
return "Invalid GSTIN number (15 characters, e.g. 22AAAAA0000A1Z5)";
|
|
13330
|
+
}
|
|
13331
|
+
return null;
|
|
13332
|
+
}
|
|
13333
|
+
__name(validateGstin, "validateGstin");
|
|
13334
|
+
function validateIndiaTaxIds(gstin, pan, options) {
|
|
13335
|
+
const gstinErr = validateGstin(gstin, {
|
|
13336
|
+
required: options?.requiredGstin
|
|
13337
|
+
});
|
|
13338
|
+
if (gstinErr) return gstinErr;
|
|
13339
|
+
if (options?.requiredPan && (!pan || !pan.trim())) {
|
|
13340
|
+
return "PAN is required";
|
|
13230
13341
|
}
|
|
13231
|
-
if (pan && !/^[A-Z]{5}[0-9]{4}[A-Z]$/i.test(pan)) {
|
|
13342
|
+
if (pan && !/^[A-Z]{5}[0-9]{4}[A-Z]$/i.test(pan.trim())) {
|
|
13232
13343
|
return "Invalid PAN format (e.g. ABCDE1234F)";
|
|
13233
13344
|
}
|
|
13234
13345
|
return null;
|
|
@@ -13236,7 +13347,7 @@ function validateIndiaTaxIds(gstin, pan) {
|
|
|
13236
13347
|
__name(validateIndiaTaxIds, "validateIndiaTaxIds");
|
|
13237
13348
|
function validateAadhaar(aadhaar) {
|
|
13238
13349
|
if (!aadhaar) return null;
|
|
13239
|
-
if (!/^[0-9]{12}$/.test(aadhaar)) {
|
|
13350
|
+
if (!/^[0-9]{12}$/.test(aadhaar.replace(/\s+/g, ""))) {
|
|
13240
13351
|
return "Invalid Aadhaar number (12 digits)";
|
|
13241
13352
|
}
|
|
13242
13353
|
return null;
|
|
@@ -13244,11 +13355,13 @@ function validateAadhaar(aadhaar) {
|
|
|
13244
13355
|
__name(validateAadhaar, "validateAadhaar");
|
|
13245
13356
|
function validatePersonKyc(person, options) {
|
|
13246
13357
|
const required = options?.required === true;
|
|
13247
|
-
if (required && !person.aadhaarNo) return "Aadhaar number is required";
|
|
13248
|
-
if (required && !person.panNo) return "PAN is required";
|
|
13358
|
+
if (required && (!person.aadhaarNo || !person.aadhaarNo.trim())) return "Aadhaar number is required";
|
|
13359
|
+
if (required && (!person.panNo || !person.panNo.trim())) return "PAN is required";
|
|
13249
13360
|
const aadhaarErr = validateAadhaar(person.aadhaarNo ?? null);
|
|
13250
13361
|
if (aadhaarErr) return aadhaarErr;
|
|
13251
|
-
const panErr = validateIndiaTaxIds(null, person.panNo ?? null
|
|
13362
|
+
const panErr = validateIndiaTaxIds(null, person.panNo ?? null, {
|
|
13363
|
+
requiredPan: required
|
|
13364
|
+
});
|
|
13252
13365
|
if (panErr) return panErr;
|
|
13253
13366
|
return null;
|
|
13254
13367
|
}
|
|
@@ -13594,7 +13707,9 @@ function createVendorOnboardHandlers(config) {
|
|
|
13594
13707
|
}, {
|
|
13595
13708
|
getDataSource: /* @__PURE__ */ __name(async () => dataSource, "getDataSource"),
|
|
13596
13709
|
entityMap: {
|
|
13597
|
-
configs: entityMap.configs
|
|
13710
|
+
configs: entityMap.configs,
|
|
13711
|
+
users: entityMap.users,
|
|
13712
|
+
vendors: entityMap.vendors
|
|
13598
13713
|
},
|
|
13599
13714
|
getCms
|
|
13600
13715
|
});
|
|
@@ -13720,7 +13835,9 @@ function createVendorOnboardHandlers(config) {
|
|
|
13720
13835
|
const profile = parseVendorProfileFromBody(body.vendor, {
|
|
13721
13836
|
defaultRegistrationStatus: "approved"
|
|
13722
13837
|
});
|
|
13723
|
-
const gstError =
|
|
13838
|
+
const gstError = validateGstin(profile.gstin, {
|
|
13839
|
+
required: true
|
|
13840
|
+
});
|
|
13724
13841
|
if (gstError) return json({
|
|
13725
13842
|
error: gstError
|
|
13726
13843
|
}, {
|
|
@@ -29361,7 +29478,10 @@ function createCmsApiHandler(config) {
|
|
|
29361
29478
|
if (pe) return pe;
|
|
29362
29479
|
try {
|
|
29363
29480
|
const body = await req.json();
|
|
29364
|
-
const
|
|
29481
|
+
const discountIdsRaw = Array.isArray(body?.discountIds) ? body.discountIds : body?.discountId ? [
|
|
29482
|
+
body.discountId
|
|
29483
|
+
] : [];
|
|
29484
|
+
const discountIds = discountIdsRaw.map((id) => Number(id)).filter((id) => Number.isFinite(id) && id > 0);
|
|
29365
29485
|
const currency = typeof body?.currency === "string" ? body.currency.trim().toUpperCase() : "INR";
|
|
29366
29486
|
let vendorId = null;
|
|
29367
29487
|
if (resolveSessionUser) {
|
|
@@ -29371,7 +29491,7 @@ function createCmsApiHandler(config) {
|
|
|
29371
29491
|
}
|
|
29372
29492
|
const orderLinesNorm = normalizeOrderLinesInput(body?.orderLines);
|
|
29373
29493
|
if (orderLinesNorm && orderLinesNorm.length > 0) {
|
|
29374
|
-
const result2 = await calculateOrderTotalsFromLines(dataSource, entityMap, orderLinesNorm, currency,
|
|
29494
|
+
const result2 = await calculateOrderTotalsFromLines(dataSource, entityMap, orderLinesNorm, currency, discountIds.length > 0 ? discountIds : null, vendorId);
|
|
29375
29495
|
return config.json(result2);
|
|
29376
29496
|
}
|
|
29377
29497
|
const itemsSummary = String(body?.itemsSummary ?? "").trim();
|
|
@@ -29384,7 +29504,7 @@ function createCmsApiHandler(config) {
|
|
|
29384
29504
|
lines: []
|
|
29385
29505
|
});
|
|
29386
29506
|
}
|
|
29387
|
-
const result = await calculateOrderTotals(dataSource, entityMap, itemsSummary,
|
|
29507
|
+
const result = await calculateOrderTotals(dataSource, entityMap, itemsSummary, discountIds[0] ?? null, vendorId);
|
|
29388
29508
|
return config.json(result);
|
|
29389
29509
|
} catch (err) {
|
|
29390
29510
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -29572,7 +29692,7 @@ function createCmsApiHandler(config) {
|
|
|
29572
29692
|
status: 400
|
|
29573
29693
|
});
|
|
29574
29694
|
}
|
|
29575
|
-
const { resendOrderNotification } = await import('./order-notification-dispatcher-
|
|
29695
|
+
const { resendOrderNotification } = await import('./order-notification-dispatcher-AT4IFAGL.js');
|
|
29576
29696
|
const result = await resendOrderNotification(triggerKey, orderId, {
|
|
29577
29697
|
dataSource,
|
|
29578
29698
|
entityMap,
|
|
@@ -29672,7 +29792,7 @@ function createCmsApiHandler(config) {
|
|
|
29672
29792
|
status: "cancelled"
|
|
29673
29793
|
});
|
|
29674
29794
|
const fireOrderCancelledNotification = /* @__PURE__ */ __name((refundAmount) => {
|
|
29675
|
-
void import('./emit-order-notification-trigger-
|
|
29795
|
+
void import('./emit-order-notification-trigger-HZQPPSFB.js').then(({ fireOrderNotificationTrigger }) => {
|
|
29676
29796
|
fireOrderNotificationTrigger("order_cancelled", orderId, {
|
|
29677
29797
|
dataSource,
|
|
29678
29798
|
entityMap
|
|
@@ -30705,7 +30825,7 @@ function createStorefrontApiHandler(config) {
|
|
|
30705
30825
|
const otpPepper = config.otpPepper;
|
|
30706
30826
|
const defaultPhoneCc = config.defaultPhoneCountryCode;
|
|
30707
30827
|
function fireOrderPlacedNotification(orderId) {
|
|
30708
|
-
void import('./emit-order-notification-trigger-
|
|
30828
|
+
void import('./emit-order-notification-trigger-HZQPPSFB.js').then(({ fireOrderNotificationTrigger }) => {
|
|
30709
30829
|
fireOrderNotificationTrigger("order_placed", orderId, {
|
|
30710
30830
|
dataSource,
|
|
30711
30831
|
entityMap
|
|
@@ -61,7 +61,7 @@ async function emitOrderNotificationTrigger(triggerKey, orderId, deps, extra) {
|
|
|
61
61
|
total: fo.total ?? 0,
|
|
62
62
|
currency: String(fo.currency ?? "INR"),
|
|
63
63
|
vendorId: fo.vendorId ?? null,
|
|
64
|
-
|
|
64
|
+
extraVariables: extra?.extraVariables,
|
|
65
65
|
...extra?.refundAmount != null ? {
|
|
66
66
|
refundAmount: extra.refundAmount
|
|
67
67
|
} : {}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
// src/auth/auth-debug.ts
|
|
4
|
+
var LOG_PREFIX = "[cms-auth]";
|
|
5
|
+
function isAuthDebugEnabled() {
|
|
6
|
+
const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
7
|
+
return v === "1" || v === "true" || v === "yes";
|
|
8
|
+
}
|
|
9
|
+
__name(isAuthDebugEnabled, "isAuthDebugEnabled");
|
|
10
|
+
function isAuthDebugClientEnabled() {
|
|
11
|
+
if (typeof window === "undefined") return false;
|
|
12
|
+
const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
13
|
+
return v === "1" || v === "true" || v === "yes";
|
|
14
|
+
}
|
|
15
|
+
__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
|
|
16
|
+
function logAuth(message, data) {
|
|
17
|
+
if (!isAuthDebugEnabled()) return;
|
|
18
|
+
if (data) console.info(LOG_PREFIX, message, data);
|
|
19
|
+
else console.info(LOG_PREFIX, message);
|
|
20
|
+
}
|
|
21
|
+
__name(logAuth, "logAuth");
|
|
22
|
+
function logAuthClient(message, data) {
|
|
23
|
+
if (!isAuthDebugClientEnabled()) return;
|
|
24
|
+
if (data) console.info(LOG_PREFIX, message, data);
|
|
25
|
+
else console.info(LOG_PREFIX, message);
|
|
26
|
+
}
|
|
27
|
+
__name(logAuthClient, "logAuthClient");
|
|
28
|
+
function summarizeSessionUserForLog(user) {
|
|
29
|
+
if (!user || typeof user !== "object") return {
|
|
30
|
+
present: false
|
|
31
|
+
};
|
|
32
|
+
const u = user;
|
|
33
|
+
return {
|
|
34
|
+
present: true,
|
|
35
|
+
email: u.email ?? null,
|
|
36
|
+
id: u.id ?? null,
|
|
37
|
+
adminAccess: u.adminAccess ?? null,
|
|
38
|
+
isRBACAdmin: u.isRBACAdmin ?? null,
|
|
39
|
+
isVendorPortal: u.isVendorPortal ?? null,
|
|
40
|
+
groupName: u.groupName ?? null
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
|
|
44
|
+
function nextAuthCookieDebugInfo() {
|
|
45
|
+
const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
|
|
46
|
+
const isHttps = nextAuthUrl.startsWith("https");
|
|
47
|
+
return {
|
|
48
|
+
nextAuthUrl,
|
|
49
|
+
hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
|
|
50
|
+
cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
|
|
51
|
+
cookieSecure: isHttps,
|
|
52
|
+
nodeEnv: process.env.NODE_ENV ?? "(unset)"
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
|
|
56
|
+
|
|
57
|
+
// src/auth/middleware.ts
|
|
58
|
+
var defaultPublicApiMethods = {
|
|
59
|
+
"/api/contacts": [
|
|
60
|
+
"POST"
|
|
61
|
+
],
|
|
62
|
+
"/api/form-submissions": [
|
|
63
|
+
"POST"
|
|
64
|
+
],
|
|
65
|
+
"/api/blogs": [
|
|
66
|
+
"GET"
|
|
67
|
+
],
|
|
68
|
+
"/api/forms": [
|
|
69
|
+
"GET"
|
|
70
|
+
],
|
|
71
|
+
"/api/auth": [
|
|
72
|
+
"GET",
|
|
73
|
+
"POST"
|
|
74
|
+
],
|
|
75
|
+
"/api/health": [
|
|
76
|
+
"GET"
|
|
77
|
+
],
|
|
78
|
+
"/api/users/forgot-password": [
|
|
79
|
+
"POST"
|
|
80
|
+
],
|
|
81
|
+
"/api/users/set-password": [
|
|
82
|
+
"POST"
|
|
83
|
+
],
|
|
84
|
+
"/api/users/invite": [
|
|
85
|
+
"GET",
|
|
86
|
+
"POST"
|
|
87
|
+
],
|
|
88
|
+
/** Public keys only (e.g. googleEnabled); secrets stay private in the settings handler. */
|
|
89
|
+
"/api/settings/auth_providers": [
|
|
90
|
+
"GET"
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
function legacyGetSessionToken(request) {
|
|
94
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
95
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
96
|
+
return secure ?? regular;
|
|
97
|
+
}
|
|
98
|
+
__name(legacyGetSessionToken, "legacyGetSessionToken");
|
|
99
|
+
function sessionCookiePresence(request) {
|
|
100
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
101
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
102
|
+
const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
|
|
103
|
+
return {
|
|
104
|
+
hasSecureToken: Boolean(secure),
|
|
105
|
+
hasRegularToken: Boolean(regular),
|
|
106
|
+
hasChunkedToken: hasChunked,
|
|
107
|
+
resolved: Boolean(secure ?? regular ?? hasChunked)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
__name(sessionCookiePresence, "sessionCookiePresence");
|
|
111
|
+
function isPublicMethod(pathname, method, publicApiMethods) {
|
|
112
|
+
for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
|
|
113
|
+
if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
__name(isPublicMethod, "isPublicMethod");
|
|
118
|
+
async function hasValidSession(request, secret, legacyGetToken) {
|
|
119
|
+
const presence = sessionCookiePresence(request);
|
|
120
|
+
if (presence.resolved || presence.hasChunkedToken) return true;
|
|
121
|
+
if (request.req) {
|
|
122
|
+
try {
|
|
123
|
+
const { getToken } = await import('next-auth/jwt');
|
|
124
|
+
const token = await getToken({
|
|
125
|
+
req: request.req,
|
|
126
|
+
secret
|
|
127
|
+
});
|
|
128
|
+
if (token != null) return true;
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return Boolean(legacyGetToken(request));
|
|
133
|
+
}
|
|
134
|
+
__name(hasValidSession, "hasValidSession");
|
|
135
|
+
function createCmsMiddleware(config = {}) {
|
|
136
|
+
const { publicAdminPaths = [
|
|
137
|
+
"/admin/signin",
|
|
138
|
+
"/admin/forgot-password",
|
|
139
|
+
"/admin/reset-password",
|
|
140
|
+
"/admin/invite"
|
|
141
|
+
], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
|
|
142
|
+
return /* @__PURE__ */ __name(async function cmsMiddleware(request) {
|
|
143
|
+
const pathname = request.nextUrl.pathname;
|
|
144
|
+
const method = request.method;
|
|
145
|
+
if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
|
|
146
|
+
return {
|
|
147
|
+
type: "next"
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (pathname.startsWith("/admin")) {
|
|
151
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
152
|
+
const cookies = sessionCookiePresence(request);
|
|
153
|
+
if (!authenticated) {
|
|
154
|
+
logAuth("middleware: admin redirect to signin (no session)", {
|
|
155
|
+
pathname,
|
|
156
|
+
method,
|
|
157
|
+
usesGetToken: Boolean(request.req),
|
|
158
|
+
...cookies,
|
|
159
|
+
expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
type: "redirect",
|
|
163
|
+
url: new URL(signInPath, request.url).toString()
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
logAuth("middleware: admin allowed", {
|
|
167
|
+
pathname,
|
|
168
|
+
method,
|
|
169
|
+
usesGetToken: Boolean(request.req),
|
|
170
|
+
...cookies
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (pathname.startsWith("/api")) {
|
|
174
|
+
if (isPublicMethod(pathname, method, publicApiMethods)) {
|
|
175
|
+
return {
|
|
176
|
+
type: "next"
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
180
|
+
if (!authenticated) {
|
|
181
|
+
logAuth("middleware: api 401 (no session)", {
|
|
182
|
+
pathname,
|
|
183
|
+
method,
|
|
184
|
+
usesGetToken: Boolean(request.req),
|
|
185
|
+
...sessionCookiePresence(request)
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
type: "json",
|
|
189
|
+
status: 401,
|
|
190
|
+
body: {
|
|
191
|
+
error: "Unauthorized"
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
type: "next"
|
|
198
|
+
};
|
|
199
|
+
}, "cmsMiddleware");
|
|
200
|
+
}
|
|
201
|
+
__name(createCmsMiddleware, "createCmsMiddleware");
|
|
202
|
+
|
|
203
|
+
export { createCmsMiddleware, defaultPublicApiMethods, isAuthDebugClientEnabled, isAuthDebugEnabled, logAuth, logAuthClient, nextAuthCookieDebugInfo, summarizeSessionUserForLog };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkUQWZUZ5X_cjs = require('./chunk-UQWZUZ5X.cjs');
|
|
4
4
|
require('./chunk-UCKN4BBY.cjs');
|
|
5
5
|
require('./chunk-USNT2KNT.cjs');
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ require('./chunk-USNT2KNT.cjs');
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "emitOrderNotificationTrigger", {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkUQWZUZ5X_cjs.emitOrderNotificationTrigger; }
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "fireOrderNotificationTrigger", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
15
|
+
get: function () { return chunkUQWZUZ5X_cjs.fireOrderNotificationTrigger; }
|
|
16
16
|
});
|