Skip to content

Commit 25ef870

Browse files
authored
fix: restore createAutoEncrypter() functionality (#2710)
Corrects the import name of the AutoEncrypter class. Passes through client constructor options to CSFLE lib. NODE-3042
1 parent 16a22c4 commit 25ef870

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/connection_string.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ export function parseOptions(
418418

419419
checkTLSOptions(mongoOptions);
420420
if (mongoClient && options.autoEncryption) {
421-
mongoOptions.autoEncrypter = createAutoEncrypter(mongoClient);
421+
mongoOptions.autoEncrypter = createAutoEncrypter(mongoClient, options);
422422
}
423423
if (options.promiseLibrary) PromiseProvider.set(options.promiseLibrary);
424424

src/operations/connect.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { resolveSRVRecord } from '../connection_string';
44
import { emitDeprecationWarning, Callback } from '../utils';
55
import { CMAP_EVENT_NAMES } from '../cmap/events';
66
import * as BSON from '../bson';
7-
import type { MongoClient, MongoOptions } from '../mongo_client';
7+
import type { MongoClient, MongoOptions, MongoClientOptions } from '../mongo_client';
88
import { Connection } from '../cmap/connection';
99
import { Server } from '../sdam/server';
1010
import type { AutoEncrypter } from '../deps';
@@ -114,8 +114,11 @@ function registerDeprecatedEventNotifiers(client: MongoClient) {
114114
* returns undefined if CSFLE is not enabled.
115115
* @throws if optional 'mongodb-client-encryption' dependency missing
116116
*/
117-
export function createAutoEncrypter(client: MongoClient): AutoEncrypter | undefined {
118-
if (!client.options.autoEncryption) {
117+
export function createAutoEncrypter(
118+
client: MongoClient,
119+
options: MongoClientOptions
120+
): AutoEncrypter | undefined {
121+
if (!options.autoEncryption) {
119122
return;
120123
}
121124
try {
@@ -135,10 +138,12 @@ export function createAutoEncrypter(client: MongoClient): AutoEncrypter | undefi
135138
'Please make sure you are loading the correct version of `mongodb-client-encryption`'
136139
);
137140
}
138-
// eslint-disable-next-line @typescript-eslint/no-var-requires
139-
const { AutoEncrypterClass } = mongodbClientEncryption.extension(require('../../lib/index'));
141+
const { AutoEncrypter: AutoEncrypterClass } = mongodbClientEncryption.extension(
142+
// eslint-disable-next-line @typescript-eslint/no-var-requires
143+
require('../../lib/index')
144+
);
140145

141-
const mongoCryptOptions = Object.assign({ bson: BSON }, client.options.autoEncryption);
146+
const mongoCryptOptions = Object.assign({ bson: BSON }, options.autoEncryption);
142147
return new AutoEncrypterClass(client, mongoCryptOptions);
143148
}
144149

0 commit comments

Comments
 (0)