@e-techsolutions/e-baas-sdk 1.0.0
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 +235 -0
- package/dist/index.d.ts +622 -0
- package/dist/index.esm.js +1 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# E-BaaS SDK
|
|
2
|
+
|
|
3
|
+
The official TypeScript SDK for E-BaaS (Enterprise Backend as a Service) - A comprehensive backend-as-a-service platform similar to Supabase.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @e-baas/sdk
|
|
9
|
+
# or
|
|
10
|
+
yarn add @e-baas/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { createClient } from '@e-baas/sdk';
|
|
17
|
+
|
|
18
|
+
const ebaas = createClient('https://your-project.e-baas.io', 'your-anon-key');
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
- **Authentication** - Email/password and OAuth providers (Google, GitHub, Facebook)
|
|
24
|
+
- **Database** - PostgreSQL with real-time subscriptions and RPC support
|
|
25
|
+
- **Storage** - File uploads with CDN integration and image transformations
|
|
26
|
+
- **Realtime** - WebSocket subscriptions for live data updates
|
|
27
|
+
- **Edge Functions** - Serverless functions with Deno runtime
|
|
28
|
+
- **TypeScript** - Full type safety and IntelliSense support
|
|
29
|
+
|
|
30
|
+
## Usage Examples
|
|
31
|
+
|
|
32
|
+
### Authentication
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// Sign up with email/password
|
|
36
|
+
const { user, session, error } = await ebaas.auth.signUp({
|
|
37
|
+
email: 'user@example.com',
|
|
38
|
+
password: 'secure-password',
|
|
39
|
+
name: 'John Doe'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Sign in
|
|
43
|
+
const { user, session, error } = await ebaas.auth.signIn({
|
|
44
|
+
email: 'user@example.com',
|
|
45
|
+
password: 'secure-password'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Get current user
|
|
49
|
+
const user = await ebaas.auth.getUser();
|
|
50
|
+
|
|
51
|
+
// Sign out
|
|
52
|
+
await ebaas.auth.signOut();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Database Operations
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
// Select data
|
|
59
|
+
const { data, error } = await ebaas
|
|
60
|
+
.from('users')
|
|
61
|
+
.select('id, name, email')
|
|
62
|
+
.eq('status', 'active')
|
|
63
|
+
.order('created_at', { ascending: false })
|
|
64
|
+
.limit(10)
|
|
65
|
+
.execute();
|
|
66
|
+
|
|
67
|
+
// Insert data
|
|
68
|
+
const { data, error } = await ebaas
|
|
69
|
+
.from('users')
|
|
70
|
+
.insert([
|
|
71
|
+
{ name: 'John Doe', email: 'john@example.com' },
|
|
72
|
+
{ name: 'Jane Smith', email: 'jane@example.com' }
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
// Update data
|
|
76
|
+
const { data, error } = await ebaas
|
|
77
|
+
.from('users')
|
|
78
|
+
.update({ status: 'inactive' })
|
|
79
|
+
.eq('id', 123);
|
|
80
|
+
|
|
81
|
+
// Delete data
|
|
82
|
+
const { data, error } = await ebaas
|
|
83
|
+
.from('users')
|
|
84
|
+
.delete()
|
|
85
|
+
.eq('status', 'inactive');
|
|
86
|
+
|
|
87
|
+
// RPC (stored procedures)
|
|
88
|
+
const { data, error } = await ebaas.rpc('get_user_stats', {
|
|
89
|
+
user_id: 123
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Storage
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
// Upload file
|
|
97
|
+
const { data, error } = await ebaas.storage
|
|
98
|
+
.from('avatars')
|
|
99
|
+
.upload('user-123.jpg', file, {
|
|
100
|
+
cacheControl: '3600',
|
|
101
|
+
upsert: true
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Download file
|
|
105
|
+
const { data, error } = await ebaas.storage
|
|
106
|
+
.from('avatars')
|
|
107
|
+
.download('user-123.jpg');
|
|
108
|
+
|
|
109
|
+
// Get public URL
|
|
110
|
+
const { data } = ebaas.storage
|
|
111
|
+
.from('avatars')
|
|
112
|
+
.getPublicUrl('user-123.jpg');
|
|
113
|
+
|
|
114
|
+
// Get signed URL (for private files)
|
|
115
|
+
const { data, error } = await ebaas.storage
|
|
116
|
+
.from('private-docs')
|
|
117
|
+
.createSignedUrl('document.pdf', 60); // 60 seconds
|
|
118
|
+
|
|
119
|
+
// List files
|
|
120
|
+
const { data, error } = await ebaas.storage
|
|
121
|
+
.from('avatars')
|
|
122
|
+
.list('', {
|
|
123
|
+
limit: 100,
|
|
124
|
+
offset: 0,
|
|
125
|
+
sortBy: { column: 'name', order: 'asc' }
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Realtime Subscriptions
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// Subscribe to database changes
|
|
133
|
+
const channel = ebaas.channel('realtime:users');
|
|
134
|
+
|
|
135
|
+
channel.onPostgresChanges({
|
|
136
|
+
event: '*', // INSERT, UPDATE, DELETE, or *
|
|
137
|
+
schema: 'public',
|
|
138
|
+
table: 'users'
|
|
139
|
+
}, (payload) => {
|
|
140
|
+
console.log('Change received!', payload);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
channel.subscribe();
|
|
144
|
+
|
|
145
|
+
// Broadcast messages
|
|
146
|
+
channel.send({
|
|
147
|
+
type: 'broadcast',
|
|
148
|
+
event: 'message',
|
|
149
|
+
payload: { text: 'Hello World!' }
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Presence tracking
|
|
153
|
+
channel.track({ user_id: 123, status: 'online' });
|
|
154
|
+
|
|
155
|
+
// Unsubscribe
|
|
156
|
+
channel.unsubscribe();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Edge Functions
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// Invoke function
|
|
163
|
+
const { data, error } = await ebaas.functions.invoke('hello-world', {
|
|
164
|
+
body: { name: 'John' },
|
|
165
|
+
headers: { 'Content-Type': 'application/json' }
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// List functions
|
|
169
|
+
const { data, error } = await ebaas.functions.list();
|
|
170
|
+
|
|
171
|
+
// Get function details
|
|
172
|
+
const { data, error } = await ebaas.functions.get('hello-world');
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Advanced Configuration
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
const ebaas = createClient('https://your-project.e-baas.io', 'your-anon-key', {
|
|
179
|
+
auth: {
|
|
180
|
+
autoRefreshToken: true,
|
|
181
|
+
persistSession: true,
|
|
182
|
+
detectSessionInUrl: true
|
|
183
|
+
},
|
|
184
|
+
realtime: {
|
|
185
|
+
params: {
|
|
186
|
+
eventsPerSecond: 10
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
global: {
|
|
190
|
+
headers: {
|
|
191
|
+
'x-custom-header': 'custom-value'
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Error Handling
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { EBaaSError } from '@e-baas/sdk';
|
|
201
|
+
|
|
202
|
+
try {
|
|
203
|
+
const { data } = await ebaas.from('users').select('*').execute();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
if (error instanceof EBaaSError) {
|
|
206
|
+
console.error('E-BaaS Error:', error.message);
|
|
207
|
+
console.error('Status:', error.status);
|
|
208
|
+
console.error('Details:', error.details);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## TypeScript Support
|
|
214
|
+
|
|
215
|
+
The SDK is built with TypeScript and provides full type safety:
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
interface User {
|
|
219
|
+
id: number;
|
|
220
|
+
name: string;
|
|
221
|
+
email: string;
|
|
222
|
+
created_at: string;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const { data, error } = await ebaas
|
|
226
|
+
.from<User>('users')
|
|
227
|
+
.select('*')
|
|
228
|
+
.execute();
|
|
229
|
+
|
|
230
|
+
// data is now typed as User[] | null
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT
|