shogun-core 4.2.2 → 4.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.
@@ -134142,7 +134142,16 @@ class DataBase {
134142
134142
  */
134143
134143
  async put(path, data) {
134144
134144
  const node = this.navigateToPath(this.node, path);
134145
- return await node.put(data).then();
134145
+ return new Promise((resolve, reject) => {
134146
+ node.put(data, (ack) => {
134147
+ if (ack && ack.err) {
134148
+ reject(new Error(ack.err));
134149
+ }
134150
+ else {
134151
+ resolve(ack);
134152
+ }
134153
+ });
134154
+ });
134146
134155
  }
134147
134156
  /**
134148
134157
  * Sets data at the specified path
@@ -134152,7 +134161,16 @@ class DataBase {
134152
134161
  */
134153
134162
  async set(path, data) {
134154
134163
  const node = this.navigateToPath(this.node, path);
134155
- return await node.set(data).then();
134164
+ return new Promise((resolve, reject) => {
134165
+ node.set(data, (ack) => {
134166
+ if (ack && ack.err) {
134167
+ reject(new Error(ack.err));
134168
+ }
134169
+ else {
134170
+ resolve(ack);
134171
+ }
134172
+ });
134173
+ });
134156
134174
  }
134157
134175
  /**
134158
134176
  * Removes data at the specified path
@@ -134161,7 +134179,16 @@ class DataBase {
134161
134179
  */
134162
134180
  async remove(path) {
134163
134181
  const node = this.navigateToPath(this.node, path);
134164
- return await node.put(null).then();
134182
+ return new Promise((resolve, reject) => {
134183
+ node.put(null, (ack) => {
134184
+ if (ack && ack.err) {
134185
+ reject(new Error(ack.err));
134186
+ }
134187
+ else {
134188
+ resolve(ack);
134189
+ }
134190
+ });
134191
+ });
134165
134192
  }
134166
134193
  /**
134167
134194
  * Checks if a user is currently logged in
@@ -134692,7 +134719,11 @@ class DataBase {
134692
134719
  if (normalizedUsername.length === 0) {
134693
134720
  throw new Error("Username cannot be empty");
134694
134721
  }
134695
- const existingUser = await this.gun.get(userPub).then();
134722
+ const existingUser = await new Promise((resolve) => {
134723
+ this.gun.get(userPub).once((data) => {
134724
+ resolve(data);
134725
+ });
134726
+ });
134696
134727
  const isNewUser = !existingUser || !existingUser.alias;
134697
134728
  // const isNewUser = true;
134698
134729
  // Get user's encryption public key (epub) for comprehensive tracking
@@ -134864,18 +134895,20 @@ class DataBase {
134864
134895
  */
134865
134896
  async createReverseLookup(username, userPub) {
134866
134897
  try {
134867
- const ack = await this.node
134868
- .get("userAliases")
134869
- .get(userPub)
134870
- .put(username)
134871
- .then();
134872
- if (ack.err) {
134873
- console.error(`Error creating reverse lookup: ${ack.err}`);
134874
- return false;
134875
- }
134876
- else {
134877
- return true;
134878
- }
134898
+ return new Promise((resolve) => {
134899
+ this.node
134900
+ .get("userAliases")
134901
+ .get(userPub)
134902
+ .put(username, (ack) => {
134903
+ if (ack && ack.err) {
134904
+ console.error(`Error creating reverse lookup: ${ack.err}`);
134905
+ resolve(false);
134906
+ }
134907
+ else {
134908
+ resolve(true);
134909
+ }
134910
+ });
134911
+ });
134879
134912
  }
134880
134913
  catch (error) {
134881
134914
  console.error(`Error creating reverse lookup: ${error}`);
@@ -134948,9 +134981,14 @@ class DataBase {
134948
134981
  }
134949
134982
  // Method 1: Try GunDB standard alias lookup (~@alias)
134950
134983
  try {
134951
- const aliasData = await this.gun.get(`~@${normalizedAlias}`).then();
134952
- if (aliasData && aliasData["~pubKeyOfUser"]) {
134953
- const userPub = aliasData["~pubKeyOfUser"]["#"] || aliasData["~pubKeyOfUser"];
134984
+ const aliasData = this.gun.get(`~@${normalizedAlias}`);
134985
+ const aliasDataObj = await new Promise((resolve) => {
134986
+ aliasData.once((data) => {
134987
+ resolve(data);
134988
+ });
134989
+ });
134990
+ if (aliasDataObj && aliasDataObj["~pubKeyOfUser"]) {
134991
+ const userPub = aliasDataObj["~pubKeyOfUser"]["#"] || aliasDataObj["~pubKeyOfUser"];
134954
134992
  if (userPub) {
134955
134993
  const userData = await this.getUserDataByPub(userPub);
134956
134994
  if (userData) {
@@ -134964,10 +135002,14 @@ class DataBase {
134964
135002
  }
134965
135003
  // Method 2: Try username mapping (usernames/alias -> userPub)
134966
135004
  try {
134967
- const userPub = await this.node
134968
- .get("usernames")
134969
- .get(normalizedAlias)
134970
- .then();
135005
+ const userPub = await new Promise((resolve) => {
135006
+ this.node
135007
+ .get("usernames")
135008
+ .get(normalizedAlias)
135009
+ .once((data) => {
135010
+ resolve(data);
135011
+ });
135012
+ });
134971
135013
  if (userPub) {
134972
135014
  const userData = await this.getUserDataByPub(userPub);
134973
135015
  if (userData) {
@@ -134997,7 +135039,14 @@ class DataBase {
134997
135039
  }
134998
135040
  // Method 1: Try user registry (users/userPub -> user data)
134999
135041
  try {
135000
- const userData = await this.node.get("users").get(userPub).then();
135042
+ const userData = await new Promise((resolve) => {
135043
+ this.node
135044
+ .get("users")
135045
+ .get(userPub)
135046
+ .once((data) => {
135047
+ resolve(data);
135048
+ });
135049
+ });
135001
135050
  if (userData && userData.username) {
135002
135051
  return {
135003
135052
  userPub: userData.userPub || userPub,
@@ -135013,7 +135062,11 @@ class DataBase {
135013
135062
  }
135014
135063
  // Method 2: Try user's own node
135015
135064
  try {
135016
- const userNodeData = await this.gun.get(userPub).then();
135065
+ const userNodeData = await new Promise((resolve) => {
135066
+ this.gun.get(userPub).once((data) => {
135067
+ resolve(data);
135068
+ });
135069
+ });
135017
135070
  if (userNodeData && userNodeData.username) {
135018
135071
  return {
135019
135072
  userPub: userPub,
@@ -135044,7 +135097,14 @@ class DataBase {
135044
135097
  if (!epub || typeof epub !== "string") {
135045
135098
  return null;
135046
135099
  }
135047
- const userPub = await this.node.get("epubKeys").get(epub).then();
135100
+ const userPub = await new Promise((resolve) => {
135101
+ this.node
135102
+ .get("epubKeys")
135103
+ .get(epub)
135104
+ .once((data) => {
135105
+ resolve(data);
135106
+ });
135107
+ });
135048
135108
  return userPub || null;
135049
135109
  }
135050
135110
  catch (error) {
@@ -135062,7 +135122,14 @@ class DataBase {
135062
135122
  if (!userPub || typeof userPub !== "string") {
135063
135123
  return null;
135064
135124
  }
135065
- const alias = await this.node.get("userAliases").get(userPub).then();
135125
+ const alias = await new Promise((resolve) => {
135126
+ this.node
135127
+ .get("userAliases")
135128
+ .get(userPub)
135129
+ .once((data) => {
135130
+ resolve(data);
135131
+ });
135132
+ });
135066
135133
  return alias || null;
135067
135134
  }
135068
135135
  catch (error) {
@@ -135101,19 +135168,39 @@ class DataBase {
135101
135168
  const timestamp = Date.now();
135102
135169
  // Update in user registry
135103
135170
  try {
135104
- await this.node
135105
- .get("users")
135106
- .get(userPub)
135107
- .get("lastSeen")
135108
- .put(timestamp)
135109
- .then();
135171
+ await new Promise((resolve, reject) => {
135172
+ this.node
135173
+ .get("users")
135174
+ .get(userPub)
135175
+ .get("lastSeen")
135176
+ .put(timestamp, (ack) => {
135177
+ if (ack && ack.err) {
135178
+ reject(new Error(ack.err));
135179
+ }
135180
+ else {
135181
+ resolve();
135182
+ }
135183
+ });
135184
+ });
135110
135185
  }
135111
135186
  catch (error) {
135112
135187
  console.error(`Failed to update lastSeen in user registry:`, error);
135113
135188
  }
135114
135189
  // Update in user's own node
135115
135190
  try {
135116
- await this.gun.get(userPub).get("lastSeen").put(timestamp).then();
135191
+ await new Promise((resolve, reject) => {
135192
+ this.gun
135193
+ .get(userPub)
135194
+ .get("lastSeen")
135195
+ .put(timestamp, (ack) => {
135196
+ if (ack && ack.err) {
135197
+ reject(new Error(ack.err));
135198
+ }
135199
+ else {
135200
+ resolve();
135201
+ }
135202
+ });
135203
+ });
135117
135204
  }
135118
135205
  catch (error) {
135119
135206
  console.error(`Failed to update lastSeen in user node:`, error);
@@ -135364,10 +135451,19 @@ class DataBase {
135364
135451
  questions: JSON.stringify(securityQuestions),
135365
135452
  hint: encryptedHint,
135366
135453
  };
135367
- const ack = await this.node.get(userPub)
135368
- .get("security")
135369
- .put(securityPayload)
135370
- .then();
135454
+ const ack = await new Promise((resolve, reject) => {
135455
+ this.node
135456
+ .get(userPub)
135457
+ .get("security")
135458
+ .put(securityPayload, (ack) => {
135459
+ if (ack && ack.err) {
135460
+ reject(new Error(ack.err));
135461
+ }
135462
+ else {
135463
+ resolve(ack);
135464
+ }
135465
+ });
135466
+ });
135371
135467
  if (ack.err) {
135372
135468
  console.error("Error saving security data to public graph:", ack.err);
135373
135469
  throw new Error(ack.err);
@@ -135390,15 +135486,26 @@ class DataBase {
135390
135486
  try {
135391
135487
  // Find the user's data using direct lookup
135392
135488
  const normalizedUsername = username.trim().toLowerCase();
135393
- const userPub = (await this.node.get("usernames").get(normalizedUsername).then()) ||
135394
- null;
135489
+ const userPub = await new Promise((resolve) => {
135490
+ this.node
135491
+ .get("usernames")
135492
+ .get(normalizedUsername)
135493
+ .once((data) => {
135494
+ resolve(data);
135495
+ });
135496
+ });
135395
135497
  if (!userPub) {
135396
135498
  return { success: false, error: "User not found" };
135397
135499
  }
135398
135500
  // Access the user's security data directly from their public key node
135399
- const securityData = await this.node.get(userPub)
135400
- .get("security")
135401
- .then();
135501
+ const securityData = await new Promise((resolve) => {
135502
+ this.node
135503
+ .get(userPub)
135504
+ .get("security")
135505
+ .once((data) => {
135506
+ resolve(data);
135507
+ });
135508
+ });
135402
135509
  if (!securityData || !securityData.hint) {
135403
135510
  return {
135404
135511
  success: false,