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