@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.
@@ -361,6 +361,9 @@ function createFileStorageProvider(config) {
361
361
  // impl/nodejs/storage/FileTokenStorageProvider.ts
362
362
  var fs2 = __toESM(require("fs"), 1);
363
363
  var path2 = __toESM(require("path"), 1);
364
+ var META_FILE = "_meta.json";
365
+ var TOMBSTONES_FILE = "_tombstones.json";
366
+ var HISTORY_FILE = "_history.json";
364
367
  var FileTokenStorageProvider = class {
365
368
  id = "file-token-storage";
366
369
  name = "File Token Storage";
@@ -418,7 +421,7 @@ var FileTokenStorageProvider = class {
418
421
  };
419
422
  try {
420
423
  const files = fs2.readdirSync(this.tokensDir).filter(
421
- (f) => f.endsWith(".json") && f !== "_meta.json" && f !== "_tombstones.json" && !f.startsWith("archived_") && // Skip archived tokens
424
+ (f) => f.endsWith(".json") && f !== META_FILE && f !== TOMBSTONES_FILE && f !== HISTORY_FILE && !f.startsWith("archived_") && // Skip archived tokens
422
425
  !f.startsWith("token-") && // Skip legacy token format
423
426
  !f.startsWith("nametag-")
424
427
  // Skip nametag files (not tokens)
@@ -440,7 +443,7 @@ var FileTokenStorageProvider = class {
440
443
  } catch {
441
444
  }
442
445
  }
443
- const tombstonesPath = path2.join(this.tokensDir, "_tombstones.json");
446
+ const tombstonesPath = path2.join(this.tokensDir, TOMBSTONES_FILE);
444
447
  if (fs2.existsSync(tombstonesPath)) {
445
448
  try {
446
449
  const content = fs2.readFileSync(tombstonesPath, "utf-8");
@@ -466,7 +469,7 @@ var FileTokenStorageProvider = class {
466
469
  async save(data) {
467
470
  try {
468
471
  fs2.writeFileSync(
469
- path2.join(this.tokensDir, "_meta.json"),
472
+ path2.join(this.tokensDir, META_FILE),
470
473
  JSON.stringify(data._meta, null, 2)
471
474
  );
472
475
  const reservedKeys = ["_meta", "_tombstones", "_outbox", "_sent", "_invalid"];
@@ -493,7 +496,7 @@ var FileTokenStorageProvider = class {
493
496
  }
494
497
  }
495
498
  fs2.writeFileSync(
496
- path2.join(this.tokensDir, "_tombstones.json"),
499
+ path2.join(this.tokensDir, TOMBSTONES_FILE),
497
500
  JSON.stringify(data._tombstones, null, 2)
498
501
  );
499
502
  }
@@ -534,6 +537,60 @@ var FileTokenStorageProvider = class {
534
537
  return false;
535
538
  }
536
539
  }
540
+ // =========================================================================
541
+ // History operations
542
+ // =========================================================================
543
+ get historyPath() {
544
+ return path2.join(this.tokensDir, HISTORY_FILE);
545
+ }
546
+ readHistoryFile() {
547
+ try {
548
+ if (fs2.existsSync(this.historyPath)) {
549
+ return JSON.parse(fs2.readFileSync(this.historyPath, "utf-8"));
550
+ }
551
+ } catch {
552
+ }
553
+ return {};
554
+ }
555
+ writeHistoryFile(data) {
556
+ fs2.writeFileSync(this.historyPath, JSON.stringify(data, null, 2));
557
+ }
558
+ async addHistoryEntry(entry) {
559
+ const data = this.readHistoryFile();
560
+ data[entry.dedupKey] = entry;
561
+ this.writeHistoryFile(data);
562
+ }
563
+ async getHistoryEntries() {
564
+ const data = this.readHistoryFile();
565
+ return Object.values(data).sort((a, b) => b.timestamp - a.timestamp);
566
+ }
567
+ async hasHistoryEntry(dedupKey) {
568
+ const data = this.readHistoryFile();
569
+ return dedupKey in data;
570
+ }
571
+ async clearHistory() {
572
+ try {
573
+ if (fs2.existsSync(this.historyPath)) {
574
+ fs2.unlinkSync(this.historyPath);
575
+ }
576
+ } catch {
577
+ }
578
+ }
579
+ async importHistoryEntries(entries) {
580
+ if (entries.length === 0) return 0;
581
+ const data = this.readHistoryFile();
582
+ let imported = 0;
583
+ for (const entry of entries) {
584
+ if (!(entry.dedupKey in data)) {
585
+ data[entry.dedupKey] = entry;
586
+ imported++;
587
+ }
588
+ }
589
+ if (imported > 0) {
590
+ this.writeHistoryFile(data);
591
+ }
592
+ return imported;
593
+ }
537
594
  };
538
595
  function createFileTokenStorageProvider(config) {
539
596
  return new FileTokenStorageProvider(config);