@cloudbase/cli 2.0.3 → 2.0.5
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/.editorconfig +9 -9
- package/.eslintignore +7 -7
- package/.eslintrc +35 -35
- package/.prettierrc.js +29 -29
- package/.vscode/launch.json +16 -16
- package/LICENSE +5 -5
- package/README.md +35 -35
- package/bin/cloudbase.js +5 -5
- package/changelog.md +6 -6
- package/jest.config.js +17 -17
- package/lib/commands/account/login.js +18 -18
- package/lib/commands/run/list.js +2 -3
- package/lib/commands/storage/storage.js +1 -1
- package/lib/env/login.js +7 -7
- package/lib/utils/tcbrApi/callTcbrApi.js +2 -2
- package/package.json +3 -3
- package/post-install.js +61 -61
- package/runtime/nodejs/bootstrap.js +255 -255
- package/runtime/nodejs/runtime.js +183 -183
- package/src/auth/index.ts +1 -1
- package/src/auth/login.ts +91 -91
- package/src/auth/logout.ts +7 -7
- package/src/commands/account/index.ts +2 -2
- package/src/commands/account/login.ts +192 -192
- package/src/commands/account/logout.ts +24 -24
- package/src/commands/env/base.ts +90 -90
- package/src/commands/env/create.ts +92 -92
- package/src/commands/env/domain.ts +186 -186
- package/src/commands/env/index.ts +4 -4
- package/src/commands/env/login.ts +235 -235
- package/src/commands/framework/index.ts +124 -124
- package/src/commands/functions/alias/getRoute.ts +76 -76
- package/src/commands/functions/alias/index.ts +2 -2
- package/src/commands/functions/alias/setRoute.ts +82 -82
- package/src/commands/functions/code-download.ts +100 -100
- package/src/commands/functions/code-update.ts +62 -62
- package/src/commands/functions/concurrency/delete.ts +45 -45
- package/src/commands/functions/concurrency/index.ts +2 -2
- package/src/commands/functions/concurrency/list.ts +58 -58
- package/src/commands/functions/concurrency/set.ts +47 -47
- package/src/commands/functions/config-update.ts +76 -76
- package/src/commands/functions/copy.ts +62 -62
- package/src/commands/functions/delete.ts +79 -79
- package/src/commands/functions/deploy.ts +293 -293
- package/src/commands/functions/detail.ts +138 -138
- package/src/commands/functions/index.ts +16 -16
- package/src/commands/functions/invoke.ts +121 -121
- package/src/commands/functions/layer/bind.ts +182 -182
- package/src/commands/functions/layer/common.ts +8 -8
- package/src/commands/functions/layer/create.ts +49 -49
- package/src/commands/functions/layer/delete.ts +73 -73
- package/src/commands/functions/layer/download.ts +92 -92
- package/src/commands/functions/layer/index.ts +7 -7
- package/src/commands/functions/layer/list.ts +94 -94
- package/src/commands/functions/layer/sort.ts +76 -76
- package/src/commands/functions/list.ts +68 -68
- package/src/commands/functions/log.ts +148 -148
- package/src/commands/functions/run.ts +249 -249
- package/src/commands/functions/trigger-create.ts +79 -79
- package/src/commands/functions/trigger-delete.ts +105 -105
- package/src/commands/functions/version/index.ts +1 -1
- package/src/commands/functions/version/list.ts +73 -73
- package/src/commands/functions/version/publish.ts +43 -43
- package/src/commands/gateway/create.ts +109 -109
- package/src/commands/gateway/delete.ts +81 -81
- package/src/commands/gateway/domain.ts +159 -159
- package/src/commands/gateway/index.ts +5 -5
- package/src/commands/gateway/list.ts +76 -76
- package/src/commands/gateway/switch.ts +107 -107
- package/src/commands/helpers/index.ts +2 -2
- package/src/commands/helpers/init.ts +431 -431
- package/src/commands/helpers/new.ts +117 -117
- package/src/commands/helpers/open.ts +67 -67
- package/src/commands/hosting/hosting.ts +360 -360
- package/src/commands/index.ts +13 -13
- package/src/commands/lowcode/app.ts +34 -34
- package/src/commands/lowcode/comps.ts +322 -322
- package/src/commands/lowcode/index.ts +1 -1
- package/src/commands/lowcode/utils.ts +24 -24
- package/src/commands/run/image/index.ts +4 -4
- package/src/commands/run/list.ts +2 -3
- package/src/commands/run/standalonegateway/common.ts +7 -7
- package/src/commands/run/standalonegateway/create.ts +85 -85
- package/src/commands/run/standalonegateway/destroy.ts +59 -59
- package/src/commands/run/standalonegateway/index.ts +4 -4
- package/src/commands/run/standalonegateway/list.ts +53 -53
- package/src/commands/run/standalonegateway/package.ts +62 -62
- package/src/commands/run/standalonegateway/turn.ts +63 -63
- package/src/commands/run/version/index.ts +4 -4
- package/src/commands/smart.ts +132 -132
- package/src/commands/storage/storage.ts +464 -464
- package/src/commands/third/thirdAttach.ts +49 -49
- package/src/completion/index.ts +13 -13
- package/src/decorators/captureError.ts +25 -25
- package/src/decorators/constants.ts +12 -12
- package/src/decorators/deprecate.ts +25 -25
- package/src/decorators/guard.ts +42 -42
- package/src/decorators/index.ts +7 -7
- package/src/decorators/injectParams.ts +54 -54
- package/src/decorators/params/common.ts +28 -28
- package/src/decorators/params/index.ts +35 -35
- package/src/env/domain.ts +33 -33
- package/src/env/index.ts +63 -63
- package/src/env/login.ts +80 -80
- package/src/error.ts +36 -36
- package/src/function/alias.ts +43 -43
- package/src/function/base.ts +253 -253
- package/src/function/code.ts +55 -55
- package/src/function/concurrency.ts +57 -57
- package/src/function/create.ts +78 -78
- package/src/function/delete.ts +42 -42
- package/src/function/index.ts +10 -10
- package/src/function/layer/attach.ts +68 -68
- package/src/function/layer/create.ts +63 -63
- package/src/function/layer/delete.ts +21 -21
- package/src/function/layer/download.ts +54 -54
- package/src/function/layer/index.ts +7 -7
- package/src/function/layer/list.ts +32 -32
- package/src/function/layer/sort.ts +24 -24
- package/src/function/trigger.ts +97 -97
- package/src/function/update.ts +35 -35
- package/src/function/version.ts +38 -38
- package/src/function/vpc.ts +22 -22
- package/src/gateway/index.ts +137 -137
- package/src/hosting.ts +212 -212
- package/src/index.ts +13 -13
- package/src/logger.ts +17 -17
- package/src/run/create.ts +23 -23
- package/src/run/delete.ts +15 -15
- package/src/run/image/build.ts +36 -36
- package/src/run/image/delete.ts +13 -13
- package/src/run/image/index.ts +3 -3
- package/src/run/image/info.ts +26 -26
- package/src/run/list.ts +29 -29
- package/src/run/repo.ts +24 -24
- package/src/run/standalonegateway/create.ts +24 -24
- package/src/run/standalonegateway/destroy.ts +19 -19
- package/src/run/standalonegateway/index.ts +4 -4
- package/src/run/standalonegateway/list.ts +74 -74
- package/src/run/standalonegateway/package/list.ts +24 -24
- package/src/run/standalonegateway/turn/index.ts +1 -1
- package/src/run/standalonegateway/turn/off.ts +19 -19
- package/src/run/standalonegateway/turn/on.ts +19 -19
- package/src/run/version/create.ts +68 -68
- package/src/run/version/delete.ts +15 -15
- package/src/run/version/index.ts +5 -5
- package/src/run/version/list.ts +16 -16
- package/src/run/version/modify.ts +16 -16
- package/src/run/version/repo.ts +27 -27
- package/src/run/version/update.ts +58 -58
- package/src/storage.ts +114 -114
- package/src/third/index.ts +12 -12
- package/src/utils/auth.ts +15 -15
- package/src/utils/cli-table.ts +23 -23
- package/src/utils/config.ts +39 -39
- package/src/utils/env.ts +244 -244
- package/src/utils/fs/del.ts +5 -5
- package/src/utils/fs/index.ts +71 -71
- package/src/utils/function-packer.ts +97 -97
- package/src/utils/log.ts +81 -81
- package/src/utils/net/cloud-api-request.ts +62 -62
- package/src/utils/net/credential.ts +53 -53
- package/src/utils/net/index.ts +4 -4
- package/src/utils/net/manager-service.ts +36 -36
- package/src/utils/net/proxy.ts +6 -6
- package/src/utils/notice.ts +28 -28
- package/src/utils/output/highlight.ts +5 -5
- package/src/utils/output/index.ts +2 -2
- package/src/utils/output/link.ts +10 -10
- package/src/utils/output/loading.ts +82 -82
- package/src/utils/parallel.ts +82 -82
- package/src/utils/platform/index.ts +2 -2
- package/src/utils/platform/mac.ts +21 -21
- package/src/utils/platform/os.ts +64 -64
- package/src/utils/platform/port.ts +10 -10
- package/src/utils/progress-bar.ts +38 -38
- package/src/utils/prompt/select.ts +59 -59
- package/src/utils/reporter/agree.ts +20 -20
- package/src/utils/reporter/download.ts +26 -26
- package/src/utils/reporter/index.ts +3 -3
- package/src/utils/reporter/usage.ts +20 -20
- package/src/utils/store/auth.ts +49 -49
- package/src/utils/store/common.ts +8 -8
- package/src/utils/store/db.ts +68 -68
- package/src/utils/store/index.ts +4 -4
- package/src/utils/store/usage.ts +12 -12
- package/src/utils/tcbrApi/callTcbrApi.ts +1 -1
- package/src/utils/template.ts +170 -170
- package/src/utils/tools/encoding.ts +8 -8
- package/src/utils/tools/index.ts +4 -4
- package/src/utils/tools/object.ts +33 -33
- package/src/utils/tools/time.ts +38 -38
- package/src/utils/tools/uid.ts +19 -19
- package/templates/html/loginFail.html +90 -90
- package/templates/html/loginSuccess.html +86 -86
- package/templates/server/node/_gitignore +54 -54
- package/templates/server/node/cloudbaserc.json +10 -10
- package/templates/server/node/index.js +5 -5
- package/templates/server/node/package.json +9 -9
- package/tsconfig.json +19 -19
- package/tsconfig.test.json +13 -13
- package/.vscode/settings.json +0 -3
- package/lib/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.js +0 -268
- package/lib/utils/tcbrApi/tcbr-cloud-api/error.js +0 -17
- package/lib/utils/tcbrApi/tcbr-cloud-api/index.js +0 -17
- package/lib/utils/tcbrApi/tcbr-cloud-api/request.js +0 -40
- package/lib/utils/tcbrApi/tcbr-cloud-api-request.js +0 -61
- package/src/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.ts +0 -363
- package/src/utils/tcbrApi/tcbr-cloud-api/error.ts +0 -30
- package/src/utils/tcbrApi/tcbr-cloud-api/index.ts +0 -1
- package/src/utils/tcbrApi/tcbr-cloud-api/request.ts +0 -28
- package/src/utils/tcbrApi/tcbr-cloud-api-request.ts +0 -66
- package/types/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.d.ts +0 -51
- package/types/utils/tcbrApi/tcbr-cloud-api/error.d.ts +0 -20
- package/types/utils/tcbrApi/tcbr-cloud-api/index.d.ts +0 -1
- package/types/utils/tcbrApi/tcbr-cloud-api/request.d.ts +0 -4
- package/types/utils/tcbrApi/tcbr-cloud-api-request.d.ts +0 -9
package/tsconfig.test.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compileOnSave": true,
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"target": "ES2017",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"outDir": "lib",
|
|
8
|
-
"types": ["node", "jest"],
|
|
9
|
-
"esModuleInterop": true
|
|
10
|
-
},
|
|
11
|
-
"include": ["src/**/*", "test/**/*"],
|
|
12
|
-
"exclude": ["node_modules", "test"]
|
|
13
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compileOnSave": true,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"target": "ES2017",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"outDir": "lib",
|
|
8
|
+
"types": ["node", "jest"],
|
|
9
|
+
"esModuleInterop": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*", "test/**/*"],
|
|
12
|
+
"exclude": ["node_modules", "test"]
|
|
13
|
+
}
|
package/.vscode/settings.json
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.CloudApiService = exports.nodeFetch = exports.fetchStream = exports.fetch = void 0;
|
|
16
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
17
|
-
const url_1 = require("url");
|
|
18
|
-
const query_string_1 = __importDefault(require("query-string"));
|
|
19
|
-
const request_1 = require("./request");
|
|
20
|
-
const error_1 = require("./error");
|
|
21
|
-
function isObject(x) {
|
|
22
|
-
return typeof x === 'object' && !Array.isArray(x) && x !== null;
|
|
23
|
-
}
|
|
24
|
-
function deepRemoveVoid(obj) {
|
|
25
|
-
if (Array.isArray(obj)) {
|
|
26
|
-
return obj.map(deepRemoveVoid);
|
|
27
|
-
}
|
|
28
|
-
else if (isObject(obj)) {
|
|
29
|
-
let result = {};
|
|
30
|
-
for (const key in obj) {
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
32
|
-
const value = obj[key];
|
|
33
|
-
if (typeof value !== 'undefined' && value !== null) {
|
|
34
|
-
result[key] = deepRemoveVoid(value);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return obj;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function sha256(message, secret, encoding) {
|
|
45
|
-
const hmac = crypto_1.default.createHmac('sha256', secret);
|
|
46
|
-
return hmac.update(message).digest(encoding);
|
|
47
|
-
}
|
|
48
|
-
function getHash(message) {
|
|
49
|
-
const hash = crypto_1.default.createHash('sha256');
|
|
50
|
-
return hash.update(message).digest('hex');
|
|
51
|
-
}
|
|
52
|
-
function getDate(timestamp) {
|
|
53
|
-
const date = new Date(timestamp * 1000);
|
|
54
|
-
const year = date.getUTCFullYear();
|
|
55
|
-
const month = ('0' + (date.getUTCMonth() + 1)).slice(-2);
|
|
56
|
-
const day = ('0' + date.getUTCDate()).slice(-2);
|
|
57
|
-
return `${year}-${month}-${day}`;
|
|
58
|
-
}
|
|
59
|
-
const ServiceVersionMap = {
|
|
60
|
-
tcb: '2018-06-08',
|
|
61
|
-
scf: '2018-04-16',
|
|
62
|
-
flexdb: '2018-11-27',
|
|
63
|
-
cam: '2019-01-16',
|
|
64
|
-
vpc: '2017-03-12',
|
|
65
|
-
ssl: '2019-12-05',
|
|
66
|
-
tcbr: '2022-02-17',
|
|
67
|
-
};
|
|
68
|
-
exports.fetch = request_1.fetch;
|
|
69
|
-
exports.fetchStream = request_1.fetchStream;
|
|
70
|
-
exports.nodeFetch = request_1.nodeFetch;
|
|
71
|
-
const isTokenExpired = (credential, gap = 120) => credential.tokenExpired && Number(credential.tokenExpired) < Date.now() + gap * 1000;
|
|
72
|
-
class CloudApiService {
|
|
73
|
-
constructor(options) {
|
|
74
|
-
if (!options) {
|
|
75
|
-
throw new error_1.CloudBaseError('Options cloud not be empty!');
|
|
76
|
-
}
|
|
77
|
-
const { service, baseParams, version, proxy, region, credential, getCredential, timeout = 60000 } = options;
|
|
78
|
-
this.service = service;
|
|
79
|
-
this.timeout = timeout;
|
|
80
|
-
if (this.service === 'tcb' && process.env.CLOUDBASE_TCB_CLOUDAPI_PROXY) {
|
|
81
|
-
this.proxy = process.env.CLOUDBASE_TCB_CLOUDAPI_PROXY;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
this.proxy = proxy;
|
|
85
|
-
}
|
|
86
|
-
if (this.service === 'tcb' && process.env.CLOUDBASE_TCB_CLOUDAPI_REGION) {
|
|
87
|
-
this.region = process.env.CLOUDBASE_TCB_CLOUDAPI_REGION;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.region = region || process.env.TENCENTCLOUD_REGION || 'ap-shanghai';
|
|
91
|
-
}
|
|
92
|
-
this.credential = credential;
|
|
93
|
-
this.baseParams = baseParams || {};
|
|
94
|
-
this.getCredential = getCredential;
|
|
95
|
-
this.version = ServiceVersionMap[service] || version;
|
|
96
|
-
}
|
|
97
|
-
static getInstance(options) {
|
|
98
|
-
var _a;
|
|
99
|
-
const { service } = options;
|
|
100
|
-
if ((_a = CloudApiService.serviceCacheMap) === null || _a === void 0 ? void 0 : _a[service]) {
|
|
101
|
-
return CloudApiService.serviceCacheMap[service];
|
|
102
|
-
}
|
|
103
|
-
const apiService = new CloudApiService(options);
|
|
104
|
-
CloudApiService.serviceCacheMap = Object.assign({}, CloudApiService.serviceCacheMap);
|
|
105
|
-
CloudApiService.serviceCacheMap[service] = apiService;
|
|
106
|
-
return apiService;
|
|
107
|
-
}
|
|
108
|
-
get baseUrl() {
|
|
109
|
-
const urlMap = {
|
|
110
|
-
tcb: 'https://tcb.tencentcloudapi.com',
|
|
111
|
-
flexdb: 'https://flexdb.tencentcloudapi.com',
|
|
112
|
-
lowcode: `${process.env.CLOUDBASE_LOWCODE_ENDPOINT || 'https://lcap.cloud.tencent.com'}/api/v1/cliapi`,
|
|
113
|
-
tcbr: 'https://tcbr.tencentcloudapi.com',
|
|
114
|
-
};
|
|
115
|
-
if (this.service === 'tcb' && process.env.CLOUDBASE_TCB_CLOUDAPI_HOST) {
|
|
116
|
-
return `http://${process.env.CLOUDBASE_TCB_CLOUDAPI_HOST}`;
|
|
117
|
-
}
|
|
118
|
-
if (urlMap[this.service]) {
|
|
119
|
-
return urlMap[this.service];
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
return `https://${this.service}.tencentcloudapi.com`;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
request(actionOrOptions, assignData = {}, assignMethod = 'POST') {
|
|
126
|
-
var _a;
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
let action;
|
|
129
|
-
let data;
|
|
130
|
-
let method;
|
|
131
|
-
let region;
|
|
132
|
-
if (typeof actionOrOptions === 'string') {
|
|
133
|
-
action = actionOrOptions;
|
|
134
|
-
data = assignData;
|
|
135
|
-
method = assignMethod;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
action = actionOrOptions === null || actionOrOptions === void 0 ? void 0 : actionOrOptions.action;
|
|
139
|
-
data = (actionOrOptions === null || actionOrOptions === void 0 ? void 0 : actionOrOptions.data) || {};
|
|
140
|
-
method = (actionOrOptions === null || actionOrOptions === void 0 ? void 0 : actionOrOptions.method) || 'POST';
|
|
141
|
-
region = actionOrOptions === null || actionOrOptions === void 0 ? void 0 : actionOrOptions.region;
|
|
142
|
-
}
|
|
143
|
-
this.action = action;
|
|
144
|
-
this.data = deepRemoveVoid(Object.assign(Object.assign({}, data), this.baseParams));
|
|
145
|
-
this.method = method;
|
|
146
|
-
this.url = this.baseUrl;
|
|
147
|
-
if (!((_a = this.credential) === null || _a === void 0 ? void 0 : _a.secretId) || isTokenExpired(this.credential)) {
|
|
148
|
-
if (!this.getCredential) {
|
|
149
|
-
throw new error_1.CloudBaseError('You must provide credential info!');
|
|
150
|
-
}
|
|
151
|
-
if (typeof this.getCredential !== 'function') {
|
|
152
|
-
throw new error_1.CloudBaseError('The getCredential option must be a function!');
|
|
153
|
-
}
|
|
154
|
-
const credential = yield this.getCredential();
|
|
155
|
-
if (!credential) {
|
|
156
|
-
throw new error_1.CloudBaseError('Calling getCredential function get no credential info!');
|
|
157
|
-
}
|
|
158
|
-
this.credential = credential;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const data = yield this.requestWithSign(region);
|
|
162
|
-
if (data.Response.Error) {
|
|
163
|
-
const tcError = new error_1.CloudBaseError(data.Response.Error.Message, {
|
|
164
|
-
action,
|
|
165
|
-
requestId: data.Response.RequestId,
|
|
166
|
-
code: data.Response.Error.Code,
|
|
167
|
-
original: data.Response.Error
|
|
168
|
-
});
|
|
169
|
-
throw tcError;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
return data.Response;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch (e) {
|
|
176
|
-
if (e.name === 'CloudBaseError') {
|
|
177
|
-
throw e;
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
throw new error_1.CloudBaseError(e.message, {
|
|
181
|
-
action,
|
|
182
|
-
code: e.code,
|
|
183
|
-
type: e.type
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
requestWithSign(region) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
const timestamp = Math.floor(Date.now() / 1000);
|
|
192
|
-
const { method, timeout, data } = this;
|
|
193
|
-
if (method === 'GET') {
|
|
194
|
-
this.url += '?' + query_string_1.default.stringify(data);
|
|
195
|
-
}
|
|
196
|
-
if (method === 'POST') {
|
|
197
|
-
this.payload = data;
|
|
198
|
-
}
|
|
199
|
-
const { CLOUDBASE_TCB_CLOUDAPI_HOST } = process.env;
|
|
200
|
-
if (this.service === 'tcb' && CLOUDBASE_TCB_CLOUDAPI_HOST) {
|
|
201
|
-
this.host = CLOUDBASE_TCB_CLOUDAPI_HOST;
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
this.host = new url_1.URL(this.url).host;
|
|
205
|
-
}
|
|
206
|
-
const config = {
|
|
207
|
-
method,
|
|
208
|
-
timeout,
|
|
209
|
-
headers: {
|
|
210
|
-
Host: this.host,
|
|
211
|
-
'X-TC-Action': this.action,
|
|
212
|
-
'X-TC-Region': region || this.region,
|
|
213
|
-
'X-TC-Timestamp': timestamp,
|
|
214
|
-
'X-TC-Version': this.version
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
if (this.credential.token) {
|
|
218
|
-
config.headers['X-TC-Token'] = this.credential.token;
|
|
219
|
-
}
|
|
220
|
-
if (method === 'GET') {
|
|
221
|
-
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
222
|
-
}
|
|
223
|
-
if (method === 'POST') {
|
|
224
|
-
config.body = JSON.stringify(data);
|
|
225
|
-
config.headers['Content-Type'] = 'application/json';
|
|
226
|
-
}
|
|
227
|
-
const sign = this.getRequestSign(timestamp);
|
|
228
|
-
config.headers['Authorization'] = sign;
|
|
229
|
-
return (0, exports.fetch)(this.url, config, this.proxy);
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
getRequestSign(timestamp) {
|
|
233
|
-
const { method, url, service } = this;
|
|
234
|
-
const { secretId, secretKey } = this.credential;
|
|
235
|
-
const urlObj = new url_1.URL(url);
|
|
236
|
-
let headers = '';
|
|
237
|
-
const signedHeaders = 'content-type;host';
|
|
238
|
-
if (method === 'GET') {
|
|
239
|
-
headers = 'content-type:application/x-www-form-urlencoded\n';
|
|
240
|
-
}
|
|
241
|
-
if (method === 'POST') {
|
|
242
|
-
headers = 'content-type:application/json\n';
|
|
243
|
-
}
|
|
244
|
-
let path = urlObj.pathname;
|
|
245
|
-
if (path === '/api/v1/cliapi' && service === 'lowcode') {
|
|
246
|
-
path = '//lcap.cloud.tencent.com/api/v1/cliapi';
|
|
247
|
-
headers += 'host:lcap.cloud.tencent.com\n';
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
headers += `host:${this.host}\n`;
|
|
251
|
-
}
|
|
252
|
-
const querystring = urlObj.search.slice(1);
|
|
253
|
-
const payloadHash = this.payload ? getHash(JSON.stringify(this.payload)) : getHash('');
|
|
254
|
-
const canonicalRequest = `${method}\n${path}\n${querystring}\n${headers}\n${signedHeaders}\n${payloadHash}`;
|
|
255
|
-
const date = getDate(timestamp);
|
|
256
|
-
const StringToSign = `TC3-HMAC-SHA256\n${timestamp}\n${date}/${service}/tc3_request\n${getHash(canonicalRequest)}`;
|
|
257
|
-
const kDate = sha256(date, `TC3${secretKey}`);
|
|
258
|
-
const kService = sha256(service, kDate);
|
|
259
|
-
const kSigning = sha256('tc3_request', kService);
|
|
260
|
-
const signature = sha256(StringToSign, kSigning, 'hex');
|
|
261
|
-
return `TC3-HMAC-SHA256 Credential=${secretId}/${date}/${service}/tc3_request, SignedHeaders=${signedHeaders}, Signature=${signature}`;
|
|
262
|
-
}
|
|
263
|
-
clearCredentialCache() {
|
|
264
|
-
this.credential = null;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
exports.CloudApiService = CloudApiService;
|
|
268
|
-
CloudApiService.serviceCacheMap = {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CloudBaseError = void 0;
|
|
4
|
-
class CloudBaseError extends Error {
|
|
5
|
-
constructor(message, options = {}) {
|
|
6
|
-
super();
|
|
7
|
-
this.name = 'CloudBaseError';
|
|
8
|
-
const { code = '', action = '', original = null, requestId = '', type } = options;
|
|
9
|
-
this.message = `[${action}]\nRequestId:${requestId}\n${message}`;
|
|
10
|
-
this.original = original;
|
|
11
|
-
this.code = code;
|
|
12
|
-
this.requestId = requestId;
|
|
13
|
-
this.action = action;
|
|
14
|
-
this.type = type;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.CloudBaseError = CloudBaseError;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./cloud-api-service"), exports);
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.fetchStream = exports.fetch = exports.nodeFetch = void 0;
|
|
16
|
-
const url_1 = require("url");
|
|
17
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
18
|
-
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
19
|
-
exports.nodeFetch = node_fetch_1.default;
|
|
20
|
-
function fetch(url, config = {}, proxy = '') {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
if (proxy) {
|
|
23
|
-
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
|
|
24
|
-
}
|
|
25
|
-
const escapeUrl = new url_1.URL(url).toString();
|
|
26
|
-
const res = yield (0, node_fetch_1.default)(escapeUrl, config);
|
|
27
|
-
return res.json();
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
exports.fetch = fetch;
|
|
31
|
-
function fetchStream(url, config = {}, proxy = '') {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
if (proxy) {
|
|
34
|
-
config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
|
|
35
|
-
}
|
|
36
|
-
const escapeUrl = new url_1.URL(url).toString();
|
|
37
|
-
return (0, node_fetch_1.default)(escapeUrl, config);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
exports.fetchStream = fetchStream;
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CloudApiService = void 0;
|
|
13
|
-
const toolbox_1 = require("@cloudbase/toolbox");
|
|
14
|
-
const index_1 = require("./tcbr-cloud-api/index");
|
|
15
|
-
const error_1 = require("../../error");
|
|
16
|
-
const constant_1 = require("../../constant");
|
|
17
|
-
let commonCredential;
|
|
18
|
-
const isTokenExpired = (credential, gap = 120) => credential.accessTokenExpired && Number(credential.accessTokenExpired) < Date.now() + gap * 1000;
|
|
19
|
-
class CloudApiService {
|
|
20
|
-
constructor(service, baseParams, version = '') {
|
|
21
|
-
this.apiService = new index_1.CloudApiService({
|
|
22
|
-
service,
|
|
23
|
-
version: service === 'tcr'
|
|
24
|
-
? version
|
|
25
|
-
: service === 'tcbr'
|
|
26
|
-
? '2022-02-17'
|
|
27
|
-
: '2019-09-24',
|
|
28
|
-
baseParams,
|
|
29
|
-
proxy: (0, toolbox_1.getProxy)(),
|
|
30
|
-
timeout: constant_1.REQUEST_TIMEOUT,
|
|
31
|
-
getCredential: () => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
if ((commonCredential === null || commonCredential === void 0 ? void 0 : commonCredential.secretId) && !isTokenExpired(commonCredential)) {
|
|
33
|
-
return commonCredential;
|
|
34
|
-
}
|
|
35
|
-
const credential = yield (0, toolbox_1.getCredentialWithoutCheck)();
|
|
36
|
-
if (!credential) {
|
|
37
|
-
throw new error_1.CloudBaseError('无有效身份信息,请使用 cloudbase login 登录');
|
|
38
|
-
}
|
|
39
|
-
commonCredential = credential;
|
|
40
|
-
return Object.assign(Object.assign({}, credential), { tokenExpired: Number(credential.accessTokenExpired) });
|
|
41
|
-
})
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
static getInstance(service) {
|
|
45
|
-
var _a;
|
|
46
|
-
if ((_a = CloudApiService.serviceCacheMap) === null || _a === void 0 ? void 0 : _a[service]) {
|
|
47
|
-
return CloudApiService.serviceCacheMap[service];
|
|
48
|
-
}
|
|
49
|
-
const apiService = new CloudApiService(service);
|
|
50
|
-
CloudApiService.serviceCacheMap[service] = apiService;
|
|
51
|
-
return apiService;
|
|
52
|
-
}
|
|
53
|
-
request(action, data = {}, method = 'POST') {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const region = this.region || (yield (0, toolbox_1.getRegion)());
|
|
56
|
-
return this.apiService.request({ action, data, method, region });
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.CloudApiService = CloudApiService;
|
|
61
|
-
CloudApiService.serviceCacheMap = {};
|