@metamask-previews/authenticated-user-storage 3.0.2-preview-8bfa290fb → 4.0.0-preview-0a30e47

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 +12 -3
  2. package/dist/{authenticated-user-storage-method-action-types.d.mts → authenticated-user-storage-method-action-types.d.ts} +3 -4
  3. package/dist/authenticated-user-storage-method-action-types.d.ts.map +1 -0
  4. package/dist/{authenticated-user-storage-method-action-types.mjs → authenticated-user-storage-method-action-types.js} +1 -1
  5. package/dist/authenticated-user-storage-method-action-types.js.map +1 -0
  6. package/dist/{authenticated-user-storage.d.cts → authenticated-user-storage.d.ts} +10 -11
  7. package/dist/authenticated-user-storage.d.ts.map +1 -0
  8. package/dist/{authenticated-user-storage.mjs → authenticated-user-storage.js} +38 -70
  9. package/dist/authenticated-user-storage.js.map +1 -0
  10. package/dist/{env.d.cts → env.d.ts} +1 -1
  11. package/dist/env.d.ts.map +1 -0
  12. package/dist/{env.mjs → env.js} +1 -1
  13. package/dist/env.js.map +1 -0
  14. package/dist/{index.d.cts → index.d.ts} +8 -8
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +4 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/{types.d.cts → types.d.ts} +3 -3
  19. package/dist/types.d.ts.map +1 -0
  20. package/dist/types.js +2 -0
  21. package/dist/types.js.map +1 -0
  22. package/dist/{validators.d.mts → validators.d.ts} +3 -3
  23. package/dist/validators.d.ts.map +1 -0
  24. package/dist/{validators.mjs → validators.js} +2 -2
  25. package/dist/validators.js.map +1 -0
  26. package/package.json +17 -21
  27. package/dist/authenticated-user-storage-method-action-types.cjs +0 -7
  28. package/dist/authenticated-user-storage-method-action-types.cjs.map +0 -1
  29. package/dist/authenticated-user-storage-method-action-types.d.cts +0 -84
  30. package/dist/authenticated-user-storage-method-action-types.d.cts.map +0 -1
  31. package/dist/authenticated-user-storage-method-action-types.d.mts.map +0 -1
  32. package/dist/authenticated-user-storage-method-action-types.mjs.map +0 -1
  33. package/dist/authenticated-user-storage.cjs +0 -301
  34. package/dist/authenticated-user-storage.cjs.map +0 -1
  35. package/dist/authenticated-user-storage.d.cts.map +0 -1
  36. package/dist/authenticated-user-storage.d.mts +0 -143
  37. package/dist/authenticated-user-storage.d.mts.map +0 -1
  38. package/dist/authenticated-user-storage.mjs.map +0 -1
  39. package/dist/env.cjs +0 -24
  40. package/dist/env.cjs.map +0 -1
  41. package/dist/env.d.cts.map +0 -1
  42. package/dist/env.d.mts +0 -10
  43. package/dist/env.d.mts.map +0 -1
  44. package/dist/env.mjs.map +0 -1
  45. package/dist/index.cjs +0 -13
  46. package/dist/index.cjs.map +0 -1
  47. package/dist/index.d.cts.map +0 -1
  48. package/dist/index.d.mts +0 -8
  49. package/dist/index.d.mts.map +0 -1
  50. package/dist/index.mjs +0 -4
  51. package/dist/index.mjs.map +0 -1
  52. package/dist/types.cjs +0 -3
  53. package/dist/types.cjs.map +0 -1
  54. package/dist/types.d.cts.map +0 -1
  55. package/dist/types.d.mts +0 -106
  56. package/dist/types.d.mts.map +0 -1
  57. package/dist/types.mjs +0 -2
  58. package/dist/types.mjs.map +0 -1
  59. package/dist/validators.cjs +0 -172
  60. package/dist/validators.cjs.map +0 -1
  61. package/dist/validators.d.cts +0 -84
  62. package/dist/validators.d.cts.map +0 -1
  63. package/dist/validators.d.mts.map +0 -1
  64. package/dist/validators.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.0.0]
11
+
10
12
  ### Changed
11
13
 
