import config from '@nftx/config'; import { query as sendQuery } from '@nftx/utils'; import { syncApiBlock } from './nsync'; const queryApi = async ({ url, query: givenQuery = {}, method = 'GET', }: { url: string; query?: Record; method?: string; }) => { // Make sure the api is up to date (or switch to live mode if necessary) syncApiBlock(); const uri = new URL(url, config.urls.NFTX_API_URL); const query: Record = { ...givenQuery, ebn: 'true', source: config.internal.source, }; // Add the api key header const headers: Record = { 'Content-Type': 'application/json', }; if (config.keys.NFTX_API) { headers['Authorization'] = config.keys.NFTX_API; } else { console.warn('No NFTX API key found'); } // Send the request const data = await sendQuery({ url: uri.toString(), method, headers, query, }); return data; }; export default queryApi;