1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-05 19:23:19 +00:00

refactor: introduce @bitwarden/device-type

This commit is contained in:
addisonbeck
2025-08-09 12:00:44 -04:00
parent 326d7bf3bd
commit b1cea2359e
15 changed files with 191 additions and 70 deletions

1
.github/CODEOWNERS vendored
View File

@@ -102,6 +102,7 @@ libs/client-type @bitwarden/team-platform-dev
libs/core-test-utils @bitwarden/team-platform-dev
libs/state @bitwarden/team-platform-dev
libs/state-test-utils @bitwarden/team-platform-dev
libs/device-type @bitwarden/team-platform-dev
# Web utils used across app and connectors
apps/web/src/utils/ @bitwarden/team-platform-dev
# Web core and shared files

View File

@@ -1,70 +1 @@
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum DeviceType {
Android = 0,
iOS = 1,
ChromeExtension = 2,
FirefoxExtension = 3,
OperaExtension = 4,
EdgeExtension = 5,
WindowsDesktop = 6,
MacOsDesktop = 7,
LinuxDesktop = 8,
ChromeBrowser = 9,
FirefoxBrowser = 10,
OperaBrowser = 11,
EdgeBrowser = 12,
IEBrowser = 13,
UnknownBrowser = 14,
AndroidAmazon = 15,
UWP = 16,
SafariBrowser = 17,
VivaldiBrowser = 18,
VivaldiExtension = 19,
SafariExtension = 20,
SDK = 21,
Server = 22,
WindowsCLI = 23,
MacOsCLI = 24,
LinuxCLI = 25,
DuckDuckGoBrowser = 26,
}
/**
* Device type metadata
* Each device type has a category corresponding to the client type and platform (Android, iOS, Chrome, Firefox, etc.)
*/
interface DeviceTypeMetadata {
category: "mobile" | "extension" | "webApp" | "desktop" | "cli" | "sdk" | "server";
platform: string;
}
export const DeviceTypeMetadata: Record<DeviceType, DeviceTypeMetadata> = {
[DeviceType.Android]: { category: "mobile", platform: "Android" },
[DeviceType.iOS]: { category: "mobile", platform: "iOS" },
[DeviceType.AndroidAmazon]: { category: "mobile", platform: "Amazon" },
[DeviceType.ChromeExtension]: { category: "extension", platform: "Chrome" },
[DeviceType.FirefoxExtension]: { category: "extension", platform: "Firefox" },
[DeviceType.OperaExtension]: { category: "extension", platform: "Opera" },
[DeviceType.EdgeExtension]: { category: "extension", platform: "Edge" },
[DeviceType.VivaldiExtension]: { category: "extension", platform: "Vivaldi" },
[DeviceType.SafariExtension]: { category: "extension", platform: "Safari" },
[DeviceType.ChromeBrowser]: { category: "webApp", platform: "Chrome" },
[DeviceType.FirefoxBrowser]: { category: "webApp", platform: "Firefox" },
[DeviceType.OperaBrowser]: { category: "webApp", platform: "Opera" },
[DeviceType.EdgeBrowser]: { category: "webApp", platform: "Edge" },
[DeviceType.IEBrowser]: { category: "webApp", platform: "IE" },
[DeviceType.SafariBrowser]: { category: "webApp", platform: "Safari" },
[DeviceType.VivaldiBrowser]: { category: "webApp", platform: "Vivaldi" },
[DeviceType.DuckDuckGoBrowser]: { category: "webApp", platform: "DuckDuckGo" },
[DeviceType.UnknownBrowser]: { category: "webApp", platform: "Unknown" },
[DeviceType.WindowsDesktop]: { category: "desktop", platform: "Windows" },
[DeviceType.MacOsDesktop]: { category: "desktop", platform: "macOS" },
[DeviceType.LinuxDesktop]: { category: "desktop", platform: "Linux" },
[DeviceType.UWP]: { category: "desktop", platform: "Windows UWP" },
[DeviceType.WindowsCLI]: { category: "cli", platform: "Windows" },
[DeviceType.MacOsCLI]: { category: "cli", platform: "macOS" },
[DeviceType.LinuxCLI]: { category: "cli", platform: "Linux" },
[DeviceType.SDK]: { category: "sdk", platform: "" },
[DeviceType.Server]: { category: "server", platform: "" },
};
export { DeviceType, DeviceTypeMetadata } from "@bitwarden/device-type";

View File

@@ -0,0 +1,5 @@
# device-type
Owned by: platform
Constants and helpers for working with specific device types

View File

@@ -0,0 +1,3 @@
import baseConfig from "../../eslint.config.mjs";
export default [...baseConfig];

View File

@@ -0,0 +1,10 @@
module.exports = {
displayName: "device-type",
preset: "../../jest.preset.js",
testEnvironment: "node",
transform: {
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
},
moduleFileExtensions: ["ts", "js", "html"],
coverageDirectory: "../../coverage/libs/device-type",
};

View File

@@ -0,0 +1,11 @@
{
"name": "@bitwarden/device-type",
"version": "0.0.1",
"description": "Constants and helpers for working with specific device types",
"private": true,
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "GPL-3.0",
"author": "platform"
}

View File

@@ -0,0 +1,33 @@
{
"name": "device-type",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/device-type/src",
"projectType": "library",
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/device-type",
"main": "libs/device-type/src/index.ts",
"tsConfig": "libs/device-type/tsconfig.lib.json",
"assets": ["libs/device-type/*.md"]
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/device-type/**/*.ts"]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/device-type/jest.config.js"
}
}
}
}

