import {z} from 'zod' export type IdentityProviderSchema = {date_created?: string | undefined, date_modified?: string | undefined, id?: string | undefined, public_id?: string | undefined, saml_settings?: Record | undefined, settings: Record, type: 'onelogin.com' | 'auth0.com' | 'okta.com' | 'GENERIC', verbose_logging?: boolean | undefined}; export type PatchApiV1AuthSamlIdpIdentityProviderIdArgs = {'App-ID': string, 'Auth-Token': string, identity_provider_id: string, body: IdentityProviderSchema}; export type PatchApiV1AuthSamlIdpIdentityProviderIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const identityProviderSchema = z.object({date_created: z.string().optional(), date_modified: z.string().optional(), id: z.string().optional(), public_id: z.string().optional(), saml_settings: z.object({}).optional(), settings: z.object({}), type: z.enum(["onelogin.com", "auth0.com", "okta.com", "GENERIC"]), verbose_logging: z.boolean().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 }; /** * Update a particular identity provider by id * * PATCH /v1/auth/saml/idp/{identity_provider_id}/ */ export const patchApiV1AuthSamlIdpIdentityProviderId = async (args: PatchApiV1AuthSamlIdpIdentityProviderIdArgs, options: PatchApiV1AuthSamlIdpIdentityProviderIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/auth/saml/idp/${encodeURIComponent(String(args.identity_provider_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(identityProviderSchema, await res.json()) };