@egdesk/next-api-plugin 1.5.110 → 1.5.112
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 +22 -1
- package/dist/generate-proxy.js +22 -1
- package/dist/generate-visitor-auth.js +40 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -138,6 +138,27 @@ function resolveVisitorAuthMcpApiUrl(): string {
|
|
|
138
138
|
return 'http://localhost:8080';
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/** Phase 7b visitor BYO tools must hit desktop MCP (secrets), not the tunnel gateway. */
|
|
142
|
+
const VISITOR_AUTH_DESKTOP_ONLY_TOOLS = new Set(['register_gcp', 'gcp_status', 'forget_gcp']);
|
|
143
|
+
|
|
144
|
+
function resolveVisitorAuthMcpApiUrlForTool(tool: string): string {
|
|
145
|
+
if (VISITOR_AUTH_DESKTOP_ONLY_TOOLS.has(tool)) {
|
|
146
|
+
const internal = process.env.EGDESK_MCP_INTERNAL_URL;
|
|
147
|
+
if (internal && internal.trim()) return internal.replace(/\\/$/, '');
|
|
148
|
+
return 'http://localhost:8080';
|
|
149
|
+
}
|
|
150
|
+
return resolveVisitorAuthMcpApiUrl();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function visitorAuthToolFromProxyBody(body: string): string {
|
|
154
|
+
try {
|
|
155
|
+
const parsed = JSON.parse(body) as { tool?: string; op?: string };
|
|
156
|
+
return String(parsed.tool || parsed.op || '').trim();
|
|
157
|
+
} catch {
|
|
158
|
+
return '';
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
141
162
|
export async function middleware(request: NextRequest) {
|
|
142
163
|
const { pathname } = request.nextUrl;
|
|
143
164
|
|
|
@@ -463,7 +484,7 @@ export async function middleware(request: NextRequest) {
|
|
|
463
484
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
464
485
|
try {
|
|
465
486
|
const body = await request.text();
|
|
466
|
-
const apiUrl =
|
|
487
|
+
const apiUrl = resolveVisitorAuthMcpApiUrlForTool(visitorAuthToolFromProxyBody(body));
|
|
467
488
|
|
|
468
489
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
469
490
|
method: 'POST',
|
package/dist/generate-proxy.js
CHANGED
|
@@ -116,6 +116,27 @@ function resolveVisitorAuthMcpApiUrl(): string {
|
|
|
116
116
|
return 'http://localhost:8080';
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/** Phase 7b visitor BYO tools must hit desktop MCP (secrets), not the tunnel gateway. */
|
|
120
|
+
const VISITOR_AUTH_DESKTOP_ONLY_TOOLS = new Set(['register_gcp', 'gcp_status', 'forget_gcp']);
|
|
121
|
+
|
|
122
|
+
function resolveVisitorAuthMcpApiUrlForTool(tool: string): string {
|
|
123
|
+
if (VISITOR_AUTH_DESKTOP_ONLY_TOOLS.has(tool)) {
|
|
124
|
+
const internal = process.env.EGDESK_MCP_INTERNAL_URL;
|
|
125
|
+
if (internal && internal.trim()) return internal.replace(/\\/$/, '');
|
|
126
|
+
return 'http://localhost:8080';
|
|
127
|
+
}
|
|
128
|
+
return resolveVisitorAuthMcpApiUrl();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function visitorAuthToolFromProxyBody(body: string): string {
|
|
132
|
+
try {
|
|
133
|
+
const parsed = JSON.parse(body) as { tool?: string; op?: string };
|
|
134
|
+
return String(parsed.tool || parsed.op || '').trim();
|
|
135
|
+
} catch {
|
|
136
|
+
return '';
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
119
140
|
/** Forward this site's origin so EGDesk can bind visitor sessions to this site only. */
|
|
120
141
|
function visitorForwardHeaders(request: NextRequest): Record<string, string> {
|
|
121
142
|
const headers = buildEgdeskHeaders();
|
|
@@ -816,7 +837,7 @@ export async function proxy(request: NextRequest) {
|
|
|
816
837
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
817
838
|
try {
|
|
818
839
|
const body = await request.text();
|
|
819
|
-
const apiUrl =
|
|
840
|
+
const apiUrl = resolveVisitorAuthMcpApiUrlForTool(visitorAuthToolFromProxyBody(body));
|
|
820
841
|
|
|
821
842
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
822
843
|
method: 'POST',
|
|
@@ -84,6 +84,45 @@ function removeIfExists(filePath) {
|
|
|
84
84
|
console.warn(`⚠️ Could not remove ${filePath}:`, error);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
+
/** site-origin mode (HANDOFF §9.2): Google redirects to the operator custom domain. */
|
|
88
|
+
const VISITOR_AUTH_CALLBACK_ROUTE = `import { NextRequest, NextResponse } from 'next/server';
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Proxies operator/end-user direct OAuth callbacks to desktop MCP.
|
|
92
|
+
* Generated by @egdesk/next-api-plugin — do not edit.
|
|
93
|
+
*/
|
|
94
|
+
function resolveEgdeskMcpInternalUrl(): string {
|
|
95
|
+
const internal = process.env.EGDESK_MCP_INTERNAL_URL;
|
|
96
|
+
if (internal && internal.trim()) return internal.replace(/\\/$/, '');
|
|
97
|
+
return 'http://localhost:8080';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function GET(request: NextRequest) {
|
|
101
|
+
const internal = resolveEgdeskMcpInternalUrl();
|
|
102
|
+
const incoming = new URL(request.url);
|
|
103
|
+
const target = new URL(\`\${internal}/visitor-auth/callback\`);
|
|
104
|
+
target.search = incoming.search;
|
|
105
|
+
const origin = request.headers.get('origin') || incoming.origin;
|
|
106
|
+
const response = await fetch(target.toString(), {
|
|
107
|
+
method: 'GET',
|
|
108
|
+
redirect: 'manual',
|
|
109
|
+
headers: {
|
|
110
|
+
Origin: origin,
|
|
111
|
+
'X-Visitor-Origin': origin,
|
|
112
|
+
},
|
|
113
|
+
cache: 'no-store',
|
|
114
|
+
});
|
|
115
|
+
const location = response.headers.get('location');
|
|
116
|
+
if (response.status >= 300 && response.status < 400 && location) {
|
|
117
|
+
return NextResponse.redirect(location, response.status);
|
|
118
|
+
}
|
|
119
|
+
const text = await response.text();
|
|
120
|
+
return new NextResponse(text, {
|
|
121
|
+
status: response.status,
|
|
122
|
+
headers: { 'Content-Type': response.headers.get('content-type') || 'text/html; charset=utf-8' },
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
87
126
|
const CALLBACK_PAGE = `'use client';
|
|
88
127
|
|
|
89
128
|
/**
|
|
@@ -709,6 +748,7 @@ function generateVisitorAuth(projectPath) {
|
|
|
709
748
|
const appDir = resolveAppDir(projectPath);
|
|
710
749
|
ensureVisitorAuthConfig(projectPath);
|
|
711
750
|
writeGenerated(path.join(appDir, 'auth', 'callback', 'page.tsx'), CALLBACK_PAGE);
|
|
751
|
+
writeGenerated(path.join(appDir, 'visitor-auth', 'callback', 'route.ts'), VISITOR_AUTH_CALLBACK_ROUTE);
|
|
712
752
|
writeGenerated(path.join(projectPath, 'egdesk-visitor-google.ts'), VISITOR_HELPERS);
|
|
713
753
|
writeGenerated(path.join(projectPath, 'egdesk-visitor-gcp-byo.tsx'), VISITOR_GCP_BYO_COMPONENT);
|
|
714
754
|
removeIfExists(path.join(appDir, 'api', 'visitor-google', 'route.ts'));
|
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.117";
|
|
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.117';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|