@xmtp/browser-sdk 2.0.13 → 2.1.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.
Files changed (43) hide show
  1. package/dist/index.d.ts +849 -678
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/workers/client.js +1 -1
  5. package/dist/workers/client.js.map +1 -1
  6. package/dist/workers/utils.js +1 -1
  7. package/dist/workers/utils.js.map +1 -1
  8. package/package.json +9 -11
  9. package/src/Client.ts +71 -31
  10. package/src/ClientWorkerClass.ts +62 -19
  11. package/src/Conversation.ts +60 -33
  12. package/src/Conversations.ts +96 -48
  13. package/src/DecodedMessage.ts +8 -5
  14. package/src/Dm.ts +14 -4
  15. package/src/Group.ts +27 -20
  16. package/src/Preferences.ts +21 -10
  17. package/src/Utils.ts +2 -2
  18. package/src/UtilsWorkerClass.ts +56 -15
  19. package/src/WorkerClient.ts +25 -3
  20. package/src/WorkerConversation.ts +11 -2
  21. package/src/WorkerConversations.ts +19 -4
  22. package/src/WorkerPreferences.ts +4 -0
  23. package/src/index.ts +3 -1
  24. package/src/types/actions/client.ts +181 -0
  25. package/src/types/actions/conversation.ts +146 -0
  26. package/src/types/actions/conversations.ts +146 -0
  27. package/src/types/actions/dm.ts +19 -0
  28. package/src/types/actions/group.ts +161 -0
  29. package/src/types/actions/preferences.ts +68 -0
  30. package/src/types/actions/streams.ts +44 -0
  31. package/src/types/actions/utils.ts +29 -0
  32. package/src/types/actions.ts +75 -0
  33. package/src/types/options.ts +18 -0
  34. package/src/utils/conversions.ts +60 -0
  35. package/src/utils/createClient.ts +6 -1
  36. package/src/utils/errors.ts +3 -1
  37. package/src/workers/client.ts +243 -190
  38. package/src/workers/utils.ts +25 -29
  39. package/src/types/clientEvents.ts +0 -693
  40. package/src/types/clientStreamEvents.ts +0 -45
  41. package/src/types/index.ts +0 -4
  42. package/src/types/utils.ts +0 -72
  43. package/src/types/utilsEvents.ts +0 -60
