@metamask-previews/connectivity-controller 0.1.0-preview-fa81dffb → 0.1.0-preview-ab102d86

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 CHANGED
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Add `init` method to asynchronously fetch and set the initial connectivity status from the adapter ([#7679](https://github.com/MetaMask/core/pull/7679))
13
+ - The controller now initializes with a default state (online) and requires calling `init()` to fetch the actual status
14
+ - Add `setConnectivityStatus` method to manually set connectivity status ([#7676](https://github.com/MetaMask/core/pull/7676))
15
+ - The method is exposed as a messenger action `ConnectivityController:setConnectivityStatus`
16
+
17
+ ### Changed
18
+
19
+ - **BREAKING:** `ConnectivityAdapter.getStatus()` must now return a `Promise<ConnectivityStatus>` (async) ([#7679](https://github.com/MetaMask/core/pull/7679))
20
+ - Adapter implementations must update their `getStatus()` method to return a Promise
21
+ - This change enables asynchronous initialization of the controller via the `init()` method
22
+
10
23
  ## [0.1.0]
11
24
 
12
25
  ### Added
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
4
+ * Do not edit manually.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=ConnectivityController-method-action-types.cjs.map
@@ -0,0 +1 @@
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { ConnectivityController } from './ConnectivityController';\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 ConnectivityControllerSetConnectivityStatusAction;\n"]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ import type { ConnectivityController } from "./ConnectivityController.cjs";
6
+ /**
7
+ * Sets the connectivity status.
8
+ *
9
+ * @param status - The connectivity status to set.
10
+ */
11
+ export type ConnectivityControllerSetConnectivityStatusAction = {
12
+ type: `ConnectivityController:setConnectivityStatus`;
13
+ handler: ConnectivityController['setConnectivityStatus'];
14
+ };
15
+ /**
16
+ * Union of all ConnectivityController action types.
17
+ */
18
+ export type ConnectivityControllerMethodActions = ConnectivityControllerSetConnectivityStatusAction;
19
+ //# sourceMappingURL=ConnectivityController-method-action-types.d.cts.map
@@ -0,0 +1 @@
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,qCAAiC;AAEvE;;;;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,GAC7C,iDAAiD,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ import type { ConnectivityController } from "./ConnectivityController.mjs";
6
+ /**
7
+ * Sets the connectivity status.
8
+ *
9
+ * @param status - The connectivity status to set.
10
+ */
11
+ export type ConnectivityControllerSetConnectivityStatusAction = {
12
+ type: `ConnectivityController:setConnectivityStatus`;
13
+ handler: ConnectivityController['setConnectivityStatus'];
14
+ };
15
+ /**
16
+ * Union of all ConnectivityController action types.
17
+ */
18
+ export type ConnectivityControllerMethodActions = ConnectivityControllerSetConnectivityStatusAction;
19
+ //# sourceMappingURL=ConnectivityController-method-action-types.d.mts.map
@@ -0,0 +1 @@
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,qCAAiC;AAEvE;;;;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,GAC7C,iDAAiD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * Do not edit manually.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=ConnectivityController-method-action-types.mjs.map
@@ -0,0 +1 @@
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { ConnectivityController } from './ConnectivityController';\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 ConnectivityControllerSetConnectivityStatusAction;\n"]}
@@ -1,4 +1,16 @@
1
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;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.ConnectivityController = exports.getDefaultConnectivityControllerState = exports.controllerName = void 0;
4
16
  const base_controller_1 = require("@metamask/base-controller");
@@ -34,6 +46,7 @@ function getDefaultConnectivityControllerState() {
34
46
  };
35
47
  }
36
48
  exports.getDefaultConnectivityControllerState = getDefaultConnectivityControllerState;
49
+ const MESSENGER_EXPOSED_METHODS = ['setConnectivityStatus'];
37
50
  /**
38
51
  * ConnectivityController stores the device's internet connectivity status.
39
52
  *
@@ -57,22 +70,35 @@ class ConnectivityController extends base_controller_1.BaseController {
57
70
  * @param args.connectivityAdapter - The connectivity adapter to use.
58
71
  */
59
72
  constructor({ messenger, connectivityAdapter, }) {
60
- const initialStatus = connectivityAdapter.getStatus();
61
73
  super({
62
74
  messenger,
63
75
  metadata: connectivityControllerMetadata,
64
76
  name: exports.controllerName,
65
- state: {
66
- ...getDefaultConnectivityControllerState(),
67
- connectivityStatus: initialStatus,
68
- },
77
+ state: getDefaultConnectivityControllerState(),
69
78
  });
70
- connectivityAdapter.onConnectivityChange((status) => {
71
- this.update((draftState) => {
72
- draftState.connectivityStatus = status;
73
- });
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;
74
99
  });
75
100
  }
76
101
  }
77
102
  exports.ConnectivityController = ConnectivityController;
103
+ _ConnectivityController_connectivityAdapter = new WeakMap();
78
104
  //# sourceMappingURL=ConnectivityController.cjs.map
@@ -1 +1 @@
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"]}
1
+ {"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,uBAAuB,CAAU,CAAC;AAmErE;;;;;;;;;;;;;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 = ['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,6 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
+ import { ConnectivityControllerMethodActions } from "./ConnectivityController-method-action-types.cjs";
4
5
  import type { ConnectivityAdapter, ConnectivityStatus } from "./types.cjs";
5
6
  /**
6
7
  * The name of the {@link ConnectivityController}, used to namespace the
@@ -34,7 +35,7 @@ export type ConnectivityControllerGetStateAction = ControllerGetStateAction<type
34
35
  /**
35
36
  * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.
36
37
  */
37
- export type ConnectivityControllerActions = ConnectivityControllerGetStateAction;
38
+ export type ConnectivityControllerActions = ConnectivityControllerGetStateAction | ConnectivityControllerMethodActions;
38
39
  /**
39
40
  * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.
40
41
  */
@@ -85,6 +86,7 @@ export type ConnectivityControllerOptions = {
85
86
  * enabling the UI and other controllers to adapt when the user goes offline.
86
87
  */
87
88
  export declare class ConnectivityController extends BaseController<typeof controllerName, ConnectivityControllerState, ConnectivityControllerMessenger> {
89
+ #private;
88
90
  /**
89
91
  * Constructs a new {@link ConnectivityController}.
90
92
  *
@@ -93,6 +95,16 @@ export declare class ConnectivityController extends BaseController<typeof contro
93
95
  * @param args.connectivityAdapter - The connectivity adapter to use.
94
96
  */
95
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;
96
108
  }
97
109
  export {};
98
110
  //# sourceMappingURL=ConnectivityController.d.cts.map
@@ -1 +1 @@
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"}
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,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"}
@@ -1,6 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
+ import { ConnectivityControllerMethodActions } from "./ConnectivityController-method-action-types.mjs";
4
5
  import type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs";
5
6
  /**
6
7
  * The name of the {@link ConnectivityController}, used to namespace the
@@ -34,7 +35,7 @@ export type ConnectivityControllerGetStateAction = ControllerGetStateAction<type
34
35
  /**
35
36
  * Actions that {@link ConnectivityControllerMessenger} exposes to other consumers.
36
37
  */
37
- export type ConnectivityControllerActions = ConnectivityControllerGetStateAction;
38
+ export type ConnectivityControllerActions = ConnectivityControllerGetStateAction | ConnectivityControllerMethodActions;
38
39
  /**
39
40
  * Actions from other messengers that {@link ConnectivityControllerMessenger} calls.
40
41
  */
@@ -85,6 +86,7 @@ export type ConnectivityControllerOptions = {
85
86
  * enabling the UI and other controllers to adapt when the user goes offline.
86
87
  */
87
88
  export declare class ConnectivityController extends BaseController<typeof controllerName, ConnectivityControllerState, ConnectivityControllerMessenger> {
89
+ #private;
88
90
  /**
89
91
  * Constructs a new {@link ConnectivityController}.
90
92
  *
@@ -93,6 +95,16 @@ export declare class ConnectivityController extends BaseController<typeof contro
93
95
  * @param args.connectivityAdapter - The connectivity adapter to use.
94
96
  */
95
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;
96
108
  }
97
109
  export {};
98
110
  //# sourceMappingURL=ConnectivityController.d.mts.map
@@ -1 +1 @@
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"}
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,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"}
@@ -1,3 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ 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");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _ConnectivityController_connectivityAdapter;
1
13
  import { BaseController } from "@metamask/base-controller";
2
14
  import { CONNECTIVITY_STATUSES } from "./types.mjs";
3
15
  /**
@@ -30,6 +42,7 @@ export function getDefaultConnectivityControllerState() {
30
42
  connectivityStatus: CONNECTIVITY_STATUSES.Online,
31
43
  };
32
44
  }
45
+ const MESSENGER_EXPOSED_METHODS = ['setConnectivityStatus'];
33
46
  /**
34
47
  * ConnectivityController stores the device's internet connectivity status.
35
48
  *
@@ -53,21 +66,34 @@ export class ConnectivityController extends BaseController {
53
66
  * @param args.connectivityAdapter - The connectivity adapter to use.
54
67
  */
55
68
  constructor({ messenger, connectivityAdapter, }) {
56
- const initialStatus = connectivityAdapter.getStatus();
57
69
  super({
58
70
  messenger,
59
71
  metadata: connectivityControllerMetadata,
60
72
  name: controllerName,
61
- state: {
62
- ...getDefaultConnectivityControllerState(),
63
- connectivityStatus: initialStatus,
64
- },
73
+ state: getDefaultConnectivityControllerState(),
65
74
  });
66
- connectivityAdapter.onConnectivityChange((status) => {
67
- this.update((draftState) => {
68
- draftState.connectivityStatus = status;
69
- });
75
+ _ConnectivityController_connectivityAdapter.set(this, void 0);
76
+ __classPrivateFieldSet(this, _ConnectivityController_connectivityAdapter, connectivityAdapter, "f");
77
+ __classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").onConnectivityChange(this.setConnectivityStatus.bind(this));
78
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
79
+ }
80
+ /**
81
+ * Initializes the controller by fetching the initial connectivity status.
82
+ */
83
+ async init() {
84
+ const initialStatus = await __classPrivateFieldGet(this, _ConnectivityController_connectivityAdapter, "f").getStatus();
85
+ this.setConnectivityStatus(initialStatus);
86
+ }
87
+ /**
88
+ * Sets the connectivity status.
89
+ *
90
+ * @param status - The connectivity status to set.
91
+ */
92
+ setConnectivityStatus(status) {
93
+ this.update((draftState) => {
94
+ draftState.connectivityStatus = status;
70
95
  });
71
96
  }
72
97
  }
98
+ _ConnectivityController_connectivityAdapter = new WeakMap();
73
99
  //# sourceMappingURL=ConnectivityController.mjs.map
@@ -1 +1 @@
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"]}
1
+ {"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,uBAAuB,CAAU,CAAC;AAmErE;;;;;;;;;;;;;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 = ['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 @@
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"]}
1
+ {"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"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.cjs";
2
+ export type { ConnectivityControllerSetConnectivityStatusAction } from "./ConnectivityController-method-action-types.cjs";
2
3
  export type { ConnectivityAdapter, ConnectivityStatus } from "./types.cjs";
3
4
  export { CONNECTIVITY_STATUSES } from "./types.cjs";
4
5
  export { ConnectivityController, getDefaultConnectivityControllerState, } from "./ConnectivityController.cjs";
@@ -1 +1 @@
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"}
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,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"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { ConnectivityControllerState, ConnectivityControllerGetStateAction, ConnectivityControllerActions, ConnectivityControllerStateChangeEvent, ConnectivityControllerEvents, ConnectivityControllerMessenger, } from "./ConnectivityController.mjs";
2
+ export type { ConnectivityControllerSetConnectivityStatusAction } from "./ConnectivityController-method-action-types.mjs";
2
3
  export type { ConnectivityAdapter, ConnectivityStatus } from "./types.mjs";
3
4
  export { CONNECTIVITY_STATUSES } from "./types.mjs";
4
5
  export { ConnectivityController, getDefaultConnectivityControllerState, } from "./ConnectivityController.mjs";
@@ -1 +1 @@
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"}
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,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 @@
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"]}
1
+ {"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 @@
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"]}
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 CHANGED
@@ -14,11 +14,11 @@ export type ConnectivityStatus = (typeof CONNECTIVITY_STATUSES)[keyof typeof CON
14
14
  */
15
15
  export type ConnectivityAdapter = {
16
16
  /**
17
- * Returns the current connectivity status.
17
+ * Returns a promise that resolves to the current connectivity status.
18
18
  *
19
- * @returns 'online' if the device is online, 'offline' otherwise.
19
+ * @returns A promise that resolves to 'online' if the device is online, 'offline' otherwise.
20
20
  */
21
- getStatus(): ConnectivityStatus;
21
+ getStatus(): Promise<ConnectivityStatus>;
22
22
  /**
23
23
  * Registers a callback to be called when connectivity status changes.
24
24
  *
@@ -1 +1 @@
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"}
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 CHANGED
@@ -14,11 +14,11 @@ export type ConnectivityStatus = (typeof CONNECTIVITY_STATUSES)[keyof typeof CON
14
14
  */
15
15
  export type ConnectivityAdapter = {
16
16
  /**
17
- * Returns the current connectivity status.
17
+ * Returns a promise that resolves to the current connectivity status.
18
18
  *
19
- * @returns 'online' if the device is online, 'offline' otherwise.
19
+ * @returns A promise that resolves to 'online' if the device is online, 'offline' otherwise.
20
20
  */
21
- getStatus(): ConnectivityStatus;
21
+ getStatus(): Promise<ConnectivityStatus>;
22
22
  /**
23
23
  * Registers a callback to be called when connectivity status changes.
24
24
  *
@@ -1 +1 @@
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"}
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"}
@@ -1 +1 @@
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"]}
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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/connectivity-controller",
3
- "version": "0.1.0-preview-fa81dffb",
3
+ "version": "0.1.0-preview-ab102d86",
4
4
  "description": "ConnectivityController stores the device's internet connectivity status",
5
5
  "keywords": [
6
6
  "MetaMask",