@evident-ai/cli 0.1.6 → 0.2.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/dist/chunk-MWOWXSOP.js +120 -0
- package/dist/chunk-MWOWXSOP.js.map +1 -0
- package/dist/config-J7LPYFVS.js +30 -0
- package/dist/config-J7LPYFVS.js.map +1 -0
- package/dist/index.js +572 -147
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/config.ts
|
|
4
|
+
import Conf from "conf";
|
|
5
|
+
import { homedir } from "os";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
var environmentPresets = {
|
|
8
|
+
local: {
|
|
9
|
+
apiUrl: "http://localhost:3001/v1",
|
|
10
|
+
tunnelUrl: "ws://localhost:8787"
|
|
11
|
+
},
|
|
12
|
+
dev: {
|
|
13
|
+
apiUrl: "https://api.dev.evident.run/v1",
|
|
14
|
+
tunnelUrl: "wss://tunnel.dev.evident.run"
|
|
15
|
+
},
|
|
16
|
+
production: {
|
|
17
|
+
// Production URLs also have aliases: api.evident.run, tunnel.evident.run
|
|
18
|
+
apiUrl: "https://api.production.evident.run/v1",
|
|
19
|
+
tunnelUrl: "wss://tunnel.production.evident.run"
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var defaults = environmentPresets.production;
|
|
23
|
+
var currentEnvironment = "production";
|
|
24
|
+
function setEnvironment(env) {
|
|
25
|
+
currentEnvironment = env;
|
|
26
|
+
}
|
|
27
|
+
function getEnvironment() {
|
|
28
|
+
const envVar = process.env.EVIDENT_ENV;
|
|
29
|
+
if (envVar && environmentPresets[envVar]) {
|
|
30
|
+
return envVar;
|
|
31
|
+
}
|
|
32
|
+
return currentEnvironment;
|
|
33
|
+
}
|
|
34
|
+
function getEnvConfig() {
|
|
35
|
+
return environmentPresets[getEnvironment()];
|
|
36
|
+
}
|
|
37
|
+
function getApiUrl() {
|
|
38
|
+
return process.env.EVIDENT_API_URL ?? getEnvConfig().apiUrl;
|
|
39
|
+
}
|
|
40
|
+
function getTunnelUrl() {
|
|
41
|
+
return process.env.EVIDENT_TUNNEL_URL ?? getEnvConfig().tunnelUrl;
|
|
42
|
+
}
|
|
43
|
+
var config = new Conf({
|
|
44
|
+
projectName: "evident",
|
|
45
|
+
projectSuffix: "",
|
|
46
|
+
defaults
|
|
47
|
+
});
|
|
48
|
+
var credentials = new Conf({
|
|
49
|
+
projectName: "evident",
|
|
50
|
+
projectSuffix: "",
|
|
51
|
+
configName: "credentials",
|
|
52
|
+
defaults: {}
|
|
53
|
+
});
|
|
54
|
+
function getConfigDir() {
|
|
55
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
56
|
+
if (xdgConfig) {
|
|
57
|
+
return join(xdgConfig, "evident");
|
|
58
|
+
}
|
|
59
|
+
return join(homedir(), ".config", "evident");
|
|
60
|
+
}
|
|
61
|
+
function getApiUrlConfig() {
|
|
62
|
+
return getApiUrl();
|
|
63
|
+
}
|
|
64
|
+
function getTunnelUrlConfig() {
|
|
65
|
+
return getTunnelUrl();
|
|
66
|
+
}
|
|
67
|
+
function getCredentials() {
|
|
68
|
+
return {
|
|
69
|
+
token: credentials.get("token"),
|
|
70
|
+
user: credentials.get("user"),
|
|
71
|
+
expiresAt: credentials.get("expiresAt")
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function setCredentials(creds) {
|
|
75
|
+
if (creds.token) credentials.set("token", creds.token);
|
|
76
|
+
if (creds.user) credentials.set("user", creds.user);
|
|
77
|
+
if (creds.expiresAt) credentials.set("expiresAt", creds.expiresAt);
|
|
78
|
+
}
|
|
79
|
+
function clearCredentials() {
|
|
80
|
+
credentials.clear();
|
|
81
|
+
}
|
|
82
|
+
function hasValidCredentials() {
|
|
83
|
+
const creds = getCredentials();
|
|
84
|
+
if (!creds.token) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (creds.expiresAt) {
|
|
88
|
+
const expiresAt = new Date(creds.expiresAt);
|
|
89
|
+
if (expiresAt < /* @__PURE__ */ new Date()) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function getCliName() {
|
|
96
|
+
if (process.env.npm_execpath?.includes("npx")) {
|
|
97
|
+
return "npx @evident-ai/cli";
|
|
98
|
+
}
|
|
99
|
+
const argv1 = process.argv[1] || "";
|
|
100
|
+
if (argv1.includes("tsx") || argv1.includes("ts-node")) {
|
|
101
|
+
return "pnpm --filter @evident-ai/cli dev:run";
|
|
102
|
+
}
|
|
103
|
+
return "evident";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
setEnvironment,
|
|
108
|
+
getEnvironment,
|
|
109
|
+
config,
|
|
110
|
+
credentials,
|
|
111
|
+
getConfigDir,
|
|
112
|
+
getApiUrlConfig,
|
|
113
|
+
getTunnelUrlConfig,
|
|
114
|
+
getCredentials,
|
|
115
|
+
setCredentials,
|
|
116
|
+
clearCredentials,
|
|
117
|
+
hasValidCredentials,
|
|
118
|
+
getCliName
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=chunk-MWOWXSOP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/config.ts"],"sourcesContent":["/**\n * CLI Configuration\n *\n * Manages configuration values and file-based credential storage.\n * Supports multiple environments: local, dev, production\n */\n\nimport Conf from 'conf';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\n// Supported environments\nexport type Environment = 'local' | 'dev' | 'production';\n\n// Configuration schema\ninterface ConfigSchema {\n apiUrl: string;\n tunnelUrl: string;\n}\n\n// Credentials schema (stored separately with stricter permissions)\ninterface CredentialsSchema {\n token?: string;\n user?: {\n id: string;\n email: string;\n };\n expiresAt?: string;\n}\n\n// Environment presets\n// Domain format: {service}.{env}.evident.run (with aliases for production)\n// API URLs include /v1 prefix as all endpoints are versioned\nconst environmentPresets: Record<Environment, ConfigSchema> = {\n local: {\n apiUrl: 'http://localhost:3001/v1',\n tunnelUrl: 'ws://localhost:8787',\n },\n dev: {\n apiUrl: 'https://api.dev.evident.run/v1',\n tunnelUrl: 'wss://tunnel.dev.evident.run',\n },\n production: {\n // Production URLs also have aliases: api.evident.run, tunnel.evident.run\n apiUrl: 'https://api.production.evident.run/v1',\n tunnelUrl: 'wss://tunnel.production.evident.run',\n },\n};\n\n// Default to production\nconst defaults: ConfigSchema = environmentPresets.production;\n\n// Current environment (can be set via --env flag or EVIDENT_ENV)\nlet currentEnvironment: Environment = 'production';\n\n/**\n * Set the current environment\n */\nexport function setEnvironment(env: Environment): void {\n currentEnvironment = env;\n}\n\n/**\n * Get the current environment\n */\nexport function getEnvironment(): Environment {\n // Environment variable takes precedence\n const envVar = process.env.EVIDENT_ENV as Environment | undefined;\n if (envVar && environmentPresets[envVar]) {\n return envVar;\n }\n return currentEnvironment;\n}\n\n/**\n * Get configuration for current environment\n */\nfunction getEnvConfig(): ConfigSchema {\n return environmentPresets[getEnvironment()];\n}\n\n// Environment overrides (env vars take highest precedence)\nfunction getApiUrl(): string {\n return process.env.EVIDENT_API_URL ?? getEnvConfig().apiUrl;\n}\n\nfunction getTunnelUrl(): string {\n return process.env.EVIDENT_TUNNEL_URL ?? getEnvConfig().tunnelUrl;\n}\n\n// Configuration store\nconst config = new Conf<ConfigSchema>({\n projectName: 'evident',\n projectSuffix: '',\n defaults,\n});\n\n// Credentials store (separate file with restricted access)\nconst credentials = new Conf<CredentialsSchema>({\n projectName: 'evident',\n projectSuffix: '',\n configName: 'credentials',\n defaults: {},\n});\n\n/**\n * Get the configuration directory path\n */\nexport function getConfigDir(): string {\n // XDG_CONFIG_HOME on Linux, ~/.config on others\n const xdgConfig = process.env.XDG_CONFIG_HOME;\n if (xdgConfig) {\n return join(xdgConfig, 'evident');\n }\n return join(homedir(), '.config', 'evident');\n}\n\n/**\n * Get the API URL\n */\nexport function getApiUrlConfig(): string {\n return getApiUrl();\n}\n\n/**\n * Get the tunnel WebSocket URL\n */\nexport function getTunnelUrlConfig(): string {\n return getTunnelUrl();\n}\n\n/**\n * Get stored credentials\n */\nexport function getCredentials(): CredentialsSchema {\n return {\n token: credentials.get('token'),\n user: credentials.get('user'),\n expiresAt: credentials.get('expiresAt'),\n };\n}\n\n/**\n * Store credentials\n */\nexport function setCredentials(creds: CredentialsSchema): void {\n if (creds.token) credentials.set('token', creds.token);\n if (creds.user) credentials.set('user', creds.user);\n if (creds.expiresAt) credentials.set('expiresAt', creds.expiresAt);\n}\n\n/**\n * Clear stored credentials\n */\nexport function clearCredentials(): void {\n credentials.clear();\n}\n\n/**\n * Check if we have valid credentials\n */\nexport function hasValidCredentials(): boolean {\n const creds = getCredentials();\n\n if (!creds.token) {\n return false;\n }\n\n if (creds.expiresAt) {\n const expiresAt = new Date(creds.expiresAt);\n if (expiresAt < new Date()) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Get the CLI command name based on how it was invoked.\n * Returns 'evident' for normal usage, or the actual invocation for dev/npx usage.\n */\nexport function getCliName(): string {\n // Check if running via npx\n if (process.env.npm_execpath?.includes('npx')) {\n return 'npx @evident-ai/cli';\n }\n\n // Check if running via tsx (development)\n const argv1 = process.argv[1] || '';\n if (argv1.includes('tsx') || argv1.includes('ts-node')) {\n return 'pnpm --filter @evident-ai/cli dev:run';\n }\n\n // Default to 'evident' for normal installed CLI\n return 'evident';\n}\n\nexport { config, credentials };\n"],"mappings":";;;AAOA,OAAO,UAAU;AACjB,SAAS,eAAe;AACxB,SAAS,YAAY;AAwBrB,IAAM,qBAAwD;AAAA,EAC5D,OAAO;AAAA,IACL,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,KAAK;AAAA,IACH,QAAQ;AAAA,IACR,WAAW;AAAA,EACb;AAAA,EACA,YAAY;AAAA;AAAA,IAEV,QAAQ;AAAA,IACR,WAAW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AAI,aAAa,MAAM,SAAS;AACnE;AAKO,SAAS,mBAAyB;AACvC,cAAY,MAAM;AACpB;AAKO,SAAS,sBAA+B;AAC7C,QAAM,QAAQ,eAAe;AAE7B,MAAI,CAAC,MAAM,OAAO;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,MAAM,WAAW;AACnB,UAAM,YAAY,IAAI,KAAK,MAAM,SAAS;AAC1C,QAAI,YAAY,oBAAI,KAAK,GAAG;AAC1B,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;AAMO,SAAS,aAAqB;AAEnC,MAAI,QAAQ,IAAI,cAAc,SAAS,KAAK,GAAG;AAC7C,WAAO;AAAA,EACT;AAGA,QAAM,QAAQ,QAAQ,KAAK,CAAC,KAAK;AACjC,MAAI,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,SAAS,GAAG;AACtD,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
clearCredentials,
|
|
4
|
+
config,
|
|
5
|
+
credentials,
|
|
6
|
+
getApiUrlConfig,
|
|
7
|
+
getCliName,
|
|
8
|
+
getConfigDir,
|
|
9
|
+
getCredentials,
|
|
10
|
+
getEnvironment,
|
|
11
|
+
getTunnelUrlConfig,
|
|
12
|
+
hasValidCredentials,
|
|
13
|
+
setCredentials,
|
|
14
|
+
setEnvironment
|
|
15
|
+
} from "./chunk-MWOWXSOP.js";
|
|
16
|
+
export {
|
|
17
|
+
clearCredentials,
|
|
18
|
+
config,
|
|
19
|
+
credentials,
|
|
20
|
+
getApiUrlConfig,
|
|
21
|
+
getCliName,
|
|
22
|
+
getConfigDir,
|
|
23
|
+
getCredentials,
|
|
24
|
+
getEnvironment,
|
|
25
|
+
getTunnelUrlConfig,
|
|
26
|
+
hasValidCredentials,
|
|
27
|
+
setCredentials,
|
|
28
|
+
setEnvironment
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=config-J7LPYFVS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|