@egdesk/next-api-plugin 1.5.70 → 1.5.84

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 CHANGED
@@ -37,7 +37,7 @@ This will generate:
37
37
  - `app/auth/callback/page.tsx` - Exchanges EGDesk’s one-time login code (**generated — do not edit**)
38
38
  - `.env.local` - Environment variables (`NEXT_PUBLIC_EGDESK_*` only — no Supabase keys)
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).
40
+ Add `{EGDesk public URL}/visitor-auth/callback/**` to the EGDesk Supabase Auth redirect allowlist (once per EGDesk/tunnel origin, not each published site). The pending login id is a path segment so concurrent visitors do not share one in-memory slot.
41
41
 
42
42
  2. Add `.env.local` to your `.gitignore` (if not already there)
43
43
 
@@ -75,10 +75,12 @@ Published sites do **not** receive `SUPABASE_URL` or the anon key. Visitor Googl
75
75
 
76
76
  Add the **EGDesk** callback (not each site origin) to **Supabase → Authentication → URL Configuration → Redirect URLs**:
77
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/**`
78
+ - Local (owner and localhost visitor): `http://localhost:54321/auth/callback` exactly. Do not add a path or `?vid=` — Supabase will fall back to the Site URL (`egdesk.cloud`).
79
+ - Tunnel: `https://tunneling-service.onrender.com/t/{tunnelId}/visitor-auth/callback/**` or `https://tunneling-service.onrender.com/**`
80
80
 
81
- Do not add `?vid=` — extra query params make Supabase fall back to the Site URL (`egdesk.cloud`).
81
+ Do not put the pending id in a query string (`?vid=`) — extra query params make Supabase fall back to the Site URL (`egdesk.cloud`).
82
+
83
+ On a published host, `NEXT_PUBLIC_EGDESK_API_URL` must be the tunnel MCP root (`https://…/t/{id}`), not `http://localhost:8080`. The generated helper will refuse that localhost fallback in the browser.
82
84
 
83
85
  Owner MCP (`startDriveAuthLogin`) is a separate credential on the EGDesk machine. Visitor login does not overwrite it.
84
86
 
package/dist/cli.js CHANGED
@@ -37,7 +37,7 @@ async function main() {
37
37
  console.log(' --help, -h Show this help message');
38
38
  console.log('');
39
39
  console.log('Visitor Google sign-in is brokered by EGDesk (no Supabase keys on the site).');
40
- console.log('Add {EGDesk public URL}/visitor-auth/callback to the Supabase Auth redirect allowlist.');
40
+ console.log('Add {EGDesk public URL}/visitor-auth/callback/** to the Supabase Auth redirect allowlist.');
41
41
  console.log('');
42
42
  console.log('Example:');
43
43
  console.log(' egdesk-next-setup --url http://localhost:8080 --api-key mykey');
@@ -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), Bizinfo grants (MCP), NPS workplace headcount (MCP), and browser recorder replay / live browse.
142
+ * internal knowledge / business identity / company research (MCP), company research docs (cited tool-result blocks), Korean law (MCP), Bizinfo grants (MCP), NPS workplace headcount (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.
@@ -1768,6 +1768,87 @@ export async function searchCompanyResearch(searchText: string) {
1768
1768
  return callCompanyResearchTool('companyresearch_search', { searchText });
1769
1769
  }
1770
1770
 
1771
+ // ==========================================
1772
+ // COMPANY RESEARCH DOCS (interactive cited canvases)
1773
+ // ==========================================
1774
+
1775
+ /** List interactive company research docs (one per businessNumber) */
1776
+ export async function listCompanyResearchDocs() {
1777
+ return callCompanyResearchTool('companyresearch_doc_list', {});
1778
+ }
1779
+
1780
+ /** Get company research doc by businessNumber or docId */
1781
+ export async function getCompanyResearchDoc(options: {
1782
+ businessNumber?: string;
1783
+ docId?: string;
1784
+ }) {
1785
+ return callCompanyResearchTool('companyresearch_doc_get', options);
1786
+ }
1787
+
1788
+ /** Get or create the doc for a company (unique per businessNumber) */
1789
+ export async function getOrCreateCompanyResearchDoc(input: {
1790
+ businessNumber: string;
1791
+ companyName?: string;
1792
+ domain?: string;
1793
+ title?: string;
1794
+ }) {
1795
+ return callCompanyResearchTool('companyresearch_doc_get_or_create', input);
1796
+ }
1797
+
1798
+ /**
1799
+ * Run a company-research tool and append a cited block to the company doc —
1800
+ * same as "문서에 넣기" in the Company Research doc editor UI.
1801
+ */
1802
+ export async function insertCompanyResearchDocToolResult(input: {
1803
+ businessNumber: string;
1804
+ toolName: string;
1805
+ params?: Record<string, unknown>;
1806
+ companyName?: string;
1807
+ domain?: string;
1808
+ title?: string;
1809
+ }) {
1810
+ return callCompanyResearchTool('companyresearch_doc_insert_tool_result', input);
1811
+ }
1812
+
1813
+ /** Append already-fetched tool JSON to a company doc without re-running the tool */
1814
+ export async function insertCompanyResearchDocResult(input: {
1815
+ businessNumber: string;
1816
+ toolName: string;
1817
+ rawResult: unknown;
1818
+ companyName?: string;
1819
+ domain?: string;
1820
+ title?: string;
1821
+ }) {
1822
+ return callCompanyResearchTool('companyresearch_doc_insert_result', input);
1823
+ }
1824
+
1825
+ /** Fixed proposal deck layouts and hard content limits (no LLM). */
1826
+ export async function getProposalLayoutCatalog() {
1827
+ return callCompanyResearchTool('companyresearch_proposal_layout_catalog', {});
1828
+ }
1829
+
1830
+ /** Validate structured proposal slide JSON → placeholders + slides[] for export. */
1831
+ export async function parseProposalSlideContent(content: unknown) {
1832
+ return callCompanyResearchTool('companyresearch_proposal_parse_content', { content });
1833
+ }
1834
+
1835
+ /** LLM: excerpt → structured proposal content (same as Doc Editor slide-from-text). */
1836
+ export async function structureCompanyResearchDocSlideFromText(text: string) {
1837
+ return callCompanyResearchTool('companyresearch_doc_slide_from_text', { text });
1838
+ }
1839
+
1840
+ /** Append slides[] to a company research doc deck. */
1841
+ export async function appendCompanyResearchDocSlides(input: {
1842
+ businessNumber?: string;
1843
+ docId?: string;
1844
+ slides: unknown[];
1845
+ companyName?: string;
1846
+ domain?: string;
1847
+ title?: string;
1848
+ }) {
1849
+ return callCompanyResearchTool('companyresearch_doc_append_slides', input);
1850
+ }
1851
+
1771
1852
  // ==========================================
