@amaster.ai/client 1.1.0-beta.7 → 1.1.0-beta.70

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/types/bpm.d.ts CHANGED
@@ -2,21 +2,21 @@
2
2
  * ============================================================================
3
3
  * BPM Module - Type Definitions
4
4
  * ============================================================================
5
- *
5
+ *
6
6
  * This module provides Business Process Management (BPM) capabilities
7
7
  * based on Camunda BPMN engine.
8
- *
8
+ *
9
9
  * ## Key Features
10
10
  * - Start and manage BPMN processes
11
11
  * - Query and complete user tasks
12
12
  * - Manage process variables
13
13
  * - Query process history
14
14
  * - Handle BPMN flows (approval, business processes, etc.)
15
- *
15
+ *
16
16
  * @module bpm
17
17
  */
18
18
 
19
- import type { ClientResult } from './common';
19
+ import type { ClientResult } from "./common";
20
20
 
21
21
  // ==================== Variable Types ====================
22
22
 
@@ -24,13 +24,13 @@ import type { ClientResult } from './common';
24
24
  * Camunda variable type
25
25
  */
26
26
  export type CamundaVariableType =
27
- | 'String'
28
- | 'Boolean'
29
- | 'Integer'
30
- | 'Long'
31
- | 'Double'
32
- | 'Date'
33
- | 'Json';
27
+ | "String"
28
+ | "Boolean"
29
+ | "Integer"
30
+ | "Long"
31
+ | "Double"
32
+ | "Date"
33
+ | "Json";
34
34
 
35
35
  /**
36
36
  * Camunda variable value (can be any JSON-serializable type)
@@ -47,7 +47,7 @@ export type CamundaVariableValue =
47
47
 
48
48
  /**
49
49
  * Camunda variable with type hint
50
- *
50
+ *
51
51
  * @example
52
52
  * ```typescript
53
53
  * const variable: CamundaVariable = {
@@ -63,7 +63,7 @@ export interface CamundaVariable {
63
63
 
64
64
  /**
65
65
  * Variable submission format for process/task
66
- *
66
+ *
67
67
  * @example
68
68
  * ```typescript
69
69
  * const submission: VariableSubmission = {
@@ -157,18 +157,50 @@ export interface Task {
157
157
  id: string;
158
158
  /** Task name */
159
159
  name: string;
160
+ /** Task description */
161
+ description?: string | null;
160
162
  /** Assignee user ID */
161
- assignee: string | null;
162
- /** Process instance ID */
163
- processInstanceId: string;
164
- /** Task definition key */
165
- taskDefinitionKey: string;
163
+ assignee?: string | null;
164
+ /** Task owner */
165
+ owner?: string | null;
166
166
  /** Task creation time */
167
- created: string;
167
+ created?: string | null;
168
168
  /** Task due date */
169
- due: string | null;
169
+ due?: string | null;
170
+ /** Task follow-up date */
171
+ followUp?: string | null;
172
+ /** Last update time */
173
+ lastUpdated?: string | null;
174
+ /** Delegation state */
175
+ delegationState?: string | null;
170
176
  /** Task priority */
171
- priority: number;
177
+ priority?: number;
178
+ /** Process instance ID */
179
+ processInstanceId?: string | null;
180
+ /** Process definition ID */
181
+ processDefinitionId?: string | null;
182
+ /** Execution ID */
183
+ executionId?: string | null;
184
+ /** Task definition key */
185
+ taskDefinitionKey?: string | null;
186
+ /** Parent task ID */
187
+ parentTaskId?: string | null;
188
+ /** Case execution ID */
189
+ caseExecutionId?: string | null;
190
+ /** Case instance ID */
191
+ caseInstanceId?: string | null;
192
+ /** Case definition ID */
193
+ caseDefinitionId?: string | null;
194
+ /** Whether task is suspended */
195
+ suspended?: boolean;
196
+ /** Form key */
197
+ formKey?: string | null;
198
+ /** Camunda form reference */
199
+ camundaFormRef?: string | null;
200
+ /** Tenant ID */
201
+ tenantId?: string | null;
202
+ /** Task state */
203
+ taskState?: string | null;
172
204
  }
