esa-cli 0.0.2-beta.9 → 1.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 (85) hide show
  1. package/README.md +32 -149
  2. package/dist/commands/commit/index.js +49 -104
  3. package/dist/commands/commit/prodBuild.js +2 -3
  4. package/dist/commands/common/constant.js +4 -4
  5. package/dist/commands/common/utils.js +419 -0
  6. package/dist/commands/config.js +2 -2
  7. package/dist/commands/deploy/helper.js +51 -54
  8. package/dist/commands/deploy/index.js +51 -174
  9. package/dist/commands/deployments/delete.js +32 -22
  10. package/dist/commands/deployments/index.js +4 -4
  11. package/dist/commands/deployments/list.js +21 -34
  12. package/dist/commands/dev/build.js +3 -3
  13. package/dist/commands/dev/doProcess.js +5 -5
  14. package/dist/commands/dev/ew2/cacheService.js +33 -0
  15. package/dist/commands/dev/ew2/devEntry.js +2 -1
  16. package/dist/commands/dev/ew2/devPack.js +31 -20
  17. package/dist/commands/dev/ew2/kvService.js +50 -0
  18. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  19. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  20. package/dist/commands/dev/ew2/server.js +165 -29
  21. package/dist/commands/dev/index.js +17 -18
  22. package/dist/commands/dev/mockWorker/devPack.js +19 -10
  23. package/dist/commands/dev/mockWorker/server.js +7 -6
  24. package/dist/commands/domain/add.js +4 -4
  25. package/dist/commands/domain/delete.js +7 -7
  26. package/dist/commands/domain/index.js +4 -4
  27. package/dist/commands/domain/list.js +10 -10
  28. package/dist/commands/init/helper.js +654 -20
  29. package/dist/commands/init/index.js +88 -152
  30. package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
  31. package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
  32. package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
  33. package/dist/commands/init/template.jsonc +84 -0
  34. package/dist/commands/init/types.js +1 -0
  35. package/dist/commands/lang.js +2 -2
  36. package/dist/commands/login/index.js +74 -34
  37. package/dist/commands/logout.js +6 -6
  38. package/dist/commands/route/add.js +105 -49
  39. package/dist/commands/route/delete.js +33 -27
  40. package/dist/commands/route/helper.js +123 -0
  41. package/dist/commands/route/index.js +4 -4
  42. package/dist/commands/route/list.js +56 -17
  43. package/dist/commands/routine/delete.js +9 -8
  44. package/dist/commands/routine/index.js +6 -5
  45. package/dist/commands/routine/list.js +45 -39
  46. package/dist/commands/site/index.js +3 -3
  47. package/dist/commands/site/list.js +6 -7
  48. package/dist/commands/utils.js +61 -25
  49. package/dist/components/descriptionInput.js +1 -1
  50. package/dist/components/filterSelector.js +1 -1
  51. package/dist/components/mutiLevelSelect.js +19 -20
  52. package/dist/components/mutiSelectTable.js +1 -1
  53. package/dist/components/routeBuilder.js +68 -0
  54. package/dist/components/selectInput.js +2 -3
  55. package/dist/components/selectItem.js +1 -1
  56. package/dist/docs/Commands_en.md +164 -117
  57. package/dist/docs/Commands_zh_CN.md +155 -107
  58. package/dist/docs/Config_en.md +70 -0
  59. package/dist/docs/Config_zh_CN.md +68 -0
  60. package/dist/i18n/index.js +2 -2
  61. package/dist/i18n/locales.json +447 -71
  62. package/dist/index.js +28 -13
  63. package/dist/libs/api.js +32 -9
  64. package/dist/libs/apiService.js +294 -73
  65. package/dist/libs/git/index.js +86 -9
  66. package/dist/libs/interface.js +0 -1
  67. package/dist/libs/logger.js +162 -10
  68. package/dist/libs/service.js +2 -2
  69. package/dist/libs/templates/index.js +1 -1
  70. package/dist/utils/checkAssetsExist.js +80 -0
  71. package/dist/utils/checkDevPort.js +5 -19
  72. package/dist/utils/checkEntryFileExist.js +10 -0
  73. package/dist/utils/checkIsRoutineCreated.js +27 -21
  74. package/dist/utils/checkVersion.js +119 -1
  75. package/dist/utils/command.js +149 -0
  76. package/dist/utils/compress.js +142 -0
  77. package/dist/utils/download.js +8 -8
  78. package/dist/utils/fileMd5.js +1 -1
  79. package/dist/utils/fileUtils/index.js +136 -45
  80. package/dist/utils/installDeno.js +4 -4
  81. package/dist/utils/installEw2.js +9 -9
  82. package/dist/utils/openInBrowser.js +1 -1
  83. package/dist/utils/prompt.js +97 -0
  84. package/package.json +24 -13
  85. package/zh_CN.md +29 -154
