@xano/cli 1.0.6-beta.0 → 1.0.6-beta.1

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 (29) hide show
  1. package/README.md +28 -3
  2. package/dist/base-command.d.ts +2 -0
  3. package/dist/base-command.js +10 -4
  4. package/dist/commands/ephemeral/pull/index.d.ts +3 -1
  5. package/dist/commands/ephemeral/pull/index.js +15 -14
  6. package/dist/commands/ephemeral/push/index.d.ts +3 -1
  7. package/dist/commands/ephemeral/push/index.js +17 -16
  8. package/dist/commands/ephemeral/static_host/build/delete/index.d.ts +20 -0
  9. package/dist/commands/ephemeral/static_host/build/delete/index.js +121 -0
  10. package/dist/commands/ephemeral/static_host/build/get/index.d.ts +18 -0
  11. package/dist/commands/ephemeral/static_host/build/get/index.js +137 -0
  12. package/dist/commands/ephemeral/static_host/build/list/index.d.ts +19 -0
  13. package/dist/commands/ephemeral/static_host/build/list/index.js +158 -0
  14. package/dist/commands/ephemeral/static_host/build/pull/index.d.ts +53 -0
  15. package/dist/commands/ephemeral/static_host/build/pull/index.js +308 -0
  16. package/dist/commands/ephemeral/static_host/build/push/index.d.ts +24 -0
  17. package/dist/commands/ephemeral/static_host/build/push/index.js +250 -0
  18. package/dist/commands/ephemeral/static_host/create/index.d.ts +18 -0
  19. package/dist/commands/ephemeral/static_host/create/index.js +92 -0
  20. package/dist/commands/ephemeral/static_host/deploy/index.d.ts +19 -0
  21. package/dist/commands/ephemeral/static_host/deploy/index.js +112 -0
  22. package/dist/commands/ephemeral/static_host/edit/index.d.ts +24 -0
  23. package/dist/commands/ephemeral/static_host/edit/index.js +158 -0
  24. package/dist/commands/ephemeral/static_host/get/index.d.ts +19 -0
  25. package/dist/commands/ephemeral/static_host/get/index.js +101 -0
  26. package/dist/commands/ephemeral/static_host/list/index.d.ts +18 -0
  27. package/dist/commands/ephemeral/static_host/list/index.js +152 -0
  28. package/oclif.manifest.json +3932 -2741
  29. package/package.json +7 -1
