@infuro/cms-core 1.0.36 → 1.0.39
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 +459 -496
- package/dist/admin.js +459 -496
- package/dist/api.cjs +36 -36
- package/dist/api.js +4 -4
- package/dist/auth.cjs +51 -51
- package/dist/auth.js +3 -3
- package/dist/{chunk-COBORIJH.cjs → chunk-22FFHLTO.cjs} +39 -56
- package/dist/{chunk-X6H5VBQ2.cjs → chunk-E6WVP7BK.cjs} +6 -6
- package/dist/{chunk-2AEVFOQP.cjs → chunk-ERJK5QXN.cjs} +418 -139
- package/dist/{chunk-VMY2S32H.js → chunk-NNQBWDCI.js} +39 -56
- package/dist/{chunk-WO2DW4AU.cjs → chunk-OIGCAGH7.cjs} +7 -7
- package/dist/{chunk-UF3BYUXY.js → chunk-P7QCLE5W.js} +4 -3
- package/dist/{chunk-FG6I64HP.js → chunk-SBRBR3VO.js} +1 -1
- package/dist/{chunk-JS2W7XZ4.js → chunk-SFDZMGHD.js} +351 -72
- package/dist/{chunk-LI2IXVAY.js → chunk-UXMDSNIG.js} +1 -1
- package/dist/{chunk-KPKFNLQQ.cjs → chunk-WMXPKKXU.cjs} +4 -3
- package/dist/index.cjs +260 -260
- package/dist/index.d.cts +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +8 -8
- package/dist/migrations/1775500000000-RssFeedsAndArticles.ts +0 -1
- package/dist/migrations/1775700000000-JobSchedules.ts +0 -1
- package/dist/migrations/1781260000000-RenameWhatsappTriggerBindingsToOrderNotificationBindings.ts +92 -0
- package/dist/migrations/1781270000000-ComboVendorId.ts +58 -0
- package/dist/{whatsapp-trigger-dispatcher-ONHXI7UY.cjs → order-notification-dispatcher-RU7BTGGX.cjs} +3 -4
- package/dist/{whatsapp-trigger-dispatcher-PWFI4FKP.js → order-notification-dispatcher-XWIJYDGA.js} +1 -2
- package/dist/{rbac-debug-db-HWP65A4O.cjs → rbac-debug-db-KHG4FJC3.cjs} +2 -2
- package/dist/{rbac-debug-db-QJH3AD34.js → rbac-debug-db-QWHOENBR.js} +1 -1
- package/package.json +147 -147
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { notificationTriggerEmitter } from './chunk-HCIRL37O.js';
|
|
2
2
|
import { queueEmail } from './chunk-5ELSW2UP.js';
|
|
3
3
|
import { applyTemplateVars } from './chunk-CRFV5WJK.js';
|
|
4
|
-
import { resolveEventOrderTemplate, EVENT_ORDER_WHATSAPP_PARAM_KEYS } from './chunk-KFFB6EMZ.js';
|
|
5
4
|
import { __name } from './chunk-SHUYVCID.js';
|
|
6
5
|
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses';
|
|
7
6
|
import nodemailer from 'nodemailer';
|
|
@@ -434,9 +433,9 @@ var WhatsAppService = class {
|
|
|
434
433
|
let body = opts.body?.trim() ?? "";
|
|
435
434
|
const variables = opts.variables ?? {};
|
|
436
435
|
if (opts.templateKey?.trim() && this.getMessageTemplateRow) {
|
|
437
|
-
const { resolveEventOrderTemplate
|
|
436
|
+
const { resolveEventOrderTemplate, EVENT_ORDER_TEMPLATE_KEY } = await import('./event-order-defaults-SDRNAZHC.js');
|
|
438
437
|
if (opts.templateKey.trim() === EVENT_ORDER_TEMPLATE_KEY) {
|
|
439
|
-
const resolved = await
|
|
438
|
+
const resolved = await resolveEventOrderTemplate("whatsapp", async (ch, key) => {
|
|
440
439
|
const row = await this.getMessageTemplateRow(ch, key);
|
|
441
440
|
if (!row) return null;
|
|
442
441
|
return {
|
|
@@ -2034,7 +2033,7 @@ function emailPlugin(config) {
|
|
|
2034
2033
|
}
|
|
2035
2034
|
__name(emailPlugin, "emailPlugin");
|
|
2036
2035
|
|
|
2037
|
-
// src/lib/
|
|
2036
|
+
// src/lib/order-notification-dispatcher.ts
|
|
2038
2037
|
var initialized = false;
|
|
2039
2038
|
function maskPhone3(raw) {
|
|
2040
2039
|
const digits = String(raw ?? "").replace(/\D/g, "");
|
|
@@ -2088,48 +2087,52 @@ async function isTriggerCatalogEnabled(triggerKey, dataSource, entityMap) {
|
|
|
2088
2087
|
}
|
|
2089
2088
|
}
|
|
2090
2089
|
__name(isTriggerCatalogEnabled, "isTriggerCatalogEnabled");
|
|
2091
|
-
async function
|
|
2092
|
-
if (!entityMap.
|
|
2093
|
-
console.warn("[order-notifications]
|
|
2090
|
+
async function loadBoundTemplate(triggerKey, channel, dataSource, entityMap) {
|
|
2091
|
+
if (!entityMap.order_notification_bindings || !entityMap.message_templates) {
|
|
2092
|
+
console.warn("[order-notifications] order_notification_bindings or message_templates missing from entityMap");
|
|
2094
2093
|
return null;
|
|
2095
2094
|
}
|
|
2096
|
-
const binding = await dataSource.getRepository(entityMap.
|
|
2095
|
+
const binding = await dataSource.getRepository(entityMap.order_notification_bindings).findOne({
|
|
2097
2096
|
where: {
|
|
2098
2097
|
triggerKey,
|
|
2098
|
+
channel,
|
|
2099
2099
|
enabled: true
|
|
2100
2100
|
}
|
|
2101
2101
|
});
|
|
2102
2102
|
if (!binding) {
|
|
2103
|
-
console.warn("[order-notifications] no
|
|
2104
|
-
triggerKey
|
|
2103
|
+
console.warn("[order-notifications] no order_notification_bindings row", {
|
|
2104
|
+
triggerKey,
|
|
2105
|
+
channel
|
|
2105
2106
|
});
|
|
2106
2107
|
return null;
|
|
2107
2108
|
}
|
|
2108
2109
|
const templateId = binding.messageTemplateId;
|
|
2109
2110
|
if (templateId == null) {
|
|
2110
2111
|
console.warn("[order-notifications] binding exists but no template selected", {
|
|
2111
|
-
triggerKey
|
|
2112
|
+
triggerKey,
|
|
2113
|
+
channel
|
|
2112
2114
|
});
|
|
2113
2115
|
return null;
|
|
2114
2116
|
}
|
|
2115
2117
|
const template = await dataSource.getRepository(entityMap.message_templates).findOne({
|
|
2116
2118
|
where: {
|
|
2117
2119
|
id: templateId,
|
|
2118
|
-
channel
|
|
2120
|
+
channel,
|
|
2119
2121
|
deleted: false,
|
|
2120
2122
|
enabled: true
|
|
2121
2123
|
}
|
|
2122
2124
|
});
|
|
2123
2125
|
if (!template) {
|
|
2124
|
-
console.warn("[order-notifications] bound
|
|
2126
|
+
console.warn("[order-notifications] bound template not found or disabled", {
|
|
2125
2127
|
triggerKey,
|
|
2128
|
+
channel,
|
|
2126
2129
|
templateId
|
|
2127
2130
|
});
|
|
2128
2131
|
return null;
|
|
2129
2132
|
}
|
|
2130
2133
|
return template;
|
|
2131
2134
|
}
|
|
2132
|
-
__name(
|
|
2135
|
+
__name(loadBoundTemplate, "loadBoundTemplate");
|
|
2133
2136
|
function mergeTriggerVariables(payload, rich) {
|
|
2134
2137
|
const basic = {
|
|
2135
2138
|
orderId: String(payload.orderId ?? ""),
|
|
@@ -2150,43 +2153,16 @@ function mergeTriggerVariables(payload, rich) {
|
|
|
2150
2153
|
};
|
|
2151
2154
|
}
|
|
2152
2155
|
__name(mergeTriggerVariables, "mergeTriggerVariables");
|
|
2153
|
-
async function
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
const getTemplateRow = /* @__PURE__ */ __name(async (channel, templateKey) => {
|
|
2157
|
-
const row = await templateRepo.findOne({
|
|
2158
|
-
where: {
|
|
2159
|
-
channel,
|
|
2160
|
-
templateKey,
|
|
2161
|
-
deleted: false
|
|
2162
|
-
}
|
|
2163
|
-
});
|
|
2164
|
-
if (!row) return null;
|
|
2165
|
-
const r = row;
|
|
2166
|
-
return {
|
|
2167
|
-
subject: r.subject,
|
|
2168
|
-
body: r.body,
|
|
2169
|
-
externalTemplateRef: r.externalTemplateRef,
|
|
2170
|
-
name: r.name,
|
|
2171
|
-
language: r.providerMeta?.language ?? null,
|
|
2172
|
-
paramOrder: r.providerMeta?.paramOrder ?? null,
|
|
2173
|
-
enabled: r.enabled
|
|
2174
|
-
};
|
|
2175
|
-
}, "getTemplateRow");
|
|
2176
|
-
const resolved = await resolveEventOrderTemplate("email", getTemplateRow, null);
|
|
2177
|
-
if (!resolved?.enabled) {
|
|
2178
|
-
console.warn("[order-notifications] email template disabled or missing for order_placed", {
|
|
2179
|
-
orderId
|
|
2180
|
-
});
|
|
2181
|
-
return;
|
|
2182
|
-
}
|
|
2156
|
+
async function sendEmailForTrigger(triggerKey, orderId, variables, contactEmail, dataSource, entityMap, getCms) {
|
|
2157
|
+
const template = await loadBoundTemplate(triggerKey, "email", dataSource, entityMap);
|
|
2158
|
+
if (!template) return;
|
|
2183
2159
|
const [branding, emailSettings] = await Promise.all([
|
|
2184
2160
|
getSettingsGroup(dataSource, entityMap, "branding"),
|
|
2185
2161
|
getSettingsGroup(dataSource, entityMap, "email")
|
|
2186
2162
|
]);
|
|
2187
2163
|
const companyDetails = mergeEmailLayoutCompanyDetails(branding, emailSettings);
|
|
2188
|
-
const subject = applyTemplateVars(
|
|
2189
|
-
const bodyHtml = applyTemplateVars(
|
|
2164
|
+
const subject = applyTemplateVars(template.subject ?? "Order update", variables);
|
|
2165
|
+
const bodyHtml = applyTemplateVars(template.body, variables);
|
|
2190
2166
|
const html = renderLayout({
|
|
2191
2167
|
bodyHtml,
|
|
2192
2168
|
companyDetails
|
|
@@ -2199,15 +2175,21 @@ async function sendOrderPlacedEmail(orderId, dataSource, entityMap, getCms, vari
|
|
|
2199
2175
|
text: bodyHtml.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim()
|
|
2200
2176
|
});
|
|
2201
2177
|
console.log("[order-notifications] email queued", {
|
|
2178
|
+
triggerKey,
|
|
2202
2179
|
orderId,
|
|
2203
2180
|
to: contactEmail
|
|
2204
2181
|
});
|
|
2205
2182
|
}
|
|
2206
|
-
__name(
|
|
2183
|
+
__name(sendEmailForTrigger, "sendEmailForTrigger");
|
|
2207
2184
|
async function sendWhatsAppForTrigger(triggerKey, orderId, phone, variables, dataSource, entityMap, getCms) {
|
|
2208
|
-
const template = await
|
|
2185
|
+
const template = await loadBoundTemplate(triggerKey, "whatsapp", dataSource, entityMap);
|
|
2209
2186
|
if (!template) return;
|
|
2210
|
-
const paramOrder = template.providerMeta?.paramOrder
|
|
2187
|
+
const paramOrder = template.providerMeta?.paramOrder ?? [];
|
|
2188
|
+
if (paramOrder.length === 0) {
|
|
2189
|
+
console.warn("[order-notifications] WhatsApp template has no paramOrder set \u2014 variables may send blank/wrong", {
|
|
2190
|
+
triggerKey
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2211
2193
|
const cms = await getCms();
|
|
2212
2194
|
const metaTemplateName = resolveMetaWhatsAppTemplateName({
|
|
2213
2195
|
externalTemplateRef: template.externalTemplateRef,
|
|
@@ -2264,21 +2246,22 @@ async function handleTrigger(triggerKey, payload, dataSource, entityMap, getCms)
|
|
|
2264
2246
|
const variables = mergeTriggerVariables(payload, context?.variables);
|
|
2265
2247
|
const contactEmail = context?.contact.email?.trim() || "";
|
|
2266
2248
|
const contactPhone = context?.contact.phone?.trim() || payload.customerPhone?.trim() || "";
|
|
2267
|
-
if (
|
|
2268
|
-
await
|
|
2269
|
-
} else
|
|
2249
|
+
if (contactEmail) {
|
|
2250
|
+
await sendEmailForTrigger(triggerKey, payload.orderId, variables, contactEmail, dataSource, entityMap, getCms);
|
|
2251
|
+
} else {
|
|
2270
2252
|
console.warn("[order-notifications] skip email: no customer email", {
|
|
2253
|
+
triggerKey,
|
|
2271
2254
|
orderId: payload.orderId
|
|
2272
2255
|
});
|
|
2273
2256
|
}
|
|
2274
|
-
if (
|
|
2257
|
+
if (contactPhone) {
|
|
2258
|
+
await sendWhatsAppForTrigger(triggerKey, payload.orderId, contactPhone, variables, dataSource, entityMap, getCms);
|
|
2259
|
+
} else {
|
|
2275
2260
|
console.warn("[order-notifications] skip WhatsApp: no customer phone", {
|
|
2276
2261
|
triggerKey,
|
|
2277
2262
|
orderId: payload.orderId
|
|
2278
2263
|
});
|
|
2279
|
-
return;
|
|
2280
2264
|
}
|
|
2281
|
-
await sendWhatsAppForTrigger(triggerKey, payload.orderId, contactPhone, variables, dataSource, entityMap, getCms);
|
|
2282
2265
|
}
|
|
2283
2266
|
__name(handleTrigger, "handleTrigger");
|
|
2284
2267
|
function initWhatsappTriggerDispatcher(deps) {
|
|
@@ -2290,7 +2273,7 @@ function initWhatsappTriggerDispatcher(deps) {
|
|
|
2290
2273
|
console.error("[order-notifications]", triggerKey, err);
|
|
2291
2274
|
});
|
|
2292
2275
|
});
|
|
2293
|
-
console.log("[order-notifications] dispatcher initialized (email + WhatsApp)");
|
|
2276
|
+
console.log("[order-notifications] dispatcher initialized (email + WhatsApp, unified via order_notification_bindings)");
|
|
2294
2277
|
}
|
|
2295
2278
|
__name(initWhatsappTriggerDispatcher, "initWhatsappTriggerDispatcher");
|
|
2296
2279
|
async function resendOrderNotification(triggerKey, orderId, deps) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkWMXPKKXU_cjs = require('./chunk-WMXPKKXU.cjs');
|
|
4
4
|
var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
|
|
5
5
|
|
|
6
6
|
// src/auth/helpers.ts
|
|
@@ -10,7 +10,7 @@ var RBAC_ADMIN_ONLY_ENTITIES = /* @__PURE__ */ new Set([
|
|
|
10
10
|
"permissions"
|
|
11
11
|
]);
|
|
12
12
|
function sessionHasEntityAccess(user, entity, action) {
|
|
13
|
-
return
|
|
13
|
+
return chunkWMXPKKXU_cjs.explainSessionEntityAccess(user, entity, action).allowed;
|
|
14
14
|
}
|
|
15
15
|
chunkUSNT2KNT_cjs.__name(sessionHasEntityAccess, "sessionHasEntityAccess");
|
|
16
16
|
function canManageRoles(user) {
|
|
@@ -101,8 +101,8 @@ function createAuthHelpersFromGetSession(getSession, NextResponse) {
|
|
|
101
101
|
}
|
|
102
102
|
const u = session.user;
|
|
103
103
|
const allowed = sessionHasEntityAccess(u, entity, action);
|
|
104
|
-
const { reason } =
|
|
105
|
-
|
|
104
|
+
const { reason } = chunkWMXPKKXU_cjs.explainSessionEntityAccess(u, entity, action);
|
|
105
|
+
chunkWMXPKKXU_cjs.logRbac("authHelpers.requireEntityPermission", {
|
|
106
106
|
entity,
|
|
107
107
|
action,
|
|
108
108
|
allowed,
|
|
@@ -134,10 +134,10 @@ function createAuthHelpersFromGetSession(getSession, NextResponse) {
|
|
|
134
134
|
}
|
|
135
135
|
const u = session.user;
|
|
136
136
|
if (u.isRBACAdmin) return null;
|
|
137
|
-
if (
|
|
137
|
+
if (chunkWMXPKKXU_cjs.isVendorPortalUser(u)) return null;
|
|
138
138
|
if (u.adminAccess === true) return null;
|
|
139
139
|
if (u.adminAccess === false) {
|
|
140
|
-
|
|
140
|
+
chunkWMXPKKXU_cjs.logRbac("requireAdminAccess denied (adminAccess:false)", {
|
|
141
141
|
email: u.email,
|
|
142
142
|
groupName: u.groupName,
|
|
143
143
|
isVendorPortal: u.isVendorPortal
|
|
@@ -149,7 +149,7 @@ function createAuthHelpersFromGetSession(getSession, NextResponse) {
|
|
|
149
149
|
status: 403
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
|
-
|
|
152
|
+
chunkWMXPKKXU_cjs.logRbac("requireAdminAccess denied (no matching rule)", {
|
|
153
153
|
email: u.email,
|
|
154
154
|
adminAccess: u.adminAccess,
|
|
155
155
|
groupName: u.groupName,
|
|
@@ -16,7 +16,7 @@ var PERMISSION_ENTITY_INTERNAL_EXCLUDE = /* @__PURE__ */ new Set([
|
|
|
16
16
|
"wishlist_items",
|
|
17
17
|
"message_templates",
|
|
18
18
|
"order_notification_triggers",
|
|
19
|
-
"
|
|
19
|
+
"order_notification_bindings",
|
|
20
20
|
"vendor_users",
|
|
21
21
|
"vendor_roles",
|
|
22
22
|
"vendor_role_permissions"
|
|
@@ -127,7 +127,8 @@ var VENDOR_SCOPED_STORE_ENTITIES = /* @__PURE__ */ new Set([
|
|
|
127
127
|
"vendor_customers",
|
|
128
128
|
"discounts",
|
|
129
129
|
"events",
|
|
130
|
-
"refund_policies"
|
|
130
|
+
"refund_policies",
|
|
131
|
+
"combos"
|
|
131
132
|
]);
|
|
132
133
|
var VENDOR_STORE_RBAC_ENTITIES = /* @__PURE__ */ new Set([
|
|
133
134
|
...VENDOR_SCOPED_STORE_ENTITIES,
|
|
@@ -592,7 +593,7 @@ async function logEntityAccessDecision(dataSource, context, user, entity, action
|
|
|
592
593
|
const id = Number(user.id);
|
|
593
594
|
if (Number.isFinite(id)) {
|
|
594
595
|
try {
|
|
595
|
-
const { loadDbPermissionsForUser } = await import('./rbac-debug-db-
|
|
596
|
+
const { loadDbPermissionsForUser } = await import('./rbac-debug-db-QWHOENBR.js');
|
|
596
597
|
dbPermissions = await loadDbPermissionsForUser(dataSource, id);
|
|
597
598
|
} catch (e) {
|
|
598
599
|
dbPermissions = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPermissionableEntityKeys, ADMIN_GROUP_NAME, isSuperAdmin, permissionRowsToRecord, vendorPortalFlagsFromUser } from './chunk-
|
|
1
|
+
import { getPermissionableEntityKeys, ADMIN_GROUP_NAME, isSuperAdmin, permissionRowsToRecord, vendorPortalFlagsFromUser } from './chunk-P7QCLE5W.js';
|
|
2
2
|
import { __name } from './chunk-SHUYVCID.js';
|
|
3
3
|
import { getToken } from 'next-auth/jwt';
|
|
4
4
|
import _CredentialsProvider from 'next-auth/providers/credentials';
|