Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update open api and implement external storage endpoints #15

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions __tests__/external-recording-storage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { beforeAll, describe, expect, it } from 'vitest';
import { v4 as uuidv4 } from 'uuid';
import { createTestClient } from './create-test-client';
import { StreamClient } from '../src/StreamClient';

describe('external storage CRUD API', () => {
let client: StreamClient;
const storageName = `streamnodetest${uuidv4()}`;

beforeAll(() => {
client = createTestClient();
});

it('create', async () => {
const response = await client.video.createExternalStorage({
name: storageName,
bucket: 'test',
storage_type: 'test',
});

expect(response).toBeDefined();
});

it('read', async () => {
const readResponse = await client.video.listExternalStorages();

expect(readResponse.external_storages).toBeDefined();
expect(readResponse.external_storages[storageName]).toBeDefined();
});

it('update', async () => {
const newBucket = 'new bucket';
const response = await client.video.updateExternalStorage(storageName, {
bucket: newBucket,
storage_type: 'test',
});

expect(response.bucket).toBe('new bucket');
});

it('delete', async () => {
const response = await client.video.deleteExternalStorage({
name: storageName,
});

expect(response).toBeDefined();
});
});
14 changes: 7 additions & 7 deletions src/StreamCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
VideoUpdateCallMembersRequest,
VideoUpdateUserPermissionsRequest,
VideoQueryMembersRequest,
VideoStartRecordingRequest,
} from './gen/video';
import { OmitTypeId } from './types';

Expand All @@ -26,11 +27,7 @@ export class StreamCall {
private readonly id: string,
) {
this.baseRequest = { id: this.id, type: this.type };
const configuration = this.streamClient.getConfiguration({
basePath:
this.streamClient.options.basePath ??
'https://video.stream-io-api.com/video',
});
const configuration = this.streamClient.getConfiguration('video');
this.apiClient = new DefaultApi(configuration);
}

Expand Down Expand Up @@ -97,8 +94,11 @@ export class StreamCall {
return this.apiClient.startHLSBroadcasting({ ...this.baseRequest });
};

startRecording = () => {
return this.apiClient.startRecording({ ...this.baseRequest });
startRecording = (request?: VideoStartRecordingRequest) => {
return this.apiClient.startRecording({
...this.baseRequest,
videoStartRecordingRequest: request ?? {},
});
};

startTranscription = () => {
Expand Down
8 changes: 6 additions & 2 deletions src/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export class StreamClient {
}
};

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

return mapping[name];
},
basePath: options?.basePath ?? this.options.basePath,
basePath:
this.options.basePath ??
(product === 'chat'
? 'https://chat.stream-io-api.com'
: 'https://video.stream-io-api.com'),
headers: {
'X-Stream-Client': 'stream-node-' + process.env.PKG_VERSION,
},
Expand Down
43 changes: 38 additions & 5 deletions src/StreamVideoClient.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import { StreamCall } from './StreamCall';
import { StreamClient } from './StreamClient';
import {
CheckExternalStorageRequest,
DefaultApi,
DeleteCallTypeRequest,
DeleteExternalStorageRequest,
GetCallTypeRequest,
ServerSideApi,
SettingsApi,
VideoCreateCallTypeRequest,
VideoCreateExternalStorageRequest,
VideoQueryCallsRequest,
VideoUpdateCallTypeRequest,
VideoUpdateExternalStorageRequest,
} from './gen/video';

export class StreamVideoClient {
private readonly apiClient: DefaultApi;
private readonly videoServerSideApiClient: ServerSideApi;
private readonly settingsApi: SettingsApi;

constructor(private readonly streamClient: StreamClient) {
const configuration = this.streamClient.getConfiguration({
basePath:
this.streamClient.options.basePath ??
'https://video.stream-io-api.com/video',
});
const configuration = this.streamClient.getConfiguration('video');
this.apiClient = new DefaultApi(configuration);
this.settingsApi = new SettingsApi(configuration);
this.videoServerSideApiClient = new ServerSideApi(configuration);
}

Expand Down Expand Up @@ -61,4 +64,34 @@ export class StreamVideoClient {
videoUpdateCallTypeRequest,
});
};

listExternalStorages = () => {
return this.settingsApi.listExternalStorage();
};

createExternalStorage = (
videoCreateExternalStorageRequest: VideoCreateExternalStorageRequest,
) => {
return this.settingsApi.createExternalStorage({
videoCreateExternalStorageRequest,
});
};

deleteExternalStorage = (request: DeleteExternalStorageRequest) => {
return this.settingsApi.deleteExternalStorage(request);
};

updateExternalStorage = (
name: string,
videoUpdateExternalStorageRequest: VideoUpdateExternalStorageRequest,
) => {
return this.videoServerSideApiClient.updateExternalStorage({
name,
videoUpdateExternalStorageRequest,
});
};

checkExternalStorage = (request: CheckExternalStorageRequest) => {
return this.videoServerSideApiClient.checkExternalStorage(request);
};
}
1 change: 1 addition & 0 deletions src/gen/video/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.openapi-generator-ignore
apis/DefaultApi.ts
apis/ServerSideApi.ts
apis/SettingsApi.ts
apis/index.ts
index.ts
models/index.ts
Expand Down
Loading
Loading