fontdue-js 3.0.0-alpha10 → 3.0.0-alpha12

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +165 -13
  3. package/dist/__generated__/FontdueAdminToolbarQuery.graphql.d.ts +20 -0
  4. package/dist/__generated__/FontdueAdminToolbarQuery.graphql.js +80 -0
  5. package/dist/__tests__/createFontdueFetch.test.js +222 -0
  6. package/dist/__tests__/imageLoader.test.js +62 -0
  7. package/dist/__tests__/networkFetch.test.js +22 -0
  8. package/dist/__tests__/nextAdapter.test.js +64 -0
  9. package/dist/__tests__/preview.test.js +96 -0
  10. package/dist/__tests__/previewServer.test.js +118 -0
  11. package/dist/components/BuyButton/index.d.ts +2 -2
  12. package/dist/components/BuyButton/index.js +3 -3
  13. package/dist/components/CharacterViewer/index.d.ts +2 -2
  14. package/dist/components/CharacterViewer/index.js +3 -3
  15. package/dist/components/ConfigContext.d.ts +10 -0
  16. package/dist/components/ConfigContext.js +5 -1
  17. package/dist/components/FontdueAdminToolbar/index.js +26 -25
  18. package/dist/components/FontdueProvider/index.js +2 -2
  19. package/dist/components/NewsletterSignup/index.d.ts +2 -2
  20. package/dist/components/NewsletterSignup/index.js +2 -2
  21. package/dist/components/TestFontsForm/index.d.ts +2 -2
  22. package/dist/components/TestFontsForm/index.js +2 -2
  23. package/dist/components/TypeTester/TypeTesterStandalone.d.ts +2 -2
  24. package/dist/components/TypeTester/TypeTesterStandalone.js +2 -2
  25. package/dist/components/TypeTesters/index.d.ts +2 -2
  26. package/dist/components/TypeTesters/index.js +3 -3
  27. package/dist/loadFontdueProviderQuery.d.ts +2 -1
  28. package/dist/loadFontdueProviderQuery.js +5 -2
  29. package/dist/next/image-loader.js +22 -3
  30. package/dist/next/tenant.js +39 -3
  31. package/dist/preview/constants.d.ts +3 -0
  32. package/dist/preview/constants.js +18 -0
  33. package/dist/preview/index.d.ts +49 -0
  34. package/dist/preview/index.js +164 -0
  35. package/dist/preview/server.d.ts +20 -0
  36. package/dist/preview/server.js +89 -0
  37. package/dist/relay/environment.d.ts +6 -0
  38. package/dist/relay/environment.js +4 -1
  39. package/dist/relay/loadSerializableQuery.d.ts +13 -3
  40. package/dist/relay/loadSerializableQuery.js +2 -0
  41. package/dist/relay/serverConfig.d.ts +3 -0
  42. package/dist/relay/serverConfig.js +26 -1
  43. package/dist/server/index.d.ts +37 -0
  44. package/dist/server/index.js +135 -0
  45. package/package.json +4 -1
  46. package/types/next-headers.d.ts +9 -0
@@ -26,11 +26,30 @@ vi.mock('next/navigation', () => ({
26
26
  throw new Error('NEXT_NOT_FOUND');
27
27
  }
28
28
  }));
29
+
30
+ // Draft mode + the preview token cookie, controllable per test. Default: not
31
+ // previewing, so prepareFontdueRender takes the public (cached) path.
32
+ const draft = vi.hoisted(() => ({
33
+ enabled: false,
34
+ token: undefined
35
+ }));
36
+ vi.mock('next/headers', () => ({
37
+ draftMode: async () => ({
38
+ isEnabled: draft.enabled
39
+ }),
40
+ cookies: async () => ({
41
+ get: name => name === 'fontdue_preview_token' && draft.token ? {
42
+ value: draft.token
43
+ } : undefined
44
+ })
45
+ }));
29
46
  beforeEach(() => {
30
47
  vi.resetModules();
31
48
  revalidateTag.mockClear();
32
49
  vi.unstubAllEnvs();
33
50
  vi.restoreAllMocks();
51
+ draft.enabled = false;
52
+ draft.token = undefined;
34
53
  });
35
54
  function stubSingleTenant() {
36
55
  let url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'https://acme.fontdue.com';
@@ -196,6 +215,51 @@ describe('prepareFontdueRender', () => {
196
215
  slug: 'sans'
197
216
  }))).rejects.toThrow('NEXT_NOT_FOUND');
198
217
  });
