@infuro/cms-core 1.0.34 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +13 -0
  2. package/dist/OrderTrackPage-W3J6WIG2.js +426 -0
  3. package/dist/OrderTrackPage-Z6FCJQYY.cjs +428 -0
  4. package/dist/admin.cjs +35254 -21613
  5. package/dist/admin.d.cts +192 -9
  6. package/dist/admin.d.ts +192 -9
  7. package/dist/admin.js +34301 -20755
  8. package/dist/api.cjs +137 -17531
  9. package/dist/api.d.cts +633 -3
  10. package/dist/api.d.ts +633 -3
  11. package/dist/api.js +15 -17528
  12. package/dist/auth.cjs +192 -1034
  13. package/dist/auth.d.cts +197 -54
  14. package/dist/auth.d.ts +197 -54
  15. package/dist/auth.js +4 -966
  16. package/dist/chunk-2AEVFOQP.cjs +30436 -0
  17. package/dist/chunk-3DZRIZOD.cjs +52 -0
  18. package/dist/chunk-5ELSW2UP.js +150 -0
  19. package/dist/chunk-7NMT3GBR.cjs +29 -0
  20. package/dist/chunk-COBORIJH.cjs +2373 -0
  21. package/dist/chunk-CRFV5WJK.js +16 -0
  22. package/dist/chunk-D5FBNKQM.cjs +104 -0
  23. package/dist/chunk-FG6I64HP.js +604 -0
  24. package/dist/chunk-GO7PPYNU.js +76 -0
  25. package/dist/chunk-HCIRL37O.js +21 -0
  26. package/dist/chunk-HF3L2GIT.cjs +194 -0
  27. package/dist/chunk-HT5DI3XW.cjs +82 -0
  28. package/dist/chunk-JC6DLWTE.js +21 -0
  29. package/dist/chunk-JS2W7XZ4.js +30312 -0
  30. package/dist/chunk-JXF23MPG.js +25 -0
  31. package/dist/chunk-KFFB6EMZ.js +123 -0
  32. package/dist/chunk-KPKFNLQQ.cjs +648 -0
  33. package/dist/chunk-LI2IXVAY.js +171 -0
  34. package/dist/chunk-MQBT33IV.js +48 -0
  35. package/dist/chunk-OOTLNH63.cjs +18 -0
  36. package/dist/chunk-PNOKNSG2.cjs +222 -0
  37. package/dist/chunk-SHUYVCID.js +4 -0
  38. package/dist/chunk-SPQFNIYJ.cjs +132 -0
  39. package/dist/chunk-SYBOCAWB.js +97 -0
  40. package/dist/chunk-TDV6EJHV.js +192 -0
  41. package/dist/chunk-UCKN4BBY.cjs +24 -0
  42. package/dist/chunk-UF3BYUXY.js +616 -0
  43. package/dist/chunk-UPLVMVRX.cjs +23 -0
  44. package/dist/chunk-USNT2KNT.cjs +6 -0
  45. package/dist/chunk-VMY2S32H.js +2342 -0
  46. package/dist/chunk-WEMDMVHQ.js +216 -0
  47. package/dist/chunk-WO2DW4AU.cjs +182 -0
  48. package/dist/chunk-X47PBV4I.js +79 -0
  49. package/dist/chunk-X6H5VBQ2.cjs +620 -0
  50. package/dist/chunk-XQ3QUHWR.cjs +83 -0
  51. package/dist/chunk-XW5ATPRW.cjs +155 -0
  52. package/dist/cli.cjs +107 -86
  53. package/dist/cli.js +66 -29
  54. package/dist/email-queue-CGZBVVAS.js +2 -0
  55. package/dist/email-queue-TPZWLTIV.cjs +23 -0
  56. package/dist/emit-order-notification-trigger-D2N3KFHL.cjs +16 -0
  57. package/dist/emit-order-notification-trigger-IVLWKKJL.js +3 -0
  58. package/dist/erp-config-enabled-CUMQ6N2V.cjs +11 -0
  59. package/dist/erp-config-enabled-T37X7T34.js +2 -0
  60. package/dist/erp-order-invoice-3YISSOWW.js +3 -0
  61. package/dist/erp-order-invoice-ZR5F2KTA.cjs +12 -0
  62. package/dist/event-order-defaults-EMWBIGL3.cjs +39 -0
  63. package/dist/event-order-defaults-SDRNAZHC.js +2 -0
  64. package/dist/hooks.cjs +259 -132
  65. package/dist/hooks.d.cts +42 -1
  66. package/dist/hooks.d.ts +42 -1
  67. package/dist/hooks.js +234 -91
  68. package/dist/index.cjs +3679 -22356
  69. package/dist/index.d.cts +2173 -643
  70. package/dist/index.d.ts +2173 -643
  71. package/dist/index.js +2587 -22119
  72. package/dist/interpolate-WAKPN56R.cjs +11 -0
  73. package/dist/interpolate-WDUWDF3I.js +2 -0
  74. package/dist/migrations/1779400000000-ConvertStatusToEnum.ts +142 -0
  75. package/dist/migrations/1779400000000-SeedDefaultCurrencies.ts +33 -0
  76. package/dist/migrations/1779500000000-VendorRolesAndPermissions.ts +102 -0
  77. package/dist/migrations/1779600000000-VendorRegistrationProfile.ts +52 -0
  78. package/dist/migrations/1779700000000-CollectionIsCatalog.ts +22 -0
  79. package/dist/migrations/1779710000000-CollectionPlatformCatalog.ts +60 -0
  80. package/dist/migrations/1779720000000-ProductCategoryPlatformCatalog.ts +157 -0
  81. package/dist/migrations/1779800000000-EventsAndEventProducts.ts +173 -0
  82. package/dist/migrations/1779810000000-BackfillVendorRoleEventsPermissions.ts +38 -0
  83. package/dist/migrations/1779820000000-FixProductsCategoryForeignKey.ts +70 -0
  84. package/dist/migrations/1779830000000-ProductTitleColumn.ts +32 -0
  85. package/dist/migrations/1779840000000-EventAboutAndVisibilityFields.ts +34 -0
  86. package/dist/migrations/1779850000000-EventCityCountrySplit.ts +43 -0
  87. package/dist/migrations/1779860000000-CreateCombos.ts +140 -0
  88. package/dist/migrations/1780100000000-OrderAttendeesEventId.ts +55 -0
  89. package/dist/migrations/1780110000000-EventContactFormId.ts +49 -0
  90. package/dist/migrations/1780130000000-ProductVariants.ts +54 -0
  91. package/dist/migrations/1780140000000-EventManagementEnhancements.ts +44 -0
  92. package/dist/migrations/1780160000000-EventRegistrationGstProductContactForm.ts +79 -0
  93. package/dist/migrations/1780170000000-ComboCurrencyPrices.ts +20 -0
  94. package/dist/migrations/1781110000000-VendorOwnerCombosPermission.ts +38 -0
  95. package/dist/migrations/1781120000000-RefundPoliciesAndRequests.ts +225 -0
  96. package/dist/migrations/1781130000000-CreateAttendees.ts +44 -0
  97. package/dist/migrations/1781140000000-EventOrderNotifications.ts +29 -0
  98. package/dist/migrations/1781150000000-EventNamedLists.ts +28 -0
  99. package/dist/migrations/1781160000000-RefundPolicyEventTiers.ts +27 -0
  100. package/dist/migrations/1781170000000-EventRefundPolicy.ts +42 -0
  101. package/dist/migrations/1781180000000-RemoveCartItemsUniqueConstraint.ts +15 -0
  102. package/dist/migrations/1781190000000-RenameProductTaxesToProductConfig.ts +84 -0
  103. package/dist/migrations/1781200000000-VendorOwnerProductConfigPermissions.ts +51 -0
  104. package/dist/migrations/1781210000000-VendorRoleProductConfigPermissions.ts +46 -0
  105. package/dist/migrations/1781220000000-AddWhatsappTriggerBindings.ts +23 -0
  106. package/dist/migrations/1781230000000-AddOrderNotificationTriggers.ts +46 -0
  107. package/dist/migrations/1781240000000-DropEventOrderNotificationColumns.ts +29 -0
  108. package/dist/migrations/1781250000000-RemoveOrderRefundedTrigger.ts +36 -0
  109. package/dist/migrations/helpers/vendor-role-seed.ts +243 -0
  110. package/dist/paid-order-erp-3USEG6WL.js +3 -0
  111. package/dist/paid-order-erp-FSQ3GSXE.cjs +12 -0
  112. package/dist/pg-boss-service-4XF2TQ2E.js +2 -0
  113. package/dist/pg-boss-service-L6MTF4EQ.cjs +15 -0
  114. package/dist/razorpay-KLO2KNCB.js +49 -0
  115. package/dist/razorpay-U23LGY72.cjs +56 -0
  116. package/dist/rbac-debug-db-HWP65A4O.cjs +35 -0
  117. package/dist/rbac-debug-db-QJH3AD34.js +33 -0
  118. package/dist/sms-defaults-2NL24H57.js +2 -0
  119. package/dist/sms-defaults-KCOPKQBA.cjs +19 -0
  120. package/dist/stripe-4FD27QVJ.js +51 -0
  121. package/dist/stripe-VU6OEG2D.cjs +57 -0
  122. package/dist/theme.cjs +31 -59
  123. package/dist/theme.d.cts +78 -3
  124. package/dist/theme.d.ts +78 -3
  125. package/dist/theme.js +23 -20
  126. package/dist/vendor-invite-status-77O7ZQ3U.cjs +19 -0
  127. package/dist/vendor-invite-status-PWJ3DE76.js +2 -0
  128. package/dist/whatsapp-trigger-dispatcher-ONHXI7UY.cjs +19 -0
  129. package/dist/whatsapp-trigger-dispatcher-PWFI4FKP.js +6 -0
  130. package/package.json +147 -142
  131. package/dist/admin.cjs.map +0 -1
  132. package/dist/admin.js.map +0 -1
  133. package/dist/api.cjs.map +0 -1
  134. package/dist/api.js.map +0 -1
  135. package/dist/auth.cjs.map +0 -1
  136. package/dist/auth.js.map +0 -1
  137. package/dist/cli.cjs.map +0 -1
  138. package/dist/cli.js.map +0 -1
  139. package/dist/config-DJ5CmQvS.d.cts +0 -8
  140. package/dist/config-DJ5CmQvS.d.ts +0 -8
  141. package/dist/hooks.cjs.map +0 -1
  142. package/dist/hooks.js.map +0 -1
  143. package/dist/index-Bf5GO8fu.d.cts +0 -583
  144. package/dist/index-DOiJuMQA.d.ts +0 -583
  145. package/dist/index.cjs.map +0 -1
  146. package/dist/index.js.map +0 -1
  147. package/dist/theme.cjs.map +0 -1
  148. package/dist/theme.js.map +0 -1
  149. package/dist/types-DCVaXlPV.d.cts +0 -78
  150. package/dist/types-DCVaXlPV.d.ts +0 -78
  151. package/dist/vendor-scope-DTYhJk_I.d.cts +0 -129
  152. package/dist/vendor-scope-DTYhJk_I.d.ts +0 -129
