@e-techsolutions/e-baas-sdk 1.0.1 → 1.0.3
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 +120 -7
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,17 +5,17 @@ The official TypeScript SDK for E-BaaS (Enterprise Backend as a Service) - A com
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @e-baas
|
|
8
|
+
npm install @e-techsolutions/e-baas-sdk
|
|
9
9
|
# or
|
|
10
|
-
yarn add @e-baas
|
|
10
|
+
yarn add @e-techsolutions/e-baas-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import { createClient } from '@e-baas
|
|
16
|
+
import { createClient } from '@e-techsolutions/e-baas-sdk';
|
|
17
17
|
|
|
18
|
-
const ebaas = createClient('https://your-project.e-baas.
|
|
18
|
+
const ebaas = createClient('https://your-project.e-baas.apiservices.app.br', 'your-anon-key');
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## Features
|
|
@@ -24,7 +24,7 @@ const ebaas = createClient('https://your-project.e-baas.io', 'your-anon-key');
|
|
|
24
24
|
- **Database** - PostgreSQL with real-time subscriptions and RPC support
|
|
25
25
|
- **Storage** - File uploads with CDN integration and image transformations
|
|
26
26
|
- **Realtime** - WebSocket subscriptions for live data updates
|
|
27
|
-
- **Edge Functions** - Serverless functions with Deno
|
|
27
|
+
- **Edge Functions** - Serverless functions with dual runtime (Node.js VM + Deno) and native SDK integration
|
|
28
28
|
- **TypeScript** - Full type safety and IntelliSense support
|
|
29
29
|
|
|
30
30
|
## Usage Examples
|
|
@@ -158,8 +158,10 @@ channel.unsubscribe();
|
|
|
158
158
|
|
|
159
159
|
### Edge Functions
|
|
160
160
|
|
|
161
|
+
#### Client-side Function Invocation
|
|
162
|
+
|
|
161
163
|
```typescript
|
|
162
|
-
// Invoke function
|
|
164
|
+
// Invoke function from client
|
|
163
165
|
const { data, error } = await ebaas.functions.invoke('hello-world', {
|
|
164
166
|
body: { name: 'John' },
|
|
165
167
|
headers: { 'Content-Type': 'application/json' }
|
|
@@ -172,6 +174,49 @@ const { data, error } = await ebaas.functions.list();
|
|
|
172
174
|
const { data, error } = await ebaas.functions.get('hello-world');
|
|
173
175
|
```
|
|
174
176
|
|
|
177
|
+
#### Native SDK Integration in Edge Functions
|
|
178
|
+
|
|
179
|
+
**NEW in v1.0.1+**: The SDK is now natively available within Edge Functions:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
// Edge Function example with native SDK access
|
|
183
|
+
const { method, url } = req;
|
|
184
|
+
|
|
185
|
+
if (method === 'POST') {
|
|
186
|
+
const body = await req.json();
|
|
187
|
+
|
|
188
|
+
// Native database access - no imports needed!
|
|
189
|
+
const users = await from('users').select('*').limit(10);
|
|
190
|
+
|
|
191
|
+
// Native storage access
|
|
192
|
+
const bucket = bucket('uploads');
|
|
193
|
+
await bucket.upload('file.jpg', body.fileData);
|
|
194
|
+
|
|
195
|
+
// Native realtime notifications
|
|
196
|
+
await channel('notifications').send('user_created', {
|
|
197
|
+
user: body.userData
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Call other edge functions
|
|
201
|
+
const result = await invoke('send-email', {
|
|
202
|
+
body: { email: body.email }
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return createResponse({ success: true, users, result });
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
#### Available Globals in Edge Functions
|
|
210
|
+
|
|
211
|
+
- `from(table)` - Database table access
|
|
212
|
+
- `rpc(function, args)` - RPC calls
|
|
213
|
+
- `bucket(name)` - Storage bucket access
|
|
214
|
+
- `channel(name)` - Realtime channel access
|
|
215
|
+
- `invoke(functionName, options)` - Function orchestration
|
|
216
|
+
- `ebaas.*` - Full SDK object access
|
|
217
|
+
- `env.*` - Environment variables
|
|
218
|
+
- `context.*` - Function execution context
|
|
219
|
+
|
|
175
220
|
## Advanced Configuration
|
|
176
221
|
|
|
177
222
|
```typescript
|
|
@@ -197,7 +242,7 @@ const ebaas = createClient('https://your-project.e-baas.io', 'your-anon-key', {
|
|
|
197
242
|
## Error Handling
|
|
198
243
|
|
|
199
244
|
```typescript
|
|
200
|
-
import { EBaaSError } from '@e-baas
|
|
245
|
+
import { EBaaSError } from '@e-techsolutions/e-baas-sdk';
|
|
201
246
|
|
|
202
247
|
try {
|
|
203
248
|
const { data } = await ebaas.from('users').select('*').execute();
|
|
@@ -230,6 +275,74 @@ const { data, error } = await ebaas
|
|
|
230
275
|
// data is now typed as User[] | null
|
|
231
276
|
```
|
|
232
277
|
|
|
278
|
+
## Edge Functions Runtime Support
|
|
279
|
+
|
|
280
|
+
**NEW in v1.0.1+**: Enhanced Edge Functions with dual runtime support:
|
|
281
|
+
|
|
282
|
+
### Runtime Options
|
|
283
|
+
- **Node.js VM** (Default) - Docker/K3s friendly, isolated-vm execution
|
|
284
|
+
- **Deno** (Optional) - TypeScript-first runtime with Web APIs
|
|
285
|
+
|
|
286
|
+
### Features
|
|
287
|
+
- **Native SDK Integration** - Full platform access within functions
|
|
288
|
+
- **Auto-detected Runtime** - Automatically chooses Node.js in Docker environments
|
|
289
|
+
- **Secure Execution** - Isolated VM with memory and timeout limits
|
|
290
|
+
- **Function Orchestration** - Functions can call other functions
|
|
291
|
+
- **Supabase-compatible API** - Same developer experience as Supabase Edge Functions
|
|
292
|
+
|
|
293
|
+
### Example Edge Function
|
|
294
|
+
|
|
295
|
+
```typescript
|
|
296
|
+
// my-function.ts
|
|
297
|
+
const { method, url } = req;
|
|
298
|
+
|
|
299
|
+
// CORS handling
|
|
300
|
+
if (method === 'OPTIONS') {
|
|
301
|
+
return corsResponse(createResponse(null, { status: 200 }));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
// Database operations
|
|
306
|
+
const users = await from('users').select('name, email').limit(5);
|
|
307
|
+
|
|
308
|
+
// Storage operations
|
|
309
|
+
const files = await bucket('uploads').list('public/');
|
|
310
|
+
|
|
311
|
+
// Realtime notifications
|
|
312
|
+
await channel('notifications').send('function_executed', {
|
|
313
|
+
timestamp: new Date().toISOString(),
|
|
314
|
+
userCount: users.data?.length || 0
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// Function orchestration
|
|
318
|
+
const emailResult = await invoke('send-notification', {
|
|
319
|
+
body: { message: 'Function executed successfully' }
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return createResponse({
|
|
323
|
+
success: true,
|
|
324
|
+
users: users.data,
|
|
325
|
+
files: files.data,
|
|
326
|
+
emailSent: emailResult.data
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
} catch (error) {
|
|
330
|
+
console.error('Function error:', error);
|
|
331
|
+
return createResponse({ error: error.message }, { status: 500 });
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Changelog
|
|
336
|
+
|
|
337
|
+
### v1.0.1 (2024-06-24)
|
|
338
|
+
- 🚀 **NEW**: Native SDK integration in Edge Functions
|
|
339
|
+
- 🚀 **NEW**: Dual runtime support (Node.js VM + Deno)
|
|
340
|
+
- 🚀 **NEW**: Auto-runtime detection for Docker environments
|
|
341
|
+
- 🚀 **NEW**: Global SDK methods in Edge Functions
|
|
342
|
+
- 🚀 **NEW**: Function orchestration capabilities
|
|
343
|
+
- 🔧 Enhanced security with isolated VM execution
|
|
344
|
+
- 🔧 Improved Docker/K3s compatibility
|
|
345
|
+
|
|
233
346
|
## License
|
|
234
347
|
|
|
235
348
|
MIT
|