poad 2.55.0 → 2.55.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poad",
3
- "version": "2.55.0",
3
+ "version": "2.55.2",
4
4
  "engine": "0.28.0",
5
5
  "runner": "0.2.0",
6
6
  "main": "index.js",
package/project/deploy.js CHANGED
@@ -1,10 +1,12 @@
1
- // poad deploy [--env <branche>] [--dry-run] [--yes] [--json]
1
+ // poad deploy [--env <branche>] [--dry-run] [--allow-destructive] [--yes] [--json]
2
2
  //
3
3
  // Envoie le dossier poad/ (liste blanche, sans aucun secret : utils/cloud/bundle.js)
4
4
  // à l'environnement du projet poad.io lié :
5
5
  // POST v1/projects/:id/branches/:branch/deploy (application/gzip)
6
6
  // x-poad-sha commit git courant, si poad/ n'a aucun changement non commité
7
7
  // x-poad-dry-run 1 avec --dry-run : le serveur dit ce qu'il ferait, rien ne change
8
+ // x-poad-allow-destructive 1 avec --allow-destructive : migrations qui suppriment
9
+ // (drop, truncate, delete, rename) permises ; sinon le déploiement est refusé
8
10
  // réponse : { deploy_id?, status?, migrations: { applied, pending, errors } }
9
11
  // asynchrone (deploy_id et état non terminé) : GET …/deploys/:deploy_id jusqu'à la fin
10
12
  //
@@ -16,7 +18,7 @@ const FAILED = ['failed', 'error', 'cancelled', 'canceled', 'refused'];
16
18
 
17
19
  const names = (list) => (Array.isArray(list) ? list : []).map((m) => (typeof m === 'string' ? m : m && (m.name || m.version || m.file || m.migration)) || '?');
18
20
  const errorsOf = (list) =>
19
- (Array.isArray(list) ? list : []).map((e) => (typeof e === 'string' ? { migration: null, message: e } : { migration: (e && (e.migration || e.name || e.version || e.file)) || null, message: String((e && (e.message || e.error)) || 'error') }));
21
+ (Array.isArray(list) ? list : []).map((e) => (typeof e === 'string' ? { migration: null, message: e } : { migration: (e && (e.migration || e.name || e.version || e.file)) || null, message: String((e && (e.message || e.error)) || 'error'), code: (e && e.code) || null, files: Array.isArray(e && e.files) ? e.files.map(String) : [] }));
20
22
 
21
23
  /** Résultat d'un déploiement, ramené aux champs connus */
