import {z} from 'zod' export type UserRole = 'A' | 'M' | 'B'; export type StaticOrganizationRoles = '0d48f530-095c-43fe-8aea-6673bcacabe6' | 'c955f4e1-9477-43f0-8349-6fbc629fccc9' | '7bde5959-d676-47d2-b779-35b64323d278'; export type PlanType = 'API' | 'CHAT' | 'ON_PREMISE' | 'LICENSE' | 'MISTRAL_CODE'; export type OrganizationMemberCreate = {role_names?: (Array<'member' | 'billing_manager' | 'organization_admin'> | null) | undefined, roles?: (Array | Array | null) | undefined, role_name?: ('member' | 'billing_manager' | 'organization_admin' | null) | undefined, role?: (UserRole | StaticOrganizationRoles | null) | undefined, email: string, first_name: string, last_name: string, subscription_types?: (Array | null) | undefined}; export type CreateApiV1AdminUsersArgs = {body: Array}; export type CreateApiV1AdminUsersOptions = {baseUrl?: string | undefined, AdminApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationUsersCreateOUT = z.object({invalid_emails: z.array(z.string()), email_to_user_id: z.record(z.string(), z.string())}); 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 }; /** * Create Users * * POST /v1/admin/users */ export const createApiV1AdminUsers = async (args: CreateApiV1AdminUsersArgs, options?: CreateApiV1AdminUsersOptions) => { const {baseUrl = "https://api.mistral.ai", fetch: fetchFn = fetch, AdminApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AdminApiKey !== undefined) headers.set('authorization', `Bearer ${AdminApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/users${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 validateResponse(organizationUsersCreateOUT, await res.json()) };