@project-ajax/sdk 0.0.60 → 0.0.62
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/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/package.json +4 -16
- package/src/index.ts +0 -1
- package/dist/capabilities/slashCommand.d.ts +0 -56
- package/dist/capabilities/slashCommand.d.ts.map +0 -1
- package/dist/capabilities/slashCommand.js +0 -32
- 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/capabilities/slashCommand.ts +0 -71
- 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,254 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
afterEach,
|
|
3
|
-
beforeEach,
|
|
4
|
-
describe,
|
|
5
|
-
expect,
|
|
6
|
-
it,
|
|
7
|
-
type Mock,
|
|
8
|
-
vi,
|
|
9
|
-
} from "vitest";
|
|
10
|
-
import { Result } from "../api/result.js";
|
|
11
|
-
import { Config } from "../config.js";
|
|
12
|
-
import {
|
|
13
|
-
baseFlags,
|
|
14
|
-
cleanupTmpDirectories,
|
|
15
|
-
createAndLoadConfig,
|
|
16
|
-
createBaseContext,
|
|
17
|
-
} from "./utils/testing.js";
|
|
18
|
-
|
|
19
|
-
// Mock external dependencies
|
|
20
|
-
vi.mock("../deploy.js", () => ({
|
|
21
|
-
deployWorker: vi.fn(),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
import { deployWorker } from "../deploy.js";
|
|
25
|
-
import { deploy } from "./deploy.impl.js";
|
|
26
|
-
|
|
27
|
-
afterEach(cleanupTmpDirectories);
|
|
28
|
-
|
|
29
|
-
describe("deploy", () => {
|
|
30
|
-
let stderrSpy: Mock<typeof process.stderr.write>;
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
stderrSpy = vi
|
|
34
|
-
.spyOn(process.stderr, "write")
|
|
35
|
-
.mockImplementation(() => true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("deploys existing worker when workerId is set", async () => {
|
|
39
|
-
const [mockConfig] = await createAndLoadConfig({
|
|
40
|
-
configFile: {
|
|
41
|
-
token:
|
|
42
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
43
|
-
workerId: "worker-123",
|
|
44
|
-
environment: "local",
|
|
45
|
-
baseUrl: "http://localhost:3000",
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
vi.spyOn(Config, "load").mockResolvedValue(mockConfig);
|
|
50
|
-
vi.mocked(deployWorker).mockResolvedValue(
|
|
51
|
-
Result.success({ workerId: "worker-123" }),
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
const updateSpy = vi.spyOn(mockConfig, "update");
|
|
55
|
-
const context = createBaseContext();
|
|
56
|
-
|
|
57
|
-
await deploy.call(context, baseFlags);
|
|
58
|
-
|
|
59
|
-
expect(deployWorker).toHaveBeenCalledWith(expect.anything(), {
|
|
60
|
-
workerPath: process.cwd(),
|
|
61
|
-
workerId: "worker-123",
|
|
62
|
-
token:
|
|
63
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
64
|
-
environment: "local",
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
expect(updateSpy).toHaveBeenCalledWith({
|
|
68
|
-
workerId: "worker-123",
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const allCalls = stderrSpy.mock.calls.map((call) => call[0]).join("");
|
|
72
|
-
expect(allCalls).toContain("Deploying worker...");
|
|
73
|
-
expect(allCalls).toContain("✓ Successfully deployed worker");
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("deploys new worker with name flag", async () => {
|
|
77
|
-
const [mockConfig] = await createAndLoadConfig({
|
|
78
|
-
configFile: {
|
|
79
|
-
token:
|
|
80
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
81
|
-
workerId: null,
|
|
82
|
-
environment: "local",
|
|
83
|
-
baseUrl: "http://localhost:3000",
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
vi.spyOn(Config, "load").mockResolvedValue(mockConfig);
|
|
88
|
-
vi.mocked(deployWorker).mockResolvedValue(
|
|
89
|
-
Result.success({ workerId: "worker-456" }),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const updateSpy = vi.spyOn(mockConfig, "update");
|
|
93
|
-
const context = createBaseContext();
|
|
94
|
-
vi.spyOn(context.io, "input").mockResolvedValue("my-worker");
|
|
95
|
-
|
|
96
|
-
await deploy.call(context, { ...baseFlags, name: "my-worker" });
|
|
97
|
-
|
|
98
|
-
expect(deployWorker).toHaveBeenCalledWith(expect.anything(), {
|
|
99
|
-
name: "my-worker",
|
|
100
|
-
workerPath: process.cwd(),
|
|
101
|
-
token:
|
|
102
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
103
|
-
environment: "local",
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
expect(updateSpy).toHaveBeenCalledWith({
|
|
107
|
-
workerId: "worker-456",
|
|
108
|
-
});
|
|
109
|
-
expect(context.io.input).not.toHaveBeenCalled();
|
|
110
|
-
|
|
111
|
-
const allCalls = stderrSpy.mock.calls.map((call) => call[0]).join("");
|
|
112
|
-
expect(allCalls).toContain("✓ Successfully deployed worker");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("prompts for name when deploying new worker without name flag", async () => {
|
|
116
|
-
const [mockConfig] = await createAndLoadConfig({
|
|
117
|
-
configFile: {
|
|
118
|
-
token:
|
|
119
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
120
|
-
workerId: null,
|
|
121
|
-
environment: "local",
|
|
122
|
-
baseUrl: "http://localhost:3000",
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
vi.spyOn(Config, "load").mockResolvedValue(mockConfig);
|
|
127
|
-
vi.mocked(deployWorker).mockResolvedValue(
|
|
128
|
-
Result.success({ workerId: "worker-789" }),
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const updateSpy = vi.spyOn(mockConfig, "update");
|
|
132
|
-
const context = createBaseContext();
|
|
133
|
-
vi.spyOn(context.io, "input").mockResolvedValue("prompted-worker");
|
|
134
|
-
|
|
135
|
-
await deploy.call(context, baseFlags);
|
|
136
|
-
|
|
137
|
-
expect(context.io.input).toHaveBeenCalledWith({
|
|
138
|
-
message: "Enter a name for the worker",
|
|
139
|
-
required: true,
|
|
140
|
-
noTTY: "Provide a name for the worker with --name",
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
expect(deployWorker).toHaveBeenCalledWith(expect.anything(), {
|
|
144
|
-
name: "prompted-worker",
|
|
145
|
-
workerPath: process.cwd(),
|
|
146
|
-
token:
|
|
147
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
148
|
-
environment: "local",
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
expect(updateSpy).toHaveBeenCalledWith({
|
|
152
|
-
workerId: "worker-789",
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("throws error when name is not provided", async () => {
|
|
157
|
-
const [mockConfig] = await createAndLoadConfig({
|
|
158
|
-
configFile: {
|
|
159
|
-
token:
|
|
160
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
161
|
-
workerId: null,
|
|
162
|
-
environment: "local",
|
|
163
|
-
baseUrl: "http://localhost:3000",
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
vi.spyOn(Config, "load").mockResolvedValue(mockConfig);
|
|
168
|
-
|
|
169
|
-
const context = createBaseContext();
|
|
170
|
-
vi.spyOn(context.io, "input").mockResolvedValue("");
|
|
171
|
-
|
|
172
|
-
await expect(deploy.call(context, baseFlags)).rejects.toThrow(
|
|
173
|
-
"Name is required",
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("throws error when both workerId and name are provided", async () => {
|
|
178
|
-
const [mockConfig] = await createAndLoadConfig({
|
|
179
|
-
configFile: {
|
|
180
|
-
token:
|
|
181
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
182
|
-
workerId: "worker-123",
|
|
183
|
-
environment: "local",
|
|
184
|
-
baseUrl: "http://localhost:3000",
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
vi.spyOn(Config, "load").mockResolvedValue(mockConfig);
|
|
189
|
-
|
|
190
|
-
const context = createBaseContext();
|
|
191
|
-
|
|
192
|
-
await expect(
|
|
193
|
-
deploy.call(context, { ...baseFlags, name: "my-worker" }),
|
|
194
|
-
).rejects.toThrow("Cannot specify a name when updating an existing worker");
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("handles deployment failure", async () => {
|
|
198
|
-
const [mockConfig] = await createAndLoadConfig({
|
|
199
|
-
configFile: {
|
|
200
|
-
token:
|
|
201
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
202
|
-
workerId: "worker-123",
|
|
203
|
-
environment: "local",
|
|
204
|
-
baseUrl: "http://localhost:3000",
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
vi.spyOn(Config, "load").mockResolvedValue(mockConfig);
|
|
209
|
-
vi.mocked(deployWorker).mockResolvedValue(
|
|
210
|
-
Result.fail({
|
|
211
|
-
status: 500,
|
|
212
|
-
statusText: "Internal Server Error",
|
|
213
|
-
message: "Deployment failed",
|
|
214
|
-
}),
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
const context = createBaseContext();
|
|
218
|
-
|
|
219
|
-
await deploy.call(context, baseFlags);
|
|
220
|
-
|
|
221
|
-
const allCalls = stderrSpy.mock.calls.map((call) => call[0]).join("");
|
|
222
|
-
expect(allCalls).toContain("✗ Failed to deploy worker");
|
|
223
|
-
expect(allCalls).toContain("Deployment failed");
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("trims whitespace from prompted name", async () => {
|
|
227
|
-
const [mockConfig] = await createAndLoadConfig({
|
|
228
|
-
configFile: {
|
|
229
|
-
token:
|
|
230
|
-
"1.2.eyJzcGFjZUlkIjoic3BhY2UxIiwidXNlcklkIjoidXNlcjEiLCJjZWxsSWQiOiJjZWxsMSJ9.sig",
|
|
231
|
-
workerId: null,
|
|
232
|
-
environment: "local",
|
|
233
|
-
baseUrl: "http://localhost:3000",
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
vi.spyOn(Config, "load").mockResolvedValue(mockConfig);
|
|
238
|
-
vi.mocked(deployWorker).mockResolvedValue(
|
|
239
|
-
Result.success({ workerId: "worker-999" }),
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
const context = createBaseContext();
|
|
243
|
-
vi.spyOn(context.io, "input").mockResolvedValue(" worker-name ");
|
|
244
|
-
|
|
245
|
-
await deploy.call(context, baseFlags);
|
|
246
|
-
|
|
247
|
-
expect(deployWorker).toHaveBeenCalledWith(
|
|
248
|
-
expect.anything(),
|
|
249
|
-
expect.objectContaining({
|
|
250
|
-
name: "worker-name",
|
|
251
|
-
}),
|
|
252
|
-
);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { ApiError } from "../api/client.js";
|
|
2
|
-
import { Result } from "../api/result.js";
|
|
3
|
-
import { deployWorker } from "../deploy.js";
|
|
4
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
5
|
-
|
|
6
|
-
interface DeployFlags {
|
|
7
|
-
name?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const deploy = buildAuthedHandler(async function (flags: DeployFlags) {
|
|
11
|
-
const { token } = this.config.tokenInfo;
|
|
12
|
-
const workerId = this.config.workerId;
|
|
13
|
-
|
|
14
|
-
const environment = this.config.environment;
|
|
15
|
-
if (!environment) {
|
|
16
|
-
// Unexpected to get here when token is set
|
|
17
|
-
throw new Error("Unexpected error: Environment not set");
|
|
18
|
-
}
|
|
19
|
-
const workerPath = this.process.cwd();
|
|
20
|
-
|
|
21
|
-
this.io.writeErr("Deploying worker...");
|
|
22
|
-
|
|
23
|
-
const name = flags.name;
|
|
24
|
-
if (workerId && name) {
|
|
25
|
-
throw new Error("Cannot specify a name when updating an existing worker");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let result: Result<{ workerId: string }, ApiError>;
|
|
29
|
-
if (workerId) {
|
|
30
|
-
result = await deployWorker(this, {
|
|
31
|
-
workerPath,
|
|
32
|
-
workerId,
|
|
33
|
-
token,
|
|
34
|
-
environment,
|
|
35
|
-
});
|
|
36
|
-
} else {
|
|
37
|
-
let validatedName: string;
|
|
38
|
-
if (name) {
|
|
39
|
-
validatedName = name;
|
|
40
|
-
} else {
|
|
41
|
-
const nameInput = await this.io.input({
|
|
42
|
-
message: "Enter a name for the worker",
|
|
43
|
-
required: true,
|
|
44
|
-
noTTY: "Provide a name for the worker with --name",
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const trimmedName = nameInput?.trim();
|
|
48
|
-
|
|
49
|
-
if (!trimmedName) {
|
|
50
|
-
throw new Error("Name is required");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
validatedName = trimmedName;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
result = await deployWorker(this, {
|
|
57
|
-
name: validatedName,
|
|
58
|
-
workerPath,
|
|
59
|
-
token,
|
|
60
|
-
environment,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (Result.isSuccess(result)) {
|
|
65
|
-
const { workerId } = Result.unwrap(result);
|
|
66
|
-
await this.config.update({ workerId });
|
|
67
|
-
this.io.writeErr("✓ Successfully deployed worker");
|
|
68
|
-
} else {
|
|
69
|
-
this.io.writeErr("✗ Failed to deploy worker");
|
|
70
|
-
this.io.writeErr(result.error.message);
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { buildCommand } from "@stricli/core";
|
|
2
|
-
import { globalFlags } from "../flags.js";
|
|
3
|
-
|
|
4
|
-
export default buildCommand({
|
|
5
|
-
docs: {
|
|
6
|
-
brief: "Deploy a worker to the Project Ajax platform",
|
|
7
|
-
},
|
|
8
|
-
|
|
9
|
-
parameters: {
|
|
10
|
-
flags: {
|
|
11
|
-
...globalFlags,
|
|
12
|
-
name: {
|
|
13
|
-
kind: "parsed",
|
|
14
|
-
parse: String,
|
|
15
|
-
brief: "The name of the worker (if it has not yet been created)",
|
|
16
|
-
optional: true,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
loader: () => import("./deploy.impl.js").then((m) => m.deploy),
|
|
22
|
-
});
|
|
@@ -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
|
-
});
|