mongodb 6.9.0 → 6.10.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.
Files changed (127) hide show
  1. package/lib/beta.d.ts +407 -12
  2. package/lib/bson.js +1 -0
  3. package/lib/bson.js.map +1 -1
  4. package/lib/bulk/common.js +60 -71
  5. package/lib/bulk/common.js.map +1 -1
  6. package/lib/bulk/unordered.js +3 -3
  7. package/lib/bulk/unordered.js.map +1 -1
  8. package/lib/change_stream.js +3 -2
  9. package/lib/change_stream.js.map +1 -1
  10. package/lib/cmap/auth/mongo_credentials.js +2 -7
  11. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  12. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
  13. package/lib/cmap/auth/mongodb_oidc/command_builders.js +1 -1
  14. package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -1
  15. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +1 -1
  16. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -1
  17. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -1
  18. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  19. package/lib/cmap/command_monitoring_events.js +10 -1
  20. package/lib/cmap/command_monitoring_events.js.map +1 -1
  21. package/lib/cmap/commands.js +50 -18
  22. package/lib/cmap/commands.js.map +1 -1
  23. package/lib/cmap/connection.js +9 -2
  24. package/lib/cmap/connection.js.map +1 -1
  25. package/lib/cmap/wire_protocol/constants.js +2 -2
  26. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  27. package/lib/cmap/wire_protocol/responses.js +26 -1
  28. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  29. package/lib/connection_string.js +1 -7
  30. package/lib/connection_string.js.map +1 -1
  31. package/lib/cursor/aggregation_cursor.js.map +1 -1
  32. package/lib/cursor/client_bulk_write_cursor.js +52 -0
  33. package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
  34. package/lib/cursor/find_cursor.js.map +1 -1
  35. package/lib/db.js +1 -1
  36. package/lib/error.js +76 -3
  37. package/lib/error.js.map +1 -1
  38. package/lib/explain.js +6 -6
  39. package/lib/explain.js.map +1 -1
  40. package/lib/index.js +6 -3
  41. package/lib/index.js.map +1 -1
  42. package/lib/mongo_client.js +14 -0
  43. package/lib/mongo_client.js.map +1 -1
  44. package/lib/mongo_client_auth_providers.js +6 -2
  45. package/lib/mongo_client_auth_providers.js.map +1 -1
  46. package/lib/mongo_types.js.map +1 -1
  47. package/lib/operations/aggregate.js.map +1 -1
  48. package/lib/operations/client_bulk_write/client_bulk_write.js +83 -0
  49. package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
  50. package/lib/operations/client_bulk_write/command_builder.js +154 -19
  51. package/lib/operations/client_bulk_write/command_builder.js.map +1 -1
  52. package/lib/operations/client_bulk_write/executor.js +109 -0
  53. package/lib/operations/client_bulk_write/executor.js.map +1 -0
  54. package/lib/operations/client_bulk_write/results_merger.js +204 -0
  55. package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
  56. package/lib/operations/execute_operation.js +7 -0
  57. package/lib/operations/execute_operation.js.map +1 -1
  58. package/lib/operations/find.js.map +1 -1
  59. package/lib/operations/operation.js +5 -1
  60. package/lib/operations/operation.js.map +1 -1
  61. package/lib/operations/search_indexes/create.js.map +1 -1
  62. package/lib/operations/search_indexes/drop.js.map +1 -1
  63. package/lib/operations/search_indexes/update.js.map +1 -1
  64. package/lib/sdam/server.js +2 -1
  65. package/lib/sdam/server.js.map +1 -1
  66. package/lib/sdam/server_description.js +3 -0
  67. package/lib/sdam/server_description.js.map +1 -1
  68. package/lib/sdam/srv_polling.js +5 -1
  69. package/lib/sdam/srv_polling.js.map +1 -1
  70. package/lib/sdam/topology_description.js.map +1 -1
  71. package/lib/sessions.js +9 -2
  72. package/lib/sessions.js.map +1 -1
  73. package/lib/utils.js +25 -9
  74. package/lib/utils.js.map +1 -1
  75. package/lib/write_concern.js.map +1 -1
  76. package/mongodb.d.ts +407 -12
  77. package/package.json +1 -1
  78. package/src/beta.ts +1 -1
  79. package/src/bson.ts +3 -0
  80. package/src/bulk/common.ts +80 -120
  81. package/src/bulk/unordered.ts +3 -4
  82. package/src/change_stream.ts +5 -2
  83. package/src/cmap/auth/mongo_credentials.ts +2 -8
  84. package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +1 -1
  85. package/src/cmap/auth/mongodb_oidc/command_builders.ts +1 -2
  86. package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +1 -2
  87. package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +1 -1
  88. package/src/cmap/auth/mongodb_oidc.ts +1 -2
  89. package/src/cmap/command_monitoring_events.ts +16 -2
  90. package/src/cmap/commands.ts +71 -25
  91. package/src/cmap/connection.ts +17 -4
  92. package/src/cmap/wire_protocol/constants.ts +2 -2
  93. package/src/cmap/wire_protocol/on_demand/document.ts +1 -2
  94. package/src/cmap/wire_protocol/responses.ts +31 -2
  95. package/src/connection_string.ts +2 -9
  96. package/src/cursor/aggregation_cursor.ts +2 -2
  97. package/src/cursor/client_bulk_write_cursor.ts +79 -0
  98. package/src/cursor/find_cursor.ts +2 -2
  99. package/src/db.ts +1 -1
  100. package/src/error.ts +98 -2
  101. package/src/explain.ts +47 -11
  102. package/src/index.ts +26 -1
  103. package/src/mongo_client.ts +29 -1
  104. package/src/mongo_client_auth_providers.ts +8 -2
  105. package/src/mongo_types.ts +2 -1
  106. package/src/operations/aggregate.ts +9 -1
  107. package/src/operations/client_bulk_write/client_bulk_write.ts +107 -0
  108. package/src/operations/client_bulk_write/command_builder.ts +216 -30
  109. package/src/operations/client_bulk_write/common.ts +148 -23
  110. package/src/operations/client_bulk_write/executor.ts +137 -0
  111. package/src/operations/client_bulk_write/results_merger.ts +260 -0
  112. package/src/operations/execute_operation.ts +8 -0
  113. package/src/operations/find.ts +8 -1
  114. package/src/operations/operation.ts +6 -1
  115. package/src/operations/search_indexes/create.ts +1 -2
  116. package/src/operations/search_indexes/drop.ts +1 -2
  117. package/src/operations/search_indexes/update.ts +1 -2
  118. package/src/sdam/server.ts +2 -1
  119. package/src/sdam/server_description.ts +9 -0
  120. package/src/sdam/srv_polling.ts +5 -2
  121. package/src/sdam/topology_description.ts +0 -1
  122. package/src/sessions.ts +16 -2
  123. package/src/utils.ts +40 -10
  124. package/src/write_concern.ts +4 -1
  125. package/lib/cmap/auth/mongocr.js +0 -35
  126. package/lib/cmap/auth/mongocr.js.map +0 -1
  127. package/src/cmap/auth/mongocr.ts +0 -38
