@metamask-previews/authenticated-user-storage 2.0.0-preview-51b287c55 → 2.0.0-preview-2f3fe6006

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +0 -10
  2. package/README.md +1 -26
  3. package/dist/authenticated-user-storage-method-action-types.cjs.map +1 -1
  4. package/dist/authenticated-user-storage-method-action-types.d.cts +1 -26
  5. package/dist/authenticated-user-storage-method-action-types.d.cts.map +1 -1
  6. package/dist/authenticated-user-storage-method-action-types.d.mts +1 -26
  7. package/dist/authenticated-user-storage-method-action-types.d.mts.map +1 -1
  8. package/dist/authenticated-user-storage-method-action-types.mjs.map +1 -1
  9. package/dist/authenticated-user-storage.cjs +0 -64
  10. package/dist/authenticated-user-storage.cjs.map +1 -1
  11. package/dist/authenticated-user-storage.d.cts +1 -20
  12. package/dist/authenticated-user-storage.d.cts.map +1 -1
  13. package/dist/authenticated-user-storage.d.mts +1 -20
  14. package/dist/authenticated-user-storage.d.mts.map +1 -1
  15. package/dist/authenticated-user-storage.mjs +1 -65
  16. package/dist/authenticated-user-storage.mjs.map +1 -1
  17. package/dist/index.cjs +1 -3
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +2 -3
  20. package/dist/index.d.cts.map +1 -1
  21. package/dist/index.d.mts +2 -3
  22. package/dist/index.d.mts.map +1 -1
  23. package/dist/index.mjs +0 -1
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/types.cjs.map +1 -1
  26. package/dist/types.d.cts +0 -1
  27. package/dist/types.d.cts.map +1 -1
  28. package/dist/types.d.mts +0 -1
  29. package/dist/types.d.mts.map +1 -1
  30. package/dist/types.mjs.map +1 -1
  31. package/dist/validators.cjs +1 -53
  32. package/dist/validators.cjs.map +1 -1
  33. package/dist/validators.d.cts +0 -58
  34. package/dist/validators.d.cts.map +1 -1
  35. package/dist/validators.d.mts +0 -58
  36. package/dist/validators.d.mts.map +1 -1
  37. package/dist/validators.mjs +1 -51
  38. package/dist/validators.mjs.map +1 -1
  39. package/package.json +2 -2
@@ -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,EAC9B,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,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,GAAG,GAAG,GAAG,0BAA0B,CAAC,uBAAA,IAAI,oDAAa,CAA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AAiB,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} 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"]}
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;AAO7C,OAAO,EACL,6BAA6B,EAC7B,6BAA6B,EAC9B,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;CACpB,CAAC;AAoEX,kBAAkB;AAElB;;;;;GAKG;AACH,MAAM,OAAO,+BAAgC,S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AA2B;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 ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types';\nimport {\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] 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 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,11 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUserStorageApiUrl = exports.ASSETS_WATCHLIST_MAX_ASSETS = exports.AuthenticatedUserStorageService = exports.getAuthenticatedStorageUrl = void 0;
3
+ exports.getUserStorageApiUrl = 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
- var validators_1 = require("./validators.cjs");
8
- Object.defineProperty(exports, "ASSETS_WATCHLIST_MAX_ASSETS", { enumerable: true, get: function () { return validators_1.ASSETS_WATCHLIST_MAX_ASSETS; } });
9
7
  var env_1 = require("./env.cjs");
10
8
  Object.defineProperty(exports, "getUserStorageApiUrl", { enumerable: true, get: function () { return env_1.getUserStorageApiUrl; } });
11
9
  //# sourceMappingURL=index.cjs.map
@@ -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,+CAA2D;AAAlD,yHAAA,2BAA2B,OAAA;AAkBpC,iCAA6C;AAApC,2GAAA,oBAAoB,OAAA","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\nexport { ASSETS_WATCHLIST_MAX_ASSETS } 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 NotificationPreferences,\n AssetsWatchlistBlob,\n ClientType,\n} from './types';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+EAGsC;AAFpC,wIAAA,0BAA0B,OAAA;AAC1B,6IAAA,+BAA+B,OAAA;AAiBjC,iCAA6C;AAApC,2GAAA,oBAAoB,OAAA","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\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} 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 NotificationPreferences,\n ClientType,\n} from './types';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,8 +1,7 @@
1
1
  export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from "./authenticated-user-storage.cjs";
