@cloudant/couchbackup 2.11.1-SNAPSHOT-261 → 2.11.1-SNAPSHOT-264
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/includes/request.js +24 -34
- package/package.json +2 -3
package/includes/request.js
CHANGED
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
const pkg = require('../package.json');
|
|
17
17
|
const { CloudantV1, CouchdbSessionAuthenticator } = require('@ibm-cloud/cloudant');
|
|
18
18
|
const { IamAuthenticator, NoAuthAuthenticator } = require('ibm-cloud-sdk-core');
|
|
19
|
-
const retryPlugin = require('retry-axios');
|
|
20
19
|
const debug = require('debug')('couchbackup:request');
|
|
21
20
|
|
|
22
21
|
const userAgent = 'couchbackup-cloudant/' + pkg.version + ' (Node.js ' +
|
|
@@ -25,7 +24,7 @@ const userAgent = 'couchbackup-cloudant/' + pkg.version + ' (Node.js ' +
|
|
|
25
24
|
// An interceptor function to help augment error bodies with a little
|
|
26
25
|
// extra information so we can continue to use consistent messaging
|
|
27
26
|
// after the ugprade to @ibm-cloud/cloudant
|
|
28
|
-
|
|
27
|
+
function errorHelper(err) {
|
|
29
28
|
debug('Entering error helper interceptor');
|
|
30
29
|
let method;
|
|
31
30
|
let requestUrl;
|
|
@@ -75,7 +74,18 @@ const errorHelper = async function(err) {
|
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
return Promise.reject(err);
|
|
78
|
-
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Interceptor function to add the User-Agent header.
|
|
80
|
+
// An interceptor is used because setting UA in headers
|
|
81
|
+
// option during client initialization means it gets overwritten
|
|
82
|
+
// by the default value during a request.
|
|
83
|
+
// This interceptor is further along the chain and able to
|
|
84
|
+
// replace the default value.
|
|
85
|
+
function userAgentHelper(requestConfig) {
|
|
86
|
+
requestConfig.headers['User-Agent'] = userAgent;
|
|
87
|
+
return requestConfig;
|
|
88
|
+
}
|
|
79
89
|
|
|
80
90
|
function newSimpleClient(rawUrl, opts) {
|
|
81
91
|
const url = new URL(rawUrl);
|
|
@@ -120,43 +130,23 @@ function newSimpleClient(rawUrl, opts) {
|
|
|
120
130
|
function newClient(rawUrl, opts) {
|
|
121
131
|
const { service, dbName, actUrl } = newSimpleClient(rawUrl, opts);
|
|
122
132
|
const authenticator = service.getAuthenticator();
|
|
123
|
-
// Configure retries
|
|
124
|
-
const maxRetries = 2; // for 3 total attempts
|
|
125
|
-
service.getHttpClient().defaults.raxConfig = {
|
|
126
|
-
// retries for status codes
|
|
127
|
-
retry: maxRetries,
|
|
128
|
-
// retries for non-response e.g. ETIMEDOUT
|
|
129
|
-
noResponseRetries: maxRetries,
|
|
130
|
-
backoffType: 'exponential',
|
|
131
|
-
httpMethodsToRetry: ['GET', 'HEAD', 'POST'],
|
|
132
|
-
statusCodesToRetry: [
|
|
133
|
-
[429, 429],
|
|
134
|
-
[500, 599]
|
|
135
|
-
],
|
|
136
|
-
shouldRetry: err => {
|
|
137
|
-
const cfg = retryPlugin.getConfig(err);
|
|
138
|
-
// cap at max retries regardless of response/non-response type
|
|
139
|
-
if (cfg.currentRetryAttempt >= maxRetries) {
|
|
140
|
-
return false;
|
|
141
|
-
} else {
|
|
142
|
-
return retryPlugin.shouldRetryRequest(err);
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
instance: service.getHttpClient()
|
|
146
|
-
};
|
|
147
|
-
retryPlugin.attach(service.getHttpClient());
|
|
148
133
|
|
|
134
|
+
// Add interceptors
|
|
135
|
+
// Request interceptor to set the User-Agent header
|
|
136
|
+
// Response interceptor to put URLs in error messages
|
|
137
|
+
// Add for the token manager if present
|
|
149
138
|
if (authenticator.tokenManager && authenticator.tokenManager.requestWrapperInstance) {
|
|
139
|
+
authenticator.tokenManager.requestWrapperInstance.axiosInstance.interceptors.request.use(userAgentHelper, null);
|
|
150
140
|
authenticator.tokenManager.requestWrapperInstance.axiosInstance.interceptors.response.use(null, errorHelper);
|
|
151
141
|
}
|
|
152
|
-
//
|
|
142
|
+
// and add for the client
|
|
143
|
+
service.getHttpClient().interceptors.request.use(userAgentHelper, null);
|
|
153
144
|
service.getHttpClient().interceptors.response.use(null, errorHelper);
|
|
154
145
|
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}, null);
|
|
146
|
+
// Configure retries
|
|
147
|
+
// Note: this MUST happen last after all other interceptors have been registered
|
|
148
|
+
const maxRetries = 2; // for 3 total attempts
|
|
149
|
+
service.enableRetries({ maxRetries });
|
|
160
150
|
|
|
161
151
|
return { service, dbName, url: actUrl.toString() };
|
|
162
152
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudant/couchbackup",
|
|
3
|
-
"version": "2.11.1-SNAPSHOT-
|
|
3
|
+
"version": "2.11.1-SNAPSHOT-264",
|
|
4
4
|
"description": "CouchBackup - command-line backup utility for Cloudant/CouchDB",
|
|
5
5
|
"homepage": "https://github.com/IBM/couchbackup",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"ibm-cloud-sdk-core": "^5.0.2",
|
|
32
|
-
"retry-axios": "^2.6.0",
|
|
33
32
|
"axios": "^1.7.4"
|
|
34
33
|
},
|
|
35
34
|
"main": "app.js",
|
|
@@ -50,7 +49,7 @@
|
|
|
50
49
|
"mocha": "10.8.2",
|
|
51
50
|
"nock": "13.5.6",
|
|
52
51
|
"tail": "2.2.6",
|
|
53
|
-
"uuid": "11.0.
|
|
52
|
+
"uuid": "11.0.3"
|
|
54
53
|
},
|
|
55
54
|
"scripts": {
|
|
56
55
|
"lint": "eslint --ignore-path .gitignore .",
|