@ 关键路径/客户端
Type-safet JavaScript/TypeScript HTTP客户端 SDK 为关键路径.
升级? 升级一次
@critical-path/*组合在一起。 编码代理: 遵循 更新(md); 已标记断开的更改 刹车 此软件包中CHANGELOG.md。 。 。 .
@critical-path/client 提供轻量级,端到端类型安全的SDK,用于与来自任何网络或节点.js应用程序的临界路径REST API端点进行交互.
* 安装
npm install @critical-path/client
# or
pnpm add @critical-path/client
使用示例
import { CriticalPathClient } from '@critical-path/client';
const client = new CriticalPathClient({
baseUrl: '/api/critical-path'
});
// Fetch projects
const projects = await client.getProjects();
// Fetch tasks for a project
const tasks = await client.getTasks('proj_1'); // every task, following pagination
// One page at a time, with filters
const { items, nextCursor } = await client.queryTasks({ projectId: 'proj_1', status: ['todo', 'in_progress'], limit: 50 });
// Create a new task
const newTask = await client.createTask({
projectId: 'proj_1',
title: 'Design UI Wireframes',
priority: 'high',
status: 'todo'
});
// Identity comes from your auth headers (resolved by the server's getContext), never from
// request bodies. Without auth, writes are attributed to "anonymous".
// Update task status
await client.updateTask(newTask.id, { status: 'in_progress' });
// Add threaded comment
const comment = await client.addComment({
taskId: newTask.id,
content: 'Initial implementation ready for review'
}); // authored by the caller the server resolves from your auth headers
// Add emoji reaction
await client.addCommentReaction(comment.id, { emoji: '🚀' });
// Remove emoji reaction
await client.removeCommentReaction(comment.id, { emoji: '🚀' });
// Upload file directly or register storage attachment
const attachment = await client.uploadAttachmentFile({
filename: 'architecture.png',
data: fileBuffer,
mimeType: 'image/png',
taskId: newTask.id,
commentId: comment.id
}); // binary data is base64-encoded automatically
// Calculate Critical Path Method (CPM) schedule & bottlenecks
const cpmAnalysis = await client.calculateCriticalPath('proj_1'); // or { calendars: 'assignee', levelResources: true }
const portfolio = await client.calculatePortfolioCriticalPath({ projectIds: ['proj_1', 'proj_2'], calendars: 'assignee', levelResources: true });
// Options on both: effort: 'remaining'; on portfolio: includeHiddenWork, projectOrder
console.log('Total project duration:', cpmAnalysis.totalDurationHours);
console.log('Bottleneck tasks:', cpmAnalysis.criticalTaskIds);
// Ladder of Abstraction (macro, standard, concrete rungs)
const ladder = await client.getTimelineLadder('proj_1', { level: 'all' });
console.log('Macro phase progress:', ladder.macro?.overallProgressPercentage);
console.log('Standard Gantt items:', ladder.standard?.tasks.length);
console.log('Concrete deliverables & daily effort:', ladder.concrete);
// Single task ladder drilldown
const taskLadder = await client.getTaskLadder(newTask.id);
QQ 配置
const client = new CriticalPathClient({
baseUrl: '/api/critical-path',
// Static headers, or a function called before every request (e.g. to refresh tokens)
headers: async () => ({ Authorization: `Bearer ${await auth.getAccessToken()}` }),
timeoutMs: 15_000, // abort slow requests (default: none)
retry: { retries: 2, baseDelayMs: 250 }, // GET only: network errors, 429, 502-504 (default: off)
fetch: customFetch // optional fetch implementation
});
注销和每个呼叫标题
with() 返回对每次调用都应用选项的有范围客户端:
const controller = new AbortController();
const tasks = await client.with({ signal: controller.signal }).getTasks(projectId);
// later, e.g. when a component unmounts:
controller.abort();
await client.with({ headers: { 'X-Request-Id': id }, timeoutMs: 5_000 }).getProject(projectId);
错误
非-2xx 响应抛出 CriticalPathError数字 :
import { CriticalPathError } from '@critical-path/client';
try {
await client.addDependency(taskId, { dependsOnTaskId });
} catch (err) {
if (err instanceof CriticalPathError) {
err.status; // e.g. 409
err.issues; // field-level problems for 400 validation errors
err.body?.cyclePath; // the rest of the server's error body
}
}
删除方法解析到 false 而不是在资源不存在时投掷。 网络故障、 超时( E)TimeoutError)和取消(AbortError)被抛出一地.
每个服务器路径都有客户端方法; 3; routes.test.ts 如果添加一条没有一条路由, 则失败 .
许可证
麻省理工学院 关键路径