From 1d2757e42bc8ee5dc93e0cdfe550bf763b6e3ceb Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Tue, 24 Oct 2023 09:18:23 -0400 Subject: [PATCH] Noop notifications for dev (#6671) * Noop notifications for dev We rarely have notifications set up for development environments, this removes the error messages related to missing server notification services * Log actions in noop service * Add line breaks * Improve log messages * Ignore local config at all levels --- .gitignore | 3 ++ .../browser/src/background/main.background.ts | 2 +- apps/cli/.gitignore | 1 - apps/desktop/webpack.renderer.js | 3 ++ apps/web/.gitignore | 1 - .../src/services/jslib-services.module.ts | 9 ++++-- libs/common/src/platform/misc/flags.ts | 4 ++- .../services/noop-notifications.service.ts | 28 +++++++++++++++++++ .../src/services/notifications.service.ts | 2 +- 9 files changed, 45 insertions(+), 8 deletions(-) delete mode 100644 apps/cli/.gitignore create mode 100644 libs/common/src/platform/services/noop-notifications.service.ts diff --git a/.gitignore b/.gitignore index 11a4d4c80f..6dea4b43f1 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,6 @@ junit.xml documentation.json .eslintcache storybook-static + +# Local app configuration +apps/**/config/local.json diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index 5c47c1aaf9..d9b65362de 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -572,12 +572,12 @@ export default class MainBackground { this.stateService ); this.notificationsService = new NotificationsService( + this.logService, this.syncService, this.appIdService, this.apiService, this.environmentService, logoutCallback, - this.logService, this.stateService, this.authService, this.messagingService diff --git a/apps/cli/.gitignore b/apps/cli/.gitignore deleted file mode 100644 index dd2669506e..0000000000 --- a/apps/cli/.gitignore +++ /dev/null @@ -1 +0,0 @@ -config/local.json diff --git a/apps/desktop/webpack.renderer.js b/apps/desktop/webpack.renderer.js index ea1c350c38..1ba67764c4 100644 --- a/apps/desktop/webpack.renderer.js +++ b/apps/desktop/webpack.renderer.js @@ -13,6 +13,8 @@ console.log("Renderer process config"); const envConfig = configurator.load(NODE_ENV); configurator.log(envConfig); +const ENV = process.env.ENV == null ? "development" : process.env.ENV; + const common = { module: { rules: [ @@ -170,6 +172,7 @@ const renderer = { chunkFilename: "[id].[contenthash].css", }), new webpack.EnvironmentPlugin({ + ENV: ENV, FLAGS: envConfig.flags, DEV_FLAGS: NODE_ENV === "development" ? envConfig.devFlags : {}, }), diff --git a/apps/web/.gitignore b/apps/web/.gitignore index 142fd15088..f942b115a1 100644 --- a/apps/web/.gitignore +++ b/apps/web/.gitignore @@ -1,3 +1,2 @@ !dev-server.shared.pem -config/local.json stats.json diff --git a/libs/angular/src/services/jslib-services.module.ts b/libs/angular/src/services/jslib-services.module.ts index 060593d4a5..959db09eb8 100644 --- a/libs/angular/src/services/jslib-services.module.ts +++ b/libs/angular/src/services/jslib-services.module.ts @@ -82,7 +82,7 @@ import { StateService as StateServiceAbstraction } from "@bitwarden/common/platf import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { ValidationService as ValidationServiceAbstraction } from "@bitwarden/common/platform/abstractions/validation.service"; import { StateFactory } from "@bitwarden/common/platform/factories/state-factory"; -import { flagEnabled } from "@bitwarden/common/platform/misc/flags"; +import { devFlagEnabled, flagEnabled } from "@bitwarden/common/platform/misc/flags"; import { Account } from "@bitwarden/common/platform/models/domain/account"; import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state"; import { AppIdService } from "@bitwarden/common/platform/services/app-id.service"; @@ -94,6 +94,7 @@ import { EncryptServiceImplementation } from "@bitwarden/common/platform/service import { MultithreadEncryptServiceImplementation } from "@bitwarden/common/platform/services/cryptography/multithread-encrypt.service.implementation"; import { EnvironmentService } from "@bitwarden/common/platform/services/environment.service"; import { FileUploadService } from "@bitwarden/common/platform/services/file-upload/file-upload.service"; +import { NoopNotificationsService } from "@bitwarden/common/platform/services/noop-notifications.service"; import { StateService } from "@bitwarden/common/platform/services/state.service"; import { ValidationService } from "@bitwarden/common/platform/services/validation.service"; import { WebCryptoFunctionService } from "@bitwarden/common/platform/services/web-crypto-function.service"; @@ -529,14 +530,16 @@ import { AbstractThemingService } from "./theming/theming.service.abstraction"; }, { provide: NotificationsServiceAbstraction, - useClass: NotificationsService, + useClass: devFlagEnabled("noopNotifications") + ? NoopNotificationsService + : NotificationsService, deps: [ + LogService, SyncServiceAbstraction, AppIdServiceAbstraction, ApiServiceAbstraction, EnvironmentServiceAbstraction, LOGOUT_CALLBACK, - LogService, StateServiceAbstraction, AuthServiceAbstraction, MessagingServiceAbstraction, diff --git a/libs/common/src/platform/misc/flags.ts b/libs/common/src/platform/misc/flags.ts index 5360950567..7a8b5ca194 100644 --- a/libs/common/src/platform/misc/flags.ts +++ b/libs/common/src/platform/misc/flags.ts @@ -8,7 +8,9 @@ export type SharedFlags = { // required to avoid linting errors when there are no flags /* eslint-disable @typescript-eslint/ban-types */ -export type SharedDevFlags = {}; +export type SharedDevFlags = { + noopNotifications: boolean; +}; function getFlags(envFlags: string | T): T { if (typeof envFlags === "string") { diff --git a/libs/common/src/platform/services/noop-notifications.service.ts b/libs/common/src/platform/services/noop-notifications.service.ts new file mode 100644 index 0000000000..9ff6dae931 --- /dev/null +++ b/libs/common/src/platform/services/noop-notifications.service.ts @@ -0,0 +1,28 @@ +import { NotificationsService as NotificationsServiceAbstraction } from "../../abstractions/notifications.service"; +import { LogService } from "../abstractions/log.service"; + +export class NoopNotificationsService implements NotificationsServiceAbstraction { + constructor(private logService: LogService) {} + + init(): Promise { + this.logService.info( + "Initializing no-op notification service, no push notifications will be received" + ); + return Promise.resolve(); + } + + updateConnection(sync?: boolean): Promise { + this.logService.info("Updating notification service connection"); + return Promise.resolve(); + } + + reconnectFromActivity(): Promise { + this.logService.info("Reconnecting notification service from activity"); + return Promise.resolve(); + } + + disconnectFromInactivity(): Promise { + this.logService.info("Disconnecting notification service from inactivity"); + return Promise.resolve(); + } +} diff --git a/libs/common/src/services/notifications.service.ts b/libs/common/src/services/notifications.service.ts index 79b120c737..c5983fb37f 100644 --- a/libs/common/src/services/notifications.service.ts +++ b/libs/common/src/services/notifications.service.ts @@ -28,12 +28,12 @@ export class NotificationsService implements NotificationsServiceAbstraction { private reconnectTimer: any = null; constructor( + private logService: LogService, private syncService: SyncService, private appIdService: AppIdService, private apiService: ApiService, private environmentService: EnvironmentService, private logoutCallback: (expired: boolean) => Promise, - private logService: LogService, private stateService: StateService, private authService: AuthService, private messagingService: MessagingService