@metamask/name-controller 7.0.0 → 8.0.1

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 (154) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/dist/NameController.cjs +410 -0
  3. package/dist/NameController.cjs.map +1 -0
  4. package/dist/{types/NameController.d.ts → NameController.d.cts} +5 -5
  5. package/dist/NameController.d.cts.map +1 -0
  6. package/dist/NameController.d.mts +106 -0
  7. package/dist/NameController.d.mts.map +1 -0
  8. package/dist/NameController.mjs +404 -13
  9. package/dist/NameController.mjs.map +1 -1
  10. package/dist/constants.cjs +111 -0
  11. package/dist/constants.cjs.map +1 -0
  12. package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
  13. package/dist/constants.d.cts.map +1 -0
  14. package/dist/constants.d.mts +105 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.mjs +106 -8
  17. package/dist/constants.mjs.map +1 -1
  18. package/dist/index.cjs +23 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +7 -0
  21. package/dist/index.d.cts.map +1 -0
  22. package/dist/index.d.mts +7 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +6 -36
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/logger.cjs +7 -0
  27. package/dist/logger.cjs.map +1 -0
  28. package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
  29. package/dist/logger.d.cts.map +1 -0
  30. package/dist/logger.d.mts +5 -0
  31. package/dist/logger.d.mts.map +1 -0
  32. package/dist/logger.mjs +3 -9
  33. package/dist/logger.mjs.map +1 -1
  34. package/dist/providers/ens.cjs +65 -0
  35. package/dist/providers/ens.cjs.map +1 -0
  36. package/dist/{types/providers/ens.d.ts → providers/ens.d.cts} +2 -2
  37. package/dist/providers/ens.d.cts.map +1 -0
  38. package/dist/providers/ens.d.mts +12 -0
  39. package/dist/providers/ens.d.mts.map +1 -0
  40. package/dist/providers/ens.mjs +59 -8
  41. package/dist/providers/ens.mjs.map +1 -1
  42. package/dist/providers/etherscan.cjs +130 -0
  43. package/dist/providers/etherscan.cjs.map +1 -0
  44. package/dist/{types/providers/etherscan.d.ts → providers/etherscan.d.cts} +2 -2
  45. package/dist/providers/etherscan.d.cts.map +1 -0
  46. package/dist/providers/etherscan.d.mts +10 -0
  47. package/dist/providers/etherscan.d.mts.map +1 -0
  48. package/dist/providers/etherscan.mjs +124 -10
  49. package/dist/providers/etherscan.mjs.map +1 -1
  50. package/dist/providers/lens.cjs +77 -0
  51. package/dist/providers/lens.cjs.map +1 -0
  52. package/dist/{types/providers/lens.d.ts → providers/lens.d.cts} +2 -2
  53. package/dist/providers/lens.d.cts.map +1 -0
  54. package/dist/providers/lens.d.mts +10 -0
  55. package/dist/providers/lens.d.mts.map +1 -0
  56. package/dist/providers/lens.mjs +71 -9
  57. package/dist/providers/lens.mjs.map +1 -1
  58. package/dist/providers/token.cjs +68 -0
  59. package/dist/providers/token.cjs.map +1 -0
  60. package/dist/{types/providers/token.d.ts → providers/token.d.cts} +2 -2
  61. package/dist/providers/token.d.cts.map +1 -0
  62. package/dist/providers/token.d.mts +10 -0
  63. package/dist/providers/token.d.mts.map +1 -0
  64. package/dist/providers/token.mjs +62 -9
  65. package/dist/providers/token.mjs.map +1 -1
  66. package/dist/types.cjs +12 -0
  67. package/dist/types.cjs.map +1 -0
  68. package/dist/{types/types.d.ts → types.d.cts} +1 -1
  69. package/dist/types.d.cts.map +1 -0
  70. package/dist/types.d.mts +77 -0
  71. package/dist/types.d.mts.map +1 -0
  72. package/dist/types.mjs +8 -7
  73. package/dist/types.mjs.map +1 -1
  74. package/dist/util.cjs +76 -0
  75. package/dist/util.cjs.map +1 -0
  76. package/dist/{types/util.d.ts → util.d.cts} +1 -1
  77. package/dist/util.d.cts.map +1 -0
  78. package/dist/util.d.mts +35 -0
  79. package/dist/util.d.mts.map +1 -0
  80. package/dist/util.mjs +68 -13
  81. package/dist/util.mjs.map +1 -1
  82. package/package.json +22 -16
  83. package/dist/NameController.js +0 -15
  84. package/dist/NameController.js.map +0 -1
  85. package/dist/chunk-6AVJOVIX.mjs +0 -519
  86. package/dist/chunk-6AVJOVIX.mjs.map +0 -1
  87. package/dist/chunk-6W3DEAGA.mjs +0 -10
  88. package/dist/chunk-6W3DEAGA.mjs.map +0 -1
  89. package/dist/chunk-BLG7EQAA.mjs +0 -66
  90. package/dist/chunk-BLG7EQAA.mjs.map +0 -1
  91. package/dist/chunk-DSVOMJX6.mjs +0 -43
  92. package/dist/chunk-DSVOMJX6.mjs.map +0 -1
  93. package/dist/chunk-JHYBLEC5.js +0 -43
  94. package/dist/chunk-JHYBLEC5.js.map +0 -1
  95. package/dist/chunk-L244TFFU.mjs +0 -9
  96. package/dist/chunk-L244TFFU.mjs.map +0 -1
  97. package/dist/chunk-PL2KMW2Y.js +0 -519
  98. package/dist/chunk-PL2KMW2Y.js.map +0 -1
  99. package/dist/chunk-PL7IXD33.js +0 -10
  100. package/dist/chunk-PL7IXD33.js.map +0 -1
  101. package/dist/chunk-QBR7BSWB.js +0 -9
  102. package/dist/chunk-QBR7BSWB.js.map +0 -1
  103. package/dist/chunk-RYIUDJOI.js +0 -66
  104. package/dist/chunk-RYIUDJOI.js.map +0 -1
  105. package/dist/chunk-SHTSUEYM.mjs +0 -113
  106. package/dist/chunk-SHTSUEYM.mjs.map +0 -1
  107. package/dist/chunk-ST2ADXPO.js +0 -67
  108. package/dist/chunk-ST2ADXPO.js.map +0 -1
  109. package/dist/chunk-UALYD4SG.mjs +0 -138
  110. package/dist/chunk-UALYD4SG.mjs.map +0 -1
  111. package/dist/chunk-W64QIPGB.js +0 -80
  112. package/dist/chunk-W64QIPGB.js.map +0 -1
  113. package/dist/chunk-WHDNAWDA.mjs +0 -67
  114. package/dist/chunk-WHDNAWDA.mjs.map +0 -1
  115. package/dist/chunk-WSOVXHAC.mjs +0 -80
  116. package/dist/chunk-WSOVXHAC.mjs.map +0 -1
  117. package/dist/chunk-X55IV67M.js +0 -138
  118. package/dist/chunk-X55IV67M.js.map +0 -1
  119. package/dist/chunk-XQXO5QPM.js +0 -113
  120. package/dist/chunk-XQXO5QPM.js.map +0 -1
  121. package/dist/chunk-XUI43LEZ.mjs +0 -30
  122. package/dist/chunk-XUI43LEZ.mjs.map +0 -1
  123. package/dist/chunk-Z4BLTVTB.js +0 -30
  124. package/dist/chunk-Z4BLTVTB.js.map +0 -1
  125. package/dist/constants.js +0 -10
  126. package/dist/constants.js.map +0 -1
  127. package/dist/index.js +0 -37
  128. package/dist/index.js.map +0 -1
  129. package/dist/logger.js +0 -10
  130. package/dist/logger.js.map +0 -1
  131. package/dist/providers/ens.js +0 -10
  132. package/dist/providers/ens.js.map +0 -1
  133. package/dist/providers/etherscan.js +0 -12
  134. package/dist/providers/etherscan.js.map +0 -1
  135. package/dist/providers/lens.js +0 -11
  136. package/dist/providers/lens.js.map +0 -1
  137. package/dist/providers/token.js +0 -11
  138. package/dist/providers/token.js.map +0 -1
  139. package/dist/tsconfig.build.tsbuildinfo +0 -1
  140. package/dist/types/NameController.d.ts.map +0 -1
  141. package/dist/types/constants.d.ts.map +0 -1
  142. package/dist/types/index.d.ts +0 -7
  143. package/dist/types/index.d.ts.map +0 -1
  144. package/dist/types/logger.d.ts.map +0 -1
  145. package/dist/types/providers/ens.d.ts.map +0 -1
  146. package/dist/types/providers/etherscan.d.ts.map +0 -1
  147. package/dist/types/providers/lens.d.ts.map +0 -1
  148. package/dist/types/providers/token.d.ts.map +0 -1
  149. package/dist/types/types.d.ts.map +0 -1
  150. package/dist/types/util.d.ts.map +0 -1
  151. package/dist/types.js +0 -8
  152. package/dist/types.js.map +0 -1
  153. package/dist/util.js +0 -14
  154. package/dist/util.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/NameController.ts"],"sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { isSafeDynamicKey } from '@metamask/controller-utils';\n\nimport type {\n NameProvider,\n NameProviderRequest,\n NameProviderResult,\n NameProviderSourceResult,\n} from './types';\nimport { NameType } from './types';\n\nexport const FALLBACK_VARIATION = '*';\nexport const PROPOSED_NAME_EXPIRE_DURATION = 60 * 60 * 24; // 24 hours\n\n/**\n * Enumerates the possible origins responsible for setting a petname.\n */\nexport enum NameOrigin {\n // Originated from an account identity.\n ACCOUNT_IDENTITY = 'account-identity',\n // Originated from an address book entry.\n ADDRESS_BOOK = 'address-book',\n // Originated from the API (NameController.setName). This is the default.\n API = 'api',\n // Originated from the user taking action in the UI.\n UI = 'ui',\n}\n\nconst DEFAULT_UPDATE_DELAY = 60 * 2; // 2 Minutes\nconst DEFAULT_VARIATION = '';\n\nconst controllerName = 'NameController';\n\nconst stateMetadata = {\n names: { persist: true, anonymous: false },\n nameSources: { persist: true, anonymous: false },\n};\n\nconst getDefaultState = () => ({\n names: {\n [NameType.ETHEREUM_ADDRESS]: {},\n },\n nameSources: {},\n});\n\nexport type ProposedNamesEntry = {\n proposedNames: string[];\n lastRequestTime: number | null;\n updateDelay: number | null;\n};\n\nexport type NameEntry = {\n name: string | null;\n sourceId: string | null;\n origin: NameOrigin | null;\n proposedNames: Record<string, ProposedNamesEntry>;\n};\n\nexport type SourceEntry = {\n label: string;\n};\n\nexport type NameControllerState = {\n // Type > Value > Variation > Entry\n names: Record<NameType, Record<string, Record<string, NameEntry>>>;\n nameSources: Record<string, SourceEntry>;\n};\n\nexport type GetNameState = ControllerGetStateAction<\n typeof controllerName,\n NameControllerState\n>;\n\nexport type NameStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n NameControllerState\n>;\n\nexport type NameControllerActions = GetNameState;\n\nexport type NameControllerEvents = NameStateChange;\n\nexport type NameControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n NameControllerActions,\n NameControllerEvents,\n never,\n never\n>;\n\nexport type NameControllerOptions = {\n messenger: NameControllerMessenger;\n providers: NameProvider[];\n state?: Partial<NameControllerState>;\n updateDelay?: number;\n};\n\nexport type UpdateProposedNamesRequest = {\n value: string;\n type: NameType;\n sourceIds?: string[];\n onlyUpdateAfterDelay?: boolean;\n variation?: string;\n};\n\nexport type UpdateProposedNamesResult = {\n results: Record<string, { proposedNames?: string[]; error?: unknown }>;\n};\n\nexport type SetNameRequest = {\n value: string;\n type: NameType;\n name: string | null;\n sourceId?: string;\n variation?: string;\n origin?: NameOrigin;\n};\n\n/**\n * Controller for storing and deriving names for values such as Ethereum addresses.\n */\nexport class NameController extends BaseController<\n typeof controllerName,\n NameControllerState,\n NameControllerMessenger\n> {\n #providers: NameProvider[];\n\n #updateDelay: number;\n\n /**\n * Construct a Name controller.\n *\n * @param options - Controller options.\n * @param options.messenger - Restricted controller messenger for the name controller.\n * @param options.providers - Array of name provider instances to propose names.\n * @param options.state - Initial state to set on the controller.\n * @param options.updateDelay - The delay in seconds before a new request to a source should be made.\n */\n constructor({\n messenger,\n providers,\n state,\n updateDelay,\n }: NameControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#providers = providers;\n this.#updateDelay = updateDelay ?? DEFAULT_UPDATE_DELAY;\n }\n\n /**\n * Set the user specified name for a value.\n *\n * @param request - Request object.\n * @param request.name - Name to set.\n * @param request.sourceId - Optional ID of the source of the proposed name.\n * @param request.type - Type of value to set the name for.\n * @param request.value - Value to set the name for.\n * @param request.variation - Variation of the raw value to set the name for. The chain ID if the type is Ethereum address.\n */\n setName(request: SetNameRequest) {\n this.#validateSetNameRequest(request);\n\n const {\n value,\n type,\n name,\n sourceId: requestSourceId,\n origin: requestOrigin,\n variation,\n } = request;\n const sourceId = requestSourceId ?? null;\n // If the name is being cleared, the fallback origin should be cleared as well.\n const fallbackOrigin = name === null ? null : NameOrigin.API;\n const origin = requestOrigin ?? fallbackOrigin;\n\n this.#updateEntry(value, type, variation, (entry: NameEntry) => {\n entry.name = name;\n entry.sourceId = sourceId;\n entry.origin = origin;\n });\n }\n\n /**\n * Generate the proposed names for a value using the name providers and store them in the state.\n *\n * @param request - Request object.\n * @param request.value - Value to update the proposed names for.\n * @param request.type - Type of value to update the proposed names for.\n * @param request.sourceIds - Optional array of source IDs to limit which sources are used by the providers. If not provided, all sources in all providers will be used.\n * @param request.variation - Variation of the raw value to update proposed names for. The chain ID if the type is Ethereum address.\n * @returns The updated proposed names for the value.\n */\n async updateProposedNames(\n request: UpdateProposedNamesRequest,\n ): Promise<UpdateProposedNamesResult> {\n this.#validateUpdateProposedNamesRequest(request);\n\n const providerResponses = (\n await Promise.all(\n this.#providers.map((provider) =>\n this.#getProviderResponse(request, provider),\n ),\n )\n ).filter((response) => Boolean(response)) as NameProviderResult[];\n\n this.#updateProposedNameState(request, providerResponses);\n this.#updateSourceState(this.#providers);\n this.#removeExpiredEntries();\n\n return this.#getUpdateProposedNamesResult(providerResponses);\n }\n\n #updateProposedNameState(\n request: UpdateProposedNamesRequest,\n providerResponses: NameProviderResult[],\n ) {\n const { value, type, variation } = request;\n const currentTime = this.#getCurrentTimeSeconds();\n\n this.#updateEntry(value, type, variation, (entry: NameEntry) => {\n this.#removeDormantProposedNames(entry.proposedNames, type);\n\n for (const providerResponse of providerResponses) {\n const { results } = providerResponse;\n\n for (const sourceId of Object.keys(providerResponse.results)) {\n const result = results[sourceId];\n const { proposedNames, updateDelay } = result;\n\n const proposedNameEntry = entry.proposedNames[sourceId] ?? {\n proposedNames: [],\n lastRequestTime: null,\n updateDelay: null,\n };\n\n entry.proposedNames[sourceId] = proposedNameEntry;\n\n if (proposedNames) {\n proposedNameEntry.proposedNames = proposedNames;\n }\n\n proposedNameEntry.lastRequestTime = currentTime;\n proposedNameEntry.updateDelay = updateDelay ?? null;\n }\n }\n });\n }\n\n #updateSourceState(providers: NameProvider[]) {\n const newNameSources = { ...this.state.nameSources };\n\n for (const provider of providers) {\n const { sourceLabels } = provider.getMetadata();\n\n for (const sourceId of Object.keys(sourceLabels)) {\n newNameSources[sourceId] = {\n label: sourceLabels[sourceId],\n };\n }\n }\n\n this.update((state) => {\n state.nameSources = newNameSources;\n });\n }\n\n #getUpdateProposedNamesResult(\n providerResponses: NameProviderResult[],\n ): UpdateProposedNamesResult {\n return providerResponses.reduce(\n (acc: UpdateProposedNamesResult, providerResponse) => {\n const { results } = providerResponse;\n\n for (const sourceId of Object.keys(results)) {\n const { proposedNames, error } = results[sourceId];\n\n acc.results[sourceId] = {\n proposedNames,\n error,\n };\n }\n\n return acc;\n },\n { results: {} },\n );\n }\n\n async #getProviderResponse(\n request: UpdateProposedNamesRequest,\n provider: NameProvider,\n ): Promise<NameProviderResult | undefined> {\n const {\n value,\n type,\n sourceIds: requestedSourceIds,\n onlyUpdateAfterDelay,\n variation,\n } = request;\n\n /* istanbul ignore next */\n const variationKey = variation ?? DEFAULT_VARIATION;\n const supportedSourceIds = this.#getSourceIds(provider, type);\n const currentTime = this.#getCurrentTimeSeconds();\n const normalizedValue = this.#normalizeValue(value, type);\n\n const matchingSourceIds = supportedSourceIds.filter((sourceId) => {\n if (requestedSourceIds && !requestedSourceIds.includes(sourceId)) {\n return false;\n }\n\n if (onlyUpdateAfterDelay) {\n const entry =\n this.state.names[type]?.[normalizedValue]?.[variationKey] ?? {};\n const proposedNamesEntry = entry.proposedNames?.[sourceId] ?? {};\n const lastRequestTime = proposedNamesEntry.lastRequestTime ?? 0;\n const updateDelay = proposedNamesEntry.updateDelay ?? this.#updateDelay;\n\n if (currentTime - lastRequestTime < updateDelay) {\n return false;\n }\n }\n\n return true;\n });\n\n if (!matchingSourceIds.length) {\n return undefined;\n }\n\n const providerRequest: NameProviderRequest = {\n value: this.#normalizeValue(value, type),\n type,\n sourceIds: requestedSourceIds ? matchingSourceIds : undefined,\n variation: this.#normalizeVariation(variationKey, type),\n };\n\n let responseError: unknown | undefined;\n let response: NameProviderResult | undefined;\n\n try {\n response = await provider.getProposedNames(providerRequest);\n responseError = response.error;\n } catch (error) {\n responseError = error;\n }\n\n return this.#normalizeProviderResult(\n response,\n responseError,\n matchingSourceIds,\n );\n }\n\n #normalizeProviderResult(\n result: NameProviderResult | undefined,\n responseError: unknown,\n matchingSourceIds: string[],\n ): NameProviderResult {\n const error = responseError ?? undefined;\n\n const results = matchingSourceIds.reduce((acc, sourceId) => {\n const sourceResult = result?.results?.[sourceId];\n\n const normalizedSourceResult = this.#normalizeProviderSourceResult(\n sourceResult,\n responseError,\n );\n\n return {\n ...acc,\n [sourceId]: normalizedSourceResult,\n };\n }, {});\n\n return { results, error };\n }\n\n #normalizeProviderSourceResult(\n result: NameProviderSourceResult | undefined,\n responseError: unknown,\n ): NameProviderSourceResult | undefined {\n const error = result?.error ?? responseError ?? undefined;\n const updateDelay = result?.updateDelay ?? undefined;\n let proposedNames = error ? undefined : result?.proposedNames ?? undefined;\n\n if (proposedNames) {\n proposedNames = proposedNames.filter(\n (proposedName) => proposedName?.length,\n );\n }\n\n return {\n proposedNames,\n error,\n updateDelay,\n };\n }\n\n #normalizeValue(value: string, type: NameType): string {\n /* istanbul ignore next */\n switch (type) {\n case NameType.ETHEREUM_ADDRESS:\n return value.toLowerCase();\n\n default:\n return value;\n }\n }\n\n #normalizeVariation(variation: string, type: NameType): string {\n /* istanbul ignore next */\n switch (type) {\n case NameType.ETHEREUM_ADDRESS:\n return variation.toLowerCase();\n\n default:\n return variation;\n }\n }\n\n #updateEntry(\n value: string,\n type: NameType,\n variation: string | undefined,\n callback: (entry: NameEntry) => void,\n ) {\n /* istanbul ignore next */\n const variationKey = variation ?? DEFAULT_VARIATION;\n const normalizedValue = this.#normalizeValue(value, type);\n const normalizedVariation = this.#normalizeVariation(variationKey, type);\n\n if (\n [normalizedValue, normalizedVariation].some(\n (key) => !isSafeDynamicKey(key),\n )\n ) {\n return;\n }\n\n this.update((state) => {\n const typeEntries = state.names[type] || {};\n state.names[type] = typeEntries;\n\n const variationEntries = typeEntries[normalizedValue] || {};\n typeEntries[normalizedValue] = variationEntries;\n\n const entry = variationEntries[normalizedVariation] ?? {\n proposedNames: {},\n name: null,\n sourceId: null,\n origin: null,\n };\n variationEntries[normalizedVariation] = entry;\n\n callback(entry);\n });\n }\n\n #getCurrentTimeSeconds(): number {\n return Math.round(Date.now() / 1000);\n }\n\n #validateSetNameRequest(request: SetNameRequest) {\n const { name, value, type, sourceId, variation, origin } = request;\n const errorMessages: string[] = [];\n\n this.#validateValue(value, errorMessages);\n this.#validateType(type, errorMessages);\n this.#validateName(name, errorMessages);\n this.#validateSourceId(sourceId, type, name, errorMessages);\n this.#validateVariation(variation, type, errorMessages);\n this.#validateOrigin(origin, name, errorMessages);\n\n if (errorMessages.length) {\n throw new Error(errorMessages.join(' '));\n }\n }\n\n #validateUpdateProposedNamesRequest(request: UpdateProposedNamesRequest) {\n const { value, type, sourceIds, variation } = request;\n const errorMessages: string[] = [];\n\n this.#validateValue(value, errorMessages);\n this.#validateType(type, errorMessages);\n this.#validateSourceIds(sourceIds, type, errorMessages);\n this.#validateDuplicateSourceIds(type, errorMessages);\n this.#validateVariation(variation, type, errorMessages);\n\n if (errorMessages.length) {\n throw new Error(errorMessages.join(' '));\n }\n }\n\n #validateValue(value: string, errorMessages: string[]) {\n if (!value?.length || typeof value !== 'string') {\n errorMessages.push('Must specify a non-empty string for value.');\n }\n }\n\n #validateType(type: NameType, errorMessages: string[]) {\n if (!Object.values(NameType).includes(type)) {\n errorMessages.push(\n `Must specify one of the following types: ${Object.values(\n NameType,\n ).join(', ')}`,\n );\n }\n }\n\n #validateName(name: string | null, errorMessages: string[]) {\n if (name === null) {\n return;\n }\n\n if (!name?.length || typeof name !== 'string') {\n errorMessages.push('Must specify a non-empty string or null for name.');\n }\n }\n\n #validateSourceIds(\n sourceIds: string[] | undefined,\n type: NameType,\n errorMessages: string[],\n ) {\n if (!sourceIds) {\n return;\n }\n\n const allSourceIds = this.#getAllSourceIds(type);\n const missingSourceIds = [];\n\n for (const sourceId of sourceIds) {\n if (!allSourceIds.includes(sourceId)) {\n missingSourceIds.push(sourceId);\n continue;\n }\n }\n\n if (missingSourceIds.length) {\n errorMessages.push(\n `Unknown source IDs for type '${type}': ${missingSourceIds.join(', ')}`,\n );\n }\n }\n\n #validateSourceId(\n sourceId: string | undefined,\n type: NameType,\n name: string | null,\n errorMessages: string[],\n ) {\n if (sourceId === null || sourceId === undefined) {\n return;\n }\n\n if (name === null) {\n errorMessages.push(\n `Cannot specify a source ID when clearing the saved name: ${sourceId}`,\n );\n return;\n }\n\n const allSourceIds = this.#getAllSourceIds(type);\n\n if (!sourceId.length || typeof sourceId !== 'string') {\n errorMessages.push('Must specify a non-empty string for sourceId.');\n return;\n }\n\n if (!allSourceIds.includes(sourceId)) {\n errorMessages.push(`Unknown source ID for type '${type}': ${sourceId}`);\n }\n }\n\n #validateDuplicateSourceIds(type: NameType, errorMessages: string[]) {\n const allSourceIds = this.#getAllSourceIds(type);\n\n const duplicateSourceIds = allSourceIds.filter(\n (sourceId, index) => allSourceIds.indexOf(sourceId) !== index,\n );\n\n if (duplicateSourceIds.length) {\n errorMessages.push(\n `Duplicate source IDs found for type '${type}': ${duplicateSourceIds.join(\n ', ',\n )}`,\n );\n }\n }\n\n #validateVariation(\n variation: string | undefined,\n type: string,\n errorMessages: string[],\n ) {\n if (type !== NameType.ETHEREUM_ADDRESS) {\n return;\n }\n\n if (\n !variation?.length ||\n typeof variation !== 'string' ||\n (!variation.match(/^0x[0-9A-Fa-f]+$/u) &&\n variation !== FALLBACK_VARIATION)\n ) {\n errorMessages.push(\n `Must specify a chain ID in hexidecimal format or the fallback, \"${FALLBACK_VARIATION}\", for variation when using '${type}' type.`,\n );\n }\n }\n\n #validateOrigin(\n origin: NameOrigin | null | undefined,\n name: string | null,\n errorMessages: string[],\n ) {\n if (!origin) {\n return;\n }\n\n if (name === null) {\n errorMessages.push(\n `Cannot specify an origin when clearing the saved name: ${origin}`,\n );\n return;\n }\n\n if (!Object.values(NameOrigin).includes(origin)) {\n errorMessages.push(\n `Must specify one of the following origins: ${Object.values(\n NameOrigin,\n ).join(', ')}`,\n );\n }\n }\n\n #getAllSourceIds(type: NameType): string[] {\n return (\n this.#providers\n /* istanbul ignore next */\n .map((provider) => this.#getSourceIds(provider, type))\n .flat()\n );\n }\n\n #getSourceIds(provider: NameProvider, type: NameType): string[] {\n return provider.getMetadata().sourceIds[type];\n }\n\n #removeDormantProposedNames(\n proposedNames: Record<string, ProposedNamesEntry>,\n type: NameType,\n ) {\n if (Object.keys(proposedNames).length === 0) {\n return;\n }\n\n const typeSourceIds = this.#getAllSourceIds(type);\n\n const dormantSourceIds = Object.keys(proposedNames).filter(\n (sourceId) => !typeSourceIds.includes(sourceId),\n );\n\n for (const dormantSourceId of dormantSourceIds) {\n delete proposedNames[dormantSourceId];\n }\n }\n\n #removeExpiredEntries(): void {\n const currentTime = this.#getCurrentTimeSeconds();\n\n this.update((state: NameControllerState) => {\n const entries = this.#getEntriesList(state);\n for (const { nameType, value, variation, entry } of entries) {\n if (entry.name !== null) {\n continue;\n }\n\n const proposedNames = Object.values(entry.proposedNames);\n const allProposedNamesExpired = proposedNames.every(\n (proposedName: ProposedNamesEntry) =>\n currentTime - (proposedName.lastRequestTime ?? 0) >=\n PROPOSED_NAME_EXPIRE_DURATION,\n );\n\n if (allProposedNamesExpired) {\n delete state.names[nameType][value][variation];\n }\n }\n });\n }\n\n #getEntriesList(state: NameControllerState): {\n nameType: NameType;\n value: string;\n variation: string;\n entry: NameEntry;\n }[] {\n return Object.entries(state.names).flatMap(([type, typeEntries]) =>\n Object.entries(typeEntries).flatMap(([value, variationEntries]) =>\n Object.entries(variationEntries).map(([variation, entry]) => ({\n entry,\n nameType: type as NameType,\n value,\n variation,\n })),\n ),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;AAKA,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAU1B,IAAM,qBAAqB;AAC3B,IAAM,gCAAgC,KAAK,KAAK;AAKhD,IAAK,aAAL,kBAAKA,gBAAL;AAEL,EAAAA,YAAA,sBAAm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AAK,OAAO,CAAC,UAA+B;AAC1C,UAAM,UAAU,sBAAK,oCAAL,WAAqB;AACrC,eAAW,EAAE,UAAU,OAAO,WAAW,MAAM,KAAK,SAAS;AAC3D,UAAI,MAAM,SAAS,MAAM;AACvB;AAAA,MACF;AAEA,YAAM,gBAAgB,OAAO,OAAO,MAAM,aAAa;AACvD,YAAM,0BAA0B,cAAc;AAAA,QAC5C,CAAC,iBACC,eAAe,aAAa,mBAAmB,MAC/C;AAAA,MACJ;AAEA,UAAI,yBAAyB;AAC3B,eAAO,MAAM,MAAM,QAAQ,EAAE,KAAK,EAAE,SAAS;AAAA,MAC/C;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA;AAAA,oBAAe,SAAC,OAKZ;AACF,SAAO,OAAO,QAAQ,MAAM,KAAK,EAAE;AAAA,IAAQ,CAAC,CAAC,MAAM,WAAW,MAC5D,OAAO,QAAQ,WAAW,EAAE;AAAA,MAAQ,CAAC,CAAC,OAAO,gBAAgB,MAC3D,OAAO,QAAQ,gBAAgB,EAAE,IAAI,CAAC,CAAC,WAAW,KAAK,OAAO;AAAA,QAC5D;AAAA,QACA,UAAU;AAAA,QACV;AAAA,QACA;AAAA,MACF,EAAE;AAAA,IACJ;AAAA,EACF;AACF;","names":["NameOrigin"]}
