@egdesk/next-api-plugin 1.5.28 → 1.5.33
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-helpers.js +189 -3
- package/dist/generate-middleware.js +40 -8
- package/dist/generate-proxy.js +35 -4
- 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
|
|
package/dist/generate-helpers.js
CHANGED
|
@@ -137,7 +137,7 @@ function generateHelpers(projectPath, options = {}) {
|
|
|
137
137
|
const helperContent = `/**
|
|
138
138
|
* EGDesk Helper Functions for Next.js
|
|
139
139
|
*
|
|
140
|
-
* Type-safe helpers for EGDesk user data, Google Workspace (Sheets / Drive
|
|
140
|
+
* Type-safe helpers for EGDesk user data, Google Workspace (Sheets / Drive MCP + sync, Gmail, Apps Script),
|
|
141
141
|
* FinanceHub (banks, cards, Hometax, promissory notes),
|
|
142
142
|
* internal knowledge / business identity / company research (MCP), Korean law (MCP), and browser recorder replay.
|
|
143
143
|
* Works in both client and server components.
|
|
@@ -2704,7 +2704,7 @@ export async function deletePageIndexDocument(docId: string) {
|
|
|
2704
2704
|
}
|
|
2705
2705
|
|
|
2706
2706
|
// ==========================================
|
|
2707
|
-
// Drive (MCP) — change watch / poll / events
|
|
2707
|
+
// Drive (MCP) — files, folders, change watch / poll / events
|
|
2708
2708
|
// ==========================================
|
|
2709
2709
|
|
|
2710
2710
|
/**
|
|
@@ -2832,7 +2832,7 @@ export async function setDriveTargetFolders(folderIds: string[]) {
|
|
|
2832
2832
|
return callDriveTool('drive_set_target_folders', { folderIds });
|
|
2833
2833
|
}
|
|
2834
2834
|
|
|
2835
|
-
/** Upload a local file into a
|
|
2835
|
+
/** Upload a local file into a Drive folder (local → Workspace) */
|
|
2836
2836
|
export async function uploadDriveFile(options: {
|
|
2837
2837
|
filePath: string;
|
|
2838
2838
|
folderId?: string;
|
|
@@ -2842,6 +2842,84 @@ export async function uploadDriveFile(options: {
|
|
|
2842
2842
|
return callDriveTool('drive_upload', options);
|
|
2843
2843
|
}
|
|
2844
2844
|
|
|
2845
|
+
/** List Drive files by folder and/or query */
|
|
2846
|
+
export async function listDriveFiles(options: {
|
|
2847
|
+
folderId?: string;
|
|
2848
|
+
query?: string;
|
|
2849
|
+
pageSize?: number;
|
|
2850
|
+
pageToken?: string;
|
|
2851
|
+
} = {}) {
|
|
2852
|
+
return callDriveTool('drive_list_files', options);
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
/** Get Drive file or folder metadata */
|
|
2856
|
+
export async function getDriveFile(fileId: string) {
|
|
2857
|
+
return callDriveTool('drive_get_file', { fileId });
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
/** Create a Drive folder */
|
|
2861
|
+
export async function createDriveFolder(name: string, parentId?: string) {
|
|
2862
|
+
return callDriveTool('drive_create_folder', { name, parentId });
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
/** Download a Drive file to a local path */
|
|
2866
|
+
export async function downloadDriveFile(fileId: string, destPath: string) {
|
|
2867
|
+
return callDriveTool('drive_download', { fileId, destPath });
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
/** Move a file or folder into destFolderId */
|
|
2871
|
+
export async function moveDriveFile(fileId: string, destFolderId: string) {
|
|
2872
|
+
return callDriveTool('drive_move', { fileId, destFolderId });
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
/** Copy a Drive file */
|
|
2876
|
+
export async function copyDriveFile(options: {
|
|
2877
|
+
fileId: string;
|
|
2878
|
+
destName?: string;
|
|
2879
|
+
destFolderId?: string;
|
|
2880
|
+
}) {
|
|
2881
|
+
return callDriveTool('drive_copy', options);
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
/** Rename a Drive file or folder */
|
|
2885
|
+
export async function renameDriveFile(fileId: string, name: string) {
|
|
2886
|
+
return callDriveTool('drive_rename', { fileId, name });
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
/** Move a Drive file or folder to trash */
|
|
2890
|
+
export async function trashDriveFile(fileId: string) {
|
|
2891
|
+
return callDriveTool('drive_trash', { fileId });
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
/** Find or create the top-level EGDesk Drive folder */
|
|
2895
|
+
export async function findOrCreateEgdeskFolder() {
|
|
2896
|
+
return callDriveTool('drive_find_or_create_egdesk_folder', {});
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
/** Find or create EGDesk/Dev, Transactions, or Tax Invoices */
|
|
2900
|
+
export async function findOrCreateEgdeskSubfolder(
|
|
2901
|
+
subfolder: 'Dev' | 'Transactions' | 'Tax Invoices',
|
|
2902
|
+
) {
|
|
2903
|
+
return callDriveTool('drive_find_or_create_subfolder', { subfolder });
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
/** Move a file into an EGDesk subfolder */
|
|
2907
|
+
export async function moveDriveFileToEgdeskFolder(
|
|
2908
|
+
fileId: string,
|
|
2909
|
+
subfolder: 'Dev' | 'Transactions' | 'Tax Invoices',
|
|
2910
|
+
) {
|
|
2911
|
+
return callDriveTool('drive_move_to_egdesk_folder', { fileId, subfolder });
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
/** Create a spreadsheet and organize it into an EGDesk subfolder */
|
|
2915
|
+
export async function createSpreadsheetInEgdeskFolder(options: {
|
|
2916
|
+
title: string;
|
|
2917
|
+
subfolder: 'Dev' | 'Transactions' | 'Tax Invoices';
|
|
2918
|
+
data?: string[][];
|
|
2919
|
+
}) {
|
|
2920
|
+
return callDriveTool('drive_create_spreadsheet_in_folder', options);
|
|
2921
|
+
}
|
|
2922
|
+
|
|
2845
2923
|
/**
|
|
2846
2924
|
* Drive HTTP sync (same as GET/POST /drive/sync).
|
|
2847
2925
|
* Omit options to GET status. Pass \`direction: 'toLocal'\` to download, or
|
|
@@ -2860,6 +2938,114 @@ export async function syncDrive(options: {
|
|
|
2860
2938
|
});
|
|
2861
2939
|
}
|
|
2862
2940
|
|
|
2941
|
+
// ==========================================
|
|
2942
|
+
// Google Sheets (MCP) — create / read / update / append
|
|
2943
|
+
// ==========================================
|
|
2944
|
+
|
|
2945
|
+
/**
|
|
2946
|
+
* Call EGDesk Sheets MCP tool.
|
|
2947
|
+
*
|
|
2948
|
+
* - Server: \`POST {apiUrl}/sheets/tools/call\`
|
|
2949
|
+
* - Client: \`POST /__sheets_proxy\`
|
|
2950
|
+
*/
|
|
2951
|
+
export async function callSheetsTool(
|
|
2952
|
+
toolName: string,
|
|
2953
|
+
args: Record<string, any> = {}
|
|
2954
|
+
): Promise<any> {
|
|
2955
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
2956
|
+
|
|
2957
|
+
const isServer = typeof window === 'undefined';
|
|
2958
|
+
|
|
2959
|
+
let response: Response;
|
|
2960
|
+
if (isServer) {
|
|
2961
|
+
const apiUrl =
|
|
2962
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
2963
|
+
EGDESK_CONFIG.apiUrl;
|
|
2964
|
+
response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
2965
|
+
method: 'POST',
|
|
2966
|
+
headers: buildServerEgdeskHeaders(),
|
|
2967
|
+
body
|
|
2968
|
+
});
|
|
2969
|
+
} else {
|
|
2970
|
+
response = await apiFetch('/__sheets_proxy', {
|
|
2971
|
+
method: 'POST',
|
|
2972
|
+
headers: { 'Content-Type': 'application/json' },
|
|
2973
|
+
body
|
|
2974
|
+
});
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
return parseEgdeskMcpToolResponse(response);
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
/** Spreadsheet metadata (tabs, dimensions) */
|
|
2981
|
+
export async function getSpreadsheet(spreadsheetId: string) {
|
|
2982
|
+
return callSheetsTool('sheets_get_spreadsheet', { spreadsheetId });
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
/** Read a range (A1 notation) */
|
|
2986
|
+
export async function getSheetRange(spreadsheetId: string, range: string) {
|
|
2987
|
+
return callSheetsTool('sheets_get_range', { spreadsheetId, range });
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
/** Read a range including formula vs literal per cell */
|
|
2991
|
+
export async function getSheetRangeWithFormulas(spreadsheetId: string, range: string) {
|
|
2992
|
+
return callSheetsTool('sheets_get_range_with_formulas', { spreadsheetId, range });
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
/** Header row of a tab */
|
|
2996
|
+
export async function getSheetHeaders(spreadsheetId: string, sheetName?: string) {
|
|
2997
|
+
return callSheetsTool('sheets_get_headers', { spreadsheetId, sheetName });
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
/** First N rows of a tab */
|
|
3001
|
+
export async function getSheetSampleData(options: {
|
|
3002
|
+
spreadsheetId: string;
|
|
3003
|
+
sheetName?: string;
|
|
3004
|
+
rows?: number;
|
|
3005
|
+
}) {
|
|
3006
|
+
return callSheetsTool('sheets_get_sample_data', options);
|
|
3007
|
+
}
|
|
3008
|
+
|
|
3009
|
+
/** Metadata + headers + sample rows for every tab */
|
|
3010
|
+
export async function getSpreadsheetFullContext(spreadsheetId: string, sampleRows?: number) {
|
|
3011
|
+
return callSheetsTool('sheets_get_full_context', { spreadsheetId, sampleRows });
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
/** Create a spreadsheet, optionally seeding Sheet1 */
|
|
3015
|
+
export async function createSpreadsheet(title: string, data?: string[][]) {
|
|
3016
|
+
return callSheetsTool('sheets_create_spreadsheet', { title, data });
|
|
3017
|
+
}
|
|
3018
|
+
|
|
3019
|
+
/** Add a tab to an existing spreadsheet */
|
|
3020
|
+
export async function createSheetTab(spreadsheetId: string, title: string) {
|
|
3021
|
+
return callSheetsTool('sheets_create_tab', { spreadsheetId, title });
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
/** Overwrite a range */
|
|
3025
|
+
export async function updateSheetRange(spreadsheetId: string, range: string, values: string[][]) {
|
|
3026
|
+
return callSheetsTool('sheets_update_range', { spreadsheetId, range, values });
|
|
3027
|
+
}
|
|
3028
|
+
|
|
3029
|
+
/** Append rows after the last non-empty row in range */
|
|
3030
|
+
export async function appendSheetValues(spreadsheetId: string, range: string, values: string[][]) {
|
|
3031
|
+
return callSheetsTool('sheets_append_values', { spreadsheetId, range, values });
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
/** Clear cell values in a range */
|
|
3035
|
+
export async function clearSheetRange(spreadsheetId: string, range: string) {
|
|
3036
|
+
return callSheetsTool('sheets_clear_range', { spreadsheetId, range });
|
|
3037
|
+
}
|
|
3038
|
+
|
|
3039
|
+
/** Bold + gray the first row of a tab */
|
|
3040
|
+
export async function formatSheetHeaders(spreadsheetId: string, sheetName?: string) {
|
|
3041
|
+
return callSheetsTool('sheets_format_headers', { spreadsheetId, sheetName });
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
/** Tint a synced data tab */
|
|
3045
|
+
export async function tintSheetDataTab(spreadsheetId: string, sheetName: string) {
|
|
3046
|
+
return callSheetsTool('sheets_tint_data_tab', { spreadsheetId, sheetName });
|
|
3047
|
+
}
|
|
3048
|
+
|
|
2863
3049
|
// ==========================================
|
|
2864
3050
|
// Google Sheets HTTP sync — My DB ↔ Workspace
|
|
2865
3051
|
// ==========================================
|
|
@@ -73,12 +73,26 @@ import type { NextRequest } from 'next/server';
|
|
|
73
73
|
/**
|
|
74
74
|
* EGDesk Database Proxy Middleware
|
|
75
75
|
*
|
|
76
|
-
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __kakao_proxy, __drive_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
|
|
76
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __kakao_proxy, __drive_proxy, __sheets_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
|
|
77
77
|
* and forwards them to the EGDesk MCP HTTP server.
|
|
78
78
|
* This allows CORS-free database access in both local and tunneled environments.
|
|
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
|
|
|
@@ -268,6 +282,29 @@ export async function middleware(request: NextRequest) {
|
|
|
268
282
|
}
|
|
269
283
|
}
|
|
270
284
|
|
|
285
|
+
if (pathname.includes('__sheets_proxy')) {
|
|
286
|
+
try {
|
|
287
|
+
const body = await request.text();
|
|
288
|
+
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
289
|
+
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
|
+
|
|
293
|
+
const response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
294
|
+
method: 'POST',
|
|
295
|
+
headers,
|
|
296
|
+
body,
|
|
297
|
+
});
|
|
298
|
+
const result = await response.json();
|
|
299
|
+
return NextResponse.json(result, { status: response.status });
|
|
300
|
+
} catch (error: any) {
|
|
301
|
+
return NextResponse.json(
|
|
302
|
+
{ error: 'Proxy error', message: error.message },
|
|
303
|
+
{ status: 500 }
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
271
308
|
if (pathname.includes('__egdesk_http_proxy')) {
|
|
272
309
|
try {
|
|
273
310
|
const payload = await request.json().catch(() => ({} as Record<string, unknown>));
|
|
@@ -353,14 +390,11 @@ export async function middleware(request: NextRequest) {
|
|
|
353
390
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
354
391
|
try {
|
|
355
392
|
const body = await request.text();
|
|
356
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
357
393
|
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
394
|
|
|
361
395
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
362
396
|
method: 'POST',
|
|
363
|
-
headers,
|
|
397
|
+
headers: visitorUpstreamHeaders(request),
|
|
364
398
|
body,
|
|
365
399
|
});
|
|
366
400
|
const result = await response.json();
|
|
@@ -376,10 +410,8 @@ export async function middleware(request: NextRequest) {
|
|
|
376
410
|
if (pathname.includes('__visitor_google_proxy')) {
|
|
377
411
|
try {
|
|
378
412
|
const body = await request.text();
|
|
379
|
-
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
380
413
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
381
|
-
const headers
|
|
382
|
-
if (apiKey) headers['X-Api-Key'] = apiKey;
|
|
414
|
+
const headers = visitorUpstreamHeaders(request);
|
|
383
415
|
const authorization = request.headers.get('authorization');
|
|
384
416
|
if (authorization) headers['Authorization'] = authorization;
|
|
385
417
|
|
package/dist/generate-proxy.js
CHANGED
|
@@ -75,7 +75,7 @@ import type { NextRequest } from 'next/server';
|
|
|
75
75
|
/**
|
|
76
76
|
* EGDesk Database Proxy (Next.js 16+)
|
|
77
77
|
*
|
|
78
|
-
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, __instagram_proxy, __financehub_proxy, __blog_proxy, __youtube_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
|
|
78
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __sheets_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, __instagram_proxy, __financehub_proxy, __blog_proxy, __youtube_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
|
|
79
79
|
* and forwards them to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
|
|
80
80
|
*
|
|
81
81
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -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
|
|
|
@@ -340,6 +349,28 @@ export async function proxy(request: NextRequest) {
|
|
|
340
349
|
}
|
|
341
350
|
}
|
|
342
351
|
|
|
352
|
+
if (pathname.includes('__sheets_proxy')) {
|
|
353
|
+
try {
|
|
354
|
+
const body = await request.text();
|
|
355
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
356
|
+
|
|
357
|
+
const response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
358
|
+
method: 'POST',
|
|
359
|
+
headers: buildEgdeskHeaders(),
|
|
360
|
+
body,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
const result = await response.json();
|
|
364
|
+
|
|
365
|
+
return NextResponse.json(result, { status: response.status });
|
|
366
|
+
} catch (error: any) {
|
|
367
|
+
return NextResponse.json(
|
|
368
|
+
{ error: 'Proxy error', message: error.message },
|
|
369
|
+
{ status: 500 }
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
343
374
|
if (pathname.includes('__egdesk_http_proxy')) {
|
|
344
375
|
try {
|
|
345
376
|
const payload = await request.json().catch(() => ({} as Record<string, unknown>));
|
|
@@ -614,7 +645,7 @@ export async function proxy(request: NextRequest) {
|
|
|
614
645
|
|
|
615
646
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
616
647
|
method: 'POST',
|
|
617
|
-
headers:
|
|
648
|
+
headers: visitorForwardHeaders(request),
|
|
618
649
|
body,
|
|
619
650
|
});
|
|
620
651
|
|
|
@@ -633,7 +664,7 @@ export async function proxy(request: NextRequest) {
|
|
|
633
664
|
try {
|
|
634
665
|
const body = await request.text();
|
|
635
666
|
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
636
|
-
const headers =
|
|
667
|
+
const headers = visitorForwardHeaders(request);
|
|
637
668
|
const authorization = request.headers.get('authorization');
|
|
638
669
|
if (authorization) headers['Authorization'] = authorization;
|
|
639
670
|
|
|
@@ -662,7 +693,7 @@ export const config = {
|
|
|
662
693
|
matcher: [
|
|
663
694
|
/*
|
|
664
695
|
* Match all paths except static assets
|
|
665
|
-
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __egdesk_http_proxy / __gmail_proxy / __apps_script_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy / __financehub_proxy / __blog_proxy / __youtube_proxy / __visitor_auth_proxy / __visitor_google_proxy
|
|
696
|
+
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __sheets_proxy / __egdesk_http_proxy / __gmail_proxy / __apps_script_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy / __financehub_proxy / __blog_proxy / __youtube_proxy / __visitor_auth_proxy / __visitor_google_proxy
|
|
666
697
|
*/
|
|
667
698
|
'/:path*',
|
|
668
699
|
],
|
|
@@ -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.46";
|
|
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.46';
|
|
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"');
|