@fjell/client-api 4.4.13 → 4.4.14

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.
Files changed (89) hide show
  1. package/dist/AItemAPI.d.ts +4 -4
  2. package/dist/CItemAPI.d.ts +5 -5
  3. package/dist/ClientApi.d.ts +1 -1
  4. package/dist/ClientApiOptions.d.ts +3 -3
  5. package/dist/Instance.d.ts +3 -3
  6. package/dist/InstanceFactory.d.ts +3 -3
  7. package/dist/PItemAPI.d.ts +4 -4
  8. package/dist/Utilities.d.ts +1 -1
  9. package/dist/index.d.ts +6 -6
  10. package/dist/index.js +544 -5
  11. package/dist/index.js.map +7 -1
  12. package/dist/logger.d.ts +1 -1
  13. package/dist/ops/action.d.ts +4 -4
  14. package/dist/ops/all.d.ts +4 -4
  15. package/dist/ops/allAction.d.ts +4 -4
  16. package/dist/ops/allFacet.d.ts +4 -4
  17. package/dist/ops/create.d.ts +4 -4
  18. package/dist/ops/facet.d.ts +4 -4
  19. package/dist/ops/find.d.ts +4 -4
  20. package/dist/ops/findOne.d.ts +4 -4
  21. package/dist/ops/get.d.ts +4 -4
  22. package/dist/ops/index.d.ts +5 -5
  23. package/dist/ops/one.d.ts +4 -4
  24. package/dist/ops/remove.d.ts +4 -4
  25. package/dist/ops/update.d.ts +4 -4
  26. package/package.json +8 -11
  27. package/vitest.config.ts +25 -0
  28. package/dist/AItemAPI.js +0 -52
  29. package/dist/AItemAPI.js.map +0 -1
  30. package/dist/CItemAPI.js +0 -30
  31. package/dist/CItemAPI.js.map +0 -1
  32. package/dist/Instance.js +0 -19
  33. package/dist/Instance.js.map +0 -1
  34. package/dist/InstanceFactory.js +0 -19
  35. package/dist/InstanceFactory.js.map +0 -1
  36. package/dist/PItemAPI.js +0 -44
  37. package/dist/PItemAPI.js.map +0 -1
  38. package/dist/Registry.js +0 -31
  39. package/dist/Registry.js.map +0 -1
  40. package/dist/Utilities.js +0 -153
  41. package/dist/Utilities.js.map +0 -1
  42. package/dist/index.cjs +0 -586
  43. package/dist/index.cjs.map +0 -1
  44. package/dist/logger.js +0 -6
  45. package/dist/logger.js.map +0 -1
  46. package/dist/ops/action.js +0 -21
  47. package/dist/ops/action.js.map +0 -1
  48. package/dist/ops/all.js +0 -25
  49. package/dist/ops/all.js.map +0 -1
  50. package/dist/ops/allAction.js +0 -24
  51. package/dist/ops/allAction.js.map +0 -1
  52. package/dist/ops/allFacet.js +0 -24
  53. package/dist/ops/allFacet.js.map +0 -1
  54. package/dist/ops/create.js +0 -23
  55. package/dist/ops/create.js.map +0 -1
  56. package/dist/ops/facet.js +0 -34
  57. package/dist/ops/facet.js.map +0 -1
  58. package/dist/ops/find.js +0 -26
  59. package/dist/ops/find.js.map +0 -1
  60. package/dist/ops/findOne.js +0 -27
  61. package/dist/ops/findOne.js.map +0 -1
  62. package/dist/ops/get.js +0 -19
  63. package/dist/ops/get.js.map +0 -1
  64. package/dist/ops/index.js +0 -32
  65. package/dist/ops/index.js.map +0 -1
  66. package/dist/ops/one.js +0 -30
  67. package/dist/ops/one.js.map +0 -1
  68. package/dist/ops/remove.js +0 -19
  69. package/dist/ops/remove.js.map +0 -1
  70. package/dist/ops/update.js +0 -20
  71. package/dist/ops/update.js.map +0 -1
  72. package/docs/docs.config.ts +0 -77
  73. package/docs/index.html +0 -18
  74. package/docs/package.json +0 -34
  75. package/docs/public/README.md +0 -165
  76. package/docs/public/api-reference.md +0 -408
  77. package/docs/public/examples-README.md +0 -387
  78. package/docs/public/fjell-icon.svg +0 -1
  79. package/docs/public/package.json +0 -5
  80. package/docs/src/index.css +0 -34
  81. package/docs/src/main.tsx +0 -12
  82. package/docs/src/test/setup.ts +0 -1
  83. package/docs/src/types.d.ts +0 -44
  84. package/docs/tsconfig.node.json +0 -13
  85. package/docs/vitest.config.ts +0 -14
  86. package/examples/README.md +0 -387
  87. package/examples/enterprise-example.ts +0 -852
  88. package/examples/multi-level-keys.ts +0 -467
  89. package/examples/simple-example.ts +0 -346
