sliftutils 1.1.1 → 1.1.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/index.d.ts CHANGED
@@ -176,6 +176,20 @@ declare module "sliftutils/misc/https/httpsCerts" {
176
176
 
177
177
  }
178
178
 
179
+ declare module "sliftutils/misc/https/ip" {
180
+ export declare const getExternalIP: {
181
+ (): Promise<string>;
182
+ reset(): void;
183
+ set(newValue: Promise<string>): void;
184
+ };
185
+ export declare const getPublicIP: {
186
+ (): Promise<string>;
187
+ reset(): void;
188
+ set(newValue: Promise<string>): void;
189
+ };
190
+
191
+ }
192
+
179
193
  declare module "sliftutils/misc/https/node-forge-ed25519" {
180
194
 
181
195
 
@@ -0,0 +1,10 @@
1
+ export declare const getExternalIP: {
2
+ (): Promise<string>;
3
+ reset(): void;
4
+ set(newValue: Promise<string>): void;
5
+ };
6
+ export declare const getPublicIP: {
7
+ (): Promise<string>;
8
+ reset(): void;
9
+ set(newValue: Promise<string>): void;
10
+ };
@@ -0,0 +1,21 @@
1
+ import { lazy } from "socket-function/src/caching";
2
+ import { httpsRequest } from "socket-function/src/https";
3
+
4
+ const ipServers = [
5
+ "http://quentinbrooks.com:4283",
6
+ "https://ipinfo.io/ip",
7
+ "https://api.ipify.org"
8
+ ];
9
+
10
+ export const getExternalIP = lazy((async function getExternalIP(): Promise<string> {
11
+ for (let server of ipServers) {
12
+ try {
13
+ return (await httpsRequest(server, undefined, undefined, false)).toString();
14
+ } catch (e) {
15
+ console.warn(`Failed to get external ip from ${server}: ${e}`);
16
+ }
17
+ }
18
+ throw new Error(`Failed to get external ip from any server`);
19
+ }));
20
+
21
+ export const getPublicIP = getExternalIP;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [