@metamask-previews/authenticated-user-storage 2.1.0-preview-48e768b22 → 2.1.0-preview-1bd5239bf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/authenticated-user-storage-method-action-types.cjs.map +1 -1
- package/dist/authenticated-user-storage-method-action-types.d.cts +0 -6
- package/dist/authenticated-user-storage-method-action-types.d.cts.map +1 -1
- package/dist/authenticated-user-storage-method-action-types.d.mts +0 -6
- package/dist/authenticated-user-storage-method-action-types.d.mts.map +1 -1
- package/dist/authenticated-user-storage-method-action-types.mjs.map +1 -1
- package/dist/authenticated-user-storage.cjs +2 -13
- package/dist/authenticated-user-storage.cjs.map +1 -1
- package/dist/authenticated-user-storage.d.cts +0 -6
- package/dist/authenticated-user-storage.d.cts.map +1 -1
- package/dist/authenticated-user-storage.d.mts +0 -6
- package/dist/authenticated-user-storage.d.mts.map +1 -1
- package/dist/authenticated-user-storage.mjs +3 -14
- package/dist/authenticated-user-storage.mjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +6 -7
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +6 -7
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/validators.cjs +16 -3
- package/dist/validators.cjs.map +1 -1
- package/dist/validators.d.cts +8 -3
- package/dist/validators.d.cts.map +1 -1
- package/dist/validators.d.mts +8 -3
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +15 -2
- package/dist/validators.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `PriceAlertPreference` type, required `priceAlerts` field on `NotificationPreferences`, and `DEFAULT_PRICE_ALERT_PREFERENCES` constant ([#9316](https://github.com/MetaMask/core/pull/9316))
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- **BREAKING:** Make `agenticCli` required on `NotificationPreferences` (previously optional on the type) ([#9316](https://github.com/MetaMask/core/pull/9316))
|
|
17
|
+
- Remove client-side backfill of `agenticCli` and `priceAlerts` in `getNotificationPreferences`; the API merges defaults on GET ([#9316](https://github.com/MetaMask/core/pull/9316))
|
|
18
|
+
|
|
10
19
|
## [2.1.0]
|
|
11
20
|
|
|
12
21
|
### Added
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticated-user-storage-method-action-types.cjs","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';\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 *
|
|
1
|
+
{"version":3,"file":"authenticated-user-storage-method-action-types.cjs","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';\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"]}
|
|
@@ -34,12 +34,6 @@ export type AuthenticatedUserStorageServiceRevokeDelegationAction = {
|
|
|
34
34
|
/**
|
|
35
35
|
* Returns the notification preferences for the authenticated user.
|
|
36
36
|
*
|
|
37
|
-
* Legacy payloads that omit `agenticCli` are coerced with
|
|
38
|
-
* {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns
|
|
39
|
-
* a non-`null` value, `agenticCli` is always present (backfilled), even
|
|
40
|
-
* though {@link NotificationPreferences} marks it optional until the next
|
|
41
|
-
* major release.
|
|
42
|
-
*
|
|
43
37
|
* @returns The notification preferences object, or `null` if none have been
|
|
44
38
|
* set (404).
|
|
45
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticated-user-storage-method-action-types.d.cts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"authenticated-user-storage-method-action-types.d.cts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,+BAA+B,CAAC,4BAA4B,CAAC,CAAC;CACxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,+BAA+B,CAAC,4BAA4B,CAAC,CAAC;CACxE,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4CAA4C,GACpD,oDAAoD,GACpD,qDAAqD,GACrD,qDAAqD,GACrD,+DAA+D,GAC/D,+DAA+D,GAC/D,uDAAuD,GACvD,uDAAuD,CAAC"}
|
|
@@ -34,12 +34,6 @@ export type AuthenticatedUserStorageServiceRevokeDelegationAction = {
|
|
|
34
34
|
/**
|
|
35
35
|
* Returns the notification preferences for the authenticated user.
|
|
36
36
|
*
|
|
37
|
-
* Legacy payloads that omit `agenticCli` are coerced with
|
|
38
|
-
* {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns
|
|
39
|
-
* a non-`null` value, `agenticCli` is always present (backfilled), even
|
|
40
|
-
* though {@link NotificationPreferences} marks it optional until the next
|
|
41
|
-
* major release.
|
|
42
|
-
*
|
|
43
37
|
* @returns The notification preferences object, or `null` if none have been
|
|
44
38
|
* set (404).
|
|
45
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticated-user-storage-method-action-types.d.mts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"authenticated-user-storage-method-action-types.d.mts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,+BAA+B,CAAC,4BAA4B,CAAC,CAAC;CACxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,+BAA+B,CAAC,4BAA4B,CAAC,CAAC;CACxE,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4CAA4C,GACpD,oDAAoD,GACpD,qDAAqD,GACrD,qDAAqD,GACrD,+DAA+D,GAC/D,+DAA+D,GAC/D,uDAAuD,GACvD,uDAAuD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticated-user-storage-method-action-types.mjs","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';\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 *
|
|
1
|
+
{"version":3,"file":"authenticated-user-storage-method-action-types.mjs","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';\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"]}
|
|
@@ -148,12 +148,6 @@ class AuthenticatedUserStorageService extends base_data_service_1.BaseDataServic
|
|
|
148
148
|
/**
|
|
149
149
|
* Returns the notification preferences for the authenticated user.
|
|
150
150
|
*
|
|
151
|
-
* Legacy payloads that omit `agenticCli` are coerced with
|
|
152
|
-
* {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns
|
|
153
|
-
* a non-`null` value, `agenticCli` is always present (backfilled), even
|
|
154
|
-
* though {@link NotificationPreferences} marks it optional until the next
|
|
155
|
-
* major release.
|
|
156
|
-
*
|
|
157
151
|
* @returns The notification preferences object, or `null` if none have been
|
|
158
152
|
* set (404).
|
|
159
153
|
*/
|
|
@@ -176,13 +170,8 @@ class AuthenticatedUserStorageService extends base_data_service_1.BaseDataServic
|
|
|
176
170
|
if (data === null) {
|
|
177
171
|
return null;
|
|
178
172
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
...data,
|
|
182
|
-
agenticCli: data.agenticCli ?? { ...validators_1.DEFAULT_AGENTIC_CLI_PREFERENCES },
|
|
183
|
-
};
|
|
184
|
-
(0, validators_1.assertNotificationPreferences)(backfilledData);
|
|
185
|
-
return backfilledData;
|
|
173
|
+
(0, validators_1.assertNotificationPreferences)(data);
|
|
174
|
+
return data;
|
|
186
175
|
}
|
|
187
176
|
/**
|
|
188
177
|
* Creates or updates the notification preferences for the authenticated user.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticated-user-storage.cjs","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mEAA8D;AAE9D,iEAAuD;AAMvD,mCAA6C;AAQ7C,iDAMsB;AAEtB,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iCAAiC,CAAC;AAE7D;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,WAAwB;IACjE,OAAO,GAAG,IAAA,0BAAoB,EAAC,WAAW,CAAC,SAAS,CAAC;AACvD,CAAC;AAFD,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,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';\nimport type { Environment } from './env';\nimport { getUserStorageApiUrl } from './env';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertNotificationPreferences,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n} from './validators';\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 * Legacy payloads that omit `agenticCli` are coerced with\n * {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns\n * a non-`null` value, `agenticCli` is always present (backfilled), even\n * though {@link NotificationPreferences} marks it optional until the next\n * major release.\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 // backfill agenticCli preferences if it is undefined\n const backfilledData = {\n ...data,\n agenticCli: data.agenticCli ?? { ...DEFAULT_AGENTIC_CLI_PREFERENCES },\n };\n\n assertNotificationPreferences(backfilledData);\n return backfilledData;\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)}/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)}/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"]}
|
|
1
|
+
{"version":3,"file":"authenticated-user-storage.cjs","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mEAA8D;AAE9D,iEAAuD;AAMvD,mCAA6C;AAQ7C,iDAKsB;AAEtB,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iCAAiC,CAAC;AAE7D;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,WAAwB;IACjE,OAAO,GAAG,IAAA,0BAAoB,EAAC,WAAW,CAAC,SAAS,CAAC;AACvD,CAAC;AAFD,gEAEC;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,MAAa,+BAAgC,SAAQ,mCAGpD;IAGC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,WAAW,EACX,aAAa,GAKd;QACC,KAAK,CAAC,EAAE,IAAI,EAAE,mBAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC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,CAAC,SAAS,CAAC,IAAI,CAAC;iBAC3B,CAAC,CAAC;gBAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,4BAAS,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;AA3TD,0EA2TC;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';\nimport type { Environment } from './env';\nimport { getUserStorageApiUrl } from './env';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertNotificationPreferences,\n} from './validators';\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)}/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)}/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"]}
|
|
@@ -107,12 +107,6 @@ export declare class AuthenticatedUserStorageService extends BaseDataService<typ
|
|
|
107
107
|
/**
|
|
108
108
|
* Returns the notification preferences for the authenticated user.
|
|
109
109
|
*
|
|
110
|
-
* Legacy payloads that omit `agenticCli` are coerced with
|
|
111
|
-
* {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns
|
|
112
|
-
* a non-`null` value, `agenticCli` is always present (backfilled), even
|
|
113
|
-
* though {@link NotificationPreferences} marks it optional until the next
|
|
114
|
-
* major release.
|
|
115
|
-
*
|
|
116
110
|
* @returns The notification preferences object, or `null` if none have been
|
|
117
111
|
* set (404).
|
|
118
112
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticated-user-storage.d.cts","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,6DAAyD;AACrH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAc;AAEzC,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,oBAAgB;
|
|
1
|
+
{"version":3,"file":"authenticated-user-storage.d.cts","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,6DAAyD;AACrH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAc;AAEzC,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,oBAAgB;AAUjB;;;GAGG;AACH,eAAO,MAAM,WAAW,oCAAoC,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAE3E;AAcD;;GAEG;AACH,MAAM,M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AAI,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"}
|
|
@@ -107,12 +107,6 @@ export declare class AuthenticatedUserStorageService extends BaseDataService<typ
|
|
|
107
107
|
/**
|
|
108
108
|
* Returns the notification preferences for the authenticated user.
|
|
109
109
|
*
|
|
110
|
-
* Legacy payloads that omit `agenticCli` are coerced with
|
|
111
|
-
* {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns
|
|
112
|
-
* a non-`null` value, `agenticCli` is always present (backfilled), even
|
|
113
|
-
* though {@link NotificationPreferences} marks it optional until the next
|
|
114
|
-
* major release.
|
|
115
|
-
*
|
|
116
110
|
* @returns The notification preferences object, or `null` if none have been
|
|
117
111
|
* set (404).
|
|
118
112
|
*/
|
|
@@ -1 +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,6DAAyD;AACrH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAc;AAEzC,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,oBAAgB;
|
|
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,6DAAyD;AACrH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAc;AAEzC,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,oBAAgB;AAUjB;;;GAGG;AACH,eAAO,MAAM,WAAW,oCAAoC,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAE3E;AAcD;;GAEG;AACH,MAAM,MAAM,+CAA+C,GACzD,kCAAkC,CAAC,OAAO,WAAW,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GACvC,4CAA4C,GAC5C,+CAA+C,CAAC;AAEpD;;;GAGG;AACH,KAAK,4CAA4C,GAAG;IAClD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACxD,CAAC;AAEF;;;GAGG;AACH,KAAK,cAAc,GAAG,4CAA4C,CAAC;AAEnE;;GAEG;AACH,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;;;;;;;;;;;OAWG;IACG,kBAAkB,CACtB,IAAI,EAAE,mBAAmB,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;CA6CjB"}
|
|
@@ -13,7 +13,7 @@ var _AuthenticatedUserStorageService_instances, _AuthenticatedUserStorageService
|
|
|
13
13
|
import { BaseDataService } from "@metamask/base-data-service";
|
|
14
14
|
import { HttpError } from "@metamask/controller-utils";
|
|
15
15
|
import { getUserStorageApiUrl } from "./env.mjs";
|
|
16
|
-
import { assertAssetsWatchlistBlob, assertAssetsWatchlistBlobForWrite, assertDelegationResponseArray, assertNotificationPreferences
|
|
16
|
+
import { assertAssetsWatchlistBlob, assertAssetsWatchlistBlobForWrite, assertDelegationResponseArray, assertNotificationPreferences } from "./validators.mjs";
|
|
17
17
|
// === GENERAL ===
|
|
18
18
|
/**
|
|
19
19
|
* The name of the {@link AuthenticatedUserStorageService} service, used to
|
|
@@ -144,12 +144,6 @@ export class AuthenticatedUserStorageService extends BaseDataService {
|
|
|
144
144
|
/**
|
|
145
145
|
* Returns the notification preferences for the authenticated user.
|
|
146
146
|
*
|
|
147
|
-
* Legacy payloads that omit `agenticCli` are coerced with
|
|
148
|
-
* {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns
|
|
149
|
-
* a non-`null` value, `agenticCli` is always present (backfilled), even
|
|
150
|
-
* though {@link NotificationPreferences} marks it optional until the next
|
|
151
|
-
* major release.
|
|
152
|
-
*
|
|
153
147
|
* @returns The notification preferences object, or `null` if none have been
|
|
154
148
|
* set (404).
|
|
155
149
|
*/
|
|
@@ -172,13 +166,8 @@ export class AuthenticatedUserStorageService extends BaseDataService {
|
|
|
172
166
|
if (data === null) {
|
|
173
167
|
return null;
|
|
174
168
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
...data,
|
|
178
|
-
agenticCli: data.agenticCli ?? { ...DEFAULT_AGENTIC_CLI_PREFERENCES },
|
|
179
|
-
};
|
|
180
|
-
assertNotificationPreferences(backfilledData);
|
|
181
|
-
return backfilledData;
|
|
169
|
+
assertNotificationPreferences(data);
|
|
170
|
+
return data;
|
|
182
171
|
}
|
|
183
172
|
/**
|
|
184
173
|
* Creates or updates the notification preferences for the authenticated user.
|
|
@@ -1 +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,kBAAc;AAQ7C,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC7B,+BAA+B,EAChC,yBAAqB;AAEtB,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,+BAAgC,SAAQ,eAGpD;IAGC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,WAAW,EACX,aAAa,GAKd;QACC,KAAK,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;;QApBhD,+DAA0B;QAqBjC,uBAAA,IAAI,gDAAgB,WAAW,MAAA,CAAC;QAEhC,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CA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AC;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';\nimport type { Environment } from './env';\nimport { getUserStorageApiUrl } from './env';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertNotificationPreferences,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n} from './validators';\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 * Legacy payloads that omit `agenticCli` are coerced with\n * {@link DEFAULT_AGENTIC_CLI_PREFERENCES} on read. When this method returns\n * a non-`null` value, `agenticCli` is always present (backfilled), even\n * though {@link NotificationPreferences} marks it optional until the next\n * major release.\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 // backfill agenticCli preferences if it is undefined\n const backfilledData = {\n ...data,\n agenticCli: data.agenticCli ?? { ...DEFAULT_AGENTIC_CLI_PREFERENCES },\n };\n\n assertNotificationPreferences(backfilledData);\n return backfilledData;\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)}/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)}/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"]}
|
|
1
|
+
{"version":3,"file":"authenticated-user-storage.mjs","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":";;;;;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M,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';\nimport type { Environment } from './env';\nimport { getUserStorageApiUrl } from './env';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertNotificationPreferences,\n} from './validators';\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)}/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)}/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/index.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUserStorageApiUrl = exports.DEFAULT_AGENTIC_CLI_PREFERENCES = exports.ASSETS_WATCHLIST_MAX_ASSETS = exports.AuthenticatedUserStorageService = exports.getAuthenticatedStorageUrl = void 0;
|
|
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
4
|
var authenticated_user_storage_1 = require("./authenticated-user-storage.cjs");
|
|
5
5
|
Object.defineProperty(exports, "getAuthenticatedStorageUrl", { enumerable: true, get: function () { return authenticated_user_storage_1.getAuthenticatedStorageUrl; } });
|
|
6
6
|
Object.defineProperty(exports, "AuthenticatedUserStorageService", { enumerable: true, get: function () { return authenticated_user_storage_1.AuthenticatedUserStorageService; } });
|
|
7
7
|
var validators_1 = require("./validators.cjs");
|
|
8
8
|
Object.defineProperty(exports, "ASSETS_WATCHLIST_MAX_ASSETS", { enumerable: true, get: function () { return validators_1.ASSETS_WATCHLIST_MAX_ASSETS; } });
|
|
9
9
|
Object.defineProperty(exports, "DEFAULT_AGENTIC_CLI_PREFERENCES", { enumerable: true, get: function () { return validators_1.DEFAULT_AGENTIC_CLI_PREFERENCES; } });
|
|
10
|
+
Object.defineProperty(exports, "DEFAULT_PRICE_ALERT_PREFERENCES", { enumerable: true, get: function () { return validators_1.DEFAULT_PRICE_ALERT_PREFERENCES; } });
|
|
10
11
|
var env_1 = require("./env.cjs");
|
|
11
12
|
Object.defineProperty(exports, "getUserStorageApiUrl", { enumerable: true, get: function () { return env_1.getUserStorageApiUrl; } });
|
|
12
13
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAGsC;AAFpC,wIAAA,0BAA0B,OAAA;AAC1B,6IAAA,+BAA+B,OAAA;AAEjC,+
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAGsC;AAFpC,wIAAA,0BAA0B,OAAA;AAC1B,6IAAA,+BAA+B,OAAA;AAEjC,+CAIsB;AAHpB,yHAAA,2BAA2B,OAAA;AAC3B,6HAAA,+BAA+B,OAAA;AAC/B,6HAAA,+BAA+B,OAAA;AAmBjC,iCAA6C;AAApC,2GAAA,oBAAoB,OAAA","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\nexport {\n ASSETS_WATCHLIST_MAX_ASSETS,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n DEFAULT_PRICE_ALERT_PREFERENCES,\n} from './validators';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n AuthenticatedUserStorageServiceGetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceSetAssetsWatchlistAction,\n} from './authenticated-user-storage-method-action-types';\nexport { getUserStorageApiUrl } from './env';\nexport type { Environment } from './env';\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';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from "./authenticated-user-storage.cjs";
|
|
2
|
-
export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, } from "./validators.cjs";
|
|
2
|
+
export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } from "./validators.cjs";
|
|
3
3
|
export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from "./authenticated-user-storage.cjs";
|
|
4
4
|
export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from "./authenticated-user-storage-method-action-types.cjs";
|
|
5
5
|
export { getUserStorageApiUrl } from "./env.cjs";
|
|
6
6
|
export type { Environment } from "./env.cjs";
|
|
7
|
-
export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, AgenticCliPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from "./types.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
8
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,yCAAqC;AACtC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,GAChC,yBAAqB;AACtB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,yCAAqC;AACtC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,uDAAuD,EACvD,uDAAuD,GACxD,6DAAyD;AAC1D,OAAO,EAAE,oBAAoB,EAAE,kBAAc;AAC7C,YAAY,EAAE,WAAW,EAAE,kBAAc;AACzC,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,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,GACX,oBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,yCAAqC;AACtC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,yBAAqB;AACtB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,yCAAqC;AACtC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,uDAAuD,EACvD,uDAAuD,GACxD,6DAAyD;AAC1D,OAAO,EAAE,oBAAoB,EAAE,kBAAc;AAC7C,YAAY,EAAE,WAAW,EAAE,kBAAc;AACzC,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,oBAAgB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from "./authenticated-user-storage.mjs";
|
|
2
|
-
export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, } from "./validators.mjs";
|
|
2
|
+
export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } from "./validators.mjs";
|
|
3
3
|
export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from "./authenticated-user-storage.mjs";
|
|
4
4
|
export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from "./authenticated-user-storage-method-action-types.mjs";
|
|
5
5
|
export { getUserStorageApiUrl } from "./env.mjs";
|
|
6
6
|
export type { Environment } from "./env.mjs";
|
|
7
|
-
export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, AgenticCliPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from "./types.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
8
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,yCAAqC;AACtC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,GAChC,yBAAqB;AACtB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,yCAAqC;AACtC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,uDAAuD,EACvD,uDAAuD,GACxD,6DAAyD;AAC1D,OAAO,EAAE,oBAAoB,EAAE,kBAAc;AAC7C,YAAY,EAAE,WAAW,EAAE,kBAAc;AACzC,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,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,GACX,oBAAgB"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,yCAAqC;AACtC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,yBAAqB;AACtB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,yCAAqC;AACtC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,uDAAuD,EACvD,uDAAuD,GACxD,6DAAyD;AAC1D,OAAO,EAAE,oBAAoB,EAAE,kBAAc;AAC7C,YAAY,EAAE,WAAW,EAAE,kBAAc;AACzC,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,oBAAgB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService } from "./authenticated-user-storage.mjs";
|
|
2
|
-
export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES } from "./validators.mjs";
|
|
2
|
+
export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES } from "./validators.mjs";
|
|
3
3
|
export { getUserStorageApiUrl } from "./env.mjs";
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAChC,yCAAqC;AACtC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAChC,yBAAqB;AAkBtB,OAAO,EAAE,oBAAoB,EAAE,kBAAc","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\nexport {\n ASSETS_WATCHLIST_MAX_ASSETS,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n} from './validators';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n AuthenticatedUserStorageServiceGetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceSetAssetsWatchlistAction,\n} from './authenticated-user-storage-method-action-types';\nexport { getUserStorageApiUrl } from './env';\nexport type { Environment } from './env';\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 NotificationPreferences,\n AssetsWatchlistBlob,\n ClientType,\n} from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAChC,yCAAqC;AACtC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAChC,yBAAqB;AAkBtB,OAAO,EAAE,oBAAoB,EAAE,kBAAc","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\nexport {\n ASSETS_WATCHLIST_MAX_ASSETS,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n DEFAULT_PRICE_ALERT_PREFERENCES,\n} from './validators';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n AuthenticatedUserStorageServiceGetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceSetAssetsWatchlistAction,\n} from './authenticated-user-storage-method-action-types';\nexport { getUserStorageApiUrl } from './env';\nexport type { Environment } from './env';\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';\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +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\
|
|
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';\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -86,21 +86,20 @@ export type SocialAIPreference = {
|
|
|
86
86
|
txAmountLimit?: number;
|
|
87
87
|
mutedTraderProfileIds: string[];
|
|
88
88
|
};
|
|
89
|
+
export type PriceAlertPreference = {
|
|
90
|
+
inAppNotificationsEnabled: boolean;
|
|
91
|
+
pushNotificationsEnabled: boolean;
|
|
92
|
+
};
|
|
89
93
|
/**
|
|
90
94
|
* Notification preferences for the authenticated user.
|
|
91
|
-
*
|
|
92
|
-
* `agenticCli` is optional on this type for the current minor release.
|
|
93
|
-
* {@link AuthenticatedUserStorageService.getNotificationPreferences} always
|
|
94
|
-
* backfills it when absent from stored data. The next major release should
|
|
95
|
-
* make `agenticCli` required on this type.
|
|
96
95
|
*/
|
|
97
96
|
export type NotificationPreferences = {
|
|
98
97
|
walletActivity: WalletActivityPreference;
|
|
99
98
|
marketing: MarketingPreference;
|
|
100
99
|
perps: PerpsPreference;
|
|
101
100
|
socialAI: SocialAIPreference;
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
agenticCli: AgenticCliPreference;
|
|
102
|
+
priceAlerts: PriceAlertPreference;
|
|
104
103
|
};
|
|
105
104
|
export type { AssetsWatchlistBlob } from "./validators.cjs";
|
|
106
105
|
/** The type of client making the request. */
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +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,C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AC;IACnC,wBAAwB,EAAE,OAAO,CAAC;IAClC,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,yBAAyB,EAAE,OAAO,CAAC;IACnC,wBAAwB,EAAE,OAAO,CAAC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,yBAAyB,EAAE,OAAO,CAAC;IACnC,wBAAwB,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,wBAAwB,CAAC;IACzC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,UAAU,EAAE,oBAAoB,CAAC;IACjC,WAAW,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAUF,YAAY,EAAE,mBAAmB,EAAE,yBAAqB;AAMxD,6CAA6C;AAC7C,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -86,21 +86,20 @@ export type SocialAIPreference = {
|
|
|
86
86
|
txAmountLimit?: number;
|
|
87
87
|
mutedTraderProfileIds: string[];
|
|
88
88
|
};
|
|
89
|
+
export type PriceAlertPreference = {
|
|
90
|
+
inAppNotificationsEnabled: boolean;
|
|
91
|
+
pushNotificationsEnabled: boolean;
|
|
92
|
+
};
|
|
89
93
|
/**
|
|
90
94
|
* Notification preferences for the authenticated user.
|
|
91
|
-
*
|
|
92
|
-
* `agenticCli` is optional on this type for the current minor release.
|
|
93
|
-
* {@link AuthenticatedUserStorageService.getNotificationPreferences} always
|
|
94
|
-
* backfills it when absent from stored data. The next major release should
|
|
95
|
-
* make `agenticCli` required on this type.
|
|
96
95
|
*/
|
|
97
96
|
export type NotificationPreferences = {
|
|
98
97
|
walletActivity: WalletActivityPreference;
|
|
99
98
|
marketing: MarketingPreference;
|
|
100
99
|
perps: PerpsPreference;
|
|
101
100
|
socialAI: SocialAIPreference;
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
agenticCli: AgenticCliPreference;
|
|
102
|
+
priceAlerts: PriceAlertPreference;
|
|
104
103
|
};
|
|
105
104
|
export type { AssetsWatchlistBlob } from "./validators.mjs";
|
|
106
105
|
/** The type of client making the request. */
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","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,GAAG;IAC/B,yEAAyE;IACzE,cAAc,EAAE,GAAG,CAAC;IACpB,4CAA4C;IAC5C,UAAU,EAAE,GAAG,CAAC;IAChB,mDAAmD;IACnD,SAAS,EAAE,GAAG,CAAC;IACf,yCAAyC;IACzC,WAAW,EAAE,M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AAqB,EAAE,MAAM,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,yBAAyB,EAAE,OAAO,CAAC;IACnC,wBAAwB,EAAE,OAAO,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,cAAc,EAAE,wBAAwB,CAAC;IACzC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,UAAU,EAAE,oBAAoB,CAAC;IACjC,WAAW,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAUF,YAAY,EAAE,mBAAmB,EAAE,yBAAqB;AAMxD,6CAA6C;AAC7C,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","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\
|
|
1
|
+
{"version":3,"file":"types.mjs","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';\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
|
package/dist/validators.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertAssetsWatchlistBlobForWrite = exports.assertAssetsWatchlistBlob = exports.assertNotificationPreferences = exports.assertDelegationResponseArray = exports.ASSETS_WATCHLIST_MAX_ASSETS = exports.DEFAULT_AGENTIC_CLI_PREFERENCES = void 0;
|
|
3
|
+
exports.assertAssetsWatchlistBlobForWrite = exports.assertAssetsWatchlistBlob = exports.assertNotificationPreferences = exports.assertDelegationResponseArray = exports.ASSETS_WATCHLIST_MAX_ASSETS = exports.DEFAULT_PRICE_ALERT_PREFERENCES = exports.DEFAULT_AGENTIC_CLI_PREFERENCES = void 0;
|
|
4
4
|
const superstruct_1 = require("@metamask/superstruct");
|
|
5
5
|
/**
|
|
6
6
|
* Matches a 0x-prefixed hex string with zero or more hex digits.
|
|
@@ -70,21 +70,34 @@ const AgenticCliPreferenceSchema = (0, superstruct_1.type)({
|
|
|
70
70
|
inAppNotificationsEnabled: (0, superstruct_1.boolean)(),
|
|
71
71
|
pushNotificationsEnabled: (0, superstruct_1.boolean)(),
|
|
72
72
|
});
|
|
73
|
+
const PriceAlertPreferenceSchema = (0, superstruct_1.type)({
|
|
74
|
+
inAppNotificationsEnabled: (0, superstruct_1.boolean)(),
|
|
75
|
+
pushNotificationsEnabled: (0, superstruct_1.boolean)(),
|
|
76
|
+
});
|
|
73
77
|
const NotificationPreferencesSchema = (0, superstruct_1.type)({
|
|
74
78
|
walletActivity: WalletActivityPreferenceSchema,
|
|
75
79
|
marketing: MarketingPreferenceSchema,
|
|
76
80
|
perps: PerpsPreferenceSchema,
|
|
77
81
|
socialAI: SocialAIPreferenceSchema,
|
|
78
82
|
agenticCli: AgenticCliPreferenceSchema,
|
|
83
|
+
priceAlerts: PriceAlertPreferenceSchema,
|
|
79
84
|
});
|
|
80
85
|
/**
|
|
81
|
-
* Default Agentic CLI notification preferences
|
|
82
|
-
*
|
|
86
|
+
* Default Agentic CLI notification preferences for consumers building a
|
|
87
|
+
* fresh `NotificationPreferences` object.
|
|
83
88
|
*/
|
|
84
89
|
exports.DEFAULT_AGENTIC_CLI_PREFERENCES = {
|
|
85
90
|
inAppNotificationsEnabled: true,
|
|
86
91
|
pushNotificationsEnabled: true,
|
|
87
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* Default price-alert notification preferences for consumers building a
|
|
95
|
+
* fresh `NotificationPreferences` object.
|
|
96
|
+
*/
|
|
97
|
+
exports.DEFAULT_PRICE_ALERT_PREFERENCES = {
|
|
98
|
+
inAppNotificationsEnabled: true,
|
|
99
|
+
pushNotificationsEnabled: true,
|
|
100
|
+
};
|
|
88
101
|
/**
|
|
89
102
|
* Maximum number of entries allowed in an assets-watchlist on write. Reads
|
|
90
103
|
* are lenient: a server payload exceeding this size will still validate as
|
package/dist/validators.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;AACA,uDAY+B;AAQ/B;;;;;GAKG;AACH,MAAM,aAAa,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,iBAAiB,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,IAAA,kBAAI,EAAC;IACxB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,aAAa;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAA,kBAAI,EAAC;IAClC,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,aAAa;IACxB,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,IAAA,mBAAK,EAAC,YAAY,CAAC;IAC5B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,aAAa;CACzB,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IACpC,cAAc,EAAE,aAAa;IAC7B,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,aAAa;IACxB,WAAW,EAAE,IAAA,oBAAM,GAAE;IACrB,YAAY,EAAE,aAAa;IAC3B,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IACpC,g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oBAAM,EAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;AAC9C,CAAC;AAJD,sEAIC;AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CACvC,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;AAC1C,CAAC;AAJD,8DAIC;AAED;;;;;;;;;GASG;AACH,SAAgB,iCAAiC,CAC/C,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;AAC/C,CAAC;AAJD,8EAIC","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} from './types';\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 myx: 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 NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n agenticCli: AgenticCliPreferenceSchema,\n});\n\n/**\n * Default Agentic CLI notification preferences applied when coercing legacy\n * notification-preference blobs that omit `agenticCli`.\n */\nexport const DEFAULT_AGENTIC_CLI_PREFERENCES: AgenticCliPreference = {\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"]}
|
|
1
|
+
{"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;AACA,uDAY+B;AAS/B;;;;;GAKG;AACH,MAAM,aAAa,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,iBAAiB,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,IAAA,kBAAI,EAAC;IACxB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,aAAa;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAA,kBAAI,EAAC;IAClC,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,aAAa;IACxB,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,IAAA,mBAAK,EAAC,YAAY,CAAC;IAC5B,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,aAAa;CACzB,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IACpC,cAAc,EAAE,aAAa;IAC7B,UAAU,EAAE,aAAa;IACzB,SAAS,EAAE,aAAa;IACxB,WAAW,EAAE,IAAA,oBAAM,GAAE;IACrB,YAAY,EAAE,aAAa;IAC3B,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IACpC,gBAAgB,EAAE,sBAAsB;IAC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B,CAAC;CAC9D,CAAC,CACH,CAAC;AAoBF;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,IAAA,mBAAK,EAAC,wBAAwB,CAAC,CAAC,CAAC;AAChD,CAAC;AAJD,sEAIC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;AAC9C,CAAC;AAJD,sEAIC;AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CACvC,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;AAC1C,CAAC;AAJD,8DAIC;AAED;;;;;;;;;GASG;AACH,SAAgB,iCAAiC,CAC/C,IAAa;IAEb,IAAA,oBAAM,EAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;AAC/C,CAAC;AAJD,8EAIC","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';\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 myx: 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"]}
|
package/dist/validators.d.cts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Infer } from "@metamask/superstruct";
|
|
2
|
-
import type { AgenticCliPreference, DelegationResponse, NotificationPreferences } from "./types.cjs";
|
|
2
|
+
import type { AgenticCliPreference, DelegationResponse, NotificationPreferences, PriceAlertPreference } from "./types.cjs";
|
|
3
3
|
/**
|
|
4
|
-
* Default Agentic CLI notification preferences
|
|
5
|
-
*
|
|
4
|
+
* Default Agentic CLI notification preferences for consumers building a
|
|
5
|
+
* fresh `NotificationPreferences` object.
|
|
6
6
|
*/
|
|
7
7
|
export declare const DEFAULT_AGENTIC_CLI_PREFERENCES: AgenticCliPreference;
|
|
8
|
+
/**
|
|
9
|
+
* Default price-alert notification preferences for consumers building a
|
|
10
|
+
* fresh `NotificationPreferences` object.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_PRICE_ALERT_PREFERENCES: PriceAlertPreference;
|
|
8
13
|
/**
|
|
9
14
|
* Maximum number of entries allowed in an assets-watchlist on write. Reads
|
|
10
15
|
* are lenient: a server payload exceeding this size will still validate as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAenD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAenD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACrB,oBAAgB;AAiGjB;;;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"}
|
package/dist/validators.d.mts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import type { Infer } from "@metamask/superstruct";
|
|
2
|
-
import type { AgenticCliPreference, DelegationResponse, NotificationPreferences } from "./types.mjs";
|
|
2
|
+
import type { AgenticCliPreference, DelegationResponse, NotificationPreferences, PriceAlertPreference } from "./types.mjs";
|
|
3
3
|
/**
|
|
4
|
-
* Default Agentic CLI notification preferences
|
|
5
|
-
*
|
|
4
|
+
* Default Agentic CLI notification preferences for consumers building a
|
|
5
|
+
* fresh `NotificationPreferences` object.
|
|
6
6
|
*/
|
|
7
7
|
export declare const DEFAULT_AGENTIC_CLI_PREFERENCES: AgenticCliPreference;
|
|
8
|
+
/**
|
|
9
|
+
* Default price-alert notification preferences for consumers building a
|
|
10
|
+
* fresh `NotificationPreferences` object.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_PRICE_ALERT_PREFERENCES: PriceAlertPreference;
|
|
8
13
|
/**
|
|
9
14
|
* Maximum number of entries allowed in an assets-watchlist on write. Reads
|
|
10
15
|
* are lenient: a server payload exceeding this size will still validate as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAenD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAenD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACrB,oBAAgB;AAiGjB;;;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"}
|
package/dist/validators.mjs
CHANGED
|
@@ -67,21 +67,34 @@ const AgenticCliPreferenceSchema = type({
|
|
|
67
67
|
inAppNotificationsEnabled: boolean(),
|
|
68
68
|
pushNotificationsEnabled: boolean(),
|
|
69
69
|
});
|
|
70
|
+
const PriceAlertPreferenceSchema = type({
|
|
71
|
+
inAppNotificationsEnabled: boolean(),
|
|
72
|
+
pushNotificationsEnabled: boolean(),
|
|
73
|
+
});
|
|
70
74
|
const NotificationPreferencesSchema = type({
|
|
71
75
|
walletActivity: WalletActivityPreferenceSchema,
|
|
72
76
|
marketing: MarketingPreferenceSchema,
|
|
73
77
|
perps: PerpsPreferenceSchema,
|
|
74
78
|
socialAI: SocialAIPreferenceSchema,
|
|
75
79
|
agenticCli: AgenticCliPreferenceSchema,
|
|
80
|
+
priceAlerts: PriceAlertPreferenceSchema,
|
|
76
81
|
});
|
|
77
82
|
/**
|
|
78
|
-
* Default Agentic CLI notification preferences
|
|
79
|
-
*
|
|
83
|
+
* Default Agentic CLI notification preferences for consumers building a
|
|
84
|
+
* fresh `NotificationPreferences` object.
|
|
80
85
|
*/
|
|
81
86
|
export const DEFAULT_AGENTIC_CLI_PREFERENCES = {
|
|
82
87
|
inAppNotificationsEnabled: true,
|
|
83
88
|
pushNotificationsEnabled: true,
|
|
84
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* Default price-alert notification preferences for consumers building a
|
|
92
|
+
* fresh `NotificationPreferences` object.
|
|
93
|
+
*/
|
|
94
|
+
export const DEFAULT_PRICE_ALERT_PREFERENCES = {
|
|
95
|
+
inAppNotificationsEnabled: true,
|
|
96
|
+
pushNotificationsEnabled: true,
|
|
97
|
+
};
|
|
85
98
|
/**
|
|
86
99
|
* Maximum number of entries allowed in an assets-watchlist on write. Reads
|
|
87
100
|
* are lenient: a server payload exceeding this size will still validate as
|
package/dist/validators.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.mjs","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,EACL,8BAA8B;AAQ/B;;;;;GAKG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,IAAI,CAAC;IACxB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C,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,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} from './types';\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 myx: 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 NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n agenticCli: AgenticCliPreferenceSchema,\n});\n\n/**\n * Default Agentic CLI notification preferences applied when coercing legacy\n * notification-preference blobs that omit `agenticCli`.\n */\nexport const DEFAULT_AGENTIC_CLI_PREFERENCES: AgenticCliPreference = {\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"]}
|
|
1
|
+
{"version":3,"file":"validators.mjs","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,EACL,8BAA8B;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,aA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M,EAAE,CAAC,EAAE,CAAC,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';\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 myx: 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"]}
|
package/package.json
CHANGED