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

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/index.d.ts CHANGED
@@ -1,44 +1,40 @@
1
1
  /**
2
- * ============================================================================
3
- * @amaster.ai/client - Unified API Client
4
- * ============================================================================
5
- *
6
- * A Supabase-inspired unified client for the Amaster platform.
7
- *
2
+ * * A Supabase-inspired unified client for the Amaster platform.
3
+ *
8
4
  * ## Features
9
5
  * - Single client instance for all services (auth, entity, bpm, workflow)
10
6
  * - Automatic token management and refresh
11
7
  * - Auto-attach authentication to all requests
12
8
  * - Centralized error handling
13
- *
9
+ *
14
10
  * ## Quick Start
15
11
  * ```typescript
16
12
  * import { createClient } from '@amaster.ai/client';
17
- *
13
+ *
18
14
  * const client = createClient({
19
15
  * baseURL: 'https://api.amaster.ai',
20
16
  * onUnauthorized: () => window.location.href = '/login'
21
17
  * });
22
- *
18
+ *
23
19
  * // Login
24
20
  * await client.auth.login({ email, password });
25
- *
21
+ *
26
22
  * // All subsequent requests automatically include auth token
27
23
  * await client.entity.list('default', 'users');
28
24
  * await client.bpm.startProcess('approval', {});
29
25
  * ```
30
- *
26
+ *
31
27
  * ## Module Documentation
32
28
  * For detailed API documentation, see individual module type definitions:
33
29
  * - **Authentication**: {@link ./auth/index.d.ts} (split into user, password-auth, code-auth, oauth, permissions, profile)
34
30
  * - **Entity Operations**: {@link ./entity.d.ts}
35
31
  * - **BPM (Business Process)**: {@link ./bpm.d.ts}
36
32
  * - **Workflow Execution**: {@link ./workflow.d.ts}
37
- *
33
+ *
38
34
  * ## AI-Friendly Type Structure
39
35
  * This package provides modular type definitions optimized for AI tools and large language models.
40
36
  * Types are split into focused modules that can be loaded on-demand:
41
- *
37
+ *
42
38
  * **Authentication Types** (70-88% token savings):
43
39
  * - `@amaster.ai/client/auth/user` - User types (100 lines)
44
40
  * - `@amaster.ai/client/auth/password-auth` - Login/register (200 lines)
@@ -46,507 +42,293 @@
46
42
  * - `@amaster.ai/client/auth/oauth` - OAuth providers (120 lines)
47
43
  * - `@amaster.ai/client/auth/permissions` - Permission helpers (80 lines)
48
44
  * - `@amaster.ai/client/auth/profile` - Profile management (100 lines)
49
- *
50
- * @packageDocumentation
51
- */
45
+ * */
52
46
 
53
- import type { AuthClientAPI } from './auth/index';
54
- import type { EntityClientAPI } from './entity';
55
- import type { BpmClientAPI } from './bpm';
56
- import type { WorkflowClientAPI } from './workflow';
57
- import type { ASRClient } from './asr';
58
- import type { CopilotA2UIClient } from './copilot';
59
- import type { FunctionClient } from './function';
60
- import type { TTSClient } from './tts';
47
+ import type { AuthClientAPI } from "./auth/index";
48
+ import type { EntityClientAPI } from "./entity";
49
+ import type { BpmClientAPI } from "./bpm";
50
+ import type { WorkflowClientAPI } from "./workflow";
51
+ import type { ASRClientConfig, ASRClient, ASRHttpClientConfig, ASRHttpClient } from "./asr";
52
+ import type { CopilotClientAPI } from "./copilot";
53
+ import type { FunctionClientAPI } from "./function";
54
+ import type { TTSClientAPI } from "./tts";
55
+ import type { S3ClientAPI } from "./s3";
56
+ import type { HttpClient } from "./http";
61
57
 
62
58
  /**
63
59
  * Configuration options for creating an Amaster client
64
- *
65
- * @example
66
- * Basic configuration:
67
- * ```typescript
68
- * const client = createClient({
69
- * baseURL: 'https://api.amaster.ai'
70
- * });
71
- * ```
72
- *
73
- * @example
74
- * With authentication callbacks:
75
- * ```typescript
76
- * const client = createClient({
77
- * baseURL: 'https://api.amaster.ai',
78
- * onUnauthorized: () => {
79
- * console.log('User is not authenticated');
80
- * window.location.href = '/login';
81
- * },
82
- * onTokenExpired: () => {
83
- * console.log('Token expired, refreshing...');
84
- * }
85
- * });
86
- * ```
87
- *
88
- * @example
89
- * With custom headers:
90
- * ```typescript
91
- * const client = createClient({
92
- * baseURL: 'https://api.amaster.ai',
93
- * headers: {
94
- * 'X-Tenant-ID': 'tenant-123',
95
- * 'X-App-Version': '1.0.0'
96
- * }
97
- * });
98
- * ```
60
+ *
99
61
  */
