import {z} from 'zod' export type GetApiMyeduzzV1SalesIdArgs = {id: string}; export type GetApiMyeduzzV1SalesIdOptions = {baseUrl?: string | undefined, eduzzAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiMyeduzzV1SalesIdResponse = z.object({id: z.string(), contractId: z.string().nullable(), status: z.enum(["open", "processing", "paid", "canceled", "waitingRefund", "refunded", "duplicated", "expired", "recovering", "waitingPayment", "scheduled", "negotiated"]), grossGain: z.object({currency: z.string(), value: z.number()}), netGain: z.object({currency: z.string(), value: z.number()}), partnersGain: z.object({currency: z.string(), value: z.number()}), affiliatesGain: z.object({currency: z.string(), value: z.number()}), fee: z.object({currency: z.string(), value: z.number()}).nullable(), total: z.object({currency: z.string(), value: z.number()}), totalInterest: z.object({currency: z.string(), value: z.number()}), installments: z.number(), alumyFee: z.object({currency: z.string(), value: z.number()}).nullable(), installmentSettlementFee: z.object({currency: z.string(), value: z.number()}).nullable(), others: z.object({currency: z.string(), value: z.number()}), currency: z.string(), locale: z.string(), dueDate: z.string(), paidAt: z.string().nullable(), creditDate: z.string().nullable(), isInfiniteFunnel: z.boolean(), recoveringStatus: z.enum(["inactive", "active", "canceled"]), tracker: z.string().nullable(), tracker2: z.string().nullable(), tracker3: z.string().nullable(), createdAt: z.string(), updatedAt: z.string(), payment: z.object({method: z.enum(["bankslip", "creditCard", "pix", "combinedPayment", "installmentBankslip", "eWallet", "eduzzBalance", "unknown"]), detail: z.enum(["bankslip", "cefBankslip", "creditCard", "amexCreditCard", "dinersCreditCard", "discoverCreditCard", "eloCreditCard", "hipercardCreditCard", "hiperCreditCard", "jcbCreditCard", "mastercardCreditCard", "unionpayCreditCard", "visaCreditCard", "pagdividido", "multipleCards", "pix", "automaticPix", "combinedPayment", "installmentBankslip", "paypal", "eduzzBalance", "unknown"]), link: z.string().nullable()}), product: z.object({id: z.string(), name: z.string(), type: z.enum(["digital", "physical", "service", "ticket", "ecommerce", "package", "project"]), billingType: z.enum(["recurrence", "single", "free", "other", "unknown"]), sku: z.string().nullable()}), refund: z.object({type: z.enum(["common", "partial"]), value: z.object({currency: z.string(), value: z.number()}), partialValue: z.object({currency: z.string(), value: z.number()}), refundedAt: z.string().nullable(), requestedAt: z.string().nullable(), motive: z.string().nullable(), requesterName: z.string().nullable()}).nullable(), affiliate: z.object({id: z.string(), name: z.string()}).nullable(), recipient: z.object({id: z.string(), name: z.string(), email: z.string(), document: z.string(), phone: z.string()}), buyer: z.object({id: z.string(), name: z.string(), email: z.string(), document: z.string(), phone: z.string(), phone2: z.string().nullable(), phone3: z.string().nullable(), address: z.object({zipCode: z.string(), street: z.string(), number: z.string().nullable(), complement: z.string().nullable(), neighborhood: z.string(), city: z.string(), state: z.string()})}), producer: z.object({id: z.string(), name: z.string()}), affiliates: z.array(z.object({id: z.string(), name: z.string(), email: z.string(), netGain: z.object({currency: z.string(), value: z.number()})})), partners: z.array(z.object({id: z.string(), name: z.string(), email: z.string(), netGain: z.object({currency: z.string(), value: z.number()})})), items: z.array(z.object({id: z.string(), productId: z.string(), description: z.string(), unitValue: z.object({currency: z.string(), value: z.number()}), quantity: z.number(), value: z.object({currency: z.string(), value: z.number()}), discount: z.object({currency: z.string(), value: z.number()}).nullable(), freightType: z.string().nullable(), freightDeadline: z.string().nullable(), trackingCode: z.string().nullable()})), offer: z.object({name: z.string().nullable()}), utm: z.object({source: z.string().nullable(), campaign: z.string().nullable(), medium: z.string().nullable(), content: z.string().nullable(), term: z.string().nullable()}).nullable(), orderBump: z.object({has: z.boolean(), isMainSale: z.boolean(), mainSaleId: z.number().nullable()})}); 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 }; /** * Obtém detalhes de uma venda específica * * GET /myeduzz/v1/sales/:id */ export const getApiMyeduzzV1SalesId = async (args: GetApiMyeduzzV1SalesIdArgs, options?: GetApiMyeduzzV1SalesIdOptions) => { 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 (eduzzAuth !== undefined) headers.set('authorization', `Bearer ${eduzzAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/myeduzz/v1/sales/:id${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(getApiMyeduzzV1SalesIdResponse, await res.json()) };