stream-chat 5.6.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.
Files changed (40) hide show
  1. package/README.md +59 -114
  2. package/dist/browser.es.js +464 -366
  3. package/dist/browser.es.js.map +1 -1
  4. package/dist/browser.full-bundle.min.js +1 -1
  5. package/dist/browser.full-bundle.min.js.map +1 -1
  6. package/dist/browser.js +464 -366
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index.es.js +464 -366
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.js +464 -366
  11. package/dist/index.js.map +1 -1
  12. package/dist/types/channel.d.ts +124 -124
  13. package/dist/types/channel.d.ts.map +1 -1
  14. package/dist/types/channel_state.d.ts +41 -41
  15. package/dist/types/channel_state.d.ts.map +1 -1
  16. package/dist/types/client.d.ts +190 -163
  17. package/dist/types/client.d.ts.map +1 -1
  18. package/dist/types/client_state.d.ts +6 -6
  19. package/dist/types/client_state.d.ts.map +1 -1
  20. package/dist/types/connection.d.ts +10 -10
  21. package/dist/types/connection.d.ts.map +1 -1
  22. package/dist/types/connection_fallback.d.ts +7 -7
  23. package/dist/types/connection_fallback.d.ts.map +1 -1
  24. package/dist/types/insights.d.ts +2 -2
  25. package/dist/types/token_manager.d.ts +6 -6
  26. package/dist/types/token_manager.d.ts.map +1 -1
  27. package/dist/types/types.d.ts +404 -236
  28. package/dist/types/types.d.ts.map +1 -1
  29. package/dist/types/utils.d.ts +2 -2
  30. package/dist/types/utils.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/channel.ts +196 -290
  33. package/src/channel_state.ts +54 -219
  34. package/src/client.ts +297 -524
  35. package/src/client_state.ts +6 -6
  36. package/src/connection.ts +7 -22
  37. package/src/connection_fallback.ts +7 -21
  38. package/src/token_manager.ts +6 -6
  39. package/src/types.ts +540 -487
  40. package/src/utils.ts +7 -11
package/README.md CHANGED
@@ -1,52 +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<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
39
- ```
50
+ import { StreamChat } from 'stream-chat';
51
+ // Or if you are on commonjs
52
+ const StreamChat = require('stream-chat').StreamChat;
40
53
 
41
- 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');
55
+
56
+ const channel = client.channel('messaging', 'TestChannel');
57
+ await channel.create();
58
+ ```
42
59
 
43
- **NOTE:** If you utilize the `setAnonymousUser` function you must account for this in your user types.
60
+ Or you can customize the generics:
44
61
 
45
62
  ```typescript
46
- import { StreamChat } from 'stream-chat';
47
- // or if you are on commonjs
48
- const StreamChat = require('stream-chat').StreamChat;
49
-
50
63
  type ChatChannel = { image: string; category?: string };
51
64
  type ChatUser1 = { nickname: string; age: number; admin?: boolean };
52
65
  type ChatUser2 = { nickname: string; avatar?: string };
@@ -57,116 +70,48 @@ type CustomReaction = { size?: number };
57
70
  type ChatEvent = { quitChannel?: boolean };
58
71
  type CustomCommands = 'giphy';
59
72
 
60
- // Instantiate a new client (server side)
61
- // you can also use `new StreamChat<T,T,...>()`
62
- const client = StreamChat.getInstance<
63
- ChatAttachment,
64
- ChatChannel,
65
- CustomCommands,
66
- ChatEvent,
67
- UserMessage | AdminMessage,
68
- CustomReaction,
69
- ChatUser1 | ChatUser2
70
- >('YOUR_API_KEY', 'API_KEY_SECRET');
71
-
72
- /**
73
- * Instantiate a new client (client side)
74
- * Unused generics default to Record<string, unknown>
75
- * with the exception of Command which defaults to string & {}
76
- */
77
- const client = StreamChat.getInstance<{}, ChatChannel, {}, {}, UserMessage | AdminMessage, {}, ChatUser1 | ChatUser2>(
78
- 'YOUR_API_KEY',
79
- );
80
- ```
81
-
82
- 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.
83
-
84
- ```typescript
85
- // Valid queries
86
- // users: { duration: string; users: UserResponse<ChatUser1 | ChatUser2>[]; }
87
- const users = await client.queryUsers({ id: '1080' });
88
- const users = await client.queryUsers({ nickname: 'streamUser' });
89
- const users = await client.queryUsers({ nickname: { $eq: 'streamUser' } });
90
-
91
- // Invalid queries
92
- const users = await client.queryUsers({ nickname: { $contains: ['stream'] } }); // $contains is only an operator on arrays
93
- const users = await client.queryUsers({ nickname: 1080 }); // nickname must be a string
94
- const users = await client.queryUsers({ name: { $eq: 1080 } }); // name must be a string
95
- ```
73
+ type StreamType = {
74
+ attachmentType: ChatAttachment;
75
+ channelType: ChatChannel;
76
+ commandType: CustomCommands;
77
+ eventType: ChatEvent;
78
+ messageType: UserMessage | AdminMessage;
79
+ reactionType: CustomReaction;
80
+ userType: ChatUser1 | ChatUser2;
81
+ };
96
82
 
