@xano/cli 0.0.2

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 (49) hide show
  1. package/README.md +1200 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +5 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +5 -0
  6. package/dist/base-command.d.ts +11 -0
  7. package/dist/base-command.js +40 -0
  8. package/dist/commands/ephemeral/run/job/index.d.ts +19 -0
  9. package/dist/commands/ephemeral/run/job/index.js +318 -0
  10. package/dist/commands/ephemeral/run/service/index.d.ts +18 -0
  11. package/dist/commands/ephemeral/run/service/index.js +286 -0
  12. package/dist/commands/function/create/index.d.ts +18 -0
  13. package/dist/commands/function/create/index.js +280 -0
  14. package/dist/commands/function/edit/index.d.ts +24 -0
  15. package/dist/commands/function/edit/index.js +482 -0
  16. package/dist/commands/function/get/index.d.ts +18 -0
  17. package/dist/commands/function/get/index.js +279 -0
  18. package/dist/commands/function/list/index.d.ts +19 -0
  19. package/dist/commands/function/list/index.js +208 -0
  20. package/dist/commands/profile/create/index.d.ts +17 -0
  21. package/dist/commands/profile/create/index.js +123 -0
  22. package/dist/commands/profile/delete/index.d.ts +14 -0
  23. package/dist/commands/profile/delete/index.js +124 -0
  24. package/dist/commands/profile/edit/index.d.ts +18 -0
  25. package/dist/commands/profile/edit/index.js +129 -0
  26. package/dist/commands/profile/get-default/index.d.ts +6 -0
  27. package/dist/commands/profile/get-default/index.js +44 -0
  28. package/dist/commands/profile/list/index.d.ts +10 -0
  29. package/dist/commands/profile/list/index.js +115 -0
  30. package/dist/commands/profile/set-default/index.d.ts +9 -0
  31. package/dist/commands/profile/set-default/index.js +63 -0
  32. package/dist/commands/profile/wizard/index.d.ts +15 -0
  33. package/dist/commands/profile/wizard/index.js +350 -0
  34. package/dist/commands/static_host/build/create/index.d.ts +18 -0
  35. package/dist/commands/static_host/build/create/index.js +194 -0
  36. package/dist/commands/static_host/build/get/index.d.ts +16 -0
  37. package/dist/commands/static_host/build/get/index.js +165 -0
  38. package/dist/commands/static_host/build/list/index.d.ts +17 -0
  39. package/dist/commands/static_host/build/list/index.js +192 -0
  40. package/dist/commands/static_host/list/index.d.ts +15 -0
  41. package/dist/commands/static_host/list/index.js +187 -0
  42. package/dist/commands/workspace/list/index.d.ts +11 -0
  43. package/dist/commands/workspace/list/index.js +154 -0
  44. package/dist/help.d.ts +20 -0
  45. package/dist/help.js +26 -0
  46. package/dist/index.d.ts +1 -0
  47. package/dist/index.js +1 -0
  48. package/oclif.manifest.json +1370 -0
  49. package/package.json +79 -0
