stream-chat 8.57.1 → 9.0.0-rc.2

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 (96) hide show
  1. package/README.md +59 -65
  2. package/dist/cjs/index.browser.cjs +11043 -0
  3. package/dist/cjs/index.browser.cjs.map +7 -0
  4. package/dist/cjs/index.node.cjs +22452 -0
  5. package/dist/cjs/index.node.cjs.map +7 -0
  6. package/dist/esm/index.js +11039 -0
  7. package/dist/esm/index.js.map +7 -0
  8. package/dist/types/base64.d.ts +0 -1
  9. package/dist/types/campaign.d.ts +12 -13
  10. package/dist/types/channel.d.ts +143 -145
  11. package/dist/types/channel_manager.d.ts +23 -27
  12. package/dist/types/channel_state.d.ts +51 -52
  13. package/dist/types/client.d.ts +293 -347
  14. package/dist/types/client_state.d.ts +7 -8
  15. package/dist/types/connection.d.ts +13 -16
  16. package/dist/types/connection_fallback.d.ts +5 -6
  17. package/dist/types/constants.d.ts +0 -1
  18. package/dist/types/custom_types.d.ts +22 -0
  19. package/dist/types/errors.d.ts +2 -3
  20. package/dist/types/events.d.ts +0 -1
  21. package/dist/types/index.d.ts +1 -1
  22. package/dist/types/insights.d.ts +5 -7
  23. package/dist/types/moderation.d.ts +8 -9
  24. package/dist/types/permissions.d.ts +2 -3
  25. package/dist/types/poll.d.ts +34 -35
  26. package/dist/types/poll_manager.d.ts +9 -10
  27. package/dist/types/search_controller.d.ts +42 -47
  28. package/dist/types/segment.d.ts +7 -8
  29. package/dist/types/signing.d.ts +3 -5
  30. package/dist/types/store.d.ts +5 -6
  31. package/dist/types/thread.d.ts +31 -31
  32. package/dist/types/thread_manager.d.ts +10 -11
  33. package/dist/types/token_manager.d.ts +9 -10
  34. package/dist/types/types.d.ts +820 -822
  35. package/dist/types/utils.d.ts +34 -36
  36. package/package.json +55 -59
  37. package/src/campaign.ts +4 -4
  38. package/src/channel.ts +195 -226
  39. package/src/channel_manager.ts +37 -51
  40. package/src/channel_state.ts +59 -82
  41. package/src/client.ts +287 -345
  42. package/src/client_state.ts +8 -8
  43. package/src/connection.ts +31 -21
  44. package/src/connection_fallback.ts +15 -13
  45. package/src/custom_types.ts +13 -0
  46. package/src/errors.ts +1 -1
  47. package/src/index.ts +1 -0
  48. package/src/moderation.ts +8 -13
  49. package/src/permissions.ts +1 -1
  50. package/src/poll.ts +51 -68
  51. package/src/poll_manager.ts +10 -15
  52. package/src/search_controller.ts +37 -49
  53. package/src/segment.ts +4 -11
  54. package/src/signing.ts +10 -5
  55. package/src/thread.ts +31 -39
  56. package/src/thread_manager.ts +14 -14
  57. package/src/token_manager.ts +10 -9
  58. package/src/types.ts +641 -766
  59. package/src/utils.ts +31 -66
  60. package/dist/browser.es.js +0 -19235
  61. package/dist/browser.es.js.map +0 -1
  62. package/dist/browser.full-bundle.min.js +0 -2
  63. package/dist/browser.full-bundle.min.js.map +0 -1
  64. package/dist/browser.js +0 -19316
  65. package/dist/browser.js.map +0 -1
  66. package/dist/index.es.js +0 -19238
  67. package/dist/index.es.js.map +0 -1
  68. package/dist/index.js +0 -19322
  69. package/dist/index.js.map +0 -1
  70. package/dist/types/base64.d.ts.map +0 -1
  71. package/dist/types/campaign.d.ts.map +0 -1
  72. package/dist/types/channel.d.ts.map +0 -1
  73. package/dist/types/channel_manager.d.ts.map +0 -1
  74. package/dist/types/channel_state.d.ts.map +0 -1
  75. package/dist/types/client.d.ts.map +0 -1
  76. package/dist/types/client_state.d.ts.map +0 -1
  77. package/dist/types/connection.d.ts.map +0 -1
  78. package/dist/types/connection_fallback.d.ts.map +0 -1
  79. package/dist/types/constants.d.ts.map +0 -1
  80. package/dist/types/errors.d.ts.map +0 -1
  81. package/dist/types/events.d.ts.map +0 -1
  82. package/dist/types/index.d.ts.map +0 -1
  83. package/dist/types/insights.d.ts.map +0 -1
  84. package/dist/types/moderation.d.ts.map +0 -1
  85. package/dist/types/permissions.d.ts.map +0 -1
  86. package/dist/types/poll.d.ts.map +0 -1
  87. package/dist/types/poll_manager.d.ts.map +0 -1
  88. package/dist/types/search_controller.d.ts.map +0 -1
  89. package/dist/types/segment.d.ts.map +0 -1
  90. package/dist/types/signing.d.ts.map +0 -1
  91. package/dist/types/store.d.ts.map +0 -1
  92. package/dist/types/thread.d.ts.map +0 -1
  93. package/dist/types/thread_manager.d.ts.map +0 -1
  94. package/dist/types/token_manager.d.ts.map +0 -1
  95. package/dist/types/types.d.ts.map +0 -1
  96. package/dist/types/utils.d.ts.map +0 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.
