@metamask-previews/authenticated-user-storage 3.0.2-preview-3866c0ff1 → 3.0.2-preview-e3275932a

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/authenticated-user-storage-method-action-types.cjs +7 -0
  3. package/dist/authenticated-user-storage-method-action-types.cjs.map +1 -0
  4. package/dist/{authenticated-user-storage-method-action-types.d.ts → authenticated-user-storage-method-action-types.d.cts} +2 -2
  5. package/dist/authenticated-user-storage-method-action-types.d.cts.map +1 -0
  6. package/dist/authenticated-user-storage-method-action-types.d.mts +83 -0
  7. package/dist/authenticated-user-storage-method-action-types.d.mts.map +1 -0
  8. package/dist/{authenticated-user-storage-method-action-types.js → authenticated-user-storage-method-action-types.mjs} +1 -1
  9. package/dist/authenticated-user-storage-method-action-types.mjs.map +1 -0
  10. package/dist/authenticated-user-storage.cjs +282 -0
  11. package/dist/authenticated-user-storage.cjs.map +1 -0
  12. package/dist/{authenticated-user-storage.d.ts → authenticated-user-storage.d.cts} +8 -8
  13. package/dist/authenticated-user-storage.d.cts.map +1 -0
  14. package/dist/authenticated-user-storage.d.mts +142 -0
  15. package/dist/authenticated-user-storage.d.mts.map +1 -0
  16. package/dist/{authenticated-user-storage.js → authenticated-user-storage.mjs} +45 -32
  17. package/dist/authenticated-user-storage.mjs.map +1 -0
  18. package/dist/env.cjs +24 -0
  19. package/dist/env.cjs.map +1 -0
  20. package/dist/{env.d.ts → env.d.cts} +1 -1
  21. package/dist/env.d.cts.map +1 -0
  22. package/dist/env.d.mts +10 -0
  23. package/dist/env.d.mts.map +1 -0
  24. package/dist/{env.js → env.mjs} +1 -1
  25. package/dist/env.mjs.map +1 -0
  26. package/dist/index.cjs +13 -0
  27. package/dist/index.cjs.map +1 -0
  28. package/dist/{index.d.ts → index.d.cts} +8 -8
  29. package/dist/index.d.cts.map +1 -0
  30. package/dist/index.d.mts +8 -0
  31. package/dist/index.d.mts.map +1 -0
  32. package/dist/index.mjs +4 -0
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/types.cjs +3 -0
  35. package/dist/types.cjs.map +1 -0
  36. package/dist/{types.d.ts → types.d.cts} +3 -3
  37. package/dist/types.d.cts.map +1 -0
  38. package/dist/types.d.mts +107 -0
  39. package/dist/types.d.mts.map +1 -0
  40. package/dist/types.mjs +2 -0
  41. package/dist/types.mjs.map +1 -0
  42. package/dist/validators.cjs +173 -0
  43. package/dist/validators.cjs.map +1 -0
  44. package/dist/{validators.d.ts → validators.d.cts} +3 -3
  45. package/dist/validators.d.cts.map +1 -0
  46. package/dist/validators.d.mts +84 -0
  47. package/dist/validators.d.mts.map +1 -0
  48. package/dist/{validators.js → validators.mjs} +2 -2
  49. package/dist/validators.mjs.map +1 -0
  50. package/package.json +18 -14
  51. package/dist/authenticated-user-storage-method-action-types.d.ts.map +0 -1
  52. package/dist/authenticated-user-storage-method-action-types.js.map +0 -1
  53. package/dist/authenticated-user-storage.d.ts.map +0 -1
  54. package/dist/authenticated-user-storage.js.map +0 -1
  55. package/dist/env.d.ts.map +0 -1
  56. package/dist/env.js.map +0 -1
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js +0 -4
  59. package/dist/index.js.map +0 -1
  60. package/dist/types.d.ts.map +0 -1
  61. package/dist/types.js +0 -2
  62. package/dist/types.js.map +0 -1
  63. package/dist/validators.d.ts.map +0 -1
  64. package/dist/validators.js.map +0 -1