2
- export { ASSETS_WATCHLIST_MAX_ASSETS } from "./validators.cjs";
3
2
  export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from "./authenticated-user-storage.cjs";
4
- export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from "./authenticated-user-storage-method-action-types.cjs";
3
+ export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, } from "./authenticated-user-storage-method-action-types.cjs";
5
4
  export { getUserStorageApiUrl } from "./env.cjs";
6
5
  export type { Environment } from "./env.cjs";
7
- export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from "./types.cjs";
6
+ export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, NotificationPreferences, ClientType, } from "./types.cjs";
8
7
  //# sourceMappingURL=index.d.cts.map
@@ -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,EAAE,2BAA2B,EAAE,yBAAqB;AAC3D,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,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,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,GAChE,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,uBAAuB,EACvB,UAAU,GACX,oBAAgB"}
package/dist/index.d.mts CHANGED
@@ -1,8 +1,7 @@
1
1
  export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from "./authenticated-user-storage.mjs";
2
- export { ASSETS_WATCHLIST_MAX_ASSETS } from "./validators.mjs";
3
2
  export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from "./authenticated-user-storage.mjs";
4
- export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from "./authenticated-user-storage-method-action-types.mjs";
3
+ export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, } from "./authenticated-user-storage-method-action-types.mjs";
5
4
  export { getUserStorageApiUrl } from "./env.mjs";
6
5
  export type { Environment } from "./env.mjs";
7
- export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from "./types.mjs";
6
+ export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, NotificationPreferences, ClientType, } from "./types.mjs";
8
7
  //# sourceMappingURL=index.d.mts.map
@@ -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,EAAE,2BAA2B,EAAE,yBAAqB;AAC3D,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,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,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,GAChE,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,uBAAuB,EACvB,UAAU,GACX,oBAAgB"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
1
  export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService } from "./authenticated-user-storage.mjs";
2
- export { ASSETS_WATCHLIST_MAX_ASSETS } from "./validators.mjs";
3
2
  export { getUserStorageApiUrl } from "./env.mjs";
4
3
  //# sourceMappingURL=index.mjs.map
@@ -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,EAAE,2BAA2B,EAAE,yBAAqB;AAkB3D,OAAO,EAAE,oBAAoB,EAAE,kBAAc","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\nexport { ASSETS_WATCHLIST_MAX_ASSETS } 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 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;AAgBtC,OAAO,EAAE,oBAAoB,EAAE,kBAAc","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage';\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} 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 NotificationPreferences,\n ClientType,\n} from './types';\n"]}
@@ -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 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\n/** Notification preferences for the authenticated user. */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\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"]}
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 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\n/** Notification preferences for the authenticated user. */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\n};\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
@@ -89,7 +89,6 @@ export type NotificationPreferences = {
89
89
  perps: PerpsPreference;
90
90
  socialAI: SocialAIPreference;
91
91
  };
92
- export type { AssetsWatchlistBlob } from "./validators.cjs";
93
92
  /** The type of client making the request. */
94
93
  export type ClientType = 'extension' | 'mobile' | 'portfolio';
95
94
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GA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erpsPreference;
90
90
  socialAI: SocialAIPreference;
91
91
  };
92
- export type { AssetsWatchlistBlob } from "./validators.mjs";
93
92
  /** The type of client making the request. */
94
93
  export type ClientType = 'extension' | 'mobile' | 'portfolio';
95
94
  //# sourceMappingURL=types.d.mts.map
@@ -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,MAAM,CAAC;IACpB,4CAA4C;IAC5C,YAAY,EAAE,GAAG,CAAC;IAClB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,oDAAoD;AACpD,MAAM,MAAM,oBAAoB,GAAG;IACjC,gBAAgB,EAAE,gBAAgB,CAAC;IACn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AwB,CAAC;IACzC,SAAS,EAAE,mBAAmB,CAAC;IAC/B,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,kBAAkB,CAAC;CAC9B,CAAC;AAMF,6CAA6C;AAC7C,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC"}
@@ -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 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\n/** Notification preferences for the authenticated user. */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\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"]}
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 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\n/** Notification preferences for the authenticated user. */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\n};\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
@@ -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 = void 0;
3
+ exports.assertNotificationPreferences = exports.assertDelegationResponseArray = 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.
@@ -72,33 +72,6 @@ const NotificationPreferencesSchema = (0, superstruct_1.type)({
72
72
  perps: PerpsPreferenceSchema,
73
73
  socialAI: SocialAIPreferenceSchema,
74
74
  });
