@near-js/providers
Advanced tools
Comparing version 0.0.7 to 0.0.8
export declare function exponentialBackoff(startWaitTime: any, retryNumber: any, waitBackoff: any, getResult: any): Promise<any>; | ||
//# sourceMappingURL=exponential-backoff.d.ts.map |
@@ -12,1 +12,2 @@ export interface ConnectionInfo { | ||
export declare function fetchJson(connectionInfoOrUrl: string | ConnectionInfo, json?: string): Promise<any>; | ||
//# sourceMappingURL=fetch_json.d.ts.map |
@@ -40,2 +40,3 @@ "use strict"; | ||
const types_1 = require("@near-js/types"); | ||
const utils_1 = require("@near-js/utils"); | ||
const http_errors_1 = __importDefault(require("http-errors")); | ||
@@ -46,3 +47,2 @@ const exponential_backoff_1 = require("./exponential-backoff"); | ||
const RETRY_NUMBER = 10; | ||
const logWarning = (...args) => !process.env['NEAR_NO_LOGS'] && console.warn(...args); | ||
function fetchJson(connectionInfoOrUrl, json) { | ||
@@ -58,7 +58,5 @@ return __awaiter(this, void 0, void 0, function* () { | ||
const response = yield (0, exponential_backoff_1.exponentialBackoff)(START_WAIT_TIME_MS, RETRY_NUMBER, BACKOFF_MULTIPLIER, () => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
try { | ||
if (!global.fetch) { | ||
global.fetch = (yield Promise.resolve().then(() => __importStar(require('./fetch')))).default; | ||
} | ||
const response = yield global.fetch(connectionInfo.url, { | ||
const response = yield ((_a = global.fetch) !== null && _a !== void 0 ? _a : (yield Promise.resolve().then(() => __importStar(require('./fetch')))).default)(connectionInfo.url, { | ||
method: json ? 'POST' : 'GET', | ||
@@ -70,5 +68,9 @@ body: json ? json : undefined, | ||
if (response.status === 503) { | ||
logWarning(`Retrying HTTP request for ${connectionInfo.url} as it's not available now`); | ||
utils_1.Logger.warn(`Retrying HTTP request for ${connectionInfo.url} as it's not available now`); | ||
return null; | ||
} | ||
else if (response.status === 408) { | ||
utils_1.Logger.warn(`Retrying HTTP request for ${connectionInfo.url} as the previous connection was unused for some time`); | ||
return null; | ||
} | ||
throw (0, http_errors_1.default)(response.status, yield response.text()); | ||
@@ -80,3 +82,3 @@ } | ||
if (error.toString().includes('FetchError') || error.toString().includes('Failed to fetch')) { | ||
logWarning(`Retrying HTTP request for ${connectionInfo.url} because of error: ${error}`); | ||
utils_1.Logger.warn(`Retrying HTTP request for ${connectionInfo.url} because of error: ${error}`); | ||
return null; | ||
@@ -83,0 +85,0 @@ } |
export default function (resource: any, init: any): any; | ||
//# sourceMappingURL=fetch.d.ts.map |
@@ -5,1 +5,2 @@ export { exponentialBackoff } from './exponential-backoff'; | ||
export { fetchJson } from './fetch_json'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -54,3 +54,3 @@ import { AccessKeyWithPublicKey, BlockId, BlockReference, BlockResult, BlockChangeResult, ChangeResult, ChunkId, ChunkResult, EpochValidatorInfo, FinalExecutionOutcome, GasPrice, LightClientProof, LightClientProofRequest, NextLightClientBlockRequest, NextLightClientBlockResponse, NearProtocolConfig, NodeStatusResult, QueryResponseKind } from '@near-js/types'; | ||
/** | ||
* Query the RPC by passing an {@link providers/provider!RpcQueryRequest} | ||
* Query the RPC by passing an {@link "@near-js/types".provider/request.RpcQueryRequest | RpcQueryRequest } | ||
* @see [https://docs.near.org/api/rpc/contracts](https://docs.near.org/api/rpc/contracts) | ||
@@ -66,3 +66,3 @@ * | ||
* | ||
* @param blockQuery {@link providers/provider!BlockReference} (passing a {@link providers/provider!BlockId} is deprecated) | ||
* @param blockQuery {@link BlockReference} (passing a {@link BlockId} is deprecated) | ||
*/ | ||
@@ -162,1 +162,2 @@ block(blockQuery: BlockId | BlockReference): Promise<BlockResult>; | ||
} | ||
//# sourceMappingURL=json-rpc-provider.d.ts.map |
@@ -29,3 +29,3 @@ "use strict"; | ||
* which can be used to interact with the [NEAR RPC API](https://docs.near.org/api/rpc/introduction). | ||
* @see {@link providers/provider | providers} for a list of request and response types | ||
* @see {@link "@near-js/types".provider | provider} for a list of request and response types | ||
*/ | ||
@@ -35,3 +35,2 @@ const utils_1 = require("@near-js/utils"); | ||
const transactions_1 = require("@near-js/transactions"); | ||
const borsh_1 = require("borsh"); | ||
const exponential_backoff_1 = require("./exponential-backoff"); | ||
@@ -113,3 +112,3 @@ const provider_1 = require("./provider"); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.sendJsonRpc('tx', [(0, borsh_1.baseEncode)(txHash), accountId]); | ||
return this.sendJsonRpc('tx', [(0, utils_1.baseEncode)(txHash), accountId]); | ||
}); | ||
@@ -135,3 +134,3 @@ } | ||
else { | ||
return this.sendJsonRpc('EXPERIMENTAL_tx_status', [(0, borsh_1.baseEncode)(txHash), accountId]); | ||
return this.sendJsonRpc('EXPERIMENTAL_tx_status', [(0, utils_1.baseEncode)(txHash), accountId]); | ||
} | ||
@@ -141,3 +140,3 @@ }); | ||
/** | ||
* Query the RPC by passing an {@link providers/provider!RpcQueryRequest} | ||
* Query the RPC by passing an {@link "@near-js/types".provider/request.RpcQueryRequest | RpcQueryRequest } | ||
* @see [https://docs.near.org/api/rpc/contracts](https://docs.near.org/api/rpc/contracts) | ||
@@ -169,3 +168,3 @@ * | ||
* | ||
* @param blockQuery {@link providers/provider!BlockReference} (passing a {@link providers/provider!BlockId} is deprecated) | ||
* @param blockQuery {@link BlockReference} (passing a {@link BlockId} is deprecated) | ||
*/ | ||
@@ -389,5 +388,3 @@ block(blockQuery) { | ||
if (error.type === 'TimeoutError') { | ||
if (!process.env['NEAR_NO_LOGS']) { | ||
console.warn(`Retrying request to ${method} as it has timed out`, params); | ||
} | ||
utils_1.Logger.warn(`Retrying request to ${method} as it has timed out`, params); | ||
return null; | ||
@@ -394,0 +391,0 @@ } |
@@ -30,1 +30,2 @@ /** | ||
} | ||
//# sourceMappingURL=provider.d.ts.map |
{ | ||
"name": "@near-js/providers", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Library of implementations for interfacing with the NEAR blockchain", | ||
@@ -11,16 +11,16 @@ "main": "lib/index.js", | ||
"bn.js": "5.2.1", | ||
"borsh": "^0.7.0", | ||
"http-errors": "^1.7.2", | ||
"@near-js/transactions": "0.2.1", | ||
"borsh": "1.0.0", | ||
"http-errors": "1.7.2", | ||
"@near-js/transactions": "1.0.0", | ||
"@near-js/types": "0.0.4", | ||
"@near-js/utils": "0.0.4" | ||
"@near-js/utils": "0.0.5" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.11.18", | ||
"jest": "^26.0.1", | ||
"ts-jest": "^26.5.6", | ||
"typescript": "^4.9.4" | ||
"@types/node": "18.11.18", | ||
"jest": "26.0.1", | ||
"ts-jest": "26.5.6", | ||
"typescript": "4.9.4" | ||
}, | ||
"optionalDependencies": { | ||
"node-fetch": "^2.6.1" | ||
"node-fetch": "2.6.7" | ||
}, | ||
@@ -27,0 +27,0 @@ "files": [ |
@@ -7,6 +7,6 @@ # @near-js/providers | ||
- [Provider](src/provider.ts) abstract class for interacting with NEAR RPC | ||
- [JsonRpcProvider](src/json-rpc-provider.ts) implementation of `Provider` for [JSON-RPC](https://www.jsonrpc.org/) | ||
- [fetch](src/fetch.ts) NodeJS `fetch` implementation | ||
- [fetchJson](src/fetch_json.ts) low-level function for fetching and parsing RPC data | ||
- [Provider](https://github.com/near/near-api-js/blob/master/packages/providers/src/provider.ts) abstract class for interacting with NEAR RPC | ||
- [JsonRpcProvider](https://github.com/near/near-api-js/blob/master/packages/providers/src/json-rpc-provider.ts) implementation of `Provider` for [JSON-RPC](https://www.jsonrpc.org/) | ||
- [fetch](https://github.com/near/near-api-js/blob/master/packages/providers/src/fetch.ts) NodeJS `fetch` implementation | ||
- [fetchJson](https://github.com/near/near-api-js/blob/master/packages/providers/src/fetch_json.ts) low-level function for fetching and parsing RPC data | ||
@@ -13,0 +13,0 @@ # License |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
47650
21
1
773
+ Added@near-js/crypto@1.0.0(transitive)
+ Added@near-js/keystores@0.0.6(transitive)
+ Added@near-js/signers@0.0.6(transitive)
+ Added@near-js/transactions@1.0.0(transitive)
+ Added@near-js/utils@0.0.5(transitive)
+ Added@noble/curves@1.2.0(transitive)
+ Added@noble/hashes@1.3.2(transitive)
+ Addedbase-x@2.0.6(transitive)
+ Addedborsh@1.0.0(transitive)
+ Addedbs58@4.0.0(transitive)
+ Addedhttp-errors@1.7.2(transitive)
+ Addedinherits@2.0.3(transitive)
+ Addedmustache@4.0.0(transitive)
+ Addednode-fetch@2.6.7(transitive)
+ Addedsetprototypeof@1.1.1(transitive)
+ Addedtoidentifier@1.0.0(transitive)
- Removed@near-js/crypto@0.0.5(transitive)
- Removed@near-js/keystores@0.0.5(transitive)
- Removed@near-js/signers@0.0.5(transitive)
- Removed@near-js/transactions@0.2.1(transitive)
- Removed@near-js/utils@0.0.4(transitive)
- Removedbase-x@3.0.10(transitive)
- Removedborsh@0.7.0(transitive)
- Removedbs58@4.0.1(transitive)
- Removedhttp-errors@1.8.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmustache@4.2.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedsetprototypeof@1.2.0(transitive)
- Removedtext-encoding-utf-8@1.0.2(transitive)
- Removedtoidentifier@1.0.1(transitive)
- Removedtweetnacl@1.0.3(transitive)
Updated@near-js/transactions@1.0.0
Updated@near-js/utils@0.0.5
Updatedborsh@1.0.0
Updatedhttp-errors@1.7.2