diff --git a/src/deauthorizer.ts b/src/deauthorizer.ts new file mode 100644 index 00000000..c1ccf566 --- /dev/null +++ b/src/deauthorizer.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import { JsonMap } from '@salesforce/ts-types'; + +export abstract class Deauthorizer { + public async removeAll(): Promise { + const result = { + successes: [], + failures: [], + } as Deauthorizer.Result; + + const environments = await this.find(); + for (const id of Object.keys(environments)) { + try { + await this.remove(id); + result.successes.push(id); + } catch { + result.failures.push(id); + } + } + return result; + } + + public abstract find(): Promise>; + public abstract remove(id: string): Promise; +} + +export namespace Deauthorizer { + export type Result = { + successes: string[]; + failures: string[]; + }; +} diff --git a/src/exported.ts b/src/exported.ts index 499b3767..13fc355e 100644 --- a/src/exported.ts +++ b/src/exported.ts @@ -7,6 +7,7 @@ export { generateTableChoices } from './util'; export { Deployable, Deployer } from './deployer'; +export { Deauthorizer } from './deauthorizer'; export { Prompter } from './prompter'; export { SfHook } from './hooks'; export * from './types'; diff --git a/src/hooks.ts b/src/hooks.ts index 637533d9..2f498d61 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -10,13 +10,15 @@ import { Hook, Hooks } from '@oclif/core/lib/interfaces/hooks'; import { cli } from 'cli-ux'; import { Duration, env } from '@salesforce/kit'; import { Deployer } from './deployer'; -import { EnvList, EnvDisplay, JsonObject, Deploy, Login } from './types'; +import { EnvList, EnvDisplay, JsonObject, Deploy, Login, Logout } from './types'; +import { Deauthorizer } from './deauthorizer'; interface SfHooks extends Hooks { 'sf:env:list': EnvList.HookMeta; 'sf:env:display': EnvDisplay.HookMeta; 'sf:deploy': Deploy.HookMeta; 'sf:login': Login.HookMeta; + 'sf:logout': Logout.HookMeta; } type GenericHook = Hook>; @@ -42,4 +44,5 @@ export namespace SfHook { export type EnvDisplay = GenericHook<'sf:env:display', T>; export type Deploy = GenericHook<'sf:deploy', T>; export type Login = Hook<'sf:login', SfHooks>; + export type Logout = Hook<'sf:logout', SfHooks>; } diff --git a/src/types/index.ts b/src/types/index.ts index 22558544..970f1813 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -5,6 +5,7 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ +import { Deauthorizer } from '../deauthorizer'; import { Deployer } from '../deployer'; export type JsonObject = { @@ -101,3 +102,10 @@ export namespace Login { return: void; }; } + +export namespace Logout { + export type HookMeta = { + options: {}; + return: T; + }; +}