mirror of
https://github.com/bitwarden/browser
synced 2026-02-11 22:13:32 +00:00
tweak vendor organization; add README
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { deepFreeze } from "../util";
|
||||
|
||||
import { ExtensionMetadata, SiteMetadata, VendorId } from "./type";
|
||||
import { ExtensionMetadata, SiteMetadata } from "./type";
|
||||
import { VendorId } from "./vendor/type";
|
||||
|
||||
/** Describes the capabilities of an extension site.
|
||||
* This type is immutable.
|
||||
|
||||
@@ -1,37 +1,24 @@
|
||||
import { DefaultExtensionRegistry } from "./default-extension-registry";
|
||||
import { Extension } from "./metadata";
|
||||
import { ExtensionMetadata } from "./type";
|
||||
import { AddyIo, AddyIoExtensions } from "./vendor/addy-io";
|
||||
import { DuckDuckGo, DuckDuckGoExtensions } from "./vendor/duck-duck-go";
|
||||
import { Fastmail, FastmailExtensions } from "./vendor/fastmail";
|
||||
import { ForwardEmail, ForwardEmailExtensions } from "./vendor/forward-email";
|
||||
import { Mozilla, MozillaExtensions } from "./vendor/mozilla";
|
||||
import { SimpleLogin, SimpleLoginExtensions } from "./vendor/simple-login";
|
||||
import { VendorMetadata } from "./vendor/type";
|
||||
import { VendorExtensions, Vendors } from "./vendor";
|
||||
|
||||
// FIXME: find a better way to build the registry than a hard-coded factory function
|
||||
|
||||
/** Constructs the extension registry */
|
||||
export function buildRegistry() {
|
||||
function registerAll(vendor: VendorMetadata, extensions: ExtensionMetadata[]) {
|
||||
registry.registerVendor(vendor);
|
||||
for (const extension of extensions) {
|
||||
registry.registerExtension(extension);
|
||||
}
|
||||
}
|
||||
|
||||
const registry = new DefaultExtensionRegistry();
|
||||
|
||||
for (const site of Reflect.ownKeys(Extension) as string[]) {
|
||||
registry.registerSite(Extension[site]);
|
||||
}
|
||||
|
||||
registerAll(AddyIo, AddyIoExtensions);
|
||||
registerAll(DuckDuckGo, DuckDuckGoExtensions);
|
||||
registerAll(Fastmail, FastmailExtensions);
|
||||
registerAll(ForwardEmail, ForwardEmailExtensions);
|
||||
registerAll(Mozilla, MozillaExtensions);
|
||||
registerAll(SimpleLogin, SimpleLoginExtensions);
|
||||
for (const vendor of Vendors) {
|
||||
registry.registerVendor(vendor);
|
||||
}
|
||||
|
||||
for (const extension of VendorExtensions) {
|
||||
registry.registerExtension(extension);
|
||||
}
|
||||
|
||||
return registry;
|
||||
}
|
||||
|
||||
34
libs/common/src/tools/extension/vendor/README.md
vendored
Normal file
34
libs/common/src/tools/extension/vendor/README.md
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
# Vendors
|
||||
|
||||
This folder contains vendor-specific logic that extends the
|
||||
Bitwarden password manager.
|
||||
|
||||
## Vendor IDs
|
||||
|
||||
A vendor's ID is used to identify and trace the code provided by
|
||||
a vendor across Bitwarden. There are a few rules that vendor ids
|
||||
must follow:
|
||||
|
||||
1. They should be human-readable. (No UUIDs.)
|
||||
2. They may only contain lowercase ASCII characters and numbers.
|
||||
3. They must retain backwards compatibility with prior versions.
|
||||
|
||||
As such, any given ID may not not match the vendor's present
|
||||
brand identity. Said branding may be stored in `VendorMetadata.name`.
|
||||
|
||||
## Core files
|
||||
|
||||
There are 4 vendor-independent files in this directory.
|
||||
|
||||
- `data.ts` - core metadata used for system initialization
|
||||
- `index.ts` - exports vendor metadata
|
||||
- `README.md` - this file
|
||||
- `type.ts` - type definitions for vendor metadata
|
||||
|
||||
## Vendor definitions
|
||||
|
||||
Each vendor should have one and only one definition, whose name
|
||||
MUST match their `VendorId`. The vendor is free to use either a
|
||||
single file (e.g. `bitwarden.ts`) or a folder containing multiple
|
||||
files (e.g. `bitwarden/extension.ts`, `bitwarden/forwarder.ts`) to
|
||||
host their files.
|
||||
42
libs/common/src/tools/extension/vendor/data.ts
vendored
42
libs/common/src/tools/extension/vendor/data.ts
vendored
@@ -1,7 +1,3 @@
|
||||
import { Site } from "../data";
|
||||
|
||||
import { VendorMetadata } from "./type";
|
||||
|
||||
export const Vendor = Object.freeze({
|
||||
anonaddy: "anonaddy",
|
||||
duckduckgo: "duckduckgo",
|
||||
@@ -10,41 +6,3 @@ export const Vendor = Object.freeze({
|
||||
forwardemail: "forwardemail",
|
||||
simplelogin: "simplelogin",
|
||||
} as const);
|
||||
|
||||
export const VendorInfo: Record<string, VendorMetadata> = {
|
||||
[Vendor.anonaddy]: {
|
||||
id: Vendor.anonaddy,
|
||||
name: "Addy.io",
|
||||
},
|
||||
[Vendor.duckduckgo]: {
|
||||
id: Vendor.duckduckgo,
|
||||
name: "DuckDuckGo",
|
||||
},
|
||||
[Vendor.fastmail]: {
|
||||
id: Vendor.fastmail,
|
||||
name: "Fastmail",
|
||||
},
|
||||
[Vendor.mozilla]: {
|
||||
id: Vendor.mozilla,
|
||||
name: "Mozilla",
|
||||
},
|
||||
[Vendor.forwardemail]: {
|
||||
id: Vendor.forwardemail,
|
||||
name: "Forward Email",
|
||||
},
|
||||
[Vendor.simplelogin]: {
|
||||
id: Vendor.simplelogin,
|
||||
name: "SimpleLogin",
|
||||
},
|
||||
};
|
||||
|
||||
export const VendorsByExtension = {
|
||||
[Site.forwarder]: [
|
||||
Vendor.anonaddy,
|
||||
Vendor.duckduckgo,
|
||||
Vendor.fastmail,
|
||||
Vendor.mozilla,
|
||||
Vendor.forwardemail,
|
||||
Vendor.simplelogin,
|
||||
] as const,
|
||||
} as const;
|
||||
|
||||
28
libs/common/src/tools/extension/vendor/index.ts
vendored
Normal file
28
libs/common/src/tools/extension/vendor/index.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { deepFreeze } from "../../util";
|
||||
|
||||
import { AddyIo, AddyIoExtensions } from "./addy-io";
|
||||
import { DuckDuckGo, DuckDuckGoExtensions } from "./duck-duck-go";
|
||||
import { Fastmail, FastmailExtensions } from "./fastmail";
|
||||
import { ForwardEmail, ForwardEmailExtensions } from "./forward-email";
|
||||
import { Mozilla, MozillaExtensions } from "./mozilla";
|
||||
import { SimpleLogin, SimpleLoginExtensions } from "./simple-login";
|
||||
|
||||
export const Vendors = deepFreeze([
|
||||
AddyIo,
|
||||
DuckDuckGo,
|
||||
Fastmail,
|
||||
ForwardEmail,
|
||||
Mozilla,
|
||||
SimpleLogin,
|
||||
]);
|
||||
|
||||
export const VendorExtensions = deepFreeze(
|
||||
[
|
||||
AddyIoExtensions,
|
||||
DuckDuckGoExtensions,
|
||||
FastmailExtensions,
|
||||
ForwardEmailExtensions,
|
||||
MozillaExtensions,
|
||||
SimpleLoginExtensions,
|
||||
].flat(),
|
||||
);
|
||||
@@ -1,9 +1,7 @@
|
||||
import { SiteId } from "../type";
|
||||
|
||||
import { VendorsByExtension } from "./data";
|
||||
import { Vendor } from "./data";
|
||||
|
||||
/** Identifies a vendor extending bitwarden */
|
||||
export type VendorId = (typeof VendorsByExtension)[SiteId][number];
|
||||
export type VendorId = keyof typeof Vendor;
|
||||
|
||||
/** The capabilities and descriptive content for an extension */
|
||||
export type VendorMetadata = {
|
||||
|
||||
Reference in New Issue
Block a user