import {z} from 'zod' export type TraitsV0 = {type: string, username?: string | undefined, primary_email_address?: string | undefined, secondary_email_address?: string | undefined, external_id?: string | undefined, family_name?: string | undefined, given_name?: string | undefined, formatted_name?: string | undefined, middle_name?: string | undefined, honorific_prefix?: string | undefined, honorific_suffix?: string | undefined, nick_name?: string | undefined, title?: string | undefined, primary_phone?: string | undefined, secondary_phone?: string | undefined, profile_url?: string | undefined, photo?: string | undefined, preferred_language?: string | undefined, locale?: string | undefined, timezone?: string | undefined, formatted_address?: string | undefined, street_address?: string | undefined, locality?: string | undefined, region?: string | undefined, postal_code?: string | undefined, country?: string | undefined, user_type?: string | undefined, employee_number?: string | undefined, cost_center?: string | undefined, organization?: string | undefined, division?: string | undefined, department?: string | undefined, manager_id?: string | undefined, manager_name?: string | undefined}; export type Identity = {id?: string | undefined, realm_id?: string | undefined, tenant_id?: string | undefined, display_name?: string | undefined, create_time?: string | undefined, update_time?: string | undefined, status?: string | undefined, traits?: TraitsV0 | undefined, enrollment_status?: ('ENROLLED' | 'PENDING' | 'INVITE_FAILED' | 'UNENROLLED') | undefined}; export type CreateApiV1TenantsTenantIdRealmsRealmIdIdentitiesArgs = {tenant_id: string, realm_id: string, body: {identity: Identity}}; export type CreateApiV1TenantsTenantIdRealmsRealmIdIdentitiesOptions = {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 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 }; /** * Create a New Identity * * POST /v1/tenants/{tenant_id}/realms/{realm_id}/identities */ export const createApiV1TenantsTenantIdRealmsRealmIdIdentities = async (args: CreateApiV1TenantsTenantIdRealmsRealmIdIdentitiesArgs, options?: CreateApiV1TenantsTenantIdRealmsRealmIdIdentitiesOptions) => { const {baseUrl = "https://api-us.beyondidentity.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "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(identity, await res.json()) };