@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
|
@@ -312,6 +312,9 @@ function createFileStorageProvider(config) {
|
|
|
312
312
|
// impl/nodejs/storage/FileTokenStorageProvider.ts
|
|
313
313
|
import * as fs2 from "fs";
|
|
314
314
|
import * as path2 from "path";
|
|
315
|
+
var META_FILE = "_meta.json";
|
|
316
|
+
var TOMBSTONES_FILE = "_tombstones.json";
|
|
317
|
+
var HISTORY_FILE = "_history.json";
|
|
315
318
|
var FileTokenStorageProvider = class {
|
|
316
319
|
id = "file-token-storage";
|
|
317
320
|
name = "File Token Storage";
|
|
@@ -369,7 +372,7 @@ var FileTokenStorageProvider = class {
|
|
|
369
372
|
};
|
|
370
373
|
try {
|
|
371
374
|
const files = fs2.readdirSync(this.tokensDir).filter(
|
|
372
|
-
(f) => f.endsWith(".json") && f !==
|
|
375
|
+
(f) => f.endsWith(".json") && f !== META_FILE && f !== TOMBSTONES_FILE && f !== HISTORY_FILE && !f.startsWith("archived_") && // Skip archived tokens
|
|
373
376
|
!f.startsWith("token-") && // Skip legacy token format
|
|
374
377
|
!f.startsWith("nametag-")
|
|
375
378
|
// Skip nametag files (not tokens)
|
|
@@ -391,7 +394,7 @@ var FileTokenStorageProvider = class {
|
|
|
391
394
|
} catch {
|
|
392
395
|
}
|
|
393
396
|
}
|
|
394
|
-
const tombstonesPath = path2.join(this.tokensDir,
|
|
397
|
+
const tombstonesPath = path2.join(this.tokensDir, TOMBSTONES_FILE);
|
|
395
398
|
if (fs2.existsSync(tombstonesPath)) {
|
|
396
399
|
try {
|
|
397
400
|
const content = fs2.readFileSync(tombstonesPath, "utf-8");
|
|
@@ -417,7 +420,7 @@ var FileTokenStorageProvider = class {
|
|
|
417
420
|
async save(data) {
|
|
418
421
|
try {
|
|
419
422
|
fs2.writeFileSync(
|
|
420
|
-
path2.join(this.tokensDir,
|
|
423
|
+
path2.join(this.tokensDir, META_FILE),
|
|
421
424
|
JSON.stringify(data._meta, null, 2)
|
|
422
425
|
);
|
|
423
426
|
const reservedKeys = ["_meta", "_tombstones", "_outbox", "_sent", "_invalid"];
|
|
@@ -444,7 +447,7 @@ var FileTokenStorageProvider = class {
|
|
|
444
447
|
}
|
|
445
448
|
}
|
|
446
449
|
fs2.writeFileSync(
|
|
447
|
-
path2.join(this.tokensDir,
|
|
450
|
+
path2.join(this.tokensDir, TOMBSTONES_FILE),
|
|
448
451
|
JSON.stringify(data._tombstones, null, 2)
|
|
449
452
|
);
|
|
450
453
|
}
|
|
@@ -485,6 +488,60 @@ var FileTokenStorageProvider = class {
|
|
|
485
488
|
return false;
|
|
486
489
|
}
|
|
487
490
|
}
|
|
491
|
+
// =========================================================================
|
|
492
|
+
// History operations
|
|
493
|
+
// =========================================================================
|
|
494
|
+
get historyPath() {
|
|
495
|
+
return path2.join(this.tokensDir, HISTORY_FILE);
|
|
496
|
+
}
|
|
497
|
+
readHistoryFile() {
|
|
498
|
+
try {
|
|
499
|
+
if (fs2.existsSync(this.historyPath)) {
|
|
500
|
+
return JSON.parse(fs2.readFileSync(this.historyPath, "utf-8"));
|
|
501
|
+
}
|
|
502
|
+
} catch {
|
|
503
|
+
}
|
|
504
|
+
return {};
|
|
505
|
+
}
|
|
506
|
+
writeHistoryFile(data) {
|
|
507
|
+
fs2.writeFileSync(this.historyPath, JSON.stringify(data, null, 2));
|
|
508
|
+
}
|
|
509
|
+
async addHistoryEntry(entry) {
|
|
510
|
+
const data = this.readHistoryFile();
|
|
511
|
+
data[entry.dedupKey] = entry;
|
|
512
|
+
this.writeHistoryFile(data);
|
|
513
|
+
}
|
|
514
|
+
async getHistoryEntries() {
|
|
515
|
+
const data = this.readHistoryFile();
|
|
516
|
+
return Object.values(data).sort((a, b) => b.timestamp - a.timestamp);
|
|
517
|
+
}
|
|
518
|
+
async hasHistoryEntry(dedupKey) {
|
|
519
|
+
const data = this.readHistoryFile();
|
|
520
|
+
return dedupKey in data;
|
|
521
|
+
}
|
|
522
|
+
async clearHistory() {
|
|
523
|
+
try {
|
|
524
|
+
if (fs2.existsSync(this.historyPath)) {
|
|
525
|
+
fs2.unlinkSync(this.historyPath);
|
|
526
|
+
}
|
|
527
|
+
} catch {
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
async importHistoryEntries(entries) {
|
|
531
|
+
if (entries.length === 0) return 0;
|
|
532
|
+
const data = this.readHistoryFile();
|
|
533
|
+
let imported = 0;
|
|
534
|
+
for (const entry of entries) {
|
|
535
|
+
if (!(entry.dedupKey in data)) {
|
|
536
|
+
data[entry.dedupKey] = entry;
|
|
537
|
+
imported++;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (imported > 0) {
|
|
541
|
+
this.writeHistoryFile(data);
|
|
542
|
+
}
|
|
543
|
+
return imported;
|
|
544
|
+
}
|
|
488
545
|
};
|
|
489
546
|
function createFileTokenStorageProvider(config) {
|
|
490
547
|
return new FileTokenStorageProvider(config);
|