From 29b5643310570f4f1b03f55acafd59166b08fc00 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Wed, 13 Mar 2024 09:21:57 +1000 Subject: [PATCH] =?UTF-8?q?[AC-2278]=C2=A0[BEEEP]=20Typesafe=20Angular=20D?= =?UTF-8?q?I=20(#8206)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use SafeProvider as a factory for all our providers to ensure that the DI token, implementation, and deps all match. --------- Co-authored-by: Matt Gibson --- .../app/services/desktop-theming.service.ts | 3 - .../src/app/services/services.module.ts | 8 +- .../services/theming/theming.service.ts | 9 +- .../src/platform/utils/safe-provider.ts | 114 ++ libs/angular/src/services/injection-tokens.ts | 39 +- .../src/services/jslib-services.module.ts | 1539 +++++++++-------- 6 files changed, 928 insertions(+), 784 deletions(-) create mode 100644 libs/angular/src/platform/utils/safe-provider.ts diff --git a/apps/desktop/src/app/services/desktop-theming.service.ts b/apps/desktop/src/app/services/desktop-theming.service.ts index 2d0e19eae3..005ef4ccc0 100644 --- a/apps/desktop/src/app/services/desktop-theming.service.ts +++ b/apps/desktop/src/app/services/desktop-theming.service.ts @@ -1,9 +1,6 @@ -import { Injectable } from "@angular/core"; - import { ThemingService } from "@bitwarden/angular/platform/services/theming/theming.service"; import { ThemeType } from "@bitwarden/common/platform/enums"; -@Injectable() export class DesktopThemingService extends ThemingService { protected async getSystemTheme(): Promise { return await ipc.platform.getSystemTheme(); diff --git a/apps/desktop/src/app/services/services.module.ts b/apps/desktop/src/app/services/services.module.ts index efc93d698b..7a64408b5e 100644 --- a/apps/desktop/src/app/services/services.module.ts +++ b/apps/desktop/src/app/services/services.module.ts @@ -1,6 +1,8 @@ +import { DOCUMENT } from "@angular/common"; import { APP_INITIALIZER, InjectionToken, NgModule } from "@angular/core"; import { AbstractThemingService } from "@bitwarden/angular/platform/services/theming/theming.service.abstraction"; +import { safeProvider } from "@bitwarden/angular/platform/utils/safe-provider"; import { SECURE_STORAGE, STATE_FACTORY, @@ -11,6 +13,7 @@ import { OBSERVABLE_MEMORY_STORAGE, OBSERVABLE_DISK_STORAGE, WINDOW, + SafeInjectionToken, } from "@bitwarden/angular/services/injection-tokens"; import { JslibServicesModule } from "@bitwarden/angular/services/jslib-services.module"; import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout-settings.service"; @@ -148,10 +151,11 @@ const RELOAD_CALLBACK = new InjectionToken<() => any>("RELOAD_CALLBACK"); provide: FileDownloadService, useClass: DesktopFileDownloadService, }, - { + safeProvider({ provide: AbstractThemingService, useClass: DesktopThemingService, - }, + deps: [StateServiceAbstraction, WINDOW, DOCUMENT as SafeInjectionToken], + }), { provide: EncryptedMessageHandlerService, deps: [ diff --git a/libs/angular/src/platform/services/theming/theming.service.ts b/libs/angular/src/platform/services/theming/theming.service.ts index 6ee85e9ad7..5274abb607 100644 --- a/libs/angular/src/platform/services/theming/theming.service.ts +++ b/libs/angular/src/platform/services/theming/theming.service.ts @@ -1,25 +1,20 @@ -import { DOCUMENT } from "@angular/common"; -import { Inject, Injectable } from "@angular/core"; import { BehaviorSubject, filter, fromEvent, Observable } from "rxjs"; import { StateService } from "@bitwarden/common/platform/abstractions/state.service"; import { ThemeType } from "@bitwarden/common/platform/enums"; -import { WINDOW } from "../../../services/injection-tokens"; - import { Theme } from "./theme"; import { ThemeBuilder } from "./theme-builder"; import { AbstractThemingService } from "./theming.service.abstraction"; -@Injectable() export class ThemingService implements AbstractThemingService { private _theme = new BehaviorSubject(null); theme$: Observable = this._theme.pipe(filter((x) => x !== null)); constructor( private stateService: StateService, - @Inject(WINDOW) private window: Window, - @Inject(DOCUMENT) private document: Document, + private window: Window, + private document: Document, ) { // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. // eslint-disable-next-line @typescript-eslint/no-floating-promises diff --git a/libs/angular/src/platform/utils/safe-provider.ts b/libs/angular/src/platform/utils/safe-provider.ts new file mode 100644 index 0000000000..65ce49cda9 --- /dev/null +++ b/libs/angular/src/platform/utils/safe-provider.ts @@ -0,0 +1,114 @@ +import { Provider } from "@angular/core"; +import { Constructor, Opaque } from "type-fest"; + +import { SafeInjectionToken } from "../../services/injection-tokens"; + +/** + * The return type of our dependency helper functions. + * Used to distinguish a type safe provider definition from a non-type safe provider definition. + */ +export type SafeProvider = Opaque; + +// TODO: type-fest also provides a type like this when we upgrade >= 3.7.0 +type AbstractConstructor = abstract new (...args: any) => T; + +type MapParametersToDeps = { + [K in keyof T]: AbstractConstructor | SafeInjectionToken; +}; + +type SafeInjectionTokenType = T extends SafeInjectionToken ? J : never; + +/** + * Represents a dependency provided with the useClass option. + */ +type SafeClassProvider< + A extends AbstractConstructor, + I extends Constructor>, + D extends MapParametersToDeps>, +> = { + provide: A; + useClass: I; + deps: D; +}; + +/** + * Represents a dependency provided with the useValue option. + */ +type SafeValueProvider, V extends SafeInjectionTokenType> = { + provide: A; + useValue: V; +}; + +/** + * Represents a dependency provided with the useFactory option where a SafeInjectionToken is used as the token. + */ +type SafeFactoryProviderWithToken< + A extends SafeInjectionToken, + I extends (...args: any) => InstanceType>, + D extends MapParametersToDeps>, +> = { + provide: A; + useFactory: I; + deps: D; +}; + +/** + * Represents a dependency provided with the useFactory option where an abstract class is used as the token. + */ +type SafeFactoryProviderWithClass< + A extends AbstractConstructor, + I extends (...args: any) => InstanceType, + D extends MapParametersToDeps>, +> = { + provide: A; + useFactory: I; + deps: D; +}; + +/** + * Represents a dependency provided with the useExisting option. + */ +type SafeExistingProvider< + A extends Constructor | AbstractConstructor, + I extends Constructor> | AbstractConstructor>, +> = { + provide: A; + useExisting: I; +}; + +/** + * A factory function that creates a provider for the ngModule providers array. + * This guarantees type safety for your provider definition. It does nothing at runtime. + * @param provider Your provider object in the usual shape (e.g. using useClass, useValue, useFactory, etc.) + * @returns The exact same object without modification (pass-through). + */ +export const safeProvider = < + // types for useClass + AClass extends AbstractConstructor, + IClass extends Constructor>, + DClass extends MapParametersToDeps>, + // types for useValue + AValue extends SafeInjectionToken, + VValue extends SafeInjectionTokenType, + // types for useFactoryWithToken + AFactoryToken extends SafeInjectionToken, + IFactoryToken extends (...args: any) => InstanceType>, + DFactoryToken extends MapParametersToDeps>, + // types for useFactoryWithClass + AFactoryClass extends AbstractConstructor, + IFactoryClass extends (...args: any) => InstanceType, + DFactoryClass extends MapParametersToDeps>, + // types for useExisting + AExisting extends Constructor | AbstractConstructor, + IExisting extends + | Constructor> + | AbstractConstructor>, +>( + provider: + | SafeClassProvider + | SafeValueProvider + | SafeFactoryProviderWithToken + | SafeFactoryProviderWithClass + | SafeExistingProvider + | Constructor, +): SafeProvider => provider as SafeProvider; diff --git a/libs/angular/src/services/injection-tokens.ts b/libs/angular/src/services/injection-tokens.ts index f069d9b5f3..b2c2299c34 100644 --- a/libs/angular/src/services/injection-tokens.ts +++ b/libs/angular/src/services/injection-tokens.ts @@ -7,26 +7,39 @@ import { } from "@bitwarden/common/platform/abstractions/storage.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; -export const WINDOW = new InjectionToken("WINDOW"); -export const OBSERVABLE_MEMORY_STORAGE = new InjectionToken< +declare const tag: unique symbol; +/** + * A (more) typesafe version of InjectionToken which will more strictly enforce the generic type parameter. + * @remarks The default angular implementation does not use the generic type to define the structure of the object, + * so the structural type system will not complain about a mismatch in the type parameter. + * This is solved by assigning T to an arbitrary private property. + */ +export class SafeInjectionToken extends InjectionToken { + private readonly [tag]: T; +} + +export const WINDOW = new SafeInjectionToken("WINDOW"); +export const OBSERVABLE_MEMORY_STORAGE = new SafeInjectionToken< AbstractMemoryStorageService & ObservableStorageService >("OBSERVABLE_MEMORY_STORAGE"); -export const OBSERVABLE_DISK_STORAGE = new InjectionToken< +export const OBSERVABLE_DISK_STORAGE = new SafeInjectionToken< AbstractStorageService & ObservableStorageService >("OBSERVABLE_DISK_STORAGE"); -export const OBSERVABLE_DISK_LOCAL_STORAGE = new InjectionToken< +export const OBSERVABLE_DISK_LOCAL_STORAGE = new SafeInjectionToken< AbstractStorageService & ObservableStorageService >("OBSERVABLE_DISK_LOCAL_STORAGE"); -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< +export const MEMORY_STORAGE = new SafeInjectionToken( + "MEMORY_STORAGE", +); +export const SECURE_STORAGE = new SafeInjectionToken("SECURE_STORAGE"); +export const STATE_FACTORY = new SafeInjectionToken("STATE_FACTORY"); +export const STATE_SERVICE_USE_CACHE = new SafeInjectionToken("STATE_SERVICE_USE_CACHE"); +export const LOGOUT_CALLBACK = new SafeInjectionToken< (expired: boolean, userId?: string) => Promise >("LOGOUT_CALLBACK"); -export const LOCKED_CALLBACK = new InjectionToken<(userId?: string) => Promise>( +export const LOCKED_CALLBACK = new SafeInjectionToken<(userId?: string) => Promise>( "LOCKED_CALLBACK", ); -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"); +export const LOCALES_DIRECTORY = new SafeInjectionToken("LOCALES_DIRECTORY"); +export const SYSTEM_LANGUAGE = new SafeInjectionToken("SYSTEM_LANGUAGE"); +export const LOG_MAC_FAILURES = new SafeInjectionToken("LOG_MAC_FAILURES"); diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index b78feb7038..a568befc71 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -1,4 +1,6 @@ +import { DOCUMENT } from "@angular/common"; import { LOCALE_ID, NgModule } from "@angular/core"; +import { UnwrapOpaque } from "type-fest"; import { AuthRequestServiceAbstraction, @@ -183,7 +185,10 @@ import { import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service"; import { SendApiService as SendApiServiceAbstraction } from "@bitwarden/common/tools/send/services/send-api.service.abstraction"; import { SendService } from "@bitwarden/common/tools/send/services/send.service"; -import { SendService as SendServiceAbstraction } from "@bitwarden/common/tools/send/services/send.service.abstraction"; +import { + InternalSendService, + SendService as SendServiceAbstraction, +} from "@bitwarden/common/tools/send/services/send.service.abstraction"; import { CipherService as CipherServiceAbstraction } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CollectionService as CollectionServiceAbstraction } from "@bitwarden/common/vault/abstractions/collection.service"; import { CipherFileUploadService as CipherFileUploadServiceAbstraction } from "@bitwarden/common/vault/abstractions/file-upload/cipher-file-upload.service"; @@ -228,6 +233,7 @@ import { BroadcasterService } from "../platform/services/broadcaster.service"; import { FormValidationErrorsService } from "../platform/services/form-validation-errors.service"; import { ThemingService } from "../platform/services/theming/theming.service"; import { AbstractThemingService } from "../platform/services/theming/theming.service.abstraction"; +import { safeProvider, SafeProvider } from "../platform/utils/safe-provider"; import { LOCALES_DIRECTORY, @@ -237,6 +243,7 @@ import { MEMORY_STORAGE, OBSERVABLE_DISK_STORAGE, OBSERVABLE_MEMORY_STORAGE, + SafeInjectionToken, SECURE_STORAGE, STATE_FACTORY, STATE_SERVICE_USE_CACHE, @@ -245,764 +252,771 @@ import { } from "./injection-tokens"; import { ModalService } from "./modal.service"; -@NgModule({ - declarations: [], - providers: [ - AuthGuard, - UnauthGuard, - ModalService, - PasswordRepromptService, - - { provide: WINDOW, useValue: window }, - { - provide: LOCALE_ID, - useFactory: (i18nService: I18nServiceAbstraction) => i18nService.translationLocale, - deps: [I18nServiceAbstraction], - }, - { - provide: LOCALES_DIRECTORY, - useValue: "./locales", - }, - { - provide: SYSTEM_LANGUAGE, - useFactory: (window: Window) => window.navigator.language, - deps: [WINDOW], - }, - { - provide: STATE_FACTORY, - useValue: new StateFactory(GlobalState, Account), - }, - { - provide: STATE_SERVICE_USE_CACHE, - useValue: true, - }, - { - provide: LOGOUT_CALLBACK, - useFactory: - (messagingService: MessagingServiceAbstraction) => (expired: boolean, userId?: string) => - messagingService.send("logout", { expired: expired, userId: userId }), - deps: [MessagingServiceAbstraction], - }, - { - provide: LOCKED_CALLBACK, - useValue: null, - }, - { - provide: LOG_MAC_FAILURES, - useValue: true, - }, - { - provide: AppIdServiceAbstraction, - useClass: AppIdService, - deps: [GlobalStateProvider], - }, - { - provide: AuditServiceAbstraction, - useClass: AuditService, - deps: [CryptoFunctionServiceAbstraction, ApiServiceAbstraction], - }, - { - provide: AuthServiceAbstraction, - useClass: AuthService, - deps: [ - MessagingServiceAbstraction, - CryptoServiceAbstraction, - ApiServiceAbstraction, - StateServiceAbstraction, - ], - }, - { - provide: LoginStrategyServiceAbstraction, - useClass: LoginStrategyService, - deps: [ - CryptoServiceAbstraction, - ApiServiceAbstraction, - TokenServiceAbstraction, - AppIdServiceAbstraction, - PlatformUtilsServiceAbstraction, - MessagingServiceAbstraction, - LogService, - KeyConnectorServiceAbstraction, - EnvironmentServiceAbstraction, - StateServiceAbstraction, - TwoFactorServiceAbstraction, - I18nServiceAbstraction, - EncryptService, - PasswordStrengthServiceAbstraction, - PolicyServiceAbstraction, - DeviceTrustCryptoServiceAbstraction, - AuthRequestServiceAbstraction, - GlobalStateProvider, - ], - }, - { - provide: FileUploadServiceAbstraction, - useClass: FileUploadService, - deps: [LoginServiceAbstraction], - }, - { - provide: CipherFileUploadServiceAbstraction, - useClass: CipherFileUploadService, - deps: [ApiServiceAbstraction, FileUploadServiceAbstraction], - }, - { - provide: CipherServiceAbstraction, - useFactory: ( - cryptoService: CryptoServiceAbstraction, - domainSettingsService: DomainSettingsService, - apiService: ApiServiceAbstraction, - i18nService: I18nServiceAbstraction, - searchService: SearchServiceAbstraction, - stateService: StateServiceAbstraction, - autofillSettingsService: AutofillSettingsServiceAbstraction, - encryptService: EncryptService, - fileUploadService: CipherFileUploadServiceAbstraction, - configService: ConfigServiceAbstraction, - ) => - new CipherService( - cryptoService, - domainSettingsService, - apiService, - i18nService, - searchService, - stateService, - autofillSettingsService, - encryptService, - fileUploadService, - configService, - ), - deps: [ - CryptoServiceAbstraction, - DomainSettingsService, - ApiServiceAbstraction, - I18nServiceAbstraction, - SearchServiceAbstraction, - StateServiceAbstraction, - AutofillSettingsServiceAbstraction, - EncryptService, - CipherFileUploadServiceAbstraction, - ConfigServiceAbstraction, - ], - }, - { - provide: FolderServiceAbstraction, - useClass: FolderService, - deps: [ - CryptoServiceAbstraction, - I18nServiceAbstraction, - CipherServiceAbstraction, - StateServiceAbstraction, - StateProvider, - ], - }, - { - provide: InternalFolderService, - useExisting: FolderServiceAbstraction, - }, - { - provide: FolderApiServiceAbstraction, - useClass: FolderApiService, - deps: [FolderServiceAbstraction, ApiServiceAbstraction], - }, - { - provide: AccountApiServiceAbstraction, - useClass: AccountApiServiceImplementation, - deps: [ - ApiServiceAbstraction, - UserVerificationServiceAbstraction, - LogService, - InternalAccountService, - ], - }, - { - provide: AccountServiceAbstraction, - useClass: AccountServiceImplementation, - deps: [MessagingServiceAbstraction, LogService, GlobalStateProvider], - }, - { - provide: InternalAccountService, - useExisting: AccountServiceAbstraction, - }, - { - provide: AccountUpdateServiceAbstraction, - useClass: AvatarUpdateService, - deps: [ApiServiceAbstraction, StateServiceAbstraction], - }, - { provide: LogService, useFactory: () => new ConsoleLogService(false) }, - { - provide: CollectionServiceAbstraction, - useClass: CollectionService, - deps: [CryptoServiceAbstraction, I18nServiceAbstraction, StateProvider], - }, - { - provide: EnvironmentServiceAbstraction, - useClass: EnvironmentService, - deps: [StateProvider, AccountServiceAbstraction], - }, - { - provide: TotpServiceAbstraction, - useClass: TotpService, - deps: [CryptoFunctionServiceAbstraction, LogService, StateServiceAbstraction], - }, - { provide: TokenServiceAbstraction, useClass: TokenService, deps: [StateServiceAbstraction] }, - { - provide: KeyGenerationServiceAbstraction, - useClass: KeyGenerationService, - deps: [CryptoFunctionServiceAbstraction], - }, - { - provide: CryptoServiceAbstraction, - useClass: CryptoService, - deps: [ - KeyGenerationServiceAbstraction, - CryptoFunctionServiceAbstraction, - EncryptService, - PlatformUtilsServiceAbstraction, - LogService, - StateServiceAbstraction, - AccountServiceAbstraction, - StateProvider, - ], - }, - { - provide: PasswordStrengthServiceAbstraction, - useClass: PasswordStrengthService, - deps: [], - }, - { - provide: PasswordGenerationServiceAbstraction, - useClass: PasswordGenerationService, - deps: [CryptoServiceAbstraction, PolicyServiceAbstraction, StateServiceAbstraction], - }, - { - provide: UsernameGenerationServiceAbstraction, - useClass: UsernameGenerationService, - deps: [CryptoServiceAbstraction, StateServiceAbstraction, ApiServiceAbstraction], - }, - { - provide: ApiServiceAbstraction, - useClass: ApiService, - deps: [ - TokenServiceAbstraction, - PlatformUtilsServiceAbstraction, - EnvironmentServiceAbstraction, - AppIdServiceAbstraction, - LOGOUT_CALLBACK, - ], - }, - { - provide: SendServiceAbstraction, - useClass: SendService, - deps: [ - CryptoServiceAbstraction, - I18nServiceAbstraction, - KeyGenerationServiceAbstraction, - StateServiceAbstraction, - ], - }, - { - provide: SendApiServiceAbstraction, - useClass: SendApiService, - deps: [ApiServiceAbstraction, FileUploadServiceAbstraction, SendServiceAbstraction], - }, - { - provide: SyncServiceAbstraction, - useClass: SyncService, - deps: [ - ApiServiceAbstraction, - SettingsServiceAbstraction, - FolderServiceAbstraction, - CipherServiceAbstraction, - CryptoServiceAbstraction, - CollectionServiceAbstraction, - MessagingServiceAbstraction, - PolicyServiceAbstraction, - SendServiceAbstraction, - LogService, - KeyConnectorServiceAbstraction, - StateServiceAbstraction, - ProviderServiceAbstraction, - FolderApiServiceAbstraction, - OrganizationServiceAbstraction, - SendApiServiceAbstraction, - LOGOUT_CALLBACK, - ], - }, - { provide: BroadcasterServiceAbstraction, useClass: BroadcasterService }, - { - provide: SettingsServiceAbstraction, - useClass: SettingsService, - deps: [StateServiceAbstraction], - }, - { - provide: VaultTimeoutSettingsServiceAbstraction, - useClass: VaultTimeoutSettingsService, - deps: [ - CryptoServiceAbstraction, - TokenServiceAbstraction, - PolicyServiceAbstraction, - StateServiceAbstraction, - BiometricStateService, - ], - }, - { - provide: VaultTimeoutService, - useClass: VaultTimeoutService, - deps: [ - CipherServiceAbstraction, - FolderServiceAbstraction, - CollectionServiceAbstraction, - CryptoServiceAbstraction, - PlatformUtilsServiceAbstraction, - MessagingServiceAbstraction, - SearchServiceAbstraction, - StateServiceAbstraction, - AuthServiceAbstraction, - VaultTimeoutSettingsServiceAbstraction, - StateEventRunnerService, - LOCKED_CALLBACK, - LOGOUT_CALLBACK, - ], - }, - { - provide: VaultTimeoutServiceAbstraction, - useExisting: VaultTimeoutService, - }, - { - provide: SsoLoginServiceAbstraction, - useClass: SsoLoginService, - deps: [StateProvider], - }, - { - provide: StateServiceAbstraction, - useClass: StateService, - deps: [ - AbstractStorageService, - SECURE_STORAGE, - MEMORY_STORAGE, - LogService, - STATE_FACTORY, - AccountServiceAbstraction, - EnvironmentServiceAbstraction, - MigrationRunner, - STATE_SERVICE_USE_CACHE, - ], - }, - { - provide: ImportApiServiceAbstraction, - useClass: ImportApiService, - deps: [ApiServiceAbstraction], - }, - { - provide: ImportServiceAbstraction, - useClass: ImportService, - deps: [ - CipherServiceAbstraction, - FolderServiceAbstraction, - ImportApiServiceAbstraction, - I18nServiceAbstraction, - CollectionServiceAbstraction, - CryptoServiceAbstraction, - ], - }, - { - provide: IndividualVaultExportServiceAbstraction, - useClass: IndividualVaultExportService, - deps: [ - FolderServiceAbstraction, - CipherServiceAbstraction, - CryptoServiceAbstraction, - CryptoFunctionServiceAbstraction, - StateServiceAbstraction, - ], - }, - { - provide: OrganizationVaultExportServiceAbstraction, - useClass: OrganizationVaultExportService, - deps: [ - CipherServiceAbstraction, - ApiServiceAbstraction, - CryptoServiceAbstraction, - CryptoFunctionServiceAbstraction, - StateServiceAbstraction, - CollectionServiceAbstraction, - ], - }, - { - provide: VaultExportServiceAbstraction, - useClass: VaultExportService, - deps: [IndividualVaultExportServiceAbstraction, OrganizationVaultExportServiceAbstraction], - }, - { - provide: SearchServiceAbstraction, - useClass: SearchService, - deps: [LogService, I18nServiceAbstraction], - }, - { - provide: NotificationsServiceAbstraction, - useClass: devFlagEnabled("noopNotifications") - ? NoopNotificationsService - : NotificationsService, - deps: [ - LogService, - SyncServiceAbstraction, - AppIdServiceAbstraction, - ApiServiceAbstraction, - EnvironmentServiceAbstraction, - LOGOUT_CALLBACK, - StateServiceAbstraction, - AuthServiceAbstraction, - MessagingServiceAbstraction, - ], - }, - { - provide: CryptoFunctionServiceAbstraction, - useClass: WebCryptoFunctionService, - deps: [WINDOW], - }, - { - provide: EncryptService, - useFactory: encryptServiceFactory, - deps: [CryptoFunctionServiceAbstraction, LogService, LOG_MAC_FAILURES], - }, - { - provide: EventUploadServiceAbstraction, - useClass: EventUploadService, - deps: [ApiServiceAbstraction, StateServiceAbstraction, LogService], - }, - { - provide: EventCollectionServiceAbstraction, - useClass: EventCollectionService, - deps: [ - CipherServiceAbstraction, - StateServiceAbstraction, - OrganizationServiceAbstraction, - EventUploadServiceAbstraction, - ], - }, - { - provide: PolicyServiceAbstraction, - useClass: PolicyService, - deps: [StateProvider, OrganizationServiceAbstraction], - }, - { - provide: InternalPolicyService, - useExisting: PolicyServiceAbstraction, - }, - { - provide: PolicyApiServiceAbstraction, - useClass: PolicyApiService, - deps: [InternalPolicyService, ApiServiceAbstraction], - }, - { - provide: KeyConnectorServiceAbstraction, - useClass: KeyConnectorService, - deps: [ - StateServiceAbstraction, - CryptoServiceAbstraction, - ApiServiceAbstraction, - TokenServiceAbstraction, - LogService, - OrganizationServiceAbstraction, - KeyGenerationServiceAbstraction, - LOGOUT_CALLBACK, - ], - }, - { - provide: UserVerificationServiceAbstraction, - useClass: UserVerificationService, - deps: [ - StateServiceAbstraction, - CryptoServiceAbstraction, - I18nServiceAbstraction, - UserVerificationApiServiceAbstraction, - PinCryptoServiceAbstraction, - LogService, - VaultTimeoutSettingsServiceAbstraction, - PlatformUtilsServiceAbstraction, - ], - }, - { - provide: OrganizationServiceAbstraction, - useClass: OrganizationService, - deps: [StateServiceAbstraction, StateProvider], - }, - { - provide: InternalOrganizationServiceAbstraction, - useExisting: OrganizationServiceAbstraction, - }, - { - provide: OrganizationUserService, - useClass: OrganizationUserServiceImplementation, - deps: [ApiServiceAbstraction], - }, - { - provide: PasswordResetEnrollmentServiceAbstraction, - useClass: PasswordResetEnrollmentServiceImplementation, - deps: [ - OrganizationApiServiceAbstraction, - AccountServiceAbstraction, - CryptoServiceAbstraction, - OrganizationUserService, - I18nServiceAbstraction, - ], - }, - { - provide: ProviderServiceAbstraction, - useClass: ProviderService, - deps: [StateProvider], - }, - { - provide: TwoFactorServiceAbstraction, - useClass: TwoFactorService, - deps: [I18nServiceAbstraction, PlatformUtilsServiceAbstraction], - }, - { - provide: AbstractThemingService, - useClass: ThemingService, - }, - { - provide: FormValidationErrorsServiceAbstraction, - useClass: FormValidationErrorsService, - }, - { - provide: UserVerificationApiServiceAbstraction, - useClass: UserVerificationApiService, - deps: [ApiServiceAbstraction], - }, - { - provide: OrganizationApiServiceAbstraction, - useClass: OrganizationApiService, - // This is a slightly odd dependency tree for a specialized api service - // it depends on SyncService so that new data can be retrieved through the sync - // rather than updating the OrganizationService directly. Instead OrganizationService - // subscribes to sync notifications and will update itself based on that. - deps: [ApiServiceAbstraction, SyncServiceAbstraction], - }, - { - provide: SyncNotifierServiceAbstraction, - useClass: SyncNotifierService, - }, - { - provide: ConfigService, - useClass: ConfigService, - deps: [ - StateServiceAbstraction, - ConfigApiServiceAbstraction, - AuthServiceAbstraction, - EnvironmentServiceAbstraction, - LogService, - ], - }, - { - provide: ConfigServiceAbstraction, - useExisting: ConfigService, - }, - { - provide: ConfigApiServiceAbstraction, - useClass: ConfigApiService, - deps: [ApiServiceAbstraction, AuthServiceAbstraction], - }, - { - provide: AnonymousHubServiceAbstraction, - useClass: AnonymousHubService, - deps: [EnvironmentServiceAbstraction, LoginStrategyServiceAbstraction, LogService], - }, - { - provide: ValidationServiceAbstraction, - useClass: ValidationService, - deps: [I18nServiceAbstraction, PlatformUtilsServiceAbstraction], - }, - { - provide: LoginServiceAbstraction, - useClass: LoginService, - deps: [StateServiceAbstraction], - }, - { - provide: OrgDomainServiceAbstraction, - useClass: OrgDomainService, - deps: [PlatformUtilsServiceAbstraction, I18nServiceAbstraction], - }, - { - provide: OrgDomainInternalServiceAbstraction, - useExisting: OrgDomainServiceAbstraction, - }, - { - provide: OrgDomainApiServiceAbstraction, - useClass: OrgDomainApiService, - deps: [OrgDomainServiceAbstraction, ApiServiceAbstraction], - }, - { - provide: DevicesApiServiceAbstraction, - useClass: DevicesApiServiceImplementation, - deps: [ApiServiceAbstraction], - }, - { - provide: DevicesServiceAbstraction, - useClass: DevicesServiceImplementation, - deps: [DevicesApiServiceAbstraction], - }, - { - provide: DeviceTrustCryptoServiceAbstraction, - useClass: DeviceTrustCryptoService, - deps: [ - KeyGenerationServiceAbstraction, - CryptoFunctionServiceAbstraction, - CryptoServiceAbstraction, - EncryptService, - StateServiceAbstraction, - AppIdServiceAbstraction, - DevicesApiServiceAbstraction, - I18nServiceAbstraction, - PlatformUtilsServiceAbstraction, - ], - }, - { - provide: AuthRequestServiceAbstraction, - useClass: AuthRequestService, - deps: [ - AppIdServiceAbstraction, - CryptoServiceAbstraction, - ApiServiceAbstraction, - StateServiceAbstraction, - ], - }, - { - provide: PinCryptoServiceAbstraction, - useClass: PinCryptoService, - deps: [ - StateServiceAbstraction, - CryptoServiceAbstraction, - VaultTimeoutSettingsServiceAbstraction, - LogService, - ], - }, - - { - provide: WebAuthnLoginPrfCryptoServiceAbstraction, - useClass: WebAuthnLoginPrfCryptoService, - deps: [CryptoFunctionServiceAbstraction], - }, - { - provide: WebAuthnLoginApiServiceAbstraction, - useClass: WebAuthnLoginApiService, - deps: [ApiServiceAbstraction, EnvironmentServiceAbstraction], - }, - { - provide: WebAuthnLoginServiceAbstraction, - useClass: WebAuthnLoginService, - deps: [ - WebAuthnLoginApiServiceAbstraction, - LoginStrategyServiceAbstraction, - WebAuthnLoginPrfCryptoServiceAbstraction, - WINDOW, - LogService, - ], - }, - { - provide: StorageServiceProvider, - useClass: StorageServiceProvider, - deps: [OBSERVABLE_DISK_STORAGE, OBSERVABLE_MEMORY_STORAGE], - }, - { - provide: StateEventRegistrarService, - useClass: StateEventRegistrarService, - deps: [GlobalStateProvider, StorageServiceProvider], - }, - { - provide: StateEventRunnerService, - useClass: StateEventRunnerService, - deps: [GlobalStateProvider, StorageServiceProvider], - }, - { - provide: GlobalStateProvider, - useClass: DefaultGlobalStateProvider, - deps: [StorageServiceProvider], - }, - { - provide: ActiveUserStateProvider, - useClass: DefaultActiveUserStateProvider, - deps: [AccountServiceAbstraction, StorageServiceProvider, StateEventRegistrarService], - }, - { - provide: SingleUserStateProvider, - useClass: DefaultSingleUserStateProvider, - deps: [StorageServiceProvider, StateEventRegistrarService], - }, - { - provide: DerivedStateProvider, - useClass: DefaultDerivedStateProvider, - deps: [OBSERVABLE_MEMORY_STORAGE], - }, - { - provide: StateProvider, - useClass: DefaultStateProvider, - deps: [ - ActiveUserStateProvider, - SingleUserStateProvider, - GlobalStateProvider, - DerivedStateProvider, - ], - }, - { - provide: OrganizationBillingServiceAbstraction, - useClass: OrganizationBillingService, - deps: [ - CryptoServiceAbstraction, - EncryptService, - I18nServiceAbstraction, - OrganizationApiServiceAbstraction, - OrganizationServiceAbstraction, - StateProvider, - ], - }, - { - provide: AutofillSettingsServiceAbstraction, - useClass: AutofillSettingsService, - deps: [StateProvider, PolicyServiceAbstraction], - }, - { - provide: BadgeSettingsServiceAbstraction, - useClass: BadgeSettingsService, - deps: [StateProvider], - }, - { - provide: DomainSettingsService, - useClass: DefaultDomainSettingsService, - deps: [StateProvider], - }, - { - provide: BiometricStateService, - useClass: DefaultBiometricStateService, - deps: [StateProvider], - }, - { - provide: VaultSettingsServiceAbstraction, - useClass: VaultSettingsService, - deps: [StateProvider], - }, - { - provide: MigrationRunner, - useClass: MigrationRunner, - deps: [AbstractStorageService, LogService, MigrationBuilderService], - }, - { - provide: MigrationBuilderService, - useClass: MigrationBuilderService, - }, - { - provide: BillingApiServiceAbstraction, - useClass: BillingApiService, - deps: [ApiServiceAbstraction], - }, - { - provide: PaymentMethodWarningsServiceAbstraction, - useClass: PaymentMethodWarningsService, - deps: [BillingApiServiceAbstraction, StateProvider], - }, - ], -}) -export class JslibServicesModule {} +/** + * Provider definitions used in the ngModule. + * Add your provider definition here using the safeProvider function as a wrapper. This will give you type safety. + * If you need help please ask for it, do NOT change the type of this array. + */ +const typesafeProviders: Array = [ + safeProvider(AuthGuard), + safeProvider(UnauthGuard), + safeProvider(ModalService), + safeProvider(PasswordRepromptService), + safeProvider({ provide: WINDOW, useValue: window }), + safeProvider({ + provide: LOCALE_ID as SafeInjectionToken, + useFactory: (i18nService: I18nServiceAbstraction) => i18nService.translationLocale, + deps: [I18nServiceAbstraction], + }), + safeProvider({ + provide: LOCALES_DIRECTORY, + useValue: "./locales", + }), + safeProvider({ + provide: SYSTEM_LANGUAGE, + useFactory: (window: Window) => window.navigator.language, + deps: [WINDOW], + }), + safeProvider({ + provide: STATE_FACTORY, + useValue: new StateFactory(GlobalState, Account), + }), + safeProvider({ + provide: STATE_SERVICE_USE_CACHE, + useValue: true, + }), + safeProvider({ + provide: LOGOUT_CALLBACK, + useFactory: + (messagingService: MessagingServiceAbstraction) => (expired: boolean, userId?: string) => + Promise.resolve(messagingService.send("logout", { expired: expired, userId: userId })), + deps: [MessagingServiceAbstraction], + }), + safeProvider({ + provide: LOCKED_CALLBACK, + useValue: null, + }), + safeProvider({ + provide: LOG_MAC_FAILURES, + useValue: true, + }), + safeProvider({ + provide: AppIdServiceAbstraction, + useClass: AppIdService, + deps: [GlobalStateProvider], + }), + safeProvider({ + provide: AuditServiceAbstraction, + useClass: AuditService, + deps: [CryptoFunctionServiceAbstraction, ApiServiceAbstraction], + }), + safeProvider({ + provide: AuthServiceAbstraction, + useClass: AuthService, + deps: [ + MessagingServiceAbstraction, + CryptoServiceAbstraction, + ApiServiceAbstraction, + StateServiceAbstraction, + ], + }), + safeProvider({ + provide: LoginStrategyServiceAbstraction, + useClass: LoginStrategyService, + deps: [ + CryptoServiceAbstraction, + ApiServiceAbstraction, + TokenServiceAbstraction, + AppIdServiceAbstraction, + PlatformUtilsServiceAbstraction, + MessagingServiceAbstraction, + LogService, + KeyConnectorServiceAbstraction, + EnvironmentServiceAbstraction, + StateServiceAbstraction, + TwoFactorServiceAbstraction, + I18nServiceAbstraction, + EncryptService, + PasswordStrengthServiceAbstraction, + PolicyServiceAbstraction, + DeviceTrustCryptoServiceAbstraction, + AuthRequestServiceAbstraction, + GlobalStateProvider, + ], + }), + safeProvider({ + provide: FileUploadServiceAbstraction, + useClass: FileUploadService, + deps: [LogService], + }), + safeProvider({ + provide: CipherFileUploadServiceAbstraction, + useClass: CipherFileUploadService, + deps: [ApiServiceAbstraction, FileUploadServiceAbstraction], + }), + safeProvider({ + provide: CipherServiceAbstraction, + useFactory: ( + cryptoService: CryptoServiceAbstraction, + domainSettingsService: DomainSettingsService, + apiService: ApiServiceAbstraction, + i18nService: I18nServiceAbstraction, + searchService: SearchServiceAbstraction, + stateService: StateServiceAbstraction, + autofillSettingsService: AutofillSettingsServiceAbstraction, + encryptService: EncryptService, + fileUploadService: CipherFileUploadServiceAbstraction, + configService: ConfigServiceAbstraction, + ) => + new CipherService( + cryptoService, + domainSettingsService, + apiService, + i18nService, + searchService, + stateService, + autofillSettingsService, + encryptService, + fileUploadService, + configService, + ), + deps: [ + CryptoServiceAbstraction, + DomainSettingsService, + ApiServiceAbstraction, + I18nServiceAbstraction, + SearchServiceAbstraction, + StateServiceAbstraction, + AutofillSettingsServiceAbstraction, + EncryptService, + CipherFileUploadServiceAbstraction, + ConfigServiceAbstraction, + ], + }), + safeProvider({ + provide: InternalFolderService, + useClass: FolderService, + deps: [ + CryptoServiceAbstraction, + I18nServiceAbstraction, + CipherServiceAbstraction, + StateServiceAbstraction, + StateProvider, + ], + }), + safeProvider({ + provide: FolderServiceAbstraction, + useExisting: InternalFolderService, + }), + safeProvider({ + provide: FolderApiServiceAbstraction, + useClass: FolderApiService, + deps: [InternalFolderService, ApiServiceAbstraction], + }), + safeProvider({ + provide: AccountApiServiceAbstraction, + useClass: AccountApiServiceImplementation, + deps: [ + ApiServiceAbstraction, + UserVerificationServiceAbstraction, + LogService, + InternalAccountService, + ], + }), + safeProvider({ + provide: InternalAccountService, + useClass: AccountServiceImplementation, + deps: [MessagingServiceAbstraction, LogService, GlobalStateProvider], + }), + safeProvider({ + provide: AccountServiceAbstraction, + useExisting: InternalAccountService, + }), + safeProvider({ + provide: AccountUpdateServiceAbstraction, + useClass: AvatarUpdateService, + deps: [ApiServiceAbstraction, StateServiceAbstraction], + }), + safeProvider({ provide: LogService, useFactory: () => new ConsoleLogService(false), deps: [] }), + safeProvider({ + provide: CollectionServiceAbstraction, + useClass: CollectionService, + deps: [CryptoServiceAbstraction, I18nServiceAbstraction, StateProvider], + }), + safeProvider({ + provide: EnvironmentServiceAbstraction, + useClass: EnvironmentService, + deps: [StateProvider, AccountServiceAbstraction], + }), + safeProvider({ + provide: TotpServiceAbstraction, + useClass: TotpService, + deps: [CryptoFunctionServiceAbstraction, LogService], + }), + safeProvider({ + provide: TokenServiceAbstraction, + useClass: TokenService, + deps: [StateServiceAbstraction], + }), + safeProvider({ + provide: KeyGenerationServiceAbstraction, + useClass: KeyGenerationService, + deps: [CryptoFunctionServiceAbstraction], + }), + safeProvider({ + provide: CryptoServiceAbstraction, + useClass: CryptoService, + deps: [ + KeyGenerationServiceAbstraction, + CryptoFunctionServiceAbstraction, + EncryptService, + PlatformUtilsServiceAbstraction, + LogService, + StateServiceAbstraction, + AccountServiceAbstraction, + StateProvider, + ], + }), + safeProvider({ + provide: PasswordStrengthServiceAbstraction, + useClass: PasswordStrengthService, + deps: [], + }), + safeProvider({ + provide: PasswordGenerationServiceAbstraction, + useClass: PasswordGenerationService, + deps: [CryptoServiceAbstraction, PolicyServiceAbstraction, StateServiceAbstraction], + }), + safeProvider({ + provide: UsernameGenerationServiceAbstraction, + useClass: UsernameGenerationService, + deps: [CryptoServiceAbstraction, StateServiceAbstraction, ApiServiceAbstraction], + }), + safeProvider({ + provide: ApiServiceAbstraction, + useClass: ApiService, + deps: [ + TokenServiceAbstraction, + PlatformUtilsServiceAbstraction, + EnvironmentServiceAbstraction, + AppIdServiceAbstraction, + LOGOUT_CALLBACK, + ], + }), + safeProvider({ + provide: SendServiceAbstraction, + useExisting: InternalSendService, + }), + safeProvider({ + provide: InternalSendService, + useClass: SendService, + deps: [ + CryptoServiceAbstraction, + I18nServiceAbstraction, + KeyGenerationServiceAbstraction, + StateServiceAbstraction, + ], + }), + safeProvider({ + provide: SendApiServiceAbstraction, + useClass: SendApiService, + deps: [ApiServiceAbstraction, FileUploadServiceAbstraction, InternalSendService], + }), + safeProvider({ + provide: SyncServiceAbstraction, + useClass: SyncService, + deps: [ + ApiServiceAbstraction, + DomainSettingsService, + InternalFolderService, + CipherServiceAbstraction, + CryptoServiceAbstraction, + CollectionServiceAbstraction, + MessagingServiceAbstraction, + InternalPolicyService, + InternalSendService, + LogService, + KeyConnectorServiceAbstraction, + StateServiceAbstraction, + ProviderServiceAbstraction, + FolderApiServiceAbstraction, + InternalOrganizationServiceAbstraction, + SendApiServiceAbstraction, + LOGOUT_CALLBACK, + ], + }), + safeProvider({ provide: BroadcasterServiceAbstraction, useClass: BroadcasterService, deps: [] }), + safeProvider({ + provide: SettingsServiceAbstraction, + useClass: SettingsService, + deps: [StateServiceAbstraction], + }), + safeProvider({ + provide: VaultTimeoutSettingsServiceAbstraction, + useClass: VaultTimeoutSettingsService, + deps: [ + CryptoServiceAbstraction, + TokenServiceAbstraction, + PolicyServiceAbstraction, + StateServiceAbstraction, + BiometricStateService, + ], + }), + safeProvider({ + provide: VaultTimeoutService, + useClass: VaultTimeoutService, + deps: [ + CipherServiceAbstraction, + FolderServiceAbstraction, + CollectionServiceAbstraction, + CryptoServiceAbstraction, + PlatformUtilsServiceAbstraction, + MessagingServiceAbstraction, + SearchServiceAbstraction, + StateServiceAbstraction, + AuthServiceAbstraction, + VaultTimeoutSettingsServiceAbstraction, + StateEventRunnerService, + LOCKED_CALLBACK, + LOGOUT_CALLBACK, + ], + }), + safeProvider({ + provide: VaultTimeoutServiceAbstraction, + useExisting: VaultTimeoutService, + }), + safeProvider({ + provide: SsoLoginServiceAbstraction, + useClass: SsoLoginService, + deps: [StateProvider], + }), + safeProvider({ + provide: StateServiceAbstraction, + useClass: StateService, + deps: [ + AbstractStorageService, + SECURE_STORAGE, + MEMORY_STORAGE, + LogService, + STATE_FACTORY, + AccountServiceAbstraction, + EnvironmentServiceAbstraction, + MigrationRunner, + STATE_SERVICE_USE_CACHE, + ], + }), + safeProvider({ + provide: ImportApiServiceAbstraction, + useClass: ImportApiService, + deps: [ApiServiceAbstraction], + }), + safeProvider({ + provide: ImportServiceAbstraction, + useClass: ImportService, + deps: [ + CipherServiceAbstraction, + FolderServiceAbstraction, + ImportApiServiceAbstraction, + I18nServiceAbstraction, + CollectionServiceAbstraction, + CryptoServiceAbstraction, + ], + }), + safeProvider({ + provide: IndividualVaultExportServiceAbstraction, + useClass: IndividualVaultExportService, + deps: [ + FolderServiceAbstraction, + CipherServiceAbstraction, + CryptoServiceAbstraction, + CryptoFunctionServiceAbstraction, + StateServiceAbstraction, + ], + }), + safeProvider({ + provide: OrganizationVaultExportServiceAbstraction, + useClass: OrganizationVaultExportService, + deps: [ + CipherServiceAbstraction, + ApiServiceAbstraction, + CryptoServiceAbstraction, + CryptoFunctionServiceAbstraction, + StateServiceAbstraction, + CollectionServiceAbstraction, + ], + }), + safeProvider({ + provide: VaultExportServiceAbstraction, + useClass: VaultExportService, + deps: [IndividualVaultExportServiceAbstraction, OrganizationVaultExportServiceAbstraction], + }), + safeProvider({ + provide: SearchServiceAbstraction, + useClass: SearchService, + deps: [LogService, I18nServiceAbstraction], + }), + safeProvider({ + provide: NotificationsServiceAbstraction, + useClass: devFlagEnabled("noopNotifications") ? NoopNotificationsService : NotificationsService, + deps: [ + LogService, + SyncServiceAbstraction, + AppIdServiceAbstraction, + ApiServiceAbstraction, + EnvironmentServiceAbstraction, + LOGOUT_CALLBACK, + StateServiceAbstraction, + AuthServiceAbstraction, + MessagingServiceAbstraction, + ], + }), + safeProvider({ + provide: CryptoFunctionServiceAbstraction, + useClass: WebCryptoFunctionService, + deps: [WINDOW], + }), + safeProvider({ + provide: EncryptService, + useFactory: encryptServiceFactory, + deps: [CryptoFunctionServiceAbstraction, LogService, LOG_MAC_FAILURES], + }), + safeProvider({ + provide: EventUploadServiceAbstraction, + useClass: EventUploadService, + deps: [ApiServiceAbstraction, StateServiceAbstraction, LogService], + }), + safeProvider({ + provide: EventCollectionServiceAbstraction, + useClass: EventCollectionService, + deps: [ + CipherServiceAbstraction, + StateServiceAbstraction, + OrganizationServiceAbstraction, + EventUploadServiceAbstraction, + ], + }), + safeProvider({ + provide: InternalPolicyService, + useClass: PolicyService, + deps: [StateProvider, OrganizationServiceAbstraction], + }), + safeProvider({ + provide: PolicyServiceAbstraction, + useExisting: InternalPolicyService, + }), + safeProvider({ + provide: PolicyApiServiceAbstraction, + useClass: PolicyApiService, + deps: [InternalPolicyService, ApiServiceAbstraction], + }), + safeProvider({ + provide: KeyConnectorServiceAbstraction, + useClass: KeyConnectorService, + deps: [ + StateServiceAbstraction, + CryptoServiceAbstraction, + ApiServiceAbstraction, + TokenServiceAbstraction, + LogService, + OrganizationServiceAbstraction, + KeyGenerationServiceAbstraction, + LOGOUT_CALLBACK, + ], + }), + safeProvider({ + provide: UserVerificationServiceAbstraction, + useClass: UserVerificationService, + deps: [ + StateServiceAbstraction, + CryptoServiceAbstraction, + I18nServiceAbstraction, + UserVerificationApiServiceAbstraction, + PinCryptoServiceAbstraction, + LogService, + VaultTimeoutSettingsServiceAbstraction, + PlatformUtilsServiceAbstraction, + ], + }), + safeProvider({ + provide: InternalOrganizationServiceAbstraction, + useClass: OrganizationService, + deps: [StateServiceAbstraction, StateProvider], + }), + safeProvider({ + provide: OrganizationServiceAbstraction, + useExisting: InternalOrganizationServiceAbstraction, + }), + safeProvider({ + provide: OrganizationUserService, + useClass: OrganizationUserServiceImplementation, + deps: [ApiServiceAbstraction], + }), + safeProvider({ + provide: PasswordResetEnrollmentServiceAbstraction, + useClass: PasswordResetEnrollmentServiceImplementation, + deps: [ + OrganizationApiServiceAbstraction, + AccountServiceAbstraction, + CryptoServiceAbstraction, + OrganizationUserService, + I18nServiceAbstraction, + ], + }), + safeProvider({ + provide: ProviderServiceAbstraction, + useClass: ProviderService, + deps: [StateProvider], + }), + safeProvider({ + provide: TwoFactorServiceAbstraction, + useClass: TwoFactorService, + deps: [I18nServiceAbstraction, PlatformUtilsServiceAbstraction], + }), + safeProvider({ + provide: AbstractThemingService, + useClass: ThemingService, + deps: [StateServiceAbstraction, WINDOW, DOCUMENT as SafeInjectionToken], + }), + safeProvider({ + provide: FormValidationErrorsServiceAbstraction, + useClass: FormValidationErrorsService, + deps: [], + }), + safeProvider({ + provide: UserVerificationApiServiceAbstraction, + useClass: UserVerificationApiService, + deps: [ApiServiceAbstraction], + }), + safeProvider({ + provide: OrganizationApiServiceAbstraction, + useClass: OrganizationApiService, + // This is a slightly odd dependency tree for a specialized api service + // it depends on SyncService so that new data can be retrieved through the sync + // rather than updating the OrganizationService directly. Instead OrganizationService + // subscribes to sync notifications and will update itself based on that. + deps: [ApiServiceAbstraction, SyncServiceAbstraction], + }), + safeProvider({ + provide: SyncNotifierServiceAbstraction, + useClass: SyncNotifierService, + deps: [], + }), + safeProvider({ + provide: ConfigService, + useClass: ConfigService, + deps: [ + StateServiceAbstraction, + ConfigApiServiceAbstraction, + AuthServiceAbstraction, + EnvironmentServiceAbstraction, + LogService, + ], + }), + safeProvider({ + provide: ConfigServiceAbstraction, + useExisting: ConfigService, + }), + safeProvider({ + provide: ConfigApiServiceAbstraction, + useClass: ConfigApiService, + deps: [ApiServiceAbstraction, AuthServiceAbstraction], + }), + safeProvider({ + provide: AnonymousHubServiceAbstraction, + useClass: AnonymousHubService, + deps: [EnvironmentServiceAbstraction, LoginStrategyServiceAbstraction, LogService], + }), + safeProvider({ + provide: ValidationServiceAbstraction, + useClass: ValidationService, + deps: [I18nServiceAbstraction, PlatformUtilsServiceAbstraction], + }), + safeProvider({ + provide: LoginServiceAbstraction, + useClass: LoginService, + deps: [StateServiceAbstraction], + }), + safeProvider({ + provide: OrgDomainInternalServiceAbstraction, + useClass: OrgDomainService, + deps: [PlatformUtilsServiceAbstraction, I18nServiceAbstraction], + }), + safeProvider({ + provide: OrgDomainServiceAbstraction, + useExisting: OrgDomainInternalServiceAbstraction, + }), + safeProvider({ + provide: OrgDomainApiServiceAbstraction, + useClass: OrgDomainApiService, + deps: [OrgDomainInternalServiceAbstraction, ApiServiceAbstraction], + }), + safeProvider({ + provide: DevicesApiServiceAbstraction, + useClass: DevicesApiServiceImplementation, + deps: [ApiServiceAbstraction], + }), + safeProvider({ + provide: DevicesServiceAbstraction, + useClass: DevicesServiceImplementation, + deps: [DevicesApiServiceAbstraction], + }), + safeProvider({ + provide: DeviceTrustCryptoServiceAbstraction, + useClass: DeviceTrustCryptoService, + deps: [ + KeyGenerationServiceAbstraction, + CryptoFunctionServiceAbstraction, + CryptoServiceAbstraction, + EncryptService, + StateServiceAbstraction, + AppIdServiceAbstraction, + DevicesApiServiceAbstraction, + I18nServiceAbstraction, + PlatformUtilsServiceAbstraction, + ], + }), + safeProvider({ + provide: AuthRequestServiceAbstraction, + useClass: AuthRequestService, + deps: [ + AppIdServiceAbstraction, + CryptoServiceAbstraction, + ApiServiceAbstraction, + StateServiceAbstraction, + ], + }), + safeProvider({ + provide: PinCryptoServiceAbstraction, + useClass: PinCryptoService, + deps: [ + StateServiceAbstraction, + CryptoServiceAbstraction, + VaultTimeoutSettingsServiceAbstraction, + LogService, + ], + }), + safeProvider({ + provide: WebAuthnLoginPrfCryptoServiceAbstraction, + useClass: WebAuthnLoginPrfCryptoService, + deps: [CryptoFunctionServiceAbstraction], + }), + safeProvider({ + provide: WebAuthnLoginApiServiceAbstraction, + useClass: WebAuthnLoginApiService, + deps: [ApiServiceAbstraction, EnvironmentServiceAbstraction], + }), + safeProvider({ + provide: WebAuthnLoginServiceAbstraction, + useClass: WebAuthnLoginService, + deps: [ + WebAuthnLoginApiServiceAbstraction, + LoginStrategyServiceAbstraction, + WebAuthnLoginPrfCryptoServiceAbstraction, + WINDOW, + LogService, + ], + }), + safeProvider({ + provide: StorageServiceProvider, + useClass: StorageServiceProvider, + deps: [OBSERVABLE_DISK_STORAGE, OBSERVABLE_MEMORY_STORAGE], + }), + safeProvider({ + provide: StateEventRegistrarService, + useClass: StateEventRegistrarService, + deps: [GlobalStateProvider, StorageServiceProvider], + }), + safeProvider({ + provide: StateEventRunnerService, + useClass: StateEventRunnerService, + deps: [GlobalStateProvider, StorageServiceProvider], + }), + safeProvider({ + provide: GlobalStateProvider, + useClass: DefaultGlobalStateProvider, + deps: [StorageServiceProvider], + }), + safeProvider({ + provide: ActiveUserStateProvider, + useClass: DefaultActiveUserStateProvider, + deps: [AccountServiceAbstraction, StorageServiceProvider, StateEventRegistrarService], + }), + safeProvider({ + provide: SingleUserStateProvider, + useClass: DefaultSingleUserStateProvider, + deps: [StorageServiceProvider, StateEventRegistrarService], + }), + safeProvider({ + provide: DerivedStateProvider, + useClass: DefaultDerivedStateProvider, + deps: [OBSERVABLE_MEMORY_STORAGE], + }), + safeProvider({ + provide: StateProvider, + useClass: DefaultStateProvider, + deps: [ + ActiveUserStateProvider, + SingleUserStateProvider, + GlobalStateProvider, + DerivedStateProvider, + ], + }), + safeProvider({ + provide: OrganizationBillingServiceAbstraction, + useClass: OrganizationBillingService, + deps: [ + CryptoServiceAbstraction, + EncryptService, + I18nServiceAbstraction, + OrganizationApiServiceAbstraction, + ], + }), + safeProvider({ + provide: AutofillSettingsServiceAbstraction, + useClass: AutofillSettingsService, + deps: [StateProvider, PolicyServiceAbstraction], + }), + safeProvider({ + provide: BadgeSettingsServiceAbstraction, + useClass: BadgeSettingsService, + deps: [StateProvider], + }), + safeProvider({ + provide: DomainSettingsService, + useClass: DefaultDomainSettingsService, + deps: [StateProvider], + }), + safeProvider({ + provide: BiometricStateService, + useClass: DefaultBiometricStateService, + deps: [StateProvider], + }), + safeProvider({ + provide: VaultSettingsServiceAbstraction, + useClass: VaultSettingsService, + deps: [StateProvider], + }), + safeProvider({ + provide: MigrationRunner, + useClass: MigrationRunner, + deps: [AbstractStorageService, LogService, MigrationBuilderService], + }), + safeProvider({ + provide: MigrationBuilderService, + useClass: MigrationBuilderService, + deps: [], + }), + safeProvider({ + provide: BillingApiServiceAbstraction, + useClass: BillingApiService, + deps: [ApiServiceAbstraction], + }), + safeProvider({ + provide: PaymentMethodWarningsServiceAbstraction, + useClass: PaymentMethodWarningsService, + deps: [BillingApiServiceAbstraction, StateProvider], + }), +]; function encryptServiceFactory( cryptoFunctionservice: CryptoFunctionServiceAbstraction, @@ -1013,3 +1027,10 @@ function encryptServiceFactory( ? new MultithreadEncryptServiceImplementation(cryptoFunctionservice, logService, logMacFailures) : new EncryptServiceImplementation(cryptoFunctionservice, logService, logMacFailures); } + +@NgModule({ + declarations: [], + // Do not register your dependency here! Add it to the typesafeProviders array using the helper function + providers: typesafeProviders as UnwrapOpaque[], +}) +export class JslibServicesModule {}