@xano/cli 1.2.0 → 1.3.1-beta.0

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 (192) hide show
  1. package/README.md +381 -4
  2. package/dist/base-command.d.ts +54 -36
  3. package/dist/base-command.js +246 -169
  4. package/dist/commands/auth/index.d.ts +1 -1
  5. package/dist/commands/auth/index.js +7 -7
  6. package/dist/commands/branch/create/index.d.ts +1 -1
  7. package/dist/commands/branch/create/index.js +1 -1
  8. package/dist/commands/branch/set_live/index.d.ts +22 -0
  9. package/dist/commands/branch/set_live/index.js +60 -1
  10. package/dist/commands/ephemeral/create/index.d.ts +18 -0
  11. package/dist/commands/ephemeral/create/index.js +103 -0
  12. package/dist/commands/ephemeral/delete/index.d.ts +18 -0
  13. package/dist/commands/ephemeral/delete/index.js +99 -0
  14. package/dist/commands/ephemeral/edit/index.d.ts +18 -0
  15. package/dist/commands/ephemeral/edit/index.js +109 -0
  16. package/dist/commands/ephemeral/get/index.d.ts +21 -0
  17. package/dist/commands/ephemeral/get/index.js +125 -0
  18. package/dist/commands/ephemeral/impersonate/index.d.ts +20 -0
  19. package/dist/commands/ephemeral/impersonate/index.js +120 -0
  20. package/dist/commands/ephemeral/list/index.d.ts +19 -0
  21. package/dist/commands/ephemeral/list/index.js +123 -0
  22. package/dist/commands/ephemeral/pull/index.d.ts +19 -0
  23. package/dist/commands/ephemeral/pull/index.js +163 -0
  24. package/dist/commands/ephemeral/push/index.d.ts +35 -0
  25. package/dist/commands/ephemeral/push/index.js +228 -0
  26. package/dist/commands/ephemeral/static_host/build/delete/index.d.ts +20 -0
  27. package/dist/commands/ephemeral/static_host/build/delete/index.js +121 -0
  28. package/dist/commands/ephemeral/static_host/build/get/index.d.ts +18 -0
  29. package/dist/commands/ephemeral/static_host/build/get/index.js +137 -0
  30. package/dist/commands/ephemeral/static_host/build/list/index.d.ts +18 -0
  31. package/dist/commands/ephemeral/static_host/build/list/index.js +137 -0
  32. package/dist/commands/ephemeral/static_host/build/pull/index.d.ts +53 -0
  33. package/dist/commands/ephemeral/static_host/build/pull/index.js +308 -0
  34. package/dist/commands/ephemeral/static_host/build/push/index.d.ts +24 -0
  35. package/dist/commands/ephemeral/static_host/build/push/index.js +250 -0
  36. package/dist/commands/ephemeral/static_host/create/index.d.ts +18 -0
  37. package/dist/commands/ephemeral/static_host/create/index.js +92 -0
  38. package/dist/commands/ephemeral/static_host/deploy/index.d.ts +19 -0
  39. package/dist/commands/ephemeral/static_host/deploy/index.js +112 -0
  40. package/dist/commands/ephemeral/static_host/edit/index.d.ts +24 -0
  41. package/dist/commands/ephemeral/static_host/edit/index.js +158 -0
  42. package/dist/commands/ephemeral/static_host/get/index.d.ts +19 -0
  43. package/dist/commands/ephemeral/static_host/get/index.js +101 -0
  44. package/dist/commands/ephemeral/static_host/list/index.d.ts +17 -0
  45. package/dist/commands/ephemeral/static_host/list/index.js +132 -0
  46. package/dist/commands/flatten/index.d.ts +34 -0
  47. package/dist/commands/flatten/index.js +140 -0
  48. package/dist/commands/function/create/index.d.ts +15 -0
  49. package/dist/commands/function/create/index.js +41 -1
  50. package/dist/commands/function/edit/index.d.ts +15 -0
  51. package/dist/commands/function/edit/index.js +66 -32
  52. package/dist/commands/function/get/index.js +2 -3
  53. package/dist/commands/function/run/index.d.ts +1 -0
  54. package/dist/commands/function/run/index.js +19 -6
  55. package/dist/commands/policy/catalogue/index.d.ts +15 -0
  56. package/dist/commands/policy/catalogue/index.js +29 -0
  57. package/dist/commands/policy/create/index.d.ts +18 -0
  58. package/dist/commands/policy/create/index.js +39 -0
  59. package/dist/commands/policy/delete/index.d.ts +19 -0
  60. package/dist/commands/policy/delete/index.js +61 -0
  61. package/dist/commands/policy/evaluate/index.d.ts +32 -0
  62. package/dist/commands/policy/evaluate/index.js +71 -0
  63. package/dist/commands/policy/list/index.d.ts +14 -0
  64. package/dist/commands/policy/list/index.js +21 -0
  65. package/dist/commands/policy/parse/index.d.ts +19 -0
  66. package/dist/commands/policy/parse/index.js +18 -0
  67. package/dist/commands/policy/publish/index.d.ts +20 -0
  68. package/dist/commands/policy/publish/index.js +38 -0
  69. package/dist/commands/policy/runs/index.d.ts +54 -0
  70. package/dist/commands/policy/runs/index.js +273 -0
  71. package/dist/commands/policy/status/index.d.ts +21 -0
  72. package/dist/commands/policy/status/index.js +54 -0
  73. package/dist/commands/profile/create/index.d.ts +1 -1
  74. package/dist/commands/profile/create/index.js +7 -7
  75. package/dist/commands/profile/me/index.js +1 -1
  76. package/dist/commands/profile/use/index.js +0 -4
  77. package/dist/commands/profile/wizard/index.d.ts +1 -1
  78. package/dist/commands/profile/wizard/index.js +12 -10
  79. package/dist/commands/profile/workspace/set/index.js +1 -1
  80. package/dist/commands/release/create/index.js +7 -0
  81. package/dist/commands/release/deploy/index.d.ts +28 -0
  82. package/dist/commands/release/deploy/index.js +90 -6
  83. package/dist/commands/release/edit/index.js +2 -2
  84. package/dist/commands/release/export/index.js +1 -2
  85. package/dist/commands/release/import/index.js +6 -2
  86. package/dist/commands/release/list/index.d.ts +7 -0
  87. package/dist/commands/release/list/index.js +54 -10
  88. package/dist/commands/release/pull/index.d.ts +0 -6
  89. package/dist/commands/release/pull/index.js +13 -99
  90. package/dist/commands/release/push/index.js +21 -3
  91. package/dist/commands/sandbox/env/get_all/index.js +1 -1
  92. package/dist/commands/sandbox/env/set_all/index.js +1 -1
  93. package/dist/commands/sandbox/get/index.js +1 -1
  94. package/dist/commands/sandbox/license/get/index.js +1 -1
  95. package/dist/commands/sandbox/license/set/index.js +1 -1
  96. package/dist/commands/sandbox/pull/index.d.ts +0 -1
  97. package/dist/commands/sandbox/pull/index.js +13 -81
  98. package/dist/commands/sandbox/push/index.d.ts +1 -1
  99. package/dist/commands/sandbox/push/index.js +11 -6
  100. package/dist/commands/skills/pull/index.d.ts +30 -0
  101. package/dist/commands/skills/pull/index.js +118 -0
  102. package/dist/commands/static_host/build/create/index.d.ts +1 -1
  103. package/dist/commands/static_host/build/create/index.js +2 -2
  104. package/dist/commands/static_host/build/pull/index.js +1 -1
  105. package/dist/commands/static_host/build/push/index.js +1 -1
  106. package/dist/commands/static_host/edit/index.js +1 -1
  107. package/dist/commands/tenant/backup/export/index.js +1 -2
  108. package/dist/commands/tenant/backup/import/index.js +1 -1
  109. package/dist/commands/tenant/cluster/create/index.js +1 -1
  110. package/dist/commands/tenant/cluster/license/get/index.js +1 -1
  111. package/dist/commands/tenant/cluster/license/set/index.js +1 -1
  112. package/dist/commands/tenant/create/index.d.ts +4 -1
  113. package/dist/commands/tenant/create/index.js +26 -5
  114. package/dist/commands/tenant/deploy_platform/index.js +1 -1
  115. package/dist/commands/tenant/deploy_release/index.d.ts +40 -0
  116. package/dist/commands/tenant/deploy_release/index.js +186 -4
  117. package/dist/commands/tenant/edit/index.d.ts +2 -0
  118. package/dist/commands/tenant/edit/index.js +46 -11
  119. package/dist/commands/tenant/env/get_all/index.js +1 -1
  120. package/dist/commands/tenant/env/set_all/index.js +1 -1
  121. package/dist/commands/tenant/impersonate/index.d.ts +1 -1
  122. package/dist/commands/tenant/impersonate/index.js +14 -14
  123. package/dist/commands/tenant/license/get/index.js +1 -1
  124. package/dist/commands/tenant/license/set/index.js +1 -1
  125. package/dist/commands/tenant/pull/index.d.ts +0 -6
  126. package/dist/commands/tenant/pull/index.js +14 -100
  127. package/dist/commands/tenant_deploy_request/bypass/index.d.ts +31 -0
  128. package/dist/commands/tenant_deploy_request/bypass/index.js +109 -0
  129. package/dist/commands/tenant_deploy_request/create/index.d.ts +21 -0
  130. package/dist/commands/tenant_deploy_request/create/index.js +108 -0
  131. package/dist/commands/tenant_deploy_request/edit/index.d.ts +22 -0
  132. package/dist/commands/tenant_deploy_request/edit/index.js +103 -0
  133. package/dist/commands/tenant_deploy_request/get/index.d.ts +25 -0
  134. package/dist/commands/tenant_deploy_request/get/index.js +116 -0
  135. package/dist/commands/tenant_deploy_request/list/index.d.ts +20 -0
  136. package/dist/commands/tenant_deploy_request/list/index.js +122 -0
  137. package/dist/commands/tenant_deploy_request/revision/index.d.ts +21 -0
  138. package/dist/commands/tenant_deploy_request/revision/index.js +83 -0
  139. package/dist/commands/tenant_deploy_request/set_status/index.d.ts +38 -0
  140. package/dist/commands/tenant_deploy_request/set_status/index.js +159 -0
  141. package/dist/commands/workspace/git/pull/index.d.ts +4 -4
  142. package/dist/commands/workspace/git/pull/index.js +158 -97
  143. package/dist/commands/workspace/pull/index.d.ts +9 -5
  144. package/dist/commands/workspace/pull/index.js +83 -106
  145. package/dist/commands/workspace/push/index.d.ts +19 -0
  146. package/dist/commands/workspace/push/index.js +124 -5
  147. package/dist/help.js +4 -2
  148. package/dist/policy-command.d.ts +90 -0
  149. package/dist/policy-command.js +94 -0
  150. package/dist/update-check.d.ts +1 -1
  151. package/dist/update-check.js +1 -1
  152. package/dist/utils/document-parser.d.ts +126 -0
  153. package/dist/utils/document-parser.js +332 -4
  154. package/dist/utils/flatten.d.ts +36 -0
  155. package/dist/utils/flatten.js +68 -0
  156. package/dist/utils/knowledge-sync.d.ts +1 -0
  157. package/dist/utils/knowledge-sync.js +11 -6
  158. package/dist/utils/microservice-wait.d.ts +53 -0
  159. package/dist/utils/microservice-wait.js +84 -0
  160. package/dist/utils/multidoc-push.d.ts +143 -2
  161. package/dist/utils/multidoc-push.js +479 -40
  162. package/dist/utils/paging.d.ts +2 -1
  163. package/dist/utils/paging.js +0 -1
  164. package/dist/utils/policy/catalogue.d.ts +7 -0
  165. package/dist/utils/policy/catalogue.js +72 -0
  166. package/dist/utils/policy/errors.d.ts +12 -0
  167. package/dist/utils/policy/errors.js +61 -0
  168. package/dist/utils/policy/feedback.d.ts +68 -0
  169. package/dist/utils/policy/feedback.js +165 -0
  170. package/dist/utils/policy/findings.d.ts +23 -0
  171. package/dist/utils/policy/findings.js +65 -0
  172. package/dist/utils/policy/gate.d.ts +161 -0
  173. package/dist/utils/policy/gate.js +201 -0
  174. package/dist/utils/policy/goal.d.ts +46 -0
  175. package/dist/utils/policy/goal.js +95 -0
  176. package/dist/utils/policy/permission.d.ts +23 -0
  177. package/dist/utils/policy/permission.js +84 -0
  178. package/dist/utils/policy/push-gate.d.ts +5 -0
  179. package/dist/utils/policy/push-gate.js +29 -0
  180. package/dist/utils/policy/release.d.ts +85 -0
  181. package/dist/utils/policy/release.js +115 -0
  182. package/dist/utils/policy/request.d.ts +55 -0
  183. package/dist/utils/policy/request.js +115 -0
  184. package/dist/utils/policy/runs.d.ts +30 -0
  185. package/dist/utils/policy/runs.js +101 -0
  186. package/dist/utils/policy/status.d.ts +47 -0
  187. package/dist/utils/policy/status.js +117 -0
  188. package/dist/utils/policy/types.d.ts +185 -0
  189. package/dist/utils/policy/types.js +1 -0
  190. package/dist/utils/reference-checker.js +14 -3
  191. package/oclif.manifest.json +8538 -3445
  192. package/package.json +16 -1
