doboxa-js 1.0.2 → 1.1.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 +134 -72
- package/dist/{chunk-CGJD4ZO5.mjs → chunk-7RN7PBJH.mjs} +11 -1
- package/dist/chunk-7RN7PBJH.mjs.map +1 -0
- package/dist/{chunk-36DDSV5T.mjs → chunk-RTI5YLAB.mjs} +163 -44
- package/dist/chunk-RTI5YLAB.mjs.map +1 -0
- package/dist/client-BrWpdgrN.d.mts +3024 -0
- package/dist/client-BrWpdgrN.d.ts +3024 -0
- package/dist/client.d.mts +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +167 -28
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +2 -2
- package/dist/errors-lG5MwUyw.d.mts +176 -0
- package/dist/errors-lG5MwUyw.d.ts +176 -0
- package/dist/errors.d.mts +1 -0
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +11 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +3 -1
- package/dist/index.d.mts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +172 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -10
- package/dist/index.mjs.map +1 -1
- package/dist/models.d.mts +2 -0
- package/dist/models.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunk-36DDSV5T.mjs.map +0 -1
- package/dist/chunk-CGJD4ZO5.mjs.map +0 -1
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 https://pl.doboxa.biz
|
|
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,15 +266,63 @@ 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
|
+
### Product catalog (BaseLinker connector)
|
|
273
|
+
|
|
274
|
+
The product catalog is not part of API v2 - it is served by Doboxa's BaseLinker
|
|
275
|
+
connector (shop integration file) on its own URL. The merchant finds both
|
|
276
|
+
credentials in the Doboxa client panel: **Integracje → Edycja** on the BaseLinker
|
|
277
|
+
integration. The modal shows the connector URL and the **Hasło** (password)
|
|
278
|
+
field.
|
|
279
|
+
|
|
280
|
+
```typescript
|
|
281
|
+
const doboxa = new Doboxa({
|
|
282
|
+
baseURL: "https://pl.doboxa.biz",
|
|
283
|
+
catalog: {
|
|
284
|
+
url: "https://pl.doboxa.biz/api/base-linker/{clientToken}/{language}",
|
|
285
|
+
password: "YOUR_BL_PASS",
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
const catalog = doboxa.catalog!; // defined because `catalog` config was passed
|
|
289
|
+
|
|
290
|
+
// Connector capabilities
|
|
291
|
+
console.log(await catalog.fileVersion());
|
|
292
|
+
console.log(await catalog.supportedMethods());
|
|
293
|
+
|
|
294
|
+
// Categories: { "<id>": "Category / Path" }
|
|
295
|
+
const categories = await catalog.categories();
|
|
296
|
+
|
|
297
|
+
// One page of designs (100 per page)
|
|
298
|
+
const { pages, items } = await catalog.list({ page: 1 });
|
|
299
|
+
console.log(pages, items[0].id, items[0].name, items[0].price);
|
|
300
|
+
|
|
301
|
+
// Full data (images, variants) for selected designs
|
|
302
|
+
const data = await catalog.data({
|
|
303
|
+
products_id: [items[0].id],
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Notes:
|
|
308
|
+
|
|
309
|
+
- The catalog uses only the connector password, so no `apiKey` is needed - the
|
|
310
|
+
client works with the catalog, with the API and with both.
|
|
311
|
+
- `list()` returns one entry per design (the first variant); `data()` returns
|
|
312
|
+
the design with all of its variants.
|
|
313
|
+
- Prices are strings in PLN (up to 3 decimals) and are most likely **net**
|
|
314
|
+
prices - the markup is set by the merchant in the panel ("Zarządzanie cenami").
|
|
315
|
+
- The connector has no order methods, so orders are still created through
|
|
316
|
+
API v2 (`doboxa.orders`).
|
|
317
|
+
- Connector errors are returned with HTTP 200 and are thrown as
|
|
318
|
+
`DoboxaConnectorError` (with `errorCode` and `errorText`).
|
|
319
|
+
|
|
272
320
|
## Environment Variables
|
|
273
321
|
|
|
274
322
|
You can set the API base URL using an environment variable:
|
|
275
323
|
|
|
276
324
|
```bash
|
|
277
|
-
export DOBOXA_API_URL=https://
|
|
325
|
+
export DOBOXA_API_URL=https://pl.doboxa.biz
|
|
278
326
|
```
|
|
279
327
|
|
|
280
328
|
The library will use this value if no `baseURL` is provided in the configuration.
|
|
@@ -289,20 +337,20 @@ import {
|
|
|
289
337
|
DoboxaAPIError,
|
|
290
338
|
DoboxaAuthenticationError,
|
|
291
339
|
DoboxaValidationError,
|
|
292
|
-
} from
|
|
340
|
+
} from "doboxa-js";
|
|
293
341
|
|
|
294
342
|
try {
|
|
295
343
|
await doboxa.orders.create(orderData);
|
|
296
344
|
} catch (error) {
|
|
297
345
|
if (error instanceof DoboxaAuthenticationError) {
|
|
298
|
-
console.error(
|
|
346
|
+
console.error("Authentication failed:", error.message);
|
|
299
347
|
} else if (error instanceof DoboxaValidationError) {
|
|
300
|
-
console.error(
|
|
301
|
-
console.error(
|
|
348
|
+
console.error("Validation error:", error.message);
|
|
349
|
+
console.error("Invalid parameters:", error.invalidParameters);
|
|
302
350
|
} else if (error instanceof DoboxaAPIError) {
|
|
303
|
-
console.error(
|
|
351
|
+
console.error("API error:", error.statusCode, error.message);
|
|
304
352
|
} else {
|
|
305
|
-
console.error(
|
|
353
|
+
console.error("Unknown error:", error);
|
|
306
354
|
}
|
|
307
355
|
}
|
|
308
356
|
```
|
|
@@ -318,7 +366,7 @@ import type {
|
|
|
318
366
|
OrderStatus,
|
|
319
367
|
PageOfInvoices,
|
|
320
368
|
// ... and many more
|
|
321
|
-
} from
|
|
369
|
+
} from "doboxa-js";
|
|
322
370
|
```
|
|
323
371
|
|
|
324
372
|
## API Reference
|
|
@@ -326,10 +374,12 @@ import type {
|
|
|
326
374
|
### Resources
|
|
327
375
|
|
|
328
376
|
- **Authentication**: `doboxa.authentication`
|
|
377
|
+
|
|
329
378
|
- `login(params)` - Login with username and password
|
|
330
379
|
- `refreshToken(refreshToken)` - Refresh access token
|
|
331
380
|
|
|
332
381
|
- **Orders**: `doboxa.orders`
|
|
382
|
+
|
|
333
383
|
- `create(params)` - Create an order
|
|
334
384
|
- `getStatus(orderId)` - Get order status
|
|
335
385
|
- `updateStatus(orderId, params)` - Update order status
|
|
@@ -340,27 +390,40 @@ import type {
|
|
|
340
390
|
- `cancel(params)` - Cancel an order
|
|
341
391
|
|
|
342
392
|
- **Invoices**: `doboxa.invoices`
|
|
393
|
+
|
|
343
394
|
- `list(params?)` - List invoices
|
|
344
395
|
- `retrieve(invoiceId)` - Get a specific invoice
|
|
345
396
|
|
|
346
397
|
- **Clients**: `doboxa.clients`
|
|
398
|
+
|
|
347
399
|
- `list(params?)` - List clients
|
|
348
400
|
|
|
349
401
|
- **Discount Codes**: `doboxa.discountCodes`
|
|
402
|
+
|
|
350
403
|
- `list(params?)` - List discount codes
|
|
351
404
|
|
|
352
405
|
- **Tracking Numbers**: `doboxa.trackingNumbers`
|
|
406
|
+
|
|
353
407
|
- `list(params?)` - List tracking numbers
|
|
354
408
|
|
|
355
409
|
- **Order Comments**: `doboxa.orderComments`
|
|
410
|
+
|
|
356
411
|
- `list(params?)` - List order comments
|
|
357
412
|
|
|
358
413
|
- **Order Status Changes**: `doboxa.orderStatusChanges`
|
|
414
|
+
|
|
359
415
|
- `list(params?)` - List order status changes
|
|
360
416
|
|
|
361
417
|
- **Users**: `doboxa.users`
|
|
362
418
|
- `me()` - Get current user
|
|
363
419
|
|
|
420
|
+
- **Catalog**: `doboxa.catalog` (only when the `catalog` config is provided)
|
|
421
|
+
- `fileVersion()` - Get the connector platform and version
|
|
422
|
+
- `supportedMethods()` - Get the list of supported actions
|
|
423
|
+
- `categories()` - Get all product categories
|
|
424
|
+
- `list(params?)` - List one page of products (designs)
|
|
425
|
+
- `data(params)` - Get full product data (images, variants) for design ids
|
|
426
|
+
|
|
364
427
|
## License
|
|
365
428
|
|
|
366
429
|
ISC
|
|
@@ -368,4 +431,3 @@ ISC
|
|
|
368
431
|
## Support
|
|
369
432
|
|
|
370
433
|
For API access and support, please contact the Doboxa team at [doboxa.com](https://doboxa.com).
|
|
371
|
-
|
|
@@ -75,6 +75,15 @@ var DoboxaAuthenticationError = class _DoboxaAuthenticationError extends DoboxaE
|
|
|
75
75
|
Object.setPrototypeOf(this, _DoboxaAuthenticationError.prototype);
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
+
var DoboxaConnectorError = class _DoboxaConnectorError extends DoboxaError {
|
|
79
|
+
constructor(errorCode, errorText, message) {
|
|
80
|
+
super(message || errorText || `BaseLinker connector error: ${errorCode}`);
|
|
81
|
+
this.name = "DoboxaConnectorError";
|
|
82
|
+
this.errorCode = errorCode;
|
|
83
|
+
this.errorText = errorText;
|
|
84
|
+
Object.setPrototypeOf(this, _DoboxaConnectorError.prototype);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
78
87
|
var DoboxaValidationError = class _DoboxaValidationError extends DoboxaAPIError {
|
|
79
88
|
constructor(statusCode, message, body) {
|
|
80
89
|
super(statusCode, message, body);
|
|
@@ -101,7 +110,8 @@ export {
|
|
|
101
110
|
DoboxaError,
|
|
102
111
|
DoboxaAPIError,
|
|
103
112
|
DoboxaAuthenticationError,
|
|
113
|
+
DoboxaConnectorError,
|
|
104
114
|
DoboxaValidationError,
|
|
105
115
|
parseErrorResponse
|
|
106
116
|
};
|
|
107
|
-
//# sourceMappingURL=chunk-
|
|
117
|
+
//# sourceMappingURL=chunk-7RN7PBJH.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 the BaseLinker connector returns an error.\n * The connector always answers with HTTP 200, so the error is carried in the body.\n */\nexport class DoboxaConnectorError extends DoboxaError {\n /**\n * Machine readable error code, e.g. \"bad_password\", \"no_password\", \"unsupported_method\"\n */\n public readonly errorCode: string;\n /**\n * Human readable error text returned by the connector\n */\n public readonly errorText: string;\n\n constructor(errorCode: string, errorText: string, message?: string) {\n super(message || errorText || `BaseLinker connector error: ${errorCode}`);\n this.name = 'DoboxaConnectorError';\n this.errorCode = errorCode;\n this.errorText = errorText;\n Object.setPrototypeOf(this, DoboxaConnectorError.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;AAMO,IAAM,uBAAN,MAAM,8BAA6B,YAAY;AAAA,EAUpD,YAAY,WAAmB,WAAmB,SAAkB;AAClE,UAAM,WAAW,aAAa,+BAA+B,SAAS,EAAE;AACxE,SAAK,OAAO;AACZ,SAAK,YAAY;AACjB,SAAK,YAAY;AACjB,WAAO,eAAe,MAAM,sBAAqB,SAAS;AAAA,EAC5D;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":[]}
|