import { LiteralUnion } from 'type-fest'; import { ZodType, z } from 'zod'; export { default as parseJson } from 'parse-json'; interface Logger { trace(message?: any, ...detail: any[]): void; debug(message?: any, ...detail: any[]): void; info(message?: any, ...detail: any[]): void; warn(message?: any, ...detail: any[]): void; error(message?: any, ...detail: any[]): void; } type RateLimitResult = { /** * The identifier used to uniquely track this rate limit. * * This will typically be the customer's ID or IP address. */ id: string; /** * Whether or not the request passed the rate limit. */ passed: boolean; /** * The interval in milliseconds over which the rate limit is enforced. */ intervalMs: number; /** * The maximum number of requests that can be made per interval. */ limit: number; /** * The current number of requests that have been made against the rate limit. */ current: number; /** * The number of requests that can be made before the rate limit resets. * * Will be `0` if the rate limit has been exceeded. */ remaining: number; /** * The time in milliseconds since the Unix epoch UTC at which the rate limit * will reset. */ resetTimeMs: number; }; declare class BaseError extends Error { constructor({ message, cause }: { message: string; cause?: unknown; }); } declare class HttpError extends BaseError { readonly statusCode: number; readonly headers?: Record; constructor({ message, statusCode, headers, cause }: { message: string; statusCode?: number; headers?: Record; cause?: unknown; }); } declare class RateLimitError extends HttpError { readonly rateLimitResult: RateLimitResult; constructor({ rateLimitResult, message, headers, cause }: { rateLimitResult: RateLimitResult; message?: string; headers?: Record; cause?: unknown; }); } declare class JsonRpcError extends HttpError { readonly jsonRpcErrorCode: number; readonly jsonRpcId: string | number | null; constructor({ message, jsonRpcErrorCode, jsonRpcId, statusCode, cause }: { message: string; jsonRpcErrorCode: number; jsonRpcId?: string | number | null; statusCode?: number; cause?: unknown; }); } declare class ZodValidationError extends HttpError { constructor({ statusCode, prefix, cause }: { statusCode?: number; prefix?: string; cause: unknown; }); } type Algorithm = LiteralUnion<'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512', string>; type HashObjectOptions = { /** @default 'SHA-256' */ readonly algorithm?: Algorithm; }; /** * Returns a stable, deterministic hash of the given object, defaulting to * using `sha256` as the hashing algorithm and `hex` as the encoding. */ declare function hashObject(object: Record): Promise; /** * @see https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-ratelimit-headers-06 */ declare function getRateLimitHeaders(rateLimitResult?: RateLimitResult): Record | undefined; /** * From `inputObj`, create a new object that does not include `keys`. * * @example * ```js * omit({ a: 1, b: 2, c: 3 }, 'a', 'c') // { b: 2 } * ``` */ declare const omit: | object, K extends keyof any>(inputObj: T, ...keys: K[]) => Omit; /** * From `inputObj`, create a new object that only includes `keys`. * * @example * ```js * pick({ a: 1, b: 2, c: 3 }, 'a', 'c') // { a: 1, c: 3 } * ``` */ declare const pick: | object, K extends keyof T>(inputObj: T, ...keys: K[]) => Pick; declare function assert(expr: unknown, message?: string): asserts expr; declare function assert(expr: unknown, statusCode?: number, message?: string): asserts expr; /** * Parses the given input against the given Zod schema, throwing a * `ZodValidationError` if the input is invalid. */ declare function parseZodSchema>(schema: TSchema, input: unknown, { error, statusCode }?: { error?: string; statusCode?: number; }): z.infer; declare function sha256(input?: string | ArrayBuffer | ArrayBufferView): Promise; declare function getEnv(name: string): string | undefined; /** * Creates a new `URLSearchParams` object with all values coerced to strings * that correctly handles arrays of values as repeated keys (or CSV) and * correctly removes `undefined` keys and values. */ declare function sanitizeSearchParams(searchParams?: Record | object, { csv }?: { /** * Whether to use comma-separated-values for arrays or multiple entries. * * Defaults to `false` and will use multiple entries. */ csv?: boolean; }): URLSearchParams; declare function pruneUndefined>(obj: T): NonNullable<{ [K in keyof T]: Exclude; }>; declare function pruneNullOrUndefined>(obj: T): NonNullable<{ [K in keyof T]: Exclude; }>; declare function pruneNullOrUndefinedDeep>(obj: T): NonNullable<{ [K in keyof T]: Exclude; }>; declare function pruneEmpty>(obj: T): NonNullable<{ [K in keyof T]: Exclude; }>; declare function pruneEmptyDeep(value?: T): undefined | (T extends Record ? { [K in keyof T]: Exclude; } : T extends Array ? Array> : Exclude); /** * Slugifies a string. * * - converts to lowercase * - decamelizes (fooBar -> foo-bar) * - replaces non-latin characters with latin equivalents (transliteration) * - replaces spaces with hyphens * - removes trailing hyphens * - removes leading hyphens * - removes multiple consecutive hyphens * - removes multiple consecutive spaces * * @see https://github.com/sindresorhus/slugify */ declare function slugify(input: string): string; export { type Algorithm, BaseError, type HashObjectOptions, HttpError, JsonRpcError, type Logger, RateLimitError, type RateLimitResult, ZodValidationError, assert, getEnv, getRateLimitHeaders, hashObject, omit, parseZodSchema, pick, pruneEmpty, pruneEmptyDeep, pruneNullOrUndefined, pruneNullOrUndefinedDeep, pruneUndefined, sanitizeSearchParams, sha256, slugify };