package/dist/auth.cjs CHANGED
@@ -1,1043 +1,201 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
32
2
 
33
- // src/auth/permission-entities.ts
34
- function isSuperAdminGroupName(name) {
35
- return name === ADMIN_GROUP_NAME;
36
- }
37
- function getPermissionableEntityKeys(entityMap) {
38
- const fromMap = Object.keys(entityMap).filter((k) => !PERMISSION_ENTITY_INTERNAL_EXCLUDE.has(k));
39
- const logical = PERMISSION_LOGICAL_ENTITIES.filter((k) => !fromMap.includes(k));
40
- return [...fromMap.sort(), ...logical].filter((k, i, a) => a.indexOf(k) === i);
41
- }
42
- function permissionRowsToRecord(rows) {
43
- const out = {};
44
- if (!rows?.length) return out;
45
- for (const p of rows) {
46
- out[p.entity] = {
47
- c: !!p.canCreate,
48
- r: !!p.canRead,
49
- u: !!p.canUpdate,
50
- d: !!p.canDelete
51
- };
52
- }
53
- return out;
54
- }
55
- function hasEntityPermission(record, entity, action) {
56
- const p = record?.[entity];
57
- if (!p) return false;
58
- if (action === "create") return p.c;
59
- if (action === "read") return p.r;
60
- if (action === "update") return p.u;
61
- return p.d;
62
- }
63
- var PERMISSION_ENTITY_INTERNAL_EXCLUDE, PERMISSION_LOGICAL_ENTITIES, ADMIN_GROUP_NAME;
64
- var init_permission_entities = __esm({
65
- "src/auth/permission-entities.ts"() {
66
- "use strict";
67
- PERMISSION_ENTITY_INTERNAL_EXCLUDE = /* @__PURE__ */ new Set([
68
- "users",
69
- "password_reset_tokens",
70
- "user_groups",
71
- "permissions",
72
- "comments",
73
- "form_fields",
74
- "configs",
75
- "knowledge_base_chunks",
76
- "carts",
77
- "cart_items",
78
- "wishlists",
79
- "wishlist_items",
80
- "message_templates",
81
- "vendor_users"
82
- ]);
83
- PERMISSION_LOGICAL_ENTITIES = [
84
- "users",
85
- "forms",
86
- "form_submissions",
87
- "dashboard",
88
- "upload",
89
- "settings",
90
- "analytics",
91
- "chat"
92
- ];
93
- ADMIN_GROUP_NAME = "Administrator";
94
- }
95
- });
3
+ var chunkX6H5VBQ2_cjs = require('./chunk-X6H5VBQ2.cjs');
4
+ var chunkWO2DW4AU_cjs = require('./chunk-WO2DW4AU.cjs');
5
+ var chunkKPKFNLQQ_cjs = require('./chunk-KPKFNLQQ.cjs');
6
+ require('./chunk-USNT2KNT.cjs');
96
7
 
97
- // src/auth/role-helpers.ts
98
- function isSuperAdmin(user) {
99
- if (!user) return false;
100
- if (user.groupId === SUPER_ADMIN_GROUP_ID) return true;
101
- if (user.isRBACAdmin === true) return true;
102
- return isSuperAdminGroupName(user.groupName);
103
- }
104
- function isVendorAdmin(user) {
105
- if (!user?.email || isSuperAdmin(user)) return false;
106
- if (user.groupId === VENDOR_ADMIN_GROUP_ID) return true;
107
- if ((user.vendorIds?.length ?? 0) > 0) return true;
108
- return isVendorGroupName(user.groupName);
109
- }
110
- var SUPER_ADMIN_GROUP_ID, VENDOR_ADMIN_GROUP_ID;
111
- var init_role_helpers = __esm({
112
- "src/auth/role-helpers.ts"() {
113
- "use strict";
114
- init_permission_entities();
115
- init_vendor_scope();
116
- SUPER_ADMIN_GROUP_ID = 1;
117
- VENDOR_ADMIN_GROUP_ID = 5;
118
- }
119
- });
120
8
 
