ibm-cloud-sdk-core 4.3.3 → 5.0.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/.secrets.baseline +4 -4
- package/CHANGELOG.md +25 -0
- package/MIGRATION-V5.md +15 -0
- package/build/docs/ibm-cloud-sdk-core.md +0 -24
- package/docs/ibm-cloud-sdk-core.api.json +0 -378
- package/es/index.d.ts +1 -3
- package/es/index.js +1 -3
- package/etc/ibm-cloud-sdk-core.api.md +0 -30
- package/ibm-cloud-sdk-core.d.ts +0 -90
- package/index.d.ts +1 -3
- package/index.js +2 -16
- package/package.json +3 -5
- package/sdk-test-utilities/README.md +8 -0
- package/{es/lib/sdk-test-helpers.js → sdk-test-utilities/index.js} +41 -20
- package/sdk-test-utilities/package-lock.json +516 -0
- package/sdk-test-utilities/package.json +17 -0
- package/temp/ibm-cloud-sdk-core.api.json +0 -378
- package/temp/ibm-cloud-sdk-core.api.md +0 -30
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkforsuccessfulexecution.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkmediaheaders.md +0 -85
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkurlandmethod.md +0 -85
- package/build/docs/ibm-cloud-sdk-core.unittestutils.checkuserheader.md +0 -85
- package/build/docs/ibm-cloud-sdk-core.unittestutils.expecttobepromise.md +0 -53
- package/build/docs/ibm-cloud-sdk-core.unittestutils.getoptions.md +0 -55
- package/build/docs/ibm-cloud-sdk-core.unittestutils.md +0 -86
- package/es/lib/sdk-test-helpers.browser.d.ts +0 -21
- package/es/lib/sdk-test-helpers.browser.js +0 -23
- package/es/lib/sdk-test-helpers.d.ts +0 -72
- package/lib/sdk-test-helpers.browser.d.ts +0 -21
- package/lib/sdk-test-helpers.browser.js +0 -32
- package/lib/sdk-test-helpers.d.ts +0 -72
- package/lib/sdk-test-helpers.js +0 -102
package/ibm-cloud-sdk-core.d.ts
CHANGED
|
@@ -345,66 +345,6 @@ export declare function buildRequestFileObject(fileParam: FileWithMetadata): Pro
|
|
|
345
345
|
*/
|
|
346
346
|
export declare function checkCredentials(obj: any, credsToCheck: string[]): Error | null;
|
|
347
347
|
|
|
348
|
-
/**
|
|
349
|
-
* This method simply ensures that the method executed without any issues by extracting
|
|
350
|
-
* the argument from the mock object for the `createRequest` method and verifying that it is an object.
|
|
351
|
-
*
|
|
352
|
-
* @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
|
|
353
|
-
*/
|
|
354
|
-
declare function checkForSuccessfulExecution(createRequestMock: any): void;
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
|
|
358
|
-
* and checks for the expected values for `Accept` and `Content-Type`. This to verify that the SDK sets
|
|
359
|
-
* the correct values in the code.
|
|
360
|
-
*
|
|
361
|
-
* @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
|
|
362
|
-
* @param accept - the expected value for the `Accept` header
|
|
363
|
-
* @param contentType - the expected value for the `Content-Type` header
|
|
364
|
-
*/
|
|
365
|
-
declare function checkMediaHeaders(createRequestMock: any, accept: string, contentType: string): void;
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* (C) Copyright IBM Corp. 2019, 2022.
|
|
369
|
-
*
|
|
370
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
371
|
-
* you may not use this file except in compliance with the License.
|
|
372
|
-
* You may obtain a copy of the License at
|
|
373
|
-
*
|
|
374
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
375
|
-
*
|
|
376
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
377
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
378
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
379
|
-
* See the License for the specific language governing permissions and
|
|
380
|
-
* limitations under the License.
|
|
381
|
-
*/
|
|
382
|
-
/**
|
|
383
|
-
* This module provides a set of helper methods used to reduce code duplication in the generated unit tests
|
|
384
|
-
* for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
|
|
385
|
-
* package - they are meant to be exported and made available to dependent libraries.
|
|
386
|
-
*/
|
|
387
|
-
/**
|
|
388
|
-
* Takes the request options constructed by the SDK and checks that the `url` and `method` properties
|
|
389
|
-
* were set to their correct values.
|
|
390
|
-
*
|
|
391
|
-
* @param options - the options object put together by the SDK, retrieved from the createRequest mock
|
|
392
|
-
* @param url - The URL path of the service endpoint, from the paths section of the API definition
|
|
393
|
-
* @param method - The HTTP method for the request, from the API definition
|
|
394
|
-
*/
|
|
395
|
-
declare function checkUrlAndMethod(options: any, url: string, method: any): void;
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
|
|
399
|
-
* and checks for the expected value for a user-defined header. This is verify that the SDK accepts header
|
|
400
|
-
* parameters and sends them as headers in the request.
|
|
401
|
-
*
|
|
402
|
-
* @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
|
|
403
|
-
* @param userHeaderName - the name of the header passed by the user, e.g. `Contained-Content-Type`
|
|
404
|
-
* @param userHeaderValue - the expected value for the header passed by the user
|
|
405
|
-
*/
|
|
406
|
-
declare function checkUserHeader(createRequestMock: any, userHeaderName: string, userHeaderValue: string): void;
|
|
407
|
-
|
|
408
348
|
/**
|
|
409
349
|
* The CloudPakForDataAuthenticator will either use a username/password pair or a username/apikey pair to obtain
|
|
410
350
|
* a bearer token from a token server. When the bearer token expires, a new token is obtained from the token server.
|
|
@@ -636,14 +576,6 @@ export declare class Cp4dTokenManager extends JwtTokenManager {
|
|
|
636
576
|
protected requestToken(): Promise<any>;
|
|
637
577
|
}
|
|
638
578
|
|
|
639
|
-
/**
|
|
640
|
-
* This method simply ensures that the SDK methods return Promises by checking for
|
|
641
|
-
* the `then` function - common way to assess whether or not an object is a Promise.
|
|
642
|
-
*
|
|
643
|
-
* @param sdkPromise - the Promise returned by an SDK method
|
|
644
|
-
*/
|
|
645
|
-
declare function expectToBePromise(sdkPromise: any): void;
|
|
646
|
-
|
|
647
579
|
export declare function fileExistsAtPath(filepath: string): boolean;
|
|
648
580
|
|
|
649
581
|
/**
|
|
@@ -746,16 +678,6 @@ export declare function getMissingParams(params: {
|
|
|
746
678
|
*/
|
|
747
679
|
export declare function getNewLogger(moduleName: string): SDKLogger;
|
|
748
680
|
|
|
749
|
-
/**
|
|
750
|
-
* This method extracts the `options` property from the object passed into `createRequest`. This property is
|
|
751
|
-
* an object containing all of the SDK method-specific information (like `path` and `body`) used to build a request.
|
|
752
|
-
* This method is just a convenience method for the unit tests to be able to make assertions on the items in the request.
|
|
753
|
-
*
|
|
754
|
-
* @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
|
|
755
|
-
* @returns Object
|
|
756
|
-
*/
|
|
757
|
-
declare function getOptions(createRequestMock: any): any;
|
|
758
|
-
|
|
759
681
|
/**
|
|
760
682
|
* Return a query parameter value from a URL
|
|
761
683
|
*
|
|
@@ -1532,18 +1454,6 @@ export declare class TokenRequestBasedAuthenticator extends Authenticator {
|
|
|
1532
1454
|
*/
|
|
1533
1455
|
export declare function toLowerKeys(obj: Object): Object;
|
|
1534
1456
|
|
|
1535
|
-
declare namespace unitTestUtils {
|
|
1536
|
-
export {
|
|
1537
|
-
checkUrlAndMethod,
|
|
1538
|
-
checkMediaHeaders,
|
|
1539
|
-
checkUserHeader,
|
|
1540
|
-
checkForSuccessfulExecution,
|
|
1541
|
-
getOptions,
|
|
1542
|
-
expectToBePromise
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
export { unitTestUtils }
|
|
1546
|
-
|
|
1547
1457
|
/**
|
|
1548
1458
|
* Configuration values for a service.
|
|
1549
1459
|
*/
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2019,
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2024.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -16,12 +16,10 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* @module ibm-cloud-sdk-core
|
|
18
18
|
*/
|
|
19
|
-
import * as unitTestUtils from './lib/sdk-test-helpers';
|
|
20
19
|
export { BaseService, UserOptions } from './lib/base-service';
|
|
21
20
|
export * from './auth';
|
|
22
21
|
export * from './lib/helper';
|
|
23
22
|
export { default as qs } from './lib/querystring';
|
|
24
23
|
export { default as contentType } from './lib/content-type';
|
|
25
24
|
export * from './lib/stream-to-promise';
|
|
26
|
-
export { unitTestUtils };
|
|
27
25
|
export { getNewLogger, SDKLogger } from './lib/get-new-logger';
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* (C) Copyright IBM Corp. 2019,
|
|
3
|
+
* (C) Copyright IBM Corp. 2019, 2024.
|
|
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.
|
|
@@ -25,18 +25,6 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
25
25
|
if (k2 === undefined) k2 = k;
|
|
26
26
|
o[k2] = m[k];
|
|
27
27
|
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
28
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
41
29
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
42
30
|
};
|
|
@@ -44,12 +32,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
32
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
33
|
};
|
|
46
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.getNewLogger = exports.
|
|
35
|
+
exports.getNewLogger = exports.contentType = exports.qs = exports.BaseService = void 0;
|
|
48
36
|
/**
|
|
49
37
|
* @module ibm-cloud-sdk-core
|
|
50
38
|
*/
|
|
51
|
-
var unitTestUtils = __importStar(require("./lib/sdk-test-helpers"));
|
|
52
|
-
exports.unitTestUtils = unitTestUtils;
|
|
53
39
|
var base_service_1 = require("./lib/base-service");
|
|
54
40
|
Object.defineProperty(exports, "BaseService", { enumerable: true, get: function () { return base_service_1.BaseService; } });
|
|
55
41
|
__exportStar(require("./auth"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ibm-cloud-sdk-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "./es/index.d.ts",
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"camelcase": "^6.3.0",
|
|
42
42
|
"debug": "^4.3.4",
|
|
43
43
|
"dotenv": "^16.4.5",
|
|
44
|
-
"expect": "^27.5.1",
|
|
45
44
|
"extend": "3.0.2",
|
|
46
45
|
"file-type": "16.5.4",
|
|
47
46
|
"form-data": "4.0.0",
|
|
@@ -55,11 +54,10 @@
|
|
|
55
54
|
"semver": "^7.5.3"
|
|
56
55
|
},
|
|
57
56
|
"browser": {
|
|
58
|
-
"./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser"
|
|
59
|
-
"./lib/sdk-test-helpers": "./lib/sdk-test-helpers.browser"
|
|
57
|
+
"./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser"
|
|
60
58
|
},
|
|
61
59
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
60
|
+
"node": ">=18"
|
|
63
61
|
},
|
|
64
62
|
"scripts": {
|
|
65
63
|
"clean": "rm -fr node_modules",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# SDK Test Utilities
|
|
2
|
+
|
|
3
|
+
A set of utility methods for unit tests in IBM Cloud SDKs.
|
|
4
|
+
|
|
5
|
+
This package is published separately from `ibm-cloud-sdk-core`. It includes `expect`
|
|
6
|
+
as a dependency, which is not intended for inclusion in production packages. This
|
|
7
|
+
utility package should only be installed as a _development_ dependency and the logic
|
|
8
|
+
it contains will only ever be needed for tests.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* (C) Copyright IBM Corp. 2019,
|
|
2
|
+
* (C) Copyright IBM Corp. 2019, 2024.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -13,12 +13,15 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
const { expect } = require('expect');
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
|
-
* This module provides a set of
|
|
20
|
+
* This module provides a set of utility methods used to reduce code duplication in the generated unit tests
|
|
19
21
|
* for the SDKs that depend on this core package. Note that these methods are not used by the tests for this
|
|
20
22
|
* package - they are meant to be exported and made available to dependent libraries.
|
|
21
23
|
*/
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
26
|
* Takes the request options constructed by the SDK and checks that the `url` and `method` properties
|
|
24
27
|
* were set to their correct values.
|
|
@@ -27,10 +30,11 @@ import expect from 'expect';
|
|
|
27
30
|
* @param url - The URL path of the service endpoint, from the paths section of the API definition
|
|
28
31
|
* @param method - The HTTP method for the request, from the API definition
|
|
29
32
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
function checkUrlAndMethod(options, url, method) {
|
|
34
|
+
expect(options.url).toEqual(url);
|
|
35
|
+
expect(options.method).toEqual(method);
|
|
33
36
|
}
|
|
37
|
+
|
|
34
38
|
/**
|
|
35
39
|
* Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
|
|
36
40
|
* and checks for the expected values for `Accept` and `Content-Type`. This to verify that the SDK sets
|
|
@@ -40,11 +44,12 @@ export function checkUrlAndMethod(options, url, method) {
|
|
|
40
44
|
* @param accept - the expected value for the `Accept` header
|
|
41
45
|
* @param contentType - the expected value for the `Content-Type` header
|
|
42
46
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
function checkMediaHeaders(createRequestMock, accept, contentType) {
|
|
48
|
+
const { headers } = createRequestMock.mock.calls[0][0].defaultOptions;
|
|
49
|
+
expect(headers.Accept).toEqual(accept);
|
|
50
|
+
expect(headers['Content-Type']).toEqual(contentType);
|
|
47
51
|
}
|
|
52
|
+
|
|
48
53
|
/**
|
|
49
54
|
* Takes the mock object for the `createRequest` method, extracts the headers that were sent with the call,
|
|
50
55
|
* and checks for the expected value for a user-defined header. This is verify that the SDK accepts header
|
|
@@ -54,20 +59,26 @@ export function checkMediaHeaders(createRequestMock, accept, contentType) {
|
|
|
54
59
|
* @param userHeaderName - the name of the header passed by the user, e.g. `Contained-Content-Type`
|
|
55
60
|
* @param userHeaderValue - the expected value for the header passed by the user
|
|
56
61
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
function checkUserHeader(
|
|
63
|
+
createRequestMock,
|
|
64
|
+
userHeaderName,
|
|
65
|
+
userHeaderValue
|
|
66
|
+
) {
|
|
67
|
+
const { headers } = createRequestMock.mock.calls[0][0].defaultOptions;
|
|
68
|
+
expect(headers[userHeaderName]).toEqual(userHeaderValue);
|
|
60
69
|
}
|
|
70
|
+
|
|
61
71
|
/**
|
|
62
72
|
* This method simply ensures that the method executed without any issues by extracting
|
|
63
73
|
* the argument from the mock object for the `createRequest` method and verifying that it is an object.
|
|
64
74
|
*
|
|
65
75
|
* @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
|
|
66
76
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
function checkForSuccessfulExecution(createRequestMock) {
|
|
78
|
+
const sdkParams = createRequestMock.mock.calls[0][0];
|
|
79
|
+
expect(typeof sdkParams).toEqual('object');
|
|
70
80
|
}
|
|
81
|
+
|
|
71
82
|
/**
|
|
72
83
|
* This method extracts the `options` property from the object passed into `createRequest`. This property is
|
|
73
84
|
* an object containing all of the SDK method-specific information (like `path` and `body`) used to build a request.
|
|
@@ -76,15 +87,25 @@ export function checkForSuccessfulExecution(createRequestMock) {
|
|
|
76
87
|
* @param createRequestMock - the jest mock object for the `createRequest` method in the `RequestWrapper` class
|
|
77
88
|
* @returns Object
|
|
78
89
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
function getOptions(createRequestMock) {
|
|
91
|
+
return createRequestMock.mock.calls[0][0].options;
|
|
81
92
|
}
|
|
93
|
+
|
|
82
94
|
/**
|
|
83
95
|
* This method simply ensures that the SDK methods return Promises by checking for
|
|
84
96
|
* the `then` function - common way to assess whether or not an object is a Promise.
|
|
85
97
|
*
|
|
86
98
|
* @param sdkPromise - the Promise returned by an SDK method
|
|
87
99
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
100
|
+
function expectToBePromise(sdkPromise) {
|
|
101
|
+
expect(typeof sdkPromise.then).toBe('function');
|
|
90
102
|
}
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
checkUrlAndMethod,
|
|
106
|
+
checkMediaHeaders,
|
|
107
|
+
checkUserHeader,
|
|
108
|
+
checkForSuccessfulExecution,
|
|
109
|
+
getOptions,
|
|
110
|
+
expectToBePromise,
|
|
111
|
+
};
|