@shware/http 2.9.1 → 2.9.2

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.
@@ -24,53 +24,11 @@ __export(geolocation_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(geolocation_exports);
26
26
  var import_adapter = require("hono/adapter");
27
- var import_ip = require("../utils/ip.cjs");
28
- function getGeolocationFromCloudflareWorker(c) {
29
- return {
30
- ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
31
- city: c.req.header("cf-ipcity"),
32
- country: c.req.header("cf-ipcountry"),
33
- continent: c.req.header("cf-ipcontinent"),
34
- longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
35
- latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
36
- region: c.req.header("cf-region-code"),
37
- metro_code: c.req.header("cf-metro-code"),
38
- postal_code: c.req.header("cf-postal-code"),
39
- time_zone: c.req.header("cf-timezone")
40
- };
41
- }
42
- function getGeolocationFromVercel(c) {
43
- return {
44
- ip_address: c.req.header("x-real-ip"),
45
- city: c.req.header("x-vercel-ip-city"),
46
- country: c.req.header("x-vercel-ip-country"),
47
- continent: c.req.header("x-vercel-ip-continent"),
48
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
49
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
50
- region: c.req.header("x-vercel-ip-country-region"),
51
- metro_code: void 0,
52
- postal_code: c.req.header("x-vercel-ip-postal-code"),
53
- time_zone: void 0
54
- };
55
- }
56
- function getGeolocationFromCloudfront(c) {
57
- return {
58
- ip_address: (0, import_ip.extractIpAddress)(c.req.header("CloudFront-Viewer-Address")) ?? void 0,
59
- city: c.req.header("CloudFront-Viewer-City"),
60
- country: c.req.header("CloudFront-Viewer-Country"),
61
- continent: void 0,
62
- longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : void 0,
63
- latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : void 0,
64
- region: c.req.header("CloudFront-Viewer-Country-Region"),
65
- metro_code: c.req.header("CloudFront-Viewer-Metro-Code"),
66
- postal_code: c.req.header("CloudFront-Viewer-Postal-Code"),
67
- time_zone: c.req.header("CloudFront-Viewer-Time-Zone")
68
- };
69
- }
27
+ var import_geolocation = require("../utils/geolocation.cjs");
70
28
  function geolocation(c) {
71
- if ((0, import_adapter.getRuntimeKey)() === "workerd") return getGeolocationFromCloudflareWorker(c);
72
- if (c.req.header("x-vercel-id")) return getGeolocationFromVercel(c);
73
- return getGeolocationFromCloudfront(c);
29
+ if ((0, import_adapter.getRuntimeKey)() === "workerd") return (0, import_geolocation.getGeolocationFromCloudflare)(c.req.raw);
30
+ if (c.req.header("x-vercel-id")) return (0, import_geolocation.getGeolocationFromVercel)(c.req.raw);
31
+ return (0, import_geolocation.getGeolocationFromCloudfront)(c.req.raw);
74
32
  }
75
33
  // Annotate the CommonJS export names for ESM import in node:
76
34
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport { getRuntimeKey } from 'hono/adapter';\nimport { extractIpAddress } from '../utils/ip';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n time_zone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region: c.req.header('x-vercel-ip-country-region'),\n metro_code: undefined,\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n time_zone: undefined,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')) ?? undefined,\n city: c.req.header('CloudFront-Viewer-City'),\n country: c.req.header('CloudFront-Viewer-Country'),\n continent: undefined,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : undefined,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : undefined,\n region: c.req.header('CloudFront-Viewer-Country-Region'),\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code'),\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code'),\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone'),\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA8B;AAC9B,gBAAiC;AAgBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IAC7E,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACrC,YAAY,EAAE,IAAI,OAAO,eAAe;AAAA,IACxC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,WAAW,EAAE,IAAI,OAAO,aAAa;AAAA,EACvC;AACF;AAGA,SAAS,yBAAyB,GAAyB;AACzD,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,WAAW;AAAA,IACpC,MAAM,EAAE,IAAI,OAAO,kBAAkB;AAAA,IACrC,SAAS,EAAE,IAAI,OAAO,qBAAqB;AAAA,IAC3C,WAAW,EAAE,IAAI,OAAO,uBAAuB;AAAA,IAC/C,WAAW,EAAE,IAAI,OAAO,uBAAuB,IAC3C,OAAO,EAAE,IAAI,OAAO,uBAAuB,CAAC,IAC5C;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,sBAAsB,IACzC,OAAO,EAAE,IAAI,OAAO,sBAAsB,CAAC,IAC3C;AAAA,IACJ,QAAQ,EAAE,IAAI,OAAO,4BAA4B;AAAA,IACjD,YAAY;AAAA,IACZ,aAAa,EAAE,IAAI,OAAO,yBAAyB;AAAA,IACnD,WAAW;AAAA,EACb;AACF;AAGA,SAAS,6BAA6B,GAAyB;AAC7D,SAAO;AAAA,IACL,gBAAY,4BAAiB,EAAE,IAAI,OAAO,2BAA2B,CAAC,KAAK;AAAA,IAC3E,MAAM,EAAE,IAAI,OAAO,wBAAwB;AAAA,IAC3C,SAAS,EAAE,IAAI,OAAO,2BAA2B;AAAA,IACjD,WAAW;AAAA,IACX,WAAW,EAAE,IAAI,OAAO,6BAA6B,IACjD,OAAO,EAAE,IAAI,OAAO,6BAA6B,CAAC,IAClD;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,4BAA4B,IAC/C,OAAO,EAAE,IAAI,OAAO,4BAA4B,CAAC,IACjD;AAAA,IACJ,QAAQ,EAAE,IAAI,OAAO,kCAAkC;AAAA,IACvD,YAAY,EAAE,IAAI,OAAO,8BAA8B;AAAA,IACvD,aAAa,EAAE,IAAI,OAAO,+BAA+B;AAAA,IACzD,WAAW,EAAE,IAAI,OAAO,6BAA6B;AAAA,EACvD;AACF;AAEO,SAAS,YAAY,GAAyB;AACnD,UAAI,8BAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport { getRuntimeKey } from 'hono/adapter';\nimport {\n type Geolocation,\n getGeolocationFromCloudflare,\n getGeolocationFromCloudfront,\n getGeolocationFromVercel,\n} from '../utils/geolocation';\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflare(c.req.raw);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c.req.raw);\n return getGeolocationFromCloudfront(c.req.raw);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA8B;AAC9B,yBAKO;AAEA,SAAS,YAAY,GAAyB;AACnD,UAAI,8BAAc,MAAM,UAAW,YAAO,iDAA6B,EAAE,IAAI,GAAG;AAChF,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,YAAO,6CAAyB,EAAE,IAAI,GAAG;AAC1E,aAAO,iDAA6B,EAAE,IAAI,GAAG;AAC/C;","names":[]}
@@ -1,17 +1,6 @@
1
1
  import { Context } from 'hono';
