@project-ajax/sdk 0.0.60 → 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.
Files changed (142) hide show
  1. package/package.json +3 -11
  2. package/dist/cli/api/client.d.ts +0 -212
  3. package/dist/cli/api/client.d.ts.map +0 -1
  4. package/dist/cli/api/client.js +0 -330
  5. package/dist/cli/api/result.d.ts +0 -43
  6. package/dist/cli/api/result.d.ts.map +0 -1
  7. package/dist/cli/api/result.js +0 -43
  8. package/dist/cli/bin/cli.d.ts +0 -3
  9. package/dist/cli/bin/cli.d.ts.map +0 -1
  10. package/dist/cli/bin/cli.js +0 -5
  11. package/dist/cli/commands/auth.d.ts +0 -2
  12. package/dist/cli/commands/auth.d.ts.map +0 -1
  13. package/dist/cli/commands/auth.impl.d.ts +0 -5
  14. package/dist/cli/commands/auth.impl.d.ts.map +0 -1
  15. package/dist/cli/commands/auth.impl.js +0 -45
  16. package/dist/cli/commands/auth.impl.test.d.ts +0 -2
  17. package/dist/cli/commands/auth.impl.test.d.ts.map +0 -1
  18. package/dist/cli/commands/auth.js +0 -56
  19. package/dist/cli/commands/bundle.d.ts +0 -2
  20. package/dist/cli/commands/bundle.d.ts.map +0 -1
  21. package/dist/cli/commands/bundle.impl.d.ts +0 -2
  22. package/dist/cli/commands/bundle.impl.d.ts.map +0 -1
  23. package/dist/cli/commands/bundle.impl.js +0 -21
  24. package/dist/cli/commands/bundle.impl.test.d.ts +0 -2
  25. package/dist/cli/commands/bundle.impl.test.d.ts.map +0 -1
  26. package/dist/cli/commands/bundle.js +0 -23
  27. package/dist/cli/commands/capabilities.d.ts +0 -2
  28. package/dist/cli/commands/capabilities.d.ts.map +0 -1
  29. package/dist/cli/commands/capabilities.impl.d.ts +0 -3
  30. package/dist/cli/commands/capabilities.impl.d.ts.map +0 -1
  31. package/dist/cli/commands/capabilities.impl.js +0 -40
  32. package/dist/cli/commands/capabilities.js +0 -24
  33. package/dist/cli/commands/connect.d.ts +0 -2
  34. package/dist/cli/commands/connect.d.ts.map +0 -1
  35. package/dist/cli/commands/connect.impl.d.ts +0 -6
  36. package/dist/cli/commands/connect.impl.d.ts.map +0 -1
  37. package/dist/cli/commands/connect.impl.js +0 -116
  38. package/dist/cli/commands/connect.js +0 -78
  39. package/dist/cli/commands/deploy.d.ts +0 -3
  40. package/dist/cli/commands/deploy.d.ts.map +0 -1
  41. package/dist/cli/commands/deploy.impl.d.ts +0 -6
  42. package/dist/cli/commands/deploy.impl.d.ts.map +0 -1
  43. package/dist/cli/commands/deploy.impl.js +0 -60
  44. package/dist/cli/commands/deploy.impl.test.d.ts +0 -2
  45. package/dist/cli/commands/deploy.impl.test.d.ts.map +0 -1
  46. package/dist/cli/commands/deploy.js +0 -22
  47. package/dist/cli/commands/env.d.ts +0 -2
  48. package/dist/cli/commands/env.d.ts.map +0 -1
  49. package/dist/cli/commands/env.impl.d.ts +0 -11
  50. package/dist/cli/commands/env.impl.d.ts.map +0 -1
  51. package/dist/cli/commands/env.impl.js +0 -62
  52. package/dist/cli/commands/env.js +0 -39
  53. package/dist/cli/commands/exec.d.ts +0 -3
  54. package/dist/cli/commands/exec.d.ts.map +0 -1
  55. package/dist/cli/commands/exec.impl.d.ts +0 -7
  56. package/dist/cli/commands/exec.impl.d.ts.map +0 -1
  57. package/dist/cli/commands/exec.impl.js +0 -123
  58. package/dist/cli/commands/exec.js +0 -30
  59. package/dist/cli/commands/runs.d.ts +0 -2
  60. package/dist/cli/commands/runs.d.ts.map +0 -1
  61. package/dist/cli/commands/runs.impl.d.ts +0 -4
  62. package/dist/cli/commands/runs.impl.d.ts.map +0 -1
  63. package/dist/cli/commands/runs.impl.js +0 -71
  64. package/dist/cli/commands/runs.js +0 -45
  65. package/dist/cli/commands/secrets.d.ts +0 -2
  66. package/dist/cli/commands/secrets.d.ts.map +0 -1
  67. package/dist/cli/commands/secrets.impl.d.ts +0 -5
  68. package/dist/cli/commands/secrets.impl.d.ts.map +0 -1
  69. package/dist/cli/commands/secrets.impl.js +0 -99
  70. package/dist/cli/commands/secrets.js +0 -64
  71. package/dist/cli/commands/utils/testing.d.ts +0 -13
  72. package/dist/cli/commands/utils/testing.d.ts.map +0 -1
  73. package/dist/cli/commands/utils/testing.js +0 -58
  74. package/dist/cli/config.d.ts +0 -63
  75. package/dist/cli/config.d.ts.map +0 -1
  76. package/dist/cli/config.js +0 -194
  77. package/dist/cli/config.test.d.ts +0 -2
  78. package/dist/cli/config.test.d.ts.map +0 -1
  79. package/dist/cli/context.d.ts +0 -15
  80. package/dist/cli/context.d.ts.map +0 -1
  81. package/dist/cli/context.js +0 -16
  82. package/dist/cli/deploy.d.ts +0 -37
  83. package/dist/cli/deploy.d.ts.map +0 -1
  84. package/dist/cli/deploy.js +0 -100
  85. package/dist/cli/flags.d.ts +0 -21
  86. package/dist/cli/flags.d.ts.map +0 -1
  87. package/dist/cli/flags.js +0 -49
  88. package/dist/cli/handler.d.ts +0 -14
  89. package/dist/cli/handler.d.ts.map +0 -1
  90. package/dist/cli/handler.js +0 -32
  91. package/dist/cli/io.d.ts +0 -55
  92. package/dist/cli/io.d.ts.map +0 -1
  93. package/dist/cli/io.js +0 -96
  94. package/dist/cli/routes.d.ts +0 -2
  95. package/dist/cli/routes.d.ts.map +0 -1
  96. package/dist/cli/routes.js +0 -62
  97. package/dist/cli/utils/array.d.ts +0 -2
  98. package/dist/cli/utils/array.d.ts.map +0 -1
  99. package/dist/cli/utils/array.js +0 -10
  100. package/dist/cli/utils/openUrl.d.ts +0 -4
  101. package/dist/cli/utils/openUrl.d.ts.map +0 -1
  102. package/dist/cli/utils/openUrl.js +0 -43
  103. package/dist/cli/utils/string.d.ts +0 -2
  104. package/dist/cli/utils/string.d.ts.map +0 -1
  105. package/dist/cli/utils/string.js +0 -12
  106. package/src/cli/api/client.ts +0 -628
  107. package/src/cli/api/result.ts +0 -71
  108. package/src/cli/bin/cli.ts +0 -7
  109. package/src/cli/commands/.cursor/rules/testing-commands.mdc +0 -212
  110. package/src/cli/commands/auth.impl.test.ts +0 -228
  111. package/src/cli/commands/auth.impl.ts +0 -56
  112. package/src/cli/commands/auth.ts +0 -63
  113. package/src/cli/commands/bundle.impl.test.ts +0 -143
  114. package/src/cli/commands/bundle.impl.ts +0 -21
  115. package/src/cli/commands/bundle.ts +0 -23
  116. package/src/cli/commands/capabilities.impl.ts +0 -47
  117. package/src/cli/commands/capabilities.ts +0 -25
  118. package/src/cli/commands/connect.impl.ts +0 -149
  119. package/src/cli/commands/connect.ts +0 -80
  120. package/src/cli/commands/deploy.impl.test.ts +0 -254
  121. package/src/cli/commands/deploy.impl.ts +0 -73
  122. package/src/cli/commands/deploy.ts +0 -22
  123. package/src/cli/commands/env.impl.ts +0 -88
  124. package/src/cli/commands/env.ts +0 -38
  125. package/src/cli/commands/exec.impl.ts +0 -171
  126. package/src/cli/commands/exec.ts +0 -32
  127. package/src/cli/commands/runs.impl.ts +0 -87
  128. package/src/cli/commands/runs.ts +0 -49
  129. package/src/cli/commands/secrets.impl.ts +0 -130
  130. package/src/cli/commands/secrets.ts +0 -73
  131. package/src/cli/commands/utils/testing.ts +0 -66
  132. package/src/cli/config.test.ts +0 -108
  133. package/src/cli/config.ts +0 -265
  134. package/src/cli/context.ts +0 -26
  135. package/src/cli/deploy.ts +0 -190
  136. package/src/cli/flags.ts +0 -72
  137. package/src/cli/handler.ts +0 -68
  138. package/src/cli/io.ts +0 -132
  139. package/src/cli/routes.ts +0 -61
  140. package/src/cli/utils/array.ts +0 -7
  141. package/src/cli/utils/openUrl.ts +0 -53
  142. package/src/cli/utils/string.ts +0 -9
