@quicknode/sdk 1.1.5 → 2.0.1

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.
Files changed (66) hide show
  1. package/README.md +3 -8
  2. package/cjs/index.js +15 -1093
  3. package/esm/{src/client → client}/client.js +0 -2
  4. package/esm/{src/index.js → index.js} +0 -2
  5. package/esm/lib/validation/ValidateInput.js +16 -0
  6. package/esm/lib/validation/validators.js +15 -0
  7. package/index.d.ts +6 -2767
  8. package/package.json +11 -29
  9. package/esm/package.json.js +0 -3
  10. package/esm/src/api/api.js +0 -94
  11. package/esm/src/api/controllers/contracts.js +0 -34
  12. package/esm/src/api/controllers/events.js +0 -113
  13. package/esm/src/api/controllers/nfts.js +0 -227
  14. package/esm/src/api/controllers/tokens.js +0 -93
  15. package/esm/src/api/controllers/transactions.js +0 -120
  16. package/esm/src/api/controllers/utils.js +0 -53
  17. package/esm/src/api/graphql/customUrqlClient.js +0 -23
  18. package/esm/src/api/graphql/generatedTypes.js +0 -22
  19. package/esm/src/api/graphql/modifyQueryForChain.js +0 -28
  20. package/esm/src/api/index.d.ts +0 -2690
  21. package/esm/src/api/index.js +0 -2
  22. package/esm/src/api/types/chains.js +0 -7
  23. package/esm/src/api/types/contracts/getContractDetails.js +0 -12
  24. package/esm/src/api/types/events/getAll.js +0 -7
  25. package/esm/src/api/types/events/getByContract.js +0 -12
  26. package/esm/src/api/types/nfts/getByContractAddress.js +0 -10
  27. package/esm/src/api/types/nfts/getByWalletAddress.js +0 -18
  28. package/esm/src/api/types/nfts/getCollectionDetails.js +0 -11
  29. package/esm/src/api/types/nfts/getCollectionEvents.js +0 -12
  30. package/esm/src/api/types/nfts/getNFTDetails.js +0 -9
  31. package/esm/src/api/types/nfts/getNFTEvents.js +0 -13
  32. package/esm/src/api/types/nfts/getTrendingCollections.js +0 -7
  33. package/esm/src/api/types/nfts/verifyOwnershipByAddress.js +0 -12
  34. package/esm/src/api/types/tokens/getBalancesByWalletAddress.js +0 -12
  35. package/esm/src/api/types/transactions/getByHash.js +0 -11
  36. package/esm/src/api/types/transactions/getBySearch.js +0 -7
  37. package/esm/src/api/types/utils/gasPrices.js +0 -12
  38. package/esm/src/api/utils/constants.js +0 -3
  39. package/esm/src/api/utils/helpers.js +0 -11
  40. package/esm/src/api/utils/isValidENSAddress.js +0 -21
  41. package/esm/src/api/utils/postQueryFormatter.js +0 -24
  42. package/esm/src/api/utils/removeNodesAndEdges.js +0 -51
  43. package/esm/src/lib/validation/ValidateInput.js +0 -35
  44. package/esm/src/lib/validation/codegenDerivedValidators.js +0 -28
  45. package/esm/src/lib/validation/validators.js +0 -105
  46. package/esm/{src/client → client}/index.js +0 -0
  47. package/esm/{src/core → core}/addOns/nftTokenV2/actions.js +0 -0
  48. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_fetchNFTCollectionDetails.js +0 -0
  49. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_fetchNFTs.js +0 -0
  50. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_fetchNFTsByCollection.js +0 -0
  51. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_getTokenMetadataByContractAddress.js +0 -0
  52. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_getTokenMetadataBySymbol.js +0 -0
  53. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_getTransactionsByAddress.js +0 -0
  54. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_getTransfersByNFT.js +0 -0
  55. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_getWalletTokenBalance.js +0 -0
  56. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_getWalletTokenTransactions.js +0 -0
  57. package/esm/{src/core → core}/addOns/nftTokenV2/types/qn_verifyNFTsOwner.js +0 -0
  58. package/esm/{src/core → core}/addOns/shared/helpers.js +0 -0
  59. package/esm/{src/core → core}/chains.js +0 -0
  60. package/esm/{src/core → core}/core.js +0 -0
  61. package/esm/{src/core → core}/index.d.ts +4 -4
  62. /package/esm/{src/core → core}/index.js +0 -0
  63. /package/esm/{src/lib → lib}/errors/QNChainNotSupported.js +0 -0
  64. /package/esm/{src/lib → lib}/errors/QNInputValidationError.js +0 -0
  65. /package/esm/{src/lib → lib}/errors/QNInvalidEnpointUrl.js +0 -0
  66. /package/esm/{src/lib → lib}/helpers/globalFetch.js +0 -0
