@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.
Files changed (59) hide show
  1. package/README.md +268 -59
  2. package/dist/astro/{chunk-3UVUDDNY.js → chunk-CG2QBHNU.js} +1 -1
  3. package/dist/astro/graphql.cjs +154 -59
  4. package/dist/astro/graphql.d.cts +75 -6
  5. package/dist/astro/graphql.d.ts +75 -6
  6. package/dist/astro/graphql.js +150 -59
  7. package/dist/astro/index.cjs +1 -1
  8. package/dist/astro/index.js +1 -1
  9. package/dist/chunk-3NCEVJJ3.js +10 -0
  10. package/dist/{chunk-BJ2LBLWO.js → chunk-LIDUJWWJ.js} +6 -4
  11. package/dist/chunk-M3RBYJ5J.js +499 -0
  12. package/dist/{chunk-DGZA7KX7.js → chunk-S5RWVMDJ.js} +0 -24
  13. package/dist/{chunk-YR7P4IWE.js → chunk-SF6TN4JR.js} +1 -9
  14. package/dist/chunk-TN6SNAR2.js +26 -0
  15. package/dist/graphql/codegen.cjs +557 -0
  16. package/dist/graphql/codegen.d.cts +23 -0
  17. package/dist/graphql/codegen.d.ts +23 -0
  18. package/dist/graphql/codegen.js +99 -0
  19. package/dist/graphql.cjs +185 -59
  20. package/dist/graphql.d.cts +110 -6
  21. package/dist/graphql.d.ts +110 -6
  22. package/dist/graphql.js +91 -430
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.d.cts +1 -1
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +10 -6
  27. package/dist/nextjs/chunk-B4GVZEOL.js +549 -0
  28. package/dist/nextjs/components.cjs +297 -81
  29. package/dist/nextjs/components.d.cts +26 -11
  30. package/dist/nextjs/components.d.ts +26 -11
  31. package/dist/nextjs/components.js +289 -73
  32. package/dist/nextjs/graphql.cjs +952 -315
  33. package/dist/nextjs/graphql.d.cts +225 -83
  34. package/dist/nextjs/graphql.d.ts +225 -83
  35. package/dist/nextjs/graphql.js +634 -314
  36. package/dist/nextjs/index.cjs +116 -54
  37. package/dist/nextjs/index.d.cts +61 -23
  38. package/dist/nextjs/index.d.ts +61 -23
  39. package/dist/nextjs/index.js +97 -299
  40. package/dist/nextjs/{server-CjpELYvq.d.ts → server-BL-sqZvu.d.cts} +1 -1
  41. package/dist/nextjs/{server-CjpELYvq.d.cts → server-BL-sqZvu.d.ts} +1 -1
  42. package/dist/nuxt/{chunk-P6ENNAEE.js → chunk-FMC3DP7N.js} +1 -1
  43. package/dist/nuxt/graphql.cjs +154 -59
  44. package/dist/nuxt/graphql.d.cts +75 -6
  45. package/dist/nuxt/graphql.d.ts +75 -6
  46. package/dist/nuxt/graphql.js +150 -59
  47. package/dist/nuxt/index.cjs +1 -1
  48. package/dist/nuxt/index.js +1 -1
  49. package/dist/react/components.cjs +1 -1
  50. package/dist/react/components.js +1 -1
  51. package/dist/sveltekit/{chunk-FSARVMG5.js → chunk-AJPKBAHO.js} +1 -1
  52. package/dist/sveltekit/graphql.cjs +154 -59
  53. package/dist/sveltekit/graphql.d.cts +75 -6
  54. package/dist/sveltekit/graphql.d.ts +75 -6
  55. package/dist/sveltekit/graphql.js +150 -59
  56. package/dist/sveltekit/index.cjs +1 -1
  57. package/dist/sveltekit/index.js +1 -1
  58. package/package.json +6 -1
  59. package/dist/nextjs/chunk-U4HXENF7.js +0 -231
