@xmtp/browser-sdk 2.0.13 → 2.1.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.
- package/dist/index.d.ts +849 -678
- 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 +9 -11
- package/src/Client.ts +71 -31
- package/src/ClientWorkerClass.ts +62 -19
- package/src/Conversation.ts +60 -33
- package/src/Conversations.ts +96 -48
- package/src/DecodedMessage.ts +8 -5
- package/src/Dm.ts +14 -4
- package/src/Group.ts +27 -20
- package/src/Preferences.ts +21 -10
- package/src/Utils.ts +2 -2
- package/src/UtilsWorkerClass.ts +56 -15
- package/src/WorkerClient.ts +25 -3
- package/src/WorkerConversation.ts +11 -2
- package/src/WorkerConversations.ts +19 -4
- package/src/WorkerPreferences.ts +4 -0
- package/src/index.ts +3 -1
- package/src/types/actions/client.ts +181 -0
- package/src/types/actions/conversation.ts +146 -0
- package/src/types/actions/conversations.ts +146 -0
- package/src/types/actions/dm.ts +19 -0
- package/src/types/actions/group.ts +161 -0
- package/src/types/actions/preferences.ts +68 -0
- package/src/types/actions/streams.ts +44 -0
- package/src/types/actions/utils.ts +29 -0
- package/src/types/actions.ts +75 -0
- package/src/types/options.ts +18 -0
- package/src/utils/conversions.ts +60 -0
- package/src/utils/createClient.ts +6 -1
- package/src/utils/errors.ts +3 -1
- package/src/workers/client.ts +243 -190
- package/src/workers/utils.ts +25 -29
- package/src/types/clientEvents.ts +0 -693
- package/src/types/clientStreamEvents.ts +0 -45
- package/src/types/index.ts +0 -4
- package/src/types/utils.ts +0 -72
- package/src/types/utilsEvents.ts +0 -60
package/src/Group.ts
CHANGED
|
@@ -13,9 +13,9 @@ import type { SafeConversation } from "@/utils/conversions";
|
|
|
13
13
|
*
|
|
14
14
|
* This class is not intended to be initialized directly.
|
|
15
15
|
*/
|
|
16
|
-
export class Group extends Conversation {
|
|
16
|
+
export class Group<ContentTypes = unknown> extends Conversation<ContentTypes> {
|
|
17
17
|
#admins: SafeConversation["admins"] = [];
|
|
18
|
-
#client: Client
|
|
18
|
+
#client: Client<ContentTypes>;
|
|
19
19
|
#description?: SafeConversation["description"];
|
|
20
20
|
#id: string;
|
|
21
21
|
#imageUrl?: SafeConversation["imageUrl"];
|
|
@@ -37,7 +37,11 @@ export class Group extends Conversation {
|
|
|
37
37
|
* @param id - Identifier for the group conversation
|
|
38
38
|
* @param data - Optional conversation data to initialize with
|
|
39
39
|
*/
|
|
40
|
-
constructor(
|
|
40
|
+
constructor(
|
|
41
|
+
client: Client<ContentTypes>,
|
|
42
|
+
id: string,
|
|
43
|
+
data?: SafeConversation,
|
|
44
|
+
) {
|
|
41
45
|
super(client, id, data);
|
|
42
46
|
this.#client = client;
|
|
43
47
|
this.#id = id;
|
|
@@ -68,7 +72,7 @@ export class Group extends Conversation {
|
|
|
68
72
|
* @param name The new name for the group
|
|
69
73
|
*/
|
|
70
74
|
async updateName(name: string) {
|
|
71
|
-
await this.#client.sendMessage("
|
|
75
|
+
await this.#client.sendMessage("group.updateName", {
|
|
72
76
|
id: this.#id,
|
|
73
77
|
name,
|
|
74
78
|
});
|
|
@@ -88,7 +92,7 @@ export class Group extends Conversation {
|
|
|
88
92
|
* @param imageUrl The new image URL for the group
|
|
89
93
|
*/
|
|
90
94
|
async updateImageUrl(imageUrl: string) {
|
|
91
|
-
await this.#client.sendMessage("
|
|
95
|
+
await this.#client.sendMessage("group.updateImageUrl", {
|
|
92
96
|
id: this.#id,
|
|
93
97
|
imageUrl,
|
|
94
98
|
});
|
|
@@ -108,7 +112,7 @@ export class Group extends Conversation {
|
|
|
108
112
|
* @param description The new description for the group
|
|
109
113
|
*/
|
|
110
114
|
async updateDescription(description: string) {
|
|
111
|
-
await this.#client.sendMessage("
|
|
115
|
+
await this.#client.sendMessage("group.updateDescription", {
|
|
112
116
|
id: this.#id,
|
|
113
117
|
description,
|
|
114
118
|
});
|
|
@@ -135,7 +139,7 @@ export class Group extends Conversation {
|
|
|
135
139
|
* @returns Array of admin inbox IDs
|
|
136
140
|
*/
|
|
137
141
|
async listAdmins() {
|
|
138
|
-
const admins = await this.#client.sendMessage("
|
|
142
|
+
const admins = await this.#client.sendMessage("group.listAdmins", {
|
|
139
143
|
id: this.#id,
|
|
140
144
|
});
|
|
141
145
|
this.#admins = admins;
|
|
@@ -148,9 +152,12 @@ export class Group extends Conversation {
|
|
|
148
152
|
* @returns Array of super admin inbox IDs
|
|
149
153
|
*/
|
|
150
154
|
async listSuperAdmins() {
|
|
151
|
-
const superAdmins = await this.#client.sendMessage(
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
const superAdmins = await this.#client.sendMessage(
|
|
156
|
+
"group.listSuperAdmins",
|
|
157
|
+
{
|
|
158
|
+
id: this.#id,
|
|
159
|
+
},
|
|
160
|
+
);
|
|
154
161
|
this.#superAdmins = superAdmins;
|
|
155
162
|
return superAdmins;
|
|
156
163
|
}
|
|
@@ -161,7 +168,7 @@ export class Group extends Conversation {
|
|
|
161
168
|
* @returns The group's permissions
|
|
162
169
|
*/
|
|
163
170
|
async permissions() {
|
|
164
|
-
return this.#client.sendMessage("
|
|
171
|
+
return this.#client.sendMessage("group.permissions", {
|
|
165
172
|
id: this.#id,
|
|
166
173
|
});
|
|
167
174
|
}
|
|
@@ -178,7 +185,7 @@ export class Group extends Conversation {
|
|
|
178
185
|
policy: PermissionPolicy,
|
|
179
186
|
metadataField?: MetadataField,
|
|
180
187
|
) {
|
|
181
|
-
return this.#client.sendMessage("
|
|
188
|
+
return this.#client.sendMessage("group.updatePermission", {
|
|
182
189
|
id: this.#id,
|
|
183
190
|
permissionType,
|
|
184
191
|
policy,
|
|
@@ -214,7 +221,7 @@ export class Group extends Conversation {
|
|
|
214
221
|
* @param identifiers Array of member identifiers to add
|
|
215
222
|
*/
|
|
216
223
|
async addMembersByIdentifiers(identifiers: Identifier[]) {
|
|
217
|
-
return this.#client.sendMessage("
|
|
224
|
+
return this.#client.sendMessage("group.addMembersByIdentifiers", {
|
|
218
225
|
id: this.#id,
|
|
219
226
|
identifiers,
|
|
220
227
|
});
|
|
@@ -226,7 +233,7 @@ export class Group extends Conversation {
|
|
|
226
233
|
* @param inboxIds Array of inbox IDs to add
|
|
227
234
|
*/
|
|
228
235
|
async addMembers(inboxIds: string[]) {
|
|
229
|
-
return this.#client.sendMessage("
|
|
236
|
+
return this.#client.sendMessage("group.addMembers", {
|
|
230
237
|
id: this.#id,
|
|
231
238
|
inboxIds,
|
|
232
239
|
});
|
|
@@ -238,7 +245,7 @@ export class Group extends Conversation {
|
|
|
238
245
|
* @param identifiers Array of member identifiers to remove
|
|
239
246
|
*/
|
|
240
247
|
async removeMembersByIdentifiers(identifiers: Identifier[]) {
|
|
241
|
-
return this.#client.sendMessage("
|
|
248
|
+
return this.#client.sendMessage("group.removeMembersByIdentifiers", {
|
|
242
249
|
id: this.#id,
|
|
243
250
|
identifiers,
|
|
244
251
|
});
|
|
@@ -250,7 +257,7 @@ export class Group extends Conversation {
|
|
|
250
257
|
* @param inboxIds Array of inbox IDs to remove
|
|
251
258
|
*/
|
|
252
259
|
async removeMembers(inboxIds: string[]) {
|
|
253
|
-
return this.#client.sendMessage("
|
|
260
|
+
return this.#client.sendMessage("group.removeMembers", {
|
|
254
261
|
id: this.#id,
|
|
255
262
|
inboxIds,
|
|
256
263
|
});
|
|
@@ -262,7 +269,7 @@ export class Group extends Conversation {
|
|
|
262
269
|
* @param inboxId The inbox ID of the member to promote
|
|
263
270
|
*/
|
|
264
271
|
async addAdmin(inboxId: string) {
|
|
265
|
-
return this.#client.sendMessage("
|
|
272
|
+
return this.#client.sendMessage("group.addAdmin", {
|
|
266
273
|
id: this.#id,
|
|
267
274
|
inboxId,
|
|
268
275
|
});
|
|
@@ -274,7 +281,7 @@ export class Group extends Conversation {
|
|
|
274
281
|
* @param inboxId The inbox ID of the admin to demote
|
|
275
282
|
*/
|
|
276
283
|
async removeAdmin(inboxId: string) {
|
|
277
|
-
return this.#client.sendMessage("
|
|
284
|
+
return this.#client.sendMessage("group.removeAdmin", {
|
|
278
285
|
id: this.#id,
|
|
279
286
|
inboxId,
|
|
280
287
|
});
|
|
@@ -286,7 +293,7 @@ export class Group extends Conversation {
|
|
|
286
293
|
* @param inboxId The inbox ID of the member to promote
|
|
287
294
|
*/
|
|
288
295
|
async addSuperAdmin(inboxId: string) {
|
|
289
|
-
return this.#client.sendMessage("
|
|
296
|
+
return this.#client.sendMessage("group.addSuperAdmin", {
|
|
290
297
|
id: this.#id,
|
|
291
298
|
inboxId,
|
|
292
299
|
});
|
|
@@ -298,7 +305,7 @@ export class Group extends Conversation {
|
|
|
298
305
|
* @param inboxId The inbox ID of the super admin to demote
|
|
299
306
|
*/
|
|
300
307
|
async removeSuperAdmin(inboxId: string) {
|
|
301
|
-
return this.#client.sendMessage("
|
|
308
|
+
return this.#client.sendMessage("group.removeSuperAdmin", {
|
|
302
309
|
id: this.#id,
|
|
303
310
|
inboxId,
|
|
304
311
|
});
|
package/src/Preferences.ts
CHANGED
|
@@ -9,18 +9,22 @@ import type { Client } from "./Client";
|
|
|
9
9
|
*
|
|
10
10
|
* This class is not intended to be initialized directly.
|
|
11
11
|
*/
|
|
12
|
-
export class Preferences {
|
|
13
|
-
#client: Client
|
|
12
|
+
export class Preferences<ContentTypes = unknown> {
|
|
13
|
+
#client: Client<ContentTypes>;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Creates a new preferences instance
|
|
17
17
|
*
|
|
18
18
|
* @param client - The client instance managing preferences
|
|
19
19
|
*/
|
|
20
|
-
constructor(client: Client) {
|
|
20
|
+
constructor(client: Client<ContentTypes>) {
|
|
21
21
|
this.#client = client;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
sync() {
|
|
25
|
+
return this.#client.sendMessage("preferences.sync", undefined);
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
29
|
* Retrieves the current inbox state
|
|
26
30
|
*
|
|
@@ -28,7 +32,7 @@ export class Preferences {
|
|
|
28
32
|
* @returns Promise that resolves with the inbox state
|
|
29
33
|
*/
|
|
30
34
|
async inboxState(refreshFromNetwork?: boolean) {
|
|
31
|
-
return this.#client.sendMessage("inboxState", {
|
|
35
|
+
return this.#client.sendMessage("preferences.inboxState", {
|
|
32
36
|
refreshFromNetwork: refreshFromNetwork ?? false,
|
|
33
37
|
});
|
|
34
38
|
}
|
|
@@ -44,7 +48,7 @@ export class Preferences {
|
|
|
44
48
|
inboxIds: string[],
|
|
45
49
|
refreshFromNetwork?: boolean,
|
|
46
50
|
) {
|
|
47
|
-
return this.#client.sendMessage("inboxStateFromInboxIds", {
|
|
51
|
+
return this.#client.sendMessage("preferences.inboxStateFromInboxIds", {
|
|
48
52
|
inboxIds,
|
|
49
53
|
refreshFromNetwork: refreshFromNetwork ?? false,
|
|
50
54
|
});
|
|
@@ -57,7 +61,9 @@ export class Preferences {
|
|
|
57
61
|
* @returns Promise that resolves with the latest inbox state
|
|
58
62
|
*/
|
|
59
63
|
async getLatestInboxState(inboxId: string) {
|
|
60
|
-
return this.#client.sendMessage("getLatestInboxState", {
|
|
64
|
+
return this.#client.sendMessage("preferences.getLatestInboxState", {
|
|
65
|
+
inboxId,
|
|
66
|
+
});
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
/**
|
|
@@ -67,7 +73,9 @@ export class Preferences {
|
|
|
67
73
|
* @returns Promise that resolves when consent states are updated
|
|
68
74
|
*/
|
|
69
75
|
async setConsentStates(records: SafeConsent[]) {
|
|
70
|
-
return this.#client.sendMessage("setConsentStates", {
|
|
76
|
+
return this.#client.sendMessage("preferences.setConsentStates", {
|
|
77
|
+
records,
|
|
78
|
+
});
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
/**
|
|
@@ -78,7 +86,10 @@ export class Preferences {
|
|
|
78
86
|
* @returns Promise that resolves with the consent state
|
|
79
87
|
*/
|
|
80
88
|
async getConsentState(entityType: ConsentEntityType, entity: string) {
|
|
81
|
-
return this.#client.sendMessage("getConsentState", {
|
|
89
|
+
return this.#client.sendMessage("preferences.getConsentState", {
|
|
90
|
+
entityType,
|
|
91
|
+
entity,
|
|
92
|
+
});
|
|
82
93
|
}
|
|
83
94
|
|
|
84
95
|
/**
|
|
@@ -97,7 +108,7 @@ export class Preferences {
|
|
|
97
108
|
void callback?.(error, value ?? undefined);
|
|
98
109
|
},
|
|
99
110
|
);
|
|
100
|
-
await this.#client.sendMessage("streamConsent", {
|
|
111
|
+
await this.#client.sendMessage("preferences.streamConsent", {
|
|
101
112
|
streamId,
|
|
102
113
|
});
|
|
103
114
|
asyncStream.onReturn = () => {
|
|
@@ -125,7 +136,7 @@ export class Preferences {
|
|
|
125
136
|
void callback?.(error, value ?? undefined);
|
|
126
137
|
},
|
|
127
138
|
);
|
|
128
|
-
await this.#client.sendMessage("streamPreferences", {
|
|
139
|
+
await this.#client.sendMessage("preferences.streamPreferences", {
|
|
129
140
|
streamId,
|
|
130
141
|
});
|
|
131
142
|
asyncStream.onReturn = () => {
|
package/src/Utils.ts
CHANGED
|
@@ -25,7 +25,7 @@ export class Utils extends UtilsWorkerClass {
|
|
|
25
25
|
* @returns Promise that resolves with the generated inbox ID
|
|
26
26
|
*/
|
|
27
27
|
async generateInboxId(identifier: Identifier) {
|
|
28
|
-
return this.sendMessage("generateInboxId", {
|
|
28
|
+
return this.sendMessage("utils.generateInboxId", {
|
|
29
29
|
identifier,
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -38,7 +38,7 @@ export class Utils extends UtilsWorkerClass {
|
|
|
38
38
|
* @returns Promise that resolves with the inbox ID for the identifier
|
|
39
39
|
*/
|
|
40
40
|
async getInboxIdForIdentifier(identifier: Identifier, env?: XmtpEnv) {
|
|
41
|
-
return this.sendMessage("getInboxIdForIdentifier", {
|
|
41
|
+
return this.sendMessage("utils.getInboxIdForIdentifier", {
|
|
42
42
|
identifier,
|
|
43
43
|
env,
|
|
44
44
|
});
|
package/src/UtilsWorkerClass.ts
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import { v4 } from "uuid";
|
|
2
2
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "@/types";
|
|
3
|
+
ActionErrorData,
|
|
4
|
+
ActionName,
|
|
5
|
+
ActionWithoutData,
|
|
6
|
+
ExtractActionData,
|
|
7
|
+
ExtractActionResult,
|
|
8
|
+
} from "@/types/actions";
|
|
9
|
+
import type { UtilsWorkerAction } from "@/types/actions/utils";
|
|
9
10
|
|
|
10
11
|
const handleError = (event: ErrorEvent) => {
|
|
11
|
-
console.error(`Worker error on line ${event.lineno} in "${event.filename}"`);
|
|
12
12
|
console.error(event.message);
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Class that sets up a worker and provides communications for utility functions
|
|
17
|
+
*
|
|
18
|
+
* This class is not meant to be used directly, it is extended by the Utils class
|
|
19
|
+
* to provide an interface to the worker.
|
|
20
|
+
*
|
|
21
|
+
* @param worker - The worker to use for the utils class
|
|
22
|
+
* @param enableLogging - Whether to enable logging in the worker
|
|
23
|
+
* @returns A new UtilsWorkerClass instance
|
|
24
|
+
*/
|
|
15
25
|
export class UtilsWorkerClass {
|
|
16
26
|
#worker: Worker;
|
|
17
27
|
|
|
@@ -25,20 +35,35 @@ export class UtilsWorkerClass {
|
|
|
25
35
|
constructor(worker: Worker, enableLogging: boolean) {
|
|
26
36
|
this.#worker = worker;
|
|
27
37
|
this.#worker.addEventListener("message", this.handleMessage);
|
|
28
|
-
|
|
38
|
+
if (enableLogging) {
|
|
39
|
+
this.#worker.addEventListener("error", handleError);
|
|
40
|
+
}
|
|
29
41
|
this.#enableLogging = enableLogging;
|
|
30
42
|
void this.init(enableLogging);
|
|
31
43
|
}
|
|
32
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Initializes the utils worker
|
|
47
|
+
*
|
|
48
|
+
* @param enableLogging - Whether to enable logging in the worker
|
|
49
|
+
* @returns A promise that resolves when the worker is initialized
|
|
50
|
+
*/
|
|
33
51
|
async init(enableLogging: boolean) {
|
|
34
|
-
return this.sendMessage("init", {
|
|
52
|
+
return this.sendMessage("utils.init", {
|
|
35
53
|
enableLogging,
|
|
36
54
|
});
|
|
37
55
|
}
|
|
38
56
|
|
|
39
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Sends an action message to the utils worker
|
|
59
|
+
*
|
|
60
|
+
* @param action - The action to send to the worker
|
|
61
|
+
* @param data - The data to send to the worker
|
|
62
|
+
* @returns A promise that resolves when the action is completed
|
|
63
|
+
*/
|
|
64
|
+
sendMessage<A extends ActionName<UtilsWorkerAction>>(
|
|
40
65
|
action: A,
|
|
41
|
-
data:
|
|
66
|
+
data: ExtractActionData<UtilsWorkerAction, A>,
|
|
42
67
|
) {
|
|
43
68
|
const promiseId = v4();
|
|
44
69
|
this.#worker.postMessage({
|
|
@@ -46,17 +71,28 @@ export class UtilsWorkerClass {
|
|
|
46
71
|
id: promiseId,
|
|
47
72
|
data,
|
|
48
73
|
});
|
|
49
|
-
const promise = new Promise
|
|
74
|
+
const promise = new Promise((resolve, reject) => {
|
|
50
75
|
this.#promises.set(promiseId, {
|
|
51
76
|
resolve: resolve as (value: unknown) => void,
|
|
52
77
|
reject,
|
|
53
78
|
});
|
|
54
79
|
});
|
|
55
|
-
return promise
|
|
80
|
+
return promise as [ExtractActionResult<UtilsWorkerAction, A>] extends [
|
|
81
|
+
undefined,
|
|
82
|
+
]
|
|
83
|
+
? Promise<void>
|
|
84
|
+
: Promise<ExtractActionResult<UtilsWorkerAction, A>>;
|
|
56
85
|
}
|
|
57
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Handles a message from the utils worker
|
|
89
|
+
*
|
|
90
|
+
* @param event - The event to handle
|
|
91
|
+
*/
|
|
58
92
|
handleMessage = (
|
|
59
|
-
event: MessageEvent<
|
|
93
|
+
event: MessageEvent<
|
|
94
|
+
ActionWithoutData<UtilsWorkerAction> | ActionErrorData<UtilsWorkerAction>
|
|
95
|
+
>,
|
|
60
96
|
) => {
|
|
61
97
|
const eventData = event.data;
|
|
62
98
|
if (this.#enableLogging) {
|
|
@@ -73,9 +109,14 @@ export class UtilsWorkerClass {
|
|
|
73
109
|
}
|
|
74
110
|
};
|
|
75
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Removes all event listeners and terminates the worker
|
|
114
|
+
*/
|
|
76
115
|
close() {
|
|
77
116
|
this.#worker.removeEventListener("message", this.handleMessage);
|
|
78
|
-
this.#
|
|
117
|
+
if (this.#enableLogging) {
|
|
118
|
+
this.#worker.removeEventListener("error", handleError);
|
|
119
|
+
}
|
|
79
120
|
this.#worker.terminate();
|
|
80
121
|
}
|
|
81
122
|
}
|
package/src/WorkerClient.ts
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
type KeyPackageStatus,
|
|
6
6
|
type SignatureRequestType,
|
|
7
7
|
} from "@xmtp/wasm-bindings";
|
|
8
|
-
import
|
|
8
|
+
import { HistorySyncUrls } from "@/constants";
|
|
9
|
+
import type { ClientOptions } from "@/types/options";
|
|
9
10
|
import { createClient } from "@/utils/createClient";
|
|
10
11
|
import { WorkerConversations } from "@/WorkerConversations";
|
|
11
12
|
import { WorkerPreferences } from "@/WorkerPreferences";
|
|
@@ -13,13 +14,15 @@ import { WorkerPreferences } from "@/WorkerPreferences";
|
|
|
13
14
|
export class WorkerClient {
|
|
14
15
|
#client: Client;
|
|
15
16
|
#conversations: WorkerConversations;
|
|
17
|
+
#options?: ClientOptions;
|
|
16
18
|
#preferences: WorkerPreferences;
|
|
17
19
|
|
|
18
|
-
constructor(client: Client) {
|
|
20
|
+
constructor(client: Client, options?: ClientOptions) {
|
|
19
21
|
this.#client = client;
|
|
20
22
|
const conversations = client.conversations();
|
|
21
23
|
this.#conversations = new WorkerConversations(this, conversations);
|
|
22
24
|
this.#preferences = new WorkerPreferences(client, conversations);
|
|
25
|
+
this.#options = options;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
static async create(
|
|
@@ -27,7 +30,7 @@ export class WorkerClient {
|
|
|
27
30
|
options?: Omit<ClientOptions, "codecs">,
|
|
28
31
|
) {
|
|
29
32
|
const client = await createClient(identifier, options);
|
|
30
|
-
return new WorkerClient(client);
|
|
33
|
+
return new WorkerClient(client, options);
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
get accountIdentifier() {
|
|
@@ -178,4 +181,23 @@ export class WorkerClient {
|
|
|
178
181
|
installationIds,
|
|
179
182
|
) as Promise<Map<string, KeyPackageStatus>>;
|
|
180
183
|
}
|
|
184
|
+
|
|
185
|
+
apiStatistics() {
|
|
186
|
+
return this.#client.apiStatistics();
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
apiIdentityStatistics() {
|
|
190
|
+
return this.#client.apiIdentityStatistics();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
apiAggregateStatistics() {
|
|
194
|
+
return this.#client.apiAggregateStatistics();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async uploadDebugArchive(serverUrl?: string) {
|
|
198
|
+
const env = this.#options?.env || "dev";
|
|
199
|
+
const historySyncUrl =
|
|
200
|
+
this.#options?.historySyncUrl || HistorySyncUrls[env];
|
|
201
|
+
return this.#client.uploadDebugArchive(serverUrl || historySyncUrl);
|
|
202
|
+
}
|
|
181
203
|
}
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
MessageDisappearingSettings,
|
|
3
3
|
type ConsentState,
|
|
4
4
|
type Conversation,
|
|
5
|
+
type ConversationDebugInfo,
|
|
5
6
|
type EncodedContent,
|
|
6
7
|
type GroupMember,
|
|
7
8
|
type HmacKey,
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
import type { WorkerClient } from "@/WorkerClient";
|
|
21
22
|
|
|
22
23
|
export class WorkerConversation {
|
|
23
|
-
// eslint-disable-next-line no-unused-private-class-members
|
|
24
24
|
#client: WorkerClient;
|
|
25
25
|
|
|
26
26
|
#group: Conversation;
|
|
@@ -217,6 +217,15 @@ export class WorkerConversation {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
getHmacKeys() {
|
|
220
|
-
return this.#group.getHmacKeys() as HmacKey[]
|
|
220
|
+
return this.#group.getHmacKeys() as Map<string, HmacKey[]>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async debugInfo() {
|
|
224
|
+
return (await this.#group.getDebugInfo()) as ConversationDebugInfo;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async getDuplicateDms() {
|
|
228
|
+
const dms = await this.#group.findDuplicateDms();
|
|
229
|
+
return dms.map((dm) => new WorkerConversation(this.#client, dm));
|
|
221
230
|
}
|
|
222
231
|
}
|
|
@@ -78,8 +78,11 @@ export class WorkerConversations {
|
|
|
78
78
|
listGroups(
|
|
79
79
|
options?: Omit<SafeListConversationsOptions, "conversation_type">,
|
|
80
80
|
) {
|
|
81
|
-
const groups = this.#conversations.
|
|
82
|
-
|
|
81
|
+
const groups = this.#conversations.list(
|
|
82
|
+
fromSafeListConversationsOptions({
|
|
83
|
+
...(options ?? {}),
|
|
84
|
+
conversationType: ConversationType.Group,
|
|
85
|
+
}),
|
|
83
86
|
) as ConversationListItem[];
|
|
84
87
|
return groups.map(
|
|
85
88
|
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
@@ -87,14 +90,24 @@ export class WorkerConversations {
|
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">) {
|
|
90
|
-
const groups = this.#conversations.
|
|
91
|
-
|
|
93
|
+
const groups = this.#conversations.list(
|
|
94
|
+
fromSafeListConversationsOptions({
|
|
95
|
+
...(options ?? {}),
|
|
96
|
+
conversationType: ConversationType.Dm,
|
|
97
|
+
}),
|
|
92
98
|
) as ConversationListItem[];
|
|
93
99
|
return groups.map(
|
|
94
100
|
(item) => new WorkerConversation(this.#client, item.conversation),
|
|
95
101
|
);
|
|
96
102
|
}
|
|
97
103
|
|
|
104
|
+
newGroupOptimistic(options?: SafeCreateGroupOptions) {
|
|
105
|
+
const group = this.#conversations.createGroupOptimistic(
|
|
106
|
+
options ? fromSafeCreateGroupOptions(options) : undefined,
|
|
107
|
+
);
|
|
108
|
+
return new WorkerConversation(this.#client, group);
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
async newGroupWithIdentifiers(
|
|
99
112
|
identifiers: Identifier[],
|
|
100
113
|
options?: SafeCreateGroupOptions,
|
|
@@ -164,6 +177,7 @@ export class WorkerConversations {
|
|
|
164
177
|
streamAllMessages(
|
|
165
178
|
callback?: StreamCallback<Message>,
|
|
166
179
|
conversationType?: ConversationType,
|
|
180
|
+
consentStates?: ConsentState[],
|
|
167
181
|
) {
|
|
168
182
|
const on_message = (message: Message) => {
|
|
169
183
|
void callback?.(null, message);
|
|
@@ -174,6 +188,7 @@ export class WorkerConversations {
|
|
|
174
188
|
return this.#conversations.streamAllMessages(
|
|
175
189
|
{ on_message, on_error },
|
|
176
190
|
conversationType,
|
|
191
|
+
consentStates,
|
|
177
192
|
);
|
|
178
193
|
}
|
|
179
194
|
}
|
package/src/WorkerPreferences.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { Client } from "./Client";
|
|
2
|
+
export type { ExtractCodecContentTypes } from "./Client";
|
|
2
3
|
export { Conversations } from "./Conversations";
|
|
3
4
|
export { Conversation } from "./Conversation";
|
|
4
5
|
export { Dm } from "./Dm";
|
|
@@ -7,7 +8,7 @@ export type { MessageDeliveryStatus, MessageKind } from "./DecodedMessage";
|
|
|
7
8
|
export { DecodedMessage } from "./DecodedMessage";
|
|
8
9
|
export { Utils } from "./Utils";
|
|
9
10
|
export { ApiUrls, HistorySyncUrls } from "./constants";
|
|
10
|
-
export type * from "./types";
|
|
11
|
+
export type * from "./types/options";
|
|
11
12
|
export * from "./utils/conversions";
|
|
12
13
|
export type { AsyncStream, StreamCallback } from "./AsyncStream";
|
|
13
14
|
export type {
|
|
@@ -50,3 +51,4 @@ export {
|
|
|
50
51
|
SortDirection,
|
|
51
52
|
} from "@xmtp/wasm-bindings";
|
|
52
53
|
export type { Signer } from "./utils/signer";
|
|
54
|
+
export * from "./utils/errors";
|