@sunggang/ui-lib 0.4.44 → 0.4.45
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/LiffProvider.cjs.js +74 -82
- package/LiffProvider.esm.js +74 -82
- package/package.json +1 -1
- package/src/lib/Provider/LiffProvider.d.ts +0 -1
package/LiffProvider.cjs.js
CHANGED
|
@@ -468,6 +468,8 @@ var LiffProvider = function(param) {
|
|
|
468
468
|
var userInfoStorageKey = "".concat(localStorageKey, "-userInfo");
|
|
469
469
|
// liff profile 的 localStorage key
|
|
470
470
|
var liffProfileStorageKey = "".concat(localStorageKey, "-liffProfile");
|
|
471
|
+
// liff initialized flag 的 localStorage key
|
|
472
|
+
var liffInitializedStorageKey = "".concat(localStorageKey, "-liffInitialized");
|
|
471
473
|
// 從 localStorage 載入 userInfo
|
|
472
474
|
var loadUserInfoFromStorage = function() {
|
|
473
475
|
try {
|
|
@@ -516,6 +518,16 @@ var LiffProvider = function(param) {
|
|
|
516
518
|
}, [
|
|
517
519
|
liffProfileStorageKey
|
|
518
520
|
]);
|
|
521
|
+
// 儲存 liffInitialized flag 到 localStorage
|
|
522
|
+
var saveLiffInitializedToStorage = React.useCallback(function() {
|
|
523
|
+
try {
|
|
524
|
+
window.localStorage.setItem(liffInitializedStorageKey, "1");
|
|
525
|
+
} catch (err) {
|
|
526
|
+
console.error("儲存 liffInitialized 失敗:", err);
|
|
527
|
+
}
|
|
528
|
+
}, [
|
|
529
|
+
liffInitializedStorageKey
|
|
530
|
+
]);
|
|
519
531
|
var fetchMemberInfo = function() {
|
|
520
532
|
var _ref = _async_to_generator(function(token) {
|
|
521
533
|
var response, err;
|
|
@@ -624,6 +636,13 @@ var LiffProvider = function(param) {
|
|
|
624
636
|
// token 無效時清除 userInfo
|
|
625
637
|
setUserInfo(null);
|
|
626
638
|
window.localStorage.removeItem(userInfoStorageKey);
|
|
639
|
+
// token 無效也清除 liff 相關快取與已初始化標記
|
|
640
|
+
try {
|
|
641
|
+
window.localStorage.removeItem(liffProfileStorageKey);
|
|
642
|
+
window.localStorage.removeItem(liffInitializedStorageKey);
|
|
643
|
+
} catch (e) {
|
|
644
|
+
// ignore
|
|
645
|
+
}
|
|
627
646
|
return [
|
|
628
647
|
3,
|
|
629
648
|
7
|
|
@@ -858,13 +877,27 @@ var LiffProvider = function(param) {
|
|
|
858
877
|
}();
|
|
859
878
|
// 確保 LIFF init 只執行一次且在需要時才執行
|
|
860
879
|
var ensureLiffInitialized = React.useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
861
|
-
var customFetch, liff, originalFetch,
|
|
880
|
+
var storedFlag, customFetch, liff, originalFetch, profile, e1;
|
|
862
881
|
return _ts_generator(this, function(_state) {
|
|
863
882
|
switch(_state.label){
|
|
864
883
|
case 0:
|
|
884
|
+
console.log("ensureLiffInitialized called", liffInitialized);
|
|
885
|
+
// 如果 state 或 localStorage 上已有 initialized 的標記,就視為已初始化
|
|
865
886
|
if (liffInitialized) return [
|
|
866
887
|
2
|
|
867
888
|
];
|
|
889
|
+
try {
|
|
890
|
+
storedFlag = window.localStorage.getItem(liffInitializedStorageKey);
|
|
891
|
+
if (storedFlag === "1") {
|
|
892
|
+
setLiffInitialized(true);
|
|
893
|
+
console.log("liffInitialized loaded from storage");
|
|
894
|
+
return [
|
|
895
|
+
2
|
|
896
|
+
];
|
|
897
|
+
}
|
|
898
|
+
} catch (e) {
|
|
899
|
+
// ignore
|
|
900
|
+
}
|
|
868
901
|
if (!liffId) {
|
|
869
902
|
console.warn("liffId 未提供,跳過 liff.init()。");
|
|
870
903
|
return [
|
|
@@ -875,9 +908,9 @@ var LiffProvider = function(param) {
|
|
|
875
908
|
case 1:
|
|
876
909
|
_state.trys.push([
|
|
877
910
|
1,
|
|
878
|
-
|
|
911
|
+
8,
|
|
879
912
|
,
|
|
880
|
-
|
|
913
|
+
9
|
|
881
914
|
]);
|
|
882
915
|
customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
|
|
883
916
|
// eslint-disable-next-line no-inner-declarations
|
|
@@ -905,21 +938,49 @@ var LiffProvider = function(param) {
|
|
|
905
938
|
];
|
|
906
939
|
case 3:
|
|
907
940
|
_state.sent();
|
|
941
|
+
_state.label = 4;
|
|
942
|
+
case 4:
|
|
943
|
+
_state.trys.push([
|
|
944
|
+
4,
|
|
945
|
+
6,
|
|
946
|
+
,
|
|
947
|
+
7
|
|
948
|
+
]);
|
|
949
|
+
return [
|
|
950
|
+
4,
|
|
951
|
+
liff.getProfile()
|
|
952
|
+
];
|
|
953
|
+
case 5:
|
|
954
|
+
profile = _state.sent();
|
|
955
|
+
setLiffProfile(profile);
|
|
956
|
+
saveLiffProfileToStorage(profile);
|
|
957
|
+
return [
|
|
958
|
+
3,
|
|
959
|
+
7
|
|
960
|
+
];
|
|
961
|
+
case 6:
|
|
962
|
+
_state.sent();
|
|
963
|
+
return [
|
|
964
|
+
3,
|
|
965
|
+
7
|
|
966
|
+
];
|
|
967
|
+
case 7:
|
|
908
968
|
setLiffObject(liff);
|
|
909
969
|
setLiffInitialized(true);
|
|
970
|
+
saveLiffInitializedToStorage();
|
|
910
971
|
console.log("LIFF initialized.");
|
|
911
972
|
return [
|
|
912
973
|
3,
|
|
913
|
-
|
|
974
|
+
9
|
|
914
975
|
];
|
|
915
|
-
case
|
|
916
|
-
|
|
917
|
-
console.error("ensureLiffInitialized failed:",
|
|
976
|
+
case 8:
|
|
977
|
+
e1 = _state.sent();
|
|
978
|
+
console.error("ensureLiffInitialized failed:", e1);
|
|
918
979
|
return [
|
|
919
980
|
3,
|
|
920
|
-
|
|
981
|
+
9
|
|
921
982
|
];
|
|
922
|
-
case
|
|
983
|
+
case 9:
|
|
923
984
|
return [
|
|
924
985
|
2
|
|
925
986
|
];
|
|
@@ -928,7 +989,10 @@ var LiffProvider = function(param) {
|
|
|
928
989
|
}), [
|
|
929
990
|
liffInitialized,
|
|
930
991
|
liffId,
|
|
931
|
-
openInApp
|
|
992
|
+
openInApp,
|
|
993
|
+
saveLiffInitializedToStorage,
|
|
994
|
+
saveLiffProfileToStorage,
|
|
995
|
+
liffInitializedStorageKey
|
|
932
996
|
]);
|
|
933
997
|
var accountLogin = function() {
|
|
934
998
|
var _ref = _async_to_generator(function(username, password) {
|
|
@@ -1001,77 +1065,6 @@ var LiffProvider = function(param) {
|
|
|
1001
1065
|
return _ref.apply(this, arguments);
|
|
1002
1066
|
};
|
|
1003
1067
|
}();
|
|
1004
|
-
// 取得 LIFF profile(LIFF 的會員資料,與 API 的 member 分開處理)
|
|
1005
|
-
var getLiffProfile = React.useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
1006
|
-
var sdk, imported, profile, err;
|
|
1007
|
-
return _ts_generator(this, function(_state) {
|
|
1008
|
-
switch(_state.label){
|
|
1009
|
-
case 0:
|
|
1010
|
-
_state.trys.push([
|
|
1011
|
-
0,
|
|
1012
|
-
5,
|
|
1013
|
-
,
|
|
1014
|
-
6
|
|
1015
|
-
]);
|
|
1016
|
-
// 確保 LIFF 已初始化
|
|
1017
|
-
return [
|
|
1018
|
-
4,
|
|
1019
|
-
ensureLiffInitialized()
|
|
1020
|
-
];
|
|
1021
|
-
case 1:
|
|
1022
|
-
_state.sent();
|
|
1023
|
-
sdk = liffObject;
|
|
1024
|
-
if (!!sdk) return [
|
|
1025
|
-
3,
|
|
1026
|
-
3
|
|
1027
|
-
];
|
|
1028
|
-
return [
|
|
1029
|
-
4,
|
|
1030
|
-
Promise.resolve().then(function () { return require('./index.cjs3.js'); })
|
|
1031
|
-
];
|
|
1032
|
-
case 2:
|
|
1033
|
-
imported = _state.sent();
|
|
1034
|
-
sdk = imported.liff;
|
|
1035
|
-
setLiffObject(sdk);
|
|
1036
|
-
_state.label = 3;
|
|
1037
|
-
case 3:
|
|
1038
|
-
if (!sdk || typeof sdk.isLoggedIn !== "function" || !sdk.isLoggedIn()) {
|
|
1039
|
-
console.warn("getLiffProfile: LIFF not initialized or user not logged in");
|
|
1040
|
-
return [
|
|
1041
|
-
2,
|
|
1042
|
-
null
|
|
1043
|
-
];
|
|
1044
|
-
}
|
|
1045
|
-
return [
|
|
1046
|
-
4,
|
|
1047
|
-
sdk.getProfile()
|
|
1048
|
-
];
|
|
1049
|
-
case 4:
|
|
1050
|
-
profile = _state.sent();
|
|
1051
|
-
setLiffProfile(profile);
|
|
1052
|
-
saveLiffProfileToStorage(profile);
|
|
1053
|
-
return [
|
|
1054
|
-
2,
|
|
1055
|
-
profile
|
|
1056
|
-
];
|
|
1057
|
-
case 5:
|
|
1058
|
-
err = _state.sent();
|
|
1059
|
-
console.error("取得 LIFF profile 失敗:", err);
|
|
1060
|
-
return [
|
|
1061
|
-
2,
|
|
1062
|
-
null
|
|
1063
|
-
];
|
|
1064
|
-
case 6:
|
|
1065
|
-
return [
|
|
1066
|
-
2
|
|
1067
|
-
];
|
|
1068
|
-
}
|
|
1069
|
-
});
|
|
1070
|
-
}), [
|
|
1071
|
-
liffObject,
|
|
1072
|
-
ensureLiffInitialized,
|
|
1073
|
-
saveLiffProfileToStorage
|
|
1074
|
-
]);
|
|
1075
1068
|
var ensureLiffTokenValid = React.useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
1076
1069
|
var _parsedStore_data, _parsedStore_state, jwtTokenValue, jwtToken, parsedStore, isValid, _tmp, err;
|
|
1077
1070
|
return _ts_generator(this, function(_state) {
|
|
@@ -1257,7 +1250,6 @@ var LiffProvider = function(param) {
|
|
|
1257
1250
|
initializeLiff: function() {
|
|
1258
1251
|
return initializeLiff(false);
|
|
1259
1252
|
},
|
|
1260
|
-
getLiffProfile: getLiffProfile,
|
|
1261
1253
|
liffProfile: liffProfile,
|
|
1262
1254
|
isFriendship: isFriendship,
|
|
1263
1255
|
ensureLiffTokenValid: ensureLiffTokenValid,
|
package/LiffProvider.esm.js
CHANGED
|
@@ -464,6 +464,8 @@ var LiffProvider = function(param) {
|
|
|
464
464
|
var userInfoStorageKey = "".concat(localStorageKey, "-userInfo");
|
|
465
465
|
// liff profile 的 localStorage key
|
|
466
466
|
var liffProfileStorageKey = "".concat(localStorageKey, "-liffProfile");
|
|
467
|
+
// liff initialized flag 的 localStorage key
|
|
468
|
+
var liffInitializedStorageKey = "".concat(localStorageKey, "-liffInitialized");
|
|
467
469
|
// 從 localStorage 載入 userInfo
|
|
468
470
|
var loadUserInfoFromStorage = function() {
|
|
469
471
|
try {
|
|
@@ -512,6 +514,16 @@ var LiffProvider = function(param) {
|
|
|
512
514
|
}, [
|
|
513
515
|
liffProfileStorageKey
|
|
514
516
|
]);
|
|
517
|
+
// 儲存 liffInitialized flag 到 localStorage
|
|
518
|
+
var saveLiffInitializedToStorage = useCallback(function() {
|
|
519
|
+
try {
|
|
520
|
+
window.localStorage.setItem(liffInitializedStorageKey, "1");
|
|
521
|
+
} catch (err) {
|
|
522
|
+
console.error("儲存 liffInitialized 失敗:", err);
|
|
523
|
+
}
|
|
524
|
+
}, [
|
|
525
|
+
liffInitializedStorageKey
|
|
526
|
+
]);
|
|
515
527
|
var fetchMemberInfo = function() {
|
|
516
528
|
var _ref = _async_to_generator(function(token) {
|
|
517
529
|
var response, err;
|
|
@@ -620,6 +632,13 @@ var LiffProvider = function(param) {
|
|
|
620
632
|
// token 無效時清除 userInfo
|
|
621
633
|
setUserInfo(null);
|
|
622
634
|
window.localStorage.removeItem(userInfoStorageKey);
|
|
635
|
+
// token 無效也清除 liff 相關快取與已初始化標記
|
|
636
|
+
try {
|
|
637
|
+
window.localStorage.removeItem(liffProfileStorageKey);
|
|
638
|
+
window.localStorage.removeItem(liffInitializedStorageKey);
|
|
639
|
+
} catch (e) {
|
|
640
|
+
// ignore
|
|
641
|
+
}
|
|
623
642
|
return [
|
|
624
643
|
3,
|
|
625
644
|
7
|
|
@@ -854,13 +873,27 @@ var LiffProvider = function(param) {
|
|
|
854
873
|
}();
|
|
855
874
|
// 確保 LIFF init 只執行一次且在需要時才執行
|
|
856
875
|
var ensureLiffInitialized = useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
857
|
-
var customFetch, liff, originalFetch,
|
|
876
|
+
var storedFlag, customFetch, liff, originalFetch, profile, e1;
|
|
858
877
|
return _ts_generator(this, function(_state) {
|
|
859
878
|
switch(_state.label){
|
|
860
879
|
case 0:
|
|
880
|
+
console.log("ensureLiffInitialized called", liffInitialized);
|
|
881
|
+
// 如果 state 或 localStorage 上已有 initialized 的標記,就視為已初始化
|
|
861
882
|
if (liffInitialized) return [
|
|
862
883
|
2
|
|
863
884
|
];
|
|
885
|
+
try {
|
|
886
|
+
storedFlag = window.localStorage.getItem(liffInitializedStorageKey);
|
|
887
|
+
if (storedFlag === "1") {
|
|
888
|
+
setLiffInitialized(true);
|
|
889
|
+
console.log("liffInitialized loaded from storage");
|
|
890
|
+
return [
|
|
891
|
+
2
|
|
892
|
+
];
|
|
893
|
+
}
|
|
894
|
+
} catch (e) {
|
|
895
|
+
// ignore
|
|
896
|
+
}
|
|
864
897
|
if (!liffId) {
|
|
865
898
|
console.warn("liffId 未提供,跳過 liff.init()。");
|
|
866
899
|
return [
|
|
@@ -871,9 +904,9 @@ var LiffProvider = function(param) {
|
|
|
871
904
|
case 1:
|
|
872
905
|
_state.trys.push([
|
|
873
906
|
1,
|
|
874
|
-
|
|
907
|
+
8,
|
|
875
908
|
,
|
|
876
|
-
|
|
909
|
+
9
|
|
877
910
|
]);
|
|
878
911
|
customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
|
|
879
912
|
// eslint-disable-next-line no-inner-declarations
|
|
@@ -901,21 +934,49 @@ var LiffProvider = function(param) {
|
|
|
901
934
|
];
|
|
902
935
|
case 3:
|
|
903
936
|
_state.sent();
|
|
937
|
+
_state.label = 4;
|
|
938
|
+
case 4:
|
|
939
|
+
_state.trys.push([
|
|
940
|
+
4,
|
|
941
|
+
6,
|
|
942
|
+
,
|
|
943
|
+
7
|
|
944
|
+
]);
|
|
945
|
+
return [
|
|
946
|
+
4,
|
|
947
|
+
liff.getProfile()
|
|
948
|
+
];
|
|
949
|
+
case 5:
|
|
950
|
+
profile = _state.sent();
|
|
951
|
+
setLiffProfile(profile);
|
|
952
|
+
saveLiffProfileToStorage(profile);
|
|
953
|
+
return [
|
|
954
|
+
3,
|
|
955
|
+
7
|
|
956
|
+
];
|
|
957
|
+
case 6:
|
|
958
|
+
_state.sent();
|
|
959
|
+
return [
|
|
960
|
+
3,
|
|
961
|
+
7
|
|
962
|
+
];
|
|
963
|
+
case 7:
|
|
904
964
|
setLiffObject(liff);
|
|
905
965
|
setLiffInitialized(true);
|
|
966
|
+
saveLiffInitializedToStorage();
|
|
906
967
|
console.log("LIFF initialized.");
|
|
907
968
|
return [
|
|
908
969
|
3,
|
|
909
|
-
|
|
970
|
+
9
|
|
910
971
|
];
|
|
911
|
-
case
|
|
912
|
-
|
|
913
|
-
console.error("ensureLiffInitialized failed:",
|
|
972
|
+
case 8:
|
|
973
|
+
e1 = _state.sent();
|
|
974
|
+
console.error("ensureLiffInitialized failed:", e1);
|
|
914
975
|
return [
|
|
915
976
|
3,
|
|
916
|
-
|
|
977
|
+
9
|
|
917
978
|
];
|
|
918
|
-
case
|
|
979
|
+
case 9:
|
|
919
980
|
return [
|
|
920
981
|
2
|
|
921
982
|
];
|
|
@@ -924,7 +985,10 @@ var LiffProvider = function(param) {
|
|
|
924
985
|
}), [
|
|
925
986
|
liffInitialized,
|
|
926
987
|
liffId,
|
|
927
|
-
openInApp
|
|
988
|
+
openInApp,
|
|
989
|
+
saveLiffInitializedToStorage,
|
|
990
|
+
saveLiffProfileToStorage,
|
|
991
|
+
liffInitializedStorageKey
|
|
928
992
|
]);
|
|
929
993
|
var accountLogin = function() {
|
|
930
994
|
var _ref = _async_to_generator(function(username, password) {
|
|
@@ -997,77 +1061,6 @@ var LiffProvider = function(param) {
|
|
|
997
1061
|
return _ref.apply(this, arguments);
|
|
998
1062
|
};
|
|
999
1063
|
}();
|
|
1000
|
-
// 取得 LIFF profile(LIFF 的會員資料,與 API 的 member 分開處理)
|
|
1001
|
-
var getLiffProfile = useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
1002
|
-
var sdk, imported, profile, err;
|
|
1003
|
-
return _ts_generator(this, function(_state) {
|
|
1004
|
-
switch(_state.label){
|
|
1005
|
-
case 0:
|
|
1006
|
-
_state.trys.push([
|
|
1007
|
-
0,
|
|
1008
|
-
5,
|
|
1009
|
-
,
|
|
1010
|
-
6
|
|
1011
|
-
]);
|
|
1012
|
-
// 確保 LIFF 已初始化
|
|
1013
|
-
return [
|
|
1014
|
-
4,
|
|
1015
|
-
ensureLiffInitialized()
|
|
1016
|
-
];
|
|
1017
|
-
case 1:
|
|
1018
|
-
_state.sent();
|
|
1019
|
-
sdk = liffObject;
|
|
1020
|
-
if (!!sdk) return [
|
|
1021
|
-
3,
|
|
1022
|
-
3
|
|
1023
|
-
];
|
|
1024
|
-
return [
|
|
1025
|
-
4,
|
|
1026
|
-
import('./index.esm3.js')
|
|
1027
|
-
];
|
|
1028
|
-
case 2:
|
|
1029
|
-
imported = _state.sent();
|
|
1030
|
-
sdk = imported.liff;
|
|
1031
|
-
setLiffObject(sdk);
|
|
1032
|
-
_state.label = 3;
|
|
1033
|
-
case 3:
|
|
1034
|
-
if (!sdk || typeof sdk.isLoggedIn !== "function" || !sdk.isLoggedIn()) {
|
|
1035
|
-
console.warn("getLiffProfile: LIFF not initialized or user not logged in");
|
|
1036
|
-
return [
|
|
1037
|
-
2,
|
|
1038
|
-
null
|
|
1039
|
-
];
|
|
1040
|
-
}
|
|
1041
|
-
return [
|
|
1042
|
-
4,
|
|
1043
|
-
sdk.getProfile()
|
|
1044
|
-
];
|
|
1045
|
-
case 4:
|
|
1046
|
-
profile = _state.sent();
|
|
1047
|
-
setLiffProfile(profile);
|
|
1048
|
-
saveLiffProfileToStorage(profile);
|
|
1049
|
-
return [
|
|
1050
|
-
2,
|
|
1051
|
-
profile
|
|
1052
|
-
];
|
|
1053
|
-
case 5:
|
|
1054
|
-
err = _state.sent();
|
|
1055
|
-
console.error("取得 LIFF profile 失敗:", err);
|
|
1056
|
-
return [
|
|
1057
|
-
2,
|
|
1058
|
-
null
|
|
1059
|
-
];
|
|
1060
|
-
case 6:
|
|
1061
|
-
return [
|
|
1062
|
-
2
|
|
1063
|
-
];
|
|
1064
|
-
}
|
|
1065
|
-
});
|
|
1066
|
-
}), [
|
|
1067
|
-
liffObject,
|
|
1068
|
-
ensureLiffInitialized,
|
|
1069
|
-
saveLiffProfileToStorage
|
|
1070
|
-
]);
|
|
1071
1064
|
var ensureLiffTokenValid = useCallback(/*#__PURE__*/ _async_to_generator(function() {
|
|
1072
1065
|
var _parsedStore_data, _parsedStore_state, jwtTokenValue, jwtToken, parsedStore, isValid, _tmp, err;
|
|
1073
1066
|
return _ts_generator(this, function(_state) {
|
|
@@ -1253,7 +1246,6 @@ var LiffProvider = function(param) {
|
|
|
1253
1246
|
initializeLiff: function() {
|
|
1254
1247
|
return initializeLiff(false);
|
|
1255
1248
|
},
|
|
1256
|
-
getLiffProfile: getLiffProfile,
|
|
1257
1249
|
liffProfile: liffProfile,
|
|
1258
1250
|
isFriendship: isFriendship,
|
|
1259
1251
|
ensureLiffTokenValid: ensureLiffTokenValid,
|
package/package.json
CHANGED
|
@@ -7,7 +7,6 @@ type LiffContextType = {
|
|
|
7
7
|
accessToken: string;
|
|
8
8
|
liffError: string | null;
|
|
9
9
|
initializeLiff: () => Promise<void>;
|
|
10
|
-
getLiffProfile: () => Promise<any | null>;
|
|
11
10
|
isFriendship: boolean | null;
|
|
12
11
|
ensureLiffTokenValid: () => Promise<boolean>;
|
|
13
12
|
loginType: string | null;
|