@preprio/toolkit 0.6.0-alpha.8 → 1.0.0-rc.1
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 +111 -1363
- package/dist/astro/index.cjs +1555 -182
- package/dist/astro/index.d.cts +201 -1
- package/dist/astro/index.d.ts +201 -1
- package/dist/astro/index.js +1557 -29
- package/dist/{chunk-ATPB7GEC.js → chunk-33GWVTRJ.js} +1 -1
- package/dist/chunk-A2J7R4LR.js +256 -0
- package/dist/{chunk-T7ESBVBI.js → chunk-DSJ22P6J.js} +6 -1
- package/dist/chunk-KM2GME62.js +1255 -0
- package/dist/chunk-UTKH7DOI.js +58 -0
- package/dist/chunk-V7MCHPE7.js +85 -0
- package/dist/{chunk-2QGUP7VQ.js → chunk-WBMN4L7G.js} +1680 -579
- package/dist/chunk-Y7JWV7WV.js +374 -0
- package/dist/codegen/index.cjs +82 -0
- package/dist/codegen/index.d.cts +70 -0
- package/dist/codegen/index.d.ts +70 -0
- package/dist/codegen/index.js +64 -0
- package/dist/index.cjs +3729 -553
- package/dist/index.d.cts +403 -19
- package/dist/index.d.ts +403 -19
- package/dist/index.js +345 -24
- package/dist/live-preview-HCBNBC6C.js +19 -0
- package/dist/nextjs/components.cjs +1872 -729
- package/dist/nextjs/components.d.cts +5 -51
- package/dist/nextjs/components.d.ts +5 -51
- package/dist/nextjs/components.js +8 -274
- package/dist/nextjs/index.cjs +1228 -181
- package/dist/nextjs/index.d.cts +247 -92
- package/dist/nextjs/index.d.ts +247 -92
- package/dist/nextjs/index.js +1629 -111
- package/dist/nextjs/live-action.cjs +298 -0
- package/dist/nextjs/live-action.d.cts +12 -0
- package/dist/nextjs/live-action.d.ts +12 -0
- package/dist/nextjs/live-action.js +68 -0
- package/dist/nextjs/live.cjs +2010 -0
- package/dist/nextjs/live.d.cts +54 -0
- package/dist/nextjs/live.d.ts +54 -0
- package/dist/nextjs/live.js +287 -0
- package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
- package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
- package/dist/nuxt/index.cjs +15 -16
- package/dist/nuxt/index.d.cts +167 -6
- package/dist/nuxt/index.d.ts +167 -6
- package/dist/nuxt/index.js +402 -15
- package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
- package/dist/nuxt/live.cjs +1928 -0
- package/dist/nuxt/live.d.cts +45 -0
- package/dist/nuxt/live.d.ts +45 -0
- package/dist/nuxt/live.js +216 -0
- package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
- package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
- package/dist/react/components.cjs +1865 -480
- package/dist/react/components.d.cts +43 -8
- package/dist/react/components.d.ts +43 -8
- package/dist/react/components.js +1865 -480
- package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
- package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
- package/dist/sveltekit/index.cjs +15 -16
- package/dist/sveltekit/index.d.cts +111 -10
- package/dist/sveltekit/index.d.ts +111 -10
- package/dist/sveltekit/index.js +398 -15
- package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
- package/dist/sveltekit/live.cjs +1940 -0
- package/dist/sveltekit/live.d.cts +61 -0
- package/dist/sveltekit/live.d.ts +61 -0
- package/dist/sveltekit/live.js +220 -0
- package/package.json +132 -71
- package/src/astro/PreprToolbar.astro +7 -1
- package/src/astro/PreprTrackingPixel.astro +2 -4
- package/src/nuxt/PreprToolbar.vue +12 -1
- package/src/nuxt/PreprTrackingPixel.vue +2 -4
- package/src/sveltekit/PreprToolbar.svelte +17 -2
- package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
- package/dist/astro/chunk-R2YPGDVU.js +0 -173
- package/dist/astro/graphql.cjs +0 -1078
- package/dist/astro/graphql.d.cts +0 -300
- package/dist/astro/graphql.d.ts +0 -300
- package/dist/astro/graphql.js +0 -984
- package/dist/astro/index-XT_z-RYT.d.cts +0 -130
- package/dist/astro/index-XT_z-RYT.d.ts +0 -130
- package/dist/chunk-3NCEVJJ3.js +0 -10
- package/dist/chunk-OY7OKO6Q.js +0 -499
- package/dist/chunk-S5RWVMDJ.js +0 -148
- package/dist/graphql/codegen.cjs +0 -557
- package/dist/graphql/codegen.d.cts +0 -23
- package/dist/graphql/codegen.d.ts +0 -23
- package/dist/graphql/codegen.js +0 -99
- package/dist/graphql.cjs +0 -1020
- package/dist/graphql.d.cts +0 -335
- package/dist/graphql.d.ts +0 -335
- package/dist/graphql.js +0 -448
- package/dist/nextjs/chunk-O2SBSBDG.js +0 -549
- package/dist/nextjs/graphql.cjs +0 -1811
- package/dist/nextjs/graphql.d.cts +0 -498
- package/dist/nextjs/graphql.d.ts +0 -498
- package/dist/nextjs/graphql.js +0 -1397
- package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
- package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
- package/dist/nuxt/chunk-SX3MSVPK.js +0 -417
- package/dist/nuxt/graphql.cjs +0 -1085
- package/dist/nuxt/graphql.d.cts +0 -297
- package/dist/nuxt/graphql.d.ts +0 -297
- package/dist/nuxt/graphql.js +0 -985
- package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
- package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
- package/dist/pixel-DwW7cXJm.d.cts +0 -49
- package/dist/pixel-DwW7cXJm.d.ts +0 -49
- package/dist/server-Brr1UgtW.d.ts +0 -59
- package/dist/server-DJuS3YU0.d.cts +0 -59
- package/dist/sveltekit/chunk-UOASSHZO.js +0 -413
- package/dist/sveltekit/graphql.cjs +0 -1091
- package/dist/sveltekit/graphql.d.cts +0 -302
- package/dist/sveltekit/graphql.d.ts +0 -302
- package/dist/sveltekit/graphql.js +0 -991
- package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
- package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -1,7 +1,167 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { a as PreprFeatures, P as PreprHeaders, c as PreprToolbarProps, d as PreprToolbarComponentProps } from './server-BL-sqZvu.js';
|
|
3
|
-
export { b as PreprError, e as extractAccessToken, i as isPersonalizedResponse, v as validatePreprToken } from './server-BL-sqZvu.js';
|
|
4
2
|
|
|
3
|
+
type Dictionary = Record<string, unknown>;
|
|
4
|
+
declare const dictionaries: {
|
|
5
|
+
en: Dictionary;
|
|
6
|
+
nl: Dictionary;
|
|
7
|
+
fr: Dictionary;
|
|
8
|
+
de: Dictionary;
|
|
9
|
+
};
|
|
10
|
+
type Locale = keyof typeof dictionaries;
|
|
11
|
+
|
|
12
|
+
/** A segment from Prepr, as listed in the toolbar's segment picker. */
|
|
13
|
+
interface PreprSegment {
|
|
14
|
+
readonly _id: string;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
19
|
+
* form leaves room for per-feature options later without a breaking change.
|
|
20
|
+
*/
|
|
21
|
+
type PreprFeatureConfig = boolean | {
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
25
|
+
interface PreprFeatures {
|
|
26
|
+
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
27
|
+
segments?: PreprFeatureConfig;
|
|
28
|
+
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
29
|
+
abTesting?: PreprFeatureConfig;
|
|
30
|
+
/**
|
|
31
|
+
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
32
|
+
* tooltip/overlay and the close-edit pill.
|
|
33
|
+
*
|
|
34
|
+
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
35
|
+
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
36
|
+
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
37
|
+
* to visitors. See iframe-bridge.ts.
|
|
38
|
+
*/
|
|
39
|
+
editMode?: PreprFeatureConfig;
|
|
40
|
+
}
|
|
41
|
+
/** Options shared by the toolbar and the preview runtime. */
|
|
42
|
+
interface PreprToolbarOptions {
|
|
43
|
+
/** Log what the toolkit does to the browser console. Default `false`. */
|
|
44
|
+
debug?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Language of the toolbar and the visual editor labels. Defaults to the
|
|
47
|
+
* first supported browser language, then English.
|
|
48
|
+
*/
|
|
49
|
+
locale?: Locale;
|
|
50
|
+
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
51
|
+
features?: PreprFeatures;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for the preview runtime. Two independent axes: `features` decides
|
|
55
|
+
* *what runs*, `ui` decides *whether the toolbar is visible*.
|
|
56
|
+
*/
|
|
57
|
+
interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Mount the visible `<prepr-toolbar>` element. Default `true`.
|
|
60
|
+
*
|
|
61
|
+
* `false` keeps every non-visual side effect wired — click-to-edit, the
|
|
62
|
+
* editor bridge, scroll restore, cookies and headers — with no chrome of its
|
|
63
|
+
* own. That is how a site gets live editing, or editor scroll restore, while
|
|
64
|
+
* rendering its own UI instead of the bar.
|
|
65
|
+
*
|
|
66
|
+
* Already implied inside the editor's iframe (the CMS owns the chrome there)
|
|
67
|
+
* and by `?prepr_hide_bar=true`, so this option is for consumers who want a
|
|
68
|
+
* headless preview by their own choice.
|
|
69
|
+
*/
|
|
70
|
+
ui?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
73
|
+
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
74
|
+
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
75
|
+
* the editor's origin exactly: scheme, host and port.
|
|
76
|
+
*
|
|
77
|
+
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
78
|
+
* that frames the preview can then switch on preview and edit mode and
|
|
79
|
+
* receives the field-edit events, which carry content item ids.
|
|
80
|
+
*/
|
|
81
|
+
allowedEditorOrigins?: string[];
|
|
82
|
+
/**
|
|
83
|
+
* Set when your preview token uses GraphQL strict mode, where required
|
|
84
|
+
* fields are never null. The editor then holds back new entries until
|
|
85
|
+
* their required fields are filled, and never sends a cleared required
|
|
86
|
+
* field as null. Applies to live preview on the same page as well, so the
|
|
87
|
+
* live preview helpers do not need their own `strictMode`.
|
|
88
|
+
*/
|
|
89
|
+
strictMode?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Strip the invisible stega characters out of visible text at runtime.
|
|
92
|
+
* Default `true`.
|
|
93
|
+
*
|
|
94
|
+
* Preview content carries an encoded payload inside the text itself. Left in
|
|
95
|
+
* place it is invisible but real: it inflates `String.length`, breaks text
|
|
96
|
+
* measurement and truncation, and is announced by screen readers.
|
|
97
|
+
*
|
|
98
|
+
* Set `false` only when the site already strips the characters itself — for
|
|
99
|
+
* example by passing every field through `stegaClean` as it renders.
|
|
100
|
+
* Click-to-edit is unaffected either way: elements are still tagged from the
|
|
101
|
+
* payload, so the overlay keeps working.
|
|
102
|
+
*/
|
|
103
|
+
autoClean?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The data the toolbar shows. `getToolbarProps` builds it on the server from
|
|
107
|
+
* the request headers.
|
|
108
|
+
*/
|
|
109
|
+
interface PreprToolbarProps {
|
|
110
|
+
/**
|
|
111
|
+
* Server-resolved active segment. Optional: omit it with `segments`
|
|
112
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
113
|
+
* the persisted cookie is used.
|
|
114
|
+
*/
|
|
115
|
+
readonly activeSegment?: string | null;
|
|
116
|
+
/**
|
|
117
|
+
* Server-resolved active A/B variant. Optional: omit it with `abTesting`
|
|
118
|
+
* disabled, where there is nothing to resolve. When enabled and omitted,
|
|
119
|
+
* the persisted cookie is used.
|
|
120
|
+
*/
|
|
121
|
+
readonly activeVariant?: string | null;
|
|
122
|
+
/** Available segments to personalize on. */
|
|
123
|
+
readonly segments?: readonly PreprSegment[];
|
|
124
|
+
/** @deprecated Alias for `segments`. */
|
|
125
|
+
readonly data?: readonly PreprSegment[];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Prop type for the framework `<PreprToolbar>` components: the toolbar data
|
|
129
|
+
* plus the options bag core `createPreprPreview` accepts.
|
|
130
|
+
*/
|
|
131
|
+
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
132
|
+
options?: PreprPreviewOptions;
|
|
133
|
+
}
|
|
134
|
+
/** The two sides of an A/B test. */
|
|
135
|
+
type PreprVariant = 'A' | 'B';
|
|
136
|
+
/**
|
|
137
|
+
* The headers to send with a Prepr GraphQL request so the API personalizes
|
|
138
|
+
* the response for this visitor. `getPreprHeaders` returns them; spread them
|
|
139
|
+
* into the request's `headers`.
|
|
140
|
+
*/
|
|
141
|
+
interface PreprHeaders {
|
|
142
|
+
readonly 'prepr-customer-id'?: string;
|
|
143
|
+
readonly 'Prepr-Segments'?: string;
|
|
144
|
+
readonly 'Prepr-ABtesting'?: PreprVariant;
|
|
145
|
+
readonly 'Prepr-Preview-Bar'?: 'true';
|
|
146
|
+
readonly 'Prepr-Context-utm_source'?: string;
|
|
147
|
+
readonly 'Prepr-Context-utm_medium'?: string;
|
|
148
|
+
readonly 'Prepr-Context-utm_term'?: string;
|
|
149
|
+
readonly 'Prepr-Context-utm_content'?: string;
|
|
150
|
+
readonly 'Prepr-Context-utm_campaign'?: string;
|
|
151
|
+
readonly 'Prepr-Context-initial_referral'?: string;
|
|
152
|
+
readonly 'Prepr-Visitor-IP'?: string;
|
|
153
|
+
readonly 'Prepr-Hubspot-Id'?: string;
|
|
154
|
+
readonly 'Prepr-Customer-Id-Created'?: 'true';
|
|
155
|
+
/** The visitor's browser User-Agent, used by the API for device detection. */
|
|
156
|
+
readonly 'User-Agent'?: string;
|
|
157
|
+
/** @deprecated Never populated; the visitor's value is under `User-Agent`. */
|
|
158
|
+
readonly 'Prepr-User-Agent'?: string;
|
|
159
|
+
readonly 'Prepr-Package'?: string;
|
|
160
|
+
}
|
|
161
|
+
/** Why a `PreprError` was thrown; read it from `error.code`. */
|
|
162
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
163
|
+
|
|
164
|
+
/** Options for the Prepr middleware of every framework. */
|
|
5
165
|
interface PreprMiddlewareOptions {
|
|
6
166
|
/** Enable preview-mode headers (segment/AB overrides, preview bar). */
|
|
7
167
|
preview?: boolean;
|
|
@@ -23,6 +183,17 @@ interface PreprMiddlewareOptions {
|
|
|
23
183
|
declare function createPreprMiddleware(request: NextRequest, options?: PreprMiddlewareOptions): NextResponse;
|
|
24
184
|
declare function createPreprMiddleware(request: NextRequest, response: NextResponse, options?: PreprMiddlewareOptions): NextResponse;
|
|
25
185
|
|
|
186
|
+
/**
|
|
187
|
+
* What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
|
|
188
|
+
* `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
|
|
189
|
+
* string-like object such as codegen's `TypedDocumentString`.
|
|
190
|
+
*/
|
|
191
|
+
type QueryInput = string | {
|
|
192
|
+
kind: 'Document';
|
|
193
|
+
} | {
|
|
194
|
+
toString(): string;
|
|
195
|
+
};
|
|
196
|
+
|
|
26
197
|
/** Prepr Customer ID for the current request. Server-only. */
|
|
27
198
|
declare function getPreprUUID(): Promise<string | null>;
|
|
28
199
|
/** Active segment for the current request. Server-only. */
|
|
@@ -43,83 +214,47 @@ declare function getPreprHeaders(): Promise<PreprHeaders>;
|
|
|
43
214
|
* bad or missing token can't crash the host app.
|
|
44
215
|
*/
|
|
45
216
|
declare function getToolbarProps(token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
217
|
+
interface NextNormalizeQueryOptions {
|
|
218
|
+
/**
|
|
219
|
+
* Pass the same preview flag as the middleware; never `true` on a
|
|
220
|
+
* production deployment. When false (the default) the request is not read,
|
|
221
|
+
* so static and ISR pages stay static.
|
|
222
|
+
*/
|
|
223
|
+
enabled?: boolean;
|
|
224
|
+
/** Which operation to use when the document holds more than one. */
|
|
225
|
+
operationName?: string;
|
|
52
226
|
}
|
|
53
227
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* carry on.
|
|
57
|
-
*
|
|
58
|
-
* Draft mode is what keeps preview fresh with Cache Components: Next.js then
|
|
59
|
-
* renders every page per request and skips `'use cache'` entries and the Data
|
|
60
|
-
* Cache, so an edit shows on the next load without a publish webhook.
|
|
228
|
+
* Show the Prepr editor's unsaved changes in server components: pass the
|
|
229
|
+
* query and its result, and render what comes back.
|
|
61
230
|
*
|
|
62
|
-
*
|
|
231
|
+
* ```ts
|
|
232
|
+
* const page = await normalizeQuery(GetPageDocument, data, { enabled: isPreview });
|
|
233
|
+
* ```
|
|
63
234
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* if (draft) return draft;
|
|
235
|
+
* Needs `PreprRefresh` mounted, and `_id` selected on every item and
|
|
236
|
+
* component that should update. Server-only; Next.js 16+.
|
|
67
237
|
*/
|
|
68
|
-
declare function
|
|
69
|
-
/**
|
|
70
|
-
* The route handler `preprDraftRedirect` sends preview visitors to: turns on
|
|
71
|
-
* draft mode and redirects back to the page. Answers 404 outside preview.
|
|
72
|
-
* Only same-origin paths are followed, so it cannot be used as an open
|
|
73
|
-
* redirect.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* // app/api/prepr/draft/route.ts
|
|
77
|
-
* export const GET = createPreprDraftRoute({
|
|
78
|
-
* preview: process.env.PREPR_ENV === 'preview',
|
|
79
|
-
* });
|
|
80
|
-
*/
|
|
81
|
-
declare function createPreprDraftRoute(options: Pick<PreprDraftOptions, 'preview'>): (request: Request) => Promise<Response>;
|
|
238
|
+
declare function normalizeQuery<T>(query: QueryInput, result: T, options?: NextNormalizeQueryOptions): Promise<T>;
|
|
82
239
|
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
* The webhook's ID, shown in Prepr under Settings → Webhooks. Prepr signs
|
|
90
|
-
* each request with it (HMAC-SHA256 of the body, in the `Prepr-Signature`
|
|
91
|
-
* header). Keep it in an environment variable.
|
|
92
|
-
*/
|
|
93
|
-
secret: string | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Passed to `revalidateTag`. The default `{ expire: 0 }` shows a publish
|
|
96
|
-
* on the very next request; `'max'` serves the old page once more while
|
|
97
|
-
* the new one renders in the background.
|
|
98
|
-
*/
|
|
99
|
-
profile?: PreprRevalidateProfile;
|
|
240
|
+
/** Error thrown by the token helpers and the segments fetch. */
|
|
241
|
+
declare class PreprError extends Error {
|
|
242
|
+
readonly code: PreprErrorCode;
|
|
243
|
+
readonly context?: string | undefined;
|
|
244
|
+
readonly originalError?: Error | undefined;
|
|
245
|
+
constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
|
|
100
246
|
}
|
|
101
247
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* or `preprCacheTags`. On publish, unpublish and delete it also revalidates
|
|
105
|
-
* the item's `preprModelTag`, so list pages and lookups that found nothing
|
|
106
|
-
* pick up new and removed items. `schema.changed` refreshes the schema the
|
|
107
|
-
* client rewrites queries with.
|
|
108
|
-
*
|
|
109
|
-
* Other events (draft edits, new assets, visitors, segments) are
|
|
110
|
-
* acknowledged and revalidate nothing, so the webhook can subscribe to
|
|
111
|
-
* everything.
|
|
112
|
-
*
|
|
113
|
-
* Requests without a valid `Prepr-Signature` or older than five minutes get
|
|
114
|
-
* 401; without `secret` every request gets 500.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* // app/api/prepr/webhook/route.ts
|
|
118
|
-
* export const POST = createPreprWebhookRoute({
|
|
119
|
-
* secret: process.env.PREPR_WEBHOOK_SECRET,
|
|
120
|
-
* });
|
|
248
|
+
* Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
|
|
249
|
+
* @throws PreprError if the token is missing or not an HTTPS URL.
|
|
121
250
|
*/
|
|
122
|
-
declare function
|
|
251
|
+
declare function validatePreprToken(token: string): void;
|
|
252
|
+
/**
|
|
253
|
+
* Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
|
|
254
|
+
* -> `abc123`.
|
|
255
|
+
* @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
|
|
256
|
+
*/
|
|
257
|
+
declare function extractAccessToken(graphqlUrl: string): string;
|
|
123
258
|
|
|
124
259
|
/**
|
|
125
260
|
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
@@ -134,11 +269,16 @@ declare function createPreprWebhookRoute(options: PreprWebhookOptions): (request
|
|
|
134
269
|
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
135
270
|
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
136
271
|
*/
|
|
137
|
-
/** Config
|
|
272
|
+
/** Config for the Prepr tracking pixel, passed to `loadTrackingPixel`. */
|
|
138
273
|
interface PreprPixelConfig {
|
|
139
274
|
destinations?: {
|
|
275
|
+
/** Also push tracked events to Google Tag Manager's `dataLayer`. */
|
|
140
276
|
googleTagManager?: boolean;
|
|
141
277
|
};
|
|
278
|
+
/**
|
|
279
|
+
* How much of a personalized or A/B element must be in view to count as an
|
|
280
|
+
* impression, as the pixel defines it.
|
|
281
|
+
*/
|
|
142
282
|
variantImpressionThreshold?: number;
|
|
143
283
|
}
|
|
144
284
|
type PreprQueueArgs = unknown[];
|
|
@@ -162,9 +302,9 @@ interface PreprTrackingPixelProps {
|
|
|
162
302
|
/**
|
|
163
303
|
* Loads Prepr's CDN tracking pixel on mount. Renders nothing.
|
|
164
304
|
*
|
|
165
|
-
* The pixel
|
|
166
|
-
*
|
|
167
|
-
*
|
|
305
|
+
* The pixel counts a view for the content item named by the page's
|
|
306
|
+
* `<meta property="prepr:id">` tag, and a new one when a client-side route
|
|
307
|
+
* change points that tag at another item.
|
|
168
308
|
*/
|
|
169
309
|
declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): null;
|
|
170
310
|
|
|
@@ -174,22 +314,37 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
|
|
|
174
314
|
* `createPreprPreview` mounts imperatively.
|
|
175
315
|
*/
|
|
176
316
|
declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
|
|
177
|
-
/**
|
|
178
|
-
* Gets each client-side navigation's decision in before the click: when the
|
|
179
|
-
* visitor hovers over a same-site link (or presses it, on touch devices), it
|
|
180
|
-
* asks `createPreprProxy` which variants they get on that page. Clicks are
|
|
181
|
-
* never held: the new page paints with those variants when the answer is in,
|
|
182
|
-
* and keeps its personalized sections hidden until then otherwise. Pages
|
|
183
|
-
* without personalization answer with no groups and are not asked again for
|
|
184
|
-
* an hour.
|
|
185
|
-
*
|
|
186
|
-
* Mount it once in the root layout, so links on pages without a
|
|
187
|
-
* `PreprStack` are covered too. Links to other sites and links that open a
|
|
188
|
-
* new tab or download are left alone.
|
|
189
|
-
*
|
|
190
|
-
* @example
|
|
191
|
-
* <PreprPersonalizationSwitch />
|
|
192
|
-
*/
|
|
193
|
-
declare function PreprPersonalizationSwitch(): null;
|
|
194
317
|
|
|
195
|
-
|
|
318
|
+
/** Executes a registered query. `query` is opaque — string or DocumentNode. */
|
|
319
|
+
interface LiveFetcher {
|
|
320
|
+
(query: unknown, variables?: Record<string, unknown>): Promise<unknown>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
interface LivePreviewConfig {
|
|
324
|
+
/**
|
|
325
|
+
* Pass your preview flag; never `true` on a production deployment.
|
|
326
|
+
* Defaults to false: nothing starts and `useLive` is a passthrough.
|
|
327
|
+
*/
|
|
328
|
+
enabled?: boolean;
|
|
329
|
+
/** Runs registered queries against Prepr GraphQL in preview mode. */
|
|
330
|
+
fetcher?: LiveFetcher;
|
|
331
|
+
/** Exact editor origins, replacing the `*.prepr.io` default. */
|
|
332
|
+
allowedEditorOrigins?: string[];
|
|
333
|
+
/** Your preview token uses GraphQL strict mode; see the toolbar option. */
|
|
334
|
+
strictMode?: boolean;
|
|
335
|
+
}
|
|
336
|
+
interface PreprRefreshProps {
|
|
337
|
+
/** Pass your preview flag; never `true` on a production deployment. */
|
|
338
|
+
enabled?: boolean;
|
|
339
|
+
/** Exact editor origins, replacing the `*.prepr.io` default. */
|
|
340
|
+
allowedEditorOrigins?: string[];
|
|
341
|
+
/** Your preview token uses GraphQL strict mode; see the toolbar option. */
|
|
342
|
+
strictMode?: boolean;
|
|
343
|
+
}
|
|
344
|
+
interface UseLiveOptions {
|
|
345
|
+
/** Query (string or DocumentNode) passed as-is to the fetcher. */
|
|
346
|
+
query?: unknown;
|
|
347
|
+
variables?: Record<string, unknown>;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export { type LiveFetcher, type LivePreviewConfig, type NextNormalizeQueryOptions, PreprError, type PreprMiddlewareOptions, type PreprRefreshProps, PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps, type UseLiveOptions, createPreprMiddleware, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, normalizeQuery, validatePreprToken };
|