@@ -0,0 +1,142 @@
1
+ import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from "@metamask/base-data-service";
2
+ import { BaseDataService } from "@metamask/base-data-service";
3
+ import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
4
+ import type { Messenger } from "@metamask/messenger";
5
+ import type { AuthenticatedUserStorageServiceMethodActions } from "./authenticated-user-storage-method-action-types.mjs";
6
+ import type { Environment } from "./env.mjs";
7
+ import type { AssetsWatchlistBlob, ClientType, DelegationResponse, DelegationSubmission, NotificationPreferences } from "./types.mjs";
8
+ /**
9
+ * The name of the {@link AuthenticatedUserStorageService} service, used to
10
+ * namespace the service's actions and events.
11
+ */
12
+ export declare const serviceName = "AuthenticatedUserStorageService";
13
+ /**
14
+ * Builds the versioned API base URL for a given environment.
15
+ *
16
+ * @param environment - The target environment.
17
+ * @returns The base URL including the `/api/v1` path segment.
18
+ */
19
+ export declare function getAuthenticatedStorageUrl(environment: Environment): string;
20
+ /**
21
+ * Invalidates cached queries for {@link AuthenticatedUserStorageService}.
22
+ */
23
+ export type AuthenticatedUserStorageInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
24
+ /**
25
+ * Actions that {@link AuthenticatedUserStorageService} exposes to other
26
+ * consumers.
27
+ */
28
+ export type AuthenticatedUserStorageActions = AuthenticatedUserStorageServiceMethodActions | AuthenticatedUserStorageInvalidateQueriesAction;
29
+ /**
30
+ * Retrieves a bearer token from the `AuthenticationController`, logging in the
31
+ * user if necessary.
32
+ */
33
+ type AuthenticationControllerGetBearerTokenAction = {
34
+ type: 'AuthenticationController:getBearerToken';
35
+ handler: (entropySourceId?: string) => Promise<string>;
36
+ };
37
+ /**
38
+ * Actions from other messengers that {@link AuthenticatedUserStorageService}
39
+ * calls.
40
+ */
41
+ type AllowedActions = AuthenticationControllerGetBearerTokenAction;
42
+ /**
43
+ * Published when {@link AuthenticatedUserStorageService}'s cache is updated.
44
+ */
45
+ export type AuthenticatedUserStorageCacheUpdatedEvent = DataServiceCacheUpdatedEvent<typeof serviceName>;
46
+ /**
47
+ * Published when a key within {@link AuthenticatedUserStorageService}'s cache
48
+ * is updated.
49
+ */
50
+ export type AuthenticatedUserStorageGranularCacheUpdatedEvent = DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
51
+ /**
52
+ * Events that {@link AuthenticatedUserStorageService} exposes to other
53
+ * consumers.
54
+ */
55
+ export type AuthenticatedUserStorageEvents = AuthenticatedUserStorageCacheUpdatedEvent | AuthenticatedUserStorageGranularCacheUpdatedEvent;
56
+ /**
57
+ * Events from other messengers that
58
+ * {@link AuthenticatedUserStorageService} subscribes to.
59
+ */
60
+ type AllowedEvents = never;
61
+ /**
62
+ * The messenger which is restricted to actions and events accessed by
63
+ * {@link AuthenticatedUserStorageService}.
64
+ */
65
+ export type AuthenticatedUserStorageMessenger = Messenger<typeof serviceName, AuthenticatedUserStorageActions | AllowedActions, AuthenticatedUserStorageEvents | AllowedEvents>;
66
+ /**
67
+ * Data service wrapping authenticated user-storage API endpoints.
68
+ *
69
+ * Provides methods for managing delegations and notification preferences
70
+ * for the authenticated user.
71
+ */
72
+ export declare class AuthenticatedUserStorageService extends BaseDataService<typeof serviceName, AuthenticatedUserStorageMessenger> {
73
+ #private;
74
+ /**
75
+ * Constructs a new AuthenticatedUserStorageService.
76
+ *
77
+ * @param args - The constructor arguments.
78
+ * @param args.messenger - The messenger suited for this service.
79
+ * @param args.environment - The target environment (dev, uat, prod).
80
+ * @param args.policyOptions - Options to pass to `createServicePolicy`, which
81
+ * is used to wrap each request. See {@link CreateServicePolicyOptions}.
82
+ */
83
+ constructor({ messenger, environment, policyOptions, }: {
84
+ messenger: AuthenticatedUserStorageMessenger;
85
+ environment: Environment;
86
+ policyOptions?: CreateServicePolicyOptions;
87
+ });
88
+ /**
89
+ * Returns all delegation records belonging to the authenticated user.
90
+ *
91
+ * @returns An array of delegation records, or an empty array if none exist.
92
+ */
93
+ listDelegations(): Promise<DelegationResponse[]>;
94
+ /**
95
+ * Stores a signed delegation record for the authenticated user.
96
+ *
97
+ * @param submission - The signed delegation and its metadata.
98
+ * @param clientType - Optional client type header.
99
+ */
100
+ createDelegation(submission: DelegationSubmission, clientType?: ClientType): Promise<void>;
101
+ /**
102
+ * Revokes (deletes) a delegation record.
103
+ *
104
+ * @param delegationHash - The unique hash identifying the delegation.
105
+ */
106
+ revokeDelegation(delegationHash: string): Promise<void>;
107
+ /**
108
+ * Returns the notification preferences for the authenticated user.
109
+ *
110
+ * @returns The notification preferences object, or `null` if none have been
111
+ * set (404).
112
+ */
113
+ getNotificationPreferences(): Promise<NotificationPreferences | null>;
114
+ /**
115
+ * Creates or updates the notification preferences for the authenticated user.
116
+ *
117
+ * @param prefs - The full notification preferences object.
118
+ * @param clientType - Optional client type header.
119
+ */
120
+ putNotificationPreferences(prefs: NotificationPreferences, clientType?: ClientType): Promise<void>;
121
+ /**
122
+ * Returns the assets-watchlist for the authenticated user.
123
+ *
124
+ * @returns The assets-watchlist blob, or `null` if none has been set (404).
125
+ */
126
+ getAssetsWatchlist(): Promise<AssetsWatchlistBlob | null>;
127
+ /**
128
+ * Creates or updates the assets-watchlist for the authenticated user.
129
+ *
130
+ * @param blob - The full assets-watchlist blob. The `assets` array may
131
+ * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
132
+ * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
133
+ * request is sent.
134
+ * @param clientType - Optional client type header.
135
+ * @throws A `StructError` from `@metamask/superstruct` if `blob` is
136
+ * structurally invalid or `assets` exceeds the cap; an `HttpError` from
137
+ * `@metamask/controller-utils` if the API responds with a non-2xx status.
138
+ */
139
+ setAssetsWatchlist(blob: AssetsWatchlistBlob, clientType?: ClientType): Promise<void>;
140
+ }
141
+ export {};
142
+ //# sourceMappingURL=authenticated-user-storage.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticated-user-storage.d.mts","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,4CAA4C,EAAE,6DAA4D;AACxH,OAAO,KAAK,EAAE,WAAW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,SAAS,EAAE,iCAAiC,CAAC;QAC7C,WAAW,EAAE,WAAW,CAAC;QACzB,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAUD;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAwBtD;;;;;OAKG;IACG,gBAAgB,CACpB,UAAU,EAAE,oBAAoB,EAChC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAiChB;;;;OAIG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7D;;;;;OAKG;IACG,0BAA0B,IAAI,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;IAgC3E;;;;;OAKG;IACG,0BAA0B,CAC9B,KAAK,EAAE,uBAAuB,EAC9B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAiChB;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAgC/D;;;;;;;;;;;OAWG;IACG,kBAAkB,CACtB,IAAI,EAAE,mBAAmB,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;CA6CjB"}
@@ -1,7 +1,19 @@
1
- import { BaseDataService } from '@metamask/base-data-service';
2
- import { HttpError } from '@metamask/controller-utils';
3
- import { getUserStorageApiUrl } from './env.js';
4
- import { assertAssetsWatchlistBlob, assertAssetsWatchlistBlobForWrite, assertDelegationResponseArray, assertNotificationPreferences, } from './validators.js';
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _AuthenticatedUserStorageService_instances, _AuthenticatedUserStorageService_environment, _AuthenticatedUserStorageService_getHeaders;
13
+ import { BaseDataService } from "@metamask/base-data-service";
14
+ import { HttpError } from "@metamask/controller-utils";
15
+ import { getUserStorageApiUrl } from "./env.mjs";
16
+ import { assertAssetsWatchlistBlob, assertAssetsWatchlistBlobForWrite, assertDelegationResponseArray, assertNotificationPreferences } from "./validators.mjs";
5
17
  // === GENERAL ===
