@egdesk/next-api-plugin 1.5.49 → 1.5.53
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 +47 -4
- package/dist/generate-helpers.js +75 -2
- package/dist/generate-proxy.js +24 -2
- package/dist/generate-visitor-auth.d.ts +1 -0
- package/dist/generate-visitor-auth.js +87 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,8 +32,9 @@ This will generate:
|
|
|
32
32
|
- `middleware.ts` or `proxy.ts` - Database proxy (includes visitor auth/google)
|
|
33
33
|
- `egdesk.config.ts` - Type-safe table definitions
|
|
34
34
|
- `egdesk-helpers.ts` - Helper functions for database access
|
|
35
|
-
- `egdesk-visitor-google.ts` - Visitor Google login (
|
|
36
|
-
- `
|
|
35
|
+
- `egdesk-visitor-google.ts` - Visitor Google login helper (**generated — do not edit**)
|
|
36
|
+
- `egdesk.visitor-auth.ts` - Site-owned login defaults (created once, never overwritten)
|
|
37
|
+
- `app/auth/callback/page.tsx` - Exchanges EGDesk’s one-time login code (**generated — do not edit**)
|
|
37
38
|
- `.env.local` - Environment variables (`NEXT_PUBLIC_EGDESK_*` only — no Supabase keys)
|
|
38
39
|
|
|
39
40
|
Add `{EGDesk public URL}/visitor-auth/callback` to the EGDesk Supabase Auth redirect allowlist (once per EGDesk/tunnel origin, not each published site).
|
|
@@ -72,10 +73,51 @@ NEXT_PUBLIC_EGDESK_API_KEY=your-api-key-here
|
|
|
72
73
|
|
|
73
74
|
Published sites do **not** receive `SUPABASE_URL` or the anon key. Visitor Google sign-in is brokered by EGDesk: the site redirects through `{EGDESK_API}/visitor-auth`, EGDesk creates an Auth user, and the site stores an opaque session id bound to **this site's origin**. Another published site on the same EGDesk cannot reuse that session.
|
|
74
75
|
|
|
75
|
-
Add the **EGDesk** callback (not each site origin) to **Supabase → Authentication → URL Configuration → Redirect URLs
|
|
76
|
+
Add the **EGDesk** callback (not each site origin) to **Supabase → Authentication → URL Configuration → Redirect URLs**:
|
|
77
|
+
|
|
78
|
+
- Local: `http://localhost:54321/auth/callback`
|
|
79
|
+
- Tunnel: `https://tunneling-service.onrender.com/t/{tunnelId}/visitor-auth/callback` or `https://tunneling-service.onrender.com/**`
|
|
80
|
+
|
|
81
|
+
Do not add `?vid=` — extra query params make Supabase fall back to the Site URL (`egdesk.cloud`).
|
|
76
82
|
|
|
77
83
|
Owner MCP (`startDriveAuthLogin`) is a separate credential on the EGDesk machine. Visitor login does not overwrite it.
|
|
78
84
|
|
|
85
|
+
### Visitor login: generated vs site-owned
|
|
86
|
+
|
|
87
|
+
| File | Owner | Overwritten on codegen? |
|
|
88
|
+
|------|--------|-------------------------|
|
|
89
|
+
| `egdesk-visitor-google.ts` | EGDesk plugin | Yes |
|
|
90
|
+
| `app/auth/callback/page.tsx` | EGDesk plugin | Yes |
|
|
91
|
+
| `egdesk.visitor-auth.ts` | The site | **No** |
|
|
92
|
+
| `app/login/page.tsx` (or any custom UI) | The site | Never generated |
|
|
93
|
+
|
|
94
|
+
Do not copy helper constants into `src/` to survive regeneration. Import presets and pass them:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import {
|
|
98
|
+
startVisitorGoogleLogin,
|
|
99
|
+
VISITOR_BASIC_SCOPES,
|
|
100
|
+
VISITOR_WORKSPACE_SCOPES,
|
|
101
|
+
} from './egdesk-visitor-google';
|
|
102
|
+
|
|
103
|
+
// Sign-in only (smaller Google consent)
|
|
104
|
+
await startVisitorGoogleLogin({ next: '/dashboard', scopes: VISITOR_BASIC_SCOPES });
|
|
105
|
+
|
|
106
|
+
// Drive / Sheets / Docs / Slides
|
|
107
|
+
await startVisitorGoogleLogin({ next: '/drive', scopes: VISITOR_WORKSPACE_SCOPES });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Project default (never overwritten):
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// egdesk.visitor-auth.ts
|
|
114
|
+
export const VISITOR_AUTH = {
|
|
115
|
+
scopes: 'basic' as 'basic' | 'workspace',
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`NEXT_PUBLIC_EGDESK_VISITOR_SCOPES=basic|workspace` overrides that file. EGDesk allowlists scopes server-side; unknown Google APIs are dropped. Older helpers that send no scopes still get workspace (previous default).
|
|
120
|
+
|
|
79
121
|
### Custom Setup
|
|
80
122
|
|
|
81
123
|
You can programmatically run the setup:
|
|
@@ -161,7 +203,8 @@ startDriveAuthLogin()
|
|
|
161
203
|
getDriveAuthStatus()
|
|
162
204
|
|
|
163
205
|
// Visitor Google — import from egdesk-visitor-google.ts, not egdesk-helpers.ts
|
|
164
|
-
startVisitorGoogleLogin()
|
|
206
|
+
startVisitorGoogleLogin({ scopes: VISITOR_BASIC_SCOPES })
|
|
207
|
+
startVisitorGoogleLogin({ scopes: VISITOR_WORKSPACE_SCOPES })
|
|
165
208
|
getVisitorGoogleStatus()
|
|
166
209
|
listVisitorDriveFiles()
|
|
167
210
|
getVisitorSheetRange(spreadsheetId, range)
|
package/dist/generate-helpers.js
CHANGED
|
@@ -139,7 +139,7 @@ function generateHelpers(projectPath, options = {}) {
|
|
|
139
139
|
*
|
|
140
140
|
* Type-safe helpers for EGDesk user data, Google Workspace (Sheets / Drive / Docs / Slides MCP + sync, Gmail, Apps Script),
|
|
141
141
|
* FinanceHub (banks, cards, Hometax, promissory notes),
|
|
142
|
-
* internal knowledge / business identity / company research (MCP), Korean law (MCP), and browser recorder replay / live browse.
|
|
142
|
+
* internal knowledge / business identity / company research (MCP), Korean law (MCP), Bizinfo grants (MCP), and browser recorder replay / live browse.
|
|
143
143
|
* Works in both client and server components.
|
|
144
144
|
*
|
|
145
145
|
* Generated by @egdesk/next-api-plugin — do not edit by hand.
|
|
@@ -2308,6 +2308,79 @@ export async function getKoreanLawDecision(id: string) {
|
|
|
2308
2308
|
return callKoreanLawTool('korean_law_get_decision', { id });
|
|
2309
2309
|
}
|
|
2310
2310
|
|
|
2311
|
+
// ==========================================
|
|
2312
|
+
// BIZINFO / 기업마당 지원사업 (MCP)
|
|
2313
|
+
// ==========================================
|
|
2314
|
+
|
|
2315
|
+
/**
|
|
2316
|
+
* Call EGDesk Bizinfo MCP tool (기업마당 지원사업 공고 — grants, not company verify).
|
|
2317
|
+
*
|
|
2318
|
+
* - Server: \`POST {apiUrl}/bizinfo/tools/call\`
|
|
2319
|
+
* - Client: \`POST /__bizinfo_proxy\` (see proxy.ts / middleware)
|
|
2320
|
+
* - Tunnel: \`POST https://tunneling-service.onrender.com/t/{id}/bizinfo/tools/call\`
|
|
2321
|
+
*/
|
|
2322
|
+
export async function callBizinfoTool(
|
|
2323
|
+
toolName: string,
|
|
2324
|
+
args: Record<string, any> = {}
|
|
2325
|
+
): Promise<any> {
|
|
2326
|
+
const body = JSON.stringify({ tool: toolName, arguments: args });
|
|
2327
|
+
|
|
2328
|
+
const isServer = typeof window === 'undefined';
|
|
2329
|
+
|
|
2330
|
+
let response: Response;
|
|
2331
|
+
if (isServer) {
|
|
2332
|
+
const apiUrl =
|
|
2333
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
2334
|
+
EGDESK_CONFIG.apiUrl;
|
|
2335
|
+
response = await fetch(\`\${apiUrl}/bizinfo/tools/call\`, {
|
|
2336
|
+
method: 'POST',
|
|
2337
|
+
headers: buildServerEgdeskHeaders(),
|
|
2338
|
+
body
|
|
2339
|
+
});
|
|
2340
|
+
} else {
|
|
2341
|
+
response = await apiFetch('/__bizinfo_proxy', {
|
|
2342
|
+
method: 'POST',
|
|
2343
|
+
headers: { 'Content-Type': 'application/json' },
|
|
2344
|
+
body
|
|
2345
|
+
});
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
return parseEgdeskMcpToolResponse(response);
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
/** Search government grants / 지원사업 (category, region, optional client-side query). Not a company registry. */
|
|
2352
|
+
export async function searchBizinfo(
|
|
2353
|
+
options: {
|
|
2354
|
+
category?: 'finance' | 'tech' | 'talent' | 'export' | 'domestic' | 'startup' | 'management' | 'other';
|
|
2355
|
+
region?: string;
|
|
2356
|
+
hashtags?: string;
|
|
2357
|
+
query?: string;
|
|
2358
|
+
display?: number;
|
|
2359
|
+
page?: number;
|
|
2360
|
+
} = {}
|
|
2361
|
+
) {
|
|
2362
|
+
return callBizinfoTool('bizinfo_search', options);
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
/** Currently open 지원사업, sorted by deadline */
|
|
2366
|
+
export async function listOpenBizinfo(
|
|
2367
|
+
options: {
|
|
2368
|
+
category?: 'finance' | 'tech' | 'talent' | 'export' | 'domestic' | 'startup' | 'management' | 'other';
|
|
2369
|
+
region?: string;
|
|
2370
|
+
hashtags?: string;
|
|
2371
|
+
query?: string;
|
|
2372
|
+
display?: number;
|
|
2373
|
+
page?: number;
|
|
2374
|
+
} = {}
|
|
2375
|
+
) {
|
|
2376
|
+
return callBizinfoTool('bizinfo_open', options);
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
/** Get one announcement by pblancId */
|
|
2380
|
+
export async function getBizinfoAnnouncement(id: string) {
|
|
2381
|
+
return callBizinfoTool('bizinfo_get', { id });
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2311
2384
|
// ==========================================
|
|
2312
2385
|
// SEO (MCP)
|
|
2313
2386
|
// ==========================================
|
|
@@ -2862,7 +2935,7 @@ export async function deletePageIndexDocument(docId: string) {
|
|
|
2862
2935
|
*
|
|
2863
2936
|
* Owner MCP auth on EGDesk: GOOGLE_SERVICE_ACCOUNT_JSON or Google Workspace sign-in
|
|
2864
2937
|
* via startDriveAuthLogin() — configures THIS EGDesk instance, not website visitors.
|
|
2865
|
-
* Website visitors should use startVisitorGoogleLogin() from egdesk-visitor-google.ts
|
|
2938
|
+
* Website visitors should use startVisitorGoogleLogin({ scopes }) from egdesk-visitor-google.ts
|
|
2866
2939
|
* (EGDesk brokers Auth; the site never receives Supabase keys).
|
|
2867
2940
|
* Share target folders with the service account when using SA credentials.
|
|
2868
2941
|
*
|
package/dist/generate-proxy.js
CHANGED
|
@@ -75,7 +75,7 @@ import type { NextRequest } from 'next/server';
|
|
|
75
75
|
/**
|
|
76
76
|
* EGDesk Database Proxy (Next.js 16+)
|
|
77
77
|
*
|
|
78
|
-
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __sheets_proxy, __docs_proxy, __slides_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, __instagram_proxy, __financehub_proxy, __blog_proxy, __youtube_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
|
|
78
|
+
* Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __bizinfo_proxy, __seo_proxy, __ssl_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __sheets_proxy, __docs_proxy, __slides_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, __instagram_proxy, __financehub_proxy, __blog_proxy, __youtube_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
|
|
79
79
|
* and forwards them to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
|
|
80
80
|
*
|
|
81
81
|
* Generated by @egdesk/next-api-plugin
|
|
@@ -217,6 +217,28 @@ export async function proxy(request: NextRequest) {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
+
if (pathname.includes('__bizinfo_proxy')) {
|
|
221
|
+
try {
|
|
222
|
+
const body = await request.text();
|
|
223
|
+
const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
224
|
+
|
|
225
|
+
const response = await fetch(\`\${apiUrl}/bizinfo/tools/call\`, {
|
|
226
|
+
method: 'POST',
|
|
227
|
+
headers: buildEgdeskHeaders(),
|
|
228
|
+
body,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const result = await response.json();
|
|
232
|
+
|
|
233
|
+
return NextResponse.json(result, { status: response.status });
|
|
234
|
+
} catch (error: any) {
|
|
235
|
+
return NextResponse.json(
|
|
236
|
+
{ error: 'Proxy error', message: error.message },
|
|
237
|
+
{ status: 500 }
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
220
242
|
if (pathname.includes('__seo_proxy')) {
|
|
221
243
|
try {
|
|
222
244
|
const body = await request.text();
|
|
@@ -737,7 +759,7 @@ export const config = {
|
|
|
737
759
|
matcher: [
|
|
738
760
|
/*
|
|
739
761
|
* Match all paths except static assets
|
|
740
|
-
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __sheets_proxy / __docs_proxy / __slides_proxy / __egdesk_http_proxy / __gmail_proxy / __apps_script_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy / __financehub_proxy / __blog_proxy / __youtube_proxy / __visitor_auth_proxy / __visitor_google_proxy
|
|
762
|
+
* The proxy function filters for __user_data_proxy / __browser_recording_proxy / __internal_knowledge_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __bizinfo_proxy / __seo_proxy / __ssl_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __sheets_proxy / __docs_proxy / __slides_proxy / __egdesk_http_proxy / __gmail_proxy / __apps_script_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy / __financehub_proxy / __blog_proxy / __youtube_proxy / __visitor_auth_proxy / __visitor_google_proxy
|
|
741
763
|
*/
|
|
742
764
|
'/:path*',
|
|
743
765
|
],
|
|
@@ -5,4 +5,5 @@
|
|
|
5
5
|
* EGDesk (same Auth project) and receive an opaque session id.
|
|
6
6
|
* Published sites never receive SUPABASE_URL or the anon key.
|
|
7
7
|
*/
|
|
8
|
+
export declare function ensureVisitorAuthConfig(projectPath: string): boolean;
|
|
8
9
|
export declare function generateVisitorAuth(projectPath: string): void;
|
|
@@ -40,6 +40,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
40
40
|
};
|
|
41
41
|
})();
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.ensureVisitorAuthConfig = ensureVisitorAuthConfig;
|
|
43
44
|
exports.generateVisitorAuth = generateVisitorAuth;
|
|
44
45
|
const fs = __importStar(require("fs"));
|
|
45
46
|
const path = __importStar(require("path"));
|
|
@@ -87,7 +88,11 @@ const CALLBACK_PAGE = `'use client';
|
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
90
|
* Visitor Google OAuth callback.
|
|
90
|
-
* Generated by @egdesk/next-api-plugin.
|
|
91
|
+
* Generated by @egdesk/next-api-plugin — do not edit.
|
|
92
|
+
*
|
|
93
|
+
* Customize login UI in your own pages (e.g. app/login/page.tsx).
|
|
94
|
+
* Set default scopes in egdesk.visitor-auth.ts, or pass them to
|
|
95
|
+
* startVisitorGoogleLogin({ scopes: VISITOR_BASIC_SCOPES }).
|
|
91
96
|
*
|
|
92
97
|
* EGDesk completes Google/Supabase OAuth, then redirects here with ?code=
|
|
93
98
|
* (a one-time EGDesk code, not a Supabase token). This page exchanges it
|
|
@@ -126,6 +131,23 @@ export default function VisitorAuthCallbackPage() {
|
|
|
126
131
|
);
|
|
127
132
|
}
|
|
128
133
|
`;
|
|
134
|
+
const VISITOR_AUTH_CONFIG = `/**
|
|
135
|
+
* Visitor Google login defaults for this site.
|
|
136
|
+
*
|
|
137
|
+
* OWNED BY THIS PROJECT — EGDesk will not overwrite this file.
|
|
138
|
+
* Generated helpers (egdesk-visitor-google.ts) read these defaults.
|
|
139
|
+
*
|
|
140
|
+
* Customize login UI in your own pages. Do not edit generated helpers.
|
|
141
|
+
*/
|
|
142
|
+
export const VISITOR_AUTH = {
|
|
143
|
+
/**
|
|
144
|
+
* 'basic' — email/profile only (smaller Google consent).
|
|
145
|
+
* 'workspace' — Drive (per-file), Sheets, Docs, Slides.
|
|
146
|
+
* A page can still pass startVisitorGoogleLogin({ scopes: VISITOR_WORKSPACE_SCOPES }).
|
|
147
|
+
*/
|
|
148
|
+
scopes: 'basic' as 'basic' | 'workspace',
|
|
149
|
+
};
|
|
150
|
+
`;
|
|
129
151
|
const VISITOR_HELPERS = `/**
|
|
130
152
|
* EGDesk visitor Google helpers (published-site visitors).
|
|
131
153
|
*
|
|
@@ -134,25 +156,51 @@ const VISITOR_HELPERS = `/**
|
|
|
134
156
|
* The opaque session is bound to this site origin and will not work on
|
|
135
157
|
* another published site that shares the same EGDesk.
|
|
136
158
|
*
|
|
137
|
-
*
|
|
159
|
+
* Generated by @egdesk/next-api-plugin — do not edit.
|
|
160
|
+
* Customize login UI in your pages. Set default scopes in egdesk.visitor-auth.ts
|
|
161
|
+
* or pass startVisitorGoogleLogin({ scopes: VISITOR_BASIC_SCOPES }).
|
|
138
162
|
*
|
|
139
|
-
*
|
|
163
|
+
* Import this file only from pages that need visitor Google.
|
|
140
164
|
*/
|
|
141
165
|
|
|
142
166
|
import { apiFetch } from './egdesk-helpers';
|
|
167
|
+
import { VISITOR_AUTH } from './egdesk.visitor-auth';
|
|
143
168
|
|
|
144
169
|
const VISITOR_SESSION_KEY = 'egdesk_visitor_session';
|
|
145
170
|
|
|
146
|
-
export
|
|
171
|
+
export type VisitorScopePreset = 'basic' | 'workspace';
|
|
172
|
+
|
|
173
|
+
export const VISITOR_BASIC_SCOPES = [
|
|
147
174
|
'https://www.googleapis.com/auth/userinfo.email',
|
|
148
175
|
'https://www.googleapis.com/auth/userinfo.profile',
|
|
176
|
+
'openid',
|
|
177
|
+
] as const;
|
|
178
|
+
|
|
179
|
+
export const VISITOR_WORKSPACE_SCOPES = [
|
|
180
|
+
...VISITOR_BASIC_SCOPES,
|
|
149
181
|
'https://www.googleapis.com/auth/drive.file',
|
|
150
182
|
'https://www.googleapis.com/auth/spreadsheets',
|
|
151
183
|
'https://www.googleapis.com/auth/documents',
|
|
152
184
|
'https://www.googleapis.com/auth/presentations',
|
|
153
|
-
'openid',
|
|
154
185
|
] as const;
|
|
155
186
|
|
|
187
|
+
/** @deprecated use VISITOR_WORKSPACE_SCOPES */
|
|
188
|
+
export const VISITOR_GOOGLE_OAUTH_SCOPES = VISITOR_WORKSPACE_SCOPES;
|
|
189
|
+
|
|
190
|
+
function resolveVisitorLoginScopes(
|
|
191
|
+
override?: readonly string[] | VisitorScopePreset,
|
|
192
|
+
): string[] {
|
|
193
|
+
if (override === 'basic') return [...VISITOR_BASIC_SCOPES];
|
|
194
|
+
if (override === 'workspace') return [...VISITOR_WORKSPACE_SCOPES];
|
|
195
|
+
if (Array.isArray(override) && override.length > 0) return [...override];
|
|
196
|
+
const fromEnv =
|
|
197
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_VISITOR_SCOPES) || '';
|
|
198
|
+
if (fromEnv === 'workspace') return [...VISITOR_WORKSPACE_SCOPES];
|
|
199
|
+
if (fromEnv === 'basic') return [...VISITOR_BASIC_SCOPES];
|
|
200
|
+
if (VISITOR_AUTH.scopes === 'workspace') return [...VISITOR_WORKSPACE_SCOPES];
|
|
201
|
+
return [...VISITOR_BASIC_SCOPES];
|
|
202
|
+
}
|
|
203
|
+
|
|
156
204
|
function getVisitorSessionId(): string | null {
|
|
157
205
|
if (typeof window === 'undefined') return null;
|
|
158
206
|
return window.localStorage.getItem(VISITOR_SESSION_KEY);
|
|
@@ -202,6 +250,22 @@ export function resolveVisitorAppPath(path: string): string {
|
|
|
202
250
|
return base + normalized;
|
|
203
251
|
}
|
|
204
252
|
|
|
253
|
+
/** MCP root for the public tunnel, e.g. https://tunneling-service.onrender.com/t/{id} */
|
|
254
|
+
export function resolveEgdeskPublicUrl(): string {
|
|
255
|
+
const configured =
|
|
256
|
+
(typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
|
|
257
|
+
'http://localhost:8080';
|
|
258
|
+
if (typeof window === 'undefined') return configured;
|
|
259
|
+
const parts = window.location.pathname.split('/').filter(Boolean);
|
|
260
|
+
const onTunnelGateway =
|
|
261
|
+
window.location.hostname === 'tunneling-service.onrender.com' ||
|
|
262
|
+
window.location.hostname.endsWith('.egdesk.cloud');
|
|
263
|
+
if (onTunnelGateway && parts[0] === 't' && parts[1]) {
|
|
264
|
+
return window.location.origin + '/t/' + parts[1];
|
|
265
|
+
}
|
|
266
|
+
return configured;
|
|
267
|
+
}
|
|
268
|
+
|
|
205
269
|
async function callVisitorAuth(tool: string, args: Record<string, unknown> = {}) {
|
|
206
270
|
const response = await apiFetch('/__visitor_auth_proxy', {
|
|
207
271
|
method: 'POST',
|
|
@@ -231,10 +295,14 @@ async function callVisitorGoogle(tool: string, args: Record<string, unknown> = {
|
|
|
231
295
|
/**
|
|
232
296
|
* Sign a website visitor in with Google via EGDesk.
|
|
233
297
|
* Creates/uses an EGDesk user; Google tokens stay under that user_id on EGDesk.
|
|
298
|
+
*
|
|
299
|
+
* Default scopes come from egdesk.visitor-auth.ts (never overwritten).
|
|
300
|
+
* Pass scopes to override per button, e.g. VISITOR_BASIC_SCOPES or 'workspace'.
|
|
234
301
|
*/
|
|
235
302
|
export async function startVisitorGoogleLogin(options: {
|
|
236
303
|
next?: string;
|
|
237
304
|
forceConsent?: boolean;
|
|
305
|
+
scopes?: readonly string[] | VisitorScopePreset;
|
|
238
306
|
} = {}) {
|
|
239
307
|
if (typeof window === 'undefined') {
|
|
240
308
|
throw new Error('startVisitorGoogleLogin() must run in the browser');
|
|
@@ -244,15 +312,15 @@ export async function startVisitorGoogleLogin(options: {
|
|
|
244
312
|
);
|
|
245
313
|
const returnTo = new URL(resolveVisitorAppPath('/auth/callback'), window.location.origin);
|
|
246
314
|
returnTo.searchParams.set('next', next);
|
|
247
|
-
//
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
|
|
315
|
+
// Localhost → EGDesk :54321. Tunnel site → {gateway}/t/{id}/visitor-auth/callback.
|
|
316
|
+
const egdeskPublicUrl = resolveEgdeskPublicUrl();
|
|
317
|
+
const scopes = resolveVisitorLoginScopes(options.scopes);
|
|
251
318
|
|
|
252
319
|
const result = await callVisitorAuth('start', {
|
|
253
320
|
returnTo: returnTo.toString(),
|
|
254
321
|
egdeskPublicUrl,
|
|
255
|
-
forceConsent: options.forceConsent
|
|
322
|
+
forceConsent: options.forceConsent === true,
|
|
323
|
+
scopes,
|
|
256
324
|
});
|
|
257
325
|
if (!result?.authUrl) {
|
|
258
326
|
throw new Error(result?.error || 'Failed to start visitor Google login');
|
|
@@ -300,8 +368,17 @@ export async function getVisitorSheetRange(spreadsheetId: string, range: string)
|
|
|
300
368
|
return callVisitorGoogle('getSheetRange', { spreadsheetId, range });
|
|
301
369
|
}
|
|
302
370
|
`;
|
|
371
|
+
function ensureVisitorAuthConfig(projectPath) {
|
|
372
|
+
const configPath = path.join(projectPath, 'egdesk.visitor-auth.ts');
|
|
373
|
+
if (fs.existsSync(configPath))
|
|
374
|
+
return false;
|
|
375
|
+
fs.writeFileSync(configPath, VISITOR_AUTH_CONFIG.replace(/\r?\n/g, os.EOL), 'utf-8');
|
|
376
|
+
console.log(`✅ Created ${configPath} (site-owned; will not be overwritten)`);
|
|
377
|
+
return true;
|
|
378
|
+
}
|
|
303
379
|
function generateVisitorAuth(projectPath) {
|
|
304
380
|
const appDir = resolveAppDir(projectPath);
|
|
381
|
+
ensureVisitorAuthConfig(projectPath);
|
|
305
382
|
writeGenerated(path.join(appDir, 'auth', 'callback', 'page.tsx'), CALLBACK_PAGE);
|
|
306
383
|
writeGenerated(path.join(projectPath, 'egdesk-visitor-google.ts'), VISITOR_HELPERS);
|
|
307
384
|
removeIfExists(path.join(appDir, 'api', 'visitor-google', 'route.ts'));
|
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.61";
|
|
12
12
|
export interface SetupOptions {
|
|
13
13
|
egdeskUrl?: string;
|
|
14
14
|
/** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
|
|
@@ -43,4 +43,4 @@ export { generateProxy } from './generate-proxy';
|
|
|
43
43
|
export { generateHelpers, generateSchemaFile, ensureSchemaFile, formatEgdeskSchemaFileContent } from './generate-helpers';
|
|
44
44
|
export type { SchemaTableDefinition, EnsureSchemaFileResult, GenerateHelpersOptions } from './generate-helpers';
|
|
45
45
|
export { generateApiWrapper } from './generate-api-wrapper';
|
|
46
|
-
export { generateVisitorAuth } from './generate-visitor-auth';
|
|
46
|
+
export { generateVisitorAuth, ensureVisitorAuthConfig } from './generate-visitor-auth';
|
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.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.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.61';
|
|
50
50
|
const fs = __importStar(require("fs"));
|
|
51
51
|
const path = __importStar(require("path"));
|
|
52
52
|
const setup_userdata_1 = require("./setup-userdata");
|
|
@@ -196,7 +196,8 @@ async function setupNextApiPlugin(projectPath, options = {}) {
|
|
|
196
196
|
console.log(' - egdesk.config.ts (type-safe config)');
|
|
197
197
|
console.log(' - egdesk.schema.ts (committed seed schema — add to git if newly created)');
|
|
198
198
|
console.log(' - egdesk-helpers.ts (helper functions)');
|
|
199
|
-
console.log(' - egdesk-visitor-google.ts (visitor Google
|
|
199
|
+
console.log(' - egdesk-visitor-google.ts (generated visitor Google helper — do not edit)');
|
|
200
|
+
console.log(' - egdesk.visitor-auth.ts (site-owned login defaults; never overwritten)');
|
|
200
201
|
console.log(' - src/lib/api.ts (basePath-aware fetch wrapper)');
|
|
201
202
|
console.log(' - app/auth/callback/page.tsx (exchanges EGDesk one-time login code)');
|
|
202
203
|
console.log(' - .env.development.local (dev environment variables)');
|
|
@@ -243,3 +244,4 @@ var generate_api_wrapper_2 = require("./generate-api-wrapper");
|
|
|
243
244
|
Object.defineProperty(exports, "generateApiWrapper", { enumerable: true, get: function () { return generate_api_wrapper_2.generateApiWrapper; } });
|
|
244
245
|
var generate_visitor_auth_2 = require("./generate-visitor-auth");
|
|
245
246
|
Object.defineProperty(exports, "generateVisitorAuth", { enumerable: true, get: function () { return generate_visitor_auth_2.generateVisitorAuth; } });
|
|
247
|
+
Object.defineProperty(exports, "ensureVisitorAuthConfig", { enumerable: true, get: function () { return generate_visitor_auth_2.ensureVisitorAuthConfig; } });
|