import {z} from 'zod' export type CreateApiV1TenantsTenantIdRealmsRealmIdBatchCredentialBindingJobsArgs = {tenant_id: string, realm_id: string, body: {batch_credential_binding_job: unknown}}; export type CreateApiV1TenantsTenantIdRealmsRealmIdBatchCredentialBindingJobsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1TenantsTenantIdRealmsRealmIdBatchCredentialBindingJobsResponse = z.object({id: z.string().optional(), tenant_id: z.string().min(1).optional(), realm_id: z.string().min(1).optional(), identity_ids: z.array(z.string().min(1)), state: z.string().optional(), state_commentary: z.object({errors: z.record(z.string(), z.object({last_error: z.string(), failed_permanently: z.boolean().optional()})).optional()}).optional(), create_time: z.string().optional(), update_time: z.string().optional(), job_template: z.object({post_binding_redirect_uri: z.string().optional(), authenticator_config: z.object({config: z.union([z.unknown(), z.unknown()]).optional()}).optional(), authenticator_config_id: z.string().optional(), expire_time: 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 }; /** * Create a New Batch Credential Binding Job * * POST /v1/tenants/{tenant_id}/realms/{realm_id}/batch-credential-binding-jobs */ export const createApiV1TenantsTenantIdRealmsRealmIdBatchCredentialBindingJobs = async (args: CreateApiV1TenantsTenantIdRealmsRealmIdBatchCredentialBindingJobsArgs, options?: CreateApiV1TenantsTenantIdRealmsRealmIdBatchCredentialBindingJobsOptions) => { 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))}/batch-credential-binding-jobs${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(createApiV1TenantsTenantIdRealmsRealmIdBatchCredentialBindingJobsResponse, await res.json()) };