@preprio/toolkit 0.6.0-alpha.8 → 1.0.0-rc.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.
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-ATPB7GEC.js → chunk-33GWVTRJ.js} +1 -1
  7. package/dist/chunk-A2J7R4LR.js +256 -0
  8. package/dist/{chunk-T7ESBVBI.js → chunk-DSJ22P6J.js} +6 -1
  9. package/dist/chunk-KM2GME62.js +1255 -0
  10. package/dist/chunk-UTKH7DOI.js +58 -0
  11. package/dist/chunk-V7MCHPE7.js +85 -0
  12. package/dist/{chunk-2QGUP7VQ.js → chunk-WBMN4L7G.js} +1680 -579
  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 -729
  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 -274
  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-R2YPGDVU.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-OY7OKO6Q.js +0 -499
  83. package/dist/chunk-S5RWVMDJ.js +0 -148
  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-O2SBSBDG.js +0 -549
  93. package/dist/nextjs/graphql.cjs +0 -1811
  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 -1397
  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-SX3MSVPK.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-UOASSHZO.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
@@ -5,13 +5,11 @@
5
5
  */
6
6
  import { onMounted } from 'vue';
7
7
  import { loadTrackingPixel } from '@preprio/toolkit';
8
+ import type { PreprPixelConfig } from '@preprio/toolkit';
8
9
 
9
10
  const props = defineProps<{
10
11
  id: string;
11
- config?: {
12
- destinations?: { googleTagManager?: boolean };
13
- variantImpressionThreshold?: number;
14
- };
12
+ config?: PreprPixelConfig;
15
13
  }>();
16
14
 
