Skip to content

Commit 91ca7f6

Browse files
committed
Add documentation for TLS
1 parent 52f6b1d commit 91ca7f6

File tree

4 files changed

+89
-13
lines changed

4 files changed

+89
-13
lines changed

esdoc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"source": "./src",
33
"destination": "./docs/build",
44
"includes": ["\\.js$"],
5-
"excludes": ["external"],
5+
"excludes": ["external", "internal"],
66
"package": "./package.json",
77
"title": "Neo4j Bolt Driver for Javascript",
88
"unexportIdentifier": true,

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"babelify": "^6.3.0",
2222
"browserify": "^11.0.0",
2323
"esdoc": "^0.4.0",
24+
"esdoc-importpath-plugin": "0.0.1",
2425
"glob": "^5.0.14",
2526
"gulp": "^3.9.0",
2627
"gulp-babel": "^5.2.1",

src/v1/driver.js

+85-7
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,27 @@ import Session from './session';
2121
import {Pool} from './internal/pool';
2222
import {connect} from "./internal/connector";
2323
import StreamObserver from './internal/stream-observer';
24+
import {VERSION} from '../../version';
2425

2526
/**
26-
* A Driver instance is used for mananging {@link Session}s.
27-
* @access public
28-
*/
27+
* A driver maintains one or more {@link Session sessions} with a remote
28+
* Neo4j instance. Through the {@link Session sessions} you can send statements
29+
* and retrieve results from the database.
30+
*
31+
* Drivers are reasonably expensive to create - you should strive to keep one
32+
* driver instance around per Neo4j Instance you connect to.
33+
*
34+
* @access public
35+
*/
2936
class Driver {
3037
/**
38+
* You should not be calling this directly, instead use {@link driver}.
3139
* @constructor
3240
* @param {string} url
3341
* @param {string} userAgent
3442
* @param {Object} token
3543
* @param {Object} config
44+
* @access private
3645
*/
3746
constructor(url, userAgent = 'neo4j-javascript/0.0', token = {}, config = {}) {
3847
this._url = url;
@@ -85,7 +94,16 @@ class Driver {
8594
}
8695

8796
/**
88-
* Create and return new session
97+
* Acquire a session to communicate with the database. The driver maintains
98+
* a pool of sessions, so calling this method is normally cheap because you
99+
* will be pulling a session out of the common pool.
100+
*
101+
* This comes with some responsibility - make sure you always call
102+
* {@link Session#close()} when you are done using a session, and likewise,
103+
* make sure you don't close your session before you are done using it. Once
104+
* it is returned to the pool, the session will be reset to a clean state and
105+
* made available for others to use.
106+
*
89107
* @return {Session} new session.
90108
*/
91109
session() {
@@ -113,8 +131,9 @@ class Driver {
113131
}
114132

115133
/**
116-
* Close sessions connections
117-
* @return
134+
* Close all open sessions and other associated resources. You should
135+
* make sure to use this when you are done with this driver instance.
136+
* @return undefined
118137
*/
119138
close() {
120139
for (let sessionId in this._openSessions) {
@@ -143,4 +162,63 @@ class _ConnectionStreamObserver extends StreamObserver {
143162
}
144163
}
145164

146-
export default Driver
165+
let USER_AGENT = "neo4j-javascript/" + VERSION;
166+
167+
/**
168+
* Construct a new Neo4j Driver. This is your main entry point for this
169+
* library.
170+
*
171+
* ## Configuration
172+
*
173+
* This function optionally takes a configuration argument. Available configuration
174+
* options are as follows:
175+
*
176+
* {
177+
* // Enable TLS encryption. This is on by default in modern NodeJS installs,
178+
* // but off by default in the Web Bundle and old (<=1.0.0) NodeJS installs
179+
* // due to technical limitations on those platforms.
180+
* encrypted: true|false,
181+
*
182+
* // Trust strategy to use if encryption is enabled. There is no mode to disable
183+
* // trust other than disabling encryption altogether. The reason for
184+
* // this is that if you don't know who you are talking to, it is easy for an
185+
* // attacker to hijack your encrypted connection, rendering encryption pointless.
186+
* //
187+
* // TRUST_ON_FIRST_USE is the default for modern NodeJS deployments, and works
188+
* // similarly to how `ssl` works - the first time we connect to a new host,
189+
* // we remember the certificate they use. If the certificate ever changes, we
190+
* // assume it is an attempt to hijack the connection and require manual intervention.
191+
* // This means that by default, connections "just work" while still giving you
192+
* // good encrypted protection.
193+
* //
194+
* // TRUST_SIGNED_CERTIFICATES is the classic approach to trust verification -
195+
* // whenever we establish an encrypted connection, we ensure the host is using
196+
* // an encryption certificate that is in, or is signed by, a certificate listed
197+
* // as trusted. In the web bundle, this list of trusted certificates is maintained
198+
* // by the web browser. In NodeJS, you configure the list with the next config option.
199+
* trust: "TRUST_ON_FIRST_USE" | "TRUST_SIGNED_CERTIFICATES",
200+
*
201+
* // List of one or more paths to trusted encryption certificates. This only
202+
* // works in the NodeJS bundle, and only matters if you use "TRUST_SIGNED_CERTIFICATES".
203+
* // The certificate files should be in regular X.509 PEM format.
204+
* // For instance, ['./trusted.pem']
205+
* trustedCertificates: [],
206+
*
207+
* // Path to a file where the driver saves hosts it has seen in the past, this is
208+
* // very similar to the ssl tool's known_hosts file. Each time we connect to a
209+
* // new host, a hash of their certificate is stored along with the domain name and
210+
* // port, and this is then used to verify the host certificate does not change.
211+
* // This setting has no effect unless TRUST_ON_FIRST_USE is enabled.
212+
* knownHosts:"~/.neo4j/known_hosts",
213+
* }
214+
*
215+
* @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"
216+
* @param {Map<String,String>} authToken Authentication credentials. See {@link auth} for helpers.
217+
* @param {Object} config Configuration object. See the configuration section above for details.
218+
* @returns {Driver}
219+
*/
220+
function driver(url, authToken, config={}) {
221+
return new Driver(url, USER_AGENT, authToken, config);
222+
}
223+
224+
export {Driver, driver}

src/v1/index.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
*/
1919

2020
import {int, isInt} from './integer';
21-
import Driver from './driver';
22-
import {VERSION} from '../version';
21+
import {driver} from './driver';
2322
import {Node, Relationship, UnboundRelationship, PathSegment, Path} from './graph-types'
2423

25-
let USER_AGENT = "neo4j-javascript/" + VERSION;
26-
2724
export default {
28-
driver: (url, token, config={}) => new Driver(url, USER_AGENT, token, config),
25+
driver,
2926
int,
3027
isInt,
3128
auth: {

0 commit comments

Comments
 (0)