esa-cli 0.0.2-beta.10 → 0.0.2-beta.13

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 (75) hide show
  1. package/dist/commands/commit/index.js +26 -115
  2. package/dist/commands/commit/prodBuild.js +2 -3
  3. package/dist/commands/common/routineUtils.js +276 -0
  4. package/dist/commands/config.js +1 -1
  5. package/dist/commands/deploy/helper.js +40 -61
  6. package/dist/commands/deploy/index.js +90 -188
  7. package/dist/commands/deployments/delete.js +32 -22
  8. package/dist/commands/deployments/index.js +2 -2
  9. package/dist/commands/deployments/list.js +22 -38
  10. package/dist/commands/dev/build.js +3 -3
  11. package/dist/commands/dev/doProcess.js +5 -5
  12. package/dist/commands/dev/ew2/cacheService.js +33 -0
  13. package/dist/commands/dev/ew2/devEntry.js +2 -1
  14. package/dist/commands/dev/ew2/devPack.js +22 -11
  15. package/dist/commands/dev/ew2/kvService.js +27 -0
  16. package/dist/commands/dev/ew2/mock/cache.js +99 -15
  17. package/dist/commands/dev/ew2/mock/kv.js +142 -21
  18. package/dist/commands/dev/ew2/server.js +162 -27
  19. package/dist/commands/dev/index.js +14 -15
  20. package/dist/commands/dev/mockWorker/devPack.js +16 -7
  21. package/dist/commands/dev/mockWorker/server.js +7 -6
  22. package/dist/commands/domain/add.js +2 -2
  23. package/dist/commands/domain/delete.js +7 -7
  24. package/dist/commands/domain/index.js +2 -2
  25. package/dist/commands/domain/list.js +10 -10
  26. package/dist/commands/init/helper.js +87 -13
  27. package/dist/commands/init/index.js +461 -57
  28. package/dist/commands/init/template.jsonc +34 -0
  29. package/dist/commands/lang.js +2 -2
  30. package/dist/commands/login/index.js +57 -7
  31. package/dist/commands/logout.js +5 -5
  32. package/dist/commands/route/add.js +138 -49
  33. package/dist/commands/route/delete.js +33 -27
  34. package/dist/commands/route/helper.js +124 -0
  35. package/dist/commands/route/index.js +2 -2
  36. package/dist/commands/route/list.js +56 -17
  37. package/dist/commands/routine/delete.js +2 -2
  38. package/dist/commands/routine/index.js +2 -2
  39. package/dist/commands/routine/list.js +9 -21
  40. package/dist/commands/site/index.js +1 -1
  41. package/dist/commands/site/list.js +6 -7
  42. package/dist/commands/utils.js +55 -19
  43. package/dist/components/descriptionInput.js +1 -1
  44. package/dist/components/mutiSelectTable.js +1 -1
  45. package/dist/components/selectInput.js +2 -3
  46. package/dist/components/selectItem.js +1 -1
  47. package/dist/docs/Commands_en.md +25 -15
  48. package/dist/docs/Commands_zh_CN.md +12 -2
  49. package/dist/docs/eslint-config-en.md +1 -0
  50. package/dist/docs/eslint-config.md +73 -0
  51. package/dist/docs/init-command-quick-test.md +208 -0
  52. package/dist/docs/init-command-test-guide.md +598 -0
  53. package/dist/i18n/index.js +2 -2
  54. package/dist/i18n/locales.json +261 -17
  55. package/dist/index.js +17 -12
  56. package/dist/libs/api.js +32 -9
  57. package/dist/libs/apiService.js +258 -85
  58. package/dist/libs/git/index.js +8 -4
  59. package/dist/libs/interface.js +0 -1
  60. package/dist/libs/logger.js +63 -7
  61. package/dist/libs/service.js +2 -2
  62. package/dist/libs/templates/index.js +1 -1
  63. package/dist/utils/checkAssetsExist.js +80 -0
  64. package/dist/utils/checkDevPort.js +3 -17
  65. package/dist/utils/checkEntryFileExist.js +10 -0
  66. package/dist/utils/checkIsRoutineCreated.js +16 -31
  67. package/dist/utils/checkVersion.js +1 -1
  68. package/dist/utils/compress.js +80 -0
  69. package/dist/utils/download.js +5 -5
  70. package/dist/utils/fileMd5.js +1 -1
  71. package/dist/utils/fileUtils/index.js +71 -22
  72. package/dist/utils/installDeno.js +3 -3
  73. package/dist/utils/installEw2.js +7 -7
  74. package/dist/utils/openInBrowser.js +1 -1
  75. package/package.json +11 -6
