@sunggang/ui-lib 0.4.50 → 0.4.51

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.
@@ -460,13 +460,10 @@ var LiffProvider = function(param) {
460
460
  var _useState2 = _sliced_to_array(React.useState(null), 2), liffError = _useState2[0], setLiffError = _useState2[1];
461
461
  var _useState3 = _sliced_to_array(React.useState(null), 2), loginData = _useState3[0], setLoginData = _useState3[1];
462
462
  var _useState4 = _sliced_to_array(React.useState(null), 2), userInfo = _useState4[0], setUserInfo = _useState4[1];
463
- var _useState5 = _sliced_to_array(React.useState(null), 2), liffProfile = _useState5[0], setLiffProfile = _useState5[1];
464
- var _useState6 = _sliced_to_array(React.useState(null), 2), isFriendship = _useState6[0], setFriendship = _useState6[1];
465
- var _useState7 = _sliced_to_array(React.useState(null), 2), loginType = _useState7[0], setLoginType = _useState7[1];
463
+ var _useState5 = _sliced_to_array(React.useState(null), 2), isFriendship = _useState5[0], setFriendship = _useState5[1];
464
+ var _useState6 = _sliced_to_array(React.useState(null), 2), loginType = _useState6[0], setLoginType = _useState6[1];
466
465
  // userInfo 的 localStorage key
467
466
  var userInfoStorageKey = "".concat(localStorageKey, "-userInfo");
468
- // liff userInfo 的 localStorage key
469
- var liffUserInfoStorageKey = "".concat(localStorageKey, "-liffUserInfo");
470
467
  // 從 localStorage 載入 userInfo
471
468
  var loadUserInfoFromStorage = function() {
472
469
  try {
@@ -489,28 +486,6 @@ var LiffProvider = function(param) {
489
486
  console.error("儲存 userInfo 失敗:", err);
490
487
  }
491
488
  };
492
- // 從 localStorage 載入 LIFF userInfo
493
- var loadLiffUserInfoFromStorage = function() {
494
- try {
495
- var stored = window.localStorage.getItem(liffUserInfoStorageKey);
496
- if (stored) {
497
- var parsed = JSON.parse(stored);
498
- setLiffProfile(parsed);
499
- return parsed;
500
- }
501
- } catch (err) {
502
- console.error("載入 liffUserInfo 失敗:", err);
503
- }
504
- return null;
505
- };
506
- // 儲存 LIFF userInfo 到 localStorage
507
- var saveLiffUserInfoToStorage = function(info) {
508
- try {
509
- window.localStorage.setItem(liffUserInfoStorageKey, JSON.stringify(info));
510
- } catch (err) {
511
- console.error("儲存 liffUserInfo 失敗:", err);
512
- }
513
- };
514
489
  var fetchMemberInfo = function() {
515
490
  var _ref = _async_to_generator(function(token) {
516
491
  var response, err;
@@ -728,15 +703,15 @@ var LiffProvider = function(param) {
728
703
  // 初始化 LIFF
729
704
  var initializeLiff = function() {
730
705
  var _ref = _async_to_generator(function(isValid) {
731
- var customFetch, liff, redirectUri, originalFetch, profile, profileErr, e, msg, lineToken, tempFriendship, friendship, friendFlag, error, err;
706
+ var customFetch, liff, originalFetch, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
732
707
  return _ts_generator(this, function(_state) {
733
708
  switch(_state.label){
734
709
  case 0:
735
710
  _state.trys.push([
736
711
  0,
737
- 19,
712
+ 9,
738
713
  ,
739
- 20
714
+ 10
740
715
  ]);
741
716
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
742
717
  // eslint-disable-next-line no-inner-declarations
@@ -752,6 +727,21 @@ var LiffProvider = function(param) {
752
727
  ];
753
728
  case 1:
754
729
  liff = _state.sent().liff;
730
+ originalFetch = window.fetch;
731
+ window.fetch = customFetch;
732
+ 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);
733
+ return [
734
+ 4,
735
+ liff.init({
736
+ liffId: liffId,
737
+ withLoginOnExternalBrowser: false
738
+ })
739
+ ];
740
+ case 2:
741
+ _state.sent();
742
+ console.log("LIFF init succeeded.");
743
+ setLiffObject(liff);
744
+ lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
755
745
  // 未登入先進行登入
756
746
  if (!liff.isLoggedIn()) {
757
747
  redirectUri = customerRedirectUrl || "".concat(window.location.href);
@@ -769,151 +759,42 @@ var LiffProvider = function(param) {
769
759
  liff.login({
770
760
  redirectUri: redirectUri
771
761
  });
772
- return [
773
- 2
774
- ];
775
762
  }
776
- originalFetch = window.fetch;
777
- window.fetch = customFetch;
778
- 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);
779
- if (!!liff.isLoggedIn()) return [
780
- 3,
781
- 11
782
- ];
783
- if (!(!liffId || typeof liffId !== "string" || liffId.trim() === "")) return [
784
- 3,
785
- 2
786
- ];
787
- console.warn("liffId 未提供或為空字串,跳過 liff.init()。");
788
- return [
789
- 3,
790
- 11
791
- ];
792
- case 2:
793
- _state.trys.push([
794
- 2,
795
- 10,
796
- ,
797
- 11
798
- ]);
799
- if (!(typeof liff.init !== "function")) return [
800
- 3,
801
- 3
802
- ];
803
- console.warn("liff.init 尚未提供,跳過 init。");
804
- return [
805
- 3,
806
- 9
807
- ];
808
- case 3:
809
- return [
810
- 4,
811
- liff.init({
812
- liffId: liffId,
813
- withLoginOnExternalBrowser: false
814
- })
815
- ];
816
- case 4:
817
- _state.sent();
818
- console.log("LIFF init succeeded.");
819
- setLiffObject(liff);
820
- _state.label = 5;
821
- case 5:
822
- _state.trys.push([
823
- 5,
824
- 7,
825
- ,
826
- 8
827
- ]);
828
- return [
829
- 4,
830
- liff.getProfile()
831
- ];
832
- case 6:
833
- profile = _state.sent();
834
- setLiffProfile(profile);
835
- saveLiffUserInfoToStorage(profile);
836
- return [
837
- 3,
838
- 8
839
- ];
840
- case 7:
841
- profileErr = _state.sent();
842
- // 取得 profile 失敗不致命,後續可由 caller 取得
843
- console.warn("取得 LIFF profile 失敗(非致命):", profileErr);
844
- return [
845
- 3,
846
- 8
847
- ];
848
- case 8:
849
- // 標記為已初始化(persist),避免 redirect 回來時重複 init
850
- try {
851
- window.localStorage.setItem("".concat(localStorageKey, "-liffInitialized"), "1");
852
- } catch (e) {
853
- // ignore
854
- }
855
- _state.label = 9;
856
- case 9:
857
- return [
858
- 3,
859
- 11
860
- ];
861
- case 10:
862
- e = _state.sent();
863
- // 如果是缺少 liffId 的 SDK 錯誤,安靜短路並不要把錯誤曝露給使用者
864
- msg = (e === null || e === void 0 ? void 0 : e.message) || String(e);
865
- if (typeof msg === "string" && msg.includes("liffId is necessary")) {
866
- console.warn("略過 liff.init 錯誤(缺少 liffId):", msg);
867
- } else {
868
- throw e;
869
- }
870
- return [
871
- 3,
872
- 11
873
- ];
874
- case 11:
875
- lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
876
763
  tempFriendship = null;
877
764
  if (!lineToken) return [
878
765
  3,
879
- 18
766
+ 8
880
767
  ];
881
- _state.label = 12;
882
- case 12:
768
+ _state.label = 3;
769
+ case 3:
883
770
  _state.trys.push([
884
- 12,
885
- 15,
771
+ 3,
772
+ 5,
886
773
  ,
887
- 16
774
+ 6
888
775
  ]);
889
- if (!!liff.isLoggedIn()) return [
890
- 3,
891
- 14
892
- ];
893
776
  return [
894
777
  4,
895
778
  liff.getFriendship()
896
779
  ];
897
- case 13:
780
+ case 4:
898
781
  friendship = _state.sent();
899
782
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
900
783
  setFriendship(friendFlag);
901
784
  tempFriendship = friendFlag;
902
785
  console.log("isFriendship", friendFlag);
903
- _state.label = 14;
904
- case 14:
905
786
  return [
906
787
  3,
907
- 16
788
+ 6
908
789
  ];
909
- case 15:
790
+ case 5:
910
791
  error = _state.sent();
911
792
  console.error("Error in liff.getFriendship():", error);
912
793
  return [
913
794
  3,
914
- 16
795
+ 6
915
796
  ];
916
- case 16:
797
+ case 6:
917
798
  console.log("isValid", isValid);
918
799
  if (tempFriendship && isValid) return [
919
800
  2
@@ -922,23 +803,23 @@ var LiffProvider = function(param) {
922
803
  4,
923
804
  loginInit(lineToken)
924
805
  ];
925
- case 17:
806
+ case 7:
926
807
  _state.sent();
927
- _state.label = 18;
928
- case 18:
808
+ _state.label = 8;
809
+ case 8:
929
810
  return [
930
811
  3,
931
- 20
812
+ 10
932
813
  ];
933
- case 19:
814
+ case 9:
934
815
  err = _state.sent();
935
816
  setLiffError(err.toString());
936
817
  console.log("LIFF init failed.", err);
937
818
  return [
938
819
  3,
939
- 20
820
+ 10
940
821
  ];
941
- case 20:
822
+ case 10:
942
823
  return [
943
824
  2
944
825
  ];
@@ -1118,7 +999,6 @@ var LiffProvider = function(param) {
1118
999
  // 初始載入時從 localStorage 載入 userInfo
1119
1000
  React.useEffect(function() {
1120
1001
  loadUserInfoFromStorage();
1121
- loadLiffUserInfoFromStorage();
1122
1002
  }, []);
1123
1003
  // 客戶端初始化 LIFF
1124
1004
  React.useEffect(function() {
@@ -1209,8 +1089,7 @@ var LiffProvider = function(param) {
1209
1089
  isFriendship: isFriendship,
1210
1090
  ensureLiffTokenValid: ensureLiffTokenValid,
1211
1091
  accountLogin: accountLogin,
1212
- loginType: loginType,
1213
- liffProfile: liffProfile
1092
+ loginType: loginType
1214
1093
  };
1215
1094
  }, [
1216
1095
  liffObject,
@@ -1221,8 +1100,7 @@ var LiffProvider = function(param) {
1221
1100
  isFriendship,
1222
1101
  ensureLiffTokenValid,
1223
1102
  accountLogin,
1224
- loginType,
1225
- liffProfile
1103
+ loginType
1226
1104
  ]);
1227
1105
  return /*#__PURE__*/ jsxRuntime.jsx(LiffContext.Provider, {
1228
1106
  value: contextValue,
@@ -456,13 +456,10 @@ var LiffProvider = function(param) {
456
456
  var _useState2 = _sliced_to_array(useState(null), 2), liffError = _useState2[0], setLiffError = _useState2[1];
457
457
  var _useState3 = _sliced_to_array(useState(null), 2), loginData = _useState3[0], setLoginData = _useState3[1];
458
458
  var _useState4 = _sliced_to_array(useState(null), 2), userInfo = _useState4[0], setUserInfo = _useState4[1];
459
- var _useState5 = _sliced_to_array(useState(null), 2), liffProfile = _useState5[0], setLiffProfile = _useState5[1];
460
- var _useState6 = _sliced_to_array(useState(null), 2), isFriendship = _useState6[0], setFriendship = _useState6[1];
461
- var _useState7 = _sliced_to_array(useState(null), 2), loginType = _useState7[0], setLoginType = _useState7[1];
459
+ var _useState5 = _sliced_to_array(useState(null), 2), isFriendship = _useState5[0], setFriendship = _useState5[1];
460
+ var _useState6 = _sliced_to_array(useState(null), 2), loginType = _useState6[0], setLoginType = _useState6[1];
462
461
  // userInfo 的 localStorage key
463
462
  var userInfoStorageKey = "".concat(localStorageKey, "-userInfo");
464
- // liff userInfo 的 localStorage key
465
- var liffUserInfoStorageKey = "".concat(localStorageKey, "-liffUserInfo");
466
463
  // 從 localStorage 載入 userInfo
467
464
  var loadUserInfoFromStorage = function() {
468
465
  try {
@@ -485,28 +482,6 @@ var LiffProvider = function(param) {
485
482
  console.error("儲存 userInfo 失敗:", err);
486
483
  }
487
484
  };
488
- // 從 localStorage 載入 LIFF userInfo
489
- var loadLiffUserInfoFromStorage = function() {
490
- try {
491
- var stored = window.localStorage.getItem(liffUserInfoStorageKey);
492
- if (stored) {
493
- var parsed = JSON.parse(stored);
494
- setLiffProfile(parsed);
495
- return parsed;
496
- }
497
- } catch (err) {
498
- console.error("載入 liffUserInfo 失敗:", err);
499
- }
500
- return null;
501
- };
502
- // 儲存 LIFF userInfo 到 localStorage
503
- var saveLiffUserInfoToStorage = function(info) {
504
- try {
505
- window.localStorage.setItem(liffUserInfoStorageKey, JSON.stringify(info));
506
- } catch (err) {
507
- console.error("儲存 liffUserInfo 失敗:", err);
508
- }
509
- };
510
485
  var fetchMemberInfo = function() {
511
486
  var _ref = _async_to_generator(function(token) {
512
487
  var response, err;
@@ -724,15 +699,15 @@ var LiffProvider = function(param) {
724
699
  // 初始化 LIFF
725
700
  var initializeLiff = function() {
726
701
  var _ref = _async_to_generator(function(isValid) {
727
- var customFetch, liff, redirectUri, originalFetch, profile, profileErr, e, msg, lineToken, tempFriendship, friendship, friendFlag, error, err;
702
+ var customFetch, liff, originalFetch, lineToken, redirectUri, tempFriendship, friendship, friendFlag, error, err;
728
703
  return _ts_generator(this, function(_state) {
729
704
  switch(_state.label){
730
705
  case 0:
731
706
  _state.trys.push([
732
707
  0,
733
- 19,
708
+ 9,
734
709
  ,
735
- 20
710
+ 10
736
711
  ]);
737
712
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
738
713
  // eslint-disable-next-line no-inner-declarations
@@ -748,6 +723,21 @@ var LiffProvider = function(param) {
748
723
  ];
749
724
  case 1:
750
725
  liff = _state.sent().liff;
726
+ originalFetch = window.fetch;
727
+ window.fetch = customFetch;
728
+ 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);
729
+ return [
730
+ 4,
731
+ liff.init({
732
+ liffId: liffId,
733
+ withLoginOnExternalBrowser: false
734
+ })
735
+ ];
736
+ case 2:
737
+ _state.sent();
738
+ console.log("LIFF init succeeded.");
739
+ setLiffObject(liff);
740
+ lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
751
741
  // 未登入先進行登入
752
742
  if (!liff.isLoggedIn()) {
753
743
  redirectUri = customerRedirectUrl || "".concat(window.location.href);
@@ -765,151 +755,42 @@ var LiffProvider = function(param) {
765
755
  liff.login({
766
756
  redirectUri: redirectUri
767
757
  });
768
- return [
769
- 2
770
- ];
771
758
  }
772
- originalFetch = window.fetch;
773
- window.fetch = customFetch;
774
- 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);
775
- if (!!liff.isLoggedIn()) return [
776
- 3,
777
- 11
778
- ];
779
- if (!(!liffId || typeof liffId !== "string" || liffId.trim() === "")) return [
780
- 3,
781
- 2
782
- ];
783
- console.warn("liffId 未提供或為空字串,跳過 liff.init()。");
784
- return [
785
- 3,
786
- 11
787
- ];
788
- case 2:
789
- _state.trys.push([
790
- 2,
791
- 10,
792
- ,
793
- 11
794
- ]);
795
- if (!(typeof liff.init !== "function")) return [
796
- 3,
797
- 3
798
- ];
799
- console.warn("liff.init 尚未提供,跳過 init。");
800
- return [
801
- 3,
802
- 9
803
- ];
804
- case 3:
805
- return [
806
- 4,
807
- liff.init({
808
- liffId: liffId,
809
- withLoginOnExternalBrowser: false
810
- })
811
- ];
812
- case 4:
813
- _state.sent();
814
- console.log("LIFF init succeeded.");
815
- setLiffObject(liff);
816
- _state.label = 5;
817
- case 5:
818
- _state.trys.push([
819
- 5,
820
- 7,
821
- ,
822
- 8
823
- ]);
824
- return [
825
- 4,
826
- liff.getProfile()
827
- ];
828
- case 6:
829
- profile = _state.sent();
830
- setLiffProfile(profile);
831
- saveLiffUserInfoToStorage(profile);
832
- return [
833
- 3,
834
- 8
835
- ];
836
- case 7:
837
- profileErr = _state.sent();
838
- // 取得 profile 失敗不致命,後續可由 caller 取得
839
- console.warn("取得 LIFF profile 失敗(非致命):", profileErr);
840
- return [
841
- 3,
842
- 8
843
- ];
844
- case 8:
845
- // 標記為已初始化(persist),避免 redirect 回來時重複 init
846
- try {
847
- window.localStorage.setItem("".concat(localStorageKey, "-liffInitialized"), "1");
848
- } catch (e) {
849
- // ignore
850
- }
851
- _state.label = 9;
852
- case 9:
853
- return [
854
- 3,
855
- 11
856
- ];
857
- case 10:
858
- e = _state.sent();
859
- // 如果是缺少 liffId 的 SDK 錯誤,安靜短路並不要把錯誤曝露給使用者
860
- msg = (e === null || e === void 0 ? void 0 : e.message) || String(e);
861
- if (typeof msg === "string" && msg.includes("liffId is necessary")) {
862
- console.warn("略過 liff.init 錯誤(缺少 liffId):", msg);
863
- } else {
864
- throw e;
865
- }
866
- return [
867
- 3,
868
- 11
869
- ];
870
- case 11:
871
- lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
872
759
  tempFriendship = null;
873
760
  if (!lineToken) return [
874
761
  3,
875
- 18
762
+ 8
876
763
  ];
877
- _state.label = 12;
878
- case 12:
764
+ _state.label = 3;
765
+ case 3:
879
766
  _state.trys.push([
880
- 12,
881
- 15,
767
+ 3,
768
+ 5,
882
769
  ,
883
- 16
770
+ 6
884
771
  ]);
885
- if (!!liff.isLoggedIn()) return [
886
- 3,
887
- 14
888
- ];
889
772
  return [
890
773
  4,
891
774
  liff.getFriendship()
892
775
  ];
893
- case 13:
776
+ case 4:
894
777
  friendship = _state.sent();
895
778
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
896
779
  setFriendship(friendFlag);
897
780
  tempFriendship = friendFlag;
898
781
  console.log("isFriendship", friendFlag);
899
- _state.label = 14;
900
- case 14:
901
782
  return [
902
783
  3,
903
- 16
784
+ 6
904
785
  ];
905
- case 15:
786
+ case 5:
906
787
  error = _state.sent();
907
788
  console.error("Error in liff.getFriendship():", error);
908
789
  return [
909
790
  3,
910
- 16
791
+ 6
911
792
  ];
912
- case 16:
793
+ case 6:
913
794
  console.log("isValid", isValid);
914
795
  if (tempFriendship && isValid) return [
915
796
  2
@@ -918,23 +799,23 @@ var LiffProvider = function(param) {
918
799
  4,
919
800
  loginInit(lineToken)
920
801
  ];
921
- case 17:
802
+ case 7:
922
803
  _state.sent();
923
- _state.label = 18;
924
- case 18:
804
+ _state.label = 8;
805
+ case 8:
925
806
  return [
926
807
  3,
927
- 20
808
+ 10
928
809
  ];
929
- case 19:
810
+ case 9:
930
811
  err = _state.sent();
931
812
  setLiffError(err.toString());
932
813
  console.log("LIFF init failed.", err);
933
814
  return [
934
815
  3,
935
- 20
816
+ 10
936
817
  ];
937
- case 20:
818
+ case 10:
938
819
  return [
939
820
  2
940
821
  ];
@@ -1114,7 +995,6 @@ var LiffProvider = function(param) {
1114
995
  // 初始載入時從 localStorage 載入 userInfo
1115
996
  useEffect(function() {
1116
997
  loadUserInfoFromStorage();
1117
- loadLiffUserInfoFromStorage();
1118
998
  }, []);
1119
999
  // 客戶端初始化 LIFF
1120
1000
  useEffect(function() {
@@ -1205,8 +1085,7 @@ var LiffProvider = function(param) {
1205
1085
  isFriendship: isFriendship,
1206
1086
  ensureLiffTokenValid: ensureLiffTokenValid,
1207
1087
  accountLogin: accountLogin,
1208
- loginType: loginType,
1209
- liffProfile: liffProfile
1088
+ loginType: loginType
1210
1089
  };
1211
1090
  }, [
1212
1091
  liffObject,
@@ -1217,8 +1096,7 @@ var LiffProvider = function(param) {
1217
1096
  isFriendship,
1218
1097
  ensureLiffTokenValid,
1219
1098
  accountLogin,
1220
- loginType,
1221
- liffProfile
1099
+ loginType
1222
1100
  ]);
1223
1101
  return /*#__PURE__*/ jsx(LiffContext.Provider, {
1224
1102
  value: contextValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.4.50",
3
+ "version": "0.4.51",
4
4
  "sideEffects": [
5
5
  "*.css",
6
6
  "./src/style.css",