6
18
  /**
7
19
  * The name of the {@link AuthenticatedUserStorageService} service, used to
@@ -35,7 +47,6 @@ const MESSENGER_EXPOSED_METHODS = [
35
47
  * for the authenticated user.
36
48
  */
37
49
  export class AuthenticatedUserStorageService extends BaseDataService {
38
- #environment;
39
50
  /**
40
51
  * Constructs a new AuthenticatedUserStorageService.
41
52
  *
@@ -47,7 +58,9 @@ export class AuthenticatedUserStorageService extends BaseDataService {
47
58
  */
48
59
  constructor({ messenger, environment, policyOptions, }) {
49
60
  super({ name: serviceName, messenger, policyOptions });
50
- this.#environment = environment;
61
+ _AuthenticatedUserStorageService_instances.add(this);
62
+ _AuthenticatedUserStorageService_environment.set(this, void 0);
63
+ __classPrivateFieldSet(this, _AuthenticatedUserStorageService_environment, environment, "f");
51
64
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
52
65
  }
53
66
  /**
@@ -56,11 +69,11 @@ export class AuthenticatedUserStorageService extends BaseDataService {
56
69
  * @returns An array of delegation records, or an empty array if none exist.
57
70
  */
58
71
  async listDelegations() {
59
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;
72
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/delegations`;
60
73
  const data = await this.fetchQuery({
61
74
  queryKey: [`${this.name}:listDelegations`],
62
75
  queryFn: async () => {
63
- const headers = await this.#getHeaders();
76
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
64
77
  const response = await fetch(url, { headers });
65
78
  if (!response.ok) {
66
79
  throw new HttpError(response.status, `Failed to list delegations: ${response.status}`);
@@ -78,7 +91,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
78
91
  * @param clientType - Optional client type header.
79
92
  */
80
93
  async createDelegation(submission, clientType) {
81
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;
94
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/delegations`;
82
95
  await this.fetchQuery({
83
96
  queryKey: [
84
97
  `${this.name}:createDelegation`,
@@ -86,7 +99,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
86
99
  ],
87
100
  staleTime: 0,
88
101
  queryFn: async () => {
89
- const headers = await this.#getHeaders(clientType);
102
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
90
103
  const response = await fetch(url, {
91
104
  method: 'POST',
92
105
  headers,
@@ -108,12 +121,12 @@ export class AuthenticatedUserStorageService extends BaseDataService {
108
121
  * @param delegationHash - The unique hash identifying the delegation.
109
122
  */
110
123
  async revokeDelegation(delegationHash) {
111
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations/${encodeURIComponent(delegationHash)}`;
124
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/delegations/${encodeURIComponent(delegationHash)}`;
112
125
  await this.fetchQuery({
113
126
  queryKey: [`${this.name}:revokeDelegation`, delegationHash],
114
127
  staleTime: 0,
115
128
  queryFn: async () => {
116
- const headers = await this.#getHeaders();
129
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
117
130
  const response = await fetch(url, {
118
131
  method: 'DELETE',
119
132
  headers,
@@ -135,11 +148,11 @@ export class AuthenticatedUserStorageService extends BaseDataService {
135
148
  * set (404).
136
149
  */
137
150
  async getNotificationPreferences() {
138
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;
151
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/notifications`;
139
152
  const data = await this.fetchQuery({
140
153
  queryKey: [`${this.name}:getNotificationPreferences`],
141
154
  queryFn: async () => {
142
- const headers = await this.#getHeaders();
155
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
143
156
  const response = await fetch(url, { headers });
144
157
  if (response.status === 404) {
145
158
  return null;
@@ -163,7 +176,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
163
176
  * @param clientType - Optional client type header.
164
177
  */
165
178
  async putNotificationPreferences(prefs, clientType) {
166
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;
179
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/notifications`;
167
180
  await this.fetchQuery({
168
181
  queryKey: [
169
182
  `${this.name}:putNotificationPreferences`,
@@ -171,7 +184,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
171
184
  ],
172
185
  staleTime: 0,
173
186
  queryFn: async () => {
174
- const headers = await this.#getHeaders(clientType);
187
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
175
188
  const response = await fetch(url, {
176
189
  method: 'PUT',
177
190
  headers,
@@ -193,11 +206,11 @@ export class AuthenticatedUserStorageService extends BaseDataService {
193
206
  * @returns The assets-watchlist blob, or `null` if none has been set (404).
194
207
  */
195
208
  async getAssetsWatchlist() {
196
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;
209
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/assets-watchlist`;
197
210
  const data = await this.fetchQuery({
198
211
  queryKey: [`${this.name}:getAssetsWatchlist`],
199
212
  queryFn: async () => {
200
- const headers = await this.#getHeaders();
213
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
201
214
  const response = await fetch(url, { headers });
202
215
  if (response.status === 404) {
203
216
  return null;
@@ -228,12 +241,12 @@ export class AuthenticatedUserStorageService extends BaseDataService {
228
241
  */
229
242
  async setAssetsWatchlist(blob, clientType) {
230
243
  assertAssetsWatchlistBlobForWrite(blob);
231
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;
244
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/assets-watchlist`;
232
245
  await this.fetchQuery({
233
246
  queryKey: [`${this.name}:setAssetsWatchlist`, blob],
234
247
  staleTime: 0,
235
248
  queryFn: async () => {
236
- const headers = await this.#getHeaders(clientType);
249
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
237
250
  const response = await fetch(url, {
238
251
  method: 'PUT',
239
252
  headers,
@@ -249,16 +262,16 @@ export class AuthenticatedUserStorageService extends BaseDataService {
249
262
  queryKey: [`${this.name}:getAssetsWatchlist`],
250
263
  });
251
264
  }
252
- async #getHeaders(clientType) {
253
- const accessToken = await this.messenger.call('AuthenticationController:getBearerToken');
254
- const headers = {
255
- 'Content-Type': 'application/json',
256
- Authorization: `Bearer ${accessToken}`,
257
- };
258
- if (clientType) {
259
- headers['X-Client-Type'] = clientType;
260
- }
261
- return headers;
262
- }
263
265
  }
264
- //# sourceMappingURL=authenticated-user-storage.js.map
266
+ _AuthenticatedUserStorageService_environment = new WeakMap(), _AuthenticatedUserStorageService_instances = new WeakSet(), _AuthenticatedUserStorageService_getHeaders = async function _AuthenticatedUserStorageService_getHeaders(clientType) {
267
+ const accessToken = await this.messenger.call('AuthenticationController:getBearerToken');
268
+ const headers = {
269
+ 'Content-Type': 'application/json',
270
+ Authorization: `Bearer ${accessToken}`,
271
+ };
272
+ if (clientType) {
273
+ headers['X-Client-Type'] = clientType;
274
+ }
275
+ return headers;
276
+ };
277
+ //# sourceMappingURL=authenticated-user-storage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticated-user-storage.mjs","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAE9D,OAAO,EAAE,SAAS,EAAE,mCAAmC;AAMvD,OAAO,EAAE,oBAAoB,EAAE,kBAAiB;AAQhD,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC9B,yBAAwB;AAEzB,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,WAAwB;IACjE,OAAO,GAAG,oBAAoB,CAAC,WAAW,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,4BAA4B;IAC5B,4BAA4B;IAC5B,oBAAoB;IACpB,oBAAoB;CACZ,CAAC;AAoEX,kBAAkB;AAElB;;;;;GAKG;AACH,MAAM,OAAO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AI,EAAa,UAAU,CAAC,CAAC;gBACnD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;oBAChC,MAAM,EAAE,KAAK;oBACb,OAAO;oBACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;iBAC3B,CAAC,CAAC;gBAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,SAAS,CACjB,QAAQ,CAAC,MAAM,EACf,mCAAmC,QAAQ,CAAC,MAAM,EAAE,CACrD,CAAC;gBACJ,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC3B,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,qBAAqB,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;CAeF;wKAbC,KAAK,sDAAa,UAAuB;IACvC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAC3C,yCAAyC,CAC1C,CAAC;IACF,MAAM,OAAO,GAA2B;QACtC,cAAc,EAAE,kBAAkB;QAClC,aAAa,EAAE,UAAU,WAAW,EAAE;KACvC,CAAC;IACF,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC;IACxC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { AuthenticatedUserStorageServiceMethodActions } from './authenticated-user-storage-method-action-types.js';\nimport type { Environment } from './env.js';\nimport { getUserStorageApiUrl } from './env.js';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types.js';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertNotificationPreferences,\n} from './validators.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link AuthenticatedUserStorageService} service, used to\n * namespace the service's actions and events.\n */\nexport const serviceName = 'AuthenticatedUserStorageService';\n\n/**\n * Builds the versioned API base URL for a given environment.\n *\n * @param environment - The target environment.\n * @returns The base URL including the `/api/v1` path segment.\n */\nexport function getAuthenticatedStorageUrl(environment: Environment): string {\n return `${getUserStorageApiUrl(environment)}/api/v1`;\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'listDelegations',\n 'createDelegation',\n 'revokeDelegation',\n 'getNotificationPreferences',\n 'putNotificationPreferences',\n 'getAssetsWatchlist',\n 'setAssetsWatchlist',\n] as const;\n\n/**\n * Invalidates cached queries for {@link AuthenticatedUserStorageService}.\n */\nexport type AuthenticatedUserStorageInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link AuthenticatedUserStorageService} exposes to other\n * consumers.\n */\nexport type AuthenticatedUserStorageActions =\n | AuthenticatedUserStorageServiceMethodActions\n | AuthenticatedUserStorageInvalidateQueriesAction;\n\n/**\n * Retrieves a bearer token from the `AuthenticationController`, logging in the\n * user if necessary.\n */\ntype AuthenticationControllerGetBearerTokenAction = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Actions from other messengers that {@link AuthenticatedUserStorageService}\n * calls.\n */\ntype AllowedActions = AuthenticationControllerGetBearerTokenAction;\n\n/**\n * Published when {@link AuthenticatedUserStorageService}'s cache is updated.\n */\nexport type AuthenticatedUserStorageCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link AuthenticatedUserStorageService}'s cache\n * is updated.\n */\nexport type AuthenticatedUserStorageGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link AuthenticatedUserStorageService} exposes to other\n * consumers.\n */\nexport type AuthenticatedUserStorageEvents =\n | AuthenticatedUserStorageCacheUpdatedEvent\n | AuthenticatedUserStorageGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that\n * {@link AuthenticatedUserStorageService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link AuthenticatedUserStorageService}.\n */\nexport type AuthenticatedUserStorageMessenger = Messenger<\n typeof serviceName,\n AuthenticatedUserStorageActions | AllowedActions,\n AuthenticatedUserStorageEvents | AllowedEvents\n>;\n\n// === SERVICE ===\n\n/**\n * Data service wrapping authenticated user-storage API endpoints.\n *\n * Provides methods for managing delegations and notification preferences\n * for the authenticated user.\n */\nexport class AuthenticatedUserStorageService extends BaseDataService<\n typeof serviceName,\n AuthenticatedUserStorageMessenger\n> {\n readonly #environment: Environment;\n\n /**\n * Constructs a new AuthenticatedUserStorageService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.environment - The target environment (dev, uat, prod).\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n environment,\n policyOptions,\n }: {\n messenger: AuthenticatedUserStorageMessenger;\n environment: Environment;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({ name: serviceName, messenger, policyOptions });\n this.#environment = environment;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Returns all delegation records belonging to the authenticated user.\n *\n * @returns An array of delegation records, or an empty array if none exist.\n */\n async listDelegations(): Promise<DelegationResponse[]> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:listDelegations`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to list delegations: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n assertDelegationResponseArray(data);\n return data;\n }\n\n /**\n * Stores a signed delegation record for the authenticated user.\n *\n * @param submission - The signed delegation and its metadata.\n * @param clientType - Optional client type header.\n */\n async createDelegation(\n submission: DelegationSubmission,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:createDelegation`,\n submission.metadata.delegationHash,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify(submission),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to create delegation: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:listDelegations`],\n });\n }\n\n /**\n * Revokes (deletes) a delegation record.\n *\n * @param delegationHash - The unique hash identifying the delegation.\n */\n async revokeDelegation(delegationHash: string): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations/${encodeURIComponent(delegationHash)}`;\n\n await this.fetchQuery({\n queryKey: [`${this.name}:revokeDelegation`, delegationHash],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, {\n method: 'DELETE',\n headers,\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to revoke delegation: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:listDelegations`],\n });\n }\n\n /**\n * Returns the notification preferences for the authenticated user.\n *\n * @returns The notification preferences object, or `null` if none have been\n * set (404).\n */\n async getNotificationPreferences(): Promise<NotificationPreferences | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getNotificationPreferences`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get notification preferences: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertNotificationPreferences(data);\n return data;\n }\n\n /**\n * Creates or updates the notification preferences for the authenticated user.\n *\n * @param prefs - The full notification preferences object.\n * @param clientType - Optional client type header.\n */\n async putNotificationPreferences(\n prefs: NotificationPreferences,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:putNotificationPreferences`,\n prefs as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(prefs),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put notification preferences: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getNotificationPreferences`],\n });\n }\n\n /**\n * Returns the assets-watchlist for the authenticated user.\n *\n * @returns The assets-watchlist blob, or `null` if none has been set (404).\n */\n async getAssetsWatchlist(): Promise<AssetsWatchlistBlob | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getAssetsWatchlist`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get assets watchlist: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertAssetsWatchlistBlob(data);\n return data;\n }\n\n /**\n * Creates or updates the assets-watchlist for the authenticated user.\n *\n * @param blob - The full assets-watchlist blob. The `assets` array may\n * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;\n * this is enforced by `assertAssetsWatchlistBlobForWrite` before the\n * request is sent.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `blob` is\n * structurally invalid or `assets` exceeds the cap; an `HttpError` from\n * `@metamask/controller-utils` if the API responds with a non-2xx status.\n */\n async setAssetsWatchlist(\n blob: AssetsWatchlistBlob,\n clientType?: ClientType,\n ): Promise<void> {\n assertAssetsWatchlistBlobForWrite(blob);\n\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;\n\n await this.fetchQuery({\n queryKey: [`${this.name}:setAssetsWatchlist`, blob as unknown as Json],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(blob),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put assets watchlist: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getAssetsWatchlist`],\n });\n }\n\n async #getHeaders(clientType?: ClientType): Promise<Record<string, string>> {\n const accessToken = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n };\n if (clientType) {\n headers['X-Client-Type'] = clientType;\n }\n return headers;\n }\n}\n"]}
package/dist/env.cjs ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUserStorageApiUrl = void 0;
4
+ const API_SUBDOMAINS = {
5
+ dev: 'dev-api',
6
+ uat: 'uat-api',
7
+ prod: 'api',
8
+ };
9
+ /**
10
+ * Returns the user-storage API base URL for the given environment.
11
+ *
12
+ * @param environment - The target environment.
13
+ * @returns The base URL for the user-storage API.
14
+ * @throws If the environment is invalid.
15
+ */
16
+ function getUserStorageApiUrl(environment) {
17
+ const subdomain = API_SUBDOMAINS[environment];
18
+ if (!subdomain) {
19
+ throw new Error(`Invalid environment: ${String(environment)}`);
20
+ }
21
+ return `https://user-storage.${subdomain}.cx.metamask.io`;
22
+ }
23
+ exports.getUserStorageApiUrl = getUserStorageApiUrl;
24
+ //# sourceMappingURL=env.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.cjs","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;;AAEA,MAAM,cAAc,GAAG;IACrB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,KAAK;CACmC,CAAC;AAEjD;;;;;;GAMG;AACH,SAAgB,oBAAoB,CAAC,WAAwB;IAC3D,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,wBAAwB,SAAS,iBAAiB,CAAC;AAC5D,CAAC;AAND,oDAMC","sourcesContent":["export type Environment = 'dev' | 'uat' | 'prod';\n\nconst API_SUBDOMAINS = {\n dev: 'dev-api',\n uat: 'uat-api',\n prod: 'api',\n} as const satisfies Record<Environment, string>;\n\n/**\n * Returns the user-storage API base URL for the given environment.\n *\n * @param environment - The target environment.\n * @returns The base URL for the user-storage API.\n * @throws If the environment is invalid.\n */\nexport function getUserStorageApiUrl(environment: Environment): string {\n const subdomain = API_SUBDOMAINS[environment];\n if (!subdomain) {\n throw new Error(`Invalid environment: ${String(environment)}`);\n }\n return `https://user-storage.${subdomain}.cx.metamask.io`;\n}\n"]}
@@ -7,4 +7,4 @@ export type Environment = 'dev' | 'uat' | 'prod';
7
7
  * @throws If the environment is invalid.
8
8
  */
9
9
  export declare function getUserStorageApiUrl(environment: Environment): string;
10
- //# sourceMappingURL=env.d.ts.map
10
+ //# sourceMappingURL=env.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.cts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAQjD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAMrE"}
package/dist/env.d.mts ADDED
@@ -0,0 +1,10 @@
1
+ export type Environment = 'dev' | 'uat' | 'prod';
2
+ /**
3
+ * Returns the user-storage API base URL for the given environment.
4
+ *
5
+ * @param environment - The target environment.
6
+ * @returns The base URL for the user-storage API.
7
+ * @throws If the environment is invalid.
8
+ */
9
+ export declare function getUserStorageApiUrl(environment: Environment): string;
10
+ //# sourceMappingURL=env.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.mts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAQjD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAMrE"}
@@ -17,4 +17,4 @@ export function getUserStorageApiUrl(environment) {
17
17
  }
18
18
  return `https://user-storage.${subdomain}.cx.metamask.io`;
19
19
  }
20
- //# sourceMappingURL=env.js.map
20
+ //# sourceMappingURL=env.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.mjs","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG;IACrB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,KAAK;CACmC,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAwB;IAC3D,MAAM,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC9C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,wBAAwB,SAAS,iBAAiB,CAAC;AAC5D,CAAC","sourcesContent":["export type Environment = 'dev' | 'uat' | 'prod';\n\nconst API_SUBDOMAINS = {\n dev: 'dev-api',\n uat: 'uat-api',\n prod: 'api',\n} as const satisfies Record<Environment, string>;\n\n/**\n * Returns the user-storage API base URL for the given environment.\n *\n * @param environment - The target environment.\n * @returns The base URL for the user-storage API.\n * @throws If the environment is invalid.\n */\nexport function getUserStorageApiUrl(environment: Environment): string {\n const subdomain = API_SUBDOMAINS[environment];\n if (!subdomain) {\n throw new Error(`Invalid environment: ${String(environment)}`);\n }\n return `https://user-storage.${subdomain}.cx.metamask.io`;\n}\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUserStorageApiUrl = exports.DEFAULT_PRICE_ALERT_PREFERENCES = exports.DEFAULT_AGENTIC_CLI_PREFERENCES = exports.ASSETS_WATCHLIST_MAX_ASSETS = exports.AuthenticatedUserStorageService = exports.getAuthenticatedStorageUrl = void 0;
4
+ var authenticated_user_storage_js_1 = require("./authenticated-user-storage.cjs");
5
+ Object.defineProperty(exports, "getAuthenticatedStorageUrl", { enumerable: true, get: function () { return authenticated_user_storage_js_1.getAuthenticatedStorageUrl; } });
6
+ Object.defineProperty(exports, "AuthenticatedUserStorageService", { enumerable: true, get: function () { return authenticated_user_storage_js_1.AuthenticatedUserStorageService; } });
7
+ var validators_js_1 = require("./validators.cjs");
8
+ Object.defineProperty(exports, "ASSETS_WATCHLIST_MAX_ASSETS", { enumerable: true, get: function () { return validators_js_1.ASSETS_WATCHLIST_MAX_ASSETS; } });
9
+ Object.defineProperty(exports, "DEFAULT_AGENTIC_CLI_PREFERENCES", { enumerable: true, get: function () { return validators_js_1.DEFAULT_AGENTIC_CLI_PREFERENCES; } });
10
+ Object.defineProperty(exports, "DEFAULT_PRICE_ALERT_PREFERENCES", { enumerable: true, get: function () { return validators_js_1.DEFAULT_PRICE_ALERT_PREFERENCES; } });
11
+ var env_js_1 = require("./env.cjs");
12
+ Object.defineProperty(exports, "getUserStorageApiUrl", { enumerable: true, get: function () { return env_js_1.getUserStorageApiUrl; } });
13
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,kFAGyC;AAFvC,2IAAA,0BAA0B,OAAA;AAC1B,gJAAA,+BAA+B,OAAA;AAEjC,kDAIyB;AAHvB,4HAAA,2BAA2B,OAAA;AAC3B,gIAAA,+BAA+B,OAAA;AAC/B,gIAAA,+BAA+B,OAAA;AAmBjC,oCAAgD;AAAvC,8GAAA,oBAAoB,OAAA","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage.js';\nexport {\n ASSETS_WATCHLIST_MAX_ASSETS,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n DEFAULT_PRICE_ALERT_PREFERENCES,\n} from './validators.js';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage.js';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n AuthenticatedUserStorageServiceGetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceSetAssetsWatchlistAction,\n} from './authenticated-user-storage-method-action-types.js';\nexport { getUserStorageApiUrl } from './env.js';\nexport type { Environment } from './env.js';\nexport type {\n Caveat,\n SignedDelegation,\n DelegationMetadata,\n DelegationSubmission,\n DelegationResponse,\n WalletActivityAccount,\n WalletActivityPreference,\n MarketingPreference,\n PerpsWatchlistExchange,\n PerpsWatchlistMarkets,\n PerpsPreference,\n SocialAIPreference,\n AgenticCliPreference,\n PriceAlertPreference,\n NotificationPreferences,\n AssetsWatchlistBlob,\n ClientType,\n} from './types.js';\n"]}
@@ -1,8 +1,8 @@
1
- export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from './authenticated-user-storage.js';
2
- export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } from './validators.js';
3
- export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from './authenticated-user-storage.js';
4
- export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from './authenticated-user-storage-method-action-types.js';
5
- export { getUserStorageApiUrl } from './env.js';
6
- export type { Environment } from './env.js';
7
- export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, AgenticCliPreference, PriceAlertPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from './types.js';
8
- //# sourceMappingURL=index.d.ts.map
1
+ export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from "./authenticated-user-storage.cjs";
2
+ export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } from "./validators.cjs";
3
+ export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from "./authenticated-user-storage.cjs";
4
+ export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from "./authenticated-user-storage-method-action-types.cjs";
5
+ export { getUserStorageApiUrl } from "./env.cjs";
6
+ export type { Environment } from "./env.cjs";
7
+ export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, AgenticCliPreference, PriceAlertPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from "./types.cjs";
8
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,yCAAwC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,yBAAwB;AACzB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,yCAAwC;AACzC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,uDAAuD,EACvD,uDAAuD,GACxD,6DAA4D;AAC7D,OAAO,EAAE,oBAAoB,EAAE,kBAAiB;AAChD,YAAY,EAAE,WAAW,EAAE,kBAAiB;AAC5C,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,GACX,oBAAmB"}
@@ -0,0 +1,8 @@
1
+ export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from "./authenticated-user-storage.mjs";
2
+ export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } from "./validators.mjs";
3
+ export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from "./authenticated-user-storage.mjs";
4
+ export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from "./authenticated-user-storage-method-action-types.mjs";
5
+ export { getUserStorageApiUrl } from "./env.mjs";
6
+ export type { Environment } from "./env.mjs";
7
+ export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, AgenticCliPreference, PriceAlertPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from "./types.mjs";
8
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,yCAAwC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,yBAAwB;AACzB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,yCAAwC;AACzC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,uDAAuD,EACvD,uDAAuD,GACxD,6DAA4D;AAC7D,OAAO,EAAE,oBAAoB,EAAE,kBAAiB;AAChD,YAAY,EAAE,WAAW,EAAE,kBAAiB;AAC5C,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,GACX,oBAAmB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService } from "./authenticated-user-storage.mjs";
2
+ export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES } from "./validators.mjs";
3
+ export { getUserStorageApiUrl } from "./env.mjs";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAChC,yCAAwC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAChC,yBAAwB;AAkBzB,OAAO,EAAE,oBAAoB,EAAE,kBAAiB","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage.js';\nexport {\n ASSETS_WATCHLIST_MAX_ASSETS,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n DEFAULT_PRICE_ALERT_PREFERENCES,\n} from './validators.js';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage.js';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n AuthenticatedUserStorageServiceGetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceSetAssetsWatchlistAction,\n} from './authenticated-user-storage-method-action-types.js';\nexport { getUserStorageApiUrl } from './env.js';\nexport type { Environment } from './env.js';\nexport type {\n Caveat,\n SignedDelegation,\n DelegationMetadata,\n DelegationSubmission,\n DelegationResponse,\n WalletActivityAccount,\n WalletActivityPreference,\n MarketingPreference,\n PerpsWatchlistExchange,\n PerpsWatchlistMarkets,\n PerpsPreference,\n SocialAIPreference,\n AgenticCliPreference,\n PriceAlertPreference,\n NotificationPreferences,\n AssetsWatchlistBlob,\n ClientType,\n} from './types.js';\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\n// Delegations\n// ---------------------------------------------------------------------------\n\n/** A single caveat attached to a delegation. */\nexport type Caveat = {\n /** Address of the caveat enforcer contract (0x-prefixed). */\n enforcer: Hex;\n /** ABI-encoded caveat terms (0x-prefixed). */\n terms: Hex;\n /** ABI-encoded caveat arguments (0x-prefixed). */\n args: Hex;\n};\n\n/** An EIP-712 signed delegation. */\nexport type SignedDelegation = {\n /** Address the delegation is granted to (0x-prefixed). */\n delegate: Hex;\n /** Address granting the delegation (0x-prefixed). */\n delegator: Hex;\n /** Root authority or parent delegation hash (0x-prefixed). */\n authority: Hex;\n /** Caveats restricting how the delegation may be used. */\n caveats: Caveat[];\n /** Unique salt to prevent replay (0x-prefixed). */\n salt: Hex;\n /** EIP-712 signature over the delegation (0x-prefixed). */\n signature: Hex;\n};\n\n/** Metadata associated with a delegation. */\nexport type DelegationMetadata = {\n /** Keccak-256 hash uniquely identifying the delegation (0x-prefixed). */\n delegationHash: Hex;\n /** Chain ID in hex format (0x-prefixed). */\n chainIdHex: Hex;\n /** Token allowance in hex format (0x-prefixed). */\n allowance: Hex;\n /** Symbol of the token (e.g. \"USDC\"). */\n tokenSymbol: string;\n /** Token contract address (0x-prefixed). */\n tokenAddress: Hex;\n /** Type of delegation. */\n type: string;\n};\n\n/** Request body for submitting a new delegation. */\nexport type DelegationSubmission = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n/** A stored delegation record returned by the API. */\nexport type DelegationResponse = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n// ---------------------------------------------------------------------------\n// Preferences\n// ---------------------------------------------------------------------------\n\n/** Wallet activity tracking for a single address. */\nexport type WalletActivityAccount = {\n /** Wallet address to track activity for (0x-prefixed). */\n address: Hex;\n enabled: boolean;\n};\n\nexport type AgenticCliPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\nexport type WalletActivityPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n accounts: WalletActivityAccount[];\n};\n\nexport type MarketingPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\nexport type PerpsWatchlistExchange = {\n testnet: string[];\n mainnet: string[];\n};\n\nexport type PerpsWatchlistMarkets = {\n hyperliquid: PerpsWatchlistExchange;\n myx: PerpsWatchlistExchange;\n};\n\nexport type PerpsPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n watchlistMarkets?: PerpsWatchlistMarkets;\n};\n\nexport type SocialAIPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n txAmountLimit?: number;\n mutedTraderProfileIds: string[];\n};\n\nexport type PriceAlertPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\n/**\n * Notification preferences for the authenticated user.\n */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\n agenticCli: AgenticCliPreference;\n priceAlerts: PriceAlertPreference;\n};\n\n// ---------------------------------------------------------------------------\n// Assets watchlist\n// ---------------------------------------------------------------------------\n\n// `AssetsWatchlistBlob` is inferred from `AssetsWatchlistBlobSchema` in\n// `./validators` and re-exported here so the public type surface remains in\n// `./types`. Keeping the runtime schema and the static type co-located in\n// one file keeps the two in lock-step.\nexport type { AssetsWatchlistBlob } from './validators.js';\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
@@ -1,4 +1,4 @@
1
- import type { Hex } from '@metamask/utils';
1
+ import type { Hex } from "@metamask/utils";
2
2
  /** A single caveat attached to a delegation. */
3
3
  export type Caveat = {
4
4
  /** Address of the caveat enforcer contract (0x-prefixed). */
@@ -101,7 +101,7 @@ export type NotificationPreferences = {
101
101
  agenticCli: AgenticCliPreference;
102
102
  priceAlerts: PriceAlertPreference;
103
103
  };
104
- export type { AssetsWatchlistBlob } from './validators.js';
104
+ export type { AssetsWatchlistBlob } from "./validators.cjs";
105
105
  /** The type of client making the request. */
106
106
  export type ClientType = 'extension' | 'mobile' | 'portfolio';
107
- //# sourceMappingURL=types.d.ts.map
107
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAM3C,gDAAgD;AAChD,MAAM,MAAM,MAAM,GAAG;IACnB,6DAA6D;IAC7D,QAAQ,EAAE,GAAG,CAAC;IACd,8CAA8C;IAC9C,KAAK,EAAE,GAAG,CAAC;IACX,kDAAkD;IAClD,IAAI,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,0DAA0D;IAC1D,QAAQ,EAAE,GAAG,CAAC;IACd,qDAAqD;IACrD,SAAS,EAAE,GAAG,CAAC;IACf,8DAA8D;IAC9D,SAAS,EAAE,GAAG,CAAC;IACf,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,mDAAmD;IACnD,IAAI,EAAE,GAAG,CAAC;IACV,2DAA2D;IAC3D,SAAS,EAAE,GAAG,CAAC;CAChB,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,kBAAkB,GAA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