Skip to content

Commit

Permalink
Adds external message handler type
Browse files Browse the repository at this point in the history
  • Loading branch information
sleekslush committed Apr 25, 2024
1 parent 4b20b0b commit ce2e0d3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions api/messaging/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export namespace PlasmoMessaging {
targetOrigin?: string
}

export type ExternalRequest<TName = any, TBody = Record<any, any>> = {
name: TName
sender: chrome.runtime.MessageSender
} & TBody

export type RelayMessage<TName = any, TBody = any> = Request<TName, TBody> & {
/**
* Used to resolve corresponding window.postMessage messages
Expand Down Expand Up @@ -49,6 +54,15 @@ export namespace PlasmoMessaging {
response: Response<ResponseBody>
) => void | Promise<void> | boolean

export type ExternalHandler<
RequestName = string,
RequestBody = any,
ResponseBody = any
> = (
request: ExternalRequest<RequestName, RequestBody>,
response: Response<ResponseBody>
) => void | Promise<void> | boolean

export type PortHandler<RequestBody = any, ResponseBody = any> = Handler<
PortName,
RequestBody,
Expand All @@ -61,6 +75,11 @@ export namespace PlasmoMessaging {
ResponseBody
>

export type ExternalMessageHandler<
RequestBody = any,
ResponseBody = any
> = ExternalHandler<string, RequestBody, ResponseBody>

export interface SendFx<TName = string> {
<RequestBody = any, ResponseBody = any>(
request: Request<TName, RequestBody>,
Expand Down

0 comments on commit ce2e0d3

Please sign in to comment.