Skip to content

Commit 0b8c1b4

Browse files
committed
Fix useragent string on metadata object in 5.3
1 parent 3ee1fa6 commit 0b8c1b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+481
-152
lines changed

packages/bolt-connection/src/bolt/request-message.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ export default class RequestMessage {
200200
* @return {RequestMessage} new HELLO message.
201201
*/
202202
static hello5x3 (userAgent, boltAgent, notificationFilter = null, routing = null) {
203-
const metadata = { user_agent: userAgent, bolt_agent: boltAgent }
203+
const metadata = { bolt_agent: boltAgent }
204+
205+
if (userAgent) {
206+
metadata.user_agent = userAgent
207+
}
204208

205209
if (notificationFilter) {
206210
if (notificationFilter.minimumSeverityLevel) {

packages/core/src/internal/bolt-agent/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* limitations under the License.
1818
*/
1919

20-
export * from './BoltAgent'
20+
export * from './bolt-agent'

packages/core/src/internal/bolt-agent/deno/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* limitations under the License.
1818
*/
1919

20-
export * from './BoltAgent'
20+
export * from './bolt-agent'

packages/core/src/internal/bolt-agent/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* limitations under the License.
1818
*/
1919

20-
export * from './node/index'
20+
export * from './node'

packages/core/src/internal/bolt-agent/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
* limitations under the License.
1818
*/
1919

20-
export * from './BoltAgent'
20+
export * from './bolt-agent'

packages/neo4j-driver-deno/generate.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,25 @@ async function copyAndTransform(inDir: string, outDir: string) {
129129
}
130130
}
131131

132-
// Special fix for bolt-connection/channel/index.js and core/bolt-agent/index.js
133-
// Replace the "node channel" with the "deno channel", since Deno supports different APIs
132+
// Special fix for core/internal/bolt-agent/index.js
134133
// Replace the "node boltAgent" with the "deno boltAgent", since Deno supports different APIs
135-
if (inPath.endsWith("channel/index.js") || inPath.endsWith("bolt-agent/index.ts")) {
134+
if(inPath.endsWith("bolt-agent/index.ts")){
135+
console.log(inPath)
136+
console.log(contents)
137+
contents = contents.replace(
138+
`export * from './node/index.ts'`,
139+
`export * from './deno/index.ts'`,
140+
);
141+
}
142+
143+
// Special fix for bolt-connection/channel/index.js and core/internal/bolt-agent/index.js
144+
// Replace the "node channel" with the "deno channel", since Deno supports different APIs
145+
if (inPath.endsWith("channel/index.js")) {
146+
console.log(inPath)
147+
console.log(contents)
136148
contents = contents.replace(
137-
`export * from './node/index'`,
138-
`export * from './deno/index'`,
149+
`export * from './node/index.js'`,
150+
`export * from './deno/index.js'`,
139151
);
140152
}
141153
}

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class BoltProtocol {
175175
* @param {function()} param.onComplete the callback to invoke on completion.
176176
* @returns {StreamObserver} the stream observer that monitors the corresponding server response.
177177
*/
178-
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
178+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
179179
const observer = new LoginObserver({
180180
onError: error => this._onLoginError(error, onError),
181181
onCompleted: metadata => this._onLoginCompleted(metadata, onComplete)
@@ -184,7 +184,7 @@ export default class BoltProtocol {
184184
// passing notification filter on this protocol version throws an error
185185
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
186186

187-
this.write(RequestMessage.init(userAgent, authToken), observer, true)
187+
this.write(RequestMessage.init(userAgent === '' || userAgent == null ? boltAgent : userAgent, authToken), observer, true)
188188

189189
return observer
190190
}

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
6969
return metadata
7070
}
7171

72-
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
72+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
7373
const observer = new LoginObserver({
7474
onError: error => this._onLoginError(error, onError),
7575
onCompleted: metadata => this._onLoginCompleted(metadata, authToken, onComplete)
@@ -78,7 +78,7 @@ export default class BoltProtocol extends BoltProtocolV2 {
7878
// passing notification filter on this protocol version throws an error
7979
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
8080

81-
this.write(RequestMessage.hello(userAgent, authToken), observer, true)
81+
this.write(RequestMessage.hello(userAgent === '' || userAgent == null ? boltAgent : userAgent, authToken), observer, true)
8282

8383
return observer
8484
}

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v4x1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default class BoltProtocol extends BoltProtocolV4 {
7373
return this._transformer
7474
}
7575

76-
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
76+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
7777
const observer = new LoginObserver({
7878
onError: error => this._onLoginError(error, onError),
7979
onCompleted: metadata => this._onLoginCompleted(metadata, authToken, onComplete)
@@ -83,7 +83,7 @@ export default class BoltProtocol extends BoltProtocolV4 {
8383
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
8484

8585
this.write(
86-
RequestMessage.hello(userAgent, authToken, this._serversideRouting),
86+
RequestMessage.hello(userAgent === '' || userAgent == null ? boltAgent : userAgent, authToken, this._serversideRouting),
8787
observer,
8888
true
8989
)

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v4x3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default class BoltProtocol extends BoltProtocolV42 {
8989
* @param {function(onComplte)} args.onComplete On complete callback
9090
* @returns {LoginObserver} The Login observer
9191
*/
92-
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
92+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
9393
const observer = new LoginObserver({
9494
onError: error => this._onLoginError(error, onError),
9595
onCompleted: metadata => {
@@ -104,7 +104,7 @@ export default class BoltProtocol extends BoltProtocolV42 {
104104
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
105105

106106
this.write(
107-
RequestMessage.hello(userAgent, authToken, this._serversideRouting, ['utc']),
107+
RequestMessage.hello(userAgent === '' || userAgent == null ? boltAgent : userAgent, authToken, this._serversideRouting, ['utc']),
108108
observer,
109109
true
110110
)

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v5x0.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class BoltProtocol extends BoltProtocolV44 {
5353
* @param {function(onComplte)} args.onComplete On complete callback
5454
* @returns {LoginObserver} The Login observer
5555
*/
56-
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
56+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
5757
const observer = new LoginObserver({
5858
onError: error => this._onLoginError(error, onError),
5959
onCompleted: metadata => this._onLoginCompleted(metadata, authToken, onComplete)
@@ -63,7 +63,7 @@ export default class BoltProtocol extends BoltProtocolV44 {
6363
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
6464

6565
this.write(
66-
RequestMessage.hello(userAgent, authToken, this._serversideRouting),
66+
RequestMessage.hello(userAgent === '' || userAgent == null ? boltAgent : userAgent, authToken, this._serversideRouting),
6767
observer,
6868
true
6969
)

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v5x1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class BoltProtocol extends BoltProtocolV5x0 {
5757
* @param {function(onComplete)} args.onComplete On complete callback
5858
* @returns {LoginObserver} The Login observer
5959
*/
60-
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
60+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
6161
const state = {}
6262
const observer = new LoginObserver({
6363
onError: error => this._onLoginError(error, onError),
@@ -71,7 +71,7 @@ export default class BoltProtocol extends BoltProtocolV5x0 {
7171
assertNotificationFilterIsEmpty(notificationFilter, this._onProtocolError, observer)
7272

7373
this.write(
74-
RequestMessage.hello5x1(userAgent, this._serversideRouting),
74+
RequestMessage.hello5x1(userAgent === '' || userAgent == null ? boltAgent : userAgent, this._serversideRouting),
7575
observer,
7676
false
7777
)

packages/neo4j-driver-deno/lib/bolt-connection/bolt/bolt-protocol-v5x2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ export default class BoltProtocol extends BoltProtocolV5x1 {
5050
*
5151
* @param {Object} args The params
5252
* @param {string} args.userAgent The user agent
53+
* @param {string} args.boltAgent The bolt agent
5354
* @param {any} args.authToken The auth token
5455
* @param {NotificationFilter} args.notificationFilter The notification filters.
5556
* @param {function(error)} args.onError On error callback
5657
* @param {function(onComplete)} args.onComplete On complete callback
5758
* @returns {LoginObserver} The Login observer
5859
*/
59-
initialize ({ userAgent, authToken, notificationFilter, onError, onComplete } = {}) {
60+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
6061
const state = {}
6162
const observer = new LoginObserver({
6263
onError: error => this._onLoginError(error, onError),
@@ -67,7 +68,8 @@ export default class BoltProtocol extends BoltProtocolV5x1 {
6768
})
6869

6970
this.write(
70-
RequestMessage.hello5x2(userAgent, notificationFilter, this._serversideRouting),
71+
// if useragent is null then for all versions before 5.3 it should be bolt agent by default
72+
RequestMessage.hello5x2(userAgent === '' || userAgent == null ? boltAgent : userAgent, notificationFilter, this._serversideRouting),
7173
observer,
7274
false
7375
)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import BoltProtocolV5x2 from './bolt-protocol-v5x2.js'
20+
21+
import transformersFactories from './bolt-protocol-v5x3.transformer.js'
22+
import Transformer from './transformer.js'
23+
import RequestMessage from './request-message.js'
24+
import { LoginObserver } from './stream-observers.js'
25+
26+
import { internal } from '../../core/index.ts'
27+
28+
const {
29+
constants: { BOLT_PROTOCOL_V5_3 }
30+
} = internal
31+
32+
export default class BoltProtocol extends BoltProtocolV5x2 {
33+
get version () {
34+
return BOLT_PROTOCOL_V5_3
35+
}
36+
37+
get transformer () {
38+
if (this._transformer === undefined) {
39+
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log)))
40+
}
41+
return this._transformer
42+
}
43+
44+
/**
45+
* Initialize a connection with the server
46+
*
47+
* @param {Object} args The params
48+
* @param {string} args.userAgent The user agent
49+
* @param {any} args.authToken The auth token
50+
* @param {NotificationFilter} args.notificationFilter The notification filters.
51+
* @param {function(error)} args.onError On error callback
52+
* @param {function(onComplete)} args.onComplete On complete callback
53+
* @returns {LoginObserver} The Login observer
54+
*/
55+
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) {
56+
const state = {}
57+
const observer = new LoginObserver({
58+
onError: error => this._onLoginError(error, onError),
59+
onCompleted: metadata => {
60+
state.metadata = metadata
61+
return this._onLoginCompleted(metadata)
62+
}
63+
})
64+
65+
this.write(
66+
RequestMessage.hello5x3(userAgent, boltAgent, notificationFilter, this._serversideRouting),
67+
observer,
68+
false
69+
)
70+
71+
return this.logon({
72+
authToken,
73+
onComplete: metadata => onComplete({ ...metadata, ...state.metadata }),
74+
onError,
75+
flush: true
76+
})
77+
}
78+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import v5x2 from './bolt-protocol-v5x2.transformer.js'
21+
22+
export default {
23+
...v5x2
24+
}

packages/neo4j-driver-deno/lib/bolt-connection/bolt/create.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import BoltProtocolV4x4 from './bolt-protocol-v4x4.js'
2929
import BoltProtocolV5x0 from './bolt-protocol-v5x0.js'
3030
import BoltProtocolV5x1 from './bolt-protocol-v5x1.js'
3131
import BoltProtocolV5x2 from './bolt-protocol-v5x2.js'
32+
import BoltProtocolV5x3 from './bolt-protocol-v5x3.js'
3233
// eslint-disable-next-line no-unused-vars
3334
import { Chunker, Dechunker } from '../channel/index.js'
3435
import ResponseHandler from './response-handler.js'
@@ -213,6 +214,14 @@ function createProtocol (
213214
onProtocolError,
214215
serversideRouting
215216
)
217+
case 5.3:
218+
return new BoltProtocolV5x3(server,
219+
chunker,
220+
packingConfig,
221+
createResponseHandler,
222+
log,
223+
onProtocolError,
224+
serversideRouting)
216225
default:
217226
throw newError('Unknown Bolt protocol version: ' + version)
218227
}

packages/neo4j-driver-deno/lib/bolt-connection/bolt/handshake.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function parseNegotiatedResponse (buffer) {
7676
*/
7777
function newHandshakeBuffer () {
7878
return createHandshakeMessage([
79-
[version(5, 2), version(5, 0)],
79+
[version(5, 3), version(5, 0)],
8080
[version(4, 4), version(4, 2)],
8181
version(4, 1),
8282
version(3, 0)

packages/neo4j-driver-deno/lib/bolt-connection/bolt/request-message.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,42 @@ export default class RequestMessage {
191191
)
192192
}
193193

194+
/**
195+
* Create a new HELLO message.
196+
* @param {string} userAgent the user agent.
197+
* @param {string} boltAgent the bolt agent.
198+
* @param {NotificationFilter} notificationFilter the notification filter configured
199+
* @param {Object} routing server side routing, set to routing context to turn on server side routing (> 4.1)
200+
* @return {RequestMessage} new HELLO message.
201+
*/
202+
static hello5x3 (userAgent, boltAgent, notificationFilter = null, routing = null) {
203+
const metadata = { bolt_agent: boltAgent }
204+
205+
if (userAgent) {
206+
metadata.user_agent = userAgent
207+
}
208+
209+
if (notificationFilter) {
210+
if (notificationFilter.minimumSeverityLevel) {
211+
metadata.notifications_minimum_severity = notificationFilter.minimumSeverityLevel
212+
}
213+
214+
if (notificationFilter.disabledCategories) {
215+
metadata.notifications_disabled_categories = notificationFilter.disabledCategories
216+
}
217+
}
218+
219+
if (routing) {
220+
metadata.routing = routing
221+
}
222+
223+
return new RequestMessage(
224+
HELLO,
225+
[metadata],
226+
() => `HELLO ${json.stringify(metadata)}`
227+
)
228+
}
229+
194230
/**
195231
* Create a new LOGON message.
196232
*

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-direct.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const {
3232
const { SERVICE_UNAVAILABLE } = error
3333

3434
export default class DirectConnectionProvider extends PooledConnectionProvider {
35-
constructor ({ id, config, log, address, userAgent, authToken }) {
36-
super({ id, config, log, userAgent, authToken })
35+
constructor ({ id, config, log, address, userAgent, boltAgent, authToken }) {
36+
super({ id, config, log, userAgent, boltAgent, authToken })
3737

3838
this._address = address
3939
}

0 commit comments

Comments
 (0)