esa-cli 1.0.1 → 1.0.2-beta.1

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.
@@ -0,0 +1,126 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as $OpenApi from '@alicloud/openapi-client';
11
+ // Domestic site endpoint
12
+ const DOMESTIC_ENDPOINT = 'esa.cn-hangzhou.aliyuncs.com';
13
+ // International site endpoint
14
+ const INTERNATIONAL_ENDPOINT = 'esa.ap-southeast-1.aliyuncs.com';
15
+ /**
16
+ * Validate credentials for a single endpoint
17
+ */
18
+ function validateEndpoint(accessKeyId, accessKeySecret, endpoint) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ try {
21
+ const apiConfig = new $OpenApi.Config({
22
+ accessKeyId,
23
+ accessKeySecret,
24
+ endpoint
25
+ });
26
+ const client = new $OpenApi.default.default(apiConfig);
27
+ const params = {
28
+ action: 'GetErService',
29
+ version: '2024-09-10',
30
+ protocol: 'https',
31
+ method: 'GET',
32
+ authType: 'AK',
33
+ bodyType: 'json',
34
+ reqBodyType: 'json',
35
+ style: 'RPC',
36
+ pathname: '/',
37
+ toMap: function () {
38
+ return this;
39
+ }
40
+ };
41
+ const request = new $OpenApi.OpenApiRequest({
42
+ query: {}
43
+ });
44
+ const runtime = {
45
+ toMap: function () {
46
+ return this;
47
+ }
48
+ };
49
+ const response = yield client.callApi(params, request, runtime);
50
+ if (response.statusCode === 200) {
51
+ if (response.body.Status === 'Running') {
52
+ return { valid: true };
53
+ }
54
+ else {
55
+ return {
56
+ valid: false,
57
+ message: 'Functions and Pages is not active'
58
+ };
59
+ }
60
+ }
61
+ else if (response.statusCode === 403) {
62
+ return {
63
+ valid: false,
64
+ message: 'Permission denied: Access key or secret is incorrect'
65
+ };
66
+ }
67
+ else {
68
+ return {
69
+ valid: false,
70
+ message: `Error: ${response.statusCode}`
71
+ };
72
+ }
73
+ }
74
+ catch (error) {
75
+ return {
76
+ valid: false,
77
+ message: error instanceof Error ? error.message : 'Unknown error'
78
+ };
79
+ }
80
+ });
81
+ }
82
+ /**
83
+ * Validate if AK/SK/endpoint are valid
84
+ *
85
+ * @param accessKeyId - AccessKey ID
86
+ * @param accessKeySecret - AccessKey Secret
87
+ * @returns Validation result, including whether valid, site type and endpoint
88
+ */
89
+ export function validateCredentials(accessKeyId, accessKeySecret) {
90
+ return __awaiter(this, void 0, void 0, function* () {
91
+ if (process.env.CUSTOM_ENDPOINT) {
92
+ const result = yield validateEndpoint(accessKeyId, accessKeySecret, process.env.CUSTOM_ENDPOINT);
93
+ if (result.valid) {
94
+ return { valid: true, endpoint: process.env.CUSTOM_ENDPOINT };
95
+ }
96
+ else {
97
+ return { valid: false, message: result.message };
98
+ }
99
+ }
100
+ // First validate domestic site
101
+ const domesticResult = yield validateEndpoint(accessKeyId, accessKeySecret, DOMESTIC_ENDPOINT);
102
+ if (domesticResult.valid) {
103
+ return {
104
+ valid: true,
105
+ siteType: 'domestic',
106
+ endpoint: DOMESTIC_ENDPOINT
107
+ };
108
+ }
109
+ // If domestic site validation fails, validate international site
110
+ const internationalResult = yield validateEndpoint(accessKeyId, accessKeySecret, INTERNATIONAL_ENDPOINT);
111
+ if (internationalResult.valid) {
112
+ return {
113
+ valid: true,
114
+ siteType: 'international',
115
+ endpoint: INTERNATIONAL_ENDPOINT
116
+ };
117
+ }
118
+ // Both failed, return failure result
119
+ return {
120
+ valid: false,
121
+ message: domesticResult.message ||
122
+ internationalResult.message ||
123
+ 'Invalid credentials'
124
+ };
125
+ });
126
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-beta.1",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",
package/zh_CN.md CHANGED
@@ -3,10 +3,10 @@
3
3
  ESA CLI 是用于构建阿里云 ESA Functions 与 Pages 的命令行工具。
4
4
 
5
5
  <p>
6
- <a href="https://discord.gg/xygV6MYx">
6
+ <a href="https://discord.gg/BxcRVEeh">
7
7
  <img alt="Discord 中文" src="https://img.shields.io/badge/Discord-中文-5865F2?logo=discord&logoColor=white" />
8
8
  </a>
9
- <a href="https://discord.gg/YeFg4yUA" style="margin-left:8px;">
9
+ <a href="https://discord.gg/SHYe5926" style="margin-left:8px;">
10
10
  <img alt="Discord English" src="https://img.shields.io/badge/Discord-English-5865F2?logo=discord&logoColor=white" />
11
11
  </a>
12
12
  </p>