@vex-chat/libvex 0.27.1 → 1.0.0-rc.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/Client.d.ts +326 -70
- package/dist/Client.js +1445 -1471
- package/dist/Client.js.map +1 -1
- package/dist/IStorage.d.ts +58 -93
- package/dist/IStorage.js +1 -2
- package/dist/IStorage.js.map +1 -1
- package/dist/Storage.d.ts +11 -12
- package/dist/Storage.js +382 -447
- package/dist/Storage.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/capitalize.js +1 -4
- package/dist/utils/capitalize.js.map +1 -1
- package/dist/utils/constants.js +2 -5
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/createLogger.js +8 -15
- package/dist/utils/createLogger.js.map +1 -1
- package/dist/utils/formatBytes.js +1 -4
- package/dist/utils/formatBytes.js.map +1 -1
- package/dist/utils/sqlSessionToCrypto.d.ts +2 -2
- package/dist/utils/sqlSessionToCrypto.js +5 -9
- package/dist/utils/sqlSessionToCrypto.js.map +1 -1
- package/dist/utils/uint8uuid.d.ts +2 -2
- package/dist/utils/uint8uuid.js +5 -10
- package/dist/utils/uint8uuid.js.map +1 -1
- package/package.json +42 -43
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/RELEASING.md +0 -95
- package/dist/__tests__/Client.d.ts +0 -1
- package/dist/__tests__/Client.js +0 -271
- package/dist/__tests__/Client.js.map +0 -1
- package/jest.config.js +0 -18
- package/mise.toml +0 -3
package/dist/Client.d.ts
CHANGED
|
@@ -1,191 +1,344 @@
|
|
|
1
|
-
|
|
2
|
-
import { XTypes } from "@vex-chat/types";
|
|
1
|
+
import type { IChannel, IDevice, IEmoji, IFileResponse, IFileSQL, IInvite, IPermission, IServer, ISessionSQL } from "@vex-chat/types";
|
|
3
2
|
import { AxiosError } from "axios";
|
|
4
3
|
import { EventEmitter } from "events";
|
|
5
|
-
import { IStorage } from "./IStorage";
|
|
6
|
-
interface ICensoredUser {
|
|
7
|
-
lastSeen: number;
|
|
8
|
-
userID: string;
|
|
9
|
-
username: string;
|
|
10
|
-
}
|
|
4
|
+
import type { IStorage } from "./IStorage.js";
|
|
11
5
|
/**
|
|
12
6
|
* IMessage is a chat message.
|
|
13
7
|
*/
|
|
14
8
|
export interface IMessage {
|
|
9
|
+
/** Hex-encoded nonce used for message encryption. */
|
|
15
10
|
nonce: string;
|
|
11
|
+
/** Globally unique message identifier. */
|
|
16
12
|
mailID: string;
|
|
13
|
+
/** Sender device ID. */
|
|
17
14
|
sender: string;
|
|
15
|
+
/** Recipient device ID. */
|
|
18
16
|
recipient: string;
|
|
17
|
+
/** Plaintext message content (or empty string when decryption failed). */
|
|
19
18
|
message: string;
|
|
19
|
+
/** Whether this message was received or sent by the current client. */
|
|
20
20
|
direction: "incoming" | "outgoing";
|
|
21
|
+
/** Time the message was created/received. */
|
|
21
22
|
timestamp: Date;
|
|
23
|
+
/** Whether payload decryption succeeded. */
|
|
22
24
|
decrypted: boolean;
|
|
25
|
+
/** Channel ID for group messages; `null` for direct messages. */
|
|
23
26
|
group: string | null;
|
|
27
|
+
/** `true` when this message was forwarded to another owned device. */
|
|
24
28
|
forward: boolean;
|
|
29
|
+
/** User ID of the original author. */
|
|
25
30
|
authorID: string;
|
|
31
|
+
/** User ID of the intended reader. */
|
|
26
32
|
readerID: string;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
35
|
* IPermission is a permission to a resource.
|
|
36
|
+
*
|
|
37
|
+
* Common fields:
|
|
38
|
+
* - `permissionID`: unique permission row ID
|
|
39
|
+
* - `userID`: user receiving this grant
|
|
40
|
+
* - `resourceID`: target server/channel/etc.
|
|
41
|
+
* - `resourceType`: type string for the resource
|
|
42
|
+
* - `powerLevel`: authorization level
|
|
30
43
|
*/
|
|
31
|
-
export
|
|
32
|
-
}
|
|
44
|
+
export type { IPermission } from "@vex-chat/types";
|
|
33
45
|
/**
|
|
34
46
|
* IKeys are a pair of ed25519 public and private keys,
|
|
35
47
|
* encoded as hex strings.
|
|
36
48
|
*/
|
|
37
49
|
export interface IKeys {
|
|
50
|
+
/** Public Ed25519 key as hex. */
|
|
38
51
|
public: string;
|
|
52
|
+
/** Secret Ed25519 key as hex. Store securely. */
|
|
39
53
|
private: string;
|
|
40
54
|
}
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Device record associated with a user account.
|
|
57
|
+
*
|
|
58
|
+
* Common fields:
|
|
59
|
+
* - `deviceID`: unique device identifier
|
|
60
|
+
* - `owner`: owning user ID
|
|
61
|
+
* - `signKey`: signing public key
|
|
62
|
+
* - `name`: user-facing device name
|
|
63
|
+
* - `lastLogin`: last login timestamp string
|
|
64
|
+
* - `deleted`: soft-delete flag
|
|
65
|
+
*/
|
|
66
|
+
export type { IDevice } from "@vex-chat/types";
|
|
43
67
|
/**
|
|
44
68
|
* IUser is a single user on the vex platform.
|
|
69
|
+
*
|
|
70
|
+
* This is intentionally a censored user shape for client use, containing:
|
|
71
|
+
* - `userID`
|
|
72
|
+
* - `username`
|
|
73
|
+
* - `lastSeen`
|
|
45
74
|
*/
|
|
46
|
-
export interface IUser
|
|
75
|
+
export interface IUser {
|
|
76
|
+
/** Last-seen timestamp (unix epoch milliseconds). */
|
|
77
|
+
lastSeen: number;
|
|
78
|
+
/** User identifier. */
|
|
79
|
+
userID: string;
|
|
80
|
+
/** Public username. */
|
|
81
|
+
username: string;
|
|
47
82
|
}
|
|
48
83
|
/**
|
|
49
84
|
* ISession is an end to end encryption session with another peer.
|
|
85
|
+
*
|
|
86
|
+
* Key fields include:
|
|
87
|
+
* - `sessionID`
|
|
88
|
+
* - `userID`
|
|
89
|
+
* - `deviceID`
|
|
90
|
+
* - `mode` (`initiator` or `receiver`)
|
|
91
|
+
* - `publicKey` and `fingerprint`
|
|
92
|
+
* - `lastUsed`
|
|
93
|
+
* - `verified`
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const session: ISession = {
|
|
98
|
+
* sessionID: "f6e4fbd0-7222-4ba8-b799-c227faf5c8de",
|
|
99
|
+
* userID: "f34f5e37-616f-4d3a-a437-e7c27c31cb73",
|
|
100
|
+
* deviceID: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
|
|
101
|
+
* mode: "initiator",
|
|
102
|
+
* SK: "7d9afde6683ecc2d1f55e34e1b95de9d4042dfd4e8cda7fdf3f0f7e02fef8f9a",
|
|
103
|
+
* publicKey: "d58f39dc4bcfe4e8ef022f34e8b6f4f6ddc9c4acee30c0d58f126aa5db3f61b0",
|
|
104
|
+
* fingerprint: "05294b9aa81d0fd0ca12a4b585f531d8ef1f53f8ea3d0200a0df3f9c44a7d8b1",
|
|
105
|
+
* lastUsed: new Date(),
|
|
106
|
+
* verified: false,
|
|
107
|
+
* };
|
|
108
|
+
* ```
|
|
50
109
|
*/
|
|
51
|
-
export interface ISession extends
|
|
110
|
+
export interface ISession extends ISessionSQL {
|
|
52
111
|
}
|
|
53
112
|
/**
|
|
54
113
|
* IChannel is a chat channel on a server.
|
|
114
|
+
*
|
|
115
|
+
* Common fields:
|
|
116
|
+
* - `channelID`
|
|
117
|
+
* - `serverID`
|
|
118
|
+
* - `name`
|
|
55
119
|
*/
|
|
56
|
-
export
|
|
57
|
-
}
|
|
120
|
+
export type { IChannel } from "@vex-chat/types";
|
|
58
121
|
/**
|
|
59
122
|
* IServer is a single chat server.
|
|
123
|
+
*
|
|
124
|
+
* Common fields:
|
|
125
|
+
* - `serverID`
|
|
126
|
+
* - `name`
|
|
127
|
+
* - `icon` (optional URL/data)
|
|
60
128
|
*/
|
|
61
|
-
export
|
|
62
|
-
}
|
|
129
|
+
export type { IServer } from "@vex-chat/types";
|
|
63
130
|
/**
|
|
64
131
|
* Ifile is an uploaded encrypted file.
|
|
132
|
+
*
|
|
133
|
+
* Common fields:
|
|
134
|
+
* - `fileID`: file identifier
|
|
135
|
+
* - `owner`: owner device/user ID
|
|
136
|
+
* - `nonce`: file encryption nonce (hex)
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* const file: IFile = {
|
|
141
|
+
* fileID: "bb1c3fd1-4928-48ab-9d09-3ea0972fbd9d",
|
|
142
|
+
* owner: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
|
|
143
|
+
* nonce: "aa6c8d42f3fdd032a1e9fced4be379582d26ce8f69822d64",
|
|
144
|
+
* };
|
|
145
|
+
* ```
|
|
65
146
|
*/
|
|
66
|
-
export interface IFile extends
|
|
147
|
+
export interface IFile extends IFileSQL {
|
|
67
148
|
}
|
|
68
149
|
/**
|
|
69
150
|
* IFileRes is a server response to a file retrieval request.
|
|
151
|
+
*
|
|
152
|
+
* Structure:
|
|
153
|
+
* - `details`: metadata (`IFile`)
|
|
154
|
+
* - `data`: decrypted binary bytes
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* const response: IFileRes = {
|
|
159
|
+
* details: {
|
|
160
|
+
* fileID: "bb1c3fd1-4928-48ab-9d09-3ea0972fbd9d",
|
|
161
|
+
* owner: "9b0f3f46-06ad-4bc4-8adf-4de10e13cb9c",
|
|
162
|
+
* nonce: "aa6c8d42f3fdd032a1e9fced4be379582d26ce8f69822d64",
|
|
163
|
+
* },
|
|
164
|
+
* data: Buffer.from("hello"),
|
|
165
|
+
* };
|
|
166
|
+
* ```
|
|
70
167
|
*/
|
|
71
|
-
export interface IFileRes extends
|
|
168
|
+
export interface IFileRes extends IFileResponse {
|
|
72
169
|
}
|
|
73
170
|
/**
|
|
74
171
|
* @ignore
|
|
75
172
|
*/
|
|
76
|
-
interface IMe {
|
|
77
|
-
user
|
|
78
|
-
|
|
173
|
+
export interface IMe {
|
|
174
|
+
/** Returns the currently authenticated user profile. */
|
|
175
|
+
user: () => IUser;
|
|
176
|
+
/** Returns metadata for the currently authenticated device. */
|
|
177
|
+
device: () => IDevice;
|
|
178
|
+
/** Uploads and sets a new avatar image for the current user. */
|
|
79
179
|
setAvatar: (avatar: Buffer) => Promise<void>;
|
|
80
180
|
}
|
|
81
181
|
/**
|
|
82
182
|
* @ignore
|
|
83
183
|
*/
|
|
84
|
-
interface IUsers {
|
|
184
|
+
export interface IUsers {
|
|
185
|
+
/**
|
|
186
|
+
* Looks up a user by user ID, username, or signing key.
|
|
187
|
+
*/
|
|
85
188
|
retrieve: (userID: string) => Promise<[IUser | null, AxiosError | null]>;
|
|
189
|
+
/** Returns users with whom the current device has active sessions. */
|
|
86
190
|
familiars: () => Promise<IUser[]>;
|
|
87
191
|
}
|
|
88
192
|
/**
|
|
89
193
|
* @ignore
|
|
90
194
|
*/
|
|
91
|
-
interface IMessages {
|
|
195
|
+
export interface IMessages {
|
|
196
|
+
/** Sends an encrypted direct message to one user. */
|
|
92
197
|
send: (userID: string, message: string) => Promise<void>;
|
|
198
|
+
/** Sends an encrypted message to all members of a channel. */
|
|
93
199
|
group: (channelID: string, message: string) => Promise<void>;
|
|
200
|
+
/** Returns local direct-message history with one user. */
|
|
94
201
|
retrieve: (userID: string) => Promise<IMessage[]>;
|
|
202
|
+
/** Returns local group-message history for one channel. */
|
|
95
203
|
retrieveGroup: (channelID: string) => Promise<IMessage[]>;
|
|
204
|
+
/** Deletes local history for a user/channel, optionally older than a duration. */
|
|
96
205
|
delete: (userOrChannelID: string, duration?: string) => Promise<void>;
|
|
206
|
+
/** Deletes all locally stored message history. */
|
|
97
207
|
purge: () => Promise<void>;
|
|
98
208
|
}
|
|
99
209
|
/**
|
|
100
210
|
* @ignore
|
|
101
211
|
*/
|
|
102
|
-
interface IServers {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
212
|
+
export interface IServers {
|
|
213
|
+
/** Lists servers available to the authenticated user. */
|
|
214
|
+
retrieve: () => Promise<IServer[]>;
|
|
215
|
+
/** Gets one server by ID. */
|
|
216
|
+
retrieveByID: (serverID: string) => Promise<IServer | null>;
|
|
217
|
+
/** Creates a server. */
|
|
218
|
+
create: (name: string) => Promise<IServer>;
|
|
219
|
+
/** Deletes a server. */
|
|
106
220
|
delete: (serverID: string) => Promise<void>;
|
|
221
|
+
/** Leaves a server by removing the user's permission entry. */
|
|
107
222
|
leave: (serverID: string) => Promise<void>;
|
|
108
223
|
}
|
|
109
224
|
/**
|
|
110
225
|
* @ignore
|
|
111
226
|
*/
|
|
112
|
-
interface IModeration {
|
|
227
|
+
export interface IModeration {
|
|
228
|
+
/** Removes a user from a server by revoking their server permission(s). */
|
|
113
229
|
kick: (userID: string, serverID: string) => Promise<void>;
|
|
114
|
-
|
|
230
|
+
/** Returns all permission entries for a server. */
|
|
231
|
+
fetchPermissionList: (serverID: string) => Promise<IPermission[]>;
|
|
115
232
|
}
|
|
116
233
|
/**
|
|
117
234
|
* @ignore
|
|
118
235
|
*/
|
|
119
|
-
interface IPermissions {
|
|
120
|
-
|
|
236
|
+
export interface IPermissions {
|
|
237
|
+
/** Lists permissions granted to the authenticated user. */
|
|
238
|
+
retrieve: () => Promise<IPermission[]>;
|
|
239
|
+
/** Deletes one permission grant. */
|
|
121
240
|
delete: (permissionID: string) => Promise<void>;
|
|
122
241
|
}
|
|
123
242
|
/**
|
|
124
243
|
* @ignore
|
|
125
244
|
*/
|
|
126
|
-
interface IInvites {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
245
|
+
export interface IInvites {
|
|
246
|
+
/** Redeems an invite and returns the created permission grant. */
|
|
247
|
+
redeem: (inviteID: string) => Promise<IPermission>;
|
|
248
|
+
/** Creates an invite for a server and duration. */
|
|
249
|
+
create: (serverID: string, duration: string) => Promise<IInvite>;
|
|
250
|
+
/** Lists active invites for a server. */
|
|
251
|
+
retrieve: (serverID: string) => Promise<IInvite[]>;
|
|
130
252
|
}
|
|
131
253
|
/**
|
|
132
254
|
* @ignore
|
|
133
255
|
*/
|
|
134
|
-
interface IChannels {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
256
|
+
export interface IChannels {
|
|
257
|
+
/** Lists channels in a server. */
|
|
258
|
+
retrieve: (serverID: string) => Promise<IChannel[]>;
|
|
259
|
+
/** Gets one channel by ID. */
|
|
260
|
+
retrieveByID: (channelID: string) => Promise<IChannel | null>;
|
|
261
|
+
/** Creates a channel in a server. */
|
|
262
|
+
create: (name: string, serverID: string) => Promise<IChannel>;
|
|
263
|
+
/** Deletes a channel. */
|
|
138
264
|
delete: (channelID: string) => Promise<void>;
|
|
265
|
+
/** Lists users currently visible in a channel. */
|
|
139
266
|
userList: (channelID: string) => Promise<IUser[]>;
|
|
140
267
|
}
|
|
141
268
|
/**
|
|
142
269
|
* @ignore
|
|
143
270
|
*/
|
|
144
|
-
interface ISessions {
|
|
145
|
-
|
|
146
|
-
|
|
271
|
+
export interface ISessions {
|
|
272
|
+
/** Returns all locally known sessions. */
|
|
273
|
+
retrieve: () => Promise<ISessionSQL[]>;
|
|
274
|
+
/** Builds a human-readable verification phrase from a session fingerprint. */
|
|
275
|
+
verify: (session: ISessionSQL) => string;
|
|
276
|
+
/** Marks one session as verification-confirmed. */
|
|
147
277
|
markVerified: (fingerprint: string) => Promise<void>;
|
|
148
278
|
}
|
|
149
279
|
/**
|
|
150
280
|
* @ignore
|
|
151
281
|
*/
|
|
152
|
-
interface IDevices {
|
|
153
|
-
|
|
154
|
-
|
|
282
|
+
export interface IDevices {
|
|
283
|
+
/** Fetches one device by ID. */
|
|
284
|
+
retrieve: (deviceIdentifier: string) => Promise<IDevice | null>;
|
|
285
|
+
/** Registers the current key material as a new device. */
|
|
286
|
+
register: () => Promise<IDevice | null>;
|
|
287
|
+
/** Deletes one of the account's devices (except the currently active one). */
|
|
155
288
|
delete: (deviceID: string) => Promise<void>;
|
|
156
289
|
}
|
|
157
290
|
/**
|
|
158
291
|
* @ignore
|
|
159
292
|
*/
|
|
160
|
-
interface IFiles {
|
|
161
|
-
|
|
162
|
-
|
|
293
|
+
export interface IFiles {
|
|
294
|
+
/** Uploads and encrypts a file. */
|
|
295
|
+
create: (file: Buffer) => Promise<[IFileSQL, string]>;
|
|
296
|
+
/** Downloads and decrypts a file using a file ID and key. */
|
|
297
|
+
retrieve: (fileID: string, key: string) => Promise<IFileResponse | null>;
|
|
163
298
|
}
|
|
164
299
|
/**
|
|
165
300
|
* @ignore
|
|
166
301
|
*/
|
|
167
|
-
interface
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
302
|
+
export interface IEmojis {
|
|
303
|
+
/** Uploads a custom emoji to a server. */
|
|
304
|
+
create: (emoji: Buffer, name: string, serverID: string) => Promise<IEmoji | null>;
|
|
305
|
+
/** Lists emojis available on a server. */
|
|
306
|
+
retrieveList: (serverID: string) => Promise<IEmoji[]>;
|
|
307
|
+
/** Fetches one emoji's metadata by ID. */
|
|
308
|
+
retrieve: (emojiID: string) => Promise<IEmoji | null>;
|
|
171
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Progress payload emitted by the `fileProgress` event.
|
|
312
|
+
*/
|
|
172
313
|
export interface IFileProgress {
|
|
314
|
+
/** Correlation token (file ID, nonce, or label depending on operation). */
|
|
173
315
|
token: string;
|
|
316
|
+
/** Whether this progress event is for upload or download. */
|
|
174
317
|
direction: "upload" | "download";
|
|
318
|
+
/** Integer percentage from `0` to `100`. */
|
|
175
319
|
progress: number;
|
|
320
|
+
/** Bytes transferred so far. */
|
|
176
321
|
loaded: number;
|
|
322
|
+
/** Total expected bytes when available, otherwise `0`. */
|
|
177
323
|
total: number;
|
|
178
324
|
}
|
|
179
325
|
/**
|
|
180
326
|
* IClientOptions are the options you can pass into the client.
|
|
181
327
|
*/
|
|
182
328
|
export interface IClientOptions {
|
|
329
|
+
/** Logging level for client runtime logs. */
|
|
183
330
|
logLevel?: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
331
|
+
/** API host without protocol. Defaults to `api.vex.wtf`. */
|
|
184
332
|
host?: string;
|
|
333
|
+
/** Folder path where the sqlite file is created. */
|
|
185
334
|
dbFolder?: string;
|
|
335
|
+
/** Use sqlite in-memory mode (`:memory:`) instead of a file. */
|
|
186
336
|
inMemoryDb?: boolean;
|
|
337
|
+
/** Logging level for storage/database logs. */
|
|
187
338
|
dbLogLevel?: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
339
|
+
/** Use `http/ws` instead of `https/wss`. Intended for local/dev environments. */
|
|
188
340
|
unsafeHttp?: boolean;
|
|
341
|
+
/** Whether local message history should be persisted by default storage. */
|
|
189
342
|
saveHistory?: boolean;
|
|
190
343
|
}
|
|
191
344
|
export declare interface Client {
|
|
@@ -218,6 +371,14 @@ export declare interface Client {
|
|
|
218
371
|
* @event
|
|
219
372
|
*/
|
|
220
373
|
on(event: "ready", callback: () => void): this;
|
|
374
|
+
/**
|
|
375
|
+
* Emitted before the first inbox fetch/decrypt cycle after connect.
|
|
376
|
+
*
|
|
377
|
+
* Use this to show temporary loading UI while historical messages are
|
|
378
|
+
* decrypted from server payloads.
|
|
379
|
+
*
|
|
380
|
+
* @event
|
|
381
|
+
*/
|
|
221
382
|
on(event: "decryptingMail", callback: () => void): this;
|
|
222
383
|
/**
|
|
223
384
|
* This is emitted when you are connected to the chat.
|
|
@@ -354,13 +515,33 @@ export declare interface Client {
|
|
|
354
515
|
*
|
|
355
516
|
* main();
|
|
356
517
|
* ```
|
|
357
|
-
*
|
|
358
|
-
* @noInheritDoc
|
|
359
518
|
*/
|
|
360
519
|
export declare class Client extends EventEmitter {
|
|
520
|
+
/**
|
|
521
|
+
* Loads a key file from disk.
|
|
522
|
+
*
|
|
523
|
+
* Pass-through utility from `@vex-chat/crypto`.
|
|
524
|
+
*/
|
|
361
525
|
static loadKeyFile: (path: string, password: string) => string;
|
|
362
|
-
|
|
363
|
-
|
|
526
|
+
/**
|
|
527
|
+
* Saves a key file to disk.
|
|
528
|
+
*
|
|
529
|
+
* Pass-through utility from `@vex-chat/crypto`.
|
|
530
|
+
*/
|
|
531
|
+
static saveKeyFile: (path: string, password: string, keyToSave: string, iterationOverride?: number) => void;
|
|
532
|
+
/**
|
|
533
|
+
* Creates and initializes a client in one step.
|
|
534
|
+
*
|
|
535
|
+
* @param privateKey Optional hex secret key. When omitted, a fresh key is generated.
|
|
536
|
+
* @param options Runtime options.
|
|
537
|
+
* @param storage Optional custom storage backend implementing `IStorage`.
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```ts
|
|
541
|
+
* const client = await Client.create(privateKey, { host: "api.vex.wtf" });
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
static create: (privateKey?: string, options?: IClientOptions, storage?: IStorage) => Promise<Client>;
|
|
364
545
|
/**
|
|
365
546
|
* Generates an ed25519 secret key as a hex string.
|
|
366
547
|
*
|
|
@@ -376,37 +557,75 @@ export declare class Client extends EventEmitter {
|
|
|
376
557
|
private static getMnemonic;
|
|
377
558
|
private static deserializeExtra;
|
|
378
559
|
/**
|
|
379
|
-
*
|
|
560
|
+
* User operations.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```ts
|
|
564
|
+
* const [user] = await client.users.retrieve("alice");
|
|
565
|
+
* const familiarUsers = await client.users.familiars();
|
|
566
|
+
* ```
|
|
380
567
|
*/
|
|
381
568
|
users: IUsers;
|
|
382
|
-
|
|
569
|
+
/**
|
|
570
|
+
* Emoji operations.
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
* ```ts
|
|
574
|
+
* const emoji = await client.emoji.create(imageBuffer, "party", serverID);
|
|
575
|
+
* const list = await client.emoji.retrieveList(serverID);
|
|
576
|
+
* ```
|
|
577
|
+
*/
|
|
578
|
+
emoji: IEmojis;
|
|
579
|
+
/**
|
|
580
|
+
* Helpers for information/actions related to the currently authenticated account.
|
|
581
|
+
*/
|
|
383
582
|
me: IMe;
|
|
384
|
-
devices: IDevices;
|
|
385
583
|
/**
|
|
386
|
-
*
|
|
584
|
+
* Device management methods.
|
|
387
585
|
*/
|
|
586
|
+
devices: IDevices;
|
|
587
|
+
/** File upload/download methods. */
|
|
388
588
|
files: IFiles;
|
|
389
589
|
/**
|
|
390
|
-
*
|
|
590
|
+
* Permission-management methods for the current user.
|
|
391
591
|
*/
|
|
392
592
|
permissions: IPermissions;
|
|
393
593
|
/**
|
|
394
|
-
*
|
|
594
|
+
* Server moderation helper methods.
|
|
395
595
|
*/
|
|
396
596
|
moderation: IModeration;
|
|
397
597
|
/**
|
|
398
|
-
*
|
|
598
|
+
* Invite-management methods.
|
|
399
599
|
*/
|
|
400
600
|
invites: IInvites;
|
|
401
601
|
/**
|
|
402
|
-
*
|
|
602
|
+
* Message operations (direct and group).
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```ts
|
|
606
|
+
* await client.messages.send(userID, "Hello!");
|
|
607
|
+
* await client.messages.group(channelID, "Hello channel!");
|
|
608
|
+
* const dmHistory = await client.messages.retrieve(userID);
|
|
609
|
+
* ```
|
|
403
610
|
*/
|
|
404
611
|
messages: IMessages;
|
|
405
612
|
/**
|
|
406
|
-
*
|
|
613
|
+
* Encryption-session helpers.
|
|
407
614
|
*/
|
|
408
615
|
sessions: ISessions;
|
|
616
|
+
/**
|
|
617
|
+
* Server operations.
|
|
618
|
+
*
|
|
619
|
+
* @example
|
|
620
|
+
* ```ts
|
|
621
|
+
* const servers = await client.servers.retrieve();
|
|
622
|
+
* const created = await client.servers.create("Team Space");
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
409
625
|
servers: IServers;
|
|
626
|
+
/**
|
|
627
|
+
* Channel operations.
|
|
628
|
+
*/
|
|
410
629
|
channels: IChannels;
|
|
411
630
|
/**
|
|
412
631
|
* This is true if the client has ever been initialized. You can only initialize
|
|
@@ -443,6 +662,14 @@ export declare class Client extends EventEmitter {
|
|
|
443
662
|
private forwarded;
|
|
444
663
|
private prefixes;
|
|
445
664
|
private constructor();
|
|
665
|
+
/**
|
|
666
|
+
* Returns the current HTTP API origin with protocol.
|
|
667
|
+
*
|
|
668
|
+
* @example
|
|
669
|
+
* ```ts
|
|
670
|
+
* console.log(client.getHost()); // "https://api.vex.wtf"
|
|
671
|
+
* ```
|
|
672
|
+
*/
|
|
446
673
|
getHost(): string;
|
|
447
674
|
/**
|
|
448
675
|
* Manually closes the client. Emits the closed event on successful shutdown.
|
|
@@ -452,16 +679,43 @@ export declare class Client extends EventEmitter {
|
|
|
452
679
|
* Gets the hex string representations of the public and private keys.
|
|
453
680
|
*/
|
|
454
681
|
getKeys(): IKeys;
|
|
682
|
+
/**
|
|
683
|
+
* Authenticates with username/password and stores the auth token/cookie.
|
|
684
|
+
*
|
|
685
|
+
* @param username Account username.
|
|
686
|
+
* @param password Account password.
|
|
687
|
+
* @returns `null` on success, or the thrown error object on failure.
|
|
688
|
+
*
|
|
689
|
+
* @example
|
|
690
|
+
* ```ts
|
|
691
|
+
* const err = await client.login("alice", "correct horse battery staple");
|
|
692
|
+
* if (err) console.error(err);
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
455
695
|
login(username: string, password: string): Promise<Error | null>;
|
|
456
696
|
/**
|
|
457
697
|
* Returns the authorization cookie details. Throws if you don't have a
|
|
458
698
|
* valid authorization cookie.
|
|
459
699
|
*/
|
|
700
|
+
/**
|
|
701
|
+
* Returns details about the currently authenticated session.
|
|
702
|
+
*
|
|
703
|
+
* @returns The authenticated user, token expiry, and active token.
|
|
704
|
+
*
|
|
705
|
+
* @example
|
|
706
|
+
* ```ts
|
|
707
|
+
* const auth = await client.whoami();
|
|
708
|
+
* console.log(auth.user.username, new Date(auth.exp));
|
|
709
|
+
* ```
|
|
710
|
+
*/
|
|
460
711
|
whoami(): Promise<{
|
|
461
|
-
user:
|
|
712
|
+
user: IUser;
|
|
462
713
|
exp: number;
|
|
463
714
|
token: string;
|
|
464
715
|
}>;
|
|
716
|
+
/**
|
|
717
|
+
* Logs out the current authenticated session from the server.
|
|
718
|
+
*/
|
|
465
719
|
logout(): Promise<void>;
|
|
466
720
|
/**
|
|
467
721
|
* Connects your device to the chat. You must have an valid authorization cookie.
|
|
@@ -476,7 +730,10 @@ export declare class Client extends EventEmitter {
|
|
|
476
730
|
*
|
|
477
731
|
* @example [user, err] = await client.register("MyUsername");
|
|
478
732
|
*/
|
|
479
|
-
register(username: string, password: string): Promise<[
|
|
733
|
+
register(username: string, password: string): Promise<[IUser | null, Error | null]>;
|
|
734
|
+
/**
|
|
735
|
+
* Returns a compact `<username><deviceID>` debug label.
|
|
736
|
+
*/
|
|
480
737
|
toString(): string;
|
|
481
738
|
private redeemInvite;
|
|
482
739
|
private retrieveInvites;
|
|
@@ -561,4 +818,3 @@ export declare class Client extends EventEmitter {
|
|
|
561
818
|
private ping;
|
|
562
819
|
private censorPreKey;
|
|
563
820
|
}
|
|
564
|
-
export {};
|