Skip to content

Instantly share code, notes, and snippets.

@artizirk
Created July 26, 2023 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artizirk/de03f5caa334303c7871da8d4542696e to your computer and use it in GitHub Desktop.
Save artizirk/de03f5caa334303c7871da8d4542696e to your computer and use it in GitHub Desktop.
Clickup ApiService from chrome extention, includes some nondocumented API's
let ApiService = class ApiService extends ngx_oauth_client__WEBPACK_IMPORTED_MODULE_2__["NgxOAuthClient"] {
constructor(http, data, router, slimLoadingBarService) {
super(http);
this.http = http;
this.data = data;
this.router = router;
this.slimLoadingBarService = slimLoadingBarService;
this.isLoading = false;
this.showStorageErrorMsg = false;
}
requestInterceptor(request) {
setTimeout(() => {
this.isLoading = true;
this.slimLoadingBarService.start();
}, 100);
const token = this.fetchToken('access_token');
if (token) {
return request.setHeaders({ Authorization: token, sessionid: localStorage.getItem('sessionid') });
}
return request;
}
responseInterceptor(request, response) {
setTimeout(() => {
this.isLoading = false;
this.slimLoadingBarService.complete();
}, 1000);
return response;
}
errorInterceptor(request, error) {
setTimeout(() => {
this.isLoading = false;
this.slimLoadingBarService.complete();
}, 100);
if (error && error.error && error.error.ECODE && error.error.ECODE === 'GBUSED_005') {
setTimeout(() => {
this.showStorageErrorMsg = true;
}, 100);
}
return Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error);
}
getUser() {
return this.get('v1/user');
}
getTeams() {
return this.get('v1/team');
}
getSpaces(team) {
return this.get(`v1/team/${team.id}/space`);
}
getProjects(space) {
return this.get(`v1/space/${space.id}/project`);
}
getShared(team) {
return this.get(`v1/team/${team.id}/shared`);
}
getMembers(list) {
return this.get(`v2/list/${list.id}/member`);
}
createTask(list, task) {
if (task['content'] && task['content'] === '{}') {
task['content'] = JSON.stringify({ ops: [] });
}
task['from_mobile'] = true;
return this.post(`v1/list/${list.id}/task`, task);
}
getTasksN(team, space = null, project = null, list = null, status = '', parent = '') {
const params = [];
if (space) {
params.push('space_ids[]=' + space.id);
}
if (project) {
params.push('project_ids[]=' + project.id);
}
if (list) {
params.push('list_ids[]=' + list.id);
}
if (status) {
params.push('statuses[]=' + status);
}
if (parent) {
params.push('parent=' + parent);
}
params.push('order_by=order');
params.push('subtasks_by_status=true');
return this.get(`v1/team/${team.id}/task?${params.join('&')}`);
}
getTasksByIds(team, taskIds) {
const params = [];
taskIds.forEach(id => {
params.push('task_ids[]=' + id);
});
params.push('order_by=updated');
return this.get(`v1/team/${team.id}/task?${params.join('&')}`);
}
addTime(taskId, start, end, time) {
return this.post(`v1/task/${taskId}/time`, { start, end });
}
getTime(taskId) {
return this.get(`v1/task/${taskId}/time`);
}
addAttachment(taskId, formData) {
const token = this.fetchToken('access_token');
return this.post(`v1/task/${taskId}/attachment`, formData, {
headers: {
'Authorization': token,
'Content-Type': 'image/png',
'filename': 'screenshot1.png'
},
onUploadProgress: function (progressEvent) {
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
}
});
}
attachEmail(taskId, formData) {
const token = this.fetchToken('access_token');
return this.post(`v1/task/${taskId}/attachment`, formData, {
headers: {
'Authorization': token,
'Content-Type': 'multipart/form-data'
},
onUploadProgress: function (progressEvent) {
const percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
}
});
}
search(teamId, query) {
return this.get(`/v1/team/${teamId}/search`, {
query: query,
skipAttachments: true,
skipComments: true,
skipContentMatches: true
});
}
searchV2(teamId, query) {
return this.get(`/v1/team/${teamId}/searchTasks`, {
query: query,
skipAttachments: true,
skipComments: true,
skipContentMatches: true
});
}
searchSubcategories(teamId, query) {
return this.get(`/v1/team/${teamId}/subcategorySearch`, {
query: query,
filter_empty: true
});
}
searchTasksByEmailId(teamId, emailId) {
return this.get(`/v1/team/${teamId}/email_task/${emailId}`);
}
searchTasksByEmailIds(teamId, emailIds) {
const params = [];
emailIds.forEach(id => {
params.push('email_ids[]=' + id);
});
return this.get(`/v1/team/${teamId}/email_task?${params.join('&')}`);
}
createFavorite(data) {
return this.post(`/v1/favorite`, data).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
updateFavorite(id, data) {
return this.put(`/v1/favorite/${id}`, data).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
positionFavorite(id, data) {
return this.put(`/v1/favorite/${id}/position`, data).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
removeFavorite(id) {
return this.delete(`/v1/favorite/${id}?team=${this.data.defaultTeam.id}`, {
data: {
team: this.data.defaultTeam.id
}
}).pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
getFavorites(teamId) {
return this.get(`/v1/favorite/?team=${teamId}`).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
searchTasks(teamId, query, spaceId, searchSubtasks) {
return this.get(`/v1/favorite/?team=${teamId}`).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
getTasks(param, param2, id, id2, id3, true1, lastIdx, b, b2, param10) {
return this.get(`/v1/favorite/?team=${param}`).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
getTaskIds(searchParams) {
return this.get(`/v1/favorite/?team=1`).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
getAllCategories(project) {
return this.get(`/v1/team/${this.data.defaultTeam.id}/project/${project.id}/category`).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
createScratchpadNote(data) {
return this.post(`/v1/scratchpad/`, data);
}
getScratchpadNotes(showArchived = false) {
let url = `/v1/scratchpad`;
if (!showArchived) {
url += `?archived=false`;
}
return this.get(url);
}
getScratchpadNote(id) {
return this.get(`/v1/scratchpad/${id}`);
}
editScratchpadNote(noteId, data) {
return this.put(`/v1/scratchpad/${noteId}`, data).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
deleteScratchpadNotes(noteIds) {
return this.delete(`/v1/scratchpad/?note_ids[]=${noteIds}`);
}
getNoteHistory(noteId) {
return this.get(`/v1/scratchpad/${noteId}/history`).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
updateUser(updateFields) {
return this.http.put(`/v1/user`, updateFields).pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
getTask(taskId, allFields = true, showError = true, redirectOnError = true, extraParams = null) {
const searchParams = {};
if (extraParams) {
Object.keys(extraParams).filter(key => typeof extraParams[key] !== 'undefined').forEach(key => {
searchParams[key] = [extraParams[key]];
});
}
return this.get(`/v1/task/${taskId}?fields[]=simple_statuses`).
pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_7__["catchError"])(({ error }) => Object(rxjs__WEBPACK_IMPORTED_MODULE_1__["throwError"])(error)));
}
checkIsNotepadExtInstalled() {
return this.http.get('chrome-extension://kihklnbmjghmdbdnpfnbbomndgcldejl/index.html');
}
getCurrentTimer(teamId) {
return this.get(`/v2/team/${teamId}/time_entries/current`);
}
getRecentSessions(teamId) {
return this.get(`/v2/team/${teamId}/time_entries/recent`);
}
startTimer(teamId, data) {
return this.post(`/v2/team/${teamId}/time_entries/start`, data);
}
stopTimer(teamId, data) {
return this.post(`/v2/team/${teamId}/time_entries/stop`, data);
}
removeTimer(teamId, timeEntryId) {
return this.delete(`/v2/team/${teamId}/time_entries/${timeEntryId}`);
}
};
ApiService = tslib__WEBPACK_IMPORTED_MODULE_0__["__decorate"]([
Object(ngx_oauth_client__WEBPACK_IMPORTED_MODULE_2__["Configuration"])(_environments_environment__WEBPACK_IMPORTED_MODULE_3__["environment"].api),
Object(ngx_oauth_client__WEBPACK_IMPORTED_MODULE_2__["DefaultHeaders"])({
'Content-Type': 'application/json',
'Accept': 'application/json'
})
], ApiService);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment