Skip to content

Commit 4cf6f41

Browse files
authored
feat(ensnode-sdk): introduce EnsIndexerClient (#1643)
1 parent b06e60f commit 4cf6f41

25 files changed

+686
-13
lines changed

.changeset/petite-rings-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ensnode/ensnode-sdk": minor
3+
---
4+
5+
Introduces `EnsIndexerClient` class, supporting easy interactions with ENSIndexer APIs.

packages/ensnode-sdk/src/ensapi/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ const _EXAMPLE_INDEXING_STATUS_FOLLOWING_RESPONSE: EnsApiIndexingStatusResponse
200200
responseCode: EnsApiIndexingStatusResponseCodes.Ok,
201201
});
202202

203-
// Mock fetch globally
203+
// Mock fetch globally (auto-restored by vitest)
204204
const mockFetch = vi.fn();
205-
global.fetch = mockFetch;
205+
vi.stubGlobal("fetch", mockFetch);
206206

207207
describe("EnsApiClient", () => {
208208
beforeEach(() => {

packages/ensnode-sdk/src/ensapi/client.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ import { getDefaultEnsNodeUrl } from "./deployments";
3333
/**
3434
* Configuration options for ENSNode API client
3535
*/
36-
export interface ClientOptions {
36+
export interface EnsApiClientOptions {
3737
/** The ENSNode API URL */
3838
url: URL;
3939
}
4040

41+
/**
42+
* Configuration options for ENSNode API client
43+
*
44+
* @deprecated Use {@link EnsApiClientOptions} instead.
45+
*/
46+
export type ClientOptions = EnsApiClientOptions;
47+
4148
/**
4249
* EnsApi Client
4350
*
@@ -93,22 +100,22 @@ export interface ClientOptions {
93100
* ```
94101
*/
95102
export class EnsApiClient {
96-
private readonly options: ClientOptions;
103+
private readonly options: EnsApiClientOptions;
97104

98-
static defaultOptions(): ClientOptions {
105+
static defaultOptions(): EnsApiClientOptions {
99106
return {
100107
url: getDefaultEnsNodeUrl(),
101108
};
102109
}
103110

104-
constructor(options: Partial<ClientOptions> = {}) {
111+
constructor(options: Partial<EnsApiClientOptions> = {}) {
105112
this.options = {
106113
...EnsApiClient.defaultOptions(),
107114
...options,
108115
};
109116
}
110117

111-
getOptions(): Readonly<ClientOptions> {
118+
getOptions(): Readonly<EnsApiClientOptions> {
112119
return Object.freeze({
113120
url: new URL(this.options.url.href),
114121
});
@@ -311,7 +318,7 @@ export class EnsApiClient {
311318
* @returns {EnsApiConfigResponse}
312319
*
313320
* @throws if the ENSApi request fails
314-
* @throws if the ENSApi returns an error response
321+
* @throws if the ENSApi returns a non-ok response
315322
* @throws if the ENSApi response breaks required invariants
316323
*/
317324
async config(): Promise<EnsApiConfigResponse> {
@@ -342,7 +349,7 @@ export class EnsApiClient {
342349
* @returns {EnsApiIndexingStatusResponse}
343350
*
344351
* @throws if the ENSApi request fails
345-
* @throws if the ENSApi returns an error response
352+
* @throws if the ENSApi returns a non-ok response
346353
* @throws if the ENSApi response breaks required invariants
347354
*/
348355
async indexingStatus(): Promise<EnsApiIndexingStatusResponse> {
@@ -366,9 +373,7 @@ export class EnsApiClient {
366373
try {
367374
errorResponse = deserializeErrorResponse(responseData);
368375
} catch {
369-
// if errorResponse could not be determined,
370-
// it means the response includes indexing status data
371-
console.log("Indexing Status API: handling a known indexing status server error.");
376+
// No-op: allow subsequent deserialization of indexing status response.
372377
}
373378

374379
// however, if errorResponse was defined,
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
export * from "./api";
2-
export { type ClientOptions, ENSNodeClient, EnsApiClient } from "./client";
2+
export {
3+
type ClientOptions,
4+
ENSNodeClient,
5+
EnsApiClient,
6+
type EnsApiClientOptions,
7+
} from "./client";
38
export * from "./client-error";
49
export * from "./config";
510
export * from "./deployments";
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Unvalidated } from "../../../shared/types";
2+
import { deserializeEnsIndexerPublicConfig } from "../../config/deserialize";
3+
import type { EnsIndexerConfigResponse } from "./response";
4+
import type { SerializedEnsIndexerConfigResponse } from "./serialized-response";
5+
6+
/**
7+
* Deserialize value into {@link EnsIndexerConfigResponse} object.
8+
*/
9+
export function deserializeEnsIndexerConfigResponse(
10+
maybeResponse: Unvalidated<SerializedEnsIndexerConfigResponse>,
11+
): EnsIndexerConfigResponse {
12+
return deserializeEnsIndexerPublicConfig(maybeResponse, "EnsIndexerConfigResponse");
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from "./deserialize";
2+
export * from "./response";
3+
export * from "./serialize";
4+
export * from "./serialized-response";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { EnsIndexerPublicConfig } from "../../config/types";
2+
3+
/**
4+
* ENSIndexer Public Config Response
5+
*/
6+
export type EnsIndexerConfigResponse = EnsIndexerPublicConfig;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { serializeEnsIndexerPublicConfig } from "../../config/serialize";
2+
import type { EnsIndexerConfigResponse } from "./response";
3+
import type { SerializedEnsIndexerConfigResponse } from "./serialized-response";
4+
5+
export function serializeEnsIndexerConfigResponse(
6+
response: EnsIndexerConfigResponse,
7+
): SerializedEnsIndexerConfigResponse {
8+
return serializeEnsIndexerPublicConfig(response);
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { SerializedEnsIndexerPublicConfig } from "../../config/serialized-types";
2+
3+
export type SerializedEnsIndexerConfigResponse = SerializedEnsIndexerPublicConfig;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./config";
2+
export * from "./indexing-status";

0 commit comments

Comments
 (0)