export type IntrospectionRevocationRequest = {client_id: string, client_secret: string, token: string}; export type CreateApiTokenRevocationArgs = {body: IntrospectionRevocationRequest}; export type CreateApiTokenRevocationOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Revoke existing token * * POST /token/revocation */ export const createApiTokenRevocation = async (args: CreateApiTokenRevocationArgs, options?: CreateApiTokenRevocationOptions) => { const {baseUrl = "https://api.elliemae.com/oauth2/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") const url = `${baseUrl.replace(/\/+$/, '')}/token/revocation${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };