@cloudbase/cli 1.12.7-alpha.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/.editorconfig +9 -9
  2. package/.eslintignore +7 -7
  3. package/.eslintrc +35 -35
  4. package/.prettierrc.js +29 -29
  5. package/.vscode/launch.json +16 -16
  6. package/.vscode/settings.json +3 -0
  7. package/LICENSE +5 -5
  8. package/README.md +35 -35
  9. package/bin/cloudbase.js +5 -5
  10. package/bin/tcb.js +0 -0
  11. package/changelog.md +6 -6
  12. package/jest.config.js +17 -17
  13. package/lib/commands/account/login.js +18 -18
  14. package/lib/commands/run/create.js +6 -1
  15. package/lib/commands/run/delete.js +6 -1
  16. package/lib/commands/run/image/common.js +1 -1
  17. package/lib/commands/run/image/delete.js +5 -0
  18. package/lib/commands/run/image/download.js +5 -0
  19. package/lib/commands/run/image/list.js +5 -0
  20. package/lib/commands/run/image/upload.js +5 -0
  21. package/lib/commands/run/index.js +1 -0
  22. package/lib/commands/run/list.js +7 -1
  23. package/lib/commands/run/service/config.js +112 -0
  24. package/lib/commands/run/service/create.js +140 -0
  25. package/lib/commands/run/service/deploy.js +145 -0
  26. package/lib/commands/run/service/index.js +21 -0
  27. package/lib/commands/run/service/list.js +115 -0
  28. package/lib/commands/run/service/update.js +132 -0
  29. package/lib/commands/run/version/common.js +1 -1
  30. package/lib/commands/run/version/create.js +5 -0
  31. package/lib/commands/run/version/delete.js +5 -0
  32. package/lib/commands/run/version/list.js +5 -0
  33. package/lib/commands/run/version/modify.js +5 -0
  34. package/lib/commands/run/version/update.js +5 -0
  35. package/lib/commands/storage/storage.js +1 -1
  36. package/lib/constant.js +20 -1
  37. package/lib/env/login.js +7 -7
  38. package/lib/help.js +40 -38
  39. package/lib/run/index.js +1 -0
  40. package/lib/run/service/common.js +163 -0
  41. package/lib/run/service/config.js +70 -0
  42. package/lib/run/service/create.js +67 -0
  43. package/lib/run/service/deployPackage.js +87 -0
  44. package/lib/run/service/index.js +23 -0
  45. package/lib/run/service/list.js +31 -0
  46. package/lib/run/service/showLogs.js +116 -0
  47. package/lib/run/service/update.js +83 -0
  48. package/lib/utils/checkTcbrEnv.js +74 -0
  49. package/lib/utils/commonParamsCheck.js +48 -0
  50. package/lib/utils/index.js +3 -0
  51. package/lib/utils/tcbrApi/callTcbrApi.js +38 -0
  52. package/lib/utils/tcbrApi/index.js +17 -0
  53. package/lib/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.js +268 -0
  54. package/lib/utils/tcbrApi/tcbr-cloud-api/error.js +17 -0
  55. package/lib/utils/tcbrApi/tcbr-cloud-api/index.js +17 -0
  56. package/lib/utils/tcbrApi/tcbr-cloud-api/request.js +40 -0
  57. package/lib/utils/tcbrApi/tcbr-cloud-api-request.js +61 -0
  58. package/lib/utils/validator.js +32 -1
  59. package/package.json +88 -88
  60. package/post-install.js +61 -61
  61. package/runtime/nodejs/bootstrap.js +255 -255
  62. package/runtime/nodejs/runtime.js +183 -183
  63. package/src/auth/index.ts +1 -1
  64. package/src/auth/login.ts +91 -91
  65. package/src/auth/logout.ts +7 -7
  66. package/src/commands/account/index.ts +2 -2
  67. package/src/commands/account/login.ts +192 -192
  68. package/src/commands/account/logout.ts +24 -24
  69. package/src/commands/common.ts +246 -246
  70. package/src/commands/env/base.ts +90 -90
  71. package/src/commands/env/create.ts +92 -92
  72. package/src/commands/env/domain.ts +186 -186
  73. package/src/commands/env/index.ts +4 -4
  74. package/src/commands/env/login.ts +235 -235
  75. package/src/commands/framework/index.ts +124 -124
  76. package/src/commands/functions/alias/getRoute.ts +76 -76
  77. package/src/commands/functions/alias/index.ts +2 -2
  78. package/src/commands/functions/alias/setRoute.ts +82 -82
  79. package/src/commands/functions/code-download.ts +100 -100
  80. package/src/commands/functions/code-update.ts +62 -62
  81. package/src/commands/functions/concurrency/delete.ts +45 -45
  82. package/src/commands/functions/concurrency/index.ts +2 -2
  83. package/src/commands/functions/concurrency/list.ts +58 -58
  84. package/src/commands/functions/concurrency/set.ts +47 -47
  85. package/src/commands/functions/config-update.ts +76 -76
  86. package/src/commands/functions/copy.ts +62 -62
  87. package/src/commands/functions/delete.ts +79 -79
  88. package/src/commands/functions/deploy.ts +293 -293
  89. package/src/commands/functions/detail.ts +138 -138
  90. package/src/commands/functions/index.ts +16 -16
  91. package/src/commands/functions/invoke.ts +121 -121
  92. package/src/commands/functions/layer/bind.ts +182 -182
  93. package/src/commands/functions/layer/common.ts +8 -8
  94. package/src/commands/functions/layer/create.ts +49 -49
  95. package/src/commands/functions/layer/delete.ts +73 -73
  96. package/src/commands/functions/layer/download.ts +92 -92
  97. package/src/commands/functions/layer/index.ts +7 -7
  98. package/src/commands/functions/layer/list.ts +94 -94
  99. package/src/commands/functions/layer/sort.ts +76 -76
  100. package/src/commands/functions/list.ts +68 -68
  101. package/src/commands/functions/log.ts +148 -148
  102. package/src/commands/functions/run.ts +249 -249
  103. package/src/commands/functions/trigger-create.ts +79 -79
  104. package/src/commands/functions/trigger-delete.ts +105 -105
  105. package/src/commands/functions/version/index.ts +1 -1
  106. package/src/commands/functions/version/list.ts +73 -73
  107. package/src/commands/functions/version/publish.ts +43 -43
  108. package/src/commands/gateway/create.ts +109 -109
  109. package/src/commands/gateway/delete.ts +81 -81
  110. package/src/commands/gateway/domain.ts +159 -159
  111. package/src/commands/gateway/index.ts +5 -5
  112. package/src/commands/gateway/list.ts +76 -76
  113. package/src/commands/gateway/switch.ts +107 -107
  114. package/src/commands/helpers/index.ts +2 -2
  115. package/src/commands/helpers/init.ts +431 -431
  116. package/src/commands/helpers/new.ts +117 -117
  117. package/src/commands/helpers/open.ts +67 -67
  118. package/src/commands/hosting/hosting.ts +360 -360
  119. package/src/commands/index.ts +13 -13
  120. package/src/commands/lowcode/app.ts +34 -34
  121. package/src/commands/lowcode/comps.ts +322 -322
  122. package/src/commands/lowcode/index.ts +1 -1
  123. package/src/commands/lowcode/utils.ts +24 -24
  124. package/src/commands/run/create.ts +9 -2
  125. package/src/commands/run/delete.ts +8 -2
  126. package/src/commands/run/image/common.ts +1 -1
  127. package/src/commands/run/image/delete.ts +8 -1
  128. package/src/commands/run/image/download.ts +7 -1
  129. package/src/commands/run/image/index.ts +4 -4
  130. package/src/commands/run/image/list.ts +7 -2
  131. package/src/commands/run/image/upload.ts +8 -1
  132. package/src/commands/run/index.ts +2 -1
  133. package/src/commands/run/list.ts +11 -3
  134. package/src/commands/run/service/config.ts +81 -0
  135. package/src/commands/run/service/create.ts +118 -0
  136. package/src/commands/run/service/deploy.ts +121 -0
  137. package/src/commands/run/service/index.ts +5 -0
  138. package/src/commands/run/service/list.ts +94 -0
  139. package/src/commands/run/service/update.ts +104 -0
  140. package/src/commands/run/standalonegateway/common.ts +7 -7
  141. package/src/commands/run/standalonegateway/create.ts +85 -85
  142. package/src/commands/run/standalonegateway/destroy.ts +59 -59
  143. package/src/commands/run/standalonegateway/index.ts +4 -4
  144. package/src/commands/run/standalonegateway/list.ts +53 -53
  145. package/src/commands/run/standalonegateway/package.ts +62 -62
  146. package/src/commands/run/standalonegateway/turn.ts +63 -63
  147. package/src/commands/run/version/common.ts +1 -1
  148. package/src/commands/run/version/create.ts +8 -1
  149. package/src/commands/run/version/delete.ts +8 -2
  150. package/src/commands/run/version/index.ts +4 -4
  151. package/src/commands/run/version/list.ts +7 -1
  152. package/src/commands/run/version/modify.ts +8 -1
  153. package/src/commands/run/version/update.ts +8 -1
  154. package/src/commands/smart.ts +132 -132
  155. package/src/commands/storage/storage.ts +464 -464
  156. package/src/commands/third/thirdAttach.ts +49 -49
  157. package/src/completion/index.ts +13 -13
  158. package/src/constant.ts +35 -1
  159. package/src/decorators/captureError.ts +25 -25
  160. package/src/decorators/constants.ts +12 -12
  161. package/src/decorators/deprecate.ts +25 -25
  162. package/src/decorators/guard.ts +42 -42
  163. package/src/decorators/index.ts +7 -7
  164. package/src/decorators/injectParams.ts +54 -54
  165. package/src/decorators/params/common.ts +28 -28
  166. package/src/decorators/params/index.ts +35 -35
  167. package/src/env/domain.ts +33 -33
  168. package/src/env/index.ts +63 -63
  169. package/src/env/login.ts +80 -80
  170. package/src/error.ts +36 -36
  171. package/src/function/alias.ts +43 -43
  172. package/src/function/base.ts +253 -253
  173. package/src/function/code.ts +55 -55
  174. package/src/function/concurrency.ts +57 -57
  175. package/src/function/create.ts +78 -78
  176. package/src/function/delete.ts +42 -42
  177. package/src/function/index.ts +10 -10
  178. package/src/function/layer/attach.ts +68 -68
  179. package/src/function/layer/create.ts +63 -63
  180. package/src/function/layer/delete.ts +21 -21
  181. package/src/function/layer/download.ts +54 -54
  182. package/src/function/layer/index.ts +7 -7
  183. package/src/function/layer/list.ts +32 -32
  184. package/src/function/layer/sort.ts +24 -24
  185. package/src/function/trigger.ts +97 -97
  186. package/src/function/update.ts +35 -35
  187. package/src/function/version.ts +38 -38
  188. package/src/function/vpc.ts +22 -22
  189. package/src/gateway/index.ts +137 -137
  190. package/src/help.ts +50 -48
  191. package/src/hosting.ts +212 -212
  192. package/src/index.ts +13 -13
  193. package/src/logger.ts +17 -17
  194. package/src/run/create.ts +23 -23
  195. package/src/run/delete.ts +15 -15
  196. package/src/run/image/build.ts +36 -36
  197. package/src/run/image/delete.ts +13 -13
  198. package/src/run/image/index.ts +3 -3
  199. package/src/run/image/info.ts +26 -26
  200. package/src/run/index.ts +2 -1
  201. package/src/run/list.ts +29 -29
  202. package/src/run/repo.ts +24 -24
  203. package/src/run/service/common.ts +206 -0
  204. package/src/run/service/config.ts +77 -0
  205. package/src/run/service/create.ts +52 -0
  206. package/src/run/service/deployPackage.ts +63 -0
  207. package/src/run/service/index.ts +7 -0
  208. package/src/run/service/list.ts +29 -0
  209. package/src/run/service/showLogs.ts +98 -0
  210. package/src/run/service/update.ts +81 -0
  211. package/src/run/standalonegateway/create.ts +24 -24
  212. package/src/run/standalonegateway/destroy.ts +19 -19
  213. package/src/run/standalonegateway/index.ts +4 -4
  214. package/src/run/standalonegateway/list.ts +74 -74
  215. package/src/run/standalonegateway/package/list.ts +24 -24
  216. package/src/run/standalonegateway/turn/index.ts +1 -1
  217. package/src/run/standalonegateway/turn/off.ts +19 -19
  218. package/src/run/standalonegateway/turn/on.ts +19 -19
  219. package/src/run/version/create.ts +68 -68
  220. package/src/run/version/delete.ts +15 -15
  221. package/src/run/version/index.ts +5 -5
  222. package/src/run/version/list.ts +16 -16
  223. package/src/run/version/modify.ts +16 -16
  224. package/src/run/version/repo.ts +27 -27
  225. package/src/run/version/update.ts +58 -58
  226. package/src/storage.ts +114 -114
  227. package/src/third/index.ts +12 -12
  228. package/src/types.ts +128 -2
  229. package/src/utils/auth.ts +15 -15
  230. package/src/utils/checkTcbrEnv.ts +67 -0
  231. package/src/utils/cli-table.ts +23 -23
  232. package/src/utils/commonParamsCheck.ts +65 -0
  233. package/src/utils/config.ts +39 -39
  234. package/src/utils/env.ts +244 -244
  235. package/src/utils/fs/del.ts +5 -5
  236. package/src/utils/fs/index.ts +71 -71
  237. package/src/utils/function-packer.ts +97 -97
  238. package/src/utils/index.ts +5 -1
  239. package/src/utils/log.ts +81 -81
  240. package/src/utils/net/cloud-api-request.ts +62 -62
  241. package/src/utils/net/credential.ts +53 -53
  242. package/src/utils/net/http-request.ts +84 -84
  243. package/src/utils/net/index.ts +4 -4
  244. package/src/utils/net/manager-service.ts +36 -36
  245. package/src/utils/net/proxy.ts +6 -6
  246. package/src/utils/notice.ts +28 -28
  247. package/src/utils/output/highlight.ts +5 -5
  248. package/src/utils/output/index.ts +2 -2
  249. package/src/utils/output/link.ts +10 -10
  250. package/src/utils/output/loading.ts +82 -82
  251. package/src/utils/parallel.ts +82 -82
  252. package/src/utils/platform/index.ts +2 -2
  253. package/src/utils/platform/mac.ts +21 -21
  254. package/src/utils/platform/os.ts +64 -64
  255. package/src/utils/platform/port.ts +10 -10
  256. package/src/utils/progress-bar.ts +38 -38
  257. package/src/utils/prompt/select.ts +59 -59
  258. package/src/utils/reporter/agree.ts +20 -20
  259. package/src/utils/reporter/download.ts +26 -26
  260. package/src/utils/reporter/index.ts +3 -3
  261. package/src/utils/reporter/usage.ts +20 -20
  262. package/src/utils/store/auth.ts +49 -49
  263. package/src/utils/store/common.ts +8 -8
  264. package/src/utils/store/db.ts +68 -68
  265. package/src/utils/store/index.ts +4 -4
  266. package/src/utils/store/usage.ts +12 -12
  267. package/src/utils/tcbrApi/callTcbrApi.ts +28 -0
  268. package/src/utils/tcbrApi/index.ts +1 -0
  269. package/src/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.ts +363 -0
  270. package/src/utils/tcbrApi/tcbr-cloud-api/error.ts +30 -0
  271. package/src/utils/tcbrApi/tcbr-cloud-api/index.ts +1 -0
  272. package/src/utils/tcbrApi/tcbr-cloud-api/request.ts +28 -0
  273. package/src/utils/tcbrApi/tcbr-cloud-api-request.ts +66 -0
  274. package/src/utils/template.ts +170 -170
  275. package/src/utils/tools/encoding.ts +8 -8
  276. package/src/utils/tools/index.ts +4 -4
  277. package/src/utils/tools/object.ts +33 -33
  278. package/src/utils/tools/time.ts +38 -38
  279. package/src/utils/tools/uid.ts +19 -19
  280. package/src/utils/validator.ts +64 -32
  281. package/templates/html/loginFail.html +90 -90
  282. package/templates/html/loginSuccess.html +86 -86
  283. package/templates/server/node/_gitignore +54 -54
  284. package/templates/server/node/cloudbaserc.json +10 -10
  285. package/templates/server/node/index.js +5 -5
  286. package/templates/server/node/package.json +9 -9
  287. package/tsconfig.json +19 -19
  288. package/tsconfig.test.json +13 -13
  289. package/types/commands/run/index.d.ts +1 -0
  290. package/types/commands/run/service/config.d.ts +14 -0
  291. package/types/commands/run/service/create.d.ts +13 -0
  292. package/types/commands/run/service/deploy.d.ts +13 -0
  293. package/types/commands/run/service/index.d.ts +5 -0
  294. package/types/commands/run/service/list.d.ts +13 -0
  295. package/types/commands/run/service/update.d.ts +13 -0
  296. package/types/constant.d.ts +18 -0
  297. package/types/run/index.d.ts +1 -0
  298. package/types/run/service/common.d.ts +32 -0
  299. package/types/run/service/config.d.ts +23 -0
  300. package/types/run/service/create.d.ts +7 -0
  301. package/types/run/service/deployPackage.d.ts +11 -0
  302. package/types/run/service/index.d.ts +7 -0
  303. package/types/run/service/list.d.ts +2 -0
  304. package/types/run/service/showLogs.d.ts +2 -0
  305. package/types/run/service/update.d.ts +2 -0
  306. package/types/types.d.ts +116 -2
  307. package/types/utils/checkTcbrEnv.d.ts +3 -0
  308. package/types/utils/commonParamsCheck.d.ts +3 -0
  309. package/types/utils/index.d.ts +3 -0
  310. package/types/utils/tcbrApi/callTcbrApi.d.ts +1 -0
  311. package/types/utils/tcbrApi/index.d.ts +1 -0
  312. package/types/utils/tcbrApi/tcbr-cloud-api/cloud-api-service.d.ts +51 -0
  313. package/types/utils/tcbrApi/tcbr-cloud-api/error.d.ts +20 -0
  314. package/types/utils/tcbrApi/tcbr-cloud-api/index.d.ts +1 -0
  315. package/types/utils/tcbrApi/tcbr-cloud-api/request.d.ts +4 -0
  316. package/types/utils/tcbrApi/tcbr-cloud-api-request.d.ts +9 -0
  317. package/types/utils/validator.d.ts +4 -0
@@ -0,0 +1,116 @@
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.getLogs = exports.getBuildStatus = void 0;
16
+ const utils_1 = require("../../utils");
17
+ const chalk_1 = __importDefault(require("chalk"));
18
+ function getBuildStatus(envId, serviceName) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const { data: deployRes } = yield (0, utils_1.callTcbrApi)('DescribeCloudRunDeployRecord', {
21
+ EnvId: envId,
22
+ ServerName: serviceName,
23
+ });
24
+ if (deployRes === null || deployRes === void 0 ? void 0 : deployRes.DeployRecords) {
25
+ if ((deployRes === null || deployRes === void 0 ? void 0 : deployRes.DeployRecords[0].Status) === "deploying") {
26
+ return Promise.resolve('pending');
27
+ }
28
+ else {
29
+ return Promise.resolve('completed');
30
+ }
31
+ }
32
+ else {
33
+ return Promise.resolve('pending');
34
+ }
35
+ });
36
+ }
37
+ exports.getBuildStatus = getBuildStatus;
38
+ function getBuildId(envId, serviceName) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const { data: deployRes } = yield (0, utils_1.callTcbrApi)('DescribeCloudRunDeployRecord', {
41
+ EnvId: envId,
42
+ ServerName: serviceName,
43
+ });
44
+ if (deployRes === null || deployRes === void 0 ? void 0 : deployRes.DeployRecords) {
45
+ if (deployRes.DeployRecords[0].Status !== 'deploying') {
46
+ return Promise.resolve(deployRes.DeployRecords[0].BuildId);
47
+ }
48
+ }
49
+ });
50
+ }
51
+ function getRunId(envId, serviceName) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ return new Promise((resolve) => {
54
+ const timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
55
+ const { data: deployRes } = yield (0, utils_1.callTcbrApi)('DescribeCloudRunDeployRecord', {
56
+ EnvId: envId,
57
+ ServerName: serviceName,
58
+ });
59
+ if (deployRes === null || deployRes === void 0 ? void 0 : deployRes.DeployRecords) {
60
+ clearInterval(timer);
61
+ resolve(deployRes.DeployRecords[0].RunId);
62
+ }
63
+ }), 3000);
64
+ });
65
+ });
66
+ }
67
+ function showProcessLogs(envId, runId, serviceName) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return new Promise(resolve => {
70
+ const timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
71
+ if ((yield getBuildStatus(envId, serviceName)) === 'completed') {
72
+ clearInterval(timer);
73
+ resolve();
74
+ }
75
+ else {
76
+ const { data: processLogs } = yield (0, utils_1.callTcbrApi)('DescribeCloudRunProcessLog', {
77
+ EnvId: envId,
78
+ RunId: runId,
79
+ });
80
+ if (processLogs === null || processLogs === void 0 ? void 0 : processLogs.Logs) {
81
+ console.log(processLogs === null || processLogs === void 0 ? void 0 : processLogs.Logs.join('\n'));
82
+ }
83
+ }
84
+ }), 5000);
85
+ });
86
+ });
87
+ }
88
+ function showBuildLogs(envId, serviceName, serverVersion = '', offset = 0) {
89
+ var _a, _b;
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ const buildId = yield getBuildId(envId, serviceName);
92
+ const { data } = yield (0, utils_1.callTcbrApi)('DescribeCloudRunBuildLog', {
93
+ EnvId: envId,
94
+ BuildId: buildId,
95
+ ServerName: serviceName,
96
+ ServerVersion: serverVersion || '',
97
+ Offset: offset || 0,
98
+ });
99
+ if ((_a = data === null || data === void 0 ? void 0 : data.Log) === null || _a === void 0 ? void 0 : _a.Text) {
100
+ console.log((_b = data === null || data === void 0 ? void 0 : data.Log) === null || _b === void 0 ? void 0 : _b.Text);
101
+ }
102
+ return Promise.resolve();
103
+ });
104
+ }
105
+ function getLogs(options) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const runId = yield getRunId(options.envId, options.serviceName);
108
+ console.log(chalk_1.default.blue('============ 日志开始 ==============='));
109
+ yield showProcessLogs(options.envId, runId, options.serviceName);
110
+ if ((yield getBuildStatus(options.envId, options.serviceName)) === 'completed') {
111
+ yield showBuildLogs(options.envId, options.serviceName);
112
+ }
113
+ console.log(chalk_1.default.blue('============ 日志结束 ==============='));
114
+ });
115
+ }
116
+ exports.getLogs = getLogs;
@@ -0,0 +1,83 @@
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.updateTcbrService = exports.updateCloudRunServer = void 0;
16
+ const toolbox_1 = require("@cloudbase/toolbox");
17
+ const inquirer_1 = __importDefault(require("inquirer"));
18
+ const __1 = require("..");
19
+ const utils_1 = require("../../utils");
20
+ const common_1 = require("./common");
21
+ const showLogs_1 = require("./showLogs");
22
+ function updateCloudRunServer(serviceConfigOptions) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ try {
25
+ const res = yield (0, utils_1.callTcbrApi)('UpdateCloudRunServer', serviceConfigOptions);
26
+ return res;
27
+ }
28
+ catch (error) {
29
+ console.log(error);
30
+ }
31
+ });
32
+ }
33
+ exports.updateCloudRunServer = updateCloudRunServer;
34
+ function updateTcbrService(options) {
35
+ var _a;
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const { data: serviceDetail } = yield (0, __1.describeCloudRunServerDetail)({
38
+ envId: options.envId,
39
+ serviceName: options.serviceName
40
+ });
41
+ if (serviceDetail === undefined) {
42
+ throw new toolbox_1.CloudBaseError('当前服务不存在,请使用 tcb run service:create 创建服务');
43
+ }
44
+ const status = yield (0, showLogs_1.getBuildStatus)(options.envId, options.serviceName);
45
+ if (status === 'pending') {
46
+ throw new toolbox_1.CloudBaseError('服务正在更新部署,请稍后再试,或查看实时部署日志');
47
+ }
48
+ const previousServerConfig = serviceDetail === null || serviceDetail === void 0 ? void 0 : serviceDetail.ServerConfig;
49
+ const newServiceOptions = yield (0, common_1.tcbrServiceOptions)(options, true, true, previousServerConfig);
50
+ if (!options.noConfirm) {
51
+ const { confirm } = yield inquirer_1.default.prompt([
52
+ {
53
+ type: 'confirm',
54
+ name: 'confirm',
55
+ message: '确定要更新服务吗?',
56
+ }
57
+ ]);
58
+ if (!confirm) {
59
+ return;
60
+ }
61
+ }
62
+ const updateRes = yield updateCloudRunServer(newServiceOptions);
63
+ if (updateRes instanceof Error) {
64
+ throw new toolbox_1.CloudBaseError('当前已有部署发布任务运行中,请稍后再试,或查看实时部署日志');
65
+ }
66
+ const taskId = (_a = updateRes.data) === null || _a === void 0 ? void 0 : _a.TaskId;
67
+ if (options.json) {
68
+ console.log(JSON.stringify(updateRes, null, 2));
69
+ }
70
+ if (process.argv.includes('--verbose')) {
71
+ yield (0, showLogs_1.getLogs)({
72
+ envId: options.envId,
73
+ taskId,
74
+ serviceName: options.serviceName
75
+ });
76
+ console.log(`本次任务的 TaskID: ${taskId}`);
77
+ }
78
+ else {
79
+ toolbox_1.logger.success('更新服务成功, 本次任务的 TaskID: ' + taskId);
80
+ }
81
+ });
82
+ }
83
+ exports.updateTcbrService = updateTcbrService;
@@ -0,0 +1,74 @@
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.logEnvCheck = exports.checkTcbrEnv = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const error_1 = require("../error");
18
+ const net_1 = require("./net");
19
+ const tcbService = net_1.CloudApiService.getInstance('tcb');
20
+ const oldCmdSet = `
21
+ 服务列表:tcb run:deprecated list --envId <envId>
22
+ 创建服务:tcb run:deprecated create --envId <envId> --name <name>
23
+ 删除服务:tcb run:deprecated delete --envId <envId> --serviceName <serviceName>
24
+
25
+ 版本列表:tcb run:deprecated version list --envId <envId> --serviceName <serviceName>
26
+ 创建版本:tcb run:deprecated version create --envId <envId> --serviceName <serviceName>
27
+ 分配流量:tcb run:deprecated version modify --envId <envId> --serviceName <serviceName>
28
+ 滚动更新:tcb run:deprecated version update --envId <envId> --serviceName <serviceName> --versionName <versionName>
29
+ 删除版本:tcb run:deprecated version delete --envId <envId> --serviceName <serviceName> --versionName <versionName>
30
+
31
+ 查看镜像:tcb run:deprecated image list --envId <envId> --serviceName <serviceName>
32
+ 上传镜像:tcb run:deprecated image upload --envId <envId> --serviceName <serviceName> --imageId <imageId> --imageTag <imageTag>
33
+ 下载镜像:tcb run:deprecated image download --envId <envId> --serviceName <serviceName> --imageTag <imageTag>
34
+ 删除镜像:tcb run:deprecated image delete --envId <envId> --serviceName <serviceName> --imageTag <imageTag>
35
+ `;
36
+ const newCmdSet = `
37
+ 查看环境下服务:tcb run service:list --envId <envId>
38
+ 创建云托管服务:tcb run service:create --envId <envId> --serviceName <serviceName> --containerPort <containerPort>
39
+ 更新云托管服务:tcb run service:update --envId <envId> --serviceName <serviceName> --containerPort <containerPort>
40
+ 部署云托管服务:tcb run deploy --envId <envId> --serviceName <serviceName> --containerPort <containerPort>
41
+ 更新服务基础配置:tcb run service:config --envId <envId> --serviceName <serviceName>
42
+ `;
43
+ function checkTcbrEnv(envId, isTcbr) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ if (envId === undefined) {
46
+ throw new error_1.CloudBaseError('请使用 -e 或 --envId 指定环境 ID');
47
+ }
48
+ const { EnvList: [envInfo] } = yield tcbService.request('DescribeEnvs', {
49
+ EnvId: envId
50
+ });
51
+ if (envInfo === undefined) {
52
+ throw new error_1.CloudBaseError('无法读取到有效的环境信息,请检查环境 ID 是否正确');
53
+ }
54
+ if ((envInfo.EnvType === 'tcbr' && isTcbr) || (envInfo.EnvType !== 'tcbr' && !isTcbr)) {
55
+ return 0;
56
+ }
57
+ else if (envInfo.EnvType === 'tcbr' && !isTcbr) {
58
+ return 1;
59
+ }
60
+ else if (envInfo.EnvType !== 'tcbr' && isTcbr) {
61
+ return 2;
62
+ }
63
+ });
64
+ }
65
+ exports.checkTcbrEnv = checkTcbrEnv;
66
+ function logEnvCheck(envId, warningType) {
67
+ if (warningType === 1) {
68
+ throw new error_1.CloudBaseError(`当前能力不支持 ${envId} 环境,请使用如下操作集:${chalk_1.default.grey(newCmdSet)}`);
69
+ }
70
+ else if (warningType === 2) {
71
+ throw new error_1.CloudBaseError(`当前能力不支持 ${envId} 环境,请使用如下操作集:${chalk_1.default.grey(oldCmdSet)}`);
72
+ }
73
+ }
74
+ exports.logEnvCheck = logEnvCheck;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseInputParam = exports.parseOptionalParams = void 0;
4
+ const error_1 = require("../error");
5
+ const run_1 = require("../run");
6
+ const validator_1 = require("./validator");
7
+ function parseOptionalParams(options) {
8
+ let cpuConverted;
9
+ let memConverted;
10
+ if (options.cpu || options.mem) {
11
+ let data = (0, validator_1.validateCpuMem)(options.cpu, options.mem);
12
+ [cpuConverted, memConverted] = [data.cpuOutput, data.memOutput];
13
+ }
14
+ let maxNumConverted;
15
+ if (options.maxNum) {
16
+ maxNumConverted = (0, run_1.convertNumber)(options.maxNum);
17
+ if (maxNumConverted < 0 || maxNumConverted > 50) {
18
+ throw new error_1.CloudBaseError('最大副本数必须大于等于0且小于等于50');
19
+ }
20
+ }
21
+ let minNumConverted;
22
+ if (options.minNum) {
23
+ minNumConverted = (0, run_1.convertNumber)(options.minNum);
24
+ if (minNumConverted < 0 || minNumConverted > 50) {
25
+ throw new error_1.CloudBaseError('最小副本数必须大于等于0且小于等于50');
26
+ }
27
+ }
28
+ if (minNumConverted > maxNumConverted) {
29
+ throw new error_1.CloudBaseError('最小副本数不能大于最大副本数');
30
+ }
31
+ return {
32
+ cpuConverted,
33
+ memConverted,
34
+ maxNumConverted,
35
+ minNumConverted
36
+ };
37
+ }
38
+ exports.parseOptionalParams = parseOptionalParams;
39
+ function parseInputParam(originalParam, override, handler, overrideVal, defaultVal, ...args) {
40
+ return originalParam
41
+ ? (typeof handler === 'function')
42
+ ? handler(originalParam, ...args)
43
+ : originalParam
44
+ : override
45
+ ? overrideVal
46
+ : defaultVal;
47
+ }
48
+ exports.parseInputParam = parseInputParam;
@@ -32,3 +32,6 @@ __exportStar(require("./auth"), exports);
32
32
  __exportStar(require("./store"), exports);
33
33
  __exportStar(require("./notice"), exports);
34
34
  __exportStar(require("./parallel"), exports);
35
+ __exportStar(require("./tcbrApi"), exports);
36
+ __exportStar(require("./checkTcbrEnv"), exports);
37
+ __exportStar(require("./commonParamsCheck"), exports);
@@ -0,0 +1,38 @@
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.callTcbrApi = void 0;
13
+ const toolbox_1 = require("@cloudbase/toolbox");
14
+ const tcbr_cloud_api_request_1 = require("./tcbr-cloud-api-request");
15
+ const tcbrService = tcbr_cloud_api_request_1.CloudApiService.getInstance('tcbr');
16
+ function callTcbrApi(action, data) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ try {
19
+ const res = yield tcbrService.request(action, data);
20
+ return {
21
+ code: 0,
22
+ errmsg: 'success',
23
+ data: Object.assign({}, res)
24
+ };
25
+ }
26
+ catch (e) {
27
+ if (e.code === 'AuthFailure.UnauthorizedOperation') {
28
+ console.log('\n', `requestId: ${e.requestId}`);
29
+ throw new toolbox_1.CloudBaseError('您没有权限执行此操作,请检查 CAM 策略\n');
30
+ }
31
+ else if (e.code === 'LimitExceeded') {
32
+ throw new toolbox_1.CloudBaseError(`${e.original.Message}\n`);
33
+ }
34
+ return e;
35
+ }
36
+ });
37
+ }
38
+ exports.callTcbrApi = callTcbrApi;
@@ -0,0 +1,17 @@
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("./callTcbrApi"), exports);
@@ -0,0 +1,268 @@
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 = {};
@@ -0,0 +1,17 @@
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;