@egdesk/next-api-plugin 1.3.1 → 1.4.0
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 +31 -9
- package/dist/generate-helpers.js +199 -5
- package/dist/generate-middleware.js +34 -2
- package/dist/generate-proxy.js +35 -3
- package/package.json +1 -1
- package/src/generate-helpers.ts +199 -5
- package/src/generate-middleware.ts +34 -2
- package/src/generate-proxy.ts +35 -3
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Next.js plugin for EGDesk database proxy integration. Provides middleware-based
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- 🔒 CORS-free database access via Next.js middleware
|
|
7
|
+
- 🔒 CORS-free database access via Next.js middleware (or `proxy.ts` on Next.js 16+)
|
|
8
8
|
- 🌐 Works in both local and tunneled environments
|
|
9
|
-
- 📝 Type-safe table definitions and helper functions
|
|
9
|
+
- 📝 Type-safe table definitions and helper functions (user data, FinanceHub, internal knowledge / business identity / company research, browser recording)
|
|
10
10
|
- 🚀 Auto-discovery of database tables
|
|
11
11
|
- 🔧 Zero configuration after setup
|
|
12
12
|
|
|
@@ -81,14 +81,21 @@ await setupNextApiPlugin('/path/to/project', {
|
|
|
81
81
|
|
|
82
82
|
## How It Works
|
|
83
83
|
|
|
84
|
-
The plugin
|
|
84
|
+
The plugin generates `middleware.ts` or `proxy.ts` that intercepts special paths and forwards them to your EGDesk HTTP MCP server so the browser never talks to another origin directly.
|
|
85
85
|
|
|
86
|
-
**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
**Proxied paths (examples):**
|
|
87
|
+
|
|
88
|
+
| Path | Forwards to |
|
|
89
|
+
|------|-------------|
|
|
90
|
+
| `__user_data_proxy` | `POST /user-data/tools/call` |
|
|
91
|
+
| `__browser_recording_proxy` | `POST /browser-recording/tools/call` |
|
|
92
|
+
| `__internal_knowledge_proxy` | `POST /internal-knowledge/tools/call` (knowledge docs, business identity snapshots, company research) |
|
|
93
|
+
|
|
94
|
+
**User-data request flow:**
|
|
95
|
+
1. Your code calls `queryTable()` or another helper
|
|
96
|
+
2. Helper fetches `__user_data_proxy`
|
|
97
|
+
3. Middleware/proxy forwards to `http://<EGDESK>/user-data/tools/call`
|
|
98
|
+
4. Parsed JSON is returned to your component
|
|
92
99
|
|
|
93
100
|
## API Reference
|
|
94
101
|
|
|
@@ -121,6 +128,21 @@ listTables()
|
|
|
121
128
|
|
|
122
129
|
// Get table schema
|
|
123
130
|
getTableSchema(tableName: string)
|
|
131
|
+
|
|
132
|
+
// Internal Knowledge / Business Identity / Company Research (MCP)
|
|
133
|
+
callInternalKnowledgeTool(toolName: string, args?: Record<string, any>)
|
|
134
|
+
listKnowledgeDocuments(snapshotId: string, category?: 'hierarchy' | 'process' | 'policy' | 'note')
|
|
135
|
+
getKnowledgeDocument(documentId: string)
|
|
136
|
+
searchKnowledgeContent(snapshotId: string, searchText: string, category?: ...)
|
|
137
|
+
getKnowledgeByCategory(snapshotId: string, category: ...)
|
|
138
|
+
listBusinessIdentitySnapshots(brandKey?: string)
|
|
139
|
+
getBusinessIdentitySnapshot(snapshotId: string)
|
|
140
|
+
getBusinessIdentityCompanyInfo(snapshotId: string)
|
|
141
|
+
getBusinessIdentityServicesProducts(snapshotId: string)
|
|
142
|
+
listCompanyResearch(status?: 'completed' | 'failed' | 'in_progress')
|
|
143
|
+
getCompanyResearchById(researchId: string)
|
|
144
|
+
getCompanyResearchByDomain(domain: string)
|
|
145
|
+
searchCompanyResearch(searchText: string)
|
|
124
146
|
```
|
|
125
147
|
|
|
126
148
|
### Configuration Types
|
package/dist/generate-helpers.js
CHANGED
|
@@ -50,7 +50,8 @@ 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,
|
|
53
|
+
* Type-safe helpers for EGDesk user data, FinanceHub (banks, cards, Hometax, promissory notes),
|
|
54
|
+
* internal knowledge / business identity / company research (MCP), and browser recorder replay.
|
|
54
55
|
* Works in both client and server components.
|
|
55
56
|
*
|
|
56
57
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -325,7 +326,7 @@ export async function callFinanceHubTool(
|
|
|
325
326
|
toolName: string,
|
|
326
327
|
args: Record<string, any> = {}
|
|
327
328
|
): Promise<any> {
|
|
328
|
-
const body = JSON.stringify({ tool: toolName, args });
|
|
329
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
329
330
|
const headers: Record<string, string> = {
|
|
330
331
|
'Content-Type': 'application/json'
|
|
331
332
|
};
|
|
@@ -450,12 +451,203 @@ export async function getOverallStats() {
|
|
|
450
451
|
}
|
|
451
452
|
|
|
452
453
|
/**
|
|
453
|
-
* Get sync operation history
|
|
454
|
+
* Get bank/card sync operation history (sync_operations table)
|
|
454
455
|
*/
|
|
455
456
|
export async function getSyncHistory(limit: number = 50) {
|
|
456
457
|
return callFinanceHubTool('financehub_get_sync_history', { limit });
|
|
457
458
|
}
|
|
458
459
|
|
|
460
|
+
/**
|
|
461
|
+
* List Hometax business connections (hometax_connections: counts, spreadsheet URLs, status)
|
|
462
|
+
*/
|
|
463
|
+
export async function listHometaxConnections() {
|
|
464
|
+
return callFinanceHubTool('financehub_list_hometax_connections', {});
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Query electronic tax invoices synced from Hometax (tax_invoices table)
|
|
469
|
+
*/
|
|
470
|
+
export async function queryTaxInvoices(options: {
|
|
471
|
+
businessNumber?: string;
|
|
472
|
+
invoiceType?: 'sales' | 'purchase';
|
|
473
|
+
startDate?: string;
|
|
474
|
+
endDate?: string;
|
|
475
|
+
limit?: number;
|
|
476
|
+
offset?: number;
|
|
477
|
+
} = {}) {
|
|
478
|
+
return callFinanceHubTool('financehub_query_tax_invoices', options);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Query cash receipts synced from Hometax (cash_receipts table)
|
|
483
|
+
*/
|
|
484
|
+
export async function queryCashReceipts(options: {
|
|
485
|
+
businessNumber?: string;
|
|
486
|
+
startDate?: string;
|
|
487
|
+
endDate?: string;
|
|
488
|
+
limit?: number;
|
|
489
|
+
offset?: number;
|
|
490
|
+
} = {}) {
|
|
491
|
+
return callFinanceHubTool('financehub_query_cash_receipts', options);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Get Hometax Excel import sync history (hometax_sync_operations). Not the same as getSyncHistory (banks/cards).
|
|
496
|
+
*/
|
|
497
|
+
export async function getHometaxSyncHistory(limit: number = 50) {
|
|
498
|
+
return callFinanceHubTool('financehub_get_hometax_sync_history', { limit });
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Query promissory notes (promissory_notes: 어음, issued/received)
|
|
503
|
+
*/
|
|
504
|
+
export async function queryPromissoryNotes(options: {
|
|
505
|
+
bankId?: string;
|
|
506
|
+
accountId?: string;
|
|
507
|
+
status?: string;
|
|
508
|
+
noteType?: 'issued' | 'received';
|
|
509
|
+
maturityStart?: string;
|
|
510
|
+
maturityEnd?: string;
|
|
511
|
+
issueStart?: string;
|
|
512
|
+
issueEnd?: string;
|
|
513
|
+
searchText?: string;
|
|
514
|
+
limit?: number;
|
|
515
|
+
offset?: number;
|
|
516
|
+
} = {}) {
|
|
517
|
+
return callFinanceHubTool('financehub_query_promissory_notes', options);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// ==========================================
|
|
521
|
+
// INTERNAL KNOWLEDGE / BUSINESS IDENTITY / COMPANY RESEARCH (MCP)
|
|
522
|
+
// ==========================================
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Call EGDesk Internal Knowledge MCP tool (knowledge docs, business identity snapshots, company research).
|
|
526
|
+
*
|
|
527
|
+
* - Server: \`POST {apiUrl}/internal-knowledge/tools/call\`
|
|
528
|
+
* - Client: \`POST /__internal_knowledge_proxy\` (see proxy.ts / middleware)
|
|
529
|
+
*/
|
|
530
|
+
export async function callInternalKnowledgeTool(
|
|
531
|
+
toolName: string,
|
|
532
|
+
args: Record<string, any> = {}
|
|
533
|
+
): Promise<any> {
|
|
534
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
535
|
+
const headers: Record<string, string> = {
|
|
536
|
+
'Content-Type': 'application/json'
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
const isServer = typeof window === 'undefined';
|
|
540
|
+
|
|
541
|
+
let response: Response;
|
|
542
|
+
if (isServer) {
|
|
543
|
+
const apiUrl =
|
|
544
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
545
|
+
EGDESK_CONFIG.apiUrl;
|
|
546
|
+
const apiKey =
|
|
547
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_KEY) ||
|
|
548
|
+
EGDESK_CONFIG.apiKey;
|
|
549
|
+
if (apiKey) {
|
|
550
|
+
headers['X-Api-Key'] = apiKey;
|
|
551
|
+
}
|
|
552
|
+
response = await fetch(\`\${apiUrl}/internal-knowledge/tools/call\`, {
|
|
553
|
+
method: 'POST',
|
|
554
|
+
headers,
|
|
555
|
+
body
|
|
556
|
+
});
|
|
557
|
+
} else {
|
|
558
|
+
response = await fetch('/__internal_knowledge_proxy', {
|
|
559
|
+
method: 'POST',
|
|
560
|
+
headers,
|
|
561
|
+
body
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return parseEgdeskMcpToolResponse(response);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** List internal knowledge documents for a business identity snapshot */
|
|
569
|
+
export async function listKnowledgeDocuments(
|
|
570
|
+
snapshotId: string,
|
|
571
|
+
category?: 'hierarchy' | 'process' | 'policy' | 'note'
|
|
572
|
+
) {
|
|
573
|
+
return callInternalKnowledgeTool('knowledge_list_documents', {
|
|
574
|
+
snapshotId,
|
|
575
|
+
...(category != null ? { category } : {})
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/** Get one knowledge document by ID (full markdown content) */
|
|
580
|
+
export async function getKnowledgeDocument(documentId: string) {
|
|
581
|
+
return callInternalKnowledgeTool('knowledge_get_document', { documentId });
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** Search knowledge documents by text in title or content */
|
|
585
|
+
export async function searchKnowledgeContent(
|
|
586
|
+
snapshotId: string,
|
|
587
|
+
searchText: string,
|
|
588
|
+
category?: 'hierarchy' | 'process' | 'policy' | 'note'
|
|
589
|
+
) {
|
|
590
|
+
return callInternalKnowledgeTool('knowledge_search_content', {
|
|
591
|
+
snapshotId,
|
|
592
|
+
searchText,
|
|
593
|
+
...(category != null ? { category } : {})
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** Get all documents of a single category for a snapshot */
|
|
598
|
+
export async function getKnowledgeByCategory(
|
|
599
|
+
snapshotId: string,
|
|
600
|
+
category: 'hierarchy' | 'process' | 'policy' | 'note'
|
|
601
|
+
) {
|
|
602
|
+
return callInternalKnowledgeTool('knowledge_get_by_category', { snapshotId, category });
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** List business identity snapshots (optional brand filter) */
|
|
606
|
+
export async function listBusinessIdentitySnapshots(brandKey?: string) {
|
|
607
|
+
return callInternalKnowledgeTool('businessidentity_list_snapshots', {
|
|
608
|
+
...(brandKey != null ? { brandKey } : {})
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/** Full snapshot by ID (identity JSON, SEO/SSL analysis, etc.) */
|
|
613
|
+
export async function getBusinessIdentitySnapshot(snapshotId: string) {
|
|
614
|
+
return callInternalKnowledgeTool('businessidentity_get_snapshot', { snapshotId });
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/** Company info slice from a snapshot (contact, structure, partners, industries) */
|
|
618
|
+
export async function getBusinessIdentityCompanyInfo(snapshotId: string) {
|
|
619
|
+
return callInternalKnowledgeTool('businessidentity_get_company_info', { snapshotId });
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/** Services and products from a snapshot */
|
|
623
|
+
export async function getBusinessIdentityServicesProducts(snapshotId: string) {
|
|
624
|
+
return callInternalKnowledgeTool('businessidentity_get_services_products', { snapshotId });
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/** List company research records */
|
|
628
|
+
export async function listCompanyResearch(
|
|
629
|
+
status?: 'completed' | 'failed' | 'in_progress'
|
|
630
|
+
) {
|
|
631
|
+
return callInternalKnowledgeTool('companyresearch_list_all', {
|
|
632
|
+
...(status != null ? { status } : {})
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/** One company research record by ID */
|
|
637
|
+
export async function getCompanyResearchById(researchId: string) {
|
|
638
|
+
return callInternalKnowledgeTool('companyresearch_get_by_id', { researchId });
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/** Research records for a domain */
|
|
642
|
+
export async function getCompanyResearchByDomain(domain: string) {
|
|
643
|
+
return callInternalKnowledgeTool('companyresearch_get_by_domain', { domain });
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/** Search company research by company name or domain */
|
|
647
|
+
export async function searchCompanyResearch(searchText: string) {
|
|
648
|
+
return callInternalKnowledgeTool('companyresearch_search', { searchText });
|
|
649
|
+
}
|
|
650
|
+
|
|
459
651
|
// ==========================================
|
|
460
652
|
// BROWSER RECORDING HELPERS
|
|
461
653
|
// ==========================================
|
|
@@ -509,7 +701,7 @@ export async function listBrowserRecordingTests() {
|
|
|
509
701
|
return callBrowserRecordingTool('browser_recording_list_saved_tests', {});
|
|
510
702
|
}
|
|
511
703
|
|
|
512
|
-
/** Inspect a spec
|
|
704
|
+
/** Inspect a spec: date UI, defaultReplayDates, labeledFieldReplayBlocks, etc. */
|
|
513
705
|
export async function getBrowserRecordingReplayOptions(testFile: string) {
|
|
514
706
|
return callBrowserRecordingTool('browser_recording_get_replay_options', { testFile });
|
|
515
707
|
}
|
|
@@ -518,9 +710,11 @@ export type BrowserRecordingRunOptions = {
|
|
|
518
710
|
startDate?: string;
|
|
519
711
|
endDate?: string;
|
|
520
712
|
datePickersByIndex?: string[];
|
|
713
|
+
/** Per captureLabeledFields step, values in field order */
|
|
714
|
+
labeledFieldFills?: (string | undefined)[][];
|
|
521
715
|
};
|
|
522
716
|
|
|
523
|
-
/** Replay a saved recording in Chrome */
|
|
717
|
+
/** Replay a saved recording in Chrome (optional dates + labeledFieldFills) */
|
|
524
718
|
export async function runBrowserRecording(
|
|
525
719
|
testFile: string,
|
|
526
720
|
options: BrowserRecordingRunOptions = {}
|
|
@@ -73,8 +73,8 @@ import type { NextRequest } from 'next/server';
|
|
|
73
73
|
/**
|
|
74
74
|
* EGDesk Database Proxy Middleware
|
|
75
75
|
*
|
|
76
|
-
* Intercepts __user_data_proxy
|
|
77
|
-
* to the EGDesk MCP HTTP server.
|
|
76
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, and __internal_knowledge_proxy requests
|
|
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
|
|
@@ -149,6 +149,38 @@ export async function middleware(request: NextRequest) {
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
if (pathname.includes('__internal_knowledge_proxy')) {
|
|
153
|
+
try {
|
|
154
|
+
const body = await request.text();
|
|
155
|
+
|
|
156
|
+
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
157
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
158
|
+
|
|
159
|
+
const headers: HeadersInit = {
|
|
160
|
+
'Content-Type': 'application/json',
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
if (apiKey) {
|
|
164
|
+
headers['X-Api-Key'] = apiKey;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const response = await fetch(\`\${apiUrl}/internal-knowledge/tools/call\`, {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers,
|
|
170
|
+
body,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const result = await response.json();
|
|
174
|
+
|
|
175
|
+
return NextResponse.json(result, { status: response.status });
|
|
176
|
+
} catch (error: any) {
|
|
177
|
+
return NextResponse.json(
|
|
178
|
+
{ error: 'Proxy error', message: error.message },
|
|
179
|
+
{ status: 500 }
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
152
184
|
// Continue to next middleware or route
|
|
153
185
|
return NextResponse.next();
|
|
154
186
|
}
|
package/dist/generate-proxy.js
CHANGED
|
@@ -75,8 +75,8 @@ import type { NextRequest } from 'next/server';
|
|
|
75
75
|
/**
|
|
76
76
|
* EGDesk Database Proxy (Next.js 16+)
|
|
77
77
|
*
|
|
78
|
-
* Intercepts __user_data_proxy
|
|
79
|
-
* to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
|
|
78
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, and __internal_knowledge_proxy requests
|
|
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
|
|
82
82
|
*/
|
|
@@ -150,6 +150,38 @@ export async function proxy(request: NextRequest) {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
if (pathname.includes('__internal_knowledge_proxy')) {
|
|
154
|
+
try {
|
|
155
|
+
const body = await request.text();
|
|
156
|
+
|
|
157
|
+
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
158
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
159
|
+
|
|
160
|
+
const headers: HeadersInit = {
|
|
161
|
+
'Content-Type': 'application/json',
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
if (apiKey) {
|
|
165
|
+
headers['X-Api-Key'] = apiKey;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const response = await fetch(\`\${apiUrl}/internal-knowledge/tools/call\`, {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers,
|
|
171
|
+
body,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const result = await response.json();
|
|
175
|
+
|
|
176
|
+
return NextResponse.json(result, { status: response.status });
|
|
177
|
+
} catch (error: any) {
|
|
178
|
+
return NextResponse.json(
|
|
179
|
+
{ error: 'Proxy error', message: error.message },
|
|
180
|
+
{ status: 500 }
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
153
185
|
// Continue to next proxy or route
|
|
154
186
|
return NextResponse.next();
|
|
155
187
|
}
|
|
@@ -158,7 +190,7 @@ export const config = {
|
|
|
158
190
|
matcher: [
|
|
159
191
|
/*
|
|
160
192
|
* Match all paths except static assets
|
|
161
|
-
* The proxy function filters for __user_data_proxy / __browser_recording_proxy
|
|
193
|
+
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy
|
|
162
194
|
*/
|
|
163
195
|
'/:path*',
|
|
164
196
|
],
|
package/package.json
CHANGED
package/src/generate-helpers.ts
CHANGED
|
@@ -17,7 +17,8 @@ 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,
|
|
20
|
+
* Type-safe helpers for EGDesk user data, FinanceHub (banks, cards, Hometax, promissory notes),
|
|
21
|
+
* internal knowledge / business identity / company research (MCP), and browser recorder replay.
|
|
21
22
|
* Works in both client and server components.
|
|
22
23
|
*
|
|
23
24
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -292,7 +293,7 @@ export async function callFinanceHubTool(
|
|
|
292
293
|
toolName: string,
|
|
293
294
|
args: Record<string, any> = {}
|
|
294
295
|
): Promise<any> {
|
|
295
|
-
const body = JSON.stringify({ tool: toolName, args });
|
|
296
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
296
297
|
const headers: Record<string, string> = {
|
|
297
298
|
'Content-Type': 'application/json'
|
|
298
299
|
};
|
|
@@ -417,12 +418,203 @@ export async function getOverallStats() {
|
|
|
417
418
|
}
|
|
418
419
|
|
|
419
420
|
/**
|
|
420
|
-
* Get sync operation history
|
|
421
|
+
* Get bank/card sync operation history (sync_operations table)
|
|
421
422
|
*/
|
|
422
423
|
export async function getSyncHistory(limit: number = 50) {
|
|
423
424
|
return callFinanceHubTool('financehub_get_sync_history', { limit });
|
|
424
425
|
}
|
|
425
426
|
|
|
427
|
+
/**
|
|
428
|
+
* List Hometax business connections (hometax_connections: counts, spreadsheet URLs, status)
|
|
429
|
+
*/
|
|
430
|
+
export async function listHometaxConnections() {
|
|
431
|
+
return callFinanceHubTool('financehub_list_hometax_connections', {});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Query electronic tax invoices synced from Hometax (tax_invoices table)
|
|
436
|
+
*/
|
|
437
|
+
export async function queryTaxInvoices(options: {
|
|
438
|
+
businessNumber?: string;
|
|
439
|
+
invoiceType?: 'sales' | 'purchase';
|
|
440
|
+
startDate?: string;
|
|
441
|
+
endDate?: string;
|
|
442
|
+
limit?: number;
|
|
443
|
+
offset?: number;
|
|
444
|
+
} = {}) {
|
|
445
|
+
return callFinanceHubTool('financehub_query_tax_invoices', options);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Query cash receipts synced from Hometax (cash_receipts table)
|
|
450
|
+
*/
|
|
451
|
+
export async function queryCashReceipts(options: {
|
|
452
|
+
businessNumber?: string;
|
|
453
|
+
startDate?: string;
|
|
454
|
+
endDate?: string;
|
|
455
|
+
limit?: number;
|
|
456
|
+
offset?: number;
|
|
457
|
+
} = {}) {
|
|
458
|
+
return callFinanceHubTool('financehub_query_cash_receipts', options);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Get Hometax Excel import sync history (hometax_sync_operations). Not the same as getSyncHistory (banks/cards).
|
|
463
|
+
*/
|
|
464
|
+
export async function getHometaxSyncHistory(limit: number = 50) {
|
|
465
|
+
return callFinanceHubTool('financehub_get_hometax_sync_history', { limit });
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Query promissory notes (promissory_notes: 어음, issued/received)
|
|
470
|
+
*/
|
|
471
|
+
export async function queryPromissoryNotes(options: {
|
|
472
|
+
bankId?: string;
|
|
473
|
+
accountId?: string;
|
|
474
|
+
status?: string;
|
|
475
|
+
noteType?: 'issued' | 'received';
|
|
476
|
+
maturityStart?: string;
|
|
477
|
+
maturityEnd?: string;
|
|
478
|
+
issueStart?: string;
|
|
479
|
+
issueEnd?: string;
|
|
480
|
+
searchText?: string;
|
|
481
|
+
limit?: number;
|
|
482
|
+
offset?: number;
|
|
483
|
+
} = {}) {
|
|
484
|
+
return callFinanceHubTool('financehub_query_promissory_notes', options);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// ==========================================
|
|
488
|
+
// INTERNAL KNOWLEDGE / BUSINESS IDENTITY / COMPANY RESEARCH (MCP)
|
|
489
|
+
// ==========================================
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Call EGDesk Internal Knowledge MCP tool (knowledge docs, business identity snapshots, company research).
|
|
493
|
+
*
|
|
494
|
+
* - Server: \`POST {apiUrl}/internal-knowledge/tools/call\`
|
|
495
|
+
* - Client: \`POST /__internal_knowledge_proxy\` (see proxy.ts / middleware)
|
|
496
|
+
*/
|
|
497
|
+
export async function callInternalKnowledgeTool(
|
|
498
|
+
toolName: string,
|
|
499
|
+
args: Record<string, any> = {}
|
|
500
|
+
): Promise<any> {
|
|
501
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
502
|
+
const headers: Record<string, string> = {
|
|
503
|
+
'Content-Type': 'application/json'
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
const isServer = typeof window === 'undefined';
|
|
507
|
+
|
|
508
|
+
let response: Response;
|
|
509
|
+
if (isServer) {
|
|
510
|
+
const apiUrl =
|
|
511
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
512
|
+
EGDESK_CONFIG.apiUrl;
|
|
513
|
+
const apiKey =
|
|
514
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_KEY) ||
|
|
515
|
+
EGDESK_CONFIG.apiKey;
|
|
516
|
+
if (apiKey) {
|
|
517
|
+
headers['X-Api-Key'] = apiKey;
|
|
518
|
+
}
|
|
519
|
+
response = await fetch(\`\${apiUrl}/internal-knowledge/tools/call\`, {
|
|
520
|
+
method: 'POST',
|
|
521
|
+
headers,
|
|
522
|
+
body
|
|
523
|
+
});
|
|
524
|
+
} else {
|
|
525
|
+
response = await fetch('/__internal_knowledge_proxy', {
|
|
526
|
+
method: 'POST',
|
|
527
|
+
headers,
|
|
528
|
+
body
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return parseEgdeskMcpToolResponse(response);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/** List internal knowledge documents for a business identity snapshot */
|
|
536
|
+
export async function listKnowledgeDocuments(
|
|
537
|
+
snapshotId: string,
|
|
538
|
+
category?: 'hierarchy' | 'process' | 'policy' | 'note'
|
|
539
|
+
) {
|
|
540
|
+
return callInternalKnowledgeTool('knowledge_list_documents', {
|
|
541
|
+
snapshotId,
|
|
542
|
+
...(category != null ? { category } : {})
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** Get one knowledge document by ID (full markdown content) */
|
|
547
|
+
export async function getKnowledgeDocument(documentId: string) {
|
|
548
|
+
return callInternalKnowledgeTool('knowledge_get_document', { documentId });
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** Search knowledge documents by text in title or content */
|
|
552
|
+
export async function searchKnowledgeContent(
|
|
553
|
+
snapshotId: string,
|
|
554
|
+
searchText: string,
|
|
555
|
+
category?: 'hierarchy' | 'process' | 'policy' | 'note'
|
|
556
|
+
) {
|
|
557
|
+
return callInternalKnowledgeTool('knowledge_search_content', {
|
|
558
|
+
snapshotId,
|
|
559
|
+
searchText,
|
|
560
|
+
...(category != null ? { category } : {})
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** Get all documents of a single category for a snapshot */
|
|
565
|
+
export async function getKnowledgeByCategory(
|
|
566
|
+
snapshotId: string,
|
|
567
|
+
category: 'hierarchy' | 'process' | 'policy' | 'note'
|
|
568
|
+
) {
|
|
569
|
+
return callInternalKnowledgeTool('knowledge_get_by_category', { snapshotId, category });
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** List business identity snapshots (optional brand filter) */
|
|
573
|
+
export async function listBusinessIdentitySnapshots(brandKey?: string) {
|
|
574
|
+
return callInternalKnowledgeTool('businessidentity_list_snapshots', {
|
|
575
|
+
...(brandKey != null ? { brandKey } : {})
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/** Full snapshot by ID (identity JSON, SEO/SSL analysis, etc.) */
|
|
580
|
+
export async function getBusinessIdentitySnapshot(snapshotId: string) {
|
|
581
|
+
return callInternalKnowledgeTool('businessidentity_get_snapshot', { snapshotId });
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** Company info slice from a snapshot (contact, structure, partners, industries) */
|
|
585
|
+
export async function getBusinessIdentityCompanyInfo(snapshotId: string) {
|
|
586
|
+
return callInternalKnowledgeTool('businessidentity_get_company_info', { snapshotId });
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** Services and products from a snapshot */
|
|
590
|
+
export async function getBusinessIdentityServicesProducts(snapshotId: string) {
|
|
591
|
+
return callInternalKnowledgeTool('businessidentity_get_services_products', { snapshotId });
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/** List company research records */
|
|
595
|
+
export async function listCompanyResearch(
|
|
596
|
+
status?: 'completed' | 'failed' | 'in_progress'
|
|
597
|
+
) {
|
|
598
|
+
return callInternalKnowledgeTool('companyresearch_list_all', {
|
|
599
|
+
...(status != null ? { status } : {})
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** One company research record by ID */
|
|
604
|
+
export async function getCompanyResearchById(researchId: string) {
|
|
605
|
+
return callInternalKnowledgeTool('companyresearch_get_by_id', { researchId });
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/** Research records for a domain */
|
|
609
|
+
export async function getCompanyResearchByDomain(domain: string) {
|
|
610
|
+
return callInternalKnowledgeTool('companyresearch_get_by_domain', { domain });
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/** Search company research by company name or domain */
|
|
614
|
+
export async function searchCompanyResearch(searchText: string) {
|
|
615
|
+
return callInternalKnowledgeTool('companyresearch_search', { searchText });
|
|
616
|
+
}
|
|
617
|
+
|
|
426
618
|
// ==========================================
|
|
427
619
|
// BROWSER RECORDING HELPERS
|
|
428
620
|
// ==========================================
|
|
@@ -476,7 +668,7 @@ export async function listBrowserRecordingTests() {
|
|
|
476
668
|
return callBrowserRecordingTool('browser_recording_list_saved_tests', {});
|
|
477
669
|
}
|
|
478
670
|
|
|
479
|
-
/** Inspect a spec
|
|
671
|
+
/** Inspect a spec: date UI, defaultReplayDates, labeledFieldReplayBlocks, etc. */
|
|
480
672
|
export async function getBrowserRecordingReplayOptions(testFile: string) {
|
|
481
673
|
return callBrowserRecordingTool('browser_recording_get_replay_options', { testFile });
|
|
482
674
|
}
|
|
@@ -485,9 +677,11 @@ export type BrowserRecordingRunOptions = {
|
|
|
485
677
|
startDate?: string;
|
|
486
678
|
endDate?: string;
|
|
487
679
|
datePickersByIndex?: string[];
|
|
680
|
+
/** Per captureLabeledFields step, values in field order */
|
|
681
|
+
labeledFieldFills?: (string | undefined)[][];
|
|
488
682
|
};
|
|
489
683
|
|
|
490
|
-
/** Replay a saved recording in Chrome */
|
|
684
|
+
/** Replay a saved recording in Chrome (optional dates + labeledFieldFills) */
|
|
491
685
|
export async function runBrowserRecording(
|
|
492
686
|
testFile: string,
|
|
493
687
|
options: BrowserRecordingRunOptions = {}
|
|
@@ -43,8 +43,8 @@ import type { NextRequest } from 'next/server';
|
|
|
43
43
|
/**
|
|
44
44
|
* EGDesk Database Proxy Middleware
|
|
45
45
|
*
|
|
46
|
-
* Intercepts __user_data_proxy
|
|
47
|
-
* to the EGDesk MCP HTTP server.
|
|
46
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, and __internal_knowledge_proxy requests
|
|
47
|
+
* and forwards them to the EGDesk MCP HTTP server.
|
|
48
48
|
* This allows CORS-free database access in both local and tunneled environments.
|
|
49
49
|
*
|
|
50
50
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -119,6 +119,38 @@ export async function middleware(request: NextRequest) {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
if (pathname.includes('__internal_knowledge_proxy')) {
|
|
123
|
+
try {
|
|
124
|
+
const body = await request.text();
|
|
125
|
+
|
|
126
|
+
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
127
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
128
|
+
|
|
129
|
+
const headers: HeadersInit = {
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
if (apiKey) {
|
|
134
|
+
headers['X-Api-Key'] = apiKey;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const response = await fetch(\`\${apiUrl}/internal-knowledge/tools/call\`, {
|
|
138
|
+
method: 'POST',
|
|
139
|
+
headers,
|
|
140
|
+
body,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const result = await response.json();
|
|
144
|
+
|
|
145
|
+
return NextResponse.json(result, { status: response.status });
|
|
146
|
+
} catch (error: any) {
|
|
147
|
+
return NextResponse.json(
|
|
148
|
+
{ error: 'Proxy error', message: error.message },
|
|
149
|
+
{ status: 500 }
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
122
154
|
// Continue to next middleware or route
|
|
123
155
|
return NextResponse.next();
|
|
124
156
|
}
|
package/src/generate-proxy.ts
CHANGED
|
@@ -45,8 +45,8 @@ import type { NextRequest } from 'next/server';
|
|
|
45
45
|
/**
|
|
46
46
|
* EGDesk Database Proxy (Next.js 16+)
|
|
47
47
|
*
|
|
48
|
-
* Intercepts __user_data_proxy
|
|
49
|
-
* to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
|
|
48
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, and __internal_knowledge_proxy requests
|
|
49
|
+
* and forwards them to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
|
|
50
50
|
*
|
|
51
51
|
* Generated by @egdesk/next-api-plugin
|
|
52
52
|
*/
|
|
@@ -120,6 +120,38 @@ export async function proxy(request: NextRequest) {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
if (pathname.includes('__internal_knowledge_proxy')) {
|
|
124
|
+
try {
|
|
125
|
+
const body = await request.text();
|
|
126
|
+
|
|
127
|
+
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
128
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
129
|
+
|
|
130
|
+
const headers: HeadersInit = {
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
if (apiKey) {
|
|
135
|
+
headers['X-Api-Key'] = apiKey;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const response = await fetch(\`\${apiUrl}/internal-knowledge/tools/call\`, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers,
|
|
141
|
+
body,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const result = await response.json();
|
|
145
|
+
|
|
146
|
+
return NextResponse.json(result, { status: response.status });
|
|
147
|
+
} catch (error: any) {
|
|
148
|
+
return NextResponse.json(
|
|
149
|
+
{ error: 'Proxy error', message: error.message },
|
|
150
|
+
{ status: 500 }
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
123
155
|
// Continue to next proxy or route
|
|
124
156
|
return NextResponse.next();
|
|
125
157
|
}
|
|
@@ -128,7 +160,7 @@ export const config = {
|
|
|
128
160
|
matcher: [
|
|
129
161
|
/*
|
|
130
162
|
* Match all paths except static assets
|
|
131
|
-
* The proxy function filters for __user_data_proxy / __browser_recording_proxy
|
|
163
|
+
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy
|
|
132
164
|
*/
|
|
133
165
|
'/:path*',
|
|
134
166
|
],
|