@translated/lara 2.0.0-beta.6 → 2.0.0-beta.7

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/lib/Translator.js CHANGED
@@ -38,9 +38,7 @@ export class Translator {
38
38
  }, async (error) => {
39
39
  var _a, _b, _c, _d, _e, _f;
40
40
  const originalRequest = error.config;
41
- if (originalRequest.isRetry)
42
- return Promise.reject(error);
43
- if (error.response && error.response.status === 401 && error.response.data.message === 'jwt expired') {
41
+ if (!originalRequest.isRetry && error.response && error.response.status === 401 && error.response.data.message === 'jwt expired') {
44
42
  this.token = undefined;
45
43
  const token = await this.authenticate();
46
44
  originalRequest.isRetry = true;
@@ -60,30 +58,30 @@ export class Translator {
60
58
  return this.token;
61
59
  // If we have a refresh token, use it to get a new token
62
60
  if (this.refreshToken) {
63
- const { data } = await axios.post(`${(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.serverUrl) !== null && _b !== void 0 ? _b : DEFAULT_BASE_URL}/v2/auth/refresh`, null, {
61
+ const { data, headers } = await axios.post(`${(_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.serverUrl) !== null && _b !== void 0 ? _b : DEFAULT_BASE_URL}/v2/auth/refresh`, null, {
64
62
  headers: {
65
63
  authorization: `Bearer ${this.refreshToken}`,
66
64
  'X-Lara-Date': new Date().toUTCString(),
67
65
  },
68
66
  });
69
67
  this.token = data.token;
70
- this.refreshToken = data.refresh_token;
68
+ this.refreshToken = headers['x-lara-refresh-token'];
71
69
  return this.token;
72
70
  }
73
71
  else if (this.accessKey) {
74
72
  // Use access key to get a new token
75
- const { data } = await axios.post(`${(_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.serverUrl) !== null && _d !== void 0 ? _d : DEFAULT_BASE_URL}/v2/auth`, this.accessKey, {
73
+ const { data, headers } = await axios.post(`${(_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.serverUrl) !== null && _d !== void 0 ? _d : DEFAULT_BASE_URL}/v2/auth`, this.accessKey, {
76
74
  headers: {
77
75
  'X-Lara-Date': new Date().toUTCString(),
78
76
  },
79
77
  });
80
78
  this.token = data.token;
81
- this.refreshToken = data.refresh_token;
79
+ this.refreshToken = headers['x-lara-refresh-token'];
82
80
  return this.token;
83
81
  }
84
82
  else if (this.credentials) {
85
83
  // Use credentials to get a new token
86
- const { data } = await axios.post(
84
+ const { data, headers } = await axios.post(
87
85
  //FIXME: client id should be set
88
86
  `${(_f = (_e = this.options) === null || _e === void 0 ? void 0 : _e.serverUrl) !== null && _f !== void 0 ? _f : DEFAULT_BASE_URL}/v2/auth/Unknown/login`, this.credentials, {
89
87
  headers: {
@@ -91,7 +89,7 @@ export class Translator {
91
89
  },
92
90
  });
93
91
  this.token = data.token;
94
- this.refreshToken = data.refresh_token;
92
+ this.refreshToken = headers['x-lara-refresh-token'];
95
93
  return this.token;
96
94
  }
97
95
  else if (this.authToken) {
@@ -10,3 +10,6 @@ export type Credentials = {
10
10
  email: string;
11
11
  password: string;
12
12
  };
13
+ export type AuthenticationResponse = {
14
+ token: string;
15
+ };
@@ -1 +1 @@
1
- export declare const version = "2.0.0-beta.5";
1
+ export declare const version = "2.0.0-beta.6";
@@ -1 +1 @@
1
- export const version = '2.0.0-beta.5';
1
+ export const version = '2.0.0-beta.6';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@translated/lara",
3
- "version": "2.0.0-beta.6",
3
+ "version": "2.0.0-beta.7",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "engines": {