Browse Source

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
pull/6681/head
Matt Gibson 2 years ago committed by GitHub
parent
commit
1d2757e42b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .gitignore
  2. 2
      apps/browser/src/background/main.background.ts
  3. 1
      apps/cli/.gitignore
  4. 3
      apps/desktop/webpack.renderer.js
  5. 1
      apps/web/.gitignore
  6. 9
      libs/angular/src/services/jslib-services.module.ts
  7. 4
      libs/common/src/platform/misc/flags.ts
  8. 28
      libs/common/src/platform/services/noop-notifications.service.ts
  9. 2
      libs/common/src/services/notifications.service.ts

3
.gitignore vendored

@ -42,3 +42,6 @@ junit.xml @@ -42,3 +42,6 @@ junit.xml
documentation.json
.eslintcache
storybook-static
# Local app configuration
apps/**/config/local.json

2
apps/browser/src/background/main.background.ts

@ -572,12 +572,12 @@ export default class MainBackground { @@ -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

1
apps/cli/.gitignore vendored

@ -1 +0,0 @@ @@ -1 +0,0 @@
config/local.json

3
apps/desktop/webpack.renderer.js

@ -13,6 +13,8 @@ console.log("Renderer process config"); @@ -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 = { @@ -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 : {},
}),

1
apps/web/.gitignore vendored

@ -1,3 +1,2 @@ @@ -1,3 +1,2 @@
!dev-server.shared.pem
config/local.json
stats.json

9
libs/angular/src/services/jslib-services.module.ts

@ -82,7 +82,7 @@ import { StateService as StateServiceAbstraction } from "@bitwarden/common/platf @@ -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 @@ -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"; @@ -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,

4
libs/common/src/platform/misc/flags.ts

@ -8,7 +8,9 @@ export type SharedFlags = { @@ -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<T>(envFlags: string | T): T {
if (typeof envFlags === "string") {

28
libs/common/src/platform/services/noop-notifications.service.ts

@ -0,0 +1,28 @@ @@ -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<void> {
this.logService.info(
"Initializing no-op notification service, no push notifications will be received"
);
return Promise.resolve();
}
updateConnection(sync?: boolean): Promise<void> {
this.logService.info("Updating notification service connection");
return Promise.resolve();
}
reconnectFromActivity(): Promise<void> {
this.logService.info("Reconnecting notification service from activity");
return Promise.resolve();
}
disconnectFromInactivity(): Promise<void> {
this.logService.info("Disconnecting notification service from inactivity");
return Promise.resolve();
}
}

2
libs/common/src/services/notifications.service.ts

@ -28,12 +28,12 @@ export class NotificationsService implements NotificationsServiceAbstraction { @@ -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<void>,
private logService: LogService,
private stateService: StateService,
private authService: AuthService,
private messagingService: MessagingService

Loading…
Cancel
Save