@egdesk/next-api-plugin 1.5.77 → 1.5.86
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 +19 -4
- package/dist/cli.js +1 -1
- package/dist/generate-helpers.js +21 -0
- package/dist/generate-visitor-auth.js +127 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -3
- 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,25 @@ 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 loopback 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
|
+
### OAuth bounce by site type
|
|
84
|
+
|
|
85
|
+
| Where the visitor opens the site | Google `redirectTo` (allowlisted) |
|
|
86
|
+
|----------------------------------|-----------------------------------|
|
|
87
|
+
| `localhost` / `127.0.0.1` (:4000 dev, :3000 prod) | `http://localhost:54321/auth/callback` |
|
|
88
|
+
| LAN IP (`192.168.x.x`, etc.) + tunnel env | `{tunnel MCP root}/visitor-auth/callback/{pendingId}` |
|
|
89
|
+
| LAN IP, no tunnel (same PC as EGDesk only) | `http://localhost:54321/auth/callback` |
|
|
90
|
+
| Tunnel URL or custom domain | `{MCP root}/visitor-auth/callback/{pendingId}` |
|
|
91
|
+
|
|
92
|
+
Hosted-coding **prod** (`:3000`) is built with `basePath` `/t/{tunnelId}/p/{project}` — use that prefix in URLs (e.g. `http://localhost:3000/t/{id}/p/my-app/visitor-auth`). EGDesk injects `NEXT_PUBLIC_EGDESK_API_URL` and `NEXT_PUBLIC_EGDESK_API_KEY` at build and `next start` so the client bundle and middleware proxy agree.
|
|
93
|
+
|
|
94
|
+
`localhost` and `127.0.0.1` on the same port are treated as the same site for session checks, but remain distinct origin strings in storage.
|
|
95
|
+
|
|
96
|
+
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 on non-dev hosts.
|
|
82
97
|
|
|
83
98
|
Owner MCP (`startDriveAuthLogin`) is a separate credential on the EGDesk machine. Visitor login does not overwrite it.
|
|
84
99
|
|
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 (
|
|
@@ -156,6 +169,20 @@ const VISITOR_HELPERS = `/**
|
|
|
156
169
|
* The opaque session is bound to this site origin and will not work on
|
|
157
170
|
* another published site that shares the same EGDesk.
|
|
158
171
|
*
|
|
172
|
+
* OAuth bounce (where Google redirects before returning to this site):
|
|
173
|
+
*
|
|
174
|
+
* | Where you open the site | Google redirectTo |
|
|
175
|
+
* |--------------------------------------|-------------------------------------------|
|
|
176
|
+
* | localhost / 127.0.0.1 (:4000/:3000) | http://localhost:54321/auth/callback |
|
|
177
|
+
* | LAN IP (192.168.x.x) + tunnel env | {tunnel}/visitor-auth/callback/{pendingId}|
|
|
178
|
+
* | LAN IP, no tunnel (same PC only) | http://localhost:54321/auth/callback |
|
|
179
|
+
* | Render / egdesk.cloud tunnel URL | {MCP root}/t/{id}/visitor-auth/callback/{id}|
|
|
180
|
+
* | Custom domain (yourdomain.com) | https://{domain}/visitor-auth/callback/{id} |
|
|
181
|
+
*
|
|
182
|
+
* Prod hosted coding (:3000) is built with basePath /t/{id}/p/{project}.
|
|
183
|
+
* Use that prefix in URLs. EGDesk injects NEXT_PUBLIC_EGDESK_API_URL at build/start.
|
|
184
|
+
* localhost and 127.0.0.1 on the same port count as the same site for session checks.
|
|
185
|
+
*
|
|
159
186
|
* Generated by @egdesk/next-api-plugin — do not edit.
|
|
160
187
|
* Customize login UI in your pages. Set default scopes in egdesk.visitor-auth.ts
|
|
161
188
|
* or pass startVisitorGoogleLogin({ scopes: VISITOR_BASIC_SCOPES }).
|
|
@@ -274,20 +301,105 @@ export function resolveVisitorAppPath(path: string): string {
|
|
|
274
301
|
return base + normalized;
|
|
275
302
|
}
|
|
276
303
|
|
|
277
|
-
|
|
304
|
+
function isLoopbackHostname(hostname: string): boolean {
|
|
305
|
+
return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function isPrivateLanHostname(hostname: string): boolean {
|
|
309
|
+
const match = hostname.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);
|
|
310
|
+
if (!match) return false;
|
|
311
|
+
const a = Number(match[1]);
|
|
312
|
+
const b = Number(match[2]);
|
|
313
|
+
if (a === 10) return true;
|
|
314
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
315
|
+
if (a === 192 && b === 168) return true;
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function isDevSiteHostname(hostname: string): boolean {
|
|
320
|
+
return isLoopbackHostname(hostname) || isPrivateLanHostname(hostname);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function isLocalEgdeskUrl(value: string): boolean {
|
|
324
|
+
try {
|
|
325
|
+
return isLoopbackHostname(new URL(value).hostname);
|
|
326
|
+
} catch {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function isTunnelMcpRoot(value: string): boolean {
|
|
332
|
+
try {
|
|
333
|
+
const parsed = new URL(value);
|
|
334
|
+
return (
|
|
335
|
+
parsed.hostname === 'tunneling-service.onrender.com' ||
|
|
336
|
+
parsed.hostname.endsWith('.egdesk.cloud') ||
|
|
337
|
+
/\\/t\\/[^/]+/.test(parsed.pathname)
|
|
338
|
+
);
|
|
339
|
+
} catch {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* MCP root passed to visitor-auth start (egdeskPublicUrl).
|
|
346
|
+
*
|
|
347
|
+
* - Loopback dev → configured URL or http://localhost:8080 (OAuth still bounces via :54321).
|
|
348
|
+
* - LAN IP → tunnel MCP root from NEXT_PUBLIC_EGDESK_API_URL / _TUNNEL_URL (required).
|
|
349
|
+
* - Tunnel/custom domain → tunnel MCP root; never window.location.origin on dev/LAN hosts.
|
|
350
|
+
*
|
|
351
|
+
* Published hosts must never silently fall back to http://localhost:8080.
|
|
352
|
+
*/
|
|
278
353
|
export function resolveEgdeskPublicUrl(): string {
|
|
279
|
-
const configured =
|
|
354
|
+
const configured = (
|
|
280
355
|
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
281
|
-
'
|
|
282
|
-
|
|
356
|
+
''
|
|
357
|
+
).replace(/\\/$/, '');
|
|
358
|
+
const tunnelUrl = (
|
|
359
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_TUNNEL_URL) ||
|
|
360
|
+
''
|
|
361
|
+
).replace(/\\/$/, '');
|
|
362
|
+
const preferred = configured || tunnelUrl;
|
|
363
|
+
|
|
364
|
+
if (typeof window === 'undefined') {
|
|
365
|
+
return preferred || 'http://localhost:8080';
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const hostname = window.location.hostname;
|
|
283
369
|
const parts = window.location.pathname.split('/').filter(Boolean);
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
370
|
+
const onTunnelPath = parts[0] === 't' && Boolean(parts[1]);
|
|
371
|
+
const onKnownGateway =
|
|
372
|
+
hostname === 'tunneling-service.onrender.com' || hostname.endsWith('.egdesk.cloud');
|
|
373
|
+
|
|
374
|
+
// Only the Render/egdesk.cloud gateway uses /t/{id} in the OAuth bounce path.
|
|
375
|
+
// Custom domains (sheetbot.cloud) bounce at {origin}/visitor-auth/callback/{id} — no /t/ prefix.
|
|
376
|
+
if (onTunnelPath && onKnownGateway) {
|
|
288
377
|
return window.location.origin + '/t/' + parts[1];
|
|
289
378
|
}
|
|
290
|
-
|
|
379
|
+
|
|
380
|
+
if (isDevSiteHostname(hostname)) {
|
|
381
|
+
if (isPrivateLanHostname(hostname) && preferred && isTunnelMcpRoot(preferred)) {
|
|
382
|
+
return preferred;
|
|
383
|
+
}
|
|
384
|
+
if (isLoopbackHostname(hostname)) {
|
|
385
|
+
return preferred || 'http://localhost:8080';
|
|
386
|
+
}
|
|
387
|
+
if (preferred && !isLocalEgdeskUrl(preferred)) {
|
|
388
|
+
return preferred;
|
|
389
|
+
}
|
|
390
|
+
throw new Error(
|
|
391
|
+
'Visitor Google login from a LAN IP requires NEXT_PUBLIC_EGDESK_API_URL to be the tunnel MCP root (https://…/t/{id}).',
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if (preferred && !isLocalEgdeskUrl(preferred)) {
|
|
396
|
+
return preferred;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
console.error(
|
|
400
|
+
'[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.',
|
|
401
|
+
);
|
|
402
|
+
return window.location.origin;
|
|
291
403
|
}
|
|
292
404
|
|
|
293
405
|
async function callVisitorAuth(tool: string, args: Record<string, unknown> = {}) {
|
|
@@ -336,8 +448,13 @@ export async function startVisitorGoogleLogin(options: {
|
|
|
336
448
|
);
|
|
337
449
|
const returnTo = new URL(resolveVisitorAppPath('/auth/callback'), window.location.origin);
|
|
338
450
|
returnTo.searchParams.set('next', next);
|
|
339
|
-
//
|
|
451
|
+
// OAuth bounce is chosen server-side from returnTo + egdeskPublicUrl — see file header table.
|
|
340
452
|
const egdeskPublicUrl = resolveEgdeskPublicUrl();
|
|
453
|
+
if (isLocalEgdeskUrl(egdeskPublicUrl) && !isDevSiteHostname(window.location.hostname)) {
|
|
454
|
+
throw new Error(
|
|
455
|
+
'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}).',
|
|
456
|
+
);
|
|
457
|
+
}
|
|
341
458
|
const scopes = resolveVisitorLoginScopes(options.scopes);
|
|
342
459
|
|
|
343
460
|
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.91";
|
|
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.91';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
@@ -205,8 +205,10 @@ 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.
|
|
209
|
-
console.log('
|
|
208
|
+
console.log(' 2. Supabase Auth redirect URLs (once per EGDesk/tunnel origin):');
|
|
209
|
+
console.log(' - http://localhost:54321/auth/callback (exact — loopback hosted-coding + owner)');
|
|
210
|
+
console.log(' - {EGDesk public URL}/visitor-auth/callback/** (tunnel / LAN IP with tunnel env)');
|
|
211
|
+
console.log(' Loopback → :54321; LAN IP or tunnel → /visitor-auth/callback/{pendingId} (see egdesk-visitor-google.ts header)');
|
|
210
212
|
console.log(' Visitor sessions are bound to each site origin and cannot be reused across sites');
|
|
211
213
|
console.log(' 3. Restart your Next.js dev server');
|
|
212
214
|
console.log(' 4. Import and use helpers in your components:');
|