@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,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
- };
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=config.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.test.d.ts","sourceRoot":"","sources":["../../src/cli/config.test.ts"],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
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 { IO } from "./io.js";
7
- export interface LocalContext extends CommandContext, StricliAutoCompleteContext {
8
- readonly fs: typeof fs;
9
- readonly io: IO;
10
- readonly os: typeof os;
11
- readonly path: typeof path;
12
- readonly process: NodeJS.Process;
13
- }
14
- export declare function buildContext(process: NodeJS.Process): LocalContext;
15
- //# sourceMappingURL=context.d.ts.map
@@ -1 +0,0 @@
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,EAAE,EAAE,MAAM,SAAS,CAAC;AAE7B,MAAM,WAAW,YAChB,SAAQ,cAAc,EACrB,0BAA0B;IAC3B,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;CACjC;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,GAAG,YAAY,CAQlE"}
@@ -1,16 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as os from "node:os";
3
- import * as path from "node:path";
4
- import { IO } from "./io.js";
5
- function buildContext(process) {
6
- return {
7
- fs,
8
- io: new IO({ debugEnabled: false }),
9
- os,
10
- path,
11
- process
12
- };
13
- }
14
- export {
15
- buildContext
16
- };
@@ -1,37 +0,0 @@
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 BaseDeployOptions {
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
- }
18
- export interface CreateDeployOptions extends BaseDeployOptions {
19
- /**
20
- * Name of the worker (if it has not yet been created)
21
- */
22
- name: string;
23
- }
24
- export interface UpdateDeployOptions extends BaseDeployOptions {
25
- /**
26
- * ID of the worker to update
27
- */
28
- workerId: string;
29
- }
30
- export type DeployOptions = CreateDeployOptions | UpdateDeployOptions;
31
- /**
32
- * Deploy a worker to the specified environment
33
- */
34
- export declare function deployWorker(context: AuthedContext, options: DeployOptions): Promise<Result<{
35
- workerId: string;
36
- }, ApiError>>;
37
- //# sourceMappingURL=deploy.d.ts.map
@@ -1 +0,0 @@
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,iBAAiB;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;CACzB;AAED,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAEtE;;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,CAkEjD"}
@@ -1,100 +0,0 @@
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 } = options;
8
- const absPath = path.resolve(process.cwd(), workerPath);
9
- context.io.debug(`Deploying worker from: ${absPath}`);
10
- const client = context.apiClient;
11
- let uploadUrl;
12
- let uploadFields;
13
- let workerId;
14
- if ("workerId" in options) {
15
- context.io.writeErr(`Updating worker...`);
16
- workerId = options.workerId;
17
- const updateResult = await client.updateWorkerBundle(workerId);
18
- if (Result.isSuccess(updateResult)) {
19
- const res = Result.unwrap(updateResult);
20
- uploadUrl = res.url;
21
- uploadFields = res.fields;
22
- } else {
23
- context.io.writeErr(
24
- "Failed to generate pre-signed upload URL for worker bundle:"
25
- );
26
- throw new Error(updateResult.error.message);
27
- }
28
- } else {
29
- context.io.writeErr(`Creating worker...`);
30
- const createResult = await client.createWorker(options.name);
31
- if (Result.isSuccess(createResult)) {
32
- const res = Result.unwrap(createResult);
33
- uploadUrl = res.url;
34
- uploadFields = res.fields;
35
- workerId = res.worker.workerId;
36
- } else {
37
- console.error("Failed to create worker:");
38
- throw new Error(createResult.error.message);
39
- }
40
- }
41
- context.io.debug(`Generated upload URL: ${uploadUrl}`);
42
- context.io.writeErr("Building worker bundle...");
43
- const archivePath = await buildWorkerBundle(context, absPath);
44
- context.io.debug(`Created bundle at: ${archivePath}`);
45
- context.io.writeErr("Uploading bundle...");
46
- await uploadBundle(uploadUrl, uploadFields, archivePath);
47
- context.io.debug("Upload complete");
48
- context.io.writeErr("Fetching and saving worker capabilities...");
49
- const capabilitiesResult = await client.fetchAndSaveCapabilities(workerId);
50
- if (Result.isSuccess(capabilitiesResult)) {
51
- return Result.success({ workerId });
52
- } else {
53
- return capabilitiesResult;
54
- }
55
- }
56
- async function buildWorkerBundle(context, workerPath) {
57
- const entrypoint = "src/index.ts";
58
- if (!fs.existsSync(path.join(workerPath, entrypoint))) {
59
- throw new Error(`Entrypoint not found: ${entrypoint}`);
60
- }
61
- const outdir = fs.mkdtempSync("/tmp/workers-build-");
62
- esbuild.buildSync({
63
- entryPoints: [entrypoint],
64
- absWorkingDir: workerPath,
65
- bundle: true,
66
- outdir,
67
- platform: "node"
68
- });
69
- context.io.debug(`Built bundle to: ${outdir}`);
70
- const archiveDir = fs.mkdtempSync("/tmp/workers-archive-");
71
- const archivePath = path.join(archiveDir, "archive.tar.gz");
72
- childProcess.execSync(`tar -czf ${archivePath} -C ${outdir} .`);
73
- return archivePath;
74
- }
75
- async function uploadBundle(url, fields, archivePath) {
76
- const formData = new FormData();
77
- for (const [key, value] of Object.entries(fields)) {
78
- formData.append(key, value);
79
- }
80
- const fileBuffer = fs.readFileSync(archivePath);
81
- formData.append(
82
- "file",
83
- new Blob([new Uint8Array(fileBuffer)]),
84
- "archive.tar.gz"
85
- );
86
- const response = await fetch(url, {
87
- method: "POST",
88
- body: formData
89
- });
90
- if (!response.ok) {
91
- const errorText = await response.text();
92
- throw new Error(
93
- `Failed to upload bundle: ${response.status} ${response.statusText}
94
- ${errorText}`
95
- );
96
- }
97
- }
98
- export {
99
- deployWorker
100
- };
@@ -1,21 +0,0 @@
1
- import type { TypedFlagParameter } from "@stricli/core";
2
- import { type Environment } from "./config.js";
3
- import type { LocalContext } from "./context.js";
4
- export interface GlobalFlags {
5
- config?: string;
6
- debug: boolean;
7
- env?: Environment;
8
- "base-url"?: string;
9
- token?: string;
10
- "worker-id"?: string;
11
- }
12
- export declare const globalFlags: {
13
- [K in keyof Required<GlobalFlags>]: TypedFlagParameter<GlobalFlags[K], LocalContext>;
14
- };
15
- export interface FormatFlags {
16
- plain: boolean;
17
- }
18
- export declare const formatFlags: {
19
- [K in keyof Required<FormatFlags>]: TypedFlagParameter<FormatFlags[K], LocalContext>;
20
- };
21
- //# sourceMappingURL=flags.d.ts.map
@@ -1 +0,0 @@
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,EAAE,KAAK,WAAW,EAAgB,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,WAAW,WAAW;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,WAAW,EAAE;KACxB,CAAC,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,kBAAkB,CACrD,WAAW,CAAC,CAAC,CAAC,EACd,YAAY,CACZ;CAqCD,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"}
package/dist/cli/flags.js DELETED
@@ -1,49 +0,0 @@
1
- import { Environments } from "./config.js";
2
- const globalFlags = {
3
- config: {
4
- kind: "parsed",
5
- parse: String,
6
- brief: "The path to the config file to use",
7
- optional: true
8
- },
9
- debug: {
10
- kind: "boolean",
11
- brief: "Enable debug logging",
12
- default: false
13
- },
14
- env: {
15
- kind: "enum",
16
- values: Environments,
17
- brief: "The environment to use for the command",
18
- optional: true
19
- },
20
- "base-url": {
21
- kind: "parsed",
22
- parse: String,
23
- brief: "The base URL to use for all API requests",
24
- optional: true
25
- },
26
- token: {
27
- kind: "parsed",
28
- parse: String,
29
- brief: "The token to use for authentication",
30
- optional: true
31
- },
32
- "worker-id": {
33
- kind: "parsed",
34
- parse: String,
35
- brief: "The ID of the worker to use for the command",
36
- optional: true
37
- }
38
- };
39
- const formatFlags = {
40
- plain: {
41
- kind: "boolean",
42
- brief: "Output the results in plain text format",
43
- default: false
44
- }
45
- };
46
- export {
47
- formatFlags,
48
- globalFlags
49
- };
@@ -1,14 +0,0 @@
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
@@ -1 +0,0 @@
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,mBAiBd;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,UA7BlB,YAAY,8DA6CnB"}
@@ -1,32 +0,0 @@
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 configFilePath = flags.config ?? this.process.env.WORKERS_CONFIG_FILE_PATH ?? "./workers.json";
6
- const config = await Config.load({
7
- configFilePath,
8
- processEnv: process.env,
9
- flags
10
- });
11
- this.io.debugEnabled = flags.debug;
12
- await handler.call({ ...this, config }, flags, ...args);
13
- };
14
- }
15
- function buildAuthedHandler(handler) {
16
- return buildHandler(function(flags, ...args) {
17
- const { token, cellId } = this.config.tokenInfo;
18
- const environment = this.config.environment;
19
- const client = new ApiClient({
20
- token,
21
- environment,
22
- baseUrl: this.config.baseUrl,
23
- cellId,
24
- writer: this.io
25
- });
26
- return handler.call({ ...this, apiClient: client }, flags, ...args);
27
- });
28
- }
29
- export {
30
- buildAuthedHandler,
31
- buildHandler
32
- };
package/dist/cli/io.d.ts DELETED
@@ -1,55 +0,0 @@
1
- import * as prompts from "@inquirer/prompts";
2
- import { type TableCell } from "@visulima/tabular";
3
- export interface WriterOptions {
4
- debugEnabled: boolean;
5
- }
6
- export interface TableOptions {
7
- headers: TableCell[] | TableCell[][];
8
- rows: TableCell[][];
9
- plain: boolean;
10
- }
11
- type WithSafety<T> = T & {
12
- noTTY: string;
13
- };
14
- /**
15
- * IO manages safe, consistent, input and output patterns for the CLI.
16
- */
17
- export declare class IO {
18
- #private;
19
- debugEnabled: boolean;
20
- constructor(options: WriterOptions);
21
- /**
22
- * Writes a debug message to standard error.
23
- *
24
- * @param args The arguments to write.
25
- */
26
- debug(...args: Parameters<typeof console.log>): void;
27
- /**
28
- * Writes a message to standard out.
29
- *
30
- * @param args The arguments to write.
31
- */
32
- writeOut(...args: Parameters<typeof process.stdout.write>): void;
33
- /**
34
- * Writes a message to standard error.
35
- *
36
- * @param args The arguments to write.
37
- */
38
- writeErr(...args: Parameters<typeof process.stderr.write>): void;
39
- /**
40
- * Writes a table to standard out.
41
- *
42
- * @param tableConfig The table configuration.
43
- */
44
- writeTableOut(tableConfig: TableOptions): void;
45
- /**
46
- * Writes a table to standard error.
47
- *
48
- * @param tableConfig The table configuration.
49
- */
50
- writeTableErr(tableConfig: TableOptions): void;
51
- confirm(config: WithSafety<Parameters<typeof prompts.confirm>[0]>): Promise<boolean | void>;
52
- input(config: WithSafety<Parameters<typeof prompts.input>[0]>): Promise<string | void>;
53
- }
54
- export {};
55
- //# sourceMappingURL=io.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/cli/io.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAe,KAAK,SAAS,EAAkB,MAAM,mBAAmB,CAAC;AAEhF,MAAM,WAAW,aAAa;IAC7B,YAAY,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,EAAE,CAAC;IACrC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CACf;AAED,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,qBAAa,EAAE;;IACd,YAAY,EAAE,OAAO,CAAC;gBAEV,OAAO,EAAE,aAAa;IAIlC;;;;OAIG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC;IAW7C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAIzD;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAIzD;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;IAKvC;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;IAKvC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAKjE,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;CAuC7D"}