mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +00:00
[PM-7489] Introduce MessageSender & MessageListener (#8709)
* Introduce MessageSender * Update `messageSenderFactory` * Remove Comment * Use BrowserApi * Update Comment * Rename to CommandDefinition * Add More Documentation to MessageSender * Add `EMPTY` helpers and remove NoopMessageSender * Calm Down Logging * Limit Logging On Known Errors * Use `messageStream` Parameter Co-authored-by: Matt Gibson <mgibson@bitwarden.com> * Add eslint rules * Update Error Handling Co-authored-by: Cesar Gonzalez <cesar.a.gonzalezcs@gmail.com> * Delete Lazy Classes In Favor of Observable Factories * Remove Fido Messages --------- Co-authored-by: Matt Gibson <mgibson@bitwarden.com> Co-authored-by: Cesar Gonzalez <cesar.a.gonzalezcs@gmail.com>
This commit is contained in:
23
libs/common/src/platform/messaging/helpers.ts
Normal file
23
libs/common/src/platform/messaging/helpers.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { MonoTypeOperatorFunction, map } from "rxjs";
|
||||
|
||||
import { Message, CommandDefinition } from "./types";
|
||||
|
||||
export const getCommand = (commandDefinition: CommandDefinition<object> | string) => {
|
||||
if (typeof commandDefinition === "string") {
|
||||
return commandDefinition;
|
||||
} else {
|
||||
return commandDefinition.command;
|
||||
}
|
||||
};
|
||||
|
||||
export const EXTERNAL_SOURCE_TAG = Symbol("externalSource");
|
||||
|
||||
export const isExternalMessage = (message: Message<object>) => {
|
||||
return (message as Record<PropertyKey, unknown>)?.[EXTERNAL_SOURCE_TAG] === true;
|
||||
};
|
||||
|
||||
export const tagAsExternal: MonoTypeOperatorFunction<Message<object>> = map(
|
||||
(message: Message<object>) => {
|
||||
return Object.assign(message, { [EXTERNAL_SOURCE_TAG]: true });
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user