@amaster.ai/client 1.1.0-beta.4 → 1.1.0-beta.41
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/dist/index.cjs +84 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +84 -8
- package/dist/index.js.map +1 -1
- package/package.json +15 -11
- package/types/__tests__/type-checks.test-d.ts +163 -0
- package/types/asr.d.ts +10 -114
- package/types/auth/code-auth.d.ts +5 -154
- package/types/auth/index.d.ts +54 -96
- package/types/auth/oauth.d.ts +6 -143
- package/types/auth/password-auth.d.ts +38 -137
- package/types/auth/profile.d.ts +4 -103
- package/types/auth/user.d.ts +8 -32
- package/types/bpm.d.ts +182 -92
- package/types/common.d.ts +52 -44
- package/types/copilot.d.ts +78 -124
- package/types/entity.d.ts +65 -342
- package/types/function.d.ts +11 -88
- package/types/index.d.ts +85 -278
- package/types/s3.d.ts +96 -0
- package/types/tts.d.ts +10 -128
- package/types/workflow.d.ts +16 -165
- package/types/auth/permissions.d.ts +0 -254
package/types/tts.d.ts
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* TTS (Text-to-Speech) - Type Definitions
|
|
4
|
-
* ============================================================================
|
|
5
|
-
*
|
|
6
|
-
* Real-time text-to-speech synthesis using WebSocket connection.
|
|
2
|
+
* * Real-time text-to-speech synthesis using WebSocket connection.
|
|
7
3
|
*
|
|
8
4
|
* @module tts
|
|
9
5
|
*/
|
|
10
6
|
|
|
11
7
|
/**
|
|
12
8
|
* TTS Client Configuration
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* Configure TTS with custom voice:
|
|
16
|
-
* ```typescript
|
|
17
|
-
* const client = createClient({ baseURL: 'https://api.amaster.ai' });
|
|
18
|
-
*
|
|
19
|
-
* // Reconfigure TTS client
|
|
20
|
-
* client.tts = createTTSClient({
|
|
21
|
-
* voice: 'Cherry',
|
|
22
|
-
* audioFormat: 'pcm',
|
|
23
|
-
* sampleRate: 24000,
|
|
24
|
-
* autoPlay: true,
|
|
25
|
-
* onAudioStart: () => console.log('Audio started'),
|
|
26
|
-
* onAudioEnd: () => console.log('Audio ended')
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
9
|
+
*
|
|
29
10
|
*/
|
|
30
11
|
export interface TTSClientConfig {
|
|
31
12
|
/** WebSocket path override */
|
|
@@ -63,75 +44,20 @@ export interface TTSClientConfig {
|
|
|
63
44
|
}
|
|
64
45
|
|
|
65
46
|
/**
|
|
66
|
-
* TTS Client API
|
|
67
|
-
*
|
|
68
|
-
* Real-time text-to-speech synthesis client using WebSocket.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* Basic usage:
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const client = createClient({ baseURL: 'https://api.amaster.ai' });
|
|
74
|
-
*
|
|
75
|
-
* // Connect to TTS service
|
|
76
|
-
* await client.tts.connect();
|
|
77
|
-
*
|
|
78
|
-
* // Synthesize and play speech
|
|
79
|
-
* await client.tts.speak('Hello, welcome to Amaster!');
|
|
80
|
-
*
|
|
81
|
-
* // Close connection when done
|
|
82
|
-
* client.tts.close();
|
|
83
|
-
* ```
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* With custom voice and callbacks:
|
|
87
|
-
* ```typescript
|
|
88
|
-
* const client = createClient({ baseURL: 'https://api.amaster.ai' });
|
|
89
|
-
*
|
|
90
|
-
* client.tts = createTTSClient({
|
|
91
|
-
* voice: 'Cherry',
|
|
92
|
-
* autoPlay: true,
|
|
93
|
-
* onReady: () => console.log('TTS ready'),
|
|
94
|
-
* onAudioStart: () => console.log('Playing audio'),
|
|
95
|
-
* onAudioEnd: () => console.log('Audio finished'),
|
|
96
|
-
* onError: (error) => console.error('TTS error:', error)
|
|
97
|
-
* });
|
|
47
|
+
* TTS (Text-to-Speech) Client API
|
|
98
48
|
*
|
|
99
|
-
*
|
|
100
|
-
* await client.tts.speak('This is a test message');
|
|
101
|
-
* ```
|
|
49
|
+
* Provides real-time text-to-speech synthesis via WebSocket.
|
|
102
50
|
*
|
|
103
|
-
* @
|
|
104
|
-
* Manual audio playback:
|
|
105
|
-
* ```typescript
|
|
106
|
-
* const client = createClient({ baseURL: 'https://api.amaster.ai' });
|
|
107
|
-
*
|
|
108
|
-
* client.tts = createTTSClient({
|
|
109
|
-
* autoPlay: false,
|
|
110
|
-
* onAudioChunk: (chunks) => {
|
|
111
|
-
* console.log(`Received ${chunks.length} audio chunks`);
|
|
112
|
-
* }
|
|
113
|
-
* });
|
|
114
|
-
*
|
|
115
|
-
* await client.tts.connect();
|
|
116
|
-
* await client.tts.speak('Hello world');
|
|
117
|
-
*
|
|
118
|
-
* // Manually play collected audio
|
|
119
|
-
* client.tts.play();
|
|
120
|
-
* ```
|
|
51
|
+
* @since 1.0.0
|
|
121
52
|
*/
|
|
122
|
-
export interface
|
|
53
|
+
export interface TTSClientAPI {
|
|
123
54
|
/**
|
|
124
55
|
* Connect to TTS service
|
|
125
56
|
*
|
|
126
57
|
* Establishes WebSocket connection to the text-to-speech service.
|
|
127
58
|
*
|
|
128
59
|
* @returns Promise that resolves when connected
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* await client.tts.connect();
|
|
133
|
-
* console.log('Connected to TTS service');
|
|
134
|
-
* ```
|
|
60
|
+
*
|
|
135
61
|
*/
|
|
136
62
|
connect(): Promise<void>;
|
|
137
63
|
|
|
@@ -142,37 +68,7 @@ export interface TTSClient {
|
|
|
142
68
|
*
|
|
143
69
|
* @param text - Text to synthesize
|
|
144
70
|
* @returns Promise that resolves when synthesis starts
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* Simple text:
|
|
148
|
-
* ```typescript
|
|
149
|
-
* await client.tts.speak('Hello, how can I help you today?');
|
|
150
|
-
* ```
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* Multiple sentences:
|
|
154
|
-
* ```typescript
|
|
155
|
-
* await client.tts.speak(
|
|
156
|
-
* 'Welcome to our service. ' +
|
|
157
|
-
* 'We are glad to have you here. ' +
|
|
158
|
-
* 'Let me know if you need any assistance.'
|
|
159
|
-
* );
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* Sequential playback:
|
|
164
|
-
* ```typescript
|
|
165
|
-
* await client.tts.speak('First message');
|
|
166
|
-
* // Wait for first message to complete
|
|
167
|
-
* await new Promise(resolve => {
|
|
168
|
-
* const originalOnEnd = client.tts.onAudioEnd;
|
|
169
|
-
* client.tts.onAudioEnd = () => {
|
|
170
|
-
* resolve(undefined);
|
|
171
|
-
* client.tts.onAudioEnd = originalOnEnd;
|
|
172
|
-
* };
|
|
173
|
-
* });
|
|
174
|
-
* await client.tts.speak('Second message');
|
|
175
|
-
* ```
|
|
71
|
+
*
|
|
176
72
|
*/
|
|
177
73
|
speak(text: string): Promise<void>;
|
|
178
74
|
|
|
@@ -180,16 +76,7 @@ export interface TTSClient {
|
|
|
180
76
|
* Play audio from chunks
|
|
181
77
|
*
|
|
182
78
|
* Manually plays audio chunks when autoPlay is disabled.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* ```typescript
|
|
186
|
-
* client.tts = createTTSClient({ autoPlay: false });
|
|
187
|
-
* await client.tts.connect();
|
|
188
|
-
* await client.tts.speak('Hello world');
|
|
189
|
-
*
|
|
190
|
-
* // Manually trigger playback
|
|
191
|
-
* client.tts.play();
|
|
192
|
-
* ```
|
|
79
|
+
*
|
|
193
80
|
*/
|
|
194
81
|
play(): void;
|
|
195
82
|
|
|
@@ -197,12 +84,7 @@ export interface TTSClient {
|
|
|
197
84
|
* Close connection
|
|
198
85
|
*
|
|
199
86
|
* Closes the WebSocket connection and releases resources.
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```typescript
|
|
203
|
-
* // Cleanup when done
|
|
204
|
-
* client.tts.close();
|
|
205
|
-
* ```
|
|
87
|
+
*
|
|
206
88
|
*/
|
|
207
89
|
close(): void;
|
|
208
90
|
}
|
package/types/workflow.d.ts
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ============================================================================
|
|
3
|
-
* Workflow Module - Type Definitions
|
|
4
|
-
* ============================================================================
|
|
5
|
-
*
|
|
6
|
-
* This module provides workflow execution capabilities using Dify-style
|
|
7
|
-
* workflow engine.
|
|
8
|
-
*
|
|
9
|
-
* ## Key Features
|
|
10
|
-
* - Execute workflows with inputs
|
|
11
|
-
* - Blocking or streaming execution modes
|
|
12
|
-
* - File upload support
|
|
13
|
-
* - Trace ID for debugging
|
|
14
|
-
* - Auto-inject app_id from URL
|
|
15
2
|
*
|
|
16
3
|
* @module workflow
|
|
17
4
|
*/
|
|
@@ -39,15 +26,7 @@ export type WorkflowInputValue =
|
|
|
39
26
|
|
|
40
27
|
/**
|
|
41
28
|
* Workflow file attachment
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* const file: WorkflowFile = {
|
|
46
|
-
* name: 'document.pdf',
|
|
47
|
-
* type: 'application/pdf',
|
|
48
|
-
* url: 'https://cdn.example.com/document.pdf'
|
|
49
|
-
* };
|
|
50
|
-
* ```
|
|
29
|
+
*
|
|
51
30
|
*/
|
|
52
31
|
export interface WorkflowFile {
|
|
53
32
|
/** File name */
|
|
@@ -63,31 +42,7 @@ export interface WorkflowFile {
|
|
|
63
42
|
/**
|
|
64
43
|
* Workflow execution request parameters
|
|
65
44
|
*
|
|
66
|
-
* @
|
|
67
|
-
* Simple execution:
|
|
68
|
-
* ```typescript
|
|
69
|
-
* const request: WorkflowRunRequest = {
|
|
70
|
-
* inputs: {
|
|
71
|
-
* query: 'What is the weather?',
|
|
72
|
-
* location: 'New York'
|
|
73
|
-
* }
|
|
74
|
-
* };
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* With files:
|
|
79
|
-
* ```typescript
|
|
80
|
-
* const request: WorkflowRunRequest = {
|
|
81
|
-
* inputs: { action: 'analyze' },
|
|
82
|
-
* files: [{
|
|
83
|
-
* name: 'data.csv',
|
|
84
|
-
* type: 'text/csv',
|
|
85
|
-
* url: 'https://example.com/data.csv'
|
|
86
|
-
* }],
|
|
87
|
-
* user: 'user-123',
|
|
88
|
-
* trace_id: 'trace-abc-456'
|
|
89
|
-
* };
|
|
90
|
-
* ```
|
|
45
|
+
* @since 1.0.0
|
|
91
46
|
*/
|
|
92
47
|
export interface WorkflowRunRequest {
|
|
93
48
|
/** Input variables for the workflow */
|
|
@@ -112,22 +67,7 @@ export interface WorkflowRunRequest {
|
|
|
112
67
|
* Workflow execution response
|
|
113
68
|
*
|
|
114
69
|
* @template TOutput - The type of workflow outputs
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```typescript
|
|
118
|
-
* interface AnalysisOutput {
|
|
119
|
-
* summary: string;
|
|
120
|
-
* sentiment: 'positive' | 'negative' | 'neutral';
|
|
121
|
-
* keywords: string[];
|
|
122
|
-
* }
|
|
123
|
-
*
|
|
124
|
-
* const result = await client.workflow.run<AnalysisOutput>('text-analysis', {
|
|
125
|
-
* text: 'This is a great product!'
|
|
126
|
-
* });
|
|
127
|
-
*
|
|
128
|
-
* console.log(result.data.outputs.summary);
|
|
129
|
-
* console.log(result.data.outputs.sentiment); // 'positive'
|
|
130
|
-
* ```
|
|
70
|
+
*
|
|
131
71
|
*/
|
|
132
72
|
export interface WorkflowRunResponse<TOutput = Record<string, unknown>> {
|
|
133
73
|
/** Task ID */
|
|
@@ -136,7 +76,6 @@ export interface WorkflowRunResponse<TOutput = Record<string, unknown>> {
|
|
|
136
76
|
workflow_run_id: string;
|
|
137
77
|
/**
|
|
138
78
|
* Execution status
|
|
139
|
-
* @example 'succeeded', 'failed', 'running'
|
|
140
79
|
*/
|
|
141
80
|
status: string;
|
|
142
81
|
/** Workflow output data */
|
|
@@ -162,38 +101,7 @@ export interface WorkflowRunResponse<TOutput = Record<string, unknown>> {
|
|
|
162
101
|
*
|
|
163
102
|
* Provides methods for executing Dify-style workflows.
|
|
164
103
|
*
|
|
165
|
-
* @
|
|
166
|
-
* Complete workflow execution:
|
|
167
|
-
* ```typescript
|
|
168
|
-
* const client = createClient({ baseURL: 'https://api.amaster.ai' });
|
|
169
|
-
*
|
|
170
|
-
* // 1. Simple text processing workflow
|
|
171
|
-
* const result = await client.workflow.run('text-summarizer', {
|
|
172
|
-
* text: 'Long article content here...',
|
|
173
|
-
* max_words: 100
|
|
174
|
-
* });
|
|
175
|
-
*
|
|
176
|
-
* if (result.data) {
|
|
177
|
-
* console.log('Summary:', result.data.outputs.summary);
|
|
178
|
-
* console.log('Time taken:', result.data.elapsed_time, 'ms');
|
|
179
|
-
* console.log('Tokens used:', result.data.total_tokens);
|
|
180
|
-
* }
|
|
181
|
-
*
|
|
182
|
-
* // 2. Data analysis workflow with type safety
|
|
183
|
-
* interface AnalysisOutput {
|
|
184
|
-
* insights: string[];
|
|
185
|
-
* score: number;
|
|
186
|
-
* recommendations: string[];
|
|
187
|
-
* }
|
|
188
|
-
*
|
|
189
|
-
* const analysis = await client.workflow.run<AnalysisOutput>('data-analyzer', {
|
|
190
|
-
* dataset: 'sales-2024',
|
|
191
|
-
* metric: 'revenue'
|
|
192
|
-
* });
|
|
193
|
-
*
|
|
194
|
-
* console.log('Insights:', analysis.data.outputs.insights);
|
|
195
|
-
* console.log('Score:', analysis.data.outputs.score);
|
|
196
|
-
* ```
|
|
104
|
+
* @since 1.0.0
|
|
197
105
|
*/
|
|
198
106
|
export interface WorkflowClientAPI {
|
|
199
107
|
/**
|
|
@@ -208,81 +116,24 @@ export interface WorkflowClientAPI {
|
|
|
208
116
|
* @returns Workflow execution result
|
|
209
117
|
*
|
|
210
118
|
* @example
|
|
211
|
-
* Simple execution
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* language: 'en'
|
|
119
|
+
* // Simple execution
|
|
120
|
+
* const result = await client.workflow.run('data-processor', {
|
|
121
|
+
* source: 'users',
|
|
122
|
+
* limit: 100
|
|
216
123
|
* });
|
|
217
124
|
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* With full request configuration:
|
|
223
|
-
* ```typescript
|
|
224
|
-
* const result = await client.workflow.run('document-processor', {
|
|
225
|
-
* inputs: {
|
|
226
|
-
* action: 'extract',
|
|
227
|
-
* format: 'json'
|
|
228
|
-
* },
|
|
229
|
-
* files: [{
|
|
230
|
-
* name: 'invoice.pdf',
|
|
231
|
-
* url: 'https://example.com/invoice.pdf'
|
|
232
|
-
* }],
|
|
233
|
-
* user: 'user-123',
|
|
234
|
-
* trace_id: 'req-abc-456'
|
|
235
|
-
* });
|
|
236
|
-
* ```
|
|
237
|
-
*
|
|
238
|
-
* @example
|
|
239
|
-
* Type-safe outputs:
|
|
240
|
-
* ```typescript
|
|
241
|
-
* interface SentimentOutput {
|
|
242
|
-
* sentiment: 'positive' | 'negative' | 'neutral';
|
|
243
|
-
* confidence: number;
|
|
244
|
-
* keywords: string[];
|
|
245
|
-
* }
|
|
246
|
-
*
|
|
247
|
-
* const result = await client.workflow.run<SentimentOutput>('sentiment-analysis', {
|
|
248
|
-
* text: 'I love this product! It works great.'
|
|
249
|
-
* });
|
|
250
|
-
*
|
|
251
|
-
* if (result.data) {
|
|
252
|
-
* // TypeScript knows the structure of outputs
|
|
253
|
-
* console.log(result.data.outputs.sentiment); // Type: 'positive' | 'negative' | 'neutral'
|
|
254
|
-
* console.log(result.data.outputs.confidence); // Type: number
|
|
255
|
-
* console.log(result.data.outputs.keywords); // Type: string[]
|
|
125
|
+
* if (result.success) {
|
|
126
|
+
* console.log('Output:', result.data.outputs);
|
|
256
127
|
* }
|
|
257
|
-
* ```
|
|
258
128
|
*
|
|
259
129
|
* @example
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
* const result = await client.workflow.run('
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
* console.error('Workflow failed:', result.error.message);
|
|
266
|
-
* } else if (result.data.error) {
|
|
267
|
-
* console.error('Workflow error:', result.data.error);
|
|
268
|
-
* } else {
|
|
269
|
-
* console.log('Success:', result.data.outputs);
|
|
270
|
-
* }
|
|
271
|
-
* ```
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* Performance monitoring:
|
|
275
|
-
* ```typescript
|
|
276
|
-
* const startTime = Date.now();
|
|
277
|
-
* const result = await client.workflow.run('heavy-task', { data: largeDataset });
|
|
130
|
+
* // With type safety
|
|
131
|
+
* type Output = { processedCount: number; results: string[] };
|
|
132
|
+
* const result = await client.workflow.run<Output>('batch-processor', {
|
|
133
|
+
* batchSize: 50
|
|
134
|
+
* });
|
|
278
135
|
*
|
|
279
|
-
*
|
|
280
|
-
* console.log(`Network time: ${Date.now() - startTime}ms`);
|
|
281
|
-
* console.log(`Execution time: ${result.data.elapsed_time}ms`);
|
|
282
|
-
* console.log(`Steps: ${result.data.total_steps}`);
|
|
283
|
-
* console.log(`Tokens: ${result.data.total_tokens}`);
|
|
284
|
-
* }
|
|
285
|
-
* ```
|
|
136
|
+
* @since 1.0.0
|
|
286
137
|
*/
|
|
287
138
|
run<TOutput = Record<string, unknown>>(
|
|
288
139
|
workflowName: string,
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================================
|
|
3
|
-
* Permission Checking - Type Definitions & Helpers
|
|
4
|
-
* ============================================================================
|
|
5
|
-
*
|
|
6
|
-
* Permission and role checking utilities:
|
|
7
|
-
* - Type-safe permission checking
|
|
8
|
-
* - Role validation
|
|
9
|
-
* - Permission helpers
|
|
10
|
-
*
|
|
11
|
-
* @module auth/permissions
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import type { User } from './user';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Permission check result
|
|
18
|
-
*/
|
|
19
|
-
export interface PermissionCheckResult {
|
|
20
|
-
/** Whether the permission check passed */
|
|
21
|
-
granted: boolean;
|
|
22
|
-
|
|
23
|
-
/** Optional reason if denied */
|
|
24
|
-
reason?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Permission checking helpers
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* Check single permission:
|
|
32
|
-
* ```typescript
|
|
33
|
-
* import { hasPermission } from '@amaster.ai/client/auth/permissions';
|
|
34
|
-
*
|
|
35
|
-
* const user = await client.auth.getMe().then(r => r.data);
|
|
36
|
-
*
|
|
37
|
-
* if (hasPermission(user, 'user:delete')) {
|
|
38
|
-
* showDeleteButton();
|
|
39
|
-
* }
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* Check role:
|
|
44
|
-
* ```typescript
|
|
45
|
-
* import { hasRole } from '@amaster.ai/client/auth/permissions';
|
|
46
|
-
*
|
|
47
|
-
* if (hasRole(user, 'admin')) {
|
|
48
|
-
* showAdminPanel();
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* Check any of multiple permissions:
|
|
54
|
-
* ```typescript
|
|
55
|
-
* import { hasAnyPermission } from '@amaster.ai/client/auth/permissions';
|
|
56
|
-
*
|
|
57
|
-
* if (hasAnyPermission(user, ['user:read', 'user:write', 'user:delete'])) {
|
|
58
|
-
* showUserManagement();
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export namespace PermissionHelpers {
|
|
63
|
-
/**
|
|
64
|
-
* Check if user has a specific permission
|
|
65
|
-
*
|
|
66
|
-
* @param user - User object with permissions
|
|
67
|
-
* @param permission - Permission to check (format: "resource:action")
|
|
68
|
-
* @returns True if user has the permission
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const canDelete = hasPermission(user, 'user:delete');
|
|
73
|
-
* const canRead = hasPermission(user, 'order:read');
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export function hasPermission(user: User | null | undefined, permission: string): boolean;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Check if user has a specific role
|
|
80
|
-
*
|
|
81
|
-
* @param user - User object with roles
|
|
82
|
-
* @param role - Role code to check
|
|
83
|
-
* @returns True if user has the role
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```typescript
|
|
87
|
-
* const isAdmin = hasRole(user, 'admin');
|
|
88
|
-
* const isManager = hasRole(user, 'manager');
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export function hasRole(user: User | null | undefined, role: string): boolean;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Check if user has ANY of the specified permissions
|
|
95
|
-
*
|
|
96
|
-
* @param user - User object with permissions
|
|
97
|
-
* @param permissions - Array of permissions to check
|
|
98
|
-
* @returns True if user has at least one permission
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* // User can access if they have ANY of these permissions
|
|
103
|
-
* const canAccessUsers = hasAnyPermission(user, [
|
|
104
|
-
* 'user:read',
|
|
105
|
-
* 'user:write',
|
|
106
|
-
* 'user:delete'
|
|
107
|
-
* ]);
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export function hasAnyPermission(user: User | null | undefined, permissions: string[]): boolean;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Check if user has ALL of the specified permissions
|
|
114
|
-
*
|
|
115
|
-
* @param user - User object with permissions
|
|
116
|
-
* @param permissions - Array of permissions to check
|
|
117
|
-
* @returns True if user has all permissions
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* // User needs ALL of these permissions
|
|
122
|
-
* const canManageUsers = hasAllPermissions(user, [
|
|
123
|
-
* 'user:read',
|
|
124
|
-
* 'user:write',
|
|
125
|
-
* 'user:delete'
|
|
126
|
-
* ]);
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
export function hasAllPermissions(user: User | null | undefined, permissions: string[]): boolean;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Check if user has ANY of the specified roles
|
|
133
|
-
*
|
|
134
|
-
* @param user - User object with roles
|
|
135
|
-
* @param roles - Array of role codes to check
|
|
136
|
-
* @returns True if user has at least one role
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const isStaff = hasAnyRole(user, ['admin', 'moderator', 'support']);
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
export function hasAnyRole(user: User | null | undefined, roles: string[]): boolean;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Check if user has ALL of the specified roles
|
|
147
|
-
*
|
|
148
|
-
* @param user - User object with roles
|
|
149
|
-
* @param roles - Array of role codes to check
|
|
150
|
-
* @returns True if user has all roles
|
|
151
|
-
*
|
|
152
|
-
* @example
|
|
153
|
-
* ```typescript
|
|
154
|
-
* const isSuperAdmin = hasAllRoles(user, ['admin', 'superuser']);
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
export function hasAllRoles(user: User | null | undefined, roles: string[]): boolean;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Re-export helpers as individual functions for convenience
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* import { hasPermission, hasRole } from '@amaster.ai/client/auth/permissions';
|
|
166
|
-
*
|
|
167
|
-
* const canDelete = hasPermission(user, 'user:delete');
|
|
168
|
-
* const isAdmin = hasRole(user, 'admin');
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Check if user has a specific permission
|
|
174
|
-
*
|
|
175
|
-
* @param user - User object with permissions
|
|
176
|
-
* @param permission - Permission to check (format: "resource:action")
|
|
177
|
-
* @returns True if user has the permission
|
|
178
|
-
*
|
|
179
|
-
* @example
|
|
180
|
-
* ```typescript
|
|
181
|
-
* const canDelete = hasPermission(user, 'user:delete');
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
export declare function hasPermission(user: User | null | undefined, permission: string): boolean;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Check if user has a specific role
|
|
188
|
-
*
|
|
189
|
-
* @param user - User object with roles
|
|
190
|
-
* @param role - Role code to check
|
|
191
|
-
* @returns True if user has the role
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```typescript
|
|
195
|
-
* const isAdmin = hasRole(user, 'admin');
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
export declare function hasRole(user: User | null | undefined, role: string): boolean;
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Check if user has ANY of the specified permissions
|
|
202
|
-
*
|
|
203
|
-
* @param user - User object with permissions
|
|
204
|
-
* @param permissions - Array of permissions to check
|
|
205
|
-
* @returns True if user has at least one permission
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* ```typescript
|
|
209
|
-
* const canAccessUsers = hasAnyPermission(user, ['user:read', 'user:write']);
|
|
210
|
-
* ```
|
|
211
|
-
*/
|
|
212
|
-
export declare function hasAnyPermission(user: User | null | undefined, permissions: string[]): boolean;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Check if user has ALL of the specified permissions
|
|
216
|
-
*
|
|
217
|
-
* @param user - User object with permissions
|
|
218
|
-
* @param permissions - Array of permissions to check
|
|
219
|
-
* @returns True if user has all permissions
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```typescript
|
|
223
|
-
* const canManageUsers = hasAllPermissions(user, ['user:read', 'user:write', 'user:delete']);
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
export declare function hasAllPermissions(user: User | null | undefined, permissions: string[]): boolean;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Check if user has ANY of the specified roles
|
|
230
|
-
*
|
|
231
|
-
* @param user - User object with roles
|
|
232
|
-
* @param roles - Array of role codes to check
|
|
233
|
-
* @returns True if user has at least one role
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* ```typescript
|
|
237
|
-
* const isStaff = hasAnyRole(user, ['admin', 'moderator']);
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
export declare function hasAnyRole(user: User | null | undefined, roles: string[]): boolean;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Check if user has ALL of the specified roles
|
|
244
|
-
*
|
|
245
|
-
* @param user - User object with roles
|
|
246
|
-
* @param roles - Array of role codes to check
|
|
247
|
-
* @returns True if user has all roles
|
|
248
|
-
*
|
|
249
|
-
* @example
|
|
250
|
-
* ```typescript
|
|
251
|
-
* const isSuperAdmin = hasAllRoles(user, ['admin', 'superuser']);
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
export declare function hasAllRoles(user: User | null | undefined, roles: string[]): boolean;
|