export type CreateUserKeyRequest = {name?: (string | null) | undefined, expiresInDays?: number | undefined}; export type CreateApiApiVVersionUsersKeysArgs = {version: string, body: CreateUserKeyRequest}; export type CreateApiApiVVersionUsersKeysOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Generate API Key * * POST /api/v{version}/users/keys */ export const createApiApiVVersionUsersKeys = async (args: CreateApiApiVVersionUsersKeysArgs, options?: CreateApiApiVVersionUsersKeysOptions) => { const {baseUrl = "https://api.zrexpress.app", fetch: fetchFn = fetch, bearerAuth, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) if (apiKey !== undefined) headers.set("X-Api-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v${encodeURIComponent(String(args.version))}/users/keys${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };