@nuxt/scripts 0.13.2 → 1.0.0-beta.12
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/README.md +15 -0
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/48AF9EJD.js +1 -0
- package/dist/client/_nuxt/Bk6ed9rg.js +1 -0
- package/dist/client/_nuxt/C4Cj8gBr.js +162 -0
- package/dist/client/_nuxt/{Bje-0OHL.js → DP0kj6Xn.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/919b81d8-ed3a-4222-8a40-df0031cc3b99.json +1 -0
- package/dist/client/_nuxt/entry.D45OuV0w.css +1 -0
- package/dist/client/_nuxt/error-404.B57D-jUQ.css +1 -0
- package/dist/client/_nuxt/error-500.DTHUW7BI.css +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +113 -4
- package/dist/module.d.ts +176 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +780 -299
- package/dist/registry.d.ts +6 -0
- package/dist/registry.mjs +94 -18
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.d.vue.ts +30 -2
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue +40 -15
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue.d.ts +30 -2
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsCircle.vue +7 -7
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsHeatmapLayer.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsInfoWindow.vue +12 -12
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarker.vue +6 -6
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.d.vue.ts +21 -9
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue +8 -8
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue.d.ts +21 -9
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.vue +11 -5
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPolygon.vue +7 -7
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPolyline.vue +7 -7
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsRectangle.vue +7 -7
- package/dist/runtime/components/ScriptCrisp.d.vue.ts +1 -1
- package/dist/runtime/components/ScriptCrisp.vue +1 -1
- package/dist/runtime/components/ScriptCrisp.vue.d.ts +1 -1
- package/dist/runtime/components/ScriptGoogleAdsense.vue +1 -1
- package/dist/runtime/components/ScriptInstagramEmbed.d.vue.ts +53 -0
- package/dist/runtime/components/ScriptInstagramEmbed.vue +38 -0
- package/dist/runtime/components/ScriptInstagramEmbed.vue.d.ts +53 -0
- package/dist/runtime/components/ScriptIntercom.d.vue.ts +1 -1
- package/dist/runtime/components/ScriptIntercom.vue +4 -3
- package/dist/runtime/components/ScriptIntercom.vue.d.ts +1 -1
- package/dist/runtime/components/ScriptPayPalButtons.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptPayPalButtons.vue +13 -11
- package/dist/runtime/components/ScriptPayPalButtons.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMarks.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMarks.vue +10 -8
- package/dist/runtime/components/ScriptPayPalMarks.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMessages.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptPayPalMessages.vue +11 -9
- package/dist/runtime/components/ScriptPayPalMessages.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptStripePricingTable.vue +2 -2
- package/dist/runtime/components/ScriptVimeoPlayer.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptVimeoPlayer.vue +1 -1
- package/dist/runtime/components/ScriptVimeoPlayer.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptXEmbed.d.vue.ts +82 -0
- package/dist/runtime/components/ScriptXEmbed.vue +76 -0
- package/dist/runtime/components/ScriptXEmbed.vue.d.ts +82 -0
- package/dist/runtime/components/ScriptYouTubePlayer.d.vue.ts +12 -1
- package/dist/runtime/components/ScriptYouTubePlayer.vue +44 -16
- package/dist/runtime/components/ScriptYouTubePlayer.vue.d.ts +12 -1
- package/dist/runtime/composables/useScript.js +36 -5
- package/dist/runtime/composables/useScriptEventPage.js +2 -2
- package/dist/runtime/composables/useScriptTriggerConsent.js +1 -1
- package/dist/runtime/composables/useScriptTriggerElement.js +1 -1
- package/dist/runtime/composables/useScriptTriggerIdleTimeout.js +1 -1
- package/dist/runtime/composables/useScriptTriggerServiceWorker.d.ts +7 -0
- package/dist/runtime/composables/useScriptTriggerServiceWorker.js +39 -0
- package/dist/runtime/npm-script-stub.d.ts +20 -0
- package/dist/runtime/npm-script-stub.js +73 -0
- package/dist/runtime/registry/clarity.js +21 -25
- package/dist/runtime/registry/cloudflare-web-analytics.js +1 -1
- package/dist/runtime/registry/crisp.js +1 -1
- package/dist/runtime/registry/databuddy-analytics.js +1 -1
- package/dist/runtime/registry/fathom-analytics.js +1 -1
- package/dist/runtime/registry/google-adsense.js +1 -1
- package/dist/runtime/registry/google-analytics.js +2 -2
- package/dist/runtime/registry/google-maps.d.ts +1 -1
- package/dist/runtime/registry/google-maps.js +1 -1
- package/dist/runtime/registry/google-recaptcha.d.ts +27 -0
- package/dist/runtime/registry/google-recaptcha.js +45 -0
- package/dist/runtime/registry/google-sign-in.d.ts +84 -0
- package/dist/runtime/registry/google-sign-in.js +50 -0
- package/dist/runtime/registry/google-tag-manager.d.ts +4 -2
- package/dist/runtime/registry/google-tag-manager.js +16 -6
- package/dist/runtime/registry/hotjar.js +1 -1
- package/dist/runtime/registry/instagram-embed.d.ts +23 -0
- package/dist/runtime/registry/instagram-embed.js +22 -0
- package/dist/runtime/registry/intercom.js +1 -1
- package/dist/runtime/registry/lemon-squeezy.d.ts +0 -1
- package/dist/runtime/registry/matomo-analytics.js +3 -3
- package/dist/runtime/registry/meta-pixel.js +1 -1
- package/dist/runtime/registry/npm.js +1 -1
- package/dist/runtime/registry/paypal.d.ts +1 -1
- package/dist/runtime/registry/paypal.js +2 -2
- package/dist/runtime/registry/plausible-analytics.js +21 -13
- package/dist/runtime/registry/posthog.d.ts +27 -0
- package/dist/runtime/registry/posthog.js +88 -0
- package/dist/runtime/registry/reddit-pixel.js +1 -1
- package/dist/runtime/registry/rybbit-analytics.js +41 -9
- package/dist/runtime/registry/segment.js +1 -1
- package/dist/runtime/registry/snapchat-pixel.js +1 -1
- package/dist/runtime/registry/stripe.d.ts +1 -1
- package/dist/runtime/registry/stripe.js +1 -1
- package/dist/runtime/registry/tiktok-pixel.d.ts +44 -0
- package/dist/runtime/registry/tiktok-pixel.js +44 -0
- package/dist/runtime/registry/umami-analytics.js +1 -1
- package/dist/runtime/registry/vimeo-player.d.ts +2 -2
- package/dist/runtime/registry/vimeo-player.js +1 -1
- package/dist/runtime/registry/x-embed.d.ts +77 -0
- package/dist/runtime/registry/x-embed.js +41 -0
- package/dist/runtime/registry/x-pixel.js +1 -1
- package/dist/runtime/registry/youtube-player.d.ts +7 -7
- package/dist/runtime/registry/youtube-player.js +1 -1
- package/dist/runtime/server/google-static-maps-proxy.d.ts +2 -0
- package/dist/runtime/server/google-static-maps-proxy.js +54 -0
- package/dist/runtime/server/instagram-embed-asset.d.ts +2 -0
- package/dist/runtime/server/instagram-embed-asset.js +42 -0
- package/dist/runtime/server/instagram-embed-image.d.ts +2 -0
- package/dist/runtime/server/instagram-embed-image.js +54 -0
- package/dist/runtime/server/instagram-embed.d.ts +2 -0
- package/dist/runtime/server/instagram-embed.js +91 -0
- package/dist/runtime/server/proxy-handler.d.ts +6 -0
- package/dist/runtime/server/proxy-handler.js +264 -0
- package/dist/runtime/server/utils/privacy.d.ts +141 -0
- package/dist/runtime/server/utils/privacy.js +324 -0
- package/dist/runtime/server/x-embed-image.d.ts +2 -0
- package/dist/runtime/server/x-embed-image.js +53 -0
- package/dist/runtime/server/x-embed.d.ts +49 -0
- package/dist/runtime/server/x-embed.js +31 -0
- package/dist/runtime/types.d.ts +61 -20
- package/dist/runtime/utils/pure.d.ts +9 -0
- package/dist/runtime/utils/pure.js +0 -0
- package/dist/runtime/utils.d.ts +5 -4
- package/dist/runtime/utils.js +12 -2
- package/dist/shared/scripts.DLRgvHQg.mjs +288 -0
- package/dist/stats.d.mts +39 -0
- package/dist/stats.d.ts +39 -0
- package/dist/stats.mjs +711 -0
- package/dist/types.d.mts +1 -1
- package/package.json +59 -46
- package/dist/client/_nuxt/DMut0W-e.js +0 -162
- package/dist/client/_nuxt/builds/meta/5e0206fe-a683-423c-8d59-2596d0b16fee.json +0 -1
- package/dist/client/_nuxt/entry.BjfcJo5q.css +0 -1
- package/dist/client/_nuxt/error-404.B0ZhSNwd.css +0 -1
- package/dist/client/_nuxt/error-500.D4MdgPaC.css +0 -1
- package/dist/client/_nuxt/iNmKC7TZ.js +0 -1
- package/dist/client/_nuxt/rttsH3SL.js +0 -1
|
@@ -0,0 +1,324 @@
|
|
|
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)
|
|
5
|
+
return { ...FULL_PRIVACY };
|
|
6
|
+
if (input === false || input === void 0 || input === null)
|
|
7
|
+
return { ...NO_PRIVACY };
|
|
8
|
+
return {
|
|
9
|
+
ip: input.ip ?? false,
|
|
10
|
+
userAgent: input.userAgent ?? false,
|
|
11
|
+
language: input.language ?? false,
|
|
12
|
+
screen: input.screen ?? false,
|
|
13
|
+
timezone: input.timezone ?? false,
|
|
14
|
+
hardware: input.hardware ?? false
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function mergePrivacy(base, override) {
|
|
18
|
+
if (override === void 0 || override === null)
|
|
19
|
+
return base;
|
|
20
|
+
if (typeof override === "boolean")
|
|
21
|
+
return resolvePrivacy(override);
|
|
22
|
+
return {
|
|
23
|
+
ip: override.ip !== void 0 ? override.ip : base.ip,
|
|
24
|
+
userAgent: override.userAgent !== void 0 ? override.userAgent : base.userAgent,
|
|
25
|
+
language: override.language !== void 0 ? override.language : base.language,
|
|
26
|
+
screen: override.screen !== void 0 ? override.screen : base.screen,
|
|
27
|
+
timezone: override.timezone !== void 0 ? override.timezone : base.timezone,
|
|
28
|
+
hardware: override.hardware !== void 0 ? override.hardware : base.hardware
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export const IP_HEADERS = [
|
|
32
|
+
"x-forwarded-for",
|
|
33
|
+
"x-real-ip",
|
|
34
|
+
"forwarded",
|
|
35
|
+
"cf-connecting-ip",
|
|
36
|
+
"true-client-ip",
|
|
37
|
+
"x-client-ip",
|
|
38
|
+
"x-cluster-client-ip"
|
|
39
|
+
];
|
|
40
|
+
export const FINGERPRINT_HEADERS = [
|
|
41
|
+
"user-agent",
|
|
42
|
+
"accept-language",
|
|
43
|
+
"accept-encoding",
|
|
44
|
+
"sec-ch-ua",
|
|
45
|
+
"sec-ch-ua-platform",
|
|
46
|
+
"sec-ch-ua-mobile",
|
|
47
|
+
"sec-ch-ua-full-version-list"
|
|
48
|
+
];
|
|
49
|
+
export const SENSITIVE_HEADERS = [
|
|
50
|
+
"cookie",
|
|
51
|
+
"authorization",
|
|
52
|
+
"proxy-authorization",
|
|
53
|
+
"x-csrf-token",
|
|
54
|
+
"www-authenticate"
|
|
55
|
+
];
|
|
56
|
+
export const STRIP_PARAMS = {
|
|
57
|
+
// IP addresses — anonymized to subnet
|
|
58
|
+
ip: ["uip", "ip", "client_ip_address", "ip_address", "user_ip", "ipaddress", "context.ip"],
|
|
59
|
+
// User identifiers — intentionally preserved for analytics functionality
|
|
60
|
+
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"],
|
|
61
|
+
// User data (PII) — intentionally preserved; hashed by analytics SDKs before sending
|
|
62
|
+
userData: ["ud", "user_data", "userdata", "email", "phone", "traits.email", "traits.phone"],
|
|
63
|
+
// Screen/Hardware — generalized to common buckets
|
|
64
|
+
screen: ["sr", "vp", "sd", "screen", "viewport", "colordepth", "pixelratio", "sh", "sw"],
|
|
65
|
+
// Hardware capabilities — generalized to common buckets
|
|
66
|
+
hardware: ["hardwareconcurrency", "devicememory", "cpu", "mem"],
|
|
67
|
+
// Platform identifiers — low entropy, kept as-is (e.g. "Linux", "x86")
|
|
68
|
+
platform: ["plat", "platform", "d_a", "d_ot"],
|
|
69
|
+
// Version strings — generalized to major version only (d_os = Snapchat OS version, uapv = GA platform version)
|
|
70
|
+
version: ["d_os", "uapv"],
|
|
71
|
+
// Browser version lists — generalized to major versions (d_bvs = Snapchat, uafvl = GA Client Hints)
|
|
72
|
+
browserVersion: ["d_bvs", "uafvl"],
|
|
73
|
+
// Browser data lists — replaced with empty value
|
|
74
|
+
browserData: ["plugins", "fonts"],
|
|
75
|
+
// Location/Timezone — generalized
|
|
76
|
+
location: ["tz", "timezone", "timezoneoffset"],
|
|
77
|
+
// Canvas/WebGL/Audio fingerprints — replaced with empty value (pure fingerprints, no analytics value)
|
|
78
|
+
canvas: ["canvas", "webgl", "audiofingerprint"],
|
|
79
|
+
// Combined device fingerprinting (X/Twitter dv param contains: timezone, locale, vendor, platform, screen, etc.)
|
|
80
|
+
deviceInfo: ["dv", "device_info", "deviceinfo"]
|
|
81
|
+
};
|
|
82
|
+
export const NORMALIZE_PARAMS = {
|
|
83
|
+
language: ["ul", "lang", "language", "languages"],
|
|
84
|
+
userAgent: ["ua", "useragent", "user_agent", "client_user_agent", "context.useragent"]
|
|
85
|
+
};
|
|
86
|
+
export function anonymizeIP(ip) {
|
|
87
|
+
if (ip.includes(":")) {
|
|
88
|
+
return `${ip.split(":").slice(0, 3).join(":")}::`;
|
|
89
|
+
}
|
|
90
|
+
const parts = ip.split(".");
|
|
91
|
+
if (parts.length === 4) {
|
|
92
|
+
parts[3] = "0";
|
|
93
|
+
return parts.join(".");
|
|
94
|
+
}
|
|
95
|
+
return ip;
|
|
96
|
+
}
|
|
97
|
+
export function normalizeUserAgent(ua) {
|
|
98
|
+
const tokens = [
|
|
99
|
+
["Edg/", "Edge"],
|
|
100
|
+
["OPR/", "Opera"],
|
|
101
|
+
["Opera/", "Opera"],
|
|
102
|
+
["Firefox/", "Firefox"],
|
|
103
|
+
["Chrome/", "Chrome"],
|
|
104
|
+
["Safari/", "Safari"]
|
|
105
|
+
];
|
|
106
|
+
for (const [pattern, family] of tokens) {
|
|
107
|
+
const idx = ua.indexOf(pattern);
|
|
108
|
+
if (idx !== -1) {
|
|
109
|
+
const versionStart = idx + pattern.length;
|
|
110
|
+
const majorVersion = ua.slice(versionStart).match(/^(\d+)/)?.[1];
|
|
111
|
+
if (majorVersion)
|
|
112
|
+
return `Mozilla/5.0 (compatible; ${family}/${majorVersion}.0)`;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return "Mozilla/5.0 (compatible)";
|
|
116
|
+
}
|
|
117
|
+
export function normalizeLanguage(lang) {
|
|
118
|
+
return lang.split(",")[0]?.split(";")[0]?.trim() || "en";
|
|
119
|
+
}
|
|
120
|
+
const SCREEN_BUCKETS = {
|
|
121
|
+
desktop: { w: 1920, h: 1080 },
|
|
122
|
+
tablet: { w: 768, h: 1024 },
|
|
123
|
+
mobile: { w: 360, h: 640 }
|
|
124
|
+
};
|
|
125
|
+
function getDeviceClass(width) {
|
|
126
|
+
if (width >= 1200)
|
|
127
|
+
return "desktop";
|
|
128
|
+
if (width >= 700)
|
|
129
|
+
return "tablet";
|
|
130
|
+
return "mobile";
|
|
131
|
+
}
|
|
132
|
+
export function generalizeScreen(value, dimension) {
|
|
133
|
+
if (typeof value === "string" && value.includes("x")) {
|
|
134
|
+
const width = Number.parseInt(value.split("x")[0] || "0");
|
|
135
|
+
const cls = getDeviceClass(width);
|
|
136
|
+
return `${SCREEN_BUCKETS[cls].w}x${SCREEN_BUCKETS[cls].h}`;
|
|
137
|
+
}
|
|
138
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
139
|
+
if (!Number.isNaN(num)) {
|
|
140
|
+
const cls = getDeviceClass(num);
|
|
141
|
+
const bucketed = dimension === "height" ? SCREEN_BUCKETS[cls].h : SCREEN_BUCKETS[cls].w;
|
|
142
|
+
return typeof value === "number" ? bucketed : String(bucketed);
|
|
143
|
+
}
|
|
144
|
+
return "1920x1080";
|
|
145
|
+
}
|
|
146
|
+
export function generalizeHardware(value) {
|
|
147
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
148
|
+
if (Number.isNaN(num))
|
|
149
|
+
return 4;
|
|
150
|
+
if (num >= 16)
|
|
151
|
+
return 16;
|
|
152
|
+
if (num >= 8)
|
|
153
|
+
return 8;
|
|
154
|
+
if (num >= 4)
|
|
155
|
+
return 4;
|
|
156
|
+
return 2;
|
|
157
|
+
}
|
|
158
|
+
export function generalizeVersion(value) {
|
|
159
|
+
if (typeof value !== "string")
|
|
160
|
+
return String(value);
|
|
161
|
+
const match = value.match(/^(\d+)(([.\-_])\d+)*/);
|
|
162
|
+
if (!match)
|
|
163
|
+
return String(value);
|
|
164
|
+
const major = match[1];
|
|
165
|
+
const sep = match[3] || ".";
|
|
166
|
+
const segmentCount = value.split(/[.\-_]/).length;
|
|
167
|
+
return major + `${sep}0`.repeat(segmentCount - 1);
|
|
168
|
+
}
|
|
169
|
+
export function generalizeBrowserVersions(value) {
|
|
170
|
+
if (typeof value !== "string")
|
|
171
|
+
return String(value);
|
|
172
|
+
const zeroSegments = (ver) => {
|
|
173
|
+
const parts = ver.split(".");
|
|
174
|
+
return parts[0] + parts.slice(1).map(() => ".0").join("");
|
|
175
|
+
};
|
|
176
|
+
if (value.includes('"version"'))
|
|
177
|
+
return value.replace(/("version"\s*:\s*")(\d+(?:\.\d+)*)/g, (_, prefix, ver) => prefix + zeroSegments(ver));
|
|
178
|
+
if (value.includes(";"))
|
|
179
|
+
return value.replace(/;(\d+(?:\.\d+)*)/g, (_, ver) => `;${zeroSegments(ver)}`);
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
export function generalizeTimezone(value) {
|
|
183
|
+
if (typeof value === "number") {
|
|
184
|
+
return Math.round(value / 180) * 180;
|
|
185
|
+
}
|
|
186
|
+
if (typeof value === "string") {
|
|
187
|
+
return "UTC";
|
|
188
|
+
}
|
|
189
|
+
return 0;
|
|
190
|
+
}
|
|
191
|
+
export function anonymizeDeviceInfo(value) {
|
|
192
|
+
const sep = value.includes("|") ? "|" : "&";
|
|
193
|
+
const parts = value.split(sep);
|
|
194
|
+
if (parts.length < 4)
|
|
195
|
+
return value;
|
|
196
|
+
const result = [...parts];
|
|
197
|
+
for (let i = 0; i < parts.length; i++) {
|
|
198
|
+
const part = parts[i];
|
|
199
|
+
if (part.includes("/") && /^[A-Z]/.test(part)) {
|
|
200
|
+
result[i] = String(generalizeTimezone(part));
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (/^[a-z]{2}(?:-[a-z]{2,})?$/i.test(part)) {
|
|
204
|
+
result[i] = normalizeLanguage(part);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const num = Number(part);
|
|
208
|
+
if (!Number.isNaN(num) && num >= 300 && num <= 1e4) {
|
|
209
|
+
const nextNum = Number(parts[i + 1]);
|
|
210
|
+
if (!Number.isNaN(nextNum) && nextNum >= 300 && nextNum <= 1e4) {
|
|
211
|
+
const cls = getDeviceClass(num);
|
|
212
|
+
result[i] = String(SCREEN_BUCKETS[cls].w);
|
|
213
|
+
result[i + 1] = String(SCREEN_BUCKETS[cls].h);
|
|
214
|
+
i++;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
result[i] = String(generalizeScreen(num));
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (!Number.isNaN(num) && num < -60) {
|
|
221
|
+
result[i] = String(generalizeTimezone(num));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return result.join(sep);
|
|
225
|
+
}
|
|
226
|
+
export function stripPayloadFingerprinting(payload, privacy) {
|
|
227
|
+
const p = privacy || FULL_PRIVACY;
|
|
228
|
+
const result = {};
|
|
229
|
+
let deviceClass;
|
|
230
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
231
|
+
if (key.toLowerCase() === "sw") {
|
|
232
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
233
|
+
if (!Number.isNaN(num))
|
|
234
|
+
deviceClass = getDeviceClass(num);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
for (const [key, value] of Object.entries(payload)) {
|
|
238
|
+
const lowerKey = key.toLowerCase();
|
|
239
|
+
const matchesParam = (key2, params) => {
|
|
240
|
+
const lk = key2.toLowerCase();
|
|
241
|
+
return params.some((pm) => {
|
|
242
|
+
const lp = pm.toLowerCase();
|
|
243
|
+
return lk === lp || lk.startsWith(`${lp}[`);
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
const isLanguageParam = NORMALIZE_PARAMS.language.some((pm) => lowerKey === pm.toLowerCase());
|
|
247
|
+
if (isLanguageParam) {
|
|
248
|
+
if (Array.isArray(value)) {
|
|
249
|
+
result[key] = p.language ? value.map((v) => typeof v === "string" ? normalizeLanguage(v) : v) : value;
|
|
250
|
+
} else if (typeof value === "string") {
|
|
251
|
+
result[key] = p.language ? normalizeLanguage(value) : value;
|
|
252
|
+
} else {
|
|
253
|
+
result[key] = value;
|
|
254
|
+
}
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const isUserAgentParam = NORMALIZE_PARAMS.userAgent.some((pm) => lowerKey === pm.toLowerCase());
|
|
258
|
+
if (isUserAgentParam && typeof value === "string") {
|
|
259
|
+
result[key] = p.userAgent ? normalizeUserAgent(value) : value;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
if (matchesParam(key, STRIP_PARAMS.ip) && typeof value === "string") {
|
|
263
|
+
result[key] = p.ip ? anonymizeIP(value) : value;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (matchesParam(key, STRIP_PARAMS.screen)) {
|
|
267
|
+
if (!p.screen) {
|
|
268
|
+
result[key] = value;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (["sd", "colordepth", "pixelratio"].includes(lowerKey)) {
|
|
272
|
+
result[key] = value;
|
|
273
|
+
} else if (lowerKey === "sh" && deviceClass) {
|
|
274
|
+
const paired = SCREEN_BUCKETS[deviceClass].h;
|
|
275
|
+
result[key] = typeof value === "number" ? paired : String(paired);
|
|
276
|
+
} else {
|
|
277
|
+
result[key] = generalizeScreen(value, lowerKey === "sw" ? "width" : lowerKey === "sh" ? "height" : void 0);
|
|
278
|
+
}
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (matchesParam(key, STRIP_PARAMS.hardware)) {
|
|
282
|
+
result[key] = p.screen ? generalizeHardware(value) : value;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (matchesParam(key, STRIP_PARAMS.version)) {
|
|
286
|
+
result[key] = p.hardware ? generalizeVersion(value) : value;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (matchesParam(key, STRIP_PARAMS.browserVersion)) {
|
|
290
|
+
result[key] = p.hardware ? generalizeBrowserVersions(value) : value;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
if (matchesParam(key, STRIP_PARAMS.location)) {
|
|
294
|
+
result[key] = p.timezone ? generalizeTimezone(value) : value;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (matchesParam(key, STRIP_PARAMS.browserData)) {
|
|
298
|
+
result[key] = p.hardware ? Array.isArray(value) ? [] : "" : value;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (matchesParam(key, STRIP_PARAMS.canvas)) {
|
|
302
|
+
result[key] = p.hardware ? typeof value === "number" ? 0 : typeof value === "object" ? {} : "" : value;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
if (matchesParam(key, STRIP_PARAMS.deviceInfo)) {
|
|
306
|
+
result[key] = p.hardware ? typeof value === "string" ? anonymizeDeviceInfo(value) : "" : value;
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
if (matchesParam(key, STRIP_PARAMS.platform)) {
|
|
310
|
+
result[key] = value;
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (Array.isArray(value)) {
|
|
314
|
+
result[key] = value.map(
|
|
315
|
+
(item) => typeof item === "object" && item !== null ? stripPayloadFingerprinting(item, privacy) : item
|
|
316
|
+
);
|
|
317
|
+
} else if (typeof value === "object" && value !== null) {
|
|
318
|
+
result[key] = stripPayloadFingerprinting(value, privacy);
|
|
319
|
+
} else {
|
|
320
|
+
result[key] = value;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
@@ -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.from({ length: 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
|
+
});
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,36 +1,45 @@
|
|
|
1
|
+
import type { UseScriptInput, UseScriptOptions, VueScriptInstance } from '@unhead/vue';
|
|
1
2
|
import type { Script } from '@unhead/vue/types';
|
|
2
|
-
import type { UseScriptInput, VueScriptInstance, UseScriptOptions } from '@unhead/vue';
|
|
3
|
-
import type { ComputedRef, Ref } from 'vue';
|
|
4
|
-
import type { InferInput, ObjectSchema, ValiError } from 'valibot';
|
|
5
3
|
import type { Import } from 'unimport';
|
|
6
|
-
import type {
|
|
4
|
+
import type { InferInput, ObjectSchema, ValiError } from 'valibot';
|
|
5
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
6
|
+
import type { ClarityInput } from './registry/clarity.js';
|
|
7
7
|
import type { CloudflareWebAnalyticsInput } from './registry/cloudflare-web-analytics.js';
|
|
8
|
+
import type { CrispInput } from './registry/crisp.js';
|
|
8
9
|
import type { DatabuddyAnalyticsInput } from './registry/databuddy-analytics.js';
|
|
9
|
-
import type { MetaPixelInput } from './registry/meta-pixel.js';
|
|
10
10
|
import type { FathomAnalyticsInput } from './registry/fathom-analytics.js';
|
|
11
|
+
import type { GoogleAdsenseInput } from './registry/google-adsense.js';
|
|
12
|
+
import type { GoogleAnalyticsInput } from './registry/google-analytics.js';
|
|
13
|
+
import type { GoogleMapsInput } from './registry/google-maps.js';
|
|
14
|
+
import type { GoogleRecaptchaInput } from './registry/google-recaptcha.js';
|
|
15
|
+
import type { GoogleTagManagerInput } from './registry/google-tag-manager.js';
|
|
11
16
|
import type { HotjarInput } from './registry/hotjar.js';
|
|
12
17
|
import type { IntercomInput } from './registry/intercom.js';
|
|
13
|
-
import type {
|
|
18
|
+
import type { LemonSqueezyInput } from './registry/lemon-squeezy.js';
|
|
14
19
|
import type { MatomoAnalyticsInput } from './registry/matomo-analytics.js';
|
|
20
|
+
import type { MetaPixelInput } from './registry/meta-pixel.js';
|
|
21
|
+
import type { NpmInput } from './registry/npm.js';
|
|
22
|
+
import type { PayPalInput } from './registry/paypal.js';
|
|
23
|
+
import type { PlausibleAnalyticsInput } from './registry/plausible-analytics.js';
|
|
24
|
+
import type { PostHogInput } from './registry/posthog.js';
|
|
25
|
+
import type { RedditPixelInput } from './registry/reddit-pixel.js';
|
|
26
|
+
import type { RybbitAnalyticsInput } from './registry/rybbit-analytics.js';
|
|
27
|
+
import type { SegmentInput } from './registry/segment.js';
|
|
28
|
+
import type { SnapTrPixelInput } from './registry/snapchat-pixel.js';
|
|
15
29
|
import type { StripeInput } from './registry/stripe.js';
|
|
30
|
+
import type { TikTokPixelInput } from './registry/tiktok-pixel.js';
|
|
31
|
+
import type { UmamiAnalyticsInput } from './registry/umami-analytics.js';
|
|
16
32
|
import type { VimeoPlayerInput } from './registry/vimeo-player.js';
|
|
17
33
|
import type { XPixelInput } from './registry/x-pixel.js';
|
|
18
|
-
import type { SnapTrPixelInput } from './registry/snapchat-pixel.js';
|
|
19
34
|
import type { YouTubePlayerInput } from './registry/youtube-player.js';
|
|
20
|
-
import type { PlausibleAnalyticsInput } from './registry/plausible-analytics.js';
|
|
21
|
-
import type { NpmInput } from './registry/npm.js';
|
|
22
|
-
import type { LemonSqueezyInput } from './registry/lemon-squeezy.js';
|
|
23
|
-
import type { GoogleAdsenseInput } from './registry/google-adsense.js';
|
|
24
|
-
import type { ClarityInput } from './registry/clarity.js';
|
|
25
|
-
import type { CrispInput } from './registry/crisp.js';
|
|
26
|
-
import type { GoogleAnalyticsInput } from './registry/google-analytics.js';
|
|
27
|
-
import type { GoogleTagManagerInput } from './registry/google-tag-manager.js';
|
|
28
|
-
import type { UmamiAnalyticsInput } from './registry/umami-analytics.js';
|
|
29
|
-
import type { RybbitAnalyticsInput } from './registry/rybbit-analytics.js';
|
|
30
|
-
import type { RedditPixelInput } from './registry/reddit-pixel.js';
|
|
31
|
-
import type { PayPalInput } from './registry/paypal.js';
|
|
32
35
|
export type WarmupStrategy = false | 'preload' | 'preconnect' | 'dns-prefetch';
|
|
33
|
-
export type UseScriptContext<T extends Record<symbol | string, any>> = VueScriptInstance<T
|
|
36
|
+
export type UseScriptContext<T extends Record<symbol | string, any>> = VueScriptInstance<T> & {
|
|
37
|
+
/**
|
|
38
|
+
* Remove and reload the script. Useful for scripts that need to re-execute
|
|
39
|
+
* after SPA navigation (e.g., DOM-scanning scripts like iubenda).
|
|
40
|
+
*/
|
|
41
|
+
reload: () => Promise<T>;
|
|
42
|
+
};
|
|
34
43
|
export type NuxtUseScriptOptions<T extends Record<symbol | string, any> = {}> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
35
44
|
/**
|
|
36
45
|
* The trigger to load the script:
|
|
@@ -48,8 +57,24 @@ export type NuxtUseScriptOptions<T extends Record<symbol | string, any> = {}> =
|
|
|
48
57
|
* - `false` - Do not bundle the script. (default)
|
|
49
58
|
*
|
|
50
59
|
* Note: Using 'force' may significantly increase build time as scripts will be re-downloaded on every build.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Use `scripts.firstParty: true` in nuxt.config instead for bundling and routing scripts through your domain.
|
|
51
62
|
*/
|
|
52
63
|
bundle?: boolean | 'force';
|
|
64
|
+
/**
|
|
65
|
+
* Opt-out of first-party routing for this specific script when global `scripts.firstParty` is enabled.
|
|
66
|
+
* Set to `false` to load this script directly from its original source instead of through your domain.
|
|
67
|
+
*
|
|
68
|
+
* Note: This option only works as an opt-out. To enable first-party routing, use the global `scripts.firstParty` option in nuxt.config.
|
|
69
|
+
*/
|
|
70
|
+
firstParty?: false;
|
|
71
|
+
/**
|
|
72
|
+
* Load the script in a web worker using Partytown.
|
|
73
|
+
* When enabled, adds `type="text/partytown"` to the script tag.
|
|
74
|
+
* Requires @nuxtjs/partytown to be installed and configured separately.
|
|
75
|
+
* @see https://partytown.qwik.dev/
|
|
76
|
+
*/
|
|
77
|
+
partytown?: boolean;
|
|
53
78
|
/**
|
|
54
79
|
* Skip any schema validation for the script input. This is useful for loading the script stubs for development without
|
|
55
80
|
* loading the actual script and not getting warnings.
|
|
@@ -90,6 +115,8 @@ export type NuxtUseScriptOptionsSerializable = Omit<NuxtUseScriptOptions, 'use'
|
|
|
90
115
|
idleTimeout: number;
|
|
91
116
|
} | {
|
|
92
117
|
interaction: string[];
|
|
118
|
+
} | {
|
|
119
|
+
serviceWorker: true;
|
|
93
120
|
};
|
|
94
121
|
};
|
|
95
122
|
export type NuxtUseScriptInput = UseScriptInput;
|
|
@@ -135,16 +162,19 @@ export interface ScriptRegistry {
|
|
|
135
162
|
googleAdsense?: GoogleAdsenseInput;
|
|
136
163
|
googleAnalytics?: GoogleAnalyticsInput;
|
|
137
164
|
googleMaps?: GoogleMapsInput;
|
|
165
|
+
googleRecaptcha?: GoogleRecaptchaInput;
|
|
138
166
|
lemonSqueezy?: LemonSqueezyInput;
|
|
139
167
|
googleTagManager?: GoogleTagManagerInput;
|
|
140
168
|
hotjar?: HotjarInput;
|
|
141
169
|
intercom?: IntercomInput;
|
|
142
170
|
paypal?: PayPalInput;
|
|
171
|
+
posthog?: PostHogInput;
|
|
143
172
|
matomoAnalytics?: MatomoAnalyticsInput;
|
|
144
173
|
rybbitAnalytics?: RybbitAnalyticsInput;
|
|
145
174
|
redditPixel?: RedditPixelInput;
|
|
146
175
|
segment?: SegmentInput;
|
|
147
176
|
stripe?: StripeInput;
|
|
177
|
+
tiktokPixel?: TikTokPixelInput;
|
|
148
178
|
xPixel?: XPixelInput;
|
|
149
179
|
snapchatPixel?: SnapTrPixelInput;
|
|
150
180
|
youtubePlayer?: YouTubePlayerInput;
|
|
@@ -181,6 +211,17 @@ export type RegistryScriptInput<T = EmptyOptionsSchema, Bundelable extends boole
|
|
|
181
211
|
export interface RegistryScript {
|
|
182
212
|
import?: Import;
|
|
183
213
|
scriptBundling?: false | ((options?: any) => string | false);
|
|
214
|
+
/**
|
|
215
|
+
* First-party routing configuration for this script.
|
|
216
|
+
* - `string` - The proxy config key to use (e.g., 'googleAnalytics', 'metaPixel')
|
|
217
|
+
* - `false` - Explicitly disable first-party routing for this script
|
|
218
|
+
* - `undefined` - Use the default key derived from the function name
|
|
219
|
+
*
|
|
220
|
+
* When set to a string, the script's URLs will be rewritten and collection
|
|
221
|
+
* endpoints will be routed through your server when `scripts.firstParty` is enabled.
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
proxy?: string | false;
|
|
184
225
|
label?: string;
|
|
185
226
|
src?: string | false;
|
|
186
227
|
category?: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy configuration for third-party scripts.
|
|
3
|
+
*/
|
|
4
|
+
export interface ProxyRewrite {
|
|
5
|
+
/** Domain and path to match (e.g., 'www.google-analytics.com/g/collect') */
|
|
6
|
+
from: string;
|
|
7
|
+
/** Local path to rewrite to (e.g., '/_scripts/c/ga/g/collect') */
|
|
8
|
+
to: string;
|
|
9
|
+
}
|
|
File without changes
|
package/dist/runtime/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EmptyOptionsSchema, InferIfSchema, NuxtUseScriptOptions, RegistryScriptInput, ScriptRegistry, UseFunctionType, UseScriptContext } from '#nuxt-scripts/types';
|
|
2
2
|
import type { UseScriptInput } from '@unhead/vue';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ObjectSchema } from 'valibot';
|
|
4
4
|
export type MaybePromise<T> = Promise<T> | T;
|
|
5
5
|
type OptionsFn<O> = (options: InferIfSchema<O>, ctx: {
|
|
6
6
|
scriptInput?: UseScriptInput & {
|
|
@@ -10,8 +10,9 @@ type OptionsFn<O> = (options: InferIfSchema<O>, ctx: {
|
|
|
10
10
|
scriptInput?: UseScriptInput;
|
|
11
11
|
scriptOptions?: NuxtUseScriptOptions;
|
|
12
12
|
schema?: O extends ObjectSchema<any, any> ? O : undefined;
|
|
13
|
-
clientInit?: () => void
|
|
13
|
+
clientInit?: () => void | Promise<any>;
|
|
14
|
+
scriptMode?: 'external' | 'npm';
|
|
14
15
|
});
|
|
15
16
|
export declare function scriptRuntimeConfig<T extends keyof ScriptRegistry>(key: T): ScriptRegistry[T];
|
|
16
17
|
export declare function useRegistryScript<T extends Record<string | symbol, any>, O = EmptyOptionsSchema>(registryKey: keyof ScriptRegistry | string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>>;
|
|
17
|
-
export
|
|
18
|
+
export * from './utils/pure.js';
|
package/dist/runtime/utils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { parse } from "#nuxt-scripts-validator";
|
|
1
2
|
import { defu } from "defu";
|
|
2
3
|
import { useRuntimeConfig } from "nuxt/app";
|
|
4
|
+
import { parseQuery, parseURL, withQuery } from "ufo";
|
|
3
5
|
import { useScript } from "./composables/useScript.js";
|
|
4
|
-
import {
|
|
5
|
-
import { parseURL, withQuery, parseQuery } from "ufo";
|
|
6
|
+
import { createNpmScriptStub } from "./npm-script-stub.js";
|
|
6
7
|
function validateScriptInputSchema(key, schema, options) {
|
|
7
8
|
if (import.meta.dev) {
|
|
8
9
|
try {
|
|
@@ -20,6 +21,14 @@ export function useRegistryScript(registryKey, optionsFn, _userOptions) {
|
|
|
20
21
|
const scriptConfig = scriptRuntimeConfig(registryKey);
|
|
21
22
|
const userOptions = Object.assign(_userOptions || {}, typeof scriptConfig === "object" ? scriptConfig : {});
|
|
22
23
|
const options = optionsFn(userOptions, { scriptInput: userOptions.scriptInput });
|
|
24
|
+
if (options.scriptMode === "npm") {
|
|
25
|
+
return createNpmScriptStub({
|
|
26
|
+
key: String(registryKey),
|
|
27
|
+
use: options.scriptOptions?.use,
|
|
28
|
+
clientInit: options.clientInit,
|
|
29
|
+
trigger: userOptions.scriptOptions?.trigger
|
|
30
|
+
});
|
|
31
|
+
}
|
|
23
32
|
let finalScriptInput = options.scriptInput;
|
|
24
33
|
const userSrc = userOptions.scriptInput?.src;
|
|
25
34
|
const optionsSrc = options.scriptInput?.src;
|
|
@@ -86,3 +95,4 @@ export function useRegistryScript(registryKey, optionsFn, _userOptions) {
|
|
|
86
95
|
};
|
|
87
96
|
return useScript(scriptInput, scriptOptions);
|
|
88
97
|
}
|
|
98
|
+
export * from "./utils/pure.js";
|