@phala/cloud
Version:
TypeScript SDK for Phala Cloud API
87 lines • 3.66 kB
TypeScript
import { ofetch, type FetchOptions, type FetchRequest } from "ofetch";
import { type SafeResult, RequestError, type ClientConfig } from "./types/client";
export type { SafeResult } from "./types/client";
/**
* HTTP Client class with ofetch compatibility
*/
export declare class Client {
protected fetchInstance: typeof ofetch;
readonly config: ClientConfig;
constructor(config?: ClientConfig);
/**
* Get the underlying ofetch instance for advanced usage
*/
get raw(): import("ofetch").$Fetch;
/**
* Perform GET request (throws on error)
*/
get<T = unknown>(request: FetchRequest, options?: Omit<FetchOptions, "method">): Promise<T>;
/**
* Perform POST request (throws on error)
*/
post<T = unknown>(request: FetchRequest, body?: RequestInit["body"] | Record<string, unknown>, options?: Omit<FetchOptions, "method" | "body">): Promise<T>;
/**
* Perform PUT request (throws on error)
*/
put<T = unknown>(request: FetchRequest, body?: RequestInit["body"] | Record<string, unknown>, options?: Omit<FetchOptions, "method" | "body">): Promise<T>;
/**
* Perform PATCH request (throws on error)
*/
patch<T = unknown>(request: FetchRequest, body?: RequestInit["body"] | Record<string, unknown>, options?: Omit<FetchOptions, "method" | "body">): Promise<T>;
/**
* Perform DELETE request (throws on error)
*/
delete<T = unknown>(request: FetchRequest, options?: Omit<FetchOptions, "method">): Promise<T>;
/**
* Safe wrapper for any request method (zod-style result)
*/
private safeRequest;
/**
* Safe GET request (returns SafeResult)
*/
safeGet<T = unknown>(request: FetchRequest, options?: Omit<FetchOptions, "method">): Promise<SafeResult<T, RequestError>>;
/**
* Safe POST request (returns SafeResult)
*/
safePost<T = unknown>(request: FetchRequest, body?: RequestInit["body"] | Record<string, unknown>, options?: Omit<FetchOptions, "method" | "body">): Promise<SafeResult<T, RequestError>>;
/**
* Safe PUT request (returns SafeResult)
*/
safePut<T = unknown>(request: FetchRequest, body?: RequestInit["body"] | Record<string, unknown>, options?: Omit<FetchOptions, "method" | "body">): Promise<SafeResult<T, RequestError>>;
/**
* Safe PATCH request (returns SafeResult)
*/
safePatch<T = unknown>(request: FetchRequest, body?: RequestInit["body"] | Record<string, unknown>, options?: Omit<FetchOptions, "method" | "body">): Promise<SafeResult<T, RequestError>>;
/**
* Safe DELETE request (returns SafeResult)
*/
safeDelete<T = unknown>(request: FetchRequest, options?: Omit<FetchOptions, "method">): Promise<SafeResult<T, RequestError>>;
}
/**
* Create a new HTTP client instance
*
* Configuration can be provided via parameters or environment variables:
* - PHALA_CLOUD_API_KEY: API key for authentication
* - PHALA_CLOUD_API_PREFIX: Base URL prefix for the API
*
* Debug Logging:
* - Set DEBUG=phala::api-client to enable cURL-like request/response logging
* - This will print detailed information about each API call in a format similar to cURL
*
* @example
* ```typescript
* // Using explicit configuration
* const client = createClient({
* apiKey: 'your-api-key',
* baseURL: 'https://custom-api.example.com'
* })
*
* // Using environment variables (set PHALA_CLOUD_API_KEY)
* const client = createClient()
*
* // To enable debug logging:
* // DEBUG=phala::api-client node your-script.js
* ```
*/
export declare function createClient(config?: ClientConfig): Client;
//# sourceMappingURL=client.d.ts.map