All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Add
Messenger.getRegisteredActionTypesmethod, which returns the action types the messenger can call directly (#9271) - Add a
buildChildutility method toMessenger(#9338)
- Bump
@metamask/utilsfrom^11.9.0to^11.11.0(#9074)
- BREAKING: Remove deprecated
generate-action-typesCLI tool (#9367)- The CLI has been extracted to
@metamask/messenger-cli. Usemessenger-action-typesfrom that package instead.
- The CLI has been extracted to
- Fix
Messenger.delegateandMessenger.revoketo reduce the chance of TS2590 errors when delegatee has large number of actions/events or a large number of actions/events are being delegated (#8748)
- Allow overriding action handler in subclass (#8617)
- The
Messengerclass now has a protectedgetActionmethod which returns the action handler for a given action name.
- The
- Add
subscribeOnceandwaitUntilutility methods toMessenger(#8575)
- Deprecate
generate-action-typesCLI tool andmessenger-generate-action-typesbinary (#8378)- The CLI has been extracted to
@metamask/messenger-cli. Usemessenger-action-typesfrom this package instead.
- The CLI has been extracted to
- Throw different error for missing delegated actions (#8557)
- Drop peer dependency on
eslintto prevent audit failures on consumers using ESLint 8.x (#8371)
- Add
generate-action-typesCLI tool (#8264)- Generates TypeScript action type files for controllers and services that define
MESSENGER_EXPOSED_METHODS. - Available as a CLI binary (
messenger-generate-action-types).typescriptandeslintare peer dependencies.
- Generates TypeScript action type files for controllers and services that define
- This package is now considered stable (#8317)
- Add
captureExceptionconstructor parameter (#6605)- This function will be used to capture any errors thrown from subscribers.
- If this is unset but a parent is provided,
captureExceptionis inherited from the parent.
- Stop re-throwing subscriber errors in a
setTimeout(#6605)- Instead errors are captured with
captureException, or logged to the console.
- Instead errors are captured with
- Allow disabling namespace checks in unit tests using the new
MOCK_ANY_NAMESPACEconstant andMockAnyNamespacetype (#6420)- To disable namespace checks, use
MockAnyNamespaceas theNamespacetype parameter, and useMOCK_ANY_NAMESPACEas thenamespaceconstructor parameter.
- To disable namespace checks, use
- Keep delegated handlers when unregistering actions (#6395)
- Migrate
Messengerclass from@metamask/base-controllerpackage (#6127) - Add
delegateandrevokemethods (#6132)- These allow delegating or revoking capabilities (actions or events) from one
Messengerinstance to another. - This allows passing capabilities through chains of messengers of arbitrary length
- See this ADR for details: https://github.com/MetaMask/decisions/blob/main/decisions/core/0012-messenger-delegation.md
- These allow delegating or revoking capabilities (actions or events) from one
- Add
parentconstructor parameter and type parameter toMessenger(#6142)- All capabilities registered under this messenger's namespace are delegated to the parent automatically. This is similar to how the
RestrictedMessengerwould automatically delegate all capabilities to the messenger it was created from.
- All capabilities registered under this messenger's namespace are delegated to the parent automatically. This is similar to how the
- Add
MessengerActionsandMessengerEventsutility types for extracting actions/events from aMessengertype (#6317)
- BREAKING: Add
Namespacetype parameter and requirednamespaceconstructor parameter (#6132)- All published events and registered actions should fall under the given namespace. Typically the namespace is the controller or service name. This is the equivalent to the
Namespaceparameter from the oldRestrictedMessengerclass.
- All published events and registered actions should fall under the given namespace. Typically the namespace is the controller or service name. This is the equivalent to the
- BREAKING: The
typeproperty ofActionConstraintandEventConstraintis now aNamespacedNamerather than a string (#6132) - Add default for
ReturnHandlertype parameter ofSelectorEventHandlerandSelectorFunction(#6262, #6264) - Add default of
neverto action and event type parameters ofMessenger(#6311)
- BREAKING: Remove
RestrictedMessengerclass (#6132)- Existing
RestrictedMessengerinstances should be replaced with aMessengerwith theparentconstructor parameter set to the global messenger. We can now use the same class everywhere, passing capabilities usingdelegate. - See this ADR for details: https://github.com/MetaMask/decisions/blob/main/decisions/core/0012-messenger-delegation.md
- Existing