From 711c4d6951e20b21be63213b5cf3446d90486e2e Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 13 Sep 2024 22:30:37 +0200 Subject: [PATCH] Fix spr endpoint --- README.md | 2 +- src/debug/debug.test.ts | 2 +- src/node/node.ts | 12 +++--------- src/node/types.ts | 3 +++ 4 files changed, 8 insertions(+), 11 deletions(-) create mode 100644 src/node/types.ts diff --git a/README.md b/README.md index c0b3e6f..0e84e5b 100644 --- a/README.md +++ b/README.md @@ -308,7 +308,7 @@ const node = await codex.node; Get Node's SPR -- returns Promise +- returns Promise<[CodexSpr](./src/node/types.ts#L1)> Example: diff --git a/src/debug/debug.test.ts b/src/debug/debug.test.ts index 58d1406..ec14479 100644 --- a/src/debug/debug.test.ts +++ b/src/debug/debug.test.ts @@ -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, diff --git a/src/node/node.ts b/src/node/node.ts index a7f0b56..1029e8e 100644 --- a/src/node/node.ts +++ b/src/node/node.ts @@ -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> { + async spr(): Promise> { 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); } /** diff --git a/src/node/types.ts b/src/node/types.ts new file mode 100644 index 0000000..169e999 --- /dev/null +++ b/src/node/types.ts @@ -0,0 +1,3 @@ +export type CodexSpr = { + spr: string; +};