@voltade/wess-sdk 1.0.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.
- package/README.md +352 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +195 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +59 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/branches.d.ts +55 -0
- package/dist/resources/branches.d.ts.map +1 -0
- package/dist/resources/branches.js +67 -0
- package/dist/resources/branches.js.map +1 -0
- package/dist/resources/customers.d.ts +18 -0
- package/dist/resources/customers.d.ts.map +1 -0
- package/dist/resources/customers.js +20 -0
- package/dist/resources/customers.js.map +1 -0
- package/dist/resources/index.d.ts +7 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +7 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/user.d.ts +16 -0
- package/dist/resources/user.d.ts.map +1 -0
- package/dist/resources/user.js +18 -0
- package/dist/resources/user.js.map +1 -0
- package/dist/types/appointment.d.ts +164 -0
- package/dist/types/appointment.d.ts.map +1 -0
- package/dist/types/appointment.js +67 -0
- package/dist/types/appointment.js.map +1 -0
- package/dist/types/branch.d.ts +60 -0
- package/dist/types/branch.d.ts.map +1 -0
- package/dist/types/branch.js +59 -0
- package/dist/types/branch.js.map +1 -0
- package/dist/types/config.d.ts +17 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +15 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/customer.d.ts +37 -0
- package/dist/types/customer.d.ts.map +1 -0
- package/dist/types/customer.js +36 -0
- package/dist/types/customer.js.map +1 -0
- package/dist/types/error.d.ts +14 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/error.js +12 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +17 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/user.d.ts +26 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +17 -0
- package/dist/types/user.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +80 -0
package/README.md
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
# @voltade/wess-sdk
|
|
2
|
+
|
|
3
|
+
A comprehensive, type-safe TypeScript SDK for the WESS Open API with built-in error handling and resource-based architecture.
|
|
4
|
+
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://github.com/voltade/wess-sdk/packages)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- 🔒 **Type-safe**: Full TypeScript support with exported types
|
|
11
|
+
- 🏗️ **Resource-based architecture**: Organized by API domain (user, branches, customers)
|
|
12
|
+
- ⚠️ **Error handling**: Specific error classes for different failure scenarios
|
|
13
|
+
- 🔌 **Zero dependencies**: Uses native `fetch` API (Node.js 18+)
|
|
14
|
+
- 🛠️ **Configurable**: Environment variables or programmatic configuration
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
> **Note:** This package is published to GitHub Packages (not npm) as a private package.
|
|
19
|
+
|
|
20
|
+
### Prerequisites
|
|
21
|
+
|
|
22
|
+
1. **Create a GitHub Personal Access Token:**
|
|
23
|
+
|
|
24
|
+
- Go to https://github.com/settings/tokens/new
|
|
25
|
+
- Give it a name (e.g., "npm-packages")
|
|
26
|
+
- Select scopes: `read:packages` and `repo`
|
|
27
|
+
- Generate and copy the token
|
|
28
|
+
|
|
29
|
+
2. **Configure npm to use GitHub Packages:**
|
|
30
|
+
|
|
31
|
+
Create or update `.npmrc` in your project root:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
@voltade:registry=https://npm.pkg.github.com
|
|
35
|
+
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_TOKEN
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
> **Important:** Add `.npmrc` to your `.gitignore` to avoid committing your token!
|
|
39
|
+
|
|
40
|
+
3. **Install the package:**
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @voltade/wess-sdk
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
yarn add @voltade/wess-sdk
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm add @voltade/wess-sdk
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { WessClient } from "@voltade/wess-sdk";
|
|
58
|
+
|
|
59
|
+
// Initialize the client
|
|
60
|
+
const client = new WessClient({
|
|
61
|
+
baseUrl: "https://your-wess-api.com/api",
|
|
62
|
+
bearerToken: "your-bearer-token",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Get current user
|
|
66
|
+
const user = await client.user.get();
|
|
67
|
+
console.log(user.data.name);
|
|
68
|
+
|
|
69
|
+
// List all branches
|
|
70
|
+
const branches = await client.branches.list();
|
|
71
|
+
|
|
72
|
+
// Get a specific branch
|
|
73
|
+
const branch = await client.branches.get(4630);
|
|
74
|
+
|
|
75
|
+
// Get online appointment services for a branch
|
|
76
|
+
const services = await client.branches.getOnlineAppointmentServices(4630);
|
|
77
|
+
|
|
78
|
+
// Get available employees for specific products
|
|
79
|
+
const employees = await client.branches.getOnlineAppointmentEmployees(4630, {
|
|
80
|
+
product_ids: [1718, 5523],
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Get available time slots
|
|
84
|
+
const timeSlots = await client.branches.getOnlineAppointmentTimeSlots(4630, {
|
|
85
|
+
product_ids: [1718],
|
|
86
|
+
date: "2024-12-15",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Search customers by phone number
|
|
90
|
+
const customers = await client.customers.searchByPhoneNumber("+60123456789");
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Configuration
|
|
94
|
+
|
|
95
|
+
### Environment Variables
|
|
96
|
+
|
|
97
|
+
The SDK can be configured using environment variables:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
WESS_BASE_URL=https://your-wess-api.com/api
|
|
101
|
+
WESS_BEARER_TOKEN=your-bearer-token
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Client Options
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
interface WessClientConfig {
|
|
108
|
+
/** Base URL for the WESS API (default: from WESS_BASE_URL env var) */
|
|
109
|
+
baseUrl?: string;
|
|
110
|
+
/** Bearer token for authentication (default: from WESS_BEARER_TOKEN env var) */
|
|
111
|
+
bearerToken?: string;
|
|
112
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
113
|
+
timeout?: number;
|
|
114
|
+
/** Custom headers to include in all requests */
|
|
115
|
+
headers?: Record<string, string>;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## API Reference
|
|
120
|
+
|
|
121
|
+
### User Resource
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Get current authenticated user
|
|
125
|
+
const response = await client.user.get();
|
|
126
|
+
// Returns: { code: number, data: User }
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Branches Resource
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// List all branches
|
|
133
|
+
const branches = await client.branches.list();
|
|
134
|
+
// Returns: Branch[]
|
|
135
|
+
|
|
136
|
+
// Get a single branch
|
|
137
|
+
const branch = await client.branches.get(branchId);
|
|
138
|
+
// Returns: Branch
|
|
139
|
+
|
|
140
|
+
// Get a customer from a branch
|
|
141
|
+
const customer = await client.branches.getCustomer(branchId, customerId);
|
|
142
|
+
// Returns: Customer
|
|
143
|
+
|
|
144
|
+
// Get online appointment services
|
|
145
|
+
const services = await client.branches.getOnlineAppointmentServices(branchId);
|
|
146
|
+
// Returns: OnlineAppointmentService[]
|
|
147
|
+
|
|
148
|
+
// Get employees for online appointments (filtered by product IDs)
|
|
149
|
+
const employees = await client.branches.getOnlineAppointmentEmployees(
|
|
150
|
+
branchId,
|
|
151
|
+
{
|
|
152
|
+
product_ids: [1718, 5523],
|
|
153
|
+
}
|
|
154
|
+
);
|
|
155
|
+
// Returns: OnlineAppointmentEmployee[]
|
|
156
|
+
|
|
157
|
+
// Get available time slots
|
|
158
|
+
const slots = await client.branches.getOnlineAppointmentTimeSlots(branchId, {
|
|
159
|
+
product_ids: [1718],
|
|
160
|
+
date: "2024-12-15", // YYYY-MM-DD format
|
|
161
|
+
});
|
|
162
|
+
// Returns: OnlineAppointmentTimeSlot[]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Customers Resource
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
// Search customers by phone number
|
|
169
|
+
const customers = await client.customers.searchByPhoneNumber("+60123456789");
|
|
170
|
+
// Returns: Customer[]
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Error Handling
|
|
174
|
+
|
|
175
|
+
The SDK provides specific error classes for different failure scenarios:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import {
|
|
179
|
+
WessError,
|
|
180
|
+
WessAuthenticationError,
|
|
181
|
+
WessNotFoundError,
|
|
182
|
+
WessValidationError,
|
|
183
|
+
WessNetworkError,
|
|
184
|
+
WessTimeoutError,
|
|
185
|
+
} from "@voltade/wess-sdk";
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
const branch = await client.branches.get(99999);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (error instanceof WessAuthenticationError) {
|
|
191
|
+
// 401 - Invalid or expired token
|
|
192
|
+
console.error("Please check your bearer token");
|
|
193
|
+
} else if (error instanceof WessNotFoundError) {
|
|
194
|
+
// 404 - Resource not found
|
|
195
|
+
console.error("Branch not found");
|
|
196
|
+
} else if (error instanceof WessValidationError) {
|
|
197
|
+
// 422 - Validation failed
|
|
198
|
+
console.error("Validation errors:", error.errors);
|
|
199
|
+
} else if (error instanceof WessNetworkError) {
|
|
200
|
+
// Network connectivity issues
|
|
201
|
+
console.error("Network error:", error.message);
|
|
202
|
+
} else if (error instanceof WessTimeoutError) {
|
|
203
|
+
// Request timeout
|
|
204
|
+
console.error("Request timed out");
|
|
205
|
+
} else if (error instanceof WessError) {
|
|
206
|
+
// Generic API error
|
|
207
|
+
console.error(`API error (${error.statusCode}):`, error.message);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Available Error Classes
|
|
213
|
+
|
|
214
|
+
| Error Class | Status Code | Description |
|
|
215
|
+
| ------------------------- | ----------- | ------------------------------ |
|
|
216
|
+
| `WessError` | Any | Base error class |
|
|
217
|
+
| `WessAuthenticationError` | 401 | Invalid or missing credentials |
|
|
218
|
+
| `WessNotFoundError` | 404 | Resource not found |
|
|
219
|
+
| `WessValidationError` | 422 | Request validation failed |
|
|
220
|
+
| `WessNetworkError` | - | Network connectivity issues |
|
|
221
|
+
| `WessTimeoutError` | - | Request timeout |
|
|
222
|
+
|
|
223
|
+
## TypeScript Support
|
|
224
|
+
|
|
225
|
+
All types are exported and fully documented:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
import type {
|
|
229
|
+
// Config
|
|
230
|
+
WessClientConfig,
|
|
231
|
+
RequestOptions,
|
|
232
|
+
|
|
233
|
+
// User
|
|
234
|
+
User,
|
|
235
|
+
UserResponse,
|
|
236
|
+
|
|
237
|
+
// Branch
|
|
238
|
+
Branch,
|
|
239
|
+
|
|
240
|
+
// Customer
|
|
241
|
+
Customer,
|
|
242
|
+
|
|
243
|
+
// Online Appointments
|
|
244
|
+
OnlineAppointmentService,
|
|
245
|
+
OnlineAppointmentEmployee,
|
|
246
|
+
OnlineAppointmentTimeSlot,
|
|
247
|
+
ServiceDetails,
|
|
248
|
+
EmployeeProduct,
|
|
249
|
+
GetEmployeesParams,
|
|
250
|
+
GetTimeSlotsParams,
|
|
251
|
+
|
|
252
|
+
// Errors
|
|
253
|
+
ApiErrorResponse,
|
|
254
|
+
ValidationErrorResponse,
|
|
255
|
+
} from "@voltade/wess-sdk";
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Advanced Usage
|
|
259
|
+
|
|
260
|
+
### Direct Resource Access
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { WessClient, BranchesResource } from "@voltade/wess-sdk";
|
|
264
|
+
|
|
265
|
+
const client = new WessClient({ baseUrl: "...", bearerToken: "..." });
|
|
266
|
+
|
|
267
|
+
// Access resources directly
|
|
268
|
+
const branches: BranchesResource = client.branches;
|
|
269
|
+
const allBranches = await branches.list();
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Custom HTTP Client
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
const httpClient = client.getHttpClient();
|
|
276
|
+
|
|
277
|
+
// Make custom requests
|
|
278
|
+
const response = await httpClient.get("/custom-endpoint", {
|
|
279
|
+
params: { key: "value" },
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Requirements
|
|
284
|
+
|
|
285
|
+
- Node.js >= 18.0.0
|
|
286
|
+
- TypeScript >= 5.0.0
|
|
287
|
+
|
|
288
|
+
## Architecture
|
|
289
|
+
|
|
290
|
+
```
|
|
291
|
+
@voltade/wess-sdk/
|
|
292
|
+
├── index.ts # Main entry point & WessClient class
|
|
293
|
+
├── client.ts # HTTP client wrapper
|
|
294
|
+
├── types.ts # TypeScript type definitions
|
|
295
|
+
├── errors.ts # Error classes
|
|
296
|
+
├── resources/
|
|
297
|
+
│ ├── index.ts # Resource exports
|
|
298
|
+
│ ├── user.ts # User resource
|
|
299
|
+
│ ├── branches.ts # Branches resource
|
|
300
|
+
│ └── customers.ts # Customers resource
|
|
301
|
+
└── utils/
|
|
302
|
+
└── pagination.ts # Pagination utilities (if needed)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## Publishing (Maintainers Only)
|
|
306
|
+
|
|
307
|
+
This package is published exclusively to GitHub Packages. To publish a new version:
|
|
308
|
+
|
|
309
|
+
### 1. Create a GitHub Personal Access Token
|
|
310
|
+
|
|
311
|
+
- Go to https://github.com/settings/tokens/new
|
|
312
|
+
- Name: `npm-publish-token`
|
|
313
|
+
- Select scopes: `write:packages`, `read:packages`, and `repo`
|
|
314
|
+
- Generate and copy the token
|
|
315
|
+
|
|
316
|
+
### 2. Authenticate with GitHub Packages
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
npm login --registry=https://npm.pkg.github.com
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
- **Username:** `voltade`
|
|
323
|
+
- **Password:** Your personal access token
|
|
324
|
+
- **Email:** Your GitHub email
|
|
325
|
+
|
|
326
|
+
### 3. Publish
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
# Bump version in package.json first
|
|
330
|
+
npm version patch # or minor, or major
|
|
331
|
+
|
|
332
|
+
# Publish to GitHub Packages
|
|
333
|
+
npm publish
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
> **Note:** This package is NOT published to npm, only to GitHub Packages.
|
|
337
|
+
|
|
338
|
+
## Contributing
|
|
339
|
+
|
|
340
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
341
|
+
|
|
342
|
+
## License
|
|
343
|
+
|
|
344
|
+
MIT © Voltade
|
|
345
|
+
|
|
346
|
+
## Support
|
|
347
|
+
|
|
348
|
+
For issues and questions, please file an issue on [GitHub](https://github.com/voltade/wess-sdk/issues).
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
Made with ❤️ by Voltade
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WESS HTTP Client
|
|
3
|
+
* Core HTTP wrapper with built-in error handling
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestOptions, WessClientConfig } from "./types.js";
|
|
6
|
+
export declare class HttpClient {
|
|
7
|
+
private readonly baseUrl;
|
|
8
|
+
private readonly bearerToken;
|
|
9
|
+
private readonly timeout;
|
|
10
|
+
private readonly defaultHeaders;
|
|
11
|
+
constructor(config: WessClientConfig);
|
|
12
|
+
private buildUrl;
|
|
13
|
+
private getHeaders;
|
|
14
|
+
private handleResponse;
|
|
15
|
+
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
16
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
17
|
+
put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
18
|
+
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAWnE,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAyB;gBAE5C,MAAM,EAAE,gBAAgB;IAuBpC,OAAO,CAAC,QAAQ;IA2BhB,OAAO,CAAC,UAAU;YAUJ,cAAc;IA+BtB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;IAkC9D,IAAI,CAAC,CAAC,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC;IAmCP,GAAG,CAAC,CAAC,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC,CAAC,CAAC;IAmCP,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;CAiCxE"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WESS HTTP Client
|
|
3
|
+
* Core HTTP wrapper with built-in error handling
|
|
4
|
+
*/
|
|
5
|
+
import { WessError, WessAuthenticationError, WessNotFoundError, WessValidationError, WessNetworkError, WessTimeoutError, WessRateLimitError, } from "./errors.js";
|
|
6
|
+
export class HttpClient {
|
|
7
|
+
baseUrl;
|
|
8
|
+
bearerToken;
|
|
9
|
+
timeout;
|
|
10
|
+
defaultHeaders;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.baseUrl = config.baseUrl;
|
|
13
|
+
this.bearerToken = config.bearerToken;
|
|
14
|
+
this.timeout = config.timeout ?? 30000;
|
|
15
|
+
this.defaultHeaders = {
|
|
16
|
+
Accept: "application/json",
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
...config.headers,
|
|
19
|
+
};
|
|
20
|
+
if (!this.baseUrl) {
|
|
21
|
+
throw new WessError("Base URL is required. Set WESS_BASE_URL env var or pass baseUrl in config.");
|
|
22
|
+
}
|
|
23
|
+
if (!this.bearerToken) {
|
|
24
|
+
throw new WessError("Bearer token is required. Set WESS_BEARER_TOKEN env var or pass bearerToken in config.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
buildUrl(path, params) {
|
|
28
|
+
// Ensure baseUrl ends with / and path doesn't start with /
|
|
29
|
+
const base = this.baseUrl.endsWith("/") ? this.baseUrl : this.baseUrl + "/";
|
|
30
|
+
const cleanPath = path.startsWith("/") ? path.slice(1) : path;
|
|
31
|
+
const url = new URL(cleanPath, base);
|
|
32
|
+
if (params) {
|
|
33
|
+
for (const [key, value] of Object.entries(params)) {
|
|
34
|
+
if (value === undefined || value === null)
|
|
35
|
+
continue;
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
// Handle array params like product_ids[]
|
|
38
|
+
for (const item of value) {
|
|
39
|
+
url.searchParams.append(`${key}[]`, String(item));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
url.searchParams.set(key, String(value));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return url.toString();
|
|
48
|
+
}
|
|
49
|
+
getHeaders(customHeaders) {
|
|
50
|
+
return {
|
|
51
|
+
...this.defaultHeaders,
|
|
52
|
+
Authorization: `Bearer ${this.bearerToken}`,
|
|
53
|
+
...customHeaders,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async handleResponse(response) {
|
|
57
|
+
if (response.ok) {
|
|
58
|
+
const text = await response.text();
|
|
59
|
+
if (!text)
|
|
60
|
+
return {};
|
|
61
|
+
return JSON.parse(text);
|
|
62
|
+
}
|
|
63
|
+
let errorData = {};
|
|
64
|
+
try {
|
|
65
|
+
errorData = await response.json();
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// Response body might not be JSON
|
|
69
|
+
}
|
|
70
|
+
const message = errorData.message || `HTTP ${response.status}: ${response.statusText}`;
|
|
71
|
+
switch (response.status) {
|
|
72
|
+
case 401:
|
|
73
|
+
throw new WessAuthenticationError(message);
|
|
74
|
+
case 404:
|
|
75
|
+
throw new WessNotFoundError(message);
|
|
76
|
+
case 422:
|
|
77
|
+
throw new WessValidationError(message, errorData.errors);
|
|
78
|
+
case 429:
|
|
79
|
+
throw new WessRateLimitError(message);
|
|
80
|
+
default:
|
|
81
|
+
throw new WessError(message, response.status, errorData);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async get(path, options = {}) {
|
|
85
|
+
const url = this.buildUrl(path, options.params);
|
|
86
|
+
const controller = new AbortController();
|
|
87
|
+
const timeoutId = setTimeout(() => controller.abort(), options.timeout ?? this.timeout);
|
|
88
|
+
try {
|
|
89
|
+
const response = await fetch(url, {
|
|
90
|
+
method: "GET",
|
|
91
|
+
headers: this.getHeaders(options.headers),
|
|
92
|
+
signal: controller.signal,
|
|
93
|
+
});
|
|
94
|
+
return this.handleResponse(response);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (error instanceof WessError)
|
|
98
|
+
throw error;
|
|
99
|
+
if (error instanceof Error) {
|
|
100
|
+
if (error.name === "AbortError") {
|
|
101
|
+
throw new WessTimeoutError(`Request timeout after ${options.timeout ?? this.timeout}ms`);
|
|
102
|
+
}
|
|
103
|
+
throw new WessNetworkError(error.message);
|
|
104
|
+
}
|
|
105
|
+
throw new WessNetworkError("Unknown network error");
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
clearTimeout(timeoutId);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async post(path, body, options = {}) {
|
|
112
|
+
const url = this.buildUrl(path, options.params);
|
|
113
|
+
const controller = new AbortController();
|
|
114
|
+
const timeoutId = setTimeout(() => controller.abort(), options.timeout ?? this.timeout);
|
|
115
|
+
try {
|
|
116
|
+
const response = await fetch(url, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: this.getHeaders(options.headers),
|
|
119
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
120
|
+
signal: controller.signal,
|
|
121
|
+
});
|
|
122
|
+
return this.handleResponse(response);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (error instanceof WessError)
|
|
126
|
+
throw error;
|
|
127
|
+
if (error instanceof Error) {
|
|
128
|
+
if (error.name === "AbortError") {
|
|
129
|
+
throw new WessTimeoutError(`Request timeout after ${options.timeout ?? this.timeout}ms`);
|
|
130
|
+
}
|
|
131
|
+
throw new WessNetworkError(error.message);
|
|
132
|
+
}
|
|
133
|
+
throw new WessNetworkError("Unknown network error");
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
clearTimeout(timeoutId);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async put(path, body, options = {}) {
|
|
140
|
+
const url = this.buildUrl(path, options.params);
|
|
141
|
+
const controller = new AbortController();
|
|
142
|
+
const timeoutId = setTimeout(() => controller.abort(), options.timeout ?? this.timeout);
|
|
143
|
+
try {
|
|
144
|
+
const response = await fetch(url, {
|
|
145
|
+
method: "PUT",
|
|
146
|
+
headers: this.getHeaders(options.headers),
|
|
147
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
148
|
+
signal: controller.signal,
|
|
149
|
+
});
|
|
150
|
+
return this.handleResponse(response);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (error instanceof WessError)
|
|
154
|
+
throw error;
|
|
155
|
+
if (error instanceof Error) {
|
|
156
|
+
if (error.name === "AbortError") {
|
|
157
|
+
throw new WessTimeoutError(`Request timeout after ${options.timeout ?? this.timeout}ms`);
|
|
158
|
+
}
|
|
159
|
+
throw new WessNetworkError(error.message);
|
|
160
|
+
}
|
|
161
|
+
throw new WessNetworkError("Unknown network error");
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
clearTimeout(timeoutId);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async delete(path, options = {}) {
|
|
168
|
+
const url = this.buildUrl(path, options.params);
|
|
169
|
+
const controller = new AbortController();
|
|
170
|
+
const timeoutId = setTimeout(() => controller.abort(), options.timeout ?? this.timeout);
|
|
171
|
+
try {
|
|
172
|
+
const response = await fetch(url, {
|
|
173
|
+
method: "DELETE",
|
|
174
|
+
headers: this.getHeaders(options.headers),
|
|
175
|
+
signal: controller.signal,
|
|
176
|
+
});
|
|
177
|
+
return this.handleResponse(response);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error instanceof WessError)
|
|
181
|
+
throw error;
|
|
182
|
+
if (error instanceof Error) {
|
|
183
|
+
if (error.name === "AbortError") {
|
|
184
|
+
throw new WessTimeoutError(`Request timeout after ${options.timeout ?? this.timeout}ms`);
|
|
185
|
+
}
|
|
186
|
+
throw new WessNetworkError(error.message);
|
|
187
|
+
}
|
|
188
|
+
throw new WessNetworkError("Unknown network error");
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
clearTimeout(timeoutId);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,SAAS,EACT,uBAAuB,EACvB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,MAAM,OAAO,UAAU;IACJ,OAAO,CAAS;IAChB,WAAW,CAAS;IACpB,OAAO,CAAS;IAChB,cAAc,CAAyB;IAExD,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,KAAK,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG;YACpB,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;YAClC,GAAG,MAAM,CAAC,OAAO;SAClB,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,SAAS,CACjB,4EAA4E,CAC7E,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,IAAI,C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AAC;QACzC,MAAM,SAAS,GAAG,UAAU,CAC1B,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EACxB,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAChC,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAChC,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC;gBACzC,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,cAAc,CAAI,QAAQ,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,SAAS;gBAAE,MAAM,KAAK,CAAC;YAE5C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;gBAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAChC,MAAM,IAAI,gBAAgB,CACxB,yBAAyB,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,CAC7D,CAAC;gBACJ,CAAC;gBACD,MAAM,IAAI,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC5C,CAAC;YAED,MAAM,IAAI,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;QACtD,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,SAAS,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WESS SDK Error Classes
|
|
3
|
+
*/
|
|
4
|
+
export declare class WessError extends Error {
|
|
5
|
+
readonly statusCode?: number | undefined;
|
|
6
|
+
readonly response?: unknown | undefined;
|
|
7
|
+
constructor(message: string, statusCode?: number | undefined, response?: unknown | undefined);
|
|
8
|
+
}
|
|
9
|
+
export declare class WessAuthenticationError extends WessError {
|
|
10
|
+
constructor(message?: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class WessNotFoundError extends WessError {
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class WessValidationError extends WessError {
|
|
16
|
+
readonly errors: Record<string, string[]>;
|
|
17
|
+
constructor(message: string, errors?: Record<string, string[]>);
|
|
18
|
+
}
|
|
19
|
+
export declare class WessNetworkError extends WessError {
|
|
20
|
+
constructor(message?: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class WessTimeoutError extends WessError {
|
|
23
|
+
constructor(message?: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class WessRateLimitError extends WessError {
|
|
26
|
+
constructor(message?: string);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qBAAa,SAAU,SAAQ,KAAK;aAGhB,UAAU,CAAC,EAAE,MAAM;aACnB,QAAQ,CAAC,EAAE,OAAO;gBAFlC,OAAO,EAAE,MAAM,EACC,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,QAAQ,CAAC,EAAE,OAAO,YAAA;CAMrC;AAED,qBAAa,uBAAwB,SAAQ,SAAS;gBACxC,OAAO,SAAoB;CAKxC;AAED,qBAAa,iBAAkB,SAAQ,SAAS;gBAClC,OAAO,SAAuB;CAK3C;AAED,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,SAAgB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBAErC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM;CAMnE;AAED,qBAAa,gBAAiB,SAAQ,SAAS;gBACjC,OAAO,SAA2B;CAK/C;AAED,qBAAa,gBAAiB,SAAQ,SAAS;gBACjC,OAAO,SAAoB;CAKxC;AAED,qBAAa,kBAAmB,SAAQ,SAAS;gBACnC,OAAO,SAAsB;CAK1C"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WESS SDK Error Classes
|
|
3
|
+
*/
|
|
4
|
+
export class WessError extends Error {
|
|
5
|
+
statusCode;
|
|
6
|
+
response;
|
|
7
|
+
constructor(message, statusCode, response) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.statusCode = statusCode;
|
|
10
|
+
this.response = response;
|
|
11
|
+
this.name = "WessError";
|
|
12
|
+
Object.setPrototypeOf(this, WessError.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class WessAuthenticationError extends WessError {
|
|
16
|
+
constructor(message = "Unauthenticated") {
|
|
17
|
+
super(message, 401);
|
|
18
|
+
this.name = "WessAuthenticationError";
|
|
19
|
+
Object.setPrototypeOf(this, WessAuthenticationError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class WessNotFoundError extends WessError {
|
|
23
|
+
constructor(message = "Resource not found") {
|
|
24
|
+
super(message, 404);
|
|
25
|
+
this.name = "WessNotFoundError";
|
|
26
|
+
Object.setPrototypeOf(this, WessNotFoundError.prototype);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class WessValidationError extends WessError {
|
|
30
|
+
errors;
|
|
31
|
+
constructor(message, errors = {}) {
|
|
32
|
+
super(message, 422);
|
|
33
|
+
this.name = "WessValidationError";
|
|
34
|
+
this.errors = errors;
|
|
35
|
+
Object.setPrototypeOf(this, WessValidationError.prototype);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export class WessNetworkError extends WessError {
|
|
39
|
+
constructor(message = "Network error occurred") {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = "WessNetworkError";
|
|
42
|
+
Object.setPrototypeOf(this, WessNetworkError.prototype);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export class WessTimeoutError extends WessError {
|
|
46
|
+
constructor(message = "Request timeout") {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = "WessTimeoutError";
|
|
49
|
+
Object.setPrototypeOf(this, WessTimeoutError.prototype);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class WessRateLimitError extends WessError {
|
|
53
|
+
constructor(message = "Too many requests") {
|
|
54
|
+
super(message, 429);
|
|
55
|
+
this.name = "WessRateLimitError";
|
|
56
|
+
Object.setPrototypeOf(this, WessRateLimitError.prototype);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAGhB;IACA;IAHlB,YACE,OAAe,EACC,UAAmB,EACnB,QAAkB;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,eAAU,GAAV,UAAU,CAAS;QACnB,aAAQ,GAAR,QAAQ,CAAU;QAGlC,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;CACF;AAED,MAAM,OAAO,uBAAwB,SAAQ,SAAS;IACpD,YAAY,OAAO,GAAG,iBAAiB;QACrC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,uBAAuB,CAAC,SAAS,CAAC,CAAC;IACjE,CAAC;CACF;AAED,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,YAAY,OAAO,GAAG,oBAAoB;QACxC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC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