edmaxlabs-core 1.2.0 → 1.2.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 +72 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +72 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -110,6 +110,26 @@ var HttpsRequest = class {
|
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
+
// src/utils/waiter.ts
|
|
114
|
+
var listeners = /* @__PURE__ */ new Map();
|
|
115
|
+
var waiters = /* @__PURE__ */ new Map();
|
|
116
|
+
function emitValue(key, value) {
|
|
117
|
+
const keyListeners = listeners.get(key) || [];
|
|
118
|
+
keyListeners.forEach((listener) => listener(value));
|
|
119
|
+
const keyWaiters = waiters.get(key) || [];
|
|
120
|
+
keyWaiters.forEach((resolve) => resolve(value));
|
|
121
|
+
waiters.delete(key);
|
|
122
|
+
}
|
|
123
|
+
function onValue(key, callback) {
|
|
124
|
+
const current = listeners.get(key) || [];
|
|
125
|
+
current.push(callback);
|
|
126
|
+
listeners.set(key, current);
|
|
127
|
+
return () => {
|
|
128
|
+
const next = (listeners.get(key) || []).filter((cb) => cb !== callback);
|
|
129
|
+
listeners.set(key, next);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
113
133
|
// src/authentication/Authentication.ts
|
|
114
134
|
var Authentication = class {
|
|
115
135
|
constructor() {
|
|
@@ -127,6 +147,7 @@ var Authentication = class {
|
|
|
127
147
|
return;
|
|
128
148
|
}
|
|
129
149
|
ldb.setItem("eauth", JSON.stringify(credentials));
|
|
150
|
+
emitValue("credentials", credentials);
|
|
130
151
|
};
|
|
131
152
|
this.currentUser = () => {
|
|
132
153
|
const ldb = localStorage;
|
|
@@ -142,48 +163,59 @@ var Authentication = class {
|
|
|
142
163
|
onSignOut,
|
|
143
164
|
onDeleted
|
|
144
165
|
}) => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
let userDocUnsubscribe;
|
|
167
|
+
const attachUserListener = (creds) => {
|
|
168
|
+
if (userDocUnsubscribe) {
|
|
169
|
+
userDocUnsubscribe();
|
|
170
|
+
userDocUnsubscribe = void 0;
|
|
171
|
+
}
|
|
172
|
+
if (!creds) {
|
|
173
|
+
this.eUser = void 0;
|
|
174
|
+
onSignOut?.();
|
|
151
175
|
return;
|
|
152
|
-
if (change === "insert") {
|
|
153
|
-
if (snapshot.data.logged === "false" || snapshot.data.logged === false) {
|
|
154
|
-
this.eUser = void 0;
|
|
155
|
-
this.saveCredentials(null);
|
|
156
|
-
if (onSignOut)
|
|
157
|
-
onSignOut();
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
const result = Credentials.fromMap(snapshot.toMap());
|
|
161
|
-
this.eUser = result;
|
|
162
|
-
this.saveCredentials(result);
|
|
163
|
-
onChange(result);
|
|
164
176
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
177
|
+
const userRef = this.app?.database.collection("users").doc(creds.uid);
|
|
178
|
+
if (!userRef)
|
|
179
|
+
return;
|
|
180
|
+
userDocUnsubscribe = userRef.onSnapshot(
|
|
181
|
+
(snapshot, change) => {
|
|
182
|
+
if (change === "insert" || change === "update") {
|
|
183
|
+
if (snapshot.data.logged === "false" || snapshot.data.logged === false) {
|
|
184
|
+
this.eUser = void 0;
|
|
185
|
+
this.saveCredentials(null);
|
|
186
|
+
onSignOut?.();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const result = Credentials.fromMap(snapshot.toMap());
|
|
190
|
+
this.eUser = result;
|
|
191
|
+
this.saveCredentials(result);
|
|
192
|
+
onChange(result);
|
|
193
|
+
}
|
|
194
|
+
if (change === "delete") {
|
|
195
|
+
this.eUser = void 0;
|
|
196
|
+
this.saveCredentials(null);
|
|
197
|
+
onSignOut?.();
|
|
198
|
+
onDeleted?.();
|
|
199
|
+
}
|
|
172
200
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
const current = this.currentUser();
|
|
204
|
+
if (current) {
|
|
205
|
+
this.eUser = current;
|
|
206
|
+
onChange(current);
|
|
207
|
+
attachUserListener(current);
|
|
208
|
+
}
|
|
209
|
+
const unsubscribeCredentials = onValue(
|
|
210
|
+
"credentials",
|
|
211
|
+
(creds) => {
|
|
212
|
+
attachUserListener(creds);
|
|
185
213
|
}
|
|
186
|
-
|
|
214
|
+
);
|
|
215
|
+
return () => {
|
|
216
|
+
unsubscribeCredentials?.();
|
|
217
|
+
userDocUnsubscribe?.();
|
|
218
|
+
};
|
|
187
219
|
};
|
|
188
220
|
this.createUserWithEmailAndPassword = async ({
|
|
189
221
|
email,
|
|
@@ -268,7 +300,7 @@ var Authentication = class {
|
|
|
268
300
|
});
|
|
269
301
|
return;
|
|
270
302
|
};
|
|
271
|
-
this.rules = async (path,
|
|
303
|
+
this.rules = async (path, context) => {
|
|
272
304
|
const res = await new HttpsRequest({
|
|
273
305
|
method: "POST" /* POST */,
|
|
274
306
|
endpoint: this.client.getBaseUrl + "/auth/rules/verify",
|
|
@@ -277,9 +309,7 @@ var Authentication = class {
|
|
|
277
309
|
},
|
|
278
310
|
body: {
|
|
279
311
|
path,
|
|
280
|
-
|
|
281
|
-
context,
|
|
282
|
-
hello: "world"
|
|
312
|
+
context
|
|
283
313
|
}
|
|
284
314
|
}).sendRequest();
|
|
285
315
|
return res;
|