@unicitylabs/sphere-sdk 0.6.13-dev.3 → 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/index.cjs
CHANGED
|
@@ -11994,7 +11994,8 @@ var CommunicationsModule = class {
|
|
|
11994
11994
|
autoSave: config?.autoSave ?? true,
|
|
11995
11995
|
maxMessages: config?.maxMessages ?? 1e3,
|
|
11996
11996
|
maxPerConversation: config?.maxPerConversation ?? 200,
|
|
11997
|
-
readReceipts: config?.readReceipts ?? true
|
|
11997
|
+
readReceipts: config?.readReceipts ?? true,
|
|
11998
|
+
cacheMessages: config?.cacheMessages ?? true
|
|
11998
11999
|
};
|
|
11999
12000
|
}
|
|
12000
12001
|
// ===========================================================================
|
|
@@ -12050,6 +12051,7 @@ var CommunicationsModule = class {
|
|
|
12050
12051
|
* Falls back to legacy global 'direct_messages' key for migration.
|
|
12051
12052
|
*/
|
|
12052
12053
|
async load() {
|
|
12054
|
+
if (!this.config.cacheMessages) return;
|
|
12053
12055
|
this.ensureInitialized();
|
|
12054
12056
|
this.messages.clear();
|
|
12055
12057
|
let data = await this.deps.storage.get(STORAGE_KEYS_ADDRESS.MESSAGES);
|
|
@@ -12109,9 +12111,11 @@ var CommunicationsModule = class {
|
|
|
12109
12111
|
timestamp: Date.now(),
|
|
12110
12112
|
isRead: false
|
|
12111
12113
|
};
|
|
12112
|
-
this.
|
|
12113
|
-
|
|
12114
|
-
|
|
12114
|
+
if (this.config.cacheMessages) {
|
|
12115
|
+
this.messages.set(message.id, message);
|
|
12116
|
+
if (this.config.autoSave) {
|
|
12117
|
+
await this.save();
|
|
12118
|
+
}
|
|
12115
12119
|
}
|
|
12116
12120
|
return message;
|
|
12117
12121
|
}
|
|
@@ -12150,7 +12154,7 @@ var CommunicationsModule = class {
|
|
|
12150
12154
|
msg.isRead = true;
|
|
12151
12155
|
}
|
|
12152
12156
|
}
|
|
12153
|
-
if (this.config.autoSave) {
|
|
12157
|
+
if (this.config.cacheMessages && this.config.autoSave) {
|
|
12154
12158
|
await this.save();
|
|
12155
12159
|
}
|
|
12156
12160
|
if (this.config.readReceipts && this.deps?.transport.sendReadReceipt) {
|
|
@@ -12198,6 +12202,7 @@ var CommunicationsModule = class {
|
|
|
12198
12202
|
* Delete all messages in a conversation with a peer
|
|
12199
12203
|
*/
|
|
12200
12204
|
async deleteConversation(peerPubkey) {
|
|
12205
|
+
if (!this.config.cacheMessages) return;
|
|
12201
12206
|
for (const [id, msg] of this.messages) {
|
|
12202
12207
|
if (msg.senderPubkey === peerPubkey || msg.recipientPubkey === peerPubkey) {
|
|
12203
12208
|
this.messages.delete(id);
|
|
@@ -12324,7 +12329,7 @@ var CommunicationsModule = class {
|
|
|
12324
12329
|
handleIncomingMessage(msg) {
|
|
12325
12330
|
const isHistorical = msg.timestamp < this.initializedAt;
|
|
12326
12331
|
if (msg.isSelfWrap && msg.recipientTransportPubkey) {
|
|
12327
|
-
if (this.messages.has(msg.id)) return;
|
|
12332
|
+
if (this.config.cacheMessages && this.messages.has(msg.id)) return;
|
|
12328
12333
|
const message2 = {
|
|
12329
12334
|
id: msg.id,
|
|
12330
12335
|
senderPubkey: this.deps.identity.chainPubkey,
|
|
@@ -12334,9 +12339,11 @@ var CommunicationsModule = class {
|
|
|
12334
12339
|
timestamp: msg.timestamp,
|
|
12335
12340
|
isRead: isHistorical
|
|
12336
12341
|
};
|
|
12337
|
-
this.
|
|
12342
|
+
if (this.config.cacheMessages) {
|
|
12343
|
+
this.messages.set(message2.id, message2);
|
|
12344
|
+
}
|
|
12338
12345
|
this.deps.emitEvent("message:dm", message2);
|
|
12339
|
-
if (this.config.autoSave) {
|
|
12346
|
+
if (this.config.cacheMessages && this.config.autoSave) {
|
|
12340
12347
|
this.save();
|
|
12341
12348
|
}
|
|
12342
12349
|
return;
|
|
@@ -12347,7 +12354,7 @@ var CommunicationsModule = class {
|
|
|
12347
12354
|
if (tp === ownChainPubkey) return;
|
|
12348
12355
|
if (ownChainPubkey.length === 66 && (ownChainPubkey.startsWith("02") || ownChainPubkey.startsWith("03")) && tp === ownChainPubkey.slice(2)) return;
|
|
12349
12356
|
}
|
|
12350
|
-
if (this.messages.has(msg.id)) return;
|
|
12357
|
+
if (this.config.cacheMessages && this.messages.has(msg.id)) return;
|
|
12351
12358
|
const message = {
|
|
12352
12359
|
id: msg.id,
|
|
12353
12360
|
senderPubkey: msg.senderTransportPubkey,
|
|
@@ -12357,7 +12364,9 @@ var CommunicationsModule = class {
|
|
|
12357
12364
|
timestamp: msg.timestamp,
|
|
12358
12365
|
isRead: isHistorical
|
|
12359
12366
|
};
|
|
12360
|
-
this.
|
|
12367
|
+
if (this.config.cacheMessages) {
|
|
12368
|
+
this.messages.set(message.id, message);
|
|
12369
|
+
}
|
|
12361
12370
|
this.deps.emitEvent("message:dm", message);
|
|
12362
12371
|
for (const handler of this.dmHandlers) {
|
|
12363
12372
|
try {
|
|
@@ -12366,10 +12375,12 @@ var CommunicationsModule = class {
|
|
|
12366
12375
|
logger.error("Communications", "Handler error:", error);
|
|
12367
12376
|
}
|
|
12368
12377
|
}
|
|
12369
|
-
if (this.config.
|
|
12370
|
-
this.
|
|
12378
|
+
if (this.config.cacheMessages) {
|
|
12379
|
+
if (this.config.autoSave) {
|
|
12380
|
+
this.save();
|
|
12381
|
+
}
|
|
12382
|
+
this.pruneIfNeeded();
|
|
12371
12383
|
}
|
|
12372
|
-
this.pruneIfNeeded();
|
|
12373
12384
|
}
|
|
12374
12385
|
handleComposingIndicator(indicator) {
|
|
12375
12386
|
const composing = {
|
|
@@ -16891,6 +16902,7 @@ var Sphere = class _Sphere {
|
|
|
16891
16902
|
_l1Config;
|
|
16892
16903
|
_groupChatConfig;
|
|
16893
16904
|
_marketConfig;
|
|
16905
|
+
_communicationsConfig;
|
|
16894
16906
|
// Events
|
|
16895
16907
|
eventHandlers = /* @__PURE__ */ new Map();
|
|
16896
16908
|
// Provider management
|
|
@@ -16900,7 +16912,7 @@ var Sphere = class _Sphere {
|
|
|
16900
16912
|
// ===========================================================================
|
|
16901
16913
|
// Constructor (private)
|
|
16902
16914
|
// ===========================================================================
|
|
16903
|
-
constructor(storage, transport, oracle, tokenStorage, l1Config, priceProvider, groupChatConfig, marketConfig) {
|
|
16915
|
+
constructor(storage, transport, oracle, tokenStorage, l1Config, priceProvider, groupChatConfig, marketConfig, communicationsConfig) {
|
|
16904
16916
|
this._storage = storage;
|
|
16905
16917
|
this._transport = transport;
|
|
16906
16918
|
this._oracle = oracle;
|
|
@@ -16911,8 +16923,9 @@ var Sphere = class _Sphere {
|
|
|
16911
16923
|
this._l1Config = l1Config;
|
|
16912
16924
|
this._groupChatConfig = groupChatConfig;
|
|
16913
16925
|
this._marketConfig = marketConfig;
|
|
16926
|
+
this._communicationsConfig = communicationsConfig;
|
|
16914
16927
|
this._payments = createPaymentsModule({ l1: l1Config });
|
|
16915
|
-
this._communications = createCommunicationsModule();
|
|
16928
|
+
this._communications = createCommunicationsModule(communicationsConfig);
|
|
16916
16929
|
this._groupChat = groupChatConfig ? createGroupChatModule(groupChatConfig) : null;
|
|
16917
16930
|
this._market = marketConfig ? createMarketModule(marketConfig) : null;
|
|
16918
16931
|
}
|
|
@@ -17100,7 +17113,8 @@ var Sphere = class _Sphere {
|
|
|
17100
17113
|
options.l1,
|
|
17101
17114
|
options.price,
|
|
17102
17115
|
groupChatConfig,
|
|
17103
|
-
marketConfig
|
|
17116
|
+
marketConfig,
|
|
17117
|
+
options.communications
|
|
17104
17118
|
);
|
|
17105
17119
|
sphere._password = options.password ?? null;
|
|
17106
17120
|
progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
|
|
@@ -17158,7 +17172,8 @@ var Sphere = class _Sphere {
|
|
|
17158
17172
|
options.l1,
|
|
17159
17173
|
options.price,
|
|
17160
17174
|
groupChatConfig,
|
|
17161
|
-
marketConfig
|
|
17175
|
+
marketConfig,
|
|
17176
|
+
options.communications
|
|
17162
17177
|
);
|
|
17163
17178
|
sphere._password = options.password ?? null;
|
|
17164
17179
|
if (!options.storage.isConnected()) {
|
|
@@ -17236,7 +17251,8 @@ var Sphere = class _Sphere {
|
|
|
17236
17251
|
options.l1,
|
|
17237
17252
|
options.price,
|
|
17238
17253
|
groupChatConfig,
|
|
17239
|
-
marketConfig
|
|
17254
|
+
marketConfig,
|
|
17255
|
+
options.communications
|
|
17240
17256
|
);
|
|
17241
17257
|
sphere._password = options.password ?? null;
|
|
17242
17258
|
progress?.({ step: "storing_keys", message: "Storing wallet keys..." });
|
|
@@ -18302,7 +18318,7 @@ var Sphere = class _Sphere {
|
|
|
18302
18318
|
addressTransport.setFallbackDmSince(this._dmSince);
|
|
18303
18319
|
}
|
|
18304
18320
|
const payments = createPaymentsModule({ l1: this._l1Config });
|
|
18305
|
-
const communications = createCommunicationsModule();
|
|
18321
|
+
const communications = createCommunicationsModule(this._communicationsConfig);
|
|
18306
18322
|
const groupChat = this._groupChatConfig ? createGroupChatModule(this._groupChatConfig) : null;
|
|
18307
18323
|
const market = this._marketConfig ? createMarketModule(this._marketConfig) : null;
|
|
18308
18324
|
payments.initialize({
|