@xmtp/browser-sdk 0.0.1 → 0.0.2
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 +144 -87
- 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/package.json +2 -2
- package/src/Client.ts +16 -10
- package/src/Conversation.ts +8 -2
- package/src/Conversations.ts +30 -0
- package/src/DecodedMessage.ts +6 -6
- package/src/WorkerClient.ts +8 -8
- package/src/WorkerConversation.ts +48 -42
- package/src/WorkerConversations.ts +39 -7
- package/src/types/clientEvents.ts +49 -9
- package/src/utils/conversions.ts +124 -93
- package/src/utils/createClient.ts +6 -1
- package/src/workers/client.ts +75 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
2
|
-
import {
|
|
2
|
+
import { SignatureRequestType, ConsentState, ConsentEntityType, Conversations as Conversations$1, Client as Client$1, Conversation as Conversation$1, EncodedContent, ContentTypeId, DeliveryStatus, GroupMessageKind, Message, SortDirection, ListMessagesOptions, GroupMembershipState, ConversationType, ListConversationsOptions, GroupPermissionsOptions, CreateGroupOptions, PermissionPolicy, Installation, InboxState, Consent, PermissionLevel, GroupMember } from '@xmtp/wasm-bindings';
|
|
3
3
|
export * from '@xmtp/wasm-bindings';
|
|
4
|
-
import { ContentCodec, ContentTypeId, EncodedContent } from '@xmtp/content-type-primitives';
|
|
4
|
+
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
5
5
|
|
|
6
6
|
declare const ApiUrls: {
|
|
7
7
|
readonly local: "http://localhost:5555";
|
|
@@ -100,11 +100,11 @@ type ClientEvents =
|
|
|
100
100
|
id: string;
|
|
101
101
|
result: undefined;
|
|
102
102
|
data: {
|
|
103
|
-
type:
|
|
103
|
+
type: SignatureRequestType;
|
|
104
104
|
bytes: Uint8Array;
|
|
105
105
|
};
|
|
106
106
|
} | {
|
|
107
|
-
action: "
|
|
107
|
+
action: "applySignatures";
|
|
108
108
|
id: string;
|
|
109
109
|
result: undefined;
|
|
110
110
|
data: undefined;
|
|
@@ -149,9 +149,9 @@ type ClientEvents =
|
|
|
149
149
|
} | {
|
|
150
150
|
action: "getConsentState";
|
|
151
151
|
id: string;
|
|
152
|
-
result:
|
|
152
|
+
result: ConsentState;
|
|
153
153
|
data: {
|
|
154
|
-
entityType:
|
|
154
|
+
entityType: ConsentEntityType;
|
|
155
155
|
entity: string;
|
|
156
156
|
};
|
|
157
157
|
} | {
|
|
@@ -179,6 +179,13 @@ type ClientEvents =
|
|
|
179
179
|
data: {
|
|
180
180
|
id: string;
|
|
181
181
|
};
|
|
182
|
+
} | {
|
|
183
|
+
action: "getDmByInboxId";
|
|
184
|
+
id: string;
|
|
185
|
+
result: SafeConversation | undefined;
|
|
186
|
+
data: {
|
|
187
|
+
inboxId: string;
|
|
188
|
+
};
|
|
182
189
|
} | {
|
|
183
190
|
action: "getConversations";
|
|
184
191
|
id: string;
|
|
@@ -186,6 +193,20 @@ type ClientEvents =
|
|
|
186
193
|
data: {
|
|
187
194
|
options?: SafeListConversationsOptions;
|
|
188
195
|
};
|
|
196
|
+
} | {
|
|
197
|
+
action: "getGroups";
|
|
198
|
+
id: string;
|
|
199
|
+
result: SafeConversation[];
|
|
200
|
+
data: {
|
|
201
|
+
options?: Omit<SafeListConversationsOptions, "conversation_type">;
|
|
202
|
+
};
|
|
203
|
+
} | {
|
|
204
|
+
action: "getDms";
|
|
205
|
+
id: string;
|
|
206
|
+
result: SafeConversation[];
|
|
207
|
+
data: {
|
|
208
|
+
options?: Omit<SafeListConversationsOptions, "conversation_type">;
|
|
209
|
+
};
|
|
189
210
|
} | {
|
|
190
211
|
action: "newGroup";
|
|
191
212
|
id: string;
|
|
@@ -194,6 +215,13 @@ type ClientEvents =
|
|
|
194
215
|
accountAddresses: string[];
|
|
195
216
|
options?: SafeCreateGroupOptions;
|
|
196
217
|
};
|
|
218
|
+
} | {
|
|
219
|
+
action: "newDm";
|
|
220
|
+
id: string;
|
|
221
|
+
result: SafeConversation;
|
|
222
|
+
data: {
|
|
223
|
+
accountAddress: string;
|
|
224
|
+
};
|
|
197
225
|
} | {
|
|
198
226
|
action: "syncConversations";
|
|
199
227
|
id: string;
|
|
@@ -377,7 +405,7 @@ type ClientEvents =
|
|
|
377
405
|
} | {
|
|
378
406
|
action: "getGroupConsentState";
|
|
379
407
|
id: string;
|
|
380
|
-
result:
|
|
408
|
+
result: ConsentState;
|
|
381
409
|
data: {
|
|
382
410
|
id: string;
|
|
383
411
|
};
|
|
@@ -387,7 +415,14 @@ type ClientEvents =
|
|
|
387
415
|
result: undefined;
|
|
388
416
|
data: {
|
|
389
417
|
id: string;
|
|
390
|
-
state:
|
|
418
|
+
state: ConsentState;
|
|
419
|
+
};
|
|
420
|
+
} | {
|
|
421
|
+
action: "getDmPeerInboxId";
|
|
422
|
+
id: string;
|
|
423
|
+
result: string;
|
|
424
|
+
data: {
|
|
425
|
+
id: string;
|
|
391
426
|
};
|
|
392
427
|
};
|
|
393
428
|
type ClientEventsActions = ClientEvents["action"];
|
|
@@ -462,17 +497,21 @@ type EventsErrorData<Events extends GenericEvent> = {
|
|
|
462
497
|
|
|
463
498
|
declare class WorkerConversations {
|
|
464
499
|
#private;
|
|
465
|
-
constructor(client: WorkerClient, conversations:
|
|
500
|
+
constructor(client: WorkerClient, conversations: Conversations$1);
|
|
466
501
|
sync(): Promise<void>;
|
|
467
502
|
getConversationById(id: string): WorkerConversation | undefined;
|
|
468
503
|
getMessageById(id: string): SafeMessage | undefined;
|
|
504
|
+
getDmByInboxId(inboxId: string): WorkerConversation | undefined;
|
|
469
505
|
list(options?: SafeListConversationsOptions): Promise<WorkerConversation[]>;
|
|
506
|
+
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<WorkerConversation[]>;
|
|
507
|
+
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<WorkerConversation[]>;
|
|
470
508
|
newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
|
|
509
|
+
newDm(accountAddress: string): Promise<WorkerConversation>;
|
|
471
510
|
}
|
|
472
511
|
|
|
473
512
|
declare class WorkerClient {
|
|
474
513
|
#private;
|
|
475
|
-
constructor(client:
|
|
514
|
+
constructor(client: Client$1);
|
|
476
515
|
static create(accountAddress: string, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
|
|
477
516
|
get accountAddress(): string;
|
|
478
517
|
get inboxId(): string;
|
|
@@ -482,21 +521,21 @@ declare class WorkerClient {
|
|
|
482
521
|
getAddWalletSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
483
522
|
getRevokeWalletSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
484
523
|
getRevokeInstallationsSignatureText(): Promise<string | undefined>;
|
|
485
|
-
addSignature(type:
|
|
486
|
-
|
|
524
|
+
addSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<void>;
|
|
525
|
+
applySignatures(): Promise<void>;
|
|
487
526
|
canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
|
|
488
527
|
registerIdentity(): Promise<void>;
|
|
489
528
|
findInboxIdByAddress(address: string): Promise<string | undefined>;
|
|
490
|
-
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.
|
|
491
|
-
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.
|
|
529
|
+
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
530
|
+
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
492
531
|
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
493
|
-
getConsentState(entityType:
|
|
532
|
+
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
494
533
|
get conversations(): WorkerConversations;
|
|
495
534
|
}
|
|
496
535
|
|
|
497
536
|
declare class WorkerConversation {
|
|
498
537
|
#private;
|
|
499
|
-
constructor(client: WorkerClient, group:
|
|
538
|
+
constructor(client: WorkerClient, group: Conversation$1);
|
|
500
539
|
get id(): string;
|
|
501
540
|
get name(): string;
|
|
502
541
|
updateName(name: string): Promise<void>;
|
|
@@ -513,12 +552,12 @@ declare class WorkerConversation {
|
|
|
513
552
|
creatorInboxId: string;
|
|
514
553
|
conversationType: string;
|
|
515
554
|
};
|
|
516
|
-
members(): Promise<
|
|
555
|
+
members(): Promise<SafeGroupMember[]>;
|
|
517
556
|
get admins(): string[];
|
|
518
557
|
get superAdmins(): string[];
|
|
519
558
|
get permissions(): {
|
|
520
|
-
policyType: _xmtp_wasm_bindings.
|
|
521
|
-
policySet: _xmtp_wasm_bindings.
|
|
559
|
+
policyType: _xmtp_wasm_bindings.GroupPermissionsOptions;
|
|
560
|
+
policySet: _xmtp_wasm_bindings.PermissionPolicySet;
|
|
522
561
|
};
|
|
523
562
|
isAdmin(inboxId: string): boolean;
|
|
524
563
|
isSuperAdmin(inboxId: string): boolean;
|
|
@@ -532,25 +571,26 @@ declare class WorkerConversation {
|
|
|
532
571
|
addSuperAdmin(inboxId: string): Promise<void>;
|
|
533
572
|
removeSuperAdmin(inboxId: string): Promise<void>;
|
|
534
573
|
publishMessages(): Promise<void>;
|
|
535
|
-
sendOptimistic(encodedContent:
|
|
536
|
-
send(encodedContent:
|
|
537
|
-
messages(options?: SafeListMessagesOptions): _xmtp_wasm_bindings.
|
|
538
|
-
get consentState():
|
|
539
|
-
updateConsentState(state:
|
|
574
|
+
sendOptimistic(encodedContent: EncodedContent): string;
|
|
575
|
+
send(encodedContent: EncodedContent): Promise<string>;
|
|
576
|
+
messages(options?: SafeListMessagesOptions): _xmtp_wasm_bindings.Message[];
|
|
577
|
+
get consentState(): ConsentState;
|
|
578
|
+
updateConsentState(state: ConsentState): void;
|
|
579
|
+
dmPeerInboxId(): string;
|
|
540
580
|
}
|
|
541
581
|
|
|
542
|
-
declare const toContentTypeId: (contentTypeId:
|
|
543
|
-
declare const fromContentTypeId: (contentTypeId: ContentTypeId) =>
|
|
582
|
+
declare const toContentTypeId: (contentTypeId: ContentTypeId) => ContentTypeId$1;
|
|
583
|
+
declare const fromContentTypeId: (contentTypeId: ContentTypeId$1) => ContentTypeId;
|
|
544
584
|
type SafeContentTypeId = {
|
|
545
585
|
authorityId: string;
|
|
546
586
|
typeId: string;
|
|
547
587
|
versionMajor: number;
|
|
548
588
|
versionMinor: number;
|
|
549
589
|
};
|
|
550
|
-
declare const toSafeContentTypeId: (contentTypeId: ContentTypeId) => SafeContentTypeId;
|
|
551
|
-
declare const fromSafeContentTypeId: (contentTypeId: SafeContentTypeId) => ContentTypeId;
|
|
552
|
-
declare const toEncodedContent: (content:
|
|
553
|
-
declare const fromEncodedContent: (content: EncodedContent) =>
|
|
590
|
+
declare const toSafeContentTypeId: (contentTypeId: ContentTypeId$1) => SafeContentTypeId;
|
|
591
|
+
declare const fromSafeContentTypeId: (contentTypeId: SafeContentTypeId) => ContentTypeId$1;
|
|
592
|
+
declare const toEncodedContent: (content: EncodedContent) => EncodedContent$1;
|
|
593
|
+
declare const fromEncodedContent: (content: EncodedContent$1) => EncodedContent;
|
|
554
594
|
type SafeEncodedContent = {
|
|
555
595
|
type: SafeContentTypeId;
|
|
556
596
|
parameters: Record<string, string>;
|
|
@@ -558,42 +598,45 @@ type SafeEncodedContent = {
|
|
|
558
598
|
compression?: number;
|
|
559
599
|
content: Uint8Array;
|
|
560
600
|
};
|
|
561
|
-
declare const toSafeEncodedContent: (content: EncodedContent) => SafeEncodedContent;
|
|
562
|
-
declare const fromSafeEncodedContent: (content: SafeEncodedContent) => EncodedContent;
|
|
601
|
+
declare const toSafeEncodedContent: (content: EncodedContent$1) => SafeEncodedContent;
|
|
602
|
+
declare const fromSafeEncodedContent: (content: SafeEncodedContent) => EncodedContent$1;
|
|
563
603
|
type SafeMessage = {
|
|
564
604
|
content: SafeEncodedContent;
|
|
565
605
|
convoId: string;
|
|
566
|
-
deliveryStatus:
|
|
606
|
+
deliveryStatus: DeliveryStatus;
|
|
567
607
|
id: string;
|
|
568
|
-
kind:
|
|
608
|
+
kind: GroupMessageKind;
|
|
569
609
|
senderInboxId: string;
|
|
570
610
|
sentAtNs: bigint;
|
|
571
611
|
};
|
|
572
|
-
declare const toSafeMessage: (message:
|
|
612
|
+
declare const toSafeMessage: (message: Message) => SafeMessage;
|
|
573
613
|
type SafeListMessagesOptions = {
|
|
574
|
-
|
|
614
|
+
deliveryStatus?: DeliveryStatus;
|
|
615
|
+
direction?: SortDirection;
|
|
575
616
|
limit?: bigint;
|
|
576
|
-
|
|
577
|
-
|
|
617
|
+
sentAfterNs?: bigint;
|
|
618
|
+
sentBeforeNs?: bigint;
|
|
578
619
|
};
|
|
579
|
-
declare const toSafeListMessagesOptions: (options:
|
|
580
|
-
declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) =>
|
|
620
|
+
declare const toSafeListMessagesOptions: (options: ListMessagesOptions) => SafeListMessagesOptions;
|
|
621
|
+
declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) => ListMessagesOptions;
|
|
581
622
|
type SafeListConversationsOptions = {
|
|
582
|
-
|
|
583
|
-
|
|
623
|
+
allowedStates?: GroupMembershipState[];
|
|
624
|
+
conversationType?: ConversationType;
|
|
625
|
+
createdAfterNs?: bigint;
|
|
626
|
+
createdBeforeNs?: bigint;
|
|
584
627
|
limit?: bigint;
|
|
585
628
|
};
|
|
586
|
-
declare const toSafeListConversationsOptions: (options:
|
|
587
|
-
declare const fromSafeListConversationsOptions: (options: SafeListConversationsOptions) =>
|
|
629
|
+
declare const toSafeListConversationsOptions: (options: ListConversationsOptions) => SafeListConversationsOptions;
|
|
630
|
+
declare const fromSafeListConversationsOptions: (options: SafeListConversationsOptions) => ListConversationsOptions;
|
|
588
631
|
type SafeCreateGroupOptions = {
|
|
589
|
-
permissions?:
|
|
632
|
+
permissions?: GroupPermissionsOptions;
|
|
590
633
|
name?: string;
|
|
591
634
|
imageUrlSquare?: string;
|
|
592
635
|
description?: string;
|
|
593
636
|
pinnedFrameUrl?: string;
|
|
594
637
|
};
|
|
595
|
-
declare const toSafeCreateGroupOptions: (options:
|
|
596
|
-
declare const fromSafeCreateGroupOptions: (options: SafeCreateGroupOptions) =>
|
|
638
|
+
declare const toSafeCreateGroupOptions: (options: CreateGroupOptions) => SafeCreateGroupOptions;
|
|
639
|
+
declare const fromSafeCreateGroupOptions: (options: SafeCreateGroupOptions) => CreateGroupOptions;
|
|
597
640
|
type SafeConversation = {
|
|
598
641
|
id: string;
|
|
599
642
|
name: string;
|
|
@@ -601,16 +644,16 @@ type SafeConversation = {
|
|
|
601
644
|
description: string;
|
|
602
645
|
pinnedFrameUrl: string;
|
|
603
646
|
permissions: {
|
|
604
|
-
policyType:
|
|
647
|
+
policyType: GroupPermissionsOptions;
|
|
605
648
|
policySet: {
|
|
606
|
-
addAdminPolicy:
|
|
607
|
-
addMemberPolicy:
|
|
608
|
-
removeAdminPolicy:
|
|
609
|
-
removeMemberPolicy:
|
|
610
|
-
updateGroupDescriptionPolicy:
|
|
611
|
-
updateGroupImageUrlSquarePolicy:
|
|
612
|
-
updateGroupNamePolicy:
|
|
613
|
-
updateGroupPinnedFrameUrlPolicy:
|
|
649
|
+
addAdminPolicy: PermissionPolicy;
|
|
650
|
+
addMemberPolicy: PermissionPolicy;
|
|
651
|
+
removeAdminPolicy: PermissionPolicy;
|
|
652
|
+
removeMemberPolicy: PermissionPolicy;
|
|
653
|
+
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
654
|
+
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
655
|
+
updateGroupNamePolicy: PermissionPolicy;
|
|
656
|
+
updateGroupPinnedFrameUrlPolicy: PermissionPolicy;
|
|
614
657
|
};
|
|
615
658
|
};
|
|
616
659
|
isActive: boolean;
|
|
@@ -628,30 +671,38 @@ type SafeInstallation = {
|
|
|
628
671
|
id: string;
|
|
629
672
|
clientTimestampNs?: bigint;
|
|
630
673
|
};
|
|
631
|
-
declare const toSafeInstallation: (installation:
|
|
674
|
+
declare const toSafeInstallation: (installation: Installation) => SafeInstallation;
|
|
632
675
|
type SafeInboxState = {
|
|
633
676
|
accountAddresses: string[];
|
|
634
677
|
inboxId: string;
|
|
635
678
|
installations: SafeInstallation[];
|
|
636
679
|
recoveryAddress: string;
|
|
637
680
|
};
|
|
638
|
-
declare const toSafeInboxState: (inboxState:
|
|
681
|
+
declare const toSafeInboxState: (inboxState: InboxState) => SafeInboxState;
|
|
639
682
|
type SafeConsent = {
|
|
640
683
|
entity: string;
|
|
641
|
-
entityType:
|
|
642
|
-
state:
|
|
684
|
+
entityType: ConsentEntityType;
|
|
685
|
+
state: ConsentState;
|
|
643
686
|
};
|
|
644
|
-
declare const toSafeConsent: (consent:
|
|
645
|
-
declare const fromSafeConsent: (consent: SafeConsent) =>
|
|
687
|
+
declare const toSafeConsent: (consent: Consent) => SafeConsent;
|
|
688
|
+
declare const fromSafeConsent: (consent: SafeConsent) => Consent;
|
|
646
689
|
type SafeGroupMember = {
|
|
647
690
|
accountAddresses: string[];
|
|
648
|
-
consentState:
|
|
691
|
+
consentState: ConsentState;
|
|
649
692
|
inboxId: string;
|
|
650
693
|
installationIds: string[];
|
|
651
|
-
permissionLevel:
|
|
694
|
+
permissionLevel: PermissionLevel;
|
|
652
695
|
};
|
|
696
|
+
declare class WasmGroupMember {
|
|
697
|
+
account_addresses: string[];
|
|
698
|
+
consent_state: ConsentState;
|
|
699
|
+
inbox_id: string;
|
|
700
|
+
installation_ids: string[];
|
|
701
|
+
permission_level: PermissionLevel;
|
|
702
|
+
constructor(inbox_id: string, account_addresses: string[], installation_ids: string[], permission_level: PermissionLevel, consent_state: ConsentState);
|
|
703
|
+
}
|
|
653
704
|
declare const toSafeGroupMember: (member: WasmGroupMember) => SafeGroupMember;
|
|
654
|
-
declare const fromSafeGroupMember: (member: SafeGroupMember) =>
|
|
705
|
+
declare const fromSafeGroupMember: (member: SafeGroupMember) => GroupMember;
|
|
655
706
|
|
|
656
707
|
declare class ClientWorkerClass {
|
|
657
708
|
#private;
|
|
@@ -666,7 +717,7 @@ type MessageDeliveryStatus = "unpublished" | "published" | "failed";
|
|
|
666
717
|
declare class DecodedMessage {
|
|
667
718
|
#private;
|
|
668
719
|
content: any;
|
|
669
|
-
contentType: ContentTypeId;
|
|
720
|
+
contentType: ContentTypeId$1;
|
|
670
721
|
conversationId: string;
|
|
671
722
|
deliveryStatus: MessageDeliveryStatus;
|
|
672
723
|
fallback?: string;
|
|
@@ -703,16 +754,16 @@ declare class Conversation {
|
|
|
703
754
|
admins(): Promise<string[]>;
|
|
704
755
|
superAdmins(): Promise<string[]>;
|
|
705
756
|
get permissions(): {
|
|
706
|
-
policyType: _xmtp_wasm_bindings.
|
|
757
|
+
policyType: _xmtp_wasm_bindings.GroupPermissionsOptions;
|
|
707
758
|
policySet: {
|
|
708
|
-
addAdminPolicy: _xmtp_wasm_bindings.
|
|
709
|
-
addMemberPolicy: _xmtp_wasm_bindings.
|
|
710
|
-
removeAdminPolicy: _xmtp_wasm_bindings.
|
|
711
|
-
removeMemberPolicy: _xmtp_wasm_bindings.
|
|
712
|
-
updateGroupDescriptionPolicy: _xmtp_wasm_bindings.
|
|
713
|
-
updateGroupImageUrlSquarePolicy: _xmtp_wasm_bindings.
|
|
714
|
-
updateGroupNamePolicy: _xmtp_wasm_bindings.
|
|
715
|
-
updateGroupPinnedFrameUrlPolicy: _xmtp_wasm_bindings.
|
|
759
|
+
addAdminPolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
760
|
+
addMemberPolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
761
|
+
removeAdminPolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
762
|
+
removeMemberPolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
763
|
+
updateGroupDescriptionPolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
764
|
+
updateGroupImageUrlSquarePolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
765
|
+
updateGroupNamePolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
766
|
+
updateGroupPinnedFrameUrlPolicy: _xmtp_wasm_bindings.PermissionPolicy;
|
|
716
767
|
};
|
|
717
768
|
} | undefined;
|
|
718
769
|
isAdmin(inboxId: string): Promise<boolean>;
|
|
@@ -727,11 +778,12 @@ declare class Conversation {
|
|
|
727
778
|
addSuperAdmin(inboxId: string): Promise<undefined>;
|
|
728
779
|
removeSuperAdmin(inboxId: string): Promise<undefined>;
|
|
729
780
|
publishMessages(): Promise<undefined>;
|
|
730
|
-
sendOptimistic(content: any, contentType?: ContentTypeId): Promise<string>;
|
|
731
|
-
send(content: any, contentType?: ContentTypeId): Promise<string>;
|
|
781
|
+
sendOptimistic(content: any, contentType?: ContentTypeId$1): Promise<string>;
|
|
782
|
+
send(content: any, contentType?: ContentTypeId$1): Promise<string>;
|
|
732
783
|
messages(options?: SafeListMessagesOptions): Promise<DecodedMessage[]>;
|
|
733
|
-
consentState(): Promise<
|
|
734
|
-
updateConsentState(state:
|
|
784
|
+
consentState(): Promise<ConsentState>;
|
|
785
|
+
updateConsentState(state: ConsentState): Promise<undefined>;
|
|
786
|
+
dmPeerInboxId(): Promise<string>;
|
|
735
787
|
}
|
|
736
788
|
|
|
737
789
|
declare class Conversations {
|
|
@@ -740,8 +792,12 @@ declare class Conversations {
|
|
|
740
792
|
sync(): Promise<undefined>;
|
|
741
793
|
getConversationById(id: string): Promise<SafeConversation | undefined>;
|
|
742
794
|
getMessageById(id: string): Promise<SafeMessage | undefined>;
|
|
795
|
+
getDmByInboxId(inboxId: string): Promise<SafeConversation | undefined>;
|
|
743
796
|
list(options?: SafeListConversationsOptions): Promise<Conversation[]>;
|
|
797
|
+
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<SafeConversation[]>;
|
|
798
|
+
listDms(options?: Omit<SafeListConversationsOptions, "conversation_type">): Promise<SafeConversation[]>;
|
|
744
799
|
newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<Conversation>;
|
|
800
|
+
newDm(accountAddress: string): Promise<Conversation>;
|
|
745
801
|
}
|
|
746
802
|
|
|
747
803
|
declare class Client extends ClientWorkerClass {
|
|
@@ -757,20 +813,21 @@ declare class Client extends ClientWorkerClass {
|
|
|
757
813
|
getCreateInboxSignatureText(): Promise<string | undefined>;
|
|
758
814
|
getAddWalletSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
759
815
|
getRevokeWalletSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
760
|
-
|
|
761
|
-
|
|
816
|
+
getRevokeInstallationsSignatureText(): Promise<string | undefined>;
|
|
817
|
+
addSignature(type: SignatureRequestType, bytes: Uint8Array): Promise<undefined>;
|
|
818
|
+
applySignatures(): Promise<undefined>;
|
|
762
819
|
registerIdentity(): Promise<undefined>;
|
|
763
820
|
isRegistered(): Promise<boolean>;
|
|
764
821
|
canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
|
|
765
822
|
findInboxIdByAddress(address: string): Promise<string | undefined>;
|
|
766
|
-
inboxState(refreshFromNetwork
|
|
823
|
+
inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
|
|
767
824
|
getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
|
|
768
825
|
setConsentStates(records: SafeConsent[]): Promise<undefined>;
|
|
769
|
-
getConsentState(entityType:
|
|
826
|
+
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
770
827
|
get conversations(): Conversations;
|
|
771
|
-
codecFor(contentType: ContentTypeId): ContentCodec | undefined;
|
|
772
|
-
encodeContent(content: any, contentType: ContentTypeId): SafeEncodedContent;
|
|
773
|
-
decodeContent(message: SafeMessage, contentType: ContentTypeId): any;
|
|
828
|
+
codecFor(contentType: ContentTypeId$1): ContentCodec | undefined;
|
|
829
|
+
encodeContent(content: any, contentType: ContentTypeId$1): SafeEncodedContent;
|
|
830
|
+
decodeContent(message: SafeMessage, contentType: ContentTypeId$1): any;
|
|
774
831
|
}
|
|
775
832
|
|
|
776
833
|
declare class UtilsWorkerClass {
|
|
@@ -788,4 +845,4 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
788
845
|
getInboxIdForAddress(address: string, env?: XmtpEnv): Promise<string | undefined>;
|
|
789
846
|
}
|
|
790
847
|
|
|
791
|
-
export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EncryptionOptions, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SendMessageData, type StorageOptions, Utils, type UtilsEvents, type UtilsEventsActions, type UtilsEventsClientMessageData, type UtilsEventsClientPostMessageData, type UtilsEventsErrorData, type UtilsEventsResult, type UtilsEventsWorkerMessageData, type UtilsEventsWorkerPostMessageData, type UtilsSendMessageData, type XmtpEnv, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage };
|
|
848
|
+
export { ApiUrls, Client, type ClientEvents, type ClientEventsActions, type ClientEventsClientMessageData, type ClientEventsClientPostMessageData, type ClientEventsErrorData, type ClientEventsResult, type ClientEventsWorkerMessageData, type ClientEventsWorkerPostMessageData, type ClientOptions, type ClientSendMessageData, type ContentOptions, Conversation, Conversations, DecodedMessage, type EncryptionOptions, type EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SendMessageData, type StorageOptions, Utils, type UtilsEvents, type UtilsEventsActions, type UtilsEventsClientMessageData, type UtilsEventsClientPostMessageData, type UtilsEventsErrorData, type UtilsEventsResult, type UtilsEventsWorkerMessageData, type UtilsEventsWorkerPostMessageData, type UtilsSendMessageData, WasmGroupMember, type XmtpEnv, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{WasmContentTypeId as i,WasmEncodedContent as r,WasmListMessagesOptions as o,WasmListConversationsOptions as a,WasmCreateGroupOptions as d,WasmConsent as c,WasmGroupMember as p,WasmGroupMessageKind as l,WasmDeliveryStatus as m}from"@xmtp/wasm-bindings";import{v4 as h}from"uuid";import{ContentTypeId as u}from"@xmtp/content-type-primitives";const g=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class y{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",g),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",g),this.#e.terminate()}}const b=e=>new u({authorityId:e.authority_id,typeId:e.type_id,versionMajor:e.version_major,versionMinor:e.version_minor}),v=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),I=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new u({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),_=e=>({type:b(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),w=e=>new r(v(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),x=e=>({type:I(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),A=e=>({type:M(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),S=e=>({content:x(_(e.content)),convoId:e.convo_id,deliveryStatus:e.delivery_status,id:e.id,kind:e.kind,senderInboxId:e.sender_inbox_id,sentAtNs:e.sent_at_ns}),f=e=>({delivery_status:e.delivery_status,limit:e.limit,sent_after_ns:e.sent_after_ns,sent_before_ns:e.sent_before_ns}),k=e=>new o(e.sent_before_ns,e.sent_after_ns,e.limit,e.delivery_status),U=e=>({created_after_ns:e.created_after_ns,created_before_ns:e.created_before_ns,limit:e.limit}),G=e=>new a(e.created_after_ns,e.created_before_ns,e.limit),L=e=>({permissions:e.permissions,name:e.group_name,imageUrlSquare:e.group_image_url_square,description:e.group_description,pinnedFrameUrl:e.group_pinned_frame_url}),C=e=>new d(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl),F=e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,pinnedFrameUrl:e.pinnedFrameUrl,permissions:{policyType:e.permissions.policyType,policySet:{addAdminPolicy:e.permissions.policySet.add_admin_policy,addMemberPolicy:e.permissions.policySet.add_member_policy,removeAdminPolicy:e.permissions.policySet.remove_admin_policy,removeMemberPolicy:e.permissions.policySet.remove_member_policy,updateGroupDescriptionPolicy:e.permissions.policySet.update_group_description_policy,updateGroupImageUrlSquarePolicy:e.permissions.policySet.update_group_image_url_square_policy,updateGroupNamePolicy:e.permissions.policySet.update_group_name_policy,updateGroupPinnedFrameUrlPolicy:e.permissions.policySet.update_group_pinned_frame_url_policy}},isActive:e.isActive,addedByInboxId:e.addedByInboxId,metadata:e.metadata,admins:e.admins,superAdmins:e.superAdmins,createdAtNs:e.createdAtNs}),N=e=>({id:e.id,clientTimestampNs:e.client_timestamp_ns}),B=e=>({accountAddresses:e.account_addresses,inboxId:e.inbox_id,installations:e.installations.map(N),recoveryAddress:e.recovery_address}),E=e=>({entity:e.entity,entityType:e.entity_type,state:e.state}),T=e=>new c(e.entityType,e.state,e.entity),j=e=>({accountAddresses:e.account_addresses,consentState:e.consent_state,inboxId:e.inbox_id,installationIds:e.installation_ids,permissionLevel:e.permission_level}),P=e=>new p(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState);class R{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;senderInboxId;sentAtNs;constructor(e,t){switch(this.#n=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,t.kind){case l.Application:this.kind="application";break;case l.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case m.Unpublished:this.deliveryStatus="unpublished";break;case m.Published:this.deliveryStatus="published";break;case m.Failed:this.deliveryStatus="failed"}this.contentType=M(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#n.decodeContent(t,this.contentType)}}class q{#n;#i;#r;#o;#a;#d;#c;#p;#l;#m;#h;constructor(e,t,s){this.#n=e,this.#i=t,this.#u(s)}#u(e){this.#r=e?.name??"",this.#o=e?.imageUrl??"",this.#a=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#p=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#m=e?.permissions??void 0,this.#h=e?.createdAtNs??void 0}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#o}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#o=e}get description(){return this.#a}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#a=e}get pinnedFrameUrl(){return this.#d}async updatePinnedFrameUrl(e){await this.#n.sendMessage("updateGroupPinnedFrameUrl",{id:this.#i,pinnedFrameUrl:e}),this.#d=e}get isActive(){return this.#c}get addedByInboxId(){return this.#p}get createdAtNs(){return this.#h}get createdAt(){return this.#h?(e=this.#h,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#l}async members(){return this.#n.sendMessage("getGroupMembers",{id:this.#i})}async admins(){return this.#n.sendMessage("getGroupAdmins",{id:this.#i})}async superAdmins(){return this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i})}get permissions(){return this.#m}async isAdmin(e){return(await this.admins()).includes(e)}async isSuperAdmin(e){return(await this.superAdmins()).includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#u(e)}async addMembers(e){return this.#n.sendMessage("addGroupMembers",{id:this.#i,accountAddresses:e})}async addMembersByInboxId(e){return this.#n.sendMessage("addGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async removeMembers(e){return this.#n.sendMessage("removeGroupMembers",{id:this.#i,accountAddresses:e})}async removeMembersByInboxId(e){return this.#n.sendMessage("removeGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("addGroupAdmin",{id:this.#i,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("removeGroupAdmin",{id:this.#i,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("addGroupSuperAdmin",{id:this.#i,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("removeGroupSuperAdmin",{id:this.#i,inboxId:e})}async publishMessages(){return this.#n.sendMessage("publishGroupMessages",{id:this.#i})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendOptimisticGroupMessage",{id:this.#i,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendGroupMessage",{id:this.#i,content:n})}async messages(e){return(await this.#n.sendMessage("getGroupMessages",{id:this.#i,options:e})).map((e=>new R(this.#n,e)))}async consentState(){return this.#n.sendMessage("getGroupConsentState",{id:this.#i})}async updateConsentState(e){return this.#n.sendMessage("updateGroupConsentState",{id:this.#i,state:e})}}class W{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async getConversationById(e){return this.#n.sendMessage("getConversationById",{id:e})}async getMessageById(e){return this.#n.sendMessage("getMessageById",{id:e})}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new q(this.#n,e.id,e)))}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new q(this.#n,s.id,s)}}class D extends y{address;options;#g=!1;#y;#b;#v;#I;constructor(t,s){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),s?.enableLogging??!1),this.address=t,this.options=s,this.#v=new W(this);const i=[new e,new n,...s?.codecs??[]];this.#I=new Map(i.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{address:this.address,options:this.options});this.#y=e.inboxId,this.#b=e.installationId,this.#g=!0}static async create(e,t){const s=new D(e,t);return await s.init(),s}get isReady(){return this.#g}get inboxId(){return this.#y}get installationId(){return this.#b}async getCreateInboxSignatureText(){return this.sendMessage("getCreateInboxSignatureText",void 0)}async getAddWalletSignatureText(e){return this.sendMessage("getAddWalletSignatureText",{accountAddress:e})}async getRevokeWalletSignatureText(e){return this.sendMessage("getRevokeWalletSignatureText",{accountAddress:e})}async addSignature(e,t){return this.sendMessage("addSignature",{type:e,bytes:t})}async applySignaturesRequests(){return this.sendMessage("applySignaturesRequests",void 0)}async registerIdentity(){return this.sendMessage("registerIdentity",void 0)}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}async findInboxIdByAddress(e){return this.sendMessage("findInboxIdByAddress",{address:e})}async inboxState(e){return this.sendMessage("inboxState",{refreshFromNetwork:e})}async getLatestInboxState(e){return this.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.sendMessage("getConsentState",{entityType:e,entity:t})}get conversations(){return this.#v}codecFor(e){return this.#I.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),x(n)}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==l.MembershipChange)throw new Error("Error decoding group membership change");const i=A(e.content);return n.decode(i,this)}}const $=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class O{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",$),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",$),this.#e.terminate()}}class z extends O{#t;constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1),this.#t=e??!1}async generateInboxId(e){return this.sendMessage("generateInboxId",{address:e,enableLogging:this.#t})}async getInboxIdForAddress(e,t){return this.sendMessage("getInboxIdForAddress",{address:e,env:t,enableLogging:this.#t})}}const H={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};export{H as ApiUrls,D as Client,q as Conversation,W as Conversations,R as DecodedMessage,z as Utils,v as fromContentTypeId,w as fromEncodedContent,T as fromSafeConsent,M as fromSafeContentTypeId,C as fromSafeCreateGroupOptions,A as fromSafeEncodedContent,P as fromSafeGroupMember,G as fromSafeListConversationsOptions,k as fromSafeListMessagesOptions,b as toContentTypeId,_ as toEncodedContent,E as toSafeConsent,I as toSafeContentTypeId,F as toSafeConversation,L as toSafeCreateGroupOptions,x as toSafeEncodedContent,j as toSafeGroupMember,B as toSafeInboxState,N as toSafeInstallation,U as toSafeListConversationsOptions,f as toSafeListMessagesOptions,S as toSafeMessage};
|
|
1
|
+
import{GroupUpdatedCodec as e,ContentTypeGroupUpdated as t}from"@xmtp/content-type-group-updated";import{ContentTypeText as s,TextCodec as n}from"@xmtp/content-type-text";import{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as o,ListConversationsOptions as a,CreateGroupOptions as d,Consent as c,GroupMember as l,GroupMessageKind as p,DeliveryStatus as m}from"@xmtp/wasm-bindings";import{v4 as h}from"uuid";import{ContentTypeId as u}from"@xmtp/content-type-primitives";const g=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class y{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",g),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("client received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",g),this.#e.terminate()}}const I=e=>new u({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),b=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),v=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new u({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),w=e=>({type:I(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),x=e=>new r(b(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),A=e=>({type:v(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),S=e=>({type:M(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),k=e=>({content:A(w(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),f=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),N=e=>new o(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),U=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),G=e=>new a(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),C=e=>({permissions:e.permissions,name:e.groupName,imageUrlSquare:e.groupImageUrlSquare,description:e.groupDescription,pinnedFrameUrl:e.groupPinnedFrameUrl}),L=e=>new d(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl),P=e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,pinnedFrameUrl:e.pinnedFrameUrl,permissions:{policyType:e.permissions.policyType,policySet:{addAdminPolicy:e.permissions.policySet.addAdminPolicy,addMemberPolicy:e.permissions.policySet.addMemberPolicy,removeAdminPolicy:e.permissions.policySet.removeAdminPolicy,removeMemberPolicy:e.permissions.policySet.removeMemberPolicy,updateGroupDescriptionPolicy:e.permissions.policySet.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.permissions.policySet.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.permissions.policySet.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:e.permissions.policySet.updateGroupPinnedFrameUrlPolicy}},isActive:e.isActive,addedByInboxId:e.addedByInboxId,metadata:e.metadata,admins:e.admins,superAdmins:e.superAdmins,createdAtNs:e.createdAtNs}),B=e=>({id:e.id,clientTimestampNs:e.clientTimestampNs}),T=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(B),recoveryAddress:e.recoveryAddress}),F=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),E=e=>new c(e.entityType,e.state,e.entity);class D{account_addresses;consent_state;inbox_id;installation_ids;permission_level;constructor(e,t,s,n,i){this.inbox_id=e,this.account_addresses=t,this.installation_ids=s,this.permission_level=n,this.consent_state=i}}const _=e=>({accountAddresses:e.account_addresses,consentState:e.consent_state,inboxId:e.inbox_id,installationIds:e.installation_ids,permissionLevel:e.permission_level}),j=e=>new l(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState);class R{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;senderInboxId;sentAtNs;constructor(e,t){switch(this.#n=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,t.kind){case p.Application:this.kind="application";break;case p.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case m.Unpublished:this.deliveryStatus="unpublished";break;case m.Published:this.deliveryStatus="published";break;case m.Failed:this.deliveryStatus="failed"}this.contentType=M(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression,this.content=this.#n.decodeContent(t,this.contentType)}}class q{#n;#i;#r;#o;#a;#d;#c;#l;#p;#m;#h;constructor(e,t,s){this.#n=e,this.#i=t,this.#u(s)}#u(e){this.#r=e?.name??"",this.#o=e?.imageUrl??"",this.#a=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#l=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#m=e?.permissions??void 0,this.#h=e?.createdAtNs??void 0}get id(){return this.#i}get name(){return this.#r}async updateName(e){await this.#n.sendMessage("updateGroupName",{id:this.#i,name:e}),this.#r=e}get imageUrl(){return this.#o}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#o=e}get description(){return this.#a}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#a=e}get pinnedFrameUrl(){return this.#d}async updatePinnedFrameUrl(e){await this.#n.sendMessage("updateGroupPinnedFrameUrl",{id:this.#i,pinnedFrameUrl:e}),this.#d=e}get isActive(){return this.#c}get addedByInboxId(){return this.#l}get createdAtNs(){return this.#h}get createdAt(){return this.#h?(e=this.#h,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#p}async members(){return this.#n.sendMessage("getGroupMembers",{id:this.#i})}async admins(){return this.#n.sendMessage("getGroupAdmins",{id:this.#i})}async superAdmins(){return this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i})}get permissions(){return this.#m}async isAdmin(e){return(await this.admins()).includes(e)}async isSuperAdmin(e){return(await this.superAdmins()).includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#u(e)}async addMembers(e){return this.#n.sendMessage("addGroupMembers",{id:this.#i,accountAddresses:e})}async addMembersByInboxId(e){return this.#n.sendMessage("addGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async removeMembers(e){return this.#n.sendMessage("removeGroupMembers",{id:this.#i,accountAddresses:e})}async removeMembersByInboxId(e){return this.#n.sendMessage("removeGroupMembersByInboxId",{id:this.#i,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("addGroupAdmin",{id:this.#i,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("removeGroupAdmin",{id:this.#i,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("addGroupSuperAdmin",{id:this.#i,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("removeGroupSuperAdmin",{id:this.#i,inboxId:e})}async publishMessages(){return this.#n.sendMessage("publishGroupMessages",{id:this.#i})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendOptimisticGroupMessage",{id:this.#i,content:n})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const n="string"==typeof e?this.#n.encodeContent(e,t??s):this.#n.encodeContent(e,t);return this.#n.sendMessage("sendGroupMessage",{id:this.#i,content:n})}async messages(e){return(await this.#n.sendMessage("getGroupMessages",{id:this.#i,options:e})).map((e=>new R(this.#n,e)))}async consentState(){return this.#n.sendMessage("getGroupConsentState",{id:this.#i})}async updateConsentState(e){return this.#n.sendMessage("updateGroupConsentState",{id:this.#i,state:e})}async dmPeerInboxId(){return this.#n.sendMessage("getDmPeerInboxId",{id:this.#i})}}class W{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async getConversationById(e){return this.#n.sendMessage("getConversationById",{id:e})}async getMessageById(e){return this.#n.sendMessage("getMessageById",{id:e})}async getDmByInboxId(e){return this.#n.sendMessage("getDmByInboxId",{inboxId:e})}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new q(this.#n,e.id,e)))}async listGroups(e){return this.#n.sendMessage("getGroups",{options:e})}async listDms(e){return this.#n.sendMessage("getDms",{options:e})}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new q(this.#n,s.id,s)}async newDm(e){const t=await this.#n.sendMessage("newDm",{accountAddress:e});return new q(this.#n,t.id,t)}}class $ extends y{address;options;#g=!1;#y;#I;#b;#v;constructor(t,s){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),s?.enableLogging??!1),this.address=t,this.options=s,this.#b=new W(this);const i=[new e,new n,...s?.codecs??[]];this.#v=new Map(i.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{address:this.address,options:this.options});this.#y=e.inboxId,this.#I=e.installationId,this.#g=!0}static async create(e,t){const s=new $(e,t);return await s.init(),s}get isReady(){return this.#g}get inboxId(){return this.#y}get installationId(){return this.#I}async getCreateInboxSignatureText(){return this.sendMessage("getCreateInboxSignatureText",void 0)}async getAddWalletSignatureText(e){return this.sendMessage("getAddWalletSignatureText",{accountAddress:e})}async getRevokeWalletSignatureText(e){return this.sendMessage("getRevokeWalletSignatureText",{accountAddress:e})}async getRevokeInstallationsSignatureText(){return this.sendMessage("getRevokeInstallationsSignatureText",void 0)}async addSignature(e,t){return this.sendMessage("addSignature",{type:e,bytes:t})}async applySignatures(){return this.sendMessage("applySignatures",void 0)}async registerIdentity(){return this.sendMessage("registerIdentity",void 0)}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}async findInboxIdByAddress(e){return this.sendMessage("findInboxIdByAddress",{address:e})}async inboxState(e){return this.sendMessage("inboxState",{refreshFromNetwork:e??!1})}async getLatestInboxState(e){return this.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.sendMessage("getConsentState",{entityType:e,entity:t})}get conversations(){return this.#b}codecFor(e){return this.#v.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new Error(`Codec not found for "${t.toString()}" content type`);const n=s.encode(e,this),i=s.fallback(e);return i&&(n.fallback=i),A(n)}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==p.MembershipChange)throw new Error("Error decoding group membership change");const i=S(e.content);return n.decode(i,this)}}const O=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class z{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",O),this.#t=t}sendMessage(e,t){const s=h();this.#e.postMessage({action:e,id:s,data:t});return new Promise(((e,t)=>{this.#s.set(s,{resolve:e,reject:t})}))}handleMessage=e=>{const t=e.data;this.#t&&console.log("utils received event data",t);const s=this.#s.get(t.id);s&&(this.#s.delete(t.id),"error"in t?s.reject(new Error(t.error)):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",O),this.#e.terminate()}}class H extends z{#t;constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1),this.#t=e??!1}async generateInboxId(e){return this.sendMessage("generateInboxId",{address:e,enableLogging:this.#t})}async getInboxIdForAddress(e,t){return this.sendMessage("getInboxIdForAddress",{address:e,env:t,enableLogging:this.#t})}}const J={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"};export{J as ApiUrls,$ as Client,q as Conversation,W as Conversations,R as DecodedMessage,H as Utils,D as WasmGroupMember,b as fromContentTypeId,x as fromEncodedContent,E as fromSafeConsent,M as fromSafeContentTypeId,L as fromSafeCreateGroupOptions,S as fromSafeEncodedContent,j as fromSafeGroupMember,G as fromSafeListConversationsOptions,N as fromSafeListMessagesOptions,I as toContentTypeId,w as toEncodedContent,F as toSafeConsent,v as toSafeContentTypeId,P as toSafeConversation,C as toSafeCreateGroupOptions,A as toSafeEncodedContent,_ as toSafeGroupMember,T as toSafeInboxState,B as toSafeInstallation,U as toSafeListConversationsOptions,f as toSafeListMessagesOptions,k as toSafeMessage};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|