@project-ajax/sdk 0.0.28
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/README.md +22 -0
- package/dist/block.d.ts +321 -0
- package/dist/block.d.ts.map +1 -0
- package/dist/block.js +0 -0
- package/dist/builder.d.ts +12 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +22 -0
- package/dist/capabilities/slashCommand.d.ts +56 -0
- package/dist/capabilities/slashCommand.d.ts.map +1 -0
- package/dist/capabilities/slashCommand.js +32 -0
- package/dist/capabilities/sync.d.ts +58 -0
- package/dist/capabilities/sync.d.ts.map +1 -0
- package/dist/capabilities/sync.js +26 -0
- package/dist/capabilities/tool.d.ts +69 -0
- package/dist/capabilities/tool.d.ts.map +1 -0
- package/dist/capabilities/tool.js +75 -0
- package/dist/capabilities/tool.test.d.ts +2 -0
- package/dist/capabilities/tool.test.d.ts.map +1 -0
- package/dist/cli/api/client.d.ts +185 -0
- package/dist/cli/api/client.d.ts.map +1 -0
- package/dist/cli/api/client.js +315 -0
- package/dist/cli/api/result.d.ts +43 -0
- package/dist/cli/api/result.d.ts.map +1 -0
- package/dist/cli/api/result.js +43 -0
- package/dist/cli/bin/cli.d.ts +3 -0
- package/dist/cli/bin/cli.d.ts.map +1 -0
- package/dist/cli/bin/cli.js +5 -0
- package/dist/cli/commands/auth.d.ts +2 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.impl.d.ts +10 -0
- package/dist/cli/commands/auth.impl.d.ts.map +1 -0
- package/dist/cli/commands/auth.impl.js +68 -0
- package/dist/cli/commands/auth.js +71 -0
- package/dist/cli/commands/bundle.d.ts +2 -0
- package/dist/cli/commands/bundle.d.ts.map +1 -0
- package/dist/cli/commands/bundle.impl.d.ts +2 -0
- package/dist/cli/commands/bundle.impl.d.ts.map +1 -0
- package/dist/cli/commands/bundle.impl.js +21 -0
- package/dist/cli/commands/bundle.js +23 -0
- package/dist/cli/commands/capabilities.d.ts +2 -0
- package/dist/cli/commands/capabilities.d.ts.map +1 -0
- package/dist/cli/commands/capabilities.impl.d.ts +3 -0
- package/dist/cli/commands/capabilities.impl.d.ts.map +1 -0
- package/dist/cli/commands/capabilities.impl.js +40 -0
- package/dist/cli/commands/capabilities.js +24 -0
- package/dist/cli/commands/deploy.d.ts +3 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.impl.d.ts +2 -0
- package/dist/cli/commands/deploy.impl.d.ts.map +1 -0
- package/dist/cli/commands/deploy.impl.js +31 -0
- package/dist/cli/commands/deploy.js +16 -0
- package/dist/cli/commands/exec.d.ts +3 -0
- package/dist/cli/commands/exec.d.ts.map +1 -0
- package/dist/cli/commands/exec.impl.d.ts +7 -0
- package/dist/cli/commands/exec.impl.d.ts.map +1 -0
- package/dist/cli/commands/exec.impl.js +122 -0
- package/dist/cli/commands/exec.js +30 -0
- package/dist/cli/commands/runs.d.ts +2 -0
- package/dist/cli/commands/runs.d.ts.map +1 -0
- package/dist/cli/commands/runs.impl.d.ts +4 -0
- package/dist/cli/commands/runs.impl.d.ts.map +1 -0
- package/dist/cli/commands/runs.impl.js +71 -0
- package/dist/cli/commands/runs.js +45 -0
- package/dist/cli/commands/secrets.d.ts +2 -0
- package/dist/cli/commands/secrets.d.ts.map +1 -0
- package/dist/cli/commands/secrets.impl.d.ts +5 -0
- package/dist/cli/commands/secrets.impl.d.ts.map +1 -0
- package/dist/cli/commands/secrets.impl.js +93 -0
- package/dist/cli/commands/secrets.js +64 -0
- package/dist/cli/config.d.ts +38 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +133 -0
- package/dist/cli/context.d.ts +15 -0
- package/dist/cli/context.d.ts.map +1 -0
- package/dist/cli/context.js +16 -0
- package/dist/cli/deploy.d.ts +25 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +101 -0
- package/dist/cli/flags.d.ts +16 -0
- package/dist/cli/flags.d.ts.map +1 -0
- package/dist/cli/flags.js +24 -0
- package/dist/cli/handler.d.ts +14 -0
- package/dist/cli/handler.d.ts.map +1 -0
- package/dist/cli/handler.js +30 -0
- package/dist/cli/routes.d.ts +2 -0
- package/dist/cli/routes.d.ts.map +1 -0
- package/dist/cli/routes.js +44 -0
- package/dist/cli/utils/array.d.ts +2 -0
- package/dist/cli/utils/array.d.ts.map +1 -0
- package/dist/cli/utils/array.js +10 -0
- package/dist/cli/utils/string.d.ts +2 -0
- package/dist/cli/utils/string.d.ts.map +1 -0
- package/dist/cli/utils/string.js +12 -0
- package/dist/cli/writer.d.ts +48 -0
- package/dist/cli/writer.d.ts.map +1 -0
- package/dist/cli/writer.js +73 -0
- package/dist/error.d.ts +8 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +11 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/schema.d.ts +45 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +14 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/package.json +79 -0
- package/src/block.ts +529 -0
- package/src/builder.ts +26 -0
- package/src/capabilities/slashCommand.ts +71 -0
- package/src/capabilities/sync.ts +76 -0
- package/src/capabilities/tool.test.ts +181 -0
- package/src/capabilities/tool.ts +145 -0
- package/src/cli/api/client.ts +588 -0
- package/src/cli/api/result.ts +71 -0
- package/src/cli/bin/cli.ts +7 -0
- package/src/cli/commands/auth.impl.ts +92 -0
- package/src/cli/commands/auth.ts +77 -0
- package/src/cli/commands/bundle.impl.ts +21 -0
- package/src/cli/commands/bundle.ts +23 -0
- package/src/cli/commands/capabilities.impl.ts +47 -0
- package/src/cli/commands/capabilities.ts +25 -0
- package/src/cli/commands/deploy.impl.ts +34 -0
- package/src/cli/commands/deploy.ts +16 -0
- package/src/cli/commands/exec.impl.ts +169 -0
- package/src/cli/commands/exec.ts +32 -0
- package/src/cli/commands/runs.impl.ts +87 -0
- package/src/cli/commands/runs.ts +49 -0
- package/src/cli/commands/secrets.impl.ts +124 -0
- package/src/cli/commands/secrets.ts +73 -0
- package/src/cli/config.ts +175 -0
- package/src/cli/context.ts +26 -0
- package/src/cli/deploy.ts +175 -0
- package/src/cli/flags.ts +43 -0
- package/src/cli/handler.ts +62 -0
- package/src/cli/routes.ts +43 -0
- package/src/cli/utils/array.ts +7 -0
- package/src/cli/utils/string.ts +9 -0
- package/src/cli/writer.ts +97 -0
- package/src/error.ts +12 -0
- package/src/index.ts +3 -0
- package/src/schema.ts +54 -0
- package/src/types.ts +10 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
+
const runsCommands = buildRouteMap({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Commands for managing worker runs"
|
|
6
|
+
},
|
|
7
|
+
routes: {
|
|
8
|
+
list: buildCommand({
|
|
9
|
+
docs: {
|
|
10
|
+
brief: "List all runs for a worker"
|
|
11
|
+
},
|
|
12
|
+
parameters: {
|
|
13
|
+
flags: {
|
|
14
|
+
...globalFlags,
|
|
15
|
+
...formatFlags
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
loader: () => import("./runs.impl.js").then((m) => m.listRuns)
|
|
19
|
+
}),
|
|
20
|
+
logs: buildCommand({
|
|
21
|
+
docs: {
|
|
22
|
+
brief: "Get logs for a specific run"
|
|
23
|
+
},
|
|
24
|
+
parameters: {
|
|
25
|
+
positional: {
|
|
26
|
+
kind: "tuple",
|
|
27
|
+
parameters: [
|
|
28
|
+
{
|
|
29
|
+
brief: "The run ID to get logs for",
|
|
30
|
+
parse: String,
|
|
31
|
+
placeholder: "runId"
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
flags: {
|
|
36
|
+
...globalFlags
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
loader: () => import("./runs.impl.js").then((m) => m.getRunLogs)
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
export {
|
|
44
|
+
runsCommands
|
|
45
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/secrets.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,wEAqE1B,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
2
|
+
export declare const setSecrets: (this: import("../context.js").LocalContext, flags: GlobalFlags, ...args: string[]) => Promise<void>;
|
|
3
|
+
export declare const listSecrets: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
|
|
4
|
+
export declare const removeSecret: (this: import("../context.js").LocalContext, flags: GlobalFlags, key: string) => Promise<void>;
|
|
5
|
+
//# sourceMappingURL=secrets.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/secrets.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK5D,eAAO,MAAM,UAAU,sGA0BrB,CAAC;AAEH,eAAO,MAAM,WAAW,iGAkCtB,CAAC;AAEH,eAAO,MAAM,YAAY,gGAwBvB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Result } from "../api/result.js";
|
|
2
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
+
import { chunkEvery } from "../utils/array.js";
|
|
4
|
+
import { pluralize } from "../utils/string.js";
|
|
5
|
+
const setSecrets = buildAuthedHandler(async function(_flags, ...args) {
|
|
6
|
+
const secrets = parseSecretArgs(args);
|
|
7
|
+
const { workerId } = this.config;
|
|
8
|
+
if (!workerId) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
this.writer.writeErr(`Setting ${pluralize(secrets.length, "secret")}...`);
|
|
14
|
+
const result = await this.apiClient.upsertSecrets(workerId, secrets);
|
|
15
|
+
if (Result.isSuccess(result)) {
|
|
16
|
+
for (const secret of Result.unwrap(result).secrets) {
|
|
17
|
+
this.writer.writeErr(`Set secret "${secret.key}"`);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
this.writer.writeErr(`\u2717 Failed to set secrets`);
|
|
21
|
+
this.writer.writeErr(`\u2717 ${result.error.message}`);
|
|
22
|
+
throw new Error(result.error.message);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const listSecrets = buildAuthedHandler(async function(flags) {
|
|
26
|
+
const { workerId } = this.config;
|
|
27
|
+
if (!workerId) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
this.process.stderr.write(`Fetching secrets...`);
|
|
33
|
+
const result = await this.apiClient.listSecrets(workerId);
|
|
34
|
+
if (Result.isSuccess(result)) {
|
|
35
|
+
this.process.stderr.write("OK\n\n");
|
|
36
|
+
const data = Result.unwrap(result);
|
|
37
|
+
if (data.secrets.length === 0) {
|
|
38
|
+
this.writer.writeErr("No secrets for this worker.");
|
|
39
|
+
} else {
|
|
40
|
+
this.writer.writeTableOut({
|
|
41
|
+
headers: ["Key", "Created At"],
|
|
42
|
+
rows: data.secrets.map((secret) => [secret.key, secret.createdAt]),
|
|
43
|
+
plain: flags.plain
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
this.process.stderr.write("ERROR\n\n");
|
|
48
|
+
this.writer.writeErr(`\u2717 Failed to list secrets`);
|
|
49
|
+
this.writer.writeErr(`\u2717 ${result.error.message}`);
|
|
50
|
+
throw new Error(result.error.message);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const removeSecret = buildAuthedHandler(async function(_flags, key) {
|
|
54
|
+
const { workerId } = this.config;
|
|
55
|
+
if (!workerId) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
this.process.stderr.write(`Removing secret "${key}"...`);
|
|
61
|
+
const result = await this.apiClient.deleteSecret(workerId, key);
|
|
62
|
+
if (Result.isSuccess(result)) {
|
|
63
|
+
this.process.stderr.write("OK\n\n");
|
|
64
|
+
} else {
|
|
65
|
+
this.process.stderr.write("ERROR\n\n");
|
|
66
|
+
this.writer.writeErr(`\u2717 Failed to remove secret "${key}"`);
|
|
67
|
+
this.writer.writeErr(`\u2717 ${result.error.message}`);
|
|
68
|
+
throw new Error(result.error.message);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
function usageError() {
|
|
72
|
+
return new Error(
|
|
73
|
+
"Invalid secrets provided. Usage: workers secrets set <key> <value> [<key2> <value2>...] or <key>=<value> [<key2>=<value2>...]"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function parseSecretArgs(args) {
|
|
77
|
+
if (args.length === 0) {
|
|
78
|
+
throw usageError();
|
|
79
|
+
}
|
|
80
|
+
const tokens = args.flatMap((arg) => arg.split(/[=:]/));
|
|
81
|
+
const secrets = chunkEvery(tokens, 2).map(([key, value]) => {
|
|
82
|
+
if (!key || !value) {
|
|
83
|
+
throw usageError();
|
|
84
|
+
}
|
|
85
|
+
return { key, value };
|
|
86
|
+
});
|
|
87
|
+
return secrets;
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
listSecrets,
|
|
91
|
+
removeSecret,
|
|
92
|
+
setSecrets
|
|
93
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
+
const secretsCommands = buildRouteMap({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Commands for managing worker secrets"
|
|
6
|
+
},
|
|
7
|
+
routes: {
|
|
8
|
+
set: buildCommand({
|
|
9
|
+
docs: {
|
|
10
|
+
brief: "Set one or more secrets for a worker. Supports 'key value' or 'key=value' format."
|
|
11
|
+
},
|
|
12
|
+
parameters: {
|
|
13
|
+
positional: {
|
|
14
|
+
kind: "array",
|
|
15
|
+
parameter: {
|
|
16
|
+
brief: "Secret key-value pairs (key value or key=value)",
|
|
17
|
+
parse: String,
|
|
18
|
+
placeholder: "secrets..."
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
flags: {
|
|
22
|
+
...globalFlags
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
loader: () => import("./secrets.impl.js").then((m) => m.setSecrets)
|
|
26
|
+
}),
|
|
27
|
+
list: buildCommand({
|
|
28
|
+
docs: {
|
|
29
|
+
brief: "List all secrets for a worker (keys only)"
|
|
30
|
+
},
|
|
31
|
+
parameters: {
|
|
32
|
+
flags: {
|
|
33
|
+
...globalFlags,
|
|
34
|
+
...formatFlags
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
loader: () => import("./secrets.impl.js").then((m) => m.listSecrets)
|
|
38
|
+
}),
|
|
39
|
+
rm: buildCommand({
|
|
40
|
+
docs: {
|
|
41
|
+
brief: "Remove a secret from a worker"
|
|
42
|
+
},
|
|
43
|
+
parameters: {
|
|
44
|
+
positional: {
|
|
45
|
+
kind: "tuple",
|
|
46
|
+
parameters: [
|
|
47
|
+
{
|
|
48
|
+
brief: "The secret key name to remove",
|
|
49
|
+
parse: String,
|
|
50
|
+
placeholder: "key"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
flags: {
|
|
55
|
+
...globalFlags
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
loader: () => import("./secrets.impl.js").then((m) => m.removeSecret)
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
export {
|
|
63
|
+
secretsCommands
|
|
64
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const Environments: readonly ["local", "staging", "dev", "prod"];
|
|
2
|
+
export type Environment = (typeof Environments)[number];
|
|
3
|
+
interface ConfigFile {
|
|
4
|
+
environment?: Environment;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
token: string | null;
|
|
7
|
+
workerId: string | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseEnvironment(name: string): Environment;
|
|
10
|
+
export declare class TokenNotSetError extends Error {
|
|
11
|
+
constructor(message?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare function parseEnvironmentName(name: string): Environment;
|
|
14
|
+
export declare class Config {
|
|
15
|
+
#private;
|
|
16
|
+
constructor(configFilePath: string, configFile: ConfigFile);
|
|
17
|
+
setEnvironment(environment: Environment): Promise<void>;
|
|
18
|
+
setBaseUrl(baseUrl: string): Promise<void>;
|
|
19
|
+
get baseUrl(): string | undefined;
|
|
20
|
+
get token(): string | null;
|
|
21
|
+
get tokenInfo(): {
|
|
22
|
+
token: string;
|
|
23
|
+
spaceId: string;
|
|
24
|
+
cellId: string;
|
|
25
|
+
};
|
|
26
|
+
get environment(): "local" | "staging" | "dev" | "prod" | undefined;
|
|
27
|
+
get workerId(): string | null;
|
|
28
|
+
setToken(token: string | null): Promise<void>;
|
|
29
|
+
setWorkerId(workerId: string | null): Promise<void>;
|
|
30
|
+
static load(configFilePath: string): Promise<Config>;
|
|
31
|
+
}
|
|
32
|
+
export declare function extractPayloadFromToken(token: string): {
|
|
33
|
+
spaceId: string;
|
|
34
|
+
userId: string;
|
|
35
|
+
cellId: string;
|
|
36
|
+
};
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,8CAA+C,CAAC;AACzE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,UAAU,UAAU;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAM1D;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAEzC,OAAO,GAAE,MAA6D;CAKvE;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAM9D;AAED,qBAAa,MAAM;;gBAIN,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU;IAKpD,cAAc,CAAC,WAAW,EAAE,WAAW;IAKvC,UAAU,CAAC,OAAO,EAAE,MAAM;IAKhC,IAAI,OAAO,uBAEV;IAED,IAAI,KAAK,kBAER;IAED,IAAI,SAAS,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAQlE;IAED,IAAI,WAAW,qDAEd;IAED,IAAI,QAAQ,kBAEX;IAEK,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;WAa5B,IAAI,CAAC,cAAc,EAAE,MAAM;CAyBxC;AAQD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CACf,CAoCA"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
const Environments = ["local", "staging", "dev", "prod"];
|
|
4
|
+
function parseEnvironment(name) {
|
|
5
|
+
if (["local", "staging", "dev", "prod"].includes(name)) {
|
|
6
|
+
return name;
|
|
7
|
+
}
|
|
8
|
+
throw new Error(`Invalid environment name: ${name}`);
|
|
9
|
+
}
|
|
10
|
+
class TokenNotSetError extends Error {
|
|
11
|
+
constructor(message = "Not authenticated. Run 'workers auth login' first.") {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "TokenNotSetError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function parseEnvironmentName(name) {
|
|
17
|
+
if (["local", "staging", "dev", "prod"].includes(name)) {
|
|
18
|
+
return name;
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Invalid environment name: ${name}`);
|
|
21
|
+
}
|
|
22
|
+
class Config {
|
|
23
|
+
#configFile;
|
|
24
|
+
#configFilePath;
|
|
25
|
+
constructor(configFilePath, configFile) {
|
|
26
|
+
this.#configFilePath = configFilePath;
|
|
27
|
+
this.#configFile = configFile;
|
|
28
|
+
}
|
|
29
|
+
async setEnvironment(environment) {
|
|
30
|
+
this.#configFile.environment = environment;
|
|
31
|
+
await this.#writeConfigFile();
|
|
32
|
+
}
|
|
33
|
+
async setBaseUrl(baseUrl) {
|
|
34
|
+
this.#configFile.baseUrl = baseUrl;
|
|
35
|
+
await this.#writeConfigFile();
|
|
36
|
+
}
|
|
37
|
+
get baseUrl() {
|
|
38
|
+
return this.#configFile.baseUrl;
|
|
39
|
+
}
|
|
40
|
+
get token() {
|
|
41
|
+
return this.#configFile.token;
|
|
42
|
+
}
|
|
43
|
+
get tokenInfo() {
|
|
44
|
+
const token = this.#configFile.token;
|
|
45
|
+
if (!token) {
|
|
46
|
+
throw new TokenNotSetError();
|
|
47
|
+
}
|
|
48
|
+
const { spaceId, cellId } = extractPayloadFromToken(token);
|
|
49
|
+
return { token, spaceId, cellId };
|
|
50
|
+
}
|
|
51
|
+
get environment() {
|
|
52
|
+
return this.#configFile.environment;
|
|
53
|
+
}
|
|
54
|
+
get workerId() {
|
|
55
|
+
return this.#configFile.workerId;
|
|
56
|
+
}
|
|
57
|
+
async setToken(token) {
|
|
58
|
+
this.#configFile.token = token;
|
|
59
|
+
await this.#writeConfigFile();
|
|
60
|
+
}
|
|
61
|
+
async setWorkerId(workerId) {
|
|
62
|
+
this.#configFile.workerId = workerId;
|
|
63
|
+
await this.#writeConfigFile();
|
|
64
|
+
}
|
|
65
|
+
async #writeConfigFile() {
|
|
66
|
+
await fs.promises.writeFile(
|
|
67
|
+
this.#configFilePath,
|
|
68
|
+
JSON.stringify(this.#configFile, null, 2),
|
|
69
|
+
"utf-8"
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
static async load(configFilePath) {
|
|
73
|
+
const absConfigFilePath = path.resolve(process.cwd(), configFilePath);
|
|
74
|
+
const configFile = await Config.#readConfigFile(absConfigFilePath);
|
|
75
|
+
return new Config(absConfigFilePath, configFile);
|
|
76
|
+
}
|
|
77
|
+
static async #readConfigFile(configFilePath) {
|
|
78
|
+
let configFile;
|
|
79
|
+
try {
|
|
80
|
+
const configContents = await fs.promises.readFile(
|
|
81
|
+
configFilePath,
|
|
82
|
+
"utf-8"
|
|
83
|
+
);
|
|
84
|
+
configFile = JSON.parse(configContents);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (isENOENT(error)) {
|
|
87
|
+
configFile = { token: null, workerId: null };
|
|
88
|
+
} else {
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return configFile;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function isENOENT(error) {
|
|
96
|
+
return error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
97
|
+
}
|
|
98
|
+
function extractPayloadFromToken(token) {
|
|
99
|
+
try {
|
|
100
|
+
const parts = token.split(".");
|
|
101
|
+
if (parts.length !== 4 || !parts[2]) {
|
|
102
|
+
throw new Error("Invalid token format.");
|
|
103
|
+
}
|
|
104
|
+
const payloadBase64 = parts[2];
|
|
105
|
+
const payloadJson = Buffer.from(payloadBase64, "base64url").toString(
|
|
106
|
+
"utf-8"
|
|
107
|
+
);
|
|
108
|
+
const payload = JSON.parse(payloadJson);
|
|
109
|
+
if (!payload.spaceId || !payload.userId || !payload.cellId) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
"Token payload missing required fields (spaceId, userId, cellId)."
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
spaceId: payload.spaceId,
|
|
116
|
+
userId: payload.userId,
|
|
117
|
+
cellId: payload.cellId
|
|
118
|
+
};
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (error instanceof Error && error.message.startsWith("Token")) {
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
throw new Error("Failed to parse token payload.");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export {
|
|
127
|
+
Config,
|
|
128
|
+
Environments,
|
|
129
|
+
TokenNotSetError,
|
|
130
|
+
extractPayloadFromToken,
|
|
131
|
+
parseEnvironment,
|
|
132
|
+
parseEnvironmentName
|
|
133
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import type { StricliAutoCompleteContext } from "@stricli/auto-complete";
|
|
5
|
+
import type { CommandContext } from "@stricli/core";
|
|
6
|
+
import { Writer } from "./writer.js";
|
|
7
|
+
export interface LocalContext extends CommandContext, StricliAutoCompleteContext {
|
|
8
|
+
readonly fs: typeof fs;
|
|
9
|
+
readonly os: typeof os;
|
|
10
|
+
readonly path: typeof path;
|
|
11
|
+
readonly process: NodeJS.Process;
|
|
12
|
+
readonly writer: Writer;
|
|
13
|
+
}
|
|
14
|
+
export declare function buildContext(process: NodeJS.Process): LocalContext;
|
|
15
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +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,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,WAAW,YAChB,SAAQ,cAAc,EACrB,0BAA0B;IAC3B,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,GAAG,YAAY,CAQlE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { Writer } from "./writer.js";
|
|
5
|
+
function buildContext(process) {
|
|
6
|
+
return {
|
|
7
|
+
fs,
|
|
8
|
+
os,
|
|
9
|
+
path,
|
|
10
|
+
process,
|
|
11
|
+
writer: new Writer({ debugEnabled: false })
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
buildContext
|
|
16
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ApiError, Environment } from "./api/client.js";
|
|
2
|
+
import { Result } from "./api/result.js";
|
|
3
|
+
import type { AuthedContext } from "./handler.js";
|
|
4
|
+
export interface DeployOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Path to the worker directory to deploy
|
|
7
|
+
*/
|
|
8
|
+
workerPath: string;
|
|
9
|
+
/**
|
|
10
|
+
* API token for authentication
|
|
11
|
+
*/
|
|
12
|
+
token: string;
|
|
13
|
+
/**
|
|
14
|
+
* Environment to deploy to
|
|
15
|
+
*/
|
|
16
|
+
environment: Environment;
|
|
17
|
+
workerId?: string | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Deploy a worker to the specified environment
|
|
21
|
+
*/
|
|
22
|
+
export declare function deployWorker(context: AuthedContext, options: DeployOptions): Promise<Result<{
|
|
23
|
+
workerId: string;
|
|
24
|
+
}, ApiError>>;
|
|
25
|
+
//# sourceMappingURL=deploy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,CAAC,CAAC,CAiEjD"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import * as childProcess from "node:child_process";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import * as esbuild from "esbuild";
|
|
5
|
+
import { Result } from "./api/result.js";
|
|
6
|
+
async function deployWorker(context, options) {
|
|
7
|
+
const { workerPath, workerId: workerIdForUpdate } = options;
|
|
8
|
+
const absPath = path.resolve(process.cwd(), workerPath);
|
|
9
|
+
context.writer.debug(`Deploying worker from: ${absPath}`);
|
|
10
|
+
const client = context.apiClient;
|
|
11
|
+
let uploadUrl;
|
|
12
|
+
let uploadFields;
|
|
13
|
+
let workerId;
|
|
14
|
+
context.writer.writeErr(
|
|
15
|
+
workerIdForUpdate ? `Updating worker...` : `Creating worker...`
|
|
16
|
+
);
|
|
17
|
+
if (workerIdForUpdate) {
|
|
18
|
+
workerId = workerIdForUpdate;
|
|
19
|
+
const updateResult = await client.updateWorkerBundle(workerIdForUpdate);
|
|
20
|
+
if (Result.isSuccess(updateResult)) {
|
|
21
|
+
const res = Result.unwrap(updateResult);
|
|
22
|
+
uploadUrl = res.url;
|
|
23
|
+
uploadFields = res.fields;
|
|
24
|
+
} else {
|
|
25
|
+
context.writer.writeErr(
|
|
26
|
+
"Failed to generate pre-signed upload URL for worker bundle:"
|
|
27
|
+
);
|
|
28
|
+
throw new Error(updateResult.error.message);
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
const createResult = await client.createWorker("tmp-give-me-a-good-name");
|
|
32
|
+
if (Result.isSuccess(createResult)) {
|
|
33
|
+
const res = Result.unwrap(createResult);
|
|
34
|
+
uploadUrl = res.url;
|
|
35
|
+
uploadFields = res.fields;
|
|
36
|
+
workerId = res.worker.workerId;
|
|
37
|
+
} else {
|
|
38
|
+
console.error("Failed to create worker:");
|
|
39
|
+
throw new Error(createResult.error.message);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
context.writer.debug(`Generated upload URL: ${uploadUrl}`);
|
|
43
|
+
context.writer.writeErr("Building worker bundle...");
|
|
44
|
+
const archivePath = await buildWorkerBundle(context, absPath);
|
|
45
|
+
context.writer.debug(`Created bundle at: ${archivePath}`);
|
|
46
|
+
context.writer.writeErr("Uploading bundle...");
|
|
47
|
+
await uploadBundle(uploadUrl, uploadFields, archivePath);
|
|
48
|
+
context.writer.debug("Upload complete");
|
|
49
|
+
context.writer.writeErr("Fetching and saving worker capabilities...");
|
|
50
|
+
const capabilitiesResult = await client.fetchAndSaveCapabilities(workerId);
|
|
51
|
+
if (Result.isSuccess(capabilitiesResult)) {
|
|
52
|
+
return Result.success({ workerId });
|
|
53
|
+
} else {
|
|
54
|
+
return capabilitiesResult;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function buildWorkerBundle(context, workerPath) {
|
|
58
|
+
const entrypoint = "src/index.ts";
|
|
59
|
+
if (!fs.existsSync(path.join(workerPath, entrypoint))) {
|
|
60
|
+
throw new Error(`Entrypoint not found: ${entrypoint}`);
|
|
61
|
+
}
|
|
62
|
+
const outdir = fs.mkdtempSync("/tmp/workers-build-");
|
|
63
|
+
esbuild.buildSync({
|
|
64
|
+
entryPoints: [entrypoint],
|
|
65
|
+
absWorkingDir: workerPath,
|
|
66
|
+
bundle: true,
|
|
67
|
+
outdir,
|
|
68
|
+
platform: "node"
|
|
69
|
+
});
|
|
70
|
+
context.writer.debug(`Built bundle to: ${outdir}`);
|
|
71
|
+
const archiveDir = fs.mkdtempSync("/tmp/workers-archive-");
|
|
72
|
+
const archivePath = path.join(archiveDir, "archive.tar.gz");
|
|
73
|
+
childProcess.execSync(`tar -czf ${archivePath} -C ${outdir} .`);
|
|
74
|
+
return archivePath;
|
|
75
|
+
}
|
|
76
|
+
async function uploadBundle(url, fields, archivePath) {
|
|
77
|
+
const formData = new FormData();
|
|
78
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
79
|
+
formData.append(key, value);
|
|
80
|
+
}
|
|
81
|
+
const fileBuffer = fs.readFileSync(archivePath);
|
|
82
|
+
formData.append(
|
|
83
|
+
"file",
|
|
84
|
+
new Blob([new Uint8Array(fileBuffer)]),
|
|
85
|
+
"archive.tar.gz"
|
|
86
|
+
);
|
|
87
|
+
const response = await fetch(url, {
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: formData
|
|
90
|
+
});
|
|
91
|
+
if (!response.ok) {
|
|
92
|
+
const errorText = await response.text();
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Failed to upload bundle: ${response.status} ${response.statusText}
|
|
95
|
+
${errorText}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
deployWorker
|
|
101
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TypedFlagParameter } from "@stricli/core";
|
|
2
|
+
import type { LocalContext } from "./context.js";
|
|
3
|
+
export interface GlobalFlags {
|
|
4
|
+
config?: string;
|
|
5
|
+
debug: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const globalFlags: {
|
|
8
|
+
[K in keyof Required<GlobalFlags>]: TypedFlagParameter<GlobalFlags[K], LocalContext>;
|
|
9
|
+
};
|
|
10
|
+
export interface FormatFlags {
|
|
11
|
+
plain: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const formatFlags: {
|
|
14
|
+
[K in keyof Required<FormatFlags>]: TypedFlagParameter<FormatFlags[K], LocalContext>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../../src/cli/flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,WAAW;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CACf;AAED,eAAO,MAAM,WAAW,EAAE;KACxB,CAAC,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,kBAAkB,CACrD,WAAW,CAAC,CAAC,CAAC,EACd,YAAY,CACZ;CAaD,CAAC;AAEF,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,OAAO,CAAC;CACf;AAED,eAAO,MAAM,WAAW,EAAE;KACxB,CAAC,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,kBAAkB,CACrD,WAAW,CAAC,CAAC,CAAC,EACd,YAAY,CACZ;CAOD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const globalFlags = {
|
|
2
|
+
config: {
|
|
3
|
+
kind: "parsed",
|
|
4
|
+
parse: String,
|
|
5
|
+
brief: "The path to the config file to use",
|
|
6
|
+
optional: true
|
|
7
|
+
},
|
|
8
|
+
debug: {
|
|
9
|
+
kind: "boolean",
|
|
10
|
+
brief: "Enable debug logging",
|
|
11
|
+
default: false
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const formatFlags = {
|
|
15
|
+
plain: {
|
|
16
|
+
kind: "boolean",
|
|
17
|
+
brief: "Output the results in plain text format",
|
|
18
|
+
default: false
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
formatFlags,
|
|
23
|
+
globalFlags
|
|
24
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BaseArgs } from "@stricli/core";
|
|
2
|
+
import { ApiClient } from "./api/client.js";
|
|
3
|
+
import { Config } from "./config.js";
|
|
4
|
+
import type { LocalContext } from "./context.js";
|
|
5
|
+
import type { GlobalFlags } from "./flags.js";
|
|
6
|
+
export interface HandlerContext extends LocalContext {
|
|
7
|
+
config: Config;
|
|
8
|
+
}
|
|
9
|
+
export interface AuthedContext extends HandlerContext {
|
|
10
|
+
apiClient: ApiClient;
|
|
11
|
+
}
|
|
12
|
+
export declare function buildHandler<const FLAGS, const ARGS extends BaseArgs = []>(handler: (this: HandlerContext, flags: FLAGS, ...args: ARGS) => Promise<void> | void): (this: LocalContext, flags: GlobalFlags & FLAGS, ...args: ARGS) => Promise<void>;
|
|
13
|
+
export declare function buildAuthedHandler<const FLAGS, const ARGS extends BaseArgs = []>(handler: (this: AuthedContext, flags: FLAGS, ...args: ARGS) => Promise<void> | void): (this: LocalContext, flags: GlobalFlags & FLAGS, ...args: ARGS) => Promise<void>;
|
|
14
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/cli/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,cAAe,SAAQ,YAAY;IACnD,MAAM,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc;IACpD,SAAS,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,SAAS,QAAQ,GAAG,EAAE,EACzE,OAAO,EAAE,CACR,IAAI,EAAE,cAAc,EACpB,KAAK,EAAE,KAAK,EACZ,GAAG,IAAI,EAAE,IAAI,KACT,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,IAGxB,MAAM,YAAY,EAClB,OAAO,WAAW,GAAG,KAAK,EAC1B,GAAG,MAAM,IAAI,mBAQd;AAED,wBAAgB,kBAAkB,CACjC,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,IAAI,SAAS,QAAQ,GAAG,EAAE,EAEhC,OAAO,EAAE,CACR,IAAI,EAAE,aAAa,EACnB,KAAK,EAAE,KAAK,EACZ,GAAG,IAAI,EAAE,IAAI,KACT,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,UApBlB,YAAY,8DAuCnB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ApiClient } from "./api/client.js";
|
|
2
|
+
import { Config } from "./config.js";
|
|
3
|
+
function buildHandler(handler) {
|
|
4
|
+
return async function(flags, ...args) {
|
|
5
|
+
const config = await Config.load(flags.config ?? "./workers.json");
|
|
6
|
+
this.writer.debugEnabled = flags.debug;
|
|
7
|
+
await handler.call({ ...this, config }, flags, ...args);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function buildAuthedHandler(handler) {
|
|
11
|
+
return buildHandler(function(flags, ...args) {
|
|
12
|
+
const environment = this.config.environment;
|
|
13
|
+
if (!environment) {
|
|
14
|
+
throw new Error("Unexpected error: Environment not set");
|
|
15
|
+
}
|
|
16
|
+
const { token, cellId } = this.config.tokenInfo;
|
|
17
|
+
const client = new ApiClient({
|
|
18
|
+
token,
|
|
19
|
+
environment,
|
|
20
|
+
baseUrl: this.config.baseUrl,
|
|
21
|
+
cellId,
|
|
22
|
+
writer: this.writer
|
|
23
|
+
});
|
|
24
|
+
return handler.call({ ...this, apiClient: client }, flags, ...args);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
buildAuthedHandler,
|
|
29
|
+
buildHandler
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/cli/routes.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,GAAG,0EAgBd,CAAC"}
|