@metamask/name-controller 8.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.
- package/CHANGELOG.md +26 -1
- package/dist/NameController.cjs +410 -0
- package/dist/NameController.cjs.map +1 -0
- package/dist/{types/NameController.d.ts → NameController.d.cts} +5 -5
- package/dist/NameController.d.cts.map +1 -0
- package/dist/NameController.d.mts +106 -0
- package/dist/NameController.d.mts.map +1 -0
- package/dist/NameController.mjs +404 -13
- package/dist/NameController.mjs.map +1 -1
- package/dist/constants.cjs +111 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +105 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +106 -8
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -36
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +3 -9
- package/dist/logger.mjs.map +1 -1
- package/dist/providers/ens.cjs +65 -0
- package/dist/providers/ens.cjs.map +1 -0
- package/dist/{types/providers/ens.d.ts → providers/ens.d.cts} +2 -2
- package/dist/providers/ens.d.cts.map +1 -0
- package/dist/providers/ens.d.mts +12 -0
- package/dist/providers/ens.d.mts.map +1 -0
- package/dist/providers/ens.mjs +59 -8
- package/dist/providers/ens.mjs.map +1 -1
- package/dist/providers/etherscan.cjs +130 -0
- package/dist/providers/etherscan.cjs.map +1 -0
- package/dist/{types/providers/etherscan.d.ts → providers/etherscan.d.cts} +2 -2
- package/dist/providers/etherscan.d.cts.map +1 -0
- package/dist/providers/etherscan.d.mts +10 -0
- package/dist/providers/etherscan.d.mts.map +1 -0
- package/dist/providers/etherscan.mjs +124 -10
- package/dist/providers/etherscan.mjs.map +1 -1
- package/dist/providers/lens.cjs +77 -0
- package/dist/providers/lens.cjs.map +1 -0
- package/dist/{types/providers/lens.d.ts → providers/lens.d.cts} +2 -2
- package/dist/providers/lens.d.cts.map +1 -0
- package/dist/providers/lens.d.mts +10 -0
- package/dist/providers/lens.d.mts.map +1 -0
- package/dist/providers/lens.mjs +71 -9
- package/dist/providers/lens.mjs.map +1 -1
- package/dist/providers/token.cjs +68 -0
- package/dist/providers/token.cjs.map +1 -0
- package/dist/{types/providers/token.d.ts → providers/token.d.cts} +2 -2
- package/dist/providers/token.d.cts.map +1 -0
- package/dist/providers/token.d.mts +10 -0
- package/dist/providers/token.d.mts.map +1 -0
- package/dist/providers/token.mjs +62 -9
- package/dist/providers/token.mjs.map +1 -1
- package/dist/types.cjs +12 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types/types.d.ts → types.d.cts} +1 -1
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +77 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +8 -7
- package/dist/types.mjs.map +1 -1
- package/dist/util.cjs +76 -0
- package/dist/util.cjs.map +1 -0
- package/dist/{types/util.d.ts → util.d.cts} +1 -1
- package/dist/util.d.cts.map +1 -0
- package/dist/util.d.mts +35 -0
- package/dist/util.d.mts.map +1 -0
- package/dist/util.mjs +68 -13
- package/dist/util.mjs.map +1 -1
- package/package.json +21 -15
- package/dist/NameController.js +0 -15
- package/dist/NameController.js.map +0 -1
- package/dist/chunk-6AVJOVIX.mjs +0 -519
- package/dist/chunk-6AVJOVIX.mjs.map +0 -1
- package/dist/chunk-6W3DEAGA.mjs +0 -10
- package/dist/chunk-6W3DEAGA.mjs.map +0 -1
- package/dist/chunk-BLG7EQAA.mjs +0 -66
- package/dist/chunk-BLG7EQAA.mjs.map +0 -1
- package/dist/chunk-DSVOMJX6.mjs +0 -43
- package/dist/chunk-DSVOMJX6.mjs.map +0 -1
- package/dist/chunk-JHYBLEC5.js +0 -43
- package/dist/chunk-JHYBLEC5.js.map +0 -1
- package/dist/chunk-L244TFFU.mjs +0 -9
- package/dist/chunk-L244TFFU.mjs.map +0 -1
- package/dist/chunk-PL2KMW2Y.js +0 -519
- package/dist/chunk-PL2KMW2Y.js.map +0 -1
- package/dist/chunk-PL7IXD33.js +0 -10
- package/dist/chunk-PL7IXD33.js.map +0 -1
- package/dist/chunk-QBR7BSWB.js +0 -9
- package/dist/chunk-QBR7BSWB.js.map +0 -1
- package/dist/chunk-RYIUDJOI.js +0 -66
- package/dist/chunk-RYIUDJOI.js.map +0 -1
- package/dist/chunk-SHTSUEYM.mjs +0 -113
- package/dist/chunk-SHTSUEYM.mjs.map +0 -1
- package/dist/chunk-ST2ADXPO.js +0 -67
- package/dist/chunk-ST2ADXPO.js.map +0 -1
- package/dist/chunk-UALYD4SG.mjs +0 -138
- package/dist/chunk-UALYD4SG.mjs.map +0 -1
- package/dist/chunk-W64QIPGB.js +0 -80
- package/dist/chunk-W64QIPGB.js.map +0 -1
- package/dist/chunk-WHDNAWDA.mjs +0 -67
- package/dist/chunk-WHDNAWDA.mjs.map +0 -1
- package/dist/chunk-WSOVXHAC.mjs +0 -80
- package/dist/chunk-WSOVXHAC.mjs.map +0 -1
- package/dist/chunk-X55IV67M.js +0 -138
- package/dist/chunk-X55IV67M.js.map +0 -1
- package/dist/chunk-XQXO5QPM.js +0 -113
- package/dist/chunk-XQXO5QPM.js.map +0 -1
- package/dist/chunk-XUI43LEZ.mjs +0 -30
- package/dist/chunk-XUI43LEZ.mjs.map +0 -1
- package/dist/chunk-Z4BLTVTB.js +0 -30
- package/dist/chunk-Z4BLTVTB.js.map +0 -1
- package/dist/constants.js +0 -10
- package/dist/constants.js.map +0 -1
- package/dist/index.js +0 -37
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -10
- package/dist/logger.js.map +0 -1
- package/dist/providers/ens.js +0 -10
- package/dist/providers/ens.js.map +0 -1
- package/dist/providers/etherscan.js +0 -12
- package/dist/providers/etherscan.js.map +0 -1
- package/dist/providers/lens.js +0 -11
- package/dist/providers/lens.js.map +0 -1
- package/dist/providers/token.js +0 -11
- package/dist/providers/token.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/NameController.d.ts.map +0 -1
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -7
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/providers/ens.d.ts.map +0 -1
- package/dist/types/providers/etherscan.d.ts.map +0 -1
- package/dist/types/providers/lens.d.ts.map +0 -1
- package/dist/types/providers/token.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/util.d.ts.map +0 -1
- package/dist/types.js +0 -8
- package/dist/types.js.map +0 -1
- package/dist/util.js +0 -14
- package/dist/util.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"lens.mjs","sourceRoot":"","sources":["../../src/providers/lens.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAO9D,OAAO,EAAE,QAAQ,EAAE,qBAAiB;AACpC,OAAO,EAAE,OAAO,EAAE,oBAAgB;AAElC,MAAM,EAAE,GAAG,MAAM,CAAC;AAClB,MAAM,KAAK,GAAG,eAAe,CAAC;AAC9B,MAAM,QAAQ,GAAG,sBAAsB,CAAC;AAExC,MAAM,KAAK,GAAG;;;;;;;EAOZ,CAAC;AAEH,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;AAYtD,MAAM,OAAO,gBAAgB;IAG3B,YAAY,EAAE,SAAS,KAAoC,EAAE;QAF7D,8CAA0B;QAGxB,uBAAA,IAAI,+BAAc,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAA,CAAC;IAC9C,CAAC;IAED,WAAW;QACT,OAAO;YACL,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YAChD,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,OAA4B;QAE5B,IAAI,CAAC,uBAAA,IAAI,mCAAW,MAAf,IAAI,CAAa,EAAE;YACtB,GAAG,CAAC,8BAA8B,CAAC,CAAC;YAEpC,OAAO;gBACL,OAAO,EAAE;oBACP,CAAC,EAAE,CAAC,EAAE;wBACJ,aAAa,EAAE,EAAE;qBAClB;iBACF;aACF,CAAC;SACH;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAC1B,MAAM,SAAS,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;QAErC,GAAG,CAAC,iBAAiB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QAEtC,IAAI;YACF,MAAM,YAAY,GAAG,MAAM,OAAO,CAChC,QAAQ,EACR,KAAK,EACL,SAAS,CACV,CAAC;YAEF,MAAM,QAAQ,GAAG,YAAY,EAAE,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC;YACrD,MAAM,aAAa,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAEhE,GAAG,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;YAEzC,OAAO;gBACL,OAAO,EAAE;oBACP,CAAC,EAAE,CAAC,EAAE;wBACJ,aAAa;qBACd;iBACF;aACF,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;YAC7B,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF","sourcesContent":["import { createModuleLogger, projectLogger } from '../logger';\nimport type {\n NameProvider,\n NameProviderMetadata,\n NameProviderRequest,\n NameProviderResult,\n} from '../types';\nimport { NameType } from '../types';\nimport { graphQL } from '../util';\n\nconst ID = 'lens';\nconst LABEL = 'Lens Protocol';\nconst LENS_URL = `https://api.lens.dev`;\n\nconst QUERY = `\nquery HandlesForAddress($address: EthereumAddress!) {\n profiles(request: { ownedBy: [$address] }) {\n items {\n handle\n }\n }\n}`;\n\nconst log = createModuleLogger(projectLogger, 'lens');\n\ntype LensResponse = {\n profiles: {\n items: [\n {\n handle: string;\n },\n ];\n };\n};\n\nexport class LensNameProvider 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 } = request;\n const variables = { address: value };\n\n log('Sending request', { variables });\n\n try {\n const responseData = await graphQL<LensResponse>(\n LENS_URL,\n QUERY,\n variables,\n );\n\n const profiles = responseData?.profiles?.items ?? [];\n const proposedNames = profiles.map((profile) => profile.handle);\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"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _TokenNameProvider_isEnabled;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TokenNameProvider = void 0;
|
|
16
|
+
const logger_1 = require("../logger.cjs");
|
|
17
|
+
const types_1 = require("../types.cjs");
|
|
18
|
+
const util_1 = require("../util.cjs");
|
|
19
|
+
const ID = 'token';
|
|
20
|
+
const LABEL = 'Blockchain (Token Name)';
|
|
21
|
+
const log = (0, logger_1.createModuleLogger)(logger_1.projectLogger, 'token');
|
|
22
|
+
class TokenNameProvider {
|
|
23
|
+
constructor({ isEnabled } = {}) {
|
|
24
|
+
_TokenNameProvider_isEnabled.set(this, void 0);
|
|
25
|
+
__classPrivateFieldSet(this, _TokenNameProvider_isEnabled, isEnabled || (() => true), "f");
|
|
26
|
+
}
|
|
27
|
+
getMetadata() {
|
|
28
|
+
return {
|
|
29
|
+
sourceIds: { [types_1.NameType.ETHEREUM_ADDRESS]: [ID] },
|
|
30
|
+
sourceLabels: { [ID]: LABEL },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async getProposedNames(request) {
|
|
34
|
+
if (!__classPrivateFieldGet(this, _TokenNameProvider_isEnabled, "f").call(this)) {
|
|
35
|
+
log('Skipping request as disabled');
|
|
36
|
+
return {
|
|
37
|
+
results: {
|
|
38
|
+
[ID]: {
|
|
39
|
+
proposedNames: [],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const { value, variation: chainId } = request;
|
|
45
|
+
const url = `https://token.api.cx.metamask.io/token/${chainId}?address=${value}`;
|
|
46
|
+
log('Sending request', url);
|
|
47
|
+
try {
|
|
48
|
+
const responseData = await (0, util_1.handleFetch)(url);
|
|
49
|
+
const proposedName = responseData.name;
|
|
50
|
+
const proposedNames = proposedName ? [proposedName] : [];
|
|
51
|
+
log('New proposed names', proposedNames);
|
|
52
|
+
return {
|
|
53
|
+
results: {
|
|
54
|
+
[ID]: {
|
|
55
|
+
proposedNames,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
log('Request failed', error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.TokenNameProvider = TokenNameProvider;
|
|
67
|
+
_TokenNameProvider_isEnabled = new WeakMap();
|
|
68
|
+
//# sourceMappingURL=token.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.cjs","sourceRoot":"","sources":["../../src/providers/token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAA8D;AAO9D,wCAAoC;AACpC,sCAAsC;AAEtC,MAAM,EAAE,GAAG,OAAO,CAAC;AACnB,MAAM,KAAK,GAAG,yBAAyB,CAAC;AAExC,MAAM,GAAG,GAAG,IAAA,2BAAkB,EAAC,sBAAa,EAAE,OAAO,CAAC,CAAC;AAEvD,MAAa,iBAAiB;IAG5B,YAAY,EAAE,SAAS,KAAoC,EAAE;QAF7D,+CAA0B;QAGxB,uBAAA,IAAI,gCAAc,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAA,CAAC;IAC9C,CAAC;IAED,WAAW;QACT,OAAO;YACL,SAAS,EAAE,EAAE,CAAC,gBAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YAChD,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,OAA4B;QAE5B,IAAI,CAAC,uBAAA,IAAI,oCAAW,MAAf,IAAI,CAAa,EAAE;YACtB,GAAG,CAAC,8BAA8B,CAAC,CAAC;YAEpC,OAAO;gBACL,OAAO,EAAE;oBACP,CAAC,EAAE,CAAC,EAAE;wBACJ,aAAa,EAAE,EAAE;qBAClB;iBACF;aACF,CAAC;SACH;QAED,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,GAAG,GAAG,0CAA0C,OAAO,YAAY,KAAK,EAAE,CAAC;QAEjF,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;QAE5B,IAAI;YACF,MAAM,YAAY,GAAG,MAAM,IAAA,kBAAW,EAAC,GAAG,CAAC,CAAC;YAC5C,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC;YACvC,MAAM,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAEzD,GAAG,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;YAEzC,OAAO;gBACL,OAAO,EAAE;oBACP,CAAC,EAAE,CAAC,EAAE;wBACJ,aAAa;qBACd;iBACF;aACF,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;YAC7B,MAAM,KAAK,CAAC;SACb;IACH,CAAC;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.cx.metamask.io/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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NameProvider, NameProviderMetadata, NameProviderRequest, NameProviderResult } from
|
|
1
|
+
import type { NameProvider, NameProviderMetadata, NameProviderRequest, NameProviderResult } from "../types.cjs";
|
|
2
2
|
export declare class TokenNameProvider implements NameProvider {
|
|
3
3
|
#private;
|
|
4
4
|
constructor({ isEnabled }?: {
|
|
@@ -7,4 +7,4 @@ export declare class TokenNameProvider implements NameProvider {
|
|
|
7
7
|
getMetadata(): NameProviderMetadata;
|
|
8
8
|
getProposedNames(request: NameProviderRequest): Promise<NameProviderResult>;
|
|
9
9
|
}
|
|
10
|
-
//# sourceMappingURL=token.d.
|
|
10
|
+
//# sourceMappingURL=token.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.d.cts","sourceRoot":"","sources":["../../src/providers/token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EACnB,qBAAiB;AASlB,qBAAa,iBAAkB,YAAW,YAAY;;gBAGxC,EAAE,SAAS,EAAE,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAA;KAAO;IAI7D,WAAW,IAAI,oBAAoB;IAO7B,gBAAgB,CACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC;CAqC/B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { NameProvider, NameProviderMetadata, NameProviderRequest, NameProviderResult } from "../types.mjs";
|
|
2
|
+
export declare class TokenNameProvider implements NameProvider {
|
|
3
|
+
#private;
|
|
4
|
+
constructor({ isEnabled }?: {
|
|
5
|
+
isEnabled?: () => boolean;
|
|
6
|
+
});
|
|
7
|
+
getMetadata(): NameProviderMetadata;
|
|
8
|
+
getProposedNames(request: NameProviderRequest): Promise<NameProviderResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=token.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"token.d.mts","sourceRoot":"","sources":["../../src/providers/token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EACnB,qBAAiB;AASlB,qBAAa,iBAAkB,YAAW,YAAY;;gBAGxC,EAAE,SAAS,EAAE,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,OAAO,CAAA;KAAO;IAI7D,WAAW,IAAI,oBAAoB;IAO7B,gBAAgB,CACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,kBAAkB,CAAC;CAqC/B"}
|
package/dist/providers/token.mjs
CHANGED
|
@@ -1,11 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import "../chunk-6W3DEAGA.mjs";
|
|
7
|
-
import "../chunk-XUI43LEZ.mjs";
|
|
8
|
-
export {
|
|
9
|
-
TokenNameProvider
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
10
6
|
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _TokenNameProvider_isEnabled;
|
|
13
|
+
import { createModuleLogger, projectLogger } from "../logger.mjs";
|
|
14
|
+
import { NameType } from "../types.mjs";
|
|
15
|
+
import { handleFetch } from "../util.mjs";
|
|
16
|
+
const ID = 'token';
|
|
17
|
+
const LABEL = 'Blockchain (Token Name)';
|
|
18
|
+
const log = createModuleLogger(projectLogger, 'token');
|
|
19
|
+
export class TokenNameProvider {
|
|
20
|
+
constructor({ isEnabled } = {}) {
|
|
21
|
+
_TokenNameProvider_isEnabled.set(this, void 0);
|
|
22
|
+
__classPrivateFieldSet(this, _TokenNameProvider_isEnabled, isEnabled || (() => true), "f");
|
|
23
|
+
}
|
|
24
|
+
getMetadata() {
|
|
25
|
+
return {
|
|
26
|
+
sourceIds: { [NameType.ETHEREUM_ADDRESS]: [ID] },
|
|
27
|
+
sourceLabels: { [ID]: LABEL },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async getProposedNames(request) {
|
|
31
|
+
if (!__classPrivateFieldGet(this, _TokenNameProvider_isEnabled, "f").call(this)) {
|
|
32
|
+
log('Skipping request as disabled');
|
|
33
|
+
return {
|
|
34
|
+
results: {
|
|
35
|
+
[ID]: {
|
|
36
|
+
proposedNames: [],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const { value, variation: chainId } = request;
|
|
42
|
+
const url = `https://token.api.cx.metamask.io/token/${chainId}?address=${value}`;
|
|
43
|
+
log('Sending request', url);
|
|
44
|
+
try {
|
|
45
|
+
const responseData = await handleFetch(url);
|
|
46
|
+
const proposedName = responseData.name;
|
|
47
|
+
const proposedNames = proposedName ? [proposedName] : [];
|
|
48
|
+
log('New proposed names', proposedNames);
|
|
49
|
+
return {
|
|
50
|
+
results: {
|
|
51
|
+
[ID]: {
|
|
52
|
+
proposedNames,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
log('Request failed', error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
_TokenNameProvider_isEnabled = new WeakMap();
|
|
11
64
|
//# sourceMappingURL=token.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"token.mjs","sourceRoot":"","sources":["../../src/providers/token.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAkB;AAO9D,OAAO,EAAE,QAAQ,EAAE,qBAAiB;AACpC,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,MAAM,EAAE,GAAG,OAAO,CAAC;AACnB,MAAM,KAAK,GAAG,yBAAyB,CAAC;AAExC,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAEvD,MAAM,OAAO,iBAAiB;IAG5B,YAAY,EAAE,SAAS,KAAoC,EAAE;QAF7D,+CAA0B;QAGxB,uBAAA,IAAI,gCAAc,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAA,CAAC;IAC9C,CAAC;IAED,WAAW;QACT,OAAO;YACL,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;YAChD,YAAY,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE;SAC9B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,OAA4B;QAE5B,IAAI,CAAC,uBAAA,IAAI,oCAAW,MAAf,IAAI,CAAa,EAAE;YACtB,GAAG,CAAC,8BAA8B,CAAC,CAAC;YAEpC,OAAO;gBACL,OAAO,EAAE;oBACP,CAAC,EAAE,CAAC,EAAE;wBACJ,aAAa,EAAE,EAAE;qBAClB;iBACF;aACF,CAAC;SACH;QAED,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,GAAG,GAAG,0CAA0C,OAAO,YAAY,KAAK,EAAE,CAAC;QAEjF,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;QAE5B,IAAI;YACF,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;YAC5C,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC;YACvC,MAAM,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAEzD,GAAG,CAAC,oBAAoB,EAAE,aAAa,CAAC,CAAC;YAEzC,OAAO;gBACL,OAAO,EAAE;oBACP,CAAC,EAAE,CAAC,EAAE;wBACJ,aAAa;qBACd;iBACF;aACF,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;YAC7B,MAAM,KAAK,CAAC;SACb;IACH,CAAC;CACF","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.cx.metamask.io/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.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NameType = void 0;
|
|
4
|
+
/** The name types supported by the NameController. */
|
|
5
|
+
var NameType;
|
|
6
|
+
(function (NameType) {
|
|
7
|
+
/** The address of an Ethereum account. */
|
|
8
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
+
NameType["ETHEREUM_ADDRESS"] = "ethereumAddress";
|
|
11
|
+
})(NameType || (exports.NameType = NameType = {}));
|
|
12
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,0CAA0C;IAC1C,gFAAgF;IAChF,gEAAgE;IAChE,gDAAoC,CAAA;AACtC,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB","sourcesContent":["/** The name types supported by the NameController. */\nexport enum NameType {\n /** The address of an Ethereum account. */\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,oBAAY,QAAQ;IAClB,0CAA0C;IAG1C,gBAAgB,oBAAoB;CACrC;AAED,wCAAwC;AACxC,MAAM,MAAM,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,MAAM,MAAM,mBAAmB,GAAG;IAChC,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB,wCAAwC;IACxC,IAAI,EAAE,QAAQ,CAAC;IAEf,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oGAAoG;AACpG,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IAElD;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,WAAW,IAAI,oBAAoB,CAAC;IAEpC;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC7E,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** The name types supported by the NameController. */
|
|
2
|
+
export declare enum NameType {
|
|
3
|
+
/** The address of an Ethereum account. */
|
|
4
|
+
ETHEREUM_ADDRESS = "ethereumAddress"
|
|
5
|
+
}
|
|
6
|
+
/** The metadata for a name provider. */
|
|
7
|
+
export type NameProviderMetadata = {
|
|
8
|
+
/**
|
|
9
|
+
* IDs for each alternate source of proposed names.
|
|
10
|
+
* Keyed by the name type.
|
|
11
|
+
*/
|
|
12
|
+
sourceIds: Record<NameType, string[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Friendly labels to describe each source of proposed names.
|
|
15
|
+
* Keyed by the source ID.
|
|
16
|
+
*/
|
|
17
|
+
sourceLabels: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
/** The request data to get proposed names from a name provider. */
|
|
20
|
+
export type NameProviderRequest = {
|
|
21
|
+
/** The optional list of source IDs to get proposed names from. */
|
|
22
|
+
sourceIds?: string[];
|
|
23
|
+
/** The type of name being requested. */
|
|
24
|
+
type: NameType;
|
|
25
|
+
/** The raw value to get proposed names for. */
|
|
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;
|
|
32
|
+
};
|
|
33
|
+
/** The resulting data after requesting proposed names from a name provider, for a single source. */
|
|
34
|
+
export type NameProviderSourceResult = {
|
|
35
|
+
/**
|
|
36
|
+
* The array of proposed names from the source.
|
|
37
|
+
* Undefined if there is an error.
|
|
38
|
+
*/
|
|
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;
|
|
45
|
+
/**
|
|
46
|
+
* An error that occurred while fetching the proposed names from the source.
|
|
47
|
+
* Undefined if there was no error.
|
|
48
|
+
*/
|
|
49
|
+
error?: unknown;
|
|
50
|
+
};
|
|
51
|
+
/** The resulting data after requesting proposed names from a name provider. */
|
|
52
|
+
export type NameProviderResult = {
|
|
53
|
+
/**
|
|
54
|
+
* The resulting data from each alternate source of proposed names supported by the name provider.
|
|
55
|
+
* Keyed by the source ID.
|
|
56
|
+
*/
|
|
57
|
+
results: Record<string, NameProviderSourceResult>;
|
|
58
|
+
/**
|
|
59
|
+
* An error that occurred while fetching the proposed names that was not specific to a single source.
|
|
60
|
+
* Undefined if there was no error.
|
|
61
|
+
*/
|
|
62
|
+
error?: unknown;
|
|
63
|
+
};
|
|
64
|
+
/** An object capable of proposing friendly names for a raw value of a given type. */
|
|
65
|
+
export type NameProvider = {
|
|
66
|
+
/**
|
|
67
|
+
* Returns metadata about the name provider.
|
|
68
|
+
*/
|
|
69
|
+
getMetadata(): NameProviderMetadata;
|
|
70
|
+
/**
|
|
71
|
+
* Returns proposed names for the given value and request data.
|
|
72
|
+
*
|
|
73
|
+
* @param request - The request data including the value to propose names for.
|
|
74
|
+
*/
|
|
75
|
+
getProposedNames(request: NameProviderRequest): Promise<NameProviderResult>;
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,oBAAY,QAAQ;IAClB,0CAA0C;IAG1C,gBAAgB,oBAAoB;CACrC;AAED,wCAAwC;AACxC,MAAM,MAAM,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,MAAM,MAAM,mBAAmB,GAAG;IAChC,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAErB,wCAAwC;IACxC,IAAI,EAAE,QAAQ,CAAC;IAEf,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oGAAoG;AACpG,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IAElD;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,qFAAqF;AACrF,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,WAAW,IAAI,oBAAoB,CAAC;IAEpC;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAC7E,CAAC"}
|
package/dist/types.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/** The name types supported by the NameController. */
|
|
2
|
+
export var NameType;
|
|
3
|
+
(function (NameType) {
|
|
4
|
+
/** The address of an Ethereum account. */
|
|
5
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
NameType["ETHEREUM_ADDRESS"] = "ethereumAddress";
|
|
8
|
+
})(NameType || (NameType = {}));
|
|
8
9
|
//# sourceMappingURL=types.mjs.map
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,0CAA0C;IAC1C,gFAAgF;IAChF,gEAAgE;IAChE,gDAAoC,CAAA;AACtC,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB","sourcesContent":["/** The name types supported by the NameController. */\nexport enum NameType {\n /** The address of an Ethereum account. */\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\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.cjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertIsError = exports.successfulFetch = exports.handleFetch = exports.graphQL = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Execute a GraphQL query.
|
|
6
|
+
*
|
|
7
|
+
* @param url - GraphQL endpoint URL.
|
|
8
|
+
* @param query - GraphQL query.
|
|
9
|
+
* @param variables - GraphQL variables.
|
|
10
|
+
*/
|
|
11
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
|
+
async function graphQL(url, query,
|
|
14
|
+
// TODO: Replace `any` with type
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
+
variables) {
|
|
17
|
+
const body = JSON.stringify({
|
|
18
|
+
query,
|
|
19
|
+
variables,
|
|
20
|
+
});
|
|
21
|
+
const response = await handleFetch(url, {
|
|
22
|
+
body,
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return response?.data;
|
|
29
|
+
}
|
|
30
|
+
exports.graphQL = graphQL;
|
|
31
|
+
// Below functions are intentionally copied from controller-utils to avoid a package dependency
|
|
32
|
+
/**
|
|
33
|
+
* Execute fetch and return object response.
|
|
34
|
+
*
|
|
35
|
+
* @param request - The request information.
|
|
36
|
+
* @param options - The fetch options.
|
|
37
|
+
* @returns The fetch response JSON data.
|
|
38
|
+
*/
|
|
39
|
+
async function handleFetch(request, options) {
|
|
40
|
+
const response = await successfulFetch(request, options);
|
|
41
|
+
const object = await response.json();
|
|
42
|
+
return object;
|
|
43
|
+
}
|
|
44
|
+
exports.handleFetch = handleFetch;
|
|
45
|
+
/**
|
|
46
|
+
* Execute fetch and verify that the response was successful.
|
|
47
|
+
*
|
|
48
|
+
* @param request - Request information.
|
|
49
|
+
* @param options - Fetch options.
|
|
50
|
+
* @returns The fetch response.
|
|
51
|
+
*/
|
|
52
|
+
async function successfulFetch(request, options) {
|
|
53
|
+
const response = await fetch(request, options);
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new Error(`Fetch failed with status '${response.status}' for request '${request}'`);
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
exports.successfulFetch = successfulFetch;
|
|
60
|
+
/**
|
|
61
|
+
* Assert that a value is an error. If it's not an error, throw an
|
|
62
|
+
* error that wraps the given value.
|
|
63
|
+
*
|
|
64
|
+
* TODO: Migrate this to @metamask/utils
|
|
65
|
+
*
|
|
66
|
+
* @param error - The value that we expect to be an error.
|
|
67
|
+
* @throws Throws an error wrapping the given value if it's not an error.
|
|
68
|
+
*/
|
|
69
|
+
function assertIsError(error) {
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
throw new Error(`Invalid error of type '${typeof error}'`);
|
|
74
|
+
}
|
|
75
|
+
exports.assertIsError = assertIsError;
|
|
76
|
+
//# sourceMappingURL=util.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.cjs","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,gFAAgF;AAChF,gEAAgE;AACzD,KAAK,UAAU,OAAO,CAC3B,GAAW,EACX,KAAa;AACb,gCAAgC;AAChC,8DAA8D;AAC9D,SAA8B;IAE9B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1B,KAAK;QACL,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE;QACtC,IAAI;QACJ,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IAEH,OAAO,QAAQ,EAAE,IAAI,CAAC;AACxB,CAAC;AArBD,0BAqBC;AAED,+FAA+F;AAE/F;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAAC,OAAe,EAAE,OAAqB;IACtE,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACrC,OAAO,MAAM,CAAC;AAChB,CAAC;AAJD,kCAIC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,eAAe,CAAC,OAAe,EAAE,OAAqB;IAC1E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;QAChB,MAAM,IAAI,KAAK,CACb,6BAA6B,QAAQ,CAAC,MAAM,kBAAkB,OAAO,GAAG,CACzE,CAAC;KACH;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AARD,0CAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,OAAO;KACR;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,KAAK,GAAG,CAAC,CAAC;AAC7D,CAAC;AALD,sCAKC","sourcesContent":["/**\n * Execute a GraphQL query.\n *\n * @param url - GraphQL endpoint URL.\n * @param query - GraphQL query.\n * @param variables - GraphQL variables.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\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"]}
|
|
@@ -32,4 +32,4 @@ export declare function successfulFetch(request: string, options?: RequestInit):
|
|
|
32
32
|
* @throws Throws an error wrapping the given value if it's not an error.
|
|
33
33
|
*/
|
|
34
34
|
export declare function assertIsError(error: unknown): asserts error is Error;
|
|
35
|
-
//# sourceMappingURL=util.d.
|
|
35
|
+
//# sourceMappingURL=util.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.cts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EAGb,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.d.mts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Execute a GraphQL query.
|
|
3
|
+
*
|
|
4
|
+
* @param url - GraphQL endpoint URL.
|
|
5
|
+
* @param query - GraphQL query.
|
|
6
|
+
* @param variables - GraphQL variables.
|
|
7
|
+
*/
|
|
8
|
+
export declare function graphQL<T>(url: string, query: string, variables: Record<string, any>): Promise<T>;
|
|
9
|
+
/**
|
|
10
|
+
* Execute fetch and return object response.
|
|
11
|
+
*
|
|
12
|
+
* @param request - The request information.
|
|
13
|
+
* @param options - The fetch options.
|
|
14
|
+
* @returns The fetch response JSON data.
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleFetch(request: string, options?: RequestInit): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* Execute fetch and verify that the response was successful.
|
|
19
|
+
*
|
|
20
|
+
* @param request - Request information.
|
|
21
|
+
* @param options - Fetch options.
|
|
22
|
+
* @returns The fetch response.
|
|
23
|
+
*/
|
|
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;
|
|
35
|
+
//# sourceMappingURL=util.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.mts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EAGb,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.mjs
CHANGED
|
@@ -1,14 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Execute a GraphQL query.
|
|
3
|
+
*
|
|
4
|
+
* @param url - GraphQL endpoint URL.
|
|
5
|
+
* @param query - GraphQL query.
|
|
6
|
+
* @param variables - GraphQL variables.
|
|
7
|
+
*/
|
|
8
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
+
export async function graphQL(url, query,
|
|
11
|
+
// TODO: Replace `any` with type
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
variables) {
|
|
14
|
+
const body = JSON.stringify({
|
|
15
|
+
query,
|
|
16
|
+
variables,
|
|
17
|
+
});
|
|
18
|
+
const response = await handleFetch(url, {
|
|
19
|
+
body,
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
return response?.data;
|
|
26
|
+
}
|
|
27
|
+
// Below functions are intentionally copied from controller-utils to avoid a package dependency
|
|
28
|
+
/**
|
|
29
|
+
* Execute fetch and return object response.
|
|
30
|
+
*
|
|
31
|
+
* @param request - The request information.
|
|
32
|
+
* @param options - The fetch options.
|
|
33
|
+
* @returns The fetch response JSON data.
|
|
34
|
+
*/
|
|
35
|
+
export async function handleFetch(request, options) {
|
|
36
|
+
const response = await successfulFetch(request, options);
|
|
37
|
+
const object = await response.json();
|
|
38
|
+
return object;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Execute fetch and verify that the response was successful.
|
|
42
|
+
*
|
|
43
|
+
* @param request - Request information.
|
|
44
|
+
* @param options - Fetch options.
|
|
45
|
+
* @returns The fetch response.
|
|
46
|
+
*/
|
|
47
|
+
export async function successfulFetch(request, options) {
|
|
48
|
+
const response = await fetch(request, options);
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw new Error(`Fetch failed with status '${response.status}' for request '${request}'`);
|
|
51
|
+
}
|
|
52
|
+
return response;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Assert that a value is an error. If it's not an error, throw an
|
|
56
|
+
* error that wraps the given value.
|
|
57
|
+
*
|
|
58
|
+
* TODO: Migrate this to @metamask/utils
|
|
59
|
+
*
|
|
60
|
+
* @param error - The value that we expect to be an error.
|
|
61
|
+
* @throws Throws an error wrapping the given value if it's not an error.
|
|
62
|
+
*/
|
|
63
|
+
export function assertIsError(error) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Invalid error of type '${typeof error}'`);
|
|
68
|
+
}
|
|
14
69
|
//# sourceMappingURL=util.mjs.map
|
package/dist/util.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"util.mjs","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,gFAAgF;AAChF,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,GAAW,EACX,KAAa;AACb,gCAAgC;AAChC,8DAA8D;AAC9D,SAA8B;IAE9B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC1B,KAAK;QACL,SAAS;KACV,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE;QACtC,IAAI;QACJ,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IAEH,OAAO,QAAQ,EAAE,IAAI,CAAC;AACxB,CAAC;AAED,+FAA+F;AAE/F;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAe,EAAE,OAAqB;IACtE,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACrC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAe,EAAE,OAAqB;IAC1E,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC/C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;QAChB,MAAM,IAAI,KAAK,CACb,6BAA6B,QAAQ,CAAC,MAAM,kBAAkB,OAAO,GAAG,CACzE,CAAC;KACH;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,YAAY,KAAK,EAAE;QAC1B,OAAO;KACR;IACD,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,KAAK,GAAG,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["/**\n * Execute a GraphQL query.\n *\n * @param url - GraphQL endpoint URL.\n * @param query - GraphQL query.\n * @param variables - GraphQL variables.\n */\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\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"]}
|