@infuro/cms-core 1.0.50 → 1.0.52

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 (31) hide show
  1. package/dist/admin.cjs +843 -402
  2. package/dist/admin.d.cts +13 -1
  3. package/dist/admin.d.ts +13 -1
  4. package/dist/admin.js +843 -402
  5. package/dist/api.cjs +35 -35
  6. package/dist/api.js +4 -4
  7. package/dist/auth.cjs +44 -43
  8. package/dist/auth.d.cts +2 -3
  9. package/dist/auth.d.ts +2 -3
  10. package/dist/auth.js +2 -1
  11. package/dist/{chunk-JCMOOPNX.cjs → chunk-3BPD5NGU.cjs} +210 -90
  12. package/dist/chunk-7L6KWI7S.cjs +212 -0
  13. package/dist/{chunk-YV5PK4JW.cjs → chunk-BC22I7C7.cjs} +45 -247
  14. package/dist/{chunk-WRKV6MHB.js → chunk-BNKZNLEX.js} +2 -196
  15. package/dist/{chunk-IPDHT2UV.js → chunk-CTXBYO2J.js} +94 -104
  16. package/dist/{chunk-UUWAUHUW.cjs → chunk-JN4AFHZ4.cjs} +94 -105
  17. package/dist/{chunk-JE22VP6S.js → chunk-MXIWUFBP.js} +1 -1
  18. package/dist/{chunk-LT2WOPKA.js → chunk-UO5Q5RXB.js} +181 -61
  19. package/dist/{chunk-KOTXDSQB.cjs → chunk-UQWZUZ5X.cjs} +1 -1
  20. package/dist/chunk-WUQAOTHA.js +203 -0
  21. package/dist/{emit-order-notification-trigger-6XX7LSC4.js → emit-order-notification-trigger-HZQPPSFB.js} +1 -1
  22. package/dist/{emit-order-notification-trigger-NASG7ZEO.cjs → emit-order-notification-trigger-NR3VN6C6.cjs} +3 -3
  23. package/dist/index.cjs +334 -299
  24. package/dist/index.d.cts +6 -4
  25. package/dist/index.d.ts +6 -4
  26. package/dist/index.js +59 -24
  27. package/dist/middleware.cjs +15 -0
  28. package/dist/middleware.js +2 -0
  29. package/dist/{order-notification-dispatcher-3TA4ETYJ.js → order-notification-dispatcher-AT4IFAGL.js} +2 -2
  30. package/dist/{order-notification-dispatcher-ZEAZ5SHV.cjs → order-notification-dispatcher-YBAWDOIO.cjs} +5 -5
  31. package/package.json +6 -1
