doboxa-js 1.0.1 → 1.0.3
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 +79 -72
- package/dist/chunk-CGJD4ZO5.mjs +107 -0
- package/dist/chunk-CGJD4ZO5.mjs.map +1 -0
- package/dist/chunk-WGEOQ35B.mjs +3097 -0
- package/dist/chunk-WGEOQ35B.mjs.map +1 -0
- package/dist/client-BfIS6ja2.d.mts +2759 -0
- package/dist/client-BfIS6ja2.d.ts +2759 -0
- package/dist/client.d.mts +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +2066 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +8 -0
- package/dist/client.mjs.map +1 -0
- package/dist/errors-CtijMwu-.d.mts +161 -0
- package/dist/errors-CtijMwu-.d.ts +161 -0
- package/dist/errors.d.mts +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +91 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +15 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.d.mts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +3744 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +719 -0
- package/dist/index.mjs.map +1 -0
- package/dist/models.d.mts +2 -0
- package/dist/models.d.ts +2 -0
- package/dist/models.js +1 -0
- package/dist/models.js.map +1 -0
- package/dist/models.mjs +1 -0
- package/dist/models.mjs.map +1 -0
- package/package.json +8 -1
- package/api-doc.yaml +0 -2013
- package/openapi-generator-config.yaml +0 -15
- package/openapitools.json +0 -7
- package/src/client.ts +0 -99
- package/src/errors.ts +0 -90
- package/src/http/client.ts +0 -156
- package/src/index.ts +0 -31
- package/src/models.ts +0 -0
- package/src/resources/authentication.ts +0 -73
- package/src/resources/clients.ts +0 -32
- package/src/resources/discountCodes.ts +0 -32
- package/src/resources/invoices.ts +0 -46
- package/src/resources/orderComments.ts +0 -38
- package/src/resources/orderStatusChanges.ts +0 -38
- package/src/resources/orders.ts +0 -123
- package/src/resources/trackingNumbers.ts +0 -38
- package/src/resources/users.ts +0 -28
- package/src/types/index.ts +0 -59
- package/src/utils/config.ts +0 -10
- package/src/utils/tokenManager.ts +0 -68
- package/tsconfig.json +0 -12
- package/tsup.config.ts +0 -30
package/README.md
CHANGED
|
@@ -24,11 +24,11 @@ yarn add doboxa-js
|
|
|
24
24
|
### Basic Setup
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
import Doboxa from
|
|
27
|
+
import Doboxa from "doboxa-js";
|
|
28
28
|
|
|
29
29
|
// Initialize the client
|
|
30
30
|
const doboxa = new Doboxa({
|
|
31
|
-
baseURL:
|
|
31
|
+
baseURL: "https://pl.doboxa.biz", // Optional: defaults to DOBOXA_API_URL env var or http://localhost
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -39,20 +39,20 @@ The library supports two authentication methods:
|
|
|
39
39
|
#### Method 1: Login with Username and Password
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
-
import Doboxa from
|
|
42
|
+
import Doboxa from "doboxa-js";
|
|
43
43
|
|
|
44
44
|
const doboxa = new Doboxa({
|
|
45
|
-
baseURL:
|
|
45
|
+
baseURL: "https://pl.doboxa.biz",
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
// Login with your Doboxa account credentials
|
|
49
49
|
const authResponse = await doboxa.authentication.login({
|
|
50
|
-
username:
|
|
51
|
-
password:
|
|
50
|
+
username: "your-username",
|
|
51
|
+
password: "your-password",
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
console.log(
|
|
55
|
-
console.log(
|
|
54
|
+
console.log("Access token:", authResponse.token);
|
|
55
|
+
console.log("Refresh token:", authResponse.refresh_token);
|
|
56
56
|
|
|
57
57
|
// Tokens are automatically stored and used for subsequent requests
|
|
58
58
|
```
|
|
@@ -62,11 +62,11 @@ console.log('Refresh token:', authResponse.refresh_token);
|
|
|
62
62
|
If you already have an access token:
|
|
63
63
|
|
|
64
64
|
```typescript
|
|
65
|
-
import Doboxa from
|
|
65
|
+
import Doboxa from "doboxa-js";
|
|
66
66
|
|
|
67
67
|
const doboxa = new Doboxa({
|
|
68
|
-
apiKey:
|
|
69
|
-
baseURL:
|
|
68
|
+
apiKey: "your-access-token",
|
|
69
|
+
baseURL: "https://pl.doboxa.biz",
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
// You can now make API calls immediately
|
|
@@ -82,48 +82,48 @@ const doboxa = new Doboxa({
|
|
|
82
82
|
|
|
83
83
|
```typescript
|
|
84
84
|
const order = await doboxa.orders.create({
|
|
85
|
-
external_id:
|
|
85
|
+
external_id: "ORDER-12345",
|
|
86
86
|
deliver_address: {
|
|
87
|
-
first_name:
|
|
88
|
-
last_name:
|
|
89
|
-
phone_number:
|
|
90
|
-
email:
|
|
91
|
-
address1:
|
|
92
|
-
city:
|
|
93
|
-
post_code:
|
|
94
|
-
country_iso:
|
|
87
|
+
first_name: "John",
|
|
88
|
+
last_name: "Doe",
|
|
89
|
+
phone_number: "+48123456789",
|
|
90
|
+
email: "john.doe@example.com",
|
|
91
|
+
address1: "123 Main St",
|
|
92
|
+
city: "Warsaw",
|
|
93
|
+
post_code: "00-001",
|
|
94
|
+
country_iso: "PL",
|
|
95
95
|
},
|
|
96
96
|
items: [
|
|
97
97
|
{
|
|
98
|
-
id:
|
|
99
|
-
name:
|
|
98
|
+
id: "SKU-123",
|
|
99
|
+
name: "Product Name",
|
|
100
100
|
qty: 2,
|
|
101
101
|
item_price: 9999, // Price in cents (99.99)
|
|
102
102
|
},
|
|
103
103
|
],
|
|
104
104
|
order_time: new Date().toISOString(),
|
|
105
|
-
order_channel:
|
|
106
|
-
currency:
|
|
105
|
+
order_channel: "channel_id",
|
|
106
|
+
currency: "PLN",
|
|
107
107
|
});
|
|
108
108
|
```
|
|
109
109
|
|
|
110
110
|
#### Get Order Status
|
|
111
111
|
|
|
112
112
|
```typescript
|
|
113
|
-
const status = await doboxa.orders.getStatus(
|
|
114
|
-
console.log(
|
|
115
|
-
console.log(
|
|
113
|
+
const status = await doboxa.orders.getStatus("order-id-123");
|
|
114
|
+
console.log("Order status:", status.status);
|
|
115
|
+
console.log("Item statuses:", status.item_status);
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
#### Update Order Status
|
|
119
119
|
|
|
120
120
|
```typescript
|
|
121
|
-
await doboxa.orders.updateStatus(
|
|
122
|
-
status:
|
|
121
|
+
await doboxa.orders.updateStatus("order-id-123", {
|
|
122
|
+
status: "paid",
|
|
123
123
|
item_status: [
|
|
124
124
|
{
|
|
125
|
-
doboxa_item_id:
|
|
126
|
-
status:
|
|
125
|
+
doboxa_item_id: "item-123",
|
|
126
|
+
status: "paid",
|
|
127
127
|
},
|
|
128
128
|
],
|
|
129
129
|
});
|
|
@@ -132,17 +132,17 @@ await doboxa.orders.updateStatus('order-id-123', {
|
|
|
132
132
|
#### Get Order Comments
|
|
133
133
|
|
|
134
134
|
```typescript
|
|
135
|
-
const comments = await doboxa.orders.getComments(
|
|
136
|
-
console.log(
|
|
135
|
+
const comments = await doboxa.orders.getComments("order-id-123");
|
|
136
|
+
console.log("Comments:", comments.items);
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
#### Create Order Comment
|
|
140
140
|
|
|
141
141
|
```typescript
|
|
142
|
-
const comment = await doboxa.orders.createComment(
|
|
143
|
-
author_type:
|
|
144
|
-
author_email:
|
|
145
|
-
content:
|
|
142
|
+
const comment = await doboxa.orders.createComment("order-id-123", {
|
|
143
|
+
author_type: "client",
|
|
144
|
+
author_email: "client@example.com",
|
|
145
|
+
content: "This is a comment",
|
|
146
146
|
created_at: new Date().toISOString(),
|
|
147
147
|
});
|
|
148
148
|
```
|
|
@@ -150,25 +150,25 @@ const comment = await doboxa.orders.createComment('order-id-123', {
|
|
|
150
150
|
#### Get Order Invoices
|
|
151
151
|
|
|
152
152
|
```typescript
|
|
153
|
-
const invoices = await doboxa.orders.getInvoices(
|
|
154
|
-
console.log(
|
|
153
|
+
const invoices = await doboxa.orders.getInvoices("order-id-123");
|
|
154
|
+
console.log("Invoices:", invoices.items);
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
#### Get Order Tracking Numbers
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
|
-
const tracking = await doboxa.orders.getTrackingNumbers(
|
|
161
|
-
console.log(
|
|
160
|
+
const tracking = await doboxa.orders.getTrackingNumbers("order-id-123");
|
|
161
|
+
console.log("Tracking numbers:", tracking.items);
|
|
162
162
|
```
|
|
163
163
|
|
|
164
164
|
#### Cancel an Order
|
|
165
165
|
|
|
166
166
|
```typescript
|
|
167
167
|
const result = await doboxa.orders.cancel({
|
|
168
|
-
order_id:
|
|
168
|
+
order_id: "order-id-123",
|
|
169
169
|
});
|
|
170
|
-
console.log(
|
|
171
|
-
console.log(
|
|
170
|
+
console.log("Cancelled:", result.cancelled);
|
|
171
|
+
console.log("Details:", result.details);
|
|
172
172
|
```
|
|
173
173
|
|
|
174
174
|
### Invoices
|
|
@@ -178,20 +178,20 @@ console.log('Details:', result.details);
|
|
|
178
178
|
```typescript
|
|
179
179
|
const invoices = await doboxa.invoices.list({
|
|
180
180
|
page: 1,
|
|
181
|
-
from:
|
|
182
|
-
to:
|
|
181
|
+
from: "2024-01-01T00:00:00Z", // Optional: ISO date-time string
|
|
182
|
+
to: "2024-12-31T23:59:59Z", // Optional: ISO date-time string
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
console.log(
|
|
186
|
-
console.log(
|
|
185
|
+
console.log("Invoices:", invoices.items);
|
|
186
|
+
console.log("Next page:", invoices.next_page);
|
|
187
187
|
```
|
|
188
188
|
|
|
189
189
|
#### Retrieve a Specific Invoice
|
|
190
190
|
|
|
191
191
|
```typescript
|
|
192
|
-
const invoice = await doboxa.invoices.retrieve(
|
|
193
|
-
console.log(
|
|
194
|
-
console.log(
|
|
192
|
+
const invoice = await doboxa.invoices.retrieve("invoice-id-123");
|
|
193
|
+
console.log("Invoice:", invoice);
|
|
194
|
+
console.log("PDF URL:", invoice.file);
|
|
195
195
|
```
|
|
196
196
|
|
|
197
197
|
### Clients
|
|
@@ -203,7 +203,7 @@ const clients = await doboxa.clients.list({
|
|
|
203
203
|
page: 1,
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
-
console.log(
|
|
206
|
+
console.log("Clients:", clients.items);
|
|
207
207
|
```
|
|
208
208
|
|
|
209
209
|
### Discount Codes
|
|
@@ -215,7 +215,7 @@ const discountCodes = await doboxa.discountCodes.list({
|
|
|
215
215
|
page: 1,
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
-
console.log(
|
|
218
|
+
console.log("Discount codes:", discountCodes.items);
|
|
219
219
|
```
|
|
220
220
|
|
|
221
221
|
### Tracking Numbers
|
|
@@ -225,11 +225,11 @@ console.log('Discount codes:', discountCodes.items);
|
|
|
225
225
|
```typescript
|
|
226
226
|
const trackingNumbers = await doboxa.trackingNumbers.list({
|
|
227
227
|
page: 1,
|
|
228
|
-
from:
|
|
229
|
-
to:
|
|
228
|
+
from: "2024-01-01T00:00:00Z",
|
|
229
|
+
to: "2024-12-31T23:59:59Z",
|
|
230
230
|
});
|
|
231
231
|
|
|
232
|
-
console.log(
|
|
232
|
+
console.log("Tracking numbers:", trackingNumbers.items);
|
|
233
233
|
```
|
|
234
234
|
|
|
235
235
|
### Order Comments
|
|
@@ -239,11 +239,11 @@ console.log('Tracking numbers:', trackingNumbers.items);
|
|
|
239
239
|
```typescript
|
|
240
240
|
const comments = await doboxa.orderComments.list({
|
|
241
241
|
page: 1,
|
|
242
|
-
from:
|
|
243
|
-
to:
|
|
242
|
+
from: "2024-01-01T00:00:00Z",
|
|
243
|
+
to: "2024-12-31T23:59:59Z",
|
|
244
244
|
});
|
|
245
245
|
|
|
246
|
-
console.log(
|
|
246
|
+
console.log("Comments:", comments.items);
|
|
247
247
|
```
|
|
248
248
|
|
|
249
249
|
### Order Status Changes
|
|
@@ -253,11 +253,11 @@ console.log('Comments:', comments.items);
|
|
|
253
253
|
```typescript
|
|
254
254
|
const statusChanges = await doboxa.orderStatusChanges.list({
|
|
255
255
|
page: 1,
|
|
256
|
-
from:
|
|
257
|
-
to:
|
|
256
|
+
from: "2024-01-01T00:00:00Z",
|
|
257
|
+
to: "2024-12-31T23:59:59Z",
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
-
console.log(
|
|
260
|
+
console.log("Status changes:", statusChanges.items);
|
|
261
261
|
```
|
|
262
262
|
|
|
263
263
|
### Users
|
|
@@ -266,7 +266,7 @@ console.log('Status changes:', statusChanges.items);
|
|
|
266
266
|
|
|
267
267
|
```typescript
|
|
268
268
|
const me = await doboxa.users.me();
|
|
269
|
-
console.log(
|
|
269
|
+
console.log("Current user:", me.username);
|
|
270
270
|
```
|
|
271
271
|
|
|
272
272
|
## Environment Variables
|
|
@@ -274,7 +274,7 @@ console.log('Current user:', me.username);
|
|
|
274
274
|
You can set the API base URL using an environment variable:
|
|
275
275
|
|
|
276
276
|
```bash
|
|
277
|
-
export DOBOXA_API_URL=https://
|
|
277
|
+
export DOBOXA_API_URL=https://pl.doboxa.biz
|
|
278
278
|
```
|
|
279
279
|
|
|
280
280
|
The library will use this value if no `baseURL` is provided in the configuration.
|
|
@@ -289,20 +289,20 @@ import {
|
|
|
289
289
|
DoboxaAPIError,
|
|
290
290
|
DoboxaAuthenticationError,
|
|
291
291
|
DoboxaValidationError,
|
|
292
|
-
} from
|
|
292
|
+
} from "doboxa-js";
|
|
293
293
|
|
|
294
294
|
try {
|
|
295
295
|
await doboxa.orders.create(orderData);
|
|
296
296
|
} catch (error) {
|
|
297
297
|
if (error instanceof DoboxaAuthenticationError) {
|
|
298
|
-
console.error(
|
|
298
|
+
console.error("Authentication failed:", error.message);
|
|
299
299
|
} else if (error instanceof DoboxaValidationError) {
|
|
300
|
-
console.error(
|
|
301
|
-
console.error(
|
|
300
|
+
console.error("Validation error:", error.message);
|
|
301
|
+
console.error("Invalid parameters:", error.invalidParameters);
|
|
302
302
|
} else if (error instanceof DoboxaAPIError) {
|
|
303
|
-
console.error(
|
|
303
|
+
console.error("API error:", error.statusCode, error.message);
|
|
304
304
|
} else {
|
|
305
|
-
console.error(
|
|
305
|
+
console.error("Unknown error:", error);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
```
|
|
@@ -318,7 +318,7 @@ import type {
|
|
|
318
318
|
OrderStatus,
|
|
319
319
|
PageOfInvoices,
|
|
320
320
|
// ... and many more
|
|
321
|
-
} from
|
|
321
|
+
} from "doboxa-js";
|
|
322
322
|
```
|
|
323
323
|
|
|
324
324
|
## API Reference
|
|
@@ -326,10 +326,12 @@ import type {
|
|
|
326
326
|
### Resources
|
|
327
327
|
|
|
328
328
|
- **Authentication**: `doboxa.authentication`
|
|
329
|
+
|
|
329
330
|
- `login(params)` - Login with username and password
|
|
330
331
|
- `refreshToken(refreshToken)` - Refresh access token
|
|
331
332
|
|
|
332
333
|
- **Orders**: `doboxa.orders`
|
|
334
|
+
|
|
333
335
|
- `create(params)` - Create an order
|
|
334
336
|
- `getStatus(orderId)` - Get order status
|
|
335
337
|
- `updateStatus(orderId, params)` - Update order status
|
|
@@ -340,22 +342,28 @@ import type {
|
|
|
340
342
|
- `cancel(params)` - Cancel an order
|
|
341
343
|
|
|
342
344
|
- **Invoices**: `doboxa.invoices`
|
|
345
|
+
|
|
343
346
|
- `list(params?)` - List invoices
|
|
344
347
|
- `retrieve(invoiceId)` - Get a specific invoice
|
|
345
348
|
|
|
346
349
|
- **Clients**: `doboxa.clients`
|
|
350
|
+
|
|
347
351
|
- `list(params?)` - List clients
|
|
348
352
|
|
|
349
353
|
- **Discount Codes**: `doboxa.discountCodes`
|
|
354
|
+
|
|
350
355
|
- `list(params?)` - List discount codes
|
|
351
356
|
|
|
352
357
|
- **Tracking Numbers**: `doboxa.trackingNumbers`
|
|
358
|
+
|
|
353
359
|
- `list(params?)` - List tracking numbers
|
|
354
360
|
|
|
355
361
|
- **Order Comments**: `doboxa.orderComments`
|
|
362
|
+
|
|
356
363
|
- `list(params?)` - List order comments
|
|
357
364
|
|
|
358
365
|
- **Order Status Changes**: `doboxa.orderStatusChanges`
|
|
366
|
+
|
|
359
367
|
- `list(params?)` - List order status changes
|
|
360
368
|
|
|
361
369
|
- **Users**: `doboxa.users`
|
|
@@ -368,4 +376,3 @@ ISC
|
|
|
368
376
|
## Support
|
|
369
377
|
|
|
370
378
|
For API access and support, please contact the Doboxa team at [doboxa.com](https://doboxa.com).
|
|
371
|
-
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/errors.ts
|
|
42
|
+
var DoboxaError = class _DoboxaError extends Error {
|
|
43
|
+
constructor(message) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.name = "DoboxaError";
|
|
46
|
+
Object.setPrototypeOf(this, _DoboxaError.prototype);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var DoboxaAPIError = class _DoboxaAPIError extends DoboxaError {
|
|
50
|
+
constructor(statusCode, message, body) {
|
|
51
|
+
super(message);
|
|
52
|
+
this.name = "DoboxaAPIError";
|
|
53
|
+
this.statusCode = statusCode;
|
|
54
|
+
if (body) {
|
|
55
|
+
if ("result_code" in body) {
|
|
56
|
+
this.code = body.result_code;
|
|
57
|
+
}
|
|
58
|
+
if ("error_message" in body) {
|
|
59
|
+
this.errorMessage = body.error_message || void 0;
|
|
60
|
+
}
|
|
61
|
+
if ("invalid_parameters" in body && body.invalid_parameters) {
|
|
62
|
+
this.invalidParameters = body.invalid_parameters.map((param) => ({
|
|
63
|
+
parameter: param.parameter,
|
|
64
|
+
error_cause: param.error_cause
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
Object.setPrototypeOf(this, _DoboxaAPIError.prototype);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var DoboxaAuthenticationError = class _DoboxaAuthenticationError extends DoboxaError {
|
|
72
|
+
constructor(message = "Authentication failed") {
|
|
73
|
+
super(message);
|
|
74
|
+
this.name = "DoboxaAuthenticationError";
|
|
75
|
+
Object.setPrototypeOf(this, _DoboxaAuthenticationError.prototype);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var DoboxaValidationError = class _DoboxaValidationError extends DoboxaAPIError {
|
|
79
|
+
constructor(statusCode, message, body) {
|
|
80
|
+
super(statusCode, message, body);
|
|
81
|
+
this.name = "DoboxaValidationError";
|
|
82
|
+
Object.setPrototypeOf(this, _DoboxaValidationError.prototype);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function parseErrorResponse(statusCode, body) {
|
|
86
|
+
if (typeof body === "object" && body !== null) {
|
|
87
|
+
if ("invalid_parameters" in body || "error_message" in body) {
|
|
88
|
+
return body;
|
|
89
|
+
}
|
|
90
|
+
if ("error_message" in body && "result_code" in body) {
|
|
91
|
+
return body;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
__spreadValues,
|
|
99
|
+
__spreadProps,
|
|
100
|
+
__async,
|
|
101
|
+
DoboxaError,
|
|
102
|
+
DoboxaAPIError,
|
|
103
|
+
DoboxaAuthenticationError,
|
|
104
|
+
DoboxaValidationError,
|
|
105
|
+
parseErrorResponse
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=chunk-CGJD4ZO5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts"],"sourcesContent":["import type { InvalidRequestDataResponse, ServerErrorResponse } from './types/generated/src/models';\n\n/**\n * Base error class for all Doboxa errors\n */\nexport class DoboxaError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'DoboxaError';\n Object.setPrototypeOf(this, DoboxaError.prototype);\n }\n}\n\n/**\n * Error thrown when API returns an error response\n */\nexport class DoboxaAPIError extends DoboxaError {\n public readonly statusCode: number;\n public readonly code?: number;\n public readonly errorMessage?: string;\n public readonly invalidParameters?: Array<{ parameter: string; error_cause: string }>;\n\n constructor(\n statusCode: number,\n message: string,\n body?: InvalidRequestDataResponse | ServerErrorResponse\n ) {\n super(message);\n this.name = 'DoboxaAPIError';\n this.statusCode = statusCode;\n\n if (body) {\n if ('result_code' in body) {\n this.code = body.result_code;\n }\n if ('error_message' in body) {\n this.errorMessage = body.error_message || undefined;\n }\n if ('invalid_parameters' in body && body.invalid_parameters) {\n this.invalidParameters = body.invalid_parameters.map((param) => ({\n parameter: param.parameter,\n error_cause: param.error_cause,\n }));\n }\n }\n\n Object.setPrototypeOf(this, DoboxaAPIError.prototype);\n }\n}\n\n/**\n * Error thrown when authentication fails\n */\nexport class DoboxaAuthenticationError extends DoboxaError {\n constructor(message: string = 'Authentication failed') {\n super(message);\n this.name = 'DoboxaAuthenticationError';\n Object.setPrototypeOf(this, DoboxaAuthenticationError.prototype);\n }\n}\n\n/**\n * Error thrown when request validation fails\n */\nexport class DoboxaValidationError extends DoboxaAPIError {\n constructor(statusCode: number, message: string, body?: InvalidRequestDataResponse) {\n super(statusCode, message, body);\n this.name = 'DoboxaValidationError';\n Object.setPrototypeOf(this, DoboxaValidationError.prototype);\n }\n}\n\n/**\n * Parse error response from API\n */\nexport function parseErrorResponse(\n statusCode: number,\n body: unknown\n): InvalidRequestDataResponse | ServerErrorResponse | undefined {\n if (typeof body === 'object' && body !== null) {\n if ('invalid_parameters' in body || 'error_message' in body) {\n return body as InvalidRequestDataResponse;\n }\n if ('error_message' in body && 'result_code' in body) {\n return body as ServerErrorResponse;\n }\n }\n return undefined;\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,IAAM,cAAN,MAAM,qBAAoB,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,aAAY,SAAS;AAAA,EACnD;AACF;AAKO,IAAM,iBAAN,MAAM,wBAAuB,YAAY;AAAA,EAM9C,YACE,YACA,SACA,MACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAElB,QAAI,MAAM;AACR,UAAI,iBAAiB,MAAM;AACzB,aAAK,OAAO,KAAK;AAAA,MACnB;AACA,UAAI,mBAAmB,MAAM;AAC3B,aAAK,eAAe,KAAK,iBAAiB;AAAA,MAC5C;AACA,UAAI,wBAAwB,QAAQ,KAAK,oBAAoB;AAC3D,aAAK,oBAAoB,KAAK,mBAAmB,IAAI,CAAC,WAAW;AAAA,UAC/D,WAAW,MAAM;AAAA,UACjB,aAAa,MAAM;AAAA,QACrB,EAAE;AAAA,MACJ;AAAA,IACF;AAEA,WAAO,eAAe,MAAM,gBAAe,SAAS;AAAA,EACtD;AACF;AAKO,IAAM,4BAAN,MAAM,mCAAkC,YAAY;AAAA,EACzD,YAAY,UAAkB,yBAAyB;AACrD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,2BAA0B,SAAS;AAAA,EACjE;AACF;AAKO,IAAM,wBAAN,MAAM,+BAA8B,eAAe;AAAA,EACxD,YAAY,YAAoB,SAAiB,MAAmC;AAClF,UAAM,YAAY,SAAS,IAAI;AAC/B,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,uBAAsB,SAAS;AAAA,EAC7D;AACF;AAKO,SAAS,mBACd,YACA,MAC8D;AAC9D,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;AAC7C,QAAI,wBAAwB,QAAQ,mBAAmB,MAAM;AAC3D,aAAO;AAAA,IACT;AACA,QAAI,mBAAmB,QAAQ,iBAAiB,MAAM;AACpD,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|