@@ -1,693 +0,0 @@
1
- import type {
2
- ConsentEntityType,
3
- ConsentState,
4
- ConversationType,
5
- Identifier,
6
- MetadataField,
7
- PermissionPolicy,
8
- PermissionUpdateType,
9
- SignatureRequestType,
10
- } from "@xmtp/wasm-bindings";
11
- import type {
12
- ClientOptions,
13
- EventsClientMessageData,
14
- EventsClientPostMessageData,
15
- EventsErrorData,
16
- EventsResult,
17
- EventsWorkerMessageData,
18
- EventsWorkerPostMessageData,
19
- SendMessageData,
20
- } from "@/types";
21
- import type {
22
- SafeConsent,
23
- SafeConversation,
24
- SafeCreateDmOptions,
25
- SafeCreateGroupOptions,
26
- SafeEncodedContent,
27
- SafeGroupMember,
28
- SafeHmacKey,
29
- SafeHmacKeys,
30
- SafeInboxState,
31
- SafeKeyPackageStatus,
32
- SafeListConversationsOptions,
33
- SafeListMessagesOptions,
34
- SafeMessage,
35
- SafeMessageDisappearingSettings,
36
- } from "@/utils/conversions";
37
-
38
- export type ClientEvents =
39
- /**
40
- * Stream actions
41
- */
42
- | {
43
- action: "endStream";
44
- id: string;
45
- result: undefined;
46
- data: {
47
- streamId: string;
48
- };
49
- }
50
- /**
51
- * Client actions
52
- */
53
- | {
54
- action: "init";
55
- id: string;
56
- result: {
57
- inboxId: string;
58
- installationId: string;
59
- installationIdBytes: Uint8Array;
60
- };
61
- data: {
62
- identifier: Identifier;
63
- options?: ClientOptions;
64
- };
65
- }
66
- | {
67
- action: "createInboxSignatureText";
68
- id: string;
69
- result: string | undefined;
70
- data: undefined;
71
- }
72
- | {
73
- action: "addAccountSignatureText";
74
- id: string;
75
- result: string | undefined;
76
- data: {
77
- newIdentifier: Identifier;
78
- };
79
- }
80
- | {
81
- action: "removeAccountSignatureText";
82
- id: string;
83
- result: string | undefined;
84
- data: {
85
- identifier: Identifier;
86
- };
87
- }
88
- | {
89
- action: "revokeAllOtherInstallationsSignatureText";
90
- id: string;
91
- result: string | undefined;
92
- data: undefined;
93
- }
94
- | {
95
- action: "revokeInstallationsSignatureText";
96
- id: string;
97
- result: string | undefined;
98
- data: {
99
- installationIds: Uint8Array[];
100
- };
101
- }
102
- | {
103
- action: "changeRecoveryIdentifierSignatureText";
104
- id: string;
105
- result: string | undefined;
106
- data: {
107
- identifier: Identifier;
108
- };
109
- }
110
- | {
111
- action: "addEcdsaSignature";
112
- id: string;
113
- result: undefined;
114
- data: {
115
- type: SignatureRequestType;
116
- bytes: Uint8Array;
117
- };
118
- }
119
- | {
120
- action: "addScwSignature";
121
- id: string;
122
- result: undefined;
123
- data: {
124
- type: SignatureRequestType;
125
- bytes: Uint8Array;
126
- chainId: bigint;
127
- blockNumber?: bigint;
128
- };
129
- }
130
- | {
131
- action: "applySignatures";
132
- id: string;
133
- result: undefined;
134
- data: undefined;
135
- }
136
- | {
137
- action: "registerIdentity";
138
- id: string;
139
- result: undefined;
140
- data: undefined;
141
- }
142
- | {
143
- action: "isRegistered";
144
- id: string;
145
- result: boolean;
146
- data: undefined;
147
- }
148
- | {
149
- action: "canMessage";
150
- id: string;
151
- result: Map<string, boolean>;
152
- data: {
153
- identifiers: Identifier[];
154
- };
155
- }
156
- | {
157
- action: "inboxState";
158
- id: string;
159
- result: SafeInboxState;
160
- data: {
161
- refreshFromNetwork: boolean;
162
- };
163
- }
164
- | {
165
- action: "inboxStateFromInboxIds";
166
- id: string;
167
- result: SafeInboxState[];
168
- data: {
169
- inboxIds: string[];
170
- refreshFromNetwork: boolean;
171
- };
172
- }
173
- | {
174
- action: "getLatestInboxState";
175
- id: string;
176
- result: SafeInboxState;
177
- data: {
178
- inboxId: string;
179
- };
180
- }
181
- | {
182
- action: "setConsentStates";
183
- id: string;
184
- result: undefined;
185
- data: {
186
- records: SafeConsent[];
187
- };
188
- }
189
- | {
190
- action: "getConsentState";
191
- id: string;
192
- result: ConsentState;
193
- data: {
194
- entityType: ConsentEntityType;
195
- entity: string;
196
- };
197
- }
198
- | {
199
- action: "findInboxIdByIdentifier";
200
- id: string;
201
- result: string | undefined;
202
- data: {
203
- identifier: Identifier;
204
- };
205
- }
206
- | {
207
- action: "signWithInstallationKey";
208
- id: string;
209
- result: Uint8Array;
210
- data: {
211
- signatureText: string;
212
- };
213
- }
214
- | {
215
- action: "verifySignedWithInstallationKey";
216
- id: string;
217
- result: boolean;
218
- data: {
219
- signatureText: string;
220
- signatureBytes: Uint8Array;
221
- };
222
- }
223
- | {
224
- action: "verifySignedWithPublicKey";
225
- id: string;
226
- result: boolean;
227
- data: {
228
- signatureText: string;
229
- signatureBytes: Uint8Array;
230
- publicKey: Uint8Array;
231
- };
232
- }
233
- | {
234
- action: "getKeyPackageStatusesForInstallationIds";
235
- id: string;
236
- result: Map<string, SafeKeyPackageStatus>;
237
- data: {
238
- installationIds: string[];
239
- };
240
- }
241
- /**
242
- * Conversations actions
243
- */
244
- | {
245
- action: "getConversationById";
246
- id: string;
247
- result: SafeConversation | undefined;
248
- data: {
249
- id: string;
250
- };
251
- }
252
- | {
253
- action: "getMessageById";
254
- id: string;
255
- result: SafeMessage | undefined;
256
- data: {
257
- id: string;
258
- };
259
- }
260
- | {
261
- action: "getDmByInboxId";
262
- id: string;
263
- result: SafeConversation | undefined;
264
- data: {
265
- inboxId: string;
266
- };
267
- }
268
- | {
269
- action: "getConversations";
270
- id: string;
271
- result: SafeConversation[];
272
- data: {
273
- options?: SafeListConversationsOptions;
274
- };
275
- }
276
- | {
277
- action: "getGroups";
278
- id: string;
279
- result: SafeConversation[];
280
- data: {
281
- options?: Omit<SafeListConversationsOptions, "conversation_type">;
282
- };
283
- }
284
- | {
285
- action: "getDms";
286
- id: string;
287
- result: SafeConversation[];
288
- data: {
289
- options?: Omit<SafeListConversationsOptions, "conversation_type">;
290
- };
291
- }
292
- | {
293
- action: "newGroupWithIdentifiers";
294
- id: string;
295
- result: SafeConversation;
296
- data: {
297
- identifiers: Identifier[];
298
- options?: SafeCreateGroupOptions;
299
- };
300
- }
301
- | {
302
- action: "newGroupWithInboxIds";
303
- id: string;
304
- result: SafeConversation;
305
- data: {
306
- inboxIds: string[];
307
- options?: SafeCreateGroupOptions;
308
- };
309
- }
310
- | {
311
- action: "newDmWithIdentifier";
312
- id: string;
313
- result: SafeConversation;
314
- data: {
315
- identifier: Identifier;
316
- options?: SafeCreateDmOptions;
317
- };
318
- }
319
- | {
320
- action: "newDmWithInboxId";
321
- id: string;
322
- result: SafeConversation;
323
- data: {
324
- inboxId: string;
325
- options?: SafeCreateDmOptions;
326
- };
327
- }
328
- | {
329
- action: "syncConversations";
330
- id: string;
331
- result: undefined;
332
- data: undefined;
333
- }
334
- | {
335
- action: "syncAllConversations";
336
- id: string;
337
- result: undefined;
338
- data: {
339
- consentStates?: ConsentState[];
340
- };
341
- }
342
- | {
343
- action: "getHmacKeys";
344
- id: string;
345
- result: SafeHmacKeys;
346
- data: undefined;
347
- }
348
- | {
349
- action: "streamAllGroups";
350
- id: string;
351
- result: undefined;
352
- data: {
353
- streamId: string;
354
- conversationType?: ConversationType;
355
- };
356
- }
357
- | {
358
- action: "streamAllMessages";
359
- id: string;
360
- result: undefined;
361
- data: {
362
- streamId: string;
363
- conversationType?: ConversationType;
364
- };
365
- }
366
- | {
367
- action: "streamConsent";
368
- id: string;
369
- result: undefined;
370
- data: {
371
- streamId: string;
372
- };
373
- }
374
- | {
375
- action: "streamPreferences";
376
- id: string;
377
- result: undefined;
378
- data: {
379
- streamId: string;
380
- };
381
- }
382
- /**
383
- * Group actions
384
- */
385
- | {
386
- action: "syncGroup";
387
- id: string;
388
- result: SafeConversation;
389
- data: {
390
- id: string;
391
- };
392
- }
393
- | {
394
- action: "sendGroupMessage";
395
- id: string;
396
- result: string;
397
- data: {
398
- id: string;
399
- content: SafeEncodedContent;
400
- };
401
- }
402
- | {
403
- action: "sendOptimisticGroupMessage";
404
- id: string;
405
- result: string;
406
- data: {
407
- id: string;
408
- content: SafeEncodedContent;
409
- };
410
- }
411
- | {
412
- action: "publishGroupMessages";
413
- id: string;
414
- result: undefined;
415
- data: {
416
- id: string;
417
- };
418
- }
419
- | {
420
- action: "getGroupMessages";
421
- id: string;
422
- result: SafeMessage[];
423
- data: {
424
- id: string;
425
- options?: SafeListMessagesOptions;
426
- };
427
- }
428
- | {
429
- action: "getGroupMembers";
430
- id: string;
431
- result: SafeGroupMember[];
432
- data: {
433
- id: string;
434
- };
435
- }
436
- | {
437
- action: "getGroupAdmins";
438
- id: string;
439
- result: string[];
440
- data: {
441
- id: string;
442
- };
443
- }
444
- | {
445
- action: "getGroupSuperAdmins";
446
- id: string;
447
- result: string[];
448
- data: {
449
- id: string;
450
- };
451
- }
452
- | {
453
- action: "isGroupAdmin";
454
- id: string;
455
- result: boolean;
456
- data: {
457
- id: string;
458
- inboxId: string;
459
- };
460
- }
461
- | {
462
- action: "isGroupSuperAdmin";
463
- id: string;
464
- result: boolean;
465
- data: {
466
- id: string;
467
- inboxId: string;
468
- };
469
- }
470
- | {
471
- action: "addGroupMembers";
472
- id: string;
473
- result: undefined;
474
- data: {
475
- id: string;
476
- identifiers: Identifier[];
477
- };
478
- }
479
- | {
480
- action: "removeGroupMembers";
481
- id: string;
482
- result: undefined;
483
- data: {
484
- id: string;
485
- identifiers: Identifier[];
486
- };
487
- }
488
- | {
489
- action: "addGroupMembersByInboxId";
490
- id: string;
491
- result: undefined;
492
- data: {
493
- id: string;
494
- inboxIds: string[];
495
- };
496
- }
497
- | {
498
- action: "removeGroupMembersByInboxId";
499
- id: string;
500
- result: undefined;
501
- data: {
502
- id: string;
503
- inboxIds: string[];
504
- };
505
- }
506
- | {
507
- action: "addGroupAdmin";
508
- id: string;
509
- result: undefined;
510
- data: {
511
- id: string;
512
- inboxId: string;
513
- };
514
- }
515
- | {
516
- action: "removeGroupAdmin";
517
- id: string;
518
- result: undefined;
519
- data: {
520
- id: string;
521
- inboxId: string;
522
- };
523
- }
524
- | {
525
- action: "addGroupSuperAdmin";
526
- id: string;
527
- result: undefined;
528
- data: {
529
- id: string;
530
- inboxId: string;
531
- };
532
- }
533
- | {
534
- action: "removeGroupSuperAdmin";
535
- id: string;
536
- result: undefined;
537
- data: {
538
- id: string;
539
- inboxId: string;
540
- };
541
- }
542
- | {
543
- action: "updateGroupName";
544
- id: string;
545
- result: undefined;
546
- data: {
547
- id: string;
548
- name: string;
549
- };
550
- }
551
- | {
552
- action: "updateGroupDescription";
553
- id: string;
554
- result: undefined;
555
- data: {
556
- id: string;
557
- description: string;
558
- };
559
- }
560
- | {
561
- action: "updateGroupImageUrlSquare";
562
- id: string;
563
- result: undefined;
564
- data: {
565
- id: string;
566
- imageUrl: string;
567
- };
568
- }
569
- | {
570
- action: "getGroupConsentState";
571
- id: string;
572
- result: ConsentState;
573
- data: {
574
- id: string;
575
- };
576
- }
577
- | {
578
- action: "updateGroupConsentState";
579
- id: string;
580
- result: undefined;
581
- data: {
582
- id: string;
583
- state: ConsentState;
584
- };
585
- }
586
- | {
587
- action: "getDmPeerInboxId";
588
- id: string;
589
- result: string;
590
- data: {
591
- id: string;
592
- };
593
- }
594
- | {
595
- action: "updateGroupPermissionPolicy";
596
- id: string;
597
- result: undefined;
598
- data: {
599
- id: string;
600
- permissionType: PermissionUpdateType;
601
- policy: PermissionPolicy;
602
- metadataField?: MetadataField;
603
- };
604
- }
605
- | {
606
- action: "getGroupPermissions";
607
- id: string;
608
- result: SafeConversation["permissions"];
609
- data: {
610
- id: string;
611
- };
612
- }
613
- | {
614
- action: "getGroupMessageDisappearingSettings";
615
- id: string;
616
- result: SafeMessageDisappearingSettings | undefined;
617
- data: {
618
- id: string;
619
- };
620
- }
621
- | {
622
- action: "updateGroupMessageDisappearingSettings";
623
- id: string;
624
- result: undefined;
625
- data: SafeMessageDisappearingSettings & {
626
- id: string;
627
- };
628
- }
629
- | {
630
- action: "removeGroupMessageDisappearingSettings";
631
- id: string;
632
- result: undefined;
633
- data: {
634
- id: string;
635
- };
636
- }
637
- | {
638
- action: "isGroupMessageDisappearingEnabled";
639
- id: string;
640
- result: boolean;
641
- data: {
642
- id: string;
643
- };
644
- }
645
- | {
646
- action: "streamGroupMessages";
647
- id: string;
648
- result: undefined;
649
- data: {
650
- groupId: string;
651
- streamId: string;
652
- };
653
- }
654
- | {
655
- action: "getGroupPausedForVersion";
656
- id: string;
657
- result: string | undefined;
658
- data: {
659
- id: string;
660
- };
661
- }
662
- | {
663
- action: "getGroupHmacKeys";
664
- id: string;
665
- result: SafeHmacKey[];
666
- data: {
667
- id: string;
668
- };
669
- };
670
-
671
- export type ClientEventsActions = ClientEvents["action"];
672
-
673
- export type ClientEventsClientMessageData =
674
- EventsClientMessageData<ClientEvents>;
675
-
676
- export type ClientEventsWorkerMessageData =
677
- EventsWorkerMessageData<ClientEvents>;
678
-
679
- export type ClientEventsResult<A extends ClientEventsActions> = EventsResult<
680
- ClientEvents,
681
- A
682
- >;
683
-
684
- export type ClientSendMessageData<A extends ClientEventsActions> =
685
- SendMessageData<ClientEvents, A>;
686
-
687
- export type ClientEventsWorkerPostMessageData<A extends ClientEventsActions> =
688
- EventsWorkerPostMessageData<ClientEvents, A>;
689
-
690
- export type ClientEventsClientPostMessageData<A extends ClientEventsActions> =
691
- EventsClientPostMessageData<ClientEvents, A>;
692
-
693
- export type ClientEventsErrorData = EventsErrorData<ClientEvents>;
@@ -1,45 +0,0 @@
1
- import type { UserPreference } from "@xmtp/wasm-bindings";
2
- import type {
3
- StreamEventsClientPostMessageData,
4
- StreamEventsErrorData,
5
- StreamEventsResult,
6
- } from "@/types";
7
- import type {
8
- SafeConsent,
9
- SafeConversation,
10
- SafeMessage,
11
- } from "@/utils/conversions";
12
-
13
- export type ClientStreamEvents =
14
- | {
15
- type: "message";
16
- streamId: string;
17
- result: SafeMessage | undefined;
18
- }
19
- | {
20
- type: "group";
21
- streamId: string;
22
- result: SafeConversation | undefined;
23
- }
24
- | {
25
- type: "consent";
26
- streamId: string;
27
- result: SafeConsent[] | undefined;
28
- }
29
- | {
30
- type: "preferences";
31
- streamId: string;
32
- result: UserPreference[] | undefined;
33
- };
34
-
35
- export type ClientStreamEventsTypes = ClientStreamEvents["type"];
36
-
37
- export type ClientStreamEventsResult<A extends ClientStreamEventsTypes> =
38
- StreamEventsResult<ClientStreamEvents, A>;
39
-
40
- export type ClientStreamEventsWorkerPostMessageData<
41
- A extends ClientStreamEventsTypes,
42
- > = StreamEventsClientPostMessageData<ClientStreamEvents, A>;
43
-
44
- export type ClientStreamEventsErrorData =
45
- StreamEventsErrorData<ClientStreamEvents>;
@@ -1,4 +0,0 @@
1
- export type * from "./options";
2
- export type * from "./clientEvents";
3
- export type * from "./utilsEvents";
4
- export type * from "./utils";