@nuxt/scripts 1.0.0-beta.2 → 1.0.0-beta.4

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.
@@ -1,3 +1,29 @@
1
+ const FULL_PRIVACY = { ip: true, userAgent: true, language: true, screen: true, timezone: true, hardware: true };
2
+ const NO_PRIVACY = { ip: false, userAgent: false, language: false, screen: false, timezone: false, hardware: false };
3
+ export function resolvePrivacy(input) {
4
+ if (input === true) return { ...FULL_PRIVACY };
5
+ if (input === false || input === void 0 || input === null) return { ...NO_PRIVACY };
6
+ return {
7
+ ip: input.ip ?? false,
8
+ userAgent: input.userAgent ?? false,
9
+ language: input.language ?? false,
10
+ screen: input.screen ?? false,
11
+ timezone: input.timezone ?? false,
12
+ hardware: input.hardware ?? false
13
+ };
14
+ }
15
+ export function mergePrivacy(base, override) {
16
+ if (override === void 0 || override === null) return base;
17
+ if (typeof override === "boolean") return resolvePrivacy(override);
18
+ return {
19
+ ip: override.ip !== void 0 ? override.ip : base.ip,
20
+ userAgent: override.userAgent !== void 0 ? override.userAgent : base.userAgent,
21
+ language: override.language !== void 0 ? override.language : base.language,
22
+ screen: override.screen !== void 0 ? override.screen : base.screen,
23
+ timezone: override.timezone !== void 0 ? override.timezone : base.timezone,
24
+ hardware: override.hardware !== void 0 ? override.hardware : base.hardware
25
+ };
26
+ }
1
27
  export const IP_HEADERS = [
2
28
  "x-forwarded-for",
3
29
  "x-real-ip",
@@ -183,7 +209,8 @@ export function anonymizeDeviceInfo(value) {
183
209
  }
184
210
  return result.join(sep);
185
211
  }
