ardent-cli-beta 0.0.10 → 0.0.11

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/README.md CHANGED
@@ -13,8 +13,9 @@ local session. The CLI always talks to Ardent's production control plane. Oclif
13
13
  provides help, version, autocomplete, and native JSON command behavior. Resource
14
14
  context is retained from login. Project listing, creation, deletion, and local
15
15
  context switching are implemented. Organization member listing, invitation,
16
- removal, and pending-invitation cancellation are implemented; other resource
17
- commands are not implemented yet.
16
+ removal, and pending-invitation cancellation are implemented. Connector listing
17
+ and registration are implemented; registration follows connector status, while
18
+ credential delivery and replication readiness remain owed.
18
19
 
19
20
  Set `ARDENT_API_URL` to point the CLI at a development control plane. Without
20
21
  it, the CLI uses `https://production.tryardent.com`.
@@ -33,6 +34,8 @@ npm run build
33
34
  ./bin/run.js member invite teammate@example.com
34
35
  ./bin/run.js member invite administrator@example.com --role admin
35
36
  ./bin/run.js member delete teammate@example.com
37
+ ./bin/run.js connector list
38
+ ./bin/run.js connector create postgresql 'postgresql://user:password@database.example.com/app'
36
39
  ARDENT_API_URL=http://localhost:8080 ./bin/run.js login --token <token>