1772
1853
  // BROWSER RECORDING HELPERS
1773
1854
  // ==========================================
@@ -1856,6 +1937,27 @@ export async function runBrowserRecording(
1856
1937
  });
1857
1938
  }
1858
1939
 
1940
+ /** Indexed actions for a saved recording (use upToActionIndex with playBrowserRecordingUpTo) */
1941
+ export async function listBrowserRecordingActions(testFile: string) {
1942
+ return callBrowserRecordingTool('browser_recording_list_actions', { testFile });
1943
+ }
1944
+
1945
+ /**
1946
+ * Replay through upToActionIndex, keep Chrome open as a live session, then
1947
+ * inspect/click/fill and saveBrowserRecordingSession to write a new recording.
1948
+ */
1949
+ export async function playBrowserRecordingUpTo(
1950
+ testFile: string,
1951
+ upToActionIndex: number,
1952
+ options: BrowserRecordingRunOptions = {}
1953
+ ) {
1954
+ return callBrowserRecordingTool('browser_recording_play_up_to', {
1955
+ testFile,
1956
+ upToActionIndex,
1957
+ ...options,
1958
+ });
1959
+ }
1960
+
1859
1961
  /** List Playwright scheduler entries for browser recorder tests */
1860
1962
  export async function listBrowserRecordingSchedules() {
1861
1963
  return callBrowserRecordingTool('browser_recording_list_schedules', {});
@@ -3757,23 +3859,41 @@ export async function getGoogleSlidesAuthStatus() {
3757
3859
  return callSlidesTool('slides_auth_status', {});
3758
3860
  }
3759
3861
 
3760
- export async function createGoogleSlides(title: string) {
3761
- return callSlidesTool('slides_create', { title });
3862
+ /**
3863
+ * Create a Google Slides presentation.
3864
+ * Pass preferOAuth: true (default) to create in the signed-in user's Drive when a service account is also configured.
3865
+ */
3866
+ export async function createGoogleSlides(
3867
+ title: string,
3868
+ options: WorkspaceVisitorCallOptions = {},
3869
+ ) {
3870
+ const preferOAuth = options.preferOAuth ?? true;
3871
+ return callSlidesTool('slides_create', { title, preferOAuth }, options);
3762
3872
  }
3763
3873
 
3764
- export async function getGoogleSlides(presentationId: string) {
3765
- return callSlidesTool('slides_get', { presentationId });
3874
+ export async function getGoogleSlides(
3875
+ presentationId: string,
3876
+ options: WorkspaceVisitorCallOptions = {},
3877
+ ) {
3878
+ const preferOAuth = options.preferOAuth ?? true;
3879
+ return callSlidesTool('slides_get', { presentationId, preferOAuth }, options);
3766
3880
  }
3767
3881
 
3768
- export async function getGoogleSlidesText(presentationId: string) {
3769
- return callSlidesTool('slides_get_text', { presentationId });
3882
+ export async function getGoogleSlidesText(
3883
+ presentationId: string,
3884
+ options: WorkspaceVisitorCallOptions = {},
3885
+ ) {
3886
+ const preferOAuth = options.preferOAuth ?? true;
3887
+ return callSlidesTool('slides_get_text', { presentationId, preferOAuth }, options);
3770
3888
  }
3771
3889
 
3772
3890
  export async function addGoogleSlide(
3773
3891
  presentationId: string,
3774
- options: { text?: string; insertionIndex?: number } = {},
3892
+ options: { text?: string; insertionIndex?: number; preferOAuth?: boolean } = {},
3893
+ callOptions: WorkspaceVisitorCallOptions = {},
3775
3894
  ) {
3776
- return callSlidesTool('slides_add_slide', { presentationId, ...options });
3895
+ const preferOAuth = options.preferOAuth ?? callOptions.preferOAuth ?? true;
3896
+ return callSlidesTool('slides_add_slide', { presentationId, ...options, preferOAuth }, callOptions);
3777
3897
  }
3778
3898
 
3779
3899
  export async function replaceGoogleSlidesText(
@@ -3781,8 +3901,14 @@ export async function replaceGoogleSlidesText(
3781
3901
  findText: string,
3782
3902
  replaceText: string,
3783
3903
  matchCase?: boolean,
3904
+ options: WorkspaceVisitorCallOptions = {},
3784
3905
  ) {
3785
- return callSlidesTool('slides_replace_text', { presentationId, findText, replaceText, matchCase });
3906
+ const preferOAuth = options.preferOAuth ?? true;
3907
+ return callSlidesTool(
3908
+ 'slides_replace_text',
3909
+ { presentationId, findText, replaceText, matchCase, preferOAuth },
3910
+ options,
3911
+ );
3786
3912
  }
3787
3913
 
3788
3914
  export async function insertGoogleSlidesImage(
@@ -3792,9 +3918,30 @@ export async function insertGoogleSlidesImage(
3792
3918
  imageUrl?: string;
3793
3919
  slideIndex?: number;
3794
3920
  slideObjectId?: string;
3921
+ preferOAuth?: boolean;
3795
3922
  },
3923
+ callOptions: WorkspaceVisitorCallOptions = {},
3924
+ ) {
3925
+ const preferOAuth = options.preferOAuth ?? callOptions.preferOAuth ?? true;
3926
+ return callSlidesTool('slides_insert_image', { ...options, preferOAuth }, callOptions);
3927
+ }
3928
+
3929
+ export async function getGoogleSlidesProposalLayoutCatalog() {
3930
+ return callSlidesTool('slides_proposal_layout_catalog', {});
3931
+ }
3932
+
3933
+ /** Append a slide from structured proposal content to a Google Slides deck. */
3934
+ export async function fillGoogleSlideFromProposalContent(
3935
+ presentationId: string,
3936
+ content: unknown,
3937
+ options: WorkspaceVisitorCallOptions = {},
3796
3938
  ) {
3797
- return callSlidesTool('slides_insert_image', { presentationId, ...options });
3939
+ const preferOAuth = options.preferOAuth ?? true;
3940
+ return callSlidesTool(
3941
+ 'slides_fill_from_content',
3942
+ { presentationId, content, preferOAuth },
3943
+ options,
3944
+ );
3798
3945
  }
3799
3946
 
3800
3947
  // ==========================================
@@ -4241,7 +4388,8 @@ export async function getEgdeskTunnel(role?: 'prod' | 'dev') {
4241
4388
  // ==========================================
4242
4389
 
4243
4390
  /**
4244
- * Call EGDesk Phone MCP tool (Messages Web devices, inbox, SMS queue, consent).
4391
+ * Call EGDesk Phone MCP tool (Messages Web devices, inbox, SMS queue, consent,
4392
+ * snapshot links, inbound/outbound rules, background listener).
4245
4393
  *
4246
4394
  * - Server: \`POST {apiUrl}/phone/tools/call\`
4247
4395
  * - Client: \`POST /__phone_proxy\` (see proxy.ts / middleware)
@@ -4316,15 +4464,28 @@ export async function syncPhoneConversations(deviceId: string) {
4316
4464
 
4317
4465
  export async function listPhoneConversationMessages(options: {
4318
4466
  deviceId: string;
4319
- convKey: string;
4467
+ convKey?: string;
4468
+ phoneNumber?: string;
4320
4469
  }) {
4321
4470
  return callPhoneTool('phone_list_conversation_messages', options);
4322
4471
  }
4323
4472
 
4473
+ export async function getPhoneMessages(options: {
4474
+ deviceId: string;
4475
+ phoneNumber?: string;
4476
+ convKey?: string;
4477
+ title?: string;
4478
+ preview?: string;
4479
+ }) {
4480
+ return callPhoneTool('phone_get_messages', options);
4481
+ }
4482
+
4324
4483
  export async function syncPhoneConversationThread(options: {
4325
4484
  deviceId: string;
4326
- convKey: string;
4327
- title: string;
4485
+ convKey?: string;
4486
+ title?: string;
4487
+ preview?: string;
4488
+ phoneNumber?: string;
4328
4489
  }) {
4329
4490
  return callPhoneTool('phone_sync_conversation_thread', options);
4330
4491
  }
@@ -4349,6 +4510,19 @@ export async function sendPhoneSms(options: {
4349
4510
  return callPhoneTool('phone_send', options);
4350
4511
  }
4351
4512
 
4513
+ /** Alias of sendPhoneSms — enqueues an SMS job for the background worker. */
4514
+ export async function enqueuePhoneSms(options: {
4515
+ deviceId: string;
4516
+ phoneNumber: string;
4517
+ message: string;
4518
+ snapshotId?: string;
4519
+ scheduledAt?: number;
4520
+ isMarketing?: boolean;
4521
+ brandName?: string;
4522
+ }) {
4523
+ return callPhoneTool('phone_enqueue', options);
4524
+ }
4525
+
4352
4526
  export async function listPhoneQueue(options: {
4353
4527
  deviceId?: string;
4354
4528
  snapshotId?: string;
@@ -4369,6 +4543,14 @@ export async function listPhoneDevicesForSnapshot(snapshotId: string) {
4369
4543
  return callPhoneTool('phone_list_for_snapshot', { snapshotId });
4370
4544
  }
4371
4545
 
4546
+ export async function listPhoneSnapshotLinks() {
4547
+ return callPhoneTool('phone_list_snapshot_links', {});
4548
+ }
4549
+
4550
+ export async function listPhoneSnapshotsForDevice(deviceId: string) {
4551
+ return callPhoneTool('phone_list_snapshots_for_device', { deviceId });
4552
+ }
4553
+
4372
4554
  export async function linkPhoneSnapshot(options: {
4373
4555
  snapshotId: string;
4374
4556
  deviceId: string;
@@ -4399,6 +4581,66 @@ export async function syncPhoneConsentEvents(snapshotId: string) {
4399
4581
  return callPhoneTool('phone_consent_events_sync', { snapshotId });
4400
4582
  }
4401
4583
 
4584
+ export async function setPhoneConsentAction(options: {
4585
+ snapshotId: string;
4586
+ phone: string;
4587
+ action: 'opt_in' | 'opt_out';
4588
+ }) {
4589
+ return callPhoneTool('phone_consent_action_set', options);
4590
+ }
4591
+
4592
+ export async function createPhoneMessageRule(options: {
4593
+ deviceId: string;
4594
+ enabled?: boolean;
4595
+ matchPhone?: string;
4596
+ matchBodyContains?: string;
4597
+ matchBodyRegex?: string;
4598
+ matchDirection?: 'incoming' | 'outgoing' | 'any';
4599
+ actionType: 'script' | 'send_sms' | 'webhook';
4600
+ actionPayload: Record<string, any>;
4601
+ cooldownMs?: number;
4602
+ }) {
4603
+ return callPhoneTool('phone_rule_create', options);
4604
+ }
4605
+
4606
+ export async function updatePhoneMessageRule(options: {
4607
+ ruleId: string;
4608
+ enabled?: boolean;
4609
+ matchPhone?: string;
4610
+ matchBodyContains?: string;
4611
+ matchBodyRegex?: string;
4612
+ matchDirection?: 'incoming' | 'outgoing' | 'any';
4613
+ actionType?: 'script' | 'send_sms' | 'webhook';
4614
+ actionPayload?: Record<string, any>;
4615
+ cooldownMs?: number;
4616
+ }) {
4617
+ return callPhoneTool('phone_rule_update', options);
4618
+ }
4619
+
4620
+ export async function deletePhoneMessageRule(ruleId: string) {
4621
+ return callPhoneTool('phone_rule_delete', { ruleId });
4622
+ }
4623
+
4624
+ export async function listPhoneMessageRules(deviceId?: string) {
4625
+ return callPhoneTool('phone_rule_list', deviceId ? { deviceId } : {});
4626
+ }
4627
+
4628
+ export async function getPhoneListenerStatus(deviceId?: string) {
4629
+ return callPhoneTool('phone_listener_status', deviceId ? { deviceId } : {});
4630
+ }
4631
+
4632
+ export async function testPhoneListener(options: {
4633
+ deviceId: string;
4634
+ body: string;
4635
+ phone?: string;
4636
+ direction?: 'incoming' | 'outgoing' | 'unknown';
4637
+ convKey?: string;
4638
+ title?: string;
4639
+ dryRun?: boolean;
4640
+ }) {
4641
+ return callPhoneTool('phone_listener_test', options);
4642
+ }
4643
+
4402
4644
  // ==========================================
4403
4645
  // INSTAGRAM (MCP)
4404
4646
  // ==========================================
@@ -113,15 +113,28 @@ export default function VisitorAuthCallbackPage() {
113
113
  setMessage('Missing login code. Close this page and try Sign in with Google again.');
114
114
  return;
115
115
  }
116
+ let finished = false;
117
+ const timer = window.setTimeout(() => {
118
+ if (finished) return;
119
+ finished = true;
120
+ setMessage('Sign-in timed out. Close this page and try Sign in with Google again.');
121
+ }, 20000);
116
122
  void exchangeVisitorAuthCode(code)
117
123
  .then(() => {
124
+ if (finished) return;
125
+ finished = true;
126
+ window.clearTimeout(timer);
118
127
  const dest = resolveVisitorAppPath(next.startsWith('/') ? next : '/');
119
128
  window.location.replace(dest);
120
129
  })
121
130
  .catch((err: unknown) => {
131
+ if (finished) return;
132
+ finished = true;
133
+ window.clearTimeout(timer);
122
134
  const text = err instanceof Error ? err.message : String(err);
123
135
  setMessage('Sign-in failed: ' + text);
124
136
  });
137
+ return () => window.clearTimeout(timer);
125
138
  }, []);
126
139
 
127
140
  return (
@@ -274,20 +287,98 @@ export function resolveVisitorAppPath(path: string): string {
274
287
  return base + normalized;
275
288
  }
276
289
 
277
- /** MCP root for the public tunnel, e.g. https://tunneling-service.onrender.com/t/{id} */
290
+ function isLoopbackHostname(hostname: string): boolean {
291
+ return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
292
+ }
293
+
294
+ function isPrivateLanHostname(hostname: string): boolean {
295
+ const match = hostname.match(/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/);
296
+ if (!match) return false;
297
+ const a = Number(match[1]);
298
+ const b = Number(match[2]);
299
+ if (a === 10) return true;
300
+ if (a === 172 && b >= 16 && b <= 31) return true;
301
+ if (a === 192 && b === 168) return true;
302
+ return false;
303
+ }
304
+
305
+ function isDevSiteHostname(hostname: string): boolean {
306
+ return isLoopbackHostname(hostname) || isPrivateLanHostname(hostname);
307
+ }
308
+
309
+ function isLocalEgdeskUrl(value: string): boolean {
310
+ try {
311
+ return isLoopbackHostname(new URL(value).hostname);
312
+ } catch {
313
+ return false;
314
+ }
315
+ }
316
+
317
+ function isTunnelMcpRoot(value: string): boolean {
318
+ try {
319
+ const parsed = new URL(value);
320
+ return (
321
+ parsed.hostname === 'tunneling-service.onrender.com' ||
322
+ parsed.hostname.endsWith('.egdesk.cloud') ||
323
+ /\\/t\\/[^/]+/.test(parsed.pathname)
324
+ );
325
+ } catch {
326
+ return false;
327
+ }
328
+ }
329
+
330
+ /**
331
+ * MCP root used as the Google/Supabase OAuth bounce.
332
+ * Published hosts must never silently fall back to http://localhost:8080.
333
+ */
278
334
  export function resolveEgdeskPublicUrl(): string {
279
- const configured =
335
+ const configured = (
280
336
  (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
281
- 'http://localhost:8080';
282
- if (typeof window === 'undefined') return configured;
337
+ ''
338
+ ).replace(/\\/$/, '');
339
+ const tunnelUrl = (
340
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_TUNNEL_URL) ||
341
+ ''
342
+ ).replace(/\\/$/, '');
343
+ const preferred = configured || tunnelUrl;
344
+
345
+ if (typeof window === 'undefined') {
346
+ return preferred || 'http://localhost:8080';
347
+ }
348
+
349
+ const hostname = window.location.hostname;
283
350
  const parts = window.location.pathname.split('/').filter(Boolean);
284
- const onTunnelGateway =
285
- window.location.hostname === 'tunneling-service.onrender.com' ||
286
- window.location.hostname.endsWith('.egdesk.cloud');
287
- if (onTunnelGateway && parts[0] === 't' && parts[1]) {
351
+ const onTunnelPath = parts[0] === 't' && Boolean(parts[1]);
352
+ const onKnownGateway =
353
+ hostname === 'tunneling-service.onrender.com' || hostname.endsWith('.egdesk.cloud');
354
+
355
+ if (onTunnelPath && (onKnownGateway || !isLoopbackHostname(hostname))) {
288
356
  return window.location.origin + '/t/' + parts[1];
289
357
  }
290
- return configured;
358
+
359
+ if (isDevSiteHostname(hostname)) {
360
+ if (isPrivateLanHostname(hostname) && preferred && isTunnelMcpRoot(preferred)) {
361
+ return preferred;
362
+ }
363
+ if (isLoopbackHostname(hostname)) {
364
+ return preferred || 'http://localhost:8080';
365
+ }
366
+ if (preferred && !isLocalEgdeskUrl(preferred)) {
367
+ return preferred;
368
+ }
369
+ throw new Error(
370
+ 'Visitor Google login from a LAN IP requires NEXT_PUBLIC_EGDESK_API_URL to be the tunnel MCP root (https://…/t/{id}).',
371
+ );
372
+ }
373
+
374
+ if (preferred && !isLocalEgdeskUrl(preferred)) {
375
+ return preferred;
376
+ }
377
+
378
+ console.error(
379
+ '[egdesk-visitor-google] NEXT_PUBLIC_EGDESK_API_URL is missing or points at localhost on a published host. Using window.location.origin for the OAuth bounce.',
380
+ );
381
+ return window.location.origin;
291
382
  }
292
383
 
293
384
  async function callVisitorAuth(tool: string, args: Record<string, unknown> = {}) {
@@ -336,8 +427,14 @@ export async function startVisitorGoogleLogin(options: {
336
427
  );
337
428
  const returnTo = new URL(resolveVisitorAppPath('/auth/callback'), window.location.origin);
338
429
  returnTo.searchParams.set('next', next);
339
- // Localhost → EGDesk :54321. Tunnel site → {gateway}/t/{id}/visitor-auth/callback.
430
+ // Localhost → allowlisted http://localhost:54321/auth/callback.
431
+ // Tunnel / custom domain → {MCP root}/visitor-auth/callback/{pendingId}.
340
432
  const egdeskPublicUrl = resolveEgdeskPublicUrl();
433
+ if (isLocalEgdeskUrl(egdeskPublicUrl) && !isDevSiteHostname(window.location.hostname)) {
434
+ throw new Error(
435
+ 'Visitor Google login cannot use a localhost EGDesk URL from a published site. Set NEXT_PUBLIC_EGDESK_API_URL to the tunnel MCP root (https://…/t/{id}).',
436
+ );
437
+ }
341
438
  const scopes = resolveVisitorLoginScopes(options.scopes);
342
439
 
343
440
  const result = await callVisitorAuth('start', {
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.75";
11
+ export declare const COMPATIBLE_APP_VERSION = "1.4.89";
12
12
  export interface SetupOptions {
13
13
  egdeskUrl?: string;
14
14
  /** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ exports.setupNextApiPlugin = setupNextApiPlugin;
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.75';
49
+ exports.COMPATIBLE_APP_VERSION = '1.4.89';
50
50
  const fs = __importStar(require("fs"));
51
51
  const path = __importStar(require("path"));
52
52
  const setup_userdata_1 = require("./setup-userdata");
@@ -205,7 +205,7 @@ async function setupNextApiPlugin(projectPath, options = {}) {
205
205
  console.log('');
206
206
  console.log('📝 Next steps:');
207
207
  console.log(' 1. Add .env.*.local to your .gitignore');
208
- console.log(' 2. Add this EGDesk public URL + /visitor-auth/callback to Supabase Auth redirect URLs');
208
+ console.log(' 2. Add this EGDesk public URL + /visitor-auth/callback/** to Supabase Auth redirect URLs');
209
209
  console.log(' (once per EGDesk/tunnel origin — not each published site)');
210
210
  console.log(' Visitor sessions are bound to each site origin and cannot be reused across sites');
211
211
  console.log(' 3. Restart your Next.js dev server');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egdesk/next-api-plugin",
3
- "version": "1.5.70",
3
+ "version": "1.5.84",
4
4
  "description": "Next.js plugin for EGDesk database proxy integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",