@preprio/toolkit 0.5.0-rc.1 → 0.6.0-alpha.0

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.
Files changed (69) hide show
  1. package/README.md +300 -19
  2. package/dist/astro/chunk-3UVUDDNY.js +173 -0
  3. package/dist/astro/graphql.cjs +983 -0
  4. package/dist/astro/graphql.d.cts +231 -0
  5. package/dist/astro/graphql.d.ts +231 -0
  6. package/dist/astro/graphql.js +893 -0
  7. package/dist/astro/index-XT_z-RYT.d.cts +130 -0
  8. package/dist/astro/index-XT_z-RYT.d.ts +130 -0
  9. package/dist/astro/index.cjs +14 -1
  10. package/dist/astro/index.d.cts +1 -120
  11. package/dist/astro/index.d.ts +1 -120
  12. package/dist/astro/index.js +15 -153
  13. package/dist/{chunk-4JNKYIEV.js → chunk-BJ2LBLWO.js} +69 -268
  14. package/dist/chunk-DGZA7KX7.js +172 -0
  15. package/dist/chunk-YR7P4IWE.js +187 -0
  16. package/dist/graphql.cjs +894 -0
  17. package/dist/graphql.d.cts +231 -0
  18. package/dist/graphql.d.ts +231 -0
  19. package/dist/graphql.js +787 -0
  20. package/dist/index.cjs +74 -111
  21. package/dist/index.d.cts +11 -62
  22. package/dist/index.d.ts +11 -62
  23. package/dist/index.js +23 -167
  24. package/dist/nextjs/chunk-U4HXENF7.js +231 -0
  25. package/dist/nextjs/components.cjs +188 -114
  26. package/dist/nextjs/components.d.cts +33 -2
  27. package/dist/nextjs/components.d.ts +33 -2
  28. package/dist/nextjs/components.js +132 -4
  29. package/dist/nextjs/graphql.cjs +1315 -0
  30. package/dist/nextjs/graphql.d.cts +361 -0
  31. package/dist/nextjs/graphql.d.ts +361 -0
  32. package/dist/nextjs/graphql.js +1218 -0
  33. package/dist/nextjs/index.cjs +126 -6
  34. package/dist/nextjs/index.d.cts +53 -141
  35. package/dist/nextjs/index.d.ts +53 -141
  36. package/dist/nextjs/index.js +113 -203
  37. package/dist/nextjs/server-CjpELYvq.d.cts +156 -0
  38. package/dist/nextjs/server-CjpELYvq.d.ts +156 -0
  39. package/dist/nuxt/chunk-P6ENNAEE.js +417 -0
  40. package/dist/nuxt/graphql.cjs +990 -0
  41. package/dist/nuxt/graphql.d.cts +228 -0
  42. package/dist/nuxt/graphql.d.ts +228 -0
  43. package/dist/nuxt/graphql.js +894 -0
  44. package/dist/nuxt/index.cjs +14 -1
  45. package/dist/nuxt/index.d.cts +3 -148
  46. package/dist/nuxt/index.d.ts +3 -148
  47. package/dist/nuxt/index.js +15 -391
  48. package/dist/nuxt/server-8v6OHbsw.d.cts +158 -0
  49. package/dist/nuxt/server-8v6OHbsw.d.ts +158 -0
  50. package/dist/pixel-DwW7cXJm.d.cts +49 -0
  51. package/dist/pixel-DwW7cXJm.d.ts +49 -0
  52. package/dist/react/components.cjs +86 -112
  53. package/dist/react/components.js +86 -112
  54. package/dist/server-Brr1UgtW.d.ts +59 -0
  55. package/dist/server-DJuS3YU0.d.cts +59 -0
  56. package/dist/sveltekit/chunk-FSARVMG5.js +413 -0
  57. package/dist/sveltekit/graphql.cjs +996 -0
  58. package/dist/sveltekit/graphql.d.cts +233 -0
  59. package/dist/sveltekit/graphql.d.ts +233 -0
  60. package/dist/sveltekit/graphql.js +900 -0
  61. package/dist/sveltekit/index.cjs +14 -1
  62. package/dist/sveltekit/index.d.cts +3 -88
  63. package/dist/sveltekit/index.d.ts +3 -88
  64. package/dist/sveltekit/index.js +15 -387
  65. package/dist/sveltekit/server-CO847mEV.d.cts +98 -0
  66. package/dist/sveltekit/server-CO847mEV.d.ts +98 -0
  67. package/dist/{pixel-e1fUWl2Y.d.cts → types-BYH9XqmN.d.cts} +2 -50
  68. package/dist/{pixel-e1fUWl2Y.d.ts → types-BYH9XqmN.d.ts} +2 -50
  69. package/package.json +31 -1