@@ -11,7 +11,8 @@ export const Aspect = {
11
11
  EXPLAINABLE: Symbol('EXPLAINABLE'),
12
12
  SKIP_COLLATION: Symbol('SKIP_COLLATION'),
13
13
  CURSOR_CREATING: Symbol('CURSOR_CREATING'),
14
- MUST_SELECT_SAME_SERVER: Symbol('MUST_SELECT_SAME_SERVER')
14
+ MUST_SELECT_SAME_SERVER: Symbol('MUST_SELECT_SAME_SERVER'),
15
+ COMMAND_BATCHING: Symbol('COMMAND_BATCHING')
15
16
  } as const;
16
17
 
17
18
  /** @public */
@@ -98,6 +99,10 @@ export abstract class AbstractOperation<TResult = any> {
98
99
  this[kSession] = undefined;
99
100
  }
100
101
 
102
+ resetBatch(): boolean {
103
+ return true;
104
+ }
105
+
101
106
  get canRetryRead(): boolean {
102
107
  return this.hasAspect(Aspect.RETRYABLE) && this.hasAspect(Aspect.READ_OPERATION);
103
108
  }
@@ -1,5 +1,4 @@
1
- import type { Document } from 'bson';
2
-
1
+ import type { Document } from '../../bson';
3
2
  import type { Collection } from '../../collection';
