Socket
Socket
Sign inDemoInstall

neo4j-driver

Package Overview
Dependencies
Maintainers
2
Versions
162
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neo4j-driver - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

7

lib/v1/index.js

@@ -151,3 +151,8 @@ 'use strict';

* // exponential backoff using initial delay of 1 second. Default value is 30000 which is 30 seconds.
* maxTransactionRetryTime: 30000,
* maxTransactionRetryTime: 30000, // 30 seconds
*
* // Specify socket connection timeout in milliseconds. Non-numeric, negative and zero values are treated as an
* // infinite timeout. Connection will be then bound by the timeout configured on the operating system level.
* // Timeout value should be numeric and greater or equal to zero.
* connectionTimeout: 5000, // 5 seconds
* }

@@ -154,0 +159,0 @@ *

90

lib/v1/internal/ch-config.js

@@ -11,6 +11,2 @@ 'use strict';

var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _features = require('./features');

@@ -43,47 +39,49 @@

var ChannelConfig = function () {
function ChannelConfig(host, port, driverConfig, connectionErrorCode) {
(0, _classCallCheck3.default)(this, ChannelConfig);
var DEFAULT_CONNECTION_TIMEOUT_MILLIS = 0; // turned off by default
this.host = host;
this.port = port;
this.encrypted = ChannelConfig._extractEncrypted(driverConfig);
this.trust = ChannelConfig._extractTrust(driverConfig);
this.trustedCertificates = ChannelConfig._extractTrustedCertificates(driverConfig);
this.knownHostsPath = ChannelConfig._extractKnownHostsPath(driverConfig);
this.connectionErrorCode = connectionErrorCode || _error.SERVICE_UNAVAILABLE;
var ChannelConfig = function ChannelConfig(host, port, driverConfig, connectionErrorCode) {
(0, _classCallCheck3.default)(this, ChannelConfig);
this.host = host;
this.port = port;
this.encrypted = extractEncrypted(driverConfig);
this.trust = extractTrust(driverConfig);
this.trustedCertificates = extractTrustedCertificates(driverConfig);
this.knownHostsPath = extractKnownHostsPath(driverConfig);
this.connectionErrorCode = connectionErrorCode || _error.SERVICE_UNAVAILABLE;
this.connectionTimeout = extractConnectionTimeout(driverConfig);
};
exports.default = ChannelConfig;
function extractEncrypted(driverConfig) {
// check if encryption was configured by the user, use explicit null check because we permit boolean value
var encryptionConfigured = driverConfig.encrypted == null;
// default to using encryption if trust-all-certificates is available
return encryptionConfigured ? (0, _features2.default)('trust_all_certificates') : driverConfig.encrypted;
}
function extractTrust(driverConfig) {
if (driverConfig.trust) {
return driverConfig.trust;
}
// default to using TRUST_ALL_CERTIFICATES if it is available
return (0, _features2.default)('trust_all_certificates') ? 'TRUST_ALL_CERTIFICATES' : 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES';
}
(0, _createClass3.default)(ChannelConfig, null, [{
key: '_extractEncrypted',
value: function _extractEncrypted(driverConfig) {
// check if encryption was configured by the user, use explicit null check because we permit boolean value
var encryptionConfigured = driverConfig.encrypted == null;
// default to using encryption if trust-all-certificates is available
return encryptionConfigured ? (0, _features2.default)('trust_all_certificates') : driverConfig.encrypted;
}
}, {
key: '_extractTrust',
value: function _extractTrust(driverConfig) {
if (driverConfig.trust) {
return driverConfig.trust;
}
// default to using TRUST_ALL_CERTIFICATES if it is available
return (0, _features2.default)('trust_all_certificates') ? 'TRUST_ALL_CERTIFICATES' : 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES';
}
}, {
key: '_extractTrustedCertificates',
value: function _extractTrustedCertificates(driverConfig) {
return driverConfig.trustedCertificates || [];
}
}, {
key: '_extractKnownHostsPath',
value: function _extractKnownHostsPath(driverConfig) {
return driverConfig.knownHosts || null;
}
}]);
return ChannelConfig;
}();
function extractTrustedCertificates(driverConfig) {
return driverConfig.trustedCertificates || [];
}
exports.default = ChannelConfig;
;
function extractKnownHostsPath(driverConfig) {
return driverConfig.knownHosts || null;
}
function extractConnectionTimeout(driverConfig) {
var configuredTimeout = parseInt(driverConfig.connectionTimeout, 10);
if (!configuredTimeout || configuredTimeout < 0) {
return DEFAULT_CONNECTION_TIMEOUT_MILLIS;
}
return configuredTimeout;
}

@@ -322,2 +322,4 @@ 'use strict';

}, this._handleConnectionError);
this._setupConnectionTimeout(config, this._conn);
}

