@depup/mongodb 7.1.0-depup.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 (396) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +33 -0
  3. package/etc/prepare.js +12 -0
  4. package/lib/admin.js +136 -0
  5. package/lib/admin.js.map +1 -0
  6. package/lib/bson.js +85 -0
  7. package/lib/bson.js.map +1 -0
  8. package/lib/bulk/common.js +835 -0
  9. package/lib/bulk/common.js.map +1 -0
  10. package/lib/bulk/ordered.js +67 -0
  11. package/lib/bulk/ordered.js.map +1 -0
  12. package/lib/bulk/unordered.js +92 -0
  13. package/lib/bulk/unordered.js.map +1 -0
  14. package/lib/change_stream.js +513 -0
  15. package/lib/change_stream.js.map +1 -0
  16. package/lib/client-side-encryption/auto_encrypter.js +272 -0
  17. package/lib/client-side-encryption/auto_encrypter.js.map +1 -0
  18. package/lib/client-side-encryption/client_encryption.js +609 -0
  19. package/lib/client-side-encryption/client_encryption.js.map +1 -0
  20. package/lib/client-side-encryption/errors.js +138 -0
  21. package/lib/client-side-encryption/errors.js.map +1 -0
  22. package/lib/client-side-encryption/mongocryptd_manager.js +85 -0
  23. package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -0
  24. package/lib/client-side-encryption/providers/aws.js +23 -0
  25. package/lib/client-side-encryption/providers/aws.js.map +1 -0
  26. package/lib/client-side-encryption/providers/azure.js +132 -0
  27. package/lib/client-side-encryption/providers/azure.js.map +1 -0
  28. package/lib/client-side-encryption/providers/gcp.js +16 -0
  29. package/lib/client-side-encryption/providers/gcp.js.map +1 -0
  30. package/lib/client-side-encryption/providers/index.js +43 -0
  31. package/lib/client-side-encryption/providers/index.js.map +1 -0
  32. package/lib/client-side-encryption/state_machine.js +427 -0
  33. package/lib/client-side-encryption/state_machine.js.map +1 -0
  34. package/lib/cmap/auth/auth_provider.js +51 -0
  35. package/lib/cmap/auth/auth_provider.js.map +1 -0
  36. package/lib/cmap/auth/aws4.js +161 -0
  37. package/lib/cmap/auth/aws4.js.map +1 -0
  38. package/lib/cmap/auth/aws_temporary_credentials.js +103 -0
  39. package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
  40. package/lib/cmap/auth/gssapi.js +155 -0
  41. package/lib/cmap/auth/gssapi.js.map +1 -0
  42. package/lib/cmap/auth/mongo_credentials.js +169 -0
  43. package/lib/cmap/auth/mongo_credentials.js.map +1 -0
  44. package/lib/cmap/auth/mongodb_aws.js +128 -0
  45. package/lib/cmap/auth/mongodb_aws.js.map +1 -0
  46. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
  47. package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
  48. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
  49. package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
  50. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
  51. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
  52. package/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
  53. package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
  54. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -0
  55. package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -0
  56. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
  57. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -0
  58. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +32 -0
  59. package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -0
  60. package/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
  61. package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -0
  62. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +23 -0
  63. package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
  64. package/lib/cmap/auth/mongodb_oidc.js +73 -0
  65. package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
  66. package/lib/cmap/auth/plain.js +26 -0
  67. package/lib/cmap/auth/plain.js.map +1 -0
  68. package/lib/cmap/auth/providers.js +22 -0
  69. package/lib/cmap/auth/providers.js.map +1 -0
  70. package/lib/cmap/auth/scram.js +254 -0
  71. package/lib/cmap/auth/scram.js.map +1 -0
  72. package/lib/cmap/auth/x509.js +36 -0
  73. package/lib/cmap/auth/x509.js.map +1 -0
  74. package/lib/cmap/command_monitoring_events.js +223 -0
  75. package/lib/cmap/command_monitoring_events.js.map +1 -0
  76. package/lib/cmap/commands.js +535 -0
  77. package/lib/cmap/commands.js.map +1 -0
  78. package/lib/cmap/connect.js +381 -0
  79. package/lib/cmap/connect.js.map +1 -0
  80. package/lib/cmap/connection.js +571 -0
  81. package/lib/cmap/connection.js.map +1 -0
  82. package/lib/cmap/connection_pool.js +558 -0
  83. package/lib/cmap/connection_pool.js.map +1 -0
  84. package/lib/cmap/connection_pool_events.js +190 -0
  85. package/lib/cmap/connection_pool_events.js.map +1 -0
  86. package/lib/cmap/errors.js +108 -0
  87. package/lib/cmap/errors.js.map +1 -0
  88. package/lib/cmap/handshake/client_metadata.js +242 -0
  89. package/lib/cmap/handshake/client_metadata.js.map +1 -0
  90. package/lib/cmap/metrics.js +62 -0
  91. package/lib/cmap/metrics.js.map +1 -0
  92. package/lib/cmap/stream_description.js +70 -0
  93. package/lib/cmap/stream_description.js.map +1 -0
  94. package/lib/cmap/wire_protocol/compression.js +178 -0
  95. package/lib/cmap/wire_protocol/compression.js.map +1 -0
  96. package/lib/cmap/wire_protocol/constants.js +21 -0
  97. package/lib/cmap/wire_protocol/constants.js.map +1 -0
  98. package/lib/cmap/wire_protocol/on_data.js +111 -0
  99. package/lib/cmap/wire_protocol/on_data.js.map +1 -0
  100. package/lib/cmap/wire_protocol/on_demand/document.js +222 -0
  101. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
  102. package/lib/cmap/wire_protocol/responses.js +315 -0
  103. package/lib/cmap/wire_protocol/responses.js.map +1 -0
  104. package/lib/cmap/wire_protocol/shared.js +35 -0
  105. package/lib/cmap/wire_protocol/shared.js.map +1 -0
  106. package/lib/collection.js +751 -0
  107. package/lib/collection.js.map +1 -0
  108. package/lib/connection_string.js +1090 -0
  109. package/lib/connection_string.js.map +1 -0
  110. package/lib/constants.js +170 -0
  111. package/lib/constants.js.map +1 -0
  112. package/lib/cursor/abstract_cursor.js +924 -0
  113. package/lib/cursor/abstract_cursor.js.map +1 -0
  114. package/lib/cursor/aggregation_cursor.js +164 -0
  115. package/lib/cursor/aggregation_cursor.js.map +1 -0
  116. package/lib/cursor/change_stream_cursor.js +104 -0
  117. package/lib/cursor/change_stream_cursor.js.map +1 -0
  118. package/lib/cursor/client_bulk_write_cursor.js +52 -0
  119. package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
  120. package/lib/cursor/explainable_cursor.js +36 -0
  121. package/lib/cursor/explainable_cursor.js.map +1 -0
  122. package/lib/cursor/find_cursor.js +399 -0
  123. package/lib/cursor/find_cursor.js.map +1 -0
  124. package/lib/cursor/list_collections_cursor.js +34 -0
  125. package/lib/cursor/list_collections_cursor.js.map +1 -0
  126. package/lib/cursor/list_indexes_cursor.js +32 -0
  127. package/lib/cursor/list_indexes_cursor.js.map +1 -0
  128. package/lib/cursor/list_search_indexes_cursor.js +14 -0
  129. package/lib/cursor/list_search_indexes_cursor.js.map +1 -0
  130. package/lib/cursor/run_command_cursor.js +94 -0
  131. package/lib/cursor/run_command_cursor.js.map +1 -0
  132. package/lib/db.js +419 -0
  133. package/lib/db.js.map +1 -0
  134. package/lib/deps.js +112 -0
  135. package/lib/deps.js.map +1 -0
  136. package/lib/encrypter.js +106 -0
  137. package/lib/encrypter.js.map +1 -0
  138. package/lib/error.js +1380 -0
  139. package/lib/error.js.map +1 -0
  140. package/lib/explain.js +59 -0
  141. package/lib/explain.js.map +1 -0
  142. package/lib/gridfs/download.js +305 -0
  143. package/lib/gridfs/download.js.map +1 -0
  144. package/lib/gridfs/index.js +164 -0
  145. package/lib/gridfs/index.js.map +1 -0
  146. package/lib/gridfs/upload.js +358 -0
  147. package/lib/gridfs/upload.js.map +1 -0
  148. package/lib/index.js +193 -0
  149. package/lib/index.js.map +1 -0
  150. package/lib/mongo_client.js +557 -0
  151. package/lib/mongo_client.js.map +1 -0
  152. package/lib/mongo_client_auth_providers.js +80 -0
  153. package/lib/mongo_client_auth_providers.js.map +1 -0
  154. package/lib/mongo_logger.js +655 -0
  155. package/lib/mongo_logger.js.map +1 -0
  156. package/lib/mongo_types.js +56 -0
  157. package/lib/mongo_types.js.map +1 -0
  158. package/lib/operations/aggregate.js +90 -0
  159. package/lib/operations/aggregate.js.map +1 -0
  160. package/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
  161. package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
  162. package/lib/operations/client_bulk_write/command_builder.js +340 -0
  163. package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
  164. package/lib/operations/client_bulk_write/common.js +3 -0
  165. package/lib/operations/client_bulk_write/common.js.map +1 -0
  166. package/lib/operations/client_bulk_write/executor.js +120 -0
  167. package/lib/operations/client_bulk_write/executor.js.map +1 -0
  168. package/lib/operations/client_bulk_write/results_merger.js +204 -0
  169. package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
  170. package/lib/operations/command.js +83 -0
  171. package/lib/operations/command.js.map +1 -0
  172. package/lib/operations/count.js +45 -0
  173. package/lib/operations/count.js.map +1 -0
  174. package/lib/operations/create_collection.js +109 -0
  175. package/lib/operations/create_collection.js.map +1 -0
  176. package/lib/operations/delete.js +125 -0
  177. package/lib/operations/delete.js.map +1 -0
  178. package/lib/operations/distinct.js +61 -0
  179. package/lib/operations/distinct.js.map +1 -0
  180. package/lib/operations/drop.js +93 -0
  181. package/lib/operations/drop.js.map +1 -0
  182. package/lib/operations/end_sessions.js +34 -0
  183. package/lib/operations/end_sessions.js.map +1 -0
  184. package/lib/operations/estimated_document_count.js +41 -0
  185. package/lib/operations/estimated_document_count.js.map +1 -0
  186. package/lib/operations/execute_operation.js +239 -0
  187. package/lib/operations/execute_operation.js.map +1 -0
  188. package/lib/operations/find.js +148 -0
  189. package/lib/operations/find.js.map +1 -0
  190. package/lib/operations/find_and_modify.js +158 -0
  191. package/lib/operations/find_and_modify.js.map +1 -0
  192. package/lib/operations/get_more.js +62 -0
  193. package/lib/operations/get_more.js.map +1 -0
  194. package/lib/operations/indexes.js +186 -0
  195. package/lib/operations/indexes.js.map +1 -0
  196. package/lib/operations/insert.js +70 -0
  197. package/lib/operations/insert.js.map +1 -0
  198. package/lib/operations/kill_cursors.js +43 -0
  199. package/lib/operations/kill_cursors.js.map +1 -0
  200. package/lib/operations/list_collections.js +53 -0
  201. package/lib/operations/list_collections.js.map +1 -0
  202. package/lib/operations/list_databases.js +40 -0
  203. package/lib/operations/list_databases.js.map +1 -0
  204. package/lib/operations/operation.js +102 -0
  205. package/lib/operations/operation.js.map +1 -0
  206. package/lib/operations/profiling_level.js +43 -0
  207. package/lib/operations/profiling_level.js.map +1 -0
  208. package/lib/operations/remove_user.js +27 -0
  209. package/lib/operations/remove_user.js.map +1 -0
  210. package/lib/operations/rename.js +38 -0
  211. package/lib/operations/rename.js.map +1 -0
  212. package/lib/operations/run_command.js +47 -0
  213. package/lib/operations/run_command.js.map +1 -0
  214. package/lib/operations/search_indexes/create.js +33 -0
  215. package/lib/operations/search_indexes/create.js.map +1 -0
  216. package/lib/operations/search_indexes/drop.js +43 -0
  217. package/lib/operations/search_indexes/drop.js.map +1 -0
  218. package/lib/operations/search_indexes/update.js +35 -0
  219. package/lib/operations/search_indexes/update.js.map +1 -0
  220. package/lib/operations/set_profiling_level.js +53 -0
  221. package/lib/operations/set_profiling_level.js.map +1 -0
  222. package/lib/operations/stats.js +27 -0
  223. package/lib/operations/stats.js.map +1 -0
  224. package/lib/operations/update.js +188 -0
  225. package/lib/operations/update.js.map +1 -0
  226. package/lib/operations/validate_collection.js +37 -0
  227. package/lib/operations/validate_collection.js.map +1 -0
  228. package/lib/read_concern.js +73 -0
  229. package/lib/read_concern.js.map +1 -0
  230. package/lib/read_preference.js +191 -0
  231. package/lib/read_preference.js.map +1 -0
  232. package/lib/sdam/common.js +49 -0
  233. package/lib/sdam/common.js.map +1 -0
  234. package/lib/sdam/events.js +146 -0
  235. package/lib/sdam/events.js.map +1 -0
  236. package/lib/sdam/monitor.js +544 -0
  237. package/lib/sdam/monitor.js.map +1 -0
  238. package/lib/sdam/server.js +404 -0
  239. package/lib/sdam/server.js.map +1 -0
  240. package/lib/sdam/server_description.js +204 -0
  241. package/lib/sdam/server_description.js.map +1 -0
  242. package/lib/sdam/server_selection.js +294 -0
  243. package/lib/sdam/server_selection.js.map +1 -0
  244. package/lib/sdam/server_selection_events.js +85 -0
  245. package/lib/sdam/server_selection_events.js.map +1 -0
  246. package/lib/sdam/srv_polling.js +108 -0
  247. package/lib/sdam/srv_polling.js.map +1 -0
  248. package/lib/sdam/topology.js +652 -0
  249. package/lib/sdam/topology.js.map +1 -0
  250. package/lib/sdam/topology_description.js +383 -0
  251. package/lib/sdam/topology_description.js.map +1 -0
  252. package/lib/sessions.js +892 -0
  253. package/lib/sessions.js.map +1 -0
  254. package/lib/sort.js +103 -0
  255. package/lib/sort.js.map +1 -0
  256. package/lib/timeout.js +296 -0
  257. package/lib/timeout.js.map +1 -0
  258. package/lib/transactions.js +135 -0
  259. package/lib/transactions.js.map +1 -0
  260. package/lib/utils.js +1163 -0
  261. package/lib/utils.js.map +1 -0
  262. package/lib/write_concern.js +100 -0
  263. package/lib/write_concern.js.map +1 -0
  264. package/mongodb.d.ts +9018 -0
  265. package/package.json +197 -0
  266. package/src/admin.ts +173 -0
  267. package/src/bson.ts +149 -0
  268. package/src/bulk/common.ts +1251 -0
  269. package/src/bulk/ordered.ts +83 -0
  270. package/src/bulk/unordered.ts +115 -0
  271. package/src/change_stream.ts +1160 -0
  272. package/src/client-side-encryption/auto_encrypter.ts +469 -0
  273. package/src/client-side-encryption/client_encryption.ts +1150 -0
  274. package/src/client-side-encryption/errors.ts +144 -0
  275. package/src/client-side-encryption/mongocryptd_manager.ts +100 -0
  276. package/src/client-side-encryption/providers/aws.ts +33 -0
  277. package/src/client-side-encryption/providers/azure.ts +181 -0
  278. package/src/client-side-encryption/providers/gcp.ts +16 -0
  279. package/src/client-side-encryption/providers/index.ts +207 -0
  280. package/src/client-side-encryption/state_machine.ts +651 -0
  281. package/src/cmap/auth/auth_provider.ts +77 -0
  282. package/src/cmap/auth/aws4.ts +207 -0
  283. package/src/cmap/auth/aws_temporary_credentials.ts +129 -0
  284. package/src/cmap/auth/gssapi.ts +203 -0
  285. package/src/cmap/auth/mongo_credentials.ts +292 -0
  286. package/src/cmap/auth/mongodb_aws.ts +179 -0
  287. package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +88 -0
  288. package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +73 -0
  289. package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +188 -0
  290. package/src/cmap/auth/mongodb_oidc/command_builders.ts +53 -0
  291. package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +46 -0
  292. package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +141 -0
  293. package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +31 -0
  294. package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
  295. package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +22 -0
  296. package/src/cmap/auth/mongodb_oidc.ts +185 -0
  297. package/src/cmap/auth/plain.ts +25 -0
  298. package/src/cmap/auth/providers.ts +22 -0
  299. package/src/cmap/auth/scram.ts +344 -0
  300. package/src/cmap/auth/x509.ts +43 -0
  301. package/src/cmap/command_monitoring_events.ts +316 -0
  302. package/src/cmap/commands.ts +788 -0
  303. package/src/cmap/connect.ts +518 -0
  304. package/src/cmap/connection.ts +931 -0
  305. package/src/cmap/connection_pool.ts +831 -0
  306. package/src/cmap/connection_pool_events.ts +300 -0
  307. package/src/cmap/errors.ts +119 -0
  308. package/src/cmap/handshake/client_metadata.ts +353 -0
  309. package/src/cmap/metrics.ts +58 -0
  310. package/src/cmap/stream_description.ts +96 -0
  311. package/src/cmap/wire_protocol/compression.ts +211 -0
  312. package/src/cmap/wire_protocol/constants.ts +17 -0
  313. package/src/cmap/wire_protocol/on_data.ts +139 -0
  314. package/src/cmap/wire_protocol/on_demand/document.ts +358 -0
  315. package/src/cmap/wire_protocol/responses.ts +393 -0
  316. package/src/cmap/wire_protocol/shared.ts +48 -0
  317. package/src/collection.ts +1314 -0
  318. package/src/connection_string.ts +1297 -0
  319. package/src/constants.ts +176 -0
  320. package/src/cursor/abstract_cursor.ts +1247 -0
  321. package/src/cursor/aggregation_cursor.ts +245 -0
  322. package/src/cursor/change_stream_cursor.ts +171 -0
  323. package/src/cursor/client_bulk_write_cursor.ts +83 -0
  324. package/src/cursor/explainable_cursor.ts +51 -0
  325. package/src/cursor/find_cursor.ts +497 -0
  326. package/src/cursor/list_collections_cursor.ts +50 -0
  327. package/src/cursor/list_indexes_cursor.ts +37 -0
  328. package/src/cursor/list_search_indexes_cursor.ts +20 -0
  329. package/src/cursor/run_command_cursor.ts +178 -0
  330. package/src/db.ts +621 -0
  331. package/src/deps.ts +227 -0
  332. package/src/encrypter.ts +127 -0
  333. package/src/error.ts +1567 -0
  334. package/src/explain.ts +124 -0
  335. package/src/gridfs/download.ts +483 -0
  336. package/src/gridfs/index.ts +264 -0
  337. package/src/gridfs/upload.ts +537 -0
  338. package/src/index.ts +633 -0
  339. package/src/mongo_client.ts +1155 -0
  340. package/src/mongo_client_auth_providers.ts +87 -0
  341. package/src/mongo_logger.ts +1081 -0
  342. package/src/mongo_types.ts +678 -0
  343. package/src/operations/aggregate.ts +153 -0
  344. package/src/operations/client_bulk_write/client_bulk_write.ts +72 -0
  345. package/src/operations/client_bulk_write/command_builder.ts +487 -0
  346. package/src/operations/client_bulk_write/common.ts +276 -0
  347. package/src/operations/client_bulk_write/executor.ts +149 -0
  348. package/src/operations/client_bulk_write/results_merger.ts +260 -0
  349. package/src/operations/command.ts +171 -0
  350. package/src/operations/count.ts +74 -0
  351. package/src/operations/create_collection.ts +218 -0
  352. package/src/operations/delete.ts +183 -0
  353. package/src/operations/distinct.ts +92 -0
  354. package/src/operations/drop.ts +130 -0
  355. package/src/operations/end_sessions.ts +44 -0
  356. package/src/operations/estimated_document_count.ts +61 -0
  357. package/src/operations/execute_operation.ts +319 -0
  358. package/src/operations/find.ts +254 -0
  359. package/src/operations/find_and_modify.ts +319 -0
  360. package/src/operations/get_more.ts +108 -0
  361. package/src/operations/indexes.ts +418 -0
  362. package/src/operations/insert.ts +108 -0
  363. package/src/operations/kill_cursors.ts +64 -0
  364. package/src/operations/list_collections.ts +108 -0
  365. package/src/operations/list_databases.ts +68 -0
  366. package/src/operations/operation.ts +181 -0
  367. package/src/operations/profiling_level.ts +46 -0
  368. package/src/operations/remove_user.ts +36 -0
  369. package/src/operations/rename.ts +60 -0
  370. package/src/operations/run_command.ts +79 -0
  371. package/src/operations/search_indexes/create.ts +56 -0
  372. package/src/operations/search_indexes/drop.ts +58 -0
  373. package/src/operations/search_indexes/update.ts +45 -0
  374. package/src/operations/set_profiling_level.ts +74 -0
  375. package/src/operations/stats.ts +37 -0
  376. package/src/operations/update.ts +318 -0
  377. package/src/operations/validate_collection.ts +50 -0
  378. package/src/read_concern.ts +88 -0
  379. package/src/read_preference.ts +256 -0
  380. package/src/sdam/common.ts +74 -0
  381. package/src/sdam/events.ts +219 -0
  382. package/src/sdam/monitor.ts +771 -0
  383. package/src/sdam/server.ts +595 -0
  384. package/src/sdam/server_description.ts +297 -0
  385. package/src/sdam/server_selection.ts +415 -0
  386. package/src/sdam/server_selection_events.ts +142 -0
  387. package/src/sdam/srv_polling.ts +146 -0
  388. package/src/sdam/topology.ts +1100 -0
  389. package/src/sdam/topology_description.ts +548 -0
  390. package/src/sessions.ts +1244 -0
  391. package/src/sort.ts +141 -0
  392. package/src/timeout.ts +405 -0
  393. package/src/transactions.ts +181 -0
  394. package/src/utils.ts +1434 -0
  395. package/src/write_concern.ts +183 -0
  396. package/tsconfig.json +46 -0
