import {z} from 'zod' export type StateFiling = {state_code?: string | undefined, state_name?: string | undefined, state_id_number?: string | undefined, state_tax_withheld?: number | undefined, state_income?: number | undefined}; export type Form1099MISCUpdateRequest = {tax_year: string, rents?: number | undefined, royalties?: number | undefined, other_income?: number | undefined, federal_tax_withheld?: number | undefined, fishing_boat_proceeds?: number | undefined, medical_healthcare_payments?: number | undefined, is_direct_sale?: boolean | undefined, substitute_payments?: number | undefined, crop_insurance?: number | undefined, gross_proceeds_attorney?: number | undefined, fish_purchased_for_resale?: number | undefined, section_409a_deferrals?: number | undefined, is_fatca?: boolean | undefined, excess_golden_parachute?: number | undefined, nonqualified_deferred_compensation?: number | undefined, account_number?: string | undefined, is_second_tin_notice?: boolean | undefined, is_postal?: boolean | undefined, email_address?: string | undefined, state_filing?: Array | undefined, submission_id: string, is_void?: boolean | undefined}; export type UpdateApiPayoutUserTokenTaxForm1099miscArgs = {body: Form1099MISCUpdateRequest}; export type UpdateApiPayoutUserTokenTaxForm1099miscOptions = {baseUrl?: string | undefined, AUTHORIZERNAME?: string | undefined, fetch?: typeof fetch | undefined}; export const form1099UpdateCorrectionResponse = z.object({submission_id: z.string().optional(), record_id: z.string().optional(), operation: z.enum(["UPDATE", "CORRECTION"]).optional(), original_submission_id: z.string().optional(), status: z.enum(["SUCCESS", "FAILURE"]).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 }; /** * Update or Correct Form 1099-MISC * * PUT /payout/{user_token}/tax/form1099misc * * Also accepts auth: api_key */ export const updateApiPayoutUserTokenTaxForm1099misc = async (args: UpdateApiPayoutUserTokenTaxForm1099miscArgs, options?: UpdateApiPayoutUserTokenTaxForm1099miscOptions) => { const {baseUrl = "https://api.masspay.io/v1.0.0", fetch: fetchFn = fetch, AUTHORIZERNAME} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AUTHORIZERNAME !== undefined) headers.set("Authorization", AUTHORIZERNAME) const url = `${baseUrl.replace(/\/+$/, '')}/payout/${encodeURIComponent(String(args.user_token))}/tax/form1099misc${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(form1099UpdateCorrectionResponse, await res.json()) };