75
- /**
76
- * Maximum number of entries allowed in an assets-watchlist on write. Reads
77
- * are lenient: a server payload exceeding this size will still validate as
78
- * an `AssetsWatchlistBlob`. Encoded into
79
- * {@link AssetsWatchlistBlobWriteSchema}.
80
- */
81
- exports.ASSETS_WATCHLIST_MAX_ASSETS = 100;
82
- /**
83
- * The shape we accept on the way **in** from the server. Lenient by design:
84
- * a malformed payload throws, but a well-formed payload with more than
85
- * {@link ASSETS_WATCHLIST_MAX_ASSETS} assets is still considered valid so we
86
- * don't reject existing server-side data.
87
- */
88
- const AssetsWatchlistBlobSchema = (0, superstruct_1.type)({
89
- version: (0, superstruct_1.literal)(1),
90
- assets: (0, superstruct_1.array)((0, superstruct_1.string)()),
91
- });
92
- /**
93
- * The shape we accept on the way **out** to the server. Extends
94
- * {@link AssetsWatchlistBlobSchema} with a hard cap on `assets.length`.
95
- * Validation failures throw a `StructError`, e.g.
96
- * `"At path: assets -- Expected a array with a length between \`0\` and
97
- * \`100\` but received one with a length of \`N\`"`.
98
- */
99
- const AssetsWatchlistBlobWriteSchema = (0, superstruct_1.assign)(AssetsWatchlistBlobSchema, (0, superstruct_1.type)({
100
- assets: (0, superstruct_1.size)((0, superstruct_1.array)((0, superstruct_1.string)()), 0, exports.ASSETS_WATCHLIST_MAX_ASSETS),
101
- }));
102
75
  /**
103
76
  * Asserts that the given value is a valid `DelegationResponse[]`.
104
77
  *
@@ -119,29 +92,4 @@ function assertNotificationPreferences(data) {
119
92
  (0, superstruct_1.assert)(data, NotificationPreferencesSchema);
120
93
  }
121
94
  exports.assertNotificationPreferences = assertNotificationPreferences;
122
- /**
123
- * Asserts that the given value is a valid `AssetsWatchlistBlob` (read-side,
124
- * lenient).
125
- *
126
- * @param data - The unknown value to validate.
127
- * @throws If the value does not match the expected schema.
128
- */
129
- function assertAssetsWatchlistBlob(data) {
130
- (0, superstruct_1.assert)(data, AssetsWatchlistBlobSchema);
131
- }
132
- exports.assertAssetsWatchlistBlob = assertAssetsWatchlistBlob;
133
- /**
134
- * Asserts that the given value is a valid `AssetsWatchlistBlob` for
135
- * **writes**. In addition to the structural checks performed by
136
- * {@link assertAssetsWatchlistBlob}, this enforces that `assets` contains at
137
- * most {@link ASSETS_WATCHLIST_MAX_ASSETS} entries.
138
- *
139
- * @param data - The unknown value to validate.
140
- * @throws A `StructError` if the value does not match the expected schema
141
- * (including the size constraint).
142
- */
143
- function assertAssetsWatchlistBlobForWrite(data) {
144
- (0, superstruct_1.assert)(data, AssetsWatchlistBlobWriteSchema);
145
- }
146
- exports.assertAssetsWatchlistBlobForWrite = assertAssetsWatchlistBlobForWrite;
147
95
  //# sourceMappingURL=validators.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.cjs","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;AACA,uDAY+B;AAI/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;IACxC,QAAQ,EAAE,wBAAwB;CACnC,CAAC,CAAC;AAEH,MAAM,2BAA2B,GAAG,IAAA,kBAAI,EAAC;IACvC,OAAO,EAAE,aAAa;IACtB,OAAO,EAAE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9C,SAAS,EAAE,yBAAyB;IACpC,KAAK,EAAE,qBAAqB;IAC5B,QAAQ,EAAE,wBAAwB;CACnC,CAAC,CAAC;AAEH;;;;;GAKG;AACU,QAAA,2BAA2B,GAAG,GAAG,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,IAAA,kBAAI,EAAC;IACrC,OAAO,EAAE,IAAA,qBAAO,EAAC,CAAC,CAAC;IACnB,MAAM,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACxB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,8BAA8B,GAAG,IAAA,oBAAM,EAC3C,yBAAyB,EACzB,IAAA,kBAAI,EAAC;IACH,MAAM,EAAE,IAAA,kBAAI,EAAC,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,CAAC,EAAE,mCAA2B,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 { DelegationResponse, NotificationPreferences } 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 NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\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":";;;AAAA,uDAS+B;AAI/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;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A,kBAAI,EAAC;IACvC,WAAW,EAAE,4BAA4B;IACzC,GAAG,EAAE,4BAA4B;CAClC,CAAC,CAAC;AAEH,MAAM,qBAAqB,GAAG,IAAA,kBAAI,EAAC;IACjC,yBAAyB,EAAE,IAAA,qBAAO,GAAE;IACpC,wBAAwB,EAAE,IAAA,qBAAO,GAAE;IACnC,gBAAgB,EAAE,IAAA,sBAAQ,EAAC,2BAA2B,CAAC;CACxD,CAAC,CAAC;AAEH,MAAM,wBAAwB,GAAG,IAAA,kBAAI,EAAC;IACpC,yBAAyB,EAAE,IAAA,qBAAO,GAAE;IACpC,wBAAwB,EAAE,IAAA,qBAAO,GAAE;IACnC,aAAa,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACjC,qBAAqB,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACvC,CAAC,CAAC;AAEH,MAAM,6BAA6B,GAAG,IAAA,kBAAI,EAAC;IACzC,cAAc,EAAE,8BAA8B;IAC9C,SAAS,EAAE,yBAAyB;IACpC,KAAK,EAAE,qBAAqB;IAC5B,QAAQ,EAAE,wBAAwB;CACnC,CAAC,CAAC;AAEH;;;;;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","sourcesContent":["import {\n array,\n assert,\n boolean,\n number,\n optional,\n pattern,\n string,\n type,\n} from '@metamask/superstruct';\n\nimport type { DelegationResponse, NotificationPreferences } 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 NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n});\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"]}