100
62
  export interface AmasterClientOptions {
101
63
  /**
102
64
  * Base URL for the Amaster API
103
- *
104
- * @example 'https://api.amaster.ai'
105
- * @example 'https://my-app.amaster.ai'
65
+ *
106
66
  */
107
67
  baseURL: string;
108
68
 
109
69
  /**
110
70
  * Optional custom headers to include in ALL requests
111
- *
71
+ *
112
72
  * These headers will be merged with authentication headers.
113
73
  * Useful for tenant IDs, API keys, or application metadata.
114
- *
115
- * @example
116
- * ```typescript
117
- * {
118
- * 'X-Tenant-ID': 'tenant-123',
119
- * 'X-App-Version': '1.0.0',
120
- * 'X-Custom-Header': 'custom-value'
121
- * }
122
- * ```
74
+ *
123
75
  */
124
76
  headers?: Record<string, string>;
125
77
 
126
78
  /**
127
79
  * Callback triggered when a 401 Unauthorized response is received
128
- *
80
+ *
129
81
  * Use this to redirect to login page or show authentication modal.
130
82
  * This callback is invoked BEFORE the request promise rejects.
131
- *
132
- * @example
133
- * Redirect to login page:
134
- * ```typescript
135
- * onUnauthorized: () => {
136
- * window.location.href = '/login';
137
- * }
138
- * ```
139
- *
140
- * @example
141
- * Show modal:
142
- * ```typescript
143
- * onUnauthorized: () => {
144
- * showLoginModal();
145
- * }
146
- * ```
83
+ *
147
84
  */
148
85
  onUnauthorized?: () => void;
149
86
 
150
87
  /**
151
88
  * Callback triggered when the access token expires
152
- *
89
+ *
153
90
  * Note: Token refresh is handled automatically by the client.
154
91
  * This callback is for additional actions like logging or analytics.
155
- *
156
- * @example
157
- * ```typescript
158
- * onTokenExpired: () => {
159
- * console.log('Token expired, auto-refreshing...');
160
- * analytics.track('token_expired');
161
- * }
162
- * ```
92
+ *
163
93
  */
164
94
  onTokenExpired?: () => void;
165
95
 
166
96
  /**
167
97
  * Enable automatic token refresh (default: true)
168
- *
98
+ *
169
99
  * When enabled, tokens are automatically refreshed before expiry.
170
- *
100
+ *
171
101
  * @default true
172
102
  */
173
103
  autoRefresh?: boolean;
174
104
 
175
105
  /**
176
106
  * Token refresh threshold in seconds (default: 300)
177
- *
107
+ *
178
108
  * Tokens will be refreshed this many seconds before expiry.
179
109
  * For example, if set to 300 (5 minutes), a token expiring at
180
110
  * 10:00:00 will be refreshed at 9:55:00.
181
- *
111
+ *
182
112
  * @default 300
183
113
  */
184
114
  refreshThreshold?: number;
115
+
116
+ /**
117
+ * Auto-handle OAuth callback on page load (default: true)
118
+ *
119
+ * Automatically detects and processes `#access_token` in URL hash,
120
+ * then clears the hash for security. Set to `false` to manually
121
+ * call `client.auth.handleOAuthCallback()`.
122
+ *
123
+ * @default true
124
+ */
125
+ autoHandleOAuthCallback?: boolean;
185
126
  }
186
127
 
187
128
  /**
188
129
  * Unified Amaster Client interface
189
- *
130
+ *
190
131
  * This is the main client object returned by `createClient()`.
191
132
  * It provides access to all Amaster services through a unified interface.
192
- *
133
+ *
193
134
  * ## Core Modules
194
135
  * - {@link auth} - Authentication and user management
195
136
  * - {@link entity} - CRUD operations for entities
196
137
  * - {@link bpm} - Business process management
197
138
  * - {@link workflow} - Workflow execution
198
- *
139
+ *
199
140
  * ## Token Management
200
141
  * - {@link isAuthenticated} - Check if user is authenticated
201
142
  * - {@link getAccessToken} - Get current access token
202
143
  * - {@link setAccessToken} - Set access token manually
203
144
  * - {@link clearAuth} - Clear all authentication state
204
- *
205
- * @example
206
- * Complete authentication flow:
207
- * ```typescript
208
- * const client = createClient({ baseURL: 'https://api.amaster.ai' });
209
- *
210
- * // 1. Login
211
- * await client.auth.login({
212
- * email: 'user@example.com',
213
- * password: 'password123'
214
- * });
215
- *
216
- * // 2. Check authentication
217
- * if (client.isAuthenticated()) {
218
- * console.log('User is logged in');
219
- * }
220
- *
221
- * // 3. Get current token
222
- * const token = client.getAccessToken();
223
- *
224
- * // 4. Use any service (token automatically attached)
225
- * const users = await client.entity.list('default', 'users');
226
- *
227
- * // 5. Logout
228
- * await client.auth.logout();
229
- * ```
145
+ *
230
146
  */
