@nuxt/scripts 1.0.0-beta.1 → 1.0.0-beta.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.
Files changed (70) hide show
  1. package/README.md +6 -0
  2. package/dist/client/200.html +1 -1
  3. package/dist/client/404.html +1 -1
  4. package/dist/client/_nuxt/CD5B-xvT.js +1 -0
  5. package/dist/client/_nuxt/D-kOnTuH.js +162 -0
  6. package/dist/client/_nuxt/DdVDSbUA.js +1 -0
  7. package/dist/client/_nuxt/{DTDyDxvR.js → Ds2G8aQM.js} +1 -1
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/f1474569-6922-450d-bc3f-4fd5f3e1391a.json +1 -0
  10. package/dist/client/_nuxt/entry.D45OuV0w.css +1 -0
  11. package/dist/client/_nuxt/error-404.B57D-jUQ.css +1 -0
  12. package/dist/client/_nuxt/error-500.DTHUW7BI.css +1 -0
  13. package/dist/client/index.html +1 -1
  14. package/dist/module.d.mts +87 -2
  15. package/dist/module.json +1 -1
  16. package/dist/module.mjs +678 -142
  17. package/dist/registry.mjs +11 -0
  18. package/dist/runtime/components/ScriptInstagramEmbed.d.vue.ts +53 -0
  19. package/dist/runtime/components/ScriptInstagramEmbed.vue +38 -0
  20. package/dist/runtime/components/ScriptInstagramEmbed.vue.d.ts +53 -0
  21. package/dist/runtime/components/ScriptXEmbed.d.vue.ts +82 -0
  22. package/dist/runtime/components/ScriptXEmbed.vue +76 -0
  23. package/dist/runtime/components/ScriptXEmbed.vue.d.ts +82 -0
  24. package/dist/runtime/composables/useScript.js +24 -3
  25. package/dist/runtime/composables/useScriptTriggerServiceWorker.d.ts +7 -0
  26. package/dist/runtime/composables/useScriptTriggerServiceWorker.js +39 -0
  27. package/dist/runtime/plugins/sw-register.client.d.ts +2 -0
  28. package/dist/runtime/plugins/sw-register.client.js +12 -0
  29. package/dist/runtime/registry/instagram-embed.d.ts +23 -0
  30. package/dist/runtime/registry/instagram-embed.js +22 -0
  31. package/dist/runtime/registry/lemon-squeezy.d.ts +0 -1
  32. package/dist/runtime/registry/plausible-analytics.js +2 -2
  33. package/dist/runtime/registry/posthog.d.ts +1 -0
  34. package/dist/runtime/registry/posthog.js +2 -8
  35. package/dist/runtime/registry/tiktok-pixel.d.ts +1 -0
  36. package/dist/runtime/registry/tiktok-pixel.js +1 -0
  37. package/dist/runtime/registry/x-embed.d.ts +77 -0
  38. package/dist/runtime/registry/x-embed.js +41 -0
  39. package/dist/runtime/server/instagram-embed-asset.d.ts +2 -0
  40. package/dist/runtime/server/instagram-embed-asset.js +42 -0
  41. package/dist/runtime/server/instagram-embed-image.d.ts +2 -0
  42. package/dist/runtime/server/instagram-embed-image.js +54 -0
  43. package/dist/runtime/server/instagram-embed.d.ts +2 -0
  44. package/dist/runtime/server/instagram-embed.js +91 -0
  45. package/dist/runtime/server/proxy-handler.d.ts +6 -0
  46. package/dist/runtime/server/proxy-handler.js +246 -0
  47. package/dist/runtime/server/sw-handler.d.ts +2 -0
  48. package/dist/runtime/server/sw-handler.js +25 -0
  49. package/dist/runtime/server/utils/privacy.d.ts +141 -0
  50. package/dist/runtime/server/utils/privacy.js +309 -0
  51. package/dist/runtime/server/x-embed-image.d.ts +2 -0
  52. package/dist/runtime/server/x-embed-image.js +53 -0
  53. package/dist/runtime/server/x-embed.d.ts +49 -0
  54. package/dist/runtime/server/x-embed.js +31 -0
  55. package/dist/runtime/sw/proxy-sw.template.d.ts +1 -0
  56. package/dist/runtime/sw/proxy-sw.template.js +54 -0
  57. package/dist/runtime/types.d.ts +29 -0
  58. package/dist/runtime/utils/pure.d.ts +13 -0
  59. package/dist/runtime/utils/pure.js +67 -0
  60. package/dist/runtime/utils.d.ts +1 -1
  61. package/dist/runtime/utils.js +2 -1
  62. package/dist/types.d.mts +1 -1
  63. package/package.json +27 -26
  64. package/dist/client/_nuxt/Bdf7Qtwg.js +0 -1
  65. package/dist/client/_nuxt/CoyZWCgl.js +0 -162
  66. package/dist/client/_nuxt/Ds1k3yKJ.js +0 -1
  67. package/dist/client/_nuxt/builds/meta/62574f80-71d4-4f9e-8b96-145c85230d99.json +0 -1
  68. package/dist/client/_nuxt/entry.BjfcJo5q.css +0 -1
  69. package/dist/client/_nuxt/error-404.D45Vtjcx.css +0 -1
  70. package/dist/client/_nuxt/error-500.BOm1rWQf.css +0 -1
