@xmtp/browser-sdk 6.4.1 → 6.5.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 +69 -111
- 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 -3
- package/src/Client.ts +14 -115
- package/src/Conversation.ts +13 -0
- package/src/WorkerClient.ts +7 -14
- package/src/WorkerConversation.ts +8 -4
- package/src/constants.ts +0 -5
- package/src/index.ts +1 -5
- package/src/types/actions/client.ts +2 -10
- package/src/types/actions/conversation.ts +10 -0
- package/src/types/options.ts +13 -27
- package/src/utils/createClient.ts +27 -58
- package/src/utils/inboxId.ts +15 -5
- package/src/utils/inboxState.ts +9 -5
- package/src/utils/installations.ts +17 -8
- package/src/workers/client.ts +7 -2
- package/src/utils/createBackend.ts +0 -45
package/src/Client.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { type ContentCodec } from "@xmtp/content-type-primitives";
|
|
2
|
-
import {
|
|
3
|
-
Backend,
|
|
4
|
-
LogLevel,
|
|
5
|
-
type ArchiveOptions,
|
|
6
|
-
type Identifier,
|
|
7
|
-
type InboxState,
|
|
8
|
-
} from "@xmtp/wasm-bindings";
|
|
2
|
+
import { LogLevel, type Identifier } from "@xmtp/wasm-bindings";
|
|
9
3
|
import { CodecRegistry } from "@/CodecRegistry";
|
|
10
4
|
import { Conversations } from "@/Conversations";
|
|
11
5
|
import { DebugInformation } from "@/DebugInformation";
|
|
@@ -16,7 +10,6 @@ import type {
|
|
|
16
10
|
ExtractCodecContentTypes,
|
|
17
11
|
XmtpEnv,
|
|
18
12
|
} from "@/types/options";
|
|
19
|
-
import { createBackend } from "@/utils/createBackend";
|
|
20
13
|
import {
|
|
21
14
|
AccountAlreadyAssociatedError,
|
|
22
15
|
InboxReassignError,
|
|
@@ -29,23 +22,6 @@ import { toSafeSigner, type SafeSigner, type Signer } from "@/utils/signer";
|
|
|
29
22
|
import { uuid } from "@/utils/uuid";
|
|
30
23
|
import { WorkerBridge } from "@/utils/WorkerBridge";
|
|
31
24
|
|
|
32
|
-
/**
|
|
33
|
-
* Resolves a `Backend` instance from either a `Backend` or an `XmtpEnv` string.
|
|
34
|
-
*
|
|
35
|
-
* @param envOrBackend - A `Backend` instance, or an `XmtpEnv` string
|
|
36
|
-
* @param gatewayHost - Optional gateway host (only used when `envOrBackend` is an `XmtpEnv`)
|
|
37
|
-
* @returns A `Backend` instance
|
|
38
|
-
*/
|
|
39
|
-
const resolveBackend = async (
|
|
40
|
-
envOrBackend?: XmtpEnv | Backend,
|
|
41
|
-
gatewayHost?: string,
|
|
42
|
-
): Promise<Backend> => {
|
|
43
|
-
if (envOrBackend instanceof Backend) {
|
|
44
|
-
return envOrBackend;
|
|
45
|
-
}
|
|
46
|
-
return createBackend({ env: envOrBackend, gatewayHost });
|
|
47
|
-
};
|
|
48
|
-
|
|
49
25
|
/**
|
|
50
26
|
* Client for interacting with the XMTP network
|
|
51
27
|
*/
|
|
@@ -54,7 +30,6 @@ export class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
54
30
|
#codecRegistry: CodecRegistry;
|
|
55
31
|
#conversations: Conversations<ContentTypes>;
|
|
56
32
|
#debugInformation: DebugInformation;
|
|
57
|
-
#env?: XmtpEnv;
|
|
58
33
|
#identifier?: Identifier;
|
|
59
34
|
#inboxId?: string;
|
|
60
35
|
#installationId?: string;
|
|
@@ -122,7 +97,6 @@ export class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
122
97
|
options: this.#options,
|
|
123
98
|
});
|
|
124
99
|
this.#appVersion = result.appVersion;
|
|
125
|
-
this.#env = result.env as XmtpEnv;
|
|
126
100
|
this.#identifier = identifier;
|
|
127
101
|
this.#inboxId = result.inboxId;
|
|
128
102
|
this.#installationId = result.installationId;
|
|
@@ -272,13 +246,6 @@ export class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
272
246
|
return this.#appVersion;
|
|
273
247
|
}
|
|
274
248
|
|
|
275
|
-
/**
|
|
276
|
-
* Gets the XMTP environment used by this client
|
|
277
|
-
*/
|
|
278
|
-
get env() {
|
|
279
|
-
return this.#env;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
249
|
/**
|
|
283
250
|
* Creates signature text for creating a new inbox
|
|
284
251
|
*
|
|
@@ -592,27 +559,10 @@ export class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
592
559
|
/**
|
|
593
560
|
* Revokes specific installations of the client's inbox without a client
|
|
594
561
|
*
|
|
562
|
+
* @param env - The environment to use
|
|
595
563
|
* @param signer - The signer to use
|
|
596
564
|
* @param inboxId - The inbox ID to revoke installations for
|
|
597
565
|
* @param installationIds - The installation IDs to revoke
|
|
598
|
-
* @param backend - Optional `Backend` instance created with `createBackend()`
|
|
599
|
-
*/
|
|
600
|
-
static async revokeInstallations(
|
|
601
|
-
signer: Signer,
|
|
602
|
-
inboxId: string,
|
|
603
|
-
installationIds: Uint8Array[],
|
|
604
|
-
backend?: Backend,
|
|
605
|
-
): Promise<void>;
|
|
606
|
-
/**
|
|
607
|
-
* Revokes specific installations of the client's inbox without a client
|
|
608
|
-
*
|
|
609
|
-
* @param signer - The signer to use
|
|
610
|
-
* @param inboxId - The inbox ID to revoke installations for
|
|
611
|
-
* @param installationIds - The installation IDs to revoke
|
|
612
|
-
* @param env - The environment to use
|
|
613
|
-
* @param gatewayHost - Optional gateway host
|
|
614
|
-
* @deprecated Pass a `Backend` instance created with `createBackend()` instead
|
|
615
|
-
* of `XmtpEnv` and `gatewayHost`.
|
|
616
566
|
*/
|
|
617
567
|
static async revokeInstallations(
|
|
618
568
|
signer: Signer,
|
|
@@ -620,53 +570,30 @@ export class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
620
570
|
installationIds: Uint8Array[],
|
|
621
571
|
env?: XmtpEnv,
|
|
622
572
|
gatewayHost?: string,
|
|
623
|
-
): Promise<void>;
|
|
624
|
-
static async revokeInstallations(
|
|
625
|
-
signer: Signer,
|
|
626
|
-
inboxId: string,
|
|
627
|
-
installationIds: Uint8Array[],
|
|
628
|
-
envOrBackend?: XmtpEnv | Backend,
|
|
629
|
-
gatewayHost?: string,
|
|
630
573
|
) {
|
|
631
|
-
|
|
632
|
-
|
|
574
|
+
await utilsRevokeInstallations(
|
|
575
|
+
signer,
|
|
576
|
+
inboxId,
|
|
577
|
+
installationIds,
|
|
578
|
+
env,
|
|
579
|
+
gatewayHost,
|
|
580
|
+
);
|
|
633
581
|
}
|
|
634
582
|
|
|
635
|
-
/**
|
|
636
|
-
* Fetches the inbox states for the specified inbox IDs from the network
|
|
637
|
-
* without a client
|
|
638
|
-
*
|
|
639
|
-
* @param inboxIds - The inbox IDs to get the state for
|
|
640
|
-
* @param backend - Optional `Backend` instance created with `createBackend()`
|
|
641
|
-
* @returns The inbox states for the specified inbox IDs
|
|
642
|
-
*/
|
|
643
|
-
static async fetchInboxStates(
|
|
644
|
-
inboxIds: string[],
|
|
645
|
-
backend?: Backend,
|
|
646
|
-
): Promise<InboxState[]>;
|
|
647
583
|
/**
|
|
648
584
|
* Fetches the inbox states for the specified inbox IDs from the network
|
|
649
585
|
* without a client
|
|
650
586
|
*
|
|
651
587
|
* @param inboxIds - The inbox IDs to get the state for
|
|
652
588
|
* @param env - The environment to use
|
|
653
|
-
* @param gatewayHost - Optional gateway host
|
|
654
589
|
* @returns The inbox states for the specified inbox IDs
|
|
655
|
-
* @deprecated Pass a `Backend` instance created with `createBackend()` instead
|
|
656
|
-
* of `XmtpEnv` and `gatewayHost`.
|
|
657
590
|
*/
|
|
658
591
|
static async fetchInboxStates(
|
|
659
592
|
inboxIds: string[],
|
|
660
593
|
env?: XmtpEnv,
|
|
661
594
|
gatewayHost?: string,
|
|
662
|
-
): Promise<InboxState[]>;
|
|
663
|
-
static async fetchInboxStates(
|
|
664
|
-
inboxIds: string[],
|
|
665
|
-
envOrBackend?: XmtpEnv | Backend,
|
|
666
|
-
gatewayHost?: string,
|
|
667
595
|
) {
|
|
668
|
-
|
|
669
|
-
return utilsInboxStateFromInboxIds(backend, inboxIds);
|
|
596
|
+
return utilsInboxStateFromInboxIds(inboxIds, env, gatewayHost);
|
|
670
597
|
}
|
|
671
598
|
|
|
672
599
|
/**
|
|
@@ -713,40 +640,17 @@ export class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
713
640
|
return this.#worker.action("client.canMessage", { identifiers });
|
|
714
641
|
}
|
|
715
642
|
|
|
716
|
-
/**
|
|
717
|
-
* Checks if the specified identifiers can be messaged
|
|
718
|
-
*
|
|
719
|
-
* @param identifiers - The identifiers to check
|
|
720
|
-
* @param backend - Optional `Backend` instance created with `createBackend()`
|
|
721
|
-
* @returns Map of identifiers to whether they can be messaged
|
|
722
|
-
*/
|
|
723
|
-
static async canMessage(
|
|
724
|
-
identifiers: Identifier[],
|
|
725
|
-
backend?: Backend,
|
|
726
|
-
): Promise<Map<string, boolean>>;
|
|
727
643
|
/**
|
|
728
644
|
* Checks if the specified identifiers can be messaged
|
|
729
645
|
*
|
|
730
646
|
* @param identifiers - The identifiers to check
|
|
731
647
|
* @param env - Optional XMTP environment
|
|
732
648
|
* @returns Map of identifiers to whether they can be messaged
|
|
733
|
-
* @deprecated Pass a `Backend` instance created with `createBackend()` instead
|
|
734
|
-
* of `XmtpEnv`.
|
|
735
649
|
*/
|
|
736
|
-
|
|
737
|
-
static async canMessage(
|
|
738
|
-
identifiers: Identifier[],
|
|
739
|
-
env?: XmtpEnv,
|
|
740
|
-
): Promise<Map<string, boolean>>;
|
|
741
|
-
/* eslint-enable @typescript-eslint/unified-signatures */
|
|
742
|
-
static async canMessage(
|
|
743
|
-
identifiers: Identifier[],
|
|
744
|
-
envOrBackend?: XmtpEnv | Backend,
|
|
745
|
-
) {
|
|
746
|
-
const backend = await resolveBackend(envOrBackend);
|
|
650
|
+
static async canMessage(identifiers: Identifier[], env?: XmtpEnv) {
|
|
747
651
|
const canMessageMap = new Map<string, boolean>();
|
|
748
652
|
for (const identifier of identifiers) {
|
|
749
|
-
const inboxId = await getInboxIdForIdentifier(
|
|
653
|
+
const inboxId = await getInboxIdForIdentifier(identifier, env);
|
|
750
654
|
canMessageMap.set(
|
|
751
655
|
identifier.identifier.toLowerCase(),
|
|
752
656
|
inboxId !== undefined,
|
|
@@ -831,14 +735,9 @@ export class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
831
735
|
/**
|
|
832
736
|
* Send a sync request to other devices on the network
|
|
833
737
|
*
|
|
834
|
-
* @param options - Archive options specifying what to sync
|
|
835
|
-
* @param serverUrl - The server URL for the sync request
|
|
836
738
|
* @returns Promise that resolves when the sync request is sent
|
|
837
739
|
*/
|
|
838
|
-
async sendSyncRequest(
|
|
839
|
-
return this.#worker.action("client.sendSyncRequest"
|
|
840
|
-
options,
|
|
841
|
-
serverUrl,
|
|
842
|
-
});
|
|
740
|
+
async sendSyncRequest() {
|
|
741
|
+
return this.#worker.action("client.sendSyncRequest");
|
|
843
742
|
}
|
|
844
743
|
}
|
package/src/Conversation.ts
CHANGED
|
@@ -140,6 +140,19 @@ export class Conversation<ContentTypes = unknown> {
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Decodes, decrypts, and persists a raw envelope from a group message stream.
|
|
145
|
+
*
|
|
146
|
+
* @param envelopeBytes - Raw protobuf-encoded envelope bytes from the stream
|
|
147
|
+
* @returns The processed and stored messages
|
|
148
|
+
*/
|
|
149
|
+
async processStreamedMessage(envelopeBytes: Uint8Array) {
|
|
150
|
+
return this.#worker.action("conversation.processStreamedMessage", {
|
|
151
|
+
id: this.#id,
|
|
152
|
+
envelopeBytes,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
143
156
|
/**
|
|
144
157
|
* Sends a message
|
|
145
158
|
*
|
package/src/WorkerClient.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
verifySignedWithPublicKey,
|
|
3
|
-
type ArchiveOptions,
|
|
4
3
|
type Client,
|
|
5
4
|
type Identifier,
|
|
6
5
|
type KeyPackageStatus,
|
|
7
6
|
type SignatureRequestHandle,
|
|
8
7
|
} from "@xmtp/wasm-bindings";
|
|
9
|
-
import type { ClientOptions
|
|
8
|
+
import type { ClientOptions } from "@/types/options";
|
|
10
9
|
import { createClient } from "@/utils/createClient";
|
|
11
10
|
import type { SafeSigner } from "@/utils/signer";
|
|
12
11
|
import { WorkerConversations } from "@/WorkerConversations";
|
|
@@ -17,12 +16,10 @@ export class WorkerClient {
|
|
|
17
16
|
#client: Client;
|
|
18
17
|
#conversations: WorkerConversations;
|
|
19
18
|
#debugInformation: WorkerDebugInformation;
|
|
20
|
-
#env: XmtpEnv;
|
|
21
19
|
#preferences: WorkerPreferences;
|
|
22
20
|
|
|
23
|
-
constructor(client: Client
|
|
21
|
+
constructor(client: Client) {
|
|
24
22
|
this.#client = client;
|
|
25
|
-
this.#env = env;
|
|
26
23
|
const conversations = client.conversations();
|
|
27
24
|
this.#conversations = new WorkerConversations(this, conversations);
|
|
28
25
|
this.#debugInformation = new WorkerDebugInformation(client);
|
|
@@ -33,8 +30,8 @@ export class WorkerClient {
|
|
|
33
30
|
identifier: Identifier,
|
|
34
31
|
options?: Omit<ClientOptions, "codecs">,
|
|
35
32
|
) {
|
|
36
|
-
const
|
|
37
|
-
return new WorkerClient(client
|
|
33
|
+
const client = await createClient(identifier, options);
|
|
34
|
+
return new WorkerClient(client);
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
get libxmtpVersion() {
|
|
@@ -45,10 +42,6 @@ export class WorkerClient {
|
|
|
45
42
|
return this.#client.appVersion;
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
get env() {
|
|
49
|
-
return this.#env;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
45
|
get accountIdentifier() {
|
|
53
46
|
return this.#client.accountIdentifier;
|
|
54
47
|
}
|
|
@@ -151,7 +144,7 @@ export class WorkerClient {
|
|
|
151
144
|
}
|
|
152
145
|
|
|
153
146
|
async getInboxIdByIdentifier(identifier: Identifier) {
|
|
154
|
-
return this.#client.
|
|
147
|
+
return this.#client.findInboxIdByIdentifier(identifier);
|
|
155
148
|
}
|
|
156
149
|
|
|
157
150
|
signWithInstallationKey(signatureText: string) {
|
|
@@ -192,7 +185,7 @@ export class WorkerClient {
|
|
|
192
185
|
) as Promise<Map<string, KeyPackageStatus>>;
|
|
193
186
|
}
|
|
194
187
|
|
|
195
|
-
async sendSyncRequest(
|
|
196
|
-
return this.#client.
|
|
188
|
+
async sendSyncRequest() {
|
|
189
|
+
return this.#client.sendSyncRequest();
|
|
197
190
|
}
|
|
198
191
|
}
|
|
@@ -153,19 +153,19 @@ export class WorkerConversation {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
async addMembersByIdentifiers(identifiers: Identifier[]) {
|
|
156
|
-
return this.#group.
|
|
156
|
+
return this.#group.addMembers(identifiers);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
async addMembers(inboxIds: string[]) {
|
|
160
|
-
return this.#group.
|
|
160
|
+
return this.#group.addMembersByInboxId(inboxIds);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
async removeMembersByIdentifiers(identifiers: Identifier[]) {
|
|
164
|
-
return this.#group.
|
|
164
|
+
return this.#group.removeMembers(identifiers);
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
async removeMembers(inboxIds: string[]) {
|
|
168
|
-
return this.#group.
|
|
168
|
+
return this.#group.removeMembersByInboxId(inboxIds);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
async addAdmin(inboxId: string) {
|
|
@@ -188,6 +188,10 @@ export class WorkerConversation {
|
|
|
188
188
|
return this.#group.publishMessages();
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
async processStreamedMessage(envelopeBytes: Uint8Array) {
|
|
192
|
+
return this.#group.processStreamedGroupMessage(envelopeBytes);
|
|
193
|
+
}
|
|
194
|
+
|
|
191
195
|
async send(encodedContent: EncodedContent, opts?: SendMessageOpts) {
|
|
192
196
|
return this.#group.send(encodedContent, opts ?? { shouldPush: true });
|
|
193
197
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pre-configured URLs for the XMTP network based on the environment
|
|
3
3
|
*
|
|
4
|
-
* @deprecated Use `createBackend()` instead.
|
|
5
4
|
* @constant
|
|
6
5
|
* @property {string} local - The local URL for the XMTP network
|
|
7
6
|
* @property {string} dev - The development URL for the XMTP network
|
|
@@ -25,8 +24,4 @@ export const HistorySyncUrls = {
|
|
|
25
24
|
local: "http://localhost:5558",
|
|
26
25
|
dev: "https://message-history.dev.ephemera.network",
|
|
27
26
|
production: "https://message-history.production.ephemera.network",
|
|
28
|
-
"testnet-staging": "https://message-history.dev.ephemera.network",
|
|
29
|
-
"testnet-dev": "https://message-history.dev.ephemera.network",
|
|
30
|
-
testnet: "https://message-history.dev.ephemera.network",
|
|
31
|
-
mainnet: "https://message-history.production.ephemera.network",
|
|
32
27
|
} as const;
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,6 @@ export { Conversation } from "./Conversation";
|
|
|
5
5
|
export { Dm } from "./Dm";
|
|
6
6
|
export { Group } from "./Group";
|
|
7
7
|
export { DecodedMessage } from "./DecodedMessage";
|
|
8
|
-
export { createBackend } from "./utils/createBackend";
|
|
9
8
|
export { generateInboxId, getInboxIdForIdentifier } from "./utils/inboxId";
|
|
10
9
|
export { metadataFieldName } from "./utils/metadata";
|
|
11
10
|
export { ApiUrls, HistorySyncUrls } from "./constants";
|
|
@@ -17,10 +16,7 @@ export type {
|
|
|
17
16
|
Action,
|
|
18
17
|
Actions,
|
|
19
18
|
ApiStats,
|
|
20
|
-
ArchiveOptions,
|
|
21
19
|
Attachment,
|
|
22
|
-
Backend,
|
|
23
|
-
BackendBuilder,
|
|
24
20
|
Consent,
|
|
25
21
|
ConversationDebugInfo,
|
|
26
22
|
ConversationListItem,
|
|
@@ -54,6 +50,7 @@ export type {
|
|
|
54
50
|
Reaction,
|
|
55
51
|
ReadReceipt,
|
|
56
52
|
RemoteAttachment,
|
|
53
|
+
RemoteAttachmentInfo,
|
|
57
54
|
Reply,
|
|
58
55
|
SendMessageOpts,
|
|
59
56
|
SignatureRequestHandle,
|
|
@@ -65,7 +62,6 @@ export type {
|
|
|
65
62
|
} from "@xmtp/wasm-bindings";
|
|
66
63
|
export {
|
|
67
64
|
ActionStyle,
|
|
68
|
-
BackupElementSelectionOption,
|
|
69
65
|
ConsentEntityType,
|
|
70
66
|
ConsentState,
|
|
71
67
|
ContentType,
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ArchiveOptions,
|
|
3
|
-
Identifier,
|
|
4
|
-
KeyPackageStatus,
|
|
5
|
-
} from "@xmtp/wasm-bindings";
|
|
1
|
+
import type { Identifier, KeyPackageStatus } from "@xmtp/wasm-bindings";
|
|
6
2
|
import type { ClientOptions } from "@/types/options";
|
|
7
3
|
import type { SafeSigner } from "@/utils/signer";
|
|
8
4
|
|
|
@@ -12,7 +8,6 @@ export type ClientAction =
|
|
|
12
8
|
id: string;
|
|
13
9
|
result: {
|
|
14
10
|
appVersion: string;
|
|
15
|
-
env: string;
|
|
16
11
|
inboxId: string;
|
|
17
12
|
installationId: string;
|
|
18
13
|
installationIdBytes: Uint8Array;
|
|
@@ -221,8 +216,5 @@ export type ClientAction =
|
|
|
221
216
|
action: "client.sendSyncRequest";
|
|
222
217
|
id: string;
|
|
223
218
|
result: undefined;
|
|
224
|
-
data:
|
|
225
|
-
options: ArchiveOptions;
|
|
226
|
-
serverUrl: string;
|
|
227
|
-
};
|
|
219
|
+
data: undefined;
|
|
228
220
|
};
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
GroupMember,
|
|
9
9
|
Intent,
|
|
10
10
|
ListMessagesOptions,
|
|
11
|
+
Message,
|
|
11
12
|
MessageDisappearingSettings,
|
|
12
13
|
MultiRemoteAttachment,
|
|
13
14
|
Reaction,
|
|
@@ -50,6 +51,15 @@ export type ConversationAction =
|
|
|
50
51
|
id: string;
|
|
51
52
|
};
|
|
52
53
|
}
|
|
54
|
+
| {
|
|
55
|
+
action: "conversation.processStreamedMessage";
|
|
56
|
+
id: string;
|
|
57
|
+
result: Message[];
|
|
58
|
+
data: {
|
|
59
|
+
id: string;
|
|
60
|
+
envelopeBytes: Uint8Array;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
53
63
|
| {
|
|
54
64
|
action: "conversation.messages";
|
|
55
65
|
id: string;
|
package/src/types/options.ts
CHANGED
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
import type {
|
|
6
6
|
Actions,
|
|
7
7
|
Attachment,
|
|
8
|
-
Backend,
|
|
9
8
|
DeletedMessage,
|
|
10
9
|
GroupUpdated,
|
|
11
10
|
Intent,
|
|
@@ -18,16 +17,10 @@ import type {
|
|
|
18
17
|
TransactionReference,
|
|
19
18
|
WalletSendCalls,
|
|
20
19
|
} from "@xmtp/wasm-bindings";
|
|
20
|
+
import type { ApiUrls } from "@/constants";
|
|
21
21
|
import type { DecodedMessage } from "@/DecodedMessage";
|
|
22
22
|
|
|
23
|
-
export type XmtpEnv =
|
|
24
|
-
| "local"
|
|
25
|
-
| "dev"
|
|
26
|
-
| "production"
|
|
27
|
-
| "testnet-staging"
|
|
28
|
-
| "testnet-dev"
|
|
29
|
-
| "testnet"
|
|
30
|
-
| "mainnet";
|
|
23
|
+
export type XmtpEnv = keyof typeof ApiUrls;
|
|
31
24
|
|
|
32
25
|
/**
|
|
33
26
|
* Network options
|
|
@@ -42,29 +35,15 @@ export type NetworkOptions = {
|
|
|
42
35
|
* specific endpoint
|
|
43
36
|
*/
|
|
44
37
|
apiUrl?: string;
|
|
45
|
-
/**
|
|
46
|
-
* gatewayHost can be used to override the gateway endpoint
|
|
47
|
-
*/
|
|
48
|
-
gatewayHost?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Custom app version
|
|
51
|
-
*/
|
|
52
|
-
appVersion?: string;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Device sync options
|
|
57
|
-
*/
|
|
58
|
-
export type DeviceSyncOptions = {
|
|
59
38
|
/**
|
|
60
39
|
* historySyncUrl can be used to override the `env` flag and connect to a
|
|
61
40
|
* specific endpoint for syncing history
|
|
62
41
|
*/
|
|
63
42
|
historySyncUrl?: string | null;
|
|
64
43
|
/**
|
|
65
|
-
*
|
|
44
|
+
* gatewayHost can be used to override the gateway endpoint
|
|
66
45
|
*/
|
|
67
|
-
|
|
46
|
+
gatewayHost?: string | null;
|
|
68
47
|
};
|
|
69
48
|
|
|
70
49
|
export type ContentOptions = {
|
|
@@ -119,10 +98,17 @@ export type OtherOptions = {
|
|
|
119
98
|
* Disable automatic registration when creating a client
|
|
120
99
|
*/
|
|
121
100
|
disableAutoRegister?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Disable device sync
|
|
103
|
+
*/
|
|
104
|
+
disableDeviceSync?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Custom app version
|
|
107
|
+
*/
|
|
108
|
+
appVersion?: string;
|
|
122
109
|
};
|
|
123
110
|
|
|
124
|
-
export type ClientOptions =
|
|
125
|
-
DeviceSyncOptions &
|
|
111
|
+
export type ClientOptions = NetworkOptions &
|
|
126
112
|
ContentOptions &
|
|
127
113
|
StorageOptions &
|
|
128
114
|
OtherOptions;
|
|
@@ -1,85 +1,51 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
createClient as createWasmClient,
|
|
3
|
+
DeviceSyncWorkerMode,
|
|
4
4
|
generateInboxId,
|
|
5
5
|
getInboxIdForIdentifier,
|
|
6
|
-
type Backend,
|
|
7
6
|
type Identifier,
|
|
8
7
|
} from "@xmtp/wasm-bindings";
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
const networkOptionKeys = [
|
|
13
|
-
"env",
|
|
14
|
-
"apiUrl",
|
|
15
|
-
"gatewayHost",
|
|
16
|
-
"appVersion",
|
|
17
|
-
] as const;
|
|
18
|
-
|
|
19
|
-
const hasBackend = (options: object): options is { backend: Backend } => {
|
|
20
|
-
return "backend" in options;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const resolveBackend = async (
|
|
24
|
-
options?: Omit<ClientOptions, "codecs">,
|
|
25
|
-
): Promise<Backend> => {
|
|
26
|
-
if (!options) {
|
|
27
|
-
return createBackend();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (hasBackend(options)) {
|
|
31
|
-
// Validate that no NetworkOptions fields are also set
|
|
32
|
-
const conflicting = networkOptionKeys.filter(
|
|
33
|
-
(key) =>
|
|
34
|
-
key in options && (options as Record<string, unknown>)[key] != null,
|
|
35
|
-
);
|
|
36
|
-
if (conflicting.length > 0) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`Cannot specify both 'backend' and network options (${conflicting.join(", ")}). ` +
|
|
39
|
-
`Use either a pre-built Backend or network options, not both.`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return options.backend;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// No backend provided — build one from NetworkOptions
|
|
46
|
-
return createBackend(options as NetworkOptions);
|
|
47
|
-
};
|
|
8
|
+
import { ApiUrls, HistorySyncUrls } from "@/constants";
|
|
9
|
+
import type { ClientOptions } from "@/types/options";
|
|
48
10
|
|
|
49
11
|
export const createClient = async (
|
|
50
12
|
identifier: Identifier,
|
|
51
13
|
options?: Omit<ClientOptions, "codecs">,
|
|
52
14
|
) => {
|
|
53
|
-
const
|
|
54
|
-
|
|
15
|
+
const env = options?.env || "dev";
|
|
16
|
+
const host = options?.apiUrl || ApiUrls[env];
|
|
17
|
+
const gatewayHost = options?.gatewayHost || undefined;
|
|
18
|
+
const isSecure = host.startsWith("https");
|
|
55
19
|
const inboxId =
|
|
56
|
-
(await getInboxIdForIdentifier(
|
|
20
|
+
(await getInboxIdForIdentifier(host, gatewayHost, isSecure, identifier)) ||
|
|
57
21
|
generateInboxId(identifier);
|
|
58
|
-
|
|
59
|
-
const envString = envToString(backend.env);
|
|
60
|
-
|
|
61
22
|
const dbPath =
|
|
62
23
|
options?.dbPath === undefined
|
|
63
|
-
? `xmtp-${
|
|
24
|
+
? `xmtp-${env}-${inboxId}.db3`
|
|
64
25
|
: options.dbPath;
|
|
65
|
-
|
|
66
26
|
const isLogging =
|
|
67
27
|
options &&
|
|
68
28
|
(options.loggingLevel !== undefined ||
|
|
69
29
|
options.structuredLogging ||
|
|
70
30
|
options.performanceLogging);
|
|
71
31
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
32
|
+
const historySyncUrl =
|
|
33
|
+
options?.historySyncUrl === undefined
|
|
34
|
+
? HistorySyncUrls[env]
|
|
35
|
+
: options.historySyncUrl;
|
|
36
|
+
|
|
37
|
+
const deviceSyncWorkerMode = options?.disableDeviceSync
|
|
38
|
+
? DeviceSyncWorkerMode.Disabled
|
|
39
|
+
: DeviceSyncWorkerMode.Enabled;
|
|
75
40
|
|
|
76
|
-
|
|
77
|
-
|
|
41
|
+
return createWasmClient(
|
|
42
|
+
host,
|
|
78
43
|
inboxId,
|
|
79
44
|
identifier,
|
|
80
45
|
dbPath,
|
|
81
46
|
options?.dbEncryptionKey,
|
|
82
|
-
|
|
47
|
+
historySyncUrl,
|
|
48
|
+
deviceSyncWorkerMode,
|
|
83
49
|
isLogging
|
|
84
50
|
? {
|
|
85
51
|
structured: options.structuredLogging ?? false,
|
|
@@ -88,8 +54,11 @@ export const createClient = async (
|
|
|
88
54
|
}
|
|
89
55
|
: undefined,
|
|
90
56
|
undefined, // allowOffline
|
|
57
|
+
options?.appVersion,
|
|
58
|
+
options?.gatewayHost,
|
|
91
59
|
undefined, // nonce
|
|
60
|
+
undefined, // authCallback
|
|
61
|
+
undefined, // authHandle
|
|
62
|
+
undefined, // clientMode
|
|
92
63
|
);
|
|
93
|
-
|
|
94
|
-
return { client, env: envString };
|
|
95
64
|
};
|
package/src/utils/inboxId.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import init, {
|
|
2
2
|
generateInboxId as wasmGenerateInboxId,
|
|
3
3
|
getInboxIdForIdentifier as wasmGetInboxIdForIdentifier,
|
|
4
|
-
type Backend,
|
|
5
4
|
type Identifier,
|
|
6
5
|
} from "@xmtp/wasm-bindings";
|
|
6
|
+
import { ApiUrls } from "@/constants";
|
|
7
|
+
import type { XmtpEnv } from "@/types/options";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Generates an inbox ID for a given identifier
|
|
@@ -21,16 +22,25 @@ export const generateInboxId = async (
|
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* Gets the inbox ID for a specific identifier
|
|
25
|
+
* Gets the inbox ID for a specific identifier and optional environment
|
|
25
26
|
*
|
|
26
|
-
* @param backend - The Backend instance for API communication
|
|
27
27
|
* @param identifier - The identifier to get the inbox ID for
|
|
28
|
+
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
29
|
+
* @param gatewayHost - Optional gateway host override
|
|
28
30
|
* @returns Promise that resolves with the inbox ID for the identifier
|
|
29
31
|
*/
|
|
30
32
|
export const getInboxIdForIdentifier = async (
|
|
31
|
-
backend: Backend,
|
|
32
33
|
identifier: Identifier,
|
|
34
|
+
env?: XmtpEnv,
|
|
35
|
+
gatewayHost?: string,
|
|
33
36
|
): Promise<string | undefined> => {
|
|
34
37
|
await init();
|
|
35
|
-
|
|
38
|
+
const host = env ? ApiUrls[env] : ApiUrls.dev;
|
|
39
|
+
const isSecure = host.startsWith("https");
|
|
40
|
+
return wasmGetInboxIdForIdentifier(
|
|
41
|
+
host,
|
|
42
|
+
gatewayHost ?? null,
|
|
43
|
+
isSecure,
|
|
44
|
+
identifier,
|
|
45
|
+
);
|
|
36
46
|
};
|