@preprio/toolkit 0.6.0-alpha.9 → 1.0.0-rc.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 (116) hide show
  1. package/README.md +111 -1363
  2. package/dist/astro/index.cjs +1555 -182
  3. package/dist/astro/index.d.cts +201 -1
  4. package/dist/astro/index.d.ts +201 -1
  5. package/dist/astro/index.js +1557 -29
  6. package/dist/chunk-A2J7R4LR.js +256 -0
  7. package/dist/{chunk-5QIWVDP2.js → chunk-DBKZWOXA.js} +1 -1
  8. package/dist/{chunk-WQBKQG4R.js → chunk-EWXBE3JD.js} +6 -1
  9. package/dist/chunk-KM2GME62.js +1255 -0
  10. package/dist/{chunk-J66UOCK6.js → chunk-LJA5K4KM.js} +1680 -579
  11. package/dist/chunk-UTKH7DOI.js +58 -0
  12. package/dist/chunk-V7MCHPE7.js +85 -0
  13. package/dist/chunk-Y7JWV7WV.js +374 -0
  14. package/dist/codegen/index.cjs +82 -0
  15. package/dist/codegen/index.d.cts +70 -0
  16. package/dist/codegen/index.d.ts +70 -0
  17. package/dist/codegen/index.js +64 -0
  18. package/dist/index.cjs +3729 -553
  19. package/dist/index.d.cts +403 -19
  20. package/dist/index.d.ts +403 -19
  21. package/dist/index.js +345 -24
  22. package/dist/live-preview-HCBNBC6C.js +19 -0
  23. package/dist/nextjs/components.cjs +1872 -754
  24. package/dist/nextjs/components.d.cts +5 -51
  25. package/dist/nextjs/components.d.ts +5 -51
  26. package/dist/nextjs/components.js +8 -299
  27. package/dist/nextjs/index.cjs +1228 -181
  28. package/dist/nextjs/index.d.cts +247 -92
  29. package/dist/nextjs/index.d.ts +247 -92
  30. package/dist/nextjs/index.js +1629 -111
  31. package/dist/nextjs/live-action.cjs +298 -0
  32. package/dist/nextjs/live-action.d.cts +12 -0
  33. package/dist/nextjs/live-action.d.ts +12 -0
  34. package/dist/nextjs/live-action.js +68 -0
  35. package/dist/nextjs/live.cjs +2010 -0
  36. package/dist/nextjs/live.d.cts +54 -0
  37. package/dist/nextjs/live.d.ts +54 -0
  38. package/dist/nextjs/live.js +287 -0
  39. package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
  40. package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
  41. package/dist/nuxt/index.cjs +15 -16
  42. package/dist/nuxt/index.d.cts +167 -6
  43. package/dist/nuxt/index.d.ts +167 -6
  44. package/dist/nuxt/index.js +402 -15
  45. package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
  46. package/dist/nuxt/live.cjs +1928 -0
  47. package/dist/nuxt/live.d.cts +45 -0
  48. package/dist/nuxt/live.d.ts +45 -0
  49. package/dist/nuxt/live.js +216 -0
  50. package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
  51. package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
  52. package/dist/react/components.cjs +1865 -480
  53. package/dist/react/components.d.cts +43 -8
  54. package/dist/react/components.d.ts +43 -8
  55. package/dist/react/components.js +1865 -480
  56. package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
  57. package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
  58. package/dist/sveltekit/index.cjs +15 -16
  59. package/dist/sveltekit/index.d.cts +111 -10
  60. package/dist/sveltekit/index.d.ts +111 -10
  61. package/dist/sveltekit/index.js +398 -15
  62. package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
  63. package/dist/sveltekit/live.cjs +1940 -0
  64. package/dist/sveltekit/live.d.cts +61 -0
  65. package/dist/sveltekit/live.d.ts +61 -0
  66. package/dist/sveltekit/live.js +220 -0
  67. package/package.json +132 -71
  68. package/src/astro/PreprToolbar.astro +7 -1
  69. package/src/astro/PreprTrackingPixel.astro +2 -4
  70. package/src/nuxt/PreprToolbar.vue +12 -1
  71. package/src/nuxt/PreprTrackingPixel.vue +2 -4
  72. package/src/sveltekit/PreprToolbar.svelte +17 -2
  73. package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
  74. package/dist/astro/chunk-UN4JADNU.js +0 -173
  75. package/dist/astro/graphql.cjs +0 -1078
  76. package/dist/astro/graphql.d.cts +0 -300
  77. package/dist/astro/graphql.d.ts +0 -300
  78. package/dist/astro/graphql.js +0 -984
  79. package/dist/astro/index-XT_z-RYT.d.cts +0 -130
  80. package/dist/astro/index-XT_z-RYT.d.ts +0 -130
  81. package/dist/chunk-3NCEVJJ3.js +0 -10
  82. package/dist/chunk-S5RWVMDJ.js +0 -148
  83. package/dist/chunk-XL4Y7FGW.js +0 -499
  84. package/dist/graphql/codegen.cjs +0 -557
  85. package/dist/graphql/codegen.d.cts +0 -23
  86. package/dist/graphql/codegen.d.ts +0 -23
  87. package/dist/graphql/codegen.js +0 -99
  88. package/dist/graphql.cjs +0 -1020
  89. package/dist/graphql.d.cts +0 -335
  90. package/dist/graphql.d.ts +0 -335
  91. package/dist/graphql.js +0 -448
  92. package/dist/nextjs/chunk-CMV6ZP6E.js +0 -549
  93. package/dist/nextjs/graphql.cjs +0 -1836
  94. package/dist/nextjs/graphql.d.cts +0 -498
  95. package/dist/nextjs/graphql.d.ts +0 -498
  96. package/dist/nextjs/graphql.js +0 -1422
  97. package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
  98. package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
  99. package/dist/nuxt/chunk-XWOABVMW.js +0 -417
  100. package/dist/nuxt/graphql.cjs +0 -1085
  101. package/dist/nuxt/graphql.d.cts +0 -297
  102. package/dist/nuxt/graphql.d.ts +0 -297
  103. package/dist/nuxt/graphql.js +0 -985
  104. package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
  105. package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
  106. package/dist/pixel-DwW7cXJm.d.cts +0 -49
  107. package/dist/pixel-DwW7cXJm.d.ts +0 -49
  108. package/dist/server-Brr1UgtW.d.ts +0 -59
  109. package/dist/server-DJuS3YU0.d.cts +0 -59
  110. package/dist/sveltekit/chunk-3S5RA6G5.js +0 -413
  111. package/dist/sveltekit/graphql.cjs +0 -1091
  112. package/dist/sveltekit/graphql.d.cts +0 -302
  113. package/dist/sveltekit/graphql.d.ts +0 -302
  114. package/dist/sveltekit/graphql.js +0 -991
  115. package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
  116. package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
