stream-chat 4.4.3-dev.2 → 5.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/README.md +4 -13
- package/dist/browser.es.js +1229 -720
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.full-bundle.min.js +1 -1
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/browser.js +1229 -719
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +1229 -720
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1229 -719
- package/dist/index.js.map +1 -1
- package/dist/types/base64.d.ts.map +1 -1
- package/dist/types/channel.d.ts +19 -15
- package/dist/types/channel.d.ts.map +1 -1
- package/dist/types/channel_state.d.ts +2 -2
- package/dist/types/channel_state.d.ts.map +1 -1
- package/dist/types/client.d.ts +25 -42
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client_state.d.ts +2 -2
- package/dist/types/client_state.d.ts.map +1 -1
- package/dist/types/connection.d.ts +14 -49
- package/dist/types/connection.d.ts.map +1 -1
- package/dist/types/connection_fallback.d.ts +41 -0
- package/dist/types/connection_fallback.d.ts.map +1 -0
- package/dist/types/errors.d.ts +14 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/insights.d.ts +17 -10
- package/dist/types/insights.d.ts.map +1 -1
- package/dist/types/permissions.d.ts.map +1 -1
- package/dist/types/signing.d.ts +3 -3
- package/dist/types/signing.d.ts.map +1 -1
- package/dist/types/token_manager.d.ts +2 -2
- package/dist/types/token_manager.d.ts.map +1 -1
- package/dist/types/types.d.ts +94 -88
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +13 -3
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/base64.ts +1 -4
- package/src/channel.ts +133 -461
- package/src/channel_state.ts +31 -158
- package/src/client.ts +291 -712
- package/src/client_state.ts +2 -2
- package/src/connection.ts +146 -395
- package/src/connection_fallback.ts +205 -0
- package/src/errors.ts +58 -0
- package/src/insights.ts +38 -32
- package/src/permissions.ts +3 -24
- package/src/signing.ts +6 -17
- package/src/token_manager.ts +6 -18
- package/src/types.ts +268 -512
- package/src/utils.ts +58 -24
- package/CHANGELOG.md +0 -844
package/src/utils.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import FormData from 'form-data';
|
|
2
|
-
import {
|
|
3
|
-
AscDesc,
|
|
4
|
-
LiteralStringForUnion,
|
|
5
|
-
OwnUserBase,
|
|
6
|
-
OwnUserResponse,
|
|
7
|
-
UnknownType,
|
|
8
|
-
UserResponse,
|
|
9
|
-
} from './types';
|
|
2
|
+
import { AscDesc, LiteralStringForUnion, OwnUserBase, OwnUserResponse, UR, UserResponse } from './types';
|
|
10
3
|
|
|
11
4
|
/**
|
|
12
5
|
* logChatPromiseExecution - utility function for logging the execution of a promise..
|
|
@@ -42,8 +35,7 @@ function isReadableStream(obj: unknown): obj is NodeJS.ReadStream {
|
|
|
42
35
|
return (
|
|
43
36
|
obj !== null &&
|
|
44
37
|
typeof obj === 'object' &&
|
|
45
|
-
((obj as NodeJS.ReadStream).readable ||
|
|
46
|
-
typeof (obj as NodeJS.ReadStream)._read === 'function')
|
|
38
|
+
((obj as NodeJS.ReadStream).readable || typeof (obj as NodeJS.ReadStream)._read === 'function')
|
|
47
39
|
);
|
|
48
40
|
}
|
|
49
41
|
|
|
@@ -63,16 +55,13 @@ function isFileWebAPI(uri: unknown): uri is File {
|
|
|
63
55
|
}
|
|
64
56
|
|
|
65
57
|
export function isOwnUser<
|
|
66
|
-
ChannelType extends
|
|
58
|
+
ChannelType extends UR = UR,
|
|
67
59
|
CommandType extends string = LiteralStringForUnion,
|
|
68
|
-
UserType extends
|
|
60
|
+
UserType extends UR = UR
|
|
69
61
|
>(
|
|
70
62
|
user?: OwnUserResponse<ChannelType, CommandType, UserType> | UserResponse<UserType>,
|
|
71
63
|
): user is OwnUserResponse<ChannelType, CommandType, UserType> {
|
|
72
|
-
return (
|
|
73
|
-
(user as OwnUserResponse<ChannelType, CommandType, UserType>)?.total_unread_count !==
|
|
74
|
-
undefined
|
|
75
|
-
);
|
|
64
|
+
return (user as OwnUserResponse<ChannelType, CommandType, UserType>)?.total_unread_count !== undefined;
|
|
76
65
|
}
|
|
77
66
|
|
|
78
67
|
export function isOwnUserBaseProperty(property: string) {
|
|
@@ -113,9 +102,7 @@ export function addFileToFormData(
|
|
|
113
102
|
|
|
114
103
|
return data;
|
|
115
104
|
}
|
|
116
|
-
export function normalizeQuerySort<T extends Record<string, AscDesc | undefined>>(
|
|
117
|
-
sort: T | T[],
|
|
118
|
-
) {
|
|
105
|
+
export function normalizeQuerySort<T extends Record<string, AscDesc | undefined>>(sort: T | T[]) {
|
|
119
106
|
const sortFields: Array<{ direction: AscDesc; field: keyof T }> = [];
|
|
120
107
|
const sortArr = Array.isArray(sort) ? sort : [sort];
|
|
121
108
|
for (const item of sortArr) {
|
|
@@ -199,15 +186,62 @@ function getRandomBytes(length: number): Uint8Array {
|
|
|
199
186
|
return bytes;
|
|
200
187
|
}
|
|
201
188
|
|
|
202
|
-
export function convertErrorToJson(err:
|
|
189
|
+
export function convertErrorToJson(err: Error) {
|
|
203
190
|
const jsonObj = {} as Record<string, unknown>;
|
|
204
191
|
|
|
205
192
|
if (!err) return jsonObj;
|
|
206
193
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
194
|
+
try {
|
|
195
|
+
Object.getOwnPropertyNames(err).forEach((key) => {
|
|
196
|
+
jsonObj[key] = Object.getOwnPropertyDescriptor(err, key);
|
|
197
|
+
});
|
|
198
|
+
} catch (_) {
|
|
199
|
+
return {
|
|
200
|
+
error: 'failed to serialize the error',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
211
203
|
|
|
212
204
|
return jsonObj;
|
|
213
205
|
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* isOnline safely return the navigator.online value for browser env
|
|
209
|
+
* if navigator is not in global object, it always return true
|
|
210
|
+
*/
|
|
211
|
+
export function isOnline() {
|
|
212
|
+
const nav =
|
|
213
|
+
typeof navigator !== 'undefined'
|
|
214
|
+
? navigator
|
|
215
|
+
: typeof window !== 'undefined' && window.navigator
|
|
216
|
+
? window.navigator
|
|
217
|
+
: undefined;
|
|
218
|
+
|
|
219
|
+
if (!nav) {
|
|
220
|
+
console.warn('isOnline failed to access window.navigator and assume browser is online');
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// RN navigator has undefined for onLine
|
|
225
|
+
if (typeof nav.onLine !== 'boolean') {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return nav.onLine;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* listenForConnectionChanges - Adds an event listener fired on browser going online or offline
|
|
234
|
+
*/
|
|
235
|
+
export function addConnectionEventListeners(cb: (e: Event) => void) {
|
|
236
|
+
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
237
|
+
window.addEventListener('offline', cb);
|
|
238
|
+
window.addEventListener('online', cb);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function removeConnectionEventListeners(cb: (e: Event) => void) {
|
|
243
|
+
if (typeof window !== 'undefined' && window.removeEventListener) {
|
|
244
|
+
window.removeEventListener('offline', cb);
|
|
245
|
+
window.removeEventListener('online', cb);
|
|
246
|
+
}
|
|
247
|
+
}
|