@@ -0,0 +1,125 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import BaseCommand from '../../../base-command.js';
3
+ export default class EphemeralGet extends BaseCommand {
4
+ static args = {
5
+ tenant_name: Args.string({
6
+ description: 'Ephemeral tenant name to retrieve',
7
+ required: true,
8
+ }),
9
+ };
10
+ static description = 'Get details of a specific ephemeral tenant';
11
+ static examples = [
12
+ `$ xano ephemeral get e4f2-9ab1-xyz1
13
+ Tenant: PR preview (e4f2-9ab1-xyz1)
14
+ State: ok
15
+ License: tier1
16
+ Expires: in 1h 0m
17
+ `,
18
+ `$ xano ephemeral get e4f2-9ab1-xyz1 -w 5 -o json`,
19
+ ];
20
+ static flags = {
21
+ ...BaseCommand.baseFlags,
22
+ output: Flags.string({
23
+ char: 'o',
24
+ default: 'summary',
25
+ description: 'Output format',
26
+ options: ['summary', 'json'],
27
+ required: false,
28
+ }),
29
+ workspace: Flags.string({
30
+ char: 'w',
31
+ description: 'Workspace ID (uses profile workspace if not provided)',
32
+ required: false,
33
+ }),
34
+ };
35
+ async run() {
36
+ const { args, flags } = await this.parse(EphemeralGet);
37
+ const { profile } = this.resolveProfile(flags);
38
+ const workspaceId = flags.workspace || profile.workspace;
39
+ if (!workspaceId) {
40
+ this.error('No workspace ID provided. Use --workspace flag or set one in your profile.');
41
+ }
42
+ const tenantName = args.tenant_name;
43
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}`;
44
+ try {
45
+ const response = await this.verboseFetch(apiUrl, {
46
+ headers: {
47
+ accept: 'application/json',
48
+ Authorization: `Bearer ${profile.access_token}`,
49
+ },
50
+ method: 'GET',
51
+ }, flags.verbose, profile.access_token);
52
+ if (!response.ok) {
53
+ const errorText = await response.text();
54
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
55
+ }
56
+ const tenant = (await response.json());
57
+ if (flags.output === 'json') {
58
+ this.log(JSON.stringify(tenant, null, 2));
59
+ }
60
+ else {
61
+ this.log(`Tenant: ${tenant.display || tenant.name} (${tenant.name})`);
62
+ if (tenant.state)
63
+ this.log(` State: ${tenant.state}`);
64
+ if (tenant.license)
65
+ this.log(` License: ${tenant.license}`);
66
+ if (tenant.xano_domain)
67
+ this.log(` Domain: ${tenant.xano_domain}`);
68
+ if (tenant.domain)
69
+ this.log(` Custom Domain: ${tenant.domain}`);
70
+ if (tenant.cluster?.name)
71
+ this.log(` Cluster: ${tenant.cluster.name}`);
72
+ const releaseName = typeof tenant.release === 'string' ? tenant.release : tenant.release?.name;
73
+ const releaseId = typeof tenant.release === 'object' ? tenant.release?.id : undefined;
74
+ if (releaseName)
75
+ this.log(` Release: ${releaseName} (ID: ${releaseId})`);
76
+ if (tenant.platform?.name)
77
+ this.log(` Platform: ${tenant.platform.name}`);
78
+ if (tenant.version !== undefined)
79
+ this.log(` Version: ${tenant.version}`);
80
+ if (tenant.tasks !== undefined)
81
+ this.log(` Tasks: ${tenant.tasks}`);
82
+ if (tenant.ingress !== undefined)
83
+ this.log(` Ingress: ${tenant.ingress}`);
84
+ if (tenant.type)
85
+ this.log(` Type: ${tenant.type}`);
86
+ this.log(` Expires: ${this.formatExpiration(tenant.ephemeral_expires_at)}`);
87
+ if (tenant.deployed_at) {
88
+ const d = new Date(tenant.deployed_at);
89
+ const deployedDate = Number.isNaN(d.getTime()) ? tenant.deployed_at : d.toISOString().split('T')[0];
90
+ this.log(` Deployed: ${deployedDate}`);
91
+ }
92
+ }
93
+ }
94
+ catch (error) {
95
+ if (error instanceof Error) {
96
+ this.error(`Failed to get ephemeral tenant: ${error.message}`);
97
+ }
98
+ else {
99
+ this.error(`Failed to get ephemeral tenant: ${String(error)}`);
100
+ }
101
+ }
102
+ }
103
+ /**
104
+ * Render a unix-epoch-seconds expiration as a human-readable "in Xh Ym" string,
105
+ * falling back to an ISO timestamp if the value has already passed or is absent.
106
+ */
107
+ formatExpiration(expiresAt) {
108
+ if (!expiresAt) {
109
+ return '-';
110
+ }
111
+ // The API serializes the timestamp field as a date string
112
+ // ("2026-07-24 19:49:15+0000"); tolerate a raw unix-epoch number too.
113
+ const expiresMs = typeof expiresAt === 'number' ? expiresAt * 1000 : Date.parse(String(expiresAt).replace(' ', 'T'));
114
+ if (Number.isNaN(expiresMs)) {
115
+ return String(expiresAt);
116
+ }
117
+ const diffSeconds = (expiresMs - Date.now()) / 1000;
118
+ if (diffSeconds <= 0) {
119
+ return `${new Date(expiresMs).toISOString()} (expired)`;
120
+ }
121
+ const hours = Math.floor(diffSeconds / 3600);
122
+ const minutes = Math.floor((diffSeconds % 3600) / 60);
123
+ return `in ${hours}h ${minutes}m`;
124
+ }
125
+ }
@@ -0,0 +1,20 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class EphemeralImpersonate 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
+ guest: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'url-only': import("@oclif/core/interfaces").BooleanFlag<boolean>;
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
+ private getFrontendUrl;
19
+ private getImpersonateResponse;
20
+ }
@@ -0,0 +1,120 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import open from 'open';
3
+ import BaseCommand from '../../../base-command.js';
4
+ export default class EphemeralImpersonate extends BaseCommand {
5
+ static args = {
6
+ tenant_name: Args.string({
7
+ description: 'Ephemeral tenant name to impersonate',
8
+ required: true,
9
+ }),
10
+ };
11
+ static description = 'Impersonate an ephemeral tenant and open it in the browser';
12
+ static examples = [
13
+ `$ xano ephemeral impersonate e4f2-9ab1-xyz1
14
+ Opening browser...
15
+ Impersonation successful!
16
+ `,
17
+ `$ xano ephemeral impersonate e4f2-9ab1-xyz1 -o json`,
18
+ `$ xano ephemeral impersonate e4f2-9ab1-xyz1 --guest --url-only`,
19
+ ];
20
+ static flags = {
21
+ ...BaseCommand.baseFlags,
22
+ guest: Flags.boolean({
23
+ char: 'g',
24
+ default: false,
25
+ description: 'Mint a read-only guest session (browse only; no schema/data/config changes)',
26
+ required: false,
27
+ }),
28
+ output: Flags.string({
29
+ char: 'o',
30
+ default: 'summary',
31
+ description: 'Output format',
32
+ options: ['summary', 'json'],
33
+ required: false,
34
+ }),
35
+ 'url-only': Flags.boolean({
36
+ char: 'u',
37
+ default: false,
38
+ description: 'Print the URL without opening the browser',
39
+ required: false,
40
+ }),
41
+ workspace: Flags.string({
42
+ char: 'w',
43
+ description: 'Workspace ID (uses profile workspace if not provided)',
44
+ required: false,
45
+ }),
46
+ };
47
+ async run() {
48
+ const { args, flags } = await this.parse(EphemeralImpersonate);
49
+ const { profile } = this.resolveProfile(flags);
50
+ const workspaceId = flags.workspace || profile.workspace;
51
+ if (!workspaceId) {
52
+ this.error('No workspace ID provided. Use --workspace flag or set one in your profile.');
53
+ }
54
+ const tenantName = args.tenant_name;
55
+ try {
56
+ const response = await this.getImpersonateResponse(profile, workspaceId, tenantName, flags.guest);
57
+ if (flags.output === 'json') {
58
+ this.log(JSON.stringify(response, null, 2));
59
+ }
60
+ else {
61
+ const frontendUrl = this.getFrontendUrl(profile.instance_origin);
62
+ const params = new URLSearchParams({
63
+ _ti: response._ti,
64
+ });
65
+ const impersonateUrl = `${frontendUrl}/impersonate?${params.toString()}`;
66
+ if (flags['url-only']) {
67
+ this.log(impersonateUrl);
68
+ }
69
+ else {
70
+ this.log('Opening browser...');
71
+ await open(impersonateUrl);
72
+ this.log('Impersonation successful!');
73
+ }
74
+ }
75
+ process.exit(0);
76
+ }
77
+ catch (error) {
78
+ if (error instanceof Error) {
79
+ this.error(`Failed to impersonate tenant: ${error.message}`);
80
+ }
81
+ else {
82
+ this.error(`Failed to impersonate tenant: ${String(error)}`);
83
+ }
84
+ }
85
+ }
86
+ getFrontendUrl(instanceOrigin) {
87
+ try {
88
+ const url = new URL(instanceOrigin);
89
+ if (url.hostname === 'localhost' || url.hostname === '127.0.0.1') {
90
+ url.port = '4200';
91
+ return url.origin;
92
+ }
93
+ }
94
+ catch {
95
+ // fall through
96
+ }
97
+ return instanceOrigin;
98
+ }
99
+ async getImpersonateResponse(profile, workspaceId, tenantName, guest = false) {
100
+ const query = guest ? '?guest_read_only=true' : '';
101
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${encodeURIComponent(tenantName)}/impersonate${query}`;
102
+ const { verbose } = await this.parse(EphemeralImpersonate).then((r) => r.flags);
103
+ const response = await this.verboseFetch(apiUrl, {
104
+ headers: {
105
+ accept: 'application/json',
106
+ Authorization: `Bearer ${profile.access_token}`,
107
+ },
108
+ method: 'GET',
109
+ }, verbose, profile.access_token);
110
+ if (!response.ok) {
111
+ const errorText = await response.text();
112
+ throw new Error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
113
+ }
114
+ const result = (await response.json());
115
+ if (!result._ti) {
116
+ throw new Error('No one-time token returned from impersonate API');
117
+ }
118
+ return result;
119
+ }
120
+ }
@@ -0,0 +1,19 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class EphemeralList extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ global: import("@oclif/core/interfaces").BooleanFlag<boolean>;
7
+ output: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
8
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
9
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
10
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
11
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ };
13
+ run(): Promise<void>;
14
+ /**
15
+ * Render a unix-epoch-seconds expiration as a human-readable "in Xh Ym" string,
16
+ * falling back to an ISO timestamp if the value has already passed or is malformed.
17
+ */
18
+ private formatExpiration;
19
+ }
@@ -0,0 +1,123 @@
1
+ import { Flags } from '@oclif/core';
2
+ import BaseCommand from '../../../base-command.js';
3
+ import { buildPagingJson } from '../../../utils/paging.js';
4
+ export default class EphemeralList extends BaseCommand {
5
+ static description = 'List ephemeral tenants in a workspace, or across the whole instance with --global';
6
+ static examples = [
7
+ `$ xano ephemeral list
8
+ Ephemeral tenants in workspace 5:
9
+ - PR preview (e4f2-9ab1-...) [ok] - expires in 1h 0m
10
+ - Demo (e7a3-2c10-...) [ok] - expires in 23h 12m
11
+ `,
12
+ `$ xano ephemeral list --global
13
+ Ephemeral tenants (all workspaces):
14
+ - PR preview (e4f2-9ab1-...) [ok] - expires in 1h 0m
15
+ `,
16
+ `$ xano ephemeral list -w 5 -o json`,
17
+ ];
18
+ static flags = {
19
+ ...BaseCommand.baseFlags,
20
+ global: Flags.boolean({
21
+ default: false,
22
+ description: 'List ephemeral tenants across the whole instance (all workspaces)',
23
+ required: false,
24
+ }),
25
+ output: Flags.string({
26
+ char: 'o',
27
+ default: 'summary',
28
+ description: 'Output format',
29
+ options: ['summary', 'json'],
30
+ required: false,
31
+ }),
32
+ workspace: Flags.string({
33
+ char: 'w',
34
+ description: 'Workspace ID (uses profile workspace if not provided)',
35
+ required: false,
36
+ }),
37
+ };
38
+ async run() {
39
+ const { flags } = await this.parse(EphemeralList);
40
+ const { profile } = this.resolveProfile(flags);
41
+ let workspaceId;
42
+ let apiUrl;
43
+ if (flags.global) {
44
+ apiUrl = `${profile.instance_origin}/api:meta/ephemeral`;
45
+ }
46
+ else {
47
+ workspaceId = flags.workspace || profile.workspace;
48
+ if (!workspaceId) {
49
+ this.error('No workspace ID provided. Use --workspace flag or set one in your profile.');
50
+ }
51
+ apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/ephemeral`;
52
+ }
53
+ try {
54
+ const response = await this.verboseFetch(apiUrl, {
55
+ headers: {
56
+ accept: 'application/json',
57
+ Authorization: `Bearer ${profile.access_token}`,
58
+ },
59
+ method: 'GET',
60
+ }, flags.verbose, profile.access_token);
61
+ if (!response.ok) {
62
+ const errorText = await response.text();
63
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
64
+ }
65
+ const data = (await response.json());
66
+ let tenants;
67
+ if (Array.isArray(data)) {
68
+ tenants = data;
69
+ }
70
+ else if (data && typeof data === 'object' && Array.isArray(data.items)) {
71
+ tenants = data.items;
72
+ }
73
+ else {
74
+ this.error('Unexpected API response format');
75
+ }
76
+ if (flags.output === 'json') {
77
+ this.log(JSON.stringify(buildPagingJson({ items: tenants }, { tier: 'none' }), null, 2));
78
+ }
79
+ else if (tenants.length === 0) {
80
+ this.log('No ephemeral tenants found');
81
+ }
82
+ else {
83
+ this.log(flags.global ? 'Ephemeral tenants (all workspaces):' : `Ephemeral tenants in workspace ${workspaceId}:`);
84
+ for (const tenant of tenants) {
85
+ const state = tenant.state ? ` [${tenant.state}]` : '';
86
+ const expires = ` - expires ${this.formatExpiration(tenant.ephemeral_expires_at)}`;
87
+ const workspaceLabel = flags.global && tenant.workspace_id ? ` (workspace ${tenant.workspace_id})` : '';
88
+ this.log(` - ${tenant.display || tenant.name} (${tenant.name})${state}${expires}${workspaceLabel}`);
89
+ }
90
+ }
91
+ }
92
+ catch (error) {
93
+ if (error instanceof Error) {
94
+ this.error(`Failed to list ephemeral tenants: ${error.message}`);
95
+ }
96
+ else {
97
+ this.error(`Failed to list ephemeral tenants: ${String(error)}`);
98
+ }
99
+ }
100
+ }
101
+ /**
102
+ * Render a unix-epoch-seconds expiration as a human-readable "in Xh Ym" string,
103
+ * falling back to an ISO timestamp if the value has already passed or is malformed.
104
+ */
105
+ formatExpiration(expiresAt) {
106
+ if (!expiresAt) {
107
+ return '-';
108
+ }
109
+ // The API serializes the timestamp field as a date string
110
+ // ("2026-07-24 19:49:15+0000"); tolerate a raw unix-epoch number too.
111
+ const expiresMs = typeof expiresAt === 'number' ? expiresAt * 1000 : Date.parse(String(expiresAt).replace(' ', 'T'));
112
+ if (Number.isNaN(expiresMs)) {
113
+ return String(expiresAt);
114
+ }
115
+ const diffSeconds = (expiresMs - Date.now()) / 1000;
116
+ if (diffSeconds <= 0) {
117
+ return `${new Date(expiresMs).toISOString()} (expired)`;
118
+ }
119
+ const hours = Math.floor(diffSeconds / 3600);
120
+ const minutes = Math.floor((diffSeconds % 3600) / 60);
121
+ return `in ${hours}h ${minutes}m`;
122
+ }
123
+ }
@@ -0,0 +1,19 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class EphemeralPull 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
+ directory: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
10
+ draft: import("@oclif/core/interfaces").BooleanFlag<boolean>;
11
+ env: import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ records: import("@oclif/core/interfaces").BooleanFlag<boolean>;
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,163 @@
1
+ import { Args, Flags } from '@oclif/core';
2
+ import snakeCase from 'lodash.snakecase';
3
+ import * as fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import BaseCommand from '../../../base-command.js';
6
+ import { buildApiGroupFolderResolver, buildChannelServerResolver, parseDocument, resolveDocumentPath, } from '../../../utils/document-parser.js';
7
+ export default class EphemeralPull extends BaseCommand {
8
+ static args = {
9
+ tenant_name: Args.string({
10
+ description: 'Ephemeral tenant name to pull from',
11
+ required: true,
12
+ }),
13
+ };
14
+ static description = 'Pull an ephemeral tenant multidoc from the Xano Metadata API and split into individual files';
15
+ static examples = [
16
+ `$ xano ephemeral pull e4f2-9ab1-xyz1
17
+ Pulled 42 documents from tenant e4f2-9ab1-xyz1 to current directory
18
+ `,
19
+ `$ xano ephemeral pull e4f2-9ab1-xyz1 -d ./my-tenant
20
+ Pulled 42 documents from tenant e4f2-9ab1-xyz1 to ./my-tenant
21
+ `,
22
+ `$ xano ephemeral pull e4f2-9ab1-xyz1 -d ./output -w 40
23
+ Pulled 15 documents from tenant e4f2-9ab1-xyz1 to ./output
24
+ `,
25
+ `$ xano ephemeral pull e4f2-9ab1-xyz1 --profile production --env --records
26
+ Pulled 58 documents from tenant e4f2-9ab1-xyz1
27
+ `,
28
+ `$ xano ephemeral pull e4f2-9ab1-xyz1 --draft`,
29
+ ];
30
+ static flags = {
31
+ ...BaseCommand.baseFlags,
32
+ directory: Flags.string({
33
+ char: 'd',
34
+ default: '.',
35
+ description: 'Output directory for pulled documents (defaults to current directory)',
36
+ required: false,
37
+ }),
38
+ draft: Flags.boolean({
39
+ default: false,
40
+ description: 'Include draft versions',
41
+ required: false,
42
+ }),
43
+ env: Flags.boolean({
44
+ default: false,
45
+ description: 'Include environment variables',
46
+ required: false,
47
+ }),
48
+ records: Flags.boolean({
49
+ default: false,
50
+ description: 'Include records',
51
+ required: false,
52
+ }),
53
+ workspace: Flags.string({
54
+ char: 'w',
55
+ description: 'Workspace ID (optional if set in profile)',
56
+ required: false,
57
+ }),
58
+ };
59
+ async run() {
60
+ const { args, flags } = await this.parse(EphemeralPull);
61
+ const { profile, profileName } = this.resolveProfile(flags);
62
+ // Determine workspace_id from flag or profile
63
+ let workspaceId;
64
+ if (flags.workspace) {
65
+ workspaceId = flags.workspace;
66
+ }
67
+ else if (profile.workspace) {
68
+ workspaceId = profile.workspace;
69
+ }
70
+ else {
71
+ this.error(`Workspace ID is required. Either:\n` +
72
+ ` 1. Provide it as a flag: xano ephemeral pull <tenant_name> -w <workspace_id>\n` +
73
+ ` 2. Set it in your profile using: xano profile:edit ${profileName} -w <workspace_id>`);
74
+ }
75
+ const tenantName = args.tenant_name;
76
+ // Build query parameters
77
+ const queryParams = new URLSearchParams({
78
+ env: flags.env.toString(),
79
+ include_draft: flags.draft.toString(),
80
+ records: flags.records.toString(),
81
+ });
82
+ // Construct the API URL
83
+ const apiUrl = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/tenant/${tenantName}/multidoc?${queryParams.toString()}`;
84
+ // Fetch multidoc from the API
85
+ let responseText;
86
+ const requestHeaders = {
87
+ accept: 'application/json',
88
+ Authorization: `Bearer ${profile.access_token}`,
89
+ };
90
+ try {
91
+ const response = await this.verboseFetch(apiUrl, {
92
+ headers: requestHeaders,
93
+ method: 'GET',
94
+ }, flags.verbose, profile.access_token);
95
+ if (!response.ok) {
96
+ const errorText = await response.text();
97
+ this.error(`API request failed with status ${response.status}: ${response.statusText}\n${errorText}`);
98
+ }
99
+ responseText = await response.text();
100
+ }
101
+ catch (error) {
102
+ if (error instanceof Error) {
103
+ this.error(`Failed to fetch multidoc: ${error.message}`);
104
+ }
105
+ else {
106
+ this.error(`Failed to fetch multidoc: ${String(error)}`);
107
+ }
108
+ }
109
+ // Split the response into individual documents
110
+ const rawDocuments = responseText.split('\n---\n');
111
+ // Parse each document
112
+ const documents = [];
113
+ for (const raw of rawDocuments) {
114
+ const trimmed = raw.trim();
115
+ if (!trimmed) {
116
+ continue;
117
+ }
118
+ const parsed = parseDocument(trimmed);
119
+ if (parsed) {
120
+ documents.push(parsed);
121
+ }
122
+ }
123
+ if (documents.length === 0) {
124
+ this.log('No documents found in response');
125
+ return;
126
+ }
127
+ // Resolve the output directory
128
+ const outputDir = path.resolve(flags.directory);
129
+ // Create the output directory if it doesn't exist
130
+ fs.mkdirSync(outputDir, { recursive: true });
131
+ // Resolve api_group names to unique folder names, disambiguating collisions
132
+ const getApiGroupFolder = buildApiGroupFolderResolver(documents, snakeCase);
133
+ // Resolve a realtime v2 channel path -> owning realtime_server name, so
134
+ // messages can nest under their channel's server (see resolver docs).
135
+ const getChannelServer = buildChannelServerResolver(documents);
136
+ // Track filenames per type to handle duplicates
137
+ const filenameCounters = new Map();
138
+ let writtenCount = 0;
139
+ for (const doc of documents) {
140
+ const { baseName, typeDir } = resolveDocumentPath(doc, outputDir, {
141
+ getApiGroupFolder,
142
+ getChannelServer,
143
+ join: path.join,
144
+ snakeCase,
145
+ });
146
+ fs.mkdirSync(typeDir, { recursive: true });
147
+ // Track duplicates per directory
148
+ const dirKey = path.relative(outputDir, typeDir);
149
+ if (!filenameCounters.has(dirKey)) {
150
+ filenameCounters.set(dirKey, new Map());
151
+ }
152
+ const typeCounters = filenameCounters.get(dirKey);
153
+ const count = typeCounters.get(baseName) || 0;
154
+ typeCounters.set(baseName, count + 1);
155
+ // Append numeric suffix for duplicates
156
+ const filename = count === 0 ? `${baseName}.xs` : `${baseName}_${count + 1}.xs`;
157
+ const filePath = path.join(typeDir, filename);
158
+ fs.writeFileSync(filePath, doc.content, 'utf8');
159
+ writtenCount++;
160
+ }
161
+ this.log(`Pulled ${writtenCount} documents from tenant ${tenantName} to ${flags.directory}`);
162
+ }
163
+ }
@@ -0,0 +1,35 @@
1
+ import BaseCommand from '../../../base-command.js';
2
+ export default class EphemeralPush 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
+ delete: import("@oclif/core/interfaces").BooleanFlag<boolean>;
10
+ directory: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
11
+ 'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
12
+ env: import("@oclif/core/interfaces").BooleanFlag<boolean>;
13
+ force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
14
+ guids: import("@oclif/core/interfaces").BooleanFlag<boolean>;
15
+ records: import("@oclif/core/interfaces").BooleanFlag<boolean>;
16
+ sync: import("@oclif/core/interfaces").BooleanFlag<boolean>;
17
+ transaction: import("@oclif/core/interfaces").BooleanFlag<boolean>;
18
+ truncate: import("@oclif/core/interfaces").BooleanFlag<boolean>;
19
+ wait: import("@oclif/core/interfaces").BooleanFlag<boolean>;
20
+ 'wait-timeout': import("@oclif/core/interfaces").OptionFlag<number, import("@oclif/core/interfaces").CustomOptions>;
21
+ workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
22
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
23
+ profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
24
+ verbose: import("@oclif/core/interfaces").BooleanFlag<boolean>;
25
+ };
26
+ /** Number of lines the last progress render wrote (for in-place TTY updates). */
27
+ private lastRenderLines;
28
+ run(): Promise<void>;
29
+ /**
30
+ * Poll GET .../tenant/{name}/microservice until auto microservices settle.
31
+ * Renders a one-line-per-microservice progress view that updates in place, then
32
+ * exits non-zero if any auto microservice failed or the wait timed out.
33
+ */
34
+ private waitForDeploy;
35
+ }