nuxt-skew-protection 0.1.2 → 0.1.3
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.cjs +2 -160
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -161
- package/dist/runtime/app/components/SkewNotification.d.vue.ts +2 -3
- package/dist/runtime/app/components/SkewNotification.vue +13 -14
- package/dist/runtime/app/components/SkewNotification.vue.d.ts +2 -3
- package/dist/runtime/app/composables/useSkewProtection.d.ts +2 -1
- package/dist/runtime/app/composables/useSkewProtection.js +11 -2
- package/dist/runtime/app/plugins/sw-track-user-modules.client.js +1 -1
- package/package.json +8 -8
package/dist/module.cjs
CHANGED
|
@@ -47,91 +47,6 @@ function resolveNitroPreset(nitroConfig) {
|
|
|
47
47
|
|
|
48
48
|
const logger = kit.useLogger("nuxt-skew-protection");
|
|
49
49
|
|
|
50
|
-
const awsS3CLIDriver = unstorage.defineDriver((opts) => {
|
|
51
|
-
const { bucket, prefix = "", region, profile } = opts;
|
|
52
|
-
if (!bucket) {
|
|
53
|
-
throw new Error("[aws-s3-cli] bucket is required");
|
|
54
|
-
}
|
|
55
|
-
function buildCommand(subcommand) {
|
|
56
|
-
const regionFlag = region ? `--region ${region}` : "";
|
|
57
|
-
const profileFlag = profile ? `--profile ${profile}` : "";
|
|
58
|
-
return `aws s3api ${subcommand} ${regionFlag} ${profileFlag}`.trim();
|
|
59
|
-
}
|
|
60
|
-
function getKey(key) {
|
|
61
|
-
return prefix ? `${prefix}${key}` : key;
|
|
62
|
-
}
|
|
63
|
-
async function execAWS(subcommand) {
|
|
64
|
-
const command = buildCommand(subcommand);
|
|
65
|
-
const result = await tinyexec.x("sh", ["-c", command], {
|
|
66
|
-
throwOnError: true
|
|
67
|
-
});
|
|
68
|
-
return result.stdout.trim();
|
|
69
|
-
}
|
|
70
|
-
const driver = {
|
|
71
|
-
name: "aws-s3-cli",
|
|
72
|
-
options: opts,
|
|
73
|
-
async hasItem(key) {
|
|
74
|
-
await execAWS(`head-object --bucket "${bucket}" --key "${getKey(key)}"`);
|
|
75
|
-
return true;
|
|
76
|
-
},
|
|
77
|
-
async getItem(key) {
|
|
78
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `s3-get-${Date.now()}.json`);
|
|
79
|
-
await execAWS(`get-object --bucket "${bucket}" --key "${getKey(key)}" "${tmpFile}"`);
|
|
80
|
-
const content = node_fs.readFileSync(tmpFile, "utf-8");
|
|
81
|
-
const result = JSON.parse(content);
|
|
82
|
-
node_fs.unlinkSync(tmpFile);
|
|
83
|
-
return result;
|
|
84
|
-
},
|
|
85
|
-
async getItemRaw(key) {
|
|
86
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `s3-get-${Date.now()}.bin`);
|
|
87
|
-
await execAWS(`get-object --bucket "${bucket}" --key "${getKey(key)}" "${tmpFile}"`);
|
|
88
|
-
const result = node_fs.readFileSync(tmpFile);
|
|
89
|
-
node_fs.unlinkSync(tmpFile);
|
|
90
|
-
return result;
|
|
91
|
-
},
|
|
92
|
-
async setItem(key, value) {
|
|
93
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `s3-put-${Date.now()}.json`);
|
|
94
|
-
node_fs.writeFileSync(tmpFile, JSON.stringify(value));
|
|
95
|
-
await execAWS(`put-object --bucket "${bucket}" --key "${getKey(key)}" --body "${tmpFile}"`);
|
|
96
|
-
node_fs.unlinkSync(tmpFile);
|
|
97
|
-
},
|
|
98
|
-
async setItemRaw(key, value) {
|
|
99
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `s3-put-${Date.now()}.bin`);
|
|
100
|
-
node_fs.writeFileSync(tmpFile, value);
|
|
101
|
-
await execAWS(`put-object --bucket "${bucket}" --key "${getKey(key)}" --body "${tmpFile}"`);
|
|
102
|
-
node_fs.unlinkSync(tmpFile);
|
|
103
|
-
},
|
|
104
|
-
async removeItem(key) {
|
|
105
|
-
await execAWS(`delete-object --bucket "${bucket}" --key "${getKey(key)}"`);
|
|
106
|
-
},
|
|
107
|
-
async getKeys(base) {
|
|
108
|
-
const searchPrefix = base ? getKey(base) : prefix;
|
|
109
|
-
const prefixFlag = searchPrefix ? `--prefix "${searchPrefix}"` : "";
|
|
110
|
-
const result = await execAWS(`list-objects-v2 --bucket "${bucket}" ${prefixFlag}`);
|
|
111
|
-
const data = JSON.parse(result);
|
|
112
|
-
if (!data.Contents || !Array.isArray(data.Contents)) {
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
115
|
-
return data.Contents.map((item) => {
|
|
116
|
-
let key = item.Key;
|
|
117
|
-
if (prefix && key.startsWith(prefix)) {
|
|
118
|
-
key = key.slice(prefix.length);
|
|
119
|
-
}
|
|
120
|
-
return key;
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
async clear(base) {
|
|
124
|
-
const keys = await driver.getKeys(base);
|
|
125
|
-
for (const key of keys) {
|
|
126
|
-
await driver.removeItem(key);
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
async dispose() {
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
return driver;
|
|
133
|
-
});
|
|
134
|
-
|
|
135
50
|
const cloudflareKVWranglerDriver = unstorage.defineDriver((opts) => {
|
|
136
51
|
const { namespaceId, local = false } = opts;
|
|
137
52
|
if (!namespaceId) {
|
|
@@ -204,70 +119,6 @@ stderr: ${result.stderr}`
|
|
|
204
119
|
return driver;
|
|
205
120
|
});
|
|
206
121
|
|
|
207
|
-
const netlifyBlobsCLIDriver = unstorage.defineDriver((opts) => {
|
|
208
|
-
const { siteId, storeName = "production" } = opts;
|
|
209
|
-
function buildCommand(subcommand) {
|
|
210
|
-
const siteFlag = siteId ? `--site ${siteId}` : "";
|
|
211
|
-
return `netlify blobs:${subcommand} ${siteFlag}`.trim();
|
|
212
|
-
}
|
|
213
|
-
async function execNetlify(subcommand) {
|
|
214
|
-
const command = buildCommand(subcommand);
|
|
215
|
-
const result = await tinyexec.x("sh", ["-c", command], {
|
|
216
|
-
throwOnError: true
|
|
217
|
-
});
|
|
218
|
-
return result.stdout.trim();
|
|
219
|
-
}
|
|
220
|
-
const driver = {
|
|
221
|
-
name: "netlify-blobs-cli",
|
|
222
|
-
options: opts,
|
|
223
|
-
async hasItem(key) {
|
|
224
|
-
await execNetlify(`get "${key}" --store "${storeName}"`);
|
|
225
|
-
return true;
|
|
226
|
-
},
|
|
227
|
-
async getItem(key) {
|
|
228
|
-
const result = await execNetlify(`get "${key}" --store "${storeName}"`);
|
|
229
|
-
return JSON.parse(result);
|
|
230
|
-
},
|
|
231
|
-
async getItemRaw(key) {
|
|
232
|
-
const result = await execNetlify(`get "${key}" --store "${storeName}"`);
|
|
233
|
-
return Buffer.from(result, "utf-8");
|
|
234
|
-
},
|
|
235
|
-
async setItem(key, value) {
|
|
236
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `netlify-blob-${Date.now()}.json`);
|
|
237
|
-
node_fs.writeFileSync(tmpFile, JSON.stringify(value));
|
|
238
|
-
await execNetlify(`set "${key}" "${tmpFile}" --store "${storeName}"`);
|
|
239
|
-
node_fs.unlinkSync(tmpFile);
|
|
240
|
-
},
|
|
241
|
-
async setItemRaw(key, value) {
|
|
242
|
-
const tmpFile = node_path.join(node_os.tmpdir(), `netlify-blob-${Date.now()}.bin`);
|
|
243
|
-
node_fs.writeFileSync(tmpFile, value);
|
|
244
|
-
await execNetlify(`set "${key}" "${tmpFile}" --store "${storeName}"`);
|
|
245
|
-
node_fs.unlinkSync(tmpFile);
|
|
246
|
-
},
|
|
247
|
-
async removeItem(key) {
|
|
248
|
-
await execNetlify(`delete "${key}" --store "${storeName}"`);
|
|
249
|
-
},
|
|
250
|
-
async getKeys(base) {
|
|
251
|
-
const prefix = base || "";
|
|
252
|
-
const result = await execNetlify(`list --store "${storeName}" --prefix "${prefix}" --json`);
|
|
253
|
-
const blobs = JSON.parse(result);
|
|
254
|
-
if (Array.isArray(blobs)) {
|
|
255
|
-
return blobs.map((blob) => blob.key || blob);
|
|
256
|
-
}
|
|
257
|
-
return [];
|
|
258
|
-
},
|
|
259
|
-
async clear(base) {
|
|
260
|
-
const keys = await driver.getKeys(base);
|
|
261
|
-
for (const key of keys) {
|
|
262
|
-
await driver.removeItem(key);
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
async dispose() {
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
return driver;
|
|
269
|
-
});
|
|
270
|
-
|
|
271
122
|
const vercelKVCLIDriver = unstorage.defineDriver((opts) => {
|
|
272
123
|
const { storeName, teamId } = opts;
|
|
273
124
|
if (!storeName) {
|
|
@@ -361,13 +212,6 @@ async function resolveBuildTimeDriver(storage) {
|
|
|
361
212
|
case "vercel-kv": {
|
|
362
213
|
return vercelKVCLIDriver(driverOptions);
|
|
363
214
|
}
|
|
364
|
-
case "s3":
|
|
365
|
-
case "aws-s3": {
|
|
366
|
-
return awsS3CLIDriver(driverOptions);
|
|
367
|
-
}
|
|
368
|
-
case "netlify-blobs": {
|
|
369
|
-
return netlifyBlobsCLIDriver(driverOptions);
|
|
370
|
-
}
|
|
371
215
|
}
|
|
372
216
|
const lazyDriver = await import(`unstorage/drivers/${storage.driver}`).then((m) => m.default);
|
|
373
217
|
return lazyDriver(driverOptions);
|
|
@@ -828,8 +672,9 @@ export {}
|
|
|
828
672
|
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [];
|
|
829
673
|
nuxt.options.nitro.publicAssets.push({
|
|
830
674
|
dir: swPath,
|
|
831
|
-
maxAge: 0
|
|
675
|
+
maxAge: 0,
|
|
832
676
|
// Service workers should not be cached
|
|
677
|
+
baseURL: "/_skew"
|
|
833
678
|
});
|
|
834
679
|
if (options.storage && options.bundlePreviousDeploymentChunks) {
|
|
835
680
|
nuxt.hook("nitro:build:public-assets", async (nitro) => {
|
|
@@ -884,9 +729,6 @@ export {}
|
|
|
884
729
|
});
|
|
885
730
|
}
|
|
886
731
|
}
|
|
887
|
-
if (options.checkForUpdateStrategy === "polling") {
|
|
888
|
-
nuxt.options.experimental.checkOutdatedBuildInterval = 20;
|
|
889
|
-
}
|
|
890
732
|
}
|
|
891
733
|
}
|
|
892
734
|
});
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeFileSync, unlinkSync,
|
|
1
|
+
import { writeFileSync, unlinkSync, existsSync, readFileSync, promises } from 'node:fs';
|
|
2
2
|
import { useNuxt, tryUseNuxt, useLogger, defineNuxtModule, createResolver, addTypeTemplate, addComponent, addPlugin, addImports, addServerHandler } from '@nuxt/kit';
|
|
3
3
|
import { provider, env } from 'std-env';
|
|
4
4
|
import { join } from 'node:path';
|
|
@@ -44,91 +44,6 @@ function resolveNitroPreset(nitroConfig) {
|
|
|
44
44
|
|
|
45
45
|
const logger = useLogger("nuxt-skew-protection");
|
|
46
46
|
|
|
47
|
-
const awsS3CLIDriver = defineDriver((opts) => {
|
|
48
|
-
const { bucket, prefix = "", region, profile } = opts;
|
|
49
|
-
if (!bucket) {
|
|
50
|
-
throw new Error("[aws-s3-cli] bucket is required");
|
|
51
|
-
}
|
|
52
|
-
function buildCommand(subcommand) {
|
|
53
|
-
const regionFlag = region ? `--region ${region}` : "";
|
|
54
|
-
const profileFlag = profile ? `--profile ${profile}` : "";
|
|
55
|
-
return `aws s3api ${subcommand} ${regionFlag} ${profileFlag}`.trim();
|
|
56
|
-
}
|
|
57
|
-
function getKey(key) {
|
|
58
|
-
return prefix ? `${prefix}${key}` : key;
|
|
59
|
-
}
|
|
60
|
-
async function execAWS(subcommand) {
|
|
61
|
-
const command = buildCommand(subcommand);
|
|
62
|
-
const result = await x("sh", ["-c", command], {
|
|
63
|
-
throwOnError: true
|
|
64
|
-
});
|
|
65
|
-
return result.stdout.trim();
|
|
66
|
-
}
|
|
67
|
-
const driver = {
|
|
68
|
-
name: "aws-s3-cli",
|
|
69
|
-
options: opts,
|
|
70
|
-
async hasItem(key) {
|
|
71
|
-
await execAWS(`head-object --bucket "${bucket}" --key "${getKey(key)}"`);
|
|
72
|
-
return true;
|
|
73
|
-
},
|
|
74
|
-
async getItem(key) {
|
|
75
|
-
const tmpFile = join(tmpdir(), `s3-get-${Date.now()}.json`);
|
|
76
|
-
await execAWS(`get-object --bucket "${bucket}" --key "${getKey(key)}" "${tmpFile}"`);
|
|
77
|
-
const content = readFileSync(tmpFile, "utf-8");
|
|
78
|
-
const result = JSON.parse(content);
|
|
79
|
-
unlinkSync(tmpFile);
|
|
80
|
-
return result;
|
|
81
|
-
},
|
|
82
|
-
async getItemRaw(key) {
|
|
83
|
-
const tmpFile = join(tmpdir(), `s3-get-${Date.now()}.bin`);
|
|
84
|
-
await execAWS(`get-object --bucket "${bucket}" --key "${getKey(key)}" "${tmpFile}"`);
|
|
85
|
-
const result = readFileSync(tmpFile);
|
|
86
|
-
unlinkSync(tmpFile);
|
|
87
|
-
return result;
|
|
88
|
-
},
|
|
89
|
-
async setItem(key, value) {
|
|
90
|
-
const tmpFile = join(tmpdir(), `s3-put-${Date.now()}.json`);
|
|
91
|
-
writeFileSync(tmpFile, JSON.stringify(value));
|
|
92
|
-
await execAWS(`put-object --bucket "${bucket}" --key "${getKey(key)}" --body "${tmpFile}"`);
|
|
93
|
-
unlinkSync(tmpFile);
|
|
94
|
-
},
|
|
95
|
-
async setItemRaw(key, value) {
|
|
96
|
-
const tmpFile = join(tmpdir(), `s3-put-${Date.now()}.bin`);
|
|
97
|
-
writeFileSync(tmpFile, value);
|
|
98
|
-
await execAWS(`put-object --bucket "${bucket}" --key "${getKey(key)}" --body "${tmpFile}"`);
|
|
99
|
-
unlinkSync(tmpFile);
|
|
100
|
-
},
|
|
101
|
-
async removeItem(key) {
|
|
102
|
-
await execAWS(`delete-object --bucket "${bucket}" --key "${getKey(key)}"`);
|
|
103
|
-
},
|
|
104
|
-
async getKeys(base) {
|
|
105
|
-
const searchPrefix = base ? getKey(base) : prefix;
|
|
106
|
-
const prefixFlag = searchPrefix ? `--prefix "${searchPrefix}"` : "";
|
|
107
|
-
const result = await execAWS(`list-objects-v2 --bucket "${bucket}" ${prefixFlag}`);
|
|
108
|
-
const data = JSON.parse(result);
|
|
109
|
-
if (!data.Contents || !Array.isArray(data.Contents)) {
|
|
110
|
-
return [];
|
|
111
|
-
}
|
|
112
|
-
return data.Contents.map((item) => {
|
|
113
|
-
let key = item.Key;
|
|
114
|
-
if (prefix && key.startsWith(prefix)) {
|
|
115
|
-
key = key.slice(prefix.length);
|
|
116
|
-
}
|
|
117
|
-
return key;
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
async clear(base) {
|
|
121
|
-
const keys = await driver.getKeys(base);
|
|
122
|
-
for (const key of keys) {
|
|
123
|
-
await driver.removeItem(key);
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
async dispose() {
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
return driver;
|
|
130
|
-
});
|
|
131
|
-
|
|
132
47
|
const cloudflareKVWranglerDriver = defineDriver((opts) => {
|
|
133
48
|
const { namespaceId, local = false } = opts;
|
|
134
49
|
if (!namespaceId) {
|
|
@@ -201,70 +116,6 @@ stderr: ${result.stderr}`
|
|
|
201
116
|
return driver;
|
|
202
117
|
});
|
|
203
118
|
|
|
204
|
-
const netlifyBlobsCLIDriver = defineDriver((opts) => {
|
|
205
|
-
const { siteId, storeName = "production" } = opts;
|
|
206
|
-
function buildCommand(subcommand) {
|
|
207
|
-
const siteFlag = siteId ? `--site ${siteId}` : "";
|
|
208
|
-
return `netlify blobs:${subcommand} ${siteFlag}`.trim();
|
|
209
|
-
}
|
|
210
|
-
async function execNetlify(subcommand) {
|
|
211
|
-
const command = buildCommand(subcommand);
|
|
212
|
-
const result = await x("sh", ["-c", command], {
|
|
213
|
-
throwOnError: true
|
|
214
|
-
});
|
|
215
|
-
return result.stdout.trim();
|
|
216
|
-
}
|
|
217
|
-
const driver = {
|
|
218
|
-
name: "netlify-blobs-cli",
|
|
219
|
-
options: opts,
|
|
220
|
-
async hasItem(key) {
|
|
221
|
-
await execNetlify(`get "${key}" --store "${storeName}"`);
|
|
222
|
-
return true;
|
|
223
|
-
},
|
|
224
|
-
async getItem(key) {
|
|
225
|
-
const result = await execNetlify(`get "${key}" --store "${storeName}"`);
|
|
226
|
-
return JSON.parse(result);
|
|
227
|
-
},
|
|
228
|
-
async getItemRaw(key) {
|
|
229
|
-
const result = await execNetlify(`get "${key}" --store "${storeName}"`);
|
|
230
|
-
return Buffer.from(result, "utf-8");
|
|
231
|
-
},
|
|
232
|
-
async setItem(key, value) {
|
|
233
|
-
const tmpFile = join(tmpdir(), `netlify-blob-${Date.now()}.json`);
|
|
234
|
-
writeFileSync(tmpFile, JSON.stringify(value));
|
|
235
|
-
await execNetlify(`set "${key}" "${tmpFile}" --store "${storeName}"`);
|
|
236
|
-
unlinkSync(tmpFile);
|
|
237
|
-
},
|
|
238
|
-
async setItemRaw(key, value) {
|
|
239
|
-
const tmpFile = join(tmpdir(), `netlify-blob-${Date.now()}.bin`);
|
|
240
|
-
writeFileSync(tmpFile, value);
|
|
241
|
-
await execNetlify(`set "${key}" "${tmpFile}" --store "${storeName}"`);
|
|
242
|
-
unlinkSync(tmpFile);
|
|
243
|
-
},
|
|
244
|
-
async removeItem(key) {
|
|
245
|
-
await execNetlify(`delete "${key}" --store "${storeName}"`);
|
|
246
|
-
},
|
|
247
|
-
async getKeys(base) {
|
|
248
|
-
const prefix = base || "";
|
|
249
|
-
const result = await execNetlify(`list --store "${storeName}" --prefix "${prefix}" --json`);
|
|
250
|
-
const blobs = JSON.parse(result);
|
|
251
|
-
if (Array.isArray(blobs)) {
|
|
252
|
-
return blobs.map((blob) => blob.key || blob);
|
|
253
|
-
}
|
|
254
|
-
return [];
|
|
255
|
-
},
|
|
256
|
-
async clear(base) {
|
|
257
|
-
const keys = await driver.getKeys(base);
|
|
258
|
-
for (const key of keys) {
|
|
259
|
-
await driver.removeItem(key);
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
|
-
async dispose() {
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
return driver;
|
|
266
|
-
});
|
|
267
|
-
|
|
268
119
|
const vercelKVCLIDriver = defineDriver((opts) => {
|
|
269
120
|
const { storeName, teamId } = opts;
|
|
270
121
|
if (!storeName) {
|
|
@@ -358,13 +209,6 @@ async function resolveBuildTimeDriver(storage) {
|
|
|
358
209
|
case "vercel-kv": {
|
|
359
210
|
return vercelKVCLIDriver(driverOptions);
|
|
360
211
|
}
|
|
361
|
-
case "s3":
|
|
362
|
-
case "aws-s3": {
|
|
363
|
-
return awsS3CLIDriver(driverOptions);
|
|
364
|
-
}
|
|
365
|
-
case "netlify-blobs": {
|
|
366
|
-
return netlifyBlobsCLIDriver(driverOptions);
|
|
367
|
-
}
|
|
368
212
|
}
|
|
369
213
|
const lazyDriver = await import(`unstorage/drivers/${storage.driver}`).then((m) => m.default);
|
|
370
214
|
return lazyDriver(driverOptions);
|
|
@@ -825,8 +669,9 @@ export {}
|
|
|
825
669
|
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [];
|
|
826
670
|
nuxt.options.nitro.publicAssets.push({
|
|
827
671
|
dir: swPath,
|
|
828
|
-
maxAge: 0
|
|
672
|
+
maxAge: 0,
|
|
829
673
|
// Service workers should not be cached
|
|
674
|
+
baseURL: "/_skew"
|
|
830
675
|
});
|
|
831
676
|
if (options.storage && options.bundlePreviousDeploymentChunks) {
|
|
832
677
|
nuxt.hook("nitro:build:public-assets", async (nitro) => {
|
|
@@ -881,9 +726,6 @@ export {}
|
|
|
881
726
|
});
|
|
882
727
|
}
|
|
883
728
|
}
|
|
884
|
-
if (options.checkForUpdateStrategy === "polling") {
|
|
885
|
-
nuxt.options.experimental.checkOutdatedBuildInterval = 20;
|
|
886
|
-
}
|
|
887
729
|
}
|
|
888
730
|
}
|
|
889
731
|
});
|
|
@@ -6,14 +6,13 @@ interface Props {
|
|
|
6
6
|
forceOpen?: boolean;
|
|
7
7
|
}
|
|
8
8
|
declare var __VLS_1: {
|
|
9
|
-
|
|
9
|
+
isCurrentChunksOutdated: any;
|
|
10
10
|
dismiss: any;
|
|
11
11
|
reload: any;
|
|
12
12
|
timeAgo: any;
|
|
13
13
|
releaseDate: any;
|
|
14
|
-
releaseCount: any;
|
|
15
|
-
invalidatedCount: any;
|
|
16
14
|
payload: any;
|
|
15
|
+
isAppOutdated: any;
|
|
17
16
|
};
|
|
18
17
|
type __VLS_Slots = {} & {
|
|
19
18
|
default?: (props: typeof __VLS_1) => any;
|
|
@@ -9,17 +9,25 @@ const props = defineProps({
|
|
|
9
9
|
const emit = defineEmits(["dismiss", "reload", "update:open", "chunksOutdated"]);
|
|
10
10
|
const skewProtection = useSkewProtection();
|
|
11
11
|
const chunksOutdated = ref(false);
|
|
12
|
+
const appOutdated = ref(false);
|
|
12
13
|
const outdatedPayload = ref(null);
|
|
13
|
-
skewProtection.
|
|
14
|
+
skewProtection.onCurrentChunksOutdated((payload) => {
|
|
14
15
|
chunksOutdated.value = true;
|
|
15
16
|
outdatedPayload.value = payload;
|
|
16
|
-
emit("chunksOutdated", payload);
|
|
17
17
|
});
|
|
18
|
-
|
|
18
|
+
skewProtection.onAppOutdated(() => {
|
|
19
|
+
appOutdated.value = true;
|
|
20
|
+
});
|
|
21
|
+
const isCurrentChunksOutdated = computed(() => {
|
|
19
22
|
if (props.forceOpen)
|
|
20
23
|
return true;
|
|
21
24
|
return chunksOutdated.value;
|
|
22
25
|
});
|
|
26
|
+
const isAppOutdated = computed(() => {
|
|
27
|
+
if (props.forceOpen)
|
|
28
|
+
return true;
|
|
29
|
+
return appOutdated.value;
|
|
30
|
+
});
|
|
23
31
|
const releaseDate = computed(() => {
|
|
24
32
|
const timestamp = skewProtection.manifest.value?.timestamp;
|
|
25
33
|
return timestamp ? new Date(timestamp) : /* @__PURE__ */ new Date();
|
|
@@ -27,16 +35,8 @@ const releaseDate = computed(() => {
|
|
|
27
35
|
const timeAgo = useTimeAgo(releaseDate, {
|
|
28
36
|
showSecond: true
|
|
29
37
|
});
|
|
30
|
-
const releaseCount = computed(() => {
|
|
31
|
-
return outdatedPayload.value?.passedReleases.length ?? 0;
|
|
32
|
-
});
|
|
33
|
-
const invalidatedCount = computed(() => {
|
|
34
|
-
return outdatedPayload.value?.invalidatedModules.length ?? 0;
|
|
35
|
-
});
|
|
36
38
|
function handleDismiss() {
|
|
37
39
|
chunksOutdated.value = false;
|
|
38
|
-
outdatedPayload.value = null;
|
|
39
|
-
emit("update:open", false);
|
|
40
40
|
emit("dismiss");
|
|
41
41
|
}
|
|
42
42
|
async function handleReload() {
|
|
@@ -50,13 +50,12 @@ async function handleReload() {
|
|
|
50
50
|
|
|
51
51
|
<template>
|
|
52
52
|
<slot
|
|
53
|
-
:is-
|
|
53
|
+
:is-current-chunks-outdated="isCurrentChunksOutdated"
|
|
54
54
|
:dismiss="handleDismiss"
|
|
55
55
|
:reload="handleReload"
|
|
56
56
|
:time-ago="timeAgo"
|
|
57
57
|
:release-date="releaseDate"
|
|
58
|
-
:release-count="releaseCount"
|
|
59
|
-
:invalidated-count="invalidatedCount"
|
|
60
58
|
:payload="outdatedPayload"
|
|
59
|
+
:is-app-outdated="isAppOutdated"
|
|
61
60
|
/>
|
|
62
61
|
</template>
|
|
@@ -6,14 +6,13 @@ interface Props {
|
|
|
6
6
|
forceOpen?: boolean;
|
|
7
7
|
}
|
|
8
8
|
declare var __VLS_1: {
|
|
9
|
-
|
|
9
|
+
isCurrentChunksOutdated: any;
|
|
10
10
|
dismiss: any;
|
|
11
11
|
reload: any;
|
|
12
12
|
timeAgo: any;
|
|
13
13
|
releaseDate: any;
|
|
14
|
-
releaseCount: any;
|
|
15
|
-
invalidatedCount: any;
|
|
16
14
|
payload: any;
|
|
15
|
+
isAppOutdated: any;
|
|
17
16
|
};
|
|
18
17
|
type __VLS_Slots = {} & {
|
|
19
18
|
default?: (props: typeof __VLS_1) => any;
|
|
@@ -3,7 +3,8 @@ import type { Ref } from 'vue';
|
|
|
3
3
|
import type { ChunksOutdatedPayload } from '../../types.js';
|
|
4
4
|
export declare function useSkewProtection(): {
|
|
5
5
|
cookie: import("#app").CookieRef<any>;
|
|
6
|
-
|
|
6
|
+
onCurrentChunksOutdated: (callback: (payload: ChunksOutdatedPayload) => void | Promise<void>) => () => void;
|
|
7
|
+
onAppOutdated: (callback: (manifest?: NuxtAppManifestMeta) => void | Promise<void>) => void;
|
|
7
8
|
checkForUpdates: () => Promise<void>;
|
|
8
9
|
simulateUpdate(): Promise<void>;
|
|
9
10
|
manifest: Ref<NuxtAppManifestMeta | null>;
|
|
@@ -20,7 +20,7 @@ export function useSkewProtection() {
|
|
|
20
20
|
await nuxtApp.hooks.callHook("app:manifest:update", meta);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function onCurrentChunksOutdated(callback) {
|
|
24
24
|
const hook = nuxtApp.hooks.hook("skew-protection:chunks-outdated", callback);
|
|
25
25
|
onUnmounted(() => {
|
|
26
26
|
if (typeof hook === "function") {
|
|
@@ -29,10 +29,19 @@ export function useSkewProtection() {
|
|
|
29
29
|
});
|
|
30
30
|
return hook;
|
|
31
31
|
}
|
|
32
|
+
function onAppOutdated(callback) {
|
|
33
|
+
const hook = nuxtApp.hooks.hook("app:manifest:update", callback);
|
|
34
|
+
onUnmounted(() => {
|
|
35
|
+
if (typeof hook === "function") {
|
|
36
|
+
hook();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
32
40
|
return {
|
|
33
41
|
...skewProtection,
|
|
34
42
|
cookie,
|
|
35
|
-
|
|
43
|
+
onCurrentChunksOutdated,
|
|
44
|
+
onAppOutdated,
|
|
36
45
|
checkForUpdates,
|
|
37
46
|
async simulateUpdate() {
|
|
38
47
|
if (!import.meta.dev) {
|
|
@@ -18,7 +18,7 @@ export default defineNuxtPlugin({
|
|
|
18
18
|
const skew = useSkewProtection();
|
|
19
19
|
const versionCookie = skew.cookie.value;
|
|
20
20
|
const manifest = ref();
|
|
21
|
-
navigator.serviceWorker.register("/sw.js");
|
|
21
|
+
navigator.serviceWorker.register("/_skew/sw.js");
|
|
22
22
|
function getLoadedModules() {
|
|
23
23
|
return new Promise((resolve) => {
|
|
24
24
|
const messageHandler = (event) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-skew-protection",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "Instantly adopted Nuxt releases with long-lived build assets.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nuxt/kit": "^4.1.
|
|
32
|
+
"@nuxt/kit": "^4.1.3",
|
|
33
33
|
"@nuxtjs/robots": "^5.5.5",
|
|
34
34
|
"consola": "^3.4.2",
|
|
35
35
|
"cookie-es": "^2.0.0",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
"eslint": "^9.37.0",
|
|
65
65
|
"eventsource": "^4.0.0",
|
|
66
66
|
"execa": "^9.6.0",
|
|
67
|
-
"firebase-functions": "^6.
|
|
67
|
+
"firebase-functions": "^6.5.0",
|
|
68
68
|
"happy-dom": "^19.0.2",
|
|
69
|
-
"ioredis": "^5.8.
|
|
70
|
-
"nuxt": "^4.1.
|
|
71
|
-
"playwright-core": "^1.
|
|
69
|
+
"ioredis": "^5.8.1",
|
|
70
|
+
"nuxt": "^4.1.3",
|
|
71
|
+
"playwright-core": "^1.56.0",
|
|
72
72
|
"tsx": "^4.20.6",
|
|
73
73
|
"typescript": "^5.9.3",
|
|
74
74
|
"unocss": "^66.5.2",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"vitest": "^3.2.4",
|
|
77
77
|
"vue": "^3.5.22",
|
|
78
78
|
"vue-router": "^4.5.1",
|
|
79
|
-
"vue-tsc": "^3.1.
|
|
80
|
-
"wrangler": "^4.42.
|
|
79
|
+
"vue-tsc": "^3.1.1",
|
|
80
|
+
"wrangler": "^4.42.1",
|
|
81
81
|
"ws": "^8.18.3"
|
|
82
82
|
},
|
|
83
83
|
"resolutions": {
|