@nuxt/scripts 1.3.6 → 2.0.0-beta.1

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 (207) hide show
  1. package/THIRD_PARTY_LICENSES.md +124 -0
  2. package/dist/devtools-client/200.html +1 -1
  3. package/dist/devtools-client/404.html +1 -1
  4. package/dist/devtools-client/_nuxt/{B551Pnuh.js → 2p1_IuX2.js} +1 -1
  5. package/dist/devtools-client/_nuxt/{KxC4Q3ev.js → 9elIQxwW.js} +1 -1
  6. package/dist/devtools-client/_nuxt/{DTP8MRtW.js → BNPn63Jz.js} +1 -1
  7. package/dist/devtools-client/_nuxt/BjRLaDIG.js +152 -0
  8. package/dist/devtools-client/_nuxt/BtNUYBXT.js +8 -0
  9. package/dist/devtools-client/_nuxt/CDDBpkXG.js +3 -0
  10. package/dist/devtools-client/_nuxt/Cpb0XAYP.js +1 -0
  11. package/dist/devtools-client/_nuxt/DAsiyhPm.js +6 -0
  12. package/dist/devtools-client/_nuxt/{VICyrUSM.js → DabLKy7M.js} +1 -1
  13. package/dist/devtools-client/_nuxt/Dat651Oh.js +1 -0
  14. package/dist/devtools-client/_nuxt/DcG2ZXvY.js +1 -0
  15. package/dist/devtools-client/_nuxt/DmlGWZ2X.js +1 -0
  16. package/dist/devtools-client/_nuxt/KsX6Az5B.js +1 -0
  17. package/dist/devtools-client/_nuxt/RL1np866.js +28 -0
  18. package/dist/devtools-client/_nuxt/UmWNrBO5.js +2 -0
  19. package/dist/devtools-client/_nuxt/builds/latest.json +1 -1
  20. package/dist/devtools-client/_nuxt/builds/meta/e28b96f1-78e8-41a4-ad6f-904cd078f85e.json +1 -0
  21. package/dist/devtools-client/_nuxt/{entry.CYUdJFoE.css → entry.9HJPJ6Hp.css} +1 -1
  22. package/dist/devtools-client/_nuxt/error-404.DnwL1N6v.css +1 -0
  23. package/dist/devtools-client/_nuxt/error-500.DEbXRLdm.css +1 -0
  24. package/dist/devtools-client/docs/index.html +1 -1
  25. package/dist/devtools-client/first-party/index.html +1 -1
  26. package/dist/devtools-client/index.html +1 -1
  27. package/dist/devtools-client/registry/index.html +1 -1
  28. package/dist/module.d.mts +2 -86
  29. package/dist/module.d.ts +2 -86
  30. package/dist/module.json +3 -3
  31. package/dist/module.mjs +71 -328
  32. package/dist/registry.mjs +54 -22
  33. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.d.vue.ts +1 -28
  34. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue +7 -50
  35. package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue.d.ts +1 -28
  36. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.d.vue.ts +0 -8
  37. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue +1 -13
  38. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsOverlayView.vue.d.ts +0 -8
  39. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsStaticMap.d.vue.ts +4 -4
  40. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsStaticMap.vue +9 -15
  41. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsStaticMap.vue.d.ts +4 -4
  42. package/dist/runtime/components/GoogleMaps/useGoogleMapsResource.d.ts +0 -22
  43. package/dist/runtime/components/GoogleMaps/useGoogleMapsResource.js +0 -31
  44. package/dist/runtime/components/Leaflet/ScriptLeafletGeoJson.d.vue.ts +31 -0
  45. package/dist/runtime/components/Leaflet/ScriptLeafletGeoJson.vue +43 -0
  46. package/dist/runtime/components/Leaflet/ScriptLeafletGeoJson.vue.d.ts +31 -0
  47. package/dist/runtime/components/Leaflet/ScriptLeafletMap.d.vue.ts +90 -0
  48. package/dist/runtime/components/Leaflet/ScriptLeafletMap.vue +171 -0
  49. package/dist/runtime/components/Leaflet/ScriptLeafletMap.vue.d.ts +90 -0
  50. package/dist/runtime/components/Leaflet/ScriptLeafletMarker.d.vue.ts +47 -0
  51. package/dist/runtime/components/Leaflet/ScriptLeafletMarker.vue +70 -0
  52. package/dist/runtime/components/Leaflet/ScriptLeafletMarker.vue.d.ts +47 -0
  53. package/dist/runtime/components/Leaflet/ScriptLeafletPopup.d.vue.ts +31 -0
  54. package/dist/runtime/components/Leaflet/ScriptLeafletPopup.vue +81 -0
  55. package/dist/runtime/components/Leaflet/ScriptLeafletPopup.vue.d.ts +31 -0
  56. package/dist/runtime/components/Leaflet/ScriptLeafletTileLayer.d.vue.ts +26 -0
  57. package/dist/runtime/components/Leaflet/ScriptLeafletTileLayer.vue +38 -0
  58. package/dist/runtime/components/Leaflet/ScriptLeafletTileLayer.vue.d.ts +26 -0
  59. package/dist/runtime/components/Leaflet/useLeafletResource.d.ts +30 -0
  60. package/dist/runtime/components/Leaflet/useLeafletResource.js +46 -0
  61. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.d.vue.ts +39 -0
  62. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.vue +84 -0
  63. package/dist/runtime/components/MapLibre/ScriptMapLibreGeoJson.vue.d.ts +39 -0
  64. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.d.vue.ts +122 -0
  65. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.vue +214 -0
  66. package/dist/runtime/components/MapLibre/ScriptMapLibreMap.vue.d.ts +122 -0
  67. package/dist/runtime/components/MapLibre/ScriptMapLibreMarker.d.vue.ts +35 -0
  68. package/dist/runtime/components/MapLibre/ScriptMapLibreMarker.vue +98 -0
  69. package/dist/runtime/components/MapLibre/ScriptMapLibreMarker.vue.d.ts +35 -0
  70. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.d.vue.ts +12 -0
  71. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.vue +23 -0
  72. package/dist/runtime/components/MapLibre/ScriptMapLibreNavigationControl.vue.d.ts +12 -0
  73. package/dist/runtime/components/MapLibre/ScriptMapLibrePopup.d.vue.ts +31 -0
  74. package/dist/runtime/components/MapLibre/ScriptMapLibrePopup.vue +99 -0
  75. package/dist/runtime/components/MapLibre/ScriptMapLibrePopup.vue.d.ts +31 -0
  76. package/dist/runtime/components/MapLibre/useMapLibreResource.d.ts +23 -0
  77. package/dist/runtime/components/MapLibre/useMapLibreResource.js +41 -0
  78. package/dist/runtime/components/ScriptCrisp.vue +20 -18
  79. package/dist/runtime/components/ScriptDeskCrew.d.vue.ts +40 -0
  80. package/dist/runtime/components/ScriptDeskCrew.vue +82 -0
  81. package/dist/runtime/components/ScriptDeskCrew.vue.d.ts +40 -0
  82. package/dist/runtime/components/ScriptIntercom.vue +21 -19
  83. package/dist/runtime/components/ScriptLoadingIndicator.d.vue.ts +1 -1
  84. package/dist/runtime/components/ScriptLoadingIndicator.vue.d.ts +1 -1
  85. package/dist/runtime/components/ScriptPayPalButtons.vue +7 -3
  86. package/dist/runtime/components/ScriptPayPalMessages.vue +8 -4
  87. package/dist/runtime/composables/useScript.js +96 -49
  88. package/dist/runtime/composables/useScriptProxyUrl.d.ts +4 -8
  89. package/dist/runtime/composables/useScriptProxyUrl.js +0 -7
  90. package/dist/runtime/composables/useScriptTriggerIdleTimeout.d.ts +2 -1
  91. package/dist/runtime/composables/useScriptTriggerIdleTimeout.js +3 -34
  92. package/dist/runtime/composables/useScriptTriggerInteraction.d.ts +2 -1
  93. package/dist/runtime/composables/useScriptTriggerInteraction.js +13 -46
  94. package/dist/runtime/composables/useScriptTriggerServiceWorker.d.ts +2 -1
  95. package/dist/runtime/composables/useScriptTriggerServiceWorker.js +5 -38
  96. package/dist/runtime/leaflet-styles.d.ts +13 -0
  97. package/dist/runtime/leaflet-styles.js +684 -0
  98. package/dist/runtime/maplibre-styles.d.ts +7 -0
  99. package/dist/runtime/maplibre-styles.js +25 -0
  100. package/dist/runtime/npm-script-api-state.d.ts +4 -0
  101. package/dist/runtime/npm-script-api-state.js +13 -0
  102. package/dist/runtime/registry/crisp.d.ts +1 -1
  103. package/dist/runtime/registry/crisp.js +30 -18
  104. package/dist/runtime/registry/deskcrew.d.ts +52 -0
  105. package/dist/runtime/registry/deskcrew.js +31 -0
  106. package/dist/runtime/registry/google-analytics.d.ts +0 -2
  107. package/dist/runtime/registry/google-maps.d.ts +2 -11
  108. package/dist/runtime/registry/google-maps.js +31 -10
  109. package/dist/runtime/registry/google-tag-manager.d.ts +0 -2
  110. package/dist/runtime/registry/leaflet.d.ts +13 -0
  111. package/dist/runtime/registry/leaflet.js +29 -0
  112. package/dist/runtime/registry/maplibre.d.ts +13 -0
  113. package/dist/runtime/registry/maplibre.js +29 -0
  114. package/dist/runtime/registry/matomo-analytics.js +1 -8
  115. package/dist/runtime/registry/plausible-analytics.d.ts +4 -16
  116. package/dist/runtime/registry/plausible-analytics.js +15 -58
  117. package/dist/runtime/registry/rybbit-analytics.d.ts +0 -4
  118. package/dist/runtime/registry/rybbit-analytics.js +1 -4
  119. package/dist/runtime/registry/schemas.d.ts +61 -5
  120. package/dist/runtime/registry/schemas.js +64 -5
  121. package/dist/runtime/registry/tiktok-pixel.d.ts +2 -12
  122. package/dist/runtime/registry/tiktok-pixel.js +1 -1
  123. package/dist/runtime/registry/usercentrics.js +46 -6
  124. package/dist/runtime/registry/youtube-player.d.ts +3 -4
  125. package/dist/runtime/registry/youtube-player.js +30 -23
  126. package/dist/runtime/server/bluesky-embed-image.d.ts +1 -1
  127. package/dist/runtime/server/bluesky-embed.d.ts +1 -1
  128. package/dist/runtime/server/bluesky-embed.js +3 -6
  129. package/dist/runtime/server/gravatar-proxy.d.ts +1 -1
  130. package/dist/runtime/server/gravatar-proxy.js +2 -3
  131. package/dist/runtime/server/instagram-embed-asset.d.ts +1 -1
  132. package/dist/runtime/server/instagram-embed-image.d.ts +1 -1
  133. package/dist/runtime/server/instagram-embed.d.ts +1 -1
  134. package/dist/runtime/server/instagram-embed.js +4 -7
  135. package/dist/runtime/server/utils/cached-upstream.d.ts +4 -11
  136. package/dist/runtime/server/utils/embed-rewriters.d.ts +3 -5
  137. package/dist/runtime/server/utils/embed-rewriters.js +8 -8
  138. package/dist/runtime/server/utils/image-proxy.d.ts +1 -1
  139. package/dist/runtime/server/utils/image-proxy.js +2 -3
  140. package/dist/runtime/server/utils/instagram-embed.d.ts +6 -6
  141. package/dist/runtime/server/utils/instagram-embed.js +18 -19
  142. package/dist/runtime/server/utils/proxy-url.d.ts +5 -6
  143. package/dist/runtime/server/utils/proxy-url.js +1 -4
  144. package/dist/runtime/server/x-embed-image.d.ts +1 -1
  145. package/dist/runtime/server/x-embed.d.ts +48 -1
  146. package/dist/runtime/server/x-embed.js +3 -6
  147. package/dist/runtime/types.d.ts +13 -13
  148. package/dist/runtime/utils/abortable-promise.js +26 -5
  149. package/dist/runtime/utils/nuxt-ready-script-trigger.d.ts +3 -0
  150. package/dist/runtime/utils/nuxt-ready-script-trigger.js +16 -0
  151. package/dist/runtime/utils.js +21 -32
  152. package/dist/stats.mjs +13 -0
  153. package/dist/types-source.mjs +1173 -100
  154. package/dist/types.d.mts +2 -2
  155. package/package.json +34 -21
  156. package/LICENSE.md +0 -9
  157. package/bin/cli.mjs +0 -2
  158. package/dist/cli.d.mts +0 -2
  159. package/dist/cli.d.ts +0 -2
  160. package/dist/cli.mjs +0 -50
  161. package/dist/devtools-client/_nuxt/8ltZ0o6d.js +0 -1
  162. package/dist/devtools-client/_nuxt/B8_EBdhg.js +0 -152
  163. package/dist/devtools-client/_nuxt/BKdLzFmX.js +0 -3
  164. package/dist/devtools-client/_nuxt/Bf2Kt1P0.js +0 -28
  165. package/dist/devtools-client/_nuxt/CC0GKROJ.js +0 -1
  166. package/dist/devtools-client/_nuxt/CH5oUfNi.js +0 -1
  167. package/dist/devtools-client/_nuxt/CMXzQxJZ.js +0 -1
  168. package/dist/devtools-client/_nuxt/CP7c-Js6.js +0 -8
  169. package/dist/devtools-client/_nuxt/C_v3_O0R.js +0 -6
  170. package/dist/devtools-client/_nuxt/CxN78VhB.js +0 -1
  171. package/dist/devtools-client/_nuxt/Dkc7iTdR.js +0 -1
  172. package/dist/devtools-client/_nuxt/builds/meta/35e54cbc-079c-4313-8838-34632d9dac97.json +0 -1
  173. package/dist/devtools-client/_nuxt/error-404.Bq2JQbJs.css +0 -1
  174. package/dist/devtools-client/_nuxt/error-500.5E_FOzlc.css +0 -1
  175. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.d.vue.ts +0 -13
  176. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.vue +0 -15
  177. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsAdvancedMarkerElement.vue.d.ts +0 -13
  178. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsHeatmapLayer.d.vue.ts +0 -27
  179. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsHeatmapLayer.vue +0 -34
  180. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsHeatmapLayer.vue.d.ts +0 -27
  181. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.d.vue.ts +0 -13
  182. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.vue +0 -11
  183. package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.vue.d.ts +0 -13
  184. package/dist/runtime/components/GoogleMaps/bindGoogleMapsEvents.d.ts +0 -13
  185. package/dist/runtime/components/GoogleMaps/bindGoogleMapsEvents.js +0 -8
  186. package/dist/runtime/components/GoogleMaps/injectionKeys.d.ts +0 -10
  187. package/dist/runtime/components/GoogleMaps/injectionKeys.js +0 -2
  188. package/dist/runtime/composables/useScriptProxyToken.d.ts +0 -12
  189. package/dist/runtime/composables/useScriptProxyToken.js +0 -4
  190. package/dist/runtime/npm-script-stub.d.ts +0 -20
  191. package/dist/runtime/npm-script-stub.js +0 -72
  192. package/dist/runtime/plugins/proxy-token.server.d.ts +0 -10
  193. package/dist/runtime/plugins/proxy-token.server.js +0 -17
  194. package/dist/runtime/server/google-maps-geocode-proxy.d.ts +0 -2
  195. package/dist/runtime/server/google-maps-geocode-proxy.js +0 -43
  196. package/dist/runtime/server/google-static-maps-proxy.d.ts +0 -2
  197. package/dist/runtime/server/google-static-maps-proxy.js +0 -56
  198. package/dist/runtime/server/utils/proxy-query.d.ts +0 -2
  199. package/dist/runtime/server/utils/proxy-query.js +0 -10
  200. package/dist/runtime/server/utils/sign-constants.d.ts +0 -16
  201. package/dist/runtime/server/utils/sign-constants.js +0 -5
  202. package/dist/runtime/server/utils/sign.d.ts +0 -101
  203. package/dist/runtime/server/utils/sign.js +0 -91
  204. package/dist/runtime/server/utils/withSigning.d.ts +0 -23
  205. package/dist/runtime/server/utils/withSigning.js +0 -19
  206. package/dist/runtime/unhead-features.d.ts +0 -1
  207. package/dist/runtime/unhead-features.js +0 -3
