@preprio/toolkit 0.1.0-beta.3 → 0.1.0-beta.5
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/LICENSE +202 -0
- package/README.md +5 -1
- package/dist/astro/index.cjs +34 -10
- package/dist/astro/index.js +34 -10
- package/dist/{chunk-5JGPWQVA.js → chunk-NLQIRN5O.js} +84 -24
- package/dist/index.cjs +103 -28
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +20 -5
- package/dist/json-script.cjs +32 -0
- package/dist/json-script.d.cts +17 -0
- package/dist/json-script.d.ts +17 -0
- package/dist/json-script.js +7 -0
- package/dist/nextjs/components.cjs +84 -24
- package/dist/nextjs/components.js +1 -1
- package/dist/nextjs/index.cjs +23 -5
- package/dist/nextjs/index.js +23 -5
- package/dist/nuxt/index.cjs +34 -10
- package/dist/nuxt/index.js +34 -10
- package/dist/sveltekit/index.cjs +34 -10
- package/dist/sveltekit/index.js +34 -10
- package/package.json +52 -14
- package/src/astro/PreprToolbar.astro +2 -1
- package/src/astro/PreprTrackingPixel.astro +3 -1
package/dist/sveltekit/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "0.1.0-beta.
|
|
2
|
+
var VERSION = "0.1.0-beta.5";
|
|
3
3
|
|
|
4
4
|
// src/core/constants.ts
|
|
5
5
|
var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
|
|
@@ -20,6 +20,20 @@ var UTM_PARAMS = [
|
|
|
20
20
|
"utm_content",
|
|
21
21
|
"utm_campaign"
|
|
22
22
|
];
|
|
23
|
+
function serializeCookie(cookie) {
|
|
24
|
+
const parts = [
|
|
25
|
+
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
26
|
+
`Max-Age=${cookie.maxAge}`,
|
|
27
|
+
`Path=${cookie.path}`
|
|
28
|
+
];
|
|
29
|
+
if (cookie.sameSite) {
|
|
30
|
+
parts.push(`SameSite=${cookie.sameSite}`);
|
|
31
|
+
}
|
|
32
|
+
if (cookie.secure) {
|
|
33
|
+
parts.push("Secure");
|
|
34
|
+
}
|
|
35
|
+
return parts.join("; ");
|
|
36
|
+
}
|
|
23
37
|
function parseCookies(request) {
|
|
24
38
|
const cookies = /* @__PURE__ */ new Map();
|
|
25
39
|
const header = request.headers.get("cookie");
|
|
@@ -38,7 +52,11 @@ function processPreprRequest(request, opts) {
|
|
|
38
52
|
const requestHeaders = new Headers(request.headers);
|
|
39
53
|
const responseCookies = [];
|
|
40
54
|
const requestCookies = parseCookies(request);
|
|
41
|
-
const
|
|
55
|
+
const url = new URL(request.url);
|
|
56
|
+
const searchParams = url.searchParams;
|
|
57
|
+
const forwardedProto = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
|
|
58
|
+
const isSecure = forwardedProto ? forwardedProto === "https" : url.protocol === "https:";
|
|
59
|
+
const crossSite = isSecure ? { sameSite: "None", secure: true } : {};
|
|
42
60
|
for (const key of UTM_PARAMS) {
|
|
43
61
|
const value = searchParams.get(key);
|
|
44
62
|
if (value !== null) {
|
|
@@ -87,6 +105,15 @@ function processPreprRequest(request, opts) {
|
|
|
87
105
|
}
|
|
88
106
|
requestHeaders.set("Prepr-Preview-Bar", "true");
|
|
89
107
|
const isLivePreview = searchParams.get(PARAM_HIDE_BAR) === "true";
|
|
108
|
+
if (!isLivePreview && !requestCookies.has(COOKIE_PREVIEW_MODE)) {
|
|
109
|
+
responseCookies.push({
|
|
110
|
+
name: COOKIE_PREVIEW_MODE,
|
|
111
|
+
value: "true",
|
|
112
|
+
maxAge: ONE_YEAR_SECONDS,
|
|
113
|
+
path: "/",
|
|
114
|
+
...crossSite
|
|
115
|
+
});
|
|
116
|
+
}
|
|
90
117
|
if (!isLivePreview) {
|
|
91
118
|
const segmentCookie = requestCookies.get(COOKIE_SEGMENT);
|
|
92
119
|
if (segmentCookie) {
|
|
@@ -105,7 +132,8 @@ function processPreprRequest(request, opts) {
|
|
|
105
132
|
name: COOKIE_VARIANT,
|
|
106
133
|
value: previewAb,
|
|
107
134
|
maxAge: ONE_YEAR_SECONDS,
|
|
108
|
-
path: "/"
|
|
135
|
+
path: "/",
|
|
136
|
+
...crossSite
|
|
109
137
|
});
|
|
110
138
|
}
|
|
111
139
|
}
|
|
@@ -117,7 +145,8 @@ function processPreprRequest(request, opts) {
|
|
|
117
145
|
name: COOKIE_SEGMENT,
|
|
118
146
|
value: previewSegment,
|
|
119
147
|
maxAge: ONE_YEAR_SECONDS,
|
|
120
|
-
path: "/"
|
|
148
|
+
path: "/",
|
|
149
|
+
...crossSite
|
|
121
150
|
});
|
|
122
151
|
}
|
|
123
152
|
}
|
|
@@ -137,12 +166,7 @@ function preprHandle(options) {
|
|
|
137
166
|
}
|
|
138
167
|
const response = await resolve(event);
|
|
139
168
|
for (const cookie of responseCookies) {
|
|
140
|
-
|
|
141
|
-
`${cookie.name}=${encodeURIComponent(cookie.value)}`,
|
|
142
|
-
`Max-Age=${cookie.maxAge}`,
|
|
143
|
-
`Path=${cookie.path}`
|
|
144
|
-
];
|
|
145
|
-
response.headers.append("Set-Cookie", parts.join("; "));
|
|
169
|
+
response.headers.append("Set-Cookie", serializeCookie(cookie));
|
|
146
170
|
}
|
|
147
171
|
return response;
|
|
148
172
|
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preprio/toolkit",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"description": "Prepr personalization, A/B testing and preview toolkit for Next.js, Nuxt, Astro, SvelteKit and Express",
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Prepr B.V. (https://prepr.io)",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"prepr",
|
|
9
|
+
"cms",
|
|
10
|
+
"headless-cms",
|
|
11
|
+
"personalization",
|
|
12
|
+
"ab-testing",
|
|
13
|
+
"preview",
|
|
14
|
+
"visual-editing",
|
|
15
|
+
"nextjs",
|
|
16
|
+
"nuxt",
|
|
17
|
+
"astro",
|
|
18
|
+
"sveltekit"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18.17"
|
|
25
|
+
},
|
|
6
26
|
"repository": {
|
|
7
27
|
"type": "git",
|
|
8
28
|
"url": "git+https://github.com/preprio/prepr-toolkit.git",
|
|
@@ -23,6 +43,16 @@
|
|
|
23
43
|
"import": "./dist/nextjs/index.js",
|
|
24
44
|
"require": "./dist/nextjs/index.cjs"
|
|
25
45
|
},
|
|
46
|
+
"./json-script": {
|
|
47
|
+
"types": "./dist/json-script.d.ts",
|
|
48
|
+
"import": "./dist/json-script.js",
|
|
49
|
+
"require": "./dist/json-script.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./nextjs/components": {
|
|
52
|
+
"types": "./dist/nextjs/components.d.ts",
|
|
53
|
+
"import": "./dist/nextjs/components.js",
|
|
54
|
+
"require": "./dist/nextjs/components.cjs"
|
|
55
|
+
},
|
|
26
56
|
"./nextjs/image-loader": {
|
|
27
57
|
"types": "./dist/nextjs/image-loader.d.ts",
|
|
28
58
|
"import": "./dist/nextjs/image-loader.js",
|
|
@@ -53,6 +83,16 @@
|
|
|
53
83
|
"src/sveltekit/*.svelte",
|
|
54
84
|
"src/nuxt/*.vue"
|
|
55
85
|
],
|
|
86
|
+
"scripts": {
|
|
87
|
+
"gen:css": "node scripts/compile-css.mjs",
|
|
88
|
+
"prebuild": "rm -rf dist && pnpm gen:css && node scripts/check-version.mjs",
|
|
89
|
+
"pretest": "pnpm gen:css",
|
|
90
|
+
"pretypecheck": "pnpm gen:css",
|
|
91
|
+
"build": "tsup",
|
|
92
|
+
"postbuild": "node scripts/check-exports.mjs",
|
|
93
|
+
"test": "vitest run",
|
|
94
|
+
"typecheck": "tsc --noEmit"
|
|
95
|
+
},
|
|
56
96
|
"dependencies": {
|
|
57
97
|
"@vercel/stega": "^1.1.0",
|
|
58
98
|
"preact": "^10.29.7"
|
|
@@ -60,7 +100,9 @@
|
|
|
60
100
|
"peerDependencies": {
|
|
61
101
|
"next": ">=13",
|
|
62
102
|
"react": ">=17",
|
|
63
|
-
"react-dom": ">=17"
|
|
103
|
+
"react-dom": ">=17",
|
|
104
|
+
"svelte": ">=4",
|
|
105
|
+
"vue": ">=3"
|
|
64
106
|
},
|
|
65
107
|
"peerDependenciesMeta": {
|
|
66
108
|
"next": {
|
|
@@ -71,6 +113,12 @@
|
|
|
71
113
|
},
|
|
72
114
|
"react-dom": {
|
|
73
115
|
"optional": true
|
|
116
|
+
},
|
|
117
|
+
"svelte": {
|
|
118
|
+
"optional": true
|
|
119
|
+
},
|
|
120
|
+
"vue": {
|
|
121
|
+
"optional": true
|
|
74
122
|
}
|
|
75
123
|
},
|
|
76
124
|
"devDependencies": {
|
|
@@ -86,15 +134,5 @@
|
|
|
86
134
|
"tsup": "^8.5.1",
|
|
87
135
|
"typescript": "^5.9.3",
|
|
88
136
|
"vitest": "^4.1.10"
|
|
89
|
-
},
|
|
90
|
-
"scripts": {
|
|
91
|
-
"gen:css": "node scripts/compile-css.mjs",
|
|
92
|
-
"prebuild": "rm -rf dist && pnpm gen:css && node scripts/check-version.mjs",
|
|
93
|
-
"pretest": "pnpm gen:css",
|
|
94
|
-
"pretypecheck": "pnpm gen:css",
|
|
95
|
-
"build": "tsup",
|
|
96
|
-
"postbuild": "node scripts/check-exports.mjs",
|
|
97
|
-
"test": "vitest run",
|
|
98
|
-
"typecheck": "tsc --noEmit"
|
|
99
137
|
}
|
|
100
|
-
}
|
|
138
|
+
}
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
* data shape of primitives/arrays.)
|
|
30
30
|
*/
|
|
31
31
|
import type { PreprToolbarProps } from '@preprio/toolkit';
|
|
32
|
+
import { serializeForScriptTag } from '@preprio/toolkit/json-script';
|
|
32
33
|
|
|
33
34
|
type Props = PreprToolbarProps;
|
|
34
35
|
|
|
@@ -40,7 +41,7 @@ const props = { activeSegment, activeVariant, segments: segments ?? data ?? [] }
|
|
|
40
41
|
<script
|
|
41
42
|
type="application/json"
|
|
42
43
|
data-prepr-toolbar-props
|
|
43
|
-
set:html={
|
|
44
|
+
set:html={serializeForScriptTag(props)}
|
|
44
45
|
/>
|
|
45
46
|
|
|
46
47
|
<script>
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* from '@preprio/toolkit'` would fail to resolve in the browser. See
|
|
15
15
|
* `PreprToolbar.astro` for the full explanation.
|
|
16
16
|
*/
|
|
17
|
+
import { serializeForScriptTag } from '@preprio/toolkit/json-script';
|
|
18
|
+
|
|
17
19
|
interface Props {
|
|
18
20
|
id: string;
|
|
19
21
|
config?: {
|
|
@@ -34,7 +36,7 @@ const payload = { id, config };
|
|
|
34
36
|
<script
|
|
35
37
|
type="application/json"
|
|
36
38
|
data-prepr-pixel-props
|
|
37
|
-
set:html={
|
|
39
|
+
set:html={serializeForScriptTag(payload)}
|
|
38
40
|
/>
|
|
39
41
|
|
|
40
42
|
<script>
|