218
+
219
+ // React.cache doesn't memoize outside an RSC render (see configureFontdueRender
220
+ // above), so the slot write is a no-op here — capture what prepareFontdueRender
221
+ // passes to setFontdueServerConfig instead.
222
+ async function captureRenderConfig(params) {
223
+ let captured;
224
+ vi.doMock('../relay/serverConfig', async importActual => ({
225
+ ...(await importActual()),
226
+ setFontdueServerConfig: c => {
227
+ captured = c;
228
+ }
229
+ }));
230
+ const {
231
+ prepareFontdueRender
232
+ } = await importTenant();
233
+ await prepareFontdueRender(props(params));
234
+ vi.doUnmock('../relay/serverConfig');
235
+ return captured;
236
+ }
237
+ it('public render: sets the tenant config with cache tags and no token', async () => {
238
+ var _config$headers;
239
+ stubMultiTenant({
240
+ origin: 'http://app:4000'
241
+ });
242
+ const config = await captureRenderConfig({
243
+ domain: 'acme.fontdue.com'
244
+ });
245
+ expect(config.cacheTags).toEqual(['graphql:acme.fontdue.com']);
246
+ expect((_config$headers = config.headers) === null || _config$headers === void 0 ? void 0 : _config$headers.authorization).toBeUndefined();
247
+ });
248
+ it('preview render: folds the token into headers and drops cache tags', async () => {
249
+ var _config$headers2;
250
+ stubMultiTenant({
251
+ origin: 'http://app:4000'
252
+ });
253
+ draft.enabled = true;
254
+ draft.token = 'admin-tok';
255
+ const config = await captureRenderConfig({
256
+ domain: 'acme.fontdue.com'
257
+ });
258
+ // Embeds (createNetworkFetch) and the app's fetch (createFontdueFetch) both
259
+ // read this, so both reveal hidden fonts; no tags keeps the render live.
260
+ expect((_config$headers2 = config.headers) === null || _config$headers2 === void 0 ? void 0 : _config$headers2.authorization).toBe('Bearer admin-tok');
261
+ expect(config.cacheTags).toBeUndefined();
262
+ });
199
263
  });
