UNPKG

lago-javascript-client

Version:
34 lines (33 loc) 1.18 kB
// deno-lint-ignore-file no-explicit-any import { Api } from "./openapi/client.js"; export const Client = (apiKey, apiConfig) => { const api = new Api({ securityWorker: (apiKey) => apiKey ? { headers: { Authorization: `Bearer ${apiKey}` } } : {}, // Cloudflare Workers doesn't support some options like credentials so need to override default baseApiParams: { redirect: "follow", }, ...apiConfig, }); api.setSecurityData(apiKey); return api; }; // https://github.com/remix-run/remix/blob/ef26f7671a9619966a6cfa3c39e196d44fbf32cf/packages/remix-server-runtime/responses.ts#L60 function isResponse(value) { return (value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined"); } export async function getLagoError(error) { if (isResponse(error)) { if (!error.bodyUsed) { const errorJson = await error.json(); return errorJson; } return error.error; } throw new Error(error); } export * from "./openapi/client.js";