import {z} from 'zod' export type GetApiApiUmbrellaV1UsersIdOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createdAt = z.string(); export const adminCreator = z.object({username: z.string().optional()}); export const updatedAt = z.string(); export const adminUpdater = z.object({username: z.string().optional()}); export const user = z.object({id: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional(), email: z.string().optional(), website: z.string().optional(), use_description: z.string().optional(), registration_source: z.string().optional(), throttle_by_ip: z.boolean().optional(), roles: z.string().optional(), enabled: z.string().optional(), api_key: z.string().optional(), api_key_hides_at: z.string().optional(), api_key_preview: z.string().optional(), email_verified: z.boolean().optional(), registration_ip: z.string().optional(), registration_user_agent: z.string().optional(), registration_referer: z.string().optional(), registration_origin: z.string().optional(), created_at: createdAt.optional(), creator: adminCreator.optional(), updated_at: updatedAt.optional(), updater: adminUpdater.optional()}); export const getApiApiUmbrellaV1UsersIdResponse = z.object({user: user.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get the API user/API key * * GET /api-umbrella/v1/users/{id} * * Also accepts auth: admin_auth_token */ export const getApiApiUmbrellaV1UsersId = async (options: GetApiApiUmbrellaV1UsersIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("X-Api-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api-umbrella/v1/users/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiUmbrellaV1UsersIdResponse, await res.json()) };