edmaxlabs-core 2.7.2 → 2.7.3
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 +75 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -7
- package/dist/index.d.ts +3 -7
- package/dist/index.mjs +75 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -45,10 +45,10 @@ interface DisplayInfo {
|
|
|
45
45
|
declare class Credentials {
|
|
46
46
|
uid: string;
|
|
47
47
|
displayInfo: DisplayInfo;
|
|
48
|
-
|
|
48
|
+
data: Record<string, any>;
|
|
49
|
+
verified: boolean;
|
|
49
50
|
createdAt: Timestamp;
|
|
50
51
|
updatedAt: Timestamp;
|
|
51
|
-
lastLogged: Timestamp;
|
|
52
52
|
private constructor();
|
|
53
53
|
static fromMap(map: Record<string, any>): Credentials;
|
|
54
54
|
toMap(): Record<string, any>;
|
|
@@ -85,12 +85,8 @@ declare class Authentication {
|
|
|
85
85
|
password: string;
|
|
86
86
|
}) => Promise<Credentials | null>;
|
|
87
87
|
deleteUser: () => Promise<void>;
|
|
88
|
+
resetPassword: () => Promise<any>;
|
|
88
89
|
signOut: () => Promise<void>;
|
|
89
|
-
resetPassword: () => Promise<string>;
|
|
90
|
-
rules: (path: string, context: Record<string, any>) => Promise<{
|
|
91
|
-
success: boolean;
|
|
92
|
-
allowed: any;
|
|
93
|
-
}>;
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
declare class DocumentSnapshot {
|
package/dist/index.d.ts
CHANGED
|
@@ -45,10 +45,10 @@ interface DisplayInfo {
|
|
|
45
45
|
declare class Credentials {
|
|
46
46
|
uid: string;
|
|
47
47
|
displayInfo: DisplayInfo;
|
|
48
|
-
|
|
48
|
+
data: Record<string, any>;
|
|
49
|
+
verified: boolean;
|
|
49
50
|
createdAt: Timestamp;
|
|
50
51
|
updatedAt: Timestamp;
|
|
51
|
-
lastLogged: Timestamp;
|
|
52
52
|
private constructor();
|
|
53
53
|
static fromMap(map: Record<string, any>): Credentials;
|
|
54
54
|
toMap(): Record<string, any>;
|
|
@@ -85,12 +85,8 @@ declare class Authentication {
|
|
|
85
85
|
password: string;
|
|
86
86
|
}) => Promise<Credentials | null>;
|
|
87
87
|
deleteUser: () => Promise<void>;
|
|
88
|
+
resetPassword: () => Promise<any>;
|
|
88
89
|
signOut: () => Promise<void>;
|
|
89
|
-
resetPassword: () => Promise<string>;
|
|
90
|
-
rules: (path: string, context: Record<string, any>) => Promise<{
|
|
91
|
-
success: boolean;
|
|
92
|
-
allowed: any;
|
|
93
|
-
}>;
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
declare class DocumentSnapshot {
|
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
1
|
// src/authentication/Credentials.ts
|
|
2
2
|
var Credentials = class _Credentials {
|
|
3
|
-
constructor(uid, displayInfo,
|
|
3
|
+
constructor(uid, displayInfo, data, verified, createdAt, updatedAt) {
|
|
4
4
|
this.uid = uid;
|
|
5
5
|
this.displayInfo = displayInfo;
|
|
6
|
+
this.data = data;
|
|
7
|
+
this.verified = verified;
|
|
6
8
|
this.createdAt = createdAt;
|
|
7
9
|
this.updatedAt = updatedAt;
|
|
8
|
-
this.lastLogged = lastLogged;
|
|
9
|
-
this.logged = logged === true;
|
|
10
10
|
}
|
|
11
11
|
static fromMap(map) {
|
|
12
|
-
const uid = map.id ?? map.uid ??
|
|
13
|
-
const data = map.data ?? map;
|
|
14
|
-
const
|
|
12
|
+
const uid = map.id ?? map.uid ?? map._id ?? null;
|
|
13
|
+
const data = map.data ?? map.user ?? map;
|
|
14
|
+
const displayInfo = data.displayInfo;
|
|
15
15
|
const createdAt = data.createdAt;
|
|
16
16
|
const updatedAt = data.updatedAt;
|
|
17
|
-
const lastLogged = data.lastLogged;
|
|
18
|
-
const logged = data.logged;
|
|
19
17
|
const result = new _Credentials(
|
|
20
18
|
uid,
|
|
21
|
-
|
|
19
|
+
displayInfo,
|
|
20
|
+
data.data,
|
|
21
|
+
data.verified,
|
|
22
22
|
createdAt,
|
|
23
|
-
updatedAt
|
|
24
|
-
lastLogged,
|
|
25
|
-
logged
|
|
23
|
+
updatedAt
|
|
26
24
|
);
|
|
27
25
|
return result;
|
|
28
26
|
}
|
|
@@ -30,10 +28,10 @@ var Credentials = class _Credentials {
|
|
|
30
28
|
return {
|
|
31
29
|
uid: this.uid,
|
|
32
30
|
displayInfo: this.displayInfo,
|
|
31
|
+
data: this.data,
|
|
32
|
+
verified: this.verified,
|
|
33
33
|
createdAt: this.createdAt,
|
|
34
|
-
updatedAt: this.updatedAt
|
|
35
|
-
lastLogged: this.lastLogged,
|
|
36
|
-
logged: this.logged
|
|
34
|
+
updatedAt: this.updatedAt
|
|
37
35
|
};
|
|
38
36
|
}
|
|
39
37
|
};
|
|
@@ -118,32 +116,23 @@ var _Authentication = class _Authentication {
|
|
|
118
116
|
}) => {
|
|
119
117
|
this.eUser = void 0;
|
|
120
118
|
this.saveCredentials(null);
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}).get();
|
|
127
|
-
if (data.length > 0) {
|
|
128
|
-
throw new Error("Email Already In Use.");
|
|
129
|
-
}
|
|
130
|
-
const userRef = await app?.collection("authentication").add({
|
|
131
|
-
email,
|
|
132
|
-
password,
|
|
133
|
-
logged: true,
|
|
134
|
-
lastLogged: Date.now(),
|
|
135
|
-
displayInfo: {
|
|
136
|
-
firstname: email.split("@")[0],
|
|
137
|
-
lastname: "",
|
|
138
|
-
surname: "",
|
|
139
|
-
profile: "./logo.png",
|
|
119
|
+
const res = await new HttpsRequest({
|
|
120
|
+
method: "POST" /* POST */,
|
|
121
|
+
endpoint: `${this.app?.getBaseUrl()}/auth/create`,
|
|
122
|
+
headers: { "authorization": this.app?.getConfig().token ?? "", "x-project": this.app?.getConfig().project ?? "" },
|
|
123
|
+
body: {
|
|
140
124
|
email,
|
|
141
|
-
|
|
125
|
+
password,
|
|
126
|
+
project: this.client?.getConfig().project
|
|
142
127
|
}
|
|
143
|
-
});
|
|
144
|
-
if (!
|
|
145
|
-
throw new Error("Something went wrong
|
|
128
|
+
}).sendRequest();
|
|
129
|
+
if (!res.success) {
|
|
130
|
+
throw new Error("Something went wrong. Try Again.");
|
|
146
131
|
}
|
|
132
|
+
if (res.success === false) {
|
|
133
|
+
throw new Error(res.error ?? "Authentication Failed");
|
|
134
|
+
}
|
|
135
|
+
const userRef = res.result;
|
|
147
136
|
this.eUser = Credentials.fromMap(userRef);
|
|
148
137
|
this.saveCredentials(this.eUser);
|
|
149
138
|
return Credentials.fromMap(userRef.toMap());
|
|
@@ -152,28 +141,23 @@ var _Authentication = class _Authentication {
|
|
|
152
141
|
email,
|
|
153
142
|
password
|
|
154
143
|
}) => {
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}).
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
throw new Error("Auth Failed.");
|
|
144
|
+
const res = await new HttpsRequest({
|
|
145
|
+
method: "POST" /* POST */,
|
|
146
|
+
endpoint: `${this.app?.getBaseUrl()}/auth/login`,
|
|
147
|
+
headers: { "authorization": this.app?.getConfig().token ?? "", "x-project": this.app?.getConfig().project ?? "" },
|
|
148
|
+
body: {
|
|
149
|
+
email,
|
|
150
|
+
password,
|
|
151
|
+
project: this.client?.getConfig().project
|
|
152
|
+
}
|
|
153
|
+
}).sendRequest();
|
|
154
|
+
if (!res.success) {
|
|
155
|
+
throw new Error("Something went wrong. Try Again.");
|
|
168
156
|
}
|
|
169
|
-
if (
|
|
170
|
-
throw new Error(
|
|
157
|
+
if (res.success === false) {
|
|
158
|
+
throw new Error(res.error ?? "Authentication Failed");
|
|
171
159
|
}
|
|
172
|
-
const _data =
|
|
173
|
-
await app?.collection("authentication").doc(_data.id).update({
|
|
174
|
-
logged: true,
|
|
175
|
-
lastLogged: Date.now()
|
|
176
|
-
});
|
|
160
|
+
const _data = res.result;
|
|
177
161
|
this.eUser = Credentials.fromMap(_data);
|
|
178
162
|
this.saveCredentials(this.eUser);
|
|
179
163
|
return Credentials.fromMap(_data);
|
|
@@ -182,62 +166,54 @@ var _Authentication = class _Authentication {
|
|
|
182
166
|
if (!this.eUser) {
|
|
183
167
|
throw new Error("No User Signed in");
|
|
184
168
|
}
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
169
|
+
const res = await new HttpsRequest({
|
|
170
|
+
method: "POST" /* POST */,
|
|
171
|
+
endpoint: `${this.app?.getBaseUrl()}/auth/delete`,
|
|
172
|
+
headers: { "authorization": this.app?.getConfig().token ?? "", "x-project": this.app?.getConfig().project ?? "" },
|
|
173
|
+
body: {
|
|
174
|
+
uid: this.eUser.uid,
|
|
175
|
+
project: this.client?.getConfig().project
|
|
176
|
+
}
|
|
177
|
+
}).sendRequest();
|
|
178
|
+
if (!res.status) {
|
|
179
|
+
throw new Error("Something went wrong. Try Again.");
|
|
180
|
+
}
|
|
181
|
+
if (res.status === false) {
|
|
182
|
+
throw new Error(res.error ?? "Authentication Failed");
|
|
189
183
|
}
|
|
190
184
|
this.eUser = void 0;
|
|
191
185
|
this.saveCredentials(null);
|
|
192
186
|
};
|
|
193
|
-
this.signOut = async () => {
|
|
194
|
-
const app = this.app?.getDatabase;
|
|
195
|
-
const luid = this.currentUser();
|
|
196
|
-
this.eUser = void 0;
|
|
197
|
-
this.saveCredentials(null);
|
|
198
|
-
if (luid)
|
|
199
|
-
await app?.collection("authentication").doc(luid?.uid).update({
|
|
200
|
-
logged: false,
|
|
201
|
-
lastLogged: Date.now()
|
|
202
|
-
});
|
|
203
|
-
return;
|
|
204
|
-
};
|
|
205
187
|
this.resetPassword = async () => {
|
|
206
188
|
const app = this.app?.getDatabase;
|
|
207
189
|
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
|
-
};
|
|
219
|
-
this.rules = async (path, context) => {
|
|
220
190
|
const res = await new HttpsRequest({
|
|
221
191
|
method: "POST" /* POST */,
|
|
222
|
-
endpoint: this.
|
|
223
|
-
headers: {
|
|
224
|
-
authorization: this.client.getConfig().token,
|
|
225
|
-
project: this.client.getConfig().project
|
|
226
|
-
},
|
|
192
|
+
endpoint: `${this.app?.getBaseUrl()}/auth/reset`,
|
|
193
|
+
headers: { "authorization": this.app?.getConfig().token ?? "", "x-project": this.app?.getConfig().project ?? "" },
|
|
227
194
|
body: {
|
|
228
|
-
|
|
229
|
-
|
|
195
|
+
uid: luid,
|
|
196
|
+
project: this.client?.getConfig().project
|
|
230
197
|
}
|
|
231
198
|
}).sendRequest();
|
|
232
|
-
|
|
199
|
+
if (!res.status) {
|
|
200
|
+
throw new Error("Something went wrong. Try Again.");
|
|
201
|
+
}
|
|
202
|
+
if (res.status === false) {
|
|
203
|
+
throw new Error(res.error ?? "Authentication Failed");
|
|
204
|
+
}
|
|
205
|
+
const url = res.url;
|
|
206
|
+
return url;
|
|
207
|
+
};
|
|
208
|
+
this.signOut = async () => {
|
|
209
|
+
this.eUser = void 0;
|
|
210
|
+
this.saveCredentials(null);
|
|
211
|
+
return;
|
|
233
212
|
};
|
|
234
213
|
if (_Authentication.instance)
|
|
235
214
|
return _Authentication.instance;
|
|
236
215
|
this.client = EdmaxLabs.instance;
|
|
237
|
-
this.app =
|
|
238
|
-
token: "auth",
|
|
239
|
-
project: "698457c2f7448550b9e166c4"
|
|
240
|
-
});
|
|
216
|
+
this.app = EdmaxLabs.instance;
|
|
241
217
|
_Authentication.instance = this;
|
|
242
218
|
this.restoreSession();
|
|
243
219
|
}
|
|
@@ -310,7 +286,7 @@ var _Authentication = class _Authentication {
|
|
|
310
286
|
onSignOut?.();
|
|
311
287
|
return;
|
|
312
288
|
}
|
|
313
|
-
const userRef = this.app?.getDatabase.collection("
|
|
289
|
+
const userRef = this.app?.getDatabase.collection("__users").doc(creds.uid);
|
|
314
290
|
if (!userRef)
|
|
315
291
|
return;
|
|
316
292
|
userDocUnsubscribe = userRef.onSnapshot(
|