@unicitylabs/sphere-sdk 0.4.9 → 0.5.1

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.
Files changed (43) hide show
  1. package/dist/connect/index.cjs +3 -1
  2. package/dist/connect/index.cjs.map +1 -1
  3. package/dist/connect/index.js +3 -1
  4. package/dist/connect/index.js.map +1 -1
  5. package/dist/core/index.cjs +384 -119
  6. package/dist/core/index.cjs.map +1 -1
  7. package/dist/core/index.d.cts +244 -194
  8. package/dist/core/index.d.ts +244 -194
  9. package/dist/core/index.js +384 -119
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/impl/browser/connect/index.cjs +3 -1
  12. package/dist/impl/browser/connect/index.cjs.map +1 -1
  13. package/dist/impl/browser/connect/index.js +3 -1
  14. package/dist/impl/browser/connect/index.js.map +1 -1
  15. package/dist/impl/browser/index.cjs +67 -3
  16. package/dist/impl/browser/index.cjs.map +1 -1
  17. package/dist/impl/browser/index.js +67 -3
  18. package/dist/impl/browser/index.js.map +1 -1
  19. package/dist/impl/browser/ipfs.cjs +3 -1
  20. package/dist/impl/browser/ipfs.cjs.map +1 -1
  21. package/dist/impl/browser/ipfs.js +3 -1
  22. package/dist/impl/browser/ipfs.js.map +1 -1
  23. package/dist/impl/nodejs/connect/index.cjs +3 -1
  24. package/dist/impl/nodejs/connect/index.cjs.map +1 -1
  25. package/dist/impl/nodejs/connect/index.js +3 -1
  26. package/dist/impl/nodejs/connect/index.js.map +1 -1
  27. package/dist/impl/nodejs/index.cjs +64 -5
  28. package/dist/impl/nodejs/index.cjs.map +1 -1
  29. package/dist/impl/nodejs/index.d.cts +668 -628
  30. package/dist/impl/nodejs/index.d.ts +668 -628
  31. package/dist/impl/nodejs/index.js +64 -5
  32. package/dist/impl/nodejs/index.js.map +1 -1
  33. package/dist/index.cjs +384 -119
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +248 -194
  36. package/dist/index.d.ts +248 -194
  37. package/dist/index.js +384 -119
  38. package/dist/index.js.map +1 -1
  39. package/dist/l1/index.cjs +3 -1
  40. package/dist/l1/index.cjs.map +1 -1
  41. package/dist/l1/index.js +3 -1
  42. package/dist/l1/index.js.map +1 -1
  43. package/package.json +1 -1
@@ -58,7 +58,9 @@ var STORAGE_KEYS_ADDRESS = {
58
58
  /** Group chat: members for this address */
59
59
  GROUP_CHAT_MEMBERS: "group_chat_members",
60
60
  /** Group chat: processed event IDs for deduplication */
61
- GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events"
61
+ GROUP_CHAT_PROCESSED_EVENTS: "group_chat_processed_events",
62
+ /** Processed V5 split group IDs for Nostr re-delivery dedup */
63
+ PROCESSED_SPLIT_GROUP_IDS: "processed_split_group_ids"
62
64
  };
63
65
  var STORAGE_KEYS = {
64
66
  ...STORAGE_KEYS_GLOBAL,
@@ -649,9 +651,10 @@ function createIndexedDBStorageProvider(config) {
649
651
 
650
652
  // impl/browser/storage/IndexedDBTokenStorageProvider.ts
651
653
  var DB_NAME2 = "sphere-token-storage";
652
- var DB_VERSION2 = 1;
654
+ var DB_VERSION2 = 2;
653
655
  var STORE_TOKENS = "tokens";
654
656
  var STORE_META = "meta";
657
+ var STORE_HISTORY = "history";
655
658
  var connectionSeq2 = 0;
656
659
  var IndexedDBTokenStorageProvider = class {
657
660
  id = "indexeddb-token-storage";
@@ -919,6 +922,9 @@ var IndexedDBTokenStorageProvider = class {
919
922
  if (!db.objectStoreNames.contains(STORE_META)) {
920
923
  db.createObjectStore(STORE_META);
921
924
  }
925
+ if (!db.objectStoreNames.contains(STORE_HISTORY)) {
926
+ db.createObjectStore(STORE_HISTORY, { keyPath: "dedupKey" });
927
+ }
922
928
  };
923
929
  });
924
930
  }
