diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 590887b3cad..9502a9c404d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -18,6 +18,7 @@ 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 +libs/user-core @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/libs/common/src/types/guid.ts b/libs/common/src/types/guid.ts index bf891b55691..5edd34e4fc5 100644 --- a/libs/common/src/types/guid.ts +++ b/libs/common/src/types/guid.ts @@ -2,7 +2,9 @@ import { Opaque } from "type-fest"; export type Guid = Opaque; -export type UserId = Opaque; +// Convenience re-export of UserId from it's original location, any library that +// wants to be lower level than common should instead import it from user-core. +export { UserId } from "@bitwarden/user-core"; export type OrganizationId = Opaque; export type CollectionId = Opaque; export type ProviderId = Opaque; diff --git a/libs/user-core/README.md b/libs/user-core/README.md new file mode 100644 index 00000000000..57975746606 --- /dev/null +++ b/libs/user-core/README.md @@ -0,0 +1,6 @@ +# user-core + +Owned by: auth + +The very basic concept that constitutes a user, this needs to be very low level to facilitate +Platform keeping their own code low level. diff --git a/libs/user-core/eslint.config.mjs b/libs/user-core/eslint.config.mjs new file mode 100644 index 00000000000..9c37d10e3ff --- /dev/null +++ b/libs/user-core/eslint.config.mjs @@ -0,0 +1,3 @@ +import baseConfig from "../../eslint.config.mjs"; + +export default [...baseConfig]; diff --git a/libs/user-core/jest.config.js b/libs/user-core/jest.config.js new file mode 100644 index 00000000000..e38a12f3eb5 --- /dev/null +++ b/libs/user-core/jest.config.js @@ -0,0 +1,10 @@ +module.exports = { + displayName: "user-core", + preset: "../../jest.preset.js", + testEnvironment: "node", + transform: { + "^.+\\.[tj]s$": ["ts-jest", { tsconfig: "/tsconfig.spec.json" }], + }, + moduleFileExtensions: ["ts", "js", "html"], + coverageDirectory: "../../coverage/libs/user-core", +}; diff --git a/libs/user-core/package.json b/libs/user-core/package.json new file mode 100644 index 00000000000..2251d2ceace --- /dev/null +++ b/libs/user-core/package.json @@ -0,0 +1,10 @@ +{ + "name": "@bitwarden/user-core", + "version": "0.0.0", + "description": "The very basic concept that constitutes a user, this needs to be very low level to facilitate Platform keeping their own code low level.", + "type": "commonjs", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "license": "GPL-3.0", + "author": "auth" +} diff --git a/libs/user-core/project.json b/libs/user-core/project.json new file mode 100644 index 00000000000..60d5873208d --- /dev/null +++ b/libs/user-core/project.json @@ -0,0 +1,27 @@ +{ + "name": "user-core", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/user-core/src", + "projectType": "library", + "tags": [], + "targets": { + "build": { + "executor": "@nx/js:tsc", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/libs/user-core", + "main": "libs/user-core/src/index.ts", + "tsConfig": "libs/user-core/tsconfig.lib.json", + "assets": ["libs/user-core/*.md"] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], + "options": { + "jestConfig": "libs/user-core/jest.config.js", + "passWithNoTests": true + } + } + } +} diff --git a/libs/user-core/src/index.ts b/libs/user-core/src/index.ts new file mode 100644 index 00000000000..42e663c851a --- /dev/null +++ b/libs/user-core/src/index.ts @@ -0,0 +1,9 @@ +import { Opaque } from "type-fest"; + +/** + * The main identifier for a user. It is a string that should be in valid guid format. + * + * You should avoid `as UserId`-ing strings as much as possible and instead retrieve the {@see UserId} from + * a valid source instead. + */ +export type UserId = Opaque; diff --git a/libs/user-core/tsconfig.json b/libs/user-core/tsconfig.json new file mode 100644 index 00000000000..62ebbd94647 --- /dev/null +++ b/libs/user-core/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/user-core/tsconfig.lib.json b/libs/user-core/tsconfig.lib.json new file mode 100644 index 00000000000..9cbf6736007 --- /dev/null +++ b/libs/user-core/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/user-core/tsconfig.spec.json b/libs/user-core/tsconfig.spec.json new file mode 100644 index 00000000000..1275f148a18 --- /dev/null +++ b/libs/user-core/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 e9701cbd7ee..d7c23e0997b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -427,6 +427,10 @@ "version": "0.0.0", "license": "GPL-3.0" }, + "libs/user-core": { + "version": "0.0.0", + "license": "GPL-3.0" + }, "libs/vault": { "name": "@bitwarden/vault", "version": "0.0.0", @@ -4640,6 +4644,10 @@ "resolved": "libs/ui/common", "link": true }, + "node_modules/@bitwarden/user-core": { + "resolved": "libs/user-core", + "link": true + }, "node_modules/@bitwarden/vault": { "resolved": "libs/vault", "link": true diff --git a/tsconfig.base.json b/tsconfig.base.json index c820306fd15..c462ab97d37 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -47,6 +47,7 @@ "@bitwarden/storage-test-utils": ["libs/storage-test-utils/src/index.ts"], "@bitwarden/ui-common": ["./libs/ui/common/src"], "@bitwarden/ui-common/setup-jest": ["./libs/ui/common/src/setup-jest"], + "@bitwarden/user-core": ["libs/user-core/src/index.ts"], "@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"],