UNPKG

@aptos-labs/aptos-client

Version:

Client package for accessing the Aptos network API.

73 lines 2.84 kB
/** * Shared utilities used by all entry points (Node, fetch, browser). * * @remarks * Extracted to a single module so that parsing, serialization, URL building, * and cookie logic stay consistent across runtimes. * * @internal * @module shared */ import type { AptosClientRequest, CookieJarLike } from "./types.js"; /** * Build a `URL` from a base string and optional query parameters. * `bigint` values are stringified automatically via `String()`. * @internal */ export declare function buildUrl(base: string, params?: AptosClientRequest["params"]): URL; /** * Serialize a request body to a `BodyInit`-compatible value. * * - `null` / `undefined` → `undefined` (no body sent) * - `Uint8Array` → passed through (valid `ArrayBufferView`/`BodyInit`) * - Anything else → `JSON.stringify` * * @internal */ export declare function serializeBody(body: unknown): BodyInit | undefined; /** * Set the `content-type` header to `application/json` when the body is * a non-binary, non-null value and no content-type has been set. * @internal */ export declare function applyJsonContentType(body: unknown, headers: Headers): void; /** * Parse a response body as JSON, returning the raw text when parsing fails. * * Returning raw text (instead of throwing) preserves backward compatibility * with v2, where `got` returned error responses as normal `AptosClientResponse` * objects. This lets the caller (e.g., the TS SDK) inspect the status code and * handle the error however it chooses. * * @internal */ export declare function parseJsonSafely(res: Response): Promise<any>; /** * Merge cookies from a {@link CookieJarLike} into the request headers. * @internal */ export declare function applyCookiesToHeaders(headers: Headers, url: URL, jar: CookieJarLike): void; /** * Store any `Set-Cookie` headers from the response in the cookie jar. * * Includes a defensive check for `Headers.getSetCookie()` availability, * since it may be absent in some React Native environments. * @internal */ export declare function storeResponseCookies(url: URL, headers: Headers, jar: CookieJarLike): void; /** * Convert a `Headers` instance to a plain `Record<string, string | string[]>`. * * This preserves backward compatibility with aptos-client v2, which * returned Node's `IncomingHttpHeaders` (a plain object) from the `got` * library. Consumers (e.g., the TS SDK) access headers via bracket * notation (`response.headers["x-aptos-cursor"]`), which only works on * plain objects — not on `Headers` instances. * * Multi-value `set-cookie` headers are returned as `string[]` to match * Node's `IncomingHttpHeaders` shape and avoid losing cookie boundaries. * * @internal */ export declare function headersToRecord(headers: Headers): Record<string, string | string[]>; //# sourceMappingURL=shared.d.ts.map