poad 2.72.0 → 2.73.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/package.json +1 -1
- package/project/connection.js +8 -3
- package/project/logs.js +3 -0
- package/project/source.js +5 -2
- package/test/connection.test.js +20 -0
- package/test/source.test.js +1 -0
- package/utils/help-details.js +5 -3
- package/utils/logline.js +2 -2
- package/utils/migrations.js +5 -1
package/package.json
CHANGED
package/project/connection.js
CHANGED
|
@@ -17,7 +17,7 @@ const flows = require('./flows');
|
|
|
17
17
|
|
|
18
18
|
const NAME_RE = /^[a-z][a-z0-9-]{0,62}$/;
|
|
19
19
|
const TIMEOUT_MS = 40000;
|
|
20
|
-
const USAGE = 'Usage: poad connection ls | types [--provides tabular] | add <name> --type <id> [--set key=value …] | add <name> --url <https://…> [--credential <c>] [--auth bearer|header|basic] [--header <Name>] [--methods GET,POST] [--paths /v1/**] [--rate 10/s] [--timeout 30s] [--test-path /] | test <name> [--path /x] | rm <name> [--force], and --env <name> | --project <id> for poad.io';
|
|
20
|
+
const USAGE = 'Usage: poad connection ls | types [--provides tabular] | add <name> --type <id> [--set key=value …] [--account user|project] | add <name> --url <https://…> [--credential <c>] [--auth bearer|header|basic] [--header <Name>] [--methods GET,POST] [--paths /v1/**] [--rate 10/s] [--timeout 30s] [--test-path /] | test <name> [--path /x] | rm <name> [--force], and --env <name> | --project <id> for poad.io';
|
|
21
21
|
|
|
22
22
|
/** Options --clé valeur d'une liste de mots ; rend { opts, rest } ou { error }. Pure. */
|
|
23
23
|
const options = (words, known) => {
|
|
@@ -74,7 +74,11 @@ const typedBody = (name, o, type, env = {}) => {
|
|
|
74
74
|
values[k] = f.kind === 'number' ? Number(v) : f.kind === 'boolean' ? v === 'true' : v;
|
|
75
75
|
}
|
|
76
76
|
for (const f of type.fields) if (/secret/.test(f.kind) && env[`POAD_SECRET_${f.key.toUpperCase()}`]) values[f.key] = env[`POAD_SECRET_${f.key.toUpperCase()}`];
|
|
77
|
-
|
|
77
|
+
if (o.account !== undefined && o.account !== 'user' && o.account !== 'project') return { error: `--account: user (each user connects their own account) or project (one account for the project)` };
|
|
78
|
+
if (o.account === 'user' && type.auth?.type !== 'oauth2') return { error: `--account user: only with an OAuth 2 type (each user connects their own account)` };
|
|
79
|
+
// Services personnels (per_user_default du type : Todoist, Google Sheets, Notion en OAuth) : compte de l'utilisateur par défaut
|
|
80
|
+
const perUser = o.account === 'user' || (o.account !== 'project' && type.per_user_default === true);
|
|
81
|
+
return { name, type: type.id, values, ...(perUser ? { per_user: true } : {}), ...(o.url ? { base_url: o.url } : {}), ...(o.rate ? { rate: o.rate } : {}), ...(o.timeout ? { timeout: o.timeout } : {}) };
|
|
78
82
|
};
|
|
79
83
|
|
|
80
84
|
/** Ligne d'un type pour types. Pure. */
|
|
@@ -171,7 +175,8 @@ const main = async (args = {}, raw, deps = {}) => {
|
|
|
171
175
|
if (!['add', 'test', 'rm'].includes(command) || !name) return fail(USAGE, 2);
|
|
172
176
|
if (!NAME_RE.test(name)) return fail(`Invalid connection name "${name}": lowercase letters, digits and "-", starting with a letter.`, 2);
|
|
173
177
|
if (command === 'add') {
|
|
174
|
-
|
|
178
|
+
// --account user|project : compte de l'utilisateur qui déclenche ou compte du projet (OAuth 2) ; défaut : celui du type
|
|
179
|
+
const parsed = options(words.slice(2), ['url', 'credential', 'auth', 'header', 'methods', 'paths', 'rate', 'timeout', 'test-path', 'type', 'set', 'account']);
|
|
175
180
|
if (parsed.error) return fail(`poad connection add: ${parsed.error}.\n${USAGE}`, 2);
|
|
176
181
|
let body;
|
|
177
182
|
if (parsed.opts.type) {
|
package/project/logs.js
CHANGED
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
// et le navigateur (source=server|browser) ; page=<id> pour une page
|
|
32
32
|
// poad logs storage upload=<id> un envoi en morceaux (storage 0.6+) : début, interruption,
|
|
33
33
|
// reprise, fin, annulation, abandon ; bucket=<id> pour un bucket
|
|
34
|
+
// poad logs flows bucket=depots object=<chemin> un objet du Stockage lu par une étape (GET …/object) ou
|
|
35
|
+
// qui a lancé un flow (engine 0.70.1+) ; trigger=storage les lancements par un
|
|
36
|
+
// envoi, event=storage.object.created
|
|
34
37
|
// poad logs data event=sync_pull device=<id> synchronisation d'une table synchronisée (engine 0.70+) :
|
|
35
38
|
// sync_pull, sync_push (data), sync_purge (meta), avec table= et device=
|
|
36
39
|
// poad logs limit=500 nombre de lignes (100 par défaut)
|
package/project/source.js
CHANGED
|
@@ -305,7 +305,10 @@ const engineText = (e) => {
|
|
|
305
305
|
small: `file of ${bytes(p.size || 0)}, below ${bytes(p.threshold || 0)}`,
|
|
306
306
|
size: `key ${(p.key || []).join(', ')}, file of ${bytes(p.size || 0)}, filters pushed down`,
|
|
307
307
|
}[e.code] || e.code;
|
|
308
|
-
|
|
308
|
+
// Engine 0.71.0 : colonnes converties par Postgres en Wasm (numeric, géométrie…), leurs filtres restent à Postgres
|
|
309
|
+
const conv = e.engine === 'wasm' && Array.isArray(e.converted) ? e.converted : [];
|
|
310
|
+
const tail = conv.length ? `; ${conv.map((c) => `${/geometry|geography/i.test(c.type) ? 'geometry' : c.type} (column ${c.column})`).join(', ')} converted by Postgres, filtered by Postgres` : '';
|
|
311
|
+
return `${e.engine === 'wasm' ? 'wasm' : 'file_fdw'} (${why}${tail})`;
|
|
309
312
|
};
|
|
310
313
|
|
|
311
314
|
/** Nombre avec séparateur de milliers. Pure. */
|
|
@@ -982,7 +985,7 @@ const main = async (args = {}, raw, deps = {}) => {
|
|
|
982
985
|
if (!r) return;
|
|
983
986
|
if (json) return console.log(JSON.stringify(r, null, 2));
|
|
984
987
|
console.log(`${chalk.greenBright('✔')} ${pos[0]} ⇢ ${pos[1]} ${chalk.grey(sub === 'add' ? 'declared: include it in both directions' : 'removed')}`);
|
|
985
|
-
console.log(chalk.grey(r.stored === 'source' ? ` in ${r.file || `the source ${r.source}`}` : ' in the comment of the column: it goes with the next migration (poad db diff)'));
|
|
988
|
+
console.log(chalk.grey(r.stored === 'source' ? ` in ${r.file || `the source ${r.source}`}` : r.file ? ` migration ${r.file} (written and applied: commit it with poad/)` : ' in the comment of the column: it goes with the next migration (poad db diff)'));
|
|
986
989
|
for (const p of r.problems || []) console.log(chalk.yellowBright(` ${p.path ? `${p.path}: ` : ''}${p.message}`));
|
|
987
990
|
return;
|
|
988
991
|
}
|
package/test/connection.test.js
CHANGED
|
@@ -39,3 +39,23 @@ test('typedBody : secret jamais en argument, lu dans POAD_SECRET_<CLÉ>', () =>
|
|
|
39
39
|
test('describeType : hôtes du secret', () => {
|
|
40
40
|
assert.equal(describeType(AIRTABLE), 'airtable Airtable (applications) secret → api.airtable.com');
|
|
41
41
|
});
|
|
42
|
+
|
|
43
|
+
test('logs : action= et type= filtrent les actions de connexion des étapes de flow (connection_type)', () => {
|
|
44
|
+
const { attrConditions } = require('../utils/logline');
|
|
45
|
+
const r = attrConditions({ connection: 'mon-todoist', action: 'create_task', type: 'todoist' });
|
|
46
|
+
assert.deepStrictEqual(r.conditions, [
|
|
47
|
+
["attrs->>'connection' = ?", 'mon-todoist'],
|
|
48
|
+
["attrs->>'action' = ?", 'create_task'],
|
|
49
|
+
["attrs->>'connection_type' = ?", 'todoist'],
|
|
50
|
+
]);
|
|
51
|
+
assert.match(attrConditions({ action: true }).error, /action=<name>: a value is expected, such as action=create_task/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('add --type : compte de l’utilisateur par défaut pour un service personnel (per_user_default), --account project sinon', () => {
|
|
55
|
+
const { typedBody } = require('../project/connection');
|
|
56
|
+
const type = { id: 'todoist-oauth', fields: [], auth: { type: 'oauth2' }, per_user_default: true };
|
|
57
|
+
assert.strictEqual(typedBody('t', {}, type, {}).per_user, true);
|
|
58
|
+
assert.strictEqual(typedBody('t', { account: 'project' }, type, {}).per_user, undefined);
|
|
59
|
+
assert.strictEqual(typedBody('t', {}, { ...type, per_user_default: false }, {}).per_user, undefined);
|
|
60
|
+
assert.match(typedBody('t', { account: 'user' }, { id: 'x', fields: [], auth: { type: 'bearer' } }, {}).error, /only with an OAuth 2 type/);
|
|
61
|
+
});
|
package/test/source.test.js
CHANGED
|
@@ -477,6 +477,7 @@ test('engineText : moteur d\'une table distante d\'après le code et les paramè
|
|
|
477
477
|
assert.equal(engineText({ engine: 'file', code: 'small', params: { size: 2 * 1024 * 1024, threshold: 8 * 1024 * 1024 } }), 'file_fdw (file of 2 MB, below 8 MB)');
|
|
478
478
|
assert.equal(engineText({ engine: 'file', code: 'forced_blocked', params: { columns: [{ column: 'geom', type: 'geometry' }] } }), 'file_fdw (wasm requested, but Wasm does not handle geometry (column geom))');
|
|
479
479
|
assert.equal(engineText(null), '');
|
|
480
|
+
assert.equal(engineText({ engine: 'wasm', code: 'size', params: { key: ['code'], size: 9 * 1024 * 1024 }, converted: [{ column: 'geom', type: 'geometry(MultiPolygon,4326)' }, { column: 'm', type: 'numeric' }] }), 'wasm (key code, file of 9 MB, filters pushed down; geometry (column geom), numeric (column m) converted by Postgres, filtered by Postgres)');
|
|
480
481
|
const lines = sourceLines({ name: 'gares', valid: true, mode: 'virtual', table: 'public.gares', remote: { attached: true, location: 'https://x/y.csv', format: 'csv', engine: { engine: 'file', code: 'key', params: {} }, setting: 'auto' } }).join('\n');
|
|
481
482
|
assert.match(lines, /engine: file_fdw \(no key declared\)/);
|
|
482
483
|
});
|
package/utils/help-details.js
CHANGED
|
@@ -97,7 +97,7 @@ const sheets = {
|
|
|
97
97
|
logs: {
|
|
98
98
|
usage: ['poad logs [service …] [<filter>=<value> …] [-f] [--json]', 'poad logs [service …] [<filter>=<value> …] [-f] [--json] --env <name> [--project <id>]'],
|
|
99
99
|
text: [
|
|
100
|
-
'Unified logs of the project (every service, the project functions and flow steps), the latest 100 lines by default. Services: gateway, data, auth, storage, meta, functions, flows, postgres, files (remote tables, engine 0.68.0+), egress (every outbound call: connection, host, path without query, status, duration, engine 0.69.0+; filters connection= host=; user= : calls made with the OAuth 2 account of an end user, engine 0.70.0+), logs, engine, mailpit, keycloak, valkey, ai.',
|
|
100
|
+
'Unified logs of the project (every service, the project functions and flow steps), the latest 100 lines by default. Services: gateway, data, auth, storage, meta, functions, flows, postgres, files (remote tables, engine 0.68.0+), egress (every outbound call: connection, host, path without query, status, duration, engine 0.69.0+; filters connection= host=; user= : calls made with the OAuth 2 account of an end user, engine 0.70.0+), flows (connection actions of flow steps: filters connection= action= type=, such as poad logs flows action=create_task, engine 0.71.0+), logs, engine, mailpit, keycloak, valkey, ai.',
|
|
101
101
|
],
|
|
102
102
|
options: [
|
|
103
103
|
['level=warn', 'warn, error and fatal'],
|
|
@@ -118,7 +118,9 @@ const sheets = {
|
|
|
118
118
|
['channel=<name>', 'a realtime channel (engine 0.32+): joins, leaves, subscriptions, deliveries'],
|
|
119
119
|
['source=<name>', 'a source of poad/sources (engine 0.64+): each synchronisation (received, added, updated, removed) and its failures'],
|
|
120
120
|
['upload=<id>', 'a chunked storage upload (storage 0.6+): started, interrupted, resumed, finished, cancelled or abandoned'],
|
|
121
|
-
['bucket=<id>', 'the lines about a storage bucket: uploads, upload rules'],
|
|
121
|
+
['bucket=<id>', 'the lines about a storage bucket: uploads, upload rules, objects read by a flow step or that started a flow (engine 0.70.1+)'],
|
|
122
|
+
['object=<path>', 'an object of a bucket: read by a flow step (GET …/object), or that started a flow (engine 0.70.1+)'],
|
|
123
|
+
['trigger=<kind>', 'runs started by a kind of trigger: webhook, client, cron, storage (engine 0.70.1+), database (engine 0.71.0+)'],
|
|
122
124
|
['limit=100', 'number of lines, from 1 to 10000'],
|
|
123
125
|
['-f, --follow', 'follow live'],
|
|
124
126
|
['--json', 'one JSON line per entry (for jq)'],
|
|
@@ -359,7 +361,7 @@ sheets.relation = {
|
|
|
359
361
|
usage: ['poad relation ls [table] [--json]', 'poad relation add <table.column> <table.column> [--name <relation>]', 'poad relation rm <table.column> <table.column>', 'poad relation suggest <table>', 'poad relation check <table.column> <table.column>'],
|
|
360
362
|
text: [
|
|
361
363
|
'Relations without a foreign key (engine 0.70.0+): a column that points at a column of another table, view, remote or linked table (Postgres refuses a foreign key towards a foreign table, or from a view). The data API nests them in both directions like a foreign key: gares?select=*,commune(*) and communes?select=*,gares(*).',
|
|
362
|
-
'Where it is written: a column of a source goes to poad/sources/<name>.yaml (relations:); a column of a table or a view goes to its comment (@poad {"relation": …}), so it follows the migrations to the other environments.',
|
|
364
|
+
'Where it is written: a column of a source goes to poad/sources/<name>.yaml (relations:); a column of a table or a view goes to its comment (@poad {"relation": …}) through a new migration of poad/migrations, written and applied at once (engine 0.71.0+), so it follows the migrations to the other environments.',
|
|
363
365
|
],
|
|
364
366
|
options: [
|
|
365
367
|
['ls [table]', 'foreign keys and declared relations of the schema public (⇢ : declared)'],
|
package/utils/logline.js
CHANGED
|
@@ -5,8 +5,8 @@ const LEVELS = ['debug', 'info', 'warn', 'error', 'fatal'];
|
|
|
5
5
|
|
|
6
6
|
// Options de filtre → attribut de la ligne (attrs). Mêmes noms et même sens
|
|
7
7
|
// que les paramètres de /logs/v1 (services/logs/src/api.ts de l'infra).
|
|
8
|
-
const ATTR_OPTIONS = { flow: 'flow', step: 'step', function: 'function', tool: 'tool', outcome: 'outcome', provider: 'provider', model: 'model', event: 'event', table: 'table', channel: 'channel', front: 'front', page: 'page', source: 'source_name', upload: 'upload_id', bucket: 'bucket', connection: 'connection', host: 'host', user: 'user_id', device: 'device' };
|
|
9
|
-
const EXAMPLES = { flow: 'demo-flux', step: 'appel', function: 'demo-stats', tool: 'select_rows', outcome: 'refused', provider: 'anthropic', model: 'claude-opus-5-5', event: 'ai_default_model_changed', table: 'notes', channel: 'notes', front: 'k3x9q2m7a1bc', page: 'accueil', source: 'communes', upload: '0b8e8f7e-1b2c-4d5e-8f90-123456789abc', bucket: 'documents', connection: 'sncf', host: 'api.sncf.com', user: '4dbcaf19-7549-4c48-a3ad-f6bc173d3c48', device: 'alice-tel' };
|
|
8
|
+
const ATTR_OPTIONS = { flow: 'flow', step: 'step', function: 'function', tool: 'tool', outcome: 'outcome', provider: 'provider', model: 'model', event: 'event', table: 'table', channel: 'channel', front: 'front', page: 'page', source: 'source_name', upload: 'upload_id', bucket: 'bucket', object: 'object', trigger: 'trigger_kind', connection: 'connection', action: 'action', type: 'connection_type', host: 'host', user: 'user_id', device: 'device' };
|
|
9
|
+
const EXAMPLES = { flow: 'demo-flux', step: 'appel', function: 'demo-stats', tool: 'select_rows', outcome: 'refused', provider: 'anthropic', model: 'claude-opus-5-5', event: 'ai_default_model_changed', table: 'notes', channel: 'notes', front: 'k3x9q2m7a1bc', page: 'accueil', source: 'communes', upload: '0b8e8f7e-1b2c-4d5e-8f90-123456789abc', bucket: 'documents', object: 'releves/mars.csv', trigger: 'storage', connection: 'sncf', action: 'create_task', type: 'todoist', host: 'api.sncf.com', user: '4dbcaf19-7549-4c48-a3ad-f6bc173d3c48', device: 'alice-tel' };
|
|
10
10
|
// Identifiant d'exécution (UUID) entier, ou son début : 8 caractères au moins
|
|
11
11
|
const RUN_RE = /^[0-9a-f-]{8,36}$/;
|
|
12
12
|
|
package/utils/migrations.js
CHANGED
|
@@ -53,7 +53,11 @@ function create(root, name) {
|
|
|
53
53
|
if (!slug) throw new Error('a migration needs a name: poad migration new <name>');
|
|
54
54
|
fs.mkdirSync(dir(root), { recursive: true });
|
|
55
55
|
let version = timestamp();
|
|
56
|
-
//
|
|
56
|
+
// Toujours après la dernière migration du dossier : une migration écrite à la main avec un horodatage d'avance
|
|
57
|
+
// (ou une horloge en retard) passerait sinon avant elle à poad db reset, sur des tables pas encore créées.
|
|
58
|
+
// Deux migrations créées dans la même seconde : la seconde passe après.
|
|
59
|
+
const last = files(root).list.reduce((m, f) => (Number(f.version) > m ? Number(f.version) : m), 0);
|
|
60
|
+
if (Number(version) <= last) version = String(last + 1);
|
|
57
61
|
while (files(root).list.some((m) => m.version === version)) version = String(Number(version) + 1);
|
|
58
62
|
const file = path.join(dir(root), `${version}_${slug}.sql`);
|
|
59
63
|
fs.writeFileSync(
|