@shware/http 2.10.0 → 2.10.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.
- package/dist/index.cjs +0 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +1 -1
- package/dist/utils/geolocation.cjs +6 -2
- package/dist/utils/geolocation.cjs.map +1 -1
- package/dist/utils/geolocation.mjs +6 -2
- package/dist/utils/geolocation.mjs.map +1 -1
- package/dist/utils/google-tag-gateway.cjs.map +1 -1
- package/dist/utils/google-tag-gateway.d.cts +1 -1
- package/dist/utils/google-tag-gateway.d.ts +1 -1
- package/dist/utils/google-tag-gateway.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/utils/ip.cjs +0 -53
- package/dist/utils/ip.cjs.map +0 -1
- package/dist/utils/ip.d.cts +0 -3
- package/dist/utils/ip.d.ts +0 -3
- package/dist/utils/ip.mjs +0 -28
- package/dist/utils/ip.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -48,7 +48,6 @@ __export(index_exports, {
|
|
|
48
48
|
getErrorInfo: () => import_parse.getErrorInfo,
|
|
49
49
|
getErrorMessage: () => import_parse.getErrorMessage,
|
|
50
50
|
getFieldViolations: () => import_parse.getFieldViolations,
|
|
51
|
-
getGeolocation: () => import_geolocation.getGeolocation,
|
|
52
51
|
getNextPageParam: () => import_response.getNextPageParam,
|
|
53
52
|
getPreviousPageParam: () => import_response.getPreviousPageParam,
|
|
54
53
|
initialPageParam: () => import_response.initialPageParam,
|
|
@@ -65,7 +64,6 @@ var import_response = require("./response.cjs");
|
|
|
65
64
|
var import_snowflake = require("./snowflake.cjs");
|
|
66
65
|
var MAX_LENGTH = __toESM(require("./max-length/index.cjs"), 1);
|
|
67
66
|
var import_timing = require("./utils/timing.cjs");
|
|
68
|
-
var import_geolocation = require("./utils/geolocation.cjs");
|
|
69
67
|
var import_google_tag_gateway = require("./utils/google-tag-gateway.cjs");
|
|
70
68
|
var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
|
|
71
69
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -88,7 +86,6 @@ var import_iso_3601_1 = require("./iso/iso_3601_1.cjs");
|
|
|
88
86
|
getErrorInfo,
|
|
89
87
|
getErrorMessage,
|
|
90
88
|
getFieldViolations,
|
|
91
|
-
getGeolocation,
|
|
92
89
|
getNextPageParam,
|
|
93
90
|
getPreviousPageParam,
|
|
94
91
|
initialPageParam,
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 {
|
|
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 { 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,mBAKO;AAEP,oBAcO;AACP,oBAAoD;AACpD,mBAAkE;AAClE,sBAQO;AAeP,uBAAkC;AAElC,iBAA4B;AAC5B,oBAAuB;AACvB,gCAA0C;AAC1C,wBAAoD;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -7,7 +7,6 @@ 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
10
|
export { forwardToGoogleTagGateway } from './utils/google-tag-gateway.cjs';
|
|
12
11
|
export { ISO3166CountryCode, ISO_3601_1 } from './iso/iso_3601_1.cjs';
|
|
13
12
|
import 'i18next';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ 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
10
|
export { forwardToGoogleTagGateway } from './utils/google-tag-gateway.js';
|
|
12
11
|
export { ISO3166CountryCode, ISO_3601_1 } from './iso/iso_3601_1.js';
|
|
13
12
|
import 'i18next';
|
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,6 @@ 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
26
|
import { forwardToGoogleTagGateway } from "./utils/google-tag-gateway.mjs";
|
|
28
27
|
import { ISO_3601_1 } from "./iso/iso_3601_1.mjs";
|
|
29
28
|
export {
|
|
@@ -45,7 +44,6 @@ export {
|
|
|
45
44
|
getErrorInfo,
|
|
46
45
|
getErrorMessage,
|
|
47
46
|
getFieldViolations,
|
|
48
|
-
getGeolocation,
|
|
49
47
|
getNextPageParam,
|
|
50
48
|
getPreviousPageParam,
|
|
51
49
|
initialPageParam,
|
package/dist/index.mjs.map
CHANGED
|
@@ -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 {
|
|
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 { 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,iCAAiC;AAC1C,SAAS,kBAA2C;","names":[]}
|
|
@@ -26,7 +26,6 @@ __export(geolocation_exports, {
|
|
|
26
26
|
getGeolocationFromVercel: () => getGeolocationFromVercel
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(geolocation_exports);
|
|
29
|
-
var import_ip = require("./ip.cjs");
|
|
30
29
|
function toNumber(value) {
|
|
31
30
|
return value ? Number(value) : void 0;
|
|
32
31
|
}
|
|
@@ -56,9 +55,14 @@ function getGeolocationFromVercel(r) {
|
|
|
56
55
|
postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
|
|
57
56
|
};
|
|
58
57
|
}
|
|
58
|
+
function stripPort(value) {
|
|
59
|
+
if (!value) return null;
|
|
60
|
+
const i = value.lastIndexOf(":");
|
|
61
|
+
return i !== -1 && /^\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;
|
|
62
|
+
}
|
|
59
63
|
function getGeolocationFromCloudfront(r) {
|
|
60
64
|
return {
|
|
61
|
-
ip_address: (
|
|
65
|
+
ip_address: stripPort(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
|
|
62
66
|
city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
|
|
63
67
|
country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
|
|
64
68
|
longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["export 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\nfunction stripPort(value: string | null): string | null {\n if (!value) return null;\n const i = value.lastIndexOf(':');\n return i !== -1 && /^\\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;\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: stripPort(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,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;AAEA,SAAS,UAAU,OAAqC;AACtD,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,IAAI,MAAM,YAAY,GAAG;AAC/B,SAAO,MAAM,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,GAAG,CAAC,IAAI;AAC5E;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,UAAU,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK;AAAA,IACrE,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":[]}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/utils/geolocation.ts
|
|
2
|
-
import { extractIpAddress } from "./ip.mjs";
|
|
3
2
|
function toNumber(value) {
|
|
4
3
|
return value ? Number(value) : void 0;
|
|
5
4
|
}
|
|
@@ -29,9 +28,14 @@ function getGeolocationFromVercel(r) {
|
|
|
29
28
|
postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
|
|
30
29
|
};
|
|
31
30
|
}
|
|
31
|
+
function stripPort(value) {
|
|
32
|
+
if (!value) return null;
|
|
33
|
+
const i = value.lastIndexOf(":");
|
|
34
|
+
return i !== -1 && /^\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;
|
|
35
|
+
}
|
|
32
36
|
function getGeolocationFromCloudfront(r) {
|
|
33
37
|
return {
|
|
34
|
-
ip_address:
|
|
38
|
+
ip_address: stripPort(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
|
|
35
39
|
city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
|
|
36
40
|
country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
|
|
37
41
|
longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["export 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\nfunction stripPort(value: string | null): string | null {\n if (!value) return null;\n const i = value.lastIndexOf(':');\n return i !== -1 && /^\\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;\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: stripPort(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,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;AAEA,SAAS,UAAU,OAAqC;AACtD,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,IAAI,MAAM,YAAY,GAAG;AAC/B,SAAO,MAAM,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,GAAG,CAAC,IAAI;AAC5E;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,UAAU,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK;AAAA,IACrE,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":[]}
|
|
@@ -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
|
|
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 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;AAO/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":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* In a browser, verify the
|
|
2
|
+
* In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
|
|
3
3
|
* should read ok. Verify that geographical information is being included by navigating to:
|
|
4
4
|
* https://example.com/metrics/?validate_geo=healthy. The page should read ok.
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* In a browser, verify the
|
|
2
|
+
* In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
|
|
3
3
|
* should read ok. Verify that geographical information is being included by navigating to:
|
|
4
4
|
* https://example.com/metrics/?validate_geo=healthy. The page should read ok.
|
|
5
5
|
*/
|
|
@@ -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
|
|
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 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;AAO/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
package/dist/utils/ip.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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/ip.ts
|
|
21
|
-
var ip_exports = {};
|
|
22
|
-
__export(ip_exports, {
|
|
23
|
-
extractIpAddress: () => extractIpAddress
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(ip_exports);
|
|
26
|
-
var import_net = require("net");
|
|
27
|
-
function extractIpAddress(ip) {
|
|
28
|
-
if (!ip) return null;
|
|
29
|
-
if ((0, import_net.isIPv4)(ip) || (0, import_net.isIPv6)(ip)) return ip;
|
|
30
|
-
if (ip.includes(".") && ip.includes(":")) {
|
|
31
|
-
const [address] = ip.split(":");
|
|
32
|
-
if ((0, import_net.isIPv4)(address)) return address;
|
|
33
|
-
}
|
|
34
|
-
if (!ip.includes("[") && !ip.includes("]") && !ip.includes(".") && ip.includes(":")) {
|
|
35
|
-
const parts = ip.split(":");
|
|
36
|
-
parts.pop();
|
|
37
|
-
const address = parts.join(":");
|
|
38
|
-
if ((0, import_net.isIPv6)(address)) return address;
|
|
39
|
-
}
|
|
40
|
-
try {
|
|
41
|
-
const url = new URL(`https://${ip}`);
|
|
42
|
-
const hostname = url.hostname.replace("[", "").replace("]", "");
|
|
43
|
-
if ((0, import_net.isIPv4)(hostname) || (0, import_net.isIPv6)(hostname)) return hostname;
|
|
44
|
-
return null;
|
|
45
|
-
} catch (_) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
-
0 && (module.exports = {
|
|
51
|
-
extractIpAddress
|
|
52
|
-
});
|
|
53
|
-
//# sourceMappingURL=ip.cjs.map
|
package/dist/utils/ip.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/ip.ts"],"sourcesContent":["import { isIPv4, isIPv6 } from 'net';\n\nexport function extractIpAddress(ip: string | undefined | null): string | null {\n if (!ip) return null;\n if (isIPv4(ip) || isIPv6(ip)) return ip;\n if (ip.includes('.') && ip.includes(':')) {\n const [address] = ip.split(':');\n if (isIPv4(address)) return address;\n }\n if (!ip.includes('[') && !ip.includes(']') && !ip.includes('.') && ip.includes(':')) {\n const parts = ip.split(':');\n parts.pop();\n const address = parts.join(':');\n if (isIPv6(address)) return address;\n }\n\n try {\n const url = new URL(`https://${ip}`);\n const hostname = url.hostname.replace('[', '').replace(']', '');\n if (isIPv4(hostname) || isIPv6(hostname)) return hostname;\n return null;\n } catch (_) {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAExB,SAAS,iBAAiB,IAA8C;AAC7E,MAAI,CAAC,GAAI,QAAO;AAChB,UAAI,mBAAO,EAAE,SAAK,mBAAO,EAAE,EAAG,QAAO;AACrC,MAAI,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACxC,UAAM,CAAC,OAAO,IAAI,GAAG,MAAM,GAAG;AAC9B,YAAI,mBAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AACA,MAAI,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACnF,UAAM,QAAQ,GAAG,MAAM,GAAG;AAC1B,UAAM,IAAI;AACV,UAAM,UAAU,MAAM,KAAK,GAAG;AAC9B,YAAI,mBAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AAEA,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,WAAW,EAAE,EAAE;AACnC,UAAM,WAAW,IAAI,SAAS,QAAQ,KAAK,EAAE,EAAE,QAAQ,KAAK,EAAE;AAC9D,YAAI,mBAAO,QAAQ,SAAK,mBAAO,QAAQ,EAAG,QAAO;AACjD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/utils/ip.d.cts
DELETED
package/dist/utils/ip.d.ts
DELETED
package/dist/utils/ip.mjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// src/utils/ip.ts
|
|
2
|
-
import { isIPv4, isIPv6 } from "net";
|
|
3
|
-
function extractIpAddress(ip) {
|
|
4
|
-
if (!ip) return null;
|
|
5
|
-
if (isIPv4(ip) || isIPv6(ip)) return ip;
|
|
6
|
-
if (ip.includes(".") && ip.includes(":")) {
|
|
7
|
-
const [address] = ip.split(":");
|
|
8
|
-
if (isIPv4(address)) return address;
|
|
9
|
-
}
|
|
10
|
-
if (!ip.includes("[") && !ip.includes("]") && !ip.includes(".") && ip.includes(":")) {
|
|
11
|
-
const parts = ip.split(":");
|
|
12
|
-
parts.pop();
|
|
13
|
-
const address = parts.join(":");
|
|
14
|
-
if (isIPv6(address)) return address;
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const url = new URL(`https://${ip}`);
|
|
18
|
-
const hostname = url.hostname.replace("[", "").replace("]", "");
|
|
19
|
-
if (isIPv4(hostname) || isIPv6(hostname)) return hostname;
|
|
20
|
-
return null;
|
|
21
|
-
} catch (_) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export {
|
|
26
|
-
extractIpAddress
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=ip.mjs.map
|
package/dist/utils/ip.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/ip.ts"],"sourcesContent":["import { isIPv4, isIPv6 } from 'net';\n\nexport function extractIpAddress(ip: string | undefined | null): string | null {\n if (!ip) return null;\n if (isIPv4(ip) || isIPv6(ip)) return ip;\n if (ip.includes('.') && ip.includes(':')) {\n const [address] = ip.split(':');\n if (isIPv4(address)) return address;\n }\n if (!ip.includes('[') && !ip.includes(']') && !ip.includes('.') && ip.includes(':')) {\n const parts = ip.split(':');\n parts.pop();\n const address = parts.join(':');\n if (isIPv6(address)) return address;\n }\n\n try {\n const url = new URL(`https://${ip}`);\n const hostname = url.hostname.replace('[', '').replace(']', '');\n if (isIPv4(hostname) || isIPv6(hostname)) return hostname;\n return null;\n } catch (_) {\n return null;\n }\n}\n"],"mappings":";AAAA,SAAS,QAAQ,cAAc;AAExB,SAAS,iBAAiB,IAA8C;AAC7E,MAAI,CAAC,GAAI,QAAO;AAChB,MAAI,OAAO,EAAE,KAAK,OAAO,EAAE,EAAG,QAAO;AACrC,MAAI,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACxC,UAAM,CAAC,OAAO,IAAI,GAAG,MAAM,GAAG;AAC9B,QAAI,OAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AACA,MAAI,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACnF,UAAM,QAAQ,GAAG,MAAM,GAAG;AAC1B,UAAM,IAAI;AACV,UAAM,UAAU,MAAM,KAAK,GAAG;AAC9B,QAAI,OAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AAEA,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,WAAW,EAAE,EAAE;AACnC,UAAM,WAAW,IAAI,SAAS,QAAQ,KAAK,EAAE,EAAE,QAAQ,KAAK,EAAE;AAC9D,QAAI,OAAO,QAAQ,KAAK,OAAO,QAAQ,EAAG,QAAO;AACjD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;","names":[]}
|