import {z} from 'zod' export type NhprEKACreateHPRID = {council?: boolean | undefined, domain_name?: string | undefined, email?: string | undefined, first_name?: string | undefined, hp_category_code?: number | undefined, hp_sub_category_code?: number | undefined, hprId?: string | undefined, id_type?: string | undefined, last_name?: string | undefined, middle_name?: string | undefined, notify_user?: boolean | undefined, password?: string | undefined, pincode?: string | undefined, profile_photo?: string | undefined, role?: number | undefined, source_type?: string | undefined, txnId?: string | undefined}; export type CreateApiAbdmNhprV1HprAadhaarCreateArgs = {'X-Pt-Id'?: string | undefined, 'X-Partner-Pt-Id'?: string | undefined, 'X-Hip-Id'?: string | undefined, body: NhprEKACreateHPRID}; export type CreateApiAbdmNhprV1HprAadhaarCreateOptions = {baseUrl?: string | undefined, authApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const nhprEKACreateHPRIDResponse = z.object({auth_methods: z.array(z.string()).optional(), categories: z.unknown(), category_id: z.number().int().optional(), day_of_birth: z.string().optional(), district_code: z.string().optional(), district_name: z.string().optional(), email: z.string().optional(), first_name: z.string().optional(), gender: z.string().optional(), hpr_id_number: z.string().optional(), hprId: z.string().optional(), kyc_photo: z.string().optional(), last_name: z.string().optional(), middle_name: z.string().optional(), mobile: z.string().optional(), month_of_birth: z.string().optional(), name: z.string().optional(), new: z.boolean().optional(), state_code: z.string().optional(), state_name: z.string().optional(), sub_category_id: z.number().int().optional(), year_of_birth: z.string().optional()}); export const handlerTypedAPIResponseGithubComEkaCareNdhmPkgNhprNhprEKACreateHPRIDResponse = z.object({data: nhprEKACreateHPRIDResponse.optional(), error: z.unknown(), success: z.boolean().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 }; /** * Create HPR ID * * POST /abdm/nhpr/v1/hpr/aadhaar/create */ export const createApiAbdmNhprV1HprAadhaarCreate = async (args: CreateApiAbdmNhprV1HprAadhaarCreateArgs, options?: CreateApiAbdmNhprV1HprAadhaarCreateOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch, authApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Pt-Id'] != null) headers.set("X-Pt-Id", String(args['X-Pt-Id'])) if (args['X-Partner-Pt-Id'] != null) headers.set("X-Partner-Pt-Id", String(args['X-Partner-Pt-Id'])) if (args['X-Hip-Id'] != null) headers.set("X-Hip-Id", String(args['X-Hip-Id'])) if (authApiKey !== undefined) headers.set('authorization', `Bearer ${authApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/abdm/nhpr/v1/hpr/aadhaar/create${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(handlerTypedAPIResponseGithubComEkaCareNdhmPkgNhprNhprEKACreateHPRIDResponse, await res.json()) };