maritime-cli 0.2.0 → 0.2.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.
package/dist/api.d.ts CHANGED
@@ -21,4 +21,5 @@ export declare function authGet<T>(path: string): Promise<T>;
21
21
  export declare function authPost<T>(path: string, body?: JsonRecord): Promise<T>;
22
22
  export declare function authPut<T>(path: string, body?: JsonRecord): Promise<T>;
23
23
  export declare function authDelete<T = JsonRecord>(path: string): Promise<T>;
24
+ export declare function publicGet<T>(path: string): Promise<T>;
24
25
  export {};
package/dist/api.js CHANGED
@@ -9,6 +9,9 @@ export class CliHttpError extends Error {
9
9
  this.detail = detail;
10
10
  }
11
11
  }
12
+ function isErrorWithMessage(error) {
13
+ return typeof error === 'object' && error !== null && 'message' in error;
14
+ }
12
15
  export function getApiUrl() {
13
16
  const stored = config.get('apiUrl');
14
17
  return (stored ||
@@ -46,13 +49,24 @@ async function handleResponse(response) {
46
49
  }
47
50
  return payload;
48
51
  }
52
+ async function requestJson(path, init) {
53
+ const url = `${getApiUrl()}${path}`;
54
+ let response;
55
+ try {
56
+ response = await fetch(url, init);
57
+ }
58
+ catch (error) {
59
+ const detail = isErrorWithMessage(error) ? error.message : 'Unknown network error';
60
+ throw new CliHttpError(0, `Unable to reach Maritime API at ${getApiUrl()}: ${detail}`);
61
+ }
62
+ return handleResponse(response);
63
+ }
49
64
  export async function postJson(path, body) {
50
- const response = await fetch(`${getApiUrl()}${path}`, {
65
+ return requestJson(path, {
51
66
  method: 'POST',
52
67
  headers: { 'Content-Type': 'application/json' },
53
68
  body: JSON.stringify(body),
54
69
  });
55
- return handleResponse(response);
56
70
  }
57
71
  function authHeaders(token) {
58
72
  return {
@@ -62,35 +76,37 @@ function authHeaders(token) {
62
76
  }
63
77
  export async function authGet(path) {
64
78
  const token = requireAuth();
65
- const response = await fetch(`${getApiUrl()}${path}`, {
79
+ return requestJson(path, {
66
80
  method: 'GET',
67
81
  headers: authHeaders(token),
68
82
  });
69
- return handleResponse(response);
70
83
  }
71
84
  export async function authPost(path, body = {}) {
72
85
  const token = requireAuth();
73
- const response = await fetch(`${getApiUrl()}${path}`, {
86
+ return requestJson(path, {
74
87
  method: 'POST',
75
88
  headers: authHeaders(token),
76
89
  body: JSON.stringify(body),
77
90
  });
78
- return handleResponse(response);
79
91
  }
80
92
  export async function authPut(path, body = {}) {
81
93
  const token = requireAuth();
82
- const response = await fetch(`${getApiUrl()}${path}`, {
94
+ return requestJson(path, {
83
95
  method: 'PUT',
84
96
  headers: authHeaders(token),
85
97
  body: JSON.stringify(body),
86
98
  });
87
- return handleResponse(response);
88
99
  }
89
100
  export async function authDelete(path) {
90
101
  const token = requireAuth();
91
- const response = await fetch(`${getApiUrl()}${path}`, {
102
+ return requestJson(path, {
92
103
  method: 'DELETE',
93
104
  headers: authHeaders(token),
94
105
  });
95
- return handleResponse(response);
106
+ }
107
+ export async function publicGet(path) {
108
+ return requestJson(path, {
109
+ method: 'GET',
110
+ headers: { 'Content-Type': 'application/json' },
111
+ });
96
112
  }
@@ -1,26 +1,11 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
- import { CliHttpError, getApiUrl } from '../api.js';
3
+ import { CliHttpError, publicGet } from '../api.js';
4
4
  export const templatesCommand = new Command('templates')
5
5
  .description('List available agent templates')
6
6
  .action(async () => {
7
7
  try {
8
- const response = await fetch(`${getApiUrl()}/api/templates`, {
9
- method: 'GET',
10
- headers: { 'Content-Type': 'application/json' },
11
- });
12
- if (!response.ok) {
13
- const text = await response.text();
14
- let detail = `Request failed with status ${response.status}`;
15
- try {
16
- const json = JSON.parse(text);
17
- if (typeof json.detail === 'string')
18
- detail = json.detail;
19
- }
20
- catch { /* ignore */ }
21
- throw new CliHttpError(response.status, detail);
22
- }
23
- const templates = await response.json();
8
+ const templates = await publicGet('/api/templates');
24
9
  if (templates.length === 0) {
25
10
  console.log(chalk.dim('No templates available.'));
26
11
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maritime-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Maritime CLI - Deploy AI agents from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",