edgeone-cli 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.
- package/README.md +104 -0
- package/dist/api/client.d.ts +54 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +196 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/signer.d.ts +47 -0
- package/dist/api/signer.d.ts.map +1 -0
- package/dist/api/signer.js +100 -0
- package/dist/api/signer.js.map +1 -0
- package/dist/commands/config.d.ts +19 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +265 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/edgeone.d.ts +14 -0
- package/dist/commands/edgeone.d.ts.map +1 -0
- package/dist/commands/edgeone.js +415 -0
- package/dist/commands/edgeone.js.map +1 -0
- package/dist/edgeone/tasks/prefetch.d.ts +23 -0
- package/dist/edgeone/tasks/prefetch.d.ts.map +1 -0
- package/dist/edgeone/tasks/prefetch.js +16 -0
- package/dist/edgeone/tasks/prefetch.js.map +1 -0
- package/dist/edgeone/tasks/purge.d.ts +23 -0
- package/dist/edgeone/tasks/purge.d.ts.map +1 -0
- package/dist/edgeone/tasks/purge.js +16 -0
- package/dist/edgeone/tasks/purge.js.map +1 -0
- package/dist/errors/codes.d.ts +67 -0
- package/dist/errors/codes.d.ts.map +1 -0
- package/dist/errors/codes.js +134 -0
- package/dist/errors/codes.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/crypto.d.ts +13 -0
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/crypto.js +86 -0
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/signature.d.ts +14 -0
- package/dist/utils/signature.d.ts.map +1 -0
- package/dist/utils/signature.js +48 -0
- package/dist/utils/signature.js.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# EdgeOne CLI
|
|
2
|
+
|
|
3
|
+
> 本地化 EdgeOne 服务管理工具
|
|
4
|
+
|
|
5
|
+
## 简介
|
|
6
|
+
|
|
7
|
+
EdgeOne CLI 是一个命令行工具,用于在本地方便地管理 EdgeOne 配置。
|
|
8
|
+
|
|
9
|
+
## 功能特性
|
|
10
|
+
|
|
11
|
+
- ✅ **配置管理** - 本地安全存储 API 凭证
|
|
12
|
+
- 📋 **交互式配置** - 友好的命令行交互
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# 克隆项目
|
|
18
|
+
git clone <repository-url>
|
|
19
|
+
cd edgeone-cli
|
|
20
|
+
|
|
21
|
+
# 安装依赖
|
|
22
|
+
pnpm install
|
|
23
|
+
|
|
24
|
+
# 全局安装(可选)
|
|
25
|
+
pnpm link
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 快速开始
|
|
29
|
+
|
|
30
|
+
### 1. 初始化配置
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
node src/index.js config init
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
按提示输入您的 EdgeOne 凭证信息。
|
|
37
|
+
|
|
38
|
+
### 2. 查看配置
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
node src/index.js config show
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 命令说明
|
|
45
|
+
|
|
46
|
+
### config - 配置管理
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# 初始化配置
|
|
50
|
+
edgeone config init
|
|
51
|
+
|
|
52
|
+
# 显示当前配置
|
|
53
|
+
edgeone config show
|
|
54
|
+
|
|
55
|
+
# 编辑配置项
|
|
56
|
+
edgeone config edit
|
|
57
|
+
|
|
58
|
+
# 删除配置
|
|
59
|
+
edgeone config remove
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 配置文件
|
|
63
|
+
|
|
64
|
+
配置文件存储在 `~/.edgeone/config.json`:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"secretId": "your-secret-id",
|
|
69
|
+
"secretKey": "your-secret-key",
|
|
70
|
+
"zoneId": "your-zone-id",
|
|
71
|
+
"domain": "example.com"
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 开发
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# 安装依赖
|
|
79
|
+
pnpm install
|
|
80
|
+
|
|
81
|
+
# 运行
|
|
82
|
+
node src/index.js
|
|
83
|
+
|
|
84
|
+
# 或使用 npm script
|
|
85
|
+
pnpm start
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 项目结构
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
edgeone-cli/
|
|
92
|
+
├── src/
|
|
93
|
+
│ ├── commands/ # 命令定义
|
|
94
|
+
│ │ └── config.js
|
|
95
|
+
│ ├── utils/ # 工具函数
|
|
96
|
+
│ ├── config/ # 配置相关
|
|
97
|
+
│ └── index.js # 入口文件
|
|
98
|
+
├── package.json
|
|
99
|
+
└── README.md
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 许可证
|
|
103
|
+
|
|
104
|
+
ISC
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EdgeOne API 客户端
|
|
3
|
+
*/
|
|
4
|
+
import type { ConfigMode } from "../commands/config.js";
|
|
5
|
+
interface CreatePurgeTaskOptions {
|
|
6
|
+
zoneId?: string;
|
|
7
|
+
type: "purge_url" | "purge_prefix" | "purge_all";
|
|
8
|
+
targets?: string[];
|
|
9
|
+
url?: string;
|
|
10
|
+
}
|
|
11
|
+
interface CreatePrefetchTaskOptions {
|
|
12
|
+
zoneId?: string;
|
|
13
|
+
urls: string[];
|
|
14
|
+
}
|
|
15
|
+
interface CreatePurgeTaskResponse {
|
|
16
|
+
Response: {
|
|
17
|
+
RequestId: string;
|
|
18
|
+
JobId?: string;
|
|
19
|
+
Error?: {
|
|
20
|
+
Code: string;
|
|
21
|
+
Message: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare class EdgeOneClient {
|
|
26
|
+
private secretId;
|
|
27
|
+
private secretKey;
|
|
28
|
+
private endpoint;
|
|
29
|
+
private region;
|
|
30
|
+
private mode;
|
|
31
|
+
constructor(secretId: string, secretKey: string, endpoint: string, region?: string, mode?: ConfigMode);
|
|
32
|
+
/**
|
|
33
|
+
* 发送请求
|
|
34
|
+
*/
|
|
35
|
+
private request;
|
|
36
|
+
/**
|
|
37
|
+
* 创建清除缓存任务
|
|
38
|
+
*/
|
|
39
|
+
createPurgeTask(options: CreatePurgeTaskOptions): Promise<CreatePurgeTaskResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* 查询清除缓存任务
|
|
42
|
+
*/
|
|
43
|
+
describePurgeTasks(zoneIds?: string[]): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
* 创建预热任务
|
|
46
|
+
*/
|
|
47
|
+
createPrefetchTask(options: CreatePrefetchTaskOptions): Promise<CreatePurgeTaskResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* 查询预热任务
|
|
50
|
+
*/
|
|
51
|
+
describePrefetchTasks(zoneIds?: string[]): Promise<any>;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,UAAU,sBAAsB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,WAAW,GAAG,cAAc,GAAG,WAAW,CAAC;IACjD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,UAAU,yBAAyB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,UAAU,uBAAuB;IAC/B,QAAQ,EAAE;QACR,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;CACH;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,IAAI,CAAa;gBAEb,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAiB,EAAE,IAAI,GAAE,UAAyB;IAQ3H;;OAEG;YACW,OAAO;IAuDrB;;OAEG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAWxF;;OAEG;IACG,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IA8D1D;;OAEG;IACG,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAS9F;;OAEG;IACG,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CA6D9D"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { calculateSignature } from "../utils/signature.js";
|
|
2
|
+
export class EdgeOneClient {
|
|
3
|
+
secretId;
|
|
4
|
+
secretKey;
|
|
5
|
+
endpoint;
|
|
6
|
+
region;
|
|
7
|
+
mode;
|
|
8
|
+
constructor(secretId, secretKey, endpoint, region = "ap-guangzhou", mode = "production") {
|
|
9
|
+
this.secretId = secretId;
|
|
10
|
+
this.secretKey = secretKey;
|
|
11
|
+
this.endpoint = endpoint;
|
|
12
|
+
this.region = region;
|
|
13
|
+
this.mode = mode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 发送请求
|
|
17
|
+
*/
|
|
18
|
+
async request(action, version, params) {
|
|
19
|
+
const timestamp = Math.floor(Date.now() / 1000).toString();
|
|
20
|
+
// 请求体直接使用传入的参数
|
|
21
|
+
const requestBody = JSON.stringify(params);
|
|
22
|
+
// 计算签名
|
|
23
|
+
const authorization = calculateSignature({
|
|
24
|
+
secretId: this.secretId,
|
|
25
|
+
secretKey: this.secretKey,
|
|
26
|
+
endpoint: this.endpoint,
|
|
27
|
+
action,
|
|
28
|
+
requestBody,
|
|
29
|
+
timestamp,
|
|
30
|
+
});
|
|
31
|
+
const requestHeaders = {
|
|
32
|
+
Authorization: authorization,
|
|
33
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
34
|
+
"X-TC-Action": action,
|
|
35
|
+
"X-TC-Version": version,
|
|
36
|
+
"X-TC-Timestamp": timestamp,
|
|
37
|
+
"X-TC-Language": "zh-CN",
|
|
38
|
+
};
|
|
39
|
+
// 仅在调试模式下显示请求信息
|
|
40
|
+
if (this.mode === "debug") {
|
|
41
|
+
console.log("\n请求信息:");
|
|
42
|
+
console.log(` URL: https://${this.endpoint}`);
|
|
43
|
+
console.log(` Headers: ${JSON.stringify({ ...requestHeaders, Authorization: "***" }, null, 2)}`);
|
|
44
|
+
console.log(` Body: ${requestBody}\n`);
|
|
45
|
+
}
|
|
46
|
+
// 发送请求
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(`https://${this.endpoint}`, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: requestHeaders,
|
|
51
|
+
body: requestBody,
|
|
52
|
+
});
|
|
53
|
+
const result = await response.json();
|
|
54
|
+
// 仅在调试模式下显示响应结果
|
|
55
|
+
if (this.mode === "debug") {
|
|
56
|
+
console.log("响应结果:");
|
|
57
|
+
console.log(JSON.stringify(result, null, 2));
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 创建清除缓存任务
|
|
67
|
+
*/
|
|
68
|
+
async createPurgeTask(options) {
|
|
69
|
+
const params = {
|
|
70
|
+
ZoneId: options.zoneId || "*",
|
|
71
|
+
Type: options.type,
|
|
72
|
+
Method: "delete",
|
|
73
|
+
Targets: options.targets || [],
|
|
74
|
+
};
|
|
75
|
+
return await this.request("CreatePurgeTask", "2022-09-01", params);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 查询清除缓存任务
|
|
79
|
+
*/
|
|
80
|
+
async describePurgeTasks(zoneIds) {
|
|
81
|
+
const now = new Date();
|
|
82
|
+
const oneMonthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
|
83
|
+
// 格式化为 ISO 8601 格式,时区为 +08:00
|
|
84
|
+
const toISOStringWithTimezone = (date) => {
|
|
85
|
+
const year = date.getFullYear();
|
|
86
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
87
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
88
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
89
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
90
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
91
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}+08:00`;
|
|
92
|
+
};
|
|
93
|
+
const baseParams = {
|
|
94
|
+
StartTime: toISOStringWithTimezone(oneMonthAgo),
|
|
95
|
+
EndTime: toISOStringWithTimezone(now),
|
|
96
|
+
};
|
|
97
|
+
// 如果没有指定 zoneIds,直接查询
|
|
98
|
+
if (!zoneIds || zoneIds.length === 0) {
|
|
99
|
+
return await this.request("DescribePurgeTasks", "2022-09-01", baseParams);
|
|
100
|
+
}
|
|
101
|
+
// 如果只有一个 zone,直接查询
|
|
102
|
+
if (zoneIds.length === 1) {
|
|
103
|
+
baseParams.ZoneId = zoneIds[0];
|
|
104
|
+
return await this.request("DescribePurgeTasks", "2022-09-01", baseParams);
|
|
105
|
+
}
|
|
106
|
+
// 多个 zone,并发查询并合并结果
|
|
107
|
+
const requests = zoneIds.map(zoneId => {
|
|
108
|
+
const params = { ...baseParams, ZoneId: zoneId };
|
|
109
|
+
return this.request("DescribePurgeTasks", "2022-09-01", params);
|
|
110
|
+
});
|
|
111
|
+
const results = await Promise.all(requests);
|
|
112
|
+
// 合并结果
|
|
113
|
+
const merged = { Response: {} };
|
|
114
|
+
const allTasks = [];
|
|
115
|
+
for (const result of results) {
|
|
116
|
+
if (result.Response?.Error) {
|
|
117
|
+
// 如果任何一个请求失败,返回第一个错误
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
if (result.Response?.PurgeTasks) {
|
|
121
|
+
allTasks.push(...result.Response.PurgeTasks);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// 合并成功响应
|
|
125
|
+
merged.Response = {
|
|
126
|
+
...results[0].Response,
|
|
127
|
+
PurgeTasks: allTasks,
|
|
128
|
+
};
|
|
129
|
+
return merged;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 创建预热任务
|
|
133
|
+
*/
|
|
134
|
+
async createPrefetchTask(options) {
|
|
135
|
+
const params = {
|
|
136
|
+
ZoneId: options.zoneId || "*",
|
|
137
|
+
Targets: options.urls,
|
|
138
|
+
};
|
|
139
|
+
return await this.request("CreatePrefetchTask", "2022-09-01", params);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 查询预热任务
|
|
143
|
+
*/
|
|
144
|
+
async describePrefetchTasks(zoneIds) {
|
|
145
|
+
const now = new Date();
|
|
146
|
+
const oneMonthAgo = new Date(now.getTime() - 30 * 24 * 60 * 60 * 1000);
|
|
147
|
+
// 格式化为 ISO 8601 格式,时区为 +08:00
|
|
148
|
+
const toISOStringWithTimezone = (date) => {
|
|
149
|
+
const year = date.getFullYear();
|
|
150
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
151
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
152
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
153
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
154
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
155
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}+08:00`;
|
|
156
|
+
};
|
|
157
|
+
const baseParams = {
|
|
158
|
+
StartTime: toISOStringWithTimezone(oneMonthAgo),
|
|
159
|
+
EndTime: toISOStringWithTimezone(now),
|
|
160
|
+
};
|
|
161
|
+
// 如果没有指定 zoneIds,直接查询
|
|
162
|
+
if (!zoneIds || zoneIds.length === 0) {
|
|
163
|
+
return await this.request("DescribePrefetchTasks", "2022-09-01", baseParams);
|
|
164
|
+
}
|
|
165
|
+
// 如果只有一个 zone,直接查询
|
|
166
|
+
if (zoneIds.length === 1) {
|
|
167
|
+
baseParams.ZoneId = zoneIds[0];
|
|
168
|
+
return await this.request("DescribePrefetchTasks", "2022-09-01", baseParams);
|
|
169
|
+
}
|
|
170
|
+
// 多个 zone,并发查询并合并结果
|
|
171
|
+
const requests = zoneIds.map(zoneId => {
|
|
172
|
+
const params = { ...baseParams, ZoneId: zoneId };
|
|
173
|
+
return this.request("DescribePrefetchTasks", "2022-09-01", params);
|
|
174
|
+
});
|
|
175
|
+
const results = await Promise.all(requests);
|
|
176
|
+
// 合并结果
|
|
177
|
+
const merged = { Response: {} };
|
|
178
|
+
const allTasks = [];
|
|
179
|
+
for (const result of results) {
|
|
180
|
+
if (result.Response?.Error) {
|
|
181
|
+
// 如果任何一个请求失败,返回第一个错误
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
if (result.Response?.PrefetchTasks) {
|
|
185
|
+
allTasks.push(...result.Response.PrefetchTasks);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// 合并成功响应
|
|
189
|
+
merged.Response = {
|
|
190
|
+
...results[0].Response,
|
|
191
|
+
PrefetchTasks: allTasks,
|
|
192
|
+
};
|
|
193
|
+
return merged;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAyB3D,MAAM,OAAO,aAAa;IAChB,QAAQ,CAAS;IACjB,SAAS,CAAS;IAClB,QAAQ,CAAS;IACjB,MAAM,CAAS;IACf,IAAI,CAAa;IAEzB,YAAY,QAAgB,EAAE,SAAiB,EAAE,QAAgB,EAAE,MAAM,GAAG,cAAc,EAAE,OAAmB,YAAY;QACzH,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,OAAe,EAAE,MAA2B;QAChF,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QAE3D,eAAe;QACf,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAE3C,OAAO;QACP,MAAM,aAAa,GAAG,kBAAkB,CAAC;YACvC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EAA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,CAAC,MAAM,CAAC,EAAE;YACpC,MAAM,MAAM,GAAG,EAAE,GAAG,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;YACjD,OAAO,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAE5C,OAAO;QACP,MAAM,MAAM,GAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAU,EAAE,CAAC;QAE3B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;gBAC3B,qBAAqB;gBACrB,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,IAAI,MAAM,CAAC,QAAQ,EAAE,aAAa,EAAE,CAAC;gBACnC,QAAQ,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAED,SAAS;QACT,MAAM,CAAC,QAAQ,GAAG;YAChB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ;YACtB,aAAa,EAAE,QAAQ;SACxB,CAAC;QAEF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
interface SignOptions {
|
|
2
|
+
method: string;
|
|
3
|
+
host: string;
|
|
4
|
+
path: string;
|
|
5
|
+
queryParams?: Record<string, any>;
|
|
6
|
+
bodyParams?: Record<string, any>;
|
|
7
|
+
headers?: Record<string, string>;
|
|
8
|
+
secretId: string;
|
|
9
|
+
secretKey: string;
|
|
10
|
+
service: string;
|
|
11
|
+
region?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class Signer {
|
|
14
|
+
/**
|
|
15
|
+
* 计算 HMAC-SHA256
|
|
16
|
+
*/
|
|
17
|
+
private static hmacSha256;
|
|
18
|
+
/**
|
|
19
|
+
* 计算 SHA256
|
|
20
|
+
*/
|
|
21
|
+
private static sha256;
|
|
22
|
+
/**
|
|
23
|
+
* 计算 SHA256 hex
|
|
24
|
+
*/
|
|
25
|
+
private static sha256Hex;
|
|
26
|
+
/**
|
|
27
|
+
* 获取日期
|
|
28
|
+
*/
|
|
29
|
+
private static getDate;
|
|
30
|
+
/**
|
|
31
|
+
* 构建 Query String
|
|
32
|
+
*/
|
|
33
|
+
private static buildQueryString;
|
|
34
|
+
/**
|
|
35
|
+
* URI 编码(RFC3986)
|
|
36
|
+
*/
|
|
37
|
+
private static _encodeURIComponent;
|
|
38
|
+
/**
|
|
39
|
+
* 签名
|
|
40
|
+
*/
|
|
41
|
+
static sign(options: SignOptions): {
|
|
42
|
+
headers: Record<string, string>;
|
|
43
|
+
body: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../../src/api/signer.ts"],"names":[],"mappings":"AAKA,UAAU,WAAW;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,MAAM;IACjB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,MAAM;IAIrB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,SAAS;IAIxB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,OAAO;IAKtB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAe/B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAIlC;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;CA6DrF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 腾讯云 API 签名工具 (TC3-HMAC-SHA256)
|
|
3
|
+
*/
|
|
4
|
+
import crypto from 'crypto';
|
|
5
|
+
export class Signer {
|
|
6
|
+
/**
|
|
7
|
+
* 计算 HMAC-SHA256
|
|
8
|
+
*/
|
|
9
|
+
static hmacSha256(key, message) {
|
|
10
|
+
return crypto.createHmac('sha256', key).update(message).digest();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 计算 SHA256
|
|
14
|
+
*/
|
|
15
|
+
static sha256(message) {
|
|
16
|
+
return crypto.createHash('sha256').update(message).digest();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 计算 SHA256 hex
|
|
20
|
+
*/
|
|
21
|
+
static sha256Hex(message) {
|
|
22
|
+
return crypto.createHash('sha256').update(message).digest('hex');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 获取日期
|
|
26
|
+
*/
|
|
27
|
+
static getDate(timestamp) {
|
|
28
|
+
const date = new Date(timestamp * 1000);
|
|
29
|
+
return date.toISOString().substr(0, 10);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 构建 Query String
|
|
33
|
+
*/
|
|
34
|
+
static buildQueryString(params) {
|
|
35
|
+
const sortedKeys = Object.keys(params).sort();
|
|
36
|
+
return sortedKeys
|
|
37
|
+
.map((key) => {
|
|
38
|
+
const value = params[key];
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
return value
|
|
41
|
+
.map((v) => `${this._encodeURIComponent(key)}=${this._encodeURIComponent(String(v))}`)
|
|
42
|
+
.join('&');
|
|
43
|
+
}
|
|
44
|
+
return `${this._encodeURIComponent(key)}=${this._encodeURIComponent(String(value))}`;
|
|
45
|
+
})
|
|
46
|
+
.join('&');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* URI 编码(RFC3986)
|
|
50
|
+
*/
|
|
51
|
+
static _encodeURIComponent(str) {
|
|
52
|
+
return encodeURIComponent(str).replace(/[!*'()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 签名
|
|
56
|
+
*/
|
|
57
|
+
static sign(options) {
|
|
58
|
+
const { method, host, path, queryParams = {}, bodyParams = {}, secretId, secretKey, service, region = 'ap-guangzhou', } = options;
|
|
59
|
+
// 1. 拼接规范查询字符串
|
|
60
|
+
const queryString = this.buildQueryString(queryParams);
|
|
61
|
+
// 2. 拼接请求体
|
|
62
|
+
const body = bodyParams ? JSON.stringify(bodyParams) : '';
|
|
63
|
+
const contentType = 'application/json';
|
|
64
|
+
// 3. 计算时间戳
|
|
65
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
66
|
+
const date = this.getDate(timestamp);
|
|
67
|
+
// 4. 拼接 CanonicalRequest
|
|
68
|
+
const httpRequestMethod = method;
|
|
69
|
+
const canonicalUri = path;
|
|
70
|
+
const canonicalQueryString = queryString;
|
|
71
|
+
const canonicalHeaders = `content-type:${contentType}\nhost:${host}\n`;
|
|
72
|
+
const signedHeaders = 'content-type;host';
|
|
73
|
+
const hashedRequestPayload = this.sha256Hex(body);
|
|
74
|
+
const canonicalRequest = `${httpRequestMethod}\n${canonicalUri}\n${canonicalQueryString}\n${canonicalHeaders}\n${signedHeaders}\n${hashedRequestPayload}`;
|
|
75
|
+
// 5. 拼接 StringToSign
|
|
76
|
+
const algorithm = 'TC3-HMAC-SHA256';
|
|
77
|
+
const credentialScope = `${date}/${service}/request`;
|
|
78
|
+
const hashedCanonicalRequest = this.sha256Hex(canonicalRequest);
|
|
79
|
+
const stringToSign = `${algorithm}\n${timestamp}\n${credentialScope}\n${hashedCanonicalRequest}`;
|
|
80
|
+
// 6. 计算签名
|
|
81
|
+
const secretDate = this.hmacSha256(Buffer.from(`TC3${secretKey}`, 'utf-8'), date);
|
|
82
|
+
const secretService = this.hmacSha256(secretDate, service);
|
|
83
|
+
const secretSigning = this.hmacSha256(secretService, 'request');
|
|
84
|
+
const signature = this.hmacSha256(secretSigning, stringToSign).toString('hex');
|
|
85
|
+
// 7. 拼接 Authorization
|
|
86
|
+
const authorization = `${algorithm} Credential=${secretId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
|
|
87
|
+
// 8. 构造请求头
|
|
88
|
+
const headers = {
|
|
89
|
+
Authorization: authorization,
|
|
90
|
+
'Content-Type': contentType,
|
|
91
|
+
Host: host,
|
|
92
|
+
'X-TC-Action': bodyParams.Action || '',
|
|
93
|
+
'X-TC-Timestamp': timestamp.toString(),
|
|
94
|
+
'X-TC-Version': bodyParams.Version || '',
|
|
95
|
+
'X-TC-Region': region,
|
|
96
|
+
};
|
|
97
|
+
return { headers, body };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/api/signer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAe5B,MAAM,OAAO,MAAM;IACjB;;OAEG;IACK,MAAM,CAAC,UAAU,CAAC,GAAW,EAAE,OAAe;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C,MAAM,IAAI,EAAE;YACtC,gBAAgB,EAAE,SAAS,CAAC,QAAQ,EAAE;YACtC,cAAc,EAAE,UAAU,CAAC,OAAO,IAAI,EAAE;YACxC,aAAa,EAAE,MAAM;SACtB,CAAC;QAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
type ConfigMode = 'debug' | 'production';
|
|
3
|
+
interface Config {
|
|
4
|
+
secretId: string;
|
|
5
|
+
secretKey: string;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
mode: ConfigMode;
|
|
8
|
+
domainIdList: string[];
|
|
9
|
+
}
|
|
10
|
+
declare const CONFIG_FILE: string;
|
|
11
|
+
/**
|
|
12
|
+
* 读取配置(自动解密,自动迁移旧格式)
|
|
13
|
+
*/
|
|
14
|
+
declare function readConfig(): Config | null;
|
|
15
|
+
declare const configCmd: Command;
|
|
16
|
+
export default configCmd;
|
|
17
|
+
export { readConfig, CONFIG_FILE };
|
|
18
|
+
export type { ConfigMode };
|
|
19
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/commands/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,KAAK,UAAU,GAAG,OAAO,GAAG,YAAY,CAAC;AAWzC,UAAU,MAAM;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAGD,QAAA,MAAM,WAAW,QAAuC,CAAC;AAWzD;;GAEG;AACH,iBAAS,UAAU,IAAI,MAAM,GAAG,IAAI,CAoCnC;AA0DD,QAAA,MAAM,SAAS,SACgB,CAAC;AAyKhC,eAAe,SAAS,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;AACnC,YAAY,EAAE,UAAU,EAAE,CAAC"}
|