export type TokenTypeHint = 'access_token' | 'refresh_token'; export type TokenRevocationRequestCreate = {token: string, token_type_hint?: TokenTypeHint | undefined}; export type CreateApiOauthTokenRevokeArgs = {body: TokenRevocationRequestCreate}; export type CreateApiOauthTokenRevokeOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Revoke a token * * POST /oauth/token/revoke */ export const createApiOauthTokenRevoke = async (args: CreateApiOauthTokenRevokeArgs, options?: CreateApiOauthTokenRevokeOptions) => { const {baseUrl = "https://api.pinterest.com/v5", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/oauth/token/revoke${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 };