import {z} from 'zod' export type GetApiV1VerificationItrGet26asDetailsArgs = {itr_client_id: string, tds_id: string}; export type GetApiV1VerificationItrGet26asDetailsOptions = {baseUrl: string, Oauth2ClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; export const basic26asDetails = z.object({sr_no: z.unknown(), name_of_deductor: z.unknown(), total_amount_paid: z.unknown(), total_tax_deducted: z.unknown(), total_tds_deposited: z.unknown(), tan_of_deductor: z.unknown(), section: z.unknown(), transaction_date: z.unknown(), status_of_booking: z.unknown(), date_of_booking: z.unknown(), remarks: z.unknown(), amount_paid: z.unknown(), tax_deducted: z.unknown(), tds_deposited: z.unknown()}); export const details26as = z.object({assessment_year: z.unknown(), tds_data: z.array(basic26asDetails).optional()}); export const rESPONSEDETAILS26AS = z.object({code: z.number().int(), timestamp: z.number().int().optional(), transaction_id: z.string().optional(), sub_code: z.string().optional(), message: z.string(), data: details26as.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 }; /** * Get 26As Details * * GET /v1/verification/itr/get-26as-details */ export const getApiV1VerificationItrGet26asDetails = async (args: GetApiV1VerificationItrGet26asDetailsArgs, options: GetApiV1VerificationItrGet26asDetailsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Oauth2ClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.itr_client_id != null) query.append("itr_client_id", String(args.itr_client_id)) if (args.tds_id != null) query.append("tds_id", String(args.tds_id)) if (Oauth2ClientCredentials !== undefined) headers.set('authorization', `Bearer ${Oauth2ClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/verification/itr/get-26as-details${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(rESPONSEDETAILS26AS, await res.json()) };