@lastbrain/ai-ui-core 1.0.46 → 1.0.47
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enhanced-gateway.d.ts","sourceRoot":"","sources":["../../../src/route-handlers/nextjs/enhanced-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"enhanced-gateway.d.ts","sourceRoot":"","sources":["../../../src/route-handlers/nextjs/enhanced-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAiNxD,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,IAAI,CACxB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,GAAG,CACvB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAA;CAAE,8BAGjD"}
|
|
@@ -69,8 +69,7 @@ function mapAuthRouteToPublicRoute(path) {
|
|
|
69
69
|
return routeMappings[cleanPath];
|
|
70
70
|
}
|
|
71
71
|
// Try pattern matching with priority to longer/more specific patterns first
|
|
72
|
-
const sortedPatterns = Object.entries(routeMappings)
|
|
73
|
-
.sort(([a], [b]) => b.length - a.length); // Longer patterns first
|
|
72
|
+
const sortedPatterns = Object.entries(routeMappings).sort(([a], [b]) => b.length - a.length); // Longer patterns first
|
|
74
73
|
console.log(`[Enhanced Gateway] No exact match for "${cleanPath}", trying patterns...`);
|
|
75
74
|
for (const [pattern, target] of sortedPatterns) {
|
|
76
75
|
if (cleanPath.startsWith(pattern + "/") || cleanPath === pattern) {
|
|
@@ -99,22 +98,22 @@ async function handleRequest(request, context) {
|
|
|
99
98
|
console.log("[Enhanced Gateway] Bearer token:", LB_API_KEY ? `${LB_API_KEY.substring(0, 10)}...` : "MISSING");
|
|
100
99
|
try {
|
|
101
100
|
// Déterminer le type d'auth selon le path
|
|
102
|
-
const isAuthRoute = originalPath.startsWith(
|
|
101
|
+
const isAuthRoute = originalPath.startsWith("auth/") || mappedPath.startsWith("auth/");
|
|
103
102
|
const headers = {
|
|
104
103
|
"Content-Type": "application/json",
|
|
105
104
|
};
|
|
106
105
|
if (isAuthRoute) {
|
|
107
106
|
// Routes auth/* : forward les cookies de session
|
|
108
107
|
console.log("[Enhanced Gateway] Auth route - forwarding session cookies");
|
|
109
|
-
const cookies = request.headers.get(
|
|
108
|
+
const cookies = request.headers.get("cookie");
|
|
110
109
|
if (cookies) {
|
|
111
|
-
headers[
|
|
110
|
+
headers["Cookie"] = cookies;
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
else {
|
|
115
114
|
// Routes v1/* : utiliser LB_API_KEY
|
|
116
115
|
console.log("[Enhanced Gateway] API route - using LB_API_KEY");
|
|
117
|
-
headers[
|
|
116
|
+
headers["Authorization"] = `Bearer ${LB_API_KEY}`;
|
|
118
117
|
}
|
|
119
118
|
let body;
|
|
120
119
|
if (request.method === "POST" ||
|
|
@@ -132,7 +131,7 @@ async function handleRequest(request, context) {
|
|
|
132
131
|
method: request.method,
|
|
133
132
|
headers,
|
|
134
133
|
body,
|
|
135
|
-
credentials: isAuthRoute ?
|
|
134
|
+
credentials: isAuthRoute ? "include" : "omit", // Include cookies for auth routes
|
|
136
135
|
});
|
|
137
136
|
if (!response.ok) {
|
|
138
137
|
const errorText = await response.text();
|
package/package.json
CHANGED
|
@@ -29,7 +29,9 @@ function mapAuthRouteToPublicRoute(path: string): string {
|
|
|
29
29
|
// Remove leading 'ai/' if present (for routes like ai/auth/prompts)
|
|
30
30
|
const cleanPath = rawPath.startsWith("ai/") ? rawPath.slice(3) : rawPath;
|
|
31
31
|
|
|
32
|
-
console.log(
|
|
32
|
+
console.log(
|
|
33
|
+
`[Enhanced Gateway] Raw path: "${path}" -> Clean path: "${cleanPath}"`
|
|
34
|
+
);
|
|
33
35
|
|
|
34
36
|
// Route mapping: auth routes -> public routes (without api/public/v1 prefix)
|
|
35
37
|
const routeMappings: Record<string, string> = {
|
|
@@ -83,24 +85,33 @@ function mapAuthRouteToPublicRoute(path: string): string {
|
|
|
83
85
|
|
|
84
86
|
// Try exact match first
|
|
85
87
|
if (routeMappings[cleanPath]) {
|
|
86
|
-
console.log(
|
|
88
|
+
console.log(
|
|
89
|
+
`[Enhanced Gateway] Exact match: "${cleanPath}" -> "${routeMappings[cleanPath]}"`
|
|
90
|
+
);
|
|
87
91
|
return routeMappings[cleanPath];
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
// Try pattern matching with priority to longer/more specific patterns first
|
|
91
|
-
const sortedPatterns = Object.entries(routeMappings)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
const sortedPatterns = Object.entries(routeMappings).sort(
|
|
96
|
+
([a], [b]) => b.length - a.length
|
|
97
|
+
); // Longer patterns first
|
|
98
|
+
|
|
99
|
+
console.log(
|
|
100
|
+
`[Enhanced Gateway] No exact match for "${cleanPath}", trying patterns...`
|
|
101
|
+
);
|
|
95
102
|
for (const [pattern, target] of sortedPatterns) {
|
|
96
103
|
if (cleanPath.startsWith(pattern + "/") || cleanPath === pattern) {
|
|
97
|
-
console.log(
|
|
104
|
+
console.log(
|
|
105
|
+
`[Enhanced Gateway] Pattern match: "${pattern}" -> "${target}"`
|
|
106
|
+
);
|
|
98
107
|
return target + cleanPath.slice(pattern.length);
|
|
99
108
|
}
|
|
100
109
|
}
|
|
101
110
|
|
|
102
111
|
// Fallback: return clean path as-is
|
|
103
|
-
console.log(
|
|
112
|
+
console.log(
|
|
113
|
+
`[Enhanced Gateway] No pattern match, using fallback: "${cleanPath}"`
|
|
114
|
+
);
|
|
104
115
|
return cleanPath;
|
|
105
116
|
}
|
|
106
117
|
|
|
@@ -135,8 +146,9 @@ async function handleRequest(
|
|
|
135
146
|
|
|
136
147
|
try {
|
|
137
148
|
// Déterminer le type d'auth selon le path
|
|
138
|
-
const isAuthRoute =
|
|
139
|
-
|
|
149
|
+
const isAuthRoute =
|
|
150
|
+
originalPath.startsWith("auth/") || mappedPath.startsWith("auth/");
|
|
151
|
+
|
|
140
152
|
const headers: HeadersInit = {
|
|
141
153
|
"Content-Type": "application/json",
|
|
142
154
|
};
|
|
@@ -144,14 +156,14 @@ async function handleRequest(
|
|
|
144
156
|
if (isAuthRoute) {
|
|
145
157
|
// Routes auth/* : forward les cookies de session
|
|
146
158
|
console.log("[Enhanced Gateway] Auth route - forwarding session cookies");
|
|
147
|
-
const cookies = request.headers.get(
|
|
159
|
+
const cookies = request.headers.get("cookie");
|
|
148
160
|
if (cookies) {
|
|
149
|
-
headers[
|
|
161
|
+
headers["Cookie"] = cookies;
|
|
150
162
|
}
|
|
151
163
|
} else {
|
|
152
164
|
// Routes v1/* : utiliser LB_API_KEY
|
|
153
165
|
console.log("[Enhanced Gateway] API route - using LB_API_KEY");
|
|
154
|
-
headers[
|
|
166
|
+
headers["Authorization"] = `Bearer ${LB_API_KEY}`;
|
|
155
167
|
}
|
|
156
168
|
|
|
157
169
|
let body: string | undefined;
|
|
@@ -172,7 +184,7 @@ async function handleRequest(
|
|
|
172
184
|
method: request.method,
|
|
173
185
|
headers,
|
|
174
186
|
body,
|
|
175
|
-
credentials: isAuthRoute ?
|
|
187
|
+
credentials: isAuthRoute ? "include" : "omit", // Include cookies for auth routes
|
|
176
188
|
});
|
|
177
189
|
|
|
178
190
|
if (!response.ok) {
|