edmaxlabs-core 2.6.9 → 2.7.2

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 CHANGED
@@ -151,7 +151,7 @@ var _Authentication = class _Authentication {
151
151
  this.eUser = void 0;
152
152
  this.saveCredentials(null);
153
153
  const app = this.app?.getDatabase;
154
- const data = await app?.collection("users").query.where({
154
+ const data = await app?.collection("authentication").query.where({
155
155
  key: "email",
156
156
  op: "===",
157
157
  value: email
@@ -159,7 +159,7 @@ var _Authentication = class _Authentication {
159
159
  if (data.length > 0) {
160
160
  throw new Error("Email Already In Use.");
161
161
  }
162
- const userRef = await app?.collection("users").add({
162
+ const userRef = await app?.collection("authentication").add({
163
163
  email,
164
164
  password,
165
165
  logged: true,
@@ -185,7 +185,7 @@ var _Authentication = class _Authentication {
185
185
  password
186
186
  }) => {
187
187
  const app = this.app?.getDatabase;
188
- const data = await app?.collection("users").query.where({
188
+ const data = await app?.collection("authentication").query.where({
189
189
  key: "email",
190
190
  op: "===",
191
191
  value: email
@@ -194,6 +194,7 @@ var _Authentication = class _Authentication {
194
194
  op: "===",
195
195
  value: password
196
196
  }).get();
197
+ console.log("Auth Data:", data);
197
198
  if (data === void 0) {
198
199
  throw new Error("Auth Failed.");
199
200
  }
@@ -201,7 +202,7 @@ var _Authentication = class _Authentication {
201
202
  throw new Error("User Not Found.");
202
203
  }
203
204
  const _data = data[0];
204
- await app?.collection("users").doc(_data.id).update({
205
+ await app?.collection("authentication").doc(_data.id).update({
205
206
  logged: true,
206
207
  lastLogged: Date.now()
207
208
  });
@@ -214,7 +215,7 @@ var _Authentication = class _Authentication {
214
215
  throw new Error("No User Signed in");
215
216
  }
216
217
  const app = this.app?.getDatabase;
217
- const userRef = await app?.collection("users").doc(this.eUser.uid).delete();
218
+ const userRef = await app?.collection("authentication").doc(this.eUser.uid).delete();
218
219
  if (userRef) {
219
220
  throw new Error("Something went wrong try Again.");
220
221
  }
@@ -227,7 +228,7 @@ var _Authentication = class _Authentication {
227
228
  this.eUser = void 0;
228
229
  this.saveCredentials(null);
229
230
  if (luid)
230
- await app?.collection("users").doc(luid?.uid).update({
231
+ await app?.collection("authentication").doc(luid?.uid).update({
231
232
  logged: false,
232
233
  lastLogged: Date.now()
233
234
  });
@@ -267,7 +268,7 @@ var _Authentication = class _Authentication {
267
268
  this.client = EdmaxLabs.instance;
268
269
  this.app = new EdmaxLabs({
269
270
  token: "auth",
270
- project: "6922d5982b23ae6a12e51d85"
271
+ project: "698457c2f7448550b9e166c4"
271
272
  });
272
273
  _Authentication.instance = this;
273
274
  this.restoreSession();
@@ -341,7 +342,7 @@ var _Authentication = class _Authentication {
341
342
  onSignOut?.();
342
343
  return;
343
344
  }
344
- const userRef = this.app?.getDatabase.collection("users").doc(creds.uid);
345
+ const userRef = this.app?.getDatabase.collection("authentication").doc(creds.uid);
345
346
  if (!userRef)
346
347
  return;
347
348
  userDocUnsubscribe = userRef.onSnapshot(
@@ -460,7 +461,8 @@ var DocumentRef = class {
460
461
  endpoint: `${this.app.getBaseUrl()}/db/update`,
461
462
  headers: {
462
463
  authorization: this.app.getConfig().token,
463
- "x-project": this.app.getConfig().project
464
+ "x-project": this.app.getConfig().project,
465
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
464
466
  },
465
467
  body: { collection: this.collection, id: this.id, data }
466
468
  }).sendRequest();
@@ -506,7 +508,8 @@ var DocumentRef = class {
506
508
  endpoint: `${this.app.getBaseUrl()}/db/create`,
507
509
  headers: {
508
510
  authorization: this.app.getConfig().token,
509
- "x-project": this.app.getConfig().project
511
+ "x-project": this.app.getConfig().project,
512
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
510
513
  },
511
514
  body: { collection: this.collection, data: { ...data, id: this.id } }
512
515
  }).sendRequest();
@@ -562,7 +565,8 @@ var DocumentRef = class {
562
565
  endpoint: `${this.app.getBaseUrl()}/db/delete`,
563
566
  headers: {
564
567
  authorization: this.app.getConfig().token,
565
- "x-project": this.app.getConfig().project
568
+ "x-project": this.app.getConfig().project,
569
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
566
570
  },
567
571
  body: { collection: this.collection, id: this.id }
568
572
  }).sendRequest();
@@ -595,7 +599,8 @@ var DocumentRef = class {
595
599
  endpoint: `${this.app.getBaseUrl()}/db/read`,
596
600
  headers: {
597
601
  authorization: this.app.getConfig().token,
598
- "x-project": this.app.getConfig().project
602
+ "x-project": this.app.getConfig().project,
603
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
599
604
  },
600
605
  body: {
601
606
  collection: this.collection,
@@ -733,7 +738,7 @@ var Query = class {
733
738
  return new HttpsRequest({
734
739
  method: "POST" /* POST */,
735
740
  endpoint: `${this.app.getBaseUrl()}/db/update`,
736
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
741
+ headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project, "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()) },
737
742
  body: {
738
743
  collection: this.collection,
739
744
  filter: genfilter,
@@ -873,7 +878,11 @@ var Query = class {
873
878
  const res = await new HttpsRequest({
874
879
  method: "POST" /* POST */,
875
880
  endpoint: `${this.app.getBaseUrl()}/db/read`,
876
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
881
+ headers: {
882
+ authorization: this.app.getConfig().token,
883
+ "x-project": this.app.getConfig().project,
884
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
885
+ },
877
886
  body: {
878
887
  collection: this.collection,
879
888
  filter: genfilter
@@ -976,6 +985,7 @@ var socketURI = "https://api.edmaxlabs.com";
976
985
  var CollectionRef = class {
977
986
  constructor(app, collection) {
978
987
  this.app = app;
988
+ this.authentication = app.getAuthentication;
979
989
  this.collection = collection;
980
990
  this.persistence = app.offline().persistence;
981
991
  this.syncEngine = app.offline().syncEngine;
@@ -1028,9 +1038,13 @@ var CollectionRef = class {
1028
1038
  endpoint: `${this.app.getBaseUrl()}/db/create`,
1029
1039
  headers: {
1030
1040
  authorization: this.app.getConfig().token,
1031
- "x-project": this.app.getConfig().project
1041
+ "x-project": this.app.getConfig().project,
1042
+ user: JSON.stringify(this.authentication.currentUser()?.toMap())
1032
1043
  },
1033
- body: { collection: this.collection, data: { ...data, id: "" } }
1044
+ body: {
1045
+ collection: this.collection,
1046
+ data: { ...data, id: "" }
1047
+ }
1034
1048
  }).sendRequest();
1035
1049
  if (!res?.success || !res.document)
1036
1050
  return null;
@@ -1085,7 +1099,9 @@ var CollectionRef = class {
1085
1099
  endpoint: `${serverURI}/db/read`,
1086
1100
  headers: {
1087
1101
  authorization: this.app.getConfig().token,
1088
- "x-project": this.app.getConfig().project
1102
+ "x-project": this.app.getConfig().project,
1103
+ user: JSON.stringify(this.authentication.currentUser()?.toMap()),
1104
+ "x-user": JSON.stringify(this.authentication.currentUser()?.toMap())
1089
1105
  },
1090
1106
  body: {
1091
1107
  collection: this.collection,
@@ -1120,7 +1136,9 @@ var CollectionRef = class {
1120
1136
  endpoint: `${serverURI}/db/read`,
1121
1137
  headers: {
1122
1138
  authorization: this.app.getConfig().token,
1123
- "x-project": this.app.getConfig().project
1139
+ "x-project": this.app.getConfig().project,
1140
+ user: JSON.stringify(this.authentication.currentUser()?.toMap()),
1141
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
1124
1142
  },
1125
1143
  body: {
1126
1144
  collection: this.collection,
@@ -1292,7 +1310,11 @@ var Batch = class {
1292
1310
  const res = await new HttpsRequest({
1293
1311
  method: "POST" /* POST */,
1294
1312
  endpoint: `${serverURI}/db/batch`,
1295
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
1313
+ headers: {
1314
+ authorization: this.app.getConfig().token,
1315
+ "x-project": this.app.getConfig().project,
1316
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
1317
+ },
1296
1318
  body: { ops: this.ops }
1297
1319
  }).sendRequest();
1298
1320
  if (res?.error) {
@@ -1406,7 +1428,13 @@ var Realtime = class {
1406
1428
  }
1407
1429
  this.socket = (0, import_socket.io)(this.app.getSocketUrl(), {
1408
1430
  transports: ["websocket"],
1409
- auth: { token: this.app.getConfig().token, "x-project": this.app.getConfig().project },
1431
+ auth: {
1432
+ token: this.app.getConfig().token,
1433
+ "x-project": this.app.getConfig().project,
1434
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()),
1435
+ user: this.app.getAuthentication.currentUser()
1436
+ // Pass user info for personalized permissions
1437
+ },
1410
1438
  autoConnect: true,
1411
1439
  reconnection: true,
1412
1440
  reconnectionAttempts: Infinity,
@@ -1543,7 +1571,7 @@ var Functions = class {
1543
1571
  const res = await new HttpsRequest({
1544
1572
  method: "POST" /* POST */,
1545
1573
  endpoint: serverURI + "/functions/call/" + functionName,
1546
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
1574
+ headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project, "user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()), "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()) },
1547
1575
  body: data
1548
1576
  }).sendRequest();
1549
1577
  return res;
@@ -2508,7 +2536,7 @@ var SyncEngine = class {
2508
2536
  const res = await new HttpsRequest({
2509
2537
  method: "POST" /* POST */,
2510
2538
  endpoint: `${this.app.getBaseUrl()}/db/create`,
2511
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
2539
+ headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project, user: JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()), "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()) },
2512
2540
  body: {
2513
2541
  collection: mutation.collection,
2514
2542
  data: mutation.payload
@@ -2534,7 +2562,12 @@ var SyncEngine = class {
2534
2562
  const res = await new HttpsRequest({
2535
2563
  method: "POST" /* POST */,
2536
2564
  endpoint: `${this.app.getBaseUrl()}/db/update`,
2537
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
2565
+ headers: {
2566
+ authorization: this.app.getConfig().token,
2567
+ "x-project": this.app.getConfig().project,
2568
+ user: JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()),
2569
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
2570
+ },
2538
2571
  body: {
2539
2572
  collection: mutation.collection,
2540
2573
  document: mutation.documentId,
@@ -2566,7 +2599,12 @@ var SyncEngine = class {
2566
2599
  const res = await new HttpsRequest({
2567
2600
  method: "POST" /* POST */,
2568
2601
  endpoint: `${this.app.getBaseUrl()}/db/delete`,
2569
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
2602
+ headers: {
2603
+ authorization: this.app.getConfig().token,
2604
+ "x-project": this.app.getConfig().project,
2605
+ user: JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()),
2606
+ "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
2607
+ },
2570
2608
  body: {
2571
2609
  collection: mutation.collection,
2572
2610
  document: mutation.documentId
@@ -2707,11 +2745,10 @@ var StorageRef = class {
2707
2745
  if (!srcFile) {
2708
2746
  throw new Error("Invalid File");
2709
2747
  }
2710
- console.log("SRCF");
2711
2748
  const res = await new HttpsRequest({
2712
2749
  method: "POST" /* POST */,
2713
2750
  endpoint: serverURI + "/storage/file/upload",
2714
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
2751
+ headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project, "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()), "user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()) },
2715
2752
  file: srcFile,
2716
2753
  isMultipart: true
2717
2754
  }).sendRequest();
@@ -2728,7 +2765,7 @@ var StorageRef = class {
2728
2765
  const res = await new HttpsRequest({
2729
2766
  method: "POST" /* POST */,
2730
2767
  endpoint: serverURI + "/storage/file/delete",
2731
- headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
2768
+ headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project, "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()), "user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()) },
2732
2769
  body: {
2733
2770
  file_id: id
2734
2771
  }