@vex-chat/libvex 0.21.0-rc.0 → 0.27.1
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/README.md +24 -27
- package/dist/Client.d.ts +37 -43
- package/dist/Client.js +320 -510
- package/dist/Client.js.map +1 -1
- package/dist/IStorage.d.ts +9 -8
- package/dist/Storage.d.ts +10 -9
- package/dist/Storage.js +12 -17
- package/dist/Storage.js.map +1 -1
- package/dist/__tests__/Client.js +176 -247
- package/dist/__tests__/Client.js.map +1 -1
- package/dist/utils/capitalize.js +1 -2
- package/dist/utils/capitalize.js.map +1 -1
- package/dist/utils/createLogger.js +2 -1
- package/dist/utils/createLogger.js.map +1 -1
- package/dist/utils/formatBytes.js +1 -2
- package/dist/utils/formatBytes.js.map +1 -1
- package/dist/utils/sqlSessionToCrypto.d.ts +2 -2
- package/dist/utils/sqlSessionToCrypto.js +2 -1
- package/dist/utils/sqlSessionToCrypto.js.map +1 -1
- package/dist/utils/uint8uuid.d.ts +2 -2
- package/dist/utils/uint8uuid.js +5 -4
- package/dist/utils/uint8uuid.js.map +1 -1
- package/jest.config.js +17 -19
- package/package.json +17 -23
- package/.changeset/pre.json +0 -8
- package/.changeset/prerelease-rc.md +0 -5
- package/CHANGELOG.md +0 -7
package/README.md
CHANGED
|
@@ -8,46 +8,43 @@ nodejs for interfacing with xchat server. Use it for a client, a bot, whatever y
|
|
|
8
8
|
|
|
9
9
|
## Quickstart
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
11
|
+
```ts
|
|
14
12
|
import { Client } from "@vex-chat/libvex";
|
|
15
13
|
|
|
16
14
|
async function main() {
|
|
17
|
-
//
|
|
15
|
+
// generate a secret key to use, save this somewhere permanent
|
|
18
16
|
const privateKey = Client.generateSecretKey();
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
const client = await Client.create(privateKey, {
|
|
22
|
-
host: "api.vex.wtf",
|
|
23
|
-
logLevel: "info",
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Register (only needed once per new key)
|
|
27
|
-
// await client.register("Username", "Password123");
|
|
18
|
+
const client = new Client(privateKey);
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
/* the ready event is emitted when init() is finished.
|
|
21
|
+
you must wait until this event fires to perform
|
|
22
|
+
registration or login. */
|
|
23
|
+
client.on("ready", async () => {
|
|
24
|
+
// you must register once before you can log in
|
|
25
|
+
await client.register(Client.randomUsername());
|
|
26
|
+
await client.login();
|
|
27
|
+
});
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
/* The authed event fires when login() successfully completes
|
|
30
|
+
and the server indicates you are authorized. You must wait to
|
|
31
|
+
perform any operations besides register() and login() until
|
|
32
|
+
this occurs. */
|
|
33
|
+
client.on("authed", async () => {
|
|
34
|
+
const me = await client.users.me();
|
|
40
35
|
|
|
41
|
-
//
|
|
36
|
+
// send a message
|
|
42
37
|
await client.messages.send(me.userID, "Hello world!");
|
|
43
38
|
});
|
|
44
39
|
|
|
40
|
+
/* Outgoing and incoming messages are emitted here. */
|
|
45
41
|
client.on("message", (message) => {
|
|
46
|
-
console.log(
|
|
47
|
-
`Received message from ${message.sender}:`,
|
|
48
|
-
message.message
|
|
49
|
-
);
|
|
42
|
+
console.log("message:", message);
|
|
50
43
|
});
|
|
44
|
+
|
|
45
|
+
/* you must call init() to initialize the keyring and
|
|
46
|
+
start the client. */
|
|
47
|
+
client.init();
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
main();
|
package/dist/Client.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { XTypes } from "@vex-chat/types";
|
|
3
|
+
import { AxiosError } from "axios";
|
|
2
4
|
import { EventEmitter } from "events";
|
|
3
5
|
import { IStorage } from "./IStorage";
|
|
4
6
|
interface ICensoredUser {
|
|
5
|
-
lastSeen:
|
|
7
|
+
lastSeen: number;
|
|
6
8
|
userID: string;
|
|
7
9
|
username: string;
|
|
8
10
|
}
|
|
@@ -26,7 +28,7 @@ export interface IMessage {
|
|
|
26
28
|
/**
|
|
27
29
|
* IPermission is a permission to a resource.
|
|
28
30
|
*/
|
|
29
|
-
export interface IPermission extends XTypes.IPermission {
|
|
31
|
+
export interface IPermission extends XTypes.SQL.IPermission {
|
|
30
32
|
}
|
|
31
33
|
/**
|
|
32
34
|
* IKeys are a pair of ed25519 public and private keys,
|
|
@@ -36,7 +38,7 @@ export interface IKeys {
|
|
|
36
38
|
public: string;
|
|
37
39
|
private: string;
|
|
38
40
|
}
|
|
39
|
-
export interface IDevice extends XTypes.IDevice {
|
|
41
|
+
export interface IDevice extends XTypes.SQL.IDevice {
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* IUser is a single user on the vex platform.
|
|
@@ -46,41 +48,41 @@ export interface IUser extends ICensoredUser {
|
|
|
46
48
|
/**
|
|
47
49
|
* ISession is an end to end encryption session with another peer.
|
|
48
50
|
*/
|
|
49
|
-
export interface ISession extends XTypes.
|
|
51
|
+
export interface ISession extends XTypes.SQL.ISession {
|
|
50
52
|
}
|
|
51
53
|
/**
|
|
52
54
|
* IChannel is a chat channel on a server.
|
|
53
55
|
*/
|
|
54
|
-
export interface IChannel extends XTypes.IChannel {
|
|
56
|
+
export interface IChannel extends XTypes.SQL.IChannel {
|
|
55
57
|
}
|
|
56
58
|
/**
|
|
57
59
|
* IServer is a single chat server.
|
|
58
60
|
*/
|
|
59
|
-
export interface IServer extends XTypes.IServer {
|
|
61
|
+
export interface IServer extends XTypes.SQL.IServer {
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
64
|
* Ifile is an uploaded encrypted file.
|
|
63
65
|
*/
|
|
64
|
-
export interface IFile extends XTypes.
|
|
66
|
+
export interface IFile extends XTypes.SQL.IFile {
|
|
65
67
|
}
|
|
66
68
|
/**
|
|
67
69
|
* IFileRes is a server response to a file retrieval request.
|
|
68
70
|
*/
|
|
69
|
-
export interface IFileRes extends XTypes.IFileResponse {
|
|
71
|
+
export interface IFileRes extends XTypes.HTTP.IFileResponse {
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
* @ignore
|
|
73
75
|
*/
|
|
74
76
|
interface IMe {
|
|
75
77
|
user: () => ICensoredUser;
|
|
76
|
-
device: () => XTypes.IDevice;
|
|
78
|
+
device: () => XTypes.SQL.IDevice;
|
|
77
79
|
setAvatar: (avatar: Buffer) => Promise<void>;
|
|
78
80
|
}
|
|
79
81
|
/**
|
|
80
82
|
* @ignore
|
|
81
83
|
*/
|
|
82
84
|
interface IUsers {
|
|
83
|
-
retrieve: (userID: string) => Promise<[IUser | null,
|
|
85
|
+
retrieve: (userID: string) => Promise<[IUser | null, AxiosError | null]>;
|
|
84
86
|
familiars: () => Promise<IUser[]>;
|
|
85
87
|
}
|
|
86
88
|
/**
|
|
@@ -98,9 +100,9 @@ interface IMessages {
|
|
|
98
100
|
* @ignore
|
|
99
101
|
*/
|
|
100
102
|
interface IServers {
|
|
101
|
-
retrieve: () => Promise<XTypes.IServer[]>;
|
|
102
|
-
retrieveByID: (serverID: string) => Promise<XTypes.IServer | null>;
|
|
103
|
-
create: (name: string) => Promise<XTypes.IServer>;
|
|
103
|
+
retrieve: () => Promise<XTypes.SQL.IServer[]>;
|
|
104
|
+
retrieveByID: (serverID: string) => Promise<XTypes.SQL.IServer | null>;
|
|
105
|
+
create: (name: string) => Promise<XTypes.SQL.IServer>;
|
|
104
106
|
delete: (serverID: string) => Promise<void>;
|
|
105
107
|
leave: (serverID: string) => Promise<void>;
|
|
106
108
|
}
|
|
@@ -109,30 +111,30 @@ interface IServers {
|
|
|
109
111
|
*/
|
|
110
112
|
interface IModeration {
|
|
111
113
|
kick: (userID: string, serverID: string) => Promise<void>;
|
|
112
|
-
fetchPermissionList: (serverID: string) => Promise<XTypes.IPermission[]>;
|
|
114
|
+
fetchPermissionList: (serverID: string) => Promise<XTypes.SQL.IPermission[]>;
|
|
113
115
|
}
|
|
114
116
|
/**
|
|
115
117
|
* @ignore
|
|
116
118
|
*/
|
|
117
119
|
interface IPermissions {
|
|
118
|
-
retrieve: () => Promise<XTypes.IPermission[]>;
|
|
120
|
+
retrieve: () => Promise<XTypes.SQL.IPermission[]>;
|
|
119
121
|
delete: (permissionID: string) => Promise<void>;
|
|
120
122
|
}
|
|
121
123
|
/**
|
|
122
124
|
* @ignore
|
|
123
125
|
*/
|
|
124
126
|
interface IInvites {
|
|
125
|
-
redeem: (inviteID: string) => Promise<XTypes.IPermission>;
|
|
126
|
-
create: (serverID: string, duration: string) => Promise<XTypes.IInvite>;
|
|
127
|
-
retrieve: (serverID: string) => Promise<XTypes.IInvite[]>;
|
|
127
|
+
redeem: (inviteID: string) => Promise<XTypes.SQL.IPermission>;
|
|
128
|
+
create: (serverID: string, duration: string) => Promise<XTypes.SQL.IInvite>;
|
|
129
|
+
retrieve: (serverID: string) => Promise<XTypes.SQL.IInvite[]>;
|
|
128
130
|
}
|
|
129
131
|
/**
|
|
130
132
|
* @ignore
|
|
131
133
|
*/
|
|
132
134
|
interface IChannels {
|
|
133
|
-
retrieve: (serverID: string) => Promise<XTypes.IChannel[]>;
|
|
134
|
-
retrieveByID: (channelID: string) => Promise<XTypes.IChannel | null>;
|
|
135
|
-
create: (name: string, serverID: string) => Promise<XTypes.IChannel>;
|
|
135
|
+
retrieve: (serverID: string) => Promise<XTypes.SQL.IChannel[]>;
|
|
136
|
+
retrieveByID: (channelID: string) => Promise<XTypes.SQL.IChannel | null>;
|
|
137
|
+
create: (name: string, serverID: string) => Promise<XTypes.SQL.IChannel>;
|
|
136
138
|
delete: (channelID: string) => Promise<void>;
|
|
137
139
|
userList: (channelID: string) => Promise<IUser[]>;
|
|
138
140
|
}
|
|
@@ -140,32 +142,32 @@ interface IChannels {
|
|
|
140
142
|
* @ignore
|
|
141
143
|
*/
|
|
142
144
|
interface ISessions {
|
|
143
|
-
retrieve: () => Promise<XTypes.
|
|
144
|
-
verify: (session: XTypes.
|
|
145
|
+
retrieve: () => Promise<XTypes.SQL.ISession[]>;
|
|
146
|
+
verify: (session: XTypes.SQL.ISession) => string;
|
|
145
147
|
markVerified: (fingerprint: string) => Promise<void>;
|
|
146
148
|
}
|
|
147
149
|
/**
|
|
148
150
|
* @ignore
|
|
149
151
|
*/
|
|
150
152
|
interface IDevices {
|
|
151
|
-
retrieve: (deviceIdentifier: string) => Promise<XTypes.IDevice | null>;
|
|
152
|
-
register: () => Promise<XTypes.IDevice | null>;
|
|
153
|
+
retrieve: (deviceIdentifier: string) => Promise<XTypes.SQL.IDevice | null>;
|
|
154
|
+
register: () => Promise<XTypes.SQL.IDevice | null>;
|
|
153
155
|
delete: (deviceID: string) => Promise<void>;
|
|
154
156
|
}
|
|
155
157
|
/**
|
|
156
158
|
* @ignore
|
|
157
159
|
*/
|
|
158
160
|
interface IFiles {
|
|
159
|
-
create: (file: Buffer) => Promise<[XTypes.
|
|
160
|
-
retrieve: (fileID: string, key: string) => Promise<XTypes.IFileResponse | null>;
|
|
161
|
+
create: (file: Buffer) => Promise<[XTypes.SQL.IFile, string]>;
|
|
162
|
+
retrieve: (fileID: string, key: string) => Promise<XTypes.HTTP.IFileResponse | null>;
|
|
161
163
|
}
|
|
162
164
|
/**
|
|
163
165
|
* @ignore
|
|
164
166
|
*/
|
|
165
167
|
interface IEmoji {
|
|
166
|
-
create: (emoji: Buffer, name: string, serverID: string) => Promise<XTypes.IEmoji | null>;
|
|
167
|
-
retrieveList: (serverID: string) => Promise<XTypes.IEmoji[]>;
|
|
168
|
-
retrieve: (emojiID: string) => Promise<XTypes.IEmoji | null>;
|
|
168
|
+
create: (emoji: Buffer, name: string, serverID: string) => Promise<XTypes.SQL.IEmoji | null>;
|
|
169
|
+
retrieveList: (serverID: string) => Promise<XTypes.SQL.IEmoji[]>;
|
|
170
|
+
retrieve: (emojiID: string) => Promise<XTypes.SQL.IEmoji | null>;
|
|
169
171
|
}
|
|
170
172
|
export interface IFileProgress {
|
|
171
173
|
token: string;
|
|
@@ -185,7 +187,6 @@ export interface IClientOptions {
|
|
|
185
187
|
dbLogLevel?: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
186
188
|
unsafeHttp?: boolean;
|
|
187
189
|
saveHistory?: boolean;
|
|
188
|
-
token?: string;
|
|
189
190
|
}
|
|
190
191
|
export declare interface Client {
|
|
191
192
|
/**
|
|
@@ -358,8 +359,8 @@ export declare interface Client {
|
|
|
358
359
|
*/
|
|
359
360
|
export declare class Client extends EventEmitter {
|
|
360
361
|
static loadKeyFile: (path: string, password: string) => string;
|
|
361
|
-
static saveKeyFile: (path: string, password: string, keyToSave: string, iterationOverride?: number) => void;
|
|
362
|
-
static create: (privateKey?: string, options?: IClientOptions, storage?: IStorage) => Promise<Client>;
|
|
362
|
+
static saveKeyFile: (path: string, password: string, keyToSave: string, iterationOverride?: number | undefined) => void;
|
|
363
|
+
static create: (privateKey?: string | undefined, options?: IClientOptions | undefined, storage?: IStorage | undefined) => Promise<Client>;
|
|
363
364
|
/**
|
|
364
365
|
* Generates an ed25519 secret key as a hex string.
|
|
365
366
|
*
|
|
@@ -439,19 +440,10 @@ export declare class Client extends EventEmitter {
|
|
|
439
440
|
private mailInterval?;
|
|
440
441
|
private manuallyClosing;
|
|
441
442
|
private token;
|
|
442
|
-
private deviceToken;
|
|
443
443
|
private forwarded;
|
|
444
444
|
private prefixes;
|
|
445
|
-
private ax;
|
|
446
445
|
private constructor();
|
|
447
|
-
private getTokenPath;
|
|
448
|
-
private saveToken;
|
|
449
|
-
private loadToken;
|
|
450
|
-
clearToken(): void;
|
|
451
446
|
getHost(): string;
|
|
452
|
-
private getDeviceTokenPath;
|
|
453
|
-
private saveDeviceToken;
|
|
454
|
-
private loadDeviceToken;
|
|
455
447
|
/**
|
|
456
448
|
* Manually closes the client. Emits the closed event on successful shutdown.
|
|
457
449
|
*/
|
|
@@ -493,6 +485,8 @@ export declare class Client extends EventEmitter {
|
|
|
493
485
|
private retrieveEmojiByID;
|
|
494
486
|
private leaveServer;
|
|
495
487
|
private kickUser;
|
|
488
|
+
private addCookie;
|
|
489
|
+
private getCookies;
|
|
496
490
|
private uploadEmoji;
|
|
497
491
|
private retrieveOrCreateDevice;
|
|
498
492
|
private registerDevice;
|