@snakechat/commskit-node 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/LICENSE +21 -0
- package/README.md +87 -2
- package/dist/adapters-8ztjEYtz.d.ts +83 -0
- package/dist/call.d.ts +34 -0
- package/dist/call.js +51 -0
- package/dist/call.js.map +1 -0
- package/dist/chat.d.ts +64 -0
- package/dist/chat.js +30 -0
- package/dist/chat.js.map +1 -0
- package/dist/chunk-5BJ2SNM5.js +26 -0
- package/dist/chunk-5BJ2SNM5.js.map +1 -0
- package/dist/chunk-6I27CI32.js +586 -0
- package/dist/chunk-6I27CI32.js.map +1 -0
- package/dist/chunk-BBFVG7QU.js +52 -0
- package/dist/chunk-BBFVG7QU.js.map +1 -0
- package/dist/chunk-GR4PMGCS.js +82 -0
- package/dist/chunk-GR4PMGCS.js.map +1 -0
- package/dist/chunk-KL4WRZKZ.js +799 -0
- package/dist/chunk-KL4WRZKZ.js.map +1 -0
- package/dist/chunk-KLKRK6OG.js +107 -0
- package/dist/chunk-KLKRK6OG.js.map +1 -0
- package/dist/chunk-LY2GJWN7.js +708 -0
- package/dist/chunk-LY2GJWN7.js.map +1 -0
- package/dist/chunk-SEDRF62Q.js +39 -0
- package/dist/chunk-SEDRF62Q.js.map +1 -0
- package/dist/chunk-U4Z5INIW.js +1192 -0
- package/dist/chunk-U4Z5INIW.js.map +1 -0
- package/dist/chunk-XOXZZYSW.js +247 -0
- package/dist/chunk-XOXZZYSW.js.map +1 -0
- package/dist/chunk-XQ6FLRX7.js +179 -0
- package/dist/chunk-XQ6FLRX7.js.map +1 -0
- package/dist/chunk-XQFQN73U.js +38 -0
- package/dist/chunk-XQFQN73U.js.map +1 -0
- package/dist/connections-CGEPiZPF.d.ts +128 -0
- package/dist/core.d.ts +26 -0
- package/dist/core.js +89 -0
- package/dist/core.js.map +1 -0
- package/dist/devices-oLIB_M19.d.ts +97 -0
- package/dist/express.d.ts +19 -0
- package/dist/express.js +34 -0
- package/dist/express.js.map +1 -0
- package/dist/fastify.d.ts +22 -0
- package/dist/fastify.js +42 -0
- package/dist/fastify.js.map +1 -0
- package/dist/feature-B2bEXLZG.d.ts +233 -0
- package/dist/feature-DQUbnYE-.d.ts +284 -0
- package/dist/feature-DwKkuOBh.d.ts +195 -0
- package/dist/hub-CPrWmIvB.d.ts +174 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -0
- package/dist/integration.d.ts +97 -0
- package/dist/integration.js +151 -0
- package/dist/integration.js.map +1 -0
- package/dist/models-D1lehXIu.d.ts +31 -0
- package/dist/models-DTXEX1Q8.d.ts +34 -0
- package/dist/moderation.d.ts +9 -0
- package/dist/moderation.js +48 -0
- package/dist/moderation.js.map +1 -0
- package/dist/push.d.ts +198 -0
- package/dist/push.js +475 -0
- package/dist/push.js.map +1 -0
- package/dist/redis.d.ts +103 -0
- package/dist/redis.js +296 -0
- package/dist/redis.js.map +1 -0
- package/dist/s3.d.ts +75 -0
- package/dist/s3.js +315 -0
- package/dist/s3.js.map +1 -0
- package/dist/util-B32rIBVA.d.ts +22 -0
- package/package.json +146 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 prateek0128
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @snakechat/commskit-node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Node.js / TypeScript server for the commskit wire protocol. It is a sibling of the Python backend
|
|
4
|
+
(`../backend-python`, package `commskit`) and speaks exactly the same protocol
|
|
5
|
+
([`../../docs/archive/PROTOCOL.md`](https://github.com/prateek0128/chat-call-module/blob/main/docs/archive/PROTOCOL.md)), so the existing clients (`mobile/`, `web/`,
|
|
6
|
+
`examples/backend/demo-server-python` page) work against it unchanged. A database created by either backend works with the other
|
|
7
|
+
(same table and column names).
|
|
8
|
+
|
|
9
|
+
**Status: feature-complete.** Core, chat, call signalling, moderation (block / report / admin review),
|
|
10
|
+
devices + push (Expo, Apple VoIP), the Redis bridge and S3 storage are implemented. 172 tests pass (1 more is
|
|
11
|
+
skipped: it needs a real `redis-server`). Redis, S3, Expo and APNs are tested with fakes, not real services.
|
|
12
|
+
Guides: [`../../docs/backend/backend-node/`](https://github.com/prateek0128/chat-call-module/tree/main/docs/backend/backend-node).
|
|
13
|
+
|
|
14
|
+
Stack: TypeScript (strict), Node >= 20, ESM, `ws`, `kysely` (better-sqlite3 for tests/demo, `pg` for production),
|
|
15
|
+
`jose` (HS256 JWT, claim `uid`), tsup, vitest.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @snakechat/commskit-node kysely ws jose
|
|
21
|
+
npm install better-sqlite3 # or: pg
|
|
22
|
+
npm install fastify # or: express (optional peer dependencies)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Fastify (chat only)
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import Fastify from "fastify";
|
|
29
|
+
import Database from "better-sqlite3";
|
|
30
|
+
import { Kysely, SqliteDialect } from "kysely";
|
|
31
|
+
import { ChatFeature, CommsHub, JwtAuth, ensureSchema } from "@snakechat/commskit-node";
|
|
32
|
+
import { commskitPlugin } from "@snakechat/commskit-node/fastify";
|
|
33
|
+
|
|
34
|
+
const db = new Kysely<any>({ dialect: new SqliteDialect({ database: new Database("comms.db") }) });
|
|
35
|
+
await ensureSchema(db); // creates chats, messages, calls, comms_* tables (idempotent)
|
|
36
|
+
|
|
37
|
+
const hub = new CommsHub({ auth: new JwtAuth(process.env.JWT_SECRET!), db });
|
|
38
|
+
hub.install(new ChatFeature()); // allow-all policy, LocalDiskStorage("comms_media")
|
|
39
|
+
|
|
40
|
+
const app = Fastify();
|
|
41
|
+
await app.register(commskitPlugin, { hub }); // REST routes + /ws/:token upgrade
|
|
42
|
+
await app.listen({ port: 8080 });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Express (chat only)
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { createServer } from "node:http";
|
|
49
|
+
import express from "express";
|
|
50
|
+
import { commskitRouter, attach } from "@snakechat/commskit-node/express";
|
|
51
|
+
|
|
52
|
+
const app = express();
|
|
53
|
+
app.use(commskitRouter(hub)); // /chats/...
|
|
54
|
+
const server = createServer(app);
|
|
55
|
+
attach(server, hub); // /ws/:token
|
|
56
|
+
server.listen(8080);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
No framework: `createServer((req, res) => restListener(hub)(req, res))` plus `hub.attach(server)`.
|
|
60
|
+
|
|
61
|
+
## Python name mapping
|
|
62
|
+
|
|
63
|
+
| Python (`commskit`) | Node (`@snakechat/commskit-node`) |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `CommsHub(auth=, session_factory=, users=, push=, ...)` | `new CommsHub({ auth, db, users, push, connections, rateLimiter, roleResolver, onHandlerError, cameOnlineCooldown })` |
|
|
66
|
+
| `ChatFeature(...).install(hub)` | `hub.install(new ChatFeature({ policy, storage, devices, config }))` |
|
|
67
|
+
| `ChatConfig`, `ChatPolicy`, `AllowAllChatPolicy` | `ChatConfig` (partial object), `ChatPolicy`, `AllowAllChatPolicy` |
|
|
68
|
+
| `JwtAuth`, `StaticUserDirectory`, `NullUserDirectory`, `NoopPush`, `LocalDiskStorage` | same names |
|
|
69
|
+
| `ConnectionManager`, `PresenceBridge`, `RateLimiter`, `RateLimit` | same names |
|
|
70
|
+
| `hub.on(type, handler)`, `hub.on_connect`, `hub.on_disconnect` | `hub.on`, `hub.onConnect(hook, allRoles?)`, `hub.onDisconnect` |
|
|
71
|
+
| `hub.events.on("chat.message_sent", fn)` | same event names |
|
|
72
|
+
| `chat.send_message_as`, `chat.send_system_message`, `chat.delete_user_data` | `chat.sendMessageAs`, `chat.sendSystemMessage`, `chat.deleteUserData` |
|
|
73
|
+
| `hub.ws_router()` / `hub.rest_router()` | `hub.attach(server)` / `hub.handleUpgrade(...)` and `hub.restRoutes()` |
|
|
74
|
+
| `CommsBase.metadata.create_all` | `ensureSchema(db)` |
|
|
75
|
+
|
|
76
|
+
Handlers receive `(userId, message, db)`; `db` is the hub's Kysely instance (the per-frame "session"; use
|
|
77
|
+
`db.transaction()` where you need atomicity).
|
|
78
|
+
|
|
79
|
+
## Develop
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
npm install
|
|
83
|
+
npm run typecheck && npm test && npm run build
|
|
84
|
+
python test/golden/generate_golden.py # re-record the golden frames from the Python backend (optional)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`test/golden.test.ts` replays a scripted exchange against this server and requires frames identical (after
|
|
88
|
+
id/timestamp normalisation) to the fixtures recorded from the Python backend.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** Token is missing, invalid or expired. */
|
|
2
|
+
declare class AuthError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
interface AuthAdapter {
|
|
6
|
+
/** Return the user id for `token` or throw (any exception = invalid). */
|
|
7
|
+
userIdFromToken(token: string): string | Promise<string>;
|
|
8
|
+
}
|
|
9
|
+
/** HS256 (by default) JWT auth reading the user id from `claim`. */
|
|
10
|
+
declare class JwtAuth implements AuthAdapter {
|
|
11
|
+
private key;
|
|
12
|
+
private algorithm;
|
|
13
|
+
private claim;
|
|
14
|
+
constructor(secret: string, options?: {
|
|
15
|
+
algorithm?: string;
|
|
16
|
+
claim?: string;
|
|
17
|
+
} | string);
|
|
18
|
+
userIdFromToken(token: string): Promise<string>;
|
|
19
|
+
}
|
|
20
|
+
/** Call the adapter, supporting both sync and async implementations. */
|
|
21
|
+
declare function resolveUserId(auth: AuthAdapter, token: string): Promise<string>;
|
|
22
|
+
interface UserProfile {
|
|
23
|
+
name?: string | null;
|
|
24
|
+
avatar?: string | null;
|
|
25
|
+
}
|
|
26
|
+
interface UserDirectory {
|
|
27
|
+
/** Display info for the ids it knows; unknown ids may be omitted. */
|
|
28
|
+
getProfiles(userIds: readonly string[]): Promise<Record<string, UserProfile>>;
|
|
29
|
+
}
|
|
30
|
+
/** Knows nobody: names fall back to user ids / "Someone". */
|
|
31
|
+
declare class NullUserDirectory implements UserDirectory {
|
|
32
|
+
getProfiles(): Promise<Record<string, UserProfile>>;
|
|
33
|
+
}
|
|
34
|
+
/** In-memory directory (tests, demos). */
|
|
35
|
+
declare class StaticUserDirectory implements UserDirectory {
|
|
36
|
+
profiles: Record<string, UserProfile>;
|
|
37
|
+
constructor(profiles?: Record<string, UserProfile>);
|
|
38
|
+
getProfiles(userIds: readonly string[]): Promise<Record<string, UserProfile>>;
|
|
39
|
+
}
|
|
40
|
+
interface PushSender {
|
|
41
|
+
/** Push to every device of `userId`. Must not throw for "no devices". */
|
|
42
|
+
send(userId: string, title: string, body: string, data: Record<string, unknown>, channel?: string, ttl?: number | null): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
declare class NoopPush implements PushSender {
|
|
45
|
+
send(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/** Optional: backs the `/chats/expo/push/token` routes (`SqlDeviceRegistry` is the SQL implementation). */
|
|
48
|
+
interface DeviceRegistry {
|
|
49
|
+
register(userId: string, payload: Record<string, unknown>): Promise<unknown>;
|
|
50
|
+
remove(userId: string, payload: Record<string, unknown>): Promise<unknown>;
|
|
51
|
+
}
|
|
52
|
+
interface MediaInfo {
|
|
53
|
+
file_url: string;
|
|
54
|
+
file_name: string;
|
|
55
|
+
file_size: number;
|
|
56
|
+
file_type: string;
|
|
57
|
+
media_type: string;
|
|
58
|
+
thumbnail_url?: string | null;
|
|
59
|
+
duration?: number | null;
|
|
60
|
+
}
|
|
61
|
+
interface MediaStorage {
|
|
62
|
+
/** Store the file and return where it lives. Throw `UploadRejected` to reject it with a message. */
|
|
63
|
+
upload(chatId: number, fileName: string, data: Buffer, mediaType: string): Promise<MediaInfo>;
|
|
64
|
+
/** Optional: remove a stored file (unsend, user deletion). Must not throw for files already gone. */
|
|
65
|
+
delete?(fileUrl: string): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/** Throw from `MediaStorage.upload` to refuse a file; the message goes to the client (Python: ValueError). */
|
|
68
|
+
declare class UploadRejected extends Error {
|
|
69
|
+
}
|
|
70
|
+
/** Delete files through `storage.delete` when the storage has it. Never throws; returns how many succeeded. */
|
|
71
|
+
declare function deleteMedia(storage: unknown, ...fileUrls: (string | null | undefined)[]): Promise<number>;
|
|
72
|
+
/** Writes files under `root/chat/<chatId>/<mediaType>/`; `file_url` is `baseUrl` + relative path (serve `root` yourself). */
|
|
73
|
+
declare class LocalDiskStorage implements MediaStorage {
|
|
74
|
+
root: string;
|
|
75
|
+
baseUrl: string;
|
|
76
|
+
constructor(root?: string, baseUrl?: string);
|
|
77
|
+
upload(chatId: number, fileName: string, data: Buffer, mediaType: string): Promise<MediaInfo>;
|
|
78
|
+
/** Local path of a URL this storage produced; null for anything else (incl. `..` tricks). */
|
|
79
|
+
pathFor(fileUrl: string): string | null;
|
|
80
|
+
delete(fileUrl: string): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { type AuthAdapter as A, type DeviceRegistry as D, JwtAuth as J, LocalDiskStorage as L, type MediaInfo as M, NoopPush as N, type PushSender as P, StaticUserDirectory as S, UploadRejected as U, AuthError as a, type MediaStorage as b, NullUserDirectory as c, type UserDirectory as d, type UserProfile as e, deleteMedia as f, resolveUserId as r };
|
package/dist/call.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { C as CallInfo } from './feature-DwKkuOBh.js';
|
|
2
|
+
export { A as ACTIVE_CALL_STATUSES, a as AllowAllCallPolicy, b as CallChatBridge, c as CallConfig, d as CallDecision, e as CallFeature, f as CallFeatureOptions, g as CallHandlers, h as CallLifecycle, i as CallPolicy, j as CallService, k as allow, l as callLogText, m as defaultCallConfig, n as deny, o as endStatus } from './feature-DwKkuOBh.js';
|
|
3
|
+
export { C as CallsTable, c as callDdl } from './models-DTXEX1Q8.js';
|
|
4
|
+
import './hub-CPrWmIvB.js';
|
|
5
|
+
import 'node:http';
|
|
6
|
+
import 'node:stream';
|
|
7
|
+
import 'ws';
|
|
8
|
+
import './adapters-8ztjEYtz.js';
|
|
9
|
+
import './connections-CGEPiZPF.js';
|
|
10
|
+
import 'kysely';
|
|
11
|
+
import './util-B32rIBVA.js';
|
|
12
|
+
|
|
13
|
+
declare function callPayload(event: string, info: CallInfo, extra?: Record<string, unknown>): Record<string, any>;
|
|
14
|
+
/** Legacy: caller-side call_initiated / call_ringing carry the *receiver* in caller_id / caller_name. */
|
|
15
|
+
declare const callerView: (info: CallInfo) => Record<string, unknown>;
|
|
16
|
+
/** Legacy: busy is a call_rejected with call_id null. */
|
|
17
|
+
declare function busyPayload(callerId: string, receiverId: string, callType: string): Record<string, unknown>;
|
|
18
|
+
/** Tagged so clients only tear down call UI for call errors. */
|
|
19
|
+
declare const callError: (error: string, extra?: Record<string, unknown>) => Record<string, unknown>;
|
|
20
|
+
|
|
21
|
+
interface TurnCredentials {
|
|
22
|
+
username: string;
|
|
23
|
+
password: string;
|
|
24
|
+
ttl: number;
|
|
25
|
+
uris: string[];
|
|
26
|
+
}
|
|
27
|
+
/** username = "<expiry>[:<userId>]", password = base64(HMAC-SHA1(secret, username)). */
|
|
28
|
+
declare function turnCredentials(secret: string, uris: readonly string[], ttl?: number, userId?: string | null, now?: number | null): TurnCredentials;
|
|
29
|
+
|
|
30
|
+
declare function uuidv5(name: string, namespace?: string): string;
|
|
31
|
+
/** CallKit UUID for a call: UUIDv5(NAMESPACE_URL, "commskit:call:<callId>"). */
|
|
32
|
+
declare const callkitUuid: (callId: string) => string;
|
|
33
|
+
|
|
34
|
+
export { CallInfo, type TurnCredentials, busyPayload, callError, callPayload, callerView, callkitUuid, turnCredentials, uuidv5 };
|
package/dist/call.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ACTIVE_CALL_STATUSES,
|
|
3
|
+
AllowAllCallPolicy,
|
|
4
|
+
CallFeature,
|
|
5
|
+
CallHandlers,
|
|
6
|
+
CallInfo,
|
|
7
|
+
CallLifecycle,
|
|
8
|
+
CallService,
|
|
9
|
+
allow,
|
|
10
|
+
busyPayload,
|
|
11
|
+
callError,
|
|
12
|
+
callLogText,
|
|
13
|
+
callPayload,
|
|
14
|
+
callerView,
|
|
15
|
+
callkitUuid,
|
|
16
|
+
defaultCallConfig,
|
|
17
|
+
deny,
|
|
18
|
+
endStatus,
|
|
19
|
+
turnCredentials,
|
|
20
|
+
uuidv5
|
|
21
|
+
} from "./chunk-KL4WRZKZ.js";
|
|
22
|
+
import {
|
|
23
|
+
callDdl
|
|
24
|
+
} from "./chunk-XQFQN73U.js";
|
|
25
|
+
import "./chunk-GR4PMGCS.js";
|
|
26
|
+
import "./chunk-BBFVG7QU.js";
|
|
27
|
+
import "./chunk-KLKRK6OG.js";
|
|
28
|
+
import "./chunk-5BJ2SNM5.js";
|
|
29
|
+
export {
|
|
30
|
+
ACTIVE_CALL_STATUSES,
|
|
31
|
+
AllowAllCallPolicy,
|
|
32
|
+
CallFeature,
|
|
33
|
+
CallHandlers,
|
|
34
|
+
CallInfo,
|
|
35
|
+
CallLifecycle,
|
|
36
|
+
CallService,
|
|
37
|
+
allow,
|
|
38
|
+
busyPayload,
|
|
39
|
+
callDdl,
|
|
40
|
+
callError,
|
|
41
|
+
callLogText,
|
|
42
|
+
callPayload,
|
|
43
|
+
callerView,
|
|
44
|
+
callkitUuid,
|
|
45
|
+
defaultCallConfig,
|
|
46
|
+
deny,
|
|
47
|
+
endStatus,
|
|
48
|
+
turnCredentials,
|
|
49
|
+
uuidv5
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=call.js.map
|
package/dist/call.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/chat.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export { A as AllowAllChatPolicy, C as ChatActionError, a as ChatConfig, b as ChatFeature, c as ChatFeatureOptions, d as ChatPolicy, e as ChatRow, f as ChatService, D as DELETED_TYPE, M as MessageDto, g as MessageRow, R as RESERVED_TYPES, h as ReplyPreview, S as SYSTEM_TYPE, i as defaultChatConfig, m as messageDto } from './feature-DQUbnYE-.js';
|
|
2
|
+
import { Generated } from 'kysely';
|
|
3
|
+
import { a as Dialect } from './hub-CPrWmIvB.js';
|
|
4
|
+
import './adapters-8ztjEYtz.js';
|
|
5
|
+
import './connections-CGEPiZPF.js';
|
|
6
|
+
import 'node:http';
|
|
7
|
+
import 'node:stream';
|
|
8
|
+
import 'ws';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Chat tables: same table/column names as the Python `commskit.chat.models` (and matrimonial-backend-v2).
|
|
12
|
+
* No foreign key to a users table, so the kit does not depend on the host's user model.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
type Ts = string | Date;
|
|
16
|
+
interface ChatsTable {
|
|
17
|
+
id: Generated<number>;
|
|
18
|
+
user1_id: string;
|
|
19
|
+
user2_id: string;
|
|
20
|
+
created_at: Ts | null;
|
|
21
|
+
updated_at: Ts | null;
|
|
22
|
+
}
|
|
23
|
+
interface MessagesTable {
|
|
24
|
+
id: Generated<number>;
|
|
25
|
+
chat_id: number;
|
|
26
|
+
sender_id: string;
|
|
27
|
+
content: string | null;
|
|
28
|
+
message_type: string | null;
|
|
29
|
+
file_url: string | null;
|
|
30
|
+
file_name: string | null;
|
|
31
|
+
file_size: number | string | null;
|
|
32
|
+
file_type: string | null;
|
|
33
|
+
thumbnail_url: string | null;
|
|
34
|
+
duration: number | null;
|
|
35
|
+
is_read: boolean | number | null;
|
|
36
|
+
is_delivered: boolean | number | null;
|
|
37
|
+
is_call: boolean | number | null;
|
|
38
|
+
call_id: string | null;
|
|
39
|
+
reply_to_id: number | null;
|
|
40
|
+
created_at: Ts | null;
|
|
41
|
+
updated_at: Ts | null;
|
|
42
|
+
}
|
|
43
|
+
interface MessageHiddenTable {
|
|
44
|
+
id: Generated<number>;
|
|
45
|
+
user_id: string;
|
|
46
|
+
message_id: number;
|
|
47
|
+
created_at: Ts | null;
|
|
48
|
+
}
|
|
49
|
+
interface ChatClearedTable {
|
|
50
|
+
id: Generated<number>;
|
|
51
|
+
user_id: string;
|
|
52
|
+
chat_id: number;
|
|
53
|
+
cleared_at: Ts;
|
|
54
|
+
up_to_message_id: number;
|
|
55
|
+
}
|
|
56
|
+
interface ChatTables {
|
|
57
|
+
chats: ChatsTable;
|
|
58
|
+
messages: MessagesTable;
|
|
59
|
+
comms_message_hidden: MessageHiddenTable;
|
|
60
|
+
comms_chat_cleared: ChatClearedTable;
|
|
61
|
+
}
|
|
62
|
+
declare function chatDdl(dialect: Dialect): string[];
|
|
63
|
+
|
|
64
|
+
export { type ChatClearedTable, type ChatTables, type ChatsTable, type MessageHiddenTable, type MessagesTable, chatDdl };
|
package/dist/chat.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AllowAllChatPolicy,
|
|
3
|
+
ChatActionError,
|
|
4
|
+
ChatFeature,
|
|
5
|
+
ChatService,
|
|
6
|
+
DELETED_TYPE,
|
|
7
|
+
RESERVED_TYPES,
|
|
8
|
+
SYSTEM_TYPE,
|
|
9
|
+
chatDdl,
|
|
10
|
+
defaultChatConfig,
|
|
11
|
+
messageDto
|
|
12
|
+
} from "./chunk-U4Z5INIW.js";
|
|
13
|
+
import "./chunk-XQ6FLRX7.js";
|
|
14
|
+
import "./chunk-GR4PMGCS.js";
|
|
15
|
+
import "./chunk-BBFVG7QU.js";
|
|
16
|
+
import "./chunk-KLKRK6OG.js";
|
|
17
|
+
import "./chunk-5BJ2SNM5.js";
|
|
18
|
+
export {
|
|
19
|
+
AllowAllChatPolicy,
|
|
20
|
+
ChatActionError,
|
|
21
|
+
ChatFeature,
|
|
22
|
+
ChatService,
|
|
23
|
+
DELETED_TYPE,
|
|
24
|
+
RESERVED_TYPES,
|
|
25
|
+
SYSTEM_TYPE,
|
|
26
|
+
chatDdl,
|
|
27
|
+
defaultChatConfig,
|
|
28
|
+
messageDto
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=chat.js.map
|
package/dist/chat.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/core/logger.ts
|
|
2
|
+
var consoleLogger = {
|
|
3
|
+
info: () => void 0,
|
|
4
|
+
warn: (m, ...a) => console.warn(`[commskit] ${m}`, ...a),
|
|
5
|
+
error: (m, ...a) => console.error(`[commskit] ${m}`, ...a)
|
|
6
|
+
};
|
|
7
|
+
var silentLogger = { info() {
|
|
8
|
+
}, warn() {
|
|
9
|
+
}, error() {
|
|
10
|
+
} };
|
|
11
|
+
var current = consoleLogger;
|
|
12
|
+
function setLogger(logger2) {
|
|
13
|
+
current = logger2;
|
|
14
|
+
}
|
|
15
|
+
var logger = {
|
|
16
|
+
info: (m, ...a) => current.info(m, ...a),
|
|
17
|
+
warn: (m, ...a) => current.warn(m, ...a),
|
|
18
|
+
error: (m, ...a) => current.error(m, ...a)
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
silentLogger,
|
|
23
|
+
setLogger,
|
|
24
|
+
logger
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-5BJ2SNM5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/logger.ts"],"sourcesContent":["export interface Logger {\n info(msg: string, ...args: unknown[]): void;\n warn(msg: string, ...args: unknown[]): void;\n error(msg: string, ...args: unknown[]): void;\n}\n\nconst consoleLogger: Logger = {\n info: () => undefined,\n warn: (m, ...a) => console.warn(`[commskit] ${m}`, ...a),\n error: (m, ...a) => console.error(`[commskit] ${m}`, ...a),\n};\n\nexport const silentLogger: Logger = { info() {}, warn() {}, error() {} };\n\nlet current: Logger = consoleLogger;\n\n/** Replace the kit-wide logger (default: warnings and errors to the console). */\nexport function setLogger(logger: Logger): void {\n current = logger;\n}\n\nexport const logger: Logger = {\n info: (m, ...a) => current.info(m, ...a),\n warn: (m, ...a) => current.warn(m, ...a),\n error: (m, ...a) => current.error(m, ...a),\n};\n"],"mappings":";AAMA,IAAM,gBAAwB;AAAA,EAC5B,MAAM,MAAM;AAAA,EACZ,MAAM,CAAC,MAAM,MAAM,QAAQ,KAAK,cAAc,CAAC,IAAI,GAAG,CAAC;AAAA,EACvD,OAAO,CAAC,MAAM,MAAM,QAAQ,MAAM,cAAc,CAAC,IAAI,GAAG,CAAC;AAC3D;AAEO,IAAM,eAAuB,EAAE,OAAO;AAAC,GAAG,OAAO;AAAC,GAAG,QAAQ;AAAC,EAAE;AAEvE,IAAI,UAAkB;AAGf,SAAS,UAAUA,SAAsB;AAC9C,YAAUA;AACZ;AAEO,IAAM,SAAiB;AAAA,EAC5B,MAAM,CAAC,MAAM,MAAM,QAAQ,KAAK,GAAG,GAAG,CAAC;AAAA,EACvC,MAAM,CAAC,MAAM,MAAM,QAAQ,KAAK,GAAG,GAAG,CAAC;AAAA,EACvC,OAAO,CAAC,MAAM,MAAM,QAAQ,MAAM,GAAG,GAAG,CAAC;AAC3C;","names":["logger"]}
|