esa-cli 1.0.8-beta.4 → 1.0.9

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.
@@ -389,57 +389,46 @@ export function waitForCodeVersionReady(name_1, codeVersion_1, env_1) {
389
389
  */
390
390
  export function displayDeploySuccess(projectName_1) {
391
391
  return __awaiter(this, arguments, void 0, function* (projectName, showDomainGuide = true, showRouteGuide = true) {
392
- var _a;
392
+ var _a, _b;
393
393
  const service = yield ApiService.getInstance();
394
394
  const res = yield service.getRoutine({ Name: projectName });
395
395
  const defaultUrl = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.DefaultRelatedRecord;
396
- const visitUrl = defaultUrl ? 'https://' + defaultUrl : '';
397
- const accent = chalk.hex('#7C3AED');
396
+ let visitUrl = defaultUrl ? 'https://' + defaultUrl : '';
397
+ // Get access token for the visit URL
398
+ let hasToken = false;
399
+ if (visitUrl) {
400
+ const tokenRes = yield service.getRoutineAccessToken({
401
+ Name: projectName
402
+ });
403
+ const token = (_b = tokenRes === null || tokenRes === void 0 ? void 0 : tokenRes.data) === null || _b === void 0 ? void 0 : _b.Token;
404
+ if (token) {
405
+ visitUrl += `?esa_er_token=${token}`;
406
+ hasToken = true;
407
+ }
408
+ }
398
409
  const label = chalk.hex('#22c55e');
399
410
  const subtle = chalk.gray;
400
- const title = `${chalk.bold('🚀 ')}${chalk.bold(t('init_deploy_success').d('Deploy Success'))}`;
401
- const lineUrl = `${label('URL')} ${visitUrl ? chalk.yellowBright(visitUrl) : subtle('-')}`;
402
- const lineProject = `${label('APP')} ${chalk.cyan(projectName || '-')}`;
403
- const lineCd = projectName
404
- ? `${label('TIP')} ${t('deploy_success_cd').d('Enter project directory')}: ${chalk.green(`cd ${projectName}`)}`
405
- : '';
406
- const guides = [];
411
+ const orange = chalk.hex('#FFA500');
412
+ logger.block();
413
+ logger.log(`${chalk.bold('🚀')} ${chalk.hex('#7C3AED').bold(t('init_deploy_success').d('Deploy Success'))}`);
414
+ logger.block();
415
+ logger.log(`${label('APP')} ${chalk.cyan(projectName || '-')}`);
416
+ if (hasToken) {
417
+ logger.log(orange(`⏰ ${t('token_validity_tip').d('Token is valid for 1 hour')}`));
418
+ }
419
+ logger.log(`${label('URL')} ${visitUrl ? chalk.yellowBright(visitUrl) : subtle('-')}`);
420
+ if (projectName) {
421
+ logger.block();
422
+ logger.log(`${label('TIP')} ${t('deploy_success_cd').d('Enter project directory')}: ${chalk.green(`cd ${projectName}`)}`);
423
+ }
407
424
  if (showDomainGuide) {
408
- guides.push(`${label('TIP')} ${t('deploy_success_guide').d('Add a custom domain')}: ${chalk.green('esa-cli domain add <DOMAIN>')}`);
425
+ logger.log(`${label('TIP')} ${t('deploy_success_guide').d('Add a custom domain')}: ${chalk.green('esa-cli domain add <DOMAIN>')}`);
409
426
  }
410
427
  if (showRouteGuide) {
411
- guides.push(`${label('TIP')} ${t('deploy_success_guide_2').d('Add routes for a site')}: ${chalk.green('esa-cli route add -r <ROUTE> -s <SITE>')}`);
428
+ logger.log(`${label('TIP')} ${t('deploy_success_guide_2').d('Add routes for a site')}: ${chalk.green('esa-cli route add -r <ROUTE> -s <SITE>')}`);
412
429
  }
413
- const tip = `${subtle(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'))}`;
414
- const lines = [
415
- accent(title),
416
- '',
417
- lineProject,
418
- lineUrl,
419
- lineCd ? '' : '',
420
- lineCd || '',
421
- guides.length ? '' : '',
422
- ...guides,
423
- guides.length ? '' : '',
424
- tip
425
- ];
426
- const stripAnsi = (s) => s.replace(/\x1B\[[0-?]*[ -\/]*[@-~]/g, '');
427
- const contentWidth = Math.max(...lines.map((l) => stripAnsi(l).length));
428
- const borderColor = chalk.hex('#00D4FF').bold;
429
- const top = `${borderColor('╔')}${borderColor('═'.repeat(contentWidth + 2))}${borderColor('╗')}`;
430
- const bottom = `${borderColor('╚')}${borderColor('═'.repeat(contentWidth + 2))}${borderColor('╝')}`;
431
- const boxLines = [
432
- top,
433
- ...lines.map((l) => {
434
- const pad = ' '.repeat(contentWidth - stripAnsi(l).length);
435
- const left = borderColor('║');
436
- const right = borderColor('║');
437
- return `${left} ${l}${pad} ${right}`;
438
- }),
439
- bottom
440
- ];
441
430
  logger.block();
442
- boxLines.forEach((l) => logger.log(l));
431
+ logger.log(subtle(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.')));
443
432
  logger.block();
444
433
  });
445
434
  }
@@ -12,11 +12,11 @@ class EdgeKV {
12
12
  if (typeof root === 'undefined') {
13
13
  root = Deno.cwd();
14
14
  }
15
- if (root === '/') {
15
+ const prev = path.resolve(root, '../');
16
+ if (prev === root) {
16
17
  return Deno.cwd();
17
18
  }
18
19
  const file = path.join(root, 'cliconfig.toml');
19
- const prev = path.resolve(root, '../');
20
20
  try {
21
21
  const hasToml = fs.existsSync(file);
22
22
  if (hasToml) {
@@ -13,42 +13,11 @@ import t from '../../i18n/index.js';
13
13
  import logger from '../../libs/logger.js';
14
14
  import { getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
15
15
  import { validateCredentials } from '../../utils/validateCredentials.js';
16
- /** Parse STS token string: "AccessKeyId,AccessKeySecret,SecurityToken" or JSON */
17
- function parseStsToken(raw) {
18
- var _a, _b, _c;
19
- const s = raw.trim();
20
- if (!s)
21
- return null;
22
- if (s.startsWith('{')) {
23
- try {
24
- const o = JSON.parse(s);
25
- const accessKeyId = (_a = o.AccessKeyId) !== null && _a !== void 0 ? _a : o.accessKeyId;
26
- const accessKeySecret = (_b = o.AccessKeySecret) !== null && _b !== void 0 ? _b : o.accessKeySecret;
27
- const securityToken = (_c = o.SecurityToken) !== null && _c !== void 0 ? _c : o.securityToken;
28
- if (accessKeyId && accessKeySecret && securityToken) {
29
- return { accessKeyId, accessKeySecret, securityToken };
30
- }
31
- }
32
- catch (_d) {
33
- return null;
34
- }
35
- return null;
36
- }
37
- const parts = s.split(',').map((p) => p.trim());
38
- if (parts.length >= 3) {
39
- return {
40
- accessKeyId: parts[0],
41
- accessKeySecret: parts[1],
42
- securityToken: parts.slice(2).join(',').trim()
43
- };
44
- }
45
- return null;
46
- }
47
16
  const login = {
48
17
  command: 'login',
49
18
  describe: `🔑 ${t('login_describe').d('Login to the server')}`,
50
19
  builder: (yargs) => {
51
- var _a, _b, _c;
20
+ var _a, _b;
52
21
  return yargs
53
22
  .option('access-key-id', {
54
23
  alias: 'ak',
@@ -59,10 +28,6 @@ const login = {
59
28
  alias: 'sk',
60
29
  describe: (_b = t('login_option_access_key_secret')) === null || _b === void 0 ? void 0 : _b.d('AccessKey Secret'),
61
30
  type: 'string'
62
- })
63
- .option('sts-token', {
64
- describe: (_c = t('login_option_sts_token')) === null || _c === void 0 ? void 0 : _c.d('STS token: AccessKeyId,AccessKeySecret,SecurityToken (comma-separated, one-shot)'),
65
- type: 'string'
66
31
  });
67
32
  },
68
33
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
@@ -73,10 +38,8 @@ export default login;
73
38
  export function handleLogin(argv) {
74
39
  return __awaiter(this, void 0, void 0, function* () {
75
40
  generateDefaultConfig();
76
- const envSecurityToken = process.env.ESA_SECURITY_TOKEN;
77
- if (process.env.ESA_ACCESS_KEY_ID &&
78
- process.env.ESA_ACCESS_KEY_SECRET) {
79
- const result = yield validateCredentials(process.env.ESA_ACCESS_KEY_ID, process.env.ESA_ACCESS_KEY_SECRET, envSecurityToken);
41
+ if (process.env.ESA_ACCESS_KEY_ID && process.env.ESA_ACCESS_KEY_SECRET) {
42
+ const result = yield validateCredentials(process.env.ESA_ACCESS_KEY_ID, process.env.ESA_ACCESS_KEY_SECRET);
80
43
  if (result.valid) {
81
44
  logger.log(t('login_get_credentials_from_environment_variables').d('Get credentials from environment variables'));
82
45
  logger.success(t('login_success').d('Login success!'));
@@ -86,27 +49,6 @@ export function handleLogin(argv) {
86
49
  }
87
50
  return;
88
51
  }
89
- const stsTokenRaw = argv === null || argv === void 0 ? void 0 : argv['sts-token'];
90
- if (stsTokenRaw) {
91
- const parsed = parseStsToken(stsTokenRaw);
92
- if (!parsed) {
93
- logger.error(t('login_sts_token_format_invalid').d('Invalid STS token format. Use: AccessKeyId,AccessKeySecret,SecurityToken'));
94
- return;
95
- }
96
- const result = yield validateCredentials(parsed.accessKeyId, parsed.accessKeySecret, parsed.securityToken);
97
- if (result.valid) {
98
- logger.success(t('login_success').d('Login success!'));
99
- updateCliConfigFile(Object.assign({ auth: {
100
- accessKeyId: parsed.accessKeyId,
101
- accessKeySecret: parsed.accessKeySecret,
102
- securityToken: parsed.securityToken
103
- } }, (result.endpoint ? { endpoint: result.endpoint } : {})));
104
- }
105
- else {
106
- logger.error(result.message || 'Login failed');
107
- }
108
- return;
109
- }
110
52
  const accessKeyId = argv === null || argv === void 0 ? void 0 : argv['access-key-id'];
111
53
  const accessKeySecret = argv === null || argv === void 0 ? void 0 : argv['access-key-secret'];
112
54
  if (accessKeyId && accessKeySecret) {
@@ -131,7 +73,7 @@ export function handleLogin(argv) {
131
73
  cliConfig.auth &&
132
74
  cliConfig.auth.accessKeyId &&
133
75
  cliConfig.auth.accessKeySecret) {
134
- const loginStatus = yield validateCredentials(cliConfig.auth.accessKeyId, cliConfig.auth.accessKeySecret, cliConfig.auth.securityToken);
76
+ const loginStatus = yield validateCredentials(cliConfig.auth.accessKeyId, cliConfig.auth.accessKeySecret);
135
77
  if (loginStatus.valid) {
136
78
  logger.warn(t('login_already').d('You are already logged in.'));
137
79
  const selected = (yield clackSelect({
@@ -157,47 +99,6 @@ export function handleLogin(argv) {
157
99
  }
158
100
  export function interactiveLogin() {
159
101
  return __awaiter(this, void 0, void 0, function* () {
160
- const loginMethod = (yield clackSelect({
161
- message: t('login_method_select').d('Choose login method'),
162
- options: [
163
- {
164
- label: t('login_method_aksk').d('AK/SK (AccessKey ID + AccessKey Secret)'),
165
- value: 'aksk'
166
- },
167
- {
168
- label: t('login_method_sts').d('STS Token (one-shot: AccessKeyId,AccessKeySecret,SecurityToken)'),
169
- value: 'sts'
170
- }
171
- ]
172
- }));
173
- if (isCancel(loginMethod)) {
174
- return;
175
- }
176
- if (loginMethod === 'sts') {
177
- const stsInput = (yield clackText({
178
- message: t('login_sts_token_prompt').d('Enter STS token (AccessKeyId,AccessKeySecret,SecurityToken):')
179
- }));
180
- if (isCancel(stsInput))
181
- return;
182
- const parsed = parseStsToken(stsInput);
183
- if (!parsed) {
184
- logger.error(t('login_sts_token_format_invalid').d('Invalid STS token format. Use: AccessKeyId,AccessKeySecret,SecurityToken'));
185
- return;
186
- }
187
- const loginStatus = yield validateCredentials(parsed.accessKeyId, parsed.accessKeySecret, parsed.securityToken);
188
- if (loginStatus.valid) {
189
- yield updateCliConfigFile(Object.assign({ auth: {
190
- accessKeyId: parsed.accessKeyId,
191
- accessKeySecret: parsed.accessKeySecret,
192
- securityToken: parsed.securityToken
193
- } }, (loginStatus.endpoint ? { endpoint: loginStatus.endpoint } : {})));
194
- logger.success(t('login_success').d('Login success!'));
195
- }
196
- else {
197
- logger.error(loginStatus.message || 'Login failed');
198
- }
199
- return;
200
- }
201
102
  const styledUrl = chalk.underline.blue('https://ram.console.aliyun.com/manage/ak');
202
103
  logger.log(`🔑 ${chalk.underline(t('login_get_ak_sk').d(`Please go to the following link to get your account's AccessKey ID and AccessKey Secret`))}`);
203
104
  logger.log(`👉 ${styledUrl}`);
@@ -28,18 +28,11 @@ export function handleLogout() {
28
28
  return;
29
29
  }
30
30
  if (!cliConfig.auth) {
31
- cliConfig.auth = {
32
- accessKeyId: '',
33
- accessKeySecret: '',
34
- securityToken: ''
35
- };
31
+ cliConfig.auth = { accessKeyId: '', accessKeySecret: '' };
36
32
  }
37
33
  else {
38
34
  cliConfig.auth.accessKeyId = '';
39
35
  cliConfig.auth.accessKeySecret = '';
40
- if ('securityToken' in cliConfig.auth) {
41
- cliConfig.auth.securityToken = '';
42
- }
43
36
  }
44
37
  yield updateCliConfigFile(cliConfig);
45
38
  logger.success(t('logout_success').d('Logout successfully'));
@@ -16,7 +16,7 @@ import { ApiService } from '../libs/apiService.js';
16
16
  import { isInstalledGit } from '../libs/git/index.js';
17
17
  import logger from '../libs/logger.js';
18
18
  import { getRoot } from '../utils/fileUtils/base.js';
19
- import { getApiConfig, getCliConfig, projectConfigPath } from '../utils/fileUtils/index.js';
19
+ import { getCliConfig, projectConfigPath } from '../utils/fileUtils/index.js';
20
20
  import { validateCredentials } from '../utils/validateCredentials.js';
21
21
  import { getRoutineDetails } from './common/utils.js';
22
22
  export const checkDirectory = (isCheckGit = false) => {
@@ -78,26 +78,28 @@ export function validDomain(domain) {
78
78
  }
79
79
  export function checkIsLoginSuccess() {
80
80
  return __awaiter(this, void 0, void 0, function* () {
81
- var _a, _b, _c;
81
+ var _a, _b;
82
82
  const cliConfig = getCliConfig();
83
83
  let accessKeyId = process.env.ESA_ACCESS_KEY_ID || ((_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId);
84
84
  let accessKeySecret = process.env.ESA_ACCESS_KEY_SECRET || ((_b = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret);
85
- const securityToken = process.env.ESA_SECURITY_TOKEN || ((_c = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _c === void 0 ? void 0 : _c.securityToken);
86
85
  if (accessKeyId && accessKeySecret) {
87
- const result = yield validateCredentials(accessKeyId, accessKeySecret, securityToken);
86
+ const result = yield validateCredentials(accessKeyId, accessKeySecret);
88
87
  const server = yield ApiService.getInstance();
89
88
  if (result.valid) {
90
- const auth = {
91
- accessKeyId,
92
- accessKeySecret
93
- };
94
- if (securityToken)
95
- auth.securityToken = securityToken;
96
- // 使用配置文件/项目里的 endpoint,避免 validateCredentials 探测到的公网域名
97
- //(如 esa.cn-hangzhou)覆盖用户显式配置的预发等地址
98
- const fileConfig = getApiConfig();
99
- server.updateConfig(Object.assign(Object.assign({}, fileConfig), { auth }));
100
- api.updateConfig(Object.assign(Object.assign({}, fileConfig), { auth }));
89
+ server.updateConfig({
90
+ auth: {
91
+ accessKeyId,
92
+ accessKeySecret
93
+ },
94
+ endpoint: result.endpoint
95
+ });
96
+ api.updateConfig({
97
+ auth: {
98
+ accessKeyId,
99
+ accessKeySecret
100
+ },
101
+ endpoint: result.endpoint
102
+ });
101
103
  return true;
102
104
  }
103
105
  }
@@ -1075,30 +1075,6 @@
1075
1075
  "en": "AccessKey Secret (SK)",
1076
1076
  "zh_CN": "AccessKey Secret (SK)"
1077
1077
  },
1078
- "login_option_sts_token": {
1079
- "en": "STS token: AccessKeyId,AccessKeySecret,SecurityToken (comma-separated, one-shot)",
1080
- "zh_CN": "STS 临时凭证:AccessKeyId,AccessKeySecret,SecurityToken(逗号分隔,一次性输入)"
1081
- },
1082
- "login_sts_token_prompt": {
1083
- "en": "Enter STS token (AccessKeyId,AccessKeySecret,SecurityToken):",
1084
- "zh_CN": "请输入 STS 凭证(AccessKeyId,AccessKeySecret,SecurityToken):"
1085
- },
1086
- "login_sts_token_format_invalid": {
1087
- "en": "Invalid STS token format. Use: AccessKeyId,AccessKeySecret,SecurityToken",
1088
- "zh_CN": "STS 凭证格式错误,请使用:AccessKeyId,AccessKeySecret,SecurityToken"
1089
- },
1090
- "login_method_select": {
1091
- "en": "Choose login method",
1092
- "zh_CN": "选择登录方式"
1093
- },
1094
- "login_method_aksk": {
1095
- "en": "AK/SK (AccessKey ID + AccessKey Secret)",
1096
- "zh_CN": "AK/SK(AccessKey ID + AccessKey Secret)"
1097
- },
1098
- "login_method_sts": {
1099
- "en": "STS Token (one-shot: AccessKeyId,AccessKeySecret,SecurityToken)",
1100
- "zh_CN": "STS 临时凭证(一次性输入:AccessKeyId,AccessKeySecret,SecurityToken)"
1101
- },
1102
1078
  "login_option_skip_login": {
1103
1079
  "en": "Skip login",
1104
1080
  "zh_CN": "跳过登录"
@@ -1346,5 +1322,17 @@
1346
1322
  "login_get_credentials_from_environment_variables": {
1347
1323
  "en": "Get credentials from environment variables",
1348
1324
  "zh_CN": ""
1325
+ },
1326
+ "main_skip_update_check": {
1327
+ "en": "Skip CLI version update check",
1328
+ "zh_CN": ""
1329
+ },
1330
+ "deploy_visit_url": {
1331
+ "en": "Visit URL (with token)",
1332
+ "zh_CN": ""
1333
+ },
1334
+ "token_validity_tip": {
1335
+ "en": "Token is valid for 1 hour",
1336
+ "zh_CN": "该 URL 有效期为 1 小时"
1349
1337
  }
1350
1338
  }
package/dist/index.js CHANGED
@@ -44,6 +44,9 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
44
44
  if (argv.debug) {
45
45
  logger.setLogLevel('debug');
46
46
  }
47
+ if (argv.skipUpdateCheck) {
48
+ return;
49
+ }
47
50
  try {
48
51
  // Pass current command (first positional) so version check can decide prompting behavior
49
52
  yield checkCLIVersion((argv._ && argv._[0] ? String(argv._[0]) : ''));
@@ -66,6 +69,11 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
66
69
  describe: t('dev_option_debugger').d('Output debug logs'),
67
70
  type: 'boolean',
68
71
  default: false
72
+ })
73
+ .options('skip-update-check', {
74
+ describe: t('main_skip_update_check').d('Skip CLI version update check'),
75
+ type: 'boolean',
76
+ default: false
69
77
  });
70
78
  esa.command('*', false, () => { }, (args) => {
71
79
  if (args._.length > 0) {
package/dist/libs/api.js CHANGED
@@ -74,10 +74,13 @@ class Client {
74
74
  this.client = Client.createClient(config);
75
75
  }
76
76
  static createClient(config) {
77
- var _a, _b, _c;
78
- const apiConfig = new $OpenApi.Config(Object.assign({ accessKeyId: (_a = config.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId, accessKeySecret: (_b = config.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret, endpoint: config.endpoint, userAgent: CLI_USER_AGENT }, (((_c = config.auth) === null || _c === void 0 ? void 0 : _c.securityToken)
79
- ? { securityToken: config.auth.securityToken }
80
- : {})));
77
+ var _a, _b;
78
+ const apiConfig = new $OpenApi.Config({
79
+ accessKeyId: (_a = config.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
80
+ accessKeySecret: (_b = config.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
81
+ endpoint: config.endpoint,
82
+ userAgent: CLI_USER_AGENT
83
+ });
81
84
  return new ESA.default(apiConfig);
82
85
  }
83
86
  updateConfig(config) {
@@ -16,10 +16,13 @@ import { CLI_USER_AGENT } from './constants.js';
16
16
  import { Environment } from './interface.js';
17
17
  export class ApiService {
18
18
  constructor(cliConfig) {
19
- var _a, _b, _c;
20
- let apiConfig = new $OpenApi.Config(Object.assign({ accessKeyId: (_a = cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId, accessKeySecret: (_b = cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret, endpoint: cliConfig.endpoint, userAgent: CLI_USER_AGENT }, (((_c = cliConfig.auth) === null || _c === void 0 ? void 0 : _c.securityToken)
21
- ? { securityToken: cliConfig.auth.securityToken }
22
- : {})));
19
+ var _a, _b;
20
+ let apiConfig = new $OpenApi.Config({
21
+ accessKeyId: (_a = cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
22
+ accessKeySecret: (_b = cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
23
+ endpoint: cliConfig.endpoint,
24
+ userAgent: CLI_USER_AGENT
25
+ });
23
26
  this.client = new $OpenApi.default.default(apiConfig);
24
27
  }
25
28
  static getInstance() {
@@ -32,10 +35,13 @@ export class ApiService {
32
35
  });
33
36
  }
34
37
  updateConfig(newConfig) {
35
- var _a, _b, _c;
36
- let apiConfig = new $OpenApi.Config(Object.assign({ accessKeyId: (_a = newConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId, accessKeySecret: (_b = newConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret, endpoint: newConfig.endpoint, userAgent: CLI_USER_AGENT }, (((_c = newConfig.auth) === null || _c === void 0 ? void 0 : _c.securityToken)
37
- ? { securityToken: newConfig.auth.securityToken }
38
- : {})));
38
+ var _a, _b;
39
+ let apiConfig = new $OpenApi.Config({
40
+ accessKeyId: (_a = newConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
41
+ accessKeySecret: (_b = newConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
42
+ endpoint: newConfig.endpoint,
43
+ userAgent: CLI_USER_AGENT
44
+ });
39
45
  this.client = new $OpenApi.default.default(apiConfig);
40
46
  }
41
47
  /**
@@ -1094,5 +1100,51 @@ export class ApiService {
1094
1100
  return null;
1095
1101
  });
1096
1102
  }
1103
+ getRoutineAccessToken(requestParams) {
1104
+ return __awaiter(this, void 0, void 0, function* () {
1105
+ try {
1106
+ let params = {
1107
+ action: 'GetRoutineAccessToken',
1108
+ version: '2024-09-10',
1109
+ protocol: 'https',
1110
+ method: 'GET',
1111
+ authType: 'AK',
1112
+ bodyType: 'json',
1113
+ reqBodyType: 'json',
1114
+ style: 'RPC',
1115
+ pathname: '/',
1116
+ toMap: function () {
1117
+ return this;
1118
+ }
1119
+ };
1120
+ let request = new $OpenApi.OpenApiRequest({
1121
+ query: {
1122
+ Name: requestParams.Name
1123
+ }
1124
+ });
1125
+ let runtime = {
1126
+ toMap: function () {
1127
+ return this;
1128
+ }
1129
+ };
1130
+ const res = yield this.client.callApi(params, request, runtime);
1131
+ if (res.statusCode === 200 && res.body) {
1132
+ const ret = {
1133
+ code: res.statusCode.toString(),
1134
+ data: {
1135
+ RequestId: res.body.RequestId,
1136
+ Token: res.body.Token,
1137
+ DefaultRelatedRecord: res.body.DefaultRelatedRecord
1138
+ }
1139
+ };
1140
+ return ret;
1141
+ }
1142
+ }
1143
+ catch (error) {
1144
+ // Token retrieval failure is non-critical, silently return null
1145
+ }
1146
+ return null;
1147
+ });
1148
+ }
1097
1149
  }
1098
1150
  ApiService.instance = null;
@@ -49,7 +49,7 @@ export function checkCLIVersion(currentCommand) {
49
49
  const fetchTimeout = setTimeout(() => controller.abort(), 5000);
50
50
  let response;
51
51
  try {
52
- response = yield fetch('https://registry.npmjs.org/esa-cli/latest', {
52
+ response = yield fetch('https://registry.npmmirror.com/esa-cli/latest', {
53
53
  signal: controller.signal
54
54
  });
55
55
  }
@@ -16,6 +16,14 @@ import logger from '../../libs/logger.js';
16
16
  import { getDirName, getRoot } from './base.js';
17
17
  const __dirname = getDirName(import.meta.url);
18
18
  const root = getRoot();
19
+ /**
20
+ * Strip JSONC content (comments + trailing commas) to make it valid JSON
21
+ */
22
+ function stripJsonc(content) {
23
+ return content
24
+ .replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '')
25
+ .replace(/,\s*([}\]])/g, '$1');
26
+ }
19
27
  // Function to get the actual project config file path (supports both .jsonc and .toml)
20
28
  export const getProjectConfigPath = (filePath = root) => {
21
29
  const configFormats = ['esa.jsonc', 'esa.toml'];
@@ -72,7 +80,7 @@ export function updateProjectConfigFile(configUpdate_1) {
72
80
  // Detect file format based on file extension
73
81
  if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
74
82
  // Handle JSONC format
75
- const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
83
+ const jsonContent = stripJsonc(configFileContent);
76
84
  config = JSON.parse(jsonContent);
77
85
  config = Object.assign(Object.assign({}, config), configUpdate);
78
86
  updatedConfigString = JSON.stringify(config, null, 2) + '\n';
@@ -101,7 +109,7 @@ export function updateCliConfigFile(configUpdate) {
101
109
  // Detect file format based on file extension
102
110
  if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
103
111
  // Handle JSONC format
104
- const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
112
+ const jsonContent = stripJsonc(configFileContent);
105
113
  config = JSON.parse(jsonContent);
106
114
  config = Object.assign(Object.assign({}, config), configUpdate);
107
115
  updatedConfigString = JSON.stringify(config, null, 2) + '\n';
@@ -126,8 +134,8 @@ export function readConfigFile(configPath) {
126
134
  const configFileContent = fs.readFileSync(configPath, 'utf-8');
127
135
  try {
128
136
  if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
129
- // Remove comments for JSON parsing
130
- const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
137
+ // Remove comments and trailing commas for JSON parsing
138
+ const jsonContent = stripJsonc(configFileContent);
131
139
  const config = JSON.parse(jsonContent);
132
140
  return config;
133
141
  }
@@ -260,13 +268,12 @@ export function getDevOpenBrowserUrl() {
260
268
  return `http://localhost:${port}`;
261
269
  }
262
270
  export const getApiConfig = () => {
263
- var _a, _b, _c;
271
+ var _a, _b;
264
272
  const [cliConfig, projectConfig] = getConfigurations();
265
273
  let defaultConfig = {
266
274
  auth: {
267
275
  accessKeyId: '',
268
- accessKeySecret: '',
269
- securityToken: undefined
276
+ accessKeySecret: ''
270
277
  },
271
278
  endpoint: `esa.cn-hangzhou.aliyuncs.com`
272
279
  };
@@ -274,8 +281,7 @@ export const getApiConfig = () => {
274
281
  const config = {
275
282
  auth: {
276
283
  accessKeyId: (_a = combinedConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
277
- accessKeySecret: (_b = combinedConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
278
- securityToken: (_c = combinedConfig.auth) === null || _c === void 0 ? void 0 : _c.securityToken
284
+ accessKeySecret: (_b = combinedConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret
279
285
  },
280
286
  endpoint: combinedConfig.endpoint
281
287
  };
@@ -14,14 +14,15 @@ const DOMESTIC_ENDPOINT = 'esa.cn-hangzhou.aliyuncs.com';
14
14
  const INTERNATIONAL_ENDPOINT = 'esa.ap-southeast-1.aliyuncs.com';
15
15
  /**
16
16
  * Validate credentials for a single endpoint
17
- * @param securityToken - Optional STS SecurityToken; when provided, uses STS auth
18
17
  */
19
- function validateEndpoint(accessKeyId, accessKeySecret, endpoint, securityToken) {
18
+ function validateEndpoint(accessKeyId, accessKeySecret, endpoint) {
20
19
  return __awaiter(this, void 0, void 0, function* () {
21
20
  try {
22
- const apiConfig = new $OpenApi.Config(Object.assign({ accessKeyId,
21
+ const apiConfig = new $OpenApi.Config({
22
+ accessKeyId,
23
23
  accessKeySecret,
24
- endpoint }, (securityToken ? { securityToken } : {})));
24
+ endpoint
25
+ });
25
26
  const client = new $OpenApi.default.default(apiConfig);
26
27
  const params = {
27
28
  action: 'GetErService',
@@ -79,24 +80,25 @@ function validateEndpoint(accessKeyId, accessKeySecret, endpoint, securityToken)
79
80
  });
80
81
  }
81
82
  /**
82
- * Validate if AK/SK/endpoint are valid (supports STS when securityToken is provided)
83
+ * Validate if AK/SK/endpoint are valid
83
84
  *
84
85
  * @param accessKeyId - AccessKey ID
85
86
  * @param accessKeySecret - AccessKey Secret
86
- * @param securityToken - Optional STS SecurityToken for temporary credentials
87
87
  * @returns Validation result, including whether valid, site type and endpoint
88
88
  */
89
- export function validateCredentials(accessKeyId, accessKeySecret, securityToken) {
89
+ export function validateCredentials(accessKeyId, accessKeySecret) {
90
90
  return __awaiter(this, void 0, void 0, function* () {
91
- const withToken = (ep) => validateEndpoint(accessKeyId, accessKeySecret, ep, securityToken);
92
91
  if (process.env.CUSTOM_ENDPOINT) {
93
- const result = yield withToken(process.env.CUSTOM_ENDPOINT);
92
+ const result = yield validateEndpoint(accessKeyId, accessKeySecret, process.env.CUSTOM_ENDPOINT);
94
93
  if (result.valid) {
95
94
  return { valid: true, endpoint: process.env.CUSTOM_ENDPOINT };
96
95
  }
97
- return { valid: false, message: result.message };
96
+ else {
97
+ return { valid: false, message: result.message };
98
+ }
98
99
  }
99
- const domesticResult = yield withToken(DOMESTIC_ENDPOINT);
100
+ // First validate domestic site
101
+ const domesticResult = yield validateEndpoint(accessKeyId, accessKeySecret, DOMESTIC_ENDPOINT);
100
102
  if (domesticResult.valid) {
101
103
  return {
102
104
  valid: true,
@@ -104,7 +106,8 @@ export function validateCredentials(accessKeyId, accessKeySecret, securityToken)
104
106
  endpoint: DOMESTIC_ENDPOINT
105
107
  };
106
108
  }
107
- const internationalResult = yield withToken(INTERNATIONAL_ENDPOINT);
109
+ // If domestic site validation fails, validate international site
110
+ const internationalResult = yield validateEndpoint(accessKeyId, accessKeySecret, INTERNATIONAL_ENDPOINT);
108
111
  if (internationalResult.valid) {
109
112
  return {
110
113
  valid: true,
@@ -112,6 +115,7 @@ export function validateCredentials(accessKeyId, accessKeySecret, securityToken)
112
115
  endpoint: INTERNATIONAL_ENDPOINT
113
116
  };
114
117
  }
118
+ // Both failed, return failure result
115
119
  return {
116
120
  valid: false,
117
121
  message: domesticResult.message ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "1.0.8-beta.4",
3
+ "version": "1.0.9",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",