22
24
  function summarize(d = {}) {
@@ -40,14 +42,18 @@ function gitState(dir) {
40
42
  const { spawnSync } = require('child_process');
41
43
  const git = (a) => spawnSync('git', a, { cwd: dir, encoding: 'utf8', timeout: 10000 });
42
44
  const head = git(['rev-parse', 'HEAD']);
43
- if (head.status !== 0) return { repo: false, sha: null, dirty: false };
45
+ if (head.status !== 0) {
46
+ // Dans un dépôt sans aucun commit : rev-parse HEAD échoue aussi, mais ce n'est pas « hors dépôt »
47
+ const inside = git(['rev-parse', '--is-inside-work-tree']);
48
+ return { repo: false, empty: inside.status === 0 && inside.stdout.trim() === 'true', sha: null, dirty: false };
49
+ }
44
50
  const st = git(['status', '--porcelain', '--', '.']);
45
51
  const dirty = st.status === 0 ? st.stdout.split('\n').filter(Boolean) : [];
46
52
  return { repo: true, sha: head.stdout.trim(), dirty: dirty.length > 0, changes: dirty.length };
47
53
  }
48
54
 
49
55
  module.exports = (args, raw) =>
50
- require('../utils/cloud/cli').run(raw, { values: ['env', 'project'], flags: ['dry-run'] }, async ({ opts, out }) => {
56
+ require('../utils/cloud/cli').run(raw, { values: ['env', 'project'], flags: ['dry-run', 'allow-destructive'] }, async ({ opts, out }) => {
51
57
  const path = require('path');
52
58
  const api = require('../utils/cloud/api');
53
59
  const cli = require('../utils/cloud/cli');
@@ -60,6 +66,7 @@ module.exports = (args, raw) =>
60
66
  const { id } = cli.targetProject(opts);
61
67
  const poadDir = path.dirname(root);
62
68
  const dryRun = Boolean(opts['dry-run']);
69
+ const allowDestructive = Boolean(opts['allow-destructive']);
63
70
 
64
71
  const env = await branches.resolve(id, { wanted: opts.env, root });
65
72
  let b;
@@ -82,6 +89,7 @@ module.exports = (args, raw) =>
82
89
  out.log(chalk.grey(` ${b.files.length} files, ${kb(b.tgz.length)} compressed: ${migrations} migration(s), ${functions} function(s), ${flows} flow(s)`));
83
90
  if (git.repo && git.dirty) out.log(chalk.yellowBright(` ⚠ poad/ has ${git.changes} uncommitted change(s): the files of the disk are sent, without a commit id.`));
84
91
  else if (sha) out.log(chalk.grey(` commit ${sha.slice(0, 12)}`));
92
+ else if (git.empty) out.log(chalk.grey(' git repository without any commit yet: no commit id'));
85
93
  else out.log(chalk.grey(' not in a git repository: no commit id'));
86
94
  for (const s of b.skipped) out.log(chalk.grey(` skipped ${s.path}: ${s.reason}`));
87
95
 
@@ -93,6 +101,7 @@ module.exports = (args, raw) =>
93
101
  const headers = {};
94
102
  if (sha) headers['x-poad-sha'] = sha;
95
103
  if (dryRun) headers['x-poad-dry-run'] = '1';
104
+ if (allowDestructive) headers['x-poad-allow-destructive'] = '1';
96
105
  let result = summarize(await api.call('POST', `${route}/deploy`, { body: b.tgz, contentType: 'application/gzip', headers, what: 'deploy', timeout: 300000 }));
97
106
 
98
107
  // Déploiement asynchrone : suivi jusqu'à son terme
@@ -113,7 +122,11 @@ module.exports = (args, raw) =>
113
122
  out.log(' ');
114
123
  for (const n of m.applied) out.log(` ${chalk.greenBright('✔')} ${n}`);
115
124
  for (const n of m.pending) out.log(` ${chalk.yellow('○')} ${n} ${chalk.grey(dryRun ? '(would be applied)' : '(pending)')}`);
116
- for (const e of m.errors) out.log(` ${chalk.redBright('✕')} ${e.migration ? chalk.bold(e.migration) + ': ' : ''}${e.message}`);
125
+ for (const e of m.errors) {
126
+ out.log(` ${chalk.redBright('✕')} ${e.migration ? chalk.bold(e.migration) + ': ' : ''}${e.message}`);
127
+ // Refus pour migrations destructives : lesquelles, et comment confirmer
128
+ for (const f of e.files || []) out.log(` ${chalk.yellow(f)}`);
129
+ }
117
130
  if (!m.applied.length && !m.pending.length && !m.errors.length) out.log(chalk.grey(' No migration to apply.'));
118
131
  out.log(' ');
119
132
  if (result.failed) out.log(chalk.redBright(` Deploy failed${result.message ? `: ${result.message}` : ''}.`));
@@ -255,7 +255,7 @@ Object.assign(sheets, {
255
255
  notes: [EXIT_NOTE],
256
256
  },
257
257
  deploy: {
258
- usage: ['poad deploy [--env <name>] [--dry-run] [--yes] [--json]'],
258
+ usage: ['poad deploy [--env <name>] [--dry-run] [--allow-destructive] [--yes] [--json]'],
259
259
  text: [
260
260
  'Send the poad/ folder to an environment of the linked poad.io project, which applies its pending migrations and loads its functions, flows, API, auth and storage settings.',
261
261
  'Sent: migrations, auth, storage, functions, flows, api, reference, variables (defaults, no secret), types, credentials/manifest.json (names and types only, never values), seed.sql, config.toml (without any secret key). Never sent: poad/secrets.toml, .env files, data/, backups/, node_modules, symbolic links. If a value of poad/secrets.toml appears in a file to send, nothing is sent.',
@@ -263,6 +263,7 @@ Object.assign(sheets, {
263
263
  options: [
264
264
  ['--env <name>', 'the environment (default: the current git branch if it exists on poad.io, else main)'],
265
265
  ['--dry-run', 'poad.io says what it would do (migrations to apply), nothing changes'],
266
+ ['--allow-destructive', 'allow pending migrations that drop, truncate, delete or rename (refused otherwise, with the files named)'],
266
267
  ['--yes', 'no question for production (required outside a terminal)'],
267
268
  PROJECT_OPT,
268
269
  JSON_OPT,
package/utils/latest.js CHANGED
@@ -14,9 +14,14 @@
14
14
  const { isVersion, isRelease, compareVersions } = require('./version');
15
15
 
16
16
  const TAGS_URL = 'https://hub.docker.com/v2/repositories/poadio/engine/tags?page_size=100';
17
+ // permalink par l'API de GitHub (contenu brut) : la dernière version tout de suite, là où
18
+ // raw.githubusercontent.com garde jusqu'à 5 min de cache ; raw en secours (limite de l'API atteinte)
19
+ const PERMALINK_API = 'https://api.github.com/repos/poadio/permalink/contents/poad.json';
17
20
  const PERMALINK_URL = 'https://raw.githubusercontent.com/poadio/permalink/main/poad.json';
18
21
  const CHANNELS = ['stable', 'beta'];
19
- const CACHE_TTL = 6 * 3600 * 1000;
22
+ // 15 min : une version publiée est vue vite (plusieurs versions par jour en développement),
23
+ // sans dépasser la limite de l'API de GitHub sans authentification (60 lectures par heure)
24
+ const CACHE_TTL = 15 * 60 * 1000;
20
25
 
21
26
  // Seules les versions x.y.z comptent : ni latest, ni préversion
22
27
  const pickLatest = (tags) => {
@@ -24,9 +29,9 @@ const pickLatest = (tags) => {
24
29
  return versions.length ? versions.sort(compareVersions).pop() : null;
25
30
  };
26
31
 
27
- const fetchJson = async (url, timeout) => {
32
+ const fetchJson = async (url, timeout, headers = {}) => {
28
33
  try {
29
- const res = await fetch(url, { signal: AbortSignal.timeout(timeout), headers: { 'cache-control': 'no-cache' } });
34
+ const res = await fetch(url, { signal: AbortSignal.timeout(timeout), headers: { 'cache-control': 'no-cache', ...headers } });
30
35
  return res.ok ? await res.json() : null;
31
36
  } catch {
32
37
  return null;
@@ -40,7 +45,7 @@ const latestEngine = async (timeout = 4000) => {
40
45
 
41
46
  /** Versions d'engine par canal lues dans permalink : { stable?, beta? }, ou null */
42
47
  const permalinkEngines = async (timeout = 4000) => {
43
- const body = await fetchJson(PERMALINK_URL, timeout);
48
+ const body = (await fetchJson(PERMALINK_API, timeout, { accept: 'application/vnd.github.raw+json', 'user-agent': 'poad-cli' })) || (await fetchJson(PERMALINK_URL, timeout));
44
49
  const engine = body && typeof body === 'object' ? body.engine : null;
45
50
  if (!engine || typeof engine !== 'object') return null;
46
51
  const out = {};