17
15
  onMounted(() => {
@@ -8,7 +8,20 @@
8
8
  */
9
9
  import { onMount } from 'svelte';
10
10
  import { createPreprPreview } from '@preprio/toolkit';
11
- import type { PreprToolbarComponentProps } from '@preprio/toolkit';
11
+ import type {
12
+ PreprNavigationAdapter,
13
+ PreprToolbarComponentProps,
14
+ } from '@preprio/toolkit';
15
+
16
+ interface Props extends PreprToolbarComponentProps {
17
+ /**
18
+ * How the toolbar changes the URL when a segment or variant is picked.
19
+ * Defaults to a full page load; pass the app's router for a soft
20
+ * navigation, e.g. `{ navigate: (url) => goto(url, { invalidateAll: true }),
21
+ * currentPath: () => page.url.pathname + page.url.search }`.
22
+ */
23
+ navigation?: PreprNavigationAdapter;
24
+ }
12
25
 
13
26
  let {
14
27
  activeSegment,
@@ -16,12 +29,14 @@
16
29
  data,
17
30
  segments,
18
31
  options,
19
- }: PreprToolbarComponentProps = $props();
32
+ navigation,
33
+ }: Props = $props();
20
34
 
21
35
  onMount(() => {
22
36
  const controller = createPreprPreview({
23
37
  props: { activeSegment, activeVariant, data, segments },
24
38
  options,
39
+ navigation,
25
40
  });
26
41
  return () => controller.destroy();
27
42
  });
@@ -5,13 +5,11 @@
5
5
  */
6
6
  import { onMount } from 'svelte';
7
7
  import { loadTrackingPixel } from '@preprio/toolkit';
8
+ import type { PreprPixelConfig } from '@preprio/toolkit';
8
9
 
9
10
  interface Props {
10
11
  id: string;
11
- config?: {
12
- destinations?: { googleTagManager?: boolean };
13
- variantImpressionThreshold?: number;
14
- };
12
+ config?: PreprPixelConfig;
15
13
  }
16
14
 
17
15
  let { id, config }: Props = $props();
@@ -1,173 +0,0 @@
1
- // src/version.ts
2
- var VERSION = "0.6.0-alpha.8";
3
-
4
- // src/core/features.ts
5
- function isEnabled(config) {
6
- if (typeof config === "boolean") return config;
7
- return config?.enabled ?? true;
8
- }
9
- function resolveFeatures(features) {
10
- return {
11
- segments: isEnabled(features?.segments),
12
- abTesting: isEnabled(features?.abTesting),
13
- editMode: isEnabled(features?.editMode)
14
- };
15
- }
16
- var ALL_FEATURES_ENABLED = Object.freeze({
17
- segments: true,
18
- abTesting: true,
19
- editMode: true
20
- });
21
-
22
- // src/core/server.ts
23
- var PreprError = class extends Error {
24
- constructor(message, code, context, originalError) {
25
- super(message);
26
- this.code = code;
27
- this.context = context;
28
- this.originalError = originalError;
29
- this.name = "PreprError";
30
- }
31
- };
32
- function getPreprUUIDFromHeaders(headers) {
33
- return headers.get("prepr-customer-id");
34
- }
35
- function getActiveSegmentFromHeaders(headers) {
36
- return headers.get("Prepr-Segments");
37
- }
38
- function getActiveVariantFromHeaders(headers) {
39
- return headers.get("Prepr-ABtesting");
40
- }
41
- var PREPR_HEADER_KEYS = [
42
- "prepr-customer-id",
43
- "Prepr-Segments",
44
- "Prepr-ABtesting",
45
- "Prepr-Preview-Bar",
46
- "Prepr-Context-utm_source",
47
- "Prepr-Context-utm_medium",
48
- "Prepr-Context-utm_term",
49
- "Prepr-Context-utm_content",
50
- "Prepr-Context-utm_campaign",
51
- "Prepr-Context-initial_referral",
52
- "Prepr-Visitor-IP",
53
- "Prepr-Hubspot-Id",
54
- "Prepr-Customer-Id-Created",
55
- "User-Agent",
56
- "Prepr-Package"
57
- ];
58
- function getPreprHeadersFromHeaders(headers) {
59
- const preprHeaders = {};
60
- const copy = (key) => {
61
- const value = headers.get(key);
62
- if (value !== null) {
63
- preprHeaders[key] = value;
64
- }
65
- };
66
- for (const key of PREPR_HEADER_KEYS) {
67
- copy(key);
68
- }
69
- return preprHeaders;
70
- }
71
- function validatePreprToken(token) {
72
- if (!token) {
73
- throw new PreprError(
74
- "Token is required",
75
- "MISSING_TOKEN",
76
- "validatePreprToken"
77
- );
78
- }
79
- if (!token.startsWith("https://")) {
80
- throw new PreprError(
81
- "Token must be a valid HTTPS URL",
82
- "INVALID_TOKEN",
83
- "validatePreprToken"
84
- );
85
- }
86
- }
87
- async function getPreprEnvironmentSegments(token) {
88
- validatePreprToken(token);
89
- try {
90
- const response = await fetch(token, {
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.
96
- "User-Agent": `Prepr-Preview-Bar/${VERSION}`,
97
- "Content-Type": "application/json"
98
- },
99
- method: "POST",
100
- body: JSON.stringify({
101
- query: `{
102
- _Segments {
103
- _id
104
- name
105
- }
106
- }`
107
- })
108
- });
109
- if (!response.ok) {
110
- throw new PreprError(
111
- `HTTP ${response.status}: ${response.statusText}`,
112
- "HTTP_ERROR",
113
- "getPreprEnvironmentSegments"
114
- );
115
- }
116
- const json = await response.json();
117
- if (!json || !json.data || !json.data._Segments) {
118
- throw new PreprError(
119
- "Invalid response format from Prepr API",
120
- "INVALID_RESPONSE",
121
- "getPreprEnvironmentSegments"
122
- );
123
- }
124
- return json.data._Segments;
125
- } catch (error) {
126
- if (error instanceof PreprError) {
127
- throw error;
128
- }
129
- throw new PreprError(
130
- "Failed to fetch segments from Prepr API",
131
- "FETCH_ERROR",
132
- "getPreprEnvironmentSegments",
133
- error instanceof Error ? error : new Error(String(error))
134
- );
135
- }
136
- }
137
- async function getToolbarPropsFromHeaders(headers, token, features) {
138
- const resolved = resolveFeatures(features);
139
- let segments = [];
140
- if (resolved.segments) {
141
- try {
142
- segments = await getPreprEnvironmentSegments(token);
143
- } catch {
144
- segments = [];
145
- }
146
- }
147
- return {
148
- activeSegment: resolved.segments ? getActiveSegmentFromHeaders(headers) : null,
149
- activeVariant: resolved.abTesting ? getActiveVariantFromHeaders(headers) : null,
150
- segments,
151
- data: segments
152
- };
153
- }
154
-
155
- // src/core/personalization.ts
156
- var PERSONALIZED_VARY = /\bPrepr-(Segments|ABTesting)/i;
157
- function isPersonalizedResponse(source) {
158
- const headers = "headers" in source ? source.headers : source;
159
- return PERSONALIZED_VARY.test(headers.get("vary") ?? "");
160
- }
161
-
162
- export {
163
- VERSION,
164
- resolveFeatures,
165
- PreprError,
166
- getPreprUUIDFromHeaders,
167
- getActiveSegmentFromHeaders,
168
- getActiveVariantFromHeaders,
169
- getPreprHeadersFromHeaders,
170
- validatePreprToken,
171
- getToolbarPropsFromHeaders,
172
- isPersonalizedResponse
173
- };