smoonb 0.0.16 → 0.0.17
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/src/commands/backup.js +11 -16
- package/src/commands/config.js +8 -1
- package/src/index.js +11 -3
- package/src/utils/config.js +2 -2
package/package.json
CHANGED
package/src/commands/backup.js
CHANGED
|
@@ -261,11 +261,10 @@ async function backupEdgeFunctions(config, backupDir) {
|
|
|
261
261
|
|
|
262
262
|
console.log(chalk.gray(' - Listando Edge Functions via Management API...'));
|
|
263
263
|
|
|
264
|
-
// ✅ Usar fetch direto para Management API
|
|
264
|
+
// ✅ Usar fetch direto para Management API com Personal Access Token
|
|
265
265
|
const functionsResponse = await fetch(`https://api.supabase.com/v1/projects/${config.supabase.projectId}/functions`, {
|
|
266
266
|
headers: {
|
|
267
|
-
'Authorization': `Bearer ${config.supabase.
|
|
268
|
-
'apikey': config.supabase.serviceKey,
|
|
267
|
+
'Authorization': `Bearer ${config.supabase.accessToken}`,
|
|
269
268
|
'Content-Type': 'application/json'
|
|
270
269
|
}
|
|
271
270
|
});
|
|
@@ -294,11 +293,10 @@ async function backupEdgeFunctions(config, backupDir) {
|
|
|
294
293
|
try {
|
|
295
294
|
console.log(chalk.gray(` - Baixando: ${func.name}`));
|
|
296
295
|
|
|
297
|
-
// ✅ Baixar código da function via Management API
|
|
296
|
+
// ✅ Baixar código da function via Management API com Personal Access Token
|
|
298
297
|
const functionResponse = await fetch(`https://api.supabase.com/v1/projects/${config.supabase.projectId}/functions/${func.name}`, {
|
|
299
298
|
headers: {
|
|
300
|
-
'Authorization': `Bearer ${config.supabase.
|
|
301
|
-
'apikey': config.supabase.serviceKey,
|
|
299
|
+
'Authorization': `Bearer ${config.supabase.accessToken}`,
|
|
302
300
|
'Content-Type': 'application/json'
|
|
303
301
|
}
|
|
304
302
|
});
|
|
@@ -363,11 +361,10 @@ async function backupAuthSettings(config, backupDir) {
|
|
|
363
361
|
try {
|
|
364
362
|
console.log(chalk.gray(' - Exportando configurações de Auth via Management API...'));
|
|
365
363
|
|
|
366
|
-
// ✅ Usar fetch direto para Management API
|
|
367
|
-
const authResponse = await fetch(`https://api.supabase.com/v1/projects/${config.supabase.projectId}/auth
|
|
364
|
+
// ✅ Usar fetch direto para Management API com Personal Access Token
|
|
365
|
+
const authResponse = await fetch(`https://api.supabase.com/v1/projects/${config.supabase.projectId}/config/auth`, {
|
|
368
366
|
headers: {
|
|
369
|
-
'Authorization': `Bearer ${config.supabase.
|
|
370
|
-
'apikey': config.supabase.serviceKey,
|
|
367
|
+
'Authorization': `Bearer ${config.supabase.accessToken}`,
|
|
371
368
|
'Content-Type': 'application/json'
|
|
372
369
|
}
|
|
373
370
|
});
|
|
@@ -404,11 +401,10 @@ async function backupStorage(config, backupDir) {
|
|
|
404
401
|
|
|
405
402
|
console.log(chalk.gray(' - Listando buckets de Storage via Management API...'));
|
|
406
403
|
|
|
407
|
-
// ✅ Usar fetch direto para Management API
|
|
404
|
+
// ✅ Usar fetch direto para Management API com Personal Access Token
|
|
408
405
|
const storageResponse = await fetch(`https://api.supabase.com/v1/projects/${config.supabase.projectId}/storage/buckets`, {
|
|
409
406
|
headers: {
|
|
410
|
-
'Authorization': `Bearer ${config.supabase.
|
|
411
|
-
'apikey': config.supabase.serviceKey,
|
|
407
|
+
'Authorization': `Bearer ${config.supabase.accessToken}`,
|
|
412
408
|
'Content-Type': 'application/json'
|
|
413
409
|
}
|
|
414
410
|
});
|
|
@@ -434,11 +430,10 @@ async function backupStorage(config, backupDir) {
|
|
|
434
430
|
try {
|
|
435
431
|
console.log(chalk.gray(` - Processando bucket: ${bucket.name}`));
|
|
436
432
|
|
|
437
|
-
// ✅ Listar objetos do bucket via Management API
|
|
433
|
+
// ✅ Listar objetos do bucket via Management API com Personal Access Token
|
|
438
434
|
const objectsResponse = await fetch(`https://api.supabase.com/v1/projects/${config.supabase.projectId}/storage/buckets/${bucket.name}/objects`, {
|
|
439
435
|
headers: {
|
|
440
|
-
'Authorization': `Bearer ${config.supabase.
|
|
441
|
-
'apikey': config.supabase.serviceKey,
|
|
436
|
+
'Authorization': `Bearer ${config.supabase.accessToken}`,
|
|
442
437
|
'Content-Type': 'application/json'
|
|
443
438
|
}
|
|
444
439
|
});
|
package/src/commands/config.js
CHANGED
|
@@ -39,7 +39,8 @@ async function initializeConfig(configPath) {
|
|
|
39
39
|
url: 'https://your-project-id.supabase.co',
|
|
40
40
|
serviceKey: 'your-service-key-here',
|
|
41
41
|
anonKey: 'your-anon-key-here',
|
|
42
|
-
databaseUrl: 'postgresql://postgres:[password]@db.your-project-id.supabase.co:5432/postgres'
|
|
42
|
+
databaseUrl: 'postgresql://postgres:[password]@db.your-project-id.supabase.co:5432/postgres',
|
|
43
|
+
accessToken: 'your-personal-access-token-here'
|
|
43
44
|
},
|
|
44
45
|
backup: {
|
|
45
46
|
includeFunctions: true,
|
|
@@ -106,6 +107,12 @@ async function showConfig(configPath) {
|
|
|
106
107
|
} else {
|
|
107
108
|
console.log(chalk.yellow(' - Database URL: Não configurada'));
|
|
108
109
|
}
|
|
110
|
+
|
|
111
|
+
if (config.supabase?.accessToken && config.supabase.accessToken !== 'your-personal-access-token-here') {
|
|
112
|
+
console.log(chalk.gray(' - Access Token: Configurado'));
|
|
113
|
+
} else {
|
|
114
|
+
console.log(chalk.yellow(' - Access Token: Não configurado (obrigatório para Management API)'));
|
|
115
|
+
}
|
|
109
116
|
|
|
110
117
|
console.log(chalk.blue('\n📊 Configurações de backup:'));
|
|
111
118
|
console.log(chalk.gray(` - Output Dir: ${config.backup?.outputDir || './backups'}`));
|
package/src/index.js
CHANGED
|
@@ -88,12 +88,20 @@ function showQuickHelp() {
|
|
|
88
88
|
"supabase": {
|
|
89
89
|
"projectId": "abc123def456",
|
|
90
90
|
"url": "https://abc123def456.supabase.co",
|
|
91
|
-
"serviceKey": "
|
|
92
|
-
"anonKey": "
|
|
93
|
-
"databaseUrl": "postgresql://postgres:[senha]@db.abc123def456.supabase.co:5432/postgres"
|
|
91
|
+
"serviceKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkXVCJ9...",
|
|
92
|
+
"anonKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkXVCJ9...",
|
|
93
|
+
"databaseUrl": "postgresql://postgres:[senha]@db.abc123def456.supabase.co:5432/postgres",
|
|
94
|
+
"accessToken": "sbp_1234567890abcdef1234567890abcdef"
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
|
|
98
|
+
🔑 PERSONAL ACCESS TOKEN (OBRIGATÓRIO):
|
|
99
|
+
Para Management API (Edge Functions, Auth Settings, Storage):
|
|
100
|
+
1. Acesse: https://supabase.com/dashboard/account/tokens
|
|
101
|
+
2. Clique em "Generate new token"
|
|
102
|
+
3. Copie o token (formato: sbp_...)
|
|
103
|
+
4. Adicione ao .smoonbrc como "accessToken"
|
|
104
|
+
|
|
97
105
|
🔧 COMO CONFIGURAR:
|
|
98
106
|
1. npx smoonb config --init
|
|
99
107
|
2. Edite .smoonbrc com suas credenciais
|
package/src/utils/config.js
CHANGED
|
@@ -85,8 +85,8 @@ function validateFor(config, action) {
|
|
|
85
85
|
if (!config.supabase?.url) {
|
|
86
86
|
errors.push('supabase.url é obrigatório');
|
|
87
87
|
}
|
|
88
|
-
if (!config.supabase?.
|
|
89
|
-
errors.push('supabase.
|
|
88
|
+
if (!config.supabase?.accessToken) {
|
|
89
|
+
errors.push('supabase.accessToken é obrigatório para Management API');
|
|
90
90
|
}
|
|
91
91
|
break;
|
|
92
92
|
}
|