@egdesk/next-api-plugin 1.5.77 → 1.5.84
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/README.md +6 -4
- package/dist/cli.js +1 -1
- package/dist/generate-helpers.js +21 -0
- package/dist/generate-visitor-auth.js +107 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ This will generate:
|
|
|
37
37
|
- `app/auth/callback/page.tsx` - Exchanges EGDesk’s one-time login code (**generated — do not edit**)
|
|
38
38
|
- `.env.local` - Environment variables (`NEXT_PUBLIC_EGDESK_*` only — no Supabase keys)
|
|
39
39
|
|
|
40
|
-
Add `{EGDesk public URL}/visitor-auth/callback
|
|
40
|
+
Add `{EGDesk public URL}/visitor-auth/callback/**` to the EGDesk Supabase Auth redirect allowlist (once per EGDesk/tunnel origin, not each published site). The pending login id is a path segment so concurrent visitors do not share one in-memory slot.
|
|
41
41
|
|
|
42
42
|
2. Add `.env.local` to your `.gitignore` (if not already there)
|
|
43
43
|
|
|
@@ -75,10 +75,12 @@ Published sites do **not** receive `SUPABASE_URL` or the anon key. Visitor Googl
|
|
|
75
75
|
|
|
76
76
|
Add the **EGDesk** callback (not each site origin) to **Supabase → Authentication → URL Configuration → Redirect URLs**:
|
|
77
77
|
|
|
78
|
-
- Local: `http://localhost:54321/auth/callback`
|
|
79
|
-
- Tunnel: `https://tunneling-service.onrender.com/t/{tunnelId}/visitor-auth/callback
|
|
78
|
+
- Local (owner and localhost visitor): `http://localhost:54321/auth/callback` exactly. Do not add a path or `?vid=` — Supabase will fall back to the Site URL (`egdesk.cloud`).
|
|
79
|
+
- Tunnel: `https://tunneling-service.onrender.com/t/{tunnelId}/visitor-auth/callback/**` or `https://tunneling-service.onrender.com/**`
|
|
80
80
|
|
|
81
|
-
Do not
|
|
81
|
+
Do not put the pending id in a query string (`?vid=`) — extra query params make Supabase fall back to the Site URL (`egdesk.cloud`).
|
|
82
|
+
|
|
83
|
+
On a published host, `NEXT_PUBLIC_EGDESK_API_URL` must be the tunnel MCP root (`https://…/t/{id}`), not `http://localhost:8080`. The generated helper will refuse that localhost fallback in the browser.
|
|
82
84
|
|
|
83
85
|
Owner MCP (`startDriveAuthLogin`) is a separate credential on the EGDesk machine. Visitor login does not overwrite it.
|
|
84
86
|
|
package/dist/cli.js
CHANGED
|
@@ -37,7 +37,7 @@ async function main() {
|
|
|
37
37
|
console.log(' --help, -h Show this help message');
|
|
38
38
|
console.log('');
|
|
39
39
|
console.log('Visitor Google sign-in is brokered by EGDesk (no Supabase keys on the site).');
|
|
40
|
-
console.log('Add {EGDesk public URL}/visitor-auth/callback to the Supabase Auth redirect allowlist.');
|
|
40
|
+
console.log('Add {EGDesk public URL}/visitor-auth/callback/** to the Supabase Auth redirect allowlist.');
|
|
41
41
|
console.log('');
|
|
42
42
|
console.log('Example:');
|
|
43
43
|
console.log(' egdesk-next-setup --url http://localhost:8080 --api-key mykey');
|
package/dist/generate-helpers.js
CHANGED
|
@@ -1937,6 +1937,27 @@ export async function runBrowserRecording(
|
|
|
1937
1937
|
});
|
|
1938
1938
|
}
|
|
1939
1939
|
|
|
1940
|
+
/** Indexed actions for a saved recording (use upToActionIndex with playBrowserRecordingUpTo) */
|
|
1941
|
+
export async function listBrowserRecordingActions(testFile: string) {
|
|
1942
|
+
return callBrowserRecordingTool('browser_recording_list_actions', { testFile });
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
/**
|
|
1946
|
+
* Replay through upToActionIndex, keep Chrome open as a live session, then
|
|
1947
|
+
* inspect/click/fill and saveBrowserRecordingSession to write a new recording.
|
|
1948
|
+
*/
|
|
1949
|
+
export async function playBrowserRecordingUpTo(
|
|
1950
|
+
testFile: string,
|
|
1951
|
+
upToActionIndex: number,
|
|
1952
|
+
options: BrowserRecordingRunOptions = {}
|
|
1953
|
+
) {
|
|
1954
|
+
return callBrowserRecordingTool('browser_recording_play_up_to', {
|
|
1955
|
+
testFile,
|
|
1956
|
+
upToActionIndex,
|
|
1957
|
+
...options,
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1940
1961
|
/** List Playwright scheduler entries for browser recorder tests */
|
|
1941
1962
|
export async function listBrowserRecordingSchedules() {
|
|
1942
1963
|
return callBrowserRecordingTool('browser_recording_list_schedules', {});
|
|
@@ -113,15 +113,28 @@ export default function VisitorAuthCallbackPage() {
|
|
|
113
113
|
setMessage('Missing login code. Close this page and try Sign in with Google again.');
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
|
+
let finished = false;
|
|
117
|
+
const timer = window.setTimeout(() => {
|
|
118
|
+
if (finished) return;
|
|
119
|
+
finished = true;
|
|
120
|
+
setMessage('Sign-in timed out. Close this page and try Sign in with Google again.');
|
|
121
|
+
}, 20000);
|
|
116
122
|
void exchangeVisitorAuthCode(code)
|
|
117
123
|
.then(() => {
|
|
124
|
+
if (finished) return;
|
|
125
|
+
finished = true;
|
|
126
|
+
window.clearTimeout(timer);
|
|
118
127
|
const dest = resolveVisitorAppPath(next.startsWith('/') ? next : '/');
|
|
119
128
|
window.location.replace(dest);
|
|
120
129
|
})
|
|
121
130
|
.catch((err: unknown) => {
|
|
131
|
+
if (finished) return;
|
|
132
|
+
finished = true;
|
|
133
|
+
window.clearTimeout(timer);
|
|
122
134
|
const text = err instanceof Error ? err.message : String(err);
|
|
123
135
|
setMessage('Sign-in failed: ' + text);
|
|
124
136
|
});
|
|
137
|
+
return () => window.clearTimeout(timer);
|
|
125
138
|
}, []);
|
|
126
139
|
|
|
127
140
|
return (
|
|
@@ -274,20 +287,98 @@ export function resolveVisitorAppPath(path: string): string {
|
|
|
274
287
|
return base + normalized;
|
|
275
288
|
}
|
|
276
289
|
|
|
277
|
-
|
|
290
|
+
function isLoopbackHostname(hostname: string): boolean {
|
|
291
|
+
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function isPrivateLanHostname(hostname: string): boolean {
|
|
295
|
+
const match = hostname.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);
|
|
296
|
+
if (!match) return false;
|
|
297
|
+
const a = Number(match[1]);
|
|
298
|
+
const b = Number(match[2]);
|
|
299
|
+
if (a === 10) return true;
|
|
300
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
301
|
+
if (a === 192 && b === 168) return true;
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function isDevSiteHostname(hostname: string): boolean {
|
|
306
|
+
return isLoopbackHostname(hostname) || isPrivateLanHostname(hostname);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function isLocalEgdeskUrl(value: string): boolean {
|
|
310
|
+
try {
|
|
311
|
+
return isLoopbackHostname(new URL(value).hostname);
|
|
312
|
+
} catch {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function isTunnelMcpRoot(value: string): boolean {
|
|
318
|
+
try {
|
|
319
|
+
const parsed = new URL(value);
|
|
320
|
+
return (
|
|
321
|
+
parsed.hostname === 'tunneling-service.onrender.com' ||
|
|
322
|
+
parsed.hostname.endsWith('.egdesk.cloud') ||
|
|
323
|
+
/\\/t\\/[^/]+/.test(parsed.pathname)
|
|
324
|
+
);
|
|
325
|
+
} catch {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* MCP root used as the Google/Supabase OAuth bounce.
|
|
332
|
+
* Published hosts must never silently fall back to http://localhost:8080.
|
|
333
|
+
*/
|
|
278
334
|
export function resolveEgdeskPublicUrl(): string {
|
|
279
|
-
const configured =
|
|
335
|
+
const configured = (
|
|
280
336
|
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
281
|
-
'
|
|
282
|
-
|
|
337
|
+
''
|
|
338
|
+
).replace(/\\/$/, '');
|
|
339
|
+
const tunnelUrl = (
|
|
340
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_TUNNEL_URL) ||
|
|
341
|
+
''
|
|
342
|
+
).replace(/\\/$/, '');
|
|
343
|
+
const preferred = configured || tunnelUrl;
|
|
344
|
+
|
|
345
|
+
if (typeof window === 'undefined') {
|
|
346
|
+
return preferred || 'http://localhost:8080';
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const hostname = window.location.hostname;
|
|
283
350
|
const parts = window.location.pathname.split('/').filter(Boolean);
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
351
|
+
const onTunnelPath = parts[0] === 't' && Boolean(parts[1]);
|
|
352
|
+
const onKnownGateway =
|
|
353
|
+
hostname === 'tunneling-service.onrender.com' || hostname.endsWith('.egdesk.cloud');
|
|
354
|
+
|
|
355
|
+
if (onTunnelPath && (onKnownGateway || !isLoopbackHostname(hostname))) {
|
|
288
356
|
return window.location.origin + '/t/' + parts[1];
|
|
289
357
|
}
|
|
290
|
-
|
|
358
|
+
|
|
359
|
+
if (isDevSiteHostname(hostname)) {
|
|
360
|
+
if (isPrivateLanHostname(hostname) && preferred && isTunnelMcpRoot(preferred)) {
|
|
361
|
+
return preferred;
|
|
362
|
+
}
|
|
363
|
+
if (isLoopbackHostname(hostname)) {
|
|
364
|
+
return preferred || 'http://localhost:8080';
|
|
365
|
+
}
|
|
366
|
+
if (preferred && !isLocalEgdeskUrl(preferred)) {
|
|
367
|
+
return preferred;
|
|
368
|
+
}
|
|
369
|
+
throw new Error(
|
|
370
|
+
'Visitor Google login from a LAN IP requires NEXT_PUBLIC_EGDESK_API_URL to be the tunnel MCP root (https://…/t/{id}).',
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (preferred && !isLocalEgdeskUrl(preferred)) {
|
|
375
|
+
return preferred;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
console.error(
|
|
379
|
+
'[egdesk-visitor-google] NEXT_PUBLIC_EGDESK_API_URL is missing or points at localhost on a published host. Using window.location.origin for the OAuth bounce.',
|
|
380
|
+
);
|
|
381
|
+
return window.location.origin;
|
|
291
382
|
}
|
|
292
383
|
|
|
293
384
|
async function callVisitorAuth(tool: string, args: Record<string, unknown> = {}) {
|
|
@@ -336,8 +427,14 @@ export async function startVisitorGoogleLogin(options: {
|
|
|
336
427
|
);
|
|
337
428
|
const returnTo = new URL(resolveVisitorAppPath('/auth/callback'), window.location.origin);
|
|
338
429
|
returnTo.searchParams.set('next', next);
|
|
339
|
-
// Localhost →
|
|
430
|
+
// Localhost → allowlisted http://localhost:54321/auth/callback.
|
|
431
|
+
// Tunnel / custom domain → {MCP root}/visitor-auth/callback/{pendingId}.
|
|
340
432
|
const egdeskPublicUrl = resolveEgdeskPublicUrl();
|
|
433
|
+
if (isLocalEgdeskUrl(egdeskPublicUrl) && !isDevSiteHostname(window.location.hostname)) {
|
|
434
|
+
throw new Error(
|
|
435
|
+
'Visitor Google login cannot use a localhost EGDesk URL from a published site. Set NEXT_PUBLIC_EGDESK_API_URL to the tunnel MCP root (https://…/t/{id}).',
|
|
436
|
+
);
|
|
437
|
+
}
|
|
341
438
|
const scopes = resolveVisitorLoginScopes(options.scopes);
|
|
342
439
|
|
|
343
440
|
const result = await callVisitorAuth('start', {
|
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.89";
|
|
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.89';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
@@ -205,7 +205,7 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
205
205
|
console.log('');
|
|
206
206
|
console.log('📝 Next steps:');
|
|
207
207
|
console.log(' 1. Add .env.*.local to your .gitignore');
|
|
208
|
-
console.log(' 2. Add this EGDesk public URL + /visitor-auth/callback to Supabase Auth redirect URLs');
|
|
208
|
+
console.log(' 2. Add this EGDesk public URL + /visitor-auth/callback/** to Supabase Auth redirect URLs');
|
|
209
209
|
console.log(' (once per EGDesk/tunnel origin — not each published site)');
|
|
210
210
|
console.log(' Visitor sessions are bound to each site origin and cannot be reused across sites');
|
|
211
211
|
console.log(' 3. Restart your Next.js dev server');
|