@eoscafe/light-api
Advanced tools
Comparing version 3.2.17 to 3.2.18
import { GetAccount, GetBalances, GetKeyAccounts, GetCodehash, GetAccountInfo } from "./types/api"; | ||
export declare type Fetch = (url: string | Request, init?: RequestInit) => Promise<Response>; | ||
/** | ||
@@ -15,13 +14,7 @@ * JsonRpc | ||
chain: string; | ||
fetchBuiltin: Fetch; | ||
timeout: number; | ||
constructor(chain: string, args?: { | ||
fetch?: Fetch; | ||
endpoint?: string; | ||
timeout?: number; | ||
}); | ||
fetchWithTimeout(resource: string, options: { | ||
[key: string]: any; | ||
timeout: number; | ||
}): Promise<Response>; | ||
/** | ||
@@ -28,0 +21,0 @@ * get |
@@ -68,5 +68,9 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var endpoints_1 = require("./endpoints"); | ||
var rpcerror_1 = require("./rpcerror"); | ||
var cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
var chainToEndpoint = { | ||
@@ -87,2 +91,20 @@ eos: "https://api.light.xeos.me", | ||
}; | ||
function fetchWithTimeout(resource, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var timeout, controller, id, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
timeout = options.timeout; | ||
controller = new AbortController(); | ||
id = setTimeout(function () { return controller.abort(); }, timeout); | ||
return [4 /*yield*/, cross_fetch_1.default(resource, __assign({}, (options || {}), { signal: controller.signal }))]; | ||
case 1: | ||
response = _a.sent(); | ||
clearTimeout(id); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
@@ -106,8 +128,2 @@ * JsonRpc | ||
} | ||
if (args.fetch) { | ||
this.fetchBuiltin = args.fetch; | ||
} | ||
else { | ||
this.fetchBuiltin = global.fetch; | ||
} | ||
if (args.timeout) { | ||
@@ -117,20 +133,2 @@ this.timeout = args.timeout; | ||
} | ||
JsonRpc.prototype.fetchWithTimeout = function (resource, options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var timeout, controller, id, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
timeout = options.timeout; | ||
controller = new AbortController(); | ||
id = setTimeout(function () { return controller.abort(); }, timeout); | ||
return [4 /*yield*/, this.fetchBuiltin(resource, __assign({}, (options || {}), { signal: controller.signal }))]; | ||
case 1: | ||
response = _a.sent(); | ||
clearTimeout(id); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
@@ -155,3 +153,3 @@ * get | ||
_a.trys.push([1, 4, , 5]); | ||
return [4 /*yield*/, this.fetchWithTimeout(url, { | ||
return [4 /*yield*/, fetchWithTimeout(url, { | ||
method: "GET", | ||
@@ -158,0 +156,0 @@ timeout: this.timeout |
{ | ||
"name": "@eoscafe/light-api", | ||
"version": "3.2.17", | ||
"version": "3.2.18", | ||
"description": "Light API HTTP Javascript library", | ||
@@ -42,3 +42,6 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "a1affc3ddd1c5626ac56d9e02a29a31683edea6d" | ||
"gitHead": "a1affc3ddd1c5626ac56d9e02a29a31683edea6d", | ||
"dependencies": { | ||
"cross-fetch": "^3.1.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
53183
1
773
+ Addedcross-fetch@^3.1.5
+ Addedcross-fetch@3.1.8(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)