@project-ajax/sdk 0.0.55 → 0.0.56
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/cli/api/client.d.ts +2 -2
- package/dist/cli/api/client.d.ts.map +1 -1
- package/dist/cli/commands/auth.impl.js +6 -6
- package/dist/cli/commands/bundle.impl.js +2 -2
- package/dist/cli/commands/capabilities.impl.js +4 -4
- package/dist/cli/commands/connect.impl.js +13 -13
- package/dist/cli/commands/deploy.impl.d.ts.map +1 -1
- package/dist/cli/commands/deploy.impl.js +10 -16
- package/dist/cli/commands/env.impl.d.ts.map +1 -1
- package/dist/cli/commands/env.impl.js +7 -10
- package/dist/cli/commands/exec.impl.d.ts.map +1 -1
- package/dist/cli/commands/exec.impl.js +14 -16
- package/dist/cli/commands/runs.impl.js +7 -7
- package/dist/cli/commands/secrets.impl.js +12 -12
- package/dist/cli/commands/utils/testing.d.ts +2 -11
- package/dist/cli/commands/utils/testing.d.ts.map +1 -1
- package/dist/cli/commands/utils/testing.js +4 -4
- package/dist/cli/context.d.ts +2 -2
- package/dist/cli/context.d.ts.map +1 -1
- package/dist/cli/context.js +3 -3
- package/dist/cli/deploy.js +11 -11
- package/dist/cli/handler.js +2 -2
- package/dist/cli/{writer.d.ts → io.d.ts} +10 -3
- package/dist/cli/io.d.ts.map +1 -0
- package/dist/cli/{writer.js → io.js} +24 -2
- package/package.json +3 -3
- package/src/cli/api/client.ts +3 -3
- package/src/cli/commands/auth.impl.ts +6 -6
- package/src/cli/commands/bundle.impl.ts +2 -2
- package/src/cli/commands/capabilities.impl.ts +4 -4
- package/src/cli/commands/connect.impl.ts +13 -13
- package/src/cli/commands/deploy.impl.test.ts +9 -14
- package/src/cli/commands/deploy.impl.ts +11 -16
- package/src/cli/commands/env.impl.ts +7 -11
- package/src/cli/commands/exec.impl.ts +14 -16
- package/src/cli/commands/runs.impl.ts +7 -7
- package/src/cli/commands/secrets.impl.ts +12 -12
- package/src/cli/commands/utils/testing.ts +5 -4
- package/src/cli/context.ts +3 -3
- package/src/cli/deploy.ts +11 -11
- package/src/cli/handler.ts +2 -2
- package/src/cli/{writer.ts → io.ts} +34 -2
- package/dist/cli/writer.d.ts.map +0 -1
package/dist/cli/api/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* API client for making authenticated requests to the Workers API
|
|
3
3
|
*/
|
|
4
|
-
import type {
|
|
4
|
+
import type { IO } from "../io.js";
|
|
5
5
|
import { Result } from "./result.js";
|
|
6
6
|
export type Environment = "local" | "staging" | "dev" | "prod";
|
|
7
7
|
interface ApiClientConfig {
|
|
@@ -9,7 +9,7 @@ interface ApiClientConfig {
|
|
|
9
9
|
environment: Environment;
|
|
10
10
|
baseUrl?: string | undefined;
|
|
11
11
|
cellId: string;
|
|
12
|
-
writer:
|
|
12
|
+
writer: IO;
|
|
13
13
|
}
|
|
14
14
|
export interface ApiError {
|
|
15
15
|
status: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/cli/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/cli/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAAC;AAE/D,UAAU,eAAe;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,EAAE,CAAC;CACX;AAID,MAAM,WAAW,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ACjD,MAAM,CACL;QACC,IAAI,EAAE,KAAK,CAAC;YACX,QAAQ,EAAE,MAAM,CAAC;YACjB,OAAO,EAAE,MAAM,CAAC;YAChB,KAAK,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;YACxB,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;SACvB,CAAC,CAAC;KACH,EACD,QAAQ,CACR,CACD;IASD;;OAEG;IACG,UAAU,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACX,OAAO,CACT,MAAM,CACL;QACC,IAAI,EAAE,MAAM,CAAC;KACb,EACD,QAAQ,CACR,CACD;CASD"}
|
|
@@ -4,15 +4,15 @@ const login = buildHandler(async function(_, token) {
|
|
|
4
4
|
const environment = this.config.environment;
|
|
5
5
|
if (!token) {
|
|
6
6
|
const url = `${this.config.baseUrl}/__workers__?createToken=true`;
|
|
7
|
-
this.
|
|
7
|
+
this.io.writeErr(`Opening browser to create a token...
|
|
8
8
|
${url}
|
|
9
9
|
`);
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
10
|
+
this.io.writeErr("After creating a token, run:");
|
|
11
|
+
this.io.writeErr(" npx workers auth login <token>");
|
|
12
12
|
try {
|
|
13
13
|
await openNotionUrl(environment, url);
|
|
14
14
|
} catch (_error) {
|
|
15
|
-
this.
|
|
15
|
+
this.io.writeErr(
|
|
16
16
|
`Failed to open browser automatically. Please visit:
|
|
17
17
|
${url}`
|
|
18
18
|
);
|
|
@@ -24,10 +24,10 @@ ${url}
|
|
|
24
24
|
token,
|
|
25
25
|
workerId: null
|
|
26
26
|
});
|
|
27
|
-
this.
|
|
27
|
+
this.io.writeErr("Successfully logged in!");
|
|
28
28
|
});
|
|
29
29
|
const show = buildHandler(function() {
|
|
30
|
-
this.
|
|
30
|
+
this.io.writeOut(`${this.config.token ?? ""}`);
|
|
31
31
|
});
|
|
32
32
|
const logout = buildHandler(async function() {
|
|
33
33
|
await this.config.update({
|
|
@@ -10,8 +10,8 @@ const downloadBundle = buildAuthedHandler(async function() {
|
|
|
10
10
|
}
|
|
11
11
|
const result = await this.apiClient.downloadWorkerBundle(workerId);
|
|
12
12
|
if (Result.isFail(result)) {
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
13
|
+
this.io.writeErr(`\u2717 Failed to download bundle`);
|
|
14
|
+
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
Readable.fromWeb(result.value).pipe(this.process.stdout);
|
|
@@ -13,9 +13,9 @@ const listCapabilities = buildAuthedHandler(async function(flags) {
|
|
|
13
13
|
this.process.stderr.write("OK\n\n");
|
|
14
14
|
const data = Result.unwrap(result);
|
|
15
15
|
if (data.capabilities.length === 0) {
|
|
16
|
-
this.
|
|
16
|
+
this.io.writeErr("No capabilities found for this worker.");
|
|
17
17
|
} else {
|
|
18
|
-
this.
|
|
18
|
+
this.io.writeTableOut({
|
|
19
19
|
headers: ["Key", "Tag"],
|
|
20
20
|
rows: data.capabilities.map((capability) => [
|
|
21
21
|
capability.key,
|
|
@@ -27,10 +27,10 @@ const listCapabilities = buildAuthedHandler(async function(flags) {
|
|
|
27
27
|
} else {
|
|
28
28
|
this.process.stderr.write("ERROR\n\n");
|
|
29
29
|
if (result.error.validationError) {
|
|
30
|
-
this.
|
|
30
|
+
this.io.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
|
|
31
31
|
throw new Error(result.error.validationError.debugMessage);
|
|
32
32
|
} else {
|
|
33
|
-
this.
|
|
33
|
+
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
34
34
|
throw new Error(result.error.message);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -11,10 +11,10 @@ const listProviders = buildAuthedHandler(async function(flags) {
|
|
|
11
11
|
this.process.stderr.write("OK\n\n");
|
|
12
12
|
const providers = providersResult.value.providers;
|
|
13
13
|
if (providers.length === 0) {
|
|
14
|
-
this.
|
|
14
|
+
this.io.writeErr("No OAuth providers are currently available.");
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
this.
|
|
17
|
+
this.io.writeTableOut({
|
|
18
18
|
headers: ["Provider", "Description"],
|
|
19
19
|
rows: providers.map((provider) => [provider.key, provider.displayName]),
|
|
20
20
|
plain: flags.plain
|
|
@@ -34,21 +34,21 @@ const addConnection = buildAuthedHandler(async function(_flags, provider) {
|
|
|
34
34
|
}
|
|
35
35
|
this.process.stderr.write("OK\n\n");
|
|
36
36
|
const { authorizationUrl } = startResult.value;
|
|
37
|
-
this.
|
|
37
|
+
this.io.writeErr("Opening your browser to continue the OAuth flow...");
|
|
38
38
|
try {
|
|
39
39
|
await openBrowserUrl(authorizationUrl);
|
|
40
40
|
} catch (error) {
|
|
41
|
-
this.
|
|
41
|
+
this.io.writeErr(
|
|
42
42
|
`Unable to open the browser automatically (${String(
|
|
43
43
|
error
|
|
44
44
|
)}). Please open the link below manually.`
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
47
|
+
this.io.writeErr("");
|
|
48
|
+
this.io.writeErr("If the browser did not open, visit:");
|
|
49
|
+
this.io.writeErr(` ${authorizationUrl}`);
|
|
50
|
+
this.io.writeErr("");
|
|
51
|
+
this.io.writeErr(
|
|
52
52
|
"After completing the flow in your browser, return to the CLI."
|
|
53
53
|
);
|
|
54
54
|
});
|
|
@@ -66,10 +66,10 @@ const listConnections = buildAuthedHandler(async function(flags) {
|
|
|
66
66
|
this.process.stderr.write("OK\n\n");
|
|
67
67
|
const secrets = secretsResult.value.secrets;
|
|
68
68
|
if (secrets.length === 0) {
|
|
69
|
-
this.
|
|
69
|
+
this.io.writeErr("No OAuth connections found for this worker.");
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
this.
|
|
72
|
+
this.io.writeTableOut({
|
|
73
73
|
headers: ["Env Var", "Created At"],
|
|
74
74
|
rows: secrets.map((secret) => [
|
|
75
75
|
`process.env.${secret.key}`,
|
|
@@ -104,8 +104,8 @@ function requireWorkerId(context) {
|
|
|
104
104
|
return workerId;
|
|
105
105
|
}
|
|
106
106
|
function reportApiError(context, error, action) {
|
|
107
|
-
context.
|
|
108
|
-
context.
|
|
107
|
+
context.io.writeErr(`\u2717 Failed to ${action}`);
|
|
108
|
+
context.io.writeErr(`\u2717 ${error.message}`);
|
|
109
109
|
throw new Error(error.message);
|
|
110
110
|
}
|
|
111
111
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.impl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.impl.ts"],"names":[],"mappings":"AAKA,UAAU,WAAW;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,MAAM,uHA+DjB,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import prompts from "prompts";
|
|
2
1
|
import { Result } from "../api/result.js";
|
|
3
2
|
import { deployWorker } from "../deploy.js";
|
|
4
3
|
import { buildAuthedHandler } from "../handler.js";
|
|
@@ -10,7 +9,7 @@ const deploy = buildAuthedHandler(async function(flags) {
|
|
|
10
9
|
throw new Error("Unexpected error: Environment not set");
|
|
11
10
|
}
|
|
12
11
|
const workerPath = this.process.cwd();
|
|
13
|
-
this.
|
|
12
|
+
this.io.writeErr("Deploying worker...");
|
|
14
13
|
const name = flags.name;
|
|
15
14
|
if (workerId && name) {
|
|
16
15
|
throw new Error("Cannot specify a name when updating an existing worker");
|
|
@@ -28,21 +27,16 @@ const deploy = buildAuthedHandler(async function(flags) {
|
|
|
28
27
|
if (name) {
|
|
29
28
|
validatedName = name;
|
|
30
29
|
} else {
|
|
31
|
-
const
|
|
32
|
-
type: "text",
|
|
33
|
-
name: "name",
|
|
30
|
+
const nameInput = await this.io.input({
|
|
34
31
|
message: "Enter a name for the worker",
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return "Name is required";
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
32
|
+
required: true,
|
|
33
|
+
noTTY: "Provide a name for the worker with --name"
|
|
41
34
|
});
|
|
42
|
-
|
|
35
|
+
const trimmedName = nameInput?.trim();
|
|
36
|
+
if (!trimmedName) {
|
|
43
37
|
throw new Error("Name is required");
|
|
44
38
|
}
|
|
45
|
-
validatedName =
|
|
39
|
+
validatedName = trimmedName;
|
|
46
40
|
}
|
|
47
41
|
result = await deployWorker(this, {
|
|
48
42
|
name: validatedName,
|
|
@@ -54,10 +48,10 @@ const deploy = buildAuthedHandler(async function(flags) {
|
|
|
54
48
|
if (Result.isSuccess(result)) {
|
|
55
49
|
const { workerId: workerId2 } = Result.unwrap(result);
|
|
56
50
|
await this.config.update({ workerId: workerId2 });
|
|
57
|
-
this.
|
|
51
|
+
this.io.writeErr("\u2713 Successfully deployed worker");
|
|
58
52
|
} else {
|
|
59
|
-
this.
|
|
60
|
-
this.
|
|
53
|
+
this.io.writeErr("\u2717 Failed to deploy worker");
|
|
54
|
+
this.io.writeErr(result.error.message);
|
|
61
55
|
return;
|
|
62
56
|
}
|
|
63
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/env.impl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/env.impl.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC5B,GAAG,EAAE,OAAO,CAAC;CACb;AAED,eAAO,MAAM,gBAAgB,SAAS,CAAC;AAEvC,eAAO,MAAM,OAAO,uJAiDlB,CAAC;AAEH,wBAAgB,gBAAgB,CAC/B,UAAU,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAC/C,MAAM,CASR;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAapD"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import prompts from "prompts";
|
|
2
1
|
import { Result } from "../api/result.js";
|
|
3
2
|
import { buildAuthedHandler } from "../handler.js";
|
|
4
3
|
import { pluralize } from "../utils/string.js";
|
|
@@ -16,22 +15,20 @@ const pullEnv = buildAuthedHandler(async function(flags, filePath) {
|
|
|
16
15
|
destination
|
|
17
16
|
);
|
|
18
17
|
if (this.fs.existsSync(absoluteDestination) && !flags.yes) {
|
|
19
|
-
const
|
|
20
|
-
type: "confirm",
|
|
21
|
-
name: "overwrite",
|
|
18
|
+
const overwrite = await this.io.confirm({
|
|
22
19
|
message: `File "${destination}" already exists. Overwrite it?`,
|
|
23
|
-
|
|
20
|
+
noTTY: `File "${destination}" already exists.`
|
|
24
21
|
});
|
|
25
22
|
if (overwrite !== true) {
|
|
26
|
-
this.
|
|
23
|
+
this.io.writeErr("Aborted.");
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
|
-
this.
|
|
27
|
+
this.io.writeErr("Fetching environment variables...");
|
|
31
28
|
const envResult = await this.apiClient.pullEnv(workerId);
|
|
32
29
|
if (Result.isFail(envResult)) {
|
|
33
|
-
this.
|
|
34
|
-
this.
|
|
30
|
+
this.io.writeErr("\u2717 Failed to fetch env vars");
|
|
31
|
+
this.io.writeErr(`\u2717 ${envResult.error.message}`);
|
|
35
32
|
throw new Error(envResult.error.message);
|
|
36
33
|
}
|
|
37
34
|
const envEntries = envResult.value.env;
|
|
@@ -40,7 +37,7 @@ const pullEnv = buildAuthedHandler(async function(flags, filePath) {
|
|
|
40
37
|
recursive: true
|
|
41
38
|
});
|
|
42
39
|
await this.fs.promises.writeFile(absoluteDestination, fileContents, "utf8");
|
|
43
|
-
this.
|
|
40
|
+
this.io.writeErr(
|
|
44
41
|
`Wrote ${pluralize(envEntries.length, "env var")} to "${destination}"`
|
|
45
42
|
);
|
|
46
43
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/exec.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM/C,UAAU,SAAU,SAAQ,WAAW;IACtC,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,IAAI,
|
|
1
|
+
{"version":3,"file":"exec.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/exec.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM/C,UAAU,SAAU,SAAQ,WAAW;IACtC,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,IAAI,2HA2Jf,CAAC"}
|
|
@@ -27,7 +27,7 @@ const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
|
27
27
|
value
|
|
28
28
|
};
|
|
29
29
|
});
|
|
30
|
-
this.
|
|
30
|
+
this.io.writeErr(`Executing capability "${capabilityName}"...`);
|
|
31
31
|
if (flags.stream) {
|
|
32
32
|
const result = await this.apiClient.runCapability(
|
|
33
33
|
workerId,
|
|
@@ -52,20 +52,20 @@ const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
|
52
52
|
allOutput.push(parsedLine.event.data);
|
|
53
53
|
}
|
|
54
54
|
parsedLine.event.data.trim().split("\n").forEach((dataLine) => {
|
|
55
|
-
this.
|
|
55
|
+
this.io.writeErr(
|
|
56
56
|
`[worker:${parsedLine.event.stream}] ${dataLine.trim()}`
|
|
57
57
|
);
|
|
58
58
|
});
|
|
59
59
|
break;
|
|
60
60
|
case "result":
|
|
61
|
-
this.
|
|
61
|
+
this.io.writeOut(JSON.stringify(parsedLine.result, null, 2));
|
|
62
62
|
break;
|
|
63
63
|
case "error":
|
|
64
|
-
this.
|
|
64
|
+
this.io.writeErr(`Error: ${parsedLine.error}`);
|
|
65
65
|
break;
|
|
66
66
|
}
|
|
67
67
|
} catch (error) {
|
|
68
|
-
this.
|
|
68
|
+
this.io.writeErr(`Error parsing log line: ${jsonLine}: ${error}`);
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
for await (const log of result.value) {
|
|
@@ -82,19 +82,17 @@ const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
|
82
82
|
}
|
|
83
83
|
return;
|
|
84
84
|
} else {
|
|
85
|
-
this.
|
|
85
|
+
this.io.writeErr(`
|
|
86
86
|
\u2717 Failed to execute capability`);
|
|
87
87
|
if (result.error.validationError) {
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
|
|
91
|
-
);
|
|
92
|
-
this.writer.writeErr(`
|
|
88
|
+
this.io.writeErr(` \u2717 HTTP Error: ${result.error.status}`);
|
|
89
|
+
this.io.writeErr(` \u2717 ${result.error.validationError.debugMessage}`);
|
|
90
|
+
this.io.writeErr(`
|
|
93
91
|
${usageHint}`);
|
|
94
92
|
throw new Error(result.error.validationError.debugMessage);
|
|
95
93
|
} else {
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
94
|
+
this.io.writeErr(` \u2717 HTTP Error: ${result.error.status}`);
|
|
95
|
+
this.io.writeErr(` \u2717 ${result.error.message}`);
|
|
98
96
|
throw new Error(result.error.message);
|
|
99
97
|
}
|
|
100
98
|
}
|
|
@@ -108,11 +106,11 @@ ${usageHint}`);
|
|
|
108
106
|
);
|
|
109
107
|
if (Result.isSuccess(result)) {
|
|
110
108
|
const data = Result.unwrap(result);
|
|
111
|
-
this.
|
|
109
|
+
this.io.writeOut(JSON.stringify(data.result, null, 2));
|
|
112
110
|
} else {
|
|
113
|
-
this.
|
|
111
|
+
this.io.writeErr(`
|
|
114
112
|
\u2717 Failed to execute capability`);
|
|
115
|
-
this.
|
|
113
|
+
this.io.writeErr(` \u2717 ${result.error.message}`);
|
|
116
114
|
throw new Error(result.error.message);
|
|
117
115
|
}
|
|
118
116
|
}
|
|
@@ -13,9 +13,9 @@ const listRuns = buildAuthedHandler(async function(flags) {
|
|
|
13
13
|
this.process.stderr.write("OK\n\n");
|
|
14
14
|
const data = Result.unwrap(result);
|
|
15
15
|
if (data.runs.length === 0) {
|
|
16
|
-
this.
|
|
16
|
+
this.io.writeErr("No runs found for this worker.");
|
|
17
17
|
} else {
|
|
18
|
-
this.
|
|
18
|
+
this.io.writeTableOut({
|
|
19
19
|
headers: ["Run ID", "Name", "Started At", "Ended At", "Exit Code"],
|
|
20
20
|
rows: data.runs.map((run) => [
|
|
21
21
|
run.runId,
|
|
@@ -30,10 +30,10 @@ const listRuns = buildAuthedHandler(async function(flags) {
|
|
|
30
30
|
} else {
|
|
31
31
|
this.process.stderr.write("ERROR\n\n");
|
|
32
32
|
if (result.error.validationError) {
|
|
33
|
-
this.
|
|
33
|
+
this.io.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
|
|
34
34
|
throw new Error(result.error.validationError.debugMessage);
|
|
35
35
|
} else {
|
|
36
|
-
this.
|
|
36
|
+
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
37
37
|
throw new Error(result.error.message);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -53,14 +53,14 @@ const getRunLogs = buildAuthedHandler(async function(_flags, runId) {
|
|
|
53
53
|
if (Result.isSuccess(result)) {
|
|
54
54
|
this.process.stderr.write("OK\n\n");
|
|
55
55
|
const data = Result.unwrap(result);
|
|
56
|
-
this.
|
|
56
|
+
this.io.writeOut(data.logs);
|
|
57
57
|
} else {
|
|
58
58
|
this.process.stderr.write("ERROR\n\n");
|
|
59
59
|
if (result.error.validationError) {
|
|
60
|
-
this.
|
|
60
|
+
this.io.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
|
|
61
61
|
throw new Error(result.error.validationError.debugMessage);
|
|
62
62
|
} else {
|
|
63
|
-
this.
|
|
63
|
+
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
64
64
|
throw new Error(result.error.message);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -10,15 +10,15 @@ const setSecrets = buildAuthedHandler(async function(_flags, ...args) {
|
|
|
10
10
|
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
|
-
this.
|
|
13
|
+
this.io.writeErr(`Setting ${pluralize(secrets.length, "secret")}...`);
|
|
14
14
|
const result = await this.apiClient.upsertSecrets(workerId, secrets);
|
|
15
15
|
if (Result.isSuccess(result)) {
|
|
16
16
|
for (const secret of Result.unwrap(result).secrets) {
|
|
17
|
-
this.
|
|
17
|
+
this.io.writeErr(`Set secret "${secret.key}"`);
|
|
18
18
|
}
|
|
19
19
|
} else {
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
20
|
+
this.io.writeErr(`\u2717 Failed to set secrets`);
|
|
21
|
+
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
22
22
|
throw new Error(result.error.message);
|
|
23
23
|
}
|
|
24
24
|
});
|
|
@@ -35,24 +35,24 @@ const listSecrets = buildAuthedHandler(async function(flags) {
|
|
|
35
35
|
this.process.stderr.write("OK\n\n");
|
|
36
36
|
const data = Result.unwrap(result);
|
|
37
37
|
if (data.secrets.length === 0) {
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
38
|
+
this.io.writeErr("No secrets for this worker.");
|
|
39
|
+
this.io.writeErr(
|
|
40
40
|
"To list OAuth connect secrets, use `npx workers connect list`"
|
|
41
41
|
);
|
|
42
42
|
} else {
|
|
43
|
-
this.
|
|
43
|
+
this.io.writeTableOut({
|
|
44
44
|
headers: ["Key", "Created At"],
|
|
45
45
|
rows: data.secrets.map((secret) => [secret.key, secret.createdAt]),
|
|
46
46
|
plain: flags.plain
|
|
47
47
|
});
|
|
48
|
-
this.
|
|
48
|
+
this.io.writeErr(
|
|
49
49
|
"To list OAuth connect secrets, use `npx workers connect list`"
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
} else {
|
|
53
53
|
this.process.stderr.write("ERROR\n\n");
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
54
|
+
this.io.writeErr(`\u2717 Failed to list secrets`);
|
|
55
|
+
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
56
56
|
throw new Error(result.error.message);
|
|
57
57
|
}
|
|
58
58
|
});
|
|
@@ -69,8 +69,8 @@ const removeSecret = buildAuthedHandler(async function(_flags, key) {
|
|
|
69
69
|
this.process.stderr.write("OK\n\n");
|
|
70
70
|
} else {
|
|
71
71
|
this.process.stderr.write("ERROR\n\n");
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
72
|
+
this.io.writeErr(`\u2717 Failed to remove secret "${key}"`);
|
|
73
|
+
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
74
74
|
throw new Error(result.error.message);
|
|
75
75
|
}
|
|
76
76
|
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as os from "node:os";
|
|
3
|
-
import * as path from "node:path";
|
|
4
1
|
import { Config, type ConfigMap } from "../../config.js";
|
|
2
|
+
import type { LocalContext } from "../../context.js";
|
|
5
3
|
import type { GlobalFlags } from "../../flags.js";
|
|
6
|
-
import { Writer } from "../../writer.js";
|
|
7
4
|
export declare const tmpDirectories: string[];
|
|
8
5
|
export declare const baseFlags: GlobalFlags;
|
|
9
6
|
export declare function createAndLoadConfig({ configFile, env, flags, }: {
|
|
@@ -11,12 +8,6 @@ export declare function createAndLoadConfig({ configFile, env, flags, }: {
|
|
|
11
8
|
env?: Partial<NodeJS.ProcessEnv>;
|
|
12
9
|
flags?: Partial<GlobalFlags>;
|
|
13
10
|
}): Promise<[config: Config, path: string]>;
|
|
14
|
-
export declare function createBaseContext():
|
|
15
|
-
writer: Writer;
|
|
16
|
-
process: NodeJS.Process;
|
|
17
|
-
fs: typeof fs;
|
|
18
|
-
os: typeof os;
|
|
19
|
-
path: path.PlatformPath;
|
|
20
|
-
};
|
|
11
|
+
export declare function createBaseContext(): LocalContext;
|
|
21
12
|
export declare function cleanupTmpDirectories(): Promise<void>;
|
|
22
13
|
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/utils/testing.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/utils/testing.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,eAAO,MAAM,cAAc,EAAE,MAAM,EAAO,CAAC;AAE3C,eAAO,MAAM,SAAS,EAAE,WAEvB,CAAC;AAEF,wBAAsB,mBAAmB,CAAC,EACzC,UAAU,EACV,GAAG,EACH,KAAK,GACL,EAAE;IACF,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/B,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAC7B,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAa1C;AAED,wBAAgB,iBAAiB,IAAI,YAAY,CAQhD;AAED,wBAAsB,qBAAqB,kBAO1C"}
|
|
@@ -4,7 +4,7 @@ import * as os from "node:os";
|
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import * as path from "node:path";
|
|
6
6
|
import { Config } from "../../config.js";
|
|
7
|
-
import {
|
|
7
|
+
import { IO } from "../../io.js";
|
|
8
8
|
const tmpDirectories = [];
|
|
9
9
|
const baseFlags = {
|
|
10
10
|
debug: false
|
|
@@ -27,11 +27,11 @@ async function createAndLoadConfig({
|
|
|
27
27
|
}
|
|
28
28
|
function createBaseContext() {
|
|
29
29
|
return {
|
|
30
|
-
writer: new Writer({ debugEnabled: false }),
|
|
31
|
-
process,
|
|
32
30
|
fs,
|
|
31
|
+
io: new IO({ debugEnabled: false }),
|
|
33
32
|
os,
|
|
34
|
-
path
|
|
33
|
+
path,
|
|
34
|
+
process
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
async function cleanupTmpDirectories() {
|
package/dist/cli/context.d.ts
CHANGED
|
@@ -3,13 +3,13 @@ import * as os from "node:os";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import type { StricliAutoCompleteContext } from "@stricli/auto-complete";
|
|
5
5
|
import type { CommandContext } from "@stricli/core";
|
|
6
|
-
import {
|
|
6
|
+
import { IO } from "./io.js";
|
|
7
7
|
export interface LocalContext extends CommandContext, StricliAutoCompleteContext {
|
|
8
8
|
readonly fs: typeof fs;
|
|
9
|
+
readonly io: IO;
|
|
9
10
|
readonly os: typeof os;
|
|
10
11
|
readonly path: typeof path;
|
|
11
12
|
readonly process: NodeJS.Process;
|
|
12
|
-
readonly writer: Writer;
|
|
13
13
|
}
|
|
14
14
|
export declare function buildContext(process: NodeJS.Process): LocalContext;
|
|
15
15
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/cli/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/cli/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,MAAM,WAAW,YAChB,SAAQ,cAAc,EACrB,0BAA0B;IAC3B,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;CACjC;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,GAAG,YAAY,CAQlE"}
|
package/dist/cli/context.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as os from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { IO } from "./io.js";
|
|
5
5
|
function buildContext(process) {
|
|
6
6
|
return {
|
|
7
7
|
fs,
|
|
8
|
+
io: new IO({ debugEnabled: false }),
|
|
8
9
|
os,
|
|
9
10
|
path,
|
|
10
|
-
process
|
|
11
|
-
writer: new Writer({ debugEnabled: false })
|
|
11
|
+
process
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
export {
|
package/dist/cli/deploy.js
CHANGED
|
@@ -6,13 +6,13 @@ import { Result } from "./api/result.js";
|
|
|
6
6
|
async function deployWorker(context, options) {
|
|
7
7
|
const { workerPath } = options;
|
|
8
8
|
const absPath = path.resolve(process.cwd(), workerPath);
|
|
9
|
-
context.
|
|
9
|
+
context.io.debug(`Deploying worker from: ${absPath}`);
|
|
10
10
|
const client = context.apiClient;
|
|
11
11
|
let uploadUrl;
|
|
12
12
|
let uploadFields;
|
|
13
13
|
let workerId;
|
|
14
14
|
if ("workerId" in options) {
|
|
15
|
-
context.
|
|
15
|
+
context.io.writeErr(`Updating worker...`);
|
|
16
16
|
workerId = options.workerId;
|
|
17
17
|
const updateResult = await client.updateWorkerBundle(workerId);
|
|
18
18
|
if (Result.isSuccess(updateResult)) {
|
|
@@ -20,13 +20,13 @@ async function deployWorker(context, options) {
|
|
|
20
20
|
uploadUrl = res.url;
|
|
21
21
|
uploadFields = res.fields;
|
|
22
22
|
} else {
|
|
23
|
-
context.
|
|
23
|
+
context.io.writeErr(
|
|
24
24
|
"Failed to generate pre-signed upload URL for worker bundle:"
|
|
25
25
|
);
|
|
26
26
|
throw new Error(updateResult.error.message);
|
|
27
27
|
}
|
|
28
28
|
} else {
|
|
29
|
-
context.
|
|
29
|
+
context.io.writeErr(`Creating worker...`);
|
|
30
30
|
const createResult = await client.createWorker(options.name);
|
|
31
31
|
if (Result.isSuccess(createResult)) {
|
|
32
32
|
const res = Result.unwrap(createResult);
|
|
@@ -38,14 +38,14 @@ async function deployWorker(context, options) {
|
|
|
38
38
|
throw new Error(createResult.error.message);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
context.
|
|
42
|
-
context.
|
|
41
|
+
context.io.debug(`Generated upload URL: ${uploadUrl}`);
|
|
42
|
+
context.io.writeErr("Building worker bundle...");
|
|
43
43
|
const archivePath = await buildWorkerBundle(context, absPath);
|
|
44
|
-
context.
|
|
45
|
-
context.
|
|
44
|
+
context.io.debug(`Created bundle at: ${archivePath}`);
|
|
45
|
+
context.io.writeErr("Uploading bundle...");
|
|
46
46
|
await uploadBundle(uploadUrl, uploadFields, archivePath);
|
|
47
|
-
context.
|
|
48
|
-
context.
|
|
47
|
+
context.io.debug("Upload complete");
|
|
48
|
+
context.io.writeErr("Fetching and saving worker capabilities...");
|
|
49
49
|
const capabilitiesResult = await client.fetchAndSaveCapabilities(workerId);
|
|
50
50
|
if (Result.isSuccess(capabilitiesResult)) {
|
|
51
51
|
return Result.success({ workerId });
|
|
@@ -66,7 +66,7 @@ async function buildWorkerBundle(context, workerPath) {
|
|
|
66
66
|
outdir,
|
|
67
67
|
platform: "node"
|
|
68
68
|
});
|
|
69
|
-
context.
|
|
69
|
+
context.io.debug(`Built bundle to: ${outdir}`);
|
|
70
70
|
const archiveDir = fs.mkdtempSync("/tmp/workers-archive-");
|
|
71
71
|
const archivePath = path.join(archiveDir, "archive.tar.gz");
|
|
72
72
|
childProcess.execSync(`tar -czf ${archivePath} -C ${outdir} .`);
|