@archlast/cli 0.0.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.
- package/README.md +141 -0
- package/dist/analyzer.d.ts +96 -0
- package/dist/analyzer.d.ts.map +1 -0
- package/dist/analyzer.js +404 -0
- package/dist/auth.d.ts +14 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +106 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +322875 -0
- package/dist/commands/build.d.ts +6 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +36 -0
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +23 -0
- package/dist/commands/data.d.ts +6 -0
- package/dist/commands/data.d.ts.map +1 -0
- package/dist/commands/data.js +300 -0
- package/dist/commands/deploy.d.ts +9 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +59 -0
- package/dist/commands/dev.d.ts +10 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +132 -0
- package/dist/commands/generate.d.ts +6 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +100 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/logs.d.ts +10 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +38 -0
- package/dist/commands/pull.d.ts +16 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +415 -0
- package/dist/commands/restart.d.ts +11 -0
- package/dist/commands/restart.d.ts.map +1 -0
- package/dist/commands/restart.js +63 -0
- package/dist/commands/start.d.ts +11 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +74 -0
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +69 -0
- package/dist/commands/stop.d.ts +8 -0
- package/dist/commands/stop.d.ts.map +1 -0
- package/dist/commands/stop.js +23 -0
- package/dist/commands/upgrade.d.ts +12 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +77 -0
- package/dist/docker/compose.d.ts +3 -0
- package/dist/docker/compose.d.ts.map +1 -0
- package/dist/docker/compose.js +47 -0
- package/dist/docker/config.d.ts +12 -0
- package/dist/docker/config.d.ts.map +1 -0
- package/dist/docker/config.js +183 -0
- package/dist/docker/manager.d.ts +19 -0
- package/dist/docker/manager.d.ts.map +1 -0
- package/dist/docker/manager.js +239 -0
- package/dist/docker/ports.d.ts +6 -0
- package/dist/docker/ports.d.ts.map +1 -0
- package/dist/docker/restart-on-deploy.d.ts +6 -0
- package/dist/docker/restart-on-deploy.d.ts.map +1 -0
- package/dist/docker/types.d.ts +36 -0
- package/dist/docker/types.d.ts.map +1 -0
- package/dist/docker/types.js +1 -0
- package/dist/events-listener.d.ts +19 -0
- package/dist/events-listener.d.ts.map +1 -0
- package/dist/events-listener.js +105 -0
- package/dist/generator.d.ts +44 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +1816 -0
- package/dist/generators/di.d.ts +21 -0
- package/dist/generators/di.d.ts.map +1 -0
- package/dist/generators/di.js +100 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/project.d.ts +18 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/protocol.d.ts +58 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +5 -0
- package/dist/uploader.d.ts +63 -0
- package/dist/uploader.d.ts.map +1 -0
- package/dist/uploader.js +255 -0
- package/dist/watcher.d.ts +13 -0
- package/dist/watcher.d.ts.map +1 -0
- package/dist/watcher.js +38 -0
- package/package.json +58 -0
- package/scripts/postinstall.cjs +65 -0
package/dist/auth.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
const BETTER_AUTH_API_KEY_PREFIX = "arch_";
|
|
4
|
+
const BETTER_AUTH_API_KEY_PATTERN = /^arch_[a-zA-Z0-9]{32,}$/;
|
|
5
|
+
export function validateApiKey(apiKey) {
|
|
6
|
+
if (!apiKey) {
|
|
7
|
+
return { valid: false, error: "API key is required" };
|
|
8
|
+
}
|
|
9
|
+
if (!apiKey.startsWith(BETTER_AUTH_API_KEY_PREFIX)) {
|
|
10
|
+
return { valid: false, error: 'API key must start with "arch_" prefix' };
|
|
11
|
+
}
|
|
12
|
+
if (!BETTER_AUTH_API_KEY_PATTERN.test(apiKey)) {
|
|
13
|
+
return { valid: false, error: "Invalid API key format" };
|
|
14
|
+
}
|
|
15
|
+
return { valid: true };
|
|
16
|
+
}
|
|
17
|
+
export class AdminTokenNotFoundError extends Error {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(`API key not found. Please set ARCHLAST_API_KEY in your environment or .env.local file.
|
|
20
|
+
|
|
21
|
+
API keys can be created via the admin dashboard at /_archlast/admin/api-keys
|
|
22
|
+
Set the ARCHLAST_API_KEY environment variable with your API key.`);
|
|
23
|
+
this.name = "AdminTokenNotFoundError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function isBetterAuthApiKey(token) {
|
|
27
|
+
return token.startsWith(BETTER_AUTH_API_KEY_PREFIX);
|
|
28
|
+
}
|
|
29
|
+
export function extractFromEnv(content, varName) {
|
|
30
|
+
const lines = content.split("\n");
|
|
31
|
+
for (const line of lines) {
|
|
32
|
+
const trimmed = line.trim();
|
|
33
|
+
if (trimmed.startsWith(`${varName}=`)) {
|
|
34
|
+
const match = trimmed.match(new RegExp(`^${varName}=(?:"([^"]*)"|'([^']*)'|(.+))$`));
|
|
35
|
+
if (match) {
|
|
36
|
+
return match[1] || match[2] || match[3] || null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
export function readAdminToken(archlastPath) {
|
|
43
|
+
const apiKey = process.env.ARCHLAST_API_KEY;
|
|
44
|
+
const validation = validateApiKey(apiKey || "");
|
|
45
|
+
if (!validation.valid) {
|
|
46
|
+
throw new Error(validation.error || "Invalid API key");
|
|
47
|
+
}
|
|
48
|
+
if (apiKey) {
|
|
49
|
+
return apiKey;
|
|
50
|
+
}
|
|
51
|
+
const searchPaths = [];
|
|
52
|
+
if (archlastPath) {
|
|
53
|
+
searchPaths.push(path.resolve(archlastPath, ".env.local"));
|
|
54
|
+
searchPaths.push(path.resolve(archlastPath, ".env"));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
searchPaths.push(path.resolve(process.cwd(), ".env.local"));
|
|
58
|
+
searchPaths.push(path.resolve(process.cwd(), ".env"));
|
|
59
|
+
let currentDir = process.cwd();
|
|
60
|
+
for (let i = 0; i < 5; i++) {
|
|
61
|
+
const repoArchlast = path.join(currentDir, "apps", "archlast", ".env.local");
|
|
62
|
+
if (fs.existsSync(repoArchlast)) {
|
|
63
|
+
searchPaths.push(repoArchlast);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
const parent = path.dirname(currentDir);
|
|
67
|
+
if (parent === currentDir)
|
|
68
|
+
break;
|
|
69
|
+
currentDir = parent;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const filePath of searchPaths) {
|
|
73
|
+
if (fs.existsSync(filePath)) {
|
|
74
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
75
|
+
const key = extractFromEnv(content, "ARCHLAST_API_KEY");
|
|
76
|
+
if (key) {
|
|
77
|
+
return key;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw new AdminTokenNotFoundError();
|
|
82
|
+
}
|
|
83
|
+
export function getAuthHeaders(archlastPath) {
|
|
84
|
+
const apiKey = readAdminToken(archlastPath);
|
|
85
|
+
return {
|
|
86
|
+
"x-api-key": apiKey,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export function hashString(str) {
|
|
90
|
+
let hash = 0;
|
|
91
|
+
for (let i = 0; i < str.length; i++) {
|
|
92
|
+
const char = str.charCodeAt(i);
|
|
93
|
+
hash = (hash << 5) - hash + char;
|
|
94
|
+
hash = hash & hash;
|
|
95
|
+
}
|
|
96
|
+
return Math.abs(hash).toString(36);
|
|
97
|
+
}
|
|
98
|
+
export function hashFile(filePath) {
|
|
99
|
+
try {
|
|
100
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
101
|
+
return hashString(content.trim());
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|