@shware/http 2.11.4 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +13 -0
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/cache/index.cjs +5 -30
- package/dist/cache/index.cjs.map +1 -1
- package/dist/cache/index.d.cts +7 -5
- package/dist/cache/index.d.cts.map +1 -0
- package/dist/cache/index.d.mts +11 -0
- package/dist/cache/index.d.mts.map +1 -0
- package/dist/cache/index.mjs +5 -6
- package/dist/cache/index.mjs.map +1 -1
- package/dist/error/detail.cjs +100 -90
- package/dist/error/detail.cjs.map +1 -1
- package/dist/error/detail.d.cts +77 -78
- package/dist/error/detail.d.cts.map +1 -0
- package/dist/error/detail.d.mts +108 -0
- package/dist/error/detail.d.mts.map +1 -0
- package/dist/error/detail.mjs +99 -65
- package/dist/error/detail.mjs.map +1 -1
- package/dist/error/i18n/en-us.cjs +5 -29
- package/dist/error/i18n/en-us.cjs.map +1 -1
- package/dist/error/i18n/en-us.d.cts +3 -1
- package/dist/error/i18n/en-us.d.cts.map +1 -0
- package/dist/error/i18n/en-us.d.mts +5 -0
- package/dist/error/i18n/en-us.d.mts.map +1 -0
- package/dist/error/i18n/en-us.mjs +5 -5
- package/dist/error/i18n/en-us.mjs.map +1 -1
- package/dist/error/index.cjs +29 -56
- package/dist/error/index.cjs.map +1 -1
- package/dist/error/index.d.cts +12 -10
- package/dist/error/index.d.cts.map +1 -0
- package/dist/error/index.d.mts +21 -0
- package/dist/error/index.d.mts.map +1 -0
- package/dist/error/index.mjs +25 -28
- package/dist/error/index.mjs.map +1 -1
- package/dist/error/parse.cjs +63 -61
- package/dist/error/parse.cjs.map +1 -1
- package/dist/error/parse.d.cts +8 -7
- package/dist/error/parse.d.cts.map +1 -0
- package/dist/error/{parse.d.ts → parse.d.mts} +8 -7
- package/dist/error/parse.d.mts.map +1 -0
- package/dist/error/parse.mjs +59 -33
- package/dist/error/parse.mjs.map +1 -1
- package/dist/error/reason.cjs +0 -19
- package/dist/error/reason.d.cts +5 -4
- package/dist/error/reason.d.cts.map +1 -0
- package/dist/error/reason.d.mts +6 -0
- package/dist/error/reason.d.mts.map +1 -0
- package/dist/error/reason.mjs +1 -1
- package/dist/error/status.cjs +103 -256
- package/dist/error/status.cjs.map +1 -1
- package/dist/error/status.d.cts +58 -58
- package/dist/error/status.d.cts.map +1 -0
- package/dist/error/status.d.mts +69 -0
- package/dist/error/status.d.mts.map +1 -0
- package/dist/error/status.mjs +98 -227
- package/dist/error/status.mjs.map +1 -1
- package/dist/google-one-tap/index.cjs +135 -138
- package/dist/google-one-tap/index.cjs.map +1 -1
- package/dist/google-one-tap/index.d.cts +49 -48
- package/dist/google-one-tap/index.d.cts.map +1 -0
- package/dist/google-one-tap/index.d.mts +82 -0
- package/dist/google-one-tap/index.d.mts.map +1 -0
- package/dist/google-one-tap/index.mjs +133 -112
- package/dist/google-one-tap/index.mjs.map +1 -1
- package/dist/google-one-tap/types.cjs +0 -19
- package/dist/google-one-tap/types.d.cts +124 -122
- package/dist/google-one-tap/types.d.cts.map +1 -0
- package/dist/google-one-tap/types.d.mts +157 -0
- package/dist/google-one-tap/types.d.mts.map +1 -0
- package/dist/google-one-tap/types.mjs +1 -1
- package/dist/hono/authorizer.cjs +28 -65
- package/dist/hono/authorizer.cjs.map +1 -1
- package/dist/hono/authorizer.d.cts +12 -11
- package/dist/hono/authorizer.d.cts.map +1 -0
- package/dist/hono/authorizer.d.mts +19 -0
- package/dist/hono/authorizer.d.mts.map +1 -0
- package/dist/hono/authorizer.mjs +23 -36
- package/dist/hono/authorizer.mjs.map +1 -1
- package/dist/hono/csrf.cjs +81 -92
- package/dist/hono/csrf.cjs.map +1 -1
- package/dist/hono/csrf.d.cts +46 -45
- package/dist/hono/csrf.d.cts.map +1 -0
- package/dist/hono/csrf.d.mts +76 -0
- package/dist/hono/csrf.d.mts.map +1 -0
- package/dist/hono/csrf.mjs +76 -63
- package/dist/hono/csrf.mjs.map +1 -1
- package/dist/hono/geolocation.cjs +10 -34
- package/dist/hono/geolocation.cjs.map +1 -1
- package/dist/hono/geolocation.d.cts +5 -4
- package/dist/hono/geolocation.d.cts.map +1 -0
- package/dist/hono/geolocation.d.mts +7 -0
- package/dist/hono/geolocation.d.mts.map +1 -0
- package/dist/hono/geolocation.mjs +8 -12
- package/dist/hono/geolocation.mjs.map +1 -1
- package/dist/hono/handler.cjs +37 -61
- package/dist/hono/handler.cjs.map +1 -1
- package/dist/hono/handler.d.cts +26 -25
- package/dist/hono/handler.d.cts.map +1 -0
- package/dist/hono/handler.d.mts +32 -0
- package/dist/hono/handler.d.mts.map +1 -0
- package/dist/hono/handler.mjs +34 -34
- package/dist/hono/handler.mjs.map +1 -1
- package/dist/hono/index.cjs +14 -48
- package/dist/hono/index.d.cts +7 -15
- package/dist/hono/index.d.mts +7 -0
- package/dist/hono/index.mjs +4 -14
- package/dist/hono/rate-limit.cjs +65 -110
- package/dist/hono/rate-limit.cjs.map +1 -1
- package/dist/hono/rate-limit.d.cts +27 -26
- package/dist/hono/rate-limit.d.cts.map +1 -0
- package/dist/hono/rate-limit.d.mts +36 -0
- package/dist/hono/rate-limit.d.mts.map +1 -0
- package/dist/hono/rate-limit.mjs +60 -81
- package/dist/hono/rate-limit.mjs.map +1 -1
- package/dist/hono/validator.cjs +47 -66
- package/dist/hono/validator.cjs.map +1 -1
- package/dist/hono/validator.d.cts +25 -30
- package/dist/hono/validator.d.cts.map +1 -0
- package/dist/hono/validator.d.mts +26 -0
- package/dist/hono/validator.d.mts.map +1 -0
- package/dist/hono/validator.mjs +43 -43
- package/dist/hono/validator.mjs.map +1 -1
- package/dist/index.cjs +39 -95
- package/dist/index.d.cts +12 -14
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +5 -48
- package/dist/iso/iso_3601_1.cjs +1512 -290
- package/dist/iso/iso_3601_1.cjs.map +1 -1
- package/dist/iso/iso_3601_1.d.cts +8 -6
- package/dist/iso/iso_3601_1.d.cts.map +1 -0
- package/dist/iso/iso_3601_1.d.mts +11 -0
- package/dist/iso/iso_3601_1.d.mts.map +1 -0
- package/dist/iso/iso_3601_1.mjs +1511 -265
- package/dist/iso/iso_3601_1.mjs.map +1 -1
- package/dist/max-length/index.cjs +158 -91
- package/dist/max-length/index.cjs.map +1 -1
- package/dist/max-length/index.d.cts +110 -1
- package/dist/max-length/index.d.cts.map +1 -0
- package/dist/{index-BhgdyigB.d.ts → max-length/index.d.mts} +9 -28
- package/dist/max-length/index.d.mts.map +1 -0
- package/dist/max-length/index.mjs +133 -47
- package/dist/max-length/index.mjs.map +1 -1
- package/dist/message.cjs +5 -30
- package/dist/message.cjs.map +1 -1
- package/dist/message.d.cts +3 -1
- package/dist/message.d.cts.map +1 -0
- package/dist/{message.d.ts → message.d.mts} +3 -1
- package/dist/message.d.mts.map +1 -0
- package/dist/message.mjs +5 -6
- package/dist/message.mjs.map +1 -1
- package/dist/polyfills/index.cjs +4 -4
- package/dist/polyfills/index.cjs.map +1 -1
- package/dist/polyfills/index.d.cts +1 -2
- package/dist/polyfills/index.d.mts +1 -0
- package/dist/polyfills/index.mjs +5 -2
- package/dist/polyfills/index.mjs.map +1 -1
- package/dist/response.cjs +191 -208
- package/dist/response.cjs.map +1 -1
- package/dist/response.d.cts +53 -54
- package/dist/response.d.cts.map +1 -0
- package/dist/response.d.mts +82 -0
- package/dist/response.d.mts.map +1 -0
- package/dist/response.mjs +182 -175
- package/dist/response.mjs.map +1 -1
- package/dist/snowflake.cjs +48 -70
- package/dist/snowflake.cjs.map +1 -1
- package/dist/snowflake.d.cts +16 -14
- package/dist/snowflake.d.cts.map +1 -0
- package/dist/snowflake.d.mts +31 -0
- package/dist/snowflake.d.mts.map +1 -0
- package/dist/snowflake.mjs +46 -44
- package/dist/snowflake.mjs.map +1 -1
- package/dist/utils/geolocation.cjs +51 -75
- package/dist/utils/geolocation.cjs.map +1 -1
- package/dist/utils/geolocation.d.cts +14 -12
- package/dist/utils/geolocation.d.cts.map +1 -0
- package/dist/utils/{geolocation.d.ts → geolocation.d.mts} +14 -12
- package/dist/utils/geolocation.d.mts.map +1 -0
- package/dist/utils/geolocation.mjs +47 -47
- package/dist/utils/geolocation.mjs.map +1 -1
- package/dist/utils/google-tag-gateway.cjs +35 -56
- package/dist/utils/google-tag-gateway.cjs.map +1 -1
- package/dist/utils/google-tag-gateway.d.cts +3 -1
- package/dist/utils/google-tag-gateway.d.cts.map +1 -0
- package/dist/utils/{google-tag-gateway.d.ts → google-tag-gateway.d.mts} +3 -1
- package/dist/utils/google-tag-gateway.d.mts.map +1 -0
- package/dist/utils/google-tag-gateway.mjs +33 -30
- package/dist/utils/google-tag-gateway.mjs.map +1 -1
- package/dist/utils/timing.cjs +50 -71
- package/dist/utils/timing.cjs.map +1 -1
- package/dist/utils/timing.d.cts +11 -9
- package/dist/utils/timing.d.cts.map +1 -0
- package/dist/utils/timing.d.mts +15 -0
- package/dist/utils/timing.d.mts.map +1 -0
- package/dist/utils/timing.mjs +49 -46
- package/dist/utils/timing.mjs.map +1 -1
- package/dist/webhook/index.cjs +43 -72
- package/dist/webhook/index.cjs.map +1 -1
- package/dist/webhook/index.d.cts +3 -1
- package/dist/webhook/index.d.cts.map +1 -0
- package/dist/webhook/{index.d.ts → index.d.mts} +3 -1
- package/dist/webhook/index.d.mts.map +1 -0
- package/dist/webhook/index.mjs +41 -46
- package/dist/webhook/index.mjs.map +1 -1
- package/package.json +49 -24
- package/dist/cache/index.d.ts +0 -9
- package/dist/error/detail.d.ts +0 -109
- package/dist/error/i18n/en-us.d.ts +0 -3
- package/dist/error/index.d.ts +0 -19
- package/dist/error/reason.cjs.map +0 -1
- package/dist/error/reason.d.ts +0 -5
- package/dist/error/reason.mjs.map +0 -1
- package/dist/error/status.d.ts +0 -69
- package/dist/google-one-tap/index.d.ts +0 -81
- package/dist/google-one-tap/types.cjs.map +0 -1
- package/dist/google-one-tap/types.d.ts +0 -155
- package/dist/google-one-tap/types.mjs.map +0 -1
- package/dist/hono/authorizer.d.ts +0 -18
- package/dist/hono/csrf.d.ts +0 -75
- package/dist/hono/geolocation.d.ts +0 -6
- package/dist/hono/handler.d.ts +0 -31
- package/dist/hono/index.cjs.map +0 -1
- package/dist/hono/index.d.ts +0 -15
- package/dist/hono/index.mjs.map +0 -1
- package/dist/hono/rate-limit.d.ts +0 -35
- package/dist/hono/validator.d.ts +0 -31
- package/dist/index-BhgdyigB.d.cts +0 -129
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.mjs.map +0 -1
- package/dist/iso/iso_3601_1.d.ts +0 -9
- package/dist/max-length/index.d.ts +0 -1
- package/dist/polyfills/index.d.ts +0 -2
- package/dist/response.d.ts +0 -83
- package/dist/snowflake.d.ts +0 -29
- package/dist/utils/timing.d.ts +0 -13
|
@@ -1,59 +1,38 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/google-tag-gateway.ts
|
|
21
|
-
var google_tag_gateway_exports = {};
|
|
22
|
-
__export(google_tag_gateway_exports, {
|
|
23
|
-
forwardToGoogleTagGateway: () => forwardToGoogleTagGateway
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(google_tag_gateway_exports);
|
|
26
|
-
var import_geolocation = require("./geolocation.cjs");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_geolocation = require("./geolocation.cjs");
|
|
3
|
+
//#region src/utils/google-tag-gateway.ts
|
|
4
|
+
/**
|
|
5
|
+
* In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
|
|
6
|
+
* should read ok. Verify that geographical information is being included by navigating to:
|
|
7
|
+
* https://example.com/metrics/?validate_geo=healthy. The page should read ok.
|
|
8
|
+
*/
|
|
27
9
|
async function forwardToGoogleTagGateway(request, gaId) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
responseHeaders.delete("content-length");
|
|
53
|
-
return new Response(response.body, { status: response.status, headers: responseHeaders });
|
|
10
|
+
const GATEWAY_HOST = `${gaId}.fps.goog`;
|
|
11
|
+
const { pathname, search } = new URL(request.url);
|
|
12
|
+
const target = `https://${GATEWAY_HOST}${pathname}${search}`;
|
|
13
|
+
const headers = new Headers();
|
|
14
|
+
headers.set("host", GATEWAY_HOST);
|
|
15
|
+
const cookie = request.headers.get("cookie");
|
|
16
|
+
if (cookie) headers.set("cookie", cookie);
|
|
17
|
+
const { country, region } = require_utils_geolocation.getGeolocation(request);
|
|
18
|
+
if (country && region) headers.set("x-forwarded-countryregion", `${country}-${region}`);
|
|
19
|
+
else if (country) headers.set("x-forwarded-country", country);
|
|
20
|
+
else if (region) headers.set("x-forwarded-region", region);
|
|
21
|
+
const body = request.method !== "GET" && request.method !== "HEAD" ? await request.arrayBuffer() : void 0;
|
|
22
|
+
const response = await fetch(target, {
|
|
23
|
+
method: request.method,
|
|
24
|
+
headers,
|
|
25
|
+
body
|
|
26
|
+
});
|
|
27
|
+
const responseHeaders = new Headers(response.headers);
|
|
28
|
+
responseHeaders.delete("content-encoding");
|
|
29
|
+
responseHeaders.delete("content-length");
|
|
30
|
+
return new Response(response.body, {
|
|
31
|
+
status: response.status,
|
|
32
|
+
headers: responseHeaders
|
|
33
|
+
});
|
|
54
34
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.forwardToGoogleTagGateway = forwardToGoogleTagGateway;
|
|
37
|
+
|
|
59
38
|
//# sourceMappingURL=google-tag-gateway.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\n\n/**\n * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n\n // Buffer the body instead of streaming it. The conversion endpoint\n // (g/measurement/conversion) answers POSTs with a 302 to www.google.com, and we want\n // to follow that hop on the server so the browser never sees a Google domain (the whole\n // point of the first-party gateway). Following a redirect requires re-issuing the\n // request, which undici cannot do with a one-shot `request.body` stream — it throws\n // \"fetch failed\", surfacing as a 500. A buffered body is replayable, so the redirect\n // is followed transparently here.\n const body = hasBody ? await request.arrayBuffer() : undefined;\n\n const response = await fetch(target, {\n method: request.method,\n headers,\n body,\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-tag-gateway.cjs","names":["getGeolocation"],"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\n\n/**\n * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n\n // Buffer the body instead of streaming it. The conversion endpoint\n // (g/measurement/conversion) answers POSTs with a 302 to www.google.com, and we want\n // to follow that hop on the server so the browser never sees a Google domain (the whole\n // point of the first-party gateway). Following a redirect requires re-issuing the\n // request, which undici cannot do with a one-shot `request.body` stream — it throws\n // \"fetch failed\", surfacing as a 500. A buffered body is replayable, so the redirect\n // is followed transparently here.\n const body = hasBody ? await request.arrayBuffer() : undefined;\n\n const response = await fetch(target, {\n method: request.method,\n headers,\n body,\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":";;;;;;;;AAOA,eAAsB,0BAA0B,SAAkB,MAAc;CAC9E,MAAM,eAAe,GAAG,KAAK;CAC7B,MAAM,EAAE,UAAU,WAAW,IAAI,IAAI,QAAQ,GAAG;CAEhD,MAAM,SAAS,WAAW,eAAe,WAAW;CAEpD,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,IAAI,QAAQ,YAAY;CAGhC,MAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;CAC3C,IAAI,QAAQ,QAAQ,IAAI,UAAU,MAAM;CAIxC,MAAM,EAAE,SAAS,WAAWA,0BAAAA,eAAe,OAAO;CAElD,IAAI,WAAW,QACb,QAAQ,IAAI,6BAA6B,GAAG,QAAQ,GAAG,QAAQ;MAC1D,IAAI,SACT,QAAQ,IAAI,uBAAuB,OAAO;MACrC,IAAI,QACT,QAAQ,IAAI,sBAAsB,MAAM;CAY1C,MAAM,OATU,QAAQ,WAAW,SAAS,QAAQ,WAAW,SASxC,MAAM,QAAQ,YAAY,IAAI,KAAA;CAErD,MAAM,WAAW,MAAM,MAAM,QAAQ;EACnC,QAAQ,QAAQ;EAChB;EACA;CACF,CAAC;CAID,MAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;CACpD,gBAAgB,OAAO,kBAAkB;CACzC,gBAAgB,OAAO,gBAAgB;CAEvC,OAAO,IAAI,SAAS,SAAS,MAAM;EAAE,QAAQ,SAAS;EAAQ,SAAS;CAAgB,CAAC;AAC1F"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
//#region src/utils/google-tag-gateway.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
|
|
3
4
|
* should read ok. Verify that geographical information is being included by navigating to:
|
|
4
5
|
* https://example.com/metrics/?validate_geo=healthy. The page should read ok.
|
|
5
6
|
*/
|
|
6
7
|
declare function forwardToGoogleTagGateway(request: Request, gaId: string): Promise<Response>;
|
|
7
|
-
|
|
8
|
+
//#endregion
|
|
8
9
|
export { forwardToGoogleTagGateway };
|
|
10
|
+
//# sourceMappingURL=google-tag-gateway.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-tag-gateway.d.cts","names":[],"sources":["../../src/utils/google-tag-gateway.ts"],"mappings":";;;;;;iBAOsB,0BAA0B,SAAS,SAAS,eAAY,QAAA"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
//#region src/utils/google-tag-gateway.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
|
|
3
4
|
* should read ok. Verify that geographical information is being included by navigating to:
|
|
4
5
|
* https://example.com/metrics/?validate_geo=healthy. The page should read ok.
|
|
5
6
|
*/
|
|
6
7
|
declare function forwardToGoogleTagGateway(request: Request, gaId: string): Promise<Response>;
|
|
7
|
-
|
|
8
|
+
//#endregion
|
|
8
9
|
export { forwardToGoogleTagGateway };
|
|
10
|
+
//# sourceMappingURL=google-tag-gateway.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-tag-gateway.d.mts","names":[],"sources":["../../src/utils/google-tag-gateway.ts"],"mappings":";;;;;;iBAOsB,0BAA0B,SAAS,SAAS,eAAY,QAAA"}
|
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
// src/utils/google-tag-gateway.ts
|
|
2
1
|
import { getGeolocation } from "./geolocation.mjs";
|
|
2
|
+
//#region src/utils/google-tag-gateway.ts
|
|
3
|
+
/**
|
|
4
|
+
* In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
|
|
5
|
+
* should read ok. Verify that geographical information is being included by navigating to:
|
|
6
|
+
* https://example.com/metrics/?validate_geo=healthy. The page should read ok.
|
|
7
|
+
*/
|
|
3
8
|
async function forwardToGoogleTagGateway(request, gaId) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
responseHeaders.delete("content-length");
|
|
29
|
-
return new Response(response.body, { status: response.status, headers: responseHeaders });
|
|
9
|
+
const GATEWAY_HOST = `${gaId}.fps.goog`;
|
|
10
|
+
const { pathname, search } = new URL(request.url);
|
|
11
|
+
const target = `https://${GATEWAY_HOST}${pathname}${search}`;
|
|
12
|
+
const headers = new Headers();
|
|
13
|
+
headers.set("host", GATEWAY_HOST);
|
|
14
|
+
const cookie = request.headers.get("cookie");
|
|
15
|
+
if (cookie) headers.set("cookie", cookie);
|
|
16
|
+
const { country, region } = getGeolocation(request);
|
|
17
|
+
if (country && region) headers.set("x-forwarded-countryregion", `${country}-${region}`);
|
|
18
|
+
else if (country) headers.set("x-forwarded-country", country);
|
|
19
|
+
else if (region) headers.set("x-forwarded-region", region);
|
|
20
|
+
const body = request.method !== "GET" && request.method !== "HEAD" ? await request.arrayBuffer() : void 0;
|
|
21
|
+
const response = await fetch(target, {
|
|
22
|
+
method: request.method,
|
|
23
|
+
headers,
|
|
24
|
+
body
|
|
25
|
+
});
|
|
26
|
+
const responseHeaders = new Headers(response.headers);
|
|
27
|
+
responseHeaders.delete("content-encoding");
|
|
28
|
+
responseHeaders.delete("content-length");
|
|
29
|
+
return new Response(response.body, {
|
|
30
|
+
status: response.status,
|
|
31
|
+
headers: responseHeaders
|
|
32
|
+
});
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
export { forwardToGoogleTagGateway };
|
|
36
|
+
|
|
34
37
|
//# sourceMappingURL=google-tag-gateway.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\n\n/**\n * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n\n // Buffer the body instead of streaming it. The conversion endpoint\n // (g/measurement/conversion) answers POSTs with a 302 to www.google.com, and we want\n // to follow that hop on the server so the browser never sees a Google domain (the whole\n // point of the first-party gateway). Following a redirect requires re-issuing the\n // request, which undici cannot do with a one-shot `request.body` stream — it throws\n // \"fetch failed\", surfacing as a 500. A buffered body is replayable, so the redirect\n // is followed transparently here.\n const body = hasBody ? await request.arrayBuffer() : undefined;\n\n const response = await fetch(target, {\n method: request.method,\n headers,\n body,\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-tag-gateway.mjs","names":[],"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\n\n/**\n * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n\n // Buffer the body instead of streaming it. The conversion endpoint\n // (g/measurement/conversion) answers POSTs with a 302 to www.google.com, and we want\n // to follow that hop on the server so the browser never sees a Google domain (the whole\n // point of the first-party gateway). Following a redirect requires re-issuing the\n // request, which undici cannot do with a one-shot `request.body` stream — it throws\n // \"fetch failed\", surfacing as a 500. A buffered body is replayable, so the redirect\n // is followed transparently here.\n const body = hasBody ? await request.arrayBuffer() : undefined;\n\n const response = await fetch(target, {\n method: request.method,\n headers,\n body,\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":";;;;;;;AAOA,eAAsB,0BAA0B,SAAkB,MAAc;CAC9E,MAAM,eAAe,GAAG,KAAK;CAC7B,MAAM,EAAE,UAAU,WAAW,IAAI,IAAI,QAAQ,GAAG;CAEhD,MAAM,SAAS,WAAW,eAAe,WAAW;CAEpD,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,IAAI,QAAQ,YAAY;CAGhC,MAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;CAC3C,IAAI,QAAQ,QAAQ,IAAI,UAAU,MAAM;CAIxC,MAAM,EAAE,SAAS,WAAW,eAAe,OAAO;CAElD,IAAI,WAAW,QACb,QAAQ,IAAI,6BAA6B,GAAG,QAAQ,GAAG,QAAQ;MAC1D,IAAI,SACT,QAAQ,IAAI,uBAAuB,OAAO;MACrC,IAAI,QACT,QAAQ,IAAI,sBAAsB,MAAM;CAY1C,MAAM,OATU,QAAQ,WAAW,SAAS,QAAQ,WAAW,SASxC,MAAM,QAAQ,YAAY,IAAI,KAAA;CAErD,MAAM,WAAW,MAAM,MAAM,QAAQ;EACnC,QAAQ,QAAQ;EAChB;EACA;CACF,CAAC;CAID,MAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;CACpD,gBAAgB,OAAO,kBAAkB;CACzC,gBAAgB,OAAO,gBAAgB;CAEvC,OAAO,IAAI,SAAS,SAAS,MAAM;EAAE,QAAQ,SAAS;EAAQ,SAAS;CAAgB,CAAC;AAC1F"}
|
package/dist/utils/timing.cjs
CHANGED
|
@@ -1,74 +1,53 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/timing.ts
|
|
21
|
-
var timing_exports = {};
|
|
22
|
-
__export(timing_exports, {
|
|
23
|
-
timing: () => timing
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(timing_exports);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/utils/timing.ts
|
|
26
3
|
function timing(options = { enabled: true }) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
4
|
+
const { enabled, crossOrigin } = options;
|
|
5
|
+
let start = performance.now();
|
|
6
|
+
const headers = [];
|
|
7
|
+
const timers = /* @__PURE__ */ new Map();
|
|
8
|
+
return {
|
|
9
|
+
startTime: (name, description) => {
|
|
10
|
+
timers.set(name, {
|
|
11
|
+
description,
|
|
12
|
+
start: performance.now()
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
endTime: (name, precision) => {
|
|
16
|
+
const timer = timers.get(name);
|
|
17
|
+
if (!timer) {
|
|
18
|
+
console.warn(`timing: ${name} not found`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const { start, description } = timer;
|
|
22
|
+
const dur = (performance.now() - start).toFixed(precision ?? 1);
|
|
23
|
+
timers.delete(name);
|
|
24
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
25
|
+
headers.push(metric);
|
|
26
|
+
},
|
|
27
|
+
mark: (name, description, precision) => {
|
|
28
|
+
const dur = (performance.now() - start).toFixed(precision ?? 1);
|
|
29
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
30
|
+
headers.push(metric);
|
|
31
|
+
start = performance.now();
|
|
32
|
+
},
|
|
33
|
+
setMetric: (name, value, description, precision) => {
|
|
34
|
+
if (typeof value === "number") {
|
|
35
|
+
const dur = value.toFixed(precision ?? 1);
|
|
36
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
37
|
+
headers.push(metric);
|
|
38
|
+
} else {
|
|
39
|
+
const metric = value ? `${name};desc="${value}"` : `${name}`;
|
|
40
|
+
headers.push(metric);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
setTiming: (response) => {
|
|
44
|
+
if (!enabled) return;
|
|
45
|
+
response.headers.append("Server-Timing", headers.join(","));
|
|
46
|
+
response.headers.append("Timing-Allow-Origin", crossOrigin ?? "*");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
69
49
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.timing = timing;
|
|
52
|
+
|
|
74
53
|
//# sourceMappingURL=timing.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/timing.ts"],"sourcesContent":["interface Timer {\n description?: string;\n start: number;\n}\n\nexport interface Options {\n enabled: boolean;\n crossOrigin?: string;\n}\n\nexport function timing(options: Options = { enabled: true }) {\n const { enabled, crossOrigin } = options;\n let start = performance.now();\n const headers: string[] = [];\n const timers = new Map<string, Timer>();\n\n return {\n startTime: (name: Lowercase<string>, description?: string) => {\n timers.set(name, { description, start: performance.now() });\n },\n endTime: (name: Lowercase<string>, precision?: number) => {\n const timer = timers.get(name);\n if (!timer) {\n console.warn(`timing: ${name} not found`);\n return;\n }\n const { start, description } = timer;\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n timers.delete(name);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n },\n mark: (name: Lowercase<string>, description?: string, precision?: number) => {\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n start = performance.now();\n },\n setMetric: (\n name: Lowercase<string>,\n value: number | string | undefined,\n description?: string,\n precision?: number\n ) => {\n if (typeof value === 'number') {\n const dur = value.toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n } else {\n const metric = value ? `${name};desc=\"${value}\"` : `${name}`;\n headers.push(metric);\n }\n },\n setTiming: (response: Response) => {\n if (!enabled) return;\n response.headers.append('Server-Timing', headers.join(','));\n response.headers.append('Timing-Allow-Origin', crossOrigin ?? '*');\n },\n };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"timing.cjs","names":[],"sources":["../../src/utils/timing.ts"],"sourcesContent":["interface Timer {\n description?: string;\n start: number;\n}\n\nexport interface Options {\n enabled: boolean;\n crossOrigin?: string;\n}\n\nexport function timing(options: Options = { enabled: true }) {\n const { enabled, crossOrigin } = options;\n let start = performance.now();\n const headers: string[] = [];\n const timers = new Map<string, Timer>();\n\n return {\n startTime: (name: Lowercase<string>, description?: string) => {\n timers.set(name, { description, start: performance.now() });\n },\n endTime: (name: Lowercase<string>, precision?: number) => {\n const timer = timers.get(name);\n if (!timer) {\n console.warn(`timing: ${name} not found`);\n return;\n }\n const { start, description } = timer;\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n timers.delete(name);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n },\n mark: (name: Lowercase<string>, description?: string, precision?: number) => {\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n start = performance.now();\n },\n setMetric: (\n name: Lowercase<string>,\n value: number | string | undefined,\n description?: string,\n precision?: number\n ) => {\n if (typeof value === 'number') {\n const dur = value.toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n } else {\n const metric = value ? `${name};desc=\"${value}\"` : `${name}`;\n headers.push(metric);\n }\n },\n setTiming: (response: Response) => {\n if (!enabled) return;\n response.headers.append('Server-Timing', headers.join(','));\n response.headers.append('Timing-Allow-Origin', crossOrigin ?? '*');\n },\n };\n}\n"],"mappings":";;AAUA,SAAgB,OAAO,UAAmB,EAAE,SAAS,KAAK,GAAG;CAC3D,MAAM,EAAE,SAAS,gBAAgB;CACjC,IAAI,QAAQ,YAAY,IAAI;CAC5B,MAAM,UAAoB,CAAC;CAC3B,MAAM,yBAAS,IAAI,IAAmB;CAEtC,OAAO;EACL,YAAY,MAAyB,gBAAyB;GAC5D,OAAO,IAAI,MAAM;IAAE;IAAa,OAAO,YAAY,IAAI;GAAE,CAAC;EAC5D;EACA,UAAU,MAAyB,cAAuB;GACxD,MAAM,QAAQ,OAAO,IAAI,IAAI;GAC7B,IAAI,CAAC,OAAO;IACV,QAAQ,KAAK,WAAW,KAAK,WAAW;IACxC;GACF;GACA,MAAM,EAAE,OAAO,gBAAgB;GAC/B,MAAM,OAAO,YAAY,IAAI,IAAI,MAAA,CAAO,QAAQ,aAAa,CAAC;GAC9D,OAAO,OAAO,IAAI;GAClB,MAAM,SAAS,cACX,GAAG,KAAK,OAAO,IAAI,SAAS,YAAY,KACxC,GAAG,KAAK,OAAO;GACnB,QAAQ,KAAK,MAAM;EACrB;EACA,OAAO,MAAyB,aAAsB,cAAuB;GAC3E,MAAM,OAAO,YAAY,IAAI,IAAI,MAAA,CAAO,QAAQ,aAAa,CAAC;GAC9D,MAAM,SAAS,cACX,GAAG,KAAK,OAAO,IAAI,SAAS,YAAY,KACxC,GAAG,KAAK,OAAO;GACnB,QAAQ,KAAK,MAAM;GACnB,QAAQ,YAAY,IAAI;EAC1B;EACA,YACE,MACA,OACA,aACA,cACG;GACH,IAAI,OAAO,UAAU,UAAU;IAC7B,MAAM,MAAM,MAAM,QAAQ,aAAa,CAAC;IACxC,MAAM,SAAS,cACX,GAAG,KAAK,OAAO,IAAI,SAAS,YAAY,KACxC,GAAG,KAAK,OAAO;IACnB,QAAQ,KAAK,MAAM;GACrB,OAAO;IACL,MAAM,SAAS,QAAQ,GAAG,KAAK,SAAS,MAAM,KAAK,GAAG;IACtD,QAAQ,KAAK,MAAM;GACrB;EACF;EACA,YAAY,aAAuB;GACjC,IAAI,CAAC,SAAS;GACd,SAAS,QAAQ,OAAO,iBAAiB,QAAQ,KAAK,GAAG,CAAC;GAC1D,SAAS,QAAQ,OAAO,uBAAuB,eAAe,GAAG;EACnE;CACF;AACF"}
|
package/dist/utils/timing.d.cts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
//#region src/utils/timing.d.ts
|
|
1
2
|
interface Options {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
crossOrigin?: string;
|
|
4
5
|
}
|
|
5
6
|
declare function timing(options?: Options): {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
startTime: (name: Lowercase<string>, description?: string) => void;
|
|
8
|
+
endTime: (name: Lowercase<string>, precision?: number) => void;
|
|
9
|
+
mark: (name: Lowercase<string>, description?: string, precision?: number) => void;
|
|
10
|
+
setMetric: (name: Lowercase<string>, value: number | string | undefined, description?: string, precision?: number) => void;
|
|
11
|
+
setTiming: (response: Response) => void;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
export {
|
|
13
|
+
//#endregion
|
|
14
|
+
export { Options, timing };
|
|
15
|
+
//# sourceMappingURL=timing.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.d.cts","names":[],"sources":["../../src/utils/timing.ts"],"mappings":";UAKiB;EACf;EACA;;iBAGc,OAAO,UAAS;EAO5B,YAAS,MAAS,mBAAiB;EAGnC,UAAO,MAAS,mBAAiB;EAcjC,OAAI,MAAS,mBAAiB,sBAAsB;EAQpD,YAAS,MACD,mBAAiB,oCACW,sBACd;EActB,YAAS,UAAa"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/utils/timing.d.ts
|
|
2
|
+
interface Options {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
crossOrigin?: string;
|
|
5
|
+
}
|
|
6
|
+
declare function timing(options?: Options): {
|
|
7
|
+
startTime: (name: Lowercase<string>, description?: string) => void;
|
|
8
|
+
endTime: (name: Lowercase<string>, precision?: number) => void;
|
|
9
|
+
mark: (name: Lowercase<string>, description?: string, precision?: number) => void;
|
|
10
|
+
setMetric: (name: Lowercase<string>, value: number | string | undefined, description?: string, precision?: number) => void;
|
|
11
|
+
setTiming: (response: Response) => void;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { Options, timing };
|
|
15
|
+
//# sourceMappingURL=timing.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.d.mts","names":[],"sources":["../../src/utils/timing.ts"],"mappings":";UAKiB;EACf;EACA;;iBAGc,OAAO,UAAS;EAO5B,YAAS,MAAS,mBAAiB;EAGnC,UAAO,MAAS,mBAAiB;EAcjC,OAAI,MAAS,mBAAiB,sBAAsB;EAQpD,YAAS,MACD,mBAAiB,oCACW,sBACd;EActB,YAAS,UAAa"}
|
package/dist/utils/timing.mjs
CHANGED
|
@@ -1,49 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/utils/timing.ts
|
|
2
2
|
function timing(options = { enabled: true }) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
3
|
+
const { enabled, crossOrigin } = options;
|
|
4
|
+
let start = performance.now();
|
|
5
|
+
const headers = [];
|
|
6
|
+
const timers = /* @__PURE__ */ new Map();
|
|
7
|
+
return {
|
|
8
|
+
startTime: (name, description) => {
|
|
9
|
+
timers.set(name, {
|
|
10
|
+
description,
|
|
11
|
+
start: performance.now()
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
endTime: (name, precision) => {
|
|
15
|
+
const timer = timers.get(name);
|
|
16
|
+
if (!timer) {
|
|
17
|
+
console.warn(`timing: ${name} not found`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { start, description } = timer;
|
|
21
|
+
const dur = (performance.now() - start).toFixed(precision ?? 1);
|
|
22
|
+
timers.delete(name);
|
|
23
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
24
|
+
headers.push(metric);
|
|
25
|
+
},
|
|
26
|
+
mark: (name, description, precision) => {
|
|
27
|
+
const dur = (performance.now() - start).toFixed(precision ?? 1);
|
|
28
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
29
|
+
headers.push(metric);
|
|
30
|
+
start = performance.now();
|
|
31
|
+
},
|
|
32
|
+
setMetric: (name, value, description, precision) => {
|
|
33
|
+
if (typeof value === "number") {
|
|
34
|
+
const dur = value.toFixed(precision ?? 1);
|
|
35
|
+
const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
|
|
36
|
+
headers.push(metric);
|
|
37
|
+
} else {
|
|
38
|
+
const metric = value ? `${name};desc="${value}"` : `${name}`;
|
|
39
|
+
headers.push(metric);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
setTiming: (response) => {
|
|
43
|
+
if (!enabled) return;
|
|
44
|
+
response.headers.append("Server-Timing", headers.join(","));
|
|
45
|
+
response.headers.append("Timing-Allow-Origin", crossOrigin ?? "*");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
45
48
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
//#endregion
|
|
50
|
+
export { timing };
|
|
51
|
+
|
|
49
52
|
//# sourceMappingURL=timing.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/timing.ts"],"sourcesContent":["interface Timer {\n description?: string;\n start: number;\n}\n\nexport interface Options {\n enabled: boolean;\n crossOrigin?: string;\n}\n\nexport function timing(options: Options = { enabled: true }) {\n const { enabled, crossOrigin } = options;\n let start = performance.now();\n const headers: string[] = [];\n const timers = new Map<string, Timer>();\n\n return {\n startTime: (name: Lowercase<string>, description?: string) => {\n timers.set(name, { description, start: performance.now() });\n },\n endTime: (name: Lowercase<string>, precision?: number) => {\n const timer = timers.get(name);\n if (!timer) {\n console.warn(`timing: ${name} not found`);\n return;\n }\n const { start, description } = timer;\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n timers.delete(name);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n },\n mark: (name: Lowercase<string>, description?: string, precision?: number) => {\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n start = performance.now();\n },\n setMetric: (\n name: Lowercase<string>,\n value: number | string | undefined,\n description?: string,\n precision?: number\n ) => {\n if (typeof value === 'number') {\n const dur = value.toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n } else {\n const metric = value ? `${name};desc=\"${value}\"` : `${name}`;\n headers.push(metric);\n }\n },\n setTiming: (response: Response) => {\n if (!enabled) return;\n response.headers.append('Server-Timing', headers.join(','));\n response.headers.append('Timing-Allow-Origin', crossOrigin ?? '*');\n },\n };\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"timing.mjs","names":[],"sources":["../../src/utils/timing.ts"],"sourcesContent":["interface Timer {\n description?: string;\n start: number;\n}\n\nexport interface Options {\n enabled: boolean;\n crossOrigin?: string;\n}\n\nexport function timing(options: Options = { enabled: true }) {\n const { enabled, crossOrigin } = options;\n let start = performance.now();\n const headers: string[] = [];\n const timers = new Map<string, Timer>();\n\n return {\n startTime: (name: Lowercase<string>, description?: string) => {\n timers.set(name, { description, start: performance.now() });\n },\n endTime: (name: Lowercase<string>, precision?: number) => {\n const timer = timers.get(name);\n if (!timer) {\n console.warn(`timing: ${name} not found`);\n return;\n }\n const { start, description } = timer;\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n timers.delete(name);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n },\n mark: (name: Lowercase<string>, description?: string, precision?: number) => {\n const dur = (performance.now() - start).toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n start = performance.now();\n },\n setMetric: (\n name: Lowercase<string>,\n value: number | string | undefined,\n description?: string,\n precision?: number\n ) => {\n if (typeof value === 'number') {\n const dur = value.toFixed(precision ?? 1);\n const metric = description\n ? `${name};dur=${dur};desc=\"${description}\"`\n : `${name};dur=${dur}`;\n headers.push(metric);\n } else {\n const metric = value ? `${name};desc=\"${value}\"` : `${name}`;\n headers.push(metric);\n }\n },\n setTiming: (response: Response) => {\n if (!enabled) return;\n response.headers.append('Server-Timing', headers.join(','));\n response.headers.append('Timing-Allow-Origin', crossOrigin ?? '*');\n },\n };\n}\n"],"mappings":";AAUA,SAAgB,OAAO,UAAmB,EAAE,SAAS,KAAK,GAAG;CAC3D,MAAM,EAAE,SAAS,gBAAgB;CACjC,IAAI,QAAQ,YAAY,IAAI;CAC5B,MAAM,UAAoB,CAAC;CAC3B,MAAM,yBAAS,IAAI,IAAmB;CAEtC,OAAO;EACL,YAAY,MAAyB,gBAAyB;GAC5D,OAAO,IAAI,MAAM;IAAE;IAAa,OAAO,YAAY,IAAI;GAAE,CAAC;EAC5D;EACA,UAAU,MAAyB,cAAuB;GACxD,MAAM,QAAQ,OAAO,IAAI,IAAI;GAC7B,IAAI,CAAC,OAAO;IACV,QAAQ,KAAK,WAAW,KAAK,WAAW;IACxC;GACF;GACA,MAAM,EAAE,OAAO,gBAAgB;GAC/B,MAAM,OAAO,YAAY,IAAI,IAAI,MAAA,CAAO,QAAQ,aAAa,CAAC;GAC9D,OAAO,OAAO,IAAI;GAClB,MAAM,SAAS,cACX,GAAG,KAAK,OAAO,IAAI,SAAS,YAAY,KACxC,GAAG,KAAK,OAAO;GACnB,QAAQ,KAAK,MAAM;EACrB;EACA,OAAO,MAAyB,aAAsB,cAAuB;GAC3E,MAAM,OAAO,YAAY,IAAI,IAAI,MAAA,CAAO,QAAQ,aAAa,CAAC;GAC9D,MAAM,SAAS,cACX,GAAG,KAAK,OAAO,IAAI,SAAS,YAAY,KACxC,GAAG,KAAK,OAAO;GACnB,QAAQ,KAAK,MAAM;GACnB,QAAQ,YAAY,IAAI;EAC1B;EACA,YACE,MACA,OACA,aACA,cACG;GACH,IAAI,OAAO,UAAU,UAAU;IAC7B,MAAM,MAAM,MAAM,QAAQ,aAAa,CAAC;IACxC,MAAM,SAAS,cACX,GAAG,KAAK,OAAO,IAAI,SAAS,YAAY,KACxC,GAAG,KAAK,OAAO;IACnB,QAAQ,KAAK,MAAM;GACrB,OAAO;IACL,MAAM,SAAS,QAAQ,GAAG,KAAK,SAAS,MAAM,KAAK,GAAG;IACtD,QAAQ,KAAK,MAAM;GACrB;EACF;EACA,YAAY,aAAuB;GACjC,IAAI,CAAC,SAAS;GACd,SAAS,QAAQ,OAAO,iBAAiB,QAAQ,KAAK,GAAG,CAAC;GAC1D,SAAS,QAAQ,OAAO,uBAAuB,eAAe,GAAG;EACnE;CACF;AACF"}
|