Skip to content

Commit feb97da

Browse files
fix: replace StreamChatGenerics with module augmentation (#1458)
fix: `channel_role` has been removed from the type of the `members` parameter of the `Channel.inviteMembers` method fix: properties `created_by` and `created_by_id` have been added to `ChannelData` and `ChannelQueryOptions` types BREAKING CHANGE: dropped jsDelivr bundle (#1468) BREAKING CHANGE: dropped `StreamChatGenerics`, use `Custom<Entity>Data` to extend your types BREAKING CHANGE: type `InviteOptions` has been renamed to `UpdateChannelOptions` BREAKING CHANGE: type `UpdateChannelOptions` has been renamed to `UpdateChannelTypeRequest` BREAKING CHANGE: type `ThreadResponseCustomData` has been renamed to `CustomThreadData` BREAKING CHANGE: type `MarkAllReadOptions` has been deleted in favour of type `MarkChannelsReadOptions` BREAKING CHANGE: type `QueryFilter` no longer supports `$ne` and `$nin` operators BREAKING CHANGE: type `ChannelMembership` has been deleted in favour of type `ChannelMemberResponse` BREAKING CHANGE: function `formatMessage` (`utils.ts`) no longer returns `__html` property in the formatted message output
1 parent 92a546e commit feb97da

25 files changed

+1534
-1982
lines changed

README.md

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.
2222

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/).
2424

2525
## ⚙️ Installation
2626

@@ -36,95 +36,89 @@ npm install stream-chat
3636
yarn add stream-chat
3737
```
3838

39-
### JS deliver
39+
## ✨ Getting Started
4040

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');
4445

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+
});
4650

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+
});
4856

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();
5360

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' });
5563

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' } });
5866
```
5967

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:
8269

83-
const client = StreamChat.getInstance<StreamType>('YOUR_API_KEY', 'API_KEY_SECRET');
70+
```ts
71+
// stream-custom-data.d.ts
8472

85-
// Create channel
86-
const channel = client.channel('messaging', 'TestChannel');
87-
await channel.create();
73+
import 'stream-chat';
8874

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+
}
9483

95-
// Send message
96-
const { message } = await channel.sendMessage({ text: `Test message` });
84+
// index.ts
9785

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
10093
```
10194

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.
10397
104-
## 🔗 (Optional) Development Setup in Combination with our SDKs
98+
## 🔗 (Optional) Development Setup in Combination With Our SDKs
10599

106100
### Connect to [Stream Chat React Native SDK](https://github.com/GetStream/stream-chat-react-native)
107101

108-
Run in the root of this repo
102+
Run in the root of this repository:
109103

110-
```shell
104+
```sh
111105
yarn link
112106
```
113107

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:
115109

116-
```shell
110+
```sh
117111
yarn link stream-chat
118112
yarn start
119113
```
120114

121-
Open `metro.config.js` file and set value for watchFolders as
115+
Open `metro.config.js` file and set value for `watchFolders` as:
122116

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'
125119

126120
module.exports = {
127-
// the rest of the metro config goes here
121+
// the rest of the metro configuration goes here
128122
...
129123
watchFolders: [projectRoot].concat(alternateRoots).concat([streamChatRoot]),
130124
resolver: {
@@ -139,25 +133,25 @@ module.exports = {
139133
};
140134
```
141135

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.
143137

144-
Run in the root of this repo
138+
Run in the root of this repository:
145139

146-
```shell
140+
```sh
147141
yarn start
148142
```
149143

150-
## 📚 More code examples
144+
## 📚 More Code Examples
151145

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.
153147

154148
## ✍️ Contributing
155149

156150
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.
157151

158152
Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips.
159153

160-
## 🧑‍💻 We are hiring!
154+
## 🧑‍💻 We Are Hiring!
161155

162156
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.
163157
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.

assets/logo.svg

Lines changed: 31 additions & 16 deletions
Loading

docs/typescript.md

Lines changed: 0 additions & 122 deletions
This file was deleted.

src/campaign.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { StreamChat } from './client';
2-
import { CampaignData, DefaultGenerics, ExtendableGenerics, GetCampaignOptions } from './types';
2+
import { CampaignData, GetCampaignOptions } from './types';
33

4-
export class Campaign<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
4+
export class Campaign {
55
id: string | null;
66
data?: CampaignData;
7-
client: StreamChat<StreamChatGenerics>;
7+
client: StreamChat;
88

9-
constructor(client: StreamChat<StreamChatGenerics>, id: string | null, data?: CampaignData) {
9+
constructor(client: StreamChat, id: string | null, data?: CampaignData) {
1010
this.client = client;
1111
this.id = id;
1212
this.data = data;

0 commit comments

Comments
 (0)