@rivium/chat 0.1.2 → 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 CHANGED
@@ -95,6 +95,8 @@ app.get('/chat-token', requireLogin, async (req, res) => {
95
95
  ```typescript
96
96
  riviumChat.users.createToken({ userId, info?, ttl? }) // 1 h default, 24 h max
97
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
98
100
  ```
99
101
 
100
102
  `revokeTokens` invalidates every token issued to that user so far; it takes
@@ -113,6 +115,8 @@ riviumChat.rooms.addParticipant(roomId, options) // Add participant to room
113
115
  riviumChat.rooms.removeParticipant(roomId, userId) // Remove participant (idempotent)
114
116
  riviumChat.rooms.delete(roomId) // Permanently delete a room
115
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
116
120
  ```
117
121
 
118
122
  ### Messages
@@ -182,6 +186,31 @@ await riviumChat.webhooks.setPushTemplates({
182
186
  });
183
187
  ```
184
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
+
185
214
  ## Links
186
215
 
187
216
  - [Rivium Chat](https://rivium.co/cloud/rivium-chat) - Learn more about Rivium Chat
@@ -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
  }
@@ -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;
@@ -1,5 +1,11 @@
1
1
  import { HttpClient } from '../client';
2
- import { CreateUserTokenOptions, UserToken, RevokeTokensResult } from '../types';
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
+ };
3
9
  /**
4
10
  * User tokens — how your app proves **who** the user is.
5
11
  *
@@ -28,4 +34,15 @@ export declare class Users {
28
34
  * within seconds, for REST and realtime alike.
29
35
  */
30
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>;
31
48
  }
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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
+ }
4
15
  /**
5
16
  * User tokens — how your app proves **who** the user is.
6
17
  *
@@ -34,5 +45,20 @@ class Users {
34
45
  async revokeTokens(userId) {
35
46
  return this.client.post(`/api/v1/users/${encodeURIComponent(userId)}/revoke-tokens`);
36
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
+ }
37
63
  }
38
64
  exports.Users = Users;
package/dist/types.d.ts CHANGED
@@ -179,3 +179,28 @@ export interface RevokeTokensResult {
179
179
  /** Tokens issued at or before this moment are no longer accepted. */
180
180
  revokedBefore: string;
181
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivium/chat",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "RiviumChat Node.js SDK — server-side chat rooms, messages, reactions, pins, and webhooks",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",