import {z} from 'zod' export type GetApiV1AccountSsoProvidersArgs = {region?: number | undefined}; export type GetApiV1AccountSsoProvidersOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const accountV1SSOProviderInfo = z.object({enabled: z.boolean().optional(), id: z.string().optional(), name: z.string().optional(), region: z.number().int().optional(), slug: z.string().optional(), ssoType: z.string().optional()}); export const accountV1ListSSOProvidersReply = z.object({providers: z.array(accountV1SSOProviderInfo).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 }; /** * ListSSOProviders 列出指定区域的 SSO 提供商 * * GET /v1/account/sso/providers */ export const getApiV1AccountSsoProviders = async (args: GetApiV1AccountSsoProvidersArgs, options: GetApiV1AccountSsoProvidersOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.region != null) query.append("region", String(args.region)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/account/sso/providers${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(accountV1ListSSOProvidersReply, await res.json()) };