186
- export function stripPayloadFingerprinting(payload) {
212
+ export function stripPayloadFingerprinting(payload, privacy) {
213
+ const p = privacy || FULL_PRIVACY;
187
214
  const result = {};
188
215
  let deviceClass;
189
216
  for (const [key, value] of Object.entries(payload)) {
@@ -194,24 +221,38 @@ export function stripPayloadFingerprinting(payload) {
194
221
  }
195
222
  for (const [key, value] of Object.entries(payload)) {
196
223
  const lowerKey = key.toLowerCase();
197
- const isLanguageParam = NORMALIZE_PARAMS.language.some((p) => lowerKey === p.toLowerCase());
198
- const isUserAgentParam = NORMALIZE_PARAMS.userAgent.some((p) => lowerKey === p.toLowerCase());
199
- if ((isLanguageParam || isUserAgentParam) && typeof value === "string") {
200
- result[key] = isLanguageParam ? normalizeLanguage(value) : normalizeUserAgent(value);
201
- continue;
202
- }
203
224
  const matchesParam = (key2, params) => {
204
225
  const lk = key2.toLowerCase();
205
- return params.some((p) => {
206
- const lp = p.toLowerCase();
226
+ return params.some((pm) => {
227
+ const lp = pm.toLowerCase();
207
228
  return lk === lp || lk.startsWith(lp + "[");
208
229
  });
209
230
  };
231
+ const isLanguageParam = NORMALIZE_PARAMS.language.some((pm) => lowerKey === pm.toLowerCase());
232
+ if (isLanguageParam) {
233
+ if (Array.isArray(value)) {
234
+ result[key] = p.language ? value.map((v) => typeof v === "string" ? normalizeLanguage(v) : v) : value;
235
+ } else if (typeof value === "string") {
236
+ result[key] = p.language ? normalizeLanguage(value) : value;
237
+ } else {
238
+ result[key] = value;
239
+ }
240
+ continue;
241
+ }
242
+ const isUserAgentParam = NORMALIZE_PARAMS.userAgent.some((pm) => lowerKey === pm.toLowerCase());
243
+ if (isUserAgentParam && typeof value === "string") {
244
+ result[key] = p.userAgent ? normalizeUserAgent(value) : value;
245
+ continue;
246
+ }
210
247
  if (matchesParam(key, STRIP_PARAMS.ip) && typeof value === "string") {
211
- result[key] = anonymizeIP(value);
248
+ result[key] = p.ip ? anonymizeIP(value) : value;
212
249
  continue;
213
250
  }
214
251
  if (matchesParam(key, STRIP_PARAMS.screen)) {
252
+ if (!p.screen) {
253
+ result[key] = value;
254
+ continue;
255
+ }
215
256
  if (["sd", "colordepth", "pixelratio"].includes(lowerKey)) {
216
257
  result[key] = value;
217
258
  } else if (lowerKey === "sh" && deviceClass) {
@@ -223,31 +264,31 @@ export function stripPayloadFingerprinting(payload) {
223
264
  continue;
224
265
  }
225
266
  if (matchesParam(key, STRIP_PARAMS.hardware)) {
226
- result[key] = generalizeHardware(value);
267
+ result[key] = p.screen ? generalizeHardware(value) : value;
227
268
  continue;
228
269
  }
229
270
  if (matchesParam(key, STRIP_PARAMS.version)) {
230
- result[key] = generalizeVersion(value);
271
+ result[key] = p.hardware ? generalizeVersion(value) : value;
231
272
  continue;
232
273
  }
233
274
  if (matchesParam(key, STRIP_PARAMS.browserVersion)) {
234
- result[key] = generalizeBrowserVersions(value);
275
+ result[key] = p.hardware ? generalizeBrowserVersions(value) : value;
235
276
  continue;
236
277
  }
237
278
  if (matchesParam(key, STRIP_PARAMS.location)) {
238
- result[key] = generalizeTimezone(value);
279
+ result[key] = p.timezone ? generalizeTimezone(value) : value;
239
280
  continue;
240
281
  }
241
282
  if (matchesParam(key, STRIP_PARAMS.browserData)) {
242
- result[key] = Array.isArray(value) ? [] : "";
283
+ result[key] = p.hardware ? Array.isArray(value) ? [] : "" : value;
243
284
  continue;
244
285
  }
245
286
  if (matchesParam(key, STRIP_PARAMS.canvas)) {
246
- result[key] = typeof value === "number" ? 0 : typeof value === "object" ? {} : "";
287
+ result[key] = p.hardware ? typeof value === "number" ? 0 : typeof value === "object" ? {} : "" : value;
247
288
  continue;
248
289
  }
249
290
  if (matchesParam(key, STRIP_PARAMS.deviceInfo)) {
250
- result[key] = typeof value === "string" ? anonymizeDeviceInfo(value) : "";
291
+ result[key] = p.hardware ? typeof value === "string" ? anonymizeDeviceInfo(value) : "" : value;
251
292
  continue;
252
293
  }
253
294
  if (matchesParam(key, STRIP_PARAMS.platform)) {
@@ -256,10 +297,10 @@ export function stripPayloadFingerprinting(payload) {
256
297
  }
257
298
  if (Array.isArray(value)) {
258
299
  result[key] = value.map(
259
- (item) => typeof item === "object" && item !== null ? stripPayloadFingerprinting(item) : item
300
+ (item) => typeof item === "object" && item !== null ? stripPayloadFingerprinting(item, privacy) : item
260
301
  );
261
302
  } else if (typeof value === "object" && value !== null) {
262
- result[key] = stripPayloadFingerprinting(value);
303
+ result[key] = stripPayloadFingerprinting(value, privacy);
263
304
  } else {
264
305
  result[key] = value;
265
306
  }
@@ -37,7 +37,7 @@ export function rewriteScriptUrls(content, rewrites) {
37
37
  rewriteSuffix = remainder;
38
38
  }
39
39
  }
40
- } else if (fromPath && inner.startsWith(from) || isSuffixMatch && inner.includes(from)) {
40
+ } else if (fromPath && (inner.startsWith(from) || isSuffixMatch && inner.includes(from))) {
41
41
  const domainEnd = inner.indexOf(from) + from.length;
42
42
  const nextChar = inner[domainEnd];
43
43
  if (!nextChar || nextChar === "/" || nextChar === "?" || nextChar === "#") {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxt/scripts",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.2",
4
+ "version": "1.0.0-beta.4",
5
5
  "description": "Load third-party scripts with better performance, privacy and DX in Nuxt Apps.",
6
6
  "author": {
7
7
  "website": "https://harlanzw.com",
@@ -87,7 +87,7 @@
87
87
  }
88
88
  },
89
89
  "dependencies": {
90
- "@nuxt/devtools-kit": "^3.2.1",
90
+ "@nuxt/devtools-kit": "^3.2.2",
91
91
  "@nuxt/kit": "^4.3.1",
92
92
  "@vueuse/core": "^14.2.1",
93
93
  "consola": "^3.4.2",
@@ -108,7 +108,7 @@
108
108
  "valibot": "^1.2.0"
109
109
  },
110
110
  "devDependencies": {
111
- "@nuxt/devtools-ui-kit": "^3.2.1",
111
+ "@nuxt/devtools-ui-kit": "^3.2.2",
112
112
  "@nuxt/eslint-config": "^1.15.2",
113
113
  "@nuxt/module-builder": "^1.0.2",
114
114
  "@nuxt/test-utils": "^4.0.0",
@@ -125,14 +125,14 @@
125
125
  "knitwork": "^1.3.0",
126
126
  "nuxt": "^4.3.1",
127
127
  "playwright-core": "^1.58.2",
128
- "posthog-js": "^1.353.0",
129
- "shiki": "^3.22.0",
128
+ "posthog-js": "^1.353.1",
129
+ "shiki": "^3.23.0",
130
130
  "typescript": "5.9.3",
131
131
  "vitest": "^4.0.18",
132
132
  "vue": "^3.5.29",
133
133
  "vue-router": "^5.0.3",
134
134
  "vue-tsc": "^3.2.5",
135
- "@nuxt/scripts": "1.0.0-beta.2"
135
+ "@nuxt/scripts": "1.0.0-beta.4"
136
136
  },
137
137
  "resolutions": {
138
138
  "@nuxt/scripts": "workspace:*"