package/package.json CHANGED
@@ -6,27 +6,18 @@
6
6
  "directory": "packages/libs/sdk"
7
7
  },
8
8
  "license": "MIT",
9
- "version": "1.1.5",
9
+ "version": "2.0.1",
10
10
  "main": "./cjs/index.js",
11
- "module": "./esm/src/index.js",
11
+ "module": "./esm/index.js",
12
12
  "types": "./index.d.ts",
13
13
  "sideEffects": false,
14
14
  "dependencies": {
15
- "@urql/core": "^4.2.0",
16
- "@urql/exchange-graphcache": "^6.4.0",
17
15
  "cross-fetch": "^3.1.6",
18
- "graphql": "^16.6.0",
19
- "klona": "^2.0.6",
20
16
  "tslib": "^2.5.3",
21
- "viem": "^1.2.0",
17
+ "viem": "^1.20.0",
22
18
  "zod": "^3.21.4"
23
19
  },
24
20
  "devDependencies": {
25
- "@graphql-codegen/cli": "4.0.1",
26
- "@graphql-codegen/fragment-matcher": "^3.3.1",
27
- "@graphql-codegen/typed-document-node": "^4.0.1",
28
- "@graphql-codegen/typescript": "2.8.0",
29
- "@graphql-codegen/typescript-operations": "^2.5.5",
30
21
  "@pollyjs/adapter-node-http": "^6.0.5",
31
22
  "@pollyjs/core": "^6.0.5",
32
23
  "@pollyjs/persister-fs": "^6.0.5",
@@ -38,32 +29,23 @@
38
29
  "eslint-plugin-no-only-tests": "^3.1.0",
39
30
  "supertest": "^6.3.3"
40
31
  },
41
- "scripts": {
42
- "codegen": "npx graphql-codegen --require dotenv/config"
43
- },
32
+ "scripts": {},
44
33
  "exports": {
45
34
  ".": {
46
- "import": "./esm/src/index.js",
47
- "require": "./cjs/index.js"
48
- },
49
- "./api": {
50
- "import": "./esm/src/api/index.js",
51
- "default": "./cjs/src/api/index.js",
52
- "types": "./esm/src/api/index.d.ts"
35
+ "import": "./esm/index.js",
36
+ "require": "./cjs/index.js",
37
+ "types": "./index.d.ts"
53
38
  },
54
39
  "./core": {
55
- "import": "./esm/src/core/index.js",
56
- "default": "./cjs/src/core/index.js",
57
- "types": "./esm/src/core/index.d.ts"
40
+ "import": "./esm/core/index.js",
41
+ "default": "./cjs/core/index.js",
42
+ "types": "./esm/core/index.d.ts"
58
43
  }
59
44
  },
60
45
  "typesVersions": {
61
46
  "*": {
62
- "api": [
63
- "./esm/src/api/index.d.ts"
64
- ],
65
47
  "core": [
66
- "./esm/src/core/index.d.ts"
48
+ "./esm/core/index.d.ts"
67
49
  ]
68
50
  }
69
51
  }
