nuxt-skew-protection 0.7.0 → 0.7.2

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 CHANGED
@@ -9,7 +9,7 @@
9
9
  "version": ">=5.6.7"
10
10
  }
11
11
  },
12
- "version": "0.7.0",
12
+ "version": "0.7.2",
13
13
  "builder": {
14
14
  "@nuxt/module-builder": "1.0.2",
15
15
  "unbuild": "3.6.1"
@@ -1,8 +1,4 @@
1
1
  import type { SkewAdapterConfig } from '../types.js';
2
2
  export type { SkewAdapterConfig };
3
- declare const _default: import("nuxt/app").Plugin<{
4
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
5
- }> & import("nuxt/app").ObjectPlugin<{
6
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
7
- }>;
3
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
8
4
  export default _default;
@@ -5,6 +5,8 @@ import { createSkewConnection } from "../utils/create-skew-connection.js";
5
5
  export default defineNuxtPlugin({
6
6
  name: "skew-protection:adapter-updates",
7
7
  async setup() {
8
+ if (import.meta.prerender)
9
+ return;
8
10
  const nuxtApp = useNuxtApp();
9
11
  const adapterName = useRuntimeConfig().public.skewProtection.adapterName;
10
12
  const config = {
@@ -1,8 +1,4 @@
1
1
  import type { SkewSSEConfig } from '../types.js';
2
2
  export type { SkewSSEConfig };
3
- declare const _default: import("nuxt/app").Plugin<{
4
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
5
- }> & import("nuxt/app").ObjectPlugin<{
6
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
7
- }>;
3
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
8
4
  export default _default;
@@ -5,6 +5,8 @@ import { createSkewConnection } from "../utils/create-skew-connection.js";
5
5
  export default defineNuxtPlugin({
6
6
  name: "skew-protection:sse-updates",
7
7
  async setup() {
8
+ if (import.meta.prerender)
9
+ return;
8
10
  const nuxtApp = useNuxtApp();
9
11
  const router = useRouter();
10
12
  const runtimeConfig = useRuntimeConfig();
@@ -1,8 +1,4 @@
1
1
  import type { SkewWebSocketConfig } from '../types.js';
2
2
  export type { SkewWebSocketConfig };
3
- declare const _default: import("nuxt/app").Plugin<{
4
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
5
- }> & import("nuxt/app").ObjectPlugin<{
6
- skewConnection: import("../utils/create-skew-connection.js").SkewConnection;
7
- }>;
3
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
8
4
  export default _default;
@@ -6,6 +6,8 @@ import { createSkewConnection } from "../utils/create-skew-connection.js";
6
6
  export default defineNuxtPlugin({
7
7
  name: "skew-protection:ws-updates",
8
8
  async setup() {
9
+ if (import.meta.prerender)
10
+ return;
9
11
  const nuxtApp = useNuxtApp();
10
12
  const router = useRouter();
11
13
  const runtimeConfig = useRuntimeConfig();
@@ -12,6 +12,8 @@ function normalizePath(pathOrUrl) {
12
12
  export default defineNuxtPlugin({
13
13
  name: "skew-protection:service-worker",
14
14
  setup(nuxtApp) {
15
+ if (import.meta.prerender)
16
+ return;
15
17
  if (!("serviceWorker" in navigator)) {
16
18
  logger.debug("[SW] Service Worker not supported in this browser");
17
19
  return;
@@ -1,5 +1,6 @@
1
1
  import { useBotDetection } from "#imports";
2
2
  import { useCookie, useNuxtApp, useRuntimeConfig } from "nuxt/app";
3
+ import { SKEW_MESSAGE_TYPE } from "../../const.js";
3
4
  import { init, logger } from "../../shared/logger.js";
4
5
  export function createSkewConnection(config) {
5
6
  const { name, setup } = config;
@@ -76,13 +77,17 @@ export function createSkewConnection(config) {
76
77
  const subscribeStats = () => {
77
78
  if (!isConnected || !connectionId)
78
79
  return;
79
- fetch("/_skew/subscribe-stats", {
80
- method: "POST",
81
- headers: { "Content-Type": "application/json" },
82
- credentials: "same-origin",
83
- body: JSON.stringify({ connectionId })
84
- }).catch(() => {
85
- });
80
+ if (sendFn) {
81
+ sendFn({ type: SKEW_MESSAGE_TYPE.SUBSCRIBE_STATS });
82
+ } else {
83
+ fetch("/_skew/subscribe-stats", {
84
+ method: "POST",
85
+ headers: { "Content-Type": "application/json" },
86
+ credentials: "same-origin",
87
+ body: JSON.stringify({ connectionId })
88
+ }).catch(() => {
89
+ });
90
+ }
86
91
  };
87
92
  nuxtApp.hook("app:error", disconnect);
88
93
  if (import.meta.client) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-skew-protection",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.7.2",
5
5
  "description": "Solve Nuxt version skews with persistent assets and instant updates.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -61,7 +61,7 @@
61
61
  "pkg-types": "^2.3.0",
62
62
  "std-env": "^3.10.0",
63
63
  "tinyexec": "^1.0.2",
64
- "ufo": "^1.6.1",
64
+ "ufo": "^1.6.2",
65
65
  "unstorage": "^1.17.3",
66
66
  "zod": "^4.3.5"
67
67
  },
@@ -71,7 +71,7 @@
71
71
  "@nuxt/content": "^3.10.0",
72
72
  "@nuxt/devtools-ui-kit": "^3.1.1",
73
73
  "@nuxt/module-builder": "^1.0.2",
74
- "@nuxt/test-utils": "^3.22.0",
74
+ "@nuxt/test-utils": "^3.23.0",
75
75
  "@nuxt/ui": "^4.3.0",
76
76
  "@nuxtjs/color-mode": "^4.0.0",
77
77
  "@nuxtjs/eslint-config-typescript": "^12.1.0",