edmaxlabs-core 1.0.3 → 1.0.5
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/dist/index.cjs +48 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{index.js → index.mjs} +49 -64
- package/dist/index.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -49,9 +49,8 @@ var Credentials = class _Credentials {
|
|
|
49
49
|
this.lastLogged = lastLogged;
|
|
50
50
|
}
|
|
51
51
|
static fromMap(map) {
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
const data = (_c = map.data) != null ? _c : map;
|
|
52
|
+
const uid = map.id ?? map.uid ?? "";
|
|
53
|
+
const data = map.data ?? map;
|
|
55
54
|
const d_info = data.displayInfo;
|
|
56
55
|
const createdAt = data.createdAt;
|
|
57
56
|
const updatedAt = data.updatedAt;
|
|
@@ -146,7 +145,7 @@ var Authentication = class {
|
|
|
146
145
|
if (data === void 0 || data === null) {
|
|
147
146
|
return void 0;
|
|
148
147
|
}
|
|
149
|
-
const result = JSON.parse(data
|
|
148
|
+
const result = JSON.parse(data ?? "{}");
|
|
150
149
|
return Credentials.fromMap(result);
|
|
151
150
|
};
|
|
152
151
|
this.authState = ({
|
|
@@ -154,12 +153,11 @@ var Authentication = class {
|
|
|
154
153
|
onSignOut,
|
|
155
154
|
onDeleted
|
|
156
155
|
}) => {
|
|
157
|
-
var _a;
|
|
158
156
|
const cuser = this.currentUser();
|
|
159
157
|
if (!cuser)
|
|
160
158
|
return;
|
|
161
|
-
const userRef =
|
|
162
|
-
userRef
|
|
159
|
+
const userRef = this.app?.database.collection("users").doc(cuser?.uid);
|
|
160
|
+
userRef?.onSnapshot((snapshot, change) => {
|
|
163
161
|
if (this.eUser === null || this.eUser === void 0)
|
|
164
162
|
return;
|
|
165
163
|
if (change === "insert") {
|
|
@@ -202,26 +200,25 @@ var Authentication = class {
|
|
|
202
200
|
email,
|
|
203
201
|
password
|
|
204
202
|
}) => {
|
|
205
|
-
var _a, _b;
|
|
206
203
|
this.eUser = void 0;
|
|
207
204
|
this.saveCredentials(null);
|
|
208
|
-
const db =
|
|
209
|
-
const data = await
|
|
205
|
+
const db = this.app?.database;
|
|
206
|
+
const data = await db?.collection("users").query.where({
|
|
210
207
|
key: "email",
|
|
211
208
|
op: "===",
|
|
212
209
|
value: email
|
|
213
|
-
}).get()
|
|
210
|
+
}).get();
|
|
214
211
|
if (data.length > 0) {
|
|
215
212
|
throw new Error("Email Already In Use.");
|
|
216
213
|
}
|
|
217
|
-
const userRef = await
|
|
214
|
+
const userRef = await db?.collection("users").add({
|
|
218
215
|
email,
|
|
219
216
|
password,
|
|
220
|
-
token:
|
|
217
|
+
token: this.client?.getAuth.token,
|
|
221
218
|
logged: true,
|
|
222
219
|
lastLogged: Date.now()
|
|
223
|
-
})
|
|
224
|
-
if (!
|
|
220
|
+
});
|
|
221
|
+
if (!userRef?.id || userRef?.id === "") {
|
|
225
222
|
throw new Error("Something went wrong try Again.");
|
|
226
223
|
}
|
|
227
224
|
this.eUser = Credentials.fromMap(userRef);
|
|
@@ -232,9 +229,8 @@ var Authentication = class {
|
|
|
232
229
|
email,
|
|
233
230
|
password
|
|
234
231
|
}) => {
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
const data = await (db == null ? void 0 : db.collection("users").query.where({
|
|
232
|
+
const db = this.app?.database;
|
|
233
|
+
const data = await db?.collection("users").query.where({
|
|
238
234
|
key: "email",
|
|
239
235
|
op: "===",
|
|
240
236
|
value: email
|
|
@@ -242,50 +238,48 @@ var Authentication = class {
|
|
|
242
238
|
key: "password",
|
|
243
239
|
op: "===",
|
|
244
240
|
value: password
|
|
245
|
-
}).get()
|
|
241
|
+
}).get();
|
|
246
242
|
if (data === void 0) {
|
|
247
243
|
throw new Error("Auth Failed.");
|
|
248
244
|
}
|
|
249
|
-
if (
|
|
245
|
+
if (data?.length === 0) {
|
|
250
246
|
throw new Error("User Not Found.");
|
|
251
247
|
}
|
|
252
248
|
const _data = data[0];
|
|
253
249
|
console.log("Signing ...");
|
|
254
250
|
this.eUser = Credentials.fromMap(_data);
|
|
255
251
|
this.saveCredentials(this.eUser);
|
|
256
|
-
await
|
|
252
|
+
await db?.collection("users").doc(data[0].id).update({
|
|
257
253
|
logged: true,
|
|
258
254
|
lastLogged: Date.now()
|
|
259
|
-
})
|
|
255
|
+
});
|
|
260
256
|
return Credentials.fromMap(data[0].toMap());
|
|
261
257
|
};
|
|
262
258
|
this.deleteUser = async () => {
|
|
263
|
-
var _a;
|
|
264
259
|
if (!this.eUser) {
|
|
265
260
|
throw new Error("No User Signed in");
|
|
266
261
|
}
|
|
267
|
-
const db =
|
|
268
|
-
const userRef = await
|
|
269
|
-
if (
|
|
262
|
+
const db = this.app?.database;
|
|
263
|
+
const userRef = await db?.collection("users").doc(this.eUser.uid).delete();
|
|
264
|
+
if (userRef?.id || userRef?.id === "") {
|
|
270
265
|
throw new Error("Something went wrong try Again.");
|
|
271
266
|
}
|
|
272
267
|
this.eUser = void 0;
|
|
273
268
|
this.saveCredentials(null);
|
|
274
269
|
};
|
|
275
270
|
this.signOut = async () => {
|
|
276
|
-
|
|
277
|
-
const db = (_a = this.app) == null ? void 0 : _a.database;
|
|
271
|
+
const db = this.app?.database;
|
|
278
272
|
const luid = this.currentUser();
|
|
279
273
|
this.eUser = void 0;
|
|
280
274
|
this.saveCredentials(null);
|
|
281
275
|
if (luid)
|
|
282
|
-
await
|
|
276
|
+
await db?.collection("users").doc(luid?.uid).update({
|
|
283
277
|
logged: false,
|
|
284
278
|
lastLogged: Date.now()
|
|
285
|
-
})
|
|
279
|
+
});
|
|
286
280
|
return;
|
|
287
281
|
};
|
|
288
|
-
this.rules = async (path, oparation) => {
|
|
282
|
+
this.rules = async (path, oparation, uid) => {
|
|
289
283
|
const res = await new HttpsRequest({
|
|
290
284
|
method: "POST" /* POST */,
|
|
291
285
|
endpoint: this.client.getBaseUrl + "/auth/rules/verify",
|
|
@@ -294,7 +288,8 @@ var Authentication = class {
|
|
|
294
288
|
},
|
|
295
289
|
body: {
|
|
296
290
|
path,
|
|
297
|
-
op: oparation
|
|
291
|
+
op: oparation,
|
|
292
|
+
uid
|
|
298
293
|
}
|
|
299
294
|
}).sendRequest();
|
|
300
295
|
return res;
|
|
@@ -443,19 +438,17 @@ var ArraySnapshot = class _ArraySnapshot {
|
|
|
443
438
|
constructor(id = "", index, data, dt) {
|
|
444
439
|
this.data = data;
|
|
445
440
|
this.id = id;
|
|
446
|
-
this.dt = dt
|
|
441
|
+
this.dt = dt ?? Timestamp.now();
|
|
447
442
|
}
|
|
448
443
|
static fromMap(map) {
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
const
|
|
452
|
-
const document = (_f = (_e = map.data) != null ? _e : map.document) != null ? _f : map;
|
|
444
|
+
const index = map.index ?? map.index ?? -1;
|
|
445
|
+
const id = map.id ?? map._id ?? "";
|
|
446
|
+
const document = map.data ?? map.document ?? map;
|
|
453
447
|
return new _ArraySnapshot(id, index, document);
|
|
454
448
|
}
|
|
455
449
|
toMap() {
|
|
456
|
-
var _a;
|
|
457
450
|
return {
|
|
458
|
-
id:
|
|
451
|
+
id: this.id ?? "",
|
|
459
452
|
data: this.data,
|
|
460
453
|
dt: this.dt
|
|
461
454
|
};
|
|
@@ -608,9 +601,8 @@ var DocumentSnapshot = class _DocumentSnapshot {
|
|
|
608
601
|
this.data = doc;
|
|
609
602
|
}
|
|
610
603
|
static fromMap(map) {
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
const document = (_e = (_d = (_c = map.document) != null ? _c : map.documents) != null ? _d : map.data) != null ? _e : map;
|
|
604
|
+
const id = map.id ?? map._id ?? "";
|
|
605
|
+
const document = map.document ?? map.documents ?? map.data ?? map;
|
|
614
606
|
return new _DocumentSnapshot(id, document);
|
|
615
607
|
}
|
|
616
608
|
toMap() {
|
|
@@ -950,7 +942,6 @@ var CollectionRef = class {
|
|
|
950
942
|
this.db = db;
|
|
951
943
|
}
|
|
952
944
|
async syncPendingWrite(id, collection = "default") {
|
|
953
|
-
var _a;
|
|
954
945
|
const idb = await this.getIDB("edmaxlabs");
|
|
955
946
|
const tx = idb.transaction(collection, "readwrite");
|
|
956
947
|
const store = tx.store;
|
|
@@ -960,7 +951,7 @@ var CollectionRef = class {
|
|
|
960
951
|
try {
|
|
961
952
|
const res = await new HttpsRequest({
|
|
962
953
|
method: "POST" /* POST */,
|
|
963
|
-
endpoint: `${
|
|
954
|
+
endpoint: `${this.db?.getBaseUrl}/db/${packet.action}`.replace(
|
|
964
955
|
"$",
|
|
965
956
|
"/"
|
|
966
957
|
),
|
|
@@ -969,7 +960,7 @@ var CollectionRef = class {
|
|
|
969
960
|
data: packet
|
|
970
961
|
}
|
|
971
962
|
}).sendRequest();
|
|
972
|
-
if (res
|
|
963
|
+
if (res?.success) {
|
|
973
964
|
packet.status = "success";
|
|
974
965
|
packet.timestamp = Timestamp.now();
|
|
975
966
|
await store.put(packet);
|
|
@@ -982,7 +973,6 @@ var CollectionRef = class {
|
|
|
982
973
|
await tx.done;
|
|
983
974
|
}
|
|
984
975
|
async syncPendingWrites(collection) {
|
|
985
|
-
var _a;
|
|
986
976
|
const idb = await this.getIDB("edmaxlabs");
|
|
987
977
|
const tx = idb.transaction(collection, "readwrite");
|
|
988
978
|
const store = tx.store;
|
|
@@ -991,7 +981,7 @@ var CollectionRef = class {
|
|
|
991
981
|
try {
|
|
992
982
|
const res = await new HttpsRequest({
|
|
993
983
|
method: "POST" /* POST */,
|
|
994
|
-
endpoint: `${
|
|
984
|
+
endpoint: `${this.db?.getBaseUrl}/db/${packet.action}`.replace(
|
|
995
985
|
"$",
|
|
996
986
|
"/"
|
|
997
987
|
),
|
|
@@ -1000,7 +990,7 @@ var CollectionRef = class {
|
|
|
1000
990
|
data: packet
|
|
1001
991
|
}
|
|
1002
992
|
}).sendRequest();
|
|
1003
|
-
if (res
|
|
993
|
+
if (res?.success) {
|
|
1004
994
|
packet.status = "success";
|
|
1005
995
|
packet.timestamp = Timestamp.now();
|
|
1006
996
|
await store.put(packet);
|
|
@@ -1182,7 +1172,7 @@ var CollectionRef2 = class {
|
|
|
1182
1172
|
}
|
|
1183
1173
|
}).sendRequest();
|
|
1184
1174
|
console.log(res);
|
|
1185
|
-
if (!
|
|
1175
|
+
if (!res?.success || !res.id) {
|
|
1186
1176
|
payload.status = "failed";
|
|
1187
1177
|
if (this.db.getPersistence) {
|
|
1188
1178
|
}
|
|
@@ -1251,7 +1241,7 @@ var Batch = class {
|
|
|
1251
1241
|
ops: this.ops
|
|
1252
1242
|
}
|
|
1253
1243
|
}).sendRequest();
|
|
1254
|
-
if (res
|
|
1244
|
+
if (res?.error)
|
|
1255
1245
|
throw new Error(res.error.message || "Batch commit failed");
|
|
1256
1246
|
return res;
|
|
1257
1247
|
}
|
|
@@ -1316,7 +1306,7 @@ var Database = class {
|
|
|
1316
1306
|
ops: tx.ops
|
|
1317
1307
|
}
|
|
1318
1308
|
}).sendRequest();
|
|
1319
|
-
if (res
|
|
1309
|
+
if (res?.error)
|
|
1320
1310
|
throw new Error(res.error.message || "Transaction failed");
|
|
1321
1311
|
return res;
|
|
1322
1312
|
}
|
|
@@ -1345,8 +1335,7 @@ var Realtime = class {
|
|
|
1345
1335
|
this.events = ["error", "insert", "update", "delete"];
|
|
1346
1336
|
}
|
|
1347
1337
|
connect() {
|
|
1348
|
-
|
|
1349
|
-
if (!((_a = this.db.getAuth) == null ? void 0 : _a.token))
|
|
1338
|
+
if (!this.db.getAuth?.token)
|
|
1350
1339
|
throw new Error("Auth token missing");
|
|
1351
1340
|
this.socket = (0, import_socket.io)(this.db.getSocketUrl, {
|
|
1352
1341
|
transports: ["websocket"],
|
|
@@ -1355,19 +1344,16 @@ var Realtime = class {
|
|
|
1355
1344
|
return this.socket;
|
|
1356
1345
|
}
|
|
1357
1346
|
on(event, cb) {
|
|
1358
|
-
|
|
1359
|
-
(_a = this.socket) == null ? void 0 : _a.on(event, cb);
|
|
1347
|
+
this.socket?.on(event, cb);
|
|
1360
1348
|
}
|
|
1361
1349
|
off(event, cb) {
|
|
1362
|
-
var _a, _b;
|
|
1363
1350
|
if (cb)
|
|
1364
|
-
|
|
1351
|
+
this.socket?.off(event, cb);
|
|
1365
1352
|
else
|
|
1366
|
-
|
|
1353
|
+
this.socket?.removeAllListeners(event);
|
|
1367
1354
|
}
|
|
1368
1355
|
emit(event, data) {
|
|
1369
|
-
|
|
1370
|
-
(_a = this.socket) == null ? void 0 : _a.emit(event, data);
|
|
1356
|
+
this.socket?.emit(event, data);
|
|
1371
1357
|
}
|
|
1372
1358
|
// ------------------------------------------------------------
|
|
1373
1359
|
// 🔥 ADDITIONS BELOW — NO BREAKING CHANGES
|
|
@@ -1456,9 +1442,8 @@ var StorageSnapshot = class _StorageSnapshot {
|
|
|
1456
1442
|
this.data = file;
|
|
1457
1443
|
}
|
|
1458
1444
|
static fromMap(map) {
|
|
1459
|
-
|
|
1460
|
-
const
|
|
1461
|
-
const document = (_d = (_c = map.file) != null ? _c : map.data) != null ? _d : map;
|
|
1445
|
+
const id = map.id ?? map._id ?? "";
|
|
1446
|
+
const document = map.file ?? map.data ?? map;
|
|
1462
1447
|
return new _StorageSnapshot(id, document);
|
|
1463
1448
|
}
|
|
1464
1449
|
toMap() {
|