Skip to content

Commit

Permalink
release 3.0.3-beta source code for nodejs
Browse files Browse the repository at this point in the history
  • Loading branch information
Huaweicloud-SDK committed Oct 31, 2020
1 parent ff27273 commit 0cf6d78
Show file tree
Hide file tree
Showing 45 changed files with 2,110 additions and 350 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 3.0.3-beta 2020-10-31
## HuaweiCloud SDK DevStar
- ### Features
- Add the README.MD file.
- ### Bug Fix
- None
- ### Change
- None

# 3.0.2-beta 2020-10-20
## HuaweiCloud SDK DevStar
- ### Features
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG_CN.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 3.0.3-beta 2020-10-31
## HuaweiCloud SDK DevStar
- ### 新增特性
- 增加README.MD文件
- ### 解决问题
-
- ### 特性变更
-

# 3.0.2-beta 2020-10-20
## HuaweiCloud SDK DevStar
- ### 新增特性
Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ You could obtain and install Node.js SDK through following methods:

Using npm to install project dependencies is the recommended method to use Node.js SDK:

You must install `@huaweicloud/huaweicloud-sdk-core` library no matter which product/service development kit you need to use. Take using Devstar SDK for example, you need to install `@huaweicloud/huaweicloud-sdk-core` library and `@huaweicloud/huaweicloud-sdk-devstar` library:
You must depended on `@huaweicloud/huaweicloud-sdk-core` library no matter which product/service development kit you need to use. Take using Devstar SDK for example, you need to install `@huaweicloud/huaweicloud-sdk-devstar` library:
``` xml
npm install @huaweicloud/huaweicloud-sdk-core @huaweicloud/huaweicloud-sdk-devstar
npm install @huaweicloud/huaweicloud-sdk-devstar
```

