@egdesk/next-api-plugin 1.3.0 → 1.3.2
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 +86 -40
- package/dist/setup-userdata.js +12 -4
- package/package.json +1 -1
- package/src/generate-helpers.ts +86 -40
- package/src/setup-userdata.ts +17 -5
package/dist/generate-helpers.js
CHANGED
|
@@ -50,7 +50,7 @@ function generateHelpers(projectPath) {
|
|
|
50
50
|
const helperContent = `/**
|
|
51
51
|
* EGDesk Helper Functions for Next.js
|
|
52
52
|
*
|
|
53
|
-
* Type-safe helpers for EGDesk user data, FinanceHub, and browser recorder replay.
|
|
53
|
+
* Type-safe helpers for EGDesk user data, FinanceHub (banks, cards, Hometax), and browser recorder replay.
|
|
54
54
|
* Works in both client and server components.
|
|
55
55
|
*
|
|
56
56
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -58,6 +58,45 @@ function generateHelpers(projectPath) {
|
|
|
58
58
|
|
|
59
59
|
import { EGDESK_CONFIG } from './egdesk.config';
|
|
60
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Parse EGDesk MCP \`/tools/call\` JSON so \`error\` is shown even when HTTP status is 500.
|
|
63
|
+
*/
|
|
64
|
+
async function parseEgdeskMcpToolResponse(response: Response): Promise<any> {
|
|
65
|
+
const result = await response.json().catch(() => null);
|
|
66
|
+
|
|
67
|
+
if (result && typeof result === 'object' && result.success === false) {
|
|
68
|
+
const errMsg =
|
|
69
|
+
typeof result.error === 'string'
|
|
70
|
+
? result.error
|
|
71
|
+
: result.error != null
|
|
72
|
+
? String(result.error)
|
|
73
|
+
: 'Tool call failed';
|
|
74
|
+
throw new Error(errMsg);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
let fromBody = '';
|
|
79
|
+
if (result && typeof result === 'object') {
|
|
80
|
+
if (typeof result.error === 'string') fromBody = result.error;
|
|
81
|
+
else if (typeof (result as { message?: string }).message === 'string') {
|
|
82
|
+
fromBody = (result as { message: string }).message;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
throw new Error(fromBody || \`HTTP \${response.status}: \${response.statusText}\`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (!result || result.success !== true) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
result && typeof result === 'object' && typeof result.error === 'string'
|
|
91
|
+
? result.error
|
|
92
|
+
: 'Tool call failed'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const content = result.result?.content?.[0]?.text;
|
|
97
|
+
return content ? JSON.parse(content) : null;
|
|
98
|
+
}
|
|
99
|
+
|
|
61
100
|
/**
|
|
62
101
|
* Call EGDesk user-data MCP tool
|
|
63
102
|
*
|
|
@@ -103,19 +142,7 @@ export async function callUserDataTool(
|
|
|
103
142
|
});
|
|
104
143
|
}
|
|
105
144
|
|
|
106
|
-
|
|
107
|
-
throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const result = await response.json();
|
|
111
|
-
|
|
112
|
-
if (!result.success) {
|
|
113
|
-
throw new Error(result.error || 'Tool call failed');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Parse MCP response format
|
|
117
|
-
const content = result.result?.content?.[0]?.text;
|
|
118
|
-
return content ? JSON.parse(content) : null;
|
|
145
|
+
return parseEgdeskMcpToolResponse(response);
|
|
119
146
|
}
|
|
120
147
|
|
|
121
148
|
/**
|
|
@@ -298,7 +325,7 @@ export async function callFinanceHubTool(
|
|
|
298
325
|
toolName: string,
|
|
299
326
|
args: Record<string, any> = {}
|
|
300
327
|
): Promise<any> {
|
|
301
|
-
const body = JSON.stringify({ tool: toolName, args });
|
|
328
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
302
329
|
const headers: Record<string, string> = {
|
|
303
330
|
'Content-Type': 'application/json'
|
|
304
331
|
};
|
|
@@ -329,18 +356,7 @@ export async function callFinanceHubTool(
|
|
|
329
356
|
});
|
|
330
357
|
}
|
|
331
358
|
|
|
332
|
-
|
|
333
|
-
throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const result = await response.json();
|
|
337
|
-
|
|
338
|
-
if (!result.success) {
|
|
339
|
-
throw new Error(result.error || 'Tool call failed');
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const content = result.result?.content?.[0]?.text;
|
|
343
|
-
return content ? JSON.parse(content) : null;
|
|
359
|
+
return parseEgdeskMcpToolResponse(response);
|
|
344
360
|
}
|
|
345
361
|
|
|
346
362
|
/**
|
|
@@ -434,12 +450,53 @@ export async function getOverallStats() {
|
|
|
434
450
|
}
|
|
435
451
|
|
|
436
452
|
/**
|
|
437
|
-
* Get sync operation history
|
|
453
|
+
* Get bank/card sync operation history (sync_operations table)
|
|
438
454
|
*/
|
|
439
455
|
export async function getSyncHistory(limit: number = 50) {
|
|
440
456
|
return callFinanceHubTool('financehub_get_sync_history', { limit });
|
|
441
457
|
}
|
|
442
458
|
|
|
459
|
+
/**
|
|
460
|
+
* List Hometax business connections (hometax_connections: counts, spreadsheet URLs, status)
|
|
461
|
+
*/
|
|
462
|
+
export async function listHometaxConnections() {
|
|
463
|
+
return callFinanceHubTool('financehub_list_hometax_connections', {});
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Query electronic tax invoices synced from Hometax (tax_invoices table)
|
|
468
|
+
*/
|
|
469
|
+
export async function queryTaxInvoices(options: {
|
|
470
|
+
businessNumber?: string;
|
|
471
|
+
invoiceType?: 'sales' | 'purchase';
|
|
472
|
+
startDate?: string;
|
|
473
|
+
endDate?: string;
|
|
474
|
+
limit?: number;
|
|
475
|
+
offset?: number;
|
|
476
|
+
} = {}) {
|
|
477
|
+
return callFinanceHubTool('financehub_query_tax_invoices', options);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Query cash receipts synced from Hometax (cash_receipts table)
|
|
482
|
+
*/
|
|
483
|
+
export async function queryCashReceipts(options: {
|
|
484
|
+
businessNumber?: string;
|
|
485
|
+
startDate?: string;
|
|
486
|
+
endDate?: string;
|
|
487
|
+
limit?: number;
|
|
488
|
+
offset?: number;
|
|
489
|
+
} = {}) {
|
|
490
|
+
return callFinanceHubTool('financehub_query_cash_receipts', options);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Get Hometax Excel import sync history (hometax_sync_operations). Not the same as getSyncHistory (banks/cards).
|
|
495
|
+
*/
|
|
496
|
+
export async function getHometaxSyncHistory(limit: number = 50) {
|
|
497
|
+
return callFinanceHubTool('financehub_get_hometax_sync_history', { limit });
|
|
498
|
+
}
|
|
499
|
+
|
|
443
500
|
// ==========================================
|
|
444
501
|
// BROWSER RECORDING HELPERS
|
|
445
502
|
// ==========================================
|
|
@@ -485,18 +542,7 @@ export async function callBrowserRecordingTool(
|
|
|
485
542
|
});
|
|
486
543
|
}
|
|
487
544
|
|
|
488
|
-
|
|
489
|
-
throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
const result = await response.json();
|
|
493
|
-
|
|
494
|
-
if (!result.success) {
|
|
495
|
-
throw new Error(result.error || 'Tool call failed');
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
const content = result.result?.content?.[0]?.text;
|
|
499
|
-
return content ? JSON.parse(content) : null;
|
|
545
|
+
return parseEgdeskMcpToolResponse(response);
|
|
500
546
|
}
|
|
501
547
|
|
|
502
548
|
/** List saved *.spec.js files in the EGDesk browser-recorder-tests output folder */
|
package/dist/setup-userdata.js
CHANGED
|
@@ -66,12 +66,20 @@ async function discoverTables(egdeskUrl = 'http://localhost:8080', apiKey) {
|
|
|
66
66
|
arguments: {}
|
|
67
67
|
})
|
|
68
68
|
});
|
|
69
|
+
const listResult = await listResponse.json().catch(() => null);
|
|
70
|
+
if (listResult && typeof listResult === 'object' && listResult.success === false) {
|
|
71
|
+
throw new Error(listResult.error || 'Failed to list tables');
|
|
72
|
+
}
|
|
69
73
|
if (!listResponse.ok) {
|
|
70
|
-
|
|
74
|
+
const fromBody = listResult && typeof listResult === 'object' && typeof listResult.error === 'string'
|
|
75
|
+
? listResult.error
|
|
76
|
+
: '';
|
|
77
|
+
throw new Error(fromBody || `Failed to list tables: ${listResponse.status} ${listResponse.statusText}`);
|
|
71
78
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
if (!listResult || !listResult.success) {
|
|
80
|
+
throw new Error(listResult && typeof listResult === 'object' && listResult.error
|
|
81
|
+
? String(listResult.error)
|
|
82
|
+
: 'Failed to list tables');
|
|
75
83
|
}
|
|
76
84
|
// Parse MCP response
|
|
77
85
|
const content = listResult.result?.content?.[0]?.text;
|
package/package.json
CHANGED
package/src/generate-helpers.ts
CHANGED
|
@@ -17,7 +17,7 @@ export function generateHelpers(projectPath: string): void {
|
|
|
17
17
|
const helperContent = `/**
|
|
18
18
|
* EGDesk Helper Functions for Next.js
|
|
19
19
|
*
|
|
20
|
-
* Type-safe helpers for EGDesk user data, FinanceHub, and browser recorder replay.
|
|
20
|
+
* Type-safe helpers for EGDesk user data, FinanceHub (banks, cards, Hometax), and browser recorder replay.
|
|
21
21
|
* Works in both client and server components.
|
|
22
22
|
*
|
|
23
23
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -25,6 +25,45 @@ export function generateHelpers(projectPath: string): void {
|
|
|
25
25
|
|
|
26
26
|
import { EGDESK_CONFIG } from './egdesk.config';
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Parse EGDesk MCP \`/tools/call\` JSON so \`error\` is shown even when HTTP status is 500.
|
|
30
|
+
*/
|
|
31
|
+
async function parseEgdeskMcpToolResponse(response: Response): Promise<any> {
|
|
32
|
+
const result = await response.json().catch(() => null);
|
|
33
|
+
|
|
34
|
+
if (result && typeof result === 'object' && result.success === false) {
|
|
35
|
+
const errMsg =
|
|
36
|
+
typeof result.error === 'string'
|
|
37
|
+
? result.error
|
|
38
|
+
: result.error != null
|
|
39
|
+
? String(result.error)
|
|
40
|
+
: 'Tool call failed';
|
|
41
|
+
throw new Error(errMsg);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
let fromBody = '';
|
|
46
|
+
if (result && typeof result === 'object') {
|
|
47
|
+
if (typeof result.error === 'string') fromBody = result.error;
|
|
48
|
+
else if (typeof (result as { message?: string }).message === 'string') {
|
|
49
|
+
fromBody = (result as { message: string }).message;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw new Error(fromBody || \`HTTP \${response.status}: \${response.statusText}\`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!result || result.success !== true) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
result && typeof result === 'object' && typeof result.error === 'string'
|
|
58
|
+
? result.error
|
|
59
|
+
: 'Tool call failed'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const content = result.result?.content?.[0]?.text;
|
|
64
|
+
return content ? JSON.parse(content) : null;
|
|
65
|
+
}
|
|
66
|
+
|
|
28
67
|
/**
|
|
29
68
|
* Call EGDesk user-data MCP tool
|
|
30
69
|
*
|
|
@@ -70,19 +109,7 @@ export async function callUserDataTool(
|
|
|
70
109
|
});
|
|
71
110
|
}
|
|
72
111
|
|
|
73
|
-
|
|
74
|
-
throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const result = await response.json();
|
|
78
|
-
|
|
79
|
-
if (!result.success) {
|
|
80
|
-
throw new Error(result.error || 'Tool call failed');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Parse MCP response format
|
|
84
|
-
const content = result.result?.content?.[0]?.text;
|
|
85
|
-
return content ? JSON.parse(content) : null;
|
|
112
|
+
return parseEgdeskMcpToolResponse(response);
|
|
86
113
|
}
|
|
87
114
|
|
|
88
115
|
/**
|
|
@@ -265,7 +292,7 @@ export async function callFinanceHubTool(
|
|
|
265
292
|
toolName: string,
|
|
266
293
|
args: Record<string, any> = {}
|
|
267
294
|
): Promise<any> {
|
|
268
|
-
const body = JSON.stringify({ tool: toolName, args });
|
|
295
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
269
296
|
const headers: Record<string, string> = {
|
|
270
297
|
'Content-Type': 'application/json'
|
|
271
298
|
};
|
|
@@ -296,18 +323,7 @@ export async function callFinanceHubTool(
|
|
|
296
323
|
});
|
|
297
324
|
}
|
|
298
325
|
|
|
299
|
-
|
|
300
|
-
throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const result = await response.json();
|
|
304
|
-
|
|
305
|
-
if (!result.success) {
|
|
306
|
-
throw new Error(result.error || 'Tool call failed');
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const content = result.result?.content?.[0]?.text;
|
|
310
|
-
return content ? JSON.parse(content) : null;
|
|
326
|
+
return parseEgdeskMcpToolResponse(response);
|
|
311
327
|
}
|
|
312
328
|
|
|
313
329
|
/**
|
|
@@ -401,12 +417,53 @@ export async function getOverallStats() {
|
|
|
401
417
|
}
|
|
402
418
|
|
|
403
419
|
/**
|
|
404
|
-
* Get sync operation history
|
|
420
|
+
* Get bank/card sync operation history (sync_operations table)
|
|
405
421
|
*/
|
|
406
422
|
export async function getSyncHistory(limit: number = 50) {
|
|
407
423
|
return callFinanceHubTool('financehub_get_sync_history', { limit });
|
|
408
424
|
}
|
|
409
425
|
|
|
426
|
+
/**
|
|
427
|
+
* List Hometax business connections (hometax_connections: counts, spreadsheet URLs, status)
|
|
428
|
+
*/
|
|
429
|
+
export async function listHometaxConnections() {
|
|
430
|
+
return callFinanceHubTool('financehub_list_hometax_connections', {});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Query electronic tax invoices synced from Hometax (tax_invoices table)
|
|
435
|
+
*/
|
|
436
|
+
export async function queryTaxInvoices(options: {
|
|
437
|
+
businessNumber?: string;
|
|
438
|
+
invoiceType?: 'sales' | 'purchase';
|
|
439
|
+
startDate?: string;
|
|
440
|
+
endDate?: string;
|
|
441
|
+
limit?: number;
|
|
442
|
+
offset?: number;
|
|
443
|
+
} = {}) {
|
|
444
|
+
return callFinanceHubTool('financehub_query_tax_invoices', options);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Query cash receipts synced from Hometax (cash_receipts table)
|
|
449
|
+
*/
|
|
450
|
+
export async function queryCashReceipts(options: {
|
|
451
|
+
businessNumber?: string;
|
|
452
|
+
startDate?: string;
|
|
453
|
+
endDate?: string;
|
|
454
|
+
limit?: number;
|
|
455
|
+
offset?: number;
|
|
456
|
+
} = {}) {
|
|
457
|
+
return callFinanceHubTool('financehub_query_cash_receipts', options);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Get Hometax Excel import sync history (hometax_sync_operations). Not the same as getSyncHistory (banks/cards).
|
|
462
|
+
*/
|
|
463
|
+
export async function getHometaxSyncHistory(limit: number = 50) {
|
|
464
|
+
return callFinanceHubTool('financehub_get_hometax_sync_history', { limit });
|
|
465
|
+
}
|
|
466
|
+
|
|
410
467
|
// ==========================================
|
|
411
468
|
// BROWSER RECORDING HELPERS
|
|
412
469
|
// ==========================================
|
|
@@ -452,18 +509,7 @@ export async function callBrowserRecordingTool(
|
|
|
452
509
|
});
|
|
453
510
|
}
|
|
454
511
|
|
|
455
|
-
|
|
456
|
-
throw new Error(\`HTTP \${response.status}: \${response.statusText}\`);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const result = await response.json();
|
|
460
|
-
|
|
461
|
-
if (!result.success) {
|
|
462
|
-
throw new Error(result.error || 'Tool call failed');
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
const content = result.result?.content?.[0]?.text;
|
|
466
|
-
return content ? JSON.parse(content) : null;
|
|
512
|
+
return parseEgdeskMcpToolResponse(response);
|
|
467
513
|
}
|
|
468
514
|
|
|
469
515
|
/** List saved *.spec.js files in the EGDesk browser-recorder-tests output folder */
|
package/src/setup-userdata.ts
CHANGED
|
@@ -53,14 +53,26 @@ export async function discoverTables(
|
|
|
53
53
|
})
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const listResult = await listResponse.json().catch(() => null);
|
|
57
|
+
|
|
58
|
+
if (listResult && typeof listResult === 'object' && listResult.success === false) {
|
|
59
|
+
throw new Error(listResult.error || 'Failed to list tables');
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
if (!listResponse.ok) {
|
|
63
|
+
const fromBody =
|
|
64
|
+
listResult && typeof listResult === 'object' && typeof listResult.error === 'string'
|
|
65
|
+
? listResult.error
|
|
66
|
+
: '';
|
|
67
|
+
throw new Error(fromBody || `Failed to list tables: ${listResponse.status} ${listResponse.statusText}`);
|
|
68
|
+
}
|
|
61
69
|
|
|
62
|
-
if (!listResult.success) {
|
|
63
|
-
throw new Error(
|
|
70
|
+
if (!listResult || !listResult.success) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
listResult && typeof listResult === 'object' && listResult.error
|
|
73
|
+
? String(listResult.error)
|
|
74
|
+
: 'Failed to list tables'
|
|
75
|
+
);
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
// Parse MCP response
|