nuxt-skew-protection 1.3.1 → 1.4.0

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 (48) hide show
  1. package/dist/devtools/lib/skew-protection/data.ts +4 -1
  2. package/dist/module.json +2 -2
  3. package/dist/module.mjs +46 -49
  4. package/dist/runtime/app/composables/useSkewProtection.d.ts +1 -1
  5. package/dist/runtime/app/plugins/check-updates-adapter.client.d.ts +2 -2
  6. package/dist/runtime/app/plugins/check-updates-sse.client.d.ts +2 -2
  7. package/dist/runtime/app/plugins/check-updates-sse.client.js +3 -6
  8. package/dist/runtime/app/plugins/check-updates-websocket.client.d.ts +2 -2
  9. package/dist/runtime/app/plugins/check-updates-websocket.client.js +3 -6
  10. package/dist/runtime/app/utils/create-skew-connection.d.ts +1 -10
  11. package/dist/runtime/app/utils/route-tracking.d.ts +20 -0
  12. package/dist/runtime/app/utils/route-tracking.js +8 -0
  13. package/dist/runtime/server/imports/cookie.d.ts +4 -4
  14. package/dist/runtime/server/imports/cookie.js +1 -1
  15. package/dist/runtime/server/imports/getRuntimeConfigSkewProtection.d.ts +5 -2
  16. package/dist/runtime/server/imports/getRuntimeConfigSkewProtection.js +1 -1
  17. package/dist/runtime/server/imports/utils.d.ts +3 -3
  18. package/dist/runtime/server/imports/utils.js +1 -1
  19. package/dist/runtime/server/middleware/set-skew-protection-cookie.d.ts +1 -1
  20. package/dist/runtime/server/middleware/set-skew-protection-cookie.js +2 -2
  21. package/dist/runtime/server/middleware/vercel-skew.d.ts +1 -1
  22. package/dist/runtime/server/middleware/vercel-skew.js +1 -1
  23. package/dist/runtime/server/plugins/connection-tracking-cloudflare-durable.d.ts +1 -1
  24. package/dist/runtime/server/plugins/connection-tracking-cloudflare-durable.js +1 -1
  25. package/dist/runtime/server/plugins/connection-tracking.d.ts +1 -1
  26. package/dist/runtime/server/plugins/connection-tracking.js +1 -1
  27. package/dist/runtime/server/routes/__skew/admin/stats.get.d.ts +1 -1
  28. package/dist/runtime/server/routes/__skew/admin/stats.get.js +2 -2
  29. package/dist/runtime/server/routes/__skew/health.get.d.ts +1 -5
  30. package/dist/runtime/server/routes/__skew/health.get.js +2 -2
  31. package/dist/runtime/server/routes/__skew/route.post.d.ts +1 -3
  32. package/dist/runtime/server/routes/__skew/route.post.js +2 -2
  33. package/dist/runtime/server/routes/__skew/sse.d.ts +1 -1
  34. package/dist/runtime/server/routes/__skew/sse.js +2 -2
  35. package/dist/runtime/server/routes/__skew/subscribe-stats.post.d.ts +1 -3
  36. package/dist/runtime/server/routes/__skew/subscribe-stats.post.js +2 -2
  37. package/dist/runtime/server/routes/__skew/ws.d.ts +1 -1
  38. package/dist/runtime/server/routes/__skew/ws.js +2 -2
  39. package/dist/runtime/server/routes/__skew-devtools/debug-production.get.d.ts +1 -15
  40. package/dist/runtime/server/routes/__skew-devtools/debug-production.get.js +1 -1
  41. package/dist/runtime/server/routes/__skew-devtools/debug.get.d.ts +1 -14
  42. package/dist/runtime/server/routes/__skew-devtools/debug.get.js +2 -2
  43. package/dist/runtime/shared/logger.d.ts +2 -1
  44. package/dist/runtime/shared/logger.js +2 -6
  45. package/dist/runtime/types.d.ts +0 -2
  46. package/package.json +28 -26
  47. package/dist/runtime/adapters/logger.d.ts +0 -1
  48. package/dist/runtime/adapters/logger.js +0 -6
@@ -9,7 +9,10 @@ export const productionError = ref<string | null>(null)
9
9
  const { data: debugData, status: debugStatus } = useAsyncData<DebugResponse | null>('debug', () => {
10
10
  if (!appFetch.value)
11
11
  return Promise.resolve(null)
12
- return appFetch.value<DebugResponse>('/__skew-devtools/debug').catch(() => null)
12
+ return appFetch.value<DebugResponse>('/__skew-devtools/debug').catch(() => {
13
+ // The devtools panel may load before its debug endpoint is available.
14
+ return null
15
+ })
13
16
  }, { watch: [refreshTime] })
14
17
 
15
18
  export { debugData }
package/dist/module.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "nuxt": ">=4.0.0"
5
5
  },
6
6
  "configKey": "skewProtection",
7
- "version": "1.3.1",
7
+ "version": "1.4.0",
8
8
  "builder": {
9
- "@nuxt/module-builder": "1.0.2",
9
+ "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
11
11
  }
12
12
  }
package/dist/module.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { writeFileSync, unlinkSync, existsSync, readFileSync, promises } from 'node:fs';
2
2
  import { useLogger, useNuxt, defineNuxtModule, createResolver, hasNuxtModule, addTypeTemplate, addComponent, addImports, addServerHandler, addPlugin, tryResolveModule, addTemplate } from '@nuxt/kit';
