@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,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
- };
@@ -1,63 +0,0 @@
1
- import type { GlobalFlags } from "./flags.js";
2
- export declare const Environments: readonly ["local", "staging", "dev", "prod"];
3
- export type Environment = (typeof Environments)[number];
4
- export interface ConfigMap {
5
- environment: Environment;
6
- baseUrl: string;
7
- token: string | null;
8
- workerId: string | null;
9
- }
10
- export declare function parseEnvironment(name: string): Environment;
11
- export declare class TokenNotSetError extends Error {
12
- constructor(message?: string);
13
- }
14
- /**
15
- * Manages configuration for the CLI.
16
- *
17
- * Environment variables take precedence over the config file.
18
- *
19
- * | Environment Variable | Config File | Description |
20
- * |----------------------|-------------|-------------|
21
- * | WORKERS_TOKEN | token | The token to use for authentication |
22
- * | WORKERS_ENVIRONMENT | environment | The environment to use |
23
- * | WORKERS_WORKER_ID | workerId | The worker ID to use |
24
- * | WORKERS_BASE_URL | baseUrl | The base URL to use |
25
- */
26
- export declare class Config {
27
- #private;
28
- constructor(opts: {
29
- configMap: ConfigMap;
30
- configFilePath: string;
31
- });
32
- get baseUrl(): string;
33
- get token(): string | null;
34
- get environment(): "local" | "staging" | "dev" | "prod";
35
- get workerId(): string | null;
36
- get tokenInfo(): {
37
- token: string;
38
- spaceId: string;
39
- cellId: string;
40
- };
41
- /**
42
- * Update the config with a partial config map.
43
- *
44
- * This will write only the updated keys in the config file on disk. Not all
45
- * keys are written, since some current keys in the Config object may have
46
- * come from e.g. environment variables, rather than the original config
47
- * file.
48
- *
49
- * @param config The config update.
50
- */
51
- update(config: Partial<ConfigMap>): Promise<void>;
52
- static load(opts: {
53
- configFilePath: string;
54
- processEnv: NodeJS.ProcessEnv;
55
- flags: GlobalFlags;
56
- }): Promise<Config>;
57
- }
58
- export declare function extractPayloadFromToken(token: string): {
59
- spaceId: string;
60
- userId: string;
61
- cellId: string;
62
- };
63
- //# sourceMappingURL=config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/cli/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,eAAO,MAAM,YAAY,8CAA+C,CAAC;AACzE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,MAAM,WAAW,SAAS;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,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;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;;gBAIN,IAAI,EAAE;QACjB,SAAS,EAAE,SAAS,CAAC;QACrB,cAAc,EAAE,MAAM,CAAC;KACvB;IAOD,IAAI,OAAO,WAEV;IAED,IAAI,KAAK,kBAER;IAED,IAAI,WAAW,yCAEd;IAED,IAAI,QAAQ,kBAEX;IAED,IAAI,SAAS,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAQlE;IAED;;;;;;;;;OASG;IACG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC;WAc1B,IAAI,CAAC,IAAI,EAAE;QACvB,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC;QAC9B,KAAK,EAAE,WAAW,CAAC;KACnB;CA4FD;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"}
@@ -1,194 +0,0 @@
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
- class Config {
17
- #configMap;
18
- #configFilePath;
19
- constructor(opts) {
20
- this.#configMap = opts.configMap;
21
- this.#configFilePath = opts.configFilePath;
22
- }
23
- // Getters read from the environment variables, and then the config file.
24
- get baseUrl() {
25
- return this.#configMap.baseUrl;
26
- }
27
- get token() {
28
- return this.#configMap.token;
29
- }
30
- get environment() {
31
- return this.#configMap.environment;
32
- }
33
- get workerId() {
34
- return this.#configMap.workerId;
35
- }
36
- get tokenInfo() {
37
- const token = this.token;
38
- if (!token) {
39
- throw new TokenNotSetError();
40
- }
41
- const { spaceId, cellId } = extractPayloadFromToken(token);
42
- return { token, spaceId, cellId };
43
- }
44
- /**
45
- * Update the config with a partial config map.
46
- *
47
- * This will write only the updated keys in the config file on disk. Not all
48
- * keys are written, since some current keys in the Config object may have
49
- * come from e.g. environment variables, rather than the original config
50
- * file.
51
- *
52
- * @param config The config update.
53
- */
54
- async update(config) {
55
- Object.assign(this.#configMap, config);
56
- const currentConfigFile = await Config.#readConfigFile(
57
- this.#configFilePath
58
- );
59
- Object.assign(currentConfigFile, config);
60
- await fs.promises.writeFile(
61
- this.#configFilePath,
62
- JSON.stringify(currentConfigFile, null, 2),
63
- "utf-8"
64
- );
65
- }
66
- static async load(opts) {
67
- const absConfigFilePath = path.resolve(process.cwd(), opts.configFilePath);
68
- const partialConfig = await Config.#readConfigFile(absConfigFilePath);
69
- if (opts.processEnv.WORKERS_TOKEN) {
70
- partialConfig.token = opts.processEnv.WORKERS_TOKEN;
71
- }
72
- if (opts.processEnv.WORKERS_ENVIRONMENT) {
73
- partialConfig.environment = parseEnvironment(
74
- opts.processEnv.WORKERS_ENVIRONMENT
75
- );
76
- }
77
- if (opts.processEnv.WORKERS_WORKER_ID) {
78
- partialConfig.workerId = opts.processEnv.WORKERS_WORKER_ID;
79
- }
80
- if (opts.processEnv.WORKERS_BASE_URL) {
81
- partialConfig.baseUrl = opts.processEnv.WORKERS_BASE_URL;
82
- }
83
- if (opts.flags.token) {
84
- partialConfig.token = opts.flags.token;
85
- }
86
- if (opts.flags.env) {
87
- partialConfig.environment = parseEnvironment(opts.flags.env);
88
- }
89
- if (opts.flags["base-url"]) {
90
- partialConfig.baseUrl = opts.flags["base-url"];
91
- }
92
- if (opts.flags["worker-id"]) {
93
- partialConfig.workerId = opts.flags["worker-id"];
94
- }
95
- partialConfig.environment ??= "prod";
96
- partialConfig.baseUrl ??= baseUrlForEnvironment(partialConfig.environment);
97
- const environment = partialConfig.environment;
98
- if (!environment) {
99
- throw new Error("Environment is required");
100
- }
101
- const baseUrl = partialConfig.baseUrl;
102
- if (!baseUrl) {
103
- throw new Error("Base URL is required");
104
- }
105
- const token = partialConfig.token;
106
- if (token === void 0) {
107
- throw new Error("Token is required");
108
- }
109
- const workerId = partialConfig.workerId;
110
- if (workerId === void 0) {
111
- throw new Error("Worker ID is required");
112
- }
113
- const configMap = {
114
- environment,
115
- baseUrl,
116
- token,
117
- workerId
118
- };
119
- return new Config({
120
- configFilePath: absConfigFilePath,
121
- configMap
122
- });
123
- }
124
- static async #readConfigFile(configFilePath) {
125
- let configFile;
126
- try {
127
- const configContents = await fs.promises.readFile(
128
- configFilePath,
129
- "utf-8"
130
- );
131
- configFile = JSON.parse(configContents);
132
- } catch (error) {
133
- if (isENOENT(error)) {
134
- configFile = {
135
- token: null,
136
- workerId: null
137
- };
138
- } else {
139
- throw error;
140
- }
141
- }
142
- return configFile;
143
- }
144
- }
145
- function isENOENT(error) {
146
- return error instanceof Error && "code" in error && error.code === "ENOENT";
147
- }
148
- function extractPayloadFromToken(token) {
149
- try {
150
- const parts = token.split(".");
151
- if (parts.length !== 4 || !parts[2]) {
152
- throw new Error("Invalid token format.");
153
- }
154
- const payloadBase64 = parts[2];
155
- const payloadJson = Buffer.from(payloadBase64, "base64url").toString(
156
- "utf-8"
157
- );
158
- const payload = JSON.parse(payloadJson);
159
- if (!payload.spaceId || !payload.userId || !payload.cellId) {
160
- throw new Error(
161
- "Token payload missing required fields (spaceId, userId, cellId)."
162
- );
163
- }
164
- return {
165
- spaceId: payload.spaceId,
166
- userId: payload.userId,
167
- cellId: payload.cellId
168
- };
169
- } catch (error) {
170
- if (error instanceof Error && error.message.startsWith("Token")) {
171
- throw error;
172
- }
173
- throw new Error("Failed to parse token payload.");
174
- }
175
- }
176
- function baseUrlForEnvironment(environment) {
177
- switch (environment) {
178
- case "local":
179
- return "http://localhost:3000";
180
- case "staging":
181
- return "https://staging.notion.so";
182
- case "dev":
183
- return "https://dev.notion.so";
184
- case "prod":
185
- return "https://www.notion.so";
186
- }
187
- }
188
- export {
189
- Config,
190
- Environments,
191
- TokenNotSetError,
192
- extractPayloadFromToken,
193
- parseEnvironment
194
- };