2
+ import { Geolocation } from '../utils/geolocation.cjs';
2
3
 
3
- type Geolocation = {
4
- ip_address?: string;
5
- city?: string;
6
- country?: string;
7
- continent?: string;
8
- longitude?: number;
9
- latitude?: number;
10
- region?: string;
11
- metro_code?: string;
12
- postal_code?: string;
13
- time_zone?: string;
14
- };
15
4
  declare function geolocation(c: Context): Geolocation;
16
5
 
17
- export { type Geolocation, geolocation };
6
+ export { geolocation };
@@ -1,17 +1,6 @@
1
1
  import { Context } from 'hono';
2
+ import { Geolocation } from '../utils/geolocation.js';
2
3
 
3
- type Geolocation = {
4
- ip_address?: string;
5
- city?: string;
6
- country?: string;
7
- continent?: string;
8
- longitude?: number;
9
- latitude?: number;
10
- region?: string;
11
- metro_code?: string;
12
- postal_code?: string;
13
- time_zone?: string;
14
- };
15
4
  declare function geolocation(c: Context): Geolocation;
16
5
 
17
- export { type Geolocation, geolocation };
6
+ export { geolocation };
@@ -1,52 +1,14 @@
1
1
  // src/hono/geolocation.ts
2
2
  import { getRuntimeKey } from "hono/adapter";
3
- import { extractIpAddress } from "../utils/ip.mjs";
4
- function getGeolocationFromCloudflareWorker(c) {
5
- return {
6
- ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
7
- city: c.req.header("cf-ipcity"),
8
- country: c.req.header("cf-ipcountry"),
9
- continent: c.req.header("cf-ipcontinent"),
10
- longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
11
- latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
12
- region: c.req.header("cf-region-code"),
13
- metro_code: c.req.header("cf-metro-code"),
14
- postal_code: c.req.header("cf-postal-code"),
15
- time_zone: c.req.header("cf-timezone")
16
- };
17
- }
18
- function getGeolocationFromVercel(c) {
19
- return {
20
- ip_address: c.req.header("x-real-ip"),
21
- city: c.req.header("x-vercel-ip-city"),
22
- country: c.req.header("x-vercel-ip-country"),
23
- continent: c.req.header("x-vercel-ip-continent"),
24
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
25
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
26
- region: c.req.header("x-vercel-ip-country-region"),
27
- metro_code: void 0,
28
- postal_code: c.req.header("x-vercel-ip-postal-code"),
29
- time_zone: void 0
30
- };
31
- }
32
- function getGeolocationFromCloudfront(c) {
33
- return {
34
- ip_address: extractIpAddress(c.req.header("CloudFront-Viewer-Address")) ?? void 0,
35
- city: c.req.header("CloudFront-Viewer-City"),
36
- country: c.req.header("CloudFront-Viewer-Country"),
37
- continent: void 0,
38
- longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : void 0,
39
- latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : void 0,
40
- region: c.req.header("CloudFront-Viewer-Country-Region"),
41
- metro_code: c.req.header("CloudFront-Viewer-Metro-Code"),
42
- postal_code: c.req.header("CloudFront-Viewer-Postal-Code"),
43
- time_zone: c.req.header("CloudFront-Viewer-Time-Zone")
44
- };
45
- }
3
+ import {
4
+ getGeolocationFromCloudflare,
5
+ getGeolocationFromCloudfront,
6
+ getGeolocationFromVercel
7
+ } from "../utils/geolocation.mjs";
46
8
  function geolocation(c) {
47
- if (getRuntimeKey() === "workerd") return getGeolocationFromCloudflareWorker(c);
48
- if (c.req.header("x-vercel-id")) return getGeolocationFromVercel(c);
49
- return getGeolocationFromCloudfront(c);
9
+ if (getRuntimeKey() === "workerd") return getGeolocationFromCloudflare(c.req.raw);
10
+ if (c.req.header("x-vercel-id")) return getGeolocationFromVercel(c.req.raw);
11
+ return getGeolocationFromCloudfront(c.req.raw);
50
12
  }
