@preprio/toolkit 0.6.0-alpha.6 → 0.6.0-alpha.8
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 +138 -52
- package/dist/astro/{chunk-MWRA3732.js → chunk-R2YPGDVU.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-Y7DWVOOY.js → chunk-2QGUP7VQ.js} +1 -1
- package/dist/{chunk-NSQOGI5K.js → chunk-ATPB7GEC.js} +1 -1
- package/dist/{chunk-W6AVX6FI.js → chunk-OY7OKO6Q.js} +52 -5
- package/dist/{chunk-OQGEL4TV.js → chunk-T7ESBVBI.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-PIQF5ZI5.js → chunk-O2SBSBDG.js} +58 -53
- package/dist/nextjs/components.cjs +205 -236
- package/dist/nextjs/components.d.cts +27 -22
- package/dist/nextjs/components.d.ts +27 -22
- package/dist/nextjs/components.js +198 -231
- package/dist/nextjs/graphql.cjs +418 -508
- package/dist/nextjs/graphql.d.cts +131 -135
- package/dist/nextjs/graphql.d.ts +131 -135
- package/dist/nextjs/graphql.js +353 -455
- package/dist/nextjs/index.cjs +114 -54
- package/dist/nextjs/index.d.cts +59 -33
- package/dist/nextjs/index.d.ts +59 -33
- package/dist/nextjs/index.js +108 -5
- package/dist/nuxt/{chunk-PF6GVWHV.js → chunk-SX3MSVPK.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-5K7HWMIF.js → chunk-UOASSHZO.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/graphql.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
1
|
import { DocumentNode } from 'graphql';
|
|
3
2
|
import { P as PreprHeaders, a as PreprFeatures } from './server-BL-sqZvu.js';
|
|
4
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. */
|
|
@@ -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,25 +285,16 @@ declare function loadPreprSchema(url: string, options?: {
|
|
|
255
285
|
fetch?: typeof fetch;
|
|
256
286
|
}): Promise<PreprSchemaInfo>;
|
|
257
287
|
|
|
258
|
-
/** The cookie `resolveDecisions` writes and the `PreprStack` switch reads. */
|
|
259
|
-
declare const PREPR_DECISIONS_COOKIE = "prepr_decisions";
|
|
260
|
-
interface ResolveDecisionsOptions {
|
|
261
|
-
/** Give up after this many ms; the default variant shows. Default 1000. */
|
|
262
|
-
timeoutMs?: number;
|
|
263
|
-
/**
|
|
264
|
-
* Keep the stored decision for this many ms instead of asking Prepr again.
|
|
265
|
-
* Default 10 000; `0` asks on every request. Background refreshes by
|
|
266
|
-
* `PreprPersonalizationSwitch` keep it fresh, so a page view rarely waits.
|
|
267
|
-
*/
|
|
268
|
-
freshFor?: number;
|
|
269
|
-
/** Skip the decision when this resolves to false. */
|
|
270
|
-
onlyIf?: () => boolean | Promise<boolean>;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
288
|
/** The query a page renders, as `createPreprProxy`'s `page` returns it. */
|
|
274
289
|
interface PreprProxyPage<TVariables = unknown> {
|
|
275
290
|
document: PreprDocument<unknown, TVariables>;
|
|
276
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>;
|
|
277
298
|
}
|
|
278
299
|
interface PreprProxyOptions {
|
|
279
300
|
/** A client made with this package's Next `createPreprClient`. */
|
|
@@ -289,27 +310,26 @@ interface PreprProxyOptions {
|
|
|
289
310
|
preview?: boolean;
|
|
290
311
|
/** Features disabled app-wide, as for `createPreprMiddleware`. */
|
|
291
312
|
features?: PreprFeatures;
|
|
292
|
-
/**
|
|
293
|
-
freshFor?: number;
|
|
294
|
-
/** Give up on Prepr after this many ms; the default variant shows. Default 1000. */
|
|
313
|
+
/** Give up on Prepr after this many ms; the default variants show. Default 3000. */
|
|
295
314
|
timeoutMs?: number;
|
|
296
315
|
/**
|
|
297
|
-
* Skip
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* for Prepr. Those requests get the default variants.
|
|
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.
|
|
301
319
|
*/
|
|
302
320
|
onlyIf?: (request: NextRequest) => boolean | Promise<boolean>;
|
|
303
321
|
}
|
|
304
322
|
/**
|
|
305
323
|
* Everything Prepr needs in the proxy (`proxy.ts`), in one call: the visitor's
|
|
306
324
|
* Prepr headers and customer id (`createPreprMiddleware`), the draft-mode
|
|
307
|
-
* redirect in preview, the
|
|
308
|
-
* at the top of each page, so `PreprStack` shows them before first paint.
|
|
325
|
+
* redirect in preview, and the answers to the browser's decision requests.
|
|
309
326
|
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* page
|
|
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.
|
|
313
333
|
*
|
|
314
334
|
* @example
|
|
315
335
|
* const handlePrepr = createPreprProxy({
|
|
@@ -329,41 +349,30 @@ declare function createPreprProxy(options: PreprProxyOptions): (request: NextReq
|
|
|
329
349
|
interface PreprStackProps<T> {
|
|
330
350
|
/** A stack (e.g. `page.content`) from a query run with `variants: true`. */
|
|
331
351
|
items: readonly T[];
|
|
332
|
-
/**
|
|
333
|
-
* The visitor's decisions, as a promise from `decide()`. Only the parts
|
|
334
|
-
* that vary per segment wait for it; a failed decision falls back to the
|
|
335
|
-
* default variants instead of failing the page.
|
|
336
|
-
*/
|
|
337
|
-
decisions: Promise<PreprDecisions>;
|
|
338
352
|
/**
|
|
339
353
|
* Renders resolved stack items, e.g. your section switch. `index` is the
|
|
340
354
|
* position of the block's first item in the whole stack, for anything that
|
|
341
355
|
* depends on page position, such as which section owns the h1 or the
|
|
342
356
|
* priority image.
|
|
343
357
|
*
|
|
344
|
-
* `placeholder` is true while this render only stands in for the visitor's
|
|
345
|
-
* variant of a segment group (the default variant, shown until the
|
|
346
|
-
* decision streams in). Leave `data-prepr-variant-key` off it: the tracking
|
|
347
|
-
* pixel would count an impression of a variant the visitor may never get.
|
|
348
|
-
*
|
|
349
358
|
* `defaultVariant` is false for the variants that are in the page but
|
|
350
359
|
* hidden unless the visitor gets them: the other buckets of an A/B test and
|
|
351
|
-
* the
|
|
352
|
-
*
|
|
353
|
-
*
|
|
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.
|
|
354
363
|
*/
|
|
355
364
|
render: (items: T[], position: {
|
|
356
365
|
index: number;
|
|
357
|
-
placeholder: boolean;
|
|
358
366
|
defaultVariant: boolean;
|
|
359
367
|
}) => ReactNode;
|
|
360
368
|
/**
|
|
361
369
|
* The visitor's A/B bucket, when the route already knows it (for example
|
|
362
|
-
* from a URL segment)
|
|
363
|
-
*
|
|
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.
|
|
364
373
|
*/
|
|
365
374
|
bucket?: string;
|
|
366
|
-
/** Nonce for the inline
|
|
375
|
+
/** Nonce for the inline scripts, under a strict CSP. */
|
|
367
376
|
nonce?: string;
|
|
368
377
|
/**
|
|
369
378
|
* Tag each personalization and A/B variant for Prepr's tracking pixel, so
|
|
@@ -374,49 +383,37 @@ interface PreprStackProps<T> {
|
|
|
374
383
|
* Each item's key goes on the element `render` returns for it, in order,
|
|
375
384
|
* once the page has hydrated. Each variant gets a wrapper with
|
|
376
385
|
* `display: contents`: it takes no box, but CSS child combinators (`>`) and
|
|
377
|
-
* `:first-child` from the stack's parent no longer reach the sections.
|
|
378
|
-
*
|
|
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.
|
|
379
390
|
*/
|
|
380
391
|
trackVariants?: boolean;
|
|
381
|
-
/**
|
|
382
|
-
* How many blocks, from the top, are on screen before the visitor scrolls.
|
|
383
|
-
* Default `1`; set it higher when more sections fit on the first screen
|
|
384
|
-
* (take the larger screen when it differs per device), or `0` to stream
|
|
385
|
-
* every segment group.
|
|
386
|
-
*
|
|
387
|
-
* Their segment groups do not stream: every variant is in the cached page,
|
|
388
|
-
* and the variant the proxy decided (`prepr.resolveDecisions`) shows before
|
|
389
|
-
* first paint, so nothing on screen changes while the page loads. Without
|
|
390
|
-
* a decision (no cookie yet, or the proxy's lookup failed) the default
|
|
391
|
-
* variant shows. Costs the HTML of the other variants; see `defaultVariant`
|
|
392
|
-
* in `render` to keep their images from downloading. An item with a
|
|
393
|
-
* segment group nested inside it keeps streaming.
|
|
394
|
-
*/
|
|
395
|
-
aboveTheFold?: number;
|
|
396
392
|
}
|
|
397
393
|
/**
|
|
398
|
-
* Renders a personalized stack
|
|
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.
|
|
399
405
|
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* script shows the visitor's bucket (from `resolvePreprBucket`'s cookie)
|
|
403
|
-
* before first paint, so no variant streams or swaps in. `A` is the
|
|
404
|
-
* default. Pass `bucket` instead when the route already knows it.
|
|
405
|
-
* - Each segment-personalized group, and each item with segment content
|
|
406
|
-
* nested inside it, gets its own `<Suspense>` boundary: the default
|
|
407
|
-
* variant (possibly empty) is the fallback, and this visitor's variant
|
|
408
|
-
* streams in once `decisions` resolves. Because `items` holds every
|
|
409
|
-
* variant, a group with no default variant still gets its place.
|
|
406
|
+
* The page carries the HTML of every variant: an item with nested groups
|
|
407
|
+
* repeats once per combination of their variants.
|
|
410
408
|
*
|
|
411
409
|
* @example
|
|
412
410
|
* const data = await getPage(slug); // 'use cache' + query(..., { variants: true })
|
|
413
411
|
* <PreprStack
|
|
414
412
|
* items={data.Page.content}
|
|
415
|
-
* decisions={prepr.decide(PageDocument, { slug }, { from: data })}
|
|
416
413
|
* render={(items, { index }) => <Sections sections={items} offset={index} />}
|
|
417
414
|
* />
|
|
418
415
|
*/
|
|
419
|
-
declare function PreprStack<T>({ items,
|
|
416
|
+
declare function PreprStack<T>({ items, render, bucket, nonce, trackVariants, }: PreprStackProps<T>): ReactElement;
|
|
420
417
|
|
|
421
418
|
interface PreprNextClientOptions extends PreprClientOptions {
|
|
422
419
|
/** Tags set on every cacheable fetch, for `revalidateTag`. Default `['prepr']`. */
|
|
@@ -434,6 +431,21 @@ interface PreprNextQueryOptions extends PreprQueryOptions {
|
|
|
434
431
|
* skip the Data Cache. The route renders per request.
|
|
435
432
|
*/
|
|
436
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;
|
|
437
449
|
}
|
|
438
450
|
interface PreprNextClient {
|
|
439
451
|
/**
|
|
@@ -455,31 +467,15 @@ interface PreprNextClient {
|
|
|
455
467
|
* from everything the middleware forwards: customer profile, UTM
|
|
456
468
|
* parameters, visitor IP, HubSpot id.
|
|
457
469
|
*
|
|
458
|
-
*
|
|
459
|
-
*
|
|
470
|
+
* For rendering variants yourself with `resolveVariants`. `PreprStack`
|
|
471
|
+
* does not need it: `createPreprProxy` decides every page view.
|
|
460
472
|
*/
|
|
461
473
|
decide<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: PreprDecideOptions): Promise<PreprDecisions>;
|
|
462
474
|
/**
|
|
463
|
-
* Whether the query's result holds an A/B test
|
|
464
|
-
*
|
|
475
|
+
* Whether the query's result holds an A/B test. Never reads request
|
|
476
|
+
* headers, so it also works in middleware.
|
|
465
477
|
*/
|
|
466
478
|
hasAbTests<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
|
|
467
|
-
/**
|
|
468
|
-
* In middleware (`proxy.ts`): asks Prepr which segment variant this visitor
|
|
469
|
-
* gets for each personalization group at the top of the page, and stores
|
|
470
|
-
* the answer in the `prepr_decisions` cookie on `response`. `PreprStack`
|
|
471
|
-
* then shows those variants before first paint instead of streaming them
|
|
472
|
-
* in. `createPreprProxy` calls this for you.
|
|
473
|
-
*
|
|
474
|
-
* Call it after `createPreprMiddleware`, whose visitor headers (customer id,
|
|
475
|
-
* UTM parameters, IP, HubSpot id) it forwards. A stored decision that
|
|
476
|
-
* covers the page is kept for `freshFor` (default 10 s); a first visit, UTM
|
|
477
|
-
* parameters and a segment forced in preview always ask again. Pages
|
|
478
|
-
* without segment groups at the top are skipped after a cached check.
|
|
479
|
-
* Never throws and gives up after `timeoutMs` (default 1000): the default
|
|
480
|
-
* variant shows instead.
|
|
481
|
-
*/
|
|
482
|
-
resolveDecisions<TVariables>(request: NextRequest, response: NextResponse, document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: ResolveDecisionsOptions): Promise<void>;
|
|
483
479
|
}
|
|
484
480
|
/**
|
|
485
481
|
* Prepr GraphQL client for Next.js (App Router, server only).
|
|
@@ -499,4 +495,4 @@ interface PreprNextClient {
|
|
|
499
495
|
*/
|
|
500
496
|
declare function createPreprClient(options: PreprNextClientOptions): PreprNextClient;
|
|
501
497
|
|
|
502
|
-
export {
|
|
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 };
|