@dk/jolly 0.1.0

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 (44) hide show
  1. package/.env.example +3 -0
  2. package/.mcp.json +7 -0
  3. package/.sisyphus/boulder.json +13 -0
  4. package/.sisyphus/notepads/saleor-agent-cli/decisions.md +11 -0
  5. package/.sisyphus/notepads/saleor-agent-cli/issues.md +6 -0
  6. package/.sisyphus/notepads/saleor-agent-cli/learnings.md +6 -0
  7. package/.sisyphus/plans/saleor-agent-cli.md +600 -0
  8. package/AGENTS.md +46 -0
  9. package/README.md +121 -0
  10. package/bun.lock +65 -0
  11. package/bunfig.toml +8 -0
  12. package/dist/agent.js +259 -0
  13. package/dist/bootstrap.js +492 -0
  14. package/dist/index.js +5798 -0
  15. package/package.json +29 -0
  16. package/src/agents/index.ts +1 -0
  17. package/src/agents/setup.ts +210 -0
  18. package/src/api/auth.ts +21 -0
  19. package/src/api/client.ts +78 -0
  20. package/src/api/endpoints.ts +8 -0
  21. package/src/api/index.ts +4 -0
  22. package/src/cli/agent.ts +26 -0
  23. package/src/cli/bootstrap.ts +24 -0
  24. package/src/cli/commands/agent.ts +40 -0
  25. package/src/cli/commands/app.ts +51 -0
  26. package/src/cli/commands/config.ts +38 -0
  27. package/src/cli/commands/store.ts +65 -0
  28. package/src/cli/index.ts +16 -0
  29. package/src/commands/app.ts +126 -0
  30. package/src/commands/index.ts +1 -0
  31. package/src/commands/store.ts +64 -0
  32. package/src/test/command-handlers.test.ts +227 -0
  33. package/src/test/e2e-flows.test.ts +212 -0
  34. package/src/test/entry-points.test.ts +123 -0
  35. package/src/test/error-handling.test.ts +137 -0
  36. package/src/test/helpers.ts +49 -0
  37. package/src/test/index.ts +1 -0
  38. package/src/test/mocks.ts +132 -0
  39. package/src/test/setup.ts +29 -0
  40. package/src/tui/components.ts +77 -0
  41. package/src/tui/index.ts +3 -0
  42. package/src/tui/renderer.ts +34 -0
  43. package/src/tui/theme.ts +38 -0
  44. package/tsconfig.json +20 -0
