Add a plugin API for reading HTTP response bodies (#560)

This commit is contained in:
Gregory Schier authored and GitHub committed 2026-08-16 11:10:14 -07:00
1 parent 78954e10c8
commit 10e962a0e6
29 files changed
+1274 -70

No files matched your search

@@ -1,4 +1,3 @@
import { readFileSync } from "node:fs";
import type { Context, HttpRequest } from "@yaakapp/api";
import type { AccessToken, AccessTokenRawResponse, TokenStoreArgs } from "./store";
import { deleteToken, getToken, storeToken } from "./store";
@@ -71,7 +70,7 @@ export async function getOrRefreshAccessToken(
}
httpRequest.authenticationType = "none"; // Don't inherit workspace auth
const resp = await ctx.httpRequest.send({ httpRequest });
const { httpResponse: resp, body: responseBody } = await ctx.httpRequest.send({ httpRequest });
if (resp.error) {
throw new Error(`Failed to refresh access token: ${resp.error}`);
@@ -85,7 +84,9 @@ export async function getOrRefreshAccessToken(
return null;
}
const body = resp.bodyPath ? readFileSync(resp.bodyPath, "utf8") : "";
// Sent ad-hoc, so this body came back with the response rather than being
// saved anywhere to read later.
const body = await responseBody.text();
console.log("[oauth2] Got refresh token response", resp.status);