22
22
 
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/).
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 [documentation](https://getstream.io/chat/docs/).
24
24
 
25
25
  ## ⚙️ Installation
26
26
 
@@ -36,95 +36,89 @@ npm install stream-chat
36
36
  yarn add stream-chat
37
37
  ```
38
38
 
39
- ### JS deliver
39
+ ## Getting Started
40
40
 
41
- ```html
42
- <script src="https://cdn.jsdelivr.net/npm/stream-chat"></script>
43
- ```
41
+ ```ts
42
+ import { StreamChat } from 'stream-chat';
43
+ // or if you are using CommonJS
44
+ const { StreamChat } = require('stream-chat');
44
45
 
45
- ## Getting started
46
+ const client = new StreamChat('API_KEY', 'API_SECRET', {
47
+ disableCache: true, // recommended option for server-side use
48
+ // ...other options like `baseURL`...
49
+ });
46
50
 
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>`.
51
+ // create a user
52
+ await client.upsertUser({
53
+ id: 'vishal-1',
54
+ name: 'Vishal',
55
+ });
48
56
 
49
- ```typescript
50
- import { StreamChat } from 'stream-chat';
51
- // Or if you are on commonjs
52
- const StreamChat = require('stream-chat').StreamChat;
57
+ // create a channel
58
+ const channel = client.channel('messaging', 'test-channel', { created_by_id: 'vishal-1' });
59
+ await channel.create();
53
60
 
54
- const client = StreamChat.getInstance('YOUR_API_KEY', 'API_KEY_SECRET');
61
+ // send message
62
+ const { message } = await channel.sendMessage({ text: 'This is a test message' });
55
63
 
56
- const channel = client.channel('messaging', 'TestChannel');
57
- await channel.create();
64
+ // send reaction
65
+ await channel.sendReaction(message.id, { type: 'love', user: { id: 'vishal-1' } });
58
66
  ```
59
67
 
60
- Or you can customize the generics:
61
-
62
- ```typescript
63
- type ChatChannel = { image: string; category?: string };
64
- type ChatUser1 = { nickname: string; age: number; admin?: boolean };
65
- type ChatUser2 = { nickname: string; avatar?: string };
66
- type UserMessage = { country?: string };
67
- type AdminMessage = { priorityLevel: number };
68
- type ChatAttachment = { originalURL?: string };
69
- type CustomReaction = { size?: number };
70
- type ChatEvent = { quitChannel?: boolean };
71
- type CustomCommands = 'giphy';
72
-
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
- };
68
+ The `StreamChat` client is set up to allow extension of the base types through use of module augmentation, custom types will carry through to all client returns and provide code-completion to queries (if supported). To extend Stream's entities with custom data you'll have to create a declaration file and make sure it's loaded by TypeScript, [see the list of extendable interfaces](https://github.com/GetStream/stream-chat-js/blob/master/src/custom_types.ts) and the example bellow using two of the most common ones:
82
69
 
