UNPKG

haystack-nclient

Version:

Project Haystack Network Client

56 lines (55 loc) 1.92 kB
import { FetchMethod } from './fetchVal'; /** * Represents a CSRF error. */ export declare class CsrfError extends Error { /** * Used for a type guard check. */ readonly _isCsrfError = true; /** * HTTP response code. */ readonly status: number; constructor(response: Response, message?: string); } /** * A type guard for an CSRF error. * * @param value The value to check. * @returns The result of the type guard check. */ export declare function isCsrfError(value: unknown): value is CsrfError; /** * Clear any cached CSRF tokens. * * Calling this will force all CSRF tokens to be re-requested on subsequent network calls. */ export declare function clearFinCsrfTokens(): void; /** * Asynchronously return the CSRF token for the specified host. * * @param host The host. * @returns Resolves to the CSRF token or an empty string if it can't be found. */ export declare function getFinCsrfToken(host: string): Promise<string>; /** * An enhanced fetch API for CSRF token management with the FIN framework. * * Transparently handles CSRF token management (a.k.a. attest keys) and provides additional * features for working with haystack data. * * @link https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch * * @param resource The resource to request. * @param options Optional object containing any custom settings. * @param fetchFunc Optional fetch function to use instead of global fetch. * @returns A promise that resolves to a response object. */ export declare function finCsrfFetch(resource: RequestInfo, options?: RequestInit, fetchFunc?: FetchMethod): Promise<Response>; export interface CsrfRequestInit extends RequestInit { attestHeaderName?: string; attestRequestUri?: string; attestResponseHeaderName?: string; } export declare function isCsrfRequestInit(value?: RequestInit): value is CsrfRequestInit;