@preprio/toolkit 0.3.5 → 0.4.1

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 CHANGED
@@ -1,9 +1,14 @@
1
1
  # @preprio/toolkit
2
2
 
3
- > **Beta — pre-1.0.** The package is published to `latest` and is safe to use, but the
4
- > public API can still change between minor versions (`0.2.x` → `0.3.0`). Every change
5
- > is documented in [Breaking changes](https://github.com/preprio/prepr-toolkit/blob/main/RELEASING.md#breaking-changes). Pin an exact
6
- > version in production, or use a tilde range (`~0.2.0`) so you only pick up patches.
3
+ > **Stable, pre-1.0.** The core is stable and published to `latest`. The package follows
4
+ > semver: minor and patch releases never break the public API, and any breaking change
5
+ > ships as a major bump with a migration entry in
6
+ > [Breaking changes](https://github.com/preprio/prepr-toolkit/blob/main/RELEASING.md#breaking-changes).
7
+ >
8
+ > **Framework support.** The Next.js and Astro integrations are tested end to end. The
9
+ > Nuxt, SvelteKit, and vanilla wrappers share the same core but have seen less real-world
10
+ > use. If you hit a problem with any of them, please
11
+ > [open an issue](https://github.com/preprio/prepr-toolkit/issues).
7
12
 
8
13
  A framework-agnostic TypeScript library that provides preview functionality, visual editing, and A/B testing for [Prepr CMS](https://prepr.io). Ships thin wrappers for Next.js, Nuxt, Astro, and SvelteKit on top of a vanilla core that runs anywhere.
9
14
 
@@ -30,7 +30,7 @@ __export(astro_exports, {
30
30
  module.exports = __toCommonJS(astro_exports);
31
31
 
32
32
  // src/version.ts
33
- var VERSION = "0.3.5";
33
+ var VERSION = "0.4.1";
34
34
 
35
35
  // src/core/features.ts
36
36
  function isEnabled(config) {
@@ -83,7 +83,8 @@ var PREPR_HEADER_KEYS = [
83
83
  "Prepr-Visitor-IP",
84
84
  "Prepr-Hubspot-Id",
85
85
  "Prepr-Customer-Id-Created",
86
- "Prepr-User-Agent"
86
+ "Prepr-User-Agent",
87
+ "Prepr-Package"
87
88
  ];
88
89
  function getPreprHeadersFromHeaders(headers) {
89
90
  const preprHeaders = {};
@@ -119,6 +120,10 @@ async function getPreprEnvironmentSegments(token) {
119
120
  try {
120
121
  const response = await fetch(token, {
121
122
  headers: {
123
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
124
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
125
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
126
+ // still identify the toolbar by that string.
122
127
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
123
128
  "Content-Type": "application/json"
124
129
  },
@@ -234,7 +239,7 @@ function parseCookies(request) {
234
239
  }
235
240
  return cookies;
236
241
  }
237
- function processPreprRequest(request, opts) {
242
+ function processFrameworkRequest(request, opts, framework) {
238
243
  const requestHeaders = new Headers(request.headers);
239
244
  const responseCookies = [];
240
245
  const inboundPreprHeaders = [];
@@ -269,10 +274,10 @@ function processPreprRequest(request, opts) {
269
274
  if (userAgent) {
270
275
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
271
276
  }
272
- requestHeaders.set(
273
- "Prepr-Package",
274
- `@preprio/toolkit@${opts?.version ?? VERSION}`
275
- );
277
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
278
+ if (framework) packageParts.push(`framework=${framework}`);
279
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
280
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
276
281
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
277
282
  if (ip) {
278
283
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -357,9 +362,10 @@ function processPreprRequest(request, opts) {
357
362
 
358
363
  // src/astro/index.ts
359
364
  async function onPreprRequest(context, next, options) {
360
- const { requestHeaders, responseCookies } = processPreprRequest(
365
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
361
366
  context.request,
362
- options
367
+ options,
368
+ "astro"
363
369
  );
364
370
  requestHeaders.forEach((value, key) => {
365
371
  context.request.headers.set(key, value);
@@ -60,6 +60,7 @@ interface PreprHeaders {
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
62
  readonly 'Prepr-User-Agent'?: string;
63
+ readonly 'Prepr-Package'?: string;
63
64
  }
64
65
 
65
66
  interface PreprMiddlewareOptions {
@@ -60,6 +60,7 @@ interface PreprHeaders {
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
62
  readonly 'Prepr-User-Agent'?: string;
63
+ readonly 'Prepr-Package'?: string;
63
64
  }
64
65
 
65
66
  interface PreprMiddlewareOptions {
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.3.5";
2
+ var VERSION = "0.4.1";
3
3
 
4
4
  // src/core/features.ts
5
5
  function isEnabled(config) {
@@ -52,7 +52,8 @@ var PREPR_HEADER_KEYS = [
52
52
  "Prepr-Visitor-IP",
53
53
  "Prepr-Hubspot-Id",
54
54
  "Prepr-Customer-Id-Created",
55
- "Prepr-User-Agent"
55
+ "Prepr-User-Agent",
56
+ "Prepr-Package"
56
57
  ];
57
58
  function getPreprHeadersFromHeaders(headers) {
58
59
  const preprHeaders = {};
@@ -88,6 +89,10 @@ async function getPreprEnvironmentSegments(token) {
88
89
  try {
89
90
  const response = await fetch(token, {
90
91
  headers: {
92
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
93
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
94
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
95
+ // still identify the toolbar by that string.
91
96
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
92
97
  "Content-Type": "application/json"
93
98
  },
@@ -203,7 +208,7 @@ function parseCookies(request) {
203
208
  }
204
209
  return cookies;
205
210
  }
206
- function processPreprRequest(request, opts) {
211
+ function processFrameworkRequest(request, opts, framework) {
207
212
  const requestHeaders = new Headers(request.headers);
208
213
  const responseCookies = [];
209
214
  const inboundPreprHeaders = [];
@@ -238,10 +243,10 @@ function processPreprRequest(request, opts) {
238
243
  if (userAgent) {
239
244
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
240
245
  }
241
- requestHeaders.set(
242
- "Prepr-Package",
243
- `@preprio/toolkit@${opts?.version ?? VERSION}`
244
- );
246
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
247
+ if (framework) packageParts.push(`framework=${framework}`);
248
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
249
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
245
250
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
246
251
  if (ip) {
247
252
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -326,9 +331,10 @@ function processPreprRequest(request, opts) {
326
331
 
327
332
  // src/astro/index.ts
328
333
  async function onPreprRequest(context, next, options) {
329
- const { requestHeaders, responseCookies } = processPreprRequest(
334
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
330
335
  context.request,
331
- options
336
+ options,
337
+ "astro"
332
338
  );
333
339
  requestHeaders.forEach((value, key) => {
334
340
  context.request.headers.set(key, value);
@@ -1,3 +1,6 @@
1
+ // src/version.ts
2
+ var VERSION = "0.4.1";
3
+
1
4
  // src/core/features.ts
2
5
  function isEnabled(config) {
3
6
  if (typeof config === "boolean") return config;
@@ -2281,6 +2284,7 @@ function loadTrackingPixel(trackingId, config) {
2281
2284
  } else {
2282
2285
  queueFn("init", trackingId);
2283
2286
  }
2287
+ queueFn("param", "pp", VERSION);
2284
2288
  queueFn("event", "pageload");
2285
2289
  }
2286
2290
  function trackEvent(name, data) {
@@ -2303,6 +2307,7 @@ function setTrackingParam(key, value) {
2303
2307
  }
2304
2308
 
2305
2309
  export {
2310
+ VERSION,
2306
2311
  resolveFeatures,
2307
2312
  COOKIE_PREVIEW_MODE,
2308
2313
  COOKIE_SEGMENT,
package/dist/index.cjs CHANGED
@@ -44,7 +44,7 @@ __export(src_exports, {
44
44
  module.exports = __toCommonJS(src_exports);
45
45
 
46
46
  // src/version.ts
47
- var VERSION = "0.3.5";
47
+ var VERSION = "0.4.1";
48
48
 
49
49
  // src/core/features.ts
50
50
  function isEnabled(config) {
@@ -2319,7 +2319,8 @@ var PREPR_HEADER_KEYS = [
2319
2319
  "Prepr-Visitor-IP",
2320
2320
  "Prepr-Hubspot-Id",
2321
2321
  "Prepr-Customer-Id-Created",
2322
- "Prepr-User-Agent"
2322
+ "Prepr-User-Agent",
2323
+ "Prepr-Package"
2323
2324
  ];
2324
2325
  function getPreprHeadersFromHeaders(headers) {
2325
2326
  const preprHeaders = {};
@@ -2385,6 +2386,10 @@ async function getPreprEnvironmentSegments(token) {
2385
2386
  try {
2386
2387
  const response = await fetch(token, {
2387
2388
  headers: {
2389
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
2390
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
2391
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
2392
+ // still identify the toolbar by that string.
2388
2393
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
2389
2394
  "Content-Type": "application/json"
2390
2395
  },
@@ -2476,6 +2481,9 @@ function parseCookies(request) {
2476
2481
  return cookies;
2477
2482
  }
2478
2483
  function processPreprRequest(request, opts) {
2484
+ return processFrameworkRequest(request, opts);
2485
+ }
2486
+ function processFrameworkRequest(request, opts, framework) {
2479
2487
  const requestHeaders = new Headers(request.headers);
2480
2488
  const responseCookies = [];
2481
2489
  const inboundPreprHeaders = [];
@@ -2510,10 +2518,10 @@ function processPreprRequest(request, opts) {
2510
2518
  if (userAgent) {
2511
2519
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
2512
2520
  }
2513
- requestHeaders.set(
2514
- "Prepr-Package",
2515
- `@preprio/toolkit@${opts?.version ?? VERSION}`
2516
- );
2521
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
2522
+ if (framework) packageParts.push(`framework=${framework}`);
2523
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
2524
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
2517
2525
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
2518
2526
  if (ip) {
2519
2527
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -2639,6 +2647,7 @@ function loadTrackingPixel(trackingId, config) {
2639
2647
  } else {
2640
2648
  queueFn("init", trackingId);
2641
2649
  }
2650
+ queueFn("param", "pp", VERSION);
2642
2651
  queueFn("event", "pageload");
2643
2652
  }
2644
2653
  function trackEvent(name, data) {
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
- import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-B6FtY-11.cjs';
2
- export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-B6FtY-11.cjs';
1
+ import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-Wsfvw9G2.cjs';
2
+ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-Wsfvw9G2.cjs';
3
3
 
4
4
  /**
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "0.3.5";
8
+ declare const VERSION = "0.4.1";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-B6FtY-11.js';
2
- export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-B6FtY-11.js';
1
+ import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-Wsfvw9G2.js';
2
+ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-Wsfvw9G2.js';
3
3
 
4
4
  /**
5
5
  * Package version; must match package.json. Lives in its own leaf module so
6
6
  * core can import it without cycling through the barrel.
7
7
  */
8
- declare const VERSION = "0.3.5";
8
+ declare const VERSION = "0.4.1";
9
9
 
10
10
  /**
11
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  PARAM_SEGMENT,
10
10
  PARAM_VARIANT,
11
11
  PreprToolbarElement,
12
+ VERSION,
12
13
  createPreprPreview,
13
14
  createToolbarStore,
14
15
  definePreprToolbar,
@@ -17,10 +18,7 @@ import {
17
18
  setTrackingParam,
18
19
  stegaClean,
19
20
  trackEvent
20
- } from "./chunk-HXQ6JUZM.js";
21
-
22
- // src/version.ts
23
- var VERSION = "0.3.5";
21
+ } from "./chunk-FP5XYD6J.js";
24
22
 
25
23
  // src/core/server.ts
26
24
  var PreprError = class extends Error {
@@ -55,7 +53,8 @@ var PREPR_HEADER_KEYS = [
55
53
  "Prepr-Visitor-IP",
56
54
  "Prepr-Hubspot-Id",
57
55
  "Prepr-Customer-Id-Created",
58
- "Prepr-User-Agent"
56
+ "Prepr-User-Agent",
57
+ "Prepr-Package"
59
58
  ];
60
59
  function getPreprHeadersFromHeaders(headers) {
61
60
  const preprHeaders = {};
@@ -121,6 +120,10 @@ async function getPreprEnvironmentSegments(token) {
121
120
  try {
122
121
  const response = await fetch(token, {
123
122
  headers: {
123
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
124
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
125
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
126
+ // still identify the toolbar by that string.
124
127
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
125
128
  "Content-Type": "application/json"
126
129
  },
@@ -212,6 +215,9 @@ function parseCookies(request) {
212
215
  return cookies;
213
216
  }
214
217
  function processPreprRequest(request, opts) {
218
+ return processFrameworkRequest(request, opts);
219
+ }
220
+ function processFrameworkRequest(request, opts, framework) {
215
221
  const requestHeaders = new Headers(request.headers);
216
222
  const responseCookies = [];
217
223
  const inboundPreprHeaders = [];
@@ -246,10 +252,10 @@ function processPreprRequest(request, opts) {
246
252
  if (userAgent) {
247
253
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
248
254
  }
249
- requestHeaders.set(
250
- "Prepr-Package",
251
- `@preprio/toolkit@${opts?.version ?? VERSION}`
252
- );
255
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
256
+ if (framework) packageParts.push(`framework=${framework}`);
257
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
258
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
253
259
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
254
260
  if (ip) {
255
261
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -2265,6 +2265,9 @@ function createPreprPreview(opts = {}) {
2265
2265
  // src/react/components.ts
2266
2266
  var import_react = require("react");
2267
2267
 
2268
+ // src/version.ts
2269
+ var VERSION = "0.4.1";
2270
+
2268
2271
  // src/core/pixel.ts
2269
2272
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
2270
2273
  var CACHE_BUST_INTERVAL_MS = 24 * 60 * 60 * 1e3;
@@ -2300,6 +2303,7 @@ function loadTrackingPixel(trackingId, config) {
2300
2303
  } else {
2301
2304
  queueFn("init", trackingId);
2302
2305
  }
2306
+ queueFn("param", "pp", VERSION);
2303
2307
  queueFn("event", "pageload");
2304
2308
  }
2305
2309
 
@@ -1,4 +1,4 @@
1
- import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-B6FtY-11.cjs';
1
+ import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-Wsfvw9G2.cjs';
2
2
 
3
3
  interface PreprTrackingPixelProps {
4
4
  /** Prepr tracking/access token. */
@@ -1,4 +1,4 @@
1
- import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-B6FtY-11.js';
1
+ import { k as PreprPixelConfig, l as PreprToolbarComponentProps } from '../pixel-Wsfvw9G2.js';
2
2
 
3
3
  interface PreprTrackingPixelProps {
4
4
  /** Prepr tracking/access token. */
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  createPreprPreview,
4
4
  loadTrackingPixel
5
- } from "../chunk-HXQ6JUZM.js";
5
+ } from "../chunk-FP5XYD6J.js";
6
6
 
7
7
  // src/nextjs/components.ts
8
8
  import { usePathname, useRouter } from "next/navigation";
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(nextjs_exports);
38
38
  var import_server = require("next/server");
39
39
 
40
40
  // src/version.ts
41
- var VERSION = "0.3.5";
41
+ var VERSION = "0.4.1";
42
42
 
43
43
  // src/core/constants.ts
44
44
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -100,7 +100,7 @@ function parseCookies(request) {
100
100
  }
101
101
  return cookies;
102
102
  }
103
- function processPreprRequest(request, opts) {
103
+ function processFrameworkRequest(request, opts, framework) {
104
104
  const requestHeaders = new Headers(request.headers);
105
105
  const responseCookies = [];
106
106
  const inboundPreprHeaders = [];
@@ -135,10 +135,10 @@ function processPreprRequest(request, opts) {
135
135
  if (userAgent) {
136
136
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
137
137
  }
138
- requestHeaders.set(
139
- "Prepr-Package",
140
- `@preprio/toolkit@${opts?.version ?? VERSION}`
141
- );
138
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
139
+ if (framework) packageParts.push(`framework=${framework}`);
140
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
141
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
142
142
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
143
143
  if (ip) {
144
144
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -231,9 +231,10 @@ function createPreprMiddleware(request, responseOrOptions, maybeOptions) {
231
231
  } else {
232
232
  options = responseOrOptions;
233
233
  }
234
- const { requestHeaders, responseCookies } = processPreprRequest(
234
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
235
235
  request,
236
- options
236
+ options,
237
+ "nextjs"
237
238
  );
238
239
  const response = chainedResponse ?? import_server.NextResponse.next({ request: { headers: requestHeaders } });
239
240
  if (chainedResponse) {
@@ -297,7 +298,8 @@ var PREPR_HEADER_KEYS = [
297
298
  "Prepr-Visitor-IP",
298
299
  "Prepr-Hubspot-Id",
299
300
  "Prepr-Customer-Id-Created",
300
- "Prepr-User-Agent"
301
+ "Prepr-User-Agent",
302
+ "Prepr-Package"
301
303
  ];
302
304
  function getPreprHeadersFromHeaders(headers2) {
303
305
  const preprHeaders = {};
@@ -363,6 +365,10 @@ async function getPreprEnvironmentSegments(token) {
363
365
  try {
364
366
  const response = await fetch(token, {
365
367
  headers: {
368
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
369
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
370
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
371
+ // still identify the toolbar by that string.
366
372
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
367
373
  "Content-Type": "application/json"
368
374
  },
@@ -120,6 +120,7 @@ interface PreprHeaders {
120
120
  readonly 'Prepr-Hubspot-Id'?: string;
121
121
  readonly 'Prepr-Customer-Id-Created'?: 'true';
122
122
  readonly 'Prepr-User-Agent'?: string;
123
+ readonly 'Prepr-Package'?: string;
123
124
  }
124
125
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
125
126
 
@@ -120,6 +120,7 @@ interface PreprHeaders {
120
120
  readonly 'Prepr-Hubspot-Id'?: string;
121
121
  readonly 'Prepr-Customer-Id-Created'?: 'true';
122
122
  readonly 'Prepr-User-Agent'?: string;
123
+ readonly 'Prepr-Package'?: string;
123
124
  }
124
125
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
125
126
 
@@ -2,7 +2,7 @@
2
2
  import { NextResponse } from "next/server";
3
3
 
4
4
  // src/version.ts
5
- var VERSION = "0.3.5";
5
+ var VERSION = "0.4.1";
6
6
 
7
7
  // src/core/constants.ts
8
8
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -64,7 +64,7 @@ function parseCookies(request) {
64
64
  }
65
65
  return cookies;
66
66
  }
67
- function processPreprRequest(request, opts) {
67
+ function processFrameworkRequest(request, opts, framework) {
68
68
  const requestHeaders = new Headers(request.headers);
69
69
  const responseCookies = [];
70
70
  const inboundPreprHeaders = [];
@@ -99,10 +99,10 @@ function processPreprRequest(request, opts) {
99
99
  if (userAgent) {
100
100
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
101
101
  }
102
- requestHeaders.set(
103
- "Prepr-Package",
104
- `@preprio/toolkit@${opts?.version ?? VERSION}`
105
- );
102
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
103
+ if (framework) packageParts.push(`framework=${framework}`);
104
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
105
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
106
106
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
107
107
  if (ip) {
108
108
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -195,9 +195,10 @@ function createPreprMiddleware(request, responseOrOptions, maybeOptions) {
195
195
  } else {
196
196
  options = responseOrOptions;
197
197
  }
198
- const { requestHeaders, responseCookies } = processPreprRequest(
198
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
199
199
  request,
200
- options
200
+ options,
201
+ "nextjs"
201
202
  );
202
203
  const response = chainedResponse ?? NextResponse.next({ request: { headers: requestHeaders } });
203
204
  if (chainedResponse) {
@@ -261,7 +262,8 @@ var PREPR_HEADER_KEYS = [
261
262
  "Prepr-Visitor-IP",
262
263
  "Prepr-Hubspot-Id",
263
264
  "Prepr-Customer-Id-Created",
264
- "Prepr-User-Agent"
265
+ "Prepr-User-Agent",
266
+ "Prepr-Package"
265
267
  ];
266
268
  function getPreprHeadersFromHeaders(headers2) {
267
269
  const preprHeaders = {};
@@ -327,6 +329,10 @@ async function getPreprEnvironmentSegments(token) {
327
329
  try {
328
330
  const response = await fetch(token, {
329
331
  headers: {
332
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
333
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
334
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
335
+ // still identify the toolbar by that string.
330
336
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
331
337
  "Content-Type": "application/json"
332
338
  },
@@ -35,7 +35,7 @@ __export(nuxt_exports, {
35
35
  module.exports = __toCommonJS(nuxt_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "0.3.5";
38
+ var VERSION = "0.4.1";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -111,7 +111,7 @@ function parseCookies(request) {
111
111
  }
112
112
  return cookies;
113
113
  }
114
- function processPreprRequest(request, opts) {
114
+ function processFrameworkRequest(request, opts, framework) {
115
115
  const requestHeaders = new Headers(request.headers);
116
116
  const responseCookies = [];
117
117
  const inboundPreprHeaders = [];
@@ -146,10 +146,10 @@ function processPreprRequest(request, opts) {
146
146
  if (userAgent) {
147
147
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
148
148
  }
149
- requestHeaders.set(
150
- "Prepr-Package",
151
- `@preprio/toolkit@${opts?.version ?? VERSION}`
152
- );
149
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
150
+ if (framework) packageParts.push(`framework=${framework}`);
151
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
152
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
153
153
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
154
154
  if (ip) {
155
155
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -245,9 +245,10 @@ function handlePreprRequest(event, options) {
245
245
  request.headers.set(key, value.join(", "));
246
246
  }
247
247
  }
248
- const { requestHeaders, responseCookies } = processPreprRequest(
248
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
249
249
  request,
250
- options
250
+ options,
251
+ "nuxt"
251
252
  );
252
253
  requestHeaders.forEach((value, key) => {
253
254
  req.headers[key.toLowerCase()] = value;
@@ -295,7 +296,8 @@ var PREPR_HEADER_KEYS = [
295
296
  "Prepr-Visitor-IP",
296
297
  "Prepr-Hubspot-Id",
297
298
  "Prepr-Customer-Id-Created",
298
- "Prepr-User-Agent"
299
+ "Prepr-User-Agent",
300
+ "Prepr-Package"
299
301
  ];
300
302
  function getPreprHeadersFromHeaders(headers) {
301
303
  const preprHeaders = {};
@@ -361,6 +363,10 @@ async function getPreprEnvironmentSegments(token) {
361
363
  try {
362
364
  const response = await fetch(token, {
363
365
  headers: {
366
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
367
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
368
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
369
+ // still identify the toolbar by that string.
364
370
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
365
371
  "Content-Type": "application/json"
366
372
  },
@@ -60,6 +60,7 @@ interface PreprHeaders {
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
62
  readonly 'Prepr-User-Agent'?: string;
63
+ readonly 'Prepr-Package'?: string;
63
64
  }
64
65
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
65
66
 
@@ -60,6 +60,7 @@ interface PreprHeaders {
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
62
  readonly 'Prepr-User-Agent'?: string;
63
+ readonly 'Prepr-Package'?: string;
63
64
  }
64
65
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
65
66
 
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.3.5";
2
+ var VERSION = "0.4.1";
3
3
 
4
4
  // src/core/constants.ts
5
5
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -75,7 +75,7 @@ function parseCookies(request) {
75
75
  }
76
76
  return cookies;
77
77
  }
78
- function processPreprRequest(request, opts) {
78
+ function processFrameworkRequest(request, opts, framework) {
79
79
  const requestHeaders = new Headers(request.headers);
80
80
  const responseCookies = [];
81
81
  const inboundPreprHeaders = [];
@@ -110,10 +110,10 @@ function processPreprRequest(request, opts) {
110
110
  if (userAgent) {
111
111
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
112
112
  }
113
- requestHeaders.set(
114
- "Prepr-Package",
115
- `@preprio/toolkit@${opts?.version ?? VERSION}`
116
- );
113
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
114
+ if (framework) packageParts.push(`framework=${framework}`);
115
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
116
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
117
117
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
118
118
  if (ip) {
119
119
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -209,9 +209,10 @@ function handlePreprRequest(event, options) {
209
209
  request.headers.set(key, value.join(", "));
210
210
  }
211
211
  }
212
- const { requestHeaders, responseCookies } = processPreprRequest(
212
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
213
213
  request,
214
- options
214
+ options,
215
+ "nuxt"
215
216
  );
216
217
  requestHeaders.forEach((value, key) => {
217
218
  req.headers[key.toLowerCase()] = value;
@@ -259,7 +260,8 @@ var PREPR_HEADER_KEYS = [
259
260
  "Prepr-Visitor-IP",
260
261
  "Prepr-Hubspot-Id",
261
262
  "Prepr-Customer-Id-Created",
262
- "Prepr-User-Agent"
263
+ "Prepr-User-Agent",
264
+ "Prepr-Package"
263
265
  ];
264
266
  function getPreprHeadersFromHeaders(headers) {
265
267
  const preprHeaders = {};
@@ -325,6 +327,10 @@ async function getPreprEnvironmentSegments(token) {
325
327
  try {
326
328
  const response = await fetch(token, {
327
329
  headers: {
330
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
331
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
332
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
333
+ // still identify the toolbar by that string.
328
334
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
329
335
  "Content-Type": "application/json"
330
336
  },
@@ -127,6 +127,7 @@ interface PreprHeaders {
127
127
  readonly 'Prepr-Hubspot-Id'?: string;
128
128
  readonly 'Prepr-Customer-Id-Created'?: 'true';
129
129
  readonly 'Prepr-User-Agent'?: string;
130
+ readonly 'Prepr-Package'?: string;
130
131
  }
131
132
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
132
133
 
@@ -127,6 +127,7 @@ interface PreprHeaders {
127
127
  readonly 'Prepr-Hubspot-Id'?: string;
128
128
  readonly 'Prepr-Customer-Id-Created'?: 'true';
129
129
  readonly 'Prepr-User-Agent'?: string;
130
+ readonly 'Prepr-Package'?: string;
130
131
  }
131
132
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
132
133
 
@@ -2261,6 +2261,9 @@ function createPreprPreview(opts = {}) {
2261
2261
  return controller;
2262
2262
  }
2263
2263
 
2264
+ // src/version.ts
2265
+ var VERSION = "0.4.1";
2266
+
2264
2267
  // src/core/pixel.ts
2265
2268
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
2266
2269
  var CACHE_BUST_INTERVAL_MS = 24 * 60 * 60 * 1e3;
@@ -2296,6 +2299,7 @@ function loadTrackingPixel(trackingId, config) {
2296
2299
  } else {
2297
2300
  queueFn("init", trackingId);
2298
2301
  }
2302
+ queueFn("param", "pp", VERSION);
2299
2303
  queueFn("event", "pageload");
2300
2304
  }
2301
2305
 
@@ -2237,6 +2237,9 @@ function createPreprPreview(opts = {}) {
2237
2237
  return controller;
2238
2238
  }
2239
2239
 
2240
+ // src/version.ts
2241
+ var VERSION = "0.4.1";
2242
+
2240
2243
  // src/core/pixel.ts
2241
2244
  var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
2242
2245
  var CACHE_BUST_INTERVAL_MS = 24 * 60 * 60 * 1e3;
@@ -2272,6 +2275,7 @@ function loadTrackingPixel(trackingId, config) {
2272
2275
  } else {
2273
2276
  queueFn("init", trackingId);
2274
2277
  }
2278
+ queueFn("param", "pp", VERSION);
2275
2279
  queueFn("event", "pageload");
2276
2280
  }
2277
2281
 
@@ -35,7 +35,7 @@ __export(sveltekit_exports, {
35
35
  module.exports = __toCommonJS(sveltekit_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "0.3.5";
38
+ var VERSION = "0.4.1";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -111,7 +111,7 @@ function parseCookies(request) {
111
111
  }
112
112
  return cookies;
113
113
  }
114
- function processPreprRequest(request, opts) {
114
+ function processFrameworkRequest(request, opts, framework) {
115
115
  const requestHeaders = new Headers(request.headers);
116
116
  const responseCookies = [];
117
117
  const inboundPreprHeaders = [];
@@ -146,10 +146,10 @@ function processPreprRequest(request, opts) {
146
146
  if (userAgent) {
147
147
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
148
148
  }
149
- requestHeaders.set(
150
- "Prepr-Package",
151
- `@preprio/toolkit@${opts?.version ?? VERSION}`
152
- );
149
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
150
+ if (framework) packageParts.push(`framework=${framework}`);
151
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
152
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
153
153
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
154
154
  if (ip) {
155
155
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -236,9 +236,10 @@ function processPreprRequest(request, opts) {
236
236
  var PREPR_LOCALS_KEY = "prepr";
237
237
  function preprHandle(options) {
238
238
  return async ({ event, resolve }) => {
239
- const { requestHeaders, responseCookies } = processPreprRequest(
239
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
240
240
  event.request,
241
- options
241
+ options,
242
+ "sveltekit"
242
243
  );
243
244
  requestHeaders.forEach((value, key) => {
244
245
  event.request.headers.set(key, value);
@@ -291,7 +292,8 @@ var PREPR_HEADER_KEYS = [
291
292
  "Prepr-Visitor-IP",
292
293
  "Prepr-Hubspot-Id",
293
294
  "Prepr-Customer-Id-Created",
294
- "Prepr-User-Agent"
295
+ "Prepr-User-Agent",
296
+ "Prepr-Package"
295
297
  ];
296
298
  function getPreprHeadersFromHeaders(headers) {
297
299
  const preprHeaders = {};
@@ -357,6 +359,10 @@ async function getPreprEnvironmentSegments(token) {
357
359
  try {
358
360
  const response = await fetch(token, {
359
361
  headers: {
362
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
363
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
364
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
365
+ // still identify the toolbar by that string.
360
366
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
361
367
  "Content-Type": "application/json"
362
368
  },
@@ -60,6 +60,7 @@ interface PreprHeaders {
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
62
  readonly 'Prepr-User-Agent'?: string;
63
+ readonly 'Prepr-Package'?: string;
63
64
  }
64
65
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
65
66
 
@@ -60,6 +60,7 @@ interface PreprHeaders {
60
60
  readonly 'Prepr-Hubspot-Id'?: string;
61
61
  readonly 'Prepr-Customer-Id-Created'?: 'true';
62
62
  readonly 'Prepr-User-Agent'?: string;
63
+ readonly 'Prepr-Package'?: string;
63
64
  }
64
65
  type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
65
66
 
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.3.5";
2
+ var VERSION = "0.4.1";
3
3
 
4
4
  // src/core/constants.ts
5
5
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -75,7 +75,7 @@ function parseCookies(request) {
75
75
  }
76
76
  return cookies;
77
77
  }
78
- function processPreprRequest(request, opts) {
78
+ function processFrameworkRequest(request, opts, framework) {
79
79
  const requestHeaders = new Headers(request.headers);
80
80
  const responseCookies = [];
81
81
  const inboundPreprHeaders = [];
@@ -110,10 +110,10 @@ function processPreprRequest(request, opts) {
110
110
  if (userAgent) {
111
111
  requestHeaders.set("Prepr-User-Agent", sanitizeHeaderValue(userAgent));
112
112
  }
113
- requestHeaders.set(
114
- "Prepr-Package",
115
- `@preprio/toolkit@${opts?.version ?? VERSION}`
116
- );
113
+ const packageParts = [`@preprio/toolkit@${opts?.version ?? VERSION}`];
114
+ if (framework) packageParts.push(`framework=${framework}`);
115
+ packageParts.push(`preview=${opts?.preview ? "true" : "false"}`);
116
+ requestHeaders.set("Prepr-Package", packageParts.join("; "));
117
117
  const ip = request.headers.get("Cf-Connecting-Ip") ?? request.headers.get("x-real-ip");
118
118
  if (ip) {
119
119
  requestHeaders.set("Prepr-Visitor-IP", sanitizeHeaderValue(ip));
@@ -200,9 +200,10 @@ function processPreprRequest(request, opts) {
200
200
  var PREPR_LOCALS_KEY = "prepr";
201
201
  function preprHandle(options) {
202
202
  return async ({ event, resolve }) => {
203
- const { requestHeaders, responseCookies } = processPreprRequest(
203
+ const { requestHeaders, responseCookies } = processFrameworkRequest(
204
204
  event.request,
205
- options
205
+ options,
206
+ "sveltekit"
206
207
  );
207
208
  requestHeaders.forEach((value, key) => {
208
209
  event.request.headers.set(key, value);
@@ -255,7 +256,8 @@ var PREPR_HEADER_KEYS = [
255
256
  "Prepr-Visitor-IP",
256
257
  "Prepr-Hubspot-Id",
257
258
  "Prepr-Customer-Id-Created",
258
- "Prepr-User-Agent"
259
+ "Prepr-User-Agent",
260
+ "Prepr-Package"
259
261
  ];
260
262
  function getPreprHeadersFromHeaders(headers) {
261
263
  const preprHeaders = {};
@@ -321,6 +323,10 @@ async function getPreprEnvironmentSegments(token) {
321
323
  try {
322
324
  const response = await fetch(token, {
323
325
  headers: {
326
+ "Prepr-Package": `@preprio/toolkit@${VERSION}`,
327
+ // Duplicates the version in Prepr-Package. It keeps the User-Agent
328
+ // format used by `@preprio/prepr-nextjs`, for Prepr API consumers that
329
+ // still identify the toolbar by that string.
324
330
  "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
325
331
  "Content-Type": "application/json"
326
332
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preprio/toolkit",
3
- "version": "0.3.5",
3
+ "version": "0.4.1",
4
4
  "description": "Prepr personalization, A/B testing and preview toolkit for React, Next.js, Nuxt, Astro, SvelteKit and Express",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Prepr B.V. (https://prepr.io)",