andoncloud-sdk 1.4.15 → 1.4.16
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/andoncloud-sdk.js +134 -54
- package/dist/andoncloud-sdk.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/package.json +11 -11
package/dist/andoncloud-sdk.js
CHANGED
|
@@ -381,31 +381,51 @@ var acFetch = function acFetch(url, options) {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
try {
|
|
384
|
+
var _temp4 = function _temp4() {
|
|
385
|
+
return Promise.resolve(fetch(url, options).catch(function (e) {
|
|
386
|
+
sessionStore.setNetworkError(e.message);
|
|
387
|
+
})).then(function (response) {
|
|
388
|
+
if (!(response != null && response.ok)) {
|
|
389
|
+
if (!response || response.status === 500) {
|
|
390
|
+
if (!sessionStore.networkError) {
|
|
391
|
+
sessionStore.setNetworkError(languageStore.translations.unexpectedErrorMessage);
|
|
392
|
+
}
|
|
393
|
+
} else if (response.status !== 400) {
|
|
394
|
+
sessionStore.removeSession();
|
|
395
|
+
sessionStore.removeCurrentUser();
|
|
396
|
+
sessionStore.setNotAuthorizedLoginStatus();
|
|
397
|
+
}
|
|
398
|
+
} else {
|
|
399
|
+
andoncloudFetch.callback(response, false);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return response;
|
|
403
|
+
});
|
|
404
|
+
};
|
|
405
|
+
|
|
384
406
|
var headers = sessionStore.requestHeaders();
|
|
385
407
|
|
|
386
408
|
if (headers !== null) {
|
|
387
409
|
options.headers = Object.assign({}, headers, options.headers);
|
|
388
410
|
}
|
|
389
411
|
|
|
390
|
-
|
|
391
|
-
sessionStore.
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
412
|
+
var _temp5 = function () {
|
|
413
|
+
if (sessionStore.isLoggedIn() && !options.refresh) {
|
|
414
|
+
var _sessionStore$session = sessionStore.session,
|
|
415
|
+
createdAt = _sessionStore$session.createdAt,
|
|
416
|
+
expiresIn = _sessionStore$session.expiresIn;
|
|
417
|
+
|
|
418
|
+
var _temp6 = function () {
|
|
419
|
+
if (createdAt + expiresIn < Math.round(+new Date() / 1000)) {
|
|
420
|
+
return Promise.resolve(sessionStore.refresh()).then(function () {});
|
|
397
421
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
sessionStore.setNotAuthorizedLoginStatus();
|
|
402
|
-
}
|
|
403
|
-
} else {
|
|
404
|
-
andoncloudFetch.callback(response, false);
|
|
422
|
+
}();
|
|
423
|
+
|
|
424
|
+
if (_temp6 && _temp6.then) return _temp6.then(function () {});
|
|
405
425
|
}
|
|
426
|
+
}();
|
|
406
427
|
|
|
407
|
-
|
|
408
|
-
});
|
|
428
|
+
return Promise.resolve(_temp5 && _temp5.then ? _temp5.then(_temp4) : _temp4(_temp5));
|
|
409
429
|
} catch (e) {
|
|
410
430
|
return Promise.reject(e);
|
|
411
431
|
}
|
|
@@ -661,7 +681,9 @@ function _catch(body, recover) {
|
|
|
661
681
|
var Session = function Session() {
|
|
662
682
|
this.user = {};
|
|
663
683
|
this.accessToken = null;
|
|
684
|
+
this.refreshToken = null;
|
|
664
685
|
this.tokenType = null;
|
|
686
|
+
this.createdAt = null;
|
|
665
687
|
this.expiresIn = null;
|
|
666
688
|
};
|
|
667
689
|
|
|
@@ -685,6 +707,7 @@ var SessionAPI = /*#__PURE__*/function () {
|
|
|
685
707
|
|
|
686
708
|
var formData = new FormData();
|
|
687
709
|
var scope = credentials.scope,
|
|
710
|
+
refresh = credentials.refresh,
|
|
688
711
|
code = credentials.code,
|
|
689
712
|
username = credentials.username,
|
|
690
713
|
password = credentials.password;
|
|
@@ -694,7 +717,11 @@ var SessionAPI = /*#__PURE__*/function () {
|
|
|
694
717
|
formData.append("scope", scope);
|
|
695
718
|
}
|
|
696
719
|
|
|
697
|
-
if (
|
|
720
|
+
if (refresh) {
|
|
721
|
+
formData.append("grant_type", "refresh_token");
|
|
722
|
+
formData.append("refresh_token", refresh);
|
|
723
|
+
formData.append("redirect_uri", _this2.redirectUri);
|
|
724
|
+
} else if (code) {
|
|
698
725
|
formData.append("grant_type", "authorization_code");
|
|
699
726
|
formData.append("code", code);
|
|
700
727
|
formData.append("redirect_uri", _this2.redirectUri);
|
|
@@ -706,7 +733,8 @@ var SessionAPI = /*#__PURE__*/function () {
|
|
|
706
733
|
|
|
707
734
|
var fetchParams = {
|
|
708
735
|
method: "POST",
|
|
709
|
-
body: formData
|
|
736
|
+
body: formData,
|
|
737
|
+
refresh: !!refresh
|
|
710
738
|
};
|
|
711
739
|
var session;
|
|
712
740
|
return Promise.resolve(acFetch(_this2.baseUrl + "/v2/oauth2/token", fetchParams).then(function (response) {
|
|
@@ -716,18 +744,31 @@ var SessionAPI = /*#__PURE__*/function () {
|
|
|
716
744
|
var data;
|
|
717
745
|
return Promise.resolve(function () {
|
|
718
746
|
if (response) {
|
|
719
|
-
var
|
|
747
|
+
var _temp5 = function _temp5(_result) {
|
|
720
748
|
if (_exit2) return _result;
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
session.user = _this2$getUserData;
|
|
749
|
+
|
|
750
|
+
function _temp2() {
|
|
724
751
|
session.accessToken = data.access_token;
|
|
752
|
+
session.refreshToken = data.refresh_token;
|
|
725
753
|
session.tokenType = data.token_type;
|
|
754
|
+
session.createdAt = data.created_at;
|
|
726
755
|
session.expiresIn = data.expires_in;
|
|
727
|
-
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
session = new Session();
|
|
759
|
+
|
|
760
|
+
var _temp = function () {
|
|
761
|
+
if (!refresh) {
|
|
762
|
+
return Promise.resolve(_this2.getUserData(data)).then(function (_this2$getUserData) {
|
|
763
|
+
session.user = _this2$getUserData;
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}();
|
|
767
|
+
|
|
768
|
+
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
|
|
728
769
|
};
|
|
729
770
|
|
|
730
|
-
var
|
|
771
|
+
var _temp6 = _catch(function () {
|
|
731
772
|
return Promise.resolve(response.json()).then(function (_response$json) {
|
|
732
773
|
data = _response$json;
|
|
733
774
|
|
|
@@ -741,7 +782,7 @@ var SessionAPI = /*#__PURE__*/function () {
|
|
|
741
782
|
_exit2 = 1;
|
|
742
783
|
});
|
|
743
784
|
|
|
744
|
-
return
|
|
785
|
+
return _temp6 && _temp6.then ? _temp6.then(_temp5) : _temp5(_temp6);
|
|
745
786
|
}
|
|
746
787
|
}());
|
|
747
788
|
} catch (e) {
|
|
@@ -776,7 +817,7 @@ var SessionAPI = /*#__PURE__*/function () {
|
|
|
776
817
|
return Promise.resolve(acFetch(_this4.baseUrl + "/v2/me", fetchParams)).then(function (response) {
|
|
777
818
|
var _exit3;
|
|
778
819
|
|
|
779
|
-
var
|
|
820
|
+
var _temp7 = function () {
|
|
780
821
|
if (response != null && response.ok) {
|
|
781
822
|
return Promise.resolve(response.json()).then(function (_ref2) {
|
|
782
823
|
var user = _ref2.user;
|
|
@@ -794,9 +835,9 @@ var SessionAPI = /*#__PURE__*/function () {
|
|
|
794
835
|
}
|
|
795
836
|
}();
|
|
796
837
|
|
|
797
|
-
return
|
|
838
|
+
return _temp7 && _temp7.then ? _temp7.then(function (_result3) {
|
|
798
839
|
return _exit3 ? _result3 : null;
|
|
799
|
-
}) : _exit3 ?
|
|
840
|
+
}) : _exit3 ? _temp7 : null;
|
|
800
841
|
});
|
|
801
842
|
} catch (e) {
|
|
802
843
|
return Promise.reject(e);
|
|
@@ -851,7 +892,9 @@ var SessionStore = /*#__PURE__*/function () {
|
|
|
851
892
|
authResponse: {
|
|
852
893
|
user: this.session.user,
|
|
853
894
|
accessToken: this.session.accessToken,
|
|
895
|
+
refreshToken: this.session.refreshToken,
|
|
854
896
|
tokenType: this.session.tokenType,
|
|
897
|
+
createdAt: this.session.createdAt,
|
|
855
898
|
expiresIn: this.session.expiresIn
|
|
856
899
|
}
|
|
857
900
|
};
|
|
@@ -922,28 +965,60 @@ var SessionStore = /*#__PURE__*/function () {
|
|
|
922
965
|
}
|
|
923
966
|
};
|
|
924
967
|
|
|
925
|
-
_proto2.
|
|
968
|
+
_proto2.refresh = function refresh() {
|
|
926
969
|
try {
|
|
927
970
|
var _this10 = this;
|
|
928
971
|
|
|
929
|
-
|
|
972
|
+
var _temp9 = function () {
|
|
973
|
+
if (_this10.session) {
|
|
974
|
+
return Promise.resolve(_this10.api.authorize({
|
|
975
|
+
refresh: _this10.session.refreshToken
|
|
976
|
+
})).then(function (session) {
|
|
977
|
+
if (session) {
|
|
978
|
+
_this10.session = _extends({}, _this10.session, session);
|
|
979
|
+
|
|
980
|
+
_this10.storeSession();
|
|
981
|
+
|
|
982
|
+
_this10.setConnectedLoginStatus();
|
|
983
|
+
} else {
|
|
984
|
+
_this10.removeSession();
|
|
985
|
+
|
|
986
|
+
_this10.removeCurrentUser();
|
|
987
|
+
|
|
988
|
+
_this10.setNotAuthorizedLoginStatus();
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
}();
|
|
993
|
+
|
|
994
|
+
return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function () {}) : void 0);
|
|
995
|
+
} catch (e) {
|
|
996
|
+
return Promise.reject(e);
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
_proto2.recover = function recover() {
|
|
1001
|
+
try {
|
|
1002
|
+
var _this12 = this;
|
|
1003
|
+
|
|
1004
|
+
if (_this12.session) {
|
|
930
1005
|
return Promise.resolve();
|
|
931
1006
|
}
|
|
932
1007
|
|
|
933
|
-
return Promise.resolve(
|
|
934
|
-
var
|
|
935
|
-
if (
|
|
936
|
-
return Promise.resolve(
|
|
937
|
-
|
|
1008
|
+
return Promise.resolve(_this12.restoreSession()).then(function () {
|
|
1009
|
+
var _temp10 = function () {
|
|
1010
|
+
if (_this12.session) {
|
|
1011
|
+
return Promise.resolve(_this12.api.getUserData()).then(function (user) {
|
|
1012
|
+
_this12.setCurrentUser(user);
|
|
938
1013
|
|
|
939
|
-
|
|
1014
|
+
_this12.setConnectedLoginStatus();
|
|
940
1015
|
});
|
|
941
1016
|
} else {
|
|
942
|
-
|
|
1017
|
+
_this12.setNotAuthorizedLoginStatus();
|
|
943
1018
|
}
|
|
944
1019
|
}();
|
|
945
1020
|
|
|
946
|
-
if (
|
|
1021
|
+
if (_temp10 && _temp10.then) return _temp10.then(function () {});
|
|
947
1022
|
});
|
|
948
1023
|
} catch (e) {
|
|
949
1024
|
return Promise.reject(e);
|
|
@@ -952,21 +1027,21 @@ var SessionStore = /*#__PURE__*/function () {
|
|
|
952
1027
|
|
|
953
1028
|
_proto2.logout = function logout() {
|
|
954
1029
|
try {
|
|
955
|
-
var
|
|
1030
|
+
var _this14 = this;
|
|
956
1031
|
|
|
957
|
-
var
|
|
958
|
-
if (
|
|
959
|
-
return Promise.resolve(
|
|
960
|
-
|
|
1032
|
+
var _temp12 = function () {
|
|
1033
|
+
if (_this14.session) {
|
|
1034
|
+
return Promise.resolve(_this14.api.signOut()).then(function () {
|
|
1035
|
+
_this14.removeSession();
|
|
961
1036
|
|
|
962
|
-
|
|
1037
|
+
_this14.removeCurrentUser();
|
|
963
1038
|
|
|
964
|
-
|
|
1039
|
+
_this14.setNotAuthorizedLoginStatus();
|
|
965
1040
|
});
|
|
966
1041
|
}
|
|
967
1042
|
}();
|
|
968
1043
|
|
|
969
|
-
return Promise.resolve(
|
|
1044
|
+
return Promise.resolve(_temp12 && _temp12.then ? _temp12.then(function () {}) : void 0);
|
|
970
1045
|
} catch (e) {
|
|
971
1046
|
return Promise.reject(e);
|
|
972
1047
|
}
|
|
@@ -974,12 +1049,14 @@ var SessionStore = /*#__PURE__*/function () {
|
|
|
974
1049
|
|
|
975
1050
|
_proto2.storeSession = function storeSession() {
|
|
976
1051
|
try {
|
|
977
|
-
var
|
|
1052
|
+
var _this16 = this;
|
|
978
1053
|
|
|
979
1054
|
var session_cookie = {};
|
|
980
|
-
session_cookie["access-token"] =
|
|
981
|
-
session_cookie["token
|
|
982
|
-
session_cookie["
|
|
1055
|
+
session_cookie["access-token"] = _this16.session.accessToken;
|
|
1056
|
+
session_cookie["refresh-token"] = _this16.session.refreshToken;
|
|
1057
|
+
session_cookie["token-type"] = _this16.session.tokenType;
|
|
1058
|
+
session_cookie["created-at"] = _this16.session.createdAt;
|
|
1059
|
+
session_cookie["expires-in"] = _this16.session.expiresIn;
|
|
983
1060
|
var authHeaders = JSON.stringify(session_cookie);
|
|
984
1061
|
CookiesManager.set("authHeaders", authHeaders);
|
|
985
1062
|
return Promise.resolve();
|
|
@@ -990,7 +1067,7 @@ var SessionStore = /*#__PURE__*/function () {
|
|
|
990
1067
|
|
|
991
1068
|
_proto2.restoreSession = function restoreSession() {
|
|
992
1069
|
try {
|
|
993
|
-
var
|
|
1070
|
+
var _this18 = this;
|
|
994
1071
|
|
|
995
1072
|
var cookie = CookiesManager.get("authHeaders");
|
|
996
1073
|
|
|
@@ -1001,12 +1078,14 @@ var SessionStore = /*#__PURE__*/function () {
|
|
|
1001
1078
|
var json = JSON.parse(cookie);
|
|
1002
1079
|
var session = new Session();
|
|
1003
1080
|
session.accessToken = json["access-token"];
|
|
1081
|
+
session.refreshToken = json["refresh-token"];
|
|
1004
1082
|
session.tokenType = json["token-type"];
|
|
1083
|
+
session.createdAt = json["created-at"];
|
|
1005
1084
|
session.expiresIn = json["expires-in"];
|
|
1006
|
-
|
|
1007
|
-
return Promise.resolve(
|
|
1085
|
+
_this18.session = session;
|
|
1086
|
+
return Promise.resolve(_this18.api.getUserData()).then(function (user) {
|
|
1008
1087
|
if (user) {
|
|
1009
|
-
|
|
1088
|
+
_this18.session.user = user;
|
|
1010
1089
|
}
|
|
1011
1090
|
});
|
|
1012
1091
|
} catch (e) {
|
|
@@ -3089,6 +3168,7 @@ var setLocale = function setLocale(locale) {
|
|
|
3089
3168
|
|
|
3090
3169
|
exports.App = App;
|
|
3091
3170
|
exports.Container = Container;
|
|
3171
|
+
exports.fetch = andoncloudFetch;
|
|
3092
3172
|
exports.logout = logout;
|
|
3093
3173
|
exports.notify = _t;
|
|
3094
3174
|
exports.setLocale = setLocale;
|