UNPKG

@turnkey/http

Version:

Typed HTTP client for interacting with Turnkey API

91 lines 2.91 kB
import { fetch } from "./universal"; import { TurnkeyCredentialRequestOptions } from "./webauthn"; import type { TurnkeyClient } from "."; export type { TurnkeyCredentialRequestOptions }; export { fetch }; type TBasicType = string; type TQueryShape = Record<string, TBasicType | Array<TBasicType>>; type THeadersShape = Record<string, TBasicType> | undefined; type TBodyShape = Record<string, any>; type TSubstitutionShape = Record<string, any>; /** * Represents a signed request ready to be POSTed to Turnkey * @deprecated use {@link TSignedRequest} instead */ export type SignedRequest = { body: string; stamp: string; url: string; }; /** * @deprecated */ export declare function signedRequest<B extends TBodyShape = never, Q extends TQueryShape = never, S extends TSubstitutionShape = never>(input: { uri: string; query?: Q; body?: B; substitution?: S; options?: TurnkeyCredentialRequestOptions | undefined; }): Promise<SignedRequest>; export declare function request<ResponseData = never, B extends TBodyShape = never, Q extends TQueryShape = never, S extends TSubstitutionShape = never, H extends THeadersShape = never>(input: { uri: string; method: "POST"; headers?: H; query?: Q; body?: B; substitution?: S; }): Promise<ResponseData>; /** * Seals and stamps the request body with your Turnkey API credentials. * * You can either: * - Before calling `sealAndStampRequestBody(...)`, initialize with your Turnkey API credentials via `init(...)` * - Or, provide `apiPublicKey` and `apiPrivateKey` here as arguments */ export declare function sealAndStampRequestBody(input: { body: Record<string, any>; apiPublicKey?: string; apiPrivateKey?: string; }): Promise<{ sealedBody: string; xStamp: string; }>; export declare function isHttpClient(client: any): client is TurnkeyClient; export type THttpConfig = { baseUrl: string; }; /** * Represents a signed request ready to be POSTed to Turnkey */ export type TSignedRequest = { body: string; stamp: TStamp; url: string; }; /** * Represents a stamp header name/value pair */ export type TStamp = { stampHeaderName: string; stampHeaderValue: string; }; export type GrpcStatus = { message: string; code: number; details: unknown[] | null; }; /** * Interface to implement if you want to provide your own stampers to your {@link TurnkeyClient}. * Currently Turnkey provides 2 stampers: * - applications signing requests with Passkeys or webauthn devices should use `@turnkey/webauthn-stamper` * - applications signing requests with API keys should use `@turnkey/api-key-stamper` */ export interface TStamper { stamp: (input: string) => Promise<TStamp>; } export declare class TurnkeyRequestError extends Error { details: any[] | null; code: number; constructor(input: GrpcStatus); } //# sourceMappingURL=base.d.ts.map