import {z} from 'zod' export type MarketCode = string; export type GetApiPaymentsV2RegulatoryReportingCodesArgs = {market: MarketCode, limit?: number | undefined, token?: string | undefined}; export type GetApiPaymentsV2RegulatoryReportingCodesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const marketCode = z.string().min(2).max(2); export const creditTransferSchemeType = z.enum(["SCT", "SCT_INST", "CROSS_BORDER", "GB_CT_BACS", "GB_CT_CHAPS", "GB_CT_FPS", "SE_A2A", "SE_GIRO", "DK_A2A", "DK_CT_SAMEDAY", "DK_CT_INST", "DK_CT_FIK71", "DK_CT_FIK73", "DK_CT_FIK75", "DK_CT_NEMKONTO", "DK_CT_T2", "CH_CT", "NO_CT", "NO_CT_KID", "US_CT_ACH", "US_CT_WIRE", "IS_CT", "AU_CT", "AU_CT_BECS", "AU_CT_BPAY", "HK_CT", "HK_CT_CHATS", "HK_CT_FPS", "IL_CT", "SG_CT", "SG_CT_FAST", "SG_CT_GIRO", "SG_CT_MEPS", "BG_CT", "CL_CT", "CO_CT", "CR_CT", "CZ_CT", "MX_CT", "MX_CT_SPID", "MX_CT_SPEI", "MX_CT_TEF", "MY_CT_IBG", "MY_CT_JOMPAY", "MY_CT_RENTAS", "KR_CT", "TW_CT_ACH", "TW_CT_FISC", "TH_CT", "TH_CT_BAHTNET", "TH_CT_SMART", "CA_CT_LYNX", "CA_CT_ACSS", "PE_CT", "PL_CT", "RO_CT", "TR_CT", "AE_CT", "AE_CT_IPI", "DE_CT", "FR_CT", "IN_IMPS", "IN_NEFT", "IN_RTGS", "BR_CT_PIX", "BR_CT_TED", "BOOK_TRANSFER", "CN_CT_BEPS", "CN_CT_HVPS", "VN_CT", "PH_CT_PESONET", "PH_CT_INSTAPAY", "PH_CT_PHILPASS", "PH_CT_PDDTS", "RS_CT", "JP_CT", "MU_CT", "KE_CT_RTGS", "GE_CT_RTGS", "ZA_CT_EFT", "BD_CT_BEFTN", "BD_CT_RTGS", "MA_CT", "SA_CT_SARIE", "HU_CT_VIBER", "HU_CT_GIRO"]); export const regulatoryReportingIndicator = z.enum(["CREDITOR", "DEBTOR", "BOTH"]); export const regulatoryReportingCode = z.object({market: marketCode, scheme: creditTransferSchemeType.optional(), indicator: regulatoryReportingIndicator, code: z.string(), title: z.string(), classification: z.string()}); export const getApiPaymentsV2RegulatoryReportingCodesResponse = z.object({items: z.array(regulatoryReportingCode), nextToken: z.string(), token: z.string(), limit: z.number().int()}); 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 regulatory reporting codes * * GET /payments/v2/regulatory-reporting-codes */ export const getApiPaymentsV2RegulatoryReportingCodes = async (args: GetApiPaymentsV2RegulatoryReportingCodesArgs, options?: GetApiPaymentsV2RegulatoryReportingCodesOptions) => { const {baseUrl = "https://api.atlar.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.market != null) query.append("market", String(args.market)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.token != null) query.append("token", String(args.token)) const url = `${baseUrl.replace(/\/+$/, '')}/payments/v2/regulatory-reporting-codes${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(getApiPaymentsV2RegulatoryReportingCodesResponse, await res.json()) };