@xano/cli 0.0.13 → 0.0.15

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 (62) hide show
  1. package/README.md +97 -12
  2. package/dist/commands/profile/create/index.d.ts +2 -0
  3. package/dist/commands/profile/create/index.js +15 -0
  4. package/dist/commands/profile/edit/index.d.ts +4 -0
  5. package/dist/commands/profile/edit/index.js +37 -1
  6. package/dist/commands/profile/list/index.js +5 -0
  7. package/dist/commands/profile/project/index.d.ts +6 -0
  8. package/dist/commands/profile/project/index.js +54 -0
  9. package/dist/commands/profile/token/index.d.ts +6 -0
  10. package/dist/commands/profile/token/index.js +54 -0
  11. package/dist/commands/profile/wizard/index.d.ts +1 -0
  12. package/dist/commands/profile/wizard/index.js +70 -0
  13. package/dist/commands/run/env/delete/index.d.ts +13 -0
  14. package/dist/commands/run/env/delete/index.js +65 -0
  15. package/dist/commands/run/env/get/index.d.ts +13 -0
  16. package/dist/commands/run/env/get/index.js +52 -0
  17. package/dist/commands/run/env/list/index.d.ts +11 -0
  18. package/dist/commands/run/env/list/index.js +58 -0
  19. package/dist/commands/run/env/set/index.d.ts +13 -0
  20. package/dist/commands/run/env/set/index.js +51 -0
  21. package/dist/commands/{ephemeral/run/job → run/exec}/index.d.ts +4 -3
  22. package/dist/commands/run/exec/index.js +353 -0
  23. package/dist/commands/{ephemeral/run/service → run/info}/index.d.ts +3 -5
  24. package/dist/commands/run/info/index.js +160 -0
  25. package/dist/commands/run/projects/create/index.d.ts +13 -0
  26. package/dist/commands/run/projects/create/index.js +75 -0
  27. package/dist/commands/run/projects/delete/index.d.ts +13 -0
  28. package/dist/commands/run/projects/delete/index.js +65 -0
  29. package/dist/commands/run/projects/list/index.d.ts +12 -0
  30. package/dist/commands/run/projects/list/index.js +66 -0
  31. package/dist/commands/run/projects/update/index.d.ts +15 -0
  32. package/dist/commands/run/projects/update/index.js +86 -0
  33. package/dist/commands/run/secrets/delete/index.d.ts +13 -0
  34. package/dist/commands/run/secrets/delete/index.js +65 -0
  35. package/dist/commands/run/secrets/get/index.d.ts +13 -0
  36. package/dist/commands/run/secrets/get/index.js +52 -0
  37. package/dist/commands/run/secrets/list/index.d.ts +11 -0
  38. package/dist/commands/run/secrets/list/index.js +62 -0
  39. package/dist/commands/run/secrets/set/index.d.ts +15 -0
  40. package/dist/commands/run/secrets/set/index.js +74 -0
  41. package/dist/commands/run/sessions/delete/index.d.ts +13 -0
  42. package/dist/commands/run/sessions/delete/index.js +65 -0
  43. package/dist/commands/run/sessions/get/index.d.ts +13 -0
  44. package/dist/commands/run/sessions/get/index.js +72 -0
  45. package/dist/commands/run/sessions/list/index.d.ts +12 -0
  46. package/dist/commands/run/sessions/list/index.js +64 -0
  47. package/dist/commands/run/sessions/start/index.d.ts +13 -0
  48. package/dist/commands/run/sessions/start/index.js +56 -0
  49. package/dist/commands/run/sessions/stop/index.d.ts +13 -0
  50. package/dist/commands/run/sessions/stop/index.js +56 -0
  51. package/dist/commands/run/sink/get/index.d.ts +13 -0
  52. package/dist/commands/run/sink/get/index.js +63 -0
  53. package/dist/lib/base-run-command.d.ts +41 -0
  54. package/dist/lib/base-run-command.js +73 -0
  55. package/dist/lib/run-http-client.d.ts +58 -0
  56. package/dist/lib/run-http-client.js +136 -0
  57. package/dist/lib/run-types.d.ts +226 -0
  58. package/dist/lib/run-types.js +5 -0
  59. package/oclif.manifest.json +1423 -306
  60. package/package.json +1 -1
  61. package/dist/commands/ephemeral/run/job/index.js +0 -311
  62. package/dist/commands/ephemeral/run/service/index.js +0 -287
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Base command for all run commands
3
+ */
4
+ import * as fs from 'node:fs';
5
+ import * as os from 'node:os';
6
+ import * as path from 'node:path';
7
+ import * as yaml from 'js-yaml';
8
+ import BaseCommand from '../base-command.js';
9
+ import { DEFAULT_RUN_BASE_URL, RunHttpClient } from './run-http-client.js';
10
+ export default class BaseRunCommand extends BaseCommand {
11
+ httpClient;
12
+ profile;
13
+ profileName;
14
+ /**
15
+ * Initialize the run command with profile and HTTP client
16
+ */
17
+ async initRunCommand(profileFlag) {
18
+ this.profileName = profileFlag || this.getDefaultProfile();
19
+ const credentials = this.loadCredentials();
20
+ if (!(this.profileName in credentials.profiles)) {
21
+ this.error(`Profile '${this.profileName}' not found. Available profiles: ${Object.keys(credentials.profiles).join(', ')}\n` +
22
+ `Create a profile using 'xano profile:create'`);
23
+ }
24
+ this.profile = credentials.profiles[this.profileName];
25
+ if (!this.profile.access_token) {
26
+ this.error(`Profile '${this.profileName}' is missing access_token`);
27
+ }
28
+ const baseUrl = this.profile.run_base_url || DEFAULT_RUN_BASE_URL;
29
+ this.httpClient = new RunHttpClient({
30
+ baseUrl,
31
+ authToken: this.profile.access_token,
32
+ projectId: this.profile.project,
33
+ });
34
+ }
35
+ /**
36
+ * Initialize with project required
37
+ */
38
+ async initRunCommandWithProject(profileFlag) {
39
+ await this.initRunCommand(profileFlag);
40
+ if (!this.profile.project) {
41
+ this.error(`Profile '${this.profileName}' is missing project. ` +
42
+ `Update your profile with 'xano profile:edit --project <project-id>'`);
43
+ }
44
+ }
45
+ /**
46
+ * Load credentials from file
47
+ */
48
+ loadCredentials() {
49
+ const configDir = path.join(os.homedir(), '.xano');
50
+ const credentialsPath = path.join(configDir, 'credentials.yaml');
51
+ if (!fs.existsSync(credentialsPath)) {
52
+ this.error(`Credentials file not found at ${credentialsPath}\n` +
53
+ `Create a profile using 'xano profile:create'`);
54
+ }
55
+ try {
56
+ const fileContent = fs.readFileSync(credentialsPath, 'utf8');
57
+ const parsed = yaml.load(fileContent);
58
+ if (!parsed || typeof parsed !== 'object' || !('profiles' in parsed)) {
59
+ this.error('Credentials file has invalid format.');
60
+ }
61
+ return parsed;
62
+ }
63
+ catch (error) {
64
+ this.error(`Failed to parse credentials file: ${error}`);
65
+ }
66
+ }
67
+ /**
68
+ * Format a response for JSON output
69
+ */
70
+ outputJson(data) {
71
+ this.log(JSON.stringify(data, null, 2));
72
+ }
73
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * HTTP client for Xano Run API
3
+ * Based on @xano/run-sdk HttpClient
4
+ */
5
+ export declare const DEFAULT_RUN_BASE_URL = "https://app.xano.com/";
6
+ export interface RunHttpClientConfig {
7
+ baseUrl: string;
8
+ authToken: string;
9
+ projectId?: string;
10
+ }
11
+ export declare class RunHttpClient {
12
+ private readonly config;
13
+ constructor(config: RunHttpClientConfig);
14
+ /**
15
+ * Get the project ID
16
+ */
17
+ getProjectId(): string | undefined;
18
+ /**
19
+ * Build headers for a request
20
+ */
21
+ getHeaders(contentType?: string): HeadersInit;
22
+ /**
23
+ * Build a URL with optional query parameters
24
+ */
25
+ buildUrl(path: string, queryParams?: Record<string, unknown>): string;
26
+ /**
27
+ * Build a URL scoped to the current project
28
+ */
29
+ buildProjectUrl(path: string, queryParams?: Record<string, unknown>): string;
30
+ /**
31
+ * Build a URL scoped to a specific session
32
+ */
33
+ buildSessionUrl(sessionId: string, path?: string, queryParams?: Record<string, unknown>): string;
34
+ /**
35
+ * Make an HTTP request
36
+ */
37
+ request<T>(url: string, options: RequestInit): Promise<T>;
38
+ /**
39
+ * Make a GET request
40
+ */
41
+ get<T>(url: string): Promise<T>;
42
+ /**
43
+ * Make a POST request with JSON body
44
+ */
45
+ post<T>(url: string, body?: unknown): Promise<T>;
46
+ /**
47
+ * Make a POST request with XanoScript body
48
+ */
49
+ postXanoScript<T>(url: string, code: string): Promise<T>;
50
+ /**
51
+ * Make a PATCH request
52
+ */
53
+ patch<T>(url: string, body: unknown): Promise<T>;
54
+ /**
55
+ * Make a DELETE request
56
+ */
57
+ delete<T>(url: string, body?: unknown): Promise<T>;
58
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * HTTP client for Xano Run API
3
+ * Based on @xano/run-sdk HttpClient
4
+ */
5
+ export const DEFAULT_RUN_BASE_URL = 'https://app.xano.com/';
6
+ export class RunHttpClient {
7
+ config;
8
+ constructor(config) {
9
+ this.config = config;
10
+ }
11
+ /**
12
+ * Get the project ID
13
+ */
14
+ getProjectId() {
15
+ return this.config.projectId;
16
+ }
17
+ /**
18
+ * Build headers for a request
19
+ */
20
+ getHeaders(contentType = 'application/json') {
21
+ const headers = {
22
+ 'Content-Type': contentType,
23
+ 'Authorization': `Bearer ${this.config.authToken}`,
24
+ };
25
+ return headers;
26
+ }
27
+ /**
28
+ * Build a URL with optional query parameters
29
+ */
30
+ buildUrl(path, queryParams) {
31
+ const baseUrl = this.config.baseUrl.endsWith('/')
32
+ ? this.config.baseUrl.slice(0, -1)
33
+ : this.config.baseUrl;
34
+ const url = new URL(`${baseUrl}/api:run${path}`);
35
+ if (queryParams) {
36
+ for (const [key, value] of Object.entries(queryParams)) {
37
+ if (value !== undefined && value !== null) {
38
+ if (typeof value === 'object') {
39
+ url.searchParams.set(key, JSON.stringify(value));
40
+ }
41
+ else {
42
+ url.searchParams.set(key, String(value));
43
+ }
44
+ }
45
+ }
46
+ }
47
+ return url.toString();
48
+ }
49
+ /**
50
+ * Build a URL scoped to the current project
51
+ */
52
+ buildProjectUrl(path, queryParams) {
53
+ const projectId = this.config.projectId;
54
+ if (!projectId) {
55
+ throw new Error('Project ID is required. Set it in your profile.');
56
+ }
57
+ return this.buildUrl(`/project/${projectId}${path}`, queryParams);
58
+ }
59
+ /**
60
+ * Build a URL scoped to a specific session
61
+ */
62
+ buildSessionUrl(sessionId, path = '', queryParams) {
63
+ return this.buildUrl(`/session/${sessionId}${path}`, queryParams);
64
+ }
65
+ /**
66
+ * Make an HTTP request
67
+ */
68
+ async request(url, options) {
69
+ const response = await fetch(url, options);
70
+ if (!response.ok) {
71
+ const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
72
+ error.status = response.status;
73
+ try {
74
+ error.response = await response.json();
75
+ }
76
+ catch {
77
+ error.response = await response.text();
78
+ }
79
+ throw error;
80
+ }
81
+ const text = await response.text();
82
+ if (!text) {
83
+ return undefined;
84
+ }
85
+ return JSON.parse(text);
86
+ }
87
+ /**
88
+ * Make a GET request
89
+ */
90
+ async get(url) {
91
+ return this.request(url, {
92
+ method: 'GET',
93
+ headers: this.getHeaders(),
94
+ });
95
+ }
96
+ /**
97
+ * Make a POST request with JSON body
98
+ */
99
+ async post(url, body) {
100
+ return this.request(url, {
101
+ method: 'POST',
102
+ headers: this.getHeaders(),
103
+ body: body ? JSON.stringify(body) : undefined,
104
+ });
105
+ }
106
+ /**
107
+ * Make a POST request with XanoScript body
108
+ */
109
+ async postXanoScript(url, code) {
110
+ return this.request(url, {
111
+ method: 'POST',
112
+ headers: this.getHeaders('text/x-xanoscript'),
113
+ body: code,
114
+ });
115
+ }
116
+ /**
117
+ * Make a PATCH request
118
+ */
119
+ async patch(url, body) {
120
+ return this.request(url, {
121
+ method: 'PATCH',
122
+ headers: this.getHeaders(),
123
+ body: JSON.stringify(body),
124
+ });
125
+ }
126
+ /**
127
+ * Make a DELETE request
128
+ */
129
+ async delete(url, body) {
130
+ return this.request(url, {
131
+ method: 'DELETE',
132
+ headers: this.getHeaders(),
133
+ body: body ? JSON.stringify(body) : undefined,
134
+ });
135
+ }
136
+ }
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Types for Xano Run API
3
+ * Based on @xano/run-sdk types
4
+ */
5
+ export interface PaginatedResponse<T> {
6
+ items: T[];
7
+ itemsReceived?: number;
8
+ curPage?: number;
9
+ nextPage?: number | null;
10
+ prevPage?: number | null;
11
+ offset?: number;
12
+ perPage?: number;
13
+ itemsTotal?: number;
14
+ pageTotal?: number;
15
+ }
16
+ export interface XanoRunError extends Error {
17
+ status?: number;
18
+ response?: unknown;
19
+ }
20
+ export interface Project {
21
+ id: string;
22
+ created_at: string;
23
+ name: string;
24
+ description: string;
25
+ user_id: number;
26
+ access: 'private' | 'public';
27
+ }
28
+ export interface CreateProjectInput {
29
+ name: string;
30
+ description: string;
31
+ }
32
+ export interface UpdateProjectInput {
33
+ name?: string;
34
+ description?: string;
35
+ }
36
+ export interface EnvKeysResponse {
37
+ env: string[];
38
+ }
39
+ export interface EnvValueResponse {
40
+ name: string;
41
+ value: string;
42
+ }
43
+ export interface UpdateEnvInput {
44
+ name: string;
45
+ env: {
46
+ name: string;
47
+ value: string;
48
+ };
49
+ }
50
+ export type SecretType = 'kubernetes.io/dockerconfigjson' | 'kubernetes.io/service-account-token';
51
+ export interface SecretMetadata {
52
+ name: string;
53
+ type: SecretType;
54
+ repo?: string;
55
+ }
56
+ export interface SecretKeysResponse {
57
+ secrets: SecretMetadata[];
58
+ }
59
+ export interface SecretValueResponse {
60
+ name: string;
61
+ type: SecretType;
62
+ repo?: string;
63
+ value: string;
64
+ }
65
+ export interface UpdateSecretInput {
66
+ name: string;
67
+ secret: {
68
+ name: string;
69
+ type: SecretType;
70
+ value: string;
71
+ repo?: string;
72
+ };
73
+ }
74
+ export type RunType = 'job' | 'service';
75
+ export interface RunOptions {
76
+ args?: Record<string, unknown>;
77
+ env?: Record<string, string>;
78
+ }
79
+ export interface RunBackup {
80
+ resource: string;
81
+ size: number;
82
+ }
83
+ export interface RunDefinition {
84
+ id: string;
85
+ created_at: string;
86
+ updated_at: string;
87
+ name: string;
88
+ user_id: number;
89
+ project_id: string;
90
+ sig: string;
91
+ type: RunType;
92
+ args: unknown[] | Record<string, unknown>;
93
+ doc: string;
94
+ }
95
+ export interface SessionExecution {
96
+ id: string;
97
+ created_at: string;
98
+ updated_at: string;
99
+ run_id: string;
100
+ batch_id: string | null;
101
+ state: 'complete' | 'error' | string;
102
+ error_msg: string;
103
+ response: unknown;
104
+ label: string;
105
+ boot_time: number;
106
+ pre_time: number;
107
+ main_time: number;
108
+ post_time: number;
109
+ total_time: number;
110
+ tenant_id: number;
111
+ access: string;
112
+ backup: RunBackup;
113
+ _run: RunDefinition;
114
+ }
115
+ export interface EndpointInput {
116
+ source: string;
117
+ name: string;
118
+ type: string;
119
+ nullable: boolean;
120
+ default: string;
121
+ required: boolean;
122
+ }
123
+ export interface Endpoint {
124
+ url: string;
125
+ verb: string;
126
+ input: EndpointInput[];
127
+ }
128
+ export interface MetadataApi {
129
+ url: string;
130
+ }
131
+ export interface RunResult {
132
+ run?: {
133
+ id?: string | number;
134
+ session?: SessionExecution;
135
+ result?: {
136
+ response?: unknown;
137
+ boot_time?: number;
138
+ main_time?: number;
139
+ pre_time?: number;
140
+ post_time?: number;
141
+ total_time?: number;
142
+ };
143
+ debug?: string[];
144
+ problems?: Array<{
145
+ message?: string;
146
+ severity?: string;
147
+ }>;
148
+ };
149
+ service?: {
150
+ id: number;
151
+ run: {
152
+ id: number;
153
+ };
154
+ };
155
+ logs?: unknown[];
156
+ result?: {
157
+ state?: 'complete';
158
+ response?: unknown;
159
+ boot_time?: number;
160
+ pre_time?: number;
161
+ main_time?: number;
162
+ post_time?: number;
163
+ total_time?: number;
164
+ pre_result?: unknown;
165
+ endpoints?: Endpoint[];
166
+ metadata_api?: MetadataApi;
167
+ };
168
+ }
169
+ export interface DocInfoResult {
170
+ type: RunType;
171
+ input?: Record<string, unknown>;
172
+ env?: string[];
173
+ }
174
+ export type SessionStatus = 'running' | 'stopped' | 'error';
175
+ export interface Session {
176
+ id: string;
177
+ created_at: string;
178
+ updated_at: string;
179
+ project_id: string;
180
+ state: string;
181
+ }
182
+ export interface SessionDetail {
183
+ id: string;
184
+ name: string;
185
+ status: SessionStatus;
186
+ uptime: number | null;
187
+ url?: string;
188
+ doc: string;
189
+ createdAt: string;
190
+ access: 'private' | 'public';
191
+ projectId: string | null;
192
+ backupResource: string | null;
193
+ }
194
+ export interface UpdateSessionInput {
195
+ name?: string;
196
+ access?: 'private' | 'public';
197
+ }
198
+ export interface TableColumn {
199
+ name: string;
200
+ type: string;
201
+ description?: string;
202
+ isPrimaryKey: boolean;
203
+ }
204
+ export interface RunLogEntry {
205
+ id: number;
206
+ created_at: string;
207
+ log_type: string;
208
+ duration: number;
209
+ function_name?: string;
210
+ error_msg: string;
211
+ log_object: object;
212
+ output?: string | Record<string, unknown>;
213
+ input?: unknown[];
214
+ stack?: unknown[];
215
+ value_store?: Record<string, unknown>;
216
+ }
217
+ export interface SinkTable {
218
+ guid: string;
219
+ name: string;
220
+ columns: TableColumn[];
221
+ content: Record<string, unknown>[];
222
+ }
223
+ export interface SinkData {
224
+ tables: SinkTable[];
225
+ logs: RunLogEntry[];
226
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Types for Xano Run API
3
+ * Based on @xano/run-sdk types
4
+ */
5
+ export {};