@huaweicloud/huaweicloud-sdk-core 3.1.26 → 3.1.28
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 +59 -0
- package/CHANGELOG_CN.md +59 -0
- package/ClientBuilder.d.ts +12 -17
- package/ClientBuilder.js +52 -60
- package/HcClient.d.ts +20 -8
- package/HcClient.js +47 -45
- package/README.md +44 -46
- package/README_CN.md +45 -43
- package/auth/AKSKSigner.js +1 -2
- package/auth/BasicCredentials.js +67 -24
- package/auth/GlobalCredentials.d.ts +1 -1
- package/auth/GlobalCredentials.js +80 -38
- package/auth/ICredential.d.ts +1 -0
- package/auth/ICredential.js +6 -0
- package/exception/ExceptionUtil.d.ts +2 -2
- package/exception/ExceptionUtil.js +14 -19
- package/http/DefaultHttpClient.d.ts +19 -11
- package/http/DefaultHttpClient.js +191 -113
- package/http/HttpClient.d.ts +5 -1
- package/http/IHttpRequest.d.ts +6 -4
- package/http/IHttpRequestBuilder.d.ts +2 -1
- package/http/IHttpRequestBuilder.js +6 -2
- package/internal/model/Region.d.ts +1 -1
- package/internal/model/Region.js +2 -3
- package/internal/services/iam.service.d.ts +3 -1
- package/internal/services/iam.service.js +149 -122
- package/internal/services/region.servcie.js +57 -13
- package/package.json +2 -2
- package/region/region.d.ts +7 -2
- package/region/region.js +14 -2
- package/utils/SignerUtil.d.ts +1 -2
- package/utils/SignerUtil.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
# 3.1.28 2023-03-09
|
|
2
|
+
|
|
3
|
+
### HuaweiCloud SDK AOS
|
|
4
|
+
|
|
5
|
+
- _Features_
|
|
6
|
+
- Support the following interfaces:
|
|
7
|
+
- `ListTemplates`
|
|
8
|
+
- `DeleteTemplate`
|
|
9
|
+
- `ShowTemplateMetadata`
|
|
10
|
+
- `UpdateTemplateMetadata`
|
|
11
|
+
- `ShowTemplateVersionContent`
|
|
12
|
+
- `DeleteTemplateVersion`
|
|
13
|
+
- `ShowTemplateVersionMetadata`
|
|
14
|
+
- _Bug Fix_
|
|
15
|
+
- None
|
|
16
|
+
- _Change_
|
|
17
|
+
- Changes of the interface `ListExecutionPlans`:
|
|
18
|
+
- Add the enum values `APPLY_IN_PROGRESS` to the response parameter `status`
|
|
19
|
+
- The response parameter `stack_name`, `execution_plan_name` changed to required
|
|
20
|
+
- Remove the enum values `IN_PLACE_UPDATE` from the response parameter `action` from the interface `GetExecutionPlan`
|
|
21
|
+
- The response parameter `stack_name`, `execution_plan_name` changed to required of the interface `GetExecutionPlanMetadata`
|
|
22
|
+
- Add the response parameter `resource_attributes` to the interface `ListStackResources`
|
|
23
|
+
- Changes of the interface `EstimateExecutionPlanPrice`:
|
|
24
|
+
- Add the response parameter `unsupported_message`
|
|
25
|
+
- Modify the type `object` -> `double` of the response parameter `sale_price`
|
|
26
|
+
- Modify the type `object` -> `double` of the response parameter `discount`
|
|
27
|
+
- Modify the type `object` -> `double` of the response parameter `original_price`
|
|
28
|
+
- Remove the enum values `WEEK` from the response parameter `period_type`
|
|
29
|
+
|
|
30
|
+
### HuaweiCloud SDK IoTDA
|
|
31
|
+
|
|
32
|
+
- _Features_
|
|
33
|
+
- None
|
|
34
|
+
- _Bug Fix_
|
|
35
|
+
- None
|
|
36
|
+
- _Change_
|
|
37
|
+
- Add the response parameters `connection_status_update_time`, `active_time` to the interface `UpdateDevice`
|
|
38
|
+
- Add the response parameters `connection_status_update_time`, `active_time` to the interface `ShowDevice`
|
|
39
|
+
|
|
40
|
+
### HuaweiCloud SDK OCR
|
|
41
|
+
|
|
42
|
+
- _Features_
|
|
43
|
+
- None
|
|
44
|
+
- _Bug Fix_
|
|
45
|
+
- None
|
|
46
|
+
- _Change_
|
|
47
|
+
- Add the request parameter `extended_parameters` to the interface `RecognizeAutoClassification`
|
|
48
|
+
|
|
49
|
+
# 3.1.27 2023-03-07
|
|
50
|
+
|
|
51
|
+
### HuaweiCloud SDK VOD
|
|
52
|
+
|
|
53
|
+
- _Features_
|
|
54
|
+
- Support the interface `ModifySubtitle`
|
|
55
|
+
- _Bug Fix_
|
|
56
|
+
- None
|
|
57
|
+
- _Change_
|
|
58
|
+
- None
|
|
59
|
+
|
|
1
60
|
# 3.1.26 2023-03-02
|
|
2
61
|
|
|
3
62
|
### HuaweiCloud SDK CDN
|
package/CHANGELOG_CN.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
# 3.1.28 2023-03-09
|
|
2
|
+
|
|
3
|
+
### HuaweiCloud SDK AOS
|
|
4
|
+
|
|
5
|
+
- _新增特性_
|
|
6
|
+
- 支持以下接口:
|
|
7
|
+
- `ListTemplates`
|
|
8
|
+
- `DeleteTemplate`
|
|
9
|
+
- `ShowTemplateMetadata`
|
|
10
|
+
- `UpdateTemplateMetadata`
|
|
11
|
+
- `ShowTemplateVersionContent`
|
|
12
|
+
- `DeleteTemplateVersion`
|
|
13
|
+
- `ShowTemplateVersionMetadata`
|
|
14
|
+
- _解决问题_
|
|
15
|
+
- 无
|
|
16
|
+
- _特性变更_
|
|
17
|
+
- 接口`ListExecutionPlans`:
|
|
18
|
+
- 响应参数`status`新增枚举值`APPLY_IN_PROGRESS`
|
|
19
|
+
- 响应参数`stack_name`、`execution_plan_name`改为必填
|
|
20
|
+
- 接口`GetExecutionPlan`响应参数`action`移除枚举值`IN_PLACE_UPDATE`
|
|
21
|
+
- 接口`GetExecutionPlanMetadata`响应参数`stack_name`、`execution_plan_name`改为必填
|
|
22
|
+
- 接口`ListStackResources`新增响应参数 `resource_attributes`
|
|
23
|
+
- 接口`EstimateExecutionPlanPrice`:
|
|
24
|
+
- 新增响应参数 `unsupported_message`
|
|
25
|
+
- 响应参数`sale_price`类型调整 `object` -> `double`
|
|
26
|
+
- 响应参数`discount`类型调整 `object` -> `double`
|
|
27
|
+
- 响应参数`original_price`类型调整 `object` -> `double`
|
|
28
|
+
- 响应参数`period_type`移除枚举值`WEEK`
|
|
29
|
+
|
|
30
|
+
### HuaweiCloud SDK IoTDA
|
|
31
|
+
|
|
32
|
+
- _新增特性_
|
|
33
|
+
- 无
|
|
34
|
+
- _解决问题_
|
|
35
|
+
- 无
|
|
36
|
+
- _特性变更_
|
|
37
|
+
- 接口`UpdateDevice`新增响应参数 `connection_status_update_time`、`active_time`
|
|
38
|
+
- 接口`ShowDevice`新增响应参数 `connection_status_update_time`、`active_time`
|
|
39
|
+
|
|
40
|
+
### HuaweiCloud SDK OCR
|
|
41
|
+
|
|
42
|
+
- _新增特性_
|
|
43
|
+
- 无
|
|
44
|
+
- _解决问题_
|
|
45
|
+
- 无
|
|
46
|
+
- _特性变更_
|
|
47
|
+
- 接口`RecognizeAutoClassification`新增请求参数 `extended_parameters`
|
|
48
|
+
|
|
49
|
+
# 3.1.27 2023-03-07
|
|
50
|
+
|
|
51
|
+
### HuaweiCloud SDK VOD
|
|
52
|
+
|
|
53
|
+
- _新增特性_
|
|
54
|
+
- 支持接口`ModifySubtitle`
|
|
55
|
+
- _解决问题_
|
|
56
|
+
- 无
|
|
57
|
+
- _特性变更_
|
|
58
|
+
- 无
|
|
59
|
+
|
|
1
60
|
# 3.1.26 2023-03-02
|
|
2
61
|
|
|
3
62
|
### HuaweiCloud SDK CDN
|
package/ClientBuilder.d.ts
CHANGED
|
@@ -2,37 +2,32 @@ import { HcClient } from "./HcClient";
|
|
|
2
2
|
import { ICredential } from "./auth/ICredential";
|
|
3
3
|
import { Region } from "./region/region";
|
|
4
4
|
import { UserOptions } from "./UserOptions";
|
|
5
|
-
interface CredParams {
|
|
6
|
-
ak?: string;
|
|
7
|
-
sk?: string;
|
|
8
|
-
project_id?: string;
|
|
9
|
-
domain_id?: string;
|
|
10
|
-
}
|
|
11
5
|
export declare class ClientBuilder<T> {
|
|
12
6
|
private init;
|
|
13
|
-
private
|
|
7
|
+
private endpoints?;
|
|
14
8
|
private credential?;
|
|
15
9
|
private proxyAgent?;
|
|
16
10
|
private credentialType;
|
|
17
11
|
private envParams;
|
|
18
12
|
private region?;
|
|
19
13
|
private userOptions?;
|
|
14
|
+
private credentials;
|
|
20
15
|
constructor(init: (hcClient: HcClient) => T, credentialType?: string);
|
|
21
|
-
withEndpoint(endpoint: string): ClientBuilder<T>;
|
|
16
|
+
withEndpoint(endpoint: string | string[]): ClientBuilder<T>;
|
|
22
17
|
withCredential(credential?: ICredential): ClientBuilder<T>;
|
|
23
18
|
withProxyAgent(proxyAgent: string): ClientBuilder<T>;
|
|
24
19
|
withRegion(region: Region): ClientBuilder<T>;
|
|
25
20
|
withOptions(options: UserOptions): ClientBuilder<T>;
|
|
26
21
|
build(): T;
|
|
27
22
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
23
|
+
* Get 'HUAWEICLOUD_SDK_TYPE' from environment variables
|
|
24
|
+
* If the variable does not exist, use the first credential type
|
|
25
|
+
* Generate credential entity
|
|
26
|
+
* Assign AK, SK, projectId/domainId from the environment variables
|
|
27
|
+
* If the environment variable is 'GlobalCredentials', assign the domainId
|
|
28
|
+
* @returns ICredential
|
|
33
29
|
*/
|
|
34
|
-
getCredentialFromEnvironment
|
|
35
|
-
whichCredential
|
|
36
|
-
getInputParamCredential
|
|
30
|
+
private getCredentialFromEnvironment;
|
|
31
|
+
private whichCredential;
|
|
32
|
+
private getInputParamCredential;
|
|
37
33
|
}
|
|
38
|
-
export {};
|
package/ClientBuilder.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2023 Huawei Technologies Co.,Ltd.
|
|
4
4
|
*
|
|
5
5
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
6
6
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -54,13 +54,21 @@ var ClientBuilder = /** @class */ (function () {
|
|
|
54
54
|
function ClientBuilder(init, credentialType) {
|
|
55
55
|
this.credentialType = ["BasicCredentials", "GlobalCredentials"];
|
|
56
56
|
this.envParams = process.env;
|
|
57
|
+
this.credentials = {};
|
|
57
58
|
this.init = init;
|
|
58
59
|
if (credentialType) {
|
|
59
60
|
this.credentialType = credentialType.split(",");
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
ClientBuilder.prototype.withEndpoint = function (endpoint) {
|
|
63
|
-
|
|
64
|
+
var _a;
|
|
65
|
+
this.endpoints = [];
|
|
66
|
+
if (typeof endpoint === 'string') {
|
|
67
|
+
this.endpoints.push(endpoint);
|
|
68
|
+
}
|
|
69
|
+
else if (Array.isArray(endpoint)) {
|
|
70
|
+
(_a = this.endpoints).push.apply(_a, endpoint);
|
|
71
|
+
}
|
|
64
72
|
return this;
|
|
65
73
|
};
|
|
66
74
|
ClientBuilder.prototype.withCredential = function (credential) {
|
|
@@ -100,20 +108,22 @@ var ClientBuilder = /** @class */ (function () {
|
|
|
100
108
|
if (!this.credential) {
|
|
101
109
|
throw new SdkException_1.SdkException("credential can not be null, ".concat(this.credentialType, "Credential objects are required"));
|
|
102
110
|
}
|
|
103
|
-
var client = new DefaultHttpClient_1.DefaultHttpClient(axiosOptions);
|
|
104
|
-
var hcClient = new HcClient_1.HcClient(client);
|
|
105
|
-
hcClient.withEndpoint(this.endpoint).withCredential(this.credential);
|
|
106
111
|
if (this.region) {
|
|
107
|
-
|
|
112
|
+
this.endpoints = this.region.endpoints;
|
|
108
113
|
}
|
|
114
|
+
var client = new DefaultHttpClient_1.DefaultHttpClient(axiosOptions, this.endpoints);
|
|
115
|
+
var hcClient = new HcClient_1.HcClient(client);
|
|
116
|
+
this.region && hcClient.withRegion(this.region);
|
|
117
|
+
hcClient.withCredential(this.credential).withEndpoints(this.endpoints);
|
|
109
118
|
return this.init(hcClient);
|
|
110
119
|
};
|
|
111
120
|
/**
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
121
|
+
* Get 'HUAWEICLOUD_SDK_TYPE' from environment variables
|
|
122
|
+
* If the variable does not exist, use the first credential type
|
|
123
|
+
* Generate credential entity
|
|
124
|
+
* Assign AK, SK, projectId/domainId from the environment variables
|
|
125
|
+
* If the environment variable is 'GlobalCredentials', assign the domainId
|
|
126
|
+
* @returns ICredential
|
|
117
127
|
*/
|
|
118
128
|
ClientBuilder.prototype.getCredentialFromEnvironment = function () {
|
|
119
129
|
var sdkType = process.env.HUAWEICLOUD_SDK_TYPE;
|
|
@@ -121,62 +131,44 @@ var ClientBuilder = /** @class */ (function () {
|
|
|
121
131
|
return this.getInputParamCredential(credentialTYPE, this.envParams);
|
|
122
132
|
};
|
|
123
133
|
ClientBuilder.prototype.whichCredential = function (sdkType) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
switch (sdkType) {
|
|
127
|
-
case 'BasicCredentials':
|
|
128
|
-
credentialTYPE = new BasicCredentials_1.BasicCredentials();
|
|
129
|
-
break;
|
|
130
|
-
case 'GlobalCredentials':
|
|
131
|
-
credentialTYPE = new GlobalCredentials_1.GlobalCredentials();
|
|
132
|
-
break;
|
|
133
|
-
default:
|
|
134
|
-
var obj = {};
|
|
135
|
-
var definedCredPath = path.join(this.init().getPath(), "".concat(sdkType));
|
|
136
|
-
if (!obj[sdkType]) {
|
|
137
|
-
credentialTYPE = require(definedCredPath);
|
|
138
|
-
// 多加一层
|
|
139
|
-
obj[sdkType] = credentialTYPE[sdkType];
|
|
140
|
-
}
|
|
141
|
-
credentialTYPE = new obj[sdkType]();
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
134
|
+
if (!sdkType) {
|
|
135
|
+
return new BasicCredentials_1.BasicCredentials();
|
|
144
136
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
137
|
+
switch (sdkType) {
|
|
138
|
+
case 'BasicCredentials':
|
|
139
|
+
return new BasicCredentials_1.BasicCredentials();
|
|
140
|
+
case 'GlobalCredentials':
|
|
141
|
+
return new GlobalCredentials_1.GlobalCredentials();
|
|
142
|
+
default:
|
|
143
|
+
if (this.credentials[sdkType]) {
|
|
144
|
+
return this.credentials[sdkType];
|
|
145
|
+
}
|
|
146
|
+
var definedCredPath = path.join(this.init().getPath(), "".concat(sdkType));
|
|
147
|
+
var credentialTYPE = require(definedCredPath);
|
|
148
|
+
this.credentials[sdkType] = new credentialTYPE();
|
|
149
|
+
return this.credentials[sdkType];
|
|
148
150
|
}
|
|
149
|
-
return credentialTYPE;
|
|
150
151
|
};
|
|
151
152
|
ClientBuilder.prototype.getInputParamCredential = function (CredentialsType, credential) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (key.indexOf('_') == -1) {
|
|
159
|
-
key = key.toLowerCase();
|
|
160
|
-
key = 'with' + key.charAt(0).toUpperCase() + key.slice(1);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
var arr = key.split('_').map(function (item) {
|
|
164
|
-
item = item.toLowerCase();
|
|
165
|
-
return item.charAt(0).toUpperCase() + item.slice(1);
|
|
166
|
-
});
|
|
167
|
-
if (Array.isArray(arr)) {
|
|
168
|
-
key = 'with' + arr.join("");
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
hash[key] = value;
|
|
153
|
+
var hash = Object.keys(credential)
|
|
154
|
+
.filter(function (key) { return key.indexOf("HUAWEICLOUD_SDK_") === 0; })
|
|
155
|
+
.reduce(function (acc, key) {
|
|
156
|
+
var newKey = key.substring(16);
|
|
157
|
+
if (newKey.indexOf('_') === -1) {
|
|
158
|
+
newKey = "with".concat(newKey.toLowerCase().replace(/^\w/, function (c) { return c.toUpperCase(); }));
|
|
172
159
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
160
|
+
else {
|
|
161
|
+
newKey = newKey.split('_').map(function (word) { return "".concat(word.toLowerCase().replace(/^\w/, function (c) { return c.toUpperCase(); })); }).join('');
|
|
162
|
+
newKey = "with".concat(newKey);
|
|
163
|
+
}
|
|
164
|
+
acc[newKey] = credential[key];
|
|
165
|
+
return acc;
|
|
166
|
+
}, {});
|
|
167
|
+
Object.keys(hash).forEach(function (key) {
|
|
176
168
|
if (CredentialsType[key]) {
|
|
177
|
-
CredentialsType[key](
|
|
169
|
+
CredentialsType[key](hash[key]);
|
|
178
170
|
}
|
|
179
|
-
}
|
|
171
|
+
});
|
|
180
172
|
return CredentialsType;
|
|
181
173
|
};
|
|
182
174
|
return ClientBuilder;
|
package/HcClient.d.ts
CHANGED
|
@@ -2,20 +2,32 @@ import { HttpClient } from "./http/HttpClient";
|
|
|
2
2
|
import { ICredential } from "./auth/ICredential";
|
|
3
3
|
import { SdkResponse } from "./SdkResponse";
|
|
4
4
|
import { Region } from "./region/region";
|
|
5
|
+
import { ClientOptions } from "./http/DefaultHttpClient";
|
|
6
|
+
export interface HttpRequestOptions {
|
|
7
|
+
method: string;
|
|
8
|
+
url: string;
|
|
9
|
+
contentType: string;
|
|
10
|
+
queryParams: Record<string, any>;
|
|
11
|
+
pathParams: Record<string, any>;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
data: Record<string, any>;
|
|
14
|
+
}
|
|
5
15
|
export declare class HcClient {
|
|
6
16
|
private httpClient;
|
|
7
|
-
private
|
|
8
|
-
private credential;
|
|
17
|
+
private credential?;
|
|
9
18
|
private proxyAgent;
|
|
10
19
|
private static loggerName;
|
|
11
20
|
private logger;
|
|
12
|
-
region
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
private region?;
|
|
22
|
+
private clientOptions?;
|
|
23
|
+
private endpoints?;
|
|
24
|
+
constructor(client: HttpClient, clientOptions?: ClientOptions);
|
|
25
|
+
withEndpoints(endpoints?: string[]): this;
|
|
15
26
|
withCredential(credential?: ICredential): HcClient;
|
|
16
|
-
withRegion(region?: Region):
|
|
17
|
-
withHttpsAgent(proxyAgent: string):
|
|
18
|
-
|
|
27
|
+
withRegion(region?: Region): HcClient;
|
|
28
|
+
withHttpsAgent(proxyAgent: string): HcClient;
|
|
29
|
+
overrideEndpoints(endpoint?: string[]): HcClient;
|
|
30
|
+
sendRequest<T extends SdkResponse>(options: HttpRequestOptions): Promise<T>;
|
|
19
31
|
private buildRequest;
|
|
20
32
|
private extractResponse;
|
|
21
33
|
}
|
package/HcClient.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2023 Huawei Technologies Co.,Ltd.
|
|
4
4
|
*
|
|
5
5
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
6
6
|
* or more contributor license agreements. See the NOTICE file
|
|
@@ -61,16 +61,18 @@ var IHttpRequestBuilder_1 = require("./http/IHttpRequestBuilder");
|
|
|
61
61
|
var ExceptionUtil_1 = require("./exception/ExceptionUtil");
|
|
62
62
|
var logger_1 = require("./logger");
|
|
63
63
|
var SdkStreamResponse_1 = require("./SdkStreamResponse");
|
|
64
|
+
var DefaultHttpClient_1 = require("./http/DefaultHttpClient");
|
|
64
65
|
var HcClient = /** @class */ (function () {
|
|
65
|
-
function HcClient(client) {
|
|
66
|
+
function HcClient(client, clientOptions) {
|
|
66
67
|
this.proxyAgent = '';
|
|
67
68
|
this.httpClient = client;
|
|
68
69
|
// Logging
|
|
69
70
|
this.logger = (0, logger_1.getLogger)(HcClient.loggerName, logger_1.LogLevel.INFO);
|
|
70
71
|
this.logger.debug('initialized');
|
|
72
|
+
this.clientOptions = clientOptions;
|
|
71
73
|
}
|
|
72
|
-
HcClient.prototype.
|
|
73
|
-
this.
|
|
74
|
+
HcClient.prototype.withEndpoints = function (endpoints) {
|
|
75
|
+
this.endpoints = endpoints;
|
|
74
76
|
return this;
|
|
75
77
|
};
|
|
76
78
|
HcClient.prototype.withCredential = function (credential) {
|
|
@@ -85,75 +87,81 @@ var HcClient = /** @class */ (function () {
|
|
|
85
87
|
this.proxyAgent = proxyAgent;
|
|
86
88
|
return this;
|
|
87
89
|
};
|
|
90
|
+
HcClient.prototype.overrideEndpoints = function (endpoint) {
|
|
91
|
+
var client = new DefaultHttpClient_1.DefaultHttpClient(this.clientOptions, endpoint);
|
|
92
|
+
return new HcClient(client, this.clientOptions).withCredential(this.credential).withEndpoints(endpoint);
|
|
93
|
+
};
|
|
88
94
|
HcClient.prototype.sendRequest = function (options) {
|
|
89
95
|
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
var request;
|
|
91
|
-
var _this = this;
|
|
96
|
+
var request, response, error_1;
|
|
92
97
|
return __generator(this, function (_a) {
|
|
93
98
|
switch (_a.label) {
|
|
94
99
|
case 0:
|
|
95
100
|
this.logger.debug('send request');
|
|
101
|
+
this.httpClient.credentials = this.credential;
|
|
96
102
|
return [4 /*yield*/, this.buildRequest(options)];
|
|
97
103
|
case 1:
|
|
98
104
|
request = _a.sent();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
this.httpClient.httpRequest = request;
|
|
106
|
+
_a.label = 2;
|
|
107
|
+
case 2:
|
|
108
|
+
_a.trys.push([2, 4, , 5]);
|
|
109
|
+
return [4 /*yield*/, this.httpClient.sendRequest(request)];
|
|
110
|
+
case 3:
|
|
111
|
+
response = _a.sent();
|
|
112
|
+
return [2 /*return*/, this.extractResponse(response)];
|
|
113
|
+
case 4:
|
|
114
|
+
error_1 = _a.sent();
|
|
115
|
+
throw ExceptionUtil_1.ExceptionUtil.generalException(error_1);
|
|
116
|
+
case 5: return [2 /*return*/];
|
|
105
117
|
}
|
|
106
118
|
});
|
|
107
119
|
});
|
|
108
120
|
};
|
|
109
121
|
HcClient.prototype.buildRequest = function (options) {
|
|
122
|
+
var _a;
|
|
110
123
|
return __awaiter(this, void 0, void 0, function () {
|
|
111
|
-
var
|
|
112
|
-
return __generator(this, function (
|
|
113
|
-
switch (
|
|
124
|
+
var _b, url, builder, httpRequest;
|
|
125
|
+
return __generator(this, function (_c) {
|
|
126
|
+
switch (_c.label) {
|
|
114
127
|
case 0:
|
|
115
128
|
if (!this.region) return [3 /*break*/, 2];
|
|
116
|
-
|
|
117
|
-
_a = this;
|
|
129
|
+
_b = this;
|
|
118
130
|
return [4 /*yield*/, this.credential.processAuthParams(this, this.region.id)];
|
|
119
131
|
case 1:
|
|
120
|
-
|
|
121
|
-
|
|
132
|
+
_b.credential = _c.sent();
|
|
133
|
+
_c.label = 2;
|
|
122
134
|
case 2:
|
|
123
|
-
url =
|
|
124
|
-
pathParams
|
|
125
|
-
|
|
126
|
-
url = url.replace("{"
|
|
135
|
+
url = "".concat(options.url);
|
|
136
|
+
Object.entries(options.pathParams).forEach(function (_a) {
|
|
137
|
+
var key = _a[0], value = _a[1];
|
|
138
|
+
url = url.replace("{".concat(key, "}"), value + '');
|
|
127
139
|
});
|
|
128
140
|
if (options.method === 'DELETE'
|
|
129
141
|
&& (options.data && (Object.keys(options.data).length <= 0 || options.data.length <= 0))) {
|
|
130
142
|
delete options.data;
|
|
131
143
|
}
|
|
132
|
-
if (
|
|
144
|
+
if ((_a = options.headers) === null || _a === void 0 ? void 0 : _a['Content-Type']) {
|
|
133
145
|
delete options.headers['Content-Type'];
|
|
134
146
|
}
|
|
135
147
|
if (options.contentType) {
|
|
136
148
|
if (!options.headers) {
|
|
137
149
|
options.headers = {};
|
|
138
150
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
options.
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
options.headers['content-type'] = options.contentType;
|
|
145
|
-
}
|
|
151
|
+
options.headers['content-type'] = options.contentType.toLowerCase().includes('application/json')
|
|
152
|
+
? 'application/json'
|
|
153
|
+
: options.contentType;
|
|
146
154
|
}
|
|
147
155
|
builder = new IHttpRequestBuilder_1.HttpRequestBuilder();
|
|
148
156
|
httpRequest = builder
|
|
149
|
-
.withEndpoint(
|
|
157
|
+
.withEndpoint(this.endpoints[0])
|
|
158
|
+
.withUrl(url)
|
|
150
159
|
.withHeaders(options.headers)
|
|
151
160
|
.withMethod(options.method)
|
|
152
161
|
.withPathParams(options.pathParams)
|
|
153
162
|
.withData(options.data)
|
|
154
163
|
.withQueryParams(options.queryParams)
|
|
155
164
|
.build();
|
|
156
|
-
// @ts-ignore
|
|
157
165
|
httpRequest = this.credential.processAuthRequest(httpRequest);
|
|
158
166
|
if (options['responseHeaders']) {
|
|
159
167
|
httpRequest['responseHeaders'] = options['responseHeaders'];
|
|
@@ -168,24 +176,18 @@ var HcClient = /** @class */ (function () {
|
|
|
168
176
|
});
|
|
169
177
|
};
|
|
170
178
|
HcClient.prototype.extractResponse = function (result) {
|
|
179
|
+
var _a;
|
|
171
180
|
var headers = result.headers;
|
|
172
|
-
var contentType = headers['content-type'];
|
|
173
|
-
|
|
174
|
-
if (contentType
|
|
175
|
-
&& (contentType.startsWith('application/octet-stream')
|
|
176
|
-
|| contentType.startsWith("image")
|
|
177
|
-
|| contentType.startsWith("application/zip"))) {
|
|
181
|
+
var contentType = (_a = headers['content-type']) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
182
|
+
if (/(application\/octet-stream|image|application\/zip)/.test(contentType)) {
|
|
178
183
|
var streamRes = new SdkStreamResponse_1.SdkStreamResponse();
|
|
179
184
|
streamRes.body = result.data;
|
|
180
185
|
streamRes.httpStatusCode = result.statusCode;
|
|
181
186
|
return streamRes;
|
|
182
187
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
sdkRespone.httpStatusCode = result.statusCode;
|
|
187
|
-
return sdkRespone;
|
|
188
|
-
}
|
|
188
|
+
var response = typeof result.data === 'object' ? result.data : {};
|
|
189
|
+
response.httpStatusCode = result.statusCode;
|
|
190
|
+
return response;
|
|
189
191
|
};
|
|
190
192
|
HcClient.loggerName = 'HcClient';
|
|
191
193
|
return HcClient;
|