@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,604 @@
1
+ import { getPermissionableEntityKeys, ADMIN_GROUP_NAME, isSuperAdmin, permissionRowsToRecord, vendorPortalFlagsFromUser } from './chunk-UF3BYUXY.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
+ if (!adminGroup) return;
18
+ const fullCrud = {
19
+ canCreate: true,
20
+ canRead: true,
21
+ canUpdate: true,
22
+ canDelete: true
23
+ };
24
+ for (const entity of entities) {
25
+ const existing = await permRepo.findOne({
26
+ where: {
27
+ groupId: adminGroup.id,
28
+ entity
29
+ }
30
+ });
31
+ if (existing) {
32
+ existing.canCreate = true;
33
+ existing.canRead = true;
34
+ existing.canUpdate = true;
35
+ existing.canDelete = true;
36
+ await permRepo.save(existing);
37
+ } else {
38
+ await permRepo.save(permRepo.create({
39
+ groupId: adminGroup.id,
40
+ entity,
41
+ ...fullCrud
42
+ }));
43
+ }
44
+ }
45
+ }
46
+ __name(seedAdministratorPermissions, "seedAdministratorPermissions");
47
+
48
+ // src/auth/auth-debug.ts
49
+ var LOG_PREFIX = "[cms-auth]";
50
+ function isAuthDebugEnabled() {
51
+ const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
52
+ return v === "1" || v === "true" || v === "yes";
53
+ }
54
+ __name(isAuthDebugEnabled, "isAuthDebugEnabled");
55
+ function isAuthDebugClientEnabled() {
56
+ if (typeof window === "undefined") return false;
57
+ const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
58
+ return v === "1" || v === "true" || v === "yes";
59
+ }
60
+ __name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
61
+ function logAuth(message, data) {
62
+ if (!isAuthDebugEnabled()) return;
63
+ if (data) console.info(LOG_PREFIX, message, data);
64
+ else console.info(LOG_PREFIX, message);
65
+ }
66
+ __name(logAuth, "logAuth");
67
+ function logAuthClient(message, data) {
68
+ if (!isAuthDebugClientEnabled()) return;
69
+ if (data) console.info(LOG_PREFIX, message, data);
70
+ else console.info(LOG_PREFIX, message);
71
+ }
72
+ __name(logAuthClient, "logAuthClient");
73
+ function summarizeSessionUserForLog(user) {
74
+ if (!user || typeof user !== "object") return {
75
+ present: false
76
+ };
77
+ const u = user;
78
+ return {
79
+ present: true,
80
+ email: u.email ?? null,
81
+ id: u.id ?? null,
82
+ adminAccess: u.adminAccess ?? null,
83
+ isRBACAdmin: u.isRBACAdmin ?? null,
84
+ isVendorPortal: u.isVendorPortal ?? null,
85
+ groupName: u.groupName ?? null
86
+ };
87
+ }
88
+ __name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
89
+ function nextAuthCookieDebugInfo() {
90
+ const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
91
+ const isHttps = nextAuthUrl.startsWith("https");
92
+ return {
93
+ nextAuthUrl,
94
+ hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
95
+ cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
96
+ cookieSecure: isHttps,
97
+ nodeEnv: process.env.NODE_ENV ?? "(unset)"
98
+ };
99
+ }
100
+ __name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
101
+
102
+ // src/auth/middleware.ts
103
+ var defaultPublicApiMethods = {
104
+ "/api/contacts": [
105
+ "POST"
106
+ ],
107
+ "/api/form-submissions": [
108
+ "POST"
109
+ ],
110
+ "/api/blogs": [
111
+ "GET"
112
+ ],
113
+ "/api/forms": [
114
+ "GET"
115
+ ],
116
+ "/api/auth": [
117
+ "GET",
118
+ "POST"
119
+ ],
120
+ "/api/health": [
121
+ "GET"
122
+ ],
123
+ "/api/users/forgot-password": [
124
+ "POST"
125
+ ],
126
+ "/api/users/set-password": [
127
+ "POST"
128
+ ],
129
+ "/api/users/invite": [
130
+ "POST"
131
+ ]
132
+ };
133
+ function legacyGetSessionToken(request) {
134
+ const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
135
+ const regular = request.cookies.get("next-auth.session-token")?.value;
136
+ return secure ?? regular;
137
+ }
138
+ __name(legacyGetSessionToken, "legacyGetSessionToken");
139
+ function sessionCookiePresence(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
+ const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
143
+ return {
144
+ hasSecureToken: Boolean(secure),
145
+ hasRegularToken: Boolean(regular),
146
+ hasChunkedToken: hasChunked,
147
+ resolved: Boolean(secure ?? regular)
148
+ };
149
+ }
150
+ __name(sessionCookiePresence, "sessionCookiePresence");
151
+ function isPublicMethod(pathname, method, publicApiMethods) {
152
+ for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
153
+ if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
154
+ }
155
+ return false;
156
+ }
157
+ __name(isPublicMethod, "isPublicMethod");
158
+ async function hasValidSession(request, secret, legacyGetToken) {
159
+ if (request.req) {
160
+ const token = await getToken({
161
+ req: request.req,
162
+ secret
163
+ });
164
+ return token != null;
165
+ }
166
+ return Boolean(legacyGetToken(request));
167
+ }
168
+ __name(hasValidSession, "hasValidSession");
169
+ function createCmsMiddleware(config = {}) {
170
+ const { publicAdminPaths = [
171
+ "/admin/signin",
172
+ "/admin/forgot-password",
173
+ "/admin/reset-password",
174
+ "/admin/invite"
175
+ ], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
176
+ return /* @__PURE__ */ __name(async function cmsMiddleware(request) {
177
+ const pathname = request.nextUrl.pathname;
178
+ const method = request.method;
179
+ if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
180
+ return {
181
+ type: "next"
182
+ };
183
+ }
184
+ if (pathname.startsWith("/admin")) {
185
+ const authenticated = await hasValidSession(request, secret, getSessionToken);
186
+ const cookies = sessionCookiePresence(request);
187
+ if (!authenticated) {
188
+ logAuth("middleware: admin redirect to signin (no session)", {
189
+ pathname,
190
+ method,
191
+ usesGetToken: Boolean(request.req),
192
+ ...cookies,
193
+ expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
194
+ });
195
+ return {
196
+ type: "redirect",
197
+ url: new URL(signInPath, request.url).toString()
198
+ };
199
+ }
200
+ logAuth("middleware: admin allowed", {
201
+ pathname,
202
+ method,
203
+ usesGetToken: Boolean(request.req),
204
+ ...cookies
205
+ });
206
+ }
207
+ if (pathname.startsWith("/api")) {
208
+ if (isPublicMethod(pathname, method, publicApiMethods)) {
209
+ return {
210
+ type: "next"
211
+ };
212
+ }
213
+ const authenticated = await hasValidSession(request, secret, getSessionToken);
214
+ if (!authenticated) {
215
+ logAuth("middleware: api 401 (no session)", {
216
+ pathname,
217
+ method,
218
+ usesGetToken: Boolean(request.req),
219
+ ...sessionCookiePresence(request)
220
+ });
221
+ return {
222
+ type: "json",
223
+ status: 401,
224
+ body: {
225
+ error: "Unauthorized"
226
+ }
227
+ };
228
+ }
229
+ }
230
+ return {
231
+ type: "next"
232
+ };
233
+ }, "cmsMiddleware");
234
+ }
235
+ __name(createCmsMiddleware, "createCmsMiddleware");
236
+ var CredentialsProvider = _CredentialsProvider.default ?? _CredentialsProvider;
237
+ function parseBooleanSetting(value) {
238
+ if (typeof value === "boolean") return value;
239
+ if (typeof value === "number") return value !== 0;
240
+ if (typeof value === "string") {
241
+ const normalized = value.trim().toLowerCase();
242
+ if ([
243
+ "true",
244
+ "1",
245
+ "yes",
246
+ "on"
247
+ ].includes(normalized)) return true;
248
+ if ([
249
+ "false",
250
+ "0",
251
+ "no",
252
+ "off"
253
+ ].includes(normalized)) return false;
254
+ }
255
+ if (value && typeof value === "object") {
256
+ const record = value;
257
+ const nested = parseBooleanSetting(record.value ?? record.enabled ?? record.isEnabled ?? record.active ?? record.state);
258
+ if (nested != null) return nested;
259
+ }
260
+ return null;
261
+ }
262
+ __name(parseBooleanSetting, "parseBooleanSetting");
263
+ async function checkMultiVendorEnabledViaSettingsApi() {
264
+ const FAIL_OPEN_DEFAULT = true;
265
+ const base = process.env.NEXTAUTH_URL?.replace(/\/$/, "");
266
+ if (!base) {
267
+ logAuth("multiVendorCheck: no NEXTAUTH_URL, defaulting", {
268
+ multiVendorEnabled: FAIL_OPEN_DEFAULT
269
+ });
270
+ return FAIL_OPEN_DEFAULT;
271
+ }
272
+ try {
273
+ const res = await fetch(`${base}/api/settings/multi_vendor`, {
274
+ cache: "no-store"
275
+ });
276
+ if (!res.ok) {
277
+ logAuth("multiVendorCheck: non-OK response, defaulting", {
278
+ status: res.status
279
+ });
280
+ return FAIL_OPEN_DEFAULT;
281
+ }
282
+ const data = await res.json();
283
+ const parsed = parseBooleanSetting(data?.enabled ?? data?.value ?? data?.isEnabled ?? data?.active ?? data?.state);
284
+ return parsed ?? FAIL_OPEN_DEFAULT;
285
+ } catch (err) {
286
+ logAuth("multiVendorCheck: fetch failed, defaulting", {
287
+ message: err instanceof Error ? err.message : String(err)
288
+ });
289
+ return FAIL_OPEN_DEFAULT;
290
+ }
291
+ }
292
+ __name(checkMultiVendorEnabledViaSettingsApi, "checkMultiVendorEnabledViaSettingsApi");
293
+ function sessionUserFromNextAuthUser(user) {
294
+ const g = user.group;
295
+ const isRBACAdmin = isSuperAdmin({
296
+ groupId: user.groupId ?? void 0,
297
+ groupName: g?.name,
298
+ isRBACAdmin: false
299
+ });
300
+ const entityPerms = permissionRowsToRecord(g?.permissions);
301
+ const rawAdminAccess = user.adminAccess;
302
+ const adminAccess = rawAdminAccess === true ? true : rawAdminAccess === false ? false : void 0;
303
+ const vendorIds = user.vendorIds ?? [];
304
+ const vendorRole = user.vendorRole ?? null;
305
+ const isVendorRoleOwner = user.isVendorRoleOwner ?? false;
306
+ const { isVendorPortal, isVendorOwner: isVendorOwner2 } = vendorPortalFlagsFromUser({
307
+ email: user.email,
308
+ isRBACAdmin,
309
+ groupName: g?.name,
310
+ vendorIds,
311
+ vendorRole,
312
+ isVendorRoleOwner
313
+ });
314
+ return {
315
+ id: user.id.toString(),
316
+ email: user.email,
317
+ name: user.name,
318
+ groupId: user.groupId ?? void 0,
319
+ groupName: g?.name ?? void 0,
320
+ isRBACAdmin,
321
+ entityPerms,
322
+ adminAccess,
323
+ vendorIds,
324
+ activeVendorId: user.activeVendorId ?? vendorIds[0] ?? null,
325
+ vendorRole,
326
+ vendorRoleId: user.vendorRoleId ?? null,
327
+ vendorRoleName: user.vendorRoleName ?? null,
328
+ isVendorRoleOwner,
329
+ vendorEntityPerms: user.vendorEntityPerms,
330
+ isVendorPortal,
331
+ isVendorOwner: isVendorOwner2
332
+ };
333
+ }
334
+ __name(sessionUserFromNextAuthUser, "sessionUserFromNextAuthUser");
335
+ function isCustomerGroupUser(user) {
336
+ return user.group?.name?.toLocaleLowerCase().trim() === "customer";
337
+ }
338
+ __name(isCustomerGroupUser, "isCustomerGroupUser");
339
+ function callbackUrlTargetsAdmin(callbackUrl) {
340
+ const raw = callbackUrl.trim();
341
+ if (!raw) return false;
342
+ if (raw.startsWith("/admin")) return true;
343
+ try {
344
+ const path = raw.startsWith("http") ? new URL(raw).pathname : raw.split("?")[0] ?? raw;
345
+ return path.startsWith("/admin");
346
+ } catch {
347
+ return raw.includes("/admin");
348
+ }
349
+ }
350
+ __name(callbackUrlTargetsAdmin, "callbackUrlTargetsAdmin");
351
+ function permitsCustomerLogin(allowCustomerLogin, credentials) {
352
+ if (allowCustomerLogin === true) return true;
353
+ if (allowCustomerLogin === false) return false;
354
+ const callbackUrl = typeof credentials?.callbackUrl === "string" ? credentials.callbackUrl : "";
355
+ return !callbackUrlTargetsAdmin(callbackUrl);
356
+ }
357
+ __name(permitsCustomerLogin, "permitsCustomerLogin");
358
+ function getNextAuthOptions(config) {
359
+ const { getUserByEmail, comparePassword, signInPage = "/admin/signin", secret, extend, enablePasswordLogin = true, enableOtpLogin = false, authorizeOtp, allowCustomerLogin } = config;
360
+ logAuth("getNextAuthOptions init", nextAuthCookieDebugInfo());
361
+ const providers = [];
362
+ if (enablePasswordLogin) {
363
+ providers.push(CredentialsProvider({
364
+ name: "credentials",
365
+ credentials: {
366
+ email: {
367
+ label: "Email",
368
+ type: "email"
369
+ },
370
+ password: {
371
+ label: "Password",
372
+ type: "password"
373
+ }
374
+ },
375
+ async authorize(credentials) {
376
+ const creds = credentials;
377
+ const email = creds?.email?.trim() ?? "";
378
+ if (!email || !creds?.password) {
379
+ logAuth("authorize(credentials) rejected", {
380
+ reason: "missing_email_or_password"
381
+ });
382
+ return null;
383
+ }
384
+ try {
385
+ const user = await getUserByEmail(email);
386
+ if (!user) {
387
+ logAuth("authorize(credentials) rejected", {
388
+ reason: "user_not_found",
389
+ email
390
+ });
391
+ return null;
392
+ }
393
+ if (user.blocked) {
394
+ logAuth("authorize(credentials) rejected", {
395
+ reason: "blocked",
396
+ email,
397
+ userId: user.id
398
+ });
399
+ return null;
400
+ }
401
+ if (user.deleted) {
402
+ logAuth("authorize(credentials) rejected", {
403
+ reason: "deleted",
404
+ email,
405
+ userId: user.id
406
+ });
407
+ return null;
408
+ }
409
+ if (!user.password) {
410
+ logAuth("authorize(credentials) rejected", {
411
+ reason: "no_password",
412
+ email,
413
+ userId: user.id
414
+ });
415
+ return null;
416
+ }
417
+ const valid = await comparePassword(creds.password, user.password);
418
+ if (!valid) {
419
+ logAuth("authorize(credentials) rejected", {
420
+ reason: "invalid_password",
421
+ email,
422
+ userId: user.id
423
+ });
424
+ return null;
425
+ }
426
+ if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
427
+ logAuth("authorize(credentials) rejected", {
428
+ reason: "customer_group",
429
+ email,
430
+ userId: user.id,
431
+ callbackUrl: creds?.callbackUrl ?? null
432
+ });
433
+ return null;
434
+ }
435
+ const sessionUser = sessionUserFromNextAuthUser(user);
436
+ if (sessionUser.isVendorPortal && !sessionUser.isRBACAdmin) {
437
+ const multiVendorEnabled = await checkMultiVendorEnabledViaSettingsApi();
438
+ if (!multiVendorEnabled) {
439
+ logAuth("authorize(credentials) rejected", {
440
+ reason: "multi_vendor_disabled",
441
+ email,
442
+ userId: user.id
443
+ });
444
+ return null;
445
+ }
446
+ }
447
+ logAuth("authorize(credentials) ok", summarizeSessionUserForLog(sessionUser));
448
+ return sessionUser;
449
+ } catch (err) {
450
+ console.error("[cms-auth] authorize error (credentials):", err instanceof Error ? err.message : err);
451
+ logAuth("authorize(credentials) error", {
452
+ email,
453
+ message: err instanceof Error ? err.message : String(err)
454
+ });
455
+ return null;
456
+ }
457
+ }
458
+ }));
459
+ }
460
+ if (enableOtpLogin && authorizeOtp) {
461
+ providers.push(CredentialsProvider({
462
+ id: "otp",
463
+ name: "otp",
464
+ credentials: {
465
+ identifier: {
466
+ label: "Email or phone",
467
+ type: "text"
468
+ },
469
+ code: {
470
+ label: "Code",
471
+ type: "text"
472
+ },
473
+ channel: {
474
+ label: "Channel",
475
+ type: "text"
476
+ }
477
+ },
478
+ async authorize(credentials) {
479
+ const creds = credentials;
480
+ const identifier = typeof creds?.identifier === "string" ? creds.identifier.trim() : "";
481
+ const code = typeof creds?.code === "string" ? creds.code.trim() : "";
482
+ const ch = creds?.channel === "sms" ? "sms" : "email";
483
+ if (!identifier || !code) return null;
484
+ try {
485
+ const user = await authorizeOtp({
486
+ identifier,
487
+ channel: ch,
488
+ code
489
+ });
490
+ if (!user || user.blocked || user.deleted) return null;
491
+ if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
492
+ logAuth("authorize(otp) rejected", {
493
+ reason: "customer_group",
494
+ identifier,
495
+ callbackUrl: creds?.callbackUrl ?? null
496
+ });
497
+ return null;
498
+ }
499
+ return sessionUserFromNextAuthUser(user);
500
+ } catch (err) {
501
+ console.error("[cms-auth] authorize error (otp):", err instanceof Error ? err.message : err);
502
+ return null;
503
+ }
504
+ }
505
+ }));
506
+ }
507
+ const options = {
508
+ secret: secret ?? process.env.NEXTAUTH_SECRET,
509
+ providers,
510
+ session: {
511
+ strategy: "jwt"
512
+ },
513
+ pages: {
514
+ signIn: signInPage
515
+ },
516
+ cookies: {
517
+ sessionToken: {
518
+ name: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token",
519
+ options: {
520
+ httpOnly: true,
521
+ sameSite: "lax",
522
+ path: "/",
523
+ secure: process.env.NEXTAUTH_URL?.startsWith("https") ?? false
524
+ }
525
+ }
526
+ },
527
+ callbacks: {
528
+ async jwt({ token, user, trigger, session }) {
529
+ if (user) {
530
+ logAuth("jwt callback: new sign-in", {
531
+ trigger,
532
+ user: summarizeSessionUserForLog(user)
533
+ });
534
+ const u = user;
535
+ token.id = u.id;
536
+ token.groupId = u.groupId;
537
+ token.groupName = u.groupName;
538
+ token.isRBACAdmin = u.isRBACAdmin;
539
+ token.entityPerms = u.entityPerms;
540
+ token.adminAccess = u.adminAccess;
541
+ token.vendorIds = u.vendorIds;
542
+ token.activeVendorId = u.activeVendorId;
543
+ token.vendorRole = u.vendorRole;
544
+ token.vendorRoleId = u.vendorRoleId;
545
+ token.vendorRoleName = u.vendorRoleName;
546
+ token.isVendorRoleOwner = u.isVendorRoleOwner;
547
+ token.vendorEntityPerms = u.vendorEntityPerms;
548
+ token.isVendorPortal = u.isVendorPortal;
549
+ token.isVendorOwner = u.isVendorOwner;
550
+ }
551
+ if (trigger === "update" && session && typeof session === "object") {
552
+ logAuth("jwt callback: session update", {
553
+ trigger
554
+ });
555
+ const s = session;
556
+ const t = token;
557
+ if (typeof s.name === "string") t.name = s.name;
558
+ if (typeof s.email === "string") t.email = s.email;
559
+ if (typeof s.activeVendorId === "number") t.activeVendorId = s.activeVendorId;
560
+ }
561
+ return token;
562
+ },
563
+ async session({ session, token }) {
564
+ const t = token;
565
+ logAuth("session callback", {
566
+ tokenHasId: t.id != null,
567
+ tokenEmail: typeof t.email === "string" ? t.email : null,
568
+ sessionUser: summarizeSessionUserForLog(session.user)
569
+ });
570
+ if (session.user) {
571
+ if (typeof t.name === "string") session.user.name = t.name;
572
+ if (typeof t.email === "string") session.user.email = t.email;
573
+ session.user.id = t.id;
574
+ session.user.groupId = t.groupId;
575
+ session.user.groupName = t.groupName;
576
+ session.user.isRBACAdmin = t.isRBACAdmin;
577
+ session.user.entityPerms = t.entityPerms;
578
+ session.user.adminAccess = t.adminAccess;
579
+ session.user.vendorIds = t.vendorIds;
580
+ session.user.activeVendorId = t.activeVendorId;
581
+ session.user.vendorRole = t.vendorRole;
582
+ session.user.vendorRoleId = t.vendorRoleId;
583
+ session.user.vendorRoleName = t.vendorRoleName;
584
+ session.user.isVendorRoleOwner = t.isVendorRoleOwner;
585
+ session.user.vendorEntityPerms = t.vendorEntityPerms;
586
+ session.user.isVendorPortal = t.isVendorPortal;
587
+ session.user.isVendorOwner = t.isVendorOwner;
588
+ }
589
+ return session;
590
+ }
591
+ }
592
+ };
593
+ return extend ? extend(options) : options;
594
+ }
595
+ __name(getNextAuthOptions, "getNextAuthOptions");
596
+ function getStorefrontNextAuthOptions(config) {
597
+ return getNextAuthOptions({
598
+ ...config,
599
+ allowCustomerLogin: true
600
+ });
601
+ }
602
+ __name(getStorefrontNextAuthOptions, "getStorefrontNextAuthOptions");
603
+
604
+ export { createCmsMiddleware, defaultPublicApiMethods, getNextAuthOptions, getStorefrontNextAuthOptions, isAuthDebugClientEnabled, isAuthDebugEnabled, logAuth, logAuthClient, nextAuthCookieDebugInfo, seedAdministratorPermissions, summarizeSessionUserForLog };
@@ -0,0 +1,76 @@
1
+ import { __name } from './chunk-SHUYVCID.js';
2
+ import PgBoss from 'pg-boss';
3
+
4
+ var JOB_RUNNER_QUEUE = "job-runner";
5
+ var PgBossService = class {
6
+ static {
7
+ __name(this, "PgBossService");
8
+ }
9
+ boss;
10
+ started = false;
11
+ workRegistered = /* @__PURE__ */ new Set();
12
+ constructor(connectionString, schema) {
13
+ this.boss = new PgBoss({
14
+ connectionString,
15
+ ...schema?.trim() ? {
16
+ schema: schema.trim()
17
+ } : {},
18
+ schedule: true
19
+ });
20
+ this.boss.on("error", (err) => {
21
+ console.error("[pg-boss]", err);
22
+ });
23
+ }
24
+ async start() {
25
+ if (this.started) return;
26
+ await this.boss.start();
27
+ await this.ensureQueue(JOB_RUNNER_QUEUE);
28
+ this.started = true;
29
+ }
30
+ async stop() {
31
+ if (!this.started) return;
32
+ await this.boss.stop({
33
+ graceful: true,
34
+ timeout: 1e4
35
+ });
36
+ this.started = false;
37
+ this.workRegistered.clear();
38
+ }
39
+ get raw() {
40
+ return this.boss;
41
+ }
42
+ async ensureQueue(name) {
43
+ const existing = await this.boss.getQueue(name);
44
+ if (!existing) {
45
+ await this.boss.createQueue(name);
46
+ }
47
+ }
48
+ async send(queue, data) {
49
+ await this.ensureQueue(queue);
50
+ return this.boss.send(queue, data, {
51
+ retryLimit: 2
52
+ });
53
+ }
54
+ async schedule(name, cron, data, options) {
55
+ await this.ensureQueue(name);
56
+ await this.boss.schedule(name, cron, data, options);
57
+ }
58
+ async unschedule(name) {
59
+ try {
60
+ await this.boss.unschedule(name);
61
+ } catch {
62
+ }
63
+ }
64
+ async registerWork(queue, handler) {
65
+ if (this.workRegistered.has(queue)) return;
66
+ await this.ensureQueue(queue);
67
+ await this.boss.work(queue, async (jobs) => {
68
+ for (const job of jobs) {
69
+ await handler(job.data);
70
+ }
71
+ });
72
+ this.workRegistered.add(queue);
73
+ }
74
+ };
75
+
76
+ export { JOB_RUNNER_QUEUE, PgBossService };
@@ -0,0 +1,21 @@
1
+ import { __name } from './chunk-SHUYVCID.js';
2
+ import { EventEmitter } from 'events';
3
+
4
+ var KNOWN_NOTIFICATION_TRIGGERS = {
5
+ ORDER_PLACED: "order_placed",
6
+ ORDER_CANCELLED: "order_cancelled"
7
+ };
8
+ var NotificationTriggerEmitter = class NotificationTriggerEmitter2 extends EventEmitter {
9
+ static {
10
+ __name(this, "NotificationTriggerEmitter");
11
+ }
12
+ emitTrigger(triggerKey, payload) {
13
+ this.emit("__any__", triggerKey, payload);
14
+ }
15
+ onAnyTrigger(listener) {
16
+ this.on("__any__", listener);
17
+ }
18
+ };
19
+ var notificationTriggerEmitter = new NotificationTriggerEmitter();
20
+
21
+ export { KNOWN_NOTIFICATION_TRIGGERS, notificationTriggerEmitter };