edmaxlabs-core 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 ADDED
@@ -0,0 +1,99 @@
1
+ # edmaxlabs-core
2
+
3
+ **edmaxlabs-core** is the official runtime SDK for building applications on the **EdmaxLabs platform**.
4
+
5
+ It provides a unified, developer-friendly interface to EdmaxLabs services such as **Database**, **Storage**, **Authentication**, and **Cloud Functions**, enabling you to build modern applications faster across web, server, and future platforms.
6
+
7
+ 🌐 Learn more at **[https://edmaxlabs.com](https://edmaxlabs.com)**
8
+
9
+ ---
10
+
11
+ ## ✨ What is edmaxlabs-core?
12
+
13
+ `edmaxlabs-core` is designed to be used **inside your applications** (React, vanilla JavaScript, Node.js, and more).
14
+ It acts as the bridge between your app and EdmaxLabs infrastructure, handling communication, real-time updates, and security-aware access patterns.
15
+
16
+ This package focuses on:
17
+
18
+ - Clean APIs
19
+ - Minimal footprint
20
+ - Cross-platform compatibility
21
+ - Long-term API stability
22
+
23
+ ---
24
+
25
+ ## 🚀 Features
26
+
27
+ - 🔐 **Authentication** – Secure user sign-in and session handling
28
+ - 🗄️ **Database** – Read and write structured data with real-time capabilities
29
+ - 📦 **Storage** – Upload, download, and manage files
30
+ - ⚡ **Cloud Functions** – Call server-side logic from your app
31
+ - 🔄 **Realtime** – Subscribe to live data updates
32
+ - 🧩 **Framework-agnostic** – Works with React, plain HTML/JS, Node.js, and more
33
+
34
+ ---
35
+
36
+ ## 📦 Installation
37
+
38
+ ```bash
39
+ npm install edmaxlabs-core
40
+ ```
41
+
42
+ ---
43
+
44
+ ## 🧠 Example Usage
45
+
46
+ ```ts
47
+ import { EdmaxLabs } from "edmaxlabs-core";
48
+
49
+ const edmax = new EdmaxLabs({
50
+ projectId: "your-project-id",
51
+ apiKey: "your-public-api-key",
52
+ });
53
+
54
+ const data = await edmax.db.collection("messages").get();
55
+ console.log(data);
56
+ ```
57
+
58
+ ---
59
+
60
+ ## 🎯 Who is this for?
61
+
62
+ - Frontend developers (React, Vite, Next.js, HTML)
63
+ - Backend developers (Node.js)
64
+ - Teams building SaaS, dashboards, or real-time apps
65
+ - Anyone using EdmaxLabs services in production apps
66
+
67
+ ---
68
+
69
+ ## 🔐 Security Philosophy
70
+
71
+ `edmaxlabs-core` assumes:
72
+
73
+ - Client keys are **public**
74
+ - Access is enforced by **rules and server validation**
75
+ - The client SDK provides **convenience**, not trust
76
+
77
+ All sensitive operations are validated server-side.
78
+
79
+ ---
80
+
81
+ ## 🧱 Ecosystem
82
+
83
+ - **edmaxlabs-tools** → management CLI for projects, hosting, rules and more.
84
+ - **edmaxlabs-core** → Runtime SDK for apps
85
+ - More SDKs and integrations coming soon
86
+
87
+ ---
88
+
89
+ ## 📜 License
90
+
91
+ MIT © EdmaxLabs
92
+
93
+ ---
94
+
95
+ ## 🧠 Vision
96
+
97
+ > Build once. Scale everywhere. Stay in control.
98
+
99
+ `edmaxlabs-core` is built to power applications today — and grow with you tomorrow.
@@ -0,0 +1,250 @@
1
+ import * as idb from 'idb';
2
+ import * as _socket_io_component_emitter from '@socket.io/component-emitter';
3
+ import { Socket } from 'socket.io-client';
4
+
5
+ interface TimestampData {
6
+ seconds: number;
7
+ nanoseconds: number;
8
+ }
9
+ interface TimestampJSON {
10
+ _type: "timestamp";
11
+ seconds: number;
12
+ nanoseconds: number;
13
+ }
14
+ declare class Timestamp implements TimestampData {
15
+ seconds: number;
16
+ nanoseconds: number;
17
+ constructor(seconds: number, nanoseconds?: number);
18
+ static now(): Timestamp;
19
+ static fromDate(date: Date): Timestamp;
20
+ static fromMillis(ms: number): Timestamp;
21
+ static fromMongo(dateObj: Date): Timestamp;
22
+ static fromJSON(obj: Record<string, number>): Timestamp;
23
+ toDate(): Date;
24
+ toMillis(): number;
25
+ sinceEpoch(): number;
26
+ toMongo(): Date;
27
+ format(pattern?: string): string;
28
+ compare(other: Timestamp): number;
29
+ relative(fmt?: string): string;
30
+ add({ seconds, minutes, hours, days, }: {
31
+ seconds?: number;
32
+ minutes?: number;
33
+ hours?: number;
34
+ days?: number;
35
+ }): Timestamp;
36
+ weekdayName(): string;
37
+ toJSON(): TimestampJSON;
38
+ toString(): string;
39
+ }
40
+
41
+ interface DisplayInfo {
42
+ firstname: string;
43
+ lastname: string;
44
+ surname: string;
45
+ profile: string;
46
+ email: string;
47
+ phone: string;
48
+ }
49
+ declare class Credentials {
50
+ uid: string;
51
+ displayInfo: DisplayInfo;
52
+ createdAt: Timestamp;
53
+ updatedAt: Timestamp;
54
+ lastLogged: Timestamp;
55
+ private constructor();
56
+ static fromMap(map: Record<string, any>): Credentials;
57
+ toMap(): Record<string, any>;
58
+ }
59
+
60
+ declare class Authentication {
61
+ static instance: Authentication | null;
62
+ private eUser?;
63
+ private client;
64
+ private app;
65
+ constructor();
66
+ private init;
67
+ private saveCredentials;
68
+ currentUser: () => Credentials | undefined;
69
+ authState: ({ onChange, onSignOut, onDeleted, }: {
70
+ onChange: (data: Credentials) => void;
71
+ onDeleted?: () => void;
72
+ onSignOut?: () => void;
73
+ }) => void;
74
+ createUserWithEmailAndPassword: ({ email, password, }: {
75
+ email: string;
76
+ password: string;
77
+ }) => Promise<Credentials | null>;
78
+ signInWithEmailAndPassword: ({ email, password, }: {
79
+ email: string;
80
+ password: string;
81
+ }) => Promise<Credentials | null>;
82
+ deleteUser: () => Promise<void>;
83
+ signOut: () => Promise<void>;
84
+ }
85
+
86
+ declare class ArraySnapshot {
87
+ id?: string;
88
+ data: Record<string, any>;
89
+ dt: Timestamp;
90
+ private constructor();
91
+ static fromMap(map: Record<string, any>): ArraySnapshot;
92
+ toMap(): Record<string, any>;
93
+ }
94
+
95
+ declare class Array {
96
+ db: EdmaxLabs;
97
+ collection: string;
98
+ key: string;
99
+ docID: string;
100
+ constructor(db: EdmaxLabs, collection: string, key: string, id: string);
101
+ show(): Promise<ArraySnapshot[]>;
102
+ push(data: any, id?: string): Promise<ArraySnapshot | null>;
103
+ update(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
104
+ insert(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
105
+ get(position: number): Promise<ArraySnapshot | null>;
106
+ remove(position: number): Promise<ArraySnapshot | null>;
107
+ }
108
+
109
+ declare class DocumentSnapshot {
110
+ id: string;
111
+ data: Record<string, any>;
112
+ private constructor();
113
+ static fromMap(map: Record<string, any>): DocumentSnapshot;
114
+ toMap(): Record<string, any>;
115
+ }
116
+
117
+ declare class DocumentRef {
118
+ db: EdmaxLabs;
119
+ collection: string;
120
+ id: string;
121
+ constructor(db: EdmaxLabs, collection: string, id: string);
122
+ get(): Promise<DocumentSnapshot | null>;
123
+ set(data: any): Promise<DocumentSnapshot | null>;
124
+ update(data: any): Promise<DocumentSnapshot | null>;
125
+ delete(): Promise<DocumentSnapshot | null>;
126
+ array(key: string): Array;
127
+ /**
128
+ * Realtime listener for a single document
129
+ */
130
+ onSnapshot(callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
131
+ }
132
+
133
+ declare class CollectionRef$1 {
134
+ db: EdmaxLabs;
135
+ constructor(db: EdmaxLabs);
136
+ getIDB: (collection: string) => Promise<idb.IDBPDatabase<unknown>>;
137
+ syncPendingWrite(id: string, collection?: string): Promise<boolean | undefined>;
138
+ syncPendingWrites(collection: string): Promise<void>;
139
+ }
140
+
141
+ type FilterExpression = {
142
+ key: string;
143
+ op: "==" | "===" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "nin" | "contains";
144
+ value: any;
145
+ };
146
+ declare class Query {
147
+ db: EdmaxLabs;
148
+ collection: string;
149
+ private filter;
150
+ constructor(db: EdmaxLabs, collection: string);
151
+ where(expression: FilterExpression): this;
152
+ private buildFilter;
153
+ get(): Promise<DocumentSnapshot[]>;
154
+ update(): Promise<DocumentSnapshot[]>;
155
+ onSnapshot(callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
156
+ }
157
+
158
+ declare class CollectionRef {
159
+ db: EdmaxLabs;
160
+ collection: string;
161
+ persistence: CollectionRef$1;
162
+ constructor(db: EdmaxLabs, collection: string);
163
+ doc(id: string): DocumentRef;
164
+ get query(): Query;
165
+ get(): Promise<DocumentSnapshot[]>;
166
+ add(data: any): Promise<DocumentSnapshot | null>;
167
+ /**
168
+ * Realtime listener for entire collection
169
+ */
170
+ onSnapshot(callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
171
+ }
172
+
173
+ declare class Batch {
174
+ app: EdmaxLabs;
175
+ ops: any[];
176
+ constructor(app: EdmaxLabs);
177
+ set(docRef: DocumentRef, data: any): this;
178
+ update(docRef: DocumentRef, data: any): this;
179
+ delete(docRef: DocumentRef): this;
180
+ commit(): Promise<any>;
181
+ }
182
+
183
+ declare class Database {
184
+ app: EdmaxLabs;
185
+ constructor(app: EdmaxLabs);
186
+ collection(name: string): CollectionRef;
187
+ doc(path: string): DocumentRef;
188
+ batch(): Batch;
189
+ runTransaction(transactionFn: (tx: {
190
+ ops: any[];
191
+ get: (docRef: DocumentRef) => Promise<any>;
192
+ set: (docRef: DocumentRef, data: any) => void;
193
+ update: (docRef: DocumentRef, data: any) => void;
194
+ delete: (docRef: DocumentRef) => void;
195
+ }) => Promise<void>): Promise<any>;
196
+ }
197
+
198
+ declare class Realtime {
199
+ db: EdmaxLabs;
200
+ socket: Socket | null;
201
+ events: string[];
202
+ constructor(db: EdmaxLabs);
203
+ connect(): Socket<_socket_io_component_emitter.DefaultEventsMap, _socket_io_component_emitter.DefaultEventsMap>;
204
+ on(event: string, cb: (...args: any[]) => void): void;
205
+ off(event: string, cb?: (...args: any[]) => void): void;
206
+ emit(event: string, data: any): void;
207
+ /**
208
+ * Realtime listener for entire collection
209
+ */
210
+ subscribeToCollection(collection: string, callback: (snapshot: DocumentSnapshot, change: string) => void, filter?: Record<string, any>): () => void;
211
+ /**
212
+ * Realtime listener for a single document
213
+ */
214
+ subscribeToDocument(collection: string, id: string, callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
215
+ }
216
+
217
+ declare class Functions {
218
+ app: EdmaxLabs;
219
+ constructor(app: EdmaxLabs);
220
+ call(functionName: string, data?: Record<string, any>): Promise<any>;
221
+ }
222
+
223
+ interface EdmaxLabsConfig {
224
+ token: string;
225
+ authToken: string;
226
+ }
227
+ declare class EdmaxLabs {
228
+ static instance: EdmaxLabs | null;
229
+ private baseUrl;
230
+ private socketUrl;
231
+ private auth;
232
+ private _db;
233
+ private realtime;
234
+ private persistence;
235
+ private persistence_worker;
236
+ constructor({ token, authToken }: EdmaxLabsConfig);
237
+ static allowPersistence(enable: boolean): void;
238
+ static initialize(config: EdmaxLabsConfig): EdmaxLabs;
239
+ get getPersistence(): boolean;
240
+ get getAuth(): Record<string, any>;
241
+ get getBaseUrl(): string;
242
+ get getSocketUrl(): string;
243
+ get database(): Database;
244
+ get functions(): Functions;
245
+ get rtdb(): Realtime;
246
+ sync(id: string, collection?: string): Promise<boolean | undefined>;
247
+ get authentication(): Authentication;
248
+ }
249
+
250
+ export { ArraySnapshot, Credentials, DisplayInfo, DocumentSnapshot, Timestamp, EdmaxLabs as default };
@@ -0,0 +1,250 @@
1
+ import * as idb from 'idb';
2
+ import * as _socket_io_component_emitter from '@socket.io/component-emitter';
3
+ import { Socket } from 'socket.io-client';
4
+
5
+ interface TimestampData {
6
+ seconds: number;
7
+ nanoseconds: number;
8
+ }
9
+ interface TimestampJSON {
10
+ _type: "timestamp";
11
+ seconds: number;
12
+ nanoseconds: number;
13
+ }
14
+ declare class Timestamp implements TimestampData {
15
+ seconds: number;
16
+ nanoseconds: number;
17
+ constructor(seconds: number, nanoseconds?: number);
18
+ static now(): Timestamp;
19
+ static fromDate(date: Date): Timestamp;
20
+ static fromMillis(ms: number): Timestamp;
21
+ static fromMongo(dateObj: Date): Timestamp;
22
+ static fromJSON(obj: Record<string, number>): Timestamp;
23
+ toDate(): Date;
24
+ toMillis(): number;
25
+ sinceEpoch(): number;
26
+ toMongo(): Date;
27
+ format(pattern?: string): string;
28
+ compare(other: Timestamp): number;
29
+ relative(fmt?: string): string;
30
+ add({ seconds, minutes, hours, days, }: {
31
+ seconds?: number;
32
+ minutes?: number;
33
+ hours?: number;
34
+ days?: number;
35
+ }): Timestamp;
36
+ weekdayName(): string;
37
+ toJSON(): TimestampJSON;
38
+ toString(): string;
39
+ }
40
+
41
+ interface DisplayInfo {
42
+ firstname: string;
43
+ lastname: string;
44
+ surname: string;
45
+ profile: string;
46
+ email: string;
47
+ phone: string;
48
+ }
49
+ declare class Credentials {
50
+ uid: string;
51
+ displayInfo: DisplayInfo;
52
+ createdAt: Timestamp;
53
+ updatedAt: Timestamp;
54
+ lastLogged: Timestamp;
55
+ private constructor();
56
+ static fromMap(map: Record<string, any>): Credentials;
57
+ toMap(): Record<string, any>;
58
+ }
59
+
60
+ declare class Authentication {
61
+ static instance: Authentication | null;
62
+ private eUser?;
63
+ private client;
64
+ private app;
65
+ constructor();
66
+ private init;
67
+ private saveCredentials;
68
+ currentUser: () => Credentials | undefined;
69
+ authState: ({ onChange, onSignOut, onDeleted, }: {
70
+ onChange: (data: Credentials) => void;
71
+ onDeleted?: () => void;
72
+ onSignOut?: () => void;
73
+ }) => void;
74
+ createUserWithEmailAndPassword: ({ email, password, }: {
75
+ email: string;
76
+ password: string;
77
+ }) => Promise<Credentials | null>;
78
+ signInWithEmailAndPassword: ({ email, password, }: {
79
+ email: string;
80
+ password: string;
81
+ }) => Promise<Credentials | null>;
82
+ deleteUser: () => Promise<void>;
83
+ signOut: () => Promise<void>;
84
+ }
85
+
86
+ declare class ArraySnapshot {
87
+ id?: string;
88
+ data: Record<string, any>;
89
+ dt: Timestamp;
90
+ private constructor();
91
+ static fromMap(map: Record<string, any>): ArraySnapshot;
92
+ toMap(): Record<string, any>;
93
+ }
94
+
95
+ declare class Array {
96
+ db: EdmaxLabs;
97
+ collection: string;
98
+ key: string;
99
+ docID: string;
100
+ constructor(db: EdmaxLabs, collection: string, key: string, id: string);
101
+ show(): Promise<ArraySnapshot[]>;
102
+ push(data: any, id?: string): Promise<ArraySnapshot | null>;
103
+ update(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
104
+ insert(position: number, data: any, id?: string): Promise<ArraySnapshot | null>;
105
+ get(position: number): Promise<ArraySnapshot | null>;
106
+ remove(position: number): Promise<ArraySnapshot | null>;
107
+ }
108
+
109
+ declare class DocumentSnapshot {
110
+ id: string;
111
+ data: Record<string, any>;
112
+ private constructor();
113
+ static fromMap(map: Record<string, any>): DocumentSnapshot;
114
+ toMap(): Record<string, any>;
115
+ }
116
+
117
+ declare class DocumentRef {
118
+ db: EdmaxLabs;
119
+ collection: string;
120
+ id: string;
121
+ constructor(db: EdmaxLabs, collection: string, id: string);
122
+ get(): Promise<DocumentSnapshot | null>;
123
+ set(data: any): Promise<DocumentSnapshot | null>;
124
+ update(data: any): Promise<DocumentSnapshot | null>;
125
+ delete(): Promise<DocumentSnapshot | null>;
126
+ array(key: string): Array;
127
+ /**
128
+ * Realtime listener for a single document
129
+ */
130
+ onSnapshot(callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
131
+ }
132
+
133
+ declare class CollectionRef$1 {
134
+ db: EdmaxLabs;
135
+ constructor(db: EdmaxLabs);
136
+ getIDB: (collection: string) => Promise<idb.IDBPDatabase<unknown>>;
137
+ syncPendingWrite(id: string, collection?: string): Promise<boolean | undefined>;
138
+ syncPendingWrites(collection: string): Promise<void>;
139
+ }
140
+
141
+ type FilterExpression = {
142
+ key: string;
143
+ op: "==" | "===" | "!=" | "<" | "<=" | ">" | ">=" | "in" | "nin" | "contains";
144
+ value: any;
145
+ };
146
+ declare class Query {
147
+ db: EdmaxLabs;
148
+ collection: string;
149
+ private filter;
150
+ constructor(db: EdmaxLabs, collection: string);
151
+ where(expression: FilterExpression): this;
152
+ private buildFilter;
153
+ get(): Promise<DocumentSnapshot[]>;
154
+ update(): Promise<DocumentSnapshot[]>;
155
+ onSnapshot(callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
156
+ }
157
+
158
+ declare class CollectionRef {
159
+ db: EdmaxLabs;
160
+ collection: string;
161
+ persistence: CollectionRef$1;
162
+ constructor(db: EdmaxLabs, collection: string);
163
+ doc(id: string): DocumentRef;
164
+ get query(): Query;
165
+ get(): Promise<DocumentSnapshot[]>;
166
+ add(data: any): Promise<DocumentSnapshot | null>;
167
+ /**
168
+ * Realtime listener for entire collection
169
+ */
170
+ onSnapshot(callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
171
+ }
172
+
173
+ declare class Batch {
174
+ app: EdmaxLabs;
175
+ ops: any[];
176
+ constructor(app: EdmaxLabs);
177
+ set(docRef: DocumentRef, data: any): this;
178
+ update(docRef: DocumentRef, data: any): this;
179
+ delete(docRef: DocumentRef): this;
180
+ commit(): Promise<any>;
181
+ }
182
+
183
+ declare class Database {
184
+ app: EdmaxLabs;
185
+ constructor(app: EdmaxLabs);
186
+ collection(name: string): CollectionRef;
187
+ doc(path: string): DocumentRef;
188
+ batch(): Batch;
189
+ runTransaction(transactionFn: (tx: {
190
+ ops: any[];
191
+ get: (docRef: DocumentRef) => Promise<any>;
192
+ set: (docRef: DocumentRef, data: any) => void;
193
+ update: (docRef: DocumentRef, data: any) => void;
194
+ delete: (docRef: DocumentRef) => void;
195
+ }) => Promise<void>): Promise<any>;
196
+ }
197
+
198
+ declare class Realtime {
199
+ db: EdmaxLabs;
200
+ socket: Socket | null;
201
+ events: string[];
202
+ constructor(db: EdmaxLabs);
203
+ connect(): Socket<_socket_io_component_emitter.DefaultEventsMap, _socket_io_component_emitter.DefaultEventsMap>;
204
+ on(event: string, cb: (...args: any[]) => void): void;
205
+ off(event: string, cb?: (...args: any[]) => void): void;
206
+ emit(event: string, data: any): void;
207
+ /**
208
+ * Realtime listener for entire collection
209
+ */
210
+ subscribeToCollection(collection: string, callback: (snapshot: DocumentSnapshot, change: string) => void, filter?: Record<string, any>): () => void;
211
+ /**
212
+ * Realtime listener for a single document
213
+ */
214
+ subscribeToDocument(collection: string, id: string, callback: (snapshot: DocumentSnapshot, change: string) => void): () => void;
215
+ }
216
+
217
+ declare class Functions {
218
+ app: EdmaxLabs;
219
+ constructor(app: EdmaxLabs);
220
+ call(functionName: string, data?: Record<string, any>): Promise<any>;
221
+ }
222
+
223
+ interface EdmaxLabsConfig {
224
+ token: string;
225
+ authToken: string;
226
+ }
227
+ declare class EdmaxLabs {
228
+ static instance: EdmaxLabs | null;
229
+ private baseUrl;
230
+ private socketUrl;
231
+ private auth;
232
+ private _db;
233
+ private realtime;
234
+ private persistence;
235
+ private persistence_worker;
236
+ constructor({ token, authToken }: EdmaxLabsConfig);
237
+ static allowPersistence(enable: boolean): void;
238
+ static initialize(config: EdmaxLabsConfig): EdmaxLabs;
239
+ get getPersistence(): boolean;
240
+ get getAuth(): Record<string, any>;
241
+ get getBaseUrl(): string;
242
+ get getSocketUrl(): string;
243
+ get database(): Database;
244
+ get functions(): Functions;
245
+ get rtdb(): Realtime;
246
+ sync(id: string, collection?: string): Promise<boolean | undefined>;
247
+ get authentication(): Authentication;
248
+ }
249
+
250
+ export { ArraySnapshot, Credentials, DisplayInfo, DocumentSnapshot, Timestamp, EdmaxLabs as default };