@xmtp/browser-sdk 1.0.0-rc1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +25 -13
- 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 +3 -2
- package/src/Client.ts +11 -24
- package/src/Conversations.ts +0 -46
- package/src/Preferences.ts +75 -0
- package/src/WorkerClient.ts +13 -24
- package/src/WorkerConversations.ts +0 -25
- package/src/WorkerPreferences.ts +58 -0
- package/src/index.ts +1 -0
- package/src/workers/client.ts +10 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
2
|
-
import { Identifier, SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Consent, UserPreference, Client as Client$1, EncodedContent, MessageDisappearingSettings, GroupPermissionsOptions, DeliveryStatus, GroupMessageKind, ContentType, SortDirection, PermissionLevel, ContentTypeId, ListMessagesOptions, ListConversationsOptions, PermissionPolicySet, CreateGroupOptions, CreateDMOptions, HmacKey, Installation, InboxState, GroupMember } from '@xmtp/wasm-bindings';
|
|
3
|
-
export { Consent, ConsentEntityType, ConsentState, ContentType, ContentTypeId, ConversationListItem, ConversationType, CreateDMOptions, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, Identifier, IdentifierKind, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, LogOptions, Message, MessageDisappearingSettings, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
|
|
4
1
|
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
2
|
+
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
3
|
+
import { Identifier, SignatureRequestType, ConsentState, ConsentEntityType, ConversationType, PermissionUpdateType, PermissionPolicy, MetadataField, Conversations as Conversations$1, Message, Conversation as Conversation$1, Client as Client$1, Consent, UserPreference, EncodedContent, MessageDisappearingSettings, GroupPermissionsOptions, DeliveryStatus, GroupMessageKind, ContentType, SortDirection, PermissionLevel, ContentTypeId, ListMessagesOptions, ListConversationsOptions, PermissionPolicySet, CreateGroupOptions, CreateDMOptions, HmacKey, Installation, InboxState, GroupMember } from '@xmtp/wasm-bindings';
|
|
4
|
+
export { Consent, ConsentEntityType, ConsentState, ContentType, ContentTypeId, ConversationListItem, ConversationType, CreateDMOptions, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, HmacKey, Identifier, IdentifierKind, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, LogOptions, Message, MessageDisappearingSettings, MetadataField, Opfs, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestType, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
|
|
5
5
|
|
|
6
6
|
type ResolveValue<T> = {
|
|
7
7
|
value: T | undefined;
|
|
@@ -733,6 +733,15 @@ declare class WorkerConversations {
|
|
|
733
733
|
streamGroups(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
|
|
734
734
|
streamDms(callback?: StreamCallback<Conversation$1>): _xmtp_wasm_bindings.StreamCloser;
|
|
735
735
|
streamAllMessages(callback?: StreamCallback<Message>, conversationType?: ConversationType): _xmtp_wasm_bindings.StreamCloser;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
declare class WorkerPreferences {
|
|
739
|
+
#private;
|
|
740
|
+
constructor(client: Client$1, conversations: Conversations$1);
|
|
741
|
+
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
742
|
+
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
743
|
+
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
744
|
+
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
736
745
|
streamConsent(callback?: StreamCallback<Consent[]>): _xmtp_wasm_bindings.StreamCloser;
|
|
737
746
|
streamPreferences(callback?: StreamCallback<UserPreference[]>): _xmtp_wasm_bindings.StreamCloser;
|
|
738
747
|
}
|
|
@@ -746,6 +755,8 @@ declare class WorkerClient {
|
|
|
746
755
|
get installationId(): string;
|
|
747
756
|
get installationIdBytes(): Uint8Array<ArrayBufferLike>;
|
|
748
757
|
get isRegistered(): boolean;
|
|
758
|
+
get conversations(): WorkerConversations;
|
|
759
|
+
get preferences(): WorkerPreferences;
|
|
749
760
|
createInboxSignatureText(): string | undefined;
|
|
750
761
|
addAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
751
762
|
removeAccountSignatureText(identifier: Identifier): Promise<string | undefined>;
|
|
@@ -757,11 +768,6 @@ declare class WorkerClient {
|
|
|
757
768
|
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
758
769
|
registerIdentity(): Promise<void>;
|
|
759
770
|
findInboxIdByIdentifier(identifier: Identifier): Promise<string | undefined>;
|
|
760
|
-
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
761
|
-
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
762
|
-
setConsentStates(records: SafeConsent[]): Promise<void>;
|
|
763
|
-
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
764
|
-
get conversations(): WorkerConversations;
|
|
765
771
|
signWithInstallationKey(signatureText: string): Uint8Array<ArrayBufferLike>;
|
|
766
772
|
verifySignedWithInstallationKey(signatureText: string, signatureBytes: Uint8Array): boolean;
|
|
767
773
|
verifySignedWithPublicKey(signatureText: string, signatureBytes: Uint8Array, publicKey: Uint8Array): boolean;
|
|
@@ -1109,6 +1115,15 @@ declare class Conversations {
|
|
|
1109
1115
|
streamAllMessages(callback?: StreamCallback<DecodedMessage>, conversationType?: ConversationType): Promise<AsyncStream<DecodedMessage>>;
|
|
1110
1116
|
streamAllGroupMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
1111
1117
|
streamAllDmMessages(callback?: StreamCallback<DecodedMessage>): Promise<AsyncStream<DecodedMessage>>;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
declare class Preferences {
|
|
1121
|
+
#private;
|
|
1122
|
+
constructor(client: Client);
|
|
1123
|
+
inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
|
|
1124
|
+
getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
|
|
1125
|
+
setConsentStates(records: SafeConsent[]): Promise<undefined>;
|
|
1126
|
+
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
1112
1127
|
streamConsent(callback?: StreamCallback<SafeConsent[]>): Promise<AsyncStream<SafeConsent[]>>;
|
|
1113
1128
|
streamPreferences(callback?: StreamCallback<UserPreference[]>): Promise<AsyncStream<UserPreference[]>>;
|
|
1114
1129
|
}
|
|
@@ -1140,6 +1155,8 @@ declare class Client extends ClientWorkerClass {
|
|
|
1140
1155
|
accountIdentifier(): Promise<Identifier>;
|
|
1141
1156
|
get installationId(): string | undefined;
|
|
1142
1157
|
get installationIdBytes(): Uint8Array<ArrayBufferLike> | undefined;
|
|
1158
|
+
get conversations(): Conversations;
|
|
1159
|
+
get preferences(): Preferences;
|
|
1143
1160
|
/**
|
|
1144
1161
|
* WARNING: This function should be used with caution. It is only provided
|
|
1145
1162
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1221,11 +1238,6 @@ declare class Client extends ClientWorkerClass {
|
|
|
1221
1238
|
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
1222
1239
|
static canMessage(identifiers: Identifier[], env?: XmtpEnv): Promise<Map<string, boolean>>;
|
|
1223
1240
|
findInboxIdByIdentifier(identifier: Identifier): Promise<string | undefined>;
|
|
1224
|
-
inboxState(refreshFromNetwork?: boolean): Promise<SafeInboxState>;
|
|
1225
|
-
getLatestInboxState(inboxId: string): Promise<SafeInboxState>;
|
|
1226
|
-
setConsentStates(records: SafeConsent[]): Promise<undefined>;
|
|
1227
|
-
getConsentState(entityType: ConsentEntityType, entity: string): Promise<_xmtp_wasm_bindings.ConsentState>;
|
|
1228
|
-
get conversations(): Conversations;
|
|
1229
1241
|
codecFor(contentType: ContentTypeId$1): ContentCodec | undefined;
|
|
1230
1242
|
encodeContent(content: any, contentType: ContentTypeId$1): SafeEncodedContent;
|
|
1231
1243
|
decodeContent(message: SafeMessage, contentType: ContentTypeId$1): any;
|
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 i}from"@xmtp/content-type-text";import{ContentTypeId as n,EncodedContent as r,ListMessagesOptions as a,ListConversationsOptions as o,PermissionPolicySet as d,CreateGroupOptions as c,CreateDMOptions as l,Consent as u,GroupMember as g,MessageDisappearingSettings as p,GroupPermissionsOptions as h,GroupMessageKind as m,DeliveryStatus as y,ConversationType as I,SignatureRequestType as v}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentType,ContentTypeId,ConversationListItem,ConversationType,CreateDMOptions,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,LogOptions,Message,MessageDisappearingSettings,MetadataField,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as w}from"uuid";import{ContentTypeId as M}from"@xmtp/content-type-primitives";const b=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class f{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",b),this.#t=t}sendMessage(e,t){const s=w();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 i=s.data;i.streamId===e&&("error"in i?t(new Error(i.error),null):t(null,i.result))};return this.#e.addEventListener("message",s),()=>{this.#e.removeEventListener("message",s)}};close(){this.#e.removeEventListener("message",this.handleMessage),this.#e.removeEventListener("error",b),this.#e.terminate()}}class S{#i=!1;#n;#r;onReturn=void 0;constructor(){this.#r=[],this.#n=null,this.#i=!1}get isDone(){return this.#i}callback=(e,t)=>{if(e)throw e;this.#i||(this.#n?(this.#n({done:!1,value:t}),this.#n=null):this.#r.push(t))};next=()=>this.#r.length>0?Promise.resolve({done:!1,value:this.#r.shift()}):this.#i?Promise.resolve({done:!0,value:void 0}):new Promise((e=>{this.#n=e}));return=e=>(this.#i=!0,this.onReturn?.(),Promise.resolve({done:!0,value:e}));[Symbol.asyncIterator](){return this}}const x=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),A=e=>new n(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),k=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),P=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),D=e=>({type:x(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),G=e=>new r(A(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),N=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:P(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:N(D(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),L=e=>({contentTypes:e.contentTypes,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,e.contentTypes),E=e=>({consentStates:e.consentStates,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,limit:e.limit}),U=e=>new o(e.consentStates,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.limit),R=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=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),W=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),q=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===h.CustomPolicy?_(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),O=e=>({messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0}),K=e=>new l(e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),j=async e=>{const t=e.id,s=e.name,i=e.imageUrl,n=e.description,r=e.permissions,a=e.isActive,o=e.addedByInboxId,d=await e.metadata(),c=e.admins,l=e.superAdmins,u=e.createdAtNs,g=r.policyType,p=r.policySet;return{id:t,name:s,imageUrl:i,description:n,permissions:{policyType:g,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}},F=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),$=e=>({accountIdentifiers:e.accountIdentifiers,inboxId:e.inboxId,installations:e.installations.map(F),recoveryIdentifier:e.recoveryIdentifier}),H=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),V=e=>new u(e.entityType,e.state,e.entity),z=e=>({accountIdentifiers:e.accountIdentifiers,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),J=e=>new g(e.inboxId,e.accountIdentifiers,e.installationIds,e.permissionLevel,e.consentState),Q=e=>({key:e.key,epoch:e.epoch}),X=e=>({fromNs:e.fromNs,inNs:e.inNs}),Y=e=>new p(e.fromNs,e.inNs);class Z{#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 m.Application:this.kind="application";break;case m.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case y.Unpublished:this.deliveryStatus="unpublished";break;case y.Published:this.deliveryStatus="published";break;case y.Failed:this.deliveryStatus="failed"}this.contentType=P(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 ee{#a;#o;#d;#c;#l;#u;constructor(e,t,s){this.#a=e,this.#o=t,this.#g(s)}#g(e){this.#d=e?.isActive??void 0,this.#c=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#u=e?.createdAtNs??void 0}get id(){return this.#o}get isActive(){return this.#d}get addedByInboxId(){return this.#c}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.#l}async members(){return this.#a.sendMessage("getGroupMembers",{id:this.#o})}async sync(){const e=await this.#a.sendMessage("syncGroup",{id:this.#o});return this.#g(e),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 i="string"==typeof e?this.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendOptimisticGroupMessage",{id:this.#o,content:i})}async send(e,t){if("string"!=typeof e&&!t)throw new Error("Content type is required when sending content other than text");const i="string"==typeof e?this.#a.encodeContent(e,t??s):this.#a.encodeContent(e,t);return this.#a.sendMessage("sendGroupMessage",{id:this.#o,content:i})}async messages(e){return(await this.#a.sendMessage("getGroupMessages",{id:this.#o,options:e})).map((e=>new Z(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 messageDisappearingSettings(){return this.#a.sendMessage("getGroupMessageDisappearingSettings",{id:this.#o})}async updateMessageDisappearingSettings(e,t){return this.#a.sendMessage("updateGroupMessageDisappearingSettings",{id:this.#o,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#a.sendMessage("removeGroupMessageDisappearingSettings",{id:this.#o})}async isMessageDisappearingEnabled(){return this.#a.sendMessage("isGroupMessageDisappearingEnabled",{id:this.#o})}async stream(e){const t=w(),s=new S,i=this.#a.handleStreamMessage(t,((t,i)=>{if(t)return s.callback(t,void 0),void e?.(t,void 0);const n=i?new Z(this.#a,i):void 0;s.callback(null,n),e?.(null,n)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),i()},s}async pausedForVersion(){return this.#a.sendMessage("getGroupPausedForVersion",{id:this.#o})}}class te extends ee{#a;#o;constructor(e,t,s){super(e,t,s),this.#a=e,this.#o=t}async peerInboxId(){return this.#a.sendMessage("getDmPeerInboxId",{id:this.#o})}}class se extends ee{#a;#o;#p;#h;#m;#y=[];#I=[];#g(e){this.#p=e?.name??"",this.#h=e?.imageUrl??"",this.#m=e?.description??"",this.#y=e?.admins??[],this.#I=e?.superAdmins??[]}constructor(e,t,s){super(e,t,s),this.#a=e,this.#o=t,this.#g(s)}async sync(){const e=await super.sync();return this.#g(e),e}get name(){return this.#p}async updateName(e){await this.#a.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#p=e}get imageUrl(){return this.#h}async updateImageUrl(e){await this.#a.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#h=e}get description(){return this.#m}async updateDescription(e){await this.#a.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#m=e}get admins(){return this.#y}get superAdmins(){return this.#I}async listAdmins(){const e=await this.#a.sendMessage("getGroupAdmins",{id:this.#o});return this.#y=e,e}async listSuperAdmins(){const e=await this.#a.sendMessage("getGroupSuperAdmins",{id:this.#o});return this.#I=e,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.listAdmins()).includes(e)}async isSuperAdmin(e){return(await this.listSuperAdmins()).includes(e)}async addMembersByIdentifiers(e){return this.#a.sendMessage("addGroupMembers",{id:this.#o,identifiers:e})}async addMembers(e){return this.#a.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembersByIdentifiers(e){return this.#a.sendMessage("removeGroupMembers",{id:this.#o,identifiers:e})}async removeMembers(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})}}class ie{#a;constructor(e){this.#a=e}async sync(){return this.#a.sendMessage("syncConversations",void 0)}async syncAll(e){return this.#a.sendMessage("syncAllConversations",{consentStates:e})}async getConversationById(e){const t=await this.#a.sendMessage("getConversationById",{id:e});if(t)return"group"===t.metadata.conversationType?new se(this.#a,t.id,t):new te(this.#a,t.id,t)}async getMessageById(e){const t=await this.#a.sendMessage("getMessageById",{id:e});return t?new Z(this.#a,t):void 0}async getDmByInboxId(e){const t=await this.#a.sendMessage("getDmByInboxId",{inboxId:e});return t?new te(this.#a,t.id,t):void 0}async list(e){return(await this.#a.sendMessage("getConversations",{options:e})).map((e=>"group"===e.metadata.conversationType?new se(this.#a,e.id,e):new te(this.#a,e.id,e)))}async listGroups(e){return(await this.#a.sendMessage("getGroups",{options:e})).map((e=>new se(this.#a,e.id,e)))}async listDms(e){return(await this.#a.sendMessage("getDms",{options:e})).map((e=>new te(this.#a,e.id,e)))}async newGroupWithIdentifiers(e,t){const s=await this.#a.sendMessage("newGroupWithIdentifiers",{identifiers:e,options:t});return new se(this.#a,s.id,s)}async newGroup(e,t){const s=await this.#a.sendMessage("newGroupWithInboxIds",{inboxIds:e,options:t});return new se(this.#a,s.id,s)}async newDmWithIdentifier(e,t){const s=await this.#a.sendMessage("newDmWithIdentifier",{identifier:e,options:t});return new te(this.#a,s.id,s)}async newDm(e,t){const s=await this.#a.sendMessage("newDmWithInboxId",{inboxId:e,options:t});return new te(this.#a,s.id,s)}async getHmacKeys(){return this.#a.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=w(),i=new S,n=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return i.callback(t,void 0),void e?.(t,void 0);let n;s&&(n="group"===s.metadata.conversationType?new se(this.#a,s.id,s):new te(this.#a,s.id,s)),i.callback(null,n),e?.(null,n)}));return await this.#a.sendMessage("streamAllGroups",{streamId:s,conversationType:t}),i.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),n()},i}async streamGroups(e){return this.stream(e,I.Group)}async streamDms(e){return this.stream(e,I.Dm)}async streamAllMessages(e,t){const s=w(),i=new S,n=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return i.callback(t,void 0),void e?.(t,void 0);const n=s?new Z(this.#a,s):void 0;i.callback(null,n),e?.(null,n)}));return await this.#a.sendMessage("streamAllMessages",{streamId:s,conversationType:t}),i.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:s}),n()},i}async streamAllGroupMessages(e){return this.streamAllMessages(e,I.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,I.Dm)}async streamConsent(e){const t=w(),s=new S,i=this.#a.handleStreamMessage(t,((t,i)=>{s.callback(t,i??void 0),e?.(t,i??void 0)}));return await this.#a.sendMessage("streamConsent",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),i()},s}async streamPreferences(e){const t=w(),s=new S,i=this.#a.handleStreamMessage(t,((t,i)=>{s.callback(t,i??void 0),e?.(t,i??void 0)}));return await this.#a.sendMessage("streamPreferences",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),i()},s}}class ne extends f{#v;#w;#M;#b;#f;#S;#x=!1;#A;options;constructor(t,s,n){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==n?.loggingLevel&&"off"!==n.loggingLevel),this.options=n,this.#M=s,this.#A=t,this.#w=new ie(this);const r=[new e,new i,...n?.codecs??[]];this.#v=new Map(r.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{identifier:await this.#A.getIdentifier(),encryptionKey:this.#M,options:this.options});this.#b=e.inboxId,this.#f=e.installationId,this.#S=e.installationIdBytes,this.#x=!0}static async create(e,t,s){const i=new ne(e,t,s);return await i.init(),s?.disableAutoRegister||await i.register(),i}get isReady(){return this.#x}get inboxId(){return this.#b}async accountIdentifier(){return this.#A.getIdentifier()}get installationId(){return this.#f}get installationIdBytes(){return this.#S}async unsafe_createInboxSignatureText(){return this.sendMessage("createInboxSignatureText",void 0)}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new Error("Unable to create add account signature text, `allowInboxReassign` must be true");return this.sendMessage("addAccountSignatureText",{newIdentifier:e})}async unsafe_removeAccountSignatureText(e){return this.sendMessage("removeAccountSignatureText",{identifier:e})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async unsafe_revokeInstallationsSignatureText(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async unsafe_addSignature(e,t,s){const i=await s.signMessage(t);switch(s.type){case"SCW":await this.sendMessage("addScwSignature",{type:e,bytes:i,chainId:s.getChainId(),blockNumber:s.getBlockNumber?.()});break;case"EOA":await this.sendMessage("addEcdsaSignature",{type:e,bytes:i})}}async unsafe_applySignatures(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.unsafe_createInboxSignatureText();if(e)return await this.unsafe_addSignature(v.CreateInbox,e,this.#A),this.sendMessage("registerIdentity",void 0)}async unsafe_addAccount(e,t=!1){const s=await this.findInboxIdByIdentifier(await e.getIdentifier());if(s&&!t)throw new Error(`Signer address already associated with inbox ${s}`);const i=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0);if(!i)throw new Error("Unable to generate add account signature text");await this.unsafe_addSignature(v.AddWallet,i,e),await this.unsafe_applySignatures()}async removeAccount(e){const t=await this.unsafe_removeAccountSignatureText(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.unsafe_addSignature(v.RevokeWallet,t,this.#A),await this.unsafe_applySignatures()}async revokeAllOtherInstallations(){const e=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.unsafe_addSignature(v.RevokeInstallations,e,this.#A),await this.unsafe_applySignatures()}async revokeInstallations(e){const t=await this.unsafe_revokeInstallationsSignatureText(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.unsafe_addSignature(v.RevokeInstallations,t,this.#A),await this.unsafe_applySignatures()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{identifiers:e})}static async canMessage(e,t){const s={type:"EOA",getIdentifier:()=>({identifier:"0x0000000000000000000000000000000000000000",identifierKind:"Ethereum"}),signMessage:()=>new Uint8Array};return(await ne.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(e)}async findInboxIdByIdentifier(e){return this.sendMessage("findInboxIdByIdentifier",{identifier: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.#w}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 i=s.encode(e,this),n=s.fallback(e);return n&&(i.fallback=n),N(i)}decodeContent(e,s){const i=this.codecFor(s);if(!i)throw new Error(`Codec not found for "${s.toString()}" content type`);if(s.sameAs(t)&&e.kind!==m.MembershipChange)throw new Error("Error decoding group membership change");const n=T(e.content);return i.decode(n,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 re=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class ae{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",re),this.#t=t}sendMessage(e,t){const s=w();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",re),this.#e.terminate()}}class oe extends ae{#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",{identifier:e,enableLogging:this.#t})}async getInboxIdForIdentifier(e,t){return this.sendMessage("getInboxIdForIdentifier",{identifier:e,env:t,enableLogging:this.#t})}}const de={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},ce={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{de as ApiUrls,ne as Client,ee as Conversation,ie as Conversations,Z as DecodedMessage,te as Dm,se as Group,ce as HistorySyncUrls,oe as Utils,A as fromContentTypeId,G as fromEncodedContent,V as fromSafeConsent,P as fromSafeContentTypeId,K as fromSafeCreateDmOptions,q as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,J as fromSafeGroupMember,U as fromSafeListConversationsOptions,B as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,_ as fromSafePermissionPolicySet,x as toContentTypeId,D as toEncodedContent,H as toSafeConsent,k as toSafeContentTypeId,j as toSafeConversation,O as toSafeCreateDmOptions,W as toSafeCreateGroupOptions,N as toSafeEncodedContent,z as toSafeGroupMember,Q as toSafeHmacKey,$ as toSafeInboxState,F as toSafeInstallation,E as toSafeListConversationsOptions,L as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R 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,CreateDMOptions as l,Consent as u,GroupMember as g,MessageDisappearingSettings as p,GroupPermissionsOptions as h,GroupMessageKind as m,DeliveryStatus as y,ConversationType as I,SignatureRequestType as v}from"@xmtp/wasm-bindings";export{Consent,ConsentEntityType,ConsentState,ContentType,ContentTypeId,ConversationListItem,ConversationType,CreateDMOptions,CreateGroupOptions,DeliveryStatus,EncodedContent,GroupMember,GroupMembershipState,GroupMessageKind,GroupMetadata,GroupPermissions,GroupPermissionsOptions,HmacKey,InboxState,Installation,ListConversationsOptions,ListMessagesOptions,LogOptions,Message,MessageDisappearingSettings,MetadataField,Opfs,PermissionLevel,PermissionPolicy,PermissionPolicySet,PermissionUpdateType,SignatureRequestType,SortDirection}from"@xmtp/wasm-bindings";import{v4 as w}from"uuid";import{ContentTypeId as M}from"@xmtp/content-type-primitives";const b=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class f{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",b),this.#t=t}sendMessage(e,t){const s=w();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",b),this.#e.terminate()}}class S{#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 x=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),A=e=>new i(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),k=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),P=e=>new M({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),D=e=>({type:x(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),G=e=>new r(A(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),N=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:P(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:N(D(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),L=e=>({contentTypes:e.contentTypes,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,e.contentTypes),E=e=>({consentStates:e.consentStates,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,limit:e.limit}),U=e=>new o(e.consentStates,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.limit),R=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=>new d(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),W=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),O=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===h.CustomPolicy?_(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),q=e=>({messageDisappearingSettings:e.messageDisappearingSettings?X(e.messageDisappearingSettings):void 0}),K=e=>new l(e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0),j=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,g=r.policyType,p=r.policySet;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:g,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}},F=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),$=e=>({accountIdentifiers:e.accountIdentifiers,inboxId:e.inboxId,installations:e.installations.map(F),recoveryIdentifier:e.recoveryIdentifier}),H=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),V=e=>new u(e.entityType,e.state,e.entity),z=e=>({accountIdentifiers:e.accountIdentifiers,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),J=e=>new g(e.inboxId,e.accountIdentifiers,e.installationIds,e.permissionLevel,e.consentState),Q=e=>({key:e.key,epoch:e.epoch}),X=e=>({fromNs:e.fromNs,inNs:e.inNs}),Y=e=>new p(e.fromNs,e.inNs);class Z{#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 m.Application:this.kind="application";break;case m.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case y.Unpublished:this.deliveryStatus="unpublished";break;case y.Published:this.deliveryStatus="published";break;case y.Failed:this.deliveryStatus="failed"}this.contentType=P(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 ee{#a;#o;#d;#c;#l;#u;constructor(e,t,s){this.#a=e,this.#o=t,this.#g(s)}#g(e){this.#d=e?.isActive??void 0,this.#c=e?.addedByInboxId??"",this.#l=e?.metadata??void 0,this.#u=e?.createdAtNs??void 0}get id(){return this.#o}get isActive(){return this.#d}get addedByInboxId(){return this.#c}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.#l}async members(){return this.#a.sendMessage("getGroupMembers",{id:this.#o})}async sync(){const e=await this.#a.sendMessage("syncGroup",{id:this.#o});return this.#g(e),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 Z(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 messageDisappearingSettings(){return this.#a.sendMessage("getGroupMessageDisappearingSettings",{id:this.#o})}async updateMessageDisappearingSettings(e,t){return this.#a.sendMessage("updateGroupMessageDisappearingSettings",{id:this.#o,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#a.sendMessage("removeGroupMessageDisappearingSettings",{id:this.#o})}async isMessageDisappearingEnabled(){return this.#a.sendMessage("isGroupMessageDisappearingEnabled",{id:this.#o})}async stream(e){const t=w(),s=new S,n=this.#a.handleStreamMessage(t,((t,n)=>{if(t)return s.callback(t,void 0),void e?.(t,void 0);const i=n?new Z(this.#a,n):void 0;s.callback(null,i),e?.(null,i)}));return await this.#a.sendMessage("streamGroupMessages",{groupId:this.#o,streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}async pausedForVersion(){return this.#a.sendMessage("getGroupPausedForVersion",{id:this.#o})}}class te extends ee{#a;#o;constructor(e,t,s){super(e,t,s),this.#a=e,this.#o=t}async peerInboxId(){return this.#a.sendMessage("getDmPeerInboxId",{id:this.#o})}}class se extends ee{#a;#o;#p;#h;#m;#y=[];#I=[];#g(e){this.#p=e?.name??"",this.#h=e?.imageUrl??"",this.#m=e?.description??"",this.#y=e?.admins??[],this.#I=e?.superAdmins??[]}constructor(e,t,s){super(e,t,s),this.#a=e,this.#o=t,this.#g(s)}async sync(){const e=await super.sync();return this.#g(e),e}get name(){return this.#p}async updateName(e){await this.#a.sendMessage("updateGroupName",{id:this.#o,name:e}),this.#p=e}get imageUrl(){return this.#h}async updateImageUrl(e){await this.#a.sendMessage("updateGroupImageUrlSquare",{id:this.#o,imageUrl:e}),this.#h=e}get description(){return this.#m}async updateDescription(e){await this.#a.sendMessage("updateGroupDescription",{id:this.#o,description:e}),this.#m=e}get admins(){return this.#y}get superAdmins(){return this.#I}async listAdmins(){const e=await this.#a.sendMessage("getGroupAdmins",{id:this.#o});return this.#y=e,e}async listSuperAdmins(){const e=await this.#a.sendMessage("getGroupSuperAdmins",{id:this.#o});return this.#I=e,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.listAdmins()).includes(e)}async isSuperAdmin(e){return(await this.listSuperAdmins()).includes(e)}async addMembersByIdentifiers(e){return this.#a.sendMessage("addGroupMembers",{id:this.#o,identifiers:e})}async addMembers(e){return this.#a.sendMessage("addGroupMembersByInboxId",{id:this.#o,inboxIds:e})}async removeMembersByIdentifiers(e){return this.#a.sendMessage("removeGroupMembers",{id:this.#o,identifiers:e})}async removeMembers(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})}}class ne{#a;constructor(e){this.#a=e}async sync(){return this.#a.sendMessage("syncConversations",void 0)}async syncAll(e){return this.#a.sendMessage("syncAllConversations",{consentStates:e})}async getConversationById(e){const t=await this.#a.sendMessage("getConversationById",{id:e});if(t)return"group"===t.metadata.conversationType?new se(this.#a,t.id,t):new te(this.#a,t.id,t)}async getMessageById(e){const t=await this.#a.sendMessage("getMessageById",{id:e});return t?new Z(this.#a,t):void 0}async getDmByInboxId(e){const t=await this.#a.sendMessage("getDmByInboxId",{inboxId:e});return t?new te(this.#a,t.id,t):void 0}async list(e){return(await this.#a.sendMessage("getConversations",{options:e})).map((e=>"group"===e.metadata.conversationType?new se(this.#a,e.id,e):new te(this.#a,e.id,e)))}async listGroups(e){return(await this.#a.sendMessage("getGroups",{options:e})).map((e=>new se(this.#a,e.id,e)))}async listDms(e){return(await this.#a.sendMessage("getDms",{options:e})).map((e=>new te(this.#a,e.id,e)))}async newGroupWithIdentifiers(e,t){const s=await this.#a.sendMessage("newGroupWithIdentifiers",{identifiers:e,options:t});return new se(this.#a,s.id,s)}async newGroup(e,t){const s=await this.#a.sendMessage("newGroupWithInboxIds",{inboxIds:e,options:t});return new se(this.#a,s.id,s)}async newDmWithIdentifier(e,t){const s=await this.#a.sendMessage("newDmWithIdentifier",{identifier:e,options:t});return new te(this.#a,s.id,s)}async newDm(e,t){const s=await this.#a.sendMessage("newDmWithInboxId",{inboxId:e,options:t});return new te(this.#a,s.id,s)}async getHmacKeys(){return this.#a.sendMessage("getHmacKeys",void 0)}async stream(e,t){const s=w(),n=new S,i=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);let i;s&&(i="group"===s.metadata.conversationType?new se(this.#a,s.id,s):new te(this.#a,s.id,s)),n.callback(null,i),e?.(null,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,I.Group)}async streamDms(e){return this.stream(e,I.Dm)}async streamAllMessages(e,t){const s=w(),n=new S,i=this.#a.handleStreamMessage(s,((t,s)=>{if(t)return n.callback(t,void 0),void e?.(t,void 0);const i=s?new Z(this.#a,s):void 0;n.callback(null,i),e?.(null,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,I.Group)}async streamAllDmMessages(e){return this.streamAllMessages(e,I.Dm)}}class ie{#a;constructor(e){this.#a=e}async inboxState(e){return this.#a.sendMessage("inboxState",{refreshFromNetwork:e??!1})}async getLatestInboxState(e){return this.#a.sendMessage("getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.#a.sendMessage("setConsentStates",{records:e})}async getConsentState(e,t){return this.#a.sendMessage("getConsentState",{entityType:e,entity:t})}async streamConsent(e){const t=w(),s=new S,n=this.#a.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#a.sendMessage("streamConsent",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}async streamPreferences(e){const t=w(),s=new S,n=this.#a.handleStreamMessage(t,((t,n)=>{s.callback(t,n??void 0),e?.(t,n??void 0)}));return await this.#a.sendMessage("streamPreferences",{streamId:t}),s.onReturn=()=>{this.#a.sendMessage("endStream",{streamId:t}),n()},s}}class re extends f{#v;#w;#M;#b;#f;#S;#x=!1;#A;#k;options;constructor(t,s,i){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==i?.loggingLevel&&"off"!==i.loggingLevel),this.options=i,this.#M=s,this.#k=t,this.#w=new ne(this),this.#A=new ie(this);const r=[new e,new n,...i?.codecs??[]];this.#v=new Map(r.map((e=>[e.contentType.toString(),e])))}async init(){const e=await this.sendMessage("init",{identifier:await this.#k.getIdentifier(),encryptionKey:this.#M,options:this.options});this.#b=e.inboxId,this.#f=e.installationId,this.#S=e.installationIdBytes,this.#x=!0}static async create(e,t,s){const n=new re(e,t,s);return await n.init(),s?.disableAutoRegister||await n.register(),n}get isReady(){return this.#x}get inboxId(){return this.#b}async accountIdentifier(){return this.#k.getIdentifier()}get installationId(){return this.#f}get installationIdBytes(){return this.#S}get conversations(){return this.#w}get preferences(){return this.#A}async unsafe_createInboxSignatureText(){return this.sendMessage("createInboxSignatureText",void 0)}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new Error("Unable to create add account signature text, `allowInboxReassign` must be true");return this.sendMessage("addAccountSignatureText",{newIdentifier:e})}async unsafe_removeAccountSignatureText(e){return this.sendMessage("removeAccountSignatureText",{identifier:e})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.sendMessage("revokeAllOtherInstallationsSignatureText",void 0)}async unsafe_revokeInstallationsSignatureText(e){return this.sendMessage("revokeInstallationsSignatureText",{installationIds:e})}async unsafe_addSignature(e,t,s){const n=await s.signMessage(t);switch(s.type){case"SCW":await this.sendMessage("addScwSignature",{type:e,bytes:n,chainId:s.getChainId(),blockNumber:s.getBlockNumber?.()});break;case"EOA":await this.sendMessage("addEcdsaSignature",{type:e,bytes:n})}}async unsafe_applySignatures(){return this.sendMessage("applySignatures",void 0)}async register(){const e=await this.unsafe_createInboxSignatureText();if(e)return await this.unsafe_addSignature(v.CreateInbox,e,this.#k),this.sendMessage("registerIdentity",void 0)}async unsafe_addAccount(e,t=!1){const s=await this.findInboxIdByIdentifier(await e.getIdentifier());if(s&&!t)throw new Error(`Signer address already associated with inbox ${s}`);const n=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0);if(!n)throw new Error("Unable to generate add account signature text");await this.unsafe_addSignature(v.AddWallet,n,e),await this.unsafe_applySignatures()}async removeAccount(e){const t=await this.unsafe_removeAccountSignatureText(e);if(!t)throw new Error("Unable to generate remove account signature text");await this.unsafe_addSignature(v.RevokeWallet,t,this.#k),await this.unsafe_applySignatures()}async revokeAllOtherInstallations(){const e=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)throw new Error("Unable to generate revoke all other installations signature text");await this.unsafe_addSignature(v.RevokeInstallations,e,this.#k),await this.unsafe_applySignatures()}async revokeInstallations(e){const t=await this.unsafe_revokeInstallationsSignatureText(e);if(!t)throw new Error("Unable to generate revoke installations signature text");await this.unsafe_addSignature(v.RevokeInstallations,t,this.#k),await this.unsafe_applySignatures()}async isRegistered(){return this.sendMessage("isRegistered",void 0)}async canMessage(e){return this.sendMessage("canMessage",{identifiers:e})}static async canMessage(e,t){const s={type:"EOA",getIdentifier:()=>({identifier:"0x0000000000000000000000000000000000000000",identifierKind:"Ethereum"}),signMessage:()=>new Uint8Array};return(await re.create(s,window.crypto.getRandomValues(new Uint8Array(32)),{disableAutoRegister:!0,env:t})).canMessage(e)}async findInboxIdByIdentifier(e){return this.sendMessage("findInboxIdByIdentifier",{identifier:e})}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),N(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!==m.MembershipChange)throw new Error("Error decoding group membership change");const i=T(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 ae=e=>{console.error(`Worker error on line ${e.lineno} in "${e.filename}"`),console.error(e.message)};class oe{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),this.#e.addEventListener("error",ae),this.#t=t}sendMessage(e,t){const s=w();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",ae),this.#e.terminate()}}class de extends oe{#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",{identifier:e,enableLogging:this.#t})}async getInboxIdForIdentifier(e,t){return this.sendMessage("getInboxIdForIdentifier",{identifier:e,env:t,enableLogging:this.#t})}}const ce={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},le={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{ce as ApiUrls,re as Client,ee as Conversation,ne as Conversations,Z as DecodedMessage,te as Dm,se as Group,le as HistorySyncUrls,de as Utils,A as fromContentTypeId,G as fromEncodedContent,V as fromSafeConsent,P as fromSafeContentTypeId,K as fromSafeCreateDmOptions,O as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,J as fromSafeGroupMember,U as fromSafeListConversationsOptions,B as fromSafeListMessagesOptions,Y as fromSafeMessageDisappearingSettings,_ as fromSafePermissionPolicySet,x as toContentTypeId,D as toEncodedContent,H as toSafeConsent,k as toSafeContentTypeId,j as toSafeConversation,q as toSafeCreateDmOptions,W as toSafeCreateGroupOptions,N as toSafeEncodedContent,z as toSafeGroupMember,Q as toSafeHmacKey,$ as toSafeInboxState,F as toSafeInstallation,E as toSafeListConversationsOptions,L as toSafeListMessagesOptions,C as toSafeMessage,X as toSafeMessageDisappearingSettings,R as toSafePermissionPolicySet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|