ravendb / ravendb-nodejs-client

RavenDB node.js client
MIT License
63 stars 32 forks source link

fix: Error thrown when running `DocumentStore.initialize()` with an insecure connection when passing `AuthOptions`, even if no certificate was passed. #412

Closed vxern closed 5 months ago

vxern commented 6 months ago

This PR fixes an error being thrown when DocumentStore.initialize() is run after creating a DocumentStore passing AuthOptions that do not contain a certificate.

In essence, this means that the user is forced to write the following verbose construction if they have a case where their certificate is possibly undefined:

let store: DocumentStore;
if (certificate) {
    store = new DocumentStore(host, database, { certificate, type: "pfx" });
} else {
    store = new DocumentStore(host, database);
}

store.initialize();

Instead of:

// This interface is agnostic to whether `certificate` is present or not, if it's not provided, it will just assume an insecure connection.
const store = new DocumentStore(host, database, { certificate, type: "pfx" });

store.initialize();

Given that this piece of code currently throws:

const store = new DocumentStore(host, database, { certificate: undefined, type: "pfx" });

store.initialize(); // Throws.
ml054 commented 5 months ago

@vxern Thanks for your contribution. :)

vxern commented 5 months ago

Absolutely, @ml054, thanks for looking into this.