doboxa-js 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Piotr Michalik
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,371 @@
1
+ # Doboxa JS
2
+
3
+ A library for interacting with the Doboxa API v2. This library provides a clean interface for all Doboxa API endpoints.
4
+
5
+ ## Prerequisites
6
+
7
+ Before using this library, you need to:
8
+
9
+ 1. **Contact the Doboxa team** at [doboxa.com](https://doboxa.com) to request API access for your account
10
+ 2. Have your Doboxa account **username and password** ready (these are your regular Doboxa account credentials)
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ npm install doboxa-js
16
+ # or
17
+ pnpm add doboxa-js
18
+ # or
19
+ yarn add doboxa-js
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ### Basic Setup
25
+
26
+ ```typescript
27
+ import Doboxa from 'doboxa-js';
28
+
29
+ // Initialize the client
30
+ const doboxa = new Doboxa({
31
+ baseURL: 'https://api.doboxa.biz', // Optional: defaults to DOBOXA_API_URL env var or http://localhost
32
+ });
33
+ ```
34
+
35
+ ### Authentication
36
+
37
+ The library supports two authentication methods:
38
+
39
+ #### Method 1: Login with Username and Password
40
+
41
+ ```typescript
42
+ import Doboxa from 'doboxa-js';
43
+
44
+ const doboxa = new Doboxa({
45
+ baseURL: 'https://api.doboxa.biz',
46
+ });
47
+
48
+ // Login with your Doboxa account credentials
49
+ const authResponse = await doboxa.authentication.login({
50
+ username: 'your-username',
51
+ password: 'your-password',
52
+ });
53
+
54
+ console.log('Access token:', authResponse.token);
55
+ console.log('Refresh token:', authResponse.refresh_token);
56
+
57
+ // Tokens are automatically stored and used for subsequent requests
58
+ ```
59
+
60
+ #### Method 2: Initialize with Access Token
61
+
62
+ If you already have an access token:
63
+
64
+ ```typescript
65
+ import Doboxa from 'doboxa-js';
66
+
67
+ const doboxa = new Doboxa({
68
+ apiKey: 'your-access-token',
69
+ baseURL: 'https://api.doboxa.biz',
70
+ });
71
+
72
+ // You can now make API calls immediately
73
+ ```
74
+
75
+ **Note:** The library automatically handles token refresh when tokens expire. If you're using username/password authentication, the refresh token will be used automatically.
76
+
77
+ ## Usage Examples
78
+
79
+ ### Orders
80
+
81
+ #### Create an Order
82
+
83
+ ```typescript
84
+ const order = await doboxa.orders.create({
85
+ external_id: 'ORDER-12345',
86
+ deliver_address: {
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
+ },
96
+ items: [
97
+ {
98
+ id: 'SKU-123',
99
+ name: 'Product Name',
100
+ qty: 2,
101
+ item_price: 9999, // Price in cents (99.99)
102
+ },
103
+ ],
104
+ order_time: new Date().toISOString(),
105
+ order_channel: 'channel_id',
106
+ currency: 'PLN',
107
+ });
108
+ ```
109
+
110
+ #### Get Order Status
111
+
112
+ ```typescript
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
+ ```
117
+
118
+ #### Update Order Status
119
+
120
+ ```typescript
121
+ await doboxa.orders.updateStatus('order-id-123', {
122
+ status: 'paid',
123
+ item_status: [
124
+ {
125
+ doboxa_item_id: 'item-123',
126
+ status: 'paid',
127
+ },
128
+ ],
129
+ });
130
+ ```
131
+
132
+ #### Get Order Comments
133
+
134
+ ```typescript
135
+ const comments = await doboxa.orders.getComments('order-id-123');
136
+ console.log('Comments:', comments.items);
137
+ ```
138
+
139
+ #### Create Order Comment
140
+
141
+ ```typescript
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
+ created_at: new Date().toISOString(),
147
+ });
148
+ ```
149
+
150
+ #### Get Order Invoices
151
+
152
+ ```typescript
153
+ const invoices = await doboxa.orders.getInvoices('order-id-123');
154
+ console.log('Invoices:', invoices.items);
155
+ ```
156
+
157
+ #### Get Order Tracking Numbers
158
+
159
+ ```typescript
160
+ const tracking = await doboxa.orders.getTrackingNumbers('order-id-123');
161
+ console.log('Tracking numbers:', tracking.items);
162
+ ```
163
+
164
+ #### Cancel an Order
165
+
166
+ ```typescript
167
+ const result = await doboxa.orders.cancel({
168
+ order_id: 'order-id-123',
169
+ });
170
+ console.log('Cancelled:', result.cancelled);
171
+ console.log('Details:', result.details);
172
+ ```
173
+
174
+ ### Invoices
175
+
176
+ #### List Invoices
177
+
178
+ ```typescript
179
+ const invoices = await doboxa.invoices.list({
180
+ page: 1,
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
+ });
184
+
185
+ console.log('Invoices:', invoices.items);
186
+ console.log('Next page:', invoices.next_page);
187
+ ```
188
+
189
+ #### Retrieve a Specific Invoice
190
+
191
+ ```typescript
192
+ const invoice = await doboxa.invoices.retrieve('invoice-id-123');
193
+ console.log('Invoice:', invoice);
194
+ console.log('PDF URL:', invoice.file);
195
+ ```
196
+
197
+ ### Clients
198
+
199
+ #### List Clients
200
+
201
+ ```typescript
202
+ const clients = await doboxa.clients.list({
203
+ page: 1,
204
+ });
205
+
206
+ console.log('Clients:', clients.items);
207
+ ```
208
+
209
+ ### Discount Codes
210
+
211
+ #### List Discount Codes
212
+
213
+ ```typescript
214
+ const discountCodes = await doboxa.discountCodes.list({
215
+ page: 1,
216
+ });
217
+
218
+ console.log('Discount codes:', discountCodes.items);
219
+ ```
220
+
221
+ ### Tracking Numbers
222
+
223
+ #### List Tracking Numbers
224
+
225
+ ```typescript
226
+ const trackingNumbers = await doboxa.trackingNumbers.list({
227
+ page: 1,
228
+ from: '2024-01-01T00:00:00Z',
229
+ to: '2024-12-31T23:59:59Z',
230
+ });
231
+
232
+ console.log('Tracking numbers:', trackingNumbers.items);
233
+ ```
234
+
235
+ ### Order Comments
236
+
237
+ #### List Order Comments
238
+
239
+ ```typescript
240
+ const comments = await doboxa.orderComments.list({
241
+ page: 1,
242
+ from: '2024-01-01T00:00:00Z',
243
+ to: '2024-12-31T23:59:59Z',
244
+ });
245
+
246
+ console.log('Comments:', comments.items);
247
+ ```
248
+
249
+ ### Order Status Changes
250
+
251
+ #### List Order Status Changes
252
+
253
+ ```typescript
254
+ const statusChanges = await doboxa.orderStatusChanges.list({
255
+ page: 1,
256
+ from: '2024-01-01T00:00:00Z',
257
+ to: '2024-12-31T23:59:59Z',
258
+ });
259
+
260
+ console.log('Status changes:', statusChanges.items);
261
+ ```
262
+
263
+ ### Users
264
+
265
+ #### Get Current User
266
+
267
+ ```typescript
268
+ const me = await doboxa.users.me();
269
+ console.log('Current user:', me.username);
270
+ ```
271
+
272
+ ## Environment Variables
273
+
274
+ You can set the API base URL using an environment variable:
275
+
276
+ ```bash
277
+ export DOBOXA_API_URL=https://api.doboxa.biz
278
+ ```
279
+
280
+ The library will use this value if no `baseURL` is provided in the configuration.
281
+
282
+ ## Error Handling
283
+
284
+ The library provides structured error classes:
285
+
286
+ ```typescript
287
+ import {
288
+ DoboxaError,
289
+ DoboxaAPIError,
290
+ DoboxaAuthenticationError,
291
+ DoboxaValidationError,
292
+ } from 'doboxa-js';
293
+
294
+ try {
295
+ await doboxa.orders.create(orderData);
296
+ } catch (error) {
297
+ if (error instanceof DoboxaAuthenticationError) {
298
+ console.error('Authentication failed:', error.message);
299
+ } else if (error instanceof DoboxaValidationError) {
300
+ console.error('Validation error:', error.message);
301
+ console.error('Invalid parameters:', error.invalidParameters);
302
+ } else if (error instanceof DoboxaAPIError) {
303
+ console.error('API error:', error.statusCode, error.message);
304
+ } else {
305
+ console.error('Unknown error:', error);
306
+ }
307
+ }
308
+ ```
309
+
310
+ ## TypeScript Support
311
+
312
+ This library is written in TypeScript and provides full type definitions. All API responses and request parameters are fully typed:
313
+
314
+ ```typescript
315
+ import type {
316
+ Order,
317
+ Invoice,
318
+ OrderStatus,
319
+ PageOfInvoices,
320
+ // ... and many more
321
+ } from 'doboxa-js';
322
+ ```
323
+
324
+ ## API Reference
325
+
326
+ ### Resources
327
+
328
+ - **Authentication**: `doboxa.authentication`
329
+ - `login(params)` - Login with username and password
330
+ - `refreshToken(refreshToken)` - Refresh access token
331
+
332
+ - **Orders**: `doboxa.orders`
333
+ - `create(params)` - Create an order
334
+ - `getStatus(orderId)` - Get order status
335
+ - `updateStatus(orderId, params)` - Update order status
336
+ - `getComments(orderId)` - Get order comments
337
+ - `createComment(orderId, params)` - Create order comment
338
+ - `getInvoices(orderId)` - Get order invoices
339
+ - `getTrackingNumbers(orderId)` - Get order tracking numbers
340
+ - `cancel(params)` - Cancel an order
341
+
342
+ - **Invoices**: `doboxa.invoices`
343
+ - `list(params?)` - List invoices
344
+ - `retrieve(invoiceId)` - Get a specific invoice
345
+
346
+ - **Clients**: `doboxa.clients`
347
+ - `list(params?)` - List clients
348
+
349
+ - **Discount Codes**: `doboxa.discountCodes`
350
+ - `list(params?)` - List discount codes
351
+
352
+ - **Tracking Numbers**: `doboxa.trackingNumbers`
353
+ - `list(params?)` - List tracking numbers
354
+
355
+ - **Order Comments**: `doboxa.orderComments`
356
+ - `list(params?)` - List order comments
357
+
358
+ - **Order Status Changes**: `doboxa.orderStatusChanges`
359
+ - `list(params?)` - List order status changes
360
+
361
+ - **Users**: `doboxa.users`
362
+ - `me()` - Get current user
363
+
364
+ ## License
365
+
366
+ ISC
367
+
368
+ ## Support
369
+
370
+ For API access and support, please contact the Doboxa team at [doboxa.com](https://doboxa.com).
371
+