@vention/vention-cli 0.3.2 → 0.4.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/index.esm.js +208 -0
- package/package.json +12 -9
- package/src/config.d.ts +4 -0
- package/src/config.test.d.ts +1 -0
- package/src/digital-twin-client.d.ts +3 -0
- package/src/digital-twin-client.test.d.ts +1 -0
- package/src/index.d.ts +2 -1
- package/src/models.d.ts +26 -0
- package/src/rails-client.d.ts +3 -0
- package/src/rails-client.test.d.ts +1 -0
- package/index.cjs.js +0 -19
- /package/{index.cjs.d.ts → index.esm.d.ts} +0 -0
package/index.esm.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { select, password } from '@inquirer/prompts';
|
|
5
|
+
import { promises, realpathSync } from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
|
|
8
|
+
const getConfigPath = () => {
|
|
9
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
10
|
+
if (!homeDir) {
|
|
11
|
+
console.warn(chalk.yellow("Warning: Could not determine home directory. Using current directory instead."));
|
|
12
|
+
console.warn(chalk.yellow("This may cause issues if the CLI is run from different directories."));
|
|
13
|
+
console.warn(chalk.blue("To fix this permanently, set the HOME environment variable."));
|
|
14
|
+
return path.join(process.cwd(), ".vention-cli-config.json");
|
|
15
|
+
}
|
|
16
|
+
return path.join(homeDir, ".vention-cli-config.json");
|
|
17
|
+
};
|
|
18
|
+
const saveSession = async (data) => {
|
|
19
|
+
const configPath = getConfigPath();
|
|
20
|
+
await promises.writeFile(configPath, JSON.stringify(data, null, 2));
|
|
21
|
+
};
|
|
22
|
+
const loadSession = async () => {
|
|
23
|
+
try {
|
|
24
|
+
const configPath = getConfigPath();
|
|
25
|
+
const data = await promises.readFile(configPath, "utf-8");
|
|
26
|
+
return JSON.parse(data);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error("Failed to load session:", error);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getBaseRailsUrl = (environment) => {
|
|
35
|
+
switch (environment) {
|
|
36
|
+
case "local":
|
|
37
|
+
return "http://localhost:3000";
|
|
38
|
+
case "demo":
|
|
39
|
+
return "https://vention.foo";
|
|
40
|
+
case "prod":
|
|
41
|
+
return "https://vention.io";
|
|
42
|
+
default:
|
|
43
|
+
throw new Error("Invalid environment");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const getUserAllocations = async (session) => {
|
|
47
|
+
const baseUrl = getBaseRailsUrl(session.environment);
|
|
48
|
+
const res = await fetch(`${baseUrl}/api/v3/digital_twin_infrastructure/allocations`, {
|
|
49
|
+
method: "GET",
|
|
50
|
+
headers: {
|
|
51
|
+
Accept: "application/json",
|
|
52
|
+
Origin: baseUrl,
|
|
53
|
+
Referer: `${baseUrl}/`,
|
|
54
|
+
Cookie: [
|
|
55
|
+
`vention_session=${session.ventionSession}`,
|
|
56
|
+
...(session.stytchSessionJwt ? [`stytch_session_jwt=${session.stytchSessionJwt}`] : []),
|
|
57
|
+
...(session.ventionIdpSession ? [`vention_idp_session=${session.ventionIdpSession}`] : []),
|
|
58
|
+
].join("; "),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
if (!res.ok) {
|
|
62
|
+
throw new Error(`Request failed: ${res.status} ${res.statusText}`);
|
|
63
|
+
}
|
|
64
|
+
const response = await res.json();
|
|
65
|
+
return response;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const getDigitalTwinUrl = (environment, sessionId) => {
|
|
69
|
+
switch (environment) {
|
|
70
|
+
case "local":
|
|
71
|
+
return `http://localhost:3101`;
|
|
72
|
+
case "demo":
|
|
73
|
+
return `https://digital-twin.vention.foo/digital-twin/machine-motion/passthrough/${sessionId}/80`;
|
|
74
|
+
case "prod":
|
|
75
|
+
return `https://digital-twin.vention.io/digital-twin/machine-motion/passthrough/${sessionId}/80`;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error("Invalid environment");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const makeTestRequestToLinkedDigitalTwin = async (session) => {
|
|
81
|
+
if (!session.linkedSessionToken) {
|
|
82
|
+
throw new Error("Linked session token is not set");
|
|
83
|
+
}
|
|
84
|
+
const digitalTwinUrl = getDigitalTwinUrl(session.environment, session.linkedSessionToken);
|
|
85
|
+
const res = await fetch(`${digitalTwinUrl}/v1/library`, {
|
|
86
|
+
method: "GET",
|
|
87
|
+
headers: {
|
|
88
|
+
Accept: "application/json",
|
|
89
|
+
Cookie: `digital-twin-session-${session.linkedDesignId}=s%3A${session.linkedSessionToken}.s`,
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
if (!res.ok) {
|
|
93
|
+
throw new Error(`Request failed: ${res.status} ${res.statusText}`);
|
|
94
|
+
}
|
|
95
|
+
return await res.json();
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const program = new Command();
|
|
99
|
+
program.name("vention").description("CLI tool for Vention").version("0.2.0");
|
|
100
|
+
program
|
|
101
|
+
.command("login")
|
|
102
|
+
.description("Login to Ventionn")
|
|
103
|
+
.action(async () => {
|
|
104
|
+
try {
|
|
105
|
+
const environment = (await select({
|
|
106
|
+
message: "Select environment:",
|
|
107
|
+
choices: [
|
|
108
|
+
{ name: "local", value: "local" },
|
|
109
|
+
{ name: "demo", value: "demo" },
|
|
110
|
+
{ name: "prod", value: "prod" },
|
|
111
|
+
],
|
|
112
|
+
}));
|
|
113
|
+
const ventionSession = await password({
|
|
114
|
+
message: "Enter vention_session cookie value:",
|
|
115
|
+
mask: "",
|
|
116
|
+
validate: (input) => input.length > 0 || "vention_session is required",
|
|
117
|
+
});
|
|
118
|
+
const stytchSessionJwt = environment !== "local"
|
|
119
|
+
? await password({
|
|
120
|
+
message: "Enter stytch_session_jwt cookie value:",
|
|
121
|
+
mask: "",
|
|
122
|
+
validate: (input) => input.length > 0 || "stytch_session_jwt is required for non-local environments",
|
|
123
|
+
})
|
|
124
|
+
: undefined;
|
|
125
|
+
const ventionIdpSession = environment !== "local"
|
|
126
|
+
? await password({
|
|
127
|
+
message: "Enter vention_idp_session cookie value:",
|
|
128
|
+
mask: "",
|
|
129
|
+
validate: (input) => input.length > 0 || "vention_idp_session is required for non-local environments",
|
|
130
|
+
})
|
|
131
|
+
: undefined;
|
|
132
|
+
await saveSession(Object.assign({ environment,
|
|
133
|
+
ventionSession }, (environment !== "local" ? { stytchSessionJwt, ventionIdpSession } : {})));
|
|
134
|
+
console.log(chalk.green("Successfully logged in!"));
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error(chalk.red("Login failed:"), error);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
program
|
|
142
|
+
.command("link")
|
|
143
|
+
.description("Link to a one of your active designs")
|
|
144
|
+
.action(async () => {
|
|
145
|
+
try {
|
|
146
|
+
const session = await loadSession();
|
|
147
|
+
if (!session) {
|
|
148
|
+
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
const allocations = await getUserAllocations(session);
|
|
152
|
+
if (allocations.length === 0) {
|
|
153
|
+
console.log(chalk.yellow("No active allocations found."));
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
const selectedDesign = await select({
|
|
157
|
+
message: "Select a design to link:",
|
|
158
|
+
choices: allocations.map((allocation) => ({
|
|
159
|
+
name: `${allocation.designName} (ID: ${allocation.designId})`,
|
|
160
|
+
value: { id: allocation.designId, name: allocation.designName, sessionId: allocation.sessionId },
|
|
161
|
+
})),
|
|
162
|
+
});
|
|
163
|
+
await saveSession(Object.assign(Object.assign({}, session), { linkedDesignId: selectedDesign.id, linkedSessionToken: selectedDesign.sessionId }));
|
|
164
|
+
console.log(chalk.green(`\nSuccessfully linked to design "${selectedDesign.name}" (ID: ${selectedDesign.id})`));
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.error(chalk.red("Failed to get allocations:"));
|
|
168
|
+
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
program
|
|
173
|
+
.command("test")
|
|
174
|
+
.description("Make a test request to the digital twin for the linked design")
|
|
175
|
+
.action(async () => {
|
|
176
|
+
try {
|
|
177
|
+
const session = await loadSession();
|
|
178
|
+
if (!session) {
|
|
179
|
+
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
if (!session.linkedDesignId) {
|
|
183
|
+
console.error(chalk.red("No design linked. Please run 'vention link' first."));
|
|
184
|
+
process.exit(1);
|
|
185
|
+
}
|
|
186
|
+
const allocations = await getUserAllocations(session);
|
|
187
|
+
const linkedAllocation = allocations.find(a => a.designId === session.linkedDesignId);
|
|
188
|
+
if (!linkedAllocation) {
|
|
189
|
+
console.error(chalk.red("Linked design is not currently allocated. Please check if the digital twin is running."));
|
|
190
|
+
process.exit(1);
|
|
191
|
+
}
|
|
192
|
+
const digitalTwinResponse = await makeTestRequestToLinkedDigitalTwin(session);
|
|
193
|
+
console.log(chalk.green("Digital twin response:"));
|
|
194
|
+
console.log(chalk.green(JSON.stringify(digitalTwinResponse, null, 2)));
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.error(chalk.red("Failed to get digital twin response:"));
|
|
198
|
+
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
199
|
+
process.exit(1);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const resolvedArgv = realpathSync(process.argv[1]);
|
|
203
|
+
const resolvedUrl = new URL(import.meta.url).pathname;
|
|
204
|
+
if (resolvedArgv === resolvedUrl) {
|
|
205
|
+
program.parse(process.argv);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { program };
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vention/vention-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CLI tool for Vention applications",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/VentionCo/machine-cloud.git"
|
|
@@ -12,21 +13,23 @@
|
|
|
12
13
|
},
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"bin": {
|
|
15
|
-
"vention": "index.
|
|
16
|
-
"vn": "index.
|
|
16
|
+
"vention": "index.esm.js",
|
|
17
|
+
"vn": "index.esm.js"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"
|
|
20
|
-
"chalk": "4.1.2"
|
|
20
|
+
"axios": "1.7.7",
|
|
21
|
+
"chalk": "4.1.2",
|
|
22
|
+
"commander": "14.0.0",
|
|
23
|
+
"@inquirer/prompts": "7.6.0"
|
|
21
24
|
},
|
|
22
|
-
"peerDependencies": {},
|
|
23
25
|
"devDependencies": {
|
|
24
26
|
"@nx/vite": "21.1.3",
|
|
27
|
+
"@types/inquirer": "9.0.8",
|
|
25
28
|
"@types/node": "20.11.24",
|
|
26
29
|
"typescript": "5.3.3",
|
|
27
30
|
"vitest": "3.2.3"
|
|
28
31
|
},
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"types": "./index.
|
|
32
|
+
"module": "./index.esm.js",
|
|
33
|
+
"main": "./index.esm.js",
|
|
34
|
+
"types": "./index.esm.d.ts"
|
|
32
35
|
}
|
package/src/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/index.d.ts
CHANGED
package/src/models.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface AllocationResponse {
|
|
2
|
+
cookie: {
|
|
3
|
+
originalMaxAge: number;
|
|
4
|
+
expires: string;
|
|
5
|
+
httpOnly: boolean;
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
8
|
+
sessionId: string;
|
|
9
|
+
tabId: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
allocatedResourceId: string;
|
|
12
|
+
allocationCreationTime: number;
|
|
13
|
+
allocatedResourceLastAccessTime: number;
|
|
14
|
+
allocationType: "regular" | "custom";
|
|
15
|
+
designName: string;
|
|
16
|
+
designId: number;
|
|
17
|
+
}
|
|
18
|
+
export interface SessionData {
|
|
19
|
+
environment: "local" | "demo" | "prod";
|
|
20
|
+
ventionSession: string;
|
|
21
|
+
stytchSessionJwt?: string;
|
|
22
|
+
ventionIdpSession?: string;
|
|
23
|
+
linkedDesignId?: number;
|
|
24
|
+
lastTaskId?: string;
|
|
25
|
+
linkedSessionToken?: string;
|
|
26
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SessionData, AllocationResponse } from "./models";
|
|
2
|
+
export declare const getBaseRailsUrl: (environment: SessionData["environment"]) => "http://localhost:3000" | "https://vention.foo" | "https://vention.io";
|
|
3
|
+
export declare const getUserAllocations: (session: SessionData) => Promise<AllocationResponse[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.cjs.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var commander = require('commander');
|
|
5
|
-
var chalk = require('chalk');
|
|
6
|
-
|
|
7
|
-
const program = new commander.Command();
|
|
8
|
-
program.name("vention").description("CLI tool for Vention").version("0.1.0");
|
|
9
|
-
program
|
|
10
|
-
.command("hello")
|
|
11
|
-
.description("Say hello")
|
|
12
|
-
.action(() => {
|
|
13
|
-
console.log(chalk.green("Hello from Machine Logic CLI!"));
|
|
14
|
-
});
|
|
15
|
-
if (require.main === module) {
|
|
16
|
-
program.parse(process.argv);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
exports.program = program;
|
|
File without changes
|