Skip to content

Commit 73df541

Browse files
authored
feat!: update to latest open api (#42)
1 parent 4051d93 commit 73df541

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+13229
-15795
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,7 @@ $ PRODUCT=video yarn generate:open-api
4848
$ PRODUCT=chat yarn generate:open-api:dev
4949
```
5050

51-
### Fix issues in chat code
52-
53-
If you have updated the generated chat code you'll have to fix the following issues manually in the generated code:
54-
55-
- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for imports for `ImageSizeRequest`, `OnlyUserIDRequest` in the `gen/chat/FilesApi.ts` and `gen/chat/MessagesApi.ts` files
56-
- Add `/** @ts-expect-error */ ` (make sure to use this exact comment format otherwise they will be missing from `d.ts` files) for duplicate exports in `gen/chat/index.ts`
57-
58-
### Validate that the generated code works
59-
60-
To check your work, run the following commands:
61-
62-
```
63-
yarn start
64-
yarn test
65-
```
66-
67-
If these commands run fine, we're good to go.
51+
The current chat open API contains some issues, to fix some of them apply the following commit manually after updating the chat open API: [87f8672f9c302138d2c19f07b9b5236e3ba98714](https://github.com/GetStream/stream-node/pull/42/commits/87f8672f9c302138d2c19f07b9b5236e3ba98714)
6852

6953
## Release (for Stream developers)
7054

__tests__/block-lists.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import { beforeAll, describe, expect, it } from 'vitest';
22
import { v4 as uuidv4 } from 'uuid';
33
import { createTestClient } from './create-test-client';
44
import { StreamClient } from '../src/StreamClient';
5-
import { BlockList } from '../src/gen/chat';
5+
import {
6+
CreateBlockListRequest,
7+
CreateBlockListRequestTypeEnum,
8+
} from '../src/gen/chat';
69

710
describe('block lists CRUD API', () => {
811
let client: StreamClient;
9-
let blockList: BlockList;
12+
let blockList: CreateBlockListRequest;
1013

1114
beforeAll(() => {
1215
client = createTestClient();
1316
blockList = {
1417
name: 'streamnodetest-F1' + uuidv4(),
1518
words: ['Ricciardo should retire'],
19+
type: CreateBlockListRequestTypeEnum.WORD,
1620
};
1721
});
1822

__tests__/channel-types.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ describe('channel types CRUD API', () => {
1616
const response = await client.chat.createChannelType({
1717
name: channelType,
1818
automod: CreateChannelTypeRequestAutomodEnum.DISABLED,
19+
automod_behavior: 'block',
20+
max_message_length: 1200,
1921
});
2022

2123
expect(response.name).toBe(channelType);
@@ -30,13 +32,15 @@ describe('channel types CRUD API', () => {
3032
it('update', async () => {
3133
const response = await client.chat.updateChannelType(channelType, {
3234
automod: CreateChannelTypeRequestAutomodEnum.SIMPLE,
35+
automod_behavior: 'block',
36+
max_message_length: 1200,
3337
});
3438

3539
expect(response.automod).toBe(CreateChannelTypeRequestAutomodEnum.SIMPLE);
3640

3741
const getResponse = await client.chat.getChannelType({ name: channelType });
3842

39-
// @ts-expect-error typing problem
43+
// Property 'automod' does not exist on type 'Response'.
4044
expect(getResponse.automod).toBe(
4145
CreateChannelTypeRequestAutomodEnum.SIMPLE,
4246
);

__tests__/channel.test.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,30 @@ describe('channel API', () => {
3434

3535
it('create', async () => {
3636
const response = await channel.getOrCreate({
37+
// Type error: Object literal may only specify known properties, and 'name' does not exist in type 'ChannelInput'.
3738
data: { created_by_id: user.id, name: channelId },
3839
});
3940

4041
expect(response.channel?.cid).toBe(`${channel.type}:${channel.id}`);
42+
// Type error: Property 'name' does not exist on type 'ChannelResponse'
43+
expect(response.channel?.name).toBe(channelId);
4144
});
4245

43-
// it("create - without id", async () => {
44-
// const channelWithoutId = client.chat.channel('messaging');
45-
// const response = await channelWithoutId.getOrCreate({data: {created_by_id: user.id, members: [{user_id: user.id}, {user_id: user2.id}]}});
46+
it('create - without id', async () => {
47+
const channelWithoutId = client.chat.channel('messaging');
48+
const response = await channelWithoutId.getOrCreate({
49+
data: {
50+
created_by_id: user.id,
51+
// Type error: Type '{ user_id: string; }' is missing the following properties from type 'ChannelMember':
52+
// banned, channel_role, created_at, notifications_muted, and 2 more.
53+
members: [{ user_id: user.id }, { user_id: user2.id }],
54+
},
55+
});
4656

47-
// expect(response.channel?.cid).toBe(channelWithoutId.cid);
57+
expect(response.channel?.cid).toBe(channelWithoutId.cid);
4858

49-
// await channelWithoutId.delete();
50-
// });
59+
await channelWithoutId.delete();
60+
});
5161

5262
it('update', async () => {
5363
const response = await channel.update({
@@ -69,6 +79,22 @@ describe('channel API', () => {
6979
expect(response.channel?.cooldown).toBe(100);
7080
});
7181

82+
it('queryChannels', async () => {
83+
const unfilteredResponse = await client.chat.queryChannels();
84+
85+
expect(unfilteredResponse.channels.length).toBeGreaterThan(1);
86+
87+
const filteredResponse = await client.chat.queryChannels({
88+
filter_conditions: { cid: channel.cid },
89+
});
90+
91+
expect(filteredResponse.channels.length).toBe(1);
92+
93+
const channelFromResponse = filteredResponse.channels[0];
94+
95+
expect(channelFromResponse.channel?.name).toBe(channelId);
96+
});
97+
7298
it('query members', async () => {
7399
const response = await channel.queryMembers({
74100
filter_conditions: {

__tests__/devices-push.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
33
import {
44
CreateDeviceRequest,
55
CreateDeviceRequestPushProviderEnum,
6-
PushProviderRequest,
6+
PushProvider,
77
} from '../src/gen/chat';
88
import { createTestClient } from './create-test-client';
99
import { StreamClient } from '../src/StreamClient';
@@ -20,9 +20,11 @@ describe('devices and push', () => {
2020
push_provider_name: 'firebase',
2121
user_id: user.id,
2222
};
23-
const pushProvider: PushProviderRequest = {
23+
// Type '{ name: string; type: string; xiaomi_app_secret: string; xiaomi_package_name: string; }'
24+
// is missing the following properties from type 'PushProvider': created_at, updated_at
25+
const pushProvider: PushProvider = {
2426
name: 'test-push-provider',
25-
type: 'xiaomi' as any as number,
27+
type: 'xiaomi',
2628
xiaomi_app_secret: '',
2729
xiaomi_package_name: '',
2830
};

__tests__/messages.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('messages API', () => {
3535
channel = client.chat.channel('messaging', channelId);
3636
await channel.getOrCreate({
3737
data: {
38+
// Type '{ id: string; }' is missing the following properties from type 'UserObject': banned, custom, online, role
3839
created_by: { id: user.id },
3940
members: [{ user }, { user: user2 }],
4041
},
@@ -54,7 +55,7 @@ describe('messages API', () => {
5455

5556
messageId = response.message?.id;
5657

57-
const getResponse = await channel.getManyMessages({ ids: [messageId!] });
58+
const getResponse = await channel.getManyMessages({ ids: [messageId] });
5859

5960
expect(getResponse.messages.length).toBe(1);
6061
});
@@ -66,6 +67,7 @@ describe('messages API', () => {
6667
const response = await channel.updateMessage(messageId!, {
6768
message: {
6869
text: 'https://getstream.io/',
70+
// Property 'custom' is missing in type '{ image_url: string; }' but required in type 'Attachment'
6971
attachments: [urlAttachment],
7072
user_id: user.id,
7173
},
@@ -99,6 +101,7 @@ describe('messages API', () => {
99101
language: TranslateMessageRequestLanguageEnum.HU,
100102
});
101103

104+
// Property 'message' does not exist on type 'MessageResponse'.
102105
expect(response.message?.i18n?.hu_text).toBeDefined();
103106
});
104107

@@ -150,20 +153,13 @@ describe('messages API', () => {
150153
expect(response.results).toBeDefined();
151154
});
152155

153-
it('flag and unflag', async () => {
156+
it('flag', async () => {
154157
const response = await client.flag({
155158
target_message_id: messageId!,
156159
user_id: user.id,
157160
});
158161

159162
expect(response.flag?.target_message_id).toBe(messageId!);
160-
161-
const unflagResponse = await client.unflag({
162-
target_message_id: messageId!,
163-
user_id: user.id,
164-
});
165-
166-
expect(unflagResponse).toBeDefined();
167163
});
168164

169165
it('truncate', async () => {

__tests__/user-compat.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,42 @@ import { StreamClient } from '../src/StreamClient';
66
describe('user-video compatibility API', () => {
77
let client: StreamClient;
88
const user = {
9-
id: 'stream-node-test-user',
9+
id: uuidv4(),
1010
role: 'admin',
1111
name: 'Test User for user API compatibily',
1212
custom: {
1313
note: 'compatibilty test',
1414
},
1515
};
1616

17-
beforeAll(async () => {
17+
beforeAll(() => {
1818
client = createTestClient();
19-
await client.upsertUsers({
19+
});
20+
21+
it('upsert user', async () => {
22+
const user = {
23+
id: uuidv4(),
24+
role: 'admin',
25+
name: 'Test User for user API compatibily',
26+
custom: {
27+
note: 'compatibilty test',
28+
},
29+
};
30+
31+
const response = await client.upsertUsers({
2032
users: {
2133
[user.id]: { ...user },
2234
},
2335
});
36+
37+
expect(response.users[user.id].custom.note).toBe('compatibilty test');
2438
});
2539

2640
it('create call', async () => {
2741
const call = client.video.call('default', uuidv4());
2842
const response = await call.create({ data: { created_by: user } });
2943

44+
// Backend returns: {custom: { custom: { note: 'compatibilty test' } }}
3045
expect(response.call.created_by.custom.note).toBe('compatibilty test');
3146
expect(response.call.created_by.name).toBe(
3247
'Test User for user API compatibily',

__tests__/users.test.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { beforeAll, describe, expect, it } from 'vitest';
22
import { v4 as uuidv4 } from 'uuid';
33
import { createTestClient } from './create-test-client';
44
import { StreamClient } from '../src/StreamClient';
5-
import { UserObjectRequest } from '../src/gen/chat';
5+
import { UserRequest } from '../src/gen/chat';
66

77
describe('user API', () => {
88
let client: StreamClient;
99
const userId = 'streamnodetest' + uuidv4();
10-
const newUser: UserObjectRequest = {
10+
const newUser: UserRequest = {
1111
id: userId,
1212
role: 'user',
1313
custom: {
@@ -80,7 +80,7 @@ describe('user API', () => {
8080
it('create guest', async () => {
8181
await client.updateAppSettings({ multi_tenant_enabled: false });
8282

83-
const guest: UserObjectRequest = {
83+
const guest: UserRequest = {
8484
id: uuidv4(),
8585
custom: {
8686
color: 'red',
@@ -132,14 +132,41 @@ describe('user API', () => {
132132
expect(muteResponse.mute?.target?.id).toBe(newUser.id);
133133

134134
const unmuteResponse = await client.unmuteUser({
135-
target_id: newUser.id,
136-
target_ids: [],
135+
target_ids: [newUser.id],
137136
user_id: user.id,
138137
});
139138

140139
expect(unmuteResponse).toBeDefined();
141140
});
142141

142+
it('block and unblock', async () => {
143+
const badUser: UserRequest = {
144+
id: 'bad-alice',
145+
name: 'Alice',
146+
};
147+
await client.upsertUsers({ users: { [badUser.id]: badUser } });
148+
149+
const blockResponse = await client.blockUsers({
150+
blocked_user_id: badUser.id,
151+
user_id: user.id,
152+
});
153+
154+
expect(blockResponse.blocked_user_id).toBe(badUser.id);
155+
156+
const blockedUsers = await client.getBlockedUsers({ userId: user.id });
157+
158+
expect(
159+
blockedUsers.blocks.find((b) => b.blocked_user_id === badUser.id),
160+
).toBeDefined();
161+
162+
const unblockResponse = await client.unblockUsers({
163+
blocked_user_id: badUser.id,
164+
user_id: user.id,
165+
});
166+
167+
expect(unblockResponse.duration).toBeDefined();
168+
});
169+
143170
it('send custom event', async () => {
144171
const response = await client.sendCustomEventToUser(newUser.id, {
145172
type: 'my-custom-event',
@@ -155,7 +182,9 @@ describe('user API', () => {
155182
id: newUser.id,
156183
set: {
157184
role: 'admin',
158-
color: 'blue',
185+
custom: {
186+
color: 'blue',
187+
},
159188
},
160189
unset: ['name'],
161190
},

generate-openapi.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ if [ "$PRODUCT" == 'video' ] || [ "$PRODUCT" == 'all' ] ; then
2121
PROTOCOL_REPO_DIR="../protocol"
2222
fi
2323
if [ "$FROM_REPO" == 'chat' ]; then
24-
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/video-openapi.yaml"
24+
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/v2/video-openapi.yaml"
2525
else
2626
SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/video-openapi.yaml"
2727
fi
2828

2929
if [ "$FROM_REPO" == 'chat' ]; then
3030
# Generate the Coordinator OpenAPI schema
31-
make -C $PROTOCOL_REPO_DIR video-openapi
31+
make -C $PROTOCOL_REPO_DIR openapi
3232
fi
3333

3434
OUTPUT_DIR="./src/gen/video"
@@ -64,14 +64,14 @@ if [ "$PRODUCT" == 'chat' ] || [ "$PRODUCT" == 'all' ]; then
6464
PROTOCOL_REPO_DIR="../protocol"
6565
fi
6666
if [ "$FROM_REPO" == 'chat' ]; then
67-
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/chat-openapi.yaml"
67+
SCHEMA_FILE="$PROTOCOL_REPO_DIR/releases/v2/chat-serverside-api.yaml"
6868
else
6969
SCHEMA_FILE="$PROTOCOL_REPO_DIR/openapi/chat-openapi.yaml"
7070
fi
7171

7272
if [ "$FROM_REPO" == 'chat' ]; then
7373
# Generate the Coordinator OpenAPI schema
74-
make -C $PROTOCOL_REPO_DIR chat-openapi
74+
make -C $PROTOCOL_REPO_DIR openapi
7575
fi
7676

7777
OUTPUT_DIR="./src/gen/chat"
@@ -91,7 +91,9 @@ if [ "$PRODUCT" == 'chat' ] || [ "$PRODUCT" == 'all' ]; then
9191
--additional-properties=supportsES6=true \
9292
--additional-properties=modelPropertyNaming=original \
9393
--additional-properties=enumPropertyNaming=UPPERCASE \
94-
--additional-properties=withoutRuntimeChecks=true
94+
--additional-properties=withoutRuntimeChecks=true \
95+
--global-property=skipFormModel=false \
96+
--skip-validate-spec
9597

9698
# Remove the generated API client, just keep the models
9799
cp -r $TEMP_OUTPUT_DIR/ $OUTPUT_DIR

0 commit comments

Comments
 (0)