nuxt-skew-protection 0.2.1 → 0.2.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 +1 -1
- package/dist/module.mjs +1 -1
- package/dist/sw/_nuxt-skew-sw.js +1 -0
- package/package.json +2 -2
- package/dist/module.cjs +0 -757
- package/dist/module.d.cts +0 -64
- package/dist/module.d.ts +0 -64
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -593,7 +593,7 @@ const module = defineNuxtModule({
|
|
|
593
593
|
cookie: options.cookie,
|
|
594
594
|
debug: options.debug
|
|
595
595
|
};
|
|
596
|
-
const nitroPreset =
|
|
596
|
+
const nitroPreset = resolveNitroPreset(nuxt.options.nitro);
|
|
597
597
|
addTypeTemplate({
|
|
598
598
|
filename: "types/nuxt-skew-protection.d.ts",
|
|
599
599
|
getContents: () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const loadedModules=new Set;self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())}),self.addEventListener("fetch",e=>{const t=e.request.url;(e.request.destination==="script"||t.endsWith(".js"))&&(loadedModules.add(t),e.waitUntil(self.clients.matchAll().then(a=>{a.forEach(s=>{s.postMessage({type:"MODULE_LOADED",url:t,modules:Array.from(loadedModules)})})})))}),self.addEventListener("message",e=>{if(e.data.type==="GET_MODULES"){const t=Array.from(loadedModules);e.source.postMessage({type:"MODULES_LIST",modules:t})}if(e.data.type==="CHECK_MODULE"){const t=loadedModules.has(e.data.url);e.source.postMessage({type:"MODULE_STATUS",url:e.data.url,loaded:t})}e.data.type==="RESET_MODULES"&&(loadedModules.clear(),e.source.postMessage({type:"MODULES_RESET",success:!0})),e.data.type==="ADD_MODULE"&&loadedModules.add(e.data.url)});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-skew-protection",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "Instantly adopted Nuxt releases with long-lived build assets.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"lint": "eslint . --fix",
|
|
89
|
-
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
|
|
89
|
+
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && unbuild --config sw.build.config.ts",
|
|
90
90
|
"dev": "nuxi dev playground",
|
|
91
91
|
"dev:build": "nuxi build playground",
|
|
92
92
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && nuxi prepare playground",
|
package/dist/module.cjs
DELETED
|
@@ -1,757 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_fs = require('node:fs');
|
|
4
|
-
const kit = require('@nuxt/kit');
|
|
5
|
-
const stdEnv = require('std-env');
|
|
6
|
-
const node_path = require('node:path');
|
|
7
|
-
const node_os = require('node:os');
|
|
8
|
-
const tinyexec = require('tinyexec');
|
|
9
|
-
const unstorage = require('unstorage');
|
|
10
|
-
const utils = require('consola/utils');
|
|
11
|
-
const pathe = require('pathe');
|
|
12
|
-
|
|
13
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
14
|
-
function isStaticPreset(nuxt = kit.useNuxt()) {
|
|
15
|
-
return nuxt.options.nitro?.static || nuxt.options._generate || [
|
|
16
|
-
"static",
|
|
17
|
-
"github-pages"
|
|
18
|
-
].includes(resolveNitroPreset());
|
|
19
|
-
}
|
|
20
|
-
const autodetectableProviders = {
|
|
21
|
-
azure_static: "azure",
|
|
22
|
-
cloudflare_pages: "cloudflare-pages",
|
|
23
|
-
netlify: "netlify",
|
|
24
|
-
stormkit: "stormkit",
|
|
25
|
-
vercel: "vercel",
|
|
26
|
-
cleavr: "cleavr",
|
|
27
|
-
stackblitz: "stackblitz"
|
|
28
|
-
};
|
|
29
|
-
const autodetectableStaticProviders = {
|
|
30
|
-
netlify: "netlify-static",
|
|
31
|
-
vercel: "vercel-static"
|
|
32
|
-
};
|
|
33
|
-
function detectTarget(options = {}) {
|
|
34
|
-
return options?.static ? autodetectableStaticProviders[stdEnv.provider] : autodetectableProviders[stdEnv.provider];
|
|
35
|
-
}
|
|
36
|
-
function resolveNitroPreset(nitroConfig) {
|
|
37
|
-
nitroConfig = nitroConfig || kit.tryUseNuxt()?.options?.nitro;
|
|
38
|
-
if (stdEnv.provider === "stackblitz")
|
|
39
|
-
return "stackblitz";
|
|
40
|
-
let preset;
|
|
41
|
-
if (nitroConfig && nitroConfig?.preset)
|
|
42
|
-
preset = nitroConfig.preset;
|
|
43
|
-
if (!preset)
|
|
44
|
-
preset = stdEnv.env.NITRO_PRESET || stdEnv.env.SERVER_PRESET || detectTarget() || "node-server";
|
|
45
|
-
return preset.replace("_", "-");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const logger = kit.useLogger("nuxt-skew-protection");
|
|
49
|
-
|
|
50
|
-
const cloudflareKVWranglerDriver = unstorage.defineDriver((opts) => {
|
|
51
|
-
const { namespaceId, local = false } = opts;
|
|
52
|
-
if (!namespaceId) {
|
|
53
|
-
throw new Error("[cloudflare-kv-wrangler] namespaceId is required");
|
|
54
|
-
}
|
|
55
|
-
const locationFlag = local ? "--local" : "--remote";
|
|
56
|
-
async function execWrangler(command, throwOnError = true) {
|
|
57
|
-
const result = await tinyexec.x("sh", ["-c", `npx ${command}`]);
|
|
58
|
-
if (throwOnError && result.exitCode !== 0) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
`[cloudflare-kv-wrangler] Command failed with exit code ${result.exitCode}
|
|
61
|
-
Command: ${command}
|
|
62
|
-
stdout: ${result.stdout}
|
|
63
|
-
stderr: ${result.stderr}`
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return { stdout: result.stdout.trim(), exitCode: result.exitCode || 0 };
|
|
67
|
-
}
|
|
68
|
-
const driver = {
|
|
69
|
-
name: "cloudflare-kv-wrangler",
|
|
70
|
-
options: opts,
|
|
71
|
-
async hasItem(key) {
|
|
72
|
-
const result = await execWrangler(`wrangler kv key get "${key}" --namespace-id="${namespaceId}" ${locationFlag}`, false);
|
|
73
|
-
return result.exitCode === 0;
|
|
74
|
-
},
|
|
75
|
-
async getItem(key) {
|
|
76
|
-
const result = await execWrangler(`wrangler kv key get "${key}" --namespace-id="${namespaceId}" ${locationFlag}`, false);
|
|
77
|
-
if (result.exitCode !== 0) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
return JSON.parse(result.stdout);
|
|
81
|
-
},
|
|
82
|
-
async getItemRaw(key) {
|
|
83
|
-
const result = await execWrangler(`wrangler kv key get "${key}" --namespace-id="${namespaceId}" ${locationFlag}`);
|
|
84
|
-
return Buffer.from(result.stdout, "utf-8");
|
|
85
|
-
},
|
|
86
|
-
async setItem(key, value) {
|
|
87
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `kv-${Date.now()}-${Math.random().toString(36).substring(7)}.json`);
|
|
88
|
-
node_fs.writeFileSync(tmpFile, JSON.stringify(value));
|
|
89
|
-
try {
|
|
90
|
-
await execWrangler(`wrangler kv key put "${key}" --path="${tmpFile}" --namespace-id="${namespaceId}" ${locationFlag}`);
|
|
91
|
-
} finally {
|
|
92
|
-
node_fs.unlinkSync(tmpFile);
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
async setItemRaw(key, value) {
|
|
96
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `kv-${Date.now()}.bin`);
|
|
97
|
-
node_fs.writeFileSync(tmpFile, value);
|
|
98
|
-
await execWrangler(`wrangler kv key put "${key}" --path="${tmpFile}" --namespace-id="${namespaceId}" ${locationFlag}`);
|
|
99
|
-
node_fs.unlinkSync(tmpFile);
|
|
100
|
-
},
|
|
101
|
-
async removeItem(key) {
|
|
102
|
-
await execWrangler(`wrangler kv key delete "${key}" --namespace-id="${namespaceId}" ${locationFlag}`);
|
|
103
|
-
},
|
|
104
|
-
async getKeys(base) {
|
|
105
|
-
const prefix = base ? `--prefix="${base}"` : "";
|
|
106
|
-
const result = await execWrangler(`wrangler kv key list ${prefix} --namespace-id="${namespaceId}" ${locationFlag}`);
|
|
107
|
-
const keys = JSON.parse(result.stdout);
|
|
108
|
-
return keys.map((k) => k.name);
|
|
109
|
-
},
|
|
110
|
-
async clear(base) {
|
|
111
|
-
const keys = await driver.getKeys(base);
|
|
112
|
-
for (const key of keys) {
|
|
113
|
-
await driver.removeItem(key);
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
async dispose() {
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
return driver;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const vercelKVCLIDriver = unstorage.defineDriver((opts) => {
|
|
123
|
-
const { storeName, teamId } = opts;
|
|
124
|
-
if (!storeName) {
|
|
125
|
-
throw new Error("[vercel-kv-cli] storeName is required");
|
|
126
|
-
}
|
|
127
|
-
function buildCommand(subcommand) {
|
|
128
|
-
const teamFlag = teamId ? `--team ${teamId}` : "";
|
|
129
|
-
return `vercel kv ${subcommand} ${storeName} ${teamFlag}`.trim();
|
|
130
|
-
}
|
|
131
|
-
async function execVercelKV(subcommand) {
|
|
132
|
-
const command = buildCommand(subcommand);
|
|
133
|
-
const result = await tinyexec.x("sh", ["-c", command], {
|
|
134
|
-
throwOnError: true
|
|
135
|
-
});
|
|
136
|
-
return result.stdout.trim();
|
|
137
|
-
}
|
|
138
|
-
const driver = {
|
|
139
|
-
name: "vercel-kv-cli",
|
|
140
|
-
options: opts,
|
|
141
|
-
async hasItem(key) {
|
|
142
|
-
const result = await execVercelKV(`get "${key}"`);
|
|
143
|
-
return !!result;
|
|
144
|
-
},
|
|
145
|
-
async getItem(key) {
|
|
146
|
-
const result = await execVercelKV(`get "${key}"`);
|
|
147
|
-
return JSON.parse(result);
|
|
148
|
-
},
|
|
149
|
-
async getItemRaw(key) {
|
|
150
|
-
const result = await execVercelKV(`get "${key}"`);
|
|
151
|
-
return Buffer.from(result, "utf-8");
|
|
152
|
-
},
|
|
153
|
-
async setItem(key, value) {
|
|
154
|
-
const jsonValue = JSON.stringify(value);
|
|
155
|
-
const escapedValue = jsonValue.replace(/"/g, '\\"');
|
|
156
|
-
await execVercelKV(`set "${key}" "${escapedValue}"`);
|
|
157
|
-
},
|
|
158
|
-
async setItemRaw(key, value) {
|
|
159
|
-
const base64Value = Buffer.from(value).toString("base64");
|
|
160
|
-
const escapedValue = base64Value.replace(/"/g, '\\"');
|
|
161
|
-
await execVercelKV(`set "${key}" "${escapedValue}"`);
|
|
162
|
-
},
|
|
163
|
-
async removeItem(key) {
|
|
164
|
-
await execVercelKV(`del "${key}"`);
|
|
165
|
-
},
|
|
166
|
-
async getKeys(base) {
|
|
167
|
-
const pattern = base ? `"${base}*"` : '"*"';
|
|
168
|
-
const result = await execVercelKV(`keys ${pattern}`);
|
|
169
|
-
const keys = JSON.parse(result);
|
|
170
|
-
return Array.isArray(keys) ? keys : [];
|
|
171
|
-
},
|
|
172
|
-
async clear(base) {
|
|
173
|
-
const keys = await driver.getKeys(base);
|
|
174
|
-
for (const key of keys) {
|
|
175
|
-
await driver.removeItem(key);
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
async dispose() {
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
return driver;
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
async function detectCloudflareKVNamespace() {
|
|
185
|
-
const nuxt = kit.useNuxt();
|
|
186
|
-
const rootDir = nuxt.options.rootDir || process.cwd();
|
|
187
|
-
const wranglerPath = node_path.join(rootDir, "wrangler.toml");
|
|
188
|
-
if (!node_fs.existsSync(wranglerPath)) {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const content = node_fs.readFileSync(wranglerPath, "utf-8");
|
|
193
|
-
const kvNamespaceMatch = content.match(/\[\[kv_namespaces\]\][^[]*?id\s*=\s*"([^"]+)"/);
|
|
194
|
-
if (kvNamespaceMatch?.[1]) {
|
|
195
|
-
return kvNamespaceMatch[1];
|
|
196
|
-
}
|
|
197
|
-
return null;
|
|
198
|
-
} catch {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async function resolveBuildTimeDriver(storage) {
|
|
203
|
-
const { driver, ...driverOptions } = storage;
|
|
204
|
-
switch (driver) {
|
|
205
|
-
case "cloudflare-kv-binding": {
|
|
206
|
-
let namespaceId = storage.namespaceId;
|
|
207
|
-
if (!namespaceId) {
|
|
208
|
-
namespaceId = await detectCloudflareKVNamespace();
|
|
209
|
-
}
|
|
210
|
-
return cloudflareKVWranglerDriver({
|
|
211
|
-
namespaceId,
|
|
212
|
-
...driverOptions
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
case "vercel-kv": {
|
|
216
|
-
return vercelKVCLIDriver(driverOptions);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
const lazyDriver = await import(`unstorage/drivers/${storage.driver}`).then((m) => m.default);
|
|
220
|
-
return lazyDriver(driverOptions);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function extractFileId(assetPath) {
|
|
224
|
-
const filename = assetPath.split("/").pop();
|
|
225
|
-
if (!filename)
|
|
226
|
-
return null;
|
|
227
|
-
const match = filename.match(/^([^.]+\.\w+)/);
|
|
228
|
-
return match ? match[1] ?? null : null;
|
|
229
|
-
}
|
|
230
|
-
function calculateDeletedChunks(currentAssets, previousAssets) {
|
|
231
|
-
const currentSet = new Set(currentAssets);
|
|
232
|
-
return previousAssets.filter((asset) => !currentSet.has(asset));
|
|
233
|
-
}
|
|
234
|
-
function getPreviousVersion(manifest, currentVersionId) {
|
|
235
|
-
const sortedVersions = Object.entries(manifest.versions).map(([id, data]) => ({ id, timestamp: new Date(data.timestamp).getTime() })).sort((a, b) => b.timestamp - a.timestamp);
|
|
236
|
-
const currentIndex = sortedVersions.findIndex((v) => v.id === currentVersionId);
|
|
237
|
-
if (currentIndex === -1 || currentIndex === sortedVersions.length - 1) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
return sortedVersions[currentIndex + 1]?.id || null;
|
|
241
|
-
}
|
|
242
|
-
async function getFilesRecursively(dir) {
|
|
243
|
-
const files = [];
|
|
244
|
-
const items = await node_fs.promises.readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
245
|
-
for (const item of items) {
|
|
246
|
-
const fullPath = pathe.join(dir, item.name);
|
|
247
|
-
if (item.isDirectory()) {
|
|
248
|
-
const subFiles = await getFilesRecursively(fullPath);
|
|
249
|
-
files.push(...subFiles);
|
|
250
|
-
} else {
|
|
251
|
-
files.push(fullPath);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return files;
|
|
255
|
-
}
|
|
256
|
-
async function getVersionManifest(storage) {
|
|
257
|
-
try {
|
|
258
|
-
const manifest = await storage.getItem("version-manifest.json");
|
|
259
|
-
if (manifest && typeof manifest === "object" && "versions" in manifest) {
|
|
260
|
-
return manifest;
|
|
261
|
-
}
|
|
262
|
-
return {
|
|
263
|
-
current: "",
|
|
264
|
-
versions: {}
|
|
265
|
-
};
|
|
266
|
-
} catch {
|
|
267
|
-
return {
|
|
268
|
-
current: "",
|
|
269
|
-
versions: {}
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
async function setVersionManifest(manifest, storage) {
|
|
274
|
-
await storage.setItem("version-manifest.json", manifest);
|
|
275
|
-
}
|
|
276
|
-
function createAssetManager(options) {
|
|
277
|
-
const storage = unstorage.createStorage({
|
|
278
|
-
driver: options.driver
|
|
279
|
-
});
|
|
280
|
-
const retentionDays = options.retentionDays || 7;
|
|
281
|
-
const maxNumberOfVersions = options.maxNumberOfVersions || 20;
|
|
282
|
-
async function getAssetsFromBuild(outputDir) {
|
|
283
|
-
const nuxtDir = pathe.join(outputDir, "public", "_nuxt");
|
|
284
|
-
const assets = [];
|
|
285
|
-
const nuxtFiles = await getFilesRecursively(nuxtDir);
|
|
286
|
-
for (const file of nuxtFiles) {
|
|
287
|
-
const relativePath = file.replace(nuxtDir, "");
|
|
288
|
-
assets.push(`_nuxt${relativePath}`);
|
|
289
|
-
}
|
|
290
|
-
return assets;
|
|
291
|
-
}
|
|
292
|
-
async function updateVersionsManifest(buildId, assets) {
|
|
293
|
-
const now = /* @__PURE__ */ new Date();
|
|
294
|
-
const expires = new Date(now.getTime() + retentionDays * 24 * 60 * 60 * 1e3);
|
|
295
|
-
const manifest = await getVersionManifest(storage);
|
|
296
|
-
const isExistingVersion = !!manifest.versions[buildId];
|
|
297
|
-
manifest.current = buildId;
|
|
298
|
-
manifest.versions[buildId] = {
|
|
299
|
-
timestamp: now.toISOString(),
|
|
300
|
-
expires: expires.toISOString(),
|
|
301
|
-
assets,
|
|
302
|
-
// deletedChunks will be calculated after deduplication in storeAssetsInStorage
|
|
303
|
-
deletedChunks: []
|
|
304
|
-
};
|
|
305
|
-
await setVersionManifest(manifest, storage);
|
|
306
|
-
return { manifest, isExistingVersion };
|
|
307
|
-
}
|
|
308
|
-
async function cleanupExpiredVersions() {
|
|
309
|
-
const manifest = await getVersionManifest(storage);
|
|
310
|
-
if (!manifest || !manifest.versions) {
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const now = /* @__PURE__ */ new Date();
|
|
314
|
-
const removedVersions = [];
|
|
315
|
-
const sortedVersions = Object.entries(manifest.versions).map(([id, data]) => ({ id, ...data, timestamp: new Date(data.timestamp).getTime() })).sort((a, b) => b.timestamp - a.timestamp);
|
|
316
|
-
const maxAge = retentionDays * 24 * 60 * 60 * 1e3;
|
|
317
|
-
for (let i = 0; i < sortedVersions.length; i++) {
|
|
318
|
-
const version = sortedVersions[i];
|
|
319
|
-
const isExpired = now.getTime() - version.timestamp > maxAge;
|
|
320
|
-
const exceedsCount = i >= maxNumberOfVersions;
|
|
321
|
-
const isCurrent = version.id === manifest.current;
|
|
322
|
-
if (isCurrent || i === 0 && sortedVersions.length === 1) {
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
|
-
if (isExpired || exceedsCount) {
|
|
326
|
-
const assetPromises = version.assets.map(
|
|
327
|
-
(asset) => storage.removeItem(`${version.id}/${asset}`).catch((error) => {
|
|
328
|
-
if (options.debug) {
|
|
329
|
-
logger.warn(`Failed to remove asset ${asset}:`, error);
|
|
330
|
-
}
|
|
331
|
-
})
|
|
332
|
-
);
|
|
333
|
-
await Promise.all(assetPromises);
|
|
334
|
-
delete manifest.versions[version.id];
|
|
335
|
-
if (manifest.fileIdToVersion) {
|
|
336
|
-
for (const [fileId, versionId] of Object.entries(manifest.fileIdToVersion)) {
|
|
337
|
-
if (versionId === version.id) {
|
|
338
|
-
delete manifest.fileIdToVersion[fileId];
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
removedVersions.push({
|
|
343
|
-
id: version.id,
|
|
344
|
-
reason: isExpired ? "expired" : "exceeded count limit",
|
|
345
|
-
assetCount: version.assets.length
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
if (removedVersions.length > 0) {
|
|
350
|
-
await setVersionManifest(manifest, storage);
|
|
351
|
-
logger.log(`Removing outdated build artifacts...`);
|
|
352
|
-
removedVersions.forEach((item, index) => {
|
|
353
|
-
const isLast = index === removedVersions.length - 1;
|
|
354
|
-
const prefix = isLast ? " \u2514\u2500" : " \u251C\u2500";
|
|
355
|
-
const versionInfo = `${item.id.slice(0, 8)}`;
|
|
356
|
-
const assetInfo = `(${item.assetCount} asset${item.assetCount > 1 ? "s" : ""})`;
|
|
357
|
-
const reasonInfo = `[${item.reason}]`;
|
|
358
|
-
logger.log(utils.colors.gray(`${prefix} ${versionInfo} ${assetInfo} ${reasonInfo}`));
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
async function storeAssetsInStorage(buildId, outputDir, assets) {
|
|
363
|
-
const publicDir = pathe.join(outputDir, "public");
|
|
364
|
-
const manifest = await getVersionManifest(storage);
|
|
365
|
-
if (!manifest.fileIdToVersion) {
|
|
366
|
-
manifest.fileIdToVersion = {};
|
|
367
|
-
}
|
|
368
|
-
const fileIdToVersion = manifest.fileIdToVersion;
|
|
369
|
-
const currentVersion = manifest.versions[buildId];
|
|
370
|
-
if (currentVersion) {
|
|
371
|
-
const previousVersionId = getPreviousVersion(manifest, buildId);
|
|
372
|
-
const previousAssets = previousVersionId ? manifest.versions[previousVersionId]?.assets || [] : [];
|
|
373
|
-
currentVersion.deletedChunks = calculateDeletedChunks(assets, previousAssets);
|
|
374
|
-
}
|
|
375
|
-
for (const asset of assets) {
|
|
376
|
-
const fileId = extractFileId(asset);
|
|
377
|
-
const assetPath = pathe.join(publicDir, asset);
|
|
378
|
-
const assetData = await node_fs.promises.readFile(assetPath).catch((error) => {
|
|
379
|
-
if (options.debug) {
|
|
380
|
-
logger.warn(`Failed to read ${assetPath}:`, error);
|
|
381
|
-
}
|
|
382
|
-
return null;
|
|
383
|
-
});
|
|
384
|
-
if (assetData) {
|
|
385
|
-
const storageKey = `${buildId}/${asset}`;
|
|
386
|
-
await storage.setItemRaw(storageKey, assetData).catch((error) => {
|
|
387
|
-
if (options.debug) {
|
|
388
|
-
logger.warn(`Failed to store ${storageKey}:`, error);
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
if (fileId && fileIdToVersion[fileId] && fileIdToVersion[fileId] !== buildId) {
|
|
392
|
-
const previousVersionId = fileIdToVersion[fileId];
|
|
393
|
-
if (manifest.versions[previousVersionId]) {
|
|
394
|
-
const previousAssets = manifest.versions[previousVersionId].assets;
|
|
395
|
-
const assetIndex = previousAssets.findIndex((a) => extractFileId(a) === fileId);
|
|
396
|
-
if (assetIndex !== -1) {
|
|
397
|
-
previousAssets.splice(assetIndex, 1);
|
|
398
|
-
const oldStorageKey = `${previousVersionId}/${asset}`;
|
|
399
|
-
await storage.removeItem(oldStorageKey).catch((error) => {
|
|
400
|
-
if (options.debug) {
|
|
401
|
-
logger.warn(`Failed to remove duplicate asset ${oldStorageKey}:`, error);
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
if (fileId) {
|
|
408
|
-
fileIdToVersion[fileId] = buildId;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
await setVersionManifest(manifest, storage);
|
|
413
|
-
}
|
|
414
|
-
async function listExistingVersions() {
|
|
415
|
-
const manifest = await getVersionManifest(storage);
|
|
416
|
-
if (!manifest) {
|
|
417
|
-
return [];
|
|
418
|
-
}
|
|
419
|
-
return Object.entries(manifest.versions).map(([id, data]) => ({
|
|
420
|
-
id,
|
|
421
|
-
createdAt: new Date(data.timestamp).getTime()
|
|
422
|
-
}));
|
|
423
|
-
}
|
|
424
|
-
async function restoreOldAssetsToPublic(currentBuildId, outputDir, currentAssets = [], isExistingVersion = false) {
|
|
425
|
-
const manifest = await getVersionManifest(storage);
|
|
426
|
-
if (!manifest || !manifest.versions) {
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
if (isExistingVersion) {
|
|
430
|
-
if (options.debug) {
|
|
431
|
-
logger.info(`Build ID ${currentBuildId} already exists, skipping restore`);
|
|
432
|
-
}
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
const publicDir = pathe.join(outputDir, "public");
|
|
436
|
-
const restoredAssets = [];
|
|
437
|
-
const currentAssetsSet = new Set(currentAssets);
|
|
438
|
-
const currentFileIds = /* @__PURE__ */ new Set();
|
|
439
|
-
for (const asset of currentAssets) {
|
|
440
|
-
const fileId = extractFileId(asset);
|
|
441
|
-
if (fileId) {
|
|
442
|
-
currentFileIds.add(fileId);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
const now = Date.now();
|
|
446
|
-
for (const [versionId, versionData] of Object.entries(manifest.versions)) {
|
|
447
|
-
if (versionId === currentBuildId) {
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
const assets = versionData.assets;
|
|
451
|
-
for (const asset of assets) {
|
|
452
|
-
if (currentAssetsSet.has(asset)) {
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
const fileId = extractFileId(asset);
|
|
456
|
-
if (fileId && currentFileIds.has(fileId)) {
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
const storageKey = `${versionId}/${asset}`;
|
|
460
|
-
await storage.getItemRaw(storageKey).then(async (assetData) => {
|
|
461
|
-
if (assetData) {
|
|
462
|
-
const targetPath = pathe.join(publicDir, asset);
|
|
463
|
-
await node_fs.promises.mkdir(pathe.dirname(targetPath), { recursive: true });
|
|
464
|
-
let dataToWrite;
|
|
465
|
-
if (Buffer.isBuffer(assetData)) {
|
|
466
|
-
dataToWrite = assetData;
|
|
467
|
-
} else if (typeof assetData === "object" && assetData.type === "Buffer" && Array.isArray(assetData.data)) {
|
|
468
|
-
dataToWrite = Buffer.from(assetData.data);
|
|
469
|
-
} else {
|
|
470
|
-
dataToWrite = Buffer.from(assetData);
|
|
471
|
-
}
|
|
472
|
-
await node_fs.promises.writeFile(targetPath, dataToWrite);
|
|
473
|
-
const versionTimestamp = new Date(versionData.timestamp).getTime();
|
|
474
|
-
const ageMs = now - versionTimestamp;
|
|
475
|
-
const ageMinutes = Math.floor(ageMs / 6e4);
|
|
476
|
-
const ageHours = Math.floor(ageMinutes / 60);
|
|
477
|
-
const ageDays = Math.floor(ageHours / 24);
|
|
478
|
-
let ageStr;
|
|
479
|
-
if (ageDays > 0) {
|
|
480
|
-
ageStr = `${ageDays}d ago`;
|
|
481
|
-
} else if (ageHours > 0) {
|
|
482
|
-
ageStr = `${ageHours}h ago`;
|
|
483
|
-
} else if (ageMinutes > 0) {
|
|
484
|
-
ageStr = `${ageMinutes}m ago`;
|
|
485
|
-
} else {
|
|
486
|
-
ageStr = "just now";
|
|
487
|
-
}
|
|
488
|
-
restoredAssets.push({
|
|
489
|
-
asset,
|
|
490
|
-
size: dataToWrite.byteLength,
|
|
491
|
-
versionId,
|
|
492
|
-
age: ageStr
|
|
493
|
-
});
|
|
494
|
-
}
|
|
495
|
-
}).catch((error) => {
|
|
496
|
-
if (options.debug) {
|
|
497
|
-
logger.warn(`Failed to restore asset ${asset} from version ${versionId}:`, error);
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
if (restoredAssets.length > 0) {
|
|
503
|
-
restoredAssets.forEach((item, index) => {
|
|
504
|
-
const isLast = index === restoredAssets.length - 1;
|
|
505
|
-
const prefix = isLast ? " \u2514\u2500" : " \u251C\u2500";
|
|
506
|
-
const sizeKB = (item.size / 1024).toFixed(2);
|
|
507
|
-
const displayPath = `public/${item.asset}`;
|
|
508
|
-
const sizeInfo = `(${sizeKB} kB)`;
|
|
509
|
-
const versionInfo = `[${item.versionId.slice(0, 8)}]`;
|
|
510
|
-
const ageInfo = `(${item.age})`;
|
|
511
|
-
logger.log(utils.colors.gray(`${prefix} ${displayPath} ${sizeInfo} ${versionInfo} ${ageInfo}`));
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
async function augmentBuildMetadata(buildId, outputDir) {
|
|
516
|
-
const manifest = await getVersionManifest(storage);
|
|
517
|
-
const latestPath = pathe.join(outputDir, "public", "_nuxt", "builds", "latest.json");
|
|
518
|
-
try {
|
|
519
|
-
const latestData = await node_fs.promises.readFile(latestPath, "utf-8");
|
|
520
|
-
const latestJson = JSON.parse(latestData);
|
|
521
|
-
latestJson.skewProtection = {
|
|
522
|
-
versions: manifest.versions
|
|
523
|
-
};
|
|
524
|
-
await node_fs.promises.writeFile(latestPath, JSON.stringify(latestJson, null, 2), "utf-8");
|
|
525
|
-
} catch (error) {
|
|
526
|
-
if (options.debug) {
|
|
527
|
-
logger.warn("Failed to augment builds/latest.json:", error);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
const metaPath = pathe.join(outputDir, "public", "_nuxt", "builds", "meta", `${buildId}.json`);
|
|
531
|
-
try {
|
|
532
|
-
const metaData = await node_fs.promises.readFile(metaPath, "utf-8");
|
|
533
|
-
const metaJson = JSON.parse(metaData);
|
|
534
|
-
const versionData = manifest.versions[buildId];
|
|
535
|
-
if (versionData) {
|
|
536
|
-
metaJson.skewProtection = {
|
|
537
|
-
assets: versionData.assets,
|
|
538
|
-
deletedChunks: versionData.deletedChunks,
|
|
539
|
-
timestamp: versionData.timestamp,
|
|
540
|
-
expires: versionData.expires
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
await node_fs.promises.writeFile(metaPath, JSON.stringify(metaJson, null, 2), "utf-8");
|
|
544
|
-
} catch (error) {
|
|
545
|
-
if (options.debug) {
|
|
546
|
-
logger.warn(`Failed to augment builds/meta/${buildId}.json:`, error);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return {
|
|
551
|
-
getAssetsFromBuild,
|
|
552
|
-
updateVersionsManifest,
|
|
553
|
-
cleanupExpiredVersions,
|
|
554
|
-
storeAssetsInStorage,
|
|
555
|
-
listExistingVersions,
|
|
556
|
-
restoreOldAssetsToPublic,
|
|
557
|
-
augmentBuildMetadata,
|
|
558
|
-
getManifest: () => getVersionManifest(storage)
|
|
559
|
-
};
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
const module$1 = kit.defineNuxtModule({
|
|
563
|
-
meta: {
|
|
564
|
-
name: "nuxt-skew-protection",
|
|
565
|
-
compatibility: {
|
|
566
|
-
nuxt: ">=4.0.0"
|
|
567
|
-
},
|
|
568
|
-
configKey: "skewProtection"
|
|
569
|
-
},
|
|
570
|
-
defaults: {
|
|
571
|
-
retentionDays: 30,
|
|
572
|
-
maxNumberOfVersions: 10,
|
|
573
|
-
bundlePreviousDeploymentChunks: true,
|
|
574
|
-
cookie: {
|
|
575
|
-
name: "__nkpv",
|
|
576
|
-
path: "/",
|
|
577
|
-
sameSite: "strict",
|
|
578
|
-
maxAge: 60 * 60 * 24 * 60
|
|
579
|
-
// 60 days
|
|
580
|
-
},
|
|
581
|
-
storage: {
|
|
582
|
-
driver: "fs",
|
|
583
|
-
base: "node_modules/.cache/nuxt/skew-protection"
|
|
584
|
-
},
|
|
585
|
-
debug: false
|
|
586
|
-
},
|
|
587
|
-
async setup(options, nuxt) {
|
|
588
|
-
const resolver = kit.createResolver((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('module.cjs', document.baseURI).href)));
|
|
589
|
-
logger.level = options.debug || nuxt.options.debug ? 4 : 3;
|
|
590
|
-
if (options.enabled === false) {
|
|
591
|
-
logger.debug("The module is disabled, skipping setup.");
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
nuxt.options.runtimeConfig.public = nuxt.options.runtimeConfig.public || {};
|
|
595
|
-
nuxt.options.runtimeConfig.public.skewProtection = {
|
|
596
|
-
cookie: options.cookie,
|
|
597
|
-
debug: options.debug
|
|
598
|
-
};
|
|
599
|
-
const nitroPreset = nuxt.options.nitro?.preset || resolveNitroPreset(nuxt.options.nitro);
|
|
600
|
-
kit.addTypeTemplate({
|
|
601
|
-
filename: "types/nuxt-skew-protection.d.ts",
|
|
602
|
-
getContents: () => {
|
|
603
|
-
return `// Generated by nuxt-skew-protection
|
|
604
|
-
declare module '#app' {
|
|
605
|
-
interface NuxtAppManifestMeta {
|
|
606
|
-
skewProtection?: {
|
|
607
|
-
versions?: Record<string, {
|
|
608
|
-
timestamp: string
|
|
609
|
-
expires: string
|
|
610
|
-
assets: string[]
|
|
611
|
-
deletedChunks?: string[]
|
|
612
|
-
}>
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
declare module 'nuxt/app' {
|
|
618
|
-
interface NuxtAppManifestMeta {
|
|
619
|
-
skewProtection?: {
|
|
620
|
-
versions?: Record<string, {
|
|
621
|
-
timestamp: string
|
|
622
|
-
expires: string
|
|
623
|
-
assets: string[]
|
|
624
|
-
deletedChunks?: string[]
|
|
625
|
-
}>
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
export {}
|
|
631
|
-
`;
|
|
632
|
-
}
|
|
633
|
-
}, {
|
|
634
|
-
nuxt: true
|
|
635
|
-
});
|
|
636
|
-
kit.addComponent({
|
|
637
|
-
name: "SkewNotification",
|
|
638
|
-
filePath: resolver.resolve(`./runtime/app/components/SkewNotification.vue`)
|
|
639
|
-
});
|
|
640
|
-
kit.addImports({
|
|
641
|
-
name: "useSkewProtection",
|
|
642
|
-
from: resolver.resolve("./runtime/app/composables/useSkewProtection")
|
|
643
|
-
});
|
|
644
|
-
nuxt.options.alias["nuxt-skew-protection/server"] = resolver.resolve("./runtime/server");
|
|
645
|
-
if (options.storage?.driver) {
|
|
646
|
-
nuxt.options.nitro = nuxt.options.nitro || {};
|
|
647
|
-
nuxt.options.nitro.storage = nuxt.options.nitro.storage || {};
|
|
648
|
-
nuxt.options.nitro.storage["skew-protection"] = options.storage;
|
|
649
|
-
}
|
|
650
|
-
if (!nuxt.options.dev) {
|
|
651
|
-
const isCloudflareRuntime = nitroPreset?.includes("cloudflare");
|
|
652
|
-
const isVercel = nitroPreset?.includes("vercel") || process.env.VERCEL_SKEW_PROTECTION_ENABLED === "1";
|
|
653
|
-
if (!options.checkForUpdateStrategy) {
|
|
654
|
-
options.checkForUpdateStrategy = isStaticPreset(nuxt) ? "polling" : isCloudflareRuntime ? "ws" : options.checkForUpdateStrategy || "sse";
|
|
655
|
-
}
|
|
656
|
-
if (isVercel) {
|
|
657
|
-
kit.addServerHandler({
|
|
658
|
-
handler: resolver.resolve("./runtime/server/middleware/vercel-skew"),
|
|
659
|
-
middleware: true
|
|
660
|
-
});
|
|
661
|
-
}
|
|
662
|
-
if (options.cookie !== false) {
|
|
663
|
-
kit.addServerHandler({
|
|
664
|
-
handler: resolver.resolve("./runtime/server/middleware/set-skew-protection-cookie"),
|
|
665
|
-
middleware: true
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
kit.addPlugin({
|
|
669
|
-
src: resolver.resolve("./runtime/app/plugins/sw-track-user-modules.client"),
|
|
670
|
-
mode: "client"
|
|
671
|
-
});
|
|
672
|
-
let swPath = resolver.resolve("./sw");
|
|
673
|
-
if (!node_fs.existsSync(swPath)) {
|
|
674
|
-
swPath = resolver.resolve("../sw");
|
|
675
|
-
}
|
|
676
|
-
nuxt.options.nitro = nuxt.options.nitro || {};
|
|
677
|
-
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [];
|
|
678
|
-
nuxt.options.nitro.publicAssets.push({
|
|
679
|
-
dir: swPath,
|
|
680
|
-
maxAge: 0
|
|
681
|
-
// Service workers should not be cached
|
|
682
|
-
});
|
|
683
|
-
if (options.storage && options.bundlePreviousDeploymentChunks) {
|
|
684
|
-
nuxt.hook("nitro:init", (nitro) => {
|
|
685
|
-
const buildId = nuxt.options.runtimeConfig.app.buildId ||= nuxt.options.buildId;
|
|
686
|
-
let assetManager;
|
|
687
|
-
nitro.hooks.hook("compiled", async () => {
|
|
688
|
-
const outputDir = nitro.options.output.dir;
|
|
689
|
-
assetManager = createAssetManager({
|
|
690
|
-
...options,
|
|
691
|
-
driver: await resolveBuildTimeDriver(options.storage)
|
|
692
|
-
});
|
|
693
|
-
const assets = await assetManager.getAssetsFromBuild(outputDir);
|
|
694
|
-
const { isExistingVersion } = await assetManager.updateVersionsManifest(buildId, assets);
|
|
695
|
-
logger.log(`Storing ${assets.length} assets in storage...`);
|
|
696
|
-
await assetManager.storeAssetsInStorage(buildId, outputDir, assets);
|
|
697
|
-
const existingVersions = await assetManager.listExistingVersions();
|
|
698
|
-
const versionCount = existingVersions.filter((v) => v.id !== buildId).length;
|
|
699
|
-
if (versionCount > 0) {
|
|
700
|
-
const manifest = await assetManager.getManifest();
|
|
701
|
-
let totalAssets = 0;
|
|
702
|
-
const versionSizes = [];
|
|
703
|
-
for (const [vId, vData] of Object.entries(manifest.versions)) {
|
|
704
|
-
if (vId !== buildId) {
|
|
705
|
-
totalAssets += vData.assets.length;
|
|
706
|
-
versionSizes.push(`${vId.slice(0, 8)}:${vData.assets.length}`);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
logger.log(`Restoring build files from ${versionCount} release${versionCount > 1 ? "s" : ""} (${totalAssets} assets) [${versionSizes.join(", ")}]...`);
|
|
710
|
-
}
|
|
711
|
-
await assetManager.restoreOldAssetsToPublic(buildId, outputDir, assets, isExistingVersion);
|
|
712
|
-
await assetManager.augmentBuildMetadata(buildId, outputDir);
|
|
713
|
-
});
|
|
714
|
-
nitro.hooks.hook("close", async () => {
|
|
715
|
-
if (assetManager) {
|
|
716
|
-
await assetManager.cleanupExpiredVersions();
|
|
717
|
-
}
|
|
718
|
-
});
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
if (options.checkForUpdateStrategy === "ws") {
|
|
722
|
-
if (!nuxt.options.nitro?.experimental?.websocket) {
|
|
723
|
-
logger.warn("You need to enable `experimental.websocket` in your Nitro config to use WebSockets. Falling back to polling.");
|
|
724
|
-
options.checkForUpdateStrategy = "polling";
|
|
725
|
-
} else if (isCloudflareRuntime && nitroPreset !== "cloudflare-durable") {
|
|
726
|
-
logger.warn("Websockets are only supported in Cloudflare using `cloudflare-durable` preset. Falling back to polling.");
|
|
727
|
-
options.checkForUpdateStrategy = "polling";
|
|
728
|
-
} else {
|
|
729
|
-
kit.addServerHandler({
|
|
730
|
-
route: "/_skew/ws",
|
|
731
|
-
handler: resolver.resolve(`./runtime/server/routes/_skew/ws`)
|
|
732
|
-
});
|
|
733
|
-
kit.addPlugin(resolver.resolve("./runtime/app/plugins/check-updates-websocket.client"));
|
|
734
|
-
}
|
|
735
|
-
} else if (options.checkForUpdateStrategy === "sse") {
|
|
736
|
-
if (isStaticPreset(nuxt) || isCloudflareRuntime) {
|
|
737
|
-
logger.warn("SSE not supported for static sites or Cloudflare Workers. Falling back to polling.");
|
|
738
|
-
options.checkForUpdateStrategy = "polling";
|
|
739
|
-
} else if (isCloudflareRuntime) {
|
|
740
|
-
logger.warn("SSE not supported on Cloudflare Workers (no persistent connections). Falling back to polling.");
|
|
741
|
-
options.checkForUpdateStrategy = "polling";
|
|
742
|
-
} else {
|
|
743
|
-
kit.addServerHandler({
|
|
744
|
-
route: "/_skew/sse",
|
|
745
|
-
handler: resolver.resolve("./runtime/server/routes/_skew/sse")
|
|
746
|
-
});
|
|
747
|
-
kit.addPlugin({
|
|
748
|
-
src: resolver.resolve("./runtime/app/plugins/check-updates-sse.client"),
|
|
749
|
-
mode: "client"
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
});
|
|
756
|
-
|
|
757
|
-
module.exports = module$1;
|
package/dist/module.d.cts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { CookieSerializeOptions } from 'cookie-es';
|
|
3
|
-
import { NuxtSkewProtectionRuntimeConfig } from '/home/runner/work/nuxt-skew-protection/nuxt-skew-protection/dist/runtime/types.js';
|
|
4
|
-
|
|
5
|
-
interface ModuleOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Storage configuration for versioned assets
|
|
8
|
-
*/
|
|
9
|
-
storage?: (Record<string, any> & {
|
|
10
|
-
driver: string;
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* How long to retain old versions (in days)
|
|
14
|
-
* @default 30
|
|
15
|
-
*/
|
|
16
|
-
retentionDays?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Maximum number of versions to retain
|
|
19
|
-
* @default 10
|
|
20
|
-
*/
|
|
21
|
-
maxNumberOfVersions?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Strategy for checking for version updates
|
|
24
|
-
* - 'polling': Nuxt's native polling of builds/latest.json (default)
|
|
25
|
-
* - 'sse': Use Server-Sent Events for real-time updates (requires sse: true)
|
|
26
|
-
* - 'ws': Use WebSocket via Cloudflare Durable Objects (requires durableObjects: true)
|
|
27
|
-
* @default Static: 'polling', Node: 'sse', Cloudflare: 'ws'
|
|
28
|
-
*/
|
|
29
|
-
checkForUpdateStrategy: 'polling' | 'sse' | 'ws';
|
|
30
|
-
/**
|
|
31
|
-
* Cookie configuration for storing deployment version
|
|
32
|
-
*/
|
|
33
|
-
cookie?: false | Omit<CookieSerializeOptions, 'encode'> & {
|
|
34
|
-
/**
|
|
35
|
-
* Cookie name for storing deployment version
|
|
36
|
-
* @default '__nkpv'
|
|
37
|
-
*/
|
|
38
|
-
name?: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Bundle previous deployment chunks to support users on old versions
|
|
42
|
-
* When enabled, old build assets are stored and served to users who haven't refreshed
|
|
43
|
-
* @default true
|
|
44
|
-
* @note Automatically disabled when using CDN URL
|
|
45
|
-
*/
|
|
46
|
-
bundlePreviousDeploymentChunks?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Enable or disable the module
|
|
49
|
-
* @default true
|
|
50
|
-
*/
|
|
51
|
-
enabled: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Enable debug logging
|
|
54
|
-
* @default false
|
|
55
|
-
*/
|
|
56
|
-
debug?: boolean;
|
|
57
|
-
}
|
|
58
|
-
interface ModulePublicRuntimeConfig {
|
|
59
|
-
skewProtection: NuxtSkewProtectionRuntimeConfig;
|
|
60
|
-
}
|
|
61
|
-
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
62
|
-
|
|
63
|
-
export = _default;
|
|
64
|
-
export type { ModuleOptions, ModulePublicRuntimeConfig };
|
package/dist/module.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
import { CookieSerializeOptions } from 'cookie-es';
|
|
3
|
-
import { NuxtSkewProtectionRuntimeConfig } from '/home/runner/work/nuxt-skew-protection/nuxt-skew-protection/dist/runtime/types.js';
|
|
4
|
-
|
|
5
|
-
interface ModuleOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Storage configuration for versioned assets
|
|
8
|
-
*/
|
|
9
|
-
storage?: (Record<string, any> & {
|
|
10
|
-
driver: string;
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* How long to retain old versions (in days)
|
|
14
|
-
* @default 30
|
|
15
|
-
*/
|
|
16
|
-
retentionDays?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Maximum number of versions to retain
|
|
19
|
-
* @default 10
|
|
20
|
-
*/
|
|
21
|
-
maxNumberOfVersions?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Strategy for checking for version updates
|
|
24
|
-
* - 'polling': Nuxt's native polling of builds/latest.json (default)
|
|
25
|
-
* - 'sse': Use Server-Sent Events for real-time updates (requires sse: true)
|
|
26
|
-
* - 'ws': Use WebSocket via Cloudflare Durable Objects (requires durableObjects: true)
|
|
27
|
-
* @default Static: 'polling', Node: 'sse', Cloudflare: 'ws'
|
|
28
|
-
*/
|
|
29
|
-
checkForUpdateStrategy: 'polling' | 'sse' | 'ws';
|
|
30
|
-
/**
|
|
31
|
-
* Cookie configuration for storing deployment version
|
|
32
|
-
*/
|
|
33
|
-
cookie?: false | Omit<CookieSerializeOptions, 'encode'> & {
|
|
34
|
-
/**
|
|
35
|
-
* Cookie name for storing deployment version
|
|
36
|
-
* @default '__nkpv'
|
|
37
|
-
*/
|
|
38
|
-
name?: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Bundle previous deployment chunks to support users on old versions
|
|
42
|
-
* When enabled, old build assets are stored and served to users who haven't refreshed
|
|
43
|
-
* @default true
|
|
44
|
-
* @note Automatically disabled when using CDN URL
|
|
45
|
-
*/
|
|
46
|
-
bundlePreviousDeploymentChunks?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Enable or disable the module
|
|
49
|
-
* @default true
|
|
50
|
-
*/
|
|
51
|
-
enabled: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Enable debug logging
|
|
54
|
-
* @default false
|
|
55
|
-
*/
|
|
56
|
-
debug?: boolean;
|
|
57
|
-
}
|
|
58
|
-
interface ModulePublicRuntimeConfig {
|
|
59
|
-
skewProtection: NuxtSkewProtectionRuntimeConfig;
|
|
60
|
-
}
|
|
61
|
-
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
62
|
-
|
|
63
|
-
export = _default;
|
|
64
|
-
export type { ModuleOptions, ModulePublicRuntimeConfig };
|