Skip to content

Commit 45889a7

Browse files
feat(nodejs): authenticate with user id and private key only (#23)
* feat(nodejs): authenticate with user id and private key only * remove extra file * small js doc update * fix test app * build to use the latest node version * update github actions version * update github actions version * update node version * renaming auth properties: kid -> keyId, d -> token * Update README.md Co-authored-by: Andrei Pechkurov <37772591+puzpuzpuz@users.noreply.github.com> --------- Co-authored-by: Andrei Pechkurov <37772591+puzpuzpuz@users.noreply.github.com>
1 parent 828afd1 commit 45889a7

17 files changed

+395
-236
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
node-version: [16, 20]
11+
node-version: [16, latest]
1212
steps:
1313
- name: Checkout repository
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
submodules: recursive
1717

1818
- name: Setup node
19-
uses: actions/setup-node@v3
19+
uses: actions/setup-node@v4
2020
with:
2121
node-version: ${{ matrix.node-version }}
2222

.github/workflows/publish.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout repository
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
submodules: recursive
1717

1818
- name: Setup node
19-
uses: actions/setup-node@v3
19+
uses: actions/setup-node@v4
2020
with:
21-
node-version: 20
21+
node-version: latest
2222

2323
- name: Install dependencies
2424
run: npm ci
@@ -30,7 +30,7 @@ jobs:
3030
run: npm run eslint
3131

3232
- name: Publish
33-
uses: JS-DevTools/npm-publish@v2
33+
uses: JS-DevTools/npm-publish@v3
3434
with:
3535
token: ${{ secrets.CI_TOKEN }}
3636
access: public

README.md

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,16 @@ run()
5757
const { Sender } = require('@questdb/nodejs-client');
5858

5959
async function run() {
60-
// construct a JsonWebKey
60+
// authentication details
6161
const CLIENT_ID = 'testapp';
6262
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
63-
const PUBLIC_KEY = {
64-
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
65-
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
66-
};
67-
const JWK = {
68-
...PUBLIC_KEY,
69-
d: PRIVATE_KEY,
70-
kid: CLIENT_ID,
71-
kty: 'EC',
72-
crv: 'P-256',
63+
const AUTH = {
64+
keyId: CLIENT_ID,
65+
token: PRIVATE_KEY
7366
};
7467

75-
// pass the JsonWebKey to the sender
76-
// will use it for authentication
77-
const sender = new Sender({jwk: JWK});
68+
// pass the authentication details to the sender
69+
const sender = new Sender({auth: AUTH});
7870

7971
// connect() takes an optional second argument
8072
// if 'true' passed the connection is secured with TLS encryption
@@ -99,24 +91,16 @@ run().catch(console.error);
9991
import { Sender } from '@questdb/nodejs-client';
10092

10193
async function run(): Promise<number> {
102-
// construct a JsonWebKey
94+
// authentication details
10395
const CLIENT_ID: string = 'testapp';
10496
const PRIVATE_KEY: string = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
105-
const PUBLIC_KEY: { x: string, y: string } = {
106-
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
107-
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
108-
};
109-
const JWK: { x: string, y: string, kid: string, kty: string, d: string, crv: string } = {
110-
...PUBLIC_KEY,
111-
d: PRIVATE_KEY,
112-
kid: CLIENT_ID,
113-
kty: 'EC',
114-
crv: 'P-256',
97+
const AUTH: { keyId: string, token: string } = {
98+
keyId: CLIENT_ID,
99+
token: PRIVATE_KEY
115100
};
116101

117-
// pass the JsonWebKey to the sender
118-
// will use it for authentication
119-
const sender: Sender = new Sender({jwk: JWK});
102+
// pass the authentication details to the sender
103+
const sender: Sender = new Sender({auth: AUTH});
120104

121105
// connect() takes an optional second argument
122106
// if 'true' passed the connection is secured with TLS encryption

docs/Sender.html

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ <h1 class="page-title">Class: Sender</h1>
3030

3131
<h2><span class="attribs"><span class="type-signature"></span></span>Sender<span class="signature">(options)</span><span class="type-signature"></span></h2>
3232

33-
<div class="class-description">The QuestDB client's API provides methods to connect to the database, ingest data and close the connection.
33+
<div class="class-description">The QuestDB client's API provides methods to connect to the database, ingest data, and close the connection.
3434
<p>
3535
The client supports authentication. <br>
36-
A JsonWebKey can be passed to the Sender in its constructor, the JsonWebKey will be used for authentication. <br>
37-
If no JsonWebKey specified the client will not attempt to authenticate itself with the server. <br>
38-
Details on how to configure QuestDB authentication: <a href="https://questdb.io/docs/reference/api/ilp/authenticate">https://questdb.io/docs/reference/api/ilp/authenticate</a>
36+
Authentication details can be passed to the Sender in its configuration options. <br>
37+
The user id and the user's private key are required for authentication. <br>
38+
More details on configuration options can be found in the description of the constructor. <br>
39+
Please, note that authentication is enabled by default in QuestDB Enterprise only. <br>
40+
Details on how to configure authentication in the open source version of QuestDB: <a href="https://questdb.io/docs/reference/api/ilp/authenticate">https://questdb.io/docs/reference/api/ilp/authenticate</a>
3941
</p>
4042
<p>
4143
The client also supports TLS encryption to provide a secure connection. <br>
42-
However, QuestDB does not support TLS yet and requires an external reverse-proxy, such as Nginx to enable encryption.
44+
Please, note that the open source version of QuestDB does not support TLS, and requires an external reverse-proxy, such as Nginx to enable encryption.
4345
</p></div>
4446

4547

@@ -128,7 +130,10 @@ <h5>Parameters:</h5>
128130
If the value passed is not a boolean, the setting is ignored. </li>
129131
<li>jwk: <i>{x: string, y: string, kid: string, kty: string, d: string, crv: string}</i> - JsonWebKey for authentication. <br>
130132
If not provided, client is not authenticated and server might reject the connection depending on configuration. <br>
131-
No type checks performed on the object passed. </li>
133+
No type checks performed on the object passed. <br>
134+
<b>Deprecated</b>, please, use the <i>auth</i> option instead. </li>
135+
<li>auth: <i>{keyId: string, token: string}</i> - Authentication details, `keyId` is the username, `token` is the user's private key. <br>
136+
If not provided, client is not authenticated and server might reject the connection depending on configuration. </li>
132137
<li>log: <i>(level: 'error'|'warn'|'info'|'debug', message: string) => void</i> - logging function. <br>
133138
If not provided, default logging is used which writes to the console with logging level <i>info</i>. <br>
134139
If not a function passed, the setting is ignored. </li>
@@ -174,7 +179,7 @@ <h5>Parameters:</h5>
174179

175180
<dt class="tag-source">Source:</dt>
176181
<dd class="tag-source"><ul class="dummy"><li>
177-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line27">line 27</a>
182+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line36">line 36</a>
178183
</li></ul></dd>
179184

180185

@@ -389,7 +394,7 @@ <h5>Parameters:</h5>
389394

390395
<dt class="tag-source">Source:</dt>
391396
<dd class="tag-source"><ul class="dummy"><li>
392-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line366">line 366</a>
397+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line376">line 376</a>
393398
</li></ul></dd>
394399

395400

@@ -478,7 +483,7 @@ <h4 class="name" id="atNow"><span class="type-signature"></span>atNow<span class
478483

479484
<dt class="tag-source">Source:</dt>
480485
<dd class="tag-source"><ul class="dummy"><li>
481-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line386">line 386</a>
486+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line396">line 396</a>
482487
</li></ul></dd>
483488

484489

@@ -638,7 +643,7 @@ <h5>Parameters:</h5>
638643

639644
<dt class="tag-source">Source:</dt>
640645
<dd class="tag-source"><ul class="dummy"><li>
641-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line294">line 294</a>
646+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line304">line 304</a>
642647
</li></ul></dd>
643648

644649

@@ -749,7 +754,7 @@ <h4 class="name" id="close"><span class="type-signature">(async) </span>close<sp
749754

750755
<dt class="tag-source">Source:</dt>
751756
<dd class="tag-source"><ul class="dummy"><li>
752-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line174">line 174</a>
757+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line184">line 184</a>
753758
</li></ul></dd>
754759

755760

@@ -944,7 +949,7 @@ <h5>Parameters:</h5>
944949

945950
<dt class="tag-source">Source:</dt>
946951
<dd class="tag-source"><ul class="dummy"><li>
947-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line118">line 118</a>
952+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line128">line 128</a>
948953
</li></ul></dd>
949954

950955

@@ -1126,7 +1131,7 @@ <h5>Parameters:</h5>
11261131

11271132
<dt class="tag-source">Source:</dt>
11281133
<dd class="tag-source"><ul class="dummy"><li>
1129-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line309">line 309</a>
1134+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line319">line 319</a>
11301135
</li></ul></dd>
11311136

11321137

@@ -1237,7 +1242,7 @@ <h4 class="name" id="flush"><span class="type-signature">(async) </span>flush<sp
12371242

12381243
<dt class="tag-source">Source:</dt>
12391244
<dd class="tag-source"><ul class="dummy"><li>
1240-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line187">line 187</a>
1245+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line197">line 197</a>
12411246
</li></ul></dd>
12421247

12431248

@@ -1419,7 +1424,7 @@ <h5>Parameters:</h5>
14191424

14201425
<dt class="tag-source">Source:</dt>
14211426
<dd class="tag-source"><ul class="dummy"><li>
1422-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line325">line 325</a>
1427+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line335">line 335</a>
14231428
</li></ul></dd>
14241429

14251430

@@ -1530,7 +1535,7 @@ <h4 class="name" id="reset"><span class="type-signature"></span>reset<span class
15301535

15311536
<dt class="tag-source">Source:</dt>
15321537
<dd class="tag-source"><ul class="dummy"><li>
1533-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line104">line 104</a>
1538+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line114">line 114</a>
15341539
</li></ul></dd>
15351540

15361541

@@ -1691,7 +1696,7 @@ <h5>Parameters:</h5>
16911696

16921697
<dt class="tag-source">Source:</dt>
16931698
<dd class="tag-source"><ul class="dummy"><li>
1694-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line89">line 89</a>
1699+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line99">line 99</a>
16951700
</li></ul></dd>
16961701

16971702

@@ -1851,7 +1856,7 @@ <h5>Parameters:</h5>
18511856

18521857
<dt class="tag-source">Source:</dt>
18531858
<dd class="tag-source"><ul class="dummy"><li>
1854-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line277">line 277</a>
1859+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line287">line 287</a>
18551860
</li></ul></dd>
18561861

18571862

@@ -2033,7 +2038,7 @@ <h5>Parameters:</h5>
20332038

20342039
<dt class="tag-source">Source:</dt>
20352040
<dd class="tag-source"><ul class="dummy"><li>
2036-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line252">line 252</a>
2041+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line262">line 262</a>
20372042
</li></ul></dd>
20382043

20392044

@@ -2192,7 +2197,7 @@ <h5>Parameters:</h5>
21922197

21932198
<dt class="tag-source">Source:</dt>
21942199
<dd class="tag-source"><ul class="dummy"><li>
2195-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line231">line 231</a>
2200+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line241">line 241</a>
21962201
</li></ul></dd>
21972202

21982203

@@ -2444,7 +2449,7 @@ <h5>Parameters:</h5>
24442449

24452450
<dt class="tag-source">Source:</dt>
24462451
<dd class="tag-source"><ul class="dummy"><li>
2447-
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line346">line 346</a>
2452+
<a href="src_sender.js.html">src/sender.js</a>, <a href="src_sender.js.html#line356">line 356</a>
24482453
</li></ul></dd>
24492454

24502455

@@ -2518,7 +2523,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
25182523
<br class="clear">
25192524

25202525
<footer>
2521-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
2526+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Nov 28 2023 12:41:23 GMT+0000 (Greenwich Mean Time)
25222527
</footer>
25232528

25242529
<script> prettyPrint(); </script>

docs/index.html

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,16 @@ <h3>Authentication and secure connection</h3>
9191
<pre class="prettyprint source lang-javascript"><code>const { Sender } = require('@questdb/nodejs-client');
9292

9393
async function run() {
94-
// construct a JsonWebKey
94+
// authentication details
9595
const CLIENT_ID = 'testapp';
9696
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
97-
const PUBLIC_KEY = {
98-
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
99-
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
100-
};
101-
const JWK = {
102-
...PUBLIC_KEY,
103-
d: PRIVATE_KEY,
104-
kid: CLIENT_ID,
105-
kty: 'EC',
106-
crv: 'P-256',
97+
const AUTH = {
98+
keyId: CLIENT_ID,
99+
token: PRIVATE_KEY
107100
};
108101

109-
// pass the JsonWebKey to the sender
110-
// will use it for authentication
111-
const sender = new Sender({jwk: JWK});
102+
// pass the authentication details to the sender
103+
const sender = new Sender({auth: AUTH});
112104

113105
// connect() takes an optional second argument
114106
// if 'true' passed the connection is secured with TLS encryption
@@ -130,24 +122,16 @@ <h3>TypeScript example</h3>
130122
<pre class="prettyprint source lang-typescript"><code>import { Sender } from '@questdb/nodejs-client';
131123

132124
async function run(): Promise&lt;number> {
133-
// construct a JsonWebKey
125+
// authentication details
134126
const CLIENT_ID: string = 'testapp';
135127
const PRIVATE_KEY: string = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
136-
const PUBLIC_KEY: { x: string, y: string } = {
137-
x: 'aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc',
138-
y: '__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg'
139-
};
140-
const JWK: { x: string, y: string, kid: string, kty: string, d: string, crv: string } = {
141-
...PUBLIC_KEY,
142-
d: PRIVATE_KEY,
143-
kid: CLIENT_ID,
144-
kty: 'EC',
145-
crv: 'P-256',
128+
const AUTH: { kid: string, d: string } = {
129+
keyId: CLIENT_ID,
130+
token: PRIVATE_KEY
146131
};
147132

148-
// pass the JsonWebKey to the sender
149-
// will use it for authentication
150-
const sender: Sender = new Sender({jwk: JWK});
133+
// pass the authentication details to the sender
134+
const sender: Sender = new Sender({auth: AUTH});
151135

152136
// connect() takes an optional second argument
153137
// if 'true' passed the connection is secured with TLS encryption
@@ -256,7 +240,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
256240
<br class="clear">
257241

258242
<footer>
259-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
243+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Nov 28 2023 12:41:23 GMT+0000 (Greenwich Mean Time)
260244
</footer>
261245

262246
<script> prettyPrint(); </script>

docs/index.js.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
5353
<br class="clear">
5454

5555
<footer>
56-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
56+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Nov 28 2023 12:41:23 GMT+0000 (Greenwich Mean Time)
5757
</footer>
5858

5959
<script> prettyPrint(); </script>

docs/module-@questdb_nodejs-client.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
120120
<br class="clear">
121121

122122
<footer>
123-
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Oct 09 2023 10:21:55 GMT+0300 (Eastern European Summer Time)
123+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Tue Nov 28 2023 12:41:23 GMT+0000 (Greenwich Mean Time)
124124
</footer>
125125

126126
<script> prettyPrint(); </script>

0 commit comments

Comments
 (0)