@preprio/toolkit 0.6.0-alpha.0 → 0.6.0-alpha.2

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 (52) hide show
  1. package/README.md +107 -0
  2. package/dist/astro/{chunk-3UVUDDNY.js → chunk-U7VUQL57.js} +1 -1
  3. package/dist/astro/graphql.cjs +96 -49
  4. package/dist/astro/graphql.d.cts +75 -1
  5. package/dist/astro/graphql.d.ts +75 -1
  6. package/dist/astro/graphql.js +92 -49
  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-7HSMUULV.js +452 -0
  11. package/dist/{chunk-BJ2LBLWO.js → chunk-DS3QA3HF.js} +6 -4
  12. package/dist/{chunk-DGZA7KX7.js → chunk-S5RWVMDJ.js} +0 -24
  13. package/dist/{chunk-YR7P4IWE.js → chunk-UYYTYSOD.js} +1 -9
  14. package/dist/chunk-VV4PRH7W.js +26 -0
  15. package/dist/graphql/codegen.cjs +510 -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 +96 -49
  20. package/dist/graphql.d.cts +75 -1
  21. package/dist/graphql.d.ts +75 -1
  22. package/dist/graphql.js +60 -428
  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-U4HXENF7.js → chunk-ZIUKEGEN.js} +1 -1
  28. package/dist/nextjs/components.cjs +12 -8
  29. package/dist/nextjs/components.js +14 -9
  30. package/dist/nextjs/graphql.cjs +96 -49
  31. package/dist/nextjs/graphql.d.cts +75 -1
  32. package/dist/nextjs/graphql.d.ts +75 -1
  33. package/dist/nextjs/graphql.js +92 -49
  34. package/dist/nextjs/index.cjs +1 -1
  35. package/dist/nextjs/index.js +1 -1
  36. package/dist/nuxt/{chunk-P6ENNAEE.js → chunk-GMWF6PQ5.js} +1 -1
  37. package/dist/nuxt/graphql.cjs +96 -49
  38. package/dist/nuxt/graphql.d.cts +75 -1
  39. package/dist/nuxt/graphql.d.ts +75 -1
  40. package/dist/nuxt/graphql.js +92 -49
  41. package/dist/nuxt/index.cjs +1 -1
  42. package/dist/nuxt/index.js +1 -1
  43. package/dist/react/components.cjs +1 -1
  44. package/dist/react/components.js +1 -1
  45. package/dist/sveltekit/{chunk-FSARVMG5.js → chunk-5SQUG2L4.js} +1 -1
  46. package/dist/sveltekit/graphql.cjs +96 -49
  47. package/dist/sveltekit/graphql.d.cts +75 -1
  48. package/dist/sveltekit/graphql.d.ts +75 -1
  49. package/dist/sveltekit/graphql.js +92 -49
  50. package/dist/sveltekit/index.cjs +1 -1
  51. package/dist/sveltekit/index.js +1 -1
  52. package/package.json +6 -1
@@ -3,7 +3,7 @@ import {
3
3
  getPreprHeadersFromHeaders,
4
4
  isPersonalizedResponse,
5
5
  validatePreprToken
6
- } from "./chunk-3UVUDDNY.js";
6
+ } from "./chunk-U7VUQL57.js";
7
7
 
8
8
  // src/core/variants/constants.ts
9
9
  var PREPR_CONTEXT_ALIAS = "_preprContext";
@@ -482,6 +482,63 @@ function toVariantsDocument(document2, schema) {
482
482
  };
483
483
  }
484
484
 