package/dist/graphql.js CHANGED
@@ -1,202 +1,56 @@
1
1
  import {
2
- PreprError,
3
- isPersonalizedResponse,
4
- validatePreprToken
5
- } from "./chunk-YR7P4IWE.js";
2
+ isPersonalizedResponse
3
+ } from "./chunk-3NCEVJJ3.js";
6
4
  import {
7
5
  stegaClean
8
- } from "./chunk-DGZA7KX7.js";
9
-
10
- // src/core/variants/constants.ts
11
- var PREPR_CONTEXT_ALIAS = "_preprContext";
12
- var PREPR_TYPE_ALIAS = "_preprType";
13
- var PREPR_DEFAULT_VARIANT = "ALL_OTHER_USERS";
14
-
15
- // src/core/variants/ast.ts
16
- import { parse } from "graphql/language/parser.js";
17
- var name = (value) => ({ kind: "Name", value });
18
- function selectionSet(selections) {
19
- return { kind: "SelectionSet", selections };
20
- }
21
- function contextField(withKey) {
22
- const fields = ["kind", "group_id", "variant_id"];
23
- if (withKey) fields.push("variant_key");
24
- return {
25
- kind: "Field",
26
- alias: name(PREPR_CONTEXT_ALIAS),
27
- name: name("_context"),
28
- selectionSet: selectionSet(
29
- fields.map(
30
- (field) => ({ kind: "Field", name: name(field) })
31
- )
32
- )
33
- };
34
- }
35
- function typenameField() {
36
- return {
37
- kind: "Field",
38
- alias: name(PREPR_TYPE_ALIAS),
39
- name: name("__typename")
40
- };
41
- }
42
- function inlineFragment(typeName, selections) {
43
- return {
44
- kind: "InlineFragment",
45
- typeCondition: { kind: "NamedType", name: name(typeName) },
46
- selectionSet: selectionSet(selections)
47
- };
48
- }
49
- function contextSelections(typeName, schema, onlyTypes, withType = true) {
50
- const fields = () => withType ? [contextField(true), typenameField()] : [contextField(false)];
51
- const type = schema.types[typeName];
52
- if (!type) return [];
53
- if (type.possibleTypes.length > 0) {
54
- return type.possibleTypes.filter(
55
- (member) => schema.types[member]?.hasContext && (!onlyTypes || onlyTypes.has(member))
56
- ).map((member) => inlineFragment(member, fields()));
57
- }
58
- return type.hasContext ? fields() : [];
59
- }
60
- function withoutPersonalizeArg(args = []) {
61
- return args.filter((arg) => arg.name.value !== "personalize");
62
- }
63
- function documentOf(document) {
64
- if (typeof document === "string") return parse(document);
65
- if (document instanceof String) return parse(document.toString());
66
- return document;
67
- }
68
- function collectVariables(node, used) {
69
- if (!node || typeof node !== "object") return;
70
- if (Array.isArray(node)) {
71
- for (const item of node) collectVariables(item, used);
72
- return;
73
- }
74
- const value = node;
75
- if (value.kind === "Variable") {
76
- used.add(value.name.value);
77
- return;
78
- }
79
- for (const key of Object.keys(value)) {
80
- if (key !== "loc") collectVariables(value[key], used);
81
- }
82
- }
6
+ } from "./chunk-S5RWVMDJ.js";
7
+ import {
8
+ PREPR_DEFAULT_VARIANT,
9
+ PREPR_SCHEMA_QUERY,
10
+ collectVariables,
11
+ contextOf,
12
+ decisionsFrom,
13
+ documentOf,
14
+ name,
15
+ personalizationPaths,
16
+ resolveQuery,
17
+ resolveVariants,
18
+ selectionSet,
19
+ toDecisionDocument,
20
+ toDecisionQuery,
21
+ toSchemaInfo,
22
+ toVariantsDocument,
23
+ toVariantsQuery
24
+ } from "./chunk-M3RBYJ5J.js";
25
+ import {
26
+ PreprError,
27
+ validatePreprToken
28
+ } from "./chunk-SF6TN4JR.js";
29
+ import "./chunk-TN6SNAR2.js";
83
30
 
