Skip to content

feat(NODE-4751)!: drop support for client encryption < 2.3.0 #3521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@
},
"peerDependencies": {
"@aws-sdk/credential-providers": "^3.201.0",
"snappy": "7.x.x"
"snappy": "7.x.x",
"mongodb-client-encryption": "^2.3.0"
},
"peerDependenciesMeta": {
"@aws-sdk/credential-providers": {
"optional": true
},
"snappy": {
"optional": true
},
"mongodb-client-encryption": {
"optional": true
}
},
"devDependencies": {
Expand Down
7 changes: 0 additions & 7 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ import {
Callback,
checkCollectionName,
DEFAULT_PK_FACTORY,
emitWarningOnce,
MongoDBNamespace,
normalizeHintField,
resolveOptions
Expand Down Expand Up @@ -283,12 +282,6 @@ export class Collection<TSchema extends Document = Document> {
options = {};
}

// versions of mongodb-client-encryption before v1.2.6 pass in hardcoded { w: 'majority' }
// specifically to an insertOne call in createDataKey, so we want to support this only here
if (options && Reflect.get(options, 'w')) {
options.writeConcern = WriteConcern.fromOptions(Reflect.get(options, 'w'));
}

return executeOperation(
this.s.db.s.client,
new InsertOneOperation(
Expand Down
4 changes: 1 addition & 3 deletions src/deps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import type { deserialize, Document, serialize } from './bson';
import type { Document } from './bson';
import type { AWSCredentials } from './cmap/auth/mongodb_aws';
import type { ProxyOptions } from './cmap/connection';
import { MongoMissingDependencyError } from './error';
Expand Down Expand Up @@ -214,8 +214,6 @@ export interface AutoEncryptionTlsOptions {

/** @public */
export interface AutoEncryptionOptions {
/** @internal */
bson?: { serialize: typeof serialize; deserialize: typeof deserialize };
/** @internal client for metadata lookups */
metadataClient?: MongoClient;
/** A `MongoClient` used to fetch keys from a key vault */
Expand Down
7 changes: 0 additions & 7 deletions src/encrypter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/no-var-requires */

import { deserialize, serialize } from './bson';
import { MONGO_CLIENT_EVENTS } from './constants';
import type { AutoEncrypter, AutoEncryptionOptions } from './deps';
import { MongoInvalidArgumentError, MongoMissingDependencyError } from './error';
Expand Down Expand Up @@ -58,12 +57,6 @@ export class Encrypter {
};
}

options.autoEncryption.bson = Object.create(null);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
options.autoEncryption.bson!.serialize = serialize;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
options.autoEncryption.bson!.deserialize = deserialize;

this.autoEncrypter = new AutoEncrypterClass(client, options.autoEncryption);
}

Expand Down
17 changes: 0 additions & 17 deletions src/sdam/topology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { clearTimeout, setTimeout } from 'timers';
import { promisify } from 'util';

import type { BSONSerializeOptions, Document } from '../bson';
import { deserialize, serialize } from '../bson';
import type { MongoCredentials } from '../cmap/auth/mongo_credentials';
import type { ConnectionEvents, DestroyOptions } from '../cmap/connection';
import type { CloseOptions, ConnectionPoolEvents } from '../cmap/connection_pool';
Expand Down Expand Up @@ -222,16 +221,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
/** @event */
static readonly TIMEOUT = TIMEOUT;

/**
* @internal
*
* @privateRemarks
* mongodb-client-encryption's class ClientEncryption falls back to finding the bson lib
* defined on client.topology.bson, in order to maintain compatibility with any version
* of mongodb-client-encryption we keep a reference to serialize and deserialize here.
*/
bson: { serialize: typeof serialize; deserialize: typeof deserialize };

selectServerAsync: (
selector: string | ReadPreference | ServerSelector,
options: SelectServerOptions
Expand All @@ -251,12 +240,6 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
) => this.selectServer(selector, options, callback as any)
);

// Saving a reference to these BSON functions
// supports v2.2.0 and older versions of mongodb-client-encryption
this.bson = Object.create(null);
this.bson.serialize = serialize;
this.bson.deserialize = deserialize;

// Options should only be undefined in tests, MongoClient will always have defined options
options = options ?? {
hosts: [HostAddress.fromString('localhost:27017')],
Expand Down
6 changes: 5 additions & 1 deletion test/action/dependency.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { expect } from 'chai';
import { dependencies, peerDependencies, peerDependenciesMeta } from '../../package.json';

const EXPECTED_DEPENDENCIES = ['bson', 'mongodb-connection-string-url', 'socks'];
const EXPECTED_PEER_DEPENDENCIES = ['@aws-sdk/credential-providers', 'snappy'];
const EXPECTED_PEER_DEPENDENCIES = [
'@aws-sdk/credential-providers',
'snappy',
'mongodb-client-encryption'
];

describe('package.json', function () {
describe('dependencies', function () {
Expand Down