@shware/http 2.11.3 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.cjs +13 -0
- package/dist/_virtual/_rolldown/runtime.mjs +13 -0
- package/dist/cache/index.cjs +5 -30
- package/dist/cache/index.cjs.map +1 -1
- package/dist/cache/index.d.cts +7 -5
- package/dist/cache/index.d.cts.map +1 -0
- package/dist/cache/index.d.mts +11 -0
- package/dist/cache/index.d.mts.map +1 -0
- package/dist/cache/index.mjs +5 -6
- package/dist/cache/index.mjs.map +1 -1
- package/dist/error/detail.cjs +100 -90
- package/dist/error/detail.cjs.map +1 -1
- package/dist/error/detail.d.cts +77 -78
- package/dist/error/detail.d.cts.map +1 -0
- package/dist/error/detail.d.mts +108 -0
- package/dist/error/detail.d.mts.map +1 -0
- package/dist/error/detail.mjs +99 -65
- package/dist/error/detail.mjs.map +1 -1
- package/dist/error/i18n/en-us.cjs +5 -29
- package/dist/error/i18n/en-us.cjs.map +1 -1
- package/dist/error/i18n/en-us.d.cts +3 -1
- package/dist/error/i18n/en-us.d.cts.map +1 -0
- package/dist/error/i18n/en-us.d.mts +5 -0
- package/dist/error/i18n/en-us.d.mts.map +1 -0
- package/dist/error/i18n/en-us.mjs +5 -5
- package/dist/error/i18n/en-us.mjs.map +1 -1
- package/dist/error/index.cjs +29 -56
- package/dist/error/index.cjs.map +1 -1
- package/dist/error/index.d.cts +12 -10
- package/dist/error/index.d.cts.map +1 -0
- package/dist/error/index.d.mts +21 -0
- package/dist/error/index.d.mts.map +1 -0
- package/dist/error/index.mjs +25 -28
- package/dist/error/index.mjs.map +1 -1
- package/dist/error/parse.cjs +63 -61
- package/dist/error/parse.cjs.map +1 -1
- package/dist/error/parse.d.cts +8 -7
- package/dist/error/parse.d.cts.map +1 -0
- package/dist/error/{parse.d.ts → parse.d.mts} +8 -7
- package/dist/error/parse.d.mts.map +1 -0
- package/dist/error/parse.mjs +59 -33
- package/dist/error/parse.mjs.map +1 -1
- package/dist/error/reason.cjs +0 -19
- package/dist/error/reason.d.cts +5 -4
- package/dist/error/reason.d.cts.map +1 -0
- package/dist/error/reason.d.mts +6 -0
- package/dist/error/reason.d.mts.map +1 -0
- package/dist/error/reason.mjs +1 -1
- package/dist/error/status.cjs +103 -256
- package/dist/error/status.cjs.map +1 -1
- package/dist/error/status.d.cts +58 -58
- package/dist/error/status.d.cts.map +1 -0
- package/dist/error/status.d.mts +69 -0
- package/dist/error/status.d.mts.map +1 -0
- package/dist/error/status.mjs +98 -227
- package/dist/error/status.mjs.map +1 -1
- package/dist/google-one-tap/index.cjs +135 -138
- package/dist/google-one-tap/index.cjs.map +1 -1
- package/dist/google-one-tap/index.d.cts +49 -48
- package/dist/google-one-tap/index.d.cts.map +1 -0
- package/dist/google-one-tap/index.d.mts +82 -0
- package/dist/google-one-tap/index.d.mts.map +1 -0
- package/dist/google-one-tap/index.mjs +133 -112
- package/dist/google-one-tap/index.mjs.map +1 -1
- package/dist/google-one-tap/types.cjs +0 -19
- package/dist/google-one-tap/types.d.cts +124 -122
- package/dist/google-one-tap/types.d.cts.map +1 -0
- package/dist/google-one-tap/types.d.mts +157 -0
- package/dist/google-one-tap/types.d.mts.map +1 -0
- package/dist/google-one-tap/types.mjs +1 -1
- package/dist/hono/authorizer.cjs +28 -65
- package/dist/hono/authorizer.cjs.map +1 -1
- package/dist/hono/authorizer.d.cts +12 -11
- package/dist/hono/authorizer.d.cts.map +1 -0
- package/dist/hono/authorizer.d.mts +19 -0
- package/dist/hono/authorizer.d.mts.map +1 -0
- package/dist/hono/authorizer.mjs +23 -36
- package/dist/hono/authorizer.mjs.map +1 -1
- package/dist/hono/csrf.cjs +81 -92
- package/dist/hono/csrf.cjs.map +1 -1
- package/dist/hono/csrf.d.cts +46 -45
- package/dist/hono/csrf.d.cts.map +1 -0
- package/dist/hono/csrf.d.mts +76 -0
- package/dist/hono/csrf.d.mts.map +1 -0
- package/dist/hono/csrf.mjs +76 -63
- package/dist/hono/csrf.mjs.map +1 -1
- package/dist/hono/geolocation.cjs +10 -34
- package/dist/hono/geolocation.cjs.map +1 -1
- package/dist/hono/geolocation.d.cts +5 -4
- package/dist/hono/geolocation.d.cts.map +1 -0
- package/dist/hono/geolocation.d.mts +7 -0
- package/dist/hono/geolocation.d.mts.map +1 -0
- package/dist/hono/geolocation.mjs +8 -12
- package/dist/hono/geolocation.mjs.map +1 -1
- package/dist/hono/handler.cjs +37 -61
- package/dist/hono/handler.cjs.map +1 -1
- package/dist/hono/handler.d.cts +26 -25
- package/dist/hono/handler.d.cts.map +1 -0
- package/dist/hono/handler.d.mts +32 -0
- package/dist/hono/handler.d.mts.map +1 -0
- package/dist/hono/handler.mjs +34 -34
- package/dist/hono/handler.mjs.map +1 -1
- package/dist/hono/index.cjs +14 -48
- package/dist/hono/index.d.cts +7 -15
- package/dist/hono/index.d.mts +7 -0
- package/dist/hono/index.mjs +4 -14
- package/dist/hono/rate-limit.cjs +65 -110
- package/dist/hono/rate-limit.cjs.map +1 -1
- package/dist/hono/rate-limit.d.cts +27 -26
- package/dist/hono/rate-limit.d.cts.map +1 -0
- package/dist/hono/rate-limit.d.mts +36 -0
- package/dist/hono/rate-limit.d.mts.map +1 -0
- package/dist/hono/rate-limit.mjs +60 -81
- package/dist/hono/rate-limit.mjs.map +1 -1
- package/dist/hono/validator.cjs +47 -66
- package/dist/hono/validator.cjs.map +1 -1
- package/dist/hono/validator.d.cts +25 -30
- package/dist/hono/validator.d.cts.map +1 -0
- package/dist/hono/validator.d.mts +26 -0
- package/dist/hono/validator.d.mts.map +1 -0
- package/dist/hono/validator.mjs +43 -43
- package/dist/hono/validator.mjs.map +1 -1
- package/dist/index.cjs +39 -95
- package/dist/index.d.cts +12 -14
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +5 -48
- package/dist/iso/iso_3601_1.cjs +1512 -290
- package/dist/iso/iso_3601_1.cjs.map +1 -1
- package/dist/iso/iso_3601_1.d.cts +8 -6
- package/dist/iso/iso_3601_1.d.cts.map +1 -0
- package/dist/iso/iso_3601_1.d.mts +11 -0
- package/dist/iso/iso_3601_1.d.mts.map +1 -0
- package/dist/iso/iso_3601_1.mjs +1511 -265
- package/dist/iso/iso_3601_1.mjs.map +1 -1
- package/dist/max-length/index.cjs +158 -91
- package/dist/max-length/index.cjs.map +1 -1
- package/dist/max-length/index.d.cts +110 -1
- package/dist/max-length/index.d.cts.map +1 -0
- package/dist/{index-BhgdyigB.d.ts → max-length/index.d.mts} +9 -28
- package/dist/max-length/index.d.mts.map +1 -0
- package/dist/max-length/index.mjs +133 -47
- package/dist/max-length/index.mjs.map +1 -1
- package/dist/message.cjs +5 -30
- package/dist/message.cjs.map +1 -1
- package/dist/message.d.cts +3 -1
- package/dist/message.d.cts.map +1 -0
- package/dist/{message.d.ts → message.d.mts} +3 -1
- package/dist/message.d.mts.map +1 -0
- package/dist/message.mjs +5 -6
- package/dist/message.mjs.map +1 -1
- package/dist/polyfills/index.cjs +4 -4
- package/dist/polyfills/index.cjs.map +1 -1
- package/dist/polyfills/index.d.cts +1 -2
- package/dist/polyfills/index.d.mts +1 -0
- package/dist/polyfills/index.mjs +5 -2
- package/dist/polyfills/index.mjs.map +1 -1
- package/dist/response.cjs +191 -208
- package/dist/response.cjs.map +1 -1
- package/dist/response.d.cts +53 -54
- package/dist/response.d.cts.map +1 -0
- package/dist/response.d.mts +82 -0
- package/dist/response.d.mts.map +1 -0
- package/dist/response.mjs +182 -175
- package/dist/response.mjs.map +1 -1
- package/dist/snowflake.cjs +48 -70
- package/dist/snowflake.cjs.map +1 -1
- package/dist/snowflake.d.cts +16 -14
- package/dist/snowflake.d.cts.map +1 -0
- package/dist/snowflake.d.mts +31 -0
- package/dist/snowflake.d.mts.map +1 -0
- package/dist/snowflake.mjs +46 -44
- package/dist/snowflake.mjs.map +1 -1
- package/dist/utils/geolocation.cjs +51 -75
- package/dist/utils/geolocation.cjs.map +1 -1
- package/dist/utils/geolocation.d.cts +14 -12
- package/dist/utils/geolocation.d.cts.map +1 -0
- package/dist/utils/{geolocation.d.ts → geolocation.d.mts} +14 -12
- package/dist/utils/geolocation.d.mts.map +1 -0
- package/dist/utils/geolocation.mjs +47 -47
- package/dist/utils/geolocation.mjs.map +1 -1
- package/dist/utils/google-tag-gateway.cjs +35 -56
- package/dist/utils/google-tag-gateway.cjs.map +1 -1
- package/dist/utils/google-tag-gateway.d.cts +3 -1
- package/dist/utils/google-tag-gateway.d.cts.map +1 -0
- package/dist/utils/{google-tag-gateway.d.ts → google-tag-gateway.d.mts} +3 -1
- package/dist/utils/google-tag-gateway.d.mts.map +1 -0
- package/dist/utils/google-tag-gateway.mjs +33 -30
- package/dist/utils/google-tag-gateway.mjs.map +1 -1
- package/dist/utils/timing.cjs +50 -71
- package/dist/utils/timing.cjs.map +1 -1
- package/dist/utils/timing.d.cts +11 -9
- package/dist/utils/timing.d.cts.map +1 -0
- package/dist/utils/timing.d.mts +15 -0
- package/dist/utils/timing.d.mts.map +1 -0
- package/dist/utils/timing.mjs +49 -46
- package/dist/utils/timing.mjs.map +1 -1
- package/dist/webhook/index.cjs +43 -72
- package/dist/webhook/index.cjs.map +1 -1
- package/dist/webhook/index.d.cts +3 -1
- package/dist/webhook/index.d.cts.map +1 -0
- package/dist/webhook/{index.d.ts → index.d.mts} +3 -1
- package/dist/webhook/index.d.mts.map +1 -0
- package/dist/webhook/index.mjs +41 -46
- package/dist/webhook/index.mjs.map +1 -1
- package/package.json +50 -25
- package/dist/cache/index.d.ts +0 -9
- package/dist/error/detail.d.ts +0 -109
- package/dist/error/i18n/en-us.d.ts +0 -3
- package/dist/error/index.d.ts +0 -19
- package/dist/error/reason.cjs.map +0 -1
- package/dist/error/reason.d.ts +0 -5
- package/dist/error/reason.mjs.map +0 -1
- package/dist/error/status.d.ts +0 -69
- package/dist/google-one-tap/index.d.ts +0 -81
- package/dist/google-one-tap/types.cjs.map +0 -1
- package/dist/google-one-tap/types.d.ts +0 -155
- package/dist/google-one-tap/types.mjs.map +0 -1
- package/dist/hono/authorizer.d.ts +0 -18
- package/dist/hono/csrf.d.ts +0 -75
- package/dist/hono/geolocation.d.ts +0 -6
- package/dist/hono/handler.d.ts +0 -31
- package/dist/hono/index.cjs.map +0 -1
- package/dist/hono/index.d.ts +0 -15
- package/dist/hono/index.mjs.map +0 -1
- package/dist/hono/rate-limit.d.ts +0 -35
- package/dist/hono/validator.d.ts +0 -31
- package/dist/index-BhgdyigB.d.cts +0 -129
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.mjs.map +0 -1
- package/dist/iso/iso_3601_1.d.ts +0 -9
- package/dist/max-length/index.d.ts +0 -1
- package/dist/polyfills/index.d.ts +0 -2
- package/dist/response.d.ts +0 -83
- package/dist/snowflake.d.ts +0 -29
- package/dist/utils/timing.d.ts +0 -13
package/dist/snowflake.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"snowflake.cjs","names":[],"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAS,mBAAmB,WAAmB;CAC7C,IAAI,MAAM,OAAO,KAAK,IAAI,CAAC;CAC3B,OAAO,MAAM,WACX,MAAM,OAAO,KAAK,IAAI,CAAC;CAEzB,OAAO;AACT;AAEA,IAAa,eAAb,MAA0B;CACxB,OAAuB,MAAM,OAAO;CACpC,cAA+B,OAAO,EAAE;CACxC,eAAgC,OAAO,EAAE;CACzC,mBAAoC,OAAO,SAAa;CACxD,eAAgC,EAAE,OAAO,EAAE,KAAK,KAAK;CACrD,eAAgC,EAAE,OAAO,EAAE,KAAK,KAAK;CACrD,iBAAkC,KAAK;CACvC,iBAAkC,KAAK,cAAc,KAAK;CAC1D;CACA,WAAmB,OAAO,CAAC;CAC3B,gBAAwB,OAAO,EAAE;CAEjC,YAAY,WAAmB;EAC7B,KAAK,YAAY,OAAO,SAAS,IAAI,KAAK;CAC5C;CAEA,aAAqC;EACnC,IAAI,YAAY,OAAO,KAAK,IAAI,CAAC;EACjC,IAAI,YAAY,KAAK,eAAe;GAClC,QAAQ,MAAM,qCAAqC,KAAK,gBAAgB,WAAW;GACnF,YAAY,mBAAmB,KAAK,aAAa;EACnD;EACA,IAAI,cAAc,KAAK,eAAe;GACpC,KAAK,WAAY,KAAK,WAAW,OAAO,CAAC,IAAK,KAAK;GACnD,IAAI,KAAK,aAAa,OAAO,CAAC,GAC5B,YAAY,mBAAmB,SAAS;EAE5C,OACE,KAAK,WAAW,OAAO,CAAC;EAE1B,KAAK,gBAAgB;EACrB,OACI,YAAY,KAAK,oBAAqB,KAAK,iBAC5C,KAAK,aAAa,KAAK,iBACxB,KAAK;CAET;AACF;AAGA,MAAa,MAAM,IAAI,aADL,KAAK,MAAM,KAAK,OAAO,IAAI,IACT,CAAS"}
|
package/dist/snowflake.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/snowflake.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* A distributed unique ID generator inspired by Twitter's Snowflake.
|
|
3
4
|
*
|
|
@@ -10,20 +11,21 @@
|
|
|
10
11
|
*
|
|
11
12
|
*/
|
|
12
13
|
declare class UidGenerator {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
readonly MAX: bigint;
|
|
15
|
+
private readonly machineBits;
|
|
16
|
+
private readonly sequenceBits;
|
|
17
|
+
private readonly epochMillisecond;
|
|
18
|
+
private readonly sequenceMask;
|
|
19
|
+
private readonly maxMachineId;
|
|
20
|
+
private readonly machineIdShift;
|
|
21
|
+
private readonly timeStampShift;
|
|
22
|
+
private readonly machineId;
|
|
23
|
+
private sequence;
|
|
24
|
+
private lastTimestamp;
|
|
25
|
+
constructor(mackineId: number);
|
|
26
|
+
readonly next: () => bigint;
|
|
26
27
|
}
|
|
27
28
|
declare const uid: UidGenerator;
|
|
28
|
-
|
|
29
|
+
//#endregion
|
|
29
30
|
export { UidGenerator, uid };
|
|
31
|
+
//# sourceMappingURL=snowflake.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snowflake.d.cts","names":[],"sources":["../src/snowflake.ts"],"mappings":";;;;;;;;;;;;cAoBa;WACK;mBACC;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;UACT;UACA;EAER,YAAY;WAII;;cAwBL,KAAG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/snowflake.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A distributed unique ID generator inspired by Twitter's Snowflake.
|
|
4
|
+
*
|
|
5
|
+
* ID data bits:
|
|
6
|
+
* +----------------------+----------------+-----------+
|
|
7
|
+
* | delta millisecond | machine id | sequence |
|
|
8
|
+
* +----------------------+----------------+-----------+
|
|
9
|
+
* | 41bits | 10bits | 12bits |
|
|
10
|
+
* +----------------------+----------------+-----------+
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
declare class UidGenerator {
|
|
14
|
+
readonly MAX: bigint;
|
|
15
|
+
private readonly machineBits;
|
|
16
|
+
private readonly sequenceBits;
|
|
17
|
+
private readonly epochMillisecond;
|
|
18
|
+
private readonly sequenceMask;
|
|
19
|
+
private readonly maxMachineId;
|
|
20
|
+
private readonly machineIdShift;
|
|
21
|
+
private readonly timeStampShift;
|
|
22
|
+
private readonly machineId;
|
|
23
|
+
private sequence;
|
|
24
|
+
private lastTimestamp;
|
|
25
|
+
constructor(mackineId: number);
|
|
26
|
+
readonly next: () => bigint;
|
|
27
|
+
}
|
|
28
|
+
declare const uid: UidGenerator;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { UidGenerator, uid };
|
|
31
|
+
//# sourceMappingURL=snowflake.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snowflake.d.mts","names":[],"sources":["../src/snowflake.ts"],"mappings":";;;;;;;;;;;;cAoBa;WACK;mBACC;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;mBACA;UACT;UACA;EAER,YAAY;WAII;;cAwBL,KAAG"}
|
package/dist/snowflake.mjs
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/snowflake.ts
|
|
2
|
+
/**
|
|
3
|
+
* A distributed unique ID generator inspired by Twitter's Snowflake.
|
|
4
|
+
*
|
|
5
|
+
* ID data bits:
|
|
6
|
+
* +----------------------+----------------+-----------+
|
|
7
|
+
* | delta millisecond | machine id | sequence |
|
|
8
|
+
* +----------------------+----------------+-----------+
|
|
9
|
+
* | 41bits | 10bits | 12bits |
|
|
10
|
+
* +----------------------+----------------+-----------+
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
2
13
|
function getNextMillisecond(timestamp) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
return now;
|
|
14
|
+
let now = BigInt(Date.now());
|
|
15
|
+
while (now < timestamp) now = BigInt(Date.now());
|
|
16
|
+
return now;
|
|
8
17
|
}
|
|
9
18
|
var UidGenerator = class {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.sequence = BigInt(0);
|
|
38
|
-
}
|
|
39
|
-
this.lastTimestamp = timestamp;
|
|
40
|
-
return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
var machineId = Math.floor(Math.random() * 1024);
|
|
44
|
-
var uid = new UidGenerator(machineId);
|
|
45
|
-
export {
|
|
46
|
-
UidGenerator,
|
|
47
|
-
uid
|
|
19
|
+
MAX = (1n << 63n) - 1n;
|
|
20
|
+
machineBits = BigInt(10);
|
|
21
|
+
sequenceBits = BigInt(12);
|
|
22
|
+
epochMillisecond = BigInt(1577808e6);
|
|
23
|
+
sequenceMask = ~(BigInt(-1) << this.sequenceBits);
|
|
24
|
+
maxMachineId = ~(BigInt(-1) << this.machineBits);
|
|
25
|
+
machineIdShift = this.sequenceBits;
|
|
26
|
+
timeStampShift = this.machineBits + this.sequenceBits;
|
|
27
|
+
machineId;
|
|
28
|
+
sequence = BigInt(0);
|
|
29
|
+
lastTimestamp = BigInt(-1);
|
|
30
|
+
constructor(mackineId) {
|
|
31
|
+
this.machineId = BigInt(mackineId) % this.maxMachineId;
|
|
32
|
+
}
|
|
33
|
+
next = () => {
|
|
34
|
+
let timestamp = BigInt(Date.now());
|
|
35
|
+
if (timestamp < this.lastTimestamp) {
|
|
36
|
+
console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);
|
|
37
|
+
timestamp = getNextMillisecond(this.lastTimestamp);
|
|
38
|
+
}
|
|
39
|
+
if (timestamp === this.lastTimestamp) {
|
|
40
|
+
this.sequence = this.sequence + BigInt(1) & this.sequenceMask;
|
|
41
|
+
if (this.sequence === BigInt(0)) timestamp = getNextMillisecond(timestamp);
|
|
42
|
+
} else this.sequence = BigInt(0);
|
|
43
|
+
this.lastTimestamp = timestamp;
|
|
44
|
+
return timestamp - this.epochMillisecond << this.timeStampShift | this.machineId << this.machineIdShift | this.sequence;
|
|
45
|
+
};
|
|
48
46
|
};
|
|
47
|
+
const uid = new UidGenerator(Math.floor(Math.random() * 1024));
|
|
48
|
+
//#endregion
|
|
49
|
+
export { UidGenerator, uid };
|
|
50
|
+
|
|
49
51
|
//# sourceMappingURL=snowflake.mjs.map
|
package/dist/snowflake.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"snowflake.mjs","names":[],"sources":["../src/snowflake.ts"],"sourcesContent":["/**\n * A distributed unique ID generator inspired by Twitter's Snowflake.\n *\n * ID data bits:\n * +----------------------+----------------+-----------+\n * | delta millisecond | machine id | sequence |\n * +----------------------+----------------+-----------+\n * | 41bits | 10bits | 12bits |\n * +----------------------+----------------+-----------+\n *\n */\n\nfunction getNextMillisecond(timestamp: bigint) {\n let now = BigInt(Date.now());\n while (now < timestamp) {\n now = BigInt(Date.now());\n }\n return now;\n}\n\nexport class UidGenerator {\n public readonly MAX = (1n << 63n) - 1n;\n private readonly machineBits = BigInt(10);\n private readonly sequenceBits = BigInt(12);\n private readonly epochMillisecond = BigInt(1577808000000); // 2020-1-1 00:00:00\n private readonly sequenceMask = ~(BigInt(-1) << this.sequenceBits);\n private readonly maxMachineId = ~(BigInt(-1) << this.machineBits);\n private readonly machineIdShift = this.sequenceBits;\n private readonly timeStampShift = this.machineBits + this.sequenceBits;\n private readonly machineId: bigint;\n private sequence = BigInt(0);\n private lastTimestamp = BigInt(-1);\n\n constructor(mackineId: number) {\n this.machineId = BigInt(mackineId) % this.maxMachineId;\n }\n\n public readonly next = (): bigint => {\n let timestamp = BigInt(Date.now());\n if (timestamp < this.lastTimestamp) {\n console.error(`Clock moved backwards. time gap = ${this.lastTimestamp - timestamp}`);\n timestamp = getNextMillisecond(this.lastTimestamp);\n }\n if (timestamp === this.lastTimestamp) {\n this.sequence = (this.sequence + BigInt(1)) & this.sequenceMask;\n if (this.sequence === BigInt(0)) {\n timestamp = getNextMillisecond(timestamp);\n }\n } else {\n this.sequence = BigInt(0);\n }\n this.lastTimestamp = timestamp;\n return (\n ((timestamp - this.epochMillisecond) << this.timeStampShift) |\n (this.machineId << this.machineIdShift) |\n this.sequence\n );\n };\n}\n\nconst machineId = Math.floor(Math.random() * 1024);\nexport const uid = new UidGenerator(machineId);\n"],"mappings":";;;;;;;;;;;;AAYA,SAAS,mBAAmB,WAAmB;CAC7C,IAAI,MAAM,OAAO,KAAK,IAAI,CAAC;CAC3B,OAAO,MAAM,WACX,MAAM,OAAO,KAAK,IAAI,CAAC;CAEzB,OAAO;AACT;AAEA,IAAa,eAAb,MAA0B;CACxB,OAAuB,MAAM,OAAO;CACpC,cAA+B,OAAO,EAAE;CACxC,eAAgC,OAAO,EAAE;CACzC,mBAAoC,OAAO,SAAa;CACxD,eAAgC,EAAE,OAAO,EAAE,KAAK,KAAK;CACrD,eAAgC,EAAE,OAAO,EAAE,KAAK,KAAK;CACrD,iBAAkC,KAAK;CACvC,iBAAkC,KAAK,cAAc,KAAK;CAC1D;CACA,WAAmB,OAAO,CAAC;CAC3B,gBAAwB,OAAO,EAAE;CAEjC,YAAY,WAAmB;EAC7B,KAAK,YAAY,OAAO,SAAS,IAAI,KAAK;CAC5C;CAEA,aAAqC;EACnC,IAAI,YAAY,OAAO,KAAK,IAAI,CAAC;EACjC,IAAI,YAAY,KAAK,eAAe;GAClC,QAAQ,MAAM,qCAAqC,KAAK,gBAAgB,WAAW;GACnF,YAAY,mBAAmB,KAAK,aAAa;EACnD;EACA,IAAI,cAAc,KAAK,eAAe;GACpC,KAAK,WAAY,KAAK,WAAW,OAAO,CAAC,IAAK,KAAK;GACnD,IAAI,KAAK,aAAa,OAAO,CAAC,GAC5B,YAAY,mBAAmB,SAAS;EAE5C,OACE,KAAK,WAAW,OAAO,CAAC;EAE1B,KAAK,gBAAgB;EACrB,OACI,YAAY,KAAK,oBAAqB,KAAK,iBAC5C,KAAK,aAAa,KAAK,iBACxB,KAAK;CAET;AACF;AAGA,MAAa,MAAM,IAAI,aADL,KAAK,MAAM,KAAK,OAAO,IAAI,IACT,CAAS"}
|
|
@@ -1,88 +1,64 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/utils/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);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/utils/geolocation.ts
|
|
29
3
|
function toNumber(value) {
|
|
30
|
-
|
|
4
|
+
return value ? Number(value) : void 0;
|
|
31
5
|
}
|
|
6
|
+
/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
|
|
32
7
|
function getGeolocationFromCloudflare(r) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
8
|
+
return {
|
|
9
|
+
ip_address: r.headers.get("true-client-ip") ?? r.headers.get("cf-connecting-ip") ?? void 0,
|
|
10
|
+
city: r.headers.get("cf-ipcity") ?? void 0,
|
|
11
|
+
country: r.headers.get("cf-ipcountry") ?? void 0,
|
|
12
|
+
continent: r.headers.get("cf-ipcontinent") ?? void 0,
|
|
13
|
+
longitude: toNumber(r.headers.get("cf-iplongitude")),
|
|
14
|
+
latitude: toNumber(r.headers.get("cf-iplatitude")),
|
|
15
|
+
region: r.headers.get("cf-region-code") ?? void 0,
|
|
16
|
+
metro_code: r.headers.get("cf-metro-code") ?? void 0,
|
|
17
|
+
postal_code: r.headers.get("cf-postal-code") ?? void 0,
|
|
18
|
+
time_zone: r.headers.get("cf-timezone") ?? void 0
|
|
19
|
+
};
|
|
45
20
|
}
|
|
21
|
+
/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */
|
|
46
22
|
function getGeolocationFromVercel(r) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
23
|
+
return {
|
|
24
|
+
ip_address: r.headers.get("x-real-ip") ?? void 0,
|
|
25
|
+
city: r.headers.get("x-vercel-ip-city") ?? void 0,
|
|
26
|
+
country: r.headers.get("x-vercel-ip-country") ?? void 0,
|
|
27
|
+
continent: r.headers.get("x-vercel-ip-continent") ?? void 0,
|
|
28
|
+
longitude: toNumber(r.headers.get("x-vercel-ip-longitude")),
|
|
29
|
+
latitude: toNumber(r.headers.get("x-vercel-ip-latitude")),
|
|
30
|
+
region: r.headers.get("x-vercel-ip-country-region") ?? void 0,
|
|
31
|
+
postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
|
|
32
|
+
};
|
|
57
33
|
}
|
|
58
34
|
function stripPort(value) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
35
|
+
if (!value) return null;
|
|
36
|
+
const i = value.lastIndexOf(":");
|
|
37
|
+
return i !== -1 && /^\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;
|
|
62
38
|
}
|
|
39
|
+
/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */
|
|
63
40
|
function getGeolocationFromCloudfront(r) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
41
|
+
return {
|
|
42
|
+
ip_address: stripPort(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
|
|
43
|
+
city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
|
|
44
|
+
country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
|
|
45
|
+
longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
|
|
46
|
+
latitude: toNumber(r.headers.get("CloudFront-Viewer-Latitude")),
|
|
47
|
+
region: r.headers.get("CloudFront-Viewer-Country-Region") ?? void 0,
|
|
48
|
+
metro_code: r.headers.get("CloudFront-Viewer-Metro-Code") ?? void 0,
|
|
49
|
+
postal_code: r.headers.get("CloudFront-Viewer-Postal-Code") ?? void 0,
|
|
50
|
+
time_zone: r.headers.get("CloudFront-Viewer-Time-Zone") ?? void 0
|
|
51
|
+
};
|
|
75
52
|
}
|
|
76
53
|
function getGeolocation(r) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
54
|
+
if (r.headers.get("x-vercel-id")) return getGeolocationFromVercel(r);
|
|
55
|
+
if (r.headers.get("cf-ray")) return getGeolocationFromCloudflare(r);
|
|
56
|
+
return getGeolocationFromCloudfront(r);
|
|
80
57
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.getGeolocation = getGeolocation;
|
|
60
|
+
exports.getGeolocationFromCloudflare = getGeolocationFromCloudflare;
|
|
61
|
+
exports.getGeolocationFromCloudfront = getGeolocationFromCloudfront;
|
|
62
|
+
exports.getGeolocationFromVercel = getGeolocationFromVercel;
|
|
63
|
+
|
|
88
64
|
//# sourceMappingURL=geolocation.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"file":"geolocation.cjs","names":[],"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;CAC1D,OAAO,QAAQ,OAAO,KAAK,IAAI,KAAA;AACjC;;AAGA,SAAgB,6BAA6B,GAAyB;CACpE,OAAO;EACL,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,EAAE,QAAQ,IAAI,kBAAkB,KAAK,KAAA;EACpF,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK,KAAA;EACpC,SAAS,EAAE,QAAQ,IAAI,cAAc,KAAK,KAAA;EAC1C,WAAW,EAAE,QAAQ,IAAI,gBAAgB,KAAK,KAAA;EAC9C,WAAW,SAAS,EAAE,QAAQ,IAAI,gBAAgB,CAAC;EACnD,UAAU,SAAS,EAAE,QAAQ,IAAI,eAAe,CAAC;EACjD,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,KAAK,KAAA;EAC3C,YAAY,EAAE,QAAQ,IAAI,eAAe,KAAK,KAAA;EAC9C,aAAa,EAAE,QAAQ,IAAI,gBAAgB,KAAK,KAAA;EAChD,WAAW,EAAE,QAAQ,IAAI,aAAa,KAAK,KAAA;CAC7C;AACF;;AAGA,SAAgB,yBAAyB,GAAyB;CAChE,OAAO;EACL,YAAY,EAAE,QAAQ,IAAI,WAAW,KAAK,KAAA;EAC1C,MAAM,EAAE,QAAQ,IAAI,kBAAkB,KAAK,KAAA;EAC3C,SAAS,EAAE,QAAQ,IAAI,qBAAqB,KAAK,KAAA;EACjD,WAAW,EAAE,QAAQ,IAAI,uBAAuB,KAAK,KAAA;EACrD,WAAW,SAAS,EAAE,QAAQ,IAAI,uBAAuB,CAAC;EAC1D,UAAU,SAAS,EAAE,QAAQ,IAAI,sBAAsB,CAAC;EACxD,QAAQ,EAAE,QAAQ,IAAI,4BAA4B,KAAK,KAAA;EACvD,aAAa,EAAE,QAAQ,IAAI,yBAAyB,KAAK,KAAA;CAC3D;AACF;AAEA,SAAS,UAAU,OAAqC;CACtD,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,IAAI,MAAM,YAAY,GAAG;CAC/B,OAAO,MAAM,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,GAAG,CAAC,IAAI;AAC5E;;AAGA,SAAgB,6BAA6B,GAAyB;CACpE,OAAO;EACL,YAAY,UAAU,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK,KAAA;EACrE,MAAM,EAAE,QAAQ,IAAI,wBAAwB,KAAK,KAAA;EACjD,SAAS,EAAE,QAAQ,IAAI,2BAA2B,KAAK,KAAA;EACvD,WAAW,SAAS,EAAE,QAAQ,IAAI,6BAA6B,CAAC;EAChE,UAAU,SAAS,EAAE,QAAQ,IAAI,4BAA4B,CAAC;EAC9D,QAAQ,EAAE,QAAQ,IAAI,kCAAkC,KAAK,KAAA;EAC7D,YAAY,EAAE,QAAQ,IAAI,8BAA8B,KAAK,KAAA;EAC7D,aAAa,EAAE,QAAQ,IAAI,+BAA+B,KAAK,KAAA;EAC/D,WAAW,EAAE,QAAQ,IAAI,6BAA6B,KAAK,KAAA;CAC7D;AACF;AAEA,SAAgB,eAAe,GAAyB;CACtD,IAAI,EAAE,QAAQ,IAAI,aAAa,GAAG,OAAO,yBAAyB,CAAC;CACnE,IAAI,EAAE,QAAQ,IAAI,QAAQ,GAAG,OAAO,6BAA6B,CAAC;CAClE,OAAO,6BAA6B,CAAC;AACvC"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
//#region src/utils/geolocation.d.ts
|
|
1
2
|
type Geolocation = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
ip_address?: string;
|
|
4
|
+
city?: string;
|
|
5
|
+
country?: string;
|
|
6
|
+
continent?: string;
|
|
7
|
+
longitude?: number;
|
|
8
|
+
latitude?: number;
|
|
9
|
+
region?: string;
|
|
10
|
+
metro_code?: string;
|
|
11
|
+
postal_code?: string;
|
|
12
|
+
time_zone?: string;
|
|
12
13
|
};
|
|
13
14
|
/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
|
|
14
15
|
declare function getGeolocationFromCloudflare(r: Request): Geolocation;
|
|
@@ -17,5 +18,6 @@ declare function getGeolocationFromVercel(r: Request): Geolocation;
|
|
|
17
18
|
/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */
|
|
18
19
|
declare function getGeolocationFromCloudfront(r: Request): Geolocation;
|
|
19
20
|
declare function getGeolocation(r: Request): Geolocation;
|
|
20
|
-
|
|
21
|
-
export {
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Geolocation, getGeolocation, getGeolocationFromCloudflare, getGeolocationFromCloudfront, getGeolocationFromVercel };
|
|
23
|
+
//# sourceMappingURL=geolocation.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation.d.cts","names":[],"sources":["../../src/utils/geolocation.ts"],"mappings":";KAAY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;iBAQc,6BAA6B,GAAG,UAAU;;iBAgB1C,yBAAyB,GAAG,UAAU;;iBAoBtC,6BAA6B,GAAG,UAAU;iBAc1C,eAAe,GAAG,UAAU"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
//#region src/utils/geolocation.d.ts
|
|
1
2
|
type Geolocation = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
ip_address?: string;
|
|
4
|
+
city?: string;
|
|
5
|
+
country?: string;
|
|
6
|
+
continent?: string;
|
|
7
|
+
longitude?: number;
|
|
8
|
+
latitude?: number;
|
|
9
|
+
region?: string;
|
|
10
|
+
metro_code?: string;
|
|
11
|
+
postal_code?: string;
|
|
12
|
+
time_zone?: string;
|
|
12
13
|
};
|
|
13
14
|
/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
|
|
14
15
|
declare function getGeolocationFromCloudflare(r: Request): Geolocation;
|
|
@@ -17,5 +18,6 @@ declare function getGeolocationFromVercel(r: Request): Geolocation;
|
|
|
17
18
|
/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */
|
|
18
19
|
declare function getGeolocationFromCloudfront(r: Request): Geolocation;
|
|
19
20
|
declare function getGeolocation(r: Request): Geolocation;
|
|
20
|
-
|
|
21
|
-
export {
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Geolocation, getGeolocation, getGeolocationFromCloudflare, getGeolocationFromCloudfront, getGeolocationFromVercel };
|
|
23
|
+
//# sourceMappingURL=geolocation.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geolocation.d.mts","names":[],"sources":["../../src/utils/geolocation.ts"],"mappings":";KAAY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;iBAQc,6BAA6B,GAAG,UAAU;;iBAgB1C,yBAAyB,GAAG,UAAU;;iBAoBtC,6BAA6B,GAAG,UAAU;iBAc1C,eAAe,GAAG,UAAU"}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/utils/geolocation.ts
|
|
2
2
|
function toNumber(value) {
|
|
3
|
-
|
|
3
|
+
return value ? Number(value) : void 0;
|
|
4
4
|
}
|
|
5
|
+
/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */
|
|
5
6
|
function getGeolocationFromCloudflare(r) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
};
|
|
18
19
|
}
|
|
20
|
+
/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */
|
|
19
21
|
function getGeolocationFromVercel(r) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
return {
|
|
23
|
+
ip_address: r.headers.get("x-real-ip") ?? void 0,
|
|
24
|
+
city: r.headers.get("x-vercel-ip-city") ?? void 0,
|
|
25
|
+
country: r.headers.get("x-vercel-ip-country") ?? void 0,
|
|
26
|
+
continent: r.headers.get("x-vercel-ip-continent") ?? void 0,
|
|
27
|
+
longitude: toNumber(r.headers.get("x-vercel-ip-longitude")),
|
|
28
|
+
latitude: toNumber(r.headers.get("x-vercel-ip-latitude")),
|
|
29
|
+
region: r.headers.get("x-vercel-ip-country-region") ?? void 0,
|
|
30
|
+
postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
|
|
31
|
+
};
|
|
30
32
|
}
|
|
31
33
|
function stripPort(value) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (!value) return null;
|
|
35
|
+
const i = value.lastIndexOf(":");
|
|
36
|
+
return i !== -1 && /^\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;
|
|
35
37
|
}
|
|
38
|
+
/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */
|
|
36
39
|
function getGeolocationFromCloudfront(r) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
return {
|
|
41
|
+
ip_address: stripPort(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
|
|
42
|
+
city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
|
|
43
|
+
country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
|
|
44
|
+
longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
|
|
45
|
+
latitude: toNumber(r.headers.get("CloudFront-Viewer-Latitude")),
|
|
46
|
+
region: r.headers.get("CloudFront-Viewer-Country-Region") ?? void 0,
|
|
47
|
+
metro_code: r.headers.get("CloudFront-Viewer-Metro-Code") ?? void 0,
|
|
48
|
+
postal_code: r.headers.get("CloudFront-Viewer-Postal-Code") ?? void 0,
|
|
49
|
+
time_zone: r.headers.get("CloudFront-Viewer-Time-Zone") ?? void 0
|
|
50
|
+
};
|
|
48
51
|
}
|
|
49
52
|
function getGeolocation(r) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
if (r.headers.get("x-vercel-id")) return getGeolocationFromVercel(r);
|
|
54
|
+
if (r.headers.get("cf-ray")) return getGeolocationFromCloudflare(r);
|
|
55
|
+
return getGeolocationFromCloudfront(r);
|
|
53
56
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
getGeolocationFromCloudfront,
|
|
58
|
-
getGeolocationFromVercel
|
|
59
|
-
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { getGeolocation, getGeolocationFromCloudflare, getGeolocationFromCloudfront, getGeolocationFromVercel };
|
|
59
|
+
|
|
60
60
|
//# sourceMappingURL=geolocation.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"geolocation.mjs","names":[],"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;CAC1D,OAAO,QAAQ,OAAO,KAAK,IAAI,KAAA;AACjC;;AAGA,SAAgB,6BAA6B,GAAyB;CACpE,OAAO;EACL,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,EAAE,QAAQ,IAAI,kBAAkB,KAAK,KAAA;EACpF,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK,KAAA;EACpC,SAAS,EAAE,QAAQ,IAAI,cAAc,KAAK,KAAA;EAC1C,WAAW,EAAE,QAAQ,IAAI,gBAAgB,KAAK,KAAA;EAC9C,WAAW,SAAS,EAAE,QAAQ,IAAI,gBAAgB,CAAC;EACnD,UAAU,SAAS,EAAE,QAAQ,IAAI,eAAe,CAAC;EACjD,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,KAAK,KAAA;EAC3C,YAAY,EAAE,QAAQ,IAAI,eAAe,KAAK,KAAA;EAC9C,aAAa,EAAE,QAAQ,IAAI,gBAAgB,KAAK,KAAA;EAChD,WAAW,EAAE,QAAQ,IAAI,aAAa,KAAK,KAAA;CAC7C;AACF;;AAGA,SAAgB,yBAAyB,GAAyB;CAChE,OAAO;EACL,YAAY,EAAE,QAAQ,IAAI,WAAW,KAAK,KAAA;EAC1C,MAAM,EAAE,QAAQ,IAAI,kBAAkB,KAAK,KAAA;EAC3C,SAAS,EAAE,QAAQ,IAAI,qBAAqB,KAAK,KAAA;EACjD,WAAW,EAAE,QAAQ,IAAI,uBAAuB,KAAK,KAAA;EACrD,WAAW,SAAS,EAAE,QAAQ,IAAI,uBAAuB,CAAC;EAC1D,UAAU,SAAS,EAAE,QAAQ,IAAI,sBAAsB,CAAC;EACxD,QAAQ,EAAE,QAAQ,IAAI,4BAA4B,KAAK,KAAA;EACvD,aAAa,EAAE,QAAQ,IAAI,yBAAyB,KAAK,KAAA;CAC3D;AACF;AAEA,SAAS,UAAU,OAAqC;CACtD,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,IAAI,MAAM,YAAY,GAAG;CAC/B,OAAO,MAAM,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,MAAM,GAAG,CAAC,IAAI;AAC5E;;AAGA,SAAgB,6BAA6B,GAAyB;CACpE,OAAO;EACL,YAAY,UAAU,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK,KAAA;EACrE,MAAM,EAAE,QAAQ,IAAI,wBAAwB,KAAK,KAAA;EACjD,SAAS,EAAE,QAAQ,IAAI,2BAA2B,KAAK,KAAA;EACvD,WAAW,SAAS,EAAE,QAAQ,IAAI,6BAA6B,CAAC;EAChE,UAAU,SAAS,EAAE,QAAQ,IAAI,4BAA4B,CAAC;EAC9D,QAAQ,EAAE,QAAQ,IAAI,kCAAkC,KAAK,KAAA;EAC7D,YAAY,EAAE,QAAQ,IAAI,8BAA8B,KAAK,KAAA;EAC7D,aAAa,EAAE,QAAQ,IAAI,+BAA+B,KAAK,KAAA;EAC/D,WAAW,EAAE,QAAQ,IAAI,6BAA6B,KAAK,KAAA;CAC7D;AACF;AAEA,SAAgB,eAAe,GAAyB;CACtD,IAAI,EAAE,QAAQ,IAAI,aAAa,GAAG,OAAO,yBAAyB,CAAC;CACnE,IAAI,EAAE,QAAQ,IAAI,QAAQ,GAAG,OAAO,6BAA6B,CAAC;CAClE,OAAO,6BAA6B,CAAC;AACvC"}
|