@daktela/daktela-connector 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +12 -1
- package/package.json +1 -1
- package/src/index.js +16 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
# 1.1.0
|
|
2
|
+
- Add `X-AUTH-TOKEN` header authentication (new default).
|
|
3
|
+
- Add `authMethod` option with values: `'header'` (default), `'cookie'`, `'query'`.
|
|
4
|
+
- Deprecate `cookieAuth` option (still functional for backward compatibility).
|
|
5
|
+
|
|
1
6
|
# 1.0.1
|
|
2
7
|
Update README.md
|
|
3
8
|
|
package/README.md
CHANGED
|
@@ -16,7 +16,11 @@ The only dependency of this library is HTTP client `Axios` (https://axios-http.c
|
|
|
16
16
|
`DaktelaConnector` is a class that allows you to send CRUD requests on your Daktela server.
|
|
17
17
|
Beside `instance` and `accessToken` you can pass `options` object with following parameters:
|
|
18
18
|
|
|
19
|
-
* `
|
|
19
|
+
* `authMethod` (string) - authentication method. Possible values:
|
|
20
|
+
* `'header'` (default) - uses `X-AUTH-TOKEN` HTTP header.
|
|
21
|
+
* `'cookie'` - uses `Cookie` header with `c_user` cookie.
|
|
22
|
+
* `'query'` - passes access token as query parameter.
|
|
23
|
+
* `cookieAuth` (boolean) - **deprecated**, use `authMethod` instead. When set to `true`, uses cookie authentication; when `false`, uses query parameter authentication.
|
|
20
24
|
* `userAgent` (string) - HTTP User-Agent header.
|
|
21
25
|
* `timeout` {number} - requests' timeout. Default value is `0` (no timeout).
|
|
22
26
|
|
|
@@ -40,8 +44,15 @@ Other way is to directly pass Axios's `params` argument which overrides Daktela
|
|
|
40
44
|
```js
|
|
41
45
|
require('dotenv').config();
|
|
42
46
|
const Daktela = require('daktela-connector');
|
|
47
|
+
|
|
48
|
+
// Default - uses X-AUTH-TOKEN header
|
|
43
49
|
let daktela = new Daktela.DaktelaConnector(process.env.INSTANCE, process.env.ACCESS_TOKEN);
|
|
44
50
|
|
|
51
|
+
// Or explicitly specify authentication method
|
|
52
|
+
let daktela = new Daktela.DaktelaConnector(process.env.INSTANCE, process.env.ACCESS_TOKEN, {
|
|
53
|
+
authMethod: 'cookie' // 'header' (default), 'cookie', or 'query'
|
|
54
|
+
});
|
|
55
|
+
|
|
45
56
|
//...
|
|
46
57
|
|
|
47
58
|
// login request
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -130,7 +130,8 @@ class DaktelaError extends Error {
|
|
|
130
130
|
* @param {string} url Target Daktela instance (e. g. my.daktela.com).
|
|
131
131
|
* @param {string} [accessToken=null] Access token.
|
|
132
132
|
* @param {Object} [options={}] Options of the connector. See below.
|
|
133
|
-
* @param {
|
|
133
|
+
* @param {string} options.authMethod Authentication method: 'header' (X-AUTH-TOKEN, default), 'cookie' (Cookie header), or 'query' (query parameter).
|
|
134
|
+
* @param {boolean} options.cookieAuth @deprecated Use authMethod instead. Authorize requests via Cookie header. Default value is true. Otherwise access token will be passed as query parameter.
|
|
134
135
|
* @param {string} options.userAgent User agent header.
|
|
135
136
|
* @param {number} options.timeout Specifies the number of milliseconds before the request times out. Default is 0 (no timout)
|
|
136
137
|
*/
|
|
@@ -141,10 +142,20 @@ const DaktelaConnector = function DaktelaConnector(url, accessToken = null, opti
|
|
|
141
142
|
if (!url.endsWith('/')) {
|
|
142
143
|
url += '/';
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
+
// Determine auth method: 'header' (default), 'cookie', or 'query'
|
|
146
|
+
this.authMethod = options.authMethod ?? 'header';
|
|
147
|
+
// Backward compatibility: if cookieAuth is explicitly set, use legacy behavior
|
|
148
|
+
if (options.cookieAuth !== undefined) {
|
|
149
|
+
this.authMethod = options.cookieAuth ? 'cookie' : 'query';
|
|
150
|
+
}
|
|
145
151
|
var headers = {};
|
|
146
|
-
if (
|
|
147
|
-
|
|
152
|
+
if (accessToken != null) {
|
|
153
|
+
if (this.authMethod === 'header') {
|
|
154
|
+
headers['X-AUTH-TOKEN'] = accessToken;
|
|
155
|
+
} else if (this.authMethod === 'cookie') {
|
|
156
|
+
headers['Cookie'] = 'c_user=' + accessToken;
|
|
157
|
+
}
|
|
158
|
+
// 'query' method handled in buildRequestParams()
|
|
148
159
|
}
|
|
149
160
|
if (options.userAgent !== null) {
|
|
150
161
|
headers['User-Agent'] = options.userAgent;
|
|
@@ -205,7 +216,7 @@ DaktelaConnector.prototype.buildRequestParams = function (options) {
|
|
|
205
216
|
}
|
|
206
217
|
}
|
|
207
218
|
}
|
|
208
|
-
if (
|
|
219
|
+
if (this.authMethod === 'query' && this.accessToken !== null) {
|
|
209
220
|
params.accessToken = this.accessToken;
|
|
210
221
|
}
|
|
211
222
|
return {
|