@@ -24,15 +24,16 @@ import {
2424// eslint-disable-next-line no-unused-vars
2525import { Chunker } from '../channel'
2626import { structure , v1 } from '../packstream'
27- import RequestMessage from './request-message'
27+ import RequestMessage , { SIGNATURES } from './request-message'
2828import {
2929 LoginObserver ,
30+ LogoffObserver ,
3031 ResetObserver ,
3132 ResultStreamObserver ,
3233 // eslint-disable-next-line no-unused-vars
3334 StreamObserver
3435} from './stream-observers'
35- import { internal } from 'neo4j-driver-core'
36+ import { internal , newError } from 'neo4j-driver-core'
3637import transformersFactories from './bolt-protocol-v1.transformer'
3738import Transformer from './transformer'
3839
@@ -99,6 +100,27 @@ export default class BoltProtocol {
99100 return BOLT_PROTOCOL_V1
100101 }
101102
103+ /**
104+ * @property {boolean } supportsReAuth Either if the protocol version supports re-auth or not.
105+ */
106+ get supportsReAuth ( ) {
107+ return false
108+ }
109+
110+ /**
111+ * @property {boolean } initialized Either if the protocol was initialized or not
112+ */
113+ get initialized ( ) {
114+ return ! ! this . _initialized
115+ }
116+
117+ /**
118+ * @property {object } authToken The token used in the last login
119+ */
120+ get authToken ( ) {
121+ return this . _authToken
122+ }
123+
102124 /**
103125 * Get the packer.
104126 * @return {Packer } the protocol's packer.
@@ -162,6 +184,61 @@ export default class BoltProtocol {
162184 return observer
163185 }
164186
187+ /**
188+ * Performs logoff of the underlying connection
189+ *
190+ * @param {Object } param
191+ * @param {function(err: Error) } param.onError the callback to invoke on error.
192+ * @param {function() } param.onComplete the callback to invoke on completion.
193+ * @param {boolean } param.flush whether to flush the buffered messages.
194+ *
195+ * @returns {StreamObserver } the stream observer that monitors the corresponding server response.
196+ */
197+ logoff ( { onComplete, onError, flush } = { } ) {
198+ const observer = new LogoffObserver ( {
199+ onCompleted : onComplete ,
200+ onError : onError
201+ } )
202+
203+ const error = newError (
204+ 'Driver is connected to a database that does not support logoff. ' +
205+ 'Please upgrade to Neo4j 5.5.0 or later in order to use this functionality.'
206+ )
207+
208+ // unsupported API was used, consider this a fatal error for the current connection
209+ this . _onProtocolError ( error . message )
210+ observer . onError ( error )
211+ throw error
212+ }
213+
214+ /**
215+ * Performs login of the underlying connection
216+ *
217+ * @param {Object } args
218+ * @param {Object } args.authToken the authentication token.
219+ * @param {function(err: Error) } args.onError the callback to invoke on error.
220+ * @param {function() } args.onComplete the callback to invoke on completion.
221+ * @param {boolean } args.flush whether to flush the buffered messages.
222+ *
223+ * @returns {StreamObserver } the stream observer that monitors the corresponding server response.
224+ */
225+ logon ( { authToken, onComplete, onError, flush } = { } ) {
226+ const observer = new LoginObserver ( {
227+ onCompleted : ( ) => this . _onLoginCompleted ( { } , authToken , onComplete ) ,
228+ onError : ( error ) => this . _onLoginError ( error , onError )
229+ } )
230+
231+ const error = newError (
232+ 'Driver is connected to a database that does not support logon. ' +
233+ 'Please upgrade to Neo4j 5.5.0 or later in order to use this functionality.'
234+ )
235+
236+ // unsupported API was used, consider this a fatal error for the current connection
237+ this . _onProtocolError ( error . message )
238+ observer . onError ( error )
239+ throw error
240+ }
241+
165242 /**
166243 * Perform protocol related operations for closing this connection
167244 */
@@ -391,19 +468,19 @@ export default class BoltProtocol {
391468 this . packable ( messageStruct ) ( )
392469
393470 this . _chunker . messageBoundary ( )
394-
395471 if ( flush ) {
396472 this . _chunker . flush ( )
397473 }
398474 }
399475 }
400476
401- isLastMessageLogin ( ) {
402- return this . _lastMessageSignature === 0x01
477+ isLastMessageLogon ( ) {
478+ return this . _lastMessageSignature === SIGNATURES . HELLO ||
479+ this . _lastMessageSignature === SIGNATURES . LOGON
403480 }
404481
405482 isLastMessageReset ( ) {
406- return this . _lastMessageSignature === 0x0f
483+ return this . _lastMessageSignature === SIGNATURES . RESET
407484 }
408485
409486 /**
@@ -472,7 +549,9 @@ export default class BoltProtocol {
472549 this . _responseHandler . _resetFailure ( )
473550 }
474551
475- _onLoginCompleted ( metadata , onCompleted ) {
552+ _onLoginCompleted ( metadata , authToken , onCompleted ) {
553+ this . _initialized = true
554+ this . _authToken = authToken
476555 if ( metadata ) {
477556 const serverVersion = metadata . server
478557 if ( ! this . _server . version ) {
0 commit comments