@@ -0,0 +1,212 @@
1
+ 'use strict';
2
+
3
+ var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
4
+
5
+ // src/auth/auth-debug.ts
6
+ var LOG_PREFIX = "[cms-auth]";
7
+ function isAuthDebugEnabled() {
8
+ const v = process.env.CMS_AUTH_DEBUG?.trim().toLowerCase();
9
+ return v === "1" || v === "true" || v === "yes";
10
+ }
11
+ chunkUSNT2KNT_cjs.__name(isAuthDebugEnabled, "isAuthDebugEnabled");
12
+ function isAuthDebugClientEnabled() {
13
+ if (typeof window === "undefined") return false;
14
+ const v = process.env.NEXT_PUBLIC_CMS_AUTH_DEBUG?.trim().toLowerCase();
15
+ return v === "1" || v === "true" || v === "yes";
16
+ }
17
+ chunkUSNT2KNT_cjs.__name(isAuthDebugClientEnabled, "isAuthDebugClientEnabled");
18
+ function logAuth(message, data) {
19
+ if (!isAuthDebugEnabled()) return;
20
+ if (data) console.info(LOG_PREFIX, message, data);
21
+ else console.info(LOG_PREFIX, message);
22
+ }
23
+ chunkUSNT2KNT_cjs.__name(logAuth, "logAuth");
24
+ function logAuthClient(message, data) {
25
+ if (!isAuthDebugClientEnabled()) return;
26
+ if (data) console.info(LOG_PREFIX, message, data);
27
+ else console.info(LOG_PREFIX, message);
28
+ }
29
+ chunkUSNT2KNT_cjs.__name(logAuthClient, "logAuthClient");
30
+ function summarizeSessionUserForLog(user) {
31
+ if (!user || typeof user !== "object") return {
32
+ present: false
33
+ };
34
+ const u = user;
35
+ return {
36
+ present: true,
37
+ email: u.email ?? null,
38
+ id: u.id ?? null,
39
+ adminAccess: u.adminAccess ?? null,
40
+ isRBACAdmin: u.isRBACAdmin ?? null,
41
+ isVendorPortal: u.isVendorPortal ?? null,
42
+ groupName: u.groupName ?? null
43
+ };
44
+ }
45
+ chunkUSNT2KNT_cjs.__name(summarizeSessionUserForLog, "summarizeSessionUserForLog");
46
+ function nextAuthCookieDebugInfo() {
47
+ const nextAuthUrl = process.env.NEXTAUTH_URL ?? "(unset)";
48
+ const isHttps = nextAuthUrl.startsWith("https");
49
+ return {
50
+ nextAuthUrl,
51
+ hasSecret: Boolean(process.env.NEXTAUTH_SECRET),
52
+ cookieName: isHttps ? "__Secure-next-auth.session-token" : "next-auth.session-token",
53
+ cookieSecure: isHttps,
54
+ nodeEnv: process.env.NODE_ENV ?? "(unset)"
55
+ };
56
+ }
57
+ chunkUSNT2KNT_cjs.__name(nextAuthCookieDebugInfo, "nextAuthCookieDebugInfo");
58
+
59
+ // src/auth/middleware.ts
60
+ var defaultPublicApiMethods = {
61
+ "/api/contacts": [
62
+ "POST"
63
+ ],
64
+ "/api/form-submissions": [
65
+ "POST"
66
+ ],
67
+ "/api/blogs": [
68
+ "GET"
69
+ ],
70
+ "/api/forms": [
71
+ "GET"
72
+ ],
73
+ "/api/auth": [
74
+ "GET",
75
+ "POST"
76
+ ],
77
+ "/api/health": [
78
+ "GET"
79
+ ],
80
+ "/api/users/forgot-password": [
81
+ "POST"
82
+ ],
83
+ "/api/users/set-password": [
84
+ "POST"
85
+ ],
86
+ "/api/users/invite": [
87
+ "GET",
88
+ "POST"
89
+ ],
90
+ /** Public keys only (e.g. googleEnabled); secrets stay private in the settings handler. */
91
+ "/api/settings/auth_providers": [
92
+ "GET"
93
+ ]
94
+ };
95
+ function legacyGetSessionToken(request) {
96
+ const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
97
+ const regular = request.cookies.get("next-auth.session-token")?.value;
98
+ return secure ?? regular;
99
+ }
100
+ chunkUSNT2KNT_cjs.__name(legacyGetSessionToken, "legacyGetSessionToken");
101
+ function sessionCookiePresence(request) {
102
+ const secure = request.cookies.get("__Secure-next-auth.session-token")?.value;
103
+ const regular = request.cookies.get("next-auth.session-token")?.value;
104
+ const hasChunked = Boolean(request.cookies.get("next-auth.session-token.0")?.value) || Boolean(request.cookies.get("__Secure-next-auth.session-token.0")?.value);
105
+ return {
106
+ hasSecureToken: Boolean(secure),
107
+ hasRegularToken: Boolean(regular),
108
+ hasChunkedToken: hasChunked,
109
+ resolved: Boolean(secure ?? regular ?? hasChunked)
110
+ };
111
+ }
112
+ chunkUSNT2KNT_cjs.__name(sessionCookiePresence, "sessionCookiePresence");
113
+ function isPublicMethod(pathname, method, publicApiMethods) {
114
+ for (const [endpoint, methods] of Object.entries(publicApiMethods)) {
115
+ if (pathname.startsWith(endpoint) && methods.includes(method)) return true;
116
+ }
117
+ return false;
118
+ }
119
+ chunkUSNT2KNT_cjs.__name(isPublicMethod, "isPublicMethod");
120
+ async function hasValidSession(request, secret, legacyGetToken) {
121
+ const presence = sessionCookiePresence(request);
122
+ if (presence.resolved || presence.hasChunkedToken) return true;
123
+ if (request.req) {
124
+ try {
125
+ const { getToken } = await import('next-auth/jwt');
126
+ const token = await getToken({
127
+ req: request.req,
128
+ secret
129
+ });
130
+ if (token != null) return true;
131
+ } catch {
132
+ }
133
+ }
134
+ return Boolean(legacyGetToken(request));
135
+ }
136
+ chunkUSNT2KNT_cjs.__name(hasValidSession, "hasValidSession");
137
+ function createCmsMiddleware(config = {}) {
138
+ const { publicAdminPaths = [
139
+ "/admin/signin",
140
+ "/admin/forgot-password",
141
+ "/admin/reset-password",
142
+ "/admin/invite"
143
+ ], publicApiMethods = defaultPublicApiMethods, signInPath = "/admin/signin", getSessionToken = legacyGetSessionToken, secret = process.env.NEXTAUTH_SECRET } = config;
144
+ return /* @__PURE__ */ chunkUSNT2KNT_cjs.__name(async function cmsMiddleware(request) {
145
+ const pathname = request.nextUrl.pathname;
146
+ const method = request.method;
147
+ if (publicAdminPaths.some((p) => pathname === p || pathname.startsWith(p + "/"))) {
148
+ return {
149
+ type: "next"
150
+ };
151
+ }
152
+ if (pathname.startsWith("/admin")) {
153
+ const authenticated = await hasValidSession(request, secret, getSessionToken);
154
+ const cookies = sessionCookiePresence(request);
155
+ if (!authenticated) {
156
+ logAuth("middleware: admin redirect to signin (no session)", {
157
+ pathname,
158
+ method,
159
+ usesGetToken: Boolean(request.req),
160
+ ...cookies,
161
+ expectedCookieName: process.env.NEXTAUTH_URL?.startsWith("https") ? "__Secure-next-auth.session-token" : "next-auth.session-token"
162
+ });
163
+ return {
164
+ type: "redirect",
165
+ url: new URL(signInPath, request.url).toString()
166
+ };
167
+ }
168
+ logAuth("middleware: admin allowed", {
169
+ pathname,
170
+ method,
171
+ usesGetToken: Boolean(request.req),
172
+ ...cookies
173
+ });
174
+ }
175
+ if (pathname.startsWith("/api")) {
176
+ if (isPublicMethod(pathname, method, publicApiMethods)) {
177
+ return {
178
+ type: "next"
179
+ };
180
+ }
181
+ const authenticated = await hasValidSession(request, secret, getSessionToken);
182
+ if (!authenticated) {
183
+ logAuth("middleware: api 401 (no session)", {
184
+ pathname,
185
+ method,
186
+ usesGetToken: Boolean(request.req),
187
+ ...sessionCookiePresence(request)
188
+ });
189
+ return {
190
+ type: "json",
191
+ status: 401,
192
+ body: {
193
+ error: "Unauthorized"
194
+ }
195
+ };
196
+ }
197
+ }
198
+ return {
199
+ type: "next"
200
+ };
201
+ }, "cmsMiddleware");
202
+ }
203
+ chunkUSNT2KNT_cjs.__name(createCmsMiddleware, "createCmsMiddleware");
204
+
205
+ exports.createCmsMiddleware = createCmsMiddleware;
206
+ exports.defaultPublicApiMethods = defaultPublicApiMethods;
207
+ exports.isAuthDebugClientEnabled = isAuthDebugClientEnabled;
208
+ exports.isAuthDebugEnabled = isAuthDebugEnabled;
209
+ exports.logAuth = logAuth;
210
+ exports.logAuthClient = logAuthClient;
211
+ exports.nextAuthCookieDebugInfo = nextAuthCookieDebugInfo;
212
+ exports.summarizeSessionUserForLog = summarizeSessionUserForLog;