173
205
 
174
206
  /**
@@ -196,33 +228,93 @@ export interface TaskCount {
196
228
  count: number;
197
229
  }
198
230
 
231
+ /**
232
+ * Historical task information
233
+ */
234
+ export interface HistoryTask {
235
+ /** Task ID */
236
+ id: string;
237
+ /** Task name */
238
+ name: string;
239
+ /** Task description */
240
+ description?: string | null;
241
+ /** Assignee user ID */
242
+ assignee?: string | null;
243
+ /** Task owner */
244
+ owner?: string | null;
245
+ /** Task start time */
246
+ startTime: string;
247
+ /** Task end time */
248
+ endTime?: string | null;
249
+ /** Task duration in milliseconds */
250
+ duration?: number | null;
251
+ /** Task due date */
252
+ due?: string | null;
253
+ /** Task follow-up date */
254
+ followUp?: string | null;
255
+ /** Task priority */
256
+ priority?: number;
257
+ /** Task state */
258
+ taskState?: string | null;
259
+ /** Delete reason */
260
+ deleteReason?: string | null;
261
+ /** Process instance ID */
262
+ processInstanceId?: string | null;
263
+ /** Process definition ID */
264
+ processDefinitionId?: string | null;
265
+ /** Process definition key */
266
+ processDefinitionKey?: string | null;
267
+ /** Execution ID */
268
+ executionId?: string | null;
269
+ /** Task definition key */
270
+ taskDefinitionKey?: string | null;
271
+ /** Parent task ID */
272
+ parentTaskId?: string | null;
273
+ /** Activity instance ID */
274
+ activityInstanceId?: string | null;
275
+ /** Case definition key */
276
+ caseDefinitionKey?: string | null;
277
+ /** Case definition ID */
278
+ caseDefinitionId?: string | null;
279
+ /** Case instance ID */
280
+ caseInstanceId?: string | null;
281
+ /** Case execution ID */
282
+ caseExecutionId?: string | null;
283
+ /** Tenant ID */
284
+ tenantId?: string | null;
285
+ /** Removal time */
286
+ removalTime?: string | null;
287
+ /** Root process instance ID */
288
+ rootProcessInstanceId?: string | null;
289
+ }
290
+
199
291
  // ==================== BPM Client API ====================
200
292
 
201
293
  /**
202
294
  * Business Process Management (BPM) Client API
203
- *
295
+ *
204
296
  * Provides methods for managing BPMN processes and tasks.
205
- *
297
+ *
206
298
  * @example
207
299
  * Complete BPM flow:
208
300
  * ```typescript
209
301
  * const client = createClient({ baseURL: 'https://api.amaster.ai' });
210
- *
302
+ *
211
303
  * // 1. Start a process
212
304
  * const process = await client.bpm.startProcess('approval', {
213
305
  * amount: { value: 5000, type: 'Long' },
214
306
  * requester: { value: 'user-123', type: 'String' },
215
307
  * description: { value: 'Purchase request', type: 'String' }
216
308
  * });
217
- *
309
+ *
218
310
  * console.log('Process started:', process.data.id);
219
- *
311
+ *
220
312
  * // 2. Get user's tasks
221
313
  * const tasks = await client.bpm.getTasks({
222
314
  * assignee: 'manager-456',
223
315
  * processDefinitionKey: 'approval'
224
316
  * });
225
- *
317
+ *
226
318
  * // 3. Complete a task
227
319
  * const taskId = tasks.data[0].id;
228
320
  * await client.bpm.completeTask(taskId, {
@@ -236,32 +328,27 @@ export interface BpmClientAPI {
236
328
 
237
329
  /**
238
330
  * Start a new process instance
239
- *
331
+ *
240
332
  * @param processKey - Process definition key (from BPMN diagram)
241
333
  * @param inputs - Process variables (can be simple object or VariableSubmission)
242
334
  * @returns New process instance information
243
- *
335
+ *
244
336
  * @example
245
- * Start with simple variables (type auto-inferred):
246
- * ```typescript
247
- * const result = await client.bpm.startProcess('approval', {
337
+ * // Simple start
338
+ * const result = await client.bpm.startProcess('approval-process', {
248
339
  * amount: 1000,
249
- * requester: 'user-123',
250
- * urgent: true
340
+ * requester: 'john@example.com'
251
341
  * });
252
342
  * ```
253
- *
343
+ *
254
344
  * @example
255
- * Start with explicit types:
256
- * ```typescript
257
- * const result = await client.bpm.startProcess('purchase-order', {
258
- * variables: {
259
- * amount: { value: 5000, type: 'Long' },
260
- * supplier: { value: 'ABC Corp', type: 'String' },
261
- * requestDate: { value: new Date(), type: 'Date' }
262
- * }
345
+ * // With business key
346
+ * const result = await client.bpm.startProcess('order-fulfillment', {
347
+ * orderId: 'ORDER-12345',
348
+ * items: [{ sku: 'ITEM-1', qty: 2 }]
263
349
  * });
264
- * ```
350
+ *
351
+ * @since 1.0.0
265
352
  */
