@blockfrost/blockfrost-js
Version:
A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API
173 lines (172 loc) • 9.26 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BlockFrostAPI = void 0;
/* eslint-disable tsdoc/syntax */
const config_1 = require("./config");
const accounts_1 = require("./endpoints/api/accounts");
const addresses_1 = require("./endpoints/api/addresses");
const assets_1 = require("./endpoints/api/assets");
const blocks_1 = require("./endpoints/api/blocks");
const governance_1 = require("./endpoints/api/governance");
const epochs_1 = require("./endpoints/api/epochs");
const pools_1 = require("./endpoints/api/pools");
const ledger_1 = require("./endpoints/api/ledger");
const root_1 = require("./endpoints/api/root");
const metadata_1 = require("./endpoints/api/metadata");
const mempool_1 = require("./endpoints/api/mempool");
const health_1 = require("./endpoints/api/health");
const metrics_1 = require("./endpoints/api/metrics");
const txs_1 = require("./endpoints/api/txs");
const scripts_1 = require("./endpoints/api/scripts");
const nutlink_1 = require("./endpoints/api/nutlink");
const network_1 = require("./endpoints/api/network");
const txs_2 = require("./endpoints/api/utils/txs");
const utils_1 = require("./utils");
const got_1 = require("./utils/got");
const limiter_1 = require("./utils/limiter");
// must be require, import would include package.json to the output dir together with "src" dir breaking dir hierarchy
// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../package.json');
class BlockFrostAPI {
constructor(options) {
this.accounts = accounts_1.accounts;
this.accountsDelegations = accounts_1.accountsDelegations;
this.accountsDelegationsAll = accounts_1.accountsDelegationsAll;
this.accountsRegistrations = accounts_1.accountsRegistrations;
this.accountsRegistrationsAll = accounts_1.accountsRegistrationsAll;
this.accountsRewards = accounts_1.accountsRewards;
this.accountsRewardsAll = accounts_1.accountsRewardsAll;
this.accountsHistory = accounts_1.accountsHistory;
this.accountsHistoryAll = accounts_1.accountsHistoryAll;
this.accountsWithdrawals = accounts_1.accountsWithdrawals;
this.accountsWithdrawalsAll = accounts_1.accountsWithdrawalsAll;
this.accountsMirs = accounts_1.accountsMirs;
this.accountsMirsAll = accounts_1.accountsMirsAll;
this.accountsAddresses = accounts_1.accountsAddresses;
this.accountsAddressesAll = accounts_1.accountsAddressesAll;
this.accountsAddressesAssets = accounts_1.accountsAddressesAssets;
this.accountsAddressesAssetsAll = accounts_1.accountsAddressesAssetsAll;
this.accountsAddressesTotal = accounts_1.accountsAddressesTotal;
this.assets = assets_1.assets;
this.assetsById = assets_1.assetsById;
this.assetsHistory = assets_1.assetsHistory;
this.assetsHistoryAll = assets_1.assetsHistoryAll;
this.assetsTransactions = assets_1.assetsTransactions;
this.assetsAddresses = assets_1.assetsAddresses;
this.assetsPolicyById = assets_1.assetsPolicyById;
this.assetsPolicyByIdAll = assets_1.assetsPolicyByIdAll;
this.addresses = addresses_1.addresses;
this.addressesTotal = addresses_1.addressesTotal;
this.addressesExtended = addresses_1.addressesExtended;
this.addressesTransactions = addresses_1.addressesTransactions;
this.addressesTransactionsAll = addresses_1.addressesTransactionsAll;
this.addressesUtxos = addresses_1.addressesUtxos;
this.addressesUtxosAll = addresses_1.addressesUtxosAll;
this.addressesUtxosAsset = addresses_1.addressesUtxosAsset;
this.addressesUtxosAssetAll = addresses_1.addressesUtxosAssetAll;
this.blocks = blocks_1.blocks;
this.blocksLatest = blocks_1.blocksLatest;
this.blocksLatestTxs = blocks_1.blocksLatestTxs;
this.blocksLatestTxsAll = blocks_1.blocksLatestTxsAll;
this.blocksNext = blocks_1.blocksNext;
this.blocksPrevious = blocks_1.blocksPrevious;
this.blocksTxs = blocks_1.blocksTxs;
this.blocksTxsAll = blocks_1.blocksTxsAll;
this.blocksAddresses = blocks_1.blocksAddresses;
this.blocksAddressesAll = blocks_1.blocksAddressesAll;
this.epochs = epochs_1.epochs;
this.epochsBlocks = epochs_1.epochsBlocks;
this.epochsBlocksAll = epochs_1.epochsBlocksAll;
this.epochsBlocksByPoolId = epochs_1.epochsBlocksByPoolId;
this.epochsBlocksByPoolIdAll = epochs_1.epochsBlocksByPoolIdAll;
this.epochsLatest = epochs_1.epochsLatest;
this.epochsNext = epochs_1.epochsNext;
this.epochsParameters = epochs_1.epochsParameters;
this.epochsLatestParameters = epochs_1.epochsLatestParameters;
this.epochsPrevious = epochs_1.epochsPrevious;
this.epochsStakes = epochs_1.epochsStakes;
this.epochsStakesAll = epochs_1.epochsStakesAll;
this.epochsStakesByPoolId = epochs_1.epochsStakesByPoolId;
this.epochsStakesByPoolIdAll = epochs_1.epochsStakesByPoolIdAll;
this.health = health_1.health;
this.healthClock = health_1.healthClock;
this.genesis = ledger_1.genesis;
this.mempool = mempool_1.mempool;
this.mempoolAll = mempool_1.mempoolAll;
this.mempoolTx = mempool_1.mempoolTx;
this.metadataTxsLabel = metadata_1.metadataTxsLabel;
this.metadataTxsLabelCbor = metadata_1.metadataTxsLabelCbor;
this.metadataTxsLabels = metadata_1.metadataTxsLabels;
this.mempoolByAddress = mempool_1.mempoolByAddress;
this.mempoolByAddressAll = mempool_1.mempoolByAddressAll;
this.metrics = metrics_1.metrics;
this.metricsEndpoints = metrics_1.metricsEndpoints;
this.nutlinkAddress = nutlink_1.nutlinkAddress;
this.nutlinkAddressTicker = nutlink_1.nutlinkAddressTicker;
this.nutlinkAddressTickers = nutlink_1.nutlinkAddressTickers;
this.nutlinkAddressTickersAll = nutlink_1.nutlinkAddressTickersAll;
this.nutlinkAddressTickerAll = nutlink_1.nutlinkAddressTickerAll;
this.nutlinkTickers = nutlink_1.nutlinkTickers;
this.nutlinkTickersAll = nutlink_1.nutlinkTickersAll;
this.pools = pools_1.pools;
this.poolsAll = pools_1.poolsAll;
this.poolMetadata = pools_1.poolMetadata;
this.poolsById = pools_1.poolsById;
this.poolsByIdBlocks = pools_1.poolsByIdBlocks;
this.poolsByIdDelegators = pools_1.poolsByIdDelegators;
this.poolsByIdHistory = pools_1.poolsByIdHistory;
this.poolsByIdRelays = pools_1.poolsByIdRelays;
this.poolsByIdUpdates = pools_1.poolsByIdUpdates;
this.poolsRetired = pools_1.poolsRetired;
this.poolsRetiring = pools_1.poolsRetiring;
this.poolsExtended = pools_1.poolsExtended;
this.poolsExtendedAll = pools_1.poolsExtendedAll;
this.root = root_1.root;
this.scripts = scripts_1.scripts;
this.scriptsByHash = scripts_1.scriptsByHash;
this.scriptsJson = scripts_1.scriptsJson;
this.scriptsCbor = scripts_1.scriptsCbor;
this.scriptsDatum = scripts_1.scriptsDatum;
this.scriptsDatumCbor = scripts_1.scriptsDatumCbor;
this.scriptsRedeemers = scripts_1.scriptsRedeemers;
this.txs = txs_1.txs;
this.txsMetadataCbor = txs_1.txsMetadataCbor;
this.txsDelegations = txs_1.txsDelegations;
this.txsPoolRetires = txs_1.txsPoolRetires;
this.txsPoolUpdates = txs_1.txsPoolUpdates;
this.txsStakes = txs_1.txsStakes;
this.txsUtxos = txs_1.txsUtxos;
this.txsWithdrawals = txs_1.txsWithdrawals;
this.txsMirs = txs_1.txsMirs;
this.txsMetadata = txs_1.txsMetadata;
this.txsRedeemers = txs_1.txsRedeemers;
this.txsRequiredSigners = txs_1.txsRequiredSigners;
this.txsCbor = txs_1.txsCbor;
this.txSubmit = txs_1.txSubmit;
this.network = network_1.network;
this.networkEras = network_1.networkEras;
this.utilsTxsEvaluate = txs_2.utilsTxsEvaluate;
this.utilsTxsEvaluateUtxos = txs_2.utilsTxsEvaluateUtxos;
this.options = (0, utils_1.validateOptions)(options);
let apiBase = config_1.API_URLS.mainnet;
if (this.options.network) {
if (this.options.network in config_1.API_URLS) {
apiBase = config_1.API_URLS[this.options.network];
}
else {
throw Error('Invalid network option. Valid options: mainnet, testnet, preview, preprod, sanchonet.');
}
}
this.apiUrl =
this.options?.customBackend || `${apiBase}/v${this.options.version}`;
this.projectId = this.options.projectId;
this.userAgent =
options?.userAgent ?? `${packageJson.name}@${packageJson.version}`;
this.rateLimiter = this.options.rateLimiter
? (0, limiter_1.getLimiter)(this.options.rateLimiter)
: undefined;
this.instance = (0, got_1.getInstance)(this.apiUrl, this.options, this.userAgent, this.rateLimiter);
this.governance = new governance_1.GovernanceAPI(this);
}
}
exports.BlockFrostAPI = BlockFrostAPI;