200
264
  describe('currentFontdueEndpoint', () => {
201
265
  it('multi-tenant: throws when no render config was set', async () => {
@@ -0,0 +1,96 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { handlePreviewRequest, readPreviewToken, previewAuthHeaders, PREVIEW_TOKEN_COOKIE, PREVIEW_MARKER_COOKIE } from '../preview/index.js';
3
+ function postPreview(token) {
4
+ let url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'https://site.test/api/preview';
5
+ return handlePreviewRequest(new Request(url, {
6
+ method: 'POST',
7
+ headers: {
8
+ 'content-type': 'application/json'
9
+ },
10
+ body: JSON.stringify({
11
+ token
12
+ })
13
+ }));
14
+ }
15
+ describe('handlePreviewRequest', () => {
16
+ it('enters preview: sets an httpOnly token cookie + a readable marker', async () => {
17
+ const res = await postPreview('admin.tok.123');
18
+ expect(res.status).toBe(200);
19
+ expect(await res.json()).toEqual({
20
+ ok: true,
21
+ preview: true
22
+ });
23
+ const cookies = res.headers.getSetCookie();
24
+ const tokenCookie = cookies.find(c => c.startsWith(`${PREVIEW_TOKEN_COOKIE}=`));
25
+ const markerCookie = cookies.find(c => c.startsWith(`${PREVIEW_MARKER_COOKIE}=`));
26
+ expect(tokenCookie).toContain(`${PREVIEW_TOKEN_COOKIE}=admin.tok.123`);
27
+ expect(tokenCookie).toContain('HttpOnly');
28
+ expect(tokenCookie).toContain('SameSite=Lax');
29
+ expect(tokenCookie).toContain('Path=/');
30
+ expect(markerCookie).toContain(`${PREVIEW_MARKER_COOKIE}=1`);
31
+ // The marker must be readable by the client toolbar.
32
+ expect(markerCookie).not.toContain('HttpOnly');
33
+ });
34
+ it('marks cookies Secure on https and not on http (local dev)', async () => {
35
+ const httpsCookies = (await postPreview('t')).headers.getSetCookie();
36
+ expect(httpsCookies.every(c => c.includes('Secure'))).toBe(true);
37
+ const httpCookies = (await postPreview('t', 'http://localhost:4321/api/preview')).headers.getSetCookie();
38
+ expect(httpCookies.some(c => c.includes('Secure'))).toBe(false);
39
+ });
40
+ it('rejects a POST with no token', async () => {
41
+ const res = await postPreview('');
42
+ expect(res.status).toBe(400);
43
+ expect(res.headers.getSetCookie()).toHaveLength(0);
44
+ });
45
+ it('exits preview: clears both cookies', async () => {
46
+ const res = await handlePreviewRequest(new Request('https://site.test/api/preview', {
47
+ method: 'DELETE'
48
+ }));
49
+ expect(res.status).toBe(200);
50
+ expect(await res.json()).toEqual({
51
+ ok: true,
52
+ preview: false
53
+ });
54
+ const cookies = res.headers.getSetCookie();
55
+ expect(cookies).toHaveLength(2);
56
+ // Expiry via Max-Age=0 clears the cookie.
57
+ expect(cookies.every(c => c.includes('Max-Age=0'))).toBe(true);
58
+ });
59
+ it('rejects unsupported methods', async () => {
60
+ const res = await handlePreviewRequest(new Request('https://site.test/api/preview', {
61
+ method: 'GET'
62
+ }));
63
+ expect(res.status).toBe(405);
64
+ });
65
+ it('round-trips a token with cookie-unsafe characters', async () => {
66
+ const token = 'tok+en/with=specials';
67
+ const res = await postPreview(token);
68
+ const setCookie = res.headers.getSetCookie().find(c => c.startsWith(`${PREVIEW_TOKEN_COOKIE}=`));
69
+ // Reconstruct the Cookie header the browser would send back (name=value).
70
+ const cookieHeader = setCookie.split(';')[0];
71
+ expect(readPreviewToken(cookieHeader)).toBe(token);
72
+ });
73
+ });
74
+ describe('readPreviewToken', () => {
75
+ it('extracts the token from a multi-cookie header', () => {
76
+ expect(readPreviewToken(`a=1; ${PREVIEW_TOKEN_COOKIE}=abc; ${PREVIEW_MARKER_COOKIE}=1`)).toBe('abc');
77
+ });
78
+ it('returns undefined when there is no token cookie', () => {
79
+ expect(readPreviewToken('a=1; b=2')).toBeUndefined();
80
+ expect(readPreviewToken('')).toBeUndefined();
81
+ expect(readPreviewToken(null)).toBeUndefined();
82
+ expect(readPreviewToken(undefined)).toBeUndefined();
83
+ });
84
+ });
85
+ describe('previewAuthHeaders', () => {
86
+ it('builds a Bearer header when a token is present', () => {
87
+ expect(previewAuthHeaders('abc')).toEqual({
88
+ authorization: 'Bearer abc'
89
+ });
90
+ });
91
+ it('returns an empty object when there is no token (safe to spread)', () => {
92
+ expect(previewAuthHeaders(undefined)).toEqual({});
93
+ expect(previewAuthHeaders(null)).toEqual({});
94
+ expect(previewAuthHeaders('')).toEqual({});
95
+ });
96
+ });
@@ -0,0 +1,118 @@
1
+ import { describe, it, expect, beforeEach, vi } from 'vitest';
2
+ import { runWithPreview, isPreviewing, ambientPreviewHeaders } from '../preview/server.js';
3
+ import { createFontdueFetch } from '../server/index.js';
4
+ import { PREVIEW_TOKEN_COOKIE } from '../preview/constants.js';
5
+ beforeEach(() => {
6
+ vi.unstubAllGlobals();
7
+ });
8
+ function req(token) {
9
+ return new Request('https://store.test/', {
10
+ headers: token ? {
11
+ cookie: `${PREVIEW_TOKEN_COOKIE}=${token}`
12
+ } : {}
13
+ });
14
+ }
15
+ describe('runWithPreview', () => {
16
+ it('passes public (no-token) requests through untouched and cacheable', async () => {
17
+ const response = await runWithPreview(req(), async () => {
18
+ expect(isPreviewing()).toBe(false);
19
+ return new Response('ok', {
20
+ headers: {
21
+ 'Netlify-CDN-Cache-Control': 'public, durable, s-maxage=300'
22
+ }
23
+ });
24
+ });
25
+ expect(response.headers.get('Cache-Control')).toBeNull();
26
+ expect(response.headers.get('Netlify-CDN-Cache-Control')).toBe('public, durable, s-maxage=300');
27
+ });
28
+ it('exposes the token in ambient context while previewing', async () => {
29
+ await runWithPreview(req('tok123'), async () => {
30
+ expect(isPreviewing()).toBe(true);
31
+ expect(ambientPreviewHeaders()).toEqual({
32
+ authorization: 'Bearer tok123'
33
+ });
34
+ return new Response('ok');
35
+ });
36
+
37
+ // Context unwinds after the request.
38
+ expect(isPreviewing()).toBe(false);
39
+ expect(ambientPreviewHeaders()).toEqual({});
40
+ });
41
+ it('forces preview responses out of any shared/CDN cache', async () => {
42
+ const response = await runWithPreview(req('tok123'), async () => new Response('secret', {
43
+ headers: {
44
+ 'Netlify-CDN-Cache-Control': 'public, durable, s-maxage=31536000',
45
+ 'CDN-Cache-Control': 'public, s-maxage=300',
46
+ 'Cache-Control': 'public, max-age=0, must-revalidate'
47
+ }
48
+ }));
49
+ expect(response.headers.get('Cache-Control')).toBe('private, no-store');
50
+ expect(response.headers.get('Netlify-CDN-Cache-Control')).toBeNull();
51
+ expect(response.headers.get('CDN-Cache-Control')).toBeNull();
52
+ });
53
+ it('isolates concurrent preview contexts (no cross-request leak)', async () => {
54
+ const seen = {};
55
+ await Promise.all([runWithPreview(req('tokA'), async () => {
56
+ await new Promise(r => setTimeout(r, 15));
57
+ seen.a = ambientPreviewHeaders().authorization;
58
+ return new Response('a');
59
+ }), runWithPreview(req('tokB'), async () => {
60
+ seen.b = ambientPreviewHeaders().authorization;
61
+ return new Response('b');
62
+ }), runWithPreview(req(), async () => {
63
+ seen.public = ambientPreviewHeaders().authorization;
64
+ return new Response('public');
65
+ })]);
66
+ expect(seen.a).toBe('Bearer tokA');
67
+ expect(seen.b).toBe('Bearer tokB');
68
+ expect(seen.public).toBeUndefined();
69
+ });
70
+ });
71
+ describe('createFontdueFetch + ambient preview', () => {
72
+ function mockFetch() {
73
+ const fetchMock = vi.fn(async () => ({
74
+ status: 200,
75
+ json: async () => ({
76
+ data: {}
77
+ })
78
+ }));
79
+ vi.stubGlobal('fetch', fetchMock);
80
+ return fetchMock;
81
+ }
82
+ it('a module-level fetcher forwards the ambient token, no per-call plumbing', async () => {
83
+ const fetchMock = mockFetch();
84
+ const fetchGraphql = createFontdueFetch({
85
+ url: 'https://acme.fontdue.com'
86
+ });
87
+ await runWithPreview(req('admin-tok'), async () => {
88
+ await fetchGraphql('Q', 'query Q { __typename }');
89
+ return new Response('ok');
90
+ });
91
+ const init = fetchMock.mock.calls[0][1];
92
+ expect(init.headers.authorization).toBe('Bearer admin-tok');
93
+ });
94
+ it('does not forward a token for public requests', async () => {
95
+ const fetchMock = mockFetch();
96
+ const fetchGraphql = createFontdueFetch({
97
+ url: 'https://acme.fontdue.com'
98
+ });
99
+ await fetchGraphql('Q', 'query Q { __typename }');
100
+ const init = fetchMock.mock.calls[0][1];
101
+ expect(init.headers.authorization).toBeUndefined();
102
+ });
103
+ it('explicit per-fetcher headers override the ambient context', async () => {
104
+ const fetchMock = mockFetch();
105
+ const fetchGraphql = createFontdueFetch({
106
+ url: 'https://acme.fontdue.com',
107
+ headers: {
108
+ authorization: 'Bearer explicit'
109
+ }
110
+ });
111
+ await runWithPreview(req('ambient-tok'), async () => {
112
+ await fetchGraphql('Q', 'query Q { __typename }');
113
+ return new Response('ok');
114
+ });
115
+ const init = fetchMock.mock.calls[0][1];
116
+ expect(init.headers.authorization).toBe('Bearer explicit');
117
+ });
118
+ });
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { BuyButtonIDQuery } from '../../__generated__/BuyButtonIDQuery.graphql.js';
3
3
  import { BuyButtonSlugQuery } from '../../__generated__/BuyButtonSlugQuery.graphql.js';
4
- import { SerializablePreloadedQuery } from '../../relay/loadSerializableQuery.js';
4
+ import { SerializablePreloadedQuery, type LoadQueryOptions } from '../../relay/loadSerializableQuery.js';
5
5
  import { Config } from '../ConfigContext.js';
6
6
  export interface BuyButton_props {
7
7
  collectionName?: string;
@@ -15,7 +15,7 @@ export type LoadBuyButtonQueryVariables = {
15
15
  collectionId?: never;
16
16
  collectionSlug: string;
17
17
  };
18
- export declare function loadBuyButtonQuery(variables: LoadBuyButtonQueryVariables): Promise<BuyButtonPreloadedQuery>;
18
+ export declare function loadBuyButtonQuery(variables: LoadBuyButtonQueryVariables, options?: LoadQueryOptions): Promise<BuyButtonPreloadedQuery>;
19
19
  export declare function BuyButtonPreloadedIDQueryRenderer({ preloadedQuery, ...rest }: BuyButton_props & {
20
20
  preloadedQuery: SerializablePreloadedQuery<BuyButtonIDQuery>;
21
21
  }): React.JSX.Element;
@@ -57,16 +57,16 @@ function BuyButtonComponent(_ref) {
57
57
  }
58
58
  const idQuery = (_BuyButtonIDQuery.hash && _BuyButtonIDQuery.hash !== "4fbf1dbf9e6c530a5d38c697b174d8b0" && console.error("The definition of 'BuyButtonIDQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _BuyButtonIDQuery);
59
59
  const slugQuery = (_BuyButtonSlugQuery.hash && _BuyButtonSlugQuery.hash !== "6e750adea09698f7cb61f435cd88fd26" && console.error("The definition of 'BuyButtonSlugQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _BuyButtonSlugQuery);
60
- export async function loadBuyButtonQuery(variables) {
60
+ export async function loadBuyButtonQuery(variables, options) {
61
61
  if (variables.collectionId) {
62
62
  return loadSerializableQuery(BuyButtonIDQueryNode, {
63
63
  collectionId: variables.collectionId
64
- });
64
+ }, options);
65
65
  }
66
66
  if (variables.collectionSlug) {
67
67
  return loadSerializableQuery(BuyButtonSlugQueryNode, {
68
68
  collectionSlug: variables.collectionSlug
69
- });
69
+ }, options);
70
70
  }
71
71
  throw new Error('loadBuyButtonQuery expected either a collectionId or collectionSlug');
72
72
  }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { SerializablePreloadedQuery } from '../../relay/loadSerializableQuery.js';
2
+ import { SerializablePreloadedQuery, type LoadQueryOptions } from '../../relay/loadSerializableQuery.js';
3
3
  import { CharacterViewerIDQuery } from '../../__generated__/CharacterViewerIDQuery.graphql.js';
4
4
  import { CharacterViewerSlugQuery } from '../../__generated__/CharacterViewerSlugQuery.graphql.js';
5
5
  import { Config } from '../ConfigContext.js';
@@ -13,7 +13,7 @@ export type LoadCharacterViewerQueryVariables = {
13
13
  collectionId?: never;
14
14
  collectionSlug: string;
15
15
  };
16
- export declare function loadCharacterViewerQuery(variables: LoadCharacterViewerQueryVariables): Promise<CharacterViewerPreloadedQuery>;
16
+ export declare function loadCharacterViewerQuery(variables: LoadCharacterViewerQueryVariables, options?: LoadQueryOptions): Promise<CharacterViewerPreloadedQuery>;
17
17
  export declare function CharacterViewerPreloadedIDQueryRenderer({ preloadedQuery, ...rest }: CharacterViewer_props & {
18
18
  preloadedQuery: SerializablePreloadedQuery<CharacterViewerIDQuery>;
19
19
  }): React.JSX.Element | null;
@@ -416,16 +416,16 @@ function CharacterViewerComponent(_ref3) {
416
416
  }
417
417
  const idQuery = (_CharacterViewerIDQuery.hash && _CharacterViewerIDQuery.hash !== "f90b09a4df6d95307b0a5d5fda487cdc" && console.error("The definition of 'CharacterViewerIDQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _CharacterViewerIDQuery);
418
418
  const slugQuery = (_CharacterViewerSlugQuery.hash && _CharacterViewerSlugQuery.hash !== "afa08a8f050e0434308892fea6e3c267" && console.error("The definition of 'CharacterViewerSlugQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _CharacterViewerSlugQuery);
419
- export async function loadCharacterViewerQuery(variables) {
419
+ export async function loadCharacterViewerQuery(variables, options) {
420
420
  if (variables.collectionId) {
421
421
  return loadSerializableQuery(CharacterViewerIDQueryNode, {
422
422
  collectionId: variables.collectionId
423
- });
423
+ }, options);
424
424
  }
425
425
  if (variables.collectionSlug) {
426
426
  return loadSerializableQuery(CharacterViewerSlugQueryNode, {
427
427
  collectionSlug: variables.collectionSlug
428
- });
428
+ }, options);
429
429
  }
430
430
  throw new Error('loadCharacterViewerQuery expected either collectionId or collectionSlug');
431
431
  }
@@ -23,12 +23,16 @@ interface TrackingConfig {
23
23
  consentMessage?: string;
24
24
  segment?: SegmentConfig;
25
25
  }
26
+ interface PreviewConfig {
27
+ endpoint?: string;
28
+ }
26
29
  export interface Config {
27
30
  form?: FormConfig;
28
31
  storeModal?: StoreModalConfig;
29
32
  typeTester?: TypeTesterConfig;
30
33
  stripe?: StripeConfig;
31
34
  tracking?: TrackingConfig;
35
+ preview?: PreviewConfig;
32
36
  corsErrorModal?: boolean;
33
37
  }
34
38
  export declare const mergeConfig: (base?: Config, override?: Config) => Config;
@@ -102,6 +106,9 @@ export declare const makeConfig: (config?: Config) => {
102
106
  consentMessage: string | undefined;
103
107
  segment: SegmentConfig | undefined;
104
108
  };
109
+ preview: {
110
+ endpoint: string;
111
+ };
105
112
  corsErrorModal: boolean;
106
113
  };
107
114
  declare const _default: React.Context<{
@@ -174,6 +181,9 @@ declare const _default: React.Context<{
174
181
  consentMessage: string | undefined;
175
182
  segment: SegmentConfig | undefined;
176
183
  };
184
+ preview: {
185
+ endpoint: string;
186
+ };
177
187
  corsErrorModal: boolean;
178
188
  }>;
179
189
  export default _default;
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import React from 'react';
4
+ import { PREVIEW_ENDPOINT } from '../preview/constants.js';
4
5
  const makeTypeTesterConfig = config => {
5
6
  var _config$openTypeFeatu, _config$openTypeFeatu2, _config$openTypeFeatu3, _config$openTypeFeatu4, _config$size, _config$size2, _config$size3, _config$lineHeight, _config$lineHeight2, _config$lineHeight3, _config$letterSpacing, _config$letterSpacing2, _config$letterSpacing3, _config$columns, _config$columns2, _config$columns3;
6
7
  let shy = (config === null || config === void 0 ? void 0 : config.shy) ?? false;
@@ -79,7 +80,7 @@ export const mergeConfig = (base, override) => {
79
80
  return deepMerge(base, override);
80
81
  };
81
82
  export const makeConfig = config => {
82
- var _config$form, _config$storeModal, _config$storeModal2, _config$storeModal3, _config$storeModal4, _config$stripe, _config$tracking, _config$tracking2, _config$tracking3, _config$tracking4;
83
+ var _config$form, _config$storeModal, _config$storeModal2, _config$storeModal3, _config$storeModal4, _config$stripe, _config$tracking, _config$tracking2, _config$tracking3, _config$tracking4, _config$preview;
83
84
  return {
84
85
  typeTester: makeTypeTesterConfig(config === null || config === void 0 ? void 0 : config.typeTester),
85
86
  form: {
@@ -101,6 +102,9 @@ export const makeConfig = config => {
101
102
  consentMessage: config === null || config === void 0 ? void 0 : (_config$tracking3 = config.tracking) === null || _config$tracking3 === void 0 ? void 0 : _config$tracking3.consentMessage,
102
103
  segment: config === null || config === void 0 ? void 0 : (_config$tracking4 = config.tracking) === null || _config$tracking4 === void 0 ? void 0 : _config$tracking4.segment
103
104
  },
105
+ preview: {
106
+ endpoint: (config === null || config === void 0 ? void 0 : (_config$preview = config.preview) === null || _config$preview === void 0 ? void 0 : _config$preview.endpoint) ?? PREVIEW_ENDPOINT
107
+ },
104
108
  corsErrorModal: (config === null || config === void 0 ? void 0 : config.corsErrorModal) ?? true
105
109
  };
106
110
  };
@@ -1,41 +1,42 @@
1
1
  'use client';
2
2
 
3
3
  import _FontdueAdminToolbarTokenMutation from "../../__generated__/FontdueAdminToolbarTokenMutation.graphql.js";
4
- import _FontdueAdminToolbarStaffQuery from "../../__generated__/FontdueAdminToolbarStaffQuery.graphql.js";
5
- import React, { useEffect, useState } from 'react';
4
+ import _FontdueAdminToolbarQuery from "../../__generated__/FontdueAdminToolbarQuery.graphql.js";
5
+ import React, { useContext, useEffect, useState } from 'react';
6
6
  import { commitMutation, fetchQuery, graphql, useRelayEnvironment } from 'react-relay';
7
- // Admin-only affordance for logged-in foundry staff: reveal unpublished
7
+ import ConfigContext from '../ConfigContext.js';
8
+ import { PREVIEW_ENDPOINT, PREVIEW_MARKER_COOKIE } from '../../preview/constants.js';
9
+ // Admin-only affordance for logged-in foundry admins: reveal unpublished
8
10
  // ("hidden") fonts across the whole storefront. Storefront pages are
9
11
  // server-rendered sessionless and cached, and the provider's own query is
10
12
  // preloaded server-side without the session — so `adminUser` can't ride it.
11
- // Staff presence is detected here, client-side, where the request carries
13
+ // Admin presence is detected here, client-side, where the request carries
12
14
  // the session; the public never sees this control.
13
15
  //
14
16
  // The reveal itself is not done here: entering preview brokers a short-lived
15
17
  // admin token and hands it to the framework's preview route, which switches
16
18
  // the whole app to a live, token-bearing render. Exiting clears it. Public
17
19
  // renders never touch any of this and stay static and cached.
18
- const staffQuery = (_FontdueAdminToolbarStaffQuery.hash && _FontdueAdminToolbarStaffQuery.hash !== "40c32a5790cc698bcac936bc2f27b7be" && console.error("The definition of 'FontdueAdminToolbarStaffQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _FontdueAdminToolbarStaffQuery);
20
+ const adminQuery = (_FontdueAdminToolbarQuery.hash && _FontdueAdminToolbarQuery.hash !== "8660b45f086137d249eee82459ad648d" && console.error("The definition of 'FontdueAdminToolbarQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _FontdueAdminToolbarQuery);
19
21
 
20
- // createAdminToken mints a short-lived, stateless admin token from the staff
22
+ // createAdminToken mints a short-lived, stateless admin token from the admin
21
23
  // session; it's handed to the preview route to enter draft mode.
22
24
  const tokenMutation = (_FontdueAdminToolbarTokenMutation.hash && _FontdueAdminToolbarTokenMutation.hash !== "2b82f195747c86d50fd5884d76f3b709" && console.error("The definition of 'FontdueAdminToolbarTokenMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _FontdueAdminToolbarTokenMutation);
23
25
 
24
- // Preview entry/exit route. Relative, so it hits the storefront's own origin.
25
- // Today this is the Next adapter's draft-mode route; other adapters can wire
26
- // the same contract (POST a token to enter, DELETE to exit).
27
- const PREVIEW_ENDPOINT = '/api/preview';
28
-
29
- // Readable twin of the httpOnly preview-token cookie, set by the preview
30
- // route. Lets this client component tell preview is on; the token itself is
31
- // only ever read server-side.
32
- const PREVIEW_MARKER = 'fontdue_preview';
26
+ // The preview entry/exit route and the readable marker cookie are part of the
27
+ // portable preview contract — see fontdue-js/preview. The route path defaults
28
+ // to '/api/preview' but is configurable via FontdueConfig.preview.endpoint so
29
+ // non-Next apps can mount it wherever their router expects (the Next adapter's
30
+ // draft-mode route, an Astro APIRoute, an RR7 action — all honor the same
31
+ // POST-token-to-enter / DELETE-to-exit contract).
33
32
  function hasPreviewCookie() {
34
- return typeof document !== 'undefined' && document.cookie.split('; ').some(c => c === `${PREVIEW_MARKER}=1`);
33
+ return typeof document !== 'undefined' && document.cookie.split('; ').some(c => c === `${PREVIEW_MARKER_COOKIE}=1`);
35
34
  }
36
35
  export default function FontdueAdminToolbar() {
36
+ var _useContext$preview;
37
37
  const environment = useRelayEnvironment();
38
- const [staffName, setStaffName] = useState(null);
38
+ const previewEndpoint = ((_useContext$preview = useContext(ConfigContext).preview) === null || _useContext$preview === void 0 ? void 0 : _useContext$preview.endpoint) ?? PREVIEW_ENDPOINT;
39
+ const [adminName, setAdminName] = useState(null);
39
40
  const [ready, setReady] = useState(false);
40
41
  const [open, setOpen] = useState(false);
41
42
  const [previewing, setPreviewing] = useState(false);
@@ -45,14 +46,14 @@ export default function FontdueAdminToolbar() {
45
46
  setPreviewing(hasPreviewCookie());
46
47
  // network-only: the provider's preloaded query already wrote a sessionless
47
48
  // `viewer` to the store, so we must go to the network (with the session)
48
- // rather than read that cached, staff-blind copy.
49
- const subscription = fetchQuery(environment, staffQuery, {}, {
49
+ // rather than read that cached, admin-blind copy.
50
+ const subscription = fetchQuery(environment, adminQuery, {}, {
50
51
  fetchPolicy: 'network-only'
51
52
  }).subscribe({
52
53
  next: data => {
53
54
  var _data$viewer;
54
55
  const admin = (_data$viewer = data.viewer) === null || _data$viewer === void 0 ? void 0 : _data$viewer.adminUser;
55
- if (admin) setStaffName(admin.name ?? 'admin');
56
+ if (admin) setAdminName(admin.name ?? 'admin');
56
57
  },
57
58
  error: () => setReady(true),
58
59
  complete: () => setReady(true)
@@ -60,10 +61,10 @@ export default function FontdueAdminToolbar() {
60
61
  return () => subscription.unsubscribe();
61
62
  }, [environment]);
62
63
 
63
- // Hidden until we've confirmed a staff session. The public always lands here.
64
- if (!ready || !staffName) return null;
64
+ // Hidden until we've confirmed an admin session. The public always lands here.
65
+ if (!ready || !adminName) return null;
65
66
  async function startPreview(token) {
66
- const res = await fetch(PREVIEW_ENDPOINT, {
67
+ const res = await fetch(previewEndpoint, {
67
68
  method: 'POST',
68
69
  headers: {
69
70
  'content-type': 'application/json'
@@ -104,7 +105,7 @@ export default function FontdueAdminToolbar() {
104
105
  async function exitPreview() {
105
106
  setBusy(true);
106
107
  setError(null);
107
- await fetch(PREVIEW_ENDPOINT, {
108
+ await fetch(previewEndpoint, {
108
109
  method: 'DELETE'
109
110
  });
110
111
  window.location.reload();
@@ -121,7 +122,7 @@ export default function FontdueAdminToolbar() {
121
122
  className: "fontdue-admin-toolbar__title"
122
123
  }, "Fontdue"), /*#__PURE__*/React.createElement("span", {
123
124
  className: "fontdue-admin-toolbar__user"
124
- }, staffName)), /*#__PURE__*/React.createElement("label", {
125
+ }, adminName)), /*#__PURE__*/React.createElement("label", {
125
126
  className: "fontdue-admin-toolbar__toggle"
126
127
  }, /*#__PURE__*/React.createElement("input", {
127
128
  type: "checkbox",
@@ -13,8 +13,8 @@ import retryImport from '../../retryImport.js';
13
13
  import useSerializablePreloadedQuery from '../../relay/useSerializablePreloadedQuery.js';
14
14
  const ConsentBanner = /*#__PURE__*/lazy(() => retryImport(() => import('../ConsentBanner/index.js')));
15
15
  const Tracking = /*#__PURE__*/lazy(() => retryImport(() => import('../Tracking/index.js')));
16
- // Admin-only; self-gates to a staff session and renders nothing otherwise, so
17
- // it's safe to mount for everyone. It detects staff client-side (storefront
16
+ // Admin-only; self-gates to an admin session and renders nothing otherwise, so
17
+ // it's safe to mount for everyone. It detects admins client-side (storefront
18
18
  // renders are sessionless), so it needs no fragment on the provider query.
19
19
  // Lazy so it stays out of the provider's main chunk.
20
20
  const FontdueAdminToolbar = /*#__PURE__*/lazy(() => retryImport(() => import('../FontdueAdminToolbar/index.js')));
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
- import { SerializablePreloadedQuery } from '../../relay/loadSerializableQuery.js';
2
+ import { SerializablePreloadedQuery, type LoadQueryOptions } from '../../relay/loadSerializableQuery.js';
3
3
  import { NewsletterSignupQuery } from '../../__generated__/NewsletterSignupQuery.graphql.js';
4
4
  import { Config } from '../ConfigContext.js';
5
5
  export type NewsletterSignupPreloadedQuery = SerializablePreloadedQuery<NewsletterSignupQuery>;
6
- export declare function loadNewsletterSignupQuery(): Promise<NewsletterSignupPreloadedQuery>;
6
+ export declare function loadNewsletterSignupQuery(options?: LoadQueryOptions): Promise<NewsletterSignupPreloadedQuery>;
7
7
  export interface NewsletterSignup_props {
8
8
  optInLabel?: string;
9
9
  successLabel?: string;
@@ -13,8 +13,8 @@ import useSerializablePreloadedQuery from '../../relay/useSerializablePreloadedQ
13
13
  import NewsletterSignupQueryNode from '../../__generated__/NewsletterSignupQuery.graphql.js';
14
14
  import { EnsureFontdueContext } from '../FontdueContextProvider/index.js';
15
15
  const updateCustomerMutation = (_NewsletterSignupUpdateCustomerMutation.hash && _NewsletterSignupUpdateCustomerMutation.hash !== "769087891b6f263122bbb630b3f2ca6c" && console.error("The definition of 'NewsletterSignupUpdateCustomerMutation' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _NewsletterSignupUpdateCustomerMutation);
16
- export async function loadNewsletterSignupQuery() {
17
- return loadSerializableQuery(NewsletterSignupQueryNode, {});
16
+ export async function loadNewsletterSignupQuery(options) {
17
+ return loadSerializableQuery(NewsletterSignupQueryNode, {}, options);
18
18
  }
19
19
  const query = (_NewsletterSignupQuery.hash && _NewsletterSignupQuery.hash !== "24b303198a6038318723fc0124548862" && console.error("The definition of 'NewsletterSignupQuery' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _NewsletterSignupQuery);
20
20
  function NewsletterSignupComponent(_ref) {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { TestFontsForm_Query } from '../../__generated__/TestFontsForm_Query.graphql.js';
3
- import { SerializablePreloadedQuery } from '../../relay/loadSerializableQuery.js';
3
+ import { SerializablePreloadedQuery, type LoadQueryOptions } from '../../relay/loadSerializableQuery.js';
4
4
  import { Config } from '../ConfigContext.js';
5
5
  export interface TestFontsForm_props {
6
6
  agreementLabel?: string;
@@ -8,7 +8,7 @@ export interface TestFontsForm_props {
8
8
  newsletterCheckboxChecked?: boolean;
9
9
  }
10
10
  export type TestFontsFormPreloadedQuery = SerializablePreloadedQuery<TestFontsForm_Query>;
11
- export declare function loadTestFontsFormQuery(): Promise<TestFontsFormPreloadedQuery>;
11
+ export declare function loadTestFontsFormQuery(options?: LoadQueryOptions): Promise<TestFontsFormPreloadedQuery>;
12
12
  export declare function TestFontsFormPreloadedQueryRenderer({ preloadedQuery, ...rest }: TestFontsForm_props & {
13
13
  preloadedQuery: TestFontsFormPreloadedQuery;
14
14
  }): React.JSX.Element;
@@ -194,8 +194,8 @@ const TestFontsFormComponent = _ref2 => {
194
194
  }));
195
195
  };
196
196
  const query = (_TestFontsForm_Query.hash && _TestFontsForm_Query.hash !== "cd43f0cacc4dcf01cf94fb1ff97197ca" && console.error("The definition of 'TestFontsForm_Query' appears to have changed. Run `relay-compiler` to update the generated files to receive the expected data."), _TestFontsForm_Query);
197
- export async function loadTestFontsFormQuery() {
198
- return loadSerializableQuery(TestFontsFormQueryNode, {});
197
+ export async function loadTestFontsFormQuery(options) {
198
+ return loadSerializableQuery(TestFontsFormQueryNode, {}, options);
199
199
  }
200
200
  export function TestFontsFormPreloadedQueryRenderer(_ref4) {
201
201
  let {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Alignment, Direction, FeaturesProp } from './types.js';
3
- import { SerializablePreloadedQuery } from '../../relay/loadSerializableQuery.js';
3
+ import { SerializablePreloadedQuery, type LoadQueryOptions } from '../../relay/loadSerializableQuery.js';
4
4
  import { TypeTesterStandaloneQuery } from '../../__generated__/TypeTesterStandaloneQuery.graphql.js';
5
5
  import { Config } from '../ConfigContext.js';
6
6
  interface TypeTesterStandaloneComponent_props {
@@ -30,7 +30,7 @@ export interface LoadTypeTesterQueryVariables {
30
30
  familyName: string;
31
31
  styleName: string;
32
32
  }
33
- export declare function loadTypeTesterQuery(variables: LoadTypeTesterQueryVariables): Promise<TypeTesterPreloadedQuery>;
33
+ export declare function loadTypeTesterQuery(variables: LoadTypeTesterQueryVariables, options?: LoadQueryOptions): Promise<TypeTesterPreloadedQuery>;
34
34
  export declare function TypeTesterStandalonePreloadedQueryRenderer({ preloadedQuery, ...rest }: TypeTesterStandaloneComponent_props & {
35
35
  preloadedQuery: TypeTesterPreloadedQuery;
36
36
  }): React.JSX.Element;