@@ -0,0 +1,350 @@
1
+ // src/core/live-preview/guards.ts
2
+ function isScalar(value) {
3
+ return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
4
+ }
5
+ function isObject(value) {
6
+ return value !== null && typeof value === "object" && !Array.isArray(value);
7
+ }
8
+
9
+ // src/core/live-preview/query-document.ts
10
+ var NAME_START = /[_A-Za-z]/;
11
+ var NAME_CONTINUE = /[_0-9A-Za-z]/;
12
+ var PUNCT = /* @__PURE__ */ new Set([
13
+ "!",
14
+ "$",
15
+ "&",
16
+ "(",
17
+ ")",
18
+ ":",
19
+ "=",
20
+ "@",
21
+ "[",
22
+ "]",
23
+ "{",
24
+ "|",
25
+ "}"
26
+ ]);
27
+ function tokenize(source) {
28
+ const tokens = [];
29
+ let i = 0;
30
+ const n = source.length;
31
+ while (i < n) {
32
+ const ch = source[i];
33
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "," || ch === "\uFEFF") {
34
+ i++;
35
+ } else if (ch === "#") {
36
+ while (i < n && source[i] !== "\n" && source[i] !== "\r") i++;
37
+ } else if (ch === "." && source.startsWith("...", i)) {
38
+ tokens.push({ type: "punct", value: "..." });
39
+ i += 3;
40
+ } else if (PUNCT.has(ch)) {
41
+ tokens.push({ type: "punct", value: ch });
42
+ i++;
43
+ } else if (NAME_START.test(ch)) {
44
+ const start = i;
45
+ while (i < n && NAME_CONTINUE.test(source[i])) i++;
46
+ tokens.push({ type: "name", value: source.slice(start, i) });
47
+ } else if (ch === '"') {
48
+ if (source.startsWith('"""', i)) {
49
+ i += 3;
50
+ while (i < n && !source.startsWith('"""', i)) {
51
+ i += source.startsWith('\\"""', i) ? 4 : 1;
52
+ }
53
+ if (i >= n) throw new SyntaxError("Unterminated block string");
54
+ i += 3;
55
+ } else {
56
+ i++;
57
+ while (i < n && source[i] !== '"') {
58
+ if (source[i] === "\n" || source[i] === "\r") {
59
+ throw new SyntaxError("Unterminated string");
60
+ }
61
+ i += source[i] === "\\" ? 2 : 1;
62
+ }
63
+ if (i >= n) throw new SyntaxError("Unterminated string");
64
+ i++;
65
+ }
66
+ tokens.push({ type: "value" });
67
+ } else if (ch === "-" || ch >= "0" && ch <= "9") {
68
+ i++;
69
+ while (i < n && /[0-9.eE+-]/.test(source[i])) i++;
70
+ tokens.push({ type: "value" });
71
+ } else {
72
+ throw new SyntaxError(`Unexpected character "${ch}"`);
73
+ }
74
+ }
75
+ return tokens;
76
+ }
77
+ function parseSource(source, operationName) {
78
+ const tokens = tokenize(source);
79
+ let pos = 0;
80
+ const peek = () => tokens[pos];
81
+ const isPunct = (value) => {
82
+ const t = tokens[pos];
83
+ return t?.type === "punct" && t.value === value;
84
+ };
85
+ const expectPunct = (value) => {
86
+ if (!isPunct(value)) throw new SyntaxError(`Expected "${value}"`);
87
+ pos++;
88
+ };
89
+ const expectName = () => {
90
+ const t = tokens[pos];
91
+ if (t?.type !== "name") throw new SyntaxError("Expected a name");
92
+ pos++;
93
+ return t.value;
94
+ };
95
+ const skipParens = () => {
96
+ expectPunct("(");
97
+ let depth = 1;
98
+ while (depth > 0) {
99
+ const t = tokens[pos++];
100
+ if (!t) throw new SyntaxError("Unbalanced parentheses");
101
+ if (t.type === "punct" && t.value === "(") depth++;
102
+ else if (t.type === "punct" && t.value === ")") depth--;
103
+ }
104
+ };
105
+ const skipDirectives = () => {
106
+ while (isPunct("@")) {
107
+ pos++;
108
+ expectName();
109
+ if (isPunct("(")) skipParens();
110
+ }
111
+ };
112
+ const parseSelectionSet = () => {
113
+ expectPunct("{");
114
+ const selections = [];
115
+ while (!isPunct("}")) {
116
+ if (!peek()) throw new SyntaxError("Unterminated selection set");
117
+ selections.push(parseSelection());
118
+ }
119
+ pos++;
120
+ return selections;
121
+ };
122
+ const parseSelection = () => {
123
+ if (isPunct("...")) {
124
+ pos++;
125
+ const t = peek();
126
+ if (t?.type === "name" && t.value !== "on") {
127
+ pos++;
128
+ skipDirectives();
129
+ return { kind: "spread", name: t.value };
130
+ }
131
+ let on = null;
132
+ if (t?.type === "name") {
133
+ pos++;
134
+ on = expectName();
135
+ }
136
+ skipDirectives();
137
+ return { kind: "inline", on, selections: parseSelectionSet() };
138
+ }
139
+ let name = expectName();
140
+ const key = name;
141
+ if (isPunct(":")) {
142
+ pos++;
143
+ name = expectName();
144
+ }
145
+ let hasArgs = false;
146
+ if (isPunct("(")) {
147
+ hasArgs = true;
148
+ skipParens();
149
+ }
150
+ skipDirectives();
151
+ const selections = isPunct("{") ? parseSelectionSet() : null;
152
+ return { kind: "field", name, key, hasArgs, selections };
153
+ };
154
+ const fragments = /* @__PURE__ */ new Map();
155
+ const operations = [];
156
+ while (pos < tokens.length) {
157
+ if (isPunct("{")) {
158
+ operations.push({ name: null, selections: parseSelectionSet() });
159
+ continue;
160
+ }
161
+ const keyword = expectName();
162
+ if (keyword === "fragment") {
163
+ const name = expectName();
164
+ if (expectName() !== "on") throw new SyntaxError('Expected "on"');
165
+ const on = expectName();
166
+ skipDirectives();
167
+ fragments.set(name, { on, selections: parseSelectionSet() });
168
+ } else if (keyword === "query" || keyword === "mutation" || keyword === "subscription") {
169
+ const t = peek();
170
+ let name = null;
171
+ if (t?.type === "name") name = expectName();
172
+ if (isPunct("(")) skipParens();
173
+ skipDirectives();
174
+ operations.push({ name, selections: parseSelectionSet() });
175
+ } else {
176
+ throw new SyntaxError(`Unexpected "${keyword}"`);
177
+ }
178
+ }
179
+ return { operation: pickOperation(operations, operationName), fragments };
180
+ }
181
+ function pickOperation(operations, operationName) {
182
+ const op = operationName ? operations.find((o) => o.name === operationName) : operations[0];
183
+ if (!op) throw new SyntaxError("The document has no operation");
184
+ return op.selections;
185
+ }
186
+ function fromAstSelections(set) {
187
+ return set.selections.map((s) => {
188
+ if (s.kind === "FragmentSpread")
189
+ return { kind: "spread", name: s.name.value };
190
+ if (s.kind === "InlineFragment") {
191
+ return {
192
+ kind: "inline",
193
+ on: s.typeCondition?.name.value ?? null,
194
+ selections: fromAstSelections(s.selectionSet)
195
+ };
196
+ }
197
+ const name = s.name.value;
198
+ return {
199
+ kind: "field",
200
+ name,
201
+ key: s.alias?.value ?? name,
202
+ hasArgs: Boolean(s.arguments?.length),
203
+ selections: s.selectionSet ? fromAstSelections(s.selectionSet) : null
204
+ };
205
+ });
206
+ }
207
+ function fromAst(doc, operationName) {
208
+ const fragments = /* @__PURE__ */ new Map();
209
+ const operations = [];
210
+ for (const def of doc.definitions ?? []) {
211
+ if (def.kind === "FragmentDefinition" && def.name && def.typeCondition && def.selectionSet) {
212
+ fragments.set(def.name.value, {
213
+ on: def.typeCondition.name.value,
214
+ selections: fromAstSelections(def.selectionSet)
215
+ });
216
+ } else if (def.kind === "OperationDefinition" && def.selectionSet) {
217
+ operations.push({
218
+ name: def.name?.value ?? null,
219
+ selections: fromAstSelections(def.selectionSet)
220
+ });
221
+ }
222
+ }
223
+ return { operation: pickOperation(operations, operationName), fragments };
224
+ }
225
+ var astCache = /* @__PURE__ */ new WeakMap();
226
+ var sourceCache = /* @__PURE__ */ new Map();
227
+ var SOURCE_CACHE_LIMIT = 200;
228
+ function readQueryDocument(query, operationName) {
229
+ const cacheKey = operationName ?? "";
230
+ if (typeof query === "object" && query !== null && query.kind === "Document") {
231
+ let byName = astCache.get(query);
232
+ if (!byName) astCache.set(query, byName = /* @__PURE__ */ new Map());
233
+ let parsed2 = byName.get(cacheKey);
234
+ if (!parsed2) {
235
+ parsed2 = fromAst(
236
+ query,
237
+ operationName
238
+ );
239
+ byName.set(cacheKey, parsed2);
240
+ }
241
+ return parsed2;
242
+ }
243
+ const source = String(query);
244
+ const sourceKey = `${cacheKey}
245
+ ${source}`;
246
+ let parsed = sourceCache.get(sourceKey);
247
+ if (!parsed) {
248
+ parsed = parseSource(source, operationName);
249
+ if (sourceCache.size >= SOURCE_CACHE_LIMIT) {
250
+ sourceCache.delete(sourceCache.keys().next().value);
251
+ }
252
+ sourceCache.set(sourceKey, parsed);
253
+ }
254
+ return parsed;
255
+ }
256
+ var fieldsCache = /* @__PURE__ */ new WeakMap();
257
+ function collectFields(selections, typename, doc, options = {}) {
258
+ const cacheKey = `${options.strict ? "s" : "l"}:${typename ?? ""}`;
259
+ let cached = fieldsCache.get(selections);
260
+ if (!cached) {
261
+ cached = /* @__PURE__ */ new Map();
262
+ fieldsCache.set(selections, cached);
263
+ }
264
+ const hit = cached.get(cacheKey);
265
+ if (hit) return hit;
266
+ const fields = resolveFields(selections, typename, doc, options);
267
+ cached.set(cacheKey, fields);
268
+ return fields;
269
+ }
270
+ function resolveFields(selections, typename, doc, options) {
271
+ const exact = /* @__PURE__ */ new Map();
272
+ const loose = /* @__PURE__ */ new Map();
273
+ const merged = /* @__PURE__ */ new Map();
274
+ const walkedMatched = /* @__PURE__ */ new Set();
275
+ const walkedLoose = /* @__PURE__ */ new Set();
276
+ const add = (target, s) => {
277
+ let field = target.get(s.key);
278
+ if (!field) {
279
+ field = { name: s.name, key: s.key, hasArgs: s.hasArgs, selections: [] };
280
+ target.set(s.key, field);
281
+ merged.set(field, /* @__PURE__ */ new Set());
282
+ }
283
+ const done = merged.get(field);
284
+ if (s.selections && !done.has(s.selections)) {
285
+ done.add(s.selections);
286
+ field.selections = [...field.selections, ...s.selections];
287
+ }
288
+ };
289
+ const applies = (on, list) => conditionMatches(on, typename) || typename !== void 0 && typeConditions(list, doc).includes(typename);
290
+ const walk = (list, matched) => {
291
+ for (const s of list) {
292
+ if (s.kind === "field") {
293
+ add(matched ? exact : loose, s);
294
+ } else if (s.kind === "inline") {
295
+ walk(s.selections, matched && applies(s.on, s.selections));
296
+ } else {
297
+ const fragment = doc.fragments.get(s.name);
298
+ if (!fragment) continue;
299
+ const asMatched = matched && applies(fragment.on, fragment.selections);
300
+ if (walkedMatched.has(fragment)) continue;
301
+ if (!asMatched && walkedLoose.has(fragment)) continue;
302
+ (asMatched ? walkedMatched : walkedLoose).add(fragment);
303
+ walk(fragment.selections, asMatched);
304
+ }
305
+ }
306
+ };
307
+ walk(selections, true);
308
+ if (!options.strict) {
309
+ for (const [key, field] of loose) {
310
+ if (!exact.has(key)) exact.set(key, field);
311
+ }
312
+ }
313
+ return exact;
314
+ }
315
+ function conditionMatches(on, typename) {
316
+ return on === null || typename === void 0 || on === typename;
317
+ }
318
+ var conditionsCache = /* @__PURE__ */ new WeakMap();
319
+ function typeConditions(selections, doc) {
320
+ const hit = conditionsCache.get(selections);
321
+ if (hit) return hit;
322
+ const names = /* @__PURE__ */ new Set();
323
+ const seen = /* @__PURE__ */ new Set();
324
+ const walk = (list) => {
325
+ for (const s of list) {
326
+ if (s.kind === "inline") {
327
+ if (s.on) names.add(s.on);
328
+ walk(s.selections);
329
+ } else if (s.kind === "spread") {
330
+ const fragment = doc.fragments.get(s.name);
331
+ if (!fragment || seen.has(fragment)) continue;
332
+ seen.add(fragment);
333
+ names.add(fragment.on);
334
+ walk(fragment.selections);
335
+ }
336
+ }
337
+ };
338
+ walk(selections);
339
+ const conditions = [...names];
340
+ conditionsCache.set(selections, conditions);
341
+ return conditions;
342
+ }
343
+
344
+ export {
345
+ isScalar,
346
+ isObject,
347
+ readQueryDocument,
348
+ collectFields,
349
+ typeConditions
350
+ };
@@ -0,0 +1,32 @@
1
+ // src/core/constants.ts
2
+ var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
3
+ var COOKIE_SEGMENT = "Prepr-Segments";
4
+ var COOKIE_VARIANT = "Prepr-ABtesting";
5
+ var COOKIE_UID = "__prepr_uid";
6
+ var COOKIE_HUBSPOT = "hubspotutk";
7
+ var PARAM_SEGMENT = "prepr_preview_segment";
8
+ var PARAM_VARIANT = "prepr_preview_ab";
9
+ var PARAM_HIDE_BAR = "prepr_hide_bar";
10
+ var ONE_YEAR_SECONDS = 60 * 60 * 24 * 365;
11
+ var ATTR_ENCODED = "data-prepr-encoded";
12
+ var ENCODED_SELECTOR = `[${ATTR_ENCODED}]`;
13
+ var EVENT_INIT = "prepr:initVE";
14
+ var EVENT_ITEM_CHANGED = "prepr:itemChanged";
15
+ var EVENT_FIELD_CHANGE = "prepr:fieldChange";
16
+ var EVENT_LIST_CHANGE = "prepr:listChange";
17
+
18
+ export {
19
+ COOKIE_PREVIEW_MODE,
20
+ COOKIE_SEGMENT,
21
+ COOKIE_VARIANT,
22
+ COOKIE_UID,
23
+ COOKIE_HUBSPOT,
24
+ PARAM_SEGMENT,
25
+ PARAM_VARIANT,
26
+ PARAM_HIDE_BAR,
27
+ ONE_YEAR_SECONDS,
28
+ EVENT_INIT,
29
+ EVENT_ITEM_CHANGED,
30
+ EVENT_FIELD_CHANGE,
31
+ EVENT_LIST_CHANGE
32
+ };
@@ -29,14 +29,13 @@ __export(sveltekit_exports, {
29
29
  getPreprHeadersFromLocals: () => getPreprHeadersFromLocals,
30
30
  getPreprUUID: () => getPreprUUID,
31
31
  getToolbarProps: () => getToolbarProps,
32
- isPersonalizedResponse: () => isPersonalizedResponse,
33
32
  preprHandle: () => preprHandle,
34
33
  validatePreprToken: () => validatePreprToken
35
34
  });