package/dist/index.js CHANGED
@@ -7,25 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import chalk from 'chalk';
10
11
  import yargs from 'yargs';
11
12
  import { hideBin } from 'yargs/helpers';
12
- import chalk from 'chalk';
13
- import login from './commands/login/index.js';
13
+ import commit from './commands/commit/index.js';
14
14
  import config from './commands/config.js';
15
- import dev from './commands/dev/index.js';
16
- import init from './commands/init/index.js';
17
- import routine from './commands/routine/index.js';
18
15
  import deploy from './commands/deploy/index.js';
19
- import commit from './commands/commit/index.js';
20
16
  import deployments from './commands/deployments/index.js';
17
+ import dev from './commands/dev/index.js';
21
18
  import domainCommand from './commands/domain/index.js';
22
- import routeCommand from './commands/route/index.js';
23
- import logout from './commands/logout.js';
19
+ import init from './commands/init/index.js';
24
20
  import lang from './commands/lang.js';
25
- import { getCliConfig } from './utils/fileUtils/index.js';
26
- import { handleCheckVersion } from './utils/checkVersion.js';
27
- import t from './i18n/index.js';
21
+ import login from './commands/login/index.js';
22
+ import logout from './commands/logout.js';
23
+ import routeCommand from './commands/route/index.js';
24
+ import routine from './commands/routine/index.js';
28
25
  import site from './commands/site/index.js';
26
+ import t from './i18n/index.js';
27
+ import { handleCheckVersion, checkCLIVersion } from './utils/checkVersion.js';
28
+ import { getCliConfig } from './utils/fileUtils/index.js';
29
29
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
30
30
  const argv = hideBin(process.argv);
31
31
  const cliConfig = getCliConfig();
@@ -34,11 +34,21 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
34
34
  .fail((msg, err) => {
35
35
  console.error(msg, err);
36
36
  })
37
- .scriptName('esa')
37
+ .scriptName('esa-cli')
38
38
  .locale((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) || 'en')
39
39
  .version(false)
40
40
  .wrap(null)
41
- .help(false)
41
+ .help()
42
+ .middleware((argv) => __awaiter(void 0, void 0, void 0, function* () {
43
+ try {
44
+ // Pass current command (first positional) so version check can decide prompting behavior
45
+ yield checkCLIVersion((argv._ && argv._[0] ? String(argv._[0]) : ''));
46
+ }
47
+ catch (e) {
48
+ console.log(e);
49
+ console.log('error');
50
+ }
51
+ }))
42
52
  .epilogue(`${t('main_epilogue').d('For more information, visit ESA')}: ${chalk.underline.blue('https://www.aliyun.com/product/esa')}`)
43
53
  .options('version', {
44
54
  describe: t('main_version_describe').d('Show version'),
@@ -50,11 +60,16 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
50
60
  });
