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

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
@@ -1,23 +1,103 @@
1
1
  # E-BaaS SDK
2
2
 
3
- The official TypeScript SDK for E-BaaS (Enterprise Backend as a Service) - A comprehensive backend-as-a-service platform similar to Supabase.
3
+ The official TypeScript SDK for E-BaaS (Enterprise Backend as a Service) - A comprehensive backend-as-a-service platform.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @e-techsolutions/e-baas-sdk
8
+ npm install @e-techsolutions/e-baas-sdk@latest
9
9
  # or
10
- yarn add @e-techsolutions/e-baas-sdk
10
+ yarn add @e-techsolutions/e-baas-sdk@latest
11
11
  ```
12
12
 
13
13
  ## Quick Start
14
14
 
15
15
  ```typescript
16
- import { createClient } from '@e-techsolutions/e-baas-sdk';
16
+ import { createClient } from "@e-techsolutions/e-baas-sdk";
17
17
 
18
- const ebaas = createClient('https://your-project.e-baas.apiservices.app.br', 'your-anon-key');
18
+ // Basic configuration (required)
19
+ const EBAAS_URL = process.env.EBAAS_API_URL; // required - https://your-api-e-baas-service
20
+ const EBAAS_KEY = process.env.EBAAS_API_KEY; // required - your API key
21
+ const WORKSPACE_ID = process.env.EBAAS_WORKSPACE_ID; // required - your workspace ID
22
+
23
+ export const ebaas = createClient(EBAAS_URL, EBAAS_KEY, {
24
+ // Database configuration (required)
25
+ database: {
26
+ workspaceId: WORKSPACE_ID, // required
27
+ autoDetectCustomDatabase: true, // optional (default: false)
28
+ },
29
+ // Other configurations are optional
30
+ });
19
31
  ```
20
32
 
33
+ ### Complete Authentication Flow
34
+
35
+ ```typescript
36
+ // 1. User login
37
+ const { user, session, error } = await ebaas.auth.signIn({
38
+ email: "user@example.com",
39
+ password: "secure-password",
40
+ });
41
+
42
+ if (error) {
43
+ console.error("Login failed:", error);
44
+ return;
45
+ }
46
+
47
+ // 2. Configure session in SDK (REQUIRED!)
48
+ ebaas.auth.setSession(session);
49
+
50
+ // 3. Persist session (optional)
51
+ localStorage.setItem("ebaas_session", JSON.stringify(session));
52
+ localStorage.setItem("ebaas_user", JSON.stringify(user));
53
+
54
+ // 4. Now you can use database operations normally
55
+ const { data: users, error } = await ebaas.from("users").select("*");
56
+
57
+ if (error) {
58
+ console.error("Error fetching users:", error);
59
+ } else {
60
+ console.log("Users found:", users.length);
61
+ }
62
+ ```
63
+
64
+ ### Session Restoration
65
+
66
+ ```typescript
67
+ // Restore session on app initialization
68
+ const restoreSession = () => {
69
+ const savedSession = localStorage.getItem("ebaas_session");
70
+ const savedUser = localStorage.getItem("ebaas_user");
71
+
72
+ if (savedSession && savedUser) {
73
+ const sessionData = JSON.parse(savedSession);
74
+
75
+ // Check if not expired
76
+ if (sessionData.expires_at > Date.now()) {
77
+ // Restore session in SDK
78
+ ebaas.auth.setSession(sessionData);
79
+ console.log("✅ Session restored automatically");
80
+ } else {
81
+ // Clear expired session
82
+ localStorage.removeItem("ebaas_session");
83
+ localStorage.removeItem("ebaas_user");
84
+ }
85
+ }
86
+ };
87
+ ```
88
+
89
+ ### Environment Variables
90
+
91
+ Create a `.env` file in your project root:
92
+
93
+ ```env
94
+ EBAAS_API_URL=https://your-api-e-baas-service
95
+ EBAAS_API_KEY=your-api-key-here
96
+ EBAAS_WORKSPACE_ID=your-workspace-id-here
97
+ ```
98
+
99
+ **Note**: This works with any bundler (Webpack, Vite, Next.js, etc.) that supports `process.env`.
100
+
21
101
  ## Features
22
102
 
23
103
  - **Authentication** - Email/password and OAuth providers (Google, GitHub, Facebook)
@@ -35,15 +115,15 @@ const ebaas = createClient('https://your-project.e-baas.apiservices.app.br', 'yo
35
115
  ```typescript
