@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
@@ -0,0 +1,620 @@
1
+ 'use strict';
2
+
3
+ var chunkKPKFNLQQ_cjs = require('./chunk-KPKFNLQQ.cjs');
4
+ var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
5
+ var jwt = require('next-auth/jwt');
6
+ var _CredentialsProvider = require('next-auth/providers/credentials');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var _CredentialsProvider__default = /*#__PURE__*/_interopDefault(_CredentialsProvider);
11
+
12
+ // src/auth/seed-permissions.ts
13
+ async function seedAdministratorPermissions(dataSource, entityMap) {
14
+ const entities = chunkKPKFNLQQ_cjs.getPermissionableEntityKeys(entityMap);
15
+ const groupRepo = dataSource.getRepository(entityMap.user_groups);
16
+ const permRepo = dataSource.getRepository(entityMap.permissions);
17
+ const adminGroup = await groupRepo.findOne({
18
+ where: {
19
+ name: chunkKPKFNLQQ_cjs.ADMIN_GROUP_NAME,
20
+ deleted: false
21
+ }
22
+ });
23
+ if (!adminGroup) return;
24
+ const fullCrud = {
25
+ canCreate: true,
26
+ canRead: true,
27
+ canUpdate: true,
28
+ canDelete: true
29
+ };
30
+ for (const entity of entities) {
31
+ const existing = await permRepo.findOne({
32
+ where: {
33
+ groupId: adminGroup.id,
34
+ entity
35
+ }
36
+ });
37
+ if (existing) {
38
+ existing.canCreate = true;
39
+ existing.canRead = true;
40
+ existing.canUpdate = true;
41
+ existing.canDelete = true;
42
+ await permRepo.save(existing);
43
+ } else {
44
+ await permRepo.save(permRepo.create({
45
+ groupId: adminGroup.id,
46
+ entity,
47
+ ...fullCrud
48
+ }));
49
+ }
50
+ }
51
+ }
52
+ chunkUSNT2KNT_cjs.__name(seedAdministratorPermissions, "seedAdministratorPermissions");
53
+
54
+ // src/auth/auth-debug.ts
55
+ var LOG_PREFIX = "[cms-auth]";
56
+ function isAuthDebugEnabled() {
57
+ const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
58
+ return v === "1" || v === "true" || v === "yes";
59
+ }
60
+ chunkUSNT2KNT_cjs.__name(isAuthDebugEnabled, "isAuthDebugEnabled");
61
+ function isAuthDebugClientEnabled() {
62
+ if (typeof window === "undefined") return false;
63
+ const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
64
+ return v === "1" || v === "true" || v === "yes";
65
+ }
66
+ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__name(isPublicMethod, "isPublicMethod");
164
+ async function hasValidSession(request, secret, legacyGetToken) {
165
+ if (request.req) {
166
+ const token = await jwt.getToken({
167
+ req: request.req,
168
+ secret
169
+ });
170
+ return token != null;
171
+ }
172
+ return Boolean(legacyGetToken(request));
173
+ }
174
+ chunkUSNT2KNT_cjs.__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__ */ chunkUSNT2KNT_cjs.__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
+ chunkUSNT2KNT_cjs.__name(createCmsMiddleware, "createCmsMiddleware");
242
+ var CredentialsProvider = _CredentialsProvider__default.default.default ?? _CredentialsProvider__default.default;
243
+ function parseBooleanSetting(value) {
244
+ if (typeof value === "boolean") return value;
245
+ if (typeof value === "number") return value !== 0;
246
+ if (typeof value === "string") {
247
+ const normalized = value.trim().toLowerCase();
248
+ if ([
249
+ "true",
250
+ "1",
251
+ "yes",
252
+ "on"
253
+ ].includes(normalized)) return true;
254
+ if ([
255
+ "false",
256
+ "0",
257
+ "no",
258
+ "off"
259
+ ].includes(normalized)) return false;
260
+ }
261
+ if (value && typeof value === "object") {
262
+ const record = value;
263
+ const nested = parseBooleanSetting(record.value ?? record.enabled ?? record.isEnabled ?? record.active ?? record.state);
264
+ if (nested != null) return nested;
265
+ }
266
+ return null;
267
+ }
268
+ chunkUSNT2KNT_cjs.__name(parseBooleanSetting, "parseBooleanSetting");
269
+ async function checkMultiVendorEnabledViaSettingsApi() {
270
+ const FAIL_OPEN_DEFAULT = true;
271
+ const base = process.env.NEXTAUTH_URL?.replace(/\/$/, "");
272
+ if (!base) {
273
+ logAuth("multiVendorCheck: no NEXTAUTH_URL, defaulting", {
274
+ multiVendorEnabled: FAIL_OPEN_DEFAULT
275
+ });
276
+ return FAIL_OPEN_DEFAULT;
277
+ }
278
+ try {
279
+ const res = await fetch(`${base}/api/settings/multi_vendor`, {
280
+ cache: "no-store"
281
+ });
282
+ if (!res.ok) {
283
+ logAuth("multiVendorCheck: non-OK response, defaulting", {
284
+ status: res.status
285
+ });
286
+ return FAIL_OPEN_DEFAULT;
287
+ }
288
+ const data = await res.json();
289
+ const parsed = parseBooleanSetting(data?.enabled ?? data?.value ?? data?.isEnabled ?? data?.active ?? data?.state);
290
+ return parsed ?? FAIL_OPEN_DEFAULT;
291
+ } catch (err) {
292
+ logAuth("multiVendorCheck: fetch failed, defaulting", {
293
+ message: err instanceof Error ? err.message : String(err)
294
+ });
295
+ return FAIL_OPEN_DEFAULT;
296
+ }
297
+ }
298
+ chunkUSNT2KNT_cjs.__name(checkMultiVendorEnabledViaSettingsApi, "checkMultiVendorEnabledViaSettingsApi");
299
+ function sessionUserFromNextAuthUser(user) {
300
+ const g = user.group;
301
+ const isRBACAdmin = chunkKPKFNLQQ_cjs.isSuperAdmin({
302
+ groupId: user.groupId ?? void 0,
303
+ groupName: g?.name,
304
+ isRBACAdmin: false
305
+ });
306
+ const entityPerms = chunkKPKFNLQQ_cjs.permissionRowsToRecord(g?.permissions);
307
+ const rawAdminAccess = user.adminAccess;
308
+ const adminAccess = rawAdminAccess === true ? true : rawAdminAccess === false ? false : void 0;
309
+ const vendorIds = user.vendorIds ?? [];
310
+ const vendorRole = user.vendorRole ?? null;
311
+ const isVendorRoleOwner = user.isVendorRoleOwner ?? false;
312
+ const { isVendorPortal, isVendorOwner: isVendorOwner2 } = chunkKPKFNLQQ_cjs.vendorPortalFlagsFromUser({
313
+ email: user.email,
314
+ isRBACAdmin,
315
+ groupName: g?.name,
316
+ vendorIds,
317
+ vendorRole,
318
+ isVendorRoleOwner
319
+ });
320
+ return {
321
+ id: user.id.toString(),
322
+ email: user.email,
323
+ name: user.name,
324
+ groupId: user.groupId ?? void 0,
325
+ groupName: g?.name ?? void 0,
326
+ isRBACAdmin,
327
+ entityPerms,
328
+ adminAccess,
329
+ vendorIds,
330
+ activeVendorId: user.activeVendorId ?? vendorIds[0] ?? null,
331
+ vendorRole,
332
+ vendorRoleId: user.vendorRoleId ?? null,
333
+ vendorRoleName: user.vendorRoleName ?? null,
334
+ isVendorRoleOwner,
335
+ vendorEntityPerms: user.vendorEntityPerms,
336
+ isVendorPortal,
337
+ isVendorOwner: isVendorOwner2
338
+ };
339
+ }
340
+ chunkUSNT2KNT_cjs.__name(sessionUserFromNextAuthUser, "sessionUserFromNextAuthUser");
341
+ function isCustomerGroupUser(user) {
342
+ return user.group?.name?.toLocaleLowerCase().trim() === "customer";
343
+ }
344
+ chunkUSNT2KNT_cjs.__name(isCustomerGroupUser, "isCustomerGroupUser");
345
+ function callbackUrlTargetsAdmin(callbackUrl) {
346
+ const raw = callbackUrl.trim();
347
+ if (!raw) return false;
348
+ if (raw.startsWith("/admin")) return true;
349
+ try {
350
+ const path = raw.startsWith("http") ? new URL(raw).pathname : raw.split("?")[0] ?? raw;
351
+ return path.startsWith("/admin");
352
+ } catch {
353
+ return raw.includes("/admin");
354
+ }
355
+ }
356
+ chunkUSNT2KNT_cjs.__name(callbackUrlTargetsAdmin, "callbackUrlTargetsAdmin");
357
+ function permitsCustomerLogin(allowCustomerLogin, credentials) {
358
+ if (allowCustomerLogin === true) return true;
359
+ if (allowCustomerLogin === false) return false;
360
+ const callbackUrl = typeof credentials?.callbackUrl === "string" ? credentials.callbackUrl : "";
361
+ return !callbackUrlTargetsAdmin(callbackUrl);
362
+ }
363
+ chunkUSNT2KNT_cjs.__name(permitsCustomerLogin, "permitsCustomerLogin");
364
+ function getNextAuthOptions(config) {
365
+ const { getUserByEmail, comparePassword, signInPage = "/admin/signin", secret, extend, enablePasswordLogin = true, enableOtpLogin = false, authorizeOtp, allowCustomerLogin } = config;
366
+ logAuth("getNextAuthOptions init", nextAuthCookieDebugInfo());
367
+ const providers = [];
368
+ if (enablePasswordLogin) {
369
+ providers.push(CredentialsProvider({
370
+ name: "credentials",
371
+ credentials: {
372
+ email: {
373
+ label: "Email",
374
+ type: "email"
375
+ },
376
+ password: {
377
+ label: "Password",
378
+ type: "password"
379
+ }
380
+ },
381
+ async authorize(credentials) {
382
+ const creds = credentials;
383
+ const email = creds?.email?.trim() ?? "";
384
+ if (!email || !creds?.password) {
385
+ logAuth("authorize(credentials) rejected", {
386
+ reason: "missing_email_or_password"
387
+ });
388
+ return null;
389
+ }
390
+ try {
391
+ const user = await getUserByEmail(email);
392
+ if (!user) {
393
+ logAuth("authorize(credentials) rejected", {
394
+ reason: "user_not_found",
395
+ email
396
+ });
397
+ return null;
398
+ }
399
+ if (user.blocked) {
400
+ logAuth("authorize(credentials) rejected", {
401
+ reason: "blocked",
402
+ email,
403
+ userId: user.id
404
+ });
405
+ return null;
406
+ }
407
+ if (user.deleted) {
408
+ logAuth("authorize(credentials) rejected", {
409
+ reason: "deleted",
410
+ email,
411
+ userId: user.id
412
+ });
413
+ return null;
414
+ }
415
+ if (!user.password) {
416
+ logAuth("authorize(credentials) rejected", {
417
+ reason: "no_password",
418
+ email,
419
+ userId: user.id
420
+ });
421
+ return null;
422
+ }
423
+ const valid = await comparePassword(creds.password, user.password);
424
+ if (!valid) {
425
+ logAuth("authorize(credentials) rejected", {
426
+ reason: "invalid_password",
427
+ email,
428
+ userId: user.id
429
+ });
430
+ return null;
431
+ }
432
+ if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
433
+ logAuth("authorize(credentials) rejected", {
434
+ reason: "customer_group",
435
+ email,
436
+ userId: user.id,
437
+ callbackUrl: creds?.callbackUrl ?? null
438
+ });
439
+ return null;
440
+ }
441
+ const sessionUser = sessionUserFromNextAuthUser(user);
442
+ if (sessionUser.isVendorPortal && !sessionUser.isRBACAdmin) {
443
+ const multiVendorEnabled = await checkMultiVendorEnabledViaSettingsApi();
444
+ if (!multiVendorEnabled) {
445
+ logAuth("authorize(credentials) rejected", {
446
+ reason: "multi_vendor_disabled",
447
+ email,
448
+ userId: user.id
449
+ });
450
+ return null;
451
+ }
452
+ }
453
+ logAuth("authorize(credentials) ok", summarizeSessionUserForLog(sessionUser));
454
+ return sessionUser;
455
+ } catch (err) {
456
+ console.error("[cms-auth] authorize error (credentials):", err instanceof Error ? err.message : err);
457
+ logAuth("authorize(credentials) error", {
458
+ email,
459
+ message: err instanceof Error ? err.message : String(err)
460
+ });
461
+ return null;
462
+ }
463
+ }
464
+ }));
465
+ }
466
+ if (enableOtpLogin && authorizeOtp) {
467
+ providers.push(CredentialsProvider({
468
+ id: "otp",
469
+ name: "otp",
470
+ credentials: {
471
+ identifier: {
472
+ label: "Email or phone",
473
+ type: "text"
474
+ },
475
+ code: {
476
+ label: "Code",
477
+ type: "text"
478
+ },
479
+ channel: {
480
+ label: "Channel",
481
+ type: "text"
482
+ }
483
+ },
484
+ async authorize(credentials) {
485
+ const creds = credentials;
486
+ const identifier = typeof creds?.identifier === "string" ? creds.identifier.trim() : "";
487
+ const code = typeof creds?.code === "string" ? creds.code.trim() : "";
488
+ const ch = creds?.channel === "sms" ? "sms" : "email";
489
+ if (!identifier || !code) return null;
490
+ try {
491
+ const user = await authorizeOtp({
492
+ identifier,
493
+ channel: ch,
494
+ code
495
+ });
496
+ if (!user || user.blocked || user.deleted) return null;
497
+ if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
498
+ logAuth("authorize(otp) rejected", {
499
+ reason: "customer_group",
500
+ identifier,
501
+ callbackUrl: creds?.callbackUrl ?? null
502
+ });
503
+ return null;
504
+ }
505
+ return sessionUserFromNextAuthUser(user);
506
+ } catch (err) {
507
+ console.error("[cms-auth] authorize error (otp):", err instanceof Error ? err.message : err);
508
+ return null;
509
+ }
510
+ }
511
+ }));
512
+ }
513
+ const options = {
514
+ secret: secret ?? process.env.NEXTAUTH_SECRET,
515
+ providers,
516
+ session: {
517
+ strategy: "jwt"
518
+ },
519
+ pages: {
520
+ signIn: signInPage
521
+ },
522
+ cookies: {
523
+ sessionToken: {
524
+ name: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token",
525
+ options: {
526
+ httpOnly: true,
527
+ sameSite: "lax",
528
+ path: "/",
529
+ secure: process.env.NEXTAUTH_URL?.startsWith("https") ?? false
530
+ }
531
+ }
532
+ },
533
+ callbacks: {
534
+ async jwt({ token, user, trigger, session }) {
535
+ if (user) {
536
+ logAuth("jwt callback: new sign-in", {
537
+ trigger,
538
+ user: summarizeSessionUserForLog(user)
539
+ });
540
+ const u = user;
541
+ token.id = u.id;
542
+ token.groupId = u.groupId;
543
+ token.groupName = u.groupName;
544
+ token.isRBACAdmin = u.isRBACAdmin;
545
+ token.entityPerms = u.entityPerms;
546
+ token.adminAccess = u.adminAccess;
547
+ token.vendorIds = u.vendorIds;
548
+ token.activeVendorId = u.activeVendorId;
549
+ token.vendorRole = u.vendorRole;
550
+ token.vendorRoleId = u.vendorRoleId;
551
+ token.vendorRoleName = u.vendorRoleName;
552
+ token.isVendorRoleOwner = u.isVendorRoleOwner;
553
+ token.vendorEntityPerms = u.vendorEntityPerms;
554
+ token.isVendorPortal = u.isVendorPortal;
555
+ token.isVendorOwner = u.isVendorOwner;
556
+ }
557
+ if (trigger === "update" && session && typeof session === "object") {
558
+ logAuth("jwt callback: session update", {
559
+ trigger
560
+ });
561
+ const s = session;
562
+ const t = token;
563
+ if (typeof s.name === "string") t.name = s.name;
564
+ if (typeof s.email === "string") t.email = s.email;
565
+ if (typeof s.activeVendorId === "number") t.activeVendorId = s.activeVendorId;
566
+ }
567
+ return token;
568
+ },
569
+ async session({ session, token }) {
570
+ const t = token;
571
+ logAuth("session callback", {
572
+ tokenHasId: t.id != null,
573
+ tokenEmail: typeof t.email === "string" ? t.email : null,
574
+ sessionUser: summarizeSessionUserForLog(session.user)
575
+ });
576
+ if (session.user) {
577
+ if (typeof t.name === "string") session.user.name = t.name;
578
+ if (typeof t.email === "string") session.user.email = t.email;
579
+ session.user.id = t.id;
580
+ session.user.groupId = t.groupId;
581
+ session.user.groupName = t.groupName;
582
+ session.user.isRBACAdmin = t.isRBACAdmin;
583
+ session.user.entityPerms = t.entityPerms;
584
+ session.user.adminAccess = t.adminAccess;
585
+ session.user.vendorIds = t.vendorIds;
586
+ session.user.activeVendorId = t.activeVendorId;
587
+ session.user.vendorRole = t.vendorRole;
588
+ session.user.vendorRoleId = t.vendorRoleId;
589
+ session.user.vendorRoleName = t.vendorRoleName;
590
+ session.user.isVendorRoleOwner = t.isVendorRoleOwner;
591
+ session.user.vendorEntityPerms = t.vendorEntityPerms;
592
+ session.user.isVendorPortal = t.isVendorPortal;
593
+ session.user.isVendorOwner = t.isVendorOwner;
594
+ }
595
+ return session;
596
+ }
597
+ }
598
+ };
599
+ return extend ? extend(options) : options;
600
+ }
601
+ chunkUSNT2KNT_cjs.__name(getNextAuthOptions, "getNextAuthOptions");
602
+ function getStorefrontNextAuthOptions(config) {
603
+ return getNextAuthOptions({
604
+ ...config,
605
+ allowCustomerLogin: true
606
+ });
607
+ }
608
+ chunkUSNT2KNT_cjs.__name(getStorefrontNextAuthOptions, "getStorefrontNextAuthOptions");
609
+
610
+ exports.createCmsMiddleware = createCmsMiddleware;
611
+ exports.defaultPublicApiMethods = defaultPublicApiMethods;
612
+ exports.getNextAuthOptions = getNextAuthOptions;
613
+ exports.getStorefrontNextAuthOptions = getStorefrontNextAuthOptions;
614
+ exports.isAuthDebugClientEnabled = isAuthDebugClientEnabled;
615
+ exports.isAuthDebugEnabled = isAuthDebugEnabled;
616
+ exports.logAuth = logAuth;
617
+ exports.logAuthClient = logAuthClient;
618
+ exports.nextAuthCookieDebugInfo = nextAuthCookieDebugInfo;
619
+ exports.seedAdministratorPermissions = seedAdministratorPermissions;
620
+ exports.summarizeSessionUserForLog = summarizeSessionUserForLog;
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
4
+ var PgBoss = require('pg-boss');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var PgBoss__default = /*#__PURE__*/_interopDefault(PgBoss);
9
+
10
+ var JOB_RUNNER_QUEUE = "job-runner";
11
+ var PgBossService = class {
12
+ static {
13
+ chunkUSNT2KNT_cjs.__name(this, "PgBossService");
14
+ }
15
+ boss;
16
+ started = false;
17
+ workRegistered = /* @__PURE__ */ new Set();
18
+ constructor(connectionString, schema) {
19
+ this.boss = new PgBoss__default.default({
20
+ connectionString,
21
+ ...schema?.trim() ? {
22
+ schema: schema.trim()
23
+ } : {},
24
+ schedule: true
25
+ });
26
+ this.boss.on("error", (err) => {
27
+ console.error("[pg-boss]", err);
28
+ });
29
+ }
30
+ async start() {
31
+ if (this.started) return;
32
+ await this.boss.start();
33
+ await this.ensureQueue(JOB_RUNNER_QUEUE);
34
+ this.started = true;
35
+ }
36
+ async stop() {
37
+ if (!this.started) return;
38
+ await this.boss.stop({
39
+ graceful: true,
40
+ timeout: 1e4
41
+ });
42
+ this.started = false;
43
+ this.workRegistered.clear();
44
+ }
45
+ get raw() {
46
+ return this.boss;
47
+ }
48
+ async ensureQueue(name) {
49
+ const existing = await this.boss.getQueue(name);
50
+ if (!existing) {
51
+ await this.boss.createQueue(name);
52
+ }
53
+ }
54
+ async send(queue, data) {
55
+ await this.ensureQueue(queue);
56
+ return this.boss.send(queue, data, {
57
+ retryLimit: 2
58
+ });
59
+ }
60
+ async schedule(name, cron, data, options) {
61
+ await this.ensureQueue(name);
62
+ await this.boss.schedule(name, cron, data, options);
63
+ }
64
+ async unschedule(name) {
65
+ try {
66
+ await this.boss.unschedule(name);
67
+ } catch {
68
+ }
69
+ }
70
+ async registerWork(queue, handler) {
71
+ if (this.workRegistered.has(queue)) return;
72
+ await this.ensureQueue(queue);
73
+ await this.boss.work(queue, async (jobs) => {
74
+ for (const job of jobs) {
75
+ await handler(job.data);
76
+ }
77
+ });
78
+ this.workRegistered.add(queue);
79
+ }
80
+ };
81
+
82
+ exports.JOB_RUNNER_QUEUE = JOB_RUNNER_QUEUE;
83
+ exports.PgBossService = PgBossService;