@cloudant/couchbackup 2.11.0-249 → 2.11.1-266
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 +1 -1
- package/includes/request.js +34 -50
- package/package.json +7 -8
package/README.md
CHANGED
package/includes/request.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright © 2017,
|
|
1
|
+
// Copyright © 2017, 2024 IBM Corp. All rights reserved.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -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;
|
|
@@ -38,30 +37,24 @@ const errorHelper = async function(err) {
|
|
|
38
37
|
}
|
|
39
38
|
debug('Applying response error message with status, url, and method');
|
|
40
39
|
// Override the status text with an improved message
|
|
41
|
-
let errorMsg = `${err.response.status} ${
|
|
42
|
-
`${method} ${requestUrl}`;
|
|
40
|
+
let errorMsg = `${err.response.status} ${method} ${requestUrl}`;
|
|
43
41
|
if (err.response.data) {
|
|
44
42
|
debug('Found response data');
|
|
45
43
|
// Check if we have a JSON response and try to get the error/reason
|
|
46
44
|
if (err.response.headers['content-type'] === 'application/json') {
|
|
47
45
|
debug('Response data is JSON');
|
|
48
|
-
// Append the
|
|
49
|
-
if (err.response.data.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
errorMsg += ` - Error: ${err.response.data.error}`;
|
|
53
|
-
if (err.response.data.reason) {
|
|
54
|
-
debug('Augmenting error message with reason property');
|
|
55
|
-
errorMsg += `, Reason: ${err.response.data.reason}`;
|
|
56
|
-
}
|
|
46
|
+
// Append the 'errors' message if available
|
|
47
|
+
if (err.response.data.errors && err.response.data.errors.length > 0) {
|
|
48
|
+
const originalError = err.response.data.errors[0];
|
|
49
|
+
originalError.message = `${errorMsg} - Error: ${originalError.message}`;
|
|
57
50
|
}
|
|
58
51
|
} else {
|
|
59
52
|
errorMsg += err.response.data;
|
|
53
|
+
// Set a new message for use by the node-sdk-core
|
|
54
|
+
// We use the errors array because it gets processed
|
|
55
|
+
// ahead of all other service errors.
|
|
56
|
+
err.response.data.errors = [{ message: errorMsg }];
|
|
60
57
|
}
|
|
61
|
-
// Set a new message for use by the node-sdk-core
|
|
62
|
-
// We use the errors array because it gets processed
|
|
63
|
-
// ahead of all other service errors.
|
|
64
|
-
err.response.data.errors = [{ message: errorMsg }];
|
|
65
58
|
}
|
|
66
59
|
} else if (err.request) {
|
|
67
60
|
debug('Error did not include a response');
|
|
@@ -75,7 +68,18 @@ const errorHelper = async function(err) {
|
|
|
75
68
|
}
|
|
76
69
|
}
|
|
77
70
|
return Promise.reject(err);
|
|
78
|
-
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Interceptor function to add the User-Agent header.
|
|
74
|
+
// An interceptor is used because setting UA in headers
|
|
75
|
+
// option during client initialization means it gets overwritten
|
|
76
|
+
// by the default value during a request.
|
|
77
|
+
// This interceptor is further along the chain and able to
|
|
78
|
+
// replace the default value.
|
|
79
|
+
function userAgentHelper(requestConfig) {
|
|
80
|
+
requestConfig.headers['User-Agent'] = userAgent;
|
|
81
|
+
return requestConfig;
|
|
82
|
+
}
|
|
79
83
|
|
|
80
84
|
function newSimpleClient(rawUrl, opts) {
|
|
81
85
|
const url = new URL(rawUrl);
|
|
@@ -120,43 +124,23 @@ function newSimpleClient(rawUrl, opts) {
|
|
|
120
124
|
function newClient(rawUrl, opts) {
|
|
121
125
|
const { service, dbName, actUrl } = newSimpleClient(rawUrl, opts);
|
|
122
126
|
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
127
|
|
|
128
|
+
// Add interceptors
|
|
129
|
+
// Request interceptor to set the User-Agent header
|
|
130
|
+
// Response interceptor to put URLs in error messages
|
|
131
|
+
// Add for the token manager if present
|
|
149
132
|
if (authenticator.tokenManager && authenticator.tokenManager.requestWrapperInstance) {
|
|
133
|
+
authenticator.tokenManager.requestWrapperInstance.axiosInstance.interceptors.request.use(userAgentHelper, null);
|
|
150
134
|
authenticator.tokenManager.requestWrapperInstance.axiosInstance.interceptors.response.use(null, errorHelper);
|
|
151
135
|
}
|
|
152
|
-
//
|
|
136
|
+
// and add for the client
|
|
137
|
+
service.getHttpClient().interceptors.request.use(userAgentHelper, null);
|
|
153
138
|
service.getHttpClient().interceptors.response.use(null, errorHelper);
|
|
154
139
|
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}, null);
|
|
140
|
+
// Configure retries
|
|
141
|
+
// Note: this MUST happen last after all other interceptors have been registered
|
|
142
|
+
const maxRetries = 2; // for 3 total attempts
|
|
143
|
+
service.enableRetries({ maxRetries });
|
|
160
144
|
|
|
161
145
|
return { service, dbName, url: actUrl.toString() };
|
|
162
146
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudant/couchbackup",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.1-266",
|
|
4
4
|
"description": "CouchBackup - command-line backup utility for Cloudant/CouchDB",
|
|
5
5
|
"homepage": "https://github.com/IBM/couchbackup",
|
|
6
6
|
"repository": {
|
|
@@ -20,16 +20,15 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": "^18 || ^20"
|
|
23
|
+
"node": "^18 || ^20 || ^22"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@ibm-cloud/cloudant": "0.
|
|
26
|
+
"@ibm-cloud/cloudant": "0.11.0",
|
|
27
27
|
"commander": "12.1.0",
|
|
28
28
|
"debug": "4.3.7"
|
|
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",
|
|
@@ -42,15 +41,15 @@
|
|
|
42
41
|
"eslint-config-semistandard": "17.0.0",
|
|
43
42
|
"eslint-config-standard": "17.1.0",
|
|
44
43
|
"eslint-plugin-header": "3.1.1",
|
|
45
|
-
"eslint-plugin-import": "2.
|
|
44
|
+
"eslint-plugin-import": "2.31.0",
|
|
46
45
|
"eslint-plugin-n": "15.7.0",
|
|
47
46
|
"eslint-plugin-node": "11.1.0",
|
|
48
47
|
"eslint-plugin-promise": "6.6.0",
|
|
49
48
|
"http-proxy": "1.18.1",
|
|
50
|
-
"mocha": "10.
|
|
51
|
-
"nock": "13.5.
|
|
49
|
+
"mocha": "10.8.2",
|
|
50
|
+
"nock": "13.5.6",
|
|
52
51
|
"tail": "2.2.6",
|
|
53
|
-
"uuid": "
|
|
52
|
+
"uuid": "11.0.3"
|
|
54
53
|
},
|
|
55
54
|
"scripts": {
|
|
56
55
|
"lint": "eslint --ignore-path .gitignore .",
|