@relaya-chat/core 1.0.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/LICENSE +21 -0
- package/dist/apiClient.d.ts +246 -0
- package/dist/apiClient.js +241 -0
- package/dist/chatConnection.d.ts +84 -0
- package/dist/chatConnection.js +182 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +9 -0
- package/dist/messageUtils.d.ts +106 -0
- package/dist/messageUtils.js +221 -0
- package/dist/types.d.ts +285 -0
- package/dist/types.js +17 -0
- package/package.json +37 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for Relaya chat system
|
|
3
|
+
*/
|
|
4
|
+
export interface Station {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
slug: string;
|
|
8
|
+
description: string | null;
|
|
9
|
+
is_active: boolean;
|
|
10
|
+
created_at: Date;
|
|
11
|
+
updated_at: Date;
|
|
12
|
+
/** How long (ms) a user stays in the online list after their WS closes. Default 120 000. */
|
|
13
|
+
presence_grace_period_ms: number;
|
|
14
|
+
}
|
|
15
|
+
export interface User {
|
|
16
|
+
id: string;
|
|
17
|
+
display_name: string;
|
|
18
|
+
email: string | null;
|
|
19
|
+
identity_hash: string;
|
|
20
|
+
avatar_url: string | null;
|
|
21
|
+
is_active: boolean;
|
|
22
|
+
created_at: Date;
|
|
23
|
+
updated_at: Date;
|
|
24
|
+
}
|
|
25
|
+
export interface StationMembership {
|
|
26
|
+
id: string;
|
|
27
|
+
station_id: string;
|
|
28
|
+
user_id: string;
|
|
29
|
+
joined_at: Date;
|
|
30
|
+
is_active: boolean;
|
|
31
|
+
chat_name?: string | null;
|
|
32
|
+
}
|
|
33
|
+
export interface Role {
|
|
34
|
+
id: string;
|
|
35
|
+
station_id: string;
|
|
36
|
+
name: string;
|
|
37
|
+
description: string | null;
|
|
38
|
+
priority: number;
|
|
39
|
+
is_default: boolean;
|
|
40
|
+
created_at: Date;
|
|
41
|
+
}
|
|
42
|
+
export interface RolePermission {
|
|
43
|
+
id: string;
|
|
44
|
+
role_id: string;
|
|
45
|
+
permission: string;
|
|
46
|
+
}
|
|
47
|
+
export interface MembershipRole {
|
|
48
|
+
id: string;
|
|
49
|
+
membership_id: string;
|
|
50
|
+
role_id: string;
|
|
51
|
+
assigned_at: Date;
|
|
52
|
+
assigned_by: string | null;
|
|
53
|
+
}
|
|
54
|
+
export interface Message {
|
|
55
|
+
id: string;
|
|
56
|
+
station_id: string;
|
|
57
|
+
user_id: string;
|
|
58
|
+
content: string;
|
|
59
|
+
is_deleted: boolean;
|
|
60
|
+
deleted_by: string | null;
|
|
61
|
+
deleted_at: Date | null;
|
|
62
|
+
edited_at?: Date | null;
|
|
63
|
+
edit_count?: number;
|
|
64
|
+
reply_to_message_id?: string | null;
|
|
65
|
+
reply_author_name?: string | null;
|
|
66
|
+
reply_excerpt?: string | null;
|
|
67
|
+
created_at: Date;
|
|
68
|
+
}
|
|
69
|
+
export interface MessageReport {
|
|
70
|
+
id: string;
|
|
71
|
+
station_id: string;
|
|
72
|
+
message_id: string;
|
|
73
|
+
reporter_id: string;
|
|
74
|
+
reason: string;
|
|
75
|
+
details: string | null;
|
|
76
|
+
status: 'pending' | 'reviewed' | 'dismissed';
|
|
77
|
+
reviewed_by: string | null;
|
|
78
|
+
reviewed_at: Date | null;
|
|
79
|
+
created_at: Date;
|
|
80
|
+
}
|
|
81
|
+
export interface Ban {
|
|
82
|
+
id: string;
|
|
83
|
+
station_id: string;
|
|
84
|
+
user_id: string;
|
|
85
|
+
banned_by: string;
|
|
86
|
+
reason: string | null;
|
|
87
|
+
expires_at: Date | null;
|
|
88
|
+
is_active: boolean;
|
|
89
|
+
created_at: Date;
|
|
90
|
+
lifted_at: Date | null;
|
|
91
|
+
lifted_by: string | null;
|
|
92
|
+
}
|
|
93
|
+
export interface MagicLinkToken {
|
|
94
|
+
id: string;
|
|
95
|
+
station_id: string;
|
|
96
|
+
email: string;
|
|
97
|
+
token_hash: string;
|
|
98
|
+
expires_at: Date;
|
|
99
|
+
consumed_at: Date | null;
|
|
100
|
+
created_at: Date;
|
|
101
|
+
attempts?: number;
|
|
102
|
+
}
|
|
103
|
+
export declare const PERMISSIONS: {
|
|
104
|
+
readonly READ: "chat.read";
|
|
105
|
+
readonly POST: "chat.post";
|
|
106
|
+
readonly EDIT_OWN: "chat.edit_own";
|
|
107
|
+
readonly DELETE_OWN: "chat.delete_own";
|
|
108
|
+
readonly DELETE_ANY: "chat.delete_any";
|
|
109
|
+
readonly REPORT: "chat.report";
|
|
110
|
+
readonly BAN_USER: "chat.ban_user";
|
|
111
|
+
readonly MANAGE_ROLES: "chat.manage_roles";
|
|
112
|
+
readonly MENTION_CHANNEL: "chat.mention_channel";
|
|
113
|
+
};
|
|
114
|
+
export type Permission = typeof PERMISSIONS[keyof typeof PERMISSIONS];
|
|
115
|
+
export interface UserWithPermissions extends User {
|
|
116
|
+
permissions: Permission[];
|
|
117
|
+
roles: Role[];
|
|
118
|
+
maxPriority: number;
|
|
119
|
+
chatName: string | null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* User information for client-side directory.
|
|
123
|
+
* Used to resolve user data for messages without JOINs.
|
|
124
|
+
*/
|
|
125
|
+
export interface UserInfo {
|
|
126
|
+
id: string;
|
|
127
|
+
displayName: string;
|
|
128
|
+
avatarUrl: string | null;
|
|
129
|
+
/** True when the user has an elevated (moderator/admin) role at this station. */
|
|
130
|
+
isModerator?: boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Temporal tracking for avatar changes.
|
|
134
|
+
* Used to show historical avatars within a session.
|
|
135
|
+
*/
|
|
136
|
+
export interface AvatarChange {
|
|
137
|
+
url: string | null;
|
|
138
|
+
changedAt: Date;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* DEPRECATED: MessageWithAuthor is being phased out.
|
|
142
|
+
* Messages now contain only user_id; clients resolve user data from directory.
|
|
143
|
+
* Kept temporarily for compatibility during migration.
|
|
144
|
+
*/
|
|
145
|
+
export interface MessageWithAuthor extends Message {
|
|
146
|
+
author: {
|
|
147
|
+
id: string;
|
|
148
|
+
display_name: string;
|
|
149
|
+
avatar_url: string | null;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
export interface StickerManifestEntry {
|
|
153
|
+
filename: string;
|
|
154
|
+
shortcode: string | null;
|
|
155
|
+
order: number;
|
|
156
|
+
}
|
|
157
|
+
export interface StickerListing extends StickerManifestEntry {
|
|
158
|
+
url: string;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Messages sent from the client to the server.
|
|
162
|
+
*
|
|
163
|
+
* The protocol is intentionally narrow:
|
|
164
|
+
* - message:send — post a new chat message (with optional reply data)
|
|
165
|
+
* - pong — heartbeat response to a server ping
|
|
166
|
+
*/
|
|
167
|
+
export type WsClientMessage = {
|
|
168
|
+
type: 'message:send';
|
|
169
|
+
content: string;
|
|
170
|
+
clientId: string;
|
|
171
|
+
replyToMessageId?: string;
|
|
172
|
+
replyAuthorName?: string;
|
|
173
|
+
replyExcerpt?: string;
|
|
174
|
+
} | {
|
|
175
|
+
type: 'pong';
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Messages sent from the server to the client.
|
|
179
|
+
*
|
|
180
|
+
* - auth:success — connection accepted; includes user identity + permissions + user directory
|
|
181
|
+
* - message:broadcast — a message was persisted and should be rendered
|
|
182
|
+
* - presence:update — number of unique online users changed
|
|
183
|
+
* - user:update — a user's display name or avatar changed
|
|
184
|
+
* - ping — heartbeat probe; client must reply with pong
|
|
185
|
+
* - error — a client-triggered operation failed
|
|
186
|
+
*/
|
|
187
|
+
export type WsServerMessage = {
|
|
188
|
+
type: 'auth:success';
|
|
189
|
+
userId: string | null;
|
|
190
|
+
stationId: string;
|
|
191
|
+
displayName: string;
|
|
192
|
+
chatName: string | null;
|
|
193
|
+
permissions: Permission[];
|
|
194
|
+
users: UserInfo[];
|
|
195
|
+
} | {
|
|
196
|
+
type: 'message:broadcast';
|
|
197
|
+
message: Message;
|
|
198
|
+
clientId?: string;
|
|
199
|
+
} | {
|
|
200
|
+
type: 'presence:update';
|
|
201
|
+
userCount: number;
|
|
202
|
+
totalCount: number;
|
|
203
|
+
users: Array<{
|
|
204
|
+
id: string;
|
|
205
|
+
displayName: string;
|
|
206
|
+
avatarUrl: string | null;
|
|
207
|
+
}>;
|
|
208
|
+
} | {
|
|
209
|
+
type: 'user:update';
|
|
210
|
+
userId: string;
|
|
211
|
+
updates: {
|
|
212
|
+
displayName?: string;
|
|
213
|
+
avatarUrl?: string | null;
|
|
214
|
+
};
|
|
215
|
+
timestamp: string;
|
|
216
|
+
} | {
|
|
217
|
+
type: 'message:deleted';
|
|
218
|
+
messageId: string;
|
|
219
|
+
deletedBy: string;
|
|
220
|
+
} | {
|
|
221
|
+
type: 'message:edited';
|
|
222
|
+
message: Message;
|
|
223
|
+
} | {
|
|
224
|
+
type: 'mention:notification';
|
|
225
|
+
messageId: string;
|
|
226
|
+
mentionedBy: {
|
|
227
|
+
id: string;
|
|
228
|
+
displayName: string;
|
|
229
|
+
};
|
|
230
|
+
excerpt: string;
|
|
231
|
+
} | {
|
|
232
|
+
type: 'channel:notification';
|
|
233
|
+
messageId: string;
|
|
234
|
+
mentionedBy: {
|
|
235
|
+
id: string;
|
|
236
|
+
displayName: string;
|
|
237
|
+
};
|
|
238
|
+
excerpt: string;
|
|
239
|
+
} | {
|
|
240
|
+
type: 'ping';
|
|
241
|
+
} | {
|
|
242
|
+
type: 'error';
|
|
243
|
+
code: string;
|
|
244
|
+
message: string;
|
|
245
|
+
} | {
|
|
246
|
+
type: 'stickers:updated';
|
|
247
|
+
stationId: string;
|
|
248
|
+
} | {
|
|
249
|
+
type: 'force_logout';
|
|
250
|
+
reason: string;
|
|
251
|
+
};
|
|
252
|
+
export interface CreateUserParams {
|
|
253
|
+
display_name: string;
|
|
254
|
+
email: string;
|
|
255
|
+
identity_hash: string;
|
|
256
|
+
avatar_url?: string | null;
|
|
257
|
+
}
|
|
258
|
+
export interface CreateMessageParams {
|
|
259
|
+
station_id: string;
|
|
260
|
+
user_id: string;
|
|
261
|
+
content: string;
|
|
262
|
+
reply_to_message_id?: string;
|
|
263
|
+
reply_author_name?: string;
|
|
264
|
+
reply_excerpt?: string;
|
|
265
|
+
}
|
|
266
|
+
export interface CreateBanParams {
|
|
267
|
+
station_id: string;
|
|
268
|
+
user_id: string;
|
|
269
|
+
banned_by: string;
|
|
270
|
+
reason?: string;
|
|
271
|
+
expires_at?: Date;
|
|
272
|
+
}
|
|
273
|
+
export interface CreateReportParams {
|
|
274
|
+
station_id: string;
|
|
275
|
+
message_id: string;
|
|
276
|
+
reporter_id: string;
|
|
277
|
+
reason: string;
|
|
278
|
+
details?: string;
|
|
279
|
+
}
|
|
280
|
+
export interface CreateMagicLinkParams {
|
|
281
|
+
station_id: string;
|
|
282
|
+
email: string;
|
|
283
|
+
token_hash: string;
|
|
284
|
+
expires_at: Date;
|
|
285
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) 2026 JAB Ventures, Inc. MIT License.
|
|
2
|
+
// See LICENSE file at https://github.com/relaya-chat/sdk
|
|
3
|
+
/**
|
|
4
|
+
* Shared types for Relaya chat system
|
|
5
|
+
*/
|
|
6
|
+
// ==================== PERMISSIONS ====================
|
|
7
|
+
export const PERMISSIONS = {
|
|
8
|
+
READ: 'chat.read',
|
|
9
|
+
POST: 'chat.post',
|
|
10
|
+
EDIT_OWN: 'chat.edit_own',
|
|
11
|
+
DELETE_OWN: 'chat.delete_own',
|
|
12
|
+
DELETE_ANY: 'chat.delete_any',
|
|
13
|
+
REPORT: 'chat.report',
|
|
14
|
+
BAN_USER: 'chat.ban_user',
|
|
15
|
+
MANAGE_ROLES: 'chat.manage_roles',
|
|
16
|
+
MENTION_CHANNEL: 'chat.mention_channel',
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@relaya-chat/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Real-time community chat primitives for Relaya — TypeScript types, REST API client, WebSocket connection manager. Connects to the Relaya SaaS at api.relaya.chat. Works in browser and React Native.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"chat", "real-time", "realtime", "community-chat", "websocket",
|
|
8
|
+
"api-client", "typescript", "react-native", "moderation"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/relaya-chat/sdk.git",
|
|
14
|
+
"directory": "packages/core"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://relaya.chat",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"lint": "eslint src --ext .ts"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.0.0",
|
|
35
|
+
"vitest": "^4.1.2"
|
|
36
|
+
}
|
|
37
|
+
}
|