@xmtp/browser-sdk 0.0.1 → 0.0.2
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 +144 -87
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/package.json +2 -2
- package/src/Client.ts +16 -10
- package/src/Conversation.ts +8 -2
- package/src/Conversations.ts +30 -0
- package/src/DecodedMessage.ts +6 -6
- package/src/WorkerClient.ts +8 -8
- package/src/WorkerConversation.ts +48 -42
- package/src/WorkerConversations.ts +39 -7
- package/src/types/clientEvents.ts +49 -9
- package/src/utils/conversions.ts +124 -93
- package/src/utils/createClient.ts +6 -1
- package/src/workers/client.ts +75 -5
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
WasmGroupMember,
|
|
2
|
+
ConsentState,
|
|
3
|
+
Conversation,
|
|
4
|
+
EncodedContent,
|
|
6
5
|
} from "@xmtp/wasm-bindings";
|
|
7
6
|
import {
|
|
8
7
|
fromSafeListMessagesOptions,
|
|
8
|
+
toSafeGroupMember,
|
|
9
9
|
type SafeListMessagesOptions,
|
|
10
|
+
type WasmGroupMember,
|
|
10
11
|
} from "@/utils/conversions";
|
|
11
12
|
import type { WorkerClient } from "@/WorkerClient";
|
|
12
13
|
|
|
@@ -14,9 +15,9 @@ export class WorkerConversation {
|
|
|
14
15
|
// eslint-disable-next-line no-unused-private-class-members
|
|
15
16
|
#client: WorkerClient;
|
|
16
17
|
|
|
17
|
-
#group:
|
|
18
|
+
#group: Conversation;
|
|
18
19
|
|
|
19
|
-
constructor(client: WorkerClient, group:
|
|
20
|
+
constructor(client: WorkerClient, group: Conversation) {
|
|
20
21
|
this.#client = client;
|
|
21
22
|
this.#group = group;
|
|
22
23
|
}
|
|
@@ -26,51 +27,51 @@ export class WorkerConversation {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
get name() {
|
|
29
|
-
return this.#group.
|
|
30
|
+
return this.#group.groupName();
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
async updateName(name: string) {
|
|
33
|
-
return this.#group.
|
|
34
|
+
return this.#group.updateGroupName(name);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
get imageUrl() {
|
|
37
|
-
return this.#group.
|
|
38
|
+
return this.#group.groupImageUrlSquare();
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
async updateImageUrl(imageUrl: string) {
|
|
41
|
-
return this.#group.
|
|
42
|
+
return this.#group.updateGroupImageUrlSquare(imageUrl);
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
get description() {
|
|
45
|
-
return this.#group.
|
|
46
|
+
return this.#group.groupDescription();
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
async updateDescription(description: string) {
|
|
49
|
-
return this.#group.
|
|
50
|
+
return this.#group.updateGroupDescription(description);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
get pinnedFrameUrl() {
|
|
53
|
-
return this.#group.
|
|
54
|
+
return this.#group.groupPinnedFrameUrl();
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
async updatePinnedFrameUrl(pinnedFrameUrl: string) {
|
|
57
|
-
return this.#group.
|
|
58
|
+
return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
get isActive() {
|
|
61
|
-
return this.#group.
|
|
62
|
+
return this.#group.isActive();
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
get addedByInboxId() {
|
|
65
|
-
return this.#group.
|
|
66
|
+
return this.#group.addedByInboxId();
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
get createdAtNs() {
|
|
69
|
-
return this.#group.
|
|
70
|
+
return this.#group.createdAtNs();
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
get metadata() {
|
|
73
|
-
const metadata = this.#group.
|
|
74
|
+
const metadata = this.#group.groupMetadata();
|
|
74
75
|
return {
|
|
75
76
|
creatorInboxId: metadata.creator_inbox_id(),
|
|
76
77
|
conversationType: metadata.conversation_type(),
|
|
@@ -78,31 +79,32 @@ export class WorkerConversation {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
async members() {
|
|
81
|
-
|
|
82
|
+
const members = (await this.#group.listMembers()) as WasmGroupMember[];
|
|
83
|
+
return members.map((member) => toSafeGroupMember(member));
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
get admins() {
|
|
85
|
-
return this.#group.
|
|
87
|
+
return this.#group.adminList();
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
get superAdmins() {
|
|
89
|
-
return this.#group.
|
|
91
|
+
return this.#group.superAdminList();
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
get permissions() {
|
|
93
|
-
const permissions = this.#group.
|
|
95
|
+
const permissions = this.#group.groupPermissions();
|
|
94
96
|
return {
|
|
95
|
-
policyType: permissions.
|
|
96
|
-
policySet: permissions.
|
|
97
|
+
policyType: permissions.policyType(),
|
|
98
|
+
policySet: permissions.policySet(),
|
|
97
99
|
};
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
isAdmin(inboxId: string) {
|
|
101
|
-
return this.#group.
|
|
103
|
+
return this.#group.isAdmin(inboxId);
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
isSuperAdmin(inboxId: string) {
|
|
105
|
-
return this.#group.
|
|
107
|
+
return this.#group.isSuperAdmin(inboxId);
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
async sync() {
|
|
@@ -110,60 +112,64 @@ export class WorkerConversation {
|
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
async addMembers(accountAddresses: string[]) {
|
|
113
|
-
return this.#group.
|
|
115
|
+
return this.#group.addMembers(accountAddresses);
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
async addMembersByInboxId(inboxIds: string[]) {
|
|
117
|
-
return this.#group.
|
|
119
|
+
return this.#group.addMembersByInboxId(inboxIds);
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
async removeMembers(accountAddresses: string[]) {
|
|
121
|
-
return this.#group.
|
|
123
|
+
return this.#group.removeMembers(accountAddresses);
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
async removeMembersByInboxId(inboxIds: string[]) {
|
|
125
|
-
return this.#group.
|
|
127
|
+
return this.#group.removeMembersByInboxId(inboxIds);
|
|
126
128
|
}
|
|
127
129
|
|
|
128
130
|
async addAdmin(inboxId: string) {
|
|
129
|
-
return this.#group.
|
|
131
|
+
return this.#group.addAdmin(inboxId);
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
async removeAdmin(inboxId: string) {
|
|
133
|
-
return this.#group.
|
|
135
|
+
return this.#group.removeAdmin(inboxId);
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
async addSuperAdmin(inboxId: string) {
|
|
137
|
-
return this.#group.
|
|
139
|
+
return this.#group.addSuperAdmin(inboxId);
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
async removeSuperAdmin(inboxId: string) {
|
|
141
|
-
return this.#group.
|
|
143
|
+
return this.#group.removeSuperAdmin(inboxId);
|
|
142
144
|
}
|
|
143
145
|
|
|
144
146
|
async publishMessages() {
|
|
145
|
-
return this.#group.
|
|
147
|
+
return this.#group.publishMessages();
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
sendOptimistic(encodedContent:
|
|
149
|
-
return this.#group.
|
|
150
|
+
sendOptimistic(encodedContent: EncodedContent) {
|
|
151
|
+
return this.#group.sendOptimistic(encodedContent);
|
|
150
152
|
}
|
|
151
153
|
|
|
152
|
-
async send(encodedContent:
|
|
154
|
+
async send(encodedContent: EncodedContent) {
|
|
153
155
|
return this.#group.send(encodedContent);
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
messages(options?: SafeListMessagesOptions) {
|
|
157
|
-
return this.#group.
|
|
159
|
+
return this.#group.findMessages(
|
|
158
160
|
options ? fromSafeListMessagesOptions(options) : undefined,
|
|
159
161
|
);
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
get consentState() {
|
|
163
|
-
return this.#group.
|
|
165
|
+
return this.#group.consentState();
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
updateConsentState(state:
|
|
167
|
-
this.#group.
|
|
168
|
+
updateConsentState(state: ConsentState) {
|
|
169
|
+
this.#group.updateConsentState(state);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
dmPeerInboxId() {
|
|
173
|
+
return this.#group.dmPeerInboxId();
|
|
168
174
|
}
|
|
169
175
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Conversation, Conversations } from "@xmtp/wasm-bindings";
|
|
2
2
|
import {
|
|
3
3
|
fromSafeCreateGroupOptions,
|
|
4
4
|
fromSafeListConversationsOptions,
|
|
@@ -12,9 +12,9 @@ import { WorkerConversation } from "@/WorkerConversation";
|
|
|
12
12
|
export class WorkerConversations {
|
|
13
13
|
#client: WorkerClient;
|
|
14
14
|
|
|
15
|
-
#conversations:
|
|
15
|
+
#conversations: Conversations;
|
|
16
16
|
|
|
17
|
-
constructor(client: WorkerClient, conversations:
|
|
17
|
+
constructor(client: WorkerClient, conversations: Conversations) {
|
|
18
18
|
this.#client = client;
|
|
19
19
|
this.#conversations = conversations;
|
|
20
20
|
}
|
|
@@ -25,7 +25,7 @@ export class WorkerConversations {
|
|
|
25
25
|
|
|
26
26
|
getConversationById(id: string) {
|
|
27
27
|
try {
|
|
28
|
-
const group = this.#conversations.
|
|
28
|
+
const group = this.#conversations.findGroupById(id);
|
|
29
29
|
// findGroupById will throw if group is not found
|
|
30
30
|
return new WorkerConversation(this.#client, group);
|
|
31
31
|
} catch {
|
|
@@ -36,25 +36,57 @@ export class WorkerConversations {
|
|
|
36
36
|
getMessageById(id: string) {
|
|
37
37
|
try {
|
|
38
38
|
// findMessageById will throw if message is not found
|
|
39
|
-
const message = this.#conversations.
|
|
39
|
+
const message = this.#conversations.findMessageById(id);
|
|
40
40
|
return toSafeMessage(message);
|
|
41
41
|
} catch {
|
|
42
42
|
return undefined;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
getDmByInboxId(inboxId: string) {
|
|
47
|
+
try {
|
|
48
|
+
const group = this.#conversations.findDmByTargetInboxId(inboxId);
|
|
49
|
+
return new WorkerConversation(this.#client, group);
|
|
50
|
+
} catch {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
async list(options?: SafeListConversationsOptions) {
|
|
47
56
|
const groups = (await this.#conversations.list(
|
|
48
57
|
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
49
|
-
)) as
|
|
58
|
+
)) as Conversation[];
|
|
59
|
+
return groups.map((group) => new WorkerConversation(this.#client, group));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async listGroups(
|
|
63
|
+
options?: Omit<SafeListConversationsOptions, "conversation_type">,
|
|
64
|
+
) {
|
|
65
|
+
const groups = (await this.#conversations.listGroups(
|
|
66
|
+
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
67
|
+
)) as Conversation[];
|
|
68
|
+
return groups.map((group) => new WorkerConversation(this.#client, group));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async listDms(
|
|
72
|
+
options?: Omit<SafeListConversationsOptions, "conversation_type">,
|
|
73
|
+
) {
|
|
74
|
+
const groups = (await this.#conversations.listDms(
|
|
75
|
+
options ? fromSafeListConversationsOptions(options) : undefined,
|
|
76
|
+
)) as Conversation[];
|
|
50
77
|
return groups.map((group) => new WorkerConversation(this.#client, group));
|
|
51
78
|
}
|
|
52
79
|
|
|
53
80
|
async newGroup(accountAddresses: string[], options?: SafeCreateGroupOptions) {
|
|
54
|
-
const group = await this.#conversations.
|
|
81
|
+
const group = await this.#conversations.createGroup(
|
|
55
82
|
accountAddresses,
|
|
56
83
|
options ? fromSafeCreateGroupOptions(options) : undefined,
|
|
57
84
|
);
|
|
58
85
|
return new WorkerConversation(this.#client, group);
|
|
59
86
|
}
|
|
87
|
+
|
|
88
|
+
async newDm(accountAddress: string) {
|
|
89
|
+
const group = await this.#conversations.createDm(accountAddress);
|
|
90
|
+
return new WorkerConversation(this.#client, group);
|
|
91
|
+
}
|
|
60
92
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ConsentEntityType,
|
|
3
|
+
ConsentState,
|
|
4
|
+
SignatureRequestType,
|
|
5
5
|
} from "@xmtp/wasm-bindings";
|
|
6
6
|
import type {
|
|
7
7
|
ClientOptions,
|
|
@@ -74,12 +74,12 @@ export type ClientEvents =
|
|
|
74
74
|
id: string;
|
|
75
75
|
result: undefined;
|
|
76
76
|
data: {
|
|
77
|
-
type:
|
|
77
|
+
type: SignatureRequestType;
|
|
78
78
|
bytes: Uint8Array;
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
| {
|
|
82
|
-
action: "
|
|
82
|
+
action: "applySignatures";
|
|
83
83
|
id: string;
|
|
84
84
|
result: undefined;
|
|
85
85
|
data: undefined;
|
|
@@ -131,9 +131,9 @@ export type ClientEvents =
|
|
|
131
131
|
| {
|
|
132
132
|
action: "getConsentState";
|
|
133
133
|
id: string;
|
|
134
|
-
result:
|
|
134
|
+
result: ConsentState;
|
|
135
135
|
data: {
|
|
136
|
-
entityType:
|
|
136
|
+
entityType: ConsentEntityType;
|
|
137
137
|
entity: string;
|
|
138
138
|
};
|
|
139
139
|
}
|
|
@@ -164,6 +164,14 @@ export type ClientEvents =
|
|
|
164
164
|
id: string;
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
|
+
| {
|
|
168
|
+
action: "getDmByInboxId";
|
|
169
|
+
id: string;
|
|
170
|
+
result: SafeConversation | undefined;
|
|
171
|
+
data: {
|
|
172
|
+
inboxId: string;
|
|
173
|
+
};
|
|
174
|
+
}
|
|
167
175
|
| {
|
|
168
176
|
action: "getConversations";
|
|
169
177
|
id: string;
|
|
@@ -172,6 +180,22 @@ export type ClientEvents =
|
|
|
172
180
|
options?: SafeListConversationsOptions;
|
|
173
181
|
};
|
|
174
182
|
}
|
|
183
|
+
| {
|
|
184
|
+
action: "getGroups";
|
|
185
|
+
id: string;
|
|
186
|
+
result: SafeConversation[];
|
|
187
|
+
data: {
|
|
188
|
+
options?: Omit<SafeListConversationsOptions, "conversation_type">;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
| {
|
|
192
|
+
action: "getDms";
|
|
193
|
+
id: string;
|
|
194
|
+
result: SafeConversation[];
|
|
195
|
+
data: {
|
|
196
|
+
options?: Omit<SafeListConversationsOptions, "conversation_type">;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
175
199
|
| {
|
|
176
200
|
action: "newGroup";
|
|
177
201
|
id: string;
|
|
@@ -181,6 +205,14 @@ export type ClientEvents =
|
|
|
181
205
|
options?: SafeCreateGroupOptions;
|
|
182
206
|
};
|
|
183
207
|
}
|
|
208
|
+
| {
|
|
209
|
+
action: "newDm";
|
|
210
|
+
id: string;
|
|
211
|
+
result: SafeConversation;
|
|
212
|
+
data: {
|
|
213
|
+
accountAddress: string;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
184
216
|
| {
|
|
185
217
|
action: "syncConversations";
|
|
186
218
|
id: string;
|
|
@@ -386,7 +418,7 @@ export type ClientEvents =
|
|
|
386
418
|
| {
|
|
387
419
|
action: "getGroupConsentState";
|
|
388
420
|
id: string;
|
|
389
|
-
result:
|
|
421
|
+
result: ConsentState;
|
|
390
422
|
data: {
|
|
391
423
|
id: string;
|
|
392
424
|
};
|
|
@@ -397,7 +429,15 @@ export type ClientEvents =
|
|
|
397
429
|
result: undefined;
|
|
398
430
|
data: {
|
|
399
431
|
id: string;
|
|
400
|
-
state:
|
|
432
|
+
state: ConsentState;
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
| {
|
|
436
|
+
action: "getDmPeerInboxId";
|
|
437
|
+
id: string;
|
|
438
|
+
result: string;
|
|
439
|
+
data: {
|
|
440
|
+
id: string;
|
|
401
441
|
};
|
|
402
442
|
};
|
|
403
443
|
|