@xmtp/browser-sdk 0.0.17 → 0.0.18
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 +108 -27
- 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/AsyncStream.ts +80 -0
- package/src/ClientWorkerClass.ts +28 -0
- package/src/Conversation.ts +29 -15
- package/src/Conversations.ts +79 -0
- package/src/WorkerClient.ts +2 -2
- package/src/WorkerConversation.ts +12 -8
- package/src/WorkerConversations.ts +47 -1
- package/src/types/clientEvents.ts +39 -9
- package/src/types/clientStreamEvents.ts +30 -0
- package/src/types/utils.ts +26 -0
- package/src/utils/conversions.ts +6 -17
- package/src/workers/client.ts +151 -19
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
2
|
-
import { SignatureRequestType, ConsentState, ConsentEntityType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1,
|
|
2
|
+
import { SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Client as Client$1, EncodedContent, ContentTypeId, DeliveryStatus, GroupMessageKind, SortDirection, ListMessagesOptions, GroupMembershipState, ListConversationsOptions, PermissionPolicySet, GroupPermissionsOptions, CreateGroupOptions, Installation, InboxState, Consent, PermissionLevel, GroupMember, HmacKey } from '@xmtp/wasm-bindings';
|
|
3
3
|
export { Consent, ConsentEntityType, ConsentState, ContentTypeId, ConversationType, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, Message, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection } from '@xmtp/wasm-bindings';
|
|
4
4
|
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
5
5
|
|
|
6
|
+
type ResolveValue<T> = {
|
|
7
|
+
value: T | undefined;
|
|
8
|
+
done: boolean;
|
|
9
|
+
};
|
|
10
|
+
type StreamCallback<T> = (err: Error | null, value: T | undefined) => void | Promise<void>;
|
|
11
|
+
declare class AsyncStream<T> {
|
|
12
|
+
#private;
|
|
13
|
+
onReturn: (() => void) | undefined;
|
|
14
|
+
constructor();
|
|
15
|
+
get isDone(): boolean;
|
|
16
|
+
callback: StreamCallback<T>;
|
|
17
|
+
next: () => Promise<ResolveValue<T>>;
|
|
18
|
+
return: (value: T | undefined) => Promise<{
|
|
19
|
+
done: boolean;
|
|
20
|
+
value: T | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
[Symbol.asyncIterator](): this;
|
|
23
|
+
}
|
|
24
|
+
|
|
6
25
|
declare const ApiUrls: {
|
|
7
26
|
readonly local: "http://localhost:5555";
|
|
8
27
|
readonly dev: "https://dev.xmtp.network";
|
|
@@ -71,9 +90,20 @@ type ClientOptions = NetworkOptions & ContentOptions & StorageOptions & OtherOpt
|
|
|
71
90
|
|
|
72
91
|
type ClientEvents =
|
|
73
92
|
/**
|
|
74
|
-
*
|
|
93
|
+
* Stream actions
|
|
75
94
|
*/
|
|
76
95
|
{
|
|
96
|
+
action: "endStream";
|
|
97
|
+
id: string;
|
|
98
|
+
result: undefined;
|
|
99
|
+
data: {
|
|
100
|
+
streamId: string;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Client actions
|
|
105
|
+
*/
|
|
106
|
+
| {
|
|
77
107
|
action: "init";
|
|
78
108
|
id: string;
|
|
79
109
|
result: {
|
|
@@ -293,6 +323,22 @@ type ClientEvents =
|
|
|
293
323
|
id: string;
|
|
294
324
|
result: SafeHmacKeys;
|
|
295
325
|
data: undefined;
|
|
326
|
+
} | {
|
|
327
|
+
action: "streamAllGroups";
|
|
328
|
+
id: string;
|
|
329
|
+
result: undefined;
|
|
330
|
+
data: {
|
|
331
|
+
streamId: string;
|
|
332
|
+
conversationType?: ConversationType;
|
|
333
|
+
};
|
|
334
|
+
} | {
|
|
335
|
+
action: "streamAllMessages";
|
|
336
|
+
id: string;
|
|
337
|
+
result: undefined;
|
|
338
|
+
data: {
|
|
339
|
+
streamId: string;
|
|
340
|
+
conversationType?: ConversationType;
|
|
341
|
+
};
|
|
296
342
|
}
|
|
297
343
|
/**
|
|
298
344
|
* Group actions
|
|
@@ -460,14 +506,6 @@ type ClientEvents =
|
|
|
460
506
|
id: string;
|
|
461
507
|
imageUrl: string;
|
|
462
508
|
};
|
|
463
|
-
} | {
|
|
464
|
-
action: "updateGroupPinnedFrameUrl";
|
|
465
|
-
id: string;
|
|
466
|
-
result: undefined;
|
|
467
|
-
data: {
|
|
468
|
-
id: string;
|
|
469
|
-
pinnedFrameUrl: string;
|
|
470
|
-
};
|
|
471
509
|
} | {
|
|
472
510
|
action: "getGroupConsentState";
|
|
473
511
|
id: string;
|
|
@@ -507,6 +545,14 @@ type ClientEvents =
|
|
|
507
545
|
data: {
|
|
508
546
|
id: string;
|
|
509
547
|
};
|
|
548
|
+
} | {
|
|
549
|
+
action: "streamGroupMessages";
|
|
550
|
+
id: string;
|
|
551
|
+
result: undefined;
|
|
552
|
+
data: {
|
|
553
|
+
groupId: string;
|
|
554
|
+
streamId: string;
|
|
555
|
+
};
|
|
510
556
|
};
|
|
511
557
|
type ClientEventsActions = ClientEvents["action"];
|
|
512
558
|
type ClientEventsClientMessageData = EventsClientMessageData<ClientEvents>;
|
|
@@ -577,6 +623,27 @@ type EventsErrorData<Events extends GenericEvent> = {
|
|
|
577
623
|
action: Events["action"];
|
|
578
624
|
error: string;
|
|
579
625
|
};
|
|
626
|
+
type GenericStreamEvent = {
|
|
627
|
+
type: string;
|
|
628
|
+
streamId: string;
|
|
629
|
+
result: unknown;
|
|
630
|
+
};
|
|
631
|
+
type StreamEventsClientMessageData<Events extends GenericStreamEvent> = {
|
|
632
|
+
[Type in Events["type"]]: Omit<Extract<Events, {
|
|
633
|
+
type: Type;
|
|
634
|
+
}>, "result">;
|
|
635
|
+
}[Events["type"]];
|
|
636
|
+
type StreamEventsResult<Events extends GenericStreamEvent, Type extends Events["type"]> = Extract<Events, {
|
|
637
|
+
type: Type;
|
|
638
|
+
}>["result"];
|
|
639
|
+
type StreamEventsClientPostMessageData<Events extends GenericStreamEvent, Type extends Events["type"]> = Extract<Events, {
|
|
640
|
+
type: Type;
|
|
641
|
+
}>;
|
|
642
|
+
type StreamEventsErrorData<Events extends GenericStreamEvent> = {
|
|
643
|
+
streamId: string;
|
|
644
|
+
type: Events["type"];
|
|
645
|
+
error: string;
|
|
646
|
+
};
|
|
580
647
|
|
|
581
648
|
declare class WorkerConversations {
|
|
582
649
|
#private;
|
|
@@ -584,7 +651,7 @@ declare class WorkerConversations {
|
|
|
584
651
|
sync(): Promise<void>;
|
|
585
652
|
syncAll(): Promise<number>;
|
|
586
653
|
getConversationById(id: string): WorkerConversation | undefined;
|
|
587
|
-
getMessageById(id: string):
|
|
654
|
+
getMessageById(id: string): Message | undefined;
|
|
588
655
|
getDmByInboxId(inboxId: string): WorkerConversation | undefined;
|
|
589
656
|
list(options?: SafeListConversationsOptions): WorkerConversation[];
|
|
590
657
|
listGroups(options?: Omit<SafeListConversationsOptions, "conversation_type">): WorkerConversation[];
|
|
@@ -592,6 +659,10 @@ declare class WorkerConversations {
|
|
|
592
659
|
newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<WorkerConversation>;
|
|
593
660
|
newDm(accountAddress: string): Promise<WorkerConversation>;
|
|
594
661
|
getHmacKeys(): HmacKeys;
|
|
662
|
+
stream(callback?: StreamCallback<Conversation$1>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
|
|
663
|
+
streamGroups(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
|
|
664
|
+
streamDms(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
|
|
665
|
+
streamAllMessages(callback?: StreamCallback<Message>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
|
|
595
666
|
}
|
|
596
667
|
|
|
597
668
|
declare class WorkerClient {
|
|
@@ -603,7 +674,7 @@ declare class WorkerClient {
|
|
|
603
674
|
get installationId(): string;
|
|
604
675
|
get installationIdBytes(): Uint8Array<ArrayBufferLike>;
|
|
605
676
|
get isRegistered(): boolean;
|
|
606
|
-
createInboxSignatureText():
|
|
677
|
+
createInboxSignatureText(): string | undefined;
|
|
607
678
|
addAccountSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
608
679
|
removeAccountSignatureText(accountAddress: string): Promise<string | undefined>;
|
|
609
680
|
revokeAllAOtherInstallationsSignatureText(): Promise<string | undefined>;
|
|
@@ -613,7 +684,7 @@ declare class WorkerClient {
|
|
|
613
684
|
applySignatures(): Promise<void>;
|
|
614
685
|
canMessage(accountAddresses: string[]): Promise<Map<string, boolean>>;
|
|
615
686
|
registerIdentity(): Promise<void>;
|
|
616
|
-
findInboxIdByAddress(address: string): Promise<string
|
|
687
|
+
findInboxIdByAddress(address: string): Promise<string>;
|
|
617
688
|
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
618
689
|
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
619
690
|
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
@@ -634,8 +705,6 @@ declare class WorkerConversation {
|
|
|
634
705
|
updateImageUrl(imageUrl: string): Promise<void>;
|
|
635
706
|
get description(): string;
|
|
636
707
|
updateDescription(description: string): Promise<void>;
|
|
637
|
-
get pinnedFrameUrl(): string;
|
|
638
|
-
updatePinnedFrameUrl(pinnedFrameUrl: string): Promise<void>;
|
|
639
708
|
get isActive(): boolean;
|
|
640
709
|
get addedByInboxId(): string;
|
|
641
710
|
get createdAtNs(): bigint;
|
|
@@ -665,10 +734,11 @@ declare class WorkerConversation {
|
|
|
665
734
|
publishMessages(): Promise<void>;
|
|
666
735
|
sendOptimistic(encodedContent: EncodedContent): string;
|
|
667
736
|
send(encodedContent: EncodedContent): Promise<string>;
|
|
668
|
-
messages(options?: SafeListMessagesOptions): Promise<
|
|
737
|
+
messages(options?: SafeListMessagesOptions): Promise<Message[]>;
|
|
669
738
|
get consentState(): ConsentState;
|
|
670
739
|
updateConsentState(state: ConsentState): void;
|
|
671
740
|
dmPeerInboxId(): string;
|
|
741
|
+
stream(callback?: StreamCallback<Message>): _xmtp_wasm_bindings.StreamCloser;
|
|
672
742
|
}
|
|
673
743
|
|
|
674
744
|
declare const toContentTypeId: (contentTypeId: ContentTypeId) => ContentTypeId$1;
|
|
@@ -728,8 +798,7 @@ type SafePermissionPolicySet = {
|
|
|
728
798
|
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
729
799
|
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
730
800
|
updateGroupNamePolicy: PermissionPolicy;
|
|
731
|
-
|
|
732
|
-
updateMessageExpirationPolicy: PermissionPolicy;
|
|
801
|
+
updateMessageDisappearingPolicy: PermissionPolicy;
|
|
733
802
|
};
|
|
734
803
|
declare const toSafePermissionPolicySet: (policySet: PermissionPolicySet) => SafePermissionPolicySet;
|
|
735
804
|
declare const fromSafePermissionPolicySet: (policySet: SafePermissionPolicySet) => PermissionPolicySet;
|
|
@@ -739,7 +808,6 @@ type SafeCreateGroupOptions = {
|
|
|
739
808
|
imageUrlSquare?: string;
|
|
740
809
|
name?: string;
|
|
741
810
|
permissions?: GroupPermissionsOptions;
|
|
742
|
-
pinnedFrameUrl?: string;
|
|
743
811
|
};
|
|
744
812
|
declare const toSafeCreateGroupOptions: (options: CreateGroupOptions) => SafeCreateGroupOptions;
|
|
745
813
|
declare const fromSafeCreateGroupOptions: (options: SafeCreateGroupOptions) => CreateGroupOptions;
|
|
@@ -748,7 +816,6 @@ type SafeConversation = {
|
|
|
748
816
|
name: string;
|
|
749
817
|
imageUrl: string;
|
|
750
818
|
description: string;
|
|
751
|
-
pinnedFrameUrl: string;
|
|
752
819
|
permissions: {
|
|
753
820
|
policyType: GroupPermissionsOptions;
|
|
754
821
|
policySet: {
|
|
@@ -759,8 +826,7 @@ type SafeConversation = {
|
|
|
759
826
|
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
760
827
|
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
761
828
|
updateGroupNamePolicy: PermissionPolicy;
|
|
762
|
-
|
|
763
|
-
updateMessageExpirationPolicy: PermissionPolicy;
|
|
829
|
+
updateMessageDisappearingPolicy: PermissionPolicy;
|
|
764
830
|
};
|
|
765
831
|
};
|
|
766
832
|
isActive: boolean;
|
|
@@ -811,11 +877,22 @@ declare const toSafeHmacKey: (hmacKey: HmacKey) => SafeHmacKey;
|
|
|
811
877
|
type HmacKeys = Map<string, HmacKey[]>;
|
|
812
878
|
type SafeHmacKeys = Record<string, SafeHmacKey[]>;
|
|
813
879
|
|
|
880
|
+
type ClientStreamEvents = {
|
|
881
|
+
type: "message";
|
|
882
|
+
streamId: string;
|
|
883
|
+
result: SafeMessage | undefined;
|
|
884
|
+
} | {
|
|
885
|
+
type: "group";
|
|
886
|
+
streamId: string;
|
|
887
|
+
result: SafeConversation | undefined;
|
|
888
|
+
};
|
|
889
|
+
|
|
814
890
|
declare class ClientWorkerClass {
|
|
815
891
|
#private;
|
|
816
892
|
constructor(worker: Worker, enableLogging: boolean);
|
|
817
893
|
sendMessage<A extends ClientEventsActions>(action: A, data: ClientSendMessageData<A>): Promise<ClientEventsResult<A>>;
|
|
818
894
|
handleMessage: (event: MessageEvent<ClientEventsWorkerMessageData | ClientEventsErrorData>) => void;
|
|
895
|
+
handleStreamMessage: <T extends ClientStreamEvents["result"]>(streamId: string, callback: (error: Error | null, value: T | null) => void) => () => void;
|
|
819
896
|
close(): void;
|
|
820
897
|
}
|
|
821
898
|
|
|
@@ -848,8 +925,6 @@ declare class Conversation {
|
|
|
848
925
|
updateImageUrl(imageUrl: string): Promise<void>;
|
|
849
926
|
get description(): string | undefined;
|
|
850
927
|
updateDescription(description: string): Promise<void>;
|
|
851
|
-
get pinnedFrameUrl(): string | undefined;
|
|
852
|
-
updatePinnedFrameUrl(pinnedFrameUrl: string): Promise<void>;
|
|
853
928
|
get isActive(): boolean | undefined;
|
|
854
929
|
get addedByInboxId(): string | undefined;
|
|
855
930
|
get createdAtNs(): bigint | undefined;
|
|
@@ -873,8 +948,7 @@ declare class Conversation {
|
|
|
873
948
|
updateGroupDescriptionPolicy: PermissionPolicy;
|
|
874
949
|
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
875
950
|
updateGroupNamePolicy: PermissionPolicy;
|
|
876
|
-
|
|
877
|
-
updateMessageExpirationPolicy: PermissionPolicy;
|
|
951
|
+
updateMessageDisappearingPolicy: PermissionPolicy;
|
|
878
952
|
};
|
|
879
953
|
}>;
|
|
880
954
|
updatePermission(permissionType: PermissionUpdateType, policy: PermissionPolicy, metadataField?: MetadataField): Promise<undefined>;
|
|
@@ -896,6 +970,7 @@ declare class Conversation {
|
|
|
896
970
|
consentState(): Promise<ConsentState>;
|
|
897
971
|
updateConsentState(state: ConsentState): Promise<undefined>;
|
|
898
972
|
dmPeerInboxId(): Promise<string>;
|
|
973
|
+
stream(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
899
974
|
}
|
|
900
975
|
|
|
901
976
|
declare class Conversations {
|
|
@@ -912,6 +987,12 @@ declare class Conversations {
|
|
|
912
987
|
newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions): Promise<Conversation>;
|
|
913
988
|
newDm(accountAddress: string): Promise<Conversation>;
|
|
914
989
|
getHmacKeys(): Promise<SafeHmacKeys>;
|
|
990
|
+
stream(callback?: StreamCallback<Conversation>, conversationType?: ConversationType): Promise<AsyncStream<Conversation>>;
|
|
991
|
+
streamGroups(callback?: StreamCallback<Conversation>): Promise<AsyncStream<Conversation>>;
|
|
992
|
+
streamDms(callback?: StreamCallback<Conversation>): Promise<AsyncStream<Conversation>>;
|
|
993
|
+
streamAllMessages(callback?: StreamCallback<DecodedMessage>, conversationType?: ConversationType): Promise<AsyncStream<DecodedMessage>>;
|
|
994
|
+
streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
995
|
+
streamAllDmMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
915
996
|
}
|
|
916
997
|
|
|
917
998
|
type SignMessage = (message: string) => Promise<Uint8Array> | Uint8Array;
|
|
@@ -975,4 +1056,4 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
975
1056
|
getInboxIdForAddress(address: string, env?: XmtpEnv): Promise<string | undefined>;
|
|
976
1057
|
}
|
|
977
1058
|
|
|
978
|
-
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 EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, HistorySyncUrls, type HmacKeys, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeHmacKey, type SafeHmacKeys, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SafePermissionPolicySet, type SendMessageData, type Signer, type SmartContractSigner, 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, fromSafePermissionPolicySet, isSmartContractSigner, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafePermissionPolicySet };
|
|
1059
|
+
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 EventsClientMessageData, type EventsClientPostMessageData, type EventsErrorData, type EventsResult, type EventsWorkerMessageData, type EventsWorkerPostMessageData, type GenericEvent, type GenericStreamEvent, HistorySyncUrls, type HmacKeys, type MessageDeliveryStatus, type MessageKind, type NetworkOptions, type OtherOptions, type SafeConsent, type SafeContentTypeId, type SafeConversation, type SafeCreateGroupOptions, type SafeEncodedContent, type SafeGroupMember, type SafeHmacKey, type SafeHmacKeys, type SafeInboxState, type SafeInstallation, type SafeListConversationsOptions, type SafeListMessagesOptions, type SafeMessage, type SafePermissionPolicySet, type SendMessageData, type Signer, type SmartContractSigner, type StorageOptions, type StreamEventsClientMessageData, type StreamEventsClientPostMessageData, type StreamEventsErrorData, type StreamEventsResult, 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, fromSafePermissionPolicySet, isSmartContractSigner, toContentTypeId, toEncodedContent, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeInboxState, toSafeInstallation, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafePermissionPolicySet };
|
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{ContentTypeId as i,EncodedContent as r,ListMessagesOptions as a,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,GroupPermissionsOptions as l,Consent as p,GroupMember as u,GroupMessageKind as g,DeliveryStatus as m,SignatureRequestType as h}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as y}from"uuid";import{ContentTypeId as v}from"@xmtp/content-type-primitives";const I=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class w{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",I),this.#t=t}sendMessage(e,t){const s=y();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",I),this.#e.terminate()}}const b=e=>new v({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),M=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),A=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),S=e=>new v({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),x=e=>({type:b(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),P=e=>new r(M(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),k=e=>({type:A(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),f=e=>({type:S(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),G=e=>({content:k(x(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),U=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),N=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),C=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),T=e=>new o(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),B=e=>({addAdminPolicy:e.addAdminPolicy,addMemberPolicy:e.addMemberPolicy,removeAdminPolicy:e.removeAdminPolicy,removeMemberPolicy:e.removeMemberPolicy,updateGroupDescriptionPolicy:e.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:e.updateGroupPinnedFrameUrlPolicy,updateMessageExpirationPolicy:e.updateMessageExpirationPolicy}),L=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateGroupPinnedFrameUrlPolicy,e.updateMessageExpirationPolicy),E=e=>({description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,name:e.groupName,pinnedFrameUrl:e.groupPinnedFrameUrl,permissions:e.permissions,customPermissionPolicySet:e.customPermissionPolicySet}),F=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.pinnedFrameUrl,e.customPermissionPolicySet&&e.permissions===l.CustomPolicy?L(e.customPermissionPolicySet):void 0),D=async e=>{const t=e.id,s=e.name,n=e.imageUrl,i=e.description,r=e.pinnedFrameUrl,a=e.permissions,o=e.isActive,d=e.addedByInboxId,c=await e.metadata(),l=e.admins,p=e.superAdmins,u=e.createdAtNs,g=a.policyType,m=a.policySet;return{id:t,name:s,imageUrl:n,description:i,pinnedFrameUrl:r,permissions:{policyType:g,policySet:{addAdminPolicy:m.addAdminPolicy,addMemberPolicy:m.addMemberPolicy,removeAdminPolicy:m.removeAdminPolicy,removeMemberPolicy:m.removeMemberPolicy,updateGroupDescriptionPolicy:m.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:m.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:m.updateGroupNamePolicy,updateGroupPinnedFrameUrlPolicy:m.updateGroupPinnedFrameUrlPolicy,updateMessageExpirationPolicy:m.updateMessageExpirationPolicy}},isActive:o,addedByInboxId:d,metadata:c,admins:l,superAdmins:p,createdAtNs:u}},K=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),R=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(K),recoveryAddress:e.recoveryAddress}),j=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),O=e=>new p(e.entityType,e.state,e.entity),q=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),W=e=>new u(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState),$=e=>({key:e.key,epoch:e.epoch});class H{#n;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;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,this.encodedContent=t.content,t.kind){case g.Application:this.kind="application";break;case g.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=S(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 V{#n;#i;#r;#a;#o;#d;#c;#l;#p;#u;#g=[];#m=[];constructor(e,t,s){this.#n=e,this.#i=t,this.#h(s)}#h(e){this.#r=e?.name??"",this.#a=e?.imageUrl??"",this.#o=e?.description??"",this.#d=e?.pinnedFrameUrl??"",this.#c=e?.isActive??void 0,this.#l=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#u=e?.createdAtNs??void 0,this.#g=e?.admins??[],this.#m=e?.superAdmins??[]}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.#a}async updateImageUrl(e){await this.#n.sendMessage("updateGroupImageUrlSquare",{id:this.#i,imageUrl:e}),this.#a=e}get description(){return this.#o}async updateDescription(e){await this.#n.sendMessage("updateGroupDescription",{id:this.#i,description:e}),this.#o=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.#u}get createdAt(){return this.#u?(e=this.#u,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#p}async members(){return this.#n.sendMessage("getGroupMembers",{id:this.#i})}get admins(){return this.#g}get superAdmins(){return this.#m}async syncAdmins(){const e=await this.#n.sendMessage("getGroupAdmins",{id:this.#i});this.#g=e}async syncSuperAdmins(){const e=await this.#n.sendMessage("getGroupSuperAdmins",{id:this.#i});this.#m=e}async permissions(){return this.#n.sendMessage("getGroupPermissions",{id:this.#i})}async updatePermission(e,t,s){return this.#n.sendMessage("updateGroupPermissionPolicy",{id:this.#i,permissionType:e,policy:t,metadataField:s})}async isAdmin(e){return await this.syncAdmins(),this.#g.includes(e)}async isSuperAdmin(e){return await this.syncSuperAdmins(),this.#m.includes(e)}async sync(){const e=await this.#n.sendMessage("syncGroup",{id:this.#i});this.#h(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 H(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 _{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("syncConversations",void 0)}async syncAll(){return this.#n.sendMessage("syncAllConversations",void 0)}async getConversationById(e){const t=await this.#n.sendMessage("getConversationById",{id:e});return t?new V(this.#n,e,t):void 0}async getMessageById(e){const t=await this.#n.sendMessage("getMessageById",{id:e});return t?new H(this.#n,t):void 0}async getDmByInboxId(e){const t=await this.#n.sendMessage("getDmByInboxId",{inboxId:e});return t?new V(this.#n,t.id,t):void 0}async list(e){return(await this.#n.sendMessage("getConversations",{options:e})).map((e=>new V(this.#n,e.id,e)))}async listGroups(e){return(await this.#n.sendMessage("getGroups",{options:e})).map((e=>new V(this.#n,e.id,e)))}async listDms(e){return(await this.#n.sendMessage("getDms",{options:e})).map((e=>new V(this.#n,e.id,e)))}async newGroup(e,t){const s=await this.#n.sendMessage("newGroup",{accountAddresses:e,options:t});return new V(this.#n,s.id,s)}async newDm(e){const t=await this.#n.sendMessage("newDm",{accountAddress:e});return new V(this.#n,t.id,t)}async getHmacKeys(){return this.#n.sendMessage("getHmacKeys",void 0)}}const z=e=>"getBlockNumber"in e&&"getChainId"in e;class J extends w{#y;#v;#I;#w;#b;#M;#A;#S=!1;#x;options;constructor(t,s,i,r){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==r?.loggingLevel&&"off"!==r.loggingLevel),this.#y=s,this.options=r,this.#w=i,this.#x=t,this.#I=new _(this);const a=[new e,new n,...r?.codecs??[]];this.#v=new Map(a.map((e=>[e.contentType.toString(),e])))}get accountAddress(){return this.#y}async init(){const e=await this.sendMessage("init",{address:this.accountAddress,encryptionKey:this.#w,options:this.options});this.#b=e.inboxId,this.#M=e.installationId,this.#A=e.installationIdBytes,this.#S=!0}static async create(e,t,s){const n=await e.getAddress(),i=new J(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#S}get inboxId(){return this.#b}get installationId(){return this.#M}get installationIdBytes(){return this.#A}async#P(){return this.sendMessage("createInboxSignatureText",void 0)}async#k(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#f(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#G(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async#U(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async#N(e,t,s){const n=await s.signMessage(t);z(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#C(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#P();if(e)return await this.#N(h.CreateInbox,e,this.#x),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#k(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#N(h.AddWallet,t,e),await this.#C()}async removeAccount(e){const t=await this.#f(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#N(h.RevokeWallet,t,this.#x),await this.#C()}async revokeAllOtherInstallations(){const e=await this.#G();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.#N(h.RevokeInstallations,e,this.#x),await this.#C()}async revokeInstallations(e){const t=await this.#U(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.#N(h.RevokeInstallations,t,this.#x),await this.#C()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await J.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(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.#I}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),k(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!==g.MembershipChange)throw new Error("Error decoding group membership change");const i=f(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}}const Q=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class X{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",Q),this.#t=t}sendMessage(e,t){const s=y();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",Q),this.#e.terminate()}}class Y extends X{#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 Z={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},ee={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{Z as ApiUrls,J as Client,V as Conversation,_ as Conversations,H as DecodedMessage,ee as HistorySyncUrls,Y as Utils,M as fromContentTypeId,P as fromEncodedContent,O as fromSafeConsent,S as fromSafeContentTypeId,F as fromSafeCreateGroupOptions,f as fromSafeEncodedContent,W as fromSafeGroupMember,T as fromSafeListConversationsOptions,N as fromSafeListMessagesOptions,L as fromSafePermissionPolicySet,z as isSmartContractSigner,b as toContentTypeId,x as toEncodedContent,j as toSafeConsent,A as toSafeContentTypeId,D as toSafeConversation,E as toSafeCreateGroupOptions,k as toSafeEncodedContent,q as toSafeGroupMember,$ as toSafeHmacKey,R as toSafeInboxState,K as toSafeInstallation,C as toSafeListConversationsOptions,U as toSafeListMessagesOptions,G as toSafeMessage,B as toSafePermissionPolicySet};
|
|
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 a,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,GroupPermissionsOptions as l,Consent as u,GroupMember as h,GroupMessageKind as p,DeliveryStatus as g,ConversationType as m,SignatureRequestType as y}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentTypeId,ConversationType,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,Message,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as v}from"uuid";import{ContentTypeId as w}from"@xmtp/content-type-primitives";const I=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class M{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",I),this.#t=t}sendMessage(e,t){const s=v();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))};handleStreamMessage=(e,t)=>{const s=s=>{const n=s.data;n.streamId===e&&("error"in n?t(new Error(n.error),null):t(null,n.result))};return this.#e.addEventListener("message",s),()=>{this.#e.removeEventListener("message",s)}};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",I),this.#e.terminate()}}class b{#n=!1;#i;#r;onReturn=void 0;constructor(){this.#r=[],this.#i=null,this.#n=!1}get isDone(){return this.#n}callback=(e,t)=>{if(e)throw e;this.#n||(this.#i?(this.#i({done:!1,value:t}),this.#i=null):this.#r.push(t))};next=()=>this.#r.length>0?Promise.resolve({done:!1,value:this.#r.shift()}):this.#n?Promise.resolve({done:!0,value:void 0}):new Promise((e=>{this.#i=e}));return=e=>(this.#n=!0,this.onReturn?.(),Promise.resolve({done:!0,value:e}));[Symbol.asyncIterator](){return this}}const A=e=>new w({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),S=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),x=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),k=e=>new w({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),P=e=>({type:A(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),f=e=>new r(S(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),G=e=>({type:x(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),N=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({content:G(P(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),C=e=>({deliveryStatus:e.deliveryStatus,direction:e.direction,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs}),B=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction),L=e=>({allowedStates:e.allowedStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,limit:e.limit}),D=e=>new o(e.allowedStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.limit),U=e=>({addAdminPolicy:e.addAdminPolicy,addMemberPolicy:e.addMemberPolicy,removeAdminPolicy:e.removeAdminPolicy,removeMemberPolicy:e.removeMemberPolicy,updateGroupDescriptionPolicy:e.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:e.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:e.updateGroupNamePolicy,updateMessageDisappearingPolicy:e.updateMessageDisappearingPolicy}),E=e=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),R=e=>({description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,name:e.groupName,permissions:e.permissions,customPermissionPolicySet:e.customPermissionPolicySet}),q=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===l.CustomPolicy?E(e.customPermissionPolicySet):void 0),K=async e=>{const t=e.id,s=e.name,n=e.imageUrl,i=e.description,r=e.permissions,a=e.isActive,o=e.addedByInboxId,d=await e.metadata(),c=e.admins,l=e.superAdmins,u=e.createdAtNs,h=r.policyType,p=r.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:h,policySet:{addAdminPolicy:p.addAdminPolicy,addMemberPolicy:p.addMemberPolicy,removeAdminPolicy:p.removeAdminPolicy,removeMemberPolicy:p.removeMemberPolicy,updateGroupDescriptionPolicy:p.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:p.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:p.updateGroupNamePolicy,updateMessageDisappearingPolicy:p.updateMessageDisappearingPolicy}},isActive:a,addedByInboxId:o,metadata:d,admins:c,superAdmins:l,createdAtNs:u}},j=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),O=e=>({accountAddresses:e.accountAddresses,inboxId:e.inboxId,installations:e.installations.map(j),recoveryAddress:e.recoveryAddress}),W=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),F=e=>new u(e.entityType,e.state,e.entity),$=e=>({accountAddresses:e.accountAddresses,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),H=e=>new h(e.inboxId,e.accountAddresses,e.installationIds,e.permissionLevel,e.consentState),V=e=>({key:e.key,epoch:e.epoch});class _{#a;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;senderInboxId;sentAtNs;constructor(e,t){switch(this.#a=e,this.id=t.id,this.sentAtNs=t.sentAtNs,this.conversationId=t.convoId,this.senderInboxId=t.senderInboxId,this.encodedContent=t.content,t.kind){case p.Application:this.kind="application";break;case p.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case g.Unpublished:this.deliveryStatus="unpublished";break;case g.Published:this.deliveryStatus="published";break;case g.Failed:this.deliveryStatus="failed"}this.contentType=k(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.#a.decodeContent(t,this.contentType)}}class z{#a;#o;#d;#c;#l;#u;#h;#p;#g;#m=[];#y=[];constructor(e,t,s){this.#a=e,this.#o=t,this.#v(s)}#v(e){this.#d=e?.name??"",this.#c=e?.imageUrl??"",this.#l=e?.description??"",this.#u=e?.isActive??void 0,this.#h=e?.addedByInboxId??"",this.#p=e?.metadata??void 0,this.#g=e?.createdAtNs??void 0,this.#m=e?.admins??[],this.#y=e?.superAdmins??[]}get id(){return this.#o}get name(){return this.#d}async updateName(e){await this.#a.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#d=e}get imageUrl(){return this.#c}async updateImageUrl(e){await this.#a.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#c=e}get description(){return this.#l}async updateDescription(e){await this.#a.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#l=e}get isActive(){return this.#u}get addedByInboxId(){return this.#h}get createdAtNs(){return this.#g}get createdAt(){return this.#g?(e=this.#g,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#p}async members(){return this.#a.sendMessage("getGroupMembers",{id:this.#o})}get admins(){return this.#m}get superAdmins(){return this.#y}async syncAdmins(){const e=await this.#a.sendMessage("getGroupAdmins",{id:this.#o});this.#m=e}async syncSuperAdmins(){const e=await this.#a.sendMessage("getGroupSuperAdmins",{id:this.#o});this.#y=e}async permissions(){return this.#a.sendMessage("getGroupPermissions",{id:this.#o})}async updatePermission(e,t,s){return this.#a.sendMessage("updateGroupPermissionPolicy",{id:this.#o,permissionType:e,policy:t,metadataField:s})}async isAdmin(e){return await this.syncAdmins(),this.#m.includes(e)}async isSuperAdmin(e){return await this.syncSuperAdmins(),this.#y.includes(e)}async sync(){const e=await this.#a.sendMessage("syncGroup",{id:this.#o});this.#v(e)}async addMembers(e){return this.#a.sendMessage("addGroupMembers",{id:this.#o,accountAddresses:e})}async addMembersByInboxId(e){return this.#a.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembers(e){return this.#a.sendMessage("removeGroupMembers",{id:this.#o,accountAddresses:e})}async removeMembersByInboxId(e){return this.#a.sendMessage("removeGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async addAdmin(e){return this.#a.sendMessage("addGroupAdmin",{id:this.#o,inboxId:e})}async removeAdmin(e){return this.#a.sendMessage("removeGroupAdmin",{id:this.#o,inboxId:e})}async addSuperAdmin(e){return this.#a.sendMessage("addGroupSuperAdmin",{id:this.#o,inboxId:e})}async removeSuperAdmin(e){return this.#a.sendMessage("removeGroupSuperAdmin",{id:this.#o,inboxId:e})}async publishMessages(){return this.#a.sendMessage("publishGroupMessages",{id:this.#o})}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.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendOptimisticGroupMessage",{id:this.#o,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.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendGroupMessage",{id:this.#o,content:n})}async messages(e){return(await this.#a.sendMessage("getGroupMessages",{id:this.#o,options:e})).map((e=>new _(this.#a,e)))}async consentState(){return this.#a.sendMessage("getGroupConsentState",{id:this.#o})}async updateConsentState(e){return this.#a.sendMessage("updateGroupConsentState",{id:this.#o,state:e})}async dmPeerInboxId(){return this.#a.sendMessage("getDmPeerInboxId",{id:this.#o})}async stream(e){const t=v(),s=new b,n=this.#a.handleStreamMessage(t,((t,n)=>{const i=n?new _(this.#a,n):void 0;s.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}}class J{#a;constructor(e){this.#a=e}async sync(){return this.#a.sendMessage("syncConversations",void 0)}async syncAll(){return this.#a.sendMessage("syncAllConversations",void 0)}async getConversationById(e){const t=await this.#a.sendMessage("getConversationById",{id:e});return t?new z(this.#a,e,t):void 0}async getMessageById(e){const t=await this.#a.sendMessage("getMessageById",{id:e});return t?new _(this.#a,t):void 0}async getDmByInboxId(e){const t=await this.#a.sendMessage("getDmByInboxId",{inboxId:e});return t?new z(this.#a,t.id,t):void 0}async list(e){return(await this.#a.sendMessage("getConversations",{options:e})).map((e=>new z(this.#a,e.id,e)))}async listGroups(e){return(await this.#a.sendMessage("getGroups",{options:e})).map((e=>new z(this.#a,e.id,e)))}async listDms(e){return(await this.#a.sendMessage("getDms",{options:e})).map((e=>new z(this.#a,e.id,e)))}async newGroup(e,t){const s=await this.#a.sendMessage("newGroup",{accountAddresses:e,options:t});return new z(this.#a,s.id,s)}async newDm(e){const t=await this.#a.sendMessage("newDm",{accountAddress:e});return new z(this.#a,t.id,t)}async getHmacKeys(){return this.#a.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=v(),n=new b,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new z(this.#a,s.id,s):void 0;n.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamAllGroups",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),i()},n}async streamGroups(e){return this.stream(e,m.Group)}async streamDms(e){return this.stream(e,m.Dm)}async streamAllMessages(e,t){const s=v(),n=new b,i=this.#a.handleStreamMessage(s,((t,s)=>{const i=s?new _(this.#a,s):void 0;n.callback(t,i),e?.(t,i)}));return await this.#a.sendMessage("streamAllMessages",{streamId:s,conversationType:t}),n.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),i()},n}async streamAllGroupMessages(e){return this.streamAllMessages(e,m.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,m.Dm)}}const Q=e=>"getBlockNumber"in e&&"getChainId"in e;class X extends M{#w;#I;#M;#b;#A;#S;#x;#k=!1;#P;options;constructor(t,s,i,r){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==r?.loggingLevel&&"off"!==r.loggingLevel),this.#w=s,this.options=r,this.#b=i,this.#P=t,this.#M=new J(this);const a=[new e,new n,...r?.codecs??[]];this.#I=new Map(a.map((e=>[e.contentType.toString(),e])))}get accountAddress(){return this.#w}async init(){const e=await this.sendMessage("init",{address:this.accountAddress,encryptionKey:this.#b,options:this.options});this.#A=e.inboxId,this.#S=e.installationId,this.#x=e.installationIdBytes,this.#k=!0}static async create(e,t,s){const n=await e.getAddress(),i=new X(e,n,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#k}get inboxId(){return this.#A}get installationId(){return this.#S}get installationIdBytes(){return this.#x}async#f(){return this.sendMessage("createInboxSignatureText",void 0)}async#G(e){return this.sendMessage("addAccountSignatureText",{newAccountAddress:e})}async#N(e){return this.sendMessage("removeAccountSignatureText",{accountAddress:e})}async#T(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async#C(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async#B(e,t,s){const n=await s.signMessage(t);Q(s)?await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber()}):await this.sendMessage("addSignature",{type:e,bytes:n})}async#L(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.#f();if(e)return await this.#B(y.CreateInbox,e,this.#P),this.sendMessage("registerIdentity",void 0)}async addAccount(e){const t=await this.#G(await e.getAddress());if(!t)throw new Error("Unable to generate add account signature text");await this.#B(y.AddWallet,t,e),await this.#L()}async removeAccount(e){const t=await this.#N(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.#B(y.RevokeWallet,t,this.#P),await this.#L()}async revokeAllOtherInstallations(){const e=await this.#T();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.#B(y.RevokeInstallations,e,this.#P),await this.#L()}async revokeInstallations(e){const t=await this.#C(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.#B(y.RevokeInstallations,t,this.#P),await this.#L()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{accountAddresses:e})}static async canMessage(e,t){const s={getAddress:()=>"0x0000000000000000000000000000000000000000",signMessage:()=>new Uint8Array};return(await X.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(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.#M}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),G(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=N(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}}const Y=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",Y),this.#t=t}sendMessage(e,t){const s=v();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",Y),this.#e.terminate()}}class ee 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 te={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},se={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{te as ApiUrls,X as Client,z as Conversation,J as Conversations,_ as DecodedMessage,se as HistorySyncUrls,ee as Utils,S as fromContentTypeId,f as fromEncodedContent,F as fromSafeConsent,k as fromSafeContentTypeId,q as fromSafeCreateGroupOptions,N as fromSafeEncodedContent,H as fromSafeGroupMember,D as fromSafeListConversationsOptions,B as fromSafeListMessagesOptions,E as fromSafePermissionPolicySet,Q as isSmartContractSigner,A as toContentTypeId,P as toEncodedContent,W as toSafeConsent,x as toSafeContentTypeId,K as toSafeConversation,R as toSafeCreateGroupOptions,G as toSafeEncodedContent,$ as toSafeGroupMember,V as toSafeHmacKey,O as toSafeInboxState,j as toSafeInstallation,L as toSafeListConversationsOptions,C as toSafeListMessagesOptions,T as toSafeMessage,U as toSafePermissionPolicySet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|