import {z} from 'zod' export type GetApiV2VerificationEpfoUanToEmploymentHistoryArgs = {uan_number: string, generate_pdf?: boolean | undefined}; export type GetApiV2VerificationEpfoUanToEmploymentHistoryOptions = {baseUrl: string, Oauth2ClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; export const employmentDetails = z.object({name: z.string().optional(), guardian_name: z.string().optional(), establishment_name: z.string().optional(), member_id: z.string().optional(), date_of_joining: z.string().optional(), date_of_exit: z.string().optional(), last_pf_submitted: z.string().optional()}); export const employmentHistory = z.object({pdf_url: z.string().optional(), employment_history: z.array(employmentDetails).optional()}); export const rESPONSEUANTOEMPLOYMENTHISTORYSUCCESS = z.object({code: z.number().int().optional(), timestamp: z.number().int(), transaction_id: z.string(), sub_code: z.string().optional(), message: z.string().optional(), data: employmentHistory}); 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 }; /** * Uan To Employment History Cashfree * * GET /v2/verification/epfo/uan-to-employment-history */ export const getApiV2VerificationEpfoUanToEmploymentHistory = async (args: GetApiV2VerificationEpfoUanToEmploymentHistoryArgs, options: GetApiV2VerificationEpfoUanToEmploymentHistoryOptions) => { const {baseUrl, fetch: fetchFn = fetch, Oauth2ClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.uan_number != null) query.append("uan_number", String(args.uan_number)) if (args.generate_pdf != null) query.append("generate_pdf", String(args.generate_pdf)) if (Oauth2ClientCredentials !== undefined) headers.set('authorization', `Bearer ${Oauth2ClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/verification/epfo/uan-to-employment-history${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(rESPONSEUANTOEMPLOYMENTHISTORYSUCCESS, await res.json()) };