@pump-inc/cli 0.0.1

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 (39) hide show
  1. package/README.md +905 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +7 -0
  4. package/bin/run-pkg.js +13 -0
  5. package/bin/run.cmd +3 -0
  6. package/bin/run.js +7 -0
  7. package/dist/api-XWM8zKbb.cjs +21 -0
  8. package/dist/api-client-bnV0ib_r.cjs +1207 -0
  9. package/dist/base-command-GfDxcqx6.cjs +451 -0
  10. package/dist/bin.cjs +15 -0
  11. package/dist/chunk-CbDLau6x.cjs +34 -0
  12. package/dist/commands/admin/config/set.cjs +40 -0
  13. package/dist/commands/admin/organization/create.cjs +83 -0
  14. package/dist/commands/admin/organization/get.cjs +77 -0
  15. package/dist/commands/admin/organization/list.cjs +103 -0
  16. package/dist/commands/admin/user/create.cjs +82 -0
  17. package/dist/commands/api-key/create.cjs +81 -0
  18. package/dist/commands/api-key/delete.cjs +48 -0
  19. package/dist/commands/api-key/list.cjs +85 -0
  20. package/dist/commands/api-key/update.cjs +81 -0
  21. package/dist/commands/app/create.cjs +97 -0
  22. package/dist/commands/app/deploy.cjs +74 -0
  23. package/dist/commands/app/list.cjs +64 -0
  24. package/dist/commands/app/secrets.cjs +43 -0
  25. package/dist/commands/app/status.cjs +78 -0
  26. package/dist/commands/app/stop.cjs +49 -0
  27. package/dist/commands/app/usage.cjs +79 -0
  28. package/dist/commands/auth/test.cjs +56 -0
  29. package/dist/commands/config/validate.cjs +32 -0
  30. package/dist/commands/project/create.cjs +79 -0
  31. package/dist/fix-event-emitter-uhRntilb.cjs +21 -0
  32. package/dist/index.cjs +16 -0
  33. package/dist/util/api.cjs +3 -0
  34. package/dist/util/base-command.cjs +4 -0
  35. package/dist/util/fix-event-emitter.cjs +3 -0
  36. package/dist/util/validate-config.cjs +3 -0
  37. package/dist/validate-config-C9krCzRv.cjs +24 -0
  38. package/oclif.manifest.json +1099 -0
  39. package/package.json +85 -0