51
13
  export {
52
14
  geolocation
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport { getRuntimeKey } from 'hono/adapter';\nimport { extractIpAddress } from '../utils/ip';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n time_zone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region: c.req.header('x-vercel-ip-country-region'),\n metro_code: undefined,\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n time_zone: undefined,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')) ?? undefined,\n city: c.req.header('CloudFront-Viewer-City'),\n country: c.req.header('CloudFront-Viewer-Country'),\n continent: undefined,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : undefined,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : undefined,\n region: c.req.header('CloudFront-Viewer-Country-Region'),\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code'),\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code'),\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone'),\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAgBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IAC7E,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACrC,YAAY,EAAE,IAAI,OAAO,eAAe;AAAA,IACxC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,WAAW,EAAE,IAAI,OAAO,aAAa;AAAA,EACvC;AACF;AAGA,SAAS,yBAAyB,GAAyB;AACzD,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,WAAW;AAAA,IACpC,MAAM,EAAE,IAAI,OAAO,kBAAkB;AAAA,IACrC,SAAS,EAAE,IAAI,OAAO,qBAAqB;AAAA,IAC3C,WAAW,EAAE,IAAI,OAAO,uBAAuB;AAAA,IAC/C,WAAW,EAAE,IAAI,OAAO,uBAAuB,IAC3C,OAAO,EAAE,IAAI,OAAO,uBAAuB,CAAC,IAC5C;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,sBAAsB,IACzC,OAAO,EAAE,IAAI,OAAO,sBAAsB,CAAC,IAC3C;AAAA,IACJ,QAAQ,EAAE,IAAI,OAAO,4BAA4B;AAAA,IACjD,YAAY;AAAA,IACZ,aAAa,EAAE,IAAI,OAAO,yBAAyB;AAAA,IACnD,WAAW;AAAA,EACb;AACF;AAGA,SAAS,6BAA6B,GAAyB;AAC7D,SAAO;AAAA,IACL,YAAY,iBAAiB,EAAE,IAAI,OAAO,2BAA2B,CAAC,KAAK;AAAA,IAC3E,MAAM,EAAE,IAAI,OAAO,wBAAwB;AAAA,IAC3C,SAAS,EAAE,IAAI,OAAO,2BAA2B;AAAA,IACjD,WAAW;AAAA,IACX,WAAW,EAAE,IAAI,OAAO,6BAA6B,IACjD,OAAO,EAAE,IAAI,OAAO,6BAA6B,CAAC,IAClD;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,4BAA4B,IAC/C,OAAO,EAAE,IAAI,OAAO,4BAA4B,CAAC,IACjD;AAAA,IACJ,QAAQ,EAAE,IAAI,OAAO,kCAAkC;AAAA,IACvD,YAAY,EAAE,IAAI,OAAO,8BAA8B;AAAA,IACvD,aAAa,EAAE,IAAI,OAAO,+BAA+B;AAAA,IACzD,WAAW,EAAE,IAAI,OAAO,6BAA6B;AAAA,EACvD;AACF;AAEO,SAAS,YAAY,GAAyB;AACnD,MAAI,cAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport { getRuntimeKey } from 'hono/adapter';\nimport {\n type Geolocation,\n getGeolocationFromCloudflare,\n getGeolocationFromCloudfront,\n getGeolocationFromVercel,\n} from '../utils/geolocation';\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflare(c.req.raw);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c.req.raw);\n return getGeolocationFromCloudfront(c.req.raw);\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAC9B;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,SAAS,YAAY,GAAyB;AACnD,MAAI,cAAc,MAAM,UAAW,QAAO,6BAA6B,EAAE,IAAI,GAAG;AAChF,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,EAAE,IAAI,GAAG;AAC1E,SAAO,6BAA6B,EAAE,IAAI,GAAG;AAC/C;","names":[]}
@@ -12,3 +12,4 @@ import 'hono';
12
12
  import 'zod/v4/core';
13
13
  import 'zod';
14
14
  import 'hono/request-id';
15
+ import '../utils/geolocation.cjs';
@@ -12,3 +12,4 @@ import 'hono';
12
12
  import 'zod/v4/core';
13
13
  import 'zod';
14
14
  import 'hono/request-id';