@@ -0,0 +1,188 @@
1
+ import { setTimeout } from 'timers/promises';
2
+
3
+ import { type Document } from '../../../bson';
4
+ import { MongoMissingCredentialsError } from '../../../error';
5
+ import { ns } from '../../../utils';
6
+ import type { Connection } from '../../connection';
7
+ import type { MongoCredentials } from '../mongo_credentials';
8
+ import {
9
+ type OIDCCallbackFunction,
10
+ type OIDCCallbackParams,
11
+ type OIDCResponse,
12
+ type Workflow
13
+ } from '../mongodb_oidc';
14
+ import { finishCommandDocument, startCommandDocument } from './command_builders';
15
+ import { type TokenCache } from './token_cache';
16
+
17
+ /** 5 minutes in milliseconds */
18
+ export const HUMAN_TIMEOUT_MS = 300000;
19
+ /** 1 minute in milliseconds */
20
+ export const AUTOMATED_TIMEOUT_MS = 60000;
21
+
22
+ /** Properties allowed on results of callbacks. */
23
+ const RESULT_PROPERTIES = ['accessToken', 'expiresInSeconds', 'refreshToken'];
24
+
25
+ /** Error message when the callback result is invalid. */
26
+ const CALLBACK_RESULT_ERROR =
27
+ 'User provided OIDC callbacks must return a valid object with an accessToken.';
28
+
29
+ /** The time to throttle callback calls. */
30
+ const THROTTLE_MS = 100;
31
+
32
+ /**
33
+ * OIDC implementation of a callback based workflow.
34
+ * @internal
35
+ */
36
+ export abstract class CallbackWorkflow implements Workflow {
37
+ cache: TokenCache;
38
+ callback: OIDCCallbackFunction;
39
+ lastExecutionTime: number;
40
+
41
+ /**
42
+ * Instantiate the callback workflow.
43
+ */
44
+ constructor(cache: TokenCache, callback: OIDCCallbackFunction) {
45
+ this.cache = cache;
46
+ this.callback = this.withLock(callback);
47
+ this.lastExecutionTime = Date.now() - THROTTLE_MS;
48
+ }
49
+
50
+ /**
51
+ * Get the document to add for speculative authentication. This also needs
52
+ * to add a db field from the credentials source.
53
+ */
54
+ async speculativeAuth(connection: Connection, credentials: MongoCredentials): Promise<Document> {
55
+ // Check if the Client Cache has an access token.
56
+ // If it does, cache the access token in the Connection Cache and send a JwtStepRequest
57
+ // with the cached access token in the speculative authentication SASL payload.
58
+ if (this.cache.hasAccessToken) {
59
+ const accessToken = this.cache.getAccessToken();
60
+ connection.accessToken = accessToken;
61
+ const document = finishCommandDocument(accessToken);
62
+ document.db = credentials.source;
63
+ return { speculativeAuthenticate: document };
64
+ }
65
+ return {};
66
+ }
67
+
68
+ /**
69
+ * Reauthenticate the callback workflow. For this we invalidated the access token
70
+ * in the cache and run the authentication steps again. No initial handshake needs
71
+ * to be sent.
72
+ */
73
+ async reauthenticate(connection: Connection, credentials: MongoCredentials): Promise<void> {
74
+ if (this.cache.hasAccessToken) {
75
+ // Reauthentication implies the token has expired.
76
+ if (connection.accessToken === this.cache.getAccessToken()) {
77
+ // If connection's access token is the same as the cache's, remove
78
+ // the token from the cache and connection.
79
+ this.cache.removeAccessToken();
80
+ delete connection.accessToken;
81
+ } else {
82
+ // If the connection's access token is different from the cache's, set
83
+ // the cache's token on the connection and do not remove from the
84
+ // cache.
85
+ connection.accessToken = this.cache.getAccessToken();
86
+ }
87
+ }
88
+ await this.execute(connection, credentials);
89
+ }
90
+
91
+ /**
92
+ * Execute the OIDC callback workflow.
93
+ */
94
+ abstract execute(
95
+ connection: Connection,
96
+ credentials: MongoCredentials,
97
+ response?: Document
98
+ ): Promise<void>;
99
+
100
+ /**
101
+ * Starts the callback authentication process. If there is a speculative
102
+ * authentication document from the initial handshake, then we will use that
103
+ * value to get the issuer, otherwise we will send the saslStart command.
104
+ */
105
+ protected async startAuthentication(
106
+ connection: Connection,
107
+ credentials: MongoCredentials,
108
+ response?: Document
109
+ ): Promise<Document> {
110
+ let result;
111
+ if (response?.speculativeAuthenticate) {
112
+ result = response.speculativeAuthenticate;
113
+ } else {
114
+ result = await connection.command(
115
+ ns(credentials.source),
116
+ startCommandDocument(credentials),
117
+ undefined
118
+ );
119
+ }
120
+ return result;
121
+ }
122
+
123
+ /**
124
+ * Finishes the callback authentication process.
125
+ */
126
+ protected async finishAuthentication(
127
+ connection: Connection,
128
+ credentials: MongoCredentials,
129
+ token: string,
130
+ conversationId?: number
131
+ ): Promise<void> {
132
+ await connection.command(
133
+ ns(credentials.source),
134
+ finishCommandDocument(token, conversationId),
135
+ undefined
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Executes the callback and validates the output.
141
+ */
142
+ protected async executeAndValidateCallback(params: OIDCCallbackParams): Promise<OIDCResponse> {
143
+ const result = await this.callback(params);
144
+ // Validate that the result returned by the callback is acceptable. If it is not
145
+ // we must clear the token result from the cache.
146
+ if (isCallbackResultInvalid(result)) {
147
+ throw new MongoMissingCredentialsError(CALLBACK_RESULT_ERROR);
148
+ }
149
+ return result;
150
+ }
151
+
152
+ /**
153
+ * Ensure the callback is only executed one at a time and throttles the calls
154
+ * to every 100ms.
155
+ */
156
+ protected withLock(callback: OIDCCallbackFunction): OIDCCallbackFunction {
157
+ let lock: Promise<any> = Promise.resolve();
158
+ return async (params: OIDCCallbackParams): Promise<OIDCResponse> => {
159
+ // We do this to ensure that we would never return the result of the
160
+ // previous lock, only the current callback's value would get returned.
161
+ await lock;
162
+ lock = lock
163
+
164
+ .catch(() => null)
165
+
166
+ .then(async () => {
167
+ const difference = Date.now() - this.lastExecutionTime;
168
+ if (difference <= THROTTLE_MS) {
169
+ await setTimeout(THROTTLE_MS - difference, { signal: params.timeoutContext });
170
+ }
171
+ this.lastExecutionTime = Date.now();
172
+ return await callback(params);
173
+ });
174
+ return await lock;
175
+ };
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Determines if a result returned from a request or refresh callback
181
+ * function is invalid. This means the result is nullish, doesn't contain
182
+ * the accessToken required field, and does not contain extra fields.
183
+ */
184
+ function isCallbackResultInvalid(tokenResult: unknown): boolean {
185
+ if (tokenResult == null || typeof tokenResult !== 'object') return true;
186
+ if (!('accessToken' in tokenResult)) return true;
187
+ return !Object.getOwnPropertyNames(tokenResult).every(prop => RESULT_PROPERTIES.includes(prop));
188
+ }
@@ -0,0 +1,53 @@
1
+ import { Binary, BSON, type Document } from '../../../bson';
2
+ import { type MongoCredentials } from '../mongo_credentials';
3
+ import { AuthMechanism } from '../providers';
4
+
5
+ /** @internal */
6
+ export interface OIDCCommand {
7
+ saslStart?: number;
8
+ saslContinue?: number;
9
+ conversationId?: number;
10
+ mechanism?: string;
11
+ autoAuthorize?: number;
12
+ db?: string;
13
+ payload: Binary;
14
+ }
15
+
16
+ /**
17
+ * Generate the finishing command document for authentication. Will be a
18
+ * saslStart or saslContinue depending on the presence of a conversation id.
19
+ */
20
+ export function finishCommandDocument(token: string, conversationId?: number): OIDCCommand {
21
+ if (conversationId != null) {
22
+ return {
23
+ saslContinue: 1,
24
+ conversationId: conversationId,
25
+ payload: new Binary(BSON.serialize({ jwt: token }))
26
+ };
27
+ }
28
+ // saslContinue requires a conversationId in the command to be valid so in this
29
+ // case the server allows "step two" to actually be a saslStart with the token
30
+ // as the jwt since the use of the cached value has no correlating conversating
31
+ // on the particular connection.
32
+ return {
33
+ saslStart: 1,
34
+ mechanism: AuthMechanism.MONGODB_OIDC,
35
+ payload: new Binary(BSON.serialize({ jwt: token }))
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Generate the saslStart command document.
41
+ */
42
+ export function startCommandDocument(credentials: MongoCredentials): OIDCCommand {
43
+ const payload: Document = {};
44
+ if (credentials.username) {
45
+ payload.n = credentials.username;
46
+ }
47
+ return {
48
+ saslStart: 1,
49
+ autoAuthorize: 1,
50
+ mechanism: AuthMechanism.MONGODB_OIDC,
51
+ payload: new Binary(BSON.serialize(payload))
52
+ };
53
+ }
@@ -0,0 +1,46 @@
1
+ import { MongoGCPError } from '../../../error';
2
+ import { get } from '../../../utils';
3
+ import type { OIDCCallbackFunction, OIDCCallbackParams, OIDCResponse } from '../mongodb_oidc';
4
+
5
+ /** GCP base URL. */
6
+ const GCP_BASE_URL =
7
+ 'http://metadata/computeMetadata/v1/instance/service-accounts/default/identity';
8
+
9
+ /** GCP request headers. */
10
+ const GCP_HEADERS = Object.freeze({ 'Metadata-Flavor': 'Google' });
11
+
12
+ /** Error for when the token audience is missing in the environment. */
13
+ const TOKEN_RESOURCE_MISSING_ERROR =
14
+ 'TOKEN_RESOURCE must be set in the auth mechanism properties when ENVIRONMENT is gcp.';
15
+
16
+ /**
17
+ * The callback function to be used in the automated callback workflow.
18
+ * @param params - The OIDC callback parameters.
19
+ * @returns The OIDC response.
20
+ */
21
+ export const callback: OIDCCallbackFunction = async (
22
+ params: OIDCCallbackParams
23
+ ): Promise<OIDCResponse> => {
24
+ const tokenAudience = params.tokenAudience;
25
+ if (!tokenAudience) {
26
+ throw new MongoGCPError(TOKEN_RESOURCE_MISSING_ERROR);
27
+ }
28
+ return await getGcpTokenData(tokenAudience);
29
+ };
30
+
31
+ /**
32
+ * Hit the GCP endpoint to get the token data.
33
+ */
34
+ async function getGcpTokenData(tokenAudience: string): Promise<OIDCResponse> {
35
+ const url = new URL(GCP_BASE_URL);
36
+ url.searchParams.append('audience', tokenAudience);
37
+ const response = await get(url, {
38
+ headers: GCP_HEADERS
39
+ });
40
+ if (response.status !== 200) {
41
+ throw new MongoGCPError(
42
+ `Status code ${response.status} returned from the GCP endpoint. Response body: ${response.body}`
43
+ );
44
+ }
45
+ return { accessToken: response.body };
46
+ }
@@ -0,0 +1,141 @@
1
+ import { BSON } from '../../../bson';
2
+ import { MONGODB_ERROR_CODES, MongoError, MongoOIDCError } from '../../../error';
3
+ import { Timeout, TimeoutError } from '../../../timeout';
4
+ import { type Connection } from '../../connection';
5
+ import { type MongoCredentials } from '../mongo_credentials';
6
+ import {
7
+ type IdPInfo,
8
+ OIDC_VERSION,
9
+ type OIDCCallbackFunction,
10
+ type OIDCCallbackParams,
11
+ type OIDCResponse
12
+ } from '../mongodb_oidc';
13
+ import { CallbackWorkflow, HUMAN_TIMEOUT_MS } from './callback_workflow';
14
+ import { type TokenCache } from './token_cache';
15
+
16
+ /**
17
+ * Class implementing behaviour for the non human callback workflow.
18
+ * @internal
19
+ */
20
+ export class HumanCallbackWorkflow extends CallbackWorkflow {
21
+ /**
22
+ * Instantiate the human callback workflow.
23
+ */
24
+ constructor(cache: TokenCache, callback: OIDCCallbackFunction) {
25
+ super(cache, callback);
26
+ }
27
+
28
+ /**
29
+ * Execute the OIDC human callback workflow.
30
+ */
31
+ async execute(connection: Connection, credentials: MongoCredentials): Promise<void> {
32
+ // Check if the Client Cache has an access token.
33
+ // If it does, cache the access token in the Connection Cache and perform a One-Step SASL conversation
34
+ // using the access token. If the server returns an Authentication error (18),
35
+ // invalidate the access token token from the Client Cache, clear the Connection Cache,
36
+ // and restart the authentication flow. Raise any other errors to the user. On success, exit the algorithm.
37
+ if (this.cache.hasAccessToken) {
38
+ const token = this.cache.getAccessToken();
39
+ connection.accessToken = token;
40
+ try {
41
+ return await this.finishAuthentication(connection, credentials, token);
42
+ } catch (error) {
43
+ if (
44
+ error instanceof MongoError &&
45
+ error.code === MONGODB_ERROR_CODES.AuthenticationFailed
46
+ ) {
47
+ this.cache.removeAccessToken();
48
+ delete connection.accessToken;
49
+ return await this.execute(connection, credentials);
50
+ } else {
51
+ throw error;
52
+ }
53
+ }
54
+ }
55
+ // Check if the Client Cache has a refresh token.
56
+ // If it does, call the OIDC Human Callback with the cached refresh token and IdpInfo to get a
57
+ // new access token. Cache the new access token in the Client Cache and Connection Cache.
58
+ // Perform a One-Step SASL conversation using the new access token. If the the server returns
59
+ // an Authentication error (18), clear the refresh token, invalidate the access token from the
60
+ // Client Cache, clear the Connection Cache, and restart the authentication flow. Raise any other
61
+ // errors to the user. On success, exit the algorithm.
62
+ if (this.cache.hasRefreshToken) {
63
+ const refreshToken = this.cache.getRefreshToken();
64
+ const result = await this.fetchAccessToken(
65
+ this.cache.getIdpInfo(),
66
+ credentials,
67
+ refreshToken
68
+ );
69
+ this.cache.put(result);
70
+ connection.accessToken = result.accessToken;
71
+ try {
72
+ return await this.finishAuthentication(connection, credentials, result.accessToken);
73
+ } catch (error) {
74
+ if (
75
+ error instanceof MongoError &&
76
+ error.code === MONGODB_ERROR_CODES.AuthenticationFailed
77
+ ) {
78
+ this.cache.removeRefreshToken();
79
+ delete connection.accessToken;
80
+ return await this.execute(connection, credentials);
81
+ } else {
82
+ throw error;
83
+ }
84
+ }
85
+ }
86
+
87
+ // Start a new Two-Step SASL conversation.
88
+ // Run a PrincipalStepRequest to get the IdpInfo.
89
+ // Call the OIDC Human Callback with the new IdpInfo to get a new access token and optional refresh
90
+ // token. Drivers MUST NOT pass a cached refresh token to the callback when performing
91
+ // a new Two-Step conversation. Cache the new IdpInfo and refresh token in the Client Cache and the
92
+ // new access token in the Client Cache and Connection Cache.
93
+ // Attempt to authenticate using a JwtStepRequest with the new access token. Raise any errors to the user.
94
+ const startResponse = await this.startAuthentication(connection, credentials);
95
+ const conversationId = startResponse.conversationId;
96
+ const idpInfo = BSON.deserialize(startResponse.payload.buffer) as IdPInfo;
97
+ const callbackResponse = await this.fetchAccessToken(idpInfo, credentials);
98
+ this.cache.put(callbackResponse, idpInfo);
99
+ connection.accessToken = callbackResponse.accessToken;
100
+ return await this.finishAuthentication(
101
+ connection,
102
+ credentials,
103
+ callbackResponse.accessToken,
104
+ conversationId
105
+ );
106
+ }
107
+
108
+ /**
109
+ * Fetches an access token using the callback.
110
+ */
111
+ private async fetchAccessToken(
112
+ idpInfo: IdPInfo,
113
+ credentials: MongoCredentials,
114
+ refreshToken?: string
115
+ ): Promise<OIDCResponse> {
116
+ const controller = new AbortController();
117
+ const params: OIDCCallbackParams = {
118
+ timeoutContext: controller.signal,
119
+ version: OIDC_VERSION,
120
+ idpInfo: idpInfo
121
+ };
122
+ if (credentials.username) {
123
+ params.username = credentials.username;
124
+ }
125
+ if (refreshToken) {
126
+ params.refreshToken = refreshToken;
127
+ }
128
+ const timeout = Timeout.expires(HUMAN_TIMEOUT_MS);
129
+ try {
130
+ return await Promise.race([this.executeAndValidateCallback(params), timeout]);
131
+ } catch (error) {
132
+ if (TimeoutError.is(error)) {
133
+ controller.abort();
134
+ throw new MongoOIDCError(`OIDC callback timed out after ${HUMAN_TIMEOUT_MS}ms.`);
135
+ }
136
+ throw error;
137
+ } finally {
138
+ timeout.clear();
139
+ }
140
+ }
141
+ }
@@ -0,0 +1,31 @@
1
+ import { readFile } from 'fs/promises';
2
+ import * as process from 'process';
3
+
4
+ import type { OIDCCallbackFunction, OIDCResponse } from '../mongodb_oidc';
5
+
6
+ /** The fallback file name */
7
+ const FALLBACK_FILENAME = '/var/run/secrets/kubernetes.io/serviceaccount/token';
8
+
9
+ /** The azure environment variable for the file name. */
10
+ const AZURE_FILENAME = 'AZURE_FEDERATED_TOKEN_FILE';
11
+
12
+ /** The AWS environment variable for the file name. */
13
+ const AWS_FILENAME = 'AWS_WEB_IDENTITY_TOKEN_FILE';
14
+
15
+ /**
16
+ * The callback function to be used in the automated callback workflow.
17
+ * @param params - The OIDC callback parameters.
18
+ * @returns The OIDC response.
19
+ */
20
+ export const callback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
21
+ let filename: string;
22
+ if (process.env[AZURE_FILENAME]) {
23
+ filename = process.env[AZURE_FILENAME];
24
+ } else if (process.env[AWS_FILENAME]) {
25
+ filename = process.env[AWS_FILENAME];
26
+ } else {
27
+ filename = FALLBACK_FILENAME;
28
+ }
29
+ const token = await readFile(filename, 'utf8');
30
+ return { accessToken: token };
31
+ };
@@ -0,0 +1,62 @@
1
+ import { MongoDriverError } from '../../../error';
2
+ import type { IdPInfo, OIDCResponse } from '../mongodb_oidc';
3
+
4
+ class MongoOIDCError extends MongoDriverError {}
5
+
6
+ /** @internal */
7
+ export class TokenCache {
8
+ private accessToken?: string;
9
+ private refreshToken?: string;
10
+ private idpInfo?: IdPInfo;
11
+ private expiresInSeconds?: number;
12
+
13
+ get hasAccessToken(): boolean {
14
+ return !!this.accessToken;
15
+ }
16
+
17
+ get hasRefreshToken(): boolean {
18
+ return !!this.refreshToken;
19
+ }
20
+
21
+ get hasIdpInfo(): boolean {
22
+ return !!this.idpInfo;
23
+ }
24
+
25
+ getAccessToken(): string {
26
+ if (!this.accessToken) {
27
+ throw new MongoOIDCError('Attempted to get an access token when none exists.');
28
+ }
29
+ return this.accessToken;
30
+ }
31
+
32
+ getRefreshToken(): string {
33
+ if (!this.refreshToken) {
34
+ throw new MongoOIDCError('Attempted to get a refresh token when none exists.');
35
+ }
36
+ return this.refreshToken;
37
+ }
38
+
39
+ getIdpInfo(): IdPInfo {
40
+ if (!this.idpInfo) {
41
+ throw new MongoOIDCError('Attempted to get IDP information when none exists.');
42
+ }
43
+ return this.idpInfo;
44
+ }
45
+
46
+ put(response: OIDCResponse, idpInfo?: IdPInfo) {
47
+ this.accessToken = response.accessToken;
48
+ this.refreshToken = response.refreshToken;
49
+ this.expiresInSeconds = response.expiresInSeconds;
50
+ if (idpInfo) {
51
+ this.idpInfo = idpInfo;
52
+ }
53
+ }
54
+
55
+ removeAccessToken() {
56
+ this.accessToken = undefined;
57
+ }
58
+
59
+ removeRefreshToken() {
60
+ this.refreshToken = undefined;
61
+ }
62
+ }
@@ -0,0 +1,22 @@
1
+ import * as fs from 'fs';
2
+ import * as process from 'process';
3
+
4
+ import { MongoAWSError } from '../../../error';
5
+ import type { OIDCCallbackFunction, OIDCResponse } from '../mongodb_oidc';
6
+
7
+ /** Error for when the token is missing in the environment. */
8
+ const TOKEN_MISSING_ERROR = 'OIDC_TOKEN_FILE must be set in the environment.';
9
+
10
+ /**
11
+ * The callback function to be used in the automated callback workflow.
12
+ * @param params - The OIDC callback parameters.
13
+ * @returns The OIDC response.
14
+ */
15
+ export const callback: OIDCCallbackFunction = async (): Promise<OIDCResponse> => {
16
+ const tokenFile = process.env.OIDC_TOKEN_FILE;
17
+ if (!tokenFile) {
18
+ throw new MongoAWSError(TOKEN_MISSING_ERROR);
19
+ }
20
+ const token = await fs.promises.readFile(tokenFile, 'utf8');
21
+ return { accessToken: token };
22
+ };