export type CommonsCareContext = {display?: string | undefined, id?: string | undefined}; export type CommonsDuration = {from?: string | undefined, to?: string | undefined}; export type ApproveConsent = {access_mode?: 'view' | undefined, care_contexts?: Array | undefined, duration?: CommonsDuration | undefined, erase_at?: string | undefined, hi_types?: Array | undefined, hip_id?: string | undefined}; export type ApproveRequest = {access_mode?: 'view' | undefined, consent_artefacts: Array, duration?: CommonsDuration | undefined, erase_at?: string | undefined, hi_types?: Array | undefined, id: string}; export type CreateApiAbdmV1ConsentsApproveArgs = {'X-Pt-Id'?: string | undefined, 'X-Partner-Pt-Id'?: string | undefined, 'X-Hip-Id'?: string | undefined, oid?: string | undefined, body: ApproveRequest}; export type CreateApiAbdmV1ConsentsApproveOptions = {baseUrl?: string | undefined, authApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * This endpoint is used to approve the consent * * POST /abdm/v1/consents/approve */ export const createApiAbdmV1ConsentsApprove = async (args: CreateApiAbdmV1ConsentsApproveArgs, options?: CreateApiAbdmV1ConsentsApproveOptions) => { 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") 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 (args.oid != null) query.append("oid", String(args.oid)) if (authApiKey !== undefined) headers.set('authorization', `Bearer ${authApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/abdm/v1/consents/approve${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 undefined };