@ibm-cloud/cloudant 0.0.16 → 0.0.20
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 +17 -5
- package/auth/couchdbSessionAuthenticator.js +38 -1
- package/auth/couchdbSessionAuthenticator.js.map +1 -1
- package/auth/sessionTokenManager.d.ts +1 -1
- package/auth/sessionTokenManager.js +6 -6
- package/auth/sessionTokenManager.js.map +1 -1
- package/cloudant/v1.d.ts +113 -155
- package/cloudant/v1.js +520 -681
- package/cloudant/v1.js.map +1 -1
- package/lib/cloudantBaseService.d.ts +4 -0
- package/lib/cloudantBaseService.js +97 -1
- package/lib/cloudantBaseService.js.map +1 -1
- package/lib/getAuthenticatorFromEnvCloudantExtension.js +2 -2
- 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.20
|
|
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)
|
|
@@ -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
|
|
|
@@ -57,7 +57,7 @@ var CouchdbSessionAuthenticator = /** @class */ (function (_super) {
|
|
|
57
57
|
*/
|
|
58
58
|
function CouchdbSessionAuthenticator(options) {
|
|
59
59
|
var _this = _super.call(this) || this;
|
|
60
|
-
ibm_cloud_sdk_core_1.validateInput(options, _this.requiredOptions);
|
|
60
|
+
(0, ibm_cloud_sdk_core_1.validateInput)(options, _this.requiredOptions);
|
|
61
61
|
_this.tokenOptions = Object.assign({}, options);
|
|
62
62
|
return _this;
|
|
63
63
|
}
|
|
@@ -80,7 +80,44 @@ var CouchdbSessionAuthenticator = /** @class */ (function (_super) {
|
|
|
80
80
|
* @param {object} userOptions - Configuration values for a `request` service.
|
|
81
81
|
*/
|
|
82
82
|
CouchdbSessionAuthenticator.prototype.configure = function (userOptions) {
|
|
83
|
+
// Merge the options
|
|
83
84
|
Object.assign(this.tokenOptions, userOptions);
|
|
85
|
+
// START monkey patch for https://github.com/salesforce/tough-cookie/issues/154
|
|
86
|
+
// Check if we've already patched the jar
|
|
87
|
+
var cookieJar = this.tokenOptions.jar;
|
|
88
|
+
if (cookieJar && !cookieJar.cloudantPatch) {
|
|
89
|
+
// Set the patching flag
|
|
90
|
+
cookieJar.cloudantPatch = true;
|
|
91
|
+
// Replace the store's updateCookie function with one that applies a patch to newCookie
|
|
92
|
+
var originalUpdateCookieFn_1 = cookieJar.store.updateCookie;
|
|
93
|
+
cookieJar.store.updateCookie = function (oldCookie, newCookie, cb) {
|
|
94
|
+
// Add current time as an update timestamp to the newCookie
|
|
95
|
+
newCookie.cloudantPatchUpdateTime = new Date();
|
|
96
|
+
// Replace the cookie's expiryTime function with one that uses cloudantPatchUpdateTime
|
|
97
|
+
// in place of creation time to check the expiry.
|
|
98
|
+
var originalExpiryTimeFn = newCookie.expiryTime;
|
|
99
|
+
newCookie.expiryTime = function (now) {
|
|
100
|
+
// The original expiryTime check is relative to a time in this order:
|
|
101
|
+
// 1. supplied now argument
|
|
102
|
+
// 2. this.creation (original cookie creation time)
|
|
103
|
+
// 3. current time
|
|
104
|
+
// This patch replaces 2 with an expiry check relative to the cloudantPatchUpdateTime if set instead of
|
|
105
|
+
// the creation time by passing it as the now argument.
|
|
106
|
+
return originalExpiryTimeFn.call(newCookie, newCookie.cloudantPatchUpdateTime || now);
|
|
107
|
+
};
|
|
108
|
+
// Finally delegate back to the original update function or the fallback put (which is set by Cookie
|
|
109
|
+
// when an update function is not present on the store). Since we always set an update function for our
|
|
110
|
+
// patch we need to also provide that fallback.
|
|
111
|
+
if (originalUpdateCookieFn_1) {
|
|
112
|
+
originalUpdateCookieFn_1.call(cookieJar.store, oldCookie, newCookie, cb);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
cookieJar.store.putCookie.call(cookieJar.store, newCookie, cb);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// END cookie jar monkey patch
|
|
120
|
+
// Set the token manager
|
|
84
121
|
this.tokenManager = new sessionTokenManager_1.SessionTokenManager(this.tokenOptions);
|
|
85
122
|
};
|
|
86
123
|
return CouchdbSessionAuthenticator;
|
|
@@ -1 +1 @@
|
|
|
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;IAK5D;;;;;;;OAOG;IACH,qCAAY,OAA2C;QAAvD,YACE,iBAAO,SAGR;QAFC,kCAAa,
|
|
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;IAK5D;;;;;;;OAOG;IACH,qCAAY,OAA2C;QAAvD,YACE,iBAAO,SAGR;QAFC,IAAA,kCAAa,EAAC,OAAO,EAAE,KAAI,CAAC,eAAe,CAAC,CAAC;QAC7C,KAAI,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;;IACjD,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;QACv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AAG,IAAI,yCAAmB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACjE,CAAC;IACH,kCAAC;AAAD,CAAC,AAxFD,CAAiD,kCAAa,GAwF7D;AAxFY,kEAA2B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* © Copyright IBM Corporation 2020. All Rights Reserved.
|
|
3
|
+
* © Copyright IBM Corporation 2020, 2021. All Rights Reserved.
|
|
4
4
|
*
|
|
5
5
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
* you may not use this file except in compliance with the License.
|
|
@@ -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;
|
|
@@ -113,7 +113,7 @@ var SessionTokenManager = /** @class */ (function (_super) {
|
|
|
113
113
|
*/
|
|
114
114
|
SessionTokenManager.prototype.saveTokenInfo = function (tokenResponse) {
|
|
115
115
|
var sessionCookie = tokenResponse.headers['set-cookie'];
|
|
116
|
-
if (!(sessionCookie
|
|
116
|
+
if (!Array.isArray(sessionCookie)) {
|
|
117
117
|
var err = 'Set-Cookie header not present in response';
|
|
118
118
|
throw new Error(err);
|
|
119
119
|
}
|
|
@@ -139,16 +139,16 @@ var SessionTokenManager = /** @class */ (function (_super) {
|
|
|
139
139
|
this.refreshTime = 0;
|
|
140
140
|
}
|
|
141
141
|
else {
|
|
142
|
-
this.expireTime = Number(refreshTime[1]) + ibm_cloud_sdk_core_1.getCurrentTime();
|
|
142
|
+
this.expireTime = Number(refreshTime[1]) + (0, ibm_cloud_sdk_core_1.getCurrentTime)();
|
|
143
143
|
this.refreshTime =
|
|
144
|
-
Number(refreshTime[1]) * fractionOfTtl + ibm_cloud_sdk_core_1.getCurrentTime();
|
|
144
|
+
Number(refreshTime[1]) * fractionOfTtl + (0, ibm_cloud_sdk_core_1.getCurrentTime)();
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
else {
|
|
148
148
|
// Store expire time in seconds
|
|
149
149
|
this.expireTime = Date.parse(expireTime[1]) / 1000;
|
|
150
150
|
// Set refresh time from the expire time
|
|
151
|
-
var timeToLive = this.expireTime - ibm_cloud_sdk_core_1.getCurrentTime();
|
|
151
|
+
var timeToLive = this.expireTime - (0, ibm_cloud_sdk_core_1.getCurrentTime)();
|
|
152
152
|
this.refreshTime = this.expireTime - timeToLive * (1.0 - fractionOfTtl);
|
|
153
153
|
}
|
|
154
154
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionTokenManager.js","sourceRoot":"","sources":["../../auth/sessionTokenManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;AAGH,yDAK4B;AAU5B;;;;;GAKG;AACH;IAAyC,uCAAY;IAUnD;;;;;;;;;;;;;;;OAeG;IACH,6BAAY,OAAmC;QAA/C,YACE,kBAAM,OAAO,CAAC,SAMf;QAhCS,qBAAe,GAAa;YACpC,UAAU;YACV,UAAU;YACV,YAAY;YACZ,KAAK;SACN,CAAC;QAuBA,kCAAa,
|
|
1
|
+
{"version":3,"file":"sessionTokenManager.js","sourceRoot":"","sources":["../../auth/sessionTokenManager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;AAGH,yDAK4B;AAU5B;;;;;GAKG;AACH;IAAyC,uCAAY;IAUnD;;;;;;;;;;;;;;;OAeG;IACH,6BAAY,OAAmC;QAA/C,YACE,kBAAM,OAAO,CAAC,SAMf;QAhCS,qBAAe,GAAa;YACpC,UAAU;YACV,UAAU;YACV,YAAY;YACZ,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