@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.
- package/dist/core/index.cjs +183 -80
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +222 -194
- package/dist/core/index.d.ts +222 -194
- package/dist/core/index.js +183 -80
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +64 -2
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +64 -2
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +61 -4
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +668 -628
- package/dist/impl/nodejs/index.d.ts +668 -628
- package/dist/impl/nodejs/index.js +61 -4
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +183 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +222 -194
- package/dist/index.d.ts +222 -194
- package/dist/index.js +183 -80
- package/dist/index.js.map +1 -1
- package/dist/l1/index.cjs +2 -0
- package/dist/l1/index.cjs.map +1 -1
- package/dist/l1/index.js +2 -0
- package/dist/l1/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -649,9 +649,10 @@ function createIndexedDBStorageProvider(config) {
|
|
|
649
649
|
|
|
650
650
|
// impl/browser/storage/IndexedDBTokenStorageProvider.ts
|
|
651
651
|
var DB_NAME2 = "sphere-token-storage";
|
|
652
|
-
var DB_VERSION2 =
|
|
652
|
+
var DB_VERSION2 = 2;
|
|
653
653
|
var STORE_TOKENS = "tokens";
|
|
654
654
|
var STORE_META = "meta";
|
|
655
|
+
var STORE_HISTORY = "history";
|
|
655
656
|
var connectionSeq2 = 0;
|
|
656
657
|
var IndexedDBTokenStorageProvider = class {
|
|
657
658
|
id = "indexeddb-token-storage";
|
|
@@ -919,6 +920,9 @@ var IndexedDBTokenStorageProvider = class {
|
|
|
919
920
|
if (!db.objectStoreNames.contains(STORE_META)) {
|
|
920
921
|
db.createObjectStore(STORE_META);
|
|
921
922
|
}
|
|
923
|
+
if (!db.objectStoreNames.contains(STORE_HISTORY)) {
|
|
924
|
+
db.createObjectStore(STORE_HISTORY, { keyPath: "dedupKey" });
|
|
925
|
+
}
|
|
922
926
|
};
|
|
923
927
|
});
|
|
924
928
|
}
|
|
@@ -992,6 +996,61 @@ var IndexedDBTokenStorageProvider = class {
|
|
|
992
996
|
return [];
|
|
993
997
|
}
|
|
994
998
|
}
|
|
999
|
+
// =========================================================================
|
|
1000
|
+
// Public: History operations
|
|
1001
|
+
// =========================================================================
|
|
1002
|
+
/**
|
|
1003
|
+
* Add a history entry. Uses `put` (upsert by dedupKey) so duplicate
|
|
1004
|
+
* calls with the same dedupKey simply overwrite — no duplicates.
|
|
1005
|
+
*/
|
|
1006
|
+
async addHistoryEntry(entry) {
|
|
1007
|
+
await this.putToStore(STORE_HISTORY, entry.dedupKey, entry);
|
|
1008
|
+
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Get all history entries sorted by timestamp descending.
|
|
1011
|
+
*/
|
|
1012
|
+
async getHistoryEntries() {
|
|
1013
|
+
const entries = await this.getAllFromStore(STORE_HISTORY);
|
|
1014
|
+
return entries.sort((a, b) => b.timestamp - a.timestamp);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Check if a history entry with the given dedupKey exists.
|
|
1018
|
+
*/
|
|
1019
|
+
async hasHistoryEntry(dedupKey) {
|
|
1020
|
+
const entry = await this.getFromStore(STORE_HISTORY, dedupKey);
|
|
1021
|
+
return entry !== null;
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Clear all history entries.
|
|
1025
|
+
*/
|
|
1026
|
+
async clearHistory() {
|
|
1027
|
+
if (!this.db) return;
|
|
1028
|
+
await new Promise((resolve, reject) => {
|
|
1029
|
+
const tx = this.db.transaction(STORE_HISTORY, "readwrite");
|
|
1030
|
+
const req = tx.objectStore(STORE_HISTORY).clear();
|
|
1031
|
+
req.onerror = () => reject(req.error);
|
|
1032
|
+
req.onsuccess = () => resolve();
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Bulk import history entries. Entries with existing dedupKeys are
|
|
1037
|
+
* skipped (first-write-wins). Returns the number of newly imported entries.
|
|
1038
|
+
*/
|
|
1039
|
+
async importHistoryEntries(entries) {
|
|
1040
|
+
if (!this.db || entries.length === 0) return 0;
|
|
1041
|
+
let imported = 0;
|
|
1042
|
+
for (const entry of entries) {
|
|
1043
|
+
const exists = await this.hasHistoryEntry(entry.dedupKey);
|
|
1044
|
+
if (!exists) {
|
|
1045
|
+
await this.addHistoryEntry(entry);
|
|
1046
|
+
imported++;
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return imported;
|
|
1050
|
+
}
|
|
1051
|
+
// =========================================================================
|
|
1052
|
+
// Private IndexedDB helpers (clear)
|
|
1053
|
+
// =========================================================================
|
|
995
1054
|
/**
|
|
996
1055
|
* Clear all object stores in a single database.
|
|
997
1056
|
* Opens a temporary connection, clears STORE_TOKENS and STORE_META, then closes.
|
|
@@ -1018,6 +1077,9 @@ var IndexedDBTokenStorageProvider = class {
|
|
|
1018
1077
|
if (!db2.objectStoreNames.contains(STORE_META)) {
|
|
1019
1078
|
db2.createObjectStore(STORE_META);
|
|
1020
1079
|
}
|
|
1080
|
+
if (!db2.objectStoreNames.contains(STORE_HISTORY)) {
|
|
1081
|
+
db2.createObjectStore(STORE_HISTORY, { keyPath: "dedupKey" });
|
|
1082
|
+
}
|
|
1021
1083
|
};
|
|
1022
1084
|
}),
|
|
1023
1085
|
new Promise(
|
|
@@ -1025,7 +1087,7 @@ var IndexedDBTokenStorageProvider = class {
|
|
|
1025
1087
|
)
|
|
1026
1088
|
]);
|
|
1027
1089
|
try {
|
|
1028
|
-
for (const storeName of [STORE_TOKENS, STORE_META]) {
|
|
1090
|
+
for (const storeName of [STORE_TOKENS, STORE_META, STORE_HISTORY]) {
|
|
1029
1091
|
if (db.objectStoreNames.contains(storeName)) {
|
|
1030
1092
|
await new Promise((resolve, reject) => {
|
|
1031
1093
|
const tx = db.transaction(storeName, "readwrite");
|