@evergis/api 3.0.199 → 3.0.200
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/dist/__generated__/LayersService.d.ts +2 -2
- package/dist/__generated__/ProjectsService.d.ts +2 -2
- package/dist/__generated__/StatisticService.d.ts +2 -2
- package/dist/__generated__/TablesService.d.ts +2 -2
- package/dist/__generated__/data-contracts.d.ts +4 -4
- package/dist/api.cjs.development.js +45 -5
- package/dist/api.cjs.development.js.map +1 -1
- package/dist/api.cjs.production.min.js +1 -1
- package/dist/api.cjs.production.min.js.map +1 -1
- package/dist/api.esm.js +45 -5
- package/dist/api.esm.js.map +1 -1
- package/dist/services/Account.d.ts +2 -2
- package/dist/services/Statistic.d.ts +2 -2
- package/dist/services/constants.d.ts +2 -0
- package/dist/utils/parseJwt.d.ts +1 -0
- package/package.json +2 -2
package/dist/api.esm.js
CHANGED
|
@@ -175,6 +175,16 @@ function _get(target, property, receiver) {
|
|
|
175
175
|
return _get(target, property, receiver || target);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
const STORAGE_TOKEN_KEY = "evergis-jwt-token";
|
|
179
|
+
const STORAGE_REFRESH_TOKEN_KEY = "evergis-jwt-token";
|
|
180
|
+
|
|
181
|
+
const parseJwt = token => {
|
|
182
|
+
const base64Url = token.split(".")[1];
|
|
183
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
184
|
+
const jsonPayload = decodeURIComponent(atob(base64).split("").map(c => "%" + "00".concat(c.charCodeAt(0).toString(16)).slice(-2)).join(""));
|
|
185
|
+
return JSON.parse(jsonPayload);
|
|
186
|
+
};
|
|
187
|
+
|
|
178
188
|
let HttpClient = /*#__PURE__*/function () {
|
|
179
189
|
function HttpClient(options) {
|
|
180
190
|
var _options$prefixUrl;
|
|
@@ -194,7 +204,30 @@ let HttpClient = /*#__PURE__*/function () {
|
|
|
194
204
|
value: function extend(options) {
|
|
195
205
|
var _options$prefixUrl2;
|
|
196
206
|
|
|
197
|
-
this.ky = ky.extend(options
|
|
207
|
+
this.ky = ky.extend(_extends({}, options, {
|
|
208
|
+
hooks: {
|
|
209
|
+
beforeRequest: [async request => {
|
|
210
|
+
const token = window.localStorage.getItem(STORAGE_TOKEN_KEY);
|
|
211
|
+
const refreshToken = window.localStorage.getItem(STORAGE_REFRESH_TOKEN_KEY);
|
|
212
|
+
|
|
213
|
+
if (token) {
|
|
214
|
+
var _request$headers;
|
|
215
|
+
|
|
216
|
+
const {
|
|
217
|
+
exp
|
|
218
|
+
} = parseJwt(token) || {};
|
|
219
|
+
|
|
220
|
+
if (typeof exp === 'number' && exp - new Date().getTime() < 60 * 1000) {
|
|
221
|
+
await this.post("/account/refresh-token", {
|
|
222
|
+
refreshToken
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
(_request$headers = request.headers) == null ? void 0 : _request$headers.set('Authorization', "Bearer " + (token || ''));
|
|
227
|
+
}
|
|
228
|
+
}]
|
|
229
|
+
}
|
|
230
|
+
}));
|
|
198
231
|
this.prefixUrl = ((_options$prefixUrl2 = options.prefixUrl) == null ? void 0 : _options$prefixUrl2.toString()) || '';
|
|
199
232
|
}
|
|
200
233
|
}, {
|
|
@@ -1431,13 +1464,18 @@ let Account = /*#__PURE__*/function (_AccountService) {
|
|
|
1431
1464
|
|
|
1432
1465
|
_createClass(Account, [{
|
|
1433
1466
|
key: "login",
|
|
1434
|
-
value:
|
|
1467
|
+
value: function login(params, authParams) {
|
|
1435
1468
|
if (authParams === void 0) {
|
|
1436
1469
|
authParams = {};
|
|
1437
1470
|
}
|
|
1438
1471
|
|
|
1439
1472
|
if (params) {
|
|
1440
|
-
|
|
1473
|
+
_get(_getPrototypeOf(Account.prototype), "authenticate", this).call(this, authParams, params).then(resonse => {
|
|
1474
|
+
if (resonse) {
|
|
1475
|
+
window.localStorage.setItem(STORAGE_TOKEN_KEY, resonse.token);
|
|
1476
|
+
window.localStorage.setItem(STORAGE_REFRESH_TOKEN_KEY, resonse.refreshToken);
|
|
1477
|
+
}
|
|
1478
|
+
});
|
|
1441
1479
|
}
|
|
1442
1480
|
}
|
|
1443
1481
|
}, {
|
|
@@ -1456,8 +1494,10 @@ let Account = /*#__PURE__*/function (_AccountService) {
|
|
|
1456
1494
|
}, {
|
|
1457
1495
|
key: "logout",
|
|
1458
1496
|
value: async function logout() {
|
|
1497
|
+
window.localStorage.removeItem(STORAGE_TOKEN_KEY);
|
|
1498
|
+
window.localStorage.removeItem(STORAGE_REFRESH_TOKEN_KEY);
|
|
1459
1499
|
await this.revokeToken();
|
|
1460
|
-
updateUserInfo(
|
|
1500
|
+
updateUserInfo(undefined);
|
|
1461
1501
|
this.userInfo = {};
|
|
1462
1502
|
}
|
|
1463
1503
|
}, {
|
|
@@ -7593,7 +7633,7 @@ let Api = /*#__PURE__*/function (_EventEmitter) {
|
|
|
7593
7633
|
} = _ref2;
|
|
7594
7634
|
|
|
7595
7635
|
try {
|
|
7596
|
-
|
|
7636
|
+
this.account.login(authParams, authQueryParams);
|
|
7597
7637
|
|
|
7598
7638
|
if (fetchUser) {
|
|
7599
7639
|
await this.account.fetchCurrentUser();
|