97
- **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.
83
+ const client = StreamChat.getInstance<StreamType>('YOUR_API_KEY', 'API_KEY_SECRET');
98
84
 
99
- ```typescript
100
- function isChatUser1(user: ChatUser1 | ChatUser2): user is ChatUser1 {
101
- return (user as ChatUser1).age !== undefined;
102
- }
103
-
104
- function isAdminMessage(msg: UserMessage | AdminMessage): msg is AdminMessage {
105
- return (msg as AdminMessage).priorityLevel !== undefined;
106
- }
107
- ```
108
-
109
- Intellisense, type checking, and return types are provided for all queries.
110
-
111
- ```typescript
85
+ // Create channel
112
86
  const channel = client.channel('messaging', 'TestChannel');
113
87
  await channel.create();
114
88
 
115
- // Valid queries
116
- // messages: SearchAPIResponse<ChatAttachment, ChatChannel, CommandTypes, UserMessage | AdminMessage, CustomReaction, ChatUser1 | ChatUser2>
117
- const messages = await channel.search({ country: 'NL' });
118
- const messages = await channel.search({ priorityLevel: { $gt: 5 } });
119
- const messages = await channel.search({
120
- $and: [{ priorityLevel: { $gt: 5 } }, { deleted_at: { $exists: false } }],
89
+ // Create user
90
+ await client.upsertUser({
91
+ id: 'vishal-1',
92
+ name: 'Vishal',
121
93
  });
122
94
 
123
- // Invalid queries
124
- const messages = await channel.search({ country: { $eq: 5 } }); // country must be a string
125
- const messages = await channel.search({
126
- $or: [{ id: '2' }, { reaction_counts: { $eq: 'hello' } }],
127
- }); // reaction_counts must be a number
128
- ```
129
-
130
- Custom types are carried into all creation functions as well.
95
+ // Send message
96
+ const { message } = await channel.sendMessage({ text: `Test message` });
131
97
 
132
- ```typescript
133
- // Valid
134
- client.connectUser({ id: 'testId', nickname: 'testUser', age: 3 }, 'TestToken');
135
- client.connectUser({ id: 'testId', nickname: 'testUser', avatar: 'testAvatar' }, 'TestToken');
136
-
137
- // Invalid
138
- client.connectUser({ id: 'testId' }, 'TestToken'); // Type ChatUser1 | ChatUser2 requires nickname for both types
139
- client.connectUser({ id: 'testId', nickname: true }, 'TestToken'); // nickname must be a string
140
- 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' } });
141
100
  ```
142
101
 
143
- ## More
144
-
145
- - [Logging](docs/logging.md)
146
- - [User Token](docs/userToken.md)
147
-
148
- ## Contributing
149
-
150
- 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.
151
-
152
- ### Commit message convention
153
-
154
- Since we're autogenerating our [CHANGELOG](./CHANGELOG.md), we need to follow a specific commit message convention.
155
- 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`.
156
-
157
- ## Release (for Stream developers)
102
+ Custom types provided when initializing the client will carry through to all client returns and provide intellisense to queries.
158
103
 
159
- Releasing this package involves two GitHub Action steps:
104
+ ## 📚 More code examples
160
105
 
161
- - 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.
162
107
 
163
- The job creates a pull request with the changelog. Check if it looks good.
108
+ ## ✍️ Contributing
164
109
 
165
- - 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.
166
111
 
167
- 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.
168
113
 
169
- ## We are hiring
114
+ ## 🧑‍💻 We are hiring!
170
115
 
171
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.
172
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.