From 7bd48f1c22b28d1853fb4105d4ec8405d757e8ee Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 20 May 2024 18:39:43 -0400 Subject: [PATCH 1/9] chore(NODE-6177): set up tooling for new repo --- .github/workflows/build.yml | 24 +++ .gitignore | 2 + CHANGELOG.md | 119 ------------ HISTORY.md | 359 ++++++++++++++++++++++++++++++++++++ etc/build-static.sh | 40 ---- etc/libmongocrypt.mjs | 116 ++++++++++++ package.json | 11 +- test/release.test.ts | 2 +- 8 files changed, 507 insertions(+), 166 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 CHANGELOG.md create mode 100644 HISTORY.md delete mode 100755 etc/build-static.sh create mode 100644 etc/libmongocrypt.mjs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5a4d2c7 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +on: + push: + branches: [main] + workflow_dispatch: {} + +name: build + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node: ['20.x'] # '16.x', '18.x', + name: Node.js ${{ matrix.node }} build + steps: + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + registry-url: 'https://registry.npmjs.org' + - run: npm install -g npm@latest + shell: bash + - run: node etc/libmongocrypt.mjs + shell: bash diff --git a/.gitignore b/.gitignore index c621400..677c37f 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ xunit.xml # built typescript lib prebuilds + +_libmongocrypt/ diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 8edf70d..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,119 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - -## [6.0.0](https://github.com/mongodb/libmongocrypt/compare/node-v6.0.0-alpha.3...node-v6.0.0) (2023-08-28) - -## [6.0.0-alpha.3](https://github.com/mongodb/libmongocrypt/compare/node-v6.0.0-alpha.2...node-v6.0.0-alpha.3) (2023-08-09) - -## [6.0.0-alpha.2](https://github.com/mongodb/libmongocrypt/compare/node-v2.9.0...node-v6.0.0-alpha.2) (2023-08-07) - -## [6.0.0-alpha.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.9.0...node-v6.0.0-alpha.1) (2023-07-27) - -## [6.0.0-alpha.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.9.0...node-v6.0.0-alpha.0) (2023-07-13) - -## [2.9.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.8.0...node-v2.9.0) (2023-07-12) - -## [2.8.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.8.0-alpha.0...node-v2.8.0) (2023-05-11) - -## [2.8.0-alpha.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.8.0-alpha.0...node-v2.8.0-alpha.1) (2023-04-27) - -## [2.8.0-alpha.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.7.1...node-v2.8.0-alpha.0) (2023-04-04) - -### [2.7.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.7.0...node-v2.7.1) (2023-03-20) - -## [2.7.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.7.0-alpha.0...node-v2.7.0) (2023-03-20) - -## [2.7.0-alpha.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.6.0...node-v2.7.0-alpha.0) (2023-03-14) - -## [2.6.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.6.0-alpha.0...node-v2.6.0) (2023-02-23) - -## [2.6.0-alpha.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.5.0...node-v2.6.0-alpha.0) (2023-02-16) - -## [2.5.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.4.0...node-v2.5.0) (2023-02-06) - -## [2.4.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.4.0-alpha.2...node-v2.4.0) (2023-01-26) - -## [2.4.0-alpha.2](https://github.com/mongodb/libmongocrypt/compare/node-v2.4.0-alpha.0...node-v2.4.0-alpha.2) (2023-01-24) - -## [2.4.0-alpha.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.4.0-alpha.0...node-v2.4.0-alpha.1) (2023-01-23) - -## [2.4.0-alpha.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.3.0...node-v2.4.0-alpha.0) (2023-01-20) - -## [2.3.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.1...node-v2.3.0) (2022-10-05) - -### [2.2.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0...node-v2.2.1) (2022-09-12) - -## [2.2.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.6...node-v2.2.0) (2022-08-10) - -## [2.2.0-alpha.6](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.5...node-v2.2.0-alpha.6) (2022-07-29) - -## [2.2.0-alpha.6](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.5...node-v2.2.0-alpha.6) (2022-07-29) - -## [2.2.0-alpha.5](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.4...node-v2.2.0-alpha.5) (2022-07-20) - -## [2.2.0-alpha.5](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.4...node-v2.2.0-alpha.5) (2022-07-20) - -## [2.2.0-alpha.4](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.3...node-v2.2.0-alpha.4) (2022-07-06) - -## [2.2.0-alpha.3](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.2...node-v2.2.0-alpha.3) (2022-06-23) - -## [2.2.0-alpha.2](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.1...node-v2.2.0-alpha.2) (2022-06-10) - -## [2.2.0-alpha.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.2.0-alpha.0...node-v2.2.0-alpha.1) (2022-06-01) - -## [2.2.0-alpha.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.1.0...node-v2.2.0-alpha.0) (2022-05-04) - -## [2.1.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0...node-v2.1.0) (2022-04-21) - -## [2.0.0](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.4...node-v2.0.0) (2022-02-17) - -## [2.0.0-beta.4](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.3...node-v2.0.0-beta.4) (2022-02-09) - -## [2.0.0-beta.3](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.0...node-v2.0.0-beta.3) (2022-01-31) - -## [2.0.0-beta.2](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.0...node-v2.0.0-beta.2) (2021-12-22) - -## [2.0.0-beta.1](https://github.com/mongodb/libmongocrypt/compare/node-v2.0.0-beta.0...node-v2.0.0-beta.1) (2021-12-21) - -## [2.0.0-beta.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.7...node-v2.0.0-beta.0) (2021-10-07) - -### [1.2.7](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.6...node-v1.2.7) (2021-09-14) - -### [1.2.6](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.5...node-v1.2.6) (2021-07-01) - -### [1.2.5](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.4...node-v1.2.5) (2021-06-10) - -### [1.2.4](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.3...node-v1.2.4) (2021-06-01) - -### [1.2.3](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.2...node-v1.2.3) (2021-04-06) - -### [1.2.2](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.1...node-v1.2.2) (2021-03-16) - -### [1.2.1](https://github.com/mongodb/libmongocrypt/compare/node-v1.2.0...node-v1.2.1) (2021-02-05) - -## [1.2.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.1.0...node-v1.2.0) (2021-02-02) - -### [1.1.1-beta.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.1.0...node-v1.1.1-beta.0) (2020-12-04) - -# [1.1.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.0.1...node-v1.1.0) (2020-06-23) - - - -## [1.0.1](https://github.com/mongodb/libmongocrypt/compare/node-v1.0.0...1.0.1) (2019-12-31) - - - -# [1.0.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.0.0-rc3.0...1.0.0) (2019-12-10) - - - -# [1.0.0-rc3.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.0.0-rc2.0...1.0.0-rc3.0) (2019-12-04) - - - -# [1.0.0-rc2.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.0.0-rc1.0...1.0.0-rc2.0) (2019-12-04) - - - -# [1.0.0-rc1.0](https://github.com/mongodb/libmongocrypt/compare/node-v1.0.0-rc0...1.0.0-rc1.0) (2019-12-04) diff --git a/HISTORY.md b/HISTORY.md new file mode 100644 index 0000000..0c23a3f --- /dev/null +++ b/HISTORY.md @@ -0,0 +1,359 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [6.0.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v6.0.0-alpha.3...v6.0.0) (2023-08-28) + +* 86bd61e docs: Update Node bindings README.md +* c91c8c6 docs(NODE-5527): add nodejs driver compat table (#687) +* 1edf123 docs(NODE-5425): update Node bindings docs (#685) +* c7dd6a5 chore(NODE-5448): update mongodb-client-encryption dependencies (#684) + +## [6.0.0-alpha.3](https://github.com/mongodb-js/mongodb-client-encryption/compare/v6.0.0-alpha.2...v6.0.0-alpha.3) (2023-08-09) + +* f058acd fix(NODE-5516): allow `undefined` values for optional Uint8Arrays arguments (#683) + +## [6.0.0-alpha.2](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.9.0...v6.0.0-alpha.2) (2023-08-07) + +* 9f19923 refactor(NODE-5432): Remove usages of Buffer from Node C++ bindings (#682) +* 6b95301 chore: type definition improvements for driver internal usage (#675) +* 593ff24 feat(NODE-5420)!: remove JS bindings from libmongocrypt (#667) +* 57531ba feat(NODE-5417)!: bump minimum Node.js version to v16.20.1 (#670) + +## [2.9.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.8.0...v2.9.0) (2023-07-12) + +* 342e908 feat(NODE-5431): add node bindings v6 deprecations (#666) +* 34f0ed4 ci(NODE-5331): install npm to node_artifacts directory (#656) +* 5811eba test(NODE-5268): use node 20 in ci (#650) + +## [2.8.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.8.0-alpha.0...v2.8.0) (2023-05-11) + +* 51c300f docs(NODE-5264): mark QE equality stable (#647) +* bc4b7bc docs(NODE-5261): update readme to mention cryptSharedLibPath and cryptSharedLibRequired (#643) +* e6b5be5 chore(NODE-5257): update dependencies (#639) +* 5a5ee03 test(NODE-5238): set min/max range options when required. (#636) +* afb6dc7 fix(NODE-4896): do not pass explicit session into state machine helpers (#632) +* cacbf64 MONGOCRYPT-561 enable QEv2 protocol by default (#621) +* bad374f chore(NODE-5123): fix node docs generation (#620) +* 5f8265d test(NODE-5179): remove ctr cipher tests (#611) +* 84f252e fix(NODE-5172): direct link to python 3.9 for prebuild (#609) +* c90645a fix(NODE-5172): update node-gyp (#608) +* 80ba303 test(NODE-5168): fix flaky stubbed key material test (#607) + +## [2.8.0-alpha.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.7.1...v2.8.0-alpha.0) (2023-04-04) + +* 20b4117 feat(NODE-5074): enable queryable encryption v2 (#606) +* 0efe671 ci(NODE-5131): remove npm install in node download script (#602) + +### [2.7.1](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.7.0...v2.7.1) (2023-03-20) + +* Same as `2.7.0` + +## [2.7.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.7.0-alpha.0...v2.7.0) (2023-03-20) + +* 16a52e7 docs(NODE-5094): fix docs for azure kms credential refresh (#596) +* edc8bf8 ci(NODE-5088): download node to local directory (#585) + +## [2.7.0-alpha.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.6.0...v2.7.0-alpha.0) (2023-03-14) + +* 91bb63b feat(NODE-5076): add support for Azure KMS credential auto refresh (#583) + +## [2.6.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.6.0-alpha.0...v2.6.0) (2023-02-23) + +* Same as `2.6.0-alpha.0` + +## [2.6.0-alpha.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.5.0...v2.6.0-alpha.0) (2023-02-16) + +* 860f6a3 feat(NODE-5066): add automatic credential usage to TS definitions (#576) +* a90a524 feat(NODE-5049): add support for kms gcp service accounts (#574) +* 15bd8d5 feat(NODE-4619): add KMS `accessToken` to TS definitions (#459) +* 43e98b7 fix(NODE-5053): enforce empty map for kmsProvider auto credentials (#565) + +## [2.5.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.4.0...v2.5.0) (2023-02-06) + +* 7f472ea chore: Bump http-cache-semantics from 4.1.0 to 4.1.1 in /bindings/node (#559) +* e748da9 fix(NODE-5041): replace `rangeOpts` with `rangeOptions` in Typescript definitions (#557) +* 72ae47d feat(NODE-5013): automatically create Queryable Encryption keys (#552) +* 9a2ad11 fix(NODE-5023): use correct options type for encryptExpression (#555) +* 6282a15 [MONGOCRYPT-521] LTO Build Fixes (#551) + +## [2.4.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.4.0-alpha.2...v2.4.0) (2023-01-26) + +* c5516c4 test(NODE-4897): bump release test timeout (#540) +* 04e06f3 fix(NODE-5000): make aws credential providers peer optional (#546) + +## [2.4.0-alpha.2](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.4.0-alpha.0...v2.4.0-alpha.2) (2023-01-24) + +* c117879 fix(NODE-4997): no strncasecmp on windows (#545) +* 764b899 chore(release): 2.4.0-alpha.1 +* 3014b1c feat(NODE-4694): support range indexes (#533) +* 11ed3c9 test(NODE-4993): migrate create a data key test to promise usage (#539) + +## [2.4.0-alpha.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.3.0...v2.4.0-alpha.0) (2023-01-20) + +* 031bbfa fix(NODE-4987): node csfle uses promises instead of callbacks (#537) +* ebcb768 [MONGOCRYPT-483]: Support Decimal128 in range-based Queryable Encryption (#522) +* 3c4aa8b fix(NODE-4880): specify family of ipv4 when connecting to default mongocryptd uri (#516) +* 37e1d12 ci(NODE-4666): pin to node18 instead of latest (#513) +* a154554 chore: Bump minimatch from 3.0.4 to 3.1.2 in /bindings/node (#491) +* d177281 (NODE-4779): Pin to an earlier Node LTS release on platforms that are not supported by prebuilt Node 18+ (#488) +* f70a0cf feat(NODE-4234): add aws credentials provider (#479) +* ba258a0 docs(NODE-4725): Change docs to use "in use encryption" terminology (#476) + +## [2.3.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.1...v2.3.0) (2022-10-05) + +* 7dc561c feat(NODE-4328): expose libmongocrypt version in bindings (#464) + +### [2.2.1](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0...v2.2.1) (2022-09-12) + +* 91b2bc4 fix(NODE-4556): attempt to use exported BSON (#443) + +## [2.2.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0-alpha.6...v2.2.0) (2022-08-10) + +* 6533b82 feat(NODE-4517): add official support for the key management API (#439) + +## [2.2.0-alpha.6](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0-alpha.5...v2.2.0-alpha.6) (2022-07-29) + +* d574606 chore: revert change to uri in node binding tests (#424) + +## [2.2.0-alpha.5](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0-alpha.4...v2.2.0-alpha.5) (2022-07-20) + +* d574606 chore: revert change to uri in node binding tests (#424) +* aabd8eb feat(NODE-4394): add key management API to node bindings (#414) +* ce5b1af test(NODE-4389): fix rewrap many data key test hang (#403) +* 85f64cd Revert "Node bindings should re-use top-level find-cmake.sh (#395)" (#401) +* decc2fb Node bindings should re-use top-level find-cmake.sh (#395) + +## [2.2.0-alpha.4](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0-alpha.3...v2.2.0-alpha.4) (2022-07-06) + +* adbbd6b test(NODE-4343): fix remaining spec tests (#399) +* ace6da6 test(NODE-4343): contention factor required with indexed (#397) +* 40ee992 chore(NODE-4372): bump prebuild install to 7.1.1 (#394) +* a56a784 fix(NODE-4339): remove indexKeyId (#387) +* 1b1b699 fix(NODE-4260): mongocrypterror has name getter (#383) +* 21ef15d fix(NODE-4342): remove createKey() in favor of createDataKey() (#390) +* 7d13004 fix(NODE-4356): update rewrapManyDataKey to use UpdateOne bulk ops (#389) +* 006be71 feat(NODE-4294): mark queryable encryption options beta (#380) + +## [2.2.0-alpha.3](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0-alpha.2...v2.2.0-alpha.3) (2022-06-23) + +* 3b9bbbf Use mongo-c-driver as a subdirectory for obtaining libbson (#365) +* 4c43c23 chore(NODE-4304): accept string value for queryType (#373) +* b0f94db [MONGOCRYPT-441] Accept string arguments for queryType and "index_type" (#368) + +## [2.2.0-alpha.2](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0-alpha.1...v2.2.0-alpha.2) (2022-06-10) + +* 30de861 fix(NODE-4251): fix markCommand deserialization (#364) + +## [2.2.0-alpha.1](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.2.0-alpha.0...v2.2.0-alpha.1) (2022-06-01) + +* 50fba9e fix: add missing import in Node.js bindings TS definitions (#353) +* f2c401b fix(NODE-4279): handle decrypted nested documents well with devtools decoration (#350) +* 3fbd57d [MONGOCRYPT-434] Rename "csfle" to "crypt_shared" (#352) +* 8a07c72 test(NODE-4254): use majority write concern (#348) +* 5b13ce2 test(NODE-4254): use majority write concern (#347) +* d1c222f chore(NODE-4236): use latest node driver (#345) +* 8105956 fix(NODE-4254): allow csfle to be dynamically required (#342) +* 0e8749a feat(NODE-4241): add support for rewrapManyDataKey and keyMaterial (#334) +* 2e8903f fix(NODE-4242): do not run mongocryptd if bypassQueryAnalysis (#335) +* 006f326 feat(NODE-4220): add FLE2 explicit encryption API (#327) + +## [2.2.0-alpha.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.1.0...v2.2.0-alpha.0) (2022-05-04) + +* 26471cc feat(NODE-4218): add aes256-ctr support (#324) +* bae60ca test: loosen test error assertion for fails to autospawn (#310) + +## [2.1.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.0.0...v2.1.0) (2022-04-21) + +* 7c1ce27 feat(NODE-4136): adjust Node.js bindings for shared library spec (#306) +* 4da6a64 chore: Bump minimist from 1.2.5 to 1.2.6 in /bindings/node (#278) +* 08d7f73 feat(NODE-4085): add Node.js csfle shared library option support (#265) +* 6e6c6f5 feat(NODE-3978): allow identifying decrypted fields for internal usage/testing (#266) +* 2bb42fd MONGOCRYPT-391 add 32 bit Windows build variant (#262) +* 4d707f0 Compile Warnings-as-errors Cleanup (#256) +* 171cf2e MONGOCRYPT-382 require `aws: {}` to enter NEED_KMS_CREDENTIALS (#257) +* ad2af98 MONGOCRYPT-382 Add support for providing per-KMS-request credentials (#252) + +## [2.0.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.0.0-beta.4...v2.0.0) (2022-02-17) + +* e2d09dd Fix Capitalize for ClientEncryptionTlsOptions (#244) + +## [2.0.0-beta.4](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.0.0-beta.3...v2.0.0-beta.4) (2022-02-09) + +* fd5331d feat: build and test node on m1 NODE-3631 (#245) +* d4fb3a1 test: fix incorrect done usage in beforeEach hook (#242) +* 08b5adf chore(NODE-3849)!: update dependencies and sync tooling (#241) +* b6c651e docs(NODE-3926): allow either Buffer or Binary in decrypt (#239) + +## [2.0.0-beta.3](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.0.0-beta.0...v2.0.0-beta.3) (2022-01-31) + +* 3b2d83d Revert and move only warnings-as-error flags into scripts (#237) +* 99b8461 Move CMAKE_C_FLAGS from CMakeLists.txt into Evergreen build scripts (#224) +* b886970 fix(NODE-3777): destroy socket on end (#236) +* bca4a84 feat(NODE-3777): set tls options per kms provider (#235) +* 8a173b2 MONGOCRYPT-340 add macOS m1 variant (#234) + +## [2.0.0-beta.2](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.0.0-beta.0...v2.0.0-beta.2) (2021-12-22) + +* 4e2c818 MONGOCRYPT-362 build and publish packages on Amazon Linux 2 arm64 (#233) + +## [2.0.0-beta.1](https://github.com/mongodb-js/mongodb-client-encryption/compare/v2.0.0-beta.0...v2.0.0-beta.1) (2021-12-21) + +* afa1838 fix(NODE-3633): properly forward proxyOptions to StateMachine (#230) +* d922e23 chore(NODE-3633): update Socks5 support for driver PR feedback (#227) +* 7e4280b test: increase encrypter test timeout (#226) +* 5816a19 feat(NODE-3633): add Socks5 support (#220) +* e049059 feat(NODE-3177): allow serverSelectionTimeoutMS to client (#225) +* 68adc88 feat(NODE-3781): add tls options for kms providers (#222) +* 0e3571f feat(NODE-3777): add node bindings for kms provider (#221) + +## [2.0.0-beta.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.7...v2.0.0-beta.0) (2021-10-07) + +* 17ed59b chore(NODE-3632): limit CI publishing to one version of x64 linux (#201) +* 3886dca fix(NODE-3605): bypassAutoEncryption should not spawn mongocryptd (#204) +* e89da23 feat!(NODE-3474): convert to Node-API (#193) + +### [1.2.7](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.6...v1.2.7) (2021-09-14) + +* fc67ea2 chore(NODE-3316): update author info and add bug url in package.json (#180) + +### [1.2.6](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.5...v1.2.6) (2021-07-01) + +* c3aa733 fix(NODE-3118): keyAltNames option not serialized (#176) + +### [1.2.5](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.4...v1.2.5) (2021-06-10) + +* e75d2ed fix(NODE-3350): do not export Init and helper function symbols (#177) +* ba102c0 fix(NODE-3326): binding.gyp missing from files list in package.json (#175) + +### [1.2.4](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.3...v1.2.4) (2021-06-01) + +* 7ad0c9a fix(NODE-3320): Explicitly provide list of artifacts to be published with package.files (#174) +* 05905d4 chore: update prebuild-install to latest (#171) + +### [1.2.3](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.2...v1.2.3) (2021-04-06) + +* 8e6092b fix(NODE-2995): add metadata client usage (#168) + +### [1.2.2](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.1...v1.2.2) (2021-03-16) + +* e923c17 fix: clean up memory leaks related to mongocrypt_binary_t (#166) +* 7454f03 fix: loosen peerDependencies requirement on mongodb (#161) +* 0b4bf75 chore: add AWS sessionToken TypeScript definitions (#160) + +### [1.2.1](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.2.0...v1.2.1) (2021-02-05) + +* c571e46 fix: always authorize TLS endpoints, use servername for SNI (#159) + +## [1.2.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.1.0...v1.2.0) (2021-02-02) + +* 058bdcc chore: bump ini from 1.3.5 to 1.3.8 in /bindings/node (#148) +* 788056f chore(node-binding): Add TypeScript definitions (#154) +* 6949cdd fix: copy output buffers to libmongocrypt in Node.js bindings (#149) + +### [1.1.1-beta.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.1.0...v1.1.1-beta.0) (2020-12-04) + +* 826a3d9 feat: support Azure and GCP KMS providers (#139) +* c5c7e60 chore: bump bl from 1.2.2 to 1.2.3 in /bindings/node (#128) +* 2f92ce7 chore: bump standard-version from 5.0.2 to 8.0.1 +* 08c014c chore: bump lodash from 4.17.15 to 4.17.19 +* bfeb0d5 chore: add script for prebuilding for legacy versions of node + +# [1.1.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.0.1...v1.1.0) (2020-06-23) + +* 7c07e2f fix: correct typo preventing passing a custom mongocrypt spawn path +* 5677758 chore: use node 14 to build prebuild images +* a6ecfa4 chore: update bson dev dependency to 4.x +* a65d23d chore: update version of node used to build binding to erbium +* cdde669 chore: pin prebuild-install to 5.3.0 +* 86d687f chore: don't install mongocryptd for CI test runs + +## [1.0.1](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.0.0...v1.0.1) (2019-12-31) + +* c1f1aa3 chore: update peer dependency & repository location in package.json +* fa5c6e7 feat: support `bypassAutoEncryption` directly in AutoEncrypter +* e044dc7 refactor: support explicitly set BSON module +* f974c2b fix typo in node bindings (#85) + +# [1.0.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.0.0-rc3.0...v1.0.0) (2019-12-10) + +* Same as `1.0.0-rc3.0` + +# [1.0.0-rc3.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.0.0-rc2.0...v1.0.0-rc3.0) (2019-12-04) + +* efda0f2 chore: ensure prebuild revision check works on windows as well + +# [1.0.0-rc2.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v1.0.0-rc1.0...v1.0.0-rc2.0) (2019-12-04) + +* 604147d test: fix typo in client encryption tests + +# [1.0.0-rc1.0](https://github.com/mongodb-js/mongodb-client-encryption/compare/v0.3.1...v1.0.0-rc1.0) (2019-12-04) + +* 09465d0 chore: add `standard-version` for release management +* cf43523 test: ensure no clients are left open after test runs +* b8d5307 feat: add a useful error message if we can't connect to mongocryptd +* 3e4f575 fix: support two ways of specifying `--idleShutdownTimeoutSecs` + +# v1.0.0-rc0 + +* 1aea82b fix: ensure cflags are not mixed between windows and linux +* bbdc965 test: fix `find_cmake.sh` path in node's environment setup +* ca82e87 NODE-2338 support building addon for windows +* 3eafaa4 NODE-2339: change API to remove mandatory injection +* 863d4ee NODE-2315: make --idleShutdownTimeoutSecs work +* 3e48e40 NODE-2109: Follow spec for auto-spawning mongocryptd +* 5b9f6cd NODE: minor documentation fix +* 59d4665 NODE-2298: update documentation to synergize with driver docs (#71) +* 7a145d6 NODE-2255: add support for keyVaultClient +* e310e75 NODE: fix typo in mock endpoint +* 114b35c NODE-2255: Add API for specifying a custom endpoint with AWS masterkey provider +* 65ca4c0 NODE-2255: test that fetching keys uses readConcern=majority +* 13d8b11 NODE-2255: test that created data keys insert with majority writeConcern +* a58a0f1 NODE-2278: respect user bson options when using autoEncryption +* 5eedcc7 MONGOCRYPT-178 NODE-2159 refactor libbson build for better commonality +* a8cb8e3 MONGOCRYPT-87 consume new CMake targets exported by C driver + +# v0.3.1 + +* e60f3ef NODE: incorporate documentation feedback +* d07b509 NODE: docs: document the public API of the node bindings +* 3f00866 NODE: test(cryptoHooks): test error handling of random hooks +* b0b3255 NODE: fix(cryptoHooks): propagate random hook error +* 2ea51d8 NODE: fix(crypyoHooks): make crypto hooks work in Node 4 +* 3f962b7 NODE: feat(node12): add node 12 and election support +* 5cc47c1 NODE: chore(osx): target node 10.12 +* 0e63dfa NODE: chore(osx): fix build on osx in evergreen +* d00d757 NODE: fix typo +* 1c2b5d6 NODE: format: minor formatting changes +* d8932a2 NODE: real v0.3.0 with proper prebuild-install command + +# v0.3.0 + +* e667e28 NODE: remove connecting on linux socket +* 7fbe80f NODE: fix node evergreen config +* a462f6f NODE: adds keyAltNames support +* 2ac2573 NODE: Adding prebuild support to evergreen +* ff57896 NODE: Adding node tests to evergreen +* 1bf8568 NODE: feat(cryptoCallbacks): pass crypto errors to libmongocrypt +* 55ae2a2 NODE: fix node build on osx for node 4 & 6 +* ba25da4 NODE-2072: provide infrastructure for statically linking the addon + +# v0.2.0 + +* 976116b feat: implement crypto hooks, pass them into `MongoCrypt` instances +* cf5ccf6 feat: support passing crypto callbacks to `MongoCrypt` constructor +* ef38445 test(client-encryption): drop collection before each test run +* 77ca484 NODE: handle auto-spawning mongocryptd in node bindings + +# v0.1.3 + +* 943cad3 NODE: Add tools to generate documentation in README +* 0b6be62 NODE: rely on request.bytesNeeded for ending kms requests +* 4fd9e78 test(autoEncrypter): fix incorrect cyphertext +* a67fddd refactor(encryption-options): remove initialization vector +* 98da3ae CDRIVER-3199 fix key offset +* b112463 chore: update npmignore to not publish build artifacts +* aa0b189 chore: include missing header in binding header +* 4e9924c chore: add npm ignore for publishing +* 595d995 refactor: support returning promises in `ClientEncryption` +* 72d2ba8 NODE-1854: add node bindings for client side encryption (#19) diff --git a/etc/build-static.sh b/etc/build-static.sh deleted file mode 100755 index 39ed649..0000000 --- a/etc/build-static.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit - -THIS_DIR="$(dirname "${BASH_SOURCE[0]}")" -. "$THIS_DIR/../../../.evergreen/init.sh" - -NODE_DIR="$(abspath "$THIS_DIR/..")" - -DEPS_PREFIX="$NODE_DIR/deps" -BUILD_DIR=$DEPS_PREFIX/tmp -: "${CMAKE_FLAGS:=}" -: "${WINDOWS_CMAKE_FLAGS:=}" - -# build and install libmongocrypt -mkdir -p $BUILD_DIR/libmongocrypt-build -pushd $BUILD_DIR/libmongocrypt-build #./deps/tmp/libmongocrypt-build - -CMAKE_FLAGS="-DDISABLE_NATIVE_CRYPTO=1 -DCMAKE_INSTALL_LIBDIR=lib -DENABLE_MORE_WARNINGS_AS_ERRORS=ON" -if [ "$OS_NAME" == "windows" ]; then - if [ "${WINDOWS_32BIT-}" != "ON" ]; then - WINDOWS_CMAKE_FLAGS="-Thost=x64 -A x64 -DENABLE_WINDOWS_STATIC_RUNTIME=ON" - else - WINDOWS_CMAKE_FLAGS="-DENABLE_WINDOWS_STATIC_RUNTIME=ON" - fi - run_cmake $CMAKE_FLAGS $WINDOWS_CMAKE_FLAGS -DCMAKE_PREFIX_PATH="$(native_path "$DEPS_PREFIX")" -DCMAKE_INSTALL_PREFIX="$(native_path "$DEPS_PREFIX")" "$(native_path "$LIBMONGOCRYPT_DIR")" -else - run_cmake $CMAKE_FLAGS -DCMAKE_PREFIX_PATH=$DEPS_PREFIX -DCMAKE_INSTALL_PREFIX=$DEPS_PREFIX -DCMAKE_OSX_DEPLOYMENT_TARGET="10.12" $LIBMONGOCRYPT_DIR -fi - -run_cmake --build . --target install --config RelWithDebInfo - -popd #./ - -# build the `mongodb-client-encryption` addon -# `npm install` will install a pre-built binary by default (because we use prebuild-install). -# instead, we want to build the addon from scratch. so we install with `--ignore-scripts` -# and then run the `rebuild` script to compile our bindings. -npm install --ignore-scripts -npm run rebuild diff --git a/etc/libmongocrypt.mjs b/etc/libmongocrypt.mjs new file mode 100644 index 0000000..ade8d0b --- /dev/null +++ b/etc/libmongocrypt.mjs @@ -0,0 +1,116 @@ +/* eslint-disable no-console */ +import util from 'node:util'; +import process from 'node:process'; +import fs from 'node:fs/promises'; +import child_process from 'node:child_process'; +import events from 'node:events'; +import path from 'node:path'; + +async function parseArguments() { + const libmongocryptVersion = ( + await import('../package.json', { + [process.version.split('.').at(0) === 'v16' ? 'assert' : 'with']: { type: 'json' } + }) + ).default['mongodb:libmongocrypt']; + + const options = { + url: { short: 'u', type: 'string', default: 'https://github.com/mongodb/libmongocrypt.git' }, + libversion: { short: 'l', type: 'string', default: libmongocryptVersion }, + help: { short: 'h', type: 'boolean' } + }; + + const args = util.parseArgs({ + args: process.argv.slice(2), + options, + allowPositionals: false + }); + + if (args.values.help) { + console.log( + `${process.argv[1]} ${[...Object.keys(options)] + .filter(k => k !== 'help') + .map(k => `[--${k}=${options[k].type}]`) + .join(' ')}` + ); + process.exit(0); + } + + return { libmongocrypt: { url: args.values.url, ref: args.values.libversion } }; +} + +const args = await parseArguments(); + +console.error('fetching libmongocrypt...\n', args); + +async function run(command, args = [], options = {}) { + console.error(`+ ${command} ${args.join(' ')}`, options.cwd ? `(in: ${options.cwd})` : ''); + await events.once(child_process.spawn(command, args, { stdio: 'inherit', ...options }), 'exit'); +} + +await fs.rm('_libmongocrypt', { recursive: true, force: true }); + +await run('git', ['clone', args.libmongocrypt.url, '_libmongocrypt']); + +await run('git', ['fetch', '--tags'], { cwd: '_libmongocrypt' }); + +await run('git', ['checkout', args.libmongocrypt.ref, '-b', `r-${args.libmongocrypt.ref}`], { + cwd: '_libmongocrypt' +}); + +console.error('building libmongocrypt...\n', args); + +const libmongocryptRoot = path.resolve('_libmongocrypt'); +const nodeDepsRoot = path.resolve('deps'); +const nodeBuildRoot = path.resolve(nodeDepsRoot, 'tmp', 'libmongocrypt-build'); + +await fs.rm(nodeBuildRoot, { recursive: true, force: true }); +await fs.mkdir(nodeBuildRoot, { recursive: true }); + +/** + * Given an object returns CLI flags: + * ``` + * toFlags({a: 1, b: 2}) + * // "-a=1 -b=2" + * ``` + */ +function toFlags(object) { + return Array.from(Object.entries(object)).map(([k, v]) => `-${k}=${v}`); +} + +const CMAKE_FLAGS = toFlags({ + /** We provide crypto hooks from Node.js binding to openssl (so disable system crypto) */ + DDISABLE_NATIVE_CRYPTO: '1', + /** A consistent name for the output "library" directory */ + DCMAKE_INSTALL_LIBDIR: 'lib', + /** No warnings allowed */ + DENABLE_MORE_WARNINGS_AS_ERRORS: 'ON', + /** Where to build libmongocrypt */ + DCMAKE_PREFIX_PATH: nodeDepsRoot, + /** + * Where to install libmongocrypt + * Note that `binding.gyp` will set `./deps/include` + * as an include path if BUILD_TYPE=static + */ + DCMAKE_INSTALL_PREFIX: nodeDepsRoot +}); + +const WINDOWS_CMAKE_FLAGS = + process.platform === 'win32' + ? toFlags({ Thost: 'x64', A: 'x64', DENABLE_WINDOWS_STATIC_RUNTIME: 'ON' }) + : []; + +const MACOS_CMAKE_FLAGS = + process.platform === 'darwin' ? toFlags({ DCMAKE_OSX_DEPLOYMENT_TARGET: '10.12' }) : []; + +await run( + 'cmake', + [...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...MACOS_CMAKE_FLAGS, libmongocryptRoot], + { cwd: nodeBuildRoot } +); + +await run('cmake', ['--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'], { + cwd: nodeBuildRoot +}); + +await run('npm', ['install', '--ignore-scripts']); +await run('npm', ['run', 'rebuild'], { env: { ...process.env, BUILD_TYPE: 'static' } }); diff --git a/package.json b/package.json index 0483409..0049034 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "types": "lib/index.d.ts", "files": [ "README.md", - "CHANGELOG.md", + "HISTORY.md", "addon", "lib", "src", @@ -16,7 +16,7 @@ "lib": "lib" }, "scripts": { - "install": "prebuild-install --runtime napi --tag-prefix node-v || node-gyp rebuild", + "install": "prebuild-install --runtime napi || node-gyp rebuild", "build:ts": "tsc", "clang-format": "clang-format --style=file:.clang-format --Werror -i addon/*", "check:eslint": "eslint src test", @@ -24,8 +24,7 @@ "test": "mocha test", "prepare": "node etc/prepare.js", "rebuild": "prebuild --compile", - "release": "standard-version --tag-prefix node-v --path bindings/node", - "prebuild": "prebuild --runtime napi --strip --verbose --tag-prefix node-v --all" + "prebuild": "prebuild --runtime napi --strip --verbose --all" }, "author": { "name": "The MongoDB NodeJS Team", @@ -36,6 +35,7 @@ }, "license": "Apache-2.0", "gypfile": true, + "mongodb:libmongocrypt": "1.10.0", "dependencies": { "bindings": "^1.5.0", "node-addon-api": "^4.3.0", @@ -82,8 +82,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/mongodb/libmongocrypt", - "directory": "bindings/node" + "url": "https://github.com/mongodb-js/mongodb-client-encryption" }, "tsd": { "directory": "test/types", diff --git a/test/release.test.ts b/test/release.test.ts index 2c96203..11e1250 100644 --- a/test/release.test.ts +++ b/test/release.test.ts @@ -15,7 +15,7 @@ const REQUIRED_FILES = [ 'package/package.json', 'package/lib/index.d.ts.map', 'package/lib/index.js.map', - 'package/CHANGELOG.md', + 'package/HISTORY.md', 'package/README.md', 'package/lib/index.d.ts', 'package/src/index.ts' From 0f434a6c5d3c99ae6cb2908fa5952f5f67134ac5 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 09:22:15 -0400 Subject: [PATCH 2/9] chore: add PR template --- .github/pull_request_template.md | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..e196cba --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,34 @@ +### Description + +#### What is changing? + +##### Is there new documentation needed for these changes? + +#### What is the motivation for this change? + + + + + + +### Release Highlight + + + +### Fill in title or leave empty for no highlight + + + +### Double check the following + +- [ ] Ran `npm run check:lint` script +- [ ] Self-review completed using the [steps outlined here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/CONTRIBUTING.md#reviewer-guidelines) +- [ ] PR title follows the [correct format](https://www.conventionalcommits.org/en/v1.0.0/): `type(NODE-xxxx)[!]: description` + - Example: `feat(NODE-1234)!: rewriting everything in coffeescript` +- [ ] Changes are covered by tests +- [ ] New TODOs have a related JIRA ticket From 20c5672563035d315fa2e377ee04d4b4c47d24f8 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 09:51:56 -0400 Subject: [PATCH 3/9] chore: make script detect if steps need re-running --- addon/mongocrypt.cc | 4 +- etc/libmongocrypt.mjs | 134 ++++++++++++++++++++++++------------------ etc/prepare.js | 12 ---- package.json | 3 +- 4 files changed, 79 insertions(+), 74 deletions(-) delete mode 100644 etc/prepare.js diff --git a/addon/mongocrypt.cc b/addon/mongocrypt.cc index d1e036d..54ac834 100644 --- a/addon/mongocrypt.cc +++ b/addon/mongocrypt.cc @@ -11,7 +11,7 @@ namespace node_mongocrypt { using namespace Napi; -// anonymous namepace for helpers +// anonymous namespace for helpers namespace { struct InstanceData { Reference MongoCryptContextCtor; @@ -751,7 +751,7 @@ Value MongoCrypt::MakeRewrapManyDataKeyContext(const CallbackInfo& info) { Function MongoCrypt::GetCallback(const char* name) { Napi::Value storage = Value().Get("__callbackStorage"); if (!storage.IsObject()) { - throw Error::New(Env(), "Cannot get callbacks becauses none were registered"); + throw Error::New(Env(), "Cannot get callbacks because none were registered"); } Napi::Value entry = storage.As().Get(name); if (!entry.IsFunction()) { diff --git a/etc/libmongocrypt.mjs b/etc/libmongocrypt.mjs index ade8d0b..e5855c0 100644 --- a/etc/libmongocrypt.mjs +++ b/etc/libmongocrypt.mjs @@ -16,6 +16,7 @@ async function parseArguments() { const options = { url: { short: 'u', type: 'string', default: 'https://github.com/mongodb/libmongocrypt.git' }, libversion: { short: 'l', type: 'string', default: libmongocryptVersion }, + clean: { short: 'c', type: 'boolean' }, help: { short: 'h', type: 'boolean' } }; @@ -35,37 +36,17 @@ async function parseArguments() { process.exit(0); } - return { libmongocrypt: { url: args.values.url, ref: args.values.libversion } }; + return { + libmongocrypt: { url: args.values.url, ref: args.values.libversion }, + clean: args.values.clean + }; } -const args = await parseArguments(); - -console.error('fetching libmongocrypt...\n', args); - async function run(command, args = [], options = {}) { console.error(`+ ${command} ${args.join(' ')}`, options.cwd ? `(in: ${options.cwd})` : ''); await events.once(child_process.spawn(command, args, { stdio: 'inherit', ...options }), 'exit'); } -await fs.rm('_libmongocrypt', { recursive: true, force: true }); - -await run('git', ['clone', args.libmongocrypt.url, '_libmongocrypt']); - -await run('git', ['fetch', '--tags'], { cwd: '_libmongocrypt' }); - -await run('git', ['checkout', args.libmongocrypt.ref, '-b', `r-${args.libmongocrypt.ref}`], { - cwd: '_libmongocrypt' -}); - -console.error('building libmongocrypt...\n', args); - -const libmongocryptRoot = path.resolve('_libmongocrypt'); -const nodeDepsRoot = path.resolve('deps'); -const nodeBuildRoot = path.resolve(nodeDepsRoot, 'tmp', 'libmongocrypt-build'); - -await fs.rm(nodeBuildRoot, { recursive: true, force: true }); -await fs.mkdir(nodeBuildRoot, { recursive: true }); - /** * Given an object returns CLI flags: * ``` @@ -77,40 +58,77 @@ function toFlags(object) { return Array.from(Object.entries(object)).map(([k, v]) => `-${k}=${v}`); } -const CMAKE_FLAGS = toFlags({ - /** We provide crypto hooks from Node.js binding to openssl (so disable system crypto) */ - DDISABLE_NATIVE_CRYPTO: '1', - /** A consistent name for the output "library" directory */ - DCMAKE_INSTALL_LIBDIR: 'lib', - /** No warnings allowed */ - DENABLE_MORE_WARNINGS_AS_ERRORS: 'ON', - /** Where to build libmongocrypt */ - DCMAKE_PREFIX_PATH: nodeDepsRoot, - /** - * Where to install libmongocrypt - * Note that `binding.gyp` will set `./deps/include` - * as an include path if BUILD_TYPE=static - */ - DCMAKE_INSTALL_PREFIX: nodeDepsRoot -}); - -const WINDOWS_CMAKE_FLAGS = - process.platform === 'win32' - ? toFlags({ Thost: 'x64', A: 'x64', DENABLE_WINDOWS_STATIC_RUNTIME: 'ON' }) - : []; - -const MACOS_CMAKE_FLAGS = - process.platform === 'darwin' ? toFlags({ DCMAKE_OSX_DEPLOYMENT_TARGET: '10.12' }) : []; - -await run( - 'cmake', - [...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...MACOS_CMAKE_FLAGS, libmongocryptRoot], - { cwd: nodeBuildRoot } -); - -await run('cmake', ['--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'], { - cwd: nodeBuildRoot -}); +const args = await parseArguments(); +const libmongocryptRoot = path.resolve('_libmongocrypt'); + +const libmongocryptAlreadyClonedAndCheckedOut = ( + await fs.readFile(path.join(libmongocryptRoot, '.git', 'HEAD'), 'utf8') +) + .trim() + .endsWith('r-1.10.0'); + +if (!args.clean && !libmongocryptAlreadyClonedAndCheckedOut) { + console.error('fetching libmongocrypt...', args.libmongocrypt); + await fs.rm(libmongocryptRoot, { recursive: true, force: true }); + await run('git', ['clone', args.libmongocrypt.url, libmongocryptRoot]); + await run('git', ['fetch', '--tags'], { cwd: libmongocryptRoot }); + await run('git', ['checkout', args.libmongocrypt.ref, '-b', `r-${args.libmongocrypt.ref}`], { + cwd: libmongocryptRoot + }); +} else { + console.error('libmongocrypt already up to date...', args.libmongocrypt); +} + +const libmongocryptAlreadyBuilt = + (await fs.readFile(path.join(libmongocryptRoot, 'VERSION_CURRENT'), 'utf8')).trim() === + args.libmongocrypt.ref; + +if (!args.clean && !libmongocryptAlreadyBuilt) { + console.error('building libmongocrypt...\n', args); + + const nodeDepsRoot = path.resolve('deps'); + const nodeBuildRoot = path.resolve(nodeDepsRoot, 'tmp', 'libmongocrypt-build'); + + await fs.rm(nodeBuildRoot, { recursive: true, force: true }); + await fs.mkdir(nodeBuildRoot, { recursive: true }); + + const CMAKE_FLAGS = toFlags({ + /** We provide crypto hooks from Node.js binding to openssl (so disable system crypto) */ + DDISABLE_NATIVE_CRYPTO: '1', + /** A consistent name for the output "library" directory */ + DCMAKE_INSTALL_LIBDIR: 'lib', + /** No warnings allowed */ + DENABLE_MORE_WARNINGS_AS_ERRORS: 'ON', + /** Where to build libmongocrypt */ + DCMAKE_PREFIX_PATH: nodeDepsRoot, + /** + * Where to install libmongocrypt + * Note that `binding.gyp` will set `./deps/include` + * as an include path if BUILD_TYPE=static + */ + DCMAKE_INSTALL_PREFIX: nodeDepsRoot + }); + + const WINDOWS_CMAKE_FLAGS = + process.platform === 'win32' + ? toFlags({ Thost: 'x64', A: 'x64', DENABLE_WINDOWS_STATIC_RUNTIME: 'ON' }) + : []; + + const MACOS_CMAKE_FLAGS = + process.platform === 'darwin' ? toFlags({ DCMAKE_OSX_DEPLOYMENT_TARGET: '10.12' }) : []; + + await run( + 'cmake', + [...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...MACOS_CMAKE_FLAGS, libmongocryptRoot], + { cwd: nodeBuildRoot } + ); + + await run('cmake', ['--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'], { + cwd: nodeBuildRoot + }); +} else { + console.error('libmongocrypt already built...'); +} await run('npm', ['install', '--ignore-scripts']); await run('npm', ['run', 'rebuild'], { env: { ...process.env, BUILD_TYPE: 'static' } }); diff --git a/etc/prepare.js b/etc/prepare.js deleted file mode 100644 index a491937..0000000 --- a/etc/prepare.js +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env node -var cp = require('child_process'); -var fs = require('fs'); -var os = require('os'); - -if (fs.existsSync('src')) { - cp.spawn('npm', ['run', 'build:ts'], { stdio: 'inherit', shell: os.platform() === 'win32' }); -} else { - if (!fs.existsSync('lib')) { - console.warn('MongoDB: No compiled javascript present, the driver is not installed correctly.'); - } -} diff --git a/package.json b/package.json index 0049034..76a75cd 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,11 @@ }, "scripts": { "install": "prebuild-install --runtime napi || node-gyp rebuild", - "build:ts": "tsc", "clang-format": "clang-format --style=file:.clang-format --Werror -i addon/*", "check:eslint": "eslint src test", "check:clang-format": "clang-format --style=file:.clang-format --dry-run --Werror addon/*", "test": "mocha test", - "prepare": "node etc/prepare.js", + "prepare": "tsc", "rebuild": "prebuild --compile", "prebuild": "prebuild --runtime napi --strip --verbose --all" }, From be11337de862b3e8e5a23ee85e1ae81712755025 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 09:53:19 -0400 Subject: [PATCH 4/9] chore: move script to CI folder --- {etc => .github/scripts}/libmongocrypt.mjs | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {etc => .github/scripts}/libmongocrypt.mjs (100%) diff --git a/etc/libmongocrypt.mjs b/.github/scripts/libmongocrypt.mjs similarity index 100% rename from etc/libmongocrypt.mjs rename to .github/scripts/libmongocrypt.mjs From dad84a407ebfe49ec6882b64065bffcfd3ba0f3b Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 10:02:18 -0400 Subject: [PATCH 5/9] fix: hardcoded values --- .github/scripts/libmongocrypt.mjs | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/.github/scripts/libmongocrypt.mjs b/.github/scripts/libmongocrypt.mjs index e5855c0..0de572f 100644 --- a/.github/scripts/libmongocrypt.mjs +++ b/.github/scripts/libmongocrypt.mjs @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import util from 'node:util'; import process from 'node:process'; import fs from 'node:fs/promises'; @@ -7,11 +6,9 @@ import events from 'node:events'; import path from 'node:path'; async function parseArguments() { - const libmongocryptVersion = ( - await import('../package.json', { - [process.version.split('.').at(0) === 'v16' ? 'assert' : 'with']: { type: 'json' } - }) - ).default['mongodb:libmongocrypt']; + const jsonImport = { [process.version.split('.').at(0) === 'v16' ? 'assert' : 'with']: { type: 'json' } }; + const pkg = (await import('../../package.json', jsonImport)).default; + const libmongocryptVersion = pkg['mongodb:libmongocrypt']; const options = { url: { short: 'u', type: 'string', default: 'https://github.com/mongodb/libmongocrypt.git' }, @@ -61,20 +58,14 @@ function toFlags(object) { const args = await parseArguments(); const libmongocryptRoot = path.resolve('_libmongocrypt'); -const libmongocryptAlreadyClonedAndCheckedOut = ( - await fs.readFile(path.join(libmongocryptRoot, '.git', 'HEAD'), 'utf8') -) - .trim() - .endsWith('r-1.10.0'); +const libmongocryptAlreadyClonedAndCheckedOut = (await fs.readFile(path.join(libmongocryptRoot, '.git', 'HEAD'), 'utf8')).trim().endsWith(`r-${args.libmongocrypt.ref}`); if (!args.clean && !libmongocryptAlreadyClonedAndCheckedOut) { console.error('fetching libmongocrypt...', args.libmongocrypt); await fs.rm(libmongocryptRoot, { recursive: true, force: true }); await run('git', ['clone', args.libmongocrypt.url, libmongocryptRoot]); await run('git', ['fetch', '--tags'], { cwd: libmongocryptRoot }); - await run('git', ['checkout', args.libmongocrypt.ref, '-b', `r-${args.libmongocrypt.ref}`], { - cwd: libmongocryptRoot - }); + await run('git', ['checkout', args.libmongocrypt.ref, '-b', `r-${args.libmongocrypt.ref}`], { cwd: libmongocryptRoot }); } else { console.error('libmongocrypt already up to date...', args.libmongocrypt); } @@ -117,15 +108,8 @@ if (!args.clean && !libmongocryptAlreadyBuilt) { const MACOS_CMAKE_FLAGS = process.platform === 'darwin' ? toFlags({ DCMAKE_OSX_DEPLOYMENT_TARGET: '10.12' }) : []; - await run( - 'cmake', - [...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...MACOS_CMAKE_FLAGS, libmongocryptRoot], - { cwd: nodeBuildRoot } - ); - - await run('cmake', ['--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'], { - cwd: nodeBuildRoot - }); + await run('cmake', [...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...MACOS_CMAKE_FLAGS, libmongocryptRoot], { cwd: nodeBuildRoot }); + await run('cmake', ['--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'], { cwd: nodeBuildRoot }); } else { console.error('libmongocrypt already built...'); } From 48528c9ef930897c1989c6a2639fd16b1f03df85 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 10:16:32 -0400 Subject: [PATCH 6/9] chore: improve readability --- .github/scripts/libmongocrypt.mjs | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/scripts/libmongocrypt.mjs b/.github/scripts/libmongocrypt.mjs index 0de572f..221eb76 100644 --- a/.github/scripts/libmongocrypt.mjs +++ b/.github/scripts/libmongocrypt.mjs @@ -17,11 +17,7 @@ async function parseArguments() { help: { short: 'h', type: 'boolean' } }; - const args = util.parseArgs({ - args: process.argv.slice(2), - options, - allowPositionals: false - }); + const args = util.parseArgs({ args: process.argv.slice(2), options, allowPositionals: false }); if (args.values.help) { console.log( @@ -39,18 +35,13 @@ async function parseArguments() { }; } +/** `xtrace` style command runner, uses spawn so that stdio is inherited */ async function run(command, args = [], options = {}) { console.error(`+ ${command} ${args.join(' ')}`, options.cwd ? `(in: ${options.cwd})` : ''); await events.once(child_process.spawn(command, args, { stdio: 'inherit', ...options }), 'exit'); } -/** - * Given an object returns CLI flags: - * ``` - * toFlags({a: 1, b: 2}) - * // "-a=1 -b=2" - * ``` - */ +/** CLI flag maker: `toFlags({a: 1, b: 2})` yields `['-a=1', '-b=2']` */ function toFlags(object) { return Array.from(Object.entries(object)).map(([k, v]) => `-${k}=${v}`); } @@ -58,7 +49,8 @@ function toFlags(object) { const args = await parseArguments(); const libmongocryptRoot = path.resolve('_libmongocrypt'); -const libmongocryptAlreadyClonedAndCheckedOut = (await fs.readFile(path.join(libmongocryptRoot, '.git', 'HEAD'), 'utf8')).trim().endsWith(`r-${args.libmongocrypt.ref}`); +const currentLibMongoCryptBranch = await fs.readFile(path.join(libmongocryptRoot, '.git', 'HEAD'), 'utf8').catch(() => '') +const libmongocryptAlreadyClonedAndCheckedOut = currentLibMongoCryptBranch.trim().endsWith(`r-${args.libmongocrypt.ref}`); if (!args.clean && !libmongocryptAlreadyClonedAndCheckedOut) { console.error('fetching libmongocrypt...', args.libmongocrypt); @@ -70,9 +62,8 @@ if (!args.clean && !libmongocryptAlreadyClonedAndCheckedOut) { console.error('libmongocrypt already up to date...', args.libmongocrypt); } -const libmongocryptAlreadyBuilt = - (await fs.readFile(path.join(libmongocryptRoot, 'VERSION_CURRENT'), 'utf8')).trim() === - args.libmongocrypt.ref; +const libmongocryptBuiltVersion = await fs.readFile(path.join(libmongocryptRoot, 'VERSION_CURRENT'), 'utf8').catch(() => ''); +const libmongocryptAlreadyBuilt = libmongocryptBuiltVersion.trim() === args.libmongocrypt.ref; if (!args.clean && !libmongocryptAlreadyBuilt) { console.error('building libmongocrypt...\n', args); @@ -101,12 +92,14 @@ if (!args.clean && !libmongocryptAlreadyBuilt) { }); const WINDOWS_CMAKE_FLAGS = - process.platform === 'win32' + process.platform === 'win32' // Windows is still called "win32" when it is 64-bit ? toFlags({ Thost: 'x64', A: 'x64', DENABLE_WINDOWS_STATIC_RUNTIME: 'ON' }) : []; const MACOS_CMAKE_FLAGS = - process.platform === 'darwin' ? toFlags({ DCMAKE_OSX_DEPLOYMENT_TARGET: '10.12' }) : []; + process.platform === 'darwin' // The minimum macos target version we want for + ? toFlags({ DCMAKE_OSX_DEPLOYMENT_TARGET: '10.12' }) + : []; await run('cmake', [...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...MACOS_CMAKE_FLAGS, libmongocryptRoot], { cwd: nodeBuildRoot }); await run('cmake', ['--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'], { cwd: nodeBuildRoot }); From a11f58c3bf24aa81452f9c61dd749eb6e14baaeb Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 11:42:57 -0400 Subject: [PATCH 7/9] chore: fix script path --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5a4d2c7..86d30cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,5 +20,5 @@ jobs: registry-url: 'https://registry.npmjs.org' - run: npm install -g npm@latest shell: bash - - run: node etc/libmongocrypt.mjs + - run: node .github/scripts/libmongocrypt.mjs shell: bash From b34c2d8979882f90a2de406fdb060f0b050dc297 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 12:54:38 -0400 Subject: [PATCH 8/9] chore: copy over todo --- .github/scripts/libmongocrypt.mjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/scripts/libmongocrypt.mjs b/.github/scripts/libmongocrypt.mjs index 221eb76..7604a8c 100644 --- a/.github/scripts/libmongocrypt.mjs +++ b/.github/scripts/libmongocrypt.mjs @@ -75,7 +75,21 @@ if (!args.clean && !libmongocryptAlreadyBuilt) { await fs.mkdir(nodeBuildRoot, { recursive: true }); const CMAKE_FLAGS = toFlags({ - /** We provide crypto hooks from Node.js binding to openssl (so disable system crypto) */ + /** + * We provide crypto hooks from Node.js binding to openssl (so disable system crypto) + * TODO: NODE-5455 + * + * One thing that is not obvious from the build instructions for libmongocrypt + * and the Node.js bindings is that the Node.js driver uses libmongocrypt in + * DISABLE_NATIVE_CRYPTO aka nocrypto mode, that is, instead of using native + * system libraries for crypto operations, it provides callbacks to libmongocrypt + * which, in the Node.js addon case, call JS functions that in turn call built-in + * Node.js crypto methods. + * + * That’s way more convoluted than it needs to be, considering that we always + * have a copy of OpenSSL available directly, but for now it seems to make sense + * to stick with what the Node.js addon does here. + */ DDISABLE_NATIVE_CRYPTO: '1', /** A consistent name for the output "library" directory */ DCMAKE_INSTALL_LIBDIR: 'lib', From 18aa4fc6e5f355e619007487ef6e9730669d3b33 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 21 May 2024 17:16:25 -0400 Subject: [PATCH 9/9] chore: fix clean flag --- .github/scripts/libmongocrypt.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/libmongocrypt.mjs b/.github/scripts/libmongocrypt.mjs index 7604a8c..5846bd2 100644 --- a/.github/scripts/libmongocrypt.mjs +++ b/.github/scripts/libmongocrypt.mjs @@ -52,7 +52,7 @@ const libmongocryptRoot = path.resolve('_libmongocrypt'); const currentLibMongoCryptBranch = await fs.readFile(path.join(libmongocryptRoot, '.git', 'HEAD'), 'utf8').catch(() => '') const libmongocryptAlreadyClonedAndCheckedOut = currentLibMongoCryptBranch.trim().endsWith(`r-${args.libmongocrypt.ref}`); -if (!args.clean && !libmongocryptAlreadyClonedAndCheckedOut) { +if (args.clean || !libmongocryptAlreadyClonedAndCheckedOut) { console.error('fetching libmongocrypt...', args.libmongocrypt); await fs.rm(libmongocryptRoot, { recursive: true, force: true }); await run('git', ['clone', args.libmongocrypt.url, libmongocryptRoot]); @@ -65,7 +65,7 @@ if (!args.clean && !libmongocryptAlreadyClonedAndCheckedOut) { const libmongocryptBuiltVersion = await fs.readFile(path.join(libmongocryptRoot, 'VERSION_CURRENT'), 'utf8').catch(() => ''); const libmongocryptAlreadyBuilt = libmongocryptBuiltVersion.trim() === args.libmongocrypt.ref; -if (!args.clean && !libmongocryptAlreadyBuilt) { +if (args.clean || !libmongocryptAlreadyBuilt) { console.error('building libmongocrypt...\n', args); const nodeDepsRoot = path.resolve('deps');