@metamask-previews/profile-metrics-controller 0.0.0-preview-e0d310b4 → 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
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
11
|
|
|
12
|
-
- Initial release ([#7194](https://github.com/MetaMask/core/pull/7194)
|
|
12
|
+
- Initial release ([#7194](https://github.com/MetaMask/core/pull/7194))
|
|
13
13
|
|
|
14
14
|
[Unreleased]: https://github.com/MetaMask/core/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetricsService-method-action-types.cjs","sourceRoot":"","sources":["../src/ProfileMetricsService-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 { ProfileMetricsService } from './ProfileMetricsService';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"ProfileMetricsService-method-action-types.cjs","sourceRoot":"","sources":["../src/ProfileMetricsService-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 { ProfileMetricsService } from './ProfileMetricsService';\n\n/**\n * Submit metrics to the API.\n *\n * @param data - The data to send in the metrics update request.\n * @returns The response from the API.\n */\nexport type ProfileMetricsServiceSubmitMetricsAction = {\n type: `ProfileMetricsService:submitMetrics`;\n handler: ProfileMetricsService['submitMetrics'];\n};\n\n/**\n * Union of all ProfileMetricsService action types.\n */\nexport type ProfileMetricsServiceMethodActions =\n ProfileMetricsServiceSubmitMetricsAction;\n"]}
|
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ProfileMetricsService } from "./ProfileMetricsService.cjs";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Submit metrics to the API.
|
|
8
8
|
*
|
|
9
|
-
* @param data - The data to send in the
|
|
9
|
+
* @param data - The data to send in the metrics update request.
|
|
10
10
|
* @returns The response from the API.
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
13
|
-
type: `ProfileMetricsService:
|
|
14
|
-
handler: ProfileMetricsService['
|
|
12
|
+
export type ProfileMetricsServiceSubmitMetricsAction = {
|
|
13
|
+
type: `ProfileMetricsService:submitMetrics`;
|
|
14
|
+
handler: ProfileMetricsService['submitMetrics'];
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Union of all ProfileMetricsService action types.
|
|
18
18
|
*/
|
|
19
|
-
export type ProfileMetricsServiceMethodActions =
|
|
19
|
+
export type ProfileMetricsServiceMethodActions = ProfileMetricsServiceSubmitMetricsAction;
|
|
20
20
|
//# sourceMappingURL=ProfileMetricsService-method-action-types.d.cts.map
|
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { ProfileMetricsService } from "./ProfileMetricsService.mjs";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Submit metrics to the API.
|
|
8
8
|
*
|
|
9
|
-
* @param data - The data to send in the
|
|
9
|
+
* @param data - The data to send in the metrics update request.
|
|
10
10
|
* @returns The response from the API.
|
|
11
11
|
*/
|
|
12
|
-
export type
|
|
13
|
-
type: `ProfileMetricsService:
|
|
14
|
-
handler: ProfileMetricsService['
|
|
12
|
+
export type ProfileMetricsServiceSubmitMetricsAction = {
|
|
13
|
+
type: `ProfileMetricsService:submitMetrics`;
|
|
14
|
+
handler: ProfileMetricsService['submitMetrics'];
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Union of all ProfileMetricsService action types.
|
|
18
18
|
*/
|
|
19
|
-
export type ProfileMetricsServiceMethodActions =
|
|
19
|
+
export type ProfileMetricsServiceMethodActions = ProfileMetricsServiceSubmitMetricsAction;
|
|
20
20
|
//# sourceMappingURL=ProfileMetricsService-method-action-types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetricsService-method-action-types.mjs","sourceRoot":"","sources":["../src/ProfileMetricsService-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 { ProfileMetricsService } from './ProfileMetricsService';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"ProfileMetricsService-method-action-types.mjs","sourceRoot":"","sources":["../src/ProfileMetricsService-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 { ProfileMetricsService } from './ProfileMetricsService';\n\n/**\n * Submit metrics to the API.\n *\n * @param data - The data to send in the metrics update request.\n * @returns The response from the API.\n */\nexport type ProfileMetricsServiceSubmitMetricsAction = {\n type: `ProfileMetricsService:submitMetrics`;\n handler: ProfileMetricsService['submitMetrics'];\n};\n\n/**\n * Union of all ProfileMetricsService action types.\n */\nexport type ProfileMetricsServiceMethodActions =\n ProfileMetricsServiceSubmitMetricsAction;\n"]}
|
|
@@ -12,9 +12,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
12
12
|
};
|
|
13
13
|
var _a, _ProfileMetricsService_messenger, _ProfileMetricsService_fetch, _ProfileMetricsService_policy, _ProfileMetricsService_baseURL;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.ProfileMetricsService = exports.serviceName = void 0;
|
|
15
|
+
exports.getAuthUrl = exports.ProfileMetricsService = exports.serviceName = void 0;
|
|
16
16
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
17
|
-
const
|
|
17
|
+
const profile_sync_controller_1 = require("@metamask/profile-sync-controller");
|
|
18
18
|
// === GENERAL ===
|
|
19
19
|
/**
|
|
20
20
|
* The name of the {@link ProfileMetricsService}, used to namespace the
|
|
@@ -22,7 +22,7 @@ const _1 = require("./index.cjs");
|
|
|
22
22
|
*/
|
|
23
23
|
exports.serviceName = 'ProfileMetricsService';
|
|
24
24
|
// === MESSENGER ===
|
|
25
|
-
const MESSENGER_EXPOSED_METHODS = ['
|
|
25
|
+
const MESSENGER_EXPOSED_METHODS = ['submitMetrics'];
|
|
26
26
|
// === SERVICE DEFINITION ===
|
|
27
27
|
class ProfileMetricsService {
|
|
28
28
|
/**
|
|
@@ -38,7 +38,7 @@ class ProfileMetricsService {
|
|
|
38
38
|
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
39
39
|
* @param args.env - The environment to determine the correct API endpoints.
|
|
40
40
|
*/
|
|
41
|
-
constructor({ messenger, fetch: fetchFunction, policyOptions = {}, env =
|
|
41
|
+
constructor({ messenger, fetch: fetchFunction, policyOptions = {}, env = profile_sync_controller_1.SDK.Env.DEV, }) {
|
|
42
42
|
/**
|
|
43
43
|
* The messenger suited for this service.
|
|
44
44
|
*/
|
|
@@ -61,7 +61,7 @@ class ProfileMetricsService {
|
|
|
61
61
|
__classPrivateFieldSet(this, _ProfileMetricsService_messenger, messenger, "f");
|
|
62
62
|
__classPrivateFieldSet(this, _ProfileMetricsService_fetch, fetchFunction, "f");
|
|
63
63
|
__classPrivateFieldSet(this, _ProfileMetricsService_policy, (0, controller_utils_1.createServicePolicy)(policyOptions), "f");
|
|
64
|
-
__classPrivateFieldSet(this, _ProfileMetricsService_baseURL, (
|
|
64
|
+
__classPrivateFieldSet(this, _ProfileMetricsService_baseURL, getAuthUrl(env), "f");
|
|
65
65
|
__classPrivateFieldGet(this, _ProfileMetricsService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
@@ -112,12 +112,12 @@ class ProfileMetricsService {
|
|
|
112
112
|
return __classPrivateFieldGet(this, _ProfileMetricsService_policy, "f").onDegraded(listener);
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
115
|
+
* Submit metrics to the API.
|
|
116
116
|
*
|
|
117
|
-
* @param data - The data to send in the
|
|
117
|
+
* @param data - The data to send in the metrics update request.
|
|
118
118
|
* @returns The response from the API.
|
|
119
119
|
*/
|
|
120
|
-
async
|
|
120
|
+
async submitMetrics(data) {
|
|
121
121
|
const authToken = await __classPrivateFieldGet(this, _ProfileMetricsService_messenger, "f").call('AuthenticationController:getBearerToken', data.entropySourceId || undefined);
|
|
122
122
|
await __classPrivateFieldGet(this, _ProfileMetricsService_policy, "f").execute(async () => {
|
|
123
123
|
const url = new URL(`${__classPrivateFieldGet(this, _ProfileMetricsService_baseURL, "f")}/profile/accounts`);
|
|
@@ -141,4 +141,14 @@ class ProfileMetricsService {
|
|
|
141
141
|
}
|
|
142
142
|
exports.ProfileMetricsService = ProfileMetricsService;
|
|
143
143
|
_a = ProfileMetricsService, _ProfileMetricsService_messenger = new WeakMap(), _ProfileMetricsService_fetch = new WeakMap(), _ProfileMetricsService_policy = new WeakMap(), _ProfileMetricsService_baseURL = new WeakMap();
|
|
144
|
+
/**
|
|
145
|
+
* Returns the base URL for the given environment.
|
|
146
|
+
*
|
|
147
|
+
* @param env - The environment to get the URL for.
|
|
148
|
+
* @returns The base URL for the environment.
|
|
149
|
+
*/
|
|
150
|
+
function getAuthUrl(env) {
|
|
151
|
+
return `${profile_sync_controller_1.SDK.getEnvUrls(env).authApiUrl}/api/v2`;
|
|
152
|
+
}
|
|
153
|
+
exports.getAuthUrl = getAuthUrl;
|
|
144
154
|
//# sourceMappingURL=ProfileMetricsService.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetricsService.cjs","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,iEAA4E;
|
|
1
|
+
{"version":3,"file":"ProfileMetricsService.cjs","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n type AuthenticationController,\n SDK,\n} from '@metamask/profile-sync-controller';\n\nimport { type ProfileMetricsServiceMethodActions } from '.';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ProfileMetricsService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'ProfileMetricsService';\n\n/**\n * An account address along with its associated scopes.\n */\nexport type AccountWithScopes = {\n address: string;\n scopes: `${string}:${string}`[];\n};\n\n/**\n * The shape of the request object for submitting metrics.\n */\nexport type ProfileMetricsSubmitMetricsRequest = {\n metametricsId: string;\n entropySourceId?: string | null;\n accounts: AccountWithScopes[];\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['submitMetrics'] as const;\n\n/**\n * Actions that {@link ProfileMetricsService} exposes to other consumers.\n */\nexport type ProfileMetricsServiceActions = ProfileMetricsServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ProfileMetricsService} calls.\n */\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\n/**\n * Events that {@link ProfileMetricsService} exposes to other consumers.\n */\nexport type ProfileMetricsServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ProfileMetricsService} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ProfileMetricsService}.\n */\nexport type ProfileMetricsServiceMessenger = Messenger<\n typeof serviceName,\n ProfileMetricsServiceActions | AllowedActions,\n ProfileMetricsServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\nexport class ProfileMetricsService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: ConstructorParameters<\n typeof ProfileMetricsService\n >[0]['messenger'];\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: ConstructorParameters<\n typeof ProfileMetricsService\n >[0]['fetch'];\n\n /**\n * The policy that wraps the request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * The API base URL environment.\n */\n readonly #baseURL: string;\n\n /**\n * Constructs a new ProfileMetricsService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.fetch - A function that can be used to make an HTTP request. If\n * your JavaScript environment supports `fetch` natively, you'll probably want\n * to pass that; otherwise you can pass an equivalent (such as `fetch` via\n * `node-fetch`).\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n * @param args.env - The environment to determine the correct API endpoints.\n */\n constructor({\n messenger,\n fetch: fetchFunction,\n policyOptions = {},\n env = SDK.Env.DEV,\n }: {\n messenger: ProfileMetricsServiceMessenger;\n fetch: typeof fetch;\n policyOptions?: CreateServicePolicyOptions;\n env?: SDK.Env;\n }) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#policy = createServicePolicy(policyOptions);\n this.#baseURL = getAuthUrl(env);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry. Primarily useful in tests where timers are being\n * mocked.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]) {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]) {\n return this.#policy.onBreak(listener);\n }\n\n /* eslint-disable jsdoc/check-indentation */\n /**\n * Registers a handler that will be called under one of two circumstances:\n *\n * 1. After a set number of retries prove that requests to the API\n * consistently result in one of the following failures:\n * 1. A connection initiation error\n * 2. A connection reset error\n * 3. A timeout error\n * 4. A non-JSON response\n * 5. A 502, 503, or 504 response\n * 2. After a successful request is made to the API, but the response takes\n * longer than a set duration to return.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n */\n /* eslint-enable jsdoc/check-indentation */\n onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]) {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Submit metrics to the API.\n *\n * @param data - The data to send in the metrics update request.\n * @returns The response from the API.\n */\n async submitMetrics(data: ProfileMetricsSubmitMetricsRequest): Promise<void> {\n const authToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n data.entropySourceId || undefined,\n );\n await this.#policy.execute(async () => {\n const url = new URL(`${this.#baseURL}/profile/accounts`);\n const localResponse = await this.#fetch(url, {\n method: 'PUT',\n headers: {\n Authorization: `Bearer ${authToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n metametrics_id: data.metametricsId,\n accounts: data.accounts,\n }),\n });\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n }\n}\n\n/**\n * Returns the base URL for the given environment.\n *\n * @param env - The environment to get the URL for.\n * @returns The base URL for the environment.\n */\nexport function getAuthUrl(env: SDK.Env): string {\n return `${SDK.getEnvUrls(env).authApiUrl}/api/v2`;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
|
|
2
2
|
import type { Messenger } from "@metamask/messenger";
|
|
3
|
-
import type
|
|
4
|
-
import { type ProfileMetricsServiceMethodActions
|
|
3
|
+
import { type AuthenticationController, SDK } from "@metamask/profile-sync-controller";
|
|
4
|
+
import { type ProfileMetricsServiceMethodActions } from "./index.cjs";
|
|
5
5
|
/**
|
|
6
6
|
* The name of the {@link ProfileMetricsService}, used to namespace the
|
|
7
7
|
* service's actions and events.
|
|
@@ -15,9 +15,9 @@ export type AccountWithScopes = {
|
|
|
15
15
|
scopes: `${string}:${string}`[];
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
|
-
* The shape of the request object for
|
|
18
|
+
* The shape of the request object for submitting metrics.
|
|
19
19
|
*/
|
|
20
|
-
export type
|
|
20
|
+
export type ProfileMetricsSubmitMetricsRequest = {
|
|
21
21
|
metametricsId: string;
|
|
22
22
|
entropySourceId?: string | null;
|
|
23
23
|
accounts: AccountWithScopes[];
|
|
@@ -67,7 +67,7 @@ export declare class ProfileMetricsService {
|
|
|
67
67
|
messenger: ProfileMetricsServiceMessenger;
|
|
68
68
|
fetch: typeof fetch;
|
|
69
69
|
policyOptions?: CreateServicePolicyOptions;
|
|
70
|
-
env?: Env;
|
|
70
|
+
env?: SDK.Env;
|
|
71
71
|
});
|
|
72
72
|
/**
|
|
73
73
|
* Registers a handler that will be called after a request returns a non-500
|
|
@@ -109,12 +109,19 @@ export declare class ProfileMetricsService {
|
|
|
109
109
|
*/
|
|
110
110
|
onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]): import("cockatiel").IDisposable;
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
112
|
+
* Submit metrics to the API.
|
|
113
113
|
*
|
|
114
|
-
* @param data - The data to send in the
|
|
114
|
+
* @param data - The data to send in the metrics update request.
|
|
115
115
|
* @returns The response from the API.
|
|
116
116
|
*/
|
|
117
|
-
|
|
117
|
+
submitMetrics(data: ProfileMetricsSubmitMetricsRequest): Promise<void>;
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the base URL for the given environment.
|
|
121
|
+
*
|
|
122
|
+
* @param env - The environment to get the URL for.
|
|
123
|
+
* @returns The base URL for the environment.
|
|
124
|
+
*/
|
|
125
|
+
export declare function getAuthUrl(env: SDK.Env): string;
|
|
119
126
|
export {};
|
|
120
127
|
//# sourceMappingURL=ProfileMetricsService.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetricsService.d.cts","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ProfileMetricsService.d.cts","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,EACL,KAAK,wBAAwB,EAC7B,GAAG,EACJ,0CAA0C;AAE3C,OAAO,EAAE,KAAK,kCAAkC,EAAE,oBAAU;AAI5D;;;GAGG;AACH,eAAO,MAAM,WAAW,0BAA0B,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B,CAAC;AAMF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,kCAAkC,CAAC;AAE9E;;GAEG;AACH,KAAK,cAAc,GACjB,wBAAwB,CAAC,sCAAsC,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,OAAO,WAAW,EAClB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,CAC5C,CAAC;AAIF,qBAAa,qBAAqB;;IAChC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IA4BlC;;;;;;;;;;;;OAYG;gBACS,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,aAAkB,EAClB,GAAiB,GAClB,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;QAC3C,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC;KACf;IAaD;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAIzD;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAKzD;;;;;;;;;;;;;;;;OAgBG;IAEH,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAI/D;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,kCAAkC,GAAG,OAAO,CAAC,IAAI,CAAC;CA2B7E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,MAAM,CAE/C"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CreateServicePolicyOptions, ServicePolicy } from "@metamask/controller-utils";
|
|
2
2
|
import type { Messenger } from "@metamask/messenger";
|
|
3
|
-
import type
|
|
4
|
-
import { type ProfileMetricsServiceMethodActions
|
|
3
|
+
import { type AuthenticationController, SDK } from "@metamask/profile-sync-controller";
|
|
4
|
+
import { type ProfileMetricsServiceMethodActions } from "./index.mjs";
|
|
5
5
|
/**
|
|
6
6
|
* The name of the {@link ProfileMetricsService}, used to namespace the
|
|
7
7
|
* service's actions and events.
|
|
@@ -15,9 +15,9 @@ export type AccountWithScopes = {
|
|
|
15
15
|
scopes: `${string}:${string}`[];
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
|
-
* The shape of the request object for
|
|
18
|
+
* The shape of the request object for submitting metrics.
|
|
19
19
|
*/
|
|
20
|
-
export type
|
|
20
|
+
export type ProfileMetricsSubmitMetricsRequest = {
|
|
21
21
|
metametricsId: string;
|
|
22
22
|
entropySourceId?: string | null;
|
|
23
23
|
accounts: AccountWithScopes[];
|
|
@@ -67,7 +67,7 @@ export declare class ProfileMetricsService {
|
|
|
67
67
|
messenger: ProfileMetricsServiceMessenger;
|
|
68
68
|
fetch: typeof fetch;
|
|
69
69
|
policyOptions?: CreateServicePolicyOptions;
|
|
70
|
-
env?: Env;
|
|
70
|
+
env?: SDK.Env;
|
|
71
71
|
});
|
|
72
72
|
/**
|
|
73
73
|
* Registers a handler that will be called after a request returns a non-500
|
|
@@ -109,12 +109,19 @@ export declare class ProfileMetricsService {
|
|
|
109
109
|
*/
|
|
110
110
|
onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]): import("cockatiel").IDisposable;
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
112
|
+
* Submit metrics to the API.
|
|
113
113
|
*
|
|
114
|
-
* @param data - The data to send in the
|
|
114
|
+
* @param data - The data to send in the metrics update request.
|
|
115
115
|
* @returns The response from the API.
|
|
116
116
|
*/
|
|
117
|
-
|
|
117
|
+
submitMetrics(data: ProfileMetricsSubmitMetricsRequest): Promise<void>;
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Returns the base URL for the given environment.
|
|
121
|
+
*
|
|
122
|
+
* @param env - The environment to get the URL for.
|
|
123
|
+
* @returns The base URL for the environment.
|
|
124
|
+
*/
|
|
125
|
+
export declare function getAuthUrl(env: SDK.Env): string;
|
|
119
126
|
export {};
|
|
120
127
|
//# sourceMappingURL=ProfileMetricsService.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetricsService.d.mts","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"ProfileMetricsService.d.mts","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,EACL,KAAK,wBAAwB,EAC7B,GAAG,EACJ,0CAA0C;AAE3C,OAAO,EAAE,KAAK,kCAAkC,EAAE,oBAAU;AAI5D;;;GAGG;AACH,eAAO,MAAM,WAAW,0BAA0B,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B,CAAC;AAMF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,kCAAkC,CAAC;AAE9E;;GAEG;AACH,KAAK,cAAc,GACjB,wBAAwB,CAAC,sCAAsC,CAAC;AAElE;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEhD;;;GAGG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,8BAA8B,GAAG,SAAS,CACpD,OAAO,WAAW,EAClB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,CAC5C,CAAC;AAIF,qBAAa,qBAAqB;;IAChC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IA4BlC;;;;;;;;;;;;OAYG;gBACS,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,aAAkB,EAClB,GAAiB,GAClB,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;QAC3C,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC;KACf;IAaD;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAIzD;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAKzD;;;;;;;;;;;;;;;;OAgBG;IAEH,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAI/D;;;;;OAKG;IACG,aAAa,CAAC,IAAI,EAAE,kCAAkC,GAAG,OAAO,CAAC,IAAI,CAAC;CA2B7E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,MAAM,CAE/C"}
|
|
@@ -11,7 +11,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _a, _ProfileMetricsService_messenger, _ProfileMetricsService_fetch, _ProfileMetricsService_policy, _ProfileMetricsService_baseURL;
|
|
13
13
|
import { createServicePolicy, HttpError } from "@metamask/controller-utils";
|
|
14
|
-
import {
|
|
14
|
+
import { SDK } from "@metamask/profile-sync-controller";
|
|
15
15
|
// === GENERAL ===
|
|
16
16
|
/**
|
|
17
17
|
* The name of the {@link ProfileMetricsService}, used to namespace the
|
|
@@ -19,7 +19,7 @@ import { Env, getEnvUrl } from "./index.mjs";
|
|
|
19
19
|
*/
|
|
20
20
|
export const serviceName = 'ProfileMetricsService';
|
|
21
21
|
// === MESSENGER ===
|
|
22
|
-
const MESSENGER_EXPOSED_METHODS = ['
|
|
22
|
+
const MESSENGER_EXPOSED_METHODS = ['submitMetrics'];
|
|
23
23
|
// === SERVICE DEFINITION ===
|
|
24
24
|
export class ProfileMetricsService {
|
|
25
25
|
/**
|
|
@@ -35,7 +35,7 @@ export class ProfileMetricsService {
|
|
|
35
35
|
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
36
36
|
* @param args.env - The environment to determine the correct API endpoints.
|
|
37
37
|
*/
|
|
38
|
-
constructor({ messenger, fetch: fetchFunction, policyOptions = {}, env = Env.DEV, }) {
|
|
38
|
+
constructor({ messenger, fetch: fetchFunction, policyOptions = {}, env = SDK.Env.DEV, }) {
|
|
39
39
|
/**
|
|
40
40
|
* The messenger suited for this service.
|
|
41
41
|
*/
|
|
@@ -58,7 +58,7 @@ export class ProfileMetricsService {
|
|
|
58
58
|
__classPrivateFieldSet(this, _ProfileMetricsService_messenger, messenger, "f");
|
|
59
59
|
__classPrivateFieldSet(this, _ProfileMetricsService_fetch, fetchFunction, "f");
|
|
60
60
|
__classPrivateFieldSet(this, _ProfileMetricsService_policy, createServicePolicy(policyOptions), "f");
|
|
61
|
-
__classPrivateFieldSet(this, _ProfileMetricsService_baseURL,
|
|
61
|
+
__classPrivateFieldSet(this, _ProfileMetricsService_baseURL, getAuthUrl(env), "f");
|
|
62
62
|
__classPrivateFieldGet(this, _ProfileMetricsService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
@@ -109,12 +109,12 @@ export class ProfileMetricsService {
|
|
|
109
109
|
return __classPrivateFieldGet(this, _ProfileMetricsService_policy, "f").onDegraded(listener);
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
|
-
*
|
|
112
|
+
* Submit metrics to the API.
|
|
113
113
|
*
|
|
114
|
-
* @param data - The data to send in the
|
|
114
|
+
* @param data - The data to send in the metrics update request.
|
|
115
115
|
* @returns The response from the API.
|
|
116
116
|
*/
|
|
117
|
-
async
|
|
117
|
+
async submitMetrics(data) {
|
|
118
118
|
const authToken = await __classPrivateFieldGet(this, _ProfileMetricsService_messenger, "f").call('AuthenticationController:getBearerToken', data.entropySourceId || undefined);
|
|
119
119
|
await __classPrivateFieldGet(this, _ProfileMetricsService_policy, "f").execute(async () => {
|
|
120
120
|
const url = new URL(`${__classPrivateFieldGet(this, _ProfileMetricsService_baseURL, "f")}/profile/accounts`);
|
|
@@ -137,4 +137,13 @@ export class ProfileMetricsService {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
_a = ProfileMetricsService, _ProfileMetricsService_messenger = new WeakMap(), _ProfileMetricsService_fetch = new WeakMap(), _ProfileMetricsService_policy = new WeakMap(), _ProfileMetricsService_baseURL = new WeakMap();
|
|
140
|
+
/**
|
|
141
|
+
* Returns the base URL for the given environment.
|
|
142
|
+
*
|
|
143
|
+
* @param env - The environment to get the URL for.
|
|
144
|
+
* @returns The base URL for the environment.
|
|
145
|
+
*/
|
|
146
|
+
export function getAuthUrl(env) {
|
|
147
|
+
return `${SDK.getEnvUrls(env).authApiUrl}/api/v2`;
|
|
148
|
+
}
|
|
140
149
|
//# sourceMappingURL=ProfileMetricsService.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileMetricsService.mjs","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,mCAAmC;
|
|
1
|
+
{"version":3,"file":"ProfileMetricsService.mjs","sourceRoot":"","sources":["../src/ProfileMetricsService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,mCAAmC;AAE5E,OAAO,EAEL,GAAG,EACJ,0CAA0C;AAI3C,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,uBAAuB,CAAC;AAmBnD,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG,CAAC,eAAe,CAAU,CAAC;AAkC7D,6BAA6B;AAE7B,MAAM,OAAO,qBAAqB;IAgChC;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,aAAa,GAAG,EAAE,EAClB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,GAMlB;QAjDD;;WAEG;QACM,mDAES;QAElB;;WAEG;QACM,+CAEK;QAEd;;;;WAIG;QACM,gDAAuB;QAEhC;;WAEG;QACM,iDAAiB;QA0BxB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,uBAAA,IAAI,oCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,gCAAU,aAAa,MAAA,CAAC;QAC5B,uBAAA,IAAI,iCAAW,mBAAmB,CAAC,aAAa,CAAC,MAAA,CAAC;QAClD,uBAAA,IAAI,kCAAY,UAAU,CAAC,GAAG,CAAC,MAAA,CAAC;QAEhC,uBAAA,IAAI,wCAAW,CAAC,4BAA4B,CAC1C,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,OAAO,CAAC,QAAiD;QACvD,OAAO,uBAAA,IAAI,qCAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAiD;QACvD,OAAO,uBAAA,IAAI,qCAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,4CAA4C;IAC5C;;;;;;;;;;;;;;;;OAgBG;IACH,2CAA2C;IAC3C,UAAU,CAAC,QAAoD;QAC7D,OAAO,uBAAA,IAAI,qCAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,IAAwC;QAC1D,MAAM,SAAS,GAAG,MAAM,uBAAA,IAAI,wCAAW,CAAC,IAAI,CAC1C,yCAAyC,EACzC,IAAI,CAAC,eAAe,IAAI,SAAS,CAClC,CAAC;QACF,MAAM,uBAAA,IAAI,qCAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;YACpC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,uBAAA,IAAI,sCAAS,mBAAmB,CAAC,CAAC;YACzD,MAAM,aAAa,GAAG,MAAM,uBAAA,IAAI,oCAAO,MAAX,IAAI,EAAQ,GAAG,EAAE;gBAC3C,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,SAAS,EAAE;oBACpC,cAAc,EAAE,kBAAkB;iBACnC;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,cAAc,EAAE,IAAI,CAAC,aAAa;oBAClC,QAAQ,EAAE,IAAI,CAAC,QAAQ;iBACxB,CAAC;aACH,CAAC,CAAC;YACH,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;gBACtB,MAAM,IAAI,SAAS,CACjB,aAAa,CAAC,MAAM,EACpB,aAAa,GAAG,CAAC,QAAQ,EAAE,yBAAyB,aAAa,CAAC,MAAM,GAAG,CAC5E,CAAC;YACJ,CAAC;YACD,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAY;IACrC,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,UAAU,SAAS,CAAC;AACpD,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport {\n type AuthenticationController,\n SDK,\n} from '@metamask/profile-sync-controller';\n\nimport { type ProfileMetricsServiceMethodActions } from '.';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ProfileMetricsService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'ProfileMetricsService';\n\n/**\n * An account address along with its associated scopes.\n */\nexport type AccountWithScopes = {\n address: string;\n scopes: `${string}:${string}`[];\n};\n\n/**\n * The shape of the request object for submitting metrics.\n */\nexport type ProfileMetricsSubmitMetricsRequest = {\n metametricsId: string;\n entropySourceId?: string | null;\n accounts: AccountWithScopes[];\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = ['submitMetrics'] as const;\n\n/**\n * Actions that {@link ProfileMetricsService} exposes to other consumers.\n */\nexport type ProfileMetricsServiceActions = ProfileMetricsServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ProfileMetricsService} calls.\n */\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\n/**\n * Events that {@link ProfileMetricsService} exposes to other consumers.\n */\nexport type ProfileMetricsServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ProfileMetricsService} subscribes\n * to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link ProfileMetricsService}.\n */\nexport type ProfileMetricsServiceMessenger = Messenger<\n typeof serviceName,\n ProfileMetricsServiceActions | AllowedActions,\n ProfileMetricsServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\nexport class ProfileMetricsService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: ConstructorParameters<\n typeof ProfileMetricsService\n >[0]['messenger'];\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: ConstructorParameters<\n typeof ProfileMetricsService\n >[0]['fetch'];\n\n /**\n * The policy that wraps the request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * The API base URL environment.\n */\n readonly #baseURL: string;\n\n /**\n * Constructs a new ProfileMetricsService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.fetch - A function that can be used to make an HTTP request. If\n * your JavaScript environment supports `fetch` natively, you'll probably want\n * to pass that; otherwise you can pass an equivalent (such as `fetch` via\n * `node-fetch`).\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n * @param args.env - The environment to determine the correct API endpoints.\n */\n constructor({\n messenger,\n fetch: fetchFunction,\n policyOptions = {},\n env = SDK.Env.DEV,\n }: {\n messenger: ProfileMetricsServiceMessenger;\n fetch: typeof fetch;\n policyOptions?: CreateServicePolicyOptions;\n env?: SDK.Env;\n }) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#policy = createServicePolicy(policyOptions);\n this.#baseURL = getAuthUrl(env);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry. Primarily useful in tests where timers are being\n * mocked.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]) {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]) {\n return this.#policy.onBreak(listener);\n }\n\n /* eslint-disable jsdoc/check-indentation */\n /**\n * Registers a handler that will be called under one of two circumstances:\n *\n * 1. After a set number of retries prove that requests to the API\n * consistently result in one of the following failures:\n * 1. A connection initiation error\n * 2. A connection reset error\n * 3. A timeout error\n * 4. A non-JSON response\n * 5. A 502, 503, or 504 response\n * 2. After a successful request is made to the API, but the response takes\n * longer than a set duration to return.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler. See\n * {@link CockatielEvent}.\n */\n /* eslint-enable jsdoc/check-indentation */\n onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]) {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Submit metrics to the API.\n *\n * @param data - The data to send in the metrics update request.\n * @returns The response from the API.\n */\n async submitMetrics(data: ProfileMetricsSubmitMetricsRequest): Promise<void> {\n const authToken = await this.#messenger.call(\n 'AuthenticationController:getBearerToken',\n data.entropySourceId || undefined,\n );\n await this.#policy.execute(async () => {\n const url = new URL(`${this.#baseURL}/profile/accounts`);\n const localResponse = await this.#fetch(url, {\n method: 'PUT',\n headers: {\n Authorization: `Bearer ${authToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n metametrics_id: data.metametricsId,\n accounts: data.accounts,\n }),\n });\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n }\n}\n\n/**\n * Returns the base URL for the given environment.\n *\n * @param env - The environment to get the URL for.\n * @returns The base URL for the environment.\n */\nexport function getAuthUrl(env: SDK.Env): string {\n return `${SDK.getEnvUrls(env).authApiUrl}/api/v2`;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var ProfileMetricsController_1 = require("./ProfileMetricsController.cjs");
|
|
5
|
-
Object.defineProperty(exports, "ProfileMetricsController", { enumerable: true, get: function () { return ProfileMetricsController_1.ProfileMetricsController; } });
|
|
6
|
-
Object.defineProperty(exports, "getDefaultProfileMetricsControllerState", { enumerable: true, get: function () { return ProfileMetricsController_1.getDefaultProfileMetricsControllerState; } });
|
|
3
|
+
exports.serviceName = exports.ProfileMetricsService = void 0;
|
|
7
4
|
var ProfileMetricsService_1 = require("./ProfileMetricsService.cjs");
|
|
8
5
|
Object.defineProperty(exports, "ProfileMetricsService", { enumerable: true, get: function () { return ProfileMetricsService_1.ProfileMetricsService; } });
|
|
9
6
|
Object.defineProperty(exports, "serviceName", { enumerable: true, get: function () { return ProfileMetricsService_1.serviceName; } });
|
|
10
|
-
var constants_1 = require("./constants.cjs");
|
|
11
|
-
Object.defineProperty(exports, "getEnvUrl", { enumerable: true, get: function () { return constants_1.getEnvUrl; } });
|
|
12
|
-
Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return constants_1.Env; } });
|
|
13
7
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAMA,qEAA6E;AAApE,8HAAA,qBAAqB,OAAA;AAAE,oHAAA,WAAW,OAAA","sourcesContent":["export type {\n ProfileMetricsServiceActions,\n ProfileMetricsServiceEvents,\n ProfileMetricsServiceMessenger,\n ProfileMetricsSubmitMetricsRequest,\n} from './ProfileMetricsService';\nexport { ProfileMetricsService, serviceName } from './ProfileMetricsService';\nexport type { ProfileMetricsServiceMethodActions } from './ProfileMetricsService-method-action-types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export { ProfileMetricsController, getDefaultProfileMetricsControllerState, } from "./ProfileMetricsController.cjs";
|
|
3
|
-
export type { ProfileMetricsServiceActions, ProfileMetricsServiceEvents, ProfileMetricsServiceMessenger, ProfileMetricsUpdateRequest, } from "./ProfileMetricsService.cjs";
|
|
1
|
+
export type { ProfileMetricsServiceActions, ProfileMetricsServiceEvents, ProfileMetricsServiceMessenger, ProfileMetricsSubmitMetricsRequest, } from "./ProfileMetricsService.cjs";
|
|
4
2
|
export { ProfileMetricsService, serviceName } from "./ProfileMetricsService.cjs";
|
|
5
3
|
export type { ProfileMetricsServiceMethodActions } from "./ProfileMetricsService-method-action-types.cjs";
|
|
6
|
-
export { getEnvUrl, Env } from "./constants.cjs";
|
|
7
4
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,4BAA4B,EAC5B,2BAA2B,EAC3B,8BAA8B,EAC9B,kCAAkC,GACnC,oCAAgC;AACjC,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,oCAAgC;AAC7E,YAAY,EAAE,kCAAkC,EAAE,wDAAoD"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export type {
|
|
2
|
-
export { ProfileMetricsController, getDefaultProfileMetricsControllerState, } from "./ProfileMetricsController.mjs";
|
|
3
|
-
export type { ProfileMetricsServiceActions, ProfileMetricsServiceEvents, ProfileMetricsServiceMessenger, ProfileMetricsUpdateRequest, } from "./ProfileMetricsService.mjs";
|
|
1
|
+
export type { ProfileMetricsServiceActions, ProfileMetricsServiceEvents, ProfileMetricsServiceMessenger, ProfileMetricsSubmitMetricsRequest, } from "./ProfileMetricsService.mjs";
|
|
4
2
|
export { ProfileMetricsService, serviceName } from "./ProfileMetricsService.mjs";
|
|
5
3
|
export type { ProfileMetricsServiceMethodActions } from "./ProfileMetricsService-method-action-types.mjs";
|
|
6
|
-
export { getEnvUrl, Env } from "./constants.mjs";
|
|
7
4
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,4BAA4B,EAC5B,2BAA2B,EAC3B,8BAA8B,EAC9B,kCAAkC,GACnC,oCAAgC;AACjC,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,oCAAgC;AAC7E,YAAY,EAAE,kCAAkC,EAAE,wDAAoD"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export { ProfileMetricsController, getDefaultProfileMetricsControllerState } from "./ProfileMetricsController.mjs";
|
|
2
1
|
export { ProfileMetricsService, serviceName } from "./ProfileMetricsService.mjs";
|
|
3
|
-
export { getEnvUrl, Env } from "./constants.mjs";
|
|
4
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,oCAAgC","sourcesContent":["export type {\n ProfileMetricsServiceActions,\n ProfileMetricsServiceEvents,\n ProfileMetricsServiceMessenger,\n ProfileMetricsSubmitMetricsRequest,\n} from './ProfileMetricsService';\nexport { ProfileMetricsService, serviceName } from './ProfileMetricsService';\nexport type { ProfileMetricsServiceMethodActions } from './ProfileMetricsService-method-action-types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/profile-metrics-controller",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-a5935709",
|
|
4
4
|
"description": "Sample package to illustrate best practices for controllers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -48,19 +48,14 @@
|
|
|
48
48
|
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@metamask/accounts-controller": "^35.0.0",
|
|
52
51
|
"@metamask/base-controller": "^9.0.0",
|
|
53
52
|
"@metamask/controller-utils": "^11.16.0",
|
|
54
|
-
"@metamask/keyring-controller": "^25.0.0",
|
|
55
53
|
"@metamask/messenger": "^0.3.0",
|
|
56
|
-
"@metamask/polling-controller": "^16.0.0",
|
|
57
54
|
"@metamask/profile-sync-controller": "^27.0.0",
|
|
58
|
-
"@metamask/utils": "^11.8.1"
|
|
59
|
-
"async-mutex": "^0.5.0"
|
|
55
|
+
"@metamask/utils": "^11.8.1"
|
|
60
56
|
},
|
|
61
57
|
"devDependencies": {
|
|
62
58
|
"@metamask/auto-changelog": "^3.4.4",
|
|
63
|
-
"@metamask/keyring-internal-api": "^9.0.0",
|
|
64
59
|
"@ts-bridge/cli": "^0.6.4",
|
|
65
60
|
"@types/jest": "^27.4.1",
|
|
66
61
|
"deepmerge": "^4.2.2",
|