@@ -1,408 +0,0 @@
1
- # API Reference
2
-
3
- Complete reference for all Client API interfaces and methods.
4
-
5
- ## Core Interfaces
6
-
7
- ### PItemApi<V, S>
8
-
9
- Primary Item API for independent entities that exist at the top level of your API hierarchy.
10
-
11
- **Type Parameters:**
12
- - `V` - The value type returned from API operations
13
- - `S` - The string literal type representing the item type
14
-
15
- #### Methods
16
-
17
- ##### `all(query?: ItemQuery): Promise<V[]>`
18
- Retrieve all items matching the query criteria.
19
-
20
- **Parameters:**
21
- - `query` (optional) - Query parameters for filtering and pagination
22
-
23
- **Returns:** Promise resolving to an array of items
24
-
25
- **Example:**
26
- ```typescript
27
- const users = await userApi.all({ limit: 10, offset: 0 })
28
- ```
29
-
30
- ##### `create(item: Partial<Item<S>>): Promise<V>`
31
- Create a new item.
32
-
33
- **Parameters:**
34
- - `item` - Partial item data for creation
35
-
36
- **Returns:** Promise resolving to the created item
37
-
38
- **Example:**
39
- ```typescript
40
- const user = await userApi.create({
41
- name: 'John Doe',
42
- email: 'john@example.com'
43
- })
44
- ```
45
-
46
- ##### `get(key: PriKey<S>): Promise<V>`
47
- Retrieve a specific item by its key.
48
-
49
- **Parameters:**
50
- - `key` - Primary key identifying the item
51
-
52
- **Returns:** Promise resolving to the item
53
-
54
- **Example:**
55
- ```typescript
56
- const user = await userApi.get(userKey)
57
- ```
58
-
59
- ##### `update(key: PriKey<S>, updates: Partial<Item<S>>): Promise<V>`
60
- Update an existing item.
61
-
62
- **Parameters:**
63
- - `key` - Primary key identifying the item
64
- - `updates` - Partial updates to apply
65
-
66
- **Returns:** Promise resolving to the updated item
67
-
68
- **Example:**
69
- ```typescript
70
- const updatedUser = await userApi.update(userKey, {
71
- name: 'John Smith'
72
- })
73
- ```
74
-
75
- ##### `remove(key: PriKey<S>): Promise<boolean>`
76
- Delete an item.
77
-
78
- **Parameters:**
79
- - `key` - Primary key identifying the item
80
-
81
- **Returns:** Promise resolving to true if deletion was successful
82
-
83
- **Example:**
84
- ```typescript
85
- const deleted = await userApi.remove(userKey)
86
- ```
87
-
88
- ##### `action(key: PriKey<S>, action: string, body?: any): Promise<any>`
89
- Execute a business action on a specific item.
90
-
91
- **Parameters:**
92
- - `key` - Primary key identifying the item
93
- - `action` - Name of the action to execute
94
- - `body` (optional) - Action parameters
95
-
96
- **Returns:** Promise resolving to action result
97
-
98
- **Example:**
99
- ```typescript
100
- await userApi.action(userKey, 'activate', { reason: 'manual activation' })
101
- ```
102
-
103
- ##### `find(finder: string, params?: any): Promise<V[]>`
104
- Execute a custom finder operation.
105
-
106
- **Parameters:**
107
- - `finder` - Name of the finder
108
- - `params` (optional) - Finder parameters
109
-
110
- **Returns:** Promise resolving to an array of found items
111
-
112
- **Example:**
113
- ```typescript
114
- const activeUsers = await userApi.find('active-users', { since: '2024-01-01' })
115
- ```
116
-
117
- ##### `facet(key: PriKey<S>, facet: string, params?: any): Promise<any>`
118
- Retrieve computed data or analytics for a specific item.
119
-
120
- **Parameters:**
121
- - `key` - Primary key identifying the item
122
- - `facet` - Name of the facet
123
- - `params` (optional) - Facet parameters
124
-
125
- **Returns:** Promise resolving to facet data
126
-
127
- **Example:**
128
- ```typescript
129
- const userStats = await userApi.facet(userKey, 'activity-stats')
130
- ```
131
-
132
- ##### `allAction(action: string, body?: any): Promise<V[]>`
133
- Execute a business action on all items or collections.
134
-
135
- **Parameters:**
136
- - `action` - Name of the action to execute
137
- - `body` (optional) - Action parameters
138
-
139
- **Returns:** Promise resolving to action results
140
-
141
- **Example:**
142
- ```typescript
143
- const results = await userApi.allAction('bulk-update', { status: 'active' })
144
- ```
145
-
146
- ##### `allFacet(facet: string, params?: any): Promise<any>`
147
- Retrieve computed data or analytics for collections.
148
-
149
- **Parameters:**
150
- - `facet` - Name of the facet
151
- - `params` (optional) - Facet parameters
152
-
153
- **Returns:** Promise resolving to facet data
154
-
155
- **Example:**
156
- ```typescript
157
- const userAnalytics = await userApi.allFacet('engagement-metrics', { period: 'monthly' })
158
- ```
159
-
160
- ### CItemApi<V, S, L1, L2, L3, L4, L5>
161
-
162
- Contained Item API for hierarchical entities that belong to parent resources and require location context.
163
-
164
- **Type Parameters:**
165
- - `V` - The value type returned from API operations
166
- - `S` - The string literal type representing the item type
167
- - `L1, L2, L3, L4, L5` - Location hierarchy types (up to 5 levels)
168
-
169
- **Extends:** All PItemApi methods plus location-aware variants
170
-
171
- #### Location-Aware Methods
172
-
173
- ##### `all(query: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<V[]>`
174
- Retrieve all items within a specific location context.
175
-
176
- **Parameters:**
177
- - `query` - Query parameters
178
- - `locations` (optional) - Array of location keys defining the context
179
-
180
- **Returns:** Promise resolving to an array of items
181
-
182
- **Example:**
183
- ```typescript
184
- // Get all tasks for a specific user
185
- const tasks = await taskApi.all({}, [userId])
186
-
187
- // Get all employees in a specific department
188
- const employees = await employeeApi.all({}, [orgId, deptId])
189
- ```
190
-
191
- ##### `create(item: Partial<Item<S>>, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<V>`
192
- Create a new item within a specific location context.
193
-
194
- **Parameters:**
195
- - `item` - Partial item data for creation
196
- - `locations` (optional) - Array of location keys defining the context
197
-
198
- **Returns:** Promise resolving to the created item
199
-
200
- **Example:**
201
- ```typescript
202
- const task = await taskApi.create({
203
- title: 'Complete project'
204
- }, [userId])
205
- ```
206
-
207
- ##### `find(finder: string, params?: any, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<V[]>`
208
- Execute a custom finder within a location context.
209
-
210
- ##### `allAction(action: string, body?: any, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<V[]>`
211
- Execute actions on collections within a location context.
212
-
213
- ##### `allFacet(facet: string, params?: any, locations?: LocKeyArray<L1, L2, L3, L4, L5>): Promise<any>`
214
- Retrieve analytics for collections within a location context.
215
-
216
- ## Configuration
217
-
218
- ### ApiConfig
219
-
220
- Configuration object for API instances.
221
-
222
- ```typescript
223
- interface ApiConfig {
224
- baseUrl: string;
225
- headers?: { [key: string]: string };
226
- timeout?: number;
227
- retries?: number;
228
- readAuthenticated?: boolean;
229
- writeAuthenticated?: boolean;
230
- }
231
- ```
232
-
233
- **Properties:**
234
- - `baseUrl` - Base URL for API endpoints
235
- - `headers` (optional) - Default headers to include with requests
236
- - `timeout` (optional) - Request timeout in milliseconds
237
- - `retries` (optional) - Number of retry attempts for failed requests
238
- - `readAuthenticated` (optional) - Whether read operations require authentication
239
- - `writeAuthenticated` (optional) - Whether write operations require authentication
240
-
241
- **Example:**
242
- ```typescript
243
- const config: ApiConfig = {
244
- baseUrl: 'https://api.example.com',
245
- headers: {
246
- 'Content-Type': 'application/json',
247
- 'Authorization': 'Bearer token'
248
- },
249
- timeout: 5000,
250
- retries: 3,
251
- readAuthenticated: true,
252
- writeAuthenticated: true
253
- }
254
- ```
255
-
256
- ## Factory Functions
257
-
258
- ### createPItemApi
259
-
260
- Creates a Primary Item API instance.
261
-
262
- ```typescript
263
- function createPItemApi<V, S extends string>(
264
- itemType: S,
265
- pathSegments: string[],
266
- config: ApiConfig
267
- ): PItemApi<V, S>
268
- ```
269
-
270
- **Parameters:**
271
- - `itemType` - String literal identifying the item type
272
- - `pathSegments` - Array of path segments for API endpoints
273
- - `config` - API configuration
274
-
275
- **Example:**
276
- ```typescript
277
- const userApi = createPItemApi<User, 'user'>('user', ['users'], config)
278
- ```
279
-
280
- ### createCItemApi
281
-
282
- Creates a Contained Item API instance.
283
-
284
- ```typescript
285
- function createCItemApi<V, S extends string, L1 extends string, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(
286
- itemType: S,
287
- pathSegments: string[],
288
- config: ApiConfig
289
- ): CItemApi<V, S, L1, L2, L3, L4, L5>
290
- ```
291
-
292
- **Parameters:**
293
- - `itemType` - String literal identifying the item type
294
- - `pathSegments` - Array of path segments for API endpoints (including parent segments)
295
- - `config` - API configuration
296
-
297
- **Example:**
298
- ```typescript
299
- // Single-level containment
300
- const taskApi = createCItemApi<Task, 'task', 'user'>('task', ['users', 'tasks'], config)
301
-
302
- // Multi-level containment
303
- const employeeApi = createCItemApi<Employee, 'employee', 'organization', 'department'>(
304
- 'employee',
305
- ['organizations', 'departments', 'employees'],
306
- config
307
- )
308
- ```
309
-
310
- ## Error Handling
311
-
312
- The Client API provides comprehensive error handling with detailed error information.
313
-
314
- ### Error Types
315
-
316
- - **NetworkError** - Network connectivity issues
317
- - **AuthenticationError** - Authentication failures
318
- - **AuthorizationError** - Authorization/permission issues
319
- - **ValidationError** - Request validation failures
320
- - **NotFoundError** - Resource not found
321
- - **ServerError** - Server-side errors
322
-
323
- ### Error Handling Patterns
324
-
325
- ```typescript
326
- try {
327
- const user = await userApi.get(userKey)
328
- } catch (error) {
329
- if (error instanceof NotFoundError) {
330
- console.log('User not found')
331
- } else if (error instanceof AuthenticationError) {
332
- // Redirect to login
333
- } else if (error instanceof ValidationError) {
334
- // Handle validation errors
335
- console.error('Validation errors:', error.details)
336
- } else {
337
- // Handle other errors
338
- console.error('API error:', error.message)
339
- }
340
- }
341
- ```
342
-
343
- ## Best Practices
344
-
345
- ### 1. Type Safety
346
- Always provide proper TypeScript types for your data models:
347
-
348
- ```typescript
349
- interface User {
350
- id: string;
351
- name: string;
352
- email: string;
353
- createdAt: Date;
354
- updatedAt: Date;
355
- }
356
-
357
- const userApi = createPItemApi<User, 'user'>('user', ['users'], config)
358
- ```
359
-
360
- ### 2. Error Handling
361
- Implement comprehensive error handling:
362
-
363
- ```typescript
364
- const createUser = async (userData: Partial<User>) => {
365
- try {
366
- return await userApi.create(userData)
367
- } catch (error) {
368
- // Log error and handle appropriately
369
- console.error('Failed to create user:', error)
370
- throw error
371
- }
372
- }
373
- ```
374
-
375
- ### 3. Configuration Management
376
- Use environment-specific configuration:
377
-
378
- ```typescript
379
- const config = {
380
- baseUrl: process.env.API_BASE_URL || 'http://localhost:3000',
381
- headers: {
382
- 'Authorization': `Bearer ${process.env.API_TOKEN}`
383
- }
384
- }
385
- ```
386
-
387
- ### 4. Location Context
388
- Always provide proper location context for contained items:
389
-
390
- ```typescript
391
- // Good - specific location context
392
- const userTasks = await taskApi.all({}, [userId])
393
-
394
- // Avoid - missing location context may return unexpected results
395
- const allTasks = await taskApi.all({})
396
- ```
397
-
398
- ### 5. Query Optimization
399
- Use appropriate queries and pagination:
400
-
401
- ```typescript
402
- const users = await userApi.all({
403
- limit: 50,
404
- offset: 0,
405
- sort: 'createdAt:desc',
406
- filter: 'status:active'
407
- })
408
- ```