@@ -12,6 +12,7 @@ import { LEGACY_HELLO_COMMAND } from './constants';
1212import type { AbstractCursor } from './cursor/abstract_cursor' ;
1313import type { FindCursor } from './cursor/find_cursor' ;
1414import type { Db } from './db' ;
15+ import type { AutoEncrypter } from './deps' ;
1516import {
1617 AnyError ,
1718 MongoCompatibilityError ,
@@ -1409,24 +1410,34 @@ export function commandSupportsReadConcern(command: Document, options?: Document
14091410 return false ;
14101411}
14111412
1412- /**
1413- * A utility function to get the instance of mongodb-client-encryption, if it exists.
1414- *
1415- * @throws MongoMissingDependencyError if mongodb-client-encryption isn't installed.
1416- * @returns
1417- */
1418- export function getMongoDBClientEncryption ( ) {
1419- let mongodbClientEncryption ;
1413+ /** A utility function to get the instance of mongodb-client-encryption, if it exists. */
1414+ export function getMongoDBClientEncryption ( ) : {
1415+ extension : ( mdb : typeof import ( '../src/index' ) ) => {
1416+ AutoEncrypter : any ;
1417+ ClientEncryption : any ;
1418+ } ;
1419+ } | null {
1420+ let mongodbClientEncryption = null ;
14201421
14211422 // NOTE(NODE-4254): This is to get around the circular dependency between
14221423 // mongodb-client-encryption and the driver in the test scenarios.
14231424 if (
14241425 typeof process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE === 'string' &&
14251426 process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE . length > 0
14261427 ) {
1427- mongodbClientEncryption = require ( process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE ) ;
1428+ try {
1429+ // NOTE(NODE-3199): Ensure you always wrap an optional require in the try block
1430+ mongodbClientEncryption = require ( process . env . MONGODB_CLIENT_ENCRYPTION_OVERRIDE ) ;
1431+ } catch {
1432+ // ignore
1433+ }
14281434 } else {
1429- mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
1435+ try {
1436+ // NOTE(NODE-3199): Ensure you always wrap an optional require in the try block
1437+ mongodbClientEncryption = require ( 'mongodb-client-encryption' ) ;
1438+ } catch {
1439+ // ignore
1440+ }
14301441 }
14311442
14321443 return mongodbClientEncryption ;
0 commit comments