36
116
  // Sign up with email/password
37
117
  const { user, session, error } = await ebaas.auth.signUp({
38
- email: 'user@example.com',
39
- password: 'secure-password',
40
- name: 'John Doe'
118
+ email: "user@example.com",
119
+ password: "secure-password",
120
+ name: "John Doe",
41
121
  });
42
122
 
43
123
  // Sign in
44
124
  const { user, session, error } = await ebaas.auth.signIn({
45
- email: 'user@example.com',
46
- password: 'secure-password'
125
+ email: "user@example.com",
126
+ password: "secure-password",
47
127
  });
48
128
 
49
129
  // Get current user
@@ -53,51 +133,109 @@ const user = await ebaas.auth.getUser();
53
133
  await ebaas.auth.signOut();
54
134
  ```
55
135
 
136
+ **⚠️ IMPORTANT - Session Configuration:**
137
+
138
+ After login, you **MUST** configure the session in the SDK for all subsequent operations to work correctly:
139
+
140
+ ```typescript
141
+ // Complete authentication flow
142
+ const loginUser = async () => {
143
+ // 1. Perform login
144
+ const { user, session, error } = await ebaas.auth.signIn({
145
+ email: "user@example.com",
146
+ password: "secure-password",
147
+ });
148
+
149
+ if (error) {
150
+ console.error("Login failed:", error);
151
+ return;
152
+ }
153
+
154
+ // 2. Configure session in SDK (MANDATORY STEP!)
155
+ ebaas.auth.setSession(session);
156
+
157
+ // 3. Persist session in localStorage (optional)
158
+ localStorage.setItem("ebaas_session", JSON.stringify(session));
159
+ localStorage.setItem("ebaas_user", JSON.stringify(user));
160
+
161
+ console.log("✅ Login and session configuration completed");
162
+ };
163
+
164
+ // Restore session on application initialization
165
+ const restoreSession = () => {
166
+ const savedSession = localStorage.getItem("ebaas_session");
167
+ const savedUser = localStorage.getItem("ebaas_user");
168
+
169
+ if (savedSession && savedUser) {
170
+ const sessionData = JSON.parse(savedSession);
171
+
172
+ // Check if not expired
173
+ if (sessionData.expires_at > Date.now()) {
174
+ // Restore session in SDK
175
+ ebaas.auth.setSession(sessionData);
176
+ console.log("✅ Session restored automatically");
177
+ } else {
178
+ // Clear expired session
179
+ localStorage.removeItem("ebaas_session");
180
+ localStorage.removeItem("ebaas_user");
181
+ }
182
+ }
183
+ };
184
+ ```
185
+
56
186
  ### Database Operations
57
187
 
58
188
  ```typescript
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
62
- const { data, error } = await ebaas
63
- .from('users')
64
- .select('id, name, email') // Especificar campos explicitamente é mais seguro
65
- .eq('status', 'active')
66
- .order('created_at', { ascending: false })
67
- .limit(10)
68
- .execute();
69
-
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();
189
+ // Select data
190
+ const { data: users, error } = await ebaas.from("users").select("*");
75
191
 
76
- // Insert data (POST /sdk/v1/users?operation=insert)
77
- // Retorna automaticamente os dados inseridos (com campos sensíveis filtrados)
78
- const { data, error } = await ebaas
79
- .from('users')
80
- .insert([
81
- { name: 'John Doe', email: 'john@example.com' },
82
- { name: 'Jane Smith', email: 'jane@example.com' }
83
- ]); // data contém os registros criados com IDs gerados
192
+ if (error) {
193
+ console.error("Error fetching users:", error);
194
+ } else {
195
+ console.log("Users found:", users.length);
196
+ }
84
197
 
85
- // Update data (PATCH /sdk/v1/users?operation=update&id=eq.123)
198
+ // Select specific fields for better performance
86
199
  const { data, error } = await ebaas
