1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00
Files
browser/libs/common/src/tools/integration/rpc/rpc-definition.ts
✨ Audrey ✨ 24b84985f5 [PM-9598] Introduce integrations (#10019)
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.
2024-07-09 11:04:40 -04:00

41 lines
2.0 KiB
TypeScript

import { IntegrationRequest } from "./integration-request";
/** Defines how an integration processes an RPC call.
* @remarks This interface should not be used directly. Your integration should specialize
* it to fill a specific use-case. For example, the forwarder provides two specializations as follows:
*
* // optional; supplements the `IntegrationRequest` with an integrator-supplied account Id
* type GetAccountId = RpcConfiguration<IntegrationRequest, ForwarderContext<Settings>, ForwarderRequest>
*
* // generates a forwarding address
* type CreateForwardingEmail = RpcConfiguration<ForwarderRequest, ForwarderContext<Settings>, string>
*/
export interface RpcConfiguration<Request extends IntegrationRequest, Helper, Result> {
/** determine the URL of the lookup
* @param request describes the state of the integration site
* @param helper supplies logic from bitwarden specific to the integration site
*/
url(request: Request, helper: Helper): string;
/** format the body of the rpc call; when this method is not supplied, the request omits the body
* @param request describes the state of the integration site
* @param helper supplies logic from bitwarden specific to the integration site
* @returns a JSON object supplied as the body of the request
*/
body?(request: Request, helper: Helper): any;
/** returns true when there's a JSON payload to process
* @param response the fetch API response returned by the RPC call
* @param helper supplies logic from bitwarden specific to the integration site
*/
hasJsonPayload(response: Response, helper: Helper): boolean;
/** map body parsed as json payload of the rpc call.
* @param json the object to map
* @param helper supplies logic from bitwarden specific to the integration site
* @returns When the JSON is processed successfully, a 1-tuple whose value is the processed result.
* Otherwise, a 2-tuple whose first value is undefined, and whose second value is an error message.
*/
processJson(json: any, helper: Helper): [Result?, string?];
}