Skip to content

Events

EventsSDK

EventsSDK<API, Events> = object

The SDK for the API RPC service.

Type Parameters

Type ParameterDefault type
APIobject
Eventsobject

Methods

onInterceptRequest()

onInterceptRequest(callback: (sdk: SDK<API, Events>, request: Request) => MaybePromise<void>): void

Registers an callback on new intercepted requests.

This callback is called asynchronously and cannot modify requests.

Parameters
ParameterType
callback(sdk: SDK<API, Events>, request: Request) => MaybePromise<void>
Returns

void

Example
ts
sdk.events.onInterceptRequest((sdk, request) => {
   // Do something with the request
});
onInterceptResponse()

onInterceptResponse(callback: (sdk: SDK<API, Events>, request: Request, response: Response) => MaybePromise<void>): void

Registers an callback on new intercepted responses.

This callback is called asynchronously and cannot modify responses.

Parameters
ParameterType
callback(sdk: SDK<API, Events>, request: Request, response: Response) => MaybePromise<void>
Returns

void

Example
ts
sdk.events.onInterceptResponse((sdk, request, response) => {
   // Do something with the request/response
});
onProjectChange()

onProjectChange(callback: (sdk: SDK<API, Events>, project: Project | null) => MaybePromise<void>): void

Registers an callback on project change.

This callback is called asynchronously and cannot modify the project.

It can happen that the project is null if the user deleted the currently selected one.

Parameters
ParameterType
callback(sdk: SDK<API, Events>, project: Project | null) => MaybePromise<void>
Returns

void

Example
ts
sdk.events.onProjectChange((sdk, project) => {
  if (project !== null) {
    // Do something with the project
  }
});
onUpstream()

onUpstream(callback: (sdk: SDK<API, Events>, request: RequestSpecRaw) => MaybePromise<UpstreamResult>): void

Callback called before the request is sent to the target.

This callback is called synchronously so special care should be taken to not impact overall performance.

The callback can return a Connection that will then be used to send the request. It can also return a RequestSpec to override the request sent to the target.

This will only be called if the user has enabled it for a given domain in the settings for Upstream Plugins.

Parameters
ParameterType
callback(sdk: SDK<API, Events>, request: RequestSpecRaw) => MaybePromise<UpstreamResult>
Returns

void

Example
ts
sdk.events.onUpstream(async (sdk, request) => {
   // Send all requests to example.com
   return {
     connection: await sdk.net.connect("https://example.com"),
   };
});

UpstreamResult

UpstreamResult = Connection | RequestSpec | { connection?: Connection; request?: RequestSpec; } | undefined

The result of an upstream callback.