87
- .from('users')
88
- .update({ status: 'inactive' })
89
- .eq('id', 123);
200
+ .from("users")
201
+ .select("id, name, email")
202
+ .eq("status", "active")
203
+ .order("created_at", { ascending: false })
204
+ .limit(10);
205
+
206
+ // Insert data
207
+ const { data: newUser, error: insertError } = await ebaas.from("users").insert({
208
+ name: "John Doe",
209
+ email: "john@example.com",
210
+ });
90
211
 
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
93
- const { data, error } = await ebaas
94
- .from('users')
95
- .delete()
96
- .eq('id', 123); // Filtro obrigatório para segurança
212
+ if (insertError) {
213
+ console.error("Error creating user:", insertError);
214
+ } else {
215
+ console.log("User created successfully:", newUser);
216
+ }
217
+
218
+ // Update data
219
+ const { data: updated, error: updateError } = await ebaas.from("users").update({ name: "John Smith" }).eq("id", 123);
220
+
221
+ if (updateError) {
222
+ console.error("Error updating user:", updateError);
223
+ } else {
224
+ console.log("User updated successfully:", updated);
225
+ }
226
+
227
+ // Delete data
228
+ const { data, error } = await ebaas.from("users").delete().eq("id", 123);
229
+
230
+ if (error) {
231
+ console.error("Error deleting user:", error);
232
+ } else {
233
+ console.log("User deleted successfully");
234
+ }
97
235
 
98
236
  // RPC (stored procedures)
