Skip to content

Commit

Permalink
replace more string parts with consts
Browse files Browse the repository at this point in the history
remove commented code
  • Loading branch information
InTheCloudDan committed Feb 8, 2024
1 parent 9a1983d commit f2af40e
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 84 deletions.
24 changes: 11 additions & 13 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
IConfiguration,
ILDExtensionConfiguration,
InstructionPatch,
LaunchDarklyAuthenticationSession,
ILaunchDarklyAuthenticationSession,
NewFlag,
ProjectAPI,
ReleasePhase,
Expand All @@ -22,6 +22,7 @@ import { LDExtensionConfiguration } from './ldExtensionConfiguration';
import { debuglog } from 'util';
import { CMD_LD_CONFIG } from './utils/commands';
import { legacyAuth } from './utils/legacyAuth';
import { CONST_CONFIG_LD } from './utils/constants';

interface CreateOptionsParams {
method?: string;
Expand All @@ -48,7 +49,7 @@ axios.interceptors.response.use(
originalRequest._retry = true;
const session = (await authentication.getSession('launchdarkly', ['writer'], {
createIfNone: false,
})) as LaunchDarklyAuthenticationSession;
})) as ILaunchDarklyAuthenticationSession;
config.setSession(session);
originalRequest.headers['Authorization'] = `Bearer ${session.accessToken}`;
return axios(originalRequest);
Expand Down Expand Up @@ -155,12 +156,9 @@ export class LaunchDarklyAPI {
return project;
} catch (err) {
window
.showErrorMessage(
`[LaunchDarkly] Error getting Project: ${projectKey}\n${err}`,
'Configure LaunchDarkly Extension',
)
.showErrorMessage(`${CONST_CONFIG_LD} Error getting Project: ${projectKey}\n${err}`, CONST_CONFIG_LD)
.then((selection) => {
if (selection === 'Configure LaunchDarkly Extension') commands.executeCommand(CMD_LD_CONFIG);
if (selection === CONST_CONFIG_LD) commands.executeCommand(CMD_LD_CONFIG);
});
}
}
Expand Down Expand Up @@ -199,11 +197,11 @@ export class LaunchDarklyAPI {
console.log(err);
window
.showErrorMessage(
`[LaunchDarkly] Error getting Project: ${projectKey} Environment: ${envKey}\n${err}`,
'Configure LaunchDarkly Extension',
`${CONST_CONFIG_LD} Error getting Project: ${projectKey} Environment: ${envKey}\n${err}`,
CONST_CONFIG_LD,
)
.then((selection) => {
if (selection === 'Configure LaunchDarkly Extension') commands.executeCommand(CMD_LD_CONFIG);
if (selection === CONST_CONFIG_LD) commands.executeCommand(CMD_LD_CONFIG);
});
}
}
Expand All @@ -217,11 +215,11 @@ export class LaunchDarklyAPI {
} catch (err) {
window
.showErrorMessage(
`[LaunchDarkly] Error getting Metrics for Project: ${projectKey}\n${err}`,
'Configure LaunchDarkly Extension',
`${CONST_CONFIG_LD} Error getting Metrics for Project: ${projectKey}\n${err}`,
CONST_CONFIG_LD,
)
.then((selection) => {
if (selection === 'Configure LaunchDarkly Extension') commands.executeCommand(CMD_LD_CONFIG);
if (selection === CONST_CONFIG_LD) commands.executeCommand(CMD_LD_CONFIG);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/openLaunchDarkly.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { commands, Disposable, window } from 'vscode';
import { FLAG_KEY_REGEX } from '../providers';
import { kebabCase } from 'lodash';
import { FeatureFlagConfig, FlagStoreInterface, ILDExtensionConfiguration } from '../models';
import { FeatureFlagConfig, IFlagStore, ILDExtensionConfiguration } from '../models';
import * as url from 'url';
import opn = require('opn');
import { CMD_LD_OPEN } from '../utils/commands';
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function openInLdCmd(config: ILDExtensionConfiguration): Disposab
return openInLdCmd;
}

const openFlagInBrowser = async (config: ILDExtensionConfiguration, flagKey: string, flagStore: FlagStoreInterface) => {
const openFlagInBrowser = async (config: ILDExtensionConfiguration, flagKey: string, flagStore: IFlagStore) => {
const { flag } = await flagStore.getFeatureFlag(flagKey);

// Default to first environment
Expand Down
7 changes: 4 additions & 3 deletions src/configurationMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
} from 'vscode';

import { MultiStepInput } from './multiStepInput';
import { Resource, Project, Environment, LaunchDarklyAuthenticationSession, LaunchDarklyAPIInterface } from './models';
import { Resource, Project, Environment, ILaunchDarklyAuthenticationSession, LaunchDarklyAPIInterface } from './models';
import { extensionReload } from './generalUtils';
import { logDebugMessage } from './utils/logDebugMessage';
import { LDExtensionConfiguration } from './ldExtensionConfiguration';
import { CONST_LD_PREFIX } from './utils/constants';
interface CMState {
baseUri: string;
env: string;
Expand Down Expand Up @@ -64,7 +65,7 @@ export class ConfigurationMenu {
if (selection === 'Sign In') {
const session = (await authentication.getSession('launchdarkly', ['writer'], {
createIfNone: true,
})) as LaunchDarklyAuthenticationSession;
})) as ILaunchDarklyAuthenticationSession;
this.config.setSession(session);
}
}
Expand Down Expand Up @@ -171,7 +172,7 @@ export class ConfigurationMenu {
window.withProgress(
{
location: ProgressLocation.Notification,
title: '[LaunchDarkly] Updating Configuration',
title: `${CONST_LD_PREFIX} Updating Configuration`,
cancellable: false,
},
() => {
Expand Down
7 changes: 4 additions & 3 deletions src/createFlagMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MultiStepInput, QuickPickParameters } from './multiStepInput';
import { LaunchDarklyAPI } from './api';
import { kebabCase } from 'lodash';
import { FeatureFlag, ILDExtensionConfiguration, NewFlag, ReleasePipeline } from './models';
import { CONST_LD_PREFIX } from './utils/constants';
export interface State {
name: string;
key: string;
Expand Down Expand Up @@ -157,7 +158,7 @@ export class CreateFlagMenu {
window.withProgress(
{
location: ProgressLocation.Notification,
title: '[LaunchDarkly] Flag: ${flag.key} created and key copied to your clipboard.',
title: `${CONST_LD_PREFIX} Flag: ${flag.key} created and key copied to your clipboard.`,
cancellable: false,
},
() => {
Expand All @@ -174,7 +175,7 @@ export class CreateFlagMenu {
}
}
} catch (err) {
window.showErrorMessage(`[LaunchDarkly] Creating flag ${err}`);
window.showErrorMessage(`${CONST_LD_PREFIX} Creating flag ${err}`);
}
}

Expand Down Expand Up @@ -213,7 +214,7 @@ export class CreateFlagMenu {
window.showInformationMessage(`Flag: ${flag.key} created and key copied to your clipboard.`);
this.flag = flag;
} catch (err) {
window.showErrorMessage(`[LaunchDarkly] Creating flag ${err}`);
window.showErrorMessage(`${CONST_LD_PREFIX} Creating flag ${err}`);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { LDExtensionConfiguration } from './ldExtensionConfiguration';
import * as semver from 'semver';
import { SetWorkspaceCmd } from './commands/setWorkspaceEnabled';
import { CMD_LD_CONFIG, CMD_LD_SIGNIN } from './utils/commands';
import { LaunchDarklyAuthenticationSession } from './models';
import { ILaunchDarklyAuthenticationSession } from './models';

export async function activate(ctx: ExtensionContext): Promise<void> {
const storedVersion = ctx.globalState.get('version', '5.0.0');
Expand All @@ -26,7 +26,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {

const session = (await authentication.getSession('launchdarkly', ['writer'], {
createIfNone: false,
})) as LaunchDarklyAuthenticationSession;
})) as ILaunchDarklyAuthenticationSession;
LDExtConfig.setSession(session);

const validationError = await LDExtConfig.getConfig().validate();
Expand Down Expand Up @@ -67,7 +67,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
commands.registerCommand(CMD_LD_SIGNIN, async () => {
const session = (await authentication.getSession('launchdarkly', ['writer'], {
createIfNone: true,
})) as LaunchDarklyAuthenticationSession;
})) as ILaunchDarklyAuthenticationSession;
LDExtConfig.setSession(session);
if (!(await LDExtConfig.getConfig().isConfigured())) {
window
Expand Down
15 changes: 8 additions & 7 deletions src/flagStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import { debounce, Dictionary, keyBy } from 'lodash';
import {
FeatureFlag,
FlagConfiguration,
FlagStoreInterface,
IFlagStore,
FlagWithConfiguration,
ILDExtensionConfiguration,
InstructionPatch,
PatchComment,
} from './models';
import { CMD_LD_CONFIG } from './utils/commands';
import { CONST_CONFIG_LD, CONST_LD_PREFIX } from './utils/constants';

const DATA_KIND = { namespace: 'features' };

type FlagUpdateCallback = (flag: string) => void;
type LDClientResolve = (LDClient: LDClient) => void;
type LDClientReject = () => void;

export class FlagStore implements FlagStoreInterface {
export class FlagStore implements IFlagStore {
private readonly config: ILDExtensionConfiguration;
private readonly store: LaunchDarkly.LDFeatureStore;
private flagMetadata: Dictionary<FeatureFlag>;
Expand Down Expand Up @@ -59,7 +60,7 @@ export class FlagStore implements FlagStoreInterface {
await this.stop();
await this.start();
} catch (err) {
window.showErrorMessage(`[LaunchDarkly] ${err}`);
window.showErrorMessage(`${CONST_LD_PREFIX} ${err}`);
}
},
200,
Expand Down Expand Up @@ -105,9 +106,9 @@ export class FlagStore implements FlagStoreInterface {
this.setLDClientBackgroundCheck();
} catch (err) {
window
.showErrorMessage('[LaunchDarkly] Failed to setup LaunchDarkly client', 'Configure LaunchDarkly Extension')
.showErrorMessage(`${CONST_LD_PREFIX} Failed to setup LaunchDarkly client`, CONST_CONFIG_LD)
.then((selection) => {
if (selection === 'Configure LaunchDarkly Extension') commands.executeCommand(CMD_LD_CONFIG);
if (selection === CONST_CONFIG_LD) commands.executeCommand(CMD_LD_CONFIG);
});
this.rejectLDClient();
console.error(`Failed to setup client: ${err}`);
Expand Down Expand Up @@ -193,7 +194,7 @@ export class FlagStore implements FlagStoreInterface {
console.log(`${err}`);
return;
}
window.showErrorMessage(`[LaunchDarkly] ${errMsg}`);
window.showErrorMessage(`${CONST_LD_PREFIX} ${errMsg}`);
}
},
5000,
Expand Down Expand Up @@ -349,7 +350,7 @@ export class FlagStore implements FlagStoreInterface {
return this.flagMetadata;
} catch (err) {
console.log(`Failed getting Metadata: ${err}`);
window.showErrorMessage(`[LaunchDarkly] ${err}`);
window.showErrorMessage(`${CONST_LD_PREFIX} ${err}`);
}
} else {
return this.flagMetadata;
Expand Down
4 changes: 2 additions & 2 deletions src/generalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ILDExtensionConfiguration, InstructionPatch } from './models';
import { logDebugMessage } from './utils/logDebugMessage';
import { CMD_LD_CONFIG, CMD_LD_OPEN_FLAG, CMD_LD_REFRESH_LENS, CMD_LD_TOGGLE_CMD_PROMPT } from './utils/commands';
import { registerCommand } from './utils/registerCommand';
import { CONST_CONFIG_LD } from './utils/constants';

const cache = new ToggleCache();

Expand Down Expand Up @@ -85,7 +86,6 @@ export async function setupComponents(config: ILDExtensionConfiguration, reload

if (config.getConfig().enableAliases) {
config.setAliases(new FlagAliases(config));
//aliases = new FlagAliases(config.getConfig(), ctx);
if (config.getAliases().codeRefsVersionCheck()) {
config.getAliases().setupStatusBar();
await config.getAliases().start();
Expand Down Expand Up @@ -181,7 +181,7 @@ async function showToggleMenu(config: ILDExtensionConfiguration) {
try {
flags = await config.getFlagStore().allFlagsMetadata();
} catch (err) {
window.showErrorMessage('[LaunchDarkly] Unable to retrieve flags, please check configuration.');
window.showErrorMessage(`${CONST_CONFIG_LD} Unable to retrieve flags, please check configuration.`);
return;
}
const items = [];
Expand Down
32 changes: 16 additions & 16 deletions src/ldExtensionConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { ExtensionContext, StatusBarItem, TreeView } from 'vscode';
import {
FlagStoreInterface,
FlagTreeInterface,
IFlagStore,
IFlagTree,
IConfiguration,
IFlagAliases,
ILaunchDarklyReleaseProvider,
LaunchDarklyAPIInterface,
LaunchDarklyAuthenticationSession,
LaunchDarklyTreeViewProviderInterface,
ILaunchDarklyAuthenticationSession,
ILaunchDarklyTreeViewProvider,
} from './models';

export class LDExtensionConfiguration {
private static instance: LDExtensionConfiguration;
private config?: IConfiguration;
private ctx: ExtensionContext;
private api?: LaunchDarklyAPIInterface;
private flagStore?: FlagStoreInterface;
private flagTreeView: TreeView<FlagTreeInterface>;
private flagView: LaunchDarklyTreeViewProviderInterface;
private flagStore?: IFlagStore;
private flagTreeView: TreeView<IFlagTree>;
private flagView: ILaunchDarklyTreeViewProvider;
private aliases?: IFlagAliases;
private releaseView?: ILaunchDarklyReleaseProvider;
private session?: LaunchDarklyAuthenticationSession;
private session?: ILaunchDarklyAuthenticationSession;
private statusBar?: StatusBarItem;

private constructor(ctx: ExtensionContext) {
Expand Down Expand Up @@ -66,27 +66,27 @@ export class LDExtensionConfiguration {
this.ctx = ctx;
}

getFlagStore(): FlagStoreInterface | undefined {
getFlagStore(): IFlagStore | undefined {
return this.flagStore;
}

setFlagStore(flagStore: FlagStoreInterface): void {
setFlagStore(flagStore: IFlagStore): void {
this.flagStore = flagStore;
}

getFlagTreeProvider(): TreeView<FlagTreeInterface> | undefined {
getFlagTreeProvider(): TreeView<IFlagTree> | undefined {
return this.flagTreeView;
}

setFlagTreeProvider(flagTreeProvider: TreeView<FlagTreeInterface>): void {
setFlagTreeProvider(flagTreeProvider: TreeView<IFlagTree>): void {
this.flagTreeView = flagTreeProvider;
}

getFlagView(): LaunchDarklyTreeViewProviderInterface | undefined {
getFlagView(): ILaunchDarklyTreeViewProvider | undefined {
return this.flagView;
}

setFlagView(flagView: LaunchDarklyTreeViewProviderInterface): void {
setFlagView(flagView: ILaunchDarklyTreeViewProvider): void {
this.flagView = flagView;
}

Expand All @@ -98,11 +98,11 @@ export class LDExtensionConfiguration {
this.releaseView = releaseView;
}

getSession(): LaunchDarklyAuthenticationSession | undefined {
getSession(): ILaunchDarklyAuthenticationSession | undefined {
return this.session;
}

setSession(session: LaunchDarklyAuthenticationSession): void {
setSession(session: ILaunchDarklyAuthenticationSession): void {
this.session = session;
}

Expand Down
Loading

0 comments on commit f2af40e

Please sign in to comment.