nexusapp-cli 2.1.1 → 3.0.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 (56) hide show
  1. package/dist/index.js +8 -0
  2. package/package.json +8 -2
  3. package/src/commands/bucket.ts +261 -0
  4. package/src/commands/database.ts +35 -0
  5. package/src/commands/deploy.ts +138 -4
  6. package/src/commands/exec.ts +154 -0
  7. package/src/commands/managedDb.ts +170 -0
  8. package/src/commands/volume.ts +113 -0
  9. package/src/index.ts +8 -0
  10. package/dist/client.d.ts +0 -6
  11. package/dist/client.d.ts.map +0 -1
  12. package/dist/client.js +0 -63
  13. package/dist/client.js.map +0 -1
  14. package/dist/commands/auth.d.ts +0 -3
  15. package/dist/commands/auth.d.ts.map +0 -1
  16. package/dist/commands/auth.js +0 -178
  17. package/dist/commands/auth.js.map +0 -1
  18. package/dist/commands/database.d.ts +0 -3
  19. package/dist/commands/database.d.ts.map +0 -1
  20. package/dist/commands/database.js +0 -312
  21. package/dist/commands/database.js.map +0 -1
  22. package/dist/commands/deploy.d.ts +0 -3
  23. package/dist/commands/deploy.d.ts.map +0 -1
  24. package/dist/commands/deploy.js +0 -868
  25. package/dist/commands/deploy.js.map +0 -1
  26. package/dist/commands/domain.d.ts +0 -3
  27. package/dist/commands/domain.d.ts.map +0 -1
  28. package/dist/commands/domain.js +0 -174
  29. package/dist/commands/domain.js.map +0 -1
  30. package/dist/commands/member.d.ts +0 -3
  31. package/dist/commands/member.d.ts.map +0 -1
  32. package/dist/commands/member.js +0 -175
  33. package/dist/commands/member.js.map +0 -1
  34. package/dist/commands/project.d.ts +0 -3
  35. package/dist/commands/project.d.ts.map +0 -1
  36. package/dist/commands/project.js +0 -92
  37. package/dist/commands/project.js.map +0 -1
  38. package/dist/commands/secret.d.ts +0 -3
  39. package/dist/commands/secret.d.ts.map +0 -1
  40. package/dist/commands/secret.js +0 -121
  41. package/dist/commands/secret.js.map +0 -1
  42. package/dist/commands/token.d.ts +0 -3
  43. package/dist/commands/token.d.ts.map +0 -1
  44. package/dist/commands/token.js +0 -179
  45. package/dist/commands/token.js.map +0 -1
  46. package/dist/config.d.ts +0 -10
  47. package/dist/config.d.ts.map +0 -1
  48. package/dist/config.js +0 -53
  49. package/dist/config.js.map +0 -1
  50. package/dist/index.d.ts +0 -3
  51. package/dist/index.d.ts.map +0 -1
  52. package/dist/index.js.map +0 -1
  53. package/dist/output.d.ts +0 -9
  54. package/dist/output.d.ts.map +0 -1
  55. package/dist/output.js +0 -71
  56. package/dist/output.js.map +0 -1
