ibm-cloud-sdk-core 2.4.4 → 2.7.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 +28 -0
- package/auth/authenticators/authenticator.js +0 -1
- package/auth/authenticators/basic-authenticator.js +0 -1
- package/auth/authenticators/bearer-token-authenticator.js +0 -1
- package/auth/authenticators/cloud-pak-for-data-authenticator.js +0 -1
- package/auth/authenticators/iam-authenticator.d.ts +12 -0
- package/auth/authenticators/iam-authenticator.js +12 -1
- package/auth/authenticators/index.js +7 -7
- package/auth/authenticators/no-auth-authenticator.js +0 -1
- package/auth/authenticators/token-request-based-authenticator.js +0 -1
- package/auth/index.js +6 -13
- package/auth/token-managers/cp4d-token-manager.js +0 -1
- package/auth/token-managers/iam-token-manager.d.ts +11 -0
- package/auth/token-managers/iam-token-manager.js +18 -1
- package/auth/token-managers/index.js +4 -4
- package/auth/token-managers/jwt-token-manager.js +0 -1
- package/auth/token-managers/token-manager.js +0 -1
- package/auth/utils/get-authenticator-from-environment.js +0 -1
- package/auth/utils/helpers.js +0 -1
- package/auth/utils/index.js +7 -14
- package/auth/utils/read-credentials-file.browser.js +0 -1
- package/auth/utils/read-credentials-file.js +0 -1
- package/auth/utils/read-external-sources.js +4 -2
- package/index.js +9 -17
- package/lib/base-service.d.ts +6 -0
- package/lib/base-service.js +16 -3
- package/lib/helper.js +0 -1
- package/lib/request-wrapper.d.ts +2 -0
- package/lib/request-wrapper.js +186 -83
- package/lib/sdk-test-helpers.js +0 -1
- package/lib/stream-to-promise.js +0 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [2.7.0](https://github.com/IBM/node-sdk-core/compare/v2.6.0...v2.7.0) (2020-10-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add support for compressing request bodies ([#111](https://github.com/IBM/node-sdk-core/issues/111)) ([7692d71](https://github.com/IBM/node-sdk-core/commit/7692d710fc2fb4f2c1cdfb3045d943c15d13bf1d))
|
|
7
|
+
|
|
8
|
+
# [2.6.0](https://github.com/IBM/node-sdk-core/compare/v2.5.0...v2.6.0) (2020-09-25)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* upgrade axios and re-enable gzipping responses ([#110](https://github.com/IBM/node-sdk-core/issues/110)) ([9e94251](https://github.com/IBM/node-sdk-core/commit/9e94251fd23cb60517022455017ed34d3a419362))
|
|
14
|
+
|
|
15
|
+
# [2.5.0](https://github.com/IBM/node-sdk-core/compare/v2.4.5...v2.5.0) (2020-09-18)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **IAM Authenticator:** add support for optional 'scope' property ([#109](https://github.com/IBM/node-sdk-core/issues/109)) ([1c258b7](https://github.com/IBM/node-sdk-core/commit/1c258b71470c0228e021c959984cc887d849887b))
|
|
21
|
+
|
|
22
|
+
## [2.4.5](https://github.com/IBM/node-sdk-core/compare/v2.4.4...v2.4.5) (2020-08-12)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* pin typescript dependency to 3.8.3 ([#107](https://github.com/IBM/node-sdk-core/issues/107)) ([ef27bc9](https://github.com/IBM/node-sdk-core/commit/ef27bc94b7626880cb4ab21c5c711bb98b34272d))
|
|
28
|
+
|
|
1
29
|
## [2.4.4](https://github.com/IBM/node-sdk-core/compare/v2.4.3...v2.4.4) (2020-08-06)
|
|
2
30
|
|
|
3
31
|
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.Authenticator = void 0;
|
|
19
18
|
/**
|
|
20
19
|
* Base Authenticator class for other Authenticators to extend. Not intended
|
|
21
20
|
* to be used as a stand-alone authenticator.
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.BasicAuthenticator = void 0;
|
|
32
31
|
var extend = require("extend");
|
|
33
32
|
var utils_1 = require("../utils");
|
|
34
33
|
var authenticator_1 = require("./authenticator");
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.BearerTokenAuthenticator = void 0;
|
|
32
31
|
var extend = require("extend");
|
|
33
32
|
var utils_1 = require("../utils");
|
|
34
33
|
var authenticator_1 = require("./authenticator");
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.CloudPakForDataAuthenticator = void 0;
|
|
32
31
|
var token_managers_1 = require("../token-managers");
|
|
33
32
|
var utils_1 = require("../utils");
|
|
34
33
|
var token_request_based_authenticator_1 = require("./token-request-based-authenticator");
|
|
@@ -29,6 +29,10 @@ export interface Options extends BaseOptions {
|
|
|
29
29
|
* authorization header for IAM token requests.
|
|
30
30
|
*/
|
|
31
31
|
clientSecret?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The "scope" parameter to use when fetching the bearer token from the IAM token server.
|
|
34
|
+
*/
|
|
35
|
+
scope?: string;
|
|
32
36
|
}
|
|
33
37
|
/**
|
|
34
38
|
* The [[IamAuthenticator]] will use the user-supplied `apikey`
|
|
@@ -47,6 +51,7 @@ export declare class IamAuthenticator extends TokenRequestBasedAuthenticator {
|
|
|
47
51
|
private apikey;
|
|
48
52
|
private clientId;
|
|
49
53
|
private clientSecret;
|
|
54
|
+
private scope;
|
|
50
55
|
/**
|
|
51
56
|
*
|
|
52
57
|
* Create a new [[IamAuthenticator]] instance.
|
|
@@ -62,6 +67,8 @@ export declare class IamAuthenticator extends TokenRequestBasedAuthenticator {
|
|
|
62
67
|
* authorization header for IAM token requests.
|
|
63
68
|
* @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
|
|
64
69
|
* authorization header for IAM token requests.
|
|
70
|
+
* @param {string} [options.scope] The "scope" parameter to use when fetching the bearer token from the
|
|
71
|
+
* IAM token server.
|
|
65
72
|
* @throws {Error} When the configuration options are not valid.
|
|
66
73
|
*/
|
|
67
74
|
constructor(options: Options);
|
|
@@ -73,4 +80,9 @@ export declare class IamAuthenticator extends TokenRequestBasedAuthenticator {
|
|
|
73
80
|
* authorization header for IAM token requests.
|
|
74
81
|
*/
|
|
75
82
|
setClientIdAndSecret(clientId: string, clientSecret: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Setter for the "scope" parameter to use when fetching the bearer token from the IAM token server.
|
|
85
|
+
* @param {string} scope A space seperated string that makes up the scope parameter
|
|
86
|
+
*/
|
|
87
|
+
setScope(scope: string): void;
|
|
76
88
|
}
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.IamAuthenticator = void 0;
|
|
32
31
|
var token_managers_1 = require("../token-managers");
|
|
33
32
|
var utils_1 = require("../utils");
|
|
34
33
|
var token_request_based_authenticator_1 = require("./token-request-based-authenticator");
|
|
@@ -60,6 +59,8 @@ var IamAuthenticator = /** @class */ (function (_super) {
|
|
|
60
59
|
* authorization header for IAM token requests.
|
|
61
60
|
* @param {string} [options.clientSecret] The `clientId` and `clientSecret` fields are used to form a "basic"
|
|
62
61
|
* authorization header for IAM token requests.
|
|
62
|
+
* @param {string} [options.scope] The "scope" parameter to use when fetching the bearer token from the
|
|
63
|
+
* IAM token server.
|
|
63
64
|
* @throws {Error} When the configuration options are not valid.
|
|
64
65
|
*/
|
|
65
66
|
function IamAuthenticator(options) {
|
|
@@ -69,6 +70,7 @@ var IamAuthenticator = /** @class */ (function (_super) {
|
|
|
69
70
|
_this.apikey = options.apikey;
|
|
70
71
|
_this.clientId = options.clientId;
|
|
71
72
|
_this.clientSecret = options.clientSecret;
|
|
73
|
+
_this.scope = options.scope;
|
|
72
74
|
// the param names are shared between the authenticator and the token
|
|
73
75
|
// manager so we can just pass along the options object
|
|
74
76
|
_this.tokenManager = new token_managers_1.IamTokenManager(options);
|
|
@@ -87,6 +89,15 @@ var IamAuthenticator = /** @class */ (function (_super) {
|
|
|
87
89
|
// update properties in token manager
|
|
88
90
|
this.tokenManager.setClientIdAndSecret(clientId, clientSecret);
|
|
89
91
|
};
|
|
92
|
+
/**
|
|
93
|
+
* Setter for the "scope" parameter to use when fetching the bearer token from the IAM token server.
|
|
94
|
+
* @param {string} scope A space seperated string that makes up the scope parameter
|
|
95
|
+
*/
|
|
96
|
+
IamAuthenticator.prototype.setScope = function (scope) {
|
|
97
|
+
this.scope = scope;
|
|
98
|
+
// update properties in token manager
|
|
99
|
+
this.tokenManager.setScope(scope);
|
|
100
|
+
};
|
|
90
101
|
return IamAuthenticator;
|
|
91
102
|
}(token_request_based_authenticator_1.TokenRequestBasedAuthenticator));
|
|
92
103
|
exports.IamAuthenticator = IamAuthenticator;
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
var authenticator_1 = require("./authenticator");
|
|
19
|
-
|
|
19
|
+
exports.Authenticator = authenticator_1.Authenticator;
|
|
20
20
|
var basic_authenticator_1 = require("./basic-authenticator");
|
|
21
|
-
|
|
21
|
+
exports.BasicAuthenticator = basic_authenticator_1.BasicAuthenticator;
|
|
22
22
|
var bearer_token_authenticator_1 = require("./bearer-token-authenticator");
|
|
23
|
-
|
|
23
|
+
exports.BearerTokenAuthenticator = bearer_token_authenticator_1.BearerTokenAuthenticator;
|
|
24
24
|
var cloud_pak_for_data_authenticator_1 = require("./cloud-pak-for-data-authenticator");
|
|
25
|
-
|
|
25
|
+
exports.CloudPakForDataAuthenticator = cloud_pak_for_data_authenticator_1.CloudPakForDataAuthenticator;
|
|
26
26
|
var iam_authenticator_1 = require("./iam-authenticator");
|
|
27
|
-
|
|
27
|
+
exports.IamAuthenticator = iam_authenticator_1.IamAuthenticator;
|
|
28
28
|
var no_auth_authenticator_1 = require("./no-auth-authenticator");
|
|
29
|
-
|
|
29
|
+
exports.NoAuthAuthenticator = no_auth_authenticator_1.NoAuthAuthenticator;
|
|
30
30
|
var token_request_based_authenticator_1 = require("./token-request-based-authenticator");
|
|
31
|
-
|
|
31
|
+
exports.TokenRequestBasedAuthenticator = token_request_based_authenticator_1.TokenRequestBasedAuthenticator;
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.NoAuthAuthenticator = void 0;
|
|
32
31
|
var authenticator_1 = require("./authenticator");
|
|
33
32
|
/**
|
|
34
33
|
* NoAuthAuthenticator is a placeholder authenticator implementation which
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.TokenRequestBasedAuthenticator = void 0;
|
|
32
31
|
var extend = require("extend");
|
|
33
32
|
var token_managers_1 = require("../token-managers");
|
|
34
33
|
var authenticator_1 = require("./authenticator");
|
package/auth/index.js
CHANGED
|
@@ -14,17 +14,10 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
26
|
-
};
|
|
17
|
+
function __export(m) {
|
|
18
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
19
|
+
}
|
|
27
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
__export(require("./authenticators"));
|
|
22
|
+
__export(require("./token-managers"));
|
|
23
|
+
__export(require("./utils"));
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.Cp4dTokenManager = void 0;
|
|
32
31
|
var extend = require("extend");
|
|
33
32
|
var utils_1 = require("../utils");
|
|
34
33
|
var jwt_token_manager_1 = require("./jwt-token-manager");
|
|
@@ -19,6 +19,7 @@ interface Options extends JwtTokenManagerOptions {
|
|
|
19
19
|
apikey: string;
|
|
20
20
|
clientId?: string;
|
|
21
21
|
clientSecret?: string;
|
|
22
|
+
scope?: string;
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
25
|
* The IAMTokenManager takes an api key and performs the necessary interactions with
|
|
@@ -30,6 +31,7 @@ export declare class IamTokenManager extends JwtTokenManager {
|
|
|
30
31
|
private apikey;
|
|
31
32
|
private clientId;
|
|
32
33
|
private clientSecret;
|
|
34
|
+
private scope;
|
|
33
35
|
/**
|
|
34
36
|
*
|
|
35
37
|
* Create a new [[IamTokenManager]] instance.
|
|
@@ -49,6 +51,15 @@ export declare class IamTokenManager extends JwtTokenManager {
|
|
|
49
51
|
* @constructor
|
|
50
52
|
*/
|
|
51
53
|
constructor(options: Options);
|
|
54
|
+
/**
|
|
55
|
+
* Set the IAM `scope` value.
|
|
56
|
+
* This value is the form parameter to use when fetching the bearer token
|
|
57
|
+
* from the IAM token server.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} scope - A space seperated string that makes up the scope parameter.
|
|
60
|
+
* @returns {void}
|
|
61
|
+
*/
|
|
62
|
+
setScope(scope: string): void;
|
|
52
63
|
/**
|
|
53
64
|
* Set the IAM `clientId` and `clientSecret` values.
|
|
54
65
|
* These values are used to compute the Authorization header used
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.IamTokenManager = void 0;
|
|
32
31
|
var extend = require("extend");
|
|
33
32
|
var logger_1 = require("../../lib/logger");
|
|
34
33
|
var utils_1 = require("../utils");
|
|
@@ -47,6 +46,7 @@ function onlyOne(a, b) {
|
|
|
47
46
|
return Boolean((a && !b) || (b && !a));
|
|
48
47
|
}
|
|
49
48
|
var CLIENT_ID_SECRET_WARNING = 'Warning: Client ID and Secret must BOTH be given, or the header will not be included.';
|
|
49
|
+
var SCOPE = 'scope';
|
|
50
50
|
/**
|
|
51
51
|
* The IAMTokenManager takes an api key and performs the necessary interactions with
|
|
52
52
|
* the IAM token service to obtain and store a suitable bearer token. Additionally, the IAMTokenManager
|
|
@@ -84,12 +84,26 @@ var IamTokenManager = /** @class */ (function (_super) {
|
|
|
84
84
|
if (options.clientSecret) {
|
|
85
85
|
_this.clientSecret = options.clientSecret;
|
|
86
86
|
}
|
|
87
|
+
if (options.scope) {
|
|
88
|
+
_this.scope = options.scope;
|
|
89
|
+
}
|
|
87
90
|
if (onlyOne(options.clientId, options.clientSecret)) {
|
|
88
91
|
// tslint:disable-next-line
|
|
89
92
|
logger_1.default.warn(CLIENT_ID_SECRET_WARNING);
|
|
90
93
|
}
|
|
91
94
|
return _this;
|
|
92
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Set the IAM `scope` value.
|
|
98
|
+
* This value is the form parameter to use when fetching the bearer token
|
|
99
|
+
* from the IAM token server.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} scope - A space seperated string that makes up the scope parameter.
|
|
102
|
+
* @returns {void}
|
|
103
|
+
*/
|
|
104
|
+
IamTokenManager.prototype.setScope = function (scope) {
|
|
105
|
+
this.scope = scope;
|
|
106
|
+
};
|
|
93
107
|
/**
|
|
94
108
|
* Set the IAM `clientId` and `clientSecret` values.
|
|
95
109
|
* These values are used to compute the Authorization header used
|
|
@@ -136,6 +150,9 @@ var IamTokenManager = /** @class */ (function (_super) {
|
|
|
136
150
|
rejectUnauthorized: !this.disableSslVerification,
|
|
137
151
|
}
|
|
138
152
|
};
|
|
153
|
+
if (this.scope) {
|
|
154
|
+
parameters.options.form[SCOPE] = this.scope;
|
|
155
|
+
}
|
|
139
156
|
return this.requestWrapperInstance.sendRequest(parameters);
|
|
140
157
|
};
|
|
141
158
|
return IamTokenManager;
|
|
@@ -31,10 +31,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
31
31
|
* JwtTokenManager: A class for shared functionality for parsing, storing, and requesting JWT tokens.
|
|
32
32
|
*/
|
|
33
33
|
var iam_token_manager_1 = require("./iam-token-manager");
|
|
34
|
-
|
|
34
|
+
exports.IamTokenManager = iam_token_manager_1.IamTokenManager;
|
|
35
35
|
var cp4d_token_manager_1 = require("./cp4d-token-manager");
|
|
36
|
-
|
|
36
|
+
exports.Cp4dTokenManager = cp4d_token_manager_1.Cp4dTokenManager;
|
|
37
37
|
var jwt_token_manager_1 = require("./jwt-token-manager");
|
|
38
|
-
|
|
38
|
+
exports.JwtTokenManager = jwt_token_manager_1.JwtTokenManager;
|
|
39
39
|
var token_manager_1 = require("./token-manager");
|
|
40
|
-
|
|
40
|
+
exports.TokenManager = token_manager_1.TokenManager;
|
|
@@ -28,7 +28,6 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
28
28
|
};
|
|
29
29
|
})();
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.JwtTokenManager = void 0;
|
|
32
31
|
var jwt = require("jsonwebtoken");
|
|
33
32
|
var logger_1 = require("../../lib/logger");
|
|
34
33
|
var token_manager_1 = require("./token-manager");
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.TokenManager = void 0;
|
|
19
18
|
var helper_1 = require("../../lib/helper");
|
|
20
19
|
var logger_1 = require("../../lib/logger");
|
|
21
20
|
var request_wrapper_1 = require("../../lib/request-wrapper");
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getAuthenticatorFromEnvironment = void 0;
|
|
19
18
|
var authenticators_1 = require("../authenticators");
|
|
20
19
|
var read_external_sources_1 = require("./read-external-sources");
|
|
21
20
|
/**
|
package/auth/utils/helpers.js
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getCurrentTime = exports.validateInput = exports.checkCredentials = exports.computeBasicAuthHeader = void 0;
|
|
19
18
|
var helper_1 = require("../../lib/helper");
|
|
20
19
|
/**
|
|
21
20
|
* Compute and return a Basic Authorization header from a username and password.
|
package/auth/utils/index.js
CHANGED
|
@@ -14,16 +14,9 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
26
|
-
};
|
|
17
|
+
function __export(m) {
|
|
18
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
19
|
+
}
|
|
27
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
21
|
/**
|
|
29
22
|
* @module utils
|
|
@@ -33,9 +26,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
33
26
|
* getAuthenticatorFromEnvironment: Get authenticator from external sources.
|
|
34
27
|
* readExternalSources: Get config object from external sources.
|
|
35
28
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
__export(require("./helpers"));
|
|
30
|
+
__export(require("./read-credentials-file"));
|
|
38
31
|
var get_authenticator_from_environment_1 = require("./get-authenticator-from-environment");
|
|
39
|
-
|
|
32
|
+
exports.getAuthenticatorFromEnvironment = get_authenticator_from_environment_1.getAuthenticatorFromEnvironment;
|
|
40
33
|
var read_external_sources_1 = require("./read-external-sources");
|
|
41
|
-
|
|
34
|
+
exports.readExternalSources = read_external_sources_1.readExternalSources;
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.readExternalSources = void 0;
|
|
19
18
|
var camelcase = require("camelcase");
|
|
20
19
|
var isEmpty = require("lodash.isempty");
|
|
21
20
|
var logger_1 = require("../../lib/logger");
|
|
@@ -73,13 +72,16 @@ function filterPropertiesByServiceName(envObj, serviceName) {
|
|
|
73
72
|
credentials[propName] = envObj[key];
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
|
-
// all env variables are parsed as strings, convert
|
|
75
|
+
// all env variables are parsed as strings, convert boolean vars as needed
|
|
77
76
|
if (typeof credentials.disableSsl === 'string') {
|
|
78
77
|
credentials.disableSsl = credentials.disableSsl === 'true';
|
|
79
78
|
}
|
|
80
79
|
if (typeof credentials.authDisableSsl === 'string') {
|
|
81
80
|
credentials.authDisableSsl = credentials.authDisableSsl === 'true';
|
|
82
81
|
}
|
|
82
|
+
if (typeof credentials.enableGzip === 'string') {
|
|
83
|
+
credentials.enableGzip = credentials.enableGzip === 'true';
|
|
84
|
+
}
|
|
83
85
|
return credentials;
|
|
84
86
|
}
|
|
85
87
|
/**
|
package/index.js
CHANGED
|
@@ -14,29 +14,21 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
25
|
-
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
26
|
-
};
|
|
17
|
+
function __export(m) {
|
|
18
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
19
|
+
}
|
|
27
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.unitTestUtils = void 0;
|
|
29
21
|
/**
|
|
30
22
|
* @module ibm-cloud-sdk-core
|
|
31
23
|
*/
|
|
32
24
|
var base_service_1 = require("./lib/base-service");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
exports.BaseService = base_service_1.BaseService;
|
|
26
|
+
__export(require("./auth"));
|
|
27
|
+
__export(require("./lib/helper"));
|
|
36
28
|
var querystring_1 = require("./lib/querystring");
|
|
37
|
-
|
|
29
|
+
exports.qs = querystring_1.default;
|
|
38
30
|
var content_type_1 = require("./lib/content-type");
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
exports.contentType = content_type_1.default;
|
|
32
|
+
__export(require("./lib/stream-to-promise"));
|
|
41
33
|
var unitTestUtils = require("./lib/sdk-test-helpers");
|
|
42
34
|
exports.unitTestUtils = unitTestUtils;
|
package/lib/base-service.d.ts
CHANGED
|
@@ -82,6 +82,12 @@ export declare class BaseService {
|
|
|
82
82
|
* @param {string} url The base URL for the service.
|
|
83
83
|
*/
|
|
84
84
|
setServiceUrl(url: string): void;
|
|
85
|
+
/**
|
|
86
|
+
* Turn request body compression on or off.
|
|
87
|
+
*
|
|
88
|
+
* @param {boolean} setting Will turn it on if 'true', off if 'false'.
|
|
89
|
+
*/
|
|
90
|
+
setEnableGzipCompression(setting: boolean): void;
|
|
85
91
|
/**
|
|
86
92
|
* Configure the service using external configuration
|
|
87
93
|
*
|
package/lib/base-service.js
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.BaseService = void 0;
|
|
19
18
|
var auth_1 = require("../auth");
|
|
20
19
|
var helper_1 = require("./helper");
|
|
21
20
|
var logger_1 = require("./logger");
|
|
@@ -93,6 +92,14 @@ var BaseService = /** @class */ (function () {
|
|
|
93
92
|
this.baseOptions.serviceUrl = helper_1.stripTrailingSlash(url);
|
|
94
93
|
}
|
|
95
94
|
};
|
|
95
|
+
/**
|
|
96
|
+
* Turn request body compression on or off.
|
|
97
|
+
*
|
|
98
|
+
* @param {boolean} setting Will turn it on if 'true', off if 'false'.
|
|
99
|
+
*/
|
|
100
|
+
BaseService.prototype.setEnableGzipCompression = function (setting) {
|
|
101
|
+
this.requestWrapperInstance.compressRequestData = setting;
|
|
102
|
+
};
|
|
96
103
|
/**
|
|
97
104
|
* Configure the service using external configuration
|
|
98
105
|
*
|
|
@@ -146,14 +153,20 @@ var BaseService = /** @class */ (function () {
|
|
|
146
153
|
var results = {};
|
|
147
154
|
var properties = auth_1.readExternalSources(serviceName);
|
|
148
155
|
if (properties !== null) {
|
|
149
|
-
// the user can define
|
|
150
|
-
|
|
156
|
+
// the user can define the following client-level variables in the credentials file:
|
|
157
|
+
// - url
|
|
158
|
+
// - disableSsl
|
|
159
|
+
// - enableGzip
|
|
160
|
+
var url = properties.url, disableSsl = properties.disableSsl, enableGzip = properties.enableGzip;
|
|
151
161
|
if (url) {
|
|
152
162
|
results.serviceUrl = helper_1.stripTrailingSlash(url);
|
|
153
163
|
}
|
|
154
164
|
if (disableSsl === true) {
|
|
155
165
|
results.disableSslVerification = disableSsl;
|
|
156
166
|
}
|
|
167
|
+
if (enableGzip === true) {
|
|
168
|
+
results.enableGzipCompression = enableGzip;
|
|
169
|
+
}
|
|
157
170
|
}
|
|
158
171
|
return results;
|
|
159
172
|
};
|
package/lib/helper.js
CHANGED
|
@@ -22,7 +22,6 @@ var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
|
22
22
|
return r;
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.toLowerKeys = exports.buildRequestFileObject = exports.getFormat = exports.isHTML = exports.getMissingParams = exports.stripTrailingSlash = exports.getContentType = exports.isEmptyObject = exports.isFileData = exports.isFileWithMetadata = void 0;
|
|
26
25
|
var fileType = require("file-type");
|
|
27
26
|
var isstream_1 = require("isstream");
|
|
28
27
|
var mime_types_1 = require("mime-types");
|
package/lib/request-wrapper.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
export declare class RequestWrapper {
|
|
17
17
|
private axiosInstance;
|
|
18
|
+
private compressRequestData;
|
|
18
19
|
constructor(axiosOptions?: any);
|
|
19
20
|
/**
|
|
20
21
|
* Creates the request.
|
|
@@ -34,4 +35,5 @@ export declare class RequestWrapper {
|
|
|
34
35
|
* @returns {Error}
|
|
35
36
|
*/
|
|
36
37
|
formatError(axiosError: any): Error;
|
|
38
|
+
private gzipRequestBody;
|
|
37
39
|
}
|
package/lib/request-wrapper.js
CHANGED
|
@@ -14,21 +14,60 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (_) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
17
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.RequestWrapper = void 0;
|
|
19
54
|
var axios_1 = require("axios");
|
|
20
55
|
var axios_cookiejar_support_1 = require("axios-cookiejar-support");
|
|
21
56
|
var extend = require("extend");
|
|
22
57
|
var FormData = require("form-data");
|
|
23
58
|
var https = require("https");
|
|
59
|
+
var isStream = require("isstream");
|
|
24
60
|
var querystring = require("querystring");
|
|
61
|
+
var zlib = require("zlib");
|
|
25
62
|
var helper_1 = require("./helper");
|
|
26
63
|
var logger_1 = require("./logger");
|
|
64
|
+
var stream_to_promise_1 = require("./stream-to-promise");
|
|
27
65
|
var isBrowser = typeof window === 'object';
|
|
28
66
|
var globalTransactionId = 'x-global-transaction-id';
|
|
29
67
|
var RequestWrapper = /** @class */ (function () {
|
|
30
68
|
function RequestWrapper(axiosOptions) {
|
|
31
69
|
axiosOptions = axiosOptions || {};
|
|
70
|
+
this.compressRequestData = Boolean(axiosOptions.enableGzipCompression);
|
|
32
71
|
// override several axios defaults
|
|
33
72
|
// axios sets the default Content-Type for `post`, `put`, and `patch` operations
|
|
34
73
|
// to 'application/x-www-form-urlencoded'. This causes problems, so overriding the
|
|
@@ -126,90 +165,102 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
126
165
|
* @throws {Error}
|
|
127
166
|
*/
|
|
128
167
|
RequestWrapper.prototype.sendRequest = function (parameters) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
169
|
+
var options, path, body, form, formData, qs, method, serviceUrl, headers, url, multipartForm, data, requestParams;
|
|
170
|
+
var _this = this;
|
|
171
|
+
return __generator(this, function (_a) {
|
|
172
|
+
switch (_a.label) {
|
|
173
|
+
case 0:
|
|
174
|
+
options = extend(true, {}, parameters.defaultOptions, parameters.options);
|
|
175
|
+
path = options.path, body = options.body, form = options.form, formData = options.formData, qs = options.qs, method = options.method, serviceUrl = options.serviceUrl;
|
|
176
|
+
headers = options.headers, url = options.url;
|
|
177
|
+
multipartForm = new FormData();
|
|
178
|
+
// Form params
|
|
179
|
+
if (formData) {
|
|
180
|
+
Object.keys(formData).forEach(function (key) {
|
|
181
|
+
var values = Array.isArray(formData[key]) ? formData[key] : [formData[key]];
|
|
182
|
+
// Skip keys with undefined/null values or empty object value
|
|
183
|
+
values.filter(function (v) { return v != null && !helper_1.isEmptyObject(v); }).forEach(function (value) {
|
|
184
|
+
// Special case of empty file object
|
|
185
|
+
if (value.hasOwnProperty('contentType') && !value.hasOwnProperty('data')) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (helper_1.isFileWithMetadata(value)) {
|
|
189
|
+
var fileObj = helper_1.buildRequestFileObject(value);
|
|
190
|
+
multipartForm.append(key, fileObj.value, fileObj.options);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
if (typeof value === 'object' && !helper_1.isFileData(value)) {
|
|
194
|
+
value = JSON.stringify(value);
|
|
195
|
+
}
|
|
196
|
+
multipartForm.append(key, value);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
151
200
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
201
|
+
// Path params
|
|
202
|
+
url = parsePath(url, path);
|
|
203
|
+
// Headers
|
|
204
|
+
options.headers = Object.assign({}, options.headers);
|
|
205
|
+
// Convert array-valued query params to strings
|
|
206
|
+
if (qs && Object.keys(qs).length > 0) {
|
|
207
|
+
Object.keys(qs).forEach(function (key) { return Array.isArray(qs[key]) && (qs[key] = qs[key].join(',')); });
|
|
208
|
+
}
|
|
209
|
+
// Add service default endpoint if options.url start with /
|
|
210
|
+
if (url && url.charAt(0) === '/') {
|
|
211
|
+
url = helper_1.stripTrailingSlash(serviceUrl) + url;
|
|
212
|
+
}
|
|
213
|
+
url = helper_1.stripTrailingSlash(url);
|
|
214
|
+
data = body;
|
|
215
|
+
if (form) {
|
|
216
|
+
data = querystring.stringify(form);
|
|
217
|
+
headers['Content-type'] = 'application/x-www-form-urlencoded';
|
|
218
|
+
}
|
|
219
|
+
if (formData) {
|
|
220
|
+
data = multipartForm;
|
|
221
|
+
// form-data generates headers that MUST be included or the request will fail
|
|
222
|
+
headers = extend(true, {}, headers, multipartForm.getHeaders());
|
|
223
|
+
}
|
|
224
|
+
// accept gzip encoded responses if Accept-Encoding is not already set
|
|
225
|
+
headers['Accept-Encoding'] = headers['Accept-Encoding'] || 'gzip';
|
|
226
|
+
if (!this.compressRequestData) return [3 /*break*/, 2];
|
|
227
|
+
return [4 /*yield*/, this.gzipRequestBody(data, headers)];
|
|
228
|
+
case 1:
|
|
229
|
+
data = _a.sent();
|
|
230
|
+
_a.label = 2;
|
|
231
|
+
case 2:
|
|
232
|
+
requestParams = {
|
|
233
|
+
url: url,
|
|
234
|
+
method: method,
|
|
235
|
+
headers: headers,
|
|
236
|
+
params: qs,
|
|
237
|
+
data: data,
|
|
238
|
+
responseType: options.responseType || 'json',
|
|
239
|
+
paramsSerializer: function (params) {
|
|
240
|
+
return querystring.stringify(params);
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
return [2 /*return*/, this.axiosInstance(requestParams).then(function (res) {
|
|
244
|
+
// sometimes error responses will still trigger the `then` block - escape that behavior here
|
|
245
|
+
if (!res) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
;
|
|
249
|
+
// these objects contain circular json structures and are not always relevant to the user
|
|
250
|
+
// if the user wants them, they can be accessed through the debug properties
|
|
251
|
+
delete res.config;
|
|
252
|
+
delete res.request;
|
|
253
|
+
// the other sdks use the interface `result` for the body
|
|
254
|
+
res.result = res.data;
|
|
255
|
+
delete res.data;
|
|
256
|
+
// return another promise that resolves with 'res' to be handled in generated code
|
|
257
|
+
return res;
|
|
258
|
+
}, function (err) {
|
|
259
|
+
// return another promise that rejects with 'err' to be handled in generated code
|
|
260
|
+
throw _this.formatError(err);
|
|
261
|
+
})];
|
|
262
|
+
}
|
|
155
263
|
});
|
|
156
|
-
}
|
|
157
|
-
// Path params
|
|
158
|
-
url = parsePath(url, path);
|
|
159
|
-
// Headers
|
|
160
|
-
options.headers = Object.assign({}, options.headers);
|
|
161
|
-
// Convert array-valued query params to strings
|
|
162
|
-
if (qs && Object.keys(qs).length > 0) {
|
|
163
|
-
Object.keys(qs).forEach(function (key) { return Array.isArray(qs[key]) && (qs[key] = qs[key].join(',')); });
|
|
164
|
-
}
|
|
165
|
-
// Add service default endpoint if options.url start with /
|
|
166
|
-
if (url && url.charAt(0) === '/') {
|
|
167
|
-
url = helper_1.stripTrailingSlash(serviceUrl) + url;
|
|
168
|
-
}
|
|
169
|
-
url = helper_1.stripTrailingSlash(url);
|
|
170
|
-
var data = body;
|
|
171
|
-
if (form) {
|
|
172
|
-
data = querystring.stringify(form);
|
|
173
|
-
headers['Content-type'] = 'application/x-www-form-urlencoded';
|
|
174
|
-
}
|
|
175
|
-
if (formData) {
|
|
176
|
-
data = multipartForm;
|
|
177
|
-
// form-data generates headers that MUST be included or the request will fail
|
|
178
|
-
headers = extend(true, {}, headers, multipartForm.getHeaders());
|
|
179
|
-
}
|
|
180
|
-
// TEMPORARY: Disabling gzipping due to bug in axios until fix is released:
|
|
181
|
-
// https://github.com/axios/axios/pull/1129
|
|
182
|
-
// accept gzip encoded responses if Accept-Encoding is not already set
|
|
183
|
-
// headers['Accept-Encoding'] = headers['Accept-Encoding'] || 'gzip';
|
|
184
|
-
var requestParams = {
|
|
185
|
-
url: url,
|
|
186
|
-
method: method,
|
|
187
|
-
headers: headers,
|
|
188
|
-
params: qs,
|
|
189
|
-
data: data,
|
|
190
|
-
responseType: options.responseType || 'json',
|
|
191
|
-
paramsSerializer: function (params) {
|
|
192
|
-
return querystring.stringify(params);
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
return this.axiosInstance(requestParams).then(function (res) {
|
|
196
|
-
// sometimes error responses will still trigger the `then` block - escape that behavior here
|
|
197
|
-
if (!res) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
;
|
|
201
|
-
// these objects contain circular json structures and are not always relevant to the user
|
|
202
|
-
// if the user wants them, they can be accessed through the debug properties
|
|
203
|
-
delete res.config;
|
|
204
|
-
delete res.request;
|
|
205
|
-
// the other sdks use the interface `result` for the body
|
|
206
|
-
res.result = res.data;
|
|
207
|
-
delete res.data;
|
|
208
|
-
// return another promise that resolves with 'res' to be handled in generated code
|
|
209
|
-
return res;
|
|
210
|
-
}, function (err) {
|
|
211
|
-
// return another promise that rejects with 'err' to be handled in generated code
|
|
212
|
-
throw _this.formatError(err);
|
|
213
264
|
});
|
|
214
265
|
};
|
|
215
266
|
/**
|
|
@@ -275,6 +326,58 @@ var RequestWrapper = /** @class */ (function () {
|
|
|
275
326
|
}
|
|
276
327
|
return error;
|
|
277
328
|
};
|
|
329
|
+
RequestWrapper.prototype.gzipRequestBody = function (data, headers) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
331
|
+
var contentSetToGzip, reqBuffer, _a, _b, err_1;
|
|
332
|
+
return __generator(this, function (_c) {
|
|
333
|
+
switch (_c.label) {
|
|
334
|
+
case 0:
|
|
335
|
+
contentSetToGzip = headers['Content-Encoding'] &&
|
|
336
|
+
headers['Content-Encoding'].toString().includes('gzip');
|
|
337
|
+
if (!data || contentSetToGzip) {
|
|
338
|
+
return [2 /*return*/, data];
|
|
339
|
+
}
|
|
340
|
+
_c.label = 1;
|
|
341
|
+
case 1:
|
|
342
|
+
_c.trys.push([1, 5, , 6]);
|
|
343
|
+
if (!isStream(data)) return [3 /*break*/, 3];
|
|
344
|
+
_b = (_a = Buffer).from;
|
|
345
|
+
return [4 /*yield*/, stream_to_promise_1.streamToPromise(data)];
|
|
346
|
+
case 2:
|
|
347
|
+
reqBuffer = _b.apply(_a, [_c.sent()]);
|
|
348
|
+
return [3 /*break*/, 4];
|
|
349
|
+
case 3:
|
|
350
|
+
if (data.toString && data.toString() !== '[object Object]' && !Array.isArray(data)) {
|
|
351
|
+
// this handles pretty much any primitive that isnt a JSON object or array
|
|
352
|
+
reqBuffer = Buffer.from(data.toString());
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
reqBuffer = Buffer.from(JSON.stringify(data));
|
|
356
|
+
}
|
|
357
|
+
_c.label = 4;
|
|
358
|
+
case 4: return [3 /*break*/, 6];
|
|
359
|
+
case 5:
|
|
360
|
+
err_1 = _c.sent();
|
|
361
|
+
logger_1.default.error('Error converting request body to a buffer - data will not be compressed.');
|
|
362
|
+
logger_1.default.debug(err_1);
|
|
363
|
+
return [2 /*return*/, data];
|
|
364
|
+
case 6:
|
|
365
|
+
try {
|
|
366
|
+
data = zlib.gzipSync(reqBuffer);
|
|
367
|
+
// update the headers by reference - only if the data was actually compressed
|
|
368
|
+
headers['Content-Encoding'] = 'gzip';
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
// if an exception is caught, `data` will still be in its original form
|
|
372
|
+
// we can just proceed with the request uncompressed
|
|
373
|
+
logger_1.default.error('Error compressing request body - data will not be compressed.');
|
|
374
|
+
logger_1.default.debug(err);
|
|
375
|
+
}
|
|
376
|
+
return [2 /*return*/, data];
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
};
|
|
278
381
|
return RequestWrapper;
|
|
279
382
|
}());
|
|
280
383
|
exports.RequestWrapper = RequestWrapper;
|
package/lib/sdk-test-helpers.js
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.expectToBePromise = exports.getOptions = exports.checkForSuccessfulExecution = exports.checkUserHeader = exports.checkMediaHeaders = exports.checkUrlAndMethod = void 0;
|
|
19
18
|
var expect = require("expect");
|
|
20
19
|
/**
|
|
21
20
|
* This module provides a set of helper methods used to reduce code duplication in the generated unit tests
|
package/lib/stream-to-promise.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.streamToPromise = void 0;
|
|
4
3
|
/**
|
|
5
4
|
* Helper method that can be bound to a stream - it sets the output to utf-8, captures all of the results, and returns a promise that resolves to the final text
|
|
6
5
|
* Essentially a smaller version of concat-stream wrapped in a promise
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ibm-cloud-sdk-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Core functionality to support SDKs generated with IBM's OpenAPI 3 SDK Generator.",
|
|
5
5
|
"main": "index",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/isstream": "^0.1.0",
|
|
34
34
|
"@types/node": "~10.14.19",
|
|
35
35
|
"@types/tough-cookie": "^4.0.0",
|
|
36
|
-
"axios": "^0.
|
|
36
|
+
"axios": "^0.20.0",
|
|
37
37
|
"axios-cookiejar-support": "^1.0.0",
|
|
38
38
|
"camelcase": "^5.3.1",
|
|
39
39
|
"debug": "^4.1.1",
|