/** * What every product shares: one fetch, and the headers each request carries. * * The headers are asked for per request rather than fixed at construction, because the * `Authorization` a request carries is whoever is signed in at the moment it is sent, and * that changes under the client's feet (sign-in, refresh, sign-out). */ export type Fetch = typeof fetch; /** * Which names the client speaks on the wire. * * `new` (the default) is our own layout: `/v1/data`, `/v1/identity`, `/v1/files`, `/v1/live`, * `/v1/fn`, the key in a `Snout-Key` header, the auth server's new routes and fields, and the * `live:` realtime wire. `old` is the layout 0.3.x spoke (`/rest/v1`, `apikey`, ...), for a server * that has not been updated to accept the new names yet. Only the names differ: every request * means the same thing and every answer has the same shape either way. */ export type Vocabulary = 'new' | 'old'; /** The header a request carries the project key in. */ export declare function keyHeader(vocabulary: Vocabulary): string; /** Resolves the headers one request carries: the key, and the bearer of the moment. */ export type HeaderSource = () => Promise>; export interface Transport { fetch: Fetch; headers: HeaderSource; } /** Reads a body as JSON when it says it is JSON, as text otherwise, and never throws. */ export declare function readBody(response: Response): Promise; /** The first human sentence in an error body, whichever server and whichever shape wrote it. */ export declare function messageOf(body: unknown, fallback: string): string; /** `https://x` + `/a/b` with no doubled or missing slash. */ export declare function joinUrl(base: string, path: string): string; /** * An object path with each segment encoded and the slashes kept. * * A `.` or `..` segment is refused: the URL parser resolves it (encoded as `%2e` too) before * the request leaves, so a path another user chose could walk out of its product prefix and * send this user's token and body to another endpoint of the project. */ export declare function encodePath(path: string): string; /** One path segment that cannot be `.` or `..`, however it is spelled. */ export declare function checkSegment(segment: string, whole?: string): string; /** * A fetch that never carries the key or the bearer to another origin on a redirect. * * Fetch drops `Authorization` on a cross-origin hop but keeps a custom key header (`Snout-Key`, * or `apikey` in the old vocabulary), so a function (or anything else on the project) answering * `307 Location: https://elsewhere` would hand over the key, which on a server is the server key. * Here a redirect is followed by hand: within the request's own origin as fetch would, and to * another origin without those headers (a storage download redirected to a presigned URL needs * none of them). * * In a browser the key is the public app key and a manual redirect cannot be read, so the * platform's own following is kept. A caller that set `redirect` itself is left alone. */ export declare function guardRedirects(inner: Fetch): Fetch; export declare function isBrowser(): boolean;