import {z} from 'zod' export type Search = {fields?: (Array | null) | undefined, keyword?: (string | null) | undefined}; export type Filter = {logic?: (string | null) | undefined, filters?: (Array | null) | undefined, field?: (string | null) | undefined, operator?: (string | null) | undefined, value: unknown}; export type SearchSupplierPaymentsCurrentSupplierRequest = {advancedSearch?: Search | undefined, keyword?: (string | null) | undefined, advancedFilter?: Filter | undefined, pageSize?: number | undefined, pageNumber?: number | undefined, orderBy?: (Array | null) | undefined}; export type CreateApiApiVVersionSupplierPaymentSearchArgs = {version: string, 'X-Tenant': string, body: SearchSupplierPaymentsCurrentSupplierRequest}; export type CreateApiApiVVersionSupplierPaymentSearchOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const coordinates = z.object({lat: z.number().nullable().optional(), lng: z.number().nullable().optional()}); export const addressDto = z.object({street: z.string().nullable().optional(), city: z.string().nullable().optional(), cityTerritoryId: z.string().optional(), district: z.string().nullable().optional(), districtTerritoryId: z.string().optional(), postalCode: z.string().nullable().optional(), country: z.string().nullable().optional(), coordinates: coordinates.optional()}); export const phoneDto = z.object({number1: z.string().nullable().optional(), number2: z.string().nullable().optional(), number3: z.string().nullable().optional()}); export const treasurySupplierOwnerDto = z.object({firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional()}); export const supplierLegalInformationDto = z.object({rc: z.string().nullable().optional(), nif: z.string().nullable().optional(), ai: z.string().nullable().optional(), nis: z.string().nullable().optional()}); export const treasurySupplierResponse = z.object({id: z.string().optional(), name: z.string().nullable().optional(), tenantId: z.string().nullable().optional(), address: addressDto.optional(), paymentDays: z.array(z.string()).nullable().optional(), phone: phoneDto.optional(), owner: treasurySupplierOwnerDto.optional(), legalInformation: supplierLegalInformationDto.optional()}); export const cashDrawerUserResponse = z.object({id: z.string().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional()}); export const treasuryHubResponse = z.object({id: z.string().optional(), name: z.string().nullable().optional(), type: z.string().nullable().optional(), address: addressDto.optional()}); export const cashDrawerResponse = z.object({id: z.string().optional(), cashDrawerUser: cashDrawerUserResponse.optional(), amount: z.number().optional(), isActive: z.boolean().optional(), hub: treasuryHubResponse.optional()}); export const supplierPaymentResponse = z.object({id: z.string().optional(), supplier: treasurySupplierResponse.optional(), amount: z.number().optional(), totalParcelsDelivered: z.number().int().optional(), totalParcelsCancelled: z.number().int().optional(), totalRefundsCredited: z.number().int().optional(), totalRefundsDebited: z.number().int().optional(), totalItemLabeling: z.number().int().optional(), labelingAmount: z.number().optional(), storage: z.number().optional(), createdAt: z.string().optional(), acceptedAt: z.string().nullable().optional(), cashDrawer: cashDrawerResponse.optional(), referenceId: z.string().nullable().optional(), status: z.string().nullable().optional()}); export const pagedListSupplierPaymentResponse = z.object({items: z.array(supplierPaymentResponse).nullable().optional(), pageNumber: z.number().int().optional(), pageSize: z.number().int().optional(), totalCount: z.number().int().optional(), totalPages: z.number().int().optional(), hasPrevious: z.boolean().optional(), hasNext: z.boolean().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 }; /** * Gets a list of SupplierPayment current supplier * * POST /api/v{version}/supplier-payment/search */ export const createApiApiVVersionSupplierPaymentSearch = async (args: CreateApiApiVVersionSupplierPaymentSearchArgs, options?: CreateApiApiVVersionSupplierPaymentSearchOptions) => { const {baseUrl = "https://api.zrexpress.app", fetch: fetchFn = fetch, bearerAuth, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Tenant'] != null) headers.set("X-Tenant", String(args['X-Tenant'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) if (apiKey !== undefined) headers.set("X-Api-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v${encodeURIComponent(String(args.version))}/supplier-payment/search${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(pagedListSupplierPaymentResponse, await res.json()) };