4
3
  import type { Server } from '../../sdam/server';
5
4
  import type { ClientSession } from '../../sessions';
@@ -1,5 +1,4 @@
1
- import type { Document } from 'bson';
2
-
1
+ import type { Document } from '../../bson';
3
2
  import type { Collection } from '../../collection';
4
3
  import { MONGODB_ERROR_CODES, MongoServerError } from '../../error';
5
4
  import type { Server } from '../../sdam/server';
@@ -1,5 +1,4 @@
1
- import type { Document } from 'bson';
2
-
1
+ import type { Document } from '../../bson';
3
2
  import type { Collection } from '../../collection';
4
3
  import type { Server } from '../../sdam/server';
5
4
  import type { ClientSession } from '../../sessions';
@@ -513,7 +513,8 @@ function isPinnableCommand(cmd: Document, session?: ClientSession): boolean {
513
513
  'find' in cmd ||
514
514
  'getMore' in cmd ||
515
515
  'listCollections' in cmd ||
516
- 'listIndexes' in cmd
516
+ 'listIndexes' in cmd ||
517
+ 'bulkWrite' in cmd
517
518
  );
518
519
  }
519
520
 
@@ -69,6 +69,12 @@ export class ServerDescription {
69
69
  setVersion: number | null;
70
70
  electionId: ObjectId | null;
71
71
  logicalSessionTimeoutMinutes: number | null;
72
+ /** The max message size in bytes for the server. */
73
+ maxMessageSizeBytes: number | null;
74
+ /** The max number of writes in a bulk write command. */
75
+ maxWriteBatchSize: number | null;
76
+ /** The max bson object size. */
77
+ maxBsonObjectSize: number | null;
72
78
 
73
79
  // NOTE: does this belong here? It seems we should gossip the cluster time at the CMAP level
74
80
  $clusterTime?: ClusterTime;
@@ -111,6 +117,9 @@ export class ServerDescription {
111
117
  this.setVersion = hello?.setVersion ?? null;
112
118
  this.electionId = hello?.electionId ?? null;
113
119
  this.logicalSessionTimeoutMinutes = hello?.logicalSessionTimeoutMinutes ?? null;
120
+ this.maxMessageSizeBytes = hello?.maxMessageSizeBytes ?? null;
121
+ this.maxWriteBatchSize = hello?.maxWriteBatchSize ?? null;
122
+ this.maxBsonObjectSize = hello?.maxBsonObjectSize ?? null;
114
123
  this.primary = hello?.primary ?? null;
115
124
  this.me = hello?.me?.toLowerCase() ?? null;
116
125
  this.$clusterTime = hello?.$clusterTime ?? null;
@@ -3,7 +3,7 @@ import { clearTimeout, setTimeout } from 'timers';
3
3
 
4
4
  import { MongoRuntimeError } from '../error';
5
5
  import { TypedEventEmitter } from '../mongo_types';
6
- import { HostAddress, matchesParentDomain, squashError } from '../utils';
6
+ import { checkParentDomainMatch, HostAddress, squashError } from '../utils';
7
7
 
8
8
  /**
9
9
  * @internal
@@ -127,8 +127,11 @@ export class SrvPoller extends TypedEventEmitter<SrvPollerEvents> {
127
127
 
128
128
  const finalAddresses: dns.SrvRecord[] = [];
129
129
  for (const record of srvRecords) {
130
- if (matchesParentDomain(record.name, this.srvHost)) {
130
+ try {
131
+ checkParentDomainMatch(record.name, this.srvHost);
131
132
  finalAddresses.push(record);
133
+ } catch (error) {
134
+ squashError(error);
132
135
  }
133
136
  }
134
137
 
@@ -43,7 +43,6 @@ export class TopologyDescription {
43
43
  heartbeatFrequencyMS: number;
44
44
  localThresholdMS: number;
45
45
  commonWireVersion: number;
46
-
47
46
  /**
48
47
  * Create a TopologyDescription
49
48
  */
package/src/sessions.ts CHANGED
@@ -124,6 +124,10 @@ export class ClientSession
124
124
  owner?: symbol | AbstractCursor;
125
125
  defaultTransactionOptions: TransactionOptions;
126
126
  transaction: Transaction;
127
+ /** @internal
128
+ * Keeps track of whether or not the current transaction has attempted to be committed. Is
129
+ * initially undefined. Gets set to false when startTransaction is called. When commitTransaction is sent to server, if the commitTransaction succeeds, it is then set to undefined, otherwise, set to true */
130
+ commitAttempted?: boolean;
127
131
  /** @internal */
128
132
  [kServerSession]: ServerSession | null;
129
133
  /** @internal */
@@ -417,6 +421,7 @@ export class ClientSession
417
421
  );
418
422
  }
