@metamask/connectivity-controller
Advanced tools
| "use strict"; | ||
| /** | ||
| * This file is auto generated. | ||
| * Do not edit manually. | ||
| */ | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=ConnectivityController-method-action-types.cjs.map |
| {"version":3,"file":"ConnectivityController-method-action-types.cjs","sourceRoot":"","sources":["../src/ConnectivityController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ConnectivityController } from './ConnectivityController';\n\n/**\n * Initializes the controller by fetching the initial connectivity status.\n */\nexport type ConnectivityControllerInitAction = {\n type: `ConnectivityController:init`;\n handler: ConnectivityController['init'];\n};\n\n/**\n * Sets the connectivity status.\n *\n * @param status - The connectivity status to set.\n */\nexport type ConnectivityControllerSetConnectivityStatusAction = {\n type: `ConnectivityController:setConnectivityStatus`;\n handler: ConnectivityController['setConnectivityStatus'];\n};\n\n/**\n * Union of all ConnectivityController action types.\n */\nexport type ConnectivityControllerMethodActions =\n | ConnectivityControllerInitAction\n | ConnectivityControllerSetConnectivityStatusAction;\n"]} |
| /** | ||
| * This file is auto generated. | ||
| * Do not edit manually. | ||
| */ | ||
| import type { ConnectivityController } from "./ConnectivityController.cjs"; | ||
| /** | ||
| * Initializes the controller by fetching the initial connectivity status. | ||
| */ | ||
| export type ConnectivityControllerInitAction = { | ||
| type: `ConnectivityController:init`; | ||
| handler: ConnectivityController['init']; | ||
| }; | ||
| /** | ||
| * Sets the connectivity status. | ||
| * | ||
| * @param status - The connectivity status to set. | ||
| */ | ||
| export type ConnectivityControllerSetConnectivityStatusAction = { | ||
| type: `ConnectivityController:setConnectivityStatus`; | ||
| handler: ConnectivityController['setConnectivityStatus']; | ||
| }; | ||
| /** | ||
| * Union of all ConnectivityController action types. | ||
| */ | ||
| export type ConnectivityControllerMethodActions = ConnectivityControllerInitAction | ConnectivityControllerSetConnectivityStatusAction; | ||
| //# sourceMappingURL=ConnectivityController-method-action-types.d.cts.map |
| {"version":3,"file":"ConnectivityController-method-action-types.d.cts","sourceRoot":"","sources":["../src/ConnectivityController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAiC;AAEvE;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,gCAAgC,GAChC,iDAAiD,CAAC"} |
| /** | ||
| * This file is auto generated. | ||
| * Do not edit manually. | ||
| */ | ||
| import type { ConnectivityController } from "./ConnectivityController.mjs"; | ||
| /** | ||
| * Initializes the controller by fetching the initial connectivity status. | ||
| */ | ||
| export type ConnectivityControllerInitAction = { | ||
| type: `ConnectivityController:init`; | ||
| handler: ConnectivityController['init']; | ||
| }; | ||
| /** | ||
| * Sets the connectivity status. | ||
| * | ||
| * @param status - The connectivity status to set. | ||
| */ | ||
| export type ConnectivityControllerSetConnectivityStatusAction = { | ||
| type: `ConnectivityController:setConnectivityStatus`; | ||
| handler: ConnectivityController['setConnectivityStatus']; | ||
| }; | ||
| /** | ||
| * Union of all ConnectivityController action types. | ||
| */ | ||
| export type ConnectivityControllerMethodActions = ConnectivityControllerInitAction | ConnectivityControllerSetConnectivityStatusAction; | ||
| //# sourceMappingURL=ConnectivityController-method-action-types.d.mts.map |
| {"version":3,"file":"ConnectivityController-method-action-types.d.mts","sourceRoot":"","sources":["../src/ConnectivityController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,qCAAiC;AAEvE;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,gCAAgC,GAChC,iDAAiD,CAAC"} |
| /** | ||
| * This file is auto generated. | ||
| * Do not edit manually. | ||
| */ | ||
| export {}; | ||
| //# sourceMappingURL=ConnectivityController-method-action-types.mjs.map |
| {"version":3,"file":"ConnectivityController-method-action-types.mjs","sourceRoot":"","sources":["../src/ConnectivityController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ConnectivityController } from './ConnectivityController';\n\n/**\n * Initializes the controller by fetching the initial connectivity status.\n */\nexport type ConnectivityControllerInitAction = {\n type: `ConnectivityController:init`;\n handler: ConnectivityController['init'];\n};\n\n/**\n * Sets the connectivity status.\n *\n * @param status - The connectivity status to set.\n */\nexport type ConnectivityControllerSetConnectivityStatusAction = {\n type: `ConnectivityController:setConnectivityStatus`;\n handler: ConnectivityController['setConnectivityStatus'];\n};\n\n/**\n * Union of all ConnectivityController action types.\n */\nexport type ConnectivityControllerMethodActions =\n | ConnectivityControllerInitAction\n | ConnectivityControllerSetConnectivityStatusAction;\n"]} |
+20
-1
@@ -10,2 +10,20 @@ # Changelog | ||
| ## [0.2.0] | ||
| ### Added | ||
| - Add `init` method to asynchronously fetch and set the initial connectivity status from the adapter ([#7679](https://github.com/MetaMask/core/pull/7679)) | ||
| - The controller now initializes with a default state (online) and requires calling `init()` to fetch the actual status | ||
| - This method can be called through the messenger action `ConnectivityController:init` | ||
| - Add `setConnectivityStatus` method to manually set connectivity status ([#7676](https://github.com/MetaMask/core/pull/7676)) | ||
| - The method is exposed as a messenger action `ConnectivityController:setConnectivityStatus` | ||
| ### Changed | ||
| - **BREAKING:** `ConnectivityAdapter.getStatus()` must now return a `Promise<ConnectivityStatus>` (async) ([#7679](https://github.com/MetaMask/core/pull/7679)) | ||
| - Adapter implementations must update their `getStatus()` method to return a Promise | ||
| - This change enables asynchronous initialization of the controller via the `init()` method | ||
| - Bump `@metamask/base-controller` from `^9.0.0` to `^9.0.1` ([#8317](https://github.com/MetaMask/core/pull/8317)) | ||
| - Bump `@metamask/messenger` from `^0.3.0` to `^1.0.0` ([#8317](https://github.com/MetaMask/core/pull/8317)) | ||
| ## [0.1.0] | ||
@@ -17,3 +35,4 @@ | ||
| [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/connectivity-controller@0.1.0...HEAD | ||
| [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/connectivity-controller@0.2.0...HEAD | ||
| [0.2.0]: https://github.com/MetaMask/core/compare/@metamask/connectivity-controller@0.1.0...@metamask/connectivity-controller@0.2.0 | ||
| [0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/connectivity-controller@0.1.0 |
| "use strict"; | ||
| var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
| if (kind === "m") throw new TypeError("Private method is not writable"); | ||
| if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
| if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
| return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
| }; | ||
| var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
| if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
| if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
| return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
| }; | ||
| var _ConnectivityController_connectivityAdapter; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -37,2 +49,3 @@ exports.ConnectivityController = exports.getDefaultConnectivityControllerState = exports.controllerName = void 0; | ||
| exports.getDefaultConnectivityControllerState = getDefaultConnectivityControllerState; | ||
| const MESSENGER_EXPOSED_METHODS = ['init', 'setConnectivityStatus']; | ||
| /** | ||
@@ -61,3 +74,2 @@ * ConnectivityController stores the device's internet connectivity status. | ||
| constructor({ messenger, connectivityAdapter, }) { | ||
| const initialStatus = connectivityAdapter.getStatus(); | ||
| super({ | ||
@@ -67,11 +79,24 @@ messenger, | ||
| name: exports.controllerName, | ||
| state: { | ||
| ...getDefaultConnectivityControllerState(), | ||
| connectivityStatus: initialStatus, | ||
| }, | ||
| state: getDefaultConnectivityControllerState(), | ||
| }); | ||
| connectivityAdapter.onConnectivityChange((status) => { | ||
| this.update((draftState) => { | ||
| draftState.connectivityStatus = status; | ||
| }); | ||
| _ConnectivityController_connectivityAdapter.set(this, void 0); | ||
| __classPrivateFieldSet(this, _ConnectivityController_connectivityAdapter, connectivityAdapter, "f"); | ||
| __classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").onConnectivityChange(this.setConnectivityStatus.bind(this)); | ||
| this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS); | ||
| } | ||
| /** | ||
| * Initializes the controller by fetching the initial connectivity status. | ||
| */ | ||
| async init() { | ||
| const initialStatus = await __classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").getStatus(); | ||
| this.setConnectivityStatus(initialStatus); | ||
| } | ||
| /** | ||
| * Sets the connectivity status. | ||
| * | ||
| * @param status - The connectivity status to set. | ||
| */ | ||
| setConnectivityStatus(status) { | ||
| this.update((draftState) => { | ||
| draftState.connectivityStatus = status; | ||
| }); | ||
@@ -81,2 +106,3 @@ } | ||
| exports.ConnectivityController = ConnectivityController; | ||
| _ConnectivityController_connectivityAdapter = new WeakMap(); | ||
| //# sourceMappingURL=ConnectivityController.cjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"ConnectivityController.cjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAG3D,uCAAgD;AAGhD;;;;GAIG;AACU,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAavD;;GAEG;AACH,MAAM,8BAA8B,GAAG;IACrC,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACmD,CAAC;AAEvD;;;;;;;GAOG;AACH,SAAgB,qCAAqC;IACnD,OAAO;QACL,kBAAkB,EAAE,6BAAqB,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAJD,sFAIC;AAkED;;;;;;;;;;;;;GAaG;AACH,MAAa,sBAAuB,SAAQ,gCAI3C;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,mBAAmB,GACW;QAC9B,MAAM,aAAa,GAAG,mBAAmB,CAAC,SAAS,EAAE,CAAC;QAEtD,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,8BAA8B;YACxC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE;gBACL,GAAG,qCAAqC,EAAE;gBAC1C,kBAAkB,EAAE,aAAa;aAClC;SACF,CAAC,CAAC;QAEH,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE;YAClD,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;gBACzB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlCD,wDAkCC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { CONNECTIVITY_STATUSES } from './types';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types';\n\n/**\n * The name of the {@link ConnectivityController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ConnectivityController';\n\n/**\n * State for the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerState = {\n /**\n * The current device connectivity status.\n * Named with 'connectivity' prefix to avoid conflicts when state is flattened in Redux.\n */\n connectivityStatus: ConnectivityStatus;\n};\n\n/**\n * The metadata for each property in {@link ConnectivityControllerState}.\n */\nconst connectivityControllerMetadata = {\n connectivityStatus: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<ConnectivityControllerState>;\n\n/**\n * Constructs the default {@link ConnectivityController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ConnectivityController} state.\n */\nexport function getDefaultConnectivityControllerState(): ConnectivityControllerState {\n return {\n connectivityStatus: CONNECTIVITY_STATUSES.Online,\n };\n}\n\n/**\n * Retrieves the state of the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerActions =\n ConnectivityControllerGetStateAction;\n\n/**\n * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when the state of {@link ConnectivityController} changes.\n */\nexport type ConnectivityControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Events that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerEvents =\n ConnectivityControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ConnectivityControllerMessenger} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ConnectivityController}.\n */\nexport type ConnectivityControllerMessenger = Messenger<\n typeof controllerName,\n ConnectivityControllerActions | AllowedActions,\n ConnectivityControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerOptions = {\n /**\n * The messenger for inter-controller communication.\n */\n messenger: ConnectivityControllerMessenger;\n\n /**\n * Connectivity adapter for platform-specific detection.\n */\n connectivityAdapter: ConnectivityAdapter;\n};\n\n/**\n * ConnectivityController stores the device's internet connectivity status.\n *\n * This controller is platform-agnostic and designed to be used across different\n * MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to\n * be injected, which provides platform-specific connectivity detection.\n *\n * The controller subscribes to the adapter's `onConnectivityChange` callback\n * and updates its state accordingly. All connectivity updates flow through\n * the adapter, ensuring a single source of truth.\n *\n * This controller provides a centralized state for connectivity status,\n * enabling the UI and other controllers to adapt when the user goes offline.\n */\nexport class ConnectivityController extends BaseController<\n typeof controllerName,\n ConnectivityControllerState,\n ConnectivityControllerMessenger\n> {\n /**\n * Constructs a new {@link ConnectivityController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.connectivityAdapter - The connectivity adapter to use.\n */\n constructor({\n messenger,\n connectivityAdapter,\n }: ConnectivityControllerOptions) {\n const initialStatus = connectivityAdapter.getStatus();\n\n super({\n messenger,\n metadata: connectivityControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultConnectivityControllerState(),\n connectivityStatus: initialStatus,\n },\n });\n\n connectivityAdapter.onConnectivityChange((status) => {\n this.update((draftState) => {\n draftState.connectivityStatus = status;\n });\n });\n }\n}\n"]} | ||
| {"version":3,"file":"ConnectivityController.cjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAI3D,uCAAgD;AAGhD;;;;GAIG;AACU,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAavD;;GAEG;AACH,MAAM,8BAA8B,GAAG;IACrC,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACmD,CAAC;AAEvD;;;;;;;GAOG;AACH,SAAgB,qCAAqC;IACnD,OAAO;QACL,kBAAkB,EAAE,6BAAqB,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAJD,sFAIC;AAED,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,uBAAuB,CAAU,CAAC;AAmE7E;;;;;;;;;;;;;GAaG;AACH,MAAa,sBAAuB,SAAQ,gCAI3C;IAGC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,mBAAmB,GACW;QAC9B,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,8BAA8B;YACxC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE,qCAAqC,EAAE;SAC/C,CAAC,CAAC;QAlBI,8DAA0C;QAoBjD,uBAAA,IAAI,+CAAwB,mBAAmB,MAAA,CAAC;QAEhD,uBAAA,IAAI,mDAAqB,CAAC,oBAAoB,CAC5C,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,aAAa,GAAG,MAAM,uBAAA,IAAI,mDAAqB,CAAC,SAAS,EAAE,CAAC;QAClE,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,qBAAqB,CAAC,MAA0B;QAC9C,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvDD,wDAuDC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { ConnectivityControllerMethodActions } from './ConnectivityController-method-action-types';\nimport { CONNECTIVITY_STATUSES } from './types';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types';\n\n/**\n * The name of the {@link ConnectivityController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ConnectivityController';\n\n/**\n * State for the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerState = {\n /**\n * The current device connectivity status.\n * Named with 'connectivity' prefix to avoid conflicts when state is flattened in Redux.\n */\n connectivityStatus: ConnectivityStatus;\n};\n\n/**\n * The metadata for each property in {@link ConnectivityControllerState}.\n */\nconst connectivityControllerMetadata = {\n connectivityStatus: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<ConnectivityControllerState>;\n\n/**\n * Constructs the default {@link ConnectivityController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ConnectivityController} state.\n */\nexport function getDefaultConnectivityControllerState(): ConnectivityControllerState {\n return {\n connectivityStatus: CONNECTIVITY_STATUSES.Online,\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = ['init', 'setConnectivityStatus'] as const;\n\n/**\n * Retrieves the state of the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerActions =\n | ConnectivityControllerGetStateAction\n | ConnectivityControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when the state of {@link ConnectivityController} changes.\n */\nexport type ConnectivityControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Events that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerEvents =\n ConnectivityControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ConnectivityControllerMessenger} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ConnectivityController}.\n */\nexport type ConnectivityControllerMessenger = Messenger<\n typeof controllerName,\n ConnectivityControllerActions | AllowedActions,\n ConnectivityControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerOptions = {\n /**\n * The messenger for inter-controller communication.\n */\n messenger: ConnectivityControllerMessenger;\n\n /**\n * Connectivity adapter for platform-specific detection.\n */\n connectivityAdapter: ConnectivityAdapter;\n};\n\n/**\n * ConnectivityController stores the device's internet connectivity status.\n *\n * This controller is platform-agnostic and designed to be used across different\n * MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to\n * be injected, which provides platform-specific connectivity detection.\n *\n * The controller subscribes to the adapter's `onConnectivityChange` callback\n * and updates its state accordingly. All connectivity updates flow through\n * the adapter, ensuring a single source of truth.\n *\n * This controller provides a centralized state for connectivity status,\n * enabling the UI and other controllers to adapt when the user goes offline.\n */\nexport class ConnectivityController extends BaseController<\n typeof controllerName,\n ConnectivityControllerState,\n ConnectivityControllerMessenger\n> {\n readonly #connectivityAdapter: ConnectivityAdapter;\n\n /**\n * Constructs a new {@link ConnectivityController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.connectivityAdapter - The connectivity adapter to use.\n */\n constructor({\n messenger,\n connectivityAdapter,\n }: ConnectivityControllerOptions) {\n super({\n messenger,\n metadata: connectivityControllerMetadata,\n name: controllerName,\n state: getDefaultConnectivityControllerState(),\n });\n\n this.#connectivityAdapter = connectivityAdapter;\n\n this.#connectivityAdapter.onConnectivityChange(\n this.setConnectivityStatus.bind(this),\n );\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Initializes the controller by fetching the initial connectivity status.\n */\n async init(): Promise<void> {\n const initialStatus = await this.#connectivityAdapter.getStatus();\n this.setConnectivityStatus(initialStatus);\n }\n\n /**\n * Sets the connectivity status.\n *\n * @param status - The connectivity status to set.\n */\n setConnectivityStatus(status: ConnectivityStatus): void {\n this.update((draftState) => {\n draftState.connectivityStatus = status;\n });\n }\n}\n"]} |
| import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller"; | ||
| import { BaseController } from "@metamask/base-controller"; | ||
| import type { Messenger } from "@metamask/messenger"; | ||
| import { ConnectivityControllerMethodActions } from "./ConnectivityController-method-action-types.cjs"; | ||
| import type { ConnectivityAdapter, ConnectivityStatus } from "./types.cjs"; | ||
@@ -37,3 +38,3 @@ /** | ||
| */ | ||
| export type ConnectivityControllerActions = ConnectivityControllerGetStateAction; | ||
| export type ConnectivityControllerActions = ConnectivityControllerGetStateAction | ConnectivityControllerMethodActions; | ||
| /** | ||
@@ -89,2 +90,3 @@ * Actions from other messengers that {@link ConnectivityControllerMessenger} calls. | ||
| export declare class ConnectivityController extends BaseController<typeof controllerName, ConnectivityControllerState, ConnectivityControllerMessenger> { | ||
| #private; | ||
| /** | ||
@@ -98,4 +100,14 @@ * Constructs a new {@link ConnectivityController}. | ||
| constructor({ messenger, connectivityAdapter, }: ConnectivityControllerOptions); | ||
| /** | ||
| * Initializes the controller by fetching the initial connectivity status. | ||
| */ | ||
| init(): Promise<void>; | ||
| /** | ||
| * Sets the connectivity status. | ||
| * | ||
| * @param status - The connectivity status to set. | ||
| */ | ||
| setConnectivityStatus(status: ConnectivityStatus): void; | ||
| } | ||
| export {}; | ||
| //# sourceMappingURL=ConnectivityController.d.cts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"ConnectivityController.d.cts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AAEvE;;;;GAIG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,IAAI,2BAA2B,CAInF;AAED;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACvC,oCAAoC,CAAC;AAEvC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;OAEG;IACH,SAAS,EAAE,+BAA+B,CAAC;IAE3C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE,6BAA6B;CAmBjC"} | ||
| {"version":3,"file":"ConnectivityController.d.cts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAAE,mCAAmC,EAAE,yDAAqD;AAEnG,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AAEvE;;;;GAIG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,IAAI,2BAA2B,CAInF;AAID;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,oCAAoC,GACpC,mCAAmC,CAAC;AAExC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;OAEG;IACH,SAAS,EAAE,+BAA+B,CAAC;IAE3C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;;IAGC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE,6BAA6B;IAoBhC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B;;;;OAIG;IACH,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI;CAKxD"} |
| import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller"; | ||
| import { BaseController } from "@metamask/base-controller"; | ||
| import type { Messenger } from "@metamask/messenger"; | ||
| import { ConnectivityControllerMethodActions } from "./ConnectivityController-method-action-types.mjs"; | ||
| import type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs"; | ||
@@ -37,3 +38,3 @@ /** | ||
| */ | ||
| export type ConnectivityControllerActions = ConnectivityControllerGetStateAction; | ||
| export type ConnectivityControllerActions = ConnectivityControllerGetStateAction | ConnectivityControllerMethodActions; | ||
| /** | ||
@@ -89,2 +90,3 @@ * Actions from other messengers that {@link ConnectivityControllerMessenger} calls. | ||
| export declare class ConnectivityController extends BaseController<typeof controllerName, ConnectivityControllerState, ConnectivityControllerMessenger> { | ||
| #private; | ||
| /** | ||
@@ -98,4 +100,14 @@ * Constructs a new {@link ConnectivityController}. | ||
| constructor({ messenger, connectivityAdapter, }: ConnectivityControllerOptions); | ||
| /** | ||
| * Initializes the controller by fetching the initial connectivity status. | ||
| */ | ||
| init(): Promise<void>; | ||
| /** | ||
| * Sets the connectivity status. | ||
| * | ||
| * @param status - The connectivity status to set. | ||
| */ | ||
| setConnectivityStatus(status: ConnectivityStatus): void; | ||
| } | ||
| export {}; | ||
| //# sourceMappingURL=ConnectivityController.d.mts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"ConnectivityController.d.mts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AAEvE;;;;GAIG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,IAAI,2BAA2B,CAInF;AAED;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACvC,oCAAoC,CAAC;AAEvC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;OAEG;IACH,SAAS,EAAE,+BAA+B,CAAC;IAE3C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE,6BAA6B;CAmBjC"} | ||
| {"version":3,"file":"ConnectivityController.d.mts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,EAAE,mCAAmC,EAAE,yDAAqD;AAEnG,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AAEvE;;;;GAIG;AACH,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;;OAGG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC,CAAC;AAcF;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,IAAI,2BAA2B,CAInF;AAID;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GACrC,oCAAoC,GACpC,mCAAmC,CAAC;AAExC;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,SAAS,CACrD,OAAO,cAAc,EACrB,6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,CAC7C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C;;OAEG;IACH,SAAS,EAAE,+BAA+B,CAAC;IAE3C;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;;IAGC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE,6BAA6B;IAoBhC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B;;;;OAIG;IACH,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI;CAKxD"} |
@@ -0,1 +1,13 @@ | ||
| var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
| if (kind === "m") throw new TypeError("Private method is not writable"); | ||
| if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); | ||
| if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
| return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
| }; | ||
| var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { | ||
| if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); | ||
| if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); | ||
| return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); | ||
| }; | ||
| var _ConnectivityController_connectivityAdapter; | ||
| import { BaseController } from "@metamask/base-controller"; | ||
@@ -33,2 +45,3 @@ import { CONNECTIVITY_STATUSES } from "./types.mjs"; | ||
| } | ||
| const MESSENGER_EXPOSED_METHODS = ['init', 'setConnectivityStatus']; | ||
| /** | ||
@@ -57,3 +70,2 @@ * ConnectivityController stores the device's internet connectivity status. | ||
| constructor({ messenger, connectivityAdapter, }) { | ||
| const initialStatus = connectivityAdapter.getStatus(); | ||
| super({ | ||
@@ -63,14 +75,28 @@ messenger, | ||
| name: controllerName, | ||
| state: { | ||
| ...getDefaultConnectivityControllerState(), | ||
| connectivityStatus: initialStatus, | ||
| }, | ||
| state: getDefaultConnectivityControllerState(), | ||
| }); | ||
| connectivityAdapter.onConnectivityChange((status) => { | ||
| this.update((draftState) => { | ||
| draftState.connectivityStatus = status; | ||
| }); | ||
| _ConnectivityController_connectivityAdapter.set(this, void 0); | ||
| __classPrivateFieldSet(this, _ConnectivityController_connectivityAdapter, connectivityAdapter, "f"); | ||
| __classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").onConnectivityChange(this.setConnectivityStatus.bind(this)); | ||
| this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS); | ||
| } | ||
| /** | ||
| * Initializes the controller by fetching the initial connectivity status. | ||
| */ | ||
| async init() { | ||
| const initialStatus = await __classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").getStatus(); | ||
| this.setConnectivityStatus(initialStatus); | ||
| } | ||
| /** | ||
| * Sets the connectivity status. | ||
| * | ||
| * @param status - The connectivity status to set. | ||
| */ | ||
| setConnectivityStatus(status) { | ||
| this.update((draftState) => { | ||
| draftState.connectivityStatus = status; | ||
| }); | ||
| } | ||
| } | ||
| _ConnectivityController_connectivityAdapter = new WeakMap(); | ||
| //# sourceMappingURL=ConnectivityController.mjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"ConnectivityController.mjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAG3D,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAGhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAavD;;GAEG;AACH,MAAM,8BAA8B,GAAG;IACrC,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACmD,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,UAAU,qCAAqC;IACnD,OAAO;QACL,kBAAkB,EAAE,qBAAqB,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAkED;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAI3C;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,mBAAmB,GACW;QAC9B,MAAM,aAAa,GAAG,mBAAmB,CAAC,SAAS,EAAE,CAAC;QAEtD,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,8BAA8B;YACxC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE;gBACL,GAAG,qCAAqC,EAAE;gBAC1C,kBAAkB,EAAE,aAAa;aAClC;SACF,CAAC,CAAC;QAEH,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,MAAM,EAAE,EAAE;YAClD,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;gBACzB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { CONNECTIVITY_STATUSES } from './types';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types';\n\n/**\n * The name of the {@link ConnectivityController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ConnectivityController';\n\n/**\n * State for the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerState = {\n /**\n * The current device connectivity status.\n * Named with 'connectivity' prefix to avoid conflicts when state is flattened in Redux.\n */\n connectivityStatus: ConnectivityStatus;\n};\n\n/**\n * The metadata for each property in {@link ConnectivityControllerState}.\n */\nconst connectivityControllerMetadata = {\n connectivityStatus: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<ConnectivityControllerState>;\n\n/**\n * Constructs the default {@link ConnectivityController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ConnectivityController} state.\n */\nexport function getDefaultConnectivityControllerState(): ConnectivityControllerState {\n return {\n connectivityStatus: CONNECTIVITY_STATUSES.Online,\n };\n}\n\n/**\n * Retrieves the state of the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerActions =\n ConnectivityControllerGetStateAction;\n\n/**\n * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when the state of {@link ConnectivityController} changes.\n */\nexport type ConnectivityControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Events that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerEvents =\n ConnectivityControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ConnectivityControllerMessenger} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ConnectivityController}.\n */\nexport type ConnectivityControllerMessenger = Messenger<\n typeof controllerName,\n ConnectivityControllerActions | AllowedActions,\n ConnectivityControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerOptions = {\n /**\n * The messenger for inter-controller communication.\n */\n messenger: ConnectivityControllerMessenger;\n\n /**\n * Connectivity adapter for platform-specific detection.\n */\n connectivityAdapter: ConnectivityAdapter;\n};\n\n/**\n * ConnectivityController stores the device's internet connectivity status.\n *\n * This controller is platform-agnostic and designed to be used across different\n * MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to\n * be injected, which provides platform-specific connectivity detection.\n *\n * The controller subscribes to the adapter's `onConnectivityChange` callback\n * and updates its state accordingly. All connectivity updates flow through\n * the adapter, ensuring a single source of truth.\n *\n * This controller provides a centralized state for connectivity status,\n * enabling the UI and other controllers to adapt when the user goes offline.\n */\nexport class ConnectivityController extends BaseController<\n typeof controllerName,\n ConnectivityControllerState,\n ConnectivityControllerMessenger\n> {\n /**\n * Constructs a new {@link ConnectivityController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.connectivityAdapter - The connectivity adapter to use.\n */\n constructor({\n messenger,\n connectivityAdapter,\n }: ConnectivityControllerOptions) {\n const initialStatus = connectivityAdapter.getStatus();\n\n super({\n messenger,\n metadata: connectivityControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultConnectivityControllerState(),\n connectivityStatus: initialStatus,\n },\n });\n\n connectivityAdapter.onConnectivityChange((status) => {\n this.update((draftState) => {\n draftState.connectivityStatus = status;\n });\n });\n }\n}\n"]} | ||
| {"version":3,"file":"ConnectivityController.mjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAI3D,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAGhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAavD;;GAEG;AACH,MAAM,8BAA8B,GAAG;IACrC,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;QACxB,QAAQ,EAAE,IAAI;KACf;CACmD,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,UAAU,qCAAqC;IACnD,OAAO;QACL,kBAAkB,EAAE,qBAAqB,CAAC,MAAM;KACjD,CAAC;AACJ,CAAC;AAED,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,uBAAuB,CAAU,CAAC;AAmE7E;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,sBAAuB,SAAQ,cAI3C;IAGC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,mBAAmB,GACW;QAC9B,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,8BAA8B;YACxC,IAAI,EAAE,cAAc;YACpB,KAAK,EAAE,qCAAqC,EAAE;SAC/C,CAAC,CAAC;QAlBI,8DAA0C;QAoBjD,uBAAA,IAAI,+CAAwB,mBAAmB,MAAA,CAAC;QAEhD,uBAAA,IAAI,mDAAqB,CAAC,oBAAoB,CAC5C,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CACtC,CAAC;QAEF,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,aAAa,GAAG,MAAM,uBAAA,IAAI,mDAAqB,CAAC,SAAS,EAAE,CAAC;QAClE,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,qBAAqB,CAAC,MAA0B;QAC9C,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,UAAU,CAAC,kBAAkB,GAAG,MAAM,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport { ConnectivityControllerMethodActions } from './ConnectivityController-method-action-types';\nimport { CONNECTIVITY_STATUSES } from './types';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types';\n\n/**\n * The name of the {@link ConnectivityController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ConnectivityController';\n\n/**\n * State for the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerState = {\n /**\n * The current device connectivity status.\n * Named with 'connectivity' prefix to avoid conflicts when state is flattened in Redux.\n */\n connectivityStatus: ConnectivityStatus;\n};\n\n/**\n * The metadata for each property in {@link ConnectivityControllerState}.\n */\nconst connectivityControllerMetadata = {\n connectivityStatus: {\n persist: false,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: true,\n },\n} satisfies StateMetadata<ConnectivityControllerState>;\n\n/**\n * Constructs the default {@link ConnectivityController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ConnectivityController} state.\n */\nexport function getDefaultConnectivityControllerState(): ConnectivityControllerState {\n return {\n connectivityStatus: CONNECTIVITY_STATUSES.Online,\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = ['init', 'setConnectivityStatus'] as const;\n\n/**\n * Retrieves the state of the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerActions =\n | ConnectivityControllerGetStateAction\n | ConnectivityControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when the state of {@link ConnectivityController} changes.\n */\nexport type ConnectivityControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ConnectivityControllerState\n>;\n\n/**\n * Events that {@link ConnectivityControllerMessenger} exposes to other consumers.\n */\nexport type ConnectivityControllerEvents =\n ConnectivityControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ConnectivityControllerMessenger} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ConnectivityController}.\n */\nexport type ConnectivityControllerMessenger = Messenger<\n typeof controllerName,\n ConnectivityControllerActions | AllowedActions,\n ConnectivityControllerEvents | AllowedEvents\n>;\n\n/**\n * Options for constructing the {@link ConnectivityController}.\n */\nexport type ConnectivityControllerOptions = {\n /**\n * The messenger for inter-controller communication.\n */\n messenger: ConnectivityControllerMessenger;\n\n /**\n * Connectivity adapter for platform-specific detection.\n */\n connectivityAdapter: ConnectivityAdapter;\n};\n\n/**\n * ConnectivityController stores the device's internet connectivity status.\n *\n * This controller is platform-agnostic and designed to be used across different\n * MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to\n * be injected, which provides platform-specific connectivity detection.\n *\n * The controller subscribes to the adapter's `onConnectivityChange` callback\n * and updates its state accordingly. All connectivity updates flow through\n * the adapter, ensuring a single source of truth.\n *\n * This controller provides a centralized state for connectivity status,\n * enabling the UI and other controllers to adapt when the user goes offline.\n */\nexport class ConnectivityController extends BaseController<\n typeof controllerName,\n ConnectivityControllerState,\n ConnectivityControllerMessenger\n> {\n readonly #connectivityAdapter: ConnectivityAdapter;\n\n /**\n * Constructs a new {@link ConnectivityController}.\n *\n * @param args - The arguments to this controller.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.connectivityAdapter - The connectivity adapter to use.\n */\n constructor({\n messenger,\n connectivityAdapter,\n }: ConnectivityControllerOptions) {\n super({\n messenger,\n metadata: connectivityControllerMetadata,\n name: controllerName,\n state: getDefaultConnectivityControllerState(),\n });\n\n this.#connectivityAdapter = connectivityAdapter;\n\n this.#connectivityAdapter.onConnectivityChange(\n this.setConnectivityStatus.bind(this),\n );\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Initializes the controller by fetching the initial connectivity status.\n */\n async init(): Promise<void> {\n const initialStatus = await this.#connectivityAdapter.getStatus();\n this.setConnectivityStatus(initialStatus);\n }\n\n /**\n * Sets the connectivity status.\n *\n * @param status - The connectivity status to set.\n */\n setConnectivityStatus(status: ConnectivityStatus): void {\n this.update((draftState) => {\n draftState.connectivityStatus = status;\n });\n }\n}\n"]} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AASA,qCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAC9B,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types';\nexport { CONNECTIVITY_STATUSES } from './types';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController';\n"]} | ||
| {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAUA,qCAAgD;AAAvC,8GAAA,qBAAqB,OAAA;AAC9B,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController';\nexport type { ConnectivityControllerSetConnectivityStatusAction } from './ConnectivityController-method-action-types';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types';\nexport { CONNECTIVITY_STATUSES } from './types';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController';\n"]} |
+1
-0
| export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.cjs"; | ||
| export type { ConnectivityControllerSetConnectivityStatusAction } from "./ConnectivityController-method-action-types.cjs"; | ||
| export type { ConnectivityAdapter, ConnectivityStatus } from "./types.cjs"; | ||
@@ -3,0 +4,0 @@ export { CONNECTIVITY_STATUSES } from "./types.cjs"; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AACvE,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC"} | ||
| {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,iDAAiD,EAAE,yDAAqD;AACtH,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AACvE,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC"} |
+1
-0
| export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.mjs"; | ||
| export type { ConnectivityControllerSetConnectivityStatusAction } from "./ConnectivityController-method-action-types.mjs"; | ||
| export type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs"; | ||
@@ -3,0 +4,0 @@ export { CONNECTIVITY_STATUSES } from "./types.mjs"; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AACvE,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC"} | ||
| {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,qCAAiC;AAClC,YAAY,EAAE,iDAAiD,EAAE,yDAAqD;AACtH,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAgB;AACvE,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACtC,qCAAiC","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types';\nexport { CONNECTIVITY_STATUSES } from './types';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController';\n"]} | ||
| {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAChD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACtC,qCAAiC","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController';\nexport type { ConnectivityControllerSetConnectivityStatusAction } from './ConnectivityController-method-action-types';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types';\nexport { CONNECTIVITY_STATUSES } from './types';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController';\n"]} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,qBAAqB,GAAG;IACnC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC","sourcesContent":["/**\n * Connectivity status constants.\n * Used to represent whether the device has internet connectivity.\n */\nexport const CONNECTIVITY_STATUSES = {\n Online: 'online',\n Offline: 'offline',\n} as const;\n\nexport type ConnectivityStatus =\n (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];\n\n/**\n * Adapter interface for platform-specific connectivity detection.\n * Each platform (extension, mobile) implements this interface using\n * platform-specific APIs to detect internet connectivity.\n */\nexport type ConnectivityAdapter = {\n /**\n * Returns the current connectivity status.\n *\n * @returns 'online' if the device is online, 'offline' otherwise.\n */\n getStatus(): ConnectivityStatus;\n\n /**\n * Registers a callback to be called when connectivity status changes.\n *\n * @param callback - Function called with 'online' when online, 'offline' when offline.\n */\n onConnectivityChange(callback: (status: ConnectivityStatus) => void): void;\n\n /**\n * Cleans up any resources (event listeners, subscriptions).\n */\n destroy(): void;\n};\n"]} | ||
| {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,qBAAqB,GAAG;IACnC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC","sourcesContent":["/**\n * Connectivity status constants.\n * Used to represent whether the device has internet connectivity.\n */\nexport const CONNECTIVITY_STATUSES = {\n Online: 'online',\n Offline: 'offline',\n} as const;\n\nexport type ConnectivityStatus =\n (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];\n\n/**\n * Adapter interface for platform-specific connectivity detection.\n * Each platform (extension, mobile) implements this interface using\n * platform-specific APIs to detect internet connectivity.\n */\nexport type ConnectivityAdapter = {\n /**\n * Returns a promise that resolves to the current connectivity status.\n *\n * @returns A promise that resolves to 'online' if the device is online, 'offline' otherwise.\n */\n getStatus(): Promise<ConnectivityStatus>;\n\n /**\n * Registers a callback to be called when connectivity status changes.\n *\n * @param callback - Function called with 'online' when online, 'offline' when offline.\n */\n onConnectivityChange(callback: (status: ConnectivityStatus) => void): void;\n\n /**\n * Cleans up any resources (event listeners, subscriptions).\n */\n destroy(): void;\n};\n"]} |
+3
-3
@@ -17,7 +17,7 @@ /** | ||
| /** | ||
| * Returns the current connectivity status. | ||
| * Returns a promise that resolves to the current connectivity status. | ||
| * | ||
| * @returns 'online' if the device is online, 'offline' otherwise. | ||
| * @returns A promise that resolves to 'online' if the device is online, 'offline' otherwise. | ||
| */ | ||
| getStatus(): ConnectivityStatus; | ||
| getStatus(): Promise<ConnectivityStatus>; | ||
| /** | ||
@@ -24,0 +24,0 @@ * Registers a callback to be called when connectivity status changes. |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;CAGxB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,SAAS,IAAI,kBAAkB,CAAC;IAEhC;;;;OAIG;IACH,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI,CAAC;IAE3E;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"} | ||
| {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;CAGxB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEzC;;;;OAIG;IACH,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI,CAAC;IAE3E;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"} |
+3
-3
@@ -17,7 +17,7 @@ /** | ||
| /** | ||
| * Returns the current connectivity status. | ||
| * Returns a promise that resolves to the current connectivity status. | ||
| * | ||
| * @returns 'online' if the device is online, 'offline' otherwise. | ||
| * @returns A promise that resolves to 'online' if the device is online, 'offline' otherwise. | ||
| */ | ||
| getStatus(): ConnectivityStatus; | ||
| getStatus(): Promise<ConnectivityStatus>; | ||
| /** | ||
@@ -24,0 +24,0 @@ * Registers a callback to be called when connectivity status changes. |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;CAGxB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,SAAS,IAAI,kBAAkB,CAAC;IAEhC;;;;OAIG;IACH,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI,CAAC;IAE3E;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"} | ||
| {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;CAGxB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEzC;;;;OAIG;IACH,oBAAoB,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,IAAI,CAAC;IAE3E;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC","sourcesContent":["/**\n * Connectivity status constants.\n * Used to represent whether the device has internet connectivity.\n */\nexport const CONNECTIVITY_STATUSES = {\n Online: 'online',\n Offline: 'offline',\n} as const;\n\nexport type ConnectivityStatus =\n (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];\n\n/**\n * Adapter interface for platform-specific connectivity detection.\n * Each platform (extension, mobile) implements this interface using\n * platform-specific APIs to detect internet connectivity.\n */\nexport type ConnectivityAdapter = {\n /**\n * Returns the current connectivity status.\n *\n * @returns 'online' if the device is online, 'offline' otherwise.\n */\n getStatus(): ConnectivityStatus;\n\n /**\n * Registers a callback to be called when connectivity status changes.\n *\n * @param callback - Function called with 'online' when online, 'offline' when offline.\n */\n onConnectivityChange(callback: (status: ConnectivityStatus) => void): void;\n\n /**\n * Cleans up any resources (event listeners, subscriptions).\n */\n destroy(): void;\n};\n"]} | ||
| {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC","sourcesContent":["/**\n * Connectivity status constants.\n * Used to represent whether the device has internet connectivity.\n */\nexport const CONNECTIVITY_STATUSES = {\n Online: 'online',\n Offline: 'offline',\n} as const;\n\nexport type ConnectivityStatus =\n (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];\n\n/**\n * Adapter interface for platform-specific connectivity detection.\n * Each platform (extension, mobile) implements this interface using\n * platform-specific APIs to detect internet connectivity.\n */\nexport type ConnectivityAdapter = {\n /**\n * Returns a promise that resolves to the current connectivity status.\n *\n * @returns A promise that resolves to 'online' if the device is online, 'offline' otherwise.\n */\n getStatus(): Promise<ConnectivityStatus>;\n\n /**\n * Registers a callback to be called when connectivity status changes.\n *\n * @param callback - Function called with 'online' when online, 'offline' when offline.\n */\n onConnectivityChange(callback: (status: ConnectivityStatus) => void): void;\n\n /**\n * Cleans up any resources (event listeners, subscriptions).\n */\n destroy(): void;\n};\n"]} |
+9
-8
| { | ||
| "name": "@metamask/connectivity-controller", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "ConnectivityController stores the device's internet connectivity status", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
| "changelog:validate": "../../scripts/validate-changelog.sh @metamask/connectivity-controller", | ||
| "publish:preview": "yarn npm publish --tag preview", | ||
| "generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts", | ||
| "since-latest-release": "../../scripts/since-latest-release.sh", | ||
@@ -52,4 +52,4 @@ "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter", | ||
| "dependencies": { | ||
| "@metamask/base-controller": "^9.0.0", | ||
| "@metamask/messenger": "^0.3.0" | ||
| "@metamask/base-controller": "^9.0.1", | ||
| "@metamask/messenger": "^1.0.0" | ||
| }, | ||
@@ -59,7 +59,8 @@ "devDependencies": { | ||
| "@ts-bridge/cli": "^0.6.4", | ||
| "@types/jest": "^27.4.1", | ||
| "@types/jest": "^29.5.14", | ||
| "deepmerge": "^4.2.2", | ||
| "jest": "^27.5.1", | ||
| "ts-jest": "^27.1.4", | ||
| "typedoc": "^0.24.8", | ||
| "jest": "^29.7.0", | ||
| "ts-jest": "^29.2.5", | ||
| "tsx": "^4.20.5", | ||
| "typedoc": "^0.25.13", | ||
| "typedoc-plugin-missing-exports": "^2.0.0", | ||
@@ -66,0 +67,0 @@ "typescript": "~5.3.3" |
59116
33.52%36
28.57%241
35.39%10
11.11%- Removed
Updated