Skip to content

Commit

Permalink
renaming auth properties: kid -> keyId, d -> token
Browse files Browse the repository at this point in the history
  • Loading branch information
glasstiger committed Nov 28, 2023
1 parent 570f54b commit d67dda6
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 143 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ async function run() {
const CLIENT_ID = 'testapp';
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const AUTH = {
kid: CLIENT_ID,
d: PRIVATE_KEY
keyId: CLIENT_ID,
token: PRIVATE_KEY
};

// pass the authentication details to the sender
Expand Down Expand Up @@ -95,8 +95,8 @@ async function run(): Promise<number> {
const CLIENT_ID: string = 'testapp';
const PRIVATE_KEY: string = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const AUTH: { kid: string, d: string } = {
kid: CLIENT_ID,
d: PRIVATE_KEY
keyId: CLIENT_ID,
token: PRIVATE_KEY
};

// pass the authentication details to the sender
Expand Down
4 changes: 2 additions & 2 deletions docs/Sender.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ <h5>Parameters:</h5>
If not provided, client is not authenticated and server might reject the connection depending on configuration. <br>
No type checks performed on the object passed. <br>
<b>Deprecated</b>, please, use the <i>auth</i> option instead. </li>
<li>auth: <i>{kid: string, d: string}</i> - Authentication details, `kid` is the username, `d` is the user's private key. <br>
<li>auth: <i>{keyId: string, token: string}</i> - Authentication details, `keyId` is the username, `token` is the user's private key. <br>
If not provided, client is not authenticated and server might reject the connection depending on configuration. </li>
<li>log: <i>(level: 'error'|'warn'|'info'|'debug', message: string) => void</i> - logging function. <br>
If not provided, default logging is used which writes to the console with logging level <i>info</i>. <br>
Expand Down Expand Up @@ -2523,7 +2523,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
10 changes: 5 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ <h3>Authentication and secure connection</h3>
const CLIENT_ID = 'testapp';
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const AUTH = {
kid: CLIENT_ID,
d: PRIVATE_KEY
keyId: CLIENT_ID,
token: PRIVATE_KEY
};

// pass the authentication details to the sender
Expand Down Expand Up @@ -126,8 +126,8 @@ <h3>TypeScript example</h3>
const CLIENT_ID: string = 'testapp';
const PRIVATE_KEY: string = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const AUTH: { kid: string, d: string } = {
kid: CLIENT_ID,
d: PRIVATE_KEY
keyId: CLIENT_ID,
token: PRIVATE_KEY
};

// pass the authentication details to the sender
Expand Down Expand Up @@ -240,7 +240,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-@questdb_nodejs-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
40 changes: 21 additions & 19 deletions docs/src_sender.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ <h1 class="page-title">Source: src/sender.js</h1>
* If not provided, client is not authenticated and server might reject the connection depending on configuration. &lt;br>
* No type checks performed on the object passed. &lt;br>
* &lt;b>Deprecated&lt;/b>, please, use the &lt;i>auth&lt;/i> option instead. &lt;/li>
* &lt;li>auth: &lt;i>{kid: string, d: string}&lt;/i> - Authentication details, `kid` is the username, `d` is the user's private key. &lt;br>
* &lt;li>auth: &lt;i>{keyId: string, token: string}&lt;/i> - Authentication details, `keyId` is the username, `token` is the user's private key. &lt;br>
* If not provided, client is not authenticated and server might reject the connection depending on configuration. &lt;/li>
* &lt;li>log: &lt;i>(level: 'error'|'warn'|'info'|'debug', message: string) => void&lt;/i> - logging function. &lt;br>
* If not provided, default logging is used which writes to the console with logging level &lt;i>info&lt;/i>. &lt;br>
Expand All @@ -103,7 +103,7 @@ <h1 class="page-title">Source: src/sender.js</h1>
* &lt;/p>
*/
constructor(options = undefined) {
initJwk(this, options);
this.jwk = constructJwk(options);
const noCopy = options &amp;&amp; typeof options.copyBuffer === 'boolean' &amp;&amp; !options.copyBuffer;
this.toBuffer = noCopy ? this.toBufferView : this.toBufferNew;
this.doResolve = noCopy
Expand Down Expand Up @@ -570,36 +570,38 @@ <h1 class="page-title">Source: src/sender.js</h1>
}
}

function initJwk(sender, options) {
function constructJwk(options) {
if (options) {
if (options.auth) {
if (!options.auth.kid) {
throw new Error('Missing username, please, specify the \'kid\' property of the \'auth\' config option. ' +
'For example: new Sender({auth: {kid: \'username\', d: \'private key\'}})');
if (!options.auth.keyId) {
throw new Error('Missing username, please, specify the \'keyId\' property of the \'auth\' config option. ' +
'For example: new Sender({auth: {keyId: \'username\', token: \'private key\'}})');
}
if (typeof options.auth.kid !== 'string') {
throw new Error('Please, specify the \'kid\' property of the \'auth\' config option as a string. ' +
'For example: new Sender({auth: {kid: \'username\', d: \'private key\'}})');
if (typeof options.auth.keyId !== 'string') {
throw new Error('Please, specify the \'keyId\' property of the \'auth\' config option as a string. ' +
'For example: new Sender({auth: {keyId: \'username\', token: \'private key\'}})');
}
if (!options.auth.d) {
throw new Error('Missing private key, please, specify the \'d\' property of the \'auth\' config option. ' +
'For example: new Sender({auth: {kid: \'username\', d: \'private key\'}})');
if (!options.auth.token) {
throw new Error('Missing private key, please, specify the \'token\' property of the \'auth\' config option. ' +
'For example: new Sender({auth: {keyId: \'username\', token: \'private key\'}})');
}
if (typeof options.auth.d !== 'string') {
throw new Error('Please, specify the \'d\' property of the \'auth\' config option as a string. ' +
'For example: new Sender({auth: {kid: \'username\', d: \'private key\'}})');
if (typeof options.auth.token !== 'string') {
throw new Error('Please, specify the \'token\' property of the \'auth\' config option as a string. ' +
'For example: new Sender({auth: {keyId: \'username\', token: \'private key\'}})');
}

sender.jwk = {
...options.auth,
return {
kid: options.auth.keyId,
d: options.auth.token,
...PUBLIC_KEY,
kty: 'EC',
crv: 'P-256'
};
} else {
sender.jwk = options.jwk;
return options.jwk;
}
}
return undefined;
}

exports.Sender = Sender;
Expand All @@ -620,7 +622,7 @@ <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-@q
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Mon Nov 27 2023 17:39:18 GMT+0000 (Greenwich Mean Time)
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)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions examples/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ async function run() {
const CLIENT_ID = 'testapp';
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const AUTH = {
kid: CLIENT_ID,
d: PRIVATE_KEY
keyId: CLIENT_ID,
token: PRIVATE_KEY
};

// pass the authentication details to the sender
Expand Down
4 changes: 2 additions & 2 deletions examples/auth_tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ async function run() {
const CLIENT_ID = 'testapp';
const PRIVATE_KEY = '9b9x5WhJywDEuo1KGQWSPNxtX-6X6R2BRCKhYMMY6n8';
const AUTH = {
kid: CLIENT_ID,
d: PRIVATE_KEY
keyId: CLIENT_ID,
token: PRIVATE_KEY
};

// pass the authentication details to the sender
Expand Down
Loading

0 comments on commit d67dda6

Please sign in to comment.