@unicitylabs/sphere-sdk 0.6.13 → 0.6.14
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/README.md +25 -0
- package/dist/core/index.cjs +35 -19
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +15 -0
- package/dist/core/index.d.ts +15 -0
- package/dist/core/index.js +35 -19
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +35 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +35 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.d.cts
CHANGED
|
@@ -3110,6 +3110,12 @@ interface CommunicationsModuleConfig {
|
|
|
3110
3110
|
maxPerConversation?: number;
|
|
3111
3111
|
/** Enable read receipts */
|
|
3112
3112
|
readReceipts?: boolean;
|
|
3113
|
+
/** Cache messages in memory and storage (default: true).
|
|
3114
|
+
* When false, DMs flow through onDirectMessage handlers and events
|
|
3115
|
+
* but are never stored. Useful for anonymous/ephemeral agents.
|
|
3116
|
+
* Note: deduplication is skipped when caching is disabled, so duplicate
|
|
3117
|
+
* events may occur if the relay delivers the same message twice. */
|
|
3118
|
+
cacheMessages?: boolean;
|
|
3113
3119
|
}
|
|
3114
3120
|
interface ConversationPage {
|
|
3115
3121
|
messages: DirectMessage[];
|
|
@@ -3748,6 +3754,8 @@ interface SphereCreateOptions {
|
|
|
3748
3754
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3749
3755
|
/** Market module configuration. true = enable with defaults, object = custom config. */
|
|
3750
3756
|
market?: MarketModuleConfig | boolean;
|
|
3757
|
+
/** Communications module configuration. */
|
|
3758
|
+
communications?: CommunicationsModuleConfig;
|
|
3751
3759
|
/** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
3752
3760
|
password?: string;
|
|
3753
3761
|
/**
|
|
@@ -3786,6 +3794,8 @@ interface SphereLoadOptions {
|
|
|
3786
3794
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3787
3795
|
/** Market module configuration. true = enable with defaults, object = custom config. */
|
|
3788
3796
|
market?: MarketModuleConfig | boolean;
|
|
3797
|
+
/** Communications module configuration. */
|
|
3798
|
+
communications?: CommunicationsModuleConfig;
|
|
3789
3799
|
/** Optional password to decrypt the wallet. Must match the password used during creation. */
|
|
3790
3800
|
password?: string;
|
|
3791
3801
|
/**
|
|
@@ -3832,6 +3842,8 @@ interface SphereImportOptions {
|
|
|
3832
3842
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3833
3843
|
/** Market module configuration. true = enable with defaults, object = custom config. */
|
|
3834
3844
|
market?: MarketModuleConfig | boolean;
|
|
3845
|
+
/** Communications module configuration. */
|
|
3846
|
+
communications?: CommunicationsModuleConfig;
|
|
3835
3847
|
/** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
|
|
3836
3848
|
password?: string;
|
|
3837
3849
|
/**
|
|
@@ -3908,6 +3920,8 @@ interface SphereInitOptions {
|
|
|
3908
3920
|
* Without this, a fresh wallet starts from "now" and misses older DMs.
|
|
3909
3921
|
*/
|
|
3910
3922
|
dmSince?: number;
|
|
3923
|
+
/** Communications module configuration. */
|
|
3924
|
+
communications?: CommunicationsModuleConfig;
|
|
3911
3925
|
/** Enable debug logging (default: false) */
|
|
3912
3926
|
debug?: boolean;
|
|
3913
3927
|
/** Optional callback to report initialization progress steps */
|
|
@@ -3972,6 +3986,7 @@ declare class Sphere {
|
|
|
3972
3986
|
private _l1Config;
|
|
3973
3987
|
private _groupChatConfig;
|
|
3974
3988
|
private _marketConfig;
|
|
3989
|
+
private _communicationsConfig;
|
|
3975
3990
|
private eventHandlers;
|
|
3976
3991
|
private _disabledProviders;
|
|
3977
3992
|
private _providerEventCleanups;
|
package/dist/core/index.d.ts
CHANGED
|
@@ -3110,6 +3110,12 @@ interface CommunicationsModuleConfig {
|
|
|
3110
3110
|
maxPerConversation?: number;
|
|
3111
3111
|
/** Enable read receipts */
|
|
3112
3112
|
readReceipts?: boolean;
|
|
3113
|
+
/** Cache messages in memory and storage (default: true).
|
|
3114
|
+
* When false, DMs flow through onDirectMessage handlers and events
|
|
3115
|
+
* but are never stored. Useful for anonymous/ephemeral agents.
|
|
3116
|
+
* Note: deduplication is skipped when caching is disabled, so duplicate
|
|
3117
|
+
* events may occur if the relay delivers the same message twice. */
|
|
3118
|
+
cacheMessages?: boolean;
|
|
3113
3119
|
}
|
|
3114
3120
|
interface ConversationPage {
|
|
3115
3121
|
messages: DirectMessage[];
|
|
@@ -3748,6 +3754,8 @@ interface SphereCreateOptions {
|
|
|
3748
3754
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3749
3755
|
/** Market module configuration. true = enable with defaults, object = custom config. */
|
|
3750
3756
|
market?: MarketModuleConfig | boolean;
|
|
3757
|
+
/** Communications module configuration. */
|
|
3758
|
+
communications?: CommunicationsModuleConfig;
|
|
3751
3759
|
/** Optional password to encrypt the wallet. If omitted, mnemonic is stored as plaintext. */
|
|
3752
3760
|
password?: string;
|
|
3753
3761
|
/**
|
|
@@ -3786,6 +3794,8 @@ interface SphereLoadOptions {
|
|
|
3786
3794
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3787
3795
|
/** Market module configuration. true = enable with defaults, object = custom config. */
|
|
3788
3796
|
market?: MarketModuleConfig | boolean;
|
|
3797
|
+
/** Communications module configuration. */
|
|
3798
|
+
communications?: CommunicationsModuleConfig;
|
|
3789
3799
|
/** Optional password to decrypt the wallet. Must match the password used during creation. */
|
|
3790
3800
|
password?: string;
|
|
3791
3801
|
/**
|
|
@@ -3832,6 +3842,8 @@ interface SphereImportOptions {
|
|
|
3832
3842
|
groupChat?: GroupChatModuleConfig | boolean;
|
|
3833
3843
|
/** Market module configuration. true = enable with defaults, object = custom config. */
|
|
3834
3844
|
market?: MarketModuleConfig | boolean;
|
|
3845
|
+
/** Communications module configuration. */
|
|
3846
|
+
communications?: CommunicationsModuleConfig;
|
|
3835
3847
|
/** Optional password to encrypt the wallet. If omitted, mnemonic/key is stored as plaintext. */
|
|
3836
3848
|
password?: string;
|
|
3837
3849
|
/**
|
|
@@ -3908,6 +3920,8 @@ interface SphereInitOptions {
|
|
|
3908
3920
|
* Without this, a fresh wallet starts from "now" and misses older DMs.
|
|
3909
3921
|
*/
|
|
3910
3922
|
dmSince?: number;
|
|
3923
|
+
/** Communications module configuration. */
|
|
3924
|
+
communications?: CommunicationsModuleConfig;
|
|
3911
3925
|
/** Enable debug logging (default: false) */
|
|
3912
3926
|
debug?: boolean;
|
|
3913
3927
|
/** Optional callback to report initialization progress steps */
|
|
@@ -3972,6 +3986,7 @@ declare class Sphere {
|
|
|
3972
3986
|
private _l1Config;
|
|
3973
3987
|
private _groupChatConfig;
|
|
3974
3988
|
private _marketConfig;
|
|
3989
|
+
private _communicationsConfig;
|
|
3975
3990
|
private eventHandlers;
|
|
3976
3991
|
private _disabledProviders;
|
|
3977
3992
|
private _providerEventCleanups;
|
package/dist/core/index.js
CHANGED
|
@@ -11574,7 +11574,8 @@ var CommunicationsModule = class {
|
|
|
11574
11574
|
autoSave: config?.autoSave ?? true,
|
|
11575
11575
|
maxMessages: config?.maxMessages ?? 1e3,
|
|
11576
11576
|
maxPerConversation: config?.maxPerConversation ?? 200,
|
|
11577
|
-
readReceipts: config?.readReceipts ?? true
|
|
11577
|
+
readReceipts: config?.readReceipts ?? true,
|
|
11578
|
+
cacheMessages: config?.cacheMessages ?? true
|
|
11578
11579
|
};
|
|
11579
11580
|
}
|
|
11580
11581
|
// ===========================================================================
|
|
@@ -11630,6 +11631,7 @@ var CommunicationsModule = class {
|
|
|
11630
11631
|
* Falls back to legacy global 'direct_messages' key for migration.
|
|
11631
11632
|
*/
|
|
11632
11633
|
async load() {
|
|
11634
|
+
if (!this.config.cacheMessages) return;
|
|
11633
11635
|
this.ensureInitialized();
|
|
11634
11636
|
this.messages.clear();
|
|
11635
11637
|
let data = await this.deps.storage.get(STORAGE_KEYS_ADDRESS.MESSAGES);
|
|
@@ -11689,9 +11691,11 @@ var CommunicationsModule = class {
|
|
|
11689
11691
|
timestamp: Date.now(),
|
|
11690
11692
|
isRead: false
|
|
11691
11693
|
};
|
|
11692
|
-
this.
|
|
11693
|
-
|
|
11694
|
-
|
|
11694
|
+
if (this.config.cacheMessages) {
|
|
11695
|
+
this.messages.set(message.id, message);
|
|
11696
|
+
if (this.config.autoSave) {
|
|
11697
|
+
await this.save();
|
|
11698
|
+
}
|
|
11695
11699
|
}
|
|
11696
11700
|
return message;
|
|
11697
11701
|
}
|
|
@@ -11730,7 +11734,7 @@ var CommunicationsModule = class {
|
|
|
11730
11734
|
msg.isRead = true;
|
|
11731
11735
|
}
|
|
11732
11736
|
}
|
|
11733
|
-
if (this.config.autoSave) {
|
|
11737
|
+
if (this.config.cacheMessages && this.config.autoSave) {
|
|
11734
11738
|
await this.save();
|
|
11735
11739
|
}
|
|
11736
11740
|
if (this.config.readReceipts && this.deps?.transport.sendReadReceipt) {
|
|
@@ -11778,6 +11782,7 @@ var CommunicationsModule = class {
|
|
|
11778
11782
|
* Delete all messages in a conversation with a peer
|
|
11779
11783
|
*/
|
|
11780
11784
|
async deleteConversation(peerPubkey) {
|
|
11785
|
+
if (!this.config.cacheMessages) return;
|
|
11781
11786
|
for (const [id, msg] of this.messages) {
|
|
11782
11787
|
if (msg.senderPubkey === peerPubkey || msg.recipientPubkey === peerPubkey) {
|
|
11783
11788
|
this.messages.delete(id);
|
|
@@ -11904,7 +11909,7 @@ var CommunicationsModule = class {
|
|
|
11904
11909
|
handleIncomingMessage(msg) {
|
|
11905
11910
|
const isHistorical = msg.timestamp < this.initializedAt;
|
|
11906
11911
|
if (msg.isSelfWrap && msg.recipientTransportPubkey) {
|
|
11907
|
-
if (this.messages.has(msg.id)) return;
|
|
11912
|
+
if (this.config.cacheMessages && this.messages.has(msg.id)) return;
|
|
11908
11913
|
const message2 = {
|
|
11909
11914
|
id: msg.id,
|
|
11910
11915
|
senderPubkey: this.deps.identity.chainPubkey,
|
|
@@ -11914,9 +11919,11 @@ var CommunicationsModule = class {
|
|
|
11914
11919
|
timestamp: msg.timestamp,
|
|
11915
11920
|
isRead: isHistorical
|
|
11916
11921
|
};
|
|
11917
|
-
this.
|
|
11922
|
+
if (this.config.cacheMessages) {
|
|
11923
|
+
this.messages.set(message2.id, message2);
|
|
11924
|
+
}
|
|
11918
11925
|
this.deps.emitEvent("message:dm", message2);
|
|
11919
|
-
if (this.config.autoSave) {
|
|
11926
|
+
if (this.config.cacheMessages && this.config.autoSave) {
|
|
11920
11927
|
this.save();
|
|
11921
11928
|
}
|
|
11922
11929
|
return;
|
|
@@ -11927,7 +11934,7 @@ var CommunicationsModule = class {
|
|
|
11927
11934
|
if (tp === ownChainPubkey) return;
|
|
11928
11935
|
if (ownChainPubkey.length === 66 && (ownChainPubkey.startsWith("02") || ownChainPubkey.startsWith("03")) && tp === ownChainPubkey.slice(2)) return;
|
|
11929
11936
|
}
|
|
11930
|
-
if (this.messages.has(msg.id)) return;
|
|
11937
|
+
if (this.config.cacheMessages && this.messages.has(msg.id)) return;
|
|
11931
11938
|
const message = {
|
|
11932
11939
|
id: msg.id,
|
|
11933
11940
|
senderPubkey: msg.senderTransportPubkey,
|
|
@@ -11937,7 +11944,9 @@ var CommunicationsModule = class {
|
|
|
11937
11944
|
timestamp: msg.timestamp,
|
|
11938
11945
|
isRead: isHistorical
|
|
11939
11946
|
};
|
|
11940
|
-
this.
|
|
11947
|
+
if (this.config.cacheMessages) {
|
|
11948
|
+
this.messages.set(message.id, message);
|
|
11949
|
+
}
|
|
11941
11950
|
this.deps.emitEvent("message:dm", message);
|
|
11942
11951
|
for (const handler of this.dmHandlers) {
|
|
11943
11952
|
try {
|
|
@@ -11946,10 +11955,12 @@ var CommunicationsModule = class {
|
|
|
11946
11955
|
logger.error("Communications", "Handler error:", error);
|
|
11947
11956
|
}
|
|
11948
11957
|
}
|
|
11949
|
-
if (this.config.
|
|
11950
|
-
this.
|
|
11958
|
+
if (this.config.cacheMessages) {
|
|
11959
|
+
if (this.config.autoSave) {
|
|
11960
|
+
this.save();
|
|
11961
|
+
}
|
|
11962
|
+
this.pruneIfNeeded();
|
|
11951
11963
|
}
|
|
11952
|
-
this.pruneIfNeeded();
|
|
11953
11964
|
}
|
|
11954
11965
|
handleComposingIndicator(indicator) {
|
|
11955
11966
|
const composing = {
|
|
@@ -16560,6 +16571,7 @@ var Sphere = class _Sphere {
|
|
|
16560
16571
|
_l1Config;
|
|
16561
16572
|
_groupChatConfig;
|
|
16562
16573
|
_marketConfig;
|
|
16574
|
+
_communicationsConfig;
|
|
16563
16575
|
// Events
|
|
16564
16576
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
16565
16577
|
// Provider management
|
|
@@ -16569,7 +16581,7 @@ var Sphere = class _Sphere {
|
|
|
16569
16581
|
// ===========================================================================
|
|
16570
16582
|
// Constructor (private)
|
|
16571
16583
|
// ===========================================================================
|
|
16572
|
-
constructor(storage, transport, oracle, tokenStorage, l1Config, priceProvider, groupChatConfig, marketConfig) {
|
|
16584
|
+
constructor(storage, transport, oracle, tokenStorage, l1Config, priceProvider, groupChatConfig, marketConfig, communicationsConfig) {
|
|
16573
16585
|
this._storage = storage;
|
|
16574
16586
|
this._transport = transport;
|
|
16575
16587
|
this._oracle = oracle;
|
|
@@ -16580,8 +16592,9 @@ var Sphere = class _Sphere {
|
|
|
16580
16592
|
this._l1Config = l1Config;
|
|
16581
16593
|
this._groupChatConfig = groupChatConfig;
|
|
16582
16594
|
this._marketConfig = marketConfig;
|
|
16595
|
+
this._communicationsConfig = communicationsConfig;
|
|
16583
16596
|
this._payments = createPaymentsModule({ l1: l1Config });
|
|
16584
|
-
this._communications = createCommunicationsModule();
|
|
16597
|
+
this._communications = createCommunicationsModule(communicationsConfig);
|
|
16585
16598
|
this._groupChat = groupChatConfig ? createGroupChatModule(groupChatConfig) : null;
|
|
16586
16599
|
this._market = marketConfig ? createMarketModule(marketConfig) : null;
|
|
16587
16600
|
}
|
|
@@ -16769,7 +16782,8 @@ var Sphere = class _Sphere {
|
|
|
16769
16782
|
options.l1,
|
|
16770
16783
|
options.price,
|
|
16771
16784
|
groupChatConfig,
|
|
16772
|
-
marketConfig
|
|
16785
|
+
marketConfig,
|
|
16786
|
+
options.communications
|
|
16773
16787
|
);
|
|
16774
16788
|
sphere._password = options.password ?? null;
|
|
16775
16789
|
progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
|
|
@@ -16827,7 +16841,8 @@ var Sphere = class _Sphere {
|
|
|
16827
16841
|
options.l1,
|
|
16828
16842
|
options.price,
|
|
16829
16843
|
groupChatConfig,
|
|
16830
|
-
marketConfig
|
|
16844
|
+
marketConfig,
|
|
16845
|
+
options.communications
|
|
16831
16846
|
);
|
|
16832
16847
|
sphere._password = options.password ?? null;
|
|
16833
16848
|
if (!options.storage.isConnected()) {
|
|
@@ -16905,7 +16920,8 @@ var Sphere = class _Sphere {
|
|
|
16905
16920
|
options.l1,
|
|
16906
16921
|
options.price,
|
|
16907
16922
|
groupChatConfig,
|
|
16908
|
-
marketConfig
|
|
16923
|
+
marketConfig,
|
|
16924
|
+
options.communications
|
|
16909
16925
|
);
|
|
16910
16926
|
sphere._password = options.password ?? null;
|
|
16911
16927
|
progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
|
|
@@ -17971,7 +17987,7 @@ var Sphere = class _Sphere {
|
|
|
17971
17987
|
addressTransport.setFallbackDmSince(this._dmSince);
|
|
17972
17988
|
}
|
|
17973
17989
|
const payments = createPaymentsModule({ l1: this._l1Config });
|
|
17974
|
-
const communications = createCommunicationsModule();
|
|
17990
|
+
const communications = createCommunicationsModule(this._communicationsConfig);
|
|
17975
17991
|
const groupChat = this._groupChatConfig ? createGroupChatModule(this._groupChatConfig) : null;
|
|
17976
17992
|
const market = this._marketConfig ? createMarketModule(this._marketConfig) : null;
|
|
17977
17993
|
payments.initialize({
|