@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/utils/inboxState.ts
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import init, {
|
|
2
2
|
inboxStateFromInboxIds as wasmInboxStateFromInboxIds,
|
|
3
|
-
type Backend,
|
|
4
3
|
} from "@xmtp/wasm-bindings";
|
|
4
|
+
import { ApiUrls } from "@/constants";
|
|
5
|
+
import type { XmtpEnv } from "@/types/options";
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Gets the inbox state for the specified inbox IDs
|
|
8
|
+
* Gets the inbox state for the specified inbox IDs without a client
|
|
8
9
|
*
|
|
9
|
-
* @param backend - The Backend instance for API communication
|
|
10
10
|
* @param inboxIds - The inbox IDs to get the state for
|
|
11
|
+
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
12
|
+
* @param gatewayHost - Optional gateway host override
|
|
11
13
|
* @returns The inbox state for the specified inbox IDs
|
|
12
14
|
*/
|
|
13
15
|
export const inboxStateFromInboxIds = async (
|
|
14
|
-
backend: Backend,
|
|
15
16
|
inboxIds: string[],
|
|
17
|
+
env?: XmtpEnv,
|
|
18
|
+
gatewayHost?: string,
|
|
16
19
|
) => {
|
|
17
20
|
await init();
|
|
18
|
-
|
|
21
|
+
const host = ApiUrls[env ?? "dev"];
|
|
22
|
+
return wasmInboxStateFromInboxIds(host, gatewayHost ?? null, inboxIds);
|
|
19
23
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import init, {
|
|
2
2
|
applySignatureRequest,
|
|
3
3
|
revokeInstallationsSignatureRequest,
|
|
4
|
-
type Backend,
|
|
5
4
|
type Identifier,
|
|
6
5
|
type SignatureRequestHandle,
|
|
7
6
|
} from "@xmtp/wasm-bindings";
|
|
7
|
+
import { ApiUrls } from "@/constants";
|
|
8
|
+
import type { XmtpEnv } from "@/types/options";
|
|
8
9
|
import type { Signer } from "@/utils/signer";
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -16,24 +17,28 @@ import type { Signer } from "@/utils/signer";
|
|
|
16
17
|
*
|
|
17
18
|
* It is highly recommended to use the `revokeInstallations` function instead.
|
|
18
19
|
*
|
|
19
|
-
* @param backend - The Backend instance for API communication
|
|
20
20
|
* @param identifier - The identifier to revoke installations for
|
|
21
21
|
* @param inboxId - The inbox ID to revoke installations for
|
|
22
22
|
* @param installationIds - The installation IDs to revoke
|
|
23
|
+
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
24
|
+
* @param gatewayHost - Optional gateway host override
|
|
23
25
|
* @returns The signature text and signature request ID
|
|
24
26
|
*/
|
|
25
27
|
export const revokeInstallationsSignatureText = async (
|
|
26
|
-
backend: Backend,
|
|
27
28
|
identifier: Identifier,
|
|
28
29
|
inboxId: string,
|
|
29
30
|
installationIds: Uint8Array[],
|
|
31
|
+
env?: XmtpEnv,
|
|
32
|
+
gatewayHost?: string,
|
|
30
33
|
): Promise<{
|
|
31
34
|
signatureText: string;
|
|
32
35
|
signatureRequest: SignatureRequestHandle;
|
|
33
36
|
}> => {
|
|
34
37
|
await init();
|
|
38
|
+
const host = ApiUrls[env ?? "dev"];
|
|
35
39
|
const signatureRequest = revokeInstallationsSignatureRequest(
|
|
36
|
-
|
|
40
|
+
host,
|
|
41
|
+
gatewayHost ?? null,
|
|
37
42
|
identifier,
|
|
38
43
|
inboxId,
|
|
39
44
|
installationIds,
|
|
@@ -45,28 +50,32 @@ export const revokeInstallationsSignatureText = async (
|
|
|
45
50
|
/**
|
|
46
51
|
* Revokes installations for a given inbox ID
|
|
47
52
|
*
|
|
48
|
-
* @param backend - The Backend instance for API communication
|
|
49
53
|
* @param signer - The signer to use
|
|
50
54
|
* @param inboxId - The inbox ID to revoke installations for
|
|
51
55
|
* @param installationIds - The installation IDs to revoke
|
|
56
|
+
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
57
|
+
* @param gatewayHost - Optional gateway host override
|
|
52
58
|
* @returns Promise that resolves when the revoke installations operation is complete
|
|
53
59
|
*/
|
|
54
60
|
export const revokeInstallations = async (
|
|
55
|
-
backend: Backend,
|
|
56
61
|
signer: Signer,
|
|
57
62
|
inboxId: string,
|
|
58
63
|
installationIds: Uint8Array[],
|
|
64
|
+
env?: XmtpEnv,
|
|
65
|
+
gatewayHost?: string,
|
|
59
66
|
): Promise<void> => {
|
|
60
67
|
await init();
|
|
61
68
|
const identifier = await signer.getIdentifier();
|
|
62
69
|
const { signatureText, signatureRequest } =
|
|
63
70
|
await revokeInstallationsSignatureText(
|
|
64
|
-
backend,
|
|
65
71
|
identifier,
|
|
66
72
|
inboxId,
|
|
67
73
|
installationIds,
|
|
74
|
+
env,
|
|
75
|
+
gatewayHost,
|
|
68
76
|
);
|
|
69
77
|
const signature = await signer.signMessage(signatureText);
|
|
78
|
+
const host = ApiUrls[env ?? "dev"];
|
|
70
79
|
|
|
71
80
|
switch (signer.type) {
|
|
72
81
|
case "EOA":
|
|
@@ -82,5 +91,5 @@ export const revokeInstallations = async (
|
|
|
82
91
|
break;
|
|
83
92
|
}
|
|
84
93
|
|
|
85
|
-
await applySignatureRequest(
|
|
94
|
+
await applySignatureRequest(host, gatewayHost ?? null, signatureRequest);
|
|
86
95
|
};
|
package/src/workers/client.ts
CHANGED
|
@@ -91,7 +91,6 @@ self.onmessage = async (
|
|
|
91
91
|
action,
|
|
92
92
|
result: {
|
|
93
93
|
appVersion: maybeClient.appVersion,
|
|
94
|
-
env: maybeClient.env,
|
|
95
94
|
inboxId: maybeClient.inboxId,
|
|
96
95
|
installationId: maybeClient.installationId,
|
|
97
96
|
installationIdBytes: maybeClient.installationIdBytes,
|
|
@@ -339,7 +338,7 @@ self.onmessage = async (
|
|
|
339
338
|
break;
|
|
340
339
|
}
|
|
341
340
|
case "client.sendSyncRequest": {
|
|
342
|
-
await client.sendSyncRequest(
|
|
341
|
+
await client.sendSyncRequest();
|
|
343
342
|
postMessage({ id, action, result: undefined });
|
|
344
343
|
break;
|
|
345
344
|
}
|
|
@@ -778,6 +777,12 @@ self.onmessage = async (
|
|
|
778
777
|
postMessage({ id, action, result: undefined });
|
|
779
778
|
break;
|
|
780
779
|
}
|
|
780
|
+
case "conversation.processStreamedMessage": {
|
|
781
|
+
const group = getGroup(data.id);
|
|
782
|
+
const result = await group.processStreamedMessage(data.envelopeBytes);
|
|
783
|
+
postMessage({ id, action, result });
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
781
786
|
case "conversation.messages": {
|
|
782
787
|
const group = getGroup(data.id);
|
|
783
788
|
const messages = await group.messages(data.options);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import init, {
|
|
2
|
-
BackendBuilder,
|
|
3
|
-
XmtpEnv as BindingsEnv,
|
|
4
|
-
type Backend,
|
|
5
|
-
} from "@xmtp/wasm-bindings";
|
|
6
|
-
import type { NetworkOptions, XmtpEnv } from "@/types/options";
|
|
7
|
-
|
|
8
|
-
const envMap: Record<XmtpEnv, BindingsEnv> = {
|
|
9
|
-
local: BindingsEnv.Local,
|
|
10
|
-
dev: BindingsEnv.Dev,
|
|
11
|
-
production: BindingsEnv.Production,
|
|
12
|
-
"testnet-staging": BindingsEnv.TestnetStaging,
|
|
13
|
-
"testnet-dev": BindingsEnv.TestnetDev,
|
|
14
|
-
testnet: BindingsEnv.Testnet,
|
|
15
|
-
mainnet: BindingsEnv.Mainnet,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const reverseEnvMap: Record<BindingsEnv, XmtpEnv> = {
|
|
19
|
-
[BindingsEnv.Local]: "local",
|
|
20
|
-
[BindingsEnv.Dev]: "dev",
|
|
21
|
-
[BindingsEnv.Production]: "production",
|
|
22
|
-
[BindingsEnv.TestnetStaging]: "testnet-staging",
|
|
23
|
-
[BindingsEnv.TestnetDev]: "testnet-dev",
|
|
24
|
-
[BindingsEnv.Testnet]: "testnet",
|
|
25
|
-
[BindingsEnv.Mainnet]: "mainnet",
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const envToString = (env: BindingsEnv): XmtpEnv => {
|
|
29
|
-
return reverseEnvMap[env];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const createBackend = async (
|
|
33
|
-
options?: NetworkOptions,
|
|
34
|
-
): Promise<Backend> => {
|
|
35
|
-
await init();
|
|
36
|
-
const env = options?.env ?? "dev";
|
|
37
|
-
let builder = new BackendBuilder(envMap[env]);
|
|
38
|
-
// WASM builder methods consume `self` and return a new instance,
|
|
39
|
-
// so we must reassign from the return value.
|
|
40
|
-
if (options?.apiUrl) builder = builder.setApiUrl(options.apiUrl);
|
|
41
|
-
if (options?.gatewayHost)
|
|
42
|
-
builder = builder.setGatewayHost(options.gatewayHost);
|
|
43
|
-
if (options?.appVersion) builder = builder.setAppVersion(options.appVersion);
|
|
44
|
-
return builder.build();
|
|
45
|
-
};
|