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: imports API endpoints #884

Merged
merged 9 commits into from
Jan 31, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added types for imports API methods
Add types for Import API endpoints

Update src/client.ts

Update src/client.ts

Update src/client.ts

Update src/types.ts

Co-Authored-By: Peter Deme <[email protected]>
gumuz and peterdeme committed Jan 28, 2022
commit 7b327b59a69c3aceb70aa6216c78100c55ff46dd
20 changes: 12 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -127,6 +127,10 @@ import {
FlagReportsPaginationOptions,
ExportUsersRequest,
ExportUsersResponse,
CreateImportResponse,
GetImportResponse,
ListImportsResponse,
ListImportsPaginationOptions,
} from './types';
import { InsightMetrics, postInsights } from './insights';

@@ -3084,10 +3088,10 @@ export class StreamChat<
* @private
* @param {string} filename filename of uploaded data
*
* @return {APIResponse} An ImportTask
* @return {APIResponse & CreateImportResponse} An ImportTask
*/
async _createImport(filename: string) {
return await this.post<APIResponse & { import_task: {}; upload_url: string }>(this.baseURL + `/imports`, {
return await this.post<APIResponse & CreateImportResponse>(this.baseURL + `/imports`, {
filename,
});
}
@@ -3102,10 +3106,10 @@ export class StreamChat<
* @private
* @param {string} id id of Import Task
*
* @return {APIResponse} An ImportTask
* @return {APIResponse & GetImportResponse} An ImportTask
*/
async _getImport(id: string) {
return await this.get<APIResponse & { import_task: {} }>(this.baseURL + `/imports/${id}`);
return await this.get<APIResponse & GetImportResponse>(this.baseURL + `/imports/${id}`);
}

/**
@@ -3116,11 +3120,11 @@ export class StreamChat<
* This function can, and will, break and/or be removed at any point in time.
*
* @private
* @param {{ limit?: number; offset?: number }} options pagination options
* @param {ListImportsPaginationOptions} options pagination options
*
* @return {APIResponse} An ImportTask
* @return {APIResponse & ListImportsResponse} An ImportTask
*/
async _listImports(options: { limit?: number; offset?: number }) {
return await this.get<APIResponse & { import_tasks: {}[] }>(this.baseURL + `/imports`, options);
async _listImports(options: ListImportsPaginationOptions) {
return await this.get<APIResponse & ListImportsResponse>(this.baseURL + `/imports`, options);
}
}
35 changes: 35 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -2137,3 +2137,38 @@ export type TruncateOptions<AttachmentType, MessageType, UserType> = {
skip_push?: boolean;
truncated_at?: Date;
};

export type CreateImportResponse = {
import_task: ImportTask;
upload_url: string;
};

export type GetImportResponse = {
import_task: ImportTask;
};

export type ListImportsPaginationOptions = {
limit?: number;
offset?: number;
};

export type ListImportsResponse = {
import_tasks: ImportTask[];
};

export type ImportTaskHistory = {
created_at: string;
next_state: string;
prev_state: string;
};

export type ImportTask = {
created_at: string;
filename: string;
history: ImportTaskHistory[];
id: string;
state: string;
updated_at: string;
result?: UR;
size?: number;
};