@infuro/cms-core 1.0.34 → 1.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) 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 +34329 -20923
  5. package/dist/admin.d.cts +186 -9
  6. package/dist/admin.d.ts +186 -9
  7. package/dist/admin.js +34140 -20829
  8. package/dist/api.cjs +120 -17515
  9. package/dist/api.d.cts +633 -3
  10. package/dist/api.d.ts +633 -3
  11. package/dist/api.js +14 -17528
  12. package/dist/auth.cjs +192 -1034
  13. package/dist/auth.d.cts +194 -51
  14. package/dist/auth.d.ts +194 -51
  15. package/dist/auth.js +4 -966
  16. package/dist/chunk-2XE4X74C.js +29602 -0
  17. package/dist/chunk-3DZRIZOD.cjs +52 -0
  18. package/dist/chunk-3KPNTQBV.cjs +620 -0
  19. package/dist/chunk-46GKADYE.cjs +84 -0
  20. package/dist/chunk-4TRPKBKO.js +589 -0
  21. package/dist/chunk-5ELSW2UP.js +150 -0
  22. package/dist/chunk-6KPQWRFW.js +171 -0
  23. package/dist/chunk-7NMT3GBR.cjs +29 -0
  24. package/dist/chunk-7YIBMQDR.cjs +86 -0
  25. package/dist/chunk-BGJAV67S.cjs +29710 -0
  26. package/dist/chunk-CNTSLED2.cjs +559 -0
  27. package/dist/chunk-CRFV5WJK.js +16 -0
  28. package/dist/chunk-D5FBNKQM.cjs +104 -0
  29. package/dist/chunk-EF2JBPDM.js +114 -0
  30. package/dist/chunk-EQPITOP6.js +543 -0
  31. package/dist/chunk-GO7PPYNU.js +76 -0
  32. package/dist/chunk-HF3L2GIT.cjs +194 -0
  33. package/dist/chunk-J7XHLOLO.js +830 -0
  34. package/dist/chunk-JBRR5UYL.js +87 -0
  35. package/dist/chunk-JC6DLWTE.js +21 -0
  36. package/dist/chunk-JHF4YYRC.cjs +188 -0
  37. package/dist/chunk-JXF23MPG.js +25 -0
  38. package/dist/chunk-MQBT33IV.js +48 -0
  39. package/dist/chunk-N44BJZ4C.cjs +123 -0
  40. package/dist/chunk-OOTLNH63.cjs +18 -0
  41. package/dist/chunk-PAMVINEX.cjs +577 -0
  42. package/dist/chunk-PNOKNSG2.cjs +222 -0
  43. package/dist/chunk-QM733NUK.js +186 -0
  44. package/dist/chunk-R73BKDRO.cjs +90 -0
  45. package/dist/chunk-SHUYVCID.js +4 -0
  46. package/dist/chunk-SYBOCAWB.js +97 -0
  47. package/dist/chunk-TDV6EJHV.js +192 -0
  48. package/dist/chunk-TFUOHI37.cjs +839 -0
  49. package/dist/chunk-TIAEXJLI.cjs +182 -0
  50. package/dist/chunk-UPLVMVRX.cjs +23 -0
  51. package/dist/chunk-USNT2KNT.cjs +6 -0
  52. package/dist/chunk-WEMDMVHQ.js +216 -0
  53. package/dist/chunk-XDSNZUW7.js +564 -0
  54. package/dist/chunk-XQ3QUHWR.cjs +83 -0
  55. package/dist/chunk-XW5ATPRW.cjs +155 -0
  56. package/dist/chunk-ZQ4X6OAU.js +82 -0
  57. package/dist/chunk-ZSVCP6N3.js +83 -0
  58. package/dist/cli.cjs +103 -84
  59. package/dist/cli.js +62 -27
  60. package/dist/email-FKR4FXFI.js +5 -0
  61. package/dist/email-KVKVPNCL.cjs +58 -0
  62. package/dist/email-queue-CGZBVVAS.js +2 -0
  63. package/dist/email-queue-TPZWLTIV.cjs +23 -0
  64. package/dist/erp-config-enabled-CUMQ6N2V.cjs +11 -0
  65. package/dist/erp-config-enabled-T37X7T34.js +2 -0
  66. package/dist/erp-order-invoice-3YISSOWW.js +3 -0
  67. package/dist/erp-order-invoice-ZR5F2KTA.cjs +12 -0
  68. package/dist/event-order-defaults-6E543227.js +2 -0
  69. package/dist/event-order-defaults-DUGDVGJI.cjs +39 -0
  70. package/dist/event-order-notifications-5GSAOYVS.cjs +27 -0
  71. package/dist/event-order-notifications-IIIF23D5.js +10 -0
  72. package/dist/hooks.cjs +259 -132
  73. package/dist/hooks.d.cts +42 -1
  74. package/dist/hooks.d.ts +42 -1
  75. package/dist/hooks.js +234 -91
  76. package/dist/index.cjs +3884 -22307
  77. package/dist/index.d.cts +2203 -772
  78. package/dist/index.d.ts +2203 -772
  79. package/dist/index.js +2871 -22064
  80. package/dist/interpolate-WAKPN56R.cjs +11 -0
  81. package/dist/interpolate-WDUWDF3I.js +2 -0
  82. package/dist/layout-36UFTHC5.cjs +11 -0
  83. package/dist/layout-AOBN26XG.js +2 -0
  84. package/dist/migrations/1779400000000-ConvertStatusToEnum.ts +142 -0
  85. package/dist/migrations/1779400000000-SeedDefaultCurrencies.ts +33 -0
  86. package/dist/migrations/1779500000000-VendorRolesAndPermissions.ts +102 -0
  87. package/dist/migrations/1779600000000-VendorRegistrationProfile.ts +52 -0
  88. package/dist/migrations/1779700000000-CollectionIsCatalog.ts +22 -0
  89. package/dist/migrations/1779710000000-CollectionPlatformCatalog.ts +60 -0
  90. package/dist/migrations/1779720000000-ProductCategoryPlatformCatalog.ts +157 -0
  91. package/dist/migrations/1779800000000-EventsAndEventProducts.ts +173 -0
  92. package/dist/migrations/1779810000000-BackfillVendorRoleEventsPermissions.ts +38 -0
  93. package/dist/migrations/1779820000000-FixProductsCategoryForeignKey.ts +70 -0
  94. package/dist/migrations/1779830000000-ProductTitleColumn.ts +32 -0
  95. package/dist/migrations/1779840000000-EventAboutAndVisibilityFields.ts +34 -0
  96. package/dist/migrations/1779850000000-EventCityCountrySplit.ts +43 -0
  97. package/dist/migrations/1779860000000-CreateCombos.ts +140 -0
  98. package/dist/migrations/1780100000000-OrderAttendeesEventId.ts +55 -0
  99. package/dist/migrations/1780110000000-EventContactFormId.ts +49 -0
  100. package/dist/migrations/1780130000000-ProductVariants.ts +54 -0
  101. package/dist/migrations/1780140000000-EventManagementEnhancements.ts +44 -0
  102. package/dist/migrations/1780160000000-EventRegistrationGstProductContactForm.ts +79 -0
  103. package/dist/migrations/1780170000000-ComboCurrencyPrices.ts +20 -0
  104. package/dist/migrations/1781110000000-VendorOwnerCombosPermission.ts +38 -0
  105. package/dist/migrations/1781120000000-RefundPoliciesAndRequests.ts +225 -0
  106. package/dist/migrations/1781130000000-CreateAttendees.ts +44 -0
  107. package/dist/migrations/1781140000000-EventOrderNotifications.ts +29 -0
  108. package/dist/migrations/1781150000000-EventNamedLists.ts +28 -0
  109. package/dist/migrations/1781160000000-RefundPolicyEventTiers.ts +27 -0
  110. package/dist/migrations/1781170000000-EventRefundPolicy.ts +42 -0
  111. package/dist/migrations/1781180000000-RemoveCartItemsUniqueConstraint.ts +15 -0
  112. package/dist/migrations/1781190000000-RenameProductTaxesToProductConfig.ts +84 -0
  113. package/dist/migrations/1781200000000-VendorOwnerProductConfigPermissions.ts +51 -0
  114. package/dist/migrations/1781210000000-VendorRoleProductConfigPermissions.ts +46 -0
  115. package/dist/migrations/helpers/vendor-role-seed.ts +243 -0
  116. package/dist/paid-order-erp-3USEG6WL.js +3 -0
  117. package/dist/paid-order-erp-FSQ3GSXE.cjs +12 -0
  118. package/dist/pg-boss-service-4XF2TQ2E.js +2 -0
  119. package/dist/pg-boss-service-L6MTF4EQ.cjs +15 -0
  120. package/dist/razorpay-KLO2KNCB.js +49 -0
  121. package/dist/razorpay-U23LGY72.cjs +56 -0
  122. package/dist/rbac-debug-db-D7ME7QUY.cjs +35 -0
  123. package/dist/rbac-debug-db-MTCTVNNM.js +33 -0
  124. package/dist/sms-defaults-2NL24H57.js +2 -0
  125. package/dist/sms-defaults-KCOPKQBA.cjs +19 -0
  126. package/dist/stripe-4FD27QVJ.js +51 -0
  127. package/dist/stripe-VU6OEG2D.cjs +57 -0
  128. package/dist/theme.cjs +31 -59
  129. package/dist/theme.d.cts +78 -3
  130. package/dist/theme.d.ts +78 -3
  131. package/dist/theme.js +23 -20
  132. package/dist/vendor-invite-status-77O7ZQ3U.cjs +19 -0
  133. package/dist/vendor-invite-status-PWJ3DE76.js +2 -0
  134. package/dist/whatsapp-queue-3DXA4MXU.js +2 -0
  135. package/dist/whatsapp-queue-KG65MXD5.cjs +15 -0
  136. package/package.json +147 -142
  137. package/dist/admin.cjs.map +0 -1
  138. package/dist/admin.js.map +0 -1
  139. package/dist/api.cjs.map +0 -1
  140. package/dist/api.js.map +0 -1
  141. package/dist/auth.cjs.map +0 -1
  142. package/dist/auth.js.map +0 -1
  143. package/dist/cli.cjs.map +0 -1
  144. package/dist/cli.js.map +0 -1
  145. package/dist/config-DJ5CmQvS.d.cts +0 -8
  146. package/dist/config-DJ5CmQvS.d.ts +0 -8
  147. package/dist/hooks.cjs.map +0 -1
  148. package/dist/hooks.js.map +0 -1
  149. package/dist/index-Bf5GO8fu.d.cts +0 -583
  150. package/dist/index-DOiJuMQA.d.ts +0 -583
  151. package/dist/index.cjs.map +0 -1
  152. package/dist/index.js.map +0 -1
  153. package/dist/theme.cjs.map +0 -1
  154. package/dist/theme.js.map +0 -1
  155. package/dist/types-DCVaXlPV.d.cts +0 -78
  156. package/dist/types-DCVaXlPV.d.ts +0 -78
  157. package/dist/vendor-scope-DTYhJk_I.d.cts +0 -129
  158. package/dist/vendor-scope-DTYhJk_I.d.ts +0 -129
