@amaster.ai/client 1.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,222 @@
1
+ import { AuthClient } from '@amaster.ai/auth-client';
2
+ export { LoginParams, LoginResponse, OAuthProvider, Permission, RegisterParams, Role, Session, User } from '@amaster.ai/auth-client';
3
+ import { EntityClient } from '@amaster.ai/entity-client';
4
+ export { EntityListResponse, EntityQueryParams, FilterGroup, FilterItem, FilterOperator } from '@amaster.ai/entity-client';
5
+ import { BpmClient } from '@amaster.ai/bpm-client';
6
+ export { CamundaVariable, HistoryProcessInstance, HistoryTask, ProcessInstance, ProcessVariable, Task, TaskFormSchema, TaskQueryParams } from '@amaster.ai/bpm-client';
7
+ import { WorkflowClient } from '@amaster.ai/workflow-client';
8
+ export { WorkflowFile, WorkflowInputValue, WorkflowRunRequest, WorkflowRunResponse } from '@amaster.ai/workflow-client';
9
+ export { ClientError, ClientResult } from '@amaster.ai/http-client';
10
+
11
+ /**
12
+ * Amaster Client Configuration Options
13
+ */
14
+ interface AmasterClientOptions {
15
+ /**
16
+ * Base URL for the Amaster API
17
+ * @example 'https://api.amaster.ai'
18
+ */
19
+ baseURL: string;
20
+ /**
21
+ * Optional custom headers to include in all requests
22
+ */
23
+ headers?: Record<string, string>;
24
+ /**
25
+ * Callback function triggered when a 401 Unauthorized response is received
26
+ * Useful for redirecting to login page or showing auth modal
27
+ * @example () => window.location.href = '/login'
28
+ */
29
+ onUnauthorized?: () => void;
30
+ /**
31
+ * Callback function triggered when the access token expires
32
+ * Auto-refresh is handled internally, this is for additional actions
33
+ */
34
+ onTokenExpired?: () => void;
35
+ /**
36
+ * Enable automatic token refresh (default: true)
37
+ */
38
+ autoRefresh?: boolean;
39
+ /**
40
+ * Token refresh threshold in seconds (default: 300 = 5 minutes)
41
+ * Tokens will be refreshed this many seconds before expiry
42
+ */
43
+ refreshThreshold?: number;
44
+ }
45
+ /**
46
+ * Unified Amaster Client
47
+ *
48
+ * Provides a simplified, Supabase-style API to access all Amaster services
49
+ */
50
+ interface AmasterClient {
51
+ /**
52
+ * Authentication module
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Login
57
+ * await client.auth.login({ email, password });
58
+ *
59
+ * // Register
60
+ * await client.auth.register({ username, email, password });
61
+ *
62
+ * // Logout
63
+ * await client.auth.logout();
64
+ *
65
+ * // Get current user
66
+ * const user = await client.auth.getMe();
67
+ * ```
68
+ */
69
+ auth: AuthClient;
70
+ /**
71
+ * Entity CRUD operations module
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // List entities
76
+ * const result = await client.entity.list('default', 'users', {
77
+ * page: 1,
78
+ * perPage: 20,
79
+ * orderBy: 'createdAt',
80
+ * orderDir: 'desc'
81
+ * });
82
+ *
83
+ * // Get single entity
84
+ * const user = await client.entity.get('default', 'users', 1);
85
+ *
86
+ * // Create entity
87
+ * await client.entity.create('default', 'users', { name: 'John' });
88
+ *
89
+ * // Update entity
90
+ * await client.entity.update('default', 'users', 1, { name: 'Jane' });
91
+ *
92
+ * // Delete entity
93
+ * await client.entity.delete('default', 'users', 1);
94
+ * ```
95
+ */
96
+ entity: EntityClient;
97
+ /**
98
+ * BPM (Business Process Management) module
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // Start a process
103
+ * await client.bpm.startProcess({
104
+ * processKey: 'approval-process',
105
+ * variables: { amount: 1000 }
106
+ * });
107
+ *
108
+ * // Get my tasks
109
+ * const tasks = await client.bpm.getMyTasks();
110
+ *
111
+ * // Complete a task
112
+ * await client.bpm.completeTask(taskId, { approved: true });
113
+ * ```
114
+ */
115
+ bpm: BpmClient;
116
+ /**
117
+ * Workflow execution module
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * // Execute a workflow
122
+ * const result = await client.workflow.execute('my-workflow', {
123
+ * input: { data: 'value' }
124
+ * });
125
+ * ```
126
+ */
127
+ workflow: WorkflowClient;
128
+ /**
129
+ * Check if the user is currently authenticated
130
+ */
131
+ isAuthenticated(): boolean;
132
+ /**
133
+ * Get the current access token
134
+ */
135
+ getAccessToken(): string | null;
136
+ /**
137
+ * Manually set an access token (useful for SSR or token from external auth)
138
+ */
139
+ setAccessToken(token: string): void;
140
+ /**
141
+ * Clear all authentication data
142
+ */
143
+ clearAuth(): void;
144
+ }
145
+
146
+ /**
147
+ * ============================================================================
148
+ * @amaster.ai/client - Unified Amaster Client
149
+ * ============================================================================
150
+ *
151
+ * Supabase-inspired unified API client for the Amaster platform
152
+ *
153
+ * Features:
154
+ * - Single client instance for all services (auth, entity, bpm, workflow)
155
+ * - Automatic token management and refresh
156
+ * - Auto-attach authentication to all requests
157
+ * - Centralized error handling
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const client = createClient({
162
+ * baseURL: 'https://api.amaster.ai',
163
+ * onUnauthorized: () => window.location.href = '/login'
164
+ * });
165
+ *
166
+ * // Login
167
+ * await client.auth.login({ email, password });
168
+ *
169
+ * // All subsequent requests automatically include auth token
170
+ * await client.entity.list('default', 'users');
171
+ * await client.bpm.startProcess({ processKey: 'approval' });
172
+ * ```
173
+ */
174
+
175
+ /**
176
+ * Create a unified Amaster client instance
177
+ *
178
+ * This function creates a single client that provides access to all Amaster services:
179
+ * - Authentication (login, register, logout)
180
+ * - Entity CRUD operations
181
+ * - BPM (Business Process Management)
182
+ * - Workflow execution
183
+ *
184
+ * All sub-clients automatically share the same HTTP client and authentication state,
185
+ * ensuring that tokens are consistently attached to all requests.
186
+ *
187
+ * @param options - Client configuration options
188
+ * @returns A unified Amaster client instance
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Basic usage
193
+ * const client = createClient({
194
+ * baseURL: 'https://api.amaster.ai'
195
+ * });
196
+ *
197
+ * // With authentication callbacks
198
+ * const client = createClient({
199
+ * baseURL: 'https://api.amaster.ai',
200
+ * onUnauthorized: () => {
201
+ * // Redirect to login or show auth modal
202
+ * window.location.href = '/login';
203
+ * },
204
+ * onTokenExpired: () => {
205
+ * console.log('Token expired, refreshing...');
206
+ * }
207
+ * });
208
+ *
209
+ * // Login
210
+ * await client.auth.login({
211
+ * email: 'user@example.com',
212
+ * password: 'password123'
213
+ * });
214
+ *
215
+ * // Now all requests automatically include the auth token
216
+ * const users = await client.entity.list('default', 'users');
217
+ * const tasks = await client.bpm.getMyTasks();
218
+ * ```
219
+ */
220
+ declare function createClient(options: AmasterClientOptions): AmasterClient;
221
+
222
+ export { type AmasterClient, type AmasterClientOptions, createClient };
@@ -0,0 +1,222 @@
1
+ import { AuthClient } from '@amaster.ai/auth-client';
2
+ export { LoginParams, LoginResponse, OAuthProvider, Permission, RegisterParams, Role, Session, User } from '@amaster.ai/auth-client';
3
+ import { EntityClient } from '@amaster.ai/entity-client';
4
+ export { EntityListResponse, EntityQueryParams, FilterGroup, FilterItem, FilterOperator } from '@amaster.ai/entity-client';
5
+ import { BpmClient } from '@amaster.ai/bpm-client';
6
+ export { CamundaVariable, HistoryProcessInstance, HistoryTask, ProcessInstance, ProcessVariable, Task, TaskFormSchema, TaskQueryParams } from '@amaster.ai/bpm-client';
7
+ import { WorkflowClient } from '@amaster.ai/workflow-client';
8
+ export { WorkflowFile, WorkflowInputValue, WorkflowRunRequest, WorkflowRunResponse } from '@amaster.ai/workflow-client';
9
+ export { ClientError, ClientResult } from '@amaster.ai/http-client';
10
+
11
+ /**
12
+ * Amaster Client Configuration Options
13
+ */
14
+ interface AmasterClientOptions {
15
+ /**
16
+ * Base URL for the Amaster API
17
+ * @example 'https://api.amaster.ai'
18
+ */
19
+ baseURL: string;
20
+ /**
21
+ * Optional custom headers to include in all requests
22
+ */
23
+ headers?: Record<string, string>;
24
+ /**
25
+ * Callback function triggered when a 401 Unauthorized response is received
26
+ * Useful for redirecting to login page or showing auth modal
27
+ * @example () => window.location.href = '/login'
28
+ */
29
+ onUnauthorized?: () => void;
30
+ /**
31
+ * Callback function triggered when the access token expires
32
+ * Auto-refresh is handled internally, this is for additional actions
33
+ */
34
+ onTokenExpired?: () => void;
35
+ /**
36
+ * Enable automatic token refresh (default: true)
37
+ */
38
+ autoRefresh?: boolean;
39
+ /**
40
+ * Token refresh threshold in seconds (default: 300 = 5 minutes)
41
+ * Tokens will be refreshed this many seconds before expiry
42
+ */
43
+ refreshThreshold?: number;
44
+ }
45
+ /**
46
+ * Unified Amaster Client
47
+ *
48
+ * Provides a simplified, Supabase-style API to access all Amaster services
49
+ */
50
+ interface AmasterClient {
51
+ /**
52
+ * Authentication module
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Login
57
+ * await client.auth.login({ email, password });
58
+ *
59
+ * // Register
60
+ * await client.auth.register({ username, email, password });
61
+ *
62
+ * // Logout
63
+ * await client.auth.logout();
64
+ *
65
+ * // Get current user
66
+ * const user = await client.auth.getMe();
67
+ * ```
68
+ */
69
+ auth: AuthClient;
70
+ /**
71
+ * Entity CRUD operations module
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // List entities
76
+ * const result = await client.entity.list('default', 'users', {
77
+ * page: 1,
78
+ * perPage: 20,
79
+ * orderBy: 'createdAt',
80
+ * orderDir: 'desc'
81
+ * });
82
+ *
83
+ * // Get single entity
84
+ * const user = await client.entity.get('default', 'users', 1);
85
+ *
86
+ * // Create entity
87
+ * await client.entity.create('default', 'users', { name: 'John' });
88
+ *
89
+ * // Update entity
90
+ * await client.entity.update('default', 'users', 1, { name: 'Jane' });
91
+ *
92
+ * // Delete entity
93
+ * await client.entity.delete('default', 'users', 1);
94
+ * ```
95
+ */
96
+ entity: EntityClient;
97
+ /**
98
+ * BPM (Business Process Management) module
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // Start a process
103
+ * await client.bpm.startProcess({
104
+ * processKey: 'approval-process',
105
+ * variables: { amount: 1000 }
106
+ * });
107
+ *
108
+ * // Get my tasks
109
+ * const tasks = await client.bpm.getMyTasks();
110
+ *
111
+ * // Complete a task
112
+ * await client.bpm.completeTask(taskId, { approved: true });
113
+ * ```
114
+ */
115
+ bpm: BpmClient;
116
+ /**
117
+ * Workflow execution module
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * // Execute a workflow
122
+ * const result = await client.workflow.execute('my-workflow', {
123
+ * input: { data: 'value' }
124
+ * });
125
+ * ```
126
+ */
127
+ workflow: WorkflowClient;
128
+ /**
129
+ * Check if the user is currently authenticated
130
+ */
131
+ isAuthenticated(): boolean;
132
+ /**
133
+ * Get the current access token
134
+ */
135
+ getAccessToken(): string | null;
136
+ /**
137
+ * Manually set an access token (useful for SSR or token from external auth)
138
+ */
139
+ setAccessToken(token: string): void;
140
+ /**
141
+ * Clear all authentication data
142
+ */
143
+ clearAuth(): void;
144
+ }
145
+
146
+ /**
147
+ * ============================================================================
148
+ * @amaster.ai/client - Unified Amaster Client
149
+ * ============================================================================
150
+ *
151
+ * Supabase-inspired unified API client for the Amaster platform
152
+ *
153
+ * Features:
154
+ * - Single client instance for all services (auth, entity, bpm, workflow)
155
+ * - Automatic token management and refresh
156
+ * - Auto-attach authentication to all requests
157
+ * - Centralized error handling
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * const client = createClient({
162
+ * baseURL: 'https://api.amaster.ai',
163
+ * onUnauthorized: () => window.location.href = '/login'
164
+ * });
165
+ *
166
+ * // Login
167
+ * await client.auth.login({ email, password });
168
+ *
169
+ * // All subsequent requests automatically include auth token
170
+ * await client.entity.list('default', 'users');
171
+ * await client.bpm.startProcess({ processKey: 'approval' });
172
+ * ```
173
+ */
174
+
175
+ /**
176
+ * Create a unified Amaster client instance
177
+ *
178
+ * This function creates a single client that provides access to all Amaster services:
179
+ * - Authentication (login, register, logout)
180
+ * - Entity CRUD operations
181
+ * - BPM (Business Process Management)
182
+ * - Workflow execution
183
+ *
184
+ * All sub-clients automatically share the same HTTP client and authentication state,
185
+ * ensuring that tokens are consistently attached to all requests.
186
+ *
187
+ * @param options - Client configuration options
188
+ * @returns A unified Amaster client instance
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * // Basic usage
193
+ * const client = createClient({
194
+ * baseURL: 'https://api.amaster.ai'
195
+ * });
196
+ *
197
+ * // With authentication callbacks
198
+ * const client = createClient({
199
+ * baseURL: 'https://api.amaster.ai',
200
+ * onUnauthorized: () => {
201
+ * // Redirect to login or show auth modal
202
+ * window.location.href = '/login';
203
+ * },
204
+ * onTokenExpired: () => {
205
+ * console.log('Token expired, refreshing...');
206
+ * }
207
+ * });
208
+ *
209
+ * // Login
210
+ * await client.auth.login({
211
+ * email: 'user@example.com',
212
+ * password: 'password123'
213
+ * });
214
+ *
215
+ * // Now all requests automatically include the auth token
216
+ * const users = await client.entity.list('default', 'users');
217
+ * const tasks = await client.bpm.getMyTasks();
218
+ * ```
219
+ */
220
+ declare function createClient(options: AmasterClientOptions): AmasterClient;
221
+
222
+ export { type AmasterClient, type AmasterClientOptions, createClient };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import { createAuthClient } from '@amaster.ai/auth-client';
2
+ import { createEntityClient } from '@amaster.ai/entity-client';
3
+ import { createBpmClient } from '@amaster.ai/bpm-client';
4
+ import { createWorkflowClient } from '@amaster.ai/workflow-client';
5
+ import { createHttpClient } from '@amaster.ai/http-client';
6
+
7
+ // src/client.ts
8
+ function createClient(options) {
9
+ const { baseURL, headers = {}, onUnauthorized, onTokenExpired } = options;
10
+ const baseHttpClient = createHttpClient({
11
+ baseURL,
12
+ headers
13
+ });
14
+ const auth = createAuthClient({
15
+ baseURL,
16
+ headers,
17
+ onTokenExpired,
18
+ onUnauthorized
19
+ });
20
+ const createAuthenticatedHttpClient = () => {
21
+ return {
22
+ async request(config) {
23
+ const token = auth.getAccessToken();
24
+ const authHeaders = token ? { Authorization: `Bearer ${token}` } : {};
25
+ const mergedConfig = {
26
+ ...config,
27
+ headers: {
28
+ ...config.headers,
29
+ ...authHeaders
30
+ }
31
+ };
32
+ const result = await baseHttpClient.request(mergedConfig);
33
+ if (result.status === 401 && onUnauthorized) {
34
+ onUnauthorized();
35
+ }
36
+ return result;
37
+ }
38
+ };
39
+ };
40
+ const authenticatedHttpClient = createAuthenticatedHttpClient();
41
+ const entity = createEntityClient(authenticatedHttpClient);
42
+ const bpm = createBpmClient(authenticatedHttpClient);
43
+ const workflow = createWorkflowClient(authenticatedHttpClient);
44
+ const client = {
45
+ auth,
46
+ entity,
47
+ bpm,
48
+ workflow,
49
+ // Expose token management methods from auth client
50
+ isAuthenticated: () => auth.isAuthenticated(),
51
+ getAccessToken: () => auth.getAccessToken(),
52
+ setAccessToken: (token) => auth.setAccessToken(token),
53
+ clearAuth: () => auth.clearAuth()
54
+ };
55
+ return client;
56
+ }
57
+
58
+ export { createClient };
59
+ //# sourceMappingURL=index.js.map
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;AAiFO,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;AAG7E,EAAA,MAAM,MAAA,GAAwB;AAAA,IAC5B,IAAA;AAAA,IACA,MAAA;AAAA,IACA,GAAA;AAAA,IACA,QAAA;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 * const client = createClient({\n * baseURL: 'https://api.amaster.ai',\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 { 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\n * const client = createClient({\n * baseURL: 'https://api.amaster.ai'\n * });\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\n // Return unified client interface\n const client: AmasterClient = {\n auth,\n entity,\n bpm,\n workflow,\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 ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@amaster.ai/client",
3
+ "version": "1.1.0-beta.0",
4
+ "description": "Unified API client for Amaster platform - Supabase-style interface",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "typesVersions": {
10
+ "*": {
11
+ "*": [
12
+ "./types/index.d.ts"
13
+ ],
14
+ "auth": [
15
+ "./types/auth.d.ts"
16
+ ],
17
+ "entity": [
18
+ "./types/entity.d.ts"
19
+ ],
20
+ "bpm": [
21
+ "./types/bpm.d.ts"
22
+ ],
23
+ "workflow": [
24
+ "./types/workflow.d.ts"
25
+ ],
26
+ "common": [
27
+ "./types/common.d.ts"
28
+ ]
29
+ }
30
+ },
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.cjs"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "types",
41
+ "README.md"
42
+ ],
43
+ "keywords": [
44
+ "amaster",
45
+ "client",
46
+ "sdk",
47
+ "unified-api",
48
+ "typescript"
49
+ ],
50
+ "author": "Amaster Team",
51
+ "license": "MIT",
52
+ "publishConfig": {
53
+ "access": "public",
54
+ "registry": "https://registry.npmjs.org/"
55
+ },
56
+ "dependencies": {
57
+ "@amaster.ai/bpm-client": "1.1.0-beta.0",
58
+ "@amaster.ai/workflow-client": "1.1.0-beta.0",
59
+ "@amaster.ai/http-client": "1.1.0-beta.0",
60
+ "@amaster.ai/entity-client": "1.1.0-beta.0",
61
+ "@amaster.ai/auth-client": "1.1.0-beta.0"
62
+ },
63
+ "peerDependencies": {
64
+ "axios": "^1.11.0"
65
+ },
66
+ "devDependencies": {
67
+ "@vitest/ui": "^1.0.0",
68
+ "axios": "^1.11.0",
69
+ "axios-mock-adapter": "^1.22.0",
70
+ "tsup": "^8.3.5",
71
+ "typescript": "~5.7.2",
72
+ "vitest": "^1.0.0"
73
+ },
74
+ "scripts": {
75
+ "build": "./scripts/build.sh",
76
+ "build:types": "tsc --emitDeclarationOnly --outDir types-generated",
77
+ "dev": "tsup --watch",
78
+ "clean": "rm -rf dist types-generated *.tsbuildinfo",
79
+ "type-check": "tsc --noEmit",
80
+ "validate-types": "tsc --noEmit --project tsconfig.types.json",
81
+ "test": "vitest run",
82
+ "test:watch": "vitest"
83
+ }
84
+ }