Skip to content

Commit fcd75e0

Browse files
authored
feat: update open api and implement external storage endpoints (#15)
1 parent 21b4f92 commit fcd75e0

File tree

12 files changed

+866
-1407
lines changed

12 files changed

+866
-1407
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { beforeAll, describe, expect, it } from 'vitest';
2+
import { v4 as uuidv4 } from 'uuid';
3+
import { createTestClient } from './create-test-client';
4+
import { StreamClient } from '../src/StreamClient';
5+
6+
describe('external storage CRUD API', () => {
7+
let client: StreamClient;
8+
const storageName = `streamnodetest${uuidv4()}`;
9+
10+
beforeAll(() => {
11+
client = createTestClient();
12+
});
13+
14+
it('create', async () => {
15+
const response = await client.video.createExternalStorage({
16+
name: storageName,
17+
bucket: 'test',
18+
storage_type: 'test',
19+
});
20+
21+
expect(response).toBeDefined();
22+
});
23+
24+
it('read', async () => {
25+
const readResponse = await client.video.listExternalStorages();
26+
27+
expect(readResponse.external_storages).toBeDefined();
28+
expect(readResponse.external_storages[storageName]).toBeDefined();
29+
});
30+
31+
it('update', async () => {
32+
const newBucket = 'new bucket';
33+
const response = await client.video.updateExternalStorage(storageName, {
34+
bucket: newBucket,
35+
storage_type: 'test',
36+
});
37+
38+
expect(response.bucket).toBe('new bucket');
39+
});
40+
41+
it('delete', async () => {
42+
const response = await client.video.deleteExternalStorage({
43+
name: storageName,
44+
});
45+
46+
expect(response).toBeDefined();
47+
});
48+
});

src/StreamCall.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
VideoUpdateCallMembersRequest,
1414
VideoUpdateUserPermissionsRequest,
1515
VideoQueryMembersRequest,
16+
VideoStartRecordingRequest,
1617
} from './gen/video';
1718
import { OmitTypeId } from './types';
1819

@@ -26,11 +27,7 @@ export class StreamCall {
2627
private readonly id: string,
2728
) {
2829
this.baseRequest = { id: this.id, type: this.type };
29-
const configuration = this.streamClient.getConfiguration({
30-
basePath:
31-
this.streamClient.options.basePath ??
32-
'https://video.stream-io-api.com/video',
33-
});
30+
const configuration = this.streamClient.getConfiguration('video');
3431
this.apiClient = new DefaultApi(configuration);
3532
}
3633

@@ -97,8 +94,11 @@ export class StreamCall {
9794
return this.apiClient.startHLSBroadcasting({ ...this.baseRequest });
9895
};
9996

100-
startRecording = () => {
101-
return this.apiClient.startRecording({ ...this.baseRequest });
97+
startRecording = (request?: VideoStartRecordingRequest) => {
98+
return this.apiClient.startRecording({
99+
...this.baseRequest,
100+
videoStartRecordingRequest: request ?? {},
101+
});
102102
};
103103

104104
startTranscription = () => {

src/StreamClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ export class StreamClient {
443443
}
444444
};
445445

446-
getConfiguration = (options?: { basePath?: string }) => {
446+
getConfiguration = (product: 'chat' | 'video' = 'chat') => {
447447
return new Configuration({
448448
apiKey: (name: string) => {
449449
const mapping: Record<string, string> = {
@@ -454,7 +454,11 @@ export class StreamClient {
454454

455455
return mapping[name];
456456
},
457-
basePath: options?.basePath ?? this.options.basePath,
457+
basePath:
458+
this.options.basePath ??
459+
(product === 'chat'
460+
? 'https://chat.stream-io-api.com'
461+
: 'https://video.stream-io-api.com'),
458462
headers: {
459463
'X-Stream-Client': 'stream-node-' + process.env.PKG_VERSION,
460464
},

src/StreamVideoClient.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
import { StreamCall } from './StreamCall';
22
import { StreamClient } from './StreamClient';
33
import {
4+
CheckExternalStorageRequest,
45
DefaultApi,
56
DeleteCallTypeRequest,
7+
DeleteExternalStorageRequest,
68
GetCallTypeRequest,
79
ServerSideApi,
10+
SettingsApi,
811
VideoCreateCallTypeRequest,
12+
VideoCreateExternalStorageRequest,
913
VideoQueryCallsRequest,
1014
VideoUpdateCallTypeRequest,
15+
VideoUpdateExternalStorageRequest,
1116
} from './gen/video';
1217

1318
export class StreamVideoClient {
1419
private readonly apiClient: DefaultApi;
1520
private readonly videoServerSideApiClient: ServerSideApi;
21+
private readonly settingsApi: SettingsApi;
1622

1723
constructor(private readonly streamClient: StreamClient) {
18-
const configuration = this.streamClient.getConfiguration({
19-
basePath:
20-
this.streamClient.options.basePath ??
21-
'https://video.stream-io-api.com/video',
22-
});
24+
const configuration = this.streamClient.getConfiguration('video');
2325
this.apiClient = new DefaultApi(configuration);
26+
this.settingsApi = new SettingsApi(configuration);
2427
this.videoServerSideApiClient = new ServerSideApi(configuration);
2528
}
2629

@@ -61,4 +64,34 @@ export class StreamVideoClient {
6164
videoUpdateCallTypeRequest,
6265
});
6366
};
67+
68+
listExternalStorages = () => {
69+
return this.settingsApi.listExternalStorage();
70+
};
71+
72+
createExternalStorage = (
73+
videoCreateExternalStorageRequest: VideoCreateExternalStorageRequest,
74+
) => {
75+
return this.settingsApi.createExternalStorage({
76+
videoCreateExternalStorageRequest,
77+
});
78+
};
79+
80+
deleteExternalStorage = (request: DeleteExternalStorageRequest) => {
81+
return this.settingsApi.deleteExternalStorage(request);
82+
};
83+
84+
updateExternalStorage = (
85+
name: string,
86+
videoUpdateExternalStorageRequest: VideoUpdateExternalStorageRequest,
87+
) => {
88+
return this.videoServerSideApiClient.updateExternalStorage({
89+
name,
90+
videoUpdateExternalStorageRequest,
91+
});
92+
};
93+
94+
checkExternalStorage = (request: CheckExternalStorageRequest) => {
95+
return this.videoServerSideApiClient.checkExternalStorage(request);
96+
};
6497
}

src/gen/video/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.openapi-generator-ignore
22
apis/DefaultApi.ts
33
apis/ServerSideApi.ts
4+
apis/SettingsApi.ts
45
apis/index.ts
56
index.ts
67
models/index.ts

0 commit comments

Comments
 (0)