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