@dignetwork/dig-sdk 0.0.1-alpha.101 → 0.0.1-alpha.102
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/DigNetwork/ContentServer.d.ts.map +1 -1
- package/dist/DigNetwork/ContentServer.js +9 -8
- package/dist/DigNetwork/IncentiveServer.d.ts.map +1 -1
- package/dist/DigNetwork/IncentiveServer.js +6 -5
- package/dist/DigNetwork/PropagationServer.d.ts.map +1 -1
- package/dist/DigNetwork/PropagationServer.js +9 -8
- package/dist/utils/network.d.ts +1 -0
- package/dist/utils/network.d.ts.map +1 -1
- package/dist/utils/network.js +12 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/ContentServer.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"ContentServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/ContentServer.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAIlC,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAS;IAChC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;gBAExB,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAYjC,MAAM,CACjB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC;IAaL,iBAAiB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAe3C,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC;IAM5B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAM9B,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAY7C,OAAO,CAClB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAA;KAAE,CAAC;IAYvD,SAAS,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QACjE,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC;KACpC,CAAC;IAUW,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUrD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;YAgDrD,IAAI;YA0EJ,SAAS;YAMT,gBAAgB;YAiChB,KAAK;CA6GpB"}
|
|
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const http_1 = __importDefault(require("http"));
|
|
9
9
|
const url_1 = require("url");
|
|
10
10
|
const ssl_1 = require("../utils/ssl");
|
|
11
|
+
const network_1 = require("../utils/network");
|
|
11
12
|
class ContentServer {
|
|
12
13
|
constructor(ipAddress, storeId) {
|
|
13
14
|
this.ipAddress = ipAddress;
|
|
@@ -21,7 +22,7 @@ class ContentServer {
|
|
|
21
22
|
// Method to get the content of a specified key from the peer, with optional challenge query
|
|
22
23
|
async getKey(key, rootHash, challengeHex) {
|
|
23
24
|
// Construct the base URL
|
|
24
|
-
let url = `https://${this.ipAddress}:${ContentServer.port}/chia.${this.storeId}.${rootHash}/${key}`;
|
|
25
|
+
let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/chia.${this.storeId}.${rootHash}/${key}`;
|
|
25
26
|
// If a challenge is provided, append it as a query parameter
|
|
26
27
|
if (challengeHex) {
|
|
27
28
|
url += `?challenge=${challengeHex}`;
|
|
@@ -42,17 +43,17 @@ class ContentServer {
|
|
|
42
43
|
}
|
|
43
44
|
// Method to get the .well-known information
|
|
44
45
|
async getWellKnown() {
|
|
45
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/.well-known`;
|
|
46
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/.well-known`;
|
|
46
47
|
return this.fetchJson(url);
|
|
47
48
|
}
|
|
48
49
|
// Method to get the list of known stores
|
|
49
50
|
async getKnownStores() {
|
|
50
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/.well-known/stores`;
|
|
51
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/.well-known/stores`;
|
|
51
52
|
return this.fetchJson(url);
|
|
52
53
|
}
|
|
53
54
|
// Method to get the index of all stores
|
|
54
55
|
async getStoresIndex() {
|
|
55
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/`;
|
|
56
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/`;
|
|
56
57
|
return this.fetchJson(url);
|
|
57
58
|
}
|
|
58
59
|
// Method to get the index of keys in a store
|
|
@@ -61,7 +62,7 @@ class ContentServer {
|
|
|
61
62
|
if (rootHash) {
|
|
62
63
|
udi += `.${rootHash}`;
|
|
63
64
|
}
|
|
64
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}`;
|
|
65
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}`;
|
|
65
66
|
return this.fetchJson(url);
|
|
66
67
|
}
|
|
67
68
|
// Method to check if a specific key exists (HEAD request)
|
|
@@ -70,12 +71,12 @@ class ContentServer {
|
|
|
70
71
|
if (rootHash) {
|
|
71
72
|
udi += `.${rootHash}`;
|
|
72
73
|
}
|
|
73
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}/${key}`;
|
|
74
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}/${key}`;
|
|
74
75
|
return this.head(url);
|
|
75
76
|
}
|
|
76
77
|
// Method to check if a specific store exists (HEAD request)
|
|
77
78
|
async headStore(options) {
|
|
78
|
-
let url = `https://${this.ipAddress}:${ContentServer.port}/chia.${this.storeId}`;
|
|
79
|
+
let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/chia.${this.storeId}`;
|
|
79
80
|
if (options?.hasRootHash) {
|
|
80
81
|
url += `?hasRootHash=${options.hasRootHash}`;
|
|
81
82
|
}
|
|
@@ -96,7 +97,7 @@ class ContentServer {
|
|
|
96
97
|
udi += `.${rootHash}`;
|
|
97
98
|
}
|
|
98
99
|
return new Promise((resolve, reject) => {
|
|
99
|
-
const url = `https://${this.ipAddress}:${ContentServer.port}/${udi}/${key}`;
|
|
100
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${ContentServer.port}/${udi}/${key}`;
|
|
100
101
|
const urlObj = new url_1.URL(url);
|
|
101
102
|
const requestOptions = {
|
|
102
103
|
hostname: urlObj.hostname,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IncentiveServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/IncentiveServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"IncentiveServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/IncentiveServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGhD,qBAAa,eAAe;IAC1B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,IAAI,CAAgB;gBAEhB,SAAS,EAAE,MAAM;IAKhB,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,sBAAsB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtD,uBAAuB,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAO1D,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;YAOlE,WAAW;CA6C1B"}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.IncentiveServer = void 0;
|
|
7
7
|
const https_1 = __importDefault(require("https"));
|
|
8
8
|
const url_1 = require("url");
|
|
9
|
+
const network_1 = require("../utils/network");
|
|
9
10
|
class IncentiveServer {
|
|
10
11
|
constructor(ipAddress) {
|
|
11
12
|
this.port = 4160;
|
|
@@ -13,27 +14,27 @@ class IncentiveServer {
|
|
|
13
14
|
}
|
|
14
15
|
// Method to create a new incentive program
|
|
15
16
|
async createIncentiveProgram(data) {
|
|
16
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
17
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
17
18
|
await this.makeRequest(url, "POST", data);
|
|
18
19
|
}
|
|
19
20
|
// Method to update an existing incentive program
|
|
20
21
|
async updateIncentiveProgram(data) {
|
|
21
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
22
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
22
23
|
await this.makeRequest(url, "PUT", data);
|
|
23
24
|
}
|
|
24
25
|
// Method to delete an incentive program by storeId
|
|
25
26
|
async deleteIncentiveProgram(storeId) {
|
|
26
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
27
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
27
28
|
await this.makeRequest(url, "DELETE", { storeId });
|
|
28
29
|
}
|
|
29
30
|
// Method to get all incentive programs
|
|
30
31
|
async getAllIncentivePrograms() {
|
|
31
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive`;
|
|
32
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive`;
|
|
32
33
|
return this.makeRequest(url, "GET");
|
|
33
34
|
}
|
|
34
35
|
// Method to get a specific incentive program by storeId
|
|
35
36
|
async getIncentiveProgram(storeId) {
|
|
36
|
-
const url = `https://${this.ipAddress}:${this.port}/incentive/${storeId}`;
|
|
37
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${this.port}/incentive/${storeId}`;
|
|
37
38
|
return this.makeRequest(url, "GET");
|
|
38
39
|
}
|
|
39
40
|
// Helper method to handle the HTTPS request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"PropagationServer.d.ts","sourceRoot":"","sources":["../../src/DigNetwork/PropagationServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAC;AAW1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAkBrC,qBAAa,iBAAiB;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAQ;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;gBAErC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAY9C;;OAEG;IACG,gBAAgB;IAOtB;;OAEG;IACH,gBAAgB;IAQhB;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM;IAyB3D;;OAEG;IACG,gBAAgB,CACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC;QAAE,WAAW,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAC;IA0C7D;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAuDzC;;OAEG;IACG,YAAY,CAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC;IAyBlD;;;OAGG;IACG,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAuGhD;;OAEG;IACG,mBAAmB;IAgCzB;;OAEG;WACU,WAAW,CACtB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;IA2DnB;;;OAGG;IACG,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgFlD;;OAEG;IACG,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA0B7C;;;OAGG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM;IAwGjB;;OAEG;WACU,aAAa,CACxB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;CA2FpB"}
|
|
@@ -23,6 +23,7 @@ const stream_1 = require("stream");
|
|
|
23
23
|
const credentialsUtils_1 = require("../utils/credentialsUtils");
|
|
24
24
|
const config_1 = require("../utils/config");
|
|
25
25
|
const blockchain_1 = require("../blockchain");
|
|
26
|
+
const network_1 = require("../utils/network");
|
|
26
27
|
// Helper function to trim long filenames with ellipsis and ensure consistent padding
|
|
27
28
|
function formatFilename(filename, maxLength = 30) {
|
|
28
29
|
if (!filename) {
|
|
@@ -90,7 +91,7 @@ class PropagationServer {
|
|
|
90
91
|
const config = {
|
|
91
92
|
httpsAgent: this.createHttpsAgent(),
|
|
92
93
|
};
|
|
93
|
-
let url = `https://${this.ipAddress}:${PropagationServer.port}/${this.storeId}`;
|
|
94
|
+
let url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/${this.storeId}`;
|
|
94
95
|
if (rootHash) {
|
|
95
96
|
url += `?hasRootHash=${rootHash}`;
|
|
96
97
|
}
|
|
@@ -144,7 +145,7 @@ class PropagationServer {
|
|
|
144
145
|
password: this.password,
|
|
145
146
|
};
|
|
146
147
|
}
|
|
147
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}?roothash=${rootHash}`;
|
|
148
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/upload/${this.storeId}?roothash=${rootHash}`;
|
|
148
149
|
const response = await axios_1.default.post(url, formData, config);
|
|
149
150
|
this.sessionId = response.data.sessionId;
|
|
150
151
|
spinner.success({
|
|
@@ -165,7 +166,7 @@ class PropagationServer {
|
|
|
165
166
|
const config = {
|
|
166
167
|
httpsAgent: this.createHttpsAgent(),
|
|
167
168
|
};
|
|
168
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
|
|
169
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
|
|
169
170
|
const response = await axios_1.default.head(url, config);
|
|
170
171
|
// Check for 'x-file-exists' header
|
|
171
172
|
const fileExists = response.headers["x-file-exists"] === "true";
|
|
@@ -239,7 +240,7 @@ class PropagationServer {
|
|
|
239
240
|
maxContentLength: Infinity,
|
|
240
241
|
maxBodyLength: Infinity,
|
|
241
242
|
};
|
|
242
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${dataPath}`;
|
|
243
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${dataPath}`;
|
|
243
244
|
// Create a promise that resolves when the progress stream ends
|
|
244
245
|
const progressPromise = new Promise((resolve, reject) => {
|
|
245
246
|
progressStream.on("end", resolve);
|
|
@@ -274,7 +275,7 @@ class PropagationServer {
|
|
|
274
275
|
}
|
|
275
276
|
: undefined,
|
|
276
277
|
};
|
|
277
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/commit/${this.storeId}/${this.sessionId}`;
|
|
278
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/commit/${this.storeId}/${this.sessionId}`;
|
|
278
279
|
const response = await axios_1.default.post(url, {}, config);
|
|
279
280
|
spinner.success({
|
|
280
281
|
text: (0, colorette_1.green)(`Upload session ${this.sessionId} successfully committed.`),
|
|
@@ -330,7 +331,7 @@ class PropagationServer {
|
|
|
330
331
|
* Logs progress using a local cli-progress bar.
|
|
331
332
|
*/
|
|
332
333
|
async fetchFile(dataPath) {
|
|
333
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
334
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
334
335
|
const config = {
|
|
335
336
|
responseType: "stream",
|
|
336
337
|
httpsAgent: this.createHttpsAgent(),
|
|
@@ -397,7 +398,7 @@ class PropagationServer {
|
|
|
397
398
|
const config = {
|
|
398
399
|
httpsAgent: this.createHttpsAgent(),
|
|
399
400
|
};
|
|
400
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/store/${this.storeId}/${rootHash}/${dataPath}`;
|
|
401
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/store/${this.storeId}/${rootHash}/${dataPath}`;
|
|
401
402
|
const response = await axios_1.default.head(url, config);
|
|
402
403
|
// Check the headers for file existence and size
|
|
403
404
|
const fileExists = response.headers["x-file-exists"] === "true";
|
|
@@ -417,7 +418,7 @@ class PropagationServer {
|
|
|
417
418
|
* Logs progress using a local cli-progress bar.
|
|
418
419
|
*/
|
|
419
420
|
async downloadFile(label, dataPath, rootHash, baseDir) {
|
|
420
|
-
const url = `https://${this.ipAddress}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
421
|
+
const url = `https://${(0, network_1.formatHost)(this.ipAddress)}:${PropagationServer.port}/fetch/${this.storeId}/${dataPath}`;
|
|
421
422
|
let downloadPath = path_1.default.join(baseDir, dataPath);
|
|
422
423
|
// Ensure that the directory for the file exists
|
|
423
424
|
fs_1.default.mkdirSync(path_1.default.dirname(downloadPath), { recursive: true });
|
package/dist/utils/network.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6CrE,CAAC"}
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,MAAM,GAAG,SAAS,CA6CrE,CAAC;AAGF,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,MAUzC,CAAC"}
|
package/dist/utils/network.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPublicIpAddress = void 0;
|
|
6
|
+
exports.formatHost = exports.getPublicIpAddress = void 0;
|
|
7
7
|
/*
|
|
8
8
|
* Stopgap until better solution for finding public IPS found
|
|
9
9
|
*/
|
|
@@ -52,3 +52,14 @@ const getPublicIpAddress = async () => {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
exports.getPublicIpAddress = getPublicIpAddress;
|
|
55
|
+
// Helper function to wrap IPv6 addresses in brackets
|
|
56
|
+
const formatHost = (host) => {
|
|
57
|
+
const ipv6Pattern = /^[a-fA-F0-9:]+$/; // Simple regex to match raw IPv6 addresses (without brackets)
|
|
58
|
+
const hasBrackets = /^\[.*\]$/; // Regex to check if the address already has brackets
|
|
59
|
+
// If it's an IPv6 address without brackets, add them
|
|
60
|
+
if (ipv6Pattern.test(host) && !hasBrackets.test(host)) {
|
|
61
|
+
return `[${host}]`;
|
|
62
|
+
}
|
|
63
|
+
return host; // Return the host as is (IPv4, hostname, or already bracketed IPv6)
|
|
64
|
+
};
|
|
65
|
+
exports.formatHost = formatHost;
|