@preprio/toolkit 0.6.0-alpha.1 → 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 +163 -61
- package/dist/astro/{chunk-O7N6GPAH.js → chunk-CG2QBHNU.js} +1 -1
- package/dist/astro/graphql.cjs +58 -10
- package/dist/astro/graphql.d.cts +33 -38
- package/dist/astro/graphql.d.ts +33 -38
- package/dist/astro/graphql.js +59 -11
- package/dist/astro/index.cjs +1 -1
- package/dist/astro/index.js +1 -1
- package/dist/{chunk-VI6QZTBM.js → chunk-LIDUJWWJ.js} +1 -1
- package/dist/{chunk-TBKSBXGH.js → chunk-M3RBYJ5J.js} +52 -5
- package/dist/{chunk-3JLWZQ37.js → chunk-SF6TN4JR.js} +1 -1
- package/dist/{chunk-YWIKKWBR.js → chunk-TN6SNAR2.js} +1 -1
- package/dist/graphql/codegen.cjs +51 -4
- package/dist/graphql/codegen.js +3 -3
- package/dist/graphql.cjs +89 -10
- package/dist/graphql.d.cts +69 -39
- package/dist/graphql.d.ts +69 -39
- package/dist/graphql.js +38 -9
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- 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 +288 -73
- package/dist/nextjs/graphql.cjs +856 -266
- package/dist/nextjs/graphql.d.cts +184 -116
- package/dist/nextjs/graphql.d.ts +184 -116
- package/dist/nextjs/graphql.js +543 -266
- 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-IQDSBPDN.js → chunk-FMC3DP7N.js} +1 -1
- package/dist/nuxt/graphql.cjs +58 -10
- package/dist/nuxt/graphql.d.cts +33 -38
- package/dist/nuxt/graphql.d.ts +33 -38
- package/dist/nuxt/graphql.js +59 -11
- 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-OKYZ6HPH.js → chunk-AJPKBAHO.js} +1 -1
- package/dist/sveltekit/graphql.cjs +58 -10
- package/dist/sveltekit/graphql.d.cts +33 -38
- package/dist/sveltekit/graphql.d.ts +33 -38
- package/dist/sveltekit/graphql.js +59 -11
- package/dist/sveltekit/index.cjs +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/package.json +1 -1
- package/dist/nextjs/chunk-BQ6IGSH6.js +0 -231
|
@@ -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.cjs';
|
|
3
|
+
export { b as PreprError, i as isPersonalizedResponse } from './server-BL-sqZvu.cjs';
|
|
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. */
|
|
@@ -97,39 +97,6 @@ interface PreprVariantProps {
|
|
|
97
97
|
*/
|
|
98
98
|
declare function preprVariantProps(item: unknown): PreprVariantProps;
|
|
99
99
|
|
|
100
|
-
/**
|
|
101
|
-
* The schema facts the query rewrites need, from `loadPreprSchema`. Pass it
|
|
102
|
-
* along; its shape is not part of the public API.
|
|
103
|
-
*/
|
|
104
|
-
type PreprSchema = PreprSchemaInfo;
|
|
105
|
-
/**
|
|
106
|
-
* Your query, asking for every personalization and A/B variant: what
|
|
107
|
-
* `query(..., { variants: true })` sends, as a string for your own GraphQL
|
|
108
|
-
* client. The result is the same for every visitor, so cache it like any
|
|
109
|
-
* other content query, and render it with `resolveVariants` or `PreprStack`.
|
|
110
|
-
*
|
|
111
|
-
* A query without personalizable fields comes back unchanged (minified).
|
|
112
|
-
*/
|
|
113
|
-
declare function toVariantsQuery(document: PreprDocument<unknown, unknown> | string, schema: PreprSchema): string;
|
|
114
|
-
/**
|
|
115
|
-
* The per-visitor decision query for the same query: send it with the
|
|
116
|
-
* visitor's Prepr headers, never cached, and pass the response's `data` to
|
|
117
|
-
* `decisionsFrom`.
|
|
118
|
-
*
|
|
119
|
-
* Pass the variants result as `from` whenever you have it: the query then
|
|
120
|
-
* asks only about the lists that hold segment groups on this page, which is
|
|
121
|
-
* a few hundred bytes instead of the whole page and markedly faster for a
|
|
122
|
-
* visitor Prepr has not seen before. Without `from` it asks about every
|
|
123
|
-
* personalizable list. `topLevelOnly` stops at the first personalizable list
|
|
124
|
-
* on each path, for middleware that decides only the top of a stack.
|
|
125
|
-
*
|
|
126
|
-
* Null when there is nothing to decide: send no request then.
|
|
127
|
-
*/
|
|
128
|
-
declare function toDecisionQuery(document: PreprDocument<unknown, unknown> | string, schema: PreprSchema, options?: {
|
|
129
|
-
from?: unknown;
|
|
130
|
-
topLevelOnly?: boolean;
|
|
131
|
-
}): string | null;
|
|
132
|
-
|
|
133
100
|
/**
|
|
134
101
|
* A GraphQL document accepted by `query`: a plain string, graphql-codegen's
|
|
135
102
|
* `TypedDocumentString` (`documentMode: 'string'`), or any `DocumentNode`,
|
|
@@ -223,11 +190,6 @@ interface PreprDecideOptions extends Omit<PreprQueryOptions, 'variants'> {
|
|
|
223
190
|
* none, e.g. on pages with only A/B tests or no personalization.
|
|
224
191
|
*/
|
|
225
192
|
from?: unknown;
|
|
226
|
-
/**
|
|
227
|
-
* @internal Ask only about the first personalizable list on each path,
|
|
228
|
-
* without `from`: what middleware needs for groups at the top of a stack.
|
|
229
|
-
*/
|
|
230
|
-
topLevelOnly?: boolean;
|
|
231
193
|
}
|
|
232
194
|
interface PreprQueryResult<TResult> {
|
|
233
195
|
data: TResult;
|
|
@@ -238,6 +200,74 @@ interface PreprQueryResult<TResult> {
|
|
|
238
200
|
personalized: boolean;
|
|
239
201
|
}
|
|
240
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
|
+
|
|
241
271
|
/**
|
|
242
272
|
* Loads what `toVariantsQuery` and `toDecisionQuery` need to know about your
|
|
243
273
|
* Prepr schema (which fields take `personalize`, which types can hold
|
|
@@ -255,40 +285,99 @@ declare function loadPreprSchema(url: string, options?: {
|
|
|
255
285
|
fetch?: typeof fetch;
|
|
256
286
|
}): Promise<PreprSchemaInfo>;
|
|
257
287
|
|
|
258
|
-
/** The
|
|
259
|
-
|
|
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>;
|
|
260
353
|
|
|
261
354
|
interface PreprStackProps<T> {
|
|
262
355
|
/** A stack (e.g. `page.content`) from a query run with `variants: true`. */
|
|
263
356
|
items: readonly T[];
|
|
264
|
-
/**
|
|
265
|
-
* The visitor's decisions, as a promise from `decide()`. Only the parts
|
|
266
|
-
* that vary per segment wait for it; a failed decision falls back to the
|
|
267
|
-
* default variants instead of failing the page.
|
|
268
|
-
*/
|
|
269
|
-
decisions: Promise<PreprDecisions>;
|
|
270
357
|
/**
|
|
271
358
|
* Renders resolved stack items, e.g. your section switch. `index` is the
|
|
272
359
|
* position of the block's first item in the whole stack, for anything that
|
|
273
360
|
* depends on page position, such as which section owns the h1 or the
|
|
274
361
|
* priority image.
|
|
275
362
|
*
|
|
276
|
-
* `
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
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.
|
|
280
368
|
*/
|
|
281
369
|
render: (items: T[], position: {
|
|
282
370
|
index: number;
|
|
283
|
-
|
|
371
|
+
defaultVariant: boolean;
|
|
284
372
|
}) => ReactNode;
|
|
285
373
|
/**
|
|
286
374
|
* The visitor's A/B bucket, when the route already knows it (for example
|
|
287
|
-
* from a URL segment)
|
|
288
|
-
*
|
|
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.
|
|
289
378
|
*/
|
|
290
379
|
bucket?: string;
|
|
291
|
-
/** Nonce for the inline
|
|
380
|
+
/** Nonce for the inline scripts, under a strict CSP. */
|
|
292
381
|
nonce?: string;
|
|
293
382
|
/**
|
|
294
383
|
* Tag each personalization and A/B variant for Prepr's tracking pixel, so
|
|
@@ -299,46 +388,37 @@ interface PreprStackProps<T> {
|
|
|
299
388
|
* Each item's key goes on the element `render` returns for it, in order,
|
|
300
389
|
* once the page has hydrated. Each variant gets a wrapper with
|
|
301
390
|
* `display: contents`: it takes no box, but CSS child combinators (`>`) and
|
|
302
|
-
* `:first-child` from the stack's parent no longer reach the sections.
|
|
303
|
-
*
|
|
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.
|
|
304
395
|
*/
|
|
305
396
|
trackVariants?: boolean;
|
|
306
|
-
/**
|
|
307
|
-
* How many blocks, from the top, are on screen before the visitor scrolls.
|
|
308
|
-
* Default `0`.
|
|
309
|
-
*
|
|
310
|
-
* Their segment groups do not stream: every variant is in the cached page,
|
|
311
|
-
* and the variant the proxy decided (`prepr.resolveDecisions`) shows before
|
|
312
|
-
* first paint, so nothing on screen changes while the page loads. Without
|
|
313
|
-
* a decision (no cookie yet, or the proxy's lookup failed) the default
|
|
314
|
-
* variant shows. Costs the HTML of the other variants; images in them still
|
|
315
|
-
* download. An item with a segment group nested inside it keeps streaming.
|
|
316
|
-
*/
|
|
317
|
-
aboveTheFold?: number;
|
|
318
397
|
}
|
|
319
398
|
/**
|
|
320
|
-
* Renders a personalized stack
|
|
399
|
+
* Renders a personalized stack, entirely in the prerendered page.
|
|
400
|
+
*
|
|
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.
|
|
321
410
|
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* script shows the visitor's bucket (from `resolvePreprBucket`'s cookie)
|
|
325
|
-
* before first paint, so no variant streams or swaps in. `A` is the
|
|
326
|
-
* default. Pass `bucket` instead when the route already knows it.
|
|
327
|
-
* - Each segment-personalized group, and each item with segment content
|
|
328
|
-
* nested inside it, gets its own `<Suspense>` boundary: the default
|
|
329
|
-
* variant (possibly empty) is the fallback, and this visitor's variant
|
|
330
|
-
* streams in once `decisions` resolves. Because `items` holds every
|
|
331
|
-
* variant, a group with no default variant still gets its place.
|
|
411
|
+
* The page carries the HTML of every variant: an item with nested groups
|
|
412
|
+
* repeats once per combination of their variants.
|
|
332
413
|
*
|
|
333
414
|
* @example
|
|
334
415
|
* const data = await getPage(slug); // 'use cache' + query(..., { variants: true })
|
|
335
416
|
* <PreprStack
|
|
336
417
|
* items={data.Page.content}
|
|
337
|
-
* decisions={prepr.decide(PageDocument, { slug }, { from: data })}
|
|
338
418
|
* render={(items, { index }) => <Sections sections={items} offset={index} />}
|
|
339
419
|
* />
|
|
340
420
|
*/
|
|
341
|
-
declare function PreprStack<T>({ items,
|
|
421
|
+
declare function PreprStack<T>({ items, render, bucket, nonce, trackVariants, }: PreprStackProps<T>): ReactElement;
|
|
342
422
|
|
|
343
423
|
interface PreprNextClientOptions extends PreprClientOptions {
|
|
344
424
|
/** Tags set on every cacheable fetch, for `revalidateTag`. Default `['prepr']`. */
|
|
@@ -356,6 +436,21 @@ interface PreprNextQueryOptions extends PreprQueryOptions {
|
|
|
356
436
|
* skip the Data Cache. The route renders per request.
|
|
357
437
|
*/
|
|
358
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;
|
|
359
454
|
}
|
|
360
455
|
interface PreprNextClient {
|
|
361
456
|
/**
|
|
@@ -377,42 +472,15 @@ interface PreprNextClient {
|
|
|
377
472
|
* from everything the middleware forwards: customer profile, UTM
|
|
378
473
|
* parameters, visitor IP, HubSpot id.
|
|
379
474
|
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
475
|
+
* For rendering variants yourself with `resolveVariants`. `PreprStack`
|
|
476
|
+
* does not need it: `createPreprProxy` decides every page view.
|
|
382
477
|
*/
|
|
383
478
|
decide<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: PreprDecideOptions): Promise<PreprDecisions>;
|
|
384
479
|
/**
|
|
385
|
-
* Whether the query's result holds an A/B test
|
|
386
|
-
*
|
|
480
|
+
* Whether the query's result holds an A/B test. Never reads request
|
|
481
|
+
* headers, so it also works in middleware.
|
|
387
482
|
*/
|
|
388
483
|
hasAbTests<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
|
|
389
|
-
/**
|
|
390
|
-
* In middleware (`proxy.ts`): asks Prepr which segment variant this visitor
|
|
391
|
-
* gets for each personalization group on the page, and stores the answer in
|
|
392
|
-
* the `prepr_decisions` cookie on `response`. `PreprStack` with
|
|
393
|
-
* `aboveTheFold` then shows those variants before first paint instead of
|
|
394
|
-
* streaming them in.
|
|
395
|
-
*
|
|
396
|
-
* Call it after `createPreprMiddleware`, whose visitor headers (customer id,
|
|
397
|
-
* UTM parameters, IP, HubSpot id) it forwards. A decision is an uncached
|
|
398
|
-
* Prepr request, made once per visit by default (see `reuse`); limit it
|
|
399
|
-
* with `onlyIf` to pages whose personalized content is above the fold.
|
|
400
|
-
* Pages without segment groups are skipped after a cached check. Never throws and gives up after `timeoutMs`
|
|
401
|
-
* (default 1000): the default variant shows instead.
|
|
402
|
-
*/
|
|
403
|
-
resolveDecisions<TVariables>(request: NextRequest, response: NextResponse, document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: {
|
|
404
|
-
timeoutMs?: number;
|
|
405
|
-
/**
|
|
406
|
-
* Reuse the stored decision for the rest of the visit instead of asking
|
|
407
|
-
* Prepr on every page view. Default `true`. Asks again when UTM
|
|
408
|
-
* parameters arrive, on a first visit, and when preview forces a
|
|
409
|
-
* segment. A visitor who joins a segment mid-visit (say, by submitting
|
|
410
|
-
* a form) sees the change from their next asked request.
|
|
411
|
-
*/
|
|
412
|
-
reuse?: boolean;
|
|
413
|
-
/** Skip the decision when this resolves to false, e.g. for pages without a personalized hero. */
|
|
414
|
-
onlyIf?: () => boolean | Promise<boolean>;
|
|
415
|
-
}): Promise<void>;
|
|
416
484
|
}
|
|
417
485
|
/**
|
|
418
486
|
* Prepr GraphQL client for Next.js (App Router, server only).
|
|
@@ -432,4 +500,4 @@ interface PreprNextClient {
|
|
|
432
500
|
*/
|
|
433
501
|
declare function createPreprClient(options: PreprNextClientOptions): PreprNextClient;
|
|
434
502
|
|
|
435
|
-
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 };
|