import {z} from 'zod' export type GetApiV2SellerSellerIdTransactionsArgs = {sellerId: string, startDate: string, endDate: string, page?: number | undefined, size?: number | undefined}; export type GetApiV2SellerSellerIdTransactionsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV2SellerSellerIdTransactionsResponse = z.object({content: z.array(z.object({uuid: z.string().optional(), transactionType: z.string().optional(), chargeUUID: z.string().optional(), title: z.string().optional(), installments: z.string().optional(), status: z.enum(["PAID", "FAILED", "PENDING", "CANCELLED"]).optional(), paymentMethod: z.string().optional(), grossValue: z.string().optional(), netValue: z.string().nullable().optional(), fee: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), expirationDate: z.string().optional(), paidDate: z.string().nullable().optional(), receiptDate: z.string().nullable().optional(), frequencyType: z.string().nullable().optional(), customer: z.object({document: z.string().optional(), email: z.string().optional(), name: z.string().optional(), phone: z.string().optional()}).optional(), address: z.object({city: z.string().optional(), complement: z.string().optional(), country: z.string().optional(), district: z.string().optional(), number: z.string().optional(), state: z.string().optional(), street: z.string().optional(), zipCode: z.string().optional()}).optional(), brand: z.string().optional(), first6digits: z.string().nullable().optional(), last4digits: z.string().nullable().optional(), cardHolerName: z.string().nullable().optional(), metadata: z.string().nullable().optional()})).optional(), totalElements: z.number().int().optional(), totalPages: z.number().int().optional(), size: z.number().int().optional(), page: z.number().int().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 }; /** * Lista de transações do seller * * GET /v2/seller/{sellerId}/transactions */ export const getApiV2SellerSellerIdTransactions = async (args: GetApiV2SellerSellerIdTransactionsArgs, options?: GetApiV2SellerSellerIdTransactionsOptions) => { const {baseUrl = "https://api.barte.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (ApiKeyAuth !== undefined) headers.set("X-Token-Api", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/seller/${encodeURIComponent(String(args.sellerId))}/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(getApiV2SellerSellerIdTransactionsResponse, await res.json()) };