@xano/cli 1.0.4-beta.2 → 1.0.4
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.
- package/README.md +4 -51
- package/dist/base-command.d.ts +0 -27
- package/dist/base-command.js +1 -124
- package/dist/commands/auth/index.d.ts +0 -7
- package/dist/commands/auth/index.js +9 -85
- package/dist/commands/{tenant/snapshot/list → knowledge/pull}/index.d.ts +4 -6
- package/dist/commands/knowledge/pull/index.js +86 -0
- package/dist/commands/knowledge/push/index.d.ts +20 -0
- package/dist/commands/knowledge/push/index.js +126 -0
- package/dist/commands/static_host/build/create/index.d.ts +1 -9
- package/dist/commands/static_host/build/create/index.js +4 -54
- package/dist/commands/static_host/build/get/index.d.ts +1 -1
- package/dist/commands/static_host/build/get/index.js +10 -16
- package/dist/utils/knowledge-sync.d.ts +108 -0
- package/dist/utils/knowledge-sync.js +380 -0
- package/dist/utils/multidoc-push.js +17 -21
- package/dist/utils/reference-checker.js +2 -2
- package/oclif.manifest.json +2565 -3683
- package/package.json +1 -3
- package/dist/commands/static_host/build/delete/index.d.ts +0 -19
- package/dist/commands/static_host/build/delete/index.js +0 -114
- package/dist/commands/static_host/build/pull/index.d.ts +0 -52
- package/dist/commands/static_host/build/pull/index.js +0 -300
- package/dist/commands/static_host/build/push/index.d.ts +0 -23
- package/dist/commands/static_host/build/push/index.js +0 -225
- package/dist/commands/static_host/create/index.d.ts +0 -17
- package/dist/commands/static_host/create/index.js +0 -86
- package/dist/commands/static_host/deploy/index.d.ts +0 -18
- package/dist/commands/static_host/deploy/index.js +0 -105
- package/dist/commands/static_host/edit/index.d.ts +0 -23
- package/dist/commands/static_host/edit/index.js +0 -151
- package/dist/commands/static_host/get/index.d.ts +0 -18
- package/dist/commands/static_host/get/index.js +0 -94
- package/dist/commands/static_host/migrate/index.d.ts +0 -44
- package/dist/commands/static_host/migrate/index.js +0 -205
- package/dist/commands/tenant/snapshot/create/index.d.ts +0 -17
- package/dist/commands/tenant/snapshot/create/index.js +0 -78
- package/dist/commands/tenant/snapshot/delete/index.d.ts +0 -19
- package/dist/commands/tenant/snapshot/delete/index.js +0 -102
- package/dist/commands/tenant/snapshot/list/index.js +0 -96
- package/dist/commands/tenant/snapshot/swap/index.d.ts +0 -19
- package/dist/commands/tenant/snapshot/swap/index.js +0 -103
package/README.md
CHANGED
|
@@ -47,13 +47,6 @@ xano auth
|
|
|
47
47
|
xano auth --origin https://custom.xano.com
|
|
48
48
|
xano auth --insecure # Skip TLS verification (self-signed certs)
|
|
49
49
|
xano auth --no-browser # Headless login (no local callback server)
|
|
50
|
-
|
|
51
|
-
# Pre-select instance/workspace/branch and profile name (skips the pickers)
|
|
52
|
-
xano auth -i my-instance -w 5 -b dev -p staging
|
|
53
|
-
xano auth --instance my-instance --workspace "My Workspace" --branch dev --profile staging
|
|
54
|
-
|
|
55
|
-
# Pass "" to take a picker's default: skip workspace, use live branch, default profile name
|
|
56
|
-
xano auth -i my-instance -w 5 -b "" -p ""
|
|
57
50
|
```
|
|
58
51
|
|
|
59
52
|
The default flow starts a temporary callback server on `127.0.0.1` and waits
|
|
@@ -62,20 +55,12 @@ containers, or locked-down networks where the browser can't reach the CLI's
|
|
|
62
55
|
loopback address, use `--no-browser`: the CLI prints a login URL, you open it
|
|
63
56
|
in any browser, and paste back the code it displays. No local server required.
|
|
64
57
|
|
|
65
|
-
Each picker can be pre-answered with a flag: `-i/--instance` (instance name, or numeric instance ID),
|
|
66
|
-
`-w/--workspace` (workspace ID or name), `-b/--branch` (branch label), and
|
|
67
|
-
`-p/--profile` (profile name to save). An empty value (`""`) takes the
|
|
68
|
-
picker's default answer: `-w ""` skips workspace selection, `-b ""` skips and
|
|
69
|
-
uses the live branch, and `-p ""` uses the default profile name. With all four
|
|
70
|
-
set alongside `--no-browser`, the only input is pasting the code from the
|
|
71
|
-
browser — useful for scripted or remote setups.
|
|
72
|
-
|
|
73
58
|
When stdin is piped (not a TTY), `--no-browser` reads the code directly from
|
|
74
59
|
stdin instead of prompting, so scripts and AI agents can complete the flow
|
|
75
60
|
without an interactive terminal:
|
|
76
61
|
|
|
77
62
|
```bash
|
|
78
|
-
echo "$CODE" | xano auth --no-browser
|
|
63
|
+
echo "$CODE" | xano auth --no-browser
|
|
79
64
|
```
|
|
80
65
|
|
|
81
66
|
If you can't run `xano auth` at all, you can always create a profile manually
|
|
@@ -556,46 +541,14 @@ xano sandbox reset --force
|
|
|
556
541
|
# List static hosts
|
|
557
542
|
xano static_host list
|
|
558
543
|
|
|
559
|
-
# Create
|
|
560
|
-
xano static_host create
|
|
561
|
-
xano static_host get marketing
|
|
562
|
-
xano static_host edit marketing --name marketing-v2 --description "Updated"
|
|
544
|
+
# Create a build
|
|
545
|
+
xano static_host build create default -f ./build.zip -n "v1.0.0"
|
|
563
546
|
|
|
564
547
|
# List builds
|
|
565
548
|
xano static_host build list default
|
|
566
549
|
|
|
567
550
|
# Get build details
|
|
568
|
-
xano static_host build get default
|
|
569
|
-
|
|
570
|
-
# Pull a build to disk. Defaults to the original uploaded source
|
|
571
|
-
# (including package.json). Use --source built for the compiled/served output.
|
|
572
|
-
xano static_host build pull default --build_id 52 # By build ID (original source)
|
|
573
|
-
xano static_host build pull default --build_id 52 --source built # Compiled output
|
|
574
|
-
xano static_host build pull default --latest # Latest build
|
|
575
|
-
xano static_host build pull default --env dev # Build currently deployed to dev
|
|
576
|
-
xano static_host build pull default --env prod -d ./prod-release
|
|
577
|
-
|
|
578
|
-
# Push a build (name optional — auto-generated from the timestamp if omitted).
|
|
579
|
-
# Accepts a directory (-d) or a zip file (-f). Defaults to the current directory.
|
|
580
|
-
# For package.json builds, the CLI waits for the build to finish (--no-wait to skip).
|
|
581
|
-
xano static_host build push default -d ./dist -n "v1.0.0"
|
|
582
|
-
xano static_host build push default # current dir, auto-name
|
|
583
|
-
xano static_host build push default -f ./build.zip -n "v1.0.0" # from zip file
|
|
584
|
-
xano static_host build push default -n "release" --description "Production build"
|
|
585
|
-
|
|
586
|
-
# Delete a build (prompts for confirmation; --force to skip)
|
|
587
|
-
xano static_host build delete default --build_id 52
|
|
588
|
-
xano static_host build delete default --build_id 52 --force
|
|
589
|
-
|
|
590
|
-
# Deploy a build to an environment
|
|
591
|
-
xano static_host deploy default --build_id 52 --env dev
|
|
592
|
-
xano static_host deploy default --build_id 52 --env prod
|
|
593
|
-
|
|
594
|
-
# Migrate a host to instance-managed (v2) hosting
|
|
595
|
-
xano static_host migrate newsite # one host (both envs)
|
|
596
|
-
xano static_host migrate newsite --env dev # one env
|
|
597
|
-
xano static_host migrate --all # every v1 host in the workspace
|
|
598
|
-
xano static_host migrate --all --dry-run # preview without changing anything
|
|
551
|
+
xano static_host build get default 52
|
|
599
552
|
```
|
|
600
553
|
|
|
601
554
|
## Global Options
|
package/dist/base-command.d.ts
CHANGED
|
@@ -103,31 +103,4 @@ export default abstract class BaseCommand extends Command {
|
|
|
103
103
|
* Use this for all Metadata API calls to support the --verbose flag.
|
|
104
104
|
*/
|
|
105
105
|
protected verboseFetch(url: string, options: RequestInit, verbose: boolean, authToken?: string): Promise<Response>;
|
|
106
|
-
/**
|
|
107
|
-
* Poll a static-host build until it reaches a terminal status (ok | error),
|
|
108
|
-
* showing a live, ticking spinner with the current stage and elapsed time —
|
|
109
|
-
* mirroring the UI's build progress for async (package.json) builds, which
|
|
110
|
-
* keep running after the upload returns.
|
|
111
|
-
*
|
|
112
|
-
* On a TTY it renders an animated spinner via ux.action; when quiet (JSON
|
|
113
|
-
* output) or non-interactive it falls back to plain one-line status updates.
|
|
114
|
-
*
|
|
115
|
-
* Returns the final status. Resolves to the last-seen status on timeout.
|
|
116
|
-
*/
|
|
117
|
-
protected logStaticHostUrls(opts: {
|
|
118
|
-
profile: ProfileConfig;
|
|
119
|
-
staticHost: string;
|
|
120
|
-
verbose: boolean;
|
|
121
|
-
workspaceId: string;
|
|
122
|
-
}): Promise<void>;
|
|
123
|
-
protected waitForBuild(opts: {
|
|
124
|
-
buildId: number | string;
|
|
125
|
-
intervalMs?: number;
|
|
126
|
-
profile: ProfileConfig;
|
|
127
|
-
quiet?: boolean;
|
|
128
|
-
staticHost: string;
|
|
129
|
-
timeoutMs?: number;
|
|
130
|
-
verbose: boolean;
|
|
131
|
-
workspaceId: string;
|
|
132
|
-
}): Promise<string>;
|
|
133
106
|
}
|
package/dist/base-command.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Command, Flags
|
|
1
|
+
import { Command, Flags } from '@oclif/core';
|
|
2
2
|
import * as yaml from 'js-yaml';
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
4
|
import * as os from 'node:os';
|
|
@@ -358,127 +358,4 @@ export default class BaseCommand extends Command {
|
|
|
358
358
|
}
|
|
359
359
|
return response;
|
|
360
360
|
}
|
|
361
|
-
/**
|
|
362
|
-
* Poll a static-host build until it reaches a terminal status (ok | error),
|
|
363
|
-
* showing a live, ticking spinner with the current stage and elapsed time —
|
|
364
|
-
* mirroring the UI's build progress for async (package.json) builds, which
|
|
365
|
-
* keep running after the upload returns.
|
|
366
|
-
*
|
|
367
|
-
* On a TTY it renders an animated spinner via ux.action; when quiet (JSON
|
|
368
|
-
* output) or non-interactive it falls back to plain one-line status updates.
|
|
369
|
-
*
|
|
370
|
-
* Returns the final status. Resolves to the last-seen status on timeout.
|
|
371
|
-
*/
|
|
372
|
-
async logStaticHostUrls(opts) {
|
|
373
|
-
const { profile, staticHost, verbose, workspaceId } = opts;
|
|
374
|
-
const url = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${staticHost}`;
|
|
375
|
-
try {
|
|
376
|
-
const response = await this.verboseFetch(url, {
|
|
377
|
-
headers: { accept: 'application/json', Authorization: `Bearer ${profile.access_token}` },
|
|
378
|
-
method: 'GET',
|
|
379
|
-
}, verbose, profile.access_token);
|
|
380
|
-
if (!response.ok)
|
|
381
|
-
return;
|
|
382
|
-
const host = (await response.json());
|
|
383
|
-
if (host.dev?.default_url)
|
|
384
|
-
this.log(`Dev URL: ${host.dev.default_url}`);
|
|
385
|
-
if (host.dev?.custom_url)
|
|
386
|
-
this.log(`Dev Custom URL: ${host.dev.custom_url}`);
|
|
387
|
-
if (host.prod?.default_url)
|
|
388
|
-
this.log(`Prod URL: ${host.prod.default_url}`);
|
|
389
|
-
if (host.prod?.custom_url)
|
|
390
|
-
this.log(`Prod Custom URL: ${host.prod.custom_url}`);
|
|
391
|
-
}
|
|
392
|
-
catch {
|
|
393
|
-
// Non-fatal — the build succeeded, we just can't show the URL.
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
async waitForBuild(opts) {
|
|
397
|
-
const { buildId, profile, quiet, staticHost, verbose, workspaceId } = opts;
|
|
398
|
-
const intervalMs = opts.intervalMs ?? 2000;
|
|
399
|
-
const timeoutMs = opts.timeoutMs ?? 600_000; // 10 min
|
|
400
|
-
const terminal = new Set(['error', 'ok']);
|
|
401
|
-
const url = `${profile.instance_origin}/api:meta/workspace/${workspaceId}/static_host/${staticHost}/build/${buildId}`;
|
|
402
|
-
// Spinner only on an interactive TTY and when not emitting JSON. Verbose mode
|
|
403
|
-
// also disables it (the spinner would interleave with request/response logs).
|
|
404
|
-
const animate = Boolean(process.stdout.isTTY) && !quiet && !verbose;
|
|
405
|
-
const start = Date.now();
|
|
406
|
-
const elapsed = () => Math.round((Date.now() - start) / 1000);
|
|
407
|
-
let stage = 'pending';
|
|
408
|
-
let ticker;
|
|
409
|
-
// Reflect the current stage: live spinner status on a TTY, else a plain line.
|
|
410
|
-
const render = () => {
|
|
411
|
-
if (animate) {
|
|
412
|
-
ux.action.status = `${stageLabel(stage)} (${elapsed()}s)`;
|
|
413
|
-
}
|
|
414
|
-
else if (!quiet && !terminal.has(stage)) {
|
|
415
|
-
this.log(`Build status: ${stage}`);
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
// Stop the spinner/ticker and emit a final line.
|
|
419
|
-
const conclude = (message) => {
|
|
420
|
-
if (ticker)
|
|
421
|
-
clearInterval(ticker);
|
|
422
|
-
if (animate) {
|
|
423
|
-
ux.action.stop(message);
|
|
424
|
-
}
|
|
425
|
-
else if (!quiet) {
|
|
426
|
-
this.log(message);
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
if (animate) {
|
|
430
|
-
ux.action.start('Building', stageLabel(stage));
|
|
431
|
-
// Re-render every 120ms so the elapsed counter ticks even between polls.
|
|
432
|
-
ticker = setInterval(render, 120);
|
|
433
|
-
}
|
|
434
|
-
else if (!quiet) {
|
|
435
|
-
this.log(`Build status: ${stage}`);
|
|
436
|
-
}
|
|
437
|
-
/* eslint-disable no-await-in-loop */
|
|
438
|
-
while (Date.now() - start < timeoutMs) {
|
|
439
|
-
const response = await this.verboseFetch(url, {
|
|
440
|
-
headers: { accept: 'application/json', Authorization: `Bearer ${profile.access_token}` },
|
|
441
|
-
method: 'GET',
|
|
442
|
-
}, verbose, profile.access_token);
|
|
443
|
-
if (response.ok) {
|
|
444
|
-
const build = (await response.json());
|
|
445
|
-
const status = build.status ?? 'pending';
|
|
446
|
-
if (status !== stage) {
|
|
447
|
-
stage = status;
|
|
448
|
-
render();
|
|
449
|
-
}
|
|
450
|
-
if (terminal.has(status)) {
|
|
451
|
-
const took = `${elapsed()}s`;
|
|
452
|
-
conclude(status === 'ok' ? `done in ${took}` : `failed after ${took}`);
|
|
453
|
-
return status;
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
await new Promise((resolve) => {
|
|
457
|
-
setTimeout(resolve, intervalMs);
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
/* eslint-enable no-await-in-loop */
|
|
461
|
-
conclude(`stopped waiting after ${Math.round(timeoutMs / 1000)}s (last status: ${stage || 'unknown'})`);
|
|
462
|
-
return stage;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
/** Human-friendly label for a build status stage. */
|
|
466
|
-
function stageLabel(status) {
|
|
467
|
-
switch (status) {
|
|
468
|
-
case 'building': {
|
|
469
|
-
return 'Installing & building (npm)';
|
|
470
|
-
}
|
|
471
|
-
case 'ok': {
|
|
472
|
-
return 'Finishing';
|
|
473
|
-
}
|
|
474
|
-
case 'pending': {
|
|
475
|
-
return 'Queued';
|
|
476
|
-
}
|
|
477
|
-
case 'publishing': {
|
|
478
|
-
return 'Publishing files';
|
|
479
|
-
}
|
|
480
|
-
default: {
|
|
481
|
-
return status;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
361
|
}
|
|
@@ -3,14 +3,10 @@ export default class Auth extends Command {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
-
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
6
|
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
7
|
insecure: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
|
-
instance: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
8
|
'no-browser': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
11
9
|
origin: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
-
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
-
workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
10
|
};
|
|
15
11
|
run(): Promise<void>;
|
|
16
12
|
private getHeaders;
|
|
@@ -20,9 +16,6 @@ export default class Auth extends Command {
|
|
|
20
16
|
private promptForToken;
|
|
21
17
|
private promptProfileName;
|
|
22
18
|
private readTokenFromStdin;
|
|
23
|
-
private resolveBranch;
|
|
24
|
-
private resolveInstance;
|
|
25
|
-
private resolveWorkspace;
|
|
26
19
|
private saveProfile;
|
|
27
20
|
private selectBranch;
|
|
28
21
|
private selectInstance;
|
|
@@ -23,17 +23,10 @@ Opening browser for Xano login at https://custom.xano.com...`,
|
|
|
23
23
|
To authenticate, open the following URL in any browser:
|
|
24
24
|
https://app.xano.com/login?dest=cli&display=code
|
|
25
25
|
? Paste the code shown in your browser: ****`,
|
|
26
|
-
`$ xano auth --no-browser
|
|
27
|
-
(
|
|
28
|
-
`$ echo "$CODE" | xano auth --no-browser --instance my-instance --workspace 5 --branch dev --profile staging
|
|
29
|
-
(fully scripted: the code is read from piped stdin, no prompt at all)`,
|
|
26
|
+
`$ echo "$CODE" | xano auth --no-browser
|
|
27
|
+
(the code is read from piped stdin, no prompt at all)`,
|
|
30
28
|
];
|
|
31
29
|
static flags = {
|
|
32
|
-
branch: Flags.string({
|
|
33
|
-
char: 'b',
|
|
34
|
-
description: 'Pre-select a branch by label (skips the branch picker); pass "" to skip and use the live branch',
|
|
35
|
-
required: false,
|
|
36
|
-
}),
|
|
37
30
|
config: Flags.string({
|
|
38
31
|
char: 'c',
|
|
39
32
|
description: 'Path to credentials file (default: ~/.xano/credentials.yaml)',
|
|
@@ -45,11 +38,6 @@ To authenticate, open the following URL in any browser:
|
|
|
45
38
|
default: false,
|
|
46
39
|
description: 'Skip TLS certificate verification (for self-signed certificates)',
|
|
47
40
|
}),
|
|
48
|
-
instance: Flags.string({
|
|
49
|
-
char: 'i',
|
|
50
|
-
description: 'Pre-select an instance by name or numeric ID (skips the instance picker)',
|
|
51
|
-
required: false,
|
|
52
|
-
}),
|
|
53
41
|
'no-browser': Flags.boolean({
|
|
54
42
|
default: false,
|
|
55
43
|
description: 'Headless login: print a URL and paste back the code shown in the browser, instead of starting a local callback server (use on remote/SSH/Docker hosts where 127.0.0.1 is not reachable from the browser)',
|
|
@@ -59,16 +47,6 @@ To authenticate, open the following URL in any browser:
|
|
|
59
47
|
default: 'https://app.xano.com',
|
|
60
48
|
description: 'Xano account origin URL',
|
|
61
49
|
}),
|
|
62
|
-
profile: Flags.string({
|
|
63
|
-
char: 'p',
|
|
64
|
-
description: 'Profile name to save (skips the profile name prompt); pass "" to use the default name',
|
|
65
|
-
required: false,
|
|
66
|
-
}),
|
|
67
|
-
workspace: Flags.string({
|
|
68
|
-
char: 'w',
|
|
69
|
-
description: 'Pre-select a workspace by ID or name (skips the workspace picker); pass "" to skip workspace',
|
|
70
|
-
required: false,
|
|
71
|
-
}),
|
|
72
50
|
};
|
|
73
51
|
async run() {
|
|
74
52
|
const { flags } = await this.parse(Auth);
|
|
@@ -93,9 +71,6 @@ To authenticate, open the following URL in any browser:
|
|
|
93
71
|
const isSelfHosted = !/^https:\/\/app\.(.*\.)?xano\.com$/.test(flags.origin);
|
|
94
72
|
let instance;
|
|
95
73
|
if (isSelfHosted) {
|
|
96
|
-
if (flags.instance) {
|
|
97
|
-
this.warn('Ignoring --instance: the origin itself is the instance for self-hosted Xano.');
|
|
98
|
-
}
|
|
99
74
|
instance = {
|
|
100
75
|
display: flags.origin,
|
|
101
76
|
id: 'self-hosted',
|
|
@@ -110,7 +85,7 @@ To authenticate, open the following URL in any browser:
|
|
|
110
85
|
if (instances.length === 0) {
|
|
111
86
|
this.error('No instances found. Please check your account.');
|
|
112
87
|
}
|
|
113
|
-
instance = await this.
|
|
88
|
+
instance = await this.selectInstance(instances);
|
|
114
89
|
}
|
|
115
90
|
// Step 4: Workspace selection
|
|
116
91
|
let workspace;
|
|
@@ -119,25 +94,20 @@ To authenticate, open the following URL in any browser:
|
|
|
119
94
|
this.log('Fetching available workspaces...');
|
|
120
95
|
const workspaces = await this.fetchWorkspaces(token, instance.origin);
|
|
121
96
|
if (workspaces.length > 0) {
|
|
122
|
-
workspace = await this.
|
|
97
|
+
workspace = await this.selectWorkspace(workspaces);
|
|
123
98
|
if (workspace) {
|
|
124
99
|
// Step 5: Branch selection
|
|
125
100
|
this.log('');
|
|
126
101
|
this.log('Fetching available branches...');
|
|
127
102
|
const branches = await this.fetchBranches(token, instance.origin, workspace.id);
|
|
128
|
-
|
|
103
|
+
if (branches.length > 1) {
|
|
104
|
+
branch = await this.selectBranch(branches);
|
|
105
|
+
}
|
|
129
106
|
}
|
|
130
107
|
}
|
|
131
|
-
else if (flags.workspace) {
|
|
132
|
-
this.error(`Workspace '${flags.workspace}' not found: no workspaces are available on this instance.`);
|
|
133
|
-
}
|
|
134
|
-
if (flags.branch && !workspace) {
|
|
135
|
-
this.warn('Ignoring --branch: no workspace selected.');
|
|
136
|
-
}
|
|
137
108
|
// Step 6: Profile name
|
|
138
109
|
this.log('');
|
|
139
|
-
|
|
140
|
-
const profileName = flags.profile === undefined ? await this.promptProfileName() : flags.profile.trim() || 'default';
|
|
110
|
+
const profileName = await this.promptProfileName();
|
|
141
111
|
// Step 7: Save profile
|
|
142
112
|
await this.saveProfile({
|
|
143
113
|
access_token: token,
|
|
@@ -211,7 +181,7 @@ To authenticate, open the following URL in any browser:
|
|
|
211
181
|
if (Array.isArray(data)) {
|
|
212
182
|
return data.map((inst) => ({
|
|
213
183
|
display: inst.display,
|
|
214
|
-
id:
|
|
184
|
+
id: inst.id || inst.name,
|
|
215
185
|
name: inst.name,
|
|
216
186
|
origin: new URL(inst.meta_api).origin,
|
|
217
187
|
}));
|
|
@@ -308,52 +278,6 @@ To authenticate, open the following URL in any browser:
|
|
|
308
278
|
process.stdin.on('error', () => resolve(data.trim()));
|
|
309
279
|
});
|
|
310
280
|
}
|
|
311
|
-
async resolveBranch(branches, flagValue) {
|
|
312
|
-
if (flagValue !== undefined) {
|
|
313
|
-
// An empty value means "skip and use live branch" (same as the picker's skip option)
|
|
314
|
-
if (flagValue.trim() === '') {
|
|
315
|
-
this.log('Using live branch');
|
|
316
|
-
return undefined;
|
|
317
|
-
}
|
|
318
|
-
const match = branches.find((br) => br.label === flagValue || br.id === flagValue);
|
|
319
|
-
if (!match) {
|
|
320
|
-
this.error(`Branch '${flagValue}' not found. Available branches: ${branches.map((br) => br.label).join(', ')}`);
|
|
321
|
-
}
|
|
322
|
-
this.log(`Using branch: ${match.label}`);
|
|
323
|
-
return match.id;
|
|
324
|
-
}
|
|
325
|
-
return branches.length > 1 ? this.selectBranch(branches) : undefined;
|
|
326
|
-
}
|
|
327
|
-
async resolveInstance(instances, flagValue) {
|
|
328
|
-
if (flagValue) {
|
|
329
|
-
// Numeric values match by instance ID, anything else matches by name
|
|
330
|
-
const match = /^\d+$/.test(flagValue)
|
|
331
|
-
? instances.find((inst) => inst.id === flagValue)
|
|
332
|
-
: instances.find((inst) => inst.name === flagValue);
|
|
333
|
-
if (!match) {
|
|
334
|
-
this.error(`Instance '${flagValue}' not found. Available instances: ${instances.map((inst) => `${inst.name} (${inst.id})`).join(', ')}`);
|
|
335
|
-
}
|
|
336
|
-
this.log(`Using instance: ${match.name} (${match.display})`);
|
|
337
|
-
return match;
|
|
338
|
-
}
|
|
339
|
-
return this.selectInstance(instances);
|
|
340
|
-
}
|
|
341
|
-
async resolveWorkspace(workspaces, flagValue) {
|
|
342
|
-
if (flagValue !== undefined) {
|
|
343
|
-
// An empty value means "skip workspace" (same as the picker's skip option)
|
|
344
|
-
if (flagValue.trim() === '') {
|
|
345
|
-
this.log('Skipping workspace selection');
|
|
346
|
-
return undefined;
|
|
347
|
-
}
|
|
348
|
-
const match = workspaces.find((ws) => String(ws.id) === flagValue || ws.name === flagValue);
|
|
349
|
-
if (!match) {
|
|
350
|
-
this.error(`Workspace '${flagValue}' not found. Available workspaces: ${workspaces.map((ws) => `${ws.name} (${ws.id})`).join(', ')}`);
|
|
351
|
-
}
|
|
352
|
-
this.log(`Using workspace: ${match.name} (${match.id})`);
|
|
353
|
-
return match;
|
|
354
|
-
}
|
|
355
|
-
return this.selectWorkspace(workspaces);
|
|
356
|
-
}
|
|
357
281
|
async saveProfile(profile, configPath) {
|
|
358
282
|
const credentialsPath = resolveCredentialsPath(configPath);
|
|
359
283
|
const credDir = dirname(credentialsPath);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import BaseCommand from '
|
|
2
|
-
export default class
|
|
3
|
-
static args: {
|
|
4
|
-
tenant_name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
5
|
-
};
|
|
1
|
+
import BaseCommand from '../../../base-command.js';
|
|
2
|
+
export default class KnowledgePull extends BaseCommand {
|
|
6
3
|
static description: string;
|
|
7
4
|
static examples: string[];
|
|
8
5
|
static flags: {
|
|
9
|
-
|
|
6
|
+
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
directory: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
8
|
workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
9
|
config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
10
|
profile: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Flags } from '@oclif/core';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import BaseCommand from '../../../base-command.js';
|
|
5
|
+
import { fetchKnowledgeList, safeKnowledgePath } from '../../../utils/knowledge-sync.js';
|
|
6
|
+
export default class KnowledgePull extends BaseCommand {
|
|
7
|
+
static description = 'Pull knowledge files from a workspace. Each knowledge item name is a path (e.g. "some/thing/CLAUDE.md") and its content is written to that path under the output directory.';
|
|
8
|
+
static examples = [
|
|
9
|
+
`$ xano knowledge pull
|
|
10
|
+
Pulled 4 knowledge files to current directory
|
|
11
|
+
`,
|
|
12
|
+
`$ xano knowledge pull -d ./knowledge
|
|
13
|
+
Pulled 4 knowledge files to ./knowledge
|
|
14
|
+
`,
|
|
15
|
+
`$ xano knowledge pull -d ./knowledge -w 40`,
|
|
16
|
+
`$ xano knowledge pull -b dev`,
|
|
17
|
+
];
|
|
18
|
+
static flags = {
|
|
19
|
+
...BaseCommand.baseFlags,
|
|
20
|
+
branch: Flags.string({
|
|
21
|
+
char: 'b',
|
|
22
|
+
description: 'Branch name (optional if set in profile, defaults to live)',
|
|
23
|
+
required: false,
|
|
24
|
+
}),
|
|
25
|
+
directory: Flags.string({
|
|
26
|
+
char: 'd',
|
|
27
|
+
default: '.',
|
|
28
|
+
description: 'Output directory for pulled knowledge files (defaults to current directory)',
|
|
29
|
+
required: false,
|
|
30
|
+
}),
|
|
31
|
+
workspace: Flags.string({
|
|
32
|
+
char: 'w',
|
|
33
|
+
description: 'Workspace ID (optional if set in profile)',
|
|
34
|
+
required: false,
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
async run() {
|
|
38
|
+
const { flags } = await this.parse(KnowledgePull);
|
|
39
|
+
const { profile, profileName } = this.resolveProfile(flags);
|
|
40
|
+
// Determine workspace_id from flag or profile
|
|
41
|
+
let workspaceId;
|
|
42
|
+
if (flags.workspace) {
|
|
43
|
+
workspaceId = flags.workspace;
|
|
44
|
+
}
|
|
45
|
+
else if (profile.workspace) {
|
|
46
|
+
workspaceId = profile.workspace;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.error(`Workspace ID is required. Either:\n` +
|
|
50
|
+
` 1. Provide it as a flag: xano knowledge pull -w <workspace_id>\n` +
|
|
51
|
+
` 2. Set it in your profile using: xano profile:edit ${profileName} -w <workspace_id>`);
|
|
52
|
+
}
|
|
53
|
+
const branch = flags.branch || profile.branch || '';
|
|
54
|
+
let items;
|
|
55
|
+
try {
|
|
56
|
+
items = await fetchKnowledgeList({
|
|
57
|
+
accessToken: profile.access_token,
|
|
58
|
+
branch,
|
|
59
|
+
instanceOrigin: profile.instance_origin,
|
|
60
|
+
verboseFetch: this.verboseFetch.bind(this),
|
|
61
|
+
workspaceId,
|
|
62
|
+
}, flags.verbose);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
this.error(`Failed to fetch knowledge: ${error.message}`);
|
|
66
|
+
}
|
|
67
|
+
if (items.length === 0) {
|
|
68
|
+
this.log('No knowledge found in workspace');
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const outputDir = resolve(flags.directory);
|
|
72
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
73
|
+
let writtenCount = 0;
|
|
74
|
+
for (const item of items) {
|
|
75
|
+
const filePath = safeKnowledgePath(outputDir, item.name);
|
|
76
|
+
if (!filePath) {
|
|
77
|
+
this.warn(`Skipping knowledge "${item.name}": name is not a safe relative path`);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
fs.mkdirSync(dirname(filePath), { recursive: true });
|
|
81
|
+
fs.writeFileSync(filePath, item.content ?? '', 'utf8');
|
|
82
|
+
writtenCount++;
|
|
83
|
+
}
|
|
84
|
+
this.log(`Pulled ${writtenCount} knowledge files to ${flags.directory}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BaseCommand from '../../../base-command.js';
|
|
2
|
+
export default class KnowledgePush extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
branch: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
delete: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
8
|
+
directory: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'dry-run': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
10
|
+
exclude: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
force: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
include: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
sync: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
14
|
+
workspace: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
|
+
config: 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
|
+
}
|