import {z} from 'zod' export type GetApiMyeduzzV1FinancialAffiliateFiscalDocumentsArgs = {page?: number | undefined, itemsPerPage?: number | undefined, startDate: string, endDate: string, status?: ('new' | 'pending' | 'waitingDocument' | 'canceled' | 'processed' | 'approved' | 'fileGenerated' | 'processing' | 'deleted') | undefined, name?: string | undefined, email?: string | undefined, saleId?: string | undefined, productId?: string | undefined, documentId?: string | undefined}; export type GetApiMyeduzzV1FinancialAffiliateFiscalDocumentsOptions = {baseUrl?: string | undefined, eduzzAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiMyeduzzV1FinancialAffiliateFiscalDocumentsResponse = z.object({pages: z.number(), page: z.number(), itemsPerPage: z.number(), totalItems: z.number(), items: z.array(z.object({document: z.object({id: z.string(), name: z.string(), status: z.string(), type: z.string(), baseValue: z.object({currency: z.string(), value: z.number()}), emissionDate: z.string(), referenceDate: z.string(), processingDate: z.string(), fileStatus: z.string(), taxBase: z.number(), basePercent: z.number(), taxValue: z.object({currency: z.string(), value: z.number()})}), source: z.object({taxType: z.string().nullable(), companyName: z.string(), document: z.string(), ie: z.string(), im: z.string().nullable(), email: z.string(), tel: z.string().nullable(), tel2: z.string(), cell: z.string().nullable(), address: z.object({street: z.string(), number: z.string(), complement: z.string(), district: z.string(), zipCode: z.string(), city: z.string(), uf: z.string()})}), destination: z.object({companyName: z.string(), taxType: z.string(), taxId: z.string(), ie: z.string(), im: z.string().nullable(), email: z.string(), tel: z.string().nullable(), tel2: z.string().nullable(), cell: z.string(), address: z.object({street: z.string().nullable(), number: z.string().nullable(), complement: z.string().nullable(), district: z.string().nullable(), zipCode: z.string(), countryForeign: z.string().nullable(), city: z.string().nullable(), uf: z.string().nullable(), country: z.string().nullable()})}), sale: z.object({id: z.string(), paymentDate: z.string(), total: z.object({currency: z.string(), value: z.number()})}), client: z.object({id: z.string(), name: z.string(), document: z.string(), email: z.string(), tel: z.string().nullable(), tel2: z.string().nullable(), cell: z.string(), address: z.object({street: z.string().nullable(), number: z.string().nullable(), complement: z.string().nullable(), neighborhood: z.string().nullable(), zipCode: z.string(), city: z.string().nullable(), state: z.string().nullable()})}), product: z.object({id: z.string(), title: z.string()})}))}); 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 documentos fiscais do afiliado com base em critérios como datas, status, venda e conteúdo, detalhando informações fiscais e do cliente. * * GET /myeduzz/v1/financial/affiliate/fiscal-documents */ export const getApiMyeduzzV1FinancialAffiliateFiscalDocuments = async (args: GetApiMyeduzzV1FinancialAffiliateFiscalDocumentsArgs, options?: GetApiMyeduzzV1FinancialAffiliateFiscalDocumentsOptions) => { const {baseUrl = "https://api.eduzz.com", fetch: fetchFn = fetch, eduzzAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.itemsPerPage != null) query.append("itemsPerPage", String(args.itemsPerPage)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.status != null) query.append("status", String(args.status)) if (args.name != null) query.append("name", String(args.name)) if (args.email != null) query.append("email", String(args.email)) if (args.saleId != null) query.append("saleId", String(args.saleId)) if (args.productId != null) query.append("productId", String(args.productId)) if (args.documentId != null) query.append("documentId", String(args.documentId)) if (eduzzAuth !== undefined) headers.set('authorization', `Bearer ${eduzzAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/myeduzz/v1/financial/affiliate/fiscal-documents${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(getApiMyeduzzV1FinancialAffiliateFiscalDocumentsResponse, await res.json()) };