@xmtp/browser-sdk 5.1.0 → 5.2.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/index.d.ts +126 -23
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/dist/workers/utils.js +1 -1
- package/dist/workers/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/Client.ts +80 -2
- package/src/Conversation.ts +28 -8
- package/src/Conversations.ts +42 -4
- package/src/Utils.ts +20 -2
- package/src/WorkerClient.ts +8 -0
- package/src/WorkerConversation.ts +13 -4
- package/src/WorkerConversations.ts +13 -0
- package/src/constants.ts +3 -3
- package/src/index.ts +1 -0
- package/src/types/actions/client.ts +13 -1
- package/src/types/actions/conversation.ts +12 -0
- package/src/types/actions/conversations.ts +8 -0
- package/src/types/actions/preferences.ts +6 -2
- package/src/types/actions/streams.ts +5 -0
- package/src/types/actions/utils.ts +4 -0
- package/src/types/options.ts +4 -0
- package/src/utils/conversions.ts +50 -2
- package/src/utils/createClient.ts +3 -1
- package/src/utils/streams.ts +5 -0
- package/src/workers/client.ts +49 -2
- package/src/workers/utils.ts +21 -6
package/src/utils/conversions.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
ListMessagesOptions,
|
|
13
13
|
MessageDisappearingSettings,
|
|
14
14
|
PermissionPolicySet,
|
|
15
|
+
SendMessageOpts,
|
|
15
16
|
ContentTypeId as WasmContentTypeId,
|
|
16
17
|
EncodedContent as WasmEncodedContent,
|
|
17
18
|
type ApiStats,
|
|
@@ -28,7 +29,9 @@ import {
|
|
|
28
29
|
type InboxState,
|
|
29
30
|
type Installation,
|
|
30
31
|
type KeyPackageStatus,
|
|
32
|
+
type ListConversationsOrderBy,
|
|
31
33
|
type Message,
|
|
34
|
+
type MessageSortBy,
|
|
32
35
|
type PermissionLevel,
|
|
33
36
|
type PermissionPolicy,
|
|
34
37
|
type SortDirection,
|
|
@@ -155,9 +158,15 @@ export type SafeListMessagesOptions = {
|
|
|
155
158
|
contentTypes?: ContentType[];
|
|
156
159
|
deliveryStatus?: DeliveryStatus;
|
|
157
160
|
direction?: SortDirection;
|
|
161
|
+
excludeContentTypes?: ContentType[];
|
|
162
|
+
excludeSenderInboxIds?: string[];
|
|
163
|
+
insertedAfterNs?: bigint;
|
|
164
|
+
insertedBeforeNs?: bigint;
|
|
165
|
+
kind?: GroupMessageKind;
|
|
158
166
|
limit?: bigint;
|
|
159
167
|
sentAfterNs?: bigint;
|
|
160
168
|
sentBeforeNs?: bigint;
|
|
169
|
+
sortBy?: MessageSortBy;
|
|
161
170
|
};
|
|
162
171
|
|
|
163
172
|
export const toSafeListMessagesOptions = (
|
|
@@ -166,9 +175,15 @@ export const toSafeListMessagesOptions = (
|
|
|
166
175
|
contentTypes: options.contentTypes,
|
|
167
176
|
deliveryStatus: options.deliveryStatus,
|
|
168
177
|
direction: options.direction,
|
|
178
|
+
excludeContentTypes: options.excludeContentTypes,
|
|
179
|
+
excludeSenderInboxIds: options.excludeSenderInboxIds,
|
|
180
|
+
insertedAfterNs: options.insertedAfterNs,
|
|
181
|
+
insertedBeforeNs: options.insertedBeforeNs,
|
|
182
|
+
kind: options.kind,
|
|
169
183
|
limit: options.limit,
|
|
170
184
|
sentAfterNs: options.sentAfterNs,
|
|
171
185
|
sentBeforeNs: options.sentBeforeNs,
|
|
186
|
+
sortBy: options.sortBy,
|
|
172
187
|
});
|
|
173
188
|
|
|
174
189
|
export const fromSafeListMessagesOptions = (
|
|
@@ -181,8 +196,30 @@ export const fromSafeListMessagesOptions = (
|
|
|
181
196
|
options.deliveryStatus,
|
|
182
197
|
options.direction,
|
|
183
198
|
options.contentTypes,
|
|
199
|
+
options.excludeContentTypes,
|
|
200
|
+
options.kind,
|
|
201
|
+
options.excludeSenderInboxIds,
|
|
202
|
+
options.sortBy,
|
|
203
|
+
options.insertedAfterNs,
|
|
204
|
+
options.insertedBeforeNs,
|
|
184
205
|
);
|
|
185
206
|
|
|
207
|
+
export type SafeSendMessageOpts = {
|
|
208
|
+
shouldPush: boolean;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export const toSafeSendMessageOpts = (
|
|
212
|
+
opts: SendMessageOpts,
|
|
213
|
+
): SafeSendMessageOpts => ({
|
|
214
|
+
shouldPush: opts.shouldPush,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
export const fromSafeSendMessageOpts = (
|
|
218
|
+
opts: SafeSendMessageOpts,
|
|
219
|
+
): SendMessageOpts => {
|
|
220
|
+
return new SendMessageOpts(opts.shouldPush);
|
|
221
|
+
};
|
|
222
|
+
|
|
186
223
|
export type SafeListConversationsOptions = {
|
|
187
224
|
consentStates?: ConsentState[];
|
|
188
225
|
conversationType?: ConversationType;
|
|
@@ -190,6 +227,7 @@ export type SafeListConversationsOptions = {
|
|
|
190
227
|
createdBeforeNs?: bigint;
|
|
191
228
|
includeDuplicateDms?: boolean;
|
|
192
229
|
limit?: bigint;
|
|
230
|
+
orderBy?: ListConversationsOrderBy;
|
|
193
231
|
};
|
|
194
232
|
|
|
195
233
|
export const toSafeListConversationsOptions = (
|
|
@@ -201,6 +239,7 @@ export const toSafeListConversationsOptions = (
|
|
|
201
239
|
createdBeforeNs: options.createdBeforeNs,
|
|
202
240
|
includeDuplicateDms: options.includeDuplicateDms,
|
|
203
241
|
limit: options.limit,
|
|
242
|
+
orderBy: options.orderBy,
|
|
204
243
|
});
|
|
205
244
|
|
|
206
245
|
export const fromSafeListConversationsOptions = (
|
|
@@ -213,6 +252,7 @@ export const fromSafeListConversationsOptions = (
|
|
|
213
252
|
options.createdBeforeNs,
|
|
214
253
|
options.includeDuplicateDms ?? false,
|
|
215
254
|
options.limit,
|
|
255
|
+
options.orderBy,
|
|
216
256
|
);
|
|
217
257
|
|
|
218
258
|
export type SafePermissionPolicySet = {
|
|
@@ -506,6 +546,11 @@ export const toSafeKeyPackageStatus = (
|
|
|
506
546
|
validationError: status.validationError,
|
|
507
547
|
});
|
|
508
548
|
|
|
549
|
+
export type SafeXMTPCursor = {
|
|
550
|
+
originatorID: number;
|
|
551
|
+
sequenceID: bigint;
|
|
552
|
+
};
|
|
553
|
+
|
|
509
554
|
export type SafeConversationDebugInfo = {
|
|
510
555
|
epoch: bigint;
|
|
511
556
|
maybeForked: boolean;
|
|
@@ -513,7 +558,7 @@ export type SafeConversationDebugInfo = {
|
|
|
513
558
|
isCommitLogForked?: boolean;
|
|
514
559
|
localCommitLog: string;
|
|
515
560
|
remoteCommitLog: string;
|
|
516
|
-
cursor:
|
|
561
|
+
cursor: SafeXMTPCursor[];
|
|
517
562
|
};
|
|
518
563
|
|
|
519
564
|
export const toSafeConversationDebugInfo = (
|
|
@@ -525,7 +570,10 @@ export const toSafeConversationDebugInfo = (
|
|
|
525
570
|
isCommitLogForked: debugInfo.isCommitLogForked,
|
|
526
571
|
localCommitLog: debugInfo.localCommitLog,
|
|
527
572
|
remoteCommitLog: debugInfo.remoteCommitLog,
|
|
528
|
-
cursor: debugInfo.cursor
|
|
573
|
+
cursor: debugInfo.cursor.map((cursor) => ({
|
|
574
|
+
originatorID: cursor.originator_id,
|
|
575
|
+
sequenceID: cursor.sequence_id,
|
|
576
|
+
})),
|
|
529
577
|
});
|
|
530
578
|
|
|
531
579
|
export type SafeApiStats = {
|
|
@@ -14,8 +14,9 @@ export const createClient = async (
|
|
|
14
14
|
) => {
|
|
15
15
|
const env = options?.env || "dev";
|
|
16
16
|
const host = options?.apiUrl || ApiUrls[env];
|
|
17
|
+
const gatewayHost = options?.gatewayHost ?? null;
|
|
17
18
|
const inboxId =
|
|
18
|
-
(await getInboxIdForIdentifier(host, identifier)) ||
|
|
19
|
+
(await getInboxIdForIdentifier(host, gatewayHost, identifier)) ||
|
|
19
20
|
generateInboxId(identifier);
|
|
20
21
|
const dbPath =
|
|
21
22
|
options?.dbPath === undefined
|
|
@@ -54,5 +55,6 @@ export const createClient = async (
|
|
|
54
55
|
undefined,
|
|
55
56
|
options?.debugEventsEnabled,
|
|
56
57
|
options?.appVersion,
|
|
58
|
+
options?.gatewayHost,
|
|
57
59
|
);
|
|
58
60
|
};
|
package/src/utils/streams.ts
CHANGED
|
@@ -55,6 +55,11 @@ export type StreamOptions<T = unknown, V = T> = {
|
|
|
55
55
|
* (default: true)
|
|
56
56
|
*/
|
|
57
57
|
retryOnFail?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Whether to disable network sync before starting the stream
|
|
60
|
+
* (default: false)
|
|
61
|
+
*/
|
|
62
|
+
disableSync?: boolean;
|
|
58
63
|
};
|
|
59
64
|
|
|
60
65
|
export type StreamCallback<T = unknown> = (
|
package/src/workers/client.ts
CHANGED
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
import {
|
|
22
22
|
fromEncodedContent,
|
|
23
23
|
fromSafeEncodedContent,
|
|
24
|
+
fromSafeSendMessageOpts,
|
|
24
25
|
toSafeApiStats,
|
|
25
26
|
toSafeConsent,
|
|
26
27
|
toSafeConversation,
|
|
@@ -203,10 +204,12 @@ self.onmessage = async (
|
|
|
203
204
|
const signatureRequest =
|
|
204
205
|
await client.revokeAllOtherInstallationsSignatureRequest();
|
|
205
206
|
const result = {
|
|
206
|
-
signatureText: await signatureRequest
|
|
207
|
+
signatureText: await signatureRequest?.signatureText(),
|
|
207
208
|
signatureRequestId: data.signatureRequestId,
|
|
208
209
|
};
|
|
209
|
-
|
|
210
|
+
if (signatureRequest) {
|
|
211
|
+
signatureRequests.set(data.signatureRequestId, signatureRequest);
|
|
212
|
+
}
|
|
210
213
|
postMessage({ id, action, result });
|
|
211
214
|
break;
|
|
212
215
|
}
|
|
@@ -350,6 +353,16 @@ self.onmessage = async (
|
|
|
350
353
|
});
|
|
351
354
|
break;
|
|
352
355
|
}
|
|
356
|
+
case "client.libxmtpVersion": {
|
|
357
|
+
const result = client.libxmtpVersion;
|
|
358
|
+
postMessage({ id, action, result });
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
case "client.appVersion": {
|
|
362
|
+
const result = client.appVersion;
|
|
363
|
+
postMessage({ id, action, result });
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
353
366
|
/**
|
|
354
367
|
* Debug information actions
|
|
355
368
|
*/
|
|
@@ -597,6 +610,32 @@ self.onmessage = async (
|
|
|
597
610
|
postMessage({ id, action, result: undefined });
|
|
598
611
|
break;
|
|
599
612
|
}
|
|
613
|
+
case "conversations.streamMessageDeletions": {
|
|
614
|
+
const streamCallback = (
|
|
615
|
+
error: Error | null,
|
|
616
|
+
value: string | undefined,
|
|
617
|
+
) => {
|
|
618
|
+
if (error) {
|
|
619
|
+
streamClosers.delete(data.streamId);
|
|
620
|
+
postStreamMessageError({
|
|
621
|
+
action: "stream.messageDeleted",
|
|
622
|
+
streamId: data.streamId,
|
|
623
|
+
error,
|
|
624
|
+
});
|
|
625
|
+
} else {
|
|
626
|
+
postStreamMessage({
|
|
627
|
+
action: "stream.messageDeleted",
|
|
628
|
+
streamId: data.streamId,
|
|
629
|
+
result: value,
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
const streamCloser =
|
|
634
|
+
client.conversations.streamMessageDeletions(streamCallback);
|
|
635
|
+
streamClosers.set(data.streamId, streamCloser);
|
|
636
|
+
postMessage({ id, action, result: undefined });
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
600
639
|
case "conversations.list": {
|
|
601
640
|
const conversations = client.conversations.list(data.options);
|
|
602
641
|
const result = await Promise.all(
|
|
@@ -768,6 +807,7 @@ self.onmessage = async (
|
|
|
768
807
|
const group = getGroup(data.id);
|
|
769
808
|
const result = await group.send(
|
|
770
809
|
fromEncodedContent(fromSafeEncodedContent(data.content)),
|
|
810
|
+
fromSafeSendMessageOpts(data.sendOptions),
|
|
771
811
|
);
|
|
772
812
|
postMessage({ id, action, result });
|
|
773
813
|
break;
|
|
@@ -776,6 +816,7 @@ self.onmessage = async (
|
|
|
776
816
|
const group = getGroup(data.id);
|
|
777
817
|
const result = group.sendOptimistic(
|
|
778
818
|
fromEncodedContent(fromSafeEncodedContent(data.content)),
|
|
819
|
+
fromSafeSendMessageOpts(data.sendOptions),
|
|
779
820
|
);
|
|
780
821
|
postMessage({ id, action, result });
|
|
781
822
|
break;
|
|
@@ -793,6 +834,12 @@ self.onmessage = async (
|
|
|
793
834
|
postMessage({ id, action, result });
|
|
794
835
|
break;
|
|
795
836
|
}
|
|
837
|
+
case "conversation.countMessages": {
|
|
838
|
+
const group = getGroup(data.id);
|
|
839
|
+
const result = await group.countMessages(data.options);
|
|
840
|
+
postMessage({ id, action, result });
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
796
843
|
case "conversation.members": {
|
|
797
844
|
const group = getGroup(data.id);
|
|
798
845
|
const result = await group.members();
|
package/src/workers/utils.ts
CHANGED
|
@@ -39,9 +39,10 @@ const postMessageError = (data: ActionErrorData<UtilsWorkerAction>) => {
|
|
|
39
39
|
const getInboxIdForIdentifier = async (
|
|
40
40
|
identifier: Identifier,
|
|
41
41
|
env?: XmtpEnv,
|
|
42
|
+
gatewayHost?: string,
|
|
42
43
|
) => {
|
|
43
44
|
const host = env ? ApiUrls[env] : ApiUrls.dev;
|
|
44
|
-
return get_inbox_id_for_identifier(host, identifier);
|
|
45
|
+
return get_inbox_id_for_identifier(host, gatewayHost ?? null, identifier);
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
let enableLogging = false;
|
|
@@ -75,14 +76,19 @@ self.onmessage = async (
|
|
|
75
76
|
break;
|
|
76
77
|
}
|
|
77
78
|
case "utils.getInboxIdForIdentifier": {
|
|
78
|
-
const result = await getInboxIdForIdentifier(
|
|
79
|
+
const result = await getInboxIdForIdentifier(
|
|
80
|
+
data.identifier,
|
|
81
|
+
data.env,
|
|
82
|
+
data.gatewayHost,
|
|
83
|
+
);
|
|
79
84
|
postMessage({ id, action, result });
|
|
80
85
|
break;
|
|
81
86
|
}
|
|
82
87
|
case "utils.revokeInstallationsSignatureText": {
|
|
83
88
|
const host = ApiUrls[data.env ?? "dev"];
|
|
84
|
-
const signatureRequest =
|
|
89
|
+
const signatureRequest = revokeInstallationsSignatureRequest(
|
|
85
90
|
host,
|
|
91
|
+
data.gatewayHost,
|
|
86
92
|
data.identifier,
|
|
87
93
|
data.inboxId,
|
|
88
94
|
data.installationIds,
|
|
@@ -115,15 +121,24 @@ self.onmessage = async (
|
|
|
115
121
|
);
|
|
116
122
|
break;
|
|
117
123
|
}
|
|
118
|
-
await applySignatureRequest(
|
|
124
|
+
await applySignatureRequest(
|
|
125
|
+
host,
|
|
126
|
+
data.gatewayHost ?? null,
|
|
127
|
+
signatureRequest,
|
|
128
|
+
);
|
|
119
129
|
signatureRequests.delete(data.signatureRequestId);
|
|
120
|
-
postMessage({ id, action, result:
|
|
130
|
+
postMessage({ id, action, result: [] });
|
|
121
131
|
break;
|
|
122
132
|
}
|
|
133
|
+
|
|
123
134
|
case "utils.inboxStateFromInboxIds": {
|
|
124
135
|
const host = ApiUrls[data.env ?? "dev"];
|
|
125
136
|
try {
|
|
126
|
-
const inboxStates = await inboxStateFromInboxIds(
|
|
137
|
+
const inboxStates = await inboxStateFromInboxIds(
|
|
138
|
+
host,
|
|
139
|
+
data.gatewayHost ?? null,
|
|
140
|
+
data.inboxIds,
|
|
141
|
+
);
|
|
127
142
|
const result = inboxStates.map((inboxState) =>
|
|
128
143
|
toSafeInboxState(inboxState),
|
|
129
144
|
);
|