korero-chat 0.0.0-stage → 0.1.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 +48 -2
- package/dist/LICENSE +661 -0
- package/dist/auth.d.ts +23 -0
- package/dist/auth.js +22 -0
- package/dist/channel.d.ts +44 -0
- package/dist/channel.js +56 -0
- package/dist/direct-crypto.d.ts +26 -0
- package/dist/direct-crypto.js +79 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +20 -0
- package/dist/http.d.ts +287 -0
- package/dist/http.js +95 -0
- package/dist/identity.d.ts +12 -0
- package/dist/identity.js +72 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +8 -0
- package/dist/session.d.ts +143 -0
- package/dist/session.js +648 -0
- package/dist/transport.d.ts +16 -0
- package/dist/transport.js +28 -0
- package/dist/types.d.ts +224 -0
- package/dist/types.js +12 -0
- package/package.json +36 -4
- package/src/auth.ts +42 -0
- package/src/channel.ts +71 -0
- package/src/direct-crypto.ts +90 -0
- package/src/errors.ts +20 -0
- package/src/http.ts +216 -0
- package/src/identity.ts +84 -0
- package/src/index.ts +18 -0
- package/src/session.ts +648 -0
- package/src/transport.ts +38 -0
- package/src/types.ts +199 -0
package/README.md
CHANGED
|
@@ -1,3 +1,49 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Korero.chat TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Build clients and bots for the [Korero v1 protocol](../docs/protocol.md). The SDK runs in modern browsers with Web Crypto, Bun, and Node.js 22+. Each `KoreroClient` owns a connection to one server.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install korero-chat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Listen and respond
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Channel, KoreroClient, identityFromPrivateKey } from "korero-chat";
|
|
15
|
+
|
|
16
|
+
const client = new KoreroClient("https://chat.example.org:8443");
|
|
17
|
+
const identity = identityFromPrivateKey(process.env.KORERO_PRIVATE_KEY!);
|
|
18
|
+
const channel = new Channel(process.env.KORERO_CHANNEL_ID!, client);
|
|
19
|
+
|
|
20
|
+
client.on("messageCreate", (message) => {
|
|
21
|
+
if (message.senderId === client.state.snapshot?.account.id) return;
|
|
22
|
+
if (message.text === "!ping") {
|
|
23
|
+
void message.channel.send("Pong!").catch(console.error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await client.connect({ identity, deviceName: "Ping bot" });
|
|
28
|
+
await channel.follow();
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Create an identity once with `generateIdentity()` and store its private key securely. On first connection, pass `action: { operation: "register", displayName: "Ping bot", invitation }` to `connect()` to enroll it. Use the same identity on later runs. An invitation is needed when the server requires one. If the server requires a password, include it in the action. An encrypted Korero identity backup can also be loaded with `importIdentity()`.
|
|
32
|
+
|
|
33
|
+
`client.channel(id)` is shorthand for `new Channel(id, client)`. Use `channel.send()`, `channel.history()`, `channel.join()`, `channel.edit()`, and `channel.delete()` as permitted by the server. A client can follow one channel alongside its joined channel. `client.disconnect()` closes signaling and revokes the device session. Create a new client for a new connection after disconnecting.
|
|
34
|
+
|
|
35
|
+
## Events and other operations
|
|
36
|
+
|
|
37
|
+
| Event | Payload |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `ready` | Initial server snapshot |
|
|
40
|
+
| `state` | Connection status, current snapshot, and recent messages |
|
|
41
|
+
| `messageCreate` | Live `ChannelMessage` with its channel and edit/delete methods |
|
|
42
|
+
| `messageUpdate` / `messageDelete` | Message ID and any updated content |
|
|
43
|
+
| `directMessage` / `directMessageChange` | Encrypted packet or edit/delete |
|
|
44
|
+
| `poke` | Incoming poke |
|
|
45
|
+
| `raw` | Original signaling event with its protocol type and payload |
|
|
46
|
+
|
|
47
|
+
Use `on`, `once`, and `off` to manage handlers. Register handlers before connecting to receive offline direct messages. Use `client.api` for typed HTTP operations such as account settings and administration. For end-to-end encrypted direct messages, `client.directPeer()`, `directConversation()`, and `client.sendDirect()` provide peer lookup, encryption and signing, and delivery. Check your enrolled public key and verify the conversation safety code with the recipient before sending or decrypting. See the [direct-message protocol](../docs/protocol.md#encrypted-direct-messages) for the verification requirements.
|
|
48
|
+
|
|
49
|
+
The default transport uses the runtime's HTTPS trust store and WebSocket implementation. For custom certificate trust, pass a `Transport` to the constructor. Browser callers also need their origin allowed by the server. The SDK accepts a media adapter for clients with voice support.
|