37
40
  ```
38
41
 
@@ -0,0 +1,19 @@
1
+ import { ArdentCommand } from '../../command.js';
2
+ interface ConnectorCreation {
3
+ connector_id: string;
4
+ status: 'registered' | 'registering';
5
+ }
6
+ export default class ConnectorCreate extends ArdentCommand {
7
+ static args: {
8
+ type: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
9
+ url: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
10
+ };
11
+ static description: string;
12
+ static helpGroup: string;
13
+ static flags: {
14
+ environment: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ };
17
+ run(): Promise<ConnectorCreation>;
18
+ }
19
+ export {};
@@ -0,0 +1,56 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { Args, Flags, ux } from '@oclif/core';
3
+ import { loadSession } from '../../auth/credentials.js';
4
+ import { ArdentCommand } from '../../command.js';
5
+ import { createConnector, waitForConnectorRegistration } from '../../connectors/client.js';
6
+ import { terminalText } from '../../terminal.js';
7
+ export default class ConnectorCreate extends ArdentCommand {
8
+ static args = {
9
+ type: Args.string({ description: 'Connector type', required: true }),
10
+ url: Args.string({ description: 'PostgreSQL connection URL', required: true }),
11
+ };
12
+ static description = 'Register a PostgreSQL connector in the selected project';
13
+ static helpGroup = 'Connectors';
14
+ static flags = {
15
+ environment: Flags.string({ description: 'Environment ID (defaults to Ardent Cloud)' }),
16
+ name: Flags.string({ char: 'n', description: 'Connector name' }),
17
+ };
18
+ async run() {
19
+ const { args, flags } = await this.parse(ConnectorCreate);
20
+ if (!['postgres', 'postgresql'].includes(args.type.toLowerCase())) {
21
+ this.error(`Unsupported connector type ${JSON.stringify(args.type)}. Supported: postgresql.`);
22
+ }
23
+ const session = await loadSession(this.config.configDir);
24
+ if (!session?.organization)
25
+ this.error('You must be logged in to run this command. Run ardent login.');
26
+ if (!session.selectedProject)
27
+ this.error('No project selected. Run ardent project list, then ardent project switch <name>.');
28
+ const providedName = flags.name?.trim();
29
+ if (flags.name !== undefined && !providedName)
30
+ this.error('Connector name cannot be empty.');
31
+ const name = providedName ?? `${session.selectedProject.name}-${randomUUID().slice(0, 8)}`;
32
+ const environmentID = flags.environment?.trim();
33
+ if (flags.environment !== undefined && !environmentID)
34
+ this.error('Environment ID cannot be empty.');
35
+ const interactive = !this.jsonEnabled() && ux.action.type === 'spinner';
36
+ if (interactive) {
37
+ ux.action.start(`${terminalText(name)} in ${terminalText(session.selectedProject.name)}`, 'registering');
38
+ }
39
+ else if (!this.jsonEnabled()) {
40
+ this.log(`Registering connector ${terminalText(name)} for project ${terminalText(session.selectedProject.name)}...`);
41
+ }
42
+ const registration = await createConnector(session.token, session.organization.id, session.selectedProject.id, environmentID, name, args.url);
43
+ if (!interactive) {
44
+ if (!this.jsonEnabled()) {
45
+ this.log(`Connector registration started (${terminalText(registration.connector_id)}).`);
46
+ }
47
+ return { connector_id: registration.connector_id, status: 'registering' };
48
+ }
49
+ await waitForConnectorRegistration(session.token, registration.connector_id, (status) => {
50
+ ux.action.status = status;
51
+ });
52
+ ux.action.stop(ux.colorize('green', '✓ registered'));
53
+ this.log('Credential delivery and replication readiness are still pending.');
54
+ return { connector_id: registration.connector_id, status: 'registered' };
55
+ }
56
+ }
@@ -0,0 +1,9 @@
1
+ import { ArdentCommand } from '../../command.js';
2
+ import { type Connector } from '../../connectors/client.js';
3
+ export default class ConnectorList extends ArdentCommand {
4
+ static description: string;
5
+ static helpGroup: string;
6
+ run(): Promise<{
7
+ connectors: Connector[];
8
+ }>;
9
+ }
@@ -0,0 +1,25 @@
1
+ import { loadSession } from '../../auth/credentials.js';
2
+ import { ArdentCommand } from '../../command.js';
3
+ import { listConnectors } from '../../connectors/client.js';
4
+ import { terminalText } from '../../terminal.js';
5
+ export default class ConnectorList extends ArdentCommand {
6
+ static description = 'List connectors in the selected project';
7
+ static helpGroup = 'Connectors';
8
+ async run() {
9
+ const session = await loadSession(this.config.configDir);
10
+ if (!session?.organization)
11
+ this.error('You must be logged in to run this command. Run ardent login.');
12
+ if (!session.selectedProject)
13
+ this.error('No project selected. Run ardent project list, then ardent project switch <name>.');
14
+ const connectors = await listConnectors(session.token, session.organization.id, session.selectedProject.id);
15
+ if (!this.jsonEnabled()) {
16
+ if (connectors.length === 0)
17
+ this.log('No connectors found.');
18
+ const nameWidth = Math.max(0, ...connectors.map(({ name }) => terminalText(name).length));
19
+ for (const connector of connectors) {
20
+ this.log(`${terminalText(connector.name).padEnd(nameWidth)} ${terminalText(connector.status)}`);
21
+ }
22
+ }
23
+ return { connectors };
24
+ }
25
+ }
@@ -0,0 +1,25 @@
1
+ export interface Connector {
2
+ created_at: string;
3
+ environment_id: string;
4
+ id: string;
5
+ name: string;
6
+ project_id: string;
7
+ source: {
8
+ database: string;
9
+ host: string;
10
+ port: number;
11
+ };
12
+ status: string;
13
+ updated_at: string;
14
+ }
15
+ export interface ConnectorRegistration {
16
+ connector_id: string;
17
+ }
18
+ export interface ConnectorRegistrationStatus {
19
+ connector_id: string;
20
+ failure?: string;
21
+ status: 'failed' | 'registered' | 'registering';
22
+ }
23
+ export declare function listConnectors(token: string, organizationID: string, projectID: string): Promise<Connector[]>;
24
+ export declare function createConnector(token: string, organizationID: string, projectID: string, environmentID: string | undefined, name: string, url: string): Promise<ConnectorRegistration>;
25
+ export declare function waitForConnectorRegistration(token: string, connectorID: string, onStatus?: (status: ConnectorRegistrationStatus['status']) => void): Promise<ConnectorRegistrationStatus>;
@@ -0,0 +1,76 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { request } from '../api/client.js';
3
+ export async function listConnectors(token, organizationID, projectID) {
4
+ const query = new URLSearchParams({ organization_id: organizationID, project_id: projectID });
5
+ const connectors = await request(token, `/connectors?${query}`);
6
+ if (!Array.isArray(connectors) || connectors.some((connector) => !isConnector(connector, projectID))) {
7
+ throw new Error('Ardent API returned an invalid connectors response.');
8
+ }
9
+ return connectors;
10
+ }
11
+ export async function createConnector(token, organizationID, projectID, environmentID, name, url) {
12
+ const requestID = randomUUID();
13
+ const registration = await request(token, '/connectors', {
14
+ body: JSON.stringify({
15
+ ...(environmentID ? { environment_id: environmentID } : {}),
16
+ name,
17
+ organization_id: organizationID,
18
+ project_id: projectID,
19
+ request_id: requestID,
20
+ url,
21
+ }),
22
+ method: 'POST',
23
+ });
24
+ if (!isConnectorRegistration(registration))
25
+ throw new Error('Ardent API returned an invalid connector registration response.');
26
+ return registration;
27
+ }
28
+ export async function waitForConnectorRegistration(token, connectorID, onStatus) {
29
+ for (;;) {
30
+ const status = await request(token, `/connectors/${encodeURIComponent(connectorID)}`);
31
+ if (!isConnectorRegistrationStatus(status, connectorID)) {
32
+ throw new Error('Ardent API returned an invalid connector registration status.');
33
+ }
34
+ onStatus?.(status.status);
35
+ if (status.status === 'registered')
36
+ return status;
37
+ if (status.status === 'failed')
38
+ throw new Error(status.failure || 'Connector registration failed.');
39
+ await new Promise((resolve) => setTimeout(resolve, 2000));
40
+ }
41
+ }
42
+ function isConnector(value, projectID) {
43
+ if (typeof value !== 'object' || value === null)
44
+ return false;
45
+ const connector = value;
46
+ const source = connector.source;
47
+ return (typeof connector.id === 'string' &&
48
+ connector.id.length > 0 &&
49
+ connector.project_id === projectID &&
50
+ typeof connector.environment_id === 'string' &&
51
+ connector.environment_id.length > 0 &&
52
+ typeof connector.name === 'string' &&
53
+ typeof connector.status === 'string' &&
54
+ connector.status.length > 0 &&
55
+ typeof source === 'object' &&
56
+ source !== null &&
57
+ typeof source.host === 'string' &&
58
+ Number.isInteger(source.port) &&
59
+ typeof source.database === 'string' &&
60
+ typeof connector.created_at === 'string' &&
61
+ typeof connector.updated_at === 'string');
62
+ }
63
+ function isConnectorRegistration(value) {
64
+ if (typeof value !== 'object' || value === null)
65
+ return false;
66
+ const registration = value;
67
+ return typeof registration.connector_id === 'string' && registration.connector_id.length > 0;
68
+ }
69
+ function isConnectorRegistrationStatus(value, connectorID) {
70
+ if (typeof value !== 'object' || value === null)
71
+ return false;
72
+ const status = value;
73
+ return (status.connector_id === connectorID &&
74
+ (status.status === 'registering' || status.status === 'registered' || status.status === 'failed') &&
75
+ (status.failure === undefined || typeof status.failure === 'string'));
76
+ }
@@ -95,6 +95,92 @@
95
95
  "status.js"
96
96
  ]
97
97
  },
98
+ "connector:create": {
99
+ "aliases": [],
100
+ "args": {
101
+ "type": {
102
+ "description": "Connector type",
103
+ "name": "type",
104
+ "required": true
105
+ },
106
+ "url": {
107
+ "description": "PostgreSQL connection URL",
108
+ "name": "url",
109
+ "required": true
110
+ }
111
+ },
112
+ "description": "Register a PostgreSQL connector in the selected project",
113
+ "flags": {
114
+ "json": {
115
+ "description": "Format output as json.",
116
+ "helpGroup": "GLOBAL",
117
+ "name": "json",
118
+ "allowNo": false,
119
+ "type": "boolean"
120
+ },
121
+ "environment": {
122
+ "description": "Environment ID (defaults to Ardent Cloud)",
123
+ "name": "environment",
124
+ "hasDynamicHelp": false,
125
+ "multiple": false,
126
+ "type": "option"
127
+ },
128
+ "name": {
129
+ "char": "n",
130
+ "description": "Connector name",
131
+ "name": "name",
132
+ "hasDynamicHelp": false,
133
+ "multiple": false,
134
+ "type": "option"
135
+ }
136
+ },
137
+ "hasDynamicHelp": false,
138
+ "hiddenAliases": [],
139
+ "id": "connector:create",
140
+ "pluginAlias": "ardent-cli-beta",
141
+ "pluginName": "ardent-cli-beta",
142
+ "pluginType": "core",
143
+ "strict": true,
144
+ "enableJsonFlag": true,
145
+ "helpGroup": "Connectors",
146
+ "isESM": true,
147
+ "relativePath": [
148
+ "dist",
149
+ "commands",
150
+ "connector",
151
+ "create.js"
152
+ ]
153
+ },
154
+ "connector:list": {
155
+ "aliases": [],
156
+ "args": {},
157
+ "description": "List connectors in the selected project",
158
+ "flags": {
159
+ "json": {
160
+ "description": "Format output as json.",
161
+ "helpGroup": "GLOBAL",
162
+ "name": "json",
163
+ "allowNo": false,
164
+ "type": "boolean"
165
+ }
166
+ },
167
+ "hasDynamicHelp": false,
168
+ "hiddenAliases": [],
169
+ "id": "connector:list",
170
+ "pluginAlias": "ardent-cli-beta",
171
+ "pluginName": "ardent-cli-beta",
172
+ "pluginType": "core",
173
+ "strict": true,
174
+ "enableJsonFlag": true,
175
+ "helpGroup": "Connectors",
176
+ "isESM": true,
177
+ "relativePath": [
178
+ "dist",
179
+ "commands",
180
+ "connector",
181
+ "list.js"
182
+ ]
183
+ },
98
184
  "member:delete": {
99
185
  "aliases": [],
100
186
  "args": {
@@ -350,5 +436,5 @@
350
436
  ]
351
437
  }
352
438
  },
353
- "version": "0.0.10"
439
+ "version": "0.0.11"
354
440
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ardent-cli-beta",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "The Ardent command-line interface",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",