@ensdomains/ensjs 3.0.0-alpha.61 → 3.0.0-alpha.63
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/README.md +0 -16
- package/dist/cjs/GqlManager.js +4 -0
- package/dist/cjs/contracts/getContractAddress.js +2 -2
- package/dist/cjs/functions/batch.js +23 -1
- package/dist/cjs/functions/getHistory.js +11 -9
- package/dist/cjs/functions/getNames.js +10 -2
- package/dist/cjs/functions/getOwner.js +64 -17
- package/dist/cjs/functions/getProfile.js +66 -26
- package/dist/cjs/functions/getSubnames.js +10 -1
- package/dist/cjs/functions/supportsTLD.js +1 -1
- package/dist/cjs/utils/errors.js +67 -0
- package/dist/esm/GqlManager.mjs +4 -0
- package/dist/esm/contracts/getContractAddress.mjs +2 -2
- package/dist/esm/functions/batch.mjs +23 -1
- package/dist/esm/functions/getHistory.mjs +14 -9
- package/dist/esm/functions/getNames.mjs +14 -2
- package/dist/esm/functions/getOwner.mjs +68 -17
- package/dist/esm/functions/getProfile.mjs +70 -26
- package/dist/esm/functions/getSubnames.mjs +14 -1
- package/dist/esm/functions/supportsTLD.mjs +1 -1
- package/dist/esm/utils/errors.mjs +49 -0
- package/dist/types/functions/getHistory.d.ts +19 -0
- package/dist/types/functions/getOwner.d.ts +7 -3
- package/dist/types/functions/getProfile.d.ts +1 -0
- package/dist/types/functions/getSubnames.d.ts +5 -4
- package/dist/types/index.d.ts +9 -7
- package/dist/types/utils/errors.d.ts +14 -0
- package/package.json +1 -1
- package/src/GqlManager.test.ts +17 -0
- package/src/GqlManager.ts +7 -0
- package/src/contracts/getContractAddress.ts +2 -2
- package/src/functions/batch.test.ts +41 -0
- package/src/functions/batch.ts +31 -1
- package/src/functions/getHistory.test.ts +25 -0
- package/src/functions/getHistory.ts +28 -11
- package/src/functions/getNames.test.ts +28 -0
- package/src/functions/getNames.ts +19 -2
- package/src/functions/getOwner.test.ts +161 -2
- package/src/functions/getOwner.ts +90 -18
- package/src/functions/getProfile.test.ts +129 -2
- package/src/functions/getProfile.ts +89 -32
- package/src/functions/getSubnames.test.ts +35 -0
- package/src/functions/getSubnames.ts +24 -2
- package/src/functions/supportsTLD.ts +1 -1
- package/src/utils/errors.ts +68 -0
package/README.md
CHANGED
|
@@ -417,22 +417,6 @@ Output:
|
|
|
417
417
|
- _Only applicable for address inputs_
|
|
418
418
|
- Forward resolved match check value
|
|
419
419
|
|
|
420
|
-
### getRecords
|
|
421
|
-
|
|
422
|
-
Gets all the records of a specified name, or just certain records if specified.
|
|
423
|
-
|
|
424
|
-
Input:
|
|
425
|
-
|
|
426
|
-
- `name`: string
|
|
427
|
-
- `options`: object?
|
|
428
|
-
- `contentHash`: boolean?
|
|
429
|
-
- `texts`: boolean? | string[]?
|
|
430
|
-
- Array of keys, or true for all keys
|
|
431
|
-
- `coinTypes`: boolean? | string[]?
|
|
432
|
-
- Array of keys, or true for all keys
|
|
433
|
-
|
|
434
|
-
Output: **see getProfile**
|
|
435
|
-
|
|
436
420
|
### getResolver
|
|
437
421
|
|
|
438
422
|
Gets the resolver for a specified name.
|
package/dist/cjs/GqlManager.js
CHANGED
|
@@ -30,6 +30,7 @@ __export(GqlManager_exports, {
|
|
|
30
30
|
responseMiddleware: () => responseMiddleware
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(GqlManager_exports);
|
|
33
|
+
var import_errors = require("./utils/errors");
|
|
33
34
|
var import_normalise = require("./utils/normalise");
|
|
34
35
|
const generateSelection = (selection) => ({
|
|
35
36
|
kind: "Field",
|
|
@@ -59,6 +60,7 @@ const enter = (node) => {
|
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
62
|
const requestMiddleware = (visit, parse, print) => (request) => {
|
|
63
|
+
(0, import_errors.debugSubgraphError)(request);
|
|
62
64
|
const requestBody = JSON.parse(request.body);
|
|
63
65
|
const rawQuery = requestBody.query;
|
|
64
66
|
const parsedQuery = parse(rawQuery);
|
|
@@ -73,6 +75,8 @@ const requestMiddleware = (visit, parse, print) => (request) => {
|
|
|
73
75
|
};
|
|
74
76
|
};
|
|
75
77
|
const responseMiddleware = (traverse) => (response) => {
|
|
78
|
+
if (response instanceof Error)
|
|
79
|
+
return response;
|
|
76
80
|
traverse(response).forEach(function(responseItem) {
|
|
77
81
|
if (responseItem instanceof Object && responseItem.name) {
|
|
78
82
|
if (responseItem.name && responseItem.name.includes("[")) {
|
|
@@ -56,8 +56,8 @@ const addresses = {
|
|
|
56
56
|
"5": "0x56522d00c410a43bffdf00a9a569489297385790"
|
|
57
57
|
},
|
|
58
58
|
BulkRenewal: {
|
|
59
|
-
"1": "
|
|
60
|
-
"5": "
|
|
59
|
+
"1": "0xa12159e5131b1eEf6B4857EEE3e1954744b5033A",
|
|
60
|
+
"5": "0xeA64C81d0d718620daBC02D61f3B255C641f475F"
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
const getContractAddress = (networkId) => (contractName) => {
|
|
@@ -21,6 +21,7 @@ __export(batch_exports, {
|
|
|
21
21
|
default: () => batch_default
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(batch_exports);
|
|
24
|
+
var import_errors = require("../utils/errors");
|
|
24
25
|
const raw = async ({ multicallWrapper }, ...items) => {
|
|
25
26
|
const rawDataArr = await Promise.all(
|
|
26
27
|
items.map(({ args, raw: rawRef }, i) => {
|
|
@@ -37,7 +38,7 @@ const decode = async ({ multicallWrapper }, data, passthrough, ...items) => {
|
|
|
37
38
|
const response = await multicallWrapper.decode(data, passthrough);
|
|
38
39
|
if (!response)
|
|
39
40
|
return;
|
|
40
|
-
|
|
41
|
+
const results = await Promise.allSettled(
|
|
41
42
|
response.map((ret, i) => {
|
|
42
43
|
if (passthrough[i].passthrough) {
|
|
43
44
|
return items[i].decode(
|
|
@@ -49,6 +50,27 @@ const decode = async ({ multicallWrapper }, data, passthrough, ...items) => {
|
|
|
49
50
|
return items[i].decode(ret.returnData, ...items[i].args);
|
|
50
51
|
})
|
|
51
52
|
);
|
|
53
|
+
const reducedResults = results.reduce(
|
|
54
|
+
(acc, result) => {
|
|
55
|
+
if (result.status === "fulfilled") {
|
|
56
|
+
return { ...acc, data: [...acc.data, result.value] };
|
|
57
|
+
}
|
|
58
|
+
const error = result.reason instanceof import_errors.ENSJSError ? result.reason : void 0;
|
|
59
|
+
const itemData = error == null ? void 0 : error.data;
|
|
60
|
+
const itemErrors = (error == null ? void 0 : error.errors) || [{ message: "unknown_error" }];
|
|
61
|
+
return {
|
|
62
|
+
errors: [...acc.errors, ...itemErrors],
|
|
63
|
+
data: [...acc.data, itemData]
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
{ data: [], errors: [] }
|
|
67
|
+
);
|
|
68
|
+
if (reducedResults.errors.length)
|
|
69
|
+
throw new import_errors.ENSJSError({
|
|
70
|
+
data: reducedResults.data,
|
|
71
|
+
errors: reducedResults.errors
|
|
72
|
+
});
|
|
73
|
+
return reducedResults.data;
|
|
52
74
|
};
|
|
53
75
|
var batch_default = {
|
|
54
76
|
raw,
|
|
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(getHistory_exports);
|
|
|
24
24
|
var import_address_encoder = require("@ensdomains/address-encoder");
|
|
25
25
|
var import_bytes = require("@ethersproject/bytes");
|
|
26
26
|
var import_contentHash = require("../utils/contentHash");
|
|
27
|
+
var import_errors = require("../utils/errors");
|
|
27
28
|
var import_normalise = require("../utils/normalise");
|
|
28
29
|
var import_validation = require("../utils/validation");
|
|
29
30
|
const eventFormat = {
|
|
@@ -104,6 +105,7 @@ const mapEvents = (eventArray, type) => eventArray.map(
|
|
|
104
105
|
})
|
|
105
106
|
);
|
|
106
107
|
async function getHistory({ gqlInstance }, name) {
|
|
108
|
+
var _a, _b;
|
|
107
109
|
const { client } = gqlInstance;
|
|
108
110
|
const query = gqlInstance.gql`
|
|
109
111
|
query getHistory($namehash: String!) {
|
|
@@ -231,14 +233,16 @@ async function getHistory({ gqlInstance }, name) {
|
|
|
231
233
|
const is2ldEth = (0, import_validation.checkIsDotEth)(labels);
|
|
232
234
|
const response = await client.request(query, {
|
|
233
235
|
namehash: nameHash
|
|
234
|
-
})
|
|
236
|
+
}).catch((e) => {
|
|
237
|
+
throw new import_errors.ENSJSError({
|
|
238
|
+
errors: (0, import_errors.getClientErrors)(e)
|
|
239
|
+
});
|
|
240
|
+
}).finally(import_errors.debugSubgraphLatency);
|
|
235
241
|
const domain = response == null ? void 0 : response.domain;
|
|
236
242
|
if (!domain)
|
|
237
|
-
return;
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
resolver: { events: resolverEvents }
|
|
241
|
-
} = domain;
|
|
243
|
+
return void 0;
|
|
244
|
+
const domainEvents = domain.events || [];
|
|
245
|
+
const resolverEvents = ((_a = domain.resolver) == null ? void 0 : _a.events) || [];
|
|
242
246
|
const domainHistory = mapEvents(domainEvents, "Domain");
|
|
243
247
|
const resolverHistory = mapEvents(
|
|
244
248
|
resolverEvents.filter(
|
|
@@ -247,9 +251,7 @@ async function getHistory({ gqlInstance }, name) {
|
|
|
247
251
|
"Resolver"
|
|
248
252
|
);
|
|
249
253
|
if (is2ldEth) {
|
|
250
|
-
const
|
|
251
|
-
registration: { events: registrationEvents }
|
|
252
|
-
} = domain;
|
|
254
|
+
const registrationEvents = ((_b = domain.registration) == null ? void 0 : _b.events) || [];
|
|
253
255
|
const registrationHistory = mapEvents(registrationEvents, "Registration");
|
|
254
256
|
return {
|
|
255
257
|
domain: domainHistory,
|
|
@@ -21,6 +21,7 @@ __export(getNames_exports, {
|
|
|
21
21
|
default: () => getNames_default
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getNames_exports);
|
|
24
|
+
var import_errors = require("../utils/errors");
|
|
24
25
|
var import_format = require("../utils/format");
|
|
25
26
|
var import_fuses = require("../utils/fuses");
|
|
26
27
|
var import_labels = require("../utils/labels");
|
|
@@ -383,10 +384,16 @@ const getNames = async ({ gqlInstance }, {
|
|
|
383
384
|
expiryDate: Math.floor(Date.now() / 1e3) - 90 * 24 * 60 * 60
|
|
384
385
|
};
|
|
385
386
|
}
|
|
386
|
-
const response = await client.request(finalQuery, queryVars)
|
|
387
|
+
const response = await client.request(finalQuery, queryVars).catch((e) => {
|
|
388
|
+
console.error(e);
|
|
389
|
+
throw new import_errors.ENSJSError({
|
|
390
|
+
errors: (0, import_errors.getClientErrors)(e),
|
|
391
|
+
data: []
|
|
392
|
+
});
|
|
393
|
+
}).finally(import_errors.debugSubgraphLatency);
|
|
387
394
|
const account = response == null ? void 0 : response.account;
|
|
388
395
|
if (type === "all") {
|
|
389
|
-
|
|
396
|
+
const data = [
|
|
390
397
|
...(account == null ? void 0 : account.domains.map(mapDomain)) || [],
|
|
391
398
|
...(account == null ? void 0 : account.registrations.map(mapRegistration)) || [],
|
|
392
399
|
...(account == null ? void 0 : account.wrappedDomains.map(mapWrappedDomain).filter((d) => d)) || []
|
|
@@ -402,6 +409,7 @@ const getNames = async ({ gqlInstance }, {
|
|
|
402
409
|
}
|
|
403
410
|
return a.createdAt.getTime() - b.createdAt.getTime();
|
|
404
411
|
});
|
|
412
|
+
return data;
|
|
405
413
|
}
|
|
406
414
|
if (type === "resolvedAddress") {
|
|
407
415
|
return (response == null ? void 0 : response.domains.map(mapResolvedAddress).filter((d) => d)) || [];
|
|
@@ -26,6 +26,7 @@ var import_bytes = require("@ethersproject/bytes");
|
|
|
26
26
|
var import_labels = require("../utils/labels");
|
|
27
27
|
var import_normalise = require("../utils/normalise");
|
|
28
28
|
var import_validation = require("../utils/validation");
|
|
29
|
+
var import_errors = require("../utils/errors");
|
|
29
30
|
const singleContractOwnerRaw = async ({ contracts }, contract, namehash, labels) => {
|
|
30
31
|
switch (contract) {
|
|
31
32
|
case "nameWrapper": {
|
|
@@ -53,7 +54,8 @@ const singleContractOwnerRaw = async ({ contracts }, contract, namehash, labels)
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
};
|
|
56
|
-
const raw = async ({ contracts, multicallWrapper }, name,
|
|
57
|
+
const raw = async ({ contracts, multicallWrapper }, name, options = {}) => {
|
|
58
|
+
const { contract } = options;
|
|
57
59
|
const namehash = (0, import_normalise.namehash)(name);
|
|
58
60
|
const labels = name.split(".");
|
|
59
61
|
if (contract || labels.length === 1) {
|
|
@@ -104,11 +106,14 @@ const decode = async ({
|
|
|
104
106
|
contracts,
|
|
105
107
|
multicallWrapper,
|
|
106
108
|
gqlInstance
|
|
107
|
-
}, data, name,
|
|
109
|
+
}, data, name, options = {}) => {
|
|
108
110
|
var _a, _b, _c, _d, _e;
|
|
109
111
|
if (!data)
|
|
110
112
|
return;
|
|
113
|
+
const { contract, skipGraph = true } = options;
|
|
111
114
|
const labels = name.split(".");
|
|
115
|
+
const isEth = labels[labels.length - 1] === "eth";
|
|
116
|
+
const is2LD = labels.length === 2;
|
|
112
117
|
if (contract || labels.length === 1) {
|
|
113
118
|
const singleOwner = singleContractOwnerDecode(data);
|
|
114
119
|
const obj = {
|
|
@@ -136,48 +141,85 @@ const decode = async ({
|
|
|
136
141
|
const nameWrapperOwner = decodedData[1][0];
|
|
137
142
|
let registrarOwner = (_b = decodedData[2]) == null ? void 0 : _b[0];
|
|
138
143
|
let baseReturnObject = {};
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
144
|
+
if (isEth) {
|
|
145
|
+
let graphErrors;
|
|
146
|
+
if (is2LD) {
|
|
147
|
+
if (!registrarOwner && !skipGraph) {
|
|
148
|
+
const graphRegistrantResult = await gqlInstance.client.request(registrantQuery, {
|
|
149
|
+
namehash: (0, import_normalise.namehash)(name)
|
|
150
|
+
}).catch((e) => {
|
|
151
|
+
console.error(e);
|
|
152
|
+
graphErrors = (0, import_errors.getClientErrors)(e);
|
|
153
|
+
return void 0;
|
|
154
|
+
}).finally(import_errors.debugSubgraphLatency);
|
|
155
|
+
registrarOwner = (_e = (_d = (_c = graphRegistrantResult == null ? void 0 : graphRegistrantResult.domain) == null ? void 0 : _c.registration) == null ? void 0 : _d.registrant) == null ? void 0 : _e.id;
|
|
149
156
|
baseReturnObject = {
|
|
150
157
|
expired: true
|
|
151
158
|
};
|
|
152
159
|
} else {
|
|
153
160
|
baseReturnObject = {
|
|
154
|
-
expired:
|
|
161
|
+
expired: !registrarOwner
|
|
155
162
|
};
|
|
156
163
|
}
|
|
157
164
|
}
|
|
165
|
+
if (baseReturnObject.expired && (registryOwner == null ? void 0 : registryOwner.toLowerCase()) === nameWrapper.address.toLowerCase()) {
|
|
166
|
+
const owner = {
|
|
167
|
+
owner: nameWrapperOwner,
|
|
168
|
+
ownershipLevel: "nameWrapper",
|
|
169
|
+
...baseReturnObject
|
|
170
|
+
};
|
|
171
|
+
if (graphErrors) {
|
|
172
|
+
throw new import_errors.ENSJSError({
|
|
173
|
+
data: owner,
|
|
174
|
+
errors: graphErrors
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return owner;
|
|
178
|
+
}
|
|
158
179
|
if ((registrarOwner == null ? void 0 : registrarOwner.toLowerCase()) === nameWrapper.address.toLowerCase()) {
|
|
159
|
-
|
|
180
|
+
const owner = {
|
|
160
181
|
owner: nameWrapperOwner,
|
|
161
182
|
ownershipLevel: "nameWrapper",
|
|
162
183
|
...baseReturnObject
|
|
163
184
|
};
|
|
185
|
+
if (graphErrors) {
|
|
186
|
+
throw new import_errors.ENSJSError({
|
|
187
|
+
data: owner,
|
|
188
|
+
errors: graphErrors
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return owner;
|
|
164
192
|
}
|
|
165
193
|
if (registrarOwner) {
|
|
166
|
-
|
|
194
|
+
const owner = {
|
|
167
195
|
registrant: registrarOwner,
|
|
168
196
|
owner: registryOwner,
|
|
169
197
|
ownershipLevel: "registrar",
|
|
170
198
|
...baseReturnObject
|
|
171
199
|
};
|
|
200
|
+
if (graphErrors) {
|
|
201
|
+
throw new import_errors.ENSJSError({
|
|
202
|
+
data: owner,
|
|
203
|
+
errors: graphErrors
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return owner;
|
|
172
207
|
}
|
|
173
208
|
if ((0, import_bytes.hexStripZeros)(registryOwner) !== "0x") {
|
|
174
209
|
if (labels.length === 2) {
|
|
175
|
-
|
|
210
|
+
const owner = {
|
|
176
211
|
registrant: void 0,
|
|
177
212
|
owner: registryOwner,
|
|
178
213
|
ownershipLevel: "registrar",
|
|
179
214
|
expired: true
|
|
180
215
|
};
|
|
216
|
+
if (graphErrors) {
|
|
217
|
+
throw new import_errors.ENSJSError({
|
|
218
|
+
data: owner,
|
|
219
|
+
errors: graphErrors
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return owner;
|
|
181
223
|
}
|
|
182
224
|
if (registryOwner === nameWrapper.address && nameWrapperOwner && (0, import_bytes.hexStripZeros)(nameWrapperOwner) !== "0x") {
|
|
183
225
|
return {
|
|
@@ -190,7 +232,12 @@ const decode = async ({
|
|
|
190
232
|
ownershipLevel: "registry"
|
|
191
233
|
};
|
|
192
234
|
}
|
|
193
|
-
|
|
235
|
+
if (graphErrors) {
|
|
236
|
+
throw new import_errors.ENSJSError({
|
|
237
|
+
errors: graphErrors
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
return void 0;
|
|
194
241
|
}
|
|
195
242
|
if (registryOwner === nameWrapper.address && nameWrapperOwner && (0, import_bytes.hexStripZeros)(nameWrapperOwner) !== "0x") {
|
|
196
243
|
return {
|
|
@@ -28,6 +28,7 @@ var import_bytes = require("@ethersproject/bytes");
|
|
|
28
28
|
var import_contentHash = require("../utils/contentHash");
|
|
29
29
|
var import_hexEncodedName = require("../utils/hexEncodedName");
|
|
30
30
|
var import_normalise = require("../utils/normalise");
|
|
31
|
+
var import_errors = require("../utils/errors");
|
|
31
32
|
const makeMulticallData = async ({
|
|
32
33
|
_getAddr,
|
|
33
34
|
_getContentHash,
|
|
@@ -247,7 +248,9 @@ const getDataForName = async ({
|
|
|
247
248
|
resolverAddress
|
|
248
249
|
};
|
|
249
250
|
};
|
|
250
|
-
const graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress) => {
|
|
251
|
+
const graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress, skipGraph = true) => {
|
|
252
|
+
if (skipGraph)
|
|
253
|
+
return { status: void 0, result: void 0 };
|
|
251
254
|
const query = gqlInstance.gql`
|
|
252
255
|
query getRecords($id: String!) {
|
|
253
256
|
domain(id: $id) {
|
|
@@ -286,8 +289,12 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress)
|
|
|
286
289
|
const id = (0, import_normalise.namehash)(name);
|
|
287
290
|
let domain;
|
|
288
291
|
let resolverResponse;
|
|
292
|
+
let graphErrors;
|
|
289
293
|
if (!resolverAddress) {
|
|
290
|
-
const response = await client.request(query, { id })
|
|
294
|
+
const response = await client.request(query, { id }).catch((e) => {
|
|
295
|
+
graphErrors = (0, import_errors.getClientErrors)(e);
|
|
296
|
+
return void 0;
|
|
297
|
+
}).finally(import_errors.debugSubgraphLatency);
|
|
291
298
|
domain = response == null ? void 0 : response.domain;
|
|
292
299
|
resolverResponse = domain == null ? void 0 : domain.resolver;
|
|
293
300
|
} else {
|
|
@@ -295,16 +302,22 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress)
|
|
|
295
302
|
const response = await client.request(customResolverQuery, {
|
|
296
303
|
id,
|
|
297
304
|
resolverId
|
|
298
|
-
})
|
|
305
|
+
}).catch((e) => {
|
|
306
|
+
graphErrors = (0, import_errors.getClientErrors)(e);
|
|
307
|
+
return void 0;
|
|
308
|
+
}).finally(import_errors.debugSubgraphLatency);
|
|
299
309
|
resolverResponse = response == null ? void 0 : response.resolver;
|
|
300
310
|
domain = response == null ? void 0 : response.domain;
|
|
301
311
|
}
|
|
302
312
|
if (!domain)
|
|
303
|
-
return;
|
|
313
|
+
return { errors: graphErrors };
|
|
304
314
|
const { isMigrated, createdAt, name: decryptedName } = domain;
|
|
305
315
|
const returnedRecords = {};
|
|
306
316
|
if (!resolverResponse || !wantedRecords)
|
|
307
|
-
return {
|
|
317
|
+
return {
|
|
318
|
+
errors: graphErrors,
|
|
319
|
+
result: { isMigrated, createdAt, decryptedName }
|
|
320
|
+
};
|
|
308
321
|
Object.keys(wantedRecords).forEach((key) => {
|
|
309
322
|
const data = wantedRecords[key];
|
|
310
323
|
if (typeof data === "boolean" && data) {
|
|
@@ -316,10 +329,13 @@ const graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress)
|
|
|
316
329
|
}
|
|
317
330
|
});
|
|
318
331
|
return {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
332
|
+
errors: graphErrors,
|
|
333
|
+
result: {
|
|
334
|
+
...returnedRecords,
|
|
335
|
+
decryptedName,
|
|
336
|
+
isMigrated,
|
|
337
|
+
createdAt
|
|
338
|
+
}
|
|
323
339
|
};
|
|
324
340
|
};
|
|
325
341
|
const getProfileFromName = async ({
|
|
@@ -331,7 +347,7 @@ const getProfileFromName = async ({
|
|
|
331
347
|
resolverMulticallWrapper,
|
|
332
348
|
multicallWrapper
|
|
333
349
|
}, name, options) => {
|
|
334
|
-
const { resolverAddress, fallback, ..._options } = options || {};
|
|
350
|
+
const { resolverAddress, fallback, skipGraph, ..._options } = options || {};
|
|
335
351
|
const optsLength = Object.keys(_options).length;
|
|
336
352
|
let usingOptions;
|
|
337
353
|
if (!optsLength || (_options == null ? void 0 : _options.texts) === true || (_options == null ? void 0 : _options.coinTypes) === true) {
|
|
@@ -340,11 +356,12 @@ const getProfileFromName = async ({
|
|
|
340
356
|
else
|
|
341
357
|
usingOptions = { contentHash: true, texts: true, coinTypes: true };
|
|
342
358
|
}
|
|
343
|
-
const graphResult = await graphFetch(
|
|
359
|
+
const { errors, result: graphResult } = await graphFetch(
|
|
344
360
|
{ gqlInstance },
|
|
345
361
|
name,
|
|
346
362
|
usingOptions,
|
|
347
|
-
resolverAddress
|
|
363
|
+
resolverAddress,
|
|
364
|
+
!!skipGraph
|
|
348
365
|
);
|
|
349
366
|
let isMigrated = null;
|
|
350
367
|
let createdAt = null;
|
|
@@ -352,7 +369,7 @@ const getProfileFromName = async ({
|
|
|
352
369
|
let result = null;
|
|
353
370
|
if (!graphResult) {
|
|
354
371
|
if (!fallback)
|
|
355
|
-
return;
|
|
372
|
+
return { errors };
|
|
356
373
|
result = await getDataForName(
|
|
357
374
|
{
|
|
358
375
|
contracts,
|
|
@@ -396,11 +413,23 @@ const getProfileFromName = async ({
|
|
|
396
413
|
}
|
|
397
414
|
if (!(result == null ? void 0 : result.resolverAddress))
|
|
398
415
|
return {
|
|
416
|
+
errors,
|
|
417
|
+
result: {
|
|
418
|
+
isMigrated,
|
|
419
|
+
createdAt,
|
|
420
|
+
message: !result ? "Records fetch didn't complete" : "Name doesn't have a resolver"
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
return {
|
|
424
|
+
errors,
|
|
425
|
+
result: {
|
|
426
|
+
...result,
|
|
399
427
|
isMigrated,
|
|
400
428
|
createdAt,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
429
|
+
decryptedName,
|
|
430
|
+
message: void 0
|
|
431
|
+
}
|
|
432
|
+
};
|
|
404
433
|
};
|
|
405
434
|
const getProfileFromAddress = async ({
|
|
406
435
|
contracts,
|
|
@@ -416,13 +445,15 @@ const getProfileFromAddress = async ({
|
|
|
416
445
|
try {
|
|
417
446
|
name = await getName(address);
|
|
418
447
|
} catch (e) {
|
|
419
|
-
return;
|
|
448
|
+
return {};
|
|
420
449
|
}
|
|
421
450
|
if (!name || !name.name || name.name === "")
|
|
422
|
-
return;
|
|
451
|
+
return {};
|
|
423
452
|
if (!name.match)
|
|
424
|
-
return {
|
|
425
|
-
|
|
453
|
+
return {
|
|
454
|
+
result: { ...name, isMigrated: null, createdAt: null }
|
|
455
|
+
};
|
|
456
|
+
const { errors, result } = await getProfileFromName(
|
|
426
457
|
{
|
|
427
458
|
contracts,
|
|
428
459
|
gqlInstance,
|
|
@@ -436,12 +467,15 @@ const getProfileFromAddress = async ({
|
|
|
436
467
|
options
|
|
437
468
|
);
|
|
438
469
|
if (!result || result.message)
|
|
439
|
-
return;
|
|
470
|
+
return { errors };
|
|
440
471
|
delete result.address;
|
|
441
472
|
return {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
473
|
+
errors,
|
|
474
|
+
result: {
|
|
475
|
+
...result,
|
|
476
|
+
...name,
|
|
477
|
+
message: void 0
|
|
478
|
+
}
|
|
445
479
|
};
|
|
446
480
|
};
|
|
447
481
|
const mapCoinTypes = (coin) => {
|
|
@@ -470,7 +504,7 @@ async function getProfile_default({
|
|
|
470
504
|
}
|
|
471
505
|
const inputIsAddress = (0, import_address.isAddress)(nameOrAddress);
|
|
472
506
|
if (inputIsAddress) {
|
|
473
|
-
|
|
507
|
+
const { errors: errors2, result: result2 } = await getProfileFromAddress(
|
|
474
508
|
{
|
|
475
509
|
contracts,
|
|
476
510
|
gqlInstance,
|
|
@@ -484,8 +518,11 @@ async function getProfile_default({
|
|
|
484
518
|
nameOrAddress,
|
|
485
519
|
options
|
|
486
520
|
);
|
|
521
|
+
if (errors2)
|
|
522
|
+
throw new import_errors.ENSJSError({ data: result2, errors: errors2 });
|
|
523
|
+
return result2;
|
|
487
524
|
}
|
|
488
|
-
|
|
525
|
+
const { errors, result } = await getProfileFromName(
|
|
489
526
|
{
|
|
490
527
|
contracts,
|
|
491
528
|
gqlInstance,
|
|
@@ -498,4 +535,7 @@ async function getProfile_default({
|
|
|
498
535
|
nameOrAddress,
|
|
499
536
|
options
|
|
500
537
|
);
|
|
538
|
+
if (errors)
|
|
539
|
+
throw new import_errors.ENSJSError({ data: result, errors });
|
|
540
|
+
return result;
|
|
501
541
|
}
|
|
@@ -21,6 +21,7 @@ __export(getSubnames_exports, {
|
|
|
21
21
|
default: () => getSubnames_default
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(getSubnames_exports);
|
|
24
|
+
var import_errors = require("../utils/errors");
|
|
24
25
|
var import_format = require("../utils/format");
|
|
25
26
|
var import_fuses = require("../utils/fuses");
|
|
26
27
|
var import_labels = require("../utils/labels");
|
|
@@ -98,7 +99,15 @@ const largeQuery = async ({ gqlInstance }, {
|
|
|
98
99
|
orderDirection,
|
|
99
100
|
search: search == null ? void 0 : search.toLowerCase()
|
|
100
101
|
};
|
|
101
|
-
const response = await client.request(finalQuery, queryVars)
|
|
102
|
+
const response = await client.request(finalQuery, queryVars).catch((e) => {
|
|
103
|
+
throw new import_errors.ENSJSError({
|
|
104
|
+
data: {
|
|
105
|
+
subnames: [],
|
|
106
|
+
subnameCount: 0
|
|
107
|
+
},
|
|
108
|
+
errors: (0, import_errors.getClientErrors)(e)
|
|
109
|
+
});
|
|
110
|
+
}).finally(import_errors.debugSubgraphLatency);
|
|
102
111
|
const domain = response == null ? void 0 : response.domain;
|
|
103
112
|
const subdomains = domain.subdomains.map(
|
|
104
113
|
({ wrappedDomain, ...subname }) => {
|
|
@@ -29,7 +29,7 @@ async function supportsTLD_default({ getOwner, provider }, name) {
|
|
|
29
29
|
const tld = labels[labels.length - 1];
|
|
30
30
|
if (tld === "eth")
|
|
31
31
|
return true;
|
|
32
|
-
const tldOwner = await getOwner(tld, "registry");
|
|
32
|
+
const tldOwner = await getOwner(tld, { contract: "registry" });
|
|
33
33
|
if (!(tldOwner == null ? void 0 : tldOwner.owner))
|
|
34
34
|
return false;
|
|
35
35
|
const dnsRegistrar = import_DNSRegistrar_factory.DNSRegistrar__factory.connect(
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
ENSJSError: () => ENSJSError,
|
|
22
|
+
debugSubgraphError: () => debugSubgraphError,
|
|
23
|
+
debugSubgraphLatency: () => debugSubgraphLatency,
|
|
24
|
+
getClientErrors: () => getClientErrors
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(errors_exports);
|
|
27
|
+
var import_graphql_request = require("graphql-request");
|
|
28
|
+
var import_graphql = require("graphql");
|
|
29
|
+
class ENSJSError extends Error {
|
|
30
|
+
constructor({ data, errors }) {
|
|
31
|
+
super();
|
|
32
|
+
this.name = "ENSJSSubgraphError";
|
|
33
|
+
this.data = data;
|
|
34
|
+
this.errors = errors;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const getClientErrors = (e) => {
|
|
38
|
+
var _a;
|
|
39
|
+
const error = e instanceof import_graphql_request.ClientError ? e : void 0;
|
|
40
|
+
return ((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.errors) || [new import_graphql.GraphQLError("unknown_error")];
|
|
41
|
+
};
|
|
42
|
+
const isDebugEnvironmentActive = () => {
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
const debugSubgraphError = (request) => {
|
|
46
|
+
if (isDebugEnvironmentActive() && typeof localStorage !== "undefined" && localStorage.getItem("ensjs-debug") === "ENSJSSubgraphError") {
|
|
47
|
+
if (localStorage.getItem("subgraph-debug") === "ENSJSSubgraphIndexingError" && /_meta {/.test(request.body))
|
|
48
|
+
return;
|
|
49
|
+
throw new import_graphql_request.ClientError(
|
|
50
|
+
{
|
|
51
|
+
data: void 0,
|
|
52
|
+
errors: [new import_graphql.GraphQLError("ensjs-debug")],
|
|
53
|
+
status: 200
|
|
54
|
+
},
|
|
55
|
+
request
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const debugSubgraphLatency = () => {
|
|
60
|
+
if (isDebugEnvironmentActive() && typeof localStorage !== "undefined" && localStorage.getItem("ensjs-debug") === "ENSJSSubgraphLatency") {
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
resolve();
|
|
64
|
+
}, 1e4);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
package/dist/esm/GqlManager.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/GqlManager.ts
|
|
2
|
+
import { debugSubgraphError } from "./utils/errors.mjs";
|
|
2
3
|
import { namehash } from "./utils/normalise.mjs";
|
|
3
4
|
var generateSelection = (selection) => ({
|
|
4
5
|
kind: "Field",
|
|
@@ -28,6 +29,7 @@ var enter = (node) => {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
var requestMiddleware = (visit, parse, print) => (request) => {
|
|
32
|
+
debugSubgraphError(request);
|
|
31
33
|
const requestBody = JSON.parse(request.body);
|
|
32
34
|
const rawQuery = requestBody.query;
|
|
33
35
|
const parsedQuery = parse(rawQuery);
|
|
@@ -42,6 +44,8 @@ var requestMiddleware = (visit, parse, print) => (request) => {
|
|
|
42
44
|
};
|
|
43
45
|
};
|
|
44
46
|
var responseMiddleware = (traverse) => (response) => {
|
|
47
|
+
if (response instanceof Error)
|
|
48
|
+
return response;
|
|
45
49
|
traverse(response).forEach(function(responseItem) {
|
|
46
50
|
if (responseItem instanceof Object && responseItem.name) {
|
|
47
51
|
if (responseItem.name && responseItem.name.includes("[")) {
|
|
@@ -34,8 +34,8 @@ var addresses = {
|
|
|
34
34
|
"5": "0x56522d00c410a43bffdf00a9a569489297385790"
|
|
35
35
|
},
|
|
36
36
|
BulkRenewal: {
|
|
37
|
-
"1": "
|
|
38
|
-
"5": "
|
|
37
|
+
"1": "0xa12159e5131b1eEf6B4857EEE3e1954744b5033A",
|
|
38
|
+
"5": "0xeA64C81d0d718620daBC02D61f3B255C641f475F"
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
var getContractAddress = (networkId) => (contractName) => {
|