@@ -342,3 +344,30 @@

}
/**
* Setup connection timeout on the socket, if configured.
* @param {ChannelConfig} config - configuration of this channel.
* @param {object} socket - `net.Socket` or `tls.TLSSocket` object.
* @private
*/
}, {
key: '_setupConnectionTimeout',
value: function _setupConnectionTimeout(config, socket) {
var timeout = config.connectionTimeout;
if (timeout) {
socket.on('connect', function () {
// connected - clear connection timeout
socket.setTimeout(0);
});
socket.on('timeout', function () {
// timeout fired - not connected within configured time. cancel timeout and destroy socket
socket.setTimeout(0);
socket.destroy((0, _error.newError)('Failed to establish connection in ' + timeout + 'ms', config.connectionErrorCode));
});
socket.setTimeout(timeout);
}
}
}, {
key: 'isEncrypted',

@@ -345,0 +374,0 @@ value: function isEncrypted() {

@@ -41,6 +41,4 @@ 'use strict';

this._handleConnectionError = this._handleConnectionError.bind(this);
this._connectionErrorCode = config.connectionErrorCode;
this._config = config;
this._encrypted = config.encrypted;
var scheme = "ws";

@@ -69,2 +67,5 @@ //Allow boolean for backwards compatibility

this._ws.onopen = function () {
// Connected! Cancel connection timeout
clearTimeout(self._connectionTimeoutId);
// Drain all pending messages

@@ -85,2 +86,5 @@ var pending = self._pending;

this._ws.onerror = this._handleConnectionError;
this._connectionTimeoutFired = false;
this._connectionTimeoutId = this._setupConnectionTimeout(config);
}

@@ -91,6 +95,16 @@

value: function _handleConnectionError() {
if (this._connectionTimeoutFired) {
// timeout fired - not connected within configured time
this._error = (0, _error.newError)('Failed to establish connection in ' + this._config.connectionTimeout + 'ms', this._config.connectionErrorCode);
if (this.onerror) {
this.onerror(this._error);
}
return;
}
// onerror triggers on websocket close as well.. don't get me started.
if (this._open) {
// http://stackoverflow.com/questions/25779831/how-to-catch-websocket-connection-to-ws-xxxnn-failed-connection-closed-be
this._error = (0, _error.newError)("WebSocket connection failure. Due to security " + "constraints in your web browser, the reason for the failure is not available " + "to this Neo4j Driver. Please use your browsers development console to determine " + "the root cause of the failure. Common reasons include the database being " + "unavailable, using the wrong connection URL or temporary network problems. " + "If you have enabled encryption, ensure your browser is configured to trust the " + "certificate Neo4j is configured to use. WebSocket `readyState` is: " + this._ws.readyState, this._connectionErrorCode);
this._error = (0, _error.newError)("WebSocket connection failure. Due to security " + "constraints in your web browser, the reason for the failure is not available " + "to this Neo4j Driver. Please use your browsers development console to determine " + "the root cause of the failure. Common reasons include the database being " + "unavailable, using the wrong connection URL or temporary network problems. " + "If you have enabled encryption, ensure your browser is configured to trust the " + 'certificate Neo4j is configured to use. WebSocket `readyState` is: ' + this._ws.readyState, this._config.connectionErrorCode);
if (this.onerror) {

@@ -104,3 +118,3 @@ this.onerror(this._error);

value: function isEncrypted() {
return this._encrypted;
return this._config.encrypted;
}

@@ -143,2 +157,27 @@

}
/**
* Set connection timeout on the given WebSocket, if configured.
* @return {number} the timeout id or null.
* @private
*/
}, {
key: '_setupConnectionTimeout',
value: function _setupConnectionTimeout() {
var _this = this;
var timeout = this._config.connectionTimeout;
if (timeout) {
var webSocket = this._ws;
return setTimeout(function () {
if (webSocket.readyState !== WebSocket.OPEN) {
_this._connectionTimeoutFired = true;
webSocket.close();
}
}, timeout);
}
return null;
}
}]);

@@ -145,0 +184,0 @@ return WebSocketChannel;

@@ -7,2 +7,6 @@ "use strict";

var _keys = require("babel-runtime/core-js/object/keys");
var _keys2 = _interopRequireDefault(_keys);
var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck");

@@ -103,7 +107,7 @@

value: function purgeAll() {
for (var key in this._pools.keys) {
if (this._pools.hasOwnPropertykey) {
this.purge(key);
}
}
var _this = this;
(0, _keys2.default)(this._pools).forEach(function (key) {
return _this.purge(key);
});
}

@@ -120,3 +124,4 @@ }, {

if (!pool) {
//key has been purged, don't put it back
// key has been purged, don't put it back, just destroy the resource
this._destroy(resource);
return;

@@ -123,0 +128,0 @@ }

@@ -6,3 +6,3 @@ "use strict";

});
exports.ENCRYPTION_OFF = exports.ENCRYPTION_ON = exports.parseRoutingContext = exports.parsePort = exports.parseHost = exports.parseUrl = exports.parseScheme = exports.assertString = exports.isString = exports.isEmptyObjectOrNull = undefined;
exports.ENCRYPTION_OFF = exports.ENCRYPTION_ON = exports.parseRoutingContext = exports.parsePort = exports.parseHost = exports.parseUrl = exports.parseScheme = exports.assertCypherStatement = exports.assertString = exports.isString = exports.isEmptyObjectOrNull = undefined;

