@codex-storage/sdk-js
Version:
Codex SDK to interact with the Codex decentralized storage network.
76 lines (74 loc) • 1.85 kB
JavaScript
import { Api } from './chunk-JUEFSJIF.mjs';
import { Fetch, FetchAuthBuilder } from './chunk-2VOCE3TZ.mjs';
// src/node/node.ts
var CodexNode = class {
url;
auth = {};
constructor(url, options) {
this.url = url;
if (options == null ? void 0 : options.auth) {
this.auth = options.auth;
}
}
/**
* Connect to a peer
*/
connect(peerId, addrs = []) {
const params = new URLSearchParams();
for (const addr of addrs) {
params.append("addrs", addr);
}
const url = this.url + Api.config.prefix + `/connect/${peerId}?` + params.toString();
return Fetch.safeText(url, {
method: "GET",
headers: FetchAuthBuilder.build(this.auth)
});
}
/**
* Get Node's SPR
*/
async spr(type = "json") {
const url = this.url + Api.config.prefix + "/spr";
if (type === "json") {
return Fetch.safeJson(url, {
method: "GET",
headers: {
...FetchAuthBuilder.build(this.auth),
"Content-Type": "application/json"
}
});
}
return Fetch.safeText(url, {
method: "GET",
headers: {
...FetchAuthBuilder.build(this.auth),
"Content-Type": "text/plain"
}
});
}
/**
* Get Node's PeerID
*/
peerId(type = "json") {
const url = this.url + Api.config.prefix + "/node/peerid";
if (type === "json") {
return Fetch.safeJson(url, {
method: "GET",
headers: {
...FetchAuthBuilder.build(this.auth),
"Content-Type": "application/json"
}
});
}
return Fetch.safeText(url, {
method: "GET",
headers: {
...FetchAuthBuilder.build(this.auth),
"Content-Type": "text/plain"
}
});
}
};
export { CodexNode };
//# sourceMappingURL=chunk-HPUHQWSZ.mjs.map
//# sourceMappingURL=chunk-HPUHQWSZ.mjs.map