@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.
- package/README.md +107 -0
- package/dist/astro/{chunk-3UVUDDNY.js → chunk-U7VUQL57.js} +1 -1
- package/dist/astro/graphql.cjs +96 -49
- package/dist/astro/graphql.d.cts +75 -1
- package/dist/astro/graphql.d.ts +75 -1
- package/dist/astro/graphql.js +92 -49
- package/dist/astro/index.cjs +1 -1
- package/dist/astro/index.js +1 -1
- package/dist/chunk-3NCEVJJ3.js +10 -0
- package/dist/chunk-7HSMUULV.js +452 -0
- package/dist/{chunk-BJ2LBLWO.js → chunk-DS3QA3HF.js} +6 -4
- package/dist/{chunk-DGZA7KX7.js → chunk-S5RWVMDJ.js} +0 -24
- package/dist/{chunk-YR7P4IWE.js → chunk-UYYTYSOD.js} +1 -9
- package/dist/chunk-VV4PRH7W.js +26 -0
- package/dist/graphql/codegen.cjs +510 -0
- package/dist/graphql/codegen.d.cts +23 -0
- package/dist/graphql/codegen.d.ts +23 -0
- package/dist/graphql/codegen.js +99 -0
- package/dist/graphql.cjs +96 -49
- package/dist/graphql.d.cts +75 -1
- package/dist/graphql.d.ts +75 -1
- package/dist/graphql.js +60 -428
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -6
- package/dist/nextjs/{chunk-U4HXENF7.js → chunk-ZIUKEGEN.js} +1 -1
- package/dist/nextjs/components.cjs +12 -8
- package/dist/nextjs/components.js +14 -9
- package/dist/nextjs/graphql.cjs +96 -49
- package/dist/nextjs/graphql.d.cts +75 -1
- package/dist/nextjs/graphql.d.ts +75 -1
- package/dist/nextjs/graphql.js +92 -49
- package/dist/nextjs/index.cjs +1 -1
- package/dist/nextjs/index.js +1 -1
- package/dist/nuxt/{chunk-P6ENNAEE.js → chunk-GMWF6PQ5.js} +1 -1
- package/dist/nuxt/graphql.cjs +96 -49
- package/dist/nuxt/graphql.d.cts +75 -1
- package/dist/nuxt/graphql.d.ts +75 -1
- package/dist/nuxt/graphql.js +92 -49
- 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-FSARVMG5.js → chunk-5SQUG2L4.js} +1 -1
- package/dist/sveltekit/graphql.cjs +96 -49
- package/dist/sveltekit/graphql.d.cts +75 -1
- package/dist/sveltekit/graphql.d.ts +75 -1
- package/dist/sveltekit/graphql.js +92 -49
- package/dist/sveltekit/index.cjs +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/package.json +6 -1
package/dist/graphql.js
CHANGED
|
@@ -1,203 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
validatePreprToken
|
|
5
|
-
} from "./chunk-YR7P4IWE.js";
|
|
2
|
+
isPersonalizedResponse
|
|
3
|
+
} from "./chunk-3NCEVJJ3.js";
|
|
6
4
|
import {
|
|
7
5
|
stegaClean
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
}
|
|
83
|
-
|
|
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
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
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
|
-
};
|
|
200
|
-
}
|
|
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-7HSMUULV.js";
|
|
25
|
+
import {
|
|
26
|
+
PreprError,
|
|
27
|
+
validatePreprToken
|
|
28
|
+
} from "./chunk-UYYTYSOD.js";
|
|
29
|
+
import "./chunk-VV4PRH7W.js";
|
|
201
30
|
|
|
202
31
|
// src/core/variants/probe-document.ts
|
|
203
32
|
function probeSelectionSet(set, fragments) {
|
|
@@ -257,117 +86,6 @@ function toAbProbeDocument(document) {
|
|
|
257
86
|
};
|
|
258
87
|
}
|
|
259
88
|
|
|
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
89
|
// src/core/variants/stack.ts
|
|
372
90
|
function containsKind(value, kind) {
|
|
373
91
|
if (Array.isArray(value))
|
|
@@ -414,124 +132,8 @@ function preprVariantProps(item) {
|
|
|
414
132
|
return key ? { "data-prepr-variant-key": key } : {};
|
|
415
133
|
}
|
|
416
134
|
|
|
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
135
|
// src/core/graphql/transport.ts
|
|
488
136
|
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
137
|
var OPERATION_NAME = /\b(?:query|mutation|subscription)\s+([_A-Za-z][_0-9A-Za-z]*)/;
|
|
536
138
|
var STEGA_RAW = new RegExp(
|
|
537
139
|
VERCEL_STEGA_REGEX.source,
|
|
@@ -710,16 +312,18 @@ function isParseableUrl(url) {
|
|
|
710
312
|
return false;
|
|
711
313
|
}
|
|
712
314
|
}
|
|
713
|
-
function
|
|
714
|
-
const { url } = options;
|
|
315
|
+
function assertPreprUrl(url, source) {
|
|
715
316
|
validatePreprToken(url);
|
|
716
317
|
if (!isParseableUrl(url)) {
|
|
717
318
|
throw new PreprError(
|
|
718
319
|
"Prepr GraphQL URL is not a valid URL",
|
|
719
320
|
"INVALID_TOKEN",
|
|
720
|
-
|
|
321
|
+
source
|
|
721
322
|
);
|
|
722
323
|
}
|
|
324
|
+
}
|
|
325
|
+
function createPreprClient(options) {
|
|
326
|
+
assertPreprUrl(options.url, "createPreprClient");
|
|
723
327
|
const run = createTransport(options);
|
|
724
328
|
const probeVary = createVaryProbe(run, options);
|
|
725
329
|
let schema;
|
|
@@ -776,12 +380,40 @@ function createPreprClient(options) {
|
|
|
776
380
|
)
|
|
777
381
|
};
|
|
778
382
|
}
|
|
383
|
+
|
|
384
|
+
// src/core/graphql/schema-loader.ts
|
|
385
|
+
var schemas = /* @__PURE__ */ new Map();
|
|
386
|
+
async function loadPreprSchema(url, options = {}) {
|
|
387
|
+
assertPreprUrl(url, "loadPreprSchema");
|
|
388
|
+
let schema = schemas.get(url);
|
|
389
|
+
if (!schema) {
|
|
390
|
+
const run = createTransport({ url, fetch: options.fetch, stega: "none" });
|
|
391
|
+
schema = run(
|
|
392
|
+
PREPR_SCHEMA_QUERY
|
|
393
|
+
).then((result) => toSchemaInfo(result.data)).catch((error) => {
|
|
394
|
+
schemas.delete(url);
|
|
395
|
+
if (error instanceof PreprError) throw error;
|
|
396
|
+
throw new PreprError(
|
|
397
|
+
"Prepr schema response is not an introspection result",
|
|
398
|
+
"INVALID_RESPONSE",
|
|
399
|
+
"loadPreprSchema",
|
|
400
|
+
error instanceof Error ? error : void 0
|
|
401
|
+
);
|
|
402
|
+
});
|
|
403
|
+
schemas.set(url, schema);
|
|
404
|
+
}
|
|
405
|
+
return schema;
|
|
406
|
+
}
|
|
779
407
|
export {
|
|
780
408
|
PREPR_DEFAULT_VARIANT,
|
|
781
409
|
PreprError,
|
|
782
410
|
createPreprClient,
|
|
411
|
+
decisionsFrom,
|
|
783
412
|
isPersonalizedResponse,
|
|
413
|
+
loadPreprSchema,
|
|
784
414
|
preprVariantProps,
|
|
785
415
|
resolveVariants,
|
|
786
|
-
splitStack
|
|
416
|
+
splitStack,
|
|
417
|
+
toDecisionQuery,
|
|
418
|
+
toVariantsQuery
|
|
787
419
|
};
|
package/dist/index.cjs
CHANGED
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.
|
|
10
|
+
declare const VERSION = "0.6.0-alpha.2";
|
|
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.
|
|
10
|
+
declare const VERSION = "0.6.0-alpha.2";
|
|
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-
|
|
18
|
+
} from "./chunk-DS3QA3HF.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-
|
|
35
|
+
} from "./chunk-UYYTYSOD.js";
|
|
31
36
|
import {
|
|
32
37
|
VERSION,
|
|
33
|
-
resolveFeatures
|
|
34
|
-
|
|
35
|
-
} from "./chunk-DGZA7KX7.js";
|
|
38
|
+
resolveFeatures
|
|
39
|
+
} from "./chunk-VV4PRH7W.js";
|
|
36
40
|
|
|
37
41
|
// src/core/middleware.ts
|
|
38
42
|
var UTM_PARAMS = [
|
|
@@ -2383,7 +2383,7 @@ function applyPreprDecisions() {
|
|
|
2383
2383
|
var import_react = require("react");
|
|
2384
2384
|
|
|
2385
2385
|
// src/version.ts
|
|
2386
|
-
var VERSION = "0.6.0-alpha.
|
|
2386
|
+
var VERSION = "0.6.0-alpha.2";
|
|
2387
2387
|
|
|
2388
2388
|
// src/core/pixel.ts
|
|
2389
2389
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
|
@@ -2474,15 +2474,19 @@ function PreprVariantTracking({
|
|
|
2474
2474
|
const ref = (0, import_react2.useRef)(null);
|
|
2475
2475
|
const keys = variantKeys.join(" ");
|
|
2476
2476
|
(0, import_react2.useLayoutEffect)(() => {
|
|
2477
|
-
|
|
2478
|
-
const
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2477
|
+
let tagged = [];
|
|
2478
|
+
const timer = setTimeout(() => {
|
|
2479
|
+
const elements = [...ref.current?.children ?? []];
|
|
2480
|
+
const list = keys.split(" ");
|
|
2481
|
+
const pairs = elements.length === list.length ? elements.map((element, i2) => [element, list[i2]]) : elements.slice(0, 1).map((element) => [element, list[0]]);
|
|
2482
|
+
tagged = pairs.filter(([element, key]) => {
|
|
2483
|
+
if (element.hasAttribute(VARIANT_KEY_ATTRIBUTE)) return false;
|
|
2484
|
+
element.setAttribute(VARIANT_KEY_ATTRIBUTE, key);
|
|
2485
|
+
return true;
|
|
2486
|
+
});
|
|
2484
2487
|
});
|
|
2485
2488
|
return () => {
|
|
2489
|
+
clearTimeout(timer);
|
|
2486
2490
|
for (const [element] of tagged) {
|
|
2487
2491
|
element.removeAttribute(VARIANT_KEY_ATTRIBUTE);
|
|
2488
2492
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
createPreprPreview,
|
|
4
4
|
loadTrackingPixel
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-DS3QA3HF.js";
|
|
6
|
+
import "../chunk-S5RWVMDJ.js";
|
|
7
|
+
import "../chunk-VV4PRH7W.js";
|
|
7
8
|
|
|
8
9
|
// src/nextjs/components.ts
|
|
9
10
|
import { usePathname, useRouter } from "next/navigation";
|
|
@@ -148,15 +149,19 @@ function PreprVariantTracking({
|
|
|
148
149
|
const ref = useRef(null);
|
|
149
150
|
const keys = variantKeys.join(" ");
|
|
150
151
|
useLayoutEffect(() => {
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
let tagged = [];
|
|
153
|
+
const timer = setTimeout(() => {
|
|
154
|
+
const elements = [...ref.current?.children ?? []];
|
|
155
|
+
const list = keys.split(" ");
|
|
156
|
+
const pairs = elements.length === list.length ? elements.map((element, i) => [element, list[i]]) : elements.slice(0, 1).map((element) => [element, list[0]]);
|
|
157
|
+
tagged = pairs.filter(([element, key]) => {
|
|
158
|
+
if (element.hasAttribute(VARIANT_KEY_ATTRIBUTE)) return false;
|
|
159
|
+
element.setAttribute(VARIANT_KEY_ATTRIBUTE, key);
|
|
160
|
+
return true;
|
|
161
|
+
});
|
|
158
162
|
});
|
|
159
163
|
return () => {
|
|
164
|
+
clearTimeout(timer);
|
|
160
165
|
for (const [element] of tagged) {
|
|
161
166
|
element.removeAttribute(VARIANT_KEY_ATTRIBUTE);
|
|
162
167
|
}
|