@@ -0,0 +1,492 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ var __create = Object.create;
4
+ var __getProtoOf = Object.getPrototypeOf;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __toESM = (mod, isNodeMode, target) => {
9
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
10
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
+ for (let key of __getOwnPropNames(mod))
12
+ if (!__hasOwnProp.call(to, key))
13
+ __defProp(to, key, {
14
+ get: () => mod[key],
15
+ enumerable: true
16
+ });
17
+ return to;
18
+ };
19
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
20
+ var __require = import.meta.require;
21
+
22
+ // node_modules/dotenv/lib/main.js
23
+ var require_main = __commonJS((exports, module) => {
24
+ var fs = __require("fs");
25
+ var path = __require("path");
26
+ var os = __require("os");
27
+ var crypto = __require("crypto");
28
+ var TIPS = [
29
+ "\u25C8 encrypted .env [www.dotenvx.com]",
30
+ "\u25C8 secrets for agents [www.dotenvx.com]",
31
+ "\u2301 auth for agents [www.vestauth.com]",
32
+ "\u2318 custom filepath { path: '/custom/path/.env' }",
33
+ "\u2318 enable debugging { debug: true }",
34
+ "\u2318 override existing { override: true }",
35
+ "\u2318 suppress logs { quiet: true }",
36
+ "\u2318 multiple files { path: ['.env.local', '.env'] }"
37
+ ];
38
+ function _getRandomTip() {
39
+ return TIPS[Math.floor(Math.random() * TIPS.length)];
40
+ }
41
+ function parseBoolean(value) {
42
+ if (typeof value === "string") {
43
+ return !["false", "0", "no", "off", ""].includes(value.toLowerCase());
44
+ }
45
+ return Boolean(value);
46
+ }
47
+ function supportsAnsi() {
48
+ return process.stdout.isTTY;
49
+ }
50
+ function dim(text) {
51
+ return supportsAnsi() ? `\x1B[2m${text}\x1B[0m` : text;
52
+ }
53
+ var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
54
+ function parse(src) {
55
+ const obj = {};
56
+ let lines = src.toString();
57
+ lines = lines.replace(/\r\n?/mg, `
58
+ `);
59
+ let match;
60
+ while ((match = LINE.exec(lines)) != null) {
61
+ const key = match[1];
62
+ let value = match[2] || "";
63
+ value = value.trim();
64
+ const maybeQuote = value[0];
65
+ value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
66
+ if (maybeQuote === '"') {
67
+ value = value.replace(/\\n/g, `
68
+ `);
69
+ value = value.replace(/\\r/g, "\r");
70
+ }
71
+ obj[key] = value;
72
+ }
73
+ return obj;
74
+ }
75
+ function _parseVault(options) {
76
+ options = options || {};
77
+ const vaultPath = _vaultPath(options);
78
+ options.path = vaultPath;
79
+ const result = DotenvModule.configDotenv(options);
80
+ if (!result.parsed) {
81
+ const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
82
+ err.code = "MISSING_DATA";
83
+ throw err;
84
+ }
85
+ const keys = _dotenvKey(options).split(",");
86
+ const length = keys.length;
87
+ let decrypted;
88
+ for (let i = 0;i < length; i++) {
89
+ try {
90
+ const key = keys[i].trim();
91
+ const attrs = _instructions(result, key);
92
+ decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
93
+ break;
94
+ } catch (error) {
95
+ if (i + 1 >= length) {
96
+ throw error;
97
+ }
98
+ }
99
+ }
100
+ return DotenvModule.parse(decrypted);
101
+ }
102
+ function _warn(message) {
103
+ console.error(`\u26A0 ${message}`);
104
+ }
105
+ function _debug(message) {
106
+ console.log(`\u2506 ${message}`);
107
+ }
108
+ function _log(message) {
109
+ console.log(`\u25C7 ${message}`);
110
+ }
111
+ function _dotenvKey(options) {
112
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
113
+ return options.DOTENV_KEY;
114
+ }
115
+ if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
116
+ return process.env.DOTENV_KEY;
117
+ }
118
+ return "";
119
+ }
120
+ function _instructions(result, dotenvKey) {
121
+ let uri;
122
+ try {
123
+ uri = new URL(dotenvKey);
124
+ } catch (error) {
125
+ if (error.code === "ERR_INVALID_URL") {
126
+ const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
127
+ err.code = "INVALID_DOTENV_KEY";
128
+ throw err;
129
+ }
130
+ throw error;
131
+ }
132
+ const key = uri.password;
133
+ if (!key) {
134
+ const err = new Error("INVALID_DOTENV_KEY: Missing key part");
135
+ err.code = "INVALID_DOTENV_KEY";
136
+ throw err;
137
+ }
138
+ const environment = uri.searchParams.get("environment");
139
+ if (!environment) {
140
+ const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
141
+ err.code = "INVALID_DOTENV_KEY";
142
+ throw err;
143
+ }
144
+ const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
145
+ const ciphertext = result.parsed[environmentKey];
146
+ if (!ciphertext) {
147
+ const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
148
+ err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
149
+ throw err;
150
+ }
151
+ return { ciphertext, key };
152
+ }
153
+ function _vaultPath(options) {
154
+ let possibleVaultPath = null;
155
+ if (options && options.path && options.path.length > 0) {
156
+ if (Array.isArray(options.path)) {
157
+ for (const filepath of options.path) {
158
+ if (fs.existsSync(filepath)) {
159
+ possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
160
+ }
161
+ }
162
+ } else {
163
+ possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
164
+ }
165
+ } else {
166
+ possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
167
+ }
168
+ if (fs.existsSync(possibleVaultPath)) {
169
+ return possibleVaultPath;
170
+ }
171
+ return null;
172
+ }
173
+ function _resolveHome(envPath) {
174
+ return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
175
+ }
176
+ function _configVault(options) {
177
+ const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
178
+ const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
179
+ if (debug || !quiet) {
180
+ _log("loading env from encrypted .env.vault");
181
+ }
182
+ const parsed = DotenvModule._parseVault(options);
183
+ let processEnv = process.env;
184
+ if (options && options.processEnv != null) {
185
+ processEnv = options.processEnv;
186
+ }
187
+ DotenvModule.populate(processEnv, parsed, options);
188
+ return { parsed };
189
+ }
190
+ function configDotenv(options) {
191
+ const dotenvPath = path.resolve(process.cwd(), ".env");
192
+ let encoding = "utf8";
193
+ let processEnv = process.env;
194
+ if (options && options.processEnv != null) {
195
+ processEnv = options.processEnv;
196
+ }
197
+ let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
198
+ let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
199
+ if (options && options.encoding) {
200
+ encoding = options.encoding;
201
+ } else {
202
+ if (debug) {
203
+ _debug("no encoding is specified (UTF-8 is used by default)");
204
+ }
205
+ }
206
+ let optionPaths = [dotenvPath];
207
+ if (options && options.path) {
208
+ if (!Array.isArray(options.path)) {
209
+ optionPaths = [_resolveHome(options.path)];
210
+ } else {
211
+ optionPaths = [];
212
+ for (const filepath of options.path) {
213
+ optionPaths.push(_resolveHome(filepath));
214
+ }
215
+ }
216
+ }
217
+ let lastError;
218
+ const parsedAll = {};
219
+ for (const path2 of optionPaths) {
220
+ try {
221
+ const parsed = DotenvModule.parse(fs.readFileSync(path2, { encoding }));
222
+ DotenvModule.populate(parsedAll, parsed, options);
223
+ } catch (e) {
224
+ if (debug) {
225
+ _debug(`failed to load ${path2} ${e.message}`);
226
+ }
227
+ lastError = e;
228
+ }
229
+ }
230
+ const populated = DotenvModule.populate(processEnv, parsedAll, options);
231
+ debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
232
+ quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
233
+ if (debug || !quiet) {
234
+ const keysCount = Object.keys(populated).length;
235
+ const shortPaths = [];
236
+ for (const filePath of optionPaths) {
237
+ try {
238
+ const relative = path.relative(process.cwd(), filePath);
239
+ shortPaths.push(relative);
240
+ } catch (e) {
241
+ if (debug) {
242
+ _debug(`failed to load ${filePath} ${e.message}`);
243
+ }
244
+ lastError = e;
245
+ }
246
+ }
247
+ _log(`injecting env (${keysCount}) from ${shortPaths.join(",")} ${dim(`// tip: ${_getRandomTip()}`)}`);
248
+ }
249
+ if (lastError) {
250
+ return { parsed: parsedAll, error: lastError };
251
+ } else {
252
+ return { parsed: parsedAll };
253
+ }
254
+ }
255
+ function config(options) {
256
+ if (_dotenvKey(options).length === 0) {
257
+ return DotenvModule.configDotenv(options);
258
+ }
259
+ const vaultPath = _vaultPath(options);
260
+ if (!vaultPath) {
261
+ _warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
262
+ return DotenvModule.configDotenv(options);
263
+ }
264
+ return DotenvModule._configVault(options);
265
+ }
266
+ function decrypt(encrypted, keyStr) {
267
+ const key = Buffer.from(keyStr.slice(-64), "hex");
268
+ let ciphertext = Buffer.from(encrypted, "base64");
269
+ const nonce = ciphertext.subarray(0, 12);
270
+ const authTag = ciphertext.subarray(-16);
271
+ ciphertext = ciphertext.subarray(12, -16);
272
+ try {
273
+ const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
274
+ aesgcm.setAuthTag(authTag);
275
+ return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
276
+ } catch (error) {
277
+ const isRange = error instanceof RangeError;
278
+ const invalidKeyLength = error.message === "Invalid key length";
279
+ const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
280
+ if (isRange || invalidKeyLength) {
281
+ const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
282
+ err.code = "INVALID_DOTENV_KEY";
283
+ throw err;
284
+ } else if (decryptionFailed) {
285
+ const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
286
+ err.code = "DECRYPTION_FAILED";
287
+ throw err;
288
+ } else {
289
+ throw error;
290
+ }
291
+ }
292
+ }
293
+ function populate(processEnv, parsed, options = {}) {
294
+ const debug = Boolean(options && options.debug);
295
+ const override = Boolean(options && options.override);
296
+ const populated = {};
297
+ if (typeof parsed !== "object") {
298
+ const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
299
+ err.code = "OBJECT_REQUIRED";
300
+ throw err;
301
+ }
302
+ for (const key of Object.keys(parsed)) {
303
+ if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
304
+ if (override === true) {
305
+ processEnv[key] = parsed[key];
306
+ populated[key] = parsed[key];
307
+ }
308
+ if (debug) {
309
+ if (override === true) {
310
+ _debug(`"${key}" is already defined and WAS overwritten`);
311
+ } else {
312
+ _debug(`"${key}" is already defined and was NOT overwritten`);
313
+ }
314
+ }
315
+ } else {
316
+ processEnv[key] = parsed[key];
317
+ populated[key] = parsed[key];
318
+ }
319
+ }
320
+ return populated;
321
+ }
322
+ var DotenvModule = {
323
+ configDotenv,
324
+ _configVault,
325
+ _parseVault,
326
+ config,
327
+ decrypt,
328
+ parse,
329
+ populate
330
+ };
331
+ exports.configDotenv = DotenvModule.configDotenv;
332
+ exports._configVault = DotenvModule._configVault;
333
+ exports._parseVault = DotenvModule._parseVault;
334
+ exports.config = DotenvModule.config;
335
+ exports.decrypt = DotenvModule.decrypt;
336
+ exports.parse = DotenvModule.parse;
337
+ exports.populate = DotenvModule.populate;
338
+ module.exports = DotenvModule;
339
+ });
340
+
341
+ // src/api/client.ts
342
+ class SaleorCloudClient {
343
+ baseUrl = "https://cloud.saleor.io/api";
344
+ token;
345
+ constructor(token) {
346
+ this.token = token || process.env.SALEOR_CLOUD_TOKEN || "";
347
+ if (!this.token) {
348
+ throw new Error("SALEOR_CLOUD_TOKEN environment variable is required");
349
+ }
350
+ }
351
+ async request(endpoint, options) {
352
+ const response = await fetch(`${this.baseUrl}${endpoint}`, {
353
+ ...options,
354
+ headers: {
355
+ Authorization: `Bearer ${this.token}`,
356
+ "Content-Type": "application/json",
357
+ ...options?.headers
358
+ }
359
+ });
360
+ if (!response.ok) {
361
+ throw new Error(`API error: ${response.status} ${response.statusText}`);
362
+ }
363
+ return response.json();
364
+ }
365
+ async getStores() {
366
+ return this.request("/stores");
367
+ }
368
+ async createStore(name, region = "us-east-1") {
369
+ return this.request("/stores", {
370
+ method: "POST",
371
+ body: JSON.stringify({ name, region })
372
+ });
373
+ }
374
+ async getEnvironments(storeId) {
375
+ return this.request(`/stores/${storeId}/environments`);
376
+ }
377
+ async createEnvironment(storeId, name) {
378
+ return this.request(`/stores/${storeId}/environments`, {
379
+ method: "POST",
380
+ body: JSON.stringify({ name })
381
+ });
382
+ }
383
+ async registerApp(environmentId, appType, name) {
384
+ return this.request(`/environments/${environmentId}/apps`, {
385
+ method: "POST",
386
+ body: JSON.stringify({ type: appType, name })
387
+ });
388
+ }
389
+ }
390
+
391
+ // src/api/auth.ts
392
+ var import_dotenv = __toESM(require_main(), 1);
393
+ import_dotenv.config();
394
+ function requireToken() {
395
+ const token = process.env.SALEOR_CLOUD_TOKEN;
396
+ if (!token) {
397
+ console.error("Error: SALEOR_CLOUD_TOKEN environment variable is required");
398
+ console.error("Get your token at: https://cloud.saleor.io/settings/api-tokens");
399
+ process.exit(1);
400
+ }
401
+ return token;
402
+ }
403
+
404
+ // src/tui/theme.ts
405
+ var theme = {
406
+ reset: "\x1B[0m",
407
+ bold: "\x1B[1m",
408
+ dim: "\x1B[2m",
409
+ italic: "\x1B[3m",
410
+ underline: "\x1B[4m",
411
+ fg: {
412
+ black: "\x1B[30m",
413
+ red: "\x1B[31m",
414
+ green: "\x1B[32m",
415
+ yellow: "\x1B[33m",
416
+ blue: "\x1B[34m",
417
+ magenta: "\x1B[35m",
418
+ cyan: "\x1B[36m",
419
+ white: "\x1B[37m",
420
+ gray: "\x1B[90m",
421
+ brightBlack: "\x1B[30;1m",
422
+ brightRed: "\x1B[31;1m",
423
+ brightGreen: "\x1B[32;1m",
424
+ brightYellow: "\x1B[33;1m",
425
+ brightBlue: "\x1B[34;1m",
426
+ brightMagenta: "\x1B[35;1m",
427
+ brightCyan: "\x1B[36;1m",
428
+ brightWhite: "\x1B[37;1m"
429
+ },
430
+ bg: {
431
+ black: "\x1B[40m",
432
+ red: "\x1B[41m",
433
+ green: "\x1B[42m",
434
+ yellow: "\x1B[43m",
435
+ blue: "\x1B[44m",
436
+ magenta: "\x1B[45m",
437
+ cyan: "\x1B[46m",
438
+ white: "\x1B[47m"
439
+ }
440
+ };
441
+
442
+ // src/tui/components.ts
443
+ function text(content, color) {
444
+ return `${color || theme.fg.white}${content}${theme.reset}`;
445
+ }
446
+ function success(msg) {
447
+ return text(msg, theme.fg.green);
448
+ }
449
+ function error(msg) {
450
+ return text(msg, theme.fg.red);
451
+ }
452
+ function info(msg) {
453
+ return text(msg, theme.fg.cyan);
454
+ }
455
+
456
+ // src/commands/store.ts
457
+ async function createStore(name, region) {
458
+ const token = requireToken();
459
+ const client = new SaleorCloudClient(token);
460
+ info(`Creating store: ${name} in ${region}...`);
461
+ try {
462
+ const result = await client.createStore(name, region);
463
+ success(`Store created successfully!`);
464
+ info(`Store ID: ${result.store.id}`);
465
+ info(`Dashboard: https://cloud.saleor.io/stores/${result.store.id}`);
466
+ } catch (err) {
467
+ error(`Failed to create store: ${err}`);
468
+ process.exit(1);
469
+ }
470
+ }
471
+
472
+ // src/cli/bootstrap.ts
473
+ async function main() {
474
+ const args = process.argv.slice(2);
475
+ const projectName = args[0];
476
+ if (projectName) {
477
+ console.log(`Bootstrapping Saleor project: ${projectName}...`);
478
+ await createStore(projectName, "us-east-1");
479
+ return;
480
+ }
481
+ console.log("Saleor Store Bootstrapper");
482
+ console.log(`------------------------
483
+ `);
484
+ console.log("Usage: npm create @saleor/jolly <project-name>");
485
+ console.log("Or: jolly store create --name <name>");
486
+ console.log(`
487
+ For app scaffolding: jolly app create --name <name> --type <type>`);
488
+ }
489
+ main().catch((err) => {
490
+ console.error(`Bootstrap failed: ${err}`);
491
+ process.exit(1);
492
+ });