Skip to content

Commit 2c97a5d

Browse files
authored
Merge pull request #5 from bigmontz/bolt-agent
Fix browser tests in the lite driver
2 parents 07239dd + 1bf607b commit 2c97a5d

File tree

7 files changed

+39
-18
lines changed

7 files changed

+39
-18
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface SystemInfo {
2323
hostArch: string
2424
nodeVersion: string
2525
v8Version: string
26-
platform: NodeJS.Platform
26+
platform: string
2727
release: string
2828
}
2929

packages/core/src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export interface Config {
7272
logging?: LoggingConfig
7373
resolver?: (address: string) => string[] | Promise<string[]>
7474
userAgent?: string
75+
}
76+
77+
export interface InternalConfig extends Config {
7578
boltAgent?: BoltAgent
7679
}
7780

packages/neo4j-driver-deno/lib/core/internal/bolt-agent/node/bolt-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface SystemInfo {
2323
hostArch: string
2424
nodeVersion: string
2525
v8Version: string
26-
platform: NodeJS.Platform
26+
platform: string
2727
release: string
2828
}
2929

packages/neo4j-driver-deno/lib/core/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export interface Config {
7272
logging?: LoggingConfig
7373
resolver?: (address: string) => string[] | Promise<string[]>
7474
userAgent?: string
75+
}
76+
77+
export interface InternalConfig extends Config {
7578
boltAgent?: BoltAgent
7679
}
7780

packages/neo4j-driver-deno/lib/mod.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import { DirectConnectionProvider, RoutingConnectionProvider } from './bolt-conn
104104

105105
type AuthToken = coreTypes.AuthToken
106106
type Config = coreTypes.Config
107+
type InternalConfig = coreTypes.InternalConfig
107108
type TrustStrategy = coreTypes.TrustStrategy
108109
type EncryptionLevel = coreTypes.EncryptionLevel
109110
type SessionMode = coreTypes.SessionMode
@@ -288,6 +289,9 @@ function driver (
288289
assertString(url, 'Bolt URL')
289290
const parsedUrl = urlUtil.parseDatabaseUrl(url)
290291

292+
// enabling set boltAgent
293+
const _config = config as unknown as InternalConfig
294+
291295
// Determine entryption/trust options from the URL.
292296
let routing = false
293297
let encrypted = false
@@ -323,20 +327,21 @@ function driver (
323327
// Encryption enabled on URL, propagate trust to the config.
324328
if (encrypted) {
325329
// Check for configuration conflict between URL and config.
326-
if ('encrypted' in config || 'trust' in config) {
330+
if ('encrypted' in _config || 'trust' in _config) {
327331
throw new Error(
328332
'Encryption/trust can only be configured either through URL or config, not both'
329333
)
330334
}
331-
config.encrypted = ENCRYPTION_ON
332-
config.trust = trust
335+
_config.encrypted = ENCRYPTION_ON
336+
_config.trust = trust
333337
}
334338

335339
const authTokenManager = createAuthManager(authToken)
336340

337341
// Use default user agent or user agent specified by user.
338-
config.userAgent = config.userAgent ?? USER_AGENT
339-
config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)
342+
_config.userAgent = _config.userAgent ?? USER_AGENT
343+
_config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)
344+
340345
const address = ServerAddress.fromUrl(parsedUrl.hostAndPort)
341346

342347
const meta = {
@@ -345,13 +350,13 @@ function driver (
345350
routing
346351
}
347352

348-
return new Driver(meta, config, createConnectionProviderFunction())
353+
return new Driver(meta, _config, createConnectionProviderFunction())
349354

350355
function createConnectionProviderFunction (): (id: number, config: Config, log: Logger, hostNameResolver: ConfiguredCustomResolver) => ConnectionProvider {
351356
if (routing) {
352357
return (
353358
id: number,
354-
config: Config,
359+
config: InternalConfig,
355360
log: Logger,
356361
hostNameResolver: ConfiguredCustomResolver
357362
): ConnectionProvider =>
@@ -373,7 +378,7 @@ function driver (
373378
)
374379
}
375380

376-
return (id: number, config: Config, log: Logger): ConnectionProvider =>
381+
return (id: number, config: InternalConfig, log: Logger): ConnectionProvider =>
377382
new DirectConnectionProvider({
378383
id,
379384
config,

packages/neo4j-driver-lite/src/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import { DirectConnectionProvider, RoutingConnectionProvider } from 'neo4j-drive
103103

104104
type AuthToken = coreTypes.AuthToken
105105
type Config = coreTypes.Config
106+
type InternalConfig = coreTypes.InternalConfig
106107
type TrustStrategy = coreTypes.TrustStrategy
107108
type EncryptionLevel = coreTypes.EncryptionLevel
108109
type SessionMode = coreTypes.SessionMode
@@ -287,6 +288,9 @@ function driver (
287288
assertString(url, 'Bolt URL')
288289
const parsedUrl = urlUtil.parseDatabaseUrl(url)
289290

291+
// enabling set boltAgent
292+
const _config = config as unknown as InternalConfig
293+
290294
// Determine entryption/trust options from the URL.
291295
let routing = false
292296
let encrypted = false
@@ -322,20 +326,21 @@ function driver (
322326
// Encryption enabled on URL, propagate trust to the config.
323327
if (encrypted) {
324328
// Check for configuration conflict between URL and config.
325-
if ('encrypted' in config || 'trust' in config) {
329+
if ('encrypted' in _config || 'trust' in _config) {
326330
throw new Error(
327331
'Encryption/trust can only be configured either through URL or config, not both'
328332
)
329333
}
330-
config.encrypted = ENCRYPTION_ON
331-
config.trust = trust
334+
_config.encrypted = ENCRYPTION_ON
335+
_config.trust = trust
332336
}
333337

334338
const authTokenManager = createAuthManager(authToken)
335339

336340
// Use default user agent or user agent specified by user.
337-
config.userAgent = config.userAgent ?? USER_AGENT
338-
config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)
341+
_config.userAgent = _config.userAgent ?? USER_AGENT
342+
_config.boltAgent = internal.boltAgent.fromVersion('neo4j-javascript/' + VERSION)
343+
339344
const address = ServerAddress.fromUrl(parsedUrl.hostAndPort)
340345

341346
const meta = {
@@ -344,13 +349,13 @@ function driver (
344349
routing
345350
}
346351

347-
return new Driver(meta, config, createConnectionProviderFunction())
352+
return new Driver(meta, _config, createConnectionProviderFunction())
348353

349354
function createConnectionProviderFunction (): (id: number, config: Config, log: Logger, hostNameResolver: ConfiguredCustomResolver) => ConnectionProvider {
350355
if (routing) {
351356
return (
352357
id: number,
353-
config: Config,
358+
config: InternalConfig,
354359
log: Logger,
355360
hostNameResolver: ConfiguredCustomResolver
356361
): ConnectionProvider =>
@@ -372,7 +377,7 @@ function driver (
372377
)
373378
}
374379

375-
return (id: number, config: Config, log: Logger): ConnectionProvider =>
380+
return (id: number, config: InternalConfig, log: Logger): ConnectionProvider =>
376381
new DirectConnectionProvider({
377382
id,
378383
config,

packages/neo4j-driver-lite/test/integration/browser.environment.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class BrowserEnvironment extends NodeEnvironment {
2323
async setup () {
2424
await super.setup()
2525
this.global.WebSocket = WebSocket
26+
this.global.window = {
27+
navigator: {
28+
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
29+
}
30+
}
2631
}
2732

2833
async teardown () {

0 commit comments

Comments
 (0)