@xano/cli 0.0.31 → 0.0.32

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 (72) hide show
  1. package/dist/base-command.d.ts +5 -0
  2. package/dist/base-command.js +32 -1
  3. package/dist/commands/branch/create/index.js +3 -3
  4. package/dist/commands/branch/delete/index.js +2 -2
  5. package/dist/commands/branch/edit/index.js +3 -3
  6. package/dist/commands/branch/get/index.js +2 -2
  7. package/dist/commands/branch/list/index.js +2 -2
  8. package/dist/commands/branch/set-live/index.js +2 -2
  9. package/dist/commands/function/create/index.js +2 -2
  10. package/dist/commands/function/edit/index.js +2 -2
  11. package/dist/commands/function/get/index.js +2 -2
  12. package/dist/commands/function/list/index.js +2 -2
  13. package/dist/commands/platform/get/index.d.ts +18 -0
  14. package/dist/commands/platform/get/index.js +126 -0
  15. package/dist/commands/platform/list/index.d.ts +12 -0
  16. package/dist/commands/platform/list/index.js +113 -0
  17. package/dist/commands/profile/me/index.js +2 -2
  18. package/dist/commands/release/create/index.d.ts +18 -0
  19. package/dist/commands/release/create/index.js +138 -0
  20. package/dist/commands/release/delete/index.d.ts +21 -0
  21. package/dist/commands/release/delete/index.js +134 -0
  22. package/dist/commands/release/edit/index.d.ts +21 -0
  23. package/dist/commands/release/edit/index.js +137 -0
  24. package/dist/commands/release/export/index.d.ts +20 -0
  25. package/dist/commands/release/export/index.js +142 -0
  26. package/dist/commands/release/get/index.d.ts +19 -0
  27. package/dist/commands/release/get/index.js +123 -0
  28. package/dist/commands/release/import/index.d.ts +15 -0
  29. package/dist/commands/release/import/index.js +114 -0
  30. package/dist/commands/release/list/index.d.ts +13 -0
  31. package/dist/commands/release/list/index.js +120 -0
  32. package/dist/commands/static_host/build/create/index.js +2 -2
  33. package/dist/commands/static_host/build/get/index.js +2 -2
  34. package/dist/commands/static_host/build/list/index.js +2 -2
  35. package/dist/commands/static_host/list/index.js +2 -2
  36. package/dist/commands/tenant/backup/create/index.d.ts +20 -0
  37. package/dist/commands/tenant/backup/create/index.js +113 -0
  38. package/dist/commands/tenant/backup/delete/index.d.ts +22 -0
  39. package/dist/commands/tenant/backup/delete/index.js +137 -0
  40. package/dist/commands/tenant/backup/export/index.d.ts +21 -0
  41. package/dist/commands/tenant/backup/export/index.js +147 -0
  42. package/dist/commands/tenant/backup/import/index.d.ts +21 -0
  43. package/dist/commands/tenant/backup/import/index.js +127 -0
  44. package/dist/commands/tenant/backup/list/index.d.ts +20 -0
  45. package/dist/commands/tenant/backup/list/index.js +137 -0
  46. package/dist/commands/tenant/backup/restore/index.d.ts +22 -0
  47. package/dist/commands/tenant/backup/restore/index.js +141 -0
  48. package/dist/commands/tenant/create/index.d.ts +21 -0
  49. package/dist/commands/tenant/create/index.js +155 -0
  50. package/dist/commands/tenant/delete/index.d.ts +21 -0
  51. package/dist/commands/tenant/delete/index.js +134 -0
  52. package/dist/commands/tenant/deploy-platform/index.d.ts +20 -0
  53. package/dist/commands/tenant/deploy-platform/index.js +116 -0
  54. package/dist/commands/tenant/deploy-release/index.d.ts +20 -0
  55. package/dist/commands/tenant/deploy-release/index.js +116 -0
  56. package/dist/commands/tenant/edit/index.d.ts +26 -0
  57. package/dist/commands/tenant/edit/index.js +167 -0
  58. package/dist/commands/tenant/get/index.d.ts +19 -0
  59. package/dist/commands/tenant/get/index.js +135 -0
  60. package/dist/commands/tenant/list/index.d.ts +13 -0
  61. package/dist/commands/tenant/list/index.js +123 -0
  62. package/dist/commands/workspace/create/index.js +3 -3
  63. package/dist/commands/workspace/delete/index.js +2 -2
  64. package/dist/commands/workspace/edit/index.js +3 -3
  65. package/dist/commands/workspace/get/index.js +2 -2
  66. package/dist/commands/workspace/list/index.js +2 -2
  67. package/dist/commands/workspace/pull/index.d.ts +1 -0
  68. package/dist/commands/workspace/pull/index.js +45 -10
  69. package/dist/commands/workspace/push/index.d.ts +3 -0
  70. package/dist/commands/workspace/push/index.js +41 -8
  71. package/oclif.manifest.json +3213 -1256
  72. package/package.json +10 -1