@@ -78,2 +78,10 @@ var _stringify = require("babel-runtime/core-js/json/stringify");

function assertCypherStatement(obj) {
assertString(obj, 'Cypher statement');
if (obj.trim().length == 0) {
throw new TypeError('Cypher statement is expected to be a non-empty string.');
}
return obj;
}
function isString(str) {

@@ -138,2 +146,3 @@ return Object.prototype.toString.call(str) === '[object String]';

exports.assertString = assertString;
exports.assertCypherStatement = assertCypherStatement;
exports.parseScheme = parseScheme;

@@ -140,0 +149,0 @@ exports.parseUrl = parseUrl;

@@ -82,3 +82,3 @@ 'use strict';

* Run Cypher statement
* Could be called with a statement object i.e.: {statement: "MATCH ...", parameters: {param: 1}}
* Could be called with a statement object i.e.: {text: "MATCH ...", parameters: {param: 1}}
* or with the statement and parameters as separate arguments.

@@ -100,3 +100,3 @@ * @param {mixed} statement - Cypher statement to execute

}
(0, _util.assertString)(statement, 'Cypher statement');
(0, _util.assertCypherStatement)(statement);

@@ -103,0 +103,0 @@ return this._run(statement, parameters, function (connection, streamObserver) {

@@ -92,3 +92,3 @@ 'use strict';

* Run Cypher statement
* Could be called with a statement object i.e.: <code>{statement: "MATCH ...", parameters: {param: 1}}</code>
* Could be called with a statement object i.e.: <code>{text: "MATCH ...", parameters: {param: 1}}</code>
* or with the statement and parameters as separate arguments.

@@ -108,3 +108,3 @@ * @param {mixed} statement - Cypher statement to execute

}
(0, _util.assertString)(statement, "Cypher statement");
(0, _util.assertCypherStatement)(statement);

@@ -111,0 +111,0 @@ return this._state.run(this._connectionHolder, new _TransactionStreamObserver(this), statement, parameters);

@@ -32,2 +32,2 @@ "use strict";

// system to control version names at packaging time.
exports.default = "1.4.0";
exports.default = "1.4.1";
{
"name": "neo4j-driver",
"version": "1.4.0",
"version": "1.4.1",
"description": "Connect to Neo4j 3.1.0 and up from JavaScript",

@@ -5,0 +5,0 @@ "author": "Neo Technology Inc.",

@@ -22,2 +22,3 @@ /**

import {Parameters} from "./statement-runner";
import {Neo4jError} from "./error";

@@ -58,2 +59,5 @@ declare interface AuthToken {

close(): void;
onCompleted?: (metadata: { server: string }) => void;
onError?: (error: Neo4jError) => void;
}

@@ -60,0 +64,0 @@

@@ -20,10 +20,17 @@ /**

import {inSafeRange, int, isInt, toNumber, toString} from "./integer";
import Integer, {inSafeRange, int, isInt, toNumber, toString} from "./integer";
import {Node, Path, PathSegment, Relationship, UnboundRelationship} from "./graph-types";
import {Neo4jError, PROTOCOL_ERROR, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "./error";
import Result from "./result";
import ResultSummary from "./result-summary";
import Result, {Observer, StatementResult} from "./result";
import ResultSummary, {
Notification,
NotificationPosition,
Plan,
ProfiledPlan,
ServerInfo,
StatementStatistic
} from "./result-summary";
import Record from "./record";
import Session from "./session";
import {AuthToken, Config, Driver, READ, WRITE} from "./driver";
import {AuthToken, Config, Driver, EncryptionLevel, READ, SessionMode, TrustStrategy, WRITE} from "./driver";
import Transaction from "./transaction";

@@ -78,2 +85,11 @@ import {Parameters} from "./statement-runner";

/*
Both default and non-default exports declare all visible types so that they can be used in client code like this:
import neo4j from "neo4j-driver";
const driver: neo4j.Driver = neo4j.driver("bolt://localhost");
const session: neo4j.Session = driver.session();
...
*/
declare const forExport: {

@@ -84,3 +100,2 @@ driver: typeof driver;

integer: typeof integer;
Neo4jError: typeof Neo4jError;
auth: typeof auth;

@@ -93,2 +108,23 @@ types: typeof types;

Config: Config;
EncryptionLevel: EncryptionLevel;
TrustStrategy: TrustStrategy;
SessionMode: SessionMode;
Neo4jError: Neo4jError;
Node: Node;
Relationship: Relationship;
UnboundRelationship: UnboundRelationship;
PathSegment: PathSegment;
Path: Path;
Integer: Integer;
Record: Record;
Result: Result;
StatementResult: StatementResult;
Observer: Observer;
ResultSummary: ResultSummary;
Plan: Plan,
ProfiledPlan: ProfiledPlan,
StatementStatistic: StatementStatistic,
Notification: Notification,
ServerInfo: ServerInfo,
NotificationPosition: NotificationPosition,
Session: Session;

@@ -103,3 +139,2 @@ Transaction: Transaction;

integer,
Neo4jError,
auth,

@@ -109,7 +144,30 @@ types,

error,
Driver,
AuthToken,
Config,
EncryptionLevel,
TrustStrategy,
SessionMode,
Neo4jError,
Node,
Relationship,
UnboundRelationship,
PathSegment,
Path,
Integer,
Record,
Result,
StatementResult,
Observer,
ResultSummary,
Plan,
ProfiledPlan,
StatementStatistic,
Notification,
ServerInfo,
NotificationPosition,
Session,
Config,
Transaction
}
export default forExport;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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