basecamp-api-v3
Version:
This TypeScript library provides an API wrapper for interacting with Basecamp resources, including People, Projects, Todo Sets, Todo Lists, Comments, and Authorization.
73 lines (72 loc) • 3.54 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateAComment = exports.createAComment = exports.getAComment = exports.getComments = void 0;
const fetchWithRetry_1 = require("../utils/fetchWithRetry");
const getComments = (params) => __awaiter(void 0, void 0, void 0, function* () {
let allComments = [];
let page = 1;
while (true) {
const url = `https://3.basecampapi.com/${params.accountId}/buckets/${params.projectId}/recordings/${params.recordingId}/comments.json?page=${page}`;
const options = {
method: 'get',
headers: { Authorization: `Bearer ${params.authorization}` }
};
const result = yield (0, fetchWithRetry_1.fetchDataWithRetry)({ url, options });
if (!result.success) {
console.error(`Failed to fetch comments: ${result.message}`);
return [];
}
if (!result.data || result.data.length === 0)
break;
allComments = [...allComments, ...result.data];
page++;
}
return { success: true, status: 200, data: allComments, message: 'Success' };
});
exports.getComments = getComments;
const getAComment = (params) => __awaiter(void 0, void 0, void 0, function* () {
const url = `https://3.basecampapi.com/${params.accountId}/buckets/${params.projectId}/comments/${params.commentId}.json`;
const options = {
method: 'get',
headers: { Authorization: `Bearer ${params.authorization}` }
};
return yield (0, fetchWithRetry_1.fetchDataWithRetry)({ url, options });
});
exports.getAComment = getAComment;
const createAComment = (params) => __awaiter(void 0, void 0, void 0, function* () {
const url = `https://3.basecampapi.com/${params.accountId}/buckets/${params.projectId}/recordings/${params.recordingId}/comments.json`;
const options = {
method: "post",
headers: {
Authorization: `Bearer ${params.authorization}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ content: params.content }),
muteHttpExceptions: true
};
return (0, fetchWithRetry_1.fetchDataWithRetry)({ url, options });
});
exports.createAComment = createAComment;
const updateAComment = (params) => __awaiter(void 0, void 0, void 0, function* () {
const url = `https://3.basecampapi.com/${params.accountId}/buckets/${params.projectId}/comments/${params.commentId}.json`;
const options = {
method: "put",
headers: {
Authorization: `Bearer ${params.authorization}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ content: params.content }),
muteHttpExceptions: true
};
return (0, fetchWithRetry_1.fetchDataWithRetry)({ url, options });
});
exports.updateAComment = updateAComment;
;