@phala/cloud
Version:
TypeScript SDK for Phala Cloud API
92 lines • 3.18 kB
TypeScript
import { z } from "zod";
import { type Client, type SafeResult } from "../client";
import { ActionParameters, ActionReturnType } from "../types/common";
/**
* Get current user information and validate API token
*
* Returns information about the current authenticated user.
*
* @example
* ```typescript
* import { createClient, getCurrentUser } from '@phala/cloud'
*
* const client = createClient({ apiKey: 'your-api-key' })
* const user = await getCurrentUser(client)
* // Output: { username: 'alice', email: 'alice@example.com', credits: 1000, ... }
* ```
*
* ## Returns
*
* `CurrentUser | unknown`
*
* Information about the current user. Return type depends on schema parameter.
*
* ## Parameters
*
* ### parameters (optional)
* - **Type:** `GetCurrentUserParameters`
*
* Optional behavior parameters for schema validation.
*
* ```typescript
* // Use default schema
* const user = await getCurrentUser(client)
*
* // Return raw data without validation
* const raw = await getCurrentUser(client, { schema: false })
*
* // Use custom schema
* const customSchema = z.object({ id: z.number(), name: z.string() })
* const custom = await getCurrentUser(client, { schema: customSchema })
* ```
*
* ## Safe Version
*
* Use `safeGetCurrentUser` for error handling without exceptions:
*
* ```typescript
* import { safeGetCurrentUser } from '@phala/cloud'
*
* const result = await safeGetCurrentUser(client)
* if (result.success) {
* console.log(result.data.username)
* } else {
* if ("isRequestError" in result.error) {
* console.error(`HTTP ${result.error.status}: ${result.error.message}`)
* } else {
* console.error(`Validation error: ${result.error.issues}`)
* }
* }
* ```
*/
export declare const CurrentUserSchema: z.ZodObject<{
username: z.ZodString;
email: z.ZodString;
credits: z.ZodNumber;
granted_credits: z.ZodNumber;
avatar: z.ZodString;
team_name: z.ZodString;
team_tier: z.ZodString;
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
username: z.ZodString;
email: z.ZodString;
credits: z.ZodNumber;
granted_credits: z.ZodNumber;
avatar: z.ZodString;
team_name: z.ZodString;
team_tier: z.ZodString;
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
username: z.ZodString;
email: z.ZodString;
credits: z.ZodNumber;
granted_credits: z.ZodNumber;
avatar: z.ZodString;
team_name: z.ZodString;
team_tier: z.ZodString;
}, z.ZodTypeAny, "passthrough">>;
export type CurrentUser = z.infer<typeof CurrentUserSchema>;
export type GetCurrentUserParameters<T = undefined> = ActionParameters<T>;
export type GetCurrentUserReturnType<T = undefined> = ActionReturnType<CurrentUser, T>;
export declare function getCurrentUser<T extends z.ZodSchema | false | undefined = undefined>(client: Client, parameters?: GetCurrentUserParameters<T>): Promise<GetCurrentUserReturnType<T>>;
export declare function safeGetCurrentUser<T extends z.ZodSchema | false | undefined = undefined>(client: Client, parameters?: GetCurrentUserParameters<T>): Promise<SafeResult<GetCurrentUserReturnType<T>>>;
//# sourceMappingURL=get_current_user.d.ts.map