stream-chat 6.1.0 → 6.4.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 CHANGED
@@ -1,60 +1,65 @@
1
- # Stream Chat JS
1
+ # Official JavaScript SDK for [Stream Chat](https://getstream.io/chat/)
2
2
 
3
3
  [![NPM](https://img.shields.io/npm/v/stream-chat.svg)](https://www.npmjs.com/package/stream-chat)
4
4
 
5
- stream-chat-js is the official JavaScript client for Stream Chat, a service for building chat applications.
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
- You can sign up for a Stream account at <https://getstream.io/chat/get_started/>.
19
+ ## 📝 About Stream
8
20
 
9
- ## Installation
21
+ You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.
10
22
 
11
- ### Install with NPM
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
- ### Install with Yarn
33
+ ### Yarn
18
34
 
19
35
  ```bash
20
36
  yarn add stream-chat
21
37
  ```
22
38
 
23
- ### Using JS deliver
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
- ## API Documentation
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
- attachmentType: AttachmentType;
40
- channelType: ChannelType;
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
- Custom types provided when initializing the client will carry through to all client returns and provide intellisense to queries.
54
+ const client = StreamChat.getInstance('YOUR_API_KEY', 'API_KEY_SECRET');
50
55
 
51
- **NOTE:** If you utilize the `setAnonymousUser` function you must account for this in your user types.
56
+ const channel = client.channel('messaging', 'TestChannel');
57
+ await channel.create();
58
+ ```
52
59
 
53
- ```typescript
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
- // Valid queries
124
- // messages: SearchAPIResponse<ChatAttachment, ChatChannel, CommandTypes, UserMessage | AdminMessage, CustomReaction, ChatUser1 | ChatUser2>
125
- const messages = await channel.search({ country: 'NL' });
126
- const messages = await channel.search({ priorityLevel: { $gt: 5 } });
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
- // Invalid queries
132
- const messages = await channel.search({ country: { $eq: 5 } }); // country must be a string
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
- Custom types are carried into all creation functions as well.
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
- ## More
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
- Releasing this package involves two GitHub Action steps:
104
+ ## 📚 More code examples
168
105
 
169
- - Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-js/actions/workflows/initiate_release.yml)).
106
+ Head over to [docs/typescript.md](./docs/typescript.md) for more examples.
170
107
 
171
- The job creates a pull request with the changelog. Check if it looks good.
108
+ ## ✍️ Contributing
172
109
 
173
- - Merge the pull request.
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
- Once the PR is merged, it automatically kicks off another job which will create the tag and created a GitHub release.
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.