@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,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongoCryptKMSRequestNetworkTimeoutError = exports.MongoCryptAzureKMSRequestError = exports.MongoCryptCreateEncryptedCollectionError = exports.MongoCryptCreateDataKeyError = exports.MongoCryptInvalidArgumentError = exports.defaultErrorWrapper = exports.MongoCryptError = void 0;
4
+ const error_1 = require("../error");
5
+ /**
6
+ * @public
7
+ * An error indicating that something went wrong specifically with MongoDB Client Encryption
8
+ */
9
+ class MongoCryptError extends error_1.MongoError {
10
+ /**
11
+ * **Do not use this constructor!**
12
+ *
13
+ * Meant for internal use only.
14
+ *
15
+ * @remarks
16
+ * This class is only meant to be constructed within the driver. This constructor is
17
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
18
+ *
19
+ * @public
20
+ **/
21
+ constructor(message, options = {}) {
22
+ super(message, options);
23
+ }
24
+ get name() {
25
+ return 'MongoCryptError';
26
+ }
27
+ }
28
+ exports.MongoCryptError = MongoCryptError;
29
+ const defaultErrorWrapper = (error) => new MongoCryptError(error.message, { cause: error });
30
+ exports.defaultErrorWrapper = defaultErrorWrapper;
31
+ /**
32
+ * @public
33
+ *
34
+ * An error indicating an invalid argument was provided to an encryption API.
35
+ */
36
+ class MongoCryptInvalidArgumentError extends MongoCryptError {
37
+ /**
38
+ * **Do not use this constructor!**
39
+ *
40
+ * Meant for internal use only.
41
+ *
42
+ * @remarks
43
+ * This class is only meant to be constructed within the driver. This constructor is
44
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
45
+ *
46
+ * @public
47
+ **/
48
+ constructor(message) {
49
+ super(message);
50
+ }
51
+ get name() {
52
+ return 'MongoCryptInvalidArgumentError';
53
+ }
54
+ }
55
+ exports.MongoCryptInvalidArgumentError = MongoCryptInvalidArgumentError;
56
+ /**
57
+ * @public
58
+ * An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create data keys
59
+ */
60
+ class MongoCryptCreateDataKeyError extends MongoCryptError {
61
+ /**
62
+ * **Do not use this constructor!**
63
+ *
64
+ * Meant for internal use only.
65
+ *
66
+ * @remarks
67
+ * This class is only meant to be constructed within the driver. This constructor is
68
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
69
+ *
70
+ * @public
71
+ **/
72
+ constructor(encryptedFields, { cause }) {
73
+ super(`Unable to complete creating data keys: ${cause.message}`, { cause });
74
+ this.encryptedFields = encryptedFields;
75
+ }
76
+ get name() {
77
+ return 'MongoCryptCreateDataKeyError';
78
+ }
79
+ }
80
+ exports.MongoCryptCreateDataKeyError = MongoCryptCreateDataKeyError;
81
+ /**
82
+ * @public
83
+ * An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create a collection
84
+ */
85
+ class MongoCryptCreateEncryptedCollectionError extends MongoCryptError {
86
+ /**
87
+ * **Do not use this constructor!**
88
+ *
89
+ * Meant for internal use only.
90
+ *
91
+ * @remarks
92
+ * This class is only meant to be constructed within the driver. This constructor is
93
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
94
+ *
95
+ * @public
96
+ **/
97
+ constructor(encryptedFields, { cause }) {
98
+ super(`Unable to create collection: ${cause.message}`, { cause });
99
+ this.encryptedFields = encryptedFields;
100
+ }
101
+ get name() {
102
+ return 'MongoCryptCreateEncryptedCollectionError';
103
+ }
104
+ }
105
+ exports.MongoCryptCreateEncryptedCollectionError = MongoCryptCreateEncryptedCollectionError;
106
+ /**
107
+ * @public
108
+ * An error indicating that mongodb-client-encryption failed to auto-refresh Azure KMS credentials.
109
+ */
110
+ class MongoCryptAzureKMSRequestError extends MongoCryptError {
111
+ /**
112
+ * **Do not use this constructor!**
113
+ *
114
+ * Meant for internal use only.
115
+ *
116
+ * @remarks
117
+ * This class is only meant to be constructed within the driver. This constructor is
118
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
119
+ *
120
+ * @public
121
+ **/
122
+ constructor(message, body) {
123
+ super(message);
124
+ this.body = body;
125
+ }
126
+ get name() {
127
+ return 'MongoCryptAzureKMSRequestError';
128
+ }
129
+ }
130
+ exports.MongoCryptAzureKMSRequestError = MongoCryptAzureKMSRequestError;
131
+ /** @public */
132
+ class MongoCryptKMSRequestNetworkTimeoutError extends MongoCryptError {
133
+ get name() {
134
+ return 'MongoCryptKMSRequestNetworkTimeoutError';
135
+ }
136
+ }
137
+ exports.MongoCryptKMSRequestNetworkTimeoutError = MongoCryptKMSRequestNetworkTimeoutError;
138
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/client-side-encryption/errors.ts"],"names":[],"mappings":";;;AACA,oCAAsC;AAEtC;;;GAGG;AACH,MAAa,eAAgB,SAAQ,kBAAU;IAC7C;;;;;;;;;;QAUI;IACJ,YAAY,OAAe,EAAE,UAA6B,EAAE;QAC1D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,IAAa,IAAI;QACf,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF;AAnBD,0CAmBC;AAEM,MAAM,mBAAmB,GAAG,CAAC,KAAY,EAAE,EAAE,CAClD,IAAI,eAAe,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;AAD1C,QAAA,mBAAmB,uBACuB;AAEvD;;;;GAIG;AACH,MAAa,8BAA+B,SAAQ,eAAe;IACjE;;;;;;;;;;QAUI;IACJ,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,IAAa,IAAI;QACf,OAAO,gCAAgC,CAAC;IAC1C,CAAC;CACF;AAnBD,wEAmBC;AACD;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,eAAe;IAE/D;;;;;;;;;;QAUI;IACJ,YAAY,eAAyB,EAAE,EAAE,KAAK,EAAoB;QAChE,KAAK,CAAC,0CAA0C,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED,IAAa,IAAI;QACf,OAAO,8BAA8B,CAAC;IACxC,CAAC;CACF;AArBD,oEAqBC;AAED;;;GAGG;AACH,MAAa,wCAAyC,SAAQ,eAAe;IAE3E;;;;;;;;;;QAUI;IACJ,YAAY,eAAyB,EAAE,EAAE,KAAK,EAAoB;QAChE,KAAK,CAAC,gCAAgC,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED,IAAa,IAAI;QACf,OAAO,0CAA0C,CAAC;IACpD,CAAC;CACF;AArBD,4FAqBC;AAED;;;GAGG;AACH,MAAa,8BAA+B,SAAQ,eAAe;IAGjE;;;;;;;;;;QAUI;IACJ,YAAY,OAAe,EAAE,IAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAa,IAAI;QACf,OAAO,gCAAgC,CAAC;IAC1C,CAAC;CACF;AAtBD,wEAsBC;AAED,cAAc;AACd,MAAa,uCAAwC,SAAQ,eAAe;IAC1E,IAAa,IAAI;QACf,OAAO,yCAAyC,CAAC;IACnD,CAAC;CACF;AAJD,0FAIC"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MongocryptdManager = void 0;
4
+ const error_1 = require("../error");
5
+ /**
6
+ * @internal
7
+ * An internal class that handles spawning a mongocryptd.
8
+ */
9
+ class MongocryptdManager {
10
+ static { this.DEFAULT_MONGOCRYPTD_URI = 'mongodb://localhost:27020'; }
11
+ constructor(extraOptions = {}) {
12
+ this.spawnPath = '';
13
+ this.spawnArgs = [];
14
+ this.uri =
15
+ typeof extraOptions.mongocryptdURI === 'string' && extraOptions.mongocryptdURI.length > 0
16
+ ? extraOptions.mongocryptdURI
17
+ : MongocryptdManager.DEFAULT_MONGOCRYPTD_URI;
18
+ this.bypassSpawn = !!extraOptions.mongocryptdBypassSpawn;
19
+ if (Object.hasOwn(extraOptions, 'mongocryptdSpawnPath') && extraOptions.mongocryptdSpawnPath) {
20
+ this.spawnPath = extraOptions.mongocryptdSpawnPath;
21
+ }
22
+ if (Object.hasOwn(extraOptions, 'mongocryptdSpawnArgs') &&
23
+ Array.isArray(extraOptions.mongocryptdSpawnArgs)) {
24
+ this.spawnArgs = this.spawnArgs.concat(extraOptions.mongocryptdSpawnArgs);
25
+ }
26
+ if (this.spawnArgs
27
+ .filter(arg => typeof arg === 'string')
28
+ .every(arg => arg.indexOf('--idleShutdownTimeoutSecs') < 0)) {
29
+ this.spawnArgs.push('--idleShutdownTimeoutSecs', '60');
30
+ }
31
+ }
32
+ /**
33
+ * Will check to see if a mongocryptd is up. If it is not up, it will attempt
34
+ * to spawn a mongocryptd in a detached process, and then wait for it to be up.
35
+ */
36
+ async spawn() {
37
+ const cmdName = this.spawnPath || 'mongocryptd';
38
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
39
+ const { spawn } = require('child_process');
40
+ // Spawned with stdio: ignore and detached: true
41
+ // to ensure child can outlive parent.
42
+ this._child = spawn(cmdName, this.spawnArgs, {
43
+ stdio: 'ignore',
44
+ detached: true
45
+ });
46
+ this._child.on('error', () => {
47
+ // From the FLE spec:
48
+ // "The stdout and stderr of the spawned process MUST not be exposed in the driver
49
+ // (e.g. redirect to /dev/null). Users can pass the argument --logpath to
50
+ // extraOptions.mongocryptdSpawnArgs if they need to inspect mongocryptd logs.
51
+ // If spawning is necessary, the driver MUST spawn mongocryptd whenever server
52
+ // selection on the MongoClient to mongocryptd fails. If the MongoClient fails to
53
+ // connect after spawning, the server selection error is propagated to the user."
54
+ // The AutoEncrypter and MongoCryptdManager should work together to spawn
55
+ // mongocryptd whenever necessary. Additionally, the `mongocryptd` intentionally
56
+ // shuts down after 60s and gets respawned when necessary. We rely on server
57
+ // selection timeouts when connecting to the `mongocryptd` to inform users that something
58
+ // has been configured incorrectly. For those reasons, we suppress stderr from
59
+ // the `mongocryptd` process and immediately unref the process.
60
+ });
61
+ // unref child to remove handle from event loop
62
+ this._child.unref();
63
+ }
64
+ /**
65
+ * @returns the result of `fn` or rejects with an error.
66
+ */
67
+ async withRespawn(fn) {
68
+ try {
69
+ const result = await fn();
70
+ return result;
71
+ }
72
+ catch (err) {
73
+ // If we are not bypassing spawning, then we should retry once on a MongoTimeoutError (server selection error)
74
+ const shouldSpawn = err instanceof error_1.MongoNetworkTimeoutError && !this.bypassSpawn;
75
+ if (!shouldSpawn) {
76
+ throw err;
77
+ }
78
+ }
79
+ await this.spawn();
80
+ const result = await fn();
81
+ return result;
82
+ }
83
+ }
84
+ exports.MongocryptdManager = MongocryptdManager;
85
+ //# sourceMappingURL=mongocryptd_manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongocryptd_manager.js","sourceRoot":"","sources":["../../src/client-side-encryption/mongocryptd_manager.ts"],"names":[],"mappings":";;;AAEA,oCAAoD;AAGpD;;;GAGG;AACH,MAAa,kBAAkB;aACtB,4BAAuB,GAAG,2BAA2B,AAA9B,CAA+B;IAQ7D,YAAY,eAA2C,EAAE;QAJzD,cAAS,GAAG,EAAE,CAAC;QACf,cAAS,GAAkB,EAAE,CAAC;QAI5B,IAAI,CAAC,GAAG;YACN,OAAO,YAAY,CAAC,cAAc,KAAK,QAAQ,IAAI,YAAY,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC;gBACvF,CAAC,CAAC,YAAY,CAAC,cAAc;gBAC7B,CAAC,CAAC,kBAAkB,CAAC,uBAAuB,CAAC;QAEjD,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC,YAAY,CAAC,sBAAsB,CAAC;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jF,iFAAiF;YACjF,yEAAyE;YACzE,iFAAiF;YACjF,6EAA6E;YAC7E,yFAAyF;YACzF,+EAA+E;YAC/E,+DAA+D;QACjE,CAAC,CAAC,CAAC;QAEH,+CAA+C;QAC/C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAI,EAAoB;QACvC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;YAC1B,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,8GAA8G;YAC9G,MAAM,WAAW,GAAG,GAAG,YAAY,gCAAwB,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;YACjF,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjB,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;QACD,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;;AAzFH,gDA0FC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadAWSCredentials = loadAWSCredentials;
4
+ const aws_temporary_credentials_1 = require("../../cmap/auth/aws_temporary_credentials");
5
+ /**
6
+ * @internal
7
+ */
8
+ async function loadAWSCredentials(kmsProviders, provider) {
9
+ const credentialProvider = new aws_temporary_credentials_1.AWSSDKCredentialProvider(provider);
10
+ // We shouldn't ever receive a response from the AWS SDK that doesn't have a `SecretAccessKey`
11
+ // or `AccessKeyId`. However, TS says these fields are optional. We provide empty strings
12
+ // and let libmongocrypt error if we're unable to fetch the required keys.
13
+ const { SecretAccessKey = '', AccessKeyId = '', Token } = await credentialProvider.getCredentials();
14
+ const aws = {
15
+ secretAccessKey: SecretAccessKey,
16
+ accessKeyId: AccessKeyId
17
+ };
18
+ // the AWS session token is only required for temporary credentials so only attach it to the
19
+ // result if it's present in the response from the aws sdk
20
+ Token != null && (aws.sessionToken = Token);
21
+ return { ...kmsProviders, aws };
22
+ }
23
+ //# sourceMappingURL=aws.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws.js","sourceRoot":"","sources":["../../../src/client-side-encryption/providers/aws.ts"],"names":[],"mappings":";;AASA,gDAuBC;AAhCD,yFAGmD;AAGnD;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,YAA0B,EAC1B,QAAgC;IAEhC,MAAM,kBAAkB,GAAG,IAAI,oDAAwB,CAAC,QAAQ,CAAC,CAAC;IAElE,8FAA8F;IAC9F,2FAA2F;IAC3F,0EAA0E;IAC1E,MAAM,EACJ,eAAe,GAAG,EAAE,EACpB,WAAW,GAAG,EAAE,EAChB,KAAK,EACN,GAAG,MAAM,kBAAkB,CAAC,cAAc,EAAE,CAAC;IAC9C,MAAM,GAAG,GAAqC;QAC5C,eAAe,EAAE,eAAe;QAChC,WAAW,EAAE,WAAW;KACzB,CAAC;IACF,4FAA4F;IAC5F,0DAA0D;IAC1D,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC;IAE5C,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,EAAE,CAAC;AAClC,CAAC"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tokenCache = exports.AzureCredentialCache = exports.AZURE_BASE_URL = void 0;
4
+ exports.addAzureParams = addAzureParams;
5
+ exports.prepareRequest = prepareRequest;
6
+ exports.fetchAzureKMSToken = fetchAzureKMSToken;
7
+ exports.loadAzureCredentials = loadAzureCredentials;
8
+ const error_1 = require("../../error");
9
+ const utils_1 = require("../../utils");
10
+ const errors_1 = require("../errors");
11
+ const MINIMUM_TOKEN_REFRESH_IN_MILLISECONDS = 6000;
12
+ /** Base URL for getting Azure tokens. */
13
+ exports.AZURE_BASE_URL = 'http://169.254.169.254/metadata/identity/oauth2/token?';
14
+ /**
15
+ * @internal
16
+ */
17
+ class AzureCredentialCache {
18
+ constructor() {
19
+ this.cachedToken = null;
20
+ }
21
+ async getToken() {
22
+ if (this.cachedToken == null || this.needsRefresh(this.cachedToken)) {
23
+ this.cachedToken = await this._getToken();
24
+ }
25
+ return { accessToken: this.cachedToken.accessToken };
26
+ }
27
+ needsRefresh(token) {
28
+ const timeUntilExpirationMS = token.expiresOnTimestamp - Date.now();
29
+ return timeUntilExpirationMS <= MINIMUM_TOKEN_REFRESH_IN_MILLISECONDS;
30
+ }
31
+ /**
32
+ * exposed for testing
33
+ */
34
+ resetCache() {
35
+ this.cachedToken = null;
36
+ }
37
+ /**
38
+ * exposed for testing
39
+ */
40
+ _getToken() {
41
+ return fetchAzureKMSToken();
42
+ }
43
+ }
44
+ exports.AzureCredentialCache = AzureCredentialCache;
45
+ /** @internal */
46
+ exports.tokenCache = new AzureCredentialCache();
47
+ /** @internal */
48
+ async function parseResponse(response) {
49
+ const { status, body: rawBody } = response;
50
+ const body = (() => {
51
+ try {
52
+ return JSON.parse(rawBody);
53
+ }
54
+ catch {
55
+ throw new errors_1.MongoCryptAzureKMSRequestError('Malformed JSON body in GET request.');
56
+ }
57
+ })();
58
+ if (status !== 200) {
59
+ throw new errors_1.MongoCryptAzureKMSRequestError('Unable to complete request.', body);
60
+ }
61
+ if (!body.access_token) {
62
+ throw new errors_1.MongoCryptAzureKMSRequestError('Malformed response body - missing field `access_token`.');
63
+ }
64
+ if (!body.expires_in) {
65
+ throw new errors_1.MongoCryptAzureKMSRequestError('Malformed response body - missing field `expires_in`.');
66
+ }
67
+ const expiresInMS = Number(body.expires_in) * 1000;
68
+ if (Number.isNaN(expiresInMS)) {
69
+ throw new errors_1.MongoCryptAzureKMSRequestError('Malformed response body - unable to parse int from `expires_in` field.');
70
+ }
71
+ return {
72
+ accessToken: body.access_token,
73
+ expiresOnTimestamp: Date.now() + expiresInMS
74
+ };
75
+ }
76
+ /**
77
+ * @internal
78
+ * Get the Azure endpoint URL.
79
+ */
80
+ function addAzureParams(url, resource, username) {
81
+ url.searchParams.append('api-version', '2018-02-01');
82
+ url.searchParams.append('resource', resource);
83
+ if (username) {
84
+ url.searchParams.append('client_id', username);
85
+ }
86
+ return url;
87
+ }
88
+ /**
89
+ * @internal
90
+ *
91
+ * parses any options provided by prose tests to `fetchAzureKMSToken` and merges them with
92
+ * the default values for headers and the request url.
93
+ */
94
+ function prepareRequest(options) {
95
+ const url = new URL(options.url?.toString() ?? exports.AZURE_BASE_URL);
96
+ addAzureParams(url, 'https://vault.azure.net');
97
+ const headers = { ...options.headers, 'Content-Type': 'application/json', Metadata: true };
98
+ return { headers, url };
99
+ }
100
+ /**
101
+ * @internal
102
+ *
103
+ * `AzureKMSRequestOptions` allows prose tests to modify the http request sent to the idms
104
+ * servers. This is required to simulate different server conditions. No options are expected to
105
+ * be set outside of tests.
106
+ *
107
+ * exposed for CSFLE
108
+ * [prose test 18](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#azure-imds-credentials)
109
+ */
110
+ async function fetchAzureKMSToken(options = {}) {
111
+ const { headers, url } = prepareRequest(options);
112
+ try {
113
+ const response = await (0, utils_1.get)(url, { headers });
114
+ return await parseResponse(response);
115
+ }
116
+ catch (error) {
117
+ if (error instanceof error_1.MongoNetworkTimeoutError) {
118
+ throw new errors_1.MongoCryptAzureKMSRequestError(`[Azure KMS] ${error.message}`);
119
+ }
120
+ throw error;
121
+ }
122
+ }
123
+ /**
124
+ * @internal
125
+ *
126
+ * @throws Will reject with a `MongoCryptError` if the http request fails or the http response is malformed.
127
+ */
128
+ async function loadAzureCredentials(kmsProviders) {
129
+ const azure = await exports.tokenCache.getToken();
130
+ return { ...kmsProviders, azure };
131
+ }
132
+ //# sourceMappingURL=azure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"azure.js","sourceRoot":"","sources":["../../../src/client-side-encryption/providers/azure.ts"],"names":[],"mappings":";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C,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,sBAAc,CAAC,CAAC;IAC/D,cAAc,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC3F,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,kBAAkB,CACtC,UAAkC,EAAE;IAEpC,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IACjD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,IAAA,WAAG,EAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7C,OAAO,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,gCAAwB,EAAE,CAAC;YAC9C,MAAM,IAAI,uCAA8B,CAAC,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,oBAAoB,CAAC,YAA0B;IACnE,MAAM,KAAK,GAAG,MAAM,kBAAU,CAAC,QAAQ,EAAE,CAAC;IAC1C,OAAO,EAAE,GAAG,YAAY,EAAE,KAAK,EAAE,CAAC;AACpC,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadGCPCredentials = loadGCPCredentials;
4
+ const deps_1 = require("../../deps");
5
+ /** @internal */
6
+ async function loadGCPCredentials(kmsProviders) {
7
+ const gcpMetadata = (0, deps_1.getGcpMetadata)();
8
+ if ('kModuleError' in gcpMetadata) {
9
+ return kmsProviders;
10
+ }
11
+ const { access_token: accessToken } = await gcpMetadata.instance({
12
+ property: 'service-accounts/default/token'
13
+ });
14
+ return { ...kmsProviders, gcp: { accessToken } };
15
+ }
16
+ //# sourceMappingURL=gcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcp.js","sourceRoot":"","sources":["../../../src/client-side-encryption/providers/gcp.ts"],"names":[],"mappings":";;AAIA,gDAWC;AAfD,qCAA4C;AAG5C,gBAAgB;AACT,KAAK,UAAU,kBAAkB,CAAC,YAA0B;IACjE,MAAM,WAAW,GAAG,IAAA,qBAAc,GAAE,CAAC;IAErC,IAAI,cAAc,IAAI,WAAW,EAAE,CAAC;QAClC,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,WAAW,CAAC,QAAQ,CAA2B;QACzF,QAAQ,EAAE,gCAAgC;KAC3C,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,EAAE,EAAE,WAAW,EAAE,EAAE,CAAC;AACnD,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEmptyCredentials = isEmptyCredentials;
4
+ exports.refreshKMSCredentials = refreshKMSCredentials;
5
+ const aws_1 = require("./aws");
6
+ const azure_1 = require("./azure");
7
+ const gcp_1 = require("./gcp");
8
+ /**
9
+ * Auto credential fetching should only occur when the provider is defined on the kmsProviders map
10
+ * and the settings are an empty object.
11
+ *
12
+ * This is distinct from a nullish provider key.
13
+ *
14
+ * @internal - exposed for testing purposes only
15
+ */
16
+ function isEmptyCredentials(providerName, kmsProviders) {
17
+ const provider = kmsProviders[providerName];
18
+ if (provider == null) {
19
+ return false;
20
+ }
21
+ return typeof provider === 'object' && Object.keys(provider).length === 0;
22
+ }
23
+ /**
24
+ * Load cloud provider credentials for the user provided KMS providers.
25
+ * Credentials will only attempt to get loaded if they do not exist
26
+ * and no existing credentials will get overwritten.
27
+ *
28
+ * @internal
29
+ */
30
+ async function refreshKMSCredentials(kmsProviders, credentialProviders) {
31
+ let finalKMSProviders = kmsProviders;
32
+ if (isEmptyCredentials('aws', kmsProviders)) {
33
+ finalKMSProviders = await (0, aws_1.loadAWSCredentials)(finalKMSProviders, credentialProviders?.aws);
34
+ }
35
+ if (isEmptyCredentials('gcp', kmsProviders)) {
36
+ finalKMSProviders = await (0, gcp_1.loadGCPCredentials)(finalKMSProviders);
37
+ }
38
+ if (isEmptyCredentials('azure', kmsProviders)) {
39
+ finalKMSProviders = await (0, azure_1.loadAzureCredentials)(finalKMSProviders);
40
+ }
41
+ return finalKMSProviders;
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client-side-encryption/providers/index.ts"],"names":[],"mappings":";;AA0KA,gDASC;AASD,sDAkBC;AA5MD,+BAA2C;AAC3C,mCAA+C;AAC/C,+BAA2C;AA8J3C;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,YAA6C,EAC7C,YAA0B;IAE1B,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;IAC5C,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,OAAO,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;AAC5E,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,qBAAqB,CACzC,YAA0B,EAC1B,mBAAyC;IAEzC,IAAI,iBAAiB,GAAG,YAAY,CAAC;IAErC,IAAI,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,CAAC;QAC5C,iBAAiB,GAAG,MAAM,IAAA,wBAAkB,EAAC,iBAAiB,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC;IAC5F,CAAC;IAED,IAAI,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,CAAC;QAC5C,iBAAiB,GAAG,MAAM,IAAA,wBAAkB,EAAC,iBAAiB,CAAC,CAAC;IAClE,CAAC;IAED,IAAI,kBAAkB,CAAC,OAAO,EAAE,YAAY,CAAC,EAAE,CAAC;QAC9C,iBAAiB,GAAG,MAAM,IAAA,4BAAoB,EAAC,iBAAiB,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC"}