@amaster.ai/client 1.1.0-beta.16 → 1.1.0-beta.18
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 +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +15 -11
- package/types/s3.d.ts +127 -0
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var asrClient = require('@amaster.ai/asr-client');
|
|
|
8
8
|
var copilotClient = require('@amaster.ai/copilot-client');
|
|
9
9
|
var functionClient = require('@amaster.ai/function-client');
|
|
10
10
|
var ttsClient = require('@amaster.ai/tts-client');
|
|
11
|
+
var s3Client = require('@amaster.ai/s3-client');
|
|
11
12
|
var httpClient = require('@amaster.ai/http-client');
|
|
12
13
|
|
|
13
14
|
// src/client.ts
|
|
@@ -49,6 +50,7 @@ function createClient(options) {
|
|
|
49
50
|
const workflow = workflowClient.createWorkflowClient(authenticatedHttpClient);
|
|
50
51
|
const functionClient$1 = functionClient.createFunctionClient(authenticatedHttpClient);
|
|
51
52
|
const copilot = copilotClient.createCopilotA2UIClient(authenticatedHttpClient);
|
|
53
|
+
const s3 = s3Client.createS3Client(authenticatedHttpClient);
|
|
52
54
|
const asr = asrClient.createASRClient({});
|
|
53
55
|
const tts = ttsClient.createTTSClient({});
|
|
54
56
|
const client = {
|
|
@@ -60,6 +62,7 @@ function createClient(options) {
|
|
|
60
62
|
copilot,
|
|
61
63
|
function: functionClient$1,
|
|
62
64
|
tts,
|
|
65
|
+
s3,
|
|
63
66
|
// Expose token management methods from auth client
|
|
64
67
|
isAuthenticated: () => auth.isAuthenticated(),
|
|
65
68
|
getAccessToken: () => auth.getAccessToken(),
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotA2UIClient","createASRClient","createTTSClient"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":["createHttpClient","createAuthClient","createEntityClient","createBpmClient","createWorkflowClient","functionClient","createFunctionClient","createCopilotA2UIClient","createS3Client","createASRClient","createTTSClient"],"mappings":";;;;;;;;;;;;;;AA+FO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,GAAU,EAAC,EAAG,cAAA,EAAgB,gBAAe,GAAI,OAAA;AAGlE,EAAA,MAAM,iBAAiBA,2BAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,OAAmBC,2BAAA,CAAiB;AAAA,IACxC,OAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,gCAAgC,MAAkB;AACtD,IAAA,OAAO;AAAA,MACL,MAAM,QAAW,MAAA,EAAiD;AAEhE,QAAA,MAAM,KAAA,GAAQ,KAAK,cAAA,EAAe;AAGlC,QAAA,MAAM,WAAA,GAAc,QAAQ,EAAE,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA,KAAO,EAAC;AACpE,QAAA,MAAM,YAAA,GAA8B;AAAA,UAClC,GAAG,MAAA;AAAA,UACH,OAAA,EAAS;AAAA,YACP,GAAG,MAAA,CAAO,OAAA;AAAA,YACV,GAAG;AAAA;AACL,SACF;AAGA,QAAA,MAAM,MAAA,GAAS,MAAM,cAAA,CAAe,OAAA,CAAW,YAAY,CAAA;AAG3D,QAAA,IAAI,MAAA,CAAO,MAAA,KAAW,GAAA,IAAO,cAAA,EAAgB;AAC3C,UAAA,cAAA,EAAe;AAAA,QACjB;AAEA,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF,CAAA;AAGA,EAAA,MAAM,0BAA0B,6BAAA,EAA8B;AAG9D,EAAA,MAAM,MAAA,GAAuBC,gCAAmB,uBAAuB,CAAA;AACvE,EAAA,MAAM,GAAA,GAAiBC,0BAAgB,uBAAuB,CAAA;AAC9D,EAAA,MAAM,QAAA,GAA2BC,oCAAqB,uBAAuB,CAAA;AAC7E,EAAA,MAAMC,gBAAA,GAAiCC,oCAAqB,uBAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAA6BC,sCAAwB,uBAAuB,CAAA;AAClF,EAAA,MAAM,EAAA,GAAeC,wBAAe,uBAAuB,CAAA;AAI3D,EAAA,MAAM,GAAA,GAAiBC,yBAAA,CAAgB,EAAE,CAAA;AACzC,EAAA,MAAM,GAAA,GAAiBC,yBAAA,CAAgB,EAAE,CAAA;AAGzC,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAUL,gBAAA;AAAA,IACV,GAAA;AAAA,IACA,EAAA;AAAA;AAAA,IAGA,eAAA,EAAiB,MAAM,IAAA,CAAK,eAAA,EAAgB;AAAA,IAC5C,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,cAAA,EAAgB,CAAC,KAAA,KAAkB,IAAA,CAAK,eAAe,KAAK,CAAA;AAAA,IAC5D,SAAA,EAAW,MAAM,IAAA,CAAK,SAAA;AAAU,GAClC;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * ============================================================================\n * @amaster.ai/client - Unified Amaster Client\n * ============================================================================\n * \n * Supabase-inspired unified API client for the Amaster platform\n * \n * Features:\n * - Single client instance for all services (auth, entity, bpm, workflow)\n * - Automatic token management and refresh\n * - Auto-attach authentication to all requests\n * - Centralized error handling\n * \n * @example\n * ```typescript\n * // With explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Auto-detect baseURL from env (Taro/Mini-program)\n * const client = createClient({\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Login\n * await client.auth.login({ email, password });\n * \n * // All subsequent requests automatically include auth token\n * await client.entity.list('default', 'users');\n * await client.bpm.startProcess({ processKey: 'approval' });\n * ```\n */\n\nimport { createAuthClient, type AuthClient } from \"@amaster.ai/auth-client\";\nimport { createEntityClient, type EntityClient } from \"@amaster.ai/entity-client\";\nimport { createBpmClient, type BpmClient } from \"@amaster.ai/bpm-client\";\nimport { createWorkflowClient, type WorkflowClient } from \"@amaster.ai/workflow-client\";\nimport { createASRClient, type ASRClient } from \"@amaster.ai/asr-client\";\nimport { createCopilotA2UIClient, type CopilotA2UIClient } from \"@amaster.ai/copilot-client\";\nimport { createFunctionClient, type FunctionClient } from \"@amaster.ai/function-client\";\nimport { createTTSClient, type TTSClient } from \"@amaster.ai/tts-client\";\nimport { createS3Client, type S3Client } from \"@amaster.ai/s3-client\";\nimport { createHttpClient, type HttpClient, type RequestConfig, type ClientResult } from \"@amaster.ai/http-client\";\nimport type { AmasterClient, AmasterClientOptions } from \"./types\";\n\n/**\n * Create a unified Amaster client instance\n * \n * This function creates a single client that provides access to all Amaster services:\n * - Authentication (login, register, logout)\n * - Entity CRUD operations\n * - BPM (Business Process Management)\n * - Workflow execution\n * \n * All sub-clients automatically share the same HTTP client and authentication state,\n * ensuring that tokens are consistently attached to all requests.\n * \n * @param options - Client configuration options\n * @returns A unified Amaster client instance\n * \n * @example\n * ```typescript\n * // Basic usage with explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\n * \n * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)\n * const client = createClient({});\n * \n * // With authentication callbacks\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => {\n * // Redirect to login or show auth modal\n * window.location.href = '/login';\n * },\n * onTokenExpired: () => {\n * console.log('Token expired, refreshing...');\n * }\n * });\n * \n * // Login\n * await client.auth.login({\n * email: 'user@example.com',\n * password: 'password123'\n * });\n * \n * // Now all requests automatically include the auth token\n * const users = await client.entity.list('default', 'users');\n * const tasks = await client.bpm.getMyTasks();\n * ```\n */\nexport function createClient(options: AmasterClientOptions): AmasterClient {\n const { baseURL, headers = {}, onUnauthorized, onTokenExpired } = options;\n\n // Create the base HTTP client\n const baseHttpClient = createHttpClient({\n baseURL,\n headers,\n });\n\n // Create the auth client first (it manages its own HTTP client internally)\n const auth: AuthClient = createAuthClient({\n baseURL,\n headers,\n onTokenExpired,\n onUnauthorized,\n });\n\n // Create a wrapper HTTP client that automatically adds the auth token\n const createAuthenticatedHttpClient = (): HttpClient => {\n return {\n async request<T>(config: RequestConfig): Promise<ClientResult<T>> {\n // Get the current token from auth client\n const token = auth.getAccessToken();\n \n // Merge Authorization header with existing headers\n const authHeaders = token ? { Authorization: `Bearer ${token}` } : {};\n const mergedConfig: RequestConfig = {\n ...config,\n headers: {\n ...config.headers,\n ...authHeaders,\n },\n };\n\n // Make the request with the updated config\n const result = await baseHttpClient.request<T>(mergedConfig);\n\n // Handle 401 errors\n if (result.status === 401 && onUnauthorized) {\n onUnauthorized();\n }\n\n return result;\n },\n };\n };\n\n // Create the authenticated HTTP client\n const authenticatedHttpClient = createAuthenticatedHttpClient();\n\n // Create other clients using the authenticated HTTP client\n const entity: EntityClient = createEntityClient(authenticatedHttpClient);\n const bpm: BpmClient = createBpmClient(authenticatedHttpClient);\n const workflow: WorkflowClient = createWorkflowClient(authenticatedHttpClient);\n const functionClient: FunctionClient = createFunctionClient(authenticatedHttpClient);\n const copilot: CopilotA2UIClient = createCopilotA2UIClient(authenticatedHttpClient);\n const s3: S3Client = createS3Client(authenticatedHttpClient);\n\n // ASR and TTS clients use WebSocket, create with default config\n // Users can reconfigure by accessing client.asr / client.tts directly\n const asr: ASRClient = createASRClient({});\n const tts: TTSClient = createTTSClient({});\n\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\n asr,\n copilot,\n function: functionClient,\n tts,\n s3,\n\n // Expose token management methods from auth client\n isAuthenticated: () => auth.isAuthenticated(),\n getAccessToken: () => auth.getAccessToken(),\n setAccessToken: (token: string) => auth.setAccessToken(token),\n clearAuth: () => auth.clearAuth(),\n };\n\n return client;\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,8 @@ import { FunctionClient } from '@amaster.ai/function-client';
|
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClient } from '@amaster.ai/tts-client';
|
|
16
16
|
export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
|
|
17
|
+
import { S3Client } from '@amaster.ai/s3-client';
|
|
18
|
+
export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
|
|
17
19
|
export { ClientError, ClientResult } from '@amaster.ai/http-client';
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -193,6 +195,19 @@ interface AmasterClient {
|
|
|
193
195
|
* ```
|
|
194
196
|
*/
|
|
195
197
|
tts: TTSClient;
|
|
198
|
+
/**
|
|
199
|
+
* S3 Storage module
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Upload file
|
|
204
|
+
* await client.s3.upload(file);
|
|
205
|
+
*
|
|
206
|
+
* // Download file
|
|
207
|
+
* await client.s3.download('path/to/file');
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
s3: S3Client;
|
|
196
211
|
/**
|
|
197
212
|
* Check if the user is currently authenticated
|
|
198
213
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ import { FunctionClient } from '@amaster.ai/function-client';
|
|
|
14
14
|
export { FunctionClient } from '@amaster.ai/function-client';
|
|
15
15
|
import { TTSClient } from '@amaster.ai/tts-client';
|
|
16
16
|
export { TTSClient, TTSClientConfig } from '@amaster.ai/tts-client';
|
|
17
|
+
import { S3Client } from '@amaster.ai/s3-client';
|
|
18
|
+
export { S3Client, S3Metadata, UploadRes } from '@amaster.ai/s3-client';
|
|
17
19
|
export { ClientError, ClientResult } from '@amaster.ai/http-client';
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -193,6 +195,19 @@ interface AmasterClient {
|
|
|
193
195
|
* ```
|
|
194
196
|
*/
|
|
195
197
|
tts: TTSClient;
|
|
198
|
+
/**
|
|
199
|
+
* S3 Storage module
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* // Upload file
|
|
204
|
+
* await client.s3.upload(file);
|
|
205
|
+
*
|
|
206
|
+
* // Download file
|
|
207
|
+
* await client.s3.download('path/to/file');
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
s3: S3Client;
|
|
196
211
|
/**
|
|
197
212
|
* Check if the user is currently authenticated
|
|
198
213
|
*/
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createASRClient } from '@amaster.ai/asr-client';
|
|
|
6
6
|
import { createCopilotA2UIClient } from '@amaster.ai/copilot-client';
|
|
7
7
|
import { createFunctionClient } from '@amaster.ai/function-client';
|
|
8
8
|
import { createTTSClient } from '@amaster.ai/tts-client';
|
|
9
|
+
import { createS3Client } from '@amaster.ai/s3-client';
|
|
9
10
|
import { createHttpClient } from '@amaster.ai/http-client';
|
|
10
11
|
|
|
11
12
|
// src/client.ts
|
|
@@ -47,6 +48,7 @@ function createClient(options) {
|
|
|
47
48
|
const workflow = createWorkflowClient(authenticatedHttpClient);
|
|
48
49
|
const functionClient = createFunctionClient(authenticatedHttpClient);
|
|
49
50
|
const copilot = createCopilotA2UIClient(authenticatedHttpClient);
|
|
51
|
+
const s3 = createS3Client(authenticatedHttpClient);
|
|
50
52
|
const asr = createASRClient({});
|
|
51
53
|
const tts = createTTSClient({});
|
|
52
54
|
const client = {
|
|
@@ -58,6 +60,7 @@ function createClient(options) {
|
|
|
58
60
|
copilot,
|
|
59
61
|
function: functionClient,
|
|
60
62
|
tts,
|
|
63
|
+
s3,
|
|
61
64
|
// Expose token management methods from auth client
|
|
62
65
|
isAuthenticated: () => auth.isAuthenticated(),
|
|
63
66
|
getAccessToken: () => auth.getAccessToken(),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;AA+FO,SAAS,aAAa,OAAA,EAA8C;AACzE,EAAA,MAAM,EAAE,OAAA,EAAS,OAAA,GAAU,EAAC,EAAG,cAAA,EAAgB,gBAAe,GAAI,OAAA;AAGlE,EAAA,MAAM,iBAAiB,gBAAA,CAAiB;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,OAAmB,gBAAA,CAAiB;AAAA,IACxC,OAAA;AAAA,IACA,OAAA;AAAA,IACA,cAAA;AAAA,IACA;AAAA,GACD,CAAA;AAGD,EAAA,MAAM,gCAAgC,MAAkB;AACtD,IAAA,OAAO;AAAA,MACL,MAAM,QAAW,MAAA,EAAiD;AAEhE,QAAA,MAAM,KAAA,GAAQ,KAAK,cAAA,EAAe;AAGlC,QAAA,MAAM,WAAA,GAAc,QAAQ,EAAE,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA,KAAO,EAAC;AACpE,QAAA,MAAM,YAAA,GAA8B;AAAA,UAClC,GAAG,MAAA;AAAA,UACH,OAAA,EAAS;AAAA,YACP,GAAG,MAAA,CAAO,OAAA;AAAA,YACV,GAAG;AAAA;AACL,SACF;AAGA,QAAA,MAAM,MAAA,GAAS,MAAM,cAAA,CAAe,OAAA,CAAW,YAAY,CAAA;AAG3D,QAAA,IAAI,MAAA,CAAO,MAAA,KAAW,GAAA,IAAO,cAAA,EAAgB;AAC3C,UAAA,cAAA,EAAe;AAAA,QACjB;AAEA,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,KACF;AAAA,EACF,CAAA;AAGA,EAAA,MAAM,0BAA0B,6BAAA,EAA8B;AAG9D,EAAA,MAAM,MAAA,GAAuB,mBAAmB,uBAAuB,CAAA;AACvE,EAAA,MAAM,GAAA,GAAiB,gBAAgB,uBAAuB,CAAA;AAC9D,EAAA,MAAM,QAAA,GAA2B,qBAAqB,uBAAuB,CAAA;AAC7E,EAAA,MAAM,cAAA,GAAiC,qBAAqB,uBAAuB,CAAA;AACnF,EAAA,MAAM,OAAA,GAA6B,wBAAwB,uBAAuB,CAAA;AAClF,EAAA,MAAM,EAAA,GAAe,eAAe,uBAAuB,CAAA;AAI3D,EAAA,MAAM,GAAA,GAAiB,eAAA,CAAgB,EAAE,CAAA;AACzC,EAAA,MAAM,GAAA,GAAiB,eAAA,CAAgB,EAAE,CAAA;AAGzC,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;AAAA,IACA,GAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,cAAA;AAAA,IACV,GAAA;AAAA,IACA,EAAA;AAAA;AAAA,IAGA,eAAA,EAAiB,MAAM,IAAA,CAAK,eAAA,EAAgB;AAAA,IAC5C,cAAA,EAAgB,MAAM,IAAA,CAAK,cAAA,EAAe;AAAA,IAC1C,cAAA,EAAgB,CAAC,KAAA,KAAkB,IAAA,CAAK,eAAe,KAAK,CAAA;AAAA,IAC5D,SAAA,EAAW,MAAM,IAAA,CAAK,SAAA;AAAU,GAClC;AAEA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["/**\n * ============================================================================\n * @amaster.ai/client - Unified Amaster Client\n * ============================================================================\n * \n * Supabase-inspired unified API client for the Amaster platform\n * \n * Features:\n * - Single client instance for all services (auth, entity, bpm, workflow)\n * - Automatic token management and refresh\n * - Auto-attach authentication to all requests\n * - Centralized error handling\n * \n * @example\n * ```typescript\n * // With explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Auto-detect baseURL from env (Taro/Mini-program)\n * const client = createClient({\n * onUnauthorized: () => window.location.href = '/login'\n * });\n * \n * // Login\n * await client.auth.login({ email, password });\n * \n * // All subsequent requests automatically include auth token\n * await client.entity.list('default', 'users');\n * await client.bpm.startProcess({ processKey: 'approval' });\n * ```\n */\n\nimport { createAuthClient, type AuthClient } from \"@amaster.ai/auth-client\";\nimport { createEntityClient, type EntityClient } from \"@amaster.ai/entity-client\";\nimport { createBpmClient, type BpmClient } from \"@amaster.ai/bpm-client\";\nimport { createWorkflowClient, type WorkflowClient } from \"@amaster.ai/workflow-client\";\nimport { createASRClient, type ASRClient } from \"@amaster.ai/asr-client\";\nimport { createCopilotA2UIClient, type CopilotA2UIClient } from \"@amaster.ai/copilot-client\";\nimport { createFunctionClient, type FunctionClient } from \"@amaster.ai/function-client\";\nimport { createTTSClient, type TTSClient } from \"@amaster.ai/tts-client\";\nimport { createS3Client, type S3Client } from \"@amaster.ai/s3-client\";\nimport { createHttpClient, type HttpClient, type RequestConfig, type ClientResult } from \"@amaster.ai/http-client\";\nimport type { AmasterClient, AmasterClientOptions } from \"./types\";\n\n/**\n * Create a unified Amaster client instance\n * \n * This function creates a single client that provides access to all Amaster services:\n * - Authentication (login, register, logout)\n * - Entity CRUD operations\n * - BPM (Business Process Management)\n * - Workflow execution\n * \n * All sub-clients automatically share the same HTTP client and authentication state,\n * ensuring that tokens are consistently attached to all requests.\n * \n * @param options - Client configuration options\n * @returns A unified Amaster client instance\n * \n * @example\n * ```typescript\n * // Basic usage with explicit baseURL\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\n * \n * // Auto-detect baseURL (for Taro/Mini-program or dev proxy)\n * const client = createClient({});\n * \n * // With authentication callbacks\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\n * onUnauthorized: () => {\n * // Redirect to login or show auth modal\n * window.location.href = '/login';\n * },\n * onTokenExpired: () => {\n * console.log('Token expired, refreshing...');\n * }\n * });\n * \n * // Login\n * await client.auth.login({\n * email: 'user@example.com',\n * password: 'password123'\n * });\n * \n * // Now all requests automatically include the auth token\n * const users = await client.entity.list('default', 'users');\n * const tasks = await client.bpm.getMyTasks();\n * ```\n */\nexport function createClient(options: AmasterClientOptions): AmasterClient {\n const { baseURL, headers = {}, onUnauthorized, onTokenExpired } = options;\n\n // Create the base HTTP client\n const baseHttpClient = createHttpClient({\n baseURL,\n headers,\n });\n\n // Create the auth client first (it manages its own HTTP client internally)\n const auth: AuthClient = createAuthClient({\n baseURL,\n headers,\n onTokenExpired,\n onUnauthorized,\n });\n\n // Create a wrapper HTTP client that automatically adds the auth token\n const createAuthenticatedHttpClient = (): HttpClient => {\n return {\n async request<T>(config: RequestConfig): Promise<ClientResult<T>> {\n // Get the current token from auth client\n const token = auth.getAccessToken();\n \n // Merge Authorization header with existing headers\n const authHeaders = token ? { Authorization: `Bearer ${token}` } : {};\n const mergedConfig: RequestConfig = {\n ...config,\n headers: {\n ...config.headers,\n ...authHeaders,\n },\n };\n\n // Make the request with the updated config\n const result = await baseHttpClient.request<T>(mergedConfig);\n\n // Handle 401 errors\n if (result.status === 401 && onUnauthorized) {\n onUnauthorized();\n }\n\n return result;\n },\n };\n };\n\n // Create the authenticated HTTP client\n const authenticatedHttpClient = createAuthenticatedHttpClient();\n\n // Create other clients using the authenticated HTTP client\n const entity: EntityClient = createEntityClient(authenticatedHttpClient);\n const bpm: BpmClient = createBpmClient(authenticatedHttpClient);\n const workflow: WorkflowClient = createWorkflowClient(authenticatedHttpClient);\n const functionClient: FunctionClient = createFunctionClient(authenticatedHttpClient);\n const copilot: CopilotA2UIClient = createCopilotA2UIClient(authenticatedHttpClient);\n const s3: S3Client = createS3Client(authenticatedHttpClient);\n\n // ASR and TTS clients use WebSocket, create with default config\n // Users can reconfigure by accessing client.asr / client.tts directly\n const asr: ASRClient = createASRClient({});\n const tts: TTSClient = createTTSClient({});\n\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\n asr,\n copilot,\n function: functionClient,\n tts,\n s3,\n\n // Expose token management methods from auth client\n isAuthenticated: () => auth.isAuthenticated(),\n getAccessToken: () => auth.getAccessToken(),\n setAccessToken: (token: string) => auth.setAccessToken(token),\n clearAuth: () => auth.clearAuth(),\n };\n\n return client;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amaster.ai/client",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.18",
|
|
4
4
|
"description": "Unified API client for Amaster platform - All services in one package",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -38,6 +38,9 @@
|
|
|
38
38
|
"tts": [
|
|
39
39
|
"./types/tts.d.ts"
|
|
40
40
|
],
|
|
41
|
+
"s3": [
|
|
42
|
+
"./types/s3.d.ts"
|
|
43
|
+
],
|
|
41
44
|
"common": [
|
|
42
45
|
"./types/common.d.ts"
|
|
43
46
|
]
|
|
@@ -69,16 +72,17 @@
|
|
|
69
72
|
"registry": "https://registry.npmjs.org/"
|
|
70
73
|
},
|
|
71
74
|
"dependencies": {
|
|
72
|
-
"@amaster.ai/asr-client": "1.1.0-beta.
|
|
73
|
-
"@amaster.ai/asr-http-client": "1.1.0-beta.
|
|
74
|
-
"@amaster.ai/auth-client": "1.1.0-beta.
|
|
75
|
-
"@amaster.ai/bpm-client": "1.1.0-beta.
|
|
76
|
-
"@amaster.ai/copilot-client": "1.1.0-beta.
|
|
77
|
-
"@amaster.ai/entity-client": "1.1.0-beta.
|
|
78
|
-
"@amaster.ai/function-client": "1.1.0-beta.
|
|
79
|
-
"@amaster.ai/http-client": "1.1.0-beta.
|
|
80
|
-
"@amaster.ai/
|
|
81
|
-
"@amaster.ai/workflow-client": "1.1.0-beta.
|
|
75
|
+
"@amaster.ai/asr-client": "1.1.0-beta.18",
|
|
76
|
+
"@amaster.ai/asr-http-client": "1.1.0-beta.18",
|
|
77
|
+
"@amaster.ai/auth-client": "1.1.0-beta.18",
|
|
78
|
+
"@amaster.ai/bpm-client": "1.1.0-beta.18",
|
|
79
|
+
"@amaster.ai/copilot-client": "1.1.0-beta.18",
|
|
80
|
+
"@amaster.ai/entity-client": "1.1.0-beta.18",
|
|
81
|
+
"@amaster.ai/function-client": "1.1.0-beta.18",
|
|
82
|
+
"@amaster.ai/http-client": "1.1.0-beta.18",
|
|
83
|
+
"@amaster.ai/s3-client": "1.1.0-beta.18",
|
|
84
|
+
"@amaster.ai/workflow-client": "1.1.0-beta.18",
|
|
85
|
+
"@amaster.ai/tts-client": "1.1.0-beta.18"
|
|
82
86
|
},
|
|
83
87
|
"peerDependencies": {
|
|
84
88
|
"axios": "^1.11.0"
|
package/types/s3.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ============================================================================
|
|
3
|
+
* S3 Storage Module - Type Definitions
|
|
4
|
+
* ============================================================================
|
|
5
|
+
*
|
|
6
|
+
* This module provides operations for interacting with S3-compatible object storage.
|
|
7
|
+
*
|
|
8
|
+
* ## Key Features
|
|
9
|
+
* - File upload (multipart/form-data)
|
|
10
|
+
* - File download
|
|
11
|
+
* - Metadata retrieval
|
|
12
|
+
*
|
|
13
|
+
* @module s3
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { ClientResult } from './common';
|
|
17
|
+
|
|
18
|
+
// ==================== Response Types ====================
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Upload response data
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* {
|
|
26
|
+
* key: "uploads/2024/image.png",
|
|
27
|
+
* url: "https://cdn.example.com/uploads/2024/image.png"
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export interface UploadRes {
|
|
32
|
+
/** File key in storage */
|
|
33
|
+
key: string;
|
|
34
|
+
/** Full access URL */
|
|
35
|
+
url: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* File metadata
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* {
|
|
44
|
+
* contentType: "image/png",
|
|
45
|
+
* contentLength: 1024,
|
|
46
|
+
* lastModified: "2024-01-01T12:00:00Z"
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export interface S3Metadata {
|
|
51
|
+
contentType?: string;
|
|
52
|
+
contentLength?: number;
|
|
53
|
+
lastModified?: string;
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ==================== S3 Client API ====================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* S3 Storage Client API
|
|
61
|
+
*
|
|
62
|
+
* Provides methods for uploading, downloading, and managing files in object storage.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const client = createClient();
|
|
67
|
+
*
|
|
68
|
+
* // 1. Upload file
|
|
69
|
+
* const uploadRes = await client.s3.upload(file);
|
|
70
|
+
* console.log(uploadRes.data.url);
|
|
71
|
+
*
|
|
72
|
+
* // 2. Get metadata
|
|
73
|
+
* const meta = await client.s3.getMetadata(uploadRes.data.key);
|
|
74
|
+
*
|
|
75
|
+
* // 3. Download file
|
|
76
|
+
* const blob = await client.s3.download(uploadRes.data.key);
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export interface S3Client {
|
|
80
|
+
/**
|
|
81
|
+
* Download a file
|
|
82
|
+
*
|
|
83
|
+
* @param filename - The name/key of the file to download
|
|
84
|
+
* @returns Blob data of the file
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const result = await client.s3.download('uploads/image.png');
|
|
89
|
+
* if (result.data) {
|
|
90
|
+
* const url = URL.createObjectURL(result.data);
|
|
91
|
+
* window.open(url);
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
download(filename: string): Promise<ClientResult<Blob>>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get metadata for a file
|
|
99
|
+
*
|
|
100
|
+
* @param key - The key of the file
|
|
101
|
+
* @returns File metadata
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const result = await client.s3.getMetadata('uploads/image.png');
|
|
106
|
+
* console.log('Size:', result.data.contentLength);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
getMetadata(key: string): Promise<ClientResult<S3Metadata>>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Upload a file
|
|
113
|
+
*
|
|
114
|
+
* @param file - The file to upload (File or Blob)
|
|
115
|
+
* @returns Upload result containing key and URL
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const file = event.target.files[0];
|
|
120
|
+
* const result = await client.s3.upload(file);
|
|
121
|
+
* if (result.data) {
|
|
122
|
+
* console.log('Uploaded to:', result.data.url);
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
upload(file: File | Blob): Promise<ClientResult<UploadRes>>;
|
|
127
|
+
}
|