shogun-core 3.3.6 → 3.3.7
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 +51 -21
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/core.js +2 -2
- package/dist/gundb/db.js +44 -15
- package/dist/managers/AuthManager.js +4 -3
- package/dist/managers/CoreInitializer.js +1 -1
- package/dist/types/core.d.ts +1 -1
- package/dist/types/gundb/db.d.ts +15 -6
- package/dist/types/interfaces/events.d.ts +1 -1
- package/dist/types/interfaces/shogun.d.ts +7 -1
- package/dist/types/managers/AuthManager.d.ts +1 -1
- package/package.json +1 -1
- package/dist/types/events.js +0 -70
- package/dist/types/shogun.js +0 -21
- package/dist/types/types/events.d.ts +0 -59
- package/dist/types/types/shogun.d.ts +0 -188
|
@@ -99502,8 +99502,8 @@ class ShogunCore {
|
|
|
99502
99502
|
* @description Authenticates user using a GunDB pair directly.
|
|
99503
99503
|
* Emits login event on success.
|
|
99504
99504
|
*/
|
|
99505
|
-
async loginWithPair(pair) {
|
|
99506
|
-
return this.authManager.loginWithPair(pair);
|
|
99505
|
+
async loginWithPair(username, pair) {
|
|
99506
|
+
return this.authManager.loginWithPair(username, pair);
|
|
99507
99507
|
}
|
|
99508
99508
|
/**
|
|
99509
99509
|
* Register a new user with provided credentials
|
|
@@ -100767,16 +100767,11 @@ const CONFIG = {
|
|
|
100767
100767
|
},
|
|
100768
100768
|
};
|
|
100769
100769
|
class DataBase {
|
|
100770
|
-
constructor(gun, appScope = "shogun"
|
|
100770
|
+
constructor(gun, appScope = "shogun") {
|
|
100771
100771
|
this.user = null;
|
|
100772
100772
|
this.onAuthCallbacks = [];
|
|
100773
|
-
this.disableAutoRecall = false;
|
|
100774
|
-
this.silent = false;
|
|
100775
100773
|
// Initialize event emitter
|
|
100776
100774
|
this.eventEmitter = new eventEmitter_1.EventEmitter();
|
|
100777
|
-
// Set options
|
|
100778
|
-
this.disableAutoRecall = options?.disableAutoRecall || false;
|
|
100779
|
-
this.silent = options?.silent || false;
|
|
100780
100775
|
// Validate Gun instance
|
|
100781
100776
|
if (!gun) {
|
|
100782
100777
|
throw new Error("Gun instance is required but was not provided");
|
|
@@ -100795,14 +100790,7 @@ class DataBase {
|
|
|
100795
100790
|
}
|
|
100796
100791
|
this.gun = gun;
|
|
100797
100792
|
// Recall only if NOT disabled and there's a "pair" in sessionStorage
|
|
100798
|
-
|
|
100799
|
-
typeof sessionStorage !== "undefined" &&
|
|
100800
|
-
sessionStorage.getItem("pair")) {
|
|
100801
|
-
this.user = this.gun.user().recall({ sessionStorage: true });
|
|
100802
|
-
}
|
|
100803
|
-
else {
|
|
100804
|
-
this.user = this.gun.user();
|
|
100805
|
-
}
|
|
100793
|
+
this.user = this.gun.user().recall({ sessionStorage: true });
|
|
100806
100794
|
this.subscribeToAuthEvents();
|
|
100807
100795
|
this.crypto = crypto;
|
|
100808
100796
|
this.sea = sea_1.default;
|
|
@@ -102098,6 +102086,13 @@ class DataBase {
|
|
|
102098
102086
|
: undefined,
|
|
102099
102087
|
};
|
|
102100
102088
|
}
|
|
102089
|
+
/**
|
|
102090
|
+
* Performs login with username and password
|
|
102091
|
+
* @param username Username
|
|
102092
|
+
* @param password Password
|
|
102093
|
+
* @param pair SEA pair (optional)
|
|
102094
|
+
* @returns Promise resolving to AuthResult object
|
|
102095
|
+
*/
|
|
102101
102096
|
async login(username, password, pair) {
|
|
102102
102097
|
try {
|
|
102103
102098
|
const loginResult = await this.performAuthentication(username, password, pair);
|
|
@@ -102111,6 +102106,7 @@ class DataBase {
|
|
|
102111
102106
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
102112
102107
|
const userPub = this.gun.user().is?.pub;
|
|
102113
102108
|
let alias = this.gun.user().is?.alias;
|
|
102109
|
+
let userPair = this.gun.user()?._?.sea;
|
|
102114
102110
|
if (!alias) {
|
|
102115
102111
|
alias = username;
|
|
102116
102112
|
}
|
|
@@ -102143,7 +102139,7 @@ class DataBase {
|
|
|
102143
102139
|
try {
|
|
102144
102140
|
const userInfo = {
|
|
102145
102141
|
alias: username,
|
|
102146
|
-
pair: pair ??
|
|
102142
|
+
pair: pair ?? userPair,
|
|
102147
102143
|
userPub: userPub,
|
|
102148
102144
|
};
|
|
102149
102145
|
this.saveCredentials(userInfo);
|
|
@@ -102158,6 +102154,39 @@ class DataBase {
|
|
|
102158
102154
|
return { success: false, error: String(error) };
|
|
102159
102155
|
}
|
|
102160
102156
|
}
|
|
102157
|
+
/**
|
|
102158
|
+
* Performs login with GunDB pair directly
|
|
102159
|
+
* @param username Username
|
|
102160
|
+
* @param pair SEA pair
|
|
102161
|
+
* @returns Promise resolving to AuthResult object
|
|
102162
|
+
*/
|
|
102163
|
+
async loginWithPair(username, pair) {
|
|
102164
|
+
try {
|
|
102165
|
+
const loginResult = await this.performAuthentication(username, "", pair);
|
|
102166
|
+
if (!loginResult.success) {
|
|
102167
|
+
return {
|
|
102168
|
+
success: false,
|
|
102169
|
+
error: `User '${username}' not found. Please check your username or register first.`,
|
|
102170
|
+
};
|
|
102171
|
+
}
|
|
102172
|
+
await this.runPostAuthOnAuthResult(username, pair.pub || "", {
|
|
102173
|
+
success: true,
|
|
102174
|
+
userPub: pair.pub,
|
|
102175
|
+
});
|
|
102176
|
+
try {
|
|
102177
|
+
await this.updateUserLastSeen(pair.pub);
|
|
102178
|
+
}
|
|
102179
|
+
catch (lastSeenError) {
|
|
102180
|
+
console.error(`Error updating last seen: ${lastSeenError}`);
|
|
102181
|
+
// Continue with login even if last seen update fails
|
|
102182
|
+
}
|
|
102183
|
+
return this.buildLoginResult(username, this.gun.user().is?.pub || "");
|
|
102184
|
+
}
|
|
102185
|
+
catch (error) {
|
|
102186
|
+
console.error(`Exception during login with pair: ${error}`);
|
|
102187
|
+
return { success: false, error: String(error) };
|
|
102188
|
+
}
|
|
102189
|
+
}
|
|
102161
102190
|
saveCredentials(userInfo) {
|
|
102162
102191
|
try {
|
|
102163
102192
|
const sessionInfo = {
|
|
@@ -103585,7 +103614,7 @@ class AuthManager {
|
|
|
103585
103614
|
* @description Authenticates user using a GunDB pair directly.
|
|
103586
103615
|
* Emits login event on success.
|
|
103587
103616
|
*/
|
|
103588
|
-
async loginWithPair(pair) {
|
|
103617
|
+
async loginWithPair(username, pair) {
|
|
103589
103618
|
try {
|
|
103590
103619
|
if (!pair || !pair.pub || !pair.priv || !pair.epub || !pair.epriv) {
|
|
103591
103620
|
return {
|
|
@@ -103594,7 +103623,7 @@ class AuthManager {
|
|
|
103594
103623
|
};
|
|
103595
103624
|
}
|
|
103596
103625
|
// Use the new loginWithPair method from GunInstance
|
|
103597
|
-
const result = await this.core.db.
|
|
103626
|
+
const result = await this.core.db.loginWithPair(username, pair);
|
|
103598
103627
|
if (result.success) {
|
|
103599
103628
|
// Include SEA pair in the response
|
|
103600
103629
|
const seaPair = this.core.user?._?.sea;
|
|
@@ -103604,7 +103633,8 @@ class AuthManager {
|
|
|
103604
103633
|
this.currentAuthMethod = "pair";
|
|
103605
103634
|
this.core.emit("auth:login", {
|
|
103606
103635
|
userPub: result.userPub ?? "",
|
|
103607
|
-
method: "
|
|
103636
|
+
method: "pair",
|
|
103637
|
+
username,
|
|
103608
103638
|
});
|
|
103609
103639
|
}
|
|
103610
103640
|
else {
|
|
@@ -103838,7 +103868,7 @@ class CoreInitializer {
|
|
|
103838
103868
|
throw new Error(`Failed to create Gun instance: ${error}`);
|
|
103839
103869
|
}
|
|
103840
103870
|
try {
|
|
103841
|
-
this.core.db = new gundb_1.DataBase(this.core._gun, config.gunOptions?.scope || ""
|
|
103871
|
+
this.core.db = new gundb_1.DataBase(this.core._gun, config.gunOptions?.scope || "");
|
|
103842
103872
|
// Note: user is a getter that returns _user, so we don't need to assign it
|
|
103843
103873
|
}
|
|
103844
103874
|
catch (error) {
|