edmaxlabs-core 1.0.3 → 1.0.4
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 +45 -61
- package/dist/index.cjs.map +1 -1
- package/dist/{index.js → index.mjs} +46 -62
- package/dist/{index.js.map → index.mjs.map} +1 -1
- package/package.json +3 -3
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,47 +238,45 @@ 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
282
|
this.rules = async (path, oparation) => {
|
|
@@ -443,19 +437,17 @@ var ArraySnapshot = class _ArraySnapshot {
|
|
|
443
437
|
constructor(id = "", index, data, dt) {
|
|
444
438
|
this.data = data;
|
|
445
439
|
this.id = id;
|
|
446
|
-
this.dt = dt
|
|
440
|
+
this.dt = dt ?? Timestamp.now();
|
|
447
441
|
}
|
|
448
442
|
static fromMap(map) {
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
const
|
|
452
|
-
const document = (_f = (_e = map.data) != null ? _e : map.document) != null ? _f : map;
|
|
443
|
+
const index = map.index ?? map.index ?? -1;
|
|
444
|
+
const id = map.id ?? map._id ?? "";
|
|
445
|
+
const document = map.data ?? map.document ?? map;
|
|
453
446
|
return new _ArraySnapshot(id, index, document);
|
|
454
447
|
}
|
|
455
448
|
toMap() {
|
|
456
|
-
var _a;
|
|
457
449
|
return {
|
|
458
|
-
id:
|
|
450
|
+
id: this.id ?? "",
|
|
459
451
|
data: this.data,
|
|
460
452
|
dt: this.dt
|
|
461
453
|
};
|
|
@@ -608,9 +600,8 @@ var DocumentSnapshot = class _DocumentSnapshot {
|
|
|
608
600
|
this.data = doc;
|
|
609
601
|
}
|
|
610
602
|
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;
|
|
603
|
+
const id = map.id ?? map._id ?? "";
|
|
604
|
+
const document = map.document ?? map.documents ?? map.data ?? map;
|
|
614
605
|
return new _DocumentSnapshot(id, document);
|
|
615
606
|
}
|
|
616
607
|
toMap() {
|
|
@@ -950,7 +941,6 @@ var CollectionRef = class {
|
|
|
950
941
|
this.db = db;
|
|
951
942
|
}
|
|
952
943
|
async syncPendingWrite(id, collection = "default") {
|
|
953
|
-
var _a;
|
|
954
944
|
const idb = await this.getIDB("edmaxlabs");
|
|
955
945
|
const tx = idb.transaction(collection, "readwrite");
|
|
956
946
|
const store = tx.store;
|
|
@@ -960,7 +950,7 @@ var CollectionRef = class {
|
|
|
960
950
|
try {
|
|
961
951
|
const res = await new HttpsRequest({
|
|
962
952
|
method: "POST" /* POST */,
|
|
963
|
-
endpoint: `${
|
|
953
|
+
endpoint: `${this.db?.getBaseUrl}/db/${packet.action}`.replace(
|
|
964
954
|
"$",
|
|
965
955
|
"/"
|
|
966
956
|
),
|
|
@@ -969,7 +959,7 @@ var CollectionRef = class {
|
|
|
969
959
|
data: packet
|
|
970
960
|
}
|
|
971
961
|
}).sendRequest();
|
|
972
|
-
if (res
|
|
962
|
+
if (res?.success) {
|
|
973
963
|
packet.status = "success";
|
|
974
964
|
packet.timestamp = Timestamp.now();
|
|
975
965
|
await store.put(packet);
|
|
@@ -982,7 +972,6 @@ var CollectionRef = class {
|
|
|
982
972
|
await tx.done;
|
|
983
973
|
}
|
|
984
974
|
async syncPendingWrites(collection) {
|
|
985
|
-
var _a;
|
|
986
975
|
const idb = await this.getIDB("edmaxlabs");
|
|
987
976
|
const tx = idb.transaction(collection, "readwrite");
|
|
988
977
|
const store = tx.store;
|
|
@@ -991,7 +980,7 @@ var CollectionRef = class {
|
|
|
991
980
|
try {
|
|
992
981
|
const res = await new HttpsRequest({
|
|
993
982
|
method: "POST" /* POST */,
|
|
994
|
-
endpoint: `${
|
|
983
|
+
endpoint: `${this.db?.getBaseUrl}/db/${packet.action}`.replace(
|
|
995
984
|
"$",
|
|
996
985
|
"/"
|
|
997
986
|
),
|
|
@@ -1000,7 +989,7 @@ var CollectionRef = class {
|
|
|
1000
989
|
data: packet
|
|
1001
990
|
}
|
|
1002
991
|
}).sendRequest();
|
|
1003
|
-
if (res
|
|
992
|
+
if (res?.success) {
|
|
1004
993
|
packet.status = "success";
|
|
1005
994
|
packet.timestamp = Timestamp.now();
|
|
1006
995
|
await store.put(packet);
|
|
@@ -1182,7 +1171,7 @@ var CollectionRef2 = class {
|
|
|
1182
1171
|
}
|
|
1183
1172
|
}).sendRequest();
|
|
1184
1173
|
console.log(res);
|
|
1185
|
-
if (!
|
|
1174
|
+
if (!res?.success || !res.id) {
|
|
1186
1175
|
payload.status = "failed";
|
|
1187
1176
|
if (this.db.getPersistence) {
|
|
1188
1177
|
}
|
|
@@ -1251,7 +1240,7 @@ var Batch = class {
|
|
|
1251
1240
|
ops: this.ops
|
|
1252
1241
|
}
|
|
1253
1242
|
}).sendRequest();
|
|
1254
|
-
if (res
|
|
1243
|
+
if (res?.error)
|
|
1255
1244
|
throw new Error(res.error.message || "Batch commit failed");
|
|
1256
1245
|
return res;
|
|
1257
1246
|
}
|
|
@@ -1316,7 +1305,7 @@ var Database = class {
|
|
|
1316
1305
|
ops: tx.ops
|
|
1317
1306
|
}
|
|
1318
1307
|
}).sendRequest();
|
|
1319
|
-
if (res
|
|
1308
|
+
if (res?.error)
|
|
1320
1309
|
throw new Error(res.error.message || "Transaction failed");
|
|
1321
1310
|
return res;
|
|
1322
1311
|
}
|
|
@@ -1345,8 +1334,7 @@ var Realtime = class {
|
|
|
1345
1334
|
this.events = ["error", "insert", "update", "delete"];
|
|
1346
1335
|
}
|
|
1347
1336
|
connect() {
|
|
1348
|
-
|
|
1349
|
-
if (!((_a = this.db.getAuth) == null ? void 0 : _a.token))
|
|
1337
|
+
if (!this.db.getAuth?.token)
|
|
1350
1338
|
throw new Error("Auth token missing");
|
|
1351
1339
|
this.socket = (0, import_socket.io)(this.db.getSocketUrl, {
|
|
1352
1340
|
transports: ["websocket"],
|
|
@@ -1355,19 +1343,16 @@ var Realtime = class {
|
|
|
1355
1343
|
return this.socket;
|
|
1356
1344
|
}
|
|
1357
1345
|
on(event, cb) {
|
|
1358
|
-
|
|
1359
|
-
(_a = this.socket) == null ? void 0 : _a.on(event, cb);
|
|
1346
|
+
this.socket?.on(event, cb);
|
|
1360
1347
|
}
|
|
1361
1348
|
off(event, cb) {
|
|
1362
|
-
var _a, _b;
|
|
1363
1349
|
if (cb)
|
|
1364
|
-
|
|
1350
|
+
this.socket?.off(event, cb);
|
|
1365
1351
|
else
|
|
1366
|
-
|
|
1352
|
+
this.socket?.removeAllListeners(event);
|
|
1367
1353
|
}
|
|
1368
1354
|
emit(event, data) {
|
|
1369
|
-
|
|
1370
|
-
(_a = this.socket) == null ? void 0 : _a.emit(event, data);
|
|
1355
|
+
this.socket?.emit(event, data);
|
|
1371
1356
|
}
|
|
1372
1357
|
// ------------------------------------------------------------
|
|
1373
1358
|
// 🔥 ADDITIONS BELOW — NO BREAKING CHANGES
|
|
@@ -1456,9 +1441,8 @@ var StorageSnapshot = class _StorageSnapshot {
|
|
|
1456
1441
|
this.data = file;
|
|
1457
1442
|
}
|
|
1458
1443
|
static fromMap(map) {
|
|
1459
|
-
|
|
1460
|
-
const
|
|
1461
|
-
const document = (_d = (_c = map.file) != null ? _c : map.data) != null ? _d : map;
|
|
1444
|
+
const id = map.id ?? map._id ?? "";
|
|
1445
|
+
const document = map.file ?? map.data ?? map;
|
|
1462
1446
|
return new _StorageSnapshot(id, document);
|
|
1463
1447
|
}
|
|
1464
1448
|
toMap() {
|