Skip to content

Commit

Permalink
feat: imports API endpoints (#884)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Deme <[email protected]>
  • Loading branch information
gumuz and peterdeme authored Jan 31, 2022
1 parent 0e8dd47 commit 27fccbe
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ import {
FlagReportsPaginationOptions,
ExportUsersRequest,
ExportUsersResponse,
CreateImportResponse,
GetImportResponse,
ListImportsResponse,
ListImportsPaginationOptions,
} from './types';
import { InsightMetrics, postInsights } from './insights';

Expand Down Expand Up @@ -3073,4 +3077,54 @@ export class StreamChat<
...options,
});
}

/**
* _createImport - Create an Import Task.
*
* Note: Do not use this.
* It is present for internal usage only.
* This function can, and will, break and/or be removed at any point in time.
*
* @private
* @param {string} filename filename of uploaded data
*
* @return {APIResponse & CreateImportResponse} An ImportTask
*/
async _createImport(filename: string) {
return await this.post<APIResponse & CreateImportResponse>(this.baseURL + `/imports`, {
filename,
});
}

/**
* _getImport - Get an Import Task.
*
* Note: Do not use this.
* It is present for internal usage only.
* This function can, and will, break and/or be removed at any point in time.
*
* @private
* @param {string} id id of Import Task
*
* @return {APIResponse & GetImportResponse} An ImportTask
*/
async _getImport(id: string) {
return await this.get<APIResponse & GetImportResponse>(this.baseURL + `/imports/${id}`);
}

/**
* _listImports - Lists Import Tasks.
*
* Note: Do not use this.
* It is present for internal usage only.
* This function can, and will, break and/or be removed at any point in time.
*
* @private
* @param {ListImportsPaginationOptions} options pagination options
*
* @return {APIResponse & ListImportsResponse} An ImportTask
*/
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
Expand Up @@ -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;
};

0 comments on commit 27fccbe

Please sign in to comment.