export type CallbackBody = {result?: ('SUCCESS' | 'FAIL' | 'ERROR' | 'TIMEOUT') | undefined}; export type CreateApiV1CallbackInstitutionCodeCustomerNumberSessionIdArgs = {institutionCode: string, customerNumber: string, sessionId: string, body: CallbackBody}; export type CreateApiV1CallbackInstitutionCodeCustomerNumberSessionIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Authentication response forwarded to Enfuce * * POST /v1/callback/{institutionCode}/{customerNumber}/{sessionId} */ export const createApiV1CallbackInstitutionCodeCustomerNumberSessionId = async (args: CreateApiV1CallbackInstitutionCodeCustomerNumberSessionIdArgs, options: CreateApiV1CallbackInstitutionCodeCustomerNumberSessionIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/callback/${encodeURIComponent(String(args.institutionCode))}/${encodeURIComponent(String(args.customerNumber))}/${encodeURIComponent(String(args.sessionId))}${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 };