import {z} from 'zod' export type KeyValuePair = {key: string, value: string}; export type AdditionalValues = Array; export type DigitalLayoutCode = string; export type AccountId = string; export type ProductCode = string; export type CreateApplication = {applicationName: string, enabled: boolean, additionalValues?: AdditionalValues | undefined, printed?: boolean | undefined, contactPriorityLevel: number, contactlessPriorityLevel: number, digitalLayoutCode?: DigitalLayoutCode | undefined, accountId: AccountId, productCode: ProductCode}; export type CreateApplicationWithEncryptedData = {applicationName: string, enabled: boolean, additionalValues?: AdditionalValues | undefined, printed?: boolean | undefined, contactPriorityLevel: number, contactlessPriorityLevel: number, digitalLayoutCode?: DigitalLayoutCode | undefined, accountId: AccountId, productCode: ProductCode, encryptedData?: string | undefined}; export type Country = string; export type Address = {address1: string, address2?: string | undefined, address3?: string | undefined, address4?: string | undefined, city: string, country: Country, region?: string | undefined, zipCode: 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 Expiration = {year?: number | undefined, month?: number | undefined}; export type Segment = 'SEGMENT_A' | 'SEGMENT_B' | 'SEGMENT_C' | 'SEGMENT_D' | 'SEGMENT_E' | 'SEGMENT_F'; export type PinStatus = 'D' | 'W' | 'S'; export type CreateMultiApplicationCardResourceBody = {mainApplication: CreateApplication, applications: Array, cardAddress?: Address | undefined, embossing?: Embossing | undefined, expiration?: Expiration | undefined, segment?: Segment | undefined, pinAddress?: Address | undefined, pinStatus?: PinStatus | undefined}; export type CreateApiV1MULTIAPPLICATIONCARDCustomerCustomerIdArgs = {customerId: unknown, auditUser: string, body: CreateMultiApplicationCardResourceBody}; export type CreateApiV1MULTIAPPLICATIONCARDCustomerCustomerIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const multipleResourceResponse = z.object({description: z.string().optional(), mainId: z.string(), applications: z.array(z.object({id: z.string(), accountId: z.string()}))}); 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 }; /** * Create a Multi-application card * * POST /v1/MULTI_APPLICATION_CARD/customer/{customerId} */ export const createApiV1MULTIAPPLICATIONCARDCustomerCustomerId = async (args: CreateApiV1MULTIAPPLICATIONCARDCustomerCustomerIdArgs, options: CreateApiV1MULTIAPPLICATIONCARDCustomerCustomerIdOptions) => { 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/customer/${encodeURIComponent(String(args.customerId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(multipleResourceResponse, await res.json()) };