@ensdomains/ensjs 3.0.0-alpha.62 → 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/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/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/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,9 @@
|
|
|
1
1
|
import { ENSArgs } from '..'
|
|
2
|
+
import {
|
|
3
|
+
ENSJSError,
|
|
4
|
+
getClientErrors,
|
|
5
|
+
debugSubgraphLatency,
|
|
6
|
+
} from '../utils/errors'
|
|
2
7
|
import { truncateFormat } from '../utils/format'
|
|
3
8
|
import { AllCurrentFuses, checkPCCBurned, decodeFuses } from '../utils/fuses'
|
|
4
9
|
import { decryptName } from '../utils/labels'
|
|
@@ -31,6 +36,11 @@ type WrappedSubname = BaseSubname & {
|
|
|
31
36
|
|
|
32
37
|
type Subname = WrappedSubname | UnwrappedSubname
|
|
33
38
|
|
|
39
|
+
type ReturnData = {
|
|
40
|
+
subnames: Subname[]
|
|
41
|
+
subnameCount: number
|
|
42
|
+
}
|
|
43
|
+
|
|
34
44
|
type Params = {
|
|
35
45
|
name: string
|
|
36
46
|
page?: number
|
|
@@ -127,7 +137,19 @@ const largeQuery = async (
|
|
|
127
137
|
orderDirection,
|
|
128
138
|
search: search?.toLowerCase(),
|
|
129
139
|
}
|
|
130
|
-
const response = await client
|
|
140
|
+
const response = await client
|
|
141
|
+
.request(finalQuery, queryVars)
|
|
142
|
+
.catch((e) => {
|
|
143
|
+
throw new ENSJSError({
|
|
144
|
+
data: {
|
|
145
|
+
subnames: [],
|
|
146
|
+
subnameCount: 0,
|
|
147
|
+
},
|
|
148
|
+
errors: getClientErrors(e),
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
.finally(debugSubgraphLatency)
|
|
152
|
+
|
|
131
153
|
const domain = response?.domain
|
|
132
154
|
const subdomains = domain.subdomains.map(
|
|
133
155
|
({ wrappedDomain, ...subname }: Domain) => {
|
|
@@ -174,7 +196,7 @@ const largeQuery = async (
|
|
|
174
196
|
const getSubnames = (
|
|
175
197
|
injected: ENSArgs<'gqlInstance'>,
|
|
176
198
|
functionArgs: Params,
|
|
177
|
-
): Promise<
|
|
199
|
+
): Promise<ReturnData> => {
|
|
178
200
|
return largeQuery(injected, functionArgs)
|
|
179
201
|
}
|
|
180
202
|
|
|
@@ -17,7 +17,7 @@ export default async function (
|
|
|
17
17
|
|
|
18
18
|
if (tld === 'eth') return true
|
|
19
19
|
|
|
20
|
-
const tldOwner = await getOwner(tld, 'registry')
|
|
20
|
+
const tldOwner = await getOwner(tld, { contract: 'registry' })
|
|
21
21
|
if (!tldOwner?.owner) return false
|
|
22
22
|
|
|
23
23
|
const dnsRegistrar = DNSRegistrar__factory.connect(
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ClientError } from 'graphql-request'
|
|
2
|
+
import { GraphQLError } from 'graphql'
|
|
3
|
+
|
|
4
|
+
export type ENSJSErrorName = 'ENSJSSubgraphError'
|
|
5
|
+
|
|
6
|
+
export class ENSJSError<T> extends Error {
|
|
7
|
+
name = 'ENSJSSubgraphError'
|
|
8
|
+
|
|
9
|
+
errors?: GraphQLError[]
|
|
10
|
+
|
|
11
|
+
data?: T
|
|
12
|
+
|
|
13
|
+
constructor({ data, errors }: { data?: T; errors?: GraphQLError[] }) {
|
|
14
|
+
super()
|
|
15
|
+
this.data = data
|
|
16
|
+
this.errors = errors
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getClientErrors = (e: unknown) => {
|
|
21
|
+
const error = e instanceof ClientError ? (e as ClientError) : undefined
|
|
22
|
+
return error?.response?.errors || [new GraphQLError('unknown_error')]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const isDebugEnvironmentActive = () => {
|
|
26
|
+
return (
|
|
27
|
+
process.env.NODE_ENV === 'development' ||
|
|
28
|
+
process.env.NEXT_PUBLIC_ENSJS_DEBUG === 'on'
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const debugSubgraphError = (request: any) => {
|
|
33
|
+
if (
|
|
34
|
+
isDebugEnvironmentActive() &&
|
|
35
|
+
typeof localStorage !== 'undefined' &&
|
|
36
|
+
localStorage.getItem('ensjs-debug') === 'ENSJSSubgraphError'
|
|
37
|
+
) {
|
|
38
|
+
// If we are testing indexing errors, we will allow _meta queries
|
|
39
|
+
// to pass through.
|
|
40
|
+
if (
|
|
41
|
+
localStorage.getItem('subgraph-debug') === 'ENSJSSubgraphIndexingError' &&
|
|
42
|
+
/_meta {/.test(request.body)
|
|
43
|
+
)
|
|
44
|
+
return
|
|
45
|
+
throw new ClientError(
|
|
46
|
+
{
|
|
47
|
+
data: undefined,
|
|
48
|
+
errors: [new GraphQLError('ensjs-debug')],
|
|
49
|
+
status: 200,
|
|
50
|
+
},
|
|
51
|
+
request,
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const debugSubgraphLatency = (): Promise<void> | undefined => {
|
|
57
|
+
if (
|
|
58
|
+
isDebugEnvironmentActive() &&
|
|
59
|
+
typeof localStorage !== 'undefined' &&
|
|
60
|
+
localStorage.getItem('ensjs-debug') === 'ENSJSSubgraphLatency'
|
|
61
|
+
) {
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
resolve()
|
|
65
|
+
}, 10000)
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
}
|