mongodb 5.1.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -22
- package/lib/admin.js +2 -0
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +28 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +1 -1
- package/lib/cmap/auth/auth_provider.js +21 -10
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +71 -116
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +7 -9
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +20 -29
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +125 -140
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +28 -0
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +178 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +41 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +115 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js +3 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +59 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/auth/plain.js +4 -5
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +1 -1
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/auth/scram.js +45 -73
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +8 -11
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +14 -5
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +73 -86
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +19 -23
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +56 -14
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +28 -3
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/handshake/client_metadata.js +173 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -16
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +10 -10
- package/lib/connection_string.js +50 -69
- package/lib/connection_string.js.map +1 -1
- package/lib/constants.js +11 -0
- package/lib/constants.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +2 -1
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/db.js +4 -2
- package/lib/db.js.map +1 -1
- package/lib/error.js +2 -1
- package/lib/error.js.map +1 -1
- package/lib/mongo_client.js +23 -2
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +236 -23
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/execute_operation.js +8 -27
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +1 -8
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/read_concern.js +1 -1
- package/lib/read_preference.js +2 -2
- package/lib/sdam/srv_polling.js +1 -15
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +0 -16
- package/lib/sdam/topology.js.map +1 -1
- package/lib/utils.js +33 -90
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +1 -1
- package/mongodb.d.ts +242 -93
- package/package.json +30 -31
- package/src/admin.ts +2 -0
- package/src/bulk/common.ts +29 -8
- package/src/change_stream.ts +5 -5
- package/src/cmap/auth/auth_provider.ts +29 -16
- package/src/cmap/auth/gssapi.ts +102 -149
- package/src/cmap/auth/mongo_credentials.ts +14 -23
- package/src/cmap/auth/mongocr.ts +31 -36
- package/src/cmap/auth/mongodb_aws.ts +166 -189
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +26 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +259 -0
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +47 -0
- package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +166 -0
- package/src/cmap/auth/mongodb_oidc/workflow.ts +21 -0
- package/src/cmap/auth/mongodb_oidc.ts +101 -17
- package/src/cmap/auth/plain.ts +6 -6
- package/src/cmap/auth/providers.ts +2 -2
- package/src/cmap/auth/scram.ts +56 -90
- package/src/cmap/auth/x509.ts +12 -18
- package/src/cmap/command_monitoring_events.ts +18 -3
- package/src/cmap/commands.ts +1 -1
- package/src/cmap/connect.ts +92 -114
- package/src/cmap/connection.ts +39 -25
- package/src/cmap/connection_pool.ts +89 -18
- package/src/cmap/connection_pool_events.ts +68 -6
- package/src/cmap/handshake/client_metadata.ts +272 -0
- package/src/cmap/message_stream.ts +0 -2
- package/src/cmap/wire_protocol/compression.ts +1 -1
- package/src/cmap/wire_protocol/shared.ts +1 -23
- package/src/collection.ts +13 -13
- package/src/connection_string.ts +56 -72
- package/src/constants.ts +11 -0
- package/src/cursor/abstract_cursor.ts +3 -2
- package/src/cursor/change_stream_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +1 -1
- package/src/db.ts +4 -2
- package/src/deps.ts +3 -2
- package/src/error.ts +3 -2
- package/src/index.ts +21 -3
- package/src/mongo_client.ts +60 -14
- package/src/mongo_logger.ts +341 -40
- package/src/mongo_types.ts +2 -2
- package/src/operations/add_user.ts +8 -2
- package/src/operations/aggregate.ts +1 -1
- package/src/operations/create_collection.ts +1 -1
- package/src/operations/execute_operation.ts +8 -25
- package/src/operations/find.ts +1 -11
- package/src/operations/find_and_modify.ts +4 -4
- package/src/operations/set_profiling_level.ts +1 -1
- package/src/operations/stats.ts +1 -1
- package/src/operations/update.ts +8 -4
- package/src/read_concern.ts +2 -2
- package/src/read_preference.ts +3 -3
- package/src/sdam/common.ts +2 -2
- package/src/sdam/srv_polling.ts +1 -16
- package/src/sdam/topology.ts +1 -23
- package/src/transactions.ts +1 -1
- package/src/utils.ts +37 -147
- package/src/write_concern.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"email": "dbx-node@mongodb.com"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"bson": "^5.0
|
|
28
|
+
"bson": "^5.2.0",
|
|
29
29
|
"mongodb-connection-string-url": "^2.6.0",
|
|
30
30
|
"socks": "^2.7.1"
|
|
31
31
|
},
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@aws-sdk/credential-providers": "^3.201.0",
|
|
37
|
-
"mongodb-client-encryption": "
|
|
37
|
+
"mongodb-client-encryption": ">=2.3.0 <3",
|
|
38
38
|
"snappy": "^7.2.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
@@ -51,52 +51,51 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@iarna/toml": "^2.2.5",
|
|
53
53
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
54
|
-
"@microsoft/api-extractor": "^7.
|
|
54
|
+
"@microsoft/api-extractor": "^7.34.4",
|
|
55
55
|
"@microsoft/tsdoc-config": "^0.16.2",
|
|
56
|
-
"@mongodb-js/zstd": "^1.
|
|
57
|
-
"@types/chai": "^4.3.
|
|
56
|
+
"@mongodb-js/zstd": "^1.1.0",
|
|
57
|
+
"@types/chai": "^4.3.4",
|
|
58
58
|
"@types/chai-subset": "^1.3.3",
|
|
59
|
-
"@types/express": "^4.17.
|
|
59
|
+
"@types/express": "^4.17.17",
|
|
60
60
|
"@types/kerberos": "^1.1.1",
|
|
61
|
-
"@types/mocha": "^10.0.
|
|
62
|
-
"@types/node": "^18.11.
|
|
61
|
+
"@types/mocha": "^10.0.1",
|
|
62
|
+
"@types/node": "^18.11.19",
|
|
63
63
|
"@types/saslprep": "^1.0.1",
|
|
64
|
-
"@types/semver": "^7.3.
|
|
64
|
+
"@types/semver": "^7.3.13",
|
|
65
65
|
"@types/sinon": "^10.0.13",
|
|
66
|
-
"@types/sinon-chai": "^3.2.
|
|
66
|
+
"@types/sinon-chai": "^3.2.9",
|
|
67
67
|
"@types/whatwg-url": "^11.0.0",
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
69
|
-
"@typescript-eslint/parser": "^5.
|
|
70
|
-
"chai": "^4.3.
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
69
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
70
|
+
"chai": "^4.3.7",
|
|
71
71
|
"chai-subset": "^1.6.0",
|
|
72
72
|
"chalk": "^4.1.2",
|
|
73
|
-
"eslint": "^8.
|
|
74
|
-
"eslint-config-prettier": "^8.
|
|
75
|
-
"eslint-plugin-import": "^2.
|
|
73
|
+
"eslint": "^8.36.0",
|
|
74
|
+
"eslint-config-prettier": "^8.7.0",
|
|
75
|
+
"eslint-plugin-import": "^2.27.5",
|
|
76
76
|
"eslint-plugin-prettier": "^4.2.1",
|
|
77
|
-
"eslint-plugin-simple-import-sort": "^
|
|
77
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
78
78
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
79
79
|
"express": "^4.18.2",
|
|
80
80
|
"js-yaml": "^4.1.0",
|
|
81
|
-
"mocha": "^
|
|
81
|
+
"mocha": "^10.2.0",
|
|
82
82
|
"mocha-sinon": "^2.1.2",
|
|
83
|
-
"mongodb-legacy": "^
|
|
83
|
+
"mongodb-legacy": "^5.0.0",
|
|
84
84
|
"nyc": "^15.1.0",
|
|
85
|
-
"prettier": "^2.
|
|
86
|
-
"rimraf": "^3.0.2",
|
|
85
|
+
"prettier": "^2.8.4",
|
|
87
86
|
"semver": "^7.3.8",
|
|
88
|
-
"sinon": "^
|
|
87
|
+
"sinon": "^15.0.2",
|
|
89
88
|
"sinon-chai": "^3.7.0",
|
|
90
89
|
"snappy": "^7.2.2",
|
|
91
90
|
"source-map-support": "^0.5.21",
|
|
92
91
|
"standard-version": "^9.5.0",
|
|
93
92
|
"ts-node": "^10.9.1",
|
|
94
|
-
"tsd": "^0.
|
|
95
|
-
"typescript": "^4.9.
|
|
93
|
+
"tsd": "^0.27.0",
|
|
94
|
+
"typescript": "^4.9.5",
|
|
96
95
|
"typescript-cached-transpile": "^0.0.6",
|
|
97
96
|
"v8-heapsnapshot": "^1.2.0",
|
|
98
97
|
"xml2js": "^0.4.23",
|
|
99
|
-
"yargs": "^17.
|
|
98
|
+
"yargs": "^17.7.1"
|
|
100
99
|
},
|
|
101
100
|
"license": "Apache-2.0",
|
|
102
101
|
"engines": {
|
|
@@ -109,7 +108,7 @@
|
|
|
109
108
|
"scripts": {
|
|
110
109
|
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
|
|
111
110
|
"build:ts": "node ./node_modules/typescript/bin/tsc",
|
|
112
|
-
"build:dts": "npm run build:ts && api-extractor run &&
|
|
111
|
+
"build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs",
|
|
113
112
|
"build:docs": "./etc/docs/build.ts",
|
|
114
113
|
"build:typedoc": "typedoc",
|
|
115
114
|
"check:bench": "node test/benchmarks/driverBench",
|
|
@@ -127,12 +126,12 @@
|
|
|
127
126
|
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
|
|
128
127
|
"check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
|
|
129
128
|
"check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
|
|
130
|
-
"check:aws": "mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.ts",
|
|
131
|
-
"check:oidc": "mocha --config test/
|
|
129
|
+
"check:aws": "nyc mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.ts",
|
|
130
|
+
"check:oidc": "mocha --config test/manual/mocharc.json test/manual/mongodb_oidc.prose.test.ts",
|
|
132
131
|
"check:ocsp": "mocha --config test/manual/mocharc.json test/manual/ocsp_support.test.js",
|
|
133
|
-
"check:kerberos": "mocha --config test/manual/mocharc.json test/manual/kerberos.test.
|
|
132
|
+
"check:kerberos": "nyc mocha --config test/manual/mocharc.json test/manual/kerberos.test.ts",
|
|
134
133
|
"check:tls": "mocha --config test/manual/mocharc.json test/manual/tls_support.test.js",
|
|
135
|
-
"check:ldap": "mocha --config test/manual/mocharc.json test/manual/ldap.test.js",
|
|
134
|
+
"check:ldap": "nyc mocha --config test/manual/mocharc.json test/manual/ldap.test.js",
|
|
136
135
|
"check:socks5": "mocha --config test/manual/mocharc.json test/manual/socks5.test.ts",
|
|
137
136
|
"check:csfle": "mocha --config test/mocha_mongodb.json test/integration/client-side-encryption",
|
|
138
137
|
"check:snappy": "mocha test/unit/assorted/snappy.test.js",
|
package/src/admin.ts
CHANGED
|
@@ -106,6 +106,8 @@ export class Admin {
|
|
|
106
106
|
* @param username - The username for the new user
|
|
107
107
|
* @param passwordOrOptions - An optional password for the new user, or the options for the command
|
|
108
108
|
* @param options - Optional settings for the command
|
|
109
|
+
* @deprecated Use the createUser command in `db.command()` instead.
|
|
110
|
+
* @see https://www.mongodb.com/docs/manual/reference/command/createUser/
|
|
109
111
|
*/
|
|
110
112
|
async addUser(
|
|
111
113
|
username: string,
|
package/src/bulk/common.ts
CHANGED
|
@@ -39,7 +39,7 @@ export const BatchType = Object.freeze({
|
|
|
39
39
|
} as const);
|
|
40
40
|
|
|
41
41
|
/** @public */
|
|
42
|
-
export type BatchType = typeof BatchType[keyof typeof BatchType];
|
|
42
|
+
export type BatchType = (typeof BatchType)[keyof typeof BatchType];
|
|
43
43
|
|
|
44
44
|
/** @public */
|
|
45
45
|
export interface InsertOneModel<TSchema extends Document = Document> {
|
|
@@ -212,37 +212,58 @@ export class BulkWriteResult {
|
|
|
212
212
|
return this.result.ok;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* The number of inserted documents
|
|
217
|
+
* @deprecated Use insertedCount instead.
|
|
218
|
+
*/
|
|
216
219
|
get nInserted(): number {
|
|
217
220
|
return this.result.nInserted;
|
|
218
221
|
}
|
|
219
222
|
|
|
220
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* Number of upserted documents
|
|
225
|
+
* @deprecated User upsertedCount instead.
|
|
226
|
+
*/
|
|
221
227
|
get nUpserted(): number {
|
|
222
228
|
return this.result.nUpserted;
|
|
223
229
|
}
|
|
224
230
|
|
|
225
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* Number of matched documents
|
|
233
|
+
* @deprecated Use matchedCount instead.
|
|
234
|
+
*/
|
|
226
235
|
get nMatched(): number {
|
|
227
236
|
return this.result.nMatched;
|
|
228
237
|
}
|
|
229
238
|
|
|
230
|
-
/**
|
|
239
|
+
/**
|
|
240
|
+
* Number of documents updated physically on disk
|
|
241
|
+
* @deprecated Use modifiedCount instead.
|
|
242
|
+
*/
|
|
231
243
|
get nModified(): number {
|
|
232
244
|
return this.result.nModified;
|
|
233
245
|
}
|
|
234
246
|
|
|
235
|
-
/**
|
|
247
|
+
/**
|
|
248
|
+
* Number of removed documents
|
|
249
|
+
* @deprecated Use deletedCount instead.
|
|
250
|
+
*/
|
|
236
251
|
get nRemoved(): number {
|
|
237
252
|
return this.result.nRemoved;
|
|
238
253
|
}
|
|
239
254
|
|
|
240
|
-
/**
|
|
255
|
+
/**
|
|
256
|
+
* Returns an array of all inserted ids
|
|
257
|
+
* @deprecated Use insertedIds instead.
|
|
258
|
+
*/
|
|
241
259
|
getInsertedIds(): Document[] {
|
|
242
260
|
return this.result.insertedIds;
|
|
243
261
|
}
|
|
244
262
|
|
|
245
|
-
/**
|
|
263
|
+
/**
|
|
264
|
+
* Returns an array of all upserted ids
|
|
265
|
+
* @deprecated Use upsertedIds instead.
|
|
266
|
+
*/
|
|
246
267
|
getUpsertedIds(): Document[] {
|
|
247
268
|
return this.result.upserted;
|
|
248
269
|
}
|
package/src/change_stream.ts
CHANGED
|
@@ -74,7 +74,7 @@ export type ResumeToken = unknown;
|
|
|
74
74
|
/**
|
|
75
75
|
* Represents a specific point in time on a server. Can be retrieved by using `db.command()`
|
|
76
76
|
* @public
|
|
77
|
-
* @see https://
|
|
77
|
+
* @see https://www.mongodb.com/docs/manual/reference/method/db.runCommand/#response
|
|
78
78
|
*/
|
|
79
79
|
export type OperationTime = Timestamp;
|
|
80
80
|
|
|
@@ -117,19 +117,19 @@ export interface ChangeStreamOptions extends Omit<AggregateOptions, 'writeConcer
|
|
|
117
117
|
maxAwaitTimeMS?: number;
|
|
118
118
|
/**
|
|
119
119
|
* Allows you to start a changeStream after a specified event.
|
|
120
|
-
* @see https://
|
|
120
|
+
* @see https://www.mongodb.com/docs/manual/changeStreams/#resumeafter-for-change-streams
|
|
121
121
|
*/
|
|
122
122
|
resumeAfter?: ResumeToken;
|
|
123
123
|
/**
|
|
124
124
|
* Similar to resumeAfter, but will allow you to start after an invalidated event.
|
|
125
|
-
* @see https://
|
|
125
|
+
* @see https://www.mongodb.com/docs/manual/changeStreams/#startafter-for-change-streams
|
|
126
126
|
*/
|
|
127
127
|
startAfter?: ResumeToken;
|
|
128
128
|
/** Will start the changeStream after the specified operationTime. */
|
|
129
129
|
startAtOperationTime?: OperationTime;
|
|
130
130
|
/**
|
|
131
131
|
* The number of documents to return per batch.
|
|
132
|
-
* @see https://
|
|
132
|
+
* @see https://www.mongodb.com/docs/manual/reference/command/aggregate
|
|
133
133
|
*/
|
|
134
134
|
batchSize?: number;
|
|
135
135
|
|
|
@@ -583,7 +583,7 @@ export class ChangeStream<
|
|
|
583
583
|
* @internal
|
|
584
584
|
*
|
|
585
585
|
* @param parent - The parent object that created this change stream
|
|
586
|
-
* @param pipeline - An array of {@link https://
|
|
586
|
+
* @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents
|
|
587
587
|
*/
|
|
588
588
|
constructor(
|
|
589
589
|
parent: OperationParent,
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import type { Document } from '../../bson';
|
|
2
2
|
import { MongoRuntimeError } from '../../error';
|
|
3
|
-
import type { Callback, ClientMetadataOptions } from '../../utils';
|
|
4
3
|
import type { HandshakeDocument } from '../connect';
|
|
5
4
|
import type { Connection, ConnectionOptions } from '../connection';
|
|
6
5
|
import type { MongoCredentials } from './mongo_credentials';
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Context used during authentication
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
11
|
export class AuthContext {
|
|
12
12
|
/** The connection to authenticate */
|
|
13
13
|
connection: Connection;
|
|
14
14
|
/** The credentials to use for authentication */
|
|
15
15
|
credentials?: MongoCredentials;
|
|
16
|
+
/** If the context is for reauthentication. */
|
|
17
|
+
reauthenticating = false;
|
|
16
18
|
/** The options passed to the `connect` method */
|
|
17
|
-
options:
|
|
19
|
+
options: ConnectionOptions;
|
|
18
20
|
|
|
19
21
|
/** A response from an initial auth attempt, only some mechanisms use this (e.g, SCRAM) */
|
|
20
22
|
response?: Document;
|
|
@@ -24,7 +26,7 @@ export class AuthContext {
|
|
|
24
26
|
constructor(
|
|
25
27
|
connection: Connection,
|
|
26
28
|
credentials: MongoCredentials | undefined,
|
|
27
|
-
options:
|
|
29
|
+
options: ConnectionOptions
|
|
28
30
|
) {
|
|
29
31
|
this.connection = connection;
|
|
30
32
|
this.credentials = credentials;
|
|
@@ -32,29 +34,40 @@ export class AuthContext {
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
export class AuthProvider {
|
|
37
|
+
export abstract class AuthProvider {
|
|
36
38
|
/**
|
|
37
39
|
* Prepare the handshake document before the initial handshake.
|
|
38
40
|
*
|
|
39
41
|
* @param handshakeDoc - The document used for the initial handshake on a connection
|
|
40
42
|
* @param authContext - Context for authentication flow
|
|
41
43
|
*/
|
|
42
|
-
prepare(
|
|
44
|
+
async prepare(
|
|
43
45
|
handshakeDoc: HandshakeDocument,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
callback(undefined, handshakeDoc);
|
|
46
|
+
_authContext: AuthContext
|
|
47
|
+
): Promise<HandshakeDocument> {
|
|
48
|
+
return handshakeDoc;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* Authenticate
|
|
52
53
|
*
|
|
53
54
|
* @param context - A shared context for authentication flow
|
|
54
|
-
* @param callback - The callback to return the result from the authentication
|
|
55
55
|
*/
|
|
56
|
-
auth(context: AuthContext
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
abstract auth(context: AuthContext): Promise<void>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Reauthenticate.
|
|
60
|
+
* @param context - The shared auth context.
|
|
61
|
+
*/
|
|
62
|
+
async reauth(context: AuthContext): Promise<void> {
|
|
63
|
+
if (context.reauthenticating) {
|
|
64
|
+
throw new MongoRuntimeError('Reauthentication already in progress.');
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
context.reauthenticating = true;
|
|
68
|
+
await this.auth(context);
|
|
69
|
+
} finally {
|
|
70
|
+
context.reauthenticating = false;
|
|
71
|
+
}
|
|
59
72
|
}
|
|
60
73
|
}
|