3
3
  import { colors } from 'consola/utils';
4
+ import { setupNitroRuntimeCompatibility, resolveNitroPreset, renderNitroTypeAugmentations, isNuxtGenerate } from 'nuxtseo-shared/kit';
4
5
  import { readPackageJSON } from 'pkg-types';
5
- import { resolveNitroPreset, isNuxtGenerate } from 'nuxtseo-shared/kit';
6
6
  import { join } from 'node:path';
7
7
  import { tmpdir } from 'node:os';
8
8
  import { x } from 'tinyexec';
@@ -27,7 +27,9 @@ function resolveBasePath(input = {}) {
27
27
  let mount = "";
28
28
  if (assetsDir.startsWith("/")) {
29
29
  const segments = trimSlashes(assetsDir).split("/").filter(Boolean);
30
- mount = segments.slice(0, -1).join("/");
30
+ const nuxtAssetsIndex = segments.indexOf("_nuxt");
31
+ const mountEnd = nuxtAssetsIndex === -1 ? segments.length - 1 : nuxtAssetsIndex;
32
+ mount = segments.slice(0, mountEnd).join("/");
31
33
  }
32
34
  if (!mount)
33
35
  mount = trimSlashes(app.baseURL || "");
@@ -288,21 +290,35 @@ function formatDuration(ms) {
288
290
  return `${ms}ms`;
289
291
  return `${(ms / 1e3).toFixed(2)}s`;
290
292
  }
293
+ function formatAge(timestamp, now) {
294
+ const ageMinutes = Math.floor((now - timestamp) / 6e4);
295
+ const ageHours = Math.floor(ageMinutes / 60);
296
+ const ageDays = Math.floor(ageHours / 24);
297
+ if (ageDays > 0)
298
+ return `${ageDays}d ago`;
299
+ if (ageHours > 0)
300
+ return `${ageHours}h ago`;
301
+ if (ageMinutes > 0)
302
+ return `${ageMinutes}m ago`;
303
+ return "just now";
304
+ }
291
305
  function createAssetManager(options) {
292
306
  const storage = createStorage({
293
307
  driver: options.driver
294
308
  });
295
309
  const retentionDays = options.retentionDays || 7;
296
310
  const maxNumberOfVersions = options.maxNumberOfVersions || 20;
311
+ const buildAssetsDir = (options.buildAssetsDir || "/_nuxt/").replace(/^\/+|\/+$/g, "");
312
+ const buildAssetsPath = `/${buildAssetsDir}`;
297
313
  async function getAssetsFromBuild(publicDir) {
298
314
  const startTime = Date.now();
299
- const nuxtDir = join$1(publicDir, "_nuxt");
315
+ const nuxtDir = join$1(publicDir, buildAssetsDir);
300
316
  logger.debug(`Scanning build assets from ${nuxtDir}`);
301
317
  const assets = [];
302
318
  const nuxtFiles = await getFilesRecursively(nuxtDir);
303
319
  for (const file of nuxtFiles) {
304
320
  const relativePath = file.replace(nuxtDir, "");
305
- assets.push(`_nuxt${relativePath}`);
321
+ assets.push(`${buildAssetsDir}${relativePath}`);
306
322
  }
307
323
  logger.debug(`Found ${assets.length} assets in ${formatDuration(Date.now() - startTime)}`);
308
324
  return assets;
@@ -563,25 +579,11 @@ function createAssetManager(options) {
563
579
  await promises.writeFile(targetPath, dataToWrite, { flag: "wx" });
564
580
  totalBytes += dataToWrite.byteLength;
565
581
  const versionTimestamp = new Date(versionData.timestamp).getTime();
566
- const ageMs = now - versionTimestamp;
567
- const ageMinutes = Math.floor(ageMs / 6e4);
568
- const ageHours = Math.floor(ageMinutes / 60);
569
- const ageDays = Math.floor(ageHours / 24);
570
- let ageStr;
571
- if (ageDays > 0) {
572
- ageStr = `${ageDays}d ago`;
573
- } else if (ageHours > 0) {
574
- ageStr = `${ageHours}h ago`;
575
- } else if (ageMinutes > 0) {
576
- ageStr = `${ageMinutes}m ago`;
577
- } else {
578
- ageStr = "just now";
579
- }
580
582
  return {
581
583
  asset,
582
584
  size: dataToWrite.byteLength,
583
585
  versionId,
584
- age: ageStr
586
+ age: formatAge(versionTimestamp, now)
585
587
  };
586
588
  }
587
589
  return null;
@@ -605,11 +607,7 @@ function createAssetManager(options) {
605
607
  const isLast = index === otherVersions.length - 1;
606
608
  const prefix = isLast ? " \u2514\u2500" : " \u251C\u2500";
607
609
  const versionTimestamp = new Date(versionData.timestamp).getTime();
608
- const ageMs = now - versionTimestamp;
609
- const ageMinutes = Math.floor(ageMs / 6e4);
610
- const ageHours = Math.floor(ageMinutes / 60);
611
- const ageDays = Math.floor(ageHours / 24);
612
- const ageStr = ageDays > 0 ? `${ageDays}d ago` : ageHours > 0 ? `${ageHours}h ago` : ageMinutes > 0 ? `${ageMinutes}m ago` : "just now";
610
+ const ageStr = formatAge(versionTimestamp, now);
613
611
  const restored = restoredByVersion.get(versionId) || 0;
614
612
  const total = versionData.originalAssets?.length || versionData.assets.length;
615
613
  logger.log(colors.gray(`${prefix} ${versionId.slice(0, 8)} (${restored}/${total} files restored, ${ageStr})`));
@@ -619,7 +617,7 @@ function createAssetManager(options) {
619
617
  }
620
618
  async function augmentBuildMetadata(buildId, publicDir, serverDir) {
621
619
  const manifest = await getVersionManifest(storage);
622
- const latestPath = join$1(publicDir, "_nuxt", "builds", "latest.json");
620
+ const latestPath = join$1(publicDir, buildAssetsDir, "builds", "latest.json");
623
621
  let newLatestContent;
624
622
  try {
625
623
  const latestData = await promises.readFile(latestPath, "utf-8");
@@ -641,7 +639,7 @@ function createAssetManager(options) {
641
639
  logger.warn("Failed to augment builds/latest.json:", error);
642
640
  }
643
641
  }
644
- const metaPath = join$1(publicDir, "_nuxt", "builds", "meta", `${buildId}.json`);
642
+ const metaPath = join$1(publicDir, buildAssetsDir, "builds", "meta", `${buildId}.json`);
645
643
  try {
646
644
  const metaData = await promises.readFile(metaPath, "utf-8");
647
645
  const metaJson = JSON.parse(metaData);
@@ -659,12 +657,14 @@ function createAssetManager(options) {
659
657
  }
660
658
  }
661
659
  if (serverDir && newLatestContent) {
662
- await patchNitroManifest(serverDir, "/_nuxt/builds/latest.json", newLatestContent);
660
+ await patchNitroManifest(serverDir, `${buildAssetsPath}/builds/latest.json`, newLatestContent);
663
661
  }
664
662
  }
665
663
  async function patchNitroManifest(serverDir, assetPath, newContent) {
666
664
  const nitroPath = join$1(serverDir, "chunks", "nitro", "nitro.mjs");
667
- let nitro = await promises.readFile(nitroPath, "utf-8").catch(() => null);
665
+ let nitro = await promises.readFile(nitroPath, "utf-8").catch(() => {
666
+ return null;
667
+ });
668
668
  if (!nitro)
669
669
  return;
670
670
  const assetIdx = nitro.indexOf(`"${assetPath}":`);
@@ -778,6 +778,7 @@ const module$1 = defineNuxtModule({
778
778
  logger.debug("The module is disabled, skipping setup.");
779
779
  return;
780
780
  }
781
+ const nitroCompatibility = setupNitroRuntimeCompatibility(nuxt);
781
782
  const basePathExplicit = !!options.basePath;
782
783
  const basePath = resolveBasePath({ basePath: options.basePath, app: nuxt.options.app });
783
784
  options.basePath = basePath;
@@ -888,19 +889,11 @@ export type { ChunksOutdatedPayload, SkewAdapterConfig, SkewConnection, SkewSSEC
888
889
  }, { nuxt: true });
889
890
  addTypeTemplate({
890
891
  filename: "types/nuxt-skew-protection-nitro.d.ts",
891
- getContents: () => `// Generated by nuxt-skew-protection
892
- import type { H3Event } from 'h3'
893
-
894
- declare module 'h3' {
895
- interface H3EventContext {
896
- /** Client's deployment version from skew protection cookie */
897
- skewVersion?: string
898
- }
899
- }
900
-
901
- declare module 'nitropack/types' {
902
- interface NitroRuntimeHooks {
903
- 'skew:connection:open': (payload: {
892
+ getContents: () => {
893
+ const nitroTypes = renderNitroTypeAugmentations(nitroCompatibility, {
894
+ eventContext: `/** Client's deployment version from skew protection cookie */
895
+ skewVersion?: string`,
896
+ runtimeHooks: `'skew:connection:open': (payload: {
904
897
  id: string
905
898
  version: string
906
899
  route?: string
@@ -909,16 +902,19 @@ declare module 'nitropack/types' {
909
902
  }) => void
910
903
  'skew:connection:route-update': (payload: { id: string, route: string }) => void
911
904
  'skew:connection:close': (payload: { id: string }) => void
912
- // event is H3Event for SSE (via POST), { headers } for WebSocket (no H3Event available)
913
- 'skew:subscribe-stats': (payload: { id: string, event?: H3Event | { headers?: Headers } }) => void
914
- // event is H3Event for SSE (via POST), { headers } for WebSocket (no H3Event available)
915
- 'skew:authorize-stats': (payload: { event?: H3Event | { headers?: Headers }, authorize: () => void }) => void
916
- 'skew:stats': (callback: (stats: { total: number, versions: Record<string, number>, routes: Record<string, number> }) => void) => void
917
- }
918
- }
905
+ /** event is an HTTP event for SSE, or headers for WebSocket connections. */
906
+ 'skew:subscribe-stats': (payload: { id: string, event?: ${nitroCompatibility.eventType} | { headers?: Headers } }) => void
907
+ /** event is an HTTP event for SSE, or headers for WebSocket connections. */
908
+ 'skew:authorize-stats': (payload: { event?: ${nitroCompatibility.eventType} | { headers?: Headers }, authorize: () => void }) => void
909
+ 'skew:stats': (callback: (stats: { total: number, versions: Record<string, number>, routes: Record<string, number> }) => void) => void`
910
+ });
911
+ return `// Generated by nuxt-skew-protection
912
+
913
+ ${nitroTypes}
919
914
 
920
915
  export {}
921
- `
916
+ `;
917
+ }
922
918
  }, { nitro: true });
923
919
  addComponent({
924
920
  name: "SkewNotification",
@@ -1052,6 +1048,7 @@ export {}
1052
1048
  const publicDir = nitro.options.output.publicDir;
1053
1049
  assetManager = createAssetManager({
1054
1050
  ...options,
1051
+ buildAssetsDir: nuxt.options.app.buildAssetsDir,
1055
1052
  driver: await resolveBuildTimeDriver(options.storage)
1056
1053
  });
1057
1054
  const assets = await assetManager.getAssetsFromBuild(publicDir);
@@ -14,7 +14,7 @@ export declare function useSkewProtection(options?: UseSkewProtectionOptions): {
14
14
  clientVersion: any;
15
15
  serverVersion: import("vue").ComputedRef<string | undefined>;
16
16
  isConnected: import("vue").ComputedRef<boolean>;
17
- isOnline: Readonly<import("vue").ShallowRef<boolean>>;
17
+ isOnline: Readonly<import("vue").ShallowRef<boolean, boolean>>;
18
18
  isAppOutdated: import("vue").ComputedRef<boolean>;
19
19
  isRollback: import("vue").ComputedRef<boolean>;
20
20
  connect: () => void;
@@ -1,8 +1,8 @@
1
1
  import type { SkewAdapterConfig } from '../types.js';
2
2
  export type { SkewAdapterConfig };
3
3
  declare const _default: import("nuxt/app").Plugin<{
4
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
4
+ skewConnection: import("../types.js").SkewConnection;
5
5
  }> & import("nuxt/app").ObjectPlugin<{
6
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
6
+ skewConnection: import("../types.js").SkewConnection;
7
7
  }>;
8
8
  export default _default;
@@ -1,8 +1,8 @@
1
1
  import type { SkewSSEConfig } from '../types.js';
2
2
  export type { SkewSSEConfig };
3
3
  declare const _default: import("nuxt/app").Plugin<{
4
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
4
+ skewConnection: import("../types.js").SkewConnection;
5
5
  }> & import("nuxt/app").ObjectPlugin<{
6
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
6
+ skewConnection: import("../types.js").SkewConnection;
7
7
  }>;
8
8
  export default _default;
@@ -2,6 +2,7 @@ import { useEventSource } from "@vueuse/core";
2
2
  import { defineNuxtPlugin, useNuxtApp, useRouter, useRuntimeConfig } from "nuxt/app";
3
3
  import { watch } from "vue";
4
4
  import { createSkewConnection } from "../utils/create-skew-connection.js";
5
+ import { resolveInitialRouteQuery, trackRouteChanges } from "../utils/route-tracking.js";
5
6
  export default defineNuxtPlugin({
6
7
  name: "skew-protection:sse-updates",
7
8
  async setup() {
@@ -13,7 +14,7 @@ export default defineNuxtPlugin({
13
14
  const skewConfig = runtimeConfig.public.skewProtection;
14
15
  const routeTracking = skewConfig?.routeTracking;
15
16
  const basePath = skewConfig?.basePath || "/__skew";
16
- const initialRoute = routeTracking ? `?route=${encodeURIComponent(router.currentRoute.value.path)}` : "";
17
+ const initialRoute = resolveInitialRouteQuery(routeTracking, router);
17
18
  const config = {
18
19
  url: `${basePath}/sse${initialRoute}`,
19
20
  options: {
@@ -33,11 +34,7 @@ export default defineNuxtPlugin({
33
34
  return { cleanup: sse.close };
34
35
  }
35
36
  });
36
- if (routeTracking) {
37
- router.afterEach((to) => {
38
- skewConnection.sendRoute(to.path);
39
- });
40
- }
37
+ trackRouteChanges(router, routeTracking, skewConnection);
41
38
  return { provide: { skewConnection } };
42
39
  }
43
40
  });
@@ -1,8 +1,8 @@
1
1
  import type { SkewWebSocketConfig } from '../types.js';
2
2
  export type { SkewWebSocketConfig };
3
3
  declare const _default: import("nuxt/app").Plugin<{
4
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
4
+ skewConnection: import("../types.js").SkewConnection;
5
5
  }> & import("nuxt/app").ObjectPlugin<{
6
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
6
+ skewConnection: import("../types.js").SkewConnection;
7
7
  }>;
8
8
  export default _default;
@@ -3,6 +3,7 @@ import { defineNuxtPlugin, useNuxtApp, useRouter, useRuntimeConfig } from "nuxt/
3
3
  import { watch } from "vue";
4
4
  import { SKEW_MESSAGE_TYPE } from "../../const.js";
5
5
  import { createSkewConnection } from "../utils/create-skew-connection.js";
6
+ import { resolveInitialRouteQuery, trackRouteChanges } from "../utils/route-tracking.js";
6
7
  export default defineNuxtPlugin({
7
8
  name: "skew-protection:ws-updates",
8
9
  async setup() {
@@ -15,7 +16,7 @@ export default defineNuxtPlugin({
15
16
  const routeTracking = skewConfig?.routeTracking;
16
17
  const basePath = skewConfig?.basePath || "/__skew";
17
18
  const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
18
- const initialRoute = routeTracking ? `?route=${encodeURIComponent(router.currentRoute.value.path)}` : "";
19
+ const initialRoute = resolveInitialRouteQuery(routeTracking, router);
19
20
  const config = {
20
21
  url: `${protocol}//${window.location.host}${basePath}/ws${initialRoute}`,
21
22
  options: {
@@ -45,11 +46,7 @@ export default defineNuxtPlugin({
45
46
  };
46
47
  }
47
48
  });
48
- if (routeTracking) {
49
- router.afterEach((to) => {
50
- skewConnection.sendRoute(to.path);
51
- });
52
- }
49
+ trackRouteChanges(router, routeTracking, skewConnection);
53
50
  return { provide: { skewConnection } };
54
51
  }
55
52
  });
@@ -1,4 +1,4 @@
1
- import type { Ref } from 'vue';
1
+ import type { SkewConnection } from '../types.js';
2
2
  export interface SkewMessage {
3
3
  type: string;
4
4
  version?: string;
@@ -12,13 +12,4 @@ export interface CreateSkewConnectionConfig {
12
12
  send?: (data: unknown) => void;
13
13
  } | (() => void) | void;
14
14
  }
15
- export interface SkewConnection {
16
- connect: () => void;
17
- disconnect: () => void;
18
- send: (data: unknown) => void;
19
- sendRoute: (route: string) => void;
20
- subscribeStats: () => void;
21
- buildId: string;
22
- cookie: Ref<string | null | undefined>;
23
- }
24
15
  export declare function createSkewConnection(config: CreateSkewConnectionConfig): SkewConnection;
@@ -0,0 +1,20 @@
1
+ import type { SkewConnection } from '../types.js';
2
+ export interface RouteTrackingRouter {
3
+ currentRoute: {
4
+ value: {
5
+ path: string;
6
+ };
7
+ };
8
+ afterEach: (guard: (to: {
9
+ path: string;
10
+ }) => void) => void;
11
+ }
12
+ /**
13
+ * Build the `?route=` query param appended to the initial SSE/WS connection URL
14
+ * so the server knows the client's starting route when route tracking is on.
15
+ */
16
+ export declare function resolveInitialRouteQuery(routeTracking: boolean | undefined, router: RouteTrackingRouter): string;
17
+ /**
18
+ * Send route updates to the server on client-side navigation when route tracking is on.
19
+ */
20
+ export declare function trackRouteChanges(router: RouteTrackingRouter, routeTracking: boolean | undefined, skewConnection: SkewConnection): void;
@@ -0,0 +1,8 @@
1
+ export function resolveInitialRouteQuery(routeTracking, router) {
2
+ return routeTracking ? `?route=${encodeURIComponent(router.currentRoute.value.path)}` : "";
3
+ }
4
+ export function trackRouteChanges(router, routeTracking, skewConnection) {
5
+ if (!routeTracking)
6
+ return;
7
+ router.afterEach((to) => skewConnection.sendRoute(to.path));
8
+ }
@@ -1,11 +1,11 @@
1
- import type { H3Event } from 'h3';
1
+ import type { SkewProtectionEvent } from './getRuntimeConfigSkewProtection.js';
2
2
  /**
3
3
  * Get the skew protection version cookie name from runtime config
4
4
  *
5
5
  * @param event - H3 event (optional, for better type safety)
6
6
  * @returns The configured cookie name
7
7
  */
8
- export declare function getSkewProtectionCookieName(event?: H3Event): string;
8
+ export declare function getSkewProtectionCookieName(event?: SkewProtectionEvent): string;
9
9
  /**
10
10
  * Get the skew protection version cookie value
11
11
  *
@@ -20,7 +20,7 @@ export declare function getSkewProtectionCookieName(event?: H3Event): string;
20
20
  * })
21
21
  * ```
22
22
  */
23
- export declare function getSkewProtectionCookie(event: H3Event): string | undefined;
23
+ export declare function getSkewProtectionCookie(event: SkewProtectionEvent): string | undefined;
24
24
  /**
25
25
  * Set the skew protection version cookie
26
26
  *
@@ -34,4 +34,4 @@ export declare function getSkewProtectionCookie(event: H3Event): string | undefi
34
34
  * })
35
35
  * ```
36
36
  */
37
- export declare function setSkewProtectionCookie(event: H3Event, value: string): void;
37
+ export declare function setSkewProtectionCookie(event: SkewProtectionEvent, value: string): void;
@@ -1,4 +1,4 @@
1
- import { getCookie, setCookie } from "h3";
1
+ import { getCookie, setCookie } from "#nuxtseo/h3";
2
2
  import { getRuntimeConfigSkewProtection } from "./getRuntimeConfigSkewProtection.js";
3
3
  export function getSkewProtectionCookieName(event) {
4
4
  const { cookie } = getRuntimeConfigSkewProtection(event);
@@ -1,7 +1,10 @@
1
- import type { H3Event } from 'h3';
2
1
  import type { SkewProtectionRuntimeConfig } from '../../types.js';
2
+ /** Event surface shared by Nitro 2 and Nitro 3 request handlers. */
3
+ export interface SkewProtectionEvent {
4
+ context: object;
5
+ }
3
6
  /**
4
7
  * Get skew protection runtime config with proper types
5
8
  * Ensures cookie config is always defined with required properties
6
9
  */
7
- export declare function getRuntimeConfigSkewProtection(event?: H3Event): SkewProtectionRuntimeConfig;
10
+ export declare function getRuntimeConfigSkewProtection(event?: SkewProtectionEvent): SkewProtectionRuntimeConfig;
@@ -1,4 +1,4 @@
1
- import { useRuntimeConfig } from "nitropack/runtime";
1
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
2
2
  export function getRuntimeConfigSkewProtection(event) {
3
3
  const config = useRuntimeConfig(event);
4
4
  return config.public.skewProtection;
@@ -1,10 +1,10 @@
1
- import type { H3Event } from 'h3';
1
+ import type { SkewProtectionEvent } from './getRuntimeConfigSkewProtection.js';
2
2
  /**
3
3
  * Get the client's deployment version from the skew protection cookie.
4
4
  * Returns undefined if no cookie is set.
5
5
  */
6
- export declare function getClientVersion(event: H3Event): string | undefined;
6
+ export declare function getClientVersion(event: SkewProtectionEvent): string | undefined;
7
7
  /**
8
8
  * Check if the client is outdated based on cookie version vs current build ID
9
9
  */
10
- export declare function isClientOutdated(event: H3Event): boolean;
10
+ export declare function isClientOutdated(event: SkewProtectionEvent): boolean;
@@ -1,4 +1,4 @@
1
- import { useRuntimeConfig } from "nitropack/runtime";
1
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
2
2
  import { getSkewProtectionCookie } from "./cookie.js";
3
3
  export function getClientVersion(event) {
4
4
  return getSkewProtectionCookie(event);
@@ -3,5 +3,5 @@
3
3
  * 1. Sets event.context.skewVersion on all requests (from cookie)
4
4
  * 2. Sets the skew-version cookie on document requests (HTML pages)
5
5
  */
6
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
6
+ declare const _default: any;
7
7
  export default _default;
@@ -1,5 +1,5 @@
1
- import { defineEventHandler, getHeader } from "h3";
2
- import { useRuntimeConfig } from "nitropack/runtime";
1
+ import { defineEventHandler, getHeader } from "#nuxtseo/h3";
2
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  import { getSkewProtectionCookie, setSkewProtectionCookie } from "../imports/cookie.js";
4
4
  export default defineEventHandler(async (event) => {
5
5
  const clientVersion = getSkewProtectionCookie(event);
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
1
+ declare const _default: any;
2
2
  export default _default;
@@ -1,4 +1,4 @@
1
- import { defineEventHandler, getHeader, setCookie } from "h3";
1
+ import { defineEventHandler, getHeader, setCookie } from "#nuxtseo/h3";
2
2
  export default defineEventHandler(async (event) => {
3
3
  const secFetchDest = getHeader(event, "sec-fetch-dest");
4
4
  if (secFetchDest !== "document") {
@@ -1,2 +1,2 @@
1
- declare const _default: import("nitropack/types").NitroAppPlugin;
1
+ declare const _default: any;
2
2
  export default _default;
@@ -1,4 +1,4 @@
1
- import { defineNitroPlugin } from "nitropack/runtime";
1
+ import { defineNitroPlugin } from "#nuxtseo/nitro";
2
2
  function getCtx(peer) {
3
3
  return peer?._internal?.durable?.ctx || null;
4
4
  }
@@ -1,2 +1,2 @@
1
- declare const _default: import("nitropack/types").NitroAppPlugin;
1
+ declare const _default: any;
2
2
  export default _default;
@@ -1,4 +1,4 @@
1
- import { defineNitroPlugin } from "nitropack/runtime";
1
+ import { defineNitroPlugin } from "#nuxtseo/nitro";
2
2
  export default defineNitroPlugin((nitroApp) => {
3
3
  const connections = /* @__PURE__ */ new Map();
4
4
  const statsSubscribers = /* @__PURE__ */ new Set();
@@ -2,5 +2,5 @@
2
2
  * Admin endpoint for nuxtseo.com dashboard to query live connection stats.
3
3
  * Requires Authorization header with SEO Pro key.
4
4
  */
5
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<unknown>>;
5
+ declare const _default: any;
6
6
  export default _default;
@@ -1,5 +1,5 @@
1
- import { createError, defineEventHandler, getHeader } from "h3";
2
- import { useNitroApp, useRuntimeConfig } from "nitropack/runtime";
1
+ import { createError, defineEventHandler, getHeader } from "#nuxtseo/h3";
2
+ import { useNitroApp, useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  export default defineEventHandler(async (event) => {
4
4
  const config = useRuntimeConfig(event);
5
5
  const seoProKey = config.seoProKey || process.env.NUXT_SEO_PRO_KEY;
@@ -2,9 +2,5 @@
2
2
  * Health check endpoint returning current deployment version.
3
3
  * Useful for monitoring and load balancers.
4
4
  */
5
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, {
6
- ok: boolean;
7
- version: any;
8
- uptime: number;
9
- }>;
5
+ declare const _default: any;
10
6
  export default _default;
@@ -1,5 +1,5 @@
1
- import { defineEventHandler } from "h3";
2
- import { useRuntimeConfig } from "nitropack/runtime";
1
+ import { defineEventHandler } from "#nuxtseo/h3";
2
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  export default defineEventHandler((event) => {
4
4
  const config = useRuntimeConfig(event);
5
5
  return {
@@ -1,4 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- ok: boolean;
3
- }>>;
1
+ declare const _default: any;
4
2
  export default _default;
@@ -1,5 +1,5 @@
1
- import { defineEventHandler, readBody } from "h3";
2
- import { useNitroApp } from "nitropack/runtime";
1
+ import { defineEventHandler, readBody } from "#nuxtseo/h3";
2
+ import { useNitroApp } from "#nuxtseo/nitro";
3
3
  export default defineEventHandler(async (event) => {
4
4
  const body = await readBody(event);
5
5
  if (!body?.connectionId || !body?.route) {
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
1
+ declare const _default: any;
2
2
  export default _default;
@@ -1,5 +1,5 @@
1
- import { createEventStream, defineEventHandler, getQuery, getRequestIP } from "h3";
2
- import { useNitroApp, useRuntimeConfig } from "nitropack/runtime";
1
+ import { createEventStream, defineEventHandler, getQuery, getRequestIP } from "#nuxtseo/h3";
2
+ import { useNitroApp, useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  import { SKEW_MESSAGE_TYPE } from "../../../const.js";
4
4
  import { getSkewProtectionCookie } from "../../imports/cookie.js";
5
5
  export default defineEventHandler(async (event) => {
@@ -2,7 +2,5 @@
2
2
  * POST endpoint for SSE connections to request stats subscription.
3
3
  * Since SSE is unidirectional, clients POST here to subscribe.
4
4
  */
5
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
6
- ok: boolean;
7
- }>>;
5
+ declare const _default: any;
8
6
  export default _default;
@@ -1,5 +1,5 @@
1
- import { createError, defineEventHandler, readBody } from "h3";
2
- import { useNitroApp } from "nitropack/runtime";
1
+ import { createError, defineEventHandler, readBody } from "#nuxtseo/h3";
2
+ import { useNitroApp } from "#nuxtseo/nitro";
3
3
  export default defineEventHandler(async (event) => {
4
4
  const body = await readBody(event);
5
5
  if (!body.connectionId) {
@@ -1,2 +1,2 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, never>;
1
+ declare const _default: any;
2
2
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import { parse as parseCookie } from "cookie-es";
2
- import { defineWebSocketHandler } from "h3";
3
- import { useNitroApp, useRuntimeConfig } from "nitropack/runtime";
2
+ import { defineWebSocketHandler } from "#nuxtseo/h3";
3
+ import { useNitroApp, useRuntimeConfig } from "#nuxtseo/nitro";
4
4
  import { SKEW_MESSAGE_TYPE } from "../../../const.js";
5
5
  import { getSkewProtectionCookieName } from "../../imports/cookie.js";
6
6
  export default defineWebSocketHandler({
@@ -1,20 +1,6 @@
1
- interface ProductionDebugResponse {
2
- health?: {
3
- ok: boolean;
4
- version: string;
5
- uptime: number;
6
- } | null;
7
- manifest?: Record<string, unknown> | null;
8
- stats?: {
9
- total: number;
10
- versions: Record<string, number>;
11
- routes: Record<string, number>;
12
- } | null;
13
- errors: string[];
14
- }
15
1
  /**
16
2
  * Proxy endpoint that fetches debug data from a production site.
17
3
  * Avoids CORS issues by proxying through the dev server.
18
4
  */
19
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<ProductionDebugResponse>>;
5
+ declare const _default: any;
20
6
  export default _default;
@@ -1,5 +1,5 @@
1
- import { defineEventHandler, getQuery } from "h3";
2
1
  import { $fetch } from "ofetch";
2
+ import { defineEventHandler, getQuery } from "#nuxtseo/h3";
3
3
  const RE_TRAILING_SLASHES = /\/+$/;
4
4
  export default defineEventHandler(async (event) => {
5
5
  const { url } = getQuery(event);
@@ -1,18 +1,5 @@
1
1
  /**
2
2
  * Devtools debug endpoint returning module configuration and resolved state.
3
3
  */
4
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, {
5
- version: {};
6
- siteConfigUrl: string;
7
- config: {
8
- cookie: unknown;
9
- debug: unknown;
10
- connectionTracking: unknown;
11
- routeTracking: unknown;
12
- ipTracking: unknown;
13
- reloadStrategy: unknown;
14
- multiTab: unknown;
15
- };
16
- buildId: any;
17
- }>;
4
+ declare const _default: any;
18
5
  export default _default;
@@ -1,5 +1,5 @@
1
- import { defineEventHandler } from "h3";
2
- import { useRuntimeConfig } from "nitropack/runtime";
1
+ import { defineEventHandler } from "#nuxtseo/h3";
2
+ import { useRuntimeConfig } from "#nuxtseo/nitro";
3
3
  import { getSiteConfig } from "#site-config/server/composables";
4
4
  export default defineEventHandler((event) => {
5
5
  const config = useRuntimeConfig(event);
@@ -1,4 +1,5 @@
1
- export declare const logger: import("consola").ConsolaInstance;
1
+ import type { ConsolaInstance } from 'consola';
2
+ export declare const logger: ConsolaInstance;
2
3
  /**
3
4
  * Initialize logger with runtime config
4
5
  */
@@ -1,10 +1,6 @@
1
- import { createConsola } from "consola";
2
1
  import { useRuntimeConfig } from "nuxt/app";
3
- export const logger = createConsola({
4
- defaults: {
5
- tag: "nuxt-skew-protection"
6
- }
7
- });
2
+ import { createModuleLogger } from "nuxtseo-shared/utils";
3
+ export const logger = createModuleLogger("nuxt-skew-protection");
8
4
  export function init() {
9
5
  const config = useRuntimeConfig();
10
6
  logger.level = config.public.skewProtection.debug ? 4 : 3;
@@ -1,7 +1,5 @@
1
1
  import type { CookieSerializeOptions } from 'cookie-es';
2
2
  export interface NuxtSkewProtectionRuntimeConfig {
3
- sse: boolean;
4
- durableObjects: boolean;
5
3
  /**
6
4
  * Path prefix for the module's runtime endpoints (`/ws`, `/sse`, `/health`,
7
5
  * `/route`, `/subscribe-stats`, `/admin/stats`). Defaults to `/__skew`. Set a
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-skew-protection",
3
3
  "type": "module",
4
- "version": "1.3.1",
4
+ "version": "1.4.0",
5
5
  "description": "Solve Nuxt version skews with persistent assets and instant updates.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -77,48 +77,49 @@
77
77
  }
78
78
  },
79
79
  "dependencies": {
80
- "@nuxt/kit": "^4.5.0",
81
- "@vueuse/core": "^14.3.0",
80
+ "@nuxt/kit": "^4.5.1",
81
+ "@vueuse/core": "^14.4.0",
82
82
  "consola": "^3.4.2",
83
83
  "cookie-es": "^3.1.1",
84
- "nuxt-site-config": "^4.1.1",
85
- "nuxtseo-shared": "^5.3.2",
84
+ "nuxt-site-config": "^4.1.4",
85
+ "nuxtseo-shared": "^5.3.9",
86
+ "ofetch": "^1.5.1",
86
87
  "pathe": "^2.0.3",
87
88
  "pkg-types": "^2.3.1",
88
- "tinyexec": "^1.2.4",
89
+ "tinyexec": "^1.3.0",
89
90
  "unstorage": "^1.17.5",
90
91
  "zod": "^4.4.3"
91
92
  },
92
93
  "devDependencies": {
93
- "@antfu/eslint-config": "^9.1.0",
94
+ "@antfu/eslint-config": "^9.2.0",
94
95
  "@arethetypeswrong/cli": "^0.18.5",
95
- "@nuxt/module-builder": "^1.0.2",
96
- "@nuxt/test-utils": "^4.0.3",
96
+ "@nuxt/module-builder": "^1.0.3",
97
+ "@nuxt/test-utils": "^4.1.0",
97
98
  "@nuxt/ui": "^4.10.0",
98
- "@nuxtjs/robots": "^6.1.2",
99
+ "@nuxtjs/robots": "^6.1.3",
99
100
  "@types/ws": "^8.18.1",
100
- "ably": "^2.25.0",
101
- "better-sqlite3": "^12.11.1",
102
- "bumpp": "^11.1.0",
103
- "eslint": "^10.7.0",
104
- "eslint-plugin-harlanzw": "^0.17.0",
101
+ "ably": "^2.26.0",
102
+ "better-sqlite3": "^13.0.2",
103
+ "bumpp": "^12.1.1",
104
+ "eslint": "^10.8.0",
105
+ "eslint-plugin-harlanzw": "^0.17.1",
105
106
  "eventsource": "^4.1.0",
106
- "happy-dom": "^20.10.6",
107
- "ioredis": "^5.11.1",
108
- "nuxt": "^4.5.0",
107
+ "happy-dom": "^20.11.1",
108
+ "ioredis": "^6.0.0",
109
+ "nuxt": "^4.5.1",
109
110
  "nuxt-auth-utils": "^0.5.29",
110
- "nuxtseo-layer-devtools": "^5.3.2",
111
- "playwright-core": "^1.61.1",
112
- "pusher-js": "^8.5.0",
111
+ "nuxtseo-layer-devtools": "^5.3.6",
112
+ "playwright-core": "^1.62.1",
113
+ "pusher-js": "^8.6.0",
113
114
  "std-env": "^4.2.0",
114
- "tsx": "^4.23.1",
115
- "typescript": "^6.0.3",
115
+ "tsx": "^4.23.5",
116
+ "typescript": "6.0.3",
116
117
  "unbuild": "^3.6.1",
117
118
  "vitest": "^4.1.10",
118
119
  "vue": "^3.5.40",
119
120
  "vue-router": "^5.2.0",
120
- "vue-tsc": "^3.3.7",
121
- "wrangler": "^4.112.0",
121
+ "vue-tsc": "^3.3.9",
122
+ "wrangler": "^4.118.0",
122
123
  "ws": "^8.21.1"
123
124
  },
124
125
  "resolutions": {
@@ -134,7 +135,7 @@
134
135
  "dev:build": "nuxi build playground",
135
136
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && nuxi prepare playground && pnpm run build:devtools",
136
137
  "release": "pnpm build && bumpp -x \"npx changelogen --output=CHANGELOG.md\"",
137
- "test": "vitest",
138
+ "test": "vitest && pnpm test:nuxt5",
138
139
  "test:unit": "vitest run test/unit",
139
140
  "test:integration": "vitest run test/integration",
140
141
  "test:e2e": "vitest run test/e2e",
@@ -145,6 +146,7 @@
145
146
  "test:node-polling": "node --experimental-strip-types scripts/test-node-polling.ts",
146
147
  "test:node-ws": "node --experimental-strip-types scripts/test-node-ws.ts",
147
148
  "test:static-polling": "node --experimental-strip-types scripts/test-static-polling.ts",
149
+ "test:nuxt5": "pnpm pack --out test/fixtures/nuxt5/module.tgz && node test/fixtures/nuxt5/run.mjs",
148
150
  "test:vercel-sse": "node --experimental-strip-types scripts/test-vercel-sse.ts",
149
151
  "typecheck": "nuxt typecheck",
150
152
  "test:attw": "attw --pack"
@@ -1 +0,0 @@
1
- export declare const logger: import("consola").ConsolaInstance;
@@ -1,6 +0,0 @@
1
- import { createConsola } from "consola";
2
- export const logger = createConsola({
3
- defaults: {
4
- tag: "nuxt-skew-protection"
5
- }
6
- });