import {z} from 'zod' export type UUID = string; export type GetApiApiV1OrgUsersUserUuidArgs = {userUuid: UUID}; export type GetApiApiV1OrgUsersUserUuidOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const userAvatarGradientId = z.enum(["lilac", "blush", "amethyst", "sunrise", "slate", "pearl"]); export const hexColor = z.string(); export const meshColor = z.string(); export const solidColor = z.string(); export const userAvatarColorValue = z.union([userAvatarGradientId, hexColor, meshColor, solidColor]); export const organizationMemberRole = z.enum(["member", "viewer", "interactive_viewer", "editor", "developer", "admin"]); export const organizationMemberProfile = z.object({avatarGradient: userAvatarColorValue.nullable(), avatarUrl: z.string().nullable(), isPending: z.boolean().optional(), isInviteExpired: z.boolean().optional(), isActive: z.boolean(), roleUuid: z.string().optional(), role: organizationMemberRole, organizationUuid: z.string(), email: z.string(), lastName: z.string(), firstName: z.string(), userUpdatedAt: z.string(), userCreatedAt: z.string(), userUuid: z.string()}); export const apiOrganizationMemberProfile = z.object({results: organizationMemberProfile, status: z.literal("ok")}); 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 organization member by UUID * * GET /api/v1/org/users/{userUuid} */ export const getApiApiV1OrgUsersUserUuid = async (args: GetApiApiV1OrgUsersUserUuidArgs, options: GetApiApiV1OrgUsersUserUuidOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/org/users/${encodeURIComponent(String(args.userUuid))}${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(apiOrganizationMemberProfile, await res.json()) };