1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00
Files
browser/libs/common/src/tools/integration
Alexander Aronov 8885f5da24 [PM-19914][PM-19913] trim domains and long fields in forwarders (#14141)
* PM-19913: Added max length to the generated_for and description peroperties in the FirefoxRelay API payload
* [PM-19913] Added maxLength restriction to the website and generatedBy methods. Added maxLength limit of 200 to the description of addy.io
2025-04-14 08:42:41 -04:00
..

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/rpc is 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;