12
- - Route `setAssetsWatchlist` through `BaseDataService.executeMutation` so
13
- watchlist writes are not cached, deduplicated, or retried.
14
+ - **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
15
+ - 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.
16
+ - **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
17
+ - **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
18
+ - This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
14
19
  - Bump `@metamask/utils` from `^11.11.0` to `^11.12.0` ([#10076](https://github.com/MetaMask/core/pull/10076))
20
+ - Bump `@metamask/base-data-service` from `^1.0.0` to `^2.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
21
+ - Bump `@metamask/controller-utils` from `^12.3.0` to `^13.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
22
+ - Bump `@metamask/messenger` from `^2.0.0` to `^3.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
15
23
 
16
24
  ### Removed
17
25
 
@@ -92,7 +100,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
92
100
 
93
101
  - **BREAKING**: Rename `SocialAIPreference.traderProfileIds` to `mutedTraderProfileIds` in types and notification-preferences validation to match the API payload. ([#8536](https://github.com/MetaMask/core/pull/8536))
94
102
 
95
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/authenticated-user-storage@3.0.2...HEAD
103
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/authenticated-user-storage@4.0.0...HEAD
104
+ [4.0.0]: https://github.com/MetaMask/core/compare/@metamask/authenticated-user-storage@3.0.2...@metamask/authenticated-user-storage@4.0.0
96
105
  [3.0.2]: https://github.com/MetaMask/core/compare/@metamask/authenticated-user-storage@3.0.1...@metamask/authenticated-user-storage@3.0.2
97
106
  [3.0.1]: https://github.com/MetaMask/core/compare/@metamask/authenticated-user-storage@3.0.0...@metamask/authenticated-user-storage@3.0.1
98
107
  [3.0.0]: https://github.com/MetaMask/core/compare/@metamask/authenticated-user-storage@2.1.0...@metamask/authenticated-user-storage@3.0.0
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { AuthenticatedUserStorageService } from "./authenticated-user-storage.mjs";
5
+ import type { AuthenticatedUserStorageService } from './authenticated-user-storage.js';
6
6
  /**
7
7
  * Returns all delegation records belonging to the authenticated user.
8
8
  *
@@ -67,8 +67,7 @@ export type AuthenticatedUserStorageServiceGetAssetsWatchlistAction = {
67
67
  * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
68
68
  * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
69
69
  * request is sent.
70
- * @param clientTypeOrGlobalId - Optional client type header or mutation ID.
71
- * @param globalId - Optional mutation ID when a client type is provided.
70
+ * @param clientType - Optional client type header.
72
71
  * @throws A `StructError` from `@metamask/superstruct` if `blob` is
73
72
  * structurally invalid or `assets` exceeds the cap; an `HttpError` from
74
73
  * `@metamask/controller-utils` if the API responds with a non-2xx status.
@@ -81,4 +80,4 @@ export type AuthenticatedUserStorageServiceSetAssetsWatchlistAction = {
81
80
  * Union of all AuthenticatedUserStorageService action types.
82
81
  */
83
82
  export type AuthenticatedUserStorageServiceMethodActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceRevokeDelegationAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction | AuthenticatedUserStorageServiceGetAssetsWatchlistAction | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;
84
- //# sourceMappingURL=authenticated-user-storage-method-action-types.d.mts.map
83
+ //# sourceMappingURL=authenticated-user-storage-method-action-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.d.ts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;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
  export {};
6
- //# sourceMappingURL=authenticated-user-storage-method-action-types.mjs.map
6
+ //# sourceMappingURL=authenticated-user-storage-method-action-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.js","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AuthenticatedUserStorageService } from './authenticated-user-storage.js';\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 */\nexport type AuthenticatedUserStorageServiceListDelegationsAction = {\n type: `AuthenticatedUserStorageService:listDelegations`;\n handler: AuthenticatedUserStorageService['listDelegations'];\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 */\nexport type AuthenticatedUserStorageServiceCreateDelegationAction = {\n type: `AuthenticatedUserStorageService:createDelegation`;\n handler: AuthenticatedUserStorageService['createDelegation'];\n};\n\n/**\n * Revokes (deletes) a delegation record.\n *\n * @param delegationHash - The unique hash identifying the delegation.\n */\nexport type AuthenticatedUserStorageServiceRevokeDelegationAction = {\n type: `AuthenticatedUserStorageService:revokeDelegation`;\n handler: AuthenticatedUserStorageService['revokeDelegation'];\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 */\nexport type AuthenticatedUserStorageServiceGetNotificationPreferencesAction = {\n type: `AuthenticatedUserStorageService:getNotificationPreferences`;\n handler: AuthenticatedUserStorageService['getNotificationPreferences'];\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 */\nexport type AuthenticatedUserStorageServicePutNotificationPreferencesAction = {\n type: `AuthenticatedUserStorageService:putNotificationPreferences`;\n handler: AuthenticatedUserStorageService['putNotificationPreferences'];\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 */\nexport type AuthenticatedUserStorageServiceGetAssetsWatchlistAction = {\n type: `AuthenticatedUserStorageService:getAssetsWatchlist`;\n handler: AuthenticatedUserStorageService['getAssetsWatchlist'];\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 */\nexport type AuthenticatedUserStorageServiceSetAssetsWatchlistAction = {\n type: `AuthenticatedUserStorageService:setAssetsWatchlist`;\n handler: AuthenticatedUserStorageService['setAssetsWatchlist'];\n};\n\n/**\n * Union of all AuthenticatedUserStorageService action types.\n */\nexport type AuthenticatedUserStorageServiceMethodActions =\n | AuthenticatedUserStorageServiceListDelegationsAction\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceRevokeDelegationAction\n | AuthenticatedUserStorageServiceGetNotificationPreferencesAction\n | AuthenticatedUserStorageServicePutNotificationPreferencesAction\n | AuthenticatedUserStorageServiceGetAssetsWatchlistAction\n | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;\n"]}
@@ -1,10 +1,10 @@
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.cjs";
6
- import type { Environment } from "./env.cjs";
7
- import type { AssetsWatchlistBlob, ClientType, DelegationResponse, DelegationSubmission, NotificationPreferences } from "./types.cjs";
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.js';
6
+ import type { Environment } from './env.js';
7
+ import type { AssetsWatchlistBlob, ClientType, DelegationResponse, DelegationSubmission, NotificationPreferences } from './types.js';
8
8
  /**
9
9
  * The name of the {@link AuthenticatedUserStorageService} service, used to
10
10
  * namespace the service's actions and events.
@@ -131,13 +131,12 @@ export declare class AuthenticatedUserStorageService extends BaseDataService<typ
131
131
  * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
132
132
  * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
133
133
  * request is sent.
134
- * @param clientTypeOrGlobalId - Optional client type header or mutation ID.
135
- * @param globalId - Optional mutation ID when a client type is provided.
134
+ * @param clientType - Optional client type header.
136
135
  * @throws A `StructError` from `@metamask/superstruct` if `blob` is
137
136
  * structurally invalid or `assets` exceeds the cap; an `HttpError` from
138
137
  * `@metamask/controller-utils` if the API responds with a non-2xx status.
139
138
  */
140
- setAssetsWatchlist(blob: AssetsWatchlistBlob, clientTypeOrGlobalId?: ClientType | string, globalId?: string): Promise<void>;
139
+ setAssetsWatchlist(blob: AssetsWatchlistBlob, clientType?: ClientType): Promise<void>;
141
140
  }
142
141
  export {};
143
- //# sourceMappingURL=authenticated-user-storage.d.cts.map
142
+ //# sourceMappingURL=authenticated-user-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticated-user-storage.d.ts","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KA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FieldSet) || 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";
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';
17
5
  // === GENERAL ===
18
6
  /**
19
7
  * The name of the {@link AuthenticatedUserStorageService} service, used to
20
8
  * namespace the service's actions and events.
21
9
  */
22
10
  export const serviceName = 'AuthenticatedUserStorageService';
23
- /**
24
- * Checks whether a value is a supported client type.
25
- *
26
- * This distinguishes the existing client-type argument from the optional
27
- * mutation global ID when the method is invoked through a UI query client.
28
- *
29
- * @param value - The value to check.
30
- * @returns Whether the value is a client type.
31
- */
32
- function isClientType(value) {
33
- return value === 'extension' || value === 'mobile' || value === 'portfolio';
34
- }
35
11
  /**
36
12
  * Builds the versioned API base URL for a given environment.
37
13
  *
@@ -59,6 +35,7 @@ const MESSENGER_EXPOSED_METHODS = [
59
35
  * for the authenticated user.
60
36
  */
61
37
  export class AuthenticatedUserStorageService extends BaseDataService {
38
+ #environment;
62
39
  /**
63
40
  * Constructs a new AuthenticatedUserStorageService.
64
41
  *
@@ -70,9 +47,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
70
47
  */
71
48
  constructor({ messenger, environment, policyOptions, }) {
72
49
  super({ name: serviceName, messenger, policyOptions });
73
- _AuthenticatedUserStorageService_instances.add(this);
74
- _AuthenticatedUserStorageService_environment.set(this, void 0);
75
- __classPrivateFieldSet(this, _AuthenticatedUserStorageService_environment, environment, "f");
50
+ this.#environment = environment;
76
51
  this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
77
52
  }
78
53
  /**
@@ -81,11 +56,11 @@ export class AuthenticatedUserStorageService extends BaseDataService {
81
56
  * @returns An array of delegation records, or an empty array if none exist.
82
57
  */
83
58
  async listDelegations() {
84
- const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/delegations`;
59
+ const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;
85
60
  const data = await this.fetchQuery({
86
61
  queryKey: [`${this.name}:listDelegations`],
87
62
  queryFn: async () => {
88
- const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
63
+ const headers = await this.#getHeaders();
89
64
  const response = await fetch(url, { headers });
90
65
  if (!response.ok) {
91
66
  throw new HttpError(response.status, `Failed to list delegations: ${response.status}`);
@@ -103,7 +78,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
103
78
  * @param clientType - Optional client type header.
104
79
  */
105
80
  async createDelegation(submission, clientType) {
106
- const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/delegations`;
81
+ const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;
107
82
  await this.fetchQuery({
108
83
  queryKey: [
109
84
  `${this.name}:createDelegation`,
@@ -111,7 +86,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
111
86
  ],
112
87
  staleTime: 0,
113
88
  queryFn: async () => {
114
- const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
89
+ const headers = await this.#getHeaders(clientType);
115
90
  const response = await fetch(url, {
116
91
  method: 'POST',
117
92
  headers,
@@ -133,12 +108,12 @@ export class AuthenticatedUserStorageService extends BaseDataService {
133
108
  * @param delegationHash - The unique hash identifying the delegation.
134
109
  */
135
110
  async revokeDelegation(delegationHash) {
136
- const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/delegations/${encodeURIComponent(delegationHash)}`;
111
+ const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations/${encodeURIComponent(delegationHash)}`;
137
112
  await this.fetchQuery({
138
113
  queryKey: [`${this.name}:revokeDelegation`, delegationHash],
139
114
  staleTime: 0,
140
115
  queryFn: async () => {
141
- const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
116
+ const headers = await this.#getHeaders();
142
117
  const response = await fetch(url, {
143
118
  method: 'DELETE',
144
119
  headers,
@@ -160,11 +135,11 @@ export class AuthenticatedUserStorageService extends BaseDataService {
160
135
  * set (404).
161
136
  */
162
137
  async getNotificationPreferences() {
163
- const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/notifications`;
138
+ const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;
164
139
  const data = await this.fetchQuery({
165
140
  queryKey: [`${this.name}:getNotificationPreferences`],
166
141
  queryFn: async () => {
167
- const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
142
+ const headers = await this.#getHeaders();
168
143
  const response = await fetch(url, { headers });
169
144
  if (response.status === 404) {
170
145
  return null;
@@ -188,7 +163,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
188
163
  * @param clientType - Optional client type header.
189
164
  */
190
165
  async putNotificationPreferences(prefs, clientType) {
191
- const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/notifications`;
166
+ const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;
192
167
  await this.fetchQuery({
193
168
  queryKey: [
194
169
  `${this.name}:putNotificationPreferences`,
@@ -196,7 +171,7 @@ export class AuthenticatedUserStorageService extends BaseDataService {
196
171
  ],
197
172
  staleTime: 0,
198
173
  queryFn: async () => {
199
- const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
174
+ const headers = await this.#getHeaders(clientType);
200
175
  const response = await fetch(url, {
201
176
  method: 'PUT',
202
177
  headers,
@@ -218,11 +193,11 @@ export class AuthenticatedUserStorageService extends BaseDataService {
218
193
  * @returns The assets-watchlist blob, or `null` if none has been set (404).
219
194
  */
220
195
  async getAssetsWatchlist() {
221
- const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/assets-watchlist`;
196
+ const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;
222
197
  const data = await this.fetchQuery({
223
198
  queryKey: [`${this.name}:getAssetsWatchlist`],
224
199
  queryFn: async () => {
225
- const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
200
+ const headers = await this.#getHeaders();
226
201
  const response = await fetch(url, { headers });
227
202
  if (response.status === 404) {
228
203
  return null;
@@ -246,26 +221,19 @@ export class AuthenticatedUserStorageService extends BaseDataService {
246
221
  * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
247
222
  * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
248
223
  * request is sent.
249
- * @param clientTypeOrGlobalId - Optional client type header or mutation ID.
250
- * @param globalId - Optional mutation ID when a client type is provided.
224
+ * @param clientType - Optional client type header.
251
225
  * @throws A `StructError` from `@metamask/superstruct` if `blob` is
252
226
  * structurally invalid or `assets` exceeds the cap; an `HttpError` from
253
227
  * `@metamask/controller-utils` if the API responds with a non-2xx status.
254
228
  */
255
- async setAssetsWatchlist(blob, clientTypeOrGlobalId, globalId) {
229
+ async setAssetsWatchlist(blob, clientType) {
256
230
  assertAssetsWatchlistBlobForWrite(blob);
257
- const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/preferences/assets-watchlist`;
258
- const clientType = isClientType(clientTypeOrGlobalId)
259
- ? clientTypeOrGlobalId
260
- : undefined;
261
- const mutationGlobalId = clientType
262
- ? globalId
263
- : (globalId ?? clientTypeOrGlobalId);
264
- await this.executeMutation({
265
- mutationKey: [`${this.name}:setAssetsWatchlist`, blob],
266
- globalId: mutationGlobalId,
267
- mutationFn: async () => {
268
- const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
231
+ const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;
232
+ await this.fetchQuery({
233
+ queryKey: [`${this.name}:setAssetsWatchlist`, blob],
234
+ staleTime: 0,
235
+ queryFn: async () => {
236
+ const headers = await this.#getHeaders(clientType);
269
237
  const response = await fetch(url, {
270
238
  method: 'PUT',
271
239
  headers,
@@ -281,16 +249,16 @@ export class AuthenticatedUserStorageService extends BaseDataService {
281
249
  queryKey: [`${this.name}:getAssetsWatchlist`],
282
250
  });
283
251
  }
284
- }
285
- _AuthenticatedUserStorageService_environment = new WeakMap(), _AuthenticatedUserStorageService_instances = new WeakSet(), _AuthenticatedUserStorageService_getHeaders = async function _AuthenticatedUserStorageService_getHeaders(clientType) {
286
- const accessToken = await this.messenger.call('AuthenticationController:getBearerToken');
287
- const headers = {
288
- 'Content-Type': 'application/json',
289
- Authorization: `Bearer ${accessToken}`,
290
- };
291
- if (clientType) {
292
- headers['X-Client-Type'] = clientType;
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;
293
262
  }
294
- return headers;
295
- };
296
- //# sourceMappingURL=authenticated-user-storage.mjs.map
263
+ }
264
+ //# sourceMappingURL=authenticated-user-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticated-user-storage.js","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAMvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAQhD,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,iBAAiB,CAAC;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;IAC5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,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;IAED,KAAK,CAAC,WAAW,CAAC,UAAuB;QACvC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAC3C,yCAAyC,CAC1C,CAAC;QACF,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;QACF,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC;QACxC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","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"]}
@@ -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.cts.map
10
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","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.mjs.map
20
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","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"]}
@@ -1,8 +1,8 @@
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
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,uDAAuD,EACvD,uDAAuD,GACxD,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;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,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
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 { getUserStorageApiUrl } from './env.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AAkBzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC","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,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). */
@@ -100,7 +100,7 @@ export type NotificationPreferences = {
100
100
  agenticCli: AgenticCliPreference;
101
101
  priceAlerts: PriceAlertPreference;
102
102
  };
103
- export type { AssetsWatchlistBlob } from "./validators.cjs";
103
+ export type { AssetsWatchlistBlob } from './validators.js';
104
104
  /** The type of client making the request. */
105
105
  export type ClientType = 'extension' | 'mobile' | 'portfolio';
106
- //# sourceMappingURL=types.d.cts.map
106
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;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,MAA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@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","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};\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,5 +1,5 @@
1
- import type { Infer } from "@metamask/superstruct";
2
- import type { AgenticCliPreference, DelegationResponse, NotificationPreferences, PriceAlertPreference } from "./types.mjs";
1
+ import type { Infer } from '@metamask/superstruct';
2
+ import type { AgenticCliPreference, DelegationResponse, NotificationPreferences, PriceAlertPreference } from './types.js';
3
3
  /**
4
4
  * Default Agentic CLI notification preferences for consumers building a
5
5
  * fresh `NotificationPreferences` object.
@@ -81,4 +81,4 @@ export declare function assertAssetsWatchlistBlob(data: unknown): asserts data i
81
81
  */
82
82
  export declare function assertAssetsWatchlistBlobForWrite(data: unknown): asserts data is AssetsWatchlistBlob;
83
83
  export {};
84
- //# sourceMappingURL=validators.d.mts.map
84
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAenD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAgGpB;;;GAGG;AACH,eAAO,MAAM,+BAA+B,EAAE,oBAG7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,EAAE,oBAG7C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;GAKG;AACH,QAAA,MAAM,yBAAyB;;;;;;EAG7B,CAAC;AAgBH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,uBAAuB,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC"}
@@ -1,4 +1,4 @@
1
- import { array, assert, assign, boolean, literal, number, optional, pattern, size, string, type } from "@metamask/superstruct";
1
+ import { array, assert, assign, boolean, literal, number, optional, pattern, size, string, type, } from '@metamask/superstruct';
2
2
  /**
3
3
  * Matches a 0x-prefixed hex string with zero or more hex digits.
4
4
  * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least
@@ -162,4 +162,4 @@ export function assertAssetsWatchlistBlob(data) {
162
162
  export function assertAssetsWatchlistBlobForWrite(data) {
163
163
  assert(data, AssetsWatchlistBlobWriteSchema);
164
164
  }
165
- //# sourceMappingURL=validators.mjs.map
165
+ //# sourceMappingURL=validators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,IAAI,GACL,MAAM,uBAAuB,CAAC;AAS/B;;;;;GAKG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,aAAa;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,CAAC;IAClC,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,aAAa;IACxB,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,KAAK,CAAC,YAAY,CAAC;IAC5B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,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AC,EAAE,2BAA2B,CAAC;CAC9D,CAAC,CACH,CAAC;AAoBF;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,IAAa;IAEb,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC;AAChD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,IAAa;IAEb,MAAM,CAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CACvC,IAAa;IAEb,MAAM,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iCAAiC,CAC/C,IAAa;IAEb,MAAM,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n array,\n assert,\n assign,\n boolean,\n literal,\n number,\n optional,\n pattern,\n size,\n string,\n type,\n} from '@metamask/superstruct';\n\nimport type {\n AgenticCliPreference,\n DelegationResponse,\n NotificationPreferences,\n PriceAlertPreference,\n} from './types.js';\n\n/**\n * Matches a 0x-prefixed hex string with zero or more hex digits.\n * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least\n * one digit after the prefix), this also accepts `\"0x\"` — the standard\n * encoding for empty bytes that the delegation API returns.\n */\nconst HexDataStruct = pattern(string(), /^0x[0-9a-f]*$/iu);\n\nconst CaveatSchema = type({\n enforcer: HexDataStruct,\n terms: HexDataStruct,\n args: HexDataStruct,\n});\n\nconst SignedDelegationSchema = type({\n delegate: HexDataStruct,\n delegator: HexDataStruct,\n authority: HexDataStruct,\n caveats: array(CaveatSchema),\n salt: HexDataStruct,\n signature: HexDataStruct,\n});\n\nconst DelegationMetadataSchema = type({\n delegationHash: HexDataStruct,\n chainIdHex: HexDataStruct,\n allowance: HexDataStruct,\n tokenSymbol: string(),\n tokenAddress: HexDataStruct,\n type: string(),\n});\n\nconst DelegationResponseSchema = type({\n signedDelegation: SignedDelegationSchema,\n metadata: DelegationMetadataSchema,\n});\n\nconst WalletActivityAccountSchema = type({\n address: HexDataStruct,\n enabled: boolean(),\n});\n\nconst WalletActivityPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n accounts: array(WalletActivityAccountSchema),\n});\n\nconst MarketingPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst PerpsWatchlistExchangeSchema = type({\n testnet: array(string()),\n mainnet: array(string()),\n});\n\nconst PerpsWatchlistMarketsSchema = type({\n hyperliquid: PerpsWatchlistExchangeSchema,\n});\n\nconst PerpsPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n watchlistMarkets: optional(PerpsWatchlistMarketsSchema),\n});\n\nconst SocialAIPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n txAmountLimit: optional(number()),\n mutedTraderProfileIds: array(string()),\n});\n\nconst AgenticCliPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst PriceAlertPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n agenticCli: AgenticCliPreferenceSchema,\n priceAlerts: PriceAlertPreferenceSchema,\n});\n\n/**\n * Default Agentic CLI notification preferences for consumers building a\n * fresh `NotificationPreferences` object.\n */\nexport const DEFAULT_AGENTIC_CLI_PREFERENCES: AgenticCliPreference = {\n inAppNotificationsEnabled: true,\n pushNotificationsEnabled: true,\n};\n\n/**\n * Default price-alert notification preferences for consumers building a\n * fresh `NotificationPreferences` object.\n */\nexport const DEFAULT_PRICE_ALERT_PREFERENCES: PriceAlertPreference = {\n inAppNotificationsEnabled: true,\n pushNotificationsEnabled: true,\n};\n\n/**\n * Maximum number of entries allowed in an assets-watchlist on write. Reads\n * are lenient: a server payload exceeding this size will still validate as\n * an `AssetsWatchlistBlob`. Encoded into\n * {@link AssetsWatchlistBlobWriteSchema}.\n */\nexport const ASSETS_WATCHLIST_MAX_ASSETS = 100;\n\n/**\n * The shape we accept on the way **in** from the server. Lenient by design:\n * a malformed payload throws, but a well-formed payload with more than\n * {@link ASSETS_WATCHLIST_MAX_ASSETS} assets is still considered valid so we\n * don't reject existing server-side data.\n */\nconst AssetsWatchlistBlobSchema = type({\n version: literal(1),\n assets: array(string()),\n});\n\n/**\n * The shape we accept on the way **out** to the server. Extends\n * {@link AssetsWatchlistBlobSchema} with a hard cap on `assets.length`.\n * Validation failures throw a `StructError`, e.g.\n * `\"At path: assets -- Expected a array with a length between \\`0\\` and\n * \\`100\\` but received one with a length of \\`N\\`\"`.\n */\nconst AssetsWatchlistBlobWriteSchema = assign(\n AssetsWatchlistBlobSchema,\n type({\n assets: size(array(string()), 0, ASSETS_WATCHLIST_MAX_ASSETS),\n }),\n);\n\n/**\n * The authenticated user's assets-watchlist: a mutable per-user singleton\n * blob.\n *\n * Each entry is a CAIP-19 asset identifier\n * (e.g. `eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48`).\n *\n * The `version` literal is carried inside the blob (not in the URL) so the\n * schema can evolve in a backwards-compatible way; bumping the version\n * indicates a different `assets` element shape.\n *\n * Inferred from {@link AssetsWatchlistBlobSchema} so the runtime schema and\n * the static type stay in lock-step. The size constraint on writes is\n * enforced by {@link AssetsWatchlistBlobWriteSchema} and is not encoded in\n * this static type (TypeScript cannot express \"array of length ≤ N\").\n */\nexport type AssetsWatchlistBlob = Infer<typeof AssetsWatchlistBlobSchema>;\n\n/**\n * Asserts that the given value is a valid `DelegationResponse[]`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertDelegationResponseArray(\n data: unknown,\n): asserts data is DelegationResponse[] {\n assert(data, array(DelegationResponseSchema));\n}\n\n/**\n * Asserts that the given value is a valid `NotificationPreferences`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertNotificationPreferences(\n data: unknown,\n): asserts data is NotificationPreferences {\n assert(data, NotificationPreferencesSchema);\n}\n\n/**\n * Asserts that the given value is a valid `AssetsWatchlistBlob` (read-side,\n * lenient).\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertAssetsWatchlistBlob(\n data: unknown,\n): asserts data is AssetsWatchlistBlob {\n assert(data, AssetsWatchlistBlobSchema);\n}\n\n/**\n * Asserts that the given value is a valid `AssetsWatchlistBlob` for\n * **writes**. In addition to the structural checks performed by\n * {@link assertAssetsWatchlistBlob}, this enforces that `assets` contains at\n * most {@link ASSETS_WATCHLIST_MAX_ASSETS} entries.\n *\n * @param data - The unknown value to validate.\n * @throws A `StructError` if the value does not match the expected schema\n * (including the size constraint).\n */\nexport function assertAssetsWatchlistBlobForWrite(\n data: unknown,\n): asserts data is AssetsWatchlistBlob {\n assert(data, AssetsWatchlistBlobWriteSchema);\n}\n"]}