nuxt-skew-protection 1.2.0 → 1.3.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/dist/module.d.mts +18 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +50 -10
- package/dist/runtime/app/plugins/check-updates-sse.client.js +4 -2
- package/dist/runtime/app/plugins/check-updates-websocket.client.js +4 -2
- package/dist/runtime/app/utils/create-skew-connection.js +3 -2
- package/dist/runtime/types.d.ts +8 -0
- package/package.json +23 -23
package/dist/module.d.mts
CHANGED
|
@@ -29,13 +29,29 @@ interface ModuleOptions {
|
|
|
29
29
|
* @default Static: 'polling', Node: 'sse', Cloudflare: 'ws'
|
|
30
30
|
*/
|
|
31
31
|
updateStrategy?: 'polling' | 'sse' | 'ws' | SkewAdapter;
|
|
32
|
+
/**
|
|
33
|
+
* Path prefix for the module's runtime endpoints (`/ws`, `/sse`, `/health`,
|
|
34
|
+
* `/route`, `/subscribe-stats`, `/admin/stats`).
|
|
35
|
+
*
|
|
36
|
+
* Defaults to `/__skew`. Set a sub-path when the app is path-routed behind a
|
|
37
|
+
* worker that only owns part of the host (e.g. a Pro dashboard mounted under
|
|
38
|
+
* `/pro/*` on a host shared with a marketing app): use `/pro/__skew` so the
|
|
39
|
+
* websocket/health requests resolve to this worker's deployment instead of
|
|
40
|
+
* leaking to the sibling app that owns the host route.
|
|
41
|
+
* @default '/__skew'
|
|
42
|
+
*/
|
|
43
|
+
basePath?: string;
|
|
32
44
|
/**
|
|
33
45
|
* Cookie configuration for storing deployment version
|
|
34
46
|
*/
|
|
35
47
|
cookie?: false | Omit<CookieSerializeOptions, 'encode'> & {
|
|
36
48
|
/**
|
|
37
|
-
* Cookie name for storing deployment version
|
|
38
|
-
*
|
|
49
|
+
* Cookie name for storing deployment version.
|
|
50
|
+
*
|
|
51
|
+
* Defaults to `__nkpv`, suffixed with the mount point for a path-routed app
|
|
52
|
+
* (e.g. `/pro/*` → `__nkpv_pro`) so apps sharing a host don't clobber each
|
|
53
|
+
* other's cookie. Set this to override the derived name.
|
|
54
|
+
* @default '__nkpv' (or `__nkpv_<mount>` when path-routed)
|
|
39
55
|
*/
|
|
40
56
|
name?: string;
|
|
41
57
|
};
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -14,6 +14,35 @@ import { join as join$1, dirname } from 'pathe';
|
|
|
14
14
|
|
|
15
15
|
const logger = useLogger("nuxt-skew-protection");
|
|
16
16
|
|
|
17
|
+
const SKEW_SEGMENT = "__skew";
|
|
18
|
+
const DEFAULT_COOKIE_NAME = "__nkpv";
|
|
19
|
+
function trimSlashes(value) {
|
|
20
|
+
return value.replace(/^\/+|\/+$/g, "");
|
|
21
|
+
}
|
|
22
|
+
function resolveBasePath(input = {}) {
|
|
23
|
+
if (input.basePath)
|
|
24
|
+
return `/${trimSlashes(input.basePath)}`;
|
|
25
|
+
const app = input.app || {};
|
|
26
|
+
const assetsDir = app.buildAssetsDir || "";
|
|
27
|
+
let mount = "";
|
|
28
|
+
if (assetsDir.startsWith("/")) {
|
|
29
|
+
const segments = trimSlashes(assetsDir).split("/").filter(Boolean);
|
|
30
|
+
mount = segments.slice(0, -1).join("/");
|
|
31
|
+
}
|
|
32
|
+
if (!mount)
|
|
33
|
+
mount = trimSlashes(app.baseURL || "");
|
|
34
|
+
return mount ? `/${mount}/${SKEW_SEGMENT}` : `/${SKEW_SEGMENT}`;
|
|
35
|
+
}
|
|
36
|
+
function resolveCookieName(explicitName, basePath) {
|
|
37
|
+
if (explicitName)
|
|
38
|
+
return explicitName;
|
|
39
|
+
const segments = trimSlashes(basePath).split("/").filter(Boolean);
|
|
40
|
+
if (segments[segments.length - 1] === SKEW_SEGMENT)
|
|
41
|
+
segments.pop();
|
|
42
|
+
const slug = segments.join("_");
|
|
43
|
+
return slug ? `${DEFAULT_COOKIE_NAME}_${slug}` : DEFAULT_COOKIE_NAME;
|
|
44
|
+
}
|
|
45
|
+
|
|
17
46
|
const cloudflareKVWranglerDriver = defineDriver((opts) => {
|
|
18
47
|
const { namespaceId, local = false, base = "" } = opts;
|
|
19
48
|
if (!namespaceId) {
|
|
@@ -725,7 +754,9 @@ const module$1 = defineNuxtModule({
|
|
|
725
754
|
maxNumberOfVersions: 10,
|
|
726
755
|
bundleAssets: true,
|
|
727
756
|
cookie: {
|
|
728
|
-
name
|
|
757
|
+
// `name` intentionally omitted — derived from the mount point in setup
|
|
758
|
+
// (`resolveCookieName`) so path-routed apps get a distinct cookie. An
|
|
759
|
+
// explicit `cookie.name` overrides it.
|
|
729
760
|
path: "/",
|
|
730
761
|
sameSite: "lax",
|
|
731
762
|
maxAge: 60 * 60 * 24 * 7
|
|
@@ -747,6 +778,14 @@ const module$1 = defineNuxtModule({
|
|
|
747
778
|
logger.debug("The module is disabled, skipping setup.");
|
|
748
779
|
return;
|
|
749
780
|
}
|
|
781
|
+
const basePathExplicit = !!options.basePath;
|
|
782
|
+
const basePath = resolveBasePath({ basePath: options.basePath, app: nuxt.options.app });
|
|
783
|
+
options.basePath = basePath;
|
|
784
|
+
logger.debug(`Endpoints mounted at ${basePath}/* (${basePathExplicit ? "explicit" : "auto-detected"})`);
|
|
785
|
+
if (options.cookie !== false) {
|
|
786
|
+
options.cookie = options.cookie || {};
|
|
787
|
+
options.cookie.name = resolveCookieName(options.cookie.name, basePath);
|
|
788
|
+
}
|
|
750
789
|
const rawOptions = nuxt.options.skewProtection || {};
|
|
751
790
|
if ("bundlePreviousDeploymentChunks" in rawOptions) {
|
|
752
791
|
logger.warn("`bundlePreviousDeploymentChunks` is deprecated, use `bundleAssets` instead. See https://nuxtseo.com/docs/skew-protection/releases/v1");
|
|
@@ -774,6 +813,7 @@ const module$1 = defineNuxtModule({
|
|
|
774
813
|
logger.warn("`ipTracking` requires `connectionTracking: true`. IP tracking will be disabled.");
|
|
775
814
|
}
|
|
776
815
|
nuxt.options.runtimeConfig.public.skewProtection = {
|
|
816
|
+
basePath,
|
|
777
817
|
cookie: options.cookie,
|
|
778
818
|
debug: options.debug,
|
|
779
819
|
connectionTracking: options.connectionTracking,
|
|
@@ -908,17 +948,17 @@ export {}
|
|
|
908
948
|
if (nuxt.options.dev && options.connectionTracking) {
|
|
909
949
|
if (nuxt.options.nitro?.experimental?.websocket) {
|
|
910
950
|
addServerHandler({
|
|
911
|
-
route:
|
|
951
|
+
route: `${basePath}/ws`,
|
|
912
952
|
handler: resolver.resolve("./runtime/server/routes/__skew/ws")
|
|
913
953
|
});
|
|
914
954
|
addServerHandler({
|
|
915
|
-
route:
|
|
955
|
+
route: `${basePath}/subscribe-stats`,
|
|
916
956
|
method: "post",
|
|
917
957
|
handler: resolver.resolve("./runtime/server/routes/__skew/subscribe-stats.post")
|
|
918
958
|
});
|
|
919
959
|
if (options.routeTracking) {
|
|
920
960
|
addServerHandler({
|
|
921
|
-
route:
|
|
961
|
+
route: `${basePath}/route`,
|
|
922
962
|
method: "post",
|
|
923
963
|
handler: resolver.resolve("./runtime/server/routes/__skew/route.post")
|
|
924
964
|
});
|
|
@@ -971,14 +1011,14 @@ export {}
|
|
|
971
1011
|
}
|
|
972
1012
|
if (!isStatic) {
|
|
973
1013
|
addServerHandler({
|
|
974
|
-
route:
|
|
1014
|
+
route: `${basePath}/health`,
|
|
975
1015
|
method: "get",
|
|
976
1016
|
handler: resolver.resolve("./runtime/server/routes/__skew/health.get")
|
|
977
1017
|
});
|
|
978
1018
|
}
|
|
979
1019
|
if (options.connectionTracking && !isStatic) {
|
|
980
1020
|
addServerHandler({
|
|
981
|
-
route:
|
|
1021
|
+
route: `${basePath}/admin/stats`,
|
|
982
1022
|
method: "get",
|
|
983
1023
|
handler: resolver.resolve("./runtime/server/routes/__skew/admin/stats.get")
|
|
984
1024
|
});
|
|
@@ -1130,7 +1170,7 @@ export { subscribe }`
|
|
|
1130
1170
|
logger.warn("Websockets are only supported in Cloudflare using `cloudflare-durable` preset. Falling back to polling.");
|
|
1131
1171
|
} else {
|
|
1132
1172
|
addServerHandler({
|
|
1133
|
-
route:
|
|
1173
|
+
route: `${basePath}/ws`,
|
|
1134
1174
|
handler: resolver.resolve("./runtime/server/routes/__skew/ws")
|
|
1135
1175
|
});
|
|
1136
1176
|
addPlugin(resolver.resolve("./runtime/app/plugins/check-updates-websocket.client"));
|
|
@@ -1140,18 +1180,18 @@ export { subscribe }`
|
|
|
1140
1180
|
logger.warn("SSE not supported on Cloudflare Workers (no persistent connections). Falling back to polling.");
|
|
1141
1181
|
} else {
|
|
1142
1182
|
addServerHandler({
|
|
1143
|
-
route:
|
|
1183
|
+
route: `${basePath}/sse`,
|
|
1144
1184
|
handler: resolver.resolve("./runtime/server/routes/__skew/sse")
|
|
1145
1185
|
});
|
|
1146
1186
|
if (options.connectionTracking) {
|
|
1147
1187
|
addServerHandler({
|
|
1148
|
-
route:
|
|
1188
|
+
route: `${basePath}/subscribe-stats`,
|
|
1149
1189
|
method: "post",
|
|
1150
1190
|
handler: resolver.resolve("./runtime/server/routes/__skew/subscribe-stats.post")
|
|
1151
1191
|
});
|
|
1152
1192
|
if (options.routeTracking) {
|
|
1153
1193
|
addServerHandler({
|
|
1154
|
-
route:
|
|
1194
|
+
route: `${basePath}/route`,
|
|
1155
1195
|
method: "post",
|
|
1156
1196
|
handler: resolver.resolve("./runtime/server/routes/__skew/route.post")
|
|
1157
1197
|
});
|
|
@@ -10,10 +10,12 @@ export default defineNuxtPlugin({
|
|
|
10
10
|
const nuxtApp = useNuxtApp();
|
|
11
11
|
const router = useRouter();
|
|
12
12
|
const runtimeConfig = useRuntimeConfig();
|
|
13
|
-
const
|
|
13
|
+
const skewConfig = runtimeConfig.public.skewProtection;
|
|
14
|
+
const routeTracking = skewConfig?.routeTracking;
|
|
15
|
+
const basePath = skewConfig?.basePath || "/__skew";
|
|
14
16
|
const initialRoute = routeTracking ? `?route=${encodeURIComponent(router.currentRoute.value.path)}` : "";
|
|
15
17
|
const config = {
|
|
16
|
-
url:
|
|
18
|
+
url: `${basePath}/sse${initialRoute}`,
|
|
17
19
|
options: {
|
|
18
20
|
autoReconnect: { retries: 10, delay: 5e3 }
|
|
19
21
|
}
|
|
@@ -11,11 +11,13 @@ export default defineNuxtPlugin({
|
|
|
11
11
|
const nuxtApp = useNuxtApp();
|
|
12
12
|
const router = useRouter();
|
|
13
13
|
const runtimeConfig = useRuntimeConfig();
|
|
14
|
-
const
|
|
14
|
+
const skewConfig = runtimeConfig.public.skewProtection;
|
|
15
|
+
const routeTracking = skewConfig?.routeTracking;
|
|
16
|
+
const basePath = skewConfig?.basePath || "/__skew";
|
|
15
17
|
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
16
18
|
const initialRoute = routeTracking ? `?route=${encodeURIComponent(router.currentRoute.value.path)}` : "";
|
|
17
19
|
const config = {
|
|
18
|
-
url: `${protocol}//${window.location.host}/
|
|
20
|
+
url: `${protocol}//${window.location.host}${basePath}/ws${initialRoute}`,
|
|
19
21
|
options: {
|
|
20
22
|
autoReconnect: { retries: 10, delay: 5e3 },
|
|
21
23
|
immediate: false
|
|
@@ -9,6 +9,7 @@ export function createSkewConnection(config) {
|
|
|
9
9
|
const buildId = runtimeConfig.app.buildId;
|
|
10
10
|
init();
|
|
11
11
|
const { isBot } = useBotDetection();
|
|
12
|
+
const basePath = runtimeConfig.public.skewProtection.basePath || "/__skew";
|
|
12
13
|
const cookieConfig = runtimeConfig.public.skewProtection.cookie;
|
|
13
14
|
const { name: cookieName, ...cookieOpts } = cookieConfig;
|
|
14
15
|
const cookie = useCookie(cookieName, { ...cookieOpts, readonly: false });
|
|
@@ -66,7 +67,7 @@ export function createSkewConnection(config) {
|
|
|
66
67
|
if (sendFn) {
|
|
67
68
|
sendFn({ type: "route-update", route });
|
|
68
69
|
} else if (connectionId) {
|
|
69
|
-
fetch(
|
|
70
|
+
fetch(`${basePath}/route`, {
|
|
70
71
|
method: "POST",
|
|
71
72
|
headers: { "Content-Type": "application/json" },
|
|
72
73
|
body: JSON.stringify({ connectionId, route })
|
|
@@ -81,7 +82,7 @@ export function createSkewConnection(config) {
|
|
|
81
82
|
if (sendFn) {
|
|
82
83
|
sendFn({ type: SKEW_MESSAGE_TYPE.SUBSCRIBE_STATS });
|
|
83
84
|
} else {
|
|
84
|
-
fetch(
|
|
85
|
+
fetch(`${basePath}/subscribe-stats`, {
|
|
85
86
|
method: "POST",
|
|
86
87
|
headers: { "Content-Type": "application/json" },
|
|
87
88
|
credentials: "same-origin",
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -2,6 +2,13 @@ import type { CookieSerializeOptions } from 'cookie-es';
|
|
|
2
2
|
export interface NuxtSkewProtectionRuntimeConfig {
|
|
3
3
|
sse: boolean;
|
|
4
4
|
durableObjects: boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Path prefix for the module's runtime endpoints (`/ws`, `/sse`, `/health`,
|
|
7
|
+
* `/route`, `/subscribe-stats`, `/admin/stats`). Defaults to `/__skew`. Set a
|
|
8
|
+
* sub-path (e.g. `/pro/__skew`) when the app is path-routed behind a worker
|
|
9
|
+
* that only owns part of the host, so the endpoints resolve to this app.
|
|
10
|
+
*/
|
|
11
|
+
basePath: string;
|
|
5
12
|
cookie: Omit<CookieSerializeOptions, 'encode'> & {
|
|
6
13
|
name?: string;
|
|
7
14
|
};
|
|
@@ -13,6 +20,7 @@ export interface NuxtSkewProtectionRuntimeConfig {
|
|
|
13
20
|
multiTab?: boolean;
|
|
14
21
|
}
|
|
15
22
|
export interface SkewProtectionRuntimeConfig {
|
|
23
|
+
basePath: string;
|
|
16
24
|
cookie: Omit<CookieSerializeOptions, 'encode'> & {
|
|
17
25
|
name: string;
|
|
18
26
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-skew-protection",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"description": "Solve Nuxt version skews with persistent assets and instant updates.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -77,12 +77,12 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@nuxt/kit": "^4.
|
|
80
|
+
"@nuxt/kit": "^4.5.0",
|
|
81
81
|
"@vueuse/core": "^14.3.0",
|
|
82
82
|
"consola": "^3.4.2",
|
|
83
83
|
"cookie-es": "^3.1.1",
|
|
84
|
-
"nuxt-site-config": "^4.1.
|
|
85
|
-
"nuxtseo-shared": "^5.2
|
|
84
|
+
"nuxt-site-config": "^4.1.1",
|
|
85
|
+
"nuxtseo-shared": "^5.3.2",
|
|
86
86
|
"pathe": "^2.0.3",
|
|
87
87
|
"pkg-types": "^2.3.1",
|
|
88
88
|
"tinyexec": "^1.2.4",
|
|
@@ -90,36 +90,36 @@
|
|
|
90
90
|
"zod": "^4.4.3"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
|
-
"@antfu/eslint-config": "^9.
|
|
94
|
-
"@arethetypeswrong/cli": "^0.18.
|
|
93
|
+
"@antfu/eslint-config": "^9.1.0",
|
|
94
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
95
95
|
"@nuxt/module-builder": "^1.0.2",
|
|
96
96
|
"@nuxt/test-utils": "^4.0.3",
|
|
97
|
-
"@nuxt/ui": "^4.
|
|
98
|
-
"@nuxtjs/robots": "^6.
|
|
97
|
+
"@nuxt/ui": "^4.10.0",
|
|
98
|
+
"@nuxtjs/robots": "^6.1.2",
|
|
99
99
|
"@types/ws": "^8.18.1",
|
|
100
|
-
"ably": "^2.
|
|
101
|
-
"better-sqlite3": "^12.
|
|
100
|
+
"ably": "^2.25.0",
|
|
101
|
+
"better-sqlite3": "^12.11.1",
|
|
102
102
|
"bumpp": "^11.1.0",
|
|
103
|
-
"eslint": "^10.
|
|
103
|
+
"eslint": "^10.7.0",
|
|
104
104
|
"eslint-plugin-harlanzw": "^0.17.0",
|
|
105
105
|
"eventsource": "^4.1.0",
|
|
106
|
-
"happy-dom": "^20.10.
|
|
106
|
+
"happy-dom": "^20.10.6",
|
|
107
107
|
"ioredis": "^5.11.1",
|
|
108
|
-
"nuxt": "^4.
|
|
108
|
+
"nuxt": "^4.5.0",
|
|
109
109
|
"nuxt-auth-utils": "^0.5.29",
|
|
110
|
-
"nuxtseo-layer-devtools": "^5.2
|
|
111
|
-
"playwright-core": "^1.
|
|
110
|
+
"nuxtseo-layer-devtools": "^5.3.2",
|
|
111
|
+
"playwright-core": "^1.61.1",
|
|
112
112
|
"pusher-js": "^8.5.0",
|
|
113
|
-
"std-env": "^4.
|
|
114
|
-
"tsx": "^4.
|
|
113
|
+
"std-env": "^4.2.0",
|
|
114
|
+
"tsx": "^4.23.1",
|
|
115
115
|
"typescript": "^6.0.3",
|
|
116
116
|
"unbuild": "^3.6.1",
|
|
117
|
-
"vitest": "^4.1.
|
|
118
|
-
"vue": "^3.5.
|
|
119
|
-
"vue-router": "^5.
|
|
120
|
-
"vue-tsc": "^3.3.
|
|
121
|
-
"wrangler": "^4.
|
|
122
|
-
"ws": "^8.21.
|
|
117
|
+
"vitest": "^4.1.10",
|
|
118
|
+
"vue": "^3.5.40",
|
|
119
|
+
"vue-router": "^5.2.0",
|
|
120
|
+
"vue-tsc": "^3.3.7",
|
|
121
|
+
"wrangler": "^4.112.0",
|
|
122
|
+
"ws": "^8.21.1"
|
|
123
123
|
},
|
|
124
124
|
"resolutions": {
|
|
125
125
|
"nuxt-skew-protection": "workspace:*",
|