## Use Node.js SDK
Expand All @@ -35,8 +35,8 @@ You could obtain and install Node.js SDK through following methods:
// User identity authentication
import { BasicCredentials } from "@huaweicloud/huaweicloud-sdk-core/auth/BasicCredentials";
import { GlobalCredentials } from "@huaweicloud/huaweicloud-sdk-core/auth/GlobalCredentials";
// {Service}Client, replace Devstar to your specified service, take DevstarClient for example
import { DevstarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevstarClient";
// {Service}Client, replace Devstar to your specified service, take DevStarClient for example
import { DevStarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevStarClient";
// Import the corresponding product model
import { ShowJobDetailRequest } from '@huaweicloud/huaweicloud-sdk-devstar/v1/model/ShowJobDetailRequest';
```
Expand All @@ -47,7 +47,7 @@ You could obtain and install Node.js SDK through following methods:

``` nodejs
// Use default configuration
const client = DevstarClient.newBuilder()
const client = DevStarClient.newBuilder()
```

2.2 Proxy(Optional)
Expand Down Expand Up @@ -116,7 +116,7 @@ You could obtain and install Node.js SDK through following methods:
4. Initialize the {Service}Client instance

``` nodejs
const client = DevstarClient.newBuilder()
const client = DevStarClient.newBuilder()
.withCredential(basicCredentials)
.withEndpoint(endpoint)
.withProxyAgent(proxy)
Expand Down Expand Up @@ -233,20 +233,19 @@ You could obtain and install Node.js SDK through following methods:

## Code Example

- The following example shows how to query job detail, you need to substitute your real `{Service}Client` for `DevstarClient` in actual use.
- The following example shows how to query job detail, you need to substitute your real `{Service}Client` for `DevStarClient` in actual use.
- Substitute the values for `{your ak string}`, `{your sk string}`, `{your endpoint string}`, `{your project id}`and `{job id}`.

``` nodejs
import express = require('express');
import { DevstarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevstarClient";
import { DevStarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevStarClient";
import { BasicCredentials } from "@huaweicloud/huaweicloud-sdk-core/auth/BasicCredentials";
import { ShowJobDetailRequest } from '@huaweicloud/huaweicloud-sdk-devstar/v1/model/ShowJobDetailRequest';

// Create a new express application instance
const app: express.Application = express();
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
app.get('/', function (req: any, res: { send: (arg0: string) => void; }) {
const client = DevstarClient.newBuilder()
const client = DevStarClient.newBuilder()
.withCredential(new BasicCredentials()
.withAk("{your ak string}")
.withSk("{your sk string}")
Expand Down
19 changes: 9 additions & 10 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

通过 npm 安装项目依赖是使用 Node.js SDK 的推荐方法

无论您要使用哪个产品/服务的开发工具包,都必须安装@huaweicloud/huaweicloud-sdk-core。以使用虚拟私有云Devstar SDK为例,您需要安装@huaweicloud/huaweicloud-sdk-core@huaweicloud/huaweicloud-sdk-devstar
无论您要使用哪个产品/服务的开发工具包,都必须依赖@huaweicloud/huaweicloud-sdk-core。以使用虚拟私有云Devstar SDK为例,您需要安装@huaweicloud/huaweicloud-sdk-devstar
``` xml
npm install @huaweicloud/huaweicloud-sdk-core @huaweicloud/huaweicloud-sdk-devstar
npm install @huaweicloud/huaweicloud-sdk-devstar
```

### 开始使用
Expand All @@ -38,8 +38,8 @@
// 用户身份认证
import { BasicCredentials } from "@huaweicloud/huaweicloud-sdk-core/auth/BasicCredentials";
import { GlobalCredentials } from "@huaweicloud/huaweicloud-sdk-core/auth/GlobalCredentials";
// 导入指定云服务的 {Service}Client,此处以 DevstarClient 为例
import { DevstarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevstarClient";
// 导入指定云服务的 {Service}Client,此处以 DevStarClient 为例
import { DevStarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevStarClient";
// 导入相应产品的 model
import { ShowJobDetailRequest } from '@huaweicloud/huaweicloud-sdk-devstar/v1/model/ShowJobDetailRequest';
```
Expand All @@ -50,7 +50,7 @@

``` nodejs
// 使用默认配置
const client = DevstarClient.newBuilder()
const client = DevStarClient.newBuilder()
```

2.2 代理配置(可选)
Expand Down Expand Up @@ -121,8 +121,8 @@
4. 初始化客户端

``` nodejs
// 初始化指定云服务的客户端 {Service}Client ,以初始化 DevstarClient 为例
const client = DevstarClient.newBuilder()
// 初始化指定云服务的客户端 {Service}Client ,以初始化 DevStarClient 为例
const client = DevStarClient.newBuilder()
.withCredential(basicCredentials)
.withEndpoint(endpoint)
.withProxyAgent(proxy)
Expand Down Expand Up @@ -242,15 +242,14 @@

``` nodejs
import express = require('express');
import { DevstarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevstarClient";
import { DevStarClient } from "@huaweicloud/huaweicloud-sdk-devstar/v1/DevStarClient";
import { BasicCredentials } from "@huaweicloud/huaweicloud-sdk-core/auth/BasicCredentials";
import { ShowJobDetailRequest } from '@huaweicloud/huaweicloud-sdk-devstar/v1/model/ShowJobDetailRequest';

// Create a new express application instance
const app: express.Application = express();
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
app.get('/', function (req: any, res: { send: (arg0: string) => void; }) {
const client = DevstarClient.newBuilder()
const client = DevStarClient.newBuilder()
.withCredential(new BasicCredentials()
.withAk("{your ak string}")
.withSk("{your sk string}")
Expand Down
27 changes: 15 additions & 12 deletions core/ClientBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,23 @@ export class ClientBuilder<T> {
// 判断是否有_
let hash = {};
for (let key in credential) {
const value = credential[key]
if (key.indexOf('_') == -1) {
key = key.toLowerCase();
key = 'with' + key.charAt(0).toUpperCase() + key.slice(1);
} else {
const arr = key.split('_').map(item => {
item = item.toLowerCase();
return item.charAt(0).toUpperCase() + item.slice(1);
})
if (Array.isArray(arr)) {
key = 'with' + arr.join("");
if (key.indexOf("HUAWEICLOUD_SDK_") == 0) {
const value = credential[key]
key = key.substring(16);
if (key.indexOf('_') == -1) {
key = key.toLowerCase();
key = 'with' + key.charAt(0).toUpperCase() + key.slice(1);
} else {
const arr = key.split('_').map(item => {
item = item.toLowerCase();
return item.charAt(0).toUpperCase() + item.slice(1);
})
if (Array.isArray(arr)) {
key = 'with' + arr.join("");
}
}
hash[key] = value
}
hash[key] = value
}
credential = hash;
for (const key in credential) {
Expand Down
17 changes: 12 additions & 5 deletions core/http/DefaultHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class DefaultHttpClient implements HttpClient {
res.result = res.data;
delete res.data;

let requestId = res.headers['x-request-id'];
let requestId = res.headers ? res.headers['x-request-id'] : undefined;
let reponseLength = res.result ? JSON.stringify(res.result).length : 1;
log4jsLogger.info('"' + requestParams.method + ' ' + requestParams.url + '" ' + res.status + ' ' + reponseLength + ' ' + requestId);
if (process.env.DEBUG) {
Expand All @@ -169,11 +169,18 @@ export class DefaultHttpClient implements HttpClient {
let response = err.response;
DefaultHttpClient.httpResponse = err;

let requestId = response.headers['x-request-id'];
let reponseLength = response.data ? JSON.stringify(response.data).length : 1;
log4jsLogger.info('"' + requestParams.method + ' ' + requestParams.url + '" ' + response.status + ' ' + reponseLength + ' ' + requestId);
let requestId;
let reponseLength;
let status;
if (response) {
requestId = response.headers ? response.headers['x-request-id'] : undefined;
reponseLength = response.data ? JSON.stringify(response.data).length : 1;
status = response.status;
}

log4jsLogger.info('"' + requestParams.method + ' ' + requestParams.url + '" ' + status + ' ' + reponseLength + ' ' + requestId);
if (process.env.DEBUG) {
log4jsLogger.debug('request: ' + JSON.stringify(requestParams) + ". response: " + JSON.stringify(response.data));
log4jsLogger.debug('request: ' + JSON.stringify(requestParams) + ". response: " + JSON.stringify(err));
}

// return another promise that rejects with 'err' to be handled in generated code
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "huaweicloud-sdk-nodejs-v3",
"version": "3.0.2-beta",
"version": "3.0.3-beta",
"description": "Core code for Huaweicloud SDK for Node.js",
"main": "index.js",
"scripts": {
Expand Down
5 changes: 1 addition & 4 deletions services/devstar/huaweicloud-sdk-devstar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
/**
* Generated bundle index. Do not edit.
*/
export * from './v1/public-api';
export * from './v1/public-api';
Loading

0 comments on commit 0cf6d78

Please sign in to comment.