@getxflow/cli 0.21.0 → 0.22.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.
- package/dist/commands/db.js +21 -8
- package/dist/commands/deploy.js +9 -6
- package/dist/commands/dev.js +11 -0
- package/dist/help.js +7 -2
- package/dist/json-arg.js +2 -5
- package/dist/template.js +12 -3
- package/dist/text-file.js +23 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/xflow/SKILL.md +7 -5
package/dist/commands/db.js
CHANGED
|
@@ -13,6 +13,7 @@ const args_1 = require("../args");
|
|
|
13
13
|
const config_1 = require("../config");
|
|
14
14
|
const errors_1 = require("../errors");
|
|
15
15
|
const session_1 = require("../session");
|
|
16
|
+
const text_file_1 = require("../text-file");
|
|
16
17
|
const ui_1 = require("../ui");
|
|
17
18
|
/** Migration files live in the repo; the applied history lives in the database. */
|
|
18
19
|
const MIGRATIONS_DIR = 'migrations';
|
|
@@ -92,12 +93,18 @@ async function dbStatus(args) {
|
|
|
92
93
|
(0, ui_1.warn)('A changed file will not be applied again: write a new migration');
|
|
93
94
|
}
|
|
94
95
|
}
|
|
96
|
+
function attachedProjects(database) {
|
|
97
|
+
const names = database.projects.map((project) => project.name);
|
|
98
|
+
if (database.hidden_projects > 0)
|
|
99
|
+
names.push(`+${database.hidden_projects} without access`);
|
|
100
|
+
return names.length === 0 ? 'no projects' : names.join(', ');
|
|
101
|
+
}
|
|
95
102
|
/**
|
|
96
103
|
* Logical databases of the organization, and who is attached to them.
|
|
97
104
|
*
|
|
98
105
|
* The identifier is what `xflow init --database <id>` asks for, and the list of
|
|
99
|
-
* projects is not decoration: a database
|
|
100
|
-
* one application lands in the others too.
|
|
106
|
+
* projects is not decoration: a database can be shared, so a migration written
|
|
107
|
+
* for one application lands in the others too.
|
|
101
108
|
*/
|
|
102
109
|
async function dbList() {
|
|
103
110
|
const client = (0, session_1.connect)((0, config_1.localConfig)());
|
|
@@ -111,13 +118,15 @@ async function dbList() {
|
|
|
111
118
|
database.name,
|
|
112
119
|
database.id,
|
|
113
120
|
database.schema ?? '-',
|
|
114
|
-
database
|
|
115
|
-
? 'no projects'
|
|
116
|
-
: database.projects.map((project) => project.name).join(', '),
|
|
121
|
+
attachedProjects(database),
|
|
117
122
|
]));
|
|
118
123
|
if (data.truncated)
|
|
119
124
|
(0, ui_1.note)((0, ui_1.dim)(` Shown ${data.databases.length} of ${data.total}`));
|
|
120
|
-
|
|
125
|
+
for (const database of data.databases) {
|
|
126
|
+
const attached = database.projects.length + database.hidden_projects;
|
|
127
|
+
if (attached > 1)
|
|
128
|
+
(0, ui_1.note)((0, ui_1.dim)(` ${database.name} is shared by ${attached} projects: a migration affects all of them`));
|
|
129
|
+
}
|
|
121
130
|
}
|
|
122
131
|
/** Long values would tear the columns apart; the cut is marked, never silent. */
|
|
123
132
|
const CELL_LIMIT = 60;
|
|
@@ -179,9 +188,13 @@ async function dbSchema(args) {
|
|
|
179
188
|
* database itself rather than by us guessing at the text of the SQL.
|
|
180
189
|
*/
|
|
181
190
|
async function dbQuery(args) {
|
|
182
|
-
const
|
|
191
|
+
const typed = args.words.join(' ').trim();
|
|
192
|
+
const sql = /\.sql$/i.test(typed)
|
|
193
|
+
? (0, text_file_1.readTextFile)(typed, 'An argument ending in .sql is read as a file: check the path, or end the query with ;')
|
|
194
|
+
: typed;
|
|
183
195
|
if (!sql) {
|
|
184
|
-
throw new errors_1.CliError('A query is required', 'For example: xflow db query "select * from orders order by created_at desc limit 20"'
|
|
196
|
+
throw new errors_1.CliError(typed ? `${typed} is empty` : 'A query is required', 'For example: xflow db query "select * from orders order by created_at desc limit 20", ' +
|
|
197
|
+
'or a long one from a file outside the project: xflow db query ../report.sql');
|
|
185
198
|
}
|
|
186
199
|
const { projectId, client } = await (0, session_1.projectTarget)(args);
|
|
187
200
|
const data = await (0, api_1.apiJson)(client, `/api/v1/projects/${projectId}/db/query`, {
|
package/dist/commands/deploy.js
CHANGED
|
@@ -171,17 +171,20 @@ async function deploy(args) {
|
|
|
171
171
|
(0, ui_1.out)(build.project_url);
|
|
172
172
|
// The functions were shipped by the build itself, so their addresses are known
|
|
173
173
|
// only now. A failure here does not undo a finished build: warn and stop there.
|
|
174
|
+
let functions = null;
|
|
174
175
|
try {
|
|
175
|
-
|
|
176
|
-
if (functions.length > 0) {
|
|
177
|
-
(0, ui_1.note)((0, ui_1.dim)(` Functions in .env: ${functions.join(', ')}`));
|
|
178
|
-
}
|
|
176
|
+
functions = await refreshPlatformEnv(root, client, config.projectId);
|
|
179
177
|
}
|
|
180
178
|
catch {
|
|
181
179
|
(0, ui_1.warn)('Could not refresh the function addresses in .env, the build itself is fine');
|
|
182
180
|
}
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
if (functions === null) {
|
|
182
|
+
(0, ui_1.note)((0, ui_1.dim)(' The cloud functions of this build are already live: publishing does not hold them back'));
|
|
183
|
+
}
|
|
184
|
+
else if (functions.length > 0) {
|
|
185
|
+
(0, ui_1.note)((0, ui_1.dim)(` Cloud functions live now: ${functions.join(', ')}`));
|
|
186
|
+
(0, ui_1.note)((0, ui_1.dim)(' There is one copy per project, publishing does not hold them back'));
|
|
187
|
+
}
|
|
185
188
|
(0, ui_1.note)((0, ui_1.dim)(' Show the new pages to visitors: xflow publish'));
|
|
186
189
|
}
|
|
187
190
|
async function publish(args) {
|
package/dist/commands/dev.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.dev = dev;
|
|
4
4
|
const node_os_1 = require("node:os");
|
|
5
|
+
const api_1 = require("../api");
|
|
5
6
|
const config_1 = require("../config");
|
|
6
7
|
const errors_1 = require("../errors");
|
|
7
8
|
const session_1 = require("../session");
|
|
8
9
|
const spawn_1 = require("../spawn");
|
|
9
10
|
const template_1 = require("../template");
|
|
11
|
+
const ui_1 = require("../ui");
|
|
10
12
|
/**
|
|
11
13
|
* The local dev server, handed the key this CLI picks for the project. The template
|
|
12
14
|
* proxy trades it for a pass on every function call, so which organization holds the
|
|
@@ -24,6 +26,15 @@ async function dev() {
|
|
|
24
26
|
// .env: pinned here, the key goes only to the platform that issued it.
|
|
25
27
|
VITE_XFLOW_API_URL: (0, template_1.envApiUrl)(client.apiUrl),
|
|
26
28
|
};
|
|
29
|
+
// .env only moves on link and deploy: a function someone else shipped, or a new
|
|
30
|
+
// project token, would reach this run only after one of them.
|
|
31
|
+
try {
|
|
32
|
+
const card = await (0, api_1.apiJson)(client, `/api/v1/projects/${config.projectId}`);
|
|
33
|
+
Object.assign(env, (0, template_1.platformEnv)(card.project_token, client.apiUrl, card.functions));
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
(0, ui_1.warn)(`The function addresses were not fetched (${e instanceof Error ? e.message : String(e)}): the ones in .env are used`);
|
|
37
|
+
}
|
|
27
38
|
// Ctrl+C reaches the server on its own; staying alive until it is gone is what
|
|
28
39
|
// hands its exit code back instead of leaving it to print over the prompt.
|
|
29
40
|
process.on('SIGINT', () => { });
|
package/dist/help.js
CHANGED
|
@@ -232,6 +232,7 @@ will work.`,
|
|
|
232
232
|
xflow db schema [table] tables of the project, or the columns of one
|
|
233
233
|
xflow db query "select ..." read data (--limit N: 50 by default, 300 at most;
|
|
234
234
|
--json prints the values whole)
|
|
235
|
+
xflow db query <file>.sql the same, the query read from a file
|
|
235
236
|
xflow db migrate apply migrations/*.sql
|
|
236
237
|
|
|
237
238
|
${(0, ui_1.bold)('list')} is about the organization, not about this project: it names the logical
|
|
@@ -241,7 +242,9 @@ attached to each one. That last column is the one to read before a migration.
|
|
|
241
242
|
${(0, ui_1.bold)('schema')} answers a different question than the ${(0, ui_1.bold)('migrations/')} directory: one logical
|
|
242
243
|
database is shared by several projects, so the files say what you did, and the schema
|
|
243
244
|
says what is actually in there. ${(0, ui_1.bold)('query')} runs inside a READ ONLY transaction, so
|
|
244
|
-
writes are rejected by the database itself, not by us reading your SQL.
|
|
245
|
+
writes are rejected by the database itself, not by us reading your SQL. A query with
|
|
246
|
+
double quotes goes in a .sql file outside the project: Windows PowerShell strips them from
|
|
247
|
+
arguments, and a file in migrations/ would be taken for a migration. Its table cuts
|
|
245
248
|
long values to keep the columns readable; ${(0, ui_1.bold)('--json')} prints them whole, together with
|
|
246
249
|
the applied limit and its ceiling. ${(0, ui_1.bold)('status')} named by id (${(0, ui_1.bold)('--project')}) answers with
|
|
247
250
|
the applied history alone: comparing against ${(0, ui_1.bold)('migrations/')} needs the folder.
|
|
@@ -546,7 +549,9 @@ calls fail, or go out under the key of whichever organization is active.
|
|
|
546
549
|
|
|
547
550
|
The platform address comes from the CLI too, not from .env, so the key goes to the
|
|
548
551
|
platform that issued it and nowhere else. It never reaches the browser: the page gets
|
|
549
|
-
only the ${(0, ui_1.bold)('VITE_')} variables
|
|
552
|
+
only the ${(0, ui_1.bold)('VITE_')} variables. The project token and the function addresses are
|
|
553
|
+
fetched on every start as well: a function someone else shipped answers here without a
|
|
554
|
+
deploy of yours.`,
|
|
550
555
|
pull: `${(0, ui_1.bold)('xflow pull')}: fetch the sources
|
|
551
556
|
|
|
552
557
|
By default it fetches the latest revision into the project folder and refuses to write
|
package/dist/json-arg.js
CHANGED
|
@@ -5,9 +5,9 @@ exports.jsonHint = jsonHint;
|
|
|
5
5
|
exports.bodyArg = bodyArg;
|
|
6
6
|
exports.assertJson = assertJson;
|
|
7
7
|
exports.jsonArg = jsonArg;
|
|
8
|
-
const node_fs_1 = require("node:fs");
|
|
9
8
|
const args_1 = require("./args");
|
|
10
9
|
const errors_1 = require("./errors");
|
|
10
|
+
const text_file_1 = require("./text-file");
|
|
11
11
|
/**
|
|
12
12
|
* A JSON body typed on the command line: --data for a call, --payload for a
|
|
13
13
|
* schedule. Checked here, before it leaves: PowerShell strips the double quotes
|
|
@@ -59,10 +59,7 @@ function bodyArg(args, flag) {
|
|
|
59
59
|
throw new errors_1.CliError(`--${flag} and --${fileFlag} cannot be used together`, 'Give the body once');
|
|
60
60
|
}
|
|
61
61
|
if (path !== undefined) {
|
|
62
|
-
|
|
63
|
-
throw new errors_1.CliError(`No file ${path}`, `--${fileFlag} takes the path to a file with the body`);
|
|
64
|
-
}
|
|
65
|
-
return { text: (0, node_fs_1.readFileSync)(path, 'utf-8').trim(), fromFile: path };
|
|
62
|
+
return { text: (0, text_file_1.readTextFile)(path, `--${fileFlag} takes the path to a file with the body`), fromFile: path };
|
|
66
63
|
}
|
|
67
64
|
if (inline === undefined)
|
|
68
65
|
return undefined;
|
package/dist/template.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.envApiUrl = envApiUrl;
|
|
4
|
+
exports.platformEnv = platformEnv;
|
|
4
5
|
exports.writePlatformEnv = writePlatformEnv;
|
|
5
6
|
exports.scaffoldFiles = scaffoldFiles;
|
|
6
7
|
const node_fs_1 = require("node:fs");
|
|
@@ -43,14 +44,22 @@ function functionsEnvValue(functions) {
|
|
|
43
44
|
function envApiUrl(apiUrl) {
|
|
44
45
|
return apiUrl.replace(/^https?:\/\//, '');
|
|
45
46
|
}
|
|
47
|
+
/** The variables that point a local run at the project: written to .env, handed to xflow dev. */
|
|
48
|
+
function platformEnv(projectToken, apiUrl, functions = []) {
|
|
49
|
+
return {
|
|
50
|
+
VITE_XFLOW_PROJECT_TOKEN: projectToken ?? '',
|
|
51
|
+
VITE_XFLOW_API_URL: envApiUrl(apiUrl),
|
|
52
|
+
[FUNCTIONS_ENV_KEY]: functionsEnvValue(functions),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
46
55
|
/**
|
|
47
56
|
* Point .env at the current project: written on every link and deploy, so that `npm run dev`
|
|
48
57
|
* never keeps talking to the previous one. Variables of your own are left alone.
|
|
49
58
|
*/
|
|
50
59
|
function writePlatformEnv(root, projectToken, apiUrl, functions = []) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
60
|
+
for (const [key, value] of Object.entries(platformEnv(projectToken, apiUrl, functions))) {
|
|
61
|
+
writeEnvValue(root, key, value);
|
|
62
|
+
}
|
|
54
63
|
}
|
|
55
64
|
/** Update one variable in .env without touching the rest of the file. */
|
|
56
65
|
function writeEnvValue(root, key, value) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readTextFile = readTextFile;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_util_1 = require("node:util");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
/**
|
|
8
|
+
* A file the agent wrote, whatever the shell saved it in. Windows PowerShell 5.1 writes
|
|
9
|
+
* UTF-16 with `>` and Out-File, and the code page with Set-Content: read as UTF-8, the
|
|
10
|
+
* first is garbage and the second turns non-latin text into U+FFFD without a word.
|
|
11
|
+
*/
|
|
12
|
+
function readTextFile(path, missingHint) {
|
|
13
|
+
if (!(0, node_fs_1.statSync)(path, { throwIfNoEntry: false })?.isFile())
|
|
14
|
+
throw new errors_1.CliError(`No file ${path}`, missingHint);
|
|
15
|
+
const bytes = (0, node_fs_1.readFileSync)(path);
|
|
16
|
+
const encoding = bytes[0] === 0xff && bytes[1] === 0xfe ? 'utf-16le' : 'utf-8';
|
|
17
|
+
try {
|
|
18
|
+
return new node_util_1.TextDecoder(encoding, { fatal: true }).decode(bytes).trim();
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
throw new errors_1.CliError(`${path} is not UTF-8`, 'Save it as UTF-8, in Windows PowerShell: Set-Content -Encoding utf8');
|
|
22
|
+
}
|
|
23
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_API_URL = exports.CLI_VERSION = void 0;
|
|
4
4
|
/** Keep in sync with cli/package.json. */
|
|
5
|
-
exports.CLI_VERSION = '0.
|
|
5
|
+
exports.CLI_VERSION = '0.22.0';
|
|
6
6
|
/** Overridden by XFLOW_API_URL or the `api` field in xflow.json. */
|
|
7
7
|
exports.DEFAULT_API_URL = 'https://app.getxflow.com';
|
package/package.json
CHANGED
package/skills/xflow/SKILL.md
CHANGED
|
@@ -22,7 +22,7 @@ contains the fix.
|
|
|
22
22
|
|
|
23
23
|
## Keeping these instructions current
|
|
24
24
|
|
|
25
|
-
These instructions ship with xflow CLI 0.
|
|
25
|
+
These instructions ship with xflow CLI 0.22.0, so the copy you are reading can be older than
|
|
26
26
|
the CLI answering your commands.
|
|
27
27
|
|
|
28
28
|
When the CLI says this file does not match it, run `xflow skills --refresh` and then **read
|
|
@@ -270,7 +270,7 @@ the interface, not a check.
|
|
|
270
270
|
A function that changes data should say so instead of checking the role by hand:
|
|
271
271
|
|
|
272
272
|
```js
|
|
273
|
-
exports.minRole = '
|
|
273
|
+
exports.minRole = 'developer' // 'member' | 'developer' | 'owner'
|
|
274
274
|
```
|
|
275
275
|
|
|
276
276
|
The wrapper refuses anything below that role before your code runs. Without the line every
|
|
@@ -429,8 +429,9 @@ do not see: `xflow db status` lists applied migrations with no file in your repo
|
|
|
429
429
|
somebody else's project), and `xflow db list` names who else is on yours. For the same reason
|
|
430
430
|
`migrations/` is not the schema. It says what you did; `xflow db schema [table]` says what is in
|
|
431
431
|
the database right now, and `xflow db query "select ..."` reads it inside a READ ONLY
|
|
432
|
-
transaction (50 rows by default, `--limit` up to 300; `--json` prints long values whole).
|
|
433
|
-
|
|
432
|
+
transaction (50 rows by default, `--limit` up to 300; `--json` prints long values whole). A query
|
|
433
|
+
with double quotes goes in a `.sql` file outside the project, `xflow db query ../q.sql`: PowerShell
|
|
434
|
+
strips them from arguments. Look before you write a migration against a shared database.
|
|
434
435
|
|
|
435
436
|
## File storage
|
|
436
437
|
|
|
@@ -598,7 +599,8 @@ A local run does not report anything: these logs exist for what you cannot open
|
|
|
598
599
|
own devtools.
|
|
599
600
|
|
|
600
601
|
Run the app locally with `xflow dev`, not a bare `npm run dev`: it hands the dev server
|
|
601
|
-
the key of the project's organization, which cloud functions need to answer
|
|
602
|
+
the key of the project's organization, which cloud functions need to answer, and their
|
|
603
|
+
current addresses, including functions someone else deployed.
|
|
602
604
|
|
|
603
605
|
## Environment
|
|
604
606
|
|