@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
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Readable } from "node:stream";
|
|
2
|
-
import { Result } from "../api/result.js";
|
|
3
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
-
|
|
5
|
-
export const downloadBundle = buildAuthedHandler(async function () {
|
|
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
|
-
const result = await this.apiClient.downloadWorkerBundle(workerId);
|
|
14
|
-
if (Result.isFail(result)) {
|
|
15
|
-
this.io.writeErr(`✗ Failed to download bundle`);
|
|
16
|
-
this.io.writeErr(`✗ ${result.error.message}`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
Readable.fromWeb(result.value).pipe(this.process.stdout);
|
|
21
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { globalFlags } from "../flags.js";
|
|
3
|
-
|
|
4
|
-
export const bundleCommands = buildRouteMap({
|
|
5
|
-
docs: {
|
|
6
|
-
brief: "Commands for managing worker bundles",
|
|
7
|
-
},
|
|
8
|
-
routes: {
|
|
9
|
-
download: buildCommand({
|
|
10
|
-
docs: {
|
|
11
|
-
brief: "Download the bundle for the worker",
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
parameters: {
|
|
15
|
-
flags: {
|
|
16
|
-
...globalFlags,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
loader: () => import("./bundle.impl.js").then((m) => m.downloadBundle),
|
|
21
|
-
}),
|
|
22
|
-
},
|
|
23
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import type { FormatFlags } from "../flags.js";
|
|
3
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
-
|
|
5
|
-
export const listCapabilities = buildAuthedHandler(async function (
|
|
6
|
-
flags: FormatFlags,
|
|
7
|
-
) {
|
|
8
|
-
const { workerId } = this.config;
|
|
9
|
-
if (!workerId) {
|
|
10
|
-
throw new Error(
|
|
11
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
this.process.stderr.write(`Fetching capabilities...`);
|
|
16
|
-
|
|
17
|
-
const result = await this.apiClient.listCapabilities(workerId);
|
|
18
|
-
|
|
19
|
-
if (Result.isSuccess(result)) {
|
|
20
|
-
this.process.stderr.write("OK\n\n");
|
|
21
|
-
|
|
22
|
-
const data = Result.unwrap(result);
|
|
23
|
-
if (data.capabilities.length === 0) {
|
|
24
|
-
this.io.writeErr("No capabilities found for this worker.");
|
|
25
|
-
} else {
|
|
26
|
-
this.io.writeTableOut({
|
|
27
|
-
headers: ["Key", "Tag"],
|
|
28
|
-
rows: data.capabilities.map((capability) => [
|
|
29
|
-
capability.key,
|
|
30
|
-
capability._tag,
|
|
31
|
-
]),
|
|
32
|
-
plain: flags.plain,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
this.process.stderr.write("ERROR\n\n");
|
|
37
|
-
|
|
38
|
-
// If it's a validation error, show the clean debug message
|
|
39
|
-
if (result.error.validationError) {
|
|
40
|
-
this.io.writeErr(`✗ ${result.error.validationError.debugMessage}`);
|
|
41
|
-
throw new Error(result.error.validationError.debugMessage);
|
|
42
|
-
} else {
|
|
43
|
-
this.io.writeErr(`✗ ${result.error.message}`);
|
|
44
|
-
throw new Error(result.error.message);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
-
|
|
4
|
-
export const capabilitiesCommands = buildRouteMap({
|
|
5
|
-
docs: {
|
|
6
|
-
brief: "Commands for managing worker capabilities",
|
|
7
|
-
},
|
|
8
|
-
routes: {
|
|
9
|
-
list: buildCommand({
|
|
10
|
-
docs: {
|
|
11
|
-
brief: "List all capabilities for a worker",
|
|
12
|
-
},
|
|
13
|
-
|
|
14
|
-
parameters: {
|
|
15
|
-
flags: {
|
|
16
|
-
...globalFlags,
|
|
17
|
-
...formatFlags,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
loader: () =>
|
|
22
|
-
import("./capabilities.impl.js").then((m) => m.listCapabilities),
|
|
23
|
-
}),
|
|
24
|
-
},
|
|
25
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import type { ApiError } from "../api/client.js";
|
|
2
|
-
import { Result } from "../api/result.js";
|
|
3
|
-
import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
4
|
-
import { type AuthedContext, buildAuthedHandler } from "../handler.js";
|
|
5
|
-
import { openBrowserUrl } from "../utils/openUrl.js";
|
|
6
|
-
|
|
7
|
-
export const listProviders = buildAuthedHandler(async function (
|
|
8
|
-
flags: FormatFlags,
|
|
9
|
-
) {
|
|
10
|
-
this.process.stderr.write("Fetching providers...");
|
|
11
|
-
const providersResult = await this.apiClient.listOauthProviders();
|
|
12
|
-
|
|
13
|
-
if (Result.isFail(providersResult)) {
|
|
14
|
-
this.process.stderr.write("ERROR\n\n");
|
|
15
|
-
reportApiError(this, providersResult.error, "list providers");
|
|
16
|
-
} else {
|
|
17
|
-
this.process.stderr.write("OK\n\n");
|
|
18
|
-
const providers = providersResult.value.providers;
|
|
19
|
-
if (providers.length === 0) {
|
|
20
|
-
this.io.writeErr("No OAuth providers are currently available.");
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.io.writeTableOut({
|
|
25
|
-
headers: ["Provider", "Description"],
|
|
26
|
-
rows: providers.map((provider) => [provider.key, provider.displayName]),
|
|
27
|
-
plain: flags.plain,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const addConnection = buildAuthedHandler(async function (
|
|
33
|
-
_flags: GlobalFlags,
|
|
34
|
-
provider: string,
|
|
35
|
-
) {
|
|
36
|
-
const workerId = requireWorkerId(this);
|
|
37
|
-
|
|
38
|
-
this.process.stderr.write(
|
|
39
|
-
`Starting OAuth flow with provider "${provider}"...`,
|
|
40
|
-
);
|
|
41
|
-
const startResult = await this.apiClient.startOauth({ workerId, provider });
|
|
42
|
-
|
|
43
|
-
if (Result.isFail(startResult)) {
|
|
44
|
-
this.process.stderr.write("ERROR\n\n");
|
|
45
|
-
reportApiError(this, startResult.error, "start OAuth flow");
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.process.stderr.write("OK\n\n");
|
|
50
|
-
|
|
51
|
-
const { authorizationUrl } = startResult.value;
|
|
52
|
-
|
|
53
|
-
this.io.writeErr("Opening your browser to continue the OAuth flow...");
|
|
54
|
-
try {
|
|
55
|
-
await openBrowserUrl(authorizationUrl);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
this.io.writeErr(
|
|
58
|
-
`Unable to open the browser automatically (${String(
|
|
59
|
-
error,
|
|
60
|
-
)}). Please open the link below manually.`,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
this.io.writeErr("");
|
|
65
|
-
this.io.writeErr("If the browser did not open, visit:");
|
|
66
|
-
this.io.writeErr(` ${authorizationUrl}`);
|
|
67
|
-
this.io.writeErr("");
|
|
68
|
-
this.io.writeErr(
|
|
69
|
-
"After completing the flow in your browser, return to the CLI.",
|
|
70
|
-
);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
export const listConnections = buildAuthedHandler(async function (
|
|
74
|
-
flags: FormatFlags,
|
|
75
|
-
) {
|
|
76
|
-
const workerId = requireWorkerId(this);
|
|
77
|
-
|
|
78
|
-
this.process.stderr.write("Fetching OAuth connections...");
|
|
79
|
-
const secretsResult = await this.apiClient.listSecrets(workerId, {
|
|
80
|
-
secretKinds: ["oauth"],
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
if (Result.isFail(secretsResult)) {
|
|
84
|
-
this.process.stderr.write("ERROR\n\n");
|
|
85
|
-
reportApiError(this, secretsResult.error, "list OAuth connections");
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
this.process.stderr.write("OK\n\n");
|
|
90
|
-
|
|
91
|
-
const secrets = secretsResult.value.secrets;
|
|
92
|
-
|
|
93
|
-
if (secrets.length === 0) {
|
|
94
|
-
this.io.writeErr("No OAuth connections found for this worker.");
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.io.writeTableOut({
|
|
99
|
-
headers: ["Env Var", "Created At"],
|
|
100
|
-
rows: secrets.map((secret) => [
|
|
101
|
-
`process.env.${secret.key}`,
|
|
102
|
-
secret.createdAt,
|
|
103
|
-
]),
|
|
104
|
-
plain: flags.plain,
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
export const removeConnection = buildAuthedHandler(async function (
|
|
109
|
-
_flags: GlobalFlags,
|
|
110
|
-
provider: string,
|
|
111
|
-
) {
|
|
112
|
-
const workerId = requireWorkerId(this);
|
|
113
|
-
|
|
114
|
-
this.process.stderr.write(
|
|
115
|
-
`Removing OAuth connection for provider "${provider}"...`,
|
|
116
|
-
);
|
|
117
|
-
const result = await this.apiClient.deleteOauthConnection({
|
|
118
|
-
workerId,
|
|
119
|
-
provider,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
if (Result.isFail(result)) {
|
|
123
|
-
this.process.stderr.write("ERROR\n\n");
|
|
124
|
-
reportApiError(this, result.error, "remove connection");
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
this.process.stderr.write("OK\n");
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
function requireWorkerId(context: AuthedContext): string {
|
|
132
|
-
const workerId = context.config.workerId;
|
|
133
|
-
if (!workerId) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
"No worker configured. Run 'workers deploy' first to create a worker.",
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
return workerId;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function reportApiError(
|
|
142
|
-
context: AuthedContext,
|
|
143
|
-
error: ApiError,
|
|
144
|
-
action: string,
|
|
145
|
-
): never {
|
|
146
|
-
context.io.writeErr(`✗ Failed to ${action}`);
|
|
147
|
-
context.io.writeErr(`✗ ${error.message}`);
|
|
148
|
-
throw new Error(error.message);
|
|
149
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
|
|
3
|
-
import { formatFlags, globalFlags } from "../flags.js";
|
|
4
|
-
|
|
5
|
-
export const connectCommands = buildRouteMap({
|
|
6
|
-
docs: {
|
|
7
|
-
brief: "Manage OAuth connections for your worker",
|
|
8
|
-
},
|
|
9
|
-
routes: {
|
|
10
|
-
providers: buildCommand({
|
|
11
|
-
docs: {
|
|
12
|
-
brief: "List available OAuth providers",
|
|
13
|
-
},
|
|
14
|
-
parameters: {
|
|
15
|
-
flags: {
|
|
16
|
-
...globalFlags,
|
|
17
|
-
...formatFlags,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
loader: () => import("./connect.impl.js").then((m) => m.listProviders),
|
|
21
|
-
}),
|
|
22
|
-
|
|
23
|
-
add: buildCommand({
|
|
24
|
-
docs: {
|
|
25
|
-
brief: "Start an OAuth flow for a provider",
|
|
26
|
-
},
|
|
27
|
-
parameters: {
|
|
28
|
-
positional: {
|
|
29
|
-
kind: "tuple",
|
|
30
|
-
parameters: [
|
|
31
|
-
{
|
|
32
|
-
brief: "Provider name (see `providers` command)",
|
|
33
|
-
parse: String,
|
|
34
|
-
placeholder: "provider",
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
flags: {
|
|
39
|
-
...globalFlags,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
loader: () => import("./connect.impl.js").then((m) => m.addConnection),
|
|
43
|
-
}),
|
|
44
|
-
|
|
45
|
-
list: buildCommand({
|
|
46
|
-
docs: {
|
|
47
|
-
brief: "List active OAuth connections",
|
|
48
|
-
},
|
|
49
|
-
parameters: {
|
|
50
|
-
flags: {
|
|
51
|
-
...globalFlags,
|
|
52
|
-
...formatFlags,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
loader: () => import("./connect.impl.js").then((m) => m.listConnections),
|
|
56
|
-
}),
|
|
57
|
-
|
|
58
|
-
rm: buildCommand({
|
|
59
|
-
docs: {
|
|
60
|
-
brief: "Remove an OAuth connection",
|
|
61
|
-
},
|
|
62
|
-
parameters: {
|
|
63
|
-
positional: {
|
|
64
|
-
kind: "tuple",
|
|
65
|
-
parameters: [
|
|
66
|
-
{
|
|
67
|
-
brief: "Provider name to remove",
|
|
68
|
-
parse: String,
|
|
69
|
-
placeholder: "provider",
|
|
70
|
-
},
|
|
71
|
-
],
|
|
72
|
-
},
|
|
73
|
-
flags: {
|
|
74
|
-
...globalFlags,
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
loader: () => import("./connect.impl.js").then((m) => m.removeConnection),
|
|
78
|
-
}),
|
|
79
|
-
},
|
|
80
|
-
});
|
|
@@ -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
|
-
});
|