51
61
  esa.command('*', false, () => { }, (args) => {
52
62
  if (args._.length > 0) {
63
+ // Unknown command
64
+ console.error(t('common_sub_command_fail').d('Use esa-cli <command> -h to see help'));
53
65
  }
54
66
  else {
55
67
  if (args.v) {
56
68
  handleCheckVersion();
57
69
  }
70
+ else if (args.h || args.help) {
71
+ esa.showHelp('log');
72
+ }
58
73
  else {
59
74
  esa.showHelp('log');
60
75
  }
package/dist/libs/api.js CHANGED
@@ -103,16 +103,13 @@ class Client {
103
103
  getMatchSite(params) {
104
104
  return this.callOpenApi('getMatchSite', params);
105
105
  }
106
- listRoutineCanaryAreas() {
107
- return this.callApi(this.client.listRoutineCanaryAreasWithOptions.bind(this.client));
108
- }
109
- getRoutineUserInfo() {
110
- return this.callApi(this.client.getRoutineUserInfoWithOptions.bind(this.client));
111
- }
112
106
  deleteRoutine(params) {
113
107
  const request = new $ESA.DeleteRoutineRequest(params);
114
108
  return this.callApi(this.client.deleteRoutineWithOptions.bind(this.client), request);
115
109
  }
110
+ listUserRoutines(params) {
111
+ return this.callApi(this.client.listUserRoutinesWithOptions.bind(this.client), new $ESA.ListUserRoutinesRequest(params));
112
+ }
116
113
  deleteRoutineCodeVersion(params) {
117
114
  const request = new $ESA.DeleteRoutineCodeVersionRequest(params);
118
115
  return this.callApi(this.client.deleteRoutineCodeVersionWithOptions.bind(this.client), request);
@@ -140,9 +137,6 @@ class Client {
140
137
  const request = new $ESA.CreateRoutineRequest(params);
141
138
  return this.callApi(this.client.createRoutineWithOptions.bind(this.client), request);
142
139
  }
143
- listRoutineOptionalSpecs() {
144
- return this.callApi(this.client.listRoutineOptionalSpecsWithOptions.bind(this.client));
145
- }
146
140
  createRoutineRelatedRecord(params) {
147
141
  const request = new $ESA.CreateRoutineRelatedRecordRequest(params);
148
142
  return this.callApi(this.client.createRoutineRelatedRecordWithOptions.bind(this.client), request);
@@ -151,5 +145,34 @@ class Client {
151
145
  const request = new $ESA.DeleteRoutineRelatedRecordRequest(params);
152
146
  return this.callApi(this.client.deleteRoutineRelatedRecordWithOptions.bind(this.client), request);
153
147
  }
148
+ createRoutineRoute(params) {
149
+ const request = new $ESA.CreateRoutineRouteRequest(params);
150
+ const newRequest = Object.assign(request, { mode: 'simple' });
151
+ return this.callApi(this.client.createRoutineRouteWithOptions.bind(this.client), newRequest);
152
+ }
153
+ deleteRoutineRoute(params) {
154
+ const request = new $ESA.DeleteRoutineRouteRequest(params);
155
+ return this.callApi(this.client.deleteRoutineRouteWithOptions.bind(this.client), request);
156
+ }
157
+ getRoutineRoute(params) {
158
+ const request = new $ESA.GetRoutineRouteRequest(params);
159
+ return this.callApi(this.client.getRoutineRouteWithOptions.bind(this.client), request);
160
+ }
161
+ listSiteRoutes(params) {
162
+ const request = new $ESA.ListSiteRoutesRequest(params);
163
+ return this.callApi(this.client.listSiteRoutes.bind(this.client), request);
164
+ }
165
+ listRoutineRoutes(params) {
166
+ const request = new $ESA.ListRoutineRoutesRequest(params);
167
+ return this.callApi(this.client.listRoutineRoutes.bind(this.client), request);
168
+ }
169
+ updateRoutineRoute(params) {
170
+ const request = new $ESA.UpdateRoutineRouteRequest(params);
171
+ return this.callApi(this.client.updateRoutineRoute.bind(this.client), request);
172
+ }
173
+ listRoutineCodeVersions(params) {
174
+ const request = new $ESA.ListRoutineCodeVersionsRequest(params);
175
+ return this.callApi(this.client.listRoutineCodeVersions.bind(this.client), request);
176
+ }
154
177
  }
155
178
  export default new Client();
@@ -10,10 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as $OpenApi from '@alicloud/openapi-client';
11
11
  import FormData from 'form-data';
12
12
  import fetch from 'node-fetch';
13
- import { Environment } from './interface.js';
14
- import { getApiConfig } from '../utils/fileUtils/index.js';
15
- import chain from 'lodash';
16
13
  import t from '../i18n/index.js';
14
+ import { getApiConfig } from '../utils/fileUtils/index.js';
15
+ import { Environment } from './interface.js';
17
16
  export class ApiService {
18
17
  constructor(cliConfig) {
19
18
  var _a, _b;
@@ -49,7 +48,7 @@ export class ApiService {
49
48
  * - message: (Optional) A string providing additional information in case of failure.
50
49
  */
51
50
  checkLogin() {
52
- return __awaiter(this, arguments, void 0, function* (isShowError = true) {
51
+ return __awaiter(this, void 0, void 0, function* () {
53
52
  try {
54
53
  let params = {
55
54
  action: 'GetErService',
@@ -91,7 +90,6 @@ export class ApiService {
91
90
  }
92
91
  }
93
92
  catch (error) {
94
- isShowError && console.log(error);
95
93
  return {
96
94
  success: false,
97
95
  message: t('login_failed').d('An error occurred while trying to log in.')
@@ -102,15 +100,15 @@ export class ApiService {
102
100
  quickDeployRoutine(edgeRoutine) {
103
101
  return __awaiter(this, void 0, void 0, function* () {
104
102
  try {
105
- // 上传代码到unstable版本
103
+ // Upload code to unstable version
106
104
  const stagingRes = yield this.getRoutineStagingCodeUploadInfo(edgeRoutine);
107
105
  if (stagingRes) {
108
- // 生产版本
106
+ // Production version
109
107
  const commitRes = yield this.commitRoutineStagingCode({
110
108
  Name: edgeRoutine.name,
111
109
  CodeDescription: edgeRoutine.description
112
110
  });
113
- // 发布到生产环境
111
+ // Deploy to production environment
114
112
  if (commitRes) {
115
113
  const deployRes = yield this.publishRoutineCodeVersion({
116
114
  Name: edgeRoutine.name,
@@ -130,7 +128,6 @@ export class ApiService {
130
128
  }
131
129
  publishRoutineCodeVersion(requestParams) {
132
130
  return __awaiter(this, void 0, void 0, function* () {
133
- var _a;
134
131
  try {
135
132
  let params = {
136
133
  action: 'PublishRoutineCodeVersion',
@@ -146,15 +143,11 @@ export class ApiService {
146
143
  return this;
147
144
  }
148
145
  };
149
- const CanaryAreaList = (_a = requestParams.CanaryAreaList) !== null && _a !== void 0 ? _a : [];
150
- const CanaryAreaListString = JSON.stringify(CanaryAreaList);
151
146
  let request = new $OpenApi.OpenApiRequest({
152
147
  query: {
153
148
  Env: requestParams.Env,
154
149
  Name: requestParams.Name,
155
- CodeVersion: requestParams.CodeVersion,
156
- CanaryCodeVersion: requestParams.CanaryCodeVersion,
157
- CanaryAreaList: CanaryAreaListString
150
+ CodeVersion: requestParams.CodeVersion
158
151
  }
159
152
  });
160
153
  let runtime = {
@@ -225,48 +218,11 @@ export class ApiService {
225
218
  return null;
226
219
  });
227
220
  }
228
- listRoutineCanaryAreas() {
229
- return __awaiter(this, void 0, void 0, function* () {
230
- try {
231
- let params = {
232
- action: 'ListRoutineCanaryAreas',
233
- version: '2024-09-10',
234
- protocol: 'https',
235
- method: 'GET',
236
- authType: 'AK',
237
- bodyType: 'json',
238
- reqBodyType: 'json',
239
- style: 'RPC',
240
- pathname: '/',
241
- toMap: function () {
242
- return this;
243
- }
244
- };
245
- let request = new $OpenApi.OpenApiRequest();
246
- let runtime = {
247
- toMap: function () {
248
- return this;
249
- }
250
- };
251
- const res = yield this.client.callApi(params, request, runtime);
252
- if (res.statusCode === 200 && res.body) {
253
- const ret = {
254
- CanaryAreas: res.body.CanaryAreas
255
- };
256
- return ret;
257
- }
258
- }
259
- catch (error) {
260
- console.log(error);
261
- }
262
- return null;
263
- });
264
- }
265
- getRoutineUserInfo() {
221
+ listUserRoutines(requestParams) {
266
222
  return __awaiter(this, void 0, void 0, function* () {
267
223
  try {
268
224
  let params = {
269
- action: 'GetRoutineUserInfo',
225
+ action: 'ListUserRoutines',
270
226
  version: '2024-09-10',
271
227
  protocol: 'https',
272
228
  method: 'GET',
@@ -279,7 +235,9 @@ export class ApiService {
279
235
  return this;
280
236
  }
281
237
  };
282
- let request = new $OpenApi.OpenApiRequest();
238
+ let request = new $OpenApi.OpenApiRequest({
239
+ query: requestParams || {}
240
+ });
283
241
  let runtime = {
284
242
  toMap: function () {
285
243
  return this;
@@ -287,11 +245,7 @@ export class ApiService {
287
245
  };
288
246
  const res = yield this.client.callApi(params, request, runtime);
289
247
  if (res.statusCode === 200 && res.body) {
290
- const ret = {
291
- Subdomains: res.body.RoutineName,
292
- Routines: res.body.Routines
293
- };
294
- return ret;
248
+ return res;
295
249
  }
296
250
  }
297
251
  catch (error) {
@@ -569,7 +523,6 @@ export class ApiService {
569
523
  }
570
524
  getRoutine(requestParams_1) {
571
525
  return __awaiter(this, arguments, void 0, function* (requestParams, isShowError = true) {
572
- var _a, _b, _c, _d, _e, _f, _g, _h;
573
526
  try {
574
527
  let params = {
575
528
  action: 'GetRoutine',
@@ -599,16 +552,7 @@ export class ApiService {
599
552
  if (res.statusCode === 200 && res.body) {
600
553
  const routineResponse = {
601
554
  code: res.statusCode,
602
- data: {
603
- RequestId: (_a = res.body) === null || _a === void 0 ? void 0 : _a.RequestId,
604
- CodeVersions: ((_b = res.body) === null || _b === void 0 ? void 0 : _b.CodeVersions) || [],
605
- RelatedRecords: ((_c = res.body) === null || _c === void 0 ? void 0 : _c.RelatedRecords) || [],
606
- Envs: ((_d = res.body) === null || _d === void 0 ? void 0 : _d.Envs) || [],
607
- CreateTime: (_e = res.body) === null || _e === void 0 ? void 0 : _e.CreateTime,
608
- Description: (_f = res.body) === null || _f === void 0 ? void 0 : _f.Description,
609
- RelatedRoutes: ((_g = res.body) === null || _g === void 0 ? void 0 : _g.RelatedRoutes) || [],
610
- DefaultRelatedRecord: (_h = res.body) === null || _h === void 0 ? void 0 : _h.DefaultRelatedRecord
611
- }
555
+ data: res.body
612
556
  };
613
557
  return routineResponse;
614
558
  }
@@ -640,7 +584,8 @@ export class ApiService {
640
584
  let request = new $OpenApi.OpenApiRequest({
641
585
  query: {
642
586
  Name: edgeRoutine.name,
643
- Description: edgeRoutine.description
587
+ Description: edgeRoutine.description,
588
+ HasAssets: edgeRoutine.hasAssets
644
589
  }
645
590
  });
646
591
  let runtime = {
@@ -695,7 +640,7 @@ export class ApiService {
695
640
  }
696
641
  };
697
642
  const uploadResult = yield this.client.callApi(params, request, runtime);
698
- const ossConfig = chain(uploadResult).get('body.OssPostConfig');
643
+ const ossConfig = uploadResult.body.OssPostConfig;
699
644
  if (uploadResult.statusCode !== 200 || !ossConfig) {
700
645
  return false;
701
646
  }
@@ -708,7 +653,6 @@ export class ApiService {
708
653
  formData.append('policy', policy);
709
654
  formData.append('key', key);
710
655
  formData.append('file', edgeRoutine.code);
711
- // TODO: 检查oss结果;
712
656
  const ossRes = yield fetch(Url, {
713
657
  method: 'POST',
714
658
  body: formData,
@@ -868,5 +812,282 @@ export class ApiService {
868
812
  return null;
869
813
  });
870
814
  }
815
+ listRoutineRelatedRecords(requestParams) {
816
+ return __awaiter(this, void 0, void 0, function* () {
817
+ try {
818
+ let params = {
819
+ action: 'ListRoutineRelatedRecords',
820
+ version: '2024-09-10',
821
+ protocol: 'https',
822
+ method: 'GET',
823
+ authType: 'AK',
824
+ bodyType: 'json',
825
+ reqBodyType: 'json',
826
+ style: 'RPC',
827
+ pathname: '/',
828
+ toMap: function () {
829
+ return this;
830
+ }
831
+ };
832
+ let request = new $OpenApi.OpenApiRequest({
833
+ query: {
834
+ Name: requestParams.Name,
835
+ PageNumber: requestParams.PageNumber,
836
+ PageSize: requestParams.PageSize,
837
+ SearchKeyWord: requestParams.SearchKeyWord
838
+ }
839
+ });
840
+ let runtime = {
841
+ toMap: function () {
842
+ return this;
843
+ }
844
+ };
845
+ const res = yield this.client.callApi(params, request, runtime);
846
+ if (res.statusCode === 200 && res.body) {
847
+ const ret = {
848
+ code: res.statusCode,
849
+ data: {
850
+ PageNumber: res.body.PageNumber,
851
+ PageSize: res.body.PageSize,
852
+ TotalCount: res.body.TotalCount,
853
+ RelatedRecords: res.body.RelatedRecords
854
+ }
855
+ };
856
+ return ret;
857
+ }
858
+ }
859
+ catch (error) {
860
+ console.log(error);
861
+ }
862
+ return null;
863
+ });
864
+ }
865
+ createRoutineRoute(requestParams) {
866
+ return __awaiter(this, void 0, void 0, function* () {
867
+ try {
868
+ let params = {
869
+ action: 'CreateRoutineRoute',
870
+ version: '2024-09-10',
871
+ protocol: 'https',
872
+ method: 'POST',
873
+ authType: 'AK',
874
+ bodyType: 'json',
875
+ reqBodyType: 'json',
876
+ style: 'RPC',
877
+ pathname: '/',
878
+ toMap: function () {
879
+ return this;
880
+ }
881
+ };
882
+ let request = new $OpenApi.OpenApiRequest({
883
+ query: {
884
+ SiteId: requestParams.SiteId,
885
+ RoutineName: requestParams.RoutineName,
886
+ RouteName: requestParams.RouteName,
887
+ RouteEnable: 'on',
888
+ Rule: requestParams.Rule,
889
+ Bypass: requestParams.Bypass,
890
+ Mode: 'simple'
891
+ }
892
+ });
893
+ let runtime = {
894
+ toMap: function () {
895
+ return this;
896
+ }
897
+ };
898
+ const res = yield this.client.callApi(params, request, runtime);
899
+ if (res.statusCode === 200 && res.body) {
900
+ const ret = {
901
+ code: res.statusCode,
902
+ data: {
903
+ RequestId: res.body.RequestId,
904
+ ConfigId: res.body.ConfigId
905
+ }
906
+ };
907
+ return ret;
908
+ }
909
+ }
910
+ catch (error) {
911
+ console.log(error);
912
+ }
913
+ return null;
914
+ });
915
+ }
916
+ /**
917
+ * 调用 CreateRoutineWithAssetsCodeVersion API 获取 OSS 上传配置
918
+ */
919
+ CreateRoutineWithAssetsCodeVersion(requestParams) {
920
+ return __awaiter(this, void 0, void 0, function* () {
921
+ var _a;
922
+ try {
923
+ let params = {
924
+ action: 'CreateRoutineWithAssetsCodeVersion',
925
+ version: '2024-09-10',
926
+ protocol: 'https',
927
+ method: 'POST',
928
+ authType: 'AK',
929
+ bodyType: 'json',
930
+ reqBodyType: 'json',
931
+ style: 'RPC',
932
+ pathname: '/',
933
+ toMap: function () {
934
+ return this;
935
+ }
936
+ };
937
+ let request = new $OpenApi.OpenApiRequest({
938
+ body: {
939
+ Name: requestParams.Name,
940
+ CodeDescription: requestParams.CodeDescription,
941
+ ExtraInfo: requestParams.ExtraInfo,
942
+ ConfOptions: {
943
+ NotFoundStrategy: (_a = requestParams.ConfOptions) === null || _a === void 0 ? void 0 : _a.NotFoundStrategy
944
+ }
945
+ }
946
+ });
947
+ let runtime = {
948
+ toMap: function () {
949
+ return this;
950
+ }
951
+ };
952
+ const result = yield this.client.callApi(params, request, runtime);
953
+ if (result.statusCode === 200 && result.body) {
954
+ return {
955
+ code: result.statusCode.toString(),
956
+ data: {
957
+ RequestId: result.body.RequestId,
958
+ CodeVersion: result.body.CodeVersion,
959
+ Status: result.body.Status,
960
+ OssPostConfig: result.body.OssPostConfig
961
+ }
962
+ };
963
+ }
964
+ return null;
965
+ }
966
+ catch (error) {
967
+ console.error('Error calling CreateRoutineWithAssetsCodeVersion:', error);
968
+ return null;
969
+ }
970
+ });
971
+ }
972
+ /**
973
+ * 上传文件到 OSS
974
+ */
975
+ uploadToOss(ossConfig, zipBuffer) {
976
+ return __awaiter(this, void 0, void 0, function* () {
977
+ try {
978
+ const { OSSAccessKeyId, Signature, Url, Key, Policy, XOssSecurityToken } = ossConfig;
979
+ const formData = new FormData();
980
+ formData.append('OSSAccessKeyId', OSSAccessKeyId);
981
+ formData.append('Signature', Signature);
982
+ formData.append('x-oss-security-token', XOssSecurityToken);
983
+ formData.append('policy', Policy);
984
+ formData.append('key', Key);
985
+ formData.append('file', zipBuffer);
986
+ const ossRes = yield fetch(Url, {
987
+ method: 'POST',
988
+ body: formData,
989
+ headers: formData.getHeaders()
990
+ });
991
+ return ossRes && (ossRes.status === 200 || ossRes.status === 204);
992
+ }
993
+ catch (error) {
994
+ console.error('Error uploading to OSS:', error);
995
+ return false;
996
+ }
997
+ });
998
+ }
999
+ createRoutineCodeDeployment(requestParams) {
1000
+ return __awaiter(this, void 0, void 0, function* () {
1001
+ try {
1002
+ let params = {
1003
+ action: 'CreateRoutineCodeDeployment',
1004
+ version: '2024-09-10',
1005
+ protocol: 'https',
1006
+ method: 'POST',
1007
+ authType: 'AK',
1008
+ bodyType: 'json',
1009
+ reqBodyType: 'json',
1010
+ style: 'RPC',
1011
+ pathname: '/',
1012
+ toMap: function () {
1013
+ return this;
1014
+ }
1015
+ };
1016
+ let request = new $OpenApi.OpenApiRequest({
1017
+ query: {
1018
+ Name: requestParams.Name,
1019
+ Env: requestParams.Env,
1020
+ Strategy: requestParams.Strategy,
1021
+ CodeVersions: JSON.stringify(requestParams.CodeVersions)
1022
+ }
1023
+ });
1024
+ let runtime = {
1025
+ toMap: function () {
1026
+ return this;
1027
+ }
1028
+ };
1029
+ const res = yield this.client.callApi(params, request, runtime);
1030
+ if (res.statusCode === 200 && res.body) {
1031
+ const ret = {
1032
+ code: res.statusCode,
1033
+ data: {
1034
+ RequestId: res.body.RequestId,
1035
+ Strategy: res.body.Strategy,
1036
+ DeploymentId: res.body.DeploymentId,
1037
+ CodeVersions: res.body.CodeVersions
1038
+ }
1039
+ };
1040
+ return ret;
1041
+ }
1042
+ }
1043
+ catch (error) {
1044
+ console.log(error);
1045
+ }
1046
+ return null;
1047
+ });
1048
+ }
1049
+ getRoutineCodeVersionInfo(requestParams) {
1050
+ return __awaiter(this, void 0, void 0, function* () {
1051
+ try {
1052
+ let params = {
1053
+ action: 'GetRoutineCodeVersionInfo',
1054
+ version: '2024-09-10',
1055
+ protocol: 'https',
1056
+ method: 'GET',
1057
+ authType: 'AK',
1058
+ bodyType: 'json',
1059
+ reqBodyType: 'json',
1060
+ style: 'RPC',
1061
+ pathname: '/',
1062
+ toMap: function () {
1063
+ return this;
1064
+ }
1065
+ };
1066
+ let request = new $OpenApi.OpenApiRequest({
1067
+ query: {
1068
+ Name: requestParams.Name,
1069
+ CodeVersion: requestParams.CodeVersion
1070
+ }
1071
+ });
1072
+ let runtime = {
1073
+ toMap: function () {
1074
+ return this;
1075
+ }
1076
+ };
1077
+ const res = yield this.client.callApi(params, request, runtime);
1078
+ if (res.statusCode === 200 && res.body) {
1079
+ const ret = {
1080
+ code: res.statusCode,
1081
+ data: res.body
1082
+ };
1083
+ return ret;
1084
+ }
1085
+ }
1086
+ catch (error) {
1087
+ console.log(error);
1088
+ }
1089
+ return null;
1090
+ });
1091
+ }
871
1092
  }
872
1093
  ApiService.instance = null;