@metamask/name-controller 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/dist/NameController.d.ts +15 -6
- package/dist/NameController.d.ts.map +1 -1
- package/dist/NameController.js +147 -81
- package/dist/NameController.js.map +1 -1
- package/dist/logger.d.ts +5 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +7 -0
- package/dist/logger.js.map +1 -0
- package/dist/providers/ens.d.ts +2 -1
- package/dist/providers/ens.d.ts.map +1 -1
- package/dist/providers/ens.js +33 -10
- package/dist/providers/ens.js.map +1 -1
- package/dist/providers/etherscan.d.ts +2 -2
- package/dist/providers/etherscan.d.ts.map +1 -1
- package/dist/providers/etherscan.js +85 -24
- package/dist/providers/etherscan.js.map +1 -1
- package/dist/providers/lens.d.ts +4 -0
- package/dist/providers/lens.d.ts.map +1 -1
- package/dist/providers/lens.js +47 -11
- package/dist/providers/lens.js.map +1 -1
- package/dist/providers/token.d.ts +4 -0
- package/dist/providers/token.d.ts.map +1 -1
- package/dist/providers/token.js +47 -9
- package/dist/providers/token.js.map +1 -1
- package/dist/types.d.ts +10 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +10 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +17 -1
- package/dist/util.js.map +1 -1
- package/package.json +8 -5
package/dist/providers/token.js
CHANGED
|
@@ -8,13 +8,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var _TokenNameProvider_isEnabled;
|
|
11
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
24
|
exports.TokenNameProvider = void 0;
|
|
25
|
+
const logger_1 = require("../logger");
|
|
13
26
|
const types_1 = require("../types");
|
|
14
27
|
const util_1 = require("../util");
|
|
15
28
|
const ID = 'token';
|
|
16
29
|
const LABEL = 'Blockchain (Token Name)';
|
|
30
|
+
const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'token');
|
|
17
31
|
class TokenNameProvider {
|
|
32
|
+
constructor({ isEnabled } = {}) {
|
|
33
|
+
_TokenNameProvider_isEnabled.set(this, void 0);
|
|
34
|
+
__classPrivateFieldSet(this, _TokenNameProvider_isEnabled, isEnabled || (() => true), "f");
|
|
35
|
+
}
|
|
18
36
|
getMetadata() {
|
|
19
37
|
return {
|
|
20
38
|
sourceIds: { [types_1.NameType.ETHEREUM_ADDRESS]: [ID] },
|
|
@@ -23,19 +41,39 @@ class TokenNameProvider {
|
|
|
23
41
|
}
|
|
24
42
|
getProposedNames(request) {
|
|
25
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
|
|
44
|
+
if (!__classPrivateFieldGet(this, _TokenNameProvider_isEnabled, "f").call(this)) {
|
|
45
|
+
log('Skipping request as disabled');
|
|
46
|
+
return {
|
|
47
|
+
results: {
|
|
48
|
+
[ID]: {
|
|
49
|
+
proposedNames: [],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const { value, variation: chainId } = request;
|
|
27
55
|
const url = `https://token-api.metaswap.codefi.network/token/${chainId}?address=${value}`;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
log('Sending request', url);
|
|
57
|
+
try {
|
|
58
|
+
const responseData = yield (0, util_1.handleFetch)(url);
|
|
59
|
+
const proposedName = responseData.name;
|
|
60
|
+
const proposedNames = proposedName ? [proposedName] : [];
|
|
61
|
+
log('New proposed names', proposedNames);
|
|
62
|
+
return {
|
|
63
|
+
results: {
|
|
64
|
+
[ID]: {
|
|
65
|
+
proposedNames,
|
|
66
|
+
},
|
|
34
67
|
},
|
|
35
|
-
}
|
|
36
|
-
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
log('Request failed', error);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
37
74
|
});
|
|
38
75
|
}
|
|
39
76
|
}
|
|
40
77
|
exports.TokenNameProvider = TokenNameProvider;
|
|
78
|
+
_TokenNameProvider_isEnabled = new WeakMap();
|
|
41
79
|
//# sourceMappingURL=token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/providers/token.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../src/providers/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAA8D;AAO9D,oCAAoC;AACpC,kCAAsC;AAEtC,MAAM,EAAE,GAAG,OAAO,CAAC;AACnB,MAAM,KAAK,GAAG,yBAAyB,CAAC;AAExC,MAAM,GAAG,GAAG,IAAA,2BAAkB,E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AAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;gBAC7B,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AArDD,8CAqDC","sourcesContent":["import { createModuleLogger, projectLogger } from '../logger';\nimport type {\n NameProvider,\n NameProviderMetadata,\n NameProviderRequest,\n NameProviderResult,\n} from '../types';\nimport { NameType } from '../types';\nimport { handleFetch } from '../util';\n\nconst ID = 'token';\nconst LABEL = 'Blockchain (Token Name)';\n\nconst log = createModuleLogger(projectLogger, 'token');\n\nexport class TokenNameProvider implements NameProvider {\n #isEnabled: () => boolean;\n\n constructor({ isEnabled }: { isEnabled?: () => boolean } = {}) {\n this.#isEnabled = isEnabled || (() => true);\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 const url = `https://token-api.metaswap.codefi.network/token/${chainId}?address=${value}`;\n\n log('Sending request', url);\n\n try {\n const responseData = await handleFetch(url);\n const proposedName = responseData.name;\n const proposedNames = proposedName ? [proposedName] : [];\n\n log('New proposed names', proposedNames);\n\n return {\n results: {\n [ID]: {\n proposedNames,\n },\n },\n };\n } catch (error) {\n log('Request failed', error);\n throw error;\n }\n }\n}\n"]}
|
package/dist/types.d.ts
CHANGED
|
@@ -18,14 +18,17 @@ export declare type NameProviderMetadata = {
|
|
|
18
18
|
};
|
|
19
19
|
/** The request data to get proposed names from a name provider. */
|
|
20
20
|
export declare type NameProviderRequest = {
|
|
21
|
-
/** The current chain ID of the client. */
|
|
22
|
-
chainId: string;
|
|
23
21
|
/** The optional list of source IDs to get proposed names from. */
|
|
24
22
|
sourceIds?: string[];
|
|
25
23
|
/** The type of name being requested. */
|
|
26
24
|
type: NameType;
|
|
27
25
|
/** The raw value to get proposed names for. */
|
|
28
26
|
value: string;
|
|
27
|
+
/**
|
|
28
|
+
* The variation of the raw value to get proposed names for.
|
|
29
|
+
* For example, the chain ID if the raw value is an Ethereum address.
|
|
30
|
+
*/
|
|
31
|
+
variation: string;
|
|
29
32
|
};
|
|
30
33
|
/** The resulting data after requesting proposed names from a name provider, for a single source. */
|
|
31
34
|
export declare type NameProviderSourceResult = {
|
|
@@ -34,6 +37,11 @@ export declare type NameProviderSourceResult = {
|
|
|
34
37
|
* Undefined if there is an error.
|
|
35
38
|
*/
|
|
36
39
|
proposedNames?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* The delay in seconds before the next request to the source should be made.
|
|
42
|
+
* Can be used to avoid rate limiting for example.
|
|
43
|
+
*/
|
|
44
|
+
updateDelay?: number;
|
|
37
45
|
/**
|
|
38
46
|
* An error that occurred while fetching the proposed names from the source.
|
|
39
47
|
* Undefined if there was no error.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,oBAAY,QAAQ;IAClB,0CAA0C;IAC1C,gBAAgB,oBAAoB;CACrC;AAED,wCAAwC;AACxC,oBAAY,oBAAoB,GAAG;IACjC;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAEtC;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAAC;AAEF,mEAAmE;AACnE,oBAAY,mBAAmB,GAAG;IAChC,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,oBAAY,QAAQ;IAClB,0CAA0C;IAC1C,gBAAgB,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;IAC1C,gDAAoC,CAAA;AACtC,CAAC,EAHW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAGnB","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
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,0CAA0C;IAC1C,gDAAoC,CAAA;AACtC,CAAC,EAHW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAGnB","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"]}
|
package/dist/util.d.ts
CHANGED
|
@@ -22,4 +22,14 @@ export declare function handleFetch(request: string, options?: RequestInit): Pro
|
|
|
22
22
|
* @returns The fetch response.
|
|
23
23
|
*/
|
|
24
24
|
export declare function successfulFetch(request: string, options?: RequestInit): Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* Assert that a value is an error. If it's not an error, throw an
|
|
27
|
+
* error that wraps the given value.
|
|
28
|
+
*
|
|
29
|
+
* TODO: Migrate this to @metamask/utils
|
|
30
|
+
*
|
|
31
|
+
* @param error - The value that we expect to be an error.
|
|
32
|
+
* @throws Throws an error wrapping the given value if it's not an error.
|
|
33
|
+
*/
|
|
34
|
+
export declare function assertIsError(error: unknown): asserts error is Error;
|
|
25
35
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAeZ;AAID;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,gBAIvE;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,qBAQ3E"}
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,OAAO,CAAC,CAAC,CAAC,CAeZ;AAID;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,gBAIvE;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,qBAQ3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,KAAK,CAKpE"}
|
package/dist/util.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.successfulFetch = exports.handleFetch = exports.graphQL = void 0;
|
|
12
|
+
exports.assertIsError = exports.successfulFetch = exports.handleFetch = exports.graphQL = void 0;
|
|
13
13
|
/**
|
|
14
14
|
* Execute a GraphQL query.
|
|
15
15
|
*
|
|
@@ -67,4 +67,20 @@ function successfulFetch(request, options) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
exports.successfulFetch = successfulFetch;
|
|
70
|
+
/**
|
|
71
|
+
* Assert that a value is an error. If it's not an error, throw an
|
|
72
|
+
* error that wraps the given value.
|
|
73
|
+
*
|
|
74
|
+
* TODO: Migrate this to @metamask/utils
|
|
75
|
+
*
|
|
76
|
+
* @param error - The value that we expect to be an error.
|
|
77
|
+
* @throws Throws an error wrapping the given value if it's not an error.
|
|
78
|
+
*/
|
|
79
|
+
function assertIsError(error) {
|
|
80
|
+
if (error instanceof Error) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`Invalid error of type '${typeof error}'`);
|
|
84
|
+
}
|
|
85
|
+
exports.assertIsError = assertIsError;
|
|
70
86
|
//# sourceMappingURL=util.js.map
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,SAAsB,OAAO,CAC3B,GAAW,EACX,KAAa,EACb,SAA8B;;QAE9B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;YAC1B,KAAK;YACL,SAAS;SACV,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE;YACtC,IAAI;YACJ,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;SACF,CAAC,CAAC;QAEH,OAAO,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAC;IACxB,CAAC;CAAA;AAnBD,0BAmBC;AAED,+FAA+F;AAE/F;;;;;;GAMG;AACH,SAAsB,WAAW,CAAC,OAAe,EAAE,OAAqB;;QACtE,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACrC,OAAO,MAAM,CAAC;IAChB,CAAC;CAAA;AAJD,kCAIC;AAED;;;;;;GAMG;AACH,SAAsB,eAAe,CAAC,OAAe,EAAE,OAAqB;;QAC1E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,MAAM,IAAI,KAAK,CACb,6BAA6B,QAAQ,CAAC,MAAM,kBAAkB,OAAO,GAAG,CACzE,CAAC;SACH;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CAAA;AARD,0CAQC","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 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"]}
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;GAMG;AACH,SAAsB,OAAO,CAC3B,GAAW,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L query.\n * @param variables - GraphQL variables.\n */\nexport async function graphQL<T>(\n url: string,\n query: string,\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/name-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Stores and suggests names for values such as Ethereum addresses",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -26,10 +26,13 @@
|
|
|
26
26
|
"prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
|
|
27
27
|
"publish:preview": "yarn npm publish --tag preview",
|
|
28
28
|
"test": "jest",
|
|
29
|
+
"test:clean": "jest --clearCache",
|
|
29
30
|
"test:watch": "jest --watch"
|
|
30
31
|
},
|
|
31
32
|
"dependencies": {
|
|
32
|
-
"@metamask/base-controller": "^3.2.
|
|
33
|
+
"@metamask/base-controller": "^3.2.2",
|
|
34
|
+
"@metamask/utils": "^6.2.0",
|
|
35
|
+
"async-mutex": "^0.2.6",
|
|
33
36
|
"immer": "^9.0.6"
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
@@ -38,9 +41,9 @@
|
|
|
38
41
|
"deepmerge": "^4.2.2",
|
|
39
42
|
"jest": "^27.5.1",
|
|
40
43
|
"ts-jest": "^27.1.4",
|
|
41
|
-
"typedoc": "^0.
|
|
42
|
-
"typedoc-plugin-missing-exports": "^0.
|
|
43
|
-
"typescript": "~4.
|
|
44
|
+
"typedoc": "^0.23.15",
|
|
45
|
+
"typedoc-plugin-missing-exports": "^0.23.0",
|
|
46
|
+
"typescript": "~4.8.4"
|
|
44
47
|
},
|
|
45
48
|
"engines": {
|
|
46
49
|
"node": ">=16.0.0"
|