export type BepKey = string; export type BSPAuthorizationResultCode = string; export type AuthorizationResult = {authorizationResultCode: BSPAuthorizationResultCode, authorizationDateTime: unknown}; export type CreateApiBepBepKeyAuthorizationResultArgs = {bepKey: BepKey, body: AuthorizationResult}; export type CreateApiBepBepKeyAuthorizationResultOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Finalize BEP Authentication * * POST /bep/{bepKey}/authorizationResult * * Also accepts auth: BearerToken */ export const createApiBepBepKeyAuthorizationResult = async (args: CreateApiBepBepKeyAuthorizationResultArgs, options?: CreateApiBepBepKeyAuthorizationResultOptions) => { const {baseUrl = "https://eu-west-1.api.silverflow.com/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/bep/${encodeURIComponent(String(args.bepKey))}/authorizationResult${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 };