1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00
Files
browser/libs/common/src/tools/integration/rpc/rpc.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

27 lines
920 B
TypeScript

import { IntegrationMetadata } from "../integration-metadata";
import { IntegrationRequest } from "./integration-request";
/** A runtime RPC request that returns a JSON-encoded payload.
*/
export interface JsonRpc<Parameters extends IntegrationRequest, Result> {
/** information about the integration requesting RPC */
requestor: Readonly<IntegrationMetadata>;
/** creates a fetch request for the RPC
* @param request describes the state of the integration site
*/
toRequest(request: Parameters): Request;
/** returns true when there should be a JSON payload to process
* @param response the fetch API response returned by the RPC call
*/
hasJsonPayload(response: Response): boolean;
/** processes the json payload
* @param json the object to map
* @returns on success returns [Result], on failure returns [undefined, string]
*/
processJson(json: any): [Result?, string?];
}