@amaster.ai/client 1.1.0-beta.30 → 1.1.0-beta.32

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.
@@ -1,9 +1,5 @@
1
1
  /**
2
- * ============================================================================
3
- * Function Invocation - Type Definitions
4
- * ============================================================================
5
- *
6
- * Invoke serverless functions deployed on the Amaster platform.
2
+ * * Invoke serverless functions deployed on the Amaster platform.
7
3
  *
8
4
  * @module function
9
5
  */
@@ -15,67 +11,9 @@ import type { ClientResult } from './common';
15
11
  *
16
12
  * Execute serverless functions with type-safe parameters and results.
17
13
  *
18
- * @example
19
- * Basic function call:
20
- * ```typescript
21
- * const client = createClient({ baseURL: 'https://api.amaster.ai' });
22
- *
23
- * // Call a function
24
- * const result = await client.function.invoke('sendEmail', {
25
- * to: 'user@example.com',
26
- * subject: 'Hello',
27
- * body: 'Welcome to Amaster!'
28
- * });
29
- *
30
- * if (result.data) {
31
- * console.log('Email sent successfully:', result.data);
32
- * }
33
- * ```
34
- *
35
- * @example
36
- * With TypeScript generics:
37
- * ```typescript
38
- * interface SendEmailParams {
39
- * to: string;
40
- * subject: string;
41
- * body: string;
42
- * }
43
- *
44
- * interface SendEmailResult {
45
- * messageId: string;
46
- * status: 'sent' | 'queued';
47
- * }
48
- *
49
- * const result = await client.function.invoke<SendEmailResult>(
50
- * 'sendEmail',
51
- * {
52
- * to: 'user@example.com',
53
- * subject: 'Hello',
54
- * body: 'Welcome!'
55
- * }
56
- * );
57
- *
58
- * if (result.data) {
59
- * console.log('Message ID:', result.data.messageId);
60
- * }
61
- * ```
62
- *
63
- * @example
64
- * Error handling:
65
- * ```typescript
66
- * const result = await client.function.invoke('processPayment', {
67
- * amount: 100,
68
- * currency: 'USD'
69
- * });
70
- *
71
- * if (result.error) {
72
- * console.error('Payment failed:', result.error.message);
73
- * } else {
74
- * console.log('Payment processed:', result.data);
75
- * }
76
- * ```
14
+ * @since 1.0.0
77
15
  */
