1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-21 11:35:34 +01:00

Add CoreModule (#3149)

This commit is contained in:
Oscar Hinton 2022-07-26 19:34:45 +02:00 committed by GitHub
parent 2011131bb2
commit 797938881e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 59 additions and 44 deletions

View File

@ -1,5 +1,13 @@
{
"env": {
"browser": true
},
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": ["**/core/*"]
}
]
}
}

View File

@ -13,7 +13,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service";
import { RouterService } from "../services/router.service";
import { RouterService } from "../core";
@Component({
selector: "app-lock",

View File

@ -19,8 +19,7 @@ import { Policy } from "@bitwarden/common/models/domain/policy";
import { ListResponse } from "@bitwarden/common/models/response/listResponse";
import { PolicyResponse } from "@bitwarden/common/models/response/policyResponse";
import { RouterService } from "../services/router.service";
import { StateService } from "../services/state.service";
import { RouterService, StateService } from "../core";
@Component({
selector: "app-login",

View File

@ -20,7 +20,7 @@ import { MasterPasswordPolicyOptions } from "@bitwarden/common/models/domain/mas
import { Policy } from "@bitwarden/common/models/domain/policy";
import { ReferenceEventRequest } from "@bitwarden/common/models/request/referenceEventRequest";
import { RouterService } from "../services/router.service";
import { RouterService } from "../core";
@Component({
selector: "app-register",

View File

@ -14,7 +14,7 @@ import { StateService } from "@bitwarden/common/abstractions/state.service";
import { TwoFactorService } from "@bitwarden/common/abstractions/twoFactor.service";
import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType";
import { RouterService } from "../services/router.service";
import { RouterService } from "../core";
import { TwoFactorOptionsComponent } from "./two-factor-options.component";

View File

@ -26,6 +26,7 @@ import { StateService } from "@bitwarden/common/abstractions/state.service";
import { SyncService } from "@bitwarden/common/abstractions/sync.service";
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vaultTimeout.service";
import { PolicyListService, RouterService } from "./core";
import { DisableSendPolicy } from "./organizations/policies/disable-send.component";
import { MasterPasswordPolicy } from "./organizations/policies/master-password.component";
import { PasswordGeneratorPolicy } from "./organizations/policies/password-generator.component";
@ -35,8 +36,6 @@ import { ResetPasswordPolicy } from "./organizations/policies/reset-password.com
import { SendOptionsPolicy } from "./organizations/policies/send-options.component";
import { SingleOrgPolicy } from "./organizations/policies/single-org.component";
import { TwoFactorAuthenticationPolicy } from "./organizations/policies/two-factor-authentication.component";
import { PolicyListService } from "./services/policy-list.service";
import { RouterService } from "./services/router.service";
const BroadcasterSubscriptionId = "AppComponent";
const IdleTimeout = 60000 * 10; // 10 minutes

View File

@ -6,9 +6,9 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { InfiniteScrollModule } from "ngx-infinite-scroll";
import { AppComponent } from "./app.component";
import { CoreModule } from "./core";
import { OssRoutingModule } from "./oss-routing.module";
import { OssModule } from "./oss.module";
import { ServicesModule } from "./services/services.module";
import { WildcardRoutingModule } from "./wildcard-routing.module";
@NgModule({
@ -16,7 +16,7 @@ import { WildcardRoutingModule } from "./wildcard-routing.module";
OssModule,
BrowserAnimationsModule,
FormsModule,
ServicesModule,
CoreModule,
InfiniteScrollModule,
DragDropModule,
LayoutModule,

View File

@ -9,7 +9,7 @@ import { EventResponse } from "@bitwarden/common/models/response/eventResponse";
import { ListResponse } from "@bitwarden/common/models/response/listResponse";
import { EventView } from "@bitwarden/common/models/view/eventView";
import { EventService } from "src/app/services/event.service";
import { EventService } from "src/app/core";
@Directive()
export abstract class BaseEventsComponent {

View File

@ -1,5 +1,5 @@
import { APP_INITIALIZER, NgModule } from "@angular/core";
import { ToastrModule } from "ngx-toastr";
import { CommonModule } from "@angular/common";
import { APP_INITIALIZER, NgModule, Optional, SkipSelf } from "@angular/core";
import {
JslibServicesModule,
@ -22,32 +22,24 @@ import { AbstractStorageService } from "@bitwarden/common/abstractions/storage.s
import { StateFactory } from "@bitwarden/common/factories/stateFactory";
import { MemoryStorageService } from "@bitwarden/common/services/memoryStorage.service";
import { HomeGuard } from "../guards/home.guard";
import { Account } from "../models/account";
import { GlobalState } from "../models/globalState";
import { PermissionsGuard as OrgPermissionsGuard } from "../organizations/guards/permissions.guard";
import { NavigationPermissionsService as OrgPermissionsService } from "../organizations/services/navigation-permissions.service";
import { BroadcasterMessagingService } from "./broadcasterMessaging.service";
import { BroadcasterMessagingService } from "./broadcaster-messaging.service";
import { EventService } from "./event.service";
import { HtmlStorageService } from "./htmlStorage.service";
import { HtmlStorageService } from "./html-storage.service";
import { I18nService } from "./i18n.service";
import { InitService } from "./init.service";
import { ModalService } from "./modal.service";
import { PasswordRepromptService } from "./passwordReprompt.service";
import { PasswordRepromptService } from "./password-reprompt.service";
import { PolicyListService } from "./policy-list.service";
import { RouterService } from "./router.service";
import { StateService } from "./state.service";
import { StateMigrationService } from "./stateMigration.service";
import { WebFileDownloadService } from "./webFileDownload.service";
import { WebPlatformUtilsService } from "./webPlatformUtils.service";
import { Account, GlobalState, StateService } from "./state";
import { StateMigrationService } from "./state-migration.service";
import { WebFileDownloadService } from "./web-file-download.service";
import { WebPlatformUtilsService } from "./web-platform-utils.service";
@NgModule({
imports: [ToastrModule, JslibServicesModule],
declarations: [],
imports: [CommonModule, JslibServicesModule],
providers: [
OrgPermissionsService,
OrgPermissionsGuard,
InitService,
RouterService,
EventService,
@ -106,7 +98,12 @@ import { WebPlatformUtilsService } from "./webPlatformUtils.service";
provide: FileDownloadService,
useClass: WebFileDownloadService,
},
HomeGuard,
],
})
export class ServicesModule {}
export class CoreModule {
constructor(@Optional() @SkipSelf() parentModule?: CoreModule) {
if (parentModule) {
throw new Error("CoreModule is already loaded. Import it in the AppModule only");
}
}
}

View File

@ -0,0 +1,5 @@
export * from "./core.module";
export * from "./event.service";
export * from "./policy-list.service";
export * from "./router.service";
export * from "./state/state.service";

View File

@ -1,7 +1,7 @@
import { StateMigrationService as BaseStateMigrationService } from "@bitwarden/common/services/stateMigration.service";
import { Account } from "../models/account";
import { GlobalState } from "../models/globalState";
import { Account } from "./state/account";
import { GlobalState } from "./state/global-state";
export class StateMigrationService extends BaseStateMigrationService<GlobalState, Account> {
protected async migrationStateFrom1To2(): Promise<void> {

View File

@ -0,0 +1,3 @@
export * from "./account";
export * from "./global-state";
export * from "./state.service";

View File

@ -17,8 +17,8 @@ import { SendData } from "@bitwarden/common/models/data/sendData";
import { StorageOptions } from "@bitwarden/common/models/domain/storageOptions";
import { StateService as BaseStateService } from "@bitwarden/common/services/state.service";
import { Account } from "../models/account";
import { GlobalState } from "../models/globalState";
import { Account } from "./account";
import { GlobalState } from "./global-state";
@Injectable()
export class StateService extends BaseStateService<GlobalState, Account> {
@ -43,7 +43,7 @@ export class StateService extends BaseStateService<GlobalState, Account> {
}
async addAccount(account: Account) {
// Apply web overides to default account values
// Apply web overrides to default account values
account = new Account(account);
await super.addAccount(account);
}

View File

@ -4,7 +4,9 @@ import { ActivatedRouteSnapshot, CanActivate, Router } from "@angular/router";
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/enums/authenticationStatus";
@Injectable()
@Injectable({
providedIn: "root",
})
export class HomeGuard implements CanActivate {
constructor(private router: Router, private authService: AuthService) {}

View File

@ -7,7 +7,9 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti
import { SyncService } from "@bitwarden/common/abstractions/sync.service";
import { Permissions } from "@bitwarden/common/enums/permissions";
@Injectable()
@Injectable({
providedIn: "root",
})
export class PermissionsGuard implements CanActivate {
constructor(
private router: Router,

View File

@ -8,7 +8,7 @@ import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUti
import { EventResponse } from "@bitwarden/common/models/response/eventResponse";
import { ListResponse } from "@bitwarden/common/models/response/listResponse";
import { EventService } from "../../services/event.service";
import { EventService } from "../../core";
@Component({
selector: "app-entity-events",

View File

@ -14,7 +14,7 @@ import { Organization } from "@bitwarden/common/models/domain/organization";
import { EventResponse } from "@bitwarden/common/models/response/eventResponse";
import { BaseEventsComponent } from "../../common/base.events.component";
import { EventService } from "../../services/event.service";
import { EventService } from "../../core";
@Component({
selector: "app-org-events",

View File

@ -9,7 +9,7 @@ import { PolicyType } from "@bitwarden/common/enums/policyType";
import { Organization } from "@bitwarden/common/models/domain/organization";
import { PolicyResponse } from "@bitwarden/common/models/response/policyResponse";
import { PolicyListService } from "../../services/policy-list.service";
import { PolicyListService } from "../../core";
import { BasePolicy } from "../policies/base-policy.component";
import { PolicyEditComponent } from "./policy-edit.component";

View File

@ -6,7 +6,7 @@ import { OrganizationService } from "@bitwarden/common/abstractions/organization
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { TokenService } from "@bitwarden/common/abstractions/token.service";
import { StateService } from "../services/state.service";
import { StateService } from "../core";
const BroadcasterSubscriptionId = "SettingsComponent";

View File

@ -8,9 +8,9 @@ import { InfiniteScrollModule } from "ngx-infinite-scroll";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { CoreModule } from "src/app/core";
import { OssRoutingModule } from "src/app/oss-routing.module";
import { OssModule } from "src/app/oss.module";
import { ServicesModule } from "src/app/services/services.module";
import { WildcardRoutingModule } from "src/app/wildcard-routing.module";
import { AppRoutingModule } from "./app-routing.module";
@ -27,7 +27,7 @@ import { MaximumVaultTimeoutPolicyComponent } from "./policies/maximum-vault-tim
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
ServicesModule,
CoreModule,
InfiniteScrollModule,
DragDropModule,
AppRoutingModule,

View File

@ -12,7 +12,7 @@ import { ProviderService } from "@bitwarden/common/abstractions/provider.service
import { EventResponse } from "@bitwarden/common/models/response/eventResponse";
import { BaseEventsComponent } from "src/app/common/base.events.component";
import { EventService } from "src/app/services/event.service";
import { EventService } from "src/app/core";
@Component({
selector: "provider-events",