doboxa-js 1.0.2 → 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 CHANGED
@@ -24,11 +24,11 @@ yarn add doboxa-js
24
24
  ### Basic Setup
25
25
 
26
26
  ```typescript
27
- import Doboxa from 'doboxa-js';
27
+ import Doboxa from "doboxa-js";
28
28
 
29
29
  // Initialize the client
30
30
  const doboxa = new Doboxa({
31
- baseURL: 'https://api.doboxa.biz', // Optional: defaults to DOBOXA_API_URL env var or http://localhost
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 'doboxa-js';
42
+ import Doboxa from "doboxa-js";
43
43
 
44
44
  const doboxa = new Doboxa({
45
- baseURL: 'https://api.doboxa.biz',
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: 'your-username',
51
- password: 'your-password',
50
+ username: "your-username",
51
+ password: "your-password",
52
52
  });
53
53
 
54
- console.log('Access token:', authResponse.token);
55
- console.log('Refresh token:', authResponse.refresh_token);
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 'doboxa-js';
65
+ import Doboxa from "doboxa-js";
66
66
 
67
67
  const doboxa = new Doboxa({
68
- apiKey: 'your-access-token',
69
- baseURL: 'https://api.doboxa.biz',
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: 'ORDER-12345',
85
+ external_id: "ORDER-12345",
86
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',
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: 'SKU-123',
99
- name: 'Product 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: 'channel_id',
106
- currency: 'PLN',
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('order-id-123');
114
- console.log('Order status:', status.status);
115
- console.log('Item statuses:', status.item_status);
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('order-id-123', {
122
- status: 'paid',
121
+ await doboxa.orders.updateStatus("order-id-123", {
122
+ status: "paid",
123
123
  item_status: [
124
124
  {
125
- doboxa_item_id: 'item-123',
126
- status: 'paid',
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('order-id-123');
136
- console.log('Comments:', comments.items);
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('order-id-123', {
143
- author_type: 'client',
144
- author_email: 'client@example.com',
145
- content: 'This is a comment',
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('order-id-123');
154
- console.log('Invoices:', invoices.items);
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('order-id-123');
161
- console.log('Tracking numbers:', tracking.items);
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: 'order-id-123',
168
+ order_id: "order-id-123",
169
169
  });
170
- console.log('Cancelled:', result.cancelled);
171
- console.log('Details:', result.details);
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: '2024-01-01T00:00:00Z', // Optional: ISO date-time string
182
- to: '2024-12-31T23:59:59Z', // Optional: ISO date-time string
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('Invoices:', invoices.items);
186
- console.log('Next page:', invoices.next_page);
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('invoice-id-123');
193
- console.log('Invoice:', invoice);
194
- console.log('PDF URL:', invoice.file);
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('Clients:', clients.items);
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('Discount codes:', discountCodes.items);
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: '2024-01-01T00:00:00Z',
229
- to: '2024-12-31T23:59:59Z',
228
+ from: "2024-01-01T00:00:00Z",
229
+ to: "2024-12-31T23:59:59Z",
230
230
  });
231
231
 
232
- console.log('Tracking numbers:', trackingNumbers.items);
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: '2024-01-01T00:00:00Z',
243
- to: '2024-12-31T23:59:59Z',
242
+ from: "2024-01-01T00:00:00Z",
243
+ to: "2024-12-31T23:59:59Z",
244
244
  });
245
245
 
246
- console.log('Comments:', comments.items);
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: '2024-01-01T00:00:00Z',
257
- to: '2024-12-31T23:59:59Z',
256
+ from: "2024-01-01T00:00:00Z",
257
+ to: "2024-12-31T23:59:59Z",
258
258
  });
259
259
 
260
- console.log('Status changes:', statusChanges.items);
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('Current user:', me.username);
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://api.doboxa.biz
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 'doboxa-js';
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('Authentication failed:', error.message);
298
+ console.error("Authentication failed:", error.message);
299
299
  } else if (error instanceof DoboxaValidationError) {
300
- console.error('Validation error:', error.message);
301
- console.error('Invalid parameters:', error.invalidParameters);
300
+ console.error("Validation error:", error.message);
301
+ console.error("Invalid parameters:", error.invalidParameters);
302
302
  } else if (error instanceof DoboxaAPIError) {
303
- console.error('API error:', error.statusCode, error.message);
303
+ console.error("API error:", error.statusCode, error.message);
304
304
  } else {
305
- console.error('Unknown error:', 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 'doboxa-js';
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
-
@@ -271,26 +271,24 @@ var HTTPClient = class {
271
271
  if (!accessToken || this.tokenManager.isTokenExpired()) {
272
272
  if (this.onTokenRefresh) {
273
273
  const refreshToken = this.tokenManager.getRefreshToken();
274
- if (!refreshToken) {
275
- throw new DoboxaAuthenticationError("No refresh token available");
274
+ if (refreshToken) {
275
+ let refreshPromise = this.tokenManager.getRefreshPromise();
276
+ if (!refreshPromise) {
277
+ refreshPromise = this.onTokenRefresh(refreshToken);
278
+ this.tokenManager.setRefreshPromise(refreshPromise);
279
+ }
280
+ try {
281
+ accessToken = yield refreshPromise;
282
+ } finally {
283
+ this.tokenManager.setRefreshPromise(null);
284
+ }
276
285
  }
277
- let refreshPromise = this.tokenManager.getRefreshPromise();
278
- if (!refreshPromise) {
279
- refreshPromise = this.onTokenRefresh(refreshToken);
280
- this.tokenManager.setRefreshPromise(refreshPromise);
281
- }
282
- try {
283
- accessToken = yield refreshPromise;
284
- } finally {
285
- this.tokenManager.setRefreshPromise(null);
286
- }
287
- } else {
288
- throw new DoboxaAuthenticationError("No access token available");
289
286
  }
290
287
  }
291
288
  const headers = new Headers(options.headers);
292
289
  headers.set("Content-Type", "application/json");
293
290
  headers.set("Authorization", `Bearer ${accessToken}`);
291
+ console.log("url", url);
294
292
  const response = yield fetch(url, __spreadProps(__spreadValues({}, options), {
295
293
  headers
296
294
  }));
@@ -2815,7 +2813,7 @@ var UsersResource = class {
2815
2813
  // src/client.ts
2816
2814
  var Doboxa = class {
2817
2815
  constructor(config = {}) {
2818
- const baseURL = config.baseURL || getBaseURL() || "http://localhost";
2816
+ const baseURL = config.baseURL || getBaseURL() || "https://pl.doboxa.biz";
2819
2817
  this.tokenManager = new TokenManager();
2820
2818
  if (config.apiKey) {
2821
2819
  this.tokenManager.setTokens(config.apiKey, "", 3600);
@@ -2841,20 +2839,42 @@ var Doboxa = class {
2841
2839
  baseURL,
2842
2840
  tokenManager: this.tokenManager,
2843
2841
  onTokenRefresh: (refreshToken) => __async(this, null, function* () {
2844
- const tempAuth = new AuthenticationResource(tempHttpClient, this.tokenManager);
2842
+ const tempAuth = new AuthenticationResource(
2843
+ tempHttpClient,
2844
+ this.tokenManager
2845
+ );
2845
2846
  const response = yield tempAuth.refreshToken(refreshToken);
2846
- this.tokenManager.setTokens(response.token, response.refresh_token, 3600);
2847
+ this.tokenManager.setTokens(
2848
+ response.token,
2849
+ response.refresh_token,
2850
+ 3600
2851
+ );
2847
2852
  return response.token;
2848
2853
  })
2849
2854
  });
2850
- this.authentication = new AuthenticationResource(this.httpClient, this.tokenManager);
2855
+ this.authentication = new AuthenticationResource(
2856
+ this.httpClient,
2857
+ this.tokenManager
2858
+ );
2851
2859
  this.orders = new OrdersResource(this.httpClient, this.config);
2852
2860
  this.invoices = new InvoicesResource(this.httpClient, this.config);
2853
2861
  this.clients = new ClientsResource(this.httpClient, this.config);
2854
- this.discountCodes = new DiscountCodesResource(this.httpClient, this.config);
2855
- this.trackingNumbers = new TrackingNumbersResource(this.httpClient, this.config);
2856
- this.orderComments = new OrderCommentsResource(this.httpClient, this.config);
2857
- this.orderStatusChanges = new OrderStatusChangesResource(this.httpClient, this.config);
2862
+ this.discountCodes = new DiscountCodesResource(
2863
+ this.httpClient,
2864
+ this.config
2865
+ );
2866
+ this.trackingNumbers = new TrackingNumbersResource(
2867
+ this.httpClient,
2868
+ this.config
2869
+ );
2870
+ this.orderComments = new OrderCommentsResource(
2871
+ this.httpClient,
2872
+ this.config
2873
+ );
2874
+ this.orderStatusChanges = new OrderStatusChangesResource(
2875
+ this.httpClient,
2876
+ this.config
2877
+ );
2858
2878
  this.users = new UsersResource(this.httpClient, this.config);
2859
2879
  }
2860
2880
  };
@@ -3074,4 +3094,4 @@ export {
3074
3094
  UsersResource,
3075
3095
  Doboxa
3076
3096
  };
3077
- //# sourceMappingURL=chunk-36DDSV5T.mjs.map
3097
+ //# sourceMappingURL=chunk-WGEOQ35B.mjs.map