99
- const { data, error } = await ebaas.rpc('get_user_stats', {
100
- user_id: 123
237
+ const { data, error } = await ebaas.rpc("get_user_stats", {
238
+ user_id: 123,
101
239
  });
102
240
  ```
103
241
 
@@ -105,105 +243,68 @@ const { data, error } = await ebaas.rpc('get_user_stats', {
105
243
 
106
244
  ```typescript
107
245
  // Configure with automatic custom database detection
108
- const ebaas = createClient(url, key, {
246
+ const ebaas = createClient(EBAAS_URL, EBAAS_KEY, {
109
247
  database: {
110
- workspaceId: 'your-workspace-id',
111
- autoDetectCustomDatabase: true
112
- }
248
+ workspaceId: WORKSPACE_ID,
249
+ autoDetectCustomDatabase: true, // Enable custom database auto-detection
250
+ },
113
251
  });
114
-
115
- // Configure custom database credentials
116
- const credentials = {
117
- host: 'your-postgres-host.com',
118
- port: 5432,
119
- database: 'your_custom_db',
120
- username: 'db_user',
121
- password: 'db_password',
122
- schema: 'custom_schema',
123
- sslEnabled: true
124
- };
125
-
126
- // Test connection
127
- const testResult = await ebaas.database.testCustomConnection(credentials);
128
- if (testResult.success) {
129
- await ebaas.database.configureCustomDatabase(credentials);
130
- }
131
-
132
- // Check status
133
- const status = ebaas.getCustomDatabaseStatus();
134
- console.log('Using custom database:', status.hasConfig);
135
-
136
- // Use with different schema (GET /sdk/v1/users?operation=select&select=*)
137
- const data = await ebaas.database
138
- .schema('custom_schema')
139
- .from('users')
140
- .select('*')
141
- .execute();
142
252
  ```
143
253
 
144
- For detailed information about custom database features, see [Custom Database Guide](./CUSTOM_DATABASE_GUIDE.md).
145
-
146
254
  ### Storage
147
255
 
148
256
  ```typescript
149
257
  // Upload file
150
- const { data, error } = await ebaas.storage
151
- .from('avatars')
152
- .upload('user-123.jpg', file, {
153
- cacheControl: '3600',
154
- upsert: true
155
- });
258
+ const { data, error } = await ebaas.storage.from("avatars").upload("user-123.jpg", file, {
259
+ cacheControl: "3600",
260
+ upsert: true,
261
+ });
156
262
 
157
263
  // Download file
158
- const { data, error } = await ebaas.storage
159
- .from('avatars')
160
- .download('user-123.jpg');
264
+ const { data, error } = await ebaas.storage.from("avatars").download("user-123.jpg");
161
265
 
162
266
  // Get public URL
163
- const { data } = ebaas.storage
164
- .from('avatars')
165
- .getPublicUrl('user-123.jpg');
267
+ const { data } = ebaas.storage.from("avatars").getPublicUrl("user-123.jpg");
166
268
 
167
269
  // Get signed URL (for private files)
168
- const { data, error } = await ebaas.storage
169
- .from('private-docs')
170
- .createSignedUrl('document.pdf', 60); // 60 seconds
270
+ const { data, error } = await ebaas.storage.from("private-docs").createSignedUrl("document.pdf", 60); // 60 seconds
171
271
 
172
272
  // List files
173
- const { data, error } = await ebaas.storage
174
- .from('avatars')
175
- .list('', {
176
- limit: 100,
177
- offset: 0,
178
- sortBy: { column: 'name', order: 'asc' }
179
- });
273
+ const { data, error } = await ebaas.storage.from("avatars").list("", {
274
+ limit: 100,
275
+ offset: 0,
276
+ sortBy: { column: "name", order: "asc" },
277
+ });
180
278
  ```
181
279
 
182
280
  ### Realtime Subscriptions
183
281
 
184
282
  ```typescript
185
283
  // Subscribe to database changes
186
- const channel = ebaas.channel('realtime:users');
187
-
188
- channel.onPostgresChanges({
189
- event: '*', // INSERT, UPDATE, DELETE, or *
190
- schema: 'public',
191
- table: 'users'
192
- }, (payload) => {
193
- console.log('Change received!', payload);
194
- });
284
+ const channel = ebaas.channel("realtime:users");
285
+
286
+ channel.onPostgresChanges(
287
+ {
288
+ event: "*", // INSERT, UPDATE, DELETE, or *
289
+ schema: "public",
290
+ table: "users",
291
+ },
292
+ (payload) => {
293
+ console.log("Change received!", payload);
294
+ }
295
+ );
195
296
 
196
297
  channel.subscribe();
197
298
 
198
299
  // Broadcast messages
199
300
  channel.send({
200
- type: 'broadcast',
201
- event: 'message',
202
- payload: { text: 'Hello World!' }
301
+ type: "broadcast",
302
+ event: "message",
303
+ payload: { text: "Hello World!" },
203
304
  });
204
305
 
205
306
  // Presence tracking
206
- channel.track({ user_id: 123, status: 'online' });
307
+ channel.track({ user_id: 123, status: "online" });
207
308
 
208
309
  // Unsubscribe
209
310
  channel.unsubscribe();
@@ -214,144 +315,118 @@ channel.unsubscribe();
214
315
  #### Client-side Function Invocation
215
316
 
216
317
  ```typescript
217
- // Invoke function from client
218
- const { data, error } = await ebaas.functions.invoke('hello-world', {
219
- body: { name: 'John' },
220
- headers: { 'Content-Type': 'application/json' }
318
+ // Invoke authenticated function (requires session)
319
+ const { data, error } = await ebaas.functions.invoke("hello-world", {
320
+ body: { name: "John" },
321
+ headers: { "Content-Type": "application/json" },
322
+ });
323
+
324
+ // Invoke public function (no authentication required)
325
+ const response = await fetch("https://your-api-domain.com/functions/v1/public/hello-world", {
326
+ method: "POST",
327
+ headers: { "Content-Type": "application/json" },
328
+ body: JSON.stringify({ name: "John" }),
221
329
  });
330
+ const data = await response.json();
222
331
 
223
332
  // List functions
224
333
  const { data, error } = await ebaas.functions.list();
225
334
 
226
335
  // Get function details
227
- const { data, error } = await ebaas.functions.get('hello-world');
336
+ const { data, error } = await ebaas.functions.get("hello-world");
228
337
  ```
229
338
 
230
339
  #### Native SDK Integration in Edge Functions
231
340
 
232
- **NEW in v1.0.1+**: The SDK is now natively available within Edge Functions:
341
+ The SDK is natively available within Edge Functions with global methods:
233
342
 
234
343
  ```typescript
235
- // Edge Function example with native SDK access
236
- const { method, url } = req;
237
-
238
- if (method === 'POST') {
239
- const body = await req.json();
240
-
241
- // Native database access - no imports needed!
242
- const users = await from('users').select('*').limit(10);
243
-
244
- // Native storage access
245
- const bucket = bucket('uploads');
246
- await bucket.upload('file.jpg', body.fileData);
247
-
248
- // Native realtime notifications
249
- await channel('notifications').send('user_created', {
250
- user: body.userData
251
- });
252
-
253
- // Call other edge functions
254
- const result = await invoke('send-email', {
255
- body: { email: body.email }
256
- });
257
-
258
- return createResponse({ success: true, users, result });
259
- }
344
+ // Edge Function with native SDK access
345
+ const users = await from("users").select("*").limit(10);
346
+ const bucket = bucket("uploads");
347
+ await channel("notifications").send("user_created", { user: userData });
348
+ return createResponse({ success: true, users });
260
349
  ```
261
350
 
262
- #### Available Globals in Edge Functions
263
-
264
- - `from(table)` - Database table access
265
- - `rpc(function, args)` - RPC calls
266
- - `bucket(name)` - Storage bucket access
267
- - `channel(name)` - Realtime channel access
268
- - `invoke(functionName, options)` - Function orchestration
269
- - `ebaas.*` - Full SDK object access
270
- - `env.*` - Environment variables
271
- - `context.*` - Function execution context
351
+ **Available globals**: `from()`, `rpc()`, `bucket()`, `channel()`, `invoke()`, `ebaas.*`
272
352
 
273
353
  ## Advanced Configuration
274
354
 
275
355
  ```typescript
276
- const ebaas = createClient('https://your-project.e-baas.io', 'your-anon-key', {
277
- auth: {
278
- autoRefreshToken: true,
279
- persistSession: true,
280
- detectSessionInUrl: true
281
- },
282
- realtime: {
283
- params: {
284
- eventsPerSecond: 10
285
- }
286
- },
287
- global: {
288
- headers: {
289
- 'x-custom-header': 'custom-value'
290
- }
356
+ const ebaas = createClient(
357
+ "https://your-api-domain.com", // required - API URL
358
+ "your-api-key", // required - API Key
359
+ {
360
+ // Database configuration (required)
361
+ database: {
362
+ workspaceId: "your-workspace-id", // required - Workspace ID
363
+ autoDetectCustomDatabase: true, // optional (default: false)
364
+ },
365
+ // Authentication configuration (optional)
366
+ auth: {
367
+ autoRefreshToken: true, // optional (default: true)
368
+ persistSession: true, // optional (default: true)
369
+ detectSessionInUrl: true, // optional (default: true)
370
+ },
371
+ // Realtime configuration (optional)
372
+ realtime: {
373
+ params: {
374
+ eventsPerSecond: 10, // optional (default: 10)
375
+ },
376
+ },
377
+ // Global configuration (optional)
378
+ global: {
379
+ headers: {
380
+ "x-custom-header": "custom-value", // optional - custom headers
381
+ },
382
+ },
291
383
  }
292
- });
384
+ );
293
385
  ```
294
386
 
295
387
  ## Error Handling
296
388
 
297
389
  ```typescript
298
- import { EBaaSError } from '@e-techsolutions/e-baas-sdk';
390
+ import { EBaaSError } from "@e-techsolutions/e-baas-sdk";
299
391
 
300
392
  try {
301
- // GET /sdk/v1/users?operation=select&select=*
302
- const { data } = await ebaas.from('users').select('*').execute();
393
+ const { data } = await ebaas.from("users").select("*");
303
394
  } catch (error) {
304
395
  if (error instanceof EBaaSError) {
305
- console.error('E-BaaS Error:', error.message);
306
- console.error('Status:', error.status);
307
- console.error('Details:', error.details);
396
+ console.error("E-BaaS Error:", error.message);
397
+ console.error("Status:", error.status);
398
+ console.error("Details:", error.details);
308
399
  }
309
400
  }
310
401
  ```
311
402
 
312
- ## Operações DELETE Seguras
403
+ ## Secure DELETE Operations
404
+
405
+ ### Security Validation
313
406
 
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:
407
+ E-BaaS implements strict validation for DELETE and UPDATE operations, requiring **at least one filter** to prevent accidental mass deletions:
316
408
 
317
409
  ```typescript
318
- // ✅ CORRETO: DELETE com filtro específico
319
- const { data, error } = await ebaas
320
- .from('users')
321
- .delete()
322
- .eq('id', 123);
410
+ // ✅ CORRECT: DELETE with specific filter
411
+ const { data, error } = await ebaas.from("users").delete().eq("id", 123);
323
412
 
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
413
+ // ❌ ERROR: DELETE without filters (returns "Security violation")
414
+ const { data, error } = await ebaas.from("users").delete(); // Fails with security error
328
415
  ```
329
416
 
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:
417
+ ### Secure DELETE Operations with Required Filters
418
+
419
+ Always use the SDK with proper filters for safe DELETE operations:
332
420
 
333
421
  ```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
- };
422
+ // DELETE using SDK with required filter
423
+ const { data, error } = await ebaas.from("users").delete().eq("id", userId);
424
+
425
+ if (error) {
426
+ console.error("Error deleting user:", error);
427
+ } else {
428
+ console.log("User deleted successfully");
429
+ }
355
430
  ```
356
431
 
357
432
  ## TypeScript Support
@@ -366,90 +441,15 @@ interface User {
366
441
  created_at: string;
367
442
  }
368
443
 
369
- // GET /sdk/v1/users?operation=select&select=*
370
- const { data, error } = await ebaas
371
- .from<User>('users')
372
- .select('*')
373
- .execute();
444
+ const { data, error } = await ebaas.from<User>("users").select("*");
374
445
 
375
446
  // data is now typed as User[] | null
376
447
  ```
377
448
 
378
449
  ## Edge Functions Runtime Support
379
450
 
380
- **NEW in v1.0.1+**: Enhanced Edge Functions with dual runtime support:
381
-
382
- ### Runtime Options
383
- - **Node.js VM** (Default) - Docker/K3s friendly, isolated-vm execution
384
- - **Deno** (Optional) - TypeScript-first runtime with Web APIs
385
-
386
- ### Features
387
- - **Native SDK Integration** - Full platform access within functions
388
- - **Auto-detected Runtime** - Automatically chooses Node.js in Docker environments
389
- - **Secure Execution** - Isolated VM with memory and timeout limits
390
- - **Function Orchestration** - Functions can call other functions
391
- - **Supabase-compatible API** - Same developer experience as Supabase Edge Functions
392
-
393
- ### Example Edge Function
394
-
395
- ```typescript
396
- // my-function.ts
397
- const { method, url } = req;
398
-
399
- // CORS handling
400
- if (method === 'OPTIONS') {
401
- return corsResponse(createResponse(null, { status: 200 }));
402
- }
403
-
404
- try {
405
- // Database operations
406
- const users = await from('users').select('name, email').limit(5);
407
-
408
- // Storage operations
409
- const files = await bucket('uploads').list('public/');
410
-
411
- // Realtime notifications
412
- await channel('notifications').send('function_executed', {
413
- timestamp: new Date().toISOString(),
414
- userCount: users.data?.length || 0
415
- });
416
-
417
- // Function orchestration
418
- const emailResult = await invoke('send-notification', {
419
- body: { message: 'Function executed successfully' }
420
- });
421
-
422
- return createResponse({
423
- success: true,
424
- users: users.data,
425
- files: files.data,
426
- emailSent: emailResult.data
427
- });
428
-
429
- } catch (error) {
430
- console.error('Function error:', error);
431
- return createResponse({ error: error.message }, { status: 500 });
432
- }
433
- ```
434
-
435
- ## Changelog
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
-
444
- ### v1.0.1 (2024-06-24)
445
- - 🚀 **NEW**: Native SDK integration in Edge Functions
446
- - 🚀 **NEW**: Dual runtime support (Node.js VM + Deno)
447
- - 🚀 **NEW**: Auto-runtime detection for Docker environments
448
- - 🚀 **NEW**: Global SDK methods in Edge Functions
449
- - 🚀 **NEW**: Function orchestration capabilities
450
- - 🔧 Enhanced security with isolated VM execution
451
- - 🔧 Improved Docker/K3s compatibility
451
+ Enhanced Edge Functions with dual runtime support (Node.js VM + Deno) and native SDK integration.
452
452
 
453
453
  ## License
454
454
 
455
- MIT
455
+ MIT