@@ -1,10 +0,0 @@
1
- // src/types.ts
2
- var NameType = /* @__PURE__ */ ((NameType2) => {
3
- NameType2["ETHEREUM_ADDRESS"] = "ethereumAddress";
4
- return NameType2;
5
- })(NameType || {});
6
-
7
- export {
8
- NameType
9
- };
10
- //# sourceMappingURL=chunk-6W3DEAGA.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["/** The name types supported by the NameController. */\nexport enum NameType {\n /** The address of an Ethereum account. */\n ETHEREUM_ADDRESS = 'ethereumAddress',\n}\n\n/** The metadata for a name provider. */\nexport type NameProviderMetadata = {\n /**\n * IDs for each alternate source of proposed names.\n * Keyed by the name type.\n */\n sourceIds: Record<NameType, string[]>;\n\n /**\n * Friendly labels to describe each source of proposed names.\n * Keyed by the source ID.\n */\n sourceLabels: Record<string, string>;\n};\n\n/** The request data to get proposed names from a name provider. */\nexport type NameProviderRequest = {\n /** The optional list of source IDs to get proposed names from. */\n sourceIds?: string[];\n\n /** The type of name being requested. */\n type: NameType;\n\n /** The raw value to get proposed names for. */\n value: string;\n\n /**\n * The variation of the raw value to get proposed names for.\n * For example, the chain ID if the raw value is an Ethereum address.\n */\n variation: string;\n};\n\n/** The resulting data after requesting proposed names from a name provider, for a single source. */\nexport type NameProviderSourceResult = {\n /**\n * The array of proposed names from the source.\n * Undefined if there is an error.\n */\n proposedNames?: string[];\n\n /**\n * The delay in seconds before the next request to the source should be made.\n * Can be used to avoid rate limiting for example.\n */\n updateDelay?: number;\n\n /**\n * An error that occurred while fetching the proposed names from the source.\n * Undefined if there was no error.\n */\n error?: unknown;\n};\n\n/** The resulting data after requesting proposed names from a name provider. */\nexport type NameProviderResult = {\n /**\n * The resulting data from each alternate source of proposed names supported by the name provider.\n * Keyed by the source ID.\n */\n results: Record<string, NameProviderSourceResult>;\n\n /**\n * An error that occurred while fetching the proposed names that was not specific to a single source.\n * Undefined if there was no error.\n */\n error?: unknown;\n};\n\n/** An object capable of proposing friendly names for a raw value of a given type. */\nexport type NameProvider = {\n /**\n * Returns metadata about the name provider.\n */\n getMetadata(): NameProviderMetadata;\n\n /**\n * Returns proposed names for the given value and request data.\n *\n * @param request - The request data including the value to propose names for.\n */\n getProposedNames(request: NameProviderRequest): Promise<NameProviderResult>;\n};\n"],"mappings":";AACO,IAAK,WAAL,kBAAKA,cAAL;AAEL,EAAAA,UAAA,sBAAmB;AAFT,SAAAA;AAAA,GAAA;","names":["NameType"]}
@@ -1,66 +0,0 @@
1
- import {
2
- createModuleLogger,
3
- projectLogger
4
- } from "./chunk-L244TFFU.mjs";
5
- import {
6
- __privateAdd,
7
- __privateGet,
8
- __privateSet
9
- } from "./chunk-XUI43LEZ.mjs";
10
-
11
- // src/providers/ens.ts
12
- var ID = "ens";
13
- var LABEL = "Ethereum Name Service (ENS)";
14
- var log = createModuleLogger(projectLogger, "ens");
15
- var _isEnabled, _reverseLookup;
16
- var ENSNameProvider = class {
17
- constructor({
18
- isEnabled,
19
- reverseLookup
20
- }) {
21
- __privateAdd(this, _isEnabled, void 0);
22
- __privateAdd(this, _reverseLookup, void 0);
23
- __privateSet(this, _isEnabled, isEnabled || (() => true));
24
- __privateSet(this, _reverseLookup, reverseLookup);
25
- }
26
- getMetadata() {
27
- return {
28
- sourceIds: { ["ethereumAddress" /* ETHEREUM_ADDRESS */]: [ID] },
29
- sourceLabels: { [ID]: LABEL }
30
- };
31
- }
32
- async getProposedNames(request) {
33
- if (!__privateGet(this, _isEnabled).call(this)) {
34
- log("Skipping request as disabled");
35
- return {
36
- results: {
37
- [ID]: {
38
- proposedNames: []
39
- }
40
- }
41
- };
42
- }
43
- const { value, variation: chainId } = request;
44
- log("Invoking callback", { value, chainId });
45
- try {
46
- const proposedName = await __privateGet(this, _reverseLookup).call(this, value, chainId);
47
- const proposedNames = proposedName ? [proposedName] : [];
48
- log("New proposed names", proposedNames);
49
- return {
50
- results: {
51
- [ID]: { proposedNames }
52
- }
53
- };
54
- } catch (error) {
55
- log("Request failed", error);
56
- throw error;
57
- }
58
- }
59
- };
60
- _isEnabled = new WeakMap();
61
- _reverseLookup = new WeakMap();
62
-
63
- export {
64
- ENSNameProvider
65
- };
66
- //# sourceMappingURL=chunk-BLG7EQAA.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/providers/ens.ts"],"sourcesContent":["import { projectLogger, createModuleLogger } from '../logger';\nimport type {\n NameProvider,\n NameProviderMetadata,\n NameProviderRequest,\n NameProviderResult,\n} from '../types';\nimport { NameType } from '../types';\n\nexport type ReverseLookupCallback = (\n address: string,\n chainId: string,\n) => Promise<string>;\n\nconst ID = 'ens';\nconst LABEL = 'Ethereum Name Service (ENS)';\n\nconst log = createModuleLogger(projectLogger, 'ens');\n\nexport class ENSNameProvider implements NameProvider {\n #isEnabled: () => boolean;\n\n #reverseLookup: ReverseLookupCallback;\n\n constructor({\n isEnabled,\n reverseLookup,\n }: {\n isEnabled?: () => boolean;\n reverseLookup: ReverseLookupCallback;\n }) {\n this.#isEnabled = isEnabled || (() => true);\n this.#reverseLookup = reverseLookup;\n }\n\n getMetadata(): NameProviderMetadata {\n return {\n sourceIds: { [NameType.ETHEREUM_ADDRESS]: [ID] },\n sourceLabels: { [ID]: LABEL },\n };\n }\n\n async getProposedNames(\n request: NameProviderRequest,\n ): Promise<NameProviderResult> {\n if (!this.#isEnabled()) {\n log('Skipping request as disabled');\n\n return {\n results: {\n [ID]: {\n proposedNames: [],\n },\n },\n };\n }\n\n const { value, variation: chainId } = request;\n\n log('Invoking callback', { value, chainId });\n\n try {\n const proposedName = await this.#reverseLookup(value, chainId);\n const proposedNames = proposedName ? [proposedName] : [];\n\n log('New proposed names', proposedNames);\n\n return {\n results: {\n [ID]: { proposedNames },\n },\n };\n } catch (error) {\n log('Request failed', error);\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAM,KAAK;AACX,IAAM,QAAQ;AAEd,IAAM,MAAM,mBAAmB,eAAe,KAAK;AAjBnD;AAmBO,IAAM,kBAAN,MAA8C;AAAA,EAKnD,YAAY;AAAA,IACV;AAAA,IACA;AAAA,EACF,GAGG;AAVH;AAEA;AASE,uBAAK,YAAa,cAAc,MAAM;AACtC,uBAAK,gBAAiB;AAAA,EACxB;AAAA,EAEA,cAAoC;AAClC,WAAO;AAAA,MACL,WAAW,EAAE,yCAA0B,GAAG,CAAC,EAAE,EAAE;AAAA,MAC/C,cAAc,EAAE,CAAC,EAAE,GAAG,MAAM;AAAA,IAC9B;AAAA,EACF;AAAA,EAEA,MAAM,iBACJ,SAC6B;AAC7B,QAAI,CAAC,mBAAK,YAAL,YAAmB;AACtB,UAAI,8BAA8B;AAElC,aAAO;AAAA,QACL,SAAS;AAAA,UACP,CAAC,EAAE,GAAG;AAAA,YACJ,eAAe,CAAC;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,EAAE,OAAO,WAAW,QAAQ,IAAI;AAEtC,QAAI,qBAAqB,EAAE,OAAO,QAAQ,CAAC;AAE3C,QAAI;AACF,YAAM,eAAe,MAAM,mBAAK,gBAAL,WAAoB,OAAO;AACtD,YAAM,gBAAgB,eAAe,CAAC,YAAY,IAAI,CAAC;AAEvD,UAAI,sBAAsB,aAAa;AAEvC,aAAO;AAAA,QACL,SAAS;AAAA,UACP,CAAC,EAAE,GAAG,EAAE,cAAc;AAAA,QACxB;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,UAAI,kBAAkB,KAAK;AAC3B,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAzDE;AAEA;","names":[]}
@@ -1,43 +0,0 @@
1
- // src/util.ts
2
- async function graphQL(url, query, variables) {
3
- const body = JSON.stringify({
4
- query,
5
- variables
6
- });
7
- const response = await handleFetch(url, {
8
- body,
9
- method: "POST",
10
- headers: {
11
- "Content-Type": "application/json"
12
- }
13
- });
14
- return response?.data;
15
- }
16
- async function handleFetch(request, options) {
17
- const response = await successfulFetch(request, options);
18
- const object = await response.json();
19
- return object;
20
- }
21
- async function successfulFetch(request, options) {
22
- const response = await fetch(request, options);
23
- if (!response.ok) {
24
- throw new Error(
25
- `Fetch failed with status '${response.status}' for request '${request}'`
26
- );
27
- }
28
- return response;
29
- }
30
- function assertIsError(error) {
31
- if (error instanceof Error) {
32
- return;
33
- }
34
- throw new Error(`Invalid error of type '${typeof error}'`);
35
- }
36
-
37
- export {
38
- graphQL,
39
- handleFetch,
40
- successfulFetch,
41
- assertIsError
42
- };
43
- //# sourceMappingURL=chunk-DSVOMJX6.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/util.ts"],"sourcesContent":["/**\n * Execute a GraphQL query.\n *\n * @param url - GraphQL endpoint URL.\n * @param query - GraphQL query.\n * @param variables - GraphQL variables.\n */\nexport async function graphQL<T>(\n url: string,\n query: string,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n variables: Record<string, any>,\n): Promise<T> {\n const body = JSON.stringify({\n query,\n variables,\n });\n\n const response = await handleFetch(url, {\n body,\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n return response?.data;\n}\n\n// Below functions are intentionally copied from controller-utils to avoid a package dependency\n\n/**\n * Execute fetch and return object response.\n *\n * @param request - The request information.\n * @param options - The fetch options.\n * @returns The fetch response JSON data.\n */\nexport async function handleFetch(request: string, options?: RequestInit) {\n const response = await successfulFetch(request, options);\n const object = await response.json();\n return object;\n}\n\n/**\n * Execute fetch and verify that the response was successful.\n *\n * @param request - Request information.\n * @param options - Fetch options.\n * @returns The fetch response.\n */\nexport async function successfulFetch(request: string, options?: RequestInit) {\n const response = await fetch(request, options);\n if (!response.ok) {\n throw new Error(\n `Fetch failed with status '${response.status}' for request '${request}'`,\n );\n }\n return response;\n}\n\n/**\n * Assert that a value is an error. If it's not an error, throw an\n * error that wraps the given value.\n *\n * TODO: Migrate this to @metamask/utils\n *\n * @param error - The value that we expect to be an error.\n * @throws Throws an error wrapping the given value if it's not an error.\n */\nexport function assertIsError(error: unknown): asserts error is Error {\n if (error instanceof Error) {\n return;\n }\n throw new Error(`Invalid error of type '${typeof error}'`);\n}\n"],"mappings":";AAOA,eAAsB,QACpB,KACA,OAGA,WACY;AACZ,QAAM,OAAO,KAAK,UAAU;AAAA,IAC1B;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,WAAW,MAAM,YAAY,KAAK;AAAA,IACtC;AAAA,IACA,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,EACF,CAAC;AAED,SAAO,UAAU;AACnB;AAWA,eAAsB,YAAY,SAAiB,SAAuB;AACxE,QAAM,WAAW,MAAM,gBAAgB,SAAS,OAAO;AACvD,QAAM,SAAS,MAAM,SAAS,KAAK;AACnC,SAAO;AACT;AASA,eAAsB,gBAAgB,SAAiB,SAAuB;AAC5E,QAAM,WAAW,MAAM,MAAM,SAAS,OAAO;AAC7C,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI;AAAA,MACR,6BAA6B,SAAS,MAAM,kBAAkB,OAAO;AAAA,IACvE;AAAA,EACF;AACA,SAAO;AACT;AAWO,SAAS,cAAc,OAAwC;AACpE,MAAI,iBAAiB,OAAO;AAC1B;AAAA,EACF;AACA,QAAM,IAAI,MAAM,0BAA0B,OAAO,KAAK,GAAG;AAC3D;","names":[]}
@@ -1,43 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/util.ts
2
- async function graphQL(url, query, variables) {
3
- const body = JSON.stringify({
4
- query,
5
- variables
6
- });
7
- const response = await handleFetch(url, {
8
- body,
9
- method: "POST",
10
- headers: {
11
- "Content-Type": "application/json"
12
- }
13
- });
14
- return response?.data;
15
- }
16
- async function handleFetch(request, options) {
17
- const response = await successfulFetch(request, options);
18
- const object = await response.json();
19
- return object;
20
- }
21
- async function successfulFetch(request, options) {
22
- const response = await fetch(request, options);
23
- if (!response.ok) {
24
- throw new Error(
25
- `Fetch failed with status '${response.status}' for request '${request}'`
26
- );
27
- }
28
- return response;
29
- }
30
- function assertIsError(error) {
31
- if (error instanceof Error) {
32
- return;
33
- }
34
- throw new Error(`Invalid error of type '${typeof error}'`);
35
- }
36
-
37
-
38
-
39
-
40
-
41
-
42
- exports.graphQL = graphQL; exports.handleFetch = handleFetch; exports.successfulFetch = successfulFetch; exports.assertIsError = assertIsError;
43
- //# sourceMappingURL=chunk-JHYBLEC5.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/util.ts"],"names":[],"mappings":";AAOA,eAAsB,QACpB,KACA,OAGA,WACY;AACZ,QAAM,OAAO,KAAK,UAAU;AAAA,IAC1B;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,WAAW,MAAM,YAAY,KAAK;AAAA,IACtC;AAAA,IACA,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,EACF,CAAC;AAED,SAAO,UAAU;AACnB;AAWA,eAAsB,YAAY,SAAiB,SAAuB;AACxE,QAAM,WAAW,MAAM,gBAAgB,SAAS,OAAO;AACvD,QAAM,SAAS,MAAM,SAAS,KAAK;AACnC,SAAO;AACT;AASA,eAAsB,gBAAgB,SAAiB,SAAuB;AAC5E,QAAM,WAAW,MAAM,MAAM,SAAS,OAAO;AAC7C,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,IAAI;AAAA,MACR,6BAA6B,SAAS,MAAM,kBAAkB,OAAO;AAAA,IACvE;AAAA,EACF;AACA,SAAO;AACT;AAWO,SAAS,cAAc,OAAwC;AACpE,MAAI,iBAAiB,OAAO;AAC1B;AAAA,EACF;AACA,QAAM,IAAI,MAAM,0BAA0B,OAAO,KAAK,GAAG;AAC3D","sourcesContent":["/**\n * Execute a GraphQL query.\n *\n * @param url - GraphQL endpoint URL.\n * @param query - GraphQL query.\n * @param variables - GraphQL variables.\n */\nexport async function graphQL<T>(\n url: string,\n query: string,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n variables: Record<string, any>,\n): Promise<T> {\n const body = JSON.stringify({\n query,\n variables,\n });\n\n const response = await handleFetch(url, {\n body,\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n return response?.data;\n}\n\n// Below functions are intentionally copied from controller-utils to avoid a package dependency\n\n/**\n * Execute fetch and return object response.\n *\n * @param request - The request information.\n * @param options - The fetch options.\n * @returns The fetch response JSON data.\n */\nexport async function handleFetch(request: string, options?: RequestInit) {\n const response = await successfulFetch(request, options);\n const object = await response.json();\n return object;\n}\n\n/**\n * Execute fetch and verify that the response was successful.\n *\n * @param request - Request information.\n * @param options - Fetch options.\n * @returns The fetch response.\n */\nexport async function successfulFetch(request: string, options?: RequestInit) {\n const response = await fetch(request, options);\n if (!response.ok) {\n throw new Error(\n `Fetch failed with status '${response.status}' for request '${request}'`,\n );\n }\n return response;\n}\n\n/**\n * Assert that a value is an error. If it's not an error, throw an\n * error that wraps the given value.\n *\n * TODO: Migrate this to @metamask/utils\n *\n * @param error - The value that we expect to be an error.\n * @throws Throws an error wrapping the given value if it's not an error.\n */\nexport function assertIsError(error: unknown): asserts error is Error {\n if (error instanceof Error) {\n return;\n }\n throw new Error(`Invalid error of type '${typeof error}'`);\n}\n"]}
@@ -1,9 +0,0 @@
1
- // src/logger.ts
2
- import { createProjectLogger, createModuleLogger } from "@metamask/utils";
3
- var projectLogger = createProjectLogger("name-controller");
4
-
5
- export {
6
- createModuleLogger,
7
- projectLogger
8
- };
9
- //# sourceMappingURL=chunk-L244TFFU.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/logger.ts"],"sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('name-controller');\n\nexport { createModuleLogger };\n"],"mappings":";AAAA,SAAS,qBAAqB,0BAA0B;AAEjD,IAAM,gBAAgB,oBAAoB,iBAAiB;","names":[]}