1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-21 16:18:28 +01:00

[AC-2278] [BEEEP] Typesafe Angular DI (#8206)

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 <mgibson@bitwarden.com>
This commit is contained in:
Thomas Rittson 2024-03-13 09:21:57 +10:00 committed by GitHub
parent 8f8385d822
commit 29b5643310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 928 additions and 784 deletions

View File

@ -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<ThemeType> {
return await ipc.platform.getSystemTheme();

View File

@ -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<Document>],
}),
{
provide: EncryptedMessageHandlerService,
deps: [

View File

@ -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<ThemeBuilder | null>(null);
theme$: Observable<Theme> = 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

View File

@ -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<Provider>;
// TODO: type-fest also provides a type like this when we upgrade >= 3.7.0
type AbstractConstructor<T> = abstract new (...args: any) => T;
type MapParametersToDeps<T> = {
[K in keyof T]: AbstractConstructor<T[K]> | SafeInjectionToken<T[K]>;
};
type SafeInjectionTokenType<T> = T extends SafeInjectionToken<infer J> ? J : never;
/**
* Represents a dependency provided with the useClass option.
*/
type SafeClassProvider<
A extends AbstractConstructor<any>,
I extends Constructor<InstanceType<A>>,
D extends MapParametersToDeps<ConstructorParameters<I>>,
> = {
provide: A;
useClass: I;
deps: D;
};
/**
* Represents a dependency provided with the useValue option.
*/
type SafeValueProvider<A extends SafeInjectionToken<any>, V extends SafeInjectionTokenType<A>> = {
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<any>,
I extends (...args: any) => InstanceType<SafeInjectionTokenType<A>>,
D extends MapParametersToDeps<Parameters<I>>,
> = {
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<any>,
I extends (...args: any) => InstanceType<A>,
D extends MapParametersToDeps<Parameters<I>>,
> = {
provide: A;
useFactory: I;
deps: D;
};
/**
* Represents a dependency provided with the useExisting option.
*/
type SafeExistingProvider<
A extends Constructor<any> | AbstractConstructor<any>,
I extends Constructor<InstanceType<A>> | AbstractConstructor<InstanceType<A>>,
> = {
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<any>,
IClass extends Constructor<InstanceType<AClass>>,
DClass extends MapParametersToDeps<ConstructorParameters<IClass>>,
// types for useValue
AValue extends SafeInjectionToken<any>,
VValue extends SafeInjectionTokenType<AValue>,
// types for useFactoryWithToken
AFactoryToken extends SafeInjectionToken<any>,
IFactoryToken extends (...args: any) => InstanceType<SafeInjectionTokenType<AFactoryToken>>,
DFactoryToken extends MapParametersToDeps<Parameters<IFactoryToken>>,
// types for useFactoryWithClass
AFactoryClass extends AbstractConstructor<any>,
IFactoryClass extends (...args: any) => InstanceType<AFactoryClass>,
DFactoryClass extends MapParametersToDeps<Parameters<IFactoryClass>>,
// types for useExisting
AExisting extends Constructor<any> | AbstractConstructor<any>,
IExisting extends
| Constructor<InstanceType<AExisting>>
| AbstractConstructor<InstanceType<AExisting>>,
>(
provider:
| SafeClassProvider<AClass, IClass, DClass>
| SafeValueProvider<AValue, VValue>
| SafeFactoryProviderWithToken<AFactoryToken, IFactoryToken, DFactoryToken>
| SafeFactoryProviderWithClass<AFactoryClass, IFactoryClass, DFactoryClass>
| SafeExistingProvider<AExisting, IExisting>
| Constructor<unknown>,
): SafeProvider => provider as SafeProvider;

View File

@ -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>("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<T> extends InjectionToken<T> {
private readonly [tag]: T;
}
export const WINDOW = new SafeInjectionToken<Window>("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<AbstractMemoryStorageService>("MEMORY_STORAGE");
export const SECURE_STORAGE = new InjectionToken<AbstractStorageService>("SECURE_STORAGE");
export const STATE_FACTORY = new InjectionToken<StateFactory>("STATE_FACTORY");
export const STATE_SERVICE_USE_CACHE = new InjectionToken<boolean>("STATE_SERVICE_USE_CACHE");
export const LOGOUT_CALLBACK = new InjectionToken<
export const MEMORY_STORAGE = new SafeInjectionToken<AbstractMemoryStorageService>(
"MEMORY_STORAGE",
);
export const SECURE_STORAGE = new SafeInjectionToken<AbstractStorageService>("SECURE_STORAGE");
export const STATE_FACTORY = new SafeInjectionToken<StateFactory>("STATE_FACTORY");
export const STATE_SERVICE_USE_CACHE = new SafeInjectionToken<boolean>("STATE_SERVICE_USE_CACHE");
export const LOGOUT_CALLBACK = new SafeInjectionToken<
(expired: boolean, userId?: string) => Promise<void>
>("LOGOUT_CALLBACK");
export const LOCKED_CALLBACK = new InjectionToken<(userId?: string) => Promise<void>>(
export const LOCKED_CALLBACK = new SafeInjectionToken<(userId?: string) => Promise<void>>(
"LOCKED_CALLBACK",
);
export const LOCALES_DIRECTORY = new InjectionToken<string>("LOCALES_DIRECTORY");
export const SYSTEM_LANGUAGE = new InjectionToken<string>("SYSTEM_LANGUAGE");
export const LOG_MAC_FAILURES = new InjectionToken<string>("LOG_MAC_FAILURES");
export const LOCALES_DIRECTORY = new SafeInjectionToken<string>("LOCALES_DIRECTORY");
export const SYSTEM_LANGUAGE = new SafeInjectionToken<string>("SYSTEM_LANGUAGE");
export const LOG_MAC_FAILURES = new SafeInjectionToken<boolean>("LOG_MAC_FAILURES");

View File

@ -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,63 +252,65 @@ import {
} from "./injection-tokens";
import { ModalService } from "./modal.service";
@NgModule({
declarations: [],
providers: [
AuthGuard,
UnauthGuard,
ModalService,
PasswordRepromptService,
{ provide: WINDOW, useValue: window },
{
provide: LOCALE_ID,
/**
* 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> = [
safeProvider(AuthGuard),
safeProvider(UnauthGuard),
safeProvider(ModalService),
safeProvider(PasswordRepromptService),
safeProvider({ provide: WINDOW, useValue: window }),
safeProvider({
provide: LOCALE_ID as SafeInjectionToken<string>,
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) =>
messagingService.send("logout", { expired: expired, userId: userId }),
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: [
@ -310,8 +319,8 @@ import { ModalService } from "./modal.service";
ApiServiceAbstraction,
StateServiceAbstraction,
],
},
{
}),
safeProvider({
provide: LoginStrategyServiceAbstraction,
useClass: LoginStrategyService,
deps: [
@ -334,18 +343,18 @@ import { ModalService } from "./modal.service";
AuthRequestServiceAbstraction,
GlobalStateProvider,
],
},
{
}),
safeProvider({
provide: FileUploadServiceAbstraction,
useClass: FileUploadService,
deps: [LoginServiceAbstraction],
},
{
deps: [LogService],
}),
safeProvider({
provide: CipherFileUploadServiceAbstraction,
useClass: CipherFileUploadService,
deps: [ApiServiceAbstraction, FileUploadServiceAbstraction],
},
{
}),
safeProvider({
provide: CipherServiceAbstraction,
useFactory: (
cryptoService: CryptoServiceAbstraction,
@ -383,9 +392,9 @@ import { ModalService } from "./modal.service";
CipherFileUploadServiceAbstraction,
ConfigServiceAbstraction,
],
},
{
provide: FolderServiceAbstraction,
}),
safeProvider({
provide: InternalFolderService,
useClass: FolderService,
deps: [
CryptoServiceAbstraction,
@ -394,17 +403,17 @@ import { ModalService } from "./modal.service";
StateServiceAbstraction,
StateProvider,
],
},
{
provide: InternalFolderService,
useExisting: FolderServiceAbstraction,
},
{
}),
safeProvider({
provide: FolderServiceAbstraction,
useExisting: InternalFolderService,
}),
safeProvider({
provide: FolderApiServiceAbstraction,
useClass: FolderApiService,
deps: [FolderServiceAbstraction, ApiServiceAbstraction],
},
{
deps: [InternalFolderService, ApiServiceAbstraction],
}),
safeProvider({
provide: AccountApiServiceAbstraction,
useClass: AccountApiServiceImplementation,
deps: [
@ -413,44 +422,48 @@ import { ModalService } from "./modal.service";
LogService,
InternalAccountService,
],
},
{
provide: AccountServiceAbstraction,
}),
safeProvider({
provide: InternalAccountService,
useClass: AccountServiceImplementation,
deps: [MessagingServiceAbstraction, LogService, GlobalStateProvider],
},
{
provide: InternalAccountService,
useExisting: AccountServiceAbstraction,
},
{
}),
safeProvider({
provide: AccountServiceAbstraction,
useExisting: InternalAccountService,
}),
safeProvider({
provide: AccountUpdateServiceAbstraction,
useClass: AvatarUpdateService,
deps: [ApiServiceAbstraction, StateServiceAbstraction],
},
{ provide: LogService, useFactory: () => new ConsoleLogService(false) },
{
}),
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, StateServiceAbstraction],
},
{ provide: TokenServiceAbstraction, useClass: TokenService, deps: [StateServiceAbstraction] },
{
deps: [CryptoFunctionServiceAbstraction, LogService],
}),
safeProvider({
provide: TokenServiceAbstraction,
useClass: TokenService,
deps: [StateServiceAbstraction],
}),
safeProvider({
provide: KeyGenerationServiceAbstraction,
useClass: KeyGenerationService,
deps: [CryptoFunctionServiceAbstraction],
},
{
}),
safeProvider({
provide: CryptoServiceAbstraction,
useClass: CryptoService,
deps: [
@ -463,23 +476,23 @@ import { ModalService } from "./modal.service";
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: [
@ -489,9 +502,13 @@ import { ModalService } from "./modal.service";
AppIdServiceAbstraction,
LOGOUT_CALLBACK,
],
},
{
}),
safeProvider({
provide: SendServiceAbstraction,
useExisting: InternalSendService,
}),
safeProvider({
provide: InternalSendService,
useClass: SendService,
deps: [
CryptoServiceAbstraction,
@ -499,42 +516,42 @@ import { ModalService } from "./modal.service";
KeyGenerationServiceAbstraction,
StateServiceAbstraction,
],
},
{
}),
safeProvider({
provide: SendApiServiceAbstraction,
useClass: SendApiService,
deps: [ApiServiceAbstraction, FileUploadServiceAbstraction, SendServiceAbstraction],
},
{
deps: [ApiServiceAbstraction, FileUploadServiceAbstraction, InternalSendService],
}),
safeProvider({
provide: SyncServiceAbstraction,
useClass: SyncService,
deps: [
ApiServiceAbstraction,
SettingsServiceAbstraction,
FolderServiceAbstraction,
DomainSettingsService,
InternalFolderService,
CipherServiceAbstraction,
CryptoServiceAbstraction,
CollectionServiceAbstraction,
MessagingServiceAbstraction,
PolicyServiceAbstraction,
SendServiceAbstraction,
InternalPolicyService,
InternalSendService,
LogService,
KeyConnectorServiceAbstraction,
StateServiceAbstraction,
ProviderServiceAbstraction,
FolderApiServiceAbstraction,
OrganizationServiceAbstraction,
InternalOrganizationServiceAbstraction,
SendApiServiceAbstraction,
LOGOUT_CALLBACK,
],
},
{ provide: BroadcasterServiceAbstraction, useClass: BroadcasterService },
{
}),
safeProvider({ provide: BroadcasterServiceAbstraction, useClass: BroadcasterService, deps: [] }),
safeProvider({
provide: SettingsServiceAbstraction,
useClass: SettingsService,
deps: [StateServiceAbstraction],
},
{
}),
safeProvider({
provide: VaultTimeoutSettingsServiceAbstraction,
useClass: VaultTimeoutSettingsService,
deps: [
@ -544,8 +561,8 @@ import { ModalService } from "./modal.service";
StateServiceAbstraction,
BiometricStateService,
],
},
{
}),
safeProvider({
provide: VaultTimeoutService,
useClass: VaultTimeoutService,
deps: [
@ -563,17 +580,17 @@ import { ModalService } from "./modal.service";
LOCKED_CALLBACK,
LOGOUT_CALLBACK,
],
},
{
}),
safeProvider({
provide: VaultTimeoutServiceAbstraction,
useExisting: VaultTimeoutService,
},
{
}),
safeProvider({
provide: SsoLoginServiceAbstraction,
useClass: SsoLoginService,
deps: [StateProvider],
},
{
}),
safeProvider({
provide: StateServiceAbstraction,
useClass: StateService,
deps: [
@ -587,13 +604,13 @@ import { ModalService } from "./modal.service";
MigrationRunner,
STATE_SERVICE_USE_CACHE,
],
},
{
}),
safeProvider({
provide: ImportApiServiceAbstraction,
useClass: ImportApiService,
deps: [ApiServiceAbstraction],
},
{
}),
safeProvider({
provide: ImportServiceAbstraction,
useClass: ImportService,
deps: [
@ -604,8 +621,8 @@ import { ModalService } from "./modal.service";
CollectionServiceAbstraction,
CryptoServiceAbstraction,
],
},
{
}),
safeProvider({
provide: IndividualVaultExportServiceAbstraction,
useClass: IndividualVaultExportService,
deps: [
@ -615,8 +632,8 @@ import { ModalService } from "./modal.service";
CryptoFunctionServiceAbstraction,
StateServiceAbstraction,
],
},
{
}),
safeProvider({
provide: OrganizationVaultExportServiceAbstraction,
useClass: OrganizationVaultExportService,
deps: [
@ -627,22 +644,20 @@ import { ModalService } from "./modal.service";
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,
useClass: devFlagEnabled("noopNotifications") ? NoopNotificationsService : NotificationsService,
deps: [
LogService,
SyncServiceAbstraction,
@ -654,23 +669,23 @@ import { ModalService } from "./modal.service";
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: [
@ -679,22 +694,22 @@ import { ModalService } from "./modal.service";
OrganizationServiceAbstraction,
EventUploadServiceAbstraction,
],
},
{
provide: PolicyServiceAbstraction,
}),
safeProvider({
provide: InternalPolicyService,
useClass: PolicyService,
deps: [StateProvider, OrganizationServiceAbstraction],
},
{
provide: InternalPolicyService,
useExisting: PolicyServiceAbstraction,
},
{
}),
safeProvider({
provide: PolicyServiceAbstraction,
useExisting: InternalPolicyService,
}),
safeProvider({
provide: PolicyApiServiceAbstraction,
useClass: PolicyApiService,
deps: [InternalPolicyService, ApiServiceAbstraction],
},
{
}),
safeProvider({
provide: KeyConnectorServiceAbstraction,
useClass: KeyConnectorService,
deps: [
@ -707,8 +722,8 @@ import { ModalService } from "./modal.service";
KeyGenerationServiceAbstraction,
LOGOUT_CALLBACK,
],
},
{
}),
safeProvider({
provide: UserVerificationServiceAbstraction,
useClass: UserVerificationService,
deps: [
@ -721,22 +736,22 @@ import { ModalService } from "./modal.service";
VaultTimeoutSettingsServiceAbstraction,
PlatformUtilsServiceAbstraction,
],
},
{
provide: OrganizationServiceAbstraction,
}),
safeProvider({
provide: InternalOrganizationServiceAbstraction,
useClass: OrganizationService,
deps: [StateServiceAbstraction, StateProvider],
},
{
provide: InternalOrganizationServiceAbstraction,
useExisting: OrganizationServiceAbstraction,
},
{
}),
safeProvider({
provide: OrganizationServiceAbstraction,
useExisting: InternalOrganizationServiceAbstraction,
}),
safeProvider({
provide: OrganizationUserService,
useClass: OrganizationUserServiceImplementation,
deps: [ApiServiceAbstraction],
},
{
}),
safeProvider({
provide: PasswordResetEnrollmentServiceAbstraction,
useClass: PasswordResetEnrollmentServiceImplementation,
deps: [
@ -746,31 +761,33 @@ import { ModalService } from "./modal.service";
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<Document>],
}),
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
@ -778,12 +795,13 @@ import { ModalService } from "./modal.service";
// 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: [
@ -793,56 +811,56 @@ import { ModalService } from "./modal.service";
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],
},
{
provide: OrgDomainServiceAbstraction,
}),
safeProvider({
provide: OrgDomainInternalServiceAbstraction,
useClass: OrgDomainService,
deps: [PlatformUtilsServiceAbstraction, I18nServiceAbstraction],
},
{
provide: OrgDomainInternalServiceAbstraction,
useExisting: OrgDomainServiceAbstraction,
},
{
}),
safeProvider({
provide: OrgDomainServiceAbstraction,
useExisting: OrgDomainInternalServiceAbstraction,
}),
safeProvider({
provide: OrgDomainApiServiceAbstraction,
useClass: OrgDomainApiService,
deps: [OrgDomainServiceAbstraction, ApiServiceAbstraction],
},
{
deps: [OrgDomainInternalServiceAbstraction, ApiServiceAbstraction],
}),
safeProvider({
provide: DevicesApiServiceAbstraction,
useClass: DevicesApiServiceImplementation,
deps: [ApiServiceAbstraction],
},
{
}),
safeProvider({
provide: DevicesServiceAbstraction,
useClass: DevicesServiceImplementation,
deps: [DevicesApiServiceAbstraction],
},
{
}),
safeProvider({
provide: DeviceTrustCryptoServiceAbstraction,
useClass: DeviceTrustCryptoService,
deps: [
@ -856,8 +874,8 @@ import { ModalService } from "./modal.service";
I18nServiceAbstraction,
PlatformUtilsServiceAbstraction,
],
},
{
}),
safeProvider({
provide: AuthRequestServiceAbstraction,
useClass: AuthRequestService,
deps: [
@ -866,8 +884,8 @@ import { ModalService } from "./modal.service";
ApiServiceAbstraction,
StateServiceAbstraction,
],
},
{
}),
safeProvider({
provide: PinCryptoServiceAbstraction,
useClass: PinCryptoService,
deps: [
@ -876,19 +894,18 @@ import { ModalService } from "./modal.service";
VaultTimeoutSettingsServiceAbstraction,
LogService,
],
},
{
}),
safeProvider({
provide: WebAuthnLoginPrfCryptoServiceAbstraction,
useClass: WebAuthnLoginPrfCryptoService,
deps: [CryptoFunctionServiceAbstraction],
},
{
}),
safeProvider({
provide: WebAuthnLoginApiServiceAbstraction,
useClass: WebAuthnLoginApiService,
deps: [ApiServiceAbstraction, EnvironmentServiceAbstraction],
},
{
}),
safeProvider({
provide: WebAuthnLoginServiceAbstraction,
useClass: WebAuthnLoginService,
deps: [
@ -898,43 +915,43 @@ import { ModalService } from "./modal.service";
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: [
@ -943,8 +960,8 @@ import { ModalService } from "./modal.service";
GlobalStateProvider,
DerivedStateProvider,
],
},
{
}),
safeProvider({
provide: OrganizationBillingServiceAbstraction,
useClass: OrganizationBillingService,
deps: [
@ -952,57 +969,54 @@ import { ModalService } from "./modal.service";
EncryptService,
I18nServiceAbstraction,
OrganizationApiServiceAbstraction,
OrganizationServiceAbstraction,
StateProvider,
],
},
{
}),
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],
},
],
})
export class JslibServicesModule {}
}),
];
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<SafeProvider>[],
})
export class JslibServicesModule {}