@egdesk/next-api-plugin 1.5.112 → 1.5.114
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.
- package/dist/generate-middleware.js +17 -1
- package/dist/generate-proxy.js +17 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -84,6 +84,17 @@ import type { NextRequest } from 'next/server';
|
|
|
84
84
|
*/
|
|
85
85
|
|
|
86
86
|
/** Forward this site's origin so EGDesk can bind visitor sessions to this site only. */
|
|
87
|
+
function resolveBrowserClientIpForMcp(request: NextRequest): string | undefined {
|
|
88
|
+
const xff = request.headers.get('x-forwarded-for');
|
|
89
|
+
if (xff) {
|
|
90
|
+
const first = xff.split(',')[0]?.trim();
|
|
91
|
+
if (first) return first;
|
|
92
|
+
}
|
|
93
|
+
const realIp = request.headers.get('x-real-ip');
|
|
94
|
+
if (realIp?.trim()) return realIp.trim();
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
87
98
|
function visitorUpstreamHeaders(request: NextRequest): Record<string, string> {
|
|
88
99
|
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
89
100
|
const origin = request.headers.get('origin') || request.nextUrl.origin;
|
|
@@ -93,6 +104,8 @@ function visitorUpstreamHeaders(request: NextRequest): Record<string, string> {
|
|
|
93
104
|
'X-Visitor-Origin': origin,
|
|
94
105
|
};
|
|
95
106
|
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
107
|
+
const clientIp = resolveBrowserClientIpForMcp(request);
|
|
108
|
+
if (clientIp) headers['X-EGDesk-Visitor-Client-Ip'] = clientIp;
|
|
96
109
|
return headers;
|
|
97
110
|
}
|
|
98
111
|
|
|
@@ -492,7 +505,10 @@ export async function middleware(request: NextRequest) {
|
|
|
492
505
|
body,
|
|
493
506
|
});
|
|
494
507
|
const result = await response.json();
|
|
495
|
-
|
|
508
|
+
const outHeaders: Record<string, string> = {};
|
|
509
|
+
const retryAfter = response.headers.get('retry-after');
|
|
510
|
+
if (retryAfter) outHeaders['Retry-After'] = retryAfter;
|
|
511
|
+
return NextResponse.json(result, { status: response.status, headers: outHeaders });
|
|
496
512
|
} catch (error: any) {
|
|
497
513
|
return NextResponse.json(
|
|
498
514
|
{ error: 'Proxy error', message: error.message },
|
package/dist/generate-proxy.js
CHANGED
|
@@ -137,12 +137,25 @@ function visitorAuthToolFromProxyBody(body: string): string {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
+
function resolveBrowserClientIpForMcp(request: NextRequest): string | undefined {
|
|
141
|
+
const xff = request.headers.get('x-forwarded-for');
|
|
142
|
+
if (xff) {
|
|
143
|
+
const first = xff.split(',')[0]?.trim();
|
|
144
|
+
if (first) return first;
|
|
145
|
+
}
|
|
146
|
+
const realIp = request.headers.get('x-real-ip');
|
|
147
|
+
if (realIp?.trim()) return realIp.trim();
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
140
151
|
/** Forward this site's origin so EGDesk can bind visitor sessions to this site only. */
|
|
141
152
|
function visitorForwardHeaders(request: NextRequest): Record<string, string> {
|
|
142
153
|
const headers = buildEgdeskHeaders();
|
|
143
154
|
const origin = request.headers.get('origin') || request.nextUrl.origin;
|
|
144
155
|
headers['Origin'] = origin;
|
|
145
156
|
headers['X-Visitor-Origin'] = origin;
|
|
157
|
+
const clientIp = resolveBrowserClientIpForMcp(request);
|
|
158
|
+
if (clientIp) headers['X-EGDesk-Visitor-Client-Ip'] = clientIp;
|
|
146
159
|
return headers;
|
|
147
160
|
}
|
|
148
161
|
|
|
@@ -846,8 +859,11 @@ export async function proxy(request: NextRequest) {
|
|
|
846
859
|
});
|
|
847
860
|
|
|
848
861
|
const result = await response.json();
|
|
862
|
+
const outHeaders: Record<string, string> = {};
|
|
863
|
+
const retryAfter = response.headers.get('retry-after');
|
|
864
|
+
if (retryAfter) outHeaders['Retry-After'] = retryAfter;
|
|
849
865
|
|
|
850
|
-
return NextResponse.json(result, { status: response.status });
|
|
866
|
+
return NextResponse.json(result, { status: response.status, headers: outHeaders });
|
|
851
867
|
} catch (error: any) {
|
|
852
868
|
return NextResponse.json(
|
|
853
869
|
{ error: 'Proxy error', message: error.message },
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
9
9
|
* The app checks this at setup time and warns on mismatch.
|
|
10
10
|
*/
|
|
11
|
-
export declare const COMPATIBLE_APP_VERSION = "1.4.
|
|
11
|
+
export declare const COMPATIBLE_APP_VERSION = "1.4.119";
|
|
12
12
|
export interface SetupOptions {
|
|
13
13
|
egdeskUrl?: string;
|
|
14
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ exports.setupNextApiPlugin = setupNextApiPlugin;
|
|
|
46
46
|
* The minimum EGDesk app version this plugin version is compatible with.
|
|
47
47
|
* The app checks this at setup time and warns on mismatch.
|
|
48
48
|
*/
|
|
49
|
-
exports.COMPATIBLE_APP_VERSION = '1.4.
|
|
49
|
+
exports.COMPATIBLE_APP_VERSION = '1.4.119';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|