@markwharton/liquidplanner 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * @see https://api-docs.liquidplanner.com/
8
8
  */
9
- import type { LPConfig, LPWorkspace, LPMember, LPItem, LPCostCode, LPSyncResult, LPTimesheetEntry, LPTimesheetEntryWithId, LPUpsertOptions } from './types.js';
9
+ import type { LPConfig, LPWorkspace, LPMember, LPItem, LPCostCode, LPSyncResult, LPTimesheetEntry, LPTimesheetEntryWithId, LPUpsertOptions, LPAssignmentWithContext } from './types.js';
10
10
  /**
11
11
  * LiquidPlanner API Client
12
12
  *
@@ -83,6 +83,22 @@ export declare class LPClient {
83
83
  assignments?: LPItem[];
84
84
  error?: string;
85
85
  }>;
86
+ /**
87
+ * Get assignments for a member with parent task names resolved
88
+ *
89
+ * This is a convenience method that fetches assignments and enriches
90
+ * them with parent task names in a single call (batched internally).
91
+ *
92
+ * @param memberId - The member ID to get assignments for
93
+ * @param options - Options for including additional context
94
+ * @param options.includeProject - If true, also fetch grandparent project names
95
+ */
96
+ getMyAssignmentsWithContext(memberId: number, options?: {
97
+ includeProject?: boolean;
98
+ }): Promise<{
99
+ assignments?: LPAssignmentWithContext[];
100
+ error?: string;
101
+ }>;
86
102
  /**
87
103
  * Get all cost codes in the workspace (with pagination)
88
104
  */
package/dist/client.js CHANGED
@@ -183,6 +183,55 @@ export class LPClient {
183
183
  });
184
184
  return error ? { error } : { assignments: results };
185
185
  }
186
+ /**
187
+ * Get assignments for a member with parent task names resolved
188
+ *
189
+ * This is a convenience method that fetches assignments and enriches
190
+ * them with parent task names in a single call (batched internally).
191
+ *
192
+ * @param memberId - The member ID to get assignments for
193
+ * @param options - Options for including additional context
194
+ * @param options.includeProject - If true, also fetch grandparent project names
195
+ */
196
+ async getMyAssignmentsWithContext(memberId, options) {
197
+ // 1. Get raw assignments
198
+ const { assignments, error } = await this.getMyAssignments(memberId);
199
+ if (error || !assignments)
200
+ return { error };
201
+ if (assignments.length === 0)
202
+ return { assignments: [] };
203
+ // 2. Extract unique parent IDs (tasks)
204
+ const taskIds = [...new Set(assignments.map(a => a.parentId).filter((id) => id !== undefined))];
205
+ // 3. Batch fetch all parent tasks
206
+ const taskResults = await Promise.all(taskIds.map(id => this.getItem(id)));
207
+ const taskMap = new Map();
208
+ for (const result of taskResults) {
209
+ if (result.item)
210
+ taskMap.set(result.item.id, result.item);
211
+ }
212
+ // 4. Optionally fetch grandparent projects
213
+ let projectMap = new Map();
214
+ if (options?.includeProject) {
215
+ const projectIds = [...new Set([...taskMap.values()].map(t => t.parentId).filter((id) => id !== undefined))];
216
+ const projectResults = await Promise.all(projectIds.map(id => this.getItem(id)));
217
+ for (const result of projectResults) {
218
+ if (result.item)
219
+ projectMap.set(result.item.id, result.item);
220
+ }
221
+ }
222
+ // 5. Merge context into assignments
223
+ return {
224
+ assignments: assignments.map(a => {
225
+ const task = a.parentId ? taskMap.get(a.parentId) : undefined;
226
+ const project = task?.parentId ? projectMap.get(task.parentId) : undefined;
227
+ return {
228
+ ...a,
229
+ taskName: task?.name ?? '-',
230
+ projectName: project?.name,
231
+ };
232
+ }),
233
+ };
234
+ }
186
235
  // ============================================================================
187
236
  // Cost Codes
188
237
  // ============================================================================
package/dist/index.d.ts CHANGED
@@ -28,7 +28,7 @@
28
28
  */
29
29
  export { LPClient } from './client.js';
30
30
  export { resolveTaskToAssignment } from './workflows.js';
31
- export type { LPConfig, LPItemType, LPItem, LPWorkspace, LPMember, LPCostCode, LPSyncResult, LPTimesheetEntry, LPTimesheetEntryWithId, LPTaskResolution, LPResult, LPUpsertOptions, } from './types.js';
31
+ export type { LPConfig, LPItemType, LPItem, LPWorkspace, LPMember, LPCostCode, LPSyncResult, LPTimesheetEntry, LPTimesheetEntryWithId, LPTaskResolution, LPResult, LPUpsertOptions, LPAssignmentWithContext, } from './types.js';
32
32
  export { hoursToMinutes, normalizeItemType, buildAuthHeader, filterIs, filterIn, paginatedFetch, } from './utils.js';
33
33
  export type { PaginateOptions } from './utils.js';
34
34
  export { LP_API_BASE, DEFAULT_ITEM_NAME, DEFAULT_ASSIGNMENT_NAME, } from './constants.js';
package/dist/types.d.ts CHANGED
@@ -147,3 +147,15 @@ export interface LPUpsertOptions {
147
147
  */
148
148
  accumulate?: boolean;
149
149
  }
150
+ /**
151
+ * Assignment with resolved parent context
152
+ *
153
+ * Extends LPItem with additional fields for the parent task name,
154
+ * grandparent project name, and cost code name.
155
+ */
156
+ export interface LPAssignmentWithContext extends LPItem {
157
+ /** Parent task name */
158
+ taskName?: string;
159
+ /** Grandparent project name (if requested) */
160
+ projectName?: string;
161
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markwharton/liquidplanner",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "LiquidPlanner API client for timesheet integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",