@xmtp/browser-sdk 0.0.1 → 0.0.3

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.
@@ -1,11 +1,12 @@
1
1
  import type {
2
- WasmConsentState,
3
- WasmEncodedContent,
4
- WasmGroup,
5
- WasmGroupMember,
2
+ ConsentState,
3
+ Conversation,
4
+ EncodedContent,
5
+ GroupMember,
6
6
  } from "@xmtp/wasm-bindings";
7
7
  import {
8
8
  fromSafeListMessagesOptions,
9
+ toSafeGroupMember,
9
10
  type SafeListMessagesOptions,
10
11
  } from "@/utils/conversions";
11
12
  import type { WorkerClient } from "@/WorkerClient";
@@ -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: WasmGroup;
18
+ #group: Conversation;
18
19
 
19
- constructor(client: WorkerClient, group: WasmGroup) {
20
+ constructor(client: WorkerClient, group: Conversation) {
20
21
  this.#client = client;
21
22
  this.#group = group;
22
23
  }
@@ -26,83 +27,84 @@ export class WorkerConversation {
26
27
  }
27
28
 
28
29
  get name() {
29
- return this.#group.group_name();
30
+ return this.#group.groupName();
30
31
  }
31
32
 
32
33
  async updateName(name: string) {
33
- return this.#group.update_group_name(name);
34
+ return this.#group.updateGroupName(name);
34
35
  }
35
36
 
36
37
  get imageUrl() {
37
- return this.#group.group_image_url_square();
38
+ return this.#group.groupImageUrlSquare();
38
39
  }
39
40
 
40
41
  async updateImageUrl(imageUrl: string) {
41
- return this.#group.update_group_image_url_square(imageUrl);
42
+ return this.#group.updateGroupImageUrlSquare(imageUrl);
42
43
  }
43
44
 
44
45
  get description() {
45
- return this.#group.group_description();
46
+ return this.#group.groupDescription();
46
47
  }
47
48
 
48
49
  async updateDescription(description: string) {
49
- return this.#group.update_group_description(description);
50
+ return this.#group.updateGroupDescription(description);
50
51
  }
51
52
 
52
53
  get pinnedFrameUrl() {
53
- return this.#group.group_pinned_frame_url();
54
+ return this.#group.groupPinnedFrameUrl();
54
55
  }
55
56
 
56
57
  async updatePinnedFrameUrl(pinnedFrameUrl: string) {
57
- return this.#group.update_group_pinned_frame_url(pinnedFrameUrl);
58
+ return this.#group.updateGroupPinnedFrameUrl(pinnedFrameUrl);
58
59
  }
59
60
 
60
61
  get isActive() {
61
- return this.#group.is_active();
62
+ return this.#group.isActive();
62
63
  }
63
64
 
64
65
  get addedByInboxId() {
65
- return this.#group.added_by_inbox_id();
66
+ return this.#group.addedByInboxId();
66
67
  }
67
68
 
68
69
  get createdAtNs() {
69
- return this.#group.created_at_ns();
70
+ return this.#group.createdAtNs();
70
71
  }
71
72
 
72
73
  get metadata() {
73
- const metadata = this.#group.group_metadata();
74
+ const metadata = this.#group.groupMetadata();
74
75
  return {
75
- creatorInboxId: metadata.creator_inbox_id(),
76
- conversationType: metadata.conversation_type(),
76
+ creatorInboxId: metadata.creatorInboxId(),
77
+ conversationType: metadata.conversationType(),
77
78
  };
78
79
  }
79
80
 
80
81
  async members() {
81
- return this.#group.list_members() as Promise<WasmGroupMember[]>;
82
+ const members = (await this.#group.listMembers()) as GroupMember[];
83
+ return members.map((member) => toSafeGroupMember(member));
82
84
  }
83
85
 
84
86
  get admins() {
85
- return this.#group.admin_list();
87
+ return this.#group.adminList();
86
88
  }
87
89
 
88
90
  get superAdmins() {
89
- return this.#group.super_admin_list();
91
+ return this.#group.superAdminList();
90
92
  }
91
93
 
92
94
  get permissions() {
93
- const permissions = this.#group.group_permissions();
95
+ const permissions = this.#group.groupPermissions();
94
96
  return {
95
- policyType: permissions.policy_type(),
96
- policySet: permissions.policy_set(),
97
+ policyType: permissions.policyType(),
98
+ policySet: permissions.policySet(),
97
99
  };
98
100
  }
99
101
 
100
102
  isAdmin(inboxId: string) {
101
- return this.#group.is_admin(inboxId);
103
+ return this.#group.isAdmin(inboxId);
102
104
  }
103
105
 
104
106
  isSuperAdmin(inboxId: string) {
105
- return this.#group.is_super_admin(inboxId);
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.add_members(accountAddresses);
115
+ return this.#group.addMembers(accountAddresses);
114
116
  }
115
117
 
116
118
  async addMembersByInboxId(inboxIds: string[]) {
117
- return this.#group.add_members_by_inbox_id(inboxIds);
119
+ return this.#group.addMembersByInboxId(inboxIds);
118
120
  }
119
121
 
120
122
  async removeMembers(accountAddresses: string[]) {
121
- return this.#group.remove_members(accountAddresses);
123
+ return this.#group.removeMembers(accountAddresses);
122
124
  }
123
125
 
124
126
  async removeMembersByInboxId(inboxIds: string[]) {
125
- return this.#group.remove_members_by_inbox_id(inboxIds);
127
+ return this.#group.removeMembersByInboxId(inboxIds);
126
128
  }
127
129
 
128
130
  async addAdmin(inboxId: string) {
129
- return this.#group.add_admin(inboxId);
131
+ return this.#group.addAdmin(inboxId);
130
132
  }
131
133
 
132
134
  async removeAdmin(inboxId: string) {
133
- return this.#group.remove_admin(inboxId);
135
+ return this.#group.removeAdmin(inboxId);
134
136
  }
135
137
 
136
138
  async addSuperAdmin(inboxId: string) {
137
- return this.#group.add_super_admin(inboxId);
139
+ return this.#group.addSuperAdmin(inboxId);
138
140
  }
139
141
 
140
142
  async removeSuperAdmin(inboxId: string) {
141
- return this.#group.remove_super_admin(inboxId);
143
+ return this.#group.removeSuperAdmin(inboxId);
142
144
  }
143
145
 
144
146
  async publishMessages() {
145
- return this.#group.publish_messages();
147
+ return this.#group.publishMessages();
146
148
  }
147
149
 
148
- sendOptimistic(encodedContent: WasmEncodedContent) {
149
- return this.#group.send_optimistic(encodedContent);
150
+ sendOptimistic(encodedContent: EncodedContent) {
151
+ return this.#group.sendOptimistic(encodedContent);
150
152
  }
151
153
 
152
- async send(encodedContent: WasmEncodedContent) {
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.find_messages(
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.consent_state();
165
+ return this.#group.consentState();
164
166
  }
165
167
 
166
- updateConsentState(state: WasmConsentState) {
167
- this.#group.update_consent_state(state);
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 { WasmConversations, WasmGroup } from "@xmtp/wasm-bindings";
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: WasmConversations;
15
+ #conversations: Conversations;
16
16
 
17
- constructor(client: WorkerClient, conversations: WasmConversations) {
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.find_group_by_id(id);
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.find_message_by_id(id);
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 WasmGroup[];
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.create_group(
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
  }
package/src/index.ts CHANGED
@@ -1,9 +1,36 @@
1
1
  export { Client } from "./Client";
2
2
  export { Conversations } from "./Conversations";
3
3
  export { Conversation } from "./Conversation";
4
- export * from "./DecodedMessage";
4
+ export type { MessageDeliveryStatus, MessageKind } from "./DecodedMessage";
5
+ export { DecodedMessage } from "./DecodedMessage";
5
6
  export { Utils } from "./Utils";
6
7
  export { ApiUrls } from "./constants";
7
8
  export type * from "./types";
8
9
  export * from "./utils/conversions";
9
- export type * from "@xmtp/wasm-bindings";
10
+ export {
11
+ ConsentEntityType,
12
+ ConsentState,
13
+ ConversationType,
14
+ CreateGroupOptions,
15
+ DeliveryStatus,
16
+ GroupMembershipState,
17
+ EncodedContent,
18
+ GroupMember,
19
+ GroupMetadata,
20
+ GroupPermissions,
21
+ GroupMessageKind,
22
+ GroupPermissionsOptions,
23
+ InboxState,
24
+ Installation,
25
+ ListConversationsOptions,
26
+ ListMessagesOptions,
27
+ Message,
28
+ PermissionLevel,
29
+ PermissionPolicy,
30
+ PermissionPolicySet,
31
+ PermissionUpdateType,
32
+ SignatureRequestType,
33
+ SortDirection,
34
+ Consent,
35
+ ContentTypeId,
36
+ } from "@xmtp/wasm-bindings";
@@ -1,7 +1,7 @@
1
1
  import type {
2
- WasmConsentEntityType,
3
- WasmConsentState,
4
- WasmSignatureRequestType,
2
+ ConsentEntityType,
3
+ ConsentState,
4
+ SignatureRequestType,
5
5
  } from "@xmtp/wasm-bindings";
6
6
  import type {
7
7
  ClientOptions,
@@ -38,6 +38,7 @@ export type ClientEvents =
38
38
  };
39
39
  data: {
40
40
  address: string;
41
+ encryptionKey: Uint8Array;
41
42
  options?: ClientOptions;
42
43
  };
43
44
  }
@@ -74,12 +75,23 @@ export type ClientEvents =
74
75
  id: string;
75
76
  result: undefined;
76
77
  data: {
77
- type: WasmSignatureRequestType;
78
+ type: SignatureRequestType;
78
79
  bytes: Uint8Array;
79
80
  };
80
81
  }
81
82
  | {
82
- action: "applySignaturesRequests";
83
+ action: "addScwSignature";
84
+ id: string;
85
+ result: undefined;
86
+ data: {
87
+ type: SignatureRequestType;
88
+ bytes: Uint8Array;
89
+ chainId: bigint;
90
+ blockNumber?: bigint;
91
+ };
92
+ }
93
+ | {
94
+ action: "applySignatures";
83
95
  id: string;
84
96
  result: undefined;
85
97
  data: undefined;
@@ -131,9 +143,9 @@ export type ClientEvents =
131
143
  | {
132
144
  action: "getConsentState";
133
145
  id: string;
134
- result: WasmConsentState;
146
+ result: ConsentState;
135
147
  data: {
136
- entityType: WasmConsentEntityType;
148
+ entityType: ConsentEntityType;
137
149
  entity: string;
138
150
  };
139
151
  }
@@ -164,6 +176,14 @@ export type ClientEvents =
164
176
  id: string;
165
177
  };
166
178
  }
179
+ | {
180
+ action: "getDmByInboxId";
181
+ id: string;
182
+ result: SafeConversation | undefined;
183
+ data: {
184
+ inboxId: string;
185
+ };
186
+ }
167
187
  | {
168
188
  action: "getConversations";
169
189
  id: string;
@@ -172,6 +192,22 @@ export type ClientEvents =
172
192
  options?: SafeListConversationsOptions;
173
193
  };
174
194
  }
195
+ | {
196
+ action: "getGroups";
197
+ id: string;
198
+ result: SafeConversation[];
199
+ data: {
200
+ options?: Omit<SafeListConversationsOptions, "conversation_type">;
201
+ };
202
+ }
203
+ | {
204
+ action: "getDms";
205
+ id: string;
206
+ result: SafeConversation[];
207
+ data: {
208
+ options?: Omit<SafeListConversationsOptions, "conversation_type">;
209
+ };
210
+ }
175
211
  | {
176
212
  action: "newGroup";
177
213
  id: string;
@@ -181,6 +217,14 @@ export type ClientEvents =
181
217
  options?: SafeCreateGroupOptions;
182
218
  };
183
219
  }
220
+ | {
221
+ action: "newDm";
222
+ id: string;
223
+ result: SafeConversation;
224
+ data: {
225
+ accountAddress: string;
226
+ };
227
+ }
184
228
  | {
185
229
  action: "syncConversations";
186
230
  id: string;
@@ -386,7 +430,7 @@ export type ClientEvents =
386
430
  | {
387
431
  action: "getGroupConsentState";
388
432
  id: string;
389
- result: WasmConsentState;
433
+ result: ConsentState;
390
434
  data: {
391
435
  id: string;
392
436
  };
@@ -397,7 +441,15 @@ export type ClientEvents =
397
441
  result: undefined;
398
442
  data: {
399
443
  id: string;
400
- state: WasmConsentState;
444
+ state: ConsentState;
445
+ };
446
+ }
447
+ | {
448
+ action: "getDmPeerInboxId";
449
+ id: string;
450
+ result: string;
451
+ data: {
452
+ id: string;
401
453
  };
402
454
  };
403
455
 
@@ -18,16 +18,6 @@ export type NetworkOptions = {
18
18
  apiUrl?: string;
19
19
  };
20
20
 
21
- /**
22
- * Encryption options
23
- */
24
- export type EncryptionOptions = {
25
- /**
26
- * Encryption key to use for the local DB
27
- */
28
- encryptionKey?: Uint8Array;
29
- };
30
-
31
21
  /**
32
22
  * Storage options
33
23
  */
@@ -47,13 +37,20 @@ export type ContentOptions = {
47
37
 
48
38
  export type OtherOptions = {
49
39
  /**
50
- * Enable logging of events between the client and worker
40
+ * Enable structured JSON logging
41
+ */
42
+ structuredLogging?: boolean;
43
+ /**
44
+ * Enable performance metrics
45
+ */
46
+ performanceLogging?: boolean;
47
+ /**
48
+ * Logging level
51
49
  */
52
- enableLogging?: boolean;
50
+ loggingLevel?: "off" | "error" | "warn" | "info" | "debug" | "trace";
53
51
  };
54
52
 
55
53
  export type ClientOptions = NetworkOptions &
56
- EncryptionOptions &
57
54
  StorageOptions &
58
55
  ContentOptions &
59
56
  OtherOptions;