@rivium/chat 0.1.1 → 0.1.3
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 +51 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/modules/rooms.d.ts +12 -1
- package/dist/modules/rooms.js +16 -0
- package/dist/modules/users.d.ts +48 -0
- package/dist/modules/users.js +64 -0
- package/dist/types.d.ts +44 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,30 @@ const summary = await riviumChat.rooms.getUnreadSummary('user-1');
|
|
|
79
79
|
|
|
80
80
|
## API Reference
|
|
81
81
|
|
|
82
|
+
### Users — verified identity (recommended)
|
|
83
|
+
|
|
84
|
+
Your API key ships inside every app, so it cannot prove who a user is. Mint a
|
|
85
|
+
short-lived token here and hand it to the client SDK's `tokenProvider`:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// Express example — your own login protects the route
|
|
89
|
+
app.get('/chat-token', requireLogin, async (req, res) => {
|
|
90
|
+
const { token } = await riviumChat.users.createToken({ userId: req.user.id });
|
|
91
|
+
res.json({ token });
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
riviumChat.users.createToken({ userId, info?, ttl? }) // 1 h default, 24 h max
|
|
97
|
+
riviumChat.users.revokeTokens(userId) // on logout, password change, ban
|
|
98
|
+
riviumChat.users.getNotificationSettings(userId) // App-wide push settings
|
|
99
|
+
riviumChat.users.updateNotificationSettings(userId, options) // Turn chat pushes off, mentions only, mute
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`revokeTokens` invalidates every token issued to that user so far; it takes
|
|
103
|
+
effect within about 15 seconds across servers. Client SDKs then ask your
|
|
104
|
+
endpoint for a new token, so a signed-out user gets nothing.
|
|
105
|
+
|
|
82
106
|
### Rooms
|
|
83
107
|
|
|
84
108
|
```typescript
|
|
@@ -91,6 +115,8 @@ riviumChat.rooms.addParticipant(roomId, options) // Add participant to room
|
|
|
91
115
|
riviumChat.rooms.removeParticipant(roomId, userId) // Remove participant (idempotent)
|
|
92
116
|
riviumChat.rooms.delete(roomId) // Permanently delete a room
|
|
93
117
|
riviumChat.rooms.getUnreadSummary(userId) // Get unread counts
|
|
118
|
+
riviumChat.rooms.getNotificationSettings(roomId, userId) // A user's push settings for a room
|
|
119
|
+
riviumChat.rooms.updateNotificationSettings(roomId, userId, options) // Mute a room or mentions only
|
|
94
120
|
```
|
|
95
121
|
|
|
96
122
|
### Messages
|
|
@@ -160,6 +186,31 @@ await riviumChat.webhooks.setPushTemplates({
|
|
|
160
186
|
});
|
|
161
187
|
```
|
|
162
188
|
|
|
189
|
+
### Notification settings
|
|
190
|
+
|
|
191
|
+
Let each user decide which chat pushes they get. Nothing changes until you set something.
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// Turn off chat pushes for a user across your app
|
|
195
|
+
await riviumChat.users.updateNotificationSettings('user-1', { pushLevel: 'none' });
|
|
196
|
+
|
|
197
|
+
// Only push when mentioned, and no reaction pushes
|
|
198
|
+
await riviumChat.users.updateNotificationSettings('user-1', {
|
|
199
|
+
pushLevel: 'mentions',
|
|
200
|
+
disabledEvents: ['reaction'],
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Mute one room for 8 hours, then unmute
|
|
204
|
+
await riviumChat.rooms.updateNotificationSettings(roomId, 'user-1', {
|
|
205
|
+
mutedUntil: new Date(Date.now() + 8 * 3600_000),
|
|
206
|
+
});
|
|
207
|
+
await riviumChat.rooms.updateNotificationSettings(roomId, 'user-1', { mutedUntil: null });
|
|
208
|
+
|
|
209
|
+
await riviumChat.users.getNotificationSettings('user-1');
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`pushLevel` is `all` (default), `mentions` or `none`. App-wide and room settings both apply: a push is sent only if neither blocks it.
|
|
213
|
+
|
|
163
214
|
## Links
|
|
164
215
|
|
|
165
216
|
- [Rivium Chat](https://rivium.co/cloud/rivium-chat) - Learn more about Rivium Chat
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Reactions } from './modules/reactions';
|
|
|
4
4
|
import { Pins } from './modules/pins';
|
|
5
5
|
import { Webhooks } from './modules/webhooks';
|
|
6
6
|
import { Tokens } from './modules/tokens';
|
|
7
|
+
import { Users } from './modules/users';
|
|
7
8
|
import { RiviumChatConfig } from './types';
|
|
8
9
|
export declare class RiviumChat {
|
|
9
10
|
private client;
|
|
@@ -19,6 +20,8 @@ export declare class RiviumChat {
|
|
|
19
20
|
webhooks: Webhooks;
|
|
20
21
|
/** Centrifugo connection tokens */
|
|
21
22
|
tokens: Tokens;
|
|
23
|
+
/** User tokens — verified identity for your client apps */
|
|
24
|
+
users: Users;
|
|
22
25
|
constructor(config: RiviumChatConfig);
|
|
23
26
|
}
|
|
24
27
|
export { RiviumChatError } from './client';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ const reactions_1 = require("./modules/reactions");
|
|
|
22
22
|
const pins_1 = require("./modules/pins");
|
|
23
23
|
const webhooks_1 = require("./modules/webhooks");
|
|
24
24
|
const tokens_1 = require("./modules/tokens");
|
|
25
|
+
const users_1 = require("./modules/users");
|
|
25
26
|
class RiviumChat {
|
|
26
27
|
constructor(config) {
|
|
27
28
|
this.client = new client_1.HttpClient(config);
|
|
@@ -31,6 +32,7 @@ class RiviumChat {
|
|
|
31
32
|
this.pins = new pins_1.Pins(this.client);
|
|
32
33
|
this.webhooks = new webhooks_1.Webhooks(this.client);
|
|
33
34
|
this.tokens = new tokens_1.Tokens(this.client);
|
|
35
|
+
this.users = new users_1.Users(this.client);
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
exports.RiviumChat = RiviumChat;
|
package/dist/modules/rooms.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpClient } from '../client';
|
|
2
|
-
import { Room, CreateRoomOptions, AddParticipantOptions, Participant, UnreadSummary } from '../types';
|
|
2
|
+
import { Room, CreateRoomOptions, AddParticipantOptions, Participant, UnreadSummary, NotificationSettings, UpdateNotificationSettingsOptions } from '../types';
|
|
3
3
|
export declare class Rooms {
|
|
4
4
|
private client;
|
|
5
5
|
constructor(client: HttpClient);
|
|
@@ -23,4 +23,15 @@ export declare class Rooms {
|
|
|
23
23
|
delete(roomId: string): Promise<{
|
|
24
24
|
success: boolean;
|
|
25
25
|
}>;
|
|
26
|
+
/** A participant's push settings for one room. */
|
|
27
|
+
getNotificationSettings(roomId: string, userId: string): Promise<NotificationSettings>;
|
|
28
|
+
/**
|
|
29
|
+
* Changes a participant's push settings for one room: mute it, or only
|
|
30
|
+
* notify on mentions. The user must be in the room.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* await chat.rooms.updateNotificationSettings(roomId, 'user-1', { pushLevel: 'mentions' });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
updateNotificationSettings(roomId: string, userId: string, settings: UpdateNotificationSettingsOptions): Promise<NotificationSettings>;
|
|
26
37
|
}
|
package/dist/modules/rooms.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Rooms = void 0;
|
|
4
|
+
const users_1 = require("./users");
|
|
4
5
|
class Rooms {
|
|
5
6
|
constructor(client) {
|
|
6
7
|
this.client = client;
|
|
@@ -41,5 +42,20 @@ class Rooms {
|
|
|
41
42
|
async delete(roomId) {
|
|
42
43
|
return this.client.delete(`/api/v1/rooms/${roomId}`);
|
|
43
44
|
}
|
|
45
|
+
/** A participant's push settings for one room. */
|
|
46
|
+
async getNotificationSettings(roomId, userId) {
|
|
47
|
+
return this.client.get(`/api/v1/rooms/${roomId}/notification-settings`, { userId });
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Changes a participant's push settings for one room: mute it, or only
|
|
51
|
+
* notify on mentions. The user must be in the room.
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* await chat.rooms.updateNotificationSettings(roomId, 'user-1', { pushLevel: 'mentions' });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
async updateNotificationSettings(roomId, userId, settings) {
|
|
58
|
+
return this.client.put(`/api/v1/rooms/${roomId}/notification-settings`, (0, users_1.settingsBody)(userId, settings));
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
exports.Rooms = Rooms;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { HttpClient } from '../client';
|
|
2
|
+
import { CreateUserTokenOptions, UserToken, RevokeTokensResult, NotificationSettings, UpdateNotificationSettingsOptions } from '../types';
|
|
3
|
+
export declare function settingsBody(userId: string, settings: UpdateNotificationSettingsOptions): {
|
|
4
|
+
mutedUntil?: string | null | undefined;
|
|
5
|
+
pushLevel?: import("../types").PushLevel;
|
|
6
|
+
disabledEvents?: string[];
|
|
7
|
+
userId: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* User tokens — how your app proves **who** the user is.
|
|
11
|
+
*
|
|
12
|
+
* Your API key ships inside every app, so it cannot identify a user. Mint a
|
|
13
|
+
* short-lived token here (server-side, with your server secret) and hand it to
|
|
14
|
+
* the client SDK's `tokenProvider`. The client SDKs refresh it automatically.
|
|
15
|
+
*/
|
|
16
|
+
export declare class Users {
|
|
17
|
+
private client;
|
|
18
|
+
constructor(client: HttpClient);
|
|
19
|
+
/**
|
|
20
|
+
* Creates a token for one of your users. Expires in 1 hour by default
|
|
21
|
+
* (`ttl` seconds, max 24 hours).
|
|
22
|
+
*
|
|
23
|
+
* ```ts
|
|
24
|
+
* app.get('/chat-token', requireLogin, async (req, res) => {
|
|
25
|
+
* const { token } = await chat.users.createToken({ userId: req.user.id });
|
|
26
|
+
* res.json({ token });
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
createToken(options: CreateUserTokenOptions): Promise<UserToken>;
|
|
31
|
+
/**
|
|
32
|
+
* Invalidates every token issued to this user so far — call it on logout,
|
|
33
|
+
* password change or ban. Tokens already in the user's hands stop working
|
|
34
|
+
* within seconds, for REST and realtime alike.
|
|
35
|
+
*/
|
|
36
|
+
revokeTokens(userId: string): Promise<RevokeTokensResult>;
|
|
37
|
+
/** A user's chat push settings for your whole app. */
|
|
38
|
+
getNotificationSettings(userId: string): Promise<NotificationSettings>;
|
|
39
|
+
/**
|
|
40
|
+
* Changes a user's chat push settings for your whole app, e.g. to turn chat
|
|
41
|
+
* pushes off from your own settings screen.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* await chat.users.updateNotificationSettings('user-1', { pushLevel: 'none' });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
updateNotificationSettings(userId: string, settings: UpdateNotificationSettingsOptions): Promise<NotificationSettings>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Users = void 0;
|
|
4
|
+
exports.settingsBody = settingsBody;
|
|
5
|
+
function settingsBody(userId, settings) {
|
|
6
|
+
const { mutedUntil, ...rest } = settings;
|
|
7
|
+
return {
|
|
8
|
+
userId,
|
|
9
|
+
...rest,
|
|
10
|
+
...(mutedUntil !== undefined && {
|
|
11
|
+
mutedUntil: mutedUntil instanceof Date ? mutedUntil.toISOString() : mutedUntil,
|
|
12
|
+
}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* User tokens — how your app proves **who** the user is.
|
|
17
|
+
*
|
|
18
|
+
* Your API key ships inside every app, so it cannot identify a user. Mint a
|
|
19
|
+
* short-lived token here (server-side, with your server secret) and hand it to
|
|
20
|
+
* the client SDK's `tokenProvider`. The client SDKs refresh it automatically.
|
|
21
|
+
*/
|
|
22
|
+
class Users {
|
|
23
|
+
constructor(client) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a token for one of your users. Expires in 1 hour by default
|
|
28
|
+
* (`ttl` seconds, max 24 hours).
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* app.get('/chat-token', requireLogin, async (req, res) => {
|
|
32
|
+
* const { token } = await chat.users.createToken({ userId: req.user.id });
|
|
33
|
+
* res.json({ token });
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
async createToken(options) {
|
|
38
|
+
return this.client.post('/api/v1/users/token', options);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Invalidates every token issued to this user so far — call it on logout,
|
|
42
|
+
* password change or ban. Tokens already in the user's hands stop working
|
|
43
|
+
* within seconds, for REST and realtime alike.
|
|
44
|
+
*/
|
|
45
|
+
async revokeTokens(userId) {
|
|
46
|
+
return this.client.post(`/api/v1/users/${encodeURIComponent(userId)}/revoke-tokens`);
|
|
47
|
+
}
|
|
48
|
+
/** A user's chat push settings for your whole app. */
|
|
49
|
+
async getNotificationSettings(userId) {
|
|
50
|
+
return this.client.get('/api/v1/users/notification-settings', { userId });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Changes a user's chat push settings for your whole app, e.g. to turn chat
|
|
54
|
+
* pushes off from your own settings screen.
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* await chat.users.updateNotificationSettings('user-1', { pushLevel: 'none' });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
async updateNotificationSettings(userId, settings) {
|
|
61
|
+
return this.client.put('/api/v1/users/notification-settings', settingsBody(userId, settings));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.Users = Users;
|
package/dist/types.d.ts
CHANGED
|
@@ -160,3 +160,47 @@ export interface GetTokenOptions {
|
|
|
160
160
|
userId: string;
|
|
161
161
|
info?: Record<string, any>;
|
|
162
162
|
}
|
|
163
|
+
export interface CreateUserTokenOptions {
|
|
164
|
+
/** Your own id for the user the token is for. */
|
|
165
|
+
userId: string;
|
|
166
|
+
/** Public connection info (e.g. displayName) visible to the realtime layer. */
|
|
167
|
+
info?: Record<string, any>;
|
|
168
|
+
/** Lifetime in seconds. Default 3600 (1 h), max 86400 (24 h). */
|
|
169
|
+
ttl?: number;
|
|
170
|
+
}
|
|
171
|
+
export interface UserToken {
|
|
172
|
+
/** Hand this to the client SDK's tokenProvider. */
|
|
173
|
+
token: string;
|
|
174
|
+
/** ISO timestamp; the client SDKs refresh shortly before it. */
|
|
175
|
+
expiresAt: string;
|
|
176
|
+
userId: string;
|
|
177
|
+
}
|
|
178
|
+
export interface RevokeTokensResult {
|
|
179
|
+
/** Tokens issued at or before this moment are no longer accepted. */
|
|
180
|
+
revokedBefore: string;
|
|
181
|
+
}
|
|
182
|
+
/** `all` (default), `mentions` (only when mentioned) or `none` (no chat pushes). */
|
|
183
|
+
export type PushLevel = 'all' | 'mentions' | 'none';
|
|
184
|
+
export interface NotificationSettings {
|
|
185
|
+
userId: string;
|
|
186
|
+
/** `app` for the user's app-wide settings, `room` for one room. */
|
|
187
|
+
scope: 'app' | 'room';
|
|
188
|
+
roomId?: string;
|
|
189
|
+
pushLevel: PushLevel;
|
|
190
|
+
/** ISO timestamp; no chat pushes until then. */
|
|
191
|
+
mutedUntil: string | null;
|
|
192
|
+
/** Push event types turned off, e.g. `reaction`. */
|
|
193
|
+
disabledEvents: string[];
|
|
194
|
+
updatedAt: string | null;
|
|
195
|
+
}
|
|
196
|
+
/** Only the fields you pass are changed. */
|
|
197
|
+
export interface UpdateNotificationSettingsOptions {
|
|
198
|
+
pushLevel?: PushLevel;
|
|
199
|
+
/** A Date or ISO string to mute until; `null` unmutes. */
|
|
200
|
+
mutedUntil?: Date | string | null;
|
|
201
|
+
/**
|
|
202
|
+
* Event types to turn off: new_message, file_shared, mention, reaction,
|
|
203
|
+
* message_pinned, room_created, participant_joined, participant_removed.
|
|
204
|
+
*/
|
|
205
|
+
disabledEvents?: string[];
|
|
206
|
+
}
|