@sunggang/ui-lib 0.4.54 → 0.4.56

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.
@@ -463,6 +463,7 @@ var LiffProvider = function(param) {
463
463
  var _useState5 = _sliced_to_array(React.useState(null), 2), liffProfile = _useState5[0], setLiffProfile = _useState5[1];
464
464
  var _useState6 = _sliced_to_array(React.useState(null), 2), isFriendship = _useState6[0], setFriendship = _useState6[1];
465
465
  var _useState7 = _sliced_to_array(React.useState(null), 2), loginType = _useState7[0], setLoginType = _useState7[1];
466
+ var isProcessingLiffCallback = React.useRef(false);
466
467
  // userInfo 的 localStorage key
467
468
  var userInfoStorageKey = "".concat(localStorageKey, "-userInfo");
468
469
  // liff profile 的 localStorage key
@@ -765,235 +766,187 @@ var LiffProvider = function(param) {
765
766
  };
766
767
  }();
767
768
  // 初始化 LIFF
768
- var initPromiseRef = React.useRef(null);
769
769
  var initializeLiff = function() {
770
770
  var _ref = _async_to_generator(function(isValid) {
771
+ var customFetch, liff, urlParams, hasLiffParams, originalFetch, storedProfileExists, profile, profileErr, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
771
772
  return _ts_generator(this, function(_state) {
772
- // 如果已有執行中的 initialize promise,直接等待它
773
- if (initPromiseRef.current) return [
774
- 2,
775
- initPromiseRef.current
776
- ];
777
- initPromiseRef.current = _async_to_generator(function() {
778
- var customFetch, initializedFlagKey, alreadyInitialized, liffModule, e, liff, originalFetch, storedProfileExists, profile, profileErr, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
779
- return _ts_generator(this, function(_state) {
780
- switch(_state.label){
781
- case 0:
782
- _state.trys.push([
783
- 0,
784
- 19,
785
- 20,
786
- 21
787
- ]);
788
- customFetch = // eslint-disable-next-line no-inner-declarations
789
- function customFetch(url, options) {
790
- if (url.toString().startsWith("https://liffsdk.line-scdn.net/xlt/") && url.toString().endsWith(".json")) {
791
- url = "".concat(url, "?ts=").concat(Math.random());
792
- }
793
- return originalFetch(url, options);
794
- };
795
- initializedFlagKey = "".concat(localStorageKey, "-liffInitialized");
796
- // 若之前已紀錄為 initialized,嘗試直接載入 SDK 並重用
797
- alreadyInitialized = !!window.localStorage.getItem(initializedFlagKey);
798
- liffModule = null;
799
- _state.label = 1;
800
- case 1:
801
- _state.trys.push([
802
- 1,
803
- 3,
804
- ,
805
- 4
806
- ]);
807
- return [
808
- 4,
809
- Promise.resolve().then(function () { return require('./index.cjs3.js'); })
810
- ];
811
- case 2:
812
- liffModule = _state.sent();
813
- return [
814
- 3,
815
- 4
816
- ];
817
- case 3:
818
- e = _state.sent();
819
- console.warn("載入 @line/liff 失敗:", e);
820
- throw e;
821
- case 4:
822
- liff = liffModule.liff;
823
- originalFetch = window.fetch;
824
- window.fetch = customFetch;
825
- // 如果記錄存在,嘗試重用 SDK 物件(不一定需要再呼叫 init)
826
- if (alreadyInitialized) {
827
- try {
828
- setLiffObject(liff);
829
- console.log("Reused LIFF SDK from persisted flag.");
830
- } catch (e) {
831
- console.warn("重用 LIFF SDK 失敗,將重新 init", e);
832
- }
833
- }
834
- if (!!alreadyInitialized) return [
835
- 3,
836
- 6
837
- ];
838
- if (openInApp && !(liff === null || liff === void 0 ? void 0 : liff.isInClient()) && (liff === null || liff === void 0 ? void 0 : liff.getOS()) !== "web") window.location.href = "line://app/".concat(liffId);
839
- return [
840
- 4,
841
- liff.init({
842
- liffId: liffId,
843
- withLoginOnExternalBrowser: false
844
- })
845
- ];
846
- case 5:
847
- _state.sent();
848
- // 設定 persisted flag,避免重新整理時重複 init
849
- try {
850
- window.localStorage.setItem(initializedFlagKey, "1");
851
- } catch (e) {
852
- // ignore
853
- }
854
- console.log("LIFF init succeeded.");
855
- setLiffObject(liff);
856
- _state.label = 6;
857
- case 6:
858
- // 如果 localStorage 或 state 已有 profile,就跳過重複呼叫
859
- storedProfileExists = false;
860
- try {
861
- storedProfileExists = !!window.localStorage.getItem(liffUserInfoStorageKey);
862
- } catch (e) {
863
- storedProfileExists = false;
864
- }
865
- if (!(!storedProfileExists && !liffProfile)) return [
866
- 3,
867
- 11
868
- ];
869
- _state.label = 7;
870
- case 7:
871
- _state.trys.push([
872
- 7,
873
- 9,
874
- ,
875
- 10
876
- ]);
877
- return [
878
- 4,
879
- liff.getProfile()
880
- ];
881
- case 8:
882
- profile = _state.sent();
883
- setLiffProfile(profile);
884
- saveLiffUserInfoToStorage(profile);
885
- return [
886
- 3,
887
- 10
888
- ];
889
- case 9:
890
- profileErr = _state.sent();
891
- console.warn("取得 LIFF profile 失敗(非致命):", profileErr);
892
- return [
893
- 3,
894
- 10
895
- ];
896
- case 10:
897
- return [
898
- 3,
899
- 12
900
- ];
901
- case 11:
902
- console.log("跳過 liff.getProfile():已由 localStorage 或 state 取得 profile");
903
- _state.label = 12;
904
- case 12:
905
- lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
906
- // 未登入先進行登入
907
- if (!liff.isLoggedIn()) {
908
- redirectUri = customerRedirectUrl || "".concat(window.location.href);
909
- if (liffLogin) {
910
- liff.login({
911
- redirectUri: redirectUri
912
- });
913
- return [
914
- 2
915
- ];
916
- }
917
- if (loginByUser || ignoreRoute) return [
918
- 2
919
- ];
920
- liff.login({
921
- redirectUri: redirectUri
922
- });
923
- }
924
- tempFriendship = null;
925
- if (!lineToken) return [
926
- 3,
927
- 18
928
- ];
929
- _state.label = 13;
930
- case 13:
931
- _state.trys.push([
932
- 13,
933
- 15,
934
- ,
935
- 16
936
- ]);
937
- return [
938
- 4,
939
- liff.getFriendship()
940
- ];
941
- case 14:
942
- friendship = _state.sent();
943
- friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
944
- setFriendship(friendFlag);
945
- tempFriendship = friendFlag;
946
- console.log("isFriendship", friendFlag);
947
- return [
948
- 3,
949
- 16
950
- ];
951
- case 15:
952
- error = _state.sent();
953
- console.error("Error in liff.getFriendship():", error);
954
- return [
955
- 3,
956
- 16
957
- ];
958
- case 16:
959
- console.log("isValid", isValid);
960
- if (tempFriendship && isValid) return [
961
- 2
962
- ];
963
- return [
964
- 4,
965
- loginInit(lineToken)
966
- ];
967
- case 17:
968
- _state.sent();
969
- _state.label = 18;
970
- case 18:
971
- return [
972
- 3,
973
- 21
974
- ];
975
- case 19:
976
- err = _state.sent();
977
- setLiffError((err === null || err === void 0 ? void 0 : err.toString) ? err.toString() : String(err));
978
- console.log("LIFF init failed.", err);
979
- throw err;
980
- case 20:
981
- // 清除 reference,允許下次再次初始化(若需要)
982
- initPromiseRef.current = null;
983
- return [
984
- 7
985
- ];
986
- case 21:
773
+ switch(_state.label){
774
+ case 0:
775
+ _state.trys.push([
776
+ 0,
777
+ 15,
778
+ ,
779
+ 16
780
+ ]);
781
+ customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
782
+ // eslint-disable-next-line no-inner-declarations
783
+ function customFetch(url, options) {
784
+ if (url.toString().startsWith("https://liffsdk.line-scdn.net/xlt/") && url.toString().endsWith(".json")) {
785
+ url = "".concat(url, "?ts=").concat(Math.random());
786
+ }
787
+ return originalFetch(url, options);
788
+ };
789
+ return [
790
+ 4,
791
+ Promise.resolve().then(function () { return require('./index.cjs3.js'); })
792
+ ];
793
+ case 1:
794
+ liff = _state.sent().liff;
795
+ urlParams = new URLSearchParams(window.location.search);
796
+ hasLiffParams = urlParams.has("liffClientId") || urlParams.has("liffRedirectUri");
797
+ originalFetch = window.fetch;
798
+ window.fetch = customFetch;
799
+ if (openInApp && !(liff === null || liff === void 0 ? void 0 : liff.isInClient()) && (liff === null || liff === void 0 ? void 0 : liff.getOS()) !== "web") window.location.href = "line://app/".concat(liffId);
800
+ if (hasLiffParams || isProcessingLiffCallback.current) {
801
+ isProcessingLiffCallback.current = true;
802
+ return [
803
+ 2
804
+ ];
805
+ }
806
+ return [
807
+ 4,
808
+ liff.init({
809
+ liffId: liffId,
810
+ withLoginOnExternalBrowser: false
811
+ })
812
+ ];
813
+ case 2:
814
+ _state.sent();
815
+ console.log("LIFF init succeeded.");
816
+ isProcessingLiffCallback.current = true;
817
+ setLiffObject(liff);
818
+ // 如果 localStorage 或 state 已有 profile,就跳過重複呼叫
819
+ storedProfileExists = false;
820
+ try {
821
+ storedProfileExists = !!window.localStorage.getItem(liffUserInfoStorageKey);
822
+ } catch (e) {
823
+ storedProfileExists = false;
824
+ isProcessingLiffCallback.current = false;
825
+ }
826
+ if (!(!storedProfileExists && !liffProfile)) return [
827
+ 3,
828
+ 7
829
+ ];
830
+ _state.label = 3;
831
+ case 3:
832
+ _state.trys.push([
833
+ 3,
834
+ 5,
835
+ ,
836
+ 6
837
+ ]);
838
+ return [
839
+ 4,
840
+ liff.getProfile()
841
+ ];
842
+ case 4:
843
+ profile = _state.sent();
844
+ setLiffProfile(profile);
845
+ saveLiffUserInfoToStorage(profile);
846
+ return [
847
+ 3,
848
+ 6
849
+ ];
850
+ case 5:
851
+ profileErr = _state.sent();
852
+ console.warn("取得 LIFF profile 失敗(非致命):", profileErr);
853
+ return [
854
+ 3,
855
+ 6
856
+ ];
857
+ case 6:
858
+ return [
859
+ 3,
860
+ 8
861
+ ];
862
+ case 7:
863
+ // 已有快取,跳過呼叫
864
+ console.log("跳過 liff.getProfile():已由 localStorage 或 state 取得 profile");
865
+ _state.label = 8;
866
+ case 8:
867
+ lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
868
+ // 未登入先進行登入
869
+ if (!liff.isLoggedIn()) {
870
+ redirectUri = customerRedirectUrl || "".concat(window.location.href);
871
+ if (liffLogin) {
872
+ liff.login({
873
+ redirectUri: redirectUri
874
+ });
987
875
  return [
988
876
  2
989
877
  ];
878
+ }
879
+ if (loginByUser || ignoreRoute) return [
880
+ 2
881
+ ];
882
+ liff.login({
883
+ redirectUri: redirectUri
884
+ });
990
885
  }
991
- });
992
- })();
993
- return [
994
- 2,
995
- initPromiseRef.current
996
- ];
886
+ tempFriendship = null;
887
+ if (!lineToken) return [
888
+ 3,
889
+ 14
890
+ ];
891
+ _state.label = 9;
892
+ case 9:
893
+ _state.trys.push([
894
+ 9,
895
+ 11,
896
+ ,
897
+ 12
898
+ ]);
899
+ return [
900
+ 4,
901
+ liff.getFriendship()
902
+ ];
903
+ case 10:
904
+ friendship = _state.sent();
905
+ friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
906
+ setFriendship(friendFlag);
907
+ tempFriendship = friendFlag;
908
+ console.log("isFriendship", friendFlag);
909
+ return [
910
+ 3,
911
+ 12
912
+ ];
913
+ case 11:
914
+ error = _state.sent();
915
+ console.error("Error in liff.getFriendship():", error);
916
+ return [
917
+ 3,
918
+ 12
919
+ ];
920
+ case 12:
921
+ console.log("isValid", isValid);
922
+ if (tempFriendship && isValid) return [
923
+ 2
924
+ ];
925
+ return [
926
+ 4,
927
+ loginInit(lineToken)
928
+ ];
929
+ case 13:
930
+ _state.sent();
931
+ _state.label = 14;
932
+ case 14:
933
+ return [
934
+ 3,
935
+ 16
936
+ ];
937
+ case 15:
938
+ err = _state.sent();
939
+ setLiffError(err.toString());
940
+ console.log("LIFF init failed.", err);
941
+ return [
942
+ 3,
943
+ 16
944
+ ];
945
+ case 16:
946
+ return [
947
+ 2
948
+ ];
949
+ }
997
950
  });
998
951
  });
999
952
  return function initializeLiff(isValid) {
@@ -459,6 +459,7 @@ var LiffProvider = function(param) {
459
459
  var _useState5 = _sliced_to_array(useState(null), 2), liffProfile = _useState5[0], setLiffProfile = _useState5[1];
460
460
  var _useState6 = _sliced_to_array(useState(null), 2), isFriendship = _useState6[0], setFriendship = _useState6[1];
461
461
  var _useState7 = _sliced_to_array(useState(null), 2), loginType = _useState7[0], setLoginType = _useState7[1];
462
+ var isProcessingLiffCallback = useRef(false);
462
463
  // userInfo 的 localStorage key
463
464
  var userInfoStorageKey = "".concat(localStorageKey, "-userInfo");
464
465
  // liff profile 的 localStorage key
@@ -761,235 +762,187 @@ var LiffProvider = function(param) {
761
762
  };
762
763
  }();
763
764
  // 初始化 LIFF
764
- var initPromiseRef = useRef(null);
765
765
  var initializeLiff = function() {
766
766
  var _ref = _async_to_generator(function(isValid) {
767
+ var customFetch, liff, urlParams, hasLiffParams, originalFetch, storedProfileExists, profile, profileErr, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
767
768
  return _ts_generator(this, function(_state) {
768
- // 如果已有執行中的 initialize promise,直接等待它
769
- if (initPromiseRef.current) return [
770
- 2,
771
- initPromiseRef.current
772
- ];
773
- initPromiseRef.current = _async_to_generator(function() {
774
- var customFetch, initializedFlagKey, alreadyInitialized, liffModule, e, liff, originalFetch, storedProfileExists, profile, profileErr, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
775
- return _ts_generator(this, function(_state) {
776
- switch(_state.label){
777
- case 0:
778
- _state.trys.push([
779
- 0,
780
- 19,
781
- 20,
782
- 21
783
- ]);
784
- customFetch = // eslint-disable-next-line no-inner-declarations
785
- function customFetch(url, options) {
786
- if (url.toString().startsWith("https://liffsdk.line-scdn.net/xlt/") && url.toString().endsWith(".json")) {
787
- url = "".concat(url, "?ts=").concat(Math.random());
788
- }
789
- return originalFetch(url, options);
790
- };
791
- initializedFlagKey = "".concat(localStorageKey, "-liffInitialized");
792
- // 若之前已紀錄為 initialized,嘗試直接載入 SDK 並重用
793
- alreadyInitialized = !!window.localStorage.getItem(initializedFlagKey);
794
- liffModule = null;
795
- _state.label = 1;
796
- case 1:
797
- _state.trys.push([
798
- 1,
799
- 3,
800
- ,
801
- 4
802
- ]);
803
- return [
804
- 4,
805
- import('./index.esm3.js')
806
- ];
807
- case 2:
808
- liffModule = _state.sent();
809
- return [
810
- 3,
811
- 4
812
- ];
813
- case 3:
814
- e = _state.sent();
815
- console.warn("載入 @line/liff 失敗:", e);
816
- throw e;
817
- case 4:
818
- liff = liffModule.liff;
819
- originalFetch = window.fetch;
820
- window.fetch = customFetch;
821
- // 如果記錄存在,嘗試重用 SDK 物件(不一定需要再呼叫 init)
822
- if (alreadyInitialized) {
823
- try {
824
- setLiffObject(liff);
825
- console.log("Reused LIFF SDK from persisted flag.");
826
- } catch (e) {
827
- console.warn("重用 LIFF SDK 失敗,將重新 init", e);
828
- }
829
- }
830
- if (!!alreadyInitialized) return [
831
- 3,
832
- 6
833
- ];
834
- if (openInApp && !(liff === null || liff === void 0 ? void 0 : liff.isInClient()) && (liff === null || liff === void 0 ? void 0 : liff.getOS()) !== "web") window.location.href = "line://app/".concat(liffId);
835
- return [
836
- 4,
837
- liff.init({
838
- liffId: liffId,
839
- withLoginOnExternalBrowser: false
840
- })
841
- ];
842
- case 5:
843
- _state.sent();
844
- // 設定 persisted flag,避免重新整理時重複 init
845
- try {
846
- window.localStorage.setItem(initializedFlagKey, "1");
847
- } catch (e) {
848
- // ignore
849
- }
850
- console.log("LIFF init succeeded.");
851
- setLiffObject(liff);
852
- _state.label = 6;
853
- case 6:
854
- // 如果 localStorage 或 state 已有 profile,就跳過重複呼叫
855
- storedProfileExists = false;
856
- try {
857
- storedProfileExists = !!window.localStorage.getItem(liffUserInfoStorageKey);
858
- } catch (e) {
859
- storedProfileExists = false;
860
- }
861
- if (!(!storedProfileExists && !liffProfile)) return [
862
- 3,
863
- 11
864
- ];
865
- _state.label = 7;
866
- case 7:
867
- _state.trys.push([
868
- 7,
869
- 9,
870
- ,
871
- 10
872
- ]);
873
- return [
874
- 4,
875
- liff.getProfile()
876
- ];
877
- case 8:
878
- profile = _state.sent();
879
- setLiffProfile(profile);
880
- saveLiffUserInfoToStorage(profile);
881
- return [
882
- 3,
883
- 10
884
- ];
885
- case 9:
886
- profileErr = _state.sent();
887
- console.warn("取得 LIFF profile 失敗(非致命):", profileErr);
888
- return [
889
- 3,
890
- 10
891
- ];
892
- case 10:
893
- return [
894
- 3,
895
- 12
896
- ];
897
- case 11:
898
- console.log("跳過 liff.getProfile():已由 localStorage 或 state 取得 profile");
899
- _state.label = 12;
900
- case 12:
901
- lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
902
- // 未登入先進行登入
903
- if (!liff.isLoggedIn()) {
904
- redirectUri = customerRedirectUrl || "".concat(window.location.href);
905
- if (liffLogin) {
906
- liff.login({
907
- redirectUri: redirectUri
908
- });
909
- return [
910
- 2
911
- ];
912
- }
913
- if (loginByUser || ignoreRoute) return [
914
- 2
915
- ];
916
- liff.login({
917
- redirectUri: redirectUri
918
- });
919
- }
920
- tempFriendship = null;
921
- if (!lineToken) return [
922
- 3,
923
- 18
924
- ];
925
- _state.label = 13;
926
- case 13:
927
- _state.trys.push([
928
- 13,
929
- 15,
930
- ,
931
- 16
932
- ]);
933
- return [
934
- 4,
935
- liff.getFriendship()
936
- ];
937
- case 14:
938
- friendship = _state.sent();
939
- friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
940
- setFriendship(friendFlag);
941
- tempFriendship = friendFlag;
942
- console.log("isFriendship", friendFlag);
943
- return [
944
- 3,
945
- 16
946
- ];
947
- case 15:
948
- error = _state.sent();
949
- console.error("Error in liff.getFriendship():", error);
950
- return [
951
- 3,
952
- 16
953
- ];
954
- case 16:
955
- console.log("isValid", isValid);
956
- if (tempFriendship && isValid) return [
957
- 2
958
- ];
959
- return [
960
- 4,
961
- loginInit(lineToken)
962
- ];
963
- case 17:
964
- _state.sent();
965
- _state.label = 18;
966
- case 18:
967
- return [
968
- 3,
969
- 21
970
- ];
971
- case 19:
972
- err = _state.sent();
973
- setLiffError((err === null || err === void 0 ? void 0 : err.toString) ? err.toString() : String(err));
974
- console.log("LIFF init failed.", err);
975
- throw err;
976
- case 20:
977
- // 清除 reference,允許下次再次初始化(若需要)
978
- initPromiseRef.current = null;
979
- return [
980
- 7
981
- ];
982
- case 21:
769
+ switch(_state.label){
770
+ case 0:
771
+ _state.trys.push([
772
+ 0,
773
+ 15,
774
+ ,
775
+ 16
776
+ ]);
777
+ customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
778
+ // eslint-disable-next-line no-inner-declarations
779
+ function customFetch(url, options) {
780
+ if (url.toString().startsWith("https://liffsdk.line-scdn.net/xlt/") && url.toString().endsWith(".json")) {
781
+ url = "".concat(url, "?ts=").concat(Math.random());
782
+ }
783
+ return originalFetch(url, options);
784
+ };
785
+ return [
786
+ 4,
787
+ import('./index.esm3.js')
788
+ ];
789
+ case 1:
790
+ liff = _state.sent().liff;
791
+ urlParams = new URLSearchParams(window.location.search);
792
+ hasLiffParams = urlParams.has("liffClientId") || urlParams.has("liffRedirectUri");
793
+ originalFetch = window.fetch;
794
+ window.fetch = customFetch;
795
+ if (openInApp && !(liff === null || liff === void 0 ? void 0 : liff.isInClient()) && (liff === null || liff === void 0 ? void 0 : liff.getOS()) !== "web") window.location.href = "line://app/".concat(liffId);
796
+ if (hasLiffParams || isProcessingLiffCallback.current) {
797
+ isProcessingLiffCallback.current = true;
798
+ return [
799
+ 2
800
+ ];
801
+ }
802
+ return [
803
+ 4,
804
+ liff.init({
805
+ liffId: liffId,
806
+ withLoginOnExternalBrowser: false
807
+ })
808
+ ];
809
+ case 2:
810
+ _state.sent();
811
+ console.log("LIFF init succeeded.");
812
+ isProcessingLiffCallback.current = true;
813
+ setLiffObject(liff);
814
+ // 如果 localStorage 或 state 已有 profile,就跳過重複呼叫
815
+ storedProfileExists = false;
816
+ try {
817
+ storedProfileExists = !!window.localStorage.getItem(liffUserInfoStorageKey);
818
+ } catch (e) {
819
+ storedProfileExists = false;
820
+ isProcessingLiffCallback.current = false;
821
+ }
822
+ if (!(!storedProfileExists && !liffProfile)) return [
823
+ 3,
824
+ 7
825
+ ];
826
+ _state.label = 3;
827
+ case 3:
828
+ _state.trys.push([
829
+ 3,
830
+ 5,
831
+ ,
832
+ 6
833
+ ]);
834
+ return [
835
+ 4,
836
+ liff.getProfile()
837
+ ];
838
+ case 4:
839
+ profile = _state.sent();
840
+ setLiffProfile(profile);
841
+ saveLiffUserInfoToStorage(profile);
842
+ return [
843
+ 3,
844
+ 6
845
+ ];
846
+ case 5:
847
+ profileErr = _state.sent();
848
+ console.warn("取得 LIFF profile 失敗(非致命):", profileErr);
849
+ return [
850
+ 3,
851
+ 6
852
+ ];
853
+ case 6:
854
+ return [
855
+ 3,
856
+ 8
857
+ ];
858
+ case 7:
859
+ // 已有快取,跳過呼叫
860
+ console.log("跳過 liff.getProfile():已由 localStorage 或 state 取得 profile");
861
+ _state.label = 8;
862
+ case 8:
863
+ lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
864
+ // 未登入先進行登入
865
+ if (!liff.isLoggedIn()) {
866
+ redirectUri = customerRedirectUrl || "".concat(window.location.href);
867
+ if (liffLogin) {
868
+ liff.login({
869
+ redirectUri: redirectUri
870
+ });
983
871
  return [
984
872
  2
985
873
  ];
874
+ }
875
+ if (loginByUser || ignoreRoute) return [
876
+ 2
877
+ ];
878
+ liff.login({
879
+ redirectUri: redirectUri
880
+ });
986
881
  }
987
- });
988
- })();
989
- return [
990
- 2,
991
- initPromiseRef.current
992
- ];
882
+ tempFriendship = null;
883
+ if (!lineToken) return [
884
+ 3,
885
+ 14
886
+ ];
887
+ _state.label = 9;
888
+ case 9:
889
+ _state.trys.push([
890
+ 9,
891
+ 11,
892
+ ,
893
+ 12
894
+ ]);
895
+ return [
896
+ 4,
897
+ liff.getFriendship()
898
+ ];
899
+ case 10:
900
+ friendship = _state.sent();
901
+ friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
902
+ setFriendship(friendFlag);
903
+ tempFriendship = friendFlag;
904
+ console.log("isFriendship", friendFlag);
905
+ return [
906
+ 3,
907
+ 12
908
+ ];
909
+ case 11:
910
+ error = _state.sent();
911
+ console.error("Error in liff.getFriendship():", error);
912
+ return [
913
+ 3,
914
+ 12
915
+ ];
916
+ case 12:
917
+ console.log("isValid", isValid);
918
+ if (tempFriendship && isValid) return [
919
+ 2
920
+ ];
921
+ return [
922
+ 4,
923
+ loginInit(lineToken)
924
+ ];
925
+ case 13:
926
+ _state.sent();
927
+ _state.label = 14;
928
+ case 14:
929
+ return [
930
+ 3,
931
+ 16
932
+ ];
933
+ case 15:
934
+ err = _state.sent();
935
+ setLiffError(err.toString());
936
+ console.log("LIFF init failed.", err);
937
+ return [
938
+ 3,
939
+ 16
940
+ ];
941
+ case 16:
942
+ return [
943
+ 2
944
+ ];
945
+ }
993
946
  });
994
947
  });
995
948
  return function initializeLiff(isValid) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.4.54",
3
+ "version": "0.4.56",
4
4
  "sideEffects": [
5
5
  "*.css",
6
6
  "./src/style.css",