deps.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getMongoDBClientEncryption = exports.aws4 = exports.getSocks = exports.getSnappy = exports.getGcpMetadata = exports.getAwsCredentialProvider = exports.getZstdLibrary = exports.ZStandard = exports.getKerberos = exports.Kerberos = void 0;
  4. const error_1 = require("./error");
  5. function makeErrorModule(error) {
  6. const props = error ? { kModuleError: error } : {};
  7. return new Proxy(props, {
  8. get: (_, key) => {
  9. if (key === 'kModuleError') {
  10. return error;
  11. }
  12. throw error;
  13. },
  14. set: () => {
  15. throw error;
  16. }
  17. });
  18. }
  19. exports.Kerberos = makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `kerberos` not found. Please install it to enable kerberos authentication'));
  20. function getKerberos() {
  21. try {
  22. // Ensure you always wrap an optional require in the try block NODE-3199
  23. exports.Kerberos = require('kerberos');
  24. return exports.Kerberos;
  25. }
  26. catch {
  27. return exports.Kerberos;
  28. }
  29. }
  30. exports.getKerberos = getKerberos;
  31. exports.ZStandard = makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `@mongodb-js/zstd` not found. Please install it to enable zstd compression'));
  32. function getZstdLibrary() {
  33. try {
  34. exports.ZStandard = require('@mongodb-js/zstd');
  35. return exports.ZStandard;
  36. }
  37. catch {
  38. return exports.ZStandard;
  39. }
  40. }
  41. exports.getZstdLibrary = getZstdLibrary;
  42. function getAwsCredentialProvider() {
  43. try {
  44. // Ensure you always wrap an optional require in the try block NODE-3199
  45. const credentialProvider = require('@aws-sdk/credential-providers');
  46. return credentialProvider;
  47. }
  48. catch {
  49. return makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `@aws-sdk/credential-providers` not found.' +
  50. ' Please install it to enable getting aws credentials via the official sdk.'));
  51. }
  52. }
  53. exports.getAwsCredentialProvider = getAwsCredentialProvider;
  54. function getGcpMetadata() {
  55. try {
  56. // Ensure you always wrap an optional require in the try block NODE-3199
  57. const credentialProvider = require('gcp-metadata');
  58. return credentialProvider;
  59. }
  60. catch {
  61. return makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `gcp-metadata` not found.' +
  62. ' Please install it to enable getting gcp credentials via the official sdk.'));
  63. }
  64. }
  65. exports.getGcpMetadata = getGcpMetadata;
  66. function getSnappy() {
  67. try {
  68. // Ensure you always wrap an optional require in the try block NODE-3199
  69. const value = require('snappy');
  70. return value;
  71. }
  72. catch (cause) {
  73. const kModuleError = new error_1.MongoMissingDependencyError('Optional module `snappy` not found. Please install it to enable snappy compression', { cause });
  74. return { kModuleError };
  75. }
  76. }
  77. exports.getSnappy = getSnappy;
  78. function getSocks() {
  79. try {
  80. // Ensure you always wrap an optional require in the try block NODE-3199
  81. const value = require('socks');
  82. return value;
  83. }
  84. catch (cause) {
  85. const kModuleError = new error_1.MongoMissingDependencyError('Optional module `socks` not found. Please install it to connections over a SOCKS5 proxy', { cause });
  86. return { kModuleError };
  87. }
  88. }
  89. exports.getSocks = getSocks;
  90. exports.aws4 = makeErrorModule(new error_1.MongoMissingDependencyError('Optional module `aws4` not found. Please install it to enable AWS authentication'));
  91. try {
  92. // Ensure you always wrap an optional require in the try block NODE-3199
  93. exports.aws4 = require('aws4');
  94. }
  95. catch { } // eslint-disable-line
  96. /** A utility function to get the instance of mongodb-client-encryption, if it exists. */
  97. function getMongoDBClientEncryption() {
  98. let mongodbClientEncryption = null;
  99. try {
  100. // NOTE(NODE-3199): Ensure you always wrap an optional require literally in the try block
  101. // Cannot be moved to helper utility function, bundlers search and replace the actual require call
  102. // in a way that makes this line throw at bundle time, not runtime, catching here will make bundling succeed
  103. mongodbClientEncryption = require('mongodb-client-encryption');
  104. }
  105. catch (cause) {
  106. const kModuleError = new error_1.MongoMissingDependencyError('Optional module `mongodb-client-encryption` not found. Please install it to use auto encryption or ClientEncryption.', { cause });
  107. return { kModuleError };
  108. }
  109. return mongodbClientEncryption;
  110. }
  111. exports.getMongoDBClientEncryption = getMongoDBClientEncryption;
  112. //# sourceMappingURL=deps.js.map