zitejs 0.10.0-start.16 → 0.10.0-start.17

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.
@@ -9,6 +9,7 @@ const react_1 = require("react");
9
9
  const react_2 = require("better-auth/react");
10
10
  const plugins_1 = require("better-auth/client/plugins");
11
11
  const constants_js_1 = require("./constants.js");
12
+ const previewClaim_js_1 = require("./previewClaim.js");
12
13
  const config_js_1 = require("./config.js");
13
14
  const authClient = (0, react_2.createAuthClient)({
14
15
  baseURL: '',
@@ -97,6 +98,11 @@ function loginWithRedirect(opts) {
97
98
  window._ziteUsageToken;
98
99
  if (usageToken)
99
100
  params.set(constants_js_1.USAGE_TOKEN_QUERY_PARAM, usageToken);
101
+ // A Start app's preview also needs its claim where the editor's frame dropped
102
+ // the cookie, as `loginHref()` sends it. Classic previews never have one.
103
+ const claim = (0, previewClaim_js_1.browserPreviewClaim)();
104
+ if (claim)
105
+ params.set(previewClaim_js_1.PREVIEW_CLAIM_PARAM, claim);
100
106
  const query = params.toString();
101
107
  window.location.href = query ? `/auth/login?${query}` : '/auth/login';
102
108
  }
@@ -0,0 +1,7 @@
1
+ export declare const PREVIEW_CLAIM_PARAM = "zite_preview";
2
+ /**
3
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
4
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
5
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
6
+ */
7
+ export declare const browserPreviewClaim: () => string | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.browserPreviewClaim = exports.PREVIEW_CLAIM_PARAM = void 0;
4
+ // The host's name for it (apps/zite-host/src/previewClaim.ts).
5
+ exports.PREVIEW_CLAIM_PARAM = 'zite_preview';
6
+ let captured;
7
+ /**
8
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
9
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
10
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
11
+ */
12
+ const browserPreviewClaim = () => {
13
+ captured ??= new URL(window.location.href).searchParams.get(exports.PREVIEW_CLAIM_PARAM);
14
+ return captured ?? undefined;
15
+ };
16
+ exports.browserPreviewClaim = browserPreviewClaim;
@@ -2,6 +2,7 @@ import { useEffect } from 'react';
2
2
  import { createAuthClient } from 'better-auth/react';
3
3
  import { magicLinkClient, inferAdditionalFields, } from 'better-auth/client/plugins';
4
4
  import { USAGE_TOKEN_QUERY_PARAM } from './constants.js';
5
+ import { browserPreviewClaim, PREVIEW_CLAIM_PARAM } from './previewClaim.js';
5
6
  import { getAccessMode } from './config.js';
6
7
  const authClient = createAuthClient({
7
8
  baseURL: '',
@@ -90,6 +91,11 @@ export function loginWithRedirect(opts) {
90
91
  window._ziteUsageToken;
91
92
  if (usageToken)
92
93
  params.set(USAGE_TOKEN_QUERY_PARAM, usageToken);
94
+ // A Start app's preview also needs its claim where the editor's frame dropped
95
+ // the cookie, as `loginHref()` sends it. Classic previews never have one.
96
+ const claim = browserPreviewClaim();
97
+ if (claim)
98
+ params.set(PREVIEW_CLAIM_PARAM, claim);
93
99
  const query = params.toString();
94
100
  window.location.href = query ? `/auth/login?${query}` : '/auth/login';
95
101
  }
@@ -0,0 +1,7 @@
1
+ export declare const PREVIEW_CLAIM_PARAM = "zite_preview";
2
+ /**
3
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
4
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
5
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
6
+ */
7
+ export declare const browserPreviewClaim: () => string | undefined;
@@ -0,0 +1,12 @@
1
+ // The host's name for it (apps/zite-host/src/previewClaim.ts).
2
+ export const PREVIEW_CLAIM_PARAM = 'zite_preview';
3
+ let captured;
4
+ /**
5
+ * An editor preview's access in the browser, which the host keeps on the URL because the editor's frame may drop its
6
+ * cookie (WebKit drops even Partitioned ones). Read once, before a Start app's router hides it, and shared by
7
+ * `zitejs/start` and `zitejs/auth` so sign-in keeps it either way. A classic app's URL never carries one.
8
+ */
9
+ export const browserPreviewClaim = () => {
10
+ captured ??= new URL(window.location.href).searchParams.get(PREVIEW_CLAIM_PARAM);
11
+ return captured ?? undefined;
12
+ };
@@ -1,10 +1,7 @@
1
- export declare const PREVIEW_CLAIM_PARAM = "zite_preview";
1
+ import { PREVIEW_CLAIM_PARAM } from "../auth/previewClaim.js";
2
+ export { PREVIEW_CLAIM_PARAM };
2
3
  export declare const PREVIEW_CLAIM_HEADER = "x-zite-preview";
3
- /**
4
- * An editor preview's access, which the host keeps on the URL because the editor's frame may drop its cookie (WebKit
5
- * drops even Partitioned ones). On the server the host hands it over; in the browser it's on the URL the host sent
6
- * the page to, read once, before the router hides it.
7
- */
4
+ /** An editor preview's access: on the server the host hands it over, in the browser it's on the URL. */
8
5
  export declare const previewClaim: () => string | undefined;
9
6
  /** Every same-origin fetch from the page carries the claim: server functions and the app's own routes alike. */
10
7
  export declare const carryPreviewClaim: (claim: string) => void;
@@ -1,19 +1,10 @@
1
+ import { browserPreviewClaim, PREVIEW_CLAIM_PARAM } from "../auth/previewClaim.js";
1
2
  import { currentHost } from "./host.js";
2
- // The host's names (apps/zite-host/src/previewClaim.ts).
3
- export const PREVIEW_CLAIM_PARAM = "zite_preview";
3
+ export { PREVIEW_CLAIM_PARAM };
4
+ // The host's name (apps/zite-host/src/previewClaim.ts).
4
5
  export const PREVIEW_CLAIM_HEADER = "x-zite-preview";
5
- let captured;
6
- /**
7
- * An editor preview's access, which the host keeps on the URL because the editor's frame may drop its cookie (WebKit
8
- * drops even Partitioned ones). On the server the host hands it over; in the browser it's on the URL the host sent
9
- * the page to, read once, before the router hides it.
10
- */
11
- export const previewClaim = () => {
12
- if (typeof window === "undefined")
13
- return currentHost()?.previewClaim;
14
- captured ??= new URL(window.location.href).searchParams.get(PREVIEW_CLAIM_PARAM);
15
- return captured ?? undefined;
16
- };
6
+ /** An editor preview's access: on the server the host hands it over, in the browser it's on the URL. */
7
+ export const previewClaim = () => typeof window === "undefined" ? currentHost()?.previewClaim : browserPreviewClaim();
17
8
  let carrying = false;
18
9
  /** Every same-origin fetch from the page carries the claim: server functions and the app's own routes alike. */
19
10
  export const carryPreviewClaim = (claim) => {
@@ -1 +1 @@
1
- export declare const ZITEJS_VERSION = "0.10.0-start.16";
1
+ export declare const ZITEJS_VERSION = "0.10.0-start.17";
@@ -1,2 +1,2 @@
1
1
  // Written by scripts/write-version.mjs from package.json.
2
- export const ZITEJS_VERSION = "0.10.0-start.16";
2
+ export const ZITEJS_VERSION = "0.10.0-start.17";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.10.0-start.16",
3
+ "version": "0.10.0-start.17",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "sideEffects": false,