@project-ajax/sdk 0.0.59 → 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/dist/builder.d.ts +6 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +4 -0
- package/dist/capabilities/sync.d.ts +10 -3
- package/dist/capabilities/sync.d.ts.map +1 -1
- package/dist/schema.d.ts +7 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +4 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -11
- package/src/builder.ts +15 -1
- package/src/capabilities/sync.ts +18 -3
- package/src/schema.ts +11 -2
- package/src/types.ts +15 -0
- 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
package/src/cli/api/client.ts
DELETED
|
@@ -1,628 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API client for making authenticated requests to the Workers API
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { IO } from "../io.js";
|
|
6
|
-
import { Result } from "./result.js";
|
|
7
|
-
|
|
8
|
-
export type Environment = "local" | "staging" | "dev" | "prod";
|
|
9
|
-
|
|
10
|
-
interface ApiClientConfig {
|
|
11
|
-
token: string;
|
|
12
|
-
environment: Environment;
|
|
13
|
-
baseUrl?: string | undefined;
|
|
14
|
-
cellId: string;
|
|
15
|
-
writer: IO;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type Endpoint = `/${string}`;
|
|
19
|
-
|
|
20
|
-
export interface ApiError {
|
|
21
|
-
status: number;
|
|
22
|
-
statusText: string;
|
|
23
|
-
message: string;
|
|
24
|
-
validationError?: {
|
|
25
|
-
errorId: string;
|
|
26
|
-
name: string;
|
|
27
|
-
debugMessage: string;
|
|
28
|
-
message: string;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* API client for making authenticated requests to Workers endpoints
|
|
34
|
-
*/
|
|
35
|
-
export class ApiClient {
|
|
36
|
-
readonly #token: string;
|
|
37
|
-
readonly #baseUrl: string | undefined;
|
|
38
|
-
readonly #cellId: string;
|
|
39
|
-
readonly #writer: IO;
|
|
40
|
-
|
|
41
|
-
constructor(config: ApiClientConfig) {
|
|
42
|
-
this.#token = config.token;
|
|
43
|
-
this.#baseUrl = config.baseUrl;
|
|
44
|
-
this.#cellId = config.cellId;
|
|
45
|
-
this.#writer = config.writer;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
#baseApiUrl() {
|
|
49
|
-
return `${this.#baseUrl}/api/v3`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Make an authenticated fetch request to the Workers API
|
|
54
|
-
*/
|
|
55
|
-
private async fetch(
|
|
56
|
-
endpoint: Endpoint,
|
|
57
|
-
requestOptions: Omit<RequestInit, "body"> & { body?: unknown },
|
|
58
|
-
options: { stream: true },
|
|
59
|
-
): Promise<Result<ReadableStream<Uint8Array<ArrayBufferLike>>, ApiError>>;
|
|
60
|
-
private async fetch<TResponse>(
|
|
61
|
-
endpoint: Endpoint,
|
|
62
|
-
requestOptions?: Omit<RequestInit, "body"> & { body?: unknown },
|
|
63
|
-
): Promise<Result<TResponse, ApiError>>;
|
|
64
|
-
private async fetch<TResponse>(
|
|
65
|
-
endpoint: Endpoint,
|
|
66
|
-
requestOptions: Omit<RequestInit, "body"> & { body?: unknown } = {},
|
|
67
|
-
options?: { stream: true },
|
|
68
|
-
): Promise<
|
|
69
|
-
Result<TResponse | ReadableStream<Uint8Array<ArrayBufferLike>>, ApiError>
|
|
70
|
-
> {
|
|
71
|
-
if (!endpoint.startsWith("/")) {
|
|
72
|
-
throw new Error("Endpoint must start with a slash (/)");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const url = `${this.#baseApiUrl()}${endpoint}`;
|
|
76
|
-
|
|
77
|
-
this.#writer.debug(`Fetching ${url}`);
|
|
78
|
-
this.#writer.debug(
|
|
79
|
-
`Options: ${JSON.stringify(requestOptions, null, "\t")}`,
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const headers = new Headers({
|
|
83
|
-
Authorization: `Bearer ${this.#token}`,
|
|
84
|
-
"Content-Type": "application/json",
|
|
85
|
-
"X-Notion-Cell": this.#cellId,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
const addlHeaders = headersInitToEntries(requestOptions.headers);
|
|
89
|
-
|
|
90
|
-
for (const [key, value] of addlHeaders) {
|
|
91
|
-
headers.append(key, value);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const response = await fetch(url, {
|
|
95
|
-
method: requestOptions.method ?? "GET",
|
|
96
|
-
headers,
|
|
97
|
-
body: requestOptions.body ? JSON.stringify(requestOptions.body) : null,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
this.#writer.debug(`Response: ${response.status} ${response.statusText}`);
|
|
101
|
-
|
|
102
|
-
if (!response.ok) {
|
|
103
|
-
const error = await parseApiError(response);
|
|
104
|
-
return Result.fail(error);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (options?.stream) {
|
|
108
|
-
if (!response.body) {
|
|
109
|
-
return Result.fail({
|
|
110
|
-
status: response.status,
|
|
111
|
-
statusText: response.statusText,
|
|
112
|
-
message: "No body in response",
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return Result.success(response.body);
|
|
117
|
-
} else {
|
|
118
|
-
const data = (await response.json()) as TResponse;
|
|
119
|
-
return Result.success(data);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Create a new worker
|
|
125
|
-
*/
|
|
126
|
-
async createWorker(name: string): Promise<
|
|
127
|
-
Result<
|
|
128
|
-
{
|
|
129
|
-
worker: {
|
|
130
|
-
workerId: string;
|
|
131
|
-
name: string;
|
|
132
|
-
spaceId: string;
|
|
133
|
-
createdAt: string;
|
|
134
|
-
updatedAt: string;
|
|
135
|
-
state: unknown;
|
|
136
|
-
};
|
|
137
|
-
url: string;
|
|
138
|
-
fields: Record<string, string>;
|
|
139
|
-
},
|
|
140
|
-
ApiError
|
|
141
|
-
>
|
|
142
|
-
> {
|
|
143
|
-
return this.fetch("/workersCreateWorker", {
|
|
144
|
-
method: "POST",
|
|
145
|
-
body: {
|
|
146
|
-
name,
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Update an existing worker's bundle
|
|
153
|
-
*/
|
|
154
|
-
async updateWorkerBundle(workerId: string): Promise<
|
|
155
|
-
Result<
|
|
156
|
-
{
|
|
157
|
-
url: string;
|
|
158
|
-
fields: Record<string, string>;
|
|
159
|
-
},
|
|
160
|
-
ApiError
|
|
161
|
-
>
|
|
162
|
-
> {
|
|
163
|
-
return this.fetch("/workersUpdateWorker", {
|
|
164
|
-
method: "POST",
|
|
165
|
-
body: {
|
|
166
|
-
workerId,
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Get a worker by ID
|
|
173
|
-
*/
|
|
174
|
-
async getWorker(workerId: string): Promise<
|
|
175
|
-
Result<
|
|
176
|
-
{
|
|
177
|
-
worker: {
|
|
178
|
-
workerId: string;
|
|
179
|
-
name: string;
|
|
180
|
-
spaceId: string;
|
|
181
|
-
state: unknown;
|
|
182
|
-
tools: unknown[];
|
|
183
|
-
createdAt: string;
|
|
184
|
-
updatedAt: string;
|
|
185
|
-
};
|
|
186
|
-
},
|
|
187
|
-
ApiError
|
|
188
|
-
>
|
|
189
|
-
> {
|
|
190
|
-
return this.fetch("/workersGetWorker", {
|
|
191
|
-
method: "POST",
|
|
192
|
-
body: {
|
|
193
|
-
workerId,
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* List all workers in the space
|
|
200
|
-
*/
|
|
201
|
-
async listWorkers(): Promise<
|
|
202
|
-
Result<
|
|
203
|
-
{
|
|
204
|
-
workers: Array<{
|
|
205
|
-
workerId: string;
|
|
206
|
-
name: string;
|
|
207
|
-
spaceId: string;
|
|
208
|
-
state: unknown;
|
|
209
|
-
createdAt: string;
|
|
210
|
-
updatedAt: string;
|
|
211
|
-
}>;
|
|
212
|
-
},
|
|
213
|
-
ApiError
|
|
214
|
-
>
|
|
215
|
-
> {
|
|
216
|
-
return this.fetch("/workersListWorkers", {
|
|
217
|
-
method: "POST",
|
|
218
|
-
body: {},
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Delete a worker
|
|
224
|
-
*/
|
|
225
|
-
async deleteWorker(
|
|
226
|
-
workerId: string,
|
|
227
|
-
): Promise<Result<Record<string, never>, ApiError>> {
|
|
228
|
-
return this.fetch("/workersDeleteWorker", {
|
|
229
|
-
method: "POST",
|
|
230
|
-
body: {
|
|
231
|
-
workerId,
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Fetch and save worker capabilities
|
|
238
|
-
*/
|
|
239
|
-
async fetchAndSaveCapabilities(workerId: string): Promise<
|
|
240
|
-
Result<
|
|
241
|
-
{
|
|
242
|
-
capabilities: ReadonlyArray<{
|
|
243
|
-
_tag: "sync" | "slashCommand";
|
|
244
|
-
spaceId: string;
|
|
245
|
-
workerId: string;
|
|
246
|
-
key: string;
|
|
247
|
-
config: unknown;
|
|
248
|
-
}>;
|
|
249
|
-
},
|
|
250
|
-
ApiError
|
|
251
|
-
>
|
|
252
|
-
> {
|
|
253
|
-
return this.fetch("/workersFetchAndSaveCapabilities", {
|
|
254
|
-
method: "POST",
|
|
255
|
-
body: {
|
|
256
|
-
workerId,
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Upsert secrets (create or update multiple secrets)
|
|
263
|
-
*/
|
|
264
|
-
async upsertSecrets(
|
|
265
|
-
workerId: string,
|
|
266
|
-
secrets: Array<{ key: string; value: string }>,
|
|
267
|
-
): Promise<
|
|
268
|
-
Result<
|
|
269
|
-
{
|
|
270
|
-
secrets: Array<{
|
|
271
|
-
spaceId: string;
|
|
272
|
-
workerId: string;
|
|
273
|
-
key: string;
|
|
274
|
-
createdAt: string;
|
|
275
|
-
}>;
|
|
276
|
-
},
|
|
277
|
-
ApiError
|
|
278
|
-
>
|
|
279
|
-
> {
|
|
280
|
-
return this.fetch("/workersUpsertSecrets", {
|
|
281
|
-
method: "POST",
|
|
282
|
-
body: {
|
|
283
|
-
workerId,
|
|
284
|
-
secrets,
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* List all secrets for a worker (keys only, not values)
|
|
291
|
-
*/
|
|
292
|
-
async listSecrets(
|
|
293
|
-
workerId: string,
|
|
294
|
-
options?: { secretKinds?: Array<"keyValue" | "oauth"> },
|
|
295
|
-
): Promise<
|
|
296
|
-
Result<
|
|
297
|
-
{
|
|
298
|
-
secrets: Array<{
|
|
299
|
-
spaceId: string;
|
|
300
|
-
workerId: string;
|
|
301
|
-
key: string;
|
|
302
|
-
createdAt: string;
|
|
303
|
-
kind: "keyValue" | "oauth";
|
|
304
|
-
}>;
|
|
305
|
-
},
|
|
306
|
-
ApiError
|
|
307
|
-
>
|
|
308
|
-
> {
|
|
309
|
-
return this.fetch("/workersListSecrets", {
|
|
310
|
-
method: "POST",
|
|
311
|
-
body: {
|
|
312
|
-
workerId,
|
|
313
|
-
secretKinds: options?.secretKinds,
|
|
314
|
-
},
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Pull decrypted env vars for a worker
|
|
320
|
-
*/
|
|
321
|
-
async pullEnv(workerId: string): Promise<
|
|
322
|
-
Result<
|
|
323
|
-
{
|
|
324
|
-
env: Array<{
|
|
325
|
-
key: string;
|
|
326
|
-
value: string;
|
|
327
|
-
}>;
|
|
328
|
-
},
|
|
329
|
-
ApiError
|
|
330
|
-
>
|
|
331
|
-
> {
|
|
332
|
-
return this.fetch("/workersPullEnv", {
|
|
333
|
-
method: "POST",
|
|
334
|
-
body: {
|
|
335
|
-
workerId,
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
async listOauthProviders(): Promise<
|
|
341
|
-
Result<
|
|
342
|
-
{
|
|
343
|
-
providers: Array<{
|
|
344
|
-
key: string;
|
|
345
|
-
displayName: string;
|
|
346
|
-
}>;
|
|
347
|
-
},
|
|
348
|
-
ApiError
|
|
349
|
-
>
|
|
350
|
-
> {
|
|
351
|
-
return this.fetch("/workersListOauthProviders", {
|
|
352
|
-
method: "POST",
|
|
353
|
-
body: {},
|
|
354
|
-
});
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Start the OAuth flow for a provider
|
|
359
|
-
*/
|
|
360
|
-
async startOauth(args: { workerId: string; provider: string }): Promise<
|
|
361
|
-
Result<
|
|
362
|
-
{
|
|
363
|
-
authorizationUrl: string;
|
|
364
|
-
state: string;
|
|
365
|
-
},
|
|
366
|
-
ApiError
|
|
367
|
-
>
|
|
368
|
-
> {
|
|
369
|
-
return this.fetch("/workersStartOauth", {
|
|
370
|
-
method: "POST",
|
|
371
|
-
body: {
|
|
372
|
-
workerId: args.workerId,
|
|
373
|
-
provider: args.provider,
|
|
374
|
-
},
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
/**
|
|
379
|
-
* Remove an OAuth connection for a worker
|
|
380
|
-
*/
|
|
381
|
-
async deleteOauthConnection(args: {
|
|
382
|
-
workerId: string;
|
|
383
|
-
provider: string;
|
|
384
|
-
}): Promise<Result<Record<string, never>, ApiError>> {
|
|
385
|
-
return this.fetch("/workersDeleteOauthConnection", {
|
|
386
|
-
method: "POST",
|
|
387
|
-
body: {
|
|
388
|
-
workerId: args.workerId,
|
|
389
|
-
provider: args.provider,
|
|
390
|
-
},
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* Delete a secret
|
|
396
|
-
*/
|
|
397
|
-
async deleteSecret(
|
|
398
|
-
workerId: string,
|
|
399
|
-
key: string,
|
|
400
|
-
): Promise<Result<Record<string, never>, ApiError>> {
|
|
401
|
-
return this.fetch("/workersDeleteSecret", {
|
|
402
|
-
method: "POST",
|
|
403
|
-
body: {
|
|
404
|
-
workerId,
|
|
405
|
-
key,
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* List all capabilities for a worker
|
|
412
|
-
*/
|
|
413
|
-
async listCapabilities(workerId: string): Promise<
|
|
414
|
-
Result<
|
|
415
|
-
{
|
|
416
|
-
capabilities: Array<{
|
|
417
|
-
_tag: "sync" | "slashCommand";
|
|
418
|
-
key: string;
|
|
419
|
-
}>;
|
|
420
|
-
},
|
|
421
|
-
ApiError
|
|
422
|
-
>
|
|
423
|
-
> {
|
|
424
|
-
return this.fetch("/workersListCapabilities", {
|
|
425
|
-
method: "POST",
|
|
426
|
-
body: {
|
|
427
|
-
workerId,
|
|
428
|
-
},
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Run a capability
|
|
434
|
-
*/
|
|
435
|
-
async runCapability(
|
|
436
|
-
workerId: string,
|
|
437
|
-
capabilityKey: string,
|
|
438
|
-
functionName: string | null,
|
|
439
|
-
args: Array<{ name: string; value: string }>,
|
|
440
|
-
stream: true,
|
|
441
|
-
): Promise<Result<ReadableStream<Uint8Array<ArrayBufferLike>>, ApiError>>;
|
|
442
|
-
async runCapability(
|
|
443
|
-
workerId: string,
|
|
444
|
-
capabilityKey: string,
|
|
445
|
-
functionName: string | null,
|
|
446
|
-
args: Array<{ name: string; value: string }>,
|
|
447
|
-
stream?: false | undefined,
|
|
448
|
-
): Promise<Result<{ result: unknown }, ApiError>>;
|
|
449
|
-
async runCapability(
|
|
450
|
-
workerId: string,
|
|
451
|
-
capabilityKey: string,
|
|
452
|
-
functionName: string | null,
|
|
453
|
-
args: Array<{ name: string; value: string }>,
|
|
454
|
-
stream?: boolean | undefined,
|
|
455
|
-
): Promise<
|
|
456
|
-
Result<
|
|
457
|
-
{ result: unknown } | ReadableStream<Uint8Array<ArrayBufferLike>>,
|
|
458
|
-
ApiError
|
|
459
|
-
>
|
|
460
|
-
> {
|
|
461
|
-
if (stream) {
|
|
462
|
-
return this.fetch(
|
|
463
|
-
"/workersRunCapability",
|
|
464
|
-
{
|
|
465
|
-
method: "POST",
|
|
466
|
-
body: {
|
|
467
|
-
workerId,
|
|
468
|
-
capabilityKey,
|
|
469
|
-
functionName,
|
|
470
|
-
args,
|
|
471
|
-
stream,
|
|
472
|
-
},
|
|
473
|
-
},
|
|
474
|
-
{ stream },
|
|
475
|
-
);
|
|
476
|
-
} else {
|
|
477
|
-
return this.fetch("/workersRunCapability", {
|
|
478
|
-
method: "POST",
|
|
479
|
-
body: {
|
|
480
|
-
workerId,
|
|
481
|
-
capabilityKey,
|
|
482
|
-
functionName,
|
|
483
|
-
args,
|
|
484
|
-
stream,
|
|
485
|
-
},
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Download the bundle for a worker
|
|
492
|
-
*/
|
|
493
|
-
async downloadWorkerBundle(
|
|
494
|
-
workerId: string,
|
|
495
|
-
): Promise<Result<ReadableStream<Uint8Array<ArrayBufferLike>>, ApiError>> {
|
|
496
|
-
return this.fetch(
|
|
497
|
-
"/workersGetBundle",
|
|
498
|
-
{
|
|
499
|
-
method: "POST",
|
|
500
|
-
body: {
|
|
501
|
-
workerId,
|
|
502
|
-
},
|
|
503
|
-
},
|
|
504
|
-
{ stream: true },
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
* List all runs for a worker
|
|
510
|
-
*/
|
|
511
|
-
async listRunsForWorker(workerId: string): Promise<
|
|
512
|
-
Result<
|
|
513
|
-
{
|
|
514
|
-
runs: Array<{
|
|
515
|
-
workerId: string;
|
|
516
|
-
spaceId: string;
|
|
517
|
-
runId: string;
|
|
518
|
-
name: string;
|
|
519
|
-
exitCode: number | null;
|
|
520
|
-
startedAt: string;
|
|
521
|
-
endedAt: string | null;
|
|
522
|
-
}>;
|
|
523
|
-
},
|
|
524
|
-
ApiError
|
|
525
|
-
>
|
|
526
|
-
> {
|
|
527
|
-
return this.fetch("/workersListRunsForWorker", {
|
|
528
|
-
method: "POST",
|
|
529
|
-
body: {
|
|
530
|
-
workerId,
|
|
531
|
-
},
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* Get logs for a specific run
|
|
537
|
-
*/
|
|
538
|
-
async getRunLogs(
|
|
539
|
-
workerId: string,
|
|
540
|
-
runId: string,
|
|
541
|
-
): Promise<
|
|
542
|
-
Result<
|
|
543
|
-
{
|
|
544
|
-
logs: string;
|
|
545
|
-
},
|
|
546
|
-
ApiError
|
|
547
|
-
>
|
|
548
|
-
> {
|
|
549
|
-
return this.fetch("/workersGetRunLogs", {
|
|
550
|
-
method: "POST",
|
|
551
|
-
body: {
|
|
552
|
-
workerId,
|
|
553
|
-
runId,
|
|
554
|
-
},
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
function headersInitToEntries(
|
|
560
|
-
headersInit: RequestInit["headers"],
|
|
561
|
-
): [string, string][] {
|
|
562
|
-
if (headersInit instanceof Headers) {
|
|
563
|
-
return Array.from(headersInit.entries());
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
if (Array.isArray(headersInit)) {
|
|
567
|
-
return headersInit;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
if (headersInit === undefined) {
|
|
571
|
-
return [];
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
const entries: [string, string][] = [];
|
|
575
|
-
for (const [key, value] of Object.entries(headersInit)) {
|
|
576
|
-
if (value === undefined) {
|
|
577
|
-
continue;
|
|
578
|
-
}
|
|
579
|
-
entries.push([key, value]);
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
return entries;
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
async function parseApiError(response: Response): Promise<ApiError> {
|
|
586
|
-
const errorText = await response.text();
|
|
587
|
-
const message = `[${response.status}] ${response.statusText}: ${errorText}`;
|
|
588
|
-
const error: ApiError = {
|
|
589
|
-
status: response.status,
|
|
590
|
-
statusText: response.statusText,
|
|
591
|
-
message,
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
if (response.status === 400) {
|
|
595
|
-
const validationError = parseValidationError(errorText);
|
|
596
|
-
if (validationError) {
|
|
597
|
-
error.validationError = validationError;
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
return error;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* Try to parse a ValidationError from error response text
|
|
606
|
-
*/
|
|
607
|
-
function parseValidationError(
|
|
608
|
-
errorText: string,
|
|
609
|
-
): ApiError["validationError"] | undefined {
|
|
610
|
-
try {
|
|
611
|
-
const errorJson = JSON.parse(errorText);
|
|
612
|
-
if (
|
|
613
|
-
errorJson.name === "ValidationError" &&
|
|
614
|
-
errorJson.debugMessage &&
|
|
615
|
-
errorJson.errorId
|
|
616
|
-
) {
|
|
617
|
-
return {
|
|
618
|
-
errorId: errorJson.errorId,
|
|
619
|
-
name: errorJson.name,
|
|
620
|
-
debugMessage: errorJson.debugMessage,
|
|
621
|
-
message: errorJson.message,
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
} catch {
|
|
625
|
-
// If parsing fails, return undefined
|
|
626
|
-
}
|
|
627
|
-
return undefined;
|
|
628
|
-
}
|
package/src/cli/api/result.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the union of *either* the value returned
|
|
3
|
-
* from some function *or* an arbitrary error emitted during computation.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* The left side of the Result type, the value.
|
|
8
|
-
*/
|
|
9
|
-
export interface Success<T> {
|
|
10
|
-
_tag: "success";
|
|
11
|
-
value: T;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The right side of the Result type, the error.
|
|
16
|
-
*/
|
|
17
|
-
export interface Fail<E> {
|
|
18
|
-
_tag: "fail";
|
|
19
|
-
error: E;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type Result<S, E> = Success<S> | Fail<E>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Type predicates and helpers for the Result type.
|
|
26
|
-
*/
|
|
27
|
-
export const Result = {
|
|
28
|
-
success<S>(value: S): Success<S> {
|
|
29
|
-
return { _tag: "success", value };
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
fail<E>(error: E): Fail<E> {
|
|
33
|
-
return { _tag: "fail", error };
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Success (left side) type predicate for the Result type.
|
|
38
|
-
*/
|
|
39
|
-
isSuccess<S, E>(result: Result<S, E>): result is Success<S> {
|
|
40
|
-
return result._tag === "success";
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Fail (right side) type predicate for the Result type.
|
|
45
|
-
*/
|
|
46
|
-
isFail<S, E>(result: Result<S, E>): result is Fail<E> {
|
|
47
|
-
return result._tag === "fail";
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Unwrap a Result value, throwing the error if it's set.
|
|
52
|
-
*/
|
|
53
|
-
unwrap<S, E>(result: Result<S, E>): S {
|
|
54
|
-
if (Result.isFail(result)) {
|
|
55
|
-
throw result.error;
|
|
56
|
-
} else {
|
|
57
|
-
return result.value;
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Unwrap a Result value, or return a default value if an error is set.
|
|
63
|
-
*/
|
|
64
|
-
unwrapOr<S, E>(result: Result<S, E>, defaultValue: S): S {
|
|
65
|
-
if (Result.isFail(result)) {
|
|
66
|
-
return defaultValue;
|
|
67
|
-
} else {
|
|
68
|
-
return result.value;
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
};
|
package/src/cli/bin/cli.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { run } from "@stricli/core";
|
|
3
|
-
import { buildContext } from "../context.js";
|
|
4
|
-
import { app } from "../routes.js";
|
|
5
|
-
|
|
6
|
-
// @ts-expect-error // stricli violates exactOptionalPropertyTypes
|
|
7
|
-
await run(app, process.argv.slice(2), buildContext(process));
|