@@ -1,3 +0,0 @@
1
- var name="@quicknode/sdk";var repository={type:"git",url:"https://github.com/quiknode-labs/qn-oss.git",directory:"packages/libs/sdk"};var license="MIT";var version="1.1.5";var main="./cjs/index.js";var module="./esm/src/index.js";var types="./index.d.ts";var sideEffects=false;var dependencies={"@urql/core":"^4.2.0","@urql/exchange-graphcache":"^6.4.0","cross-fetch":"^3.1.6",graphql:"^16.6.0",klona:"^2.0.6",tslib:"^2.5.3",viem:"^1.2.0",zod:"^3.21.4"};var devDependencies={"@graphql-codegen/cli":"4.0.1","@graphql-codegen/fragment-matcher":"^3.3.1","@graphql-codegen/typed-document-node":"^4.0.1","@graphql-codegen/typescript":"2.8.0","@graphql-codegen/typescript-operations":"^2.5.5","@pollyjs/adapter-node-http":"^6.0.5","@pollyjs/core":"^6.0.5","@pollyjs/persister-fs":"^6.0.5","@types/jest":"^29.5.1","@types/mocha":"^10.0.1","@types/node":"^18.13.0","@types/supertest":"^2.0.12",dotenv:"^16.0.3","eslint-plugin-no-only-tests":"^3.1.0",supertest:"^6.3.3"};var scripts={codegen:"npx graphql-codegen --require dotenv/config"};var exports={".":{"import":"./esm/src/index.js",require:"./cjs/index.js"},"./api":{"import":"./esm/src/api/index.js","default":"./cjs/src/api/index.js",types:"./esm/src/api/index.d.ts"},"./core":{"import":"./esm/src/core/index.js","default":"./cjs/src/core/index.js",types:"./esm/src/core/index.d.ts"}};var typesVersions={"*":{api:["./esm/src/api/index.d.ts"],core:["./esm/src/core/index.d.ts"]}};var packageJson = {name:name,repository:repository,license:license,version:version,main:main,module:module,types:types,sideEffects:sideEffects,dependencies:dependencies,devDependencies:devDependencies,scripts:scripts,exports:exports,typesVersions:typesVersions};
2
-
3
- export { packageJson as default, dependencies, devDependencies, exports, license, main, module, name, repository, scripts, sideEffects, types, typesVersions, version };
@@ -1,94 +0,0 @@
1
- import fetch from 'cross-fetch';
2
- import { CustomUrqlClient } from './graphql/customUrqlClient.js';
3
- import { Client, fetchExchange } from '@urql/core';
4
- import { cacheExchange } from '@urql/exchange-graphcache';
5
- import { NftsController } from './controllers/nfts.js';
6
- import { TokensController } from './controllers/tokens.js';
7
- import { UtilsController } from './controllers/utils.js';
8
- import { ContractsController } from './controllers/contracts.js';
9
- import { EventsController } from './controllers/events.js';
10
- import { DEFAULT_CHAIN } from './utils/constants.js';
11
- import { TransactionsController } from './controllers/transactions.js';
12
- import packageJson from '../../package.json.js';
13
-
14
- class API {
15
- constructor({ graphApiKey, additionalHeaders, defaultChain, } = {}) {
16
- if (!graphApiKey) {
17
- console.warn('QuickNode SDK warning: no apiKey provided. Access with no apiKey is heavily rate limited and intended for development use only. For higher rate limits or production usage, create an account on https://www.quicknode.com/');
18
- }
19
- this.graphApiKey = graphApiKey;
20
- this.additionalHeaders = additionalHeaders;
21
- this.urqlClient = this.createUrqlClient();
22
- this.customUrqlClient = new CustomUrqlClient(this.urqlClient);
23
- this.defaultChain = defaultChain || DEFAULT_CHAIN;
24
- this.nfts = new NftsController(this.customUrqlClient, this.defaultChain);
25
- this.tokens = new TokensController(this.customUrqlClient, this.defaultChain);
26
- this.utils = new UtilsController(this.customUrqlClient, this.defaultChain);
27
- this.contracts = new ContractsController(this.customUrqlClient, this.defaultChain);
28
- this.transactions = new TransactionsController(this.customUrqlClient, this.defaultChain);
29
- this.events = new EventsController(this.customUrqlClient, this.defaultChain);
30
- // Re-export the Urql client configured to use the Graph API for use with custom queries
31
- this.graphApiClient = this.urqlClient;
32
- }
33
- createUrqlClient() {
34
- const headers = { ...this.additionalHeaders };
35
- if (this.graphApiKey)
36
- headers['x-api-key'] = this.graphApiKey;
37
- headers['x-quicknode-sdk'] = 'js-sdk';
38
- headers['x-quicknode-sdk-version'] = packageJson?.version || 'n/a';
39
- const useNftKey = (data) => `${data['contractAddress']}:${data['tokenId']}`;
40
- const useAddressAsKey = (data) => `${data['address']}`;
41
- const useTransactionHashAndIndex = (data) => `${data['transactionHash']}:${data['transferIndex']}`;
42
- const urqlCache = cacheExchange({
43
- logger: (severity, message) => {
44
- if (severity === 'warn' && process.env['SHOW_URQL_WARNINGS']) {
45
- console.warn(message);
46
- }
47
- if (severity === 'debug' && process.env['SHOW_URQL_DEBUG']) {
48
- console.debug(message);
49
- }
50
- if (severity === 'error') {
51
- console.error(message);
52
- }
53
- },
54
- keys: {
55
- EVMSchemaType: () => null,
56
- Collection: useAddressAsKey,
57
- CollectionOHLCVChart: () => null,
58
- Contract: useAddressAsKey,
59
- ERC721NFT: useNftKey,
60
- ERC721Collection: useAddressAsKey,
61
- ERC1155NFT: useNftKey,
62
- ERC1155Collection: useAddressAsKey,
63
- GasPrice: () => null,
64
- NFT: useNftKey,
65
- NFTContract: useAddressAsKey,
66
- TokenAttribute: () => null,
67
- TokenContract: useAddressAsKey,
68
- TokenEvent: useTransactionHashAndIndex,
69
- TokenMintEvent: useTransactionHashAndIndex,
70
- TokenBurnEvent: useTransactionHashAndIndex,
71
- TokenSaleEvent: useTransactionHashAndIndex,
72
- TokenSwapEvent: useTransactionHashAndIndex,
73
- TokenTransferEvent: useTransactionHashAndIndex,
74
- TokenUpload: () => null,
75
- OpenSeaMetadata: () => null,
76
- Transaction: (data) => `${data['hash']}`,
77
- TrendingCollection: () => null,
78
- Wallet: (data) => `${data['address']}`,
79
- WalletNFT: () => null,
80
- WalletTokenBalance: () => null,
81
- },
82
- });
83
- const client = new Client({
84
- fetch,
85
- url: process.env['NX_GRAPHQL_API_URI'] ||
86
- 'https://api.quicknode.com/graphql',
87
- exchanges: [urqlCache, fetchExchange],
88
- fetchOptions: () => ({ headers }),
89
- });
90
- return client;
91
- }
92
- }
93
-
94
- export { API };
@@ -1,34 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { DEFAULT_CHAIN } from '../utils/constants.js';
3
- import { contractDetailsValidator } from '../types/contracts/getContractDetails.js';
4
- import { CodegenEthMainnetContractDetailsDocument } from '../graphql/generatedTypes.js';
5
- import { ValidateInput } from '../../lib/validation/ValidateInput.js';
6
- import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
7
-
8
- class ContractsController {
9
- constructor(client, defaultChain = DEFAULT_CHAIN) {
10
- this.client = client;
11
- this.defaultChain = defaultChain;
12
- }
13
- async getDetails(variables) {
14
- const { chain, ...queryVariables } = variables;
15
- const userChain = chain || this.defaultChain;
16
- const query = modifyQueryForChain(userChain, CodegenEthMainnetContractDetailsDocument);
17
- const result = await this.client.query({
18
- variables: queryVariables,
19
- query: query,
20
- });
21
- const contract = result?.data?.[userChain]?.contract;
22
- if (contract)
23
- return { contract };
24
- return { contract: null };
25
- }
26
- }
27
- __decorate([
28
- ValidateInput(contractDetailsValidator),
29
- __metadata("design:type", Function),
30
- __metadata("design:paramtypes", [Object]),
31
- __metadata("design:returntype", Promise)
32
- ], ContractsController.prototype, "getDetails", null);
33
-
34
- export { ContractsController };
@@ -1,113 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { contractEventsValidator } from '../types/events/getByContract.js';
3
- import { collectionEventsValidator } from '../types/nfts/getCollectionEvents.js';
4
- import { nftEventsValidator } from '../types/nfts/getNFTEvents.js';
5
- import { allEventsValidator } from '../types/events/getAll.js';
6
- import { CodegenEthereumMainnetEventsByContractDocument, CodegenEthMainnetEventsByCollectionDocument, CodegenEthereumMainnetEventsByNftDocument, CodegenEthereumMainnetEventsGetAllDocument } from '../graphql/generatedTypes.js';
7
- import { formatQueryResult } from '../utils/postQueryFormatter.js';
8
- import { emptyPageInfo } from '../utils/helpers.js';
9
- import { DEFAULT_CHAIN } from '../utils/constants.js';
10
- import { ValidateInput } from '../../lib/validation/ValidateInput.js';
11
- import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
12
-
13
- class EventsController {
14
- constructor(client, defaultChain = DEFAULT_CHAIN) {
15
- this.client = client;
16
- this.defaultChain = defaultChain;
17
- }
18
- async getByContract(variables) {
19
- const { chain, ...queryVariables } = variables;
20
- const userChain = chain || this.defaultChain;
21
- const query = modifyQueryForChain(userChain, CodegenEthereumMainnetEventsByContractDocument);
22
- const result = await this.client.query({
23
- query: query,
24
- variables: queryVariables,
25
- });
26
- const contract = result?.data?.[userChain]?.contract;
27
- if (!contract?.tokenEvents?.length) {
28
- return {
29
- results: [],
30
- pageInfo: emptyPageInfo,
31
- };
32
- }
33
- const formattedResult = formatQueryResult(contract, 'tokenEvents', 'tokenEventsPageInfo');
34
- return formattedResult;
35
- }
36
- async getByNFTCollection(variables) {
37
- const { chain, ...queryVariables } = variables;
38
- const userChain = chain || this.defaultChain;
39
- const query = modifyQueryForChain(userChain, CodegenEthMainnetEventsByCollectionDocument);
40
- const result = await this.client.query({
41
- query: query,
42
- variables: queryVariables,
43
- });
44
- const collection = result?.data?.[userChain]?.collection;
45
- if (!collection?.tokenEvents?.length)
46
- return { results: [], pageInfo: emptyPageInfo };
47
- function removeKeyFields(results) {
48
- const { address, ...newResults } = results;
49
- return newResults;
50
- }
51
- const formattedResult = formatQueryResult(collection, 'tokenEvents', 'tokenEventsPageInfo', null, removeKeyFields);
52
- return formattedResult;
53
- }
54
- async getByNFT(variables) {
55
- const { chain, ...queryVariables } = variables;
56
- const userChain = chain || this.defaultChain;
57
- const query = modifyQueryForChain(userChain, CodegenEthereumMainnetEventsByNftDocument);
58
- const result = await this.client.query({
59
- query: query,
60
- variables: queryVariables,
61
- });
62
- const nft = result?.data?.[userChain]?.nft;
63
- if (!nft?.tokenEvents?.length)
64
- return { results: [], pageInfo: emptyPageInfo };
65
- function removeKeyFields(results) {
66
- const { contractAddress, tokenId, ...newResults } = results;
67
- return newResults;
68
- }
69
- const formattedResult = formatQueryResult(nft, 'tokenEvents', 'tokenEventsPageInfo', null, removeKeyFields);
70
- return formattedResult;
71
- }
72
- async getAll(variables) {
73
- const { chain, ...queryVariables } = variables;
74
- const userChain = chain || this.defaultChain;
75
- const query = modifyQueryForChain(userChain, CodegenEthereumMainnetEventsGetAllDocument);
76
- const result = await this.client.query({
77
- query: query,
78
- variables: queryVariables,
79
- });
80
- const events = result?.data?.[userChain];
81
- if (events?.tokenEvents?.length) {
82
- const formattedResult = formatQueryResult(events, 'tokenEvents', 'tokenEventsPageInfo');
83
- return formattedResult;
84
- }
85
- return { results: [], pageInfo: emptyPageInfo };
86
- }
87
- }
88
- __decorate([
89
- ValidateInput(contractEventsValidator),
90
- __metadata("design:type", Function),
91
- __metadata("design:paramtypes", [Object]),
92
- __metadata("design:returntype", Promise)
93
- ], EventsController.prototype, "getByContract", null);
94
- __decorate([
95
- ValidateInput(collectionEventsValidator),
96
- __metadata("design:type", Function),
97
- __metadata("design:paramtypes", [Object]),
98
- __metadata("design:returntype", Promise)
99
- ], EventsController.prototype, "getByNFTCollection", null);
100
- __decorate([
101
- ValidateInput(nftEventsValidator),
102
- __metadata("design:type", Function),
103
- __metadata("design:paramtypes", [Object]),
104
- __metadata("design:returntype", Promise)
105
- ], EventsController.prototype, "getByNFT", null);
106
- __decorate([
107
- ValidateInput(allEventsValidator),
108
- __metadata("design:type", Function),
109
- __metadata("design:paramtypes", [Object]),
110
- __metadata("design:returntype", Promise)
111
- ], EventsController.prototype, "getAll", null);
112
-
113
- export { EventsController };
@@ -1,227 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { walletByAddressValidator } from '../types/nfts/getByWalletAddress.js';
3
- import { nftDetailsValidator } from '../types/nfts/getNFTDetails.js';
4
- import { nftCollectionDetailsValidator } from '../types/nfts/getCollectionDetails.js';
5
- import { nftTrendingCollectionsValidator } from '../types/nfts/getTrendingCollections.js';
6
- import { nftsByContractAddressValidator } from '../types/nfts/getByContractAddress.js';
7
- import { verifyOwnershipValidator } from '../types/nfts/verifyOwnershipByAddress.js';
8
- import { CodegenEthMainnetWalletNFTsByEnsDocument, CodegenEthMainnetWalletNFTsByAddressDocument, CodegenEthMainnetTrendingCollectionsDocument, CodegenEthMainnetWalletNFTsByContractAddressDocument, CodegenEthMainnetNFTDetailsDocument, CodegenEthMainnetNftCollectionDetailsDocument, CodegenEthMainnetVerifyOwnershipByAddressDocument, CodegenEthMainnetVerifyOwnershipByENSDocument } from '../graphql/generatedTypes.js';
9
- import { formatQueryResult } from '../utils/postQueryFormatter.js';
10
- import { emptyPageInfo } from '../utils/helpers.js';
11
- import { DEFAULT_CHAIN } from '../utils/constants.js';
12
- import { isValidENSAddress } from '../utils/isValidENSAddress.js';
13
- import { ValidateInput } from '../../lib/validation/ValidateInput.js';
14
- import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
15
-
16
- class NftsController {
17
- constructor(client, defaultChain = DEFAULT_CHAIN) {
18
- this.client = client;
19
- this.defaultChain = defaultChain;
20
- }
21
- async getByWallet(variables) {
22
- const { address, ...allVariables } = variables;
23
- if (isValidENSAddress(address)) {
24
- return this.getByWalletENS({
25
- ensName: address,
26
- ...allVariables,
27
- });
28
- }
29
- return this.getByWalletAddress({
30
- address,
31
- ...allVariables,
32
- });
33
- }
34
- async getByWalletENS(variables) {
35
- const { chain, ...queryVariables } = variables;
36
- const userChain = chain || this.defaultChain;
37
- const query = modifyQueryForChain(userChain, CodegenEthMainnetWalletNFTsByEnsDocument);
38
- const result = await this.client.query({
39
- query: query,
40
- variables: queryVariables,
41
- });
42
- const walletByENS = result?.data?.[userChain]?.walletByENS;
43
- if (!walletByENS?.walletNFTs?.length) {
44
- // Address can still be valid ENS name, but not have any NFTs
45
- const address = walletByENS?.address || '';
46
- const ensName = walletByENS?.ensName || '';
47
- return {
48
- address: address,
49
- ensName: ensName,
50
- results: [],
51
- pageInfo: emptyPageInfo,
52
- };
53
- }
54
- const formattedResult = formatQueryResult(walletByENS, 'walletNFTs', 'walletNFTsPageInfo', 'nft');
55
- return formattedResult;
56
- }
57
- async getByWalletAddress(variables) {
58
- const { chain, ...queryVariables } = variables;
59
- const userChain = chain || this.defaultChain;
60
- const query = modifyQueryForChain(userChain, CodegenEthMainnetWalletNFTsByAddressDocument);
61
- const result = await this.client.query({
62
- query: query,
63
- variables: queryVariables,
64
- });
65
- const walletByAddress = result?.data?.[userChain]?.walletByAddress;
66
- if (!walletByAddress?.walletNFTs?.length) {
67
- const address = walletByAddress?.address || '';
68
- const ensName = walletByAddress?.ensName || '';
69
- return {
70
- address: address,
71
- ensName: ensName,
72
- results: [],
73
- pageInfo: emptyPageInfo,
74
- };
75
- }
76
- const formattedResult = formatQueryResult(walletByAddress, 'walletNFTs', 'walletNFTsPageInfo', 'nft');
77
- return formattedResult;
78
- }
79
- async getTrendingCollections(variables) {
80
- const { chain, ...queryVariables } = variables;
81
- const userChain = chain || this.defaultChain;
82
- const query = modifyQueryForChain(userChain, CodegenEthMainnetTrendingCollectionsDocument);
83
- const result = await this.client.query({
84
- query: query,
85
- variables: queryVariables,
86
- });
87
- const chainResult = result?.data?.[userChain];
88
- if (chainResult?.trendingCollections?.length) {
89
- const formattedResult = formatQueryResult(chainResult, 'trendingCollections', 'trendingCollectionsPageInfo', 'collection');
90
- return formattedResult;
91
- }
92
- return {
93
- results: [],
94
- pageInfo: emptyPageInfo,
95
- };
96
- }
97
- async getByContractAddress(variables) {
98
- const { chain, ...queryVariables } = variables;
99
- const userChain = chain || this.defaultChain;
100
- const query = modifyQueryForChain(userChain, CodegenEthMainnetWalletNFTsByContractAddressDocument);
101
- const result = await this.client.query({
102
- query: query,
103
- variables: queryVariables,
104
- });
105
- const collection = result?.data?.[userChain]?.collection;
106
- if (!collection?.nfts?.length) {
107
- return {
108
- standard: null,
109
- results: [],
110
- pageInfo: emptyPageInfo,
111
- };
112
- }
113
- const setErcStandard = (results) => {
114
- const standardMap = {
115
- ERC1155Collection: 'ERC1155',
116
- ERC721Collection: 'ERC721',
117
- };
118
- // Remove address too since it was only used as a key field
119
- const { __typename, address, ...newResults } = results;
120
- return {
121
- ...newResults,
122
- standard: standardMap[results['__typename']] || null,
123
- };
124
- };
125
- const formattedResult = formatQueryResult(collection, 'nfts', 'nftsPageInfo', null, setErcStandard);
126
- return formattedResult;
127
- }
128
- async getNFTDetails(variables) {
129
- const { chain, ...queryVariables } = variables;
130
- const userChain = chain || this.defaultChain;
131
- const query = modifyQueryForChain(userChain, CodegenEthMainnetNFTDetailsDocument);
132
- const result = await this.client.query({
133
- query,
134
- variables: queryVariables,
135
- });
136
- const nft = result?.data?.[userChain]?.nft;
137
- if (nft)
138
- return { nft };
139
- return { nft: null };
140
- }
141
- async getCollectionDetails(variables) {
142
- const { chain, ...queryVariables } = variables;
143
- const userChain = chain || this.defaultChain;
144
- const query = modifyQueryForChain(userChain, CodegenEthMainnetNftCollectionDetailsDocument);
145
- const result = await this.client.query({
146
- query: query,
147
- variables: queryVariables,
148
- });
149
- const collection = result?.data?.[userChain]?.collection;
150
- if (collection)
151
- return { collection };
152
- return { collection: null };
153
- }
154
- async verifyOwnership(variables) {
155
- const { address, ...allVariables } = variables;
156
- if (isValidENSAddress(address)) {
157
- return this.verifyOwnershipByENS({
158
- ensName: address,
159
- ...allVariables,
160
- });
161
- }
162
- return this.verifyOwnershipByAddress({
163
- address,
164
- ...allVariables,
165
- });
166
- }
167
- async verifyOwnershipByAddress(variables) {
168
- const { chain, address, nfts } = variables;
169
- const userChain = chain || this.defaultChain;
170
- const query = modifyQueryForChain(userChain, CodegenEthMainnetVerifyOwnershipByAddressDocument);
171
- const result = await this.client.query({
172
- query: query,
173
- variables: { address, filter: { contractTokens: nfts } },
174
- });
175
- const walletNFTs = result?.data?.[userChain]?.walletByAddress?.walletNFTs;
176
- return !!walletNFTs?.length;
177
- }
178
- async verifyOwnershipByENS(variables) {
179
- const { chain, ensName, nfts } = variables;
180
- const userChain = chain || this.defaultChain;
181
- const query = modifyQueryForChain(userChain, CodegenEthMainnetVerifyOwnershipByENSDocument);
182
- const result = await this.client.query({
183
- query: query,
184
- variables: { ensName, filter: { contractTokens: nfts } },
185
- });
186
- const walletByENS = result?.data?.[userChain]?.walletByENS?.walletNFTs;
187
- return !!walletByENS?.length;
188
- }
189
- }
190
- __decorate([
191
- ValidateInput(walletByAddressValidator),
192
- __metadata("design:type", Function),
193
- __metadata("design:paramtypes", [Object]),
194
- __metadata("design:returntype", Promise)
195
- ], NftsController.prototype, "getByWallet", null);
196
- __decorate([
197
- ValidateInput(nftTrendingCollectionsValidator),
198
- __metadata("design:type", Function),
199
- __metadata("design:paramtypes", [Object]),
200
- __metadata("design:returntype", Promise)
201
- ], NftsController.prototype, "getTrendingCollections", null);
202
- __decorate([
203
- ValidateInput(nftsByContractAddressValidator),
204
- __metadata("design:type", Function),
205
- __metadata("design:paramtypes", [Object]),
206
- __metadata("design:returntype", Promise)
207
- ], NftsController.prototype, "getByContractAddress", null);
208
- __decorate([
209
- ValidateInput(nftDetailsValidator),
210
- __metadata("design:type", Function),
211
- __metadata("design:paramtypes", [Object]),
212
- __metadata("design:returntype", Promise)
213
- ], NftsController.prototype, "getNFTDetails", null);
214
- __decorate([
215
- ValidateInput(nftCollectionDetailsValidator),
216
- __metadata("design:type", Function),
217
- __metadata("design:paramtypes", [Object]),
218
- __metadata("design:returntype", Promise)
219
- ], NftsController.prototype, "getCollectionDetails", null);
220
- __decorate([
221
- ValidateInput(verifyOwnershipValidator),
222
- __metadata("design:type", Function),
223
- __metadata("design:paramtypes", [Object]),
224
- __metadata("design:returntype", Promise)
225
- ], NftsController.prototype, "verifyOwnership", null);
226
-
227
- export { NftsController };
@@ -1,93 +0,0 @@
1
- import { __decorate, __metadata } from 'tslib';
2
- import { DEFAULT_CHAIN } from '../utils/constants.js';
3
- import { balancesByWalletAddressValidator } from '../types/tokens/getBalancesByWalletAddress.js';
4
- import { CodegenEthMainnetBalancesByWalletENSDocument, CodegenEthMainnetBalancesByWalletAddressDocument } from '../graphql/generatedTypes.js';
5
- import { emptyPageInfo } from '../utils/helpers.js';
6
- import { formatQueryResult } from '../utils/postQueryFormatter.js';
7
- import { isValidENSAddress } from '../utils/isValidENSAddress.js';
8
- import { ValidateInput } from '../../lib/validation/ValidateInput.js';
9
- import { modifyQueryForChain } from '../graphql/modifyQueryForChain.js';
10
-
11
- class TokensController {
12
- constructor(client, defaultChain = DEFAULT_CHAIN) {
13
- this.client = client;
14
- this.defaultChain = defaultChain;
15
- }
16
- async getBalancesByWallet(variables) {
17
- const { address, ...allVariables } = variables;
18
- if (isValidENSAddress(address)) {
19
- return this.getBalancesByWalletENS({
20
- ensName: address,
21
- ...allVariables,
22
- });
23
- }
24
- return this.getBalancesByWalletAddress({
25
- address,
26
- ...allVariables,
27
- });
28
- }
29
- async getBalancesByWalletENS(variables) {
30
- const { chain, ...queryVariables } = variables;
31
- const userChain = chain || this.defaultChain;
32
- const query = modifyQueryForChain(userChain, CodegenEthMainnetBalancesByWalletENSDocument);
33
- const result = await this.client.query({
34
- variables: queryVariables,
35
- query: query,
36
- });
37
- const walletByENS = result?.data?.[userChain]?.walletByENS;
38
- if (!walletByENS?.tokenBalances?.length) {
39
- // Address can still be valid ENS name, but not have any balances
40
- const address = walletByENS?.address || '';
41
- const ensName = walletByENS?.ensName || '';
42
- return {
43
- address: address,
44
- ensName: ensName,
45
- results: [],
46
- pageInfo: emptyPageInfo,
47
- };
48
- }
49
- const formattedResult = formatQueryResult(walletByENS, 'tokenBalances', 'tokenBalancesPageInfo', null, this.flattenBalanceResponses // Remove the "contract" key and move info to balance result body
50
- );
51
- return formattedResult;
52
- }
53
- async getBalancesByWalletAddress(variables) {
54
- const { chain, ...queryVariables } = variables;
55
- const userChain = chain || this.defaultChain;
56
- const query = modifyQueryForChain(userChain, CodegenEthMainnetBalancesByWalletAddressDocument);
57
- const result = await this.client.query({
58
- variables: queryVariables,
59
- query: query,
60
- });
61
- const walletByAddress = result?.data?.[userChain]?.walletByAddress;
62
- if (!walletByAddress?.tokenBalances?.length) {
63
- // Address can still be valid address, but not have any balances
64
- const address = walletByAddress?.address || '';
65
- const ensName = walletByAddress?.ensName || '';
66
- return {
67
- address: address,
68
- ensName: ensName,
69
- results: [],
70
- pageInfo: emptyPageInfo,
71
- };
72
- }
73
- const formattedResult = formatQueryResult(walletByAddress, 'tokenBalances', 'tokenBalancesPageInfo', null, this.flattenBalanceResponses // Remove the "contract" key and move info to balance result body
74
- );
75
- return formattedResult;
76
- }
77
- flattenBalanceResponses(response) {
78
- const modifiedResults = response.results.map((result) => {
79
- const { contract: { ...contractInfo }, ...balanceInfo } = result;
80
- return { ...balanceInfo, ...contractInfo };
81
- });
82
- response.results = modifiedResults;
83
- return response;
84
- }
85
- }
86
- __decorate([
87
- ValidateInput(balancesByWalletAddressValidator),
88
- __metadata("design:type", Function),
89
- __metadata("design:paramtypes", [Object]),
90
- __metadata("design:returntype", Promise)
91
- ], TokensController.prototype, "getBalancesByWallet", null);
92
-
93
- export { TokensController };