import {z} from 'zod' export type Id = unknown; export type ListStringParametersBody = {items?: Array | undefined}; export type FilterType = 'MCC' | 'AMOUNT' | 'MERCHANT_COUNTRY' | 'CARDHOLDER_VERIFICATION' | 'CARD_ENTRY_MODE' | 'CARDHOLDER_PRESENT' | 'ACQUIRER_ID' | 'TRANSACTION_TYPE'; export type CountryCode = unknown; export type CountriesParameterBody = {items?: Array | undefined}; export type CardEntryMode = 'MANUAL_ENTRY' | 'MAGNETIC_STRIPE_READ' | 'CHIP_READ' | 'CONTACTLESS' | 'ELECTRONIC_COMMERCE'; export type CardEntryModeParametersBody = {items?: Array | undefined}; export type MccParametersBody = {items?: Array | undefined}; export type AmountParametersBody = {amount: unknown, shouldTriggerPartialApproval?: boolean | undefined}; export type CardholderPresentParametersBody = {cardholderPresent: boolean}; export type CardholderVerificationType = 'WALLET' | 'PIN' | 'BIO' | 'THREE_DS'; export type CardholderVerificationParametersBody = {items?: Array | undefined}; export type TransactionType = 'RETAIL' | 'CASH' | 'ATM' | 'CREDIT' | 'UNIQUE' | 'P2P_CREDIT' | 'P2P_DEBIT' | 'BALANCE_INQUIRY' | 'CASH_DISBURSEMENT'; export type TransactionTypeParametersBody = {items?: Array | undefined}; export type FilterCreateRequestBody = {parameters?: ListStringParametersBody | undefined, type: FilterType, reversed?: boolean | undefined} | {parameters?: CountriesParameterBody | undefined, type: FilterType, reversed?: boolean | undefined} | {parameters?: CardEntryModeParametersBody | undefined, type: FilterType, reversed?: boolean | undefined} | {parameters?: MccParametersBody | undefined, type: FilterType, reversed?: boolean | undefined} | {parameters?: AmountParametersBody | undefined, type: FilterType, reversed?: boolean | undefined} | {parameters?: CardholderPresentParametersBody | undefined, type: FilterType, reversed?: boolean | undefined} | {parameters?: CardholderVerificationParametersBody | undefined, type: FilterType, reversed?: boolean | undefined} | {parameters?: TransactionTypeParametersBody | undefined, type: FilterType, reversed?: boolean | undefined}; export type PatchApiV1FiltersFilterIdArgs = {'filter-id': Id, auditUser: string, body: FilterCreateRequestBody}; export type PatchApiV1FiltersFilterIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const id = z.string(); export const filterType = z.enum(["MCC", "AMOUNT", "MERCHANT_COUNTRY", "CARDHOLDER_VERIFICATION", "CARD_ENTRY_MODE", "CARDHOLDER_PRESENT", "ACQUIRER_ID", "TRANSACTION_TYPE"]); export const filterResponseBody = z.object({id: id.optional(), type: filterType.optional(), reversed: 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 Rule Filter * * PATCH /v1/filters/{filter-id} */ export const patchApiV1FiltersFilterId = async (args: PatchApiV1FiltersFilterIdArgs, options: PatchApiV1FiltersFilterIdOptions) => { 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.auditUser != null) query.append("auditUser", String(args.auditUser)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/filters/${encodeURIComponent(String(args['filter-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(filterResponseBody, await res.json()) };