diff --git a/package-lock.json b/package-lock.json index f791aee72fb..c0b7541ef00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6209,41 +6209,6 @@ "@leafygreen-ui/leafygreen-provider": "^3.1.0" } }, - "node_modules/@leichtgewicht/base64-codec": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@leichtgewicht/base64-codec/-/base64-codec-1.0.0.tgz", - "integrity": "sha512-0cgP4lRBzh3F4tlpTfs7F+PJyBN8j5yUC9KrQFWp/bREswgzZVHE8T1rNyRDWgvALwwpPtnJDQfqWUmxI33Epg==", - "dev": true - }, - "node_modules/@leichtgewicht/dns-packet": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/@leichtgewicht/dns-packet/-/dns-packet-6.0.3.tgz", - "integrity": "sha512-qmVHhFBFiBvPsk/wJ/EdoWHb+tGkzY4haybmDPukhF6w0+8wpEbrHTIRE9LzeUu2P0bAbmrK8WOXt5V5QN6jQg==", - "dev": true, - "dependencies": { - "@leichtgewicht/ip-codec": "^2.0.4", - "bytes.js": "^0.0.2", - "utf8-bytes": "^0.0.1", - "utf8-codec": "^1.0.0", - "utf8-length": "^0.0.1", - "utf8-string-bytes": "^1.0.3" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/@leichtgewicht/dns-socket": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@leichtgewicht/dns-socket/-/dns-socket-5.0.0.tgz", - "integrity": "sha512-Sbrn/OG0HTTPGSkwIDCHy8/tUI6UglIzFsMNjzZn/Na1/i5owSm6rVi9CfKNNjRcUlYEzICELYW6EoZdjwVY2A==", - "dev": true, - "dependencies": { - "@leichtgewicht/dns-packet": "^6.0.0" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/@leichtgewicht/ip-codec": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz", @@ -17616,12 +17581,6 @@ "node": ">= 0.8" } }, - "node_modules/bytes.js": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/bytes.js/-/bytes.js-0.0.2.tgz", - "integrity": "sha512-KrLm4hv5Qs9w6b0U7h1bCdqxrsf+e9QMsfHeyQFzAz94x/5Aqa+FTEUSNBtt5d2VuV3Hfiea3c4ti74RZDDYkg==", - "dev": true - }, "node_modules/cacache": { "version": "15.2.0", "resolved": "https://registry.npmjs.org/cacache/-/cacache-15.2.0.tgz", @@ -20342,22 +20301,6 @@ "node": ">=6" } }, - "node_modules/dns-query": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/dns-query/-/dns-query-0.11.2.tgz", - "integrity": "sha512-zF8qxQpqCB467o4A63DLpQClo77H642JEKMx0Ra9GFww7Rx0234Fo8NoG0LBoSBZxamWkXfLxhzDG19bTBHvXQ==", - "dev": true, - "dependencies": { - "@leichtgewicht/base64-codec": "^1.0.0", - "@leichtgewicht/dns-packet": "^6.0.2", - "@leichtgewicht/dns-socket": "^5.0.0", - "@leichtgewicht/ip-codec": "^2.0.4", - "utf8-codec": "^1.0.0" - }, - "bin": { - "dns-query": "bin/dns-query" - } - }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -42226,30 +42169,6 @@ "node": ">=0.10.0" } }, - "node_modules/utf8-bytes": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/utf8-bytes/-/utf8-bytes-0.0.1.tgz", - "integrity": "sha512-GifWmJAx2qAXT+lZLhbkWhBsy7pr6xWHiPWlVToDiELdWgZwt4Ogjf9tlgvKuALzTFR/d+EPQQI9ogJV3957Jg==", - "dev": true - }, - "node_modules/utf8-codec": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/utf8-codec/-/utf8-codec-1.0.0.tgz", - "integrity": "sha512-S/QSLezp3qvG4ld5PUfXiH7mCFxLKjSVZRFkB3DOjgwHuJPFDkInAXc/anf7BAbHt/D38ozDzL+QMZ6/7gsI6w==", - "dev": true - }, - "node_modules/utf8-length": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/utf8-length/-/utf8-length-0.0.1.tgz", - "integrity": "sha512-j/XH2ftofBiobnyApxlN/J6j/ixwT89WEjDcjT66d2i0+GIn9RZfzt8lpEXXE4jUe4NsjBSUq70kS2euQ4nnMw==", - "dev": true - }, - "node_modules/utf8-string-bytes": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/utf8-string-bytes/-/utf8-string-bytes-1.0.3.tgz", - "integrity": "sha512-i/I1Omf6lADjVBlwJpQifZOePV15snHny9w04+lc71+3t8PyWuLC/7clyoOSHOBNGXFe2PAGxmTiZ+Z4HWsPyw==", - "dev": true - }, "node_modules/util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", @@ -47888,7 +47807,6 @@ "chai": "^4.3.6", "compass-preferences-model": "^2.17.1", "depcheck": "^1.4.1", - "dns-query": "^0.11.2", "eslint": "^7.25.0", "events": "^3.3.0", "hadron-app-registry": "^9.1.4", @@ -57335,35 +57253,6 @@ "@leafygreen-ui/tokens": "^1.4.1" } }, - "@leichtgewicht/base64-codec": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@leichtgewicht/base64-codec/-/base64-codec-1.0.0.tgz", - "integrity": "sha512-0cgP4lRBzh3F4tlpTfs7F+PJyBN8j5yUC9KrQFWp/bREswgzZVHE8T1rNyRDWgvALwwpPtnJDQfqWUmxI33Epg==", - "dev": true - }, - "@leichtgewicht/dns-packet": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/@leichtgewicht/dns-packet/-/dns-packet-6.0.3.tgz", - "integrity": "sha512-qmVHhFBFiBvPsk/wJ/EdoWHb+tGkzY4haybmDPukhF6w0+8wpEbrHTIRE9LzeUu2P0bAbmrK8WOXt5V5QN6jQg==", - "dev": true, - "requires": { - "@leichtgewicht/ip-codec": "^2.0.4", - "bytes.js": "^0.0.2", - "utf8-bytes": "^0.0.1", - "utf8-codec": "^1.0.0", - "utf8-length": "^0.0.1", - "utf8-string-bytes": "^1.0.3" - } - }, - "@leichtgewicht/dns-socket": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@leichtgewicht/dns-socket/-/dns-socket-5.0.0.tgz", - "integrity": "sha512-Sbrn/OG0HTTPGSkwIDCHy8/tUI6UglIzFsMNjzZn/Na1/i5owSm6rVi9CfKNNjRcUlYEzICELYW6EoZdjwVY2A==", - "dev": true, - "requires": { - "@leichtgewicht/dns-packet": "^6.0.0" - } - }, "@leichtgewicht/ip-codec": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz", @@ -61006,7 +60895,6 @@ "chai": "^4.3.6", "compass-preferences-model": "^2.17.1", "depcheck": "^1.4.1", - "dns-query": "^0.11.2", "eslint": "^7.25.0", "events": "^3.3.0", "hadron-app-registry": "^9.1.4", @@ -72017,12 +71905,6 @@ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" }, - "bytes.js": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/bytes.js/-/bytes.js-0.0.2.tgz", - "integrity": "sha512-KrLm4hv5Qs9w6b0U7h1bCdqxrsf+e9QMsfHeyQFzAz94x/5Aqa+FTEUSNBtt5d2VuV3Hfiea3c4ti74RZDDYkg==", - "dev": true - }, "cacache": { "version": "15.2.0", "resolved": "https://registry.npmjs.org/cacache/-/cacache-15.2.0.tgz", @@ -74802,19 +74684,6 @@ "@leichtgewicht/ip-codec": "^2.0.1" } }, - "dns-query": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/dns-query/-/dns-query-0.11.2.tgz", - "integrity": "sha512-zF8qxQpqCB467o4A63DLpQClo77H642JEKMx0Ra9GFww7Rx0234Fo8NoG0LBoSBZxamWkXfLxhzDG19bTBHvXQ==", - "dev": true, - "requires": { - "@leichtgewicht/base64-codec": "^1.0.0", - "@leichtgewicht/dns-packet": "^6.0.2", - "@leichtgewicht/dns-socket": "^5.0.0", - "@leichtgewicht/ip-codec": "^2.0.4", - "utf8-codec": "^1.0.0" - } - }, "doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -93433,30 +93302,6 @@ "os-homedir": "^1.0.0" } }, - "utf8-bytes": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/utf8-bytes/-/utf8-bytes-0.0.1.tgz", - "integrity": "sha512-GifWmJAx2qAXT+lZLhbkWhBsy7pr6xWHiPWlVToDiELdWgZwt4Ogjf9tlgvKuALzTFR/d+EPQQI9ogJV3957Jg==", - "dev": true - }, - "utf8-codec": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/utf8-codec/-/utf8-codec-1.0.0.tgz", - "integrity": "sha512-S/QSLezp3qvG4ld5PUfXiH7mCFxLKjSVZRFkB3DOjgwHuJPFDkInAXc/anf7BAbHt/D38ozDzL+QMZ6/7gsI6w==", - "dev": true - }, - "utf8-length": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/utf8-length/-/utf8-length-0.0.1.tgz", - "integrity": "sha512-j/XH2ftofBiobnyApxlN/J6j/ixwT89WEjDcjT66d2i0+GIn9RZfzt8lpEXXE4jUe4NsjBSUq70kS2euQ4nnMw==", - "dev": true - }, - "utf8-string-bytes": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/utf8-string-bytes/-/utf8-string-bytes-1.0.3.tgz", - "integrity": "sha512-i/I1Omf6lADjVBlwJpQifZOePV15snHny9w04+lc71+3t8PyWuLC/7clyoOSHOBNGXFe2PAGxmTiZ+Z4HWsPyw==", - "dev": true - }, "util": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", diff --git a/packages/compass-web/package.json b/packages/compass-web/package.json index 9b060baab81..f3c9b079a9d 100644 --- a/packages/compass-web/package.json +++ b/packages/compass-web/package.json @@ -92,7 +92,6 @@ "chai": "^4.3.6", "compass-preferences-model": "^2.17.1", "depcheck": "^1.4.1", - "dns-query": "^0.11.2", "eslint": "^7.25.0", "events": "^3.3.0", "hadron-app-registry": "^9.1.4", diff --git a/packages/compass-web/polyfills/@mongodb-js/devtools-connect/index.ts b/packages/compass-web/polyfills/@mongodb-js/devtools-connect/index.ts new file mode 100644 index 00000000000..3769fe363ef --- /dev/null +++ b/packages/compass-web/polyfills/@mongodb-js/devtools-connect/index.ts @@ -0,0 +1,28 @@ +export function hookLogger() { + /* no-op */ +} +export async function connectMongoClient( + url: string, + options: any, + logger: any, + MongoClient: any +): Promise { + // Remove options not understood by the plain Node.js driver + delete options.useSystemCA; + delete options.productDocsLink; + delete options.productName; + delete options.oidc; + delete options.parentState; + delete options.parentHandle; + const client = new MongoClient(url, options); + await client.connect(); + return { + client, + state: { + getStateShareServer() { + return Promise.resolve('Not Available'); + }, + oidcPlugin: { logger }, + }, + }; +} diff --git a/packages/compass-web/polyfills/@mongodb-js/oidc-plugin/index.ts b/packages/compass-web/polyfills/@mongodb-js/oidc-plugin/index.ts deleted file mode 100644 index c7858314de8..00000000000 --- a/packages/compass-web/polyfills/@mongodb-js/oidc-plugin/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -export function createMongoDBOIDCPlugin() { - return { - logger: { - on() { - // noop - }, - off() { - // noop - }, - once() { - // noop - }, - addListener() { - // noop - }, - removeListener() { - // noop - }, - }, - }; -} diff --git a/packages/compass-web/polyfills/dns/index.ts b/packages/compass-web/polyfills/dns/index.ts deleted file mode 100644 index af38da49fe0..00000000000 --- a/packages/compass-web/polyfills/dns/index.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { query, wellknown, lookupTxt } from 'dns-query'; -import { promisify } from 'util'; -export function resolveSrv( - hostname: string, - cb: (err: any | null, res?: any) => void -) { - query( - { question: { type: 'SRV', name: hostname } }, - { endpoints: wellknown.endpoints('doh') } - ).then(({ answers }) => { - cb( - null, - answers?.flatMap((answer) => { - if (answer.type !== 'SRV') { - return []; - } - return { - ...answer.data, - name: answer.data.target, - }; - }) - ); - }, cb); -} -export function resolveTxt( - hostname: string, - cb: (err: any | null, res?: any) => void -) { - lookupTxt(hostname, { endpoints: wellknown.endpoints('doh') }).then( - ({ entries }) => { - cb( - null, - entries.map((entry) => { - return [entry.data]; - }) - ); - }, - cb - ); -} -export const promises = { - resolveSrv: promisify(resolveSrv), - resolveTxt: promisify(resolveTxt), -}; -export default { - resolveSrv, - resolveTxt, - promises, -}; diff --git a/packages/compass-web/polyfills/http/index.ts b/packages/compass-web/polyfills/http/index.ts deleted file mode 100644 index 9558f9f4285..00000000000 --- a/packages/compass-web/polyfills/http/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { EventEmitter } from 'events'; -class Server extends EventEmitter { - listen() { - queueMicrotask(() => { - this.emit('listening'); - }); - } - address() { - return null; - } - close() { - // noop - } -} -export function createServer() { - return new Server(); -} diff --git a/packages/compass-web/polyfills/os-dns-native/index.ts b/packages/compass-web/polyfills/os-dns-native/index.ts deleted file mode 100644 index 5dbd57c902f..00000000000 --- a/packages/compass-web/polyfills/os-dns-native/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { resolveSrv, resolveTxt } from 'dns'; -export const withNodeFallback = { resolveSrv, resolveTxt }; -export function wasNativelyLookedUp() { - return false; -} diff --git a/packages/compass-web/polyfills/os/index.ts b/packages/compass-web/polyfills/os/index.ts deleted file mode 100644 index 359dc59d566..00000000000 --- a/packages/compass-web/polyfills/os/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export function tmpdir() { - return ''; -} -export default { tmpdir }; diff --git a/packages/compass-web/webpack.config.js b/packages/compass-web/webpack.config.js index 95c1c905bd8..56682ef6460 100644 --- a/packages/compass-web/webpack.config.js +++ b/packages/compass-web/webpack.config.js @@ -29,34 +29,22 @@ module.exports = async (env, args) => { '@mongodb-js/ssh-tunnel': false, ssh2: false, - // Dependencies for the unsupported connection types in data-service -> - // devtools-connect package - // TODO(COMPASS-7552): We should refactor the package in a way that - // sould allow us to change all these to `{ : false }` instead of - // providing polyfills - // used for useSystemCA option - 'system-ca': false, - // used for oidc - '@mongodb-js/oidc-plugin': localPolyfill('@mongodb-js/oidc-plugin'), - http: localPolyfill('http'), - zlib: false, - os: localPolyfill('os'), + // Used for randomBytes in a few places crypto: localPolyfill('crypto'), - // used for +srv - dns: false, - 'os-dns-native': false, - 'resolve-mongodb-srv': false, - // for socks proxy connection - socks: false, - // for csfle - 'mongodb-client-encryption': false, - // for kerberos connection - kerberos: false, + + // Replace 'devtools-connect' with a package that just directly connects + // using the driver (= web-compatible driver) logic, because devtools-connect + // contains a lot of logic that makes sense in a desktop application/CLI but + // not in a web environment (DNS resolution, OIDC, CSFLE/QE, etc.) + '@mongodb-js/devtools-connect': localPolyfill( + '@mongodb-js/devtools-connect' + ), // TODO(COMPASS-7407): compass-logging // hard to disable the whole thing while there are direct dependencies // on log-writer // 'mongodb-log-writer': localPolyfill('mongodb-log-writer'), + zlib: false, v8: false, electron: false, 'hadron-ipc': false, @@ -129,21 +117,6 @@ module.exports = async (env, args) => { // TODO(ticket): move mongodb-browser from mms to the monorepo and // package it too mongodb: require.resolve('@gribnoysup/mongodb-browser'), - - // NB: We polyfill those in `@gribnoysup/mongodb-browser` already, but - // devtools-connect does its own dns resolution (for a good reason - // COMPASS-4768) for srv so we have to do it again. This is something - // that potentially mms will also need to adjust on their side if they - // ever want to support passing srv connections as-is (but they don't - // need to, they already have a resolved info for connection on their - // side) - dns: localPolyfill('dns'), - 'os-dns-native': localPolyfill('os-dns-native'), - - // We exclude it for the published distribution as it requires dns - // resolution to work which is not expected. Re-include for the - // sandbox - 'resolve-mongodb-srv': require.resolve('resolve-mongodb-srv'), }, }, });