@egdesk/next-api-plugin 1.5.28 → 1.5.32
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 +2 -2
- package/dist/generate-middleware.js +16 -7
- package/dist/generate-proxy.js +11 -2
- package/dist/generate-visitor-auth.js +9 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ NEXT_PUBLIC_EGDESK_API_URL=http://localhost:8080
|
|
|
70
70
|
NEXT_PUBLIC_EGDESK_API_KEY=your-api-key-here
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
Published sites do **not** receive `SUPABASE_URL` or the anon key. Visitor Google sign-in is brokered by EGDesk: the site redirects through `{EGDESK_API}/visitor-auth`, EGDesk creates an Auth user, and the site stores an opaque session id.
|
|
73
|
+
Published sites do **not** receive `SUPABASE_URL` or the anon key. Visitor Google sign-in is brokered by EGDesk: the site redirects through `{EGDESK_API}/visitor-auth`, EGDesk creates an Auth user, and the site stores an opaque session id bound to **this site's origin**. Another published site on the same EGDesk cannot reuse that session.
|
|
74
74
|
|
|
75
75
|
Add the **EGDesk** callback (not each site origin) to **Supabase → Authentication → URL Configuration → Redirect URLs**, e.g. `http://localhost:8080/visitor-auth/callback` (and the tunnel URL in production).
|
|
76
76
|
|
|
@@ -170,7 +170,7 @@ getVisitorSheetRange(spreadsheetId, range)
|
|
|
170
170
|
| Who | Helper | Identity |
|
|
171
171
|
|-----|--------|----------|
|
|
172
172
|
| EGDesk owner | `startDriveAuthLogin()` | Owner token for this machine’s MCP (Drive watch, sync) |
|
|
173
|
-
| Website visitor | `startVisitorGoogleLogin()` from `egdesk-visitor-google.ts` | EGDesk Auth user (login brokered by EGDesk; opaque session
|
|
173
|
+
| Website visitor | `startVisitorGoogleLogin()` from `egdesk-visitor-google.ts` | EGDesk Auth user (login brokered by EGDesk; opaque session bound to this site origin) |
|
|
174
174
|
|
|
175
175
|
Visitors **are** EGDesk Auth users. They are not the MCP owner. The published site never holds Supabase credentials; RLS still limits each user to their own token row on EGDesk.
|
|
176
176
|
|
|
@@ -79,6 +79,20 @@ import type { NextRequest } from 'next/server';
|
|
|
79
79
|
*
|
|
80
80
|
* Generated by @egdesk/next-api-plugin
|
|
81
81
|
*/
|
|
82
|
+
|
|
83
|
+
/** Forward this site's origin so EGDesk can bind visitor sessions to this site only. */
|
|
84
|
+
function visitorUpstreamHeaders(request: NextRequest): Record<string, string> {
|
|
85
|
+
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
86
|
+
const origin = request.headers.get('origin') || request.nextUrl.origin;
|
|
87
|
+
const headers: Record<string, string> = {
|
|
88
|
+
'Content-Type': 'application/json',
|
|
89
|
+
Origin: origin,
|
|
90
|
+
'X-Visitor-Origin': origin,
|
|
91
|
+
};
|
|
92
|
+
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
93
|
+
return headers;
|
|
94
|
+
}
|
|
95
|
+
|
|
82
96
|
export async function middleware(request: NextRequest) {
|
|
83
97
|
const { pathname } = request.nextUrl;
|
|
84
98
|
|
|
@@ -353,14 +367,11 @@ export async function middleware(request: NextRequest) {
|
|
|
353
367
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
354
368
|
try {
|
|
355
369
|
const body = await request.text();
|
|
356
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
357
370
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
358
|
-
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
359
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
360
371
|
|
|
361
372
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
362
373
|
method: 'POST',
|
|
363
|
-
headers,
|
|
374
|
+
headers: visitorUpstreamHeaders(request),
|
|
364
375
|
body,
|
|
365
376
|
});
|
|
366
377
|
const result = await response.json();
|
|
@@ -376,10 +387,8 @@ export async function middleware(request: NextRequest) {
|
|
|
376
387
|
if (pathname.includes('__visitor_google_proxy')) {
|
|
377
388
|
try {
|
|
378
389
|
const body = await request.text();
|
|
379
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
380
390
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
381
|
-
const headers
|
|
382
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
391
|
+
const headers = visitorUpstreamHeaders(request);
|
|
383
392
|
const authorization = request.headers.get('authorization');
|
|
384
393
|
if (authorization) headers['Authorization'] = authorization;
|
|
385
394
|
|
package/dist/generate-proxy.js
CHANGED
|
@@ -93,6 +93,15 @@ function buildEgdeskHeaders(): Record<string, string> {
|
|
|
93
93
|
return headers;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/** Forward this site's origin so EGDesk can bind visitor sessions to this site only. */
|
|
97
|
+
function visitorForwardHeaders(request: NextRequest): Record<string, string> {
|
|
98
|
+
const headers = buildEgdeskHeaders();
|
|
99
|
+
const origin = request.headers.get('origin') || request.nextUrl.origin;
|
|
100
|
+
headers['Origin'] = origin;
|
|
101
|
+
headers['X-Visitor-Origin'] = origin;
|
|
102
|
+
return headers;
|
|
103
|
+
}
|
|
104
|
+
|
|
96
105
|
export async function proxy(request: NextRequest) {
|
|
97
106
|
const { pathname } = request.nextUrl;
|
|
98
107
|
|
|
@@ -614,7 +623,7 @@ export async function proxy(request: NextRequest) {
|
|
|
614
623
|
|
|
615
624
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
616
625
|
method: 'POST',
|
|
617
|
-
headers:
|
|
626
|
+
headers: visitorForwardHeaders(request),
|
|
618
627
|
body,
|
|
619
628
|
});
|
|
620
629
|
|
|
@@ -633,7 +642,7 @@ export async function proxy(request: NextRequest) {
|
|
|
633
642
|
try {
|
|
634
643
|
const body = await request.text();
|
|
635
644
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
636
|
-
const headers =
|
|
645
|
+
const headers = visitorForwardHeaders(request);
|
|
637
646
|
const authorization = request.headers.get('authorization');
|
|
638
647
|
if (authorization) headers['Authorization'] = authorization;
|
|
639
648
|
|
|
@@ -131,6 +131,8 @@ const VISITOR_HELPERS = `/**
|
|
|
131
131
|
*
|
|
132
132
|
* Visitors become EGDesk Auth users. Login is brokered by EGDesk so this
|
|
133
133
|
* site never receives SUPABASE_URL or the anon key.
|
|
134
|
+
* The opaque session is bound to this site origin and will not work on
|
|
135
|
+
* another published site that shares the same EGDesk.
|
|
134
136
|
*
|
|
135
137
|
* Import this file only from pages that need visitor Google.
|
|
136
138
|
*
|
|
@@ -172,10 +174,15 @@ async function parseEgdeskJson(response: Response): Promise<any> {
|
|
|
172
174
|
return result;
|
|
173
175
|
}
|
|
174
176
|
|
|
177
|
+
function visitorOriginHeaders(): Record<string, string> {
|
|
178
|
+
if (typeof window === 'undefined') return {};
|
|
179
|
+
return { 'X-Visitor-Origin': window.location.origin };
|
|
180
|
+
}
|
|
181
|
+
|
|
175
182
|
async function callVisitorAuth(tool: string, args: Record<string, unknown> = {}) {
|
|
176
183
|
const response = await apiFetch('/__visitor_auth_proxy', {
|
|
177
184
|
method: 'POST',
|
|
178
|
-
headers: { 'Content-Type': 'application/json' },
|
|
185
|
+
headers: { 'Content-Type': 'application/json', ...visitorOriginHeaders() },
|
|
179
186
|
body: JSON.stringify({ tool, arguments: args }),
|
|
180
187
|
});
|
|
181
188
|
return parseEgdeskJson(response);
|
|
@@ -191,6 +198,7 @@ async function callVisitorGoogle(tool: string, args: Record<string, unknown> = {
|
|
|
191
198
|
headers: {
|
|
192
199
|
'Content-Type': 'application/json',
|
|
193
200
|
Authorization: \`Bearer \${sessionId}\`,
|
|
201
|
+
...visitorOriginHeaders(),
|
|
194
202
|
},
|
|
195
203
|
body: JSON.stringify({ tool, arguments: args }),
|
|
196
204
|
});
|
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.45";
|
|
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.45';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
@@ -206,6 +206,7 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
206
206
|
console.log(' 1. Add .env.*.local to your .gitignore');
|
|
207
207
|
console.log(' 2. Add this EGDesk public URL + /visitor-auth/callback to Supabase Auth redirect URLs');
|
|
208
208
|
console.log(' (once per EGDesk/tunnel origin — not each published site)');
|
|
209
|
+
console.log(' Visitor sessions are bound to each site origin and cannot be reused across sites');
|
|
209
210
|
console.log(' 3. Restart your Next.js dev server');
|
|
210
211
|
console.log(' 4. Import and use helpers in your components:');
|
|
211
212
|
console.log(' import { queryTable } from "./egdesk-helpers"');
|