231
147
  export interface AmasterClient {
232
148
  /**
233
149
  * Authentication module
234
- *
150
+ *
235
151
  * Provides methods for user authentication, registration, and management.
236
- *
152
+ *
237
153
  * For detailed documentation, see {@link ./auth.d.ts}
238
- *
239
- * @example
240
- * Login:
241
- * ```typescript
242
- * await client.auth.login({
243
- * email: 'user@example.com',
244
- * password: 'password123'
245
- * });
246
- * ```
247
- *
248
- * @example
249
- * Register:
250
- * ```typescript
251
- * await client.auth.register({
252
- * username: 'johndoe',
253
- * email: 'john@example.com',
254
- * password: 'Password@123'
255
- * });
256
- * ```
257
- *
258
- * @example
259
- * Get current user:
260
- * ```typescript
261
- * const result = await client.auth.getMe();
262
- * console.log(result.data); // User object
263
- * ```
154
+ *
264
155
  */
265
156
  auth: AuthClientAPI;
266
157
 
267
158
  /**
268
159
  * Entity CRUD operations module
269
- *
160
+ *
270
161
  * Provides methods for creating, reading, updating, and deleting entities.
271
- *
162
+ *
272
163
  * For detailed documentation, see {@link ./entity.d.ts}
273
- *
274
- * @example
275
- * List entities:
276
- * ```typescript
277
- * const result = await client.entity.list('default', 'users', {
278
- * page: 1,
279
- * perPage: 20,
280
- * orderBy: 'createdAt',
281
- * orderDir: 'desc'
282
- * });
283
- * ```
284
- *
285
- * @example
286
- * Create entity:
287
- * ```typescript
288
- * await client.entity.create('default', 'users', {
289
- * name: 'John Doe',
290
- * email: 'john@example.com'
291
- * });
292
- * ```
164
+ *
293
165
  */
294
166
  entity: EntityClientAPI;
295
167
 
296
168
  /**
297
169
  * Business Process Management (BPM) module
298
- *
170
+ *
299
171
  * Provides methods for managing BPMN processes and tasks.
300
- *
172
+ *
301
173
  * For detailed documentation, see {@link ./bpm.d.ts}
302
- *
303
- * @example
304
- * Start a process:
305
- * ```typescript
306
- * const result = await client.bpm.startProcess('approval', {
307
- * amount: { value: 1000, type: 'Long' },
308
- * requester: { value: 'user-123', type: 'String' }
309
- * });
310
- * ```
311
- *
312
- * @example
313
- * Get tasks:
314
- * ```typescript
315
- * const tasks = await client.bpm.getTasks({
316
- * assignee: 'user-123',
317
- * processDefinitionKey: 'approval'
318
- * });
319
- * ```
174
+ *
320
175
  */
321
176
  bpm: BpmClientAPI;
322
177
 
323
178
  /**
324
179
  * Workflow execution module
325
- *
180
+ *
326
181
  * Provides methods for executing Dify-style workflows.
327
- *
182
+ *
328
183
  * For detailed documentation, see {@link ./workflow.d.ts}
329
- *
330
- * @example
331
- * Run a workflow:
332
- * ```typescript
333
- * const result = await client.workflow.run('data-analysis', {
334
- * input_data: 'sample data',
335
- * options: { format: 'json' }
336
- * });
337
- * console.log(result.data.outputs);
338
- * ```
184
+ *
339
185
  */
340
186
  workflow: WorkflowClientAPI;
341
187
 
342
188
  /**
343
189
  * ASR (Automatic Speech Recognition) module
344
- *
190
+ *
345
191
  * Provides methods for real-time speech-to-text conversion via WebSocket.
346
- *
192
+ *
347
193
  * For detailed documentation, see {@link ./asr.d.ts}
348
194
  */
349
- asr: ASRClient;
195
+ asr: (config: ASRClientConfig) => ASRClient;
196
+
197
+ /**
198
+ * ASR HTTP module
199
+ *
200
+ * Provides methods for speech-to-text conversion via HTTP API.
201
+ *
202
+ * For detailed documentation, see
203
+ */
204
+ asrHttp: (config: ASRHttpClientConfig) => ASRHttpClient;
350
205
 
351
206
  /**
352
207
  * Copilot AI Assistant module
353
- *
354
- * Provides methods for interactive AI conversations with A2UI streaming.
355
- *
208
+ *
209
+ * Provides methods for interactive AI conversations with a2a streaming.
210
+ *
356
211
  * For detailed documentation, see {@link ./copilot.d.ts}
357
- *
358
- * @example
359
- * Chat with AI:
360
- * ```typescript
361
- * const stream = client.copilot.chat([
362
- * { role: 'user', content: 'Hello' }
363
- * ]);
364
- *
365
- * for await (const messages of stream) {
366
- * // Process A2UI messages
367
- * }
368
- * ```
212
+ *
369
213
  */
370
- copilot: CopilotA2UIClient;
214
+ copilot: CopilotClientAPI;
371
215
 
372
216
  /**
373
217
  * Serverless Function module
374
- *
218
+ *
375
219
  * Provides methods for invoking serverless functions.
376
- *
220
+ *
377
221
  * For detailed documentation, see {@link ./function.d.ts}
378
222
  */
379
- function: FunctionClient;
223
+ function: FunctionClientAPI;
380
224
 
381
225
  /**
382
226
  * TTS (Text-to-Speech) module
383
- *
227
+ *
384
228
  * Provides methods for real-time text-to-speech conversion via WebSocket.
385
- *
229
+ *
386
230
  * For detailed documentation, see {@link ./tts.d.ts}
387
231
  */
388
- tts: TTSClient;
232
+ tts: TTSClientAPI;
389
233
 
390
234
  /**
391
- * Check if the user is currently authenticated
392
- *
393
- * @returns `true` if a valid access token exists, `false` otherwise
394
- *
395
- * @example
235
+ * S3 Storage module
236
+ *
237
+ * Provides methods for file upload, download, and management.
238
+ *
239
+ * For detailed documentation, see {@link ./s3.d.ts}
240
+ */
241
+ s3: S3ClientAPI;
242
+
243
+ /**
244
+ * HTTP client instance used for all requests
245
+ *
246
+ * This is the underlying HTTP client that handles all API requests.
247
+ * It automatically includes authentication headers and base URL.
248
+ * You can use this client to make custom requests to the Amaster API
249
+ * or your own backend while still benefiting from automatic token management.
250
+ * For example:
396
251
  * ```typescript
397
- * if (client.isAuthenticated()) {
398
- * console.log('User is logged in');
399
- * } else {
400
- * console.log('Please log in');
401
- * }
252
+ * const response = await client.http.request({
253
+ * url: '/api/custom-endpoint',
254
+ * method: 'POST',
255
+ * data: { key: 'value' }
256
+ * });
257
+ * console.log(response.data);
402
258
  * ```
259
+ * Note: The `http` client is an instance of the same HTTP client used internally by the Amaster client.
260
+ * It automatically includes the base URL and authentication headers configured in `createClient()`.
261
+ */
262
+ http: HttpClient;
263
+
264
+ /**
265
+ * Check if the user is currently authenticated
266
+ *
267
+ * @returns `true` if a valid access token exists, `false` otherwise
268
+ *
403
269
  */
404
270
  isAuthenticated(): boolean;
405
271
 
406
272
  /**
407
273
  * Get the current access token
408
- *
274
+ *
409
275
  * @returns The access token string, or `null` if not authenticated
410
- *
411
- * @example
412
- * ```typescript
413
- * const token = client.getAccessToken();
414
- * if (token) {
415
- * console.log('Token:', token);
416
- * }
417
- * ```
418
- *
419
- * @example
420
- * Store token for later use:
421
- * ```typescript
422
- * const token = client.getAccessToken();
423
- * if (token) {
424
- * localStorage.setItem('backup_token', token);
425
- * }
426
- * ```
276
+ *
427
277
  */
428
278
  getAccessToken(): string | null;
429
279
 
430
280
  /**
431
281
  * Manually set the access token
432
- *
282
+ *
433
283
  * Useful when you have a token from another source (e.g., SSO, OAuth).
434
284
  * After setting the token, all requests will use it automatically.
435
- *
285
+ *
436
286
  * @param token - The JWT access token to set
437
- *
438
- * @example
439
- * Set token from OAuth:
440
- * ```typescript
441
- * const ssoToken = await getSSOToken();
442
- * client.setAccessToken(ssoToken);
443
- *
444
- * // Now all requests will use this token
445
- * await client.entity.list('default', 'users');
446
- * ```
447
- *
448
- * @example
449
- * Restore token from storage:
450
- * ```typescript
451
- * const savedToken = localStorage.getItem('auth_token');
452
- * if (savedToken) {
453
- * client.setAccessToken(savedToken);
454
- * }
455
- * ```
287
+ *
456
288
  */
457
289
  setAccessToken(token: string): void;
458
290
 
459
291
  /**
460
292
  * Clear all authentication state
461
- *
293
+ *
462
294
  * This removes:
463
295
  * - Access token
464
296
  * - User information
465
297
  * - Auto-refresh timers
466
- *
298
+ *
467
299
  * After calling this, `isAuthenticated()` will return `false`
468
300
  * and all requests will be unauthenticated.
469
- *
470
- * @example
471
- * ```typescript
472
- * client.clearAuth();
473
- * console.log(client.isAuthenticated()); // false
474
- * console.log(client.getAccessToken()); // null
475
- * ```
476
- *
477
- * @example
478
- * Logout without API call:
479
- * ```typescript
480
- * // If you want to clear local state without calling logout API
481
- * client.clearAuth();
482
- * window.location.href = '/login';
483
- * ```
301
+ *
484
302
  */
485
303
  clearAuth(): void;
486
304
  }
