import {z} from 'zod' export type GetApiUserProfileV1UsersIdArgs = {id: string, 'privacy-notice'?: string | undefined, 'x-ibm-dx-user-auth'?: string | undefined}; export type GetApiUserProfileV1UsersIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiUserProfileV1UsersIdResponse = z.object({id: z.string(), externalId: z.string().max(512), firstName: z.string().max(512).optional(), lastName: z.string().max(512).optional(), displayName: z.string().max(512).optional(), email: z.string().max(512).optional(), roles: z.array(z.enum(["authenticatedVisitor", "viewer", "editor", "manager", "admin"])), links: z.object({self: z.object({href: z.string(), methods: z.array(z.enum(["GET", "POST", "PUT", "DELETE"])), name: z.object({}).optional()})}).optional(), lastLogin: z.string().optional(), created: z.string().optional(), creator: z.object({id: z.string()}).optional(), lastModified: z.string().optional(), lastModifier: z.object({id: z.string()}).optional(), privacyNotice: z.object({version: z.string().min(1).max(20).optional(), accepted: z.string().optional(), locale: z.string().min(1).max(20).optional(), acceptRequired: z.boolean()}).optional()}).and(z.record(z.string(), z.unknown())); 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 }; /** * Find user by ID. * * GET /user-profile/v1/users/{id} */ export const getApiUserProfileV1UsersId = async (args: GetApiUserProfileV1UsersIdArgs, options: GetApiUserProfileV1UsersIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['privacy-notice'] != null) query.append("privacy-notice", String(args['privacy-notice'])) if (args['x-ibm-dx-user-auth'] != null) headers.set("x-ibm-dx-user-auth", String(args['x-ibm-dx-user-auth'])) const url = `${baseUrl.replace(/\/+$/, '')}/user-profile/v1/users/${encodeURIComponent(String(args.id))}${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(getApiUserProfileV1UsersIdResponse, await res.json()) };