@egdesk/next-api-plugin 1.5.6 → 1.5.8
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.d.ts +5 -1
- package/dist/generate-helpers.js +559 -4
- package/dist/generate-middleware.js +33 -1
- package/dist/generate-proxy.js +68 -2
- package/dist/index.d.ts +8 -1
- package/dist/index.js +104 -7
- package/dist/setup-userdata.js +30 -31
- package/package.json +8 -1
- package/src/cli.ts +0 -63
- package/src/generate-api-wrapper.ts +0 -69
- package/src/generate-helpers.ts +0 -1829
- package/src/generate-middleware.ts +0 -206
- package/src/generate-proxy.ts +0 -308
- package/src/index.ts +0 -144
- package/src/setup-userdata.ts +0 -373
- package/tsconfig.json +0 -18
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, and
|
|
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, __egdesk_config_proxy, __ai_caller_proxy, and __kakao_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
|
|
@@ -318,6 +318,72 @@ export async function proxy(request: NextRequest) {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
+
if (pathname.includes('__kakao_proxy')) {
|
|
322
|
+
try {
|
|
323
|
+
const body = await request.text();
|
|
324
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
325
|
+
|
|
326
|
+
const response = await fetch(\`\${apiUrl}/kakao/tools/call\`, {
|
|
327
|
+
method: 'POST',
|
|
328
|
+
headers: buildEgdeskHeaders(),
|
|
329
|
+
body,
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
const result = await response.json();
|
|
333
|
+
|
|
334
|
+
return NextResponse.json(result, { status: response.status });
|
|
335
|
+
} catch (error: any) {
|
|
336
|
+
return NextResponse.json(
|
|
337
|
+
{ error: 'Proxy error', message: error.message },
|
|
338
|
+
{ status: 500 }
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (pathname.includes('__egdesk_config_proxy')) {
|
|
344
|
+
try {
|
|
345
|
+
const body = await request.text();
|
|
346
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
347
|
+
|
|
348
|
+
const response = await fetch(\`\${apiUrl}/egdesk-config/tools/call\`, {
|
|
349
|
+
method: 'POST',
|
|
350
|
+
headers: buildEgdeskHeaders(),
|
|
351
|
+
body,
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
const result = await response.json();
|
|
355
|
+
|
|
356
|
+
return NextResponse.json(result, { status: response.status });
|
|
357
|
+
} catch (error: any) {
|
|
358
|
+
return NextResponse.json(
|
|
359
|
+
{ error: 'Proxy error', message: error.message },
|
|
360
|
+
{ status: 500 }
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (pathname.includes('__ai_caller_proxy')) {
|
|
366
|
+
try {
|
|
367
|
+
const body = await request.text();
|
|
368
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
369
|
+
|
|
370
|
+
const response = await fetch(\`\${apiUrl}/ai-caller/tools/call\`, {
|
|
371
|
+
method: 'POST',
|
|
372
|
+
headers: buildEgdeskHeaders(),
|
|
373
|
+
body,
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const result = await response.json();
|
|
377
|
+
|
|
378
|
+
return NextResponse.json(result, { status: response.status });
|
|
379
|
+
} catch (error: any) {
|
|
380
|
+
return NextResponse.json(
|
|
381
|
+
{ error: 'Proxy error', message: error.message },
|
|
382
|
+
{ status: 500 }
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
321
387
|
// Continue to next proxy or route
|
|
322
388
|
return NextResponse.next();
|
|
323
389
|
}
|
|
@@ -326,7 +392,7 @@ export const config = {
|
|
|
326
392
|
matcher: [
|
|
327
393
|
/*
|
|
328
394
|
* Match all paths except static assets
|
|
329
|
-
* 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
|
|
395
|
+
* 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 / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy
|
|
330
396
|
*/
|
|
331
397
|
'/:path*',
|
|
332
398
|
],
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
* Next.js plugin for EGDesk database proxy integration.
|
|
5
5
|
* Provides middleware-based database access for Next.js applications.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* The minimum EGDesk app version this plugin version is compatible with.
|
|
9
|
+
* The app checks this at setup time and warns on mismatch.
|
|
10
|
+
*/
|
|
11
|
+
export declare const COMPATIBLE_APP_VERSION = "1.4.9";
|
|
7
12
|
export interface SetupOptions {
|
|
8
13
|
egdeskUrl?: string;
|
|
9
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
|
@@ -19,6 +24,8 @@ export interface SetupOptions {
|
|
|
19
24
|
apiKey?: string;
|
|
20
25
|
useProxy?: boolean;
|
|
21
26
|
}
|
|
27
|
+
/** Next.js 15 and below use middleware.ts; proxy.ts requires Next.js 16+. */
|
|
28
|
+
export declare function detectNextUseProxy(projectPath: string): boolean;
|
|
22
29
|
/**
|
|
23
30
|
* Main setup function for Next.js projects
|
|
24
31
|
*
|
|
@@ -34,5 +41,5 @@ export { discoverTables } from './setup-userdata';
|
|
|
34
41
|
export { generateMiddleware } from './generate-middleware';
|
|
35
42
|
export { generateProxy } from './generate-proxy';
|
|
36
43
|
export { generateHelpers, generateSchemaFile, ensureSchemaFile, formatEgdeskSchemaFileContent } from './generate-helpers';
|
|
37
|
-
export type { SchemaTableDefinition, EnsureSchemaFileResult } from './generate-helpers';
|
|
44
|
+
export type { SchemaTableDefinition, EnsureSchemaFileResult, GenerateHelpersOptions } from './generate-helpers';
|
|
38
45
|
export { generateApiWrapper } from './generate-api-wrapper';
|
package/dist/index.js
CHANGED
|
@@ -5,14 +5,106 @@
|
|
|
5
5
|
* Next.js plugin for EGDesk database proxy integration.
|
|
6
6
|
* Provides middleware-based database access for Next.js applications.
|
|
7
7
|
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
8
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.generateApiWrapper = exports.formatEgdeskSchemaFileContent = exports.ensureSchemaFile = exports.generateSchemaFile = exports.generateHelpers = exports.generateProxy = exports.generateMiddleware = exports.discoverTables = void 0;
|
|
42
|
+
exports.generateApiWrapper = exports.formatEgdeskSchemaFileContent = exports.ensureSchemaFile = exports.generateSchemaFile = exports.generateHelpers = exports.generateProxy = exports.generateMiddleware = exports.discoverTables = exports.COMPATIBLE_APP_VERSION = void 0;
|
|
43
|
+
exports.detectNextUseProxy = detectNextUseProxy;
|
|
10
44
|
exports.setupNextApiPlugin = setupNextApiPlugin;
|
|
45
|
+
/**
|
|
46
|
+
* The minimum EGDesk app version this plugin version is compatible with.
|
|
47
|
+
* The app checks this at setup time and warns on mismatch.
|
|
48
|
+
*/
|
|
49
|
+
exports.COMPATIBLE_APP_VERSION = '1.4.9';
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
11
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
12
53
|
const generate_middleware_1 = require("./generate-middleware");
|
|
13
54
|
const generate_proxy_1 = require("./generate-proxy");
|
|
14
55
|
const generate_helpers_1 = require("./generate-helpers");
|
|
15
56
|
const generate_api_wrapper_1 = require("./generate-api-wrapper");
|
|
57
|
+
/** Next.js 15 and below use middleware.ts; proxy.ts requires Next.js 16+. */
|
|
58
|
+
function detectNextUseProxy(projectPath) {
|
|
59
|
+
try {
|
|
60
|
+
const pkgPath = path.join(projectPath, 'package.json');
|
|
61
|
+
if (!fs.existsSync(pkgPath)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
65
|
+
const nextVersion = pkg.dependencies?.next ?? pkg.devDependencies?.next ?? '';
|
|
66
|
+
const major = parseInt(String(nextVersion).replace(/^[^\d]*/, '').split('.')[0] ?? '', 10);
|
|
67
|
+
if (!Number.isNaN(major)) {
|
|
68
|
+
return major >= 16;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// fall through
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fetch Google/Gemini API key names from EGDesk AI Keys Manager.
|
|
78
|
+
* Returns an empty array on failure (non-blocking).
|
|
79
|
+
*/
|
|
80
|
+
async function discoverApiKeyNames(egdeskUrl, apiKey, egdeskProjectId) {
|
|
81
|
+
try {
|
|
82
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
83
|
+
if (apiKey)
|
|
84
|
+
headers['X-Api-Key'] = apiKey;
|
|
85
|
+
if (egdeskProjectId)
|
|
86
|
+
headers['X-EGDesk-Project-Id'] = egdeskProjectId;
|
|
87
|
+
const res = await fetch(`${egdeskUrl}/egdesk-config/tools/call`, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers,
|
|
90
|
+
body: JSON.stringify({ tool: 'egdesk_list_api_keys', arguments: { provider: 'google' } }),
|
|
91
|
+
});
|
|
92
|
+
if (!res.ok)
|
|
93
|
+
return [];
|
|
94
|
+
const json = (await res.json());
|
|
95
|
+
const text = json?.result?.content?.[0]?.text;
|
|
96
|
+
if (!text)
|
|
97
|
+
return [];
|
|
98
|
+
const parsed = JSON.parse(text);
|
|
99
|
+
const keys = Array.isArray(parsed?.keys) ? parsed.keys : Array.isArray(parsed) ? parsed : [];
|
|
100
|
+
return keys
|
|
101
|
+
.map((k) => (typeof k === 'string' ? k : k?.name))
|
|
102
|
+
.filter((n) => typeof n === 'string' && n.length > 0);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
16
108
|
/**
|
|
17
109
|
* Main setup function for Next.js projects
|
|
18
110
|
*
|
|
@@ -23,12 +115,14 @@ const generate_api_wrapper_1 = require("./generate-api-wrapper");
|
|
|
23
115
|
* - .env.local (environment variables)
|
|
24
116
|
*/
|
|
25
117
|
async function setupNextApiPlugin(projectPath, options = {}) {
|
|
26
|
-
const { egdeskUrl = 'http://localhost:8080', prodEgdeskUrl, discoveryUrl, egdeskProjectId, apiKey, useProxy
|
|
118
|
+
const { egdeskUrl = 'http://localhost:8080', prodEgdeskUrl, discoveryUrl, egdeskProjectId, apiKey, useProxy } = options;
|
|
119
|
+
const resolvedUseProxy = useProxy ?? detectNextUseProxy(projectPath);
|
|
27
120
|
console.log('🔍 Discovering EGDesk user-data tables...');
|
|
28
121
|
try {
|
|
29
|
-
const [devTables, prodTables] = await Promise.all([
|
|
122
|
+
const [devTables, prodTables, apiKeyNames] = await Promise.all([
|
|
30
123
|
(0, setup_userdata_1.discoverTables)(discoveryUrl ?? egdeskUrl, apiKey, egdeskProjectId, 'development'),
|
|
31
124
|
(0, setup_userdata_1.discoverTables)(discoveryUrl ?? egdeskUrl, apiKey, egdeskProjectId, 'production'),
|
|
125
|
+
discoverApiKeyNames(discoveryUrl ?? egdeskUrl, apiKey, egdeskProjectId),
|
|
32
126
|
]);
|
|
33
127
|
if (devTables.length === 0) {
|
|
34
128
|
console.warn('⚠️ No tables found. Import data in EGDesk first.');
|
|
@@ -41,6 +135,9 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
41
135
|
console.log(` ${index + 1}. ${table.displayName} (${table.rowCount} rows)`);
|
|
42
136
|
});
|
|
43
137
|
}
|
|
138
|
+
if (apiKeyNames.length > 0) {
|
|
139
|
+
console.log(`🔑 Found ${apiKeyNames.length} Google API key(s): ${apiKeyNames.join(', ')}`);
|
|
140
|
+
}
|
|
44
141
|
const config = {
|
|
45
142
|
apiKey: apiKey || null,
|
|
46
143
|
baseUrl: egdeskUrl,
|
|
@@ -53,12 +150,12 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
53
150
|
console.log('');
|
|
54
151
|
console.log('📝 Generating configuration files...');
|
|
55
152
|
// Use proxy.ts (Next.js 16+) or middleware.ts (legacy)
|
|
56
|
-
if (
|
|
153
|
+
if (resolvedUseProxy) {
|
|
57
154
|
console.log('🔄 Using proxy.ts (Next.js 16+ recommended)');
|
|
58
155
|
(0, generate_proxy_1.generateProxy)(projectPath);
|
|
59
156
|
}
|
|
60
157
|
else {
|
|
61
|
-
console.log('🔄 Using middleware.ts (
|
|
158
|
+
console.log('🔄 Using middleware.ts (Next.js 15 and below)');
|
|
62
159
|
(0, generate_middleware_1.generateMiddleware)(projectPath);
|
|
63
160
|
}
|
|
64
161
|
(0, setup_userdata_1.generateConfigFile)(projectPath, config);
|
|
@@ -67,10 +164,10 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
67
164
|
displayName: table.displayName,
|
|
68
165
|
columns: table.columns,
|
|
69
166
|
})));
|
|
70
|
-
(0, generate_helpers_1.generateHelpers)(projectPath);
|
|
167
|
+
(0, generate_helpers_1.generateHelpers)(projectPath, { apiKeyNames });
|
|
71
168
|
(0, generate_api_wrapper_1.generateApiWrapper)(projectPath);
|
|
72
169
|
(0, setup_userdata_1.updateEnvFiles)(projectPath, config, prodTables);
|
|
73
|
-
const proxyFile =
|
|
170
|
+
const proxyFile = resolvedUseProxy ? 'proxy.ts' : 'middleware.ts';
|
|
74
171
|
console.log('');
|
|
75
172
|
console.log('✅ Setup complete! Files generated:');
|
|
76
173
|
console.log(` - ${proxyFile} (database proxy)`);
|
package/dist/setup-userdata.js
CHANGED
|
@@ -92,43 +92,42 @@ async function discoverTables(egdeskUrl = 'http://localhost:8080', apiKey, egdes
|
|
|
92
92
|
if (!data || !data.tables) {
|
|
93
93
|
return [];
|
|
94
94
|
}
|
|
95
|
-
// Fetch
|
|
96
|
-
const
|
|
97
|
-
|
|
95
|
+
// Fetch all schemas in one batch request
|
|
96
|
+
const schemaResponse = await fetch(`${egdeskUrl}/user-data/tools/call`, {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers,
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
tool: 'user_data_get_schemas_batch',
|
|
101
|
+
arguments: {
|
|
102
|
+
tableNames: data.tables.map((table) => table.tableName)
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
const schemaByTableName = new Map();
|
|
107
|
+
if (schemaResponse.ok) {
|
|
98
108
|
try {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
if (schemaResponse.ok) {
|
|
108
|
-
const schemaResult = (await schemaResponse.json());
|
|
109
|
-
const schemaContent = schemaResult.result?.content?.[0]?.text;
|
|
110
|
-
const schemaData = schemaContent ? JSON.parse(schemaContent) : null;
|
|
111
|
-
tablesWithColumns.push({
|
|
112
|
-
id: table.id,
|
|
113
|
-
tableName: table.tableName,
|
|
114
|
-
displayName: table.displayName,
|
|
115
|
-
description: table.description,
|
|
116
|
-
rowCount: table.rowCount,
|
|
117
|
-
columnCount: table.columnCount,
|
|
118
|
-
columns: schemaData?.schema?.map((col) => col.name) || []
|
|
119
|
-
});
|
|
109
|
+
const schemaResult = (await schemaResponse.json());
|
|
110
|
+
const schemaContent = schemaResult.result?.content?.[0]?.text;
|
|
111
|
+
const schemaData = schemaContent ? JSON.parse(schemaContent) : null;
|
|
112
|
+
const schemas = schemaData?.schemas ?? {};
|
|
113
|
+
for (const [tableName, schemaInfo] of Object.entries(schemas)) {
|
|
114
|
+
const columns = schemaInfo?.schema?.map((col) => col.name) || [];
|
|
115
|
+
schemaByTableName.set(tableName, columns);
|
|
120
116
|
}
|
|
121
117
|
}
|
|
122
118
|
catch (error) {
|
|
123
|
-
console.warn(
|
|
124
|
-
// Add table without column info
|
|
125
|
-
tablesWithColumns.push({
|
|
126
|
-
...table,
|
|
127
|
-
columns: []
|
|
128
|
-
});
|
|
119
|
+
console.warn('Failed to parse batch schema response:', error);
|
|
129
120
|
}
|
|
130
121
|
}
|
|
131
|
-
return
|
|
122
|
+
return data.tables.map((table) => ({
|
|
123
|
+
id: table.id,
|
|
124
|
+
tableName: table.tableName,
|
|
125
|
+
displayName: table.displayName,
|
|
126
|
+
description: table.description,
|
|
127
|
+
rowCount: table.rowCount,
|
|
128
|
+
columnCount: table.columnCount,
|
|
129
|
+
columns: schemaByTableName.get(table.tableName) || []
|
|
130
|
+
}));
|
|
132
131
|
}
|
|
133
132
|
catch (error) {
|
|
134
133
|
// Connection refused / server not yet up — treat as no tables rather than a hard failure
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egdesk/next-api-plugin",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"description": "Next.js plugin for EGDesk database proxy integration",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
8
|
"egdesk-next-setup": "./dist/cli.js"
|
|
9
9
|
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
10
17
|
"scripts": {
|
|
11
18
|
"build": "tsc",
|
|
12
19
|
"dev": "tsc --watch",
|
package/src/cli.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* CLI entry point for @egdesk/next-api-plugin
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* npx egdesk-next-setup
|
|
7
|
-
* npx egdesk-next-setup --url http://localhost:8080 --api-key YOUR_KEY
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { setupNextApiPlugin } from './index';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
|
|
13
|
-
async function main() {
|
|
14
|
-
const args = process.argv.slice(2);
|
|
15
|
-
|
|
16
|
-
// Parse command line arguments
|
|
17
|
-
let egdeskUrl = 'http://localhost:8080';
|
|
18
|
-
let apiKey: string | undefined;
|
|
19
|
-
let useProxy = true; // Use proxy.ts by default (Next.js 16+)
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < args.length; i++) {
|
|
22
|
-
if (args[i] === '--url' && i + 1 < args.length) {
|
|
23
|
-
egdeskUrl = args[i + 1];
|
|
24
|
-
i++;
|
|
25
|
-
} else if (args[i] === '--api-key' && i + 1 < args.length) {
|
|
26
|
-
apiKey = args[i + 1];
|
|
27
|
-
i++;
|
|
28
|
-
} else if (args[i] === '--legacy-middleware') {
|
|
29
|
-
useProxy = false;
|
|
30
|
-
} else if (args[i] === '--help' || args[i] === '-h') {
|
|
31
|
-
console.log('Usage: egdesk-next-setup [options]');
|
|
32
|
-
console.log('');
|
|
33
|
-
console.log('Options:');
|
|
34
|
-
console.log(' --url <url> EGDesk server URL (default: http://localhost:8080)');
|
|
35
|
-
console.log(' --api-key <key> API key for authentication');
|
|
36
|
-
console.log(' --legacy-middleware Use middleware.ts instead of proxy.ts (for Next.js <16)');
|
|
37
|
-
console.log(' --help, -h Show this help message');
|
|
38
|
-
console.log('');
|
|
39
|
-
console.log('Example:');
|
|
40
|
-
console.log(' egdesk-next-setup --url http://localhost:8080 --api-key mykey');
|
|
41
|
-
console.log(' egdesk-next-setup --legacy-middleware # For Next.js <16');
|
|
42
|
-
process.exit(0);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Get current working directory (project root)
|
|
47
|
-
const projectPath = process.cwd();
|
|
48
|
-
|
|
49
|
-
console.log('🚀 EGDesk Next.js Setup');
|
|
50
|
-
console.log(`📂 Project: ${projectPath}`);
|
|
51
|
-
console.log(`🔗 EGDesk URL: ${egdeskUrl}`);
|
|
52
|
-
console.log('');
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
await setupNextApiPlugin(projectPath, { egdeskUrl, apiKey, useProxy });
|
|
56
|
-
process.exit(0);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
console.error('Setup failed:', error);
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
main();
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate API wrapper for handling basePath in client-side fetch calls
|
|
3
|
-
*
|
|
4
|
-
* Creates lib/api.ts (or src/lib/api.ts) that re-exports apiFetch from egdesk-helpers.ts
|
|
5
|
-
* so apps can use either import path.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import * as fs from 'fs';
|
|
9
|
-
import * as path from 'path';
|
|
10
|
-
import * as os from 'os';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Detect if project uses src/ directory structure
|
|
14
|
-
*/
|
|
15
|
-
function usesSrcDirectory(projectPath: string): boolean {
|
|
16
|
-
const srcPath = path.join(projectPath, 'src');
|
|
17
|
-
const srcAppPath = path.join(projectPath, 'src', 'app');
|
|
18
|
-
return fs.existsSync(srcPath) && fs.existsSync(srcAppPath);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Ensure lib directory exists
|
|
23
|
-
*/
|
|
24
|
-
function ensureLibDirectory(projectPath: string): string {
|
|
25
|
-
const hasSrc = usesSrcDirectory(projectPath);
|
|
26
|
-
const libDir = hasSrc
|
|
27
|
-
? path.join(projectPath, 'src', 'lib')
|
|
28
|
-
: path.join(projectPath, 'lib');
|
|
29
|
-
|
|
30
|
-
if (!fs.existsSync(libDir)) {
|
|
31
|
-
fs.mkdirSync(libDir, { recursive: true });
|
|
32
|
-
console.log(`📁 Created directory: ${libDir}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return libDir;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Generate lib/api.ts file that re-exports basePath-aware fetch from egdesk-helpers
|
|
40
|
-
*/
|
|
41
|
-
export function generateApiWrapper(projectPath: string): void {
|
|
42
|
-
const libDir = ensureLibDirectory(projectPath);
|
|
43
|
-
const apiPath = path.join(libDir, 'api.ts');
|
|
44
|
-
const hasSrc = usesSrcDirectory(projectPath);
|
|
45
|
-
const helpersImport = hasSrc ? '../../egdesk-helpers' : '../egdesk-helpers';
|
|
46
|
-
|
|
47
|
-
console.log(`📝 Generating API wrapper at: ${apiPath}`);
|
|
48
|
-
|
|
49
|
-
if (fs.existsSync(apiPath)) {
|
|
50
|
-
console.log('⚠️ api.ts already exists - backing up to api.backup.ts');
|
|
51
|
-
const backupPath = path.join(libDir, 'api.backup.ts');
|
|
52
|
-
fs.copyFileSync(apiPath, backupPath);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const apiContent = `/**
|
|
56
|
-
* API Fetch Wrapper for EGDesk Tunneling
|
|
57
|
-
*
|
|
58
|
-
* Re-exports apiFetch from egdesk-helpers.ts (canonical source).
|
|
59
|
-
* Use apiFetch for client-side /api/* calls — Next.js basePath does not apply to fetch().
|
|
60
|
-
*
|
|
61
|
-
* Generated by @egdesk/next-api-plugin
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
export { apiFetch, getEgdeskBasePath } from '${helpersImport}';
|
|
65
|
-
`;
|
|
66
|
-
|
|
67
|
-
fs.writeFileSync(apiPath, apiContent.replace(/\r?\n/g, os.EOL), 'utf-8');
|
|
68
|
-
console.log(`✅ Generated ${apiPath}`);
|
|
69
|
-
}
|