stream-chat 6.1.0 → 6.2.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 +49 -112
- package/dist/browser.es.js +65 -22
- 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 +65 -22
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +65 -22
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +65 -22
- package/dist/index.js.map +1 -1
- package/dist/types/client.d.ts +16 -3
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/types.d.ts +24 -3
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +22 -3
- package/src/types.ts +34 -3
package/README.md
CHANGED
|
@@ -1,60 +1,65 @@
|
|
|
1
|
-
# Stream Chat
|
|
1
|
+
# Official JavaScript SDK for [Stream Chat](https://getstream.io/chat/)
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/stream-chat)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="./assets/logo.svg" width="50%" height="50%">
|
|
7
|
+
</p>
|
|
8
|
+
<p align="center">
|
|
9
|
+
Official JavaScript API client for Stream Chat, a service for building chat applications.
|
|
10
|
+
<br />
|
|
11
|
+
<a href="https://getstream.io/chat/docs/"><strong>Explore the docs »</strong></a>
|
|
12
|
+
<br />
|
|
13
|
+
<br />
|
|
14
|
+
<a href="https://github.com/GetStream/stream-chat-js/issues">Report Bug</a>
|
|
15
|
+
·
|
|
16
|
+
<a href="https://github.com/GetStream/stream-chat-js/issues">Request Feature</a>
|
|
17
|
+
</p>
|
|
6
18
|
|
|
7
|
-
|
|
19
|
+
## 📝 About Stream
|
|
8
20
|
|
|
9
|
-
|
|
21
|
+
You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.
|
|
10
22
|
|
|
11
|
-
|
|
23
|
+
This library can be used by both frontend and backend applications. For frontend, we have frameworks that are based on this library such as the [Flutter](https://github.com/GetStream/stream-chat-flutter), [React](https://github.com/GetStream/stream-chat-react) and [Angular](https://github.com/GetStream/stream-chat-angular) SDKs. For more information, check out our [docs](https://getstream.io/chat/docs/).
|
|
24
|
+
|
|
25
|
+
## ⚙️ Installation
|
|
26
|
+
|
|
27
|
+
### NPM
|
|
12
28
|
|
|
13
29
|
```bash
|
|
14
30
|
npm install stream-chat
|
|
15
31
|
```
|
|
16
32
|
|
|
17
|
-
###
|
|
33
|
+
### Yarn
|
|
18
34
|
|
|
19
35
|
```bash
|
|
20
36
|
yarn add stream-chat
|
|
21
37
|
```
|
|
22
38
|
|
|
23
|
-
###
|
|
39
|
+
### JS deliver
|
|
24
40
|
|
|
25
41
|
```html
|
|
26
42
|
<script src="https://cdn.jsdelivr.net/npm/stream-chat"></script>
|
|
27
43
|
```
|
|
28
44
|
|
|
29
|
-
##
|
|
30
|
-
|
|
31
|
-
Documentation for this JavaScript client are available at the [Stream Website](https://getstream.io/chat/docs/?language=js).
|
|
32
|
-
|
|
33
|
-
### Typescript (v2.x.x)
|
|
45
|
+
## ✨ Getting started
|
|
34
46
|
|
|
35
47
|
The StreamChat client is setup to allow extension of the base types through use of generics when instantiated. The default instantiation has all generics set to `Record<string, unknown>`.
|
|
36
48
|
|
|
37
49
|
```typescript
|
|
38
|
-
StreamChat
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
commandType: CommandType;
|
|
42
|
-
eventType: EventType;
|
|
43
|
-
messageType: MessageType;
|
|
44
|
-
reactionType: ReactionType;
|
|
45
|
-
userType: UserType;
|
|
46
|
-
}>
|
|
47
|
-
```
|
|
50
|
+
import { StreamChat } from 'stream-chat';
|
|
51
|
+
// Or if you are on commonjs
|
|
52
|
+
const StreamChat = require('stream-chat').StreamChat;
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
const client = StreamChat.getInstance('YOUR_API_KEY', 'API_KEY_SECRET');
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
const channel = client.channel('messaging', 'TestChannel');
|
|
57
|
+
await channel.create();
|
|
58
|
+
```
|
|
52
59
|
|
|
53
|
-
|
|
54
|
-
import { StreamChat } from 'stream-chat';
|
|
55
|
-
// or if you are on commonjs
|
|
56
|
-
const StreamChat = require('stream-chat').StreamChat;
|
|
60
|
+
Or you can customize the generics:
|
|
57
61
|
|
|
62
|
+
```typescript
|
|
58
63
|
type ChatChannel = { image: string; category?: string };
|
|
59
64
|
type ChatUser1 = { nickname: string; age: number; admin?: boolean };
|
|
60
65
|
type ChatUser2 = { nickname: string; avatar?: string };
|
|
@@ -75,106 +80,38 @@ type StreamType = {
|
|
|
75
80
|
userType: ChatUser1 | ChatUser2;
|
|
76
81
|
};
|
|
77
82
|
|
|
78
|
-
// Instantiate a new client (server side)
|
|
79
|
-
// you can also use `new StreamChat<T,T,...>()`
|
|
80
83
|
const client = StreamChat.getInstance<StreamType>('YOUR_API_KEY', 'API_KEY_SECRET');
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
* Instantiate a new client (client side)
|
|
84
|
-
* Unused generics default to Record<string, unknown>
|
|
85
|
-
* with the exception of Command which defaults to string & {}
|
|
86
|
-
*/
|
|
87
|
-
const client = StreamChat.getInstance<StreamType>('YOUR_API_KEY');
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Query operations will return results that utilize the custom types added via generics. In addition the query filters are type checked and provide intellisense using both the key and type of the parameter to ensure accurate use.
|
|
91
|
-
|
|
92
|
-
```typescript
|
|
93
|
-
// Valid queries
|
|
94
|
-
// users: { duration: string; users: UserResponse<ChatUser1 | ChatUser2>[]; }
|
|
95
|
-
const users = await client.queryUsers({ id: '1080' });
|
|
96
|
-
const users = await client.queryUsers({ nickname: 'streamUser' });
|
|
97
|
-
const users = await client.queryUsers({ nickname: { $eq: 'streamUser' } });
|
|
98
|
-
|
|
99
|
-
// Invalid queries
|
|
100
|
-
const users = await client.queryUsers({ nickname: { $contains: ['stream'] } }); // $contains is only an operator on arrays
|
|
101
|
-
const users = await client.queryUsers({ nickname: 1080 }); // nickname must be a string
|
|
102
|
-
const users = await client.queryUsers({ name: { $eq: 1080 } }); // name must be a string
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
**Note:** If you have differing union types like `ChatUser1 | ChatUser2` or `UserMessage | AdminMessage` you can use [type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types) to maintain type safety when dealing with the results of queries.
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
function isChatUser1(user: ChatUser1 | ChatUser2): user is ChatUser1 {
|
|
109
|
-
return (user as ChatUser1).age !== undefined;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function isAdminMessage(msg: UserMessage | AdminMessage): msg is AdminMessage {
|
|
113
|
-
return (msg as AdminMessage).priorityLevel !== undefined;
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Intellisense, type checking, and return types are provided for all queries.
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
85
|
+
// Create channel
|
|
120
86
|
const channel = client.channel('messaging', 'TestChannel');
|
|
121
87
|
await channel.create();
|
|
122
88
|
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const messages = await channel.search({
|
|
128
|
-
$and: [{ priorityLevel: { $gt: 5 } }, { deleted_at: { $exists: false } }],
|
|
89
|
+
// Create user
|
|
90
|
+
await client.upsertUser({
|
|
91
|
+
id: 'vishal-1',
|
|
92
|
+
name: 'Vishal',
|
|
129
93
|
});
|
|
130
94
|
|
|
131
|
-
//
|
|
132
|
-
const
|
|
133
|
-
const messages = await channel.search({
|
|
134
|
-
$or: [{ id: '2' }, { reaction_counts: { $eq: 'hello' } }],
|
|
135
|
-
}); // reaction_counts must be a number
|
|
136
|
-
```
|
|
95
|
+
// Send message
|
|
96
|
+
const { message } = await channel.sendMessage({ text: `Test message` });
|
|
137
97
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
// Valid
|
|
142
|
-
client.connectUser({ id: 'testId', nickname: 'testUser', age: 3 }, 'TestToken');
|
|
143
|
-
client.connectUser({ id: 'testId', nickname: 'testUser', avatar: 'testAvatar' }, 'TestToken');
|
|
144
|
-
|
|
145
|
-
// Invalid
|
|
146
|
-
client.connectUser({ id: 'testId' }, 'TestToken'); // Type ChatUser1 | ChatUser2 requires nickname for both types
|
|
147
|
-
client.connectUser({ id: 'testId', nickname: true }, 'TestToken'); // nickname must be a string
|
|
148
|
-
client.connectUser({ id: 'testId', nickname: 'testUser', country: 'NL' }, 'TestToken'); // country does not exist on type ChatUser1 | ChatUser2
|
|
98
|
+
// Send reaction
|
|
99
|
+
await channel.sendReaction(message.id, { type: 'love', user: { id: 'vishal-1' } });
|
|
149
100
|
```
|
|
150
101
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
- [Logging](docs/logging.md)
|
|
154
|
-
- [User Token](docs/userToken.md)
|
|
155
|
-
|
|
156
|
-
## Contributing
|
|
157
|
-
|
|
158
|
-
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our license file for more details.
|
|
159
|
-
|
|
160
|
-
### Commit message convention
|
|
161
|
-
|
|
162
|
-
Since we're autogenerating our [CHANGELOG](./CHANGELOG.md), we need to follow a specific commit message convention.
|
|
163
|
-
You can read about conventional commits [here](https://www.conventionalcommits.org/). Here's how a usual commit message looks like for a new feature: `feat: allow provided config object to extend other configs`. A bugfix: `fix: prevent racing of requests`.
|
|
164
|
-
|
|
165
|
-
## Release (for Stream developers)
|
|
102
|
+
Custom types provided when initializing the client will carry through to all client returns and provide intellisense to queries.
|
|
166
103
|
|
|
167
|
-
|
|
104
|
+
## 📚 More code examples
|
|
168
105
|
|
|
169
|
-
|
|
106
|
+
Head over to [docs/typescript.md](./docs/typescript.md) for more examples.
|
|
170
107
|
|
|
171
|
-
|
|
108
|
+
## ✍️ Contributing
|
|
172
109
|
|
|
173
|
-
|
|
110
|
+
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details.
|
|
174
111
|
|
|
175
|
-
|
|
112
|
+
Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips.
|
|
176
113
|
|
|
177
|
-
## We are hiring
|
|
114
|
+
## 🧑💻 We are hiring!
|
|
178
115
|
|
|
179
116
|
We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing.
|
|
180
117
|
Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
|
package/dist/browser.es.js
CHANGED
|
@@ -9180,7 +9180,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
9180
9180
|
}, {
|
|
9181
9181
|
key: "getUserAgent",
|
|
9182
9182
|
value: function getUserAgent() {
|
|
9183
|
-
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.
|
|
9183
|
+
return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.2.0");
|
|
9184
9184
|
}
|
|
9185
9185
|
}, {
|
|
9186
9186
|
key: "setUserAgent",
|
|
@@ -10183,7 +10183,7 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
10183
10183
|
return deleteUsers;
|
|
10184
10184
|
}()
|
|
10185
10185
|
/**
|
|
10186
|
-
*
|
|
10186
|
+
* _createImportURL - Create an Import upload url.
|
|
10187
10187
|
*
|
|
10188
10188
|
* Note: Do not use this.
|
|
10189
10189
|
* It is present for internal usage only.
|
|
@@ -10196,15 +10196,15 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
10196
10196
|
*/
|
|
10197
10197
|
|
|
10198
10198
|
}, {
|
|
10199
|
-
key: "
|
|
10199
|
+
key: "_createImportURL",
|
|
10200
10200
|
value: function () {
|
|
10201
|
-
var
|
|
10201
|
+
var _createImportURL2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee71(filename) {
|
|
10202
10202
|
return _regeneratorRuntime.wrap(function _callee71$(_context71) {
|
|
10203
10203
|
while (1) {
|
|
10204
10204
|
switch (_context71.prev = _context71.next) {
|
|
10205
10205
|
case 0:
|
|
10206
10206
|
_context71.next = 2;
|
|
10207
|
-
return this.post(this.baseURL + "/
|
|
10207
|
+
return this.post(this.baseURL + "/import_urls", {
|
|
10208
10208
|
filename: filename
|
|
10209
10209
|
});
|
|
10210
10210
|
|
|
@@ -10219,7 +10219,50 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
10219
10219
|
}, _callee71, this);
|
|
10220
10220
|
}));
|
|
10221
10221
|
|
|
10222
|
-
function
|
|
10222
|
+
function _createImportURL(_x94) {
|
|
10223
|
+
return _createImportURL2.apply(this, arguments);
|
|
10224
|
+
}
|
|
10225
|
+
|
|
10226
|
+
return _createImportURL;
|
|
10227
|
+
}()
|
|
10228
|
+
/**
|
|
10229
|
+
* _createImport - Create an Import Task.
|
|
10230
|
+
*
|
|
10231
|
+
* Note: Do not use this.
|
|
10232
|
+
* It is present for internal usage only.
|
|
10233
|
+
* This function can, and will, break and/or be removed at any point in time.
|
|
10234
|
+
*
|
|
10235
|
+
* @private
|
|
10236
|
+
* @param {string} path path of uploaded data
|
|
10237
|
+
*
|
|
10238
|
+
* @return {APIResponse & CreateImportResponse} An ImportTask
|
|
10239
|
+
*/
|
|
10240
|
+
|
|
10241
|
+
}, {
|
|
10242
|
+
key: "_createImport",
|
|
10243
|
+
value: function () {
|
|
10244
|
+
var _createImport2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee72(path) {
|
|
10245
|
+
return _regeneratorRuntime.wrap(function _callee72$(_context72) {
|
|
10246
|
+
while (1) {
|
|
10247
|
+
switch (_context72.prev = _context72.next) {
|
|
10248
|
+
case 0:
|
|
10249
|
+
_context72.next = 2;
|
|
10250
|
+
return this.post(this.baseURL + "/imports", {
|
|
10251
|
+
path: path
|
|
10252
|
+
});
|
|
10253
|
+
|
|
10254
|
+
case 2:
|
|
10255
|
+
return _context72.abrupt("return", _context72.sent);
|
|
10256
|
+
|
|
10257
|
+
case 3:
|
|
10258
|
+
case "end":
|
|
10259
|
+
return _context72.stop();
|
|
10260
|
+
}
|
|
10261
|
+
}
|
|
10262
|
+
}, _callee72, this);
|
|
10263
|
+
}));
|
|
10264
|
+
|
|
10265
|
+
function _createImport(_x95) {
|
|
10223
10266
|
return _createImport2.apply(this, arguments);
|
|
10224
10267
|
}
|
|
10225
10268
|
|
|
@@ -10241,26 +10284,26 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
10241
10284
|
}, {
|
|
10242
10285
|
key: "_getImport",
|
|
10243
10286
|
value: function () {
|
|
10244
|
-
var _getImport2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
10245
|
-
return _regeneratorRuntime.wrap(function
|
|
10287
|
+
var _getImport2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee73(id) {
|
|
10288
|
+
return _regeneratorRuntime.wrap(function _callee73$(_context73) {
|
|
10246
10289
|
while (1) {
|
|
10247
|
-
switch (
|
|
10290
|
+
switch (_context73.prev = _context73.next) {
|
|
10248
10291
|
case 0:
|
|
10249
|
-
|
|
10292
|
+
_context73.next = 2;
|
|
10250
10293
|
return this.get(this.baseURL + "/imports/".concat(id));
|
|
10251
10294
|
|
|
10252
10295
|
case 2:
|
|
10253
|
-
return
|
|
10296
|
+
return _context73.abrupt("return", _context73.sent);
|
|
10254
10297
|
|
|
10255
10298
|
case 3:
|
|
10256
10299
|
case "end":
|
|
10257
|
-
return
|
|
10300
|
+
return _context73.stop();
|
|
10258
10301
|
}
|
|
10259
10302
|
}
|
|
10260
|
-
},
|
|
10303
|
+
}, _callee73, this);
|
|
10261
10304
|
}));
|
|
10262
10305
|
|
|
10263
|
-
function _getImport(
|
|
10306
|
+
function _getImport(_x96) {
|
|
10264
10307
|
return _getImport2.apply(this, arguments);
|
|
10265
10308
|
}
|
|
10266
10309
|
|
|
@@ -10282,26 +10325,26 @@ var StreamChat = /*#__PURE__*/function () {
|
|
|
10282
10325
|
}, {
|
|
10283
10326
|
key: "_listImports",
|
|
10284
10327
|
value: function () {
|
|
10285
|
-
var _listImports2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
10286
|
-
return _regeneratorRuntime.wrap(function
|
|
10328
|
+
var _listImports2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee74(options) {
|
|
10329
|
+
return _regeneratorRuntime.wrap(function _callee74$(_context74) {
|
|
10287
10330
|
while (1) {
|
|
10288
|
-
switch (
|
|
10331
|
+
switch (_context74.prev = _context74.next) {
|
|
10289
10332
|
case 0:
|
|
10290
|
-
|
|
10333
|
+
_context74.next = 2;
|
|
10291
10334
|
return this.get(this.baseURL + "/imports", options);
|
|
10292
10335
|
|
|
10293
10336
|
case 2:
|
|
10294
|
-
return
|
|
10337
|
+
return _context74.abrupt("return", _context74.sent);
|
|
10295
10338
|
|
|
10296
10339
|
case 3:
|
|
10297
10340
|
case "end":
|
|
10298
|
-
return
|
|
10341
|
+
return _context74.stop();
|
|
10299
10342
|
}
|
|
10300
10343
|
}
|
|
10301
|
-
},
|
|
10344
|
+
}, _callee74, this);
|
|
10302
10345
|
}));
|
|
10303
10346
|
|
|
10304
|
-
function _listImports(
|
|
10347
|
+
function _listImports(_x97) {
|
|
10305
10348
|
return _listImports2.apply(this, arguments);
|
|
10306
10349
|
}
|
|
10307
10350
|
|