UNPKG

@phala/cloud

Version:
126 lines 4.08 kB
import { z } from "zod"; import type { FetchError, FetchOptions, FetchRequest } from "ofetch"; /** * API Error Response Schema */ export declare const ApiErrorSchema: z.ZodObject<{ detail: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodObject<{ msg: z.ZodString; type: z.ZodOptional<z.ZodString>; ctx: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; }, "strip", z.ZodTypeAny, { msg: string; type?: string | undefined; ctx?: Record<string, unknown> | undefined; }, { msg: string; type?: string | undefined; ctx?: Record<string, unknown> | undefined; }>, "many">, z.ZodRecord<z.ZodString, z.ZodUnknown>]>; type: z.ZodOptional<z.ZodString>; code: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { detail: string | Record<string, unknown> | { msg: string; type?: string | undefined; ctx?: Record<string, unknown> | undefined; }[]; code?: string | undefined; type?: string | undefined; }, { detail: string | Record<string, unknown> | { msg: string; type?: string | undefined; ctx?: Record<string, unknown> | undefined; }[]; code?: string | undefined; type?: string | undefined; }>; export type ApiError = z.infer<typeof ApiErrorSchema>; /** * Enhanced error type that includes both HTTP and validation errors */ export type SafeError = RequestError | z.ZodError; /** * Result type for safe operations, similar to zod's SafeParseResult * Enhanced to handle both HTTP and validation errors by default */ export type SafeResult<T, E = SafeError> = { success: true; data: T; error?: never; } | { success: false; data?: never; error: E; }; /** * Base error class for HTTP requests * Compatible with ApiError interface for Result type compatibility */ export declare class RequestError extends Error implements ApiError { readonly name = "RequestError"; readonly isRequestError: true; readonly status?: number | undefined; readonly statusText?: string | undefined; readonly data?: unknown; readonly request?: FetchRequest | undefined; readonly response?: Response | undefined; readonly detail: string | Record<string, unknown> | Array<{ msg: string; type?: string; ctx?: Record<string, unknown>; }>; readonly code?: string | undefined; readonly type?: string | undefined; constructor(message: string, options?: { status?: number | undefined; statusText?: string | undefined; data?: unknown; request?: FetchRequest | undefined; response?: Response | undefined; cause?: unknown; detail?: string | Record<string, unknown> | Array<{ msg: string; type?: string; ctx?: Record<string, unknown>; }>; code?: string | undefined; type?: string | undefined; }); /** * Create RequestError from FetchError */ static fromFetchError(error: FetchError): RequestError; /** * Create RequestError from generic Error */ static fromError(error: Error, request?: FetchRequest): RequestError; } /** * Client configuration - extends FetchOptions and adds predefined API-specific options * * Environment Variables: * - PHALA_CLOUD_API_KEY: API key for authentication * - PHALA_CLOUD_API_PREFIX: Base URL prefix for the API */ export interface ClientConfig extends FetchOptions { /** * API key for authentication * If not provided, will read from PHALA_CLOUD_API_KEY environment variable */ apiKey?: string; /** * Base URL for the API (overrides FetchOptions baseURL) * If not provided, will read from PHALA_CLOUD_API_PREFIX environment variable * Defaults to "https://cloud-api.phala.network/v1" */ baseURL?: string; /** Default timeout in milliseconds (overrides FetchOptions timeout) */ timeout?: number; /** * API version to use */ version?: string; } //# sourceMappingURL=client.d.ts.map