@@ -1,42 +1,4 @@
1
- import type { Infer } from "@metamask/superstruct";
2
1
  import type { DelegationResponse, NotificationPreferences } from "./types.cjs";
3
- /**
4
- * Maximum number of entries allowed in an assets-watchlist on write. Reads
5
- * are lenient: a server payload exceeding this size will still validate as
6
- * an `AssetsWatchlistBlob`. Encoded into
7
- * {@link AssetsWatchlistBlobWriteSchema}.
8
- */
9
- export declare const ASSETS_WATCHLIST_MAX_ASSETS = 100;
10
- /**
11
- * The shape we accept on the way **in** from the server. Lenient by design:
12
- * a malformed payload throws, but a well-formed payload with more than
13
- * {@link ASSETS_WATCHLIST_MAX_ASSETS} assets is still considered valid so we
14
- * don't reject existing server-side data.
15
- */
16
- declare const AssetsWatchlistBlobSchema: import("@metamask/superstruct").Struct<{
17
- version: 1;
18
- assets: string[];
19
- }, {
20
- version: import("@metamask/superstruct").Struct<1, 1>;
21
- assets: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
22
- }>;
23
- /**
24
- * The authenticated user's assets-watchlist: a mutable per-user singleton
25
- * blob.
26
- *
27
- * Each entry is a CAIP-19 asset identifier
28
- * (e.g. `eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48`).
29
- *
30
- * The `version` literal is carried inside the blob (not in the URL) so the
31
- * schema can evolve in a backwards-compatible way; bumping the version
32
- * indicates a different `assets` element shape.
33
- *
34
- * Inferred from {@link AssetsWatchlistBlobSchema} so the runtime schema and
35
- * the static type stay in lock-step. The size constraint on writes is
36
- * enforced by {@link AssetsWatchlistBlobWriteSchema} and is not encoded in
37
- * this static type (TypeScript cannot express "array of length ≤ N").
38
- */
39
- export type AssetsWatchlistBlob = Infer<typeof AssetsWatchlistBlobSchema>;
40
2
  /**
41
3
  * Asserts that the given value is a valid `DelegationResponse[]`.
42
4
  *
@@ -51,24 +13,4 @@ export declare function assertDelegationResponseArray(data: unknown): asserts da
51
13
  * @throws If the value does not match the expected schema.
52
14
  */
