@blockfrost/blockfrost-js
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -8,2 +8,10 @@ # Changelog | ||
## [0.7.0] - 2021-06-23 | ||
### Added | ||
- `retryCount` param | ||
- `retryDelay` param | ||
- axios `requestTimeout` params | ||
## [0.6.0] - 2021-06-22 | ||
@@ -10,0 +18,0 @@ |
@@ -14,3 +14,3 @@ import { components } from './types/OpenApi'; | ||
import { txs, txsDelegations, txsMetadataCbor, txsPoolRetires, txsPoolUpdates, txsStakes, txsUtxos, txsWithdrawals, txsMirs, txsMetadata, txSubmit } from './endpoints/txs'; | ||
import { Options } from './types'; | ||
import { Options, ValidatedOptions } from './types'; | ||
declare class BlockFrostAPI { | ||
@@ -20,2 +20,3 @@ apiUrl: string; | ||
userAgent?: string; | ||
options: ValidatedOptions; | ||
constructor(options?: Options); | ||
@@ -22,0 +23,0 @@ /** |
@@ -30,3 +30,3 @@ "use strict"; | ||
constructor(options) { | ||
var _a; | ||
var _a, _b; | ||
/** | ||
@@ -563,12 +563,15 @@ * accounts - Obtain information about a specific stake account. | ||
this.txSubmit = txs_1.txSubmit; | ||
const opts = utils_1.validateOptions(options); | ||
const apiBase = opts.isTestnet ? config_1.API_URLS.testnet : config_1.API_URLS.mainnet; | ||
this.apiUrl = (options === null || options === void 0 ? void 0 : options.customBackend) || url_join_1.default(apiBase, `v${opts.version}`); | ||
this.projectId = opts.projectId; | ||
this.options = utils_1.validateOptions(options); | ||
const apiBase = this.options.isTestnet | ||
? config_1.API_URLS.testnet | ||
: config_1.API_URLS.mainnet; | ||
this.apiUrl = | ||
((_a = this.options) === null || _a === void 0 ? void 0 : _a.customBackend) || url_join_1.default(apiBase, `v${this.options.version}`); | ||
this.projectId = this.options.projectId; | ||
this.userAgent = | ||
(_a = options === null || options === void 0 ? void 0 : options.userAgent) !== null && _a !== void 0 ? _a : `${packageJson.name}@${packageJson.version}`; | ||
if (opts.retry429) { | ||
(_b = options === null || options === void 0 ? void 0 : options.userAgent) !== null && _b !== void 0 ? _b : `${packageJson.name}@${packageJson.version}`; | ||
if (this.options.retry429) { | ||
axios_retry_1.default(axios_1.default, { | ||
retries: 20, | ||
retryDelay: () => 1000, | ||
retries: this.options.retryCount, | ||
retryDelay: () => this.options.retryDelay, | ||
retryCondition: err => { | ||
@@ -580,4 +583,5 @@ var _a; | ||
} | ||
axios_1.default.defaults.timeout = this.options.requestTimeout; | ||
} | ||
} | ||
exports.BlockFrostAPI = BlockFrostAPI; |
@@ -15,2 +15,5 @@ import { AxiosError } from 'axios'; | ||
userAgent?: string; | ||
requestTimeout?: number; | ||
retryCount?: number; | ||
retryDelay?: number; | ||
}; | ||
@@ -24,2 +27,5 @@ export declare type Options = (OptionCombination1 | OptionCombination2) & AdditionalOptions; | ||
retry429: boolean; | ||
requestTimeout: number; | ||
retryCount: number; | ||
retryDelay: number; | ||
} | ||
@@ -26,0 +32,0 @@ export interface Headers { |
@@ -6,2 +6,3 @@ "use strict"; | ||
const validateOptions = (options) => { | ||
var _a, _b, _c; | ||
if (!options || (!options.customBackend && !options.projectId)) { | ||
@@ -16,2 +17,11 @@ throw Error('Missing customBackend or projectId option'); | ||
} | ||
if (options.requestTimeout && isNaN(options.requestTimeout)) { | ||
throw Error('Param requestTimeout is not a number'); | ||
} | ||
if (options.retryDelay && isNaN(options.retryDelay)) { | ||
throw Error('Param retryDelay is not a number'); | ||
} | ||
if (options.retryCount && isNaN(options.retryCount)) { | ||
throw Error('Param retryCount is not a number'); | ||
} | ||
return { | ||
@@ -23,2 +33,5 @@ customBackend: options.customBackend, | ||
retry429: options.retry429 || true, | ||
retryCount: (_a = options.retryCount) !== null && _a !== void 0 ? _a : 20, | ||
retryDelay: (_b = options.retryDelay) !== null && _b !== void 0 ? _b : 1000, | ||
requestTimeout: (_c = options.requestTimeout) !== null && _c !== void 0 ? _c : 20000, // 20 seconds | ||
}; | ||
@@ -44,2 +57,3 @@ }; | ||
const handleError = (error) => { | ||
var _a, _b, _c; | ||
if (error.code && error.errno) { | ||
@@ -54,10 +68,29 @@ // system errors such as -3008 ENOTFOUND | ||
if (error.response) { | ||
return error.response.data; | ||
if (typeof error.response.data === 'object' && | ||
((_a = error.response.data) === null || _a === void 0 ? void 0 : _a.status_code)) { | ||
// response.data is already properly formatted | ||
return error.response.data; | ||
} | ||
// response.data may contain html output (eg. errors returned by nginx) | ||
const statusCode = error.response.status; | ||
const statusText = error.response.statusText; | ||
return { | ||
status_code: statusCode, | ||
message: `${statusCode}: ${statusText}`, | ||
error: statusText, | ||
}; | ||
} | ||
else if (error.request) { | ||
return error.request.data; | ||
const jsonError = error.toJSON(); | ||
const message = (_b = jsonError.message) !== null && _b !== void 0 ? _b : 'Unexpected error while sending a request'; | ||
const errorName = (_c = jsonError.error) !== null && _c !== void 0 ? _c : 'Error'; | ||
return `${errorName}: ${message}`; | ||
} | ||
else { | ||
else if (error.message) { | ||
return error.message; | ||
} | ||
else { | ||
// we shouldn't get here, but just to be safe... | ||
return 'Unexpected error'; | ||
} | ||
}; | ||
@@ -64,0 +97,0 @@ exports.handleError = handleError; |
{ | ||
"name": "@blockfrost/blockfrost-js", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "A JavaScript/TypeScript SDK for interacting with the https://blockfrost.io API", | ||
@@ -27,7 +27,7 @@ "files": [ | ||
"dependencies": { | ||
"@blockfrost/openapi": "^0.1.19", | ||
"@yarnpkg/pnpify": "^2.4.0", | ||
"@blockfrost/openapi": "^0.1.21", | ||
"@yarnpkg/pnpify": "3.0.0-rc.6", | ||
"axios": "^0.21.1", | ||
"axios-retry": "^3.1.9", | ||
"dotenv": "^8.2.0", | ||
"dotenv": "^10.0.0", | ||
"rimraf": "^3.0.2", | ||
@@ -37,23 +37,23 @@ "url-join": "^4.0.1" | ||
"devDependencies": { | ||
"@types/jest": "^26.0.22", | ||
"@types/node": "^14.14.37", | ||
"@types/jest": "^26.0.23", | ||
"@types/node": "^15.12.4", | ||
"@types/url-join": "^4.0.0", | ||
"@typescript-eslint/eslint-plugin": "^4.21.0", | ||
"@typescript-eslint/parser": "4.21.0", | ||
"@typescript-eslint/eslint-plugin": "^4.28.0", | ||
"@typescript-eslint/parser": "4.28.0", | ||
"babel-plugin-module-resolver": "^4.1.0", | ||
"eslint": "7.14.0", | ||
"eslint": "7.29.0", | ||
"eslint-config-airbnb-base": "14.2.1", | ||
"eslint-config-prettier": "6.15.0", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-prettier": "3.1.4", | ||
"jest": "^26.6.3", | ||
"openapi-typescript": "^3.0.1", | ||
"prettier": "2.2.0", | ||
"ts-jest": "^26.4.4", | ||
"ts-node": "9.0.0", | ||
"ts-node-dev": "^1.0.0", | ||
"tsc-watch": "^4.2.8", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-import": "2.23.4", | ||
"eslint-plugin-prettier": "3.4.0", | ||
"jest": "^27.0.5", | ||
"openapi-typescript": "^4.0.1", | ||
"prettier": "2.3.1", | ||
"ts-jest": "^27.0.3", | ||
"ts-node": "10.0.0", | ||
"ts-node-dev": "^1.1.6", | ||
"tsc-watch": "^4.4.0", | ||
"tsconfig-paths": "^3.9.0", | ||
"typedoc": "^0.20.35", | ||
"typescript": "4.2.3" | ||
"typedoc": "^0.21.0", | ||
"typescript": "4.3.4" | ||
}, | ||
@@ -60,0 +60,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
214727
5511
+ Added@chevrotain/types@9.1.0(transitive)
+ Added@chevrotain/utils@9.1.0(transitive)
+ Added@types/node@22.9.4(transitive)
+ Added@yarnpkg/core@3.7.0(transitive)
+ Added@yarnpkg/pnpify@3.0.0-rc.6(transitive)
+ Added@yarnpkg/shell@3.3.0(transitive)
+ Addedchevrotain@9.1.0(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedclipanion@3.2.0-rc.43.2.1(transitive)
+ Addeddiff@5.2.0(transitive)
+ Addeddotenv@10.0.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedregexp-to-ast@0.5.0(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtinylogic@1.0.3(transitive)
+ Addedtypanion@3.14.0(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedyallist@4.0.0(transitive)
- Removed@types/node@13.13.52(transitive)
- Removed@yarnpkg/core@2.4.0(transitive)
- Removed@yarnpkg/json-proxy@2.1.1(transitive)
- Removed@yarnpkg/pnp@2.3.2(transitive)
- Removed@yarnpkg/pnpify@2.4.0(transitive)
- Removed@yarnpkg/shell@2.4.1(transitive)
- Removedany-promise@1.3.0(transitive)
- Removedasap@2.0.6(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbinjumper@0.1.4(transitive)
- Removedbl@4.1.0(transitive)
- Removedbuffer@5.7.1(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedci-info@2.0.0(transitive)
- Removedclipanion@2.6.2(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removeddotenv@8.6.0(transitive)
- Removedend-of-stream@1.1.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfs-constants@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedieee754@1.2.1(transitive)
- Removedis@3.3.0(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedjson-file-plus@3.3.1(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removednode.extend@2.0.3(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedonce@1.3.3(transitive)
- Removedpluralize@7.0.0(transitive)
- Removedpretty-bytes@5.6.0(transitive)
- Removedpromise@8.3.0(transitive)
- Removedpromise-deferred@2.0.4(transitive)
- Removedpromiseback@2.0.3(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedstream-buffers@3.0.3(transitive)
- Removedstream-to-array@2.3.0(transitive)
- Removedstream-to-promise@2.2.0(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedtar-stream@2.2.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
Updated@blockfrost/openapi@^0.1.21
Updated@yarnpkg/pnpify@3.0.0-rc.6
Updateddotenv@^10.0.0