@egdesk/next-api-plugin 1.5.32 → 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/dist/generate-helpers.js +189 -3
- package/dist/generate-middleware.js +24 -1
- package/dist/generate-proxy.js +24 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
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,7 +73,7 @@ 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
|
*
|
|
@@ -282,6 +282,29 @@ export async function middleware(request: NextRequest) {
|
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
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
|
+
|
|
285
308
|
if (pathname.includes('__egdesk_http_proxy')) {
|
|
286
309
|
try {
|
|
287
310
|
const payload = await request.json().catch(() => ({} as Record<string, unknown>));
|
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
|
|
@@ -349,6 +349,28 @@ export async function proxy(request: NextRequest) {
|
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
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
|
+
|
|
352
374
|
if (pathname.includes('__egdesk_http_proxy')) {
|
|
353
375
|
try {
|
|
354
376
|
const payload = await request.json().catch(() => ({} as Record<string, unknown>));
|
|
@@ -671,7 +693,7 @@ export const config = {
|
|
|
671
693
|
matcher: [
|
|
672
694
|
/*
|
|
673
695
|
* Match all paths except static assets
|
|
674
|
-
* 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
|
|
675
697
|
*/
|
|
676
698
|
'/:path*',
|
|
677
699
|
],
|
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");
|