@ibm-cloud/cloudant 0.0.18 → 0.0.22
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/README.md +43 -39
- package/auth/couchdbSessionAuthenticator.d.ts +7 -0
- package/auth/couchdbSessionAuthenticator.js +25 -4
- package/auth/couchdbSessionAuthenticator.js.map +1 -1
- package/auth/sessionTokenManager.js +7 -6
- package/auth/sessionTokenManager.js.map +1 -1
- package/cloudant/v1.d.ts +175 -121
- package/cloudant/v1.js +522 -649
- package/cloudant/v1.js.map +1 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/lib/cloudantBaseService.d.ts +1 -1
- package/lib/cloudantBaseService.js +38 -28
- package/lib/cloudantBaseService.js.map +1 -1
- package/lib/common.js +2 -2
- package/lib/common.js.map +1 -1
- package/lib/getAuthenticatorFromEnvCloudantExtension.d.ts +1 -1
- package/lib/getAuthenticatorFromEnvCloudantExtension.js +3 -4
- package/lib/getAuthenticatorFromEnvCloudantExtension.js.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
[](https://github.com/IBM/cloudant-node-sdk/releases/latest)
|
|
3
3
|
[](https://ibm.github.io/cloudant-node-sdk/)
|
|
4
4
|
|
|
5
|
-
# IBM Cloudant Node.js SDK Version 0.0.
|
|
5
|
+
# IBM Cloudant Node.js SDK Version 0.0.22
|
|
6
6
|
|
|
7
7
|
IBM Cloudant Node.js SDK is a client library that interacts with the
|
|
8
8
|
[IBM Cloudant APIs](https://cloud.ibm.com/apidocs/cloudant?code=node).
|
|
9
9
|
|
|
10
|
-
Disclaimer: This
|
|
11
|
-
|
|
10
|
+
Disclaimer: This library is still a 0.x release. We do consider this
|
|
11
|
+
library production-ready and capable, but there are still some
|
|
12
|
+
limitations we’re working to resolve, and refinements we want to
|
|
13
|
+
deliver. We are working really hard to minimise the disruption from
|
|
14
|
+
now until the 1.0 release, but there may still be some changes that
|
|
15
|
+
impact applications using this SDK. For now, be sure to pin versions
|
|
16
|
+
to avoid surprises.
|
|
12
17
|
|
|
13
18
|
<details>
|
|
14
19
|
<summary>Table of Contents</summary>
|
|
@@ -35,6 +40,7 @@ Changes might occur which impact applications that use this SDK.
|
|
|
35
40
|
* [Authentication with external configuration](#authentication-with-external-configuration)
|
|
36
41
|
* [Programmatic authentication](#programmatic-authentication)
|
|
37
42
|
- [Using the SDK](#using-the-sdk)
|
|
43
|
+
* [Request timeout configuration](#request-timeout-configuration)
|
|
38
44
|
* [Code examples](#code-examples)
|
|
39
45
|
+ [1. Retrieve information from an existing database](#1-retrieve-information-from-an-existing-database)
|
|
40
46
|
+ [2. Create your own database and add a document](#2-create-your-own-database-and-add-a-document)
|
|
@@ -100,12 +106,12 @@ npm install @ibm-cloud/cloudant
|
|
|
100
106
|
|
|
101
107
|
## Authentication
|
|
102
108
|
|
|
103
|
-
[service-credentials]: https://cloud.ibm.com/docs/Cloudant?topic=
|
|
104
|
-
[cloud-IAM-mgmt]: https://cloud.ibm.com/docs/Cloudant?topic=
|
|
109
|
+
[service-credentials]: https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-locating-your-service-credentials
|
|
110
|
+
[cloud-IAM-mgmt]: https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-managing-access-for-cloudant#introduction-iam-ai
|
|
105
111
|
[couch-cookie-auth]: https://docs.couchdb.org/en/stable/api/server/authn.html#cookie-authentication
|
|
106
|
-
[cloudant-cookie-auth]: https://cloud.ibm.com/docs/Cloudant?topic=
|
|
112
|
+
[cloudant-cookie-auth]: https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-work-with-your-account#cookie-authentication
|
|
107
113
|
[couch-basic-auth]: https://docs.couchdb.org/en/stable/api/server/authn.html#basic-authentication
|
|
108
|
-
[cloudant-basic-auth]: https://cloud.ibm.com/docs/
|
|
114
|
+
[cloudant-basic-auth]: https://cloud.ibm.com/docs/Cloudant?topic=Cloudant-work-with-your-account#basic-authentication
|
|
109
115
|
|
|
110
116
|
This library requires some of your
|
|
111
117
|
[Cloudant service credentials][service-credentials] to authenticate with your
|
|
@@ -198,8 +204,14 @@ or in the
|
|
|
198
204
|
|
|
199
205
|
## Using the SDK
|
|
200
206
|
|
|
201
|
-
For
|
|
202
|
-
|
|
207
|
+
For fundamental SDK usage information and config options, please see the common [IBM Cloud SDK](https://github.com/IBM/ibm-cloud-sdk-common/blob/master/README.md) documentation.
|
|
208
|
+
|
|
209
|
+
### Request timeout configuration
|
|
210
|
+
|
|
211
|
+
No request timeout is defined, but a 2.5m connect and 2.5m read timeout is set by default. Be sure to set a request timeout appropriate to your application usage and environment.
|
|
212
|
+
The [request timeout](https://github.com/IBM/ibm-cloud-sdk-common/blob/master/README.md) section contains details on how to change the value.
|
|
213
|
+
|
|
214
|
+
**Note:** System settings may take precedence over configured timeout values.
|
|
203
215
|
|
|
204
216
|
### Code examples
|
|
205
217
|
|
|
@@ -246,7 +258,7 @@ const client = CloudantV1.newInstance({ serviceName: 'EXAMPLES' });
|
|
|
246
258
|
// 2. Get server information ==================================================
|
|
247
259
|
// call service without parameters:
|
|
248
260
|
client.getServerInformation().then((serverInformation) => {
|
|
249
|
-
const version = serverInformation.result
|
|
261
|
+
const { version } = serverInformation.result;
|
|
250
262
|
console.log(`Server version ${version}`);
|
|
251
263
|
});
|
|
252
264
|
|
|
@@ -260,7 +272,7 @@ client.getDatabaseInformation({ db: dbName }).then((dbInfo) => {
|
|
|
260
272
|
|
|
261
273
|
// 4. Show document count in database =================================
|
|
262
274
|
console.log(
|
|
263
|
-
`Document count in "${dbNameResult}" database is
|
|
275
|
+
`Document count in "${dbNameResult}" database is ${documentCount}.`
|
|
264
276
|
);
|
|
265
277
|
});
|
|
266
278
|
|
|
@@ -273,9 +285,9 @@ const getDocParams: CloudantV1.GetDocumentParams = {
|
|
|
273
285
|
// call service with predefined parameters:
|
|
274
286
|
client.getDocument(getDocParams).then((documentAboutZebra) => {
|
|
275
287
|
// result object is defined as a Document here:
|
|
276
|
-
const result
|
|
288
|
+
const { result } = documentAboutZebra;
|
|
277
289
|
console.log(
|
|
278
|
-
|
|
290
|
+
`Document retrieved from database:\n${JSON.stringify(result, null, 2)}`
|
|
279
291
|
);
|
|
280
292
|
});
|
|
281
293
|
```
|
|
@@ -295,7 +307,7 @@ const getInfoFromExistingDatabase = async () => {
|
|
|
295
307
|
|
|
296
308
|
// 2. Get server information ==================================================
|
|
297
309
|
// call service without parameters:
|
|
298
|
-
const version = (await client.getServerInformation()).result
|
|
310
|
+
const { version } = (await client.getServerInformation()).result;
|
|
299
311
|
console.log(`Server version ${version}`);
|
|
300
312
|
|
|
301
313
|
// 3. Get database information for "animaldb" =================================
|
|
@@ -308,7 +320,7 @@ const getInfoFromExistingDatabase = async () => {
|
|
|
308
320
|
|
|
309
321
|
// 4. Show document count in database =================================
|
|
310
322
|
console.log(
|
|
311
|
-
`Document count in "${dbNameResult}" database is
|
|
323
|
+
`Document count in "${dbNameResult}" database is ${documentCount}.`
|
|
312
324
|
);
|
|
313
325
|
|
|
314
326
|
// 5. Get zebra document out of the database by document id ===================
|
|
@@ -318,10 +330,10 @@ const getInfoFromExistingDatabase = async () => {
|
|
|
318
330
|
const documentAboutZebra = await client.getDocument(getDocParams);
|
|
319
331
|
|
|
320
332
|
// result object is defined as a Document here:
|
|
321
|
-
const result = documentAboutZebra
|
|
333
|
+
const { result } = documentAboutZebra;
|
|
322
334
|
|
|
323
335
|
console.log(
|
|
324
|
-
|
|
336
|
+
`Document retrieved from database:\n${JSON.stringify(result, null, 2)}`
|
|
325
337
|
);
|
|
326
338
|
};
|
|
327
339
|
|
|
@@ -394,7 +406,7 @@ const createDb = client
|
|
|
394
406
|
.catch((err) => {
|
|
395
407
|
if (err.code === 412) {
|
|
396
408
|
console.log(
|
|
397
|
-
|
|
409
|
+
`Cannot create "${exampleDbName}" database, it already exists.`
|
|
398
410
|
);
|
|
399
411
|
}
|
|
400
412
|
});
|
|
@@ -457,7 +469,7 @@ const createDbAndDoc = async () => {
|
|
|
457
469
|
} catch (err) {
|
|
458
470
|
if (err.code === 412) {
|
|
459
471
|
console.log(
|
|
460
|
-
|
|
472
|
+
`Cannot create "${exampleDbName}" database, it already exists.`
|
|
461
473
|
);
|
|
462
474
|
}
|
|
463
475
|
}
|
|
@@ -569,7 +581,7 @@ client
|
|
|
569
581
|
|
|
570
582
|
// Update the document in the database
|
|
571
583
|
client
|
|
572
|
-
.postDocument({ db: exampleDbName, document
|
|
584
|
+
.postDocument({ db: exampleDbName, document })
|
|
573
585
|
// Note: for request byte stream use:
|
|
574
586
|
// .postDocument(
|
|
575
587
|
// {db: exampleDbName, document: documentAsByteStream}
|
|
@@ -578,17 +590,15 @@ client
|
|
|
578
590
|
// Keeping track with the revision number of the document object:
|
|
579
591
|
document._rev = res.result.rev;
|
|
580
592
|
console.log(
|
|
581
|
-
|
|
593
|
+
`You have updated the document:\n${JSON.stringify(document, null, 2)}`
|
|
582
594
|
);
|
|
583
595
|
});
|
|
584
596
|
})
|
|
585
597
|
.catch((err) => {
|
|
586
598
|
if (err.code === 404) {
|
|
587
599
|
console.log(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
'" database or the "example" ' +
|
|
591
|
-
'document was not found.'
|
|
600
|
+
`Cannot update document because either "${exampleDbName}" database or the "example" ` +
|
|
601
|
+
`document was not found.`
|
|
592
602
|
);
|
|
593
603
|
}
|
|
594
604
|
});
|
|
@@ -637,7 +647,7 @@ const updateDoc = async () => {
|
|
|
637
647
|
document._rev = (
|
|
638
648
|
await client.postDocument({
|
|
639
649
|
db: exampleDbName,
|
|
640
|
-
document
|
|
650
|
+
document,
|
|
641
651
|
})
|
|
642
652
|
).result.rev;
|
|
643
653
|
|
|
@@ -650,15 +660,13 @@ const updateDoc = async () => {
|
|
|
650
660
|
// ).result.rev;
|
|
651
661
|
|
|
652
662
|
console.log(
|
|
653
|
-
|
|
663
|
+
`You have updated the document:\n${JSON.stringify(document, null, 2)}`
|
|
654
664
|
);
|
|
655
665
|
} catch (err) {
|
|
656
666
|
if (err.code === 404) {
|
|
657
667
|
console.log(
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
'" database or the "example" ' +
|
|
661
|
-
'document was not found.'
|
|
668
|
+
`Cannot update document because either "${exampleDbName}" database or the "example" ` +
|
|
669
|
+
`document was not found.`
|
|
662
670
|
);
|
|
663
671
|
}
|
|
664
672
|
}
|
|
@@ -744,10 +752,8 @@ client
|
|
|
744
752
|
.catch((err) => {
|
|
745
753
|
if (err.code === 404) {
|
|
746
754
|
console.log(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
'" database or the "example" ' +
|
|
750
|
-
'document was not found.'
|
|
755
|
+
`Cannot delete document because either "${exampleDbName}" database or the "example" ` +
|
|
756
|
+
`document was not found.`
|
|
751
757
|
);
|
|
752
758
|
}
|
|
753
759
|
});
|
|
@@ -789,10 +795,8 @@ const deleteDoc = async () => {
|
|
|
789
795
|
} catch (err) {
|
|
790
796
|
if (err.code === 404) {
|
|
791
797
|
console.log(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
'" database or the "example" ' +
|
|
795
|
-
'document was not found.'
|
|
798
|
+
`Cannot delete document because either "${exampleDbName}" database or the "example" ` +
|
|
799
|
+
`document was not found.`
|
|
796
800
|
);
|
|
797
801
|
}
|
|
798
802
|
}
|
|
@@ -38,6 +38,7 @@ export declare class CouchdbSessionAuthenticator extends Authenticator {
|
|
|
38
38
|
protected tokenManager: SessionTokenManager;
|
|
39
39
|
protected requiredOptions: ['username', 'password'];
|
|
40
40
|
private tokenOptions;
|
|
41
|
+
static readonly AUTHTYPE_COUCHDB_SESSION = "COUCHDB_SESSION";
|
|
41
42
|
/**
|
|
42
43
|
* Create a new CouchdbSessionAuthenticator instance.
|
|
43
44
|
*
|
|
@@ -64,4 +65,10 @@ export declare class CouchdbSessionAuthenticator extends Authenticator {
|
|
|
64
65
|
* @param {object} userOptions - Configuration values for a `request` service.
|
|
65
66
|
*/
|
|
66
67
|
configure(userOptions: UserOptions): void;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the authenticator's type ('COUCHDB_SESSION').
|
|
70
|
+
*
|
|
71
|
+
* @returns a string that indicates the authenticator's type
|
|
72
|
+
*/
|
|
73
|
+
authenticationType(): string;
|
|
67
74
|
}
|
|
@@ -29,6 +29,17 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
29
29
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
30
|
};
|
|
31
31
|
})();
|
|
32
|
+
var __assign = (this && this.__assign) || function () {
|
|
33
|
+
__assign = Object.assign || function(t) {
|
|
34
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
35
|
+
s = arguments[i];
|
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
37
|
+
t[p] = s[p];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
};
|
|
41
|
+
return __assign.apply(this, arguments);
|
|
42
|
+
};
|
|
32
43
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
44
|
exports.CouchdbSessionAuthenticator = void 0;
|
|
34
45
|
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
|
|
@@ -57,8 +68,8 @@ var CouchdbSessionAuthenticator = /** @class */ (function (_super) {
|
|
|
57
68
|
*/
|
|
58
69
|
function CouchdbSessionAuthenticator(options) {
|
|
59
70
|
var _this = _super.call(this) || this;
|
|
60
|
-
ibm_cloud_sdk_core_1.validateInput(options, _this.requiredOptions);
|
|
61
|
-
_this.tokenOptions =
|
|
71
|
+
(0, ibm_cloud_sdk_core_1.validateInput)(options, _this.requiredOptions);
|
|
72
|
+
_this.tokenOptions = __assign({}, options);
|
|
62
73
|
return _this;
|
|
63
74
|
}
|
|
64
75
|
/**
|
|
@@ -90,13 +101,13 @@ var CouchdbSessionAuthenticator = /** @class */ (function (_super) {
|
|
|
90
101
|
cookieJar.cloudantPatch = true;
|
|
91
102
|
// Replace the store's updateCookie function with one that applies a patch to newCookie
|
|
92
103
|
var originalUpdateCookieFn_1 = cookieJar.store.updateCookie;
|
|
93
|
-
cookieJar.store.updateCookie = function (oldCookie, newCookie, cb) {
|
|
104
|
+
cookieJar.store.updateCookie = function updateCookie(oldCookie, newCookie, cb) {
|
|
94
105
|
// Add current time as an update timestamp to the newCookie
|
|
95
106
|
newCookie.cloudantPatchUpdateTime = new Date();
|
|
96
107
|
// Replace the cookie's expiryTime function with one that uses cloudantPatchUpdateTime
|
|
97
108
|
// in place of creation time to check the expiry.
|
|
98
109
|
var originalExpiryTimeFn = newCookie.expiryTime;
|
|
99
|
-
newCookie.expiryTime = function (now) {
|
|
110
|
+
newCookie.expiryTime = function expiryTime(now) {
|
|
100
111
|
// The original expiryTime check is relative to a time in this order:
|
|
101
112
|
// 1. supplied now argument
|
|
102
113
|
// 2. this.creation (original cookie creation time)
|
|
@@ -120,6 +131,16 @@ var CouchdbSessionAuthenticator = /** @class */ (function (_super) {
|
|
|
120
131
|
// Set the token manager
|
|
121
132
|
this.tokenManager = new sessionTokenManager_1.SessionTokenManager(this.tokenOptions);
|
|
122
133
|
};
|
|
134
|
+
/**
|
|
135
|
+
* Returns the authenticator's type ('COUCHDB_SESSION').
|
|
136
|
+
*
|
|
137
|
+
* @returns a string that indicates the authenticator's type
|
|
138
|
+
*/
|
|
139
|
+
// eslint-disable-next-line class-methods-use-this
|
|
140
|
+
CouchdbSessionAuthenticator.prototype.authenticationType = function () {
|
|
141
|
+
return CouchdbSessionAuthenticator.AUTHTYPE_COUCHDB_SESSION;
|
|
142
|
+
};
|
|
143
|
+
CouchdbSessionAuthenticator.AUTHTYPE_COUCHDB_SESSION = 'COUCHDB_SESSION';
|
|
123
144
|
return CouchdbSessionAuthenticator;
|
|
124
145
|
}(ibm_cloud_sdk_core_1.Authenticator));
|
|
125
146
|
exports.CouchdbSessionAuthenticator = CouchdbSessionAuthenticator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"couchdbSessionAuthenticator.js","sourceRoot":"","sources":["../../auth/couchdbSessionAuthenticator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"couchdbSessionAuthenticator.js","sourceRoot":"","sources":["../../auth/couchdbSessionAuthenticator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yDAA+E;AAC/E,6DAG+B;AAU/B;;;;;;;;;;;GAWG;AACH;IAAiD,+CAAa;IAS5D;;;;;;;OAOG;IACH,qCAAY,OAA2C;QAAvD,YACE,iBAAO,SAGR;QAFC,IAAA,kCAAa,EAAC,OAAO,EAAE,KAAI,CAAC,eAAe,CAAC,CAAC;QAC7C,KAAI,CAAC,YAAY,gBAAQ,OAAO,CAAE,CAAC;;IACrC,CAAC;IAED;;;;;;;;OAQG;IACI,kDAAY,GAAnB,UAAoB,cAAsB;QACxC,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;IAED;;;;;OAKG;IACI,+CAAS,GAAhB,UAAiB,WAAwB;QACvC,oBAAoB;QACpB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;QAE9C,+EAA+E;QAC/E,yCAAyC;QACzC,IAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;QACxC,IAAI,SAAS,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE;YACzC,wBAAwB;YACxB,SAAS,CAAC,aAAa,GAAG,IAAI,CAAC;YAC/B,uFAAuF;YACvF,IAAM,wBAAsB,GAAG,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC;YAC5D,SAAS,CAAC,KAAK,CAAC,YAAY,GAAG,SAAS,YAAY,CAClD,SAAS,EACT,SAAS,EACT,EAAE;gBAEF,2DAA2D;gBAC3D,SAAS,CAAC,uBAAuB,GAAG,IAAI,IAAI,EAAE,CAAC;gBAC/C,sFAAsF;gBACtF,iDAAiD;gBACjD,IAAM,oBAAoB,GAAG,SAAS,CAAC,UAAU,CAAC;gBAClD,SAAS,CAAC,UAAU,GAAG,SAAS,UAAU,CAAC,GAAG;oBAC5C,qEAAqE;oBACrE,2BAA2B;oBAC3B,mDAAmD;oBACnD,kBAAkB;oBAClB,uGAAuG;oBACvG,uDAAuD;oBACvD,OAAO,oBAAoB,CAAC,IAAI,CAC9B,SAAS,EACT,SAAS,CAAC,uBAAuB,IAAI,GAAG,CACzC,CAAC;gBACJ,CAAC,CAAC;gBACF,oGAAoG;gBACpG,uGAAuG;gBACvG,+CAA+C;gBAC/C,IAAI,wBAAsB,EAAE;oBAC1B,wBAAsB,CAAC,IAAI,CACzB,SAAS,CAAC,KAAK,EACf,SAAS,EACT,SAAS,EACT,EAAE,CACH,CAAC;iBACH;qBAAM;oBACL,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,CAAC;iBAChE;YACH,CAAC,CAAC;SACH;QACD,8BAA8B;QAE9B,wBAAwB;QACxB,IAAI,CAAC,YAAY,GAAG,IAAI,yCAAmB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjE,CAAC;IAED;;;;OAIG;IACH,kDAAkD;IAC3C,wDAAkB,GAAzB;QACE,OAAO,2BAA2B,CAAC,wBAAwB,CAAC;IAC9D,CAAC;IAlGe,oDAAwB,GAAG,iBAAiB,CAAC;IAmG/D,kCAAC;CAAA,AA1GD,CAAiD,kCAAa,GA0G7D;AA1GY,kEAA2B"}
|
|
@@ -64,7 +64,7 @@ var SessionTokenManager = /** @class */ (function (_super) {
|
|
|
64
64
|
'serviceUrl',
|
|
65
65
|
'jar',
|
|
66
66
|
];
|
|
67
|
-
ibm_cloud_sdk_core_1.validateInput(options, _this.requiredOptions);
|
|
67
|
+
(0, ibm_cloud_sdk_core_1.validateInput)(options, _this.requiredOptions);
|
|
68
68
|
_this.options = options;
|
|
69
69
|
_this.tokenName = 'AuthSession';
|
|
70
70
|
return _this;
|
|
@@ -75,6 +75,7 @@ var SessionTokenManager = /** @class */ (function (_super) {
|
|
|
75
75
|
* @param {OutgoingHttpHeaders} headers - the new set of headers as an object
|
|
76
76
|
* @returns {Error}
|
|
77
77
|
*/
|
|
78
|
+
// eslint-disable-next-line class-methods-use-this
|
|
78
79
|
SessionTokenManager.prototype.setHeaders = function (headers) {
|
|
79
80
|
var errMsg = 'During CouchDB Session Authentication only `request` service headers are in use';
|
|
80
81
|
throw new Error(errMsg);
|
|
@@ -92,7 +93,7 @@ var SessionTokenManager = /** @class */ (function (_super) {
|
|
|
92
93
|
var parameters = {
|
|
93
94
|
options: {
|
|
94
95
|
headers: this.options.headers,
|
|
95
|
-
url: this.options.serviceUrl
|
|
96
|
+
url: "".concat(this.options.serviceUrl, "/_session"),
|
|
96
97
|
method: 'POST',
|
|
97
98
|
body: {
|
|
98
99
|
username: this.options.username,
|
|
@@ -120,7 +121,7 @@ var SessionTokenManager = /** @class */ (function (_super) {
|
|
|
120
121
|
var sessionToken = null;
|
|
121
122
|
var expireTime = null;
|
|
122
123
|
var refreshTime = null;
|
|
123
|
-
for (var i = 0; i < sessionCookie.length && sessionToken == null; i
|
|
124
|
+
for (var i = 0; i < sessionCookie.length && sessionToken == null; i += 1) {
|
|
124
125
|
sessionToken = new RegExp('AuthSession=([^;]*);').exec(sessionCookie[i]);
|
|
125
126
|
if (sessionToken != null) {
|
|
126
127
|
expireTime = new RegExp('.*Expires=([^;]*);').exec(sessionCookie[i]);
|
|
@@ -139,16 +140,16 @@ var SessionTokenManager = /** @class */ (function (_super) {
|
|
|
139
140
|
this.refreshTime = 0;
|
|
140
141
|
}
|
|
141
142
|
else {
|
|
142
|
-
this.expireTime = Number(refreshTime[1]) + ibm_cloud_sdk_core_1.getCurrentTime();
|
|
143
|
+
this.expireTime = Number(refreshTime[1]) + (0, ibm_cloud_sdk_core_1.getCurrentTime)();
|
|
143
144
|
this.refreshTime =
|
|
144
|
-
Number(refreshTime[1]) * fractionOfTtl + ibm_cloud_sdk_core_1.getCurrentTime();
|
|
145
|
+
Number(refreshTime[1]) * fractionOfTtl + (0, ibm_cloud_sdk_core_1.getCurrentTime)();
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
else {
|
|
148
149
|
// Store expire time in seconds
|
|
149
150
|
this.expireTime = Date.parse(expireTime[1]) / 1000;
|
|
150
151
|
// Set refresh time from the expire time
|
|
151
|
-
var timeToLive = this.expireTime - ibm_cloud_sdk_core_1.getCurrentTime();
|
|
152
|
+
var timeToLive = this.expireTime - (0, ibm_cloud_sdk_core_1.getCurrentTime)();
|
|
152
153
|
this.refreshTime = this.expireTime - timeToLive * (1.0 - fractionOfTtl);
|
|
153
154
|
}
|
|
154
155
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionTokenManager.js","sourceRoot":"","sources":["../../auth/sessionTokenManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;AAGH,yDAK4B;AAU5B;;;;;GAKG;AACH;IAAyC,uCAAY;
|
|
1
|
+
{"version":3,"file":"sessionTokenManager.js","sourceRoot":"","sources":["../../auth/sessionTokenManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;AAGH,yDAK4B;AAU5B;;;;;GAKG;AACH;IAAyC,uCAAY;IAYnD;;;;;;;;;;;;;;;OAeG;IACH,6BAAY,OAAmC;QAA/C,YACE,kBAAM,OAAO,CAAC,SAMf;QAlCS,qBAAe,GAAa;YACpC,UAAU;YACV,UAAU;YACV,YAAY;YACZ,KAAK;SACN,CAAC;QAyBA,IAAA,kCAAa,EAAC,OAAO,EAAE,KAAI,CAAC,eAAe,CAAC,CAAC;QAE7C,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,KAAI,CAAC,SAAS,GAAG,aAAa,CAAC;;IACjC,CAAC;IAED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