@preprio/toolkit 0.6.0-alpha.9 → 1.0.0-rc.2
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-A2J7R4LR.js +256 -0
- package/dist/{chunk-5QIWVDP2.js → chunk-DBKZWOXA.js} +1 -1
- package/dist/{chunk-WQBKQG4R.js → chunk-EWXBE3JD.js} +6 -1
- package/dist/chunk-KM2GME62.js +1255 -0
- package/dist/{chunk-J66UOCK6.js → chunk-LJA5K4KM.js} +1680 -579
- package/dist/chunk-UTKH7DOI.js +58 -0
- package/dist/chunk-V7MCHPE7.js +85 -0
- 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 -754
- package/dist/nextjs/components.d.cts +5 -51
- package/dist/nextjs/components.d.ts +5 -51
- package/dist/nextjs/components.js +8 -299
- 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-UN4JADNU.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-S5RWVMDJ.js +0 -148
- package/dist/chunk-XL4Y7FGW.js +0 -499
- 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-CMV6ZP6E.js +0 -549
- package/dist/nextjs/graphql.cjs +0 -1836
- package/dist/nextjs/graphql.d.cts +0 -498
- package/dist/nextjs/graphql.d.ts +0 -498
- package/dist/nextjs/graphql.js +0 -1422
- package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
- package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
- package/dist/nuxt/chunk-XWOABVMW.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-3S5RA6G5.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
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
import { DocumentNode } from 'graphql';
|
|
2
|
-
import { P as PreprHeaders, a as PreprFeatures } from './server-BL-sqZvu.cjs';
|
|
3
|
-
export { b as PreprError, i as isPersonalizedResponse } from './server-BL-sqZvu.cjs';
|
|
4
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
5
|
-
import { ReactNode, ReactElement } from 'react';
|
|
6
|
-
|
|
7
|
-
/** Prepr's variant id for visitors outside every targeted segment. */
|
|
8
|
-
declare const PREPR_DEFAULT_VARIANT = "ALL_OTHER_USERS";
|
|
9
|
-
|
|
10
|
-
/** The variant ids Prepr chose for one visitor, per personalization group. */
|
|
11
|
-
type PreprDecisions = ReadonlyMap<string, readonly string[]>;
|
|
12
|
-
/**
|
|
13
|
-
* Variant ids per group from a decision response, de-duplicated and in
|
|
14
|
-
* Prepr's order. A visitor in several segments can get more than one variant
|
|
15
|
-
* of the same group, so each entry is a list.
|
|
16
|
-
*/
|
|
17
|
-
declare function decisionsFrom(data: unknown): PreprDecisions;
|
|
18
|
-
interface ResolveVariantsOptions {
|
|
19
|
-
/**
|
|
20
|
-
* The visitor's per-group variants (from a decision query). Without it,
|
|
21
|
-
* personalization groups show their default variant.
|
|
22
|
-
*/
|
|
23
|
-
decisions?: PreprDecisions;
|
|
24
|
-
/** The visitor's A/B bucket. Without it, A/B groups use the decision, then `A`. */
|
|
25
|
-
bucket?: string;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Keeps, in every list of a variants query result, only the variants this
|
|
29
|
-
* visitor gets, at any depth (page stacks, nested stacks, personalized
|
|
30
|
-
* buttons). Items outside a group are kept as they are.
|
|
31
|
-
*/
|
|
32
|
-
declare function resolveVariants<T>(data: T, options?: ResolveVariantsOptions): T;
|
|
33
|
-
|
|
34
|
-
interface FieldInfo {
|
|
35
|
-
/** Named type of the field, without list/non-null wrappers. */
|
|
36
|
-
type: string;
|
|
37
|
-
/** The field accepts Prepr's `personalize` argument (a stack). */
|
|
38
|
-
personalizable: boolean;
|
|
39
|
-
}
|
|
40
|
-
interface TypeInfo {
|
|
41
|
-
fields: Record<string, FieldInfo>;
|
|
42
|
-
/** Members of a union or implementations of an interface. */
|
|
43
|
-
possibleTypes: string[];
|
|
44
|
-
hasContext: boolean;
|
|
45
|
-
}
|
|
46
|
-
/** The slice of the schema the variant transforms need. */
|
|
47
|
-
interface PreprSchemaInfo {
|
|
48
|
-
queryType: string;
|
|
49
|
-
types: Record<string, TypeInfo>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** A run of stack items that renders the same way: see {@link splitStack}. */
|
|
53
|
-
interface PreprStackBlock<T> {
|
|
54
|
-
key: string;
|
|
55
|
-
items: T[];
|
|
56
|
-
/**
|
|
57
|
-
* Rendered position of the block's first item: a group (whichever variant
|
|
58
|
-
* shows) takes one position, any other item one each. Use it for anything
|
|
59
|
-
* that depends on page position, like which section owns the h1.
|
|
60
|
-
*/
|
|
61
|
-
index: number;
|
|
62
|
-
/**
|
|
63
|
-
* Some item in the block (or nested inside one) is a segment variant, so
|
|
64
|
-
* the block depends on the visitor and is decided per request.
|
|
65
|
-
*/
|
|
66
|
-
personalized: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Some item in the block (or nested inside one) is an A/B variant. Without
|
|
69
|
-
* a known bucket, such a block renders once per bucket and the visitor's
|
|
70
|
-
* bucket is picked in the browser before first paint.
|
|
71
|
-
*/
|
|
72
|
-
abTest: boolean;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Splits a variants-query stack into blocks. Each personalization or A/B
|
|
76
|
-
* group becomes one block (a variant can hold a different number of items
|
|
77
|
-
* than the default); consecutive items that never vary are merged.
|
|
78
|
-
*/
|
|
79
|
-
declare function splitStack<T>(items: readonly T[]): PreprStackBlock<T>[];
|
|
80
|
-
|
|
81
|
-
/** The attribute Prepr's tracking pixel reads impressions and conversions from. */
|
|
82
|
-
interface PreprVariantProps {
|
|
83
|
-
'data-prepr-variant-key'?: string;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Attributes that let Prepr's tracking pixel count impressions of this item's
|
|
87
|
-
* variant, for an item from a query run with `variants: true`. Spread them on
|
|
88
|
-
* the element that shows the item; an item outside any personalization or A/B
|
|
89
|
-
* group gets none.
|
|
90
|
-
*
|
|
91
|
-
* Items rendered by the Next.js `PreprStack` are tagged for you. Reach for this
|
|
92
|
-
* for items nested inside them (cards, buttons, models in a section) and in
|
|
93
|
-
* frameworks without `PreprStack`.
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* <article {...preprVariantProps(card)}>…</article>
|
|
97
|
-
*/
|
|
98
|
-
declare function preprVariantProps(item: unknown): PreprVariantProps;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* A GraphQL document accepted by `query`: a plain string, graphql-codegen's
|
|
102
|
-
* `TypedDocumentString` (`documentMode: 'string'`), or any `DocumentNode`,
|
|
103
|
-
* including codegen's default `TypedDocumentNode` output.
|
|
104
|
-
*
|
|
105
|
-
* The phantom `__apiType` field is how codegen attaches result and variable
|
|
106
|
-
* types; matching it structurally keeps `@graphql-typed-document-node/core`
|
|
107
|
-
* out of this package.
|
|
108
|
-
*/
|
|
109
|
-
type PreprDocument<TResult, TVariables> = string | ({
|
|
110
|
-
__apiType?: (variables: TVariables) => TResult;
|
|
111
|
-
} & (String | DocumentNode));
|
|
112
|
-
/**
|
|
113
|
-
* How stega markers are stripped from the response:
|
|
114
|
-
* - `'urls'`: only from values under URL-like keys (`url`, `slug`, `link`,
|
|
115
|
-
* `href`), where markers break links. Text keeps its markers for
|
|
116
|
-
* click-to-edit.
|
|
117
|
-
* - `'all'`: from every string.
|
|
118
|
-
* - `'none'`: never.
|
|
119
|
-
*/
|
|
120
|
-
type PreprStegaMode = 'urls' | 'all' | 'none';
|
|
121
|
-
interface PreprClientOptions {
|
|
122
|
-
/** Full Prepr GraphQL URL, `https://graphql.prepr.io/<token>`. */
|
|
123
|
-
url: string;
|
|
124
|
-
/**
|
|
125
|
-
* Fetch implementation. Defaults to the global `fetch`, read at call time so
|
|
126
|
-
* framework-patched versions (such as Next.js's) are used.
|
|
127
|
-
*/
|
|
128
|
-
fetch?: typeof fetch;
|
|
129
|
-
/**
|
|
130
|
-
* Preview mode: every query skips the HTTP cache so editors see each edit,
|
|
131
|
-
* and stega defaults to `'urls'` so click-to-edit keeps working.
|
|
132
|
-
*/
|
|
133
|
-
preview?: boolean;
|
|
134
|
-
/** Default: `'urls'` when `preview` is true, otherwise `'all'`. */
|
|
135
|
-
stega?: PreprStegaMode;
|
|
136
|
-
/**
|
|
137
|
-
* Send queries as a GET with the request body base64-encoded in a
|
|
138
|
-
* `Fastly-Query` header, which Prepr's edge serves from the nearest point
|
|
139
|
-
* of presence (about half the latency of a POST in our measurements).
|
|
140
|
-
* Queries too large for a header still go as a POST. Off by default: it
|
|
141
|
-
* relies on Prepr edge behavior that is not part of the documented API.
|
|
142
|
-
*/
|
|
143
|
-
fastlyQuery?: boolean;
|
|
144
|
-
/**
|
|
145
|
-
* @internal Fetch options for the one-time schema introspection, so a
|
|
146
|
-
* framework wrapper can put it in its data cache.
|
|
147
|
-
*/
|
|
148
|
-
schemaInit?: RequestInit;
|
|
149
|
-
/**
|
|
150
|
-
* Headers sent with every request, such as a header a proxy in front of the
|
|
151
|
-
* API requires. They are fixed when the client is created, so they cannot
|
|
152
|
-
* vary per visitor and do not stop responses from being cached. Put
|
|
153
|
-
* per-request values in the query's `headers` instead.
|
|
154
|
-
*/
|
|
155
|
-
headers?: HeadersInit;
|
|
156
|
-
}
|
|
157
|
-
interface PreprQueryOptions {
|
|
158
|
-
/**
|
|
159
|
-
* Prepr headers to forward, typically from `getPreprHeaders`. Passing any
|
|
160
|
-
* headers object, even an empty one, makes the request `no-store`: the
|
|
161
|
-
* response may be personalized and must not be shared between visitors.
|
|
162
|
-
*/
|
|
163
|
-
headers?: PreprHeaders | HeadersInit;
|
|
164
|
-
/**
|
|
165
|
-
* Extra fetch options such as `signal`. `method` and `body` are set by the
|
|
166
|
-
* client. `init.headers` are merged like `headers`, and also make the
|
|
167
|
-
* request `no-store`.
|
|
168
|
-
*/
|
|
169
|
-
init?: RequestInit;
|
|
170
|
-
/** Per-query fetch, overriding the client's (e.g. SvelteKit's `event.fetch`). */
|
|
171
|
-
fetch?: typeof fetch;
|
|
172
|
-
/**
|
|
173
|
-
* Fetch every variant instead of the visitor's: `personalize: false` is
|
|
174
|
-
* added to every personalizable field in the query, at any depth, and each
|
|
175
|
-
* item gets its `_context` (under `_preprContext`). The result is the same
|
|
176
|
-
* for every visitor, so it can be cached; pass it to `resolveVariants` with
|
|
177
|
-
* the visitor's `decide()` result to get what they see.
|
|
178
|
-
*
|
|
179
|
-
* The client learns which fields are personalizable from one schema
|
|
180
|
-
* introspection request, made on first use.
|
|
181
|
-
*/
|
|
182
|
-
variants?: boolean;
|
|
183
|
-
}
|
|
184
|
-
/** Options for `decide()`. */
|
|
185
|
-
interface PreprDecideOptions extends Omit<PreprQueryOptions, 'variants'> {
|
|
186
|
-
/**
|
|
187
|
-
* The `variants: true` result this decision is for (the whole `data`
|
|
188
|
-
* object). The decision query then asks only about the fields that hold
|
|
189
|
-
* segment personalization groups, and is skipped entirely when there are
|
|
190
|
-
* none, e.g. on pages with only A/B tests or no personalization.
|
|
191
|
-
*/
|
|
192
|
-
from?: unknown;
|
|
193
|
-
}
|
|
194
|
-
interface PreprQueryResult<TResult> {
|
|
195
|
-
data: TResult;
|
|
196
|
-
/**
|
|
197
|
-
* True when Prepr reports, through the response's `Vary` header, that the
|
|
198
|
-
* queried fields hold segment variants or A/B tests.
|
|
199
|
-
*/
|
|
200
|
-
personalized: boolean;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* The schema facts the query rewrites need, from `loadPreprSchema`. Pass it
|
|
205
|
-
* along; its shape is not part of the public API.
|
|
206
|
-
*/
|
|
207
|
-
type PreprSchema = PreprSchemaInfo;
|
|
208
|
-
/**
|
|
209
|
-
* Your query, asking for every personalization and A/B variant: what
|
|
210
|
-
* `query(..., { variants: true })` sends, as a string for your own GraphQL
|
|
211
|
-
* client. The result is the same for every visitor, so cache it like any
|
|
212
|
-
* other content query, and render it with `resolveVariants` or `PreprStack`.
|
|
213
|
-
*
|
|
214
|
-
* A query without personalizable fields comes back unchanged (minified).
|
|
215
|
-
*/
|
|
216
|
-
declare function toVariantsQuery(document: PreprDocument<unknown, unknown> | string, schema: PreprSchema): string;
|
|
217
|
-
/**
|
|
218
|
-
* The per-visitor decision query for the same query: send it with the
|
|
219
|
-
* visitor's Prepr headers, never cached, and pass the response's `data` to
|
|
220
|
-
* `decisionsFrom`.
|
|
221
|
-
*
|
|
222
|
-
* Pass the variants result as `from` whenever you have it: the query then
|
|
223
|
-
* asks only about the lists that hold segment groups on this page, which is
|
|
224
|
-
* a few hundred bytes instead of the whole page and markedly faster for a
|
|
225
|
-
* visitor Prepr has not seen before. Without `from` it asks about every
|
|
226
|
-
* personalizable list. `topLevelOnly` stops at the first personalizable list
|
|
227
|
-
* on each path, for middleware that decides only the top of a stack.
|
|
228
|
-
*
|
|
229
|
-
* Null when there is nothing to decide: send no request then.
|
|
230
|
-
*/
|
|
231
|
-
declare function toDecisionQuery(document: PreprDocument<unknown, unknown> | string, schema: PreprSchema, options?: {
|
|
232
|
-
from?: unknown;
|
|
233
|
-
topLevelOnly?: boolean;
|
|
234
|
-
}): string | null;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Tag for pages showing more items than fit in Next.js's tag limits. Every
|
|
238
|
-
* webhook event revalidates it, so those pages refresh on any change.
|
|
239
|
-
*/
|
|
240
|
-
declare const PREPR_ANY_ITEM_TAG = "prepr:any";
|
|
241
|
-
/**
|
|
242
|
-
* Cache tag for every page listing items of one model. `tagItems` adds it to
|
|
243
|
-
* list queries and to lookups that found nothing; add it yourself with
|
|
244
|
-
* `cacheTag()` for other pages that depend on which items exist.
|
|
245
|
-
* `createPreprWebhookRoute` revalidates it when an item of that model is
|
|
246
|
-
* published, unpublished or deleted.
|
|
247
|
-
*
|
|
248
|
-
* The name is compared case-insensitively and without spaces or
|
|
249
|
-
* punctuation, so the model's name in Prepr (`'Blog post'`, as webhooks send
|
|
250
|
-
* it) and its GraphQL type (`BlogPost`) give the same tag. A model whose API
|
|
251
|
-
* ID was renamed away from its name gets two different tags.
|
|
252
|
-
*
|
|
253
|
-
* @param model The model's singular name in Prepr or its GraphQL type name.
|
|
254
|
-
*/
|
|
255
|
-
declare const preprModelTag: (model: string) => string;
|
|
256
|
-
/**
|
|
257
|
-
* Cache tags for every Prepr item in a query result: `prepr:<_id>` for each
|
|
258
|
-
* object with a string `_id`, at any depth. Pair it with `cacheTag()` inside
|
|
259
|
-
* `'use cache'`, and a publish webhook revalidates only the pages that show
|
|
260
|
-
* the changed item. Run the query with `variants: true` so the tags cover
|
|
261
|
-
* every variant's items, not only those of one visitor.
|
|
262
|
-
*
|
|
263
|
-
* Next.js accepts at most 128 tags of 256 characters per `cacheTag()` call.
|
|
264
|
-
* A result past either limit returns `[PREPR_ANY_ITEM_TAG]` instead, which
|
|
265
|
-
* every webhook event revalidates.
|
|
266
|
-
*
|
|
267
|
-
* @param data A parsed JSON query result, such as `query()`'s `data`.
|
|
268
|
-
*/
|
|
269
|
-
declare function preprCacheTags(data: unknown): string[];
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Loads what `toVariantsQuery` and `toDecisionQuery` need to know about your
|
|
273
|
-
* Prepr schema (which fields take `personalize`, which types can hold
|
|
274
|
-
* variants) with one introspection request, kept in memory per URL. For a
|
|
275
|
-
* site that uses its own GraphQL client; `createPreprClient` does this
|
|
276
|
-
* itself.
|
|
277
|
-
*
|
|
278
|
-
* Load it once at startup or lazily before the first rewrite. Schema changes
|
|
279
|
-
* in Prepr take effect after a restart or redeploy.
|
|
280
|
-
*
|
|
281
|
-
* @throws PreprError when the URL is invalid or the request fails; the URL,
|
|
282
|
-
* which holds your access token, is never part of the message.
|
|
283
|
-
*/
|
|
284
|
-
declare function loadPreprSchema(url: string, options?: {
|
|
285
|
-
fetch?: typeof fetch;
|
|
286
|
-
}): Promise<PreprSchemaInfo>;
|
|
287
|
-
|
|
288
|
-
/** The query a page renders, as `createPreprProxy`'s `page` returns it. */
|
|
289
|
-
interface PreprProxyPage<TVariables = unknown> {
|
|
290
|
-
document: PreprDocument<unknown, TVariables>;
|
|
291
|
-
variables?: TVariables;
|
|
292
|
-
/**
|
|
293
|
-
* The decision query for `document`, built ahead of time (the codegen
|
|
294
|
-
* plugin's `<Name>DecisionQuery`). Sent as is, so the proxy never loads
|
|
295
|
-
* Prepr's schema to derive it; see `resolveDecisions`.
|
|
296
|
-
*/
|
|
297
|
-
decision?: PreprDocument<unknown, TVariables>;
|
|
298
|
-
}
|
|
299
|
-
interface PreprProxyOptions {
|
|
300
|
-
/** A client made with this package's Next `createPreprClient`. */
|
|
301
|
-
client: PreprNextClient;
|
|
302
|
-
/**
|
|
303
|
-
* The query the page at `url` renders with `variants: true`, or `null` for
|
|
304
|
-
* a URL that is not a CMS page. Sites that route every page through one
|
|
305
|
-
* query need one line:
|
|
306
|
-
* `(url) => ({ document: PageDocument, variables: { slug: url.pathname } })`.
|
|
307
|
-
*/
|
|
308
|
-
page: (url: URL) => PreprProxyPage<any> | null | undefined;
|
|
309
|
-
/** Whether this deployment serves preview content (draft mode, toolbar overrides). */
|
|
310
|
-
preview?: boolean;
|
|
311
|
-
/** Features disabled app-wide, as for `createPreprMiddleware`. */
|
|
312
|
-
features?: PreprFeatures;
|
|
313
|
-
/** Give up on Prepr after this many ms; the default variants show. Default 3000. */
|
|
314
|
-
timeoutMs?: number;
|
|
315
|
-
/**
|
|
316
|
-
* Skip Prepr for decision requests when this resolves to false, for example for
|
|
317
|
-
* crawlers, so they never wait for Prepr. Those requests get the default
|
|
318
|
-
* variants.
|
|
319
|
-
*/
|
|
320
|
-
onlyIf?: (request: NextRequest) => boolean | Promise<boolean>;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Everything Prepr needs in the proxy (`proxy.ts`), in one call: the visitor's
|
|
324
|
-
* Prepr headers and customer id (`createPreprMiddleware`), the draft-mode
|
|
325
|
-
* redirect in preview, and the answers to the browser's decision requests.
|
|
326
|
-
*
|
|
327
|
-
* Pages themselves never wait for Prepr: they are the same for every visitor
|
|
328
|
-
* and pass straight through. The browser sends a decision request for each
|
|
329
|
-
* page view, from the page load and when a visitor points at a link; the proxy
|
|
330
|
-
* answers it with the visitor's variant of every A/B test and personalization
|
|
331
|
-
* group on that page, asked from Prepr in one request, as text and no page.
|
|
332
|
-
* Add your own cookies or headers to the response it returns.
|
|
333
|
-
*
|
|
334
|
-
* @example
|
|
335
|
-
* const handlePrepr = createPreprProxy({
|
|
336
|
-
* client: prepr,
|
|
337
|
-
* page: (url) => ({ document: PageDocument, variables: { slug: url.pathname } }),
|
|
338
|
-
* preview: process.env.PREPR_ENV === 'preview',
|
|
339
|
-
* });
|
|
340
|
-
* export function proxy(request: NextRequest) {
|
|
341
|
-
* return handlePrepr(request);
|
|
342
|
-
* }
|
|
343
|
-
*
|
|
344
|
-
* @throws PreprError `CONTEXT_ERROR` when `client` was not made by the Next
|
|
345
|
-
* `createPreprClient`.
|
|
346
|
-
*/
|
|
347
|
-
declare function createPreprProxy(options: PreprProxyOptions): (request: NextRequest) => Promise<NextResponse>;
|
|
348
|
-
|
|
349
|
-
interface PreprStackProps<T> {
|
|
350
|
-
/** A stack (e.g. `page.content`) from a query run with `variants: true`. */
|
|
351
|
-
items: readonly T[];
|
|
352
|
-
/**
|
|
353
|
-
* Renders resolved stack items, e.g. your section switch. `index` is the
|
|
354
|
-
* position of the block's first item in the whole stack, for anything that
|
|
355
|
-
* depends on page position, such as which section owns the h1 or the
|
|
356
|
-
* priority image.
|
|
357
|
-
*
|
|
358
|
-
* `defaultVariant` is false for the variants that are in the page but
|
|
359
|
-
* hidden unless the visitor gets them: the other buckets of an A/B test and
|
|
360
|
-
* the segment variants. Give only the default variant `priority` images,
|
|
361
|
-
* and the others `loading="lazy"`: the browser downloads a hidden eager
|
|
362
|
-
* image anyway, but skips a hidden lazy one.
|
|
363
|
-
*/
|
|
364
|
-
render: (items: T[], position: {
|
|
365
|
-
index: number;
|
|
366
|
-
defaultVariant: boolean;
|
|
367
|
-
}) => ReactNode;
|
|
368
|
-
/**
|
|
369
|
-
* The visitor's A/B bucket, when the route already knows it (for example
|
|
370
|
-
* from a URL segment): A/B tests then render that bucket only. Leave it out
|
|
371
|
-
* to render both variants, and let this page view's decision pick the
|
|
372
|
-
* visitor's, like a segment group's.
|
|
373
|
-
*/
|
|
374
|
-
bucket?: string;
|
|
375
|
-
/** Nonce for the inline scripts, under a strict CSP. */
|
|
376
|
-
nonce?: string;
|
|
377
|
-
/**
|
|
378
|
-
* Tag each personalization and A/B variant for Prepr's tracking pixel, so
|
|
379
|
-
* it counts impressions (and clicks on `data-prepr-variant-event` elements
|
|
380
|
-
* inside) without `data-prepr-variant-key` in your components. Default
|
|
381
|
-
* `false`.
|
|
382
|
-
*
|
|
383
|
-
* Each item's key goes on the element `render` returns for it, in order,
|
|
384
|
-
* once the page has hydrated. Each variant gets a wrapper with
|
|
385
|
-
* `display: contents`: it takes no box, but CSS child combinators (`>`) and
|
|
386
|
-
* `:first-child` from the stack's parent no longer reach the sections. A
|
|
387
|
-
* section holding a personalized list gets the key of the variant it shows.
|
|
388
|
-
* Only the shown variant is tagged, once it shows: the pixel counts any
|
|
389
|
-
* tagged element in view, invisible or not.
|
|
390
|
-
*/
|
|
391
|
-
trackVariants?: boolean;
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Renders a personalized stack, entirely in the prerendered page.
|
|
395
|
-
*
|
|
396
|
-
* - Items that never vary render as they are.
|
|
397
|
-
* - Every A/B test and segment personalization group, at the top of the
|
|
398
|
-
* stack or nested inside an item, renders every variant, hidden. The page
|
|
399
|
-
* is the same for every visitor and never waits for Prepr: an inline script
|
|
400
|
-
* asks `createPreprProxy` for this page view's decision while the page
|
|
401
|
-
* loads, and shows the visitor's variant when it answers.
|
|
402
|
-
* `PreprPersonalizationSwitch` asks for a link's decision on hover, so it
|
|
403
|
-
* is mostly in before the next page paints. Nothing streams, and the
|
|
404
|
-
* default variant never shows first to be replaced.
|
|
405
|
-
*
|
|
406
|
-
* The page carries the HTML of every variant: an item with nested groups
|
|
407
|
-
* repeats once per combination of their variants.
|
|
408
|
-
*
|
|
409
|
-
* @example
|
|
410
|
-
* const data = await getPage(slug); // 'use cache' + query(..., { variants: true })
|
|
411
|
-
* <PreprStack
|
|
412
|
-
* items={data.Page.content}
|
|
413
|
-
* render={(items, { index }) => <Sections sections={items} offset={index} />}
|
|
414
|
-
* />
|
|
415
|
-
*/
|
|
416
|
-
declare function PreprStack<T>({ items, render, bucket, nonce, trackVariants, }: PreprStackProps<T>): ReactElement;
|
|
417
|
-
|
|
418
|
-
interface PreprNextClientOptions extends PreprClientOptions {
|
|
419
|
-
/** Tags set on every cacheable fetch, for `revalidateTag`. Default `['prepr']`. */
|
|
420
|
-
cacheTags?: string[];
|
|
421
|
-
/**
|
|
422
|
-
* `next.revalidate` for cacheable fetches. Unset leaves the installed Next
|
|
423
|
-
* version's default in place. `false` caches until `revalidateTag` runs,
|
|
424
|
-
* which suits a publish webhook calling `revalidateTag('prepr')`.
|
|
425
|
-
*/
|
|
426
|
-
revalidate?: number | false;
|
|
427
|
-
}
|
|
428
|
-
interface PreprNextQueryOptions extends PreprQueryOptions {
|
|
429
|
-
/**
|
|
430
|
-
* Forward the visitor's Prepr headers (read through `next/headers`) and
|
|
431
|
-
* skip the Data Cache. The route renders per request.
|
|
432
|
-
*/
|
|
433
|
-
personalize?: boolean;
|
|
434
|
-
/**
|
|
435
|
-
* Inside `'use cache'` (Cache Components, Next 16+): tags the cache entry
|
|
436
|
-
* with `preprCacheTags(data)` and the client's `cacheTags`, so
|
|
437
|
-
* `createPreprWebhookRoute` revalidates exactly the pages showing a changed
|
|
438
|
-
* item. List queries and lookups that found nothing also get their
|
|
439
|
-
* model's `preprModelTag`, so publishing a new item refreshes them. Pair it
|
|
440
|
-
* with `variants: true`, whose result holds every variant's items.
|
|
441
|
-
*
|
|
442
|
-
* The fetch then skips the Data Cache: a Data Cache entry carries only the
|
|
443
|
-
* client's `cacheTags`, so revalidating an item tag would re-run the
|
|
444
|
-
* `'use cache'` function against the stale response.
|
|
445
|
-
*
|
|
446
|
-
* @throws Error — from Next.js when called outside a `'use cache'` function.
|
|
447
|
-
*/
|
|
448
|
-
tagItems?: boolean;
|
|
449
|
-
}
|
|
450
|
-
interface PreprNextClient {
|
|
451
|
-
/**
|
|
452
|
-
* Run a GraphQL query against Prepr.
|
|
453
|
-
*
|
|
454
|
-
* Without `personalize`, the fetch is tagged for `revalidateTag` and may be
|
|
455
|
-
* served from the Data Cache. Do not swallow errors thrown here without
|
|
456
|
-
* `unstable_rethrow`: Next.js signals dynamic rendering by throwing from
|
|
457
|
-
* inside fetch, and the client passes those signals through untouched.
|
|
458
|
-
*
|
|
459
|
-
* @throws PreprError — `INVALID_DOCUMENT`, `FETCH_ERROR`, `HTTP_ERROR`,
|
|
460
|
-
* `INVALID_RESPONSE` or `GRAPHQL_ERROR`.
|
|
461
|
-
*/
|
|
462
|
-
query<TResult, TVariables>(document: PreprDocument<TResult, TVariables>, variables?: TVariables, options?: PreprNextQueryOptions): Promise<PreprQueryResult<TResult>>;
|
|
463
|
-
/**
|
|
464
|
-
* Which variant of each personalization and A/B group this visitor gets,
|
|
465
|
-
* for the query you render with `variants: true`. Forwards the visitor's
|
|
466
|
-
* Prepr headers (read through `next/headers`); never cached. Prepr decides
|
|
467
|
-
* from everything the middleware forwards: customer profile, UTM
|
|
468
|
-
* parameters, visitor IP, HubSpot id.
|
|
469
|
-
*
|
|
470
|
-
* For rendering variants yourself with `resolveVariants`. `PreprStack`
|
|
471
|
-
* does not need it: `createPreprProxy` decides every page view.
|
|
472
|
-
*/
|
|
473
|
-
decide<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: PreprDecideOptions): Promise<PreprDecisions>;
|
|
474
|
-
/**
|
|
475
|
-
* Whether the query's result holds an A/B test. Never reads request
|
|
476
|
-
* headers, so it also works in middleware.
|
|
477
|
-
*/
|
|
478
|
-
hasAbTests<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Prepr GraphQL client for Next.js (App Router, server only).
|
|
482
|
-
*
|
|
483
|
-
* Headerless queries go through the Data Cache with `cacheTags`; queries with
|
|
484
|
-
* `personalize: true` forward the visitor's Prepr headers and are never
|
|
485
|
-
* cached.
|
|
486
|
-
*
|
|
487
|
-
* With Cache Components, run headerless queries inside `'use cache'` (the
|
|
488
|
-
* client's fetch tags carry over to the entry, so `revalidateTag` reaches it)
|
|
489
|
-
* and `personalize: true` queries inside `<Suspense>`: `personalize` reads
|
|
490
|
-
* request headers, which `'use cache'` forbids. A headerless query outside
|
|
491
|
-
* both only prerenders when `revalidate` is set. `preview: true` works inside `'use cache'`, but the entry is still
|
|
492
|
-
* cached unless draft mode is enabled, which makes Next skip cached entries.
|
|
493
|
-
*
|
|
494
|
-
* Requires the `graphql` package, which graphql-codegen already installs.
|
|
495
|
-
*/
|
|
496
|
-
declare function createPreprClient(options: PreprNextClientOptions): PreprNextClient;
|
|
497
|
-
|
|
498
|
-
export { PREPR_ANY_ITEM_TAG, PREPR_DEFAULT_VARIANT, type PreprDecideOptions, type PreprDecisions, type PreprDocument, type PreprNextClient, type PreprNextClientOptions, type PreprNextQueryOptions, type PreprProxyOptions, type PreprProxyPage, type PreprQueryResult, type PreprSchema, PreprStack, type PreprStackBlock, type PreprStackProps, type PreprStegaMode, type PreprVariantProps, type ResolveVariantsOptions, createPreprClient, createPreprProxy, decisionsFrom, loadPreprSchema, preprCacheTags, preprModelTag, preprVariantProps, resolveVariants, splitStack, toDecisionQuery, toVariantsQuery };
|