@amaster.ai/client 1.1.0-beta.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/LICENSE +21 -0
- package/README.md +463 -0
- package/dist/index.cjs +62 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +222 -0
- package/dist/index.d.ts +222 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/package.json +84 -0
- package/types/auth.d.ts +674 -0
- package/types/bpm.d.ts +531 -0
- package/types/common.d.ts +132 -0
- package/types/entity.d.ts +710 -0
- package/types/index.d.ts +487 -0
- package/types/workflow.d.ts +291 -0
package/types/bpm.d.ts
ADDED
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* BPM Module - Type Definitions
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* This module provides Business Process Management (BPM) capabilities
|
|
7
|
+
* based on Camunda BPMN engine.
|
|
8
|
+
*
|
|
9
|
+
* ## Key Features
|
|
10
|
+
* - Start and manage BPMN processes
|
|
11
|
+
* - Query and complete user tasks
|
|
12
|
+
* - Manage process variables
|
|
13
|
+
* - Query process history
|
|
14
|
+
* - Handle BPMN flows (approval, business processes, etc.)
|
|
15
|
+
*
|
|
16
|
+
* @module bpm
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import type { ClientResult } from './common';
|
|
20
|
+
|
|
21
|
+
// ==================== Variable Types ====================
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Camunda variable type
|
|
25
|
+
*/
|
|
26
|
+
export type CamundaVariableType =
|
|
27
|
+
| 'String'
|
|
28
|
+
| 'Boolean'
|
|
29
|
+
| 'Integer'
|
|
30
|
+
| 'Long'
|
|
31
|
+
| 'Double'
|
|
32
|
+
| 'Date'
|
|
33
|
+
| 'Json';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Camunda variable value (can be any JSON-serializable type)
|
|
37
|
+
*/
|
|
38
|
+
export type CamundaVariableValue =
|
|
39
|
+
| string
|
|
40
|
+
| number
|
|
41
|
+
| boolean
|
|
42
|
+
| Date
|
|
43
|
+
| null
|
|
44
|
+
| undefined
|
|
45
|
+
| Record<string, unknown>
|
|
46
|
+
| unknown[];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Camunda variable with type hint
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const variable: CamundaVariable = {
|
|
54
|
+
* value: 1000,
|
|
55
|
+
* type: 'Long'
|
|
56
|
+
* };
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export interface CamundaVariable {
|
|
60
|
+
value: CamundaVariableValue;
|
|
61
|
+
type?: CamundaVariableType;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Variable submission format for process/task
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const submission: VariableSubmission = {
|
|
70
|
+
* variables: {
|
|
71
|
+
* amount: { value: 1000, type: 'Long' },
|
|
72
|
+
* requester: { value: 'user-123', type: 'String' },
|
|
73
|
+
* approved: { value: false, type: 'Boolean' }
|
|
74
|
+
* }
|
|
75
|
+
* };
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export interface VariableSubmission {
|
|
79
|
+
variables: Record<string, CamundaVariable>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ==================== Process Types ====================
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Process instance information
|
|
86
|
+
*/
|
|
87
|
+
export interface ProcessInstance {
|
|
88
|
+
/** Process instance ID (UUID) */
|
|
89
|
+
id: string;
|
|
90
|
+
/** Process definition ID */
|
|
91
|
+
definitionId?: string;
|
|
92
|
+
/** Business key for correlation */
|
|
93
|
+
businessKey?: string;
|
|
94
|
+
/** Whether the process has ended */
|
|
95
|
+
ended?: boolean;
|
|
96
|
+
/** Whether the process is suspended */
|
|
97
|
+
suspended?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Process instance query parameters
|
|
102
|
+
*/
|
|
103
|
+
export interface ProcessInstanceQueryParams {
|
|
104
|
+
/** Filter by process definition key */
|
|
105
|
+
processDefinitionKey?: string;
|
|
106
|
+
/** Filter active/inactive processes */
|
|
107
|
+
active?: boolean;
|
|
108
|
+
/** Pagination: first result index */
|
|
109
|
+
firstResult?: number;
|
|
110
|
+
/** Pagination: max results to return */
|
|
111
|
+
maxResults?: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Historical process instance
|
|
116
|
+
*/
|
|
117
|
+
export interface HistoryProcessInstance {
|
|
118
|
+
/** Process instance ID */
|
|
119
|
+
id: string;
|
|
120
|
+
/** Business key */
|
|
121
|
+
businessKey: string;
|
|
122
|
+
/** Process definition ID */
|
|
123
|
+
processDefinitionId: string;
|
|
124
|
+
/** Process definition key */
|
|
125
|
+
processDefinitionKey: string;
|
|
126
|
+
/** Process definition name */
|
|
127
|
+
processDefinitionName: string;
|
|
128
|
+
/** Process definition version */
|
|
129
|
+
processDefinitionVersion: number;
|
|
130
|
+
/** Start timestamp (ISO 8601) */
|
|
131
|
+
startTime: string;
|
|
132
|
+
/** End timestamp (null if still running) */
|
|
133
|
+
endTime: string | null;
|
|
134
|
+
/** Duration in milliseconds (null if still running) */
|
|
135
|
+
durationInMillis: number | null;
|
|
136
|
+
/** User who started the process */
|
|
137
|
+
startUserId: string;
|
|
138
|
+
/** Start activity ID */
|
|
139
|
+
startActivityId: string;
|
|
140
|
+
/** Delete reason (if deleted) */
|
|
141
|
+
deleteReason: string | null;
|
|
142
|
+
/** Process state */
|
|
143
|
+
state: string;
|
|
144
|
+
/** Parent process instance ID (if subprocess) */
|
|
145
|
+
superProcessInstanceId?: string;
|
|
146
|
+
/** Parent case instance ID (if CMMN) */
|
|
147
|
+
superCaseInstanceId?: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ==================== Task Types ====================
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* User task information
|
|
154
|
+
*/
|
|
155
|
+
export interface Task {
|
|
156
|
+
/** Task ID */
|
|
157
|
+
id: string;
|
|
158
|
+
/** Task name */
|
|
159
|
+
name: string;
|
|
160
|
+
/** Assignee user ID */
|
|
161
|
+
assignee: string | null;
|
|
162
|
+
/** Process instance ID */
|
|
163
|
+
processInstanceId: string;
|
|
164
|
+
/** Task definition key */
|
|
165
|
+
taskDefinitionKey: string;
|
|
166
|
+
/** Task creation time */
|
|
167
|
+
created: string;
|
|
168
|
+
/** Task due date */
|
|
169
|
+
due: string | null;
|
|
170
|
+
/** Task priority */
|
|
171
|
+
priority: number;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Task query parameters
|
|
176
|
+
*/
|
|
177
|
+
export interface TaskQueryParams {
|
|
178
|
+
/** Filter by assignee */
|
|
179
|
+
assignee?: string;
|
|
180
|
+
/** Filter by process definition key */
|
|
181
|
+
processDefinitionKey?: string;
|
|
182
|
+
/** Filter by task definition key */
|
|
183
|
+
taskDefinitionKey?: string;
|
|
184
|
+
/** Filter by process instance ID */
|
|
185
|
+
processInstanceId?: string;
|
|
186
|
+
/** Pagination: first result index */
|
|
187
|
+
firstResult?: number;
|
|
188
|
+
/** Pagination: max results to return */
|
|
189
|
+
maxResults?: number;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Task count result
|
|
194
|
+
*/
|
|
195
|
+
export interface TaskCount {
|
|
196
|
+
count: number;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ==================== BPM Client API ====================
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Business Process Management (BPM) Client API
|
|
203
|
+
*
|
|
204
|
+
* Provides methods for managing BPMN processes and tasks.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* Complete BPM flow:
|
|
208
|
+
* ```typescript
|
|
209
|
+
* const client = createClient({ baseURL: 'https://api.amaster.ai' });
|
|
210
|
+
*
|
|
211
|
+
* // 1. Start a process
|
|
212
|
+
* const process = await client.bpm.startProcess('approval', {
|
|
213
|
+
* amount: { value: 5000, type: 'Long' },
|
|
214
|
+
* requester: { value: 'user-123', type: 'String' },
|
|
215
|
+
* description: { value: 'Purchase request', type: 'String' }
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* console.log('Process started:', process.data.id);
|
|
219
|
+
*
|
|
220
|
+
* // 2. Get user's tasks
|
|
221
|
+
* const tasks = await client.bpm.getTasks({
|
|
222
|
+
* assignee: 'manager-456',
|
|
223
|
+
* processDefinitionKey: 'approval'
|
|
224
|
+
* });
|
|
225
|
+
*
|
|
226
|
+
* // 3. Complete a task
|
|
227
|
+
* const taskId = tasks.data[0].id;
|
|
228
|
+
* await client.bpm.completeTask(taskId, {
|
|
229
|
+
* approved: { value: true, type: 'Boolean' },
|
|
230
|
+
* comment: { value: 'Approved!', type: 'String' }
|
|
231
|
+
* });
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export interface BpmClientAPI {
|
|
235
|
+
// ==================== Process Management ====================
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Start a new process instance
|
|
239
|
+
*
|
|
240
|
+
* @param processKey - Process definition key (from BPMN diagram)
|
|
241
|
+
* @param inputs - Process variables (can be simple object or VariableSubmission)
|
|
242
|
+
* @returns New process instance information
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* Start with simple variables (type auto-inferred):
|
|
246
|
+
* ```typescript
|
|
247
|
+
* const result = await client.bpm.startProcess('approval', {
|
|
248
|
+
* amount: 1000,
|
|
249
|
+
* requester: 'user-123',
|
|
250
|
+
* urgent: true
|
|
251
|
+
* });
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @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
|
+
* }
|
|
263
|
+
* });
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
startProcess(
|
|
267
|
+
processKey: string,
|
|
268
|
+
inputs?: Record<string, CamundaVariableValue> | VariableSubmission
|
|
269
|
+
): Promise<ClientResult<ProcessInstance>>;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Query process instances
|
|
273
|
+
*
|
|
274
|
+
* @param params - Query parameters
|
|
275
|
+
* @returns Array of process instances
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* Get all active approval processes:
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const result = await client.bpm.getProcessInstances({
|
|
281
|
+
* processDefinitionKey: 'approval',
|
|
282
|
+
* active: true
|
|
283
|
+
* });
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
getProcessInstances(
|
|
287
|
+
params?: ProcessInstanceQueryParams
|
|
288
|
+
): Promise<ClientResult<ProcessInstance[]>>;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Get a single process instance by ID
|
|
292
|
+
*
|
|
293
|
+
* @param processInstanceId - Process instance ID
|
|
294
|
+
* @returns Process instance information
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const result = await client.bpm.getProcessInstance('proc-123-456');
|
|
299
|
+
* console.log('Process:', result.data);
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
getProcessInstance(
|
|
303
|
+
processInstanceId: string
|
|
304
|
+
): Promise<ClientResult<ProcessInstance>>;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Delete a process instance
|
|
308
|
+
*
|
|
309
|
+
* @param processInstanceId - Process instance ID
|
|
310
|
+
* @param params - Optional parameters
|
|
311
|
+
* @returns null on success
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```typescript
|
|
315
|
+
* await client.bpm.deleteProcessInstance('proc-123');
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
deleteProcessInstance(
|
|
319
|
+
processInstanceId: string,
|
|
320
|
+
params?: { skipCustomListeners?: boolean }
|
|
321
|
+
): Promise<ClientResult<null>>;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Get process variables
|
|
325
|
+
*
|
|
326
|
+
* @param params - Process instance ID and optional variable name
|
|
327
|
+
* @returns Array of process variables
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* Get all variables:
|
|
331
|
+
* ```typescript
|
|
332
|
+
* const result = await client.bpm.getProcessVariables({
|
|
333
|
+
* processInstanceId: 'proc-123'
|
|
334
|
+
* });
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* Get specific variable:
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const result = await client.bpm.getProcessVariables({
|
|
341
|
+
* processInstanceId: 'proc-123',
|
|
342
|
+
* variableName: 'amount'
|
|
343
|
+
* });
|
|
344
|
+
* ```
|
|
345
|
+
*/
|
|
346
|
+
getProcessVariables(params: {
|
|
347
|
+
processInstanceId: string;
|
|
348
|
+
variableName?: string;
|
|
349
|
+
}): Promise<ClientResult<ProcessVariable[]>>;
|
|
350
|
+
|
|
351
|
+
// ==================== Task Management ====================
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Query user tasks
|
|
355
|
+
*
|
|
356
|
+
* @param params - Query parameters
|
|
357
|
+
* @returns Array of tasks
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* Get tasks assigned to current user:
|
|
361
|
+
* ```typescript
|
|
362
|
+
* const result = await client.bpm.getTasks({
|
|
363
|
+
* assignee: 'user-123'
|
|
364
|
+
* });
|
|
365
|
+
*
|
|
366
|
+
* result.data.forEach(task => {
|
|
367
|
+
* console.log(`Task: ${task.name} (${task.id})`);
|
|
368
|
+
* });
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* Get tasks for specific process:
|
|
373
|
+
* ```typescript
|
|
374
|
+
* const result = await client.bpm.getTasks({
|
|
375
|
+
* processInstanceId: 'proc-456',
|
|
376
|
+
* assignee: 'manager-789'
|
|
377
|
+
* });
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
getTasks(params?: TaskQueryParams): Promise<ClientResult<Task[]>>;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Get task count
|
|
384
|
+
*
|
|
385
|
+
* @param params - Query parameters
|
|
386
|
+
* @returns Task count
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* const result = await client.bpm.getTaskCount({
|
|
391
|
+
* assignee: 'user-123'
|
|
392
|
+
* });
|
|
393
|
+
* console.log(`You have ${result.data.count} tasks`);
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
getTaskCount(params?: TaskQueryParams): Promise<ClientResult<TaskCount>>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Get a single task by ID
|
|
400
|
+
*
|
|
401
|
+
* @param taskId - Task ID
|
|
402
|
+
* @returns Task information
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const result = await client.bpm.getTask('task-abc-123');
|
|
407
|
+
* console.log('Task:', result.data.name);
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
getTask(taskId: string): Promise<ClientResult<Task>>;
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Complete a user task
|
|
414
|
+
*
|
|
415
|
+
* @param taskId - Task ID
|
|
416
|
+
* @param inputs - Task variables (can be simple object or VariableSubmission)
|
|
417
|
+
* @returns null on success
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* Complete with simple variables:
|
|
421
|
+
* ```typescript
|
|
422
|
+
* await client.bpm.completeTask('task-123', {
|
|
423
|
+
* approved: true,
|
|
424
|
+
* comment: 'Looks good!'
|
|
425
|
+
* });
|
|
426
|
+
* ```
|
|
427
|
+
*
|
|
428
|
+
* @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
|
+
* }
|
|
436
|
+
* });
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
completeTask(
|
|
440
|
+
taskId: string,
|
|
441
|
+
inputs: Record<string, CamundaVariableValue> | VariableSubmission
|
|
442
|
+
): Promise<ClientResult<null>>;
|
|
443
|
+
|
|
444
|
+
// ==================== History & Reporting ====================
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Query historical process instances
|
|
448
|
+
*
|
|
449
|
+
* @param params - Query parameters
|
|
450
|
+
* @returns Array of historical process instances
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* Get completed processes:
|
|
454
|
+
* ```typescript
|
|
455
|
+
* const result = await client.bpm.getHistoryProcessInstances({
|
|
456
|
+
* finished: true,
|
|
457
|
+
* processDefinitionKey: 'approval',
|
|
458
|
+
* sortBy: 'startTime',
|
|
459
|
+
* sortOrder: 'desc'
|
|
460
|
+
* });
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
getHistoryProcessInstances(
|
|
464
|
+
params?: HistoryProcessInstanceQueryParams
|
|
465
|
+
): Promise<ClientResult<HistoryProcessInstance[]>>;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Get historical process instance count
|
|
469
|
+
*
|
|
470
|
+
* @param params - Query parameters
|
|
471
|
+
* @returns Process count
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```typescript
|
|
475
|
+
* const result = await client.bpm.getHistoryProcessInstanceCount({
|
|
476
|
+
* startedBy: 'user-123',
|
|
477
|
+
* finished: true
|
|
478
|
+
* });
|
|
479
|
+
* console.log(`Completed: ${result.data.count} processes`);
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
getHistoryProcessInstanceCount(
|
|
483
|
+
params?: HistoryProcessInstanceQueryParams
|
|
484
|
+
): Promise<ClientResult<{ count: number }>>;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Process variable information
|
|
489
|
+
*/
|
|
490
|
+
export interface ProcessVariable {
|
|
491
|
+
/** Variable ID */
|
|
492
|
+
id: string;
|
|
493
|
+
/** Variable name */
|
|
494
|
+
name: string;
|
|
495
|
+
/** Variable type */
|
|
496
|
+
type: string;
|
|
497
|
+
/** Variable value */
|
|
498
|
+
value: CamundaVariableValue;
|
|
499
|
+
/** Process instance ID */
|
|
500
|
+
processInstanceId: string;
|
|
501
|
+
/** Creation time */
|
|
502
|
+
createTime?: string;
|
|
503
|
+
/** Activity instance ID */
|
|
504
|
+
activityInstanceId?: string;
|
|
505
|
+
/** Task ID (if task variable) */
|
|
506
|
+
taskId?: string;
|
|
507
|
+
/** Execution ID */
|
|
508
|
+
executionId?: string;
|
|
509
|
+
/** Error message (if any) */
|
|
510
|
+
errorMessage?: string;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Historical process instance query parameters
|
|
515
|
+
*/
|
|
516
|
+
export interface HistoryProcessInstanceQueryParams {
|
|
517
|
+
/** Filter by user who started the process */
|
|
518
|
+
startedBy?: string;
|
|
519
|
+
/** Filter finished/unfinished processes */
|
|
520
|
+
finished?: boolean;
|
|
521
|
+
/** Filter by process definition key */
|
|
522
|
+
processDefinitionKey?: string;
|
|
523
|
+
/** Sort field */
|
|
524
|
+
sortBy?: string;
|
|
525
|
+
/** Sort order */
|
|
526
|
+
sortOrder?: 'asc' | 'desc';
|
|
527
|
+
/** Pagination: first result index */
|
|
528
|
+
firstResult?: number;
|
|
529
|
+
/** Pagination: max results to return */
|
|
530
|
+
maxResults?: number;
|
|
531
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* Common Types - Shared across all modules
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* This file contains shared type definitions used by all Amaster client modules.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Standard API response wrapper
|
|
13
|
+
*
|
|
14
|
+
* All Amaster API methods return results wrapped in this structure for
|
|
15
|
+
* consistent error handling and type safety.
|
|
16
|
+
*
|
|
17
|
+
* @template T - The type of the successful response data
|
|
18
|
+
*
|
|
19
|
+
* @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);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* Check by HTTP status:
|
|
39
|
+
* ```typescript
|
|
40
|
+
* 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
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export interface ClientResult<T> {
|
|
49
|
+
/**
|
|
50
|
+
* Response data (null if error occurred)
|
|
51
|
+
*/
|
|
52
|
+
data: T | null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Error information (null if successful)
|
|
56
|
+
*/
|
|
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;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* HTTP response status code
|
|
76
|
+
*/
|
|
77
|
+
status: number;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* HTTP request methods
|
|
82
|
+
*/
|
|
83
|
+
export type HttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Pagination parameters for list queries
|
|
87
|
+
*/
|
|
88
|
+
export interface PaginationParams {
|
|
89
|
+
/**
|
|
90
|
+
* Page number (1-based)
|
|
91
|
+
* @default 1
|
|
92
|
+
*/
|
|
93
|
+
page?: number;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Number of items per page
|
|
97
|
+
* @default 20
|
|
98
|
+
*/
|
|
99
|
+
perPage?: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Paginated response structure
|
|
104
|
+
*
|
|
105
|
+
* @template T - The type of items in the list
|
|
106
|
+
*/
|
|
107
|
+
export interface PaginatedResult<T> {
|
|
108
|
+
/**
|
|
109
|
+
* Array of items for current page
|
|
110
|
+
*/
|
|
111
|
+
items: T[];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Total number of items across all pages
|
|
115
|
+
*/
|
|
116
|
+
total: number;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Current page number (1-based)
|
|
120
|
+
*/
|
|
121
|
+
page: number;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Number of items per page
|
|
125
|
+
*/
|
|
126
|
+
perPage: number;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Total number of pages
|
|
130
|
+
*/
|
|
131
|
+
totalPages?: number;
|
|
132
|
+
}
|