36
35
  module.exports = __toCommonJS(sveltekit_exports);
37
36
 
38
37
  // src/version.ts
39
- var VERSION = "0.6.0-alpha.9";
38
+ var VERSION = "1.0.0-rc.2";
40
39
 
41
40
  // src/core/constants.ts
42
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -48,6 +47,8 @@ var PARAM_SEGMENT = "prepr_preview_segment";
48
47
  var PARAM_VARIANT = "prepr_preview_ab";
49
48
  var PARAM_HIDE_BAR = "prepr_hide_bar";
50
49
  var ONE_YEAR_SECONDS = 60 * 60 * 24 * 365;
50
+ var ATTR_ENCODED = "data-prepr-encoded";
51
+ var ENCODED_SELECTOR = `[${ATTR_ENCODED}]`;
51
52
 
52
53
  // src/core/features.ts
53
54
  function isEnabled(config) {
@@ -76,6 +77,16 @@ var UTM_PARAMS = [
76
77
  "utm_campaign"
77
78
  ];
78
79
  var MAX_HEADER_VALUE_LENGTH = 2048;
80
+ function randomUUID() {
81
+ if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
82
+ const bytes = crypto.getRandomValues(new Uint8Array(16));
83
+ bytes[6] = bytes[6] & 15 | 64;
84
+ bytes[8] = bytes[8] & 63 | 128;
85
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
86
+ ""
87
+ );
88
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
89
+ }
79
90
  function sanitizeHeaderValue(value) {
80
91
  const stripped = value.replace(/[\u0000-\u001f\u007f]/g, "");
81
92
  return stripped.length > MAX_HEADER_VALUE_LENGTH ? stripped.slice(0, MAX_HEADER_VALUE_LENGTH) : stripped;
@@ -161,7 +172,7 @@ function processFrameworkRequest(request, opts, framework) {
161
172
  }
162
173
  let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
163
174
  if (!uid) {
164
- uid = crypto.randomUUID();
175
+ uid = randomUUID();
165
176
  responseCookies.push({
166
177
  name: COOKIE_UID,
167
178
  value: uid,
@@ -230,10 +241,6 @@ function processFrameworkRequest(request, opts, framework) {
230
241
  });
231
242
  }
232
243
  }
233
- if (requestHeaders.has("Prepr-Segments")) {
234
- requestHeaders.delete("Prepr-Customer-Id");
235
- requestHeaders.delete("Prepr-Customer-Id-Created");
236
- }
237
244
  return { requestHeaders, responseCookies };
238
245
  }