485
+ // src/core/graphql/document.ts
486
+ import { print } from "graphql/language/printer.js";
487
+ import { stripIgnoredCharacters } from "graphql/utilities/stripIgnoredCharacters.js";
488
+ var printed = /* @__PURE__ */ new WeakMap();
489
+ function isDocumentNode(value) {
490
+ return typeof value === "object" && value !== null && value.kind === "Document" && Array.isArray(value.definitions);
491
+ }
492
+ function invalidDocument(originalError) {
493
+ return new PreprError(
494
+ "Expected a GraphQL query string, TypedDocumentString or DocumentNode",
495
+ "INVALID_DOCUMENT",
496
+ "createPreprClient",
497
+ originalError
498
+ );
499
+ }
500
+ var minified = /* @__PURE__ */ new Map();
501
+ var MINIFIED_CACHE_LIMIT = 500;
502
+ function minify(query) {
503
+ const cached = minified.get(query);
504
+ if (cached !== void 0) return cached;
505
+ let result = query;
506
+ try {
507
+ result = stripIgnoredCharacters(query);
508
+ } catch {
509
+ }
510
+ if (minified.size < MINIFIED_CACHE_LIMIT) minified.set(query, result);
511
+ return result;
512
+ }
513
+ function resolveQuery(document2) {
514
+ if (typeof document2 === "string") return minify(document2);
515
+ if (document2 instanceof String) return minify(document2.toString());
516
+ if (!isDocumentNode(document2)) throw invalidDocument();
517
+ let query = printed.get(document2);
518
+ if (query === void 0) {
519
+ try {
520
+ query = minify(print(document2));
521
+ } catch (error) {
522
+ throw invalidDocument(error instanceof Error ? error : void 0);
523
+ }
524
+ printed.set(document2, query);
525
+ }
526
+ return query;
527
+ }
528
+
529
+ // src/core/variants/queries.ts
530
+ function toVariantsQuery(document2, schema) {
531
+ return resolveQuery(toVariantsDocument(document2, schema));
532
+ }
533
+ function toDecisionQuery(document2, schema, options = {}) {
534
+ const paths = options.from === void 0 ? void 0 : personalizationPaths(options.from);
535
+ if (paths && paths.size === 0) return null;
536
+ const decision = toDecisionDocument(document2, schema, paths, {
537
+ topLevelOnly: !paths && options.topLevelOnly
538
+ });
539
+ return decision ? resolveQuery(decision) : null;
540
+ }
541
+
485
542
  // src/core/graphql/transport.ts
486
543
  import { VERCEL_STEGA_REGEX } from "@vercel/stega";
487
544
 
@@ -534,50 +591,6 @@ function stegaClean(text) {
534
591
  return vercelStegaClean(text);
535
592
  }
536
593
 
537
- // src/core/graphql/document.ts
538
- import { print } from "graphql/language/printer.js";
539
- import { stripIgnoredCharacters } from "graphql/utilities/stripIgnoredCharacters.js";
540
- var printed = /* @__PURE__ */ new WeakMap();
541
- function isDocumentNode(value) {
542
- return typeof value === "object" && value !== null && value.kind === "Document" && Array.isArray(value.definitions);
543
- }
544
- function invalidDocument(originalError) {
545
- return new PreprError(
546
- "Expected a GraphQL query string, TypedDocumentString or DocumentNode",
547
- "INVALID_DOCUMENT",
548
- "createPreprClient",
549
- originalError
550
- );
551
- }
552
- var minified = /* @__PURE__ */ new Map();
553
- var MINIFIED_CACHE_LIMIT = 500;
554
- function minify(query) {
555
- const cached = minified.get(query);
556
- if (cached !== void 0) return cached;
557
- let result = query;
558
- try {
559
- result = stripIgnoredCharacters(query);
560
- } catch {
561
- }
562
- if (minified.size < MINIFIED_CACHE_LIMIT) minified.set(query, result);
563
- return result;
564
- }
565
- function resolveQuery(document2) {
566
- if (typeof document2 === "string") return minify(document2);
567
- if (document2 instanceof String) return minify(document2.toString());
568
- if (!isDocumentNode(document2)) throw invalidDocument();
569
- let query = printed.get(document2);
570
- if (query === void 0) {
571
- try {
572
- query = minify(print(document2));
573
- } catch (error) {
574
- throw invalidDocument(error instanceof Error ? error : void 0);
575
- }
576
- printed.set(document2, query);
577
- }
578
- return query;
579
- }
580
-
581
594
  // src/core/graphql/transport.ts
582
595
  var OPERATION_NAME = /\b(?:query|mutation|subscription)\s+([_A-Za-z][_0-9A-Za-z]*)/;
583
596
  var STEGA_RAW = new RegExp(
@@ -764,16 +777,18 @@ function isParseableUrl(url) {
764
777
  return false;
765
778
  }
766
779
  }
