2022-12-13 07:37:49 -05:00
|
|
|
import Request from 'request'
|
|
|
|
|
|
|
|
const request = Request.defaults({
|
2024-04-25 08:56:00 -04:00
|
|
|
baseUrl: 'http://127.0.0.1:3010',
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
2016-12-14 12:38:14 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
async function asyncRequest(options) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await new Promise((resolve, reject) => {
|
2022-01-10 04:29:32 -05:00
|
|
|
request(options, (err, response, body) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
} else {
|
|
|
|
resolve({ response, body })
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function sendGlobalMessage(projectId, userId, content) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-01-10 04:29:32 -05:00
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2016-12-16 11:52:50 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function getGlobalMessages(projectId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-01-10 04:29:32 -05:00
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/messages`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function sendMessage(projectId, threadId, userId, content) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-01-10 04:29:32 -05:00
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-04 08:51:08 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function getThreads(projectId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-01-10 04:29:32 -05:00
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/threads`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function resolveThread(projectId, threadId, userId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-01-10 04:29:32 -05:00
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/resolve`,
|
|
|
|
json: {
|
|
|
|
user_id: userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2024-05-21 11:50:40 -04:00
|
|
|
export async function getResolvedThreadIds(projectId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2024-05-21 11:50:40 -04:00
|
|
|
method: 'get',
|
|
|
|
url: `/project/${projectId}/resolved-thread-ids`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function editMessage(projectId, threadId, messageId, content) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-01-10 04:29:32 -05:00
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 14:14:11 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function editMessageWithUser(
|
2022-03-31 03:54:33 -04:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
messageId,
|
|
|
|
userId,
|
|
|
|
content
|
|
|
|
) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-03-31 03:54:33 -04:00
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}/edit`,
|
|
|
|
json: {
|
|
|
|
content,
|
|
|
|
userId,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-04 10:07:58 -05:00
|
|
|
export async function checkStatus() {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2023-01-04 10:07:58 -05:00
|
|
|
method: 'get',
|
|
|
|
url: `/status`,
|
|
|
|
json: true,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-01-05 06:42:34 -05:00
|
|
|
export async function getMetric(matcher) {
|
|
|
|
const { body } = await asyncRequest({
|
|
|
|
method: 'get',
|
|
|
|
url: `/metrics`,
|
|
|
|
})
|
|
|
|
const found = body.split('\n').find(matcher)
|
|
|
|
if (!found) return 0
|
|
|
|
return parseInt(found.split(' ')[1], 0)
|
|
|
|
}
|
|
|
|
|
2023-01-04 10:07:58 -05:00
|
|
|
export async function reopenThread(projectId, threadId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2023-01-04 10:07:58 -05:00
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/reopen`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function deleteThread(projectId, threadId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2023-01-04 10:07:58 -05:00
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function deleteMessage(projectId, threadId, messageId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-01-10 04:29:32 -05:00
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}/thread/${threadId}/messages/${messageId}`,
|
|
|
|
})
|
|
|
|
}
|
2018-12-20 14:14:11 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
export async function destroyProject(projectId) {
|
2024-05-22 05:37:08 -04:00
|
|
|
return await asyncRequest({
|
2022-03-16 08:20:52 -04:00
|
|
|
method: 'delete',
|
|
|
|
url: `/project/${projectId}`,
|
|
|
|
})
|
|
|
|
}
|
2024-06-10 04:39:59 -04:00
|
|
|
|
|
|
|
export async function duplicateCommentThreads(projectId, threads) {
|
|
|
|
return await asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/duplicate-comment-threads`,
|
|
|
|
json: {
|
|
|
|
threads,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
2024-06-10 08:02:56 -04:00
|
|
|
|
|
|
|
export async function generateThreadData(projectId, threads) {
|
|
|
|
return await asyncRequest({
|
|
|
|
method: 'post',
|
|
|
|
url: `/project/${projectId}/generate-thread-data`,
|
|
|
|
json: {
|
|
|
|
threads,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|