@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/functions/batch.ts
|
|
2
|
+
import { ENSJSError } from "../utils/errors.mjs";
|
|
2
3
|
var raw = async ({ multicallWrapper }, ...items) => {
|
|
3
4
|
const rawDataArr = await Promise.all(
|
|
4
5
|
items.map(({ args, raw: rawRef }, i) => {
|
|
@@ -15,7 +16,7 @@ var decode = async ({ multicallWrapper }, data, passthrough, ...items) => {
|
|
|
15
16
|
const response = await multicallWrapper.decode(data, passthrough);
|
|
16
17
|
if (!response)
|
|
17
18
|
return;
|
|
18
|
-
|
|
19
|
+
const results = await Promise.allSettled(
|
|
19
20
|
response.map((ret, i) => {
|
|
20
21
|
if (passthrough[i].passthrough) {
|
|
21
22
|
return items[i].decode(
|
|
@@ -27,6 +28,27 @@ var decode = async ({ multicallWrapper }, data, passthrough, ...items) => {
|
|
|
27
28
|
return items[i].decode(ret.returnData, ...items[i].args);
|
|
28
29
|
})
|
|
29
30
|
);
|
|
31
|
+
const reducedResults = results.reduce(
|
|
32
|
+
(acc, result) => {
|
|
33
|
+
if (result.status === "fulfilled") {
|
|
34
|
+
return { ...acc, data: [...acc.data, result.value] };
|
|
35
|
+
}
|
|
36
|
+
const error = result.reason instanceof ENSJSError ? result.reason : void 0;
|
|
37
|
+
const itemData = error?.data;
|
|
38
|
+
const itemErrors = error?.errors || [{ message: "unknown_error" }];
|
|
39
|
+
return {
|
|
40
|
+
errors: [...acc.errors, ...itemErrors],
|
|
41
|
+
data: [...acc.data, itemData]
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
{ data: [], errors: [] }
|
|
45
|
+
);
|
|
46
|
+
if (reducedResults.errors.length)
|
|
47
|
+
throw new ENSJSError({
|
|
48
|
+
data: reducedResults.data,
|
|
49
|
+
errors: reducedResults.errors
|
|
50
|
+
});
|
|
51
|
+
return reducedResults.data;
|
|
30
52
|
};
|
|
31
53
|
var batch_default = {
|
|
32
54
|
raw,
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
import { formatsByCoinType } from "@ensdomains/address-encoder";
|
|
3
3
|
import { hexStripZeros } from "@ethersproject/bytes";
|
|
4
4
|
import { decodeContenthash } from "../utils/contentHash.mjs";
|
|
5
|
+
import {
|
|
6
|
+
debugSubgraphLatency,
|
|
7
|
+
ENSJSError,
|
|
8
|
+
getClientErrors
|
|
9
|
+
} from "../utils/errors.mjs";
|
|
5
10
|
import { namehash } from "../utils/normalise.mjs";
|
|
6
11
|
import { checkIsDotEth } from "../utils/validation.mjs";
|
|
7
12
|
var eventFormat = {
|
|
@@ -209,14 +214,16 @@ async function getHistory({ gqlInstance }, name) {
|
|
|
209
214
|
const is2ldEth = checkIsDotEth(labels);
|
|
210
215
|
const response = await client.request(query, {
|
|
211
216
|
namehash: nameHash
|
|
212
|
-
})
|
|
217
|
+
}).catch((e) => {
|
|
218
|
+
throw new ENSJSError({
|
|
219
|
+
errors: getClientErrors(e)
|
|
220
|
+
});
|
|
221
|
+
}).finally(debugSubgraphLatency);
|
|
213
222
|
const domain = response?.domain;
|
|
214
223
|
if (!domain)
|
|
215
|
-
return;
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
resolver: { events: resolverEvents }
|
|
219
|
-
} = domain;
|
|
224
|
+
return void 0;
|
|
225
|
+
const domainEvents = domain.events || [];
|
|
226
|
+
const resolverEvents = domain.resolver?.events || [];
|
|
220
227
|
const domainHistory = mapEvents(domainEvents, "Domain");
|
|
221
228
|
const resolverHistory = mapEvents(
|
|
222
229
|
resolverEvents.filter(
|
|
@@ -225,9 +232,7 @@ async function getHistory({ gqlInstance }, name) {
|
|
|
225
232
|
"Resolver"
|
|
226
233
|
);
|
|
227
234
|
if (is2ldEth) {
|
|
228
|
-
const
|
|
229
|
-
registration: { events: registrationEvents }
|
|
230
|
-
} = domain;
|
|
235
|
+
const registrationEvents = domain.registration?.events || [];
|
|
231
236
|
const registrationHistory = mapEvents(registrationEvents, "Registration");
|
|
232
237
|
return {
|
|
233
238
|
domain: domainHistory,
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// src/functions/getNames.ts
|
|
2
|
+
import {
|
|
3
|
+
getClientErrors,
|
|
4
|
+
ENSJSError,
|
|
5
|
+
debugSubgraphLatency
|
|
6
|
+
} from "../utils/errors.mjs";
|
|
2
7
|
import { truncateFormat } from "../utils/format.mjs";
|
|
3
8
|
import { checkPCCBurned, decodeFuses } from "../utils/fuses.mjs";
|
|
4
9
|
import { decryptName } from "../utils/labels.mjs";
|
|
@@ -361,10 +366,16 @@ var getNames = async ({ gqlInstance }, {
|
|
|
361
366
|
expiryDate: Math.floor(Date.now() / 1e3) - 90 * 24 * 60 * 60
|
|
362
367
|
};
|
|
363
368
|
}
|
|
364
|
-
const response = await client.request(finalQuery, queryVars)
|
|
369
|
+
const response = await client.request(finalQuery, queryVars).catch((e) => {
|
|
370
|
+
console.error(e);
|
|
371
|
+
throw new ENSJSError({
|
|
372
|
+
errors: getClientErrors(e),
|
|
373
|
+
data: []
|
|
374
|
+
});
|
|
375
|
+
}).finally(debugSubgraphLatency);
|
|
365
376
|
const account = response?.account;
|
|
366
377
|
if (type === "all") {
|
|
367
|
-
|
|
378
|
+
const data = [
|
|
368
379
|
...account?.domains.map(mapDomain) || [],
|
|
369
380
|
...account?.registrations.map(mapRegistration) || [],
|
|
370
381
|
...account?.wrappedDomains.map(mapWrappedDomain).filter((d) => d) || []
|
|
@@ -380,6 +391,7 @@ var getNames = async ({ gqlInstance }, {
|
|
|
380
391
|
}
|
|
381
392
|
return a.createdAt.getTime() - b.createdAt.getTime();
|
|
382
393
|
});
|
|
394
|
+
return data;
|
|
383
395
|
}
|
|
384
396
|
if (type === "resolvedAddress") {
|
|
385
397
|
return response?.domains.map(mapResolvedAddress).filter((d) => d) || [];
|
|
@@ -4,6 +4,11 @@ import { hexStripZeros } from "@ethersproject/bytes";
|
|
|
4
4
|
import { labelhash } from "../utils/labels.mjs";
|
|
5
5
|
import { namehash as makeNamehash } from "../utils/normalise.mjs";
|
|
6
6
|
import { checkIsDotEth } from "../utils/validation.mjs";
|
|
7
|
+
import {
|
|
8
|
+
debugSubgraphLatency,
|
|
9
|
+
getClientErrors,
|
|
10
|
+
ENSJSError
|
|
11
|
+
} from "../utils/errors.mjs";
|
|
7
12
|
var singleContractOwnerRaw = async ({ contracts }, contract, namehash, labels) => {
|
|
8
13
|
switch (contract) {
|
|
9
14
|
case "nameWrapper": {
|
|
@@ -31,7 +36,8 @@ var singleContractOwnerRaw = async ({ contracts }, contract, namehash, labels) =
|
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
};
|
|
34
|
-
var raw = async ({ contracts, multicallWrapper }, name,
|
|
39
|
+
var raw = async ({ contracts, multicallWrapper }, name, options = {}) => {
|
|
40
|
+
const { contract } = options;
|
|
35
41
|
const namehash = makeNamehash(name);
|
|
36
42
|
const labels = name.split(".");
|
|
37
43
|
if (contract || labels.length === 1) {
|
|
@@ -82,10 +88,13 @@ var decode = async ({
|
|
|
82
88
|
contracts,
|
|
83
89
|
multicallWrapper,
|
|
84
90
|
gqlInstance
|
|
85
|
-
}, data, name,
|
|
91
|
+
}, data, name, options = {}) => {
|
|
86
92
|
if (!data)
|
|
87
93
|
return;
|
|
94
|
+
const { contract, skipGraph = true } = options;
|
|
88
95
|
const labels = name.split(".");
|
|
96
|
+
const isEth = labels[labels.length - 1] === "eth";
|
|
97
|
+
const is2LD = labels.length === 2;
|
|
89
98
|
if (contract || labels.length === 1) {
|
|
90
99
|
const singleOwner = singleContractOwnerDecode(data);
|
|
91
100
|
const obj = {
|
|
@@ -113,48 +122,85 @@ var decode = async ({
|
|
|
113
122
|
const nameWrapperOwner = decodedData[1][0];
|
|
114
123
|
let registrarOwner = decodedData[2]?.[0];
|
|
115
124
|
let baseReturnObject = {};
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
if (isEth) {
|
|
126
|
+
let graphErrors;
|
|
127
|
+
if (is2LD) {
|
|
128
|
+
if (!registrarOwner && !skipGraph) {
|
|
129
|
+
const graphRegistrantResult = await gqlInstance.client.request(registrantQuery, {
|
|
130
|
+
namehash: makeNamehash(name)
|
|
131
|
+
}).catch((e) => {
|
|
132
|
+
console.error(e);
|
|
133
|
+
graphErrors = getClientErrors(e);
|
|
134
|
+
return void 0;
|
|
135
|
+
}).finally(debugSubgraphLatency);
|
|
136
|
+
registrarOwner = graphRegistrantResult?.domain?.registration?.registrant?.id;
|
|
126
137
|
baseReturnObject = {
|
|
127
138
|
expired: true
|
|
128
139
|
};
|
|
129
140
|
} else {
|
|
130
141
|
baseReturnObject = {
|
|
131
|
-
expired:
|
|
142
|
+
expired: !registrarOwner
|
|
132
143
|
};
|
|
133
144
|
}
|
|
134
145
|
}
|
|
146
|
+
if (baseReturnObject.expired && registryOwner?.toLowerCase() === nameWrapper.address.toLowerCase()) {
|
|
147
|
+
const owner = {
|
|
148
|
+
owner: nameWrapperOwner,
|
|
149
|
+
ownershipLevel: "nameWrapper",
|
|
150
|
+
...baseReturnObject
|
|
151
|
+
};
|
|
152
|
+
if (graphErrors) {
|
|
153
|
+
throw new ENSJSError({
|
|
154
|
+
data: owner,
|
|
155
|
+
errors: graphErrors
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return owner;
|
|
159
|
+
}
|
|
135
160
|
if (registrarOwner?.toLowerCase() === nameWrapper.address.toLowerCase()) {
|
|
136
|
-
|
|
161
|
+
const owner = {
|
|
137
162
|
owner: nameWrapperOwner,
|
|
138
163
|
ownershipLevel: "nameWrapper",
|
|
139
164
|
...baseReturnObject
|
|
140
165
|
};
|
|
166
|
+
if (graphErrors) {
|
|
167
|
+
throw new ENSJSError({
|
|
168
|
+
data: owner,
|
|
169
|
+
errors: graphErrors
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return owner;
|
|
141
173
|
}
|
|
142
174
|
if (registrarOwner) {
|
|
143
|
-
|
|
175
|
+
const owner = {
|
|
144
176
|
registrant: registrarOwner,
|
|
145
177
|
owner: registryOwner,
|
|
146
178
|
ownershipLevel: "registrar",
|
|
147
179
|
...baseReturnObject
|
|
148
180
|
};
|
|
181
|
+
if (graphErrors) {
|
|
182
|
+
throw new ENSJSError({
|
|
183
|
+
data: owner,
|
|
184
|
+
errors: graphErrors
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return owner;
|
|
149
188
|
}
|
|
150
189
|
if (hexStripZeros(registryOwner) !== "0x") {
|
|
151
190
|
if (labels.length === 2) {
|
|
152
|
-
|
|
191
|
+
const owner = {
|
|
153
192
|
registrant: void 0,
|
|
154
193
|
owner: registryOwner,
|
|
155
194
|
ownershipLevel: "registrar",
|
|
156
195
|
expired: true
|
|
157
196
|
};
|
|
197
|
+
if (graphErrors) {
|
|
198
|
+
throw new ENSJSError({
|
|
199
|
+
data: owner,
|
|
200
|
+
errors: graphErrors
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return owner;
|
|
158
204
|
}
|
|
159
205
|
if (registryOwner === nameWrapper.address && nameWrapperOwner && hexStripZeros(nameWrapperOwner) !== "0x") {
|
|
160
206
|
return {
|
|
@@ -167,7 +213,12 @@ var decode = async ({
|
|
|
167
213
|
ownershipLevel: "registry"
|
|
168
214
|
};
|
|
169
215
|
}
|
|
170
|
-
|
|
216
|
+
if (graphErrors) {
|
|
217
|
+
throw new ENSJSError({
|
|
218
|
+
errors: graphErrors
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return void 0;
|
|
171
222
|
}
|
|
172
223
|
if (registryOwner === nameWrapper.address && nameWrapperOwner && hexStripZeros(nameWrapperOwner) !== "0x") {
|
|
173
224
|
return {
|
|
@@ -6,6 +6,11 @@ import { hexStripZeros, isBytesLike } from "@ethersproject/bytes";
|
|
|
6
6
|
import { decodeContenthash } from "../utils/contentHash.mjs";
|
|
7
7
|
import { hexEncodeName } from "../utils/hexEncodedName.mjs";
|
|
8
8
|
import { namehash } from "../utils/normalise.mjs";
|
|
9
|
+
import {
|
|
10
|
+
ENSJSError,
|
|
11
|
+
debugSubgraphLatency,
|
|
12
|
+
getClientErrors
|
|
13
|
+
} from "../utils/errors.mjs";
|
|
9
14
|
var makeMulticallData = async ({
|
|
10
15
|
_getAddr,
|
|
11
16
|
_getContentHash,
|
|
@@ -225,7 +230,9 @@ var getDataForName = async ({
|
|
|
225
230
|
resolverAddress
|
|
226
231
|
};
|
|
227
232
|
};
|
|
228
|
-
var graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress) => {
|
|
233
|
+
var graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress, skipGraph = true) => {
|
|
234
|
+
if (skipGraph)
|
|
235
|
+
return { status: void 0, result: void 0 };
|
|
229
236
|
const query = gqlInstance.gql`
|
|
230
237
|
query getRecords($id: String!) {
|
|
231
238
|
domain(id: $id) {
|
|
@@ -264,8 +271,12 @@ var graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress) =
|
|
|
264
271
|
const id = namehash(name);
|
|
265
272
|
let domain;
|
|
266
273
|
let resolverResponse;
|
|
274
|
+
let graphErrors;
|
|
267
275
|
if (!resolverAddress) {
|
|
268
|
-
const response = await client.request(query, { id })
|
|
276
|
+
const response = await client.request(query, { id }).catch((e) => {
|
|
277
|
+
graphErrors = getClientErrors(e);
|
|
278
|
+
return void 0;
|
|
279
|
+
}).finally(debugSubgraphLatency);
|
|
269
280
|
domain = response?.domain;
|
|
270
281
|
resolverResponse = domain?.resolver;
|
|
271
282
|
} else {
|
|
@@ -273,16 +284,22 @@ var graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress) =
|
|
|
273
284
|
const response = await client.request(customResolverQuery, {
|
|
274
285
|
id,
|
|
275
286
|
resolverId
|
|
276
|
-
})
|
|
287
|
+
}).catch((e) => {
|
|
288
|
+
graphErrors = getClientErrors(e);
|
|
289
|
+
return void 0;
|
|
290
|
+
}).finally(debugSubgraphLatency);
|
|
277
291
|
resolverResponse = response?.resolver;
|
|
278
292
|
domain = response?.domain;
|
|
279
293
|
}
|
|
280
294
|
if (!domain)
|
|
281
|
-
return;
|
|
295
|
+
return { errors: graphErrors };
|
|
282
296
|
const { isMigrated, createdAt, name: decryptedName } = domain;
|
|
283
297
|
const returnedRecords = {};
|
|
284
298
|
if (!resolverResponse || !wantedRecords)
|
|
285
|
-
return {
|
|
299
|
+
return {
|
|
300
|
+
errors: graphErrors,
|
|
301
|
+
result: { isMigrated, createdAt, decryptedName }
|
|
302
|
+
};
|
|
286
303
|
Object.keys(wantedRecords).forEach((key) => {
|
|
287
304
|
const data = wantedRecords[key];
|
|
288
305
|
if (typeof data === "boolean" && data) {
|
|
@@ -294,10 +311,13 @@ var graphFetch = async ({ gqlInstance }, name, wantedRecords, resolverAddress) =
|
|
|
294
311
|
}
|
|
295
312
|
});
|
|
296
313
|
return {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
314
|
+
errors: graphErrors,
|
|
315
|
+
result: {
|
|
316
|
+
...returnedRecords,
|
|
317
|
+
decryptedName,
|
|
318
|
+
isMigrated,
|
|
319
|
+
createdAt
|
|
320
|
+
}
|
|
301
321
|
};
|
|
302
322
|
};
|
|
303
323
|
var getProfileFromName = async ({
|
|
@@ -309,7 +329,7 @@ var getProfileFromName = async ({
|
|
|
309
329
|
resolverMulticallWrapper,
|
|
310
330
|
multicallWrapper
|
|
311
331
|
}, name, options) => {
|
|
312
|
-
const { resolverAddress, fallback, ..._options } = options || {};
|
|
332
|
+
const { resolverAddress, fallback, skipGraph, ..._options } = options || {};
|
|
313
333
|
const optsLength = Object.keys(_options).length;
|
|
314
334
|
let usingOptions;
|
|
315
335
|
if (!optsLength || _options?.texts === true || _options?.coinTypes === true) {
|
|
@@ -318,11 +338,12 @@ var getProfileFromName = async ({
|
|
|
318
338
|
else
|
|
319
339
|
usingOptions = { contentHash: true, texts: true, coinTypes: true };
|
|
320
340
|
}
|
|
321
|
-
const graphResult = await graphFetch(
|
|
341
|
+
const { errors, result: graphResult } = await graphFetch(
|
|
322
342
|
{ gqlInstance },
|
|
323
343
|
name,
|
|
324
344
|
usingOptions,
|
|
325
|
-
resolverAddress
|
|
345
|
+
resolverAddress,
|
|
346
|
+
!!skipGraph
|
|
326
347
|
);
|
|
327
348
|
let isMigrated = null;
|
|
328
349
|
let createdAt = null;
|
|
@@ -330,7 +351,7 @@ var getProfileFromName = async ({
|
|
|
330
351
|
let result = null;
|
|
331
352
|
if (!graphResult) {
|
|
332
353
|
if (!fallback)
|
|
333
|
-
return;
|
|
354
|
+
return { errors };
|
|
334
355
|
result = await getDataForName(
|
|
335
356
|
{
|
|
336
357
|
contracts,
|
|
@@ -374,11 +395,23 @@ var getProfileFromName = async ({
|
|
|
374
395
|
}
|
|
375
396
|
if (!result?.resolverAddress)
|
|
376
397
|
return {
|
|
398
|
+
errors,
|
|
399
|
+
result: {
|
|
400
|
+
isMigrated,
|
|
401
|
+
createdAt,
|
|
402
|
+
message: !result ? "Records fetch didn't complete" : "Name doesn't have a resolver"
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
return {
|
|
406
|
+
errors,
|
|
407
|
+
result: {
|
|
408
|
+
...result,
|
|
377
409
|
isMigrated,
|
|
378
410
|
createdAt,
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
411
|
+
decryptedName,
|
|
412
|
+
message: void 0
|
|
413
|
+
}
|
|
414
|
+
};
|
|
382
415
|
};
|
|
383
416
|
var getProfileFromAddress = async ({
|
|
384
417
|
contracts,
|
|
@@ -394,13 +427,15 @@ var getProfileFromAddress = async ({
|
|
|
394
427
|
try {
|
|
395
428
|
name = await getName(address);
|
|
396
429
|
} catch (e) {
|
|
397
|
-
return;
|
|
430
|
+
return {};
|
|
398
431
|
}
|
|
399
432
|
if (!name || !name.name || name.name === "")
|
|
400
|
-
return;
|
|
433
|
+
return {};
|
|
401
434
|
if (!name.match)
|
|
402
|
-
return {
|
|
403
|
-
|
|
435
|
+
return {
|
|
436
|
+
result: { ...name, isMigrated: null, createdAt: null }
|
|
437
|
+
};
|
|
438
|
+
const { errors, result } = await getProfileFromName(
|
|
404
439
|
{
|
|
405
440
|
contracts,
|
|
406
441
|
gqlInstance,
|
|
@@ -414,12 +449,15 @@ var getProfileFromAddress = async ({
|
|
|
414
449
|
options
|
|
415
450
|
);
|
|
416
451
|
if (!result || result.message)
|
|
417
|
-
return;
|
|
452
|
+
return { errors };
|
|
418
453
|
delete result.address;
|
|
419
454
|
return {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
455
|
+
errors,
|
|
456
|
+
result: {
|
|
457
|
+
...result,
|
|
458
|
+
...name,
|
|
459
|
+
message: void 0
|
|
460
|
+
}
|
|
423
461
|
};
|
|
424
462
|
};
|
|
425
463
|
var mapCoinTypes = (coin) => {
|
|
@@ -448,7 +486,7 @@ async function getProfile_default({
|
|
|
448
486
|
}
|
|
449
487
|
const inputIsAddress = isAddress(nameOrAddress);
|
|
450
488
|
if (inputIsAddress) {
|
|
451
|
-
|
|
489
|
+
const { errors: errors2, result: result2 } = await getProfileFromAddress(
|
|
452
490
|
{
|
|
453
491
|
contracts,
|
|
454
492
|
gqlInstance,
|
|
@@ -462,8 +500,11 @@ async function getProfile_default({
|
|
|
462
500
|
nameOrAddress,
|
|
463
501
|
options
|
|
464
502
|
);
|
|
503
|
+
if (errors2)
|
|
504
|
+
throw new ENSJSError({ data: result2, errors: errors2 });
|
|
505
|
+
return result2;
|
|
465
506
|
}
|
|
466
|
-
|
|
507
|
+
const { errors, result } = await getProfileFromName(
|
|
467
508
|
{
|
|
468
509
|
contracts,
|
|
469
510
|
gqlInstance,
|
|
@@ -476,6 +517,9 @@ async function getProfile_default({
|
|
|
476
517
|
nameOrAddress,
|
|
477
518
|
options
|
|
478
519
|
);
|
|
520
|
+
if (errors)
|
|
521
|
+
throw new ENSJSError({ data: result, errors });
|
|
522
|
+
return result;
|
|
479
523
|
}
|
|
480
524
|
export {
|
|
481
525
|
getProfile_default as default
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
// src/functions/getSubnames.ts
|
|
2
|
+
import {
|
|
3
|
+
ENSJSError,
|
|
4
|
+
getClientErrors,
|
|
5
|
+
debugSubgraphLatency
|
|
6
|
+
} from "../utils/errors.mjs";
|
|
2
7
|
import { truncateFormat } from "../utils/format.mjs";
|
|
3
8
|
import { checkPCCBurned, decodeFuses } from "../utils/fuses.mjs";
|
|
4
9
|
import { decryptName } from "../utils/labels.mjs";
|
|
@@ -76,7 +81,15 @@ var largeQuery = async ({ gqlInstance }, {
|
|
|
76
81
|
orderDirection,
|
|
77
82
|
search: search?.toLowerCase()
|
|
78
83
|
};
|
|
79
|
-
const response = await client.request(finalQuery, queryVars)
|
|
84
|
+
const response = await client.request(finalQuery, queryVars).catch((e) => {
|
|
85
|
+
throw new ENSJSError({
|
|
86
|
+
data: {
|
|
87
|
+
subnames: [],
|
|
88
|
+
subnameCount: 0
|
|
89
|
+
},
|
|
90
|
+
errors: getClientErrors(e)
|
|
91
|
+
});
|
|
92
|
+
}).finally(debugSubgraphLatency);
|
|
80
93
|
const domain = response?.domain;
|
|
81
94
|
const subdomains = domain.subdomains.map(
|
|
82
95
|
({ wrappedDomain, ...subname }) => {
|
|
@@ -7,7 +7,7 @@ async function supportsTLD_default({ getOwner, provider }, name) {
|
|
|
7
7
|
const tld = labels[labels.length - 1];
|
|
8
8
|
if (tld === "eth")
|
|
9
9
|
return true;
|
|
10
|
-
const tldOwner = await getOwner(tld, "registry");
|
|
10
|
+
const tldOwner = await getOwner(tld, { contract: "registry" });
|
|
11
11
|
if (!tldOwner?.owner)
|
|
12
12
|
return false;
|
|
13
13
|
const dnsRegistrar = DNSRegistrar__factory.connect(
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/utils/errors.ts
|
|
2
|
+
import { ClientError } from "graphql-request";
|
|
3
|
+
import { GraphQLError } from "graphql";
|
|
4
|
+
var ENSJSError = class extends Error {
|
|
5
|
+
name = "ENSJSSubgraphError";
|
|
6
|
+
errors;
|
|
7
|
+
data;
|
|
8
|
+
constructor({ data, errors }) {
|
|
9
|
+
super();
|
|
10
|
+
this.data = data;
|
|
11
|
+
this.errors = errors;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var getClientErrors = (e) => {
|
|
15
|
+
const error = e instanceof ClientError ? e : void 0;
|
|
16
|
+
return error?.response?.errors || [new GraphQLError("unknown_error")];
|
|
17
|
+
};
|
|
18
|
+
var isDebugEnvironmentActive = () => {
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
var debugSubgraphError = (request) => {
|
|
22
|
+
if (isDebugEnvironmentActive() && typeof localStorage !== "undefined" && localStorage.getItem("ensjs-debug") === "ENSJSSubgraphError") {
|
|
23
|
+
if (localStorage.getItem("subgraph-debug") === "ENSJSSubgraphIndexingError" && /_meta {/.test(request.body))
|
|
24
|
+
return;
|
|
25
|
+
throw new ClientError(
|
|
26
|
+
{
|
|
27
|
+
data: void 0,
|
|
28
|
+
errors: [new GraphQLError("ensjs-debug")],
|
|
29
|
+
status: 200
|
|
30
|
+
},
|
|
31
|
+
request
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var debugSubgraphLatency = () => {
|
|
36
|
+
if (isDebugEnvironmentActive() && typeof localStorage !== "undefined" && localStorage.getItem("ensjs-debug") === "ENSJSSubgraphLatency") {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
resolve();
|
|
40
|
+
}, 1e4);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
ENSJSError,
|
|
46
|
+
debugSubgraphError,
|
|
47
|
+
debugSubgraphLatency,
|
|
48
|
+
getClientErrors
|
|
49
|
+
};
|
|
@@ -2,6 +2,25 @@ import { ENSArgs } from '..';
|
|
|
2
2
|
declare type DomainEvent = 'NewOwner' | 'NewResolver' | 'Transfer' | 'NewTTL' | 'WrappedTransfer' | 'NameWrapped' | 'NameUnwrapped' | 'FusesSet' | 'ExpiryExtended';
|
|
3
3
|
declare type RegistrationEvent = 'NameRegistered' | 'NameRenewed' | 'NameTransferred';
|
|
4
4
|
declare type ResolverEvent = 'AddrChanged' | 'MulticoinAddrChanged' | 'NameChanged' | 'AbiChanged' | 'PubkeyChanged' | 'TextChanged' | 'ContenthashChanged' | 'InterfaceChanged' | 'AuthorisationChanged' | 'VersionChanged';
|
|
5
|
+
declare type EventTypes = 'Domain' | 'Registration' | 'Resolver';
|
|
6
|
+
declare type EventFormat = {
|
|
7
|
+
Domain: DomainEvent;
|
|
8
|
+
Registration: RegistrationEvent;
|
|
9
|
+
Resolver: ResolverEvent;
|
|
10
|
+
};
|
|
11
|
+
declare const mapEvents: <T extends EventTypes>(eventArray: any[], type: T) => {
|
|
12
|
+
type: EventFormat[T];
|
|
13
|
+
blockNumber: number;
|
|
14
|
+
transactionHash: string;
|
|
15
|
+
id: string;
|
|
16
|
+
data: object;
|
|
17
|
+
}[];
|
|
18
|
+
declare type MappedEvents = ReturnType<typeof mapEvents>;
|
|
19
|
+
export declare type ReturnData = {
|
|
20
|
+
domain: MappedEvents;
|
|
21
|
+
registration?: MappedEvents;
|
|
22
|
+
resolver: MappedEvents;
|
|
23
|
+
};
|
|
5
24
|
export declare function getHistory({ gqlInstance }: ENSArgs<'gqlInstance'>, name: string): Promise<{
|
|
6
25
|
domain: {
|
|
7
26
|
type: DomainEvent;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { ENSArgs } from '..';
|
|
2
|
-
declare type Owner = {
|
|
2
|
+
export declare type Owner = {
|
|
3
3
|
registrant?: string;
|
|
4
4
|
owner?: string;
|
|
5
5
|
ownershipLevel: 'nameWrapper' | 'registry' | 'registrar';
|
|
6
6
|
expired?: boolean;
|
|
7
7
|
};
|
|
8
|
+
declare type GetOwnerOptions = {
|
|
9
|
+
contract?: 'nameWrapper' | 'registry' | 'registrar';
|
|
10
|
+
skipGraph?: boolean;
|
|
11
|
+
};
|
|
8
12
|
declare const _default: {
|
|
9
|
-
raw: ({ contracts, multicallWrapper }: ENSArgs<"contracts" | "multicallWrapper">, name: string,
|
|
13
|
+
raw: ({ contracts, multicallWrapper }: ENSArgs<"contracts" | "multicallWrapper">, name: string, options?: GetOwnerOptions) => Promise<{
|
|
10
14
|
to: string;
|
|
11
15
|
data: string;
|
|
12
16
|
}>;
|
|
13
|
-
decode: ({ contracts, multicallWrapper, gqlInstance, }: ENSArgs<"contracts" | "gqlInstance" | "multicallWrapper">, data: string, name: string,
|
|
17
|
+
decode: ({ contracts, multicallWrapper, gqlInstance, }: ENSArgs<"contracts" | "gqlInstance" | "multicallWrapper">, data: string, name: string, options?: GetOwnerOptions) => Promise<Owner | undefined>;
|
|
14
18
|
};
|
|
15
19
|
export default _default;
|
|
@@ -36,6 +36,7 @@ declare type ProfileOptions = {
|
|
|
36
36
|
declare type InputProfileOptions = ProfileOptions & {
|
|
37
37
|
resolverAddress?: string;
|
|
38
38
|
fallback?: FallbackRecords;
|
|
39
|
+
skipGraph?: boolean;
|
|
39
40
|
};
|
|
40
41
|
export default function ({ contracts, gqlInstance, getName, _getAddr, _getContentHash, _getText, resolverMulticallWrapper, multicallWrapper, }: ENSArgs<'contracts' | 'gqlInstance' | 'getName' | '_getText' | '_getAddr' | '_getContentHash' | 'resolverMulticallWrapper' | 'multicallWrapper'>, nameOrAddress: string, options?: InputProfileOptions): Promise<ResolvedProfile | undefined>;
|
|
41
42
|
export {};
|
|
@@ -22,6 +22,10 @@ declare type WrappedSubname = BaseSubname & {
|
|
|
22
22
|
type: 'wrappedDomain';
|
|
23
23
|
};
|
|
24
24
|
declare type Subname = WrappedSubname | UnwrappedSubname;
|
|
25
|
+
declare type ReturnData = {
|
|
26
|
+
subnames: Subname[];
|
|
27
|
+
subnameCount: number;
|
|
28
|
+
};
|
|
25
29
|
declare type Params = {
|
|
26
30
|
name: string;
|
|
27
31
|
page?: number;
|
|
@@ -31,8 +35,5 @@ declare type Params = {
|
|
|
31
35
|
lastSubnames?: Array<any>;
|
|
32
36
|
search?: string;
|
|
33
37
|
};
|
|
34
|
-
declare const getSubnames: (injected: ENSArgs<'gqlInstance'>, functionArgs: Params) => Promise<
|
|
35
|
-
subnames: Subname[];
|
|
36
|
-
subnameCount: number;
|
|
37
|
-
}>;
|
|
38
|
+
declare const getSubnames: (injected: ENSArgs<'gqlInstance'>, functionArgs: Params) => Promise<ReturnData>;
|
|
38
39
|
export default getSubnames;
|