@preprio/toolkit 0.6.0-alpha.0 → 0.6.0-alpha.10
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 +268 -59
- package/dist/astro/{chunk-3UVUDDNY.js → chunk-CG2QBHNU.js} +1 -1
- package/dist/astro/graphql.cjs +154 -59
- package/dist/astro/graphql.d.cts +75 -6
- package/dist/astro/graphql.d.ts +75 -6
- package/dist/astro/graphql.js +150 -59
- package/dist/astro/index.cjs +1 -1
- package/dist/astro/index.js +1 -1
- package/dist/chunk-3NCEVJJ3.js +10 -0
- package/dist/{chunk-BJ2LBLWO.js → chunk-LIDUJWWJ.js} +6 -4
- package/dist/chunk-M3RBYJ5J.js +499 -0
- package/dist/{chunk-DGZA7KX7.js → chunk-S5RWVMDJ.js} +0 -24
- package/dist/{chunk-YR7P4IWE.js → chunk-SF6TN4JR.js} +1 -9
- package/dist/chunk-TN6SNAR2.js +26 -0
- package/dist/graphql/codegen.cjs +557 -0
- package/dist/graphql/codegen.d.cts +23 -0
- package/dist/graphql/codegen.d.ts +23 -0
- package/dist/graphql/codegen.js +99 -0
- package/dist/graphql.cjs +185 -59
- package/dist/graphql.d.cts +110 -6
- package/dist/graphql.d.ts +110 -6
- package/dist/graphql.js +91 -430
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -6
- package/dist/nextjs/chunk-B4GVZEOL.js +549 -0
- package/dist/nextjs/components.cjs +297 -81
- package/dist/nextjs/components.d.cts +26 -11
- package/dist/nextjs/components.d.ts +26 -11
- package/dist/nextjs/components.js +289 -73
- package/dist/nextjs/graphql.cjs +952 -315
- package/dist/nextjs/graphql.d.cts +225 -83
- package/dist/nextjs/graphql.d.ts +225 -83
- package/dist/nextjs/graphql.js +634 -314
- package/dist/nextjs/index.cjs +116 -54
- package/dist/nextjs/index.d.cts +61 -23
- package/dist/nextjs/index.d.ts +61 -23
- package/dist/nextjs/index.js +97 -299
- package/dist/nextjs/{server-CjpELYvq.d.ts → server-BL-sqZvu.d.cts} +1 -1
- package/dist/nextjs/{server-CjpELYvq.d.cts → server-BL-sqZvu.d.ts} +1 -1
- package/dist/nuxt/{chunk-P6ENNAEE.js → chunk-FMC3DP7N.js} +1 -1
- package/dist/nuxt/graphql.cjs +154 -59
- package/dist/nuxt/graphql.d.cts +75 -6
- package/dist/nuxt/graphql.d.ts +75 -6
- package/dist/nuxt/graphql.js +150 -59
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/react/components.cjs +1 -1
- package/dist/react/components.js +1 -1
- package/dist/sveltekit/{chunk-FSARVMG5.js → chunk-AJPKBAHO.js} +1 -1
- package/dist/sveltekit/graphql.cjs +154 -59
- package/dist/sveltekit/graphql.d.cts +75 -6
- package/dist/sveltekit/graphql.d.ts +75 -6
- package/dist/sveltekit/graphql.js +150 -59
- package/dist/sveltekit/index.cjs +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/package.json +6 -1
- package/dist/nextjs/chunk-U4HXENF7.js +0 -231
package/dist/nextjs/graphql.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
1
|
import { DocumentNode } from 'graphql';
|
|
3
|
-
import { P as PreprHeaders } from './server-
|
|
4
|
-
export {
|
|
2
|
+
import { P as PreprHeaders, a as PreprFeatures } from './server-BL-sqZvu.js';
|
|
3
|
+
export { b as PreprError, i as isPersonalizedResponse } from './server-BL-sqZvu.js';
|
|
4
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
5
5
|
import { ReactNode, ReactElement } from 'react';
|
|
6
6
|
|
|
7
7
|
/** Prepr's variant id for visitors outside every targeted segment. */
|
|
@@ -9,6 +9,12 @@ declare const PREPR_DEFAULT_VARIANT = "ALL_OTHER_USERS";
|
|
|
9
9
|
|
|
10
10
|
/** The variant ids Prepr chose for one visitor, per personalization group. */
|
|
11
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;
|
|
12
18
|
interface ResolveVariantsOptions {
|
|
13
19
|
/**
|
|
14
20
|
* The visitor's per-group variants (from a decision query). Without it,
|
|
@@ -25,6 +31,24 @@ interface ResolveVariantsOptions {
|
|
|
25
31
|
*/
|
|
26
32
|
declare function resolveVariants<T>(data: T, options?: ResolveVariantsOptions): T;
|
|
27
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
|
+
|
|
28
52
|
/** A run of stack items that renders the same way: see {@link splitStack}. */
|
|
29
53
|
interface PreprStackBlock<T> {
|
|
30
54
|
key: string;
|
|
@@ -166,11 +190,6 @@ interface PreprDecideOptions extends Omit<PreprQueryOptions, 'variants'> {
|
|
|
166
190
|
* none, e.g. on pages with only A/B tests or no personalization.
|
|
167
191
|
*/
|
|
168
192
|
from?: unknown;
|
|
169
|
-
/**
|
|
170
|
-
* @internal Ask only about the first personalizable list on each path,
|
|
171
|
-
* without `from`: what middleware needs for groups at the top of a stack.
|
|
172
|
-
*/
|
|
173
|
-
topLevelOnly?: boolean;
|
|
174
193
|
}
|
|
175
194
|
interface PreprQueryResult<TResult> {
|
|
176
195
|
data: TResult;
|
|
@@ -181,40 +200,184 @@ interface PreprQueryResult<TResult> {
|
|
|
181
200
|
personalized: boolean;
|
|
182
201
|
}
|
|
183
202
|
|
|
184
|
-
/**
|
|
185
|
-
|
|
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
|
+
/**
|
|
314
|
+
* Give up on Prepr after this many ms; the default variants show. A page
|
|
315
|
+
* load the proxy decides waits for this at most. Default 1000.
|
|
316
|
+
*/
|
|
317
|
+
timeoutMs?: number;
|
|
318
|
+
/**
|
|
319
|
+
* Skip Prepr for decision requests when this resolves to false, for example for
|
|
320
|
+
* crawlers, so they never wait for Prepr. Those requests get the default
|
|
321
|
+
* variants.
|
|
322
|
+
*/
|
|
323
|
+
onlyIf?: (request: NextRequest) => boolean | Promise<boolean>;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Everything Prepr needs in the proxy (`proxy.ts`), in one call: the visitor's
|
|
327
|
+
* Prepr headers and customer id (`createPreprMiddleware`), the draft-mode
|
|
328
|
+
* redirect in preview, and the answers to the browser's decision requests.
|
|
329
|
+
*
|
|
330
|
+
* A page load the visitor has no recent decision for is decided here, in one
|
|
331
|
+
* Prepr request for every A/B test and personalization group on the page,
|
|
332
|
+
* at most `timeoutMs`; the decision goes to the browser in a cookie, so the
|
|
333
|
+
* personalized sections paint with the visitor's variant. Every other page
|
|
334
|
+
* load passes straight through: the cookie already holds its decision, or
|
|
335
|
+
* the page has no personalization. The proxy also answers the decision
|
|
336
|
+
* requests the browser sends when a visitor points at a link, as text and no
|
|
337
|
+
* page. Add your own cookies or headers to the response it returns.
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* const handlePrepr = createPreprProxy({
|
|
341
|
+
* client: prepr,
|
|
342
|
+
* page: (url) => ({ document: PageDocument, variables: { slug: url.pathname } }),
|
|
343
|
+
* preview: process.env.PREPR_ENV === 'preview',
|
|
344
|
+
* });
|
|
345
|
+
* export function proxy(request: NextRequest) {
|
|
346
|
+
* return handlePrepr(request);
|
|
347
|
+
* }
|
|
348
|
+
*
|
|
349
|
+
* @throws PreprError `CONTEXT_ERROR` when `client` was not made by the Next
|
|
350
|
+
* `createPreprClient`.
|
|
351
|
+
*/
|
|
352
|
+
declare function createPreprProxy(options: PreprProxyOptions): (request: NextRequest) => Promise<NextResponse>;
|
|
186
353
|
|
|
187
354
|
interface PreprStackProps<T> {
|
|
188
355
|
/** A stack (e.g. `page.content`) from a query run with `variants: true`. */
|
|
189
356
|
items: readonly T[];
|
|
190
|
-
/**
|
|
191
|
-
* The visitor's decisions, as a promise from `decide()`. Only the parts
|
|
192
|
-
* that vary per segment wait for it; a failed decision falls back to the
|
|
193
|
-
* default variants instead of failing the page.
|
|
194
|
-
*/
|
|
195
|
-
decisions: Promise<PreprDecisions>;
|
|
196
357
|
/**
|
|
197
358
|
* Renders resolved stack items, e.g. your section switch. `index` is the
|
|
198
359
|
* position of the block's first item in the whole stack, for anything that
|
|
199
360
|
* depends on page position, such as which section owns the h1 or the
|
|
200
361
|
* priority image.
|
|
201
362
|
*
|
|
202
|
-
* `
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
363
|
+
* `defaultVariant` is false for the variants that are in the page but
|
|
364
|
+
* hidden unless the visitor gets them: the other buckets of an A/B test and
|
|
365
|
+
* the segment variants. Give only the default variant `priority` images,
|
|
366
|
+
* and the others `loading="lazy"`: the browser downloads a hidden eager
|
|
367
|
+
* image anyway, but skips a hidden lazy one.
|
|
206
368
|
*/
|
|
207
369
|
render: (items: T[], position: {
|
|
208
370
|
index: number;
|
|
209
|
-
|
|
371
|
+
defaultVariant: boolean;
|
|
210
372
|
}) => ReactNode;
|
|
211
373
|
/**
|
|
212
374
|
* The visitor's A/B bucket, when the route already knows it (for example
|
|
213
|
-
* from a URL segment)
|
|
214
|
-
*
|
|
375
|
+
* from a URL segment): A/B tests then render that bucket only. Leave it out
|
|
376
|
+
* to render both variants, and let this page view's decision pick the
|
|
377
|
+
* visitor's, like a segment group's.
|
|
215
378
|
*/
|
|
216
379
|
bucket?: string;
|
|
217
|
-
/** Nonce for the inline
|
|
380
|
+
/** Nonce for the inline scripts, under a strict CSP. */
|
|
218
381
|
nonce?: string;
|
|
219
382
|
/**
|
|
220
383
|
* Tag each personalization and A/B variant for Prepr's tracking pixel, so
|
|
@@ -225,46 +388,37 @@ interface PreprStackProps<T> {
|
|
|
225
388
|
* Each item's key goes on the element `render` returns for it, in order,
|
|
226
389
|
* once the page has hydrated. Each variant gets a wrapper with
|
|
227
390
|
* `display: contents`: it takes no box, but CSS child combinators (`>`) and
|
|
228
|
-
* `:first-child` from the stack's parent no longer reach the sections.
|
|
229
|
-
*
|
|
391
|
+
* `:first-child` from the stack's parent no longer reach the sections. A
|
|
392
|
+
* section holding a personalized list gets the key of the variant it shows.
|
|
393
|
+
* Only the shown variant is tagged, once it shows: the pixel counts any
|
|
394
|
+
* tagged element in view, invisible or not.
|
|
230
395
|
*/
|
|
231
396
|
trackVariants?: boolean;
|
|
232
|
-
/**
|
|
233
|
-
* How many blocks, from the top, are on screen before the visitor scrolls.
|
|
234
|
-
* Default `0`.
|
|
235
|
-
*
|
|
236
|
-
* Their segment groups do not stream: every variant is in the cached page,
|
|
237
|
-
* and the variant the proxy decided (`prepr.resolveDecisions`) shows before
|
|
238
|
-
* first paint, so nothing on screen changes while the page loads. Without
|
|
239
|
-
* a decision (no cookie yet, or the proxy's lookup failed) the default
|
|
240
|
-
* variant shows. Costs the HTML of the other variants; images in them still
|
|
241
|
-
* download. An item with a segment group nested inside it keeps streaming.
|
|
242
|
-
*/
|
|
243
|
-
aboveTheFold?: number;
|
|
244
397
|
}
|
|
245
398
|
/**
|
|
246
|
-
* Renders a personalized stack
|
|
399
|
+
* Renders a personalized stack, entirely in the prerendered page.
|
|
247
400
|
*
|
|
248
|
-
* - Items that never vary render
|
|
249
|
-
* - A/B
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
401
|
+
* - Items that never vary render as they are.
|
|
402
|
+
* - Every A/B test and segment personalization group, at the top of the
|
|
403
|
+
* stack or nested inside an item, renders every variant, hidden. The page
|
|
404
|
+
* is the same for every visitor and never waits for Prepr: an inline script
|
|
405
|
+
* asks `createPreprProxy` for this page view's decision while the page
|
|
406
|
+
* loads, and shows the visitor's variant when it answers.
|
|
407
|
+
* `PreprPersonalizationSwitch` asks for a link's decision on hover, so it
|
|
408
|
+
* is mostly in before the next page paints. Nothing streams, and the
|
|
409
|
+
* default variant never shows first to be replaced.
|
|
410
|
+
*
|
|
411
|
+
* The page carries the HTML of every variant: an item with nested groups
|
|
412
|
+
* repeats once per combination of their variants.
|
|
258
413
|
*
|
|
259
414
|
* @example
|
|
260
415
|
* const data = await getPage(slug); // 'use cache' + query(..., { variants: true })
|
|
261
416
|
* <PreprStack
|
|
262
417
|
* items={data.Page.content}
|
|
263
|
-
* decisions={prepr.decide(PageDocument, { slug }, { from: data })}
|
|
264
418
|
* render={(items, { index }) => <Sections sections={items} offset={index} />}
|
|
265
419
|
* />
|
|
266
420
|
*/
|
|
267
|
-
declare function PreprStack<T>({ items,
|
|
421
|
+
declare function PreprStack<T>({ items, render, bucket, nonce, trackVariants, }: PreprStackProps<T>): ReactElement;
|
|
268
422
|
|
|
269
423
|
interface PreprNextClientOptions extends PreprClientOptions {
|
|
270
424
|
/** Tags set on every cacheable fetch, for `revalidateTag`. Default `['prepr']`. */
|
|
@@ -282,6 +436,21 @@ interface PreprNextQueryOptions extends PreprQueryOptions {
|
|
|
282
436
|
* skip the Data Cache. The route renders per request.
|
|
283
437
|
*/
|
|
284
438
|
personalize?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Inside `'use cache'` (Cache Components, Next 16+): tags the cache entry
|
|
441
|
+
* with `preprCacheTags(data)` and the client's `cacheTags`, so
|
|
442
|
+
* `createPreprWebhookRoute` revalidates exactly the pages showing a changed
|
|
443
|
+
* item. List queries and lookups that found nothing also get their
|
|
444
|
+
* model's `preprModelTag`, so publishing a new item refreshes them. Pair it
|
|
445
|
+
* with `variants: true`, whose result holds every variant's items.
|
|
446
|
+
*
|
|
447
|
+
* The fetch then skips the Data Cache: a Data Cache entry carries only the
|
|
448
|
+
* client's `cacheTags`, so revalidating an item tag would re-run the
|
|
449
|
+
* `'use cache'` function against the stale response.
|
|
450
|
+
*
|
|
451
|
+
* @throws Error — from Next.js when called outside a `'use cache'` function.
|
|
452
|
+
*/
|
|
453
|
+
tagItems?: boolean;
|
|
285
454
|
}
|
|
286
455
|
interface PreprNextClient {
|
|
287
456
|
/**
|
|
@@ -303,42 +472,15 @@ interface PreprNextClient {
|
|
|
303
472
|
* from everything the middleware forwards: customer profile, UTM
|
|
304
473
|
* parameters, visitor IP, HubSpot id.
|
|
305
474
|
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
475
|
+
* For rendering variants yourself with `resolveVariants`. `PreprStack`
|
|
476
|
+
* does not need it: `createPreprProxy` decides every page view.
|
|
308
477
|
*/
|
|
309
478
|
decide<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: PreprDecideOptions): Promise<PreprDecisions>;
|
|
310
479
|
/**
|
|
311
|
-
* Whether the query's result holds an A/B test
|
|
312
|
-
*
|
|
480
|
+
* Whether the query's result holds an A/B test. Never reads request
|
|
481
|
+
* headers, so it also works in middleware.
|
|
313
482
|
*/
|
|
314
483
|
hasAbTests<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
|
|
315
|
-
/**
|
|
316
|
-
* In middleware (`proxy.ts`): asks Prepr which segment variant this visitor
|
|
317
|
-
* gets for each personalization group on the page, and stores the answer in
|
|
318
|
-
* the `prepr_decisions` cookie on `response`. `PreprStack` with
|
|
319
|
-
* `aboveTheFold` then shows those variants before first paint instead of
|
|
320
|
-
* streaming them in.
|
|
321
|
-
*
|
|
322
|
-
* Call it after `createPreprMiddleware`, whose visitor headers (customer id,
|
|
323
|
-
* UTM parameters, IP, HubSpot id) it forwards. A decision is an uncached
|
|
324
|
-
* Prepr request, made once per visit by default (see `reuse`); limit it
|
|
325
|
-
* with `onlyIf` to pages whose personalized content is above the fold.
|
|
326
|
-
* Pages without segment groups are skipped after a cached check. Never throws and gives up after `timeoutMs`
|
|
327
|
-
* (default 1000): the default variant shows instead.
|
|
328
|
-
*/
|
|
329
|
-
resolveDecisions<TVariables>(request: NextRequest, response: NextResponse, document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: {
|
|
330
|
-
timeoutMs?: number;
|
|
331
|
-
/**
|
|
332
|
-
* Reuse the stored decision for the rest of the visit instead of asking
|
|
333
|
-
* Prepr on every page view. Default `true`. Asks again when UTM
|
|
334
|
-
* parameters arrive, on a first visit, and when preview forces a
|
|
335
|
-
* segment. A visitor who joins a segment mid-visit (say, by submitting
|
|
336
|
-
* a form) sees the change from their next asked request.
|
|
337
|
-
*/
|
|
338
|
-
reuse?: boolean;
|
|
339
|
-
/** Skip the decision when this resolves to false, e.g. for pages without a personalized hero. */
|
|
340
|
-
onlyIf?: () => boolean | Promise<boolean>;
|
|
341
|
-
}): Promise<void>;
|
|
342
484
|
}
|
|
343
485
|
/**
|
|
344
486
|
* Prepr GraphQL client for Next.js (App Router, server only).
|
|
@@ -358,4 +500,4 @@ interface PreprNextClient {
|
|
|
358
500
|
*/
|
|
359
501
|
declare function createPreprClient(options: PreprNextClientOptions): PreprNextClient;
|
|
360
502
|
|
|
361
|
-
export {
|
|
503
|
+
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 };
|