83
- const client = StreamChat.getInstance<StreamType>('YOUR_API_KEY', 'API_KEY_SECRET');
70
+ ```ts
71
+ // stream-custom-data.d.ts
84
72
 
85
- // Create channel
86
- const channel = client.channel('messaging', 'TestChannel');
87
- await channel.create();
73
+ import 'stream-chat';
88
74
 
89
- // Create user
90
- await client.upsertUser({
91
- id: 'vishal-1',
92
- name: 'Vishal',
93
- });
75
+ declare module 'stream-chat' {
76
+ interface CustomMessageData {
77
+ custom_property?: number;
78
+ }
79
+ interface CustomUserData {
80
+ profile_picture?: string;
81
+ }
82
+ }
94
83
 
95
- // Send message
96
- const { message } = await channel.sendMessage({ text: `Test message` });
84
+ // index.ts
97
85
 
98
- // Send reaction
99
- await channel.sendReaction(message.id, { type: 'love', user: { id: 'vishal-1' } });
86
+ // property `profile_picture` is code-completed and expects type `string | undefined`
87
+ await client.partialUpdateUser({ id: 'vishal-1', set: { profile_picture: 'https://random.picture/1.jpg' } });
88
+
89
+ // property `custom_property` is code-completed and expects type `number | undefined`
90
+ const { message } = await channel.sendMessage({ text: 'This is another test message', custom_property: 255 });
91
+
92
+ message.custom_property; // in the response object as well
100
93
  ```
101
94
 
102
- Custom types provided when initializing the client will carry through to all client returns and provide intellisense to queries.
95
+ > [!WARNING]
96
+ > Generics mechanism has been removed in version `9.0.0` in favour of the module augmentation, please see [the release guide](https://getstream.io/chat/docs/node/upgrade-stream-chat-to-v9) on how to migrate.
103
97
 
104
- ## 🔗 (Optional) Development Setup in Combination with our SDKs
98
+ ## 🔗 (Optional) Development Setup in Combination With Our SDKs
105
99
 
106
100
  ### Connect to [Stream Chat React Native SDK](https://github.com/GetStream/stream-chat-react-native)
107
101
 
108
- Run in the root of this repo
102
+ Run in the root of this repository:
109
103
 
110
- ```shell
104
+ ```sh
111
105
  yarn link
112
106
  ```
113
107
 
114
- Run in the root of one of the example apps (SampleApp/TypeScriptMessaging) in the `stream-chat-react-native` repo
108
+ Run in the root of one of the example applications (SampleApp/TypeScriptMessaging) in the `stream-chat-react-native` repository:
115
109
 
116
- ```shell
110
+ ```sh
117
111
  yarn link stream-chat
118
112
  yarn start
119
113
  ```
120
114
 
121
- Open `metro.config.js` file and set value for watchFolders as
115
+ Open `metro.config.js` file and set value for `watchFolders` as:
122
116
 
123
- ```javascript
124
- const streamChatRoot = '{{CHANGE_TO_THE_PATH_TO_YOUR_PROJECT}}/stream-chat-js'
117
+ ```js
118
+ const streamChatRoot = '<PATH TO YOUR PROJECT>/stream-chat-js'
125
119
 
126
120
  module.exports = {
127
- // the rest of the metro config goes here
121
+ // the rest of the metro configuration goes here
128
122
  ...
129
123
  watchFolders: [projectRoot].concat(alternateRoots).concat([streamChatRoot]),
130
124
  resolver: {
@@ -139,17 +133,17 @@ module.exports = {
139
133
  };
140
134
  ```
141
135
 
142
- Make sure to replace `{{CHANGE_TO_THE_PATH_TO_YOUR_PROJECT}}` with the correct path for the `stream-chat-js` folder as per your directory structure.
136
+ Make sure to replace `<PATH TO YOUR PROJECT>` with the correct path for the `stream-chat-js` folder as per your directory structure.
143
137
 
144
- Run in the root of this repo
138
+ Run in the root of this repository:
145
139
 
146
- ```shell
140
+ ```sh
147
141
  yarn start
148
142
  ```
149
143
 
150
- ## 📚 More code examples
144
+ ## 📚 More Code Examples
151
145
 
152
- Head over to [docs/typescript.md](./docs/typescript.md) for more examples.
146
+ Read up more on [Logging](./docs/logging.md) and [User Token](./docs/userToken.md) or visit our [documentation](https://getstream.io/chat/docs/) for more examples.
153
147
 
154
148
  ## ✍️ Contributing
155
149
 
@@ -157,7 +151,7 @@ We welcome code changes that improve this library or fix a problem, please make
157
151
 
158
152
  Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips.
159
153
 
160
- ## 🧑‍💻 We are hiring!
154
+ ## 🧑‍💻 We Are Hiring!
161
155
 
162
156
  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.
163
157
  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.