84
- // src/core/variants/decision-document.ts
85
- function decisionSelectionSet(set, typeName, path, ctx) {
86
- const selections = [];
87
- for (const selection of set.selections) {
88
- if (selection.kind === "FragmentSpread") {
89
- const fragment = ctx.fragments[selection.name.value];
90
- if (!fragment) continue;
91
- const pruned = decisionSelectionSet(
92
- fragment.selectionSet,
93
- fragment.typeCondition.name.value,
94
- path,
95
- ctx
96
- );
97
- if (pruned) {
98
- selections.push(
99
- inlineFragment(fragment.typeCondition.name.value, [
100
- ...pruned.selections
101
- ])
102
- );
103
- }
104
- continue;
105
- }
106
- if (selection.kind === "InlineFragment") {
107
- const pruned = decisionSelectionSet(
108
- selection.selectionSet,
109
- selection.typeCondition?.name.value ?? typeName,
110
- path,
111
- ctx
112
- );
113
- if (pruned) selections.push({ ...selection, selectionSet: pruned });
114
- continue;
115
- }
116
- if (!selection.selectionSet) continue;
117
- const field = ctx.schema.types[typeName]?.fields[selection.name.value];
118
- if (!field) continue;
119
- const key = selection.alias?.value ?? selection.name.value;
120
- const fieldPath = path ? `${path}.${key}` : key;
121
- if (ctx.paths && !ctx.paths.prefixes.has(fieldPath)) continue;
122
- const child = decisionSelectionSet(
123
- selection.selectionSet,
124
- field.type,
125
- fieldPath,
126
- ctx
127
- );
128
- const groupTypes = ctx.paths?.groups.get(fieldPath);
129
- const holdsGroups = field.personalizable && (!ctx.paths || groupTypes !== void 0);
130
- if (holdsGroups) {
131
- selections.push({
132
- ...selection,
133
- arguments: withoutPersonalizeArg(selection.arguments),
134
- selectionSet: selectionSet([
135
- ...ctx.topLevelOnly ? [] : child?.selections ?? [],
136
- ...contextSelections(
137
- field.type,
138
- ctx.schema,
139
- groupTypes && !groupTypes.has("*") ? groupTypes : void 0,
140
- false
141
- )
142
- ])
143
- });
144
- } else if (child) {
145
- selections.push({
146
- ...selection,
147
- arguments: field.personalizable ? withoutPersonalizeArg(selection.arguments) : selection.arguments,
148
- selectionSet: child
149
- });
31
+ // src/core/graphql/cache-tags.ts
32
+ var MAX_TAGS = 128;
33
+ var MAX_TAG_LENGTH = 256;
34
+ var PREPR_ANY_ITEM_TAG = "prepr:any";
35
+ var preprItemTag = (id) => `prepr:${id}`;
36
+ var NOT_ALPHANUMERIC = /[^a-z0-9]/g;
37
+ var preprModelTag = (model) => `prepr:model:${model.toLowerCase().replace(NOT_ALPHANUMERIC, "")}`;
38
+ function preprCacheTags(data) {
39
+ const tags = /* @__PURE__ */ new Set();
40
+ const stack = [data];
41
+ while (stack.length > 0) {
42
+ const value = stack.pop();
43
+ if (typeof value !== "object" || value === null) continue;
44
+ const id = value._id;
45
+ if (typeof id === "string" && id !== "") {
46
+ const tag = preprItemTag(id);
47
+ if (tag.length > MAX_TAG_LENGTH) return [PREPR_ANY_ITEM_TAG];
48
+ tags.add(tag);
49
+ if (tags.size > MAX_TAGS) return [PREPR_ANY_ITEM_TAG];
150
50
  }
51
+ for (const child of Object.values(value)) stack.push(child);
151
52
  }
152
- return selections.length > 0 ? selectionSet(selections) : null;
153
- }
154
- function toDecisionDocument(document, schema, groupPaths, options) {
155
- const doc = documentOf(document);
156
- const fragments = {};
157
- for (const definition of doc.definitions) {
158
- if (definition.kind === "FragmentDefinition") {
159
- fragments[definition.name.value] = definition;
160
- }
161
- }
162
- const operation = doc.definitions.find(
163
- (definition) => definition.kind === "OperationDefinition"
164
- );
165
- if (!operation) return null;
166
- let paths;
167
- if (groupPaths) {
168
- const prefixes = /* @__PURE__ */ new Set();
169
- for (const groupPath of groupPaths.keys()) {
170
- const parts = groupPath.split(".");
171
- for (let i = 1; i <= parts.length; i++) {
172
- prefixes.add(parts.slice(0, i).join("."));
173
- }
174
- }
175
- paths = { groups: groupPaths, prefixes };
176
- }
177
- const pruned = decisionSelectionSet(
178
- operation.selectionSet,
179
- schema.queryType,
180
- "",
181
- { schema, fragments, paths, topLevelOnly: options?.topLevelOnly }
182
- );
183
- if (!pruned) return null;
184
- const used = /* @__PURE__ */ new Set();
185
- collectVariables(pruned, used);
186
- collectVariables(operation.directives, used);
187
- return {
188
- kind: "Document",
189
- definitions: [
190
- {
191
- ...operation,
192
- name: operation.name && name(`${operation.name.value}Decision`),
193
- variableDefinitions: (operation.variableDefinitions ?? []).filter(
194
- (definition) => used.has(definition.variable.name.value)
195
- ),
196
- selectionSet: pruned
197
- }
198
- ]
199
- };
53
+ return [...tags];
200
54
  }
201
55
 
202
56
  // src/core/variants/probe-document.ts
@@ -257,117 +111,6 @@ function toAbProbeDocument(document) {
257
111
  };
258
112
  }
259
113
 
260
- // src/core/variants/resolve.ts
261
- function personalizationPaths(data) {
262
- const paths = /* @__PURE__ */ new Map();
263
- const walk = (value, path) => {
264
- if (Array.isArray(value)) {
265
- for (const item of value) {
266
- if (contextOf(item)?.kind === "PERSONALIZATION") {
267
- const record = item;
268
- const type = record[PREPR_TYPE_ALIAS] ?? record.__typename;
269
- const types = paths.get(path) ?? /* @__PURE__ */ new Set();
270
- types.add(typeof type === "string" ? type : "*");
271
- paths.set(path, types);
272
- }
273
- walk(item, path);
274
- }
275
- return;
276
- }
277
- if (!value || typeof value !== "object") return;
278
- for (const [key, child] of Object.entries(value)) {
279
- if (key !== PREPR_CONTEXT_ALIAS && key !== PREPR_TYPE_ALIAS)
280
- walk(child, path ? `${path}.${key}` : key);
281
- }
282
- };
283
- walk(data, "");
284
- return paths;
285
- }
286
- function contextOf(item) {
287
- if (!item || typeof item !== "object") return null;
288
- const context = item[PREPR_CONTEXT_ALIAS];
289
- const ctx = context;
290
- return ctx?.kind && ctx.group_id ? ctx : null;
291
- }
292
- function decisionsFrom(data) {
293
- const decisions = /* @__PURE__ */ new Map();
294
- const walk = (value) => {
295
- if (Array.isArray(value)) return value.forEach(walk);
296
- if (!value || typeof value !== "object") return;
297
- const ctx = contextOf(value);
298
- if (ctx?.group_id && ctx.variant_id) {
299
- const ids = decisions.get(ctx.group_id) ?? [];
300
- if (!ids.includes(ctx.variant_id)) ids.push(ctx.variant_id);
301
- decisions.set(ctx.group_id, ids);
302
- }
303
- Object.values(value).forEach(walk);
304
- };
305
- walk(data);
306
- return decisions;
307
- }
308
- function chosenVariants(ctx, options) {
309
- const decided = options.decisions?.get(ctx.group_id);
310
- if (ctx.kind === "AB_TEST") {
311
- return options.bucket ? [options.bucket] : decided ?? ["A"];
312
- }
313
- return decided ?? [PREPR_DEFAULT_VARIANT];
314
- }
315
- function resolveVariants(data, options = {}) {
316
- const resolve = (value) => {
317
- if (Array.isArray(value)) {
318
- return value.filter((item) => {
319
- const ctx = contextOf(item);
320
- return !ctx || chosenVariants(ctx, options).includes(ctx.variant_id ?? "");
321
- }).map(resolve);
322
- }
323
- if (!value || typeof value !== "object") return value;
324
- const out = {};
325
- for (const [key, child] of Object.entries(value)) out[key] = resolve(child);
326
- return out;
327
- };
328
- return resolve(data);
329
- }
330
-
331
- // src/core/variants/schema.ts
332
- var PREPR_SCHEMA_QUERY = `query PreprPersonalizationSchema {
333
- __schema {
334
- queryType { name }
335
- types {
336
- name
337
- possibleTypes { name }
338
- fields {
339
- name
340
- args { name }
341
- type { name ofType { name ofType { name ofType { name ofType { name } } } } }
342
- }
343
- }
344
- }
345
- }`;
346
- function namedType(ref) {
347
- let current = ref;
348
- while (current && !current.name) current = current.ofType;
349
- return current?.name ?? "";
350
- }
351
- function toSchemaInfo(introspection) {
352
- const types = {};
353
- for (const type of introspection.__schema.types) {
354
- if (type.name.startsWith("__")) continue;
355
- const fields = {};
356
- for (const field of type.fields ?? []) {
357
- fields[field.name] = {
358
- type: namedType(field.type),
359
- personalizable: field.args.some((arg) => arg.name === "personalize")
360
- };
361
- }
362
- types[type.name] = {
363
- fields,
364
- possibleTypes: (type.possibleTypes ?? []).map((t) => t.name),
365
- hasContext: "_context" in fields
366
- };
367
- }
368
- return { queryType: introspection.__schema.queryType.name, types };
369
- }
370
-
371
114
  // src/core/variants/stack.ts
372
115
  function containsKind(value, kind) {
373
116
  if (Array.isArray(value))
@@ -414,124 +157,8 @@ function preprVariantProps(item) {
414
157
  return key ? { "data-prepr-variant-key": key } : {};
415
158
  }
416
159
 
417
- // src/core/variants/variants-document.ts
418
- function variantsSelectionSet(set, typeName, schema) {
419
- const selections = set.selections.map((selection) => {
420
- if (selection.kind === "InlineFragment") {
421
- return {
422
- ...selection,
423
- selectionSet: variantsSelectionSet(
424
- selection.selectionSet,
425
- selection.typeCondition?.name.value ?? typeName,
426
- schema
427
- )
428
- };
429
- }
430
- if (selection.kind !== "Field" || !selection.selectionSet) return selection;
431
- const field = schema.types[typeName]?.fields[selection.name.value];
432
- if (!field) return selection;
433
- const child = variantsSelectionSet(
434
- selection.selectionSet,
435
- field.type,
436
- schema
437
- );
438
- if (!field.personalizable) return { ...selection, selectionSet: child };
439
- return {
440
- ...selection,
441
- arguments: [
442
- ...withoutPersonalizeArg(selection.arguments),
443
- {
444
- kind: "Argument",
445
- name: name("personalize"),
446
- value: { kind: "BooleanValue", value: false }
447
- }
448
- ],
449
- selectionSet: selectionSet([
450
- ...child.selections,
451
- ...contextSelections(field.type, schema)
452
- ])
453
- };
454
- });
455
- return { ...set, selections };
456
- }
457
- function toVariantsDocument(document, schema) {
458
- const doc = documentOf(document);
459
- return {
460
- ...doc,
461
- definitions: doc.definitions.map((definition) => {
462
- if (definition.kind === "OperationDefinition") {
463
- return {
464
- ...definition,
465
- selectionSet: variantsSelectionSet(
466
- definition.selectionSet,
467
- schema.queryType,
468
- schema
469
- )
470
- };
471
- }
472
- if (definition.kind === "FragmentDefinition") {
473
- return {
474
- ...definition,
475
- selectionSet: variantsSelectionSet(
476
- definition.selectionSet,
477
- definition.typeCondition.name.value,
478
- schema
479
- )
480
- };
481
- }
482
- return definition;
483
- })
484
- };
485
- }
486
-
487
160
  // src/core/graphql/transport.ts
488
161
  import { VERCEL_STEGA_REGEX } from "@vercel/stega";
489
-
490
- // src/core/graphql/document.ts
491
- import { print } from "graphql/language/printer.js";
492
- import { stripIgnoredCharacters } from "graphql/utilities/stripIgnoredCharacters.js";
493
- var printed = /* @__PURE__ */ new WeakMap();
494
- function isDocumentNode(value) {
495
- return typeof value === "object" && value !== null && value.kind === "Document" && Array.isArray(value.definitions);
496
- }
497
- function invalidDocument(originalError) {
498
- return new PreprError(
499
- "Expected a GraphQL query string, TypedDocumentString or DocumentNode",
500
- "INVALID_DOCUMENT",
501
- "createPreprClient",
502
- originalError
503
- );
504
- }
505
- var minified = /* @__PURE__ */ new Map();
506
- var MINIFIED_CACHE_LIMIT = 500;
507
- function minify(query) {
508
- const cached = minified.get(query);
509
- if (cached !== void 0) return cached;
510
- let result = query;
511
- try {
512
- result = stripIgnoredCharacters(query);
513
- } catch {
514
- }
515
- if (minified.size < MINIFIED_CACHE_LIMIT) minified.set(query, result);
516
- return result;
517
- }
518
- function resolveQuery(document) {
519
- if (typeof document === "string") return minify(document);
520
- if (document instanceof String) return minify(document.toString());
521
- if (!isDocumentNode(document)) throw invalidDocument();
522
- let query = printed.get(document);
523
- if (query === void 0) {
524
- try {
525
- query = minify(print(document));
526
- } catch (error) {
527
- throw invalidDocument(error instanceof Error ? error : void 0);
528
- }
529
- printed.set(document, query);
530
- }
531
- return query;
532
- }
533
-
534
- // src/core/graphql/transport.ts
535
162
  var OPERATION_NAME = /\b(?:query|mutation|subscription)\s+([_A-Za-z][_0-9A-Za-z]*)/;
536
163
  var STEGA_RAW = new RegExp(
537
164
  VERCEL_STEGA_REGEX.source,
@@ -702,6 +329,7 @@ function createVaryProbe(run, options) {
702
329
  }
703
330
 
704
331
  // src/core/graphql/client.ts
332
+ var clientSchemas = /* @__PURE__ */ new WeakMap();
705
333
  function isParseableUrl(url) {
706
334
  try {
707
335
  new URL(url);
@@ -710,16 +338,18 @@ function isParseableUrl(url) {
710
338
  return false;
711
339
  }
712
340
  }
713
- function createPreprClient(options) {
714
- const { url } = options;
341
+ function assertPreprUrl(url, source) {
715
342
  validatePreprToken(url);
716
343
  if (!isParseableUrl(url)) {
717
344
  throw new PreprError(
718
345
  "Prepr GraphQL URL is not a valid URL",
719
346
  "INVALID_TOKEN",
720
- "createPreprClient"
347
+ source
721
348
  );
722
349
  }
350
+ }
351
+ function createPreprClient(options) {
352
+ assertPreprUrl(options.url, "createPreprClient");
723
353
  const run = createTransport(options);
724
354
  const probeVary = createVaryProbe(run, options);
725
355
  let schema;
@@ -736,7 +366,7 @@ function createPreprClient(options) {
736
366
  ));
737
367
  const variantsDocuments = /* @__PURE__ */ new Map();
738
368
  const decisionDocuments = /* @__PURE__ */ new Map();
739
- return {
369
+ const client = {
740
370
  async query(document, variables, queryOptions = {}) {
741
371
  const { variants, ...rest } = queryOptions;
742
372
  if (!variants) return run(document, variables, rest);
@@ -748,10 +378,10 @@ function createPreprClient(options) {
748
378
  return run(derived, variables, rest);
749
379
  },
750
380
  async decide(document, variables, queryOptions = {}) {
751
- const { from, topLevelOnly, ...rest } = queryOptions;
381
+ const { from, ...rest } = queryOptions;
752
382
  const paths = from === void 0 ? void 0 : personalizationPaths(from);
753
383
  if (paths && paths.size === 0) return /* @__PURE__ */ new Map();
754
- const signature = paths ? [...paths].map(([path, types]) => `${path}:${[...types].sort().join(",")}`).sort().join("|") : topLevelOnly ? "top" : "*";
384
+ const signature = paths ? [...paths].map(([path, types]) => `${path}:${[...types].sort().join(",")}`).sort().join("|") : "*";
755
385
  let byPaths = decisionDocuments.get(document);
756
386
  if (!byPaths) {
757
387
  byPaths = /* @__PURE__ */ new Map();
@@ -759,9 +389,7 @@ function createPreprClient(options) {
759
389
  }
760
390
  let derived = byPaths.get(signature);
761
391
  if (derived === void 0) {
762
- derived = toDecisionDocument(document, await loadSchema(), paths, {
763
- topLevelOnly: !paths && topLevelOnly
764
- });
392
+ derived = toDecisionDocument(document, await loadSchema(), paths);
765
393
  byPaths.set(signature, derived);
766
394
  }
767
395
  if (!derived) return /* @__PURE__ */ new Map();
@@ -775,13 +403,46 @@ function createPreprClient(options) {
775
403
  (vary) => vary === null || SEGMENTS_VARY.test(vary)
776
404
  )
777
405
  };
406
+ clientSchemas.set(client, loadSchema);
407
+ return client;
408
+ }
409
+
410
+ // src/core/graphql/schema-loader.ts
411
+ var schemas = /* @__PURE__ */ new Map();
412
+ async function loadPreprSchema(url, options = {}) {
413
+ assertPreprUrl(url, "loadPreprSchema");
414
+ let schema = schemas.get(url);
415
+ if (!schema) {
416
+ const run = createTransport({ url, fetch: options.fetch, stega: "none" });
417
+ schema = run(
418
+ PREPR_SCHEMA_QUERY
419
+ ).then((result) => toSchemaInfo(result.data)).catch((error) => {
420
+ schemas.delete(url);
421
+ if (error instanceof PreprError) throw error;
422
+ throw new PreprError(
423
+ "Prepr schema response is not an introspection result",
424
+ "INVALID_RESPONSE",
425
+ "loadPreprSchema",
426
+ error instanceof Error ? error : void 0
427
+ );
428
+ });
429
+ schemas.set(url, schema);
430
+ }
431
+ return schema;
778
432
  }
779
433
  export {
434
+ PREPR_ANY_ITEM_TAG,
780
435
  PREPR_DEFAULT_VARIANT,
781
436
  PreprError,
782
437
  createPreprClient,
438
+ decisionsFrom,
783
439
  isPersonalizedResponse,
440
+ loadPreprSchema,
441
+ preprCacheTags,
442
+ preprModelTag,
784
443
  preprVariantProps,
785
444
  resolveVariants,
786
- splitStack
445
+ splitStack,
446
+ toDecisionQuery,
447
+ toVariantsQuery
787
448
  };
package/dist/index.cjs CHANGED
@@ -45,7 +45,7 @@ __export(src_exports, {
45
45
  module.exports = __toCommonJS(src_exports);
46
46
 
47
47
  // src/version.ts
48
- var VERSION = "0.6.0-alpha.0";
48
+ var VERSION = "0.6.0-alpha.10";
49
49
 
50
50
  // src/core/features.ts
51
51
  function isEnabled(config) {
package/dist/index.d.cts CHANGED
@@ -7,7 +7,7 @@ export { P as PreprPixelConfig, l as loadTrackingPixel, s as setTrackingParam, t
7
7
  * Package version; must match package.json. Lives in its own leaf module so
8
8
  * core can import it without cycling through the barrel.
9
9
  */
10
- declare const VERSION = "0.6.0-alpha.0";
10
+ declare const VERSION = "0.6.0-alpha.10";
11
11
 
12
12
  /**
13
13
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { P as PreprPixelConfig, l as loadTrackingPixel, s as setTrackingParam, t
7
7
  * Package version; must match package.json. Lives in its own leaf module so
8
8
  * core can import it without cycling through the barrel.
9
9
  */
10
- declare const VERSION = "0.6.0-alpha.0";
10
+ declare const VERSION = "0.6.0-alpha.10";
11
11
 
12
12
  /**
13
13
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.js CHANGED
@@ -15,7 +15,13 @@ import {
15
15
  loadTrackingPixel,
16
16
  setTrackingParam,
17
17
  trackEvent
18
- } from "./chunk-BJ2LBLWO.js";
18
+ } from "./chunk-LIDUJWWJ.js";
19
+ import {
20
+ isPersonalizedResponse
21
+ } from "./chunk-3NCEVJJ3.js";
22
+ import {
23
+ stegaClean
24
+ } from "./chunk-S5RWVMDJ.js";
19
25
  import {
20
26
  PreprError,
21
27
  extractAccessToken,
@@ -25,14 +31,12 @@ import {
25
31
  getPreprHeadersFromHeaders,
26
32
  getPreprUUIDFromHeaders,
27
33
  getToolbarPropsFromHeaders,
28
- isPersonalizedResponse,
29
34
  validatePreprToken
30
- } from "./chunk-YR7P4IWE.js";
35
+ } from "./chunk-SF6TN4JR.js";
31
36
  import {
32
37
  VERSION,
33
- resolveFeatures,
34
- stegaClean
35
- } from "./chunk-DGZA7KX7.js";
38
+ resolveFeatures
39
+ } from "./chunk-TN6SNAR2.js";
36
40
 
37
41
  // src/core/middleware.ts
38
42
  var UTM_PARAMS = [