wallaby-cash 1.7.5 → 1.7.7

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/index.cjs.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
5
5
  const ethCryptoJs = require('eth-crypto-js');
6
6
  const axios = require('axios');
7
7
  const cryptoJs = require('crypto-js');
8
+ const jwtDecode = require('jwt-decode');
8
9
  const uuid = require('uuid');
9
10
 
10
11
  const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
@@ -4490,6 +4491,7 @@ var defaultEnvironment = (_a = browser$1$1.env.NODE_ENV) !== null && _a !== void
4490
4491
  * Please pass the network value in the WallabyConfigOptions object to override it for production-mainnet.
4491
4492
  */
4492
4493
  var defaultNetwork = 'testnet';
4494
+ var isTest = browser$1$1.env.NODE_ENV === 'test';
4493
4495
 
4494
4496
  var StorageService = /** @class */ (function () {
4495
4497
  function StorageService(_a) {
@@ -4941,6 +4943,32 @@ function objectToQueryParams(obj) {
4941
4943
  return params.toString();
4942
4944
  }
4943
4945
 
4946
+ /**
4947
+ * Checks if a given JWT has expired.
4948
+ *
4949
+ * @param jwt - The JWT string to check. If null, the function will return true.
4950
+ * @returns `true` if the JWT has expired or is null, otherwise `false`.
4951
+ */
4952
+ function jwtHasExpired(jwt) {
4953
+ if (!jwt) {
4954
+ return true;
4955
+ }
4956
+ return millisecondsToJWTTimeout(jwt) <= 0;
4957
+ }
4958
+ /**
4959
+ * Calculates the remaining time in milliseconds until a given JWT expires.
4960
+ *
4961
+ * @param jwt - The JWT string to decode and check.
4962
+ * @returns The number of milliseconds until the JWT expires. If the JWT has already expired, the returned value will be less than or equal to 0.
4963
+ */
4964
+ function millisecondsToJWTTimeout(jwt) {
4965
+ var jwtDecoded = jwtDecode.jwtDecode(jwt);
4966
+ var jwtExpirationTimeSeconds = jwtDecoded.exp;
4967
+ var jwtExpirationTimeMilliseconds = (jwtExpirationTimeSeconds !== null && jwtExpirationTimeSeconds !== void 0 ? jwtExpirationTimeSeconds : 0) * 1000;
4968
+ var timeNowMilliseconds = Date.now();
4969
+ return jwtExpirationTimeMilliseconds - timeNowMilliseconds;
4970
+ }
4971
+
4944
4972
  var Base = /** @class */ (function () {
4945
4973
  function Base(config) {
4946
4974
  var _a;
@@ -5125,6 +5153,9 @@ var Base = /** @class */ (function () {
5125
5153
  return __generator(this, function (_f) {
5126
5154
  switch (_f.label) {
5127
5155
  case 0:
5156
+ if (!isTest && jwtHasExpired(this.clientAuthToken)) {
5157
+ throw new Error('Auth token has expired - blocking API call.');
5158
+ }
5128
5159
  _d = {
5129
5160
  'Content-Type': 'application/json',
5130
5161
  'x-api-key': this.settings.apiKey