@egdesk/next-api-plugin 1.5.56 → 1.5.57
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 +18 -4
- package/dist/generate-helpers.js +92 -136
- package/dist/generate-middleware.js +25 -24
- package/dist/generate-proxy.js +24 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,7 +116,21 @@ export const VISITOR_AUTH = {
|
|
|
116
116
|
};
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
`NEXT_PUBLIC_EGDESK_VISITOR_SCOPES=basic|workspace` overrides that file.
|
|
119
|
+
`NEXT_PUBLIC_EGDESK_VISITOR_SCOPES=basic|workspace` overrides that file. You can also pass any Google scopes to `startVisitorGoogleLogin({ scopes })`. Identity scopes are always included. Older helpers that send no scopes still get workspace (previous default).
|
|
120
|
+
|
|
121
|
+
To use those visitor credentials on Workspace MCP (Sheets / Drive / Docs / Slides / Gmail / Apps Script), pass `{ asVisitor: true }` to the helper. Owner credentials stay the default.
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { callSheetsTool, getSheetRange } from './egdesk-helpers';
|
|
125
|
+
|
|
126
|
+
// Owner EGDesk credentials (default)
|
|
127
|
+
await getSheetRange(spreadsheetId, 'Sheet1!A1:B2');
|
|
128
|
+
|
|
129
|
+
// Website visitor from startVisitorGoogleLogin()
|
|
130
|
+
await callSheetsTool('sheets_get_range', { spreadsheetId, range: 'Sheet1!A1:B2' }, { asVisitor: true });
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Watch / sync / `drive_auth_login` stay owner-only even with `asVisitor`.
|
|
120
134
|
|
|
121
135
|
### Custom Setup
|
|
122
136
|
|
|
@@ -214,10 +228,10 @@ getVisitorSheetRange(spreadsheetId, range)
|
|
|
214
228
|
|
|
215
229
|
| Who | Helper | Identity |
|
|
216
230
|
|-----|--------|----------|
|
|
217
|
-
| EGDesk owner | `startDriveAuthLogin()` | Owner token for this machine’s MCP (Drive watch, sync) |
|
|
218
|
-
| Website visitor | `startVisitorGoogleLogin()`
|
|
231
|
+
| EGDesk owner | `startDriveAuthLogin()` / `callSheetsTool()` (default) | Owner token for this machine’s MCP (Drive watch, sync) |
|
|
232
|
+
| Website visitor | `startVisitorGoogleLogin()` then `callSheetsTool(..., { asVisitor: true })` | Opaque visitor session (brokered by EGDesk; bound to this site origin) |
|
|
219
233
|
|
|
220
|
-
Visitors **are** EGDesk Auth users. They are not the MCP owner
|
|
234
|
+
Visitors **are** EGDesk Auth users. They are not the MCP owner unless you opt in with `asVisitor`. The published site never holds Supabase credentials or Google tokens.
|
|
221
235
|
|
|
222
236
|
### Configuration Types
|
|
223
237
|
|
package/dist/generate-helpers.js
CHANGED
|
@@ -211,6 +211,76 @@ function buildServerEgdeskHeaders(): Record<string, string> {
|
|
|
211
211
|
return headers;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
+
const VISITOR_SESSION_KEY = 'egdesk_visitor_session';
|
|
215
|
+
|
|
216
|
+
export type WorkspaceVisitorCallOptions = {
|
|
217
|
+
asVisitor?: boolean;
|
|
218
|
+
visitorSessionId?: string;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
function getBrowserVisitorSessionId(): string | null {
|
|
222
|
+
if (typeof window === 'undefined') return null;
|
|
223
|
+
return window.localStorage.getItem(VISITOR_SESSION_KEY);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function buildWorkspaceVisitorHeaders(options: WorkspaceVisitorCallOptions = {}): Record<string, string> {
|
|
227
|
+
const headers: Record<string, string> = {};
|
|
228
|
+
if (!options.asVisitor) return headers;
|
|
229
|
+
const sessionId = options.visitorSessionId || getBrowserVisitorSessionId();
|
|
230
|
+
if (!sessionId) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
'asVisitor is set but no visitor session is available. Call startVisitorGoogleLogin() first, or pass visitorSessionId on the server.',
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
headers['Authorization'] = \`Bearer \${sessionId}\`;
|
|
236
|
+
headers['X-EGDesk-As-Visitor'] = 'true';
|
|
237
|
+
if (typeof window !== 'undefined') {
|
|
238
|
+
headers['X-Visitor-Origin'] = window.location.origin;
|
|
239
|
+
}
|
|
240
|
+
return headers;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function withVisitorToolArgs(
|
|
244
|
+
args: Record<string, any>,
|
|
245
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
246
|
+
): Record<string, any> {
|
|
247
|
+
if (!options.asVisitor) return args;
|
|
248
|
+
return { ...args, asVisitor: true };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function callWorkspaceMcpTool(
|
|
252
|
+
path: string,
|
|
253
|
+
proxyPath: string,
|
|
254
|
+
toolName: string,
|
|
255
|
+
args: Record<string, any> = {},
|
|
256
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
257
|
+
): Promise<any> {
|
|
258
|
+
const body = JSON.stringify({
|
|
259
|
+
tool: toolName,
|
|
260
|
+
arguments: withVisitorToolArgs(args, options),
|
|
261
|
+
});
|
|
262
|
+
const isServer = typeof window === 'undefined';
|
|
263
|
+
const visitorHeaders = buildWorkspaceVisitorHeaders(options);
|
|
264
|
+
let response: Response;
|
|
265
|
+
if (isServer) {
|
|
266
|
+
const apiUrl =
|
|
267
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
268
|
+
EGDESK_CONFIG.apiUrl;
|
|
269
|
+
response = await fetch(\`\${apiUrl}\${path}\`, {
|
|
270
|
+
method: 'POST',
|
|
271
|
+
headers: { ...buildServerEgdeskHeaders(), ...visitorHeaders },
|
|
272
|
+
body,
|
|
273
|
+
});
|
|
274
|
+
} else {
|
|
275
|
+
response = await apiFetch(proxyPath, {
|
|
276
|
+
method: 'POST',
|
|
277
|
+
headers: { 'Content-Type': 'application/json', ...visitorHeaders },
|
|
278
|
+
body,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return parseEgdeskMcpToolResponse(response);
|
|
282
|
+
}
|
|
283
|
+
|
|
214
284
|
/**
|
|
215
285
|
* Parse EGDesk MCP \`/tools/call\` JSON so \`error\` is shown even when HTTP status is 500.
|
|
216
286
|
*/
|
|
@@ -3168,10 +3238,9 @@ export async function deletePageIndexDocument(docId: string) {
|
|
|
3168
3238
|
* Call EGDesk Drive MCP tool (Google Drive change notifications + poll).
|
|
3169
3239
|
*
|
|
3170
3240
|
* Owner MCP auth on EGDesk: GOOGLE_SERVICE_ACCOUNT_JSON or Google Workspace sign-in
|
|
3171
|
-
* via startDriveAuthLogin() — configures THIS EGDesk instance
|
|
3172
|
-
*
|
|
3173
|
-
*
|
|
3174
|
-
* Share target folders with the service account when using SA credentials.
|
|
3241
|
+
* via startDriveAuthLogin() — configures THIS EGDesk instance.
|
|
3242
|
+
* Pass { asVisitor: true } to act as the website visitor from startVisitorGoogleLogin().
|
|
3243
|
+
* Watch / sync / drive_auth_login stay owner-only even with asVisitor.
|
|
3175
3244
|
*
|
|
3176
3245
|
* - Server: \`POST {apiUrl}/drive/tools/call\`
|
|
3177
3246
|
* - Client: \`POST /__drive_proxy\` (see proxy.ts / middleware)
|
|
@@ -3179,31 +3248,10 @@ export async function deletePageIndexDocument(docId: string) {
|
|
|
3179
3248
|
*/
|
|
3180
3249
|
export async function callDriveTool(
|
|
3181
3250
|
toolName: string,
|
|
3182
|
-
args: Record<string, any> = {}
|
|
3251
|
+
args: Record<string, any> = {},
|
|
3252
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3183
3253
|
): Promise<any> {
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
const isServer = typeof window === 'undefined';
|
|
3187
|
-
|
|
3188
|
-
let response: Response;
|
|
3189
|
-
if (isServer) {
|
|
3190
|
-
const apiUrl =
|
|
3191
|
-
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3192
|
-
EGDESK_CONFIG.apiUrl;
|
|
3193
|
-
response = await fetch(\`\${apiUrl}/drive/tools/call\`, {
|
|
3194
|
-
method: 'POST',
|
|
3195
|
-
headers: buildServerEgdeskHeaders(),
|
|
3196
|
-
body
|
|
3197
|
-
});
|
|
3198
|
-
} else {
|
|
3199
|
-
response = await apiFetch('/__drive_proxy', {
|
|
3200
|
-
method: 'POST',
|
|
3201
|
-
headers: { 'Content-Type': 'application/json' },
|
|
3202
|
-
body
|
|
3203
|
-
});
|
|
3204
|
-
}
|
|
3205
|
-
|
|
3206
|
-
return parseEgdeskMcpToolResponse(response);
|
|
3254
|
+
return callWorkspaceMcpTool('/drive/tools/call', '/__drive_proxy', toolName, args, options);
|
|
3207
3255
|
}
|
|
3208
3256
|
|
|
3209
3257
|
/** Check owner Drive auth on this EGDesk instance (service account / Google OAuth) */
|
|
@@ -3403,36 +3451,16 @@ export async function syncDrive(options: {
|
|
|
3403
3451
|
* Call EGDesk Sheets MCP tool.
|
|
3404
3452
|
*
|
|
3405
3453
|
* Auth: personal OAuth, service account, or domain-wide delegation (call getSheetsAuthStatus() first).
|
|
3454
|
+
* Pass { asVisitor: true } to act as the website visitor from startVisitorGoogleLogin().
|
|
3406
3455
|
* - Server: \`POST {apiUrl}/sheets/tools/call\`
|
|
3407
3456
|
* - Client: \`POST /__sheets_proxy\`
|
|
3408
3457
|
*/
|
|
3409
3458
|
export async function callSheetsTool(
|
|
3410
3459
|
toolName: string,
|
|
3411
|
-
args: Record<string, any> = {}
|
|
3460
|
+
args: Record<string, any> = {},
|
|
3461
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3412
3462
|
): Promise<any> {
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
const isServer = typeof window === 'undefined';
|
|
3416
|
-
|
|
3417
|
-
let response: Response;
|
|
3418
|
-
if (isServer) {
|
|
3419
|
-
const apiUrl =
|
|
3420
|
-
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3421
|
-
EGDESK_CONFIG.apiUrl;
|
|
3422
|
-
response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
3423
|
-
method: 'POST',
|
|
3424
|
-
headers: buildServerEgdeskHeaders(),
|
|
3425
|
-
body
|
|
3426
|
-
});
|
|
3427
|
-
} else {
|
|
3428
|
-
response = await apiFetch('/__sheets_proxy', {
|
|
3429
|
-
method: 'POST',
|
|
3430
|
-
headers: { 'Content-Type': 'application/json' },
|
|
3431
|
-
body
|
|
3432
|
-
});
|
|
3433
|
-
}
|
|
3434
|
-
|
|
3435
|
-
return parseEgdeskMcpToolResponse(response);
|
|
3463
|
+
return callWorkspaceMcpTool('/sheets/tools/call', '/__sheets_proxy', toolName, args, options);
|
|
3436
3464
|
}
|
|
3437
3465
|
|
|
3438
3466
|
/** Who Sheets/Docs/Slides/Drive calls act as: personal_oauth, service_account, or domain_wide_delegation */
|
|
@@ -3515,28 +3543,10 @@ export async function tintSheetDataTab(spreadsheetId: string, sheetName: string)
|
|
|
3515
3543
|
|
|
3516
3544
|
export async function callDocsTool(
|
|
3517
3545
|
toolName: string,
|
|
3518
|
-
args: Record<string, any> = {}
|
|
3546
|
+
args: Record<string, any> = {},
|
|
3547
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3519
3548
|
): Promise<any> {
|
|
3520
|
-
|
|
3521
|
-
const isServer = typeof window === 'undefined';
|
|
3522
|
-
let response: Response;
|
|
3523
|
-
if (isServer) {
|
|
3524
|
-
const apiUrl =
|
|
3525
|
-
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3526
|
-
EGDESK_CONFIG.apiUrl;
|
|
3527
|
-
response = await fetch(\`\${apiUrl}/docs/tools/call\`, {
|
|
3528
|
-
method: 'POST',
|
|
3529
|
-
headers: buildServerEgdeskHeaders(),
|
|
3530
|
-
body
|
|
3531
|
-
});
|
|
3532
|
-
} else {
|
|
3533
|
-
response = await apiFetch('/__docs_proxy', {
|
|
3534
|
-
method: 'POST',
|
|
3535
|
-
headers: { 'Content-Type': 'application/json' },
|
|
3536
|
-
body
|
|
3537
|
-
});
|
|
3538
|
-
}
|
|
3539
|
-
return parseEgdeskMcpToolResponse(response);
|
|
3549
|
+
return callWorkspaceMcpTool('/docs/tools/call', '/__docs_proxy', toolName, args, options);
|
|
3540
3550
|
}
|
|
3541
3551
|
|
|
3542
3552
|
export async function getGoogleDocsAuthStatus() {
|
|
@@ -3574,28 +3584,10 @@ export async function replaceGoogleDocText(
|
|
|
3574
3584
|
|
|
3575
3585
|
export async function callSlidesTool(
|
|
3576
3586
|
toolName: string,
|
|
3577
|
-
args: Record<string, any> = {}
|
|
3587
|
+
args: Record<string, any> = {},
|
|
3588
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3578
3589
|
): Promise<any> {
|
|
3579
|
-
|
|
3580
|
-
const isServer = typeof window === 'undefined';
|
|
3581
|
-
let response: Response;
|
|
3582
|
-
if (isServer) {
|
|
3583
|
-
const apiUrl =
|
|
3584
|
-
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3585
|
-
EGDESK_CONFIG.apiUrl;
|
|
3586
|
-
response = await fetch(\`\${apiUrl}/slides/tools/call\`, {
|
|
3587
|
-
method: 'POST',
|
|
3588
|
-
headers: buildServerEgdeskHeaders(),
|
|
3589
|
-
body
|
|
3590
|
-
});
|
|
3591
|
-
} else {
|
|
3592
|
-
response = await apiFetch('/__slides_proxy', {
|
|
3593
|
-
method: 'POST',
|
|
3594
|
-
headers: { 'Content-Type': 'application/json' },
|
|
3595
|
-
body
|
|
3596
|
-
});
|
|
3597
|
-
}
|
|
3598
|
-
return parseEgdeskMcpToolResponse(response);
|
|
3590
|
+
return callWorkspaceMcpTool('/slides/tools/call', '/__slides_proxy', toolName, args, options);
|
|
3599
3591
|
}
|
|
3600
3592
|
|
|
3601
3593
|
export async function getGoogleSlidesAuthStatus() {
|
|
@@ -3693,28 +3685,10 @@ export async function syncSheets(options: {
|
|
|
3693
3685
|
*/
|
|
3694
3686
|
export async function callGmailTool(
|
|
3695
3687
|
toolName: string,
|
|
3696
|
-
args: Record<string, any> = {}
|
|
3688
|
+
args: Record<string, any> = {},
|
|
3689
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3697
3690
|
): Promise<any> {
|
|
3698
|
-
|
|
3699
|
-
const isServer = typeof window === 'undefined';
|
|
3700
|
-
let response: Response;
|
|
3701
|
-
if (isServer) {
|
|
3702
|
-
const apiUrl =
|
|
3703
|
-
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3704
|
-
EGDESK_CONFIG.apiUrl;
|
|
3705
|
-
response = await fetch(\`\${apiUrl}/gmail/tools/call\`, {
|
|
3706
|
-
method: 'POST',
|
|
3707
|
-
headers: buildServerEgdeskHeaders(),
|
|
3708
|
-
body
|
|
3709
|
-
});
|
|
3710
|
-
} else {
|
|
3711
|
-
response = await apiFetch('/__gmail_proxy', {
|
|
3712
|
-
method: 'POST',
|
|
3713
|
-
headers: { 'Content-Type': 'application/json' },
|
|
3714
|
-
body
|
|
3715
|
-
});
|
|
3716
|
-
}
|
|
3717
|
-
return parseEgdeskMcpToolResponse(response);
|
|
3691
|
+
return callWorkspaceMcpTool('/gmail/tools/call', '/__gmail_proxy', toolName, args, options);
|
|
3718
3692
|
}
|
|
3719
3693
|
|
|
3720
3694
|
/** Who Gmail calls act as: personal_oauth, service_account, or domain_wide_delegation */
|
|
@@ -3765,28 +3739,10 @@ export async function sendGmailMessage(options: {
|
|
|
3765
3739
|
*/
|
|
3766
3740
|
export async function callAppsScriptTool(
|
|
3767
3741
|
toolName: string,
|
|
3768
|
-
args: Record<string, any> = {}
|
|
3742
|
+
args: Record<string, any> = {},
|
|
3743
|
+
options: WorkspaceVisitorCallOptions = {},
|
|
3769
3744
|
): Promise<any> {
|
|
3770
|
-
|
|
3771
|
-
const isServer = typeof window === 'undefined';
|
|
3772
|
-
let response: Response;
|
|
3773
|
-
if (isServer) {
|
|
3774
|
-
const apiUrl =
|
|
3775
|
-
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
3776
|
-
EGDESK_CONFIG.apiUrl;
|
|
3777
|
-
response = await fetch(\`\${apiUrl}/apps-script/tools/call\`, {
|
|
3778
|
-
method: 'POST',
|
|
3779
|
-
headers: buildServerEgdeskHeaders(),
|
|
3780
|
-
body
|
|
3781
|
-
});
|
|
3782
|
-
} else {
|
|
3783
|
-
response = await apiFetch('/__apps_script_proxy', {
|
|
3784
|
-
method: 'POST',
|
|
3785
|
-
headers: { 'Content-Type': 'application/json' },
|
|
3786
|
-
body
|
|
3787
|
-
});
|
|
3788
|
-
}
|
|
3789
|
-
return parseEgdeskMcpToolResponse(response);
|
|
3745
|
+
return callWorkspaceMcpTool('/apps-script/tools/call', '/__apps_script_proxy', toolName, args, options);
|
|
3790
3746
|
}
|
|
3791
3747
|
|
|
3792
3748
|
/** Apps Script auth mode and identity (OAuth or service account / DWD — call before create/push/run) */
|
|
@@ -93,6 +93,25 @@ function visitorUpstreamHeaders(request: NextRequest): Record<string, string> {
|
|
|
93
93
|
return headers;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
function workspaceUpstreamHeaders(request: NextRequest): Record<string, string> {
|
|
97
|
+
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
98
|
+
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
99
|
+
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
100
|
+
const authorization = request.headers.get('authorization');
|
|
101
|
+
const asVisitor = request.headers.get('x-egdesk-as-visitor');
|
|
102
|
+
if (authorization) headers['Authorization'] = authorization;
|
|
103
|
+
if (asVisitor) headers['X-EGDesk-As-Visitor'] = asVisitor;
|
|
104
|
+
if (asVisitor === 'true' || authorization) {
|
|
105
|
+
const origin =
|
|
106
|
+
request.headers.get('x-visitor-origin') ||
|
|
107
|
+
request.headers.get('origin') ||
|
|
108
|
+
request.nextUrl.origin;
|
|
109
|
+
headers['Origin'] = origin;
|
|
110
|
+
headers['X-Visitor-Origin'] = origin;
|
|
111
|
+
}
|
|
112
|
+
return headers;
|
|
113
|
+
}
|
|
114
|
+
|
|
96
115
|
export async function middleware(request: NextRequest) {
|
|
97
116
|
const { pathname } = request.nextUrl;
|
|
98
117
|
|
|
@@ -262,14 +281,11 @@ export async function middleware(request: NextRequest) {
|
|
|
262
281
|
if (pathname.includes('__drive_proxy')) {
|
|
263
282
|
try {
|
|
264
283
|
const body = await request.text();
|
|
265
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
266
284
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
267
|
-
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
268
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
269
285
|
|
|
270
286
|
const response = await fetch(\`\${apiUrl}/drive/tools/call\`, {
|
|
271
287
|
method: 'POST',
|
|
272
|
-
headers,
|
|
288
|
+
headers: workspaceUpstreamHeaders(request),
|
|
273
289
|
body,
|
|
274
290
|
});
|
|
275
291
|
const result = await response.json();
|
|
@@ -285,14 +301,11 @@ export async function middleware(request: NextRequest) {
|
|
|
285
301
|
if (pathname.includes('__docs_proxy')) {
|
|
286
302
|
try {
|
|
287
303
|
const body = await request.text();
|
|
288
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
289
304
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
290
|
-
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
291
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
292
305
|
|
|
293
306
|
const response = await fetch(\`\${apiUrl}/docs/tools/call\`, {
|
|
294
307
|
method: 'POST',
|
|
295
|
-
headers,
|
|
308
|
+
headers: workspaceUpstreamHeaders(request),
|
|
296
309
|
body,
|
|
297
310
|
});
|
|
298
311
|
const result = await response.json();
|
|
@@ -308,14 +321,11 @@ export async function middleware(request: NextRequest) {
|
|
|
308
321
|
if (pathname.includes('__slides_proxy')) {
|
|
309
322
|
try {
|
|
310
323
|
const body = await request.text();
|
|
311
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
312
324
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
313
|
-
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
314
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
315
325
|
|
|
316
326
|
const response = await fetch(\`\${apiUrl}/slides/tools/call\`, {
|
|
317
327
|
method: 'POST',
|
|
318
|
-
headers,
|
|
328
|
+
headers: workspaceUpstreamHeaders(request),
|
|
319
329
|
body,
|
|
320
330
|
});
|
|
321
331
|
const result = await response.json();
|
|
@@ -331,14 +341,11 @@ export async function middleware(request: NextRequest) {
|
|
|
331
341
|
if (pathname.includes('__sheets_proxy')) {
|
|
332
342
|
try {
|
|
333
343
|
const body = await request.text();
|
|
334
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
335
344
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
336
|
-
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
337
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
338
345
|
|
|
339
346
|
const response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
340
347
|
method: 'POST',
|
|
341
|
-
headers,
|
|
348
|
+
headers: workspaceUpstreamHeaders(request),
|
|
342
349
|
body,
|
|
343
350
|
});
|
|
344
351
|
const result = await response.json();
|
|
@@ -392,13 +399,10 @@ export async function middleware(request: NextRequest) {
|
|
|
392
399
|
if (pathname.includes('__gmail_proxy')) {
|
|
393
400
|
try {
|
|
394
401
|
const body = await request.text();
|
|
395
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
396
402
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
397
|
-
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
398
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
399
403
|
const response = await fetch(\`\${apiUrl}/gmail/tools/call\`, {
|
|
400
404
|
method: 'POST',
|
|
401
|
-
headers,
|
|
405
|
+
headers: workspaceUpstreamHeaders(request),
|
|
402
406
|
body,
|
|
403
407
|
});
|
|
404
408
|
const result = await response.json();
|
|
@@ -414,13 +418,10 @@ export async function middleware(request: NextRequest) {
|
|
|
414
418
|
if (pathname.includes('__apps_script_proxy')) {
|
|
415
419
|
try {
|
|
416
420
|
const body = await request.text();
|
|
417
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
418
421
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
419
|
-
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
420
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
421
422
|
const response = await fetch(\`\${apiUrl}/apps-script/tools/call\`, {
|
|
422
423
|
method: 'POST',
|
|
423
|
-
headers,
|
|
424
|
+
headers: workspaceUpstreamHeaders(request),
|
|
424
425
|
body,
|
|
425
426
|
});
|
|
426
427
|
const result = await response.json();
|
package/dist/generate-proxy.js
CHANGED
|
@@ -102,6 +102,24 @@ function visitorForwardHeaders(request: NextRequest): Record<string, string> {
|
|
|
102
102
|
return headers;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
/** Forward opt-in visitor session headers to Workspace MCP tool calls. */
|
|
106
|
+
function workspaceForwardHeaders(request: NextRequest): Record<string, string> {
|
|
107
|
+
const headers = buildEgdeskHeaders();
|
|
108
|
+
const authorization = request.headers.get('authorization');
|
|
109
|
+
const asVisitor = request.headers.get('x-egdesk-as-visitor');
|
|
110
|
+
if (authorization) headers['Authorization'] = authorization;
|
|
111
|
+
if (asVisitor) headers['X-EGDesk-As-Visitor'] = asVisitor;
|
|
112
|
+
if (asVisitor === 'true' || authorization) {
|
|
113
|
+
const origin =
|
|
114
|
+
request.headers.get('x-visitor-origin') ||
|
|
115
|
+
request.headers.get('origin') ||
|
|
116
|
+
request.nextUrl.origin;
|
|
117
|
+
headers['Origin'] = origin;
|
|
118
|
+
headers['X-Visitor-Origin'] = origin;
|
|
119
|
+
}
|
|
120
|
+
return headers;
|
|
121
|
+
}
|
|
122
|
+
|
|
105
123
|
export async function proxy(request: NextRequest) {
|
|
106
124
|
const { pathname } = request.nextUrl;
|
|
107
125
|
|
|
@@ -422,7 +440,7 @@ export async function proxy(request: NextRequest) {
|
|
|
422
440
|
|
|
423
441
|
const response = await fetch(\`\${apiUrl}/drive/tools/call\`, {
|
|
424
442
|
method: 'POST',
|
|
425
|
-
headers:
|
|
443
|
+
headers: workspaceForwardHeaders(request),
|
|
426
444
|
body,
|
|
427
445
|
});
|
|
428
446
|
|
|
@@ -444,7 +462,7 @@ export async function proxy(request: NextRequest) {
|
|
|
444
462
|
|
|
445
463
|
const response = await fetch(\`\${apiUrl}/docs/tools/call\`, {
|
|
446
464
|
method: 'POST',
|
|
447
|
-
headers:
|
|
465
|
+
headers: workspaceForwardHeaders(request),
|
|
448
466
|
body,
|
|
449
467
|
});
|
|
450
468
|
|
|
@@ -466,7 +484,7 @@ export async function proxy(request: NextRequest) {
|
|
|
466
484
|
|
|
467
485
|
const response = await fetch(\`\${apiUrl}/slides/tools/call\`, {
|
|
468
486
|
method: 'POST',
|
|
469
|
-
headers:
|
|
487
|
+
headers: workspaceForwardHeaders(request),
|
|
470
488
|
body,
|
|
471
489
|
});
|
|
472
490
|
|
|
@@ -488,7 +506,7 @@ export async function proxy(request: NextRequest) {
|
|
|
488
506
|
|
|
489
507
|
const response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
490
508
|
method: 'POST',
|
|
491
|
-
headers:
|
|
509
|
+
headers: workspaceForwardHeaders(request),
|
|
492
510
|
body,
|
|
493
511
|
});
|
|
494
512
|
|
|
@@ -540,7 +558,7 @@ export async function proxy(request: NextRequest) {
|
|
|
540
558
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
541
559
|
const response = await fetch(\`\${apiUrl}/gmail/tools/call\`, {
|
|
542
560
|
method: 'POST',
|
|
543
|
-
headers:
|
|
561
|
+
headers: workspaceForwardHeaders(request),
|
|
544
562
|
body,
|
|
545
563
|
});
|
|
546
564
|
const result = await response.json();
|
|
@@ -559,7 +577,7 @@ export async function proxy(request: NextRequest) {
|
|
|
559
577
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
560
578
|
const response = await fetch(\`\${apiUrl}/apps-script/tools/call\`, {
|
|
561
579
|
method: 'POST',
|
|
562
|
-
headers:
|
|
580
|
+
headers: workspaceForwardHeaders(request),
|
|
563
581
|
body,
|
|
564
582
|
});
|
|
565
583
|
const result = await response.json();
|
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.65";
|
|
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.65';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|