Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethersproject/web

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/web - npm Package Compare versions

Comparing version 5.0.0-beta.124 to 5.0.0-beta.125

2

_version.d.ts

@@ -1,1 +0,1 @@

export declare const version = "5.0.0-beta.124";
export declare const version = "5.0.0-beta.125";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.version = "5.0.0-beta.124";
exports.version = "5.0.0-beta.125";

@@ -5,3 +5,3 @@ export declare type ConnectionInfo = {

password?: string;
allowInsecure?: boolean;
allowInsecureAuthentication?: boolean;
timeout?: number;

@@ -8,0 +8,0 @@ headers?: {

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -10,3 +13,3 @@ if (mod && mod.__esModule) return mod;

Object.defineProperty(exports, "__esModule", { value: true });
var xmlhttprequest_1 = require("xmlhttprequest");
var cross_fetch_1 = __importDefault(require("cross-fetch"));
var base64_1 = require("@ethersproject/base64");

@@ -19,2 +22,11 @@ var errors = __importStar(require("@ethersproject/errors"));

var url = null;
// @TODO: Allow ConnectionInfo to override some of these values
var options = {
method: "GET",
mode: "cors",
cache: "no-cache",
credentials: "same-origin",
redirect: "follow",
referrer: "client",
};
var timeout = 2 * 60 * 1000;

@@ -25,4 +37,4 @@ if (typeof (connection) === "string") {

else if (typeof (connection) === "object") {
if (connection.url == null) {
errors.throwError("missing URL", errors.MISSING_ARGUMENT, { arg: "url" });
if (connection == null || connection.url == null) {
errors.throwArgumentError("missing URL", "connection.url", connection);
}

@@ -39,3 +51,3 @@ url = connection.url;

if (connection.user != null && connection.password != null) {
if (url.substring(0, 6) !== "https:" && connection.allowInsecure !== true) {
if (url.substring(0, 6) !== "https:" && connection.allowInsecureAuthentication !== true) {
errors.throwError("basic authentication requires a secure https url", errors.INVALID_ARGUMENT, { arg: "url", url: url, user: connection.user, password: "[REDACTED]" });

@@ -51,14 +63,15 @@ }

return new Promise(function (resolve, reject) {
var request = new xmlhttprequest_1.XMLHttpRequest();
var timer = null;
timer = setTimeout(function () {
if (timer == null) {
return;
}
timer = null;
reject(new Error("timeout"));
setTimeout(function () {
request.abort();
}, 0);
}, timeout);
if (timeout) {
timer = setTimeout(function () {
if (timer == null) {
return;
}
timer = null;
reject(errors.makeError("timeout", errors.TIMEOUT, {}));
//setTimeout(() => {
// request.abort();
//}, 0);
}, timeout);
}
var cancelTimeout = function () {

@@ -72,79 +85,57 @@ if (timer == null) {

if (json) {
request.open("POST", url, true);
options.method = "POST";
options.body = json;
headers["content-type"] = { key: "Content-Type", value: "application/json" };
}
else {
request.open("GET", url, true);
}
var flatHeaders = {};
Object.keys(headers).forEach(function (key) {
var header = headers[key];
request.setRequestHeader(header.key, header.value);
flatHeaders[header.key] = header.value;
});
request.onreadystatechange = function () {
if (request.readyState !== 4) {
return;
}
if (request.status != 200) {
cancelTimeout();
// @TODO: not any!
var error = new Error("invalid response - " + request.status);
error.statusCode = request.status;
if (request.responseText) {
error.responseText = request.responseText;
options.headers = flatHeaders;
return cross_fetch_1.default(url, options).then(function (response) {
return response.text().then(function (body) {
if (!response.ok) {
errors.throwError("bad response", errors.SERVER_ERROR, {
status: response.status,
body: body,
type: response.type,
url: response.url
});
}
reject(error);
return;
}
var result = null;
return body;
});
}).then(function (text) {
var json = null;
try {
result = JSON.parse(request.responseText);
json = JSON.parse(text);
}
catch (error) {
cancelTimeout();
// @TODO: not any!
var jsonError = new Error("invalid json response");
jsonError.orginialError = error;
jsonError.responseText = request.responseText;
if (json != null) {
jsonError.requestBody = json;
}
jsonError.url = url;
reject(jsonError);
return;
errors.throwError("invalid JSON", errors.SERVER_ERROR, {
body: text,
error: error,
url: url
});
}
if (processFunc) {
try {
result = processFunc(result);
json = processFunc(json);
}
catch (error) {
cancelTimeout();
error.url = url;
error.body = json;
error.responseText = request.responseText;
reject(error);
return;
errors.throwError("processing response error", errors.SERVER_ERROR, {
body: json,
error: error
});
}
}
return json;
}, function (error) {
throw error;
}).then(function (result) {
cancelTimeout();
resolve(result);
};
request.onerror = function (error) {
}, function (error) {
cancelTimeout();
reject(error);
};
try {
if (json != null) {
request.send(json);
}
else {
request.send();
}
}
catch (error) {
cancelTimeout();
// @TODO: not any!
var connectionError = new Error("connection error");
connectionError.error = error;
reject(connectionError);
}
});
});

@@ -151,0 +142,0 @@ }

{
"name": "@ethersproject/web",
"version": "5.0.0-beta.124",
"version": "5.0.0-beta.125",
"description": "Error utility functions for ethers.",
"main": "index.js",
"browser": {
"xmlhttprequest": "./browser-xmlhttprequest.js"
},
"scripts": {

@@ -17,3 +14,3 @@ "test": "echo \"Error: no test specified\" && exit 1"

"@ethersproject/strings": ">5.0.0-beta.0",
"xmlhttprequest": "1.8.0"
"cross-fetch": "3.0.4"
},

@@ -29,3 +26,3 @@ "keywords": [

},
"tarballHash": "0x99cdd9c80d988aedf6bedc30316fb519b36b4c86aadb4fd0fe6f6bf71bb2c138"
"tarballHash": "0x0f9e617f859e6d9d0dbd16146a9653390219cf5aadd418030212b804f16a3af4"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc