import {z} from 'zod' export type UpdateApiApiV1MeTaxVatFilingsFilingIdArgs = {filingId: string, body: {revision: string, currency: 'usd', accountingMethod: 'cash' | 'accrual', grossIncome: string, taxCredit: string, taxWithheld: string}}; export type UpdateApiApiV1MeTaxVatFilingsFilingIdOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const vatFiling = z.object({id: z.string(), subject: z.object({type: z.enum(["natural_person", "legal_entity"]), id: z.string(), name: z.string(), residentPermitNumber: z.string().nullable()}), period: z.object({year: z.number().int(), quarter: z.number().int().gte(1).lte(4)}), status: z.enum(["draft", "submitted"]), revision: z.string(), currency: z.literal("usd"), accountingMethod: z.string().nullable(), reported: z.object({grossIncome: z.string().nullable(), taxCredit: z.string().nullable(), taxWithheld: z.string().nullable()}), taxLiability: z.string().nullable(), readyToSubmit: z.boolean(), creditReviewRequired: z.boolean(), creditReviewStatus: z.string().nullable(), paymentRequired: z.boolean(), invoice: z.object({id: z.string(), status: z.string()}).nullable(), submittedAt: z.string().nullable(), links: z.object({portal: z.string(), assessment: z.string().nullable()})}); export const updateApiApiV1MeTaxVatFilingsFilingIdResponse = z.object({data: vatFiling}); 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 }; /** * Save and calculate VAT figures * * PUT /api/v1/me/tax/vat/filings/{filingId} * * Also accepts auth: oauth2 */ export const updateApiApiV1MeTaxVatFilingsFilingId = async (args: UpdateApiApiV1MeTaxVatFilingsFilingIdArgs, options?: UpdateApiApiV1MeTaxVatFilingsFilingIdOptions) => { const {baseUrl = "https://portal.eprospera.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/me/tax/vat/filings/${encodeURIComponent(String(args.filingId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiApiV1MeTaxVatFilingsFilingIdResponse, await res.json()) };