Skip to content

Commit

Permalink
feat: add logout hook
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 13, 2021
1 parent beb6c48 commit 4a4d79b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/deauthorizer.ts
Original file line number Diff line number Diff line change
@@ -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<T = JsonMap> {
public async removeAll(): Promise<Deauthorizer.Result> {
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<Record<string, T>>;
public abstract remove(id: string): Promise<boolean>;
}

export namespace Deauthorizer {
export type Result = {
successes: string[];
failures: string[];
};
}
1 change: 1 addition & 0 deletions src/exported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
5 changes: 4 additions & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = unknown> extends Hooks {
'sf:env:list': EnvList.HookMeta<T & JsonObject>;
'sf:env:display': EnvDisplay.HookMeta<T & JsonObject>;
'sf:deploy': Deploy.HookMeta<T & Deployer>;
'sf:login': Login.HookMeta;
'sf:logout': Logout.HookMeta<T & Deauthorizer>;
}

type GenericHook<T extends keyof SfHooks, P> = Hook<T, SfHooks<P>>;
Expand All @@ -42,4 +44,5 @@ export namespace SfHook {
export type EnvDisplay<T> = GenericHook<'sf:env:display', T>;
export type Deploy<T> = GenericHook<'sf:deploy', T>;
export type Login = Hook<'sf:login', SfHooks>;
export type Logout = Hook<'sf:logout', SfHooks>;
}
8 changes: 8 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -101,3 +102,10 @@ export namespace Login {
return: void;
};
}

export namespace Logout {
export type HookMeta<T extends Deauthorizer> = {
options: {};
return: T;
};
}

0 comments on commit 4a4d79b

Please sign in to comment.