@@ -7,24 +7,48 @@ 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 inquirer from 'inquirer';
11
- import { getApiConfig, getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
12
10
  import chalk from 'chalk';
13
- import { ApiService } from '../../libs/apiService.js';
11
+ import inquirer from 'inquirer';
14
12
  import t from '../../i18n/index.js';
13
+ import { ApiService } from '../../libs/apiService.js';
15
14
  import logger from '../../libs/logger.js';
15
+ import { getApiConfig, getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
16
16
  const login = {
17
17
  command: 'login',
18
18
  describe: `🔑 ${t('login_describe').d('Login to the server')}`,
19
- builder: {},
19
+ builder: (yargs) => {
20
+ var _a, _b;
21
+ return yargs
22
+ .option('access-key-id', {
23
+ alias: 'ak',
24
+ describe: (_a = t('login_option_access_key_id')) === null || _a === void 0 ? void 0 : _a.d('AccessKey ID'),
25
+ type: 'string'
26
+ })
27
+ .option('access-key-secret', {
28
+ alias: 'sk',
29
+ describe: (_b = t('login_option_access_key_secret')) === null || _b === void 0 ? void 0 : _b.d('AccessKey Secret'),
30
+ type: 'string'
31
+ });
32
+ },
20
33
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
21
- handleLogin();
34
+ handleLogin(argv);
22
35
  })
23
36
  };
24
37
  export default login;
