@vectorx/cloud-toolkit 0.0.0-beta-20251112071234
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 +1 -0
- package/lib/agent.kit.js +275 -0
- package/lib/config/api.config.js +12 -0
- package/lib/config/index.js +17 -0
- package/lib/container/container.js +11 -0
- package/lib/container/identifiers.js +7 -0
- package/lib/container/index.js +31 -0
- package/lib/container/types.js +2 -0
- package/lib/index.js +30 -0
- package/lib/services/auth-service.js +148 -0
- package/lib/services/index.js +18 -0
- package/lib/services/upload-service.js +192 -0
- package/lib/utils/config-merger.js +54 -0
- package/lib/utils/cos-uploader.js +104 -0
- package/lib/utils/env-helper.js +4 -0
- package/lib/utils/helper.js +66 -0
- package/lib/utils/loading.js +68 -0
- package/lib/utils/logger.js +89 -0
- package/lib/utils/open-browser.js +24 -0
- package/lib/utils/openChrome.applescript +78 -0
- package/lib/utils/output.js +37 -0
- package/lib/utils/port-finder.js +55 -0
- package/lib/utils/project-validator.js +124 -0
- package/lib/utils/request.js +77 -0
- package/lib/utils/to-hump.js +5 -0
- package/lib/utils/tracker/device.js +85 -0
- package/lib/utils/tracker/index.js +134 -0
- package/lib/utils/tracker/tracker.js +2 -0
- package/package.json +55 -0
- package/types/agent.kit.d.ts +70 -0
- package/types/config/api.config.d.ts +2 -0
- package/types/config/index.d.ts +1 -0
- package/types/container/container.d.ts +3 -0
- package/types/container/identifiers.d.ts +6 -0
- package/types/container/index.d.ts +9 -0
- package/types/container/types.d.ts +19 -0
- package/types/index.d.ts +13 -0
- package/types/services/auth-service.d.ts +22 -0
- package/types/services/index.d.ts +2 -0
- package/types/services/upload-service.d.ts +95 -0
- package/types/utils/config-merger.d.ts +1 -0
- package/types/utils/cos-uploader.d.ts +41 -0
- package/types/utils/env-helper.d.ts +1 -0
- package/types/utils/helper.d.ts +6 -0
- package/types/utils/loading.d.ts +18 -0
- package/types/utils/logger.d.ts +24 -0
- package/types/utils/open-browser.d.ts +2 -0
- package/types/utils/output.d.ts +1 -0
- package/types/utils/port-finder.d.ts +2 -0
- package/types/utils/project-validator.d.ts +10 -0
- package/types/utils/request.d.ts +25 -0
- package/types/utils/to-hump.d.ts +1 -0
- package/types/utils/tracker/device.d.ts +4 -0
- package/types/utils/tracker/index.d.ts +27 -0
- package/types/utils/tracker/tracker.d.ts +22 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
### 云开发工具集合
|
package/lib/agent.kit.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.startRcbFramework = startRcbFramework;
|
|
16
|
+
exports.startDev = startDev;
|
|
17
|
+
exports.build = build;
|
|
18
|
+
exports.createNew = createNew;
|
|
19
|
+
exports.cleanup = cleanup;
|
|
20
|
+
const child_process_1 = require("child_process");
|
|
21
|
+
const fs_1 = __importDefault(require("fs"));
|
|
22
|
+
const path_1 = __importDefault(require("path"));
|
|
23
|
+
const agent_simulator_1 = require("@vectorx/agent-simulator");
|
|
24
|
+
const archiver_1 = __importDefault(require("archiver"));
|
|
25
|
+
const semver_1 = __importDefault(require("semver"));
|
|
26
|
+
const container_1 = require("./container");
|
|
27
|
+
const env_helper_1 = require("./utils/env-helper");
|
|
28
|
+
const port_finder_1 = require("./utils/port-finder");
|
|
29
|
+
const project_validator_1 = require("./utils/project-validator");
|
|
30
|
+
let rcbProcess = null;
|
|
31
|
+
function validatePort(port, name = "端口") {
|
|
32
|
+
if (isNaN(port) || port < 1 || port > 65535) {
|
|
33
|
+
throw new Error(`无效的${name}号: ${port},${name}号必须在 1-65535 之间`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function startRcbFramework(workDir_1, port_1, watch_1) {
|
|
37
|
+
return __awaiter(this, arguments, void 0, function* (workDir, port, watch, nodePath = "node", options) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const args = [
|
|
40
|
+
...(watch ? ["--watch"] : []),
|
|
41
|
+
"--directory",
|
|
42
|
+
workDir,
|
|
43
|
+
"--port",
|
|
44
|
+
port.toString(),
|
|
45
|
+
"--enable-cors",
|
|
46
|
+
"--allowed-origins",
|
|
47
|
+
"localhost,127.0.0.1",
|
|
48
|
+
"--config",
|
|
49
|
+
"agent-cloudbase-functions.json",
|
|
50
|
+
...((options === null || options === void 0 ? void 0 : options.enableRedLangfuse) ? ["--enableRedLangfuse"] : []),
|
|
51
|
+
];
|
|
52
|
+
try {
|
|
53
|
+
const packagePath = require.resolve("@vectorx/functions-framework/package.json");
|
|
54
|
+
const packageDir = path_1.default.dirname(packagePath);
|
|
55
|
+
const rcbFfPath = path_1.default.join(packageDir, "bin/rcb-ff.js");
|
|
56
|
+
console.log("开始启动 rcb-ff 服务...");
|
|
57
|
+
if (env_helper_1.isIDE)
|
|
58
|
+
nodePath = nodePath || "node";
|
|
59
|
+
rcbProcess = (0, child_process_1.spawn)(nodePath, [rcbFfPath, ...args], {
|
|
60
|
+
stdio: ["pipe", "pipe", "pipe", "ipc"],
|
|
61
|
+
cwd: workDir,
|
|
62
|
+
});
|
|
63
|
+
rcbProcess.stdout.on("data", (data) => {
|
|
64
|
+
const output = data.toString();
|
|
65
|
+
console.log(output.trim());
|
|
66
|
+
});
|
|
67
|
+
rcbProcess.stderr.on("data", (data) => {
|
|
68
|
+
const error = data.toString();
|
|
69
|
+
console.error(error.trim());
|
|
70
|
+
});
|
|
71
|
+
rcbProcess.on("message", (message) => {
|
|
72
|
+
if ((message.type === "message" && message.data.type === "start-up") ||
|
|
73
|
+
(message.type === "start-up" && message.status === "success")) {
|
|
74
|
+
console.log("启动 rcb-ff 服务完成");
|
|
75
|
+
resolve(rcbProcess);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
rcbProcess.on("error", (error) => {
|
|
79
|
+
console.error(`启动 rcb-ff 失败: ${error}`);
|
|
80
|
+
reject(error);
|
|
81
|
+
});
|
|
82
|
+
rcbProcess.on("unhandledRejection", (error) => {
|
|
83
|
+
console.error(`unhandledRejection 错误: ${error}`);
|
|
84
|
+
});
|
|
85
|
+
rcbProcess.on("exit", (code) => {
|
|
86
|
+
if (code !== 0) {
|
|
87
|
+
reject(new Error(`rcb-ff 进程退出,退出码: ${code}`));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
reject(new Error(`找不到 @vectorx/functions-framework 包: ${error}`));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function startDev(options) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const { workDir = process.cwd(), port: specifiedPort, simulatorPort: specifiedSimulatorPort, watch = false, enableRedLangfuse = false, } = options;
|
|
100
|
+
if (!fs_1.default.existsSync(workDir)) {
|
|
101
|
+
throw new Error(`目录不存在: ${workDir}`);
|
|
102
|
+
}
|
|
103
|
+
let port;
|
|
104
|
+
if (specifiedPort) {
|
|
105
|
+
validatePort(specifiedPort, "Agent Server 端口");
|
|
106
|
+
const isAvailable = yield (0, port_finder_1.isPortAvailable)(specifiedPort);
|
|
107
|
+
if (!isAvailable) {
|
|
108
|
+
throw new Error(`端口 ${specifiedPort} 已被占用,请选择其他端口或不指定端口以自动分配`);
|
|
109
|
+
}
|
|
110
|
+
port = specifiedPort;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
port = yield (0, port_finder_1.findAvailablePort)(3000);
|
|
114
|
+
}
|
|
115
|
+
let simulatorPort;
|
|
116
|
+
if (specifiedSimulatorPort) {
|
|
117
|
+
validatePort(specifiedSimulatorPort, "模拟器端口");
|
|
118
|
+
if (specifiedSimulatorPort === port) {
|
|
119
|
+
throw new Error(`模拟器端口 ${specifiedSimulatorPort} 与 Agent Server 端口冲突,请选择不同的端口`);
|
|
120
|
+
}
|
|
121
|
+
const isAvailable = yield (0, port_finder_1.isPortAvailable)(specifiedSimulatorPort);
|
|
122
|
+
if (!isAvailable) {
|
|
123
|
+
throw new Error(`模拟器端口 ${specifiedSimulatorPort} 已被占用,请选择其他端口或不指定端口以自动分配`);
|
|
124
|
+
}
|
|
125
|
+
simulatorPort = specifiedSimulatorPort;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
simulatorPort = yield (0, port_finder_1.findAvailablePort)(port + 1);
|
|
129
|
+
}
|
|
130
|
+
yield startRcbFramework(workDir, port, watch, undefined, { enableRedLangfuse });
|
|
131
|
+
const simulator = new agent_simulator_1.AgentSimulator({
|
|
132
|
+
port: simulatorPort,
|
|
133
|
+
agentServerUrl: `http://localhost:${port}/v1/aiagent/agents/demo-agent`,
|
|
134
|
+
open: false,
|
|
135
|
+
});
|
|
136
|
+
yield simulator.start();
|
|
137
|
+
return {
|
|
138
|
+
port,
|
|
139
|
+
simulatorPort,
|
|
140
|
+
simulator,
|
|
141
|
+
rcbProcess,
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function build(options) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const { workDir = process.cwd(), outputDir = path_1.default.join(workDir, "dist"), filename = "agent.zip", upload = false, uploadInfo, } = options;
|
|
148
|
+
if (!fs_1.default.existsSync(workDir)) {
|
|
149
|
+
throw new Error(`目录不存在: ${workDir}`);
|
|
150
|
+
}
|
|
151
|
+
const validator = new project_validator_1.ProjectValidator(workDir, uploadInfo);
|
|
152
|
+
if (validator) {
|
|
153
|
+
const validationResult = yield validator.validate();
|
|
154
|
+
if (!validationResult.valid) {
|
|
155
|
+
throw new Error(`项目验证失败:\n${validationResult.errors.join("\n")}`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (!fs_1.default.existsSync(outputDir)) {
|
|
159
|
+
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
160
|
+
}
|
|
161
|
+
const zipFilename = filename.endsWith(".zip") ? filename : `${filename}.zip`;
|
|
162
|
+
const outputPath = path_1.default.join(outputDir, zipFilename);
|
|
163
|
+
yield new Promise((resolve, reject) => {
|
|
164
|
+
const output = fs_1.default.createWriteStream(outputPath);
|
|
165
|
+
const archive = (0, archiver_1.default)("zip", {
|
|
166
|
+
zlib: { level: 9 },
|
|
167
|
+
});
|
|
168
|
+
output.on("close", () => {
|
|
169
|
+
resolve();
|
|
170
|
+
});
|
|
171
|
+
archive.on("error", (err) => {
|
|
172
|
+
reject(err);
|
|
173
|
+
});
|
|
174
|
+
archive.pipe(output);
|
|
175
|
+
archive.directory(workDir, false, (data) => {
|
|
176
|
+
const excludePatterns = [/^\.git/, /^dist/, /\.zip$/, /\.DS_Store$/];
|
|
177
|
+
if (excludePatterns.some((pattern) => pattern.test(data.name))) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return data;
|
|
181
|
+
});
|
|
182
|
+
archive.finalize();
|
|
183
|
+
});
|
|
184
|
+
const size = fs_1.default.statSync(outputPath).size;
|
|
185
|
+
const uploadService = container_1.container.get(container_1.SERVICE_IDENTIFIERS.UploadService);
|
|
186
|
+
if (upload && uploadService) {
|
|
187
|
+
try {
|
|
188
|
+
const projectConfigPath = path_1.default.join(workDir, "project.config.json");
|
|
189
|
+
if (!fs_1.default.existsSync(projectConfigPath)) {
|
|
190
|
+
throw new Error("找不到项目配置文件: project.config.json");
|
|
191
|
+
}
|
|
192
|
+
const projectInfo = JSON.parse(fs_1.default.readFileSync(projectConfigPath, "utf-8"));
|
|
193
|
+
if (!projectInfo.agentId) {
|
|
194
|
+
throw new Error("项目配置文件缺少必要字段 (agentId)");
|
|
195
|
+
}
|
|
196
|
+
let version, desc;
|
|
197
|
+
if (!env_helper_1.isIDE) {
|
|
198
|
+
if (!projectInfo.version || !projectInfo.desc) {
|
|
199
|
+
throw new Error("项目配置文件缺少必要字段 (agentId, version, desc)");
|
|
200
|
+
}
|
|
201
|
+
if (!semver_1.default.valid(projectInfo.version)) {
|
|
202
|
+
throw new Error("项目配置文件中 version 字段不符合 semver 规范");
|
|
203
|
+
}
|
|
204
|
+
version = projectInfo.version;
|
|
205
|
+
desc = projectInfo.desc;
|
|
206
|
+
}
|
|
207
|
+
else if (uploadInfo && env_helper_1.isIDE) {
|
|
208
|
+
version = uploadInfo.version;
|
|
209
|
+
desc = uploadInfo.desc;
|
|
210
|
+
}
|
|
211
|
+
const result = yield uploadService.deploy({
|
|
212
|
+
targetPath: outputPath,
|
|
213
|
+
agentId: projectInfo.agentId,
|
|
214
|
+
version,
|
|
215
|
+
desc,
|
|
216
|
+
});
|
|
217
|
+
if (!result.success || result.code !== 0) {
|
|
218
|
+
throw new Error(result.message || "部署失败");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
throw new Error(`部署失败: ${error.message}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
outputPath,
|
|
227
|
+
size,
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
function createNew(options) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
const { projectName, targetDir = process.cwd() } = options;
|
|
234
|
+
if (!projectName) {
|
|
235
|
+
throw new Error("项目名称不能为空");
|
|
236
|
+
}
|
|
237
|
+
const projectDir = path_1.default.join(targetDir, projectName);
|
|
238
|
+
if (fs_1.default.existsSync(projectDir)) {
|
|
239
|
+
throw new Error(`项目目录已存在: ${projectDir}`);
|
|
240
|
+
}
|
|
241
|
+
const templateDir = path_1.default.join(__dirname, "../templates/chatbox-agent");
|
|
242
|
+
if (!fs_1.default.existsSync(templateDir)) {
|
|
243
|
+
throw new Error(`模板目录不存在: ${templateDir}`);
|
|
244
|
+
}
|
|
245
|
+
yield copyTemplate(templateDir, projectDir);
|
|
246
|
+
return {
|
|
247
|
+
projectDir,
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function copyTemplate(sourceDir, targetDir) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
if (!fs_1.default.existsSync(targetDir)) {
|
|
254
|
+
fs_1.default.mkdirSync(targetDir, { recursive: true });
|
|
255
|
+
}
|
|
256
|
+
const files = fs_1.default.readdirSync(sourceDir);
|
|
257
|
+
for (const file of files) {
|
|
258
|
+
const sourcePath = path_1.default.join(sourceDir, file);
|
|
259
|
+
const targetPath = path_1.default.join(targetDir, file);
|
|
260
|
+
const stat = fs_1.default.statSync(sourcePath);
|
|
261
|
+
if (stat.isDirectory()) {
|
|
262
|
+
yield copyTemplate(sourcePath, targetPath);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
fs_1.default.copyFileSync(sourcePath, targetPath);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
function cleanup() {
|
|
271
|
+
if (rcbProcess) {
|
|
272
|
+
rcbProcess.kill("SIGTERM");
|
|
273
|
+
rcbProcess = null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBaseUrl = getBaseUrl;
|
|
4
|
+
const apiUrls = {
|
|
5
|
+
development: "https://miniapp.beta.xiaohongshu.com",
|
|
6
|
+
production: "https://miniapp.xiaohongshu.com",
|
|
7
|
+
};
|
|
8
|
+
const env = process.env.AGENT_BUILD_ENV || "production";
|
|
9
|
+
const baseUrl = apiUrls[env] || apiUrls.development;
|
|
10
|
+
function getBaseUrl() {
|
|
11
|
+
return baseUrl;
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api.config"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.container = void 0;
|
|
4
|
+
const inversify_1 = require("inversify");
|
|
5
|
+
const auth_service_1 = require("../services/auth-service");
|
|
6
|
+
const upload_service_1 = require("../services/upload-service");
|
|
7
|
+
const identifiers_1 = require("./identifiers");
|
|
8
|
+
const container = new inversify_1.Container();
|
|
9
|
+
exports.container = container;
|
|
10
|
+
container.bind(identifiers_1.SERVICE_IDENTIFIERS.AuthService).to(auth_service_1.AuthService).inSingletonScope();
|
|
11
|
+
container.bind(identifiers_1.SERVICE_IDENTIFIERS.UploadService).to(upload_service_1.UploadService).inSingletonScope();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.SERVICE_IDENTIFIERS = exports.container = exports.ServiceProvider = void 0;
|
|
18
|
+
const container_1 = require("./container");
|
|
19
|
+
Object.defineProperty(exports, "container", { enumerable: true, get: function () { return container_1.container; } });
|
|
20
|
+
const identifiers_1 = require("./identifiers");
|
|
21
|
+
Object.defineProperty(exports, "SERVICE_IDENTIFIERS", { enumerable: true, get: function () { return identifiers_1.SERVICE_IDENTIFIERS; } });
|
|
22
|
+
class ServiceProvider {
|
|
23
|
+
static getAuthService() {
|
|
24
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.AuthService);
|
|
25
|
+
}
|
|
26
|
+
static getUploadService() {
|
|
27
|
+
return container_1.container.get(identifiers_1.SERVICE_IDENTIFIERS.UploadService);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ServiceProvider = ServiceProvider;
|
|
31
|
+
__exportStar(require("./types"), exports);
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Uploader = void 0;
|
|
18
|
+
__exportStar(require("./agent.kit"), exports);
|
|
19
|
+
var cos_uploader_1 = require("./utils/cos-uploader");
|
|
20
|
+
Object.defineProperty(exports, "Uploader", { enumerable: true, get: function () { return cos_uploader_1.Uploader; } });
|
|
21
|
+
__exportStar(require("./container"), exports);
|
|
22
|
+
__exportStar(require("./services"), exports);
|
|
23
|
+
__exportStar(require("./utils/config-merger"), exports);
|
|
24
|
+
__exportStar(require("./utils/env-helper"), exports);
|
|
25
|
+
__exportStar(require("./utils/helper"), exports);
|
|
26
|
+
__exportStar(require("./utils/logger"), exports);
|
|
27
|
+
__exportStar(require("./utils/tracker"), exports);
|
|
28
|
+
__exportStar(require("./utils/port-finder"), exports);
|
|
29
|
+
__exportStar(require("./utils/open-browser"), exports);
|
|
30
|
+
__exportStar(require("./utils/output"), exports);
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
45
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
46
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
47
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.AuthService = void 0;
|
|
55
|
+
const fs = __importStar(require("fs"));
|
|
56
|
+
const os = __importStar(require("os"));
|
|
57
|
+
const path = __importStar(require("path"));
|
|
58
|
+
const inversify_1 = require("inversify");
|
|
59
|
+
const config_1 = require("../config");
|
|
60
|
+
const helper_1 = require("../utils/helper");
|
|
61
|
+
const logger_1 = require("../utils/logger");
|
|
62
|
+
const request_1 = require("../utils/request");
|
|
63
|
+
let AuthService = class AuthService {
|
|
64
|
+
constructor() {
|
|
65
|
+
this.configDir = path.join(os.homedir(), ".rcb");
|
|
66
|
+
this.configFile = path.join(this.configDir, "config.json");
|
|
67
|
+
}
|
|
68
|
+
getToken(secretId, secretKey, nonce) {
|
|
69
|
+
const formattedTime = (0, helper_1.getFixedFormatTime)("YYYYMMDDHHmm");
|
|
70
|
+
const str = secretId + "#" + secretKey + "#" + nonce + "#" + formattedTime;
|
|
71
|
+
const token = (0, helper_1.getMd5)(str);
|
|
72
|
+
return token;
|
|
73
|
+
}
|
|
74
|
+
hasLogin() {
|
|
75
|
+
return fs.existsSync(this.configFile) && fs.statSync(this.configFile).isFile();
|
|
76
|
+
}
|
|
77
|
+
saveLoginInfo(loginInfo) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
try {
|
|
80
|
+
if (!fs.existsSync(this.configDir)) {
|
|
81
|
+
fs.mkdirSync(this.configDir, { recursive: true });
|
|
82
|
+
}
|
|
83
|
+
fs.writeFileSync(this.configFile, JSON.stringify(loginInfo, null, 2), "utf-8");
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
throw new Error("保存登录信息失败");
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
getLoginInfo() {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
try {
|
|
93
|
+
if (!fs.existsSync(this.configFile)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const content = fs.readFileSync(this.configFile, "utf-8");
|
|
97
|
+
const loginInfo = JSON.parse(content);
|
|
98
|
+
const expireTime = new Date(loginInfo.create_at + loginInfo.expire_in_sec * 1000);
|
|
99
|
+
if (expireTime < new Date()) {
|
|
100
|
+
this.clearLoginInfo();
|
|
101
|
+
logger_1.logger.error("登录信息已过期,请重新登录");
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return loginInfo;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
check(params) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
const response = yield request_1.request.fetch({
|
|
115
|
+
url: `${(0, config_1.getBaseUrl)()}/api/eros/mp/red/cloud/cli_auth`,
|
|
116
|
+
method: "POST",
|
|
117
|
+
data: {
|
|
118
|
+
body: params,
|
|
119
|
+
},
|
|
120
|
+
headers: {
|
|
121
|
+
"Content-Type": "application/json",
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
return response.data;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
throw new Error("检查登录信息失败");
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
clearLoginInfo() {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
try {
|
|
134
|
+
if (fs.existsSync(this.configFile)) {
|
|
135
|
+
fs.unlinkSync(this.configFile);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
throw new Error("清除登录信息失败");
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
exports.AuthService = AuthService;
|
|
145
|
+
exports.AuthService = AuthService = __decorate([
|
|
146
|
+
(0, inversify_1.injectable)(),
|
|
147
|
+
__metadata("design:paramtypes", [])
|
|
148
|
+
], AuthService);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./auth-service"), exports);
|
|
18
|
+
__exportStar(require("./upload-service"), exports);
|