diff --git a/.eslintrc.json b/.eslintrc.json index 45a9d063a9..afa134a65e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -134,6 +134,18 @@ "tailwindcss/no-contradicting-classname": "error" } }, + { + "files": ["libs/angular/src/**/*.ts"], + "rules": { + "no-restricted-imports": ["error", { "patterns": ["@bitwarden/angular/*", "src/**/*"] }] + } + }, + { + "files": ["libs/auth/src/**/*.ts"], + "rules": { + "no-restricted-imports": ["error", { "patterns": ["@bitwarden/auth/*", "src/**/*"] }] + } + }, { "files": ["libs/common/src/**/*.ts"], "rules": { @@ -147,15 +159,9 @@ } }, { - "files": ["libs/angular/src/**/*.ts"], + "files": ["libs/exporter/src/**/*.ts"], "rules": { - "no-restricted-imports": ["error", { "patterns": ["@bitwarden/angular/*", "src/**/*"] }] - } - }, - { - "files": ["libs/node/src/**/*.ts"], - "rules": { - "no-restricted-imports": ["error", { "patterns": ["@bitwarden/node/*", "src/**/*"] }] + "no-restricted-imports": ["error", { "patterns": ["@bitwarden/exporter/*", "src/**/*"] }] } }, { @@ -165,9 +171,9 @@ } }, { - "files": ["libs/exporter/src/**/*.ts"], + "files": ["libs/node/src/**/*.ts"], "rules": { - "no-restricted-imports": ["error", { "patterns": ["@bitwarden/exporter/*", "src/**/*"] }] + "no-restricted-imports": ["error", { "patterns": ["@bitwarden/node/*", "src/**/*"] }] } } ] diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 832a874607..1aed9c1be8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -14,6 +14,7 @@ apps/browser/src/auth @bitwarden/team-auth-dev apps/cli/src/auth @bitwarden/team-auth-dev apps/desktop/src/auth @bitwarden/team-auth-dev apps/web/src/app/auth @bitwarden/team-auth-dev +libs/auth @bitwarden/team-auth-dev # web connectors used for auth apps/web/src/connectors @bitwarden/team-auth-dev bitwarden_license/bit-web/src/app/auth @bitwarden/team-auth-dev diff --git a/.github/whitelist-capital-letters.txt b/.github/whitelist-capital-letters.txt index fd03af5f08..17047f4333 100644 --- a/.github/whitelist-capital-letters.txt +++ b/.github/whitelist-capital-letters.txt @@ -31,6 +31,7 @@ ./libs/common/src/services/vaultTimeout/vaultTimeoutSettings.service.ts ./libs/common/src/services/vaultTimeout/vaultTimeout.service.ts ./libs/common/src/services/anonymousHub.service.ts +./libs/auth/README.md ./README.md ./LICENSE_BITWARDEN.txt ./CONTRIBUTING.md diff --git a/apps/browser/tsconfig.json b/apps/browser/tsconfig.json index 6c5e4330b7..9220b89c42 100644 --- a/apps/browser/tsconfig.json +++ b/apps/browser/tsconfig.json @@ -11,6 +11,7 @@ "baseUrl": ".", "paths": { "@bitwarden/angular/*": ["../../libs/angular/src/*"], + "@bitwarden/auth": ["../../libs/auth/src"], "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/components": ["../../libs/components/src"], "@bitwarden/exporter/*": ["../../libs/exporter/src/*"] diff --git a/apps/desktop/tsconfig.json b/apps/desktop/tsconfig.json index bf55862559..f34ba7cfae 100644 --- a/apps/desktop/tsconfig.json +++ b/apps/desktop/tsconfig.json @@ -11,6 +11,7 @@ "baseUrl": ".", "paths": { "@bitwarden/angular/*": ["../../libs/angular/src/*"], + "@bitwarden/auth": ["../../libs/auth/src"], "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/components": ["../../libs/components/src"], "@bitwarden/exporter/*": ["../../libs/exporter/src/*"] diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index f5d6f72d96..9048efd39b 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -5,12 +5,13 @@ "module": "ES2020", "resolveJsonModule": true, "paths": { - "@bitwarden/web-vault/*": ["src/*"], - "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/angular/*": ["../../libs/angular/src/*"], + "@bitwarden/auth": ["../../libs/auth/src"], + "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/components": ["../../libs/components/src"], + "@bitwarden/exporter/*": ["../../libs/exporter/src/*"], "@bitwarden/importer": ["../../libs/importer/src"], - "@bitwarden/exporter/*": ["../../libs/exporter/src/*"] + "@bitwarden/web-vault/*": ["src/*"] } }, "angularCompilerOptions": { diff --git a/bitwarden_license/bit-web/tsconfig.json b/bitwarden_license/bit-web/tsconfig.json index 9f3a822488..a712fae902 100644 --- a/bitwarden_license/bit-web/tsconfig.json +++ b/bitwarden_license/bit-web/tsconfig.json @@ -2,11 +2,12 @@ "extends": "../../apps/web/tsconfig", "compilerOptions": { "paths": { - "@bitwarden/web-vault/*": ["../../apps/web/src/*"], - "@bitwarden/common/*": ["../../libs/common/src/*"], "@bitwarden/angular/*": ["../../libs/angular/src/*"], + "@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/web-vault/*": ["../../apps/web/src/*"] } }, "include": ["src/**/*.stories.ts"] diff --git a/jest.config.js b/jest.config.js index 8b54a82658..c4213fa143 100644 --- a/jest.config.js +++ b/jest.config.js @@ -21,10 +21,11 @@ module.exports = { "/bitwarden_license/bit-web/jest.config.js", "/libs/angular/jest.config.js", + "/libs/auth/jest.config.js", "/libs/common/jest.config.js", "/libs/components/jest.config.js", - "/libs/importer/jest.config.js", "/libs/exporter/jest.config.js", + "/libs/importer/jest.config.js", "/libs/node/jest.config.js", ], diff --git a/libs/auth/README.md b/libs/auth/README.md new file mode 100644 index 0000000000..59e6384fae --- /dev/null +++ b/libs/auth/README.md @@ -0,0 +1,3 @@ +# Auth + +This lib represents the public API of the Auth team at Bitwarden. Modules are imported using `@bitwarden/auth`. diff --git a/libs/auth/jest.config.js b/libs/auth/jest.config.js new file mode 100644 index 0000000000..3db83db07a --- /dev/null +++ b/libs/auth/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/auth tests", + preset: "jest-preset-angular", + setupFilesAfterEnv: ["/test.setup.ts"], + moduleNameMapper: pathsToModuleNameMapper(compilerOptions?.paths || {}, { + prefix: "/", + }), +}; diff --git a/libs/auth/package.json b/libs/auth/package.json new file mode 100644 index 0000000000..52c1be63f8 --- /dev/null +++ b/libs/auth/package.json @@ -0,0 +1,20 @@ +{ + "name": "@bitwarden/auth", + "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/auth/src/index.ts b/libs/auth/src/index.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/libs/auth/test.setup.ts b/libs/auth/test.setup.ts new file mode 100644 index 0000000000..6be6e7b8dd --- /dev/null +++ b/libs/auth/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/auth/tsconfig.json b/libs/auth/tsconfig.json new file mode 100644 index 0000000000..6004a56fb5 --- /dev/null +++ b/libs/auth/tsconfig.json @@ -0,0 +1,5 @@ +{ + "extends": "../shared/tsconfig.libs", + "include": ["src", "spec"], + "exclude": ["node_modules", "dist"] +} diff --git a/libs/auth/tsconfig.spec.json b/libs/auth/tsconfig.spec.json new file mode 100644 index 0000000000..de184bd760 --- /dev/null +++ b/libs/auth/tsconfig.spec.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "files": ["./test.setup.ts"] +} diff --git a/libs/shared/tsconfig.libs.json b/libs/shared/tsconfig.libs.json index 8eda1dc0d7..28a1ccdfa4 100644 --- a/libs/shared/tsconfig.libs.json +++ b/libs/shared/tsconfig.libs.json @@ -2,11 +2,12 @@ "extends": "./tsconfig", "compilerOptions": { "paths": { - "@bitwarden/common/*": ["../common/src/*"], "@bitwarden/angular/*": ["../angular/src/*"], - "@bitwarden/node/*": ["../node/src/*"], + "@bitwarden/auth": ["../auth/src/*"], + "@bitwarden/common/*": ["../common/src/*"], + "@bitwarden/exporter/*": ["../exporter/src/*"], "@bitwarden/importer": ["../importer/src"], - "@bitwarden/exporter/*": ["../exporter/src/*"] + "@bitwarden/node/*": ["../node/src/*"] } } } diff --git a/package-lock.json b/package-lock.json index bd51b35ce9..df157a9cff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -250,6 +250,11 @@ "version": "0.0.0", "license": "GPL-3.0" }, + "libs/auth": { + "name": "@bitwarden/auth", + "version": "0.0.0", + "license": "GPL-3.0" + }, "libs/common": { "name": "@bitwarden/common", "version": "0.0.0", @@ -4392,6 +4397,10 @@ "resolved": "libs/angular", "link": true }, + "node_modules/@bitwarden/auth": { + "resolved": "libs/auth", + "link": true + }, "node_modules/@bitwarden/browser": { "resolved": "apps/browser", "link": true diff --git a/tailwind.config.js b/tailwind.config.js index 2101288993..4011729cf5 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -3,6 +3,7 @@ const config = require("./libs/components/tailwind.config.base"); config.content = [ "./libs/components/src/**/*.{html,ts,mdx}", + "./libs/auth/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 3398efa9fd..33037c385e 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -15,11 +15,12 @@ "outDir": "dist", "baseUrl": ".", "paths": { - "@bitwarden/common/*": ["./libs/common/src/*"], "@bitwarden/angular/*": ["./libs/angular/src/*"], - "@bitwarden/node/*": ["./libs/node/src/*"], + "@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/node/*": ["./libs/node/src/*"] }, "plugins": [ { diff --git a/tsconfig.json b/tsconfig.json index 649052c152..41d9203970 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,12 +15,13 @@ "baseUrl": ".", "resolveJsonModule": true, "paths": { - "@bitwarden/common/*": ["./libs/common/src/*"], "@bitwarden/angular/*": ["./libs/angular/src/*"], - "@bitwarden/node/*": ["./libs/node/src/*"], + "@bitwarden/auth": ["./libs/auth/src"], + "@bitwarden/common/*": ["./libs/common/src/*"], "@bitwarden/components": ["./libs/components/src"], - "@bitwarden/importer": ["./libs/importer/src"], "@bitwarden/exporter/*": ["./libs/exporter/src/*"], + "@bitwarden/importer": ["./libs/importer/src"], + "@bitwarden/node/*": ["./libs/node/src/*"], "@bitwarden/web-vault/*": ["./apps/web/src/*"] }, "plugins": [