@yoryoboy/clickup-sdk
Version:
A modular TypeScript SDK for interacting with the ClickUp API
45 lines (44 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Manages operations related to ClickUp Teams (workspaces)
* Docs: https://clickup.com/api/clickupreference/operation/GetAuthorizedTeams/
*/
class TeamManager {
/**
* Creates a new TeamManager instance
* @param {AxiosInstance} client - Axios client configured with baseURL and auth
*/
constructor(client) {
this.client = client;
}
/**
* Get all teams (workspaces) the token has access to.
* Uses GET /team and returns the raw typed response.
*
* - No parameters required by the API.
* - Handles network and Axios errors with descriptive messages.
* - Keeps the response shape intact to avoid extra processing.
*/
async getTeams() {
try {
const res = await this.client.get("/team");
// Basic shape guard to handle unexpected API responses gracefully
if (!res?.data || !Array.isArray(res.data.teams)) {
throw new Error("Unexpected response format when fetching teams");
}
return res.data;
}
catch (err) {
// Normalize Axios/network errors for consumers of the SDK
const status = err?.response?.status;
const apiMessage = err?.response?.data?.err || err?.response?.data?.message;
const message = apiMessage || err?.message || "Unknown error";
// Provide context while preserving original error for debugging
const wrapped = new Error(`Failed to fetch teams: ${message}${status ? ` (HTTP ${status})` : ""}`);
wrapped.cause = err;
throw wrapped;
}
}
}
exports.default = TeamManager;