53
15
  export declare function assertNotificationPreferences(data: unknown): asserts data is NotificationPreferences;
54
- /**
55
- * Asserts that the given value is a valid `AssetsWatchlistBlob` (read-side,
56
- * lenient).
57
- *
58
- * @param data - The unknown value to validate.
59
- * @throws If the value does not match the expected schema.
60
- */
61
- export declare function assertAssetsWatchlistBlob(data: unknown): asserts data is AssetsWatchlistBlob;
62
- /**
63
- * Asserts that the given value is a valid `AssetsWatchlistBlob` for
64
- * **writes**. In addition to the structural checks performed by
65
- * {@link assertAssetsWatchlistBlob}, this enforces that `assets` contains at
66
- * most {@link ASSETS_WATCHLIST_MAX_ASSETS} entries.
67
- *
68
- * @param data - The unknown value to validate.
69
- * @throws A `StructError` if the value does not match the expected schema
70
- * (including the size constraint).
71
- */
72
- export declare function assertAssetsWatchlistBlobForWrite(data: unknown): asserts data is AssetsWatchlistBlob;
73
- export {};
74
16
  //# sourceMappingURL=validators.d.cts.map
@@ -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,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,oBAAgB;AAqF3E;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;GAKG;AACH,QAAA,MAAM,yBAAyB;;;;;;EAG7B,CAAC;AAgBH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,uBAAuB,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC"}
1
+ {"version":3,"file":"validators.d.cts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,oBAAgB;AAqF3E;;;;;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"}
@@ -1,42 +1,4 @@
1
- import type { Infer } from "@metamask/superstruct";
2
1
  import type { DelegationResponse, NotificationPreferences } from "./types.mjs";
3
- /**
4
- * Maximum number of entries allowed in an assets-watchlist on write. Reads
5
- * are lenient: a server payload exceeding this size will still validate as
6
- * an `AssetsWatchlistBlob`. Encoded into
7
- * {@link AssetsWatchlistBlobWriteSchema}.
8
- */
9
- export declare const ASSETS_WATCHLIST_MAX_ASSETS = 100;
10
- /**
11
- * The shape we accept on the way **in** from the server. Lenient by design:
12
- * a malformed payload throws, but a well-formed payload with more than
13
- * {@link ASSETS_WATCHLIST_MAX_ASSETS} assets is still considered valid so we
14
- * don't reject existing server-side data.
15
- */
16
- declare const AssetsWatchlistBlobSchema: import("@metamask/superstruct").Struct<{
17
- version: 1;
18
- assets: string[];
19
- }, {
20
- version: import("@metamask/superstruct").Struct<1, 1>;
21
- assets: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
22
- }>;
23
- /**
24
- * The authenticated user's assets-watchlist: a mutable per-user singleton
25
- * blob.
26
- *
27
- * Each entry is a CAIP-19 asset identifier
28
- * (e.g. `eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48`).
29
- *
30
- * The `version` literal is carried inside the blob (not in the URL) so the
31
- * schema can evolve in a backwards-compatible way; bumping the version
32
- * indicates a different `assets` element shape.
33
- *
34
- * Inferred from {@link AssetsWatchlistBlobSchema} so the runtime schema and
35
- * the static type stay in lock-step. The size constraint on writes is
36
- * enforced by {@link AssetsWatchlistBlobWriteSchema} and is not encoded in
37
- * this static type (TypeScript cannot express "array of length ≤ N").
38
- */
39
- export type AssetsWatchlistBlob = Infer<typeof AssetsWatchlistBlobSchema>;
40
2
  /**
41
3
  * Asserts that the given value is a valid `DelegationResponse[]`.
42
4
  *
@@ -51,24 +13,4 @@ export declare function assertDelegationResponseArray(data: unknown): asserts da
51
13
  * @throws If the value does not match the expected schema.
52
14
  */
53
15
  export declare function assertNotificationPreferences(data: unknown): asserts data is NotificationPreferences;
