import {z} from 'zod' export type CreateApiUserIdentitiesGetArgs = {body: {user_identity_id: string} | {user_identity_key: string}}; export type CreateApiUserIdentitiesGetOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const userIdentity = z.object({acs_user_ids: z.array(z.string()), created_at: z.string(), display_name: z.string().min(1), email_address: z.string().nullable(), errors: z.array(z.object({acs_system_id: z.string(), acs_user_id: z.string(), created_at: z.string(), error_code: z.literal("issue_with_acs_user"), message: z.string()})), full_name: z.string().min(1).nullable(), phone_number: z.string().nullable(), user_identity_id: z.string(), user_identity_key: z.string().min(1).nullable(), warnings: z.array(z.discriminatedUnion("warning_code", [z.object({created_at: z.string(), message: z.string(), warning_code: z.literal("being_deleted")}), z.object({created_at: z.string(), message: z.string(), warning_code: z.literal("acs_user_profile_does_not_match_user_identity")})])), workspace_id: z.string()}); export const createApiUserIdentitiesGetResponse = z.object({user_identity: userIdentity}); 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 a User Identity * * POST /user_identities/get * * Also accepts auth: pat_with_workspace, console_session_with_workspace, client_session_with_customer */ export const createApiUserIdentitiesGet = async (args: CreateApiUserIdentitiesGetArgs, options?: CreateApiUserIdentitiesGetOptions) => { const {baseUrl = "https://connect.getseam.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/user_identities/get${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(createApiUserIdentitiesGetResponse, await res.json()) };