@project-ajax/sdk 0.0.60 → 0.0.61
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/package.json +3 -11
- package/dist/cli/api/client.d.ts +0 -212
- package/dist/cli/api/client.d.ts.map +0 -1
- package/dist/cli/api/client.js +0 -330
- package/dist/cli/api/result.d.ts +0 -43
- package/dist/cli/api/result.d.ts.map +0 -1
- package/dist/cli/api/result.js +0 -43
- package/dist/cli/bin/cli.d.ts +0 -3
- package/dist/cli/bin/cli.d.ts.map +0 -1
- package/dist/cli/bin/cli.js +0 -5
- package/dist/cli/commands/auth.d.ts +0 -2
- package/dist/cli/commands/auth.d.ts.map +0 -1
- package/dist/cli/commands/auth.impl.d.ts +0 -5
- package/dist/cli/commands/auth.impl.d.ts.map +0 -1
- package/dist/cli/commands/auth.impl.js +0 -45
- package/dist/cli/commands/auth.impl.test.d.ts +0 -2
- package/dist/cli/commands/auth.impl.test.d.ts.map +0 -1
- package/dist/cli/commands/auth.js +0 -56
- package/dist/cli/commands/bundle.d.ts +0 -2
- package/dist/cli/commands/bundle.d.ts.map +0 -1
- package/dist/cli/commands/bundle.impl.d.ts +0 -2
- package/dist/cli/commands/bundle.impl.d.ts.map +0 -1
- package/dist/cli/commands/bundle.impl.js +0 -21
- package/dist/cli/commands/bundle.impl.test.d.ts +0 -2
- package/dist/cli/commands/bundle.impl.test.d.ts.map +0 -1
- package/dist/cli/commands/bundle.js +0 -23
- package/dist/cli/commands/capabilities.d.ts +0 -2
- package/dist/cli/commands/capabilities.d.ts.map +0 -1
- package/dist/cli/commands/capabilities.impl.d.ts +0 -3
- package/dist/cli/commands/capabilities.impl.d.ts.map +0 -1
- package/dist/cli/commands/capabilities.impl.js +0 -40
- package/dist/cli/commands/capabilities.js +0 -24
- package/dist/cli/commands/connect.d.ts +0 -2
- package/dist/cli/commands/connect.d.ts.map +0 -1
- package/dist/cli/commands/connect.impl.d.ts +0 -6
- package/dist/cli/commands/connect.impl.d.ts.map +0 -1
- package/dist/cli/commands/connect.impl.js +0 -116
- package/dist/cli/commands/connect.js +0 -78
- package/dist/cli/commands/deploy.d.ts +0 -3
- package/dist/cli/commands/deploy.d.ts.map +0 -1
- package/dist/cli/commands/deploy.impl.d.ts +0 -6
- package/dist/cli/commands/deploy.impl.d.ts.map +0 -1
- package/dist/cli/commands/deploy.impl.js +0 -60
- package/dist/cli/commands/deploy.impl.test.d.ts +0 -2
- package/dist/cli/commands/deploy.impl.test.d.ts.map +0 -1
- package/dist/cli/commands/deploy.js +0 -22
- package/dist/cli/commands/env.d.ts +0 -2
- package/dist/cli/commands/env.d.ts.map +0 -1
- package/dist/cli/commands/env.impl.d.ts +0 -11
- package/dist/cli/commands/env.impl.d.ts.map +0 -1
- package/dist/cli/commands/env.impl.js +0 -62
- package/dist/cli/commands/env.js +0 -39
- package/dist/cli/commands/exec.d.ts +0 -3
- package/dist/cli/commands/exec.d.ts.map +0 -1
- package/dist/cli/commands/exec.impl.d.ts +0 -7
- package/dist/cli/commands/exec.impl.d.ts.map +0 -1
- package/dist/cli/commands/exec.impl.js +0 -123
- package/dist/cli/commands/exec.js +0 -30
- package/dist/cli/commands/runs.d.ts +0 -2
- package/dist/cli/commands/runs.d.ts.map +0 -1
- package/dist/cli/commands/runs.impl.d.ts +0 -4
- package/dist/cli/commands/runs.impl.d.ts.map +0 -1
- package/dist/cli/commands/runs.impl.js +0 -71
- package/dist/cli/commands/runs.js +0 -45
- package/dist/cli/commands/secrets.d.ts +0 -2
- package/dist/cli/commands/secrets.d.ts.map +0 -1
- package/dist/cli/commands/secrets.impl.d.ts +0 -5
- package/dist/cli/commands/secrets.impl.d.ts.map +0 -1
- package/dist/cli/commands/secrets.impl.js +0 -99
- package/dist/cli/commands/secrets.js +0 -64
- package/dist/cli/commands/utils/testing.d.ts +0 -13
- package/dist/cli/commands/utils/testing.d.ts.map +0 -1
- package/dist/cli/commands/utils/testing.js +0 -58
- package/dist/cli/config.d.ts +0 -63
- package/dist/cli/config.d.ts.map +0 -1
- package/dist/cli/config.js +0 -194
- package/dist/cli/config.test.d.ts +0 -2
- package/dist/cli/config.test.d.ts.map +0 -1
- package/dist/cli/context.d.ts +0 -15
- package/dist/cli/context.d.ts.map +0 -1
- package/dist/cli/context.js +0 -16
- package/dist/cli/deploy.d.ts +0 -37
- package/dist/cli/deploy.d.ts.map +0 -1
- package/dist/cli/deploy.js +0 -100
- package/dist/cli/flags.d.ts +0 -21
- package/dist/cli/flags.d.ts.map +0 -1
- package/dist/cli/flags.js +0 -49
- package/dist/cli/handler.d.ts +0 -14
- package/dist/cli/handler.d.ts.map +0 -1
- package/dist/cli/handler.js +0 -32
- package/dist/cli/io.d.ts +0 -55
- package/dist/cli/io.d.ts.map +0 -1
- package/dist/cli/io.js +0 -96
- package/dist/cli/routes.d.ts +0 -2
- package/dist/cli/routes.d.ts.map +0 -1
- package/dist/cli/routes.js +0 -62
- package/dist/cli/utils/array.d.ts +0 -2
- package/dist/cli/utils/array.d.ts.map +0 -1
- package/dist/cli/utils/array.js +0 -10
- package/dist/cli/utils/openUrl.d.ts +0 -4
- package/dist/cli/utils/openUrl.d.ts.map +0 -1
- package/dist/cli/utils/openUrl.js +0 -43
- package/dist/cli/utils/string.d.ts +0 -2
- package/dist/cli/utils/string.d.ts.map +0 -1
- package/dist/cli/utils/string.js +0 -12
- package/src/cli/api/client.ts +0 -628
- package/src/cli/api/result.ts +0 -71
- package/src/cli/bin/cli.ts +0 -7
- package/src/cli/commands/.cursor/rules/testing-commands.mdc +0 -212
- package/src/cli/commands/auth.impl.test.ts +0 -228
- package/src/cli/commands/auth.impl.ts +0 -56
- package/src/cli/commands/auth.ts +0 -63
- package/src/cli/commands/bundle.impl.test.ts +0 -143
- package/src/cli/commands/bundle.impl.ts +0 -21
- package/src/cli/commands/bundle.ts +0 -23
- package/src/cli/commands/capabilities.impl.ts +0 -47
- package/src/cli/commands/capabilities.ts +0 -25
- package/src/cli/commands/connect.impl.ts +0 -149
- package/src/cli/commands/connect.ts +0 -80
- package/src/cli/commands/deploy.impl.test.ts +0 -254
- package/src/cli/commands/deploy.impl.ts +0 -73
- package/src/cli/commands/deploy.ts +0 -22
- package/src/cli/commands/env.impl.ts +0 -88
- package/src/cli/commands/env.ts +0 -38
- package/src/cli/commands/exec.impl.ts +0 -171
- package/src/cli/commands/exec.ts +0 -32
- package/src/cli/commands/runs.impl.ts +0 -87
- package/src/cli/commands/runs.ts +0 -49
- package/src/cli/commands/secrets.impl.ts +0 -130
- package/src/cli/commands/secrets.ts +0 -73
- package/src/cli/commands/utils/testing.ts +0 -66
- package/src/cli/config.test.ts +0 -108
- package/src/cli/config.ts +0 -265
- package/src/cli/context.ts +0 -26
- package/src/cli/deploy.ts +0 -190
- package/src/cli/flags.ts +0 -72
- package/src/cli/handler.ts +0 -68
- package/src/cli/io.ts +0 -132
- package/src/cli/routes.ts +0 -61
- package/src/cli/utils/array.ts +0 -7
- package/src/cli/utils/openUrl.ts +0 -53
- package/src/cli/utils/string.ts +0 -9
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
-
import { pluralize } from "../utils/string.js";
|
|
4
|
-
|
|
5
|
-
export interface PullEnvFlags {
|
|
6
|
-
yes: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const DEFAULT_ENV_FILE = ".env";
|
|
10
|
-
|
|
11
|
-
export const pullEnv = buildAuthedHandler(async function (
|
|
12
|
-
flags: PullEnvFlags,
|
|
13
|
-
filePath?: string,
|
|
14
|
-
) {
|
|
15
|
-
const { workerId } = this.config;
|
|
16
|
-
if (!workerId) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const destination = filePath ?? DEFAULT_ENV_FILE;
|
|
23
|
-
const absoluteDestination = this.path.resolve(
|
|
24
|
-
this.process.cwd(),
|
|
25
|
-
destination,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
if (this.fs.existsSync(absoluteDestination) && !flags.yes) {
|
|
29
|
-
const overwrite = await this.io.confirm({
|
|
30
|
-
message: `File "${destination}" already exists. Overwrite it?`,
|
|
31
|
-
noTTY: `File "${destination}" already exists.`,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (overwrite !== true) {
|
|
35
|
-
this.io.writeErr("Aborted.");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.io.writeErr("Fetching environment variables...");
|
|
41
|
-
const envResult = await this.apiClient.pullEnv(workerId);
|
|
42
|
-
|
|
43
|
-
if (Result.isFail(envResult)) {
|
|
44
|
-
this.io.writeErr("✗ Failed to fetch env vars");
|
|
45
|
-
this.io.writeErr(`✗ ${envResult.error.message}`);
|
|
46
|
-
throw new Error(envResult.error.message);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const envEntries = envResult.value.env;
|
|
50
|
-
const fileContents = serializeEnvFile(envEntries);
|
|
51
|
-
|
|
52
|
-
await this.fs.promises.mkdir(this.path.dirname(absoluteDestination), {
|
|
53
|
-
recursive: true,
|
|
54
|
-
});
|
|
55
|
-
await this.fs.promises.writeFile(absoluteDestination, fileContents, "utf8");
|
|
56
|
-
|
|
57
|
-
this.io.writeErr(
|
|
58
|
-
`Wrote ${pluralize(envEntries.length, "env var")} to "${destination}"`,
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export function serializeEnvFile(
|
|
63
|
-
envEntries: Array<{ key: string; value: string }>,
|
|
64
|
-
): string {
|
|
65
|
-
if (envEntries.length === 0) {
|
|
66
|
-
return "# No env vars configured for this worker\n";
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return envEntries
|
|
70
|
-
.map(({ key, value }) => `${key}=${formatEnvValue(value)}`)
|
|
71
|
-
.join("\n")
|
|
72
|
-
.concat("\n");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function formatEnvValue(value: string): string {
|
|
76
|
-
if (/^[A-Za-z0-9_./:-]*$/.test(value)) {
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const escaped = value
|
|
81
|
-
.replace(/\\/g, "\\\\")
|
|
82
|
-
.replace(/\n/g, "\\n")
|
|
83
|
-
.replace(/\r/g, "\\r")
|
|
84
|
-
.replace(/\t/g, "\\t")
|
|
85
|
-
.replace(/"/g, '\\"');
|
|
86
|
-
|
|
87
|
-
return `"${escaped}"`;
|
|
88
|
-
}
|
package/src/cli/commands/env.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
|
|
3
|
-
import { globalFlags } from "../flags.js";
|
|
4
|
-
|
|
5
|
-
export const envCommands = buildRouteMap({
|
|
6
|
-
docs: {
|
|
7
|
-
brief: "Work with worker environment files",
|
|
8
|
-
},
|
|
9
|
-
routes: {
|
|
10
|
-
pull: buildCommand({
|
|
11
|
-
docs: {
|
|
12
|
-
brief: "Write the worker's env vars to a .env file",
|
|
13
|
-
},
|
|
14
|
-
parameters: {
|
|
15
|
-
positional: {
|
|
16
|
-
kind: "tuple",
|
|
17
|
-
parameters: [
|
|
18
|
-
{
|
|
19
|
-
brief: "Destination file path",
|
|
20
|
-
parse: String,
|
|
21
|
-
placeholder: "file",
|
|
22
|
-
optional: true,
|
|
23
|
-
},
|
|
24
|
-
],
|
|
25
|
-
},
|
|
26
|
-
flags: {
|
|
27
|
-
...globalFlags,
|
|
28
|
-
yes: {
|
|
29
|
-
kind: "boolean",
|
|
30
|
-
brief: "Overwrite the output file without prompting",
|
|
31
|
-
default: false,
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
loader: () => import("./env.impl.js").then((m) => m.pullEnv),
|
|
36
|
-
}),
|
|
37
|
-
},
|
|
38
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import type { GlobalFlags } from "../flags.js";
|
|
3
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
-
import { chunkEvery } from "../utils/array.js";
|
|
5
|
-
|
|
6
|
-
const usageHint = `Usage: workers exec <capabilityName> <capabilityFunction> [<argName1>=<value1> <argName2>=<value2>...]`;
|
|
7
|
-
|
|
8
|
-
interface ExecFlags extends GlobalFlags {
|
|
9
|
-
stream: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const exec = buildAuthedHandler(async function (
|
|
13
|
-
flags: ExecFlags,
|
|
14
|
-
...args: readonly string[]
|
|
15
|
-
) {
|
|
16
|
-
const { workerId } = this.config;
|
|
17
|
-
if (!workerId) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const capabilityName = args[0];
|
|
24
|
-
const capabilityFunction = args[1] ?? null;
|
|
25
|
-
const functionArgs = args.slice(2).flatMap((arg) => arg.split(/[=]/));
|
|
26
|
-
|
|
27
|
-
if (!capabilityName) {
|
|
28
|
-
throw usageError();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// If there's an odd number of remaining args, the first one is the function name
|
|
32
|
-
if (functionArgs.length % 2 !== 0) {
|
|
33
|
-
throw usageError();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const argsList = chunkEvery(functionArgs, 2).map(([key, value]) => {
|
|
37
|
-
if (!key || !value) {
|
|
38
|
-
throw usageError();
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
name: key,
|
|
42
|
-
value,
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// Execute the capability
|
|
47
|
-
this.io.writeErr(`Executing capability "${capabilityName}"...`);
|
|
48
|
-
|
|
49
|
-
if (flags.stream) {
|
|
50
|
-
const result = await this.apiClient.runCapability(
|
|
51
|
-
workerId,
|
|
52
|
-
capabilityName,
|
|
53
|
-
capabilityFunction,
|
|
54
|
-
argsList,
|
|
55
|
-
true,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
if (Result.isSuccess(result)) {
|
|
59
|
-
const decoder = new TextDecoder();
|
|
60
|
-
let buffer = "";
|
|
61
|
-
|
|
62
|
-
const allOutput: string[] = [];
|
|
63
|
-
|
|
64
|
-
const onBodyLine = async (jsonLine: string) => {
|
|
65
|
-
try {
|
|
66
|
-
const parsedLine = JSON.parse(jsonLine) as
|
|
67
|
-
| {
|
|
68
|
-
_tag: "log";
|
|
69
|
-
event: {
|
|
70
|
-
stream: "stdout" | "stderr";
|
|
71
|
-
data: string;
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
| {
|
|
75
|
-
_tag: "result";
|
|
76
|
-
result: unknown;
|
|
77
|
-
}
|
|
78
|
-
| {
|
|
79
|
-
_tag: "error";
|
|
80
|
-
error: string;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
switch (parsedLine._tag) {
|
|
84
|
-
case "log":
|
|
85
|
-
if (!flags.debug) {
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (parsedLine.event.stream === "stdout") {
|
|
90
|
-
allOutput.push(parsedLine.event.data);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
parsedLine.event.data
|
|
94
|
-
.trim()
|
|
95
|
-
.split("\n")
|
|
96
|
-
.forEach((dataLine) => {
|
|
97
|
-
this.io.writeErr(
|
|
98
|
-
`[worker:${parsedLine.event.stream}] ${dataLine.trim()}`,
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
break;
|
|
103
|
-
case "result":
|
|
104
|
-
this.io.writeOut(JSON.stringify(parsedLine.result, null, 2));
|
|
105
|
-
break;
|
|
106
|
-
case "error":
|
|
107
|
-
this.io.writeErr(`Error: ${parsedLine.error}`);
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
} catch (error) {
|
|
111
|
-
this.io.writeErr(`Error parsing log line: ${jsonLine}: ${error}`);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
for await (const log of result.value) {
|
|
116
|
-
const output = decoder.decode(log);
|
|
117
|
-
buffer += output;
|
|
118
|
-
|
|
119
|
-
const lines = buffer.split("\n");
|
|
120
|
-
// Keep the last element as buffer (might be empty or incomplete line)
|
|
121
|
-
buffer = lines.pop() ?? "";
|
|
122
|
-
|
|
123
|
-
// Process all complete lines
|
|
124
|
-
for (const line of lines) {
|
|
125
|
-
await onBodyLine(line);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Process any remaining content in buffer
|
|
130
|
-
if (buffer) {
|
|
131
|
-
await onBodyLine(buffer);
|
|
132
|
-
}
|
|
133
|
-
return;
|
|
134
|
-
} else {
|
|
135
|
-
this.io.writeErr(`\n✗ Failed to execute capability`);
|
|
136
|
-
|
|
137
|
-
// If it's a validation error, show the clean debug message
|
|
138
|
-
if (result.error.validationError) {
|
|
139
|
-
this.io.writeErr(`\t✗ HTTP Error: ${result.error.status}`);
|
|
140
|
-
this.io.writeErr(`\t✗ ${result.error.validationError.debugMessage}`);
|
|
141
|
-
this.io.writeErr(`\n${usageHint}`);
|
|
142
|
-
throw new Error(result.error.validationError.debugMessage);
|
|
143
|
-
} else {
|
|
144
|
-
this.io.writeErr(`\t✗ HTTP Error: ${result.error.status}`);
|
|
145
|
-
this.io.writeErr(`\t✗ ${result.error.message}`);
|
|
146
|
-
throw new Error(result.error.message);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
const result = await this.apiClient.runCapability(
|
|
151
|
-
workerId,
|
|
152
|
-
capabilityName,
|
|
153
|
-
capabilityFunction,
|
|
154
|
-
argsList,
|
|
155
|
-
false,
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
if (Result.isSuccess(result)) {
|
|
159
|
-
const data = Result.unwrap(result);
|
|
160
|
-
this.io.writeOut(JSON.stringify(data.result, null, 2));
|
|
161
|
-
} else {
|
|
162
|
-
this.io.writeErr(`\n✗ Failed to execute capability`);
|
|
163
|
-
this.io.writeErr(`\t✗ ${result.error.message}`);
|
|
164
|
-
throw new Error(result.error.message);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
function usageError() {
|
|
170
|
-
return new Error(`Invalid arguments provided. ${usageHint}`);
|
|
171
|
-
}
|
package/src/cli/commands/exec.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { buildCommand } from "@stricli/core";
|
|
2
|
-
import { globalFlags } from "../flags.js";
|
|
3
|
-
|
|
4
|
-
export default buildCommand({
|
|
5
|
-
docs: {
|
|
6
|
-
brief: "Execute a worker capability with optional function and arguments",
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
parameters: {
|
|
10
|
-
positional: {
|
|
11
|
-
kind: "array",
|
|
12
|
-
parameter: {
|
|
13
|
-
brief:
|
|
14
|
-
"Capability name, optional function name, and arguments (key value pairs)",
|
|
15
|
-
parse: String,
|
|
16
|
-
placeholder: "capabilityName [functionName] [key value]...",
|
|
17
|
-
},
|
|
18
|
-
minimum: 1,
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
flags: {
|
|
22
|
-
...globalFlags,
|
|
23
|
-
stream: {
|
|
24
|
-
kind: "boolean",
|
|
25
|
-
brief: "Stream the output of the capability",
|
|
26
|
-
default: true,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
loader: () => import("./exec.impl.js").then((m) => m.exec),
|
|
32
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
3
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
-
|
|
5
|
-
export const listRuns = buildAuthedHandler(async function (flags: FormatFlags) {
|
|
6
|
-
const { workerId } = this.config;
|
|
7
|
-
if (!workerId) {
|
|
8
|
-
throw new Error(
|
|
9
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
this.process.stderr.write("Fetching runs...");
|
|
14
|
-
|
|
15
|
-
const result = await this.apiClient.listRunsForWorker(workerId);
|
|
16
|
-
|
|
17
|
-
if (Result.isSuccess(result)) {
|
|
18
|
-
this.process.stderr.write("OK\n\n");
|
|
19
|
-
|
|
20
|
-
const data = Result.unwrap(result);
|
|
21
|
-
if (data.runs.length === 0) {
|
|
22
|
-
this.io.writeErr("No runs found for this worker.");
|
|
23
|
-
} else {
|
|
24
|
-
this.io.writeTableOut({
|
|
25
|
-
headers: ["Run ID", "Name", "Started At", "Ended At", "Exit Code"],
|
|
26
|
-
rows: data.runs.map((run) => [
|
|
27
|
-
run.runId,
|
|
28
|
-
run.name,
|
|
29
|
-
run.startedAt,
|
|
30
|
-
run.endedAt,
|
|
31
|
-
run.exitCode,
|
|
32
|
-
]),
|
|
33
|
-
plain: flags.plain,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
this.process.stderr.write("ERROR\n\n");
|
|
38
|
-
|
|
39
|
-
// If it's a validation error, show the clean debug message
|
|
40
|
-
if (result.error.validationError) {
|
|
41
|
-
this.io.writeErr(`✗ ${result.error.validationError.debugMessage}`);
|
|
42
|
-
throw new Error(result.error.validationError.debugMessage);
|
|
43
|
-
} else {
|
|
44
|
-
this.io.writeErr(`✗ ${result.error.message}`);
|
|
45
|
-
throw new Error(result.error.message);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
export const getRunLogs = buildAuthedHandler(async function (
|
|
51
|
-
_flags: GlobalFlags,
|
|
52
|
-
runId: string,
|
|
53
|
-
) {
|
|
54
|
-
const { workerId } = this.config;
|
|
55
|
-
if (!workerId) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (!runId) {
|
|
62
|
-
throw new Error("Run ID is required");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.process.stderr.write(`Fetching logs for run ${runId}...`);
|
|
66
|
-
|
|
67
|
-
const result = await this.apiClient.getRunLogs(workerId, runId);
|
|
68
|
-
|
|
69
|
-
if (Result.isSuccess(result)) {
|
|
70
|
-
this.process.stderr.write("OK\n\n");
|
|
71
|
-
|
|
72
|
-
const data = Result.unwrap(result);
|
|
73
|
-
// Output logs directly to stdout (primary output)
|
|
74
|
-
this.io.writeOut(data.logs);
|
|
75
|
-
} else {
|
|
76
|
-
this.process.stderr.write("ERROR\n\n");
|
|
77
|
-
|
|
78
|
-
// If it's a validation error, show the clean debug message
|
|
79
|
-
if (result.error.validationError) {
|
|
80
|
-
this.io.writeErr(`✗ ${result.error.validationError.debugMessage}`);
|
|
81
|
-
throw new Error(result.error.validationError.debugMessage);
|
|
82
|
-
} else {
|
|
83
|
-
this.io.writeErr(`✗ ${result.error.message}`);
|
|
84
|
-
throw new Error(result.error.message);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
});
|
package/src/cli/commands/runs.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
-
|
|
4
|
-
export const runsCommands = buildRouteMap({
|
|
5
|
-
docs: {
|
|
6
|
-
brief: "Commands for managing worker runs",
|
|
7
|
-
},
|
|
8
|
-
routes: {
|
|
9
|
-
list: buildCommand({
|
|
10
|
-
docs: {
|
|
11
|
-
brief: "List all runs for a worker",
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
parameters: {
|
|
15
|
-
flags: {
|
|
16
|
-
...globalFlags,
|
|
17
|
-
...formatFlags,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
loader: () => import("./runs.impl.js").then((m) => m.listRuns),
|
|
22
|
-
}),
|
|
23
|
-
|
|
24
|
-
logs: buildCommand({
|
|
25
|
-
docs: {
|
|
26
|
-
brief: "Get logs for a specific run",
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
parameters: {
|
|
30
|
-
positional: {
|
|
31
|
-
kind: "tuple",
|
|
32
|
-
parameters: [
|
|
33
|
-
{
|
|
34
|
-
brief: "The run ID to get logs for",
|
|
35
|
-
parse: String,
|
|
36
|
-
placeholder: "runId",
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
flags: {
|
|
42
|
-
...globalFlags,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
loader: () => import("./runs.impl.js").then((m) => m.getRunLogs),
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
});
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
3
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
-
import { chunkEvery } from "../utils/array.js";
|
|
5
|
-
import { pluralize } from "../utils/string.js";
|
|
6
|
-
|
|
7
|
-
export const setSecrets = buildAuthedHandler(async function (
|
|
8
|
-
_flags: GlobalFlags,
|
|
9
|
-
...args: string[]
|
|
10
|
-
) {
|
|
11
|
-
const secrets = parseSecretArgs(args);
|
|
12
|
-
const { workerId } = this.config;
|
|
13
|
-
|
|
14
|
-
if (!workerId) {
|
|
15
|
-
throw new Error(
|
|
16
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
this.io.writeErr(`Setting ${pluralize(secrets.length, "secret")}...`);
|
|
21
|
-
|
|
22
|
-
const result = await this.apiClient.upsertSecrets(workerId, secrets);
|
|
23
|
-
|
|
24
|
-
if (Result.isSuccess(result)) {
|
|
25
|
-
for (const secret of Result.unwrap(result).secrets) {
|
|
26
|
-
this.io.writeErr(`Set secret "${secret.key}"`);
|
|
27
|
-
}
|
|
28
|
-
} else {
|
|
29
|
-
this.io.writeErr(`✗ Failed to set secrets`);
|
|
30
|
-
this.io.writeErr(`✗ ${result.error.message}`);
|
|
31
|
-
throw new Error(result.error.message);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export const listSecrets = buildAuthedHandler(async function (
|
|
36
|
-
flags: FormatFlags,
|
|
37
|
-
) {
|
|
38
|
-
const { workerId } = this.config;
|
|
39
|
-
if (!workerId) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this.process.stderr.write(`Fetching secrets...`);
|
|
46
|
-
|
|
47
|
-
const result = await this.apiClient.listSecrets(workerId);
|
|
48
|
-
|
|
49
|
-
if (Result.isSuccess(result)) {
|
|
50
|
-
this.process.stderr.write("OK\n\n");
|
|
51
|
-
|
|
52
|
-
const data = Result.unwrap(result);
|
|
53
|
-
if (data.secrets.length === 0) {
|
|
54
|
-
this.io.writeErr("No secrets for this worker.");
|
|
55
|
-
this.io.writeErr(
|
|
56
|
-
"To list OAuth connect secrets, use `npx workers connect list`",
|
|
57
|
-
);
|
|
58
|
-
} else {
|
|
59
|
-
this.io.writeTableOut({
|
|
60
|
-
headers: ["Key", "Created At"],
|
|
61
|
-
rows: data.secrets.map((secret) => [secret.key, secret.createdAt]),
|
|
62
|
-
plain: flags.plain,
|
|
63
|
-
});
|
|
64
|
-
this.io.writeErr(
|
|
65
|
-
"To list OAuth connect secrets, use `npx workers connect list`",
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
this.process.stderr.write("ERROR\n\n");
|
|
70
|
-
|
|
71
|
-
this.io.writeErr(`✗ Failed to list secrets`);
|
|
72
|
-
this.io.writeErr(`✗ ${result.error.message}`);
|
|
73
|
-
throw new Error(result.error.message);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export const removeSecret = buildAuthedHandler(async function (
|
|
78
|
-
_flags: GlobalFlags,
|
|
79
|
-
key: string,
|
|
80
|
-
) {
|
|
81
|
-
const { workerId } = this.config;
|
|
82
|
-
if (!workerId) {
|
|
83
|
-
throw new Error(
|
|
84
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.process.stderr.write(`Removing secret "${key}"...`);
|
|
89
|
-
|
|
90
|
-
const result = await this.apiClient.deleteSecret(workerId, key);
|
|
91
|
-
|
|
92
|
-
if (Result.isSuccess(result)) {
|
|
93
|
-
this.process.stderr.write("OK\n\n");
|
|
94
|
-
} else {
|
|
95
|
-
this.process.stderr.write("ERROR\n\n");
|
|
96
|
-
|
|
97
|
-
this.io.writeErr(`✗ Failed to remove secret "${key}"`);
|
|
98
|
-
this.io.writeErr(`✗ ${result.error.message}`);
|
|
99
|
-
throw new Error(result.error.message);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
function usageError() {
|
|
104
|
-
return new Error(
|
|
105
|
-
"Invalid secrets provided. Usage: workers secrets set <key> <value> [<key2> <value2>...] or <key>=<value> [<key2>=<value2>...]",
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Parse secret arguments from CLI, supporting "key value", "key=value", and "key:value" formats.
|
|
111
|
-
*/
|
|
112
|
-
function parseSecretArgs(
|
|
113
|
-
args: readonly string[],
|
|
114
|
-
): Array<{ key: string; value: string }> {
|
|
115
|
-
if (args.length === 0) {
|
|
116
|
-
throw usageError();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Split each arg by = or : to flatten everything into tokens
|
|
120
|
-
const tokens = args.flatMap((arg) => arg.split(/[=:]/));
|
|
121
|
-
|
|
122
|
-
const secrets = chunkEvery(tokens, 2).map(([key, value]) => {
|
|
123
|
-
if (!key || !value) {
|
|
124
|
-
throw usageError();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return { key, value };
|
|
128
|
-
});
|
|
129
|
-
return secrets;
|
|
130
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
-
|
|
4
|
-
export const secretsCommands = buildRouteMap({
|
|
5
|
-
docs: {
|
|
6
|
-
brief: "Commands for managing worker secrets",
|
|
7
|
-
},
|
|
8
|
-
routes: {
|
|
9
|
-
set: buildCommand({
|
|
10
|
-
docs: {
|
|
11
|
-
brief:
|
|
12
|
-
"Set one or more secrets for a worker. Supports 'key value' or 'key=value' format.",
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
parameters: {
|
|
16
|
-
positional: {
|
|
17
|
-
kind: "array",
|
|
18
|
-
parameter: {
|
|
19
|
-
brief: "Secret key-value pairs (key value or key=value)",
|
|
20
|
-
parse: String,
|
|
21
|
-
placeholder: "secrets...",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
flags: {
|
|
26
|
-
...globalFlags,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
loader: () => import("./secrets.impl.js").then((m) => m.setSecrets),
|
|
31
|
-
}),
|
|
32
|
-
|
|
33
|
-
list: buildCommand({
|
|
34
|
-
docs: {
|
|
35
|
-
brief: "List all secrets for a worker (keys only)",
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
parameters: {
|
|
39
|
-
flags: {
|
|
40
|
-
...globalFlags,
|
|
41
|
-
...formatFlags,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
loader: () => import("./secrets.impl.js").then((m) => m.listSecrets),
|
|
46
|
-
}),
|
|
47
|
-
|
|
48
|
-
rm: buildCommand({
|
|
49
|
-
docs: {
|
|
50
|
-
brief: "Remove a secret from a worker",
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
parameters: {
|
|
54
|
-
positional: {
|
|
55
|
-
kind: "tuple",
|
|
56
|
-
parameters: [
|
|
57
|
-
{
|
|
58
|
-
brief: "The secret key name to remove",
|
|
59
|
-
parse: String,
|
|
60
|
-
placeholder: "key",
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
flags: {
|
|
66
|
-
...globalFlags,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
loader: () => import("./secrets.impl.js").then((m) => m.removeSecret),
|
|
71
|
-
}),
|
|
72
|
-
},
|
|
73
|
-
});
|