@dynamic-labs/utils 1.1.0-alpha.13 → 1.1.0-alpha.14

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/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ ## [1.1.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.13...v1.1.0-alpha.14) (2024-01-23)
3
+
4
+
5
+ ### Features
6
+
7
+ * add wallet-book retryable ([#4462](https://github.com/dynamic-labs/DynamicAuth/issues/4462)) ([513b1a6](https://github.com/dynamic-labs/DynamicAuth/commit/513b1a67d6c49624398ad4b0cdca4f5618c9583f))
8
+
2
9
  ## [1.1.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.12...v1.1.0-alpha.13) (2024-01-23)
3
10
 
4
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/utils",
3
- "version": "1.1.0-alpha.13",
3
+ "version": "1.1.0-alpha.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -29,7 +29,7 @@
29
29
  "viem": "^1.19.13 || ^2.2.0"
30
30
  },
31
31
  "dependencies": {
32
- "@dynamic-labs/logger": "1.1.0-alpha.13",
33
- "@dynamic-labs/types": "1.1.0-alpha.13"
32
+ "@dynamic-labs/logger": "1.1.0-alpha.14",
33
+ "@dynamic-labs/types": "1.1.0-alpha.14"
34
34
  }
35
35
  }
@@ -6,7 +6,14 @@ var _tslib = require('../_virtual/_tslib.cjs');
6
6
 
7
7
  const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
8
8
  const retryableFn = (fn, options = {}) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
9
- const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', } = options;
9
+ const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', logger, } = options;
10
+ logger === null || logger === void 0 ? void 0 : logger.debug('Configured retryableFn with options: ', {
11
+ currentRetry,
12
+ fallbackValue,
13
+ maxRetries,
14
+ retryStrategy,
15
+ timeoutMs,
16
+ });
10
17
  const timeoutPromise = new Promise((_, reject) => {
11
18
  setTimeout(() => {
12
19
  reject(new Error('Timeout'));
@@ -17,7 +24,9 @@ const retryableFn = (fn, options = {}) => _tslib.__awaiter(void 0, void 0, void
17
24
  return result;
18
25
  }
19
26
  catch (err) {
27
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn caught error: ', err);
20
28
  if (currentRetry >= maxRetries) {
29
+ logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning/throwing fallback value', err, fallbackValue);
21
30
  if (fallbackValue instanceof Error) {
22
31
  throw fallbackValue;
23
32
  }
@@ -30,18 +39,24 @@ const retryableFn = (fn, options = {}) => _tslib.__awaiter(void 0, void 0, void
30
39
  const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
31
40
  (retryStrategy === 'timeout-only' && isTimeout) ||
32
41
  (retryStrategy === 'rejection-only' && !isTimeout);
42
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn shouldRetry: ', shouldRetry);
33
43
  if (!shouldRetry) {
34
44
  if (fallbackValue instanceof Error) {
45
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn throwing fallbackValue error: ', fallbackValue);
35
46
  throw err;
36
47
  }
37
48
  else if (fallbackValue === FALLBACK_UNDEFINED) {
49
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning undefined');
38
50
  return undefined;
39
51
  }
52
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning fallbackValue: ', fallbackValue);
53
+ logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning fallback value', err);
40
54
  return fallbackValue;
41
55
  }
42
56
  return retryableFn(fn, {
43
57
  currentRetry: currentRetry + 1,
44
58
  fallbackValue,
59
+ logger,
45
60
  maxRetries,
46
61
  retryStrategy,
47
62
  timeoutMs,
@@ -1,3 +1,4 @@
1
+ import { Logger } from '@dynamic-labs/logger';
1
2
  export declare const FALLBACK_UNDEFINED = "FALLBACK_UNDEFINED";
2
3
  export type RetryableFnOptions<T> = {
3
4
  /** Maximum number of retry attempts before returning fallbackValue */
@@ -10,5 +11,7 @@ export type RetryableFnOptions<T> = {
10
11
  fallbackValue?: T | Error | typeof FALLBACK_UNDEFINED;
11
12
  /** Configure whether the fn should be retried only on timeout, only on rejection, or both */
12
13
  retryStrategy?: 'timeout-only' | 'rejection-only' | 'timeout-and-rejection';
14
+ /** Set the logger to be used */
15
+ logger?: Logger | typeof console;
13
16
  };
14
17
  export declare const retryableFn: <T>(fn: () => Promise<T>, options?: RetryableFnOptions<T>) => Promise<T>;
@@ -2,7 +2,14 @@ import { __awaiter } from '../_virtual/_tslib.js';
2
2
 
3
3
  const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
4
4
  const retryableFn = (fn, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
5
- const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', } = options;
5
+ const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', logger, } = options;
6
+ logger === null || logger === void 0 ? void 0 : logger.debug('Configured retryableFn with options: ', {
7
+ currentRetry,
8
+ fallbackValue,
9
+ maxRetries,
10
+ retryStrategy,
11
+ timeoutMs,
12
+ });
6
13
  const timeoutPromise = new Promise((_, reject) => {
7
14
  setTimeout(() => {
8
15
  reject(new Error('Timeout'));
@@ -13,7 +20,9 @@ const retryableFn = (fn, options = {}) => __awaiter(void 0, void 0, void 0, func
13
20
  return result;
14
21
  }
15
22
  catch (err) {
23
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn caught error: ', err);
16
24
  if (currentRetry >= maxRetries) {
25
+ logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning/throwing fallback value', err, fallbackValue);
17
26
  if (fallbackValue instanceof Error) {
18
27
  throw fallbackValue;
19
28
  }
@@ -26,18 +35,24 @@ const retryableFn = (fn, options = {}) => __awaiter(void 0, void 0, void 0, func
26
35
  const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
27
36
  (retryStrategy === 'timeout-only' && isTimeout) ||
28
37
  (retryStrategy === 'rejection-only' && !isTimeout);
38
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn shouldRetry: ', shouldRetry);
29
39
  if (!shouldRetry) {
30
40
  if (fallbackValue instanceof Error) {
41
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn throwing fallbackValue error: ', fallbackValue);
31
42
  throw err;
32
43
  }
33
44
  else if (fallbackValue === FALLBACK_UNDEFINED) {
45
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning undefined');
34
46
  return undefined;
35
47
  }
48
+ logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning fallbackValue: ', fallbackValue);
49
+ logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning fallback value', err);
36
50
  return fallbackValue;
37
51
  }
38
52
  return retryableFn(fn, {
39
53
  currentRetry: currentRetry + 1,
40
54
  fallbackValue,
55
+ logger,
41
56
  maxRetries,
42
57
  retryStrategy,
43
58
  timeoutMs,