import {z} from 'zod' export type PeakAPIsLibraryModelRequestContactsContactBankAccount = {bankId?: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37) | undefined, bankBranch?: string | undefined, bankAccountNo?: string | undefined, bankAccountName?: string | undefined}; export type CreateApiApiV1ContactsEditArgs = {'Time-Stamp': string, 'Time-Signature': string, 'User-Token': string, 'Client-Token': string, body: {PeakContacts: {id?: string | undefined, code?: string | undefined, contacts: {name: string, type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11, prefixNameType?: (0 | 1 | 2 | 3 | 4 | 5) | undefined, prefixNameOther?: string | undefined, taxNumber?: string | undefined, branchCode?: string | undefined, address?: string | undefined, subDistrict?: string | undefined, district?: string | undefined, province?: string | undefined, country?: string | undefined, postCode?: string | undefined, callCenterNumber?: string | undefined, faxNumber?: string | undefined, email?: string | undefined, website?: string | undefined, contactFirstName?: string | undefined, contactLastName?: string | undefined, contactNickName?: string | undefined, contactPosition?: string | undefined, contactPhoneNumber?: string | undefined, contactEmail?: string | undefined, purchaseAccount?: string | undefined, sellAccount?: string | undefined, bankAccount?: PeakAPIsLibraryModelRequestContactsContactBankAccount | undefined, id?: string | undefined, code: string, contactFinanceType?: (0 | 1 | 2) | undefined}}}}; export type CreateApiApiV1ContactsEditOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const peakWCFModelsAPIAPIContactsAPIContactBankAccountModel = z.object({bankId: z.number().int().optional(), bankBranch: z.string().optional(), bankAccountNo: z.string().optional(), bankAccountName: z.string().optional()}); export const peakWCFModelsAPIAPIContactsAPIContactsModel = z.object({resCode: z.string().optional(), resDesc: z.string().optional(), id: z.string().optional(), name: z.string().optional(), code: z.string().optional(), type: z.number().int().optional(), prefixNameType: z.number().int().optional(), prefixNameOther: z.string().optional(), taxNumber: z.string().optional(), branchCode: z.string().optional(), address: z.string().optional(), subDistrict: z.string().optional(), district: z.string().optional(), province: z.string().optional(), country: z.string().optional(), postCode: z.string().optional(), callcenterNumber: z.string().optional(), faxNumber: z.string().optional(), email: z.string().optional(), website: z.string().optional(), contactFirstName: z.string().optional(), contactLastName: z.string().optional(), contactNickName: z.string().optional(), contactPosition: z.string().optional(), contactPhoneNumber: z.string().optional(), contactEmail: z.string().optional(), purchaseAccount: z.string().optional(), sellAccount: z.string().optional(), contactFinanceType: z.number().int().optional(), bankAccount: peakWCFModelsAPIAPIContactsAPIContactBankAccountModel.optional()}); export const peakWCFModelsAPIBodyAPIBodyContact = z.object({contacts: z.array(peakWCFModelsAPIAPIContactsAPIContactsModel).optional(), totalContact: z.number().int().optional(), resDesc: z.string().optional(), resCode: z.string().optional()}); export const peakWCFModelsAPIResponseResponseContactModel = z.object({peakContacts: peakWCFModelsAPIBodyAPIBodyContact.optional(), eventType: z.string().optional(), apiType: 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 }; /** * Edit Contact * * POST /api/v1/Contacts/edit */ export const createApiApiV1ContactsEdit = async (args: CreateApiApiV1ContactsEditArgs, options?: CreateApiApiV1ContactsEditOptions) => { const {baseUrl = "https://api.peakaccount.com", 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['Time-Stamp'] != null) headers.set("Time-Stamp", String(args['Time-Stamp'])) if (args['Time-Signature'] != null) headers.set("Time-Signature", String(args['Time-Signature'])) if (args['User-Token'] != null) headers.set("User-Token", String(args['User-Token'])) if (args['Client-Token'] != null) headers.set("Client-Token", String(args['Client-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/Contacts/edit${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(peakWCFModelsAPIResponseResponseContactModel, await res.json()) };