import {z} from 'zod' export type AccountId = string; export type CustomerId = string; export type Embossing = {additionalField1?: string | undefined, additionalField2?: string | undefined, additionalField3?: string | undefined, additionalField4?: string | undefined, additionalField5?: string | undefined, companyName?: string | undefined, externalLayoutCode?: string | undefined, firstName?: string | undefined, lastName?: string | undefined, additionalEmbossingName?: string | undefined, manufacturer?: string | undefined, physical?: boolean | undefined}; export type Reason = string; export type Segment = 'SEGMENT_A' | 'SEGMENT_B' | 'SEGMENT_C' | 'SEGMENT_D' | 'SEGMENT_E' | 'SEGMENT_F'; export type CardStatusPatch = 'CARD_OK' | 'CARD_BLOCKED' | 'SUSPECTED_FRAUD' | 'CARD_CLOSED_DUE_TO_FRAUD' | 'CARD_NO_RENEWAL' | 'CARD_LOST' | 'CARD_STOLEN' | 'CARD_CLOSED'; export type LimitValues = {code?: ('ATM' | 'RETAIL' | 'ALL') | undefined, reset?: boolean | undefined, singleAmount?: number | undefined, count?: number | undefined, sumAmount?: number | undefined}; export type UsageLimit = {code?: ('24H' | 'DAILY' | 'MONTHLY' | 'WEEKLY' | 'ANNUAL_YEARLY' | 'ROLLING_YEARLY') | undefined, values?: Array | undefined}; export type PinStatus = 'D' | 'W' | 'S'; export type DigitalLayoutCode = string; export type ScheduledClosingType = 'TIMEBASED'; export type ScheduledClosingTime = string; export type ScheduledClosing = {type?: ScheduledClosingType | undefined, time?: ScheduledClosingTime | undefined}; export type KeyValuePair = {key: string, value: string}; export type AdditionalValues = Array; export type Country = string; export type UpdateAddress = {address1?: string | undefined, address2?: string | undefined, address3?: string | undefined, address4?: string | undefined, city?: string | undefined, country?: Country | undefined, region?: string | undefined, zipCode?: string | undefined}; export type CardDeliveryType = 'CUSTOM_1' | 'CUSTOM_2' | 'CUSTOM_3' | 'CUSTOM_4' | 'CUSTOM_5' | 'MAIL' | 'COURIER'; export type PinDeliveryType = 'CUSTOM_1' | 'CUSTOM_2' | 'CUSTOM_3' | 'CUSTOM_4' | 'CUSTOM_5' | 'MAIL' | 'COURIER' | 'EPIN'; export type RegionAndEcommBlocking = {ecomm?: boolean | undefined, africa?: boolean | undefined, asia?: boolean | undefined, europe?: boolean | undefined, home?: boolean | undefined, northAmerica?: boolean | undefined, oceania?: boolean | undefined, southAmerica?: boolean | undefined}; export type CardUsageBlocks = {cardPresent?: boolean | undefined, atmCashDisbursement?: boolean | undefined}; export type PatchStandardResourceBody = {accountId?: AccountId | undefined, customerId?: CustomerId | undefined, embossing?: Embossing | undefined, reason?: Reason | undefined, segment?: Segment | undefined, status?: CardStatusPatch | undefined, usageLimits?: Array | undefined, pinStatus?: PinStatus | undefined, digitalLayoutCode?: DigitalLayoutCode | undefined, scheduledClosing?: ScheduledClosing | undefined, additionalValues?: AdditionalValues | undefined, cardAddress?: UpdateAddress | undefined, cardDeliveryType?: CardDeliveryType | undefined, pinAddress?: UpdateAddress | undefined, pinDeliveryType?: PinDeliveryType | undefined, regionAndEcommBlocking?: RegionAndEcommBlocking | undefined, cardUsageBlocks?: CardUsageBlocks | undefined}; export type PatchApiV4DEBITMCIdArgs = {auditUser: string, id: unknown, body: PatchStandardResourceBody}; export type PatchApiV4DEBITMCIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const resourceResponse = z.object({description: z.string().optional(), id: 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 }; /** * Update a debit Mastercard branded card * * PATCH /v4/DEBIT_MC/{id} */ export const patchApiV4DEBITMCId = async (args: PatchApiV4DEBITMCIdArgs, options: PatchApiV4DEBITMCIdOptions) => { 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(/\/+$/, '')}/v4/DEBIT_MC/${encodeURIComponent(String(args.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(resourceResponse, await res.json()) };