@metamask-previews/profile-metrics-controller 0.0.0-preview-e540d3bf → 0.0.0-preview-a5935709
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 +1 -1
- package/dist/ProfileMetricsService-method-action-types.cjs.map +1 -1
- package/dist/ProfileMetricsService-method-action-types.d.cts +6 -6
- package/dist/ProfileMetricsService-method-action-types.d.mts +6 -6
- package/dist/ProfileMetricsService-method-action-types.mjs.map +1 -1
- package/dist/ProfileMetricsService.cjs +18 -8
- package/dist/ProfileMetricsService.cjs.map +1 -1
- package/dist/ProfileMetricsService.d.cts +15 -8
- package/dist/ProfileMetricsService.d.cts.map +1 -1
- package/dist/ProfileMetricsService.d.mts +15 -8
- package/dist/ProfileMetricsService.d.mts.map +1 -1
- package/dist/ProfileMetricsService.mjs +16 -7
- package/dist/ProfileMetricsService.mjs.map +1 -1
- package/dist/index.cjs +1 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -7
- package/dist/ProfileMetricsController.cjs +0 -230
- package/dist/ProfileMetricsController.cjs.map +0 -1
- package/dist/ProfileMetricsController.d.cts +0 -120
- package/dist/ProfileMetricsController.d.cts.map +0 -1
- package/dist/ProfileMetricsController.d.mts +0 -120
- package/dist/ProfileMetricsController.d.mts.map +0 -1
- package/dist/ProfileMetricsController.mjs +0 -225
- package/dist/ProfileMetricsController.mjs.map +0 -1
- package/dist/constants.cjs +0 -29
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -14
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -14
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs +0 -25
- package/dist/constants.mjs.map +0 -1
|
@@ -1,225 +0,0 @@
|
|
|
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 _ProfileMetricsController_instances, _ProfileMetricsController_mutex, _ProfileMetricsController_assertUserOptedIn, _ProfileMetricsController_getMetaMetricsId, _ProfileMetricsController_queueFirstSyncIfNeeded, _ProfileMetricsController_addAccountToQueue, _ProfileMetricsController_removeAccountFromQueue;
|
|
13
|
-
import { StaticIntervalPollingController } from "@metamask/polling-controller";
|
|
14
|
-
import { Mutex } from "async-mutex";
|
|
15
|
-
/**
|
|
16
|
-
* The name of the {@link ProfileMetricsController}, used to namespace the
|
|
17
|
-
* controller's actions and events and to namespace the controller's state data
|
|
18
|
-
* when composed with other controllers.
|
|
19
|
-
*/
|
|
20
|
-
export const controllerName = 'ProfileMetricsController';
|
|
21
|
-
/**
|
|
22
|
-
* The metadata for each property in {@link ProfileMetricsControllerState}.
|
|
23
|
-
*/
|
|
24
|
-
const userProfileControllerMetadata = {
|
|
25
|
-
firstSyncCompleted: {
|
|
26
|
-
persist: true,
|
|
27
|
-
includeInDebugSnapshot: true,
|
|
28
|
-
includeInStateLogs: true,
|
|
29
|
-
usedInUi: false,
|
|
30
|
-
},
|
|
31
|
-
syncQueue: {
|
|
32
|
-
persist: true,
|
|
33
|
-
includeInDebugSnapshot: false,
|
|
34
|
-
includeInStateLogs: true,
|
|
35
|
-
usedInUi: false,
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Constructs the default {@link ProfileMetricsController} state. This allows
|
|
40
|
-
* consumers to provide a partial state object when initializing the controller
|
|
41
|
-
* and also helps in constructing complete state objects for this controller in
|
|
42
|
-
* tests.
|
|
43
|
-
*
|
|
44
|
-
* @returns The default {@link ProfileMetricsController} state.
|
|
45
|
-
*/
|
|
46
|
-
export function getDefaultProfileMetricsControllerState() {
|
|
47
|
-
return {
|
|
48
|
-
firstSyncCompleted: false,
|
|
49
|
-
syncQueue: {},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const MESSENGER_EXPOSED_METHODS = [];
|
|
53
|
-
export class ProfileMetricsController extends StaticIntervalPollingController() {
|
|
54
|
-
/**
|
|
55
|
-
* Constructs a new {@link ProfileMetricsController}.
|
|
56
|
-
*
|
|
57
|
-
* @param args - The constructor arguments.
|
|
58
|
-
* @param args.messenger - The messenger suited for this controller.
|
|
59
|
-
* @param args.state - The desired state with which to initialize this
|
|
60
|
-
* controller. Missing properties will be filled in with defaults.
|
|
61
|
-
* @param args.assertUserOptedIn - A function that asserts whether the user has
|
|
62
|
-
* opted in to user profile features. If the user has not opted in, sync
|
|
63
|
-
* operations will be no-ops.
|
|
64
|
-
* @param args.getMetaMetricsId - A function that returns the MetaMetrics ID
|
|
65
|
-
* of the user.
|
|
66
|
-
* @param args.interval - The interval, in milliseconds, at which the controller will
|
|
67
|
-
* attempt to send user profile data. Defaults to 10 seconds.
|
|
68
|
-
*/
|
|
69
|
-
constructor({ messenger, state, assertUserOptedIn, getMetaMetricsId, interval = 10 * 1000, }) {
|
|
70
|
-
super({
|
|
71
|
-
messenger,
|
|
72
|
-
metadata: userProfileControllerMetadata,
|
|
73
|
-
name: controllerName,
|
|
74
|
-
state: {
|
|
75
|
-
...getDefaultProfileMetricsControllerState(),
|
|
76
|
-
...state,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
_ProfileMetricsController_instances.add(this);
|
|
80
|
-
_ProfileMetricsController_mutex.set(this, new Mutex());
|
|
81
|
-
_ProfileMetricsController_assertUserOptedIn.set(this, void 0);
|
|
82
|
-
_ProfileMetricsController_getMetaMetricsId.set(this, void 0);
|
|
83
|
-
__classPrivateFieldSet(this, _ProfileMetricsController_assertUserOptedIn, assertUserOptedIn, "f");
|
|
84
|
-
__classPrivateFieldSet(this, _ProfileMetricsController_getMetaMetricsId, getMetaMetricsId, "f");
|
|
85
|
-
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
86
|
-
this.messenger.subscribe('KeyringController:unlock', () => {
|
|
87
|
-
this.startPolling(null);
|
|
88
|
-
__classPrivateFieldGet(this, _ProfileMetricsController_instances, "m", _ProfileMetricsController_queueFirstSyncIfNeeded).call(this).catch(console.error);
|
|
89
|
-
});
|
|
90
|
-
this.messenger.subscribe('KeyringController:lock', () => {
|
|
91
|
-
this.stopAllPolling();
|
|
92
|
-
});
|
|
93
|
-
this.messenger.subscribe('AccountsController:accountAdded', (account) => {
|
|
94
|
-
__classPrivateFieldGet(this, _ProfileMetricsController_instances, "m", _ProfileMetricsController_addAccountToQueue).call(this, account).catch(console.error);
|
|
95
|
-
});
|
|
96
|
-
this.messenger.subscribe('AccountsController:accountRemoved', (account) => {
|
|
97
|
-
__classPrivateFieldGet(this, _ProfileMetricsController_instances, "m", _ProfileMetricsController_removeAccountFromQueue).call(this, account).catch(console.error);
|
|
98
|
-
});
|
|
99
|
-
this.setIntervalLength(interval);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Execute a single poll to sync user profile data.
|
|
103
|
-
*
|
|
104
|
-
* The queued accounts are sent to the ProfileMetricsService, and the sync
|
|
105
|
-
* queue is cleared. This operation is mutexed to prevent concurrent
|
|
106
|
-
* executions.
|
|
107
|
-
*
|
|
108
|
-
* @returns A promise that resolves when the poll is complete.
|
|
109
|
-
*/
|
|
110
|
-
async _executePoll() {
|
|
111
|
-
await __classPrivateFieldGet(this, _ProfileMetricsController_mutex, "f").runExclusive(async () => {
|
|
112
|
-
for (const [entropySourceId, accounts] of Object.entries(this.state.syncQueue)) {
|
|
113
|
-
await this.messenger.call('ProfileMetricsService:updateProfile', {
|
|
114
|
-
metametricsId: __classPrivateFieldGet(this, _ProfileMetricsController_getMetaMetricsId, "f").call(this),
|
|
115
|
-
entropySourceId: entropySourceId === 'null' ? null : entropySourceId,
|
|
116
|
-
accounts,
|
|
117
|
-
});
|
|
118
|
-
this.update((state) => {
|
|
119
|
-
delete state.syncQueue[entropySourceId];
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
_ProfileMetricsController_mutex = new WeakMap(), _ProfileMetricsController_assertUserOptedIn = new WeakMap(), _ProfileMetricsController_getMetaMetricsId = new WeakMap(), _ProfileMetricsController_instances = new WeakSet(), _ProfileMetricsController_queueFirstSyncIfNeeded =
|
|
126
|
-
/**
|
|
127
|
-
* Add existing accounts to the sync queue if it has not been done yet.
|
|
128
|
-
*
|
|
129
|
-
* This method ensures that the first sync is only executed once,
|
|
130
|
-
* and only if the user has opted in to user profile features.
|
|
131
|
-
*/
|
|
132
|
-
async function _ProfileMetricsController_queueFirstSyncIfNeeded() {
|
|
133
|
-
await __classPrivateFieldGet(this, _ProfileMetricsController_mutex, "f").runExclusive(async () => {
|
|
134
|
-
if (this.state.firstSyncCompleted || !__classPrivateFieldGet(this, _ProfileMetricsController_assertUserOptedIn, "f").call(this)) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const newGroupedAccounts = groupAccountsByEntropySourceId(this.messenger.call('AccountsController:listAccounts'));
|
|
138
|
-
const queuedAddresses = { ...this.state.syncQueue };
|
|
139
|
-
for (const key of Object.keys(newGroupedAccounts)) {
|
|
140
|
-
if (!queuedAddresses[key]) {
|
|
141
|
-
queuedAddresses[key] = [];
|
|
142
|
-
}
|
|
143
|
-
queuedAddresses[key].push(...newGroupedAccounts[key]);
|
|
144
|
-
}
|
|
145
|
-
this.update((state) => {
|
|
146
|
-
state.firstSyncCompleted = true;
|
|
147
|
-
state.syncQueue = queuedAddresses;
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
}, _ProfileMetricsController_addAccountToQueue =
|
|
151
|
-
/**
|
|
152
|
-
* Queue the given account to be synced at the next poll.
|
|
153
|
-
*
|
|
154
|
-
* @param account - The account to sync.
|
|
155
|
-
*/
|
|
156
|
-
async function _ProfileMetricsController_addAccountToQueue(account) {
|
|
157
|
-
await __classPrivateFieldGet(this, _ProfileMetricsController_mutex, "f").runExclusive(async () => {
|
|
158
|
-
if (!__classPrivateFieldGet(this, _ProfileMetricsController_assertUserOptedIn, "f").call(this)) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
this.update((state) => {
|
|
162
|
-
const entropySourceId = getAccountEntropySourceId(account) || 'null';
|
|
163
|
-
if (!state.syncQueue[entropySourceId]) {
|
|
164
|
-
state.syncQueue[entropySourceId] = [];
|
|
165
|
-
}
|
|
166
|
-
state.syncQueue[entropySourceId].push({
|
|
167
|
-
address: account.address,
|
|
168
|
-
scopes: account.scopes,
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}, _ProfileMetricsController_removeAccountFromQueue =
|
|
173
|
-
/**
|
|
174
|
-
* Remove the given account from the sync queue.
|
|
175
|
-
*
|
|
176
|
-
* @param account - The account address to remove.
|
|
177
|
-
*/
|
|
178
|
-
async function _ProfileMetricsController_removeAccountFromQueue(account) {
|
|
179
|
-
await __classPrivateFieldGet(this, _ProfileMetricsController_mutex, "f").runExclusive(async () => {
|
|
180
|
-
this.update((state) => {
|
|
181
|
-
for (const [entropySourceId, groupedAddresses] of Object.entries(state.syncQueue)) {
|
|
182
|
-
const index = groupedAddresses.findIndex(({ address }) => address === account);
|
|
183
|
-
if (index === -1) {
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
groupedAddresses.splice(index, 1);
|
|
187
|
-
if (groupedAddresses.length === 0) {
|
|
188
|
-
delete state.syncQueue[entropySourceId];
|
|
189
|
-
}
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Retrieves the entropy source ID from the given account, if it exists.
|
|
197
|
-
*
|
|
198
|
-
* @param account - The account from which to retrieve the entropy source ID.
|
|
199
|
-
* @returns The entropy source ID, or null if it does not exist.
|
|
200
|
-
*/
|
|
201
|
-
function getAccountEntropySourceId(account) {
|
|
202
|
-
if (account.options.entropy && account.options.entropy.type === 'mnemonic') {
|
|
203
|
-
return account.options.entropy.id;
|
|
204
|
-
}
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Groups accounts by their entropy source ID.
|
|
209
|
-
*
|
|
210
|
-
* @param accounts - The accounts to group.
|
|
211
|
-
* @returns An object where each key is an entropy source ID and each value is
|
|
212
|
-
* an array of account addresses associated with that entropy source ID.
|
|
213
|
-
*/
|
|
214
|
-
function groupAccountsByEntropySourceId(accounts) {
|
|
215
|
-
return accounts.reduce((result, account) => {
|
|
216
|
-
const entropySourceId = getAccountEntropySourceId(account);
|
|
217
|
-
const key = entropySourceId || 'null';
|
|
218
|
-
if (!result[key]) {
|
|
219
|
-
result[key] = [];
|
|
220
|
-
}
|
|
221
|
-
result[key].push({ address: account.address, scopes: account.scopes });
|
|
222
|
-
return result;
|
|
223
|
-
}, {});
|
|
224
|
-
}
|
|
225
|
-
//# sourceMappingURL=ProfileMetricsController.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetricsController.m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C,CAAC;gBAClC,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAClC,OAAO,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;gBAC1C,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAGH;;;;;GAKG;AACH,SAAS,yBAAyB,CAAC,OAAwB;IACzD,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC3E,OAAO,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,SAAS,8BAA8B,CACrC,QAA2B;IAE3B,OAAO,QAAQ,CAAC,MAAM,CACpB,CAAC,MAA2C,EAAE,OAAO,EAAE,EAAE;QACvD,MAAM,eAAe,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,GAAG,GAAG,eAAe,IAAI,MAAM,CAAC;QACtC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACnB,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACvE,OAAO,MAAM,CAAC;IAChB,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import type {\n AccountsControllerAccountAddedEvent,\n AccountsControllerListAccountsAction,\n AccountsControllerAccountRemovedEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type {\n KeyringControllerLockEvent,\n KeyringControllerUnlockEvent,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport { Mutex } from 'async-mutex';\n\nimport type { ProfileMetricsServiceMethodActions } from '.';\nimport type { AccountWithScopes } from './ProfileMetricsService';\n\n/**\n * The name of the {@link ProfileMetricsController}, 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 = 'ProfileMetricsController';\n\n/**\n * Describes the shape of the state object for {@link ProfileMetricsController}.\n */\nexport type ProfileMetricsControllerState = {\n /**\n * Whether the first sync has been completed.\n */\n firstSyncCompleted: boolean;\n /**\n * The queue of accounts to be synced.\n * Each key is an entropy source ID, and each value is an array of account\n * addresses associated with that entropy source. Accounts with no entropy\n * source ID are grouped under the key \"null\".\n */\n syncQueue: Record<string, AccountWithScopes[]>;\n};\n\n/**\n * The metadata for each property in {@link ProfileMetricsControllerState}.\n */\nconst userProfileControllerMetadata = {\n firstSyncCompleted: {\n persist: true,\n includeInDebugSnapshot: true,\n includeInStateLogs: true,\n usedInUi: false,\n },\n syncQueue: {\n persist: true,\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<ProfileMetricsControllerState>;\n\n/**\n * Constructs the default {@link ProfileMetricsController} 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 ProfileMetricsController} state.\n */\nexport function getDefaultProfileMetricsControllerState(): ProfileMetricsControllerState {\n return {\n firstSyncCompleted: false,\n syncQueue: {},\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [] as const;\n\n/**\n * Retrieves the state of the {@link ProfileMetricsController}.\n */\nexport type ProfileMetricsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ProfileMetricsControllerState\n>;\n\n/**\n * Actions that {@link ProfileMetricsControllerMessenger} exposes to other consumers.\n */\nexport type ProfileMetricsControllerActions =\n | ProfileMetricsControllerGetStateAction\n | ProfileMetricsServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ProfileMetricsControllerMessenger} calls.\n */\ntype AllowedActions =\n | ProfileMetricsServiceMethodActions\n | AccountsControllerListAccountsAction;\n\n/**\n * Published when the state of {@link ProfileMetricsController} changes.\n */\nexport type ProfileMetricsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n ProfileMetricsControllerState\n >;\n\n/**\n * Events that {@link ProfileMetricsControllerMessenger} exposes to other consumers.\n */\nexport type ProfileMetricsControllerEvents =\n ProfileMetricsControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ProfileMetricsControllerMessenger} subscribes\n * to.\n */\ntype AllowedEvents =\n | KeyringControllerUnlockEvent\n | KeyringControllerLockEvent\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ProfileMetricsController}.\n */\nexport type ProfileMetricsControllerMessenger = Messenger<\n typeof controllerName,\n ProfileMetricsControllerActions | AllowedActions,\n ProfileMetricsControllerEvents | AllowedEvents\n>;\n\nexport class ProfileMetricsController extends StaticIntervalPollingController()<\n typeof controllerName,\n ProfileMetricsControllerState,\n ProfileMetricsControllerMessenger\n> {\n readonly #mutex = new Mutex();\n\n readonly #assertUserOptedIn: () => boolean;\n\n readonly #getMetaMetricsId: () => string;\n\n /**\n * Constructs a new {@link ProfileMetricsController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to initialize this\n * controller. Missing properties will be filled in with defaults.\n * @param args.assertUserOptedIn - A function that asserts whether the user has\n * opted in to user profile features. If the user has not opted in, sync\n * operations will be no-ops.\n * @param args.getMetaMetricsId - A function that returns the MetaMetrics ID\n * of the user.\n * @param args.interval - The interval, in milliseconds, at which the controller will\n * attempt to send user profile data. Defaults to 10 seconds.\n */\n constructor({\n messenger,\n state,\n assertUserOptedIn,\n getMetaMetricsId,\n interval = 10 * 1000,\n }: {\n messenger: ProfileMetricsControllerMessenger;\n state?: Partial<ProfileMetricsControllerState>;\n interval?: number;\n assertUserOptedIn: () => boolean;\n getMetaMetricsId: () => string;\n }) {\n super({\n messenger,\n metadata: userProfileControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultProfileMetricsControllerState(),\n ...state,\n },\n });\n\n this.#assertUserOptedIn = assertUserOptedIn;\n this.#getMetaMetricsId = getMetaMetricsId;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.messenger.subscribe('KeyringController:unlock', () => {\n this.startPolling(null);\n this.#queueFirstSyncIfNeeded().catch(console.error);\n });\n\n this.messenger.subscribe('KeyringController:lock', () => {\n this.stopAllPolling();\n });\n\n this.messenger.subscribe('AccountsController:accountAdded', (account) => {\n this.#addAccountToQueue(account).catch(console.error);\n });\n\n this.messenger.subscribe('AccountsController:accountRemoved', (account) => {\n this.#removeAccountFromQueue(account).catch(console.error);\n });\n\n this.setIntervalLength(interval);\n }\n\n /**\n * Execute a single poll to sync user profile data.\n *\n * The queued accounts are sent to the ProfileMetricsService, and the sync\n * queue is cleared. This operation is mutexed to prevent concurrent\n * executions.\n *\n * @returns A promise that resolves when the poll is complete.\n */\n async _executePoll(): Promise<void> {\n await this.#mutex.runExclusive(async () => {\n for (const [entropySourceId, accounts] of Object.entries(\n this.state.syncQueue,\n )) {\n await this.messenger.call('ProfileMetricsService:updateProfile', {\n metametricsId: this.#getMetaMetricsId(),\n entropySourceId: entropySourceId === 'null' ? null : entropySourceId,\n accounts,\n });\n this.update((state) => {\n delete state.syncQueue[entropySourceId];\n });\n }\n });\n }\n\n /**\n * Add existing accounts to the sync queue if it has not been done yet.\n *\n * This method ensures that the first sync is only executed once,\n * and only if the user has opted in to user profile features.\n */\n async #queueFirstSyncIfNeeded() {\n await this.#mutex.runExclusive(async () => {\n if (this.state.firstSyncCompleted || !this.#assertUserOptedIn()) {\n return;\n }\n const newGroupedAccounts = groupAccountsByEntropySourceId(\n this.messenger.call('AccountsController:listAccounts'),\n );\n const queuedAddresses = { ...this.state.syncQueue };\n for (const key of Object.keys(newGroupedAccounts)) {\n if (!queuedAddresses[key]) {\n queuedAddresses[key] = [];\n }\n queuedAddresses[key].push(...newGroupedAccounts[key]);\n }\n this.update((state) => {\n state.firstSyncCompleted = true;\n state.syncQueue = queuedAddresses;\n });\n });\n }\n\n /**\n * Queue the given account to be synced at the next poll.\n *\n * @param account - The account to sync.\n */\n async #addAccountToQueue(account: InternalAccount) {\n await this.#mutex.runExclusive(async () => {\n if (!this.#assertUserOptedIn()) {\n return;\n }\n this.update((state) => {\n const entropySourceId = getAccountEntropySourceId(account) || 'null';\n if (!state.syncQueue[entropySourceId]) {\n state.syncQueue[entropySourceId] = [];\n }\n state.syncQueue[entropySourceId].push({\n address: account.address,\n scopes: account.scopes,\n });\n });\n });\n }\n\n /**\n * Remove the given account from the sync queue.\n *\n * @param account - The account address to remove.\n */\n async #removeAccountFromQueue(account: string) {\n await this.#mutex.runExclusive(async () => {\n this.update((state) => {\n for (const [entropySourceId, groupedAddresses] of Object.entries(\n state.syncQueue,\n )) {\n const index = groupedAddresses.findIndex(\n ({ address }) => address === account,\n );\n if (index === -1) {\n continue;\n }\n groupedAddresses.splice(index, 1);\n if (groupedAddresses.length === 0) {\n delete state.syncQueue[entropySourceId];\n }\n break;\n }\n });\n });\n }\n}\n\n/**\n * Retrieves the entropy source ID from the given account, if it exists.\n *\n * @param account - The account from which to retrieve the entropy source ID.\n * @returns The entropy source ID, or null if it does not exist.\n */\nfunction getAccountEntropySourceId(account: InternalAccount): string | null {\n if (account.options.entropy && account.options.entropy.type === 'mnemonic') {\n return account.options.entropy.id;\n }\n return null;\n}\n\n/**\n * Groups accounts by their entropy source ID.\n *\n * @param accounts - The accounts to group.\n * @returns An object where each key is an entropy source ID and each value is\n * an array of account addresses associated with that entropy source ID.\n */\nfunction groupAccountsByEntropySourceId(\n accounts: InternalAccount[],\n): Record<string, AccountWithScopes[]> {\n return accounts.reduce(\n (result: Record<string, AccountWithScopes[]>, account) => {\n const entropySourceId = getAccountEntropySourceId(account);\n const key = entropySourceId || 'null';\n if (!result[key]) {\n result[key] = [];\n }\n result[key].push({ address: account.address, scopes: account.scopes });\n return result;\n },\n {},\n );\n}\n"]}
|
package/dist/constants.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnvUrl = exports.Env = void 0;
|
|
4
|
-
var Env;
|
|
5
|
-
(function (Env) {
|
|
6
|
-
Env["DEV"] = "dev";
|
|
7
|
-
Env["UAT"] = "uat";
|
|
8
|
-
Env["PRD"] = "prd";
|
|
9
|
-
})(Env || (exports.Env = Env = {}));
|
|
10
|
-
const ENV_URLS = {
|
|
11
|
-
dev: 'https://authentication.dev-api.cx.metamask.io/api/v2',
|
|
12
|
-
uat: 'https://authentication.uat-api.cx.metamask.io/api/v2',
|
|
13
|
-
prd: 'https://authentication.api.cx.metamask.io/api/v2',
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Validates and returns correct environment endpoints
|
|
17
|
-
*
|
|
18
|
-
* @param env - environment field
|
|
19
|
-
* @returns the correct environment url
|
|
20
|
-
* @throws on invalid environment passed
|
|
21
|
-
*/
|
|
22
|
-
function getEnvUrl(env) {
|
|
23
|
-
if (!ENV_URLS[env]) {
|
|
24
|
-
throw new Error('invalid environment configuration');
|
|
25
|
-
}
|
|
26
|
-
return ENV_URLS[env];
|
|
27
|
-
}
|
|
28
|
-
exports.getEnvUrl = getEnvUrl;
|
|
29
|
-
//# sourceMappingURL=constants.cjs.map
|
package/dist/constants.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,mBAAH,GAAG,QAId;AAED,MAAM,QAAQ,GAAwB;IACpC,GAAG,EAAE,sDAAsD;IAC3D,GAAG,EAAE,sDAAsD;IAC3D,GAAG,EAAE,kDAAkD;CACxD,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,GAAQ;IAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AALD,8BAKC","sourcesContent":["export enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\nconst ENV_URLS: Record<Env, string> = {\n dev: 'https://authentication.dev-api.cx.metamask.io/api/v2',\n uat: 'https://authentication.uat-api.cx.metamask.io/api/v2',\n prd: 'https://authentication.api.cx.metamask.io/api/v2',\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrl(env: Env): string {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n"]}
|
package/dist/constants.d.cts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare enum Env {
|
|
2
|
-
DEV = "dev",
|
|
3
|
-
UAT = "uat",
|
|
4
|
-
PRD = "prd"
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Validates and returns correct environment endpoints
|
|
8
|
-
*
|
|
9
|
-
* @param env - environment field
|
|
10
|
-
* @returns the correct environment url
|
|
11
|
-
* @throws on invalid environment passed
|
|
12
|
-
*/
|
|
13
|
-
export declare function getEnvUrl(env: Env): string;
|
|
14
|
-
//# sourceMappingURL=constants.d.cts.map
|
package/dist/constants.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAQD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAK1C"}
|
package/dist/constants.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare enum Env {
|
|
2
|
-
DEV = "dev",
|
|
3
|
-
UAT = "uat",
|
|
4
|
-
PRD = "prd"
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Validates and returns correct environment endpoints
|
|
8
|
-
*
|
|
9
|
-
* @param env - environment field
|
|
10
|
-
* @returns the correct environment url
|
|
11
|
-
* @throws on invalid environment passed
|
|
12
|
-
*/
|
|
13
|
-
export declare function getEnvUrl(env: Env): string;
|
|
14
|
-
//# sourceMappingURL=constants.d.mts.map
|
package/dist/constants.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAQD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAK1C"}
|
package/dist/constants.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export var Env;
|
|
2
|
-
(function (Env) {
|
|
3
|
-
Env["DEV"] = "dev";
|
|
4
|
-
Env["UAT"] = "uat";
|
|
5
|
-
Env["PRD"] = "prd";
|
|
6
|
-
})(Env || (Env = {}));
|
|
7
|
-
const ENV_URLS = {
|
|
8
|
-
dev: 'https://authentication.dev-api.cx.metamask.io/api/v2',
|
|
9
|
-
uat: 'https://authentication.uat-api.cx.metamask.io/api/v2',
|
|
10
|
-
prd: 'https://authentication.api.cx.metamask.io/api/v2',
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Validates and returns correct environment endpoints
|
|
14
|
-
*
|
|
15
|
-
* @param env - environment field
|
|
16
|
-
* @returns the correct environment url
|
|
17
|
-
* @throws on invalid environment passed
|
|
18
|
-
*/
|
|
19
|
-
export function getEnvUrl(env) {
|
|
20
|
-
if (!ENV_URLS[env]) {
|
|
21
|
-
throw new Error('invalid environment configuration');
|
|
22
|
-
}
|
|
23
|
-
return ENV_URLS[env];
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=constants.mjs.map
|
package/dist/constants.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,KAAH,GAAG,QAId;AAED,MAAM,QAAQ,GAAwB;IACpC,GAAG,EAAE,sDAAsD;IAC3D,GAAG,EAAE,sDAAsD;IAC3D,GAAG,EAAE,kDAAkD;CACxD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,GAAQ;IAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC","sourcesContent":["export enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\nconst ENV_URLS: Record<Env, string> = {\n dev: 'https://authentication.dev-api.cx.metamask.io/api/v2',\n uat: 'https://authentication.uat-api.cx.metamask.io/api/v2',\n prd: 'https://authentication.api.cx.metamask.io/api/v2',\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrl(env: Env): string {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n"]}
|