@unicitylabs/sphere-sdk 0.4.8 → 0.5.0

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.
@@ -709,9 +709,10 @@ function createIndexedDBStorageProvider(config) {
709
709
 
710
710
  // impl/browser/storage/IndexedDBTokenStorageProvider.ts
711
711
  var DB_NAME2 = "sphere-token-storage";
712
- var DB_VERSION2 = 1;
712
+ var DB_VERSION2 = 2;
713
713
  var STORE_TOKENS = "tokens";
714
714
  var STORE_META = "meta";
715
+ var STORE_HISTORY = "history";
715
716
  var connectionSeq2 = 0;
716
717
  var IndexedDBTokenStorageProvider = class {
717
718
  id = "indexeddb-token-storage";
@@ -979,6 +980,9 @@ var IndexedDBTokenStorageProvider = class {
979
980
  if (!db.objectStoreNames.contains(STORE_META)) {
980
981
  db.createObjectStore(STORE_META);
981
982
  }
983
+ if (!db.objectStoreNames.contains(STORE_HISTORY)) {
984
+ db.createObjectStore(STORE_HISTORY, { keyPath: "dedupKey" });
985
+ }
982
986
  };
983
987
  });
984
988
  }
@@ -1052,6 +1056,61 @@ var IndexedDBTokenStorageProvider = class {
1052
1056
  return [];
1053
1057
  }
1054
1058
  }
1059
+ // =========================================================================
1060
+ // Public: History operations
1061
+ // =========================================================================
1062
+ /**
1063
+ * Add a history entry. Uses `put` (upsert by dedupKey) so duplicate
1064
+ * calls with the same dedupKey simply overwrite — no duplicates.
1065
+ */
1066
+ async addHistoryEntry(entry) {
1067
+ await this.putToStore(STORE_HISTORY, entry.dedupKey, entry);
1068
+ }
1069
+ /**
1070
+ * Get all history entries sorted by timestamp descending.
1071
+ */
1072
+ async getHistoryEntries() {
1073
+ const entries = await this.getAllFromStore(STORE_HISTORY);
1074
+ return entries.sort((a, b) => b.timestamp - a.timestamp);
1075
+ }
1076
+ /**
1077
+ * Check if a history entry with the given dedupKey exists.
1078
+ */
1079
+ async hasHistoryEntry(dedupKey) {
1080
+ const entry = await this.getFromStore(STORE_HISTORY, dedupKey);
1081
+ return entry !== null;
1082
+ }
1083
+ /**
1084
+ * Clear all history entries.
1085
+ */
1086
+ async clearHistory() {
1087
+ if (!this.db) return;
1088
+ await new Promise((resolve, reject) => {
1089
+ const tx = this.db.transaction(STORE_HISTORY, "readwrite");
1090
+ const req = tx.objectStore(STORE_HISTORY).clear();
1091
+ req.onerror = () => reject(req.error);
1092
+ req.onsuccess = () => resolve();
1093
+ });
1094
+ }
1095
+ /**
1096
+ * Bulk import history entries. Entries with existing dedupKeys are
1097
+ * skipped (first-write-wins). Returns the number of newly imported entries.
1098
+ */
1099
+ async importHistoryEntries(entries) {
1100
+ if (!this.db || entries.length === 0) return 0;
1101
+ let imported = 0;
1102
+ for (const entry of entries) {
1103
+ const exists = await this.hasHistoryEntry(entry.dedupKey);
1104
+ if (!exists) {
1105
+ await this.addHistoryEntry(entry);
1106
+ imported++;
1107
+ }
1108
+ }
1109
+ return imported;
1110
+ }
1111
+ // =========================================================================
1112
+ // Private IndexedDB helpers (clear)
1113
+ // =========================================================================
1055
1114
  /**
1056
1115
  * Clear all object stores in a single database.
1057
1116
  * Opens a temporary connection, clears STORE_TOKENS and STORE_META, then closes.
@@ -1078,6 +1137,9 @@ var IndexedDBTokenStorageProvider = class {
1078
1137
  if (!db2.objectStoreNames.contains(STORE_META)) {
1079
1138
  db2.createObjectStore(STORE_META);
1080
1139
  }
1140
+ if (!db2.objectStoreNames.contains(STORE_HISTORY)) {
1141
+ db2.createObjectStore(STORE_HISTORY, { keyPath: "dedupKey" });
1142
+ }
1081
1143
  };
1082
1144
  }),
1083
1145
  new Promise(
@@ -1085,7 +1147,7 @@ var IndexedDBTokenStorageProvider = class {
1085
1147
  )
1086
1148
  ]);
1087
1149
  try {
1088
- for (const storeName of [STORE_TOKENS, STORE_META]) {
1150
+ for (const storeName of [STORE_TOKENS, STORE_META, STORE_HISTORY]) {
1089
1151
  if (db.objectStoreNames.contains(storeName)) {
1090
1152
  await new Promise((resolve, reject) => {
1091
1153
  const tx = db.transaction(storeName, "readwrite");