@infuro/cms-core 1.0.33 → 1.0.35
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/README.md +22 -6
- package/dist/OrderTrackPage-W3J6WIG2.js +426 -0
- package/dist/OrderTrackPage-Z6FCJQYY.cjs +428 -0
- package/dist/admin.cjs +34072 -20487
- package/dist/admin.d.cts +191 -9
- package/dist/admin.d.ts +191 -9
- package/dist/admin.js +33913 -20423
- package/dist/api.cjs +123 -16508
- package/dist/api.d.cts +633 -3
- package/dist/api.d.ts +633 -3
- package/dist/api.js +14 -16519
- package/dist/auth.cjs +196 -955
- package/dist/auth.d.cts +201 -42
- package/dist/auth.d.ts +201 -42
- package/dist/auth.js +4 -888
- package/dist/chunk-2XE4X74C.js +29602 -0
- package/dist/chunk-3DZRIZOD.cjs +52 -0
- package/dist/chunk-3KPNTQBV.cjs +620 -0
- package/dist/chunk-46GKADYE.cjs +84 -0
- package/dist/chunk-4TRPKBKO.js +589 -0
- package/dist/chunk-5ELSW2UP.js +150 -0
- package/dist/chunk-6KPQWRFW.js +171 -0
- package/dist/chunk-7NMT3GBR.cjs +29 -0
- package/dist/chunk-7YIBMQDR.cjs +86 -0
- package/dist/chunk-BGJAV67S.cjs +29710 -0
- package/dist/chunk-CNTSLED2.cjs +559 -0
- package/dist/chunk-CRFV5WJK.js +16 -0
- package/dist/chunk-D5FBNKQM.cjs +104 -0
- package/dist/chunk-EF2JBPDM.js +114 -0
- package/dist/chunk-EQPITOP6.js +543 -0
- package/dist/chunk-GO7PPYNU.js +76 -0
- package/dist/chunk-HF3L2GIT.cjs +194 -0
- package/dist/chunk-J7XHLOLO.js +830 -0
- package/dist/chunk-JBRR5UYL.js +87 -0
- package/dist/chunk-JC6DLWTE.js +21 -0
- package/dist/chunk-JHF4YYRC.cjs +188 -0
- package/dist/chunk-JXF23MPG.js +25 -0
- package/dist/chunk-MQBT33IV.js +48 -0
- package/dist/chunk-N44BJZ4C.cjs +123 -0
- package/dist/chunk-OOTLNH63.cjs +18 -0
- package/dist/chunk-PAMVINEX.cjs +577 -0
- package/dist/chunk-PNOKNSG2.cjs +222 -0
- package/dist/chunk-QM733NUK.js +186 -0
- package/dist/chunk-R73BKDRO.cjs +90 -0
- package/dist/chunk-SHUYVCID.js +4 -0
- package/dist/chunk-SYBOCAWB.js +97 -0
- package/dist/chunk-TDV6EJHV.js +192 -0
- package/dist/chunk-TFUOHI37.cjs +839 -0
- package/dist/chunk-TIAEXJLI.cjs +182 -0
- package/dist/chunk-UPLVMVRX.cjs +23 -0
- package/dist/chunk-USNT2KNT.cjs +6 -0
- package/dist/chunk-WEMDMVHQ.js +216 -0
- package/dist/chunk-XDSNZUW7.js +564 -0
- package/dist/chunk-XQ3QUHWR.cjs +83 -0
- package/dist/chunk-XW5ATPRW.cjs +155 -0
- package/dist/chunk-ZQ4X6OAU.js +82 -0
- package/dist/chunk-ZSVCP6N3.js +83 -0
- package/dist/cli.cjs +142 -84
- package/dist/cli.js +101 -27
- package/dist/email-FKR4FXFI.js +5 -0
- package/dist/email-KVKVPNCL.cjs +58 -0
- package/dist/email-queue-CGZBVVAS.js +2 -0
- package/dist/email-queue-TPZWLTIV.cjs +23 -0
- package/dist/erp-config-enabled-CUMQ6N2V.cjs +11 -0
- package/dist/erp-config-enabled-T37X7T34.js +2 -0
- package/dist/erp-order-invoice-3YISSOWW.js +3 -0
- package/dist/erp-order-invoice-ZR5F2KTA.cjs +12 -0
- package/dist/event-order-defaults-6E543227.js +2 -0
- package/dist/event-order-defaults-DUGDVGJI.cjs +39 -0
- package/dist/event-order-notifications-5GSAOYVS.cjs +27 -0
- package/dist/event-order-notifications-IIIF23D5.js +10 -0
- package/dist/hooks.cjs +259 -132
- package/dist/hooks.d.cts +42 -1
- package/dist/hooks.d.ts +42 -1
- package/dist/hooks.js +234 -91
- package/dist/index.cjs +3884 -21070
- package/dist/index.d.cts +2255 -749
- package/dist/index.d.ts +2255 -749
- package/dist/index.js +1925 -19891
- package/dist/interpolate-WAKPN56R.cjs +11 -0
- package/dist/interpolate-WDUWDF3I.js +2 -0
- package/dist/layout-36UFTHC5.cjs +11 -0
- package/dist/layout-AOBN26XG.js +2 -0
- package/dist/migrations/1778660000004-CreateCustomerAndCustomerContacts.ts +99 -0
- package/dist/migrations/1778660000005-AddCustomerIdToVendorCustomers.ts +39 -0
- package/dist/migrations/1778660000006-UpdateVendorCustomersContactNullable.ts +36 -0
- package/dist/migrations/1778660000007-VendorOwnerCustomerContactsPermission.ts +39 -0
- package/dist/migrations/1779300000000-VendorOwnerContactsPermission.ts +39 -0
- package/dist/migrations/1779400000000-AddCustomerContactIdToOrders.ts +33 -0
- package/dist/migrations/1779400000000-ConvertStatusToEnum.ts +142 -0
- package/dist/migrations/1779400000000-SeedDefaultCurrencies.ts +33 -0
- package/dist/migrations/1779500000000-VendorRolesAndPermissions.ts +102 -0
- package/dist/migrations/1779600000000-VendorRegistrationProfile.ts +52 -0
- package/dist/migrations/1779700000000-CollectionIsCatalog.ts +22 -0
- package/dist/migrations/1779710000000-CollectionPlatformCatalog.ts +60 -0
- package/dist/migrations/1779720000000-ProductCategoryPlatformCatalog.ts +157 -0
- package/dist/migrations/1779800000000-EventsAndEventProducts.ts +173 -0
- package/dist/migrations/1779810000000-BackfillVendorRoleEventsPermissions.ts +38 -0
- package/dist/migrations/1779820000000-FixProductsCategoryForeignKey.ts +70 -0
- package/dist/migrations/1779830000000-ProductTitleColumn.ts +32 -0
- package/dist/migrations/1779840000000-EventAboutAndVisibilityFields.ts +34 -0
- package/dist/migrations/1779850000000-EventCityCountrySplit.ts +43 -0
- package/dist/migrations/1779860000000-CreateCombos.ts +140 -0
- package/dist/migrations/1780100000000-OrderAttendeesEventId.ts +55 -0
- package/dist/migrations/1780110000000-EventContactFormId.ts +49 -0
- package/dist/migrations/1780130000000-ProductVariants.ts +54 -0
- package/dist/migrations/1780140000000-EventManagementEnhancements.ts +44 -0
- package/dist/migrations/1780160000000-EventRegistrationGstProductContactForm.ts +79 -0
- package/dist/migrations/1780170000000-ComboCurrencyPrices.ts +20 -0
- package/dist/migrations/1781110000000-VendorOwnerCombosPermission.ts +38 -0
- package/dist/migrations/1781120000000-RefundPoliciesAndRequests.ts +225 -0
- package/dist/migrations/1781130000000-CreateAttendees.ts +44 -0
- package/dist/migrations/1781140000000-EventOrderNotifications.ts +29 -0
- package/dist/migrations/1781150000000-EventNamedLists.ts +28 -0
- package/dist/migrations/1781160000000-RefundPolicyEventTiers.ts +27 -0
- package/dist/migrations/1781170000000-EventRefundPolicy.ts +42 -0
- package/dist/migrations/1781180000000-RemoveCartItemsUniqueConstraint.ts +15 -0
- package/dist/migrations/1781190000000-RenameProductTaxesToProductConfig.ts +84 -0
- package/dist/migrations/1781200000000-VendorOwnerProductConfigPermissions.ts +51 -0
- package/dist/migrations/1781210000000-VendorRoleProductConfigPermissions.ts +46 -0
- package/dist/migrations/helpers/vendor-role-seed.ts +243 -0
- package/dist/paid-order-erp-3USEG6WL.js +3 -0
- package/dist/paid-order-erp-FSQ3GSXE.cjs +12 -0
- package/dist/pg-boss-service-4XF2TQ2E.js +2 -0
- package/dist/pg-boss-service-L6MTF4EQ.cjs +15 -0
- package/dist/razorpay-KLO2KNCB.js +49 -0
- package/dist/razorpay-U23LGY72.cjs +56 -0
- package/dist/rbac-debug-db-D7ME7QUY.cjs +35 -0
- package/dist/rbac-debug-db-MTCTVNNM.js +33 -0
- package/dist/sms-defaults-2NL24H57.js +2 -0
- package/dist/sms-defaults-KCOPKQBA.cjs +19 -0
- package/dist/stripe-4FD27QVJ.js +51 -0
- package/dist/stripe-VU6OEG2D.cjs +57 -0
- package/dist/theme.cjs +31 -59
- package/dist/theme.d.cts +78 -3
- package/dist/theme.d.ts +78 -3
- package/dist/theme.js +23 -20
- package/dist/vendor-invite-status-77O7ZQ3U.cjs +19 -0
- package/dist/vendor-invite-status-PWJ3DE76.js +2 -0
- package/dist/whatsapp-queue-3DXA4MXU.js +2 -0
- package/dist/whatsapp-queue-KG65MXD5.cjs +15 -0
- package/package.json +147 -141
- package/dist/admin.cjs.map +0 -1
- package/dist/admin.js.map +0 -1
- package/dist/api.cjs.map +0 -1
- package/dist/api.js.map +0 -1
- package/dist/auth.cjs.map +0 -1
- package/dist/auth.js.map +0 -1
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/config-DJ5CmQvS.d.cts +0 -8
- package/dist/config-DJ5CmQvS.d.ts +0 -8
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.js.map +0 -1
- package/dist/index-DWd5Gjc4.d.ts +0 -582
- package/dist/index-rZTnpK7y.d.cts +0 -582
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/theme.cjs.map +0 -1
- package/dist/theme.js.map +0 -1
- package/dist/types-DCVaXlPV.d.cts +0 -78
- package/dist/types-DCVaXlPV.d.ts +0 -78
- package/dist/vendor-scope-DTYhJk_I.d.cts +0 -129
- package/dist/vendor-scope-DTYhJk_I.d.ts +0 -129
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
+
|
|
3
|
+
// src/message-templates/event-order-defaults.ts
|
|
4
|
+
var EVENT_ORDER_TEMPLATE_KEY = "eventOrderPlaced";
|
|
5
|
+
var EVENT_ORDER_TEMPLATE_VARIABLES = [
|
|
6
|
+
"eventName",
|
|
7
|
+
"eventSlug",
|
|
8
|
+
"venue",
|
|
9
|
+
"startDate",
|
|
10
|
+
"orderNumber",
|
|
11
|
+
"orderTotal",
|
|
12
|
+
"currency",
|
|
13
|
+
"customerName",
|
|
14
|
+
"customerEmail",
|
|
15
|
+
"customerPhone",
|
|
16
|
+
"productNames",
|
|
17
|
+
"trackUrl",
|
|
18
|
+
"qrImageUrl",
|
|
19
|
+
"orderDetails",
|
|
20
|
+
"orderDetailsHtml"
|
|
21
|
+
];
|
|
22
|
+
var EVENT_ORDER_WHATSAPP_PARAM_KEYS = [
|
|
23
|
+
"customerName",
|
|
24
|
+
"eventName",
|
|
25
|
+
"orderNumber",
|
|
26
|
+
"orderTotal",
|
|
27
|
+
"currency",
|
|
28
|
+
"venue",
|
|
29
|
+
"startDate",
|
|
30
|
+
"trackUrl"
|
|
31
|
+
];
|
|
32
|
+
var EVENT_ORDER_TEMPLATE_VARIABLE_HINTS = {
|
|
33
|
+
eventName: "Event title",
|
|
34
|
+
eventSlug: "Event URL slug",
|
|
35
|
+
venue: "Venue name",
|
|
36
|
+
startDate: "Formatted event start",
|
|
37
|
+
orderNumber: "Order number",
|
|
38
|
+
orderTotal: "Order total amount",
|
|
39
|
+
currency: "Currency code",
|
|
40
|
+
customerName: "Buyer name",
|
|
41
|
+
customerEmail: "Buyer email",
|
|
42
|
+
customerPhone: "Buyer phone",
|
|
43
|
+
productNames: "Comma-separated ticket names",
|
|
44
|
+
trackUrl: "Public order tracking link (QR destination)",
|
|
45
|
+
qrImageUrl: 'QR code image URL for email (use in <img src="\u2026">)',
|
|
46
|
+
orderDetails: "Plain-text order summary with line items",
|
|
47
|
+
orderDetailsHtml: "HTML order summary block",
|
|
48
|
+
trackUrlWhatsApp: "Same as trackUrl \u2014 include in Meta template as last param"
|
|
49
|
+
};
|
|
50
|
+
var EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS = [
|
|
51
|
+
{
|
|
52
|
+
channel: "email",
|
|
53
|
+
templateKey: EVENT_ORDER_TEMPLATE_KEY,
|
|
54
|
+
name: "Event order placed (email)",
|
|
55
|
+
subject: "Your tickets \u2014 {{eventName}} ({{orderNumber}})",
|
|
56
|
+
body: `<p>Hi {{customerName}},</p>
|
|
57
|
+
<p>Thank you for registering for <strong>{{eventName}}</strong>.</p>
|
|
58
|
+
{{orderDetailsHtml}}
|
|
59
|
+
<p><strong>Venue:</strong> {{venue}}<br/>
|
|
60
|
+
<strong>Date:</strong> {{startDate}}</p>
|
|
61
|
+
<p>Show this QR code at the venue or scan to open your order:</p>
|
|
62
|
+
<p style="text-align:center;margin:20px 0">
|
|
63
|
+
<img src="{{qrImageUrl}}" alt="Order QR" width="180" height="180" style="border:1px solid #e5e7eb;border-radius:8px" />
|
|
64
|
+
</p>
|
|
65
|
+
<p style="text-align:center"><a href="{{trackUrl}}">View order online</a></p>
|
|
66
|
+
<p>We look forward to seeing you there.</p>`
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
channel: "whatsapp",
|
|
70
|
+
templateKey: EVENT_ORDER_TEMPLATE_KEY,
|
|
71
|
+
name: "Event order placed (WhatsApp)",
|
|
72
|
+
body: "Hi {{customerName}}, your registration for {{eventName}} is confirmed. Order {{orderNumber}} \u2014 {{orderTotal}} {{currency}}. Venue: {{venue}}. Date: {{startDate}}. Track: {{trackUrl}}",
|
|
73
|
+
externalTemplateRef: "event_order_placed"
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
function getEventOrderTemplateDefault(channel) {
|
|
77
|
+
return EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS.find((d) => d.channel === channel);
|
|
78
|
+
}
|
|
79
|
+
__name(getEventOrderTemplateDefault, "getEventOrderTemplateDefault");
|
|
80
|
+
async function resolveEventOrderTemplate(channel, getRow, eventOverride) {
|
|
81
|
+
const def = getEventOrderTemplateDefault(channel);
|
|
82
|
+
if (!def) return null;
|
|
83
|
+
const row = await getRow(channel, EVENT_ORDER_TEMPLATE_KEY);
|
|
84
|
+
let subject = def.subject;
|
|
85
|
+
let body = def.body;
|
|
86
|
+
let externalTemplateRef = def.externalTemplateRef;
|
|
87
|
+
let enabled = true;
|
|
88
|
+
if (row) {
|
|
89
|
+
enabled = row.enabled !== false;
|
|
90
|
+
if (row.subject?.trim()) subject = row.subject.trim();
|
|
91
|
+
if (row.body.trim()) body = row.body;
|
|
92
|
+
if (row.externalTemplateRef?.trim()) externalTemplateRef = row.externalTemplateRef.trim();
|
|
93
|
+
}
|
|
94
|
+
if (eventOverride) {
|
|
95
|
+
if (eventOverride.subject?.trim()) subject = eventOverride.subject.trim();
|
|
96
|
+
if (eventOverride.body?.trim()) body = eventOverride.body;
|
|
97
|
+
if (eventOverride.externalTemplateRef?.trim()) {
|
|
98
|
+
externalTemplateRef = eventOverride.externalTemplateRef.trim();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
subject,
|
|
103
|
+
body,
|
|
104
|
+
externalTemplateRef: externalTemplateRef?.trim() || void 0,
|
|
105
|
+
enabled
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
__name(resolveEventOrderTemplate, "resolveEventOrderTemplate");
|
|
109
|
+
function pickWhatsAppTemplateParams(variables) {
|
|
110
|
+
return EVENT_ORDER_WHATSAPP_PARAM_KEYS.map((key) => String(variables[key] ?? "").slice(0, 1024));
|
|
111
|
+
}
|
|
112
|
+
__name(pickWhatsAppTemplateParams, "pickWhatsAppTemplateParams");
|
|
113
|
+
|
|
114
|
+
export { EVENT_ORDER_MESSAGE_TEMPLATE_DEFAULTS, EVENT_ORDER_TEMPLATE_KEY, EVENT_ORDER_TEMPLATE_VARIABLES, EVENT_ORDER_TEMPLATE_VARIABLE_HINTS, EVENT_ORDER_WHATSAPP_PARAM_KEYS, getEventOrderTemplateDefault, pickWhatsAppTemplateParams, resolveEventOrderTemplate };
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { getPermissionableEntityKeys, ADMIN_GROUP_NAME, isSuperAdmin, permissionRowsToRecord, vendorPortalFlagsFromUser } from './chunk-4TRPKBKO.js';
|
|
2
|
+
import { __name } from './chunk-SHUYVCID.js';
|
|
3
|
+
import { getToken } from 'next-auth/jwt';
|
|
4
|
+
import _CredentialsProvider from 'next-auth/providers/credentials';
|
|
5
|
+
|
|
6
|
+
// src/auth/seed-permissions.ts
|
|
7
|
+
async function seedAdministratorPermissions(dataSource, entityMap) {
|
|
8
|
+
const entities = getPermissionableEntityKeys(entityMap);
|
|
9
|
+
const groupRepo = dataSource.getRepository(entityMap.user_groups);
|
|
10
|
+
const permRepo = dataSource.getRepository(entityMap.permissions);
|
|
11
|
+
const adminGroup = await groupRepo.findOne({
|
|
12
|
+
where: {
|
|
13
|
+
name: ADMIN_GROUP_NAME,
|
|
14
|
+
deleted: false
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
console.log("ADMIN GROUP", adminGroup);
|
|
18
|
+
if (!adminGroup) return;
|
|
19
|
+
const fullCrud = {
|
|
20
|
+
canCreate: true,
|
|
21
|
+
canRead: true,
|
|
22
|
+
canUpdate: true,
|
|
23
|
+
canDelete: true
|
|
24
|
+
};
|
|
25
|
+
for (const entity of entities) {
|
|
26
|
+
const existing = await permRepo.findOne({
|
|
27
|
+
where: {
|
|
28
|
+
groupId: adminGroup.id,
|
|
29
|
+
entity
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
console.log("EXISTING", existing);
|
|
33
|
+
if (existing) {
|
|
34
|
+
existing.canCreate = true;
|
|
35
|
+
existing.canRead = true;
|
|
36
|
+
existing.canUpdate = true;
|
|
37
|
+
existing.canDelete = true;
|
|
38
|
+
await permRepo.save(existing);
|
|
39
|
+
} else {
|
|
40
|
+
await permRepo.save(permRepo.create({
|
|
41
|
+
groupId: adminGroup.id,
|
|
42
|
+
entity,
|
|
43
|
+
...fullCrud
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
__name(seedAdministratorPermissions, "seedAdministratorPermissions");
|
|
49
|
+
|
|
50
|
+
// src/auth/auth-debug.ts
|
|
51
|
+
var LOG_PREFIX = "[cms-auth]";
|
|
52
|
+
function isAuthDebugEnabled() {
|
|
53
|
+
const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
54
|
+
if (v === "1" || v === "true" || v === "yes") return true;
|
|
55
|
+
if (v === "0" || v === "false" || v === "no") return false;
|
|
56
|
+
return process.env.NODE_ENV === "development";
|
|
57
|
+
}
|
|
58
|
+
__name(isAuthDebugEnabled, "isAuthDebugEnabled");
|
|
59
|
+
function isAuthDebugClientEnabled() {
|
|
60
|
+
if (typeof window === "undefined") return false;
|
|
61
|
+
const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
|
|
62
|
+
if (v === "1" || v === "true" || v === "yes") return true;
|
|
63
|
+
if (v === "0" || v === "false" || v === "no") return false;
|
|
64
|
+
return process.env.NODE_ENV === "development";
|
|
65
|
+
}
|
|
66
|
+
__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
|
|
67
|
+
function logAuth(message, data) {
|
|
68
|
+
if (!isAuthDebugEnabled()) return;
|
|
69
|
+
if (data) console.info(LOG_PREFIX, message, data);
|
|
70
|
+
else console.info(LOG_PREFIX, message);
|
|
71
|
+
}
|
|
72
|
+
__name(logAuth, "logAuth");
|
|
73
|
+
function logAuthClient(message, data) {
|
|
74
|
+
if (!isAuthDebugClientEnabled()) return;
|
|
75
|
+
if (data) console.info(LOG_PREFIX, message, data);
|
|
76
|
+
else console.info(LOG_PREFIX, message);
|
|
77
|
+
}
|
|
78
|
+
__name(logAuthClient, "logAuthClient");
|
|
79
|
+
function summarizeSessionUserForLog(user) {
|
|
80
|
+
if (!user || typeof user !== "object") return {
|
|
81
|
+
present: false
|
|
82
|
+
};
|
|
83
|
+
const u = user;
|
|
84
|
+
return {
|
|
85
|
+
present: true,
|
|
86
|
+
email: u.email ?? null,
|
|
87
|
+
id: u.id ?? null,
|
|
88
|
+
adminAccess: u.adminAccess ?? null,
|
|
89
|
+
isRBACAdmin: u.isRBACAdmin ?? null,
|
|
90
|
+
isVendorPortal: u.isVendorPortal ?? null,
|
|
91
|
+
groupName: u.groupName ?? null
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
|
|
95
|
+
function nextAuthCookieDebugInfo() {
|
|
96
|
+
const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
|
|
97
|
+
const isHttps = nextAuthUrl.startsWith("https");
|
|
98
|
+
return {
|
|
99
|
+
nextAuthUrl,
|
|
100
|
+
hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
|
|
101
|
+
cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
|
|
102
|
+
cookieSecure: isHttps,
|
|
103
|
+
nodeEnv: process.env.NODE_ENV ?? "(unset)"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
|
|
107
|
+
|
|
108
|
+
// src/auth/middleware.ts
|
|
109
|
+
var defaultPublicApiMethods = {
|
|
110
|
+
"/api/contacts": [
|
|
111
|
+
"POST"
|
|
112
|
+
],
|
|
113
|
+
"/api/form-submissions": [
|
|
114
|
+
"POST"
|
|
115
|
+
],
|
|
116
|
+
"/api/blogs": [
|
|
117
|
+
"GET"
|
|
118
|
+
],
|
|
119
|
+
"/api/forms": [
|
|
120
|
+
"GET"
|
|
121
|
+
],
|
|
122
|
+
"/api/auth": [
|
|
123
|
+
"GET",
|
|
124
|
+
"POST"
|
|
125
|
+
],
|
|
126
|
+
"/api/health": [
|
|
127
|
+
"GET"
|
|
128
|
+
],
|
|
129
|
+
"/api/users/forgot-password": [
|
|
130
|
+
"POST"
|
|
131
|
+
],
|
|
132
|
+
"/api/users/set-password": [
|
|
133
|
+
"POST"
|
|
134
|
+
],
|
|
135
|
+
"/api/users/invite": [
|
|
136
|
+
"POST"
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
function legacyGetSessionToken(request) {
|
|
140
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
141
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
142
|
+
return secure ?? regular;
|
|
143
|
+
}
|
|
144
|
+
__name(legacyGetSessionToken, "legacyGetSessionToken");
|
|
145
|
+
function sessionCookiePresence(request) {
|
|
146
|
+
const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
|
|
147
|
+
const regular = request.cookies.get("next-auth.session-token")?.value;
|
|
148
|
+
const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
|
|
149
|
+
return {
|
|
150
|
+
hasSecureToken: Boolean(secure),
|
|
151
|
+
hasRegularToken: Boolean(regular),
|
|
152
|
+
hasChunkedToken: hasChunked,
|
|
153
|
+
resolved: Boolean(secure ?? regular)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
__name(sessionCookiePresence, "sessionCookiePresence");
|
|
157
|
+
function isPublicMethod(pathname, method, publicApiMethods) {
|
|
158
|
+
for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
|
|
159
|
+
if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
__name(isPublicMethod, "isPublicMethod");
|
|
164
|
+
async function hasValidSession(request, secret, legacyGetToken) {
|
|
165
|
+
if (request.req) {
|
|
166
|
+
const token = await getToken({
|
|
167
|
+
req: request.req,
|
|
168
|
+
secret
|
|
169
|
+
});
|
|
170
|
+
return token != null;
|
|
171
|
+
}
|
|
172
|
+
return Boolean(legacyGetToken(request));
|
|
173
|
+
}
|
|
174
|
+
__name(hasValidSession, "hasValidSession");
|
|
175
|
+
function createCmsMiddleware(config = {}) {
|
|
176
|
+
const { publicAdminPaths = [
|
|
177
|
+
"/admin/signin",
|
|
178
|
+
"/admin/forgot-password",
|
|
179
|
+
"/admin/reset-password",
|
|
180
|
+
"/admin/invite"
|
|
181
|
+
], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
|
|
182
|
+
return /* @__PURE__ */ __name(async function cmsMiddleware(request) {
|
|
183
|
+
const pathname = request.nextUrl.pathname;
|
|
184
|
+
const method = request.method;
|
|
185
|
+
if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
|
|
186
|
+
return {
|
|
187
|
+
type: "next"
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if (pathname.startsWith("/admin")) {
|
|
191
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
192
|
+
const cookies = sessionCookiePresence(request);
|
|
193
|
+
if (!authenticated) {
|
|
194
|
+
logAuth("middleware: admin redirect to signin (no session)", {
|
|
195
|
+
pathname,
|
|
196
|
+
method,
|
|
197
|
+
usesGetToken: Boolean(request.req),
|
|
198
|
+
...cookies,
|
|
199
|
+
expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
type: "redirect",
|
|
203
|
+
url: new URL(signInPath, request.url).toString()
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
logAuth("middleware: admin allowed", {
|
|
207
|
+
pathname,
|
|
208
|
+
method,
|
|
209
|
+
usesGetToken: Boolean(request.req),
|
|
210
|
+
...cookies
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (pathname.startsWith("/api")) {
|
|
214
|
+
if (isPublicMethod(pathname, method, publicApiMethods)) {
|
|
215
|
+
return {
|
|
216
|
+
type: "next"
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
const authenticated = await hasValidSession(request, secret, getSessionToken);
|
|
220
|
+
if (!authenticated) {
|
|
221
|
+
logAuth("middleware: api 401 (no session)", {
|
|
222
|
+
pathname,
|
|
223
|
+
method,
|
|
224
|
+
usesGetToken: Boolean(request.req),
|
|
225
|
+
...sessionCookiePresence(request)
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
type: "json",
|
|
229
|
+
status: 401,
|
|
230
|
+
body: {
|
|
231
|
+
error: "Unauthorized"
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return {
|
|
237
|
+
type: "next"
|
|
238
|
+
};
|
|
239
|
+
}, "cmsMiddleware");
|
|
240
|
+
}
|
|
241
|
+
__name(createCmsMiddleware, "createCmsMiddleware");
|
|
242
|
+
var CredentialsProvider = _CredentialsProvider.default ?? _CredentialsProvider;
|
|
243
|
+
function sessionUserFromNextAuthUser(user) {
|
|
244
|
+
const g = user.group;
|
|
245
|
+
const isRBACAdmin = isSuperAdmin({
|
|
246
|
+
groupId: user.groupId ?? void 0,
|
|
247
|
+
groupName: g?.name,
|
|
248
|
+
isRBACAdmin: false
|
|
249
|
+
});
|
|
250
|
+
const entityPerms = permissionRowsToRecord(g?.permissions);
|
|
251
|
+
const rawAdminAccess = user.adminAccess;
|
|
252
|
+
const adminAccess = rawAdminAccess === true ? true : rawAdminAccess === false ? false : void 0;
|
|
253
|
+
const vendorIds = user.vendorIds ?? [];
|
|
254
|
+
const vendorRole = user.vendorRole ?? null;
|
|
255
|
+
const isVendorRoleOwner = user.isVendorRoleOwner ?? false;
|
|
256
|
+
const { isVendorPortal, isVendorOwner: isVendorOwner2 } = vendorPortalFlagsFromUser({
|
|
257
|
+
email: user.email,
|
|
258
|
+
isRBACAdmin,
|
|
259
|
+
groupName: g?.name,
|
|
260
|
+
vendorIds,
|
|
261
|
+
vendorRole,
|
|
262
|
+
isVendorRoleOwner
|
|
263
|
+
});
|
|
264
|
+
return {
|
|
265
|
+
id: user.id.toString(),
|
|
266
|
+
email: user.email,
|
|
267
|
+
name: user.name,
|
|
268
|
+
groupId: user.groupId ?? void 0,
|
|
269
|
+
groupName: g?.name ?? void 0,
|
|
270
|
+
isRBACAdmin,
|
|
271
|
+
entityPerms,
|
|
272
|
+
adminAccess,
|
|
273
|
+
vendorIds,
|
|
274
|
+
activeVendorId: user.activeVendorId ?? vendorIds[0] ?? null,
|
|
275
|
+
vendorRole,
|
|
276
|
+
vendorRoleId: user.vendorRoleId ?? null,
|
|
277
|
+
vendorRoleName: user.vendorRoleName ?? null,
|
|
278
|
+
isVendorRoleOwner,
|
|
279
|
+
vendorEntityPerms: user.vendorEntityPerms,
|
|
280
|
+
isVendorPortal,
|
|
281
|
+
isVendorOwner: isVendorOwner2
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
__name(sessionUserFromNextAuthUser, "sessionUserFromNextAuthUser");
|
|
285
|
+
function isCustomerGroupUser(user) {
|
|
286
|
+
return user.group?.name?.toLocaleLowerCase().trim() === "customer";
|
|
287
|
+
}
|
|
288
|
+
__name(isCustomerGroupUser, "isCustomerGroupUser");
|
|
289
|
+
function callbackUrlTargetsAdmin(callbackUrl) {
|
|
290
|
+
const raw = callbackUrl.trim();
|
|
291
|
+
if (!raw) return false;
|
|
292
|
+
if (raw.startsWith("/admin")) return true;
|
|
293
|
+
try {
|
|
294
|
+
const path = raw.startsWith("http") ? new URL(raw).pathname : raw.split("?")[0] ?? raw;
|
|
295
|
+
return path.startsWith("/admin");
|
|
296
|
+
} catch {
|
|
297
|
+
return raw.includes("/admin");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
__name(callbackUrlTargetsAdmin, "callbackUrlTargetsAdmin");
|
|
301
|
+
function permitsCustomerLogin(allowCustomerLogin, credentials) {
|
|
302
|
+
if (allowCustomerLogin === true) return true;
|
|
303
|
+
if (allowCustomerLogin === false) return false;
|
|
304
|
+
const callbackUrl = typeof credentials?.callbackUrl === "string" ? credentials.callbackUrl : "";
|
|
305
|
+
return !callbackUrlTargetsAdmin(callbackUrl);
|
|
306
|
+
}
|
|
307
|
+
__name(permitsCustomerLogin, "permitsCustomerLogin");
|
|
308
|
+
function getNextAuthOptions(config) {
|
|
309
|
+
const { getUserByEmail, comparePassword, signInPage = "/admin/signin", secret, extend, enablePasswordLogin = true, enableOtpLogin = false, authorizeOtp, allowCustomerLogin } = config;
|
|
310
|
+
logAuth("getNextAuthOptions init", nextAuthCookieDebugInfo());
|
|
311
|
+
const providers = [];
|
|
312
|
+
if (enablePasswordLogin) {
|
|
313
|
+
providers.push(CredentialsProvider({
|
|
314
|
+
name: "credentials",
|
|
315
|
+
credentials: {
|
|
316
|
+
email: {
|
|
317
|
+
label: "Email",
|
|
318
|
+
type: "email"
|
|
319
|
+
},
|
|
320
|
+
password: {
|
|
321
|
+
label: "Password",
|
|
322
|
+
type: "password"
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
async authorize(credentials) {
|
|
326
|
+
const creds = credentials;
|
|
327
|
+
const email = creds?.email?.trim() ?? "";
|
|
328
|
+
if (!email || !creds?.password) {
|
|
329
|
+
logAuth("authorize(credentials) rejected", {
|
|
330
|
+
reason: "missing_email_or_password"
|
|
331
|
+
});
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
const user = await getUserByEmail(email);
|
|
336
|
+
if (!user) {
|
|
337
|
+
logAuth("authorize(credentials) rejected", {
|
|
338
|
+
reason: "user_not_found",
|
|
339
|
+
email
|
|
340
|
+
});
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
if (user.blocked) {
|
|
344
|
+
logAuth("authorize(credentials) rejected", {
|
|
345
|
+
reason: "blocked",
|
|
346
|
+
email,
|
|
347
|
+
userId: user.id
|
|
348
|
+
});
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
if (user.deleted) {
|
|
352
|
+
logAuth("authorize(credentials) rejected", {
|
|
353
|
+
reason: "deleted",
|
|
354
|
+
email,
|
|
355
|
+
userId: user.id
|
|
356
|
+
});
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
if (!user.password) {
|
|
360
|
+
logAuth("authorize(credentials) rejected", {
|
|
361
|
+
reason: "no_password",
|
|
362
|
+
email,
|
|
363
|
+
userId: user.id
|
|
364
|
+
});
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
const valid = await comparePassword(creds.password, user.password);
|
|
368
|
+
if (!valid) {
|
|
369
|
+
logAuth("authorize(credentials) rejected", {
|
|
370
|
+
reason: "invalid_password",
|
|
371
|
+
email,
|
|
372
|
+
userId: user.id
|
|
373
|
+
});
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
|
|
377
|
+
logAuth("authorize(credentials) rejected", {
|
|
378
|
+
reason: "customer_group",
|
|
379
|
+
email,
|
|
380
|
+
userId: user.id,
|
|
381
|
+
callbackUrl: creds?.callbackUrl ?? null
|
|
382
|
+
});
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
const sessionUser = sessionUserFromNextAuthUser(user);
|
|
386
|
+
logAuth("authorize(credentials) ok", summarizeSessionUserForLog(sessionUser));
|
|
387
|
+
return sessionUser;
|
|
388
|
+
} catch (err) {
|
|
389
|
+
console.error("[cms-auth] authorize error (credentials):", err instanceof Error ? err.message : err);
|
|
390
|
+
logAuth("authorize(credentials) error", {
|
|
391
|
+
email,
|
|
392
|
+
message: err instanceof Error ? err.message : String(err)
|
|
393
|
+
});
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}));
|
|
398
|
+
}
|
|
399
|
+
if (enableOtpLogin && authorizeOtp) {
|
|
400
|
+
providers.push(CredentialsProvider({
|
|
401
|
+
id: "otp",
|
|
402
|
+
name: "otp",
|
|
403
|
+
credentials: {
|
|
404
|
+
identifier: {
|
|
405
|
+
label: "Email or phone",
|
|
406
|
+
type: "text"
|
|
407
|
+
},
|
|
408
|
+
code: {
|
|
409
|
+
label: "Code",
|
|
410
|
+
type: "text"
|
|
411
|
+
},
|
|
412
|
+
channel: {
|
|
413
|
+
label: "Channel",
|
|
414
|
+
type: "text"
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
async authorize(credentials) {
|
|
418
|
+
const creds = credentials;
|
|
419
|
+
const identifier = typeof creds?.identifier === "string" ? creds.identifier.trim() : "";
|
|
420
|
+
const code = typeof creds?.code === "string" ? creds.code.trim() : "";
|
|
421
|
+
const ch = creds?.channel === "sms" ? "sms" : "email";
|
|
422
|
+
if (!identifier || !code) return null;
|
|
423
|
+
try {
|
|
424
|
+
const user = await authorizeOtp({
|
|
425
|
+
identifier,
|
|
426
|
+
channel: ch,
|
|
427
|
+
code
|
|
428
|
+
});
|
|
429
|
+
if (!user || user.blocked || user.deleted) return null;
|
|
430
|
+
if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
|
|
431
|
+
logAuth("authorize(otp) rejected", {
|
|
432
|
+
reason: "customer_group",
|
|
433
|
+
identifier,
|
|
434
|
+
callbackUrl: creds?.callbackUrl ?? null
|
|
435
|
+
});
|
|
436
|
+
return null;
|
|
437
|
+
}
|
|
438
|
+
return sessionUserFromNextAuthUser(user);
|
|
439
|
+
} catch (err) {
|
|
440
|
+
console.error("[cms-auth] authorize error (otp):", err instanceof Error ? err.message : err);
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}));
|
|
445
|
+
}
|
|
446
|
+
const options = {
|
|
447
|
+
secret: secret ?? process.env.NEXTAUTH_SECRET,
|
|
448
|
+
providers,
|
|
449
|
+
session: {
|
|
450
|
+
strategy: "jwt"
|
|
451
|
+
},
|
|
452
|
+
pages: {
|
|
453
|
+
signIn: signInPage
|
|
454
|
+
},
|
|
455
|
+
cookies: {
|
|
456
|
+
sessionToken: {
|
|
457
|
+
name: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token",
|
|
458
|
+
options: {
|
|
459
|
+
httpOnly: true,
|
|
460
|
+
sameSite: "lax",
|
|
461
|
+
path: "/",
|
|
462
|
+
secure: process.env.NEXTAUTH_URL?.startsWith("https") ?? false
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
callbacks: {
|
|
467
|
+
async jwt({ token, user, trigger, session }) {
|
|
468
|
+
if (user) {
|
|
469
|
+
logAuth("jwt callback: new sign-in", {
|
|
470
|
+
trigger,
|
|
471
|
+
user: summarizeSessionUserForLog(user)
|
|
472
|
+
});
|
|
473
|
+
const u = user;
|
|
474
|
+
token.id = u.id;
|
|
475
|
+
token.groupId = u.groupId;
|
|
476
|
+
token.groupName = u.groupName;
|
|
477
|
+
token.isRBACAdmin = u.isRBACAdmin;
|
|
478
|
+
token.entityPerms = u.entityPerms;
|
|
479
|
+
token.adminAccess = u.adminAccess;
|
|
480
|
+
token.vendorIds = u.vendorIds;
|
|
481
|
+
token.activeVendorId = u.activeVendorId;
|
|
482
|
+
token.vendorRole = u.vendorRole;
|
|
483
|
+
token.vendorRoleId = u.vendorRoleId;
|
|
484
|
+
token.vendorRoleName = u.vendorRoleName;
|
|
485
|
+
token.isVendorRoleOwner = u.isVendorRoleOwner;
|
|
486
|
+
token.vendorEntityPerms = u.vendorEntityPerms;
|
|
487
|
+
token.isVendorPortal = u.isVendorPortal;
|
|
488
|
+
token.isVendorOwner = u.isVendorOwner;
|
|
489
|
+
}
|
|
490
|
+
if (trigger === "update" && session && typeof session === "object") {
|
|
491
|
+
logAuth("jwt callback: session update", {
|
|
492
|
+
trigger
|
|
493
|
+
});
|
|
494
|
+
const s = session;
|
|
495
|
+
const t = token;
|
|
496
|
+
if (typeof s.name === "string") t.name = s.name;
|
|
497
|
+
if (typeof s.email === "string") t.email = s.email;
|
|
498
|
+
if (typeof s.activeVendorId === "number") t.activeVendorId = s.activeVendorId;
|
|
499
|
+
}
|
|
500
|
+
return token;
|
|
501
|
+
},
|
|
502
|
+
async session({ session, token }) {
|
|
503
|
+
const t = token;
|
|
504
|
+
logAuth("session callback", {
|
|
505
|
+
tokenHasId: t.id != null,
|
|
506
|
+
tokenEmail: typeof t.email === "string" ? t.email : null,
|
|
507
|
+
sessionUser: summarizeSessionUserForLog(session.user)
|
|
508
|
+
});
|
|
509
|
+
if (session.user) {
|
|
510
|
+
if (typeof t.name === "string") session.user.name = t.name;
|
|
511
|
+
if (typeof t.email === "string") session.user.email = t.email;
|
|
512
|
+
session.user.id = t.id;
|
|
513
|
+
session.user.groupId = t.groupId;
|
|
514
|
+
session.user.groupName = t.groupName;
|
|
515
|
+
session.user.isRBACAdmin = t.isRBACAdmin;
|
|
516
|
+
session.user.entityPerms = t.entityPerms;
|
|
517
|
+
session.user.adminAccess = t.adminAccess;
|
|
518
|
+
session.user.vendorIds = t.vendorIds;
|
|
519
|
+
session.user.activeVendorId = t.activeVendorId;
|
|
520
|
+
session.user.vendorRole = t.vendorRole;
|
|
521
|
+
session.user.vendorRoleId = t.vendorRoleId;
|
|
522
|
+
session.user.vendorRoleName = t.vendorRoleName;
|
|
523
|
+
session.user.isVendorRoleOwner = t.isVendorRoleOwner;
|
|
524
|
+
session.user.vendorEntityPerms = t.vendorEntityPerms;
|
|
525
|
+
session.user.isVendorPortal = t.isVendorPortal;
|
|
526
|
+
session.user.isVendorOwner = t.isVendorOwner;
|
|
527
|
+
}
|
|
528
|
+
return session;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
return extend ? extend(options) : options;
|
|
533
|
+
}
|
|
534
|
+
__name(getNextAuthOptions, "getNextAuthOptions");
|
|
535
|
+
function getStorefrontNextAuthOptions(config) {
|
|
536
|
+
return getNextAuthOptions({
|
|
537
|
+
...config,
|
|
538
|
+
allowCustomerLogin: true
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
__name(getStorefrontNextAuthOptions, "getStorefrontNextAuthOptions");
|
|
542
|
+
|
|
543
|
+
export { createCmsMiddleware, defaultPublicApiMethods, getNextAuthOptions, getStorefrontNextAuthOptions, isAuthDebugClientEnabled, isAuthDebugEnabled, logAuth, logAuthClient, nextAuthCookieDebugInfo, seedAdministratorPermissions, summarizeSessionUserForLog };
|