@@ -0,0 +1,231 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { P as PreprHeaders } from './types-BYH9XqmN.cjs';
3
+ export { a as PreprErrorCode } from './types-BYH9XqmN.cjs';
4
+ export { P as PreprError, i as isPersonalizedResponse } from './server-DJuS3YU0.cjs';
5
+
6
+ /** Prepr's variant id for visitors outside every targeted segment. */
7
+ declare const PREPR_DEFAULT_VARIANT = "ALL_OTHER_USERS";
8
+
9
+ /** The variant ids Prepr chose for one visitor, per personalization group. */
10
+ type PreprDecisions = ReadonlyMap<string, readonly string[]>;
11
+ interface ResolveVariantsOptions {
12
+ /**
13
+ * The visitor's per-group variants (from a decision query). Without it,
14
+ * personalization groups show their default variant.
15
+ */
16
+ decisions?: PreprDecisions;
17
+ /** The visitor's A/B bucket. Without it, A/B groups use the decision, then `A`. */
18
+ bucket?: string;
19
+ }
20
+ /**
21
+ * Keeps, in every list of a variants query result, only the variants this
22
+ * visitor gets, at any depth (page stacks, nested stacks, personalized
23
+ * buttons). Items outside a group are kept as they are.
24
+ */
25
+ declare function resolveVariants<T>(data: T, options?: ResolveVariantsOptions): T;
26
+
27
+ /** A run of stack items that renders the same way: see {@link splitStack}. */
28
+ interface PreprStackBlock<T> {
29
+ key: string;
30
+ items: T[];
31
+ /**
32
+ * Rendered position of the block's first item: a group (whichever variant
33
+ * shows) takes one position, any other item one each. Use it for anything
34
+ * that depends on page position, like which section owns the h1.
35
+ */
36
+ index: number;
37
+ /**
38
+ * Some item in the block (or nested inside one) is a segment variant, so
39
+ * the block depends on the visitor and is decided per request.
40
+ */
41
+ personalized: boolean;
42
+ /**
43
+ * Some item in the block (or nested inside one) is an A/B variant. Without
44
+ * a known bucket, such a block renders once per bucket and the visitor's
45
+ * bucket is picked in the browser before first paint.
46
+ */
47
+ abTest: boolean;
48
+ }
49
+ /**
50
+ * Splits a variants-query stack into blocks. Each personalization or A/B
51
+ * group becomes one block (a variant can hold a different number of items
52
+ * than the default); consecutive items that never vary are merged.
53
+ */
54
+ declare function splitStack<T>(items: readonly T[]): PreprStackBlock<T>[];
55
+
56
+ /** The attribute Prepr's tracking pixel reads impressions and conversions from. */
57
+ interface PreprVariantProps {
58
+ 'data-prepr-variant-key'?: string;
59
+ }
60
+ /**
61
+ * Attributes that let Prepr's tracking pixel count impressions of this item's
62
+ * variant, for an item from a query run with `variants: true`. Spread them on
63
+ * the element that shows the item; an item outside any personalization or A/B
64
+ * group gets none.
65
+ *
66
+ * Items rendered by the Next.js `PreprStack` are tagged for you. Reach for this
67
+ * for items nested inside them (cards, buttons, models in a section) and in
68
+ * frameworks without `PreprStack`.
69
+ *
70
+ * @example
71
+ * <article {...preprVariantProps(card)}>…</article>
72
+ */
73
+ declare function preprVariantProps(item: unknown): PreprVariantProps;
74
+
75
+ /**
76
+ * A GraphQL document accepted by `query`: a plain string, graphql-codegen's
77
+ * `TypedDocumentString` (`documentMode: 'string'`), or any `DocumentNode`,
78
+ * including codegen's default `TypedDocumentNode` output.
79
+ *
80
+ * The phantom `__apiType` field is how codegen attaches result and variable
81
+ * types; matching it structurally keeps `@graphql-typed-document-node/core`
82
+ * out of this package.
83
+ */
84
+ type PreprDocument<TResult, TVariables> = string | ({
85
+ __apiType?: (variables: TVariables) => TResult;
86
+ } & (String | DocumentNode));
87
+ /**
88
+ * How stega markers are stripped from the response:
89
+ * - `'urls'`: only from values under URL-like keys (`url`, `slug`, `link`,
90
+ * `href`), where markers break links. Text keeps its markers for
91
+ * click-to-edit.
92
+ * - `'all'`: from every string.
93
+ * - `'none'`: never.
94
+ */
95
+ type PreprStegaMode = 'urls' | 'all' | 'none';
96
+ interface PreprClientOptions {
97
+ /** Full Prepr GraphQL URL, `https://graphql.prepr.io/<token>`. */
98
+ url: string;
99
+ /**
100
+ * Fetch implementation. Defaults to the global `fetch`, read at call time so
101
+ * framework-patched versions (such as Next.js's) are used.
102
+ */
103
+ fetch?: typeof fetch;
104
+ /**
105
+ * Preview mode: every query skips the HTTP cache so editors see each edit,
106
+ * and stega defaults to `'urls'` so click-to-edit keeps working.
107
+ */
108
+ preview?: boolean;
109
+ /** Default: `'urls'` when `preview` is true, otherwise `'all'`. */
110
+ stega?: PreprStegaMode;
111
+ /**
112
+ * Send queries as a GET with the request body base64-encoded in a
113
+ * `Fastly-Query` header, which Prepr's edge serves from the nearest point
114
+ * of presence (about half the latency of a POST in our measurements).
115
+ * Queries too large for a header still go as a POST. Off by default: it
116
+ * relies on Prepr edge behavior that is not part of the documented API.
117
+ */
118
+ fastlyQuery?: boolean;
119
+ /**
120
+ * @internal Fetch options for the one-time schema introspection, so a
121
+ * framework wrapper can put it in its data cache.
122
+ */
123
+ schemaInit?: RequestInit;
124
+ /**
125
+ * Headers sent with every request, such as a header a proxy in front of the
126
+ * API requires. They are fixed when the client is created, so they cannot
127
+ * vary per visitor and do not stop responses from being cached. Put
128
+ * per-request values in the query's `headers` instead.
129
+ */
130
+ headers?: HeadersInit;
131
+ }
132
+ interface PreprQueryOptions {
133
+ /**
134
+ * Prepr headers to forward, typically from `getPreprHeaders`. Passing any
135
+ * headers object, even an empty one, makes the request `no-store`: the
136
+ * response may be personalized and must not be shared between visitors.
137
+ */
138
+ headers?: PreprHeaders | HeadersInit;
139
+ /**
140
+ * Extra fetch options such as `signal`. `method` and `body` are set by the
141
+ * client. `init.headers` are merged like `headers`, and also make the
142
+ * request `no-store`.
143
+ */
144
+ init?: RequestInit;
145
+ /** Per-query fetch, overriding the client's (e.g. SvelteKit's `event.fetch`). */
146
+ fetch?: typeof fetch;
147
+ /**
148
+ * Fetch every variant instead of the visitor's: `personalize: false` is
149
+ * added to every personalizable field in the query, at any depth, and each
150
+ * item gets its `_context` (under `_preprContext`). The result is the same
151
+ * for every visitor, so it can be cached; pass it to `resolveVariants` with
152
+ * the visitor's `decide()` result to get what they see.
153
+ *
154
+ * The client learns which fields are personalizable from one schema
155
+ * introspection request, made on first use.
156
+ */
157
+ variants?: boolean;
158
+ }
159
+ /** Options for `decide()`. */
160
+ interface PreprDecideOptions extends Omit<PreprQueryOptions, 'variants'> {
161
+ /**
162
+ * The `variants: true` result this decision is for (the whole `data`
163
+ * object). The decision query then asks only about the fields that hold
164
+ * segment personalization groups, and is skipped entirely when there are
165
+ * none, e.g. on pages with only A/B tests or no personalization.
166
+ */
167
+ from?: unknown;
168
+ /**
169
+ * @internal Ask only about the first personalizable list on each path,
170
+ * without `from`: what middleware needs for groups at the top of a stack.
171
+ */
172
+ topLevelOnly?: boolean;
173
+ }
174
+ interface PreprQueryResult<TResult> {
175
+ data: TResult;
176
+ /**
177
+ * True when Prepr reports, through the response's `Vary` header, that the
178
+ * queried fields hold segment variants or A/B tests.
179
+ */
180
+ personalized: boolean;
181
+ }
182
+ interface PreprClient {
183
+ /**
184
+ * Run a GraphQL query against Prepr.
185
+ *
186
+ * @throws PreprError — `INVALID_DOCUMENT`, `FETCH_ERROR`, `HTTP_ERROR`,
187
+ * `INVALID_RESPONSE` or `GRAPHQL_ERROR`. Any entry in the response's
188
+ * `errors` array throws; there is no partial-data mode.
189
+ */
190
+ query<TResult, TVariables>(document: PreprDocument<TResult, TVariables>, variables?: TVariables, options?: PreprQueryOptions): Promise<PreprQueryResult<TResult>>;
191
+ /**
192
+ * Which variant of each personalization and A/B group a visitor gets, for
193
+ * the same query you render with `variants: true`. Sends a cut-down copy of
194
+ * the query that selects only each item's `_context`, so the response is a
195
+ * few hundred bytes. Pass the visitor's Prepr headers: the result is only
196
+ * as personal as the headers sent.
197
+ */
198
+ decide<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: PreprDecideOptions): Promise<PreprDecisions>;
199
+ /**
200
+ * Whether the query's result holds an A/B test, e.g. to decide in
201
+ * middleware whether a visitor's A/B bucket is needed. Sends the query
202
+ * without its leaf fields and without visitor headers, so Prepr's CDN
203
+ * caches it, and reads the answer from the `Vary` header; it needs no
204
+ * schema download. Answers are also kept in memory for a minute. Resolves to
205
+ * `true` when the check itself fails, so callers err toward having the
206
+ * bucket.
207
+ */
208
+ hasAbTests<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
209
+ /**
210
+ * Whether the query's result holds a segment personalization group, from
211
+ * the same cached check as `hasAbTests`. Resolves to `true` when the check
212
+ * fails.
213
+ */
214
+ hasSegments<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
215
+ }
216
+
217
+ /**
218
+ * Create a GraphQL client for the Prepr API.
219
+ *
220
+ * Reach for it on the server, to fetch content with codegen types and get
221
+ * Prepr's personalization verdict alongside the data. Requests without
222
+ * `headers` are identical for every visitor and safe to cache; requests with
223
+ * them are always `no-store`.
224
+ *
225
+ * Requires the `graphql` package, which graphql-codegen already installs.
226
+ *
227
+ * @throws PreprError `MISSING_TOKEN` or `INVALID_TOKEN` for a bad `url`.
228
+ */
229
+ declare function createPreprClient(options: PreprClientOptions): PreprClient;
230
+
231
+ export { PREPR_DEFAULT_VARIANT, type PreprClient, type PreprClientOptions, type PreprDecideOptions, type PreprDecisions, type PreprDocument, PreprHeaders, type PreprQueryOptions, type PreprQueryResult, type PreprStackBlock, type PreprStegaMode, type PreprVariantProps, type ResolveVariantsOptions, createPreprClient, preprVariantProps, resolveVariants, splitStack };
@@ -0,0 +1,231 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { P as PreprHeaders } from './types-BYH9XqmN.js';
3
+ export { a as PreprErrorCode } from './types-BYH9XqmN.js';
4
+ export { P as PreprError, i as isPersonalizedResponse } from './server-Brr1UgtW.js';
5
+
6
+ /** Prepr's variant id for visitors outside every targeted segment. */
7
+ declare const PREPR_DEFAULT_VARIANT = "ALL_OTHER_USERS";
8
+
9
+ /** The variant ids Prepr chose for one visitor, per personalization group. */
10
+ type PreprDecisions = ReadonlyMap<string, readonly string[]>;
11
+ interface ResolveVariantsOptions {
12
+ /**
13
+ * The visitor's per-group variants (from a decision query). Without it,
14
+ * personalization groups show their default variant.
15
+ */
16
+ decisions?: PreprDecisions;
17
+ /** The visitor's A/B bucket. Without it, A/B groups use the decision, then `A`. */
18
+ bucket?: string;
19
+ }
20
+ /**
21
+ * Keeps, in every list of a variants query result, only the variants this
22
+ * visitor gets, at any depth (page stacks, nested stacks, personalized
23
+ * buttons). Items outside a group are kept as they are.
24
+ */
25
+ declare function resolveVariants<T>(data: T, options?: ResolveVariantsOptions): T;
26
+
27
+ /** A run of stack items that renders the same way: see {@link splitStack}. */
28
+ interface PreprStackBlock<T> {
29
+ key: string;
30
+ items: T[];
31
+ /**
32
+ * Rendered position of the block's first item: a group (whichever variant
33
+ * shows) takes one position, any other item one each. Use it for anything
34
+ * that depends on page position, like which section owns the h1.
35
+ */
36
+ index: number;
37
+ /**
38
+ * Some item in the block (or nested inside one) is a segment variant, so
39
+ * the block depends on the visitor and is decided per request.
40
+ */
41
+ personalized: boolean;
42
+ /**
43
+ * Some item in the block (or nested inside one) is an A/B variant. Without
44
+ * a known bucket, such a block renders once per bucket and the visitor's
45
+ * bucket is picked in the browser before first paint.
46
+ */
47
+ abTest: boolean;
48
+ }
49
+ /**
50
+ * Splits a variants-query stack into blocks. Each personalization or A/B
51
+ * group becomes one block (a variant can hold a different number of items
52
+ * than the default); consecutive items that never vary are merged.
53
+ */
54
+ declare function splitStack<T>(items: readonly T[]): PreprStackBlock<T>[];
55
+
56
+ /** The attribute Prepr's tracking pixel reads impressions and conversions from. */
57
+ interface PreprVariantProps {
58
+ 'data-prepr-variant-key'?: string;
59
+ }
60
+ /**
61
+ * Attributes that let Prepr's tracking pixel count impressions of this item's
62
+ * variant, for an item from a query run with `variants: true`. Spread them on
63
+ * the element that shows the item; an item outside any personalization or A/B
64
+ * group gets none.
65
+ *
66
+ * Items rendered by the Next.js `PreprStack` are tagged for you. Reach for this
67
+ * for items nested inside them (cards, buttons, models in a section) and in
68
+ * frameworks without `PreprStack`.
69
+ *
70
+ * @example
71
+ * <article {...preprVariantProps(card)}>…</article>
72
+ */
73
+ declare function preprVariantProps(item: unknown): PreprVariantProps;
74
+
75
+ /**
76
+ * A GraphQL document accepted by `query`: a plain string, graphql-codegen's
77
+ * `TypedDocumentString` (`documentMode: 'string'`), or any `DocumentNode`,
78
+ * including codegen's default `TypedDocumentNode` output.
79
+ *
80
+ * The phantom `__apiType` field is how codegen attaches result and variable
81
+ * types; matching it structurally keeps `@graphql-typed-document-node/core`
82
+ * out of this package.
83
+ */
84
+ type PreprDocument<TResult, TVariables> = string | ({
85
+ __apiType?: (variables: TVariables) => TResult;
86
+ } & (String | DocumentNode));
87
+ /**
88
+ * How stega markers are stripped from the response:
89
+ * - `'urls'`: only from values under URL-like keys (`url`, `slug`, `link`,
90
+ * `href`), where markers break links. Text keeps its markers for
91
+ * click-to-edit.
92
+ * - `'all'`: from every string.
93
+ * - `'none'`: never.
94
+ */
95
+ type PreprStegaMode = 'urls' | 'all' | 'none';
96
+ interface PreprClientOptions {
97
+ /** Full Prepr GraphQL URL, `https://graphql.prepr.io/<token>`. */
98
+ url: string;
99
+ /**
100
+ * Fetch implementation. Defaults to the global `fetch`, read at call time so
101
+ * framework-patched versions (such as Next.js's) are used.
102
+ */
103
+ fetch?: typeof fetch;
104
+ /**
105
+ * Preview mode: every query skips the HTTP cache so editors see each edit,
106
+ * and stega defaults to `'urls'` so click-to-edit keeps working.
107
+ */
108
+ preview?: boolean;
109
+ /** Default: `'urls'` when `preview` is true, otherwise `'all'`. */
110
+ stega?: PreprStegaMode;
111
+ /**
112
+ * Send queries as a GET with the request body base64-encoded in a
113
+ * `Fastly-Query` header, which Prepr's edge serves from the nearest point
114
+ * of presence (about half the latency of a POST in our measurements).
115
+ * Queries too large for a header still go as a POST. Off by default: it
116
+ * relies on Prepr edge behavior that is not part of the documented API.
117
+ */
118
+ fastlyQuery?: boolean;
119
+ /**
120
+ * @internal Fetch options for the one-time schema introspection, so a
121
+ * framework wrapper can put it in its data cache.
122
+ */
123
+ schemaInit?: RequestInit;
124
+ /**
125
+ * Headers sent with every request, such as a header a proxy in front of the
126
+ * API requires. They are fixed when the client is created, so they cannot
127
+ * vary per visitor and do not stop responses from being cached. Put
128
+ * per-request values in the query's `headers` instead.
129
+ */
130
+ headers?: HeadersInit;
131
+ }
132
+ interface PreprQueryOptions {
133
+ /**
134
+ * Prepr headers to forward, typically from `getPreprHeaders`. Passing any
135
+ * headers object, even an empty one, makes the request `no-store`: the
136
+ * response may be personalized and must not be shared between visitors.
137
+ */
138
+ headers?: PreprHeaders | HeadersInit;
139
+ /**
140
+ * Extra fetch options such as `signal`. `method` and `body` are set by the
141
+ * client. `init.headers` are merged like `headers`, and also make the
142
+ * request `no-store`.
143
+ */
144
+ init?: RequestInit;
145
+ /** Per-query fetch, overriding the client's (e.g. SvelteKit's `event.fetch`). */
146
+ fetch?: typeof fetch;
147
+ /**
148
+ * Fetch every variant instead of the visitor's: `personalize: false` is
149
+ * added to every personalizable field in the query, at any depth, and each
150
+ * item gets its `_context` (under `_preprContext`). The result is the same
151
+ * for every visitor, so it can be cached; pass it to `resolveVariants` with
152
+ * the visitor's `decide()` result to get what they see.
153
+ *
154
+ * The client learns which fields are personalizable from one schema
155
+ * introspection request, made on first use.
156
+ */
157
+ variants?: boolean;
158
+ }
159
+ /** Options for `decide()`. */
160
+ interface PreprDecideOptions extends Omit<PreprQueryOptions, 'variants'> {
161
+ /**
162
+ * The `variants: true` result this decision is for (the whole `data`
163
+ * object). The decision query then asks only about the fields that hold
164
+ * segment personalization groups, and is skipped entirely when there are
165
+ * none, e.g. on pages with only A/B tests or no personalization.
166
+ */
167
+ from?: unknown;
168
+ /**
169
+ * @internal Ask only about the first personalizable list on each path,
170
+ * without `from`: what middleware needs for groups at the top of a stack.
171
+ */
172
+ topLevelOnly?: boolean;
173
+ }
174
+ interface PreprQueryResult<TResult> {
175
+ data: TResult;
176
+ /**
177
+ * True when Prepr reports, through the response's `Vary` header, that the
178
+ * queried fields hold segment variants or A/B tests.
179
+ */
180
+ personalized: boolean;
181
+ }
182
+ interface PreprClient {
183
+ /**
184
+ * Run a GraphQL query against Prepr.
185
+ *
186
+ * @throws PreprError — `INVALID_DOCUMENT`, `FETCH_ERROR`, `HTTP_ERROR`,
187
+ * `INVALID_RESPONSE` or `GRAPHQL_ERROR`. Any entry in the response's
188
+ * `errors` array throws; there is no partial-data mode.
189
+ */
190
+ query<TResult, TVariables>(document: PreprDocument<TResult, TVariables>, variables?: TVariables, options?: PreprQueryOptions): Promise<PreprQueryResult<TResult>>;
191
+ /**
192
+ * Which variant of each personalization and A/B group a visitor gets, for
193
+ * the same query you render with `variants: true`. Sends a cut-down copy of
194
+ * the query that selects only each item's `_context`, so the response is a
195
+ * few hundred bytes. Pass the visitor's Prepr headers: the result is only
196
+ * as personal as the headers sent.
197
+ */
198
+ decide<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables, options?: PreprDecideOptions): Promise<PreprDecisions>;
199
+ /**
200
+ * Whether the query's result holds an A/B test, e.g. to decide in
201
+ * middleware whether a visitor's A/B bucket is needed. Sends the query
202
+ * without its leaf fields and without visitor headers, so Prepr's CDN
203
+ * caches it, and reads the answer from the `Vary` header; it needs no
204
+ * schema download. Answers are also kept in memory for a minute. Resolves to
205
+ * `true` when the check itself fails, so callers err toward having the
206
+ * bucket.
207
+ */
208
+ hasAbTests<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
209
+ /**
210
+ * Whether the query's result holds a segment personalization group, from
211
+ * the same cached check as `hasAbTests`. Resolves to `true` when the check
212
+ * fails.
213
+ */
214
+ hasSegments<TVariables>(document: PreprDocument<unknown, TVariables>, variables?: TVariables): Promise<boolean>;
215
+ }
216
+
217
+ /**
218
+ * Create a GraphQL client for the Prepr API.
219
+ *
220
+ * Reach for it on the server, to fetch content with codegen types and get
221
+ * Prepr's personalization verdict alongside the data. Requests without
222
+ * `headers` are identical for every visitor and safe to cache; requests with
223
+ * them are always `no-store`.
224
+ *
225
+ * Requires the `graphql` package, which graphql-codegen already installs.
226
+ *
227
+ * @throws PreprError `MISSING_TOKEN` or `INVALID_TOKEN` for a bad `url`.
228
+ */
229
+ declare function createPreprClient(options: PreprClientOptions): PreprClient;
230
+
231
+ export { PREPR_DEFAULT_VARIANT, type PreprClient, type PreprClientOptions, type PreprDecideOptions, type PreprDecisions, type PreprDocument, PreprHeaders, type PreprQueryOptions, type PreprQueryResult, type PreprStackBlock, type PreprStegaMode, type PreprVariantProps, type ResolveVariantsOptions, createPreprClient, preprVariantProps, resolveVariants, splitStack };