@@ -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
- };
@@ -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,3 +0,0 @@
1
- declare const _default: import("@stricli/core").Command<import("../context.js").LocalContext>;
2
- export default _default;
3
- //# sourceMappingURL=exec.d.ts.map
@@ -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
- };
@@ -1,30 +0,0 @@
1
- import { buildCommand } from "@stricli/core";
2
- import { globalFlags } from "../flags.js";
3
- var exec_default = buildCommand({
4
- docs: {
5
- brief: "Execute a worker capability with optional function and arguments"
6
- },
7
- parameters: {
8
- positional: {
9
- kind: "array",
10
- parameter: {
11
- brief: "Capability name, optional function name, and arguments (key value pairs)",
12
- parse: String,
13
- placeholder: "capabilityName [functionName] [key value]..."
14
- },
15
- minimum: 1
16
- },
17
- flags: {
18
- ...globalFlags,
19
- stream: {
20
- kind: "boolean",
21
- brief: "Stream the output of the capability",
22
- default: true
23
- }
24
- }
25
- },
26
- loader: () => import("./exec.impl.js").then((m) => m.exec)
27
- });
28
- export {
29
- exec_default as default
30
- };
@@ -1,2 +0,0 @@
1
- export declare const runsCommands: import("@stricli/core").RouteMap<import("../context.js").LocalContext>;
2
- //# sourceMappingURL=runs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runs.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/runs.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,wEA6CvB,CAAC"}
@@ -1,4 +0,0 @@
1
- import type { FormatFlags, GlobalFlags } from "../flags.js";
2
- export declare const listRuns: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
3
- export declare const getRunLogs: (this: import("../context.js").LocalContext, flags: GlobalFlags, runId: string) => Promise<void>;
4
- //# sourceMappingURL=runs.impl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runs.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/runs.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG5D,eAAO,MAAM,QAAQ,iGA2CnB,CAAC;AAEH,eAAO,MAAM,UAAU,kGAqCrB,CAAC"}
@@ -1,71 +0,0 @@
1
- import { Result } from "../api/result.js";
2
- import { buildAuthedHandler } from "../handler.js";
3
- const listRuns = 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 runs...");
11
- const result = await this.apiClient.listRunsForWorker(workerId);
12
- if (Result.isSuccess(result)) {
13
- this.process.stderr.write("OK\n\n");
14
- const data = Result.unwrap(result);
15
- if (data.runs.length === 0) {
16
- this.io.writeErr("No runs found for this worker.");
17
- } else {
18
- this.io.writeTableOut({
19
- headers: ["Run ID", "Name", "Started At", "Ended At", "Exit Code"],
20
- rows: data.runs.map((run) => [
21
- run.runId,
22
- run.name,
23
- run.startedAt,
24
- run.endedAt,
25
- run.exitCode
26
- ]),
27
- plain: flags.plain
28
- });
29
- }
30
- } else {
31
- this.process.stderr.write("ERROR\n\n");
32
- if (result.error.validationError) {
33
- this.io.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
34
- throw new Error(result.error.validationError.debugMessage);
35
- } else {
36
- this.io.writeErr(`\u2717 ${result.error.message}`);
37
- throw new Error(result.error.message);
38
- }
39
- }
40
- });
41
- const getRunLogs = buildAuthedHandler(async function(_flags, runId) {
42
- const { workerId } = this.config;
43
- if (!workerId) {
44
- throw new Error(
45
- "No worker configured. Run 'workers deploy' first to create a worker."
46
- );
47
- }
48
- if (!runId) {
49
- throw new Error("Run ID is required");
50
- }
51
- this.process.stderr.write(`Fetching logs for run ${runId}...`);
52
- const result = await this.apiClient.getRunLogs(workerId, runId);
53
- if (Result.isSuccess(result)) {
54
- this.process.stderr.write("OK\n\n");
55
- const data = Result.unwrap(result);
56
- this.io.writeOut(data.logs);
57
- } else {
58
- this.process.stderr.write("ERROR\n\n");
59
- if (result.error.validationError) {
60
- this.io.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
61
- throw new Error(result.error.validationError.debugMessage);
62
- } else {
63
- this.io.writeErr(`\u2717 ${result.error.message}`);
64
- throw new Error(result.error.message);
65
- }
66
- }
67
- });
68
- export {
69
- getRunLogs,
70
- listRuns
71
- };
@@ -1,45 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- export declare const secretsCommands: import("@stricli/core").RouteMap<import("../context.js").LocalContext>;
2
- //# sourceMappingURL=secrets.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/secrets.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe,wEAqE1B,CAAC"}
@@ -1,5 +0,0 @@
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
@@ -1 +0,0 @@
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,iGAwCtB,CAAC;AAEH,eAAO,MAAM,YAAY,gGAwBvB,CAAC"}
@@ -1,99 +0,0 @@
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.io.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.io.writeErr(`Set secret "${secret.key}"`);
18
- }
19
- } else {
20
- this.io.writeErr(`\u2717 Failed to set secrets`);
21
- this.io.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.io.writeErr("No secrets for this worker.");
39
- this.io.writeErr(
40
- "To list OAuth connect secrets, use `npx workers connect list`"
41
- );
42
- } else {
43
- this.io.writeTableOut({
44
- headers: ["Key", "Created At"],
45
- rows: data.secrets.map((secret) => [secret.key, secret.createdAt]),
46
- plain: flags.plain
47
- });
48
- this.io.writeErr(
49
- "To list OAuth connect secrets, use `npx workers connect list`"
50
- );
51
- }
52
- } else {
53
- this.process.stderr.write("ERROR\n\n");
54
- this.io.writeErr(`\u2717 Failed to list secrets`);
55
- this.io.writeErr(`\u2717 ${result.error.message}`);
56
- throw new Error(result.error.message);
57
- }
58
- });
59
- const removeSecret = buildAuthedHandler(async function(_flags, key) {
60
- const { workerId } = this.config;
61
- if (!workerId) {
62
- throw new Error(
63
- "No worker configured. Run 'workers deploy' first to create a worker."
64
- );
65
- }
66
- this.process.stderr.write(`Removing secret "${key}"...`);
67
- const result = await this.apiClient.deleteSecret(workerId, key);
68
- if (Result.isSuccess(result)) {
69
- this.process.stderr.write("OK\n\n");
70
- } else {
71
- this.process.stderr.write("ERROR\n\n");
72
- this.io.writeErr(`\u2717 Failed to remove secret "${key}"`);
73
- this.io.writeErr(`\u2717 ${result.error.message}`);
74
- throw new Error(result.error.message);
75
- }
76
- });
77
- function usageError() {
78
- return new Error(
79
- "Invalid secrets provided. Usage: workers secrets set <key> <value> [<key2> <value2>...] or <key>=<value> [<key2>=<value2>...]"
80
- );
81
- }
82
- function parseSecretArgs(args) {
83
- if (args.length === 0) {
84
- throw usageError();
85
- }
86
- const tokens = args.flatMap((arg) => arg.split(/[=:]/));
87
- const secrets = chunkEvery(tokens, 2).map(([key, value]) => {
88
- if (!key || !value) {
89
- throw usageError();
90
- }
91
- return { key, value };
92
- });
93
- return secrets;
94
- }
95
- export {
96
- listSecrets,
97
- removeSecret,
98
- setSecrets
99
- };
@@ -1,64 +0,0 @@
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
- };
@@ -1,13 +0,0 @@
1
- import { Config, type ConfigMap } from "../../config.js";
2
- import type { LocalContext } from "../../context.js";
3
- import type { GlobalFlags } from "../../flags.js";
4
- export declare const tmpDirectories: string[];
5
- export declare const baseFlags: GlobalFlags;
6
- export declare function createAndLoadConfig({ configFile, env, flags, }: {
7
- configFile: Partial<ConfigMap>;
8
- env?: Partial<NodeJS.ProcessEnv>;
9
- flags?: Partial<GlobalFlags>;
10
- }): Promise<[config: Config, path: string]>;
11
- export declare function createBaseContext(): LocalContext;
12
- export declare function cleanupTmpDirectories(): Promise<void>;
13
- //# sourceMappingURL=testing.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/utils/testing.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,eAAO,MAAM,cAAc,EAAE,MAAM,EAAO,CAAC;AAE3C,eAAO,MAAM,SAAS,EAAE,WAEvB,CAAC;AAEF,wBAAsB,mBAAmB,CAAC,EACzC,UAAU,EACV,GAAG,EACH,KAAK,GACL,EAAE;IACF,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/B,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAC7B,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAa1C;AAED,wBAAgB,iBAAiB,IAAI,YAAY,CAQhD;AAED,wBAAsB,qBAAqB,kBAO1C"}
@@ -1,58 +0,0 @@
1
- import * as fs from "node:fs";
2
- import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
- import * as os from "node:os";
4
- import { tmpdir } from "node:os";
5
- import * as path from "node:path";
6
- import { Config } from "../../config.js";
7
- import { IO } from "../../io.js";
8
- const tmpDirectories = [];
9
- const baseFlags = {
10
- debug: false
11
- };
12
- async function createAndLoadConfig({
13
- configFile,
14
- env,
15
- flags
16
- }) {
17
- const configFilePath = await createConfigFile(configFile);
18
- const map = await Config.load({
19
- configFilePath,
20
- processEnv: env ?? {},
21
- flags: {
22
- ...baseFlags,
23
- ...flags ?? {}
24
- }
25
- });
26
- return [map, configFilePath];
27
- }
28
- function createBaseContext() {
29
- return {
30
- fs,
31
- io: new IO({ debugEnabled: false }),
32
- os,
33
- path,
34
- process
35
- };
36
- }
37
- async function cleanupTmpDirectories() {
38
- while (tmpDirectories.length > 0) {
39
- const dir = tmpDirectories.pop();
40
- if (dir) {
41
- await rm(dir, { recursive: true, force: true });
42
- }
43
- }
44
- }
45
- async function createConfigFile(contents) {
46
- const dir = await mkdtemp(path.join(tmpdir(), "cmd-test-"));
47
- tmpDirectories.push(dir);
48
- const configFilePath = path.join(dir, "config.json");
49
- await writeFile(configFilePath, JSON.stringify(contents, null, 2), "utf-8");
50
- return configFilePath;
51
- }
52
- export {
53
- baseFlags,
54
- cleanupTmpDirectories,
55
- createAndLoadConfig,
56
- createBaseContext,
57
- tmpDirectories
58
- };