conjure-lite
Advanced tools
Comparing version 0.0.4 to 0.0.5
export interface ConjureContext { | ||
fetchFn: typeof fetch; | ||
basePath: string; | ||
fetchFn?: typeof fetch; | ||
tokenProvider?: () => Promise<string>; | ||
baseUrl: string; | ||
servicePath: string; | ||
} |
import type { ConjureContext } from "./ConjureContext.js"; | ||
export declare function conjureFetch<T>({ fetchFn, basePath }: ConjureContext, url: string, method: string, body?: ArrayBuffer | Blob | FormData | URLSearchParams | null | string | {}, contentType?: "application/json" | "application/octet-stream", accept?: "application/json" | "application/octet-stream"): Promise<T>; | ||
export declare function conjureFetch<T>({ fetchFn, baseUrl, servicePath, tokenProvider }: ConjureContext, url: string, method: string, body?: ArrayBuffer | Blob | FormData | URLSearchParams | null | string | {}, contentType?: "application/json" | "application/octet-stream", accept?: "application/json" | "application/octet-stream"): Promise<T>; | ||
type ConjureErrorType = "NETWORK" | "OTHER" | "PARSE" | "STATUS"; | ||
@@ -4,0 +4,0 @@ export declare class ConjureError<E> { |
// This is the ONLY file that gets put into someones build. | ||
export async function conjureFetch({ fetchFn, basePath }, url, method, body, contentType, accept) { | ||
export async function conjureFetch({ fetchFn, baseUrl, servicePath, tokenProvider }, url, method, body, contentType, accept) { | ||
if (body) { | ||
@@ -12,3 +12,3 @@ if (body instanceof URLSearchParams || body instanceof Blob || body instanceof FormData | ||
} | ||
const response = await fetchFn(`${basePath}/${url}`, { | ||
const response = await (fetchFn ?? fetch)(`${baseUrl}${servicePath}${url}`, { | ||
method, | ||
@@ -20,2 +20,3 @@ credentials: "same-origin", | ||
accept: accept ?? "application/json", | ||
...(tokenProvider ? { "Authorization": `Bearer ${await tokenProvider()}` } : {}), | ||
}, | ||
@@ -22,0 +23,0 @@ ...(body ? { body } : {}), |
{ | ||
"name": "conjure-lite", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"exports": { | ||
@@ -5,0 +5,0 @@ ".": { |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
25020
559
1