15
+ import '../utils/geolocation.js';
package/dist/index.cjs CHANGED
@@ -44,9 +44,11 @@ __export(index_exports, {
44
44
  Status: () => import_status.Status,
45
45
  StatusError: () => import_status.StatusError,
46
46
  UidGenerator: () => import_snowflake.UidGenerator,
47
+ forwardToGoogleTagGateway: () => import_google_tag_gateway.forwardToGoogleTagGateway,
47
48
  getErrorInfo: () => import_parse.getErrorInfo,
48
49
  getErrorMessage: () => import_parse.getErrorMessage,
49
50
  getFieldViolations: () => import_parse.getFieldViolations,
51
+ getGeolocation: () => import_geolocation.getGeolocation,
50
52
  getNextPageParam: () => import_response.getNextPageParam,
51
53
  getPreviousPageParam: () => import_response.getPreviousPageParam,
52
54
  initialPageParam: () => import_response.initialPageParam,
@@ -63,6 +65,8 @@ var import_response = require("./response.cjs");
63
65
  var import_snowflake = require("./snowflake.cjs");
64
66
  var MAX_LENGTH = __toESM(require("./max-length/index.cjs"), 1);
65
67
  var import_timing = require("./utils/timing.cjs");
68
+ var import_geolocation = require("./utils/geolocation.cjs");
69
+ var import_google_tag_gateway = require("./utils/google-tag-gateway.cjs");
66
70
  var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
67
71
  // Annotate the CommonJS export names for ESM import in node:
68
72
  0 && (module.exports = {
@@ -80,9 +84,11 @@ var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
80
84
  Status,
81
85
  StatusError,
82
86
  UidGenerator,
87
+ forwardToGoogleTagGateway,
83
88
  getErrorInfo,
84
89
  getErrorMessage,
85
90
  getFieldViolations,
91
+ getGeolocation,
86
92
  getNextPageParam,
87
93
  getPreviousPageParam,
88
94
  initialPageParam,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type { ErrorReason, ResolvedErrorReason } from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorInfo, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n Items,\n Pages,\n Cursor,\n pageParamsSchema,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n InfinitePageData,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { timing } from './utils/timing';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAKO;AAEP,oBAcO;AACP,oBAAoD;AACpD,mBAAkE;AAClE,sBAQO;AAeP,uBAAkC;AAElC,iBAA4B;AAC5B,oBAAuB;AACvB,wBAAoD;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type { ErrorReason, ResolvedErrorReason } from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorInfo, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n Items,\n Pages,\n Cursor,\n pageParamsSchema,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n InfinitePageData,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { timing } from './utils/timing';\nexport { getGeolocation } from './utils/geolocation';\nexport { forwardToGoogleTagGateway } from './utils/google-tag-gateway';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,mBAKO;AAEP,oBAcO;AACP,oBAAoD;AACpD,mBAAkE;AAClE,sBAQO;AAeP,uBAAkC;AAElC,iBAA4B;AAC5B,oBAAuB;AACvB,yBAA+B;AAC/B,gCAA0C;AAC1C,wBAAoD;","names":[]}
package/dist/index.d.cts CHANGED
@@ -7,6 +7,8 @@ export { Cursor, Empty, Entity, EntityId, InfinitePageData, InitParams, Items, N
7
7
  export { UidGenerator, uid } from './snowflake.cjs';
8
8
  export { i as MAX_LENGTH } from './index-BnPgRQDl.cjs';
9
9
  export { timing } from './utils/timing.cjs';
10
+ export { getGeolocation } from './utils/geolocation.cjs';
11
+ export { forwardToGoogleTagGateway } from './utils/google-tag-gateway.cjs';
10
12
  export { ISO3166CountryCode, ISO_3601_1 } from './iso/iso_3601_1.cjs';
11
13
  import 'i18next';
12
14
  import 'zod/v4/core';
package/dist/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export { Cursor, Empty, Entity, EntityId, InfinitePageData, InitParams, Items, N
7
7
  export { UidGenerator, uid } from './snowflake.js';
8
8
  export { i as MAX_LENGTH } from './index-BnPgRQDl.js';
9
9
  export { timing } from './utils/timing.js';
10
+ export { getGeolocation } from './utils/geolocation.js';
11
+ export { forwardToGoogleTagGateway } from './utils/google-tag-gateway.js';
10
12
  export { ISO3166CountryCode, ISO_3601_1 } from './iso/iso_3601_1.js';
11
13
  import 'i18next';
12
14
  import 'zod/v4/core';
package/dist/index.mjs CHANGED
@@ -23,6 +23,8 @@ import {
23
23
  import { UidGenerator, uid } from "./snowflake.mjs";
24
24
  import * as MAX_LENGTH from "./max-length/index.mjs";
25
25
  import { timing } from "./utils/timing.mjs";
26
+ import { getGeolocation } from "./utils/geolocation.mjs";
27
+ import { forwardToGoogleTagGateway } from "./utils/google-tag-gateway.mjs";
26
28
  import { ISO_3601_1 } from "./iso/iso_3601_1.mjs";
27
29
  export {
28
30
  CheckoutCreateError,
@@ -39,9 +41,11 @@ export {
39
41
  Status,
40
42
  StatusError,
41
43
  UidGenerator,
44
+ forwardToGoogleTagGateway,
42
45
  getErrorInfo,
43
46
  getErrorMessage,
44
47
  getFieldViolations,
48
+ getGeolocation,
45
49
  getNextPageParam,
46
50
  getPreviousPageParam,
47
51
  initialPageParam,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type { ErrorReason, ResolvedErrorReason } from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorInfo, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n Items,\n Pages,\n Cursor,\n pageParamsSchema,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n InfinitePageData,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { timing } from './utils/timing';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OAYK;AACP,SAAS,QAAQ,mBAAmC;AACpD,SAAS,cAAc,iBAAiB,0BAA0B;AAClE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeP,SAAS,cAAc,WAAW;AAElC,YAAY,gBAAgB;AAC5B,SAAS,cAAc;AACvB,SAAS,kBAA2C;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @example\n * import { Details, Status } from '@repo/error';\n *\n * Status.adapter = () => new Error('Error');\n *\n * const details = Details.new()\n * .requestInfo({ requestId: '1234567890', servingData: '/v1/tests' })\n * .errorInfo({ reason: 'ACCOUNT_LOCKED' });\n *\n * throw Status.alreadyExists('xxx').error(details);\n */\n\nexport {\n LoginTimeoutError,\n LoginCanceledError,\n CheckoutCreateError,\n PurchaseError,\n} from './error/index';\nexport type { ErrorReason, ResolvedErrorReason } from './error/reason';\nexport {\n DetailType,\n Details,\n type ErrorInfo,\n type RetryInfo,\n type DebugInfo,\n type QuotaFailure,\n type PreconditionFailure,\n type BadRequest,\n type RequestInfo,\n type ResourceInfo,\n type Help,\n type LocalizedMessage,\n type Detail,\n} from './error/detail';\nexport { Status, StatusError, type ErrorBody } from './error/status';\nexport { getErrorInfo, getErrorMessage, getFieldViolations } from './error/parse';\nexport {\n Items,\n Pages,\n Cursor,\n pageParamsSchema,\n initialPageParam,\n getPreviousPageParam,\n getNextPageParam,\n} from './response';\nexport type {\n Empty,\n EntityId,\n Entity,\n Response,\n InitParams,\n NextParams,\n PrevParams,\n PageParams,\n ParentPageParams,\n Page,\n InfinitePageData,\n} from './response';\n\nexport { UidGenerator, uid } from './snowflake';\n\nexport * as MAX_LENGTH from './max-length/index';\nexport { timing } from './utils/timing';\nexport { getGeolocation } from './utils/geolocation';\nexport { forwardToGoogleTagGateway } from './utils/google-tag-gateway';\nexport { ISO_3601_1, type ISO3166CountryCode } from './iso/iso_3601_1';\n"],"mappings":";AAaA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OAYK;AACP,SAAS,QAAQ,mBAAmC;AACpD,SAAS,cAAc,iBAAiB,0BAA0B;AAClE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeP,SAAS,cAAc,WAAW;AAElC,YAAY,gBAAgB;AAC5B,SAAS,cAAc;AACvB,SAAS,sBAAsB;AAC/B,SAAS,iCAAiC;AAC1C,SAAS,kBAA2C;","names":[]}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
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/geolocation.ts
21
+ var geolocation_exports = {};
22
+ __export(geolocation_exports, {
23
+ getGeolocation: () => getGeolocation,
24
+ getGeolocationFromCloudflare: () => getGeolocationFromCloudflare,
25
+ getGeolocationFromCloudfront: () => getGeolocationFromCloudfront,
26
+ getGeolocationFromVercel: () => getGeolocationFromVercel
27
+ });
28
+ module.exports = __toCommonJS(geolocation_exports);
29
+ var import_ip = require("./ip.cjs");
30
+ function toNumber(value) {
31
+ return value ? Number(value) : void 0;
32
+ }
33
+ function getGeolocationFromCloudflare(r) {
34
+ return {
35
+ ip_address: r.headers.get("true-client-ip") ?? r.headers.get("cf-connecting-ip") ?? void 0,
36
+ city: r.headers.get("cf-ipcity") ?? void 0,
37
+ country: r.headers.get("cf-ipcountry") ?? void 0,
38
+ continent: r.headers.get("cf-ipcontinent") ?? void 0,
39
+ longitude: toNumber(r.headers.get("cf-iplongitude")),
40
+ latitude: toNumber(r.headers.get("cf-iplatitude")),
41
+ region: r.headers.get("cf-region-code") ?? void 0,
42
+ metro_code: r.headers.get("cf-metro-code") ?? void 0,
43
+ postal_code: r.headers.get("cf-postal-code") ?? void 0,
44
+ time_zone: r.headers.get("cf-timezone") ?? void 0
45
+ };
46
+ }
47
+ function getGeolocationFromVercel(r) {
48
+ return {
49
+ ip_address: r.headers.get("x-real-ip") ?? void 0,
50
+ city: r.headers.get("x-vercel-ip-city") ?? void 0,
51
+ country: r.headers.get("x-vercel-ip-country") ?? void 0,
52
+ continent: r.headers.get("x-vercel-ip-continent") ?? void 0,
53
+ longitude: toNumber(r.headers.get("x-vercel-ip-longitude")),
54
+ latitude: toNumber(r.headers.get("x-vercel-ip-latitude")),
55
+ region: r.headers.get("x-vercel-ip-country-region") ?? void 0,
56
+ postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
57
+ };
58
+ }
59
+ function getGeolocationFromCloudfront(r) {
60
+ return {
61
+ ip_address: (0, import_ip.extractIpAddress)(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
62
+ city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
63
+ country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
64
+ longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
65
+ latitude: toNumber(r.headers.get("CloudFront-Viewer-Latitude")),
66
+ region: r.headers.get("CloudFront-Viewer-Country-Region") ?? void 0,
67
+ metro_code: r.headers.get("CloudFront-Viewer-Metro-Code") ?? void 0,
68
+ postal_code: r.headers.get("CloudFront-Viewer-Postal-Code") ?? void 0,
69
+ time_zone: r.headers.get("CloudFront-Viewer-Time-Zone") ?? void 0
70
+ };
71
+ }
72
+ function getGeolocation(r) {
73
+ if (r.headers.get("x-vercel-id")) return getGeolocationFromVercel(r);
74
+ if (r.headers.get("cf-ray")) return getGeolocationFromCloudflare(r);
75
+ return getGeolocationFromCloudfront(r);
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ getGeolocation,
80
+ getGeolocationFromCloudflare,
81
+ getGeolocationFromCloudfront,
82
+ getGeolocationFromVercel
83
+ });
84
+ //# sourceMappingURL=geolocation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["import { extractIpAddress } from './ip';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\nfunction toNumber(value: string | null): number | undefined {\n return value ? Number(value) : undefined;\n}\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function getGeolocationFromCloudflare(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('true-client-ip') ?? r.headers.get('cf-connecting-ip') ?? undefined,\n city: r.headers.get('cf-ipcity') ?? undefined,\n country: r.headers.get('cf-ipcountry') ?? undefined,\n continent: r.headers.get('cf-ipcontinent') ?? undefined,\n longitude: toNumber(r.headers.get('cf-iplongitude')),\n latitude: toNumber(r.headers.get('cf-iplatitude')),\n region: r.headers.get('cf-region-code') ?? undefined,\n metro_code: r.headers.get('cf-metro-code') ?? undefined,\n postal_code: r.headers.get('cf-postal-code') ?? undefined,\n time_zone: r.headers.get('cf-timezone') ?? undefined,\n };\n}\n\n/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function getGeolocationFromVercel(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('x-real-ip') ?? undefined,\n city: r.headers.get('x-vercel-ip-city') ?? undefined,\n country: r.headers.get('x-vercel-ip-country') ?? undefined,\n continent: r.headers.get('x-vercel-ip-continent') ?? undefined,\n longitude: toNumber(r.headers.get('x-vercel-ip-longitude')),\n latitude: toNumber(r.headers.get('x-vercel-ip-latitude')),\n region: r.headers.get('x-vercel-ip-country-region') ?? undefined,\n postal_code: r.headers.get('x-vercel-ip-postal-code') ?? undefined,\n };\n}\n\n/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nexport function getGeolocationFromCloudfront(r: Request): Geolocation {\n return {\n ip_address: extractIpAddress(r.headers.get('CloudFront-Viewer-Address')) ?? undefined,\n city: r.headers.get('CloudFront-Viewer-City') ?? undefined,\n country: r.headers.get('CloudFront-Viewer-Country') ?? undefined,\n longitude: toNumber(r.headers.get('CloudFront-Viewer-Longitude')),\n latitude: toNumber(r.headers.get('CloudFront-Viewer-Latitude')),\n region: r.headers.get('CloudFront-Viewer-Country-Region') ?? undefined,\n metro_code: r.headers.get('CloudFront-Viewer-Metro-Code') ?? undefined,\n postal_code: r.headers.get('CloudFront-Viewer-Postal-Code') ?? undefined,\n time_zone: r.headers.get('CloudFront-Viewer-Time-Zone') ?? undefined,\n };\n}\n\nexport function getGeolocation(r: Request): Geolocation {\n if (r.headers.get('x-vercel-id')) return getGeolocationFromVercel(r);\n if (r.headers.get('cf-ray')) return getGeolocationFromCloudflare(r);\n return getGeolocationFromCloudfront(r);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAiC;AAejC,SAAS,SAAS,OAA0C;AAC1D,SAAO,QAAQ,OAAO,KAAK,IAAI;AACjC;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IACpF,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IACpC,SAAS,EAAE,QAAQ,IAAI,cAAc,KAAK;AAAA,IAC1C,WAAW,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC9C,WAAW,SAAS,EAAE,QAAQ,IAAI,gBAAgB,CAAC;AAAA,IACnD,UAAU,SAAS,EAAE,QAAQ,IAAI,eAAe,CAAC;AAAA,IACjD,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC3C,YAAY,EAAE,QAAQ,IAAI,eAAe,KAAK;AAAA,IAC9C,aAAa,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAChD,WAAW,EAAE,QAAQ,IAAI,aAAa,KAAK;AAAA,EAC7C;AACF;AAGO,SAAS,yBAAyB,GAAyB;AAChE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IAC1C,MAAM,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IAC3C,SAAS,EAAE,QAAQ,IAAI,qBAAqB,KAAK;AAAA,IACjD,WAAW,EAAE,QAAQ,IAAI,uBAAuB,KAAK;AAAA,IACrD,WAAW,SAAS,EAAE,QAAQ,IAAI,uBAAuB,CAAC;AAAA,IAC1D,UAAU,SAAS,EAAE,QAAQ,IAAI,sBAAsB,CAAC;AAAA,IACxD,QAAQ,EAAE,QAAQ,IAAI,4BAA4B,KAAK;AAAA,IACvD,aAAa,EAAE,QAAQ,IAAI,yBAAyB,KAAK;AAAA,EAC3D;AACF;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,gBAAY,4BAAiB,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK;AAAA,IAC5E,MAAM,EAAE,QAAQ,IAAI,wBAAwB,KAAK;AAAA,IACjD,SAAS,EAAE,QAAQ,IAAI,2BAA2B,KAAK;AAAA,IACvD,WAAW,SAAS,EAAE,QAAQ,IAAI,6BAA6B,CAAC;AAAA,IAChE,UAAU,SAAS,EAAE,QAAQ,IAAI,4BAA4B,CAAC;AAAA,IAC9D,QAAQ,EAAE,QAAQ,IAAI,kCAAkC,KAAK;AAAA,IAC7D,YAAY,EAAE,QAAQ,IAAI,8BAA8B,KAAK;AAAA,IAC7D,aAAa,EAAE,QAAQ,IAAI,+BAA+B,KAAK;AAAA,IAC/D,WAAW,EAAE,QAAQ,IAAI,6BAA6B,KAAK;AAAA,EAC7D;AACF;AAEO,SAAS,eAAe,GAAyB;AACtD,MAAI,EAAE,QAAQ,IAAI,aAAa,EAAG,QAAO,yBAAyB,CAAC;AACnE,MAAI,EAAE,QAAQ,IAAI,QAAQ,EAAG,QAAO,6BAA6B,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
@@ -0,0 +1,21 @@
1
+ type Geolocation = {
2
+ ip_address?: string;
3
+ city?: string;
4
+ country?: string;
5
+ continent?: string;
6
+ longitude?: number;
7
+ latitude?: number;
8
+ region?: string;
9
+ metro_code?: string;
10
+ postal_code?: string;
11
+ time_zone?: string;
12
+ };
13
+ /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
14
+ declare function getGeolocationFromCloudflare(r: Request): Geolocation;
15
+ /** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */
16
+ declare function getGeolocationFromVercel(r: Request): Geolocation;
17
+ /** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */
18
+ declare function getGeolocationFromCloudfront(r: Request): Geolocation;
19
+ declare function getGeolocation(r: Request): Geolocation;
20
+
21
+ export { type Geolocation, getGeolocation, getGeolocationFromCloudflare, getGeolocationFromCloudfront, getGeolocationFromVercel };
@@ -0,0 +1,21 @@
1
+ type Geolocation = {
2
+ ip_address?: string;
3
+ city?: string;
4
+ country?: string;
5
+ continent?: string;
6
+ longitude?: number;
7
+ latitude?: number;
8
+ region?: string;
9
+ metro_code?: string;
10
+ postal_code?: string;
11
+ time_zone?: string;
12
+ };
13
+ /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
14
+ declare function getGeolocationFromCloudflare(r: Request): Geolocation;
15
+ /** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */
16
+ declare function getGeolocationFromVercel(r: Request): Geolocation;
17
+ /** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */
18
+ declare function getGeolocationFromCloudfront(r: Request): Geolocation;
19
+ declare function getGeolocation(r: Request): Geolocation;
20
+
21
+ export { type Geolocation, getGeolocation, getGeolocationFromCloudflare, getGeolocationFromCloudfront, getGeolocationFromVercel };
@@ -0,0 +1,56 @@
1
+ // src/utils/geolocation.ts
2
+ import { extractIpAddress } from "./ip.mjs";
3
+ function toNumber(value) {
4
+ return value ? Number(value) : void 0;
5
+ }
6
+ function getGeolocationFromCloudflare(r) {
7
+ return {
8
+ ip_address: r.headers.get("true-client-ip") ?? r.headers.get("cf-connecting-ip") ?? void 0,
9
+ city: r.headers.get("cf-ipcity") ?? void 0,
10
+ country: r.headers.get("cf-ipcountry") ?? void 0,
11
+ continent: r.headers.get("cf-ipcontinent") ?? void 0,
12
+ longitude: toNumber(r.headers.get("cf-iplongitude")),
13
+ latitude: toNumber(r.headers.get("cf-iplatitude")),
14
+ region: r.headers.get("cf-region-code") ?? void 0,
15
+ metro_code: r.headers.get("cf-metro-code") ?? void 0,
16
+ postal_code: r.headers.get("cf-postal-code") ?? void 0,
17
+ time_zone: r.headers.get("cf-timezone") ?? void 0
18
+ };
19
+ }
20
+ function getGeolocationFromVercel(r) {
21
+ return {
22
+ ip_address: r.headers.get("x-real-ip") ?? void 0,
23
+ city: r.headers.get("x-vercel-ip-city") ?? void 0,
24
+ country: r.headers.get("x-vercel-ip-country") ?? void 0,
25
+ continent: r.headers.get("x-vercel-ip-continent") ?? void 0,
26
+ longitude: toNumber(r.headers.get("x-vercel-ip-longitude")),
27
+ latitude: toNumber(r.headers.get("x-vercel-ip-latitude")),
28
+ region: r.headers.get("x-vercel-ip-country-region") ?? void 0,
29
+ postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
30
+ };
31
+ }
32
+ function getGeolocationFromCloudfront(r) {
33
+ return {
34
+ ip_address: extractIpAddress(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
35
+ city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
36
+ country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
37
+ longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
38
+ latitude: toNumber(r.headers.get("CloudFront-Viewer-Latitude")),
39
+ region: r.headers.get("CloudFront-Viewer-Country-Region") ?? void 0,
40
+ metro_code: r.headers.get("CloudFront-Viewer-Metro-Code") ?? void 0,
41
+ postal_code: r.headers.get("CloudFront-Viewer-Postal-Code") ?? void 0,
42
+ time_zone: r.headers.get("CloudFront-Viewer-Time-Zone") ?? void 0
43
+ };
44
+ }
45
+ function getGeolocation(r) {
46
+ if (r.headers.get("x-vercel-id")) return getGeolocationFromVercel(r);
47
+ if (r.headers.get("cf-ray")) return getGeolocationFromCloudflare(r);
48
+ return getGeolocationFromCloudfront(r);
49
+ }
50
+ export {
51
+ getGeolocation,
52
+ getGeolocationFromCloudflare,
53
+ getGeolocationFromCloudfront,
54
+ getGeolocationFromVercel
55
+ };
56
+ //# sourceMappingURL=geolocation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["import { extractIpAddress } from './ip';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\nfunction toNumber(value: string | null): number | undefined {\n return value ? Number(value) : undefined;\n}\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function getGeolocationFromCloudflare(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('true-client-ip') ?? r.headers.get('cf-connecting-ip') ?? undefined,\n city: r.headers.get('cf-ipcity') ?? undefined,\n country: r.headers.get('cf-ipcountry') ?? undefined,\n continent: r.headers.get('cf-ipcontinent') ?? undefined,\n longitude: toNumber(r.headers.get('cf-iplongitude')),\n latitude: toNumber(r.headers.get('cf-iplatitude')),\n region: r.headers.get('cf-region-code') ?? undefined,\n metro_code: r.headers.get('cf-metro-code') ?? undefined,\n postal_code: r.headers.get('cf-postal-code') ?? undefined,\n time_zone: r.headers.get('cf-timezone') ?? undefined,\n };\n}\n\n/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function getGeolocationFromVercel(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('x-real-ip') ?? undefined,\n city: r.headers.get('x-vercel-ip-city') ?? undefined,\n country: r.headers.get('x-vercel-ip-country') ?? undefined,\n continent: r.headers.get('x-vercel-ip-continent') ?? undefined,\n longitude: toNumber(r.headers.get('x-vercel-ip-longitude')),\n latitude: toNumber(r.headers.get('x-vercel-ip-latitude')),\n region: r.headers.get('x-vercel-ip-country-region') ?? undefined,\n postal_code: r.headers.get('x-vercel-ip-postal-code') ?? undefined,\n };\n}\n\n/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nexport function getGeolocationFromCloudfront(r: Request): Geolocation {\n return {\n ip_address: extractIpAddress(r.headers.get('CloudFront-Viewer-Address')) ?? undefined,\n city: r.headers.get('CloudFront-Viewer-City') ?? undefined,\n country: r.headers.get('CloudFront-Viewer-Country') ?? undefined,\n longitude: toNumber(r.headers.get('CloudFront-Viewer-Longitude')),\n latitude: toNumber(r.headers.get('CloudFront-Viewer-Latitude')),\n region: r.headers.get('CloudFront-Viewer-Country-Region') ?? undefined,\n metro_code: r.headers.get('CloudFront-Viewer-Metro-Code') ?? undefined,\n postal_code: r.headers.get('CloudFront-Viewer-Postal-Code') ?? undefined,\n time_zone: r.headers.get('CloudFront-Viewer-Time-Zone') ?? undefined,\n };\n}\n\nexport function getGeolocation(r: Request): Geolocation {\n if (r.headers.get('x-vercel-id')) return getGeolocationFromVercel(r);\n if (r.headers.get('cf-ray')) return getGeolocationFromCloudflare(r);\n return getGeolocationFromCloudfront(r);\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AAejC,SAAS,SAAS,OAA0C;AAC1D,SAAO,QAAQ,OAAO,KAAK,IAAI;AACjC;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IACpF,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IACpC,SAAS,EAAE,QAAQ,IAAI,cAAc,KAAK;AAAA,IAC1C,WAAW,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC9C,WAAW,SAAS,EAAE,QAAQ,IAAI,gBAAgB,CAAC;AAAA,IACnD,UAAU,SAAS,EAAE,QAAQ,IAAI,eAAe,CAAC;AAAA,IACjD,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC3C,YAAY,EAAE,QAAQ,IAAI,eAAe,KAAK;AAAA,IAC9C,aAAa,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAChD,WAAW,EAAE,QAAQ,IAAI,aAAa,KAAK;AAAA,EAC7C;AACF;AAGO,SAAS,yBAAyB,GAAyB;AAChE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IAC1C,MAAM,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IAC3C,SAAS,EAAE,QAAQ,IAAI,qBAAqB,KAAK;AAAA,IACjD,WAAW,EAAE,QAAQ,IAAI,uBAAuB,KAAK;AAAA,IACrD,WAAW,SAAS,EAAE,QAAQ,IAAI,uBAAuB,CAAC;AAAA,IAC1D,UAAU,SAAS,EAAE,QAAQ,IAAI,sBAAsB,CAAC;AAAA,IACxD,QAAQ,EAAE,QAAQ,IAAI,4BAA4B,KAAK;AAAA,IACvD,aAAa,EAAE,QAAQ,IAAI,yBAAyB,KAAK;AAAA,EAC3D;AACF;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,iBAAiB,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK;AAAA,IAC5E,MAAM,EAAE,QAAQ,IAAI,wBAAwB,KAAK;AAAA,IACjD,SAAS,EAAE,QAAQ,IAAI,2BAA2B,KAAK;AAAA,IACvD,WAAW,SAAS,EAAE,QAAQ,IAAI,6BAA6B,CAAC;AAAA,IAChE,UAAU,SAAS,EAAE,QAAQ,IAAI,4BAA4B,CAAC;AAAA,IAC9D,QAAQ,EAAE,QAAQ,IAAI,kCAAkC,KAAK;AAAA,IAC7D,YAAY,EAAE,QAAQ,IAAI,8BAA8B,KAAK;AAAA,IAC7D,aAAa,EAAE,QAAQ,IAAI,+BAA+B,KAAK;AAAA,IAC/D,WAAW,EAAE,QAAQ,IAAI,6BAA6B,KAAK;AAAA,EAC7D;AACF;AAEO,SAAS,eAAe,GAAyB;AACtD,MAAI,EAAE,QAAQ,IAAI,aAAa,EAAG,QAAO,yBAAyB,CAAC;AACnE,MAAI,EAAE,QAAQ,IAAI,QAAQ,EAAG,QAAO,6BAA6B,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
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/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");
27
+ async function forwardToGoogleTagGateway(request, gaId) {
28
+ const GATEWAY_HOST = `${gaId}.fps.goog`;
29
+ const { pathname, search } = new URL(request.url);
30
+ const target = `https://${GATEWAY_HOST}${pathname}${search}`;
31
+ const headers = new Headers();
32
+ headers.set("host", GATEWAY_HOST);
33
+ const cookie = request.headers.get("cookie");
34
+ if (cookie) headers.set("cookie", cookie);
35
+ const { country, region } = (0, import_geolocation.getGeolocation)(request);
36
+ if (country && region) {
37
+ headers.set("x-forwarded-countryregion", `${country}-${region}`);
38
+ } else if (country) {
39
+ headers.set("x-forwarded-country", country);
40
+ } else if (region) {
41
+ headers.set("x-forwarded-region", region);
42
+ }
43
+ const hasBody = request.method !== "GET" && request.method !== "HEAD";
44
+ const response = await fetch(target, {
45
+ method: request.method,
46
+ headers,
47
+ body: hasBody ? request.body : void 0,
48
+ ...hasBody && { duplex: "half" }
49
+ });
50
+ const responseHeaders = new Headers(response.headers);
51
+ responseHeaders.delete("content-encoding");
52
+ responseHeaders.delete("content-length");
53
+ return new Response(response.body, { status: response.status, headers: responseHeaders });
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ forwardToGoogleTagGateway
58
+ });
59
+ //# sourceMappingURL=google-tag-gateway.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\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 const response = await fetch(target, {\n method: request.method,\n headers,\n body: hasBody ? request.body : undefined,\n ...(hasBody && { duplex: 'half' as const }),\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA+B;AAE/B,eAAsB,0BAA0B,SAAkB,MAAc;AAC9E,QAAM,eAAe,GAAG,IAAI;AAC5B,QAAM,EAAE,UAAU,OAAO,IAAI,IAAI,IAAI,QAAQ,GAAG;AAEhD,QAAM,SAAS,WAAW,YAAY,GAAG,QAAQ,GAAG,MAAM;AAE1D,QAAM,UAAU,IAAI,QAAQ;AAC5B,UAAQ,IAAI,QAAQ,YAAY;AAGhC,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,OAAQ,SAAQ,IAAI,UAAU,MAAM;AAIxC,QAAM,EAAE,SAAS,OAAO,QAAI,mCAAe,OAAO;AAElD,MAAI,WAAW,QAAQ;AACrB,YAAQ,IAAI,6BAA6B,GAAG,OAAO,IAAI,MAAM,EAAE;AAAA,EACjE,WAAW,SAAS;AAClB,YAAQ,IAAI,uBAAuB,OAAO;AAAA,EAC5C,WAAW,QAAQ;AACjB,YAAQ,IAAI,sBAAsB,MAAM;AAAA,EAC1C;AAEA,QAAM,UAAU,QAAQ,WAAW,SAAS,QAAQ,WAAW;AAC/D,QAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,IACnC,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,MAAM,UAAU,QAAQ,OAAO;AAAA,IAC/B,GAAI,WAAW,EAAE,QAAQ,OAAgB;AAAA,EAC3C,CAAC;AAID,QAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;AACpD,kBAAgB,OAAO,kBAAkB;AACzC,kBAAgB,OAAO,gBAAgB;AAEvC,SAAO,IAAI,SAAS,SAAS,MAAM,EAAE,QAAQ,SAAS,QAAQ,SAAS,gBAAgB,CAAC;AAC1F;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare function forwardToGoogleTagGateway(request: Request, gaId: string): Promise<Response>;
2
+
3
+ export { forwardToGoogleTagGateway };
@@ -0,0 +1,3 @@
1
+ declare function forwardToGoogleTagGateway(request: Request, gaId: string): Promise<Response>;
2
+
3
+ export { forwardToGoogleTagGateway };
@@ -0,0 +1,34 @@
1
+ // src/utils/google-tag-gateway.ts
2
+ import { getGeolocation } from "./geolocation.mjs";
3
+ async function forwardToGoogleTagGateway(request, gaId) {
4
+ const GATEWAY_HOST = `${gaId}.fps.goog`;
5
+ const { pathname, search } = new URL(request.url);
6
+ const target = `https://${GATEWAY_HOST}${pathname}${search}`;
7
+ const headers = new Headers();
8
+ headers.set("host", GATEWAY_HOST);
9
+ const cookie = request.headers.get("cookie");
10
+ if (cookie) headers.set("cookie", cookie);
11
+ const { country, region } = getGeolocation(request);
12
+ if (country && region) {
13
+ headers.set("x-forwarded-countryregion", `${country}-${region}`);
14
+ } else if (country) {
15
+ headers.set("x-forwarded-country", country);
16
+ } else if (region) {
17
+ headers.set("x-forwarded-region", region);
18
+ }
19
+ const hasBody = request.method !== "GET" && request.method !== "HEAD";
20
+ const response = await fetch(target, {
21
+ method: request.method,
22
+ headers,
23
+ body: hasBody ? request.body : void 0,
24
+ ...hasBody && { duplex: "half" }
25
+ });
26
+ const responseHeaders = new Headers(response.headers);
27
+ responseHeaders.delete("content-encoding");
28
+ responseHeaders.delete("content-length");
29
+ return new Response(response.body, { status: response.status, headers: responseHeaders });
30
+ }
31
+ export {
32
+ forwardToGoogleTagGateway
33
+ };
34
+ //# sourceMappingURL=google-tag-gateway.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\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 const response = await fetch(target, {\n method: request.method,\n headers,\n body: hasBody ? request.body : undefined,\n ...(hasBody && { duplex: 'half' as const }),\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":";AAAA,SAAS,sBAAsB;AAE/B,eAAsB,0BAA0B,SAAkB,MAAc;AAC9E,QAAM,eAAe,GAAG,IAAI;AAC5B,QAAM,EAAE,UAAU,OAAO,IAAI,IAAI,IAAI,QAAQ,GAAG;AAEhD,QAAM,SAAS,WAAW,YAAY,GAAG,QAAQ,GAAG,MAAM;AAE1D,QAAM,UAAU,IAAI,QAAQ;AAC5B,UAAQ,IAAI,QAAQ,YAAY;AAGhC,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,OAAQ,SAAQ,IAAI,UAAU,MAAM;AAIxC,QAAM,EAAE,SAAS,OAAO,IAAI,eAAe,OAAO;AAElD,MAAI,WAAW,QAAQ;AACrB,YAAQ,IAAI,6BAA6B,GAAG,OAAO,IAAI,MAAM,EAAE;AAAA,EACjE,WAAW,SAAS;AAClB,YAAQ,IAAI,uBAAuB,OAAO;AAAA,EAC5C,WAAW,QAAQ;AACjB,YAAQ,IAAI,sBAAsB,MAAM;AAAA,EAC1C;AAEA,QAAM,UAAU,QAAQ,WAAW,SAAS,QAAQ,WAAW;AAC/D,QAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,IACnC,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,MAAM,UAAU,QAAQ,OAAO;AAAA,IAC/B,GAAI,WAAW,EAAE,QAAQ,OAAgB;AAAA,EAC3C,CAAC;AAID,QAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;AACpD,kBAAgB,OAAO,kBAAkB;AACzC,kBAAgB,OAAO,gBAAgB;AAEvC,SAAO,IAAI,SAAS,SAAS,MAAM,EAAE,QAAQ,SAAS,QAAQ,SAAS,gBAAgB,CAAC;AAC1F;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",