From 09a96e4ee143514a2c70728d1c0022a0127dce58 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Thu, 8 Sep 2022 06:23:32 +1000 Subject: [PATCH] Move Injection Tokens to own file (#3456) --- .../src/popup/services/services.module.ts | 7 ++--- apps/desktop/src/app/services/init.service.ts | 2 +- .../src/app/services/services.module.ts | 4 +-- apps/web/src/app/core/core.module.ts | 4 +-- apps/web/src/app/core/init.service.ts | 2 +- apps/web/src/app/core/state/state.service.ts | 2 +- libs/angular/src/services/injection-tokens.ts | 18 ++++++++++++ .../src/services/jslib-services.module.ts | 28 +++++++++---------- .../src/services/theming/theming.service.ts | 2 +- 9 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 libs/angular/src/services/injection-tokens.ts diff --git a/apps/browser/src/popup/services/services.module.ts b/apps/browser/src/popup/services/services.module.ts index c070db6087..87c1dd17e9 100644 --- a/apps/browser/src/popup/services/services.module.ts +++ b/apps/browser/src/popup/services/services.module.ts @@ -2,11 +2,8 @@ import { APP_INITIALIZER, LOCALE_ID, NgModule } from "@angular/core"; import { LockGuard as BaseLockGuardService } from "@bitwarden/angular/guards/lock.guard"; import { UnauthGuard as BaseUnauthGuardService } from "@bitwarden/angular/guards/unauth.guard"; -import { - JslibServicesModule, - MEMORY_STORAGE, - SECURE_STORAGE, -} from "@bitwarden/angular/services/jslib-services.module"; +import { MEMORY_STORAGE, SECURE_STORAGE } from "@bitwarden/angular/services/injection-tokens"; +import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module"; import { ThemingService } from "@bitwarden/angular/services/theming/theming.service"; import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; diff --git a/apps/desktop/src/app/services/init.service.ts b/apps/desktop/src/app/services/init.service.ts index 722ae013fc..7e250a1ee5 100644 --- a/apps/desktop/src/app/services/init.service.ts +++ b/apps/desktop/src/app/services/init.service.ts @@ -1,6 +1,6 @@ import { Inject, Injectable } from "@angular/core"; -import { WINDOW } from "@bitwarden/angular/services/jslib-services.module"; +import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction"; import { AbstractEncryptService } from "@bitwarden/common/abstractions/abstractEncrypt.service"; import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/abstractions/crypto.service"; diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index df32a71839..d49872987c 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -1,7 +1,6 @@ import { APP_INITIALIZER, InjectionToken, NgModule } from "@angular/core"; import { - JslibServicesModule, SECURE_STORAGE, STATE_FACTORY, STATE_SERVICE_USE_CACHE, @@ -9,7 +8,8 @@ import { LOCALES_DIRECTORY, SYSTEM_LANGUAGE, MEMORY_STORAGE, -} from "@bitwarden/angular/services/jslib-services.module"; +} from "@bitwarden/angular/services/injection-tokens"; +import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module"; import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction"; import { AbstractEncryptService } from "@bitwarden/common/abstractions/abstractEncrypt.service"; import { BroadcasterService as BroadcasterServiceAbstraction } from "@bitwarden/common/abstractions/broadcaster.service"; diff --git a/apps/web/src/app/core/core.module.ts b/apps/web/src/app/core/core.module.ts index 95e5a76606..ba22f4422c 100644 --- a/apps/web/src/app/core/core.module.ts +++ b/apps/web/src/app/core/core.module.ts @@ -2,14 +2,14 @@ import { CommonModule } from "@angular/common"; import { APP_INITIALIZER, NgModule, Optional, SkipSelf } from "@angular/core"; import { - JslibServicesModule, SECURE_STORAGE, STATE_FACTORY, STATE_SERVICE_USE_CACHE, LOCALES_DIRECTORY, SYSTEM_LANGUAGE, MEMORY_STORAGE, -} from "@bitwarden/angular/services/jslib-services.module"; +} from "@bitwarden/angular/services/injection-tokens"; +import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module"; import { ModalService as ModalServiceAbstraction } from "@bitwarden/angular/services/modal.service"; import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service"; import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/abstractions/i18n.service"; diff --git a/apps/web/src/app/core/init.service.ts b/apps/web/src/app/core/init.service.ts index 03f4d99f3a..0f61efb673 100644 --- a/apps/web/src/app/core/init.service.ts +++ b/apps/web/src/app/core/init.service.ts @@ -1,6 +1,6 @@ import { Inject, Injectable } from "@angular/core"; -import { WINDOW } from "@bitwarden/angular/services/jslib-services.module"; +import { WINDOW } from "@bitwarden/angular/services/injection-tokens"; import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction"; import { AbstractEncryptService } from "@bitwarden/common/abstractions/abstractEncrypt.service"; import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/abstractions/crypto.service"; diff --git a/apps/web/src/app/core/state/state.service.ts b/apps/web/src/app/core/state/state.service.ts index 074ffa4453..7284ad87fe 100644 --- a/apps/web/src/app/core/state/state.service.ts +++ b/apps/web/src/app/core/state/state.service.ts @@ -5,7 +5,7 @@ import { SECURE_STORAGE, STATE_FACTORY, STATE_SERVICE_USE_CACHE, -} from "@bitwarden/angular/services/jslib-services.module"; +} from "@bitwarden/angular/services/injection-tokens"; import { LogService } from "@bitwarden/common/abstractions/log.service"; import { StateMigrationService } from "@bitwarden/common/abstractions/stateMigration.service"; import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.service"; diff --git a/libs/angular/src/services/injection-tokens.ts b/libs/angular/src/services/injection-tokens.ts new file mode 100644 index 0000000000..7e1b9124b1 --- /dev/null +++ b/libs/angular/src/services/injection-tokens.ts @@ -0,0 +1,18 @@ +import { InjectionToken } from "@angular/core"; + +import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.service"; +import { StateFactory } from "@bitwarden/common/factories/stateFactory"; + +export const WINDOW = new InjectionToken("WINDOW"); +export const MEMORY_STORAGE = new InjectionToken("MEMORY_STORAGE"); +export const SECURE_STORAGE = new InjectionToken("SECURE_STORAGE"); +export const STATE_FACTORY = new InjectionToken("STATE_FACTORY"); +export const STATE_SERVICE_USE_CACHE = new InjectionToken("STATE_SERVICE_USE_CACHE"); +export const LOGOUT_CALLBACK = new InjectionToken<(expired: boolean, userId?: string) => void>( + "LOGOUT_CALLBACK" +); +export const LOCKED_CALLBACK = new InjectionToken<() => void>("LOCKED_CALLBACK"); +export const CLIENT_TYPE = new InjectionToken("CLIENT_TYPE"); +export const LOCALES_DIRECTORY = new InjectionToken("LOCALES_DIRECTORY"); +export const SYSTEM_LANGUAGE = new InjectionToken("SYSTEM_LANGUAGE"); +export const LOG_MAC_FAILURES = new InjectionToken("LOG_MAC_FAILURES"); diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index ab51488ffe..9ca75fe2da 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -1,4 +1,4 @@ -import { InjectionToken, Injector, LOCALE_ID, NgModule } from "@angular/core"; +import { Injector, LOCALE_ID, NgModule } from "@angular/core"; import { ThemingService } from "@bitwarden/angular/services/theming/theming.service"; import { AbstractThemingService } from "@bitwarden/angular/services/theming/theming.service.abstraction"; @@ -105,24 +105,22 @@ import { LockGuard } from "../guards/lock.guard"; import { UnauthGuard } from "../guards/unauth.guard"; import { BroadcasterService } from "./broadcaster.service"; +import { + WINDOW, + MEMORY_STORAGE, + SECURE_STORAGE, + STATE_FACTORY, + STATE_SERVICE_USE_CACHE, + LOGOUT_CALLBACK, + LOCKED_CALLBACK, + LOCALES_DIRECTORY, + SYSTEM_LANGUAGE, + LOG_MAC_FAILURES, +} from "./injection-tokens"; import { ModalService } from "./modal.service"; import { PasswordRepromptService } from "./passwordReprompt.service"; import { ValidationService } from "./validation.service"; -export const WINDOW = new InjectionToken("WINDOW"); -export const MEMORY_STORAGE = new InjectionToken("MEMORY_STORAGE"); -export const SECURE_STORAGE = new InjectionToken("SECURE_STORAGE"); -export const STATE_FACTORY = new InjectionToken("STATE_FACTORY"); -export const STATE_SERVICE_USE_CACHE = new InjectionToken("STATE_SERVICE_USE_CACHE"); -export const LOGOUT_CALLBACK = new InjectionToken<(expired: boolean, userId?: string) => void>( - "LOGOUT_CALLBACK" -); -export const LOCKED_CALLBACK = new InjectionToken<() => void>("LOCKED_CALLBACK"); -export const CLIENT_TYPE = new InjectionToken("CLIENT_TYPE"); -export const LOCALES_DIRECTORY = new InjectionToken("LOCALES_DIRECTORY"); -export const SYSTEM_LANGUAGE = new InjectionToken("SYSTEM_LANGUAGE"); -export const LOG_MAC_FAILURES = new InjectionToken("LOG_MAC_FAILURES"); - @NgModule({ declarations: [], providers: [ diff --git a/libs/angular/src/services/theming/theming.service.ts b/libs/angular/src/services/theming/theming.service.ts index 38eb574a72..7da6565e6d 100644 --- a/libs/angular/src/services/theming/theming.service.ts +++ b/libs/angular/src/services/theming/theming.service.ts @@ -5,7 +5,7 @@ import { BehaviorSubject, filter, fromEvent, Observable } from "rxjs"; import { StateService } from "@bitwarden/common/abstractions/state.service"; import { ThemeType } from "@bitwarden/common/enums/themeType"; -import { WINDOW } from "../jslib-services.module"; +import { WINDOW } from "../injection-tokens"; import { Theme } from "./theme"; import { ThemeBuilder } from "./themeBuilder";