121
- // src/auth/vendor-scope.ts
122
- function isVendorGroupName(name) {
123
- if (!name?.trim()) return false;
124
- const n = name.trim().toLowerCase();
125
- return n === VENDOR_OWNER_GROUP_NAME.toLowerCase() || n.includes("vendor");
126
- }
127
- function isPlatformAdministrator(user) {
128
- if (!user?.email) return false;
129
- return isSuperAdmin(user);
130
- }
131
- function isVendorPortalUser(user) {
132
- if (user?.isVendorPortal === true) return true;
133
- if (!user?.email || isPlatformAdministrator(user)) return false;
134
- if (isVendorAdmin(user)) return true;
135
- return isVendorGroupName(user.groupName);
136
- }
137
- function isVendorStaff(user) {
138
- return isVendorPortalUser(user);
139
- }
140
- function isVendorOwner(user) {
141
- if (user?.isVendorOwner === true) return true;
142
- if (!user?.email || isPlatformAdministrator(user)) return false;
143
- if (user.vendorRole === "staff") return false;
144
- if (user.vendorRole === "owner") return true;
145
- if (!isVendorPortalUser(user)) return false;
146
- return user.groupName?.trim().toLowerCase() === VENDOR_OWNER_GROUP_NAME.toLowerCase();
147
- }
148
- function canManageVendorTeam(user) {
149
- return isPlatformAdministrator(user) || isVendorOwner(user);
150
- }
151
- function canManageVendorRoles(user) {
152
- return isPlatformAdministrator(user) || isVendorOwner(user);
153
- }
154
- function canOnboardVendors(user) {
155
- return isPlatformAdministrator(user);
156
- }
157
- function resolveVendorScopeFromSessionUser(user) {
158
- if (!user?.email) return { type: "deny" };
159
- if (isPlatformAdministrator(user)) return { type: "all" };
160
- const vendorIds = user.vendorIds ?? [];
161
- if (vendorIds.length === 0) return { type: "deny" };
162
- const preferred = user.activeVendorId ?? vendorIds[0];
163
- const vendorId = vendorIds.includes(preferred) ? preferred : vendorIds[0];
164
- return { type: "vendor", vendorId, vendorIds };
165
- }
166
- function vendorPortalFlagsFromUser(input) {
167
- const vendorIds = input.vendorIds ?? [];
168
- const isVendorPortal = !input.isRBACAdmin && (vendorIds.length > 0 || isVendorGroupName(input.groupName));
169
- const isVendorOwner2 = isVendorPortal && input.vendorRole !== "staff" && (input.vendorRole === "owner" || input.groupName?.trim().toLowerCase() === VENDOR_OWNER_GROUP_NAME.toLowerCase());
170
- return { isVendorPortal, isVendorOwner: isVendorOwner2 };
171
- }
172
- var VENDOR_SCOPED_STORE_ENTITIES, VENDOR_STORE_RBAC_ENTITIES, VENDOR_OWNER_GROUP_NAME;
173
- var init_vendor_scope = __esm({
174
- "src/auth/vendor-scope.ts"() {
175
- "use strict";
176
- init_role_helpers();
177
- VENDOR_SCOPED_STORE_ENTITIES = /* @__PURE__ */ new Set([
178
- "products",
179
- "collections",
180
- "brands",
181
- "product_categories",
182
- "orders",
183
- "payments",
184
- "taxes",
185
- "attributes",
186
- "vendor_customers",
187
- "discounts"
188
- ]);
189
- VENDOR_STORE_RBAC_ENTITIES = /* @__PURE__ */ new Set([
190
- ...VENDOR_SCOPED_STORE_ENTITIES,
191
- "order_discounts",
192
- "order_addresses"
193
- ]);
194
- VENDOR_OWNER_GROUP_NAME = "Vendor Owner";
195
- }
196
- });
197
9
 
