nuxt-skew-protection 0.3.7 → 0.3.9

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
@@ -4,7 +4,7 @@
4
4
  "nuxt": ">=4.0.0"
5
5
  },
6
6
  "configKey": "skewProtection",
7
- "version": "0.3.7",
7
+ "version": "0.3.9",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,14 +1,19 @@
1
1
  import { writeFileSync, unlinkSync, existsSync, readFileSync, promises } from 'node:fs';
2
- import { useNuxt, tryUseNuxt, useLogger, defineNuxtModule, createResolver, hasNuxtModule, addTypeTemplate, addComponent, addImports, addPlugin, addServerHandler } from '@nuxt/kit';
2
+ import { useLogger, useNuxt, tryUseNuxt, defineNuxtModule, createResolver, hasNuxtModule, addTypeTemplate, addComponent, addImports, addPlugin, addServerHandler } from '@nuxt/kit';
3
3
  import { colors } from 'consola/utils';
4
+ import { useSiteConfig, installNuxtSiteConfig } from 'nuxt-site-config/kit';
4
5
  import { readPackageJSON } from 'pkg-types';
5
- import { provider, env } from 'std-env';
6
+ import * as p from '@clack/prompts';
7
+ import { $fetch } from 'ofetch';
8
+ import { isTest, isCI, provider, env } from 'std-env';
6
9
  import { join } from 'node:path';
7
10
  import { tmpdir } from 'node:os';
8
11
  import { x } from 'tinyexec';
9
12
  import { defineDriver, createStorage } from 'unstorage';
10
13
  import { join as join$1, dirname } from 'pathe';
11
14
 