54
- /**
55
- * Asserts that the given value is a valid `AssetsWatchlistBlob` (read-side,
56
- * lenient).
57
- *
58
- * @param data - The unknown value to validate.
59
- * @throws If the value does not match the expected schema.
60
- */
61
- export declare function assertAssetsWatchlistBlob(data: unknown): asserts data is AssetsWatchlistBlob;
62
- /**
63
- * Asserts that the given value is a valid `AssetsWatchlistBlob` for
64
- * **writes**. In addition to the structural checks performed by
65
- * {@link assertAssetsWatchlistBlob}, this enforces that `assets` contains at
66
- * most {@link ASSETS_WATCHLIST_MAX_ASSETS} entries.
67
- *
68
- * @param data - The unknown value to validate.
69
- * @throws A `StructError` if the value does not match the expected schema
70
- * (including the size constraint).
71
- */
72
- export declare function assertAssetsWatchlistBlobForWrite(data: unknown): asserts data is AssetsWatchlistBlob;
73
- export {};
74
16
  //# sourceMappingURL=validators.d.mts.map
@@ -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,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,oBAAgB;AAqF3E;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;GAKG;AACH,QAAA,MAAM,yBAAyB;;;;;;EAG7B,CAAC;AAgBH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,uBAAuB,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC"}
1
+ {"version":3,"file":"validators.d.mts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,oBAAgB;AAqF3E;;;;;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"}
@@ -1,4 +1,4 @@
1
- import { array, assert, assign, boolean, literal, number, optional, pattern, size, string, type } from "@metamask/superstruct";
1
+ import { array, assert, boolean, number, optional, pattern, string, type } from "@metamask/superstruct";
2
2
  /**
3
3
  * Matches a 0x-prefixed hex string with zero or more hex digits.
4
4
  * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least
@@ -69,33 +69,6 @@ const NotificationPreferencesSchema = type({
69
69
  perps: PerpsPreferenceSchema,
70
70
  socialAI: SocialAIPreferenceSchema,
71
71
  });
72
- /**
73
- * Maximum number of entries allowed in an assets-watchlist on write. Reads
74
- * are lenient: a server payload exceeding this size will still validate as
75
- * an `AssetsWatchlistBlob`. Encoded into
76
- * {@link AssetsWatchlistBlobWriteSchema}.
77
- */
78
- export const ASSETS_WATCHLIST_MAX_ASSETS = 100;
79
- /**
80
- * The shape we accept on the way **in** from the server. Lenient by design:
81
- * a malformed payload throws, but a well-formed payload with more than
82
- * {@link ASSETS_WATCHLIST_MAX_ASSETS} assets is still considered valid so we
83
- * don't reject existing server-side data.
84
- */
85
- const AssetsWatchlistBlobSchema = type({
86
- version: literal(1),
87
- assets: array(string()),
88
- });
89
- /**
90
- * The shape we accept on the way **out** to the server. Extends
91
- * {@link AssetsWatchlistBlobSchema} with a hard cap on `assets.length`.
92
- * Validation failures throw a `StructError`, e.g.
93
- * `"At path: assets -- Expected a array with a length between \`0\` and
94
- * \`100\` but received one with a length of \`N\`"`.
95
- */
96
- const AssetsWatchlistBlobWriteSchema = assign(AssetsWatchlistBlobSchema, type({
97
- assets: size(array(string()), 0, ASSETS_WATCHLIST_MAX_ASSETS),
98
- }));
99
72
  /**
100
73
  * Asserts that the given value is a valid `DelegationResponse[]`.
101
74
  *
@@ -114,27 +87,4 @@ export function assertDelegationResponseArray(data) {
114
87
  export function assertNotificationPreferences(data) {
115
88
  assert(data, NotificationPreferencesSchema);
116
89
  }
117
- /**
118
- * Asserts that the given value is a valid `AssetsWatchlistBlob` (read-side,
119
- * lenient).
120
- *
121
- * @param data - The unknown value to validate.
122
- * @throws If the value does not match the expected schema.
123
- */
124
- export function assertAssetsWatchlistBlob(data) {
125
- assert(data, AssetsWatchlistBlobSchema);
126
- }
127
- /**
128
- * Asserts that the given value is a valid `AssetsWatchlistBlob` for
129
- * **writes**. In addition to the structural checks performed by
130
- * {@link assertAssetsWatchlistBlob}, this enforces that `assets` contains at
131
- * most {@link ASSETS_WATCHLIST_MAX_ASSETS} entries.
132
- *
133
- * @param data - The unknown value to validate.
134
- * @throws A `StructError` if the value does not match the expected schema
135
- * (including the size constraint).
136
- */
137
- export function assertAssetsWatchlistBlobForWrite(data) {
138
- assert(data, AssetsWatchlistBlobWriteSchema);
139
- }
140
90
  //# sourceMappingURL=validators.mjs.map