@sunggang/ui-lib 0.4.49 → 0.4.50

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.
@@ -728,15 +728,15 @@ var LiffProvider = function(param) {
728
728
  // 初始化 LIFF
729
729
  var initializeLiff = function() {
730
730
  var _ref = _async_to_generator(function(isValid) {
731
- var customFetch, liff, redirectUri, originalFetch, profile, lineToken, tempFriendship, friendship, friendFlag, error, err;
731
+ var customFetch, liff, redirectUri, originalFetch, profile, profileErr, e, msg, lineToken, tempFriendship, friendship, friendFlag, error, err;
732
732
  return _ts_generator(this, function(_state) {
733
733
  switch(_state.label){
734
734
  case 0:
735
735
  _state.trys.push([
736
736
  0,
737
- 12,
737
+ 19,
738
738
  ,
739
- 13
739
+ 20
740
740
  ]);
741
741
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
742
742
  // eslint-disable-next-line no-inner-declarations
@@ -746,12 +746,6 @@ var LiffProvider = function(param) {
746
746
  }
747
747
  return originalFetch(url, options);
748
748
  };
749
- if (!liffId) {
750
- console.warn("liffId 未提供,無法初始化 LIFF");
751
- return [
752
- 2
753
- ];
754
- }
755
749
  return [
756
750
  4,
757
751
  Promise.resolve().then(function () { return require('./index.cjs3.js'); })
@@ -784,8 +778,34 @@ var LiffProvider = function(param) {
784
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);
785
779
  if (!!liff.isLoggedIn()) return [
786
780
  3,
787
- 4
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
788
802
  ];
803
+ console.warn("liff.init 尚未提供,跳過 init。");
804
+ return [
805
+ 3,
806
+ 9
807
+ ];
808
+ case 3:
789
809
  return [
790
810
  4,
791
811
  liff.init({
@@ -793,62 +813,107 @@ var LiffProvider = function(param) {
793
813
  withLoginOnExternalBrowser: false
794
814
  })
795
815
  ];
796
- case 2:
816
+ case 4:
797
817
  _state.sent();
798
818
  console.log("LIFF init succeeded.");
799
819
  setLiffObject(liff);
820
+ _state.label = 5;
821
+ case 5:
822
+ _state.trys.push([
823
+ 5,
824
+ 7,
825
+ ,
826
+ 8
827
+ ]);
800
828
  return [
801
829
  4,
802
830
  liff.getProfile()
803
831
  ];
804
- case 3:
832
+ case 6:
805
833
  profile = _state.sent();
806
834
  setLiffProfile(profile);
807
835
  saveLiffUserInfoToStorage(profile);
808
- _state.label = 4;
809
- case 4:
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:
810
875
  lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
811
876
  tempFriendship = null;
812
877
  if (!lineToken) return [
813
878
  3,
814
- 11
879
+ 18
815
880
  ];
816
- _state.label = 5;
817
- case 5:
881
+ _state.label = 12;
882
+ case 12:
818
883
  _state.trys.push([
819
- 5,
820
- 8,
884
+ 12,
885
+ 15,
821
886
  ,
822
- 9
887
+ 16
823
888
  ]);
824
889
  if (!!liff.isLoggedIn()) return [
825
890
  3,
826
- 7
891
+ 14
827
892
  ];
828
893
  return [
829
894
  4,
830
895
  liff.getFriendship()
831
896
  ];
832
- case 6:
897
+ case 13:
833
898
  friendship = _state.sent();
834
899
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
835
900
  setFriendship(friendFlag);
836
901
  tempFriendship = friendFlag;
837
902
  console.log("isFriendship", friendFlag);
838
- _state.label = 7;
839
- case 7:
903
+ _state.label = 14;
904
+ case 14:
840
905
  return [
841
906
  3,
842
- 9
907
+ 16
843
908
  ];
844
- case 8:
909
+ case 15:
845
910
  error = _state.sent();
846
911
  console.error("Error in liff.getFriendship():", error);
847
912
  return [
848
913
  3,
849
- 9
914
+ 16
850
915
  ];
851
- case 9:
916
+ case 16:
852
917
  console.log("isValid", isValid);
853
918
  if (tempFriendship && isValid) return [
854
919
  2
@@ -857,23 +922,23 @@ var LiffProvider = function(param) {
857
922
  4,
858
923
  loginInit(lineToken)
859
924
  ];
860
- case 10:
925
+ case 17:
861
926
  _state.sent();
862
- _state.label = 11;
863
- case 11:
927
+ _state.label = 18;
928
+ case 18:
864
929
  return [
865
930
  3,
866
- 13
931
+ 20
867
932
  ];
868
- case 12:
933
+ case 19:
869
934
  err = _state.sent();
870
935
  setLiffError(err.toString());
871
936
  console.log("LIFF init failed.", err);
872
937
  return [
873
938
  3,
874
- 13
939
+ 20
875
940
  ];
876
- case 13:
941
+ case 20:
877
942
  return [
878
943
  2
879
944
  ];
@@ -724,15 +724,15 @@ var LiffProvider = function(param) {
724
724
  // 初始化 LIFF
725
725
  var initializeLiff = function() {
726
726
  var _ref = _async_to_generator(function(isValid) {
727
- var customFetch, liff, redirectUri, originalFetch, profile, lineToken, tempFriendship, friendship, friendFlag, error, err;
727
+ var customFetch, liff, redirectUri, originalFetch, profile, profileErr, e, msg, lineToken, tempFriendship, friendship, friendFlag, error, err;
728
728
  return _ts_generator(this, function(_state) {
729
729
  switch(_state.label){
730
730
  case 0:
731
731
  _state.trys.push([
732
732
  0,
733
- 12,
733
+ 19,
734
734
  ,
735
- 13
735
+ 20
736
736
  ]);
737
737
  customFetch = // 自訂 fetch 函數,避免每次請求都改變 URL
738
738
  // eslint-disable-next-line no-inner-declarations
@@ -742,12 +742,6 @@ var LiffProvider = function(param) {
742
742
  }
743
743
  return originalFetch(url, options);
744
744
  };
745
- if (!liffId) {
746
- console.warn("liffId 未提供,無法初始化 LIFF");
747
- return [
748
- 2
749
- ];
750
- }
751
745
  return [
752
746
  4,
753
747
  import('./index.esm3.js')
@@ -780,8 +774,34 @@ var LiffProvider = function(param) {
780
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);
781
775
  if (!!liff.isLoggedIn()) return [
782
776
  3,
783
- 4
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
784
798
  ];
799
+ console.warn("liff.init 尚未提供,跳過 init。");
800
+ return [
801
+ 3,
802
+ 9
803
+ ];
804
+ case 3:
785
805
  return [
786
806
  4,
787
807
  liff.init({
@@ -789,62 +809,107 @@ var LiffProvider = function(param) {
789
809
  withLoginOnExternalBrowser: false
790
810
  })
791
811
  ];
792
- case 2:
812
+ case 4:
793
813
  _state.sent();
794
814
  console.log("LIFF init succeeded.");
795
815
  setLiffObject(liff);
816
+ _state.label = 5;
817
+ case 5:
818
+ _state.trys.push([
819
+ 5,
820
+ 7,
821
+ ,
822
+ 8
823
+ ]);
796
824
  return [
797
825
  4,
798
826
  liff.getProfile()
799
827
  ];
800
- case 3:
828
+ case 6:
801
829
  profile = _state.sent();
802
830
  setLiffProfile(profile);
803
831
  saveLiffUserInfoToStorage(profile);
804
- _state.label = 4;
805
- case 4:
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:
806
871
  lineToken = liff === null || liff === void 0 ? void 0 : liff.getAccessToken();
807
872
  tempFriendship = null;
808
873
  if (!lineToken) return [
809
874
  3,
810
- 11
875
+ 18
811
876
  ];
812
- _state.label = 5;
813
- case 5:
877
+ _state.label = 12;
878
+ case 12:
814
879
  _state.trys.push([
815
- 5,
816
- 8,
880
+ 12,
881
+ 15,
817
882
  ,
818
- 9
883
+ 16
819
884
  ]);
820
885
  if (!!liff.isLoggedIn()) return [
821
886
  3,
822
- 7
887
+ 14
823
888
  ];
824
889
  return [
825
890
  4,
826
891
  liff.getFriendship()
827
892
  ];
828
- case 6:
893
+ case 13:
829
894
  friendship = _state.sent();
830
895
  friendFlag = friendship === null || friendship === void 0 ? void 0 : friendship.friendFlag;
831
896
  setFriendship(friendFlag);
832
897
  tempFriendship = friendFlag;
833
898
  console.log("isFriendship", friendFlag);
834
- _state.label = 7;
835
- case 7:
899
+ _state.label = 14;
900
+ case 14:
836
901
  return [
837
902
  3,
838
- 9
903
+ 16
839
904
  ];
840
- case 8:
905
+ case 15:
841
906
  error = _state.sent();
842
907
  console.error("Error in liff.getFriendship():", error);
843
908
  return [
844
909
  3,
845
- 9
910
+ 16
846
911
  ];
847
- case 9:
912
+ case 16:
848
913
  console.log("isValid", isValid);
849
914
  if (tempFriendship && isValid) return [
850
915
  2
@@ -853,23 +918,23 @@ var LiffProvider = function(param) {
853
918
  4,
854
919
  loginInit(lineToken)
855
920
  ];
856
- case 10:
921
+ case 17:
857
922
  _state.sent();
858
- _state.label = 11;
859
- case 11:
923
+ _state.label = 18;
924
+ case 18:
860
925
  return [
861
926
  3,
862
- 13
927
+ 20
863
928
  ];
864
- case 12:
929
+ case 19:
865
930
  err = _state.sent();
866
931
  setLiffError(err.toString());
867
932
  console.log("LIFF init failed.", err);
868
933
  return [
869
934
  3,
870
- 13
935
+ 20
871
936
  ];
872
- case 13:
937
+ case 20:
873
938
  return [
874
939
  2
875
940
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sunggang/ui-lib",
3
- "version": "0.4.49",
3
+ "version": "0.4.50",
4
4
  "sideEffects": [
5
5
  "*.css",
6
6
  "./src/style.css",