25
- export function handleLogin() {
38
+ export function handleLogin(argv) {
26
39
  return __awaiter(this, void 0, void 0, function* () {
27
40
  generateDefaultConfig();
41
+ const accessKeyId = argv === null || argv === void 0 ? void 0 : argv['access-key-id'];
42
+ const accessKeySecret = argv === null || argv === void 0 ? void 0 : argv['access-key-secret'];
43
+ if (accessKeyId && accessKeySecret) {
44
+ yield handleLoginWithAKSK(accessKeyId, accessKeySecret);
45
+ return;
46
+ }
47
+ if (process.env.ESA_ACCESS_KEY_ID && process.env.ESA_ACCESS_KEY_SECRET) {
48
+ logger.log(`🔑 ${t('login_get_from_env').d(`Get AccessKey ID and AccessKey Secret from environment variables.`)}`);
49
+ yield handleLoginWithAKSK(process.env.ESA_ACCESS_KEY_ID, process.env.ESA_ACCESS_KEY_SECRET);
50
+ return;
51
+ }
28
52
  const cliConfig = getCliConfig();
29
53
  if (!cliConfig)
30
54
  return;
@@ -33,7 +57,7 @@ export function handleLogin() {
33
57
  cliConfig.auth.accessKeyId &&
34
58
  cliConfig.auth.accessKeySecret) {
35
59
  const service = yield ApiService.getInstance();
36
- const loginStatus = yield service.checkLogin(false);
60
+ const loginStatus = yield service.checkLogin();
37
61
  if (loginStatus.success) {
38
62
  logger.warn(t('login_already').d('You are already logged in.'));
39
63
  const action = yield inquirer.prompt([
@@ -64,6 +88,32 @@ export function handleLogin() {
64
88
  }
65
89
  });
66
90
  }
91
+ function handleLoginWithAKSK(accessKeyId, accessKeySecret) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ let apiConfig = getApiConfig();
94
+ apiConfig.auth = {
95
+ accessKeyId,
96
+ accessKeySecret
97
+ };
98
+ try {
99
+ yield updateCliConfigFile({
100
+ auth: apiConfig.auth
101
+ });
102
+ const service = yield ApiService.getInstance();
103
+ service.updateConfig(apiConfig);
104
+ const loginStatus = yield service.checkLogin();
105
+ if (loginStatus.success) {
106
+ logger.success(t('login_success').d('Login success!'));
107
+ }
108
+ else {
109
+ logger.error(loginStatus.message || 'Login failed');
110
+ }
111
+ }
112
+ catch (error) {
113
+ logger.error(t('login_failed').d('An error occurred while trying to log in.'));
114
+ }
115
+ });
116
+ }
67
117
  export function getUserInputAuthInfo() {
68
118
  return __awaiter(this, void 0, void 0, function* () {
69
119
  const styledUrl = chalk.underline.blue('https://ram.console.aliyun.com/manage/ak');
@@ -7,21 +7,21 @@ 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 { getCliConfig, updateCliConfigFile } from '../utils/fileUtils/index.js';
11
- import logger from '../libs/logger.js';
12
10
  import t from '../i18n/index.js';
11
+ import logger from '../libs/logger.js';
12
+ import { getCliConfig, updateCliConfigFile } from '../utils/fileUtils/index.js';
13
13
  const logout = {
14
14
  command: 'logout',
15
15
  describe: `📥 ${t('logout_describe').d('Logout')}`,
16
16
  builder: (yargs) => {
17
17
  return yargs;
18
18
  },
19
- handler: (argv) => {
20
- handleLogout(argv);
19
+ handler: () => {
20
+ handleLogout();
21
21
  }
22
22
  };
23
23
  export default logout;
24
- export function handleLogout(argv) {
24
+ export function handleLogout() {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  let cliConfig = getCliConfig();
27
27
  if (!cliConfig) {
@@ -7,20 +7,35 @@ 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';
11
- import logger from '../../libs/logger.js';
12
- import { checkDirectory, checkIsLoginSuccess, isValidRouteForDomain } from '../utils.js';
13
- import { getProjectConfig } from '../../utils/fileUtils/index.js';
14
- import { ApiService } from '../../libs/apiService.js';
10
+ import inquirer from 'inquirer';
15
11
  import t from '../../i18n/index.js';
16
- import { descriptionInput } from '../../components/descriptionInput.js';
17
- import { promptFilterSelector } from '../../components/filterSelector.js';
12
+ import { ApiService } from '../../libs/apiService.js';
13
+ import logger from '../../libs/logger.js';
18
14
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
15
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
16
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
17
+ import { transferRouteToRuleString } from './helper.js';
19
18
  const addRoute = {
20
- command: 'add [route] [site]',
19
+ command: 'add',
21
20
  describe: `📥 ${t('route_add_describe').d('Bind a Route to a routine')}`,
22
21
  builder: (yargs) => {
23
- return yargs.fail((msg, err, yargsIns) => {
22
+ return yargs
23
+ .option('route', {
24
+ describe: t('route_add_route_value_option').d('The route value. For example: example.com/*'),
25
+ alias: 'r',
26
+ type: 'string'
27
+ })
28
+ .option('site', {
29
+ describe: t('route_add_site_describe').d('The site to bind the route to. For example: example.com'),
30
+ alias: 's',
31
+ type: 'string'
32
+ })
33
+ .option('alias', {
34
+ alias: 'a',
35
+ describe: t('route_add_route_name_option').d('Route name (aliases)'),
36
+ type: 'string'
37
+ })
38
+ .fail((msg, err, yargsIns) => {
24
39
  if (err)
25
40
  throw err;
26
41
  if (msg) {
@@ -36,7 +51,7 @@ const addRoute = {
36
51
  };
37
52
  export function handlerAddRoute(argv) {
38
53
  return __awaiter(this, void 0, void 0, function* () {
39
- var _a, _b, _c;
54
+ var _a;
40
55
  if (!checkDirectory()) {
41
56
  return;
42
57
  }
@@ -47,8 +62,6 @@ export function handlerAddRoute(argv) {
47
62
  if (!isSuccess)
48
63
  return;
49
64
  yield validRoutine(projectConfig.name);
50
- // input route and site
51
- const { route, site } = argv;
52
65
  const listSitesReq = {
53
66
  SiteSearchType: 'fuzzy',
54
67
  Status: 'active',
@@ -57,58 +70,134 @@ export function handlerAddRoute(argv) {
57
70
  };
58
71
  const server = yield ApiService.getInstance();
59
72
  const ListSitesRes = yield server.listSites(listSitesReq);
60
- const siteList = ((ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data.Sites) || []).map((i) => ({
61
- label: i.SiteName,
73
+ if (!((_a = ListSitesRes === null || ListSitesRes === void 0 ? void 0 : ListSitesRes.data) === null || _a === void 0 ? void 0 : _a.Sites) || ListSitesRes.data.Sites.length === 0) {
74
+ logger.error(t('no_active_sites').d('No active sites found in your account'));
75
+ return;
76
+ }
77
+ const siteList = ListSitesRes.data.Sites.map((i) => ({
78
+ name: i.SiteName,
62
79
  value: i.SiteId
63
80
  }));
64
- if (route && site) {
65
- const siteId = (_a = siteList.find((item) => item.label === site)) === null || _a === void 0 ? void 0 : _a.value;
66
- const req = {
67
- Name: projectConfig.name,
68
- SiteId: Number(siteId),
69
- SiteName: String(site),
70
- Route: String(route)
71
- };
72
- const res = yield server.createRoutineRelatedRoute(req);
73
- const addSuccess = ((_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.Status) === 'OK';
74
- if (addSuccess) {
75
- logger.success(t('route_add_success').d('Add route success!'));
81
+ // 获取路由名称,支持直接通过参数传入
82
+ let routeName = argv.alias;
83
+ if (!routeName) {
84
+ const response = yield inquirer.prompt([
85
+ {
86
+ type: 'input',
87
+ name: 'routeName',
88
+ message: t('create_route_route_name').d('Enter a Route Name (Aliases):'),
89
+ validate: (input) => {
90
+ if (!input) {
91
+ return t('route_name_input_required').d('Route name is required');
92
+ }
93
+ return true;
94
+ }
95
+ }
96
+ ]);
97
+ routeName = response.routeName;
98
+ }
99
+ let siteName = argv.site;
100
+ let siteId;
101
+ if (!siteName) {
102
+ if (argv._.length > 2) {
103
+ siteName = argv._[2];
104
+ }
105
+ // 如果仍未提供站点名称,则提示选择
106
+ if (!siteName) {
107
+ const response = yield inquirer.prompt([
108
+ {
109
+ type: 'list',
110
+ name: 'routeSite',
111
+ message: t('create_route_site').d('Select a site that is active in your account:'),
112
+ choices: siteList
113
+ }
114
+ ]);
115
+ siteId = response.routeSite;
76
116
  }
77
117
  else {
78
- logger.error(t('route_add_fail').d('Add route fail!'));
118
+ // 根据站点名称查找对应的站点ID
119
+ const matchedSite = siteList.find((site) => site.name === siteName);
120
+ if (matchedSite) {
121
+ siteId = matchedSite.value;
122
+ }
123
+ else {
124
+ logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
125
+ return;
126
+ }
127
+ }
128
+ }
129
+ else {
130
+ // 根据站点名称查找对应的站点ID
131
+ const matchedSite = siteList.find((site) => site.name === siteName);
132
+ if (matchedSite) {
133
+ siteId = matchedSite.value;
134
+ }
135
+ else {
136
+ logger.error(t('site_not_found').d(`Site "${siteName}" not found in your account`));
137
+ return;
79
138
  }
80
- return;
81
139
  }
82
- logger.warn(t('interactive_mode').d('Interactive mode'));
83
- // not input route and site, enter interactive mode
84
- logger.log(`🖊️ ${t('domain_input').d('Enter the name of domain (Support fuzzy matching on tab press):')}`);
85
- const domain = yield promptFilterSelector(siteList);
86
- const inputRoute = yield descriptionInput(`🖊️ ${t('route_input').d('Enter a Route:')} (${chalk.green(t('route_validate').d('You can add an asterisk (*) as the prefix or suffix to match more URLs, such as "*.example.com/*".'))})`, true);
87
- const ROUTE_PATTERN = /^(?:\*\.)?([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*\.[a-zA-Z]{2,})(\/\*|\/[^?#]*)?$/;
88
- if (!ROUTE_PATTERN.test(inputRoute)) {
89
- return logger.error(t('route_add_invalid_route').d('Invalid route'));
140
+ // 获取路由值,支持直接通过参数传入
141
+ let inputRoute = argv.route;
142
+ if (!inputRoute) {
143
+ // 如果参数中提供了路由值,使用它
144
+ if (argv._.length > 1) {
145
+ inputRoute = argv._[1];
146
+ }
147
+ // 如果仍未提供路由值,则提示输入
148
+ if (!inputRoute) {
149
+ const response = yield inquirer.prompt([
150
+ {
151
+ type: 'input',
152
+ name: 'inputRoute',
153
+ message: t('create_route_route').d('Enter a Route (e.g., example.com/*):'),
154
+ validate: (input) => {
155
+ if (!input) {
156
+ return t('route_input_required').d('Route is required');
157
+ }
158
+ if (!input.includes('*') && !input.includes('/')) {
159
+ return t('route_format_invalid').d('Route format is invalid. Please include wildcard (*) or path (/)');
160
+ }
161
+ return true;
162
+ }
163
+ }
164
+ ]);
165
+ inputRoute = response.inputRoute;
166
+ }
90
167
  }
91
- if (!isValidRouteForDomain(inputRoute, domain.label)) {
92
- return logger.error(t('route_site_not_match').d('The route does not correspond to the domain.'));
168
+ const rule = transferRouteToRuleString(inputRoute);
169
+ if (!rule) {
170
+ logger.error(t('route_format_invalid').d('Invalid route format'));
171
+ return;
93
172
  }
94
- if (domain.value !== '') {
95
- const req = {
96
- Name: projectConfig.name,
97
- SiteId: Number(domain.value),
98
- SiteName: domain.label,
99
- Route: inputRoute
100
- };
101
- const res = yield server.createRoutineRelatedRoute(req);
102
- const addSuccess = ((_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.Status) === 'OK';
173
+ // 获取站点名称用于显示
174
+ const selectedSite = siteList.find((site) => site.value === siteId);
175
+ const displaySiteName = selectedSite ? selectedSite.name : siteName;
176
+ const req = {
177
+ RoutineName: projectConfig.name,
178
+ RouteName: routeName,
179
+ SiteId: siteId,
180
+ RouteEnable: 'on',
181
+ Bypass: 'off',
182
+ Rule: rule
183
+ };
184
+ try {
185
+ logger.info(t('creating_route').d('Creating route...'));
186
+ const res = yield server.createRoutineRoute(req);
187
+ const addSuccess = (res === null || res === void 0 ? void 0 : res.code) === 200;
103
188
  if (addSuccess) {
104
189
  logger.success(t('route_add_success').d('Add route success!'));
190
+ logger.info(`Route "${routeName}" has been successfully added to routine "${projectConfig.name}" for site "${displaySiteName}"`);
105
191
  }
106
192
  else {
107
193
  logger.error(t('route_add_fail').d('Add route fail!'));
108
194
  }
109
195
  }
110
- else {
111
- logger.error(t('invalid_domain').d('Input domain is invalid'));
196
+ catch (error) {
197
+ logger.error(t('route_add_fail').d('Add route fail!'));
198
+ if (error instanceof Error) {
199
+ logger.error(`Error: ${error.message}`);
200
+ }
112
201
  }
113
202
  });
114
203
  }
@@ -7,20 +7,30 @@ 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 { getProjectConfig } from '../../utils/fileUtils/index.js';
11
- import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
12
- import { ApiService } from '../../libs/apiService.js';
13
- import logger from '../../libs/logger.js';
14
10
  import t from '../../i18n/index.js';
11
+ import api from '../../libs/api.js';
12
+ import logger from '../../libs/logger.js';
15
13
  import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
14
+ import { getProjectConfig } from '../../utils/fileUtils/index.js';
15
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
16
16
  const deleteRoute = {
17
- command: 'delete <route>',
17
+ command: 'delete <routeName>',
18
18
  describe: `🗑 ${t('route_delete_describe').d('Delete a related route')}`,
19
19
  builder: (yargs) => {
20
- return yargs.positional('route', {
20
+ return yargs
21
+ .positional('routeName', {
21
22
  describe: t('route_delete_positional_describe').d('The name of the routes to delete'),
22
23
  type: 'string',
23
24
  demandOption: true
25
+ })
26
+ .fail((msg, err, yargsIns) => {
27
+ console.log(msg, err);
28
+ if (err)
29
+ throw err;
30
+ if (msg) {
31
+ yargsIns.showHelp('log');
32
+ }
33
+ process.exit(1);
24
34
  });
25
35
  },
26
36
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
@@ -30,7 +40,7 @@ const deleteRoute = {
30
40
  export default deleteRoute;
31
41
  export function handleDeleteRoute(argv) {
32
42
  return __awaiter(this, void 0, void 0, function* () {
33
- var _a, _b;
43
+ var _a;
34
44
  if (!checkDirectory()) {
35
45
  return;
36
46
  }
@@ -41,29 +51,25 @@ export function handleDeleteRoute(argv) {
41
51
  if (!isSuccess)
42
52
  return;
43
53
  yield validRoutine(projectConfig.name);
44
- const server = yield ApiService.getInstance();
45
- const req = { Name: projectConfig.name };
46
- const routineDetail = yield server.getRoutine(req);
47
- if (!routineDetail)
48
- return;
49
- const relatedRoutes = (_b = (_a = routineDetail.data) === null || _a === void 0 ? void 0 : _a.RelatedRoutes) !== null && _b !== void 0 ? _b : [];
50
- const deleteDomain = argv.route;
51
- const matchedSite = relatedRoutes.find((item) => {
52
- return String(item.Route) === deleteDomain;
53
- });
54
- if (matchedSite === undefined) {
55
- logger.error(t('route_not_exist').d('Route not exist!'));
54
+ const req = {
55
+ routineName: projectConfig.name
56
+ };
57
+ const res = yield api.listRoutineRoutes(req);
58
+ const configs = ((_a = res.body) === null || _a === void 0 ? void 0 : _a.configs) || [];
59
+ const deleteRouteName = argv.routeName;
60
+ const matchedRoute = configs.find((config) => config.routeName === deleteRouteName);
61
+ if (!matchedRoute) {
62
+ logger.error(t('no_route_found').d('No route found! Please check the route name.'));
56
63
  return;
57
64
  }
58
- const request = {
59
- Name: projectConfig.name,
60
- SiteId: matchedSite.SiteId,
61
- SiteName: matchedSite.SiteName,
62
- Route: matchedSite.Route,
63
- RouteId: matchedSite.RouteId
65
+ const siteId = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.siteId;
66
+ const configId = matchedRoute === null || matchedRoute === void 0 ? void 0 : matchedRoute.configId;
67
+ const deleteRouteReq = {
68
+ siteId: siteId,
69
+ configId: configId
64
70
  };
65
- const res = yield server.deleteRoutineRelatedRoute(request);
66
- const isDeleteSuccess = (res === null || res === void 0 ? void 0 : res.data.Status) === 'OK';
71
+ const deleteRouteRes = yield api.deleteRoutineRoute(deleteRouteReq);
72
+ const isDeleteSuccess = deleteRouteRes.statusCode === 200;
67
73
  if (isDeleteSuccess) {
68
74
  logger.success(t('route_delete_success').d('Delete route success!'));
69
75
  }
@@ -0,0 +1,124 @@
1
+ /* 操作符号枚举 */
2
+ export var OPERATOR_ENUM;
3
+ (function (OPERATOR_ENUM) {
4
+ OPERATOR_ENUM["Eq"] = "eq";
5
+ OPERATOR_ENUM["Ne"] = "ne";
6
+ OPERATOR_ENUM["Contains"] = "contains";
7
+ OPERATOR_ENUM["Negate_Contains"] = "negate_contains";
8
+ OPERATOR_ENUM["StartsWith"] = "starts_with";
9
+ OPERATOR_ENUM["Negate_StartsWith"] = "negate_starts_with";
10
+ OPERATOR_ENUM["EndsWith"] = "ends_with";
11
+ OPERATOR_ENUM["Negate_EndsWith"] = "negate_ends_with";
12
+ OPERATOR_ENUM["Matches"] = "matches";
13
+ OPERATOR_ENUM["Negate_Matches"] = "negate_matches";
14
+ OPERATOR_ENUM["In"] = "in";
15
+ OPERATOR_ENUM["Negate_In"] = "negate_in";
16
+ OPERATOR_ENUM["Gt"] = "gt";
17
+ OPERATOR_ENUM["Lt"] = "lt";
18
+ OPERATOR_ENUM["Ge"] = "ge";
19
+ OPERATOR_ENUM["Le"] = "le";
20
+ OPERATOR_ENUM["InList"] = "in_list";
21
+ OPERATOR_ENUM["Negate_InList"] = "negate_in_list";
22
+ })(OPERATOR_ENUM || (OPERATOR_ENUM = {}));
23
+ const RuleMatchTypeHost = 'http.host';
24
+ const RuleMatchTypeUriPath = 'http.request.uri.path';
25
+ const RuleMatchOperatorEq = OPERATOR_ENUM.Eq;
26
+ const RuleMatchOperatorStartsWith = OPERATOR_ENUM.StartsWith;
27
+ const RuleMatchOperatorEndsWith = OPERATOR_ENUM.EndsWith;
28
+ export const transferRouteToRuleString = (routePath) => {
29
+ if (!routePath) {
30
+ return '';
31
+ }
32
+ const index = routePath.indexOf('/');
33
+ let host = '';
34
+ let uriPath = '';
35
+ if (index < 0) {
36
+ host = routePath;
37
+ uriPath = '/';
38
+ }
39
+ else {
40
+ host = routePath.substring(0, index);
41
+ uriPath = routePath.substring(index);
42
+ }
43
+ let hostOperator = RuleMatchOperatorEq;
44
+ if (host.startsWith('*')) {
45
+ hostOperator = RuleMatchOperatorEndsWith;
46
+ host = host.replace(/\*/g, '');
47
+ }
48
+ let uriPathOperator = RuleMatchOperatorEq;
49
+ if (uriPath.endsWith('*')) {
50
+ uriPathOperator = RuleMatchOperatorStartsWith;
51
+ uriPath = uriPath.replace(/\*$/, '');
52
+ }
53
+ let ruleStr = '';
54
+ if (hostOperator === RuleMatchOperatorEq) {
55
+ if (uriPathOperator === RuleMatchOperatorEq) {
56
+ ruleStr = `(${RuleMatchTypeHost} ${hostOperator} "${host}" and ${RuleMatchTypeUriPath} ${uriPathOperator} "${uriPath}")`;
57
+ }
58
+ else if (uriPathOperator === RuleMatchOperatorStartsWith) {
59
+ ruleStr = `(${RuleMatchTypeHost} ${hostOperator} "${host}" and ${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath}, "${uriPath}"))`;
60
+ }
61
+ }
62
+ else if (hostOperator === RuleMatchOperatorEndsWith) {
63
+ if (uriPathOperator === RuleMatchOperatorEq) {
64
+ ruleStr = `(${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost}, "${host}") and ${RuleMatchTypeUriPath} ${uriPathOperator} "${uriPath}")`;
65
+ }
66
+ else if (uriPathOperator === RuleMatchOperatorStartsWith) {
67
+ ruleStr = `(${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost}, "${host}") and ${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath}, "${uriPath}"))`;
68
+ }
69
+ }
70
+ return ruleStr;
71
+ };
72
+ export const transferRuleStringToRoute = (ruleStr) => {
73
+ if (!ruleStr) {
74
+ return '';
75
+ }
76
+ // 去掉外层括号并按 " and " 分割
77
+ const cleanedRule = ruleStr.replace(/^\(|\)$/g, '');
78
+ const parts = cleanedRule.split(' and ');
79
+ if (parts.length !== 2) {
80
+ return '';
81
+ }
82
+ let host = '';
83
+ let uriPath = '';
84
+ // 处理host部分
85
+ const hostPart = parts[0].trim();
86
+ if (hostPart.startsWith(`${RuleMatchOperatorEndsWith}(${RuleMatchTypeHost},`)) {
87
+ // host匹配eq时的逻辑
88
+ // ends_with(http.host, "value")
89
+ const match = hostPart.match(/ends_with\(http\.host,\s*"([^"]+)"\)/);
90
+ if (match) {
91
+ host = `*${match[1]}`; // 加前缀 *
92
+ }
93
+ }
94
+ else if (hostPart.startsWith(`${RuleMatchTypeHost} ${RuleMatchOperatorEq}`)) {
95
+ // host匹配eq时的逻辑
96
+ // http.host eq "value"
97
+ const match = hostPart.match(/http\.host eq "([^"]+)"/);
98
+ if (match) {
99
+ host = match[1];
100
+ }
101
+ }
102
+ // 处理uriPath 部分
103
+ const uriPathPart = parts[1].trim();
104
+ if (uriPathPart.startsWith(`${RuleMatchOperatorStartsWith}(${RuleMatchTypeUriPath},`)) {
105
+ // uriPath匹配startsWith时的逻辑
106
+ // starts_with(http.request.uri.path, "value")
107
+ const match = uriPathPart.match(/starts_with\(http\.request\.uri\.path,\s*"([^"]+)"\)/);
108
+ if (match) {
109
+ uriPath = `${match[1]}*`; // 加后缀 *
110
+ }
111
+ }
112
+ else if (uriPathPart.startsWith(`${RuleMatchTypeUriPath} ${RuleMatchOperatorEq}`)) {
113
+ // uriPath匹配eq时的逻辑
114
+ // http.request.uri.path eq "value"
115
+ const match = uriPathPart.match(/http\.request\.uri\.path eq "([^"]+)"/);
116
+ if (match) {
117
+ uriPath = match[1];
118
+ }
119
+ }
120
+ if (!host || !uriPath) {
121
+ return '';
122
+ }
123
+ return `${host}${uriPath}`;
124
+ };
@@ -1,7 +1,7 @@
1
+ import t from '../../i18n/index.js';
2
+ import addRoute from './add.js';
1
3
  import deleteRoute from './delete.js';
2
4
  import listRoute from './list.js';
3
- import addRoute from './add.js';
4
- import t from '../../i18n/index.js';
5
5
  let yargsIns;
6
6
  const routeCommand = {
7
7
  command: 'route [script]',