web3-providers
Advanced tools
Comparing version 1.0.0-beta.50 to 1.0.0-beta.51
@@ -486,3 +486,7 @@ 'use strict'; | ||
} | ||
_this3.connection.send(JSON.stringify(payload)); | ||
try { | ||
_this3.connection.send(JSON.stringify(payload)); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
if (_this3.timeout) { | ||
@@ -506,5 +510,4 @@ timeout = setTimeout(function () { | ||
} | ||
_this3.on('connect', function () { | ||
_this3.once('connect', function () { | ||
_this3.sendPayload(payload).then(resolve).catch(reject); | ||
_this3.removeAllListeners('connect'); | ||
}); | ||
@@ -530,3 +533,3 @@ }); | ||
_this.host = path; | ||
_this.chunks = ''; | ||
_this.lastChunk = ''; | ||
return _this; | ||
@@ -549,9 +552,27 @@ } | ||
value: function onMessage(message) { | ||
var chunk = message.toString('utf8'); | ||
if (chunk.indexOf('\n') < 0) { | ||
this.chunks += chunk; | ||
return; | ||
} | ||
_get(_getPrototypeOf(IpcProvider.prototype), "onMessage", this).call(this, this.chunks + chunk.substring(0, chunk.indexOf('\n'))); | ||
this.chunks = chunk.substring(chunk.indexOf('\n') + 1); | ||
var _this2 = this; | ||
var result = null; | ||
var returnValues = []; | ||
var dechunkedData = message.toString().replace(/\}[\n\r]?\{/g, '}|--|{') | ||
.replace(/\}\][\n\r]?\[\{/g, '}]|--|[{') | ||
.replace(/\}[\n\r]?\[\{/g, '}|--|[{') | ||
.replace(/\}\][\n\r]?\{/g, '}]|--|{') | ||
.split('|--|'); | ||
dechunkedData.forEach(function (data) { | ||
result = null; | ||
if (_this2.lastChunk) { | ||
data = _this2.lastChunk + data; | ||
} | ||
try { | ||
result = JSON.parse(data); | ||
} catch (error) { | ||
_this2.lastChunk = data; | ||
return; | ||
} | ||
_this2.lastChunk = null; | ||
returnValues.push(result); | ||
}); | ||
returnValues.forEach(function (chunk) { | ||
_get(_getPrototypeOf(IpcProvider.prototype), "onMessage", _this2).call(_this2, chunk); | ||
}); | ||
} | ||
@@ -593,10 +614,10 @@ }, { | ||
value: function sendPayload(payload) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
return new Promise(function (resolve, reject) { | ||
if (!_this2.connection.writable) { | ||
_this2.connection.connect({ | ||
path: _this2.path | ||
if (!_this3.connection.writable) { | ||
_this3.connection.connect({ | ||
path: _this3.path | ||
}); | ||
} | ||
if (_this2.connection.write(JSON.stringify(payload))) { | ||
if (_this3.connection.write(JSON.stringify(payload))) { | ||
var id; | ||
@@ -608,3 +629,3 @@ if (isArray(payload)) { | ||
} | ||
_this2.once(id, resolve); | ||
_this3.once(id, resolve); | ||
return; | ||
@@ -634,2 +655,3 @@ } | ||
this.headers = options.headers; | ||
this.withCredentials = options.withCredentials || false; | ||
this.connected = true; | ||
@@ -716,3 +738,3 @@ this.providersModuleFactory = providersModuleFactory; | ||
return new Promise(function (resolve, reject) { | ||
var request = _this.providersModuleFactory.createXMLHttpRequest(_this.host, _this.timeout, _this.headers, _this.agent); | ||
var request = _this.providersModuleFactory.createXMLHttpRequest(_this.host, _this.timeout, _this.headers, _this.agent, _this.withCredentials); | ||
request.onreadystatechange = function () { | ||
@@ -1202,12 +1224,14 @@ if (request.readyState !== 0 && request.readyState !== 1) { | ||
key: "createXMLHttpRequest", | ||
value: function createXMLHttpRequest(host) { | ||
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var headers = arguments.length > 2 ? arguments[2] : undefined; | ||
var agent = arguments.length > 3 ? arguments[3] : undefined; | ||
var request = new xhr2Cookies.XMLHttpRequest(); | ||
request.nodejsSet(agent); | ||
value: function createXMLHttpRequest(host, timeout, headers, agent, withCredentials) { | ||
var request; | ||
if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) { | ||
request = new xhr2Cookies.XMLHttpRequest(); | ||
request.nodejsSet(agent); | ||
} else { | ||
request = new XMLHttpRequest(); | ||
} | ||
request.open('POST', host, true); | ||
request.setRequestHeader('Content-Type', 'application/json'); | ||
request.timeout = timeout; | ||
request.withCredentials = true; | ||
request.withCredentials = withCredentials; | ||
if (headers) { | ||
@@ -1214,0 +1238,0 @@ headers.forEach(function (header) { |
import { w3cwebsocket } from 'websocket'; | ||
import { XMLHttpRequest } from 'xhr2-cookies'; | ||
import { XMLHttpRequest as XMLHttpRequest$1 } from 'xhr2-cookies'; | ||
import URL from 'url-parse'; | ||
@@ -315,3 +315,7 @@ import isFunction from 'lodash/isFunction'; | ||
} | ||
this.connection.send(JSON.stringify(payload)); | ||
try { | ||
this.connection.send(JSON.stringify(payload)); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
if (this.timeout) { | ||
@@ -335,5 +339,4 @@ timeout = setTimeout(() => { | ||
} | ||
this.on('connect', () => { | ||
this.once('connect', () => { | ||
this.sendPayload(payload).then(resolve).catch(reject); | ||
this.removeAllListeners('connect'); | ||
}); | ||
@@ -348,3 +351,3 @@ }); | ||
this.host = path; | ||
this.chunks = ''; | ||
this.lastChunk = ''; | ||
} | ||
@@ -363,9 +366,26 @@ disconnect() { | ||
onMessage(message) { | ||
const chunk = message.toString('utf8'); | ||
if (chunk.indexOf('\n') < 0) { | ||
this.chunks += chunk; | ||
return; | ||
} | ||
super.onMessage(this.chunks + chunk.substring(0, chunk.indexOf('\n'))); | ||
this.chunks = chunk.substring(chunk.indexOf('\n') + 1); | ||
let result = null; | ||
let returnValues = []; | ||
let dechunkedData = message.toString().replace(/\}[\n\r]?\{/g, '}|--|{') | ||
.replace(/\}\][\n\r]?\[\{/g, '}]|--|[{') | ||
.replace(/\}[\n\r]?\[\{/g, '}|--|[{') | ||
.replace(/\}\][\n\r]?\{/g, '}]|--|{') | ||
.split('|--|'); | ||
dechunkedData.forEach(data => { | ||
result = null; | ||
if (this.lastChunk) { | ||
data = this.lastChunk + data; | ||
} | ||
try { | ||
result = JSON.parse(data); | ||
} catch (error) { | ||
this.lastChunk = data; | ||
return; | ||
} | ||
this.lastChunk = null; | ||
returnValues.push(result); | ||
}); | ||
returnValues.forEach(chunk => { | ||
super.onMessage(chunk); | ||
}); | ||
} | ||
@@ -427,2 +447,3 @@ registerEventListeners() { | ||
this.headers = options.headers; | ||
this.withCredentials = options.withCredentials || false; | ||
this.connected = true; | ||
@@ -472,3 +493,3 @@ this.providersModuleFactory = providersModuleFactory; | ||
return new Promise((resolve, reject) => { | ||
const request = this.providersModuleFactory.createXMLHttpRequest(this.host, this.timeout, this.headers, this.agent); | ||
const request = this.providersModuleFactory.createXMLHttpRequest(this.host, this.timeout, this.headers, this.agent, this.withCredentials); | ||
request.onreadystatechange = () => { | ||
@@ -802,9 +823,14 @@ if (request.readyState !== 0 && request.readyState !== 1) { | ||
} | ||
createXMLHttpRequest(host, timeout = 0, headers, agent) { | ||
const request = new XMLHttpRequest(); | ||
request.nodejsSet(agent); | ||
createXMLHttpRequest(host, timeout, headers, agent, withCredentials) { | ||
let request; | ||
if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) { | ||
request = new XMLHttpRequest$1(); | ||
request.nodejsSet(agent); | ||
} else { | ||
request = new XMLHttpRequest(); | ||
} | ||
request.open('POST', host, true); | ||
request.setRequestHeader('Content-Type', 'application/json'); | ||
request.timeout = timeout; | ||
request.withCredentials = true; | ||
request.withCredentials = withCredentials; | ||
if (headers) { | ||
@@ -811,0 +837,0 @@ headers.forEach(header => { |
@@ -484,3 +484,7 @@ (function (global, factory) { | ||
} | ||
_this3.connection.send(JSON.stringify(payload)); | ||
try { | ||
_this3.connection.send(JSON.stringify(payload)); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
if (_this3.timeout) { | ||
@@ -504,5 +508,4 @@ timeout = setTimeout(function () { | ||
} | ||
_this3.on('connect', function () { | ||
_this3.once('connect', function () { | ||
_this3.sendPayload(payload).then(resolve).catch(reject); | ||
_this3.removeAllListeners('connect'); | ||
}); | ||
@@ -528,3 +531,3 @@ }); | ||
_this.host = path; | ||
_this.chunks = ''; | ||
_this.lastChunk = ''; | ||
return _this; | ||
@@ -547,9 +550,27 @@ } | ||
value: function onMessage(message) { | ||
var chunk = message.toString('utf8'); | ||
if (chunk.indexOf('\n') < 0) { | ||
this.chunks += chunk; | ||
return; | ||
} | ||
_get(_getPrototypeOf(IpcProvider.prototype), "onMessage", this).call(this, this.chunks + chunk.substring(0, chunk.indexOf('\n'))); | ||
this.chunks = chunk.substring(chunk.indexOf('\n') + 1); | ||
var _this2 = this; | ||
var result = null; | ||
var returnValues = []; | ||
var dechunkedData = message.toString().replace(/\}[\n\r]?\{/g, '}|--|{') | ||
.replace(/\}\][\n\r]?\[\{/g, '}]|--|[{') | ||
.replace(/\}[\n\r]?\[\{/g, '}|--|[{') | ||
.replace(/\}\][\n\r]?\{/g, '}]|--|{') | ||
.split('|--|'); | ||
dechunkedData.forEach(function (data) { | ||
result = null; | ||
if (_this2.lastChunk) { | ||
data = _this2.lastChunk + data; | ||
} | ||
try { | ||
result = JSON.parse(data); | ||
} catch (error) { | ||
_this2.lastChunk = data; | ||
return; | ||
} | ||
_this2.lastChunk = null; | ||
returnValues.push(result); | ||
}); | ||
returnValues.forEach(function (chunk) { | ||
_get(_getPrototypeOf(IpcProvider.prototype), "onMessage", _this2).call(_this2, chunk); | ||
}); | ||
} | ||
@@ -591,10 +612,10 @@ }, { | ||
value: function sendPayload(payload) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
return new Promise(function (resolve, reject) { | ||
if (!_this2.connection.writable) { | ||
_this2.connection.connect({ | ||
path: _this2.path | ||
if (!_this3.connection.writable) { | ||
_this3.connection.connect({ | ||
path: _this3.path | ||
}); | ||
} | ||
if (_this2.connection.write(JSON.stringify(payload))) { | ||
if (_this3.connection.write(JSON.stringify(payload))) { | ||
var id; | ||
@@ -606,3 +627,3 @@ if (isArray(payload)) { | ||
} | ||
_this2.once(id, resolve); | ||
_this3.once(id, resolve); | ||
return; | ||
@@ -632,2 +653,3 @@ } | ||
this.headers = options.headers; | ||
this.withCredentials = options.withCredentials || false; | ||
this.connected = true; | ||
@@ -714,3 +736,3 @@ this.providersModuleFactory = providersModuleFactory; | ||
return new Promise(function (resolve, reject) { | ||
var request = _this.providersModuleFactory.createXMLHttpRequest(_this.host, _this.timeout, _this.headers, _this.agent); | ||
var request = _this.providersModuleFactory.createXMLHttpRequest(_this.host, _this.timeout, _this.headers, _this.agent, _this.withCredentials); | ||
request.onreadystatechange = function () { | ||
@@ -1200,12 +1222,14 @@ if (request.readyState !== 0 && request.readyState !== 1) { | ||
key: "createXMLHttpRequest", | ||
value: function createXMLHttpRequest(host) { | ||
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var headers = arguments.length > 2 ? arguments[2] : undefined; | ||
var agent = arguments.length > 3 ? arguments[3] : undefined; | ||
var request = new xhr2Cookies.XMLHttpRequest(); | ||
request.nodejsSet(agent); | ||
value: function createXMLHttpRequest(host, timeout, headers, agent, withCredentials) { | ||
var request; | ||
if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) { | ||
request = new xhr2Cookies.XMLHttpRequest(); | ||
request.nodejsSet(agent); | ||
} else { | ||
request = new XMLHttpRequest(); | ||
} | ||
request.open('POST', host, true); | ||
request.setRequestHeader('Content-Type', 'application/json'); | ||
request.timeout = timeout; | ||
request.withCredentials = true; | ||
request.withCredentials = withCredentials; | ||
if (headers) { | ||
@@ -1212,0 +1236,0 @@ headers.forEach(function (header) { |
{ | ||
"name": "web3-providers", | ||
"namespace": "ethereum", | ||
"version": "1.0.0-beta.50", | ||
"version": "1.0.0-beta.51", | ||
"description": "Web3 module to handle requests to external providers.", | ||
@@ -30,6 +30,6 @@ "repository": "https://github.com/ethereum/web3.js/tree/1.0/packages/web3-providers", | ||
"dtslint": "0.4.2", | ||
"web3-core": "1.0.0-beta.50", | ||
"web3-core-helpers": "1.0.0-beta.50", | ||
"web3-core-method": "1.0.0-beta.50", | ||
"web3-utils": "1.0.0-beta.50" | ||
"web3-core": "1.0.0-beta.51", | ||
"web3-core-helpers": "1.0.0-beta.51", | ||
"web3-core-method": "1.0.0-beta.51", | ||
"web3-utils": "1.0.0-beta.51" | ||
}, | ||
@@ -40,3 +40,3 @@ "files": [ | ||
], | ||
"gitHead": "90353080483037843a55874729a6f22ae9217539" | ||
"gitHead": "67468b3f923d85839fc06ff4eedbe553ba60c185" | ||
} |
@@ -62,8 +62,5 @@ # web3-providers | ||
```js | ||
import {ProvidersModuleFactory, BatchRequest} 'web3-providers; | ||
import {ProviderResolver, BatchRequest} 'web3-providers'; | ||
const provider = new ProvidersModuleFactory() | ||
.createProviderResolver | ||
.resolve('ws://localhost:8546'); | ||
const provider = new ProviderResolver().resolve('ws://localhost:8546'); | ||
const batchRequest = new BatchRequest(provider); | ||
@@ -84,6 +81,5 @@ | ||
```js | ||
import {ProvidersModuleFactory} from 'web3-providers'; | ||
import {ProviderDetector} from 'web3-providers'; | ||
const providerDetector = new ProvidersModuleFactory.createProviderDetector(); | ||
const givenProvider = providerDetector.detect(); | ||
const givenProvider = ProviderDetector.detect(); | ||
``` | ||
@@ -96,7 +92,5 @@ | ||
```js | ||
import {ProvidersModuleFactory} 'web3-providers; | ||
import {ProviderResolver} 'web3-providers'; | ||
const socketProviderAdapter = new ProvidersModuleFactory() | ||
.createProviderResolver | ||
.resolve('ws://localhost:8546'); | ||
const socketProviderAdapter = new ProviderResolver().resolve('ws://localhost:8546'); | ||
``` | ||
@@ -103,0 +97,0 @@ |
@@ -155,6 +155,12 @@ /* | ||
export interface HttpHeader { | ||
name: string; | ||
value: string; | ||
} | ||
export interface HttpProviderOptions { | ||
host?: string; | ||
timeout?: number; | ||
headers?: {}; | ||
headers?: HttpHeader[]; | ||
withCredentials?: boolean; | ||
} | ||
@@ -161,0 +167,0 @@ |
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
3647
139772
7
101