@wildix/xbees-conversations-utils 2.0.0 → 2.0.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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeStreamChannelMembersUserPresencesToMap = exports.normalizeStreamChannelsUserPresencesToMap = exports.normalizeStreamChannelsUsers = exports.normalizeStreamChannelsUsersToMap = exports.normalizeStreamChannelUsersToMap = exports.normalizeStreamChannelUsers = exports.normalizeStreamChannelOwnReadIndicators = exports.normalizeStreamChannelReadIndicators = exports.normalizeStreamChannelReadIndicator = exports.localizeStreamChannel = exports.localizeStreamChannelsMembersToMapByChannelId = exports.localizeStreamChannelMembers = exports.localizeStreamMember = exports.normalizeStreamMember = exports.normalizeStreamChannel = exports.localizeStreamMessage = exports.normalizeStreamMessage = exports.normalizeStreamReaction = exports.localizeStreamUser = exports.normalizeStreamUser = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
4
|
const xbees_conversations_client_1 = require("@wildix/xbees-conversations-client");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
6
|
function normalizeStreamUser(streamUser) {
|
|
7
7
|
return {
|
|
8
8
|
id: streamUser.id,
|
|
@@ -60,7 +60,9 @@ function normalizeStreamMessage(streamMessage, channelId) {
|
|
|
60
60
|
latestReactions,
|
|
61
61
|
reactionCounts: reaction_counts || {},
|
|
62
62
|
createdAt: streamMessage.created_at,
|
|
63
|
-
updatedAt: streamMessage.updated_at !== streamMessage.created_at && streamMessage.updated_at
|
|
63
|
+
updatedAt: streamMessage.updated_at !== streamMessage.created_at && streamMessage.updated_at
|
|
64
|
+
? streamMessage.updated_at
|
|
65
|
+
: undefined,
|
|
64
66
|
user,
|
|
65
67
|
quote,
|
|
66
68
|
forward,
|
|
@@ -80,9 +82,13 @@ function localizeStreamMessage(streamMessage, channelId, userId) {
|
|
|
80
82
|
const normalizedMessage = normalizeStreamMessage(streamMessage, channelId);
|
|
81
83
|
const createdAt = new Date(normalizedMessage.createdAt);
|
|
82
84
|
const updatedAt = normalizedMessage.updatedAt ? new Date(normalizedMessage.updatedAt) : undefined;
|
|
83
|
-
const latestReactions = streamMessage.latest_reactions
|
|
85
|
+
const latestReactions = streamMessage.latest_reactions
|
|
86
|
+
? streamMessage.latest_reactions.map(normalizeStreamReaction)
|
|
87
|
+
: [];
|
|
84
88
|
const ownReactionsFromLatestReactions = latestReactions.filter((r) => userId === r.userId);
|
|
85
|
-
const ownReactions = streamMessage.own_reactions
|
|
89
|
+
const ownReactions = streamMessage.own_reactions
|
|
90
|
+
? streamMessage.own_reactions.map(normalizeStreamReaction).filter((r) => userId === r.userId)
|
|
91
|
+
: [];
|
|
86
92
|
ownReactionsFromLatestReactions.forEach((reaction) => {
|
|
87
93
|
if (!ownReactions.find((ownReaction) => ownReaction.type === reaction.type)) {
|
|
88
94
|
ownReactions.push(reaction);
|
|
@@ -112,7 +118,7 @@ function normalizeStreamChannel(channel) {
|
|
|
112
118
|
if (!data) {
|
|
113
119
|
throw new Error(`Illegal channel data`);
|
|
114
120
|
}
|
|
115
|
-
let context
|
|
121
|
+
let context;
|
|
116
122
|
if (data.context) {
|
|
117
123
|
try {
|
|
118
124
|
if (typeof data.context === 'string') {
|
|
@@ -126,7 +132,7 @@ function normalizeStreamChannel(channel) {
|
|
|
126
132
|
console.error('Context Issue: ', e);
|
|
127
133
|
}
|
|
128
134
|
}
|
|
129
|
-
let assignee
|
|
135
|
+
let assignee;
|
|
130
136
|
if (data.assignee) {
|
|
131
137
|
assignee = data.assignee;
|
|
132
138
|
}
|
|
@@ -188,7 +194,9 @@ exports.localizeStreamMember = localizeStreamMember;
|
|
|
188
194
|
function localizeStreamChannelMembers(streamChannel) {
|
|
189
195
|
const { state } = streamChannel;
|
|
190
196
|
const wid = streamChannel.getClient().userID;
|
|
191
|
-
return Object.values(state.members)
|
|
197
|
+
return Object.values(state.members)
|
|
198
|
+
.map(localizeStreamMember)
|
|
199
|
+
.filter((member) => member.id !== wid);
|
|
192
200
|
}
|
|
193
201
|
exports.localizeStreamChannelMembers = localizeStreamChannelMembers;
|
|
194
202
|
function localizeStreamChannelsMembersToMapByChannelId(streamChannels) {
|
|
@@ -210,7 +218,9 @@ function localizeStreamChannel(streamChannel) {
|
|
|
210
218
|
const userId = data?.type === xbees_conversations_client_1.ChannelType.DIRECT && members.length > 0 ? members[0].user_id : null;
|
|
211
219
|
const unread = state.read[wid]?.unread_messages || 0;
|
|
212
220
|
const lastMessage = streamChannel.lastMessage();
|
|
213
|
-
const normalizedLastMessage = lastMessage
|
|
221
|
+
const normalizedLastMessage = lastMessage
|
|
222
|
+
? localizeStreamMessage(lastMessage, normalizedChannel.channelId, wid)
|
|
223
|
+
: null;
|
|
214
224
|
const lastMessageAt = normalizedLastMessage ? normalizedLastMessage.createdAt : updatedAt || createdAt;
|
|
215
225
|
const lastRead = state.read[wid]?.last_read || null;
|
|
216
226
|
const role = state.membership.role || xbees_conversations_client_1.ChannelMemberRole.MEMBER;
|
|
@@ -245,7 +255,7 @@ function normalizeStreamChannelReadIndicator(channelReadStatus, channelId) {
|
|
|
245
255
|
exports.normalizeStreamChannelReadIndicator = normalizeStreamChannelReadIndicator;
|
|
246
256
|
function normalizeStreamChannelReadIndicators(streamChannel) {
|
|
247
257
|
const wid = streamChannel.getClient().userID;
|
|
248
|
-
const { state: { read }, data } = streamChannel;
|
|
258
|
+
const { state: { read }, data, } = streamChannel;
|
|
249
259
|
return Object.values(read)
|
|
250
260
|
.filter(({ user }) => wid !== user.id)
|
|
251
261
|
.map((readIndicator) => {
|
|
@@ -255,7 +265,7 @@ function normalizeStreamChannelReadIndicators(streamChannel) {
|
|
|
255
265
|
exports.normalizeStreamChannelReadIndicators = normalizeStreamChannelReadIndicators;
|
|
256
266
|
function normalizeStreamChannelOwnReadIndicators(streamChannel) {
|
|
257
267
|
const wid = streamChannel.getClient().userID;
|
|
258
|
-
const { state: { read }, data } = streamChannel;
|
|
268
|
+
const { state: { read }, data, } = streamChannel;
|
|
259
269
|
return Object.values(read)
|
|
260
270
|
.filter(({ user }) => wid === user.id)
|
|
261
271
|
.map((readIndicator) => {
|
package/dist-es/normalization.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ChannelMemberRole, ChannelType, } from '@wildix/xbees-conversations-client';
|
|
2
|
+
import { MessageDirection, } from './types';
|
|
3
3
|
export function normalizeStreamUser(streamUser) {
|
|
4
4
|
return {
|
|
5
5
|
id: streamUser.id,
|
|
@@ -54,7 +54,9 @@ export function normalizeStreamMessage(streamMessage, channelId) {
|
|
|
54
54
|
latestReactions,
|
|
55
55
|
reactionCounts: reaction_counts || {},
|
|
56
56
|
createdAt: streamMessage.created_at,
|
|
57
|
-
updatedAt: streamMessage.updated_at !== streamMessage.created_at && streamMessage.updated_at
|
|
57
|
+
updatedAt: streamMessage.updated_at !== streamMessage.created_at && streamMessage.updated_at
|
|
58
|
+
? streamMessage.updated_at
|
|
59
|
+
: undefined,
|
|
58
60
|
user,
|
|
59
61
|
quote,
|
|
60
62
|
forward,
|
|
@@ -73,9 +75,13 @@ export function localizeStreamMessage(streamMessage, channelId, userId) {
|
|
|
73
75
|
const normalizedMessage = normalizeStreamMessage(streamMessage, channelId);
|
|
74
76
|
const createdAt = new Date(normalizedMessage.createdAt);
|
|
75
77
|
const updatedAt = normalizedMessage.updatedAt ? new Date(normalizedMessage.updatedAt) : undefined;
|
|
76
|
-
const latestReactions = streamMessage.latest_reactions
|
|
78
|
+
const latestReactions = streamMessage.latest_reactions
|
|
79
|
+
? streamMessage.latest_reactions.map(normalizeStreamReaction)
|
|
80
|
+
: [];
|
|
77
81
|
const ownReactionsFromLatestReactions = latestReactions.filter((r) => userId === r.userId);
|
|
78
|
-
const ownReactions = streamMessage.own_reactions
|
|
82
|
+
const ownReactions = streamMessage.own_reactions
|
|
83
|
+
? streamMessage.own_reactions.map(normalizeStreamReaction).filter((r) => userId === r.userId)
|
|
84
|
+
: [];
|
|
79
85
|
ownReactionsFromLatestReactions.forEach((reaction) => {
|
|
80
86
|
if (!ownReactions.find((ownReaction) => ownReaction.type === reaction.type)) {
|
|
81
87
|
ownReactions.push(reaction);
|
|
@@ -104,7 +110,7 @@ export function normalizeStreamChannel(channel) {
|
|
|
104
110
|
if (!data) {
|
|
105
111
|
throw new Error(`Illegal channel data`);
|
|
106
112
|
}
|
|
107
|
-
let context
|
|
113
|
+
let context;
|
|
108
114
|
if (data.context) {
|
|
109
115
|
try {
|
|
110
116
|
if (typeof data.context === 'string') {
|
|
@@ -118,7 +124,7 @@ export function normalizeStreamChannel(channel) {
|
|
|
118
124
|
console.error('Context Issue: ', e);
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
|
-
let assignee
|
|
127
|
+
let assignee;
|
|
122
128
|
if (data.assignee) {
|
|
123
129
|
assignee = data.assignee;
|
|
124
130
|
}
|
|
@@ -177,7 +183,9 @@ export function localizeStreamMember(member) {
|
|
|
177
183
|
export function localizeStreamChannelMembers(streamChannel) {
|
|
178
184
|
const { state } = streamChannel;
|
|
179
185
|
const wid = streamChannel.getClient().userID;
|
|
180
|
-
return Object.values(state.members)
|
|
186
|
+
return Object.values(state.members)
|
|
187
|
+
.map(localizeStreamMember)
|
|
188
|
+
.filter((member) => member.id !== wid);
|
|
181
189
|
}
|
|
182
190
|
export function localizeStreamChannelsMembersToMapByChannelId(streamChannels) {
|
|
183
191
|
return streamChannels.reduce((accumulator, channel) => {
|
|
@@ -197,7 +205,9 @@ export function localizeStreamChannel(streamChannel) {
|
|
|
197
205
|
const userId = data?.type === ChannelType.DIRECT && members.length > 0 ? members[0].user_id : null;
|
|
198
206
|
const unread = state.read[wid]?.unread_messages || 0;
|
|
199
207
|
const lastMessage = streamChannel.lastMessage();
|
|
200
|
-
const normalizedLastMessage = lastMessage
|
|
208
|
+
const normalizedLastMessage = lastMessage
|
|
209
|
+
? localizeStreamMessage(lastMessage, normalizedChannel.channelId, wid)
|
|
210
|
+
: null;
|
|
201
211
|
const lastMessageAt = normalizedLastMessage ? normalizedLastMessage.createdAt : updatedAt || createdAt;
|
|
202
212
|
const lastRead = state.read[wid]?.last_read || null;
|
|
203
213
|
const role = state.membership.role || ChannelMemberRole.MEMBER;
|
|
@@ -230,7 +240,7 @@ export function normalizeStreamChannelReadIndicator(channelReadStatus, channelId
|
|
|
230
240
|
}
|
|
231
241
|
export function normalizeStreamChannelReadIndicators(streamChannel) {
|
|
232
242
|
const wid = streamChannel.getClient().userID;
|
|
233
|
-
const { state: { read }, data } = streamChannel;
|
|
243
|
+
const { state: { read }, data, } = streamChannel;
|
|
234
244
|
return Object.values(read)
|
|
235
245
|
.filter(({ user }) => wid !== user.id)
|
|
236
246
|
.map((readIndicator) => {
|
|
@@ -239,7 +249,7 @@ export function normalizeStreamChannelReadIndicators(streamChannel) {
|
|
|
239
249
|
}
|
|
240
250
|
export function normalizeStreamChannelOwnReadIndicators(streamChannel) {
|
|
241
251
|
const wid = streamChannel.getClient().userID;
|
|
242
|
-
const { state: { read }, data } = streamChannel;
|
|
252
|
+
const { state: { read }, data, } = streamChannel;
|
|
243
253
|
return Object.values(read)
|
|
244
254
|
.filter(({ user }) => wid === user.id)
|
|
245
255
|
.map((readIndicator) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { type Channel, type ChannelMember, type Message, type Reaction, type User } from '@wildix/xbees-conversations-client';
|
|
2
|
+
import type { StreamChannel, StreamChannelMemberResponse, StreamChannelResponse, StreamMessageResponse, StreamReactionResponse, StreamReadIndicator, StreamUserResponse } from './stream';
|
|
3
|
+
import { type LocalizedChannel, type LocalizedChannelMember, type LocalizedMessage, type LocalizedReadIndicator, type LocalizedUser, type UserPresence } from './types';
|
|
4
4
|
export declare function normalizeStreamUser(streamUser: StreamUserResponse): User;
|
|
5
5
|
export declare function localizeStreamUser(streamUser: StreamUserResponse): LocalizedUser;
|
|
6
6
|
export declare function normalizeStreamReaction(streamReaction: StreamReactionResponse): Reaction;
|
package/dist-types/stream.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ChannelAccess, ChannelContext, ChannelWhatsAppStatus, Element, MessageAttachment, MessageForward, MessageGiphy, MessageQuote, MessageSmsStatus, MessageWhatsAppStatus, User as NormalizedUser } from '@wildix/xbees-conversations-client';
|
|
2
|
+
import type { Channel, ChannelAPIResponse, ChannelData, ChannelFilters, ChannelMemberResponse, ChannelMembership, ChannelResponse, ChannelSort, ChannelState, Event, ExtendableGenerics, GetReactionsAPIResponse, GetRepliesAPIResponse, LiteralStringForUnion, Message, MessageResponse, OwnUserResponse, PartialMessageUpdate, PartialUpdateChannel, Reaction, ReactionResponse, SearchAPIResponse, SyncResponse, UpdatedMessage, UR, User, UserResponse } from 'stream-chat';
|
|
3
3
|
export interface StreamChannelFields extends UR {
|
|
4
4
|
subject?: string;
|
|
5
5
|
description?: string;
|
|
@@ -114,4 +114,4 @@ export type StreamGetRepliesAPIResponse = GetRepliesAPIResponse<StreamType>;
|
|
|
114
114
|
export type StreamOwnUserResponse = OwnUserResponse<StreamType>;
|
|
115
115
|
export type StreamChannelState = ChannelState<StreamType>;
|
|
116
116
|
export type StreamGetReactionsAPIResponse = GetReactionsAPIResponse<StreamType>;
|
|
117
|
-
export type StreamReadIndicator =
|
|
117
|
+
export type StreamReadIndicator = StreamChannelState['read'][keyof StreamChannelState['read']];
|
package/dist-types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Channel, ChannelMember, ChannelMemberRole, Message, Reaction, User } from '@wildix/xbees-conversations-client';
|
|
1
|
+
import type { Channel, ChannelMember, ChannelMemberRole, Message, Reaction, User } from '@wildix/xbees-conversations-client';
|
|
2
2
|
export declare enum MessageDirection {
|
|
3
3
|
INCOMING = "incoming",
|
|
4
4
|
OUTGOING = "outgoing"
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-conversations-utils",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
7
7
|
"types": "./dist-types/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "concurrently '
|
|
9
|
+
"build": "concurrently 'pnpm run build:cjs' 'pnpm run build:es' 'pnpm run build:types'",
|
|
10
10
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
11
11
|
"build:es": "tsc -p tsconfig.es.json",
|
|
12
|
-
"build:include:deps": "
|
|
12
|
+
"build:include:deps": "pnpm --filter \"$npm_package_name\"... run build",
|
|
13
13
|
"build:types": "tsc -p tsconfig.types.json",
|
|
14
14
|
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
15
15
|
"build:api-extractor": "mkdir -p etc && api-extractor run --local --verbose",
|
|
16
16
|
"check-types": "tsc --noemit",
|
|
17
17
|
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
|
|
18
|
-
"lint": "
|
|
19
|
-
"lint:fix": "
|
|
18
|
+
"lint": "biome check . && pnpm run check-types",
|
|
19
|
+
"lint:fix": "biome check --write . && pnpm run check-types",
|
|
20
20
|
"postpublish": "node ../../scripts/postpublish.js"
|
|
21
21
|
},
|
|
22
22
|
"engines": {
|
|
@@ -26,16 +26,14 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@wildix/xbees-conversations-client": "3.1.1",
|
|
28
28
|
"stream-chat": "8.12.1",
|
|
29
|
-
"tslib": "2.
|
|
29
|
+
"tslib": "^2.6.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@tsconfig/node18": "18.2.4",
|
|
33
33
|
"@tsconfig/recommended": "1.0.1",
|
|
34
34
|
"@types/uuid": "10.0.0",
|
|
35
|
-
"@wildix/eslint-config-style-guide": "1.2.1",
|
|
36
35
|
"concurrently": "7.0.0",
|
|
37
36
|
"downlevel-dts": "0.10.1",
|
|
38
|
-
"eslint": "8.57.1",
|
|
39
37
|
"rimraf": "^3.0.0",
|
|
40
38
|
"typescript": "~5.2.2"
|
|
41
39
|
},
|