mirror of
https://github.com/bitwarden/browser
synced 2026-02-13 23:13:36 +00:00
Factor general integration logic out of the forwarder code. - Integration metadata - information generalized across any integration - Rpc mechanism - first step towards applying policy to integrations is abstracting their service calls (e.g. static baseUrl) Email forwarder integrations embedded this metadata. It was extracted to begin the process of making integrations compatible with meta-systems like policy. This PR consists mostly of interfaces, which are not particularly useful on their own. Examples on how they're used can be found in the readme.
2.5 KiB
2.5 KiB
This module defines interfaces and helpers for creating vendor integration sites.
RPC
⚠️ Only use for extension points! This logic is not suitable for general use. Making calls to the Bitwarden server api using
@bitwarden/common/tools/integration/rpcis prohibited.
Interfaces and helpers defining a remote procedure call to a vendor's service. These types provide extension points to produce and process the call without exposing a generalized fetch API.
Sample usage
An email forwarder configuration:
// define RPC shapes;
// * the request format, `RequestOptions` is common to all calls
// * the context operates on forwarder-specific settings provided by `state`.
type CreateForwardingEmailConfig<Settings> = RpcConfiguration<
RequestOptions,
ForwarderContext<Settings>
>;
// how a forwarder integration point might represent its configuration
type ForwarderConfiguration<Settings> = IntegrationConfiguration & {
forwarder: {
defaultState: Settings;
createForwardingEmail: CreateForwardingEmailConfig<Settings>;
};
};
// how an importer integration point might represent its configuration
type ImporterConfiguration = IntegrationConfiguration & {
importer: {
fileless: false | { selector: string };
formats: ContentType[];
crep:
| false
| {
/* credential exchange protocol configuration */
};
// ...
};
};
// how a plugin might be structured
export type JustTrustUsSettings = ApiSettings & EmailDomainSettings;
export type JustTrustUsConfiguration = ForwarderConfiguration<JustTrustUsSettings> &
ImporterConfiguration;
export const JustTrustUs = {
// common metadata
id: "justrustus",
name: "Just Trust Us, LLC",
extends: ["forwarder"],
// API conventions
selfHost: "never",
baseUrl: "https://api.just-trust.us/v1",
authenticate(settings: ApiSettings, context: IntegrationContext) {
return { Authorization: "Bearer " + context.authenticationToken(settings) };
},
// forwarder specific config
forwarder: {
defaultState: { domain: "just-trust.us" },
// specific RPC call
createForwardingEmail: {
url: () => context.baseUrl() + "/fowarder",
body: (request: RequestOptions) => ({ description: context.generatedBy(request) }),
hasJsonPayload: (response) => response.status === 200,
processJson: (json) => json.email,
},
},
// importer specific config
importer: {
fileless: false,
crep: false,
formats: ["text/csv", "application/json"],
},
} as JustTrustUsConfiguration;