198
- // src/auth/rbac-debug-db.ts
199
- var rbac_debug_db_exports = {};
200
- __export(rbac_debug_db_exports, {
201
- loadDbPermissionsForUser: () => loadDbPermissionsForUser
10
+ Object.defineProperty(exports, "createCmsMiddleware", {
11
+ enumerable: true,
12
+ get: function () { return chunkX6H5VBQ2_cjs.createCmsMiddleware; }
202
13
  });
203
- async function loadDbPermissionsForUser(dataSource, userId) {
204
- const rows = await dataSource.query(
205
- `
206
- SELECT u."groupId" AS "groupId", g.name AS "groupName",
207
- p.entity, p."canCreate", p."canRead", p."canUpdate", p."canDelete"
208
- FROM users u
209
- LEFT JOIN user_groups g ON g.id = u."groupId" AND g.deleted = false
210
- LEFT JOIN permissions p ON p."groupId" = g.id
211
- WHERE u.id = $1
212
- `,
213
- [userId]
214
- );
215
- const groupId = rows[0]?.groupId ?? null;
216
- const groupName = rows[0]?.groupName ?? null;
217
- const permRows = rows.filter((r) => r.entity).map((r) => ({
218
- entity: r.entity,
219
- canCreate: !!r.canCreate,
220
- canRead: !!r.canRead,
221
- canUpdate: !!r.canUpdate,
222
- canDelete: !!r.canDelete
223
- }));
224
- return {
225
- groupId,
226
- groupName,
227
- dbEntityPerms: summarizeEntityPerms(permissionRowsToRecord(permRows))
228
- };
229
- }
230
- var init_rbac_debug_db = __esm({
231
- "src/auth/rbac-debug-db.ts"() {
232
- "use strict";
233
- init_permission_entities();
234
- init_rbac_debug();
235
- }
14
+ Object.defineProperty(exports, "defaultPublicApiMethods", {
15
+ enumerable: true,
16
+ get: function () { return chunkX6H5VBQ2_cjs.defaultPublicApiMethods; }
236
17
  });
237
-
238
- // src/auth/rbac-debug.ts
239
- function isRbacDebugEnabled() {
240
- const v = process.env.CMS_RBAC_DEBUG?.trim().toLowerCase();
241
- if (v === "1" || v === "true" || v === "yes") return true;
242
- if (v === "0" || v === "false" || v === "no") return false;
243
- return process.env.NODE_ENV === "development";
244
- }
245
- function logRbac(message, data) {
246
- if (!isRbacDebugEnabled()) return;
247
- if (data) console.info(LOG_PREFIX, message, data);
248
- else console.info(LOG_PREFIX, message);
249
- }
250
- function summarizeEntityPerms(entityPerms) {
251
- const out = {};
252
- if (!entityPerms) return out;
253
- for (const [entity, p] of Object.entries(entityPerms)) {
254
- out[entity] = { c: p.c, r: p.r, u: p.u, d: p.d };
255
- }
256
- return out;
257
- }
258
- function vendorPortalFallbackReason(user, entity, action) {
259
- if (!isVendorPortalUser(user)) return null;
260
- if (entity === "dashboard" && action === "read") return "vendor_portal_dashboard_fallback";
261
- if (entity === "analytics" && action === "read") return "vendor_portal_analytics_fallback";
262
- if (entity === "settings" && action === "read") return "vendor_portal_settings_read_fallback";
263
- if (VENDOR_STORE_RBAC_ENTITIES.has(entity) && action === "read") return "vendor_portal_store_read_fallback";
264
- return null;
265
- }
266
- function explainSessionEntityAccess(user, entity, action) {
267
- const userSnapshot = {
268
- email: user?.email ?? null,
269
- id: user?.id ?? null,
270
- groupId: user?.groupId ?? null,
271
- groupName: user?.groupName ?? null,
272
- isRBACAdmin: user?.isRBACAdmin ?? false,
273
- adminAccess: user?.adminAccess ?? null,
274
- vendorIds: user?.vendorIds ?? [],
275
- activeVendorId: user?.activeVendorId ?? null,
276
- vendorRole: user?.vendorRole ?? null,
277
- isVendorPortal: user?.isVendorPortal ?? false,
278
- isVendorOwner: user?.isVendorOwner ?? false,
279
- isVendorPortalComputed: isVendorPortalUser(user),
280
- isVendorOwnerComputed: isVendorOwner(user),
281
- jwtEntityPerms: summarizeEntityPerms(user?.entityPerms),
282
- jwtEntityPermForTarget: user?.entityPerms?.[entity] ?? null
283
- };
284
- if (!user?.email) {
285
- return { allowed: false, reason: "no_session_email", userSnapshot };
286
- }
287
- if (user.isRBACAdmin) {
288
- return { allowed: true, reason: "platform_administrator", userSnapshot };
289
- }
290
- const vendorIds = user.vendorIds ?? [];
291
- const isStaff = user.vendorRole === "staff";
292
- if (vendorIds.length > 0) {
293
- if (entity === "dashboard" && action === "read") {
294
- return { allowed: true, reason: "vendor_link_dashboard_read", userSnapshot };
295
- }
296
- if (entity === "analytics" && action === "read") {
297
- return { allowed: true, reason: "vendor_link_analytics_read", userSnapshot };
298
- }
299
- if (entity === "settings") {
300
- if (action === "read") {
301
- return { allowed: true, reason: "vendor_link_settings_read", userSnapshot };
302
- }
303
- if (action === "update" && !isStaff) {
304
- return { allowed: true, reason: "vendor_link_settings_update", userSnapshot };
305
- }
306
- }
307
- if (VENDOR_STORE_RBAC_ENTITIES.has(entity)) {
308
- if (isStaff && action === "read") {
309
- return { allowed: true, reason: "vendor_staff_store_read", userSnapshot };
310
- }
311
- if (!isStaff) {
312
- return { allowed: true, reason: "vendor_link_store_full", userSnapshot };
313
- }
314
- return {
315
- allowed: false,
316
- reason: "vendor_staff_store_write_denied",
317
- userSnapshot
318
- };
319
- }
320
- }
321
- if (isVendorPortalUser(user) && isVendorOwner(user)) {
322
- if (entity === "dashboard" && action === "read") {
323
- return { allowed: true, reason: "vendor_owner_group_dashboard", userSnapshot };
324
- }
325
- if (entity === "analytics" && action === "read") {
326
- return { allowed: true, reason: "vendor_owner_group_analytics", userSnapshot };
327
- }
328
- if (entity === "settings" && (action === "read" || action === "update")) {
329
- return { allowed: true, reason: "vendor_owner_group_settings", userSnapshot };
330
- }
331
- if (VENDOR_STORE_RBAC_ENTITIES.has(entity)) {
332
- return { allowed: true, reason: "vendor_owner_group_store", userSnapshot };
333
- }
334
- }
335
- const vendorPortalReason = vendorPortalFallbackReason(user, entity, action);
336
- if (vendorPortalReason) {
337
- return { allowed: true, reason: vendorPortalReason, userSnapshot };
338
- }
339
- const explicit = user.entityPerms?.[entity];
340
- if (explicit !== void 0) {
341
- const allowed2 = hasEntityPermission(user.entityPerms, entity, action);
342
- return {
343
- allowed: allowed2,
344
- reason: allowed2 ? "jwt_entity_perms_allow" : "jwt_entity_perms_deny",
345
- userSnapshot
346
- };
347
- }
348
- const allowed = hasEntityPermission(user.entityPerms, entity, action);
349
- return {
350
- allowed,
351
- reason: allowed ? "entity_perms_fallback_allow" : "no_matching_rule",
352
- userSnapshot
353
- };
354
- }
355
- async function logEntityAccessDecision(dataSource, context, user, entity, action, extra) {
356
- if (!isRbacDebugEnabled()) return;
357
- const explanation = explainSessionEntityAccess(user, entity, action);
358
- let dbPermissions;
359
- if (dataSource && user?.id) {
360
- const id = Number(user.id);
361
- if (Number.isFinite(id)) {
362
- try {
363
- const { loadDbPermissionsForUser: loadDbPermissionsForUser2 } = await Promise.resolve().then(() => (init_rbac_debug_db(), rbac_debug_db_exports));
364
- dbPermissions = await loadDbPermissionsForUser2(dataSource, id);
365
- } catch (e) {
366
- dbPermissions = { error: e instanceof Error ? e.message : String(e) };
367
- }
368
- }
369
- }
370
- logRbac(context, {
371
- entity,
372
- action,
373
- allowed: explanation.allowed,
374
- reason: explanation.reason,
375
- ...explanation.userSnapshot,
376
- dbPermissions,
377
- ...extra
378
- });
379
- }
380
- var LOG_PREFIX;
381
- var init_rbac_debug = __esm({
382
- "src/auth/rbac-debug.ts"() {
383
- "use strict";
384
- init_permission_entities();
385
- init_vendor_scope();
386
- LOG_PREFIX = "[cms-rbac]";
387
- }
18
+ Object.defineProperty(exports, "getNextAuthOptions", {
19
+ enumerable: true,
20
+ get: function () { return chunkX6H5VBQ2_cjs.getNextAuthOptions; }
388
21
  });
389
-
390
- // src/auth/index.ts
391
- var auth_exports = {};
392
- __export(auth_exports, {
393
- ADMIN_GROUP_NAME: () => ADMIN_GROUP_NAME,
394
- OPEN_ENDPOINTS: () => OPEN_ENDPOINTS,
395
- PERMISSION_REQUIRED_ENDPOINTS: () => PERMISSION_REQUIRED_ENDPOINTS,
396
- RBAC_ADMIN_ONLY_ENTITIES: () => RBAC_ADMIN_ONLY_ENTITIES,
397
- SUPER_ADMIN_GROUP_ID: () => SUPER_ADMIN_GROUP_ID,
398
- VENDOR_ADMIN_GROUP_ID: () => VENDOR_ADMIN_GROUP_ID,
399
- VENDOR_OWNER_GROUP_NAME: () => VENDOR_OWNER_GROUP_NAME,
400
- VENDOR_SCOPED_STORE_ENTITIES: () => VENDOR_SCOPED_STORE_ENTITIES,
401
- VENDOR_STORE_RBAC_ENTITIES: () => VENDOR_STORE_RBAC_ENTITIES,
402
- canManageRoles: () => canManageRoles,
403
- canManageVendorRoles: () => canManageVendorRoles,
404
- canManageVendorTeam: () => canManageVendorTeam,
405
- canOnboardVendors: () => canOnboardVendors,
406
- createAuthHelpers: () => createAuthHelpers,
407
- createCmsAuthBundle: () => createCmsAuthBundle,
408
- createCmsMiddleware: () => createCmsMiddleware,
409
- defaultPublicApiMethods: () => defaultPublicApiMethods,
410
- explainSessionEntityAccess: () => explainSessionEntityAccess,
411
- getNextAuthOptions: () => getNextAuthOptions,
412
- getPermissionableEntityKeys: () => getPermissionableEntityKeys,
413
- getRequiredPermission: () => getRequiredPermission,
414
- getStorefrontNextAuthOptions: () => getStorefrontNextAuthOptions,
415
- hasEntityPermission: () => hasEntityPermission,
416
- isAuthDebugClientEnabled: () => isAuthDebugClientEnabled,
417
- isAuthDebugEnabled: () => isAuthDebugEnabled,
418
- isOpenEndpoint: () => isOpenEndpoint,
419
- isPlatformAdministrator: () => isPlatformAdministrator,
420
- isPublicMethod: () => isPublicMethod,
421
- isRbacDebugEnabled: () => isRbacDebugEnabled,
422
- isSuperAdmin: () => isSuperAdmin,
423
- isSuperAdminGroupName: () => isSuperAdminGroupName,
424
- isVendorAdmin: () => isVendorAdmin,
425
- isVendorGroupName: () => isVendorGroupName,
426
- isVendorOwner: () => isVendorOwner,
427
- isVendorPortalUser: () => isVendorPortalUser,
428
- isVendorStaff: () => isVendorStaff,
429
- logAuth: () => logAuth,
430
- logAuthClient: () => logAuthClient,
431
- logEntityAccessDecision: () => logEntityAccessDecision,
432
- logRbac: () => logRbac,
433
- nextAuthCookieDebugInfo: () => nextAuthCookieDebugInfo,
434
- permissionRowsToRecord: () => permissionRowsToRecord,
435
- resolveVendorScopeFromSessionUser: () => resolveVendorScopeFromSessionUser,
436
- seedAdministratorPermissions: () => seedAdministratorPermissions,
437
- sessionHasEntityAccess: () => sessionHasEntityAccess,
438
- summarizeEntityPerms: () => summarizeEntityPerms,
439
- summarizeSessionUserForLog: () => summarizeSessionUserForLog,
440
- vendorPortalFlagsFromUser: () => vendorPortalFlagsFromUser
22
+ Object.defineProperty(exports, "getStorefrontNextAuthOptions", {
23
+ enumerable: true,
24
+ get: function () { return chunkX6H5VBQ2_cjs.getStorefrontNextAuthOptions; }
441
25
  });
442
- module.exports = __toCommonJS(auth_exports);
443
-
444
- // src/auth/helpers.ts
445
- init_rbac_debug();
446
- init_vendor_scope();
447
- var RBAC_ADMIN_ONLY_ENTITIES = /* @__PURE__ */ new Set(["users", "user_groups", "permissions"]);
448
- function sessionHasEntityAccess(user, entity, action) {
449
- return explainSessionEntityAccess(user, entity, action).allowed;
450
- }
451
- function canManageRoles(user) {
452
- return !!(user?.email && user.isRBACAdmin);
453
- }
454
- var OPEN_ENDPOINTS = [
455
- { "/api/contacts": ["POST"] },
456
- { "/api/form-submissions": ["POST"] },
457
- { "/api/blogs": ["GET"] }
458
- ];
459
- var PERMISSION_REQUIRED_ENDPOINTS = {};
460
- function isOpenEndpoint(pathname) {
461
- return OPEN_ENDPOINTS.some((endpoint) => pathname.startsWith(Object.keys(endpoint)[0]));
462
- }
463
- function getRequiredPermission(pathname) {
464
- return null;
465
- }
466
- function isPublicMethod(pathname, method) {
467
- for (const endpoint of OPEN_ENDPOINTS) {
468
- const key = Object.keys(endpoint)[0];
469
- if (pathname.startsWith(key) && endpoint[key].includes(method)) return true;
470
- }
471
- return false;
472
- }
473
- function createAuthHelpers(getSession, NextResponse) {
474
- return createAuthHelpersFromGetSession(getSession, NextResponse);
475
- }
476
- function createCmsAuthBundle(getSession, NextResponse) {
477
- const auth = createAuthHelpers(getSession, NextResponse);
478
- return {
479
- requireAuth: auth.requireAuth,
480
- requireAdminAccess: auth.requireAdminAccess,
481
- requireEntityPermission: auth.requireEntityPermission,
482
- getSessionUser: auth.getAuthenticatedUser,
483
- getAuthenticatedUser: auth.getAuthenticatedUser
484
- };
485
- }
486
- function createAuthHelpersFromGetSession(getSession, NextResponse) {
487
- return {
488
- async requireAuth() {
489
- const session = await getSession();
490
- if (!session?.user?.email) {
491
- return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
492
- }
493
- return null;
494
- },
495
- async requirePermission() {
496
- const session = await getSession();
497
- if (!session?.user?.email) {
498
- return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
499
- }
500
- return null;
501
- },
502
- async requireEntityPermission(_req, entity, action) {
503
- const session = await getSession();
504
- if (!session?.user?.email) {
505
- return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
506
- }
507
- const u = session.user;
508
- const allowed = sessionHasEntityAccess(u, entity, action);
509
- const { reason } = explainSessionEntityAccess(u, entity, action);
510
- logRbac("authHelpers.requireEntityPermission", {
511
- entity,
512
- action,
513
- allowed,
514
- reason,
515
- email: u.email,
516
- groupName: u.groupName,
517
- vendorIds: u.vendorIds,
518
- isVendorPortal: u.isVendorPortal,
519
- isVendorOwner: u.isVendorOwner
520
- });
521
- if (allowed) return null;
522
- return NextResponse.json({ error: "Forbidden", entity, action, reason }, { status: 403 });
523
- },
524
- async requireAdminAccess() {
525
- const session = await getSession();
526
- if (!session?.user?.email) {
527
- return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
528
- }
529
- const u = session.user;
530
- if (u.isRBACAdmin) return null;
531
- if (isVendorPortalUser(u)) return null;
532
- if (u.adminAccess === true) return null;
533
- if (u.adminAccess === false) {
534
- logRbac("requireAdminAccess denied (adminAccess:false)", {
535
- email: u.email,
536
- groupName: u.groupName,
537
- isVendorPortal: u.isVendorPortal
538
- });
539
- return NextResponse.json({ error: "Forbidden", reason: "admin_access" }, { status: 403 });
540
- }
541
- logRbac("requireAdminAccess denied (no matching rule)", {
542
- email: u.email,
543
- adminAccess: u.adminAccess,
544
- groupName: u.groupName,
545
- isVendorPortal: u.isVendorPortal
546
- });
547
- return NextResponse.json({ error: "Forbidden", reason: "admin_access" }, { status: 403 });
548
- },
549
- async getAuthenticatedUser() {
550
- const session = await getSession();
551
- return session?.user ?? null;
552
- }
553
- };
554
- }
555
-
556
- // src/auth/index.ts
557
- init_rbac_debug();
558
- init_role_helpers();
559
- init_vendor_scope();
560
- init_permission_entities();
561
-
562
- // src/auth/seed-permissions.ts
563
- init_permission_entities();
564
- async function seedAdministratorPermissions(dataSource, entityMap) {
565
- const entities = getPermissionableEntityKeys(entityMap);
566
- const groupRepo = dataSource.getRepository(entityMap.user_groups);
567
- const permRepo = dataSource.getRepository(entityMap.permissions);
568
- const adminGroup = await groupRepo.findOne({ where: { name: ADMIN_GROUP_NAME, deleted: false } });
569
- console.log("ADMIN GROUP", adminGroup);
570
- if (!adminGroup) return;
571
- const fullCrud = { canCreate: true, canRead: true, canUpdate: true, canDelete: true };
572
- for (const entity of entities) {
573
- const existing = await permRepo.findOne({
574
- where: { groupId: adminGroup.id, entity }
575
- });
576
- console.log("EXISTING", existing);
577
- if (existing) {
578
- existing.canCreate = true;
579
- existing.canRead = true;
580
- existing.canUpdate = true;
581
- existing.canDelete = true;
582
- await permRepo.save(existing);
583
- } else {
584
- await permRepo.save(
585
- permRepo.create({
586
- groupId: adminGroup.id,
587
- entity,
588
- ...fullCrud
589
- })
590
- );
591
- }
592
- }
593
- }
594
-
595
- // src/auth/middleware.ts
596
- var import_jwt = require("next-auth/jwt");
597
-
598
- // src/auth/auth-debug.ts
599
- var LOG_PREFIX2 = "[cms-auth]";
600
- function isAuthDebugEnabled() {
601
- const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
602
- if (v === "1" || v === "true" || v === "yes") return true;
603
- if (v === "0" || v === "false" || v === "no") return false;
604
- return process.env.NODE_ENV === "development";
605
- }
606
- function isAuthDebugClientEnabled() {
607
- if (typeof window === "undefined") return false;
608
- const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
609
- if (v === "1" || v === "true" || v === "yes") return true;
610
- if (v === "0" || v === "false" || v === "no") return false;
611
- return process.env.NODE_ENV === "development";
612
- }
613
- function logAuth(message, data) {
614
- if (!isAuthDebugEnabled()) return;
615
- if (data) console.info(LOG_PREFIX2, message, data);
616
- else console.info(LOG_PREFIX2, message);
617
- }
618
- function logAuthClient(message, data) {
619
- if (!isAuthDebugClientEnabled()) return;
620
- if (data) console.info(LOG_PREFIX2, message, data);
621
- else console.info(LOG_PREFIX2, message);
622
- }
623
- function summarizeSessionUserForLog(user) {
624
- if (!user || typeof user !== "object") return { present: false };
625
- const u = user;
626
- return {
627
- present: true,
628
- email: u.email ?? null,
629
- id: u.id ?? null,
630
- adminAccess: u.adminAccess ?? null,
631
- isRBACAdmin: u.isRBACAdmin ?? null,
632
- isVendorPortal: u.isVendorPortal ?? null,
633
- groupName: u.groupName ?? null
634
- };
635
- }
636
- function nextAuthCookieDebugInfo() {
637
- const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
638
- const isHttps = nextAuthUrl.startsWith("https");
639
- return {
640
- nextAuthUrl,
641
- hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
642
- cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
643
- cookieSecure: isHttps,
644
- nodeEnv: process.env.NODE_ENV ?? "(unset)"
645
- };
646
- }
647
-
648
- // src/auth/middleware.ts
649
- var defaultPublicApiMethods = {
650
- "/api/contacts": ["POST"],
651
- "/api/form-submissions": ["POST"],
652
- "/api/blogs": ["GET"],
653
- "/api/forms": ["GET"],
654
- "/api/auth": ["GET", "POST"],
655
- "/api/health": ["GET"],
656
- "/api/users/forgot-password": ["POST"],
657
- "/api/users/set-password": ["POST"],
658
- "/api/users/invite": ["POST"]
659
- };
660
- function legacyGetSessionToken(request) {
661
- const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
662
- const regular = request.cookies.get("next-auth.session-token")?.value;
663
- return secure ?? regular;
664
- }
665
- function sessionCookiePresence(request) {
666
- const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
667
- const regular = request.cookies.get("next-auth.session-token")?.value;
668
- const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
669
- return {
670
- hasSecureToken: Boolean(secure),
671
- hasRegularToken: Boolean(regular),
672
- hasChunkedToken: hasChunked,
673
- resolved: Boolean(secure ?? regular)
674
- };
675
- }
676
- function isPublicMethod2(pathname, method, publicApiMethods) {
677
- for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
678
- if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
679
- }
680
- return false;
681
- }
682
- async function hasValidSession(request, secret, legacyGetToken) {
683
- if (request.req) {
684
- const token = await (0, import_jwt.getToken)({ req: request.req, secret });
685
- return token != null;
686
- }
687
- return Boolean(legacyGetToken(request));
688
- }
689
- function createCmsMiddleware(config = {}) {
690
- const {
691
- publicAdminPaths = ["/admin/signin", "/admin/forgot-password", "/admin/reset-password", "/admin/invite"],
692
- publicApiMethods = defaultPublicApiMethods,
693
- signInPath = "/admin/signin",
694
- getSessionToken = legacyGetSessionToken,
695
- secret = process.env.NEXTAUTH_SECRET
696
- } = config;
697
- return async function cmsMiddleware(request) {
698
- const pathname = request.nextUrl.pathname;
699
- const method = request.method;
700
- if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
701
- return { type: "next" };
702
- }
703
- if (pathname.startsWith("/admin")) {
704
- const authenticated = await hasValidSession(request, secret, getSessionToken);
705
- const cookies = sessionCookiePresence(request);
706
- if (!authenticated) {
707
- logAuth("middleware: admin redirect to signin (no session)", {
708
- pathname,
709
- method,
710
- usesGetToken: Boolean(request.req),
711
- ...cookies,
712
- expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
713
- });
714
- return { type: "redirect", url: new URL(signInPath, request.url).toString() };
715
- }
716
- logAuth("middleware: admin allowed", {
717
- pathname,
718
- method,
719
- usesGetToken: Boolean(request.req),
720
- ...cookies
721
- });
722
- }
723
- if (pathname.startsWith("/api")) {
724
- if (isPublicMethod2(pathname, method, publicApiMethods)) {
725
- return { type: "next" };
726
- }
727
- const authenticated = await hasValidSession(request, secret, getSessionToken);
728
- if (!authenticated) {
729
- logAuth("middleware: api 401 (no session)", {
730
- pathname,
731
- method,
732
- usesGetToken: Boolean(request.req),
733
- ...sessionCookiePresence(request)
734
- });
735
- return { type: "json", status: 401, body: { error: "Unauthorized" } };
736
- }
737
- }
738
- return { type: "next" };
739
- };
740
- }
741
-
742
- // src/auth/nextauth-options.ts
743
- var import_credentials = __toESM(require("next-auth/providers/credentials"), 1);
744
- init_permission_entities();
745
- init_role_helpers();
746
- init_vendor_scope();
747
- var CredentialsProvider = import_credentials.default.default ?? import_credentials.default;
748
- function sessionUserFromNextAuthUser(user) {
749
- const g = user.group;
750
- const isRBACAdmin = isSuperAdmin({
751
- groupId: user.groupId ?? void 0,
752
- groupName: g?.name,
753
- isRBACAdmin: false
754
- });
755
- const entityPerms = permissionRowsToRecord(g?.permissions);
756
- const rawAdminAccess = user.adminAccess;
757
- const adminAccess = rawAdminAccess === true ? true : rawAdminAccess === false ? false : void 0;
758
- const vendorIds = user.vendorIds ?? [];
759
- const vendorRole = user.vendorRole ?? null;
760
- const { isVendorPortal, isVendorOwner: isVendorOwner2 } = vendorPortalFlagsFromUser({
761
- email: user.email,
762
- isRBACAdmin,
763
- groupName: g?.name,
764
- vendorIds,
765
- vendorRole
766
- });
767
- return {
768
- id: user.id.toString(),
769
- email: user.email,
770
- name: user.name,
771
- groupId: user.groupId ?? void 0,
772
- groupName: g?.name ?? void 0,
773
- isRBACAdmin,
774
- entityPerms,
775
- adminAccess,
776
- vendorIds,
777
- activeVendorId: user.activeVendorId ?? vendorIds[0] ?? null,
778
- vendorRole,
779
- isVendorPortal,
780
- isVendorOwner: isVendorOwner2
781
- };
782
- }
783
- function isCustomerGroupUser(user) {
784
- return user.group?.name?.toLocaleLowerCase().trim() === "customer";
785
- }
786
- function callbackUrlTargetsAdmin(callbackUrl) {
787
- const raw = callbackUrl.trim();
788
- if (!raw) return false;
789
- if (raw.startsWith("/admin")) return true;
790
- try {
791
- const path = raw.startsWith("http") ? new URL(raw).pathname : raw.split("?")[0] ?? raw;
792
- return path.startsWith("/admin");
793
- } catch {
794
- return raw.includes("/admin");
795
- }
796
- }
797
- function permitsCustomerLogin(allowCustomerLogin, credentials) {
798
- if (allowCustomerLogin === true) return true;
799
- if (allowCustomerLogin === false) return false;
800
- const callbackUrl = typeof credentials?.callbackUrl === "string" ? credentials.callbackUrl : "";
801
- return !callbackUrlTargetsAdmin(callbackUrl);
802
- }
803
- function getNextAuthOptions(config) {
804
- const {
805
- getUserByEmail,
806
- comparePassword,
807
- signInPage = "/admin/signin",
808
- secret,
809
- extend,
810
- enablePasswordLogin = true,
811
- enableOtpLogin = false,
812
- authorizeOtp,
813
- allowCustomerLogin
814
- } = config;
815
- logAuth("getNextAuthOptions init", nextAuthCookieDebugInfo());
816
- const providers = [];
817
- if (enablePasswordLogin) {
818
- providers.push(
819
- CredentialsProvider({
820
- name: "credentials",
821
- credentials: {
822
- email: { label: "Email", type: "email" },
823
- password: { label: "Password", type: "password" }
824
- },
825
- async authorize(credentials) {
826
- const creds = credentials;
827
- const email = creds?.email?.trim() ?? "";
828
- if (!email || !creds?.password) {
829
- logAuth("authorize(credentials) rejected", { reason: "missing_email_or_password" });
830
- return null;
831
- }
832
- try {
833
- const user = await getUserByEmail(email);
834
- if (!user) {
835
- logAuth("authorize(credentials) rejected", { reason: "user_not_found", email });
836
- return null;
837
- }
838
- if (user.blocked) {
839
- logAuth("authorize(credentials) rejected", { reason: "blocked", email, userId: user.id });
840
- return null;
841
- }
842
- if (user.deleted) {
843
- logAuth("authorize(credentials) rejected", { reason: "deleted", email, userId: user.id });
844
- return null;
845
- }
846
- if (!user.password) {
847
- logAuth("authorize(credentials) rejected", { reason: "no_password", email, userId: user.id });
848
- return null;
849
- }
850
- const valid = await comparePassword(creds.password, user.password);
851
- if (!valid) {
852
- logAuth("authorize(credentials) rejected", { reason: "invalid_password", email, userId: user.id });
853
- return null;
854
- }
855
- if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
856
- logAuth("authorize(credentials) rejected", {
857
- reason: "customer_group",
858
- email,
859
- userId: user.id,
860
- callbackUrl: creds?.callbackUrl ?? null
861
- });
862
- return null;
863
- }
864
- const sessionUser = sessionUserFromNextAuthUser(user);
865
- logAuth("authorize(credentials) ok", summarizeSessionUserForLog(sessionUser));
866
- return sessionUser;
867
- } catch (err) {
868
- console.error("[cms-auth] authorize error (credentials):", err instanceof Error ? err.message : err);
869
- logAuth("authorize(credentials) error", {
870
- email,
871
- message: err instanceof Error ? err.message : String(err)
872
- });
873
- return null;
874
- }
875
- }
876
- })
877
- );
878
- }
879
- if (enableOtpLogin && authorizeOtp) {
880
- providers.push(
881
- CredentialsProvider({
882
- id: "otp",
883
- name: "otp",
884
- credentials: {
885
- identifier: { label: "Email or phone", type: "text" },
886
- code: { label: "Code", type: "text" },
887
- channel: { label: "Channel", type: "text" }
888
- },
889
- async authorize(credentials) {
890
- const creds = credentials;
891
- const identifier = typeof creds?.identifier === "string" ? creds.identifier.trim() : "";
892
- const code = typeof creds?.code === "string" ? creds.code.trim() : "";
893
- const ch = creds?.channel === "sms" ? "sms" : "email";
894
- if (!identifier || !code) return null;
895
- try {
896
- const user = await authorizeOtp({ identifier, channel: ch, code });
897
- if (!user || user.blocked || user.deleted) return null;
898
- if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
899
- logAuth("authorize(otp) rejected", {
900
- reason: "customer_group",
901
- identifier,
902
- callbackUrl: creds?.callbackUrl ?? null
903
- });
904
- return null;
905
- }
906
- return sessionUserFromNextAuthUser(user);
907
- } catch (err) {
908
- console.error("[cms-auth] authorize error (otp):", err instanceof Error ? err.message : err);
909
- return null;
910
- }
911
- }
912
- })
913
- );
914
- }
915
- const options = {
916
- secret: secret ?? process.env.NEXTAUTH_SECRET,
917
- providers,
918
- session: { strategy: "jwt" },
919
- pages: { signIn: signInPage },
920
- cookies: {
921
- sessionToken: {
922
- name: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token",
923
- options: {
924
- httpOnly: true,
925
- sameSite: "lax",
926
- path: "/",
927
- secure: process.env.NEXTAUTH_URL?.startsWith("https") ?? false
928
- }
929
- }
930
- },
931
- callbacks: {
932
- async jwt({ token, user, trigger, session }) {
933
- if (user) {
934
- logAuth("jwt callback: new sign-in", {
935
- trigger,
936
- user: summarizeSessionUserForLog(user)
937
- });
938
- const u = user;
939
- token.id = u.id;
940
- token.groupId = u.groupId;
941
- token.groupName = u.groupName;
942
- token.isRBACAdmin = u.isRBACAdmin;
943
- token.entityPerms = u.entityPerms;
944
- token.adminAccess = u.adminAccess;
945
- token.vendorIds = u.vendorIds;
946
- token.activeVendorId = u.activeVendorId;
947
- token.vendorRole = u.vendorRole;
948
- token.isVendorPortal = u.isVendorPortal;
949
- token.isVendorOwner = u.isVendorOwner;
950
- }
951
- if (trigger === "update" && session && typeof session === "object") {
952
- logAuth("jwt callback: session update", { trigger });
953
- const s = session;
954
- const t = token;
955
- if (typeof s.name === "string") t.name = s.name;
956
- if (typeof s.email === "string") t.email = s.email;
957
- if (typeof s.activeVendorId === "number") t.activeVendorId = s.activeVendorId;
958
- }
959
- return token;
960
- },
961
- async session({ session, token }) {
962
- const t = token;
963
- logAuth("session callback", {
964
- tokenHasId: t.id != null,
965
- tokenEmail: typeof t.email === "string" ? t.email : null,
966
- sessionUser: summarizeSessionUserForLog(session.user)
967
- });
968
- if (session.user) {
969
- if (typeof t.name === "string") session.user.name = t.name;
970
- if (typeof t.email === "string") session.user.email = t.email;
971
- session.user.id = t.id;
972
- session.user.groupId = t.groupId;
973
- session.user.groupName = t.groupName;
974
- session.user.isRBACAdmin = t.isRBACAdmin;
975
- session.user.entityPerms = t.entityPerms;
976
- session.user.adminAccess = t.adminAccess;
977
- session.user.vendorIds = t.vendorIds;
978
- session.user.activeVendorId = t.activeVendorId;
979
- session.user.vendorRole = t.vendorRole;
980
- session.user.isVendorPortal = t.isVendorPortal;
981
- session.user.isVendorOwner = t.isVendorOwner;
982
- }
983
- return session;
984
- }
985
- }
986
- };
987
- return extend ? extend(options) : options;
988
- }
989
- function getStorefrontNextAuthOptions(config) {
990
- return getNextAuthOptions({ ...config, allowCustomerLogin: true });
991
- }
992
- // Annotate the CommonJS export names for ESM import in node:
993
- 0 && (module.exports = {
994
- ADMIN_GROUP_NAME,
995
- OPEN_ENDPOINTS,
996
- PERMISSION_REQUIRED_ENDPOINTS,
997
- RBAC_ADMIN_ONLY_ENTITIES,
998
- SUPER_ADMIN_GROUP_ID,
999
- VENDOR_ADMIN_GROUP_ID,
1000
- VENDOR_OWNER_GROUP_NAME,
1001
- VENDOR_SCOPED_STORE_ENTITIES,
1002
- VENDOR_STORE_RBAC_ENTITIES,
1003
- canManageRoles,
1004
- canManageVendorRoles,
1005
- canManageVendorTeam,
1006
- canOnboardVendors,
1007
- createAuthHelpers,
1008
- createCmsAuthBundle,
1009
- createCmsMiddleware,
1010
- defaultPublicApiMethods,
1011
- explainSessionEntityAccess,
1012
- getNextAuthOptions,
1013
- getPermissionableEntityKeys,
1014
- getRequiredPermission,
1015
- getStorefrontNextAuthOptions,
1016
- hasEntityPermission,
1017
- isAuthDebugClientEnabled,
1018
- isAuthDebugEnabled,
1019
- isOpenEndpoint,
1020
- isPlatformAdministrator,
1021
- isPublicMethod,
1022
- isRbacDebugEnabled,
1023
- isSuperAdmin,
1024
- isSuperAdminGroupName,
1025
- isVendorAdmin,
1026
- isVendorGroupName,
1027
- isVendorOwner,
1028
- isVendorPortalUser,
1029
- isVendorStaff,
1030
- logAuth,
1031
- logAuthClient,
1032
- logEntityAccessDecision,
1033
- logRbac,
1034
- nextAuthCookieDebugInfo,
1035
- permissionRowsToRecord,
1036
- resolveVendorScopeFromSessionUser,
1037
- seedAdministratorPermissions,
1038
- sessionHasEntityAccess,
1039
- summarizeEntityPerms,
1040
- summarizeSessionUserForLog,
1041
- vendorPortalFlagsFromUser
26
+ Object.defineProperty(exports, "isAuthDebugClientEnabled", {
27
+ enumerable: true,
28
+ get: function () { return chunkX6H5VBQ2_cjs.isAuthDebugClientEnabled; }
29
+ });
30
+ Object.defineProperty(exports, "isAuthDebugEnabled", {
31
+ enumerable: true,
32
+ get: function () { return chunkX6H5VBQ2_cjs.isAuthDebugEnabled; }
33
+ });
34
+ Object.defineProperty(exports, "logAuth", {
35
+ enumerable: true,
36
+ get: function () { return chunkX6H5VBQ2_cjs.logAuth; }
37
+ });
38
+ Object.defineProperty(exports, "logAuthClient", {
39
+ enumerable: true,
40
+ get: function () { return chunkX6H5VBQ2_cjs.logAuthClient; }
41
+ });
42
+ Object.defineProperty(exports, "nextAuthCookieDebugInfo", {
43
+ enumerable: true,
44
+ get: function () { return chunkX6H5VBQ2_cjs.nextAuthCookieDebugInfo; }
45
+ });
46
+ Object.defineProperty(exports, "seedAdministratorPermissions", {
47
+ enumerable: true,
48
+ get: function () { return chunkX6H5VBQ2_cjs.seedAdministratorPermissions; }
49
+ });
50
+ Object.defineProperty(exports, "summarizeSessionUserForLog", {
51
+ enumerable: true,
52
+ get: function () { return chunkX6H5VBQ2_cjs.summarizeSessionUserForLog; }
53
+ });
54
+ Object.defineProperty(exports, "OPEN_ENDPOINTS", {
55
+ enumerable: true,
56
+ get: function () { return chunkWO2DW4AU_cjs.OPEN_ENDPOINTS; }
57
+ });
58
+ Object.defineProperty(exports, "PERMISSION_REQUIRED_ENDPOINTS", {
59
+ enumerable: true,
60
+ get: function () { return chunkWO2DW4AU_cjs.PERMISSION_REQUIRED_ENDPOINTS; }
61
+ });
62
+ Object.defineProperty(exports, "RBAC_ADMIN_ONLY_ENTITIES", {
63
+ enumerable: true,
64
+ get: function () { return chunkWO2DW4AU_cjs.RBAC_ADMIN_ONLY_ENTITIES; }
65
+ });
66
+ Object.defineProperty(exports, "canManageRoles", {
67
+ enumerable: true,
68
+ get: function () { return chunkWO2DW4AU_cjs.canManageRoles; }
69
+ });
70
+ Object.defineProperty(exports, "createAuthHelpers", {
71
+ enumerable: true,
72
+ get: function () { return chunkWO2DW4AU_cjs.createAuthHelpers; }
73
+ });
74
+ Object.defineProperty(exports, "createCmsAuthBundle", {
75
+ enumerable: true,
76
+ get: function () { return chunkWO2DW4AU_cjs.createCmsAuthBundle; }
77
+ });
78
+ Object.defineProperty(exports, "getRequiredPermission", {
79
+ enumerable: true,
80
+ get: function () { return chunkWO2DW4AU_cjs.getRequiredPermission; }
81
+ });
82
+ Object.defineProperty(exports, "isOpenEndpoint", {
83
+ enumerable: true,
84
+ get: function () { return chunkWO2DW4AU_cjs.isOpenEndpoint; }
85
+ });
86
+ Object.defineProperty(exports, "isPublicMethod", {
87
+ enumerable: true,
88
+ get: function () { return chunkWO2DW4AU_cjs.isPublicMethod; }
89
+ });
90
+ Object.defineProperty(exports, "sessionHasEntityAccess", {
91
+ enumerable: true,
92
+ get: function () { return chunkWO2DW4AU_cjs.sessionHasEntityAccess; }
93
+ });
94
+ Object.defineProperty(exports, "ADMIN_GROUP_NAME", {
95
+ enumerable: true,
96
+ get: function () { return chunkKPKFNLQQ_cjs.ADMIN_GROUP_NAME; }
97
+ });
98
+ Object.defineProperty(exports, "SUPER_ADMIN_GROUP_ID", {
99
+ enumerable: true,
100
+ get: function () { return chunkKPKFNLQQ_cjs.SUPER_ADMIN_GROUP_ID; }
101
+ });
102
+ Object.defineProperty(exports, "VENDOR_ADMIN_GROUP_ID", {
103
+ enumerable: true,
104
+ get: function () { return chunkKPKFNLQQ_cjs.VENDOR_ADMIN_GROUP_ID; }
105
+ });
106
+ Object.defineProperty(exports, "VENDOR_OWNER_GROUP_NAME", {
107
+ enumerable: true,
108
+ get: function () { return chunkKPKFNLQQ_cjs.VENDOR_OWNER_GROUP_NAME; }
109
+ });
110
+ Object.defineProperty(exports, "VENDOR_SCOPED_STORE_ENTITIES", {
111
+ enumerable: true,
112
+ get: function () { return chunkKPKFNLQQ_cjs.VENDOR_SCOPED_STORE_ENTITIES; }
113
+ });
114
+ Object.defineProperty(exports, "VENDOR_STORE_RBAC_ENTITIES", {
115
+ enumerable: true,
116
+ get: function () { return chunkKPKFNLQQ_cjs.VENDOR_STORE_RBAC_ENTITIES; }
117
+ });
118
+ Object.defineProperty(exports, "canManageVendorRoles", {
119
+ enumerable: true,
120
+ get: function () { return chunkKPKFNLQQ_cjs.canManageVendorRoles; }
121
+ });
122
+ Object.defineProperty(exports, "canManageVendorTeam", {
123
+ enumerable: true,
124
+ get: function () { return chunkKPKFNLQQ_cjs.canManageVendorTeam; }
125
+ });
126
+ Object.defineProperty(exports, "canOnboardVendors", {
127
+ enumerable: true,
128
+ get: function () { return chunkKPKFNLQQ_cjs.canOnboardVendors; }
129
+ });
130
+ Object.defineProperty(exports, "explainSessionEntityAccess", {
131
+ enumerable: true,
132
+ get: function () { return chunkKPKFNLQQ_cjs.explainSessionEntityAccess; }
133
+ });
134
+ Object.defineProperty(exports, "getPermissionableEntityKeys", {
135
+ enumerable: true,
136
+ get: function () { return chunkKPKFNLQQ_cjs.getPermissionableEntityKeys; }
137
+ });
138
+ Object.defineProperty(exports, "hasEntityPermission", {
139
+ enumerable: true,
140
+ get: function () { return chunkKPKFNLQQ_cjs.hasEntityPermission; }
141
+ });
142
+ Object.defineProperty(exports, "isPlatformAdministrator", {
143
+ enumerable: true,
144
+ get: function () { return chunkKPKFNLQQ_cjs.isPlatformAdministrator; }
145
+ });
146
+ Object.defineProperty(exports, "isRbacDebugEnabled", {
147
+ enumerable: true,
148
+ get: function () { return chunkKPKFNLQQ_cjs.isRbacDebugEnabled; }
149
+ });
150
+ Object.defineProperty(exports, "isSuperAdmin", {
151
+ enumerable: true,
152
+ get: function () { return chunkKPKFNLQQ_cjs.isSuperAdmin; }
153
+ });
154
+ Object.defineProperty(exports, "isSuperAdminGroupName", {
155
+ enumerable: true,
156
+ get: function () { return chunkKPKFNLQQ_cjs.isSuperAdminGroupName; }
157
+ });
158
+ Object.defineProperty(exports, "isVendorAdmin", {
159
+ enumerable: true,
160
+ get: function () { return chunkKPKFNLQQ_cjs.isVendorAdmin; }
161
+ });
162
+ Object.defineProperty(exports, "isVendorGroupName", {
163
+ enumerable: true,
164
+ get: function () { return chunkKPKFNLQQ_cjs.isVendorGroupName; }
165
+ });
166
+ Object.defineProperty(exports, "isVendorOwner", {
167
+ enumerable: true,
168
+ get: function () { return chunkKPKFNLQQ_cjs.isVendorOwner; }
169
+ });
170
+ Object.defineProperty(exports, "isVendorPortalUser", {
171
+ enumerable: true,
172
+ get: function () { return chunkKPKFNLQQ_cjs.isVendorPortalUser; }
173
+ });
174
+ Object.defineProperty(exports, "isVendorStaff", {
175
+ enumerable: true,
176
+ get: function () { return chunkKPKFNLQQ_cjs.isVendorStaff; }
177
+ });
178
+ Object.defineProperty(exports, "logEntityAccessDecision", {
179
+ enumerable: true,
180
+ get: function () { return chunkKPKFNLQQ_cjs.logEntityAccessDecision; }
181
+ });
182
+ Object.defineProperty(exports, "logRbac", {
183
+ enumerable: true,
184
+ get: function () { return chunkKPKFNLQQ_cjs.logRbac; }
185
+ });
186
+ Object.defineProperty(exports, "permissionRowsToRecord", {
187
+ enumerable: true,
188
+ get: function () { return chunkKPKFNLQQ_cjs.permissionRowsToRecord; }
189
+ });
190
+ Object.defineProperty(exports, "resolveVendorScopeFromSessionUser", {
191
+ enumerable: true,
192
+ get: function () { return chunkKPKFNLQQ_cjs.resolveVendorScopeFromSessionUser; }
193
+ });
194
+ Object.defineProperty(exports, "summarizeEntityPerms", {
195
+ enumerable: true,
196
+ get: function () { return chunkKPKFNLQQ_cjs.summarizeEntityPerms; }
197
+ });
198
+ Object.defineProperty(exports, "vendorPortalFlagsFromUser", {
199
+ enumerable: true,
200
+ get: function () { return chunkKPKFNLQQ_cjs.vendorPortalFlagsFromUser; }
1042
201
  });
1043
- //# sourceMappingURL=auth.cjs.map