From b532934431280c617d585225300468849a932690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Wed, 15 Apr 2026 16:19:38 +0200 Subject: [PATCH 1/2] [PM-33315] Create @bitwarden/logging --- .github/CODEOWNERS | 1 + jest.config.js | 1 + libs/logging-angular/README.md | 26 ++++++++++++++++ libs/logging-angular/eslint.config.mjs | 3 ++ libs/logging-angular/jest.config.js | 16 ++++++++++ libs/logging-angular/package.json | 15 ++++++++++ libs/logging-angular/project.json | 30 +++++++++++++++++++ .../src/flight-recorder.service.ts | 17 +++++++++++ libs/logging-angular/src/index.ts | 3 ++ .../src/logging-angular.spec.ts | 7 +++++ libs/logging-angular/tsconfig.eslint.json | 6 ++++ libs/logging-angular/tsconfig.json | 13 ++++++++ libs/logging-angular/tsconfig.lib.json | 10 +++++++ libs/logging-angular/tsconfig.spec.json | 10 +++++++ package-lock.json | 9 ++++++ tsconfig.base.json | 3 +- 16 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 libs/logging-angular/README.md create mode 100644 libs/logging-angular/eslint.config.mjs create mode 100644 libs/logging-angular/jest.config.js create mode 100644 libs/logging-angular/package.json create mode 100644 libs/logging-angular/project.json create mode 100644 libs/logging-angular/src/flight-recorder.service.ts create mode 100644 libs/logging-angular/src/index.ts create mode 100644 libs/logging-angular/src/logging-angular.spec.ts create mode 100644 libs/logging-angular/tsconfig.eslint.json create mode 100644 libs/logging-angular/tsconfig.json create mode 100644 libs/logging-angular/tsconfig.lib.json create mode 100644 libs/logging-angular/tsconfig.spec.json diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4d5fd16ab9d8..0b2fbfe0b62f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -110,6 +110,7 @@ libs/common/src/state-migrations @bitwarden/team-platform-dev libs/platform @bitwarden/team-platform-dev libs/storage-core @bitwarden/team-platform-dev libs/logging @bitwarden/team-platform-dev +libs/logging-angular @bitwarden/team-platform-dev libs/storage-test-utils @bitwarden/team-platform-dev libs/messaging @bitwarden/team-platform-dev libs/serialization @bitwarden/team-platform-dev diff --git a/jest.config.js b/jest.config.js index b3bae138b4cb..c427b1bb56eb 100644 --- a/jest.config.js +++ b/jest.config.js @@ -64,6 +64,7 @@ module.exports = { "/libs/unlock/jest.config.js", "/libs/user-crypto-management/jest.config.js", "/libs/scheduling/jest.config.js", + "/libs/logging-angular/jest.config.js", ], // Workaround for a memory leak that crashes tests in CI: diff --git a/libs/logging-angular/README.md b/libs/logging-angular/README.md new file mode 100644 index 000000000000..0af65c046d56 --- /dev/null +++ b/libs/logging-angular/README.md @@ -0,0 +1,26 @@ +# logging-angular + +Owned by: platform + +Angular wrapper for [`@bitwarden/logging`](../logging/README.md). Provides `FlightRecorderService`, an +`@Injectable` subclass of `FlightRecorder` that wires SDK readiness automatically via +`SdkLoadService.Ready`. + +## Usage + +```typescript +import { FlightRecorderService } from "@bitwarden/logging-angular"; + +@Component({ + /* ... */ +}) +export class MyComponent { + private recorder = inject(FlightRecorderService); + + async viewEvents() { + const events = await this.recorder.read(); + } +} +``` + +See [`@bitwarden/logging`](../logging/README.md) for the full API surface inherited by this service. diff --git a/libs/logging-angular/eslint.config.mjs b/libs/logging-angular/eslint.config.mjs new file mode 100644 index 000000000000..9c37d10e3ff9 --- /dev/null +++ b/libs/logging-angular/eslint.config.mjs @@ -0,0 +1,3 @@ +import baseConfig from "../../eslint.config.mjs"; + +export default [...baseConfig]; diff --git a/libs/logging-angular/jest.config.js b/libs/logging-angular/jest.config.js new file mode 100644 index 000000000000..319420fb9882 --- /dev/null +++ b/libs/logging-angular/jest.config.js @@ -0,0 +1,16 @@ +const { pathsToModuleNameMapper } = require("ts-jest"); + +const { compilerOptions } = require("../../tsconfig.base"); + +const sharedConfig = require("../../libs/shared/jest.config.angular"); + +/** @type {import('jest').Config} */ +module.exports = { + ...sharedConfig, + displayName: "logging-angular", + testEnvironment: "node", + moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths ?? {}, { + prefix: "/../../", + }), + coverageDirectory: "../../coverage/libs/logging-angular", +}; diff --git a/libs/logging-angular/package.json b/libs/logging-angular/package.json new file mode 100644 index 000000000000..d08f953a4511 --- /dev/null +++ b/libs/logging-angular/package.json @@ -0,0 +1,15 @@ +{ + "name": "@bitwarden/logging-angular", + "version": "0.0.1", + "description": "Angular wrapper for @bitwarden/logging", + "private": true, + "type": "commonjs", + "main": "index.js", + "types": "index.d.ts", + "license": "GPL-3.0", + "author": "platform", + "scripts": { + "clean": "rimraf dist", + "build": "tsc --noEmit -p tsconfig.lib.json" + } +} diff --git a/libs/logging-angular/project.json b/libs/logging-angular/project.json new file mode 100644 index 000000000000..c987c2e8a8f4 --- /dev/null +++ b/libs/logging-angular/project.json @@ -0,0 +1,30 @@ +{ + "name": "logging-angular", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/logging-angular/src", + "projectType": "library", + "tags": [], + "targets": { + "build": { + "executor": "nx:run-script", + "dependsOn": [], + "options": { + "script": "build" + } + }, + "lint": { + "executor": "@nx/eslint:lint", + "outputs": ["{options.outputFile}"], + "options": { + "lintFilePatterns": ["libs/logging-angular/**/*.ts"] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/logging-angular/jest.config.js" + } + } + } +} diff --git a/libs/logging-angular/src/flight-recorder.service.ts b/libs/logging-angular/src/flight-recorder.service.ts new file mode 100644 index 000000000000..3106156825fa --- /dev/null +++ b/libs/logging-angular/src/flight-recorder.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from "@angular/core"; + +import { SdkLoadService } from "@bitwarden/common/platform/abstractions/sdk/sdk-load.service"; +import { FlightRecorder } from "@bitwarden/logging"; + +/** + * Angular wrapper for {@link FlightRecorder}. + * + * Provides the flight recorder as an injectable service, wiring it + * to {@link SdkLoadService.Ready} automatically. + */ +@Injectable({ providedIn: "root" }) +export class FlightRecorderService extends FlightRecorder { + constructor() { + super(SdkLoadService.Ready); + } +} diff --git a/libs/logging-angular/src/index.ts b/libs/logging-angular/src/index.ts new file mode 100644 index 000000000000..4da61ec5bcb8 --- /dev/null +++ b/libs/logging-angular/src/index.ts @@ -0,0 +1,3 @@ +export { FlightRecorderService } from "./flight-recorder.service"; +// Re-export types from logging for convenience +export { FlightRecorderEvent } from "@bitwarden/logging"; diff --git a/libs/logging-angular/src/logging-angular.spec.ts b/libs/logging-angular/src/logging-angular.spec.ts new file mode 100644 index 000000000000..5f2be9c99d9c --- /dev/null +++ b/libs/logging-angular/src/logging-angular.spec.ts @@ -0,0 +1,7 @@ +import { FlightRecorderService } from "./index"; + +describe("logging-angular", () => { + it("should export FlightRecorderService", () => { + expect(FlightRecorderService).toBeDefined(); + }); +}); diff --git a/libs/logging-angular/tsconfig.eslint.json b/libs/logging-angular/tsconfig.eslint.json new file mode 100644 index 000000000000..3daf120441ad --- /dev/null +++ b/libs/logging-angular/tsconfig.eslint.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.base.json", + "files": [], + "include": ["src/**/*.ts", "src/**/*.js"], + "exclude": ["**/build", "**/dist"] +} diff --git a/libs/logging-angular/tsconfig.json b/libs/logging-angular/tsconfig.json new file mode 100644 index 000000000000..62ebbd946474 --- /dev/null +++ b/libs/logging-angular/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/libs/logging-angular/tsconfig.lib.json b/libs/logging-angular/tsconfig.lib.json new file mode 100644 index 000000000000..9cbf67360077 --- /dev/null +++ b/libs/logging-angular/tsconfig.lib.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "include": ["src/**/*.ts"], + "exclude": ["jest.config.js", "src/**/*.spec.ts"] +} diff --git a/libs/logging-angular/tsconfig.spec.json b/libs/logging-angular/tsconfig.spec.json new file mode 100644 index 000000000000..1275f148a18c --- /dev/null +++ b/libs/logging-angular/tsconfig.spec.json @@ -0,0 +1,10 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "moduleResolution": "node10", + "types": ["jest", "node"] + }, + "include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"] +} diff --git a/package-lock.json b/package-lock.json index ad0e9cb3342e..3ab22d9c5b64 100644 --- a/package-lock.json +++ b/package-lock.json @@ -536,6 +536,11 @@ "version": "0.0.1", "license": "GPL-3.0" }, + "libs/logging-angular": { + "name": "@bitwarden/logging-angular", + "version": "0.0.1", + "license": "GPL-3.0" + }, "libs/messaging": { "name": "@bitwarden/messaging", "version": "0.0.1", @@ -5055,6 +5060,10 @@ "resolved": "libs/logging", "link": true }, + "node_modules/@bitwarden/logging-angular": { + "resolved": "libs/logging-angular", + "link": true + }, "node_modules/@bitwarden/messaging": { "resolved": "libs/messaging", "link": true diff --git a/tsconfig.base.json b/tsconfig.base.json index 3aba1a13c7a5..8f67c1fda7bb 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -70,7 +70,8 @@ "@bitwarden/vault": ["./libs/vault/src"], "@bitwarden/vault-export-core": ["./libs/tools/export/vault-export/vault-export-core/src"], "@bitwarden/vault-export-ui": ["./libs/tools/export/vault-export/vault-export-ui/src"], - "@bitwarden/web-vault/*": ["./apps/web/src/*"] + "@bitwarden/web-vault/*": ["./apps/web/src/*"], + "@bitwarden/logging-angular": ["./libs/logging-angular/src/index.ts"] }, "plugins": [ { From b6744f530c15f855cddce06ba4e8c8de51607099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garci=CC=81a?= Date: Mon, 20 Apr 2026 16:28:24 +0200 Subject: [PATCH 2/2] Reorder tsconfig, fix tests --- jest.config.js | 2 +- libs/logging-angular/jest.config.js | 2 +- .../src/logging-angular.spec.ts | 22 ++++++++++++++++--- libs/logging-angular/test.setup.ts | 1 + tsconfig.base.json | 4 ++-- 5 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 libs/logging-angular/test.setup.ts diff --git a/jest.config.js b/jest.config.js index c427b1bb56eb..96f163128fbc 100644 --- a/jest.config.js +++ b/jest.config.js @@ -41,6 +41,7 @@ module.exports = { "/libs/key-management/jest.config.js", "/libs/key-management-ui/jest.config.js", "/libs/logging/jest.config.js", + "/libs/logging-angular/jest.config.js", "/libs/messaging/jest.config.js", "/libs/node/jest.config.js", "/libs/platform/jest.config.js", @@ -64,7 +65,6 @@ module.exports = { "/libs/unlock/jest.config.js", "/libs/user-crypto-management/jest.config.js", "/libs/scheduling/jest.config.js", - "/libs/logging-angular/jest.config.js", ], // Workaround for a memory leak that crashes tests in CI: diff --git a/libs/logging-angular/jest.config.js b/libs/logging-angular/jest.config.js index 319420fb9882..b1c9409dd050 100644 --- a/libs/logging-angular/jest.config.js +++ b/libs/logging-angular/jest.config.js @@ -8,7 +8,7 @@ const sharedConfig = require("../../libs/shared/jest.config.angular"); module.exports = { ...sharedConfig, displayName: "logging-angular", - testEnvironment: "node", + setupFilesAfterEnv: ["/test.setup.ts"], moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths ?? {}, { prefix: "/../../", }), diff --git a/libs/logging-angular/src/logging-angular.spec.ts b/libs/logging-angular/src/logging-angular.spec.ts index 5f2be9c99d9c..d2757a50f9e4 100644 --- a/libs/logging-angular/src/logging-angular.spec.ts +++ b/libs/logging-angular/src/logging-angular.spec.ts @@ -1,7 +1,23 @@ +import { TestBed } from "@angular/core/testing"; + +import { FlightRecorder } from "@bitwarden/logging"; + import { FlightRecorderService } from "./index"; -describe("logging-angular", () => { - it("should export FlightRecorderService", () => { - expect(FlightRecorderService).toBeDefined(); +describe("FlightRecorderService", () => { + beforeEach(() => { + TestBed.configureTestingModule({}); + }); + + it("is injectable via Angular DI", () => { + expect(TestBed.inject(FlightRecorderService)).toBeInstanceOf(FlightRecorderService); + }); + + it("is a singleton at the root injector", () => { + expect(TestBed.inject(FlightRecorderService)).toBe(TestBed.inject(FlightRecorderService)); + }); + + it("inherits from FlightRecorder", () => { + expect(TestBed.inject(FlightRecorderService)).toBeInstanceOf(FlightRecorder); }); }); diff --git a/libs/logging-angular/test.setup.ts b/libs/logging-angular/test.setup.ts new file mode 100644 index 000000000000..3f9ef28ad007 --- /dev/null +++ b/libs/logging-angular/test.setup.ts @@ -0,0 +1 @@ +import "@bitwarden/ui-common/setup-jest"; diff --git a/tsconfig.base.json b/tsconfig.base.json index 8f67c1fda7bb..c4d93333548f 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -47,6 +47,7 @@ "@bitwarden/key-management": ["./libs/key-management/src"], "@bitwarden/key-management-ui": ["./libs/key-management-ui/src"], "@bitwarden/logging": ["./libs/logging/src"], + "@bitwarden/logging-angular": ["./libs/logging-angular/src/index.ts"], "@bitwarden/messaging": ["./libs/messaging/src/index.ts"], "@bitwarden/node/*": ["./libs/node/src/*"], "@bitwarden/nx-plugin": ["./libs/nx-plugin/src/index.ts"], @@ -70,8 +71,7 @@ "@bitwarden/vault": ["./libs/vault/src"], "@bitwarden/vault-export-core": ["./libs/tools/export/vault-export/vault-export-core/src"], "@bitwarden/vault-export-ui": ["./libs/tools/export/vault-export/vault-export-ui/src"], - "@bitwarden/web-vault/*": ["./apps/web/src/*"], - "@bitwarden/logging-angular": ["./libs/logging-angular/src/index.ts"] + "@bitwarden/web-vault/*": ["./apps/web/src/*"] }, "plugins": [ {