419
423
 
424
+ this.commitAttempted = false;
420
425
  // increment txnNumber
421
426
  this.incrementTransactionNumber();
422
427
  // create transaction state
@@ -474,7 +479,7 @@ export class ClientSession
474
479
  WriteConcern.apply(command, { wtimeoutMS: 10000, w: 'majority', ...wc });
475
480
  }
476
481
 
477
- if (this.transaction.state === TxnState.TRANSACTION_COMMITTED) {
482
+ if (this.transaction.state === TxnState.TRANSACTION_COMMITTED || this.commitAttempted) {
478
483
  WriteConcern.apply(command, { wtimeoutMS: 10000, ...wc, w: 'majority' });
479
484
  }
480
485
 
@@ -494,8 +499,10 @@ export class ClientSession
494
499
 
495
500
  try {
496
501
  await executeOperation(this.client, operation);
502
+ this.commitAttempted = undefined;
497
503
  return;
498
504
  } catch (firstCommitError) {
505
+ this.commitAttempted = true;
499
506
  if (firstCommitError instanceof MongoError && isRetryableWriteError(firstCommitError)) {
500
507
  // SPEC-1185: apply majority write concern when retrying commitTransaction
501
508
  WriteConcern.apply(command, { wtimeoutMS: 10000, ...wc, w: 'majority' });
@@ -503,7 +510,14 @@ export class ClientSession
503
510
  this.unpin({ force: true });
504
511
 
505
512
  try {
506
- await executeOperation(this.client, operation);
513
+ await executeOperation(
514
+ this.client,
515
+ new RunAdminCommandOperation(command, {
516
+ session: this,
517
+ readPreference: ReadPreference.primary,
518
+ bypassPinningCheck: true
519
+ })
520
+ );
507
521
  return;
508
522
  } catch (retryCommitError) {
509
523
  // If the retry failed, we process that error instead of the original
package/src/utils.ts CHANGED
@@ -18,6 +18,7 @@ import type { FindCursor } from './cursor/find_cursor';
18
18
  import type { Db } from './db';
19
19
  import {
20
20
  type AnyError,
21
+ MongoAPIError,
21
22
  MongoCompatibilityError,
22
23
  MongoInvalidArgumentError,
23
24
  MongoNetworkTimeoutError,
@@ -25,7 +26,7 @@ import {
25
26
  MongoParseError,
26
27
  MongoRuntimeError
27
28
  } from './error';
28
- import type { Explain } from './explain';
29
+ import type { Explain, ExplainVerbosity } from './explain';
29
30
  import type { MongoClient } from './mongo_client';
30
31
  import type { CommandOperationOptions, OperationParent } from './operations/command';
31
32
  import type { Hint, OperationOptions } from './operations/operation';
@@ -251,12 +252,23 @@ export function decorateWithReadConcern(
251
252
  * @param command - the command on which to apply the explain
252
253
  * @param options - the options containing the explain verbosity
253
254
  */
254
- export function decorateWithExplain(command: Document, explain: Explain): Document {
255
- if (command.explain) {
256
- return command;
255
+ export function decorateWithExplain(
256
+ command: Document,
257
+ explain: Explain
258
+ ): {
259
+ explain: Document;
260
+ verbosity: ExplainVerbosity;
261
+ maxTimeMS?: number;
262
+ } {
263
+ type ExplainCommand = ReturnType<typeof decorateWithExplain>;
264
+ const { verbosity, maxTimeMS } = explain;
265
+ const baseCommand: ExplainCommand = { explain: command, verbosity };
266
+
267
+ if (typeof maxTimeMS === 'number') {
268
+ baseCommand.maxTimeMS = maxTimeMS;
257
269
  }
258
270
 
259
- return { explain: command, verbosity: explain.verbosity };
271
+ return baseCommand;
260
272
  }
261
273
 
262
274
  /**
@@ -1131,29 +1143,47 @@ export function parseUnsignedInteger(value: unknown): number | null {
1131
1143
  }
1132
1144
 
1133
1145
  /**
1134
- * Determines whether a provided address matches the provided parent domain.
1146
+ * This function throws a MongoAPIError in the event that either of the following is true:
1147
+ * * If the provided address domain does not match the provided parent domain
1148
+ * * If the parent domain contains less than three `.` separated parts and the provided address does not contain at least one more domain level than its parent
1135
1149
  *
1136
1150
  * If a DNS server were to become compromised SRV records would still need to
1137
1151
  * advertise addresses that are under the same domain as the srvHost.
1138
1152
  *
1139
1153
  * @param address - The address to check against a domain
1140
1154
  * @param srvHost - The domain to check the provided address against
1141
- * @returns Whether the provided address matches the parent domain
1155
+ * @returns void
1142
1156
  */
1143
- export function matchesParentDomain(address: string, srvHost: string): boolean {
1157
+ export function checkParentDomainMatch(address: string, srvHost: string): void {
1144
1158
  // Remove trailing dot if exists on either the resolved address or the srv hostname
1145
1159
  const normalizedAddress = address.endsWith('.') ? address.slice(0, address.length - 1) : address;
1146
1160
  const normalizedSrvHost = srvHost.endsWith('.') ? srvHost.slice(0, srvHost.length - 1) : srvHost;
1147
1161
 
1148
1162
  const allCharacterBeforeFirstDot = /^.*?\./;
1163
+ const srvIsLessThanThreeParts = normalizedSrvHost.split('.').length < 3;
1149
1164
  // Remove all characters before first dot
1150
1165
  // Add leading dot back to string so
1151
1166
  // an srvHostDomain = '.trusted.site'
1152
1167
  // will not satisfy an addressDomain that endsWith '.fake-trusted.site'
1153
1168
  const addressDomain = `.${normalizedAddress.replace(allCharacterBeforeFirstDot, '')}`;
1154
- const srvHostDomain = `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
1169
+ let srvHostDomain = srvIsLessThanThreeParts
1170
+ ? normalizedSrvHost
1171
+ : `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, '')}`;
1155
1172
 
1156
- return addressDomain.endsWith(srvHostDomain);
1173
+ if (!srvHostDomain.startsWith('.')) {
1174
+ srvHostDomain = '.' + srvHostDomain;
1175
+ }
1176
+ if (
1177
+ srvIsLessThanThreeParts &&
1178
+ normalizedAddress.split('.').length <= normalizedSrvHost.split('.').length
1179
+ ) {
1180
+ throw new MongoAPIError(
1181
+ 'Server record does not have at least one more domain level than parent URI'
1182
+ );
1183
+ }
1184
+ if (!addressDomain.endsWith(srvHostDomain)) {
1185
+ throw new MongoAPIError('Server record does not share hostname with parent URI');
1186
+ }
1157
1187
  }
1158
1188
 
1159
1189
  interface RequestOptions {
@@ -58,7 +58,10 @@ interface CommandWriteConcernOptions {
58
58
  * @see https://www.mongodb.com/docs/manual/reference/write-concern/
59
59
  */
60
60
  export class WriteConcern {
61
- /** Request acknowledgment that the write operation has propagated to a specified number of mongod instances or to mongod instances with specified tags. */
61
+ /**
62
+ * Request acknowledgment that the write operation has propagated to a specified number of mongod instances or to mongod instances with specified tags.
63
+ * If w is 0 and is set on a write operation, the server will not send a response.
64
+ */
62
65
  readonly w?: W;
63
66
  /** Request acknowledgment that the write operation has been written to the on-disk journal */
64
67
  readonly journal?: boolean;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoCR = void 0;
4
- const crypto = require("crypto");
5
- const error_1 = require("../../error");
6
- const utils_1 = require("../../utils");
7
- const auth_provider_1 = require("./auth_provider");
8
- class MongoCR extends auth_provider_1.AuthProvider {
9
- async auth(authContext) {
10
- const { connection, credentials } = authContext;
11
- if (!credentials) {
12
- throw new error_1.MongoMissingCredentialsError('AuthContext must provide credentials.');
13
- }
14
- const { username, password, source } = credentials;
15
- const { nonce } = await connection.command((0, utils_1.ns)(`${source}.$cmd`), { getnonce: 1 }, undefined);
16
- const hashPassword = crypto
17
- .createHash('md5')
18
- .update(`${username}:mongo:${password}`, 'utf8')
19
- .digest('hex');
20
- // Final key
21
- const key = crypto
22
- .createHash('md5')
23
- .update(`${nonce}${username}${hashPassword}`, 'utf8')
24
- .digest('hex');
25
- const authenticateCommand = {
26
- authenticate: 1,
27
- user: username,
28
- nonce,
29
- key
30
- };
31
- await connection.command((0, utils_1.ns)(`${source}.$cmd`), authenticateCommand, undefined);
32
- }
33
- }
34
- exports.MongoCR = MongoCR;
35
- //# sourceMappingURL=mongocr.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongocr.js","sourceRoot":"","sources":["../../../src/cmap/auth/mongocr.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,uCAA2D;AAC3D,uCAAiC;AACjC,mDAAiE;AAEjE,MAAa,OAAQ,SAAQ,4BAAY;IAC9B,KAAK,CAAC,IAAI,CAAC,WAAwB;QAC1C,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,WAAW,CAAC;QAChD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,oCAA4B,CAAC,uCAAuC,CAAC,CAAC;QAClF,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC;QAEnD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,IAAA,UAAE,EAAC,GAAG,MAAM,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;QAE7F,MAAM,YAAY,GAAG,MAAM;aACxB,UAAU,CAAC,KAAK,CAAC;aACjB,MAAM,CAAC,GAAG,QAAQ,UAAU,QAAQ,EAAE,EAAE,MAAM,CAAC;aAC/C,MAAM,CAAC,KAAK,CAAC,CAAC;QAEjB,YAAY;QACZ,MAAM,GAAG,GAAG,MAAM;aACf,UAAU,CAAC,KAAK,CAAC;aACjB,MAAM,CAAC,GAAG,KAAK,GAAG,QAAQ,GAAG,YAAY,EAAE,EAAE,MAAM,CAAC;aACpD,MAAM,CAAC,KAAK,CAAC,CAAC;QAEjB,MAAM,mBAAmB,GAAG;YAC1B,YAAY,EAAE,CAAC;YACf,IAAI,EAAE,QAAQ;YACd,KAAK;YACL,GAAG;SACJ,CAAC;QAEF,MAAM,UAAU,CAAC,OAAO,CAAC,IAAA,UAAE,EAAC,GAAG,MAAM,OAAO,CAAC,EAAE,mBAAmB,EAAE,SAAS,CAAC,CAAC;IACjF,CAAC;CACF;AA/BD,0BA+BC"}
@@ -1,38 +0,0 @@
1
- import * as crypto from 'crypto';
2
-
3
- import { MongoMissingCredentialsError } from '../../error';
4
- import { ns } from '../../utils';
5
- import { type AuthContext, AuthProvider } from './auth_provider';
6
-
7
- export class MongoCR extends AuthProvider {
8
- override async auth(authContext: AuthContext): Promise<void> {
9
- const { connection, credentials } = authContext;
10
- if (!credentials) {
11
- throw new MongoMissingCredentialsError('AuthContext must provide credentials.');
12
- }
13
-
14
- const { username, password, source } = credentials;
15
-
16
- const { nonce } = await connection.command(ns(`${source}.$cmd`), { getnonce: 1 }, undefined);
17
-
18
- const hashPassword = crypto
19
- .createHash('md5')
20
- .update(`${username}:mongo:${password}`, 'utf8')
21
- .digest('hex');
22
-
23
- // Final key
24
- const key = crypto
25
- .createHash('md5')
26
- .update(`${nonce}${username}${hashPassword}`, 'utf8')
27
- .digest('hex');
28
-
29
- const authenticateCommand = {
30
- authenticate: 1,
31
- user: username,
32
- nonce,
33
- key
34
- };
35
-
36
- await connection.command(ns(`${source}.$cmd`), authenticateCommand, undefined);
37
- }
38
- }