import {z} from 'zod' export type GetApiMxvPhysicalDeliveryTransactionsArgs = {refConfirmationCode?: string | undefined, refPairingCode?: string | undefined, refRequestCode?: string | undefined, refTransactionDate?: string | undefined}; export type GetApiMxvPhysicalDeliveryTransactionsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const fireAntApiModelsMXVMXVPhysicalTransactionStatus = z.object({refTransactionDate: z.string().optional(), refRequestCode: z.string().optional(), refConfirmationCode: z.string().optional(), side: z.string().optional(), quantity: z.string().optional(), contract: z.string().optional(), deliveryCode: z.string().optional(), pairingCode: z.string().optional(), warehouse: z.string().optional(), fromDate: z.string().optional(), toDate: z.string().optional(), approveDate: z.string().optional(), approveTxnum: z.string().optional(), requestStatus: z.string().optional(), rejectReason: z.string().optional(), receivedByCCP: z.string().optional(), price: z.string().optional()}); export const getApiMxvPhysicalDeliveryTransactionsResponse = z.array(fireAntApiModelsMXVMXVPhysicalTransactionStatus); 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 }; /** * Truy vấn trạng thái nhận hàng vật chất tại kho * * GET /mxv/physical-delivery/transactions */ export const getApiMxvPhysicalDeliveryTransactions = async (args: GetApiMxvPhysicalDeliveryTransactionsArgs, options?: GetApiMxvPhysicalDeliveryTransactionsOptions) => { const {baseUrl = "https://api.fireant.vn", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.refConfirmationCode != null) query.append("refConfirmationCode", String(args.refConfirmationCode)) if (args.refPairingCode != null) query.append("refPairingCode", String(args.refPairingCode)) if (args.refRequestCode != null) query.append("refRequestCode", String(args.refRequestCode)) if (args.refTransactionDate != null) query.append("refTransactionDate", String(args.refTransactionDate)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/mxv/physical-delivery/transactions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiMxvPhysicalDeliveryTransactionsResponse, await res.json()) };