@@ -0,0 +1,154 @@
1
+ import { Command } from 'commander';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+ import { client, apiError, unwrap } from '../client.js';
5
+ import { success, errorMsg, printJson } from '../output.js';
6
+
7
+ function formatBytes(n: number): string {
8
+ if (n < 1024) return `${n} B`;
9
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
10
+ if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
11
+ return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
12
+ }
13
+
14
+ /**
15
+ * Parse a "<deploymentId>:<path>" argument. Returns null if the arg has no
16
+ * colon (i.e. it's a local path). UUIDs contain hyphens but no colons, so the
17
+ * first ":" cleanly separates the two halves.
18
+ */
19
+ function parseRemoteRef(arg: string): { deploymentId: string; remotePath: string } | null {
20
+ const idx = arg.indexOf(':');
21
+ if (idx < 0) return null;
22
+ const deploymentId = arg.slice(0, idx);
23
+ const remotePath = arg.slice(idx + 1);
24
+ if (!deploymentId || !remotePath) return null;
25
+ return { deploymentId, remotePath };
26
+ }
27
+
28
+ export function registerExec(program: Command): void {
29
+ program
30
+ .command('exec <deploymentId> [command...]')
31
+ .description('Run a command inside the running deployment container (LOCAL_DOCKER only)')
32
+ .option('--timeout <seconds>', 'Max seconds before the command is killed (default 60, max 1800)', (v) => parseInt(v, 10))
33
+ .option('--workdir <path>', 'Working directory inside the container')
34
+ .option('--json', 'Output raw JSON result')
35
+ .allowUnknownOption(false)
36
+ .action(async (deploymentId, commandParts, opts) => {
37
+ if (!commandParts || commandParts.length === 0) {
38
+ errorMsg('Provide a command to run, e.g. `nexus exec <id> ls -la /app`');
39
+ process.exit(2);
40
+ }
41
+
42
+ try {
43
+ const res = await client.post(
44
+ `/api/deployments/${deploymentId}/exec`,
45
+ {
46
+ command: commandParts,
47
+ timeoutSeconds: opts.timeout,
48
+ workingDir: opts.workdir,
49
+ },
50
+ { timeout: 0 }
51
+ );
52
+ const result = unwrap(res.data);
53
+
54
+ if (opts.json) {
55
+ printJson(result);
56
+ process.exit(result.exitCode === 0 ? 0 : 1);
57
+ }
58
+
59
+ if (result.stdout) process.stdout.write(result.stdout);
60
+ if (result.stderr) process.stderr.write(result.stderr);
61
+ if (result.truncated) {
62
+ process.stderr.write('\n[output truncated at 2MB per stream]\n');
63
+ }
64
+ process.exit(result.exitCode === 0 ? 0 : result.exitCode || 1);
65
+ } catch (err) {
66
+ errorMsg(apiError(err));
67
+ process.exit(1);
68
+ }
69
+ });
70
+
71
+ program
72
+ .command('cp <source> <destination>')
73
+ .description(
74
+ 'Copy a single file between a local path and a running deployment container.\n' +
75
+ ' Upload: nexus cp ./index.html <deploymentId>:/app/public/index.html\n' +
76
+ ' Download: nexus cp <deploymentId>:/app/config.json ./config.json'
77
+ )
78
+ .action(async (source, destination) => {
79
+ const srcRemote = parseRemoteRef(source);
80
+ const dstRemote = parseRemoteRef(destination);
81
+
82
+ if (srcRemote && dstRemote) {
83
+ errorMsg('Container-to-container copy is not supported. Download first, then upload.');
84
+ process.exit(2);
85
+ }
86
+ if (!srcRemote && !dstRemote) {
87
+ errorMsg('At least one side must be a container reference (e.g. `<deploymentId>:/app/file.txt`).');
88
+ process.exit(2);
89
+ }
90
+
91
+ try {
92
+ if (!srcRemote && dstRemote) {
93
+ // Upload: local -> container
94
+ const localPath = path.resolve(source);
95
+ if (!fs.existsSync(localPath)) {
96
+ errorMsg(`Local file not found: ${localPath}`);
97
+ process.exit(1);
98
+ }
99
+ const stat = fs.statSync(localPath);
100
+ if (!stat.isFile()) {
101
+ errorMsg(`Not a regular file: ${localPath} (directory uploads not supported — tar + exec instead)`);
102
+ process.exit(1);
103
+ }
104
+ const stream = fs.createReadStream(localPath);
105
+ const res = await client.post(
106
+ `/api/deployments/${dstRemote.deploymentId}/files`,
107
+ stream,
108
+ {
109
+ params: { path: dstRemote.remotePath },
110
+ headers: {
111
+ 'Content-Type': 'application/octet-stream',
112
+ 'Content-Length': String(stat.size),
113
+ },
114
+ timeout: 0,
115
+ maxBodyLength: Infinity,
116
+ maxContentLength: Infinity,
117
+ }
118
+ );
119
+ const data = unwrap(res.data);
120
+ success(`Uploaded ${formatBytes(data.bytesWritten || stat.size)} → ${dstRemote.deploymentId}:${data.targetPath || dstRemote.remotePath}`);
121
+ return;
122
+ }
123
+
124
+ // Download: container -> local
125
+ const remote = srcRemote!;
126
+ const localPath = path.resolve(destination);
127
+ const dir = path.dirname(localPath);
128
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
129
+
130
+ const res = await client.get(`/api/deployments/${remote.deploymentId}/files`, {
131
+ params: { path: remote.remotePath },
132
+ responseType: 'stream',
133
+ timeout: 0,
134
+ maxContentLength: Infinity,
135
+ });
136
+
137
+ let bytes = 0;
138
+ res.data.on('data', (chunk: Buffer) => { bytes += chunk.length; });
139
+
140
+ await new Promise<void>((resolve, reject) => {
141
+ const writer = fs.createWriteStream(localPath);
142
+ res.data.pipe(writer);
143
+ writer.on('finish', () => resolve());
144
+ writer.on('error', reject);
145
+ res.data.on('error', reject);
146
+ });
147
+
148
+ success(`Downloaded ${formatBytes(bytes)} → ${localPath}`);
149
+ } catch (err) {
150
+ errorMsg(apiError(err));
151
+ process.exit(1);
152
+ }
153
+ });
154
+ }
@@ -0,0 +1,170 @@
1
+ import { Command } from 'commander';
2
+ import { client, apiError } from '../client.js';
3
+ import { printTable, printJson, success, errorMsg, timeAgo } from '../output.js';
4
+
5
+ export function registerManagedDb(program: Command): void {
6
+ const md = program
7
+ .command('managed-db')
8
+ .description('Managed cloud databases (AWS RDS instances)');
9
+
10
+ md
11
+ .command('list')
12
+ .description('List managed databases')
13
+ .option('--json', 'Output raw JSON')
14
+ .action(async (opts) => {
15
+ try {
16
+ const res = await client.get('/api/managed-databases');
17
+ const dbs: any[] = res.data?.managedDatabases || [];
18
+ if (opts.json) { printJson(dbs); return; }
19
+ if (!dbs.length) { console.log('No managed databases found.'); return; }
20
+ printTable(
21
+ ['ID', 'NAME', 'ENGINE', 'STATUS', 'ENDPOINT', 'CREATED'],
22
+ dbs.map((d: any) => [
23
+ d.id,
24
+ d.displayName ? `${d.name} (${d.displayName})` : d.name,
25
+ `${d.engine} ${d.engineVersion}`,
26
+ d.status,
27
+ d.endpointHost ? `${d.endpointHost}:${d.endpointPort}` : '—',
28
+ d.createdAt ? timeAgo(d.createdAt) : '—',
29
+ ])
30
+ );
31
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
32
+ });
33
+
34
+ md
35
+ .command('create <name>')
36
+ .description('Provision a new managed database')
37
+ .requiredOption('--engine <engine>', 'POSTGRES or MYSQL')
38
+ .requiredOption('--engine-version <version>', 'e.g. 17.10 (postgres), 8.0.46 (mysql)')
39
+ .option('--provider <provider>', 'AWS_RDS, GCP_CLOUD_SQL, or AZURE_DATABASE', 'AWS_RDS')
40
+ .option('--network-mode <mode>', 'public or vpc (AWS only; vpc = private, App Runner-only)')
41
+ .option('--display-name <name>', 'Friendly display name')
42
+ .option('--instance-class <class>', 'e.g. db.t3.micro (AWS) / db-custom-1-3840 (GCP)')
43
+ .option('--allocated-gb <gb>', 'Storage in GB (20-1000)')
44
+ .option('--region <region>', 'Cloud region')
45
+ .option('--json', 'Output raw JSON')
46
+ .action(async (name, opts) => {
47
+ try {
48
+ const res = await client.post('/api/managed-databases', {
49
+ name,
50
+ provider: opts.provider,
51
+ networkMode: opts.networkMode,
52
+ engine: opts.engine,
53
+ engineVersion: opts.engineVersion,
54
+ displayName: opts.displayName,
55
+ instanceClass: opts.instanceClass,
56
+ allocatedGb: opts.allocatedGb ? Number(opts.allocatedGb) : undefined,
57
+ region: opts.region,
58
+ });
59
+ const db = res.data?.managedDatabase;
60
+ if (opts.json) { printJson(db); return; }
61
+ success(`Managed database created: ${db?.id} (${db?.status})`);
62
+ console.log('Provisioning is async — run `nexus managed-db list` until status is AVAILABLE.');
63
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
64
+ });
65
+
66
+ md
67
+ .command('delete <id>')
68
+ .description('Delete a managed database (destroys data)')
69
+ .option('--json', 'Output raw JSON')
70
+ .action(async (id, opts) => {
71
+ try {
72
+ await client.delete(`/api/managed-databases/${id}`);
73
+ if (opts.json) { printJson({ success: true }); return; }
74
+ success(`Managed database ${id} deleted.`);
75
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
76
+ });
77
+
78
+ md
79
+ .command('attach <id>')
80
+ .description('Attach a managed database to a deployment')
81
+ .requiredOption('--deployment <deploymentId>', 'Deployment ID')
82
+ .option('--env-prefix <prefix>', 'Env var namespace (default DATABASE)')
83
+ .option('--json', 'Output raw JSON')
84
+ .action(async (id, opts) => {
85
+ try {
86
+ const res = await client.post(`/api/managed-databases/${id}/attach`, {
87
+ deploymentId: opts.deployment,
88
+ envPrefix: opts.envPrefix,
89
+ });
90
+ if (opts.json) { printJson(res.data?.attachment); return; }
91
+ success(`Attached to ${opts.deployment}. Redeploy for DATABASE_* env vars to take effect.`);
92
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
93
+ });
94
+
95
+ md
96
+ .command('detach <id>')
97
+ .description('Detach a managed database from a deployment')
98
+ .requiredOption('--deployment <deploymentId>', 'Deployment ID')
99
+ .option('--json', 'Output raw JSON')
100
+ .action(async (id, opts) => {
101
+ try {
102
+ await client.post(`/api/managed-databases/${id}/detach`, { deploymentId: opts.deployment });
103
+ if (opts.json) { printJson({ success: true }); return; }
104
+ success(`Detached from ${opts.deployment}.`);
105
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
106
+ });
107
+
108
+ md
109
+ .command('snapshot <id>')
110
+ .description('Create a snapshot backup of a managed database')
111
+ .option('--notes <notes>', 'Optional notes')
112
+ .option('--json', 'Output raw JSON')
113
+ .action(async (id, opts) => {
114
+ try {
115
+ const res = await client.post(`/api/managed-databases/${id}/snapshots`, { notes: opts.notes });
116
+ const snap = res.data?.snapshot;
117
+ if (opts.json) { printJson(snap); return; }
118
+ success(`Snapshot ${snap?.id} started (${snap?.status}).`);
119
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
120
+ });
121
+
122
+ md
123
+ .command('snapshots <id>')
124
+ .description('List snapshot backups for a managed database')
125
+ .option('--json', 'Output raw JSON')
126
+ .action(async (id, opts) => {
127
+ try {
128
+ const res = await client.get(`/api/managed-databases/${id}/snapshots`);
129
+ const snaps: any[] = res.data?.snapshots || [];
130
+ if (opts.json) { printJson(snaps); return; }
131
+ if (!snaps.length) { console.log('No snapshots found.'); return; }
132
+ printTable(
133
+ ['ID', 'STATUS', 'SIZE (B)', 'NOTES', 'CREATED'],
134
+ snaps.map((s: any) => [s.id, s.status, String(s.sizeBytes), s.notes || '—', s.createdAt ? timeAgo(s.createdAt) : '—'])
135
+ );
136
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
137
+ });
138
+
139
+ md
140
+ .command('query <id> <sql>')
141
+ .description('Run a SQL statement against a managed database')
142
+ .option('--json', 'Output raw JSON')
143
+ .action(async (id, sql, opts) => {
144
+ try {
145
+ const res = await client.post(`/api/managed-databases/${id}/query`, { sql });
146
+ if (opts.json) { printJson(res.data); return; }
147
+ const rows = res.data?.rows || [];
148
+ console.log(`${res.data?.classification}: ${res.data?.rowCount} row(s)`);
149
+ if (rows.length) printJson(rows);
150
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
151
+ });
152
+
153
+ md
154
+ .command('restore <id>')
155
+ .description('Restore a snapshot into a NEW managed database (non-destructive)')
156
+ .requiredOption('--snapshot <snapshotId>', 'Snapshot ID to restore from')
157
+ .requiredOption('--new-name <name>', 'Name for the restored database')
158
+ .option('--json', 'Output raw JSON')
159
+ .action(async (id, opts) => {
160
+ try {
161
+ const res = await client.post(`/api/managed-databases/${id}/restore`, {
162
+ snapshotId: opts.snapshot,
163
+ newName: opts.newName,
164
+ });
165
+ const db = res.data?.managedDatabase;
166
+ if (opts.json) { printJson(db); return; }
167
+ success(`Restore started: new database ${db?.id} (${db?.status}). Run \`nexus managed-db list\` until AVAILABLE.`);
168
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
169
+ });
170
+ }
@@ -0,0 +1,113 @@
1
+ import { Command } from 'commander';
2
+ import inquirer from 'inquirer';
3
+ import { client, apiError, unwrap } from '../client.js';
4
+ import { printTable, printJson, success, errorMsg, timeAgo } from '../output.js';
5
+
6
+ function formatBytes(bytes: number | bigint): string {
7
+ const n = typeof bytes === 'bigint' ? Number(bytes) : bytes;
8
+ if (n < 1024) return `${n} B`;
9
+ if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
10
+ if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
11
+ return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
12
+ }
13
+
14
+ export function registerVolume(program: Command): void {
15
+ const vol = program
16
+ .command('volume')
17
+ .description('Persistent storage volumes (filesystem mounts attached to deployments)');
18
+
19
+ vol
20
+ .command('list')
21
+ .description('List volumes')
22
+ .option('--json', 'Output raw JSON')
23
+ .action(async (opts) => {
24
+ try {
25
+ const res = await client.get('/api/volumes');
26
+ const volumes: any[] = unwrap(res.data) || [];
27
+ if (opts.json) { printJson(volumes); return; }
28
+ if (!volumes.length) { console.log('No volumes found.'); return; }
29
+
30
+ printTable(
31
+ ['ID', 'NAME', 'SIZE', 'STATUS', 'ATTACHED TO', 'CREATED'],
32
+ volumes.map((v: any) => [
33
+ v.id,
34
+ v.displayName ? `${v.name} (${v.displayName})` : v.name,
35
+ formatBytes(v.sizeBytes),
36
+ v.status,
37
+ v.attachment ? `${v.attachment.deploymentName}:${v.attachment.mountPath}` : '—',
38
+ v.createdAt ? timeAgo(v.createdAt) : '—',
39
+ ])
40
+ );
41
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
42
+ });
43
+
44
+ vol
45
+ .command('create <name>')
46
+ .description('Create a new volume (org-scoped)')
47
+ .option('--display-name <name>', 'Friendly display name')
48
+ .option('--json', 'Output raw JSON')
49
+ .action(async (name, opts) => {
50
+ try {
51
+ const res = await client.post('/api/volumes', { name, displayName: opts.displayName });
52
+ const v = unwrap(res.data);
53
+ if (opts.json) { printJson(v); return; }
54
+ success(`Volume created: ${v.id} (${v.name})`);
55
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
56
+ });
57
+
58
+ vol
59
+ .command('delete <id>')
60
+ .description('Delete a volume (must be detached first)')
61
+ .option('--yes', 'Skip confirmation prompt')
62
+ .action(async (id, opts) => {
63
+ if (!opts.yes) {
64
+ const { confirm } = await inquirer.prompt([
65
+ { type: 'confirm', name: 'confirm', message: `Delete volume "${id}"? Data is destroyed.`, default: false },
66
+ ]);
67
+ if (!confirm) { console.log('Cancelled.'); return; }
68
+ }
69
+ try {
70
+ await client.delete(`/api/volumes/${id}`);
71
+ success(`Volume ${id} deleted.`);
72
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
73
+ });
74
+
75
+ vol
76
+ .command('attach <id> <deployment-id>')
77
+ .description('Attach a volume to a deployment (requires redeploy to take effect)')
78
+ .option('--mount <path>', 'Mount path inside the container', '/data')
79
+ .action(async (id, deploymentId, opts) => {
80
+ try {
81
+ const res = await client.post(`/api/volumes/${id}/attach`, {
82
+ deploymentId,
83
+ mountPath: opts.mount,
84
+ });
85
+ const dv = unwrap(res.data);
86
+ success(`Attached volume ${id} to deployment ${deploymentId} at ${dv.mountPath}.`);
87
+ console.log(" Run 'nexus deploy redeploy <id>' to mount it.");
88
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
89
+ });
90
+
91
+ vol
92
+ .command('detach <id>')
93
+ .description('Detach a volume from its deployment')
94
+ .action(async (id) => {
95
+ try {
96
+ await client.post(`/api/volumes/${id}/detach`);
97
+ success(`Volume ${id} detached.`);
98
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
99
+ });
100
+
101
+ vol
102
+ .command('refresh-usage <id>')
103
+ .description('Refresh on-disk usage for a volume')
104
+ .option('--json', 'Output raw JSON')
105
+ .action(async (id, opts) => {
106
+ try {
107
+ const res = await client.post(`/api/volumes/${id}/refresh-usage`);
108
+ const v = unwrap(res.data);
109
+ if (opts.json) { printJson(v); return; }
110
+ success(`${v.name}: ${formatBytes(v.sizeBytes)}`);
111
+ } catch (err) { errorMsg(apiError(err)); process.exit(1); }
112
+ });
113
+ }
package/src/index.ts CHANGED
@@ -8,6 +8,10 @@ import { registerDomain } from './commands/domain.js';
8
8
  import { registerToken } from './commands/token.js';
9
9
  import { registerMember } from './commands/member.js';
10
10
  import { registerDatabase } from './commands/database.js';
11
+ import { registerVolume } from './commands/volume.js';
12
+ import { registerBucket } from './commands/bucket.js';
13
+ import { registerManagedDb } from './commands/managedDb.js';
14
+ import { registerExec } from './commands/exec.js';
11
15
 
12
16
  const program = new Command();
13
17
 
@@ -24,6 +28,10 @@ registerDomain(program);
24
28
  registerToken(program);
25
29
  registerMember(program);
26
30
  registerDatabase(program);
31
+ registerVolume(program);
32
+ registerBucket(program);
33
+ registerManagedDb(program);
34
+ registerExec(program);
27
35
 
28
36
  program.parseAsync(process.argv).catch((err) => {
29
37
  console.error(err.message || String(err));
package/dist/client.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- export declare const client: AxiosInstance;
3
- /** Unwrap { success, data } envelope if present, otherwise return as-is. */
4
- export declare function unwrap(responseData: any): any;
5
- export declare function apiError(error: unknown): string;
6
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,aAAa,EAAc,MAAM,OAAO,CAAC;AAkDzD,eAAO,MAAM,MAAM,eAAiB,CAAC;AAErC,4EAA4E;AAC5E,wBAAgB,MAAM,CAAC,YAAY,EAAE,GAAG,GAAG,GAAG,CAK7C;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAO/C"}
package/dist/client.js DELETED
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.client = void 0;
7
- exports.unwrap = unwrap;
8
- exports.apiError = apiError;
9
- const axios_1 = __importDefault(require("axios"));
10
- const config_js_1 = require("./config.js");
11
- function createClient() {
12
- const config = (0, config_js_1.getConfig)();
13
- const baseURL = config.apiUrl || 'https://nexusai.run';
14
- const instance = axios_1.default.create({
15
- baseURL,
16
- timeout: 30000,
17
- });
18
- instance.interceptors.request.use((req) => {
19
- const cfg = (0, config_js_1.getConfig)();
20
- if (cfg.token) {
21
- req.headers = req.headers || {};
22
- req.headers['Authorization'] = `Bearer ${cfg.token}`;
23
- }
24
- return req;
25
- });
26
- instance.interceptors.response.use((res) => res, (error) => {
27
- if (!error.response) {
28
- const url = baseURL;
29
- console.error(`Cannot reach NEXUS AI API at ${url}.`);
30
- process.exit(1);
31
- }
32
- const status = error.response.status;
33
- const data = error.response.data;
34
- if (status === 401) {
35
- console.error("Session expired. Run 'nexus auth login'");
36
- process.exit(1);
37
- }
38
- if (status === 403) {
39
- console.error(data?.message || data?.error || 'Access denied.');
40
- process.exit(1);
41
- }
42
- return Promise.reject(error);
43
- });
44
- return instance;
45
- }
46
- exports.client = createClient();
47
- /** Unwrap { success, data } envelope if present, otherwise return as-is. */
48
- function unwrap(responseData) {
49
- if (responseData && typeof responseData === 'object' && 'data' in responseData) {
50
- return responseData.data;
51
- }
52
- return responseData;
53
- }
54
- function apiError(error) {
55
- if (axios_1.default.isAxiosError(error)) {
56
- const data = error.response?.data;
57
- return data?.message || data?.error || error.message;
58
- }
59
- if (error instanceof Error)
60
- return error.message;
61
- return String(error);
62
- }
63
- //# sourceMappingURL=client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AAqDA,wBAKC;AAED,4BAOC;AAnED,kDAAyD;AACzD,2CAAwC;AAExC,SAAS,YAAY;IACnB,MAAM,MAAM,GAAG,IAAA,qBAAS,GAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,IAAI,qBAAqB,CAAC;IAEvD,MAAM,QAAQ,GAAG,eAAK,CAAC,MAAM,CAAC;QAC5B,OAAO;QACP,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QACxC,MAAM,GAAG,GAAG,IAAA,qBAAS,GAAE,CAAC;QACxB,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YACd,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC;YAChC,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,GAAG,CAAC,KAAK,EAAE,CAAC;QACvD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAChC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EACZ,CAAC,KAAiB,EAAE,EAAE;QACpB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACpB,MAAM,GAAG,GAAG,OAAO,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,gCAAgC,GAAG,GAAG,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QACrC,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAW,CAAC;QAExC,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;YACzD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,IAAI,IAAI,EAAE,KAAK,IAAI,gBAAgB,CAAC,CAAC;YAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC,CACF,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAEY,QAAA,MAAM,GAAG,YAAY,EAAE,CAAC;AAErC,4EAA4E;AAC5E,SAAgB,MAAM,CAAC,YAAiB;IACtC,IAAI,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,MAAM,IAAI,YAAY,EAAE,CAAC;QAC/E,OAAO,YAAY,CAAC,IAAI,CAAC;IAC3B,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAgB,QAAQ,CAAC,KAAc;IACrC,IAAI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAE,IAAW,CAAC;QACzC,OAAO,IAAI,EAAE,OAAO,IAAI,IAAI,EAAE,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC;IACvD,CAAC;IACD,IAAI,KAAK,YAAY,KAAK;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACjD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function registerAuth(program: Command): void;
3
- //# sourceMappingURL=auth.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyEpC,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgHnD"}