shogun-core 6.4.2 โ 6.4.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/browser/shogun-core.js +208 -172
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/src/gundb/db.js +208 -172
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/gundb/db.d.ts +4 -67
- package/package.json +1 -1
package/dist/src/gundb/db.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GunDB - Simplified database wrapper for Gun.js
|
|
3
|
-
* Provides only essential signup and login functionality
|
|
4
|
-
* Based on Gun.js User Authentication: https://deepwiki.com/amark/gun/6.1-user-authentication
|
|
5
|
-
*/
|
|
6
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -43,9 +38,6 @@ import { RxJS } from "./rxjs.js";
|
|
|
43
38
|
import { EventEmitter } from "../utils/eventEmitter.js";
|
|
44
39
|
import * as GunErrors from "./errors.js";
|
|
45
40
|
import * as crypto from "./crypto.js";
|
|
46
|
-
/**
|
|
47
|
-
* Configuration constants
|
|
48
|
-
*/
|
|
49
41
|
var CONFIG = {
|
|
50
42
|
PASSWORD: {
|
|
51
43
|
MIN_LENGTH: 8,
|
|
@@ -58,10 +50,7 @@ var DataBase = /** @class */ (function () {
|
|
|
58
50
|
this.user = null;
|
|
59
51
|
this.onAuthCallbacks = [];
|
|
60
52
|
this._isDestroyed = false;
|
|
61
|
-
console.log("[DB] Initializing DataBase");
|
|
62
|
-
// Initialize event emitter
|
|
63
53
|
this.eventEmitter = new EventEmitter();
|
|
64
|
-
// Validate Gun instance
|
|
65
54
|
if (!gun) {
|
|
66
55
|
throw new Error("Gun instance is required but was not provided");
|
|
67
56
|
}
|
|
@@ -69,14 +58,9 @@ var DataBase = /** @class */ (function () {
|
|
|
69
58
|
throw new Error("Gun instance is invalid: gun.user is not a function");
|
|
70
59
|
}
|
|
71
60
|
this.gun = gun;
|
|
72
|
-
console.log("[DB] Gun instance validated");
|
|
73
|
-
// Recall user session if available
|
|
74
61
|
this.user = this.gun.user().recall({ sessionStorage: true });
|
|
75
|
-
console.log("[DB] User recall completed");
|
|
76
62
|
this.subscribeToAuthEvents();
|
|
77
|
-
console.log("[DB] Auth events subscribed");
|
|
78
63
|
this.crypto = crypto;
|
|
79
|
-
// Get SEA from gun instance or global
|
|
80
64
|
this.sea = sea || null;
|
|
81
65
|
if (!this.sea) {
|
|
82
66
|
if (this.gun.SEA) {
|
|
@@ -91,20 +75,13 @@ var DataBase = /** @class */ (function () {
|
|
|
91
75
|
}
|
|
92
76
|
this._rxjs = new RxJS(this.gun);
|
|
93
77
|
this.node = this.gun.get(appScope);
|
|
78
|
+
this.usernamesNode = this.gun.get("usernames");
|
|
94
79
|
console.log("[DB] DataBase initialization completed");
|
|
95
80
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Initialize with app scope
|
|
98
|
-
*/
|
|
99
81
|
DataBase.prototype.initialize = function (appScope) {
|
|
100
82
|
if (appScope === void 0) { appScope = "shogun"; }
|
|
101
|
-
console.log("[DB] Initializing with appScope: ".concat(appScope));
|
|
102
83
|
this.node = this.gun.get(appScope);
|
|
103
|
-
console.log("[DB] App scope node initialized");
|
|
104
84
|
};
|
|
105
|
-
/**
|
|
106
|
-
* Subscribe to Gun auth events
|
|
107
|
-
*/
|
|
108
85
|
DataBase.prototype.subscribeToAuthEvents = function () {
|
|
109
86
|
var _this = this;
|
|
110
87
|
this.gun.on("auth", function (ack) {
|
|
@@ -117,16 +94,10 @@ var DataBase = /** @class */ (function () {
|
|
|
117
94
|
}
|
|
118
95
|
});
|
|
119
96
|
};
|
|
120
|
-
/**
|
|
121
|
-
* Notify all auth callbacks
|
|
122
|
-
*/
|
|
123
97
|
DataBase.prototype.notifyAuthListeners = function (pub) {
|
|
124
98
|
var user = this.gun.user();
|
|
125
99
|
this.onAuthCallbacks.forEach(function (cb) { return cb(user); });
|
|
126
100
|
};
|
|
127
|
-
/**
|
|
128
|
-
* Register authentication callback
|
|
129
|
-
*/
|
|
130
101
|
DataBase.prototype.onAuth = function (callback) {
|
|
131
102
|
var _this = this;
|
|
132
103
|
this.onAuthCallbacks.push(callback);
|
|
@@ -139,9 +110,6 @@ var DataBase = /** @class */ (function () {
|
|
|
139
110
|
_this.onAuthCallbacks.splice(i, 1);
|
|
140
111
|
};
|
|
141
112
|
};
|
|
142
|
-
/**
|
|
143
|
-
* Check if user is logged in
|
|
144
|
-
*/
|
|
145
113
|
DataBase.prototype.isLoggedIn = function () {
|
|
146
114
|
try {
|
|
147
115
|
var user = this.gun.user();
|
|
@@ -151,9 +119,6 @@ var DataBase = /** @class */ (function () {
|
|
|
151
119
|
return false;
|
|
152
120
|
}
|
|
153
121
|
};
|
|
154
|
-
/**
|
|
155
|
-
* Restore session from storage
|
|
156
|
-
*/
|
|
157
122
|
DataBase.prototype.restoreSession = function () {
|
|
158
123
|
try {
|
|
159
124
|
if (typeof sessionStorage === "undefined") {
|
|
@@ -184,9 +149,6 @@ var DataBase = /** @class */ (function () {
|
|
|
184
149
|
return { success: false, error: String(error) };
|
|
185
150
|
}
|
|
186
151
|
};
|
|
187
|
-
/**
|
|
188
|
-
* Logout user
|
|
189
|
-
*/
|
|
190
152
|
DataBase.prototype.logout = function () {
|
|
191
153
|
try {
|
|
192
154
|
var currentUser = this.gun.user();
|
|
@@ -202,9 +164,6 @@ var DataBase = /** @class */ (function () {
|
|
|
202
164
|
console.error("[DB] Error during logout:", error);
|
|
203
165
|
}
|
|
204
166
|
};
|
|
205
|
-
/**
|
|
206
|
-
* Validate password strength
|
|
207
|
-
*/
|
|
208
167
|
DataBase.prototype.validatePasswordStrength = function (password) {
|
|
209
168
|
if (password.length < CONFIG.PASSWORD.MIN_LENGTH) {
|
|
210
169
|
return {
|
|
@@ -214,9 +173,6 @@ var DataBase = /** @class */ (function () {
|
|
|
214
173
|
}
|
|
215
174
|
return { valid: true };
|
|
216
175
|
};
|
|
217
|
-
/**
|
|
218
|
-
* Validate signup credentials
|
|
219
|
-
*/
|
|
220
176
|
DataBase.prototype.validateSignupCredentials = function (username, password, pair) {
|
|
221
177
|
if (!username || username.length < 1) {
|
|
222
178
|
return {
|
|
@@ -238,19 +194,114 @@ var DataBase = /** @class */ (function () {
|
|
|
238
194
|
}
|
|
239
195
|
return this.validatePasswordStrength(password);
|
|
240
196
|
};
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
197
|
+
DataBase.prototype.ensureAliasAvailable = function (alias_1) {
|
|
198
|
+
return __awaiter(this, arguments, void 0, function (alias, timeout) {
|
|
199
|
+
var available;
|
|
200
|
+
if (timeout === void 0) { timeout = 5000; }
|
|
201
|
+
return __generator(this, function (_a) {
|
|
202
|
+
switch (_a.label) {
|
|
203
|
+
case 0: return [4 /*yield*/, this.isAliasAvailable(alias, timeout)];
|
|
204
|
+
case 1:
|
|
205
|
+
available = _a.sent();
|
|
206
|
+
if (!available) {
|
|
207
|
+
throw new Error("Alias \"".concat(alias, "\" is already registered in Gun"));
|
|
208
|
+
}
|
|
209
|
+
return [2 /*return*/];
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
DataBase.prototype.isAliasAvailable = function (alias_1) {
|
|
215
|
+
return __awaiter(this, arguments, void 0, function (alias, timeout) {
|
|
216
|
+
var normalizedAlias;
|
|
217
|
+
var _this = this;
|
|
218
|
+
if (timeout === void 0) { timeout = 5000; }
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
if (typeof alias !== "string" || !alias.trim()) {
|
|
221
|
+
throw new Error("Alias must be a non-empty string");
|
|
222
|
+
}
|
|
223
|
+
normalizedAlias = alias.trim().toLowerCase();
|
|
224
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
225
|
+
var settled = false;
|
|
226
|
+
var timer = setTimeout(function () {
|
|
227
|
+
if (settled)
|
|
228
|
+
return;
|
|
229
|
+
settled = true;
|
|
230
|
+
reject(new Error("Timeout while checking alias availability"));
|
|
231
|
+
}, timeout);
|
|
232
|
+
_this.usernamesNode.get(normalizedAlias).once(function (existingPub) {
|
|
233
|
+
if (settled)
|
|
234
|
+
return;
|
|
235
|
+
settled = true;
|
|
236
|
+
clearTimeout(timer);
|
|
237
|
+
resolve(!existingPub);
|
|
238
|
+
});
|
|
239
|
+
})];
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
DataBase.prototype.registerAlias = function (alias_1, userPub_1) {
|
|
244
|
+
return __awaiter(this, arguments, void 0, function (alias, userPub, timeout) {
|
|
245
|
+
var normalizedAlias, available;
|
|
246
|
+
var _this = this;
|
|
247
|
+
if (timeout === void 0) { timeout = 5000; }
|
|
248
|
+
return __generator(this, function (_a) {
|
|
249
|
+
switch (_a.label) {
|
|
250
|
+
case 0:
|
|
251
|
+
if (!alias || !alias.trim()) {
|
|
252
|
+
throw new Error("Alias must be provided for registration");
|
|
253
|
+
}
|
|
254
|
+
if (!userPub) {
|
|
255
|
+
throw new Error("userPub must be provided for alias registration");
|
|
256
|
+
}
|
|
257
|
+
normalizedAlias = alias.trim().toLowerCase();
|
|
258
|
+
return [4 /*yield*/, this.isAliasAvailable(normalizedAlias, timeout).catch(function (error) {
|
|
259
|
+
console.error("[DB] Alias availability check failed:", error);
|
|
260
|
+
throw error;
|
|
261
|
+
})];
|
|
262
|
+
case 1:
|
|
263
|
+
available = _a.sent();
|
|
264
|
+
if (!available) {
|
|
265
|
+
throw new Error("Alias \"".concat(normalizedAlias, "\" is no longer available for registration"));
|
|
266
|
+
}
|
|
267
|
+
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
268
|
+
var settled = false;
|
|
269
|
+
var timer = setTimeout(function () {
|
|
270
|
+
if (settled)
|
|
271
|
+
return;
|
|
272
|
+
settled = true;
|
|
273
|
+
reject(new Error("Timeout while registering alias"));
|
|
274
|
+
}, timeout);
|
|
275
|
+
_this.usernamesNode.get(normalizedAlias).put(userPub, function (ack) {
|
|
276
|
+
if (settled)
|
|
277
|
+
return;
|
|
278
|
+
settled = true;
|
|
279
|
+
clearTimeout(timer);
|
|
280
|
+
if (ack && ack.err) {
|
|
281
|
+
reject(new Error(String(ack.err)));
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
resolve();
|
|
285
|
+
});
|
|
286
|
+
}).catch(function (error) {
|
|
287
|
+
console.error("[DB] Failed to register alias:", error);
|
|
288
|
+
throw error;
|
|
289
|
+
})];
|
|
290
|
+
case 2:
|
|
291
|
+
_a.sent();
|
|
292
|
+
return [2 /*return*/];
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
};
|
|
244
297
|
DataBase.prototype.resetAuthState = function () {
|
|
245
298
|
try {
|
|
246
299
|
var user = this.gun.user();
|
|
247
300
|
if (user && user._) {
|
|
248
301
|
var cat = user._;
|
|
249
|
-
// Reset Gun's internal auth state
|
|
250
302
|
cat.ing = false;
|
|
251
303
|
cat.auth = null;
|
|
252
304
|
cat.act = null;
|
|
253
|
-
// Clear any pending auth operations
|
|
254
305
|
if (cat.auth) {
|
|
255
306
|
cat.auth = null;
|
|
256
307
|
}
|
|
@@ -267,9 +318,6 @@ var DataBase = /** @class */ (function () {
|
|
|
267
318
|
// Ignore
|
|
268
319
|
}
|
|
269
320
|
};
|
|
270
|
-
/**
|
|
271
|
-
* Build login result
|
|
272
|
-
*/
|
|
273
321
|
DataBase.prototype.buildLoginResult = function (username, userPub) {
|
|
274
322
|
var _a, _b;
|
|
275
323
|
var seaPair = (_b = (_a = this.gun.user()) === null || _a === void 0 ? void 0 : _a._) === null || _b === void 0 ? void 0 : _b.sea;
|
|
@@ -287,9 +335,6 @@ var DataBase = /** @class */ (function () {
|
|
|
287
335
|
: undefined,
|
|
288
336
|
};
|
|
289
337
|
};
|
|
290
|
-
/**
|
|
291
|
-
* Save credentials to session storage
|
|
292
|
-
*/
|
|
293
338
|
DataBase.prototype.saveCredentials = function (userInfo) {
|
|
294
339
|
try {
|
|
295
340
|
if (typeof sessionStorage !== "undefined") {
|
|
@@ -307,13 +352,9 @@ var DataBase = /** @class */ (function () {
|
|
|
307
352
|
console.error("[DB] Error saving credentials:", error);
|
|
308
353
|
}
|
|
309
354
|
};
|
|
310
|
-
/**
|
|
311
|
-
* Sign up a new user
|
|
312
|
-
* Based on Gun.js user().create() - https://deepwiki.com/amark/gun/6.1-user-authentication
|
|
313
|
-
*/
|
|
314
355
|
DataBase.prototype.signUp = function (username, password, pair) {
|
|
315
356
|
return __awaiter(this, void 0, void 0, function () {
|
|
316
|
-
var validation, normalizedUsername, user, loginResult, e_1, result;
|
|
357
|
+
var validation, normalizedUsername, user, loginResult, e_1, aliasError_1, result;
|
|
317
358
|
var _this = this;
|
|
318
359
|
return __generator(this, function (_a) {
|
|
319
360
|
switch (_a.label) {
|
|
@@ -322,7 +363,6 @@ var DataBase = /** @class */ (function () {
|
|
|
322
363
|
if (!validation.valid) {
|
|
323
364
|
return [2 /*return*/, { success: false, error: validation.error }];
|
|
324
365
|
}
|
|
325
|
-
console.log("[DB] Signup validation:", validation);
|
|
326
366
|
this.resetAuthState();
|
|
327
367
|
normalizedUsername = username.trim().toLowerCase();
|
|
328
368
|
user = this.gun.user();
|
|
@@ -339,7 +379,6 @@ var DataBase = /** @class */ (function () {
|
|
|
339
379
|
}
|
|
340
380
|
callbackInvoked = true;
|
|
341
381
|
if (ack.err) {
|
|
342
|
-
// Could not login with pair, try to create user with username/password
|
|
343
382
|
resolve({ success: false, error: ack.err });
|
|
344
383
|
return;
|
|
345
384
|
}
|
|
@@ -362,7 +401,6 @@ var DataBase = /** @class */ (function () {
|
|
|
362
401
|
})];
|
|
363
402
|
case 2:
|
|
364
403
|
loginResult = _a.sent();
|
|
365
|
-
// If we got a successful result, return it
|
|
366
404
|
if (loginResult && loginResult.success) {
|
|
367
405
|
return [2 /*return*/, loginResult];
|
|
368
406
|
}
|
|
@@ -371,101 +409,120 @@ var DataBase = /** @class */ (function () {
|
|
|
371
409
|
e_1 = _a.sent();
|
|
372
410
|
return [3 /*break*/, 4];
|
|
373
411
|
case 4:
|
|
374
|
-
|
|
375
|
-
return [4 /*yield*/,
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
userPub: authenticatedUserPub,
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
catch (saveError) {
|
|
438
|
-
// Ignore save errors
|
|
439
|
-
}
|
|
440
|
-
var sea = (_d = user === null || user === void 0 ? void 0 : user._) === null || _d === void 0 ? void 0 : _d.sea;
|
|
441
|
-
resolve({
|
|
442
|
-
success: true,
|
|
443
|
-
userPub: authenticatedUserPub,
|
|
444
|
-
username: normalizedUsername,
|
|
445
|
-
isNewUser: true,
|
|
446
|
-
sea: sea
|
|
447
|
-
? {
|
|
448
|
-
pub: sea.pub,
|
|
449
|
-
priv: sea.priv,
|
|
450
|
-
epub: sea.epub,
|
|
451
|
-
epriv: sea.epriv,
|
|
412
|
+
_a.trys.push([4, 6, , 7]);
|
|
413
|
+
return [4 /*yield*/, this.ensureAliasAvailable(normalizedUsername)];
|
|
414
|
+
case 5:
|
|
415
|
+
_a.sent();
|
|
416
|
+
return [3 /*break*/, 7];
|
|
417
|
+
case 6:
|
|
418
|
+
aliasError_1 = _a.sent();
|
|
419
|
+
return [2 /*return*/, {
|
|
420
|
+
success: false,
|
|
421
|
+
error: aliasError_1 instanceof Error ? aliasError_1.message : String(aliasError_1),
|
|
422
|
+
}];
|
|
423
|
+
case 7: return [4 /*yield*/, new Promise(function (resolve) {
|
|
424
|
+
var callbackInvoked = false;
|
|
425
|
+
user.create(normalizedUsername, password, function (createAck) {
|
|
426
|
+
if (callbackInvoked) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (createAck.err ||
|
|
430
|
+
(createAck.ok !== undefined && createAck.ok !== 0)) {
|
|
431
|
+
callbackInvoked = true;
|
|
432
|
+
_this.resetAuthState();
|
|
433
|
+
resolve({ success: false, error: createAck.err || "Signup failed" });
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
var userPub = createAck.pub;
|
|
437
|
+
if (!userPub) {
|
|
438
|
+
callbackInvoked = true;
|
|
439
|
+
_this.resetAuthState();
|
|
440
|
+
resolve({
|
|
441
|
+
success: false,
|
|
442
|
+
error: "No userPub available from signup",
|
|
443
|
+
});
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
user.auth(normalizedUsername, password, function (authAck) { return __awaiter(_this, void 0, void 0, function () {
|
|
447
|
+
var authenticatedUserPub, alias, userPair, registerError_1, sea;
|
|
448
|
+
var _a, _b, _c, _d;
|
|
449
|
+
return __generator(this, function (_e) {
|
|
450
|
+
switch (_e.label) {
|
|
451
|
+
case 0:
|
|
452
|
+
if (callbackInvoked) {
|
|
453
|
+
return [2 /*return*/];
|
|
454
|
+
}
|
|
455
|
+
callbackInvoked = true;
|
|
456
|
+
if (authAck.err) {
|
|
457
|
+
this.resetAuthState();
|
|
458
|
+
resolve({
|
|
459
|
+
success: false,
|
|
460
|
+
error: authAck.err || "Authentication after signup failed",
|
|
461
|
+
});
|
|
462
|
+
return [2 /*return*/];
|
|
463
|
+
}
|
|
464
|
+
authenticatedUserPub = (_a = user === null || user === void 0 ? void 0 : user.is) === null || _a === void 0 ? void 0 : _a.pub;
|
|
465
|
+
if (!authenticatedUserPub) {
|
|
466
|
+
this.resetAuthState();
|
|
467
|
+
resolve({
|
|
468
|
+
success: false,
|
|
469
|
+
error: "User not authenticated after signup",
|
|
470
|
+
});
|
|
471
|
+
return [2 /*return*/];
|
|
452
472
|
}
|
|
453
|
-
|
|
454
|
-
|
|
473
|
+
this.user = user;
|
|
474
|
+
alias = (_b = user === null || user === void 0 ? void 0 : user.is) === null || _b === void 0 ? void 0 : _b.alias;
|
|
475
|
+
userPair = (_c = user === null || user === void 0 ? void 0 : user._) === null || _c === void 0 ? void 0 : _c.sea;
|
|
476
|
+
try {
|
|
477
|
+
this.saveCredentials({
|
|
478
|
+
alias: alias || normalizedUsername,
|
|
479
|
+
pair: pair !== null && pair !== void 0 ? pair : userPair,
|
|
480
|
+
userPub: authenticatedUserPub,
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
catch (saveError) {
|
|
484
|
+
// Ignore save errors
|
|
485
|
+
}
|
|
486
|
+
_e.label = 1;
|
|
487
|
+
case 1:
|
|
488
|
+
_e.trys.push([1, 3, , 4]);
|
|
489
|
+
return [4 /*yield*/, this.registerAlias(alias || normalizedUsername, authenticatedUserPub)];
|
|
490
|
+
case 2:
|
|
491
|
+
_e.sent();
|
|
492
|
+
return [3 /*break*/, 4];
|
|
493
|
+
case 3:
|
|
494
|
+
registerError_1 = _e.sent();
|
|
495
|
+
console.error("[DB] Alias registration failed:", registerError_1);
|
|
496
|
+
return [3 /*break*/, 4];
|
|
497
|
+
case 4:
|
|
498
|
+
sea = (_d = user === null || user === void 0 ? void 0 : user._) === null || _d === void 0 ? void 0 : _d.sea;
|
|
499
|
+
resolve({
|
|
500
|
+
success: true,
|
|
501
|
+
userPub: authenticatedUserPub,
|
|
502
|
+
username: normalizedUsername,
|
|
503
|
+
isNewUser: true,
|
|
504
|
+
sea: sea
|
|
505
|
+
? {
|
|
506
|
+
pub: sea.pub,
|
|
507
|
+
priv: sea.priv,
|
|
508
|
+
epub: sea.epub,
|
|
509
|
+
epriv: sea.epriv,
|
|
510
|
+
}
|
|
511
|
+
: undefined,
|
|
512
|
+
});
|
|
513
|
+
return [2 /*return*/];
|
|
514
|
+
}
|
|
455
515
|
});
|
|
456
|
-
});
|
|
457
|
-
})
|
|
458
|
-
|
|
516
|
+
}); });
|
|
517
|
+
});
|
|
518
|
+
})];
|
|
519
|
+
case 8:
|
|
459
520
|
result = _a.sent();
|
|
460
521
|
return [2 /*return*/, result];
|
|
461
522
|
}
|
|
462
523
|
});
|
|
463
524
|
});
|
|
464
525
|
};
|
|
465
|
-
/**
|
|
466
|
-
* Login with username and password
|
|
467
|
-
* Based on Gun.js user().auth() - https://deepwiki.com/amark/gun/6.1-user-authentication
|
|
468
|
-
*/
|
|
469
526
|
DataBase.prototype.login = function (username, password, pair) {
|
|
470
527
|
return __awaiter(this, void 0, void 0, function () {
|
|
471
528
|
var normalizedUsername, user;
|
|
@@ -474,7 +531,6 @@ var DataBase = /** @class */ (function () {
|
|
|
474
531
|
this.resetAuthState();
|
|
475
532
|
normalizedUsername = username.trim().toLowerCase();
|
|
476
533
|
user = this.gun.user();
|
|
477
|
-
console.log("[DB] Login with username:", normalizedUsername);
|
|
478
534
|
return [2 /*return*/, new Promise(function (resolve) {
|
|
479
535
|
if (pair) {
|
|
480
536
|
user.auth(pair, function (ack) {
|
|
@@ -540,9 +596,6 @@ var DataBase = /** @class */ (function () {
|
|
|
540
596
|
});
|
|
541
597
|
});
|
|
542
598
|
};
|
|
543
|
-
/**
|
|
544
|
-
* Get current user
|
|
545
|
-
*/
|
|
546
599
|
DataBase.prototype.getCurrentUser = function () {
|
|
547
600
|
try {
|
|
548
601
|
var user = this.gun.user();
|
|
@@ -628,10 +681,6 @@ var DataBase = /** @class */ (function () {
|
|
|
628
681
|
});
|
|
629
682
|
});
|
|
630
683
|
};
|
|
631
|
-
/**
|
|
632
|
-
* Login with SEA pair
|
|
633
|
-
*/
|
|
634
|
-
// Legacy method - kept for backward compatibility
|
|
635
684
|
DataBase.prototype.loginWithPairLegacy = function (username, pair) {
|
|
636
685
|
return __awaiter(this, void 0, void 0, function () {
|
|
637
686
|
return __generator(this, function (_a) {
|
|
@@ -639,22 +688,15 @@ var DataBase = /** @class */ (function () {
|
|
|
639
688
|
});
|
|
640
689
|
});
|
|
641
690
|
};
|
|
642
|
-
/**
|
|
643
|
-
* Get RxJS module
|
|
644
|
-
*/
|
|
645
691
|
DataBase.prototype.rx = function () {
|
|
646
692
|
return this._rxjs;
|
|
647
693
|
};
|
|
648
|
-
/**
|
|
649
|
-
* Destroy database instance
|
|
650
|
-
*/
|
|
651
694
|
DataBase.prototype.destroy = function () {
|
|
652
695
|
if (this._isDestroyed)
|
|
653
696
|
return;
|
|
654
697
|
console.log("[DB] Destroying DataBase instance...");
|
|
655
698
|
this._isDestroyed = true;
|
|
656
699
|
this.onAuthCallbacks.length = 0;
|
|
657
|
-
// Clear event listeners
|
|
658
700
|
this.eventEmitter.removeAllListeners();
|
|
659
701
|
if (this.user) {
|
|
660
702
|
try {
|
|
@@ -668,18 +710,12 @@ var DataBase = /** @class */ (function () {
|
|
|
668
710
|
this._rxjs = undefined;
|
|
669
711
|
console.log("[DB] DataBase instance destroyed");
|
|
670
712
|
};
|
|
671
|
-
/**
|
|
672
|
-
* Aggressive auth cleanup (kept for compatibility with tests)
|
|
673
|
-
*/
|
|
674
713
|
DataBase.prototype.aggressiveAuthCleanup = function () {
|
|
675
714
|
console.log("๐งน Performing aggressive auth cleanup...");
|
|
676
715
|
this.resetAuthState();
|
|
677
716
|
this.logout();
|
|
678
717
|
console.log("โ Aggressive auth cleanup completed");
|
|
679
718
|
};
|
|
680
|
-
/**
|
|
681
|
-
* Event emitter methods for CoreInitializer compatibility
|
|
682
|
-
*/
|
|
683
719
|
DataBase.prototype.on = function (event, listener) {
|
|
684
720
|
this.eventEmitter.on(event, listener);
|
|
685
721
|
};
|