UNPKG

@apexfusionfoundation/blockfrost-js

Version:

A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API

44 lines (43 loc) 1.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInstance = void 0; const got_1 = __importDefault(require("got")); const getInstance = (apiUrl, options, userAgent, rateLimiter) => { return got_1.default.extend({ hooks: { beforeRequest: [ async (hookOptions) => { if (rateLimiter) { await rateLimiter.schedule(() => Promise.resolve(true)); } if (options.debug) { console.log(`${hookOptions.method} ${hookOptions.url}`); } }, ], beforeError: [ error => { if (options.debug) { console.error(error); } return error; }, ], }, prefixUrl: apiUrl, responseType: 'json', http2: options.http2, headers: { project_id: options.projectId, 'User-Agent': userAgent, }, retry: options.retrySettings, timeout: { request: options.requestTimeout, }, }); }; exports.getInstance = getInstance;