@project-ajax/sdk 0.0.60 → 0.0.62

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 (150) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +0 -2
  4. package/package.json +4 -16
  5. package/src/index.ts +0 -1
  6. package/dist/capabilities/slashCommand.d.ts +0 -56
  7. package/dist/capabilities/slashCommand.d.ts.map +0 -1
  8. package/dist/capabilities/slashCommand.js +0 -32
  9. package/dist/cli/api/client.d.ts +0 -212
  10. package/dist/cli/api/client.d.ts.map +0 -1
  11. package/dist/cli/api/client.js +0 -330
  12. package/dist/cli/api/result.d.ts +0 -43
  13. package/dist/cli/api/result.d.ts.map +0 -1
  14. package/dist/cli/api/result.js +0 -43
  15. package/dist/cli/bin/cli.d.ts +0 -3
  16. package/dist/cli/bin/cli.d.ts.map +0 -1
  17. package/dist/cli/bin/cli.js +0 -5
  18. package/dist/cli/commands/auth.d.ts +0 -2
  19. package/dist/cli/commands/auth.d.ts.map +0 -1
  20. package/dist/cli/commands/auth.impl.d.ts +0 -5
  21. package/dist/cli/commands/auth.impl.d.ts.map +0 -1
  22. package/dist/cli/commands/auth.impl.js +0 -45
  23. package/dist/cli/commands/auth.impl.test.d.ts +0 -2
  24. package/dist/cli/commands/auth.impl.test.d.ts.map +0 -1
  25. package/dist/cli/commands/auth.js +0 -56
  26. package/dist/cli/commands/bundle.d.ts +0 -2
  27. package/dist/cli/commands/bundle.d.ts.map +0 -1
  28. package/dist/cli/commands/bundle.impl.d.ts +0 -2
  29. package/dist/cli/commands/bundle.impl.d.ts.map +0 -1
  30. package/dist/cli/commands/bundle.impl.js +0 -21
  31. package/dist/cli/commands/bundle.impl.test.d.ts +0 -2
  32. package/dist/cli/commands/bundle.impl.test.d.ts.map +0 -1
  33. package/dist/cli/commands/bundle.js +0 -23
  34. package/dist/cli/commands/capabilities.d.ts +0 -2
  35. package/dist/cli/commands/capabilities.d.ts.map +0 -1
  36. package/dist/cli/commands/capabilities.impl.d.ts +0 -3
  37. package/dist/cli/commands/capabilities.impl.d.ts.map +0 -1
  38. package/dist/cli/commands/capabilities.impl.js +0 -40
  39. package/dist/cli/commands/capabilities.js +0 -24
  40. package/dist/cli/commands/connect.d.ts +0 -2
  41. package/dist/cli/commands/connect.d.ts.map +0 -1
  42. package/dist/cli/commands/connect.impl.d.ts +0 -6
  43. package/dist/cli/commands/connect.impl.d.ts.map +0 -1
  44. package/dist/cli/commands/connect.impl.js +0 -116
  45. package/dist/cli/commands/connect.js +0 -78
  46. package/dist/cli/commands/deploy.d.ts +0 -3
  47. package/dist/cli/commands/deploy.d.ts.map +0 -1
  48. package/dist/cli/commands/deploy.impl.d.ts +0 -6
  49. package/dist/cli/commands/deploy.impl.d.ts.map +0 -1
  50. package/dist/cli/commands/deploy.impl.js +0 -60
  51. package/dist/cli/commands/deploy.impl.test.d.ts +0 -2
  52. package/dist/cli/commands/deploy.impl.test.d.ts.map +0 -1
  53. package/dist/cli/commands/deploy.js +0 -22
  54. package/dist/cli/commands/env.d.ts +0 -2
  55. package/dist/cli/commands/env.d.ts.map +0 -1
  56. package/dist/cli/commands/env.impl.d.ts +0 -11
  57. package/dist/cli/commands/env.impl.d.ts.map +0 -1
  58. package/dist/cli/commands/env.impl.js +0 -62
  59. package/dist/cli/commands/env.js +0 -39
  60. package/dist/cli/commands/exec.d.ts +0 -3
  61. package/dist/cli/commands/exec.d.ts.map +0 -1
  62. package/dist/cli/commands/exec.impl.d.ts +0 -7
  63. package/dist/cli/commands/exec.impl.d.ts.map +0 -1
  64. package/dist/cli/commands/exec.impl.js +0 -123
  65. package/dist/cli/commands/exec.js +0 -30
  66. package/dist/cli/commands/runs.d.ts +0 -2
  67. package/dist/cli/commands/runs.d.ts.map +0 -1
  68. package/dist/cli/commands/runs.impl.d.ts +0 -4
  69. package/dist/cli/commands/runs.impl.d.ts.map +0 -1
  70. package/dist/cli/commands/runs.impl.js +0 -71
  71. package/dist/cli/commands/runs.js +0 -45
  72. package/dist/cli/commands/secrets.d.ts +0 -2
  73. package/dist/cli/commands/secrets.d.ts.map +0 -1
  74. package/dist/cli/commands/secrets.impl.d.ts +0 -5
  75. package/dist/cli/commands/secrets.impl.d.ts.map +0 -1
  76. package/dist/cli/commands/secrets.impl.js +0 -99
  77. package/dist/cli/commands/secrets.js +0 -64
  78. package/dist/cli/commands/utils/testing.d.ts +0 -13
  79. package/dist/cli/commands/utils/testing.d.ts.map +0 -1
  80. package/dist/cli/commands/utils/testing.js +0 -58
  81. package/dist/cli/config.d.ts +0 -63
  82. package/dist/cli/config.d.ts.map +0 -1
  83. package/dist/cli/config.js +0 -194
  84. package/dist/cli/config.test.d.ts +0 -2
  85. package/dist/cli/config.test.d.ts.map +0 -1
  86. package/dist/cli/context.d.ts +0 -15
  87. package/dist/cli/context.d.ts.map +0 -1
  88. package/dist/cli/context.js +0 -16
  89. package/dist/cli/deploy.d.ts +0 -37
  90. package/dist/cli/deploy.d.ts.map +0 -1
  91. package/dist/cli/deploy.js +0 -100
  92. package/dist/cli/flags.d.ts +0 -21
  93. package/dist/cli/flags.d.ts.map +0 -1
  94. package/dist/cli/flags.js +0 -49
  95. package/dist/cli/handler.d.ts +0 -14
  96. package/dist/cli/handler.d.ts.map +0 -1
  97. package/dist/cli/handler.js +0 -32
  98. package/dist/cli/io.d.ts +0 -55
  99. package/dist/cli/io.d.ts.map +0 -1
  100. package/dist/cli/io.js +0 -96
  101. package/dist/cli/routes.d.ts +0 -2
  102. package/dist/cli/routes.d.ts.map +0 -1
  103. package/dist/cli/routes.js +0 -62
  104. package/dist/cli/utils/array.d.ts +0 -2
  105. package/dist/cli/utils/array.d.ts.map +0 -1
  106. package/dist/cli/utils/array.js +0 -10
  107. package/dist/cli/utils/openUrl.d.ts +0 -4
  108. package/dist/cli/utils/openUrl.d.ts.map +0 -1
  109. package/dist/cli/utils/openUrl.js +0 -43
  110. package/dist/cli/utils/string.d.ts +0 -2
  111. package/dist/cli/utils/string.d.ts.map +0 -1
  112. package/dist/cli/utils/string.js +0 -12
  113. package/src/capabilities/slashCommand.ts +0 -71
  114. package/src/cli/api/client.ts +0 -628
  115. package/src/cli/api/result.ts +0 -71
  116. package/src/cli/bin/cli.ts +0 -7
  117. package/src/cli/commands/.cursor/rules/testing-commands.mdc +0 -212
  118. package/src/cli/commands/auth.impl.test.ts +0 -228
  119. package/src/cli/commands/auth.impl.ts +0 -56
  120. package/src/cli/commands/auth.ts +0 -63
  121. package/src/cli/commands/bundle.impl.test.ts +0 -143
  122. package/src/cli/commands/bundle.impl.ts +0 -21
  123. package/src/cli/commands/bundle.ts +0 -23
  124. package/src/cli/commands/capabilities.impl.ts +0 -47
  125. package/src/cli/commands/capabilities.ts +0 -25
  126. package/src/cli/commands/connect.impl.ts +0 -149
  127. package/src/cli/commands/connect.ts +0 -80
  128. package/src/cli/commands/deploy.impl.test.ts +0 -254
  129. package/src/cli/commands/deploy.impl.ts +0 -73
  130. package/src/cli/commands/deploy.ts +0 -22
  131. package/src/cli/commands/env.impl.ts +0 -88
  132. package/src/cli/commands/env.ts +0 -38
  133. package/src/cli/commands/exec.impl.ts +0 -171
  134. package/src/cli/commands/exec.ts +0 -32
  135. package/src/cli/commands/runs.impl.ts +0 -87
  136. package/src/cli/commands/runs.ts +0 -49
  137. package/src/cli/commands/secrets.impl.ts +0 -130
  138. package/src/cli/commands/secrets.ts +0 -73
  139. package/src/cli/commands/utils/testing.ts +0 -66
  140. package/src/cli/config.test.ts +0 -108
  141. package/src/cli/config.ts +0 -265
  142. package/src/cli/context.ts +0 -26
  143. package/src/cli/deploy.ts +0 -190
  144. package/src/cli/flags.ts +0 -72
  145. package/src/cli/handler.ts +0 -68
  146. package/src/cli/io.ts +0 -132
  147. package/src/cli/routes.ts +0 -61
  148. package/src/cli/utils/array.ts +0 -7
  149. package/src/cli/utils/openUrl.ts +0 -53
  150. package/src/cli/utils/string.ts +0 -9
