import {z} from 'zod' export type UpdateApiDomainUsersIdArgs = {id: string, domain: string, body: {entitlements?: (Array<{value: string | null, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined, profileUrl?: (string | null) | undefined, schemas: unknown, nickname?: (string | null) | undefined, preferredLanguage?: (string | null) | undefined, ims?: (Array<{value: string | null, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined, timezone?: (string | null) | undefined, displayName?: (string | null) | undefined, userType?: (string | null) | undefined, name?: ({formatted?: (string | null) | undefined, familyName?: (string | null) | undefined, givenName?: (string | null) | undefined, middleName?: (string | null) | undefined, honorificPrefix?: (string | null) | undefined, honorificSuffix?: (string | null) | undefined}) | undefined, locale?: (string | null) | undefined, 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User'?: {[key: string]: unknown} | undefined, userName: string, addresses?: (Array<{primary?: boolean | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, formatted?: (string | null) | undefined, streetAddress?: (string | null) | undefined, locality?: (string | null) | undefined, region?: (string | null) | undefined, postalCode?: (string | null) | undefined, country?: (string | null) | undefined}>) | undefined, title?: (string | null) | undefined, password?: (string | null) | undefined, photos?: (Array<{value: string | null, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined, x509Certificates?: (Array<{value: string | null, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined, emails?: (Array<{value: string | null, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined, active?: boolean | undefined, phoneNumbers?: (Array<{value: string | null, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined, roles?: (Array<{value?: (string | null) | undefined, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | 'teamohana' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined, groups?: (Array<{value: string | null, primary?: boolean | undefined, display?: (string | null) | undefined, type?: ('' | 'home' | 'work' | 'other' | null) | undefined, $ref?: (string | null) | undefined}>) | undefined}}; export type UpdateApiDomainUsersIdOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiDomainUsersIdResponse = z.object({entitlements: z.array(z.object({value: z.string().nullable(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), profileUrl: z.string().nullable().optional(), schemas: z.unknown(), nickname: z.string().nullable().optional(), preferredLanguage: z.string().nullable().optional(), ims: z.array(z.object({value: z.string().nullable(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), timezone: z.string().nullable().optional(), displayName: z.string().nullable().optional(), id: z.string(), userType: z.string().nullable().optional(), name: z.object({formatted: z.string().nullable().optional(), familyName: z.string().nullable().optional(), givenName: z.string().nullable().optional(), middleName: z.string().nullable().optional(), honorificPrefix: z.string().nullable().optional(), honorificSuffix: z.string().nullable().optional()}).optional(), locale: z.string().nullable().optional(), "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User": z.record(z.string(), z.unknown()).optional(), userName: z.string(), addresses: z.array(z.object({primary: z.boolean().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), formatted: z.string().nullable().optional(), streetAddress: z.string().nullable().optional(), locality: z.string().nullable().optional(), region: z.string().nullable().optional(), postalCode: z.string().nullable().optional(), country: z.string().nullable().optional()})).optional(), title: z.string().nullable().optional(), meta: z.object({resourceType: z.literal("user"), created: z.string(), lastModified: z.string(), location: z.string(), version: z.string()}), password: z.string().nullable().optional(), photos: z.array(z.object({value: z.string().nullable(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), x509Certificates: z.array(z.object({value: z.string().nullable(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), emails: z.array(z.object({value: z.string().nullable(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), active: z.boolean().optional(), phoneNumbers: z.array(z.object({value: z.string().nullable(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), roles: z.array(z.object({value: z.string().nullable().optional(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other", "teamohana"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), groups: z.array(z.object({value: z.string().nullable(), primary: z.boolean().optional(), display: z.string().nullable().optional(), type: z.enum(["", "home", "work", "other"]).nullable().optional(), $ref: z.string().nullable().optional()})).optional(), externalId: z.string().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 }; /** * Update a user * * PUT /{domain}/Users/{id} */ export const updateApiDomainUsersId = async (args: UpdateApiDomainUsersIdArgs, options: UpdateApiDomainUsersIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.domain))}/Users/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiDomainUsersIdResponse, await res.json()) };