import {z} from 'zod' 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 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 Segment = 'SEGMENT_A' | 'SEGMENT_B' | 'SEGMENT_C' | 'SEGMENT_D' | 'SEGMENT_E' | 'SEGMENT_F'; export type PinDeliveryType = 'CUSTOM_1' | 'CUSTOM_2' | 'CUSTOM_3' | 'CUSTOM_4' | 'CUSTOM_5' | 'MAIL' | 'COURIER' | 'EPIN'; export type PinStatus = 'D' | 'W' | 'S'; export type PatchMultiApplicationResourceBody = {cardAddress?: UpdateAddress | undefined, cardDeliveryType?: CardDeliveryType | undefined, embossing?: Embossing | undefined, segment?: Segment | undefined, pinAddress?: UpdateAddress | undefined, pinDeliveryType?: PinDeliveryType | undefined, pinStatus?: PinStatus | undefined}; export type PatchApiV1MULTIAPPLICATIONCARDIdArgs = {auditUser: string, id: unknown, body: PatchMultiApplicationResourceBody}; export type PatchApiV1MULTIAPPLICATIONCARDIdOptions = {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 Multi-application card * * PATCH /v1/MULTI_APPLICATION_CARD/{id} */ export const patchApiV1MULTIAPPLICATIONCARDId = async (args: PatchApiV1MULTIAPPLICATIONCARDIdArgs, options: PatchApiV1MULTIAPPLICATIONCARDIdOptions) => { 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/MULTI_APPLICATION_CARD/${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()) };