@@ -0,0 +1,1207 @@
1
+
2
+ //#region ../node_modules/.pnpm/typescript-result@3.5.2/node_modules/typescript-result/dist/index.js
3
+ function isPromise(value) {
4
+ if (value === null || value === void 0) return false;
5
+ if (typeof value !== "object") return false;
6
+ return value instanceof Promise || "then" in value;
7
+ }
8
+ function isFunction(value) {
9
+ return typeof value === "function";
10
+ }
11
+ function isAsyncFn(fn) {
12
+ return fn.constructor.name === "AsyncFunction";
13
+ }
14
+ function isGenerator(obj) {
15
+ return typeof obj === "object" && obj !== null && typeof obj.next === "function" && typeof obj.throw === "function" && typeof obj.return === "function" && typeof obj[Symbol.iterator] === "function" && obj[Symbol.iterator]() === obj;
16
+ }
17
+ function isAsyncGenerator(obj) {
18
+ return typeof obj === "object" && obj !== null && typeof obj.next === "function" && typeof obj.throw === "function" && typeof obj.return === "function" && typeof obj[Symbol.asyncIterator] === "function" && obj[Symbol.asyncIterator]() === obj;
19
+ }
20
+ var NonExhaustiveError = class extends Error {
21
+ constructor(error) {
22
+ super("Not all error cases were handled");
23
+ this.error = error;
24
+ }
25
+ };
26
+ var Matcher = class {
27
+ constructor(error) {
28
+ this.error = error;
29
+ }
30
+ cases = [];
31
+ defaultHandler = void 0;
32
+ when(value, ...args) {
33
+ const cases = [value, ...args.slice(0, -1)];
34
+ const handler = args.at(-1);
35
+ this.cases.push(...cases.map((value2) => ({
36
+ value: value2,
37
+ handler
38
+ })));
39
+ return this;
40
+ }
41
+ else = (handler) => {
42
+ if (this.defaultHandler) throw new Error("already registered an 'else' handler");
43
+ this.defaultHandler = handler;
44
+ return this;
45
+ };
46
+ run = () => {
47
+ const isAsync = this.cases.some((item) => isAsyncFn(item.handler));
48
+ for (const item of this.cases) if (isFunction(item.value) && this.error instanceof item.value || item.value === this.error) {
49
+ const value = item.handler(this.error);
50
+ return isPromise(value) ? value : isAsync ? Promise.resolve(value) : value;
51
+ }
52
+ if (this.defaultHandler) return this.defaultHandler(this.error);
53
+ throw new NonExhaustiveError(this.error);
54
+ };
55
+ };
56
+ var AsyncResult = class _AsyncResult extends Promise {
57
+ constructor(executor) {
58
+ super(executor);
59
+ }
60
+ *[Symbol.iterator]() {
61
+ return yield this;
62
+ }
63
+ get isAsyncResult() {
64
+ return true;
65
+ }
66
+ async toTuple() {
67
+ return (await this).toTuple();
68
+ }
69
+ async errorOrNull() {
70
+ return (await this).errorOrNull();
71
+ }
72
+ async getOrNull() {
73
+ return (await this).getOrNull();
74
+ }
75
+ async getOrDefault(defaultValue) {
76
+ return (await this).getOrDefault(defaultValue);
77
+ }
78
+ async getOrElse(onFailure) {
79
+ return (await this).getOrElse(onFailure);
80
+ }
81
+ async getOrThrow() {
82
+ return (await this).getOrThrow();
83
+ }
84
+ async fold(onSuccess, onFailure) {
85
+ return (await this).fold(onSuccess, onFailure);
86
+ }
87
+ onFailure(action) {
88
+ return new _AsyncResult((resolve, reject) => this.then(async (result) => {
89
+ try {
90
+ if (!result.ok) await action(result.error);
91
+ resolve(result);
92
+ } catch (e) {
93
+ reject(e);
94
+ }
95
+ }).catch(reject));
96
+ }
97
+ onSuccess(action) {
98
+ return new _AsyncResult((resolve, reject) => this.then(async (result) => {
99
+ try {
100
+ if (result.ok) await action(result.value);
101
+ resolve(result);
102
+ } catch (error) {
103
+ reject(error);
104
+ }
105
+ }).catch(reject));
106
+ }
107
+ map(transform) {
108
+ return new _AsyncResult((resolve, reject) => {
109
+ this.then(async (result) => resolve(await result.map(transform))).catch(reject);
110
+ });
111
+ }
112
+ mapCatching(transformValue, transformError) {
113
+ return new _AsyncResult((resolve, reject) => {
114
+ this.map(transformValue).then((result) => resolve(result)).catch((error) => {
115
+ try {
116
+ resolve(ResultFactory.error(transformError ? transformError(error) : error));
117
+ } catch (err) {
118
+ reject(err);
119
+ }
120
+ });
121
+ });
122
+ }
123
+ mapError(transform) {
124
+ return new _AsyncResult((resolve, reject) => this.then(async (result) => {
125
+ try {
126
+ resolve(result.mapError(transform));
127
+ } catch (error) {
128
+ reject(error);
129
+ }
130
+ }).catch(reject));
131
+ }
132
+ recover(onFailure) {
133
+ return new _AsyncResult((resolve, reject) => this.then(async (result) => {
134
+ try {
135
+ resolve(await result.recover(onFailure));
136
+ } catch (error) {
137
+ reject(error);
138
+ }
139
+ }).catch(reject));
140
+ }
141
+ recoverCatching(onFailure, transformError) {
142
+ return new _AsyncResult((resolve, reject) => this.then((result) => {
143
+ resolve(result.recoverCatching(onFailure, transformError));
144
+ }).catch(reject));
145
+ }
146
+ toString() {
147
+ return "AsyncResult";
148
+ }
149
+ static error(error) {
150
+ return new _AsyncResult((resolve) => resolve(ResultFactory.error(error)));
151
+ }
152
+ static ok(value) {
153
+ return new _AsyncResult((resolve) => resolve(ResultFactory.ok(value)));
154
+ }
155
+ static fromPromise(promise) {
156
+ return new _AsyncResult((resolve, reject) => {
157
+ promise.then((value) => resolve(ResultFactory.isResult(value) ? value : ResultFactory.ok(value))).catch(reject);
158
+ });
159
+ }
160
+ static fromPromiseCatching(promise, transform) {
161
+ return new _AsyncResult((resolve, reject) => {
162
+ promise.then((value) => resolve(ResultFactory.isResult(value) ? value : ResultFactory.ok(value))).catch((caughtError) => {
163
+ resolve(ResultFactory.error(transform?.(caughtError) ?? caughtError));
164
+ }).catch(reject);
165
+ });
166
+ }
167
+ };
168
+ var Result = class {
169
+ constructor(_value, _error) {
170
+ this._value = _value;
171
+ this._error = _error;
172
+ }
173
+ *[Symbol.iterator]() {
174
+ return yield this;
175
+ }
176
+ get isResult() {
177
+ return true;
178
+ }
179
+ get value() {
180
+ return this._value;
181
+ }
182
+ get error() {
183
+ return this._error;
184
+ }
185
+ get success() {
186
+ return this.error === void 0;
187
+ }
188
+ get failure() {
189
+ return this.error !== void 0;
190
+ }
191
+ get ok() {
192
+ return this.success;
193
+ }
194
+ isOk() {
195
+ return this.success;
196
+ }
197
+ isError() {
198
+ return this.failure;
199
+ }
200
+ toTuple() {
201
+ return [this._value ?? null, this._error ?? null];
202
+ }
203
+ errorOrNull() {
204
+ return this.failure ? this._error : null;
205
+ }
206
+ getOrNull() {
207
+ return this.success ? this._value : null;
208
+ }
209
+ getOrDefault(defaultValue) {
210
+ return this.success ? this._value : defaultValue;
211
+ }
212
+ getOrElse(onFailure) {
213
+ if (isAsyncFn(onFailure)) return this.success ? Promise.resolve(this._value) : onFailure(this._error);
214
+ return this.success ? this._value : onFailure(this._error);
215
+ }
216
+ getOrThrow() {
217
+ if (this.success) return this._value;
218
+ throw this._error;
219
+ }
220
+ fold(onSuccess, onFailure) {
221
+ const isAsync = isAsyncFn(onSuccess) || isAsyncFn(onFailure);
222
+ const outcome = this.success ? onSuccess(this._value) : onFailure(this._error);
223
+ return isAsync && !isPromise(outcome) ? Promise.resolve(outcome) : outcome;
224
+ }
225
+ match() {
226
+ return this.failure ? new Matcher(this._error) : void 0;
227
+ }
228
+ onFailure(action) {
229
+ const isAsync = isAsyncFn(action);
230
+ if (this.failure) {
231
+ const outcome = action(this._error);
232
+ if (isAsync) return new AsyncResult((resolve) => {
233
+ outcome.then(() => resolve(ResultFactory.error(this._error)));
234
+ });
235
+ return this;
236
+ }
237
+ return isAsync ? AsyncResult.ok(this._value) : this;
238
+ }
239
+ onSuccess(action) {
240
+ const isAsync = isAsyncFn(action);
241
+ if (this.success) {
242
+ const outcome = action(this._value);
243
+ if (isAsync) return new AsyncResult((resolve) => {
244
+ outcome.then(() => resolve(ResultFactory.ok(this._value)));
245
+ });
246
+ return this;
247
+ }
248
+ return isAsync ? AsyncResult.error(this._error) : this;
249
+ }
250
+ map(transform) {
251
+ return this.success ? ResultFactory.run(() => transform(this._value)) : isAsyncFn(transform) ? AsyncResult.error(this._error) : this;
252
+ }
253
+ mapCatching(transformValue, transformError) {
254
+ return this.success ? ResultFactory.try(() => transformValue(this._value), transformError) : this;
255
+ }
256
+ mapError(transform) {
257
+ if (this.success) return this;
258
+ return ResultFactory.error(transform(this._error));
259
+ }
260
+ recover(onFailure) {
261
+ return this.success ? isAsyncFn(onFailure) ? AsyncResult.ok(this._value) : this : ResultFactory.run(() => onFailure(this._error));
262
+ }
263
+ recoverCatching(onFailure, transformError) {
264
+ return this.success ? isAsyncFn(onFailure) ? AsyncResult.ok(this._value) : this : ResultFactory.try(() => onFailure(this._error), transformError);
265
+ }
266
+ toString() {
267
+ if (this.success) return `Result.ok(${this._value})`;
268
+ return `Result.error(${this.error})`;
269
+ }
270
+ };
271
+ var ResultFactory = class _ResultFactory {
272
+ constructor() {}
273
+ static ok(value) {
274
+ return new Result(value, void 0);
275
+ }
276
+ static error(error) {
277
+ return new Result(void 0, error);
278
+ }
279
+ static isResult(possibleResult) {
280
+ return possibleResult instanceof Result;
281
+ }
282
+ static isAsyncResult(possibleAsyncResult) {
283
+ return possibleAsyncResult instanceof AsyncResult;
284
+ }
285
+ static run(fn) {
286
+ const returnValue = fn();
287
+ if (isGenerator(returnValue) || isAsyncGenerator(returnValue)) return _ResultFactory.handleGenerator(returnValue);
288
+ if (isPromise(returnValue)) return AsyncResult.fromPromise(returnValue);
289
+ return _ResultFactory.isResult(returnValue) ? returnValue : _ResultFactory.ok(returnValue);
290
+ }
291
+ static allInternal(items, opts) {
292
+ const runner = opts.catching ? _ResultFactory.try : _ResultFactory.run;
293
+ const flattened = [];
294
+ let isAsync = items.some(isPromise);
295
+ let hasFailure = false;
296
+ for (const item of items) if (isFunction(item)) {
297
+ if (hasFailure) continue;
298
+ const returnValue = runner(item);
299
+ if (_ResultFactory.isResult(returnValue) && !returnValue.ok) {
300
+ hasFailure = true;
301
+ if (!isAsync) return returnValue;
302
+ }
303
+ if (_ResultFactory.isAsyncResult(returnValue)) isAsync = true;
304
+ flattened.push(returnValue);
305
+ } else if (_ResultFactory.isResult(item)) {
306
+ if (!item.ok) {
307
+ hasFailure = true;
308
+ if (!isAsync) return item;
309
+ }
310
+ flattened.push(item);
311
+ } else if (_ResultFactory.isAsyncResult(item)) {
312
+ isAsync = true;
313
+ flattened.push(item);
314
+ } else if (isPromise(item)) {
315
+ isAsync = true;
316
+ flattened.push(opts.catching ? AsyncResult.fromPromiseCatching(item) : AsyncResult.fromPromise(item));
317
+ } else flattened.push(_ResultFactory.ok(item));
318
+ if (isAsync) return new AsyncResult((resolve, reject) => {
319
+ const asyncResults = [];
320
+ const asyncIndexes = [];
321
+ for (let i = 0; i < flattened.length; i++) {
322
+ const item = flattened[i];
323
+ if (_ResultFactory.isAsyncResult(item)) {
324
+ asyncResults.push(item);
325
+ asyncIndexes.push(i);
326
+ }
327
+ }
328
+ Promise.all(asyncResults).then((resolvedResults) => {
329
+ const merged = [...flattened];
330
+ for (let i = 0; i < resolvedResults.length; i++) merged[asyncIndexes[i]] = resolvedResults[i];
331
+ const firstFailedResult = merged.find((resolvedResult) => !resolvedResult.ok);
332
+ if (firstFailedResult) {
333
+ resolve(firstFailedResult);
334
+ return;
335
+ }
336
+ resolve(_ResultFactory.ok(merged.map((result) => result.getOrNull())));
337
+ }).catch((reason) => {
338
+ reject(reason);
339
+ });
340
+ });
341
+ return _ResultFactory.ok(flattened.map((result) => result.getOrNull()));
342
+ }
343
+ static all(...items) {
344
+ return _ResultFactory.allInternal(items, { catching: false });
345
+ }
346
+ static allCatching(...items) {
347
+ return _ResultFactory.allInternal(items, { catching: true });
348
+ }
349
+ static wrap(fn, transformError) {
350
+ return function wrapped(...args) {
351
+ return _ResultFactory.try(() => fn(...args), transformError);
352
+ };
353
+ }
354
+ static try(fn, transform) {
355
+ try {
356
+ const returnValue = fn();
357
+ if (isGenerator(returnValue)) return _ResultFactory.handleGenerator(returnValue);
358
+ if (isAsyncGenerator(returnValue)) {
359
+ const asyncResult = _ResultFactory.handleGenerator(returnValue);
360
+ return AsyncResult.fromPromiseCatching(asyncResult, transform);
361
+ }
362
+ if (isPromise(returnValue)) return AsyncResult.fromPromiseCatching(returnValue, transform);
363
+ return _ResultFactory.isResult(returnValue) ? returnValue : _ResultFactory.ok(returnValue);
364
+ } catch (caughtError) {
365
+ return _ResultFactory.error(transform?.(caughtError) ?? caughtError);
366
+ }
367
+ }
368
+ static fromAsync(valueOrFn) {
369
+ return _ResultFactory.run(typeof valueOrFn === "function" ? valueOrFn : () => valueOrFn);
370
+ }
371
+ static fromAsyncCatching(valueOrFn, transformError) {
372
+ return _ResultFactory.try(typeof valueOrFn === "function" ? valueOrFn : () => valueOrFn, transformError);
373
+ }
374
+ static handleGenerator(it) {
375
+ function handleResult(result2) {
376
+ if (!result2.ok) return iterate(it.return(result2));
377
+ return iterate(it.next(result2.value));
378
+ }
379
+ function handleStep(step) {
380
+ if (step.done) {
381
+ if (step.value instanceof Result || step.value instanceof AsyncResult) return step.value;
382
+ return _ResultFactory.ok(step.value);
383
+ }
384
+ if (step.value instanceof Result) return handleResult(step.value);
385
+ if (step.value instanceof AsyncResult) return step.value.then(handleResult);
386
+ return iterate(it.next(step.value));
387
+ }
388
+ function iterate(iteratorResult) {
389
+ return isPromise(iteratorResult) ? iteratorResult.then(handleStep) : handleStep(iteratorResult);
390
+ }
391
+ const result = iterate(it.next());
392
+ return isPromise(result) ? AsyncResult.fromPromise(result) : result;
393
+ }
394
+ static gen(generatorOrSelfOrFn, fn) {
395
+ const it = isGenerator(generatorOrSelfOrFn) || isAsyncGenerator(generatorOrSelfOrFn) ? generatorOrSelfOrFn : typeof generatorOrSelfOrFn === "function" ? generatorOrSelfOrFn() : fn?.apply(generatorOrSelfOrFn);
396
+ return _ResultFactory.handleGenerator(it);
397
+ }
398
+ static genCatching(generatorOrSelfOrFn, transformValueOrError, transformError) {
399
+ const isGen = isGenerator(generatorOrSelfOrFn) || isAsyncGenerator(generatorOrSelfOrFn);
400
+ const self = typeof generatorOrSelfOrFn === "function" || isGen ? void 0 : generatorOrSelfOrFn;
401
+ const tValue = typeof generatorOrSelfOrFn === "function" ? generatorOrSelfOrFn : transformValueOrError;
402
+ const tError = typeof generatorOrSelfOrFn === "function" || isGen ? transformValueOrError : transformError;
403
+ try {
404
+ const it = isGen ? generatorOrSelfOrFn : self ? tValue.apply(generatorOrSelfOrFn) : tValue();
405
+ const result = _ResultFactory.handleGenerator(it);
406
+ if (_ResultFactory.isAsyncResult(result)) return result.catch((error) => AsyncResult.error(tError?.(error) ?? error));
407
+ return result;
408
+ } catch (error) {
409
+ return _ResultFactory.error(tError?.(error) ?? error);
410
+ }
411
+ }
412
+ static assertOk(result) {
413
+ if (!result.ok) throw new Error("Expected a successful result, but got an error instead");
414
+ }
415
+ static assertError(result) {
416
+ if (result.ok) throw new Error("Expected a failed result, but got a value instead");
417
+ }
418
+ static [Symbol.hasInstance](instance) {
419
+ return instance instanceof Result;
420
+ }
421
+ };
422
+ var Result2 = ResultFactory;
423
+
424
+ //#endregion
425
+ //#region ../api/dist/api-client.js
426
+ var InvalidYamlError = class extends Error {
427
+ type = "invalid-yaml-error";
428
+ issues = [];
429
+ constructor(message, issues) {
430
+ super(message);
431
+ this.issues = issues || [];
432
+ }
433
+ };
434
+ var ApiError = class extends Error {
435
+ type = "api-error";
436
+ response;
437
+ constructor(message, response) {
438
+ super(message);
439
+ this.response = response;
440
+ }
441
+ };
442
+ var BaseClient = class {
443
+ baseUrl;
444
+ apiKey;
445
+ constructor(baseUrl, apiKey) {
446
+ this.baseUrl = baseUrl;
447
+ this.apiKey = apiKey;
448
+ }
449
+ /**
450
+ * Generic method to make HTTP requests with common headers and error handling
451
+ */
452
+ async makeRequest(endpoint, options = {}) {
453
+ const { method = "GET", headers = {}, body, throwOnError = true } = options;
454
+ const fetchOptions = {
455
+ method,
456
+ headers: {
457
+ "Content-Type": "application/json",
458
+ ...headers,
459
+ "Authorization": `Bearer ${this.apiKey}`
460
+ },
461
+ credentials: "include"
462
+ };
463
+ if (body !== void 0) if (typeof body === "string") fetchOptions.body = body;
464
+ else if (headers["Content-Type"]?.includes("yaml")) fetchOptions.body = body;
465
+ else fetchOptions.body = JSON.stringify(body);
466
+ const baseUrl = this.baseUrl.endsWith("/") ? this.baseUrl : `${this.baseUrl}/`;
467
+ const requestUrl = new URL(endpoint, baseUrl);
468
+ const response = await fetch(requestUrl.toString(), fetchOptions);
469
+ const data = await response.json();
470
+ if (!response.ok && throwOnError) {
471
+ const errorData = data;
472
+ throw new ApiError(errorData.error ?? "Request failed", errorData);
473
+ }
474
+ return data;
475
+ }
476
+ /**
477
+ * HTTP method helpers
478
+ */
479
+ async get(endpoint, options) {
480
+ return this.makeRequest(endpoint, {
481
+ ...options,
482
+ method: "GET"
483
+ });
484
+ }
485
+ async post(endpoint, body, options) {
486
+ return this.makeRequest(endpoint, {
487
+ ...options,
488
+ method: "POST",
489
+ body
490
+ });
491
+ }
492
+ async patch(endpoint, body, options) {
493
+ return this.makeRequest(endpoint, {
494
+ ...options,
495
+ method: "PATCH",
496
+ body
497
+ });
498
+ }
499
+ async delete(endpoint, options) {
500
+ return this.makeRequest(endpoint, {
501
+ ...options,
502
+ method: "DELETE"
503
+ });
504
+ }
505
+ async put(endpoint, body, options) {
506
+ return this.makeRequest(endpoint, {
507
+ ...options,
508
+ method: "PUT",
509
+ body
510
+ });
511
+ }
512
+ /**
513
+ * Generic Result helper for consistent error handling
514
+ */
515
+ async withResult(operation) {
516
+ try {
517
+ const result = await operation();
518
+ return Result2.ok(result);
519
+ } catch (error) {
520
+ if (error instanceof ApiError) return Result2.error(error);
521
+ console.error("Unexpected error:", error);
522
+ return Result2.error(new ApiError("Internal server error", { error: "Internal server error" }));
523
+ }
524
+ }
525
+ /**
526
+ * Generic method to make HTTP requests without authentication
527
+ */
528
+ async makeUnauthenticatedRequest(endpoint, options = {}) {
529
+ const { method = "GET", headers = {}, body } = options;
530
+ const fetchOptions = {
531
+ method,
532
+ headers
533
+ };
534
+ if (body) fetchOptions.body = body;
535
+ return await fetch(`${this.baseUrl}${endpoint}`, fetchOptions);
536
+ }
537
+ };
538
+ var BaseResource = class {
539
+ constructor(client) {
540
+ this.client = client;
541
+ }
542
+ };
543
+ /**
544
+ * Unified Route Configuration
545
+ *
546
+ * This file provides a single source of truth for all API routes.
547
+ * It works in two modes:
548
+ *
549
+ * 1. **Pattern Mode** (for API handlers): Returns route patterns like "/:applicationId/usage"
550
+ * 2. **Builder Mode** (for API client): Returns builder functions that create full URLs
551
+ *
552
+ * Both modes share the same structure and definitions, preventing inconsistencies.
553
+ * Route builders are auto-generated from route definitions - no manual duplication needed.
554
+ */
555
+ const MOUNT_POINTS = {
556
+ application: "/api/application",
557
+ applications: "/api/applications",
558
+ project: "/api/project",
559
+ projects: "/api/projects",
560
+ org: "/api/org",
561
+ admin: "/api/admin",
562
+ apiKeys: "/api/api-keys",
563
+ auth: "/api/auth",
564
+ config: "/config",
565
+ webSettings: "/web-settings",
566
+ deployments: "/api/deployments"
567
+ };
568
+ /**
569
+ * Define routes with their patterns and mount points
570
+ * Each route has:
571
+ * - pattern: The Hono route pattern (e.g., "/:applicationId/usage")
572
+ * - mount: The mount point key (e.g., "application")
573
+ */
574
+ const routeDefinitions = {
575
+ applications: {
576
+ list: {
577
+ pattern: "/",
578
+ mount: "applications"
579
+ },
580
+ create: {
581
+ pattern: "/",
582
+ mount: "applications"
583
+ },
584
+ get: {
585
+ pattern: "/:applicationId",
586
+ mount: "application"
587
+ },
588
+ update: {
589
+ pattern: "/:applicationId",
590
+ mount: "application"
591
+ },
592
+ hasDeployments: {
593
+ pattern: "/has-deployments",
594
+ mount: "application"
595
+ },
596
+ deployments: {
597
+ create: {
598
+ pattern: "/:applicationId/deployments",
599
+ mount: "application"
600
+ },
601
+ latest: {
602
+ pattern: "/:applicationId/deployment/latest",
603
+ mount: "application"
604
+ },
605
+ byId: {
606
+ pattern: "/:applicationId/deployment/:deploymentId",
607
+ mount: "application"
608
+ },
609
+ stop: {
610
+ pattern: "/:applicationId/deployment/stop",
611
+ mount: "application"
612
+ },
613
+ usage: {
614
+ pattern: "/:applicationId/deployment/:deploymentId/usage",
615
+ mount: "application"
616
+ }
617
+ },
618
+ usage: {
619
+ get: {
620
+ pattern: "/:applicationId/usage",
621
+ mount: "application"
622
+ },
623
+ range: {
624
+ pattern: "/:applicationId/usage/range",
625
+ mount: "application"
626
+ },
627
+ execution: {
628
+ pattern: "/:applicationId/execution-usage",
629
+ mount: "application"
630
+ },
631
+ executionUnitsCurrentMonth: {
632
+ pattern: "/:applicationId/execution-units/current-month",
633
+ mount: "application"
634
+ }
635
+ },
636
+ runs: {
637
+ list: {
638
+ pattern: "/:applicationId/runs",
639
+ mount: "application"
640
+ },
641
+ breakdown: {
642
+ pattern: "/:applicationId/runs/breakdown",
643
+ mount: "application"
644
+ },
645
+ durationHistogram: {
646
+ pattern: "/:applicationId/runs/duration-histogram",
647
+ mount: "application"
648
+ }
649
+ },
650
+ secrets: {
651
+ list: {
652
+ pattern: "/:applicationId/secrets",
653
+ mount: "application"
654
+ },
655
+ upsert: {
656
+ pattern: "/:applicationId/secrets",
657
+ mount: "application"
658
+ },
659
+ delete: {
660
+ pattern: "/:applicationId/secrets/:secretName",
661
+ mount: "application"
662
+ }
663
+ },
664
+ logs: { get: {
665
+ pattern: "/:applicationId/logs",
666
+ mount: "application"
667
+ } }
668
+ },
669
+ projects: {
670
+ list: {
671
+ pattern: "/",
672
+ mount: "projects"
673
+ },
674
+ create: {
675
+ pattern: "/",
676
+ mount: "projects"
677
+ },
678
+ get: {
679
+ pattern: "/:projectId/applications",
680
+ mount: "project"
681
+ },
682
+ update: {
683
+ pattern: "/:projectId",
684
+ mount: "project"
685
+ },
686
+ executionUnitsCurrentMonth: {
687
+ pattern: "/:projectId/execution-units/current-month",
688
+ mount: "project"
689
+ }
690
+ },
691
+ organizations: {
692
+ get: {
693
+ pattern: "/",
694
+ mount: "org"
695
+ },
696
+ applications: {
697
+ pattern: "/applications",
698
+ mount: "org"
699
+ },
700
+ update: {
701
+ pattern: "/:organizationId",
702
+ mount: "org"
703
+ },
704
+ executionUnitsCurrentMonth: {
705
+ pattern: "/execution-units/current-month",
706
+ mount: "org"
707
+ }
708
+ },
709
+ apiKeys: {
710
+ list: {
711
+ pattern: "/",
712
+ mount: "apiKeys"
713
+ },
714
+ create: {
715
+ pattern: "/",
716
+ mount: "apiKeys"
717
+ },
718
+ update: {
719
+ pattern: "/:apiKeyId",
720
+ mount: "apiKeys"
721
+ },
722
+ delete: {
723
+ pattern: "/:apiKeyId",
724
+ mount: "apiKeys"
725
+ }
726
+ },
727
+ auth: { test: {
728
+ pattern: "/test",
729
+ mount: "auth"
730
+ } },
731
+ deployments: {
732
+ get: {
733
+ pattern: "/:deploymentId",
734
+ mount: "deployments"
735
+ },
736
+ runs: {
737
+ pattern: "/:deploymentId/runs",
738
+ mount: "deployments"
739
+ }
740
+ },
741
+ admin: {
742
+ users: { create: {
743
+ pattern: "/users",
744
+ mount: "admin"
745
+ } },
746
+ organizations: {
747
+ list: {
748
+ pattern: "/organizations",
749
+ mount: "admin"
750
+ },
751
+ create: {
752
+ pattern: "/organizations",
753
+ mount: "admin"
754
+ },
755
+ get: {
756
+ pattern: "/organizations/:organizationId",
757
+ mount: "admin"
758
+ }
759
+ },
760
+ config: { pumpImageTag: {
761
+ pattern: "/config/pump-image-tag",
762
+ mount: "admin"
763
+ } }
764
+ },
765
+ config: {
766
+ validateYaml: {
767
+ pattern: "/validate-yaml",
768
+ mount: "config"
769
+ },
770
+ setGlobalKey: {
771
+ pattern: "/:key",
772
+ mount: "config"
773
+ }
774
+ },
775
+ webSettings: { get: {
776
+ pattern: "/",
777
+ mount: "webSettings"
778
+ } }
779
+ };
780
+ function extractPatterns(obj) {
781
+ if (obj.pattern !== void 0) return obj.pattern;
782
+ const result = {};
783
+ for (const [key, value] of Object.entries(obj)) result[key] = extractPatterns(value);
784
+ return result;
785
+ }
786
+ Object.entries(routeDefinitions).reduce((acc, [key, value]) => {
787
+ acc[key] = extractPatterns(value);
788
+ return acc;
789
+ }, {});
790
+ /**
791
+ * Build URL from pattern and mount point, substituting parameters in order
792
+ */
793
+ function buildUrl(pattern, mount, ...params) {
794
+ let url = pattern === "/" ? mount : mount + pattern;
795
+ for (const param of params) url = url.replace(/:[^/]+/, param);
796
+ return url;
797
+ }
798
+ /**
799
+ * Recursively create route builders from route definitions
800
+ */
801
+ function createRouteBuilders(definitions, mountPoints) {
802
+ const result = {};
803
+ for (const [key, value] of Object.entries(definitions)) if (value && typeof value === "object" && "pattern" in value && "mount" in value) {
804
+ const { pattern, mount } = value;
805
+ result[key] = (...params) => buildUrl(pattern, mountPoints[mount], ...params);
806
+ } else if (value && typeof value === "object") result[key] = createRouteBuilders(value, mountPoints);
807
+ return result;
808
+ }
809
+ /**
810
+ * Route builders for API client (client-side)
811
+ * Auto-generated from routeDefinitions - parameter count is inferred from pattern
812
+ *
813
+ * Usage: this.client.get(routes.applications.usage.get(applicationId))
814
+ */
815
+ const routes = createRouteBuilders(routeDefinitions, MOUNT_POINTS);
816
+ var ApplicationSecretsResource = class extends BaseResource {
817
+ /**
818
+ * Get all secrets for an application
819
+ */
820
+ async list(applicationId) {
821
+ return this.client["withResult"](() => this.client["get"](routes.applications.secrets.list(applicationId)).then((res) => res.data));
822
+ }
823
+ /**
824
+ * Create or update a secret for an application
825
+ */
826
+ async upsert(applicationId, secretData) {
827
+ return this.client["withResult"](() => this.client["post"](routes.applications.secrets.upsert(applicationId), secretData).then((res) => res.data));
828
+ }
829
+ /**
830
+ * Delete a secret for an application
831
+ */
832
+ async delete(applicationId, secretName) {
833
+ return this.client["withResult"](() => this.client["delete"](routes.applications.secrets.delete(applicationId, secretName)).then((res) => res.data));
834
+ }
835
+ };
836
+ var ApplicationLogsResource = class extends BaseResource {
837
+ /**
838
+ * Get logs for an application
839
+ */
840
+ async get(applicationId, options) {
841
+ const params = new URLSearchParams();
842
+ if (options?.limit !== void 0) params.append("limit", options.limit.toString());
843
+ if (options?.offset !== void 0) params.append("offset", options.offset.toString());
844
+ if (options?.timestamp) params.append("timestamp", options.timestamp);
845
+ if (options?.level) params.append("level", options.level);
846
+ if (options?.deploymentId) params.append("deploymentId", options.deploymentId);
847
+ if (options?.runId) params.append("runId", options.runId);
848
+ const queryString = params.toString();
849
+ const endpoint = `${routes.applications.logs.get(applicationId)}${queryString ? `?${queryString}` : ""}`;
850
+ return this.client["withResult"](() => this.client["get"](endpoint).then((res) => res.data));
851
+ }
852
+ };
853
+ var ApplicationUsageResource = class extends BaseResource {
854
+ /**
855
+ * Get application usage summary
856
+ */
857
+ async get(applicationId) {
858
+ return this.client["withResult"](async () => {
859
+ return (await this.client["get"](routes.applications.usage.get(applicationId))).data;
860
+ });
861
+ }
862
+ /**
863
+ * Get billing usage by time range
864
+ */
865
+ async getByTimeRange(applicationId, startDate, endDate, customRange = null) {
866
+ return this.client["withResult"](async () => {
867
+ const baseUrl = this.client["baseUrl"];
868
+ const url = new URL(routes.applications.usage.range(applicationId), baseUrl);
869
+ if (startDate) url.searchParams.append("startDate", startDate);
870
+ if (endDate) url.searchParams.append("endDate", endDate);
871
+ if (customRange) url.searchParams.append("customRange", customRange);
872
+ return (await this.client["get"](url.pathname + url.search)).data;
873
+ });
874
+ }
875
+ /**
876
+ * Get execution usage by application id
877
+ */
878
+ async getExecutionUsage(applicationId) {
879
+ return this.client["withResult"](async () => {
880
+ return (await this.client["get"](routes.applications.usage.execution(applicationId))).data;
881
+ });
882
+ }
883
+ /**
884
+ * Get execution units for an application for the current month
885
+ */
886
+ async getExecutionUnitsCurrentMonth(applicationId) {
887
+ return this.client["withResult"](async () => {
888
+ return (await this.client["get"](routes.applications.usage.executionUnitsCurrentMonth(applicationId))).data;
889
+ });
890
+ }
891
+ };
892
+ var ApplicationRunsResource = class extends BaseResource {
893
+ /**
894
+ * Get application runs
895
+ */
896
+ async list(applicationId, options) {
897
+ const params = new URLSearchParams();
898
+ if (options?.limit !== void 0) params.append("limit", options.limit.toString());
899
+ if (options?.offset !== void 0) params.append("offset", options.offset.toString());
900
+ const queryString = params.toString();
901
+ const endpoint = `${routes.applications.runs.list(applicationId)}${queryString ? `?${queryString}` : ""}`;
902
+ return this.client["withResult"](() => this.client["get"](endpoint).then((res) => res.data));
903
+ }
904
+ /**
905
+ * Get application runs breakdown (success vs failure)
906
+ */
907
+ async getBreakdown(applicationId) {
908
+ return this.client["withResult"](() => this.client["get"](routes.applications.runs.breakdown(applicationId)).then((res) => res.data));
909
+ }
910
+ /**
911
+ * Get application run duration histogram
912
+ */
913
+ async getDurationHistogram(applicationId, period = "current-month") {
914
+ const params = new URLSearchParams();
915
+ params.append("period", period);
916
+ const queryString = params.toString();
917
+ const endpoint = `${routes.applications.runs.durationHistogram(applicationId)}?${queryString}`;
918
+ return this.client["withResult"](() => this.client["get"](endpoint).then((res) => res.data));
919
+ }
920
+ };
921
+ var ApplicationsResource = class extends BaseResource {
922
+ secrets;
923
+ logs;
924
+ usage;
925
+ runs;
926
+ constructor(client) {
927
+ super(client);
928
+ this.secrets = new ApplicationSecretsResource(client);
929
+ this.logs = new ApplicationLogsResource(client);
930
+ this.usage = new ApplicationUsageResource(client);
931
+ this.runs = new ApplicationRunsResource(client);
932
+ }
933
+ /**
934
+ * Get all applications in the organization
935
+ */
936
+ async list() {
937
+ return this.client["withResult"](() => this.client["get"](routes.applications.list()).then((res) => ({ applications: res.data })));
938
+ }
939
+ /**
940
+ * Get application details
941
+ */
942
+ async get(applicationId) {
943
+ return this.client["withResult"](() => this.client["get"](routes.applications.get(applicationId)));
944
+ }
945
+ /**
946
+ * Create a new application
947
+ */
948
+ async create(data) {
949
+ return this.client["withResult"](() => this.client["post"](routes.applications.create(), data));
950
+ }
951
+ /**
952
+ * Update application details
953
+ */
954
+ async update(applicationId, data) {
955
+ return this.client["withResult"](() => this.client["patch"](routes.applications.update(applicationId), data));
956
+ }
957
+ /**
958
+ * Check if any deployment exists in the organization
959
+ */
960
+ async hasDeployments() {
961
+ return this.client["withResult"](() => this.client["get"](routes.applications.hasDeployments()));
962
+ }
963
+ };
964
+ var ProjectsResource = class extends BaseResource {
965
+ /**
966
+ * Get all projects in the organization
967
+ */
968
+ async list() {
969
+ return this.client["withResult"](() => this.client["get"](routes.projects.list()));
970
+ }
971
+ /**
972
+ * Get project details with applications
973
+ */
974
+ async get(projectId) {
975
+ return this.client["withResult"](() => this.client["get"](routes.projects.get(projectId)));
976
+ }
977
+ /**
978
+ * Create a new project
979
+ */
980
+ async create(data) {
981
+ return this.client["withResult"](() => this.client["post"](routes.projects.create(), data));
982
+ }
983
+ /**
984
+ * Update project details
985
+ */
986
+ async update(projectId, data) {
987
+ return this.client["withResult"](() => this.client["patch"](routes.projects.update(projectId), data));
988
+ }
989
+ /**
990
+ * Get execution units for a project for the current month
991
+ */
992
+ async getExecutionUnitsCurrentMonth(projectId) {
993
+ return this.client["withResult"](async () => {
994
+ return (await this.client["get"](routes.projects.executionUnitsCurrentMonth(projectId))).data;
995
+ });
996
+ }
997
+ };
998
+ var OrganizationsResource = class extends BaseResource {
999
+ /**
1000
+ * Get current organization
1001
+ */
1002
+ async get() {
1003
+ return this.client["withResult"](() => this.client["get"](routes.organizations.get()));
1004
+ }
1005
+ /**
1006
+ * Update organization details
1007
+ */
1008
+ async update(organizationId, data) {
1009
+ return this.client["withResult"](() => this.client["patch"](routes.organizations.update(organizationId), data));
1010
+ }
1011
+ /**
1012
+ * Get execution units for the organization for the current month
1013
+ */
1014
+ async getExecutionUnitsCurrentMonth() {
1015
+ return this.client["withResult"](async () => {
1016
+ return (await this.client["get"](routes.organizations.executionUnitsCurrentMonth())).data;
1017
+ });
1018
+ }
1019
+ };
1020
+ var AdminOrganizationsResource = class extends BaseResource {
1021
+ /**
1022
+ * Create a new organization (admin only)
1023
+ */
1024
+ async create(organizationData) {
1025
+ return this.client["withResult"](() => this.client["post"](routes.admin.organizations.create(), organizationData).then((response) => response.data.organization));
1026
+ }
1027
+ /**
1028
+ * Get organization details by ID (admin only)
1029
+ */
1030
+ async get(organizationId) {
1031
+ return this.client["withResult"](async () => {
1032
+ return (await this.client["get"](routes.admin.organizations.get(organizationId))).data;
1033
+ });
1034
+ }
1035
+ /**
1036
+ * List all organizations (admin only)
1037
+ */
1038
+ async list() {
1039
+ return this.client["withResult"](async () => {
1040
+ return (await this.client["get"](routes.admin.organizations.list())).data;
1041
+ });
1042
+ }
1043
+ };
1044
+ var DeploymentsResource = class extends BaseResource {
1045
+ /**
1046
+ * Create a new deployment
1047
+ */
1048
+ async create({ applicationId, configYaml }) {
1049
+ const requestBody = {
1050
+ applicationId,
1051
+ config: configYaml,
1052
+ name: `deployment-${Date.now()}`,
1053
+ force: false
1054
+ };
1055
+ return this.client["withResult"](() => this.client["post"](routes.applications.deployments.create(applicationId), requestBody));
1056
+ }
1057
+ /**
1058
+ * Get latest deployment for application
1059
+ * Returns { data: Deployment | null } where null indicates no deployment exists
1060
+ */
1061
+ async getLatest(applicationId) {
1062
+ return this.client["withResult"](() => this.client["get"](routes.applications.deployments.latest(applicationId)));
1063
+ }
1064
+ /**
1065
+ * Get a deployment by ID
1066
+ */
1067
+ async get(deploymentId) {
1068
+ return this.client["withResult"](() => this.client["get"](routes.deployments.get(deploymentId)));
1069
+ }
1070
+ /**
1071
+ * Stop running deployment for application
1072
+ */
1073
+ async stop(applicationId) {
1074
+ return this.client["withResult"](() => this.client["post"](routes.applications.deployments.stop(applicationId)));
1075
+ }
1076
+ async getRuns(deploymentId, limit) {
1077
+ const queryString = limit ? `?limit=${limit}` : "";
1078
+ const endpoint = `${routes.deployments.runs(deploymentId)}${queryString}`;
1079
+ return this.client["withResult"](() => this.client["get"](endpoint));
1080
+ }
1081
+ };
1082
+ var ApiKeysResource = class extends BaseResource {
1083
+ /**
1084
+ * Get all API keys for the organization
1085
+ */
1086
+ async list() {
1087
+ return this.client["withResult"](() => this.client["get"](routes.apiKeys.list()));
1088
+ }
1089
+ /**
1090
+ * Create a new API key
1091
+ */
1092
+ async create(data) {
1093
+ return this.client["withResult"](() => this.client["post"](routes.apiKeys.create(), data));
1094
+ }
1095
+ /**
1096
+ * Update an API key
1097
+ */
1098
+ async update(apiKeyId, data) {
1099
+ return this.client["withResult"](() => this.client["patch"](routes.apiKeys.update(apiKeyId), data));
1100
+ }
1101
+ /**
1102
+ * Delete an API key
1103
+ */
1104
+ async delete(apiKeyId) {
1105
+ return this.client["withResult"](() => this.client["delete"](routes.apiKeys.delete(apiKeyId)));
1106
+ }
1107
+ };
1108
+ var AdminUsersResource = class extends BaseResource {
1109
+ /**
1110
+ * Create a new user (admin only)
1111
+ */
1112
+ async create(userData) {
1113
+ return this.client["withResult"](() => this.client["post"](routes.admin.users.create(), userData).then((response) => response.data.user));
1114
+ }
1115
+ };
1116
+ var AdminResource = class extends BaseResource {
1117
+ users;
1118
+ organizations;
1119
+ constructor(client) {
1120
+ super(client);
1121
+ this.users = new AdminUsersResource(client);
1122
+ this.organizations = new AdminOrganizationsResource(client);
1123
+ }
1124
+ };
1125
+ const postMessageKeyMapping = {
1126
+ helmRepoUrl: "HELM_REPO_URL",
1127
+ helmRepoUsername: "HELM_REPO_USERNAME",
1128
+ helmRepoPassword: "HELM_REPO_PASSWORD",
1129
+ s3Endpoint: "S3_ENDPOINT",
1130
+ s3BucketName: "S3_BUCKET_NAME",
1131
+ s3AccessKeyId: "S3_ACCESS_KEY_ID",
1132
+ s3SecretAccessKey: "S3_SECRET_ACCESS_KEY",
1133
+ s3Region: "S3_REGION",
1134
+ pumpImageTag: "PUMP_IMAGE_TAG"
1135
+ };
1136
+ var ConfigResource = class extends BaseResource {
1137
+ /**
1138
+ * Validate config YAML
1139
+ */
1140
+ async validateYaml(configYaml) {
1141
+ const responseJson = await (await this.client["makeUnauthenticatedRequest"](routes.config.validateYaml(), {
1142
+ method: "POST",
1143
+ headers: { "Content-Type": "application/x-yaml" },
1144
+ body: configYaml
1145
+ })).json();
1146
+ if (responseJson.valid) return Result2.ok(responseJson);
1147
+ else return Result2.error(new InvalidYamlError("YAML validation failed", responseJson.errors));
1148
+ }
1149
+ /**
1150
+ * Get web settings
1151
+ */
1152
+ async getWebSettings() {
1153
+ const response = await this.client["makeUnauthenticatedRequest"](routes.webSettings.get(), { method: "GET" });
1154
+ if (!response.ok) {
1155
+ const errorData = await response.json();
1156
+ return Result2.error(new ApiError(errorData.error, { error: errorData.error }));
1157
+ }
1158
+ const data = await response.json();
1159
+ return Result2.ok(data);
1160
+ }
1161
+ /**
1162
+ * Set a global config key
1163
+ */
1164
+ async setGlobalKey(key, value) {
1165
+ if (!(key in postMessageKeyMapping)) return Result2.error(new ApiError(`Invalid key: ${key}`, { error: `Invalid key: ${key}. Must be one of: ${Object.keys(postMessageKeyMapping).join(", ")}` }));
1166
+ if (key === "pumpImageTag") return this.client["withResult"](() => this.client["post"](routes.admin.config.pumpImageTag(), { pumpImageTag: value }));
1167
+ const mappedKey = postMessageKeyMapping[key];
1168
+ return this.client["withResult"](() => this.client["post"](routes.config.setGlobalKey(mappedKey), { value }));
1169
+ }
1170
+ };
1171
+ var AuthResource = class extends BaseResource {
1172
+ /**
1173
+ * Test authentication
1174
+ */
1175
+ async test() {
1176
+ return this.client["withResult"](() => this.client["get"](routes.auth.test()));
1177
+ }
1178
+ };
1179
+ var ApiClient = class extends BaseClient {
1180
+ applications;
1181
+ projects;
1182
+ organizations;
1183
+ deployments;
1184
+ apiKeys;
1185
+ admin;
1186
+ config;
1187
+ auth;
1188
+ constructor(baseUrl, apiKey) {
1189
+ super(baseUrl, apiKey);
1190
+ this.applications = new ApplicationsResource(this);
1191
+ this.projects = new ProjectsResource(this);
1192
+ this.organizations = new OrganizationsResource(this);
1193
+ this.deployments = new DeploymentsResource(this);
1194
+ this.apiKeys = new ApiKeysResource(this);
1195
+ this.admin = new AdminResource(this);
1196
+ this.config = new ConfigResource(this);
1197
+ this.auth = new AuthResource(this);
1198
+ }
1199
+ };
1200
+
1201
+ //#endregion
1202
+ Object.defineProperty(exports, 'ApiClient', {
1203
+ enumerable: true,
1204
+ get: function () {
1205
+ return ApiClient;
1206
+ }
1207
+ });