@egdesk/next-api-plugin 1.5.86 → 1.5.106
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-chunked-upload-routes.d.ts +8 -0
- package/dist/generate-chunked-upload-routes.js +215 -0
- package/dist/generate-helpers.js +612 -68
- package/dist/generate-middleware.js +21 -14
- package/dist/generate-proxy.js +39 -32
- package/dist/generate-visitor-auth.js +39 -13
- package/dist/index.d.ts +2 -1
- package/dist/index.js +10 -2
- package/package.json +1 -1
|
@@ -114,6 +114,13 @@ function workspaceUpstreamHeaders(request: NextRequest): Record<string, string>
|
|
|
114
114
|
return headers;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/** Prefer loopback MCP so middleware hops never re-enter the public tunnel. */
|
|
118
|
+
function resolveEgdeskMcpApiUrl(): string {
|
|
119
|
+
const internal = process.env.EGDESK_MCP_INTERNAL_URL;
|
|
120
|
+
if (internal && internal.trim()) return internal.replace(/\\/$/, '');
|
|
121
|
+
return (process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080').replace(/\\/$/, '');
|
|
122
|
+
}
|
|
123
|
+
|
|
117
124
|
export async function middleware(request: NextRequest) {
|
|
118
125
|
const { pathname } = request.nextUrl;
|
|
119
126
|
|
|
@@ -124,7 +131,7 @@ export async function middleware(request: NextRequest) {
|
|
|
124
131
|
|
|
125
132
|
// Read API key and URL from environment
|
|
126
133
|
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
127
|
-
const apiUrl =
|
|
134
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
128
135
|
|
|
129
136
|
const headers: HeadersInit = {
|
|
130
137
|
'Content-Type': 'application/json',
|
|
@@ -157,7 +164,7 @@ export async function middleware(request: NextRequest) {
|
|
|
157
164
|
const body = await request.text();
|
|
158
165
|
|
|
159
166
|
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
160
|
-
const apiUrl =
|
|
167
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
161
168
|
|
|
162
169
|
const headers: HeadersInit = {
|
|
163
170
|
'Content-Type': 'application/json',
|
|
@@ -189,7 +196,7 @@ export async function middleware(request: NextRequest) {
|
|
|
189
196
|
const body = await request.text();
|
|
190
197
|
|
|
191
198
|
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
192
|
-
const apiUrl =
|
|
199
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
193
200
|
|
|
194
201
|
const headers: HeadersInit = {
|
|
195
202
|
'Content-Type': 'application/json',
|
|
@@ -221,7 +228,7 @@ export async function middleware(request: NextRequest) {
|
|
|
221
228
|
const body = await request.text();
|
|
222
229
|
|
|
223
230
|
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
224
|
-
const apiUrl =
|
|
231
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
225
232
|
|
|
226
233
|
const headers: HeadersInit = {
|
|
227
234
|
'Content-Type': 'application/json',
|
|
@@ -253,7 +260,7 @@ export async function middleware(request: NextRequest) {
|
|
|
253
260
|
const body = await request.text();
|
|
254
261
|
|
|
255
262
|
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
256
|
-
const apiUrl =
|
|
263
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
257
264
|
|
|
258
265
|
const headers: HeadersInit = {
|
|
259
266
|
'Content-Type': 'application/json',
|
|
@@ -283,7 +290,7 @@ export async function middleware(request: NextRequest) {
|
|
|
283
290
|
if (pathname.includes('__drive_proxy')) {
|
|
284
291
|
try {
|
|
285
292
|
const body = await request.text();
|
|
286
|
-
const apiUrl =
|
|
293
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
287
294
|
|
|
288
295
|
const response = await fetch(\`\${apiUrl}/drive/tools/call\`, {
|
|
289
296
|
method: 'POST',
|
|
@@ -303,7 +310,7 @@ export async function middleware(request: NextRequest) {
|
|
|
303
310
|
if (pathname.includes('__docs_proxy')) {
|
|
304
311
|
try {
|
|
305
312
|
const body = await request.text();
|
|
306
|
-
const apiUrl =
|
|
313
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
307
314
|
|
|
308
315
|
const response = await fetch(\`\${apiUrl}/docs/tools/call\`, {
|
|
309
316
|
method: 'POST',
|
|
@@ -323,7 +330,7 @@ export async function middleware(request: NextRequest) {
|
|
|
323
330
|
if (pathname.includes('__slides_proxy')) {
|
|
324
331
|
try {
|
|
325
332
|
const body = await request.text();
|
|
326
|
-
const apiUrl =
|
|
333
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
327
334
|
|
|
328
335
|
const response = await fetch(\`\${apiUrl}/slides/tools/call\`, {
|
|
329
336
|
method: 'POST',
|
|
@@ -343,7 +350,7 @@ export async function middleware(request: NextRequest) {
|
|
|
343
350
|
if (pathname.includes('__sheets_proxy')) {
|
|
344
351
|
try {
|
|
345
352
|
const body = await request.text();
|
|
346
|
-
const apiUrl =
|
|
353
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
347
354
|
|
|
348
355
|
const response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
349
356
|
method: 'POST',
|
|
@@ -370,7 +377,7 @@ export async function middleware(request: NextRequest) {
|
|
|
370
377
|
}
|
|
371
378
|
const method = payload.method === 'POST' ? 'POST' : 'GET';
|
|
372
379
|
const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
|
|
373
|
-
const apiUrl =
|
|
380
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
374
381
|
const projectId = process.env.NEXT_PUBLIC_EGDESK_PROJECT_ID;
|
|
375
382
|
const egdeskEnv = process.env.NEXT_PUBLIC_EGDESK_ENV;
|
|
376
383
|
const headers: HeadersInit = { 'Content-Type': 'application/json' };
|
|
@@ -401,7 +408,7 @@ export async function middleware(request: NextRequest) {
|
|
|
401
408
|
if (pathname.includes('__gmail_proxy')) {
|
|
402
409
|
try {
|
|
403
410
|
const body = await request.text();
|
|
404
|
-
const apiUrl =
|
|
411
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
405
412
|
const response = await fetch(\`\${apiUrl}/gmail/tools/call\`, {
|
|
406
413
|
method: 'POST',
|
|
407
414
|
headers: workspaceUpstreamHeaders(request),
|
|
@@ -420,7 +427,7 @@ export async function middleware(request: NextRequest) {
|
|
|
420
427
|
if (pathname.includes('__apps_script_proxy')) {
|
|
421
428
|
try {
|
|
422
429
|
const body = await request.text();
|
|
423
|
-
const apiUrl =
|
|
430
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
424
431
|
const response = await fetch(\`\${apiUrl}/apps-script/tools/call\`, {
|
|
425
432
|
method: 'POST',
|
|
426
433
|
headers: workspaceUpstreamHeaders(request),
|
|
@@ -439,7 +446,7 @@ export async function middleware(request: NextRequest) {
|
|
|
439
446
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
440
447
|
try {
|
|
441
448
|
const body = await request.text();
|
|
442
|
-
const apiUrl =
|
|
449
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
443
450
|
|
|
444
451
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
445
452
|
method: 'POST',
|
|
@@ -459,7 +466,7 @@ export async function middleware(request: NextRequest) {
|
|
|
459
466
|
if (pathname.includes('__visitor_google_proxy')) {
|
|
460
467
|
try {
|
|
461
468
|
const body = await request.text();
|
|
462
|
-
const apiUrl =
|
|
469
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
463
470
|
const headers = visitorUpstreamHeaders(request);
|
|
464
471
|
const authorization = request.headers.get('authorization');
|
|
465
472
|
if (authorization) headers['Authorization'] = authorization;
|
package/dist/generate-proxy.js
CHANGED
|
@@ -93,6 +93,13 @@ function buildEgdeskHeaders(): Record<string, string> {
|
|
|
93
93
|
return headers;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/** Prefer loopback MCP so proxy hops never re-enter the public tunnel. */
|
|
97
|
+
function resolveEgdeskMcpApiUrl(): string {
|
|
98
|
+
const internal = process.env.EGDESK_MCP_INTERNAL_URL;
|
|
99
|
+
if (internal && internal.trim()) return internal.replace(/\\/$/, '');
|
|
100
|
+
return (process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080').replace(/\\/$/, '');
|
|
101
|
+
}
|
|
102
|
+
|
|
96
103
|
/** Forward this site's origin so EGDesk can bind visitor sessions to this site only. */
|
|
97
104
|
function visitorForwardHeaders(request: NextRequest): Record<string, string> {
|
|
98
105
|
const headers = buildEgdeskHeaders();
|
|
@@ -129,7 +136,7 @@ export async function proxy(request: NextRequest) {
|
|
|
129
136
|
if (pathname.includes('__user_data_proxy')) {
|
|
130
137
|
try {
|
|
131
138
|
const body = await request.text();
|
|
132
|
-
const apiUrl =
|
|
139
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
133
140
|
|
|
134
141
|
// Forward to EGDesk MCP server
|
|
135
142
|
const response = await fetch(\`\${apiUrl}/user-data/tools/call\`, {
|
|
@@ -152,7 +159,7 @@ export async function proxy(request: NextRequest) {
|
|
|
152
159
|
if (pathname.includes('__browser_recording_proxy')) {
|
|
153
160
|
try {
|
|
154
161
|
const body = await request.text();
|
|
155
|
-
const apiUrl =
|
|
162
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
156
163
|
|
|
157
164
|
const response = await fetch(\`\${apiUrl}/browser-recording/tools/call\`, {
|
|
158
165
|
method: 'POST',
|
|
@@ -174,7 +181,7 @@ export async function proxy(request: NextRequest) {
|
|
|
174
181
|
if (pathname.includes('__business_identity_proxy')) {
|
|
175
182
|
try {
|
|
176
183
|
const body = await request.text();
|
|
177
|
-
const apiUrl =
|
|
184
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
178
185
|
|
|
179
186
|
const response = await fetch(\`\${apiUrl}/business-identity/tools/call\`, {
|
|
180
187
|
method: 'POST',
|
|
@@ -196,7 +203,7 @@ export async function proxy(request: NextRequest) {
|
|
|
196
203
|
if (pathname.includes('__ai_center_proxy')) {
|
|
197
204
|
try {
|
|
198
205
|
const body = await request.text();
|
|
199
|
-
const apiUrl =
|
|
206
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
200
207
|
|
|
201
208
|
const response = await fetch(\`\${apiUrl}/ai-center/tools/call\`, {
|
|
202
209
|
method: 'POST',
|
|
@@ -218,7 +225,7 @@ export async function proxy(request: NextRequest) {
|
|
|
218
225
|
if (pathname.includes('__korean_law_proxy')) {
|
|
219
226
|
try {
|
|
220
227
|
const body = await request.text();
|
|
221
|
-
const apiUrl =
|
|
228
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
222
229
|
|
|
223
230
|
const response = await fetch(\`\${apiUrl}/korean-law/tools/call\`, {
|
|
224
231
|
method: 'POST',
|
|
@@ -240,7 +247,7 @@ export async function proxy(request: NextRequest) {
|
|
|
240
247
|
if (pathname.includes('__bizinfo_proxy')) {
|
|
241
248
|
try {
|
|
242
249
|
const body = await request.text();
|
|
243
|
-
const apiUrl =
|
|
250
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
244
251
|
|
|
245
252
|
const response = await fetch(\`\${apiUrl}/company-research/tools/call\`, {
|
|
246
253
|
method: 'POST',
|
|
@@ -262,7 +269,7 @@ export async function proxy(request: NextRequest) {
|
|
|
262
269
|
if (pathname.includes('__bidnotice_proxy')) {
|
|
263
270
|
try {
|
|
264
271
|
const body = await request.text();
|
|
265
|
-
const apiUrl =
|
|
272
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
266
273
|
|
|
267
274
|
const response = await fetch(\`\${apiUrl}/company-research/tools/call\`, {
|
|
268
275
|
method: 'POST',
|
|
@@ -284,7 +291,7 @@ export async function proxy(request: NextRequest) {
|
|
|
284
291
|
if (pathname.includes('__koneps_proxy')) {
|
|
285
292
|
try {
|
|
286
293
|
const body = await request.text();
|
|
287
|
-
const apiUrl =
|
|
294
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
288
295
|
|
|
289
296
|
const response = await fetch(\`\${apiUrl}/company-research/tools/call\`, {
|
|
290
297
|
method: 'POST',
|
|
@@ -306,7 +313,7 @@ export async function proxy(request: NextRequest) {
|
|
|
306
313
|
if (pathname.includes('__nps_proxy')) {
|
|
307
314
|
try {
|
|
308
315
|
const body = await request.text();
|
|
309
|
-
const apiUrl =
|
|
316
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
310
317
|
|
|
311
318
|
const response = await fetch(\`\${apiUrl}/company-research/tools/call\`, {
|
|
312
319
|
method: 'POST',
|
|
@@ -328,7 +335,7 @@ export async function proxy(request: NextRequest) {
|
|
|
328
335
|
if (pathname.includes('__seo_proxy')) {
|
|
329
336
|
try {
|
|
330
337
|
const body = await request.text();
|
|
331
|
-
const apiUrl =
|
|
338
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
332
339
|
|
|
333
340
|
const response = await fetch(\`\${apiUrl}/seo/tools/call\`, {
|
|
334
341
|
method: 'POST',
|
|
@@ -350,7 +357,7 @@ export async function proxy(request: NextRequest) {
|
|
|
350
357
|
if (pathname.includes('__hosting_coding_proxy')) {
|
|
351
358
|
try {
|
|
352
359
|
const body = await request.text();
|
|
353
|
-
const apiUrl =
|
|
360
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
354
361
|
|
|
355
362
|
const response = await fetch(\`\${apiUrl}/hosting-coding/tools/call\`, {
|
|
356
363
|
method: 'POST',
|
|
@@ -372,7 +379,7 @@ export async function proxy(request: NextRequest) {
|
|
|
372
379
|
if (pathname.includes('__company_research_proxy')) {
|
|
373
380
|
try {
|
|
374
381
|
const body = await request.text();
|
|
375
|
-
const apiUrl =
|
|
382
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
376
383
|
|
|
377
384
|
const response = await fetch(\`\${apiUrl}/company-research/tools/call\`, {
|
|
378
385
|
method: 'POST',
|
|
@@ -394,7 +401,7 @@ export async function proxy(request: NextRequest) {
|
|
|
394
401
|
if (pathname.includes('__local_agent_proxy')) {
|
|
395
402
|
try {
|
|
396
403
|
const body = await request.text();
|
|
397
|
-
const apiUrl =
|
|
404
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
398
405
|
|
|
399
406
|
const response = await fetch(\`\${apiUrl}/local-agent/tools/call\`, {
|
|
400
407
|
method: 'POST',
|
|
@@ -416,7 +423,7 @@ export async function proxy(request: NextRequest) {
|
|
|
416
423
|
if (pathname.includes('__pageindex_proxy')) {
|
|
417
424
|
try {
|
|
418
425
|
const body = await request.text();
|
|
419
|
-
const apiUrl =
|
|
426
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
420
427
|
|
|
421
428
|
const response = await fetch(\`\${apiUrl}/pageindex/tools/call\`, {
|
|
422
429
|
method: 'POST',
|
|
@@ -438,7 +445,7 @@ export async function proxy(request: NextRequest) {
|
|
|
438
445
|
if (pathname.includes('__drive_proxy')) {
|
|
439
446
|
try {
|
|
440
447
|
const body = await request.text();
|
|
441
|
-
const apiUrl =
|
|
448
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
442
449
|
|
|
443
450
|
const response = await fetch(\`\${apiUrl}/drive/tools/call\`, {
|
|
444
451
|
method: 'POST',
|
|
@@ -460,7 +467,7 @@ export async function proxy(request: NextRequest) {
|
|
|
460
467
|
if (pathname.includes('__docs_proxy')) {
|
|
461
468
|
try {
|
|
462
469
|
const body = await request.text();
|
|
463
|
-
const apiUrl =
|
|
470
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
464
471
|
|
|
465
472
|
const response = await fetch(\`\${apiUrl}/docs/tools/call\`, {
|
|
466
473
|
method: 'POST',
|
|
@@ -482,7 +489,7 @@ export async function proxy(request: NextRequest) {
|
|
|
482
489
|
if (pathname.includes('__slides_proxy')) {
|
|
483
490
|
try {
|
|
484
491
|
const body = await request.text();
|
|
485
|
-
const apiUrl =
|
|
492
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
486
493
|
|
|
487
494
|
const response = await fetch(\`\${apiUrl}/slides/tools/call\`, {
|
|
488
495
|
method: 'POST',
|
|
@@ -504,7 +511,7 @@ export async function proxy(request: NextRequest) {
|
|
|
504
511
|
if (pathname.includes('__sheets_proxy')) {
|
|
505
512
|
try {
|
|
506
513
|
const body = await request.text();
|
|
507
|
-
const apiUrl =
|
|
514
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
508
515
|
|
|
509
516
|
const response = await fetch(\`\${apiUrl}/sheets/tools/call\`, {
|
|
510
517
|
method: 'POST',
|
|
@@ -532,7 +539,7 @@ export async function proxy(request: NextRequest) {
|
|
|
532
539
|
return NextResponse.json({ error: 'Path not allowed', path: targetPath }, { status: 400 });
|
|
533
540
|
}
|
|
534
541
|
const method = payload.method === 'POST' ? 'POST' : 'GET';
|
|
535
|
-
const apiUrl =
|
|
542
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
536
543
|
const base = apiUrl.endsWith('/') ? apiUrl : \`\${apiUrl}/\`;
|
|
537
544
|
const url = new URL(targetPath.startsWith('/') ? targetPath.slice(1) : targetPath, base);
|
|
538
545
|
const query = payload.query && typeof payload.query === 'object' ? payload.query as Record<string, unknown> : {};
|
|
@@ -557,7 +564,7 @@ export async function proxy(request: NextRequest) {
|
|
|
557
564
|
if (pathname.includes('__gmail_proxy')) {
|
|
558
565
|
try {
|
|
559
566
|
const body = await request.text();
|
|
560
|
-
const apiUrl =
|
|
567
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
561
568
|
const response = await fetch(\`\${apiUrl}/gmail/tools/call\`, {
|
|
562
569
|
method: 'POST',
|
|
563
570
|
headers: workspaceForwardHeaders(request),
|
|
@@ -576,7 +583,7 @@ export async function proxy(request: NextRequest) {
|
|
|
576
583
|
if (pathname.includes('__apps_script_proxy')) {
|
|
577
584
|
try {
|
|
578
585
|
const body = await request.text();
|
|
579
|
-
const apiUrl =
|
|
586
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
580
587
|
const response = await fetch(\`\${apiUrl}/apps-script/tools/call\`, {
|
|
581
588
|
method: 'POST',
|
|
582
589
|
headers: workspaceForwardHeaders(request),
|
|
@@ -595,7 +602,7 @@ export async function proxy(request: NextRequest) {
|
|
|
595
602
|
if (pathname.includes('__knowledge_wiki_proxy')) {
|
|
596
603
|
try {
|
|
597
604
|
const body = await request.text();
|
|
598
|
-
const apiUrl =
|
|
605
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
599
606
|
|
|
600
607
|
const response = await fetch(\`\${apiUrl}/knowledge-wiki/tools/call\`, {
|
|
601
608
|
method: 'POST',
|
|
@@ -617,7 +624,7 @@ export async function proxy(request: NextRequest) {
|
|
|
617
624
|
if (pathname.includes('__kakao_proxy')) {
|
|
618
625
|
try {
|
|
619
626
|
const body = await request.text();
|
|
620
|
-
const apiUrl =
|
|
627
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
621
628
|
|
|
622
629
|
const response = await fetch(\`\${apiUrl}/kakao/tools/call\`, {
|
|
623
630
|
method: 'POST',
|
|
@@ -639,7 +646,7 @@ export async function proxy(request: NextRequest) {
|
|
|
639
646
|
if (pathname.includes('__phone_proxy')) {
|
|
640
647
|
try {
|
|
641
648
|
const body = await request.text();
|
|
642
|
-
const apiUrl =
|
|
649
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
643
650
|
|
|
644
651
|
const response = await fetch(\`\${apiUrl}/phone/tools/call\`, {
|
|
645
652
|
method: 'POST',
|
|
@@ -661,7 +668,7 @@ export async function proxy(request: NextRequest) {
|
|
|
661
668
|
if (pathname.includes('__instagram_proxy')) {
|
|
662
669
|
try {
|
|
663
670
|
const body = await request.text();
|
|
664
|
-
const apiUrl =
|
|
671
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
665
672
|
|
|
666
673
|
const response = await fetch(\`\${apiUrl}/instagram/tools/call\`, {
|
|
667
674
|
method: 'POST',
|
|
@@ -683,7 +690,7 @@ export async function proxy(request: NextRequest) {
|
|
|
683
690
|
if (pathname.includes('__egdesk_config_proxy')) {
|
|
684
691
|
try {
|
|
685
692
|
const body = await request.text();
|
|
686
|
-
const apiUrl =
|
|
693
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
687
694
|
|
|
688
695
|
const response = await fetch(\`\${apiUrl}/egdesk-config/tools/call\`, {
|
|
689
696
|
method: 'POST',
|
|
@@ -705,7 +712,7 @@ export async function proxy(request: NextRequest) {
|
|
|
705
712
|
if (pathname.includes('__ai_caller_proxy')) {
|
|
706
713
|
try {
|
|
707
714
|
const body = await request.text();
|
|
708
|
-
const apiUrl =
|
|
715
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
709
716
|
|
|
710
717
|
const response = await fetch(\`\${apiUrl}/ai-caller/tools/call\`, {
|
|
711
718
|
method: 'POST',
|
|
@@ -727,7 +734,7 @@ export async function proxy(request: NextRequest) {
|
|
|
727
734
|
if (pathname.includes('__financehub_proxy')) {
|
|
728
735
|
try {
|
|
729
736
|
const body = await request.text();
|
|
730
|
-
const apiUrl =
|
|
737
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
731
738
|
|
|
732
739
|
const response = await fetch(\`\${apiUrl}/financehub/tools/call\`, {
|
|
733
740
|
method: 'POST',
|
|
@@ -749,7 +756,7 @@ export async function proxy(request: NextRequest) {
|
|
|
749
756
|
if (pathname.includes('__blog_proxy')) {
|
|
750
757
|
try {
|
|
751
758
|
const body = await request.text();
|
|
752
|
-
const apiUrl =
|
|
759
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
753
760
|
|
|
754
761
|
const response = await fetch(\`\${apiUrl}/blog/tools/call\`, {
|
|
755
762
|
method: 'POST',
|
|
@@ -771,7 +778,7 @@ export async function proxy(request: NextRequest) {
|
|
|
771
778
|
if (pathname.includes('__youtube_proxy')) {
|
|
772
779
|
try {
|
|
773
780
|
const body = await request.text();
|
|
774
|
-
const apiUrl =
|
|
781
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
775
782
|
|
|
776
783
|
const response = await fetch(\`\${apiUrl}/youtube/tools/call\`, {
|
|
777
784
|
method: 'POST',
|
|
@@ -793,7 +800,7 @@ export async function proxy(request: NextRequest) {
|
|
|
793
800
|
if (pathname.includes('__visitor_auth_proxy')) {
|
|
794
801
|
try {
|
|
795
802
|
const body = await request.text();
|
|
796
|
-
const apiUrl =
|
|
803
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
797
804
|
|
|
798
805
|
const response = await fetch(\`\${apiUrl}/visitor-auth/tools/call\`, {
|
|
799
806
|
method: 'POST',
|
|
@@ -815,7 +822,7 @@ export async function proxy(request: NextRequest) {
|
|
|
815
822
|
if (pathname.includes('__visitor_google_proxy')) {
|
|
816
823
|
try {
|
|
817
824
|
const body = await request.text();
|
|
818
|
-
const apiUrl =
|
|
825
|
+
const apiUrl = resolveEgdeskMcpApiUrl();
|
|
819
826
|
const headers = visitorForwardHeaders(request);
|
|
820
827
|
const authorization = request.headers.get('authorization');
|
|
821
828
|
if (authorization) headers['Authorization'] = authorization;
|
|
@@ -341,11 +341,35 @@ function isTunnelMcpRoot(value: string): boolean {
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
/** Custom-domain MCP roots must not keep /t/{id}; the gateway routes those by Host. */
|
|
345
|
+
function oauthBounceRoot(value: string): string {
|
|
346
|
+
try {
|
|
347
|
+
const parsed = new URL(value);
|
|
348
|
+
const gateway =
|
|
349
|
+
parsed.hostname === 'tunneling-service.onrender.com' ||
|
|
350
|
+
parsed.hostname.endsWith('.egdesk.cloud');
|
|
351
|
+
if (!gateway && /^\\/t\\/[^/]+/.test(parsed.pathname)) return parsed.origin;
|
|
352
|
+
return value.replace(/\\/$/, '');
|
|
353
|
+
} catch {
|
|
354
|
+
return value.replace(/\\/$/, '');
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function resolveRemoteMcpRoot(configured: string, tunnelUrl: string): string {
|
|
359
|
+
if (tunnelUrl && isTunnelMcpRoot(tunnelUrl)) {
|
|
360
|
+
return oauthBounceRoot(tunnelUrl);
|
|
361
|
+
}
|
|
362
|
+
if (configured && !isLocalEgdeskUrl(configured)) {
|
|
363
|
+
return oauthBounceRoot(configured);
|
|
364
|
+
}
|
|
365
|
+
return '';
|
|
366
|
+
}
|
|
367
|
+
|
|
344
368
|
/**
|
|
345
369
|
* MCP root passed to visitor-auth start (egdeskPublicUrl).
|
|
346
370
|
*
|
|
347
|
-
* - Loopback dev →
|
|
348
|
-
* - LAN IP → tunnel MCP root from
|
|
371
|
+
* - Loopback dev → NEXT_PUBLIC_EGDESK_TUNNEL_URL when set, else local MCP (OAuth bounces via :54321).
|
|
372
|
+
* - LAN IP → tunnel MCP root from NEXT_PUBLIC_EGDESK_TUNNEL_URL or non-local API URL (required).
|
|
349
373
|
* - Tunnel/custom domain → tunnel MCP root; never window.location.origin on dev/LAN hosts.
|
|
350
374
|
*
|
|
351
375
|
* Published hosts must never silently fall back to http://localhost:8080.
|
|
@@ -359,10 +383,11 @@ export function resolveEgdeskPublicUrl(): string {
|
|
|
359
383
|
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_TUNNEL_URL) ||
|
|
360
384
|
''
|
|
361
385
|
).replace(/\\/$/, '');
|
|
362
|
-
const
|
|
386
|
+
const remoteMcpRoot = resolveRemoteMcpRoot(configured, tunnelUrl);
|
|
387
|
+
const localMcpRoot = configured || tunnelUrl || 'http://localhost:8080';
|
|
363
388
|
|
|
364
389
|
if (typeof window === 'undefined') {
|
|
365
|
-
return
|
|
390
|
+
return remoteMcpRoot || localMcpRoot;
|
|
366
391
|
}
|
|
367
392
|
|
|
368
393
|
const hostname = window.location.hostname;
|
|
@@ -378,22 +403,23 @@ export function resolveEgdeskPublicUrl(): string {
|
|
|
378
403
|
}
|
|
379
404
|
|
|
380
405
|
if (isDevSiteHostname(hostname)) {
|
|
381
|
-
if (isPrivateLanHostname(hostname)
|
|
382
|
-
return
|
|
406
|
+
if (isPrivateLanHostname(hostname)) {
|
|
407
|
+
if (remoteMcpRoot) return remoteMcpRoot;
|
|
408
|
+
throw new Error(
|
|
409
|
+
'Visitor Google login from a LAN IP requires NEXT_PUBLIC_EGDESK_TUNNEL_URL or a tunnel MCP root in NEXT_PUBLIC_EGDESK_API_URL (https://…/t/{id}).',
|
|
410
|
+
);
|
|
383
411
|
}
|
|
384
412
|
if (isLoopbackHostname(hostname)) {
|
|
385
|
-
return
|
|
386
|
-
}
|
|
387
|
-
if (preferred && !isLocalEgdeskUrl(preferred)) {
|
|
388
|
-
return preferred;
|
|
413
|
+
return remoteMcpRoot || localMcpRoot;
|
|
389
414
|
}
|
|
415
|
+
if (remoteMcpRoot) return remoteMcpRoot;
|
|
390
416
|
throw new Error(
|
|
391
|
-
'Visitor Google login from a LAN IP requires
|
|
417
|
+
'Visitor Google login from a LAN IP requires NEXT_PUBLIC_EGDESK_TUNNEL_URL or a tunnel MCP root in NEXT_PUBLIC_EGDESK_API_URL (https://…/t/{id}).',
|
|
392
418
|
);
|
|
393
419
|
}
|
|
394
420
|
|
|
395
|
-
if (
|
|
396
|
-
return
|
|
421
|
+
if (remoteMcpRoot) {
|
|
422
|
+
return remoteMcpRoot;
|
|
397
423
|
}
|
|
398
424
|
|
|
399
425
|
console.error(
|
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.111";
|
|
12
12
|
export interface SetupOptions {
|
|
13
13
|
egdeskUrl?: string;
|
|
14
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
|
@@ -40,6 +40,7 @@ export type { UserDataTable, UserDataConfig } from './setup-userdata';
|
|
|
40
40
|
export { discoverTables, generateConfigFile, loadTablesFromSchemaFile, updateEnvFiles } from './setup-userdata';
|
|
41
41
|
export { generateMiddleware } from './generate-middleware';
|
|
42
42
|
export { generateProxy } from './generate-proxy';
|
|
43
|
+
export { generateChunkedUploadRoutes, generateVoiceTranscriptChunkedUploadRoutes, } from './generate-chunked-upload-routes';
|
|
43
44
|
export { generateHelpers, generateSchemaFile, ensureSchemaFile, formatEgdeskSchemaFileContent } from './generate-helpers';
|
|
44
45
|
export type { SchemaTableDefinition, EnsureSchemaFileResult, GenerateHelpersOptions } from './generate-helpers';
|
|
45
46
|
export { generateApiWrapper } from './generate-api-wrapper';
|
package/dist/index.js
CHANGED
|
@@ -39,19 +39,20 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
39
|
};
|
|
40
40
|
})();
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.ensureVisitorAuthConfig = exports.generateVisitorAuth = 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;
|
|
42
|
+
exports.ensureVisitorAuthConfig = exports.generateVisitorAuth = exports.generateApiWrapper = exports.formatEgdeskSchemaFileContent = exports.ensureSchemaFile = exports.generateSchemaFile = exports.generateHelpers = exports.generateVoiceTranscriptChunkedUploadRoutes = exports.generateChunkedUploadRoutes = 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.111';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
53
53
|
const generate_middleware_1 = require("./generate-middleware");
|
|
54
54
|
const generate_proxy_1 = require("./generate-proxy");
|
|
55
|
+
const generate_chunked_upload_routes_1 = require("./generate-chunked-upload-routes");
|
|
55
56
|
const generate_helpers_1 = require("./generate-helpers");
|
|
56
57
|
const generate_api_wrapper_1 = require("./generate-api-wrapper");
|
|
57
58
|
const generate_visitor_auth_1 = require("./generate-visitor-auth");
|
|
@@ -186,6 +187,8 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
186
187
|
columns: table.columns,
|
|
187
188
|
})));
|
|
188
189
|
(0, generate_helpers_1.generateHelpers)(projectPath, { apiKeyNames });
|
|
190
|
+
(0, generate_chunked_upload_routes_1.generateChunkedUploadRoutes)(projectPath);
|
|
191
|
+
(0, generate_chunked_upload_routes_1.generateVoiceTranscriptChunkedUploadRoutes)(projectPath);
|
|
189
192
|
(0, generate_api_wrapper_1.generateApiWrapper)(projectPath);
|
|
190
193
|
(0, generate_visitor_auth_1.generateVisitorAuth)(projectPath);
|
|
191
194
|
(0, setup_userdata_1.updateEnvFiles)(projectPath, config, prodTables);
|
|
@@ -196,6 +199,8 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
196
199
|
console.log(' - egdesk.config.ts (type-safe config)');
|
|
197
200
|
console.log(' - egdesk.schema.ts (committed seed schema — add to git if newly created)');
|
|
198
201
|
console.log(' - egdesk-helpers.ts (helper functions)');
|
|
202
|
+
console.log(' - app/api/user/files/uploads/* (chunked My DB file uploads)');
|
|
203
|
+
console.log(' - app/api/voice-transcript/uploads/* (chunked Voice Transcript audio)');
|
|
199
204
|
console.log(' - egdesk-visitor-google.ts (generated visitor Google helper — do not edit)');
|
|
200
205
|
console.log(' - egdesk.visitor-auth.ts (site-owned login defaults; never overwritten)');
|
|
201
206
|
console.log(' - src/lib/api.ts (basePath-aware fetch wrapper)');
|
|
@@ -237,6 +242,9 @@ var generate_middleware_2 = require("./generate-middleware");
|
|
|
237
242
|
Object.defineProperty(exports, "generateMiddleware", { enumerable: true, get: function () { return generate_middleware_2.generateMiddleware; } });
|
|
238
243
|
var generate_proxy_2 = require("./generate-proxy");
|
|
239
244
|
Object.defineProperty(exports, "generateProxy", { enumerable: true, get: function () { return generate_proxy_2.generateProxy; } });
|
|
245
|
+
var generate_chunked_upload_routes_2 = require("./generate-chunked-upload-routes");
|
|
246
|
+
Object.defineProperty(exports, "generateChunkedUploadRoutes", { enumerable: true, get: function () { return generate_chunked_upload_routes_2.generateChunkedUploadRoutes; } });
|
|
247
|
+
Object.defineProperty(exports, "generateVoiceTranscriptChunkedUploadRoutes", { enumerable: true, get: function () { return generate_chunked_upload_routes_2.generateVoiceTranscriptChunkedUploadRoutes; } });
|
|
240
248
|
var generate_helpers_2 = require("./generate-helpers");
|
|
241
249
|
Object.defineProperty(exports, "generateHelpers", { enumerable: true, get: function () { return generate_helpers_2.generateHelpers; } });
|
|
242
250
|
Object.defineProperty(exports, "generateSchemaFile", { enumerable: true, get: function () { return generate_helpers_2.generateSchemaFile; } });
|