@egdesk/next-api-plugin 1.5.10 → 1.5.12
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/index.d.ts +2 -2
- package/dist/index.js +28 -5
- package/dist/setup-userdata.d.ts +5 -0
- package/dist/setup-userdata.js +73 -0
- package/package.json +1 -1
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.18";
|
|
12
12
|
export interface SetupOptions {
|
|
13
13
|
egdeskUrl?: string;
|
|
14
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
|
@@ -37,7 +37,7 @@ export declare function detectNextUseProxy(projectPath: string): boolean;
|
|
|
37
37
|
*/
|
|
38
38
|
export declare function setupNextApiPlugin(projectPath: string, options?: SetupOptions): Promise<void>;
|
|
39
39
|
export type { UserDataTable, UserDataConfig } from './setup-userdata';
|
|
40
|
-
export { discoverTables } from './setup-userdata';
|
|
40
|
+
export { discoverTables, generateConfigFile, loadTablesFromSchemaFile, updateEnvFiles } from './setup-userdata';
|
|
41
41
|
export { generateMiddleware } from './generate-middleware';
|
|
42
42
|
export { generateProxy } from './generate-proxy';
|
|
43
43
|
export { generateHelpers, generateSchemaFile, ensureSchemaFile, formatEgdeskSchemaFileContent } from './generate-helpers';
|
package/dist/index.js
CHANGED
|
@@ -39,14 +39,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.generateApiWrapper = exports.formatEgdeskSchemaFileContent = exports.ensureSchemaFile = exports.generateSchemaFile = exports.generateHelpers = exports.generateProxy = exports.generateMiddleware = exports.discoverTables = exports.COMPATIBLE_APP_VERSION = void 0;
|
|
42
|
+
exports.generateApiWrapper = exports.formatEgdeskSchemaFileContent = exports.ensureSchemaFile = exports.generateSchemaFile = exports.generateHelpers = exports.generateProxy = exports.generateMiddleware = exports.updateEnvFiles = exports.loadTablesFromSchemaFile = exports.generateConfigFile = exports.discoverTables = exports.COMPATIBLE_APP_VERSION = void 0;
|
|
43
43
|
exports.detectNextUseProxy = detectNextUseProxy;
|
|
44
44
|
exports.setupNextApiPlugin = setupNextApiPlugin;
|
|
45
45
|
/**
|
|
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.18';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
@@ -118,21 +118,41 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
118
118
|
const { egdeskUrl = 'http://localhost:8080', prodEgdeskUrl, discoveryUrl, egdeskProjectId, apiKey, useProxy } = options;
|
|
119
119
|
const resolvedUseProxy = useProxy ?? detectNextUseProxy(projectPath);
|
|
120
120
|
console.log('🔍 Discovering EGDesk user-data tables...');
|
|
121
|
+
let devTables = [];
|
|
122
|
+
let prodTables = [];
|
|
123
|
+
let apiKeyNames = [];
|
|
124
|
+
let usedSchemaFallback = false;
|
|
121
125
|
try {
|
|
122
|
-
|
|
126
|
+
[devTables, prodTables, apiKeyNames] = await Promise.all([
|
|
123
127
|
(0, setup_userdata_1.discoverTables)(discoveryUrl ?? egdeskUrl, apiKey, egdeskProjectId, 'development'),
|
|
124
128
|
(0, setup_userdata_1.discoverTables)(discoveryUrl ?? egdeskUrl, apiKey, egdeskProjectId, 'production'),
|
|
125
129
|
discoverApiKeyNames(discoveryUrl ?? egdeskUrl, apiKey, egdeskProjectId),
|
|
126
130
|
]);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('❌ Live table discovery failed:', error);
|
|
134
|
+
console.warn('⚠️ Falling back to egdesk.schema.ts so egdesk.config.ts / helpers are still generated');
|
|
135
|
+
devTables = (0, setup_userdata_1.loadTablesFromSchemaFile)(projectPath);
|
|
136
|
+
prodTables = [];
|
|
137
|
+
usedSchemaFallback = true;
|
|
138
|
+
try {
|
|
139
|
+
apiKeyNames = await discoverApiKeyNames(discoveryUrl ?? egdeskUrl, apiKey, egdeskProjectId);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
apiKeyNames = [];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
127
146
|
if (devTables.length === 0) {
|
|
128
147
|
console.warn('⚠️ No tables found. Import data in EGDesk first.');
|
|
129
148
|
console.log('');
|
|
130
149
|
console.log('Generating files anyway with empty table list...');
|
|
131
150
|
}
|
|
132
151
|
else {
|
|
133
|
-
|
|
152
|
+
const source = usedSchemaFallback ? 'schema fallback' : 'live discovery';
|
|
153
|
+
console.log(`✅ Found ${devTables.length} dev table(s), ${prodTables.length} prod table(s) (${source}):`);
|
|
134
154
|
devTables.forEach((table, index) => {
|
|
135
|
-
console.log(` ${index + 1}. ${table.displayName} (${table.rowCount} rows)`);
|
|
155
|
+
console.log(` ${index + 1}. ${table.displayName} (${table.rowCount ?? 0} rows)`);
|
|
136
156
|
});
|
|
137
157
|
}
|
|
138
158
|
if (apiKeyNames.length > 0) {
|
|
@@ -200,6 +220,9 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
200
220
|
}
|
|
201
221
|
var setup_userdata_2 = require("./setup-userdata");
|
|
202
222
|
Object.defineProperty(exports, "discoverTables", { enumerable: true, get: function () { return setup_userdata_2.discoverTables; } });
|
|
223
|
+
Object.defineProperty(exports, "generateConfigFile", { enumerable: true, get: function () { return setup_userdata_2.generateConfigFile; } });
|
|
224
|
+
Object.defineProperty(exports, "loadTablesFromSchemaFile", { enumerable: true, get: function () { return setup_userdata_2.loadTablesFromSchemaFile; } });
|
|
225
|
+
Object.defineProperty(exports, "updateEnvFiles", { enumerable: true, get: function () { return setup_userdata_2.updateEnvFiles; } });
|
|
203
226
|
var generate_middleware_2 = require("./generate-middleware");
|
|
204
227
|
Object.defineProperty(exports, "generateMiddleware", { enumerable: true, get: function () { return generate_middleware_2.generateMiddleware; } });
|
|
205
228
|
var generate_proxy_2 = require("./generate-proxy");
|
package/dist/setup-userdata.d.ts
CHANGED
|
@@ -48,6 +48,11 @@ export declare function updateEnvLocal(projectPath: string, config: UserDataConf
|
|
|
48
48
|
export declare function updateEnvFiles(projectPath: string, config: UserDataConfig,
|
|
49
49
|
/** Tables discovered for the production environment. Falls back to config.tables when omitted. */
|
|
50
50
|
prodTables?: UserDataTable[]): void;
|
|
51
|
+
/**
|
|
52
|
+
* Parse TABLES from egdesk.schema.ts (or a leftover egdesk.config.ts) when
|
|
53
|
+
* live discovery fails. Returns [] if the file is missing or unparseable.
|
|
54
|
+
*/
|
|
55
|
+
export declare function loadTablesFromSchemaFile(projectPath: string): UserDataTable[];
|
|
51
56
|
/**
|
|
52
57
|
* Generate TypeScript config file with table definitions
|
|
53
58
|
*/
|
package/dist/setup-userdata.js
CHANGED
|
@@ -43,6 +43,7 @@ exports.discoverTables = discoverTables;
|
|
|
43
43
|
exports.readEnvLocal = readEnvLocal;
|
|
44
44
|
exports.updateEnvLocal = updateEnvLocal;
|
|
45
45
|
exports.updateEnvFiles = updateEnvFiles;
|
|
46
|
+
exports.loadTablesFromSchemaFile = loadTablesFromSchemaFile;
|
|
46
47
|
exports.generateConfigFile = generateConfigFile;
|
|
47
48
|
const fs = __importStar(require("fs"));
|
|
48
49
|
const path = __importStar(require("path"));
|
|
@@ -262,6 +263,78 @@ prodTables) {
|
|
|
262
263
|
const prodPath = path.join(projectPath, '.env.production.local');
|
|
263
264
|
writeEnvFile(prodPath, config.prodBaseUrl ?? config.baseUrl, 'production', 'production', prodTables ?? config.tables);
|
|
264
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Parse TABLES from egdesk.schema.ts (or a leftover egdesk.config.ts) when
|
|
268
|
+
* live discovery fails. Returns [] if the file is missing or unparseable.
|
|
269
|
+
*/
|
|
270
|
+
function loadTablesFromSchemaFile(projectPath) {
|
|
271
|
+
const candidates = [
|
|
272
|
+
path.join(projectPath, 'egdesk.schema.ts'),
|
|
273
|
+
path.join(projectPath, 'egdesk.config.ts'),
|
|
274
|
+
];
|
|
275
|
+
for (const filePath of candidates) {
|
|
276
|
+
if (!fs.existsSync(filePath))
|
|
277
|
+
continue;
|
|
278
|
+
try {
|
|
279
|
+
const fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
280
|
+
const tablesMatch = fileContent.match(/export\s+const\s+TABLES\s*=\s*\{([\s\S]*?)\}\s*as\s+const/);
|
|
281
|
+
if (!tablesMatch)
|
|
282
|
+
continue;
|
|
283
|
+
const body = tablesMatch[1];
|
|
284
|
+
const tables = [];
|
|
285
|
+
const entryRegex = /\w+\s*:\s*\{/g;
|
|
286
|
+
let match;
|
|
287
|
+
while ((match = entryRegex.exec(body)) !== null) {
|
|
288
|
+
const start = match.index + match[0].length - 1;
|
|
289
|
+
let depth = 0;
|
|
290
|
+
let end = -1;
|
|
291
|
+
for (let i = start; i < body.length; i++) {
|
|
292
|
+
if (body[i] === '{')
|
|
293
|
+
depth++;
|
|
294
|
+
else if (body[i] === '}') {
|
|
295
|
+
depth--;
|
|
296
|
+
if (depth === 0) {
|
|
297
|
+
end = i;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (end === -1)
|
|
303
|
+
continue;
|
|
304
|
+
const block = body.slice(start + 1, end);
|
|
305
|
+
const nameMatch = block.match(/\bname\s*:\s*['"`]([^'"`]+)['"`]/);
|
|
306
|
+
const displayNameMatch = block.match(/\bdisplayName\s*:\s*['"`]([^'"`]+)['"`]/);
|
|
307
|
+
const columnsMatch = block.match(/\bcolumns\s*:\s*\[([\s\S]*?)\]/);
|
|
308
|
+
if (!nameMatch || !displayNameMatch || !columnsMatch)
|
|
309
|
+
continue;
|
|
310
|
+
const columns = [];
|
|
311
|
+
const colRegex = /['"`]([^'"`]+)['"`]/g;
|
|
312
|
+
let colMatch;
|
|
313
|
+
while ((colMatch = colRegex.exec(columnsMatch[1])) !== null) {
|
|
314
|
+
columns.push(colMatch[1]);
|
|
315
|
+
}
|
|
316
|
+
if (columns.length === 0)
|
|
317
|
+
continue;
|
|
318
|
+
tables.push({
|
|
319
|
+
id: nameMatch[1],
|
|
320
|
+
tableName: nameMatch[1],
|
|
321
|
+
displayName: displayNameMatch[1],
|
|
322
|
+
columnCount: columns.length,
|
|
323
|
+
columns,
|
|
324
|
+
rowCount: 0,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (tables.length > 0) {
|
|
328
|
+
console.log(`📋 Loaded ${tables.length} table(s) from ${path.basename(filePath)} (discovery fallback)`);
|
|
329
|
+
return tables;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
console.warn(`⚠️ Failed to parse ${filePath} for discovery fallback:`, err);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return [];
|
|
337
|
+
}
|
|
265
338
|
/**
|
|
266
339
|
* Generate TypeScript config file with table definitions
|
|
267
340
|
*/
|