@@ -1,87 +0,0 @@
1
- import { Result } from "../api/result.js";
2
- import type { FormatFlags, GlobalFlags } from "../flags.js";
3
- import { buildAuthedHandler } from "../handler.js";
4
-
5
- export const listRuns = buildAuthedHandler(async function (flags: FormatFlags) {
6
- const { workerId } = this.config;
7
- if (!workerId) {
8
- throw new Error(
9
- "No worker configured. Run 'workers deploy' first to create a worker.",
10
- );
11
- }
12
-
13
- this.process.stderr.write("Fetching runs...");
14
-
15
- const result = await this.apiClient.listRunsForWorker(workerId);
16
-
17
- if (Result.isSuccess(result)) {
18
- this.process.stderr.write("OK\n\n");
19
-
20
- const data = Result.unwrap(result);
21
- if (data.runs.length === 0) {
22
- this.io.writeErr("No runs found for this worker.");
23
- } else {
24
- this.io.writeTableOut({
25
- headers: ["Run ID", "Name", "Started At", "Ended At", "Exit Code"],
26
- rows: data.runs.map((run) => [
27
- run.runId,
28
- run.name,
29
- run.startedAt,
30
- run.endedAt,
31
- run.exitCode,
32
- ]),
33
- plain: flags.plain,
34
- });
35
- }
36
- } else {
37
- this.process.stderr.write("ERROR\n\n");
38
-
39
- // If it's a validation error, show the clean debug message
40
- if (result.error.validationError) {
41
- this.io.writeErr(`✗ ${result.error.validationError.debugMessage}`);
42
- throw new Error(result.error.validationError.debugMessage);
43
- } else {
44
- this.io.writeErr(`✗ ${result.error.message}`);
45
- throw new Error(result.error.message);
46
- }
47
- }
48
- });
49
-
50
- export const getRunLogs = buildAuthedHandler(async function (
51
- _flags: GlobalFlags,
52
- runId: string,
53
- ) {
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
-
61
- if (!runId) {
62
- throw new Error("Run ID is required");
63
- }
64
-
65
- this.process.stderr.write(`Fetching logs for run ${runId}...`);
66
-
67
- const result = await this.apiClient.getRunLogs(workerId, runId);
68
-
69
- if (Result.isSuccess(result)) {
70
- this.process.stderr.write("OK\n\n");
71
-
72
- const data = Result.unwrap(result);
73
- // Output logs directly to stdout (primary output)
74
- this.io.writeOut(data.logs);
75
- } else {
76
- this.process.stderr.write("ERROR\n\n");
77
-
78
- // If it's a validation error, show the clean debug message
79
- if (result.error.validationError) {
80
- this.io.writeErr(`✗ ${result.error.validationError.debugMessage}`);
81
- throw new Error(result.error.validationError.debugMessage);
82
- } else {
83
- this.io.writeErr(`✗ ${result.error.message}`);
84
- throw new Error(result.error.message);
85
- }
86
- }
87
- });
@@ -1,49 +0,0 @@
1
- import { buildCommand, buildRouteMap } from "@stricli/core";
2
- import { formatFlags, globalFlags } from "../flags.js";
3
-
4
- export const runsCommands = buildRouteMap({
5
- docs: {
6
- brief: "Commands for managing worker runs",
7
- },
8
- routes: {
9
- list: buildCommand({
10
- docs: {
11
- brief: "List all runs for a worker",
12
- },
13
-
14
- parameters: {
15
- flags: {
16
- ...globalFlags,
17
- ...formatFlags,
18
- },
19
- },
20
-
21
- loader: () => import("./runs.impl.js").then((m) => m.listRuns),
22
- }),
23
-
24
- logs: buildCommand({
25
- docs: {
26
- brief: "Get logs for a specific run",
27
- },
28
-
29
- parameters: {
30
- positional: {
31
- kind: "tuple",
32
- parameters: [
33
- {
34
- brief: "The run ID to get logs for",
35
- parse: String,
36
- placeholder: "runId",
37
- },
38
- ],
39
- },
40
-
41
- flags: {
42
- ...globalFlags,
43
- },
44
- },
45
-
46
- loader: () => import("./runs.impl.js").then((m) => m.getRunLogs),
47
- }),
48
- },
49
- });
@@ -1,130 +0,0 @@
1
- import { Result } from "../api/result.js";
2
- import type { FormatFlags, GlobalFlags } from "../flags.js";
3
- import { buildAuthedHandler } from "../handler.js";
4
- import { chunkEvery } from "../utils/array.js";
5
- import { pluralize } from "../utils/string.js";
6
-
7
- export const setSecrets = buildAuthedHandler(async function (
8
- _flags: GlobalFlags,
9
- ...args: string[]
10
- ) {
11
- const secrets = parseSecretArgs(args);
12
- const { workerId } = this.config;
13
-
14
- if (!workerId) {
15
- throw new Error(
16
- "No worker configured. Run 'workers deploy' first to create a worker.",
17
- );
18
- }
19
-
20
- this.io.writeErr(`Setting ${pluralize(secrets.length, "secret")}...`);
21
-
22
- const result = await this.apiClient.upsertSecrets(workerId, secrets);
23
-
24
- if (Result.isSuccess(result)) {
25
- for (const secret of Result.unwrap(result).secrets) {
26
- this.io.writeErr(`Set secret "${secret.key}"`);
27
- }
28
- } else {
29
- this.io.writeErr(`✗ Failed to set secrets`);
30
- this.io.writeErr(`✗ ${result.error.message}`);
31
- throw new Error(result.error.message);
32
- }
33
- });
34
-
35
- export const listSecrets = buildAuthedHandler(async function (
36
- flags: FormatFlags,
37
- ) {
38
- const { workerId } = this.config;
39
- if (!workerId) {
40
- throw new Error(
41
- "No worker configured. Run 'workers deploy' first to create a worker.",
42
- );
43
- }
44
-
45
- this.process.stderr.write(`Fetching secrets...`);
46
-
47
- const result = await this.apiClient.listSecrets(workerId);
48
-
49
- if (Result.isSuccess(result)) {
50
- this.process.stderr.write("OK\n\n");
51
-
52
- const data = Result.unwrap(result);
53
- if (data.secrets.length === 0) {
54
- this.io.writeErr("No secrets for this worker.");
55
- this.io.writeErr(
56
- "To list OAuth connect secrets, use `npx workers connect list`",
57
- );
58
- } else {
59
- this.io.writeTableOut({
60
- headers: ["Key", "Created At"],
61
- rows: data.secrets.map((secret) => [secret.key, secret.createdAt]),
62
- plain: flags.plain,
63
- });
64
- this.io.writeErr(
65
- "To list OAuth connect secrets, use `npx workers connect list`",
66
- );
67
- }
68
- } else {
69
- this.process.stderr.write("ERROR\n\n");
70
-
71
- this.io.writeErr(`✗ Failed to list secrets`);
72
- this.io.writeErr(`✗ ${result.error.message}`);
73
- throw new Error(result.error.message);
74
- }
75
- });
76
-
77
- export const removeSecret = buildAuthedHandler(async function (
78
- _flags: GlobalFlags,
79
- key: string,
80
- ) {
81
- const { workerId } = this.config;
82
- if (!workerId) {
83
- throw new Error(
84
- "No worker configured. Run 'workers deploy' first to create a worker.",
85
- );
86
- }
87
-
88
- this.process.stderr.write(`Removing secret "${key}"...`);
89
-
90
- const result = await this.apiClient.deleteSecret(workerId, key);
91
-
92
- if (Result.isSuccess(result)) {
93
- this.process.stderr.write("OK\n\n");
94
- } else {
95
- this.process.stderr.write("ERROR\n\n");
96
-
97
- this.io.writeErr(`✗ Failed to remove secret "${key}"`);
98
- this.io.writeErr(`✗ ${result.error.message}`);
99
- throw new Error(result.error.message);
100
- }
101
- });
102
-
103
- function usageError() {
104
- return new Error(
105
- "Invalid secrets provided. Usage: workers secrets set <key> <value> [<key2> <value2>...] or <key>=<value> [<key2>=<value2>...]",
106
- );
107
- }
108
-
109
- /**
110
- * Parse secret arguments from CLI, supporting "key value", "key=value", and "key:value" formats.
111
- */
112
- function parseSecretArgs(
113
- args: readonly string[],
114
- ): Array<{ key: string; value: string }> {
115
- if (args.length === 0) {
116
- throw usageError();
117
- }
118
-
119
- // Split each arg by = or : to flatten everything into tokens
120
- const tokens = args.flatMap((arg) => arg.split(/[=:]/));
121
-
122
- const secrets = chunkEvery(tokens, 2).map(([key, value]) => {
123
- if (!key || !value) {
124
- throw usageError();
125
- }
126
-
127
- return { key, value };
128
- });
129
- return secrets;
130
- }
@@ -1,73 +0,0 @@
1
- import { buildCommand, buildRouteMap } from "@stricli/core";
2
- import { formatFlags, globalFlags } from "../flags.js";
3
-
4
- export const secretsCommands = buildRouteMap({
5
- docs: {
6
- brief: "Commands for managing worker secrets",
7
- },
8
- routes: {
9
- set: buildCommand({
10
- docs: {
11
- brief:
12
- "Set one or more secrets for a worker. Supports 'key value' or 'key=value' format.",
13
- },
14
-
15
- parameters: {
16
- positional: {
17
- kind: "array",
18
- parameter: {
19
- brief: "Secret key-value pairs (key value or key=value)",
20
- parse: String,
21
- placeholder: "secrets...",
22
- },
23
- },
24
-
25
- flags: {
26
- ...globalFlags,
27
- },
28
- },
29
-
30
- loader: () => import("./secrets.impl.js").then((m) => m.setSecrets),
31
- }),
32
-
33
- list: buildCommand({
34
- docs: {
35
- brief: "List all secrets for a worker (keys only)",
36
- },
37
-
38
- parameters: {
39
- flags: {
40
- ...globalFlags,
41
- ...formatFlags,
42
- },
43
- },
44
-
45
- loader: () => import("./secrets.impl.js").then((m) => m.listSecrets),
46
- }),
47
-
48
- rm: buildCommand({
49
- docs: {
50
- brief: "Remove a secret from a worker",
51
- },
52
-
53
- parameters: {
54
- positional: {
55
- kind: "tuple",
56
- parameters: [
57
- {
58
- brief: "The secret key name to remove",
59
- parse: String,
60
- placeholder: "key",
61
- },
62
- ],
63
- },
64
-
65
- flags: {
66
- ...globalFlags,
67
- },
68
- },
69
-
70
- loader: () => import("./secrets.impl.js").then((m) => m.removeSecret),
71
- }),
72
- },
73
- });
@@ -1,66 +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, type ConfigMap } from "../../config.js";
7
- import type { LocalContext } from "../../context.js";
8
- import type { GlobalFlags } from "../../flags.js";
9
- import { IO } from "../../io.js";
10
-
11
- export const tmpDirectories: string[] = [];
12
-
13
- export const baseFlags: GlobalFlags = {
14
- debug: false,
15
- };
16
-
17
- export async function createAndLoadConfig({
18
- configFile,
19
- env,
20
- flags,
21
- }: {
22
- configFile: Partial<ConfigMap>;
23
- env?: Partial<NodeJS.ProcessEnv>;
24
- flags?: Partial<GlobalFlags>;
25
- }): Promise<[config: Config, path: string]> {
26
- const configFilePath = await createConfigFile(configFile);
27
-
28
- const map = await Config.load({
29
- configFilePath,
30
- processEnv: env ?? {},
31
- flags: {
32
- ...baseFlags,
33
- ...(flags ?? {}),
34
- },
35
- });
36
-
37
- return [map, configFilePath];
38
- }
39
-
40
- export function createBaseContext(): LocalContext {
41
- return {
42
- fs,
43
- io: new IO({ debugEnabled: false }),
44
- os,
45
- path,
46
- process,
47
- };
48
- }
49
-
50
- export async function cleanupTmpDirectories() {
51
- while (tmpDirectories.length > 0) {
52
- const dir = tmpDirectories.pop();
53
- if (dir) {
54
- await rm(dir, { recursive: true, force: true });
55
- }
56
- }
57
- }
58
-
59
- async function createConfigFile(contents: Partial<ConfigMap>) {
60
- const dir = await mkdtemp(path.join(tmpdir(), "cmd-test-"));
61
- tmpDirectories.push(dir);
62
- const configFilePath = path.join(dir, "config.json");
63
-
64
- await writeFile(configFilePath, JSON.stringify(contents, null, 2), "utf-8");
65
- return configFilePath;
66
- }
@@ -1,108 +0,0 @@
1
- import { readFile } from "node:fs/promises";
2
- import { afterEach, describe, expect, it } from "vitest";
3
- import {
4
- cleanupTmpDirectories,
5
- createAndLoadConfig,
6
- } from "./commands/utils/testing.js";
7
- import { Config, type ConfigMap } from "./config.js";
8
-
9
- const baseConfigMap: ConfigMap = {
10
- token: "file-token",
11
- workerId: "file-worker",
12
- environment: "local",
13
- baseUrl: "https://config.example.com",
14
- };
15
-
16
- afterEach(cleanupTmpDirectories);
17
-
18
- describe("Config.load precedence", () => {
19
- it("uses values from the config file when no overrides are present", async () => {
20
- const [config] = await createAndLoadConfig({
21
- configFile: baseConfigMap,
22
- });
23
-
24
- expect(config.token).toBe(baseConfigMap.token);
25
- expect(config.workerId).toBe(baseConfigMap.workerId);
26
- expect(config.environment).toBe(baseConfigMap.environment);
27
- expect(config.baseUrl).toBe(baseConfigMap.baseUrl);
28
- });
29
-
30
- it("prefers environment variables over the config file", async () => {
31
- const envVars = {
32
- WORKERS_TOKEN: "env-token",
33
- WORKERS_WORKER_ID: "env-worker",
34
- WORKERS_ENVIRONMENT: "staging",
35
- };
36
- const [config] = await createAndLoadConfig({
37
- configFile: baseConfigMap,
38
- env: envVars,
39
- });
40
-
41
- expect(config.token).toBe(envVars.WORKERS_TOKEN);
42
- expect(config.workerId).toBe(envVars.WORKERS_WORKER_ID);
43
- expect(config.environment).toBe(envVars.WORKERS_ENVIRONMENT);
44
- expect(config.baseUrl).toBe(baseConfigMap.baseUrl);
45
- });
46
-
47
- it("prefers flags over environment variables and config file values", async () => {
48
- const envVars = {
49
- WORKERS_WORKER_ID: "env-worker",
50
- WORKERS_ENVIRONMENT: "staging",
51
- WORKERS_BASE_URL: "https://env.example.com",
52
- };
53
-
54
- const flags = {
55
- env: "dev" as const,
56
- "base-url": "https://flag.example.com",
57
- };
58
-
59
- const [config] = await createAndLoadConfig({
60
- configFile: baseConfigMap,
61
- env: envVars,
62
- flags,
63
- });
64
-
65
- expect(config.token).toBe(baseConfigMap.token);
66
- expect(config.workerId).toBe(envVars.WORKERS_WORKER_ID);
67
- expect(config.environment).toBe(flags.env);
68
- expect(config.baseUrl).toBe(flags["base-url"]);
69
- });
70
- });
71
-
72
- describe("Config.update", () => {
73
- it("persists only provided keys to disk", async () => {
74
- const [, configFilePath] = await createAndLoadConfig({
75
- configFile: {
76
- token: "file-token",
77
- workerId: "file-worker",
78
- environment: "prod",
79
- baseUrl: "https://config.example.com",
80
- },
81
- });
82
-
83
- const config = await Config.load({
84
- configFilePath,
85
- processEnv: {
86
- WORKERS_BASE_URL: "https://env.example.com",
87
- } as NodeJS.ProcessEnv,
88
- flags: { debug: false },
89
- });
90
-
91
- expect(config.baseUrl).toBe("https://env.example.com");
92
-
93
- await config.update({
94
- token: "updated-token",
95
- });
96
-
97
- expect(config.token).toBe("updated-token");
98
-
99
- const persisted = JSON.parse(await readFile(configFilePath, "utf-8"));
100
-
101
- expect(persisted).toEqual({
102
- token: "updated-token",
103
- workerId: "file-worker",
104
- environment: "prod",
105
- baseUrl: "https://config.example.com",
106
- });
107
- });
108
- });