@vex-chat/libvex 0.20.9 → 0.21.0-rc.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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.changeset/pre.json +8 -0
- package/.changeset/prerelease-rc.md +5 -0
- package/CHANGELOG.md +7 -0
- package/README.md +27 -24
- package/RELEASING.md +95 -0
- package/dist/Client.d.ts +43 -37
- package/dist/Client.js +510 -320
- package/dist/Client.js.map +1 -1
- package/dist/IStorage.d.ts +8 -9
- package/dist/Storage.d.ts +9 -10
- package/dist/Storage.js +17 -12
- package/dist/Storage.js.map +1 -1
- package/dist/__tests__/Client.js +242 -144
- package/dist/__tests__/Client.js.map +1 -1
- package/dist/utils/capitalize.js +2 -1
- package/dist/utils/capitalize.js.map +1 -1
- package/dist/utils/constants.d.ts +8 -0
- package/dist/utils/constants.js +12 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/createLogger.js +1 -2
- package/dist/utils/createLogger.js.map +1 -1
- package/dist/utils/formatBytes.js +2 -1
- package/dist/utils/formatBytes.js.map +1 -1
- package/dist/utils/sqlSessionToCrypto.d.ts +2 -2
- package/dist/utils/sqlSessionToCrypto.js +1 -2
- package/dist/utils/sqlSessionToCrypto.js.map +1 -1
- package/dist/utils/uint8uuid.d.ts +2 -2
- package/dist/utils/uint8uuid.js +4 -5
- package/dist/utils/uint8uuid.js.map +1 -1
- package/jest.config.js +19 -17
- package/mise.toml +3 -0
- package/package.json +23 -10
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changesets
|
|
2
|
+
|
|
3
|
+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
+
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
+
find the full documentation for it [in the changesets repo](https://github.com/changesets/changesets)
|
|
6
|
+
|
|
7
|
+
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json",
|
|
3
|
+
"changelog": "@changesets/cli/changelog",
|
|
4
|
+
"commit": false,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "master",
|
|
9
|
+
"updateInternalDependencies": "patch",
|
|
10
|
+
"ignore": []
|
|
11
|
+
}
|
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -8,43 +8,46 @@ nodejs for interfacing with xchat server. Use it for a client, a bot, whatever y
|
|
|
8
8
|
|
|
9
9
|
## Quickstart
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
The client now uses an asynchronous factory pattern. You must use `Client.create()` instead of `new Client()`.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
12
14
|
import { Client } from "@vex-chat/libvex";
|
|
13
15
|
|
|
14
16
|
async function main() {
|
|
15
|
-
//
|
|
17
|
+
// Generate a secret key (save this securely, it is your identity)
|
|
16
18
|
const privateKey = Client.generateSecretKey();
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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();
|
|
20
|
+
// Client.create handles the database connection and crypto initialization for you.
|
|
21
|
+
const client = await Client.create(privateKey, {
|
|
22
|
+
host: "api.vex.wtf",
|
|
23
|
+
logLevel: "info",
|
|
27
24
|
});
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
client.
|
|
34
|
-
const me = await client.users.me();
|
|
26
|
+
// Register (only needed once per new key)
|
|
27
|
+
// await client.register("Username", "Password123");
|
|
28
|
+
|
|
29
|
+
// Login
|
|
30
|
+
await client.login("Username", "Password123");
|
|
35
31
|
|
|
36
|
-
|
|
32
|
+
// Connect to the WebSocket
|
|
33
|
+
// This establishes the real-time connection.
|
|
34
|
+
await client.connect();
|
|
35
|
+
|
|
36
|
+
// Listen for events
|
|
37
|
+
client.on("connected", async () => {
|
|
38
|
+
console.log("Connected as", client.toString());
|
|
39
|
+
const me = client.me.user();
|
|
40
|
+
|
|
41
|
+
// Send a message
|
|
37
42
|
await client.messages.send(me.userID, "Hello world!");
|
|
38
43
|
});
|
|
39
44
|
|
|
40
|
-
/* Outgoing and incoming messages are emitted here. */
|
|
41
45
|
client.on("message", (message) => {
|
|
42
|
-
console.log(
|
|
46
|
+
console.log(
|
|
47
|
+
`Received message from ${message.sender}:`,
|
|
48
|
+
message.message
|
|
49
|
+
);
|
|
43
50
|
});
|
|
44
|
-
|
|
45
|
-
/* you must call init() to initialize the keyring and
|
|
46
|
-
start the client. */
|
|
47
|
-
client.init();
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
main();
|
package/RELEASING.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Releasing @vex-chat/libvex
|
|
2
|
+
|
|
3
|
+
This repo uses [Changesets](https://github.com/changesets/changesets) for versioning and publishing.
|
|
4
|
+
|
|
5
|
+
## Dependency Chain
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
@vex-chat/types
|
|
9
|
+
└─ @vex-chat/crypto
|
|
10
|
+
└─ @vex-chat/libvex ← you are here
|
|
11
|
+
└─ vex-desktop
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**Publish types and crypto first** if they have changes, then publish libvex.
|
|
15
|
+
|
|
16
|
+
## Day-to-Day Workflow
|
|
17
|
+
|
|
18
|
+
### 1. Work on a feature branch
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
git checkout -b my-feature
|
|
22
|
+
# ... make changes ...
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Add a changeset before pushing
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx changeset
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
This prompts you to:
|
|
32
|
+
|
|
33
|
+
- Select the package (`@vex-chat/libvex`)
|
|
34
|
+
- Choose bump type (patch / minor / major)
|
|
35
|
+
- Write a short summary of the change
|
|
36
|
+
|
|
37
|
+
It creates a file in `.changeset/` — commit it with your code.
|
|
38
|
+
|
|
39
|
+
### 3. Push and open a PR
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
git add .
|
|
43
|
+
git commit -m "my feature"
|
|
44
|
+
git push -u origin my-feature
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 4. Merge to master
|
|
48
|
+
|
|
49
|
+
After merge, the **Release** GitHub Action will:
|
|
50
|
+
|
|
51
|
+
1. Detect pending changesets
|
|
52
|
+
2. Open a **"chore: version packages"** PR with bumped version + updated CHANGELOG.md
|
|
53
|
+
3. When you merge that PR, it publishes to npm automatically
|
|
54
|
+
|
|
55
|
+
## Making a Release Right Now (Locally)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx changeset # add a changeset if you haven't
|
|
59
|
+
npx changeset version # bumps package.json, writes CHANGELOG.md
|
|
60
|
+
git add . && git commit -m "chore: version packages"
|
|
61
|
+
git push
|
|
62
|
+
npx changeset publish # publishes to npm
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Release Candidates
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npx changeset pre enter rc # enter RC mode
|
|
69
|
+
npx changeset version # produces e.g. 0.21.0-rc.0
|
|
70
|
+
npx changeset publish # publishes with --tag rc
|
|
71
|
+
|
|
72
|
+
# ... more changes + changesets ...
|
|
73
|
+
npx changeset version # produces 0.21.0-rc.1
|
|
74
|
+
npx changeset publish
|
|
75
|
+
|
|
76
|
+
# ready for stable:
|
|
77
|
+
npx changeset pre exit
|
|
78
|
+
npx changeset version # produces 0.21.0
|
|
79
|
+
npx changeset publish # publishes as @latest
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## GitHub Secrets Required
|
|
83
|
+
|
|
84
|
+
- `NPM_TOKEN` — npm access token with publish permission for `@vex-chat` scope
|
|
85
|
+
- `GITHUB_TOKEN` — provided automatically by GitHub Actions
|
|
86
|
+
|
|
87
|
+
## Local Development
|
|
88
|
+
|
|
89
|
+
You can still use `yalc` for local cross-repo development:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
yarn push # builds and pushes to yalc for local consumers
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
When publishing for real, changesets handles versioning — yalc is just for local dev loops.
|
package/dist/Client.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { XTypes } from "@vex-chat/types";
|
|
3
|
-
import { AxiosError } from "axios";
|
|
1
|
+
import * as XTypes from "@vex-chat/types";
|
|
4
2
|
import { EventEmitter } from "events";
|
|
5
3
|
import { IStorage } from "./IStorage";
|
|
6
4
|
interface ICensoredUser {
|
|
7
|
-
lastSeen:
|
|
5
|
+
lastSeen: Date;
|
|
8
6
|
userID: string;
|
|
9
7
|
username: string;
|
|
10
8
|
}
|
|
@@ -28,7 +26,7 @@ export interface IMessage {
|
|
|
28
26
|
/**
|
|
29
27
|
* IPermission is a permission to a resource.
|
|
30
28
|
*/
|
|
31
|
-
export interface IPermission extends XTypes.
|
|
29
|
+
export interface IPermission extends XTypes.IPermission {
|
|
32
30
|
}
|
|
33
31
|
/**
|
|
34
32
|
* IKeys are a pair of ed25519 public and private keys,
|
|
@@ -38,7 +36,7 @@ export interface IKeys {
|
|
|
38
36
|
public: string;
|
|
39
37
|
private: string;
|
|
40
38
|
}
|
|
41
|
-
export interface IDevice extends XTypes.
|
|
39
|
+
export interface IDevice extends XTypes.IDevice {
|
|
42
40
|
}
|
|
43
41
|
/**
|
|
44
42
|
* IUser is a single user on the vex platform.
|
|
@@ -48,41 +46,41 @@ export interface IUser extends ICensoredUser {
|
|
|
48
46
|
/**
|
|
49
47
|
* ISession is an end to end encryption session with another peer.
|
|
50
48
|
*/
|
|
51
|
-
export interface ISession extends XTypes.
|
|
49
|
+
export interface ISession extends XTypes.ISessionSQL {
|
|
52
50
|
}
|
|
53
51
|
/**
|
|
54
52
|
* IChannel is a chat channel on a server.
|
|
55
53
|
*/
|
|
56
|
-
export interface IChannel extends XTypes.
|
|
54
|
+
export interface IChannel extends XTypes.IChannel {
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
59
57
|
* IServer is a single chat server.
|
|
60
58
|
*/
|
|
61
|
-
export interface IServer extends XTypes.
|
|
59
|
+
export interface IServer extends XTypes.IServer {
|
|
62
60
|
}
|
|
63
61
|
/**
|
|
64
62
|
* Ifile is an uploaded encrypted file.
|
|
65
63
|
*/
|
|
66
|
-
export interface IFile extends XTypes.
|
|
64
|
+
export interface IFile extends XTypes.IFileSQL {
|
|
67
65
|
}
|
|
68
66
|
/**
|
|
69
67
|
* IFileRes is a server response to a file retrieval request.
|
|
70
68
|
*/
|
|
71
|
-
export interface IFileRes extends XTypes.
|
|
69
|
+
export interface IFileRes extends XTypes.IFileResponse {
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
72
|
* @ignore
|
|
75
73
|
*/
|
|
76
74
|
interface IMe {
|
|
77
75
|
user: () => ICensoredUser;
|
|
78
|
-
device: () => XTypes.
|
|
76
|
+
device: () => XTypes.IDevice;
|
|
79
77
|
setAvatar: (avatar: Buffer) => Promise<void>;
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
82
80
|
* @ignore
|
|
83
81
|
*/
|
|
84
82
|
interface IUsers {
|
|
85
|
-
retrieve: (userID: string) => Promise<[IUser | null,
|
|
83
|
+
retrieve: (userID: string) => Promise<[IUser | null, Error | null]>;
|
|
86
84
|
familiars: () => Promise<IUser[]>;
|
|
87
85
|
}
|
|
88
86
|
/**
|
|
@@ -100,9 +98,9 @@ interface IMessages {
|
|
|
100
98
|
* @ignore
|
|
101
99
|
*/
|
|
102
100
|
interface IServers {
|
|
103
|
-
retrieve: () => Promise<XTypes.
|
|
104
|
-
retrieveByID: (serverID: string) => Promise<XTypes.
|
|
105
|
-
create: (name: string) => Promise<XTypes.
|
|
101
|
+
retrieve: () => Promise<XTypes.IServer[]>;
|
|
102
|
+
retrieveByID: (serverID: string) => Promise<XTypes.IServer | null>;
|
|
103
|
+
create: (name: string) => Promise<XTypes.IServer>;
|
|
106
104
|
delete: (serverID: string) => Promise<void>;
|
|
107
105
|
leave: (serverID: string) => Promise<void>;
|
|
108
106
|
}
|
|
@@ -111,30 +109,30 @@ interface IServers {
|
|
|
111
109
|
*/
|
|
112
110
|
interface IModeration {
|
|
113
111
|
kick: (userID: string, serverID: string) => Promise<void>;
|
|
114
|
-
fetchPermissionList: (serverID: string) => Promise<XTypes.
|
|
112
|
+
fetchPermissionList: (serverID: string) => Promise<XTypes.IPermission[]>;
|
|
115
113
|
}
|
|
116
114
|
/**
|
|
117
115
|
* @ignore
|
|
118
116
|
*/
|
|
119
117
|
interface IPermissions {
|
|
120
|
-
retrieve: () => Promise<XTypes.
|
|
118
|
+
retrieve: () => Promise<XTypes.IPermission[]>;
|
|
121
119
|
delete: (permissionID: string) => Promise<void>;
|
|
122
120
|
}
|
|
123
121
|
/**
|
|
124
122
|
* @ignore
|
|
125
123
|
*/
|
|
126
124
|
interface IInvites {
|
|
127
|
-
redeem: (inviteID: string) => Promise<XTypes.
|
|
128
|
-
create: (serverID: string, duration: string) => Promise<XTypes.
|
|
129
|
-
retrieve: (serverID: string) => Promise<XTypes.
|
|
125
|
+
redeem: (inviteID: string) => Promise<XTypes.IPermission>;
|
|
126
|
+
create: (serverID: string, duration: string) => Promise<XTypes.IInvite>;
|
|
127
|
+
retrieve: (serverID: string) => Promise<XTypes.IInvite[]>;
|
|
130
128
|
}
|
|
131
129
|
/**
|
|
132
130
|
* @ignore
|
|
133
131
|
*/
|
|
134
132
|
interface IChannels {
|
|
135
|
-
retrieve: (serverID: string) => Promise<XTypes.
|
|
136
|
-
retrieveByID: (channelID: string) => Promise<XTypes.
|
|
137
|
-
create: (name: string, serverID: string) => Promise<XTypes.
|
|
133
|
+
retrieve: (serverID: string) => Promise<XTypes.IChannel[]>;
|
|
134
|
+
retrieveByID: (channelID: string) => Promise<XTypes.IChannel | null>;
|
|
135
|
+
create: (name: string, serverID: string) => Promise<XTypes.IChannel>;
|
|
138
136
|
delete: (channelID: string) => Promise<void>;
|
|
139
137
|
userList: (channelID: string) => Promise<IUser[]>;
|
|
140
138
|
}
|
|
@@ -142,32 +140,32 @@ interface IChannels {
|
|
|
142
140
|
* @ignore
|
|
143
141
|
*/
|
|
144
142
|
interface ISessions {
|
|
145
|
-
retrieve: () => Promise<XTypes.
|
|
146
|
-
verify: (session: XTypes.
|
|
143
|
+
retrieve: () => Promise<XTypes.ISessionSQL[]>;
|
|
144
|
+
verify: (session: XTypes.ISessionSQL) => string;
|
|
147
145
|
markVerified: (fingerprint: string) => Promise<void>;
|
|
148
146
|
}
|
|
149
147
|
/**
|
|
150
148
|
* @ignore
|
|
151
149
|
*/
|
|
152
150
|
interface IDevices {
|
|
153
|
-
retrieve: (deviceIdentifier: string) => Promise<XTypes.
|
|
154
|
-
register: () => Promise<XTypes.
|
|
151
|
+
retrieve: (deviceIdentifier: string) => Promise<XTypes.IDevice | null>;
|
|
152
|
+
register: () => Promise<XTypes.IDevice | null>;
|
|
155
153
|
delete: (deviceID: string) => Promise<void>;
|
|
156
154
|
}
|
|
157
155
|
/**
|
|
158
156
|
* @ignore
|
|
159
157
|
*/
|
|
160
158
|
interface IFiles {
|
|
161
|
-
create: (file: Buffer) => Promise<[XTypes.
|
|
162
|
-
retrieve: (fileID: string, key: string) => Promise<XTypes.
|
|
159
|
+
create: (file: Buffer) => Promise<[XTypes.IFileSQL, string]>;
|
|
160
|
+
retrieve: (fileID: string, key: string) => Promise<XTypes.IFileResponse | null>;
|
|
163
161
|
}
|
|
164
162
|
/**
|
|
165
163
|
* @ignore
|
|
166
164
|
*/
|
|
167
165
|
interface IEmoji {
|
|
168
|
-
create: (emoji: Buffer, name: string, serverID: string) => Promise<XTypes.
|
|
169
|
-
retrieveList: (serverID: string) => Promise<XTypes.
|
|
170
|
-
retrieve: (emojiID: string) => Promise<XTypes.
|
|
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>;
|
|
171
169
|
}
|
|
172
170
|
export interface IFileProgress {
|
|
173
171
|
token: string;
|
|
@@ -187,6 +185,7 @@ export interface IClientOptions {
|
|
|
187
185
|
dbLogLevel?: "error" | "warn" | "info" | "http" | "verbose" | "debug" | "silly";
|
|
188
186
|
unsafeHttp?: boolean;
|
|
189
187
|
saveHistory?: boolean;
|
|
188
|
+
token?: string;
|
|
190
189
|
}
|
|
191
190
|
export declare interface Client {
|
|
192
191
|
/**
|
|
@@ -359,8 +358,8 @@ export declare interface Client {
|
|
|
359
358
|
*/
|
|
360
359
|
export declare class Client extends EventEmitter {
|
|
361
360
|
static loadKeyFile: (path: string, password: string) => string;
|
|
362
|
-
static saveKeyFile: (path: string, password: string, keyToSave: string, iterationOverride?: number
|
|
363
|
-
static create: (privateKey?: string
|
|
361
|
+
static saveKeyFile: (path: string, password: string, keyToSave: string, iterationOverride?: number) => void;
|
|
362
|
+
static create: (privateKey?: string, options?: IClientOptions, storage?: IStorage) => Promise<Client>;
|
|
364
363
|
/**
|
|
365
364
|
* Generates an ed25519 secret key as a hex string.
|
|
366
365
|
*
|
|
@@ -440,10 +439,19 @@ export declare class Client extends EventEmitter {
|
|
|
440
439
|
private mailInterval?;
|
|
441
440
|
private manuallyClosing;
|
|
442
441
|
private token;
|
|
442
|
+
private deviceToken;
|
|
443
443
|
private forwarded;
|
|
444
444
|
private prefixes;
|
|
445
|
+
private ax;
|
|
445
446
|
private constructor();
|
|
447
|
+
private getTokenPath;
|
|
448
|
+
private saveToken;
|
|
449
|
+
private loadToken;
|
|
450
|
+
clearToken(): void;
|
|
446
451
|
getHost(): string;
|
|
452
|
+
private getDeviceTokenPath;
|
|
453
|
+
private saveDeviceToken;
|
|
454
|
+
private loadDeviceToken;
|
|
447
455
|
/**
|
|
448
456
|
* Manually closes the client. Emits the closed event on successful shutdown.
|
|
449
457
|
*/
|
|
@@ -485,8 +493,6 @@ export declare class Client extends EventEmitter {
|
|
|
485
493
|
private retrieveEmojiByID;
|
|
486
494
|
private leaveServer;
|
|
487
495
|
private kickUser;
|
|
488
|
-
private addCookie;
|
|
489
|
-
private getCookies;
|
|
490
496
|
private uploadEmoji;
|
|
491
497
|
private retrieveOrCreateDevice;
|
|
492
498
|
private registerDevice;
|