import {z} from 'zod' export type SsoConfigType = 'bookmark' | 'entra_id_external_auth_methods' | 'generic_oidc' | 'generic_oidc_idp' | 'generic_saml' | 'okta_idp' | 'okta_sso_bi_idp' | 'scim' | 'ws_fed' | 'nametag_oauth2'; export type GetApiV1TenantsTenantIdRealmsRealmIdSsoConfigsArgs = {'x-correlation_id': string, tenant_id: string, realm_id: string, page_size?: number | undefined, page_token?: string | undefined, type?: Array | undefined, is_migrated?: boolean | undefined, order_by?: string | undefined}; export type GetApiV1TenantsTenantIdRealmsRealmIdSsoConfigsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const ssoConfigType = z.enum(["bookmark", "entra_id_external_auth_methods", "generic_oidc", "generic_oidc_idp", "generic_saml", "okta_idp", "okta_sso_bi_idp", "scim", "ws_fed", "nametag_oauth2"]); export const getApiV1TenantsTenantIdRealmsRealmIdSsoConfigsResponse = z.object({sso_configs: z.array(z.object({id: z.string(), display_name: z.string(), payload: z.union([z.object({type: ssoConfigType, login_link: z.string(), icon: z.string().optional(), is_tile_visible: z.boolean().optional()}), z.object({type: ssoConfigType, redirect_uris: z.array(z.string()), discover_endpoint: z.unknown()}), z.object({type: ssoConfigType, redirect_uris: z.array(z.string()), login_link: z.string().optional(), icon: z.string().optional(), is_tile_visible: z.boolean().optional()}), z.object({type: ssoConfigType}), z.object({type: ssoConfigType, icon: z.string().optional(), is_tile_visible: z.boolean().optional()}), z.object({type: ssoConfigType}), z.object({type: ssoConfigType}), z.object({type: ssoConfigType}), z.object({type: ssoConfigType, company_identifier: z.string()}), z.unknown(), z.object({type: ssoConfigType, icon: z.string().optional(), is_tile_visible: z.boolean().optional()})])})), total_size: z.number().int().gte(0), next_page_token: z.string().nullable().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 SSO Configs for a Realm. * * GET /v1/tenants/{tenant_id}/realms/{realm_id}/sso-configs */ export const getApiV1TenantsTenantIdRealmsRealmIdSsoConfigs = async (args: GetApiV1TenantsTenantIdRealmsRealmIdSsoConfigsArgs, options?: GetApiV1TenantsTenantIdRealmsRealmIdSsoConfigsOptions) => { 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['x-correlation_id'] != null) headers.set("x-correlation_id", String(args['x-correlation_id'])) 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)) for (const item of args.type ?? []) query.append("type", String(item)) if (args.is_migrated != null) query.append("is_migrated", String(args.is_migrated)) if (args.order_by != null) query.append("order_by", String(args.order_by)) 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))}/sso-configs${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(getApiV1TenantsTenantIdRealmsRealmIdSsoConfigsResponse, await res.json()) };