Fix spr endpoint

This commit is contained in:
Arnaud 2024-09-13 22:30:37 +02:00
parent e943a2ffa9
commit 711c4d6951
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
4 changed files with 8 additions and 11 deletions

View File

@ -308,7 +308,7 @@ const node = await codex.node;
Get Node's SPR
- returns Promise<string>
- returns Promise<[CodexSpr](./src/node/types.ts#L1)>
Example:

View File

@ -30,7 +30,7 @@ describe("debug", () => {
});
});
it("returns a success when trying to setup the log level with a correct value", async (t) => {
it("returns a success when trying to setup the log level with a correct value", async () => {
const mockResponse = {
ok: true,
status: 200,

View File

@ -1,7 +1,7 @@
import { Api } from "../api/config";
import type { SafeValue } from "../async";
import { Fetch } from "../fetch-safe/fetch-safe";
import { Promises } from "../promise-safe/promise-safe";
import type { CodexSpr } from "./types";
export class CodexNode {
readonly url: string;
@ -32,18 +32,12 @@ export class CodexNode {
/**
* Get Node's SPR
*/
async spr(): Promise<SafeValue<string>> {
async spr(): Promise<SafeValue<CodexSpr>> {
const url = this.url + Api.config.prefix + "/spr";
const res = await Fetch.safe(url, {
return Fetch.safeJson(url, {
method: "GET",
});
if (res.error) {
return res;
}
return await Promises.safe(res.data.text);
}
/**

3
src/node/types.ts Normal file
View File

@ -0,0 +1,3 @@
export type CodexSpr = {
spr: string;
};