@@ -992,6 +998,61 @@ var IndexedDBTokenStorageProvider = class {
992
998
  return [];
993
999
  }
994
1000
  }
1001
+ // =========================================================================
1002
+ // Public: History operations
1003
+ // =========================================================================
1004
+ /**
1005
+ * Add a history entry. Uses `put` (upsert by dedupKey) so duplicate
1006
+ * calls with the same dedupKey simply overwrite — no duplicates.
1007
+ */
1008
+ async addHistoryEntry(entry) {
1009
+ await this.putToStore(STORE_HISTORY, entry.dedupKey, entry);
1010
+ }
1011
+ /**
1012
+ * Get all history entries sorted by timestamp descending.
1013
+ */
1014
+ async getHistoryEntries() {
1015
+ const entries = await this.getAllFromStore(STORE_HISTORY);
1016
+ return entries.sort((a, b) => b.timestamp - a.timestamp);
1017
+ }
1018
+ /**
1019
+ * Check if a history entry with the given dedupKey exists.
1020
+ */
1021
+ async hasHistoryEntry(dedupKey) {
1022
+ const entry = await this.getFromStore(STORE_HISTORY, dedupKey);
1023
+ return entry !== null;
1024
+ }
1025
+ /**
1026
+ * Clear all history entries.
1027
+ */
1028
+ async clearHistory() {
1029
+ if (!this.db) return;
1030
+ await new Promise((resolve, reject) => {
1031
+ const tx = this.db.transaction(STORE_HISTORY, "readwrite");
1032
+ const req = tx.objectStore(STORE_HISTORY).clear();
1033
+ req.onerror = () => reject(req.error);
1034
+ req.onsuccess = () => resolve();
1035
+ });
1036
+ }
1037
+ /**
1038
+ * Bulk import history entries. Entries with existing dedupKeys are
1039
+ * skipped (first-write-wins). Returns the number of newly imported entries.
1040
+ */
1041
+ async importHistoryEntries(entries) {
1042
+ if (!this.db || entries.length === 0) return 0;
1043
+ let imported = 0;
1044
+ for (const entry of entries) {
1045
+ const exists = await this.hasHistoryEntry(entry.dedupKey);
1046
+ if (!exists) {
1047
+ await this.addHistoryEntry(entry);
1048
+ imported++;
1049
+ }
1050
+ }
1051
+ return imported;
1052
+ }
1053
+ // =========================================================================
1054
+ // Private IndexedDB helpers (clear)
1055
+ // =========================================================================
995
1056
  /**
996
1057
  * Clear all object stores in a single database.
997
1058
  * Opens a temporary connection, clears STORE_TOKENS and STORE_META, then closes.
@@ -1018,6 +1079,9 @@ var IndexedDBTokenStorageProvider = class {
1018
1079
  if (!db2.objectStoreNames.contains(STORE_META)) {
1019
1080
  db2.createObjectStore(STORE_META);
1020
1081
  }
1082
+ if (!db2.objectStoreNames.contains(STORE_HISTORY)) {
1083
+ db2.createObjectStore(STORE_HISTORY, { keyPath: "dedupKey" });
1084
+ }
1021
1085
  };
1022
1086
  }),
1023
1087
  new Promise(
@@ -1025,7 +1089,7 @@ var IndexedDBTokenStorageProvider = class {
1025
1089
  )
1026
1090
  ]);
1027
1091
  try {
1028
- for (const storeName of [STORE_TOKENS, STORE_META]) {
1092
+ for (const storeName of [STORE_TOKENS, STORE_META, STORE_HISTORY]) {
1029
1093
  if (db.objectStoreNames.contains(storeName)) {
1030
1094
  await new Promise((resolve, reject) => {
1031
1095
  const tx = db.transaction(storeName, "readwrite");