maritime-cli 0.1.0 → 0.1.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 ADDED
@@ -0,0 +1,19 @@
1
+ type JsonRecord = Record<string, unknown>;
2
+ export declare class CliHttpError extends Error {
3
+ status: number;
4
+ detail: string;
5
+ constructor(status: number, detail: string);
6
+ }
7
+ export interface CliUser {
8
+ id: string;
9
+ email: string;
10
+ name?: string | null;
11
+ image?: string | null;
12
+ }
13
+ export interface CliAuthResponse {
14
+ token: string;
15
+ user: CliUser;
16
+ }
17
+ export declare function getApiUrl(): string;
18
+ export declare function postJson<T>(path: string, body: JsonRecord): Promise<T>;
19
+ export {};
package/dist/api.js ADDED
@@ -0,0 +1,39 @@
1
+ export class CliHttpError extends Error {
2
+ status;
3
+ detail;
4
+ constructor(status, detail) {
5
+ super(detail);
6
+ this.status = status;
7
+ this.detail = detail;
8
+ }
9
+ }
10
+ export function getApiUrl() {
11
+ return (process.env.MARITIME_API_URL ||
12
+ process.env.NEXT_PUBLIC_API_URL ||
13
+ 'https://api.maritime.sh').replace(/\/+$/, '');
14
+ }
15
+ async function parseJson(response) {
16
+ const text = await response.text();
17
+ if (!text) {
18
+ return {};
19
+ }
20
+ try {
21
+ return JSON.parse(text);
22
+ }
23
+ catch {
24
+ throw new CliHttpError(response.status, `Invalid JSON response from ${response.url}`);
25
+ }
26
+ }
27
+ export async function postJson(path, body) {
28
+ const response = await fetch(`${getApiUrl()}${path}`, {
29
+ method: 'POST',
30
+ headers: { 'Content-Type': 'application/json' },
31
+ body: JSON.stringify(body),
32
+ });
33
+ const payload = await parseJson(response);
34
+ if (!response.ok) {
35
+ const detail = typeof payload.detail === 'string' ? payload.detail : `Request failed with status ${response.status}`;
36
+ throw new CliHttpError(response.status, detail);
37
+ }
38
+ return payload;
39
+ }
@@ -1,20 +1,39 @@
1
1
  import { Command } from 'commander';
2
2
  import chalk from 'chalk';
3
3
  import ora from 'ora';
4
- import Conf from 'conf';
5
- const config = new Conf({ projectName: 'maritime' });
4
+ import { config } from '../config.js';
5
+ import { CliHttpError, postJson } from '../api.js';
6
+ import { promptForPassword, promptForValue } from '../prompt.js';
6
7
  export const loginCommand = new Command('login')
