@e-techsolutions/e-baas-sdk 1.0.6 → 1.0.7

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 CHANGED
@@ -56,34 +56,44 @@ await ebaas.auth.signOut();
56
56
  ### Database Operations
57
57
 
58
58
  ```typescript
59
- // Select data
59
+ // Select data (GET /sdk/v1/users?operation=select&select=id,name,email&status=eq.active)
60
+ // IMPORTANTE: Campos sensíveis (password, hash, token, secret, key) são automaticamente
61
+ // excluídos quando usando select='*' por motivos de segurança
60
62
  const { data, error } = await ebaas
61
63
  .from('users')
62
- .select('id, name, email')
64
+ .select('id, name, email') // Especificar campos explicitamente é mais seguro
63
65
  .eq('status', 'active')
64
66
  .order('created_at', { ascending: false })
65
67
  .limit(10)
66
68
  .execute();
67
69
 
68
- // Insert data
70
+ // Para incluir todos os campos (incluindo sensíveis), especifique explicitamente:
71
+ const { data, error } = await ebaas
72
+ .from('users')
73
+ .select('id, name, email, password') // Explícito para incluir campo sensível
74
+ .execute();
75
+
76
+ // Insert data (POST /sdk/v1/users?operation=insert)
77
+ // Retorna automaticamente os dados inseridos (com campos sensíveis filtrados)
69
78
  const { data, error } = await ebaas
70
79
  .from('users')
71
80
  .insert([
72
81
  { name: 'John Doe', email: 'john@example.com' },
73
82
  { name: 'Jane Smith', email: 'jane@example.com' }
74
- ]);
83
+ ]); // data contém os registros criados com IDs gerados
75
84
 
76
- // Update data
85
+ // Update data (PATCH /sdk/v1/users?operation=update&id=eq.123)
77
86
  const { data, error } = await ebaas
78
87
  .from('users')
79
88
  .update({ status: 'inactive' })
80
89
  .eq('id', 123);
81
90
 
82
- // Delete data
91
+ // Delete data (DELETE /sdk/v1/users?operation=delete&id=eq.123)
92
+ // IMPORTANTE: DELETE requer pelo menos um filtro por motivos de segurança
83
93
  const { data, error } = await ebaas
84
94
  .from('users')
85
95
  .delete()
86
- .eq('status', 'inactive');
96
+ .eq('id', 123); // Filtro obrigatório para segurança
87
97
 
88
98
  // RPC (stored procedures)
89
99
  const { data, error } = await ebaas.rpc('get_user_stats', {
@@ -123,11 +133,12 @@ if (testResult.success) {
123
133
  const status = ebaas.getCustomDatabaseStatus();
124
134
  console.log('Using custom database:', status.hasConfig);
125
135
 
126
- // Use with different schema
136
+ // Use with different schema (GET /sdk/v1/users?operation=select&select=*)
127
137
  const data = await ebaas.database
128
138
  .schema('custom_schema')
129
139
  .from('users')
130
- .select('*');
140
+ .select('*')
141
+ .execute();
131
142
  ```
132
143
 
133
144
  For detailed information about custom database features, see [Custom Database Guide](./CUSTOM_DATABASE_GUIDE.md).
@@ -287,6 +298,7 @@ const ebaas = createClient('https://your-project.e-baas.io', 'your-anon-key', {
287
298
  import { EBaaSError } from '@e-techsolutions/e-baas-sdk';
288
299
 
289
300
  try {
301
+ // GET /sdk/v1/users?operation=select&select=*
290
302
  const { data } = await ebaas.from('users').select('*').execute();
291
303
  } catch (error) {
292
304
  if (error instanceof EBaaSError) {
@@ -297,6 +309,51 @@ try {
297
309
  }
298
310
  ```
299
311
 
312
+ ## Operações DELETE Seguras
313
+
314
+ ### Validação de Segurança
315
+ O E-BaaS implementa validação rigorosa para operações DELETE e UPDATE, exigindo **pelo menos um filtro** para prevenir exclusões acidentais em massa:
316
+
317
+ ```typescript
318
+ // ✅ CORRETO: DELETE com filtro específico
319
+ const { data, error } = await ebaas
320
+ .from('users')
321
+ .delete()
322
+ .eq('id', 123);
323
+
324
+ // ❌ ERRO: DELETE sem filtros (retorna "Security violation")
325
+ const { data, error } = await ebaas
326
+ .from('users')
327
+ .delete(); // Falha com erro de segurança
328
+ ```
329
+
330
+ ### Workaround para Casos Específicos
331
+ Em casos onde o SDK nativo apresenta problemas com operações DELETE, você pode usar requisições HTTP diretas:
332
+
333
+ ```typescript
334
+ // Workaround usando fetch direta
335
+ const deleteUser = async (userId, session, workspaceId, apiUrl, apiKey) => {
336
+ const url = `${apiUrl}/sdk/v1/users?operation=delete&id=${userId}`;
337
+
338
+ const response = await fetch(url, {
339
+ method: 'DELETE',
340
+ headers: {
341
+ 'Authorization': `Bearer ${session.access_token}`,
342
+ 'apikey': apiKey,
343
+ 'x-workspace-id': workspaceId,
344
+ 'Content-Type': 'application/json'
345
+ }
346
+ });
347
+
348
+ if (!response.ok) {
349
+ const errorData = await response.json();
350
+ throw new Error(errorData.error || `HTTP ${response.status}`);
351
+ }
352
+
353
+ return { error: null };
354
+ };
355
+ ```
356
+
300
357
  ## TypeScript Support
301
358
 
302
359
  The SDK is built with TypeScript and provides full type safety:
@@ -309,6 +366,7 @@ interface User {
309
366
  created_at: string;
310
367
  }
311
368
 
369
+ // GET /sdk/v1/users?operation=select&select=*
312
370
  const { data, error } = await ebaas
313
371
  .from<User>('users')
314
372
  .select('*')
@@ -376,6 +434,13 @@ try {
376
434
 
377
435
  ## Changelog
378
436
 
437
+ ### v1.0.8 (2025-07-17)
438
+ - 🔧 **FIX**: Correção crítica em operações DELETE no SDK
439
+ - 🔧 **FIX**: Implementação de workaround HTTP para casos de falha do SDK nativo
440
+ - 📚 **DOCS**: Documentação expandida sobre operações DELETE seguras
441
+ - 🛡️ **SECURITY**: Validação rigorosa de filtros em operações DELETE/UPDATE
442
+ - ✅ **TESTED**: Operações DELETE testadas e confirmadas funcionando
443
+
379
444
  ### v1.0.1 (2024-06-24)
380
445
  - 🚀 **NEW**: Native SDK integration in Edge Functions
381
446
  - 🚀 **NEW**: Dual runtime support (Node.js VM + Deno)