import {z} from 'zod' export type CreateApiV1GhIdentitiesGhanaIdIdNumberArgs = {idNumber: string, body: {firstname: string, lastname: string, dob?: string | undefined, phone?: string | undefined, email?: string | undefined, gender?: string | undefined}}; export type CreateApiV1GhIdentitiesGhanaIdIdNumberOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1GhIdentitiesGhanaIdIdNumberResponse = z.object({id: z.number().int().optional(), applicant: z.object({firstname: z.string().optional(), lastname: z.string().optional()}).optional(), summary: z.object({ghana_id_check: z.object({status: z.string().optional(), fieldMatches: z.object({firstname: z.boolean().optional(), lastname: z.boolean().optional()}).optional()}).optional()}).optional(), status: z.object({state: z.string().optional(), status: z.string().optional()}).optional(), ghana_id: z.object({nationalId: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), otherName: z.string().optional(), gender: z.string().optional(), dateOfBirth: z.string().optional(), nationality: z.string().optional(), dateOfIssue: z.string().optional(), dateOfExpiry: z.string().optional(), phone: z.string().optional(), address: z.string().optional(), photo: z.string().optional()}).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 }; /** * Ghana Card * * POST /v1/gh/identities/ghana-id/{idNumber} */ export const createApiV1GhIdentitiesGhanaIdIdNumber = async (args: CreateApiV1GhIdentitiesGhanaIdIdNumberArgs, options?: CreateApiV1GhIdentitiesGhanaIdIdNumberOptions) => { const {baseUrl = "https://api.qoreid.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Bearer ${sec0}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/gh/identities/ghana-id/${encodeURIComponent(String(args.idNumber))}${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(createApiV1GhIdentitiesGhanaIdIdNumberResponse, await res.json()) };