ibm-cloud-sdk-core 4.0.9 → 4.1.1

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/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v16.20.2
package/Authentication.md CHANGED
@@ -147,7 +147,7 @@ authenticator type is intended for situations in which the application will be m
147
147
  token itself in terms of initial acquisition and refreshing as needed.
148
148
 
149
149
 
150
- ## Identity and Access Management Authentication (IAM)
150
+ ## Identity and Access Management (IAM) Authentication
151
151
  The `IamAuthenticator` will accept a user-supplied api key and will perform
152
152
  the necessary interactions with the IAM token service to obtain a suitable
153
153
  bearer token for the specified api key. The authenticator will also obtain
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [4.1.1](https://github.com/IBM/node-sdk-core/compare/v4.1.0...v4.1.1) (2023-09-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * process cookies in failed responses ([#251](https://github.com/IBM/node-sdk-core/issues/251)) ([52f758b](https://github.com/IBM/node-sdk-core/commit/52f758bc5700b3ccd283e39cca7401ee8dcb60d9))
7
+
8
+ # [4.1.0](https://github.com/IBM/node-sdk-core/compare/v4.0.9...v4.1.0) (2023-07-06)
9
+
10
+
11
+ ### Features
12
+
13
+ * add logic for serializing/deserializing model objects ([#247](https://github.com/IBM/node-sdk-core/issues/247)) ([2397eae](https://github.com/IBM/node-sdk-core/commit/2397eaef56c247a2720396c7d1444b2331ae5a73))
14
+
1
15
  ## [4.0.9](https://github.com/IBM/node-sdk-core/compare/v4.0.8...v4.0.9) (2023-06-22)
2
16
 
3
17
 
@@ -0,0 +1,26 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [BaseService](./ibm-cloud-sdk-core.baseservice.md) &gt; [convertModel](./ibm-cloud-sdk-core.baseservice.convertmodel.md)
4
+
5
+ ## BaseService.convertModel() method
6
+
7
+ Applies a given modifier function on a model object. Since the model object can be a map, or an array, or a model, these types needs different handling. Considering whether the input object is a map happens with an explicit parameter.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ static convertModel(input: any, converterFn: any, isMap?: boolean): any;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | input | any | the input model object |
20
+ | converterFn | any | the function that is applied on the input object |
21
+ | isMap | boolean | _(Optional)_ is <code>true</code> when the input object should be handled as a map |
22
+
23
+ **Returns:**
24
+
25
+ any
26
+
@@ -0,0 +1,28 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [ibm-cloud-sdk-core](./ibm-cloud-sdk-core.md) &gt; [BaseService](./ibm-cloud-sdk-core.baseservice.md) &gt; [createRequestAndDeserializeResponse](./ibm-cloud-sdk-core.baseservice.createrequestanddeserializeresponse.md)
4
+
5
+ ## BaseService.createRequestAndDeserializeResponse() method
6
+
7
+ Wrapper around `createRequest` that enforces arrived response to be deserialized.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --- | --- | --- |
19
+ | parameters | any | see <code>parameters</code> in <code>createRequest</code> |
20
+ | deserializerFn | (any: any) =&gt; any | the deserializer function that is applied on the response object |
21
+ | isMap | boolean | _(Optional)_ is <code>true</code> when the response object should be handled as a map |
22
+
23
+ **Returns:**
24
+
25
+ Promise&lt;any&gt;
26
+
27
+ a Promise
28
+
@@ -33,7 +33,9 @@ export declare class BaseService
33
33
  | Method | Modifiers | Description |
34
34
  | --- | --- | --- |
35
35
  | [configureService(serviceName)](./ibm-cloud-sdk-core.baseservice.configureservice.md) | <code>protected</code> | Configure the service using external configuration |
36
+ | [convertModel(input, converterFn, isMap)](./ibm-cloud-sdk-core.baseservice.convertmodel.md) | <code>static</code> | Applies a given modifier function on a model object. Since the model object can be a map, or an array, or a model, these types needs different handling. Considering whether the input object is a map happens with an explicit parameter. |
36
37
  | [createRequest(parameters)](./ibm-cloud-sdk-core.baseservice.createrequest.md) | <code>protected</code> | Wrapper around <code>sendRequest</code> that enforces the request will be authenticated. |
38
+ | [createRequestAndDeserializeResponse(parameters, deserializerFn, isMap)](./ibm-cloud-sdk-core.baseservice.createrequestanddeserializeresponse.md) | <code>protected</code> | Wrapper around <code>createRequest</code> that enforces arrived response to be deserialized. |
37
39
  | [disableRetries()](./ibm-cloud-sdk-core.baseservice.disableretries.md) | | Disables retries. |
38
40
  | [enableRetries(retryOptions)](./ibm-cloud-sdk-core.baseservice.enableretries.md) | | Enable retries for unfulfilled requests. |
39
41
  | [getAuthenticator()](./ibm-cloud-sdk-core.baseservice.getauthenticator.md) | | Get the instance of the authenticator set on the service. |
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "metadata": {
3
3
  "toolPackage": "@microsoft/api-extractor",
4
- "toolVersion": "7.36.0",
4
+ "toolVersion": "7.36.1",
5
5
  "schemaVersion": 1011,
6
6
  "oldestForwardsCompatibleVersion": 1001,
7
7
  "tsdocConfig": {
@@ -892,6 +892,86 @@
892
892
  "isAbstract": false,
893
893
  "name": "configureService"
894
894
  },
895
+ {
896
+ "kind": "Method",
897
+ "canonicalReference": "ibm-cloud-sdk-core!BaseService.convertModel:member(1)",
898
+ "docComment": "/**\n * Applies a given modifier function on a model object. Since the model object can be a map, or an array, or a model, these types needs different handling. Considering whether the input object is a map happens with an explicit parameter.\n *\n * @param input - the input model object\n *\n * @param converterFn - the function that is applied on the input object\n *\n * @param isMap - is `true` when the input object should be handled as a map\n */\n",
899
+ "excerptTokens": [
900
+ {
901
+ "kind": "Content",
902
+ "text": "static convertModel(input: "
903
+ },
904
+ {
905
+ "kind": "Content",
906
+ "text": "any"
907
+ },
908
+ {
909
+ "kind": "Content",
910
+ "text": ", converterFn: "
911
+ },
912
+ {
913
+ "kind": "Content",
914
+ "text": "any"
915
+ },
916
+ {
917
+ "kind": "Content",
918
+ "text": ", isMap?: "
919
+ },
920
+ {
921
+ "kind": "Content",
922
+ "text": "boolean"
923
+ },
924
+ {
925
+ "kind": "Content",
926
+ "text": "): "
927
+ },
928
+ {
929
+ "kind": "Content",
930
+ "text": "any"
931
+ },
932
+ {
933
+ "kind": "Content",
934
+ "text": ";"
935
+ }
936
+ ],
937
+ "isStatic": true,
938
+ "returnTypeTokenRange": {
939
+ "startIndex": 7,
940
+ "endIndex": 8
941
+ },
942
+ "releaseTag": "Public",
943
+ "isProtected": false,
944
+ "overloadIndex": 1,
945
+ "parameters": [
946
+ {
947
+ "parameterName": "input",
948
+ "parameterTypeTokenRange": {
949
+ "startIndex": 1,
950
+ "endIndex": 2
951
+ },
952
+ "isOptional": false
953
+ },
954
+ {
955
+ "parameterName": "converterFn",
956
+ "parameterTypeTokenRange": {
957
+ "startIndex": 3,
958
+ "endIndex": 4
959
+ },
960
+ "isOptional": false
961
+ },
962
+ {
963
+ "parameterName": "isMap",
964
+ "parameterTypeTokenRange": {
965
+ "startIndex": 5,
966
+ "endIndex": 6
967
+ },
968
+ "isOptional": true
969
+ }
970
+ ],
971
+ "isOptional": false,
972
+ "isAbstract": false,
973
+ "name": "convertModel"
974
+ },
895
975
  {
896
976
  "kind": "Method",
897
977
  "canonicalReference": "ibm-cloud-sdk-core!BaseService#createRequest:member(1)",
@@ -945,6 +1025,91 @@
945
1025
  "isAbstract": false,
946
1026
  "name": "createRequest"
947
1027
  },
1028
+ {
1029
+ "kind": "Method",
1030
+ "canonicalReference": "ibm-cloud-sdk-core!BaseService#createRequestAndDeserializeResponse:member(1)",
1031
+ "docComment": "/**\n * Wrapper around `createRequest` that enforces arrived response to be deserialized.\n *\n * @param parameters - see `parameters` in `createRequest`\n *\n * @param deserializerFn - the deserializer function that is applied on the response object\n *\n * @param isMap - is `true` when the response object should be handled as a map\n *\n * @returns a Promise\n */\n",
1032
+ "excerptTokens": [
1033
+ {
1034
+ "kind": "Content",
1035
+ "text": "protected createRequestAndDeserializeResponse(parameters: "
1036
+ },
1037
+ {
1038
+ "kind": "Content",
1039
+ "text": "any"
1040
+ },
1041
+ {
1042
+ "kind": "Content",
1043
+ "text": ", deserializerFn: "
1044
+ },
1045
+ {
1046
+ "kind": "Content",
1047
+ "text": "(any: any) => any"
1048
+ },
1049
+ {
1050
+ "kind": "Content",
1051
+ "text": ", isMap?: "
1052
+ },
1053
+ {
1054
+ "kind": "Content",
1055
+ "text": "boolean"
1056
+ },
1057
+ {
1058
+ "kind": "Content",
1059
+ "text": "): "
1060
+ },
1061
+ {
1062
+ "kind": "Reference",
1063
+ "text": "Promise",
1064
+ "canonicalReference": "!Promise:interface"
1065
+ },
1066
+ {
1067
+ "kind": "Content",
1068
+ "text": "<any>"
1069
+ },
1070
+ {
1071
+ "kind": "Content",
1072
+ "text": ";"
1073
+ }
1074
+ ],
1075
+ "isStatic": false,
1076
+ "returnTypeTokenRange": {
1077
+ "startIndex": 7,
1078
+ "endIndex": 9
1079
+ },
1080
+ "releaseTag": "Public",
1081
+ "isProtected": true,
1082
+ "overloadIndex": 1,
1083
+ "parameters": [
1084
+ {
1085
+ "parameterName": "parameters",
1086
+ "parameterTypeTokenRange": {
1087
+ "startIndex": 1,
1088
+ "endIndex": 2
1089
+ },
1090
+ "isOptional": false
1091
+ },
1092
+ {
1093
+ "parameterName": "deserializerFn",
1094
+ "parameterTypeTokenRange": {
1095
+ "startIndex": 3,
1096
+ "endIndex": 4
1097
+ },
1098
+ "isOptional": false
1099
+ },
1100
+ {
1101
+ "parameterName": "isMap",
1102
+ "parameterTypeTokenRange": {
1103
+ "startIndex": 5,
1104
+ "endIndex": 6
1105
+ },
1106
+ "isOptional": true
1107
+ }
1108
+ ],
1109
+ "isOptional": false,
1110
+ "isAbstract": false,
1111
+ "name": "createRequestAndDeserializeResponse"
1112
+ },
948
1113
  {
949
1114
  "kind": "Property",
950
1115
  "canonicalReference": "ibm-cloud-sdk-core!BaseService.DEFAULT_SERVICE_NAME:member",
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2014, 2022.
2
+ * (C) Copyright IBM Corp. 2014, 2023.
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.
@@ -113,6 +113,16 @@ export declare class BaseService {
113
113
  * Disables retries.
114
114
  */
115
115
  disableRetries(): void;
116
+ /**
117
+ * Applies a given modifier function on a model object.
118
+ * Since the model object can be a map, or an array, or a model,
119
+ * these types needs different handling.
120
+ * Considering whether the input object is a map happens with an explicit parameter.
121
+ * @param input - the input model object
122
+ * @param converterFn - the function that is applied on the input object
123
+ * @param isMap - is `true` when the input object should be handled as a map
124
+ */
125
+ static convertModel(input: any, converterFn: any, isMap?: boolean): any;
116
126
  /**
117
127
  * Configure the service using external configuration
118
128
  *
@@ -142,5 +152,15 @@ export declare class BaseService {
142
152
  * @returns a Promise
143
153
  */
144
154
  protected createRequest(parameters: any): Promise<any>;
155
+ /**
156
+ * Wrapper around `createRequest` that enforces arrived response to be deserialized.
157
+ * @param parameters - see `parameters` in `createRequest`
158
+ * @param deserializerFn - the deserializer function that is applied on the response object
159
+ * @param isMap - is `true` when the response object should be handled as a map
160
+ * @returns a Promise
161
+ */
162
+ protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>;
145
163
  private readOptionsFromExternalConfig;
164
+ private static convertArray;
165
+ private static convertMap;
146
166
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2014, 2022.
2
+ * (C) Copyright IBM Corp. 2014, 2023.
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.
@@ -132,6 +132,28 @@ export class BaseService {
132
132
  disableRetries() {
133
133
  this.requestWrapperInstance.disableRetries();
134
134
  }
135
+ /**
136
+ * Applies a given modifier function on a model object.
137
+ * Since the model object can be a map, or an array, or a model,
138
+ * these types needs different handling.
139
+ * Considering whether the input object is a map happens with an explicit parameter.
140
+ * @param input - the input model object
141
+ * @param converterFn - the function that is applied on the input object
142
+ * @param isMap - is `true` when the input object should be handled as a map
143
+ */
144
+ static convertModel(input, converterFn, isMap) {
145
+ if (input == null || typeof input === 'string') {
146
+ // no need for conversation
147
+ return input;
148
+ }
149
+ if (Array.isArray(input)) {
150
+ return BaseService.convertArray(input, converterFn, isMap);
151
+ }
152
+ else if (isMap === true) {
153
+ return BaseService.convertMap(input, converterFn);
154
+ }
155
+ return converterFn(input);
156
+ }
135
157
  /**
136
158
  * Configure the service using external configuration
137
159
  *
@@ -179,6 +201,25 @@ export class BaseService {
179
201
  // resolve() handles rejection as well, so resolving the result of sendRequest should allow for proper handling later
180
202
  this.requestWrapperInstance.sendRequest(parameters));
181
203
  }
204
+ /**
205
+ * Wrapper around `createRequest` that enforces arrived response to be deserialized.
206
+ * @param parameters - see `parameters` in `createRequest`
207
+ * @param deserializerFn - the deserializer function that is applied on the response object
208
+ * @param isMap - is `true` when the response object should be handled as a map
209
+ * @returns a Promise
210
+ */
211
+ createRequestAndDeserializeResponse(parameters, deserializerFn, isMap) {
212
+ return new Promise((resolve, reject) => {
213
+ this.createRequest(parameters)
214
+ .then((r) => {
215
+ if (r !== undefined && r.result !== undefined) {
216
+ r.result = BaseService.convertModel(r.result, deserializerFn, isMap);
217
+ }
218
+ resolve(r);
219
+ })
220
+ .catch((err) => reject(err));
221
+ });
222
+ }
182
223
  // eslint-disable-next-line class-methods-use-this
183
224
  readOptionsFromExternalConfig(serviceName) {
184
225
  const results = {};
@@ -210,4 +251,18 @@ export class BaseService {
210
251
  }
211
252
  return results;
212
253
  }
254
+ static convertArray(arrayInput, converterFn, isMap) {
255
+ const serializedList = [];
256
+ arrayInput.forEach((element) => {
257
+ serializedList.push(this.convertModel(element, converterFn, isMap));
258
+ });
259
+ return serializedList;
260
+ }
261
+ static convertMap(mapInput, converterFn) {
262
+ const serializedMap = {};
263
+ Object.keys(mapInput).forEach((key) => {
264
+ serializedMap[key] = BaseService.convertModel(mapInput[key], converterFn);
265
+ });
266
+ return serializedMap;
267
+ }
213
268
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2022.
2
+ * (C) Copyright IBM Corp. 2022, 2023.
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,11 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
16
+ import { Axios } from 'axios';
17
17
  import { CookieJar } from 'tough-cookie';
18
- export declare class CookieInterceptor {
19
- private readonly cookieJar;
20
- constructor(cookieJar: CookieJar | boolean);
21
- requestInterceptor(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
22
- responseInterceptor(response: AxiosResponse): Promise<AxiosResponse<any, any>>;
23
- }
18
+ export declare const createCookieInterceptor: (cookieJar: CookieJar | boolean) => (axios: Axios) => void;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2022.
2
+ * (C) Copyright IBM Corp. 2022, 2023.
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.
@@ -22,31 +22,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  step((generator = generator.apply(thisArg, _arguments || [])).next());
23
23
  });
24
24
  };
25
+ import { isAxiosError } from 'axios';
25
26
  import extend from 'extend';
26
27
  import { CookieJar } from 'tough-cookie';
27
28
  import logger from './logger';
28
- export class CookieInterceptor {
29
- constructor(cookieJar) {
30
- if (cookieJar) {
31
- if (cookieJar === true) {
32
- logger.debug('CookieInterceptor: creating new CookieJar');
33
- this.cookieJar = new CookieJar();
34
- }
35
- else {
36
- logger.debug('CookieInterceptor: using supplied CookieJar');
37
- this.cookieJar = cookieJar;
38
- }
39
- }
40
- else {
41
- throw new Error('Must supply a cookie jar or true.');
42
- }
43
- }
44
- requestInterceptor(config) {
29
+ const internalCreateCookieInterceptor = (cookieJar) => {
30
+ /**
31
+ * This is called by Axios when a request is about to be sent in order to
32
+ * copy the cookie string from the URL to a request header.
33
+ *
34
+ * @param config the Axios request config
35
+ * @returns the request config
36
+ */
37
+ function requestInterceptor(config) {
45
38
  return __awaiter(this, void 0, void 0, function* () {
46
39
  logger.debug('CookieInterceptor: intercepting request');
47
40
  if (config && config.url) {
48
41
  logger.debug(`CookieInterceptor: getting cookies for: ${config.url}`);
49
- const cookieHeaderValue = yield this.cookieJar.getCookieString(config.url);
42
+ const cookieHeaderValue = yield cookieJar.getCookieString(config.url);
50
43
  if (cookieHeaderValue) {
51
44
  logger.debug('CookieInterceptor: setting cookie header');
52
45
  const cookieHeader = { cookie: cookieHeaderValue };
@@ -62,25 +55,65 @@ export class CookieInterceptor {
62
55
  return config;
63
56
  });
64
57
  }
65
- responseInterceptor(response) {
58
+ /**
59
+ * This is called by Axios when a 2xx response has been received.
60
+ * We'll invoke the configured cookie jar's setCookie() method to handle
61
+ * the "set-cookie" header.
62
+ * @param response the Axios response object
63
+ * @returns the response object
64
+ */
65
+ function responseInterceptor(response) {
66
66
  return __awaiter(this, void 0, void 0, function* () {
67
- logger.debug('CookieInterceptor: intercepting response.');
68
- if (response && response.headers) {
69
- logger.debug('CookieInterceptor: checking for set-cookie headers.');
70
- const cookies = response.headers['set-cookie'];
71
- if (cookies) {
72
- logger.debug(`CookieInterceptor: setting cookies in jar for URL ${response.config.url}.`);
73
- // Write cookies sequentially by chaining the promises in a reduce
74
- yield cookies.reduce((cookiePromise, cookie) => cookiePromise.then(() => this.cookieJar.setCookie(cookie, response.config.url)), Promise.resolve(null));
75
- }
76
- else {
77
- logger.debug('CookieInterceptor: no set-cookie headers.');
78
- }
67
+ logger.debug('CookieInterceptor: intercepting response to check for set-cookie headers.');
68
+ const cookies = response.headers['set-cookie'];
69
+ if (cookies) {
70
+ logger.debug(`CookieInterceptor: setting cookies in jar for URL ${response.config.url}.`);
71
+ // Write cookies sequentially by chaining the promises in a reduce
72
+ yield cookies.reduce((cookiePromise, cookie) => cookiePromise.then(() => cookieJar.setCookie(cookie, response.config.url)), Promise.resolve(null));
79
73
  }
80
74
  else {
81
- logger.debug('CookieInterceptor: no response headers.');
75
+ logger.debug('CookieInterceptor: no set-cookie headers.');
82
76
  }
83
77
  return response;
84
78
  });
85
79
  }
86
- }
80
+ /**
81
+ * This is called by Axios when a non-2xx response has been received.
82
+ * We'll simply invoke the "responseFulfilled" method since we want to
83
+ * do the same cookie handler as for a success response.
84
+ * @param error the Axios error object that describes the non-2xx response
85
+ * @returns the error object
86
+ */
87
+ function responseRejected(error) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ logger.debug('CookieIntercepter: intercepting error response');
90
+ if (isAxiosError(error)) {
91
+ logger.debug('CookieIntercepter: delegating to responseInterceptor()');
92
+ yield responseInterceptor(error.response);
93
+ }
94
+ else {
95
+ logger.debug('CookieInterceptor: no response field in error object, skipping...');
96
+ }
97
+ return Promise.reject(error);
98
+ });
99
+ }
100
+ return (axios) => {
101
+ axios.interceptors.request.use(requestInterceptor);
102
+ axios.interceptors.response.use(responseInterceptor, responseRejected);
103
+ };
104
+ };
105
+ export const createCookieInterceptor = (cookieJar) => {
106
+ if (cookieJar) {
107
+ if (cookieJar === true) {
108
+ logger.debug('CookieInterceptor: creating new CookieJar');
109
+ return internalCreateCookieInterceptor(new CookieJar());
110
+ }
111
+ else {
112
+ logger.debug('CookieInterceptor: using supplied CookieJar');
113
+ return internalCreateCookieInterceptor(cookieJar);
114
+ }
115
+ }
116
+ else {
117
+ throw new Error('Must supply a cookie jar or true.');
118
+ }
119
+ };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2014, 2022.
2
+ * (C) Copyright IBM Corp. 2014, 2023.
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.
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  /**
12
- * (C) Copyright IBM Corp. 2014, 2022.
12
+ * (C) Copyright IBM Corp. 2014, 2023.
13
13
  *
14
14
  * Licensed under the Apache License, Version 2.0 (the "License");
15
15
  * you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import { gzipSync } from 'zlib';
34
34
  import { buildRequestFileObject, isEmptyObject, isFileData, isFileWithMetadata, isJsonMimeType, stripTrailingSlash, } from './helper';
35
35
  import logger from './logger';
36
36
  import { streamToPromise } from './stream-to-promise';
37
- import { CookieInterceptor } from './cookie-support';
37
+ import { createCookieInterceptor } from './cookie-support';
38
38
  import { chainError } from './chain-error';
39
39
  export class RequestWrapper {
40
40
  constructor(axiosOptions) {
@@ -71,13 +71,9 @@ export class RequestWrapper {
71
71
  ['post', 'put', 'patch'].forEach((op) => {
72
72
  this.axiosInstance.defaults.headers[op]['Content-Type'] = 'application/json';
73
73
  });
74
- // if a cookie jar is provided, wrap the axios instance and update defaults
74
+ // if a cookie jar is provided, register our cookie interceptors with axios
75
75
  if (axiosOptions.jar) {
76
- const cookieInterceptor = new CookieInterceptor(axiosOptions.jar);
77
- const requestCookieInterceptor = (config) => cookieInterceptor.requestInterceptor(config);
78
- const responseCookieInterceptor = (response) => cookieInterceptor.responseInterceptor(response);
79
- this.axiosInstance.interceptors.request.use(requestCookieInterceptor);
80
- this.axiosInstance.interceptors.response.use(responseCookieInterceptor);
76
+ createCookieInterceptor(axiosOptions.jar)(this.axiosInstance);
81
77
  }
82
78
  // get retry config properties and conditionally enable retries
83
79
  if (axiosOptions.enableRetries) {
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.36.0"
8
+ "packageVersion": "7.36.1"
9
9
  }
10
10
  ]
11
11
  }
@@ -55,7 +55,9 @@ export class BaseService {
55
55
  // (undocumented)
56
56
  protected baseOptions: BaseServiceOptions;
57
57
  protected configureService(serviceName: string): void;
58
+ static convertModel(input: any, converterFn: any, isMap?: boolean): any;
58
59
  protected createRequest(parameters: any): Promise<any>;
60
+ protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>;
59
61
  // (undocumented)
60
62
  static DEFAULT_SERVICE_NAME: string;
61
63
  // (undocumented)
@@ -178,6 +178,16 @@ export declare class BaseService {
178
178
  * Disables retries.
179
179
  */
180
180
  disableRetries(): void;
181
+ /**
182
+ * Applies a given modifier function on a model object.
183
+ * Since the model object can be a map, or an array, or a model,
184
+ * these types needs different handling.
185
+ * Considering whether the input object is a map happens with an explicit parameter.
186
+ * @param input - the input model object
187
+ * @param converterFn - the function that is applied on the input object
188
+ * @param isMap - is `true` when the input object should be handled as a map
189
+ */
190
+ static convertModel(input: any, converterFn: any, isMap?: boolean): any;
181
191
  /**
182
192
  * Configure the service using external configuration
183
193
  *
@@ -207,7 +217,17 @@ export declare class BaseService {
207
217
  * @returns a Promise
208
218
  */
209
219
  protected createRequest(parameters: any): Promise<any>;
220
+ /**
221
+ * Wrapper around `createRequest` that enforces arrived response to be deserialized.
222
+ * @param parameters - see `parameters` in `createRequest`
223
+ * @param deserializerFn - the deserializer function that is applied on the response object
224
+ * @param isMap - is `true` when the response object should be handled as a map
225
+ * @returns a Promise
226
+ */
227
+ protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>;
210
228
  private readOptionsFromExternalConfig;
229
+ private static convertArray;
230
+ private static convertMap;
211
231
  }
212
232
 
213
233
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2014, 2022.
2
+ * (C) Copyright IBM Corp. 2014, 2023.
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.
@@ -113,6 +113,16 @@ export declare class BaseService {
113
113
  * Disables retries.
114
114
  */
115
115
  disableRetries(): void;
116
+ /**
117
+ * Applies a given modifier function on a model object.
118
+ * Since the model object can be a map, or an array, or a model,
119
+ * these types needs different handling.
120
+ * Considering whether the input object is a map happens with an explicit parameter.
121
+ * @param input - the input model object
122
+ * @param converterFn - the function that is applied on the input object
123
+ * @param isMap - is `true` when the input object should be handled as a map
124
+ */
125
+ static convertModel(input: any, converterFn: any, isMap?: boolean): any;
116
126
  /**
117
127
  * Configure the service using external configuration
118
128
  *
@@ -142,5 +152,15 @@ export declare class BaseService {
142
152
  * @returns a Promise
143
153
  */
144
154
  protected createRequest(parameters: any): Promise<any>;
155
+ /**
156
+ * Wrapper around `createRequest` that enforces arrived response to be deserialized.
157
+ * @param parameters - see `parameters` in `createRequest`
158
+ * @param deserializerFn - the deserializer function that is applied on the response object
159
+ * @param isMap - is `true` when the response object should be handled as a map
160
+ * @returns a Promise
161
+ */
162
+ protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>;
145
163
  private readOptionsFromExternalConfig;
164
+ private static convertArray;
165
+ private static convertMap;
146
166
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * (C) Copyright IBM Corp. 2014, 2022.
3
+ * (C) Copyright IBM Corp. 2014, 2023.
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.
@@ -149,6 +149,28 @@ var BaseService = /** @class */ (function () {
149
149
  BaseService.prototype.disableRetries = function () {
150
150
  this.requestWrapperInstance.disableRetries();
151
151
  };
152
+ /**
153
+ * Applies a given modifier function on a model object.
154
+ * Since the model object can be a map, or an array, or a model,
155
+ * these types needs different handling.
156
+ * Considering whether the input object is a map happens with an explicit parameter.
157
+ * @param input - the input model object
158
+ * @param converterFn - the function that is applied on the input object
159
+ * @param isMap - is `true` when the input object should be handled as a map
160
+ */
161
+ BaseService.convertModel = function (input, converterFn, isMap) {
162
+ if (input == null || typeof input === 'string') {
163
+ // no need for conversation
164
+ return input;
165
+ }
166
+ if (Array.isArray(input)) {
167
+ return BaseService.convertArray(input, converterFn, isMap);
168
+ }
169
+ else if (isMap === true) {
170
+ return BaseService.convertMap(input, converterFn);
171
+ }
172
+ return converterFn(input);
173
+ };
152
174
  /**
153
175
  * Configure the service using external configuration
154
176
  *
@@ -198,6 +220,26 @@ var BaseService = /** @class */ (function () {
198
220
  return _this.requestWrapperInstance.sendRequest(parameters);
199
221
  });
200
222
  };
223
+ /**
224
+ * Wrapper around `createRequest` that enforces arrived response to be deserialized.
225
+ * @param parameters - see `parameters` in `createRequest`
226
+ * @param deserializerFn - the deserializer function that is applied on the response object
227
+ * @param isMap - is `true` when the response object should be handled as a map
228
+ * @returns a Promise
229
+ */
230
+ BaseService.prototype.createRequestAndDeserializeResponse = function (parameters, deserializerFn, isMap) {
231
+ var _this = this;
232
+ return new Promise(function (resolve, reject) {
233
+ _this.createRequest(parameters)
234
+ .then(function (r) {
235
+ if (r !== undefined && r.result !== undefined) {
236
+ r.result = BaseService.convertModel(r.result, deserializerFn, isMap);
237
+ }
238
+ resolve(r);
239
+ })
240
+ .catch(function (err) { return reject(err); });
241
+ });
242
+ };
201
243
  // eslint-disable-next-line class-methods-use-this
202
244
  BaseService.prototype.readOptionsFromExternalConfig = function (serviceName) {
203
245
  var results = {};
@@ -229,6 +271,21 @@ var BaseService = /** @class */ (function () {
229
271
  }
230
272
  return results;
231
273
  };
274
+ BaseService.convertArray = function (arrayInput, converterFn, isMap) {
275
+ var _this = this;
276
+ var serializedList = [];
277
+ arrayInput.forEach(function (element) {
278
+ serializedList.push(_this.convertModel(element, converterFn, isMap));
279
+ });
280
+ return serializedList;
281
+ };
282
+ BaseService.convertMap = function (mapInput, converterFn) {
283
+ var serializedMap = {};
284
+ Object.keys(mapInput).forEach(function (key) {
285
+ serializedMap[key] = BaseService.convertModel(mapInput[key], converterFn);
286
+ });
287
+ return serializedMap;
288
+ };
232
289
  return BaseService;
233
290
  }());
234
291
  exports.BaseService = BaseService;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2022.
2
+ * (C) Copyright IBM Corp. 2022, 2023.
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,11 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
16
+ import { Axios } from 'axios';
17
17
  import { CookieJar } from 'tough-cookie';
18
- export declare class CookieInterceptor {
19
- private readonly cookieJar;
20
- constructor(cookieJar: CookieJar | boolean);
21
- requestInterceptor(config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig<any>>;
22
- responseInterceptor(response: AxiosResponse): Promise<AxiosResponse<any, any>>;
23
- }
18
+ export declare const createCookieInterceptor: (cookieJar: CookieJar | boolean) => (axios: Axios) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * (C) Copyright IBM Corp. 2022.
3
+ * (C) Copyright IBM Corp. 2022, 2023.
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.
@@ -54,27 +54,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
54
54
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
55
  };
56
56
  Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.CookieInterceptor = void 0;
57
+ exports.createCookieInterceptor = void 0;
58
+ var axios_1 = require("axios");
58
59
  var extend_1 = __importDefault(require("extend"));
59
60
  var tough_cookie_1 = require("tough-cookie");
60
61
  var logger_1 = __importDefault(require("./logger"));
61
- var CookieInterceptor = /** @class */ (function () {
62
- function CookieInterceptor(cookieJar) {
63
- if (cookieJar) {
64
- if (cookieJar === true) {
65
- logger_1.default.debug('CookieInterceptor: creating new CookieJar');
66
- this.cookieJar = new tough_cookie_1.CookieJar();
67
- }
68
- else {
69
- logger_1.default.debug('CookieInterceptor: using supplied CookieJar');
70
- this.cookieJar = cookieJar;
71
- }
72
- }
73
- else {
74
- throw new Error('Must supply a cookie jar or true.');
75
- }
76
- }
77
- CookieInterceptor.prototype.requestInterceptor = function (config) {
62
+ var internalCreateCookieInterceptor = function (cookieJar) {
63
+ /**
64
+ * This is called by Axios when a request is about to be sent in order to
65
+ * copy the cookie string from the URL to a request header.
66
+ *
67
+ * @param config the Axios request config
68
+ * @returns the request config
69
+ */
70
+ function requestInterceptor(config) {
78
71
  return __awaiter(this, void 0, void 0, function () {
79
72
  var cookieHeaderValue, cookieHeader;
80
73
  return __generator(this, function (_a) {
@@ -83,7 +76,7 @@ var CookieInterceptor = /** @class */ (function () {
83
76
  logger_1.default.debug('CookieInterceptor: intercepting request');
84
77
  if (!(config && config.url)) return [3 /*break*/, 2];
85
78
  logger_1.default.debug("CookieInterceptor: getting cookies for: ".concat(config.url));
86
- return [4 /*yield*/, this.cookieJar.getCookieString(config.url)];
79
+ return [4 /*yield*/, cookieJar.getCookieString(config.url)];
87
80
  case 1:
88
81
  cookieHeaderValue = _a.sent();
89
82
  if (cookieHeaderValue) {
@@ -102,23 +95,27 @@ var CookieInterceptor = /** @class */ (function () {
102
95
  }
103
96
  });
104
97
  });
105
- };
106
- CookieInterceptor.prototype.responseInterceptor = function (response) {
98
+ }
99
+ /**
100
+ * This is called by Axios when a 2xx response has been received.
101
+ * We'll invoke the configured cookie jar's setCookie() method to handle
102
+ * the "set-cookie" header.
103
+ * @param response the Axios response object
104
+ * @returns the response object
105
+ */
106
+ function responseInterceptor(response) {
107
107
  return __awaiter(this, void 0, void 0, function () {
108
108
  var cookies;
109
- var _this = this;
110
109
  return __generator(this, function (_a) {
111
110
  switch (_a.label) {
112
111
  case 0:
113
- logger_1.default.debug('CookieInterceptor: intercepting response.');
114
- if (!(response && response.headers)) return [3 /*break*/, 4];
115
- logger_1.default.debug('CookieInterceptor: checking for set-cookie headers.');
112
+ logger_1.default.debug('CookieInterceptor: intercepting response to check for set-cookie headers.');
116
113
  cookies = response.headers['set-cookie'];
117
114
  if (!cookies) return [3 /*break*/, 2];
118
115
  logger_1.default.debug("CookieInterceptor: setting cookies in jar for URL ".concat(response.config.url, "."));
119
116
  // Write cookies sequentially by chaining the promises in a reduce
120
117
  return [4 /*yield*/, cookies.reduce(function (cookiePromise, cookie) {
121
- return cookiePromise.then(function () { return _this.cookieJar.setCookie(cookie, response.config.url); });
118
+ return cookiePromise.then(function () { return cookieJar.setCookie(cookie, response.config.url); });
122
119
  }, Promise.resolve(null))];
123
120
  case 1:
124
121
  // Write cookies sequentially by chaining the promises in a reduce
@@ -127,15 +124,56 @@ var CookieInterceptor = /** @class */ (function () {
127
124
  case 2:
128
125
  logger_1.default.debug('CookieInterceptor: no set-cookie headers.');
129
126
  _a.label = 3;
130
- case 3: return [3 /*break*/, 5];
131
- case 4:
132
- logger_1.default.debug('CookieInterceptor: no response headers.');
133
- _a.label = 5;
134
- case 5: return [2 /*return*/, response];
127
+ case 3: return [2 /*return*/, response];
135
128
  }
136
129
  });
137
130
  });
131
+ }
132
+ /**
133
+ * This is called by Axios when a non-2xx response has been received.
134
+ * We'll simply invoke the "responseFulfilled" method since we want to
135
+ * do the same cookie handler as for a success response.
136
+ * @param error the Axios error object that describes the non-2xx response
137
+ * @returns the error object
138
+ */
139
+ function responseRejected(error) {
140
+ return __awaiter(this, void 0, void 0, function () {
141
+ return __generator(this, function (_a) {
142
+ switch (_a.label) {
143
+ case 0:
144
+ logger_1.default.debug('CookieIntercepter: intercepting error response');
145
+ if (!(0, axios_1.isAxiosError)(error)) return [3 /*break*/, 2];
146
+ logger_1.default.debug('CookieIntercepter: delegating to responseInterceptor()');
147
+ return [4 /*yield*/, responseInterceptor(error.response)];
148
+ case 1:
149
+ _a.sent();
150
+ return [3 /*break*/, 3];
151
+ case 2:
152
+ logger_1.default.debug('CookieInterceptor: no response field in error object, skipping...');
153
+ _a.label = 3;
154
+ case 3: return [2 /*return*/, Promise.reject(error)];
155
+ }
156
+ });
157
+ });
158
+ }
159
+ return function (axios) {
160
+ axios.interceptors.request.use(requestInterceptor);
161
+ axios.interceptors.response.use(responseInterceptor, responseRejected);
138
162
  };
139
- return CookieInterceptor;
140
- }());
141
- exports.CookieInterceptor = CookieInterceptor;
163
+ };
164
+ var createCookieInterceptor = function (cookieJar) {
165
+ if (cookieJar) {
166
+ if (cookieJar === true) {
167
+ logger_1.default.debug('CookieInterceptor: creating new CookieJar');
168
+ return internalCreateCookieInterceptor(new tough_cookie_1.CookieJar());
169
+ }
170
+ else {
171
+ logger_1.default.debug('CookieInterceptor: using supplied CookieJar');
172
+ return internalCreateCookieInterceptor(cookieJar);
173
+ }
174
+ }
175
+ else {
176
+ throw new Error('Must supply a cookie jar or true.');
177
+ }
178
+ };
179
+ exports.createCookieInterceptor = createCookieInterceptor;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * (C) Copyright IBM Corp. 2014, 2022.
2
+ * (C) Copyright IBM Corp. 2014, 2023.
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.
@@ -76,7 +76,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
76
76
  Object.defineProperty(exports, "__esModule", { value: true });
77
77
  exports.RequestWrapper = void 0;
78
78
  /**
79
- * (C) Copyright IBM Corp. 2014, 2022.
79
+ * (C) Copyright IBM Corp. 2014, 2023.
80
80
  *
81
81
  * Licensed under the Apache License, Version 2.0 (the "License");
82
82
  * you may not use this file except in compliance with the License.
@@ -139,15 +139,9 @@ var RequestWrapper = /** @class */ (function () {
139
139
  ['post', 'put', 'patch'].forEach(function (op) {
140
140
  _this.axiosInstance.defaults.headers[op]['Content-Type'] = 'application/json';
141
141
  });
142
- // if a cookie jar is provided, wrap the axios instance and update defaults
142
+ // if a cookie jar is provided, register our cookie interceptors with axios
143
143
  if (axiosOptions.jar) {
144
- var cookieInterceptor_1 = new cookie_support_1.CookieInterceptor(axiosOptions.jar);
145
- var requestCookieInterceptor = function (config) { return cookieInterceptor_1.requestInterceptor(config); };
146
- var responseCookieInterceptor = function (response) {
147
- return cookieInterceptor_1.responseInterceptor(response);
148
- };
149
- this.axiosInstance.interceptors.request.use(requestCookieInterceptor);
150
- this.axiosInstance.interceptors.response.use(responseCookieInterceptor);
144
+ (0, cookie_support_1.createCookieInterceptor)(axiosOptions.jar)(this.axiosInstance);
151
145
  }
152
146
  // get retry config properties and conditionally enable retries
153
147
  if (axiosOptions.enableRetries) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ibm-cloud-sdk-core",
3
- "version": "4.0.9",
3
+ "version": "4.1.1",
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",
@@ -55,7 +55,10 @@
55
55
  "lodash.isempty": "^4.4.0",
56
56
  "mime-types": "~2.1.18",
57
57
  "retry-axios": "^2.6.0",
58
- "tough-cookie": "^4.0.0"
58
+ "tough-cookie": "^4.1.3"
59
+ },
60
+ "overrides": {
61
+ "semver": "^7.5.3"
59
62
  },
60
63
  "browser": {
61
64
  "./auth/utils/read-credentials-file": "./auth/utils/read-credentials-file.browser",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "metadata": {
3
3
  "toolPackage": "@microsoft/api-extractor",
4
- "toolVersion": "7.36.0",
4
+ "toolVersion": "7.36.1",
5
5
  "schemaVersion": 1011,
6
6
  "oldestForwardsCompatibleVersion": 1001,
7
7
  "tsdocConfig": {
@@ -892,6 +892,86 @@
892
892
  "isAbstract": false,
893
893
  "name": "configureService"
894
894
  },
895
+ {
896
+ "kind": "Method",
897
+ "canonicalReference": "ibm-cloud-sdk-core!BaseService.convertModel:member(1)",
898
+ "docComment": "/**\n * Applies a given modifier function on a model object. Since the model object can be a map, or an array, or a model, these types needs different handling. Considering whether the input object is a map happens with an explicit parameter.\n *\n * @param input - the input model object\n *\n * @param converterFn - the function that is applied on the input object\n *\n * @param isMap - is `true` when the input object should be handled as a map\n */\n",
899
+ "excerptTokens": [
900
+ {
901
+ "kind": "Content",
902
+ "text": "static convertModel(input: "
903
+ },
904
+ {
905
+ "kind": "Content",
906
+ "text": "any"
907
+ },
908
+ {
909
+ "kind": "Content",
910
+ "text": ", converterFn: "
911
+ },
912
+ {
913
+ "kind": "Content",
914
+ "text": "any"
915
+ },
916
+ {
917
+ "kind": "Content",
918
+ "text": ", isMap?: "
919
+ },
920
+ {
921
+ "kind": "Content",
922
+ "text": "boolean"
923
+ },
924
+ {
925
+ "kind": "Content",
926
+ "text": "): "
927
+ },
928
+ {
929
+ "kind": "Content",
930
+ "text": "any"
931
+ },
932
+ {
933
+ "kind": "Content",
934
+ "text": ";"
935
+ }
936
+ ],
937
+ "isStatic": true,
938
+ "returnTypeTokenRange": {
939
+ "startIndex": 7,
940
+ "endIndex": 8
941
+ },
942
+ "releaseTag": "Public",
943
+ "isProtected": false,
944
+ "overloadIndex": 1,
945
+ "parameters": [
946
+ {
947
+ "parameterName": "input",
948
+ "parameterTypeTokenRange": {
949
+ "startIndex": 1,
950
+ "endIndex": 2
951
+ },
952
+ "isOptional": false
953
+ },
954
+ {
955
+ "parameterName": "converterFn",
956
+ "parameterTypeTokenRange": {
957
+ "startIndex": 3,
958
+ "endIndex": 4
959
+ },
960
+ "isOptional": false
961
+ },
962
+ {
963
+ "parameterName": "isMap",
964
+ "parameterTypeTokenRange": {
965
+ "startIndex": 5,
966
+ "endIndex": 6
967
+ },
968
+ "isOptional": true
969
+ }
970
+ ],
971
+ "isOptional": false,
972
+ "isAbstract": false,
973
+ "name": "convertModel"
974
+ },
895
975
  {
896
976
  "kind": "Method",
897
977
  "canonicalReference": "ibm-cloud-sdk-core!BaseService#createRequest:member(1)",
@@ -945,6 +1025,91 @@
945
1025
  "isAbstract": false,
946
1026
  "name": "createRequest"
947
1027
  },
1028
+ {
1029
+ "kind": "Method",
1030
+ "canonicalReference": "ibm-cloud-sdk-core!BaseService#createRequestAndDeserializeResponse:member(1)",
1031
+ "docComment": "/**\n * Wrapper around `createRequest` that enforces arrived response to be deserialized.\n *\n * @param parameters - see `parameters` in `createRequest`\n *\n * @param deserializerFn - the deserializer function that is applied on the response object\n *\n * @param isMap - is `true` when the response object should be handled as a map\n *\n * @returns a Promise\n */\n",
1032
+ "excerptTokens": [
1033
+ {
1034
+ "kind": "Content",
1035
+ "text": "protected createRequestAndDeserializeResponse(parameters: "
1036
+ },
1037
+ {
1038
+ "kind": "Content",
1039
+ "text": "any"
1040
+ },
1041
+ {
1042
+ "kind": "Content",
1043
+ "text": ", deserializerFn: "
1044
+ },
1045
+ {
1046
+ "kind": "Content",
1047
+ "text": "(any: any) => any"
1048
+ },
1049
+ {
1050
+ "kind": "Content",
1051
+ "text": ", isMap?: "
1052
+ },
1053
+ {
1054
+ "kind": "Content",
1055
+ "text": "boolean"
1056
+ },
1057
+ {
1058
+ "kind": "Content",
1059
+ "text": "): "
1060
+ },
1061
+ {
1062
+ "kind": "Reference",
1063
+ "text": "Promise",
1064
+ "canonicalReference": "!Promise:interface"
1065
+ },
1066
+ {
1067
+ "kind": "Content",
1068
+ "text": "<any>"
1069
+ },
1070
+ {
1071
+ "kind": "Content",
1072
+ "text": ";"
1073
+ }
1074
+ ],
1075
+ "isStatic": false,
1076
+ "returnTypeTokenRange": {
1077
+ "startIndex": 7,
1078
+ "endIndex": 9
1079
+ },
1080
+ "releaseTag": "Public",
1081
+ "isProtected": true,
1082
+ "overloadIndex": 1,
1083
+ "parameters": [
1084
+ {
1085
+ "parameterName": "parameters",
1086
+ "parameterTypeTokenRange": {
1087
+ "startIndex": 1,
1088
+ "endIndex": 2
1089
+ },
1090
+ "isOptional": false
1091
+ },
1092
+ {
1093
+ "parameterName": "deserializerFn",
1094
+ "parameterTypeTokenRange": {
1095
+ "startIndex": 3,
1096
+ "endIndex": 4
1097
+ },
1098
+ "isOptional": false
1099
+ },
1100
+ {
1101
+ "parameterName": "isMap",
1102
+ "parameterTypeTokenRange": {
1103
+ "startIndex": 5,
1104
+ "endIndex": 6
1105
+ },
1106
+ "isOptional": true
1107
+ }
1108
+ ],
1109
+ "isOptional": false,
1110
+ "isAbstract": false,
1111
+ "name": "createRequestAndDeserializeResponse"
1112
+ },
948
1113
  {
949
1114
  "kind": "Property",
950
1115
  "canonicalReference": "ibm-cloud-sdk-core!BaseService.DEFAULT_SERVICE_NAME:member",
@@ -55,7 +55,9 @@ export class BaseService {
55
55
  // (undocumented)
56
56
  protected baseOptions: BaseServiceOptions;
57
57
  protected configureService(serviceName: string): void;
58
+ static convertModel(input: any, converterFn: any, isMap?: boolean): any;
58
59
  protected createRequest(parameters: any): Promise<any>;
60
+ protected createRequestAndDeserializeResponse(parameters: any, deserializerFn: (any: any) => any, isMap?: boolean): Promise<any>;
59
61
  // (undocumented)
60
62
  static DEFAULT_SERVICE_NAME: string;
61
63
  // (undocumented)