diff --git a/packages/ensnode-sdk/package.json b/packages/ensnode-sdk/package.json index f1b5e3b45a..c3913c03a0 100644 --- a/packages/ensnode-sdk/package.json +++ b/packages/ensnode-sdk/package.json @@ -34,6 +34,16 @@ "types": "./dist/index.d.cts", "default": "./dist/index.cjs" } + }, + "./internal": { + "import": { + "types": "./dist/internal.d.ts", + "default": "./dist/internal.js" + }, + "require": { + "types": "./dist/internal.d.cts", + "default": "./dist/internal.cjs" + } } }, "main": "./dist/index.cjs", diff --git a/packages/ensnode-sdk/src/omnigraph-api/example-queries.ts b/packages/ensnode-sdk/src/omnigraph-api/example-queries.ts index d4e0127fdb..0630a16a42 100644 --- a/packages/ensnode-sdk/src/omnigraph-api/example-queries.ts +++ b/packages/ensnode-sdk/src/omnigraph-api/example-queries.ts @@ -33,20 +33,38 @@ const ENS_TEST_ENV_V2_ETH_REGISTRAR = maybeGetDatasourceContract( const VITALIK_ADDRESS = toNormalizedAddress("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"); // owns sfmonicdeb*.eth (mix of v1 + v2) on sepolia-v2 and holds v2 ETHRegistry permissions -const SEPOLIA_V2_USER_ADDRESS = toNormalizedAddress("0x2f8e8b1126e75fde0b7f731e7cb5847eba2d2574"); +const _SEPOLIA_V2_USER_ADDRESS = toNormalizedAddress("0x2f8e8b1126e75fde0b7f731e7cb5847eba2d2574"); + +const SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES = toNormalizedAddress( + "0x205d2686da3bf33f64c17f21462c51b5ead462cf", +); const DEVNET_NAME_WITH_OWNED_RESOLVER = asInterpretedName("example.eth"); -const SEPOLIA_V2_NAME_WITH_OWNED_RESOLVER = asInterpretedName("sfmonicdebmig.eth"); +const SEPOLIA_V2_NAME_WITH_OWNED_RESOLVER = asInterpretedName("demomigration.eth"); + +const SEPOLIA_V2_TEST_NAME = asInterpretedName("test-name.eth"); -export const GRAPHQL_API_EXAMPLE_QUERIES: Array<{ +export type GraphqlApiExampleQuery = { + id: string; query: string; variables: NamespaceSpecificValue>; -}> = [ +}; + +export function getGraphqlApiExampleQueryById(id: string): GraphqlApiExampleQuery { + const found = graphqlApiExampleQueryById.get(id); + if (!found) { + throw new Error(`Unknown GraphQL API example query id: ${id}`); + } + return found; +} + +export const GRAPHQL_API_EXAMPLE_QUERIES: GraphqlApiExampleQuery[] = [ //////////////// // Hello World //////////////// { + id: "hello-world", query: `# # Welcome to this interactive playground for # ENSNode's GraphQL API! @@ -65,6 +83,7 @@ query HelloWorld { // Find Domains ///////////////// { + id: "find-domains", query: ` query FindDomains( $name: String! @@ -90,7 +109,7 @@ query FindDomains( variables: { default: { name: "vitalik", order: { by: "NAME", dir: "DESC" } }, [ENSNamespaceIds.EnsTestEnv]: { name: "c", order: { by: "NAME", dir: "DESC" } }, - [ENSNamespaceIds.SepoliaV2]: { name: "sfmonic", order: { by: "NAME", dir: "DESC" } }, + [ENSNamespaceIds.SepoliaV2]: { name: "test-na", order: { by: "NAME", dir: "DESC" } }, }, }, @@ -98,6 +117,7 @@ query FindDomains( // Domain By Name /////////////////// { + id: "domain-by-name", query: ` query DomainByName($name: InterpretedName!) { domain(by: {name: $name}) { @@ -120,7 +140,7 @@ query DomainByName($name: InterpretedName!) { }`, variables: { default: { name: "eth" }, - [ENSNamespaceIds.SepoliaV2]: { name: "sfmonicdebmig.eth" }, + [ENSNamespaceIds.SepoliaV2]: { name: SEPOLIA_V2_TEST_NAME }, }, }, @@ -128,6 +148,7 @@ query DomainByName($name: InterpretedName!) { // Domain Subdomains ////////////////////// { + id: "domain-subdomains", query: ` query DomainSubdomains($name: InterpretedName!) { domain(by: {name: $name}) { @@ -148,6 +169,7 @@ query DomainSubdomains($name: InterpretedName!) { // Domain Events ///////////////// { + id: "domain-events", query: ` query DomainEvents($name: InterpretedName!) { domain(by: {name: $name}) { @@ -176,6 +198,7 @@ query DomainEvents($name: InterpretedName!) { // Account Domains //////////////////// { + id: "domains-by-address", query: ` query AccountDomains( $address: Address! @@ -194,7 +217,7 @@ query AccountDomains( variables: { default: { address: VITALIK_ADDRESS }, [ENSNamespaceIds.EnsTestEnv]: { address: accounts.owner.address }, - [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, + [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, }, }, @@ -202,6 +225,7 @@ query AccountDomains( // Account Events //////////////////// { + id: "account-events", query: ` query AccountEvents( $address: Address! @@ -213,7 +237,7 @@ query AccountEvents( variables: { default: { address: VITALIK_ADDRESS }, [ENSNamespaceIds.EnsTestEnv]: { address: accounts.deployer.address }, - [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, + [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, }, }, @@ -221,6 +245,7 @@ query AccountEvents( // Registry Domains ///////////////////// { + id: "registry-domains", query: ` query RegistryDomains( $registry: AccountIdInput! @@ -247,6 +272,7 @@ query RegistryDomains( // Permissions By Contract //////////////////////////// { + id: "permissions-by-contract", query: ` query PermissionsByContract( $contract: AccountIdInput! @@ -274,6 +300,7 @@ query PermissionsByContract( variables: { // TODO: same as above default: { contract: ENS_TEST_ENV_V2_ETH_REGISTRAR }, + // TODO: example response is empty for this address on Sepolia V2 [ENSNamespaceIds.SepoliaV2]: { contract: SEPOLIA_V2_V2_ETH_REGISTRAR }, }, }, @@ -282,6 +309,7 @@ query PermissionsByContract( // Permissions By User //////////////////////// { + id: "permissions-by-user", query: ` query PermissionsByUser($address: Address!) { account(by: { address: $address }) { @@ -297,7 +325,8 @@ query PermissionsByUser($address: Address!) { }`, variables: { default: { address: accounts.deployer.address }, - [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, + // TODO: example response is empty for this address on Sepolia V2 + [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, }, }, @@ -305,6 +334,7 @@ query PermissionsByUser($address: Address!) { // Account Resolver Permissions ////////////////////////////////// { + id: "account-resolver-permissions", query: ` query AccountResolverPermissions($address: Address!) { account(by: { address: $address }) { @@ -323,7 +353,7 @@ query AccountResolverPermissions($address: Address!) { }`, variables: { default: { address: accounts.deployer.address }, - [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_USER_ADDRESS }, + [ENSNamespaceIds.SepoliaV2]: { address: SEPOLIA_V2_ADDRESS_WITH_LOT_OF_NAMES }, }, }, @@ -331,6 +361,7 @@ query AccountResolverPermissions($address: Address!) { // Domain's Assigned Resolver ////////////////////////////// { + id: "domain-resolver", query: ` query DomainResolver($name: InterpretedName!) { domain(by: { name: $name }) { @@ -352,6 +383,7 @@ query DomainResolver($name: InterpretedName!) { // Namegraph ////////////// { + id: "namegraph", query: ` query Namegraph { root { @@ -384,3 +416,7 @@ query Namegraph { variables: { default: {} }, }, ]; + +const graphqlApiExampleQueryById = new Map( + GRAPHQL_API_EXAMPLE_QUERIES.map((entry) => [entry.id, entry]), +); diff --git a/packages/ensnode-sdk/src/shared/datasource-contract.ts b/packages/ensnode-sdk/src/shared/datasource-contract.ts index ab5224c9f2..e76d1a359d 100644 --- a/packages/ensnode-sdk/src/shared/datasource-contract.ts +++ b/packages/ensnode-sdk/src/shared/datasource-contract.ts @@ -6,7 +6,8 @@ import { type ENSNamespaceId, maybeGetDatasource, } from "@ensnode/datasources"; -import { accountIdEqual } from "@ensnode/ensnode-sdk"; + +import { accountIdEqual } from "./account-id"; /** * Gets the AccountId for the contract in the specified namespace, datasource, and diff --git a/packages/ensnode-sdk/tsup.config.ts b/packages/ensnode-sdk/tsup.config.ts index f855a15e5e..102aa82abd 100644 --- a/packages/ensnode-sdk/tsup.config.ts +++ b/packages/ensnode-sdk/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from "tsup"; export default defineConfig({ - entry: ["src/index.ts"], + entry: ["src/index.ts", "src/internal.ts"], platform: "neutral", format: ["esm", "cjs"], target: "es2022",