@@ -0,0 +1,250 @@
1
+ import { Args, Flags, ux } from '@oclif/core';
2
+ import archiver from 'archiver';
3
+ import * as fs from 'node:fs';
4
+ import * as path from 'node:path';
5
+ import BaseCommand from '../../../../../base-command.js';
6
+ import { collectStaticHostFiles } from '../../../../../utils/static-host-files.js';
7
+ const pad2 = (n) => String(n).padStart(2, '0');
8
+ /**
9
+ * Generate a default build name from a compact timestamp: `YYYYMMDD-HHmmss`
10
+ * (e.g. `20260531-143022`). Sortable, distinct down to the second, and uses
11
+ * local time so it lines up with when the user ran the command.
12
+ */
13
+ function generateBuildName(date = new Date()) {
14
+ const y = date.getFullYear();
15
+ const mo = pad2(date.getMonth() + 1);
16
+ const d = pad2(date.getDate());
17
+ const h = pad2(date.getHours());
18
+ const mi = pad2(date.getMinutes());
19
+ const s = pad2(date.getSeconds());
20
+ return `${y}${mo}${d}-${h}${mi}${s}`;
21
+ }
22
+ export default class EphemeralStaticHostBuildPush extends BaseCommand {
23
+ static args = {
24
+ tenant_name: Args.string({
25
+ description: 'Ephemeral tenant name',
26
+ required: true,
27
+ }),
28
+ };
29
+ static description = 'Push a directory or zip file as a new static host build for an ephemeral tenant';
30
+ static examples = [
31
+ `$ xano ephemeral static_host build push e4f2-9ab1-xyz1 --static-host default -d ./dist -n "v1.0.0"
32
+ Pushed 15 files as build "v1.0.0"
33
+ ID: 123
34
+ `,
35
+ `$ xano ephemeral static_host build push e4f2-9ab1-xyz1 -H default
36
+ Pushed 8 files as build "20260531-143022"
37
+ `,
38
+ `$ xano ephemeral static_host build push e4f2-9ab1-xyz1 -H default -f ./build.zip -n "v1.0.0"
39
+ Pushed build.zip as build "v1.0.0"
40
+ ID: 124
41
+ `,
42
+ `$ xano ephemeral static_host build push e4f2-9ab1-xyz1 -H myhost -n "production" --description "Production build" -w 40
43
+ Pushed 22 files as build "production"
44
+ ID: 125
45
+ `,
46
+ `$ xano ephemeral static_host build push e4f2-9ab1-xyz1 -H default -d ./static --no-gitignore
47
+ Pushed 30 files as build "20260531-143022"
48
+ `,
49
+ ];
50
+ static flags = {
51
+ ...BaseCommand.baseFlags,
52
+ description: Flags.string({
53
+ description: 'Build description',
54
+ required: false,
55
+ }),
56
+ directory: Flags.string({
57
+ char: 'd',
58
+ description: 'Directory to push (defaults to current directory)',
59
+ exclusive: ['file'],
60
+ required: false,
61
+ }),
62
+ file: Flags.string({
63
+ char: 'f',
64
+ description: 'Path to a zip file to upload (alternative to -d)',
65
+ exclusive: ['directory'],
66
+ required: false,
67
+ }),
68
+ name: Flags.string({
69
+ char: 'n',
70
+ description: 'Build name (auto-generated from the current timestamp if omitted)',
71
+ required: false,
72
+ }),
73
+ 'no-gitignore': Flags.boolean({
74
+ default: false,
75
+ description: 'Push every file in the directory, including those matched by .gitignore (the .git/ folder is always excluded)',
76
+ required: false,
77
+ }),
78
+ 'no-wait': Flags.boolean({
79
+ default: false,
80
+ description: 'Return immediately after upload instead of waiting for the build to finish',
81
+ required: false,
82
+ }),
83
+ output: Flags.string({
84
+ char: 'o',
85
+ default: 'summary',
86
+ description: 'Output format',
87
+ options: ['summary', 'json'],
88
+ required: false,
89
+ }),
90
+ 'static-host': Flags.string({
91
+ char: 'H',
92
+ description: 'Static host name',
93
+ required: true,
94
+ }),
95
+ workspace: Flags.string({
96
+ char: 'w',
97
+ description: 'Workspace ID (optional if set in profile)',
98
+ required: false,
99
+ }),
100
+ };
101
+ async run() {
102
+ const { args, flags } = await this.parse(EphemeralStaticHostBuildPush);
103
+ const { profile, profileName } = this.resolveProfile(flags);
104
+ const tenantName = args.tenant_name;
105
+ const staticHost = flags['static-host'];
106
+ let workspaceId;
107
+ if (flags.workspace) {
108
+ workspaceId = flags.workspace;
109
+ }
110
+ else if (profile.workspace) {
111
+ workspaceId = profile.workspace;
112
+ }
113
+ else {
114
+ this.error(`Workspace ID is required. Either:\n` +
115
+ ` 1. Provide it as a flag: xano ephemeral static_host build push <tenant_name> --static-host <static_host> -n <name> -w <workspace_id>\n` +
116
+ ` 2. Set it in your profile using: xano profile edit ${profileName} -w <workspace_id>`);
117
+ }
118
+ const animate = Boolean(process.stdout.isTTY) && flags.output !== 'json' && !flags.verbose;
119
+ const buildName = flags.name ?? generateBuildName();
120
+ let zipBuffer;
121
+ let fileCount = 0;
122
+ let fileName;
123
+ if (flags.file) {
124
+ const filePath = path.resolve(flags.file);
125
+ if (!fs.existsSync(filePath)) {
126
+ this.error(`File not found: ${filePath}`);
127
+ }
128
+ const fileStats = fs.statSync(filePath);
129
+ if (!fileStats.isFile()) {
130
+ this.error(`Path is not a file: ${filePath}`);
131
+ }
132
+ fileName = path.basename(filePath);
133
+ if (animate)
134
+ ux.action.start('Uploading', fileName);
135
+ zipBuffer = fs.readFileSync(filePath);
136
+ }
137
+ else {
138
+ const sourceDir = path.resolve(flags.directory ?? '.');
139
+ if (!fs.existsSync(sourceDir)) {
140
+ this.error(`Directory not found: ${sourceDir}`);
141
+ }
142
+ const dirStats = fs.statSync(sourceDir);
143
+ if (!dirStats.isDirectory()) {
144
+ this.error(`Path is not a directory: ${sourceDir}`);
145
+ }
146
+ const files = collectStaticHostFiles(sourceDir, { respectGitignore: !flags['no-gitignore'] });
147
+ if (files.length === 0) {
148
+ this.error(`No files to push from ${sourceDir} — everything is excluded by .gitignore. ` +
149
+ `Use --no-gitignore to push the entire directory.`);
150
+ }
151
+ fileCount = files.length;
152
+ if (animate)
153
+ ux.action.start('Packaging', `${fileCount} files`);
154
+ zipBuffer = await this.createZipBuffer(sourceDir, files);
155
+ if (animate) {
156
+ ux.action.stop(`${fileCount} files (${(zipBuffer.length / (1024 * 1024)).toFixed(1)} MB)`);
157
+ ux.action.start('Uploading');
158
+ }
159
+ }
160
+ const sizeMB = (zipBuffer.length / (1024 * 1024)).toFixed(1);
161
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/static_host/${staticHost}/build`;
162
+ const formData = new globalThis.FormData();
163
+ const blob = new Blob([new Uint8Array(zipBuffer)], { type: 'application/zip' });
164
+ formData.append('file', blob, fileName ?? 'build.zip');
165
+ formData.append('name', buildName);
166
+ if (flags.description) {
167
+ formData.append('description', flags.description);
168
+ }
169
+ try {
170
+ const response = await this.verboseFetch(apiUrl, {
171
+ body: formData,
172
+ headers: {
173
+ 'accept': 'application/json',
174
+ 'Authorization': `Bearer ${profile.access_token}`,
175
+ },
176
+ method: 'POST',
177
+ }, flags.verbose, profile.access_token);
178
+ if (animate) {
179
+ ux.action.stop('done');
180
+ }
181
+ if (!response.ok) {
182
+ const errorText = await response.text();
183
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
184
+ }
185
+ const result = await response.json();
186
+ if (!result || typeof result !== 'object') {
187
+ this.error('Unexpected API response format');
188
+ }
189
+ if (flags.output === 'json') {
190
+ this.log(JSON.stringify(result, null, 2));
191
+ }
192
+ else {
193
+ this.log(fileName
194
+ ? `Pushed ${fileName} as build "${buildName}" (${sizeMB} MB)`
195
+ : `Pushed ${fileCount} files as build "${buildName}" (${sizeMB} MB)`);
196
+ this.log(`ID: ${result.id}`);
197
+ if (result.status) {
198
+ this.log(`Status: ${result.status}`);
199
+ }
200
+ }
201
+ // Async (package.json) builds keep running after upload. Unless --no-wait,
202
+ // poll until the build finishes so the CLI mirrors the UI's progress.
203
+ const inProgress = result.status !== undefined && !['error', 'ok'].includes(result.status);
204
+ if (inProgress && !flags['no-wait']) {
205
+ const finalStatus = await this.waitForBuild({
206
+ buildId: result.id,
207
+ profile,
208
+ quiet: flags.output === 'json',
209
+ staticHost,
210
+ tenantName,
211
+ verbose: flags.verbose,
212
+ workspaceId,
213
+ });
214
+ if (finalStatus === 'error') {
215
+ this.error(`Build ${result.id} failed (status: error). Check the build log with: xano ephemeral static_host build get ${tenantName} --static-host ${staticHost} --build_id ${result.id}`);
216
+ }
217
+ }
218
+ if (flags.output !== 'json') {
219
+ await this.logStaticHostUrls({ profile, staticHost, tenantName, verbose: flags.verbose, workspaceId });
220
+ }
221
+ }
222
+ catch (error) {
223
+ if (error instanceof Error) {
224
+ this.error(`Failed to push build: ${error.message}`);
225
+ }
226
+ else {
227
+ this.error(`Failed to push build: ${String(error)}`);
228
+ }
229
+ }
230
+ }
231
+ async createZipBuffer(sourceDir, files) {
232
+ return new Promise((resolve, reject) => {
233
+ const chunks = [];
234
+ const archive = archiver('zip', { zlib: { level: 9 } });
235
+ archive.on('data', (chunk) => {
236
+ chunks.push(chunk);
237
+ });
238
+ archive.on('end', () => {
239
+ resolve(Buffer.concat(chunks));
240
+ });
241
+ archive.on('error', (err) => {
242
+ reject(err);
243
+ });
244
+ for (const rel of files) {
245
+ archive.file(path.join(sourceDir, rel), { name: rel });
246
+ }
247
+ archive.finalize();
248
+ });
249
+ }
250
+ }
@@ -0,0 +1,18 @@
1
+ import BaseCommand from '../../../../base-command.js';
2
+ export default class EphemeralStaticHostCreate extends BaseCommand {
3
+ static args: {
4
+ tenant_name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ name: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
13
+ config: 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
+ }
@@ -0,0 +1,92 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import BaseCommand from '../../../../base-command.js';
3
+ export default class EphemeralStaticHostCreate extends BaseCommand {
4
+ static args = {
5
+ tenant_name: Args.string({
6
+ description: 'Ephemeral tenant name',
7
+ required: true,
8
+ }),
9
+ };
10
+ static description = 'Create a new static host for an ephemeral tenant';
11
+ static examples = [
12
+ `$ xano ephemeral static_host create e4f2-9ab1-xyz1 --name marketing
13
+ Created static host 'marketing' (ID: 7)
14
+ `,
15
+ `$ xano ephemeral static_host create e4f2-9ab1-xyz1 -n marketing --description "Marketing site" -w 40
16
+ Created static host 'marketing' (ID: 7)
17
+ `,
18
+ `$ xano ephemeral static_host create e4f2-9ab1-xyz1 -n marketing -o json`,
19
+ ];
20
+ static flags = {
21
+ ...BaseCommand.baseFlags,
22
+ description: Flags.string({
23
+ description: 'Description for the static host',
24
+ required: false,
25
+ }),
26
+ name: Flags.string({
27
+ char: 'n',
28
+ description: 'Name for the new static host',
29
+ required: true,
30
+ }),
31
+ output: Flags.string({
32
+ char: 'o',
33
+ default: 'summary',
34
+ description: 'Output format',
35
+ options: ['summary', 'json'],
36
+ required: false,
37
+ }),
38
+ workspace: Flags.string({
39
+ char: 'w',
40
+ description: 'Workspace ID (optional if set in profile)',
41
+ required: false,
42
+ }),
43
+ };
44
+ async run() {
45
+ const { args, flags } = await this.parse(EphemeralStaticHostCreate);
46
+ const { profile, profileName } = this.resolveProfile(flags);
47
+ const tenantName = args.tenant_name;
48
+ let workspaceId;
49
+ if (flags.workspace) {
50
+ workspaceId = flags.workspace;
51
+ }
52
+ else if (profile.workspace) {
53
+ workspaceId = profile.workspace;
54
+ }
55
+ else {
56
+ this.error(`Workspace ID is required. Either:\n` +
57
+ ` 1. Provide it as a flag: xano ephemeral static_host create <tenant_name> --name <name> -w <workspace_id>\n` +
58
+ ` 2. Set it in your profile using: xano profile edit ${profileName} -w <workspace_id>`);
59
+ }
60
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/static_host`;
61
+ try {
62
+ const response = await this.verboseFetch(apiUrl, {
63
+ body: JSON.stringify({ description: flags.description ?? '', name: flags.name }),
64
+ headers: {
65
+ accept: 'application/json',
66
+ Authorization: `Bearer ${profile.access_token}`,
67
+ 'Content-Type': 'application/json',
68
+ },
69
+ method: 'POST',
70
+ }, flags.verbose, profile.access_token);
71
+ if (!response.ok) {
72
+ const message = await this.parseApiError(response, `Failed to create static host '${flags.name}'`);
73
+ this.error(message);
74
+ }
75
+ const host = (await response.json());
76
+ if (flags.output === 'json') {
77
+ this.log(JSON.stringify(host, null, 2));
78
+ }
79
+ else {
80
+ this.log(`Created static host '${host.name}' (ID: ${host.id})`);
81
+ }
82
+ }
83
+ catch (error) {
84
+ if (error instanceof Error) {
85
+ this.error(`Failed to create static host: ${error.message}`);
86
+ }
87
+ else {
88
+ this.error(`Failed to create static host: ${String(error)}`);
89
+ }
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,19 @@
1
+ import BaseCommand from '../../../../base-command.js';
2
+ export default class EphemeralStaticHostDeploy extends BaseCommand {
3
+ static args: {
4
+ tenant_name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ build_id: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
+ env: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'static-host': 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
+ config: 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
+ }
@@ -0,0 +1,112 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import BaseCommand from '../../../../base-command.js';
3
+ export default class EphemeralStaticHostDeploy extends BaseCommand {
4
+ static args = {
5
+ tenant_name: Args.string({
6
+ description: 'Ephemeral tenant name',
7
+ required: true,
8
+ }),
9
+ };
10
+ static description = 'Deploy a static host build to an environment for an ephemeral tenant';
11
+ static examples = [
12
+ `$ xano ephemeral static_host deploy e4f2-9ab1-xyz1 --static-host default --build_id 52 --env dev
13
+ Deployed build 52 to dev
14
+ URL: https://x1234-abcd.static.xano.io
15
+ `,
16
+ `$ xano ephemeral static_host deploy e4f2-9ab1-xyz1 -H default --build_id 52 --env prod
17
+ Deployed build 52 to prod
18
+ URL: https://x1234-abcd.static.xano.io
19
+ `,
20
+ `$ xano ephemeral static_host deploy e4f2-9ab1-xyz1 -H myhost --build_id 123 --env dev -w 40
21
+ Deployed build 123 to dev
22
+ `,
23
+ `$ xano ephemeral static_host deploy e4f2-9ab1-xyz1 -H default --build_id 52 --env prod -o json`,
24
+ ];
25
+ static flags = {
26
+ ...BaseCommand.baseFlags,
27
+ build_id: Flags.string({
28
+ description: 'Build ID to deploy',
29
+ required: true,
30
+ }),
31
+ env: Flags.string({
32
+ description: 'Target environment',
33
+ options: ['dev', 'prod'],
34
+ required: true,
35
+ }),
36
+ output: Flags.string({
37
+ char: 'o',
38
+ default: 'summary',
39
+ description: 'Output format',
40
+ options: ['summary', 'json'],
41
+ required: false,
42
+ }),
43
+ 'static-host': Flags.string({
44
+ char: 'H',
45
+ description: 'Static host name',
46
+ required: true,
47
+ }),
48
+ workspace: Flags.string({
49
+ char: 'w',
50
+ description: 'Workspace ID (optional if set in profile)',
51
+ required: false,
52
+ }),
53
+ };
54
+ async run() {
55
+ const { args, flags } = await this.parse(EphemeralStaticHostDeploy);
56
+ const { profile, profileName } = this.resolveProfile(flags);
57
+ const tenantName = args.tenant_name;
58
+ const staticHost = flags['static-host'];
59
+ let workspaceId;
60
+ if (flags.workspace) {
61
+ workspaceId = flags.workspace;
62
+ }
63
+ else if (profile.workspace) {
64
+ workspaceId = profile.workspace;
65
+ }
66
+ else {
67
+ this.error(`Workspace ID is required. Either:\n` +
68
+ ` 1. Provide it as a flag: xano ephemeral static_host deploy <tenant_name> --static-host <static_host> --build_id <id> --env <env> -w <workspace_id>\n` +
69
+ ` 2. Set it in your profile using: xano profile edit ${profileName} -w <workspace_id>`);
70
+ }
71
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/static_host/${staticHost}/build/${flags.build_id}/env`;
72
+ try {
73
+ const response = await this.verboseFetch(apiUrl, {
74
+ body: JSON.stringify({ env: flags.env }),
75
+ headers: {
76
+ 'accept': 'application/json',
77
+ 'Authorization': `Bearer ${profile.access_token}`,
78
+ 'Content-Type': 'application/json',
79
+ },
80
+ method: 'POST',
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
+ const result = await response.json();
87
+ if (!result || typeof result !== 'object') {
88
+ this.error('Unexpected API response format');
89
+ }
90
+ if (flags.output === 'json') {
91
+ this.log(JSON.stringify(result, null, 2));
92
+ }
93
+ else {
94
+ this.log(`Deployed build ${flags.build_id} to ${flags.env}`);
95
+ if (result.default_url) {
96
+ this.log(`URL: ${result.default_url}`);
97
+ }
98
+ if (result.custom_url) {
99
+ this.log(`Custom URL: ${result.custom_url}`);
100
+ }
101
+ }
102
+ }
103
+ catch (error) {
104
+ if (error instanceof Error) {
105
+ this.error(`Failed to deploy build: ${error.message}`);
106
+ }
107
+ else {
108
+ this.error(`Failed to deploy build: ${String(error)}`);
109
+ }
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,24 @@
1
+ import BaseCommand from '../../../../base-command.js';
2
+ export default class EphemeralStaticHostEdit extends BaseCommand {
3
+ static args: {
4
+ tenant_name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
5
+ };
6
+ static description: string;
7
+ static examples: string[];
8
+ static flags: {
9
+ description: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ 'git-private-key-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'git-public-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
12
+ 'git-repo': 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
+ 'static-host': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
16
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
17
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
20
+ };
21
+ run(): Promise<void>;
22
+ /** Fetch the current host record so unspecified fields are preserved on edit. */
23
+ private fetchHost;
24
+ }
@@ -0,0 +1,158 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import BaseCommand from '../../../../base-command.js';
5
+ export default class EphemeralStaticHostEdit extends BaseCommand {
6
+ static args = {
7
+ tenant_name: Args.string({
8
+ description: 'Ephemeral tenant name',
9
+ required: true,
10
+ }),
11
+ };
12
+ static description = 'Update a static host\'s name, description, or git configuration for an ephemeral tenant';
13
+ static examples = [
14
+ `$ xano ephemeral static_host edit e4f2-9ab1-xyz1 --static-host newsite --description "Marketing site"
15
+ Updated static host 'newsite'
16
+ `,
17
+ `$ xano ephemeral static_host edit e4f2-9ab1-xyz1 -H newsite --name newsite-v2
18
+ Updated static host 'newsite' (renamed to 'newsite-v2')
19
+ `,
20
+ `$ xano ephemeral static_host edit e4f2-9ab1-xyz1 -H newsite --git-repo git@github.com:me/site.git --git-private-key-file ./deploy_key
21
+ Updated static host 'newsite'
22
+ `,
23
+ ];
24
+ static flags = {
25
+ ...BaseCommand.baseFlags,
26
+ description: Flags.string({
27
+ description: 'New description for the static host',
28
+ required: false,
29
+ }),
30
+ 'git-private-key-file': Flags.string({
31
+ description: 'Path to a file containing the git SSH private key (read from disk; never passed on the command line)',
32
+ required: false,
33
+ }),
34
+ 'git-public-key': Flags.string({
35
+ description: 'Git SSH public key',
36
+ required: false,
37
+ }),
38
+ 'git-repo': Flags.string({
39
+ description: 'Git repository URL (e.g. git@github.com:org/repo.git)',
40
+ required: false,
41
+ }),
42
+ name: Flags.string({
43
+ description: 'New name for the static host (renaming changes the deployed hostname)',
44
+ required: false,
45
+ }),
46
+ output: Flags.string({
47
+ char: 'o',
48
+ default: 'summary',
49
+ description: 'Output format',
50
+ options: ['summary', 'json'],
51
+ required: false,
52
+ }),
53
+ 'static-host': Flags.string({
54
+ char: 'H',
55
+ description: 'Static host name to edit',
56
+ required: true,
57
+ }),
58
+ workspace: Flags.string({
59
+ char: 'w',
60
+ description: 'Workspace ID (optional if set in profile)',
61
+ required: false,
62
+ }),
63
+ };
64
+ async run() {
65
+ const { args, flags } = await this.parse(EphemeralStaticHostEdit);
66
+ const hasGitFlag = Boolean(flags['git-repo'] || flags['git-private-key-file'] || flags['git-public-key']);
67
+ if (!flags.name && flags.description === undefined && !hasGitFlag) {
68
+ this.error('Nothing to update. Provide at least one of --name, --description, or a --git-* flag.');
69
+ }
70
+ const { profile, profileName } = this.resolveProfile(flags);
71
+ const tenantName = args.tenant_name;
72
+ const staticHost = flags['static-host'];
73
+ let workspaceId;
74
+ if (flags.workspace) {
75
+ workspaceId = flags.workspace;
76
+ }
77
+ else if (profile.workspace) {
78
+ workspaceId = profile.workspace;
79
+ }
80
+ else {
81
+ this.error(`Workspace ID is required. Either:\n` +
82
+ ` 1. Provide it as a flag: xano ephemeral static_host edit <tenant_name> --static-host <static_host> --name <name> -w <workspace_id>\n` +
83
+ ` 2. Set it in your profile using: xano profile edit ${profileName} -w <workspace_id>`);
84
+ }
85
+ // The edit endpoint requires `name`, and merges git as a whole object —
86
+ // so fetch the current record first and only override the fields the user set.
87
+ const current = await this.fetchHost(profile, workspaceId, tenantName, staticHost, flags.verbose);
88
+ const git = { ...current.git };
89
+ if (flags['git-repo'] !== undefined)
90
+ git.repo = flags['git-repo'];
91
+ if (flags['git-public-key'] !== undefined)
92
+ git.public_key = flags['git-public-key'];
93
+ if (flags['git-private-key-file'] !== undefined) {
94
+ const keyPath = path.resolve(flags['git-private-key-file']);
95
+ if (!fs.existsSync(keyPath)) {
96
+ this.error(`Private key file not found: ${keyPath}`);
97
+ }
98
+ git.private_key = fs.readFileSync(keyPath, 'utf8').trim();
99
+ }
100
+ const body = {
101
+ description: flags.description ?? current.description ?? '',
102
+ git: {
103
+ private_key: git.private_key ?? '',
104
+ public_key: git.public_key ?? '',
105
+ repo: git.repo ?? '',
106
+ },
107
+ name: flags.name ?? current.name,
108
+ };
109
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/static_host/${staticHost}/edit`;
110
+ try {
111
+ const response = await this.verboseFetch(apiUrl, {
112
+ body: JSON.stringify(body),
113
+ headers: {
114
+ accept: 'application/json',
115
+ Authorization: `Bearer ${profile.access_token}`,
116
+ 'Content-Type': 'application/json',
117
+ },
118
+ method: 'POST',
119
+ }, flags.verbose, profile.access_token);
120
+ if (!response.ok) {
121
+ const message = await this.parseApiError(response, `Failed to update static host '${staticHost}'`);
122
+ this.error(message);
123
+ }
124
+ const updated = (await response.json());
125
+ if (flags.output === 'json') {
126
+ this.log(JSON.stringify(updated, null, 2));
127
+ }
128
+ else {
129
+ const renamed = flags.name && flags.name !== staticHost ? ` (renamed to '${flags.name}')` : '';
130
+ this.log(`Updated static host '${staticHost}'${renamed}`);
131
+ }
132
+ }
133
+ catch (error) {
134
+ if (error instanceof Error) {
135
+ this.error(`Failed to update static host: ${error.message}`);
136
+ }
137
+ else {
138
+ this.error(`Failed to update static host: ${String(error)}`);
139
+ }
140
+ }
141
+ }
142
+ /** Fetch the current host record so unspecified fields are preserved on edit. */
143
+ async fetchHost(profile, workspaceId, tenantName, staticHost, verbose) {
144
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/static_host/${staticHost}`;
145
+ const response = await this.verboseFetch(apiUrl, {
146
+ headers: {
147
+ accept: 'application/json',
148
+ Authorization: `Bearer ${profile.access_token}`,
149
+ },
150
+ method: 'GET',
151
+ }, verbose, profile.access_token);
152
+ if (!response.ok) {
153
+ const message = await this.parseApiError(response, `Static host '${staticHost}' not found`);
154
+ this.error(message);
155
+ }
156
+ return (await response.json());
157
+ }
158
+ }