import {z} from 'zod' export type PeakAPIsLibraryModelRequestTransactionSharedNormalProductsTransaction = {id?: string | undefined, productId?: string | undefined, productCode?: string | undefined, description?: string | undefined, accountCode?: string | undefined, accountSubId?: string | undefined, accountSubCode?: string | undefined, quantity?: number | undefined, price?: number | undefined, discount?: string | undefined, vatType?: (1 | 2 | 3) | undefined, isDescription?: (0 | 1) | undefined, withHoldingTaxAmount?: string | undefined}; export type PeakAPIsLibraryModelRequestTransactionSharedNormalCurrencyTransaction = {currencyId?: (0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48) | undefined, exchangeRate?: number | undefined}; export type PeakAPIsLibraryModelRequestTransactionSharedNormalReceivedTaxInvoiceTransaction = {taxInvoiceNumber?: string | undefined, taxInvoiceDate?: string | undefined, journalDate?: string | undefined, periodDate?: string | undefined}; export type PeakAPIsLibraryModelRequestTransactionSharedPaidCredit = Record; export type CreateApiApiV1CreditNotesQueueArgs = {'Time-Stamp': string, 'Time-Signature': string, 'User-Token': string, 'Client-Token': string, body: {peakCreditNotes: {creditNotes: Array<{transactionType: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 201 | 202 | 205 | 206 | 207, transactionId?: string | undefined, transactionCode?: string | undefined, reasonType: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10, creditNoteStyleType?: (0 | 1) | undefined, reasonDescription: string, goodsReturn: 0 | 1, transactions: {code?: string | undefined, issuedDate: string, dueDate?: string | undefined, contactId?: string | undefined, contactCode?: string | undefined, reference?: string | undefined, remark?: string | undefined, taxStatus?: (0 | 1 | 2) | undefined, discountTotal?: string | undefined, isTaxInvoice?: (0 | 1) | undefined, tags?: Array | undefined, products: Array, paidPayments?: ({payments: Array<{cheque?: ({accountNo: string, branchNo?: string | undefined, chequeNo: string, amount: number, chequeDate: string, 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, paymentMethodId?: string | undefined, paymentMethodCode?: string | undefined}) | undefined, note?: string | undefined, isCheque?: (0 | 1) | undefined, amount: number, paymentMethodId?: string | undefined, paymentMethodCode?: string | undefined, accountCode?: string | undefined, accountSubId?: string | undefined, accountSubCode?: string | undefined}>, paymentDate: string, withHoldingTaxAmount?: string | undefined}) | undefined, status?: ('Draft' | 'Approve') | undefined, preTaxAmount?: number | undefined, vatAmount?: number | undefined, netAmount?: number | undefined, currency?: PeakAPIsLibraryModelRequestTransactionSharedNormalCurrencyTransaction | undefined, receivedTaxInvoice?: PeakAPIsLibraryModelRequestTransactionSharedNormalReceivedTaxInvoiceTransaction | undefined}, creditNotePayment: {paidCredits?: PeakAPIsLibraryModelRequestTransactionSharedPaidCredit | undefined, returnPayments: {payments: Array<{cheque?: ({accountNo: string, branchNo?: string | undefined, chequeNo: string, amount: number, chequeDate: string, 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, paymentMethodId?: string | undefined, paymentMethodCode?: string | undefined}) | undefined, note?: string | undefined, isCheque?: (0 | 1) | undefined, amount: number, paymentMethodId?: string | undefined, paymentMethodCode?: string | undefined, accountCode?: string | undefined, accountSubId?: string | undefined, accountSubCode?: string | undefined}>, paymentDate: string, withHoldingTaxAmount?: string | undefined}}}>, keyReference?: string | undefined, url?: string | undefined}}}; export type CreateApiApiV1CreditNotesQueueOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const peakAPIsLibraryModelResponseQueueResponseQueueModel = z.object({resCode: z.string().optional(), resDesc: z.string().optional(), queueId: 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 }; /** * Create Credit Note By Queue * * POST /api/v1/CreditNotes/queue */ export const createApiApiV1CreditNotesQueue = async (args: CreateApiApiV1CreditNotesQueueArgs, options?: CreateApiApiV1CreditNotesQueueOptions) => { 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/CreditNotes/queue${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(peakAPIsLibraryModelResponseQueueResponseQueueModel, await res.json()) };