@metamask-previews/connectivity-controller 0.3.0-preview-b13d916 → 0.3.0-preview-4f4c98e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/{ConnectivityController-method-action-types.d.mts → ConnectivityController-method-action-types.d.ts} +2 -2
- package/dist/ConnectivityController-method-action-types.d.ts.map +1 -0
- package/dist/{ConnectivityController-method-action-types.mjs → ConnectivityController-method-action-types.js} +1 -1
- package/dist/ConnectivityController-method-action-types.js.map +1 -0
- package/dist/{ConnectivityController.d.cts → ConnectivityController.d.ts} +6 -6
- package/dist/ConnectivityController.d.ts.map +1 -0
- package/dist/{ConnectivityController.mjs → ConnectivityController.js} +3 -3
- package/dist/ConnectivityController.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/{selectors.d.mts → selectors.d.ts} +13 -5
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +3 -3
- package/dist/selectors.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +3 -3
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/package.json +12 -16
- package/dist/ConnectivityController-method-action-types.cjs +0 -7
- package/dist/ConnectivityController-method-action-types.cjs.map +0 -1
- package/dist/ConnectivityController-method-action-types.d.cts +0 -26
- package/dist/ConnectivityController-method-action-types.d.cts.map +0 -1
- package/dist/ConnectivityController-method-action-types.d.mts.map +0 -1
- package/dist/ConnectivityController-method-action-types.mjs.map +0 -1
- package/dist/ConnectivityController.cjs +0 -104
- package/dist/ConnectivityController.cjs.map +0 -1
- package/dist/ConnectivityController.d.cts.map +0 -1
- package/dist/ConnectivityController.d.mts +0 -110
- package/dist/ConnectivityController.d.mts.map +0 -1
- package/dist/ConnectivityController.mjs.map +0 -1
- package/dist/index.cjs +0 -11
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -7
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -7
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -28
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -31
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/types.cjs +0 -12
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -33
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
13
|
+
|
|
10
14
|
## [0.3.0]
|
|
11
15
|
|
|
12
16
|
### Added
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { ConnectivityController } from
|
|
5
|
+
import type { ConnectivityController } from './ConnectivityController.js';
|
|
6
6
|
/**
|
|
7
7
|
* Initializes the controller by fetching the initial connectivity status.
|
|
8
8
|
*/
|
|
@@ -23,4 +23,4 @@ export type ConnectivityControllerSetConnectivityStatusAction = {
|
|
|
23
23
|
* Union of all ConnectivityController action types.
|
|
24
24
|
*/
|
|
25
25
|
export type ConnectivityControllerMethodActions = ConnectivityControllerInitAction | ConnectivityControllerSetConnectivityStatusAction;
|
|
26
|
-
//# sourceMappingURL=ConnectivityController-method-action-types.d.
|
|
26
|
+
//# sourceMappingURL=ConnectivityController-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectivityController-method-action-types.d.ts","sourceRoot":"","sources":["../src/ConnectivityController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E;;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectivityController-method-action-types.js","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.js';\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"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import { BaseController } from
|
|
3
|
-
import type { Messenger } from
|
|
4
|
-
import { ConnectivityControllerMethodActions } from
|
|
5
|
-
import type { ConnectivityAdapter, ConnectivityStatus } from
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
2
|
+
import { BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { Messenger } from '@metamask/messenger';
|
|
4
|
+
import { ConnectivityControllerMethodActions } from './ConnectivityController-method-action-types.js';
|
|
5
|
+
import type { ConnectivityAdapter, ConnectivityStatus } from './types.js';
|
|
6
6
|
/**
|
|
7
7
|
* The name of the {@link ConnectivityController}, used to namespace the
|
|
8
8
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -107,4 +107,4 @@ export declare class ConnectivityController extends BaseController<typeof contro
|
|
|
107
107
|
setConnectivityStatus(status: ConnectivityStatus): void;
|
|
108
108
|
}
|
|
109
109
|
export {};
|
|
110
|
-
//# sourceMappingURL=ConnectivityController.d.
|
|
110
|
+
//# sourceMappingURL=ConnectivityController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectivityController.d.ts","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AAEtG,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE1E;;;;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;IACH,YAAY,EACV,SAAS,EACT,mBAAmB,GACpB,EAAE,6BAA6B,EAkB/B;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAG1B;IAED;;;;OAIG;IACH,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAItD;CACF"}
|
|
@@ -10,8 +10,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _ConnectivityController_connectivityAdapter;
|
|
13
|
-
import { BaseController } from
|
|
14
|
-
import { CONNECTIVITY_STATUSES } from
|
|
13
|
+
import { BaseController } from '@metamask/base-controller';
|
|
14
|
+
import { CONNECTIVITY_STATUSES } from './types.js';
|
|
15
15
|
/**
|
|
16
16
|
* The name of the {@link ConnectivityController}, used to namespace the
|
|
17
17
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -96,4 +96,4 @@ export class ConnectivityController extends BaseController {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
_ConnectivityController_connectivityAdapter = new WeakMap();
|
|
99
|
-
//# sourceMappingURL=ConnectivityController.
|
|
99
|
+
//# sourceMappingURL=ConnectivityController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConnectivityController.js","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAI3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD;;;;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.js';\nimport { CONNECTIVITY_STATUSES } from './types.js';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types.js';\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"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from './ConnectivityController.js';
|
|
2
|
+
export type { ConnectivityControllerSetConnectivityStatusAction } from './ConnectivityController-method-action-types.js';
|
|
3
|
+
export type { ConnectivityAdapter, ConnectivityStatus } from './types.js';
|
|
4
|
+
export { CONNECTIVITY_STATUSES } from './types.js';
|
|
5
|
+
export { ConnectivityController, getDefaultConnectivityControllerState, } from './ConnectivityController.js';
|
|
6
|
+
export { connectivityControllerSelectors } from './selectors.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,2BAA2B,EAC3B,oCAAoC,EACpC,6BAA6B,EAC7B,sCAAsC,EACtC,4BAA4B,EAC5B,+BAA+B,GAChC,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,iDAAiD,EAAE,MAAM,iDAAiD,CAAC;AACzH,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,+BAA+B,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController.js';\nexport type { ConnectivityControllerSetConnectivityStatusAction } from './ConnectivityController-method-action-types.js';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types.js';\nexport { CONNECTIVITY_STATUSES } from './types.js';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController.js';\nexport { connectivityControllerSelectors } from './selectors.js';\n"]}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import type { ConnectivityControllerState } from
|
|
2
|
-
import type { ConnectivityStatus } from
|
|
1
|
+
import type { ConnectivityControllerState } from './ConnectivityController.js';
|
|
2
|
+
import type { ConnectivityStatus } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Selects the connectivity status from the controller state.
|
|
5
|
+
*
|
|
6
|
+
* @param state - The controller state
|
|
7
|
+
* @returns The connectivity status
|
|
8
|
+
*/
|
|
9
|
+
declare const selectConnectivityStatus: (state: ConnectivityControllerState) => ConnectivityStatus;
|
|
3
10
|
/**
|
|
4
11
|
* Selectors for the ConnectivityController state.
|
|
5
12
|
* These can be used with Redux or directly with controller state.
|
|
6
13
|
*/
|
|
7
14
|
export declare const connectivityControllerSelectors: {
|
|
8
|
-
selectConnectivityStatus:
|
|
15
|
+
selectConnectivityStatus: typeof selectConnectivityStatus;
|
|
9
16
|
selectIsOffline: ((state: ConnectivityControllerState) => boolean) & {
|
|
10
17
|
clearCache: () => void;
|
|
11
18
|
resultsCount: () => number;
|
|
@@ -18,7 +25,7 @@ export declare const connectivityControllerSelectors: {
|
|
|
18
25
|
resetResultsCount: () => void;
|
|
19
26
|
};
|
|
20
27
|
lastResult: () => boolean;
|
|
21
|
-
dependencies: [
|
|
28
|
+
dependencies: [typeof selectConnectivityStatus];
|
|
22
29
|
recomputations: () => number;
|
|
23
30
|
resetRecomputations: () => void;
|
|
24
31
|
dependencyRecomputations: () => number;
|
|
@@ -28,4 +35,5 @@ export declare const connectivityControllerSelectors: {
|
|
|
28
35
|
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
29
36
|
};
|
|
30
37
|
};
|
|
31
|
-
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;;;;GAKG;AACH,QAAA,MAAM,wBAAwB,UACrB,2BAA2B,KACjC,kBAA8C,CAAC;AAalD;;;GAGG;AACH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;CAG3C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createSelector } from
|
|
2
|
-
import { CONNECTIVITY_STATUSES } from
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import { CONNECTIVITY_STATUSES } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Selects the connectivity status from the controller state.
|
|
5
5
|
*
|
|
@@ -22,4 +22,4 @@ export const connectivityControllerSelectors = {
|
|
|
22
22
|
selectConnectivityStatus,
|
|
23
23
|
selectIsOffline,
|
|
24
24
|
};
|
|
25
|
-
//# sourceMappingURL=selectors.
|
|
25
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.js","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAC/B,KAAkC,EACd,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,eAAe,GAAG,cAAc,CACpC,CAAC,wBAAwB,CAAC,EAC1B,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,KAAK,qBAAqB,CAAC,OAAO,CAC7E,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,wBAAwB;IACxB,eAAe;CAChB,CAAC","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type { ConnectivityControllerState } from './ConnectivityController.js';\nimport { CONNECTIVITY_STATUSES } from './types.js';\nimport type { ConnectivityStatus } from './types.js';\n\n/**\n * Selects the connectivity status from the controller state.\n *\n * @param state - The controller state\n * @returns The connectivity status\n */\nconst selectConnectivityStatus = (\n state: ConnectivityControllerState,\n): ConnectivityStatus => state.connectivityStatus;\n\n/**\n * Selects whether the device is offline.\n *\n * @param state - The controller state\n * @returns Whether the device is offline\n */\nconst selectIsOffline = createSelector(\n [selectConnectivityStatus],\n (connectivityStatus) => connectivityStatus === CONNECTIVITY_STATUSES.Offline,\n);\n\n/**\n * Selectors for the ConnectivityController state.\n * These can be used with Redux or directly with controller state.\n */\nexport const connectivityControllerSelectors = {\n selectConnectivityStatus,\n selectIsOffline,\n};\n"]}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Used to represent whether the device has internet connectivity.
|
|
4
4
|
*/
|
|
5
5
|
export declare const CONNECTIVITY_STATUSES: {
|
|
6
|
-
readonly Online:
|
|
7
|
-
readonly Offline:
|
|
6
|
+
readonly Online: 'online';
|
|
7
|
+
readonly Offline: 'offline';
|
|
8
8
|
};
|
|
9
9
|
export type ConnectivityStatus = (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];
|
|
10
10
|
/**
|
|
@@ -30,4 +30,4 @@ export type ConnectivityAdapter = {
|
|
|
30
30
|
*/
|
|
31
31
|
destroy(): void;
|
|
32
32
|
};
|
|
33
|
-
//# sourceMappingURL=types.d.
|
|
33
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;aAChC,MAAM,EAAE,QAAQ;aAChB,OAAO,EAAE,SAAS;CACV,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/connectivity-controller",
|
|
3
|
-
"version": "0.3.0-preview-
|
|
3
|
+
"version": "0.3.0-preview-4f4c98e",
|
|
4
4
|
"description": "ConnectivityController stores the device's internet connectivity status",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,19 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"types": "./dist/index.d.cts",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
34
27
|
},
|
|
35
28
|
"./package.json": "./package.json"
|
|
36
29
|
},
|
|
@@ -39,9 +32,11 @@
|
|
|
39
32
|
"registry": "https://registry.npmjs.org/"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:all": "
|
|
35
|
+
"build": "tsc --project tsconfig.build.json",
|
|
36
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
44
38
|
"build:docs": "typedoc",
|
|
39
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/connectivity-controller",
|
|
46
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/connectivity-controller",
|
|
47
42
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -61,17 +56,18 @@
|
|
|
61
56
|
},
|
|
62
57
|
"devDependencies": {
|
|
63
58
|
"@metamask/auto-changelog": "^6.1.0",
|
|
64
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
65
59
|
"@types/jest": "^30.0.0",
|
|
60
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
66
61
|
"deepmerge": "^4.2.2",
|
|
67
62
|
"jest": "^30.4.2",
|
|
63
|
+
"rimraf": "^5.0.5",
|
|
68
64
|
"ts-jest": "^29.4.11",
|
|
69
65
|
"tsx": "^4.20.5",
|
|
70
66
|
"typedoc": "^0.25.13",
|
|
71
67
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
72
|
-
"typescript": "
|
|
68
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
73
69
|
},
|
|
74
70
|
"engines": {
|
|
75
|
-
"node": "^
|
|
71
|
+
"node": "^22.14.0 || ^24"
|
|
76
72
|
}
|
|
77
73
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"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.js';\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"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is auto generated.
|
|
3
|
-
* Do not edit manually.
|
|
4
|
-
*/
|
|
5
|
-
import type { ConnectivityController } from "./ConnectivityController.cjs";
|
|
6
|
-
/**
|
|
7
|
-
* Initializes the controller by fetching the initial connectivity status.
|
|
8
|
-
*/
|
|
9
|
-
export type ConnectivityControllerInitAction = {
|
|
10
|
-
type: `ConnectivityController:init`;
|
|
11
|
-
handler: ConnectivityController['init'];
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Sets the connectivity status.
|
|
15
|
-
*
|
|
16
|
-
* @param status - The connectivity status to set.
|
|
17
|
-
*/
|
|
18
|
-
export type ConnectivityControllerSetConnectivityStatusAction = {
|
|
19
|
-
type: `ConnectivityController:setConnectivityStatus`;
|
|
20
|
-
handler: ConnectivityController['setConnectivityStatus'];
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Union of all ConnectivityController action types.
|
|
24
|
-
*/
|
|
25
|
-
export type ConnectivityControllerMethodActions = ConnectivityControllerInitAction | ConnectivityControllerSetConnectivityStatusAction;
|
|
26
|
-
//# sourceMappingURL=ConnectivityController-method-action-types.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"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,qCAAoC;AAE1E;;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"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,qCAAoC;AAE1E;;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"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.js';\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"]}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
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");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
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");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _ConnectivityController_connectivityAdapter;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ConnectivityController = exports.getDefaultConnectivityControllerState = exports.controllerName = void 0;
|
|
16
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
-
const types_js_1 = require("./types.cjs");
|
|
18
|
-
/**
|
|
19
|
-
* The name of the {@link ConnectivityController}, used to namespace the
|
|
20
|
-
* controller's actions and events and to namespace the controller's state data
|
|
21
|
-
* when composed with other controllers.
|
|
22
|
-
*/
|
|
23
|
-
exports.controllerName = 'ConnectivityController';
|
|
24
|
-
/**
|
|
25
|
-
* The metadata for each property in {@link ConnectivityControllerState}.
|
|
26
|
-
*/
|
|
27
|
-
const connectivityControllerMetadata = {
|
|
28
|
-
connectivityStatus: {
|
|
29
|
-
persist: false,
|
|
30
|
-
includeInDebugSnapshot: true,
|
|
31
|
-
includeInStateLogs: true,
|
|
32
|
-
usedInUi: true,
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Constructs the default {@link ConnectivityController} state. This allows
|
|
37
|
-
* consumers to provide a partial state object when initializing the controller
|
|
38
|
-
* and also helps in constructing complete state objects for this controller in
|
|
39
|
-
* tests.
|
|
40
|
-
*
|
|
41
|
-
* @returns The default {@link ConnectivityController} state.
|
|
42
|
-
*/
|
|
43
|
-
function getDefaultConnectivityControllerState() {
|
|
44
|
-
return {
|
|
45
|
-
connectivityStatus: types_js_1.CONNECTIVITY_STATUSES.Online,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
exports.getDefaultConnectivityControllerState = getDefaultConnectivityControllerState;
|
|
49
|
-
const MESSENGER_EXPOSED_METHODS = ['init', 'setConnectivityStatus'];
|
|
50
|
-
/**
|
|
51
|
-
* ConnectivityController stores the device's internet connectivity status.
|
|
52
|
-
*
|
|
53
|
-
* This controller is platform-agnostic and designed to be used across different
|
|
54
|
-
* MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to
|
|
55
|
-
* be injected, which provides platform-specific connectivity detection.
|
|
56
|
-
*
|
|
57
|
-
* The controller subscribes to the adapter's `onConnectivityChange` callback
|
|
58
|
-
* and updates its state accordingly. All connectivity updates flow through
|
|
59
|
-
* the adapter, ensuring a single source of truth.
|
|
60
|
-
*
|
|
61
|
-
* This controller provides a centralized state for connectivity status,
|
|
62
|
-
* enabling the UI and other controllers to adapt when the user goes offline.
|
|
63
|
-
*/
|
|
64
|
-
class ConnectivityController extends base_controller_1.BaseController {
|
|
65
|
-
/**
|
|
66
|
-
* Constructs a new {@link ConnectivityController}.
|
|
67
|
-
*
|
|
68
|
-
* @param args - The arguments to this controller.
|
|
69
|
-
* @param args.messenger - The messenger suited for this controller.
|
|
70
|
-
* @param args.connectivityAdapter - The connectivity adapter to use.
|
|
71
|
-
*/
|
|
72
|
-
constructor({ messenger, connectivityAdapter, }) {
|
|
73
|
-
super({
|
|
74
|
-
messenger,
|
|
75
|
-
metadata: connectivityControllerMetadata,
|
|
76
|
-
name: exports.controllerName,
|
|
77
|
-
state: getDefaultConnectivityControllerState(),
|
|
78
|
-
});
|
|
79
|
-
_ConnectivityController_connectivityAdapter.set(this, void 0);
|
|
80
|
-
__classPrivateFieldSet(this, _ConnectivityController_connectivityAdapter, connectivityAdapter, "f");
|
|
81
|
-
__classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").onConnectivityChange(this.setConnectivityStatus.bind(this));
|
|
82
|
-
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Initializes the controller by fetching the initial connectivity status.
|
|
86
|
-
*/
|
|
87
|
-
async init() {
|
|
88
|
-
const initialStatus = await __classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").getStatus();
|
|
89
|
-
this.setConnectivityStatus(initialStatus);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Sets the connectivity status.
|
|
93
|
-
*
|
|
94
|
-
* @param status - The connectivity status to set.
|
|
95
|
-
*/
|
|
96
|
-
setConnectivityStatus(status) {
|
|
97
|
-
this.update((draftState) => {
|
|
98
|
-
draftState.connectivityStatus = status;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.ConnectivityController = ConnectivityController;
|
|
103
|
-
_ConnectivityController_connectivityAdapter = new WeakMap();
|
|
104
|
-
//# sourceMappingURL=ConnectivityController.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityController.cjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAI3D,0CAAmD;AAGnD;;;;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,gCAAqB,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.js';\nimport { CONNECTIVITY_STATUSES } from './types.js';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types.js';\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 +0,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;AAErD,OAAO,EAAE,mCAAmC,EAAE,yDAAwD;AAEtG,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAmB;AAE1E;;;;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"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
2
|
-
import { BaseController } from "@metamask/base-controller";
|
|
3
|
-
import type { Messenger } from "@metamask/messenger";
|
|
4
|
-
import { ConnectivityControllerMethodActions } from "./ConnectivityController-method-action-types.mjs";
|
|
5
|
-
import type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs";
|
|
6
|
-
/**
|
|
7
|
-
* The name of the {@link ConnectivityController}, used to namespace the
|
|
8
|
-
* controller's actions and events and to namespace the controller's state data
|
|
9
|
-
* when composed with other controllers.
|
|
10
|
-
*/
|
|
11
|
-
export declare const controllerName = "ConnectivityController";
|
|
12
|
-
/**
|
|
13
|
-
* State for the {@link ConnectivityController}.
|
|
14
|
-
*/
|
|
15
|
-
export type ConnectivityControllerState = {
|
|
16
|
-
/**
|
|
17
|
-
* The current device connectivity status.
|
|
18
|
-
* Named with 'connectivity' prefix to avoid conflicts when state is flattened in Redux.
|
|
19
|
-
*/
|
|
20
|
-
connectivityStatus: ConnectivityStatus;
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* Constructs the default {@link ConnectivityController} state. This allows
|
|
24
|
-
* consumers to provide a partial state object when initializing the controller
|
|
25
|
-
* and also helps in constructing complete state objects for this controller in
|
|
26
|
-
* tests.
|
|
27
|
-
*
|
|
28
|
-
* @returns The default {@link ConnectivityController} state.
|
|
29
|
-
*/
|
|
30
|
-
export declare function getDefaultConnectivityControllerState(): ConnectivityControllerState;
|
|
31
|
-
/**
|
|
32
|
-
* Retrieves the state of the {@link ConnectivityController}.
|
|
33
|
-
*/
|
|
34
|
-
export type ConnectivityControllerGetStateAction = ControllerGetStateAction<typeof controllerName, ConnectivityControllerState>;
|
|
35
|
-
/**
|
|
36
|
-
* Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.
|
|
37
|
-
*/
|
|
38
|
-
export type ConnectivityControllerActions = ConnectivityControllerGetStateAction | ConnectivityControllerMethodActions;
|
|
39
|
-
/**
|
|
40
|
-
* Actions from other messengers that {@link ConnectivityControllerMessenger} calls.
|
|
41
|
-
*/
|
|
42
|
-
type AllowedActions = never;
|
|
43
|
-
/**
|
|
44
|
-
* Published when the state of {@link ConnectivityController} changes.
|
|
45
|
-
*/
|
|
46
|
-
export type ConnectivityControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, ConnectivityControllerState>;
|
|
47
|
-
/**
|
|
48
|
-
* Events that {@link ConnectivityControllerMessenger} exposes to other consumers.
|
|
49
|
-
*/
|
|
50
|
-
export type ConnectivityControllerEvents = ConnectivityControllerStateChangeEvent;
|
|
51
|
-
/**
|
|
52
|
-
* Events from other messengers that {@link ConnectivityControllerMessenger} subscribes
|
|
53
|
-
* to.
|
|
54
|
-
*/
|
|
55
|
-
type AllowedEvents = never;
|
|
56
|
-
/**
|
|
57
|
-
* The messenger restricted to actions and events accessed by
|
|
58
|
-
* {@link ConnectivityController}.
|
|
59
|
-
*/
|
|
60
|
-
export type ConnectivityControllerMessenger = Messenger<typeof controllerName, ConnectivityControllerActions | AllowedActions, ConnectivityControllerEvents | AllowedEvents>;
|
|
61
|
-
/**
|
|
62
|
-
* Options for constructing the {@link ConnectivityController}.
|
|
63
|
-
*/
|
|
64
|
-
export type ConnectivityControllerOptions = {
|
|
65
|
-
/**
|
|
66
|
-
* The messenger for inter-controller communication.
|
|
67
|
-
*/
|
|
68
|
-
messenger: ConnectivityControllerMessenger;
|
|
69
|
-
/**
|
|
70
|
-
* Connectivity adapter for platform-specific detection.
|
|
71
|
-
*/
|
|
72
|
-
connectivityAdapter: ConnectivityAdapter;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* ConnectivityController stores the device's internet connectivity status.
|
|
76
|
-
*
|
|
77
|
-
* This controller is platform-agnostic and designed to be used across different
|
|
78
|
-
* MetaMask clients (extension, mobile). It requires a `ConnectivityAdapter` to
|
|
79
|
-
* be injected, which provides platform-specific connectivity detection.
|
|
80
|
-
*
|
|
81
|
-
* The controller subscribes to the adapter's `onConnectivityChange` callback
|
|
82
|
-
* and updates its state accordingly. All connectivity updates flow through
|
|
83
|
-
* the adapter, ensuring a single source of truth.
|
|
84
|
-
*
|
|
85
|
-
* This controller provides a centralized state for connectivity status,
|
|
86
|
-
* enabling the UI and other controllers to adapt when the user goes offline.
|
|
87
|
-
*/
|
|
88
|
-
export declare class ConnectivityController extends BaseController<typeof controllerName, ConnectivityControllerState, ConnectivityControllerMessenger> {
|
|
89
|
-
#private;
|
|
90
|
-
/**
|
|
91
|
-
* Constructs a new {@link ConnectivityController}.
|
|
92
|
-
*
|
|
93
|
-
* @param args - The arguments to this controller.
|
|
94
|
-
* @param args.messenger - The messenger suited for this controller.
|
|
95
|
-
* @param args.connectivityAdapter - The connectivity adapter to use.
|
|
96
|
-
*/
|
|
97
|
-
constructor({ messenger, connectivityAdapter, }: ConnectivityControllerOptions);
|
|
98
|
-
/**
|
|
99
|
-
* Initializes the controller by fetching the initial connectivity status.
|
|
100
|
-
*/
|
|
101
|
-
init(): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* Sets the connectivity status.
|
|
104
|
-
*
|
|
105
|
-
* @param status - The connectivity status to set.
|
|
106
|
-
*/
|
|
107
|
-
setConnectivityStatus(status: ConnectivityStatus): void;
|
|
108
|
-
}
|
|
109
|
-
export {};
|
|
110
|
-
//# sourceMappingURL=ConnectivityController.d.mts.map
|
|
@@ -1 +0,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;AAErD,OAAO,EAAE,mCAAmC,EAAE,yDAAwD;AAEtG,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAmB;AAE1E;;;;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityController.mjs","sourceRoot":"","sources":["../src/ConnectivityController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAI3D,OAAO,EAAE,qBAAqB,EAAE,oBAAmB;AAGnD;;;;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.js';\nimport { CONNECTIVITY_STATUSES } from './types.js';\nimport type { ConnectivityAdapter, ConnectivityStatus } from './types.js';\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"]}
|
package/dist/index.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.connectivityControllerSelectors = exports.getDefaultConnectivityControllerState = exports.ConnectivityController = exports.CONNECTIVITY_STATUSES = void 0;
|
|
4
|
-
var types_js_1 = require("./types.cjs");
|
|
5
|
-
Object.defineProperty(exports, "CONNECTIVITY_STATUSES", { enumerable: true, get: function () { return types_js_1.CONNECTIVITY_STATUSES; } });
|
|
6
|
-
var ConnectivityController_js_1 = require("./ConnectivityController.cjs");
|
|
7
|
-
Object.defineProperty(exports, "ConnectivityController", { enumerable: true, get: function () { return ConnectivityController_js_1.ConnectivityController; } });
|
|
8
|
-
Object.defineProperty(exports, "getDefaultConnectivityControllerState", { enumerable: true, get: function () { return ConnectivityController_js_1.getDefaultConnectivityControllerState; } });
|
|
9
|
-
var selectors_js_1 = require("./selectors.cjs");
|
|
10
|
-
Object.defineProperty(exports, "connectivityControllerSelectors", { enumerable: true, get: function () { return selectors_js_1.connectivityControllerSelectors; } });
|
|
11
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAUA,wCAAmD;AAA1C,iHAAA,qBAAqB,OAAA;AAC9B,0EAGqC;AAFnC,mIAAA,sBAAsB,OAAA;AACtB,kJAAA,qCAAqC,OAAA;AAEvC,gDAAiE;AAAxD,+HAAA,+BAA+B,OAAA","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController.js';\nexport type { ConnectivityControllerSetConnectivityStatusAction } from './ConnectivityController-method-action-types.js';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types.js';\nexport { CONNECTIVITY_STATUSES } from './types.js';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController.js';\nexport { connectivityControllerSelectors } from './selectors.js';\n"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.cjs";
|
|
2
|
-
export type { ConnectivityControllerSetConnectivityStatusAction } from "./ConnectivityController-method-action-types.cjs";
|
|
3
|
-
export type { ConnectivityAdapter, ConnectivityStatus } from "./types.cjs";
|
|
4
|
-
export { CONNECTIVITY_STATUSES } from "./types.cjs";
|
|
5
|
-
export { ConnectivityController, getDefaultConnectivityControllerState, } from "./ConnectivityController.cjs";
|
|
6
|
-
export { connectivityControllerSelectors } from "./selectors.cjs";
|
|
7
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,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,qCAAoC;AACrC,YAAY,EAAE,iDAAiD,EAAE,yDAAwD;AACzH,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAmB;AAC1E,OAAO,EAAE,qBAAqB,EAAE,oBAAmB;AACnD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAoC;AACrC,OAAO,EAAE,+BAA+B,EAAE,wBAAuB"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.mjs";
|
|
2
|
-
export type { ConnectivityControllerSetConnectivityStatusAction } from "./ConnectivityController-method-action-types.mjs";
|
|
3
|
-
export type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs";
|
|
4
|
-
export { CONNECTIVITY_STATUSES } from "./types.mjs";
|
|
5
|
-
export { ConnectivityController, getDefaultConnectivityControllerState, } from "./ConnectivityController.mjs";
|
|
6
|
-
export { connectivityControllerSelectors } from "./selectors.mjs";
|
|
7
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,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,qCAAoC;AACrC,YAAY,EAAE,iDAAiD,EAAE,yDAAwD;AACzH,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAmB;AAC1E,OAAO,EAAE,qBAAqB,EAAE,oBAAmB;AACnD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAoC;AACrC,OAAO,EAAE,+BAA+B,EAAE,wBAAuB"}
|
package/dist/index.mjs
DELETED
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,qBAAqB,EAAE,oBAAmB;AACnD,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACtC,qCAAoC;AACrC,OAAO,EAAE,+BAA+B,EAAE,wBAAuB","sourcesContent":["export type {\n ConnectivityControllerState,\n ConnectivityControllerGetStateAction,\n ConnectivityControllerActions,\n ConnectivityControllerStateChangeEvent,\n ConnectivityControllerEvents,\n ConnectivityControllerMessenger,\n} from './ConnectivityController.js';\nexport type { ConnectivityControllerSetConnectivityStatusAction } from './ConnectivityController-method-action-types.js';\nexport type { ConnectivityAdapter, ConnectivityStatus } from './types.js';\nexport { CONNECTIVITY_STATUSES } from './types.js';\nexport {\n ConnectivityController,\n getDefaultConnectivityControllerState,\n} from './ConnectivityController.js';\nexport { connectivityControllerSelectors } from './selectors.js';\n"]}
|
package/dist/selectors.cjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.connectivityControllerSelectors = void 0;
|
|
4
|
-
const reselect_1 = require("reselect");
|
|
5
|
-
const types_js_1 = require("./types.cjs");
|
|
6
|
-
/**
|
|
7
|
-
* Selects the connectivity status from the controller state.
|
|
8
|
-
*
|
|
9
|
-
* @param state - The controller state
|
|
10
|
-
* @returns The connectivity status
|
|
11
|
-
*/
|
|
12
|
-
const selectConnectivityStatus = (state) => state.connectivityStatus;
|
|
13
|
-
/**
|
|
14
|
-
* Selects whether the device is offline.
|
|
15
|
-
*
|
|
16
|
-
* @param state - The controller state
|
|
17
|
-
* @returns Whether the device is offline
|
|
18
|
-
*/
|
|
19
|
-
const selectIsOffline = (0, reselect_1.createSelector)([selectConnectivityStatus], (connectivityStatus) => connectivityStatus === types_js_1.CONNECTIVITY_STATUSES.Offline);
|
|
20
|
-
/**
|
|
21
|
-
* Selectors for the ConnectivityController state.
|
|
22
|
-
* These can be used with Redux or directly with controller state.
|
|
23
|
-
*/
|
|
24
|
-
exports.connectivityControllerSelectors = {
|
|
25
|
-
selectConnectivityStatus,
|
|
26
|
-
selectIsOffline,
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=selectors.cjs.map
|
package/dist/selectors.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAG1C,0CAAmD;AAGnD;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAC/B,KAAkC,EACd,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,eAAe,GAAG,IAAA,yBAAc,EACpC,CAAC,wBAAwB,CAAC,EAC1B,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,KAAK,gCAAqB,CAAC,OAAO,CAC7E,CAAC;AAEF;;;GAGG;AACU,QAAA,+BAA+B,GAAG;IAC7C,wBAAwB;IACxB,eAAe;CAChB,CAAC","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type { ConnectivityControllerState } from './ConnectivityController.js';\nimport { CONNECTIVITY_STATUSES } from './types.js';\nimport type { ConnectivityStatus } from './types.js';\n\n/**\n * Selects the connectivity status from the controller state.\n *\n * @param state - The controller state\n * @returns The connectivity status\n */\nconst selectConnectivityStatus = (\n state: ConnectivityControllerState,\n): ConnectivityStatus => state.connectivityStatus;\n\n/**\n * Selects whether the device is offline.\n *\n * @param state - The controller state\n * @returns Whether the device is offline\n */\nconst selectIsOffline = createSelector(\n [selectConnectivityStatus],\n (connectivityStatus) => connectivityStatus === CONNECTIVITY_STATUSES.Offline,\n);\n\n/**\n * Selectors for the ConnectivityController state.\n * These can be used with Redux or directly with controller state.\n */\nexport const connectivityControllerSelectors = {\n selectConnectivityStatus,\n selectIsOffline,\n};\n"]}
|
package/dist/selectors.d.cts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ConnectivityControllerState } from "./ConnectivityController.cjs";
|
|
2
|
-
import type { ConnectivityStatus } from "./types.cjs";
|
|
3
|
-
/**
|
|
4
|
-
* Selectors for the ConnectivityController state.
|
|
5
|
-
* These can be used with Redux or directly with controller state.
|
|
6
|
-
*/
|
|
7
|
-
export declare const connectivityControllerSelectors: {
|
|
8
|
-
selectConnectivityStatus: (state: ConnectivityControllerState) => ConnectivityStatus;
|
|
9
|
-
selectIsOffline: ((state: ConnectivityControllerState) => boolean) & {
|
|
10
|
-
clearCache: () => void;
|
|
11
|
-
resultsCount: () => number;
|
|
12
|
-
resetResultsCount: () => void;
|
|
13
|
-
} & {
|
|
14
|
-
resultFunc: (resultFuncArgs_0: ConnectivityStatus) => boolean;
|
|
15
|
-
memoizedResultFunc: ((resultFuncArgs_0: ConnectivityStatus) => boolean) & {
|
|
16
|
-
clearCache: () => void;
|
|
17
|
-
resultsCount: () => number;
|
|
18
|
-
resetResultsCount: () => void;
|
|
19
|
-
};
|
|
20
|
-
lastResult: () => boolean;
|
|
21
|
-
dependencies: [(state: ConnectivityControllerState) => ConnectivityStatus];
|
|
22
|
-
recomputations: () => number;
|
|
23
|
-
resetRecomputations: () => void;
|
|
24
|
-
dependencyRecomputations: () => number;
|
|
25
|
-
resetDependencyRecomputations: () => void;
|
|
26
|
-
} & {
|
|
27
|
-
memoize: typeof import("reselect").weakMapMemoize;
|
|
28
|
-
argsMemoize: typeof import("reselect").weakMapMemoize;
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=selectors.d.cts.map
|
package/dist/selectors.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,qCAAoC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAmB;AAuBrD;;;GAGG;AACH,eAAO,MAAM,+BAA+B;sCAlBnC,2BAA2B,KACjC,kBAAkB;;;;;;;;;;;;;+BADZ,2BAA2B,KACjC,kBAAkB;;;;;;;;;CAoBpB,CAAC"}
|
package/dist/selectors.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,qCAAoC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAmB;AAuBrD;;;GAGG;AACH,eAAO,MAAM,+BAA+B;sCAlBnC,2BAA2B,KACjC,kBAAkB;;;;;;;;;;;;;+BADZ,2BAA2B,KACjC,kBAAkB;;;;;;;;;CAoBpB,CAAC"}
|
package/dist/selectors.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAG1C,OAAO,EAAE,qBAAqB,EAAE,oBAAmB;AAGnD;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAC/B,KAAkC,EACd,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,eAAe,GAAG,cAAc,CACpC,CAAC,wBAAwB,CAAC,EAC1B,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,KAAK,qBAAqB,CAAC,OAAO,CAC7E,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC7C,wBAAwB;IACxB,eAAe;CAChB,CAAC","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type { ConnectivityControllerState } from './ConnectivityController.js';\nimport { CONNECTIVITY_STATUSES } from './types.js';\nimport type { ConnectivityStatus } from './types.js';\n\n/**\n * Selects the connectivity status from the controller state.\n *\n * @param state - The controller state\n * @returns The connectivity status\n */\nconst selectConnectivityStatus = (\n state: ConnectivityControllerState,\n): ConnectivityStatus => state.connectivityStatus;\n\n/**\n * Selects whether the device is offline.\n *\n * @param state - The controller state\n * @returns Whether the device is offline\n */\nconst selectIsOffline = createSelector(\n [selectConnectivityStatus],\n (connectivityStatus) => connectivityStatus === CONNECTIVITY_STATUSES.Offline,\n);\n\n/**\n * Selectors for the ConnectivityController state.\n * These can be used with Redux or directly with controller state.\n */\nexport const connectivityControllerSelectors = {\n selectConnectivityStatus,\n selectIsOffline,\n};\n"]}
|
package/dist/types.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONNECTIVITY_STATUSES = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Connectivity status constants.
|
|
6
|
-
* Used to represent whether the device has internet connectivity.
|
|
7
|
-
*/
|
|
8
|
-
exports.CONNECTIVITY_STATUSES = {
|
|
9
|
-
Online: 'online',
|
|
10
|
-
Offline: 'offline',
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=types.cjs.map
|
package/dist/types.cjs.map
DELETED
|
@@ -1 +0,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 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"]}
|
package/dist/types.d.cts.map
DELETED
|
@@ -1 +0,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,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"}
|
package/dist/types.d.mts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Connectivity status constants.
|
|
3
|
-
* Used to represent whether the device has internet connectivity.
|
|
4
|
-
*/
|
|
5
|
-
export declare const CONNECTIVITY_STATUSES: {
|
|
6
|
-
readonly Online: "online";
|
|
7
|
-
readonly Offline: "offline";
|
|
8
|
-
};
|
|
9
|
-
export type ConnectivityStatus = (typeof CONNECTIVITY_STATUSES)[keyof typeof CONNECTIVITY_STATUSES];
|
|
10
|
-
/**
|
|
11
|
-
* Adapter interface for platform-specific connectivity detection.
|
|
12
|
-
* Each platform (extension, mobile) implements this interface using
|
|
13
|
-
* platform-specific APIs to detect internet connectivity.
|
|
14
|
-
*/
|
|
15
|
-
export type ConnectivityAdapter = {
|
|
16
|
-
/**
|
|
17
|
-
* Returns a promise that resolves to the current connectivity status.
|
|
18
|
-
*
|
|
19
|
-
* @returns A promise that resolves to 'online' if the device is online, 'offline' otherwise.
|
|
20
|
-
*/
|
|
21
|
-
getStatus(): Promise<ConnectivityStatus>;
|
|
22
|
-
/**
|
|
23
|
-
* Registers a callback to be called when connectivity status changes.
|
|
24
|
-
*
|
|
25
|
-
* @param callback - Function called with 'online' when online, 'offline' when offline.
|
|
26
|
-
*/
|
|
27
|
-
onConnectivityChange(callback: (status: ConnectivityStatus) => void): void;
|
|
28
|
-
/**
|
|
29
|
-
* Cleans up any resources (event listeners, subscriptions).
|
|
30
|
-
*/
|
|
31
|
-
destroy(): void;
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
DELETED
|
@@ -1 +0,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,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"}
|
package/dist/types.mjs.map
DELETED
|
@@ -1 +0,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 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"]}
|