@metamask-previews/analytics-data-regulation-controller 0.0.0-preview-eb6c0745c → 0.0.0-preview-76b7c67

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,16 +7,31 @@ 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 `AnalyticsDataRegulationServiceInvalidateQueriesAction`, `AnalyticsDataRegulationServiceCacheUpdatedEvent` and `AnalyticsDataRegulationServiceGranularCacheUpdatedEvent`, also included in `AnalyticsDataRegulationServiceActions` and `AnalyticsDataRegulationServiceEvents` ([#10879](https://github.com/MetaMask/core/pull/10879))
13
+ - Add support for Node.js 26 ([#10981](https://github.com/MetaMask/core/pull/10981))
14
+
10
15
  ### Changed
11
16
 
17
+ - **BREAKING:** `AnalyticsDataRegulationService` now extends `BaseDataService` from `@metamask/base-data-service` ([#10879](https://github.com/MetaMask/core/pull/10879))
18
+ - `AnalyticsDataRegulationServiceMessenger` now includes the `:invalidateQueries` action and `:cacheUpdated` events. Messengers built from `AnalyticsDataRegulationServiceActions` / `AnalyticsDataRegulationServiceEvents` pick these up automatically.
12
19
  - **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
13
20
  - This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
14
21
  - **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
15
22
  - **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
16
23
  - This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
17
- - Bump `@metamask/utils` from `^11.9.0` to `^12.0.0` ([#9074](https://github.com/MetaMask/core/pull/9074), [#10076](https://github.com/MetaMask/core/pull/10076), [#10192](https://github.com/MetaMask/core/pull/10192))
24
+ - `createDataDeletionTask` no longer retries on 5xx responses ([#10879](https://github.com/MetaMask/core/pull/10879))
25
+ - Concurrent `checkDataDeleteStatus` calls for the same regulation ID now share one request ([#10879](https://github.com/MetaMask/core/pull/10879))
26
+ - A malformed `createDataDeletionTask` response now throws `Mutation function for "AnalyticsDataRegulationService:createDataDeletionTask" returned an unexpected response: …` ([#10879](https://github.com/MetaMask/core/pull/10879), [#11213](https://github.com/MetaMask/core/pull/11213))
27
+ - Add dependencies `@metamask/base-data-service` and `@metamask/superstruct` ([#10879](https://github.com/MetaMask/core/pull/10879))
28
+ - Bump `@metamask/utils` from `^11.9.0` to `^12.0.2` ([#9074](https://github.com/MetaMask/core/pull/9074), [#10076](https://github.com/MetaMask/core/pull/10076), [#10192](https://github.com/MetaMask/core/pull/10192), [#11107](https://github.com/MetaMask/core/pull/11107), [#11474](https://github.com/MetaMask/core/pull/11474))
18
29
  - Bump `@metamask/controller-utils` from `^11.19.0` to `^13.0.0` ([#8344](https://github.com/MetaMask/core/pull/8344), [#8755](https://github.com/MetaMask/core/pull/8755), [#8774](https://github.com/MetaMask/core/pull/8774), [#9058](https://github.com/MetaMask/core/pull/9058), [#9083](https://github.com/MetaMask/core/pull/9083), [#9218](https://github.com/MetaMask/core/pull/9218), [#10160](https://github.com/MetaMask/core/pull/10160))
19
30
  - Bump `@metamask/messenger` from `^1.1.0` to `^3.0.0` ([#8373](https://github.com/MetaMask/core/pull/8373), [#8632](https://github.com/MetaMask/core/pull/8632), [#9392](https://github.com/MetaMask/core/pull/9392), [#10160](https://github.com/MetaMask/core/pull/10160))
20
31
  - Bump `@metamask/base-controller` from `^9.0.1` to `^10.1.0` ([#8457](https://github.com/MetaMask/core/pull/8457), [#10160](https://github.com/MetaMask/core/pull/10160), [#10864](https://github.com/MetaMask/core/pull/10864))
21
32
 
33
+ ### Removed
34
+
35
+ - **BREAKING:** Remove `onRetry`, `onBreak` and `onDegraded` from `AnalyticsDataRegulationService` ([#10879](https://github.com/MetaMask/core/pull/10879))
36
+
22
37
  [Unreleased]: https://github.com/MetaMask/core/
@@ -1,6 +1,6 @@
1
- import type { CreateServicePolicyOptions, ServicePolicy } from '@metamask/controller-utils';
1
+ import { BaseDataService } from '@metamask/base-data-service';
2
+ import type { CreateServicePolicyOptions, DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from '@metamask/base-data-service';
2
3
  import type { Messenger } from '@metamask/messenger';
3
- import type { IDisposable } from 'cockatiel';
4
4
  import type { AnalyticsDataRegulationServiceMethodActions } from './AnalyticsDataRegulationService-method-action-types.js';
5
5
  import { DATA_DELETE_RESPONSE_STATUSES } from './types.js';
6
6
  import type { DataDeleteStatus } from './types.js';
@@ -9,18 +9,31 @@ import type { DataDeleteStatus } from './types.js';
9
9
  * service's actions and events.
10
10
  */
11
11
  export declare const serviceName = "AnalyticsDataRegulationService";
12
+ /**
13
+ * Invalidates cached queries for {@link AnalyticsDataRegulationService}.
14
+ */
15
+ export type AnalyticsDataRegulationServiceInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
12
16
  /**
13
17
  * Actions that {@link AnalyticsDataRegulationService} exposes to other consumers.
14
18
  */
15
- export type AnalyticsDataRegulationServiceActions = AnalyticsDataRegulationServiceMethodActions;
19
+ export type AnalyticsDataRegulationServiceActions = AnalyticsDataRegulationServiceMethodActions | AnalyticsDataRegulationServiceInvalidateQueriesAction;
16
20
  /**
17
21
  * Actions from other messengers that {@link AnalyticsDataRegulationServiceMessenger} calls.
18
22
  */
19
23
  type AllowedActions = never;
24
+ /**
25
+ * Published when {@link AnalyticsDataRegulationService}'s cache is updated.
26
+ */
27
+ export type AnalyticsDataRegulationServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<typeof serviceName>;
28
+ /**
29
+ * Published when a key within {@link AnalyticsDataRegulationService}'s cache is
30
+ * updated.
31
+ */
32
+ export type AnalyticsDataRegulationServiceGranularCacheUpdatedEvent = DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
20
33
  /**
21
34
  * Events that {@link AnalyticsDataRegulationService} exposes to other consumers.
22
35
  */
23
- export type AnalyticsDataRegulationServiceEvents = never;
36
+ export type AnalyticsDataRegulationServiceEvents = AnalyticsDataRegulationServiceCacheUpdatedEvent | AnalyticsDataRegulationServiceGranularCacheUpdatedEvent;
24
37
  /**
25
38
  * Events from other messengers that {@link AnalyticsDataRegulationService} subscribes to.
26
39
  */
@@ -66,10 +79,12 @@ export type AnalyticsDataRegulationServiceOptions = {
66
79
  * @example
67
80
  *
68
81
  * ```ts
82
+ * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';
69
83
  * import { Messenger } from '@metamask/messenger';
70
84
  * import type {
71
85
  * AnalyticsDataRegulationServiceActions,
72
86
  * AnalyticsDataRegulationServiceEvents,
87
+ * AnalyticsDataRegulationServiceMessenger,
73
88
  * } from '@metamask/analytics-data-regulation-controller';
74
89
  *
75
90
  * const rootMessenger = new Messenger<
@@ -79,8 +94,8 @@ export type AnalyticsDataRegulationServiceOptions = {
79
94
  * >({ namespace: 'Root' });
80
95
  * const serviceMessenger = new Messenger<
81
96
  * 'AnalyticsDataRegulationService',
82
- * AnalyticsDataRegulationServiceActions,
83
- * AnalyticsDataRegulationServiceEvents,
97
+ * MessengerActions<AnalyticsDataRegulationServiceMessenger>,
98
+ * MessengerEvents<AnalyticsDataRegulationServiceMessenger>,
84
99
  * typeof rootMessenger,
85
100
  * >({
86
101
  * namespace: 'AnalyticsDataRegulationService',
@@ -102,49 +117,14 @@ export type AnalyticsDataRegulationServiceOptions = {
102
117
  * );
103
118
  * ```
104
119
  */
105
- export declare class AnalyticsDataRegulationService {
120
+ export declare class AnalyticsDataRegulationService extends BaseDataService<typeof serviceName, AnalyticsDataRegulationServiceMessenger> {
106
121
  #private;
107
- /**
108
- * The name of the service.
109
- */
110
- readonly name: typeof serviceName;
111
122
  /**
112
123
  * Constructs a new AnalyticsDataRegulationService object.
113
124
  *
114
125
  * @param options - The constructor options.
115
126
  */
116
127
  constructor(options: AnalyticsDataRegulationServiceOptions);
117
- /**
118
- * Registers a handler that will be called after a request returns a non-500
119
- * response, causing a retry. Primarily useful in tests where timers are being
120
- * mocked.
121
- *
122
- * @param listener - The handler to be called.
123
- * @returns An object that can be used to unregister the handler.
124
- * @see {@link createServicePolicy}
125
- */
126
- onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable;
127
- /**
128
- * Registers a handler that will be called after a set number of retry rounds
129
- * prove that requests to the API endpoint consistently return a 5xx response.
130
- *
131
- * @param listener - The handler to be called.
132
- * @returns An object that can be used to unregister the handler.
133
- * @see {@link createServicePolicy}
134
- */
135
- onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable;
136
- /**
137
- * Registers a handler that will be called under one of two circumstances:
138
- *
139
- * 1. After a set number of retries prove that requests to the API
140
- * consistently result in failures.
141
- * 2. After a successful request is made to the API, but the response takes
142
- * longer than a set duration to return.
143
- *
144
- * @param listener - The handler to be called.
145
- * @returns An object that can be used to unregister the handler.
146
- */
147
- onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]): IDisposable;
148
128
  /**
149
129
  * Creates a DELETE_ONLY regulation for the given analyticsId.
150
130
  *
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsDataRegulationService.d.ts","sourceRoot":"","sources":["../src/AnalyticsDataRegulationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EAAE,2CAA2C,EAAE,MAAM,yDAAyD,CAAC;AAC3H,OAAO,EACL,6BAA6B,EAE9B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAmBnD;;;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Error } from '@metamask/controller-utils';
1
+ import { BaseDataService } from '@metamask/base-data-service';
2
+ import { HttpError } from '@metamask/controller-utils';
3
+ import { refine, string, type } from '@metamask/superstruct';
2
4
  import { DATA_DELETE_RESPONSE_STATUSES, DATA_DELETE_STATUSES, } from './types.js';
3
5
  /**
4
6
  * Segment API regulation type for DELETE_ONLY operations.
@@ -23,6 +25,21 @@ const MESSENGER_EXPOSED_METHODS = [
23
25
  'createDataDeletionTask',
24
26
  'checkDataDeleteStatus',
25
27
  ];
28
+ // === SERVICE DEFINITION ===
29
+ /**
30
+ * A string that is non-empty once trimmed.
31
+ */
32
+ const NonEmptyStringStruct = refine(string(), 'NonEmptyString', (value) => value.trim() !== '');
33
+ /**
34
+ * Response structure from Segment API for creating a regulation.
35
+ */
36
+ const CreateRegulationResponseStruct = type({
37
+ data: type({
38
+ data: type({
39
+ regulateId: NonEmptyStringStruct,
40
+ }),
41
+ }),
42
+ });
26
43
  /**
27
44
  * Type guard to check if a value is a valid DataDeleteStatus.
28
45
  *
@@ -40,10 +57,12 @@ function isDataDeleteStatus(status) {
40
57
  * @example
41
58
  *
42
59
  * ```ts
60
+ * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';
43
61
  * import { Messenger } from '@metamask/messenger';
44
62
  * import type {
45
63
  * AnalyticsDataRegulationServiceActions,
46
64
  * AnalyticsDataRegulationServiceEvents,
65
+ * AnalyticsDataRegulationServiceMessenger,
47
66
  * } from '@metamask/analytics-data-regulation-controller';
48
67
  *
49
68
  * const rootMessenger = new Messenger<
@@ -53,8 +72,8 @@ function isDataDeleteStatus(status) {
53
72
  * >({ namespace: 'Root' });
54
73
  * const serviceMessenger = new Messenger<
55
74
  * 'AnalyticsDataRegulationService',
56
- * AnalyticsDataRegulationServiceActions,
57
- * AnalyticsDataRegulationServiceEvents,
75
+ * MessengerActions<AnalyticsDataRegulationServiceMessenger>,
76
+ * MessengerEvents<AnalyticsDataRegulationServiceMessenger>,
58
77
  * typeof rootMessenger,
59
78
  * >({
60
79
  * namespace: 'AnalyticsDataRegulationService',
@@ -76,15 +95,7 @@ function isDataDeleteStatus(status) {
76
95
  * );
77
96
  * ```
78
97
  */
79
- export class AnalyticsDataRegulationService {
80
- /**
81
- * The name of the service.
82
- */
83
- name;
84
- /**
85
- * The messenger suited for this service.
86
- */
87
- #messenger;
98
+ export class AnalyticsDataRegulationService extends BaseDataService {
88
99
  /**
89
100
  * A function that can be used to make an HTTP request.
90
101
  */
@@ -98,62 +109,21 @@ export class AnalyticsDataRegulationService {
98
109
  * This endpoint varies by environment and forwards requests to Segment API with authentication.
99
110
  */
100
111
  #segmentRegulationsEndpoint;
101
- /**
102
- * The policy that wraps the request.
103
- *
104
- * @see {@link createServicePolicy}
105
- */
106
- #policy;
107
112
  /**
108
113
  * Constructs a new AnalyticsDataRegulationService object.
109
114
  *
110
115
  * @param options - The constructor options.
111
116
  */
112
117
  constructor(options) {
113
- this.name = serviceName;
114
- this.#messenger = options.messenger;
118
+ super({
119
+ name: serviceName,
120
+ messenger: options.messenger,
121
+ policyOptions: options.policyOptions,
122
+ });
115
123
  this.#fetch = options.fetch;
116
124
  this.#segmentSourceId = options.segmentSourceId;
117
125
  this.#segmentRegulationsEndpoint = options.segmentRegulationsEndpoint;
118
- this.#policy = createServicePolicy(options.policyOptions ?? {});
119
- this.#messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
120
- }
121
- /**
122
- * Registers a handler that will be called after a request returns a non-500
123
- * response, causing a retry. Primarily useful in tests where timers are being
124
- * mocked.
125
- *
126
- * @param listener - The handler to be called.
127
- * @returns An object that can be used to unregister the handler.
128
- * @see {@link createServicePolicy}
129
- */
130
- onRetry(listener) {
131
- return this.#policy.onRetry(listener);
132
- }
133
- /**
134
- * Registers a handler that will be called after a set number of retry rounds
135
- * prove that requests to the API endpoint consistently return a 5xx response.
136
- *
137
- * @param listener - The handler to be called.
138
- * @returns An object that can be used to unregister the handler.
139
- * @see {@link createServicePolicy}
140
- */
141
- onBreak(listener) {
142
- return this.#policy.onBreak(listener);
143
- }
144
- /**
145
- * Registers a handler that will be called under one of two circumstances:
146
- *
147
- * 1. After a set number of retries prove that requests to the API
148
- * consistently result in failures.
149
- * 2. After a successful request is made to the API, but the response takes
150
- * longer than a set duration to return.
151
- *
152
- * @param listener - The handler to be called.
153
- * @returns An object that can be used to unregister the handler.
154
- */
155
- onDegraded(listener) {
156
- return this.#policy.onDegraded(listener);
126
+ this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
157
127
  }
158
128
  /**
159
129
  * Creates a DELETE_ONLY regulation for the given analyticsId.
@@ -167,30 +137,28 @@ export class AnalyticsDataRegulationService {
167
137
  throw new Error('Segment API source ID or endpoint not found');
168
138
  }
169
139
  const url = `${this.#segmentRegulationsEndpoint}/regulations/sources/${this.#segmentSourceId}`;
170
- const body = JSON.stringify({
171
- regulationType: SEGMENT_REGULATION_TYPE_DELETE_ONLY,
172
- subjectType: SEGMENT_SUBJECT_TYPE_USER_ID,
173
- subjectIds: [analyticsId],
174
- });
175
- const response = await this.#policy.execute(async () => {
176
- const localResponse = await this.#fetch(url, {
177
- method: 'POST',
178
- headers: {
179
- 'Content-Type': SEGMENT_CONTENT_TYPE,
180
- },
181
- body,
182
- });
183
- if (!localResponse.ok) {
184
- throw new HttpError(localResponse.status, `Creating data deletion task failed with status '${localResponse.status}'`);
185
- }
186
- return localResponse;
140
+ const jsonResponse = await this.executeMutation({
141
+ mutationKey: [`${this.name}:createDataDeletionTask`],
142
+ gcTime: 0,
143
+ responseStruct: CreateRegulationResponseStruct,
144
+ mutationFn: async () => {
145
+ const response = await this.#fetch(url, {
146
+ method: 'POST',
147
+ headers: {
148
+ 'Content-Type': SEGMENT_CONTENT_TYPE,
149
+ },
150
+ body: JSON.stringify({
151
+ regulationType: SEGMENT_REGULATION_TYPE_DELETE_ONLY,
152
+ subjectType: SEGMENT_SUBJECT_TYPE_USER_ID,
153
+ subjectIds: [analyticsId],
154
+ }),
155
+ });
156
+ if (!response.ok) {
157
+ throw new HttpError(response.status, `Creating data deletion task failed with status '${response.status}'`);
158
+ }
159
+ return (await response.json());
160
+ },
187
161
  });
188
- const jsonResponse = (await response.json());
189
- if (!jsonResponse?.data?.data?.regulateId ||
190
- typeof jsonResponse.data.data.regulateId !== 'string' ||
191
- jsonResponse.data.data.regulateId.trim() === '') {
192
- throw new Error('Malformed response from Segment API: missing or invalid regulateId');
193
- }
194
162
  return {
195
163
  status: DATA_DELETE_RESPONSE_STATUSES.Success,
196
164
  regulateId: jsonResponse.data.data.regulateId,
@@ -208,27 +176,30 @@ export class AnalyticsDataRegulationService {
208
176
  throw new Error('Regulation ID or endpoint not configured');
209
177
  }
210
178
  const url = `${this.#segmentRegulationsEndpoint}/regulations/${regulationId}`;
211
- const response = await this.#policy.execute(async () => {
212
- const localResponse = await this.#fetch(url, {
213
- method: 'GET',
214
- headers: {
215
- 'Content-Type': SEGMENT_CONTENT_TYPE,
216
- },
217
- });
218
- if (!localResponse.ok) {
219
- throw new HttpError(localResponse.status, `Checking data deletion status failed with status '${localResponse.status}'`);
220
- }
221
- return localResponse;
179
+ return this.fetchQuery({
180
+ queryKey: [`${this.name}:checkDataDeleteStatus`, regulationId],
181
+ staleTime: 0,
182
+ gcTime: 0,
183
+ queryFn: async () => {
184
+ const response = await this.#fetch(url, {
185
+ method: 'GET',
186
+ headers: {
187
+ 'Content-Type': SEGMENT_CONTENT_TYPE,
188
+ },
189
+ });
190
+ if (!response.ok) {
191
+ throw new HttpError(response.status, `Checking data deletion status failed with status '${response.status}'`);
192
+ }
193
+ const jsonResponse = (await response.json());
194
+ const rawStatus = jsonResponse?.data?.data?.regulation?.overallStatus;
195
+ return {
196
+ status: DATA_DELETE_RESPONSE_STATUSES.Success,
197
+ dataDeleteStatus: isDataDeleteStatus(rawStatus)
198
+ ? rawStatus
199
+ : DATA_DELETE_STATUSES.Unknown,
200
+ };
201
+ },
222
202
  });
223
- const jsonResponse = (await response.json());
224
- const rawStatus = jsonResponse?.data?.data?.regulation?.overallStatus;
225
- const dataDeleteStatus = isDataDeleteStatus(rawStatus)
226
- ? rawStatus
227
- : DATA_DELETE_STATUSES.Unknown;
228
- return {
229
- status: DATA_DELETE_RESPONSE_STATUSES.Success,
230
- dataDeleteStatus,
231
- };
232
203
  }
233
204
  }
234
205
  //# sourceMappingURL=AnalyticsDataRegulationService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsDataRegulationService.js","sourceRoot":"","sources":["../src/AnalyticsDataRegulationService.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAK5E,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,MAAM,mCAAmC,GAAG,aAAa,CAAC;AAE1D;;GAEG;AACH,MAAM,4BAA4B,GAAG,SAAS,CAAC;AAE/C;;GAEG;AACH,MAAM,oBAAoB,GAAG,iCAAiC,CAAC;AAE/D,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,gCAAgC,CAAC;AAE5D,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,wBAAwB;IACxB,uBAAuB;CACf,CAAC;AA6FX;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,MAAM,kBAAkB,GAAa,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;IACzE,OAAO,kBAAkB,CAAC,QAAQ,CAAC,MAAgB,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,OAAO,8BAA8B;IACzC;;OAEG;IACM,IAAI,CAAqB;IAElC;;OAEG;IACM,UAAU,CAA0C;IAE7D;;OAEG;IACM,MAAM,CAAe;IAE9B;;OAEG;IACM,gBAAgB,CAAS;IAElC;;;OAGG;IACM,2BAA2B,CAAS;IAE7C;;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9D,CAAC;QAED,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,2BAA2B,gBAAgB,YAAY,EAAE,CAAC;QAE9E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE;YACrD,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE;gBAC3C,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACP,cAAc,EAAE,oBAAoB;iBACrC;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;gBACtB,MAAM,IAAI,SAAS,CACjB,aAAa,CAAC,MAAM,EACpB,qDAAqD,aAAa,CAAC,MAAM,GAAG,CAC7E,CAAC;YACJ,CAAC;YAED,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAgC,CAAC;QAE5E,MAAM,SAAS,GAAG,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,CAAC;QACtE,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,SAAS,CAAC;YACpD,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC;QAEjC,OAAO;YACL,MAAM,EAAE,6BAA6B,CAAC,OAAO;YAC7C,gBAAgB;SACjB,CAAC;IACJ,CAAC;CACF","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 type { IDisposable } from 'cockatiel';\n\nimport type { AnalyticsDataRegulationServiceMethodActions } from './AnalyticsDataRegulationService-method-action-types.js';\nimport {\n DATA_DELETE_RESPONSE_STATUSES,\n DATA_DELETE_STATUSES,\n} from './types.js';\nimport type { DataDeleteStatus } from './types.js';\n\n/**\n * Segment API regulation type for DELETE_ONLY operations.\n */\nconst SEGMENT_REGULATION_TYPE_DELETE_ONLY = 'DELETE_ONLY';\n\n/**\n * Segment API subject type for user ID operations.\n */\nconst SEGMENT_SUBJECT_TYPE_USER_ID = 'USER_ID';\n\n/**\n * Segment API Content-Type header value.\n */\nconst SEGMENT_CONTENT_TYPE = 'application/vnd.segment.v1+json';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link AnalyticsDataRegulationService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'AnalyticsDataRegulationService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'createDataDeletionTask',\n 'checkDataDeleteStatus',\n] as const;\n\n/**\n * Actions that {@link AnalyticsDataRegulationService} exposes to other consumers.\n */\nexport type AnalyticsDataRegulationServiceActions =\n AnalyticsDataRegulationServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link AnalyticsDataRegulationServiceMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link AnalyticsDataRegulationService} exposes to other consumers.\n */\nexport type AnalyticsDataRegulationServiceEvents = never;\n\n/**\n * Events from other messengers that {@link AnalyticsDataRegulationService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link AnalyticsDataRegulationService}.\n */\nexport type AnalyticsDataRegulationServiceMessenger = Messenger<\n typeof serviceName,\n AnalyticsDataRegulationServiceActions | AllowedActions,\n AnalyticsDataRegulationServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * Response structure from Segment API for creating a regulation.\n */\ntype CreateRegulationResponse = {\n data: {\n data: {\n regulateId: string;\n };\n };\n};\n\n/**\n * Response structure from Segment API for getting regulation status.\n */\ntype GetRegulationStatusResponse = {\n data: {\n data: {\n regulation: {\n overallStatus: string;\n };\n };\n };\n};\n\n/**\n * Options for constructing {@link AnalyticsDataRegulationService}.\n */\nexport type AnalyticsDataRegulationServiceOptions = {\n /**\n * The messenger suited for this service.\n */\n messenger: AnalyticsDataRegulationServiceMessenger;\n\n /**\n * A function that can be used to make an HTTP request.\n */\n fetch: typeof fetch;\n\n /**\n * Segment API source ID (required for creating regulations).\n */\n segmentSourceId: string;\n\n /**\n * Base URL for the proxy endpoint that communicates with Segment's Regulations API.\n * This is a proxy endpoint (not Segment API directly) that forwards requests to Segment's\n * Regulations API and adds authentication tokens. The endpoint URL varies by environment\n * (e.g., development, staging, production) and should be configured accordingly.\n * Example: 'https://proxy.example.com/v1beta'\n */\n segmentRegulationsEndpoint: string;\n\n /**\n * Options to pass to `createServicePolicy`, which is used to wrap each request.\n */\n policyOptions?: CreateServicePolicyOptions;\n};\n\n/**\n * Type guard to check if a value is a valid DataDeleteStatus.\n *\n * @param status - The value to check.\n * @returns True if the value is a valid DataDeleteStatus.\n */\nfunction isDataDeleteStatus(status: unknown): status is DataDeleteStatus {\n const dataDeleteStatuses: string[] = Object.values(DATA_DELETE_STATUSES);\n return dataDeleteStatuses.includes(status as string);\n}\n\n/**\n * This service object is responsible for making requests to the Segment Regulations API\n * via a proxy endpoint for GDPR/CCPA data deletion functionality.\n *\n * @example\n *\n * ```ts\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * AnalyticsDataRegulationServiceActions,\n * AnalyticsDataRegulationServiceEvents,\n * } from '@metamask/analytics-data-regulation-controller';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * AnalyticsDataRegulationServiceActions,\n * AnalyticsDataRegulationServiceEvents\n * >({ namespace: 'Root' });\n * const serviceMessenger = new Messenger<\n * 'AnalyticsDataRegulationService',\n * AnalyticsDataRegulationServiceActions,\n * AnalyticsDataRegulationServiceEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'AnalyticsDataRegulationService',\n * parent: rootMessenger,\n * });\n * // Instantiate the service to register its actions on the messenger\n * new AnalyticsDataRegulationService({\n * messenger: serviceMessenger,\n * fetch,\n * segmentSourceId: 'abc123',\n * segmentRegulationsEndpoint: 'https://proxy.example.com/v1beta',\n * });\n *\n * // Later...\n * // Create a data deletion task\n * const response = await rootMessenger.call(\n * 'AnalyticsDataRegulationService:createDataDeletionTask',\n * 'user-analytics-id',\n * );\n * ```\n */\nexport class AnalyticsDataRegulationService {\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: AnalyticsDataRegulationServiceMessenger;\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: typeof fetch;\n\n /**\n * Segment API source ID.\n */\n readonly #segmentSourceId: string;\n\n /**\n * Base URL for the proxy endpoint that communicates with Segment's Regulations API.\n * This endpoint varies by environment and forwards requests to Segment API with authentication.\n */\n readonly #segmentRegulationsEndpoint: string;\n\n /**\n * The policy that wraps the request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new AnalyticsDataRegulationService object.\n *\n * @param options - The constructor options.\n */\n constructor(options: AnalyticsDataRegulationServiceOptions) {\n this.name = serviceName;\n this.#messenger = options.messenger;\n this.#fetch = options.fetch;\n this.#segmentSourceId = options.segmentSourceId;\n this.#segmentRegulationsEndpoint = options.segmentRegulationsEndpoint;\n this.#policy = createServicePolicy(options.policyOptions ?? {});\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.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\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.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak(listener);\n }\n\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 failures.\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.\n */\n onDegraded(\n listener: Parameters<ServicePolicy['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Creates a DELETE_ONLY regulation for the given analyticsId.\n *\n * @param analyticsId - The analytics ID of the user for whom to create the deletion task.\n * @returns Promise resolving to a successful deletion regulation response.\n * @throws Error if the request fails or the response is invalid.\n */\n async createDataDeletionTask(analyticsId: string): Promise<{\n status: typeof DATA_DELETE_RESPONSE_STATUSES.Success;\n regulateId: string;\n }> {\n if (!this.#segmentSourceId || !this.#segmentRegulationsEndpoint) {\n throw new Error('Segment API source ID or endpoint not found');\n }\n\n const url = `${this.#segmentRegulationsEndpoint}/regulations/sources/${this.#segmentSourceId}`;\n const body = JSON.stringify({\n regulationType: SEGMENT_REGULATION_TYPE_DELETE_ONLY,\n subjectType: SEGMENT_SUBJECT_TYPE_USER_ID,\n subjectIds: [analyticsId],\n });\n\n const response = await this.#policy.execute(async () => {\n const localResponse = await this.#fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': SEGMENT_CONTENT_TYPE,\n },\n body,\n });\n\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Creating data deletion task failed with status '${localResponse.status}'`,\n );\n }\n\n return localResponse;\n });\n\n const jsonResponse = (await response.json()) as CreateRegulationResponse;\n\n if (\n !jsonResponse?.data?.data?.regulateId ||\n typeof jsonResponse.data.data.regulateId !== 'string' ||\n jsonResponse.data.data.regulateId.trim() === ''\n ) {\n throw new Error(\n 'Malformed response from Segment API: missing or invalid regulateId',\n );\n }\n\n return {\n status: DATA_DELETE_RESPONSE_STATUSES.Success,\n regulateId: jsonResponse.data.data.regulateId,\n };\n }\n\n /**\n * Checks the status of a regulation by ID.\n *\n * @param regulationId - The regulation ID to check.\n * @returns Promise resolving to a successful regulation status response.\n * @throws Error if the request fails or the response is invalid.\n */\n async checkDataDeleteStatus(regulationId: string): Promise<{\n status: typeof DATA_DELETE_RESPONSE_STATUSES.Success;\n dataDeleteStatus: DataDeleteStatus;\n }> {\n if (!regulationId || !this.#segmentRegulationsEndpoint) {\n throw new Error('Regulation ID or endpoint not configured');\n }\n\n const url = `${this.#segmentRegulationsEndpoint}/regulations/${regulationId}`;\n\n const response = await this.#policy.execute(async () => {\n const localResponse = await this.#fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': SEGMENT_CONTENT_TYPE,\n },\n });\n\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Checking data deletion status failed with status '${localResponse.status}'`,\n );\n }\n\n return localResponse;\n });\n\n const jsonResponse = (await response.json()) as GetRegulationStatusResponse;\n\n const rawStatus = jsonResponse?.data?.data?.regulation?.overallStatus;\n const dataDeleteStatus = isDataDeleteStatus(rawStatus)\n ? rawStatus\n : DATA_DELETE_STATUSES.Unknown;\n\n return {\n status: DATA_DELETE_RESPONSE_STATUSES.Success,\n dataDeleteStatus,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"AnalyticsDataRegulationService.js","sourceRoot":"","sources":["../src/AnalyticsDataRegulationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAI7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,MAAM,mCAAmC,GAAG,aAAa,CAAC;AAE1D;;GAEG;AACH,MAAM,4BAA4B,GAAG,SAAS,CAAC;AAE/C;;GAEG;AACH,MAAM,oBAAoB,GAAG,iCA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ACF,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n CreateServicePolicyOptions,\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport { refine, string, type } from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\n\nimport type { AnalyticsDataRegulationServiceMethodActions } from './AnalyticsDataRegulationService-method-action-types.js';\nimport {\n DATA_DELETE_RESPONSE_STATUSES,\n DATA_DELETE_STATUSES,\n} from './types.js';\nimport type { DataDeleteStatus } from './types.js';\n\n/**\n * Segment API regulation type for DELETE_ONLY operations.\n */\nconst SEGMENT_REGULATION_TYPE_DELETE_ONLY = 'DELETE_ONLY';\n\n/**\n * Segment API subject type for user ID operations.\n */\nconst SEGMENT_SUBJECT_TYPE_USER_ID = 'USER_ID';\n\n/**\n * Segment API Content-Type header value.\n */\nconst SEGMENT_CONTENT_TYPE = 'application/vnd.segment.v1+json';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link AnalyticsDataRegulationService}, used to namespace the\n * service's actions and events.\n */\nexport const serviceName = 'AnalyticsDataRegulationService';\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'createDataDeletionTask',\n 'checkDataDeleteStatus',\n] as const;\n\n/**\n * Invalidates cached queries for {@link AnalyticsDataRegulationService}.\n */\nexport type AnalyticsDataRegulationServiceInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link AnalyticsDataRegulationService} exposes to other consumers.\n */\nexport type AnalyticsDataRegulationServiceActions =\n | AnalyticsDataRegulationServiceMethodActions\n | AnalyticsDataRegulationServiceInvalidateQueriesAction;\n\n/**\n * Actions from other messengers that {@link AnalyticsDataRegulationServiceMessenger} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Published when {@link AnalyticsDataRegulationService}'s cache is updated.\n */\nexport type AnalyticsDataRegulationServiceCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link AnalyticsDataRegulationService}'s cache is\n * updated.\n */\nexport type AnalyticsDataRegulationServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link AnalyticsDataRegulationService} exposes to other consumers.\n */\nexport type AnalyticsDataRegulationServiceEvents =\n | AnalyticsDataRegulationServiceCacheUpdatedEvent\n | AnalyticsDataRegulationServiceGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that {@link AnalyticsDataRegulationService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link AnalyticsDataRegulationService}.\n */\nexport type AnalyticsDataRegulationServiceMessenger = Messenger<\n typeof serviceName,\n AnalyticsDataRegulationServiceActions | AllowedActions,\n AnalyticsDataRegulationServiceEvents | AllowedEvents\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * A string that is non-empty once trimmed.\n */\nconst NonEmptyStringStruct = refine(\n string(),\n 'NonEmptyString',\n (value) => value.trim() !== '',\n);\n\n/**\n * Response structure from Segment API for creating a regulation.\n */\nconst CreateRegulationResponseStruct = type({\n data: type({\n data: type({\n regulateId: NonEmptyStringStruct,\n }),\n }),\n});\n\n/**\n * Validated response from Segment API for creating a regulation.\n */\ntype CreateRegulationResponse = Infer<typeof CreateRegulationResponseStruct>;\n\n/**\n * Response structure from Segment API for getting regulation status.\n */\ntype GetRegulationStatusResponse = {\n data: {\n data: {\n regulation: {\n overallStatus: string;\n };\n };\n };\n};\n\n/**\n * Options for constructing {@link AnalyticsDataRegulationService}.\n */\nexport type AnalyticsDataRegulationServiceOptions = {\n /**\n * The messenger suited for this service.\n */\n messenger: AnalyticsDataRegulationServiceMessenger;\n\n /**\n * A function that can be used to make an HTTP request.\n */\n fetch: typeof fetch;\n\n /**\n * Segment API source ID (required for creating regulations).\n */\n segmentSourceId: string;\n\n /**\n * Base URL for the proxy endpoint that communicates with Segment's Regulations API.\n * This is a proxy endpoint (not Segment API directly) that forwards requests to Segment's\n * Regulations API and adds authentication tokens. The endpoint URL varies by environment\n * (e.g., development, staging, production) and should be configured accordingly.\n * Example: 'https://proxy.example.com/v1beta'\n */\n segmentRegulationsEndpoint: string;\n\n /**\n * Options to pass to `createServicePolicy`, which is used to wrap each request.\n */\n policyOptions?: CreateServicePolicyOptions;\n};\n\n/**\n * Type guard to check if a value is a valid DataDeleteStatus.\n *\n * @param status - The value to check.\n * @returns True if the value is a valid DataDeleteStatus.\n */\nfunction isDataDeleteStatus(status: unknown): status is DataDeleteStatus {\n const dataDeleteStatuses: string[] = Object.values(DATA_DELETE_STATUSES);\n return dataDeleteStatuses.includes(status as string);\n}\n\n/**\n * This service object is responsible for making requests to the Segment Regulations API\n * via a proxy endpoint for GDPR/CCPA data deletion functionality.\n *\n * @example\n *\n * ```ts\n * import type { MessengerActions, MessengerEvents } from '@metamask/messenger';\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * AnalyticsDataRegulationServiceActions,\n * AnalyticsDataRegulationServiceEvents,\n * AnalyticsDataRegulationServiceMessenger,\n * } from '@metamask/analytics-data-regulation-controller';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * AnalyticsDataRegulationServiceActions,\n * AnalyticsDataRegulationServiceEvents\n * >({ namespace: 'Root' });\n * const serviceMessenger = new Messenger<\n * 'AnalyticsDataRegulationService',\n * MessengerActions<AnalyticsDataRegulationServiceMessenger>,\n * MessengerEvents<AnalyticsDataRegulationServiceMessenger>,\n * typeof rootMessenger,\n * >({\n * namespace: 'AnalyticsDataRegulationService',\n * parent: rootMessenger,\n * });\n * // Instantiate the service to register its actions on the messenger\n * new AnalyticsDataRegulationService({\n * messenger: serviceMessenger,\n * fetch,\n * segmentSourceId: 'abc123',\n * segmentRegulationsEndpoint: 'https://proxy.example.com/v1beta',\n * });\n *\n * // Later...\n * // Create a data deletion task\n * const response = await rootMessenger.call(\n * 'AnalyticsDataRegulationService:createDataDeletionTask',\n * 'user-analytics-id',\n * );\n * ```\n */\nexport class AnalyticsDataRegulationService extends BaseDataService<\n typeof serviceName,\n AnalyticsDataRegulationServiceMessenger\n> {\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: typeof fetch;\n\n /**\n * Segment API source ID.\n */\n readonly #segmentSourceId: string;\n\n /**\n * Base URL for the proxy endpoint that communicates with Segment's Regulations API.\n * This endpoint varies by environment and forwards requests to Segment API with authentication.\n */\n readonly #segmentRegulationsEndpoint: string;\n\n /**\n * Constructs a new AnalyticsDataRegulationService object.\n *\n * @param options - The constructor options.\n */\n constructor(options: AnalyticsDataRegulationServiceOptions) {\n super({\n name: serviceName,\n messenger: options.messenger,\n policyOptions: options.policyOptions,\n });\n this.#fetch = options.fetch;\n this.#segmentSourceId = options.segmentSourceId;\n this.#segmentRegulationsEndpoint = options.segmentRegulationsEndpoint;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Creates a DELETE_ONLY regulation for the given analyticsId.\n *\n * @param analyticsId - The analytics ID of the user for whom to create the deletion task.\n * @returns Promise resolving to a successful deletion regulation response.\n * @throws Error if the request fails or the response is invalid.\n */\n async createDataDeletionTask(analyticsId: string): Promise<{\n status: typeof DATA_DELETE_RESPONSE_STATUSES.Success;\n regulateId: string;\n }> {\n if (!this.#segmentSourceId || !this.#segmentRegulationsEndpoint) {\n throw new Error('Segment API source ID or endpoint not found');\n }\n\n const url = `${this.#segmentRegulationsEndpoint}/regulations/sources/${this.#segmentSourceId}`;\n\n const jsonResponse = await this.executeMutation({\n mutationKey: [`${this.name}:createDataDeletionTask`],\n gcTime: 0,\n responseStruct: CreateRegulationResponseStruct,\n mutationFn: async () => {\n const response = await this.#fetch(url, {\n method: 'POST',\n headers: {\n 'Content-Type': SEGMENT_CONTENT_TYPE,\n },\n body: JSON.stringify({\n regulationType: SEGMENT_REGULATION_TYPE_DELETE_ONLY,\n subjectType: SEGMENT_SUBJECT_TYPE_USER_ID,\n subjectIds: [analyticsId],\n }),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Creating data deletion task failed with status '${response.status}'`,\n );\n }\n\n return (await response.json()) as CreateRegulationResponse;\n },\n });\n\n return {\n status: DATA_DELETE_RESPONSE_STATUSES.Success,\n regulateId: jsonResponse.data.data.regulateId,\n };\n }\n\n /**\n * Checks the status of a regulation by ID.\n *\n * @param regulationId - The regulation ID to check.\n * @returns Promise resolving to a successful regulation status response.\n * @throws Error if the request fails or the response is invalid.\n */\n async checkDataDeleteStatus(regulationId: string): Promise<{\n status: typeof DATA_DELETE_RESPONSE_STATUSES.Success;\n dataDeleteStatus: DataDeleteStatus;\n }> {\n if (!regulationId || !this.#segmentRegulationsEndpoint) {\n throw new Error('Regulation ID or endpoint not configured');\n }\n\n const url = `${this.#segmentRegulationsEndpoint}/regulations/${regulationId}`;\n\n return this.fetchQuery({\n queryKey: [`${this.name}:checkDataDeleteStatus`, regulationId],\n staleTime: 0,\n gcTime: 0,\n queryFn: async () => {\n const response = await this.#fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': SEGMENT_CONTENT_TYPE,\n },\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Checking data deletion status failed with status '${response.status}'`,\n );\n }\n\n const jsonResponse =\n (await response.json()) as GetRegulationStatusResponse;\n const rawStatus = jsonResponse?.data?.data?.regulation?.overallStatus;\n\n return {\n status: DATA_DELETE_RESPONSE_STATUSES.Success,\n dataDeleteStatus: isDataDeleteStatus(rawStatus)\n ? rawStatus\n : DATA_DELETE_STATUSES.Unknown,\n };\n },\n });\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { AnalyticsDataRegulationController, getDefaultAnalyticsDataRegulationControllerState, } from './AnalyticsDataRegulationController.js';
2
2
  export type { AnalyticsDataRegulationControllerOptions } from './AnalyticsDataRegulationController.js';
3
3
  export { AnalyticsDataRegulationService } from './AnalyticsDataRegulationService.js';
4
- export type { AnalyticsDataRegulationServiceActions, AnalyticsDataRegulationServiceEvents, AnalyticsDataRegulationServiceMessenger, AnalyticsDataRegulationServiceOptions, } from './AnalyticsDataRegulationService.js';
4
+ export type { AnalyticsDataRegulationServiceActions, AnalyticsDataRegulationServiceCacheUpdatedEvent, AnalyticsDataRegulationServiceEvents, AnalyticsDataRegulationServiceGranularCacheUpdatedEvent, AnalyticsDataRegulationServiceInvalidateQueriesAction, AnalyticsDataRegulationServiceMessenger, AnalyticsDataRegulationServiceOptions, } from './AnalyticsDataRegulationService.js';
5
5
  export { DATA_DELETE_STATUSES, DATA_DELETE_RESPONSE_STATUSES, type DataDeleteStatus, type DataDeleteResponseStatus, } from './types.js';
6
6
  export type { DeleteRegulationResponse, DeleteRegulationStatus, } from './types.js';
7
7
  export type { AnalyticsDataRegulationControllerState } from './AnalyticsDataRegulationController.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,gDAAgD,GACjD,MAAM,wCAAwC,CAAC;AAChD,YAAY,EAAE,wCAAwC,EAAE,MAAM,wCAAwC,CAAC;AAEvG,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,YAAY,EACV,qCAAqC,EACrC,oCAAoC,EACpC,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAC7B,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,sCAAsC,EAAE,MAAM,wCAAwC,CAAC;AAErG,OAAO,EAAE,0CAA0C,EAAE,MAAM,gBAAgB,CAAC;AAE5E,YAAY,EAAE,0CAA0C,EAAE,MAAM,wCAAwC,CAAC;AAEzG,YAAY,EACV,wCAAwC,EACxC,uCAAuC,EACvC,+CAA+C,EAC/C,iDAAiD,EACjD,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,wCAAwC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,gDAAgD,GACjD,MAAM,wCAAwC,CAAC;AAChD,YAAY,EAAE,wCAAwC,EAAE,MAAM,wCAAwC,CAAC;AAEvG,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,YAAY,EACV,qCAAqC,EACrC,+CAA+C,EAC/C,oCAAoC,EACpC,uDAAuD,EACvD,qDAAqD,EACrD,uCAAuC,EACvC,qCAAqC,GACtC,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,oBAAoB,EACpB,6BAA6B,EAC7B,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,GAC9B,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,sCAAsC,EAAE,MAAM,wCAAwC,CAAC;AAErG,OAAO,EAAE,0CAA0C,EAAE,MAAM,gBAAgB,CAAC;AAE5E,YAAY,EAAE,0CAA0C,EAAE,MAAM,wCAAwC,CAAC;AAEzG,YAAY,EACV,wCAAwC,EACxC,uCAAuC,EACvC,+CAA+C,EAC/C,iDAAiD,EACjD,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,wCAAwC,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,gDAAgD,GACjD,MAAM,wCAAwC,CAAC;AAGhD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAQrF,OAAO,EACL,oBAAoB,EACpB,6BAA6B,GAG9B,MAAM,YAAY,CAAC;AAQpB,OAAO,EAAE,0CAA0C,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export {\n AnalyticsDataRegulationController,\n getDefaultAnalyticsDataRegulationControllerState,\n} from './AnalyticsDataRegulationController.js';\nexport type { AnalyticsDataRegulationControllerOptions } from './AnalyticsDataRegulationController.js';\n\nexport { AnalyticsDataRegulationService } from './AnalyticsDataRegulationService.js';\nexport type {\n AnalyticsDataRegulationServiceActions,\n AnalyticsDataRegulationServiceEvents,\n AnalyticsDataRegulationServiceMessenger,\n AnalyticsDataRegulationServiceOptions,\n} from './AnalyticsDataRegulationService.js';\n\nexport {\n DATA_DELETE_STATUSES,\n DATA_DELETE_RESPONSE_STATUSES,\n type DataDeleteStatus,\n type DataDeleteResponseStatus,\n} from './types.js';\nexport type {\n DeleteRegulationResponse,\n DeleteRegulationStatus,\n} from './types.js';\n\nexport type { AnalyticsDataRegulationControllerState } from './AnalyticsDataRegulationController.js';\n\nexport { analyticsDataRegulationControllerSelectors } from './selectors.js';\n\nexport type { AnalyticsDataRegulationControllerMessenger } from './AnalyticsDataRegulationController.js';\n\nexport type {\n AnalyticsDataRegulationControllerActions,\n AnalyticsDataRegulationControllerEvents,\n AnalyticsDataRegulationControllerGetStateAction,\n AnalyticsDataRegulationControllerStateChangeEvent,\n DataDeletionTaskCreatedEvent,\n DataRecordingFlagUpdatedEvent,\n} from './AnalyticsDataRegulationController.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,gDAAgD,GACjD,MAAM,wCAAwC,CAAC;AAGhD,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAWrF,OAAO,EACL,oBAAoB,EACpB,6BAA6B,GAG9B,MAAM,YAAY,CAAC;AAQpB,OAAO,EAAE,0CAA0C,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export {\n AnalyticsDataRegulationController,\n getDefaultAnalyticsDataRegulationControllerState,\n} from './AnalyticsDataRegulationController.js';\nexport type { AnalyticsDataRegulationControllerOptions } from './AnalyticsDataRegulationController.js';\n\nexport { AnalyticsDataRegulationService } from './AnalyticsDataRegulationService.js';\nexport type {\n AnalyticsDataRegulationServiceActions,\n AnalyticsDataRegulationServiceCacheUpdatedEvent,\n AnalyticsDataRegulationServiceEvents,\n AnalyticsDataRegulationServiceGranularCacheUpdatedEvent,\n AnalyticsDataRegulationServiceInvalidateQueriesAction,\n AnalyticsDataRegulationServiceMessenger,\n AnalyticsDataRegulationServiceOptions,\n} from './AnalyticsDataRegulationService.js';\n\nexport {\n DATA_DELETE_STATUSES,\n DATA_DELETE_RESPONSE_STATUSES,\n type DataDeleteStatus,\n type DataDeleteResponseStatus,\n} from './types.js';\nexport type {\n DeleteRegulationResponse,\n DeleteRegulationStatus,\n} from './types.js';\n\nexport type { AnalyticsDataRegulationControllerState } from './AnalyticsDataRegulationController.js';\n\nexport { analyticsDataRegulationControllerSelectors } from './selectors.js';\n\nexport type { AnalyticsDataRegulationControllerMessenger } from './AnalyticsDataRegulationController.js';\n\nexport type {\n AnalyticsDataRegulationControllerActions,\n AnalyticsDataRegulationControllerEvents,\n AnalyticsDataRegulationControllerGetStateAction,\n AnalyticsDataRegulationControllerStateChangeEvent,\n DataDeletionTaskCreatedEvent,\n DataRecordingFlagUpdatedEvent,\n} from './AnalyticsDataRegulationController.js';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/analytics-data-regulation-controller",
3
- "version": "0.0.0-preview-eb6c0745c",
3
+ "version": "0.0.0-preview-76b7c67",
4
4
  "description": "Controller for managing analytics privacy and GDPR/CCPA data deletion functionality",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -32,43 +32,44 @@
32
32
  "registry": "https://registry.npmjs.org/"
33
33
  },
34
34
  "scripts": {
35
+ "allow-scripts": "yarn workspace @metamask/core-monorepo run allow-scripts",
35
36
  "build": "tsc --project tsconfig.build.json",
36
37
  "build:all": "tsc --build tsconfig.build.json --verbose",
37
38
  "build:clean": "yarn build:only-clean && yarn build",
38
39
  "build:docs": "typedoc",
39
40
  "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
40
41
  "changelog:update": "../../scripts/update-changelog.sh @metamask/analytics-data-regulation-controller",
41
- "changelog:validate": "../../scripts/validate-changelog.sh @metamask/analytics-data-regulation-controller",
42
- "lint:tsconfigs": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
43
- "lint:tsconfigs:fix": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
44
- "messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
45
- "messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
42
+ "changelog:validate": "../../scripts/validate-changelog.sh",
43
+ "lint:tsconfigs": "node --import ../../scripts/resolver/register.ts ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
44
+ "lint:tsconfigs:fix": "node --import ../../scripts/resolver/register.ts ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
45
+ "messenger-action-types:check": "node --import ../../scripts/resolver/register.ts ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
46
+ "messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
46
47
  "since-latest-release": "../../scripts/since-latest-release.sh",
47
- "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
48
- "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
49
- "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
50
- "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
48
+ "test": "vitest",
49
+ "test:clean": "vitest --clearCache",
50
+ "test:coverage": "vitest --coverage",
51
+ "test:verbose": "vitest --reporter=verbose",
52
+ "test:watch": "vitest --watch"
51
53
  },
52
54
  "dependencies": {
53
55
  "@metamask/base-controller": "^10.1.0",
56
+ "@metamask/base-data-service": "^2.1.0",
54
57
  "@metamask/controller-utils": "^13.0.0",
55
58
  "@metamask/messenger": "^3.0.0",
56
- "@metamask/utils": "^12.0.0"
59
+ "@metamask/superstruct": "^3.4.1",
60
+ "@metamask/utils": "^12.0.2"
57
61
  },
58
62
  "devDependencies": {
59
- "@metamask/auto-changelog": "^6.2.1",
60
- "@types/jest": "^30.0.0",
63
+ "@metamask/auto-changelog": "^7.1.0",
61
64
  "@typescript/native": "npm:typescript@^7.0.2",
62
- "deepmerge": "^4.3.1",
63
- "jest": "^30.5.2",
64
- "nock": "^13.5.6",
65
+ "nock": "^15.0.5",
65
66
  "rimraf": "^6.1.3",
66
- "ts-jest": "^29.4.14",
67
67
  "typedoc": "^0.28.20",
68
68
  "typedoc-plugin-missing-exports": "^4.1.4",
69
- "typescript": "npm:@typescript/typescript6@^6.0.2"
69
+ "typescript": "npm:@typescript/typescript6@^6.0.2",
70
+ "vitest": "5.0.3"
70
71
  },
71
72
  "engines": {
72
- "node": "^22.14.0 || ^24"
73
+ "node": "^22.14.0 || ^24 || ^26"
73
74
  }
74
75
  }