@egdesk/next-api-plugin 1.5.44 → 1.5.49

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.
@@ -95,7 +95,7 @@ const CALLBACK_PAGE = `'use client';
95
95
  */
96
96
 
97
97
  import { useEffect, useState } from 'react';
98
- import { exchangeVisitorAuthCode } from '@/egdesk-visitor-google';
98
+ import { exchangeVisitorAuthCode, resolveVisitorAppPath } from '@/egdesk-visitor-google';
99
99
 
100
100
  export default function VisitorAuthCallbackPage() {
101
101
  const [message, setMessage] = useState('Finishing sign-in…');
@@ -110,7 +110,7 @@ export default function VisitorAuthCallbackPage() {
110
110
  }
111
111
  void exchangeVisitorAuthCode(code)
112
112
  .then(() => {
113
- const dest = next.startsWith('/') ? next : '/';
113
+ const dest = resolveVisitorAppPath(next.startsWith('/') ? next : '/');
114
114
  window.location.replace(dest);
115
115
  })
116
116
  .catch((err: unknown) => {
@@ -181,6 +181,27 @@ function visitorOriginHeaders(): Record<string, string> {
181
181
  return { 'X-Visitor-Origin': window.location.origin };
182
182
  }
183
183
 
184
+ /** Tunnel production apps live under /t/{id}/p/{project}. Bare /auth/callback 404s. */
185
+ export function getVisitorSiteBasePath(): string {
186
+ const fromEnv =
187
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_BASE_PATH) || '';
188
+ if (fromEnv) return fromEnv.replace(/\\/$/, '');
189
+ if (typeof window === 'undefined') return '';
190
+ const parts = window.location.pathname.split('/').filter(Boolean);
191
+ if (parts[0] === 't' && parts.length >= 4 && parts[2] === 'p') {
192
+ return '/' + parts.slice(0, 4).join('/');
193
+ }
194
+ return '';
195
+ }
196
+
197
+ export function resolveVisitorAppPath(path: string): string {
198
+ const base = getVisitorSiteBasePath();
199
+ const normalized = path.startsWith('/') ? path : '/' + path;
200
+ if (!base) return normalized;
201
+ if (normalized === base || normalized.startsWith(base + '/')) return normalized;
202
+ return base + normalized;
203
+ }
204
+
184
205
  async function callVisitorAuth(tool: string, args: Record<string, unknown> = {}) {
185
206
  const response = await apiFetch('/__visitor_auth_proxy', {
186
207
  method: 'POST',
@@ -218,10 +239,13 @@ export async function startVisitorGoogleLogin(options: {
218
239
  if (typeof window === 'undefined') {
219
240
  throw new Error('startVisitorGoogleLogin() must run in the browser');
220
241
  }
221
- const next =
222
- options.next && options.next.startsWith('/') ? options.next : window.location.pathname;
223
- const returnTo = new URL('/auth/callback', window.location.origin);
242
+ const next = resolveVisitorAppPath(
243
+ options.next && options.next.startsWith('/') ? options.next : window.location.pathname,
244
+ );
245
+ const returnTo = new URL(resolveVisitorAppPath('/auth/callback'), window.location.origin);
224
246
  returnTo.searchParams.set('next', next);
247
+ // EGDesk picks the OAuth bounce: localhost hosted coding uses
248
+ // http://localhost:54321/auth/callback so Supabase does not fall back to egdesk.cloud.
225
249
  const egdeskPublicUrl =
226
250
  process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
227
251
 
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.53";
11
+ export declare const COMPATIBLE_APP_VERSION = "1.4.58";
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.53';
49
+ exports.COMPATIBLE_APP_VERSION = '1.4.58';
50
50
  const fs = __importStar(require("fs"));
51
51
  const path = __importStar(require("path"));
52
52
  const setup_userdata_1 = require("./setup-userdata");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egdesk/next-api-plugin",
3
- "version": "1.5.44",
3
+ "version": "1.5.49",
4
4
  "description": "Next.js plugin for EGDesk database proxy integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",