@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,40 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
-
const listCapabilities = buildAuthedHandler(async function(flags) {
|
|
4
|
-
const { workerId } = this.config;
|
|
5
|
-
if (!workerId) {
|
|
6
|
-
throw new Error(
|
|
7
|
-
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
this.process.stderr.write(`Fetching capabilities...`);
|
|
11
|
-
const result = await this.apiClient.listCapabilities(workerId);
|
|
12
|
-
if (Result.isSuccess(result)) {
|
|
13
|
-
this.process.stderr.write("OK\n\n");
|
|
14
|
-
const data = Result.unwrap(result);
|
|
15
|
-
if (data.capabilities.length === 0) {
|
|
16
|
-
this.io.writeErr("No capabilities found for this worker.");
|
|
17
|
-
} else {
|
|
18
|
-
this.io.writeTableOut({
|
|
19
|
-
headers: ["Key", "Tag"],
|
|
20
|
-
rows: data.capabilities.map((capability) => [
|
|
21
|
-
capability.key,
|
|
22
|
-
capability._tag
|
|
23
|
-
]),
|
|
24
|
-
plain: flags.plain
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
this.process.stderr.write("ERROR\n\n");
|
|
29
|
-
if (result.error.validationError) {
|
|
30
|
-
this.io.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
|
|
31
|
-
throw new Error(result.error.validationError.debugMessage);
|
|
32
|
-
} else {
|
|
33
|
-
this.io.writeErr(`\u2717 ${result.error.message}`);
|
|
34
|
-
throw new Error(result.error.message);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
export {
|
|
39
|
-
listCapabilities
|
|
40
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
-
const capabilitiesCommands = buildRouteMap({
|
|
4
|
-
docs: {
|
|
5
|
-
brief: "Commands for managing worker capabilities"
|
|
6
|
-
},
|
|
7
|
-
routes: {
|
|
8
|
-
list: buildCommand({
|
|
9
|
-
docs: {
|
|
10
|
-
brief: "List all capabilities for a worker"
|
|
11
|
-
},
|
|
12
|
-
parameters: {
|
|
13
|
-
flags: {
|
|
14
|
-
...globalFlags,
|
|
15
|
-
...formatFlags
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
loader: () => import("./capabilities.impl.js").then((m) => m.listCapabilities)
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
export {
|
|
23
|
-
capabilitiesCommands
|
|
24
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/connect.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,wEA2E1B,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
2
|
-
export declare const listProviders: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
|
|
3
|
-
export declare const addConnection: (this: import("../context.js").LocalContext, flags: GlobalFlags, provider: string) => Promise<void>;
|
|
4
|
-
export declare const listConnections: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
|
|
5
|
-
export declare const removeConnection: (this: import("../context.js").LocalContext, flags: GlobalFlags, provider: string) => Promise<void>;
|
|
6
|
-
//# sourceMappingURL=connect.impl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/connect.impl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI5D,eAAO,MAAM,aAAa,iGAuBxB,CAAC;AAEH,eAAO,MAAM,aAAa,qGAuCxB,CAAC;AAEH,eAAO,MAAM,eAAe,iGAiC1B,CAAC;AAEH,eAAO,MAAM,gBAAgB,qGAqB3B,CAAC"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
-
import { openBrowserUrl } from "../utils/openUrl.js";
|
|
4
|
-
const listProviders = buildAuthedHandler(async function(flags) {
|
|
5
|
-
this.process.stderr.write("Fetching providers...");
|
|
6
|
-
const providersResult = await this.apiClient.listOauthProviders();
|
|
7
|
-
if (Result.isFail(providersResult)) {
|
|
8
|
-
this.process.stderr.write("ERROR\n\n");
|
|
9
|
-
reportApiError(this, providersResult.error, "list providers");
|
|
10
|
-
} else {
|
|
11
|
-
this.process.stderr.write("OK\n\n");
|
|
12
|
-
const providers = providersResult.value.providers;
|
|
13
|
-
if (providers.length === 0) {
|
|
14
|
-
this.io.writeErr("No OAuth providers are currently available.");
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
this.io.writeTableOut({
|
|
18
|
-
headers: ["Provider", "Description"],
|
|
19
|
-
rows: providers.map((provider) => [provider.key, provider.displayName]),
|
|
20
|
-
plain: flags.plain
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const addConnection = buildAuthedHandler(async function(_flags, provider) {
|
|
25
|
-
const workerId = requireWorkerId(this);
|
|
26
|
-
this.process.stderr.write(
|
|
27
|
-
`Starting OAuth flow with provider "${provider}"...`
|
|
28
|
-
);
|
|
29
|
-
const startResult = await this.apiClient.startOauth({ workerId, provider });
|
|
30
|
-
if (Result.isFail(startResult)) {
|
|
31
|
-
this.process.stderr.write("ERROR\n\n");
|
|
32
|
-
reportApiError(this, startResult.error, "start OAuth flow");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
this.process.stderr.write("OK\n\n");
|
|
36
|
-
const { authorizationUrl } = startResult.value;
|
|
37
|
-
this.io.writeErr("Opening your browser to continue the OAuth flow...");
|
|
38
|
-
try {
|
|
39
|
-
await openBrowserUrl(authorizationUrl);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
this.io.writeErr(
|
|
42
|
-
`Unable to open the browser automatically (${String(
|
|
43
|
-
error
|
|
44
|
-
)}). Please open the link below manually.`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
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
|
-
"After completing the flow in your browser, return to the CLI."
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
const listConnections = buildAuthedHandler(async function(flags) {
|
|
56
|
-
const workerId = requireWorkerId(this);
|
|
57
|
-
this.process.stderr.write("Fetching OAuth connections...");
|
|
58
|
-
const secretsResult = await this.apiClient.listSecrets(workerId, {
|
|
59
|
-
secretKinds: ["oauth"]
|
|
60
|
-
});
|
|
61
|
-
if (Result.isFail(secretsResult)) {
|
|
62
|
-
this.process.stderr.write("ERROR\n\n");
|
|
63
|
-
reportApiError(this, secretsResult.error, "list OAuth connections");
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
this.process.stderr.write("OK\n\n");
|
|
67
|
-
const secrets = secretsResult.value.secrets;
|
|
68
|
-
if (secrets.length === 0) {
|
|
69
|
-
this.io.writeErr("No OAuth connections found for this worker.");
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.io.writeTableOut({
|
|
73
|
-
headers: ["Env Var", "Created At"],
|
|
74
|
-
rows: secrets.map((secret) => [
|
|
75
|
-
`process.env.${secret.key}`,
|
|
76
|
-
secret.createdAt
|
|
77
|
-
]),
|
|
78
|
-
plain: flags.plain
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
const removeConnection = buildAuthedHandler(async function(_flags, provider) {
|
|
82
|
-
const workerId = requireWorkerId(this);
|
|
83
|
-
this.process.stderr.write(
|
|
84
|
-
`Removing OAuth connection for provider "${provider}"...`
|
|
85
|
-
);
|
|
86
|
-
const result = await this.apiClient.deleteOauthConnection({
|
|
87
|
-
workerId,
|
|
88
|
-
provider
|
|
89
|
-
});
|
|
90
|
-
if (Result.isFail(result)) {
|
|
91
|
-
this.process.stderr.write("ERROR\n\n");
|
|
92
|
-
reportApiError(this, result.error, "remove connection");
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
this.process.stderr.write("OK\n");
|
|
96
|
-
});
|
|
97
|
-
function requireWorkerId(context) {
|
|
98
|
-
const workerId = context.config.workerId;
|
|
99
|
-
if (!workerId) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
return workerId;
|
|
105
|
-
}
|
|
106
|
-
function reportApiError(context, error, action) {
|
|
107
|
-
context.io.writeErr(`\u2717 Failed to ${action}`);
|
|
108
|
-
context.io.writeErr(`\u2717 ${error.message}`);
|
|
109
|
-
throw new Error(error.message);
|
|
110
|
-
}
|
|
111
|
-
export {
|
|
112
|
-
addConnection,
|
|
113
|
-
listConnections,
|
|
114
|
-
listProviders,
|
|
115
|
-
removeConnection
|
|
116
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
-
const connectCommands = buildRouteMap({
|
|
4
|
-
docs: {
|
|
5
|
-
brief: "Manage OAuth connections for your worker"
|
|
6
|
-
},
|
|
7
|
-
routes: {
|
|
8
|
-
providers: buildCommand({
|
|
9
|
-
docs: {
|
|
10
|
-
brief: "List available OAuth providers"
|
|
11
|
-
},
|
|
12
|
-
parameters: {
|
|
13
|
-
flags: {
|
|
14
|
-
...globalFlags,
|
|
15
|
-
...formatFlags
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
loader: () => import("./connect.impl.js").then((m) => m.listProviders)
|
|
19
|
-
}),
|
|
20
|
-
add: buildCommand({
|
|
21
|
-
docs: {
|
|
22
|
-
brief: "Start an OAuth flow for a provider"
|
|
23
|
-
},
|
|
24
|
-
parameters: {
|
|
25
|
-
positional: {
|
|
26
|
-
kind: "tuple",
|
|
27
|
-
parameters: [
|
|
28
|
-
{
|
|
29
|
-
brief: "Provider name (see `providers` command)",
|
|
30
|
-
parse: String,
|
|
31
|
-
placeholder: "provider"
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
flags: {
|
|
36
|
-
...globalFlags
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
loader: () => import("./connect.impl.js").then((m) => m.addConnection)
|
|
40
|
-
}),
|
|
41
|
-
list: buildCommand({
|
|
42
|
-
docs: {
|
|
43
|
-
brief: "List active OAuth connections"
|
|
44
|
-
},
|
|
45
|
-
parameters: {
|
|
46
|
-
flags: {
|
|
47
|
-
...globalFlags,
|
|
48
|
-
...formatFlags
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
loader: () => import("./connect.impl.js").then((m) => m.listConnections)
|
|
52
|
-
}),
|
|
53
|
-
rm: buildCommand({
|
|
54
|
-
docs: {
|
|
55
|
-
brief: "Remove an OAuth connection"
|
|
56
|
-
},
|
|
57
|
-
parameters: {
|
|
58
|
-
positional: {
|
|
59
|
-
kind: "tuple",
|
|
60
|
-
parameters: [
|
|
61
|
-
{
|
|
62
|
-
brief: "Provider name to remove",
|
|
63
|
-
parse: String,
|
|
64
|
-
placeholder: "provider"
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
flags: {
|
|
69
|
-
...globalFlags
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
loader: () => import("./connect.impl.js").then((m) => m.removeConnection)
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
export {
|
|
77
|
-
connectCommands
|
|
78
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":";AAGA,wBAkBG"}
|
|
@@ -1 +0,0 @@
|
|
|
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,60 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import { deployWorker } from "../deploy.js";
|
|
3
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
-
const deploy = buildAuthedHandler(async function(flags) {
|
|
5
|
-
const { token } = this.config.tokenInfo;
|
|
6
|
-
const workerId = this.config.workerId;
|
|
7
|
-
const environment = this.config.environment;
|
|
8
|
-
if (!environment) {
|
|
9
|
-
throw new Error("Unexpected error: Environment not set");
|
|
10
|
-
}
|
|
11
|
-
const workerPath = this.process.cwd();
|
|
12
|
-
this.io.writeErr("Deploying worker...");
|
|
13
|
-
const name = flags.name;
|
|
14
|
-
if (workerId && name) {
|
|
15
|
-
throw new Error("Cannot specify a name when updating an existing worker");
|
|
16
|
-
}
|
|
17
|
-
let result;
|
|
18
|
-
if (workerId) {
|
|
19
|
-
result = await deployWorker(this, {
|
|
20
|
-
workerPath,
|
|
21
|
-
workerId,
|
|
22
|
-
token,
|
|
23
|
-
environment
|
|
24
|
-
});
|
|
25
|
-
} else {
|
|
26
|
-
let validatedName;
|
|
27
|
-
if (name) {
|
|
28
|
-
validatedName = name;
|
|
29
|
-
} else {
|
|
30
|
-
const nameInput = await this.io.input({
|
|
31
|
-
message: "Enter a name for the worker",
|
|
32
|
-
required: true,
|
|
33
|
-
noTTY: "Provide a name for the worker with --name"
|
|
34
|
-
});
|
|
35
|
-
const trimmedName = nameInput?.trim();
|
|
36
|
-
if (!trimmedName) {
|
|
37
|
-
throw new Error("Name is required");
|
|
38
|
-
}
|
|
39
|
-
validatedName = trimmedName;
|
|
40
|
-
}
|
|
41
|
-
result = await deployWorker(this, {
|
|
42
|
-
name: validatedName,
|
|
43
|
-
workerPath,
|
|
44
|
-
token,
|
|
45
|
-
environment
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
if (Result.isSuccess(result)) {
|
|
49
|
-
const { workerId: workerId2 } = Result.unwrap(result);
|
|
50
|
-
await this.config.update({ workerId: workerId2 });
|
|
51
|
-
this.io.writeErr("\u2713 Successfully deployed worker");
|
|
52
|
-
} else {
|
|
53
|
-
this.io.writeErr("\u2717 Failed to deploy worker");
|
|
54
|
-
this.io.writeErr(result.error.message);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
export {
|
|
59
|
-
deploy
|
|
60
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.impl.test.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.impl.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { buildCommand } from "@stricli/core";
|
|
2
|
-
import { globalFlags } from "../flags.js";
|
|
3
|
-
var deploy_default = buildCommand({
|
|
4
|
-
docs: {
|
|
5
|
-
brief: "Deploy a worker to the Project Ajax platform"
|
|
6
|
-
},
|
|
7
|
-
parameters: {
|
|
8
|
-
flags: {
|
|
9
|
-
...globalFlags,
|
|
10
|
-
name: {
|
|
11
|
-
kind: "parsed",
|
|
12
|
-
parse: String,
|
|
13
|
-
brief: "The name of the worker (if it has not yet been created)",
|
|
14
|
-
optional: true
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
loader: () => import("./deploy.impl.js").then((m) => m.deploy)
|
|
19
|
-
});
|
|
20
|
-
export {
|
|
21
|
-
deploy_default as default
|
|
22
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/env.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,wEAiCtB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface PullEnvFlags {
|
|
2
|
-
yes: boolean;
|
|
3
|
-
}
|
|
4
|
-
export declare const DEFAULT_ENV_FILE = ".env";
|
|
5
|
-
export declare const pullEnv: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags & PullEnvFlags, filePath?: string | undefined) => Promise<void>;
|
|
6
|
-
export declare function serializeEnvFile(envEntries: Array<{
|
|
7
|
-
key: string;
|
|
8
|
-
value: string;
|
|
9
|
-
}>): string;
|
|
10
|
-
export declare function formatEnvValue(value: string): string;
|
|
11
|
-
//# sourceMappingURL=env.impl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,62 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
-
import { pluralize } from "../utils/string.js";
|
|
4
|
-
const DEFAULT_ENV_FILE = ".env";
|
|
5
|
-
const pullEnv = buildAuthedHandler(async function(flags, filePath) {
|
|
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
|
-
const destination = filePath ?? DEFAULT_ENV_FILE;
|
|
13
|
-
const absoluteDestination = this.path.resolve(
|
|
14
|
-
this.process.cwd(),
|
|
15
|
-
destination
|
|
16
|
-
);
|
|
17
|
-
if (this.fs.existsSync(absoluteDestination) && !flags.yes) {
|
|
18
|
-
const overwrite = await this.io.confirm({
|
|
19
|
-
message: `File "${destination}" already exists. Overwrite it?`,
|
|
20
|
-
noTTY: `File "${destination}" already exists.`
|
|
21
|
-
});
|
|
22
|
-
if (overwrite !== true) {
|
|
23
|
-
this.io.writeErr("Aborted.");
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
this.io.writeErr("Fetching environment variables...");
|
|
28
|
-
const envResult = await this.apiClient.pullEnv(workerId);
|
|
29
|
-
if (Result.isFail(envResult)) {
|
|
30
|
-
this.io.writeErr("\u2717 Failed to fetch env vars");
|
|
31
|
-
this.io.writeErr(`\u2717 ${envResult.error.message}`);
|
|
32
|
-
throw new Error(envResult.error.message);
|
|
33
|
-
}
|
|
34
|
-
const envEntries = envResult.value.env;
|
|
35
|
-
const fileContents = serializeEnvFile(envEntries);
|
|
36
|
-
await this.fs.promises.mkdir(this.path.dirname(absoluteDestination), {
|
|
37
|
-
recursive: true
|
|
38
|
-
});
|
|
39
|
-
await this.fs.promises.writeFile(absoluteDestination, fileContents, "utf8");
|
|
40
|
-
this.io.writeErr(
|
|
41
|
-
`Wrote ${pluralize(envEntries.length, "env var")} to "${destination}"`
|
|
42
|
-
);
|
|
43
|
-
});
|
|
44
|
-
function serializeEnvFile(envEntries) {
|
|
45
|
-
if (envEntries.length === 0) {
|
|
46
|
-
return "# No env vars configured for this worker\n";
|
|
47
|
-
}
|
|
48
|
-
return envEntries.map(({ key, value }) => `${key}=${formatEnvValue(value)}`).join("\n").concat("\n");
|
|
49
|
-
}
|
|
50
|
-
function formatEnvValue(value) {
|
|
51
|
-
if (/^[A-Za-z0-9_./:-]*$/.test(value)) {
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
const escaped = value.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/"/g, '\\"');
|
|
55
|
-
return `"${escaped}"`;
|
|
56
|
-
}
|
|
57
|
-
export {
|
|
58
|
-
DEFAULT_ENV_FILE,
|
|
59
|
-
formatEnvValue,
|
|
60
|
-
pullEnv,
|
|
61
|
-
serializeEnvFile
|
|
62
|
-
};
|
package/dist/cli/commands/env.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { globalFlags } from "../flags.js";
|
|
3
|
-
const envCommands = buildRouteMap({
|
|
4
|
-
docs: {
|
|
5
|
-
brief: "Work with worker environment files"
|
|
6
|
-
},
|
|
7
|
-
routes: {
|
|
8
|
-
pull: buildCommand({
|
|
9
|
-
docs: {
|
|
10
|
-
brief: "Write the worker's env vars to a .env file"
|
|
11
|
-
},
|
|
12
|
-
parameters: {
|
|
13
|
-
positional: {
|
|
14
|
-
kind: "tuple",
|
|
15
|
-
parameters: [
|
|
16
|
-
{
|
|
17
|
-
brief: "Destination file path",
|
|
18
|
-
parse: String,
|
|
19
|
-
placeholder: "file",
|
|
20
|
-
optional: true
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
},
|
|
24
|
-
flags: {
|
|
25
|
-
...globalFlags,
|
|
26
|
-
yes: {
|
|
27
|
-
kind: "boolean",
|
|
28
|
-
brief: "Overwrite the output file without prompting",
|
|
29
|
-
default: false
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
loader: () => import("./env.impl.js").then((m) => m.pullEnv)
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
export {
|
|
38
|
-
envCommands
|
|
39
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/exec.ts"],"names":[],"mappings":";AAGA,wBA4BG"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { GlobalFlags } from "../flags.js";
|
|
2
|
-
interface ExecFlags extends GlobalFlags {
|
|
3
|
-
stream: boolean;
|
|
4
|
-
}
|
|
5
|
-
export declare const exec: (this: import("../context.js").LocalContext, flags: GlobalFlags & ExecFlags, ...args: readonly string[]) => Promise<void>;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=exec.impl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
-
import { chunkEvery } from "../utils/array.js";
|
|
4
|
-
const usageHint = `Usage: workers exec <capabilityName> <capabilityFunction> [<argName1>=<value1> <argName2>=<value2>...]`;
|
|
5
|
-
const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
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
|
-
const capabilityName = args[0];
|
|
13
|
-
const capabilityFunction = args[1] ?? null;
|
|
14
|
-
const functionArgs = args.slice(2).flatMap((arg) => arg.split(/[=]/));
|
|
15
|
-
if (!capabilityName) {
|
|
16
|
-
throw usageError();
|
|
17
|
-
}
|
|
18
|
-
if (functionArgs.length % 2 !== 0) {
|
|
19
|
-
throw usageError();
|
|
20
|
-
}
|
|
21
|
-
const argsList = chunkEvery(functionArgs, 2).map(([key, value]) => {
|
|
22
|
-
if (!key || !value) {
|
|
23
|
-
throw usageError();
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
name: key,
|
|
27
|
-
value
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
this.io.writeErr(`Executing capability "${capabilityName}"...`);
|
|
31
|
-
if (flags.stream) {
|
|
32
|
-
const result = await this.apiClient.runCapability(
|
|
33
|
-
workerId,
|
|
34
|
-
capabilityName,
|
|
35
|
-
capabilityFunction,
|
|
36
|
-
argsList,
|
|
37
|
-
true
|
|
38
|
-
);
|
|
39
|
-
if (Result.isSuccess(result)) {
|
|
40
|
-
const decoder = new TextDecoder();
|
|
41
|
-
let buffer = "";
|
|
42
|
-
const allOutput = [];
|
|
43
|
-
const onBodyLine = async (jsonLine) => {
|
|
44
|
-
try {
|
|
45
|
-
const parsedLine = JSON.parse(jsonLine);
|
|
46
|
-
switch (parsedLine._tag) {
|
|
47
|
-
case "log":
|
|
48
|
-
if (!flags.debug) {
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
if (parsedLine.event.stream === "stdout") {
|
|
52
|
-
allOutput.push(parsedLine.event.data);
|
|
53
|
-
}
|
|
54
|
-
parsedLine.event.data.trim().split("\n").forEach((dataLine) => {
|
|
55
|
-
this.io.writeErr(
|
|
56
|
-
`[worker:${parsedLine.event.stream}] ${dataLine.trim()}`
|
|
57
|
-
);
|
|
58
|
-
});
|
|
59
|
-
break;
|
|
60
|
-
case "result":
|
|
61
|
-
this.io.writeOut(JSON.stringify(parsedLine.result, null, 2));
|
|
62
|
-
break;
|
|
63
|
-
case "error":
|
|
64
|
-
this.io.writeErr(`Error: ${parsedLine.error}`);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
} catch (error) {
|
|
68
|
-
this.io.writeErr(`Error parsing log line: ${jsonLine}: ${error}`);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
for await (const log of result.value) {
|
|
72
|
-
const output = decoder.decode(log);
|
|
73
|
-
buffer += output;
|
|
74
|
-
const lines = buffer.split("\n");
|
|
75
|
-
buffer = lines.pop() ?? "";
|
|
76
|
-
for (const line of lines) {
|
|
77
|
-
await onBodyLine(line);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (buffer) {
|
|
81
|
-
await onBodyLine(buffer);
|
|
82
|
-
}
|
|
83
|
-
return;
|
|
84
|
-
} else {
|
|
85
|
-
this.io.writeErr(`
|
|
86
|
-
\u2717 Failed to execute capability`);
|
|
87
|
-
if (result.error.validationError) {
|
|
88
|
-
this.io.writeErr(` \u2717 HTTP Error: ${result.error.status}`);
|
|
89
|
-
this.io.writeErr(` \u2717 ${result.error.validationError.debugMessage}`);
|
|
90
|
-
this.io.writeErr(`
|
|
91
|
-
${usageHint}`);
|
|
92
|
-
throw new Error(result.error.validationError.debugMessage);
|
|
93
|
-
} else {
|
|
94
|
-
this.io.writeErr(` \u2717 HTTP Error: ${result.error.status}`);
|
|
95
|
-
this.io.writeErr(` \u2717 ${result.error.message}`);
|
|
96
|
-
throw new Error(result.error.message);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
const result = await this.apiClient.runCapability(
|
|
101
|
-
workerId,
|
|
102
|
-
capabilityName,
|
|
103
|
-
capabilityFunction,
|
|
104
|
-
argsList,
|
|
105
|
-
false
|
|
106
|
-
);
|
|
107
|
-
if (Result.isSuccess(result)) {
|
|
108
|
-
const data = Result.unwrap(result);
|
|
109
|
-
this.io.writeOut(JSON.stringify(data.result, null, 2));
|
|
110
|
-
} else {
|
|
111
|
-
this.io.writeErr(`
|
|
112
|
-
\u2717 Failed to execute capability`);
|
|
113
|
-
this.io.writeErr(` \u2717 ${result.error.message}`);
|
|
114
|
-
throw new Error(result.error.message);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
function usageError() {
|
|
119
|
-
return new Error(`Invalid arguments provided. ${usageHint}`);
|
|
120
|
-
}
|
|
121
|
-
export {
|
|
122
|
-
exec
|
|
123
|
-
};
|