239
246
 
@@ -427,7 +434,7 @@ async function getToolbarPropsFromHeaders(headers, token, features) {
427
434
  };
428
435
  }
429
436
 
430
- // src/sveltekit/server.ts
437
+ // src/core/request-helpers.ts
431
438
  function getPreprUUID(headers) {
432
439
  return getPreprUUIDFromHeaders(headers);
433
440
  }
@@ -443,13 +450,6 @@ function getPreprHeaders(headers) {
443
450
  async function getToolbarProps(headers, token, features) {
444
451
  return getToolbarPropsFromHeaders(headers, token, features);
445
452
  }
446
-
447
- // src/core/personalization.ts
448
- var PERSONALIZED_VARY = /\bPrepr-(Segments|ABTesting)/i;
449
- function isPersonalizedResponse(source) {
450
- const headers = "headers" in source ? source.headers : source;
451
- return PERSONALIZED_VARY.test(headers.get("vary") ?? "");
452
- }
453
453
  // Annotate the CommonJS export names for ESM import in node:
454
454
  0 && (module.exports = {
455
455
  PREPR_LOCALS_KEY,
@@ -461,7 +461,6 @@ function isPersonalizedResponse(source) {
461
461
  getPreprHeadersFromLocals,
462
462
  getPreprUUID,
463
463
  getToolbarProps,
464
- isPersonalizedResponse,
465
464
  preprHandle,
466
465
  validatePreprToken
467
466
  });
@@ -1,6 +1,85 @@
1
- import { b as PreprFeatures, P as PreprHeaders, c as PreprToolbarProps } from './server-CO847mEV.cjs';
2
- export { a as PreprError, e as extractAccessToken, i as isPersonalizedResponse, v as validatePreprToken } from './server-CO847mEV.cjs';
1
+ /** A segment from Prepr, as listed in the toolbar's segment picker. */
2
+ interface PreprSegment {
3
+ readonly _id: string;
4
+ readonly name: string;
5
+ }
6
+ /**
7
+ * Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
8
+ * form leaves room for per-feature options later without a breaking change.
9
+ */
10
+ type PreprFeatureConfig = boolean | {
11
+ enabled?: boolean;
12
+ };
13
+ /** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
14
+ interface PreprFeatures {
15
+ /** Segment picker, `Prepr-Segments` header and its cookie/query param. */
16
+ segments?: PreprFeatureConfig;
17
+ /** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
18
+ abTesting?: PreprFeatureConfig;
19
+ /**
20
+ * The site's own click-to-edit: the toolbar's Edit mode control, the stega
21
+ * tooltip/overlay and the close-edit pill.
22
+ *
23
+ * NOT a security control, and NOT the Prepr editor's live preview. When the
24
+ * site is framed by the editor, `prepr:initVE` still activates edit mode —
25
+ * that is the CMS operating inside its own iframe, not an affordance offered
26
+ * to visitors. See iframe-bridge.ts.
27
+ */
28
+ editMode?: PreprFeatureConfig;
29
+ }
30
+ /**
31
+ * The data the toolbar shows. `getToolbarProps` builds it on the server from
32
+ * the request headers.
33
+ */
34
+ interface PreprToolbarProps {
35
+ /**
36
+ * Server-resolved active segment. Optional: omit it with `segments`
37
+ * disabled, where there is nothing to resolve. When enabled and omitted,
38
+ * the persisted cookie is used.
39
+ */
40
+ readonly activeSegment?: string | null;
41
+ /**
42
+ * Server-resolved active A/B variant. Optional: omit it with `abTesting`
43
+ * disabled, where there is nothing to resolve. When enabled and omitted,
44
+ * the persisted cookie is used.
45
+ */
46
+ readonly activeVariant?: string | null;
47
+ /** Available segments to personalize on. */
48
+ readonly segments?: readonly PreprSegment[];
49
+ /** @deprecated Alias for `segments`. */
50
+ readonly data?: readonly PreprSegment[];
51
+ }
52
+ /** The two sides of an A/B test. */
53
+ type PreprVariant = 'A' | 'B';
54
+ /**
55
+ * The headers to send with a Prepr GraphQL request so the API personalizes
56
+ * the response for this visitor. `getPreprHeaders` returns them; spread them
57
+ * into the request's `headers`.
58
+ */
59
+ interface PreprHeaders {
60
+ readonly 'prepr-customer-id'?: string;
61
+ readonly 'Prepr-Segments'?: string;
62
+ readonly 'Prepr-ABtesting'?: PreprVariant;
63
+ readonly 'Prepr-Preview-Bar'?: 'true';
64
+ readonly 'Prepr-Context-utm_source'?: string;
65
+ readonly 'Prepr-Context-utm_medium'?: string;
66
+ readonly 'Prepr-Context-utm_term'?: string;
67
+ readonly 'Prepr-Context-utm_content'?: string;
68
+ readonly 'Prepr-Context-utm_campaign'?: string;
69
+ readonly 'Prepr-Context-initial_referral'?: string;
70
+ readonly 'Prepr-Visitor-IP'?: string;
71
+ readonly 'Prepr-Hubspot-Id'?: string;
72
+ readonly 'Prepr-Customer-Id-Created'?: 'true';
73
+ /** The visitor's browser User-Agent, used by the API for device detection. */
74
+ readonly 'User-Agent'?: string;
75
+ /** @deprecated Never populated; the visitor's value is under `User-Agent`. */
76
+ readonly 'Prepr-User-Agent'?: string;
77
+ readonly 'Prepr-Package'?: string;
78
+ }
79
+ /** Why a `PreprError` was thrown; read it from `error.code`. */
80
+ type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
3
81
 
82
+ /** Options for the Prepr middleware of every framework. */
4
83
  interface PreprMiddlewareOptions {
5
84
  /** Enable preview-mode headers (segment/AB overrides, preview bar). */
6
85
  preview?: boolean;
@@ -58,19 +137,41 @@ declare function preprHandle(options?: PreprMiddlewareOptions): Handle;
58
137
  */
59
138
  declare function getPreprHeadersFromLocals(locals: Record<string, unknown>): Headers;
60
139
 
61
- /** Returns the Prepr Customer ID from `event.request.headers`. */
140
+ /** Returns the Prepr Customer ID from the request headers. */
62
141
  declare function getPreprUUID(headers: Headers): string | null;
63
- /** Returns the active segment from `event.request.headers`. */
142
+ /** Returns the active segment from the request headers. */
64
143
  declare function getActiveSegment(headers: Headers): string | null;
65
- /** Returns the active A/B testing variant from `event.request.headers`. */
144
+ /** Returns the active A/B testing variant from the request headers. */
66
145
  declare function getActiveVariant(headers: Headers): string | null;
67
- /** Returns all Prepr headers from `event.request.headers`. */
146
+ /** Returns all Prepr headers from the request headers. */
68
147
  declare function getPreprHeaders(headers: Headers): PreprHeaders;
69
148
  /**
70
- * Props needed to mount `PreprToolbar.svelte`, from `event.request.headers`
71
- * plus a Prepr GraphQL token. Ungated — gate on preview mode yourself in
72
- * `+layout.server.ts`.
149
+ * Props needed to mount the `PreprToolbar` component, from the request
150
+ * headers plus a Prepr GraphQL token.
151
+ *
152
+ * Ungated: call it only when your app is in preview mode. Resolve that however
153
+ * your deployment already does — the toolkit reads no environment variables of
154
+ * its own.
73
155
  */
74
156
  declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
75
157
 
76
- export { type Handle, PREPR_LOCALS_KEY, type PreprMiddlewareOptions, type SvelteKitRequestEvent, type SvelteKitResolve, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprHeadersFromLocals, getPreprUUID, getToolbarProps, preprHandle };
158
+ /** Error thrown by the token helpers and the segments fetch. */
159
+ declare class PreprError extends Error {
160
+ readonly code: PreprErrorCode;
161
+ readonly context?: string | undefined;
162
+ readonly originalError?: Error | undefined;
163
+ constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
164
+ }
165
+ /**
166
+ * Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
167
+ * @throws PreprError if the token is missing or not an HTTPS URL.
168
+ */
169
+ declare function validatePreprToken(token: string): void;
170
+ /**
171
+ * Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
172
+ * -> `abc123`.
173
+ * @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
174
+ */
175
+ declare function extractAccessToken(graphqlUrl: string): string;
176
+
177
+ export { type Handle, PREPR_LOCALS_KEY, PreprError, type PreprMiddlewareOptions, type SvelteKitRequestEvent, type SvelteKitResolve, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprHeadersFromLocals, getPreprUUID, getToolbarProps, preprHandle, validatePreprToken };