15
+ const logger = useLogger("nuxt-skew-protection");
16
+
12
17
  function isStaticPreset(nuxt = useNuxt()) {
13
18
  return nuxt.options.nitro?.static || nuxt.options._generate || [
14
19
  "static",
@@ -42,8 +47,56 @@ function resolveNitroPreset(nitroConfig) {
42
47
  preset = env.NITRO_PRESET || env.SERVER_PRESET || detectTarget() || "node-server";
43
48
  return preset.replace("_", "-");
44
49
  }
45
-
46
- const logger = useLogger("nuxt-skew-protection");
50
+ function hookNuxtSeoProLicense() {
51
+ const nuxt = useNuxt();
52
+ const isBuild = !nuxt.options.dev && !nuxt.options._prepare;
53
+ if (isBuild && !nuxt._isNuxtSeoProVerifying) {
54
+ const license = nuxt.options.runtimeConfig.seoProKey || process.env.NUXT_SEO_PRO_KEY;
55
+ if (isTest) {
56
+ return;
57
+ }
58
+ if (!isCI && !license) {
59
+ p.log.warn("\u26A0\uFE0F Building without license in non-CI environment. A license is required for production builds.");
60
+ return;
61
+ }
62
+ if (!license) {
63
+ p.log.error("\u{1F510} Nuxt SEO Pro license required");
64
+ p.note("Set NUXT_SEO_PRO_KEY or configure via module options.\n\nhttps://nuxtseo.com/pro/dashboard", "Get your license");
65
+ throw new Error("Missing Nuxt SEO Pro license key.");
66
+ }
67
+ nuxt._isNuxtSeoProVerifying = true;
68
+ nuxt.hooks.hook("build:before", async () => {
69
+ p.intro("Nuxt SEO Pro: License Verification");
70
+ const siteConfig = useSiteConfig();
71
+ const spinner = p.spinner();
72
+ spinner.start("\u{1F511} Verifying Nuxt SEO Pro license...");
73
+ const siteUrl = siteConfig.url?.startsWith("http") ? siteConfig.url : void 0;
74
+ const siteName = siteConfig.name || void 0;
75
+ const res = await $fetch("https://nuxtseo.com/api/pro/verify", {
76
+ method: "POST",
77
+ body: { apiKey: license, siteUrl, siteName }
78
+ }).catch((err) => {
79
+ if (err?.response?.status === 401) {
80
+ spinner.stop("\u274C Invalid API key");
81
+ p.note("Your API key is invalid.\n\nhttps://nuxtseo.com/pro/dashboard", "License Issue");
82
+ throw new Error("Invalid Nuxt SEO Pro API key.");
83
+ }
84
+ if (err?.response?.status === 403) {
85
+ spinner.stop("\u274C No active subscription");
86
+ p.note("Your subscription has expired or is inactive.\n\nhttps://nuxtseo.com/pro/dashboard", "License Issue");
87
+ throw new Error("No active Nuxt SEO Pro subscription.");
88
+ }
89
+ logger.error(err);
90
+ return null;
91
+ });
92
+ if (!res) {
93
+ spinner.stop("\u26A0\uFE0F License verification skipped (network issue)");
94
+ return;
95
+ }
96
+ spinner.stop("License verified \u2713");
97
+ });
98
+ }
99
+ }
47
100
 
48
101
  const cloudflareKVWranglerDriver = defineDriver((opts) => {
49
102
  const { namespaceId, local = false, base = "" } = opts;
@@ -196,10 +249,9 @@ async function processBatch(items, batchSize, processor) {
196
249
  }
197
250
  function extractFileId(assetPath) {
198
251
  const filename = assetPath.split("/").pop();
199
- if (!filename)
252
+ if (!filename || !filename.includes("."))
200
253
  return null;
201
- const match = filename.match(/^([^.]+\.\w+)/);
202
- return match ? match[1] ?? null : null;
254
+ return filename;
203
255
  }
204
256
  function calculateDeletedChunks(currentAssets, previousAssets) {
205
257
  const currentSet = new Set(currentAssets);
@@ -380,8 +432,9 @@ function createAssetManager(options) {
380
432
  const previousAssets = manifest.versions[previousVersionId].assets;
381
433
  const assetIndex = previousAssets.findIndex((a) => extractFileId(a) === fileId);
382
434
  if (assetIndex !== -1) {
435
+ const oldAssetPath = previousAssets[assetIndex];
383
436
  previousAssets.splice(assetIndex, 1);
384
- const oldStorageKey = `${previousVersionId}/${asset}`;
437
+ const oldStorageKey = `${previousVersionId}/${oldAssetPath}`;
385
438
  await storage.removeItem(oldStorageKey).catch((error) => {
386
439
  if (options.debug) {
387
440
  logger.warn(`Failed to remove duplicate asset ${oldStorageKey}:`, error);
@@ -589,6 +642,8 @@ const module$1 = defineNuxtModule({
589
642
  logger.debug("The module is disabled, skipping setup.");
590
643
  return;
591
644
  }
645
+ await installNuxtSiteConfig();
646
+ hookNuxtSeoProLicense();
592
647
  nuxt.options.runtimeConfig.public = nuxt.options.runtimeConfig.public || {};
593
648
  nuxt.options.runtimeConfig.public.skewProtection = {
594
649
  cookie: options.cookie,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-skew-protection",
3
3
  "type": "module",
4
- "version": "0.3.7",
4
+ "version": "0.3.9",
5
5
  "description": "Solve Nuxt version skews with persistent assets and instant updates.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",
@@ -29,13 +29,15 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@nuxt/kit": "^4.2.1",
32
+ "@clack/prompts": "^0.11.0",
33
+ "@nuxt/kit": "^4.2.2",
33
34
  "@nuxtjs/robots": "^5.6.3",
34
35
  "@vueuse/core": "^14.1.0",
35
36
  "consola": "^3.4.2",
36
37
  "cookie-es": "^2.0.0",
37
38
  "defu": "^6.1.4",
38
39
  "nuxt-site-config": "^3.2.11",
40
+ "ofetch": "^1.5.1",
39
41
  "pathe": "^2.0.3",
40
42
  "pkg-types": "^2.3.0",
41
43
  "std-env": "^3.10.0",
@@ -68,7 +70,7 @@
68
70
  "firebase-functions": "^7.0.1",
69
71
  "happy-dom": "^20.0.11",
70
72
  "ioredis": "^5.8.2",
71
- "nuxt": "^4.2.1",
73
+ "nuxt": "^4.2.2",
72
74
  "playwright-core": "^1.57.0",
73
75
  "tsx": "^4.21.0",
74
76
  "typescript": "^5.9.3",
@@ -77,7 +79,7 @@
77
79
  "vitest": "^4.0.15",
78
80
  "vue": "^3.5.25",
79
81
  "vue-router": "^4.6.3",
80
- "vue-tsc": "^3.1.7",
82
+ "vue-tsc": "^3.1.8",
81
83
  "wrangler": "^4.53.0",
82
84
  "ws": "^8.18.3"
83
85
  },