@sliceapi/sdk 0.0.1
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/README.md +333 -0
- package/dist/sdk/src/client.d.ts +38 -0
- package/dist/sdk/src/client.d.ts.map +1 -0
- package/dist/sdk/src/client.js +210 -0
- package/dist/sdk/src/client.js.map +1 -0
- package/dist/sdk/src/errors.d.ts +40 -0
- package/dist/sdk/src/errors.d.ts.map +1 -0
- package/dist/sdk/src/errors.js +64 -0
- package/dist/sdk/src/errors.js.map +1 -0
- package/dist/sdk/src/index.d.ts +62 -0
- package/dist/sdk/src/index.d.ts.map +1 -0
- package/dist/sdk/src/index.js +76 -0
- package/dist/sdk/src/index.js.map +1 -0
- package/dist/sdk/src/methods/licenses.d.ts +36 -0
- package/dist/sdk/src/methods/licenses.d.ts.map +1 -0
- package/dist/sdk/src/methods/licenses.js +54 -0
- package/dist/sdk/src/methods/licenses.js.map +1 -0
- package/dist/sdk/src/methods/users.d.ts +27 -0
- package/dist/sdk/src/methods/users.d.ts.map +1 -0
- package/dist/sdk/src/methods/users.js +32 -0
- package/dist/sdk/src/methods/users.js.map +1 -0
- package/dist/sdk/src/methods/validate.d.ts +24 -0
- package/dist/sdk/src/methods/validate.d.ts.map +1 -0
- package/dist/sdk/src/methods/validate.js +29 -0
- package/dist/sdk/src/methods/validate.js.map +1 -0
- package/dist/sdk/src/types.d.ts +22 -0
- package/dist/sdk/src/types.d.ts.map +1 -0
- package/dist/sdk/src/types.js +2 -0
- package/dist/sdk/src/types.js.map +1 -0
- package/dist/shared/api-types.d.ts +213 -0
- package/dist/shared/api-types.d.ts.map +1 -0
- package/dist/shared/api-types.js +2 -0
- package/dist/shared/api-types.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
# SliceAPI SDK
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the SliceAPI LaaS (Licensing as a Service) platform. This SDK provides a type-safe, cross-platform interface for integrating license validation and management into your applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Type Safe**: Full TypeScript support with exported types
|
|
8
|
+
- ✅ **Cross-Platform**: Works in both Node.js (18+) and browser environments
|
|
9
|
+
- ✅ **Modern**: Uses native `fetch` API
|
|
10
|
+
- ✅ **Error Handling**: Custom error classes with meaningful messages
|
|
11
|
+
- ✅ **Flexible**: Configurable base URL and timeout settings
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @sliceapi/sdk
|
|
17
|
+
# or
|
|
18
|
+
yarn add @sliceapi/sdk
|
|
19
|
+
# or
|
|
20
|
+
pnpm add @sliceapi/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { SliceClient } from '@sliceapi/sdk';
|
|
27
|
+
|
|
28
|
+
// Initialize the client with your API key
|
|
29
|
+
const client = new SliceClient('sk_live_...', {
|
|
30
|
+
baseUrl: 'https://api.example.com' // Optional, defaults to process.env.SLICE_API_URL or localhost
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Validate a user's license
|
|
34
|
+
const result = await client.validate.validate('user_123');
|
|
35
|
+
|
|
36
|
+
if (result.valid) {
|
|
37
|
+
console.log('License is valid:', result.license);
|
|
38
|
+
console.log('Features:', result.features);
|
|
39
|
+
} else {
|
|
40
|
+
console.log('License invalid:', result.reason);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
### Constructor Options
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface SliceClientOptions {
|
|
50
|
+
/**
|
|
51
|
+
* Base URL for the API
|
|
52
|
+
* Defaults to process.env.SLICE_API_URL or 'http://localhost:3001'
|
|
53
|
+
*/
|
|
54
|
+
baseUrl?: string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Request timeout in milliseconds
|
|
58
|
+
* Defaults to 30000 (30 seconds)
|
|
59
|
+
*/
|
|
60
|
+
timeout?: number;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Environment Variables
|
|
65
|
+
|
|
66
|
+
- `SLICE_API_URL`: Base URL for the API (used if not provided in constructor)
|
|
67
|
+
|
|
68
|
+
## API Reference
|
|
69
|
+
|
|
70
|
+
### License Validation
|
|
71
|
+
|
|
72
|
+
#### `client.validate.validate(userId: string)`
|
|
73
|
+
|
|
74
|
+
Validates a user's license and returns the validation result.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const result = await client.validate.validate('user_123');
|
|
78
|
+
|
|
79
|
+
if (result.valid) {
|
|
80
|
+
// License is valid
|
|
81
|
+
console.log(result.license); // License object
|
|
82
|
+
console.log(result.activation); // Activation object (if exists)
|
|
83
|
+
console.log(result.features); // Array of feature flags
|
|
84
|
+
} else {
|
|
85
|
+
// License is invalid
|
|
86
|
+
console.log(result.reason); // 'expired' | 'revoked' | 'suspended' | 'exceeded_seats' | 'no_license' | 'user_not_found'
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Response Types:**
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
type ValidateLicenseResponse =
|
|
94
|
+
| { valid: true; license: License; activation?: Activation; features?: string[] }
|
|
95
|
+
| { valid: false; reason: 'expired' | 'revoked' | 'suspended' | 'exceeded_seats' | 'no_license' | 'user_not_found' };
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### User Management
|
|
99
|
+
|
|
100
|
+
#### `client.users.createUser(params: CreateUserRequest)`
|
|
101
|
+
|
|
102
|
+
Creates a new user in the system.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
const user = await client.users.createUser({
|
|
106
|
+
externalId: 'user_123', // Required: Your internal user ID
|
|
107
|
+
email: 'user@example.com', // Optional
|
|
108
|
+
name: 'John Doe', // Optional
|
|
109
|
+
metadata: { // Optional
|
|
110
|
+
source: 'signup_form'
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Request Type:**
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
interface CreateUserRequest {
|
|
119
|
+
externalId: string; // Required: Tenant's internal user ID
|
|
120
|
+
email?: string; // Optional
|
|
121
|
+
name?: string; // Optional
|
|
122
|
+
metadata?: Record<string, any>; // Optional
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### License Management
|
|
127
|
+
|
|
128
|
+
#### `client.licenses.assignLicense(licenseId: string, userId: string, metadata?: Record<string, any>)`
|
|
129
|
+
|
|
130
|
+
Assigns a license to a user.
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
const assignment = await client.licenses.assignLicense(
|
|
134
|
+
'license_123', // License ID
|
|
135
|
+
'user_456', // User ID
|
|
136
|
+
{ // Optional metadata
|
|
137
|
+
source: 'admin_panel',
|
|
138
|
+
assignedBy: 'admin_user_1'
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### `client.licenses.updateLicenseStatus(licenseId: string, status: LicenseStatus)`
|
|
144
|
+
|
|
145
|
+
Updates a license's status.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const license = await client.licenses.updateLicenseStatus(
|
|
149
|
+
'license_123',
|
|
150
|
+
'suspended' // 'active' | 'suspended' | 'revoked' | 'expired'
|
|
151
|
+
);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Error Handling
|
|
155
|
+
|
|
156
|
+
The SDK provides custom error classes for different error scenarios:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
import {
|
|
160
|
+
SliceError,
|
|
161
|
+
SliceAPIError,
|
|
162
|
+
SliceAuthenticationError,
|
|
163
|
+
SliceValidationError,
|
|
164
|
+
SliceNetworkError,
|
|
165
|
+
SliceTimeoutError,
|
|
166
|
+
} from '@sliceapi/sdk';
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
const result = await client.validate.validate('user_123');
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error instanceof SliceAuthenticationError) {
|
|
172
|
+
// Invalid API key or authentication failed
|
|
173
|
+
console.error('Auth error:', error.message, error.statusCode);
|
|
174
|
+
} else if (error instanceof SliceValidationError) {
|
|
175
|
+
// Invalid request parameters
|
|
176
|
+
console.error('Validation error:', error.message);
|
|
177
|
+
} else if (error instanceof SliceNetworkError) {
|
|
178
|
+
// Network connectivity issue
|
|
179
|
+
console.error('Network error:', error.message);
|
|
180
|
+
} else if (error instanceof SliceTimeoutError) {
|
|
181
|
+
// Request timed out
|
|
182
|
+
console.error('Timeout:', error.message);
|
|
183
|
+
} else if (error instanceof SliceAPIError) {
|
|
184
|
+
// Other API errors (4xx, 5xx)
|
|
185
|
+
console.error('API error:', error.message, error.statusCode);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Error Classes
|
|
191
|
+
|
|
192
|
+
- **`SliceError`**: Base error class for all SDK errors
|
|
193
|
+
- **`SliceAPIError`**: API errors (4xx, 5xx status codes)
|
|
194
|
+
- **`SliceAuthenticationError`**: Authentication errors (401, 403)
|
|
195
|
+
- **`SliceValidationError`**: Validation errors (400)
|
|
196
|
+
- **`SliceNetworkError`**: Network connectivity errors
|
|
197
|
+
- **`SliceTimeoutError`**: Request timeout errors
|
|
198
|
+
|
|
199
|
+
## TypeScript Support
|
|
200
|
+
|
|
201
|
+
The SDK is written in TypeScript and provides full type definitions. All types are exported for your convenience:
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
import type {
|
|
205
|
+
License,
|
|
206
|
+
LicenseStatus,
|
|
207
|
+
LaaSUser,
|
|
208
|
+
UserLicense,
|
|
209
|
+
Activation,
|
|
210
|
+
ValidateLicenseResponse,
|
|
211
|
+
CreateUserRequest,
|
|
212
|
+
// ... and more
|
|
213
|
+
} from '@sliceapi/sdk';
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Environment Support
|
|
217
|
+
|
|
218
|
+
### Node.js
|
|
219
|
+
|
|
220
|
+
The SDK works in Node.js 18+ (which includes native `fetch` support). For older versions, you may need a polyfill.
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
// Node.js example
|
|
224
|
+
import { SliceClient } from '@sliceapi/sdk';
|
|
225
|
+
|
|
226
|
+
const client = new SliceClient(process.env.SLICE_API_KEY!, {
|
|
227
|
+
baseUrl: process.env.SLICE_API_URL
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Browser
|
|
232
|
+
|
|
233
|
+
The SDK works in all modern browsers that support the `fetch` API.
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
// Browser example
|
|
237
|
+
import { SliceClient } from '@sliceapi/sdk';
|
|
238
|
+
|
|
239
|
+
const client = new SliceClient('sk_live_...', {
|
|
240
|
+
baseUrl: 'https://api.example.com'
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Examples
|
|
245
|
+
|
|
246
|
+
### Complete Example: License Validation Flow
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { SliceClient, SliceAuthenticationError } from '@sliceapi/sdk';
|
|
250
|
+
|
|
251
|
+
const client = new SliceClient('sk_live_...');
|
|
252
|
+
|
|
253
|
+
async function checkUserLicense(userId: string) {
|
|
254
|
+
try {
|
|
255
|
+
const result = await client.validate.validate(userId);
|
|
256
|
+
|
|
257
|
+
if (result.valid) {
|
|
258
|
+
console.log('✅ License is valid');
|
|
259
|
+
console.log('License ID:', result.license.id);
|
|
260
|
+
console.log('Status:', result.license.status);
|
|
261
|
+
console.log('Features:', result.features || []);
|
|
262
|
+
|
|
263
|
+
if (result.license.expiresAt) {
|
|
264
|
+
console.log('Expires at:', result.license.expiresAt);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return true;
|
|
268
|
+
} else {
|
|
269
|
+
console.log('❌ License is invalid:', result.reason);
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
} catch (error) {
|
|
273
|
+
if (error instanceof SliceAuthenticationError) {
|
|
274
|
+
console.error('Authentication failed. Check your API key.');
|
|
275
|
+
} else {
|
|
276
|
+
console.error('Error validating license:', error);
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Usage
|
|
283
|
+
await checkUserLicense('user_123');
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Example: User and License Management
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { SliceClient } from '@sliceapi/sdk';
|
|
290
|
+
|
|
291
|
+
const client = new SliceClient('sk_live_...');
|
|
292
|
+
|
|
293
|
+
// Create a user
|
|
294
|
+
const user = await client.users.createUser({
|
|
295
|
+
externalId: 'user_123',
|
|
296
|
+
email: 'user@example.com',
|
|
297
|
+
name: 'John Doe'
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
console.log('Created user:', user.id);
|
|
301
|
+
|
|
302
|
+
// Assign a license to the user
|
|
303
|
+
const assignment = await client.licenses.assignLicense(
|
|
304
|
+
'license_123',
|
|
305
|
+
'user_123',
|
|
306
|
+
{ source: 'admin_panel' }
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
console.log('License assigned:', assignment.id);
|
|
310
|
+
|
|
311
|
+
// Update license status
|
|
312
|
+
const updated = await client.licenses.updateLicenseStatus(
|
|
313
|
+
'license_123',
|
|
314
|
+
'active'
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
console.log('License status updated:', updated.status);
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## API Endpoints
|
|
321
|
+
|
|
322
|
+
The SDK uses the following API endpoints:
|
|
323
|
+
|
|
324
|
+
- `POST /api/v1/validate` - Validate user license
|
|
325
|
+
- `POST /api/v1/admin/users` - Create user
|
|
326
|
+
- `POST /api/v1/admin/licenses/:id/assign` - Assign license to user
|
|
327
|
+
- `PATCH /api/v1/admin/licenses/:id/status` - Update license status
|
|
328
|
+
|
|
329
|
+
All requests are authenticated using the `Authorization: Bearer <api_key>` header.
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { SliceRequestOptions } from './types';
|
|
2
|
+
export interface HttpClientResponse<T = any> {
|
|
3
|
+
data: T;
|
|
4
|
+
status: number;
|
|
5
|
+
statusText: string;
|
|
6
|
+
headers: Headers;
|
|
7
|
+
}
|
|
8
|
+
export declare class HttpClient {
|
|
9
|
+
private apiKey;
|
|
10
|
+
private baseUrl;
|
|
11
|
+
private defaultTimeout;
|
|
12
|
+
constructor(apiKey: string, baseUrl: string, defaultTimeout?: number);
|
|
13
|
+
/**
|
|
14
|
+
* Make an HTTP request
|
|
15
|
+
*/
|
|
16
|
+
request<T>(method: string, path: string, options?: SliceRequestOptions): Promise<HttpClientResponse<T>>;
|
|
17
|
+
/**
|
|
18
|
+
* GET request
|
|
19
|
+
*/
|
|
20
|
+
get<T>(path: string, options?: SliceRequestOptions): Promise<HttpClientResponse<T>>;
|
|
21
|
+
/**
|
|
22
|
+
* POST request
|
|
23
|
+
*/
|
|
24
|
+
post<T>(path: string, body?: any, options?: SliceRequestOptions): Promise<HttpClientResponse<T>>;
|
|
25
|
+
/**
|
|
26
|
+
* PATCH request
|
|
27
|
+
*/
|
|
28
|
+
patch<T>(path: string, body?: any, options?: SliceRequestOptions): Promise<HttpClientResponse<T>>;
|
|
29
|
+
/**
|
|
30
|
+
* Handle fetch response
|
|
31
|
+
*/
|
|
32
|
+
private handleResponse;
|
|
33
|
+
/**
|
|
34
|
+
* Handle errors from fetch
|
|
35
|
+
*/
|
|
36
|
+
private handleError;
|
|
37
|
+
}
|
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5B;;OAEG;IACH,OAAO,CAAC,WAAW;CAqBpB"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { SliceAPIError, SliceAuthenticationError, SliceNetworkError, SliceTimeoutError, SliceValidationError, } from './errors';
|
|
2
|
+
export class HttpClient {
|
|
3
|
+
constructor(apiKey, baseUrl, defaultTimeout = 30000) {
|
|
4
|
+
if (!apiKey) {
|
|
5
|
+
throw new Error('API key is required');
|
|
6
|
+
}
|
|
7
|
+
this.apiKey = apiKey;
|
|
8
|
+
this.baseUrl = baseUrl.replace(/\/$/, ''); // Remove trailing slash
|
|
9
|
+
this.defaultTimeout = defaultTimeout;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Make an HTTP request
|
|
13
|
+
*/
|
|
14
|
+
async request(method, path, options = {}) {
|
|
15
|
+
const url = `${this.baseUrl}${path}`;
|
|
16
|
+
const timeout = options.timeout ?? this.defaultTimeout;
|
|
17
|
+
const headers = {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
20
|
+
...options.headers,
|
|
21
|
+
};
|
|
22
|
+
// Create AbortController for timeout
|
|
23
|
+
const controller = new AbortController();
|
|
24
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(url, {
|
|
27
|
+
method,
|
|
28
|
+
headers,
|
|
29
|
+
signal: controller.signal,
|
|
30
|
+
});
|
|
31
|
+
clearTimeout(timeoutId);
|
|
32
|
+
// Parse response body
|
|
33
|
+
let data;
|
|
34
|
+
const contentType = response.headers.get('content-type');
|
|
35
|
+
if (contentType && contentType.includes('application/json')) {
|
|
36
|
+
try {
|
|
37
|
+
data = await response.json();
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
// If JSON parsing fails, use text
|
|
41
|
+
data = await response.text();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
data = await response.text();
|
|
46
|
+
}
|
|
47
|
+
// Handle error responses
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const errorMessage = data?.error || data?.message || `HTTP ${response.status}: ${response.statusText}`;
|
|
50
|
+
if (response.status === 401 || response.status === 403) {
|
|
51
|
+
throw new SliceAuthenticationError(errorMessage, response.status, data);
|
|
52
|
+
}
|
|
53
|
+
else if (response.status === 400) {
|
|
54
|
+
throw new SliceValidationError(errorMessage, data);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new SliceAPIError(errorMessage, response.status, data);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Extract data from ApiResponse wrapper if present
|
|
61
|
+
const responseData = data?.data !== undefined ? data.data : data;
|
|
62
|
+
return {
|
|
63
|
+
data: responseData,
|
|
64
|
+
status: response.status,
|
|
65
|
+
statusText: response.statusText,
|
|
66
|
+
headers: response.headers,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
clearTimeout(timeoutId);
|
|
71
|
+
// Handle AbortError (timeout)
|
|
72
|
+
if (error.name === 'AbortError') {
|
|
73
|
+
throw new SliceTimeoutError(`Request timeout after ${timeout}ms`);
|
|
74
|
+
}
|
|
75
|
+
// Re-throw our custom errors
|
|
76
|
+
if (error instanceof SliceAPIError ||
|
|
77
|
+
error instanceof SliceAuthenticationError ||
|
|
78
|
+
error instanceof SliceValidationError ||
|
|
79
|
+
error instanceof SliceNetworkError ||
|
|
80
|
+
error instanceof SliceTimeoutError) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
// Handle network errors
|
|
84
|
+
if (error instanceof TypeError && error.message.includes('fetch')) {
|
|
85
|
+
throw new SliceNetworkError('Network error: Failed to connect to API', error);
|
|
86
|
+
}
|
|
87
|
+
// Unknown error
|
|
88
|
+
throw new SliceNetworkError(error?.message || 'Unknown error occurred', error);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* GET request
|
|
93
|
+
*/
|
|
94
|
+
async get(path, options) {
|
|
95
|
+
return this.request('GET', path, options);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* POST request
|
|
99
|
+
*/
|
|
100
|
+
async post(path, body, options) {
|
|
101
|
+
const url = `${this.baseUrl}${path}`;
|
|
102
|
+
const timeout = options?.timeout ?? this.defaultTimeout;
|
|
103
|
+
const headers = {
|
|
104
|
+
'Content-Type': 'application/json',
|
|
105
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
106
|
+
...options?.headers,
|
|
107
|
+
};
|
|
108
|
+
const controller = new AbortController();
|
|
109
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
110
|
+
try {
|
|
111
|
+
const response = await fetch(url, {
|
|
112
|
+
method: 'POST',
|
|
113
|
+
headers,
|
|
114
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
115
|
+
signal: controller.signal,
|
|
116
|
+
});
|
|
117
|
+
clearTimeout(timeoutId);
|
|
118
|
+
return this.handleResponse(response);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
clearTimeout(timeoutId);
|
|
122
|
+
return this.handleError(error, timeout);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* PATCH request
|
|
127
|
+
*/
|
|
128
|
+
async patch(path, body, options) {
|
|
129
|
+
const url = `${this.baseUrl}${path}`;
|
|
130
|
+
const timeout = options?.timeout ?? this.defaultTimeout;
|
|
131
|
+
const headers = {
|
|
132
|
+
'Content-Type': 'application/json',
|
|
133
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
134
|
+
...options?.headers,
|
|
135
|
+
};
|
|
136
|
+
const controller = new AbortController();
|
|
137
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
138
|
+
try {
|
|
139
|
+
const response = await fetch(url, {
|
|
140
|
+
method: 'PATCH',
|
|
141
|
+
headers,
|
|
142
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
143
|
+
signal: controller.signal,
|
|
144
|
+
});
|
|
145
|
+
clearTimeout(timeoutId);
|
|
146
|
+
return this.handleResponse(response);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
clearTimeout(timeoutId);
|
|
150
|
+
return this.handleError(error, timeout);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Handle fetch response
|
|
155
|
+
*/
|
|
156
|
+
async handleResponse(response) {
|
|
157
|
+
let data;
|
|
158
|
+
const contentType = response.headers.get('content-type');
|
|
159
|
+
if (contentType && contentType.includes('application/json')) {
|
|
160
|
+
try {
|
|
161
|
+
data = await response.json();
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
data = await response.text();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
data = await response.text();
|
|
169
|
+
}
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
const errorMessage = data?.error || data?.message || `HTTP ${response.status}: ${response.statusText}`;
|
|
172
|
+
if (response.status === 401 || response.status === 403) {
|
|
173
|
+
throw new SliceAuthenticationError(errorMessage, response.status, data);
|
|
174
|
+
}
|
|
175
|
+
else if (response.status === 400) {
|
|
176
|
+
throw new SliceValidationError(errorMessage, data);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new SliceAPIError(errorMessage, response.status, data);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const responseData = data?.data !== undefined ? data.data : data;
|
|
183
|
+
return {
|
|
184
|
+
data: responseData,
|
|
185
|
+
status: response.status,
|
|
186
|
+
statusText: response.statusText,
|
|
187
|
+
headers: response.headers,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Handle errors from fetch
|
|
192
|
+
*/
|
|
193
|
+
handleError(error, timeout) {
|
|
194
|
+
if (error.name === 'AbortError') {
|
|
195
|
+
throw new SliceTimeoutError(`Request timeout after ${timeout}ms`);
|
|
196
|
+
}
|
|
197
|
+
if (error instanceof SliceAPIError ||
|
|
198
|
+
error instanceof SliceAuthenticationError ||
|
|
199
|
+
error instanceof SliceValidationError ||
|
|
200
|
+
error instanceof SliceNetworkError ||
|
|
201
|
+
error instanceof SliceTimeoutError) {
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
if (error instanceof TypeError && error.message.includes('fetch')) {
|
|
205
|
+
throw new SliceNetworkError('Network error: Failed to connect to API', error);
|
|
206
|
+
}
|
|
207
|
+
throw new SliceNetworkError(error?.message || 'Unknown error occurred', error);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAUlB,MAAM,OAAO,UAAU;IAKrB,YAAY,MAAc,EAAE,OAAe,EAAE,iBAAyB,KAAK;QACzE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,wBAAwB;QACnE,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CACX,MAAc,EACd,IAAY,EACZ,UAA+B,EAAE;QAEjC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,cAAc,CAAC;QAEvD,MAAM,OAAO,GAAgB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EjE,OAAO;YACL,IAAI,EAAE,YAAiB;YACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,QAAQ,CAAC,OAAO;SAC1B,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,WAAW,CAAC,KAAU,EAAE,OAAe;QAC7C,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAChC,MAAM,IAAI,iBAAiB,CAAC,yBAAyB,OAAO,IAAI,CAAC,CAAC;QACpE,CAAC;QAED,IACE,KAAK,YAAY,aAAa;YAC9B,KAAK,YAAY,wBAAwB;YACzC,KAAK,YAAY,oBAAoB;YACrC,KAAK,YAAY,iBAAiB;YAClC,KAAK,YAAY,iBAAiB,EAClC,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QAED,IAAI,KAAK,YAAY,SAAS,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAClE,MAAM,IAAI,iBAAiB,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;QAChF,CAAC;QAED,MAAM,IAAI,iBAAiB,CAAC,KAAK,EAAE,OAAO,IAAI,wBAAwB,EAAE,KAAK,CAAC,CAAC;IACjF,CAAC;CACF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Slice SDK errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class SliceError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when API returns an error response (4xx, 5xx)
|
|
9
|
+
*/
|
|
10
|
+
export declare class SliceAPIError extends SliceError {
|
|
11
|
+
readonly statusCode: number;
|
|
12
|
+
readonly response?: any;
|
|
13
|
+
constructor(message: string, statusCode: number, response?: any);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Error thrown when authentication fails (401, 403)
|
|
17
|
+
*/
|
|
18
|
+
export declare class SliceAuthenticationError extends SliceAPIError {
|
|
19
|
+
constructor(message: string, statusCode?: number, response?: any);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Error thrown when validation fails (400)
|
|
23
|
+
*/
|
|
24
|
+
export declare class SliceValidationError extends SliceAPIError {
|
|
25
|
+
constructor(message: string, response?: any);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when a network error occurs
|
|
29
|
+
*/
|
|
30
|
+
export declare class SliceNetworkError extends SliceError {
|
|
31
|
+
readonly originalError?: Error;
|
|
32
|
+
constructor(message: string, originalError?: Error);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Error thrown when a request times out
|
|
36
|
+
*/
|
|
37
|
+
export declare class SliceTimeoutError extends SliceError {
|
|
38
|
+
constructor(message?: string);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,UAAU;IAC3C,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,QAAQ,CAAC,EAAE,GAAG,CAAC;gBAEnB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG;CAOhE;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,aAAa;gBAC7C,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAY,EAAE,QAAQ,CAAC,EAAE,GAAG;CAKtE;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;gBACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,GAAG;CAK5C;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC/C,SAAgB,aAAa,CAAC,EAAE,KAAK,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,KAAK;CAMnD;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;gBACnC,OAAO,GAAE,MAA0B;CAKhD"}
|