@@ -0,0 +1,138 @@
1
+ import { Flags } from '@oclif/core';
2
+ import * as yaml from 'js-yaml';
3
+ import * as fs from 'node:fs';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import BaseCommand from '../../../base-command.js';
7
+ export default class ReleaseCreate extends BaseCommand {
8
+ static description = 'Create a new release in a workspace';
9
+ static examples = [
10
+ `$ xano release create --name "v1.0" --branch main
11
+ Created release: v1.0 - ID: 10
12
+ `,
13
+ `$ xano release create --name "v1.1-hotfix" --branch main --hotfix --description "Critical fix" -o json`,
14
+ ];
15
+ static flags = {
16
+ ...BaseCommand.baseFlags,
17
+ branch: Flags.string({
18
+ char: 'b',
19
+ description: 'Branch to create the release from',
20
+ required: true,
21
+ }),
22
+ description: Flags.string({
23
+ char: 'd',
24
+ description: 'Release description',
25
+ required: false,
26
+ }),
27
+ hotfix: Flags.boolean({
28
+ default: false,
29
+ description: 'Mark as a hotfix release',
30
+ required: false,
31
+ }),
32
+ name: Flags.string({
33
+ char: 'n',
34
+ description: 'Name for the release',
35
+ required: true,
36
+ }),
37
+ output: Flags.string({
38
+ char: 'o',
39
+ default: 'summary',
40
+ description: 'Output format',
41
+ options: ['summary', 'json'],
42
+ required: false,
43
+ }),
44
+ 'table-ids': Flags.string({
45
+ description: 'Comma-separated table IDs to include',
46
+ required: false,
47
+ }),
48
+ workspace: Flags.string({
49
+ char: 'w',
50
+ description: 'Workspace ID (uses profile workspace if not provided)',
51
+ required: false,
52
+ }),
53
+ };
54
+ async run() {
55
+ const { flags } = await this.parse(ReleaseCreate);
56
+ const profileName = flags.profile || this.getDefaultProfile();
57
+ const credentials = this.loadCredentials();
58
+ if (!(profileName in credentials.profiles)) {
59
+ this.error(`Profile '${profileName}' not found. Available profiles: ${Object.keys(credentials.profiles).join(', ')}\n` +
60
+ `Create a profile using 'xano profile create'`);
61
+ }
62
+ const profile = credentials.profiles[profileName];
63
+ if (!profile.instance_origin) {
64
+ this.error(`Profile '${profileName}' is missing instance_origin`);
65
+ }
66
+ if (!profile.access_token) {
67
+ this.error(`Profile '${profileName}' is missing access_token`);
68
+ }
69
+ const workspaceId = flags.workspace || profile.workspace;
70
+ if (!workspaceId) {
71
+ this.error('No workspace ID provided. Use --workspace flag or set one in your profile.');
72
+ }
73
+ const body = {
74
+ branch: flags.branch,
75
+ hotfix: flags.hotfix,
76
+ name: flags.name,
77
+ };
78
+ if (flags.description)
79
+ body.description = flags.description;
80
+ if (flags['table-ids']) {
81
+ body.table_ids = flags['table-ids'].split(',').map(id => Number.parseInt(id.trim(), 10));
82
+ }
83
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/release`;
84
+ try {
85
+ const response = await this.verboseFetch(apiUrl, {
86
+ body: JSON.stringify(body),
87
+ headers: {
88
+ 'accept': 'application/json',
89
+ 'Authorization': `Bearer ${profile.access_token}`,
90
+ 'Content-Type': 'application/json',
91
+ },
92
+ method: 'POST',
93
+ }, flags.verbose, profile.access_token);
94
+ if (!response.ok) {
95
+ const errorText = await response.text();
96
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
97
+ }
98
+ const release = await response.json();
99
+ if (flags.output === 'json') {
100
+ this.log(JSON.stringify(release, null, 2));
101
+ }
102
+ else {
103
+ this.log(`Created release: ${release.name} - ID: ${release.id}`);
104
+ if (release.branch)
105
+ this.log(` Branch: ${release.branch}`);
106
+ if (release.hotfix)
107
+ this.log(` Hotfix: true`);
108
+ }
109
+ }
110
+ catch (error) {
111
+ if (error instanceof Error) {
112
+ this.error(`Failed to create release: ${error.message}`);
113
+ }
114
+ else {
115
+ this.error(`Failed to create release: ${String(error)}`);
116
+ }
117
+ }
118
+ }
119
+ loadCredentials() {
120
+ const configDir = path.join(os.homedir(), '.xano');
121
+ const credentialsPath = path.join(configDir, 'credentials.yaml');
122
+ if (!fs.existsSync(credentialsPath)) {
123
+ this.error(`Credentials file not found at ${credentialsPath}\n` +
124
+ `Create a profile using 'xano profile create'`);
125
+ }
126
+ try {
127
+ const fileContent = fs.readFileSync(credentialsPath, 'utf8');
128
+ const parsed = yaml.load(fileContent);
129
+ if (!parsed || typeof parsed !== 'object' || !('profiles' in parsed)) {
130
+ this.error('Credentials file has invalid format.');
131
+ }
132
+ return parsed;
133
+ }
134
+ catch (error) {
135
+ this.error(`Failed to parse credentials file: ${error}`);
136
+ }
137
+ }
138
+ }
@@ -0,0 +1,21 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class ReleaseDelete extends BaseCommand {
3
+ static args: {
4
+ release_id: import("@oclif/core/interfaces").Arg<number, {
5
+ max?: number;
6
+ min?: number;
7
+ }>;
8
+ };
9
+ static description: string;
10
+ static examples: string[];
11
+ static flags: {
12
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
14
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
+ };
18
+ run(): Promise<void>;
19
+ private confirm;
20
+ private loadCredentials;
21
+ }
@@ -0,0 +1,134 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import * as yaml from 'js-yaml';
3
+ import * as fs from 'node:fs';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import BaseCommand from '../../../base-command.js';
7
+ export default class ReleaseDelete extends BaseCommand {
8
+ static args = {
9
+ release_id: Args.integer({
10
+ description: 'Release ID to delete',
11
+ required: true,
12
+ }),
13
+ };
14
+ static description = 'Delete a release permanently. This action cannot be undone.';
15
+ static examples = [
16
+ `$ xano release delete 10
17
+ Are you sure you want to delete release #10? This action cannot be undone. (y/N) y
18
+ Deleted release #10
19
+ `,
20
+ `$ xano release delete 10 --force
21
+ Deleted release #10
22
+ `,
23
+ `$ xano release delete 10 -f -o json`,
24
+ ];
25
+ static flags = {
26
+ ...BaseCommand.baseFlags,
27
+ force: Flags.boolean({
28
+ char: 'f',
29
+ default: false,
30
+ description: 'Skip confirmation prompt',
31
+ required: false,
32
+ }),
33
+ output: Flags.string({
34
+ char: 'o',
35
+ default: 'summary',
36
+ description: 'Output format',
37
+ options: ['summary', 'json'],
38
+ required: false,
39
+ }),
40
+ workspace: Flags.string({
41
+ char: 'w',
42
+ description: 'Workspace ID (uses profile workspace if not provided)',
43
+ required: false,
44
+ }),
45
+ };
46
+ async run() {
47
+ const { args, flags } = await this.parse(ReleaseDelete);
48
+ const profileName = flags.profile || this.getDefaultProfile();
49
+ const credentials = this.loadCredentials();
50
+ if (!(profileName in credentials.profiles)) {
51
+ this.error(`Profile '${profileName}' not found. Available profiles: ${Object.keys(credentials.profiles).join(', ')}\n` +
52
+ `Create a profile using 'xano profile create'`);
53
+ }
54
+ const profile = credentials.profiles[profileName];
55
+ if (!profile.instance_origin) {
56
+ this.error(`Profile '${profileName}' is missing instance_origin`);
57
+ }
58
+ if (!profile.access_token) {
59
+ this.error(`Profile '${profileName}' is missing access_token`);
60
+ }
61
+ const workspaceId = flags.workspace || profile.workspace;
62
+ if (!workspaceId) {
63
+ this.error('No workspace ID provided. Use --workspace flag or set one in your profile.');
64
+ }
65
+ const releaseId = args.release_id;
66
+ if (!flags.force) {
67
+ const confirmed = await this.confirm(`Are you sure you want to delete release #${releaseId}? This action cannot be undone.`);
68
+ if (!confirmed) {
69
+ this.log('Deletion cancelled.');
70
+ return;
71
+ }
72
+ }
73
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/release/${releaseId}`;
74
+ try {
75
+ const response = await this.verboseFetch(apiUrl, {
76
+ headers: {
77
+ 'accept': 'application/json',
78
+ 'Authorization': `Bearer ${profile.access_token}`,
79
+ },
80
+ method: 'DELETE',
81
+ }, flags.verbose, profile.access_token);
82
+ if (!response.ok) {
83
+ const errorText = await response.text();
84
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
85
+ }
86
+ if (flags.output === 'json') {
87
+ this.log(JSON.stringify({ deleted: true, release_id: releaseId }, null, 2));
88
+ }
89
+ else {
90
+ this.log(`Deleted release #${releaseId}`);
91
+ }
92
+ }
93
+ catch (error) {
94
+ if (error instanceof Error) {
95
+ this.error(`Failed to delete release: ${error.message}`);
96
+ }
97
+ else {
98
+ this.error(`Failed to delete release: ${String(error)}`);
99
+ }
100
+ }
101
+ }
102
+ async confirm(message) {
103
+ const readline = await import('node:readline');
104
+ const rl = readline.createInterface({
105
+ input: process.stdin,
106
+ output: process.stdout,
107
+ });
108
+ return new Promise((resolve) => {
109
+ rl.question(`${message} (y/N) `, (answer) => {
110
+ rl.close();
111
+ resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
112
+ });
113
+ });
114
+ }
115
+ loadCredentials() {
116
+ const configDir = path.join(os.homedir(), '.xano');
117
+ const credentialsPath = path.join(configDir, 'credentials.yaml');
118
+ if (!fs.existsSync(credentialsPath)) {
119
+ this.error(`Credentials file not found at ${credentialsPath}\n` +
120
+ `Create a profile using 'xano profile create'`);
121
+ }
122
+ try {
123
+ const fileContent = fs.readFileSync(credentialsPath, 'utf8');
124
+ const parsed = yaml.load(fileContent);
125
+ if (!parsed || typeof parsed !== 'object' || !('profiles' in parsed)) {
126
+ this.error('Credentials file has invalid format.');
127
+ }
128
+ return parsed;
129
+ }
130
+ catch (error) {
131
+ this.error(`Failed to parse credentials file: ${error}`);
132
+ }
133
+ }
134
+ }
@@ -0,0 +1,21 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class ReleaseEdit extends BaseCommand {
3
+ static args: {
4
+ release_id: import("@oclif/core/interfaces").Arg<number, {
5
+ max?: number;
6
+ min?: number;
7
+ }>;
8
+ };
9
+ static description: string;
10
+ static examples: string[];
11
+ static flags: {
12
+ description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ name: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
15
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
+ };
19
+ run(): Promise<void>;
20
+ private loadCredentials;
21
+ }
@@ -0,0 +1,137 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import * as yaml from 'js-yaml';
3
+ import * as fs from 'node:fs';
4
+ import * as os from 'node:os';
5
+ import * as path from 'node:path';
6
+ import BaseCommand from '../../../base-command.js';
7
+ export default class ReleaseEdit extends BaseCommand {
8
+ static args = {
9
+ release_id: Args.integer({
10
+ description: 'Release ID to edit',
11
+ required: true,
12
+ }),
13
+ };
14
+ static description = 'Edit an existing release';
15
+ static examples = [
16
+ `$ xano release edit 10 --name "v1.0-final" --description "Updated description"
17
+ Updated release: v1.0-final - ID: 10
18
+ `,
19
+ `$ xano release edit 10 --description "New description" -o json`,
20
+ ];
21
+ static flags = {
22
+ ...BaseCommand.baseFlags,
23
+ description: Flags.string({
24
+ char: 'd',
25
+ description: 'New description',
26
+ required: false,
27
+ }),
28
+ name: Flags.string({
29
+ char: 'n',
30
+ description: 'New name for the release',
31
+ required: false,
32
+ }),
33
+ output: Flags.string({
34
+ char: 'o',
35
+ default: 'summary',
36
+ description: 'Output format',
37
+ options: ['summary', 'json'],
38
+ required: false,
39
+ }),
40
+ workspace: Flags.string({
41
+ char: 'w',
42
+ description: 'Workspace ID (uses profile workspace if not provided)',
43
+ required: false,
44
+ }),
45
+ };
46
+ async run() {
47
+ const { args, flags } = await this.parse(ReleaseEdit);
48
+ const profileName = flags.profile || this.getDefaultProfile();
49
+ const credentials = this.loadCredentials();
50
+ if (!(profileName in credentials.profiles)) {
51
+ this.error(`Profile '${profileName}' not found. Available profiles: ${Object.keys(credentials.profiles).join(', ')}\n` +
52
+ `Create a profile using 'xano profile create'`);
53
+ }
54
+ const profile = credentials.profiles[profileName];
55
+ if (!profile.instance_origin) {
56
+ this.error(`Profile '${profileName}' is missing instance_origin`);
57
+ }
58
+ if (!profile.access_token) {
59
+ this.error(`Profile '${profileName}' is missing access_token`);
60
+ }
61
+ const workspaceId = flags.workspace || profile.workspace;
62
+ if (!workspaceId) {
63
+ this.error('No workspace ID provided. Use --workspace flag or set one in your profile.');
64
+ }
65
+ const releaseId = args.release_id;
66
+ const baseUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/release/${releaseId}`;
67
+ const headers = {
68
+ 'accept': 'application/json',
69
+ 'Authorization': `Bearer ${profile.access_token}`,
70
+ 'Content-Type': 'application/json',
71
+ };
72
+ try {
73
+ // Fetch current release state (PUT requires all fields)
74
+ const getResponse = await this.verboseFetch(baseUrl, {
75
+ headers: {
76
+ 'accept': 'application/json',
77
+ 'Authorization': `Bearer ${profile.access_token}`,
78
+ },
79
+ method: 'GET',
80
+ }, flags.verbose, profile.access_token);
81
+ if (!getResponse.ok) {
82
+ const errorText = await getResponse.text();
83
+ this.error(`Failed to fetch release: ${getResponse.status} ${getResponse.statusText}\n${errorText}`);
84
+ }
85
+ const current = await getResponse.json();
86
+ // Merge in user-provided values
87
+ const body = {
88
+ description: flags.description !== undefined ? flags.description : (current.description ?? ''),
89
+ name: flags.name !== undefined ? flags.name : current.name,
90
+ };
91
+ // Update release
92
+ const putResponse = await this.verboseFetch(baseUrl, {
93
+ body: JSON.stringify(body),
94
+ headers,
95
+ method: 'PUT',
96
+ }, flags.verbose, profile.access_token);
97
+ if (!putResponse.ok) {
98
+ const errorText = await putResponse.text();
99
+ this.error(`API request failed with status ${putResponse.status}: ${putResponse.statusText}\n${errorText}`);
100
+ }
101
+ const release = await putResponse.json();
102
+ if (flags.output === 'json') {
103
+ this.log(JSON.stringify(release, null, 2));
104
+ }
105
+ else {
106
+ this.log(`Updated release: ${release.name} - ID: ${release.id}`);
107
+ }
108
+ }
109
+ catch (error) {
110
+ if (error instanceof Error) {
111
+ this.error(`Failed to edit release: ${error.message}`);
112
+ }
113
+ else {
114
+ this.error(`Failed to edit release: ${String(error)}`);
115
+ }
116
+ }
117
+ }
118
+ loadCredentials() {
119
+ const configDir = path.join(os.homedir(), '.xano');
120
+ const credentialsPath = path.join(configDir, 'credentials.yaml');
121
+ if (!fs.existsSync(credentialsPath)) {
122
+ this.error(`Credentials file not found at ${credentialsPath}\n` +
123
+ `Create a profile using 'xano profile create'`);
124
+ }
125
+ try {
126
+ const fileContent = fs.readFileSync(credentialsPath, 'utf8');
127
+ const parsed = yaml.load(fileContent);
128
+ if (!parsed || typeof parsed !== 'object' || !('profiles' in parsed)) {
129
+ this.error('Credentials file has invalid format.');
130
+ }
131
+ return parsed;
132
+ }
133
+ catch (error) {
134
+ this.error(`Failed to parse credentials file: ${error}`);
135
+ }
136
+ }
137
+ }
@@ -0,0 +1,20 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class ReleaseExport extends BaseCommand {
3
+ static args: {
4
+ release_id: import("@oclif/core/interfaces").Arg<number, {
5
+ max?: number;
6
+ min?: number;
7
+ }>;
8
+ };
9
+ static description: string;
10
+ static examples: string[];
11
+ static flags: {
12
+ format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
13
+ output: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
16
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
+ };
18
+ run(): Promise<void>;
19
+ private loadCredentials;
20
+ }
@@ -0,0 +1,142 @@
1
+ import { Args, 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 ReleaseExport extends BaseCommand {
8
+ static args = {
9
+ release_id: Args.integer({
10
+ description: 'Release ID to export',
11
+ required: true,
12
+ }),
13
+ };
14
+ static description = 'Export (download) a release to a local file';
15
+ static examples = [
16
+ `$ xano release export 10
17
+ Downloaded release #10 to ./release-10.tar.gz
18
+ `,
19
+ `$ xano release export 10 --output ./backups/my-release.tar.gz`,
20
+ `$ xano release export 10 -o json`,
21
+ ];
22
+ static flags = {
23
+ ...BaseCommand.baseFlags,
24
+ format: Flags.string({
25
+ char: 'o',
26
+ default: 'summary',
27
+ description: 'Output format',
28
+ options: ['summary', 'json'],
29
+ required: false,
30
+ }),
31
+ output: Flags.string({
32
+ description: 'Output file path (defaults to ./release-{id}.tar.gz)',
33
+ required: false,
34
+ }),
35
+ workspace: Flags.string({
36
+ char: 'w',
37
+ description: 'Workspace ID (uses profile workspace if not provided)',
38
+ required: false,
39
+ }),
40
+ };
41
+ async run() {
42
+ const { args, flags } = await this.parse(ReleaseExport);
43
+ const profileName = flags.profile || this.getDefaultProfile();
44
+ const credentials = this.loadCredentials();
45
+ if (!(profileName in credentials.profiles)) {
46
+ this.error(`Profile '${profileName}' not found. Available profiles: ${Object.keys(credentials.profiles).join(', ')}\n` +
47
+ `Create a profile using 'xano profile create'`);
48
+ }
49
+ const profile = credentials.profiles[profileName];
50
+ if (!profile.instance_origin) {
51
+ this.error(`Profile '${profileName}' is missing instance_origin`);
52
+ }
53
+ if (!profile.access_token) {
54
+ this.error(`Profile '${profileName}' is missing access_token`);
55
+ }
56
+ const workspaceId = flags.workspace || profile.workspace;
57
+ if (!workspaceId) {
58
+ this.error('No workspace ID provided. Use --workspace flag or set one in your profile.');
59
+ }
60
+ const releaseId = args.release_id;
61
+ // Step 1: Get signed download URL
62
+ const exportUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/release/${releaseId}/export`;
63
+ try {
64
+ const response = await this.verboseFetch(exportUrl, {
65
+ headers: {
66
+ 'accept': 'application/json',
67
+ 'Authorization': `Bearer ${profile.access_token}`,
68
+ },
69
+ method: 'GET',
70
+ }, flags.verbose, profile.access_token);
71
+ if (!response.ok) {
72
+ const errorText = await response.text();
73
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
74
+ }
75
+ const exportLink = await response.json();
76
+ if (!exportLink.src) {
77
+ this.error('API did not return a download URL');
78
+ }
79
+ // Step 2: Download the file
80
+ const outputPath = flags.output || `release-${releaseId}.tar.gz`;
81
+ const resolvedPath = path.resolve(outputPath);
82
+ const downloadResponse = await fetch(exportLink.src);
83
+ if (!downloadResponse.ok) {
84
+ this.error(`Failed to download release: ${downloadResponse.status} ${downloadResponse.statusText}`);
85
+ }
86
+ if (!downloadResponse.body) {
87
+ this.error('Download response has no body');
88
+ }
89
+ const fileStream = fs.createWriteStream(resolvedPath);
90
+ const reader = downloadResponse.body.getReader();
91
+ let totalBytes = 0;
92
+ // eslint-disable-next-line no-constant-condition
93
+ while (true) {
94
+ // eslint-disable-next-line no-await-in-loop
95
+ const { done, value } = await reader.read();
96
+ if (done)
97
+ break;
98
+ fileStream.write(value);
99
+ totalBytes += value.length;
100
+ }
101
+ fileStream.end();
102
+ await new Promise((resolve, reject) => {
103
+ fileStream.on('finish', resolve);
104
+ fileStream.on('error', reject);
105
+ });
106
+ if (flags.format === 'json') {
107
+ this.log(JSON.stringify({ bytes: totalBytes, file: resolvedPath, release_id: releaseId }, null, 2));
108
+ }
109
+ else {
110
+ const sizeMb = (totalBytes / 1024 / 1024).toFixed(2);
111
+ this.log(`Downloaded release #${releaseId} to ${resolvedPath} (${sizeMb} MB)`);
112
+ }
113
+ }
114
+ catch (error) {
115
+ if (error instanceof Error) {
116
+ this.error(`Failed to export release: ${error.message}`);
117
+ }
118
+ else {
119
+ this.error(`Failed to export release: ${String(error)}`);
120
+ }
121
+ }
122
+ }
123
+ loadCredentials() {
124
+ const configDir = path.join(os.homedir(), '.xano');
125
+ const credentialsPath = path.join(configDir, 'credentials.yaml');
126
+ if (!fs.existsSync(credentialsPath)) {
127
+ this.error(`Credentials file not found at ${credentialsPath}\n` +
128
+ `Create a profile using 'xano profile create'`);
129
+ }
130
+ try {
131
+ const fileContent = fs.readFileSync(credentialsPath, 'utf8');
132
+ const parsed = yaml.load(fileContent);
133
+ if (!parsed || typeof parsed !== 'object' || !('profiles' in parsed)) {
134
+ this.error('Credentials file has invalid format.');
135
+ }
136
+ return parsed;
137
+ }
138
+ catch (error) {
139
+ this.error(`Failed to parse credentials file: ${error}`);
140
+ }
141
+ }
142
+ }
@@ -0,0 +1,19 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class ReleaseGet extends BaseCommand {
3
+ static args: {
4
+ release_id: import("@oclif/core/interfaces").Arg<number, {
5
+ max?: number;
6
+ min?: number;
7
+ }>;
8
+ };
9
+ static description: string;
10
+ static examples: string[];
11
+ static flags: {
12
+ output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
13
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
14
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
15
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ };
17
+ run(): Promise<void>;
18
+ private loadCredentials;
19
+ }