@metamask/name-controller 8.0.0 → 8.0.2
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 +35 -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
package/dist/chunk-6W3DEAGA.mjs
DELETED
|
@@ -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"]}
|
package/dist/chunk-BLG7EQAA.mjs
DELETED
|
@@ -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":[]}
|
package/dist/chunk-DSVOMJX6.mjs
DELETED
|
@@ -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":[]}
|
package/dist/chunk-JHYBLEC5.js
DELETED
|
@@ -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"]}
|
package/dist/chunk-L244TFFU.mjs
DELETED
|
@@ -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":[]}
|