@xmtp/browser-sdk 5.1.0 → 5.2.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 +126 -23
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/dist/workers/utils.js +1 -1
- package/dist/workers/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/Client.ts +80 -2
- package/src/Conversation.ts +28 -8
- package/src/Conversations.ts +42 -4
- package/src/Utils.ts +20 -2
- package/src/WorkerClient.ts +8 -0
- package/src/WorkerConversation.ts +13 -4
- package/src/WorkerConversations.ts +13 -0
- package/src/constants.ts +3 -3
- package/src/index.ts +1 -0
- package/src/types/actions/client.ts +13 -1
- package/src/types/actions/conversation.ts +12 -0
- package/src/types/actions/conversations.ts +8 -0
- package/src/types/actions/preferences.ts +6 -2
- package/src/types/actions/streams.ts +5 -0
- package/src/types/actions/utils.ts +4 -0
- package/src/types/options.ts +4 -0
- package/src/utils/conversions.ts +50 -2
- package/src/utils/createClient.ts +3 -1
- package/src/utils/streams.ts +5 -0
- package/src/workers/client.ts +49 -2
- package/src/workers/utils.ts +21 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ContentCodec, ContentTypeId as ContentTypeId$1, EncodedContent as EncodedContent$1 } from '@xmtp/content-type-primitives';
|
|
2
2
|
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
3
|
-
import { Identifier, Conversations as Conversations$1, ConsentState, Message, Conversation as Conversation$1, ConversationType, Client as Client$1, ConsentEntityType, Consent, UserPreference, SignatureRequestHandle, KeyPackageStatus, PermissionUpdateType, PermissionPolicy, MetadataField, EncodedContent, MessageDisappearingSettings, HmacKey, ConversationDebugInfo, GroupPermissionsOptions, DeliveryStatus, GroupMessageKind, ContentType, SortDirection, PermissionLevel, ContentTypeId, ListMessagesOptions, ListConversationsOptions, PermissionPolicySet, CreateGroupOptions, CreateDMOptions, Installation, InboxState, GroupMember, ApiStats, IdentityStats } 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, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestHandle, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
|
|
3
|
+
import { Identifier, Conversations as Conversations$1, ConsentState, Message, Conversation as Conversation$1, ConversationType, Client as Client$1, ConsentEntityType, Consent, UserPreference, SignatureRequestHandle, KeyPackageStatus, PermissionUpdateType, PermissionPolicy, MetadataField, EncodedContent, SendMessageOpts, MessageDisappearingSettings, HmacKey, ConversationDebugInfo, GroupPermissionsOptions, DeliveryStatus, GroupMessageKind, ContentType, SortDirection, MessageSortBy, PermissionLevel, ListConversationsOrderBy, ContentTypeId, ListMessagesOptions, ListConversationsOptions, PermissionPolicySet, CreateGroupOptions, CreateDMOptions, Installation, InboxState, GroupMember, ApiStats, IdentityStats, GroupSyncSummary } from '@xmtp/wasm-bindings';
|
|
4
|
+
export { Consent, ConsentEntityType, ConsentState, ContentType, ContentTypeId, ConversationListItem, ConversationType, CreateDMOptions, CreateGroupOptions, DeliveryStatus, EncodedContent, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, GroupSyncSummary, HmacKey, Identifier, IdentifierKind, InboxState, Installation, ListConversationsOptions, ListMessagesOptions, LogOptions, Message, MessageDisappearingSettings, MetadataField, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, SignatureRequestHandle, SortDirection, UserPreference } from '@xmtp/wasm-bindings';
|
|
5
5
|
import { GroupUpdatedCodec } from '@xmtp/content-type-group-updated';
|
|
6
6
|
import { TextCodec } from '@xmtp/content-type-text';
|
|
7
7
|
|
|
@@ -58,6 +58,11 @@ type StreamOptions<T = unknown, V = T> = {
|
|
|
58
58
|
* (default: true)
|
|
59
59
|
*/
|
|
60
60
|
retryOnFail?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Whether to disable network sync before starting the stream
|
|
63
|
+
* (default: false)
|
|
64
|
+
*/
|
|
65
|
+
disableSync?: boolean;
|
|
61
66
|
};
|
|
62
67
|
type StreamCallback<T = unknown> = (error: Error | null, value: T | undefined) => void;
|
|
63
68
|
type StreamFunction<T = unknown> = (callback: StreamCallback<T>, onFail: () => void) => Promise<() => void>;
|
|
@@ -88,9 +93,9 @@ declare const createStream: <T = unknown, V = T>(streamFunction: StreamFunction<
|
|
|
88
93
|
* @property {string} production - The production URL for the XMTP network
|
|
89
94
|
*/
|
|
90
95
|
declare const ApiUrls: {
|
|
91
|
-
readonly local: "http://localhost:
|
|
92
|
-
readonly dev: "https://dev.xmtp.network";
|
|
93
|
-
readonly production: "https://production.xmtp.network";
|
|
96
|
+
readonly local: "http://localhost:5557";
|
|
97
|
+
readonly dev: "https://api.dev.xmtp.network:5558";
|
|
98
|
+
readonly production: "https://api.production.xmtp.network:5558";
|
|
94
99
|
};
|
|
95
100
|
/**
|
|
96
101
|
* Pre-configured URLs for the XMTP history sync service based on the environment
|
|
@@ -125,6 +130,10 @@ type NetworkOptions = {
|
|
|
125
130
|
* specific endpoint for syncing history
|
|
126
131
|
*/
|
|
127
132
|
historySyncUrl?: string | null;
|
|
133
|
+
/**
|
|
134
|
+
* gatewayHost can be used to override the gateway endpoint
|
|
135
|
+
*/
|
|
136
|
+
gatewayHost?: string | null;
|
|
128
137
|
};
|
|
129
138
|
type ContentOptions = {
|
|
130
139
|
/**
|
|
@@ -230,7 +239,7 @@ declare class WorkerConversations {
|
|
|
230
239
|
#private;
|
|
231
240
|
constructor(client: WorkerClient, conversations: Conversations$1);
|
|
232
241
|
sync(): Promise<void>;
|
|
233
|
-
syncAll(consentStates?: ConsentState[]): Promise<
|
|
242
|
+
syncAll(consentStates?: ConsentState[]): Promise<_xmtp_wasm_bindings.GroupSyncSummary>;
|
|
234
243
|
getConversationById(id: string): WorkerConversation | undefined;
|
|
235
244
|
getMessageById(id: string): Message | undefined;
|
|
236
245
|
getDmByInboxId(inboxId: string): WorkerConversation | undefined;
|
|
@@ -247,6 +256,7 @@ declare class WorkerConversations {
|
|
|
247
256
|
streamGroups(callback: StreamCallback<Conversation$1>, onFail: () => void): _xmtp_wasm_bindings.StreamCloser;
|
|
248
257
|
streamDms(callback: StreamCallback<Conversation$1>, onFail: () => void): _xmtp_wasm_bindings.StreamCloser;
|
|
249
258
|
streamAllMessages(callback: StreamCallback<Message>, onFail: () => void, conversationType?: ConversationType, consentStates?: ConsentState[]): _xmtp_wasm_bindings.StreamCloser;
|
|
259
|
+
streamMessageDeletions(callback: StreamCallback<string>): _xmtp_wasm_bindings.StreamCloser;
|
|
250
260
|
}
|
|
251
261
|
|
|
252
262
|
/**
|
|
@@ -267,7 +277,7 @@ declare class WorkerDebugInformation {
|
|
|
267
277
|
declare class WorkerPreferences {
|
|
268
278
|
#private;
|
|
269
279
|
constructor(client: Client$1, conversations: Conversations$1);
|
|
270
|
-
sync(): Promise<
|
|
280
|
+
sync(): Promise<_xmtp_wasm_bindings.GroupSyncSummary>;
|
|
271
281
|
inboxState(refreshFromNetwork: boolean): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
272
282
|
inboxStateFromInboxIds(inboxIds: string[], refreshFromNetwork?: boolean): Promise<_xmtp_wasm_bindings.InboxState[]>;
|
|
273
283
|
getLatestInboxState(inboxId: string): Promise<_xmtp_wasm_bindings.InboxState>;
|
|
@@ -281,6 +291,8 @@ declare class WorkerClient {
|
|
|
281
291
|
#private;
|
|
282
292
|
constructor(client: Client$1, options?: ClientOptions);
|
|
283
293
|
static create(identifier: Identifier, options?: Omit<ClientOptions, "codecs">): Promise<WorkerClient>;
|
|
294
|
+
get libxmtpVersion(): string;
|
|
295
|
+
get appVersion(): string;
|
|
284
296
|
get accountIdentifier(): Identifier;
|
|
285
297
|
get inboxId(): string;
|
|
286
298
|
get installationId(): string;
|
|
@@ -296,7 +308,7 @@ declare class WorkerClient {
|
|
|
296
308
|
createInboxSignatureRequest(): SignatureRequestHandle | undefined;
|
|
297
309
|
addAccountSignatureRequest(newAccountIdentifier: Identifier): Promise<SignatureRequestHandle>;
|
|
298
310
|
removeAccountSignatureRequest(identifier: Identifier): Promise<SignatureRequestHandle>;
|
|
299
|
-
revokeAllOtherInstallationsSignatureRequest(): Promise<SignatureRequestHandle>;
|
|
311
|
+
revokeAllOtherInstallationsSignatureRequest(): Promise<SignatureRequestHandle | undefined>;
|
|
300
312
|
revokeInstallationsSignatureRequest(installationIds: Uint8Array[]): Promise<SignatureRequestHandle>;
|
|
301
313
|
changeRecoveryIdentifierSignatureRequest(identifier: Identifier): Promise<SignatureRequestHandle>;
|
|
302
314
|
registerIdentity(signer: SafeSigner, signatureRequest: SignatureRequestHandle): Promise<void>;
|
|
@@ -346,9 +358,10 @@ declare class WorkerConversation {
|
|
|
346
358
|
addSuperAdmin(inboxId: string): Promise<void>;
|
|
347
359
|
removeSuperAdmin(inboxId: string): Promise<void>;
|
|
348
360
|
publishMessages(): Promise<void>;
|
|
349
|
-
sendOptimistic(encodedContent: EncodedContent): string;
|
|
350
|
-
send(encodedContent: EncodedContent): Promise<string>;
|
|
361
|
+
sendOptimistic(encodedContent: EncodedContent, opts: SendMessageOpts): string;
|
|
362
|
+
send(encodedContent: EncodedContent, opts: SendMessageOpts): Promise<string>;
|
|
351
363
|
messages(options?: SafeListMessagesOptions): Promise<Message[]>;
|
|
364
|
+
countMessages(options?: SafeListMessagesOptions): Promise<bigint>;
|
|
352
365
|
get consentState(): ConsentState;
|
|
353
366
|
updateConsentState(state: ConsentState): void;
|
|
354
367
|
dmPeerInboxId(): string;
|
|
@@ -398,12 +411,23 @@ type SafeListMessagesOptions = {
|
|
|
398
411
|
contentTypes?: ContentType[];
|
|
399
412
|
deliveryStatus?: DeliveryStatus;
|
|
400
413
|
direction?: SortDirection;
|
|
414
|
+
excludeContentTypes?: ContentType[];
|
|
415
|
+
excludeSenderInboxIds?: string[];
|
|
416
|
+
insertedAfterNs?: bigint;
|
|
417
|
+
insertedBeforeNs?: bigint;
|
|
418
|
+
kind?: GroupMessageKind;
|
|
401
419
|
limit?: bigint;
|
|
402
420
|
sentAfterNs?: bigint;
|
|
403
421
|
sentBeforeNs?: bigint;
|
|
422
|
+
sortBy?: MessageSortBy;
|
|
404
423
|
};
|
|
405
424
|
declare const toSafeListMessagesOptions: (options: ListMessagesOptions) => SafeListMessagesOptions;
|
|
406
425
|
declare const fromSafeListMessagesOptions: (options: SafeListMessagesOptions) => ListMessagesOptions;
|
|
426
|
+
type SafeSendMessageOpts = {
|
|
427
|
+
shouldPush: boolean;
|
|
428
|
+
};
|
|
429
|
+
declare const toSafeSendMessageOpts: (opts: SendMessageOpts) => SafeSendMessageOpts;
|
|
430
|
+
declare const fromSafeSendMessageOpts: (opts: SafeSendMessageOpts) => SendMessageOpts;
|
|
407
431
|
type SafeListConversationsOptions = {
|
|
408
432
|
consentStates?: ConsentState[];
|
|
409
433
|
conversationType?: ConversationType;
|
|
@@ -411,6 +435,7 @@ type SafeListConversationsOptions = {
|
|
|
411
435
|
createdBeforeNs?: bigint;
|
|
412
436
|
includeDuplicateDms?: boolean;
|
|
413
437
|
limit?: bigint;
|
|
438
|
+
orderBy?: ListConversationsOrderBy;
|
|
414
439
|
};
|
|
415
440
|
declare const toSafeListConversationsOptions: (options: ListConversationsOptions) => SafeListConversationsOptions;
|
|
416
441
|
declare const fromSafeListConversationsOptions: (options: SafeListConversationsOptions) => ListConversationsOptions;
|
|
@@ -520,6 +545,10 @@ type SafeKeyPackageStatus = {
|
|
|
520
545
|
validationError?: string;
|
|
521
546
|
};
|
|
522
547
|
declare const toSafeKeyPackageStatus: (status: KeyPackageStatus) => SafeKeyPackageStatus;
|
|
548
|
+
type SafeXMTPCursor = {
|
|
549
|
+
originatorID: number;
|
|
550
|
+
sequenceID: bigint;
|
|
551
|
+
};
|
|
523
552
|
type SafeConversationDebugInfo = {
|
|
524
553
|
epoch: bigint;
|
|
525
554
|
maybeForked: boolean;
|
|
@@ -527,7 +556,7 @@ type SafeConversationDebugInfo = {
|
|
|
527
556
|
isCommitLogForked?: boolean;
|
|
528
557
|
localCommitLog: string;
|
|
529
558
|
remoteCommitLog: string;
|
|
530
|
-
cursor:
|
|
559
|
+
cursor: SafeXMTPCursor[];
|
|
531
560
|
};
|
|
532
561
|
declare const toSafeConversationDebugInfo: (debugInfo: ConversationDebugInfo) => SafeConversationDebugInfo;
|
|
533
562
|
type SafeApiStats = {
|
|
@@ -605,7 +634,7 @@ type ClientAction = {
|
|
|
605
634
|
action: "client.revokeAllOtherInstallationsSignatureText";
|
|
606
635
|
id: string;
|
|
607
636
|
result: {
|
|
608
|
-
signatureText: string;
|
|
637
|
+
signatureText: string | undefined;
|
|
609
638
|
signatureRequestId: string;
|
|
610
639
|
};
|
|
611
640
|
data: {
|
|
@@ -735,6 +764,16 @@ type ClientAction = {
|
|
|
735
764
|
data: {
|
|
736
765
|
installationIds: string[];
|
|
737
766
|
};
|
|
767
|
+
} | {
|
|
768
|
+
action: "client.libxmtpVersion";
|
|
769
|
+
id: string;
|
|
770
|
+
result: string;
|
|
771
|
+
data: undefined;
|
|
772
|
+
} | {
|
|
773
|
+
action: "client.appVersion";
|
|
774
|
+
id: string;
|
|
775
|
+
result: string;
|
|
776
|
+
data: undefined;
|
|
738
777
|
};
|
|
739
778
|
|
|
740
779
|
type ConversationAction = {
|
|
@@ -751,6 +790,7 @@ type ConversationAction = {
|
|
|
751
790
|
data: {
|
|
752
791
|
id: string;
|
|
753
792
|
content: SafeEncodedContent;
|
|
793
|
+
sendOptions: SafeSendMessageOpts;
|
|
754
794
|
};
|
|
755
795
|
} | {
|
|
756
796
|
action: "conversation.sendOptimistic";
|
|
@@ -759,6 +799,7 @@ type ConversationAction = {
|
|
|
759
799
|
data: {
|
|
760
800
|
id: string;
|
|
761
801
|
content: SafeEncodedContent;
|
|
802
|
+
sendOptions: SafeSendMessageOpts;
|
|
762
803
|
};
|
|
763
804
|
} | {
|
|
764
805
|
action: "conversation.publishMessages";
|
|
@@ -775,6 +816,14 @@ type ConversationAction = {
|
|
|
775
816
|
id: string;
|
|
776
817
|
options?: SafeListMessagesOptions;
|
|
777
818
|
};
|
|
819
|
+
} | {
|
|
820
|
+
action: "conversation.countMessages";
|
|
821
|
+
id: string;
|
|
822
|
+
result: bigint;
|
|
823
|
+
data: {
|
|
824
|
+
id: string;
|
|
825
|
+
options?: Omit<SafeListMessagesOptions, "limit" | "direction">;
|
|
826
|
+
};
|
|
778
827
|
} | {
|
|
779
828
|
action: "conversation.members";
|
|
780
829
|
id: string;
|
|
@@ -985,6 +1034,13 @@ type ConversationsAction = {
|
|
|
985
1034
|
conversationType?: ConversationType;
|
|
986
1035
|
consentStates?: ConsentState[];
|
|
987
1036
|
};
|
|
1037
|
+
} | {
|
|
1038
|
+
action: "conversations.streamMessageDeletions";
|
|
1039
|
+
id: string;
|
|
1040
|
+
result: undefined;
|
|
1041
|
+
data: {
|
|
1042
|
+
streamId: string;
|
|
1043
|
+
};
|
|
988
1044
|
};
|
|
989
1045
|
|
|
990
1046
|
type DebugInformationAction = {
|
|
@@ -1209,7 +1265,7 @@ type PreferencesAction = {
|
|
|
1209
1265
|
} | {
|
|
1210
1266
|
action: "preferences.sync";
|
|
1211
1267
|
id: string;
|
|
1212
|
-
result:
|
|
1268
|
+
result: GroupSyncSummary;
|
|
1213
1269
|
data: undefined;
|
|
1214
1270
|
} | {
|
|
1215
1271
|
action: "preferences.streamConsent";
|
|
@@ -1274,6 +1330,10 @@ type StreamAction = {
|
|
|
1274
1330
|
action: "stream.preferences";
|
|
1275
1331
|
streamId: string;
|
|
1276
1332
|
result: UserPreference[] | undefined;
|
|
1333
|
+
} | {
|
|
1334
|
+
action: "stream.messageDeleted";
|
|
1335
|
+
streamId: string;
|
|
1336
|
+
result: string | undefined;
|
|
1277
1337
|
} | {
|
|
1278
1338
|
action: "stream.fail";
|
|
1279
1339
|
streamId: string;
|
|
@@ -1429,6 +1489,13 @@ declare class Conversation<ContentTypes = unknown> {
|
|
|
1429
1489
|
* @returns Promise that resolves with an array of decoded messages
|
|
1430
1490
|
*/
|
|
1431
1491
|
messages(options?: SafeListMessagesOptions): Promise<DecodedMessage<ContentTypes>[]>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Counts messages in this conversation
|
|
1494
|
+
*
|
|
1495
|
+
* @param options - Optional filtering options
|
|
1496
|
+
* @returns Promise that resolves with the count of messages
|
|
1497
|
+
*/
|
|
1498
|
+
countMessages(options?: Omit<SafeListMessagesOptions, "limit" | "direction">): Promise<bigint>;
|
|
1432
1499
|
/**
|
|
1433
1500
|
* Gets the consent state for this conversation
|
|
1434
1501
|
*
|
|
@@ -1853,6 +1920,13 @@ declare class Conversations<ContentTypes = unknown> {
|
|
|
1853
1920
|
streamAllDmMessages(options?: StreamOptions<SafeMessage, DecodedMessage<ContentTypes>> & {
|
|
1854
1921
|
consentStates?: ConsentState[];
|
|
1855
1922
|
}): Promise<AsyncStreamProxy<DecodedMessage<ContentTypes>>>;
|
|
1923
|
+
/**
|
|
1924
|
+
* Creates a stream for message deletions
|
|
1925
|
+
*
|
|
1926
|
+
* @param options - Optional stream options
|
|
1927
|
+
* @returns Stream instance for message deletions
|
|
1928
|
+
*/
|
|
1929
|
+
streamMessageDeletions(options?: Omit<StreamOptions<string>, "disableSync" | "onFail" | "onRetry" | "onRestart" | "retryAttempts" | "retryDelay" | "retryOnFail">): Promise<AsyncStreamProxy<string>>;
|
|
1856
1930
|
}
|
|
1857
1931
|
|
|
1858
1932
|
/**
|
|
@@ -1883,7 +1957,7 @@ declare class Preferences<ContentTypes = unknown> {
|
|
|
1883
1957
|
* @param client - The client instance managing preferences
|
|
1884
1958
|
*/
|
|
1885
1959
|
constructor(client: Client<ContentTypes>);
|
|
1886
|
-
sync(): Promise<
|
|
1960
|
+
sync(): Promise<_xmtp_wasm_bindings.GroupSyncSummary>;
|
|
1887
1961
|
/**
|
|
1888
1962
|
* Retrieves the current inbox state
|
|
1889
1963
|
*
|
|
@@ -2028,6 +2102,14 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> extends ClientWork
|
|
|
2028
2102
|
* Gets the preferences manager for this client
|
|
2029
2103
|
*/
|
|
2030
2104
|
get preferences(): Preferences<ContentTypes>;
|
|
2105
|
+
/**
|
|
2106
|
+
* Gets the version of libxmtp used in the bindings
|
|
2107
|
+
*/
|
|
2108
|
+
libxmtpVersion(): Promise<string>;
|
|
2109
|
+
/**
|
|
2110
|
+
* Gets the app version used by the client
|
|
2111
|
+
*/
|
|
2112
|
+
appVersion(): Promise<string>;
|
|
2031
2113
|
/**
|
|
2032
2114
|
* Creates signature text for creating a new inbox
|
|
2033
2115
|
*
|
|
@@ -2090,7 +2172,7 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> extends ClientWork
|
|
|
2090
2172
|
* @returns The signature text and signature request ID
|
|
2091
2173
|
*/
|
|
2092
2174
|
unsafe_revokeAllOtherInstallationsSignatureText(): Promise<{
|
|
2093
|
-
signatureText: string;
|
|
2175
|
+
signatureText: string | undefined;
|
|
2094
2176
|
signatureRequestId: string;
|
|
2095
2177
|
}>;
|
|
2096
2178
|
/**
|
|
@@ -2203,7 +2285,7 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> extends ClientWork
|
|
|
2203
2285
|
* @param inboxId - The inbox ID to revoke installations for
|
|
2204
2286
|
* @param installationIds - The installation IDs to revoke
|
|
2205
2287
|
*/
|
|
2206
|
-
static revokeInstallations(signer: Signer, inboxId: string, installationIds: Uint8Array[], env?: XmtpEnv, enableLogging?: boolean): Promise<void>;
|
|
2288
|
+
static revokeInstallations(signer: Signer, inboxId: string, installationIds: Uint8Array[], env?: XmtpEnv, gatewayHost?: string, enableLogging?: boolean): Promise<void>;
|
|
2207
2289
|
/**
|
|
2208
2290
|
* Gets the inbox state for the specified inbox IDs without a client
|
|
2209
2291
|
*
|
|
@@ -2211,7 +2293,7 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> extends ClientWork
|
|
|
2211
2293
|
* @param env - The environment to use
|
|
2212
2294
|
* @returns The inbox state for the specified inbox IDs
|
|
2213
2295
|
*/
|
|
2214
|
-
static inboxStateFromInboxIds(inboxIds: string[], env?: XmtpEnv, enableLogging?: boolean): Promise<SafeInboxState[]>;
|
|
2296
|
+
static inboxStateFromInboxIds(inboxIds: string[], env?: XmtpEnv, enableLogging?: boolean, gatewayHost?: string): Promise<SafeInboxState[]>;
|
|
2215
2297
|
/**
|
|
2216
2298
|
* Changes the recovery identifier for the client's inbox
|
|
2217
2299
|
*
|
|
@@ -2265,6 +2347,20 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> extends ClientWork
|
|
|
2265
2347
|
* @throws {CodecNotFoundError} if no codec is found for the content type
|
|
2266
2348
|
*/
|
|
2267
2349
|
encodeContent(content: ContentTypes, contentType: ContentTypeId$1): SafeEncodedContent;
|
|
2350
|
+
/**
|
|
2351
|
+
* Prepares content for sending by encoding it and generating send options from the codec
|
|
2352
|
+
*
|
|
2353
|
+
* @param content - The message content to prepare for sending
|
|
2354
|
+
* @param contentType - The content type identifier for the appropriate codec
|
|
2355
|
+
* @returns An object containing the encoded content and send options
|
|
2356
|
+
* @throws {CodecNotFoundError} When no codec is registered for the specified content type
|
|
2357
|
+
*/
|
|
2358
|
+
prepareForSend(content: ContentTypes, contentType: ContentTypeId$1): {
|
|
2359
|
+
encodedContent: SafeEncodedContent;
|
|
2360
|
+
sendOptions: {
|
|
2361
|
+
shouldPush: boolean;
|
|
2362
|
+
};
|
|
2363
|
+
};
|
|
2268
2364
|
/**
|
|
2269
2365
|
* Decodes a message for a given content type
|
|
2270
2366
|
*
|
|
@@ -2329,6 +2425,7 @@ type UtilsWorkerAction = {
|
|
|
2329
2425
|
data: {
|
|
2330
2426
|
identifier: Identifier;
|
|
2331
2427
|
env?: XmtpEnv;
|
|
2428
|
+
gatewayHost?: string;
|
|
2332
2429
|
};
|
|
2333
2430
|
} | {
|
|
2334
2431
|
action: "utils.revokeInstallationsSignatureText";
|
|
@@ -2341,6 +2438,7 @@ type UtilsWorkerAction = {
|
|
|
2341
2438
|
env?: XmtpEnv;
|
|
2342
2439
|
identifier: Identifier;
|
|
2343
2440
|
inboxId: string;
|
|
2441
|
+
gatewayHost?: string;
|
|
2344
2442
|
installationIds: Uint8Array[];
|
|
2345
2443
|
signatureRequestId: string;
|
|
2346
2444
|
};
|
|
@@ -2352,6 +2450,7 @@ type UtilsWorkerAction = {
|
|
|
2352
2450
|
env?: XmtpEnv;
|
|
2353
2451
|
signer: SafeSigner;
|
|
2354
2452
|
signatureRequestId: string;
|
|
2453
|
+
gatewayHost?: string;
|
|
2355
2454
|
};
|
|
2356
2455
|
} | {
|
|
2357
2456
|
action: "utils.inboxStateFromInboxIds";
|
|
@@ -2360,6 +2459,7 @@ type UtilsWorkerAction = {
|
|
|
2360
2459
|
data: {
|
|
2361
2460
|
inboxIds: string[];
|
|
2362
2461
|
env?: XmtpEnv;
|
|
2462
|
+
gatewayHost?: string;
|
|
2363
2463
|
};
|
|
2364
2464
|
};
|
|
2365
2465
|
|
|
@@ -2425,9 +2525,10 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
2425
2525
|
*
|
|
2426
2526
|
* @param identifier - The identifier to get the inbox ID for
|
|
2427
2527
|
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
2528
|
+
* @param gatewayHost - Optional gateway host override
|
|
2428
2529
|
* @returns Promise that resolves with the inbox ID for the identifier
|
|
2429
2530
|
*/
|
|
2430
|
-
getInboxIdForIdentifier(identifier: Identifier, env?: XmtpEnv): Promise<string | undefined>;
|
|
2531
|
+
getInboxIdForIdentifier(identifier: Identifier, env?: XmtpEnv, gatewayHost?: string): Promise<string | undefined>;
|
|
2431
2532
|
/**
|
|
2432
2533
|
* Creates signature text for revoking installations
|
|
2433
2534
|
*
|
|
@@ -2441,9 +2542,10 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
2441
2542
|
* @param identifier - The identifier to revoke installations for
|
|
2442
2543
|
* @param inboxId - The inbox ID to revoke installations for
|
|
2443
2544
|
* @param installationIds - The installation IDs to revoke
|
|
2545
|
+
* @param gatewayHost - Optional gateway host override
|
|
2444
2546
|
* @returns The signature text and signature request ID
|
|
2445
2547
|
*/
|
|
2446
|
-
revokeInstallationsSignatureText(identifier: Identifier, inboxId: string, installationIds: Uint8Array[], env?: XmtpEnv): Promise<{
|
|
2548
|
+
revokeInstallationsSignatureText(identifier: Identifier, inboxId: string, installationIds: Uint8Array[], env?: XmtpEnv, gatewayHost?: string): Promise<{
|
|
2447
2549
|
signatureText: string;
|
|
2448
2550
|
signatureRequestId: string;
|
|
2449
2551
|
}>;
|
|
@@ -2454,9 +2556,10 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
2454
2556
|
* @param signer - The signer to use
|
|
2455
2557
|
* @param inboxId - The inbox ID to revoke installations for
|
|
2456
2558
|
* @param installationIds - The installation IDs to revoke
|
|
2559
|
+
* @param gatewayHost - Optional gateway host override
|
|
2457
2560
|
* @returns Promise that resolves with the result of the revoke installations operation
|
|
2458
2561
|
*/
|
|
2459
|
-
revokeInstallations(signer: Signer, inboxId: string, installationIds: Uint8Array[], env?: XmtpEnv): Promise<void>;
|
|
2562
|
+
revokeInstallations(signer: Signer, inboxId: string, installationIds: Uint8Array[], env?: XmtpEnv, gatewayHost?: string): Promise<void>;
|
|
2460
2563
|
/**
|
|
2461
2564
|
* Gets the inbox state for the specified inbox IDs without a client
|
|
2462
2565
|
*
|
|
@@ -2464,7 +2567,7 @@ declare class Utils extends UtilsWorkerClass {
|
|
|
2464
2567
|
* @param env - The environment to use
|
|
2465
2568
|
* @returns The inbox state for the specified inbox IDs
|
|
2466
2569
|
*/
|
|
2467
|
-
inboxStateFromInboxIds(inboxIds: string[], env?: XmtpEnv): Promise<SafeInboxState[]>;
|
|
2570
|
+
inboxStateFromInboxIds(inboxIds: string[], env?: XmtpEnv, gatewayHost?: string): Promise<SafeInboxState[]>;
|
|
2468
2571
|
}
|
|
2469
2572
|
|
|
2470
2573
|
declare class ClientNotInitializedError extends Error {
|
|
@@ -2501,5 +2604,5 @@ declare class StreamInvalidRetryAttemptsError extends Error {
|
|
|
2501
2604
|
constructor();
|
|
2502
2605
|
}
|
|
2503
2606
|
|
|
2504
|
-
export { AccountAlreadyAssociatedError, ApiUrls, Client, ClientNotInitializedError, CodecNotFoundError, Conversation, Conversations, DEFAULT_RETRY_ATTEMPTS, DEFAULT_RETRY_DELAY, DecodedMessage, Dm, Group, GroupNotFoundError, HistorySyncUrls, InboxReassignError, InvalidGroupMembershipChangeError, MissingContentTypeError, SignerUnavailableError, StreamFailedError, StreamInvalidRetryAttemptsError, StreamNotFoundError, Utils, createStream, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateDmOptions, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, fromSafeMessageDisappearingSettings, fromSafePermissionPolicySet, toContentTypeId, toEncodedContent, toSafeApiStats, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeConversationDebugInfo, toSafeCreateDmOptions, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeIdentityStats, toSafeInboxState, toSafeInstallation, toSafeKeyPackageStatus, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafeMessageDisappearingSettings, toSafePermissionPolicySet, toSafeSigner };
|
|
2505
|
-
export type { AsyncStreamProxy, ClientOptions, ContentOptions, EOASigner, ExtractCodecContentTypes, HmacKeys, MessageDeliveryStatus, MessageKind, NetworkOptions, OtherOptions, SCWSigner, SafeApiStats, SafeConsent, SafeContentTypeId, SafeConversation, SafeConversationDebugInfo, SafeCreateDmOptions, SafeCreateGroupOptions, SafeEncodedContent, SafeGroupMember, SafeHmacKey, SafeHmacKeys, SafeIdentityStats, SafeInboxState, SafeInstallation, SafeKeyPackageStatus, SafeListConversationsOptions, SafeListMessagesOptions, SafeMessage, SafeMessageDisappearingSettings, SafePermissionPolicySet, SafeSigner, Signer, StorageOptions, StreamCallback, StreamFunction, StreamOptions, StreamValueMutator, XmtpEnv };
|
|
2607
|
+
export { AccountAlreadyAssociatedError, ApiUrls, Client, ClientNotInitializedError, CodecNotFoundError, Conversation, Conversations, DEFAULT_RETRY_ATTEMPTS, DEFAULT_RETRY_DELAY, DecodedMessage, Dm, Group, GroupNotFoundError, HistorySyncUrls, InboxReassignError, InvalidGroupMembershipChangeError, MissingContentTypeError, SignerUnavailableError, StreamFailedError, StreamInvalidRetryAttemptsError, StreamNotFoundError, Utils, createStream, fromContentTypeId, fromEncodedContent, fromSafeConsent, fromSafeContentTypeId, fromSafeCreateDmOptions, fromSafeCreateGroupOptions, fromSafeEncodedContent, fromSafeGroupMember, fromSafeListConversationsOptions, fromSafeListMessagesOptions, fromSafeMessageDisappearingSettings, fromSafePermissionPolicySet, fromSafeSendMessageOpts, toContentTypeId, toEncodedContent, toSafeApiStats, toSafeConsent, toSafeContentTypeId, toSafeConversation, toSafeConversationDebugInfo, toSafeCreateDmOptions, toSafeCreateGroupOptions, toSafeEncodedContent, toSafeGroupMember, toSafeHmacKey, toSafeIdentityStats, toSafeInboxState, toSafeInstallation, toSafeKeyPackageStatus, toSafeListConversationsOptions, toSafeListMessagesOptions, toSafeMessage, toSafeMessageDisappearingSettings, toSafePermissionPolicySet, toSafeSendMessageOpts, toSafeSigner };
|
|
2608
|
+
export type { AsyncStreamProxy, ClientOptions, ContentOptions, EOASigner, ExtractCodecContentTypes, HmacKeys, MessageDeliveryStatus, MessageKind, NetworkOptions, OtherOptions, SCWSigner, SafeApiStats, SafeConsent, SafeContentTypeId, SafeConversation, SafeConversationDebugInfo, SafeCreateDmOptions, SafeCreateGroupOptions, SafeEncodedContent, SafeGroupMember, SafeHmacKey, SafeHmacKeys, SafeIdentityStats, SafeInboxState, SafeInstallation, SafeKeyPackageStatus, SafeListConversationsOptions, SafeListMessagesOptions, SafeMessage, SafeMessageDisappearingSettings, SafePermissionPolicySet, SafeSendMessageOpts, SafeSigner, SafeXMTPCursor, Signer, StorageOptions, StreamCallback, StreamFunction, StreamOptions, StreamValueMutator, XmtpEnv };
|
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 c,CreateGroupOptions as d,CreateDMOptions as l,Consent as u,GroupMember as g,MessageDisappearingSettings as h,GroupPermissionsOptions as p,GroupMessageKind as m,DeliveryStatus as y,ConversationType as I}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,SignatureRequestHandle,SortDirection}from"@xmtp/wasm-bindings";import{v4 as v}from"uuid";import{ContentTypeId as w}from"@xmtp/content-type-primitives";const f=e=>{console.error(e.message)};class M{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),t&&this.#e.addEventListener("error",f),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(t.error):s.resolve(t.result))};handleStreamMessage=(e,t,s)=>{const i=i=>{const n=i.data;if(n.streamId===e){if("stream.fail"===n.action)return void s?.onFail?.();"error"in n?t(n.error,void 0):t(null,n.result)}};return this.#e.addEventListener("message",i),async()=>{await this.sendMessage("endStream",{streamId:e}),this.#e.removeEventListener("message",i)}};close(){this.#e.removeEventListener("message",this.handleMessage),this.#t&&this.#e.removeEventListener("error",f),this.#e.terminate()}}const b=e=>new w({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),S=e=>new n(e.authorityId,e.typeId,e.versionMajor,e.versionMinor),x=e=>({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),A=e=>new w({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),k=e=>({type:b(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),D=e=>new r(S(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),P=e=>({type:x(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),T=e=>({type:A(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({content:P(k(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),R=e=>({contentTypes:e.contentTypes,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,e.contentTypes),L=e=>({consentStates:e.consentStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,limit:e.limit}),q=e=>new o(e.consentStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.limit),_=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}),F=e=>new c(e.addMemberPolicy,e.removeMemberPolicy,e.addAdminPolicy,e.removeAdminPolicy,e.updateGroupNamePolicy,e.updateGroupDescriptionPolicy,e.updateGroupImageUrlSquarePolicy,e.updateMessageDisappearingPolicy),B=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?J(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),G=e=>new d(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===p.CustomPolicy?F(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Q(e.messageDisappearingSettings):void 0),E=e=>({messageDisappearingSettings:e.messageDisappearingSettings?J(e.messageDisappearingSettings):void 0}),U=e=>new l(e.messageDisappearingSettings?Q(e.messageDisappearingSettings):void 0),O=async e=>{const t=e.id,s=e.name,i=e.imageUrl,n=e.description,r=e.permissions,a=e.addedByInboxId,o=await e.metadata(),c=e.admins,d=e.superAdmins,l=e.createdAtNs,u=r.policyType,g=r.policySet,h=e.isCommitLogForked;return{id:t,name:s,imageUrl:i,description:n,permissions:{policyType:u,policySet:{addAdminPolicy:g.addAdminPolicy,addMemberPolicy:g.addMemberPolicy,removeAdminPolicy:g.removeAdminPolicy,removeMemberPolicy:g.removeMemberPolicy,updateGroupDescriptionPolicy:g.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:g.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:g.updateGroupNamePolicy,updateMessageDisappearingPolicy:g.updateMessageDisappearingPolicy}},addedByInboxId:a,metadata:o,admins:c,superAdmins:d,createdAtNs:l,isCommitLogForked:h}},K=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),W=e=>({identifiers:e.accountIdentifiers,inboxId:e.inboxId,installations:e.installations.map(K),recoveryIdentifier:e.recoveryIdentifier}),j=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),$=e=>new u(e.entityType,e.state,e.entity),H=e=>({accountIdentifiers:e.accountIdentifiers,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),V=e=>new g(e.inboxId,e.accountIdentifiers,e.installationIds,e.permissionLevel,e.consentState),z=e=>({key:e.key,epoch:e.epoch}),J=e=>({fromNs:e.fromNs,inNs:e.inNs}),Q=e=>new h(e.fromNs,e.inNs),X=e=>({lifetime:e.lifetime?{notBefore:e.lifetime.not_before,notAfter:e.lifetime.not_after}:void 0,validationError:e.validationError}),Y=e=>({epoch:e.epoch,maybeForked:e.maybeForked,forkDetails:e.forkDetails,isCommitLogForked:e.isCommitLogForked,localCommitLog:e.localCommitLog,remoteCommitLog:e.remoteCommitLog,cursor:e.cursor}),Z=e=>({uploadKeyPackage:e.upload_key_package,fetchKeyPackage:e.fetch_key_package,sendGroupMessages:e.send_group_messages,sendWelcomeMessages:e.send_welcome_messages,queryGroupMessages:e.query_group_messages,queryWelcomeMessages:e.query_welcome_messages,subscribeMessages:e.subscribe_messages,subscribeWelcomes:e.subscribe_welcomes}),ee=e=>({getIdentityUpdatesV2:e.get_identity_updates_v2,getInboxIds:e.get_inbox_ids,publishIdentityUpdate:e.publish_identity_update,verifySmartContractWalletSignature:e.verify_smart_contract_wallet_signature});class te{#i;content;contentType;conversationId;deliveryStatus;fallback;compression;id;kind;parameters;encodedContent;senderInboxId;sentAtNs;constructor(e,t){switch(this.#i=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=A(t.content.type),this.parameters=new Map(Object.entries(t.content.parameters)),this.fallback=t.content.fallback,this.compression=t.content.compression;try{this.content=this.#i.decodeContent(t,this.contentType)}catch{this.content=void 0}}}class se extends Error{constructor(){super("Client not initialized, use Client.create or Client.build to create a client")}}class ie extends Error{constructor(){super("Signer unavailable, use Client.create to create a client with a signer")}}class ne extends Error{constructor(e){super(`Codec not found for "${e.toString()}" content type`)}}class re extends Error{constructor(){super("Unable to create add account signature text, `allowInboxReassign` must be true")}}class ae extends Error{constructor(e){super(`Account already associated with inbox ${e}`)}}class oe extends Error{constructor(e){super(`Group "${e}" not found`)}}class ce extends Error{constructor(e){super(`Stream "${e}" not found`)}}class de extends Error{constructor(e){super(`Invalid group membership change for message ${e}`)}}class le extends Error{constructor(){super("Content type is required when sending content other than text")}}class ue extends Error{constructor(e){super(`Stream failed, retried ${e} ${"time"+(1!==e?"s":"")}`)}}class ge extends Error{constructor(){super("Stream retry attempts must be greater than 0")}}class he{isDone=!1;#n=[];#r;onDone;onReturn;constructor(){this.#r=[],this.isDone=!1}flush(){for(;this.#n.length>0;){const e=this.#n.shift();e&&e({done:!0,value:void 0})}}done(){this.flush(),this.#r=[],this.#n=[],this.isDone=!0,this.onDone?.()}push=e=>{if(this.isDone)return;const t=this.#n.shift();t?t({done:!1,value:e}):this.#r.push(e)};next=()=>this.isDone?Promise.resolve({done:!0,value:void 0}):this.#r.length>0?Promise.resolve({done:!1,value:this.#r.shift()}):new Promise((e=>{this.#n.push(e)}));return=()=>(this.onReturn?.(),this.done(),Promise.resolve({done:!0,value:void 0}));end=()=>this.return();[Symbol.asyncIterator](){return this}}const pe=["end","isDone","next","return",Symbol.asyncIterator],me=e=>pe.includes(e);const ye=1e4,Ie=6,ve=async(e,t,s)=>{const{onEnd:i,onError:n,onFail:r,onRestart:a,onRetry:o,onValue:c,retryAttempts:d=Ie,retryDelay:l=ye,retryOnFail:u=!0}=s??{};if(u&&d<0)throw new ge;const g=new he,h=(e,s)=>{if(e)n?.(e);else if(void 0!==s)try{if(t){const e=t(s);(e=>!!e&&("object"==typeof e||"function"==typeof e)&&"then"in e&&"function"==typeof e.then)(e)?e.then((e=>{g.push(e),c?.(e)})).catch((e=>{n?.(e)})):(g.push(e),c?.(e))}else g.push(s),c?.(s)}catch(e){n?.(e)}},p=async(t=d)=>{try{if(0===t)throw g.end(),new ue(d);await(s=l,new Promise((e=>setTimeout(e,s)))),o?.(d-t+1,d);const n=await e(h,(()=>{r?.(),p()}));g.onDone=()=>{n(),i?.()},a?.()}catch(e){n?.(e),p(t-1)}var s},m=()=>{if(!u)throw g.end(),new ue(0);p()};try{const t=await e(h,(()=>{r?.(),m()}));g.onDone=()=>{t(),i?.()}}catch(e){n?.(e),m()}return new Proxy(g,{get(e,t,s){if(me(t))return Reflect.get(e,t,s)},set:()=>!0,has:(e,t)=>me(t),ownKeys:()=>pe,getOwnPropertyDescriptor(e,t){if(me(t))return{enumerable:!0,configurable:!0,value:Reflect.get(e,t)}}})};class we{#a;#i;#o;#c;#d;#l;constructor(e,t,s){this.#i=e,this.#c=t,this.#u(s)}#u(e){this.#a=e?.addedByInboxId,this.#d=e?.metadata,this.#o=e?.createdAtNs,this.#l=e?.isCommitLogForked}get id(){return this.#c}get isCommitLogForked(){return this.#l}get addedByInboxId(){return this.#a}get createdAtNs(){return this.#o}get createdAt(){return this.#o?(e=this.#o,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#d}async lastMessage(){const e=await this.#i.sendMessage("conversation.lastMessage",{id:this.#c});return e?new te(this.#i,e):void 0}async isActive(){return this.#i.sendMessage("conversation.isActive",{id:this.#c})}async members(){return this.#i.sendMessage("conversation.members",{id:this.#c})}async sync(){const e=await this.#i.sendMessage("conversation.sync",{id:this.#c});return this.#u(e),e}async publishMessages(){return this.#i.sendMessage("conversation.publishMessages",{id:this.#c})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new le;const i="string"==typeof e?this.#i.encodeContent(e,t??s):this.#i.encodeContent(e,t);return this.#i.sendMessage("conversation.sendOptimistic",{id:this.#c,content:i})}async send(e,t){if("string"!=typeof e&&!t)throw new le;const i="string"==typeof e?this.#i.encodeContent(e,t??s):this.#i.encodeContent(e,t);return this.#i.sendMessage("conversation.send",{id:this.#c,content:i})}async messages(e){return(await this.#i.sendMessage("conversation.messages",{id:this.#c,options:e})).map((e=>new te(this.#i,e)))}async consentState(){return this.#i.sendMessage("conversation.consentState",{id:this.#c})}async updateConsentState(e){return this.#i.sendMessage("conversation.updateConsentState",{id:this.#c,state:e})}async messageDisappearingSettings(){return this.#i.sendMessage("conversation.messageDisappearingSettings",{id:this.#c})}async updateMessageDisappearingSettings(e,t){return this.#i.sendMessage("conversation.updateMessageDisappearingSettings",{id:this.#c,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#i.sendMessage("conversation.removeMessageDisappearingSettings",{id:this.#c})}async isMessageDisappearingEnabled(){return this.#i.sendMessage("conversation.isMessageDisappearingEnabled",{id:this.#c})}async stream(e){return ve((async(t,s)=>{const i=v();return await this.sync(),await this.#i.sendMessage("conversation.stream",{groupId:this.#c,streamId:i}),this.#i.handleStreamMessage(i,t,{...e,onFail:s})}),(e=>new te(this.#i,e)),e)}async pausedForVersion(){return this.#i.sendMessage("conversation.pausedForVersion",{id:this.#c})}async getHmacKeys(){return this.#i.sendMessage("conversation.getHmacKeys",{id:this.#c})}async debugInfo(){return this.#i.sendMessage("conversation.debugInfo",{id:this.#c})}}class fe extends we{#i;#c;constructor(e,t,s){super(e,t,s),this.#i=e,this.#c=t}async peerInboxId(){return this.#i.sendMessage("dm.peerInboxId",{id:this.#c})}async getDuplicateDms(){return this.#i.sendMessage("dm.getDuplicateDms",{id:this.#c})}}class Me extends we{#g=[];#i;#h;#c;#p;#m;#y=[];#u(e){this.#m=e?.name??"",this.#p=e?.imageUrl??"",this.#h=e?.description??"",this.#g=e?.admins??[],this.#y=e?.superAdmins??[]}constructor(e,t,s){super(e,t,s),this.#i=e,this.#c=t,this.#u(s)}async sync(){const e=await super.sync();return this.#u(e),e}get name(){return this.#m}async updateName(e){await this.#i.sendMessage("group.updateName",{id:this.#c,name:e}),this.#m=e}get imageUrl(){return this.#p}async updateImageUrl(e){await this.#i.sendMessage("group.updateImageUrl",{id:this.#c,imageUrl:e}),this.#p=e}get description(){return this.#h}async updateDescription(e){await this.#i.sendMessage("group.updateDescription",{id:this.#c,description:e}),this.#h=e}get admins(){return this.#g}get superAdmins(){return this.#y}async listAdmins(){const e=await this.#i.sendMessage("group.listAdmins",{id:this.#c});return this.#g=e,e}async listSuperAdmins(){const e=await this.#i.sendMessage("group.listSuperAdmins",{id:this.#c});return this.#y=e,e}async permissions(){return this.#i.sendMessage("group.permissions",{id:this.#c})}async updatePermission(e,t,s){return this.#i.sendMessage("group.updatePermission",{id:this.#c,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.#i.sendMessage("group.addMembersByIdentifiers",{id:this.#c,identifiers:e})}async addMembers(e){return this.#i.sendMessage("group.addMembers",{id:this.#c,inboxIds:e})}async removeMembersByIdentifiers(e){return this.#i.sendMessage("group.removeMembersByIdentifiers",{id:this.#c,identifiers:e})}async removeMembers(e){return this.#i.sendMessage("group.removeMembers",{id:this.#c,inboxIds:e})}async addAdmin(e){return this.#i.sendMessage("group.addAdmin",{id:this.#c,inboxId:e})}async removeAdmin(e){return this.#i.sendMessage("group.removeAdmin",{id:this.#c,inboxId:e})}async addSuperAdmin(e){return this.#i.sendMessage("group.addSuperAdmin",{id:this.#c,inboxId:e})}async removeSuperAdmin(e){return this.#i.sendMessage("group.removeSuperAdmin",{id:this.#c,inboxId:e})}}class be{#i;constructor(e){this.#i=e}async sync(){return this.#i.sendMessage("conversations.sync",void 0)}async syncAll(e){return this.#i.sendMessage("conversations.syncAll",{consentStates:e})}async getConversationById(e){const t=await this.#i.sendMessage("conversations.getConversationById",{id:e});if(t)return"group"===t.metadata.conversationType?new Me(this.#i,t.id,t):new fe(this.#i,t.id,t)}async getMessageById(e){const t=await this.#i.sendMessage("conversations.getMessageById",{id:e});return t?new te(this.#i,t):void 0}async getDmByInboxId(e){const t=await this.#i.sendMessage("conversations.getDmByInboxId",{inboxId:e});return t?new fe(this.#i,t.id,t):void 0}async getDmByIdentifier(e){const t=await this.#i.findInboxIdByIdentifier(e);if(t)return this.getDmByInboxId(t)}async list(e){return(await this.#i.sendMessage("conversations.list",{options:e})).map((e=>{switch(e.metadata.conversationType){case"dm":return new fe(this.#i,e.id,e);case"group":return new Me(this.#i,e.id,e);default:return}})).filter((e=>void 0!==e))}async listGroups(e){return(await this.#i.sendMessage("conversations.listGroups",{options:e})).map((e=>new Me(this.#i,e.id,e)))}async listDms(e){return(await this.#i.sendMessage("conversations.listDms",{options:e})).map((e=>new fe(this.#i,e.id,e)))}async newGroupOptimistic(e){const t=await this.#i.sendMessage("conversations.newGroupOptimistic",{options:e});return new Me(this.#i,t.id,t)}async newGroupWithIdentifiers(e,t){const s=await this.#i.sendMessage("conversations.newGroupWithIdentifiers",{identifiers:e,options:t});return new Me(this.#i,s.id,s)}async newGroup(e,t){const s=await this.#i.sendMessage("conversations.newGroup",{inboxIds:e,options:t});return new Me(this.#i,s.id,s)}async newDmWithIdentifier(e,t){const s=await this.#i.sendMessage("conversations.newDmWithIdentifier",{identifier:e,options:t});return new fe(this.#i,s.id,s)}async newDm(e,t){const s=await this.#i.sendMessage("conversations.newDm",{inboxId:e,options:t});return new fe(this.#i,s.id,s)}async getHmacKeys(){return this.#i.sendMessage("conversations.getHmacKeys",void 0)}async stream(e){return ve((async(t,s)=>{const i=v();return await this.sync(),await this.#i.sendMessage("conversations.stream",{streamId:i,conversationType:e?.conversationType}),this.#i.handleStreamMessage(i,t,{...e,onFail:s})}),(e=>"group"===e.metadata.conversationType?new Me(this.#i,e.id,e):new fe(this.#i,e.id,e)),e)}async streamGroups(e){return this.stream({...e,conversationType:I.Group})}async streamDms(e){return this.stream({...e,conversationType:I.Dm})}async streamAllMessages(e){return ve((async(t,s)=>{const i=v();return await this.sync(),await this.#i.sendMessage("conversations.streamAllMessages",{streamId:i,conversationType:e?.conversationType,consentStates:e?.consentStates}),this.#i.handleStreamMessage(i,t,{...e,onFail:s})}),(e=>new te(this.#i,e)),e)}async streamAllGroupMessages(e){return this.streamAllMessages({...e,conversationType:I.Group})}async streamAllDmMessages(e){return this.streamAllMessages({...e,conversationType:I.Dm})}}class Se{#i;constructor(e){this.#i=e}apiStatistics(){return this.#i.sendMessage("debugInformation.apiStatistics",void 0)}apiIdentityStatistics(){return this.#i.sendMessage("debugInformation.apiIdentityStatistics",void 0)}apiAggregateStatistics(){return this.#i.sendMessage("debugInformation.apiAggregateStatistics",void 0)}clearAllStatistics(){return this.#i.sendMessage("debugInformation.clearAllStatistics",void 0)}uploadDebugArchive(e){return this.#i.sendMessage("debugInformation.uploadDebugArchive",{serverUrl:e})}}class xe{#i;constructor(e){this.#i=e}sync(){return this.#i.sendMessage("preferences.sync",void 0)}async inboxState(e){return this.#i.sendMessage("preferences.inboxState",{refreshFromNetwork:e??!1})}async inboxStateFromInboxIds(e,t){return this.#i.sendMessage("preferences.inboxStateFromInboxIds",{inboxIds:e,refreshFromNetwork:t??!1})}async getLatestInboxState(e){return this.#i.sendMessage("preferences.getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.#i.sendMessage("preferences.setConsentStates",{records:e})}async getConsentState(e,t){return this.#i.sendMessage("preferences.getConsentState",{entityType:e,entity:t})}async streamConsent(e){return ve((async(t,s)=>{const i=v();return await this.sync(),await this.#i.sendMessage("preferences.streamConsent",{streamId:i}),this.#i.handleStreamMessage(i,t,{...e,onFail:s})}),void 0,e)}async streamPreferences(e){return ve((async(t,s)=>{const i=v();return await this.sync(),await this.#i.sendMessage("preferences.streamPreferences",{streamId:i}),this.#i.handleStreamMessage(i,t,{...e,onFail:s})}),void 0,e)}}const Ae=async(e,t)=>{switch(e.type){case"EOA":return{type:"EOA",identifier:await e.getIdentifier(),signature:t};case"SCW":return{type:"SCW",identifier:await e.getIdentifier(),signature:t,chainId:e.getChainId(),blockNumber:e.getBlockNumber?.()}}},ke=e=>{console.error(e.message)};class De{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),t&&this.#e.addEventListener("error",ke),this.#t=t}async init(){return this.sendMessage("utils.init",{enableLogging:this.#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(t.error):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#t&&this.#e.removeEventListener("error",ke),this.#e.terminate()}}class Pe extends De{constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1)}async generateInboxId(e){return this.sendMessage("utils.generateInboxId",{identifier:e})}async getInboxIdForIdentifier(e,t){return this.sendMessage("utils.getInboxIdForIdentifier",{identifier:e,env:t})}async revokeInstallationsSignatureText(e,t,s,i){return this.sendMessage("utils.revokeInstallationsSignatureText",{env:i,identifier:e,inboxId:t,installationIds:s,signatureRequestId:v()})}async revokeInstallations(e,t,s,i){const n=await e.getIdentifier(),{signatureText:r,signatureRequestId:a}=await this.revokeInstallationsSignatureText(n,t,s,i),o=await e.signMessage(r),c=await Ae(e,o);return this.sendMessage("utils.revokeInstallations",{signer:c,signatureRequestId:a,env:i})}async inboxStateFromInboxIds(e,t){return this.sendMessage("utils.inboxStateFromInboxIds",{inboxIds:e,env:t})}}class Te extends M{#I;#v;#w;#f;#M;#b;#S;#x=!1;#A;#k;#D;constructor(t){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==t?.loggingLevel&&"off"!==t.loggingLevel),this.#D=t,this.#v=new be(this),this.#w=new Se(this),this.#A=new xe(this);const s=[new e,new i,...t?.codecs??[]];this.#I=new Map(s.map((e=>[e.contentType.toString(),e])))}async init(e){const t=await this.sendMessage("client.init",{identifier:e,options:this.#D});this.#f=e,this.#M=t.inboxId,this.#b=t.installationId,this.#S=t.installationIdBytes,this.#x=!0}static async create(e,t){const s=new Te(t);return s.#k=e,await s.init(await e.getIdentifier()),t?.disableAutoRegister||await s.register(),s}static async build(e,t){const s=new Te({...t,disableAutoRegister:!0});return await s.init(e),s}get options(){return this.#D}get signer(){return this.#k}get isReady(){return this.#x}get inboxId(){return this.#M}get accountIdentifier(){return this.#f}get installationId(){return this.#b}get installationIdBytes(){return this.#S}get conversations(){return this.#v}get debugInformation(){return this.#w}get preferences(){return this.#A}async unsafe_createInboxSignatureText(){return this.sendMessage("client.createInboxSignatureText",{signatureRequestId:v()})}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new re;return this.sendMessage("client.addAccountSignatureText",{newIdentifier:e,signatureRequestId:v()})}async unsafe_removeAccountSignatureText(e){return this.sendMessage("client.removeAccountSignatureText",{identifier:e,signatureRequestId:v()})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.sendMessage("client.revokeAllOtherInstallationsSignatureText",{signatureRequestId:v()})}async unsafe_revokeInstallationsSignatureText(e){return this.sendMessage("client.revokeInstallationsSignatureText",{installationIds:e,signatureRequestId:v()})}async unsafe_changeRecoveryIdentifierSignatureText(e){return this.sendMessage("client.changeRecoveryIdentifierSignatureText",{identifier:e,signatureRequestId:v()})}async unsafe_applySignatureRequest(e,t){return this.sendMessage("client.applySignatureRequest",{signer:e,signatureRequestId:t})}async register(){if(!this.#k)throw new ie;const{signatureText:e,signatureRequestId:t}=await this.unsafe_createInboxSignatureText();if(!e||!t)return;const s=await this.#k.signMessage(e),i=await Ae(this.#k,s);return this.sendMessage("client.registerIdentity",{signer:i,signatureRequestId:t})}async unsafe_addAccount(e,t=!1){if(!this.#k)throw new ie;if(!t)throw new re;const s=await this.findInboxIdByIdentifier(await e.getIdentifier());if(s)throw new ae(s);const{signatureText:i,signatureRequestId:n}=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0),r=await e.signMessage(i),a=await Ae(e,r);return this.sendMessage("client.addAccount",{identifier:a.identifier,signer:a,signatureRequestId:n})}async removeAccount(e){if(!this.#k)throw new ie;const{signatureText:t,signatureRequestId:s}=await this.unsafe_removeAccountSignatureText(e),i=await this.#k.signMessage(t),n=await Ae(this.#k,i);return this.sendMessage("client.removeAccount",{identifier:e,signer:n,signatureRequestId:s})}async revokeAllOtherInstallations(){if(!this.#k)throw new ie;const{signatureText:e,signatureRequestId:t}=await this.unsafe_revokeAllOtherInstallationsSignatureText(),s=await this.#k.signMessage(e),i=await Ae(this.#k,s);return this.sendMessage("client.revokeAllOtherInstallations",{signer:i,signatureRequestId:t})}async revokeInstallations(e){if(!this.#k)throw new ie;const{signatureText:t,signatureRequestId:s}=await this.unsafe_revokeInstallationsSignatureText(e),i=await this.#k.signMessage(t),n=await Ae(this.#k,i);return this.sendMessage("client.revokeInstallations",{installationIds:e,signer:n,signatureRequestId:s})}static async revokeInstallations(e,t,s,i,n){const r=new Pe(n);await r.init(),await r.revokeInstallations(e,t,s,i),r.close()}static async inboxStateFromInboxIds(e,t,s){const i=new Pe(s);await i.init();const n=await i.inboxStateFromInboxIds(e,t);return i.close(),n}async changeRecoveryIdentifier(e){if(!this.#k)throw new ie;const{signatureText:t,signatureRequestId:s}=await this.unsafe_changeRecoveryIdentifierSignatureText(e),i=await this.#k.signMessage(t),n=await Ae(this.#k,i);return this.sendMessage("client.changeRecoveryIdentifier",{identifier:e,signer:n,signatureRequestId:s})}async isRegistered(){return this.sendMessage("client.isRegistered",void 0)}async canMessage(e){return this.sendMessage("client.canMessage",{identifiers:e})}static async canMessage(e,t){const s=new Map,i=new Pe;for(const n of e){const e=await i.getInboxIdForIdentifier(n,t);s.set(n.identifier.toLowerCase(),void 0!==e)}return i.close(),s}async findInboxIdByIdentifier(e){return this.sendMessage("client.findInboxIdByIdentifier",{identifier:e})}codecFor(e){return this.#I.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new ne(t);const i=s.encode(e,this),n=s.fallback(e);return n&&(i.fallback=n),P(i)}decodeContent(e,s){const i=this.codecFor(s);if(!i)throw new ne(s);if(s.sameAs(t)&&e.kind!==m.MembershipChange)throw new de(e.id);const n=T(e.content);return i.decode(n,this)}signWithInstallationKey(e){return this.sendMessage("client.signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("client.verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("client.verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}async getKeyPackageStatusesForInstallationIds(e){return this.sendMessage("client.getKeyPackageStatusesForInstallationIds",{installationIds:e})}}const Ce={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},Re={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{ae as AccountAlreadyAssociatedError,Ce as ApiUrls,Te as Client,se as ClientNotInitializedError,ne as CodecNotFoundError,we as Conversation,be as Conversations,te as DecodedMessage,fe as Dm,Me as Group,oe as GroupNotFoundError,Re as HistorySyncUrls,re as InboxReassignError,de as InvalidGroupMembershipChangeError,le as MissingContentTypeError,ie as SignerUnavailableError,ue as StreamFailedError,ge as StreamInvalidRetryAttemptsError,ce as StreamNotFoundError,Pe as Utils,S as fromContentTypeId,D as fromEncodedContent,$ as fromSafeConsent,A as fromSafeContentTypeId,U as fromSafeCreateDmOptions,G as fromSafeCreateGroupOptions,T as fromSafeEncodedContent,V as fromSafeGroupMember,q as fromSafeListConversationsOptions,N as fromSafeListMessagesOptions,Q as fromSafeMessageDisappearingSettings,F as fromSafePermissionPolicySet,b as toContentTypeId,k as toEncodedContent,Z as toSafeApiStats,j as toSafeConsent,x as toSafeContentTypeId,O as toSafeConversation,Y as toSafeConversationDebugInfo,E as toSafeCreateDmOptions,B as toSafeCreateGroupOptions,P as toSafeEncodedContent,H as toSafeGroupMember,z as toSafeHmacKey,ee as toSafeIdentityStats,W as toSafeInboxState,K as toSafeInstallation,X as toSafeKeyPackageStatus,L as toSafeListConversationsOptions,R as toSafeListMessagesOptions,C as toSafeMessage,J as toSafeMessageDisappearingSettings,_ as toSafePermissionPolicySet,Ae as toSafeSigner};
|
|
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 h,SendMessageOpts as p,GroupPermissionsOptions as m,GroupMessageKind as y,DeliveryStatus as I,ConversationType 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,SignatureRequestHandle,SortDirection}from"@xmtp/wasm-bindings";import{v4 as w}from"uuid";import{ContentTypeId as f}from"@xmtp/content-type-primitives";const M=e=>{console.error(e.message)};class b{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),t&&this.#e.addEventListener("error",M),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(t.error):s.resolve(t.result))};handleStreamMessage=(e,t,s)=>{const n=n=>{const i=n.data;if(i.streamId===e){if("stream.fail"===i.action)return void s?.onFail?.();"error"in i?t(i.error,void 0):t(null,i.result)}};return this.#e.addEventListener("message",n),async()=>{await this.sendMessage("endStream",{streamId:e}),this.#e.removeEventListener("message",n)}};close(){this.#e.removeEventListener("message",this.handleMessage),this.#t&&this.#e.removeEventListener("error",M),this.#e.terminate()}}const S=e=>new f({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),x=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}),k=e=>new f({authorityId:e.authorityId,typeId:e.typeId,versionMajor:e.versionMajor,versionMinor:e.versionMinor}),D=e=>({type:S(e.type),parameters:Object.fromEntries(e.parameters),fallback:e.fallback,compression:e.compression,content:e.content}),P=e=>new r(x(e.type),new Map(Object.entries(e.parameters)),e.fallback,e.compression,e.content),T=e=>({type:A(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),C=e=>({type:k(e.type),parameters:e.parameters,fallback:e.fallback,compression:e.compression,content:e.content}),N=e=>({content:T(D(e.content)),convoId:e.convoId,deliveryStatus:e.deliveryStatus,id:e.id,kind:e.kind,senderInboxId:e.senderInboxId,sentAtNs:e.sentAtNs}),R=e=>({contentTypes:e.contentTypes,deliveryStatus:e.deliveryStatus,direction:e.direction,excludeContentTypes:e.excludeContentTypes,excludeSenderInboxIds:e.excludeSenderInboxIds,insertedAfterNs:e.insertedAfterNs,insertedBeforeNs:e.insertedBeforeNs,kind:e.kind,limit:e.limit,sentAfterNs:e.sentAfterNs,sentBeforeNs:e.sentBeforeNs,sortBy:e.sortBy}),L=e=>new a(e.sentBeforeNs,e.sentAfterNs,e.limit,e.deliveryStatus,e.direction,e.contentTypes,e.excludeContentTypes,e.kind,e.excludeSenderInboxIds,e.sortBy,e.insertedAfterNs,e.insertedBeforeNs),B=e=>({shouldPush:e.shouldPush}),q=e=>new p(e.shouldPush),F=e=>({consentStates:e.consentStates,conversationType:e.conversationType,createdAfterNs:e.createdAfterNs,createdBeforeNs:e.createdBeforeNs,includeDuplicateDms:e.includeDuplicateDms,limit:e.limit,orderBy:e.orderBy}),_=e=>new o(e.consentStates,e.conversationType,e.createdAfterNs,e.createdBeforeNs,e.includeDuplicateDms??!1,e.limit,e.orderBy),G=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),O=e=>({customPermissionPolicySet:e.customPermissionPolicySet,description:e.groupDescription,imageUrlSquare:e.groupImageUrlSquare,messageDisappearingSettings:e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0,name:e.groupName,permissions:e.permissions}),U=e=>new c(e.permissions,e.name,e.imageUrlSquare,e.description,e.customPermissionPolicySet&&e.permissions===m.CustomPolicy?E(e.customPermissionPolicySet):void 0,e.messageDisappearingSettings?Z(e.messageDisappearingSettings):void 0),W=e=>({messageDisappearingSettings:e.messageDisappearingSettings?Y(e.messageDisappearingSettings):void 0}),K=e=>new l(e.messageDisappearingSettings?Z(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.addedByInboxId,o=await e.metadata(),d=e.admins,c=e.superAdmins,l=e.createdAtNs,u=r.policyType,g=r.policySet,h=e.isCommitLogForked;return{id:t,name:s,imageUrl:n,description:i,permissions:{policyType:u,policySet:{addAdminPolicy:g.addAdminPolicy,addMemberPolicy:g.addMemberPolicy,removeAdminPolicy:g.removeAdminPolicy,removeMemberPolicy:g.removeMemberPolicy,updateGroupDescriptionPolicy:g.updateGroupDescriptionPolicy,updateGroupImageUrlSquarePolicy:g.updateGroupImageUrlSquarePolicy,updateGroupNamePolicy:g.updateGroupNamePolicy,updateMessageDisappearingPolicy:g.updateMessageDisappearingPolicy}},addedByInboxId:a,metadata:o,admins:d,superAdmins:c,createdAtNs:l,isCommitLogForked:h}},H=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),V=e=>({identifiers:e.accountIdentifiers,inboxId:e.inboxId,installations:e.installations.map(H),recoveryIdentifier:e.recoveryIdentifier}),$=e=>({entity:e.entity,entityType:e.entityType,state:e.state}),z=e=>new u(e.entityType,e.state,e.entity),J=e=>({accountIdentifiers:e.accountIdentifiers,consentState:e.consentState,inboxId:e.inboxId,installationIds:e.installationIds,permissionLevel:e.permissionLevel}),Q=e=>new g(e.inboxId,e.accountIdentifiers,e.installationIds,e.permissionLevel,e.consentState),X=e=>({key:e.key,epoch:e.epoch}),Y=e=>({fromNs:e.fromNs,inNs:e.inNs}),Z=e=>new h(e.fromNs,e.inNs),ee=e=>({lifetime:e.lifetime?{notBefore:e.lifetime.not_before,notAfter:e.lifetime.not_after}:void 0,validationError:e.validationError}),te=e=>({epoch:e.epoch,maybeForked:e.maybeForked,forkDetails:e.forkDetails,isCommitLogForked:e.isCommitLogForked,localCommitLog:e.localCommitLog,remoteCommitLog:e.remoteCommitLog,cursor:e.cursor.map((e=>({originatorID:e.originator_id,sequenceID:e.sequence_id})))}),se=e=>({uploadKeyPackage:e.upload_key_package,fetchKeyPackage:e.fetch_key_package,sendGroupMessages:e.send_group_messages,sendWelcomeMessages:e.send_welcome_messages,queryGroupMessages:e.query_group_messages,queryWelcomeMessages:e.query_welcome_messages,subscribeMessages:e.subscribe_messages,subscribeWelcomes:e.subscribe_welcomes}),ne=e=>({getIdentityUpdatesV2:e.get_identity_updates_v2,getInboxIds:e.get_inbox_ids,publishIdentityUpdate:e.publish_identity_update,verifySmartContractWalletSignature:e.verify_smart_contract_wallet_signature});class ie{#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 y.Application:this.kind="application";break;case y.MembershipChange:this.kind="membership_change"}switch(t.deliveryStatus){case I.Unpublished:this.deliveryStatus="unpublished";break;case I.Published:this.deliveryStatus="published";break;case I.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;try{this.content=this.#n.decodeContent(t,this.contentType)}catch{this.content=void 0}}}class re extends Error{constructor(){super("Client not initialized, use Client.create or Client.build to create a client")}}class ae extends Error{constructor(){super("Signer unavailable, use Client.create to create a client with a signer")}}class oe extends Error{constructor(e){super(`Codec not found for "${e.toString()}" content type`)}}class de extends Error{constructor(){super("Unable to create add account signature text, `allowInboxReassign` must be true")}}class ce extends Error{constructor(e){super(`Account already associated with inbox ${e}`)}}class le extends Error{constructor(e){super(`Group "${e}" not found`)}}class ue extends Error{constructor(e){super(`Stream "${e}" not found`)}}class ge extends Error{constructor(e){super(`Invalid group membership change for message ${e}`)}}class he extends Error{constructor(){super("Content type is required when sending content other than text")}}class pe extends Error{constructor(e){super(`Stream failed, retried ${e} ${"time"+(1!==e?"s":"")}`)}}class me extends Error{constructor(){super("Stream retry attempts must be greater than 0")}}class ye{isDone=!1;#i=[];#r;onDone;onReturn;constructor(){this.#r=[],this.isDone=!1}flush(){for(;this.#i.length>0;){const e=this.#i.shift();e&&e({done:!0,value:void 0})}}done(){this.flush(),this.#r=[],this.#i=[],this.isDone=!0,this.onDone?.()}push=e=>{if(this.isDone)return;const t=this.#i.shift();t?t({done:!1,value:e}):this.#r.push(e)};next=()=>this.isDone?Promise.resolve({done:!0,value:void 0}):this.#r.length>0?Promise.resolve({done:!1,value:this.#r.shift()}):new Promise((e=>{this.#i.push(e)}));return=()=>(this.onReturn?.(),this.done(),Promise.resolve({done:!0,value:void 0}));end=()=>this.return();[Symbol.asyncIterator](){return this}}const Ie=["end","isDone","next","return",Symbol.asyncIterator],ve=e=>Ie.includes(e);const we=1e4,fe=6,Me=async(e,t,s)=>{const{onEnd:n,onError:i,onFail:r,onRestart:a,onRetry:o,onValue:d,retryAttempts:c=fe,retryDelay:l=we,retryOnFail:u=!0}=s??{};if(u&&c<0)throw new me;const g=new ye,h=(e,s)=>{if(e)i?.(e);else if(void 0!==s)try{if(t){const e=t(s);(e=>!!e&&("object"==typeof e||"function"==typeof e)&&"then"in e&&"function"==typeof e.then)(e)?e.then((e=>{g.push(e),d?.(e)})).catch((e=>{i?.(e)})):(g.push(e),d?.(e))}else g.push(s),d?.(s)}catch(e){i?.(e)}},p=async(t=c)=>{try{if(0===t)throw g.end(),new pe(c);await(s=l,new Promise((e=>setTimeout(e,s)))),o?.(c-t+1,c);const i=await e(h,(()=>{r?.(),p()}));g.onDone=()=>{i(),n?.()},a?.()}catch(e){i?.(e),p(t-1)}var s},m=()=>{if(!u)throw g.end(),new pe(0);p()};try{const t=await e(h,(()=>{r?.(),m()}));g.onDone=()=>{t(),n?.()}}catch(e){i?.(e),m()}return new Proxy(g,{get(e,t,s){if(ve(t))return Reflect.get(e,t,s)},set:()=>!0,has:(e,t)=>ve(t),ownKeys:()=>Ie,getOwnPropertyDescriptor(e,t){if(ve(t))return{enumerable:!0,configurable:!0,value:Reflect.get(e,t)}}})};class be{#a;#n;#o;#d;#c;#l;constructor(e,t,s){this.#n=e,this.#d=t,this.#u(s)}#u(e){this.#a=e?.addedByInboxId,this.#c=e?.metadata,this.#o=e?.createdAtNs,this.#l=e?.isCommitLogForked}get id(){return this.#d}get isCommitLogForked(){return this.#l}get addedByInboxId(){return this.#a}get createdAtNs(){return this.#o}get createdAt(){return this.#o?(e=this.#o,new Date(Number(e/1000000n))):void 0;var e}get metadata(){return this.#c}async lastMessage(){const e=await this.#n.sendMessage("conversation.lastMessage",{id:this.#d});return e?new ie(this.#n,e):void 0}async isActive(){return this.#n.sendMessage("conversation.isActive",{id:this.#d})}async members(){return this.#n.sendMessage("conversation.members",{id:this.#d})}async sync(){const e=await this.#n.sendMessage("conversation.sync",{id:this.#d});return this.#u(e),e}async publishMessages(){return this.#n.sendMessage("conversation.publishMessages",{id:this.#d})}async sendOptimistic(e,t){if("string"!=typeof e&&!t)throw new he;const{encodedContent:n,sendOptions:i}="string"==typeof e?this.#n.prepareForSend(e,t??s):this.#n.prepareForSend(e,t);return this.#n.sendMessage("conversation.sendOptimistic",{id:this.#d,content:n,sendOptions:i})}async send(e,t){if("string"!=typeof e&&!t)throw new he;const{encodedContent:n,sendOptions:i}="string"==typeof e?this.#n.prepareForSend(e,t??s):this.#n.prepareForSend(e,t);return this.#n.sendMessage("conversation.send",{id:this.#d,content:n,sendOptions:i})}async messages(e){return(await this.#n.sendMessage("conversation.messages",{id:this.#d,options:e})).map((e=>new ie(this.#n,e)))}async countMessages(e){return await this.#n.sendMessage("conversation.countMessages",{id:this.#d,options:e})}async consentState(){return this.#n.sendMessage("conversation.consentState",{id:this.#d})}async updateConsentState(e){return this.#n.sendMessage("conversation.updateConsentState",{id:this.#d,state:e})}async messageDisappearingSettings(){return this.#n.sendMessage("conversation.messageDisappearingSettings",{id:this.#d})}async updateMessageDisappearingSettings(e,t){return this.#n.sendMessage("conversation.updateMessageDisappearingSettings",{id:this.#d,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#n.sendMessage("conversation.removeMessageDisappearingSettings",{id:this.#d})}async isMessageDisappearingEnabled(){return this.#n.sendMessage("conversation.isMessageDisappearingEnabled",{id:this.#d})}async stream(e){return Me((async(t,s)=>{const n=w();return e?.disableSync||await this.sync(),await this.#n.sendMessage("conversation.stream",{groupId:this.#d,streamId:n}),this.#n.handleStreamMessage(n,t,{...e,onFail:s})}),(e=>new ie(this.#n,e)),e)}async pausedForVersion(){return this.#n.sendMessage("conversation.pausedForVersion",{id:this.#d})}async getHmacKeys(){return this.#n.sendMessage("conversation.getHmacKeys",{id:this.#d})}async debugInfo(){return this.#n.sendMessage("conversation.debugInfo",{id:this.#d})}}class Se extends be{#n;#d;constructor(e,t,s){super(e,t,s),this.#n=e,this.#d=t}async peerInboxId(){return this.#n.sendMessage("dm.peerInboxId",{id:this.#d})}async getDuplicateDms(){return this.#n.sendMessage("dm.getDuplicateDms",{id:this.#d})}}class xe extends be{#g=[];#n;#h;#d;#p;#m;#y=[];#u(e){this.#m=e?.name??"",this.#p=e?.imageUrl??"",this.#h=e?.description??"",this.#g=e?.admins??[],this.#y=e?.superAdmins??[]}constructor(e,t,s){super(e,t,s),this.#n=e,this.#d=t,this.#u(s)}async sync(){const e=await super.sync();return this.#u(e),e}get name(){return this.#m}async updateName(e){await this.#n.sendMessage("group.updateName",{id:this.#d,name:e}),this.#m=e}get imageUrl(){return this.#p}async updateImageUrl(e){await this.#n.sendMessage("group.updateImageUrl",{id:this.#d,imageUrl:e}),this.#p=e}get description(){return this.#h}async updateDescription(e){await this.#n.sendMessage("group.updateDescription",{id:this.#d,description:e}),this.#h=e}get admins(){return this.#g}get superAdmins(){return this.#y}async listAdmins(){const e=await this.#n.sendMessage("group.listAdmins",{id:this.#d});return this.#g=e,e}async listSuperAdmins(){const e=await this.#n.sendMessage("group.listSuperAdmins",{id:this.#d});return this.#y=e,e}async permissions(){return this.#n.sendMessage("group.permissions",{id:this.#d})}async updatePermission(e,t,s){return this.#n.sendMessage("group.updatePermission",{id:this.#d,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.#n.sendMessage("group.addMembersByIdentifiers",{id:this.#d,identifiers:e})}async addMembers(e){return this.#n.sendMessage("group.addMembers",{id:this.#d,inboxIds:e})}async removeMembersByIdentifiers(e){return this.#n.sendMessage("group.removeMembersByIdentifiers",{id:this.#d,identifiers:e})}async removeMembers(e){return this.#n.sendMessage("group.removeMembers",{id:this.#d,inboxIds:e})}async addAdmin(e){return this.#n.sendMessage("group.addAdmin",{id:this.#d,inboxId:e})}async removeAdmin(e){return this.#n.sendMessage("group.removeAdmin",{id:this.#d,inboxId:e})}async addSuperAdmin(e){return this.#n.sendMessage("group.addSuperAdmin",{id:this.#d,inboxId:e})}async removeSuperAdmin(e){return this.#n.sendMessage("group.removeSuperAdmin",{id:this.#d,inboxId:e})}}class Ae{#n;constructor(e){this.#n=e}async sync(){return this.#n.sendMessage("conversations.sync",void 0)}async syncAll(e){return this.#n.sendMessage("conversations.syncAll",{consentStates:e})}async getConversationById(e){const t=await this.#n.sendMessage("conversations.getConversationById",{id:e});if(t)return"group"===t.metadata.conversationType?new xe(this.#n,t.id,t):new Se(this.#n,t.id,t)}async getMessageById(e){const t=await this.#n.sendMessage("conversations.getMessageById",{id:e});return t?new ie(this.#n,t):void 0}async getDmByInboxId(e){const t=await this.#n.sendMessage("conversations.getDmByInboxId",{inboxId:e});return t?new Se(this.#n,t.id,t):void 0}async getDmByIdentifier(e){const t=await this.#n.findInboxIdByIdentifier(e);if(t)return this.getDmByInboxId(t)}async list(e){return(await this.#n.sendMessage("conversations.list",{options:e})).map((e=>{switch(e.metadata.conversationType){case"dm":return new Se(this.#n,e.id,e);case"group":return new xe(this.#n,e.id,e);default:return}})).filter((e=>void 0!==e))}async listGroups(e){return(await this.#n.sendMessage("conversations.listGroups",{options:e})).map((e=>new xe(this.#n,e.id,e)))}async listDms(e){return(await this.#n.sendMessage("conversations.listDms",{options:e})).map((e=>new Se(this.#n,e.id,e)))}async newGroupOptimistic(e){const t=await this.#n.sendMessage("conversations.newGroupOptimistic",{options:e});return new xe(this.#n,t.id,t)}async newGroupWithIdentifiers(e,t){const s=await this.#n.sendMessage("conversations.newGroupWithIdentifiers",{identifiers:e,options:t});return new xe(this.#n,s.id,s)}async newGroup(e,t){const s=await this.#n.sendMessage("conversations.newGroup",{inboxIds:e,options:t});return new xe(this.#n,s.id,s)}async newDmWithIdentifier(e,t){const s=await this.#n.sendMessage("conversations.newDmWithIdentifier",{identifier:e,options:t});return new Se(this.#n,s.id,s)}async newDm(e,t){const s=await this.#n.sendMessage("conversations.newDm",{inboxId:e,options:t});return new Se(this.#n,s.id,s)}async getHmacKeys(){return this.#n.sendMessage("conversations.getHmacKeys",void 0)}async stream(e){return Me((async(t,s)=>{const n=w();return e?.disableSync||await this.sync(),await this.#n.sendMessage("conversations.stream",{streamId:n,conversationType:e?.conversationType}),this.#n.handleStreamMessage(n,t,{...e,onFail:s})}),(e=>"group"===e.metadata.conversationType?new xe(this.#n,e.id,e):new Se(this.#n,e.id,e)),e)}async streamGroups(e){return this.stream({...e,conversationType:v.Group})}async streamDms(e){return this.stream({...e,conversationType:v.Dm})}async streamAllMessages(e){return Me((async(t,s)=>{const n=w();return e?.disableSync||await this.sync(),await this.#n.sendMessage("conversations.streamAllMessages",{streamId:n,conversationType:e?.conversationType,consentStates:e?.consentStates}),this.#n.handleStreamMessage(n,t,{...e,onFail:s})}),(e=>new ie(this.#n,e)),e)}async streamAllGroupMessages(e){return this.streamAllMessages({...e,conversationType:v.Group})}async streamAllDmMessages(e){return this.streamAllMessages({...e,conversationType:v.Dm})}async streamMessageDeletions(e){return Me((async t=>{const s=w();return await this.#n.sendMessage("conversations.streamMessageDeletions",{streamId:s}),this.#n.handleStreamMessage(s,t,e)}),void 0,e)}}class ke{#n;constructor(e){this.#n=e}apiStatistics(){return this.#n.sendMessage("debugInformation.apiStatistics",void 0)}apiIdentityStatistics(){return this.#n.sendMessage("debugInformation.apiIdentityStatistics",void 0)}apiAggregateStatistics(){return this.#n.sendMessage("debugInformation.apiAggregateStatistics",void 0)}clearAllStatistics(){return this.#n.sendMessage("debugInformation.clearAllStatistics",void 0)}uploadDebugArchive(e){return this.#n.sendMessage("debugInformation.uploadDebugArchive",{serverUrl:e})}}class De{#n;constructor(e){this.#n=e}sync(){return this.#n.sendMessage("preferences.sync",void 0)}async inboxState(e){return this.#n.sendMessage("preferences.inboxState",{refreshFromNetwork:e??!1})}async inboxStateFromInboxIds(e,t){return this.#n.sendMessage("preferences.inboxStateFromInboxIds",{inboxIds:e,refreshFromNetwork:t??!1})}async getLatestInboxState(e){return this.#n.sendMessage("preferences.getLatestInboxState",{inboxId:e})}async setConsentStates(e){return this.#n.sendMessage("preferences.setConsentStates",{records:e})}async getConsentState(e,t){return this.#n.sendMessage("preferences.getConsentState",{entityType:e,entity:t})}async streamConsent(e){return Me((async(t,s)=>{const n=w();return await this.sync(),await this.#n.sendMessage("preferences.streamConsent",{streamId:n}),this.#n.handleStreamMessage(n,t,{...e,onFail:s})}),void 0,e)}async streamPreferences(e){return Me((async(t,s)=>{const n=w();return await this.sync(),await this.#n.sendMessage("preferences.streamPreferences",{streamId:n}),this.#n.handleStreamMessage(n,t,{...e,onFail:s})}),void 0,e)}}const Pe=async(e,t)=>{switch(e.type){case"EOA":return{type:"EOA",identifier:await e.getIdentifier(),signature:t};case"SCW":return{type:"SCW",identifier:await e.getIdentifier(),signature:t,chainId:e.getChainId(),blockNumber:e.getBlockNumber?.()}}},Te=e=>{console.error(e.message)};class Ce{#e;#t;#s=new Map;constructor(e,t){this.#e=e,this.#e.addEventListener("message",this.handleMessage),t&&this.#e.addEventListener("error",Te),this.#t=t}async init(){return this.sendMessage("utils.init",{enableLogging:this.#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(t.error):s.resolve(t.result))};close(){this.#e.removeEventListener("message",this.handleMessage),this.#t&&this.#e.removeEventListener("error",Te),this.#e.terminate()}}class Ne extends Ce{constructor(e){super(new Worker(new URL("./workers/utils",import.meta.url),{type:"module"}),e??!1)}async generateInboxId(e){return this.sendMessage("utils.generateInboxId",{identifier:e})}async getInboxIdForIdentifier(e,t,s){return this.sendMessage("utils.getInboxIdForIdentifier",{identifier:e,env:t,gatewayHost:s})}async revokeInstallationsSignatureText(e,t,s,n,i){return this.sendMessage("utils.revokeInstallationsSignatureText",{env:n,identifier:e,inboxId:t,installationIds:s,signatureRequestId:w(),gatewayHost:i})}async revokeInstallations(e,t,s,n,i){const r=await e.getIdentifier(),{signatureText:a,signatureRequestId:o}=await this.revokeInstallationsSignatureText(r,t,s,n,i),d=await e.signMessage(a),c=await Pe(e,d);return this.sendMessage("utils.revokeInstallations",{signer:c,signatureRequestId:o,env:n,gatewayHost:i})}async inboxStateFromInboxIds(e,t,s){return this.sendMessage("utils.inboxStateFromInboxIds",{inboxIds:e,env:t,gatewayHost:s})}}class Re extends b{#I;#v;#w;#f;#M;#b;#S;#x=!1;#A;#k;#D;constructor(t){super(new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),void 0!==t?.loggingLevel&&"off"!==t.loggingLevel),this.#D=t,this.#v=new Ae(this),this.#w=new ke(this),this.#A=new De(this);const s=[new e,new n,...t?.codecs??[]];this.#I=new Map(s.map((e=>[e.contentType.toString(),e])))}async init(e){const t=await this.sendMessage("client.init",{identifier:e,options:this.#D});this.#f=e,this.#M=t.inboxId,this.#b=t.installationId,this.#S=t.installationIdBytes,this.#x=!0}static async create(e,t){const s=new Re(t);return s.#k=e,await s.init(await e.getIdentifier()),t?.disableAutoRegister||await s.register(),s}static async build(e,t){const s=new Re({...t,disableAutoRegister:!0});return await s.init(e),s}get options(){return this.#D}get signer(){return this.#k}get isReady(){return this.#x}get inboxId(){return this.#M}get accountIdentifier(){return this.#f}get installationId(){return this.#b}get installationIdBytes(){return this.#S}get conversations(){return this.#v}get debugInformation(){return this.#w}get preferences(){return this.#A}async libxmtpVersion(){return this.sendMessage("client.libxmtpVersion",void 0)}async appVersion(){return this.sendMessage("client.appVersion",void 0)}async unsafe_createInboxSignatureText(){return this.sendMessage("client.createInboxSignatureText",{signatureRequestId:w()})}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new de;return this.sendMessage("client.addAccountSignatureText",{newIdentifier:e,signatureRequestId:w()})}async unsafe_removeAccountSignatureText(e){return this.sendMessage("client.removeAccountSignatureText",{identifier:e,signatureRequestId:w()})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.sendMessage("client.revokeAllOtherInstallationsSignatureText",{signatureRequestId:w()})}async unsafe_revokeInstallationsSignatureText(e){return this.sendMessage("client.revokeInstallationsSignatureText",{installationIds:e,signatureRequestId:w()})}async unsafe_changeRecoveryIdentifierSignatureText(e){return this.sendMessage("client.changeRecoveryIdentifierSignatureText",{identifier:e,signatureRequestId:w()})}async unsafe_applySignatureRequest(e,t){return this.sendMessage("client.applySignatureRequest",{signer:e,signatureRequestId:t})}async register(){if(!this.#k)throw new ae;const{signatureText:e,signatureRequestId:t}=await this.unsafe_createInboxSignatureText();if(!e||!t)return;const s=await this.#k.signMessage(e),n=await Pe(this.#k,s);return this.sendMessage("client.registerIdentity",{signer:n,signatureRequestId:t})}async unsafe_addAccount(e,t=!1){if(!this.#k)throw new ae;if(!t)throw new de;const s=await this.findInboxIdByIdentifier(await e.getIdentifier());if(s)throw new ce(s);const{signatureText:n,signatureRequestId:i}=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0),r=await e.signMessage(n),a=await Pe(e,r);return this.sendMessage("client.addAccount",{identifier:a.identifier,signer:a,signatureRequestId:i})}async removeAccount(e){if(!this.#k)throw new ae;const{signatureText:t,signatureRequestId:s}=await this.unsafe_removeAccountSignatureText(e),n=await this.#k.signMessage(t),i=await Pe(this.#k,n);return this.sendMessage("client.removeAccount",{identifier:e,signer:i,signatureRequestId:s})}async revokeAllOtherInstallations(){if(!this.#k)throw new ae;const{signatureText:e,signatureRequestId:t}=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)return;const s=await this.#k.signMessage(e),n=await Pe(this.#k,s);return this.sendMessage("client.revokeAllOtherInstallations",{signer:n,signatureRequestId:t})}async revokeInstallations(e){if(!this.#k)throw new ae;const{signatureText:t,signatureRequestId:s}=await this.unsafe_revokeInstallationsSignatureText(e),n=await this.#k.signMessage(t),i=await Pe(this.#k,n);return this.sendMessage("client.revokeInstallations",{installationIds:e,signer:i,signatureRequestId:s})}static async revokeInstallations(e,t,s,n,i,r){const a=new Ne(r);await a.init(),await a.revokeInstallations(e,t,s,n,i),a.close()}static async inboxStateFromInboxIds(e,t,s,n){const i=new Ne(s);await i.init();const r=await i.inboxStateFromInboxIds(e,t,n);return i.close(),r}async changeRecoveryIdentifier(e){if(!this.#k)throw new ae;const{signatureText:t,signatureRequestId:s}=await this.unsafe_changeRecoveryIdentifierSignatureText(e),n=await this.#k.signMessage(t),i=await Pe(this.#k,n);return this.sendMessage("client.changeRecoveryIdentifier",{identifier:e,signer:i,signatureRequestId:s})}async isRegistered(){return this.sendMessage("client.isRegistered",void 0)}async canMessage(e){return this.sendMessage("client.canMessage",{identifiers:e})}static async canMessage(e,t){const s=new Map,n=new Ne;for(const i of e){const e=await n.getInboxIdForIdentifier(i,t);s.set(i.identifier.toLowerCase(),void 0!==e)}return n.close(),s}async findInboxIdByIdentifier(e){return this.sendMessage("client.findInboxIdByIdentifier",{identifier:e})}codecFor(e){return this.#I.get(e.toString())}encodeContent(e,t){const s=this.codecFor(t);if(!s)throw new oe(t);return this.#P(e,s)}prepareForSend(e,t){const s=this.codecFor(t);if(!s)throw new oe(t);return{encodedContent:this.#P(e,s),sendOptions:this.#T(e,s)}}#P(e,t){const s=t.encode(e,this),n=t.fallback(e);return n&&(s.fallback=n),T(s)}#T(e,t){return{shouldPush:t.shouldPush(e)}}decodeContent(e,s){const n=this.codecFor(s);if(!n)throw new oe(s);if(s.sameAs(t)&&e.kind!==y.MembershipChange)throw new ge(e.id);const i=C(e.content);return n.decode(i,this)}signWithInstallationKey(e){return this.sendMessage("client.signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.sendMessage("client.verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,s){return this.sendMessage("client.verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:s})}async getKeyPackageStatusesForInstallationIds(e){return this.sendMessage("client.getKeyPackageStatusesForInstallationIds",{installationIds:e})}}const Le={local:"http://localhost:5557",dev:"https://api.dev.xmtp.network:5558",production:"https://api.production.xmtp.network:5558"},Be={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network"};export{ce as AccountAlreadyAssociatedError,Le as ApiUrls,Re as Client,re as ClientNotInitializedError,oe as CodecNotFoundError,be as Conversation,Ae as Conversations,ie as DecodedMessage,Se as Dm,xe as Group,le as GroupNotFoundError,Be as HistorySyncUrls,de as InboxReassignError,ge as InvalidGroupMembershipChangeError,he as MissingContentTypeError,ae as SignerUnavailableError,pe as StreamFailedError,me as StreamInvalidRetryAttemptsError,ue as StreamNotFoundError,Ne as Utils,x as fromContentTypeId,P as fromEncodedContent,z as fromSafeConsent,k as fromSafeContentTypeId,K as fromSafeCreateDmOptions,U as fromSafeCreateGroupOptions,C as fromSafeEncodedContent,Q as fromSafeGroupMember,_ as fromSafeListConversationsOptions,L as fromSafeListMessagesOptions,Z as fromSafeMessageDisappearingSettings,E as fromSafePermissionPolicySet,q as fromSafeSendMessageOpts,S as toContentTypeId,D as toEncodedContent,se as toSafeApiStats,$ as toSafeConsent,A as toSafeContentTypeId,j as toSafeConversation,te as toSafeConversationDebugInfo,W as toSafeCreateDmOptions,O as toSafeCreateGroupOptions,T as toSafeEncodedContent,J as toSafeGroupMember,X as toSafeHmacKey,ne as toSafeIdentityStats,V as toSafeInboxState,H as toSafeInstallation,ee as toSafeKeyPackageStatus,F as toSafeListConversationsOptions,R as toSafeListMessagesOptions,N as toSafeMessage,Y as toSafeMessageDisappearingSettings,G as toSafePermissionPolicySet,B as toSafeSendMessageOpts,Pe as toSafeSigner};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|