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.
@@ -0,0 +1 @@
1
+ export { D as Doboxa, a as DoboxaConfig } from './client-BfIS6ja2.mjs';
@@ -0,0 +1 @@
1
+ export { D as Doboxa, a as DoboxaConfig } from './client-BfIS6ja2.js';
package/dist/client.js CHANGED
@@ -373,26 +373,24 @@ var HTTPClient = class {
373
373
  if (!accessToken || this.tokenManager.isTokenExpired()) {
374
374
  if (this.onTokenRefresh) {
375
375
  const refreshToken = this.tokenManager.getRefreshToken();
376
- if (!refreshToken) {
377
- throw new DoboxaAuthenticationError("No refresh token available");
376
+ if (refreshToken) {
377
+ let refreshPromise = this.tokenManager.getRefreshPromise();
378
+ if (!refreshPromise) {
379
+ refreshPromise = this.onTokenRefresh(refreshToken);
380
+ this.tokenManager.setRefreshPromise(refreshPromise);
381
+ }
382
+ try {
383
+ accessToken = yield refreshPromise;
384
+ } finally {
385
+ this.tokenManager.setRefreshPromise(null);
386
+ }
378
387
  }
379
- let refreshPromise = this.tokenManager.getRefreshPromise();
380
- if (!refreshPromise) {
381
- refreshPromise = this.onTokenRefresh(refreshToken);
382
- this.tokenManager.setRefreshPromise(refreshPromise);
383
- }
384
- try {
385
- accessToken = yield refreshPromise;
386
- } finally {
387
- this.tokenManager.setRefreshPromise(null);
388
- }
389
- } else {
390
- throw new DoboxaAuthenticationError("No access token available");
391
388
  }
392
389
  }
393
390
  const headers = new Headers(options.headers);
394
391
  headers.set("Content-Type", "application/json");
395
392
  headers.set("Authorization", `Bearer ${accessToken}`);
393
+ console.log("url", url);
396
394
  const response = yield fetch(url, __spreadProps(__spreadValues({}, options), {
397
395
  headers
398
396
  }));
@@ -1996,7 +1994,7 @@ var UsersResource = class {
1996
1994
  // src/client.ts
1997
1995
  var Doboxa = class {
1998
1996
  constructor(config = {}) {
1999
- const baseURL = config.baseURL || getBaseURL() || "http://localhost";
1997
+ const baseURL = config.baseURL || getBaseURL() || "https://pl.doboxa.biz";
2000
1998
  this.tokenManager = new TokenManager();
2001
1999
  if (config.apiKey) {
2002
2000
  this.tokenManager.setTokens(config.apiKey, "", 3600);
@@ -2022,20 +2020,42 @@ var Doboxa = class {
2022
2020
  baseURL,
2023
2021
  tokenManager: this.tokenManager,
2024
2022
  onTokenRefresh: (refreshToken) => __async(this, null, function* () {
2025
- const tempAuth = new AuthenticationResource(tempHttpClient, this.tokenManager);
2023
+ const tempAuth = new AuthenticationResource(
2024
+ tempHttpClient,
2025
+ this.tokenManager
2026
+ );
2026
2027
  const response = yield tempAuth.refreshToken(refreshToken);
2027
- this.tokenManager.setTokens(response.token, response.refresh_token, 3600);
2028
+ this.tokenManager.setTokens(
2029
+ response.token,
2030
+ response.refresh_token,
2031
+ 3600
2032
+ );
2028
2033
  return response.token;
2029
2034
  })
2030
2035
  });
2031
- this.authentication = new AuthenticationResource(this.httpClient, this.tokenManager);
2036
+ this.authentication = new AuthenticationResource(
2037
+ this.httpClient,
2038
+ this.tokenManager
2039
+ );
2032
2040
  this.orders = new OrdersResource(this.httpClient, this.config);
2033
2041
  this.invoices = new InvoicesResource(this.httpClient, this.config);
2034
2042
  this.clients = new ClientsResource(this.httpClient, this.config);
2035
- this.discountCodes = new DiscountCodesResource(this.httpClient, this.config);
2036
- this.trackingNumbers = new TrackingNumbersResource(this.httpClient, this.config);
2037
- this.orderComments = new OrderCommentsResource(this.httpClient, this.config);
2038
- this.orderStatusChanges = new OrderStatusChangesResource(this.httpClient, this.config);
2043
+ this.discountCodes = new DiscountCodesResource(
2044
+ this.httpClient,
2045
+ this.config
2046
+ );
2047
+ this.trackingNumbers = new TrackingNumbersResource(
2048
+ this.httpClient,
2049
+ this.config
2050
+ );
2051
+ this.orderComments = new OrderCommentsResource(
2052
+ this.httpClient,
2053
+ this.config
2054
+ );
2055
+ this.orderStatusChanges = new OrderStatusChangesResource(
2056
+ this.httpClient,
2057
+ this.config
2058
+ );
2039
2059
  this.users = new UsersResource(this.httpClient, this.config);
2040
2060
  }
2041
2061
  };