@@ -0,0 +1,154 @@
1
+ import { Flags } from '@oclif/core';
2
+ import * as fs from 'node:fs';
3
+ import * as os from 'node:os';
4
+ import * as path from 'node:path';
5
+ import * as yaml from 'js-yaml';
6
+ import BaseCommand from '../../../base-command.js';
7
+ export default class WorkspaceList extends BaseCommand {
8
+ static flags = {
9
+ ...BaseCommand.baseFlags,
10
+ output: Flags.string({
11
+ char: 'o',
12
+ description: 'Output format',
13
+ required: false,
14
+ default: 'summary',
15
+ options: ['summary', 'json'],
16
+ }),
17
+ };
18
+ static description = 'List all workspaces from the Xano Metadata API';
19
+ static examples = [
20
+ `$ xano workspace:list
21
+ Available workspaces:
22
+ - workspace-1 (ID: 1)
23
+ - workspace-2 (ID: 2)
24
+ - workspace-3 (ID: 3)
25
+ `,
26
+ `$ xano workspace:list --profile production
27
+ Available workspaces:
28
+ - my-app (ID: 1)
29
+ - staging-env (ID: 2)
30
+ `,
31
+ `$ xano workspace:list --output json
32
+ {
33
+ "workspaces": [
34
+ {
35
+ "id": 1,
36
+ "name": "workspace-1"
37
+ },
38
+ {
39
+ "id": 2,
40
+ "name": "workspace-2"
41
+ }
42
+ ]
43
+ }
44
+ `,
45
+ `$ xano workspace:list -p staging -o json
46
+ {
47
+ "workspaces": [
48
+ {
49
+ "id": 1,
50
+ "name": "my-app"
51
+ }
52
+ ]
53
+ }
54
+ `,
55
+ ];
56
+ async run() {
57
+ const { flags } = await this.parse(WorkspaceList);
58
+ // Get profile name (default or from flag/env)
59
+ const profileName = flags.profile || this.getDefaultProfile();
60
+ // Load credentials
61
+ const credentials = this.loadCredentials();
62
+ // Get the profile configuration
63
+ if (!(profileName in credentials.profiles)) {
64
+ this.error(`Profile '${profileName}' not found. Available profiles: ${Object.keys(credentials.profiles).join(', ')}\n` +
65
+ `Create a profile using 'xano profile:create'`);
66
+ }
67
+ const profile = credentials.profiles[profileName];
68
+ // Validate required fields
69
+ if (!profile.instance_origin) {
70
+ this.error(`Profile '${profileName}' is missing instance_origin`);
71
+ }
72
+ if (!profile.access_token) {
73
+ this.error(`Profile '${profileName}' is missing access_token`);
74
+ }
75
+ // Construct the API URL
76
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace`;
77
+ // Fetch workspaces from the API
78
+ try {
79
+ const response = await fetch(apiUrl, {
80
+ method: 'GET',
81
+ headers: {
82
+ 'accept': 'application/json',
83
+ 'Authorization': `Bearer ${profile.access_token}`,
84
+ },
85
+ });
86
+ if (!response.ok) {
87
+ const errorText = await response.text();
88
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
89
+ }
90
+ const data = await response.json();
91
+ // Handle different response formats
92
+ let workspaces;
93
+ if (Array.isArray(data)) {
94
+ workspaces = data;
95
+ }
96
+ else if (data && typeof data === 'object' && 'workspaces' in data && Array.isArray(data.workspaces)) {
97
+ workspaces = data.workspaces;
98
+ }
99
+ else {
100
+ this.error('Unexpected API response format');
101
+ }
102
+ // Output results
103
+ if (flags.output === 'json') {
104
+ this.log(JSON.stringify(workspaces, null, 2));
105
+ }
106
+ else {
107
+ // summary format
108
+ if (workspaces.length === 0) {
109
+ this.log('No workspaces found');
110
+ }
111
+ else {
112
+ this.log('Available workspaces:');
113
+ for (const workspace of workspaces) {
114
+ if (workspace.id !== undefined) {
115
+ this.log(` - ${workspace.name} (ID: ${workspace.id})`);
116
+ }
117
+ else {
118
+ this.log(` - ${workspace.name}`);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ catch (error) {
125
+ if (error instanceof Error) {
126
+ this.error(`Failed to fetch workspaces: ${error.message}`);
127
+ }
128
+ else {
129
+ this.error(`Failed to fetch workspaces: ${String(error)}`);
130
+ }
131
+ }
132
+ }
133
+ loadCredentials() {
134
+ const configDir = path.join(os.homedir(), '.xano');
135
+ const credentialsPath = path.join(configDir, 'credentials.yaml');
136
+ // Check if credentials file exists
137
+ if (!fs.existsSync(credentialsPath)) {
138
+ this.error(`Credentials file not found at ${credentialsPath}\n` +
139
+ `Create a profile using 'xano profile:create'`);
140
+ }
141
+ // Read credentials file
142
+ try {
143
+ const fileContent = fs.readFileSync(credentialsPath, 'utf8');
144
+ const parsed = yaml.load(fileContent);
145
+ if (!parsed || typeof parsed !== 'object' || !('profiles' in parsed)) {
146
+ this.error('Credentials file has invalid format.');
147
+ }
148
+ return parsed;
149
+ }
150
+ catch (error) {
151
+ this.error(`Failed to parse credentials file: ${error}`);
152
+ }
153
+ }
154
+ }
package/dist/help.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { Command, Help as BaseHelp } from '@oclif/core';
2
+ import { CommandHelp as BaseCommandHelp } from '@oclif/core/help';
3
+ /**
4
+ * Custom CommandHelp class that extends the default to display environment variables
5
+ * alongside flag descriptions
6
+ */
7
+ declare class CustomCommandHelp extends BaseCommandHelp {
8
+ /**
9
+ * Override flagHelpLabel to include environment variable information
10
+ * when a flag has an associated env variable configured
11
+ */
12
+ protected flagHelpLabel(flag: Command.Flag.Any, showOptions?: boolean): string;
13
+ }
14
+ /**
15
+ * Custom Help class that uses CustomCommandHelp
16
+ */
17
+ export default class Help extends BaseHelp {
18
+ protected CommandHelpClass: typeof CustomCommandHelp;
19
+ }
20
+ export {};
package/dist/help.js ADDED
@@ -0,0 +1,26 @@
1
+ import { Help as BaseHelp } from '@oclif/core';
2
+ import { CommandHelp as BaseCommandHelp } from '@oclif/core/help';
3
+ /**
4
+ * Custom CommandHelp class that extends the default to display environment variables
5
+ * alongside flag descriptions
6
+ */
7
+ class CustomCommandHelp extends BaseCommandHelp {
8
+ /**
9
+ * Override flagHelpLabel to include environment variable information
10
+ * when a flag has an associated env variable configured
11
+ */
12
+ flagHelpLabel(flag, showOptions = false) {
13
+ const label = super.flagHelpLabel(flag, showOptions);
14
+ // Add environment variable information if present
15
+ if (flag.env) {
16
+ return `${label.trimEnd()} [env: ${flag.env}]`;
17
+ }
18
+ return label;
19
+ }
20
+ }
21
+ /**
22
+ * Custom Help class that uses CustomCommandHelp
23
+ */
24
+ export default class Help extends BaseHelp {
25
+ CommandHelpClass = CustomCommandHelp;
26
+ }
@@ -0,0 +1 @@
1
+ export { run } from '@oclif/core';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { run } from '@oclif/core';