import {z} from 'zod' export type GetApiV1AdminUsersInviteOptions = {baseUrl?: string | undefined, AdminApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const userRole = z.enum(["A", "M", "B"]); export const staticOrganizationRoles = z.enum(["0d48f530-095c-43fe-8aea-6673bcacabe6", "c955f4e1-9477-43f0-8349-6fbc629fccc9", "7bde5959-d676-47d2-b779-35b64323d278"]); export const organizationUserInviteOUT = z.object({invite_uuid: z.string(), email: z.string().nullable(), roles: z.union([z.array(userRole), z.array(staticOrganizationRoles)]), role: z.union([userRole, staticOrganizationRoles])}); export const getApiV1AdminUsersInviteResponse = z.array(organizationUserInviteOUT); 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 Invite * * GET /v1/admin/users-invite */ export const getApiV1AdminUsersInvite = async (options?: GetApiV1AdminUsersInviteOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, AdminApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (AdminApiKey !== undefined) headers.set('authorization', `Bearer ${AdminApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/users-invite${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(getApiV1AdminUsersInviteResponse, await res.json()) };