487
305
 
488
306
  /**
489
307
  * Factory function to create a unified Amaster client
490
- *
308
+ *
491
309
  * This is the main entry point for using the Amaster client library.
492
310
  * It returns a client instance that provides access to all Amaster services.
493
- *
311
+ *
494
312
  * @param options - Configuration options for the client
495
313
  * @returns A configured Amaster client instance
496
- *
497
- * @example
498
- * Basic usage:
499
- * ```typescript
500
- * import { createClient } from '@amaster.ai/client';
501
- *
502
- * const client = createClient({
503
- * baseURL: 'https://api.amaster.ai'
504
- * });
505
- *
506
- * await client.auth.login({ email, password });
507
- * ```
508
- *
509
- * @example
510
- * With callbacks:
511
- * ```typescript
512
- * const client = createClient({
513
- * baseURL: 'https://api.amaster.ai',
514
- * onUnauthorized: () => {
515
- * console.log('Session expired');
516
- * window.location.href = '/login';
517
- * },
518
- * onTokenExpired: () => {
519
- * console.log('Token expired, refreshing...');
520
- * }
521
- * });
522
- * ```
523
- *
524
- * @example
525
- * With custom headers:
526
- * ```typescript
527
- * const client = createClient({
528
- * baseURL: 'https://api.amaster.ai',
529
- * headers: {
530
- * 'X-Tenant-ID': 'tenant-123',
531
- * 'X-App-Version': '1.0.0'
532
- * }
533
- * });
534
- * ```
314
+ *
535
315
  */