@@ -0,0 +1,559 @@
1
+ 'use strict';
2
+
3
+ var chunk3KPNTQBV_cjs = require('./chunk-3KPNTQBV.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 = chunk3KPNTQBV_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: chunk3KPNTQBV_cjs.ADMIN_GROUP_NAME,
20
+ deleted: false
21
+ }
22
+ });
23
+ console.log("ADMIN GROUP", adminGroup);
24
+ if (!adminGroup) return;
25
+ const fullCrud = {
26
+ canCreate: true,
27
+ canRead: true,
28
+ canUpdate: true,
29
+ canDelete: true
30
+ };
31
+ for (const entity of entities) {
32
+ const existing = await permRepo.findOne({
33
+ where: {
34
+ groupId: adminGroup.id,
35
+ entity
36
+ }
37
+ });
38
+ console.log("EXISTING", existing);
39
+ if (existing) {
40
+ existing.canCreate = true;
41
+ existing.canRead = true;
42
+ existing.canUpdate = true;
43
+ existing.canDelete = true;
44
+ await permRepo.save(existing);
45
+ } else {
46
+ await permRepo.save(permRepo.create({
47
+ groupId: adminGroup.id,
48
+ entity,
49
+ ...fullCrud
50
+ }));
51
+ }
52
+ }
53
+ }
54
+ chunkUSNT2KNT_cjs.__name(seedAdministratorPermissions, "seedAdministratorPermissions");
55
+
56
+ // src/auth/auth-debug.ts
57
+ var LOG_PREFIX = "[cms-auth]";
58
+ function isAuthDebugEnabled() {
59
+ const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
60
+ if (v === "1" || v === "true" || v === "yes") return true;
61
+ if (v === "0" || v === "false" || v === "no") return false;
62
+ return process.env.NODE_ENV === "development";
63
+ }
64
+ chunkUSNT2KNT_cjs.__name(isAuthDebugEnabled, "isAuthDebugEnabled");
65
+ function isAuthDebugClientEnabled() {
66
+ if (typeof window === "undefined") return false;
67
+ const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
68
+ if (v === "1" || v === "true" || v === "yes") return true;
69
+ if (v === "0" || v === "false" || v === "no") return false;
70
+ return process.env.NODE_ENV === "development";
71
+ }
72
+ chunkUSNT2KNT_cjs.__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
73
+ function logAuth(message, data) {
74
+ if (!isAuthDebugEnabled()) return;
75
+ if (data) console.info(LOG_PREFIX, message, data);
76
+ else console.info(LOG_PREFIX, message);
77
+ }
78
+ chunkUSNT2KNT_cjs.__name(logAuth, "logAuth");
79
+ function logAuthClient(message, data) {
80
+ if (!isAuthDebugClientEnabled()) return;
81
+ if (data) console.info(LOG_PREFIX, message, data);
82
+ else console.info(LOG_PREFIX, message);
83
+ }
84
+ chunkUSNT2KNT_cjs.__name(logAuthClient, "logAuthClient");
85
+ function summarizeSessionUserForLog(user) {
86
+ if (!user || typeof user !== "object") return {
87
+ present: false
88
+ };
89
+ const u = user;
90
+ return {
91
+ present: true,
92
+ email: u.email ?? null,
93
+ id: u.id ?? null,
94
+ adminAccess: u.adminAccess ?? null,
95
+ isRBACAdmin: u.isRBACAdmin ?? null,
96
+ isVendorPortal: u.isVendorPortal ?? null,
97
+ groupName: u.groupName ?? null
98
+ };
99
+ }
100
+ chunkUSNT2KNT_cjs.__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
101
+ function nextAuthCookieDebugInfo() {
102
+ const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
103
+ const isHttps = nextAuthUrl.startsWith("https");
104
+ return {
105
+ nextAuthUrl,
106
+ hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
107
+ cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
108
+ cookieSecure: isHttps,
109
+ nodeEnv: process.env.NODE_ENV ?? "(unset)"
110
+ };
111
+ }
112
+ chunkUSNT2KNT_cjs.__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
113
+
114
+ // src/auth/middleware.ts
115
+ var defaultPublicApiMethods = {
116
+ "/api/contacts": [
117
+ "POST"
118
+ ],
119
+ "/api/form-submissions": [
120
+ "POST"
121
+ ],
122
+ "/api/blogs": [
123
+ "GET"
124
+ ],
125
+ "/api/forms": [
126
+ "GET"
127
+ ],
128
+ "/api/auth": [
129
+ "GET",
130
+ "POST"
131
+ ],
132
+ "/api/health": [
133
+ "GET"
134
+ ],
135
+ "/api/users/forgot-password": [
136
+ "POST"
137
+ ],
138
+ "/api/users/set-password": [
139
+ "POST"
140
+ ],
141
+ "/api/users/invite": [
142
+ "POST"
143
+ ]
144
+ };
145
+ function legacyGetSessionToken(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
+ return secure ?? regular;
149
+ }
150
+ chunkUSNT2KNT_cjs.__name(legacyGetSessionToken, "legacyGetSessionToken");
151
+ function sessionCookiePresence(request) {
152
+ const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
153
+ const regular = request.cookies.get("next-auth.session-token")?.value;
154
+ const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
155
+ return {
156
+ hasSecureToken: Boolean(secure),
157
+ hasRegularToken: Boolean(regular),
158
+ hasChunkedToken: hasChunked,
159
+ resolved: Boolean(secure ?? regular)
160
+ };
161
+ }
162
+ chunkUSNT2KNT_cjs.__name(sessionCookiePresence, "sessionCookiePresence");
163
+ function isPublicMethod(pathname, method, publicApiMethods) {
164
+ for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
165
+ if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
166
+ }
167
+ return false;
168
+ }
169
+ chunkUSNT2KNT_cjs.__name(isPublicMethod, "isPublicMethod");
170
+ async function hasValidSession(request, secret, legacyGetToken) {
171
+ if (request.req) {
172
+ const token = await jwt.getToken({
173
+ req: request.req,
174
+ secret
175
+ });
176
+ return token != null;
177
+ }
178
+ return Boolean(legacyGetToken(request));
179
+ }
180
+ chunkUSNT2KNT_cjs.__name(hasValidSession, "hasValidSession");
181
+ function createCmsMiddleware(config = {}) {
182
+ const { publicAdminPaths = [
183
+ "/admin/signin",
184
+ "/admin/forgot-password",
185
+ "/admin/reset-password",
186
+ "/admin/invite"
187
+ ], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
188
+ return /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async function cmsMiddleware(request) {
189
+ const pathname = request.nextUrl.pathname;
190
+ const method = request.method;
191
+ if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
192
+ return {
193
+ type: "next"
194
+ };
195
+ }
196
+ if (pathname.startsWith("/admin")) {
197
+ const authenticated = await hasValidSession(request, secret, getSessionToken);
198
+ const cookies = sessionCookiePresence(request);
199
+ if (!authenticated) {
200
+ logAuth("middleware: admin redirect to signin (no session)", {
201
+ pathname,
202
+ method,
203
+ usesGetToken: Boolean(request.req),
204
+ ...cookies,
205
+ expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
206
+ });
207
+ return {
208
+ type: "redirect",
209
+ url: new URL(signInPath, request.url).toString()
210
+ };
211
+ }
212
+ logAuth("middleware: admin allowed", {
213
+ pathname,
214
+ method,
215
+ usesGetToken: Boolean(request.req),
216
+ ...cookies
217
+ });
218
+ }
219
+ if (pathname.startsWith("/api")) {
220
+ if (isPublicMethod(pathname, method, publicApiMethods)) {
221
+ return {
222
+ type: "next"
223
+ };
224
+ }
225
+ const authenticated = await hasValidSession(request, secret, getSessionToken);
226
+ if (!authenticated) {
227
+ logAuth("middleware: api 401 (no session)", {
228
+ pathname,
229
+ method,
230
+ usesGetToken: Boolean(request.req),
231
+ ...sessionCookiePresence(request)
232
+ });
233
+ return {
234
+ type: "json",
235
+ status: 401,
236
+ body: {
237
+ error: "Unauthorized"
238
+ }
239
+ };
240
+ }
241
+ }
242
+ return {
243
+ type: "next"
244
+ };
245
+ }, "cmsMiddleware");
246
+ }
247
+ chunkUSNT2KNT_cjs.__name(createCmsMiddleware, "createCmsMiddleware");
248
+ var CredentialsProvider = _CredentialsProvider__default.default.default ?? _CredentialsProvider__default.default;
249
+ function sessionUserFromNextAuthUser(user) {
250
+ const g = user.group;
251
+ const isRBACAdmin = chunk3KPNTQBV_cjs.isSuperAdmin({
252
+ groupId: user.groupId ?? void 0,
253
+ groupName: g?.name,
254
+ isRBACAdmin: false
255
+ });
256
+ const entityPerms = chunk3KPNTQBV_cjs.permissionRowsToRecord(g?.permissions);
257
+ const rawAdminAccess = user.adminAccess;
258
+ const adminAccess = rawAdminAccess === true ? true : rawAdminAccess === false ? false : void 0;
259
+ const vendorIds = user.vendorIds ?? [];
260
+ const vendorRole = user.vendorRole ?? null;
261
+ const isVendorRoleOwner = user.isVendorRoleOwner ?? false;
262
+ const { isVendorPortal, isVendorOwner: isVendorOwner2 } = chunk3KPNTQBV_cjs.vendorPortalFlagsFromUser({
263
+ email: user.email,
264
+ isRBACAdmin,
265
+ groupName: g?.name,
266
+ vendorIds,
267
+ vendorRole,
268
+ isVendorRoleOwner
269
+ });
270
+ return {
271
+ id: user.id.toString(),
272
+ email: user.email,
273
+ name: user.name,
274
+ groupId: user.groupId ?? void 0,
275
+ groupName: g?.name ?? void 0,
276
+ isRBACAdmin,
277
+ entityPerms,
278
+ adminAccess,
279
+ vendorIds,
280
+ activeVendorId: user.activeVendorId ?? vendorIds[0] ?? null,
281
+ vendorRole,
282
+ vendorRoleId: user.vendorRoleId ?? null,
283
+ vendorRoleName: user.vendorRoleName ?? null,
284
+ isVendorRoleOwner,
285
+ vendorEntityPerms: user.vendorEntityPerms,
286
+ isVendorPortal,
287
+ isVendorOwner: isVendorOwner2
288
+ };
289
+ }
290
+ chunkUSNT2KNT_cjs.__name(sessionUserFromNextAuthUser, "sessionUserFromNextAuthUser");
291
+ function isCustomerGroupUser(user) {
292
+ return user.group?.name?.toLocaleLowerCase().trim() === "customer";
293
+ }
294
+ chunkUSNT2KNT_cjs.__name(isCustomerGroupUser, "isCustomerGroupUser");
295
+ function callbackUrlTargetsAdmin(callbackUrl) {
296
+ const raw = callbackUrl.trim();
297
+ if (!raw) return false;
298
+ if (raw.startsWith("/admin")) return true;
299
+ try {
300
+ const path = raw.startsWith("http") ? new URL(raw).pathname : raw.split("?")[0] ?? raw;
301
+ return path.startsWith("/admin");
302
+ } catch {
303
+ return raw.includes("/admin");
304
+ }
305
+ }
306
+ chunkUSNT2KNT_cjs.__name(callbackUrlTargetsAdmin, "callbackUrlTargetsAdmin");
307
+ function permitsCustomerLogin(allowCustomerLogin, credentials) {
308
+ if (allowCustomerLogin === true) return true;
309
+ if (allowCustomerLogin === false) return false;
310
+ const callbackUrl = typeof credentials?.callbackUrl === "string" ? credentials.callbackUrl : "";
311
+ return !callbackUrlTargetsAdmin(callbackUrl);
312
+ }
313
+ chunkUSNT2KNT_cjs.__name(permitsCustomerLogin, "permitsCustomerLogin");
314
+ function getNextAuthOptions(config) {
315
+ const { getUserByEmail, comparePassword, signInPage = "/admin/signin", secret, extend, enablePasswordLogin = true, enableOtpLogin = false, authorizeOtp, allowCustomerLogin } = config;
316
+ logAuth("getNextAuthOptions init", nextAuthCookieDebugInfo());
317
+ const providers = [];
318
+ if (enablePasswordLogin) {
319
+ providers.push(CredentialsProvider({
320
+ name: "credentials",
321
+ credentials: {
322
+ email: {
323
+ label: "Email",
324
+ type: "email"
325
+ },
326
+ password: {
327
+ label: "Password",
328
+ type: "password"
329
+ }
330
+ },
331
+ async authorize(credentials) {
332
+ const creds = credentials;
333
+ const email = creds?.email?.trim() ?? "";
334
+ if (!email || !creds?.password) {
335
+ logAuth("authorize(credentials) rejected", {
336
+ reason: "missing_email_or_password"
337
+ });
338
+ return null;
339
+ }
340
+ try {
341
+ const user = await getUserByEmail(email);
342
+ if (!user) {
343
+ logAuth("authorize(credentials) rejected", {
344
+ reason: "user_not_found",
345
+ email
346
+ });
347
+ return null;
348
+ }
349
+ if (user.blocked) {
350
+ logAuth("authorize(credentials) rejected", {
351
+ reason: "blocked",
352
+ email,
353
+ userId: user.id
354
+ });
355
+ return null;
356
+ }
357
+ if (user.deleted) {
358
+ logAuth("authorize(credentials) rejected", {
359
+ reason: "deleted",
360
+ email,
361
+ userId: user.id
362
+ });
363
+ return null;
364
+ }
365
+ if (!user.password) {
366
+ logAuth("authorize(credentials) rejected", {
367
+ reason: "no_password",
368
+ email,
369
+ userId: user.id
370
+ });
371
+ return null;
372
+ }
373
+ const valid = await comparePassword(creds.password, user.password);
374
+ if (!valid) {
375
+ logAuth("authorize(credentials) rejected", {
376
+ reason: "invalid_password",
377
+ email,
378
+ userId: user.id
379
+ });
380
+ return null;
381
+ }
382
+ if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
383
+ logAuth("authorize(credentials) rejected", {
384
+ reason: "customer_group",
385
+ email,
386
+ userId: user.id,
387
+ callbackUrl: creds?.callbackUrl ?? null
388
+ });
389
+ return null;
390
+ }
391
+ const sessionUser = sessionUserFromNextAuthUser(user);
392
+ logAuth("authorize(credentials) ok", summarizeSessionUserForLog(sessionUser));
393
+ return sessionUser;
394
+ } catch (err) {
395
+ console.error("[cms-auth] authorize error (credentials):", err instanceof Error ? err.message : err);
396
+ logAuth("authorize(credentials) error", {
397
+ email,
398
+ message: err instanceof Error ? err.message : String(err)
399
+ });
400
+ return null;
401
+ }
402
+ }
403
+ }));
404
+ }
405
+ if (enableOtpLogin && authorizeOtp) {
406
+ providers.push(CredentialsProvider({
407
+ id: "otp",
408
+ name: "otp",
409
+ credentials: {
410
+ identifier: {
411
+ label: "Email or phone",
412
+ type: "text"
413
+ },
414
+ code: {
415
+ label: "Code",
416
+ type: "text"
417
+ },
418
+ channel: {
419
+ label: "Channel",
420
+ type: "text"
421
+ }
422
+ },
423
+ async authorize(credentials) {
424
+ const creds = credentials;
425
+ const identifier = typeof creds?.identifier === "string" ? creds.identifier.trim() : "";
426
+ const code = typeof creds?.code === "string" ? creds.code.trim() : "";
427
+ const ch = creds?.channel === "sms" ? "sms" : "email";
428
+ if (!identifier || !code) return null;
429
+ try {
430
+ const user = await authorizeOtp({
431
+ identifier,
432
+ channel: ch,
433
+ code
434
+ });
435
+ if (!user || user.blocked || user.deleted) return null;
436
+ if (isCustomerGroupUser(user) && !permitsCustomerLogin(allowCustomerLogin, creds)) {
437
+ logAuth("authorize(otp) rejected", {
438
+ reason: "customer_group",
439
+ identifier,
440
+ callbackUrl: creds?.callbackUrl ?? null
441
+ });
442
+ return null;
443
+ }
444
+ return sessionUserFromNextAuthUser(user);
445
+ } catch (err) {
446
+ console.error("[cms-auth] authorize error (otp):", err instanceof Error ? err.message : err);
447
+ return null;
448
+ }
449
+ }
450
+ }));
451
+ }
452
+ const options = {
453
+ secret: secret ?? process.env.NEXTAUTH_SECRET,
454
+ providers,
455
+ session: {
456
+ strategy: "jwt"
457
+ },
458
+ pages: {
459
+ signIn: signInPage
460
+ },
461
+ cookies: {
462
+ sessionToken: {
463
+ name: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token",
464
+ options: {
465
+ httpOnly: true,
466
+ sameSite: "lax",
467
+ path: "/",
468
+ secure: process.env.NEXTAUTH_URL?.startsWith("https") ?? false
469
+ }
470
+ }
471
+ },
472
+ callbacks: {
473
+ async jwt({ token, user, trigger, session }) {
474
+ if (user) {
475
+ logAuth("jwt callback: new sign-in", {
476
+ trigger,
477
+ user: summarizeSessionUserForLog(user)
478
+ });
479
+ const u = user;
480
+ token.id = u.id;
481
+ token.groupId = u.groupId;
482
+ token.groupName = u.groupName;
483
+ token.isRBACAdmin = u.isRBACAdmin;
484
+ token.entityPerms = u.entityPerms;
485
+ token.adminAccess = u.adminAccess;
486
+ token.vendorIds = u.vendorIds;
487
+ token.activeVendorId = u.activeVendorId;
488
+ token.vendorRole = u.vendorRole;
489
+ token.vendorRoleId = u.vendorRoleId;
490
+ token.vendorRoleName = u.vendorRoleName;
491
+ token.isVendorRoleOwner = u.isVendorRoleOwner;
492
+ token.vendorEntityPerms = u.vendorEntityPerms;
493
+ token.isVendorPortal = u.isVendorPortal;
494
+ token.isVendorOwner = u.isVendorOwner;
495
+ }
496
+ if (trigger === "update" && session && typeof session === "object") {
497
+ logAuth("jwt callback: session update", {
498
+ trigger
499
+ });
500
+ const s = session;
501
+ const t = token;
502
+ if (typeof s.name === "string") t.name = s.name;
503
+ if (typeof s.email === "string") t.email = s.email;
504
+ if (typeof s.activeVendorId === "number") t.activeVendorId = s.activeVendorId;
505
+ }
506
+ return token;
507
+ },
508
+ async session({ session, token }) {
509
+ const t = token;
510
+ logAuth("session callback", {
511
+ tokenHasId: t.id != null,
512
+ tokenEmail: typeof t.email === "string" ? t.email : null,
513
+ sessionUser: summarizeSessionUserForLog(session.user)
514
+ });
515
+ if (session.user) {
516
+ if (typeof t.name === "string") session.user.name = t.name;
517
+ if (typeof t.email === "string") session.user.email = t.email;
518
+ session.user.id = t.id;
519
+ session.user.groupId = t.groupId;
520
+ session.user.groupName = t.groupName;
521
+ session.user.isRBACAdmin = t.isRBACAdmin;
522
+ session.user.entityPerms = t.entityPerms;
523
+ session.user.adminAccess = t.adminAccess;
524
+ session.user.vendorIds = t.vendorIds;
525
+ session.user.activeVendorId = t.activeVendorId;
526
+ session.user.vendorRole = t.vendorRole;
527
+ session.user.vendorRoleId = t.vendorRoleId;
528
+ session.user.vendorRoleName = t.vendorRoleName;
529
+ session.user.isVendorRoleOwner = t.isVendorRoleOwner;
530
+ session.user.vendorEntityPerms = t.vendorEntityPerms;
531
+ session.user.isVendorPortal = t.isVendorPortal;
532
+ session.user.isVendorOwner = t.isVendorOwner;
533
+ }
534
+ return session;
535
+ }
536
+ }
537
+ };
538
+ return extend ? extend(options) : options;
539
+ }
540
+ chunkUSNT2KNT_cjs.__name(getNextAuthOptions, "getNextAuthOptions");
541
+ function getStorefrontNextAuthOptions(config) {
542
+ return getNextAuthOptions({
543
+ ...config,
544
+ allowCustomerLogin: true
545
+ });
546
+ }
547
+ chunkUSNT2KNT_cjs.__name(getStorefrontNextAuthOptions, "getStorefrontNextAuthOptions");
548
+
549
+ exports.createCmsMiddleware = createCmsMiddleware;
550
+ exports.defaultPublicApiMethods = defaultPublicApiMethods;
551
+ exports.getNextAuthOptions = getNextAuthOptions;
552
+ exports.getStorefrontNextAuthOptions = getStorefrontNextAuthOptions;
553
+ exports.isAuthDebugClientEnabled = isAuthDebugClientEnabled;
554
+ exports.isAuthDebugEnabled = isAuthDebugEnabled;
555
+ exports.logAuth = logAuth;
556
+ exports.logAuthClient = logAuthClient;
557
+ exports.nextAuthCookieDebugInfo = nextAuthCookieDebugInfo;
558
+ exports.seedAdministratorPermissions = seedAdministratorPermissions;
559
+ exports.summarizeSessionUserForLog = summarizeSessionUserForLog;
@@ -0,0 +1,16 @@
1
+ import { __name } from './chunk-SHUYVCID.js';
2
+
3
+ // src/message-templates/interpolate.ts
4
+ function applyTemplateVars(template, variables) {
5
+ let out = template;
6
+ for (const [k, v] of Object.entries(variables)) {
7
+ out = out.split(`{{${k}}}`).join(v);
8
+ }
9
+ if (variables.code !== void 0) {
10
+ out = out.split("{{otp}}").join(variables.code);
11
+ }
12
+ return out;
13
+ }
14
+ __name(applyTemplateVars, "applyTemplateVars");
15
+
16
+ export { applyTemplateVars };
@@ -0,0 +1,104 @@
1
+ 'use strict';
2
+
3
+ var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
4
+
5
+ // src/plugins/erp/erp-log.ts
6
+ var ERP_LOG = "[webcore:erp]";
7
+ function logErp(event, detail) {
8
+ if (detail && Object.keys(detail).length) console.info(ERP_LOG, event, detail);
9
+ else console.info(ERP_LOG, event);
10
+ }
11
+ chunkUSNT2KNT_cjs.__name(logErp, "logErp");
12
+ function warnErp(event, detail) {
13
+ console.warn(ERP_LOG, event, detail);
14
+ }
15
+ chunkUSNT2KNT_cjs.__name(warnErp, "warnErp");
16
+ function errorErp(event, detail) {
17
+ console.error(ERP_LOG, event, detail);
18
+ }
19
+ chunkUSNT2KNT_cjs.__name(errorErp, "errorErp");
20
+ function erpSafeWebhookUrl(url) {
21
+ try {
22
+ const u = new URL(url);
23
+ return `${u.origin}${u.pathname}`;
24
+ } catch {
25
+ return "(invalid webhook URL)";
26
+ }
27
+ }
28
+ chunkUSNT2KNT_cjs.__name(erpSafeWebhookUrl, "erpSafeWebhookUrl");
29
+
30
+ // src/plugins/erp/erp-queue.ts
31
+ var ERP_QUEUE_NAME = "erp";
32
+ function queuePayloadSummary(payload) {
33
+ if (payload.kind === "order") {
34
+ const o = payload.order;
35
+ return {
36
+ kind: payload.kind,
37
+ platformOrderId: o.platformOrderId ?? o.platformOrderNumber,
38
+ itemCount: Array.isArray(o.items) ? o.items.length : 0
39
+ };
40
+ }
41
+ return {
42
+ kind: payload.kind
43
+ };
44
+ }
45
+ chunkUSNT2KNT_cjs.__name(queuePayloadSummary, "queuePayloadSummary");
46
+ async function queueErp(cms, payload) {
47
+ const queue = cms.getPlugin("queue");
48
+ if (!queue) {
49
+ warnErp("queue:add_skipped", {
50
+ reason: "queue_plugin_missing",
51
+ ...queuePayloadSummary(payload)
52
+ });
53
+ return;
54
+ }
55
+ logErp("queue:add", {
56
+ job: ERP_QUEUE_NAME,
57
+ ...queuePayloadSummary(payload)
58
+ });
59
+ await queue.add(ERP_QUEUE_NAME, payload);
60
+ }
61
+ chunkUSNT2KNT_cjs.__name(queueErp, "queueErp");
62
+ function registerErpQueueProcessor(cms) {
63
+ const queue = cms.getPlugin("queue");
64
+ if (!queue) return;
65
+ queue.registerProcessor(ERP_QUEUE_NAME, async (data) => {
66
+ const erp = cms.getPlugin("erp");
67
+ if (!erp) {
68
+ warnErp("queue:processor_skip", {
69
+ reason: "erp_plugin_missing"
70
+ });
71
+ return;
72
+ }
73
+ const payload = data;
74
+ logErp("queue:job_start", queuePayloadSummary(payload));
75
+ try {
76
+ if (payload.kind === "lead") {
77
+ await erp.submission.submitContact(payload.contact);
78
+ } else if (payload.kind === "formOpportunity") {
79
+ await erp.submission.submitFormOpportunity(payload.contact);
80
+ } else if (payload.kind === "createContact") {
81
+ await erp.submission.submitCreateContact(payload.contact);
82
+ } else if (payload.kind === "order") {
83
+ await erp.submission.submitOrder(payload.order);
84
+ } else if (payload.kind === "productUpsert") {
85
+ await erp.submission.submitProductUpsert(payload.product);
86
+ }
87
+ logErp("queue:job_done", queuePayloadSummary(payload));
88
+ } catch (e) {
89
+ errorErp("queue:job_failed", {
90
+ ...queuePayloadSummary(payload),
91
+ message: e instanceof Error ? e.message : String(e)
92
+ });
93
+ throw e;
94
+ }
95
+ });
96
+ }
97
+ chunkUSNT2KNT_cjs.__name(registerErpQueueProcessor, "registerErpQueueProcessor");
98
+
99
+ exports.erpSafeWebhookUrl = erpSafeWebhookUrl;
100
+ exports.errorErp = errorErp;
101
+ exports.logErp = logErp;
102
+ exports.queueErp = queueErp;
103
+ exports.registerErpQueueProcessor = registerErpQueueProcessor;
104
+ exports.warnErp = warnErp;