edmaxlabs-core 1.3.6 โ†’ 1.3.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
@@ -1,20 +1,19 @@
1
- ## What is edmaxlabs-core?
1
+ # EdmaxLabs Core SDK
2
2
 
3
- `edmaxlabs-core` is designed to be used directly inside your applications (React, vanilla JavaScript, Node.js, and more).
3
+ [![npm version](https://badge.fury.io/js/edmaxlabs-core.svg)](https://badge.fury.io/js/edmaxlabs-core)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
5
 
5
- It acts as the bridge between your app and EdmaxLabs infrastructure, handling communication, real-time updates, and secure data access.
6
+ `edmaxlabs-core` is the official SDK for EdmaxLabs services, providing seamless integration with Authentication, Database, Storage, and Cloud Functions. **Framework agnostic** - works with any JavaScript framework or vanilla JS.
6
7
 
7
- ---
8
-
9
- ## Features
8
+ ## ๐Ÿš€ Features
10
9
 
11
- * Authentication
12
- * Database (with realtime support)
13
- * Cloud Storage
14
- * Cloud Functions
15
- * Framework-agnostic (React, Node.js, plain JS)
16
-
17
- ---
10
+ - **Authentication** - Secure user authentication
11
+ - **Database** - Real-time database with offline support
12
+ - **Storage** - File upload/download
13
+ - **Cloud Functions** - Serverless function execution
14
+ - **Framework Agnostic** - Works with React, Vue, Angular, vanilla JS, Node.js
15
+ - **Offline Support** - Automatic sync when online
16
+ - **TypeScript** - Full TypeScript support
18
17
 
19
18
  ## ๐Ÿ“ฆ Installation
20
19
 
@@ -22,32 +21,258 @@ It acts as the bridge between your app and EdmaxLabs infrastructure, handling co
22
21
  npm install edmaxlabs-core
23
22
  ```
24
23
 
25
- ---
24
+ ## ๐Ÿง  Quick Start
25
+
26
+ ### Basic Usage
27
+
28
+ ```typescript
29
+ import EdmaxLabs from "edmaxlabs-core";
30
+
31
+ const app = new EdmaxLabs({
32
+ token: "your-api-token",
33
+ project: "your-project-id",
34
+ enableOffline: true, // Enable offline persistence
35
+ });
36
+
37
+ // Get data
38
+ const messages = await app.getDatabase.collection("messages").get();
39
+ console.log(messages);
40
+ ```
26
41
 
27
- ## ๐Ÿง  Quick Example
42
+ ### React Integration (Recommended)
28
43
 
29
- ```ts
30
- import { EdmaxLabs } from "edmaxlabs-core";
44
+ ```tsx
45
+ import EdmaxLabs from "edmaxlabs-core";
31
46
 
32
47
  const app = new EdmaxLabs({
33
48
  token: "your-token",
34
49
  project: "your-project-id",
35
- persistence: true, // optional (offline support)
50
+ enableOffline: true,
36
51
  });
37
52
 
38
- const data = await app.database.collection("messages").get();
39
- //const data = await app.database.collection("messages").doc("docid").get();
40
- //...and more
41
- console.log(data);
53
+ function ChatApp() {
54
+ const [messages, setMessages] = useState([]);
55
+ const [loading, setLoading] = useState(true);
56
+
57
+ useEffect(() => {
58
+ const unsubscribe = app.getDatabase.collection("messages").onSnapshot(
59
+ (docs) => {
60
+ setMessages(docs.map(doc => doc.data()));
61
+ setLoading(false);
62
+ }
63
+ );
64
+ return unsubscribe; // Important: cleanup to prevent memory leaks
65
+ }, []);
66
+
67
+ if (loading) return <div>Loading...</div>;
68
+
69
+ return (
70
+ <div>
71
+ {messages.map(msg => (
72
+ <div key={msg.id}>{msg.text}</div>
73
+ ))}
74
+ </div>
75
+ );
76
+ }
77
+ ```
78
+ <div>
79
+ {messages.map(msg => (
80
+ <div key={msg.id}>{msg.text}</div>
81
+ ))}
82
+ </div>
83
+ );
84
+ }
42
85
  ```
43
86
 
44
- ---
87
+ ## ๐Ÿ”ง Configuration
88
+
89
+ ```typescript
90
+ const app = new EdmaxLabs({
91
+ token: "your-api-token", // Required: Your API token
92
+ project: "your-project-id", // Required: Project identifier
93
+ baseUrl: "https://api.edmaxlabs.com", // Optional: API endpoint
94
+ enableOffline: true, // Optional: Enable offline persistence
95
+ appName: "my-app", // Optional: Unique app identifier
96
+ });
97
+ ```
98
+
99
+ ## ๐Ÿ“š API Reference
100
+
101
+ ### Database Operations
102
+
103
+ ```typescript
104
+ // Get collection
105
+ const collection = app.getDatabase.collection("users");
106
+
107
+ // Get all documents
108
+ const users = await collection.get();
109
+
110
+ // Get specific document
111
+ const user = await collection.doc("user-id").get();
112
+
113
+ // Create/update document
114
+ await collection.doc("user-id").set({
115
+ name: "John Doe",
116
+ email: "john@example.com"
117
+ });
118
+
119
+ // Update document
120
+ await collection.doc("user-id").update({
121
+ lastLogin: new Date()
122
+ });
123
+
124
+ // Delete document
125
+ await collection.doc("user-id").delete();
126
+
127
+ // Real-time listeners
128
+ const unsubscribe = collection.onSnapshot((snapshot) => {
129
+ console.log("Collection updated:", snapshot.docs);
130
+ });
131
+ ```
132
+
133
+ ### Real-time Listeners
134
+
135
+ ```typescript
136
+ // Document listener
137
+ const unsubscribeDoc = app.getDatabase.collection("users").doc("user-id").onSnapshot(
138
+ (snapshot, change) => {
139
+ console.log("Document:", snapshot?.data());
140
+ }
141
+ );
142
+
143
+ // Collection listener
144
+ const unsubscribeCollection = app.getDatabase.collection("messages").onSnapshot(
145
+ (documents, change) => {
146
+ console.log("Messages:", documents.map(doc => doc.data()));
147
+ }
148
+ );
149
+
150
+ // Cleanup when done
151
+ unsubscribeDoc();
152
+ unsubscribeCollection();
153
+ ```
154
+
155
+ ### Storage Operations
156
+
157
+ ```typescript
158
+ // Upload file
159
+ const ref = app.getStorage.ref("avatars/user-id.jpg");
160
+ await ref.put(file);
161
+
162
+ // Get download URL
163
+ const url = await ref.getDownloadURL();
164
+
165
+ // Delete file
166
+ await ref.delete();
167
+ ```
168
+
169
+ ### Authentication
170
+
171
+ ```typescript
172
+ // Get current user
173
+ const user = app.getAuthentication.currentUser;
174
+
175
+ // Listen to auth changes
176
+ const unsubscribe = app.getAuthentication.onAuthStateChanged((user) => {
177
+ console.log("User:", user);
178
+ });
179
+ ```
180
+
181
+ ## ๐Ÿ›ก๏ธ Production Considerations
182
+
183
+ ### Memory Leak Prevention
184
+
185
+ **Always cleanup listeners** when components unmount:
186
+
187
+ ```tsx
188
+ function MyComponent() {
189
+ useEffect(() => {
190
+ const unsubscribe = app.getDatabase.collection("items").onSnapshot(callback);
191
+ return unsubscribe; // โœ… Critical: prevent memory leaks
192
+ }, []);
193
+ }
194
+ ```
195
+
196
+ ### Error Handling
197
+
198
+ ```typescript
199
+ try {
200
+ const result = await app.getDatabase.collection("users").doc("id").set(data);
201
+ } catch (error) {
202
+ if (error.message.includes("quota exceeded")) {
203
+ // Handle storage full
204
+ alert("Storage is full. Please clear data.");
205
+ }
206
+ }
207
+ ```
208
+
209
+ ### Error Handling
210
+
211
+ ```typescript
212
+ try {
213
+ const result = await app.getDatabase.collection("users").doc("id").set(data);
214
+ } catch (error) {
215
+ if (error.message.includes("quota exceeded")) {
216
+ // Handle storage full
217
+ alert("Storage is full. Please clear some data.");
218
+ } else if (error.message.includes("Network")) {
219
+ // Handle offline
220
+ console.log("Will sync when online");
221
+ }
222
+ }
223
+ ```
224
+
225
+ ### Storage Limits
226
+
227
+ Monitor storage usage to prevent quota issues:
228
+
229
+ ```typescript
230
+ const { usage } = await app.getStorageUsage();
231
+ if (usage && usage.used > usage.available * 0.8) {
232
+ console.warn("Storage usage is over 80%");
233
+ }
234
+ ```
235
+
236
+ ### Input Validation
237
+
238
+ The SDK validates inputs automatically, but you should also validate:
239
+
240
+ ```typescript
241
+ // These will throw errors:
242
+ await doc.set(null); // Error: data cannot be null
243
+ await doc.set({ id: "123" }); // Error: 'id' is reserved
244
+ await doc.set([]); // Error: data cannot be an array
245
+ ```
246
+
247
+ ## ๐Ÿงช Testing
248
+
249
+ ```bash
250
+ # Run tests
251
+ npm test
252
+
253
+ # Run tests in watch mode
254
+ npm run test:watch
255
+
256
+ # Run tests with coverage
257
+ npm run test:coverage
258
+
259
+ # Type checking
260
+ npm run lint
261
+ ```
262
+
263
+ ## ๐Ÿ“– Documentation
264
+
265
+ - [Full API Reference](https://edmaxlabs.com/docs/api)
266
+ - [Migration Guide](https://edmaxlabs.com/docs/migration)
267
+ - [Best Practices](https://edmaxlabs.com/docs/best-practices)
268
+
269
+ ## ๐Ÿค Contributing
45
270
 
46
- ## ๐Ÿ“š Documentation
271
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md).
47
272
 
48
- For full guides, API references, and advanced usage:
273
+ ## ๐Ÿ“„ License
49
274
 
50
- - [https://edmaxlabs.com/docs/get-started](https://edmaxlabs.com/docs/get-started)
275
+ MIT License - see [LICENSE](LICENSE) file for details.
51
276
  - [https://edmaxlabs.com/docs/database](https://edmaxlabs.com/docs/database)
52
277
  - [https://edmaxlabs.com/docs/realtime](https://edmaxlabs.com/docs/realtime)
53
278
  - [https://edmaxlabs.com/docs/offline](https://edmaxlabs.com/docs/offline)