import {z} from 'zod' export type ResourceServer = {id?: string | undefined, realm_id?: string | undefined, tenant_id?: string | undefined, display_name?: string | undefined, is_managed?: boolean | undefined, identifier?: string | undefined, scopes?: Array | undefined}; export type CreateApiV1TenantsTenantIdRealmsRealmIdResourceServersArgs = {tenant_id: string, realm_id: string, body: {resource_server: ResourceServer}}; export type CreateApiV1TenantsTenantIdRealmsRealmIdResourceServersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const resourceServer = z.object({id: z.string().optional(), realm_id: z.string().optional(), tenant_id: z.string().optional(), display_name: z.string().optional(), is_managed: z.boolean().optional(), identifier: z.string().optional(), scopes: z.array(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 Resource Server * * POST /v1/tenants/{tenant_id}/realms/{realm_id}/resource-servers */ export const createApiV1TenantsTenantIdRealmsRealmIdResourceServers = async (args: CreateApiV1TenantsTenantIdRealmsRealmIdResourceServersArgs, options?: CreateApiV1TenantsTenantIdRealmsRealmIdResourceServersOptions) => { 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))}/resource-servers${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(resourceServer, await res.json()) };