@compilot/react-sdk 2.3.11-dev → 2.3.14-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 +152 -9
- package/dist/compilot-react-sdk.cjs.prod.js +152 -9
- package/dist/compilot-react-sdk.esm.js +153 -11
- package/dist/declarations/src/hooks/index.d.ts +1 -0
- package/dist/declarations/src/hooks/index.d.ts.map +1 -1
- package/dist/declarations/src/hooks/useCustomerStatus.d.ts.map +1 -1
- package/dist/declarations/src/hooks/useIdentityId.d.ts +5 -0
- package/dist/declarations/src/hooks/useIdentityId.d.ts.map +1 -0
- package/dist/declarations/src/hooks/useIdentityWallets.d.ts.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +5 -5
|
@@ -777,6 +777,23 @@ var useAuthenticate = function useAuthenticate(loginParams) {
|
|
|
777
777
|
return mutationState;
|
|
778
778
|
};
|
|
779
779
|
|
|
780
|
+
function simpleLeadingDebounce(fn, ms) {
|
|
781
|
+
var lastCallRes = null;
|
|
782
|
+
var lastCallTime = 0;
|
|
783
|
+
|
|
784
|
+
// debounce leading
|
|
785
|
+
var debouncedFunc = function debouncedFunc() {
|
|
786
|
+
var now = Date.now();
|
|
787
|
+
if (now - lastCallTime < ms) {
|
|
788
|
+
return lastCallRes;
|
|
789
|
+
}
|
|
790
|
+
lastCallTime = now;
|
|
791
|
+
lastCallRes = fn.apply(void 0, arguments);
|
|
792
|
+
return lastCallRes;
|
|
793
|
+
};
|
|
794
|
+
return debouncedFunc;
|
|
795
|
+
}
|
|
796
|
+
|
|
780
797
|
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
781
798
|
var queryKey = _ref.queryKey,
|
|
782
799
|
defaultValue = _ref.defaultValue;
|
|
@@ -929,17 +946,21 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
929
946
|
case 0:
|
|
930
947
|
_context.prev = 0;
|
|
931
948
|
_context.next = 3;
|
|
932
|
-
return
|
|
949
|
+
return fetchCustomerStatus(config);
|
|
933
950
|
case 3:
|
|
934
951
|
status = _context.sent;
|
|
935
952
|
setResult(status);
|
|
936
|
-
_context.next =
|
|
953
|
+
_context.next = 11;
|
|
937
954
|
break;
|
|
938
955
|
case 7:
|
|
939
956
|
_context.prev = 7;
|
|
940
957
|
_context.t0 = _context["catch"](0);
|
|
958
|
+
config._internal.logger.error({
|
|
959
|
+
msg: "Failed to fetch user status",
|
|
960
|
+
error: _context.t0
|
|
961
|
+
});
|
|
941
962
|
setError(_context.t0 instanceof Error ? _context.t0 : new Error(String(_context.t0)));
|
|
942
|
-
case
|
|
963
|
+
case 11:
|
|
943
964
|
case "end":
|
|
944
965
|
return _context.stop();
|
|
945
966
|
}
|
|
@@ -951,20 +972,62 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
951
972
|
}();
|
|
952
973
|
if (refreshOnMount) {
|
|
953
974
|
if (state.data === undefined) {
|
|
954
|
-
startLoading();
|
|
955
975
|
void updateStatus();
|
|
956
976
|
}
|
|
957
977
|
}
|
|
958
978
|
var interval = setInterval(function () {
|
|
959
979
|
return void updateStatus();
|
|
960
980
|
}, refreshInterval);
|
|
981
|
+
|
|
982
|
+
// on close, update status
|
|
983
|
+
var unsubscribeVisibility = webSdk.watchWidgetVisibleState(config, {
|
|
984
|
+
onChange: function onChange(isVisible) {
|
|
985
|
+
if (!isVisible) {
|
|
986
|
+
void updateStatus();
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
var unsubscribeAuth = webSdk.watchIsAuthenticated(config, {
|
|
991
|
+
onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
|
|
992
|
+
if (isAuthenticated) {
|
|
993
|
+
void updateStatus();
|
|
994
|
+
} else {
|
|
995
|
+
setResult(null);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
});
|
|
961
999
|
return function () {
|
|
1000
|
+
unsubscribeVisibility();
|
|
1001
|
+
unsubscribeAuth();
|
|
962
1002
|
clearInterval(interval);
|
|
963
1003
|
};
|
|
964
1004
|
}, [config._internal.identifier, refreshInterval, state.data, config, setError, setResult, startLoading]);
|
|
965
1005
|
return state;
|
|
966
1006
|
};
|
|
967
1007
|
|
|
1008
|
+
// ensure the debounce is global accross all react hook instances
|
|
1009
|
+
var fetchCustomerStatus = simpleLeadingDebounce(/*#__PURE__*/function () {
|
|
1010
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config) {
|
|
1011
|
+
var status;
|
|
1012
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1013
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1014
|
+
case 0:
|
|
1015
|
+
_context2.next = 2;
|
|
1016
|
+
return webSdk.getCustomerStatus(config);
|
|
1017
|
+
case 2:
|
|
1018
|
+
status = _context2.sent;
|
|
1019
|
+
return _context2.abrupt("return", status);
|
|
1020
|
+
case 4:
|
|
1021
|
+
case "end":
|
|
1022
|
+
return _context2.stop();
|
|
1023
|
+
}
|
|
1024
|
+
}, _callee2);
|
|
1025
|
+
}));
|
|
1026
|
+
return function (_x) {
|
|
1027
|
+
return _ref3.apply(this, arguments);
|
|
1028
|
+
};
|
|
1029
|
+
}(), 500);
|
|
1030
|
+
|
|
968
1031
|
/**
|
|
969
1032
|
* A hook that returns a function that disconnects the ComPilot SDK.
|
|
970
1033
|
*
|
|
@@ -1201,6 +1264,80 @@ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
|
1201
1264
|
});
|
|
1202
1265
|
};
|
|
1203
1266
|
|
|
1267
|
+
/**
|
|
1268
|
+
* A hook that returns the current identity id.
|
|
1269
|
+
*/
|
|
1270
|
+
var useIdentityId = function useIdentityId() {
|
|
1271
|
+
var config = useComPilotConfig();
|
|
1272
|
+
var _useAsyncQueryState = useAsyncQueryState({
|
|
1273
|
+
queryKey: ["useIdentityId", config._internal.identifier],
|
|
1274
|
+
defaultValue: null
|
|
1275
|
+
}),
|
|
1276
|
+
state = _useAsyncQueryState.state,
|
|
1277
|
+
setError = _useAsyncQueryState.setError,
|
|
1278
|
+
setResult = _useAsyncQueryState.setResult,
|
|
1279
|
+
setLoading = _useAsyncQueryState.setLoading;
|
|
1280
|
+
react.useEffect(function () {
|
|
1281
|
+
if (!config) {
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
if (webSdk.isAuthenticated(config)) {
|
|
1285
|
+
webSdk.getIdentityId(config).then(function (res) {
|
|
1286
|
+
return setResult(res);
|
|
1287
|
+
})["catch"](function (err) {
|
|
1288
|
+
config._internal.logger.error("Failed to fetch identity id", err);
|
|
1289
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
var unsubscribe = webSdk.watchIsAuthenticated(config, {
|
|
1293
|
+
onIsAuthenticatedChange: function () {
|
|
1294
|
+
var _onIsAuthenticatedChange = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(isAuthenticated) {
|
|
1295
|
+
var res;
|
|
1296
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1297
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1298
|
+
case 0:
|
|
1299
|
+
if (isAuthenticated) {
|
|
1300
|
+
_context.next = 3;
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
setResult(null);
|
|
1304
|
+
return _context.abrupt("return");
|
|
1305
|
+
case 3:
|
|
1306
|
+
_context.prev = 3;
|
|
1307
|
+
_context.next = 6;
|
|
1308
|
+
return webSdk.getIdentityId(config);
|
|
1309
|
+
case 6:
|
|
1310
|
+
res = _context.sent;
|
|
1311
|
+
setResult(res);
|
|
1312
|
+
_context.next = 14;
|
|
1313
|
+
break;
|
|
1314
|
+
case 10:
|
|
1315
|
+
_context.prev = 10;
|
|
1316
|
+
_context.t0 = _context["catch"](3);
|
|
1317
|
+
config._internal.logger.error("Failed to fetch identity id", _context.t0);
|
|
1318
|
+
setError(_context.t0 instanceof Error ? _context.t0 : new Error("Unknown error"));
|
|
1319
|
+
case 14:
|
|
1320
|
+
case "end":
|
|
1321
|
+
return _context.stop();
|
|
1322
|
+
}
|
|
1323
|
+
}, _callee, null, [[3, 10]]);
|
|
1324
|
+
}));
|
|
1325
|
+
function onIsAuthenticatedChange(_x) {
|
|
1326
|
+
return _onIsAuthenticatedChange.apply(this, arguments);
|
|
1327
|
+
}
|
|
1328
|
+
return onIsAuthenticatedChange;
|
|
1329
|
+
}(),
|
|
1330
|
+
onIsLoadingChange: function onIsLoadingChange(isLoading) {
|
|
1331
|
+
if (isLoading) {
|
|
1332
|
+
setLoading(true);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
return unsubscribe;
|
|
1337
|
+
}, [config]);
|
|
1338
|
+
return state;
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1204
1341
|
/**
|
|
1205
1342
|
* A hook that returns the current identity wallets.
|
|
1206
1343
|
*/
|
|
@@ -1239,14 +1376,19 @@ var useIdentityWallets = function useIdentityWallets() {
|
|
|
1239
1376
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1240
1377
|
while (1) switch (_context.prev = _context.next) {
|
|
1241
1378
|
case 0:
|
|
1242
|
-
|
|
1379
|
+
_context.next = 2;
|
|
1380
|
+
return webSdk.attachWalletToIdentity(config, {
|
|
1243
1381
|
wallet: wallet
|
|
1244
1382
|
});
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1383
|
+
case 2:
|
|
1384
|
+
res = _context.sent;
|
|
1385
|
+
if (res) {
|
|
1386
|
+
setQueryCacheBuster(function (prev) {
|
|
1387
|
+
return prev + 1;
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1248
1390
|
return _context.abrupt("return", res);
|
|
1249
|
-
case
|
|
1391
|
+
case 5:
|
|
1250
1392
|
case "end":
|
|
1251
1393
|
return _context.stop();
|
|
1252
1394
|
}
|
|
@@ -1304,6 +1446,7 @@ exports.useComPilotConfig = useComPilotConfig;
|
|
|
1304
1446
|
exports.useCustomerStatus = useCustomerStatus;
|
|
1305
1447
|
exports.useDisconnect = useDisconnect;
|
|
1306
1448
|
exports.useGetTxAuthDataSignature = useGetTxAuthDataSignature;
|
|
1449
|
+
exports.useIdentityId = useIdentityId;
|
|
1307
1450
|
exports.useIdentityWallets = useIdentityWallets;
|
|
1308
1451
|
exports.useOpenWidget = useOpenWidget;
|
|
1309
1452
|
Object.keys(webSdk).forEach(function (k) {
|
|
@@ -777,6 +777,23 @@ var useAuthenticate = function useAuthenticate(loginParams) {
|
|
|
777
777
|
return mutationState;
|
|
778
778
|
};
|
|
779
779
|
|
|
780
|
+
function simpleLeadingDebounce(fn, ms) {
|
|
781
|
+
var lastCallRes = null;
|
|
782
|
+
var lastCallTime = 0;
|
|
783
|
+
|
|
784
|
+
// debounce leading
|
|
785
|
+
var debouncedFunc = function debouncedFunc() {
|
|
786
|
+
var now = Date.now();
|
|
787
|
+
if (now - lastCallTime < ms) {
|
|
788
|
+
return lastCallRes;
|
|
789
|
+
}
|
|
790
|
+
lastCallTime = now;
|
|
791
|
+
lastCallRes = fn.apply(void 0, arguments);
|
|
792
|
+
return lastCallRes;
|
|
793
|
+
};
|
|
794
|
+
return debouncedFunc;
|
|
795
|
+
}
|
|
796
|
+
|
|
780
797
|
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
781
798
|
var queryKey = _ref.queryKey,
|
|
782
799
|
defaultValue = _ref.defaultValue;
|
|
@@ -929,17 +946,21 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
929
946
|
case 0:
|
|
930
947
|
_context.prev = 0;
|
|
931
948
|
_context.next = 3;
|
|
932
|
-
return
|
|
949
|
+
return fetchCustomerStatus(config);
|
|
933
950
|
case 3:
|
|
934
951
|
status = _context.sent;
|
|
935
952
|
setResult(status);
|
|
936
|
-
_context.next =
|
|
953
|
+
_context.next = 11;
|
|
937
954
|
break;
|
|
938
955
|
case 7:
|
|
939
956
|
_context.prev = 7;
|
|
940
957
|
_context.t0 = _context["catch"](0);
|
|
958
|
+
config._internal.logger.error({
|
|
959
|
+
msg: "Failed to fetch user status",
|
|
960
|
+
error: _context.t0
|
|
961
|
+
});
|
|
941
962
|
setError(_context.t0 instanceof Error ? _context.t0 : new Error(String(_context.t0)));
|
|
942
|
-
case
|
|
963
|
+
case 11:
|
|
943
964
|
case "end":
|
|
944
965
|
return _context.stop();
|
|
945
966
|
}
|
|
@@ -951,20 +972,62 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
951
972
|
}();
|
|
952
973
|
if (refreshOnMount) {
|
|
953
974
|
if (state.data === undefined) {
|
|
954
|
-
startLoading();
|
|
955
975
|
void updateStatus();
|
|
956
976
|
}
|
|
957
977
|
}
|
|
958
978
|
var interval = setInterval(function () {
|
|
959
979
|
return void updateStatus();
|
|
960
980
|
}, refreshInterval);
|
|
981
|
+
|
|
982
|
+
// on close, update status
|
|
983
|
+
var unsubscribeVisibility = webSdk.watchWidgetVisibleState(config, {
|
|
984
|
+
onChange: function onChange(isVisible) {
|
|
985
|
+
if (!isVisible) {
|
|
986
|
+
void updateStatus();
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
var unsubscribeAuth = webSdk.watchIsAuthenticated(config, {
|
|
991
|
+
onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
|
|
992
|
+
if (isAuthenticated) {
|
|
993
|
+
void updateStatus();
|
|
994
|
+
} else {
|
|
995
|
+
setResult(null);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
});
|
|
961
999
|
return function () {
|
|
1000
|
+
unsubscribeVisibility();
|
|
1001
|
+
unsubscribeAuth();
|
|
962
1002
|
clearInterval(interval);
|
|
963
1003
|
};
|
|
964
1004
|
}, [config._internal.identifier, refreshInterval, state.data, config, setError, setResult, startLoading]);
|
|
965
1005
|
return state;
|
|
966
1006
|
};
|
|
967
1007
|
|
|
1008
|
+
// ensure the debounce is global accross all react hook instances
|
|
1009
|
+
var fetchCustomerStatus = simpleLeadingDebounce(/*#__PURE__*/function () {
|
|
1010
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config) {
|
|
1011
|
+
var status;
|
|
1012
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1013
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1014
|
+
case 0:
|
|
1015
|
+
_context2.next = 2;
|
|
1016
|
+
return webSdk.getCustomerStatus(config);
|
|
1017
|
+
case 2:
|
|
1018
|
+
status = _context2.sent;
|
|
1019
|
+
return _context2.abrupt("return", status);
|
|
1020
|
+
case 4:
|
|
1021
|
+
case "end":
|
|
1022
|
+
return _context2.stop();
|
|
1023
|
+
}
|
|
1024
|
+
}, _callee2);
|
|
1025
|
+
}));
|
|
1026
|
+
return function (_x) {
|
|
1027
|
+
return _ref3.apply(this, arguments);
|
|
1028
|
+
};
|
|
1029
|
+
}(), 500);
|
|
1030
|
+
|
|
968
1031
|
/**
|
|
969
1032
|
* A hook that returns a function that disconnects the ComPilot SDK.
|
|
970
1033
|
*
|
|
@@ -1201,6 +1264,80 @@ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
|
1201
1264
|
});
|
|
1202
1265
|
};
|
|
1203
1266
|
|
|
1267
|
+
/**
|
|
1268
|
+
* A hook that returns the current identity id.
|
|
1269
|
+
*/
|
|
1270
|
+
var useIdentityId = function useIdentityId() {
|
|
1271
|
+
var config = useComPilotConfig();
|
|
1272
|
+
var _useAsyncQueryState = useAsyncQueryState({
|
|
1273
|
+
queryKey: ["useIdentityId", config._internal.identifier],
|
|
1274
|
+
defaultValue: null
|
|
1275
|
+
}),
|
|
1276
|
+
state = _useAsyncQueryState.state,
|
|
1277
|
+
setError = _useAsyncQueryState.setError,
|
|
1278
|
+
setResult = _useAsyncQueryState.setResult,
|
|
1279
|
+
setLoading = _useAsyncQueryState.setLoading;
|
|
1280
|
+
react.useEffect(function () {
|
|
1281
|
+
if (!config) {
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
if (webSdk.isAuthenticated(config)) {
|
|
1285
|
+
webSdk.getIdentityId(config).then(function (res) {
|
|
1286
|
+
return setResult(res);
|
|
1287
|
+
})["catch"](function (err) {
|
|
1288
|
+
config._internal.logger.error("Failed to fetch identity id", err);
|
|
1289
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
var unsubscribe = webSdk.watchIsAuthenticated(config, {
|
|
1293
|
+
onIsAuthenticatedChange: function () {
|
|
1294
|
+
var _onIsAuthenticatedChange = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(isAuthenticated) {
|
|
1295
|
+
var res;
|
|
1296
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1297
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1298
|
+
case 0:
|
|
1299
|
+
if (isAuthenticated) {
|
|
1300
|
+
_context.next = 3;
|
|
1301
|
+
break;
|
|
1302
|
+
}
|
|
1303
|
+
setResult(null);
|
|
1304
|
+
return _context.abrupt("return");
|
|
1305
|
+
case 3:
|
|
1306
|
+
_context.prev = 3;
|
|
1307
|
+
_context.next = 6;
|
|
1308
|
+
return webSdk.getIdentityId(config);
|
|
1309
|
+
case 6:
|
|
1310
|
+
res = _context.sent;
|
|
1311
|
+
setResult(res);
|
|
1312
|
+
_context.next = 14;
|
|
1313
|
+
break;
|
|
1314
|
+
case 10:
|
|
1315
|
+
_context.prev = 10;
|
|
1316
|
+
_context.t0 = _context["catch"](3);
|
|
1317
|
+
config._internal.logger.error("Failed to fetch identity id", _context.t0);
|
|
1318
|
+
setError(_context.t0 instanceof Error ? _context.t0 : new Error("Unknown error"));
|
|
1319
|
+
case 14:
|
|
1320
|
+
case "end":
|
|
1321
|
+
return _context.stop();
|
|
1322
|
+
}
|
|
1323
|
+
}, _callee, null, [[3, 10]]);
|
|
1324
|
+
}));
|
|
1325
|
+
function onIsAuthenticatedChange(_x) {
|
|
1326
|
+
return _onIsAuthenticatedChange.apply(this, arguments);
|
|
1327
|
+
}
|
|
1328
|
+
return onIsAuthenticatedChange;
|
|
1329
|
+
}(),
|
|
1330
|
+
onIsLoadingChange: function onIsLoadingChange(isLoading) {
|
|
1331
|
+
if (isLoading) {
|
|
1332
|
+
setLoading(true);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
return unsubscribe;
|
|
1337
|
+
}, [config]);
|
|
1338
|
+
return state;
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1204
1341
|
/**
|
|
1205
1342
|
* A hook that returns the current identity wallets.
|
|
1206
1343
|
*/
|
|
@@ -1239,14 +1376,19 @@ var useIdentityWallets = function useIdentityWallets() {
|
|
|
1239
1376
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1240
1377
|
while (1) switch (_context.prev = _context.next) {
|
|
1241
1378
|
case 0:
|
|
1242
|
-
|
|
1379
|
+
_context.next = 2;
|
|
1380
|
+
return webSdk.attachWalletToIdentity(config, {
|
|
1243
1381
|
wallet: wallet
|
|
1244
1382
|
});
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1383
|
+
case 2:
|
|
1384
|
+
res = _context.sent;
|
|
1385
|
+
if (res) {
|
|
1386
|
+
setQueryCacheBuster(function (prev) {
|
|
1387
|
+
return prev + 1;
|
|
1388
|
+
});
|
|
1389
|
+
}
|
|
1248
1390
|
return _context.abrupt("return", res);
|
|
1249
|
-
case
|
|
1391
|
+
case 5:
|
|
1250
1392
|
case "end":
|
|
1251
1393
|
return _context.stop();
|
|
1252
1394
|
}
|
|
@@ -1304,6 +1446,7 @@ exports.useComPilotConfig = useComPilotConfig;
|
|
|
1304
1446
|
exports.useCustomerStatus = useCustomerStatus;
|
|
1305
1447
|
exports.useDisconnect = useDisconnect;
|
|
1306
1448
|
exports.useGetTxAuthDataSignature = useGetTxAuthDataSignature;
|
|
1449
|
+
exports.useIdentityId = useIdentityId;
|
|
1307
1450
|
exports.useIdentityWallets = useIdentityWallets;
|
|
1308
1451
|
exports.useOpenWidget = useOpenWidget;
|
|
1309
1452
|
Object.keys(webSdk).forEach(function (k) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState, useCallback, useMemo, createContext, useContext } from 'react';
|
|
2
|
-
import { load, authenticate, isAuthenticated, watchIsAuthenticated, watchCustomerStatus, getCustomerStatus, disconnect, getTxAuthDataSignature, getIdentityWallets, attachWalletToIdentity, openWidget, isOpen
|
|
2
|
+
import { load, authenticate, isAuthenticated, watchIsAuthenticated, watchCustomerStatus, watchWidgetVisibleState, getCustomerStatus, disconnect, getTxAuthDataSignature, getIdentityId, getIdentityWallets, attachWalletToIdentity, openWidget, isOpen } from '@compilot/web-sdk';
|
|
3
3
|
export * from '@compilot/web-sdk';
|
|
4
4
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
|
|
@@ -774,6 +774,23 @@ var useAuthenticate = function useAuthenticate(loginParams) {
|
|
|
774
774
|
return mutationState;
|
|
775
775
|
};
|
|
776
776
|
|
|
777
|
+
function simpleLeadingDebounce(fn, ms) {
|
|
778
|
+
var lastCallRes = null;
|
|
779
|
+
var lastCallTime = 0;
|
|
780
|
+
|
|
781
|
+
// debounce leading
|
|
782
|
+
var debouncedFunc = function debouncedFunc() {
|
|
783
|
+
var now = Date.now();
|
|
784
|
+
if (now - lastCallTime < ms) {
|
|
785
|
+
return lastCallRes;
|
|
786
|
+
}
|
|
787
|
+
lastCallTime = now;
|
|
788
|
+
lastCallRes = fn.apply(void 0, arguments);
|
|
789
|
+
return lastCallRes;
|
|
790
|
+
};
|
|
791
|
+
return debouncedFunc;
|
|
792
|
+
}
|
|
793
|
+
|
|
777
794
|
var useAsyncQueryState = function useAsyncQueryState(_ref) {
|
|
778
795
|
var queryKey = _ref.queryKey,
|
|
779
796
|
defaultValue = _ref.defaultValue;
|
|
@@ -926,17 +943,21 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
926
943
|
case 0:
|
|
927
944
|
_context.prev = 0;
|
|
928
945
|
_context.next = 3;
|
|
929
|
-
return
|
|
946
|
+
return fetchCustomerStatus(config);
|
|
930
947
|
case 3:
|
|
931
948
|
status = _context.sent;
|
|
932
949
|
setResult(status);
|
|
933
|
-
_context.next =
|
|
950
|
+
_context.next = 11;
|
|
934
951
|
break;
|
|
935
952
|
case 7:
|
|
936
953
|
_context.prev = 7;
|
|
937
954
|
_context.t0 = _context["catch"](0);
|
|
955
|
+
config._internal.logger.error({
|
|
956
|
+
msg: "Failed to fetch user status",
|
|
957
|
+
error: _context.t0
|
|
958
|
+
});
|
|
938
959
|
setError(_context.t0 instanceof Error ? _context.t0 : new Error(String(_context.t0)));
|
|
939
|
-
case
|
|
960
|
+
case 11:
|
|
940
961
|
case "end":
|
|
941
962
|
return _context.stop();
|
|
942
963
|
}
|
|
@@ -948,20 +969,62 @@ var useCustomerStatus = function useCustomerStatus() {
|
|
|
948
969
|
}();
|
|
949
970
|
if (refreshOnMount) {
|
|
950
971
|
if (state.data === undefined) {
|
|
951
|
-
startLoading();
|
|
952
972
|
void updateStatus();
|
|
953
973
|
}
|
|
954
974
|
}
|
|
955
975
|
var interval = setInterval(function () {
|
|
956
976
|
return void updateStatus();
|
|
957
977
|
}, refreshInterval);
|
|
978
|
+
|
|
979
|
+
// on close, update status
|
|
980
|
+
var unsubscribeVisibility = watchWidgetVisibleState(config, {
|
|
981
|
+
onChange: function onChange(isVisible) {
|
|
982
|
+
if (!isVisible) {
|
|
983
|
+
void updateStatus();
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
var unsubscribeAuth = watchIsAuthenticated(config, {
|
|
988
|
+
onIsAuthenticatedChange: function onIsAuthenticatedChange(isAuthenticated) {
|
|
989
|
+
if (isAuthenticated) {
|
|
990
|
+
void updateStatus();
|
|
991
|
+
} else {
|
|
992
|
+
setResult(null);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
});
|
|
958
996
|
return function () {
|
|
997
|
+
unsubscribeVisibility();
|
|
998
|
+
unsubscribeAuth();
|
|
959
999
|
clearInterval(interval);
|
|
960
1000
|
};
|
|
961
1001
|
}, [config._internal.identifier, refreshInterval, state.data, config, setError, setResult, startLoading]);
|
|
962
1002
|
return state;
|
|
963
1003
|
};
|
|
964
1004
|
|
|
1005
|
+
// ensure the debounce is global accross all react hook instances
|
|
1006
|
+
var fetchCustomerStatus = simpleLeadingDebounce(/*#__PURE__*/function () {
|
|
1007
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config) {
|
|
1008
|
+
var status;
|
|
1009
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1010
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1011
|
+
case 0:
|
|
1012
|
+
_context2.next = 2;
|
|
1013
|
+
return getCustomerStatus(config);
|
|
1014
|
+
case 2:
|
|
1015
|
+
status = _context2.sent;
|
|
1016
|
+
return _context2.abrupt("return", status);
|
|
1017
|
+
case 4:
|
|
1018
|
+
case "end":
|
|
1019
|
+
return _context2.stop();
|
|
1020
|
+
}
|
|
1021
|
+
}, _callee2);
|
|
1022
|
+
}));
|
|
1023
|
+
return function (_x) {
|
|
1024
|
+
return _ref3.apply(this, arguments);
|
|
1025
|
+
};
|
|
1026
|
+
}(), 500);
|
|
1027
|
+
|
|
965
1028
|
/**
|
|
966
1029
|
* A hook that returns a function that disconnects the ComPilot SDK.
|
|
967
1030
|
*
|
|
@@ -1198,6 +1261,80 @@ var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
|
1198
1261
|
});
|
|
1199
1262
|
};
|
|
1200
1263
|
|
|
1264
|
+
/**
|
|
1265
|
+
* A hook that returns the current identity id.
|
|
1266
|
+
*/
|
|
1267
|
+
var useIdentityId = function useIdentityId() {
|
|
1268
|
+
var config = useComPilotConfig();
|
|
1269
|
+
var _useAsyncQueryState = useAsyncQueryState({
|
|
1270
|
+
queryKey: ["useIdentityId", config._internal.identifier],
|
|
1271
|
+
defaultValue: null
|
|
1272
|
+
}),
|
|
1273
|
+
state = _useAsyncQueryState.state,
|
|
1274
|
+
setError = _useAsyncQueryState.setError,
|
|
1275
|
+
setResult = _useAsyncQueryState.setResult,
|
|
1276
|
+
setLoading = _useAsyncQueryState.setLoading;
|
|
1277
|
+
useEffect(function () {
|
|
1278
|
+
if (!config) {
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
if (isAuthenticated(config)) {
|
|
1282
|
+
getIdentityId(config).then(function (res) {
|
|
1283
|
+
return setResult(res);
|
|
1284
|
+
})["catch"](function (err) {
|
|
1285
|
+
config._internal.logger.error("Failed to fetch identity id", err);
|
|
1286
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
var unsubscribe = watchIsAuthenticated(config, {
|
|
1290
|
+
onIsAuthenticatedChange: function () {
|
|
1291
|
+
var _onIsAuthenticatedChange = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(isAuthenticated) {
|
|
1292
|
+
var res;
|
|
1293
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1294
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1295
|
+
case 0:
|
|
1296
|
+
if (isAuthenticated) {
|
|
1297
|
+
_context.next = 3;
|
|
1298
|
+
break;
|
|
1299
|
+
}
|
|
1300
|
+
setResult(null);
|
|
1301
|
+
return _context.abrupt("return");
|
|
1302
|
+
case 3:
|
|
1303
|
+
_context.prev = 3;
|
|
1304
|
+
_context.next = 6;
|
|
1305
|
+
return getIdentityId(config);
|
|
1306
|
+
case 6:
|
|
1307
|
+
res = _context.sent;
|
|
1308
|
+
setResult(res);
|
|
1309
|
+
_context.next = 14;
|
|
1310
|
+
break;
|
|
1311
|
+
case 10:
|
|
1312
|
+
_context.prev = 10;
|
|
1313
|
+
_context.t0 = _context["catch"](3);
|
|
1314
|
+
config._internal.logger.error("Failed to fetch identity id", _context.t0);
|
|
1315
|
+
setError(_context.t0 instanceof Error ? _context.t0 : new Error("Unknown error"));
|
|
1316
|
+
case 14:
|
|
1317
|
+
case "end":
|
|
1318
|
+
return _context.stop();
|
|
1319
|
+
}
|
|
1320
|
+
}, _callee, null, [[3, 10]]);
|
|
1321
|
+
}));
|
|
1322
|
+
function onIsAuthenticatedChange(_x) {
|
|
1323
|
+
return _onIsAuthenticatedChange.apply(this, arguments);
|
|
1324
|
+
}
|
|
1325
|
+
return onIsAuthenticatedChange;
|
|
1326
|
+
}(),
|
|
1327
|
+
onIsLoadingChange: function onIsLoadingChange(isLoading) {
|
|
1328
|
+
if (isLoading) {
|
|
1329
|
+
setLoading(true);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
});
|
|
1333
|
+
return unsubscribe;
|
|
1334
|
+
}, [config]);
|
|
1335
|
+
return state;
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1201
1338
|
/**
|
|
1202
1339
|
* A hook that returns the current identity wallets.
|
|
1203
1340
|
*/
|
|
@@ -1236,14 +1373,19 @@ var useIdentityWallets = function useIdentityWallets() {
|
|
|
1236
1373
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1237
1374
|
while (1) switch (_context.prev = _context.next) {
|
|
1238
1375
|
case 0:
|
|
1239
|
-
|
|
1376
|
+
_context.next = 2;
|
|
1377
|
+
return attachWalletToIdentity(config, {
|
|
1240
1378
|
wallet: wallet
|
|
1241
1379
|
});
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1380
|
+
case 2:
|
|
1381
|
+
res = _context.sent;
|
|
1382
|
+
if (res) {
|
|
1383
|
+
setQueryCacheBuster(function (prev) {
|
|
1384
|
+
return prev + 1;
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1245
1387
|
return _context.abrupt("return", res);
|
|
1246
|
-
case
|
|
1388
|
+
case 5:
|
|
1247
1389
|
case "end":
|
|
1248
1390
|
return _context.stop();
|
|
1249
1391
|
}
|
|
@@ -1295,4 +1437,4 @@ var useOpenWidget = function useOpenWidget(loginParams) {
|
|
|
1295
1437
|
return mutationState;
|
|
1296
1438
|
};
|
|
1297
1439
|
|
|
1298
|
-
export { ComPilotProvider, useAuthenticate, useComPilotConfig, useCustomerStatus, useDisconnect, useGetTxAuthDataSignature, useIdentityWallets, useOpenWidget };
|
|
1440
|
+
export { ComPilotProvider, useAuthenticate, useComPilotConfig, useCustomerStatus, useDisconnect, useGetTxAuthDataSignature, useIdentityId, useIdentityWallets, useOpenWidget };
|
|
@@ -2,6 +2,7 @@ export * from "./useAuthenticate.js";
|
|
|
2
2
|
export * from "./useCustomerStatus.js";
|
|
3
3
|
export * from "./useDisconnect.js";
|
|
4
4
|
export * from "./useGetTxAuthDataSignature.js";
|
|
5
|
+
export * from "./useIdentityId.js";
|
|
5
6
|
export * from "./useIdentityWallets.js";
|
|
6
7
|
export * from "./useOpenWidget.js";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/hooks","sources":["index.ts"],"names":[],"mappings":"AAAA,qCAAkC;AAClC,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,wCAAqC;AACrC,mCAAgC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/hooks","sources":["index.ts"],"names":[],"mappings":"AAAA,qCAAkC;AAClC,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,mCAAgC;AAChC,wCAAqC;AACrC,mCAAgC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCustomerStatus.d.ts","sourceRoot":"../../../../src/hooks","sources":["useCustomerStatus.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCustomerStatus.d.ts","sourceRoot":"../../../../src/hooks","sources":["useCustomerStatus.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAIjE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAoC;AAGnE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,iBAAiB,yCACS,uBAAuB,KAI3D,eAAe,CAAC,cAAc,GAAG,IAAI,CA4EvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIdentityId.d.ts","sourceRoot":"../../../../src/hooks","sources":["useIdentityId.tsx"],"names":[],"mappings":"AAUA;;GAEG;AACH,eAAO,MAAM,aAAa,+EAiDzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIdentityWallets.d.ts","sourceRoot":"../../../../src/hooks","sources":["useIdentityWallets.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQpD;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;+FAiCZ,UAAU;
|
|
1
|
+
{"version":3,"file":"useIdentityWallets.d.ts","sourceRoot":"../../../../src/hooks","sources":["useIdentityWallets.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQpD;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;+FAiCZ,UAAU;CAwB5B,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.3.
|
|
3
|
+
"version": "2.3.14-dev",
|
|
4
4
|
"description": "ComPilot React SDK",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "ISC",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"pino": "^9.4.0",
|
|
29
29
|
"zod": "^3.23.8",
|
|
30
|
-
"@compilot/web-sdk": "2.3.
|
|
31
|
-
"@nexeraid/identity-api-client": "2.3.
|
|
32
|
-
"@nexeraid/
|
|
33
|
-
"@nexeraid/
|
|
30
|
+
"@compilot/web-sdk": "2.3.14-dev",
|
|
31
|
+
"@nexeraid/identity-api-client": "2.3.13-dev",
|
|
32
|
+
"@nexeraid/logger": "2.3.13-dev",
|
|
33
|
+
"@nexeraid/identity-schemas": "2.3.14-dev"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=17.0.0 <20.0.0"
|