diff --git a/.eslintrc.json b/.eslintrc.json index 08e73e5031..4fba3dd612 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -179,6 +179,12 @@ "rules": { "no-restricted-imports": ["error", { "patterns": ["@bitwarden/node/*", "src/**/*"] }] } + }, + { + "files": ["libs/vault/src/**/*.ts"], + "rules": { + "no-restricted-imports": ["error", { "patterns": ["@bitwarden/vault/*", "src/**/*"] }] + } } ] } diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 564763a866..c5f55674ae 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -39,6 +39,7 @@ apps/desktop/src/vault @bitwarden/team-vault-dev apps/web/src/app/vault @bitwarden/team-vault-dev libs/angular/src/vault @bitwarden/team-vault-dev libs/common/src/vault @bitwarden/team-vault-dev +libs/vault @bitwarden/team-vault-dev ## Admin Console team files ## apps/browser/src/admin-console @bitwarden/team-admin-console-dev diff --git a/.github/whitelist-capital-letters.txt b/.github/whitelist-capital-letters.txt index a2ed46ce99..f5a60f817c 100644 --- a/.github/whitelist-capital-letters.txt +++ b/.github/whitelist-capital-letters.txt @@ -25,6 +25,7 @@ ./libs/common/src/abstractions/anonymousHub.service.ts ./libs/common/src/services/anonymousHub.service.ts ./libs/auth/README.md +./libs/vault/README.md ./README.md ./LICENSE_BITWARDEN.txt ./CONTRIBUTING.md diff --git a/apps/browser/tsconfig.json b/apps/browser/tsconfig.json index 9220b89c42..9624939c87 100644 --- a/apps/browser/tsconfig.json +++ b/apps/browser/tsconfig.json @@ -14,7 +14,8 @@ "@bitwarden/auth": ["../../libs/auth/src"], "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/components": ["../../libs/components/src"], - "@bitwarden/exporter/*": ["../../libs/exporter/src/*"] + "@bitwarden/exporter/*": ["../../libs/exporter/src/*"], + "@bitwarden/vault": ["../../libs/auth/src"] }, "useDefineForClassFields": false }, diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json index f34ba7cfae..d587997f9e 100644 --- a/apps/desktop/tsconfig.json +++ b/apps/desktop/tsconfig.json @@ -14,7 +14,8 @@ "@bitwarden/auth": ["../../libs/auth/src"], "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/components": ["../../libs/components/src"], - "@bitwarden/exporter/*": ["../../libs/exporter/src/*"] + "@bitwarden/exporter/*": ["../../libs/exporter/src/*"], + "@bitwarden/vault": ["../../libs/vault/src"] }, "useDefineForClassFields": false }, diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 9048efd39b..67d2451158 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -11,6 +11,7 @@ "@bitwarden/components": ["../../libs/components/src"], "@bitwarden/exporter/*": ["../../libs/exporter/src/*"], "@bitwarden/importer": ["../../libs/importer/src"], + "@bitwarden/vault": ["../../libs/vault/src"], "@bitwarden/web-vault/*": ["src/*"] } }, diff --git a/bitwarden_license/bit-web/tsconfig.json b/bitwarden_license/bit-web/tsconfig.json index a712fae902..0612053e4e 100644 --- a/bitwarden_license/bit-web/tsconfig.json +++ b/bitwarden_license/bit-web/tsconfig.json @@ -7,6 +7,7 @@ "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/components": ["../../libs/components/src"], "@bitwarden/exporter/*": ["../../libs/exporter/src/*"], + "@bitwarden/vault": ["../../libs/vault/src"], "@bitwarden/web-vault/*": ["../../apps/web/src/*"] } }, diff --git a/jest.config.js b/jest.config.js index c4213fa143..035d90bda6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -27,6 +27,7 @@ module.exports = { "/libs/exporter/jest.config.js", "/libs/importer/jest.config.js", "/libs/node/jest.config.js", + "/libs/vault/jest.config.js", ], // Workaround for a memory leak that crashes tests in CI: diff --git a/libs/shared/tsconfig.libs.json b/libs/shared/tsconfig.libs.json index 18b7b1712a..85d5554270 100644 --- a/libs/shared/tsconfig.libs.json +++ b/libs/shared/tsconfig.libs.json @@ -3,12 +3,13 @@ "compilerOptions": { "paths": { "@bitwarden/angular/*": ["../angular/src/*"], - "@bitwarden/auth": ["../auth/src/*"], + "@bitwarden/auth": ["../auth/src"], "@bitwarden/common/*": ["../common/src/*"], "@bitwarden/components": ["../components/src"], "@bitwarden/exporter/*": ["../exporter/src/*"], "@bitwarden/importer": ["../importer/src"], - "@bitwarden/node/*": ["../node/src/*"] + "@bitwarden/node/*": ["../node/src/*"], + "@bitwarden/vault": ["../vault/src"] } } } diff --git a/libs/vault/README.md b/libs/vault/README.md new file mode 100644 index 0000000000..6665f2312c --- /dev/null +++ b/libs/vault/README.md @@ -0,0 +1,3 @@ +# Vault + +This lib represents the public API of the Vault team at Bitwarden. Modules are imported using `@bitwarden/vault`. diff --git a/libs/vault/jest.config.js b/libs/vault/jest.config.js new file mode 100644 index 0000000000..e960eed9f1 --- /dev/null +++ b/libs/vault/jest.config.js @@ -0,0 +1,16 @@ +const { pathsToModuleNameMapper } = require("ts-jest"); + +const { compilerOptions } = require("../shared/tsconfig.libs"); + +const sharedConfig = require("../../libs/shared/jest.config.angular"); + +/** @type {import('jest').Config} */ +module.exports = { + ...sharedConfig, + displayName: "libs/vault tests", + preset: "jest-preset-angular", + setupFilesAfterEnv: ["/test.setup.ts"], + moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { + prefix: "/", + }), +}; diff --git a/libs/vault/package.json b/libs/vault/package.json new file mode 100644 index 0000000000..48822f93a4 --- /dev/null +++ b/libs/vault/package.json @@ -0,0 +1,20 @@ +{ + "name": "@bitwarden/vault", + "version": "0.0.0", + "description": "Common code used across Bitwarden JavaScript projects.", + "keywords": [ + "bitwarden" + ], + "author": "Bitwarden Inc.", + "homepage": "https://bitwarden.com", + "repository": { + "type": "git", + "url": "https://github.com/bitwarden/clients" + }, + "license": "GPL-3.0", + "scripts": { + "clean": "rimraf dist", + "build": "npm run clean && tsc", + "build:watch": "npm run clean && tsc -watch" + } +} diff --git a/libs/vault/src/index.ts b/libs/vault/src/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/vault/test.setup.ts b/libs/vault/test.setup.ts new file mode 100644 index 0000000000..6be6e7b8dd --- /dev/null +++ b/libs/vault/test.setup.ts @@ -0,0 +1,28 @@ +import { webcrypto } from "crypto"; +import "jest-preset-angular/setup-jest"; + +Object.defineProperty(window, "CSS", { value: null }); +Object.defineProperty(window, "getComputedStyle", { + value: () => { + return { + display: "none", + appearance: ["-webkit-appearance"], + }; + }, +}); + +Object.defineProperty(document, "doctype", { + value: "", +}); +Object.defineProperty(document.body.style, "transform", { + value: () => { + return { + enumerable: true, + configurable: true, + }; + }, +}); + +Object.defineProperty(window, "crypto", { + value: webcrypto, +}); diff --git a/libs/vault/tsconfig.json b/libs/vault/tsconfig.json new file mode 100644 index 0000000000..6004a56fb5 --- /dev/null +++ b/libs/vault/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../shared/tsconfig.libs", + "include": ["src", "spec"], + "exclude": ["node_modules", "dist"] +} diff --git a/libs/vault/tsconfig.spec.json b/libs/vault/tsconfig.spec.json new file mode 100644 index 0000000000..de184bd760 --- /dev/null +++ b/libs/vault/tsconfig.spec.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] +} diff --git a/package-lock.json b/package-lock.json index 880225c2f9..bb23f28add 100644 --- a/package-lock.json +++ b/package-lock.json @@ -307,6 +307,10 @@ "@bitwarden/common": "file:../common" } }, + "libs/vault": { + "version": "0.0.0", + "license": "GPL-3.0" + }, "node_modules/@aashutoshrathi/word-wrap": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", @@ -4592,6 +4596,10 @@ "resolved": "libs/node", "link": true }, + "node_modules/@bitwarden/vault": { + "resolved": "libs/vault", + "link": true + }, "node_modules/@bitwarden/web-vault": { "resolved": "apps/web", "link": true diff --git a/tailwind.config.js b/tailwind.config.js index 4011729cf5..f5770840dd 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -4,6 +4,7 @@ const config = require("./libs/components/tailwind.config.base"); config.content = [ "./libs/components/src/**/*.{html,ts,mdx}", "./libs/auth/src/**/*.{html,ts,mdx}", + "./libs/vault/src/**/*.{html,ts,mdx}", "./apps/web/src/**/*.{html,ts,mdx}", "./bitwarden_license/bit-web/src/**/*.{html,ts,mdx}", "./.storybook/preview.js", diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 33037c385e..1a435e93c3 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -20,7 +20,8 @@ "@bitwarden/common/*": ["./libs/common/src/*"], "@bitwarden/components": ["./libs/components/src"], "@bitwarden/exporter/*": ["./libs/exporter/src/*"], - "@bitwarden/node/*": ["./libs/node/src/*"] + "@bitwarden/node/*": ["./libs/node/src/*"], + "@bitwarden/vault": ["./libs/vault/src"] }, "plugins": [ { diff --git a/tsconfig.json b/tsconfig.json index 41d9203970..d6e4db99f5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,7 +22,8 @@ "@bitwarden/exporter/*": ["./libs/exporter/src/*"], "@bitwarden/importer": ["./libs/importer/src"], "@bitwarden/node/*": ["./libs/node/src/*"], - "@bitwarden/web-vault/*": ["./apps/web/src/*"] + "@bitwarden/web-vault/*": ["./apps/web/src/*"], + "@bitwarden/vault": ["./libs/vault/src"] }, "plugins": [ {