536
316
  export declare function createClient(options: AmasterClientOptions): AmasterClient;
537
317
 
538
318
  // Re-export shared common types
539
- export type { ClientResult } from './common';
319
+ export type { ClientResult } from "./common";
540
320
 
541
321
  // Re-export main client interfaces
542
- export type { AuthClientAPI } from './auth';
543
- export type { EntityClientAPI } from './entity';
544
- export type { BpmClientAPI } from './bpm';
545
- export type { WorkflowClientAPI } from './workflow';
546
- export type { ASRClient } from './asr';
547
- export type { CopilotA2UIClient } from './copilot';
548
- export type { FunctionClient } from './function';
549
- export type { TTSClient } from './tts';
322
+ export type { AuthClientAPI } from "./auth";
323
+ export type { EntityClientAPI } from "./entity";
324
+ export type { BpmClientAPI } from "./bpm";
325
+ export type { WorkflowClientAPI } from "./workflow";
326
+ export type { ASRClient, ASRClientConfig, ASRHttpClient, ASRHttpClientConfig, Recorder, RecorderOptions } from "./asr";
327
+ export type { CopilotClientAPI } from "./copilot";
328
+ export type { FunctionClientAPI } from "./function";
329
+ export type { TTSClientAPI } from "./tts";
330
+ export type { S3ClientAPI } from "./s3";
331
+ export type { HttpClient } from "./http";
550
332
 
551
333
  // For detailed types, import directly from submodules:
552
334
  // import type { LoginParams, User } from '@amaster.ai/client/auth'