@@ -1,17 +0,0 @@
1
- import { defineNuxtPlugin, useRuntimeConfig } from "nuxt/app";
2
- import { useScriptProxyToken } from "../composables/useScriptProxyToken.js";
3
- import { generateProxyToken } from "../server/utils/sign.js";
4
- export default defineNuxtPlugin({
5
- name: "nuxt-scripts:proxy-token",
6
- enforce: "pre",
7
- setup() {
8
- const secret = useRuntimeConfig()["nuxt-scripts"]?.proxySecret;
9
- if (!secret)
10
- return;
11
- const ts = Math.floor(Date.now() / 1e3);
12
- useScriptProxyToken().value = {
13
- token: generateProxyToken(secret, ts),
14
- ts
15
- };
16
- }
17
- });
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, any>;
2
- export default _default;
@@ -1,43 +0,0 @@
1
- import { withQuery } from "ufo";
2
- import { createError, defineEventHandler, getQuery, setHeader } from "#nuxt-scripts/h3";
3
- import { useRuntimeConfig } from "#nuxt-scripts/nitro";
4
- import { createCachedJsonFetch, isSafeHttpsUrl } from "./utils/cached-upstream.js";
5
- import { stripProxyAuthQuery } from "./utils/proxy-query.js";
6
- import { withSigning } from "./utils/withSigning.js";
7
- const cachedGeocodeFetch = createCachedJsonFetch(
8
- "nuxt-scripts-geocode",
9
- 2592e3,
10
- (url) => url,
11
- {
12
- allowUrl: (url) => isSafeHttpsUrl(url) && url.hostname === "maps.googleapis.com",
13
- contentTypePrefixes: ["application/json"]
14
- }
15
- );
16
- export default withSigning(defineEventHandler(async (event) => {
17
- const runtimeConfig = useRuntimeConfig();
18
- const privateConfig = runtimeConfig["nuxt-scripts"]?.googleMapsGeocodeProxy;
19
- const apiKey = privateConfig?.apiKey;
20
- if (!apiKey) {
21
- throw createError({
22
- statusCode: 500,
23
- statusMessage: "Google Maps API key not configured for geocode proxy"
24
- });
25
- }
26
- const query = stripProxyAuthQuery(getQuery(event));
27
- const { key: _clientKey, ...safeQuery } = query;
28
- const geocodeUrl = withQuery("https://maps.googleapis.com/maps/api/geocode/json", {
29
- ...safeQuery,
30
- key: apiKey
31
- });
32
- const data = await cachedGeocodeFetch(geocodeUrl, {
33
- headers: { "User-Agent": "Nuxt Scripts Google Geocode Proxy" }
34
- }).catch((error) => {
35
- throw createError({
36
- statusCode: error.statusCode || 500,
37
- statusMessage: error.statusMessage || "Failed to geocode"
38
- });
39
- });
40
- setHeader(event, "Content-Type", "application/json");
41
- setHeader(event, "Cache-Control", "public, max-age=86400, s-maxage=86400");
42
- return data;
43
- }));
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, any>;
2
- export default _default;
@@ -1,56 +0,0 @@
1
- import { withQuery } from "ufo";
2
- import { createError, defineEventHandler, getQuery, setHeader } from "#nuxt-scripts/h3";
3
- import { useRuntimeConfig } from "#nuxt-scripts/nitro";
4
- import { createCachedBinaryFetch, isSafeHttpsUrl } from "./utils/cached-upstream.js";
5
- import { stripProxyAuthQuery } from "./utils/proxy-query.js";
6
- import { withSigning } from "./utils/withSigning.js";
7
- const cachedMapFetch = createCachedBinaryFetch("nuxt-scripts-static-map", 604800, {
8
- allowContentType: (contentType) => contentType.startsWith("image/") && contentType !== "image/svg+xml",
9
- allowUrl: (url) => isSafeHttpsUrl(url) && url.hostname === "maps.googleapis.com"
10
- });
11
- export default withSigning(defineEventHandler(async (event) => {
12
- const runtimeConfig = useRuntimeConfig();
13
- const publicConfig = runtimeConfig.public["nuxt-scripts"]?.googleStaticMapsProxy;
14
- const privateConfig = runtimeConfig["nuxt-scripts"]?.googleStaticMapsProxy;
15
- if (!publicConfig?.enabled) {
16
- throw createError({
17
- statusCode: 404,
18
- statusMessage: "Google Static Maps proxy is not enabled"
19
- });
20
- }
21
- const apiKey = privateConfig?.apiKey;
22
- if (!apiKey) {
23
- throw createError({
24
- statusCode: 500,
25
- statusMessage: "Google Maps API key not configured for proxy"
26
- });
27
- }
28
- const query = stripProxyAuthQuery(getQuery(event));
29
- const { key: _clientKey, ...safeQuery } = query;
30
- const googleMapsUrl = withQuery("https://maps.googleapis.com/maps/api/staticmap", {
31
- ...safeQuery,
32
- key: apiKey
33
- });
34
- const result = await cachedMapFetch(googleMapsUrl, {
35
- headers: { "User-Agent": "Nuxt Scripts Google Static Maps Proxy" }
36
- }).catch((error) => {
37
- throw createError({
38
- statusCode: error.statusCode || 500,
39
- statusMessage: error.statusMessage || "Failed to fetch static map"
40
- });
41
- });
42
- const contentType = result.contentType?.split(";", 1)[0]?.trim().toLowerCase();
43
- if (!contentType?.startsWith("image/") || contentType === "image/svg+xml") {
44
- throw createError({
45
- statusCode: 415,
46
- statusMessage: "Unsupported upstream content type"
47
- });
48
- }
49
- const cacheMaxAge = publicConfig.cacheMaxAge || 3600;
50
- setHeader(event, "Content-Type", result.contentType);
51
- setHeader(event, "Cache-Control", `public, max-age=${cacheMaxAge}, s-maxage=${cacheMaxAge}`);
52
- setHeader(event, "Vary", "Accept-Encoding");
53
- setHeader(event, "Content-Security-Policy", "sandbox; default-src 'none'; base-uri 'none'; form-action 'none'");
54
- setHeader(event, "X-Content-Type-Options", "nosniff");
55
- return result.body;
56
- }));
@@ -1,2 +0,0 @@
1
- /** Remove proxy-only credentials before constructing an upstream URL or cache key. */
2
- export declare function stripProxyAuthQuery(query: Record<string, unknown>): Record<string, unknown>;
@@ -1,10 +0,0 @@
1
- import { PAGE_TOKEN_PARAM, PAGE_TOKEN_TS_PARAM, SIG_PARAM } from "./sign-constants.js";
2
- const PROXY_AUTH_PARAMS = /* @__PURE__ */ new Set([SIG_PARAM, PAGE_TOKEN_PARAM, PAGE_TOKEN_TS_PARAM]);
3
- export function stripProxyAuthQuery(query) {
4
- const upstreamQuery = /* @__PURE__ */ Object.create(null);
5
- for (const [key, value] of Object.entries(query)) {
6
- if (!PROXY_AUTH_PARAMS.has(key))
7
- upstreamQuery[key] = value;
8
- }
9
- return upstreamQuery;
10
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Signing constants shared between server (HMAC) and client (page-token) code.
3
- *
4
- * Kept in a crypto-free module so client bundles can import the param names
5
- * without pulling in `node:crypto`.
6
- */
7
- /** Query param name for the HMAC signature. */
8
- export declare const SIG_PARAM = "sig";
9
- /** Length of the hex signature (16 chars = 64 bits). */
10
- export declare const SIG_LENGTH = 16;
11
- /** Query param name for the page token. */
12
- export declare const PAGE_TOKEN_PARAM = "_pt";
13
- /** Query param name for the page token timestamp. */
14
- export declare const PAGE_TOKEN_TS_PARAM = "_ts";
15
- /** Default max age for page tokens in seconds (1 hour). */
16
- export declare const PAGE_TOKEN_MAX_AGE = 3600;
@@ -1,5 +0,0 @@
1
- export const SIG_PARAM = "sig";
2
- export const SIG_LENGTH = 16;
3
- export const PAGE_TOKEN_PARAM = "_pt";
4
- export const PAGE_TOKEN_TS_PARAM = "_ts";
5
- export const PAGE_TOKEN_MAX_AGE = 3600;
@@ -1,101 +0,0 @@
1
- /**
2
- * HMAC URL signing for proxy endpoints.
3
- *
4
- * ## Why
5
- *
6
- * Proxy endpoints like `/_scripts/proxy/google-static-maps` inject a server-side
7
- * API key and forward requests to third-party services. Without signing, anyone
8
- * can call these endpoints with arbitrary parameters and burn the site owner's
9
- * API quota. Signing ensures only URLs generated server-side (during SSR/prerender
10
- * or via the `/_scripts/sign` endpoint) are accepted.
11
- *
12
- * ## How
13
- *
14
- * 1. The module stores a deterministic secret in `runtimeConfig.nuxt-scripts.proxySecret`
15
- * (env: `NUXT_SCRIPTS_PROXY_SECRET`).
16
- * 2. URLs are canonicalized (sort query keys, strip `sig`) and signed with HMAC-SHA256.
17
- * 3. The first 16 hex chars (64 bits) of the digest is appended as `?sig=<hex>`.
18
- * 4. Endpoints wrapped with `withSigning()` verify the sig against the current request.
19
- *
20
- * A 64-bit signature is enough to defeat brute force for this threat model
21
- * (a billion guesses gives a ~5% hit rate at 2^64). Longer signatures bloat
22
- * prerendered HTML for no practical gain.
23
- */
24
- import type { H3Event } from '#nuxt-scripts/h3';
25
- import { PAGE_TOKEN_MAX_AGE, PAGE_TOKEN_PARAM, PAGE_TOKEN_TS_PARAM, SIG_LENGTH, SIG_PARAM } from './sign-constants.js';
26
- export { PAGE_TOKEN_MAX_AGE, PAGE_TOKEN_PARAM, PAGE_TOKEN_TS_PARAM, SIG_LENGTH, SIG_PARAM };
27
- /**
28
- * Canonicalize a query object into a deterministic string suitable for HMAC input.
29
- *
30
- * Rules:
31
- * - The `sig` param is stripped (it can't sign itself).
32
- * - `undefined` and `null` values are skipped (mirrors `ufo.withQuery`).
33
- * - Keys are sorted alphabetically so order-independent reconstruction works.
34
- * - Arrays expand to repeated keys (e.g. `markers=a&markers=b`), matching how
35
- * `ufo.withQuery` serializes array-valued params.
36
- * - Objects are JSON-stringified (rare, but consistent with `ufo.withQuery`).
37
- * - Encoding uses `encodeURIComponent` for both keys and values so the canonical
38
- * form matches what shows up on the wire.
39
- *
40
- * The resulting string is stable across server/client and different JS runtimes
41
- * because it does not depend on `URLSearchParams` insertion order.
42
- */
43
- export declare function canonicalizeQuery(query: Record<string, unknown>): string;
44
- /**
45
- * Sign a path + query using HMAC-SHA256 and return the 16-char hex digest.
46
- *
47
- * The HMAC input is `${path}?${canonicalQuery}` so that the same query signed
48
- * against a different endpoint yields a different signature (prevents cross-
49
- * endpoint signature reuse).
50
- *
51
- * `path` should be the URL path without query string (e.g. `/_scripts/proxy/google-static-maps`).
52
- * Callers should not include origin / host since the signing contract is path-relative.
53
- */
54
- export declare function signProxyUrl(path: string, query: Record<string, unknown>, secret: string): string;
55
- /**
56
- * Build a fully-formed signed URL (path + query + sig).
57
- *
58
- * This is the primary helper for code paths that need to emit a proxy URL
59
- * (SSR components, server-side URL rewriters like instagram-embed).
60
- */
61
- export declare function buildSignedProxyUrl(path: string, query: Record<string, unknown>, secret: string): string;
62
- /**
63
- * Generate a page token that authorizes client-side proxy requests.
64
- *
65
- * Embedded in the SSR payload so the browser can attach it to reactive proxy
66
- * URL updates without needing a `/sign` round-trip. The token is scoped to
67
- * a timestamp and expires after `PAGE_TOKEN_MAX_AGE` seconds.
68
- *
69
- * Construction: first 16 hex chars of `HMAC(secret, "proxy-access:<timestamp>")`.
70
- */
71
- export declare function generateProxyToken(secret: string, timestamp: number): string;
72
- /**
73
- * Verify a page token against the current time.
74
- *
75
- * Returns `true` if the token matches the HMAC for the given timestamp AND
76
- * the timestamp is within `maxAge` seconds of `now`.
77
- */
78
- export declare function verifyProxyToken(token: string, timestamp: number, secret: string, maxAge?: number, now?: number): boolean;
79
- /**
80
- * Verify a request against either a URL signature or a page token.
81
- *
82
- * Two verification modes, checked in order:
83
- *
84
- * 1. **URL signature** (`sig` param): the exact URL was signed server-side
85
- * during SSR/prerender. Locked to the specific path + query params.
86
- *
87
- * 2. **Page token** (`_pt` + `_ts` params): the client received a short-lived
88
- * token during SSR and is making a reactive proxy request with new params.
89
- * Valid for any params on the target path, but expires after `maxAge`.
90
- *
91
- * Returns `false` if neither mode validates.
92
- */
93
- export declare function verifyProxyRequest(event: H3Event, secret: string, maxAge?: number): boolean;
94
- /**
95
- * Constant-time string comparison.
96
- *
97
- * Both inputs are expected to be equal-length hex strings. The loop runs over
98
- * the longer length so an early-exit on length mismatch doesn't leak the
99
- * expected length (though both are fixed at `SIG_LENGTH` in practice).
100
- */
101
- export declare function constantTimeEqual(a: string, b: string): boolean;
@@ -1,91 +0,0 @@
1
- import { createHmac } from "node:crypto";
2
- import { getQuery } from "#nuxt-scripts/h3";
3
- import {
4
- PAGE_TOKEN_MAX_AGE,
5
- PAGE_TOKEN_PARAM,
6
- PAGE_TOKEN_TS_PARAM,
7
- SIG_LENGTH,
8
- SIG_PARAM
9
- } from "./sign-constants.js";
10
- export { PAGE_TOKEN_MAX_AGE, PAGE_TOKEN_PARAM, PAGE_TOKEN_TS_PARAM, SIG_LENGTH, SIG_PARAM };
11
- export function canonicalizeQuery(query) {
12
- const keys = Object.keys(query).filter((k) => k !== SIG_PARAM && query[k] !== void 0 && query[k] !== null).sort();
13
- const parts = [];
14
- for (const key of keys) {
15
- const value = query[key];
16
- const encodedKey = encodeURIComponent(key);
17
- if (Array.isArray(value)) {
18
- for (const item of value) {
19
- if (item === void 0 || item === null)
20
- continue;
21
- parts.push(`${encodedKey}=${encodeURIComponent(serializeValue(item))}`);
22
- }
23
- } else {
24
- parts.push(`${encodedKey}=${encodeURIComponent(serializeValue(value))}`);
25
- }
26
- }
27
- return parts.join("&");
28
- }
29
- function serializeValue(value) {
30
- if (typeof value === "string")
31
- return value;
32
- if (typeof value === "object")
33
- return JSON.stringify(value);
34
- return String(value);
35
- }
36
- export function signProxyUrl(path, query, secret) {
37
- const canonical = canonicalizeQuery(query);
38
- const input = canonical ? `${path}?${canonical}` : path;
39
- return createHmac("sha256", secret).update(input).digest("hex").slice(0, SIG_LENGTH);
40
- }
41
- export function buildSignedProxyUrl(path, query, secret) {
42
- const sig = signProxyUrl(path, query, secret);
43
- const canonical = canonicalizeQuery(query);
44
- const queryString = canonical ? `${canonical}&${SIG_PARAM}=${sig}` : `${SIG_PARAM}=${sig}`;
45
- return `${path}?${queryString}`;
46
- }
47
- export function generateProxyToken(secret, timestamp) {
48
- return createHmac("sha256", secret).update(`proxy-access:${timestamp}`).digest("hex").slice(0, SIG_LENGTH);
49
- }
50
- export function verifyProxyToken(token, timestamp, secret, maxAge = PAGE_TOKEN_MAX_AGE, now = Math.floor(Date.now() / 1e3)) {
51
- if (!token || !secret || typeof timestamp !== "number")
52
- return false;
53
- if (token.length !== SIG_LENGTH)
54
- return false;
55
- const age = now - timestamp;
56
- if (age > maxAge || age < -60)
57
- return false;
58
- const expected = generateProxyToken(secret, timestamp);
59
- return constantTimeEqual(expected, token);
60
- }
61
- export function verifyProxyRequest(event, secret, maxAge) {
62
- if (!secret)
63
- return false;
64
- const query = getQuery(event);
65
- const rawSig = query[SIG_PARAM];
66
- const sig = Array.isArray(rawSig) ? rawSig[0] : rawSig;
67
- if (typeof sig === "string" && sig.length === SIG_LENGTH) {
68
- const path = (event.path || "").split("?")[0] || "";
69
- const expected = signProxyUrl(path, query, secret);
70
- if (constantTimeEqual(expected, sig))
71
- return true;
72
- }
73
- const rawToken = query[PAGE_TOKEN_PARAM];
74
- const rawTs = query[PAGE_TOKEN_TS_PARAM];
75
- const token = Array.isArray(rawToken) ? rawToken[0] : rawToken;
76
- const ts = Array.isArray(rawTs) ? rawTs[0] : rawTs;
77
- if (typeof token === "string" && ts !== void 0) {
78
- const timestamp = Number(ts);
79
- if (!Number.isNaN(timestamp))
80
- return verifyProxyToken(token, timestamp, secret, maxAge);
81
- }
82
- return false;
83
- }
84
- export function constantTimeEqual(a, b) {
85
- if (a.length !== b.length)
86
- return false;
87
- let diff = 0;
88
- for (let i = 0; i < a.length; i++)
89
- diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
90
- return diff === 0;
91
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Middleware wrapper that enforces HMAC signature verification on a proxy handler.
3
- *
4
- * Usage:
5
- * ```ts
6
- * export default withSigning(defineEventHandler(async (event) => {
7
- * // ... handler logic
8
- * }))
9
- * ```
10
- *
11
- * Behavior:
12
- * - Reads `runtimeConfig.nuxt-scripts.proxySecret` (server-only).
13
- * - If no secret is configured: passes through (signing not yet enabled).
14
- * This allows shipping handler wiring before components emit signed URLs.
15
- * Once `NUXT_SCRIPTS_PROXY_SECRET` is set, verification is enforced.
16
- * - If a secret IS configured and the request's signature is invalid: 403.
17
- * - Otherwise, delegates to the wrapped handler.
18
- *
19
- * The outer wrapper runs before any handler logic, so unauthorized requests
20
- * never reach the upstream fetch and cannot consume API quota.
21
- */
22
- import type { EventHandler, EventHandlerRequest, EventHandlerResponse } from '#nuxt-scripts/h3';
23
- export declare function withSigning<Req extends EventHandlerRequest = EventHandlerRequest, Res extends EventHandlerResponse = EventHandlerResponse>(handler: EventHandler<Req, Res>): EventHandler<Req, any>;
@@ -1,19 +0,0 @@
1
- import { createError, defineEventHandler } from "#nuxt-scripts/h3";
2
- import { useRuntimeConfig } from "#nuxt-scripts/nitro";
3
- import { verifyProxyRequest } from "./sign.js";
4
- export function withSigning(handler) {
5
- return defineEventHandler(async (event) => {
6
- const runtimeConfig = useRuntimeConfig();
7
- const scriptsConfig = runtimeConfig["nuxt-scripts"];
8
- const secret = scriptsConfig?.proxySecret;
9
- if (!secret)
10
- return handler(event);
11
- if (!verifyProxyRequest(event, secret, scriptsConfig?.pageTokenMaxAge)) {
12
- throw createError({
13
- statusCode: 403,
14
- statusMessage: "Invalid signature"
15
- });
16
- }
17
- return handler(event);
18
- });
19
- }
@@ -1 +0,0 @@
1
- export declare function isUnheadSourceLessScriptLoaderEnabled(): boolean;
@@ -1,3 +0,0 @@
1
- export function isUnheadSourceLessScriptLoaderEnabled() {
2
- return typeof __NUXT_SCRIPTS_UNHEAD_SOURCELESS__ !== "undefined" && __NUXT_SCRIPTS_UNHEAD_SOURCELESS__;
3
- }