From 013efb04e0ac667672ad03f3df5643662cafcc4e Mon Sep 17 00:00:00 2001 From: jsus Date: Fri, 2 Sep 2022 15:17:55 +0300 Subject: [PATCH 1/7] fix: extracting version from imported package.json --- fixup.sh | 4 ++++ src/version.ts | 8 +------- tsconfig-base.json | 3 ++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/fixup.sh b/fixup.sh index 67e09214..f42ddb50 100755 --- a/fixup.sh +++ b/fixup.sh @@ -1,13 +1,17 @@ #!/bin/sh +package_version=`npm show . version` + cat >build/cjs/package.json <build/esm/package.json < Date: Fri, 2 Sep 2022 23:57:40 +0300 Subject: [PATCH 2/7] fix: certificates path for bundling compilation This is a poor man's fix for bundling compilers like esbuild\webpack that require paths to be relative to the entry point. Certs folder is moved into cjs\esm dists so we can utilize universal path './certs' that would work for default tsc compilation and would allow copying the certs folder to whatever path bundler is gonna output compiled entry point. Some sensible error communication is also added This commit is not marked as breaking because if certs folder had not been found when grpcs is present in previous implementation the connection would not succeed and\or "File not found" error threw --- fixup.sh | 12 ++++-------- src/ssl-credentials.ts | 26 ++++++++++++++++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/fixup.sh b/fixup.sh index f42ddb50..dffea590 100755 --- a/fixup.sh +++ b/fixup.sh @@ -2,16 +2,12 @@ package_version=`npm show . version` -cat >build/cjs/package.json <build/$target/package.json <build/esm/package.json < 0) { systemRootCertificates = Buffer.from(nodeRootCertificates.join('\n')); } else { - systemRootCertificates = fs.readFileSync(FALLBACK_SYSTEM_ROOT_CERTS); + systemRootCertificates = failbackSystemRootCertificates; } return Buffer.concat([internalRootCertificates, systemRootCertificates]); @@ -47,6 +55,12 @@ export function makeSslCredentials(endpoint: string, logger: Logger, sslCredenti return makeDefaultSslCredentials(); } +const certificateNotFoundMessage = `No certificate found +It seems that you are using grpcs (secure) endpoint in a bundled environment. +Either provide YDB_SSL_ROOT_CERTIFICATES_FILE environment variable +or copy contents of ydb-nodejs-sdk/certs to ./certs path relative to the bundled file +` + export interface ISslCredentials { rootCertificates?: Buffer, clientPrivateKey?: Buffer, From e999ae5190728a999a579d619e7818a8b425464b Mon Sep 17 00:00:00 2001 From: jsus Date: Tue, 6 Sep 2022 22:38:15 +0300 Subject: [PATCH 3/7] fix: failback --> fallback --- src/ssl-credentials.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ssl-credentials.ts b/src/ssl-credentials.ts index e4520408..c6812c6a 100644 --- a/src/ssl-credentials.ts +++ b/src/ssl-credentials.ts @@ -1,5 +1,5 @@ // noinspection ES6PreferShortImport -import {Logger} from './logging'; +import { Logger } from './logging'; import fs from 'fs'; import path from 'path'; @@ -16,7 +16,7 @@ function makeInternalRootCertificates() { } const internalRootCertificates = fs.readFileSync(FALLBACK_INTERNAL_ROOT_CERTS) - const failbackSystemRootCertificates = fs.readFileSync(FALLBACK_SYSTEM_ROOT_CERTS) + const fallbackSystemRootCertificates = fs.readFileSync(FALLBACK_SYSTEM_ROOT_CERTS) let systemRootCertificates: Buffer; const tls = require('tls'); @@ -24,7 +24,7 @@ function makeInternalRootCertificates() { if (nodeRootCertificates && nodeRootCertificates.length > 0) { systemRootCertificates = Buffer.from(nodeRootCertificates.join('\n')); } else { - systemRootCertificates = failbackSystemRootCertificates; + systemRootCertificates = fallbackSystemRootCertificates; } return Buffer.concat([internalRootCertificates, systemRootCertificates]); From 1834ced9dfbcc060caf80ded84f820f41980cf4a Mon Sep 17 00:00:00 2001 From: jsus Date: Tue, 6 Sep 2022 22:40:59 +0300 Subject: [PATCH 4/7] fix: removed certs from the folder root --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 4da188a3..04990415 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ } }, "files": [ - "build/**", - "certs/" + "build/**" ], "scripts": { "test:unit": "exit 0", From 8ce2c5b2ad1d9539e66bb31445d5b259cfeea851 Mon Sep 17 00:00:00 2001 From: jsus Date: Tue, 13 Sep 2022 12:53:34 +0300 Subject: [PATCH 5/7] fix: fixup.sh & package.json paths fixes --- fixup.sh | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fixup.sh b/fixup.sh index dffea590..276e239f 100755 --- a/fixup.sh +++ b/fixup.sh @@ -7,7 +7,7 @@ for target in esm cjs; do cat >build/$target/package.json < Date: Tue, 13 Sep 2022 13:28:02 +0300 Subject: [PATCH 6/7] fix: more package.json paths fixes --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 457c25e9..e6a81863 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "ydb-sdk", "version": "3.4.0", "description": "Node.js bindings for working with YDB API over gRPC", - "main": "build/cjs/index.js", - "module": "build/esm/index.js", + "main": "build/cjs/src/index.js", + "module": "build/esm/src/index.js", "exports": { ".": { "import": "./build/esm/src/index.js", From c3f6b88b5e64747d3c639bd434d4d5a68f57c67f Mon Sep 17 00:00:00 2001 From: jsus Date: Tue, 13 Sep 2022 13:41:17 +0300 Subject: [PATCH 7/7] fix: conditional target type --- fixup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fixup.sh b/fixup.sh index 276e239f..bd912764 100755 --- a/fixup.sh +++ b/fixup.sh @@ -4,10 +4,11 @@ package_version=`npm show . version` for target in esm cjs; do cp -R certs build/$target/src/ + [[ $target == "esm" ]] && type="module" || type="commonjs" cat >build/$target/package.json <