edmaxlabs-core 2.6.8 → 2.7.1
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 +71 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +71 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -86,6 +86,7 @@ declare class Authentication {
|
|
|
86
86
|
}) => Promise<Credentials | null>;
|
|
87
87
|
deleteUser: () => Promise<void>;
|
|
88
88
|
signOut: () => Promise<void>;
|
|
89
|
+
resetPassword: () => Promise<string>;
|
|
89
90
|
rules: (path: string, context: Record<string, any>) => Promise<{
|
|
90
91
|
success: boolean;
|
|
91
92
|
allowed: any;
|
|
@@ -199,6 +200,7 @@ declare class Query {
|
|
|
199
200
|
|
|
200
201
|
declare class CollectionRef {
|
|
201
202
|
private app;
|
|
203
|
+
private authentication;
|
|
202
204
|
readonly collection: string;
|
|
203
205
|
private persistence;
|
|
204
206
|
private syncEngine;
|
package/dist/index.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ declare class Authentication {
|
|
|
86
86
|
}) => Promise<Credentials | null>;
|
|
87
87
|
deleteUser: () => Promise<void>;
|
|
88
88
|
signOut: () => Promise<void>;
|
|
89
|
+
resetPassword: () => Promise<string>;
|
|
89
90
|
rules: (path: string, context: Record<string, any>) => Promise<{
|
|
90
91
|
success: boolean;
|
|
91
92
|
allowed: any;
|
|
@@ -199,6 +200,7 @@ declare class Query {
|
|
|
199
200
|
|
|
200
201
|
declare class CollectionRef {
|
|
201
202
|
private app;
|
|
203
|
+
private authentication;
|
|
202
204
|
readonly collection: string;
|
|
203
205
|
private persistence;
|
|
204
206
|
private syncEngine;
|
package/dist/index.mjs
CHANGED
|
@@ -162,6 +162,7 @@ var _Authentication = class _Authentication {
|
|
|
162
162
|
op: "===",
|
|
163
163
|
value: password
|
|
164
164
|
}).get();
|
|
165
|
+
console.log("Auth Data:", data);
|
|
165
166
|
if (data === void 0) {
|
|
166
167
|
throw new Error("Auth Failed.");
|
|
167
168
|
}
|
|
@@ -201,6 +202,20 @@ var _Authentication = class _Authentication {
|
|
|
201
202
|
});
|
|
202
203
|
return;
|
|
203
204
|
};
|
|
205
|
+
this.resetPassword = async () => {
|
|
206
|
+
const app = this.app?.getDatabase;
|
|
207
|
+
const luid = this.currentUser();
|
|
208
|
+
const payload = {
|
|
209
|
+
uid: luid?.uid,
|
|
210
|
+
ttl: 3
|
|
211
|
+
//minutes
|
|
212
|
+
};
|
|
213
|
+
const id = await app?.collection("_auth_tokens").add(payload);
|
|
214
|
+
if (id) {
|
|
215
|
+
return `https://auth.edmaxlabs.com/reset/${id}`;
|
|
216
|
+
}
|
|
217
|
+
throw new Error("Failed to request reset tokens. Try Again");
|
|
218
|
+
};
|
|
204
219
|
this.rules = async (path, context) => {
|
|
205
220
|
const res = await new HttpsRequest({
|
|
206
221
|
method: "POST" /* POST */,
|
|
@@ -221,7 +236,7 @@ var _Authentication = class _Authentication {
|
|
|
221
236
|
this.client = EdmaxLabs.instance;
|
|
222
237
|
this.app = new EdmaxLabs({
|
|
223
238
|
token: "auth",
|
|
224
|
-
project: "
|
|
239
|
+
project: "698457c2f7448550b9e166c4"
|
|
225
240
|
});
|
|
226
241
|
_Authentication.instance = this;
|
|
227
242
|
this.restoreSession();
|
|
@@ -414,7 +429,8 @@ var DocumentRef = class {
|
|
|
414
429
|
endpoint: `${this.app.getBaseUrl()}/db/update`,
|
|
415
430
|
headers: {
|
|
416
431
|
authorization: this.app.getConfig().token,
|
|
417
|
-
"x-project": this.app.getConfig().project
|
|
432
|
+
"x-project": this.app.getConfig().project,
|
|
433
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
418
434
|
},
|
|
419
435
|
body: { collection: this.collection, id: this.id, data }
|
|
420
436
|
}).sendRequest();
|
|
@@ -460,7 +476,8 @@ var DocumentRef = class {
|
|
|
460
476
|
endpoint: `${this.app.getBaseUrl()}/db/create`,
|
|
461
477
|
headers: {
|
|
462
478
|
authorization: this.app.getConfig().token,
|
|
463
|
-
"x-project": this.app.getConfig().project
|
|
479
|
+
"x-project": this.app.getConfig().project,
|
|
480
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
464
481
|
},
|
|
465
482
|
body: { collection: this.collection, data: { ...data, id: this.id } }
|
|
466
483
|
}).sendRequest();
|
|
@@ -516,7 +533,8 @@ var DocumentRef = class {
|
|
|
516
533
|
endpoint: `${this.app.getBaseUrl()}/db/delete`,
|
|
517
534
|
headers: {
|
|
518
535
|
authorization: this.app.getConfig().token,
|
|
519
|
-
"x-project": this.app.getConfig().project
|
|
536
|
+
"x-project": this.app.getConfig().project,
|
|
537
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
520
538
|
},
|
|
521
539
|
body: { collection: this.collection, id: this.id }
|
|
522
540
|
}).sendRequest();
|
|
@@ -549,7 +567,8 @@ var DocumentRef = class {
|
|
|
549
567
|
endpoint: `${this.app.getBaseUrl()}/db/read`,
|
|
550
568
|
headers: {
|
|
551
569
|
authorization: this.app.getConfig().token,
|
|
552
|
-
"x-project": this.app.getConfig().project
|
|
570
|
+
"x-project": this.app.getConfig().project,
|
|
571
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
553
572
|
},
|
|
554
573
|
body: {
|
|
555
574
|
collection: this.collection,
|
|
@@ -687,7 +706,7 @@ var Query = class {
|
|
|
687
706
|
return new HttpsRequest({
|
|
688
707
|
method: "POST" /* POST */,
|
|
689
708
|
endpoint: `${this.app.getBaseUrl()}/db/update`,
|
|
690
|
-
headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
|
|
709
|
+
headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project, "x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()) },
|
|
691
710
|
body: {
|
|
692
711
|
collection: this.collection,
|
|
693
712
|
filter: genfilter,
|
|
@@ -827,7 +846,11 @@ var Query = class {
|
|
|
827
846
|
const res = await new HttpsRequest({
|
|
828
847
|
method: "POST" /* POST */,
|
|
829
848
|
endpoint: `${this.app.getBaseUrl()}/db/read`,
|
|
830
|
-
headers: {
|
|
849
|
+
headers: {
|
|
850
|
+
authorization: this.app.getConfig().token,
|
|
851
|
+
"x-project": this.app.getConfig().project,
|
|
852
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
853
|
+
},
|
|
831
854
|
body: {
|
|
832
855
|
collection: this.collection,
|
|
833
856
|
filter: genfilter
|
|
@@ -930,6 +953,7 @@ var socketURI = "https://api.edmaxlabs.com";
|
|
|
930
953
|
var CollectionRef = class {
|
|
931
954
|
constructor(app, collection) {
|
|
932
955
|
this.app = app;
|
|
956
|
+
this.authentication = app.getAuthentication;
|
|
933
957
|
this.collection = collection;
|
|
934
958
|
this.persistence = app.offline().persistence;
|
|
935
959
|
this.syncEngine = app.offline().syncEngine;
|
|
@@ -982,9 +1006,13 @@ var CollectionRef = class {
|
|
|
982
1006
|
endpoint: `${this.app.getBaseUrl()}/db/create`,
|
|
983
1007
|
headers: {
|
|
984
1008
|
authorization: this.app.getConfig().token,
|
|
985
|
-
"x-project": this.app.getConfig().project
|
|
1009
|
+
"x-project": this.app.getConfig().project,
|
|
1010
|
+
user: JSON.stringify(this.authentication.currentUser()?.toMap())
|
|
986
1011
|
},
|
|
987
|
-
body: {
|
|
1012
|
+
body: {
|
|
1013
|
+
collection: this.collection,
|
|
1014
|
+
data: { ...data, id: "" }
|
|
1015
|
+
}
|
|
988
1016
|
}).sendRequest();
|
|
989
1017
|
if (!res?.success || !res.document)
|
|
990
1018
|
return null;
|
|
@@ -1039,7 +1067,9 @@ var CollectionRef = class {
|
|
|
1039
1067
|
endpoint: `${serverURI}/db/read`,
|
|
1040
1068
|
headers: {
|
|
1041
1069
|
authorization: this.app.getConfig().token,
|
|
1042
|
-
"x-project": this.app.getConfig().project
|
|
1070
|
+
"x-project": this.app.getConfig().project,
|
|
1071
|
+
user: JSON.stringify(this.authentication.currentUser()?.toMap()),
|
|
1072
|
+
"x-user": JSON.stringify(this.authentication.currentUser()?.toMap())
|
|
1043
1073
|
},
|
|
1044
1074
|
body: {
|
|
1045
1075
|
collection: this.collection,
|
|
@@ -1074,7 +1104,9 @@ var CollectionRef = class {
|
|
|
1074
1104
|
endpoint: `${serverURI}/db/read`,
|
|
1075
1105
|
headers: {
|
|
1076
1106
|
authorization: this.app.getConfig().token,
|
|
1077
|
-
"x-project": this.app.getConfig().project
|
|
1107
|
+
"x-project": this.app.getConfig().project,
|
|
1108
|
+
user: JSON.stringify(this.authentication.currentUser()?.toMap()),
|
|
1109
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
1078
1110
|
},
|
|
1079
1111
|
body: {
|
|
1080
1112
|
collection: this.collection,
|
|
@@ -1246,7 +1278,11 @@ var Batch = class {
|
|
|
1246
1278
|
const res = await new HttpsRequest({
|
|
1247
1279
|
method: "POST" /* POST */,
|
|
1248
1280
|
endpoint: `${serverURI}/db/batch`,
|
|
1249
|
-
headers: {
|
|
1281
|
+
headers: {
|
|
1282
|
+
authorization: this.app.getConfig().token,
|
|
1283
|
+
"x-project": this.app.getConfig().project,
|
|
1284
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
1285
|
+
},
|
|
1250
1286
|
body: { ops: this.ops }
|
|
1251
1287
|
}).sendRequest();
|
|
1252
1288
|
if (res?.error) {
|
|
@@ -1360,7 +1396,13 @@ var Realtime = class {
|
|
|
1360
1396
|
}
|
|
1361
1397
|
this.socket = io(this.app.getSocketUrl(), {
|
|
1362
1398
|
transports: ["websocket"],
|
|
1363
|
-
auth: {
|
|
1399
|
+
auth: {
|
|
1400
|
+
token: this.app.getConfig().token,
|
|
1401
|
+
"x-project": this.app.getConfig().project,
|
|
1402
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()),
|
|
1403
|
+
user: this.app.getAuthentication.currentUser()
|
|
1404
|
+
// Pass user info for personalized permissions
|
|
1405
|
+
},
|
|
1364
1406
|
autoConnect: true,
|
|
1365
1407
|
reconnection: true,
|
|
1366
1408
|
reconnectionAttempts: Infinity,
|
|
@@ -1497,7 +1539,7 @@ var Functions = class {
|
|
|
1497
1539
|
const res = await new HttpsRequest({
|
|
1498
1540
|
method: "POST" /* POST */,
|
|
1499
1541
|
endpoint: serverURI + "/functions/call/" + functionName,
|
|
1500
|
-
headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
|
|
1542
|
+
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()) },
|
|
1501
1543
|
body: data
|
|
1502
1544
|
}).sendRequest();
|
|
1503
1545
|
return res;
|
|
@@ -2462,7 +2504,7 @@ var SyncEngine = class {
|
|
|
2462
2504
|
const res = await new HttpsRequest({
|
|
2463
2505
|
method: "POST" /* POST */,
|
|
2464
2506
|
endpoint: `${this.app.getBaseUrl()}/db/create`,
|
|
2465
|
-
headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
|
|
2507
|
+
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()) },
|
|
2466
2508
|
body: {
|
|
2467
2509
|
collection: mutation.collection,
|
|
2468
2510
|
data: mutation.payload
|
|
@@ -2488,7 +2530,12 @@ var SyncEngine = class {
|
|
|
2488
2530
|
const res = await new HttpsRequest({
|
|
2489
2531
|
method: "POST" /* POST */,
|
|
2490
2532
|
endpoint: `${this.app.getBaseUrl()}/db/update`,
|
|
2491
|
-
headers: {
|
|
2533
|
+
headers: {
|
|
2534
|
+
authorization: this.app.getConfig().token,
|
|
2535
|
+
"x-project": this.app.getConfig().project,
|
|
2536
|
+
user: JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()),
|
|
2537
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
2538
|
+
},
|
|
2492
2539
|
body: {
|
|
2493
2540
|
collection: mutation.collection,
|
|
2494
2541
|
document: mutation.documentId,
|
|
@@ -2520,7 +2567,12 @@ var SyncEngine = class {
|
|
|
2520
2567
|
const res = await new HttpsRequest({
|
|
2521
2568
|
method: "POST" /* POST */,
|
|
2522
2569
|
endpoint: `${this.app.getBaseUrl()}/db/delete`,
|
|
2523
|
-
headers: {
|
|
2570
|
+
headers: {
|
|
2571
|
+
authorization: this.app.getConfig().token,
|
|
2572
|
+
"x-project": this.app.getConfig().project,
|
|
2573
|
+
user: JSON.stringify(this.app.getAuthentication.currentUser()?.toMap()),
|
|
2574
|
+
"x-user": JSON.stringify(this.app.getAuthentication.currentUser()?.toMap())
|
|
2575
|
+
},
|
|
2524
2576
|
body: {
|
|
2525
2577
|
collection: mutation.collection,
|
|
2526
2578
|
document: mutation.documentId
|
|
@@ -2661,11 +2713,10 @@ var StorageRef = class {
|
|
|
2661
2713
|
if (!srcFile) {
|
|
2662
2714
|
throw new Error("Invalid File");
|
|
2663
2715
|
}
|
|
2664
|
-
console.log("SRCF");
|
|
2665
2716
|
const res = await new HttpsRequest({
|
|
2666
2717
|
method: "POST" /* POST */,
|
|
2667
2718
|
endpoint: serverURI + "/storage/file/upload",
|
|
2668
|
-
headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
|
|
2719
|
+
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()) },
|
|
2669
2720
|
file: srcFile,
|
|
2670
2721
|
isMultipart: true
|
|
2671
2722
|
}).sendRequest();
|
|
@@ -2682,7 +2733,7 @@ var StorageRef = class {
|
|
|
2682
2733
|
const res = await new HttpsRequest({
|
|
2683
2734
|
method: "POST" /* POST */,
|
|
2684
2735
|
endpoint: serverURI + "/storage/file/delete",
|
|
2685
|
-
headers: { authorization: this.app.getConfig().token, "x-project": this.app.getConfig().project },
|
|
2736
|
+
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()) },
|
|
2686
2737
|
body: {
|
|
2687
2738
|
file_id: id
|
|
2688
2739
|
}
|