7
- .description('Authenticate with Maritime via GitHub')
8
- .action(async () => {
9
- const spinner = ora('Opening browser for authentication...').start();
10
- // In production, this would open a browser for OAuth
11
- await new Promise((resolve) => setTimeout(resolve, 1500));
12
- spinner.succeed('Browser opened');
13
- const waitSpinner = ora('Waiting for authentication...').start();
14
- await new Promise((resolve) => setTimeout(resolve, 2000));
15
- // Simulate successful auth
16
- config.set('token', 'maritime_demo_token');
17
- config.set('user', 'developer@example.com');
18
- waitSpinner.succeed(chalk.green('Authenticated as ') + chalk.bold('developer@example.com'));
19
- console.log(chalk.dim('\nToken saved. You can now deploy agents.'));
8
+ .description('Authenticate with Maritime using email and password')
9
+ .option('-e, --email <email>', 'Email address')
10
+ .option('-p, --password <password>', 'Password')
11
+ .action(async (opts) => {
12
+ const email = await promptForValue('Email', opts.email);
13
+ const password = await promptForPassword(opts.password);
14
+ if (!email || !password) {
15
+ console.log(chalk.red('Error:') + ' email and password are required');
16
+ process.exit(1);
17
+ }
18
+ const spinner = ora('Authenticating...').start();
19
+ try {
20
+ const auth = await postJson('/api/auth/cli-login', {
21
+ email,
22
+ password,
23
+ });
24
+ config.set('token', auth.token);
25
+ config.set('user', auth.user.email);
26
+ config.set('userId', auth.user.id);
27
+ config.set('apiUrl', process.env.MARITIME_API_URL || 'https://api.maritime.sh');
28
+ spinner.succeed(chalk.green('Authenticated as ') + chalk.bold(auth.user.email));
29
+ console.log(chalk.dim('\nToken saved. You can now deploy agents.'));
30
+ }
31
+ catch (error) {
32
+ spinner.fail('Authentication failed');
33
+ if (error instanceof CliHttpError) {
34
+ console.log(chalk.red('Error:') + ` ${error.detail}`);
35
+ process.exit(error.status === 401 ? 2 : 1);
36
+ }
37
+ throw error;
38
+ }
20
39
  });
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const signupCommand: Command;
@@ -0,0 +1,42 @@
1
+ import { Command } from 'commander';
2
+ import chalk from 'chalk';
3
+ import ora from 'ora';
4
+ import { config } from '../config.js';
5
+ import { CliHttpError, postJson } from '../api.js';
6
+ import { promptForPassword, promptForValue } from '../prompt.js';
7
+ export const signupCommand = new Command('signup')
8
+ .description('Create a Maritime account with email and password')
9
+ .option('-e, --email <email>', 'Email address')
10
+ .option('-p, --password <password>', 'Password')
11
+ .option('-n, --name <name>', 'Display name')
12
+ .action(async (opts) => {
13
+ const email = await promptForValue('Email', opts.email);
14
+ const password = await promptForPassword(opts.password);
15
+ const name = await promptForValue('Name (optional)', opts.name);
16
+ if (!email || !password) {
17
+ console.log(chalk.red('Error:') + ' email and password are required');
18
+ process.exit(1);
19
+ }
20
+ const spinner = ora('Creating account...').start();
21
+ try {
22
+ const auth = await postJson('/api/auth/cli-signup', {
23
+ email,
24
+ password,
25
+ name: name || undefined,
26
+ });
27
+ config.set('token', auth.token);
28
+ config.set('user', auth.user.email);
29
+ config.set('userId', auth.user.id);
30
+ config.set('apiUrl', process.env.MARITIME_API_URL || 'https://api.maritime.sh');
31
+ spinner.succeed(chalk.green('Authenticated as ') + chalk.bold(auth.user.email));
32
+ console.log(chalk.dim('\nToken saved. You can now deploy agents.'));
33
+ }
34
+ catch (error) {
35
+ spinner.fail('Signup failed');
36
+ if (error instanceof CliHttpError) {
37
+ console.log(chalk.red('Error:') + ` ${error.detail}`);
38
+ process.exit(error.status >= 500 ? 1 : 2);
39
+ }
40
+ throw error;
41
+ }
42
+ });
@@ -0,0 +1,2 @@
1
+ import Conf from 'conf';
2
+ export declare const config: Conf<Record<string, unknown>>;
package/dist/config.js ADDED
@@ -0,0 +1,6 @@
1
+ import Conf from 'conf';
2
+ const configDir = process.env.MARITIME_CONFIG_DIR;
3
+ export const config = new Conf({
4
+ projectName: 'maritime',
5
+ ...(configDir ? { cwd: configDir } : {}),
6
+ });
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { Command } from 'commander';
3
3
  import chalk from 'chalk';
4
4
  import { loginCommand } from './commands/login.js';
5
+ import { signupCommand } from './commands/signup.js';
5
6
  import { deployCommand } from './commands/deploy.js';
6
7
  import { logsCommand } from './commands/logs.js';
7
8
  import { envCommand } from './commands/env.js';
@@ -11,6 +12,7 @@ program
11
12
  .name('maritime')
12
13
  .description(chalk.hex('#8B5CF6')('Maritime') + ' — Deploy AI agents for $1/month')
13
14
  .version('0.1.0');
15
+ program.addCommand(signupCommand);
14
16
  program.addCommand(loginCommand);
15
17
  program.addCommand(deployCommand);
16
18
  program.addCommand(logsCommand);
@@ -0,0 +1,2 @@
1
+ export declare function promptForValue(label: string, preset?: string): Promise<string>;
2
+ export declare function promptForPassword(preset?: string): Promise<string>;
package/dist/prompt.js ADDED
@@ -0,0 +1,58 @@
1
+ import { createInterface } from 'node:readline/promises';
2
+ import { stdin as input, stdout as output } from 'node:process';
3
+ function createPrompt() {
4
+ return createInterface({ input, output });
5
+ }
6
+ export async function promptForValue(label, preset) {
7
+ if (preset) {
8
+ return preset;
9
+ }
10
+ const rl = createPrompt();
11
+ try {
12
+ return (await rl.question(`${label}: `)).trim();
13
+ }
14
+ finally {
15
+ rl.close();
16
+ }
17
+ }
18
+ export async function promptForPassword(preset) {
19
+ if (preset) {
20
+ return preset;
21
+ }
22
+ if (!input.isTTY || !output.isTTY) {
23
+ return promptForValue('Password');
24
+ }
25
+ output.write('Password: ');
26
+ const wasRaw = input.isRaw;
27
+ const chunks = [];
28
+ return await new Promise((resolve) => {
29
+ input.setRawMode?.(true);
30
+ input.resume();
31
+ const cleanup = () => {
32
+ input.removeListener('data', onData);
33
+ input.setRawMode?.(Boolean(wasRaw));
34
+ output.write('\n');
35
+ };
36
+ const finish = () => {
37
+ cleanup();
38
+ resolve(chunks.join('').trim());
39
+ };
40
+ const onData = (buffer) => {
41
+ const value = buffer.toString('utf8');
42
+ if (value === '\u0003') {
43
+ cleanup();
44
+ process.exit(130);
45
+ }
46
+ if (value === '\r' || value === '\n') {
47
+ finish();
48
+ return;
49
+ }
50
+ if (value === '\u007f') {
51
+ chunks.pop();
52
+ return;
53
+ }
54
+ chunks.push(value);
55
+ };
56
+ input.on('data', onData);
57
+ });
58
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maritime-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Maritime CLI - Deploy AI agents from your terminal",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -9,15 +9,23 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/mariagorskikh/maritime"
11
11
  },
12
- "keywords": ["ai", "agents", "deploy", "cli", "maritime"],
12
+ "keywords": [
13
+ "ai",
14
+ "agents",
15
+ "deploy",
16
+ "cli",
17
+ "maritime"
18
+ ],
13
19
  "bin": {
14
20
  "maritime": "./dist/index.js"
15
21
  },
16
- "files": ["dist"],
22
+ "files": [
23
+ "dist"
24
+ ],
17
25
  "scripts": {
18
- "build": "tsc",
26
+ "build": "tsc && chmod +x dist/index.js",
19
27
  "dev": "tsx src/index.ts",
20
- "prepublishOnly": "tsc"
28
+ "prepublishOnly": "npm run build"
21
29
  },
22
30
  "dependencies": {
23
31
  "chalk": "^5.3.0",