smoonb 0.0.48 → 0.0.50
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 +339 -87
- package/bin/smoonb.js +2 -2
- package/package.json +1 -1
- package/src/commands/backup/index.js +45 -19
- package/src/commands/backup/steps/00-docker-validation.js +1 -1
- package/src/commands/backup/steps/08-edge-functions.js +6 -12
- package/src/commands/backup/steps/09-supabase-temp.js +4 -10
- package/src/commands/backup/steps/10-migrations.js +4 -10
- package/src/commands/check.js +0 -1
- package/src/commands/config.js +0 -1
- package/src/commands/functions.js +1 -1
- package/src/commands/restore/index.js +25 -9
- package/src/commands/restore/steps/01-components-selection.js +35 -48
- package/src/commands/restore/steps/02-confirmation.js +8 -13
- package/src/commands/restore/steps/04-edge-functions.js +3 -3
- package/src/commands/restore/steps/07-database-settings.js +1 -1
- package/src/commands/restore/steps/08-realtime-settings.js +1 -1
- package/src/commands/restore/utils.js +1 -1
- package/src/index.js +3 -3
- package/src/interactive/envMapper.js +38 -14
- package/src/utils/cli.js +1 -1
- package/src/utils/config.js +1 -3
- package/src/utils/docker.js +3 -3
- package/src/utils/env.js +2 -3
- package/src/utils/envMap.js +1 -1
- package/src/utils/fsx.js +2 -2
- package/src/utils/prompt.js +34 -0
- package/src/utils/realtime-settings.js +2 -2
- package/src/utils/supabase.js +10 -10
- package/src/utils/supabaseLink.js +1 -1
- package/src/utils/validation.js +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const inquirer = require('inquirer');
|
|
2
2
|
const chalk = require('chalk');
|
|
3
|
+
const { confirm } = require('../utils/prompt');
|
|
3
4
|
|
|
4
5
|
async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
5
6
|
const finalEnv = { ...env };
|
|
@@ -47,13 +48,7 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
const currentValue = finalEnv[clientKey] ?? '';
|
|
50
|
-
const
|
|
51
|
-
type: 'confirm',
|
|
52
|
-
name: 'isCorrect',
|
|
53
|
-
message: `Valor atual: ${currentValue || '(vazio)'} Este é o valor correto do projeto alvo? (S/n):`,
|
|
54
|
-
default: true,
|
|
55
|
-
prefix: ''
|
|
56
|
-
}]);
|
|
51
|
+
const isCorrect = await confirm(`Valor atual: ${currentValue || '(vazio)'}\nEste é o valor correto do projeto alvo?`, true);
|
|
57
52
|
|
|
58
53
|
let valueToWrite = currentValue;
|
|
59
54
|
if (!isCorrect) {
|
|
@@ -87,13 +82,42 @@ async function mapEnvVariablesInteractively(env, expectedKeys) {
|
|
|
87
82
|
}
|
|
88
83
|
|
|
89
84
|
async function askComponentsFlags() {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
// Explicação sobre Edge Functions
|
|
86
|
+
console.log(chalk.cyan('\n⚡ Edge Functions:'));
|
|
87
|
+
console.log(chalk.gray(' Vamos apagar as funções existentes na pasta supabase/functions, fazer um reset no link'));
|
|
88
|
+
console.log(chalk.gray(' entre a ferramenta e o projeto, e baixar novamente as funções do servidor.'));
|
|
89
|
+
console.log(chalk.gray(' Você terá a opção de manter ou apagar as funções na pasta após o backup.\n'));
|
|
90
|
+
|
|
91
|
+
const includeFunctions = await confirm('Deseja incluir Edge Functions', true);
|
|
92
|
+
|
|
93
|
+
// Explicação sobre .temp
|
|
94
|
+
console.log(chalk.cyan('\n📁 Supabase .temp:'));
|
|
95
|
+
console.log(chalk.gray(' Vamos copiar os arquivos existentes (se existirem) na pasta supabase/.temp.'));
|
|
96
|
+
console.log(chalk.gray(' Você terá a opção de manter ou apagar os arquivos nesta pasta após o backup.\n'));
|
|
97
|
+
|
|
98
|
+
// Explicação sobre Migrations
|
|
99
|
+
console.log(chalk.cyan('\n📋 Migrations:'));
|
|
100
|
+
console.log(chalk.gray(' Vamos apagar as migrations existentes (se existirem) na pasta supabase/migrations,'));
|
|
101
|
+
console.log(chalk.gray(' fazer um reset no link entre a ferramenta e o projeto, e baixar novamente as migrations'));
|
|
102
|
+
console.log(chalk.gray(' do servidor. Você terá a opção de manter ou apagar as migrations na pasta após o backup.\n'));
|
|
103
|
+
|
|
104
|
+
// Continuar com outras perguntas
|
|
105
|
+
const includeStorage = await confirm('Deseja incluir Storage', true);
|
|
106
|
+
const includeAuth = await confirm('Deseja incluir Auth', true);
|
|
107
|
+
const includeRealtime = await confirm('Deseja incluir Realtime', true);
|
|
108
|
+
const cleanFunctions = await confirm('Deseja limpar supabase/functions após o backup', false);
|
|
109
|
+
const cleanTemp = await confirm('Deseja apagar supabase/.temp após o backup', false);
|
|
110
|
+
const cleanMigrations = await confirm('Deseja apagar supabase/migrations após o backup', false);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
includeFunctions,
|
|
114
|
+
includeStorage,
|
|
115
|
+
includeAuth,
|
|
116
|
+
includeRealtime,
|
|
117
|
+
cleanFunctions,
|
|
118
|
+
cleanTemp,
|
|
119
|
+
cleanMigrations
|
|
120
|
+
};
|
|
97
121
|
}
|
|
98
122
|
|
|
99
123
|
module.exports = {
|
package/src/utils/cli.js
CHANGED
package/src/utils/config.js
CHANGED
|
@@ -13,16 +13,14 @@ async function readConfig() {
|
|
|
13
13
|
];
|
|
14
14
|
|
|
15
15
|
let configContent = null;
|
|
16
|
-
let configPath = null;
|
|
17
16
|
|
|
18
17
|
for (const configPathCandidate of configPaths) {
|
|
19
18
|
try {
|
|
20
19
|
if (fs.existsSync(configPathCandidate)) {
|
|
21
20
|
configContent = fs.readFileSync(configPathCandidate, 'utf8');
|
|
22
|
-
configPath = configPathCandidate;
|
|
23
21
|
break;
|
|
24
22
|
}
|
|
25
|
-
} catch
|
|
23
|
+
} catch {
|
|
26
24
|
// Continue para próximo caminho
|
|
27
25
|
}
|
|
28
26
|
}
|
package/src/utils/docker.js
CHANGED
|
@@ -12,7 +12,7 @@ async function detectDockerInstallation() {
|
|
|
12
12
|
// Tentar executar docker --version
|
|
13
13
|
await execAsync('docker --version');
|
|
14
14
|
return { installed: true, running: false }; // Instalado mas não sabemos se está rodando
|
|
15
|
-
} catch
|
|
15
|
+
} catch {
|
|
16
16
|
return { installed: false, running: false };
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -26,7 +26,7 @@ async function detectDockerRunning() {
|
|
|
26
26
|
// Tentar executar docker ps
|
|
27
27
|
await execAsync('docker ps');
|
|
28
28
|
return true;
|
|
29
|
-
} catch
|
|
29
|
+
} catch {
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -40,7 +40,7 @@ async function detectSupabaseCLI() {
|
|
|
40
40
|
// Tentar executar supabase --version
|
|
41
41
|
await execAsync('supabase --version');
|
|
42
42
|
return true;
|
|
43
|
-
} catch
|
|
43
|
+
} catch {
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/utils/env.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
1
|
const fsp = require('fs').promises;
|
|
3
2
|
const path = require('path');
|
|
4
3
|
|
|
@@ -27,7 +26,7 @@ function stringifyEnv(entries, existingContent) {
|
|
|
27
26
|
const seen = new Set();
|
|
28
27
|
const resultLines = [];
|
|
29
28
|
|
|
30
|
-
for (
|
|
29
|
+
for (const line of existingLines) {
|
|
31
30
|
const trimmed = line.trim();
|
|
32
31
|
if (!trimmed || trimmed.startsWith('#') || !trimmed.includes('=')) {
|
|
33
32
|
resultLines.push(line);
|
|
@@ -70,7 +69,7 @@ async function readEnvFile(filePath) {
|
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
async function writeEnvFile(filePath, entries,
|
|
72
|
+
async function writeEnvFile(filePath, entries, _options = {}) {
|
|
74
73
|
const dir = path.dirname(filePath);
|
|
75
74
|
await fsp.mkdir(dir, { recursive: true });
|
|
76
75
|
let existing = '';
|
package/src/utils/envMap.js
CHANGED
package/src/utils/fsx.js
CHANGED
|
@@ -14,13 +14,13 @@ async function copyDir(src, dest) {
|
|
|
14
14
|
await fs.promises.cp(src, dest, { recursive: true });
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
} catch
|
|
17
|
+
} catch {
|
|
18
18
|
// Fallback para fs-extra se disponível
|
|
19
19
|
try {
|
|
20
20
|
const fse = require('fs-extra');
|
|
21
21
|
await fse.copy(src, dest);
|
|
22
22
|
return;
|
|
23
|
-
} catch
|
|
23
|
+
} catch {
|
|
24
24
|
// Fallback manual usando fs nativo
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const readline = require('readline');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Função helper para fazer perguntas de confirmação customizadas
|
|
5
|
+
* Mostra (S/n) ou (s/N) em português em vez de (Y/n) ou (y/N)
|
|
6
|
+
*/
|
|
7
|
+
async function confirm(question, defaultYes = true) {
|
|
8
|
+
const rl = readline.createInterface({
|
|
9
|
+
input: process.stdin,
|
|
10
|
+
output: process.stdout
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const promptText = defaultYes ? '(S/n)' : '(s/N)';
|
|
14
|
+
const fullQuestion = `${question} ${promptText}: `;
|
|
15
|
+
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
rl.question(fullQuestion, (answer) => {
|
|
18
|
+
rl.close();
|
|
19
|
+
|
|
20
|
+
if (!answer || answer.trim() === '') {
|
|
21
|
+
resolve(defaultYes);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const normalized = answer.trim().toLowerCase();
|
|
26
|
+
resolve(normalized === 's' || normalized === 'sim' || normalized === 'y' || normalized === 'yes');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
confirm
|
|
33
|
+
};
|
|
34
|
+
|
|
@@ -70,14 +70,14 @@ async function getPreviousRealtimeSettings(backupDir) {
|
|
|
70
70
|
if (settings.realtime_settings && settings.realtime_settings.settings) {
|
|
71
71
|
return settings;
|
|
72
72
|
}
|
|
73
|
-
} catch
|
|
73
|
+
} catch {
|
|
74
74
|
// Continuar para próximo backup
|
|
75
75
|
continue;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
return null;
|
|
80
|
-
} catch
|
|
80
|
+
} catch {
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
}
|
package/src/utils/supabase.js
CHANGED
|
@@ -43,7 +43,7 @@ function findPgDumpPath() {
|
|
|
43
43
|
} else if (fs.existsSync(pgPath)) {
|
|
44
44
|
return pgPath;
|
|
45
45
|
}
|
|
46
|
-
} catch
|
|
46
|
+
} catch {
|
|
47
47
|
// Continuar para o próximo caminho
|
|
48
48
|
continue;
|
|
49
49
|
}
|
|
@@ -244,10 +244,10 @@ async function testConnection() {
|
|
|
244
244
|
const client = getSupabaseClient();
|
|
245
245
|
|
|
246
246
|
// Tentar uma operação simples
|
|
247
|
-
const {
|
|
247
|
+
const { error: testError } = await client.from('_smoonb_test').select('*').limit(1);
|
|
248
248
|
|
|
249
|
-
if (
|
|
250
|
-
throw
|
|
249
|
+
if (testError && testError.code !== 'PGRST116') { // PGRST116 = tabela não existe (esperado)
|
|
250
|
+
throw testError;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
return { success: true, message: 'Conexão estabelecida com sucesso' };
|
|
@@ -261,7 +261,7 @@ async function testConnection() {
|
|
|
261
261
|
*/
|
|
262
262
|
async function getProjectInfo(projectId) {
|
|
263
263
|
try {
|
|
264
|
-
|
|
264
|
+
getSupabaseClient(); // Garantir que cliente está disponível
|
|
265
265
|
|
|
266
266
|
// TODO: Implementar busca real de informações do projeto
|
|
267
267
|
// Por enquanto, retornar informações básicas
|
|
@@ -292,7 +292,7 @@ async function listTables() {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
return data || [];
|
|
295
|
-
} catch
|
|
295
|
+
} catch {
|
|
296
296
|
// Fallback: tentar query direta
|
|
297
297
|
try {
|
|
298
298
|
const { data, error } = await client
|
|
@@ -326,7 +326,7 @@ async function listExtensions() {
|
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
return data || [];
|
|
329
|
-
} catch
|
|
329
|
+
} catch {
|
|
330
330
|
// Fallback: tentar query direta
|
|
331
331
|
try {
|
|
332
332
|
const { data, error } = await client
|
|
@@ -349,7 +349,7 @@ async function listExtensions() {
|
|
|
349
349
|
*/
|
|
350
350
|
async function getAuthSettings() {
|
|
351
351
|
try {
|
|
352
|
-
|
|
352
|
+
getSupabaseClient(); // Garantir que cliente está disponível
|
|
353
353
|
|
|
354
354
|
// TODO: Implementar busca real de configurações de Auth
|
|
355
355
|
// Por enquanto, retornar estrutura básica
|
|
@@ -383,7 +383,7 @@ async function getStorageSettings() {
|
|
|
383
383
|
// Para cada bucket, listar objetos
|
|
384
384
|
const bucketsWithObjects = [];
|
|
385
385
|
for (const bucket of buckets) {
|
|
386
|
-
const { data: objects
|
|
386
|
+
const { data: objects } = await client.storage
|
|
387
387
|
.from(bucket.name)
|
|
388
388
|
.list();
|
|
389
389
|
|
|
@@ -408,7 +408,7 @@ async function getStorageSettings() {
|
|
|
408
408
|
*/
|
|
409
409
|
async function getRealtimeSettings() {
|
|
410
410
|
try {
|
|
411
|
-
|
|
411
|
+
getSupabaseClient(); // Garantir que cliente está disponível
|
|
412
412
|
|
|
413
413
|
// TODO: Implementar busca real de configurações de Realtime
|
|
414
414
|
// Por enquanto, retornar estrutura básica
|
package/src/utils/validation.js
CHANGED
|
@@ -46,7 +46,7 @@ function validateSupabaseUrl(url) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return { valid: true };
|
|
49
|
-
} catch
|
|
49
|
+
} catch {
|
|
50
50
|
return { valid: false, error: 'URL inválida' };
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -107,7 +107,7 @@ function validateDatabaseUrl(dbUrl) {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
return { valid: true };
|
|
110
|
-
} catch
|
|
110
|
+
} catch {
|
|
111
111
|
return { valid: false, error: 'URL da database inválida' };
|
|
112
112
|
}
|
|
113
113
|
}
|