import {z} from 'zod' export type GetApiVerificationSchemeParticipantsParticipantBicArgs = {participant_bic: string}; export type GetApiVerificationSchemeParticipantsParticipantBicOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const verificationSchemeParticipantOperationalContact = z.object({email: z.string()}); export const verificationSchemeParticipantSchemeUri = z.object({environment: z.enum(["L", "T"]), operation: z.string(), api_uri: z.string(), api_version: z.number().int(), priority_number: z.number().int(), account_holding_bics: z.array(z.string()), start_date_time: z.string(), end_date_time: z.string().optional(), note: z.string().optional()}); export const verificationSchemeParticipantSchemeRole = z.object({code: z.string()}); export const verificationSchemeParticipantSchemeOption = z.object({code: z.string(), readiness_date: z.string(), leaving_date: z.string().optional()}); export const verificationSchemeParticipantScheme = z.object({code: z.string(), uris: z.array(verificationSchemeParticipantSchemeUri), roles: z.array(verificationSchemeParticipantSchemeRole), options: z.array(verificationSchemeParticipantSchemeOption), readiness_date: z.string(), leaving_date: z.string().optional()}); export const verificationSchemeParticipantDetails = z.object({participant_bic: z.string(), participant_name: z.string(), country_code: z.string(), psd2_nans: z.array(z.string()), operational_contacts: z.array(verificationSchemeParticipantOperationalContact), schemes: z.array(verificationSchemeParticipantScheme)}); 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 }; /** * Retrieve verification scheme participant * * GET /verification_scheme_participants/{participant_bic} */ export const getApiVerificationSchemeParticipantsParticipantBic = async (args: GetApiVerificationSchemeParticipantsParticipantBicArgs, options?: GetApiVerificationSchemeParticipantsParticipantBicOptions) => { const {baseUrl = "https://sandbox.numeral.io/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/verification_scheme_participants/${encodeURIComponent(String(args.participant_bic))}${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(verificationSchemeParticipantDetails, await res.json()) };