Skip to content

Commit 7e97ef7

Browse files
authored
refactor(ensnode-sdk): move ENSNodeClient into ENSApi module (#1636)
1 parent 75c8b01 commit 7e97ef7

7 files changed

Lines changed: 66 additions & 58 deletions

File tree

packages/ensnode-sdk/src/client-error.ts renamed to packages/ensnode-sdk/src/ensapi/client-error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ErrorResponse } from "./ensapi/api/shared/errors/response";
1+
import type { ErrorResponse } from "./api/shared/errors/response";
22

33
export class ClientError extends Error {
44
details?: unknown;

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

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import type { Address } from "viem";
22
import { beforeEach, describe, expect, it, vi } from "vitest";
33

4-
import { ENSNodeClient } from "./client";
5-
import { ClientError } from "./client-error";
6-
import { DEFAULT_ENSNODE_API_URL_MAINNET, getDefaultEnsNodeUrl } from "./deployments";
7-
import { ENSNamespaceIds, type Name } from "./ens";
8-
import { deserializeENSApiPublicConfig, type SerializedENSApiPublicConfig } from "./ensapi";
4+
import { ENSNamespaceIds, type Name } from "../ens";
5+
import { PluginName } from "../ensindexer/config/types";
6+
import {
7+
ChainIndexingConfigTypeIds,
8+
ChainIndexingStatusIds,
9+
} from "../indexing-status/chain-indexing-status-snapshot";
10+
import { CrossChainIndexingStrategyIds } from "../indexing-status/cross-chain-indexing-status-snapshot";
11+
import { OmnichainIndexingStatusIds } from "../indexing-status/omnichain-indexing-status-snapshot";
12+
import type { SerializedOmnichainIndexingStatusSnapshotFollowing } from "../indexing-status/serialize/omnichain-indexing-status-snapshot";
13+
import type { ResolverRecordsSelection } from "../resolution";
914
import {
1015
deserializeIndexingStatusResponse,
1116
type ErrorResponse,
@@ -15,16 +20,12 @@ import {
1520
type ResolvePrimaryNamesResponse,
1621
type SerializedIndexingStatusResponseOk,
1722
serializeIndexingStatusResponse,
18-
} from "./ensapi/api";
19-
import { PluginName } from "./ensindexer/config/types";
20-
import {
21-
ChainIndexingConfigTypeIds,
22-
ChainIndexingStatusIds,
23-
} from "./indexing-status/chain-indexing-status-snapshot";
24-
import { CrossChainIndexingStrategyIds } from "./indexing-status/cross-chain-indexing-status-snapshot";
25-
import { OmnichainIndexingStatusIds } from "./indexing-status/omnichain-indexing-status-snapshot";
26-
import type { SerializedOmnichainIndexingStatusSnapshotFollowing } from "./indexing-status/serialize/omnichain-indexing-status-snapshot";
27-
import type { ResolverRecordsSelection } from "./resolution";
23+
} from "./api";
24+
import { ENSApiClient } from "./client";
25+
import { ClientError } from "./client-error";
26+
import { deserializeENSApiPublicConfig } from "./config/deserialize";
27+
import type { SerializedENSApiPublicConfig } from "./config/serialized-types";
28+
import { DEFAULT_ENSNODE_API_URL_MAINNET, getDefaultEnsNodeUrl } from "./deployments";
2829

2930
const EXAMPLE_NAME: Name = "example.eth";
3031
const EXAMPLE_ADDRESS: Address = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045";
@@ -201,29 +202,29 @@ const _EXAMPLE_INDEXING_STATUS_FOLLOWING_RESPONSE: IndexingStatusResponse =
201202
const mockFetch = vi.fn();
202203
global.fetch = mockFetch;
203204

204-
describe("ENSNodeClient", () => {
205+
describe("ENSApiClient", () => {
205206
beforeEach(() => {
206207
mockFetch.mockClear();
207208
});
208209

209210
describe("constructor and options", () => {
210211
it("should use default options when none provided", () => {
211-
const client = new ENSNodeClient();
212+
const client = new ENSApiClient();
212213
const options = client.getOptions();
213214

214215
expect(options).toEqual({ url: getDefaultEnsNodeUrl(ENSNamespaceIds.Mainnet) });
215216
});
216217

217218
it("should merge provided options with defaults", () => {
218219
const customUrl = new URL("https://custom.api.com");
219-
const client = new ENSNodeClient({ url: customUrl });
220+
const client = new ENSApiClient({ url: customUrl });
220221
const options = client.getOptions();
221222

222223
expect(options).toEqual({ url: customUrl });
223224
});
224225

225226
it("should return frozen options object", () => {
226-
const client = new ENSNodeClient();
227+
const client = new ENSApiClient();
227228
const options = client.getOptions();
228229

229230
expect(Object.isFrozen(options)).toBe(true);
@@ -236,7 +237,7 @@ describe("ENSNodeClient", () => {
236237
const mockResponse = { records: EXAMPLE_RECORDS_RESPONSE };
237238
mockFetch.mockResolvedValueOnce({ ok: true, json: async () => mockResponse });
238239

239-
const client = new ENSNodeClient();
240+
const client = new ENSApiClient();
240241
const response = await client.resolveRecords(EXAMPLE_NAME, EXAMPLE_SELECTION);
241242

242243
const expectedUrl = new URL(
@@ -254,7 +255,7 @@ describe("ENSNodeClient", () => {
254255
const mockResponse = { records: EXAMPLE_RECORDS_RESPONSE, trace: [] };
255256
mockFetch.mockResolvedValueOnce({ ok: true, json: async () => mockResponse });
256257

257-
const client = new ENSNodeClient();
258+
const client = new ENSApiClient();
258259
const response = await client.resolveRecords(EXAMPLE_NAME, EXAMPLE_SELECTION, {
259260
trace: true,
260261
});
@@ -274,7 +275,7 @@ describe("ENSNodeClient", () => {
274275
it("should throw error when API returns error", async () => {
275276
mockFetch.mockResolvedValueOnce({ ok: false, json: async () => EXAMPLE_ERROR_RESPONSE });
276277

277-
const client = new ENSNodeClient();
278+
const client = new ENSApiClient();
278279
await expect(client.resolveRecords(EXAMPLE_NAME, EXAMPLE_SELECTION)).rejects.toThrowError(
279280
ClientError,
280281
);
@@ -288,7 +289,7 @@ describe("ENSNodeClient", () => {
288289
json: async () => EXAMPLE_PRIMARY_NAME_RESPONSE,
289290
});
290291

291-
const client = new ENSNodeClient();
292+
const client = new ENSApiClient();
292293
const response = await client.resolvePrimaryName(EXAMPLE_ADDRESS, 1);
293294

294295
const expectedUrl = new URL(
@@ -304,7 +305,7 @@ describe("ENSNodeClient", () => {
304305
const mockResponse = { name: EXAMPLE_NAME, trace: [] };
305306
mockFetch.mockResolvedValueOnce({ ok: true, json: async () => mockResponse });
306307

307-
const client = new ENSNodeClient();
308+
const client = new ENSApiClient();
308309
const response = await client.resolvePrimaryName(EXAMPLE_ADDRESS, 1, { trace: true });
309310

310311
const expectedUrl = new URL(
@@ -323,7 +324,7 @@ describe("ENSNodeClient", () => {
323324
json: async () => EXAMPLE_PRIMARY_NAME_RESPONSE,
324325
});
325326

326-
const client = new ENSNodeClient();
327+
const client = new ENSApiClient();
327328
await client.resolvePrimaryName(EXAMPLE_ADDRESS, 1, { accelerate: true });
328329

329330
const expectedUrl = new URL(
@@ -338,7 +339,7 @@ describe("ENSNodeClient", () => {
338339
it("should throw error when API returns error", async () => {
339340
mockFetch.mockResolvedValueOnce({ ok: false, json: async () => EXAMPLE_ERROR_RESPONSE });
340341

341-
const client = new ENSNodeClient();
342+
const client = new ENSApiClient();
342343
await expect(client.resolvePrimaryName(EXAMPLE_ADDRESS, 1)).rejects.toThrowError(ClientError);
343344
});
344345
});
@@ -350,7 +351,7 @@ describe("ENSNodeClient", () => {
350351
json: async () => EXAMPLE_PRIMARY_NAMES_RESPONSE,
351352
});
352353

353-
const client = new ENSNodeClient();
354+
const client = new ENSApiClient();
354355
const response = await client.resolvePrimaryNames(EXAMPLE_ADDRESS);
355356

356357
const expectedUrl = new URL(
@@ -368,7 +369,7 @@ describe("ENSNodeClient", () => {
368369
json: async () => EXAMPLE_PRIMARY_NAMES_RESPONSE,
369370
});
370371

371-
const client = new ENSNodeClient();
372+
const client = new ENSApiClient();
372373
await client.resolvePrimaryNames(EXAMPLE_ADDRESS, { chainIds: [1, 10] });
373374

374375
const expectedUrl = new URL(
@@ -384,7 +385,7 @@ describe("ENSNodeClient", () => {
384385
const mockResponse = { ...EXAMPLE_PRIMARY_NAMES_RESPONSE, trace: [] };
385386
mockFetch.mockResolvedValueOnce({ ok: true, json: async () => mockResponse });
386387

387-
const client = new ENSNodeClient();
388+
const client = new ENSApiClient();
388389
const response = await client.resolvePrimaryNames(EXAMPLE_ADDRESS, { trace: true });
389390

390391
const expectedUrl = new URL(
@@ -403,7 +404,7 @@ describe("ENSNodeClient", () => {
403404
json: async () => EXAMPLE_PRIMARY_NAMES_RESPONSE,
404405
});
405406

406-
const client = new ENSNodeClient();
407+
const client = new ENSApiClient();
407408
await client.resolvePrimaryNames(EXAMPLE_ADDRESS, { accelerate: true });
408409

409410
const expectedUrl = new URL(
@@ -418,7 +419,7 @@ describe("ENSNodeClient", () => {
418419
it("should throw error when API returns error", async () => {
419420
mockFetch.mockResolvedValueOnce({ ok: false, json: async () => EXAMPLE_ERROR_RESPONSE });
420421

421-
const client = new ENSNodeClient();
422+
const client = new ENSApiClient();
422423
await expect(client.resolvePrimaryNames(EXAMPLE_ADDRESS)).rejects.toThrowError(ClientError);
423424
});
424425
});
@@ -429,7 +430,7 @@ describe("ENSNodeClient", () => {
429430
const requestUrl = new URL(`/api/config`, DEFAULT_ENSNODE_API_URL_MAINNET);
430431
const serializedMockedResponse = EXAMPLE_CONFIG_RESPONSE;
431432
const mockedResponse = deserializeENSApiPublicConfig(serializedMockedResponse);
432-
const client = new ENSNodeClient();
433+
const client = new ENSApiClient();
433434

434435
mockFetch.mockResolvedValueOnce({
435436
ok: true,
@@ -444,7 +445,7 @@ describe("ENSNodeClient", () => {
444445
it("should throw error when API returns error", async () => {
445446
mockFetch.mockResolvedValueOnce({ ok: false, json: async () => EXAMPLE_ERROR_RESPONSE });
446447

447-
const client = new ENSNodeClient();
448+
const client = new ENSApiClient();
448449

449450
await expect(client.config()).rejects.toThrow(/Fetching ENSNode Config Failed/i);
450451
});
@@ -456,7 +457,7 @@ describe("ENSNodeClient", () => {
456457
const requestUrl = new URL(`/api/indexing-status`, DEFAULT_ENSNODE_API_URL_MAINNET);
457458
const mockedResponse = EXAMPLE_INDEXING_STATUS_BACKFILL_RESPONSE;
458459

459-
const client = new ENSNodeClient();
460+
const client = new ENSApiClient();
460461

461462
mockFetch.mockResolvedValueOnce({
462463
ok: true,
@@ -470,7 +471,7 @@ describe("ENSNodeClient", () => {
470471

471472
it("should throw error when API returns error other than 503 error", async () => {
472473
// arrange
473-
const client = new ENSNodeClient();
474+
const client = new ENSApiClient();
474475

475476
mockFetch.mockResolvedValueOnce({ ok: false, json: async () => EXAMPLE_ERROR_RESPONSE });
476477

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ClientError } from "./client-error";
2-
import { getDefaultEnsNodeUrl } from "./deployments";
1+
import type { ResolverRecordsSelection } from "../resolution";
32
import {
43
type ConfigResponse,
54
deserializeConfigResponse,
@@ -27,8 +26,9 @@ import {
2726
type SerializedIndexingStatusResponse,
2827
type SerializedNameTokensResponse,
2928
type SerializedRegistrarActionsResponse,
30-
} from "./ensapi/api";
31-
import type { ResolverRecordsSelection } from "./resolution";
29+
} from "./api";
30+
import { ClientError } from "./client-error";
31+
import { getDefaultEnsNodeUrl } from "./deployments";
3232

3333
/**
3434
* Configuration options for ENSNode API client
@@ -48,10 +48,10 @@ export interface ClientOptions {
4848
*
4949
* @example
5050
* ```typescript
51-
* import { ENSNodeClient } from "@ensnode/ensnode-sdk";
51+
* import { ENSApiClient } from "@ensnode/ensnode-sdk";
5252
*
5353
* // Create client with default options
54-
* const client = new ENSNodeClient();
54+
* const client = new ENSApiClient();
5555
*
5656
* // Use resolution methods
5757
* const { records } = await client.resolveRecords("jesse.base.eth", {
@@ -62,35 +62,35 @@ export interface ClientOptions {
6262
*
6363
* @example
6464
* ```typescript
65-
* import { ENSNamespaceIds, ENSNodeClient, getDefaultEnsNodeUrl } from "@ensnode/ensnode-sdk";
65+
* import { ENSNamespaceIds, ENSApiClient, getDefaultEnsNodeUrl } from "@ensnode/ensnode-sdk";
6666
*
6767
* // Use default ENSNode API URL for Mainnet
68-
* const client = new ENSNodeClient({
68+
* const client = new ENSApiClient({
6969
* url: getDefaultEnsNodeUrl(ENSNamespaceIds.Mainnet),
7070
* });
7171
* ```
7272
*
7373
* @example
7474
* ```typescript
75-
* import { ENSNamespaceIds, ENSNodeClient, getDefaultEnsNodeUrl } from "@ensnode/ensnode-sdk";
75+
* import { ENSNamespaceIds, ENSApiClient, getDefaultEnsNodeUrl } from "@ensnode/ensnode-sdk";
7676
*
7777
* // Use default ENSNode API URL for Sepolia
78-
* const client = new ENSNodeClient({
78+
* const client = new ENSApiClient({
7979
* url: getDefaultEnsNodeUrl(ENSNamespaceIds.Sepolia),
8080
* });
8181
* ```
8282
*
8383
* @example
8484
* ```typescript
85-
* import { ENSNodeClient } from "@ensnode/ensnode-sdk";
85+
* import { ENSApiClient } from "@ensnode/ensnode-sdk";
8686
*
8787
* // Custom configuration
88-
* const client = new ENSNodeClient({
88+
* const client = new ENSApiClient({
8989
* url: new URL("https://my-ensnode-instance.com"),
9090
* });
9191
* ```
9292
*/
93-
export class ENSNodeClient {
93+
export class ENSApiClient {
9494
private readonly options: ClientOptions;
9595

9696
static defaultOptions(): ClientOptions {
@@ -101,7 +101,7 @@ export class ENSNodeClient {
101101

102102
constructor(options: Partial<ClientOptions> = {}) {
103103
this.options = {
104-
...ENSNodeClient.defaultOptions(),
104+
...ENSApiClient.defaultOptions(),
105105
...options,
106106
};
107107
}
@@ -399,11 +399,11 @@ export class ENSNodeClient {
399399
* ```ts
400400
* import {
401401
* registrarActionsFilter,
402-
* ENSNodeClient,
402+
* ENSApiClient,
403403
* } from "@ensnode/ensnode-sdk";
404404
* import { namehash } from "viem/ens";
405405
*
406-
* const client: ENSNodeClient;
406+
* const client: ENSApiClient;
407407
*
408408
* // Get first page with default page size (10 records)
409409
* const response = await client.registrarActions();
@@ -611,11 +611,11 @@ export class ENSNodeClient {
611611
* @example
612612
* ```ts
613613
* import {
614-
* ENSNodeClient,
614+
* ENSApiClient,
615615
* } from "@ensnode/ensnode-sdk";
616616
* import { namehash } from "viem/ens";
617617
*
618-
* const client: ENSNodeClient;
618+
* const client: ENSApiClient;
619619
*
620620
* // get latest name token records from the indexed subregistry based on the requested name
621621
* const response = await client.nameTokens({
@@ -669,3 +669,10 @@ export class ENSNodeClient {
669669
return deserializedNameTokensResponse(responseData as SerializedNameTokensResponse);
670670
}
671671
}
672+
673+
/**
674+
* ENSNode Client
675+
*
676+
* @deprecated use {@link ENSApiClient} instead
677+
*/
678+
export class ENSNodeClient extends ENSApiClient {}

packages/ensnode-sdk/src/deployments.test.ts renamed to packages/ensnode-sdk/src/ensapi/deployments.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { describe, expect, it } from "vitest";
22

3+
import { ENSNamespaceIds } from "../ens";
34
import {
45
DEFAULT_ENSNODE_API_URL_MAINNET,
56
DEFAULT_ENSNODE_API_URL_SEPOLIA,
67
getDefaultEnsNodeUrl,
78
} from "./deployments";
8-
import { ENSNamespaceIds } from "./ens";
99

1010
describe("getDefaultEnsNodeUrl", () => {
1111
it("returns the mainnet default URL when no namespace is provided", () => {
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
export * from "./api";
2+
export { type ClientOptions, ENSApiClient, ENSNodeClient } from "./client";
3+
export * from "./client-error";
24
export * from "./config";
5+
export * from "./deployments";

packages/ensnode-sdk/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
export { type ClientOptions, ENSNodeClient } from "./client";
2-
export * from "./client-error";
3-
export * from "./deployments";
41
export * from "./ens";
52
export * from "./ensapi";
63
export * from "./ensindexer";

0 commit comments

Comments
 (0)