@project-ajax/cli 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/client.d.ts +0 -2
- package/dist/api/client.d.ts.map +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.impl.d.ts +2 -3
- package/dist/commands/auth.impl.d.ts.map +1 -1
- package/dist/commands/auth.impl.js +65 -101
- package/dist/commands/auth.js +0 -27
- package/dist/commands/deploy.impl.d.ts.map +1 -1
- package/dist/commands/deploy.impl.js +6 -7
- package/dist/commands/exec.impl.js +1 -1
- package/dist/commands/utils/testing.d.ts +20 -5
- package/dist/commands/utils/testing.d.ts.map +1 -1
- package/dist/commands/utils/testing.js +66 -25
- package/dist/config.d.ts +144 -42
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +322 -140
- package/dist/deploy.d.ts +2 -1
- package/dist/deploy.d.ts.map +1 -1
- package/dist/flags.d.ts +2 -3
- package/dist/flags.d.ts.map +1 -1
- package/dist/flags.js +4 -10
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +13 -9
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +2 -3
- package/dist/token.d.ts +35 -0
- package/dist/token.d.ts.map +1 -0
- package/dist/token.js +58 -0
- package/package.json +5 -2
package/dist/config.js
CHANGED
|
@@ -1,194 +1,376 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
import Debug from "debug";
|
|
4
|
+
import z from "zod";
|
|
5
|
+
import {
|
|
6
|
+
fetchToken,
|
|
7
|
+
parseToken,
|
|
8
|
+
storeToken,
|
|
9
|
+
TokenNotSetError
|
|
10
|
+
} from "./token.js";
|
|
11
|
+
const debug = Debug("notion:workers:config");
|
|
12
|
+
const Environment = z.literal(["local", "dev", "stg", "prod"]);
|
|
13
|
+
const SpaceCache = z.object({
|
|
14
|
+
version: z.literal("1"),
|
|
15
|
+
spaces: z.record(
|
|
16
|
+
z.string(),
|
|
17
|
+
z.object({ id: z.string(), name: z.string(), cellId: z.string() })
|
|
18
|
+
)
|
|
19
|
+
});
|
|
20
|
+
const LocalConfig = z.object({
|
|
21
|
+
version: z.literal("1"),
|
|
22
|
+
environment: Environment,
|
|
23
|
+
baseURL: z.string().optional(),
|
|
24
|
+
spaceId: z.string().nullable(),
|
|
25
|
+
workerId: z.string().nullable()
|
|
26
|
+
});
|
|
27
|
+
const LocalConfigV0 = z.object({
|
|
28
|
+
environment: z.string(),
|
|
29
|
+
baseUrl: z.string(),
|
|
30
|
+
token: z.string().nullable(),
|
|
31
|
+
workerId: z.string().nullable()
|
|
32
|
+
}).partial();
|
|
33
|
+
class NoSuitableConfigFileError extends Error {
|
|
34
|
+
constructor() {
|
|
35
|
+
super("No suitable config file found");
|
|
36
|
+
this.name = "NoSuitableConfigFileError";
|
|
14
37
|
}
|
|
15
38
|
}
|
|
16
39
|
class Config {
|
|
17
|
-
#
|
|
18
|
-
#
|
|
40
|
+
#spaceCachePath;
|
|
41
|
+
#spaceCache;
|
|
42
|
+
#localConfigPath;
|
|
43
|
+
#localConfig;
|
|
44
|
+
#baseURL;
|
|
45
|
+
#environment;
|
|
46
|
+
#spaceId;
|
|
47
|
+
#workerId;
|
|
48
|
+
#token = null;
|
|
19
49
|
constructor(opts) {
|
|
20
|
-
this.#
|
|
21
|
-
this.#
|
|
50
|
+
this.#spaceCachePath = opts.spaceCachePath;
|
|
51
|
+
this.#spaceCache = opts.spaceCache;
|
|
52
|
+
this.#localConfigPath = opts.localConfigPath;
|
|
53
|
+
this.#localConfig = opts.localConfig;
|
|
54
|
+
this.#baseURL = opts.baseURL;
|
|
55
|
+
this.#spaceId = opts.spaceId;
|
|
56
|
+
this.#workerId = opts.workerId;
|
|
57
|
+
this.#environment = opts.environment;
|
|
58
|
+
this.#token = opts.token;
|
|
22
59
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return this.#configMap.baseUrl;
|
|
60
|
+
get environment() {
|
|
61
|
+
return this.#environment;
|
|
26
62
|
}
|
|
27
|
-
get
|
|
28
|
-
return this.#
|
|
63
|
+
get baseURL() {
|
|
64
|
+
return this.#baseURL;
|
|
29
65
|
}
|
|
30
|
-
get
|
|
31
|
-
return this.#
|
|
66
|
+
get spaceId() {
|
|
67
|
+
return this.#spaceId;
|
|
32
68
|
}
|
|
33
69
|
get workerId() {
|
|
34
|
-
return this.#
|
|
70
|
+
return this.#workerId;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the list of cached spaces.
|
|
74
|
+
*
|
|
75
|
+
* @returns An array of cached spaces with id, name, and cellId.
|
|
76
|
+
*/
|
|
77
|
+
getCachedSpaces() {
|
|
78
|
+
return Object.values(this.#spaceCache.spaces);
|
|
35
79
|
}
|
|
36
|
-
|
|
37
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Get the token and token information from the keychain.
|
|
82
|
+
*
|
|
83
|
+
* @returns The token and token information, or null if no token is found.
|
|
84
|
+
*/
|
|
85
|
+
async getToken() {
|
|
86
|
+
if (this.#token) {
|
|
87
|
+
return [this.#token, parseToken(this.#token)];
|
|
88
|
+
}
|
|
89
|
+
if (!this.spaceId) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const token = await fetchToken(this.spaceId);
|
|
38
93
|
if (!token) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
this.#token = token;
|
|
97
|
+
return [this.#token, parseToken(this.#token)];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get the token and token information from the keychain.
|
|
101
|
+
*
|
|
102
|
+
* Throws an error if no token is found.
|
|
103
|
+
*
|
|
104
|
+
* @returns The token and token information.
|
|
105
|
+
*/
|
|
106
|
+
async mustGetToken() {
|
|
107
|
+
const result = await this.getToken();
|
|
108
|
+
if (!result) {
|
|
39
109
|
throw new TokenNotSetError();
|
|
40
110
|
}
|
|
41
|
-
|
|
42
|
-
return { token, spaceId, cellId };
|
|
111
|
+
return result;
|
|
43
112
|
}
|
|
44
113
|
/**
|
|
45
|
-
*
|
|
114
|
+
* Log in by updating the local configuration and the space cache, and
|
|
115
|
+
* storing the token in the keychain.
|
|
46
116
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
117
|
+
* @param args The arguments to login.
|
|
118
|
+
* @param args.environment The environment to login to.
|
|
119
|
+
* @param args.token The token to login with.
|
|
120
|
+
* @param args.spaceId The space ID to login to.
|
|
121
|
+
* @param args.spaceName The space name to login to.
|
|
122
|
+
* @param args.cellId The cell ID to login to.
|
|
123
|
+
*/
|
|
124
|
+
async login(args) {
|
|
125
|
+
this.#environment = args.environment;
|
|
126
|
+
this.#spaceId = args.spaceId;
|
|
127
|
+
this.#localConfig.environment = args.environment;
|
|
128
|
+
this.#localConfig.spaceId = args.spaceId;
|
|
129
|
+
this.#writeLocalConfig();
|
|
130
|
+
this.#spaceCache.spaces[args.spaceId] = {
|
|
131
|
+
id: args.spaceId,
|
|
132
|
+
name: args.spaceName,
|
|
133
|
+
cellId: args.cellId
|
|
134
|
+
};
|
|
135
|
+
this.#writeSpaceCache();
|
|
136
|
+
await storeToken(args.spaceId, args.token);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Set the worker ID.
|
|
140
|
+
*
|
|
141
|
+
* @param workerId The worker ID to set.
|
|
142
|
+
*/
|
|
143
|
+
setWorker(workerId) {
|
|
144
|
+
this.#workerId = workerId;
|
|
145
|
+
this.#localConfig.workerId = workerId;
|
|
146
|
+
this.#writeLocalConfig();
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Switch to an existing cached space.
|
|
150
|
+
*
|
|
151
|
+
* This updates the local configuration to use the specified space.
|
|
152
|
+
* The token for this space should already exist in the keychain.
|
|
51
153
|
*
|
|
52
|
-
* @param
|
|
154
|
+
* @param spaceId The space ID to switch to.
|
|
155
|
+
* @throws Error if the space is not in the cache.
|
|
53
156
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
157
|
+
switchToSpace(spaceId) {
|
|
158
|
+
const space = this.#spaceCache.spaces[spaceId];
|
|
159
|
+
if (!space) {
|
|
160
|
+
throw new Error(`Space ${spaceId} not found in cache`);
|
|
161
|
+
}
|
|
162
|
+
this.#spaceId = spaceId;
|
|
163
|
+
this.#localConfig.spaceId = spaceId;
|
|
164
|
+
this.#writeLocalConfig();
|
|
165
|
+
}
|
|
166
|
+
#writeSpaceCache() {
|
|
167
|
+
fs.writeFileSync(
|
|
168
|
+
this.#spaceCachePath,
|
|
169
|
+
JSON.stringify(this.#spaceCache, null, 2)
|
|
58
170
|
);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
171
|
+
}
|
|
172
|
+
#writeLocalConfig() {
|
|
173
|
+
fs.writeFileSync(
|
|
174
|
+
this.#localConfigPath,
|
|
175
|
+
JSON.stringify(this.#localConfig, null, 2)
|
|
64
176
|
);
|
|
65
177
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Resolve the space cache path.
|
|
180
|
+
*
|
|
181
|
+
* @param opts Options for resolving the space cache path.
|
|
182
|
+
* @param opts.filePath The path to the space cache file.
|
|
183
|
+
* @param opts.env The environment variables.
|
|
184
|
+
* @returns The path to the space cache file.
|
|
185
|
+
*/
|
|
186
|
+
static resolveSpaceCachePath(opts) {
|
|
187
|
+
const env = opts.env;
|
|
188
|
+
const home = env.HOME;
|
|
189
|
+
const xdgConfigHome = env.XDG_CONFIG_HOME;
|
|
190
|
+
const notionHome = env.NOTION_HOME;
|
|
191
|
+
let configFileDir;
|
|
192
|
+
let configFilePath;
|
|
193
|
+
if (opts.filePath) {
|
|
194
|
+
const absPath = path.resolve(process.cwd(), opts.filePath);
|
|
195
|
+
configFileDir = path.dirname(absPath);
|
|
196
|
+
configFilePath = absPath;
|
|
197
|
+
} else {
|
|
198
|
+
if (notionHome && isDir(notionHome)) {
|
|
199
|
+
configFileDir = notionHome;
|
|
200
|
+
configFilePath = path.join(configFileDir, "spaces.json");
|
|
201
|
+
} else if (xdgConfigHome && isDir(xdgConfigHome)) {
|
|
202
|
+
configFileDir = path.join(xdgConfigHome, "notion");
|
|
203
|
+
configFilePath = path.join(configFileDir, "spaces.json");
|
|
204
|
+
} else if (home && isDir(path.join(home, ".config"))) {
|
|
205
|
+
configFileDir = path.join(home, ".config", "notion");
|
|
206
|
+
configFilePath = path.join(configFileDir, "spaces.json");
|
|
207
|
+
} else if (home && isDir(home)) {
|
|
208
|
+
configFileDir = path.join(home, ".notion");
|
|
209
|
+
configFilePath = path.join(configFileDir, "spaces.json");
|
|
210
|
+
}
|
|
82
211
|
}
|
|
83
|
-
|
|
84
|
-
|
|
212
|
+
debug("%o", { configFileDir, configFilePath });
|
|
213
|
+
if (!(configFileDir && configFilePath)) {
|
|
214
|
+
throw new NoSuitableConfigFileError();
|
|
85
215
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
216
|
+
if (!fs.existsSync(configFileDir)) {
|
|
217
|
+
fs.mkdirSync(configFileDir, { recursive: true });
|
|
88
218
|
}
|
|
89
|
-
if (
|
|
90
|
-
|
|
219
|
+
if (!isDir(configFileDir)) {
|
|
220
|
+
throw new NoSuitableConfigFileError();
|
|
91
221
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
222
|
+
if (!fs.existsSync(configFilePath)) {
|
|
223
|
+
fs.writeFileSync(
|
|
224
|
+
configFilePath,
|
|
225
|
+
JSON.stringify(Config.emptySpaceCache, null, 2)
|
|
226
|
+
);
|
|
94
227
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const environment = partialConfig.environment;
|
|
98
|
-
if (!environment) {
|
|
99
|
-
throw new Error("Environment is required");
|
|
228
|
+
if (!isFile(configFilePath)) {
|
|
229
|
+
throw new NoSuitableConfigFileError();
|
|
100
230
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
231
|
+
return configFilePath;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Resolve the local config path.
|
|
235
|
+
*
|
|
236
|
+
* @param opts Options for resolving the local config path.
|
|
237
|
+
* @param opts.filePath The path to the local config file.
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
static resolveLocalConfigPath(opts = {}) {
|
|
241
|
+
const absPath = path.resolve(
|
|
242
|
+
process.cwd(),
|
|
243
|
+
opts.filePath ?? "./workers.json"
|
|
244
|
+
);
|
|
245
|
+
if (!fs.existsSync(absPath)) {
|
|
246
|
+
fs.writeFileSync(
|
|
247
|
+
absPath,
|
|
248
|
+
JSON.stringify(Config.emptyLocalConfig, null, 2)
|
|
249
|
+
);
|
|
104
250
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
throw new Error("Token is required");
|
|
251
|
+
if (!isFile(absPath)) {
|
|
252
|
+
throw new NoSuitableConfigFileError();
|
|
108
253
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
254
|
+
return absPath;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Load config from space cache and local config files, then resolve them to
|
|
258
|
+
* a final config for this execution of the command line interface.
|
|
259
|
+
*
|
|
260
|
+
* If the local config is v0, it will be upgraded to v1.
|
|
261
|
+
*
|
|
262
|
+
* Overrides:
|
|
263
|
+
*
|
|
264
|
+
* - Environment: WORKERS_ENVIRONMENT or --env flag
|
|
265
|
+
* - Token: WORKERS_TOKEN or --token flag
|
|
266
|
+
* - Base URL: WORKERS_BASE_URL or --base-url flag
|
|
267
|
+
*
|
|
268
|
+
* @param opts The options to load the config from.
|
|
269
|
+
* @param opts.spaceCachePath The path to the space cache file.
|
|
270
|
+
* @param opts.localPath The path to the local config file.
|
|
271
|
+
* @param opts.env The process environment.
|
|
272
|
+
* @param opts.processEnv The process environment.
|
|
273
|
+
* @param opts.flags The global flags.
|
|
274
|
+
* @returns The resolved config.
|
|
275
|
+
*/
|
|
276
|
+
static load(opts) {
|
|
277
|
+
const { spaceCachePath, localPath, env, flags } = opts;
|
|
278
|
+
const cacheJson = fs.readFileSync(spaceCachePath, "utf-8");
|
|
279
|
+
const cacheRaw = JSON.parse(cacheJson);
|
|
280
|
+
const spaceCache = SpaceCache.parse(cacheRaw);
|
|
281
|
+
const localJson = fs.readFileSync(localPath, "utf-8");
|
|
282
|
+
const localRaw = JSON.parse(localJson);
|
|
283
|
+
let localConfig;
|
|
284
|
+
const v1Result = LocalConfig.safeParse(localRaw);
|
|
285
|
+
if (v1Result.success) {
|
|
286
|
+
localConfig = v1Result.data;
|
|
287
|
+
} else {
|
|
288
|
+
const v0Config = LocalConfigV0.parse(localRaw);
|
|
289
|
+
localConfig = upgradeV0ToV1(v0Config, localPath);
|
|
112
290
|
}
|
|
113
|
-
const
|
|
114
|
-
environment
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
291
|
+
const environment = Environment.parse(
|
|
292
|
+
env.WORKERS_ENVIRONMENT ?? flags.env ?? localConfig.environment
|
|
293
|
+
);
|
|
294
|
+
const baseURLOverride = env.WORKERS_BASE_URL ?? flags["base-url"] ?? localConfig.baseURL;
|
|
295
|
+
const baseURL = baseURLOverride ?? baseUrlForEnvironment(environment);
|
|
296
|
+
const spaceId = localConfig.spaceId;
|
|
297
|
+
const workerId = localConfig.workerId;
|
|
298
|
+
const token = env.WORKERS_TOKEN ?? flags.token ?? null;
|
|
119
299
|
return new Config({
|
|
120
|
-
|
|
121
|
-
|
|
300
|
+
spaceCachePath,
|
|
301
|
+
spaceCache,
|
|
302
|
+
localConfigPath: localPath,
|
|
303
|
+
localConfig,
|
|
304
|
+
environment,
|
|
305
|
+
baseURL,
|
|
306
|
+
spaceId,
|
|
307
|
+
workerId,
|
|
308
|
+
token
|
|
122
309
|
});
|
|
123
310
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
token: null,
|
|
136
|
-
workerId: null
|
|
137
|
-
};
|
|
138
|
-
} else {
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return configFile;
|
|
311
|
+
/**
|
|
312
|
+
* The empty local config.
|
|
313
|
+
*/
|
|
314
|
+
static get emptyLocalConfig() {
|
|
315
|
+
return { version: "1", environment: "prod", spaceId: null, workerId: null };
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* The empty space cache.
|
|
319
|
+
*/
|
|
320
|
+
static get emptySpaceCache() {
|
|
321
|
+
return { version: "1", spaces: {} };
|
|
143
322
|
}
|
|
144
323
|
}
|
|
145
|
-
function
|
|
146
|
-
|
|
324
|
+
function isDir(path2) {
|
|
325
|
+
try {
|
|
326
|
+
return fs.statSync(path2).isDirectory();
|
|
327
|
+
} catch {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
147
330
|
}
|
|
148
|
-
function
|
|
331
|
+
function isFile(path2) {
|
|
149
332
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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.");
|
|
333
|
+
return fs.statSync(path2).isFile();
|
|
334
|
+
} catch {
|
|
335
|
+
return false;
|
|
174
336
|
}
|
|
175
337
|
}
|
|
176
338
|
function baseUrlForEnvironment(environment) {
|
|
177
339
|
switch (environment) {
|
|
178
340
|
case "local":
|
|
179
341
|
return "http://localhost:3000";
|
|
180
|
-
case "
|
|
181
|
-
return "https://
|
|
342
|
+
case "stg":
|
|
343
|
+
return "https://stg.notion.so";
|
|
182
344
|
case "dev":
|
|
183
345
|
return "https://dev.notion.so";
|
|
184
346
|
case "prod":
|
|
185
347
|
return "https://www.notion.so";
|
|
186
348
|
}
|
|
187
349
|
}
|
|
350
|
+
function upgradeV0ToV1(v0Config, localPath) {
|
|
351
|
+
let environment = "prod";
|
|
352
|
+
if (v0Config.environment === "local" || v0Config.environment === "dev" || v0Config.environment === "stg" || v0Config.environment === "prod") {
|
|
353
|
+
environment = v0Config.environment;
|
|
354
|
+
} else if (v0Config.environment === "staging") {
|
|
355
|
+
environment = "stg";
|
|
356
|
+
}
|
|
357
|
+
let spaceId = null;
|
|
358
|
+
if (v0Config.token) {
|
|
359
|
+
const tokenInfo = parseToken(v0Config.token);
|
|
360
|
+
spaceId = tokenInfo.spaceId;
|
|
361
|
+
}
|
|
362
|
+
const localConfig = {
|
|
363
|
+
version: "1",
|
|
364
|
+
environment,
|
|
365
|
+
baseURL: v0Config.baseUrl,
|
|
366
|
+
spaceId,
|
|
367
|
+
workerId: v0Config.workerId ?? null
|
|
368
|
+
};
|
|
369
|
+
fs.writeFileSync(localPath, JSON.stringify(localConfig, null, 2));
|
|
370
|
+
return localConfig;
|
|
371
|
+
}
|
|
188
372
|
export {
|
|
189
373
|
Config,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
extractPayloadFromToken,
|
|
193
|
-
parseEnvironment
|
|
374
|
+
Environment,
|
|
375
|
+
NoSuitableConfigFileError
|
|
194
376
|
};
|
package/dist/deploy.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ApiError
|
|
1
|
+
import type { ApiError } from "./api/client.js";
|
|
2
2
|
import { Result } from "./api/result.js";
|
|
3
|
+
import type { Environment } from "./config.js";
|
|
3
4
|
import type { AuthedContext } from "./handler.js";
|
|
4
5
|
export interface BaseDeployOptions {
|
|
5
6
|
/**
|
package/dist/deploy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../src/deploy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../src/deploy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,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,CAgFjD"}
|
package/dist/flags.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { TypedFlagParameter } from "@stricli/core";
|
|
2
|
-
import {
|
|
2
|
+
import { Environment } from "./config.js";
|
|
3
3
|
import type { LocalContext } from "./context.js";
|
|
4
4
|
export interface GlobalFlags {
|
|
5
5
|
config?: string;
|
|
6
6
|
debug: boolean;
|
|
7
7
|
env?: Environment;
|
|
8
|
-
"base-url"?: string;
|
|
9
8
|
token?: string;
|
|
10
|
-
"
|
|
9
|
+
"base-url"?: string;
|
|
11
10
|
}
|
|
12
11
|
export declare const globalFlags: {
|
|
13
12
|
[K in keyof Required<GlobalFlags>]: TypedFlagParameter<GlobalFlags[K], LocalContext>;
|
package/dist/flags.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,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,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,WAAW,EAAE;KACxB,CAAC,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,kBAAkB,CACrD,WAAW,CAAC,CAAC,CAAC,EACd,YAAY,CACZ;CA+BD,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/flags.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Environment } from "./config.js";
|
|
2
2
|
const globalFlags = {
|
|
3
3
|
config: {
|
|
4
4
|
kind: "parsed",
|
|
@@ -13,26 +13,20 @@ const globalFlags = {
|
|
|
13
13
|
},
|
|
14
14
|
env: {
|
|
15
15
|
kind: "enum",
|
|
16
|
-
values:
|
|
16
|
+
values: Array.from(Environment.values),
|
|
17
17
|
brief: "The environment to use for the command",
|
|
18
18
|
optional: true
|
|
19
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
20
|
token: {
|
|
27
21
|
kind: "parsed",
|
|
28
22
|
parse: String,
|
|
29
23
|
brief: "The token to use for authentication",
|
|
30
24
|
optional: true
|
|
31
25
|
},
|
|
32
|
-
"
|
|
26
|
+
"base-url": {
|
|
33
27
|
kind: "parsed",
|
|
34
28
|
parse: String,
|
|
35
|
-
brief: "The
|
|
29
|
+
brief: "The base URL to use for all API requests",
|
|
36
30
|
optional: true
|
|
37
31
|
}
|
|
38
32
|
};
|
package/dist/handler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/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,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/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,mBAsBd;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,UAlClB,YAAY,8DAiDnB"}
|
package/dist/handler.js
CHANGED
|
@@ -2,10 +2,16 @@ import { ApiClient } from "./api/client.js";
|
|
|
2
2
|
import { Config } from "./config.js";
|
|
3
3
|
function buildHandler(handler) {
|
|
4
4
|
return async function(flags, ...args) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const globalConfigPath = Config.resolveSpaceCachePath({
|
|
6
|
+
env: this.process.env
|
|
7
|
+
});
|
|
8
|
+
const localConfigPath = Config.resolveLocalConfigPath({
|
|
9
|
+
filePath: flags.config ?? this.process.env.WORKERS_CONFIG ?? "./workers.json"
|
|
10
|
+
});
|
|
11
|
+
const config = Config.load({
|
|
12
|
+
spaceCachePath: globalConfigPath,
|
|
13
|
+
localPath: localConfigPath,
|
|
14
|
+
env: process.env,
|
|
9
15
|
flags
|
|
10
16
|
});
|
|
11
17
|
this.io.debugEnabled = flags.debug;
|
|
@@ -13,13 +19,11 @@ function buildHandler(handler) {
|
|
|
13
19
|
};
|
|
14
20
|
}
|
|
15
21
|
function buildAuthedHandler(handler) {
|
|
16
|
-
return buildHandler(function(flags, ...args) {
|
|
17
|
-
const
|
|
18
|
-
const environment = this.config.environment;
|
|
22
|
+
return buildHandler(async function(flags, ...args) {
|
|
23
|
+
const [token, { cellId }] = await this.config.mustGetToken();
|
|
19
24
|
const client = new ApiClient({
|
|
20
25
|
token,
|
|
21
|
-
|
|
22
|
-
baseUrl: this.config.baseUrl,
|
|
26
|
+
baseUrl: this.config.baseURL,
|
|
23
27
|
cellId,
|
|
24
28
|
writer: this.io
|
|
25
29
|
});
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAgDA,eAAO,MAAM,GAAG,0EAgBd,CAAC"}
|
package/dist/routes.js
CHANGED
|
@@ -10,7 +10,7 @@ import { oauthCommands } from "./commands/oauth.js";
|
|
|
10
10
|
import pack from "./commands/pack.js";
|
|
11
11
|
import { runsCommands } from "./commands/runs.js";
|
|
12
12
|
import { secretsCommands } from "./commands/secrets.js";
|
|
13
|
-
import { TokenNotSetError } from "./
|
|
13
|
+
import { TokenNotSetError } from "./token.js";
|
|
14
14
|
const routes = buildRouteMap({
|
|
15
15
|
docs: {
|
|
16
16
|
brief: "A CLI for the Project Ajax platform",
|
|
@@ -22,10 +22,9 @@ data, providing tools to Custom Agents, or running automation tasks.
|
|
|
22
22
|
Most flags are configured either with a config file or flags, but environment
|
|
23
23
|
variables can also be provided:
|
|
24
24
|
|
|
25
|
-
-
|
|
25
|
+
- WORKERS_CONFIG: The path to the config file to use (e.g. ./workers.dev.json)
|
|
26
26
|
- WORKERS_TOKEN: The token to use for authentication
|
|
27
27
|
- WORKERS_ENVIRONMENT: The environment to use
|
|
28
|
-
- WORKERS_WORKER_ID: The worker ID to use
|
|
29
28
|
- WORKERS_BASE_URL: The base API URL to use
|
|
30
29
|
`.trim(),
|
|
31
30
|
hideRoute: {
|