@compilot/react-sdk 2.2.1-dev → 2.2.5-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 +306 -251
- package/dist/compilot-react-sdk.cjs.prod.js +306 -251
- package/dist/compilot-react-sdk.esm.js +307 -252
- 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/declarations/src/utils/useAsyncQueryState.d.ts.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +5 -5
|
@@ -20,48 +20,171 @@ var AutoLoader = function AutoLoader(_ref) {
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
function _toPrimitive(t, r) {
|
|
24
|
+
if ("object" != typeof t || !t) return t;
|
|
25
|
+
var e = t[Symbol.toPrimitive];
|
|
26
|
+
if (void 0 !== e) {
|
|
27
|
+
var i = e.call(t, r || "default");
|
|
28
|
+
if ("object" != typeof i) return i;
|
|
29
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
30
|
+
}
|
|
31
|
+
return ("string" === r ? String : Number)(t);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _toPropertyKey(t) {
|
|
35
|
+
var i = _toPrimitive(t, "string");
|
|
36
|
+
return "symbol" == typeof i ? i : i + "";
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function _defineProperty(e, r, t) {
|
|
40
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
41
|
+
value: t,
|
|
42
|
+
enumerable: !0,
|
|
43
|
+
configurable: !0,
|
|
44
|
+
writable: !0
|
|
45
|
+
}) : e[r] = t, e;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function ownKeys(e, r) {
|
|
49
|
+
var t = Object.keys(e);
|
|
50
|
+
if (Object.getOwnPropertySymbols) {
|
|
51
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
52
|
+
r && (o = o.filter(function (r) {
|
|
53
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
54
|
+
})), t.push.apply(t, o);
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
function _objectSpread2(e) {
|
|
59
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
60
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
61
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
62
|
+
_defineProperty(e, r, t[r]);
|
|
63
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
64
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return e;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function _arrayWithHoles(r) {
|
|
71
|
+
if (Array.isArray(r)) return r;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function _iterableToArrayLimit(r, l) {
|
|
75
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
76
|
+
if (null != t) {
|
|
77
|
+
var e,
|
|
78
|
+
n,
|
|
79
|
+
i,
|
|
80
|
+
u,
|
|
81
|
+
a = [],
|
|
82
|
+
f = !0,
|
|
83
|
+
o = !1;
|
|
84
|
+
try {
|
|
85
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
86
|
+
if (Object(t) !== t) return;
|
|
87
|
+
f = !1;
|
|
88
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
89
|
+
} catch (r) {
|
|
90
|
+
o = !0, n = r;
|
|
91
|
+
} finally {
|
|
92
|
+
try {
|
|
93
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
94
|
+
} finally {
|
|
95
|
+
if (o) throw n;
|
|
33
96
|
}
|
|
34
|
-
},
|
|
35
|
-
set: function set(key, value) {
|
|
36
|
-
state[toKey(key)] = value;
|
|
37
|
-
},
|
|
38
|
-
get: function get(key) {
|
|
39
|
-
return state[toKey(key)];
|
|
40
97
|
}
|
|
41
|
-
|
|
42
|
-
}
|
|
98
|
+
return a;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function _arrayLikeToArray(r, a) {
|
|
103
|
+
(null == a || a > r.length) && (a = r.length);
|
|
104
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
105
|
+
return n;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function _unsupportedIterableToArray(r, a) {
|
|
109
|
+
if (r) {
|
|
110
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
111
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
112
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function _nonIterableRest() {
|
|
117
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function _slicedToArray(r, e) {
|
|
121
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var toStateKey = function toStateKey(key) {
|
|
125
|
+
return key.join(":");
|
|
126
|
+
};
|
|
127
|
+
var GlobalStateContext = /*#__PURE__*/react.createContext({
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
129
|
+
set: function set() {},
|
|
130
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
131
|
+
get: function get() {}
|
|
132
|
+
});
|
|
43
133
|
var GlobalStateProvider = function GlobalStateProvider(_ref) {
|
|
44
134
|
var children = _ref.children;
|
|
135
|
+
var _useState = react.useState({}),
|
|
136
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
137
|
+
state = _useState2[0],
|
|
138
|
+
setState = _useState2[1];
|
|
139
|
+
var set = react.useCallback(function (key, value) {
|
|
140
|
+
return setState(_objectSpread2(_objectSpread2({}, state), {}, _defineProperty({}, toStateKey(key), value)));
|
|
141
|
+
}, [state, setState]);
|
|
142
|
+
var get = react.useCallback(function (key) {
|
|
143
|
+
return state[toStateKey(key)];
|
|
144
|
+
}, [state]);
|
|
145
|
+
var value = react.useMemo(function () {
|
|
146
|
+
return {
|
|
147
|
+
set: set,
|
|
148
|
+
get: get
|
|
149
|
+
};
|
|
150
|
+
}, [get, set]);
|
|
45
151
|
return /*#__PURE__*/jsxRuntime.jsx(GlobalStateContext.Provider, {
|
|
46
|
-
value:
|
|
152
|
+
value: value,
|
|
47
153
|
children: children
|
|
48
154
|
});
|
|
49
155
|
};
|
|
50
156
|
function useGlobalState(_ref2) {
|
|
51
157
|
var key = _ref2.key,
|
|
52
|
-
defaultValue = _ref2.defaultValue
|
|
53
|
-
|
|
158
|
+
defaultValue = _ref2.defaultValue,
|
|
159
|
+
_ref2$compareState = _ref2.compareState,
|
|
160
|
+
compareState = _ref2$compareState === void 0 ? function (a, b) {
|
|
161
|
+
return a === b ? 0 : 1;
|
|
162
|
+
} : _ref2$compareState;
|
|
163
|
+
var _useContext = react.useContext(GlobalStateContext),
|
|
164
|
+
set = _useContext.set,
|
|
165
|
+
get = _useContext.get;
|
|
166
|
+
var memoizedDefaultValue = react.useMemo(function () {
|
|
167
|
+
return defaultValue;
|
|
168
|
+
}, []);
|
|
169
|
+
var keyValue = react.useMemo(function () {
|
|
170
|
+
var _ref3;
|
|
171
|
+
return (_ref3 = get(key)) !== null && _ref3 !== void 0 ? _ref3 : memoizedDefaultValue;
|
|
172
|
+
}, [key, get, memoizedDefaultValue]);
|
|
173
|
+
var setter = react.useCallback(function (valueOrSetterFn) {
|
|
174
|
+
var newValue;
|
|
175
|
+
if (typeof valueOrSetterFn === "function") {
|
|
176
|
+
var setterFn = valueOrSetterFn;
|
|
177
|
+
newValue = setterFn(keyValue);
|
|
178
|
+
} else {
|
|
179
|
+
newValue = valueOrSetterFn;
|
|
180
|
+
}
|
|
181
|
+
if (compareState(keyValue, newValue) !== 0) {
|
|
182
|
+
set(key, newValue);
|
|
183
|
+
}
|
|
184
|
+
}, [key, set, get]);
|
|
54
185
|
return react.useMemo(function () {
|
|
55
|
-
return [
|
|
56
|
-
|
|
57
|
-
function (valueOrSetterFn) {
|
|
58
|
-
if (typeof valueOrSetterFn === "function") {
|
|
59
|
-
stateClient.set(key, valueOrSetterFn(stateClient.get(key)));
|
|
60
|
-
} else {
|
|
61
|
-
stateClient.set(key, valueOrSetterFn);
|
|
62
|
-
}
|
|
63
|
-
}];
|
|
64
|
-
}, [key]);
|
|
186
|
+
return [keyValue, setter];
|
|
187
|
+
}, [keyValue, setter]);
|
|
65
188
|
}
|
|
66
189
|
|
|
67
190
|
var ComPilotContext = /*#__PURE__*/react.createContext(null);
|
|
@@ -137,53 +260,6 @@ var useComPilotConfig = function useComPilotConfig() {
|
|
|
137
260
|
return config;
|
|
138
261
|
};
|
|
139
262
|
|
|
140
|
-
function _toPrimitive(t, r) {
|
|
141
|
-
if ("object" != typeof t || !t) return t;
|
|
142
|
-
var e = t[Symbol.toPrimitive];
|
|
143
|
-
if (void 0 !== e) {
|
|
144
|
-
var i = e.call(t, r || "default");
|
|
145
|
-
if ("object" != typeof i) return i;
|
|
146
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
147
|
-
}
|
|
148
|
-
return ("string" === r ? String : Number)(t);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function _toPropertyKey(t) {
|
|
152
|
-
var i = _toPrimitive(t, "string");
|
|
153
|
-
return "symbol" == typeof i ? i : i + "";
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function _defineProperty(e, r, t) {
|
|
157
|
-
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
158
|
-
value: t,
|
|
159
|
-
enumerable: !0,
|
|
160
|
-
configurable: !0,
|
|
161
|
-
writable: !0
|
|
162
|
-
}) : e[r] = t, e;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function ownKeys(e, r) {
|
|
166
|
-
var t = Object.keys(e);
|
|
167
|
-
if (Object.getOwnPropertySymbols) {
|
|
168
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
169
|
-
r && (o = o.filter(function (r) {
|
|
170
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
171
|
-
})), t.push.apply(t, o);
|
|
172
|
-
}
|
|
173
|
-
return t;
|
|
174
|
-
}
|
|
175
|
-
function _objectSpread2(e) {
|
|
176
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
177
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
178
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
179
|
-
_defineProperty(e, r, t[r]);
|
|
180
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
181
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
return e;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
263
|
function _regeneratorRuntime() {
|
|
188
264
|
_regeneratorRuntime = function () {
|
|
189
265
|
return e;
|
|
@@ -512,69 +588,33 @@ function _asyncToGenerator(n) {
|
|
|
512
588
|
};
|
|
513
589
|
}
|
|
514
590
|
|
|
515
|
-
function
|
|
516
|
-
if (Array.isArray(r)) return r;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
function _iterableToArrayLimit(r, l) {
|
|
520
|
-
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
521
|
-
if (null != t) {
|
|
522
|
-
var e,
|
|
523
|
-
n,
|
|
524
|
-
i,
|
|
525
|
-
u,
|
|
526
|
-
a = [],
|
|
527
|
-
f = !0,
|
|
528
|
-
o = !1;
|
|
529
|
-
try {
|
|
530
|
-
if (i = (t = t.call(r)).next, 0 === l) {
|
|
531
|
-
if (Object(t) !== t) return;
|
|
532
|
-
f = !1;
|
|
533
|
-
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
534
|
-
} catch (r) {
|
|
535
|
-
o = !0, n = r;
|
|
536
|
-
} finally {
|
|
537
|
-
try {
|
|
538
|
-
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
539
|
-
} finally {
|
|
540
|
-
if (o) throw n;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
return a;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
function _arrayLikeToArray(r, a) {
|
|
548
|
-
(null == a || a > r.length) && (a = r.length);
|
|
549
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
550
|
-
return n;
|
|
591
|
+
function _arrayWithoutHoles(r) {
|
|
592
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
551
593
|
}
|
|
552
594
|
|
|
553
|
-
function
|
|
554
|
-
if (r)
|
|
555
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
556
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
557
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
558
|
-
}
|
|
595
|
+
function _iterableToArray(r) {
|
|
596
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
559
597
|
}
|
|
560
598
|
|
|
561
|
-
function
|
|
562
|
-
throw new TypeError("Invalid attempt to
|
|
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.");
|
|
563
601
|
}
|
|
564
602
|
|
|
565
|
-
function
|
|
566
|
-
return
|
|
603
|
+
function _toConsumableArray(r) {
|
|
604
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
567
605
|
}
|
|
568
606
|
|
|
569
607
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
570
608
|
|
|
571
609
|
var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
572
610
|
var mutationName = _ref.mutationName,
|
|
573
|
-
|
|
611
|
+
mutationKey = _ref.mutationKey,
|
|
612
|
+
mutationFn = _ref.mutationFn,
|
|
613
|
+
defaultValue = _ref.defaultValue;
|
|
574
614
|
var _useGlobalState = useGlobalState({
|
|
575
|
-
key: ["useAsyncMutationState"
|
|
615
|
+
key: ["useAsyncMutationState"].concat(_toConsumableArray(mutationKey !== null && mutationKey !== void 0 ? mutationKey : [])),
|
|
576
616
|
defaultValue: {
|
|
577
|
-
data:
|
|
617
|
+
data: defaultValue,
|
|
578
618
|
isIdle: true,
|
|
579
619
|
isPending: false,
|
|
580
620
|
isError: false,
|
|
@@ -632,96 +672,47 @@ var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
|
632
672
|
}
|
|
633
673
|
}, _callee, null, [[1, 9]]);
|
|
634
674
|
})), [setState, mutationFn]);
|
|
635
|
-
|
|
636
|
-
};
|
|
637
|
-
|
|
638
|
-
function _arrayWithoutHoles(r) {
|
|
639
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
function _iterableToArray(r) {
|
|
643
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
function _nonIterableSpread() {
|
|
647
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
function _toConsumableArray(r) {
|
|
651
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
655
|
-
var queryKey = _ref.queryKey,
|
|
656
|
-
defaultValue = _ref.defaultValue;
|
|
657
|
-
var _useGlobalState = useGlobalState({
|
|
658
|
-
key: ["useAsyncQueryState"].concat(_toConsumableArray(queryKey)),
|
|
659
|
-
defaultValue: defaultValue === undefined ? {
|
|
660
|
-
isLoading: false,
|
|
661
|
-
isError: false,
|
|
662
|
-
isSuccess: false,
|
|
663
|
-
error: null,
|
|
664
|
-
data: undefined
|
|
665
|
-
} : {
|
|
666
|
-
isLoading: false,
|
|
667
|
-
isError: false,
|
|
668
|
-
isSuccess: true,
|
|
669
|
-
error: null,
|
|
670
|
-
data: defaultValue
|
|
671
|
-
}
|
|
672
|
-
}),
|
|
673
|
-
_useGlobalState2 = _slicedToArray(_useGlobalState, 2),
|
|
674
|
-
state = _useGlobalState2[0],
|
|
675
|
-
setState = _useGlobalState2[1];
|
|
676
|
-
var setResult = react.useCallback(function (result) {
|
|
675
|
+
var setData = react.useCallback(function (data) {
|
|
677
676
|
setState({
|
|
678
|
-
|
|
677
|
+
data: data,
|
|
678
|
+
isIdle: false,
|
|
679
|
+
isPending: false,
|
|
679
680
|
isError: false,
|
|
680
681
|
isSuccess: true,
|
|
681
|
-
error: null
|
|
682
|
-
data: result
|
|
683
|
-
});
|
|
684
|
-
}, [setState]);
|
|
685
|
-
var setError = react.useCallback(function (error) {
|
|
686
|
-
setState({
|
|
687
|
-
isLoading: false,
|
|
688
|
-
isError: true,
|
|
689
|
-
isSuccess: false,
|
|
690
|
-
error: error,
|
|
691
|
-
data: undefined
|
|
682
|
+
error: null
|
|
692
683
|
});
|
|
693
684
|
}, [setState]);
|
|
694
|
-
var
|
|
685
|
+
var startPending = react.useCallback(function () {
|
|
686
|
+
if (state.isPending) {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
695
689
|
setState({
|
|
696
|
-
|
|
690
|
+
data: undefined,
|
|
691
|
+
isIdle: false,
|
|
692
|
+
isPending: true,
|
|
697
693
|
isError: false,
|
|
698
694
|
isSuccess: false,
|
|
699
|
-
error: null
|
|
700
|
-
data: undefined
|
|
695
|
+
error: null
|
|
701
696
|
});
|
|
702
|
-
}, [setState]);
|
|
703
|
-
var
|
|
704
|
-
|
|
705
|
-
return
|
|
706
|
-
|
|
697
|
+
}, [setState, state.isPending]);
|
|
698
|
+
var stopPending = react.useCallback(function () {
|
|
699
|
+
if (!state.isPending) {
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
setState(function (s) {
|
|
703
|
+
return _objectSpread2(_objectSpread2({}, s), {}, {
|
|
704
|
+
isPending: false
|
|
707
705
|
});
|
|
708
706
|
});
|
|
709
|
-
}, [setState]);
|
|
710
|
-
var
|
|
711
|
-
if (
|
|
712
|
-
|
|
707
|
+
}, [setState, state.isPending]);
|
|
708
|
+
var setPending = react.useCallback(function (isPending) {
|
|
709
|
+
if (isPending) {
|
|
710
|
+
startPending();
|
|
713
711
|
} else {
|
|
714
|
-
|
|
712
|
+
stopPending();
|
|
715
713
|
}
|
|
716
|
-
}, [
|
|
717
|
-
return {
|
|
718
|
-
state: state,
|
|
719
|
-
setResult: setResult,
|
|
720
|
-
setError: setError,
|
|
721
|
-
startLoading: startLoading,
|
|
722
|
-
stopLoading: stopLoading,
|
|
723
|
-
setLoading: setLoading
|
|
724
|
-
};
|
|
714
|
+
}, [startPending, stopPending]);
|
|
715
|
+
return _objectSpread2(_objectSpread2({}, state), {}, _defineProperty(_defineProperty(_defineProperty({}, mutationName, mutateAsync), "setData", setData), "setPending", setPending));
|
|
725
716
|
};
|
|
726
717
|
|
|
727
718
|
/**
|
|
@@ -739,36 +730,20 @@ var useOpenWidget = function useOpenWidget(loginParams) {
|
|
|
739
730
|
}, [config]);
|
|
740
731
|
var mutationState = useAsyncMutationState({
|
|
741
732
|
mutationName: "openWidget",
|
|
742
|
-
|
|
733
|
+
mutationKey: ["openWidget", config._internal.identifier],
|
|
734
|
+
mutationFn: mutationFn,
|
|
735
|
+
defaultValue: webSdk.isOpen(config)
|
|
743
736
|
});
|
|
744
|
-
// but open state can change without us mutating it
|
|
745
|
-
// that's the only case for now so we don't need another kind of mutation state
|
|
746
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
747
|
-
queryKey: ["useOpenWidget", config._internal.identifier],
|
|
748
|
-
defaultValue: webSdk.isOpen(config)
|
|
749
|
-
}),
|
|
750
|
-
setResult = _useAsyncQueryState.setResult,
|
|
751
|
-
setLoading = _useAsyncQueryState.setLoading,
|
|
752
|
-
queryState = _useAsyncQueryState.state;
|
|
753
737
|
react.useEffect(function () {
|
|
754
738
|
var unsubscribe = webSdk.watchWidgetVisibleState(config, {
|
|
755
739
|
onChange: function onChange(isVisible) {
|
|
756
|
-
|
|
740
|
+
mutationState.setData(isVisible);
|
|
757
741
|
},
|
|
758
|
-
onIsLoadingChange:
|
|
742
|
+
onIsLoadingChange: mutationState.setPending
|
|
759
743
|
});
|
|
760
744
|
return unsubscribe;
|
|
761
|
-
}, [config,
|
|
762
|
-
return
|
|
763
|
-
error: queryState.error,
|
|
764
|
-
isPending: queryState.isLoading,
|
|
765
|
-
isSuccess: queryState.isSuccess,
|
|
766
|
-
isError: queryState.isError,
|
|
767
|
-
isIdle: !queryState.isError && !queryState.isLoading && !queryState.isSuccess,
|
|
768
|
-
data: queryState.data
|
|
769
|
-
}), {}, {
|
|
770
|
-
openWidget: mutationState.openWidget
|
|
771
|
-
});
|
|
745
|
+
}, [config, mutationState.setData, mutationState.setPending]);
|
|
746
|
+
return mutationState;
|
|
772
747
|
};
|
|
773
748
|
|
|
774
749
|
/**
|
|
@@ -951,6 +926,7 @@ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
|
951
926
|
}(), [config._internal.widgetStateStore, config._internal.identifier]);
|
|
952
927
|
return useAsyncMutationState({
|
|
953
928
|
mutationName: "getTxAuthDataSignature",
|
|
929
|
+
mutationKey: ["getTxAuthDataSignature", config._internal.identifier],
|
|
954
930
|
mutationFn: mutationFn
|
|
955
931
|
});
|
|
956
932
|
};
|
|
@@ -970,36 +946,101 @@ var useAuthenticate = function useAuthenticate(loginParams) {
|
|
|
970
946
|
}, [config]);
|
|
971
947
|
var mutationState = useAsyncMutationState({
|
|
972
948
|
mutationName: "authenticate",
|
|
973
|
-
|
|
949
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
950
|
+
mutationFn: mutationFn,
|
|
951
|
+
defaultValue: webSdk.isAuthenticated(config)
|
|
974
952
|
});
|
|
975
|
-
var _useAsyncQueryState = useAsyncQueryState({
|
|
976
|
-
queryKey: ["useAuthenticate", config._internal.identifier],
|
|
977
|
-
defaultValue: webSdk.isAuthenticated(config)
|
|
978
|
-
}),
|
|
979
|
-
queryState = _useAsyncQueryState.state,
|
|
980
|
-
setResult = _useAsyncQueryState.setResult,
|
|
981
|
-
setLoading = _useAsyncQueryState.setLoading;
|
|
982
953
|
react.useEffect(function () {
|
|
983
954
|
var unsubscribe = webSdk.watchIsAuthenticated(config, {
|
|
984
955
|
onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
|
|
985
|
-
|
|
956
|
+
mutationState.setData(isAuthenticated);
|
|
986
957
|
},
|
|
987
|
-
onIsLoadingChange:
|
|
958
|
+
onIsLoadingChange: mutationState.setPending
|
|
988
959
|
});
|
|
989
960
|
return function () {
|
|
990
961
|
unsubscribe();
|
|
991
962
|
};
|
|
992
|
-
}, [config._internal.widgetStateStore, config._internal.identifier]);
|
|
993
|
-
return
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
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
|
+
};
|
|
1003
1044
|
};
|
|
1004
1045
|
|
|
1005
1046
|
/**
|
|
@@ -1100,11 +1141,25 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
1100
1141
|
*/
|
|
1101
1142
|
var useDisconnect = function useDisconnect() {
|
|
1102
1143
|
var config = useComPilotConfig();
|
|
1103
|
-
var mutationFn = react.useCallback(function () {
|
|
1104
|
-
|
|
1105
|
-
|
|
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]);
|
|
1106
1160
|
return useAsyncMutationState({
|
|
1107
1161
|
mutationName: "disconnect",
|
|
1162
|
+
mutationKey: ["login-state", config._internal.identifier],
|
|
1108
1163
|
mutationFn: mutationFn
|
|
1109
1164
|
});
|
|
1110
1165
|
};
|