nuxt-skew-protection 0.1.6 → 0.1.7
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.json +1 -1
- package/dist/runtime/app/composables/useSkewProtection.d.ts +6 -5
- package/dist/runtime/app/composables/useSkewProtection.js +6 -13
- package/dist/runtime/app/plugins/0.skew-protection.d.ts +3 -1
- package/dist/runtime/app/plugins/0.skew-protection.js +13 -13
- package/dist/runtime/app/plugins/check-updates-sse.client.js +3 -0
- package/dist/runtime/app/plugins/check-updates-websocket.client.js +3 -0
- package/dist/runtime/app/plugins/sw-track-user-modules.client.js +3 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import type { NuxtAppManifestMeta } from '
|
|
1
|
+
import type { NuxtAppManifestMeta } from 'nuxt/app';
|
|
2
2
|
import type { Ref } from 'vue';
|
|
3
3
|
import type { ChunksOutdatedPayload } from '../../types.js';
|
|
4
4
|
export declare function useSkewProtection(): {
|
|
5
|
-
|
|
5
|
+
manifest: Ref<NuxtAppManifestMeta | null>;
|
|
6
|
+
currentVersion: string | undefined;
|
|
7
|
+
isOutdated: Ref<boolean>;
|
|
8
|
+
cookie: Ref<string | undefined>;
|
|
9
|
+
} & {
|
|
6
10
|
onCurrentChunksOutdated: (callback: (payload: ChunksOutdatedPayload) => void | Promise<void>) => () => void;
|
|
7
11
|
onAppOutdated: (callback: (manifest?: NuxtAppManifestMeta) => void | Promise<void>) => void;
|
|
8
12
|
checkForUpdates: () => Promise<void>;
|
|
9
13
|
simulateUpdate(): Promise<void>;
|
|
10
|
-
manifest: Ref<NuxtAppManifestMeta | null>;
|
|
11
|
-
currentVersion: string | undefined;
|
|
12
|
-
isOutdated: Ref<boolean>;
|
|
13
14
|
};
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import { useCookie, useNuxtApp, useRuntimeConfig } from "#app";
|
|
2
1
|
import { buildAssetsURL } from "#internal/nuxt/paths";
|
|
2
|
+
import { useNuxtApp } from "nuxt/app";
|
|
3
3
|
import { onUnmounted } from "vue";
|
|
4
|
-
import { useRuntimeConfigSkewProtection } from "./useRuntimeConfigSkewProtection.js";
|
|
5
4
|
export function useSkewProtection() {
|
|
6
5
|
const nuxtApp = useNuxtApp();
|
|
7
|
-
const config = useRuntimeConfig();
|
|
8
|
-
const { cookie: cookieConfig } = useRuntimeConfigSkewProtection();
|
|
9
|
-
const { name: cookieName, ...cookieOptions } = cookieConfig;
|
|
10
|
-
const cookie = useCookie(cookieName, {
|
|
11
|
-
default: () => config.app.buildId,
|
|
12
|
-
...cookieOptions
|
|
13
|
-
});
|
|
14
6
|
const skewProtection = nuxtApp.$skewProtection;
|
|
7
|
+
if (!skewProtection) {
|
|
8
|
+
throw new Error("useSkewProtection must be used after the skew-protection:root plugin");
|
|
9
|
+
}
|
|
15
10
|
async function checkForUpdates() {
|
|
16
11
|
const meta = await $fetch(`${buildAssetsURL("builds/latest.json")}?${Date.now()}`).catch(() => {
|
|
17
12
|
return null;
|
|
@@ -37,9 +32,7 @@ export function useSkewProtection() {
|
|
|
37
32
|
}
|
|
38
33
|
});
|
|
39
34
|
}
|
|
40
|
-
return {
|
|
41
|
-
...skewProtection,
|
|
42
|
-
cookie,
|
|
35
|
+
return Object.assign(skewProtection, {
|
|
43
36
|
onCurrentChunksOutdated,
|
|
44
37
|
onAppOutdated,
|
|
45
38
|
checkForUpdates,
|
|
@@ -53,5 +46,5 @@ export function useSkewProtection() {
|
|
|
53
46
|
passedReleases: []
|
|
54
47
|
});
|
|
55
48
|
}
|
|
56
|
-
};
|
|
49
|
+
});
|
|
57
50
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NuxtAppManifestMeta } from '
|
|
1
|
+
import type { NuxtAppManifestMeta } from 'nuxt/app';
|
|
2
2
|
declare const _default: import("#app").Plugin<{
|
|
3
3
|
skewProtection: {
|
|
4
4
|
manifest: import("vue").Ref<{
|
|
@@ -10,6 +10,7 @@ declare const _default: import("#app").Plugin<{
|
|
|
10
10
|
} | null>;
|
|
11
11
|
currentVersion: any;
|
|
12
12
|
isOutdated: import("vue").ComputedRef<boolean>;
|
|
13
|
+
cookie: import("#app").CookieRef<any>;
|
|
13
14
|
};
|
|
14
15
|
}> & import("#app").ObjectPlugin<{
|
|
15
16
|
skewProtection: {
|
|
@@ -22,6 +23,7 @@ declare const _default: import("#app").Plugin<{
|
|
|
22
23
|
} | null>;
|
|
23
24
|
currentVersion: any;
|
|
24
25
|
isOutdated: import("vue").ComputedRef<boolean>;
|
|
26
|
+
cookie: import("#app").CookieRef<any>;
|
|
25
27
|
};
|
|
26
28
|
}>;
|
|
27
29
|
export default _default;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { useRuntimeConfig } from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { computed, ref, watch } from "vue";
|
|
5
|
-
import { useSkewProtection } from "../composables/useSkewProtection.js";
|
|
1
|
+
import { defineNuxtPlugin, useCookie, useRuntimeConfig } from "nuxt/app";
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import { useRuntimeConfigSkewProtection } from "../composables/useRuntimeConfigSkewProtection.js";
|
|
6
4
|
export default defineNuxtPlugin({
|
|
7
5
|
name: "skew-protection:root",
|
|
6
|
+
enforce: "pre",
|
|
8
7
|
setup(nuxtApp) {
|
|
9
8
|
const runtimeConfig = useRuntimeConfig();
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const { cookie: cookieConfig } = useRuntimeConfigSkewProtection();
|
|
10
|
+
const { name: cookieName, ...cookieOptions } = cookieConfig;
|
|
11
|
+
const cookie = useCookie(cookieName, {
|
|
12
|
+
default: () => runtimeConfig.app.buildId,
|
|
13
|
+
...cookieOptions
|
|
14
|
+
});
|
|
15
|
+
const currentVersion = runtimeConfig.app.buildId || cookie.value;
|
|
12
16
|
const latestVersion = ref(currentVersion);
|
|
13
17
|
const manifest = ref(null);
|
|
14
18
|
const isOutdated = computed(() => currentVersion !== latestVersion.value);
|
|
@@ -22,18 +26,14 @@ export default defineNuxtPlugin({
|
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
});
|
|
25
|
-
const focused = useWindowFocus();
|
|
26
|
-
watch(focused, () => {
|
|
27
|
-
if (isOutdated.value) {
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
29
|
}
|
|
31
30
|
return {
|
|
32
31
|
provide: {
|
|
33
32
|
skewProtection: {
|
|
34
33
|
manifest,
|
|
35
34
|
currentVersion,
|
|
36
|
-
isOutdated
|
|
35
|
+
isOutdated,
|
|
36
|
+
cookie
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
};
|
|
@@ -5,6 +5,9 @@ import { logger } from "../../shared/logger.js";
|
|
|
5
5
|
import { useSkewProtection } from "../composables/useSkewProtection.js";
|
|
6
6
|
export default defineNuxtPlugin({
|
|
7
7
|
name: "skew-protection:sse-updates",
|
|
8
|
+
dependsOn: [
|
|
9
|
+
"skew-protection:root"
|
|
10
|
+
],
|
|
8
11
|
setup() {
|
|
9
12
|
const skew = useSkewProtection();
|
|
10
13
|
const clientVersion = skew.cookie.value;
|
|
@@ -6,6 +6,9 @@ import { useRuntimeConfigSkewProtection } from "../composables/useRuntimeConfigS
|
|
|
6
6
|
import { useSkewProtection } from "../composables/useSkewProtection.js";
|
|
7
7
|
export default defineNuxtPlugin({
|
|
8
8
|
name: "skew-protection:websocket-updates",
|
|
9
|
+
dependsOn: [
|
|
10
|
+
"skew-protection:root"
|
|
11
|
+
],
|
|
9
12
|
setup(nuxtApp) {
|
|
10
13
|
const skewConfig = useRuntimeConfigSkewProtection();
|
|
11
14
|
const skewProtection = useSkewProtection();
|