@markwharton/liquidplanner 2.1.2 → 2.3.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/README.md CHANGED
@@ -200,6 +200,7 @@ const client = new LPClient({
200
200
  baseUrl: '...', // Optional: override API base URL
201
201
  onRequest: ({ method, url, description }) => { ... }, // Optional: debug callback
202
202
  cache: {}, // Optional: enable TTL caching (defaults below)
203
+ cacheInstance: cache, // Optional: custom cache backend (e.g., LayeredCache)
203
204
  retry: { // Optional: retry on 429/503
204
205
  maxRetries: 3,
205
206
  initialDelayMs: 1000,
@@ -208,7 +209,7 @@ const client = new LPClient({
208
209
  });
209
210
  ```
210
211
 
211
- `LPConfig` extends `ClientConfig` from api-core, which provides the `baseUrl`, `onRequest`, and `retry` fields. `apiToken`, `workspaceId`, and `cache` are LP-specific.
212
+ `LPConfig` extends `ClientConfig` from api-core, which provides the `baseUrl`, `onRequest`, `retry`, and `cacheInstance` fields. `apiToken`, `workspaceId`, and `cache` are LP-specific. Pass `cacheInstance` to use a custom cache backend (e.g., `LayeredCache` with persistent stores); otherwise `cache: {}` creates an in-memory `TTLCache`.
212
213
 
213
214
  ### Cache TTLs
214
215
 
@@ -223,6 +224,8 @@ const client = new LPClient({
223
224
 
224
225
  Write operations (`createTimesheetEntry`, `updateTimesheetEntry`) automatically invalidate timesheet cache entries. Call `client.invalidateTreeCache()` to refresh the workspace tree, or `client.clearCache()` to clear all cached data.
225
226
 
227
+ Failed API results (`ok: false`) are never cached — transient errors won't persist for the full TTL. See the [root README Cache System section](../../README.md#cache-system) for the full cache architecture (layered stores, PII handling, request coalescing).
228
+
226
229
  ### Retry
227
230
 
228
231
  Automatically retries on HTTP 429 (Too Many Requests) and 503 (Service Unavailable) with exponential backoff. Respects the `Retry-After` header when present.
package/dist/client.d.ts CHANGED
@@ -41,6 +41,8 @@ export declare class LPClient {
41
41
  constructor(config: LPConfig);
42
42
  /**
43
43
  * Route through cache if enabled, otherwise call factory directly.
44
+ * Failed Results (ok === false) are never cached — transient errors
45
+ * shouldn't persist for the full TTL.
44
46
  */
45
47
  private cached;
46
48
  /**
package/dist/client.js CHANGED
@@ -114,8 +114,8 @@ export class LPClient {
114
114
  this.baseUrl = config.baseUrl ?? LP_API_BASE;
115
115
  this.onRequest = config.onRequest;
116
116
  // Initialize cache if configured
117
- if (config.cache) {
118
- this.cache = new TTLCache();
117
+ if (config.cache || config.cacheInstance) {
118
+ this.cache = config.cacheInstance ?? new TTLCache();
119
119
  }
120
120
  this.cacheTtl = {
121
121
  membersTtl: config.cache?.membersTtl ?? 300000,
@@ -130,12 +130,16 @@ export class LPClient {
130
130
  }
131
131
  /**
132
132
  * Route through cache if enabled, otherwise call factory directly.
133
+ * Failed Results (ok === false) are never cached — transient errors
134
+ * shouldn't persist for the full TTL.
133
135
  */
134
- async cached(key, ttlMs, factory) {
135
- if (this.cache) {
136
- return this.cache.get(key, ttlMs, factory);
137
- }
138
- return factory();
136
+ async cached(key, ttlMs, factory, options) {
137
+ if (!this.cache)
138
+ return factory();
139
+ return this.cache.get(key, ttlMs, factory, {
140
+ ...options,
141
+ shouldCache: (data) => data.ok !== false,
142
+ });
139
143
  }
140
144
  /**
141
145
  * Clear all cached API responses.
package/dist/index.d.ts CHANGED
@@ -31,8 +31,10 @@
31
31
  export { LPClient } from './client.js';
32
32
  export { resolveTaskToAssignment } from './workflows.js';
33
33
  export type { LPConfig, LPCacheConfig, LPRetryConfig, LPItemType, HierarchyItem, LPItem, LPAncestor, LPWorkspace, LPMember, LPCostCode, LPSyncResult, LPTimesheetEntry, LPTimesheetEntryWithId, LPTaskResolution, LPUpsertOptions, LPAssignmentWithContext, LPFindItemsOptions, LPTreeNode, LPWorkspaceTree, } from './types.js';
34
- export { ok, err, getErrorMessage } from '@markwharton/api-core';
35
- export type { Result, RetryConfig, OnRequestCallback, ClientConfig } from '@markwharton/api-core';
34
+ export type { AccessTier } from './types.js';
35
+ export { METHOD_TIERS } from './types.js';
36
+ export { ok, err, getErrorMessage, TTLCache, MemoryCacheStore, LayeredCache } from '@markwharton/api-core';
37
+ export type { Result, RetryConfig, OnRequestCallback, ClientConfig, Cache, CacheStore, CacheGetOptions } from '@markwharton/api-core';
36
38
  export { hoursToMinutes, normalizeItemType, buildAuthHeader, filterIs, filterIsNot, filterIn, filterGt, filterLt, filterAfter, filterBefore, joinFilters, paginatedFetch, } from './utils.js';
37
39
  export type { PaginateOptions } from './utils.js';
38
40
  export { buildTree, getTreeAncestors, getTreeHierarchyPath, findInTree, } from './tree.js';
package/dist/index.js CHANGED
@@ -32,8 +32,9 @@
32
32
  export { LPClient } from './client.js';
33
33
  // Workflows
34
34
  export { resolveTaskToAssignment } from './workflows.js';
35
+ export { METHOD_TIERS } from './types.js';
35
36
  // Re-exported from @markwharton/api-core
36
- export { ok, err, getErrorMessage } from '@markwharton/api-core';
37
+ export { ok, err, getErrorMessage, TTLCache, MemoryCacheStore, LayeredCache } from '@markwharton/api-core';
37
38
  // Utilities
38
39
  export { hoursToMinutes, normalizeItemType, buildAuthHeader, filterIs, filterIsNot, filterIn, filterGt, filterLt, filterAfter, filterBefore, joinFilters, paginatedFetch, } from './utils.js';
39
40
  // Tree utilities
package/dist/types.d.ts CHANGED
@@ -206,6 +206,8 @@ export interface LPConfig extends ClientConfig {
206
206
  apiToken: string;
207
207
  /** Enable caching with optional TTL overrides. Omit to disable caching. */
208
208
  cache?: LPCacheConfig;
209
+ /** Whether to persist restricted-tier data in persistent cache stores (default: true). Set false to keep restricted data in memory only. */
210
+ persistRestricted?: boolean;
209
211
  }
210
212
  /**
211
213
  * Result of a timesheet sync operation
@@ -336,3 +338,12 @@ export interface LPWorkspaceTree {
336
338
  /** Total number of items in the tree */
337
339
  itemCount: number;
338
340
  }
341
+ /** Access tier for method-level authorization */
342
+ export type AccessTier = 'standard' | 'restricted';
343
+ /**
344
+ * Access tier for each data method.
345
+ *
346
+ * All LP methods are standard tier — LP data is workspace-scoped, not employee-scoped.
347
+ * Utility methods (validate, clear, invalidate) are not included.
348
+ */
349
+ export declare const METHOD_TIERS: Record<string, AccessTier>;
package/dist/types.js CHANGED
@@ -4,4 +4,28 @@
4
4
  * These types define the data structures used when interacting with
5
5
  * the LiquidPlanner API.
6
6
  */
7
- export {};
7
+ /**
8
+ * Access tier for each data method.
9
+ *
10
+ * All LP methods are standard tier — LP data is workspace-scoped, not employee-scoped.
11
+ * Utility methods (validate, clear, invalidate) are not included.
12
+ */
13
+ export const METHOD_TIERS = {
14
+ getWorkspaces: 'standard',
15
+ getWorkspaceMembers: 'standard',
16
+ getItem: 'standard',
17
+ getItems: 'standard',
18
+ getItemAncestors: 'standard',
19
+ findAssignments: 'standard',
20
+ getMyAssignments: 'standard',
21
+ getMyAssignmentsWithContext: 'standard',
22
+ findItems: 'standard',
23
+ getChildren: 'standard',
24
+ getWorkspaceTree: 'standard',
25
+ getMyWork: 'standard',
26
+ getCostCodes: 'standard',
27
+ createTimesheetEntry: 'standard',
28
+ getTimesheetEntries: 'standard',
29
+ updateTimesheetEntry: 'standard',
30
+ upsertTimesheetEntry: 'standard',
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markwharton/liquidplanner",
3
- "version": "2.1.2",
3
+ "version": "2.3.0",
4
4
  "description": "LiquidPlanner API client for timesheet integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "clean": "rm -rf dist"
17
17
  },
18
18
  "dependencies": {
19
- "@markwharton/api-core": "^1.2.0"
19
+ "@markwharton/api-core": "^1.3.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^20.10.0",