import {z} from 'zod' export type GetApiV1TenantsTenantIdRealmsRealmIdIdentitiesArgs = {tenant_id: string, realm_id: string, filter?: string | undefined, page_size?: number | undefined, page_token?: string | undefined, skip?: number | undefined}; export type GetApiV1TenantsTenantIdRealmsRealmIdIdentitiesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const traitsV0 = z.object({type: z.string(), username: z.string().min(1).max(64).optional(), primary_email_address: z.string().optional(), secondary_email_address: z.string().optional(), external_id: z.string().optional(), family_name: z.string().optional(), given_name: z.string().optional(), formatted_name: z.string().optional(), middle_name: z.string().optional(), honorific_prefix: z.string().optional(), honorific_suffix: z.string().optional(), nick_name: z.string().optional(), title: z.string().optional(), primary_phone: z.string().optional(), secondary_phone: z.string().optional(), profile_url: z.string().optional(), photo: z.string().optional(), preferred_language: z.string().optional(), locale: z.string().optional(), timezone: z.string().optional(), formatted_address: z.string().optional(), street_address: z.string().optional(), locality: z.string().optional(), region: z.string().optional(), postal_code: z.string().optional(), country: z.string().optional(), user_type: z.string().optional(), employee_number: z.string().optional(), cost_center: z.string().optional(), organization: z.string().optional(), division: z.string().optional(), department: z.string().optional(), manager_id: z.string().optional(), manager_name: z.string().optional()}); export const identity = z.object({id: z.string().optional(), realm_id: z.string().optional(), tenant_id: z.string().optional(), display_name: z.string().min(1).max(64).optional(), create_time: z.string().optional(), update_time: z.string().optional(), status: z.string().optional(), traits: traitsV0.optional(), enrollment_status: z.enum(["ENROLLED", "PENDING", "INVITE_FAILED", "UNENROLLED"]).optional()}); export const listIdentitiesResponse = z.object({identities: z.array(identity), total_size: z.number().int(), next_page_token: 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 }; /** * List Identities for a Realm * * GET /v1/tenants/{tenant_id}/realms/{realm_id}/identities */ export const getApiV1TenantsTenantIdRealmsRealmIdIdentities = async (args: GetApiV1TenantsTenantIdRealmsRealmIdIdentitiesArgs, options?: GetApiV1TenantsTenantIdRealmsRealmIdIdentitiesOptions) => { const {baseUrl = "https://api-us.beyondidentity.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", String(args.filter)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (args.skip != null) query.append("skip", String(args.skip)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tenants/${encodeURIComponent(String(args.tenant_id))}/realms/${encodeURIComponent(String(args.realm_id))}/identities${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(listIdentitiesResponse, await res.json()) };