266
353
  startProcess(
267
354
  processKey: string,
@@ -270,10 +357,10 @@ export interface BpmClientAPI {
270
357
 
271
358
  /**
272
359
  * Query process instances
273
- *
360
+ *
274
361
  * @param params - Query parameters
275
362
  * @returns Array of process instances
276
- *
363
+ *
277
364
  * @example
278
365
  * Get all active approval processes:
279
366
  * ```typescript
@@ -289,27 +376,25 @@ export interface BpmClientAPI {
289
376
 
290
377
  /**
291
378
  * Get a single process instance by ID
292
- *
379
+ *
293
380
  * @param processInstanceId - Process instance ID
294
381
  * @returns Process instance information
295
- *
382
+ *
296
383
  * @example
297
384
  * ```typescript
298
385
  * const result = await client.bpm.getProcessInstance('proc-123-456');
299
386
  * console.log('Process:', result.data);
300
387
  * ```
301
388
  */
302
- getProcessInstance(
303
- processInstanceId: string
304
- ): Promise<ClientResult<ProcessInstance>>;
389
+ getProcessInstance(processInstanceId: string): Promise<ClientResult<ProcessInstance>>;
305
390
 
306
391
  /**
307
392
  * Delete a process instance
308
- *
393
+ *
309
394
  * @param processInstanceId - Process instance ID
310
395
  * @param params - Optional parameters
311
396
  * @returns null on success
312
- *
397
+ *
313
398
  * @example
314
399
  * ```typescript
315
400
  * await client.bpm.deleteProcessInstance('proc-123');
@@ -322,10 +407,10 @@ export interface BpmClientAPI {
322
407
 
323
408
  /**
324
409
  * Get process variables
325
- *
410
+ *
326
411
  * @param params - Process instance ID and optional variable name
327
412
  * @returns Array of process variables
328
- *
413
+ *
329
414
  * @example
330
415
  * Get all variables:
331
416
  * ```typescript
@@ -333,7 +418,7 @@ export interface BpmClientAPI {
333
418
  * processInstanceId: 'proc-123'
334
419
  * });
335
420
  * ```
336
- *
421
+ *
337
422
  * @example
338
423
  * Get specific variable:
339
424
  * ```typescript
@@ -352,39 +437,45 @@ export interface BpmClientAPI {
352
437
 
353
438
  /**
354
439
  * Query user tasks
355
- *
440
+ *
356
441
  * @param params - Query parameters
357
442
  * @returns Array of tasks
358
- *
443
+ *
359
444
  * @example
360
445
  * Get tasks assigned to current user:
361
446
  * ```typescript
362
447
  * const result = await client.bpm.getTasks({
363
448
  * assignee: 'user-123'
364
449
  * });
365
- *
450
+ *
366
451
  * result.data.forEach(task => {
367
452
  * console.log(`Task: ${task.name} (${task.id})`);
368
453
  * });
369
454
  * ```
455
+ *
456
+ * @example
457
+ * // Get tasks for current user
458
+ * const result = await client.bpm.getTasks({
459
+ * assignee: 'currentUserId'
460
+ * });
370
461
  *
371
462
  * @example
372
- * Get tasks for specific process:
373
- * ```typescript
463
+ * // Get tasks for a process
374
464
  * const result = await client.bpm.getTasks({
375
- * processInstanceId: 'proc-456',
376
- * assignee: 'manager-789'
465
+ * processDefinitionKey: 'approval-process',
466
+ * maxResults: 10
377
467
  * });
378
- * ```
468
+ *
469
+ * @since 1.0.0
379
470
  */
380
471
  getTasks(params?: TaskQueryParams): Promise<ClientResult<Task[]>>;
381
472
 
382
473
  /**
383
474
  * Get task count
384
- *
475
+ *
385
476
  * @param params - Query parameters
386
477
  * @returns Task count
387
- *
478
+ *
388
479
  * @example
389
480
  * ```typescript
390
481
  * const result = await client.bpm.getTaskCount({
@@ -397,44 +488,43 @@ export interface BpmClientAPI {
397
488
 
398
489
  /**
399
490
  * Get a single task by ID
400
- *
491
+ *
401
492
  * @param taskId - Task ID
402
493
  * @returns Task information
403
- *
494
+ *
404
495
  * @example
405
- * ```typescript
406
- * const result = await client.bpm.getTask('task-abc-123');
407
- * console.log('Task:', result.data.name);
408
- * ```
496
+ * const result = await client.bpm.getTask('task-123');
497
+ * if (result.success) {
498
+ * console.log('Task:', result.data.name);
499
+ * }
500
+ *
501
+ * @since 1.0.0
409
502
  */
410
503
  getTask(taskId: string): Promise<ClientResult<Task>>;
411
504
 
412
505
  /**
413
506
  * Complete a user task
414
- *
507
+ *
415
508
  * @param taskId - Task ID
416
509
  * @param inputs - Task variables (can be simple object or VariableSubmission)
417
510
  * @returns null on success
418
- *
511
+ *
419
512
  * @example
420
- * Complete with simple variables:
421
- * ```typescript
422
- * await client.bpm.completeTask('task-123', {
513
+ * // Complete with approval
514
+ * const result = await client.bpm.completeTask('task-123', {
423
515
  * approved: true,
424
- * comment: 'Looks good!'
516
+ * comments: 'Looks good!'
425
517
  * });
426
518
  * ```
427
- *
519
+ *
428
520
  * @example
429
- * Complete with explicit types:
430
- * ```typescript
431
- * await client.bpm.completeTask('task-456', {
432
- * variables: {
433
- * approved: { value: false, type: 'Boolean' },
434
- * reason: { value: 'Insufficient budget', type: 'String' }
435
- * }
521
+ * // Complete with rejection
522
+ * const result = await client.bpm.completeTask('task-456', {
523
+ * approved: false,
524
+ * reason: 'Missing documentation'
436
525
  * });
437
- * ```
526
+ *
527
+ * @since 1.0.0
438
528
  */
439
529
  completeTask(
440
530
  taskId: string,
@@ -445,10 +535,10 @@ export interface BpmClientAPI {
445
535
 
446
536
  /**
447
537
  * Query historical process instances
448
- *
538
+ *
449
539
  * @param params - Query parameters
450
540
  * @returns Array of historical process instances
451
- *
541
+ *
452
542
  * @example
453
543
  * Get completed processes:
454
544
  * ```typescript
@@ -466,10 +556,10 @@ export interface BpmClientAPI {
466
556
 
467
557
  /**
468
558
  * Get historical process instance count
469
- *
559
+ *
470
560
  * @param params - Query parameters
471
561
  * @returns Process count
472
- *
562
+ *
473
563
  * @example
474
564
  * ```typescript
475
565
  * const result = await client.bpm.getHistoryProcessInstanceCount({
@@ -523,7 +613,7 @@ export interface HistoryProcessInstanceQueryParams {
523
613
  /** Sort field */
524
614
  sortBy?: string;
525
615
  /** Sort order */
526
- sortOrder?: 'asc' | 'desc';
616
+ sortOrder?: "asc" | "desc";
527
617
  /** Pagination: first result index */
528
618
  firstResult?: number;
529
619
  /** Pagination: max results to return */
package/types/common.d.ts CHANGED
@@ -1,12 +1,38 @@
1
1
  /**
2
- * ============================================================================
3
- * Common Types - Shared across all modules
4
- * ============================================================================
2
+ * Error information structure
5
3
  *
6
- * This file contains shared type definitions used by all Amaster client modules.
7
- *
8
- * @packageDocumentation
4
+ * @since 1.1.0
9
5
  */
6
+ export interface ClientError {
7
+ /**
8
+ * HTTP status code
9
+ */
10
+ status: number;
11
+
12
+ /**
13
+ * Error message
14
+ */
15
+ message: string;
16
+
17
+ /**
18
+ * Application-specific error code (e.g., 'INVALID_TOKEN', 'PERMISSION_DENIED')
19
+ *
20
+ * @since 1.1.0
21
+ */
22
+ code?: string;
23
+
24
+ /**
25
+ * Additional error details (optional)
26
+ */
27
+ details?: unknown;
28
+
29
+ /**
30
+ * Error timestamp (ISO 8601 format)
31
+ *
32
+ * @since 1.1.0
33
+ */
34
+ timestamp?: string;
35
+ }
10
36
 
11
37
  /**
12
38
  * Standard API response wrapper
@@ -17,33 +43,21 @@
17
43
  * @template T - The type of the successful response data
18
44
  *
19
45
  * @example
20
- * Success response:
21
- * ```typescript
22
- * const result: ClientResult<User> = await client.auth.getMe();
23
- * if (result.data) {
24
- * console.log('User:', result.data); // Type: User
25
- * }
26
- * ```
27
- *
28
- * @example
29
- * Error handling:
30
- * ```typescript
31
- * const result = await client.entity.get('default', 'users', '123');
32
- * if (result.error) {
33
- * console.error(`Error ${result.error.status}:`, result.error.message);
46
+ * // Success case
47
+ * const result = await client.entity.list('default', 'users');
48
+ * if (result.success) {
49
+ * console.log('Data:', result.data);
34
50
  * }
35
- * ```
36
51
  *
37
52
  * @example
38
- * Check by HTTP status:
39
- * ```typescript
53
+ * // Error case
40
54
  * const result = await client.auth.login({ email, password });
41
- * if (result.status === 200 && result.data) {
42
- * // Success
43
- * } else if (result.status === 401) {
44
- * // Unauthorized
55
+ * if (!result.success) {
56
+ * console.error('Error:', result.error.message);
57
+ * console.error('Code:', result.error.code);
45
58
  * }
46
- * ```
59
+ *
60
+ * @since 1.0.0
47
61
  */
48
62
  export interface ClientResult<T> {
49
63
  /**
@@ -54,27 +68,21 @@ export interface ClientResult<T> {
54
68
  /**
55
69
  * Error information (null if successful)
56
70
  */
57
- error: {
58
- /**
59
- * HTTP status code
60
- */
61
- status: number;
62
-
63
- /**
64
- * Error message
65
- */
66
- message: string;
67
-
68
- /**
69
- * Additional error details (optional)
70
- */
71
- details?: unknown;
72
- } | null;
71
+ error: ClientError | null;
73
72
 
74
73
  /**
75
74
  * HTTP response status code
76
75
  */
77
76
  status: number;
77
+
78
+ /**
79
+ * Convenience flag for checking if request was successful
80
+ *
81
+ * Equivalent to `error === null`
82
+ *
83
+ * @since 1.1.0
84
+ */
85
+ success: boolean;
78
86
  }
79
87
 
80
88
  /**