@@ -0,0 +1,25 @@
1
+ import { defineEventHandler, setResponseHeader } from "h3";
2
+ import { useRuntimeConfig } from "#imports";
3
+ import { parseURL } from "ufo";
4
+ export default defineEventHandler(async (event) => {
5
+ const config = useRuntimeConfig(event);
6
+ const proxyConfig = config["nuxt-scripts-proxy"];
7
+ const swTemplate = config["nuxt-scripts"]?.swTemplate || "";
8
+ const routes = proxyConfig?.routes || {};
9
+ const rules = Object.entries(routes).map(([localPath, proxy]) => {
10
+ const url = parseURL(proxy.replace(/\*\*$/, ""));
11
+ if (!url.host) return null;
12
+ return {
13
+ pattern: url.host,
14
+ pathPrefix: url.pathname || "",
15
+ target: localPath.replace(/\/\*\*$/, "")
16
+ };
17
+ }).filter(Boolean);
18
+ const swCode = `const INTERCEPT_RULES = ${JSON.stringify(rules)};
19
+
20
+ ${swTemplate}`;
21
+ setResponseHeader(event, "Content-Type", "application/javascript");
22
+ setResponseHeader(event, "Service-Worker-Allowed", "/");
23
+ setResponseHeader(event, "Cache-Control", "no-cache");
24
+ return swCode;
25
+ });
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Granular privacy controls for the first-party proxy.
3
+ * Each flag controls both headers AND body/query params for its domain.
4
+ */
5
+ export interface ProxyPrivacy {
6
+ /** Anonymize IP (headers + body). When false, real IP is forwarded via x-forwarded-for. */
7
+ ip?: boolean;
8
+ /** Normalize User-Agent (headers + body) */
9
+ userAgent?: boolean;
10
+ /** Normalize Accept-Language (headers + body) */
11
+ language?: boolean;
12
+ /** Generalize screen resolution, viewport, hardware concurrency, device memory */
13
+ screen?: boolean;
14
+ /** Generalize timezone offset and IANA timezone names */
15
+ timezone?: boolean;
16
+ /** Anonymize hardware fingerprints: canvas/webgl/audio, plugins/fonts, browser versions, device info */
17
+ hardware?: boolean;
18
+ }
19
+ /**
20
+ * Privacy input: `true` = full anonymize, `false` = passthrough (still strips sensitive headers),
21
+ * or a `ProxyPrivacy` object for granular control (unset flags default to `false` — opt-in).
22
+ */
23
+ export type ProxyPrivacyInput = boolean | ProxyPrivacy | null;
24
+ /** Resolved privacy with all flags explicitly set. */
25
+ export type ResolvedProxyPrivacy = Required<ProxyPrivacy>;
26
+ /**
27
+ * Normalize a privacy input to a fully-resolved object.
28
+ * Privacy is opt-in: unset object flags default to `false`.
29
+ * Each script in the registry explicitly sets all flags for its needs.
30
+ * - `true` → all flags true (full anonymize)
31
+ * - `false` / `undefined` → all flags false (passthrough)
32
+ * - `{ ip: true, hardware: true }` → only those active, rest off
33
+ */
34
+ export declare function resolvePrivacy(input?: ProxyPrivacyInput): ResolvedProxyPrivacy;
35
+ /**
36
+ * Merge privacy settings: `override` fields take precedence over `base` field-by-field.
37
+ * When `override` is undefined, returns `base` unchanged.
38
+ * When `override` is a boolean, it fully replaces `base`.
39
+ * When `override` is an object, only explicitly-set fields override.
40
+ */
41
+ export declare function mergePrivacy(base: ResolvedProxyPrivacy, override?: ProxyPrivacyInput): ResolvedProxyPrivacy;
42
+ /**
43
+ * Headers that reveal user IP address - stripped in proxy mode,
44
+ * anonymized in anonymize mode.
45
+ */
46
+ export declare const IP_HEADERS: string[];
47
+ /**
48
+ * Headers that enable fingerprinting - normalized in anonymize mode.
49
+ */
50
+ export declare const FINGERPRINT_HEADERS: string[];
51
+ /**
52
+ * Sensitive headers that should never be forwarded to third parties.
53
+ */
54
+ export declare const SENSITIVE_HEADERS: string[];
55
+ /**
56
+ * Payload parameters relevant to privacy.
57
+ *
58
+ * Note: userId and userData are intentionally NOT modified by stripPayloadFingerprinting.
59
+ * Analytics services require user identifiers (cid, uid, fbp, etc.) and user data (ud, email)
60
+ * to function correctly. These are listed here for documentation and param-detection tests only.
61
+ * The privacy model anonymizes device/browser fingerprinting while preserving user-level analytics IDs.
62
+ */
63
+ export declare const STRIP_PARAMS: {
64
+ ip: string[];
65
+ userId: string[];
66
+ userData: string[];
67
+ screen: string[];
68
+ hardware: string[];
69
+ platform: string[];
70
+ version: string[];
71
+ browserVersion: string[];
72
+ browserData: string[];
73
+ location: string[];
74
+ canvas: string[];
75
+ deviceInfo: string[];
76
+ };
77
+ /**
78
+ * Parameters that should be normalized (not stripped).
79
+ */
80
+ export declare const NORMALIZE_PARAMS: {
81
+ language: string[];
82
+ userAgent: string[];
83
+ };
84
+ /**
85
+ * Anonymize an IP address by zeroing trailing segments.
86
+ */
87
+ export declare function anonymizeIP(ip: string): string;
88
+ /**
89
+ * Normalize User-Agent to browser family and major version only.
90
+ */
91
+ export declare function normalizeUserAgent(ua: string): string;
92
+ /**
93
+ * Normalize Accept-Language to primary language tag (preserving country).
94
+ * "en-US,en;q=0.9,fr;q=0.8" → "en-US"
95
+ */
96
+ export declare function normalizeLanguage(lang: string): string;
97
+ /**
98
+ * Generalize screen resolution to 3 coarse device-class buckets (mobile / tablet / desktop).
99
+ * Handles both combined "WxH" strings and individual dimension values (sh, sw).
100
+ *
101
+ * When `dimension` is specified, uses the correct bucket for that axis:
102
+ * - 'width': [1920, 768, 360]
103
+ * - 'height': [1080, 1024, 640]
104
+ * Without `dimension`, individual values use width thresholds (backward-compatible).
105
+ */
106
+ export declare function generalizeScreen(value: unknown, dimension?: 'width' | 'height'): string | number;
107
+ /**
108
+ * Generalize hardware concurrency / device memory to common bucket.
109
+ */
110
+ export declare function generalizeHardware(value: unknown): number;
111
+ /**
112
+ * Generalize a version string to major version, preserving the original format.
113
+ * "6.17.0" → "6.0.0", "143.0.7499.4" → "143.0.0.0"
114
+ */
115
+ export declare function generalizeVersion(value: unknown): string;
116
+ /**
117
+ * Generalize browser version list to major versions, preserving segment count.
118
+ * Handles Snapchat d_bvs format: [,{"brand":"Chrome","version":"143.0.7499.4"}...]
119
+ * Handles GA uafvl format: HeadlessChrome;143.0.7499.4|Chromium;143.0.7499.4|...
120
+ */
121
+ export declare function generalizeBrowserVersions(value: unknown): string;
122
+ /**
123
+ * Generalize timezone to reduce precision.
124
+ * IANA names → UTC offset string, numeric offsets → bucketed to 3-hour intervals.
125
+ */
126
+ export declare function generalizeTimezone(value: unknown): string | number;
127
+ /**
128
+ * Anonymize a combined device-info string (e.g. X/Twitter `dv` param).
129
+ * Parses the delimited string and generalizes fingerprinting components
130
+ * (timezone, language, screen dimensions) while keeping low-entropy values.
131
+ */
132
+ export declare function anonymizeDeviceInfo(value: string): string;
133
+ /**
134
+ * Recursively anonymize fingerprinting data in payload.
135
+ * Fields are generalized or normalized rather than stripped, so endpoints
136
+ * still receive valid data with reduced fingerprinting precision.
137
+ *
138
+ * When `privacy` is provided, only categories with their flag set to `true` are processed.
139
+ * Default (no arg) = all categories active, so existing callers work unchanged.
140
+ */
141
+ export declare function stripPayloadFingerprinting(payload: Record<string, unknown>, privacy?: ResolvedProxyPrivacy): Record<string, unknown>;
@@ -0,0 +1,309 @@
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
+ }
27
+ export const IP_HEADERS = [
28
+ "x-forwarded-for",
29
+ "x-real-ip",
30
+ "forwarded",
31
+ "cf-connecting-ip",
32
+ "true-client-ip",
33
+ "x-client-ip",
34
+ "x-cluster-client-ip"
35
+ ];
36
+ export const FINGERPRINT_HEADERS = [
37
+ "user-agent",
38
+ "accept-language",
39
+ "accept-encoding",
40
+ "sec-ch-ua",
41
+ "sec-ch-ua-platform",
42
+ "sec-ch-ua-mobile",
43
+ "sec-ch-ua-full-version-list"
44
+ ];
45
+ export const SENSITIVE_HEADERS = [
46
+ "cookie",
47
+ "authorization",
48
+ "proxy-authorization",
49
+ "x-csrf-token",
50
+ "www-authenticate"
51
+ ];
52
+ export const STRIP_PARAMS = {
53
+ // IP addresses — anonymized to subnet
54
+ ip: ["uip", "ip", "client_ip_address", "ip_address", "user_ip", "ipaddress", "context.ip"],
55
+ // User identifiers — intentionally preserved for analytics functionality
56
+ userId: ["uid", "user_id", "userid", "external_id", "cid", "_gid", "fbp", "fbc", "sid", "session_id", "sessionid", "pl_id", "p_user_id", "uuid", "anonymousid", "twclid", "u_c1", "u_sclid", "u_scsid"],
57
+ // User data (PII) — intentionally preserved; hashed by analytics SDKs before sending
58
+ userData: ["ud", "user_data", "userdata", "email", "phone", "traits.email", "traits.phone"],
59
+ // Screen/Hardware — generalized to common buckets
60
+ screen: ["sr", "vp", "sd", "screen", "viewport", "colordepth", "pixelratio", "sh", "sw"],
61
+ // Hardware capabilities — generalized to common buckets
62
+ hardware: ["hardwareconcurrency", "devicememory", "cpu", "mem"],
63
+ // Platform identifiers — low entropy, kept as-is (e.g. "Linux", "x86")
64
+ platform: ["plat", "platform", "d_a", "d_ot"],
65
+ // Version strings — generalized to major version only (d_os = Snapchat OS version, uapv = GA platform version)
66
+ version: ["d_os", "uapv"],
67
+ // Browser version lists — generalized to major versions (d_bvs = Snapchat, uafvl = GA Client Hints)
68
+ browserVersion: ["d_bvs", "uafvl"],
69
+ // Browser data lists — replaced with empty value
70
+ browserData: ["plugins", "fonts"],
71
+ // Location/Timezone — generalized
72
+ location: ["tz", "timezone", "timezoneoffset"],
73
+ // Canvas/WebGL/Audio fingerprints — replaced with empty value (pure fingerprints, no analytics value)
74
+ canvas: ["canvas", "webgl", "audiofingerprint"],
75
+ // Combined device fingerprinting (X/Twitter dv param contains: timezone, locale, vendor, platform, screen, etc.)
76
+ deviceInfo: ["dv", "device_info", "deviceinfo"]
77
+ };
78
+ export const NORMALIZE_PARAMS = {
79
+ language: ["ul", "lang", "language", "languages"],
80
+ userAgent: ["ua", "useragent", "user_agent", "client_user_agent", "context.useragent"]
81
+ };
82
+ export function anonymizeIP(ip) {
83
+ if (ip.includes(":")) {
84
+ return ip.split(":").slice(0, 3).join(":") + "::";
85
+ }
86
+ const parts = ip.split(".");
87
+ if (parts.length === 4) {
88
+ parts[3] = "0";
89
+ return parts.join(".");
90
+ }
91
+ return ip;
92
+ }
93
+ export function normalizeUserAgent(ua) {
94
+ const tokens = [
95
+ ["Edg/", "Edge"],
96
+ ["OPR/", "Opera"],
97
+ ["Opera/", "Opera"],
98
+ ["Firefox/", "Firefox"],
99
+ ["Chrome/", "Chrome"],
100
+ ["Safari/", "Safari"]
101
+ ];
102
+ for (const [pattern, family] of tokens) {
103
+ const idx = ua.indexOf(pattern);
104
+ if (idx !== -1) {
105
+ const versionStart = idx + pattern.length;
106
+ const majorVersion = ua.slice(versionStart).match(/^(\d+)/)?.[1];
107
+ if (majorVersion)
108
+ return `Mozilla/5.0 (compatible; ${family}/${majorVersion}.0)`;
109
+ }
110
+ }
111
+ return "Mozilla/5.0 (compatible)";
112
+ }
113
+ export function normalizeLanguage(lang) {
114
+ return lang.split(",")[0]?.split(";")[0]?.trim() || "en";
115
+ }
116
+ const SCREEN_BUCKETS = {
117
+ desktop: { w: 1920, h: 1080 },
118
+ tablet: { w: 768, h: 1024 },
119
+ mobile: { w: 360, h: 640 }
120
+ };
121
+ function getDeviceClass(width) {
122
+ if (width >= 1200) return "desktop";
123
+ if (width >= 700) return "tablet";
124
+ return "mobile";
125
+ }
126
+ export function generalizeScreen(value, dimension) {
127
+ if (typeof value === "string" && value.includes("x")) {
128
+ const width = Number.parseInt(value.split("x")[0] || "0");
129
+ const cls = getDeviceClass(width);
130
+ return `${SCREEN_BUCKETS[cls].w}x${SCREEN_BUCKETS[cls].h}`;
131
+ }
132
+ const num = typeof value === "number" ? value : Number(value);
133
+ if (!Number.isNaN(num)) {
134
+ const cls = getDeviceClass(num);
135
+ const bucketed = dimension === "height" ? SCREEN_BUCKETS[cls].h : SCREEN_BUCKETS[cls].w;
136
+ return typeof value === "number" ? bucketed : String(bucketed);
137
+ }
138
+ return "1920x1080";
139
+ }
140
+ export function generalizeHardware(value) {
141
+ const num = typeof value === "number" ? value : Number(value);
142
+ if (Number.isNaN(num)) return 4;
143
+ if (num >= 16) return 16;
144
+ if (num >= 8) return 8;
145
+ if (num >= 4) return 4;
146
+ return 2;
147
+ }
148
+ export function generalizeVersion(value) {
149
+ if (typeof value !== "string") return String(value);
150
+ const match = value.match(/^(\d+)(([.\-_])\d+)*/);
151
+ if (!match) return String(value);
152
+ const major = match[1];
153
+ const sep = match[3] || ".";
154
+ const segmentCount = value.split(/[.\-_]/).length;
155
+ return major + (sep + "0").repeat(segmentCount - 1);
156
+ }
157
+ export function generalizeBrowserVersions(value) {
158
+ if (typeof value !== "string") return String(value);
159
+ const zeroSegments = (ver) => {
160
+ const parts = ver.split(".");
161
+ return parts[0] + parts.slice(1).map(() => ".0").join("");
162
+ };
163
+ if (value.includes('"version"'))
164
+ return value.replace(/("version"\s*:\s*")(\d+(?:\.\d+)*)/g, (_, prefix, ver) => prefix + zeroSegments(ver));
165
+ if (value.includes(";"))
166
+ return value.replace(/;(\d+(?:\.\d+)*)/g, (_, ver) => ";" + zeroSegments(ver));
167
+ return value;
168
+ }
169
+ export function generalizeTimezone(value) {
170
+ if (typeof value === "number") {
171
+ return Math.round(value / 180) * 180;
172
+ }
173
+ if (typeof value === "string") {
174
+ return "UTC";
175
+ }
176
+ return 0;
177
+ }
178
+ export function anonymizeDeviceInfo(value) {
179
+ const sep = value.includes("|") ? "|" : "&";
180
+ const parts = value.split(sep);
181
+ if (parts.length < 4) return value;
182
+ const result = [...parts];
183
+ for (let i = 0; i < parts.length; i++) {
184
+ const part = parts[i];
185
+ if (part.includes("/") && /^[A-Z]/.test(part)) {
186
+ result[i] = String(generalizeTimezone(part));
187
+ continue;
188
+ }
189
+ if (/^[a-z]{2}(?:-[a-z]{2,})?$/i.test(part)) {
190
+ result[i] = normalizeLanguage(part);
191
+ continue;
192
+ }
193
+ const num = Number(part);
194
+ if (!Number.isNaN(num) && num >= 300 && num <= 1e4) {
195
+ const nextNum = Number(parts[i + 1]);
196
+ if (!Number.isNaN(nextNum) && nextNum >= 300 && nextNum <= 1e4) {
197
+ const cls = getDeviceClass(num);
198
+ result[i] = String(SCREEN_BUCKETS[cls].w);
199
+ result[i + 1] = String(SCREEN_BUCKETS[cls].h);
200
+ i++;
201
+ continue;
202
+ }
203
+ result[i] = String(generalizeScreen(num));
204
+ continue;
205
+ }
206
+ if (!Number.isNaN(num) && num < -60) {
207
+ result[i] = String(generalizeTimezone(num));
208
+ }
209
+ }
210
+ return result.join(sep);
211
+ }
212
+ export function stripPayloadFingerprinting(payload, privacy) {
213
+ const p = privacy || FULL_PRIVACY;
214
+ const result = {};
215
+ let deviceClass;
216
+ for (const [key, value] of Object.entries(payload)) {
217
+ if (key.toLowerCase() === "sw") {
218
+ const num = typeof value === "number" ? value : Number(value);
219
+ if (!Number.isNaN(num)) deviceClass = getDeviceClass(num);
220
+ }
221
+ }
222
+ for (const [key, value] of Object.entries(payload)) {
223
+ const lowerKey = key.toLowerCase();
224
+ const matchesParam = (key2, params) => {
225
+ const lk = key2.toLowerCase();
226
+ return params.some((pm) => {
227
+ const lp = pm.toLowerCase();
228
+ return lk === lp || lk.startsWith(lp + "[");
229
+ });
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
+ }
247
+ if (matchesParam(key, STRIP_PARAMS.ip) && typeof value === "string") {
248
+ result[key] = p.ip ? anonymizeIP(value) : value;
249
+ continue;
250
+ }
251
+ if (matchesParam(key, STRIP_PARAMS.screen)) {
252
+ if (!p.screen) {
253
+ result[key] = value;
254
+ continue;
255
+ }
256
+ if (["sd", "colordepth", "pixelratio"].includes(lowerKey)) {
257
+ result[key] = value;
258
+ } else if (lowerKey === "sh" && deviceClass) {
259
+ const paired = SCREEN_BUCKETS[deviceClass].h;
260
+ result[key] = typeof value === "number" ? paired : String(paired);
261
+ } else {
262
+ result[key] = generalizeScreen(value, lowerKey === "sw" ? "width" : lowerKey === "sh" ? "height" : void 0);
263
+ }
264
+ continue;
265
+ }
266
+ if (matchesParam(key, STRIP_PARAMS.hardware)) {
267
+ result[key] = p.screen ? generalizeHardware(value) : value;
268
+ continue;
269
+ }
270
+ if (matchesParam(key, STRIP_PARAMS.version)) {
271
+ result[key] = p.hardware ? generalizeVersion(value) : value;
272
+ continue;
273
+ }
274
+ if (matchesParam(key, STRIP_PARAMS.browserVersion)) {
275
+ result[key] = p.hardware ? generalizeBrowserVersions(value) : value;
276
+ continue;
277
+ }
278
+ if (matchesParam(key, STRIP_PARAMS.location)) {
279
+ result[key] = p.timezone ? generalizeTimezone(value) : value;
280
+ continue;
281
+ }
282
+ if (matchesParam(key, STRIP_PARAMS.browserData)) {
283
+ result[key] = p.hardware ? Array.isArray(value) ? [] : "" : value;
284
+ continue;
285
+ }
286
+ if (matchesParam(key, STRIP_PARAMS.canvas)) {
287
+ result[key] = p.hardware ? typeof value === "number" ? 0 : typeof value === "object" ? {} : "" : value;
288
+ continue;
289
+ }
290
+ if (matchesParam(key, STRIP_PARAMS.deviceInfo)) {
291
+ result[key] = p.hardware ? typeof value === "string" ? anonymizeDeviceInfo(value) : "" : value;
292
+ continue;
293
+ }
294
+ if (matchesParam(key, STRIP_PARAMS.platform)) {
295
+ result[key] = value;
296
+ continue;
297
+ }
298
+ if (Array.isArray(value)) {
299
+ result[key] = value.map(
300
+ (item) => typeof item === "object" && item !== null ? stripPayloadFingerprinting(item, privacy) : item
301
+ );
302
+ } else if (typeof value === "object" && value !== null) {
303
+ result[key] = stripPayloadFingerprinting(value, privacy);
304
+ } else {
305
+ result[key] = value;
306
+ }
307
+ }
308
+ return result;
309
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
+ export default _default;
@@ -0,0 +1,53 @@
1
+ import { createError, defineEventHandler, getQuery, setHeader } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ export default defineEventHandler(async (event) => {
4
+ const query = getQuery(event);
5
+ const url = query.url;
6
+ if (!url) {
7
+ throw createError({
8
+ statusCode: 400,
9
+ statusMessage: "Image URL is required"
10
+ });
11
+ }
12
+ let parsedUrl;
13
+ try {
14
+ parsedUrl = new URL(url);
15
+ } catch {
16
+ throw createError({
17
+ statusCode: 400,
18
+ statusMessage: "Invalid image URL"
19
+ });
20
+ }
21
+ if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
22
+ throw createError({
23
+ statusCode: 400,
24
+ statusMessage: "Invalid URL scheme"
25
+ });
26
+ }
27
+ const allowedDomains = [
28
+ "pbs.twimg.com",
29
+ "abs.twimg.com",
30
+ "video.twimg.com"
31
+ ];
32
+ if (!allowedDomains.includes(parsedUrl.hostname)) {
33
+ throw createError({
34
+ statusCode: 403,
35
+ statusMessage: "Domain not allowed"
36
+ });
37
+ }
38
+ const response = await $fetch.raw(url, {
39
+ timeout: 5e3,
40
+ headers: {
41
+ "Accept": "image/webp,image/jpeg,image/png,image/*,*/*;q=0.8",
42
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
43
+ }
44
+ }).catch((error) => {
45
+ throw createError({
46
+ statusCode: error.statusCode || 500,
47
+ statusMessage: error.statusMessage || "Failed to fetch image"
48
+ });
49
+ });
50
+ setHeader(event, "Content-Type", response.headers.get("content-type") || "image/jpeg");
51
+ setHeader(event, "Cache-Control", "public, max-age=3600, s-maxage=3600");
52
+ return response._data;
53
+ });
@@ -0,0 +1,49 @@
1
+ interface TweetData {
2
+ id_str: string;
3
+ text: string;
4
+ created_at: string;
5
+ favorite_count: number;
6
+ conversation_count: number;
7
+ user: {
8
+ name: string;
9
+ screen_name: string;
10
+ profile_image_url_https: string;
11
+ verified?: boolean;
12
+ is_blue_verified?: boolean;
13
+ };
14
+ entities?: {
15
+ media?: Array<{
16
+ media_url_https: string;
17
+ type: string;
18
+ sizes: Record<string, {
19
+ w: number;
20
+ h: number;
21
+ }>;
22
+ }>;
23
+ urls?: Array<{
24
+ url: string;
25
+ expanded_url: string;
26
+ display_url: string;
27
+ }>;
28
+ };
29
+ photos?: Array<{
30
+ url: string;
31
+ width: number;
32
+ height: number;
33
+ }>;
34
+ video?: {
35
+ poster: string;
36
+ variants: Array<{
37
+ type: string;
38
+ src: string;
39
+ }>;
40
+ };
41
+ quoted_tweet?: TweetData;
42
+ parent?: {
43
+ user: {
44
+ screen_name: string;
45
+ };
46
+ };
47
+ }
48
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<TweetData>>;
49
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { createError, defineEventHandler, getQuery, setHeader } from "h3";
2
+ import { $fetch } from "ofetch";
3
+ export default defineEventHandler(async (event) => {
4
+ const query = getQuery(event);
5
+ const tweetId = query.id;
6
+ if (!tweetId || !/^\d+$/.test(tweetId)) {
7
+ throw createError({
8
+ statusCode: 400,
9
+ statusMessage: "Valid Tweet ID is required"
10
+ });
11
+ }
12
+ const randomToken = [...Array(11)].map(() => (Math.random() * 36).toString(36)[2]).join("");
13
+ const params = new URLSearchParams({ id: tweetId, token: randomToken });
14
+ const tweetData = await $fetch(
15
+ `https://cdn.syndication.twimg.com/tweet-result?${params.toString()}`,
16
+ {
17
+ headers: {
18
+ "Accept": "application/json",
19
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
20
+ }
21
+ }
22
+ ).catch((error) => {
23
+ throw createError({
24
+ statusCode: error.statusCode || 500,
25
+ statusMessage: error.statusMessage || "Failed to fetch tweet"
26
+ });
27
+ });
28
+ setHeader(event, "Content-Type", "application/json");
29
+ setHeader(event, "Cache-Control", "public, max-age=600, s-maxage=600");
30
+ return tweetData;
31
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Nuxt Scripts Service Worker - intercepts analytics requests
3
+ *
4
+ * Injected at runtime:
5
+ * - INTERCEPT_RULES: Array<{ pattern: string, pathPrefix: string, target: string }>
6
+ */
7
+
8
+ /* global INTERCEPT_RULES */
9
+
10
+ self.addEventListener('install', () => {
11
+ // console.log('[nuxt-scripts-sw] Installing...');
12
+ self.skipWaiting()
13
+ })
14
+
15
+ self.addEventListener('activate', (event) => {
16
+ // console.log('[nuxt-scripts-sw] Activating...');
17
+ event.waitUntil(self.clients.claim())
18
+ })
19
+
20
+ self.addEventListener('fetch', (event) => {
21
+ const url = new URL(event.request.url)
22
+
23
+ // Only intercept cross-origin requests
24
+ if (url.origin === self.location.origin) return
25
+
26
+ for (const rule of INTERCEPT_RULES) {
27
+ const hostMatches = url.host === rule.pattern || url.host.endsWith('.' + rule.pattern)
28
+ // Check if path prefix matches (if one is required)
29
+ const pathMatches = !rule.pathPrefix || url.pathname.startsWith(rule.pathPrefix)
30
+
31
+ if (hostMatches && pathMatches) {
32
+ // Strip path prefix from the original URL path before building proxy URL
33
+ const strippedPath = rule.pathPrefix
34
+ ? url.pathname.slice(rule.pathPrefix.length) || '/'
35
+ : url.pathname
36
+
37
+ // console.log('[nuxt-scripts-sw] Intercepting:', url.href, '->', rule.target + strippedPath);
38
+
39
+ const separator = strippedPath.startsWith('/') ? '' : '/'
40
+ const proxyUrl = new URL(rule.target + separator + strippedPath + url.search, self.location.origin)
41
+ const clonedRequest = event.request.clone()
42
+ event.respondWith(
43
+ fetch(proxyUrl.href, {
44
+ method: clonedRequest.method,
45
+ headers: clonedRequest.headers,
46
+ body: clonedRequest.method !== 'GET' && clonedRequest.method !== 'HEAD' ? clonedRequest.body : undefined,
47
+ credentials: 'same-origin',
48
+ redirect: 'follow',
49
+ }),
50
+ )
51
+ return
52
+ }
53
+ }
54
+ })