import {z} from 'zod' export type GetApiFinanceManagerFinancialEstimateVsActualPayoutsDetailsArgs = {clientId?: string | undefined, 'access-token'?: string | undefined, body: {channel?: Array | undefined, endDate?: string | undefined, listingIds?: Array | undefined, payoutDates?: Array | undefined, startDate?: string | undefined}}; export type GetApiFinanceManagerFinancialEstimateVsActualPayoutsDetailsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiFinanceManagerFinancialEstimateVsActualPayoutsDetailsResponse = z.object({error: z.unknown(), message: z.string().optional(), result: z.object({storeWise: z.array(z.object({deductions: z.object({commission: z.number().optional(), commissionTax: z.number().optional(), deliveryCommission: z.number().optional(), deliveryFee: z.number().optional(), ezReward: z.number().optional(), marketingAdjustments: z.number().optional(), marketingFees: z.number().optional(), merchantFee: z.number().optional(), otherPayments: z.number().optional(), paymentTransactionFee: z.number().optional(), preferredPartnerProgram: z.number().optional(), promoValue: z.number().optional(), taxWithHeld: z.number().optional(), tips: z.number().optional(), total: z.number().optional()}).optional(), difference: z.object({adjustments: z.object({itemTax: z.number().optional(), itemValue: z.number().optional(), total: z.number().optional()}).optional(), errorCharges: z.object({itemTax: z.number().optional(), itemValue: z.number().optional(), total: z.number().optional()}).optional(), refundByVoosh: z.object({itemTax: z.number().optional(), itemValue: z.number().optional(), total: z.number().optional()}).optional(), total: z.object({itemTax: z.number().optional(), itemValue: z.number().optional(), total: z.number().optional()}).optional()}).optional(), estimatedPayout: z.number().optional(), netPayout: z.object({total: z.number().optional()}).optional(), revenue: z.number().optional(), store: z.string().optional(), tax: z.number().optional()})).optional()}).optional(), status: z.boolean().optional(), statusCode: z.number().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 }; /** * Store Wise Estimted Vs Actual Payout * * GET /finance-manager/financial/estimate-vs-actual-payouts-details */ export const getApiFinanceManagerFinancialEstimateVsActualPayoutsDetails = async (args: GetApiFinanceManagerFinancialEstimateVsActualPayoutsDetailsArgs, options?: GetApiFinanceManagerFinancialEstimateVsActualPayoutsDetailsOptions) => { const {baseUrl = "https://growapiservicesv2server.voosh.ai", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.clientId != null) query.append("clientId", String(args.clientId)) if (args['access-token'] != null) headers.set("access-token", String(args['access-token'])) if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/finance-manager/financial/estimate-vs-actual-payouts-details${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", 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(getApiFinanceManagerFinancialEstimateVsActualPayoutsDetailsResponse, await res.json()) };