smoonb 1.0.7 → 1.0.8

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.
@@ -1,54 +1,26 @@
1
- const chalk = require('chalk');
2
- const path = require('path');
3
- const fs = require('fs');
4
- const inquirer = require('inquirer');
5
- const { t } = require('../../../i18n');
6
-
7
- /**
8
- * Etapa 5: Restaurar Auth Settings (interativo - exibir URL e valores)
9
- */
10
- module.exports = async ({ backupPath, targetProject }) => {
11
-
12
- try {
13
- const getT = global.smoonbI18n?.t || t;
14
- const authSettingsPath = path.join(backupPath, 'auth-settings.json');
15
-
16
- if (!fs.existsSync(authSettingsPath)) {
17
- console.log(chalk.yellow(` ⚠️ ${getT('restore.steps.auth.notFound')}`));
18
- return;
19
- }
20
-
21
- const authSettings = JSON.parse(fs.readFileSync(authSettingsPath, 'utf8'));
22
- const dashboardUrl = `https://supabase.com/dashboard/project/${targetProject.targetProjectId}/auth/url-config`;
23
-
24
- console.log(chalk.green(`\n ✅ ${getT('restore.steps.auth.urlTitle')}`));
25
- console.log(chalk.cyan(` ${dashboardUrl}`));
26
- console.log(chalk.yellow(`\n 📋 ${getT('restore.steps.auth.configureTitle')}`));
27
-
28
- if (authSettings.settings?.auth_url_config) {
29
- Object.entries(authSettings.settings.auth_url_config).forEach(([key, value]) => {
30
- console.log(chalk.white(` - ${key}: ${value}`));
31
- });
32
- } else if (authSettings.auth_url_config) {
33
- Object.entries(authSettings.auth_url_config).forEach(([key, value]) => {
34
- console.log(chalk.white(` - ${key}: ${value}`));
35
- });
36
- }
37
-
38
- console.log(chalk.yellow(`\n ⚠️ ${getT('restore.steps.auth.pressEnter')}`));
39
-
40
- await inquirer.prompt([{
41
- type: 'input',
42
- name: 'continue',
43
- message: getT('restore.steps.auth.pressEnter'),
44
- prefix: ''
45
- }]);
46
-
47
- console.log(chalk.green(` ✅ ${getT('restore.steps.auth.success')}`));
48
-
49
- } catch (error) {
50
- const getT = global.smoonbI18n?.t || t;
51
- console.error(chalk.red(` ❌ ${getT('restore.steps.auth.error', { message: error.message })}`));
52
- }
53
- };
54
-
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { applyConfig } = require('../management');
4
+ const { remapServiceUrls } = require('../dump');
5
+ const allowed = require('../auth-fields.json');
6
+ module.exports = async ({ backupPath, targetProject, remapUrls = true }) => {
7
+ const backup = JSON.parse(
8
+ fs.readFileSync(path.join(backupPath, 'auth-settings.json'), 'utf8'),
9
+ );
10
+ const settings =
11
+ backup.settings?.auth_url_config ||
12
+ backup.settings ||
13
+ backup.auth_url_config;
14
+ if (!settings || !Object.keys(settings).length)
15
+ throw new Error('Auth configuration missing from backup');
16
+ const desired = remapUrls
17
+ ? JSON.parse(
18
+ remapServiceUrls(
19
+ JSON.stringify(settings),
20
+ backup.project_id,
21
+ targetProject.targetProjectId,
22
+ ),
23
+ )
24
+ : settings;
25
+ return applyConfig(targetProject, 'config/auth', desired, allowed);
26
+ };