78
- export interface FunctionClient {
16
+ export interface FunctionClientAPI {
79
17
  /**
80
18
  * Invoke a serverless function
81
19
  *
@@ -84,32 +22,17 @@ export interface FunctionClient {
84
22
  * @returns Function execution result
85
23
  *
86
24
  * @example
87
- * Simple function call:
88
- * ```typescript
89
- * const result = await client.function.invoke('hello', {
90
- * name: 'World'
25
+ * const result = await client.function.invoke<{ message: string }>('sendEmail', {
26
+ * to: 'user@example.com',
27
+ * subject: 'Hello',
28
+ * body: 'Welcome!'
91
29
  * });
92
30
  *
93
- * console.log(result.data); // { message: 'Hello, World!' }
94
- * ```
95
- *
96
- * @example
97
- * Function without parameters:
98
- * ```typescript
99
- * const result = await client.function.invoke('getCurrentTime');
100
- * console.log(result.data); // { timestamp: '2024-01-01T00:00:00Z' }
101
- * ```
102
- *
103
- * @example
104
- * Complex data processing:
105
- * ```typescript
106
- * const result = await client.function.invoke('analyzeData', {
107
- * dataset: [1, 2, 3, 4, 5],
108
- * operation: 'average'
109
- * });
31
+ * if (result.success) {
32
+ * console.log(result.data.message);
33
+ * }
110
34
  *
111
- * console.log(result.data); // { result: 3, count: 5 }
112
- * ```
35
+ * @since 1.0.0
113
36
  */
114
37
  invoke<T = unknown>(
115
38
  funcName: string,
package/types/index.d.ts CHANGED
@@ -1,9 +1,5 @@
1
1
  /**
2
- * ============================================================================
3
- * @amaster.ai/client - Unified API Client
4
- * ============================================================================
5
- *
6
- * A Supabase-inspired unified client for the Amaster platform.
2
+ * * A Supabase-inspired unified client for the Amaster platform.
7
3
  *
8
4
  * ## Features
9
5
  * - Single client instance for all services (auth, entity, bpm, workflow)
@@ -46,63 +42,26 @@
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
47
  import type { AuthClientAPI } from './auth/index';
54
48
  import type { EntityClientAPI } from './entity';
55
49
  import type { BpmClientAPI } from './bpm';
56
50
  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';
51
+ import type { ASRClientAPI } 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';
61
56
 
62
57
  /**
63
58
  * 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
- * ```
59
+ *
99
60
  */
100
61
  export interface AmasterClientOptions {
101
62
  /**
102
63
  * Base URL for the Amaster API
103
- *
104
- * @example 'https://api.amaster.ai'
105
- * @example 'https://my-app.amaster.ai'
64
+ *
106
65
  */
107
66
  baseURL: string;
108
67
 
@@ -111,15 +70,7 @@ export interface AmasterClientOptions {
111
70
  *
112
71
  * These headers will be merged with authentication headers.
113
72
  * 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
- * ```
73
+ *
123
74
  */
124
75
  headers?: Record<string, string>;
125
76
 
@@ -128,22 +79,7 @@ export interface AmasterClientOptions {
128
79
  *
129
80
  * Use this to redirect to login page or show authentication modal.
130
81
  * 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
- * ```
82
+ *
147
83
  */
148
84
  onUnauthorized?: () => void;
149
85
 
@@ -152,14 +88,7 @@ export interface AmasterClientOptions {
152
88
  *
153
89
  * Note: Token refresh is handled automatically by the client.
154
90
  * 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
- * ```
91
+ *
163
92
  */
164
93
  onTokenExpired?: () => void;
165
94
 
@@ -182,6 +111,17 @@ export interface AmasterClientOptions {
182
111
  * @default 300
183
112
  */
184
113
  refreshThreshold?: number;
114
+
115
+ /**
116
+ * Auto-handle OAuth callback on page load (default: true)
117
+ *
118
+ * Automatically detects and processes `#access_token` in URL hash,
119
+ * then clears the hash for security. Set to `false` to manually
120
+ * call `client.auth.handleOAuthCallback()`.
121
+ *
122
+ * @default true
123
+ */
124
+ autoHandleOAuthCallback?: boolean;
185
125
  }
186
126
 
187
127
  /**
@@ -201,32 +141,7 @@ export interface AmasterClientOptions {
201
141
  * - {@link getAccessToken} - Get current access token
202
142
  * - {@link setAccessToken} - Set access token manually
203
143
  * - {@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
- * ```
144
+ *
230
145
  */
231
146
  export interface AmasterClient {
232
147
  /**
@@ -235,32 +150,7 @@ export interface AmasterClient {
235
150
  * Provides methods for user authentication, registration, and management.
236
151
  *
237
152
  * 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
- * ```
153
+ *
264
154
  */
265
155
  auth: AuthClientAPI;
266
156
 
@@ -270,26 +160,7 @@ export interface AmasterClient {
270
160
  * Provides methods for creating, reading, updating, and deleting entities.
271
161
  *
272
162
  * 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
- * ```
163
+ *
293
164
  */
294
165
  entity: EntityClientAPI;
295
166
 
@@ -299,24 +170,7 @@ export interface AmasterClient {
299
170
  * Provides methods for managing BPMN processes and tasks.
300
171
  *
301
172
  * 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
- * ```
173
+ *
320
174
  */
321
175
  bpm: BpmClientAPI;
322
176
 
@@ -326,16 +180,7 @@ export interface AmasterClient {
326
180
  * Provides methods for executing Dify-style workflows.
327
181
  *
328
182
  * 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
- * ```
183
+ *
339
184
  */
340
185
  workflow: WorkflowClientAPI;
341
186
 
@@ -346,7 +191,7 @@ export interface AmasterClient {
346
191
  *
347
192
  * For detailed documentation, see {@link ./asr.d.ts}
348
193
  */
349
- asr: ASRClient;
194
+ asr: ASRClientAPI;
350
195
 
351
196
  /**
352
197
  * Copilot AI Assistant module
@@ -354,20 +199,9 @@ export interface AmasterClient {
354
199
  * Provides methods for interactive AI conversations with A2UI streaming.
355
200
  *
356
201
  * 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
- * ```
202
+ *
369
203
  */
370
- copilot: CopilotA2UIClient;
204
+ copilot: CopilotClientAPI;
371
205
 
372
206
  /**
373
207
  * Serverless Function module
@@ -376,7 +210,7 @@ export interface AmasterClient {
376
210
  *
377
211
  * For detailed documentation, see {@link ./function.d.ts}
378
212
  */
379
- function: FunctionClient;
213
+ function: FunctionClientAPI;
380
214
 
381
215
  /**
382
216
  * TTS (Text-to-Speech) module
@@ -385,21 +219,22 @@ export interface AmasterClient {
385
219
  *
386
220
  * For detailed documentation, see {@link ./tts.d.ts}
387
221
  */
388
- tts: TTSClient;
222
+ tts: TTSClientAPI;
223
+
224
+ /**
225
+ * S3 Storage module
226
+ *
227
+ * Provides methods for file upload, download, and management.
228
+ *
229
+ * For detailed documentation, see {@link ./s3.d.ts}
230
+ */
231
+ s3: S3ClientAPI;
389
232
 
390
233
  /**
391
234
  * Check if the user is currently authenticated
392
235
  *
393
236
  * @returns `true` if a valid access token exists, `false` otherwise
394
- *
395
- * @example
396
- * ```typescript
397
- * if (client.isAuthenticated()) {
398
- * console.log('User is logged in');
399
- * } else {
400
- * console.log('Please log in');
401
- * }
402
- * ```
237
+ *
403
238
  */
404
239
  isAuthenticated(): boolean;
405
240
 
@@ -407,23 +242,7 @@ export interface AmasterClient {
407
242
  * Get the current access token
408
243
  *
409
244
  * @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
- * ```
245
+ *
427
246
  */
428
247
  getAccessToken(): string | null;
429
248
 
@@ -434,25 +253,7 @@ export interface AmasterClient {
434
253
  * After setting the token, all requests will use it automatically.
435
254
  *
436
255
  * @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
- * ```
256
+ *
456
257
  */
457
258
  setAccessToken(token: string): void;
458
259
 
@@ -466,21 +267,7 @@ export interface AmasterClient {
466
267
  *
467
268
  * After calling this, `isAuthenticated()` will return `false`
468
269
  * 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
- * ```
270
+ *
484
271
  */
485
272
  clearAuth(): void;
486
273
  }
@@ -493,45 +280,7 @@ export interface AmasterClient {
493
280
  *
494
281
  * @param options - Configuration options for the client
495
282
  * @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
- * ```
283
+ *
535
284
  */
536
285
  export declare function createClient(options: AmasterClientOptions): AmasterClient;
537
286
 
@@ -543,10 +292,11 @@ export type { AuthClientAPI } from './auth';
543
292
  export type { EntityClientAPI } from './entity';
544
293
  export type { BpmClientAPI } from './bpm';
545
294
  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';
295
+ export type { ASRClientAPI } from './asr';
296
+ export type { CopilotClientAPI } from './copilot';
297
+ export type { FunctionClientAPI } from './function';
298
+ export type { TTSClientAPI } from './tts';
299
+ export type { S3ClientAPI } from './s3';
550
300
 
551
301
  // For detailed types, import directly from submodules:
552
302
  // import type { LoginParams, User } from '@amaster.ai/client/auth'