@compilot/react-sdk 2.2.3-dev → 2.2.6-dev
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/compilot-react-sdk.cjs.dev.js +156 -129
- package/dist/compilot-react-sdk.cjs.prod.js +156 -129
- package/dist/compilot-react-sdk.esm.js +156 -129
- package/dist/declarations/src/hooks/useAuthenticate.d.ts.map +1 -1
- package/dist/declarations/src/hooks/useDisconnect.d.ts.map +1 -1
- package/dist/declarations/src/hooks/useGetTxAuthDataSignature.d.ts.map +1 -1
- package/dist/declarations/src/hooks/useOpenWidget.d.ts.map +1 -1
- package/dist/declarations/src/utils/useAsyncMutationState.d.ts +6 -1
- package/dist/declarations/src/utils/useAsyncMutationState.d.ts.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +5 -5
|
@@ -588,15 +588,33 @@ function _asyncToGenerator(n) {
|
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
+
function _arrayWithoutHoles(r) {
|
|
592
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function _iterableToArray(r) {
|
|
596
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function _nonIterableSpread() {
|
|
600
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function _toConsumableArray(r) {
|
|
604
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
605
|
+
}
|
|
606
|
+
|
|
591
607
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
592
608
|
|
|
593
609
|
var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
594
610
|
var mutationName = _ref.mutationName,
|
|
595
|
-
|
|
611
|
+
mutationKey = _ref.mutationKey,
|
|
612
|
+
mutationFn = _ref.mutationFn,
|
|
613
|
+
defaultValue = _ref.defaultValue;
|
|
596
614
|
var _useGlobalState = useGlobalState({
|
|
597
|
-
key: ["useAsyncMutationState"
|
|
615
|
+
key: ["useAsyncMutationState"].concat(_toConsumableArray(mutationKey !== null && mutationKey !== void 0 ? mutationKey : [])),
|
|
598
616
|
defaultValue: {
|
|
599
|
-
data:
|
|
617
|
+
data: defaultValue,
|
|
600
618
|
isIdle: true,
|
|
601
619
|
isPending: false,
|
|
602
620
|
isError: false,
|
|
@@ -654,102 +672,47 @@ var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
|
654
672
|
}
|
|
655
673
|
}, _callee, null, [[1, 9]]);
|
|
656
674
|
})), [setState, mutationFn]);
|
|
657
|
-
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
function _arrayWithoutHoles(r) {
|
|
661
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
function _iterableToArray(r) {
|
|
665
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
function _nonIterableSpread() {
|
|
669
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function _toConsumableArray(r) {
|
|
673
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
677
|
-
var queryKey = _ref.queryKey,
|
|
678
|
-
defaultValue = _ref.defaultValue;
|
|
679
|
-
var _useGlobalState = useGlobalState({
|
|
680
|
-
key: ["useAsyncQueryState"].concat(_toConsumableArray(queryKey)),
|
|
681
|
-
defaultValue: defaultValue === undefined ? {
|
|
682
|
-
isLoading: false,
|
|
683
|
-
isError: false,
|
|
684
|
-
isSuccess: false,
|
|
685
|
-
error: null,
|
|
686
|
-
data: undefined
|
|
687
|
-
} : {
|
|
688
|
-
isLoading: false,
|
|
689
|
-
isError: false,
|
|
690
|
-
isSuccess: true,
|
|
691
|
-
error: null,
|
|
692
|
-
data: defaultValue
|
|
693
|
-
}
|
|
694
|
-
}),
|
|
695
|
-
_useGlobalState2 = _slicedToArray(_useGlobalState, 2),
|
|
696
|
-
state = _useGlobalState2[0],
|
|
697
|
-
setState = _useGlobalState2[1];
|
|
698
|
-
var setResult = react.useCallback(function (result) {
|
|
675
|
+
var setData = react.useCallback(function (data) {
|
|
699
676
|
setState({
|
|
700
|
-
|
|
677
|
+
data: data,
|
|
678
|
+
isIdle: false,
|
|
679
|
+
isPending: false,
|
|
701
680
|
isError: false,
|
|
702
681
|
isSuccess: true,
|
|
703
|
-
error: null
|
|
704
|
-
data: result
|
|
682
|
+
error: null
|
|
705
683
|
});
|
|
706
684
|
}, [setState]);
|
|
707
|
-
var
|
|
708
|
-
|
|
709
|
-
isLoading: false,
|
|
710
|
-
isError: true,
|
|
711
|
-
isSuccess: false,
|
|
712
|
-
error: error,
|
|
713
|
-
data: undefined
|
|
714
|
-
});
|
|
715
|
-
}, [setState]);
|
|
716
|
-
var startLoading = react.useCallback(function () {
|
|
717
|
-
if (state.isLoading) {
|
|
685
|
+
var startPending = react.useCallback(function () {
|
|
686
|
+
if (state.isPending) {
|
|
718
687
|
return;
|
|
719
688
|
}
|
|
720
689
|
setState({
|
|
721
|
-
|
|
690
|
+
data: undefined,
|
|
691
|
+
isIdle: false,
|
|
692
|
+
isPending: true,
|
|
722
693
|
isError: false,
|
|
723
694
|
isSuccess: false,
|
|
724
|
-
error: null
|
|
725
|
-
data: undefined
|
|
695
|
+
error: null
|
|
726
696
|
});
|
|
727
|
-
}, [setState]);
|
|
728
|
-
var
|
|
729
|
-
if (!state.
|
|
697
|
+
}, [setState, state.isPending]);
|
|
698
|
+
var stopPending = react.useCallback(function () {
|
|
699
|
+
if (!state.isPending) {
|
|
730
700
|
return;
|
|
731
701
|
}
|
|
732
|
-
setState(function (
|
|
733
|
-
return _objectSpread2(_objectSpread2({},
|
|
734
|
-
|
|
702
|
+
setState(function (s) {
|
|
703
|
+
return _objectSpread2(_objectSpread2({}, s), {}, {
|
|
704
|
+
isPending: false
|
|
735
705
|
});
|
|
736
706
|
});
|
|
737
|
-
}, [setState]);
|
|
738
|
-
var
|
|
739
|
-
if (
|
|
740
|
-
|
|
707
|
+
}, [setState, state.isPending]);
|
|
708
|
+
var setPending = react.useCallback(function (isPending) {
|
|
709
|
+
if (isPending) {
|
|
710
|
+
startPending();
|
|
741
711
|
} else {
|
|
742
|
-
|
|
712
|
+
stopPending();
|
|
743
713
|
}
|
|
744
|
-
}, [
|
|
745
|
-
return {
|
|
746
|
-
state: state,
|
|
747
|
-
setResult: setResult,
|
|
748
|
-
setError: setError,
|
|
749
|
-
startLoading: startLoading,
|
|
750
|
-
stopLoading: stopLoading,
|
|
751
|
-
setLoading: setLoading
|
|
752
|
-
};
|
|
714
|
+
}, [startPending, stopPending]);
|
|
715
|
+
return _objectSpread2(_objectSpread2({}, state), {}, _defineProperty(_defineProperty(_defineProperty({}, mutationName, mutateAsync), "setData", setData), "setPending", setPending));
|
|
753
716
|
};
|
|
754
717
|
|
|
755
718
|
/**
|
|
@@ -767,36 +730,20 @@ var useOpenWidget = function useOpenWidget(loginParams) {
|
|
|
767
730
|
}, [config]);
|
|
768
731
|
var mutationState = useAsyncMutationState({
|
|
769
732
|
mutationName: "openWidget",
|
|
770
|
-
|
|
733
|
+
mutationKey: ["openWidget", config._internal.identifier],
|
|
734
|
+
mutationFn: mutationFn,
|
|
735
|
+
defaultValue: webSdk.isOpen(config)
|
|
771
736
|
});
|
|
772
|
-
// but open state can change without us mutating it
|
|
773
|
-
// that's the only case for now so we don't need another kind of mutation state
|
|
774
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
775
|
-
queryKey: ["useOpenWidget", config._internal.identifier],
|
|
776
|
-
defaultValue: webSdk.isOpen(config)
|
|
777
|
-
}),
|
|
778
|
-
setResult = _useAsyncQueryState.setResult,
|
|
779
|
-
setLoading = _useAsyncQueryState.setLoading,
|
|
780
|
-
queryState = _useAsyncQueryState.state;
|
|
781
737
|
react.useEffect(function () {
|
|
782
738
|
var unsubscribe = webSdk.watchWidgetVisibleState(config, {
|
|
783
739
|
onChange: function onChange(isVisible) {
|
|
784
|
-
|
|
740
|
+
mutationState.setData(isVisible);
|
|
785
741
|
},
|
|
786
|
-
onIsLoadingChange:
|
|
742
|
+
onIsLoadingChange: mutationState.setPending
|
|
787
743
|
});
|
|
788
744
|
return unsubscribe;
|
|
789
|
-
}, [config,
|
|
790
|
-
return
|
|
791
|
-
error: queryState.error,
|
|
792
|
-
isPending: queryState.isLoading,
|
|
793
|
-
isSuccess: queryState.isSuccess,
|
|
794
|
-
isError: queryState.isError,
|
|
795
|
-
isIdle: !queryState.isError && !queryState.isLoading && !queryState.isSuccess,
|
|
796
|
-
data: queryState.data
|
|
797
|
-
}), {}, {
|
|
798
|
-
openWidget: mutationState.openWidget
|
|
799
|
-
});
|
|
745
|
+
}, [config, mutationState.setData, mutationState.setPending]);
|
|
746
|
+
return mutationState;
|
|
800
747
|
};
|
|
801
748
|
|
|
802
749
|
/**
|
|
@@ -979,6 +926,7 @@ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
|
979
926
|
}(), [config._internal.widgetStateStore, config._internal.identifier]);
|
|
980
927
|
return useAsyncMutationState({
|
|
981
928
|
mutationName: "getTxAuthDataSignature",
|
|
929
|
+
mutationKey: ["getTxAuthDataSignature", config._internal.identifier],
|
|
982
930
|
mutationFn: mutationFn
|
|
983
931
|
});
|
|
984
932
|
};
|
|
@@ -998,36 +946,101 @@ var useAuthenticate = function useAuthenticate(loginParams) {
|
|
|
998
946
|
}, [config]);
|
|
999
947
|
var mutationState = useAsyncMutationState({
|
|
1000
948
|
mutationName: "authenticate",
|
|
1001
|
-
|
|
949
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
950
|
+
mutationFn: mutationFn,
|
|
951
|
+
defaultValue: webSdk.isAuthenticated(config)
|
|
1002
952
|
});
|
|
1003
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
1004
|
-
queryKey: ["useAuthenticate", config._internal.identifier],
|
|
1005
|
-
defaultValue: webSdk.isAuthenticated(config)
|
|
1006
|
-
}),
|
|
1007
|
-
queryState = _useAsyncQueryState.state,
|
|
1008
|
-
setResult = _useAsyncQueryState.setResult,
|
|
1009
|
-
setLoading = _useAsyncQueryState.setLoading;
|
|
1010
953
|
react.useEffect(function () {
|
|
1011
954
|
var unsubscribe = webSdk.watchIsAuthenticated(config, {
|
|
1012
955
|
onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
|
|
1013
|
-
|
|
956
|
+
mutationState.setData(isAuthenticated);
|
|
1014
957
|
},
|
|
1015
|
-
onIsLoadingChange:
|
|
958
|
+
onIsLoadingChange: mutationState.setPending
|
|
1016
959
|
});
|
|
1017
960
|
return function () {
|
|
1018
961
|
unsubscribe();
|
|
1019
962
|
};
|
|
1020
|
-
}, [config._internal.widgetStateStore, config._internal.identifier]);
|
|
1021
|
-
return
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
963
|
+
}, [config._internal.widgetStateStore, config._internal.identifier, mutationState.setData, mutationState.setPending]);
|
|
964
|
+
return mutationState;
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
968
|
+
var queryKey = _ref.queryKey,
|
|
969
|
+
defaultValue = _ref.defaultValue;
|
|
970
|
+
var _useGlobalState = useGlobalState({
|
|
971
|
+
key: ["useAsyncQueryState"].concat(_toConsumableArray(queryKey)),
|
|
972
|
+
defaultValue: defaultValue === undefined ? {
|
|
973
|
+
isLoading: false,
|
|
974
|
+
isError: false,
|
|
975
|
+
isSuccess: false,
|
|
976
|
+
error: null,
|
|
977
|
+
data: undefined
|
|
978
|
+
} : {
|
|
979
|
+
isLoading: false,
|
|
980
|
+
isError: false,
|
|
981
|
+
isSuccess: true,
|
|
982
|
+
error: null,
|
|
983
|
+
data: defaultValue
|
|
984
|
+
}
|
|
985
|
+
}),
|
|
986
|
+
_useGlobalState2 = _slicedToArray(_useGlobalState, 2),
|
|
987
|
+
state = _useGlobalState2[0],
|
|
988
|
+
setState = _useGlobalState2[1];
|
|
989
|
+
var setResult = react.useCallback(function (result) {
|
|
990
|
+
setState({
|
|
991
|
+
isLoading: false,
|
|
992
|
+
isError: false,
|
|
993
|
+
isSuccess: true,
|
|
994
|
+
error: null,
|
|
995
|
+
data: result
|
|
996
|
+
});
|
|
997
|
+
}, [setState]);
|
|
998
|
+
var setError = react.useCallback(function (error) {
|
|
999
|
+
setState({
|
|
1000
|
+
isLoading: false,
|
|
1001
|
+
isError: true,
|
|
1002
|
+
isSuccess: false,
|
|
1003
|
+
error: error,
|
|
1004
|
+
data: undefined
|
|
1005
|
+
});
|
|
1006
|
+
}, [setState]);
|
|
1007
|
+
var startLoading = react.useCallback(function () {
|
|
1008
|
+
if (state.isLoading) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
setState({
|
|
1012
|
+
isLoading: true,
|
|
1013
|
+
isError: false,
|
|
1014
|
+
isSuccess: false,
|
|
1015
|
+
error: null,
|
|
1016
|
+
data: undefined
|
|
1017
|
+
});
|
|
1018
|
+
}, [setState]);
|
|
1019
|
+
var stopLoading = react.useCallback(function () {
|
|
1020
|
+
if (!state.isLoading) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
setState(function (state) {
|
|
1024
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1025
|
+
isLoading: false
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1028
|
+
}, [setState]);
|
|
1029
|
+
var setLoading = react.useCallback(function (isLoading) {
|
|
1030
|
+
if (isLoading) {
|
|
1031
|
+
startLoading();
|
|
1032
|
+
} else {
|
|
1033
|
+
stopLoading();
|
|
1034
|
+
}
|
|
1035
|
+
}, [startLoading, stopLoading]);
|
|
1036
|
+
return {
|
|
1037
|
+
state: state,
|
|
1038
|
+
setResult: setResult,
|
|
1039
|
+
setError: setError,
|
|
1040
|
+
startLoading: startLoading,
|
|
1041
|
+
stopLoading: stopLoading,
|
|
1042
|
+
setLoading: setLoading
|
|
1043
|
+
};
|
|
1031
1044
|
};
|
|
1032
1045
|
|
|
1033
1046
|
/**
|
|
@@ -1128,11 +1141,25 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
1128
1141
|
*/
|
|
1129
1142
|
var useDisconnect = function useDisconnect() {
|
|
1130
1143
|
var config = useComPilotConfig();
|
|
1131
|
-
var mutationFn = react.useCallback(function () {
|
|
1132
|
-
|
|
1133
|
-
|
|
1144
|
+
var mutationFn = react.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1145
|
+
var isDisconnected;
|
|
1146
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1147
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1148
|
+
case 0:
|
|
1149
|
+
_context.next = 2;
|
|
1150
|
+
return webSdk.disconnect(config);
|
|
1151
|
+
case 2:
|
|
1152
|
+
isDisconnected = _context.sent;
|
|
1153
|
+
return _context.abrupt("return", !isDisconnected);
|
|
1154
|
+
case 4:
|
|
1155
|
+
case "end":
|
|
1156
|
+
return _context.stop();
|
|
1157
|
+
}
|
|
1158
|
+
}, _callee);
|
|
1159
|
+
})), [config]);
|
|
1134
1160
|
return useAsyncMutationState({
|
|
1135
1161
|
mutationName: "disconnect",
|
|
1162
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
1136
1163
|
mutationFn: mutationFn
|
|
1137
1164
|
});
|
|
1138
1165
|
};
|
|
@@ -588,15 +588,33 @@ function _asyncToGenerator(n) {
|
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
590
|
|
|
591
|
+
function _arrayWithoutHoles(r) {
|
|
592
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function _iterableToArray(r) {
|
|
596
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function _nonIterableSpread() {
|
|
600
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function _toConsumableArray(r) {
|
|
604
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
605
|
+
}
|
|
606
|
+
|
|
591
607
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
592
608
|
|
|
593
609
|
var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
594
610
|
var mutationName = _ref.mutationName,
|
|
595
|
-
|
|
611
|
+
mutationKey = _ref.mutationKey,
|
|
612
|
+
mutationFn = _ref.mutationFn,
|
|
613
|
+
defaultValue = _ref.defaultValue;
|
|
596
614
|
var _useGlobalState = useGlobalState({
|
|
597
|
-
key: ["useAsyncMutationState"
|
|
615
|
+
key: ["useAsyncMutationState"].concat(_toConsumableArray(mutationKey !== null && mutationKey !== void 0 ? mutationKey : [])),
|
|
598
616
|
defaultValue: {
|
|
599
|
-
data:
|
|
617
|
+
data: defaultValue,
|
|
600
618
|
isIdle: true,
|
|
601
619
|
isPending: false,
|
|
602
620
|
isError: false,
|
|
@@ -654,102 +672,47 @@ var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
|
654
672
|
}
|
|
655
673
|
}, _callee, null, [[1, 9]]);
|
|
656
674
|
})), [setState, mutationFn]);
|
|
657
|
-
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
function _arrayWithoutHoles(r) {
|
|
661
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
function _iterableToArray(r) {
|
|
665
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
function _nonIterableSpread() {
|
|
669
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function _toConsumableArray(r) {
|
|
673
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
677
|
-
var queryKey = _ref.queryKey,
|
|
678
|
-
defaultValue = _ref.defaultValue;
|
|
679
|
-
var _useGlobalState = useGlobalState({
|
|
680
|
-
key: ["useAsyncQueryState"].concat(_toConsumableArray(queryKey)),
|
|
681
|
-
defaultValue: defaultValue === undefined ? {
|
|
682
|
-
isLoading: false,
|
|
683
|
-
isError: false,
|
|
684
|
-
isSuccess: false,
|
|
685
|
-
error: null,
|
|
686
|
-
data: undefined
|
|
687
|
-
} : {
|
|
688
|
-
isLoading: false,
|
|
689
|
-
isError: false,
|
|
690
|
-
isSuccess: true,
|
|
691
|
-
error: null,
|
|
692
|
-
data: defaultValue
|
|
693
|
-
}
|
|
694
|
-
}),
|
|
695
|
-
_useGlobalState2 = _slicedToArray(_useGlobalState, 2),
|
|
696
|
-
state = _useGlobalState2[0],
|
|
697
|
-
setState = _useGlobalState2[1];
|
|
698
|
-
var setResult = react.useCallback(function (result) {
|
|
675
|
+
var setData = react.useCallback(function (data) {
|
|
699
676
|
setState({
|
|
700
|
-
|
|
677
|
+
data: data,
|
|
678
|
+
isIdle: false,
|
|
679
|
+
isPending: false,
|
|
701
680
|
isError: false,
|
|
702
681
|
isSuccess: true,
|
|
703
|
-
error: null
|
|
704
|
-
data: result
|
|
682
|
+
error: null
|
|
705
683
|
});
|
|
706
684
|
}, [setState]);
|
|
707
|
-
var
|
|
708
|
-
|
|
709
|
-
isLoading: false,
|
|
710
|
-
isError: true,
|
|
711
|
-
isSuccess: false,
|
|
712
|
-
error: error,
|
|
713
|
-
data: undefined
|
|
714
|
-
});
|
|
715
|
-
}, [setState]);
|
|
716
|
-
var startLoading = react.useCallback(function () {
|
|
717
|
-
if (state.isLoading) {
|
|
685
|
+
var startPending = react.useCallback(function () {
|
|
686
|
+
if (state.isPending) {
|
|
718
687
|
return;
|
|
719
688
|
}
|
|
720
689
|
setState({
|
|
721
|
-
|
|
690
|
+
data: undefined,
|
|
691
|
+
isIdle: false,
|
|
692
|
+
isPending: true,
|
|
722
693
|
isError: false,
|
|
723
694
|
isSuccess: false,
|
|
724
|
-
error: null
|
|
725
|
-
data: undefined
|
|
695
|
+
error: null
|
|
726
696
|
});
|
|
727
|
-
}, [setState]);
|
|
728
|
-
var
|
|
729
|
-
if (!state.
|
|
697
|
+
}, [setState, state.isPending]);
|
|
698
|
+
var stopPending = react.useCallback(function () {
|
|
699
|
+
if (!state.isPending) {
|
|
730
700
|
return;
|
|
731
701
|
}
|
|
732
|
-
setState(function (
|
|
733
|
-
return _objectSpread2(_objectSpread2({},
|
|
734
|
-
|
|
702
|
+
setState(function (s) {
|
|
703
|
+
return _objectSpread2(_objectSpread2({}, s), {}, {
|
|
704
|
+
isPending: false
|
|
735
705
|
});
|
|
736
706
|
});
|
|
737
|
-
}, [setState]);
|
|
738
|
-
var
|
|
739
|
-
if (
|
|
740
|
-
|
|
707
|
+
}, [setState, state.isPending]);
|
|
708
|
+
var setPending = react.useCallback(function (isPending) {
|
|
709
|
+
if (isPending) {
|
|
710
|
+
startPending();
|
|
741
711
|
} else {
|
|
742
|
-
|
|
712
|
+
stopPending();
|
|
743
713
|
}
|
|
744
|
-
}, [
|
|
745
|
-
return {
|
|
746
|
-
state: state,
|
|
747
|
-
setResult: setResult,
|
|
748
|
-
setError: setError,
|
|
749
|
-
startLoading: startLoading,
|
|
750
|
-
stopLoading: stopLoading,
|
|
751
|
-
setLoading: setLoading
|
|
752
|
-
};
|
|
714
|
+
}, [startPending, stopPending]);
|
|
715
|
+
return _objectSpread2(_objectSpread2({}, state), {}, _defineProperty(_defineProperty(_defineProperty({}, mutationName, mutateAsync), "setData", setData), "setPending", setPending));
|
|
753
716
|
};
|
|
754
717
|
|
|
755
718
|
/**
|
|
@@ -767,36 +730,20 @@ var useOpenWidget = function useOpenWidget(loginParams) {
|
|
|
767
730
|
}, [config]);
|
|
768
731
|
var mutationState = useAsyncMutationState({
|
|
769
732
|
mutationName: "openWidget",
|
|
770
|
-
|
|
733
|
+
mutationKey: ["openWidget", config._internal.identifier],
|
|
734
|
+
mutationFn: mutationFn,
|
|
735
|
+
defaultValue: webSdk.isOpen(config)
|
|
771
736
|
});
|
|
772
|
-
// but open state can change without us mutating it
|
|
773
|
-
// that's the only case for now so we don't need another kind of mutation state
|
|
774
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
775
|
-
queryKey: ["useOpenWidget", config._internal.identifier],
|
|
776
|
-
defaultValue: webSdk.isOpen(config)
|
|
777
|
-
}),
|
|
778
|
-
setResult = _useAsyncQueryState.setResult,
|
|
779
|
-
setLoading = _useAsyncQueryState.setLoading,
|
|
780
|
-
queryState = _useAsyncQueryState.state;
|
|
781
737
|
react.useEffect(function () {
|
|
782
738
|
var unsubscribe = webSdk.watchWidgetVisibleState(config, {
|
|
783
739
|
onChange: function onChange(isVisible) {
|
|
784
|
-
|
|
740
|
+
mutationState.setData(isVisible);
|
|
785
741
|
},
|
|
786
|
-
onIsLoadingChange:
|
|
742
|
+
onIsLoadingChange: mutationState.setPending
|
|
787
743
|
});
|
|
788
744
|
return unsubscribe;
|
|
789
|
-
}, [config,
|
|
790
|
-
return
|
|
791
|
-
error: queryState.error,
|
|
792
|
-
isPending: queryState.isLoading,
|
|
793
|
-
isSuccess: queryState.isSuccess,
|
|
794
|
-
isError: queryState.isError,
|
|
795
|
-
isIdle: !queryState.isError && !queryState.isLoading && !queryState.isSuccess,
|
|
796
|
-
data: queryState.data
|
|
797
|
-
}), {}, {
|
|
798
|
-
openWidget: mutationState.openWidget
|
|
799
|
-
});
|
|
745
|
+
}, [config, mutationState.setData, mutationState.setPending]);
|
|
746
|
+
return mutationState;
|
|
800
747
|
};
|
|
801
748
|
|
|
802
749
|
/**
|
|
@@ -979,6 +926,7 @@ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
|
979
926
|
}(), [config._internal.widgetStateStore, config._internal.identifier]);
|
|
980
927
|
return useAsyncMutationState({
|
|
981
928
|
mutationName: "getTxAuthDataSignature",
|
|
929
|
+
mutationKey: ["getTxAuthDataSignature", config._internal.identifier],
|
|
982
930
|
mutationFn: mutationFn
|
|
983
931
|
});
|
|
984
932
|
};
|
|
@@ -998,36 +946,101 @@ var useAuthenticate = function useAuthenticate(loginParams) {
|
|
|
998
946
|
}, [config]);
|
|
999
947
|
var mutationState = useAsyncMutationState({
|
|
1000
948
|
mutationName: "authenticate",
|
|
1001
|
-
|
|
949
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
950
|
+
mutationFn: mutationFn,
|
|
951
|
+
defaultValue: webSdk.isAuthenticated(config)
|
|
1002
952
|
});
|
|
1003
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
1004
|
-
queryKey: ["useAuthenticate", config._internal.identifier],
|
|
1005
|
-
defaultValue: webSdk.isAuthenticated(config)
|
|
1006
|
-
}),
|
|
1007
|
-
queryState = _useAsyncQueryState.state,
|
|
1008
|
-
setResult = _useAsyncQueryState.setResult,
|
|
1009
|
-
setLoading = _useAsyncQueryState.setLoading;
|
|
1010
953
|
react.useEffect(function () {
|
|
1011
954
|
var unsubscribe = webSdk.watchIsAuthenticated(config, {
|
|
1012
955
|
onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
|
|
1013
|
-
|
|
956
|
+
mutationState.setData(isAuthenticated);
|
|
1014
957
|
},
|
|
1015
|
-
onIsLoadingChange:
|
|
958
|
+
onIsLoadingChange: mutationState.setPending
|
|
1016
959
|
});
|
|
1017
960
|
return function () {
|
|
1018
961
|
unsubscribe();
|
|
1019
962
|
};
|
|
1020
|
-
}, [config._internal.widgetStateStore, config._internal.identifier]);
|
|
1021
|
-
return
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
963
|
+
}, [config._internal.widgetStateStore, config._internal.identifier, mutationState.setData, mutationState.setPending]);
|
|
964
|
+
return mutationState;
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
968
|
+
var queryKey = _ref.queryKey,
|
|
969
|
+
defaultValue = _ref.defaultValue;
|
|
970
|
+
var _useGlobalState = useGlobalState({
|
|
971
|
+
key: ["useAsyncQueryState"].concat(_toConsumableArray(queryKey)),
|
|
972
|
+
defaultValue: defaultValue === undefined ? {
|
|
973
|
+
isLoading: false,
|
|
974
|
+
isError: false,
|
|
975
|
+
isSuccess: false,
|
|
976
|
+
error: null,
|
|
977
|
+
data: undefined
|
|
978
|
+
} : {
|
|
979
|
+
isLoading: false,
|
|
980
|
+
isError: false,
|
|
981
|
+
isSuccess: true,
|
|
982
|
+
error: null,
|
|
983
|
+
data: defaultValue
|
|
984
|
+
}
|
|
985
|
+
}),
|
|
986
|
+
_useGlobalState2 = _slicedToArray(_useGlobalState, 2),
|
|
987
|
+
state = _useGlobalState2[0],
|
|
988
|
+
setState = _useGlobalState2[1];
|
|
989
|
+
var setResult = react.useCallback(function (result) {
|
|
990
|
+
setState({
|
|
991
|
+
isLoading: false,
|
|
992
|
+
isError: false,
|
|
993
|
+
isSuccess: true,
|
|
994
|
+
error: null,
|
|
995
|
+
data: result
|
|
996
|
+
});
|
|
997
|
+
}, [setState]);
|
|
998
|
+
var setError = react.useCallback(function (error) {
|
|
999
|
+
setState({
|
|
1000
|
+
isLoading: false,
|
|
1001
|
+
isError: true,
|
|
1002
|
+
isSuccess: false,
|
|
1003
|
+
error: error,
|
|
1004
|
+
data: undefined
|
|
1005
|
+
});
|
|
1006
|
+
}, [setState]);
|
|
1007
|
+
var startLoading = react.useCallback(function () {
|
|
1008
|
+
if (state.isLoading) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
setState({
|
|
1012
|
+
isLoading: true,
|
|
1013
|
+
isError: false,
|
|
1014
|
+
isSuccess: false,
|
|
1015
|
+
error: null,
|
|
1016
|
+
data: undefined
|
|
1017
|
+
});
|
|
1018
|
+
}, [setState]);
|
|
1019
|
+
var stopLoading = react.useCallback(function () {
|
|
1020
|
+
if (!state.isLoading) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
setState(function (state) {
|
|
1024
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1025
|
+
isLoading: false
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1028
|
+
}, [setState]);
|
|
1029
|
+
var setLoading = react.useCallback(function (isLoading) {
|
|
1030
|
+
if (isLoading) {
|
|
1031
|
+
startLoading();
|
|
1032
|
+
} else {
|
|
1033
|
+
stopLoading();
|
|
1034
|
+
}
|
|
1035
|
+
}, [startLoading, stopLoading]);
|
|
1036
|
+
return {
|
|
1037
|
+
state: state,
|
|
1038
|
+
setResult: setResult,
|
|
1039
|
+
setError: setError,
|
|
1040
|
+
startLoading: startLoading,
|
|
1041
|
+
stopLoading: stopLoading,
|
|
1042
|
+
setLoading: setLoading
|
|
1043
|
+
};
|
|
1031
1044
|
};
|
|
1032
1045
|
|
|
1033
1046
|
/**
|
|
@@ -1128,11 +1141,25 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
1128
1141
|
*/
|
|
1129
1142
|
var useDisconnect = function useDisconnect() {
|
|
1130
1143
|
var config = useComPilotConfig();
|
|
1131
|
-
var mutationFn = react.useCallback(function () {
|
|
1132
|
-
|
|
1133
|
-
|
|
1144
|
+
var mutationFn = react.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1145
|
+
var isDisconnected;
|
|
1146
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1147
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1148
|
+
case 0:
|
|
1149
|
+
_context.next = 2;
|
|
1150
|
+
return webSdk.disconnect(config);
|
|
1151
|
+
case 2:
|
|
1152
|
+
isDisconnected = _context.sent;
|
|
1153
|
+
return _context.abrupt("return", !isDisconnected);
|
|
1154
|
+
case 4:
|
|
1155
|
+
case "end":
|
|
1156
|
+
return _context.stop();
|
|
1157
|
+
}
|
|
1158
|
+
}, _callee);
|
|
1159
|
+
})), [config]);
|
|
1134
1160
|
return useAsyncMutationState({
|
|
1135
1161
|
mutationName: "disconnect",
|
|
1162
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
1136
1163
|
mutationFn: mutationFn
|
|
1137
1164
|
});
|
|
1138
1165
|
};
|
|
@@ -585,15 +585,33 @@ function _asyncToGenerator(n) {
|
|
|
585
585
|
};
|
|
586
586
|
}
|
|
587
587
|
|
|
588
|
+
function _arrayWithoutHoles(r) {
|
|
589
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function _iterableToArray(r) {
|
|
593
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function _nonIterableSpread() {
|
|
597
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function _toConsumableArray(r) {
|
|
601
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
602
|
+
}
|
|
603
|
+
|
|
588
604
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
589
605
|
|
|
590
606
|
var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
591
607
|
var mutationName = _ref.mutationName,
|
|
592
|
-
|
|
608
|
+
mutationKey = _ref.mutationKey,
|
|
609
|
+
mutationFn = _ref.mutationFn,
|
|
610
|
+
defaultValue = _ref.defaultValue;
|
|
593
611
|
var _useGlobalState = useGlobalState({
|
|
594
|
-
key: ["useAsyncMutationState"
|
|
612
|
+
key: ["useAsyncMutationState"].concat(_toConsumableArray(mutationKey !== null && mutationKey !== void 0 ? mutationKey : [])),
|
|
595
613
|
defaultValue: {
|
|
596
|
-
data:
|
|
614
|
+
data: defaultValue,
|
|
597
615
|
isIdle: true,
|
|
598
616
|
isPending: false,
|
|
599
617
|
isError: false,
|
|
@@ -651,102 +669,47 @@ var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
|
651
669
|
}
|
|
652
670
|
}, _callee, null, [[1, 9]]);
|
|
653
671
|
})), [setState, mutationFn]);
|
|
654
|
-
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
function _arrayWithoutHoles(r) {
|
|
658
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function _iterableToArray(r) {
|
|
662
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
function _nonIterableSpread() {
|
|
666
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
function _toConsumableArray(r) {
|
|
670
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
674
|
-
var queryKey = _ref.queryKey,
|
|
675
|
-
defaultValue = _ref.defaultValue;
|
|
676
|
-
var _useGlobalState = useGlobalState({
|
|
677
|
-
key: ["useAsyncQueryState"].concat(_toConsumableArray(queryKey)),
|
|
678
|
-
defaultValue: defaultValue === undefined ? {
|
|
679
|
-
isLoading: false,
|
|
680
|
-
isError: false,
|
|
681
|
-
isSuccess: false,
|
|
682
|
-
error: null,
|
|
683
|
-
data: undefined
|
|
684
|
-
} : {
|
|
685
|
-
isLoading: false,
|
|
686
|
-
isError: false,
|
|
687
|
-
isSuccess: true,
|
|
688
|
-
error: null,
|
|
689
|
-
data: defaultValue
|
|
690
|
-
}
|
|
691
|
-
}),
|
|
692
|
-
_useGlobalState2 = _slicedToArray(_useGlobalState, 2),
|
|
693
|
-
state = _useGlobalState2[0],
|
|
694
|
-
setState = _useGlobalState2[1];
|
|
695
|
-
var setResult = useCallback(function (result) {
|
|
672
|
+
var setData = useCallback(function (data) {
|
|
696
673
|
setState({
|
|
697
|
-
|
|
674
|
+
data: data,
|
|
675
|
+
isIdle: false,
|
|
676
|
+
isPending: false,
|
|
698
677
|
isError: false,
|
|
699
678
|
isSuccess: true,
|
|
700
|
-
error: null
|
|
701
|
-
data: result
|
|
679
|
+
error: null
|
|
702
680
|
});
|
|
703
681
|
}, [setState]);
|
|
704
|
-
var
|
|
705
|
-
|
|
706
|
-
isLoading: false,
|
|
707
|
-
isError: true,
|
|
708
|
-
isSuccess: false,
|
|
709
|
-
error: error,
|
|
710
|
-
data: undefined
|
|
711
|
-
});
|
|
712
|
-
}, [setState]);
|
|
713
|
-
var startLoading = useCallback(function () {
|
|
714
|
-
if (state.isLoading) {
|
|
682
|
+
var startPending = useCallback(function () {
|
|
683
|
+
if (state.isPending) {
|
|
715
684
|
return;
|
|
716
685
|
}
|
|
717
686
|
setState({
|
|
718
|
-
|
|
687
|
+
data: undefined,
|
|
688
|
+
isIdle: false,
|
|
689
|
+
isPending: true,
|
|
719
690
|
isError: false,
|
|
720
691
|
isSuccess: false,
|
|
721
|
-
error: null
|
|
722
|
-
data: undefined
|
|
692
|
+
error: null
|
|
723
693
|
});
|
|
724
|
-
}, [setState]);
|
|
725
|
-
var
|
|
726
|
-
if (!state.
|
|
694
|
+
}, [setState, state.isPending]);
|
|
695
|
+
var stopPending = useCallback(function () {
|
|
696
|
+
if (!state.isPending) {
|
|
727
697
|
return;
|
|
728
698
|
}
|
|
729
|
-
setState(function (
|
|
730
|
-
return _objectSpread2(_objectSpread2({},
|
|
731
|
-
|
|
699
|
+
setState(function (s) {
|
|
700
|
+
return _objectSpread2(_objectSpread2({}, s), {}, {
|
|
701
|
+
isPending: false
|
|
732
702
|
});
|
|
733
703
|
});
|
|
734
|
-
}, [setState]);
|
|
735
|
-
var
|
|
736
|
-
if (
|
|
737
|
-
|
|
704
|
+
}, [setState, state.isPending]);
|
|
705
|
+
var setPending = useCallback(function (isPending) {
|
|
706
|
+
if (isPending) {
|
|
707
|
+
startPending();
|
|
738
708
|
} else {
|
|
739
|
-
|
|
709
|
+
stopPending();
|
|
740
710
|
}
|
|
741
|
-
}, [
|
|
742
|
-
return {
|
|
743
|
-
state: state,
|
|
744
|
-
setResult: setResult,
|
|
745
|
-
setError: setError,
|
|
746
|
-
startLoading: startLoading,
|
|
747
|
-
stopLoading: stopLoading,
|
|
748
|
-
setLoading: setLoading
|
|
749
|
-
};
|
|
711
|
+
}, [startPending, stopPending]);
|
|
712
|
+
return _objectSpread2(_objectSpread2({}, state), {}, _defineProperty(_defineProperty(_defineProperty({}, mutationName, mutateAsync), "setData", setData), "setPending", setPending));
|
|
750
713
|
};
|
|
751
714
|
|
|
752
715
|
/**
|
|
@@ -764,36 +727,20 @@ var useOpenWidget = function useOpenWidget(loginParams) {
|
|
|
764
727
|
}, [config]);
|
|
765
728
|
var mutationState = useAsyncMutationState({
|
|
766
729
|
mutationName: "openWidget",
|
|
767
|
-
|
|
730
|
+
mutationKey: ["openWidget", config._internal.identifier],
|
|
731
|
+
mutationFn: mutationFn,
|
|
732
|
+
defaultValue: isOpen(config)
|
|
768
733
|
});
|
|
769
|
-
// but open state can change without us mutating it
|
|
770
|
-
// that's the only case for now so we don't need another kind of mutation state
|
|
771
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
772
|
-
queryKey: ["useOpenWidget", config._internal.identifier],
|
|
773
|
-
defaultValue: isOpen(config)
|
|
774
|
-
}),
|
|
775
|
-
setResult = _useAsyncQueryState.setResult,
|
|
776
|
-
setLoading = _useAsyncQueryState.setLoading,
|
|
777
|
-
queryState = _useAsyncQueryState.state;
|
|
778
734
|
useEffect(function () {
|
|
779
735
|
var unsubscribe = watchWidgetVisibleState(config, {
|
|
780
736
|
onChange: function onChange(isVisible) {
|
|
781
|
-
|
|
737
|
+
mutationState.setData(isVisible);
|
|
782
738
|
},
|
|
783
|
-
onIsLoadingChange:
|
|
739
|
+
onIsLoadingChange: mutationState.setPending
|
|
784
740
|
});
|
|
785
741
|
return unsubscribe;
|
|
786
|
-
}, [config,
|
|
787
|
-
return
|
|
788
|
-
error: queryState.error,
|
|
789
|
-
isPending: queryState.isLoading,
|
|
790
|
-
isSuccess: queryState.isSuccess,
|
|
791
|
-
isError: queryState.isError,
|
|
792
|
-
isIdle: !queryState.isError && !queryState.isLoading && !queryState.isSuccess,
|
|
793
|
-
data: queryState.data
|
|
794
|
-
}), {}, {
|
|
795
|
-
openWidget: mutationState.openWidget
|
|
796
|
-
});
|
|
742
|
+
}, [config, mutationState.setData, mutationState.setPending]);
|
|
743
|
+
return mutationState;
|
|
797
744
|
};
|
|
798
745
|
|
|
799
746
|
/**
|
|
@@ -976,6 +923,7 @@ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
|
976
923
|
}(), [config._internal.widgetStateStore, config._internal.identifier]);
|
|
977
924
|
return useAsyncMutationState({
|
|
978
925
|
mutationName: "getTxAuthDataSignature",
|
|
926
|
+
mutationKey: ["getTxAuthDataSignature", config._internal.identifier],
|
|
979
927
|
mutationFn: mutationFn
|
|
980
928
|
});
|
|
981
929
|
};
|
|
@@ -995,36 +943,101 @@ var useAuthenticate = function useAuthenticate(loginParams) {
|
|
|
995
943
|
}, [config]);
|
|
996
944
|
var mutationState = useAsyncMutationState({
|
|
997
945
|
mutationName: "authenticate",
|
|
998
|
-
|
|
946
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
947
|
+
mutationFn: mutationFn,
|
|
948
|
+
defaultValue: isAuthenticated(config)
|
|
999
949
|
});
|
|
1000
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
1001
|
-
queryKey: ["useAuthenticate", config._internal.identifier],
|
|
1002
|
-
defaultValue: isAuthenticated(config)
|
|
1003
|
-
}),
|
|
1004
|
-
queryState = _useAsyncQueryState.state,
|
|
1005
|
-
setResult = _useAsyncQueryState.setResult,
|
|
1006
|
-
setLoading = _useAsyncQueryState.setLoading;
|
|
1007
950
|
useEffect(function () {
|
|
1008
951
|
var unsubscribe = watchIsAuthenticated(config, {
|
|
1009
952
|
onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
|
|
1010
|
-
|
|
953
|
+
mutationState.setData(isAuthenticated);
|
|
1011
954
|
},
|
|
1012
|
-
onIsLoadingChange:
|
|
955
|
+
onIsLoadingChange: mutationState.setPending
|
|
1013
956
|
});
|
|
1014
957
|
return function () {
|
|
1015
958
|
unsubscribe();
|
|
1016
959
|
};
|
|
1017
|
-
}, [config._internal.widgetStateStore, config._internal.identifier]);
|
|
1018
|
-
return
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
960
|
+
}, [config._internal.widgetStateStore, config._internal.identifier, mutationState.setData, mutationState.setPending]);
|
|
961
|
+
return mutationState;
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
965
|
+
var queryKey = _ref.queryKey,
|
|
966
|
+
defaultValue = _ref.defaultValue;
|
|
967
|
+
var _useGlobalState = useGlobalState({
|
|
968
|
+
key: ["useAsyncQueryState"].concat(_toConsumableArray(queryKey)),
|
|
969
|
+
defaultValue: defaultValue === undefined ? {
|
|
970
|
+
isLoading: false,
|
|
971
|
+
isError: false,
|
|
972
|
+
isSuccess: false,
|
|
973
|
+
error: null,
|
|
974
|
+
data: undefined
|
|
975
|
+
} : {
|
|
976
|
+
isLoading: false,
|
|
977
|
+
isError: false,
|
|
978
|
+
isSuccess: true,
|
|
979
|
+
error: null,
|
|
980
|
+
data: defaultValue
|
|
981
|
+
}
|
|
982
|
+
}),
|
|
983
|
+
_useGlobalState2 = _slicedToArray(_useGlobalState, 2),
|
|
984
|
+
state = _useGlobalState2[0],
|
|
985
|
+
setState = _useGlobalState2[1];
|
|
986
|
+
var setResult = useCallback(function (result) {
|
|
987
|
+
setState({
|
|
988
|
+
isLoading: false,
|
|
989
|
+
isError: false,
|
|
990
|
+
isSuccess: true,
|
|
991
|
+
error: null,
|
|
992
|
+
data: result
|
|
993
|
+
});
|
|
994
|
+
}, [setState]);
|
|
995
|
+
var setError = useCallback(function (error) {
|
|
996
|
+
setState({
|
|
997
|
+
isLoading: false,
|
|
998
|
+
isError: true,
|
|
999
|
+
isSuccess: false,
|
|
1000
|
+
error: error,
|
|
1001
|
+
data: undefined
|
|
1002
|
+
});
|
|
1003
|
+
}, [setState]);
|
|
1004
|
+
var startLoading = useCallback(function () {
|
|
1005
|
+
if (state.isLoading) {
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
setState({
|
|
1009
|
+
isLoading: true,
|
|
1010
|
+
isError: false,
|
|
1011
|
+
isSuccess: false,
|
|
1012
|
+
error: null,
|
|
1013
|
+
data: undefined
|
|
1014
|
+
});
|
|
1015
|
+
}, [setState]);
|
|
1016
|
+
var stopLoading = useCallback(function () {
|
|
1017
|
+
if (!state.isLoading) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
setState(function (state) {
|
|
1021
|
+
return _objectSpread2(_objectSpread2({}, state), {}, {
|
|
1022
|
+
isLoading: false
|
|
1023
|
+
});
|
|
1024
|
+
});
|
|
1025
|
+
}, [setState]);
|
|
1026
|
+
var setLoading = useCallback(function (isLoading) {
|
|
1027
|
+
if (isLoading) {
|
|
1028
|
+
startLoading();
|
|
1029
|
+
} else {
|
|
1030
|
+
stopLoading();
|
|
1031
|
+
}
|
|
1032
|
+
}, [startLoading, stopLoading]);
|
|
1033
|
+
return {
|
|
1034
|
+
state: state,
|
|
1035
|
+
setResult: setResult,
|
|
1036
|
+
setError: setError,
|
|
1037
|
+
startLoading: startLoading,
|
|
1038
|
+
stopLoading: stopLoading,
|
|
1039
|
+
setLoading: setLoading
|
|
1040
|
+
};
|
|
1028
1041
|
};
|
|
1029
1042
|
|
|
1030
1043
|
/**
|
|
@@ -1125,11 +1138,25 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
1125
1138
|
*/
|
|
1126
1139
|
var useDisconnect = function useDisconnect() {
|
|
1127
1140
|
var config = useComPilotConfig();
|
|
1128
|
-
var mutationFn = useCallback(function () {
|
|
1129
|
-
|
|
1130
|
-
|
|
1141
|
+
var mutationFn = useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1142
|
+
var isDisconnected;
|
|
1143
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1144
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1145
|
+
case 0:
|
|
1146
|
+
_context.next = 2;
|
|
1147
|
+
return disconnect(config);
|
|
1148
|
+
case 2:
|
|
1149
|
+
isDisconnected = _context.sent;
|
|
1150
|
+
return _context.abrupt("return", !isDisconnected);
|
|
1151
|
+
case 4:
|
|
1152
|
+
case "end":
|
|
1153
|
+
return _context.stop();
|
|
1154
|
+
}
|
|
1155
|
+
}, _callee);
|
|
1156
|
+
})), [config]);
|
|
1131
1157
|
return useAsyncMutationState({
|
|
1132
1158
|
mutationName: "disconnect",
|
|
1159
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
1133
1160
|
mutationFn: mutationFn
|
|
1134
1161
|
});
|
|
1135
1162
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticate.d.ts","sourceRoot":"../../../../src/hooks","sources":["useAuthenticate.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useAuthenticate.d.ts","sourceRoot":"../../../../src/hooks","sources":["useAuthenticate.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,0CAAuC;AAGzE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,iBACZ,WAAW,KACxB,kBAAkB,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,CAkC3D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisconnect.d.ts","sourceRoot":"../../../../src/hooks","sources":["useDisconnect.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"useDisconnect.d.ts","sourceRoot":"../../../../src/hooks","sources":["useDisconnect.tsx"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,aAAa,4GAezB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetTxAuthDataSignature.d.ts","sourceRoot":"../../../../src/hooks","sources":["useGetTxAuthDataSignature.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,wCAAwC,EACxC,wBAAwB,EACxB,mCAAmC,EACnC,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAKpC;;;;GAIG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;IAC3E;;OAEG;IACH,CACE,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,wCAAwC,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoJG;AACH,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"useGetTxAuthDataSignature.d.ts","sourceRoot":"../../../../src/hooks","sources":["useGetTxAuthDataSignature.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,wCAAwC,EACxC,wBAAwB,EACxB,mCAAmC,EACnC,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAKpC;;;;GAIG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;IAC3E;;OAEG;IACH,CACE,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,wCAAwC,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoJG;AACH,eAAO,MAAM,yBAAyB,6HAgBrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOpenWidget.d.ts","sourceRoot":"../../../../src/hooks","sources":["useOpenWidget.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useOpenWidget.d.ts","sourceRoot":"../../../../src/hooks","sources":["useOpenWidget.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,0CAAuC;AAGzE;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,iBACV,WAAW,KACxB,kBAAkB,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,YAAY,CA0BzD,CAAC"}
|
|
@@ -34,10 +34,15 @@ type ErrorAsyncMutationState<TMutationFn extends AnyMutation> = {
|
|
|
34
34
|
export type RawAsyncMutationState<TMutationFn extends AnyMutation> = IdleAsyncMutationState | SuccessAsyncMutationState<TMutationFn> | LoadingAsyncMutationState | ErrorAsyncMutationState<TMutationFn>;
|
|
35
35
|
export type AsyncMutationState<TMutationFn extends AnyMutation, TMutationName extends string> = RawAsyncMutationState<TMutationFn> & {
|
|
36
36
|
[k in TMutationName]: TMutationFn;
|
|
37
|
+
} & {
|
|
38
|
+
setData: (data: Awaited<ReturnType<TMutationFn>>) => void;
|
|
39
|
+
setPending: (isPending: boolean) => void;
|
|
37
40
|
};
|
|
38
|
-
export declare const useAsyncMutationState: <TMutationFn extends AnyMutation, TMutationName extends string>({ mutationName, mutationFn, }: {
|
|
41
|
+
export declare const useAsyncMutationState: <TMutationFn extends AnyMutation, TMutationName extends string>({ mutationName, mutationKey, mutationFn, defaultValue, }: {
|
|
39
42
|
mutationName: TMutationName;
|
|
43
|
+
mutationKey: string[];
|
|
40
44
|
mutationFn: TMutationFn;
|
|
45
|
+
defaultValue?: Awaited<ReturnType<TMutationFn>>;
|
|
41
46
|
}) => AsyncMutationState<TMutationFn, TMutationName>;
|
|
42
47
|
export {};
|
|
43
48
|
//# sourceMappingURL=useAsyncMutationState.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsyncMutationState.d.ts","sourceRoot":"../../../../src/utils","sources":["useAsyncMutationState.ts"],"names":[],"mappings":"AAKA,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEpD,KAAK,sBAAsB,GAAG;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,IAAI,CAAC;IACb,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,yBAAyB,CAAC,WAAW,SAAS,WAAW,IAAI;IAChE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;IACvC,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,uBAAuB,CAAC,WAAW,SAAS,WAAW,IAAI;IAC9D,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAAG,SAAS,CAAC;IACnD,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,WAAW,SAAS,WAAW,IAC7D,sBAAsB,GACtB,yBAAyB,CAAC,WAAW,CAAC,GACtC,yBAAyB,GACzB,uBAAuB,CAAC,WAAW,CAAC,CAAC;AAEzC,MAAM,MAAM,kBAAkB,CAC5B,WAAW,SAAS,WAAW,EAC/B,aAAa,SAAS,MAAM,IAC1B,qBAAqB,CAAC,WAAW,CAAC,GAAG;KACtC,CAAC,IAAI,aAAa,GAAG,WAAW;CAClC,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,WAAW,SAAS,WAAW,EAC/B,aAAa,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"useAsyncMutationState.d.ts","sourceRoot":"../../../../src/utils","sources":["useAsyncMutationState.ts"],"names":[],"mappings":"AAKA,KAAK,WAAW,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAEpD,KAAK,sBAAsB,GAAG;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,IAAI,CAAC;IACb,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,yBAAyB,CAAC,WAAW,SAAS,WAAW,IAAI;IAChE,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;IACvC,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,uBAAuB,CAAC,WAAW,SAAS,WAAW,IAAI;IAC9D,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAAG,SAAS,CAAC;IACnD,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,KAAK,CAAC;IACjB,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,WAAW,SAAS,WAAW,IAC7D,sBAAsB,GACtB,yBAAyB,CAAC,WAAW,CAAC,GACtC,yBAAyB,GACzB,uBAAuB,CAAC,WAAW,CAAC,CAAC;AAEzC,MAAM,MAAM,kBAAkB,CAC5B,WAAW,SAAS,WAAW,EAC/B,aAAa,SAAS,MAAM,IAC1B,qBAAqB,CAAC,WAAW,CAAC,GAAG;KACtC,CAAC,IAAI,aAAa,GAAG,WAAW;CAClC,GAAG;IACF,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,KAAK,IAAI,CAAC;IAC1D,UAAU,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,WAAW,SAAS,WAAW,EAC/B,aAAa,SAAS,MAAM,4DAM3B;IACD,YAAY,EAAE,aAAa,CAAC;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,UAAU,EAAE,WAAW,CAAC;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;CACjD,KAAG,kBAAkB,CAAC,WAAW,EAAE,aAAa,CA+GhD,CAAC"}
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilot/react-sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.6-dev",
|
|
4
4
|
"description": "ComPilot React SDK",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "ISC",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"pino": "^9.4.0",
|
|
28
28
|
"zod": "^3.23.8",
|
|
29
|
-
"@compilot/web-sdk": "2.2.
|
|
30
|
-
"@nexeraid/identity-api-client": "2.2.
|
|
31
|
-
"@nexeraid/identity-schemas": "2.
|
|
32
|
-
"@nexeraid/logger": "2.2.
|
|
29
|
+
"@compilot/web-sdk": "2.2.6-dev",
|
|
30
|
+
"@nexeraid/identity-api-client": "2.2.4-dev",
|
|
31
|
+
"@nexeraid/identity-schemas": "2.2.6-dev",
|
|
32
|
+
"@nexeraid/logger": "2.2.4-dev"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=17.0.0 <20.0.0"
|