767
- function createPreprClient(options) {
768
- const { url } = options;
780
+ function assertPreprUrl(url, source) {
769
781
  validatePreprToken(url);
770
782
  if (!isParseableUrl(url)) {
771
783
  throw new PreprError(
772
784
  "Prepr GraphQL URL is not a valid URL",
773
785
  "INVALID_TOKEN",
774
- "createPreprClient"
786
+ source
775
787
  );
776
788
  }
789
+ }
790
+ function createPreprClient(options) {
791
+ assertPreprUrl(options.url, "createPreprClient");
777
792
  const run = createTransport(options);
778
793
  const probeVary = createVaryProbe(run, options);
779
794
  let schema;
@@ -876,6 +891,30 @@ function createEventClient(options, adapter) {
876
891
  };
877
892
  }
878
893
 
894
+ // src/core/graphql/schema-loader.ts
895
+ var schemas = /* @__PURE__ */ new Map();
896
+ async function loadPreprSchema(url, options = {}) {
897
+ assertPreprUrl(url, "loadPreprSchema");
898
+ let schema = schemas.get(url);
899
+ if (!schema) {
900
+ const run = createTransport({ url, fetch: options.fetch, stega: "none" });
901
+ schema = run(
902
+ PREPR_SCHEMA_QUERY
903
+ ).then((result) => toSchemaInfo(result.data)).catch((error) => {
904
+ schemas.delete(url);
905
+ if (error instanceof PreprError) throw error;
906
+ throw new PreprError(
907
+ "Prepr schema response is not an introspection result",
908
+ "INVALID_RESPONSE",
909
+ "loadPreprSchema",
910
+ error instanceof Error ? error : void 0
911
+ );
912
+ });
913
+ schemas.set(url, schema);
914
+ }
915
+ return schema;
916
+ }
917
+
879
918
  // src/astro/graphql.ts
880
919
  function createPreprClient2(options) {
881
920
  return createEventClient(options, {
@@ -886,8 +925,12 @@ export {
886
925
  PREPR_DEFAULT_VARIANT,
887
926
  PreprError,
888
927
  createPreprClient2 as createPreprClient,
928
+ decisionsFrom,
889
929
  isPersonalizedResponse,
930
+ loadPreprSchema,
890
931
  preprVariantProps,
891
932
  resolveVariants,
892
- splitStack
933
+ splitStack,
934
+ toDecisionQuery,
935
+ toVariantsQuery
893
936
  };
@@ -31,7 +31,7 @@ __export(astro_exports, {
31
31
  module.exports = __toCommonJS(astro_exports);
32
32
 
33
33
  // src/version.ts
34
- var VERSION = "0.6.0-alpha.0";
34
+ var VERSION = "0.6.0-alpha.2";
35
35
 
36
36
  // src/core/features.ts
37
37
  function isEnabled(config) {
@@ -7,7 +7,7 @@ import {
7
7
  getToolbarPropsFromHeaders,
8
8
  isPersonalizedResponse,
9
9
  resolveFeatures
10
- } from "./chunk-3UVUDDNY.js";
10
+ } from "./chunk-U7VUQL57.js";
11
11
 
12
12
  // src/core/constants.ts
13
13
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -0,0 +1,10 @@
1
+ // src/core/personalization.ts
2
+ var PERSONALIZED_VARY = /\bPrepr-(Segments|ABTesting)/i;
3
+ function isPersonalizedResponse(source) {
4
+ const headers = "headers" in source ? source.headers : source;
5
+ return PERSONALIZED_VARY.test(headers.get("vary") ?? "");
6
+ }
7
+
8
+ export {
9
+ isPersonalizedResponse
10
+ };
@@ -0,0 +1,452 @@
1
+ import {
2
+ PreprError
3
+ } from "./chunk-UYYTYSOD.js";
4
+
5
+ // src/core/variants/constants.ts
6
+ var PREPR_CONTEXT_ALIAS = "_preprContext";
7
+ var PREPR_TYPE_ALIAS = "_preprType";
8
+ var PREPR_DEFAULT_VARIANT = "ALL_OTHER_USERS";
9
+
10
+ // src/core/variants/resolve.ts
11
+ function personalizationPaths(data) {
12
+ const paths = /* @__PURE__ */ new Map();
13
+ const walk = (value, path) => {
14
+ if (Array.isArray(value)) {
15
+ for (const item of value) {
16
+ if (contextOf(item)?.kind === "PERSONALIZATION") {
17
+ const record = item;
18
+ const type = record[PREPR_TYPE_ALIAS] ?? record.__typename;
19
+ const types = paths.get(path) ?? /* @__PURE__ */ new Set();
20
+ types.add(typeof type === "string" ? type : "*");
21
+ paths.set(path, types);
22
+ }
23
+ walk(item, path);
24
+ }
25
+ return;
26
+ }
27
+ if (!value || typeof value !== "object") return;
28
+ for (const [key, child] of Object.entries(value)) {
29
+ if (key !== PREPR_CONTEXT_ALIAS && key !== PREPR_TYPE_ALIAS)
30
+ walk(child, path ? `${path}.${key}` : key);
31
+ }
32
+ };
33
+ walk(data, "");
34
+ return paths;
35
+ }
36
+ function contextOf(item) {
37
+ if (!item || typeof item !== "object") return null;
38
+ const context = item[PREPR_CONTEXT_ALIAS];
39
+ const ctx = context;
40
+ return ctx?.kind && ctx.group_id ? ctx : null;
41
+ }
42
+ function decisionsFrom(data) {
43
+ const decisions = /* @__PURE__ */ new Map();
44
+ const walk = (value) => {
45
+ if (Array.isArray(value)) return value.forEach(walk);
46
+ if (!value || typeof value !== "object") return;
47
+ const ctx = contextOf(value);
48
+ if (ctx?.group_id && ctx.variant_id) {
49
+ const ids = decisions.get(ctx.group_id) ?? [];
50
+ if (!ids.includes(ctx.variant_id)) ids.push(ctx.variant_id);
51
+ decisions.set(ctx.group_id, ids);
52
+ }
53
+ Object.values(value).forEach(walk);
54
+ };
55
+ walk(data);
56
+ return decisions;
57
+ }
58
+ function chosenVariants(ctx, options) {
59
+ const decided = options.decisions?.get(ctx.group_id);
60
+ if (ctx.kind === "AB_TEST") {
61
+ return options.bucket ? [options.bucket] : decided ?? ["A"];
62
+ }
63
+ return decided ?? [PREPR_DEFAULT_VARIANT];
64
+ }
65
+ function resolveVariants(data, options = {}) {
66
+ const resolve = (value) => {
67
+ if (Array.isArray(value)) {
68
+ return value.filter((item) => {
69
+ const ctx = contextOf(item);
70
+ return !ctx || chosenVariants(ctx, options).includes(ctx.variant_id ?? "");
71
+ }).map(resolve);
72
+ }
73
+ if (!value || typeof value !== "object") return value;
74
+ const out = {};
75
+ for (const [key, child] of Object.entries(value)) out[key] = resolve(child);
76
+ return out;
77
+ };
78
+ return resolve(data);
79
+ }
80
+
81
+ // src/core/variants/schema.ts
82
+ var PREPR_SCHEMA_QUERY = `query PreprPersonalizationSchema {
83
+ __schema {
84
+ queryType { name }
85
+ types {
86
+ name
87
+ possibleTypes { name }
88
+ fields {
89
+ name
90
+ args { name }
91
+ type { name ofType { name ofType { name ofType { name ofType { name } } } } }
92
+ }
93
+ }
94
+ }
95
+ }`;
96
+ function namedType(ref) {
97
+ let current = ref;
98
+ while (current && !current.name) current = current.ofType;
99
+ return current?.name ?? "";
100
+ }
101
+ function toSchemaInfo(introspection) {
102
+ const types = {};
103
+ for (const type of introspection.__schema.types) {
104
+ if (type.name.startsWith("__")) continue;
105
+ const fields = {};
106
+ for (const field of type.fields ?? []) {
107
+ fields[field.name] = {
108
+ type: namedType(field.type),
109
+ personalizable: field.args.some((arg) => arg.name === "personalize")
110
+ };
111
+ }
112
+ types[type.name] = {
113
+ fields,
114
+ possibleTypes: (type.possibleTypes ?? []).map((t) => t.name),
115
+ hasContext: "_context" in fields
116
+ };
117
+ }
118
+ return { queryType: introspection.__schema.queryType.name, types };
119
+ }
120
+
121
+ // src/core/graphql/document.ts
122
+ import { print } from "graphql/language/printer.js";
123
+ import { stripIgnoredCharacters } from "graphql/utilities/stripIgnoredCharacters.js";
124
+ var printed = /* @__PURE__ */ new WeakMap();
125
+ function isDocumentNode(value) {
126
+ return typeof value === "object" && value !== null && value.kind === "Document" && Array.isArray(value.definitions);
127
+ }
128
+ function invalidDocument(originalError) {
129
+ return new PreprError(
130
+ "Expected a GraphQL query string, TypedDocumentString or DocumentNode",
131
+ "INVALID_DOCUMENT",
132
+ "createPreprClient",
133
+ originalError
134
+ );
135
+ }
136
+ var minified = /* @__PURE__ */ new Map();
137
+ var MINIFIED_CACHE_LIMIT = 500;
138
+ function minify(query) {
139
+ const cached = minified.get(query);
140
+ if (cached !== void 0) return cached;
141
+ let result = query;
142
+ try {
143
+ result = stripIgnoredCharacters(query);
144
+ } catch {
145
+ }
146
+ if (minified.size < MINIFIED_CACHE_LIMIT) minified.set(query, result);
147
+ return result;
148
+ }
149
+ function resolveQuery(document) {
150
+ if (typeof document === "string") return minify(document);
151
+ if (document instanceof String) return minify(document.toString());
152
+ if (!isDocumentNode(document)) throw invalidDocument();
153
+ let query = printed.get(document);
154
+ if (query === void 0) {
155
+ try {
156
+ query = minify(print(document));
157
+ } catch (error) {
158
+ throw invalidDocument(error instanceof Error ? error : void 0);
159
+ }
160
+ printed.set(document, query);
161
+ }
162
+ return query;
163
+ }
164
+
165
+ // src/core/variants/ast.ts
166
+ import { parse } from "graphql/language/parser.js";
167
+ var name = (value) => ({ kind: "Name", value });
168
+ function selectionSet(selections) {
169
+ return { kind: "SelectionSet", selections };
170
+ }
171
+ function contextField(withKey) {
172
+ const fields = ["kind", "group_id", "variant_id"];
173
+ if (withKey) fields.push("variant_key");
174
+ return {
175
+ kind: "Field",
176
+ alias: name(PREPR_CONTEXT_ALIAS),
177
+ name: name("_context"),
178
+ selectionSet: selectionSet(
179
+ fields.map(
180
+ (field) => ({ kind: "Field", name: name(field) })
181
+ )
182
+ )
183
+ };
184
+ }
185
+ function typenameField() {
186
+ return {
187
+ kind: "Field",
188
+ alias: name(PREPR_TYPE_ALIAS),
189
+ name: name("__typename")
190
+ };
191
+ }
192
+ function inlineFragment(typeName, selections) {
193
+ return {
194
+ kind: "InlineFragment",
195
+ typeCondition: { kind: "NamedType", name: name(typeName) },
196
+ selectionSet: selectionSet(selections)
197
+ };
198
+ }
199
+ function contextSelections(typeName, schema, onlyTypes, withType = true) {
200
+ const fields = () => withType ? [contextField(true), typenameField()] : [contextField(false)];
201
+ const type = schema.types[typeName];
202
+ if (!type) return [];
203
+ if (type.possibleTypes.length > 0) {
204
+ return type.possibleTypes.filter(
205
+ (member) => schema.types[member]?.hasContext && (!onlyTypes || onlyTypes.has(member))
206
+ ).map((member) => inlineFragment(member, fields()));
207
+ }
208
+ return type.hasContext ? fields() : [];
209
+ }
210
+ function withoutPersonalizeArg(args = []) {
211
+ return args.filter((arg) => arg.name.value !== "personalize");
212
+ }
213
+ function documentOf(document) {
214
+ if (typeof document === "string") return parse(document);
215
+ if (document instanceof String) return parse(document.toString());
216
+ return document;
217
+ }
218
+ function collectVariables(node, used) {
219
+ if (!node || typeof node !== "object") return;
220
+ if (Array.isArray(node)) {
221
+ for (const item of node) collectVariables(item, used);
222
+ return;
223
+ }
224
+ const value = node;
225
+ if (value.kind === "Variable") {
226
+ used.add(value.name.value);
227
+ return;
228
+ }
229
+ for (const key of Object.keys(value)) {
230
+ if (key !== "loc") collectVariables(value[key], used);
231
+ }
232
+ }
233
+
234
+ // src/core/variants/decision-document.ts
235
+ function decisionSelectionSet(set, typeName, path, ctx) {
236
+ const selections = [];
237
+ for (const selection of set.selections) {
238
+ if (selection.kind === "FragmentSpread") {
239
+ const fragment = ctx.fragments[selection.name.value];
240
+ if (!fragment) continue;
241
+ const pruned = decisionSelectionSet(
242
+ fragment.selectionSet,
243
+ fragment.typeCondition.name.value,
244
+ path,
245
+ ctx
246
+ );
247
+ if (pruned) {
248
+ selections.push(
249
+ inlineFragment(fragment.typeCondition.name.value, [
250
+ ...pruned.selections
251
+ ])
252
+ );
253
+ }
254
+ continue;
255
+ }
256
+ if (selection.kind === "InlineFragment") {
257
+ const pruned = decisionSelectionSet(
258
+ selection.selectionSet,
259
+ selection.typeCondition?.name.value ?? typeName,
260
+ path,
261
+ ctx
262
+ );
263
+ if (pruned) selections.push({ ...selection, selectionSet: pruned });
264
+ continue;
265
+ }
266
+ if (!selection.selectionSet) continue;
267
+ const field = ctx.schema.types[typeName]?.fields[selection.name.value];
268
+ if (!field) continue;
269
+ const key = selection.alias?.value ?? selection.name.value;
270
+ const fieldPath = path ? `${path}.${key}` : key;
271
+ if (ctx.paths && !ctx.paths.prefixes.has(fieldPath)) continue;
272
+ const child = decisionSelectionSet(
273
+ selection.selectionSet,
274
+ field.type,
275
+ fieldPath,
276
+ ctx
277
+ );
278
+ const groupTypes = ctx.paths?.groups.get(fieldPath);
279
+ const holdsGroups = field.personalizable && (!ctx.paths || groupTypes !== void 0);
280
+ if (holdsGroups) {
281
+ selections.push({
282
+ ...selection,
283
+ arguments: withoutPersonalizeArg(selection.arguments),
284
+ selectionSet: selectionSet([
285
+ ...ctx.topLevelOnly ? [] : child?.selections ?? [],
286
+ ...contextSelections(
287
+ field.type,
288
+ ctx.schema,
289
+ groupTypes && !groupTypes.has("*") ? groupTypes : void 0,
290
+ false
291
+ )
292
+ ])
293
+ });
294
+ } else if (child) {
295
+ selections.push({
296
+ ...selection,
297
+ arguments: field.personalizable ? withoutPersonalizeArg(selection.arguments) : selection.arguments,
298
+ selectionSet: child
299
+ });
300
+ }
301
+ }
302
+ return selections.length > 0 ? selectionSet(selections) : null;
303
+ }
304
+ function toDecisionDocument(document, schema, groupPaths, options) {
305
+ const doc = documentOf(document);
306
+ const fragments = {};
307
+ for (const definition of doc.definitions) {
308
+ if (definition.kind === "FragmentDefinition") {
309
+ fragments[definition.name.value] = definition;
310
+ }
311
+ }
312
+ const operation = doc.definitions.find(
313
+ (definition) => definition.kind === "OperationDefinition"
314
+ );
315
+ if (!operation) return null;
316
+ let paths;
317
+ if (groupPaths) {
318
+ const prefixes = /* @__PURE__ */ new Set();
319
+ for (const groupPath of groupPaths.keys()) {
320
+ const parts = groupPath.split(".");
321
+ for (let i = 1; i <= parts.length; i++) {
322
+ prefixes.add(parts.slice(0, i).join("."));
323
+ }
324
+ }
325
+ paths = { groups: groupPaths, prefixes };
326
+ }
327
+ const pruned = decisionSelectionSet(
328
+ operation.selectionSet,
329
+ schema.queryType,
330
+ "",
331
+ { schema, fragments, paths, topLevelOnly: options?.topLevelOnly }
332
+ );
333
+ if (!pruned) return null;
334
+ const used = /* @__PURE__ */ new Set();
335
+ collectVariables(pruned, used);
336
+ collectVariables(operation.directives, used);
337
+ return {
338
+ kind: "Document",
339
+ definitions: [
340
+ {
341
+ ...operation,
342
+ name: operation.name && name(`${operation.name.value}Decision`),
343
+ variableDefinitions: (operation.variableDefinitions ?? []).filter(
344
+ (definition) => used.has(definition.variable.name.value)
345
+ ),
346
+ selectionSet: pruned
347
+ }
348
+ ]
349
+ };
350
+ }
351
+
352
+ // src/core/variants/variants-document.ts
353
+ function variantsSelectionSet(set, typeName, schema) {
354
+ const selections = set.selections.map((selection) => {
355
+ if (selection.kind === "InlineFragment") {
356
+ return {
357
+ ...selection,
358
+ selectionSet: variantsSelectionSet(
359
+ selection.selectionSet,
360
+ selection.typeCondition?.name.value ?? typeName,
361
+ schema
362
+ )
363
+ };
364
+ }
365
+ if (selection.kind !== "Field" || !selection.selectionSet) return selection;
366
+ const field = schema.types[typeName]?.fields[selection.name.value];
367
+ if (!field) return selection;
368
+ const child = variantsSelectionSet(
369
+ selection.selectionSet,
370
+ field.type,
371
+ schema
372
+ );
373
+ if (!field.personalizable) return { ...selection, selectionSet: child };
374
+ return {
375
+ ...selection,
376
+ arguments: [
377
+ ...withoutPersonalizeArg(selection.arguments),
378
+ {
379
+ kind: "Argument",
380
+ name: name("personalize"),
381
+ value: { kind: "BooleanValue", value: false }
382
+ }
383
+ ],
384
+ selectionSet: selectionSet([
385
+ ...child.selections,
386
+ ...contextSelections(field.type, schema)
387
+ ])
388
+ };
389
+ });
390
+ return { ...set, selections };
391
+ }
392
+ function toVariantsDocument(document, schema) {
393
+ const doc = documentOf(document);
394
+ return {
395
+ ...doc,
396
+ definitions: doc.definitions.map((definition) => {
397
+ if (definition.kind === "OperationDefinition") {
398
+ return {
399
+ ...definition,
400
+ selectionSet: variantsSelectionSet(
401
+ definition.selectionSet,
402
+ schema.queryType,
403
+ schema
404
+ )
405
+ };
406
+ }
407
+ if (definition.kind === "FragmentDefinition") {
408
+ return {
409
+ ...definition,
410
+ selectionSet: variantsSelectionSet(
411
+ definition.selectionSet,
412
+ definition.typeCondition.name.value,
413
+ schema
414
+ )
415
+ };
416
+ }
417
+ return definition;
418
+ })
419
+ };
420
+ }
421
+
422
+ // src/core/variants/queries.ts
423
+ function toVariantsQuery(document, schema) {
424
+ return resolveQuery(toVariantsDocument(document, schema));
425
+ }
426
+ function toDecisionQuery(document, schema, options = {}) {
427
+ const paths = options.from === void 0 ? void 0 : personalizationPaths(options.from);
428
+ if (paths && paths.size === 0) return null;
429
+ const decision = toDecisionDocument(document, schema, paths, {
430
+ topLevelOnly: !paths && options.topLevelOnly
431
+ });
432
+ return decision ? resolveQuery(decision) : null;
433
+ }
434
+
435
+ export {
436
+ PREPR_DEFAULT_VARIANT,
437
+ name,
438
+ selectionSet,
439
+ documentOf,
440
+ collectVariables,
441
+ toDecisionDocument,
442
+ personalizationPaths,
443
+ contextOf,
444
+ decisionsFrom,
445
+ resolveVariants,
446
+ PREPR_SCHEMA_QUERY,
447
+ toSchemaInfo,
448
+ toVariantsDocument,
449
+ resolveQuery,
450
+ toVariantsQuery,
451
+ toDecisionQuery
452
+ };
@@ -1,15 +1,17 @@
1
1
  import {
2
- ALL_FEATURES_ENABLED,
3
- VERSION,
4
2
  createElementCache,
5
3
  createScopedLogger,
6
4
  decodeStega,
7
5
  initDebugLogger,
8
- resolveFeatures,
9
6
  sendPreprEvent,
10
7
  setTrustedParentOrigin,
11
8
  throttle
12
- } from "./chunk-DGZA7KX7.js";
9
+ } from "./chunk-S5RWVMDJ.js";
10
+ import {
11
+ ALL_FEATURES_ENABLED,
12
+ VERSION,
13
+ resolveFeatures
14
+ } from "./chunk-VV4PRH7W.js";
13
15
 
14
16
  // src/core/stega/dom.ts
15
17
  var IGNORED_ANCESTORS = "script, style, noscript";