View File

@@ -0,0 +1,8 @@
import * as lib from "./index";
describe("device-type", () => {
// This test will fail until something is exported from index.ts
it("should work", () => {
expect(lib).toBeDefined();
});
});

View File

@@ -0,0 +1,70 @@
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
export enum DeviceType {
Android = 0,
iOS = 1,
ChromeExtension = 2,
FirefoxExtension = 3,
OperaExtension = 4,
EdgeExtension = 5,
WindowsDesktop = 6,
MacOsDesktop = 7,
LinuxDesktop = 8,
ChromeBrowser = 9,
FirefoxBrowser = 10,
OperaBrowser = 11,
EdgeBrowser = 12,
IEBrowser = 13,
UnknownBrowser = 14,
AndroidAmazon = 15,
UWP = 16,
SafariBrowser = 17,
VivaldiBrowser = 18,
VivaldiExtension = 19,
SafariExtension = 20,
SDK = 21,
Server = 22,
WindowsCLI = 23,
MacOsCLI = 24,
LinuxCLI = 25,
DuckDuckGoBrowser = 26,
}
/**
* Device type metadata
* Each device type has a category corresponding to the client type and platform (Android, iOS, Chrome, Firefox, etc.)
*/
interface DeviceTypeMetadata {
category: "mobile" | "extension" | "webApp" | "desktop" | "cli" | "sdk" | "server";
platform: string;
}
export const DeviceTypeMetadata: Record<DeviceType, DeviceTypeMetadata> = {
[DeviceType.Android]: { category: "mobile", platform: "Android" },
[DeviceType.iOS]: { category: "mobile", platform: "iOS" },
[DeviceType.AndroidAmazon]: { category: "mobile", platform: "Amazon" },
[DeviceType.ChromeExtension]: { category: "extension", platform: "Chrome" },
[DeviceType.FirefoxExtension]: { category: "extension", platform: "Firefox" },
[DeviceType.OperaExtension]: { category: "extension", platform: "Opera" },
[DeviceType.EdgeExtension]: { category: "extension", platform: "Edge" },
[DeviceType.VivaldiExtension]: { category: "extension", platform: "Vivaldi" },
[DeviceType.SafariExtension]: { category: "extension", platform: "Safari" },
[DeviceType.ChromeBrowser]: { category: "webApp", platform: "Chrome" },
[DeviceType.FirefoxBrowser]: { category: "webApp", platform: "Firefox" },
[DeviceType.OperaBrowser]: { category: "webApp", platform: "Opera" },
[DeviceType.EdgeBrowser]: { category: "webApp", platform: "Edge" },
[DeviceType.IEBrowser]: { category: "webApp", platform: "IE" },
[DeviceType.SafariBrowser]: { category: "webApp", platform: "Safari" },
[DeviceType.VivaldiBrowser]: { category: "webApp", platform: "Vivaldi" },
[DeviceType.DuckDuckGoBrowser]: { category: "webApp", platform: "DuckDuckGo" },
[DeviceType.UnknownBrowser]: { category: "webApp", platform: "Unknown" },
[DeviceType.WindowsDesktop]: { category: "desktop", platform: "Windows" },
[DeviceType.MacOsDesktop]: { category: "desktop", platform: "macOS" },
[DeviceType.LinuxDesktop]: { category: "desktop", platform: "Linux" },
[DeviceType.UWP]: { category: "desktop", platform: "Windows UWP" },
[DeviceType.WindowsCLI]: { category: "cli", platform: "Windows" },
[DeviceType.MacOsCLI]: { category: "cli", platform: "macOS" },
[DeviceType.LinuxCLI]: { category: "cli", platform: "Linux" },
[DeviceType.SDK]: { category: "sdk", platform: "" },
[DeviceType.Server]: { category: "server", platform: "" },
};

View File

@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": ["src/**/*.ts", "src/**/*.js"],
"exclude": ["**/build", "**/dist"]
}

View File

@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

View File

@@ -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"]
}

View File

@@ -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"]
}

9
package-lock.json generated
View File

@@ -337,6 +337,11 @@
"version": "0.0.1",
"license": "GPL-3.0"
},
"libs/device-type": {
"name": "@bitwarden/device-type",
"version": "0.0.1",
"license": "GPL-3.0"
},
"libs/dirt/card": {
"name": "@bitwarden/dirt-card",
"version": "0.0.0",
@@ -4599,6 +4604,10 @@
"resolved": "apps/desktop/desktop_native/napi",
"link": true
},
"node_modules/@bitwarden/device-type": {
"resolved": "libs/device-type",
"link": true
},
"node_modules/@bitwarden/dirt-card": {
"resolved": "libs/dirt/card",
"link": true

View File

@@ -29,6 +29,7 @@
"@bitwarden/common/*": ["./libs/common/src/*"],
"@bitwarden/components": ["./libs/components/src"],
"@bitwarden/core-test-utils": ["libs/core-test-utils/src/index.ts"],
"@bitwarden/device-type": ["libs/device-type/src/index.ts"],
"@bitwarden/dirt-card": ["./libs/dirt/card/src"],
"@bitwarden/generator-components": ["./libs/tools/generator/components/src"],
"@bitwarden/generator-core": ["./libs/tools/generator/core/src"],