@dynamic-labs/utils 0.19.0-alpha.13 → 0.19.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 +26 -0
- package/package.json +3 -3
- package/src/index.cjs +3 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/retryableFn.cjs +53 -0
- package/src/retryableFn.d.ts +14 -0
- package/src/retryableFn.js +48 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
|
|
2
|
+
## [0.19.0-alpha.14](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.13...v0.19.0-alpha.14) (2023-10-10)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### ⚠ BREAKING CHANGES
|
|
6
|
+
|
|
7
|
+
* remove numberOfWallets (#3521)
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add embedded widget components ([#3533](https://github.com/dynamic-labs/DynamicAuth/issues/3533)) ([513cba8](https://github.com/dynamic-labs/DynamicAuth/commit/513cba8e7694544122ff9cce3aa1aea0a0c23986))
|
|
12
|
+
* add ethers extension support to wallet-connectors ([#3544](https://github.com/dynamic-labs/DynamicAuth/issues/3544)) ([3c09ba5](https://github.com/dynamic-labs/DynamicAuth/commit/3c09ba58b0f2c745df60a87b1820abbbfc1b95b7))
|
|
13
|
+
* add switch network for turnkey wallets ([#3539](https://github.com/dynamic-labs/DynamicAuth/issues/3539)) ([1bcbbb2](https://github.com/dynamic-labs/DynamicAuth/commit/1bcbbb2bd4e333d47ce4c93d4bd4b1f29a80c1f4))
|
|
14
|
+
* editable copy for switch network view ([#3561](https://github.com/dynamic-labs/DynamicAuth/issues/3561)) ([4dea2f1](https://github.com/dynamic-labs/DynamicAuth/commit/4dea2f159ee0675d5b9ba1cb412d75e5e211b3d1))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* always call connectSucess callback after successfully connecting wallet ([#3562](https://github.com/dynamic-labs/DynamicAuth/issues/3562)) ([2587ff8](https://github.com/dynamic-labs/DynamicAuth/commit/2587ff8a915f61793b15bfa1289689514344fc75))
|
|
20
|
+
* don't let user update email if they have an embedded wallet ([#3552](https://github.com/dynamic-labs/DynamicAuth/issues/3552)) ([c710cce](https://github.com/dynamic-labs/DynamicAuth/commit/c710cce22c7a54004f56c8fc68f8c4075f5f9e51))
|
|
21
|
+
* embedded widget rerender bug ([#3545](https://github.com/dynamic-labs/DynamicAuth/issues/3545)) ([27ed979](https://github.com/dynamic-labs/DynamicAuth/commit/27ed979618ac7d9e912381faebbf61ec9e9e839c))
|
|
22
|
+
* sync passkey should not throw error ([#3535](https://github.com/dynamic-labs/DynamicAuth/issues/3535)) ([0336ba6](https://github.com/dynamic-labs/DynamicAuth/commit/0336ba65bf1cc4394e4f005f273baea26326784a))
|
|
23
|
+
* wrap eth wallet connector rpc calls in retry function ([#3497](https://github.com/dynamic-labs/DynamicAuth/issues/3497)) ([7800b45](https://github.com/dynamic-labs/DynamicAuth/commit/7800b45dc93f20731ee643e89e84d57765387778))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
* remove numberOfWallets ([#3521](https://github.com/dynamic-labs/DynamicAuth/issues/3521)) ([0174297](https://github.com/dynamic-labs/DynamicAuth/commit/017429745d08b7b1edc23bc4da43bc01b4ef1cd4))
|
|
27
|
+
|
|
2
28
|
## [0.19.0-alpha.13](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.12...v0.19.0-alpha.13) (2023-10-04)
|
|
3
29
|
|
|
4
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/utils",
|
|
3
|
-
"version": "0.19.0-alpha.
|
|
3
|
+
"version": "0.19.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.5.3"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@dynamic-labs/logger": "0.19.0-alpha.
|
|
33
|
-
"@dynamic-labs/types": "0.19.0-alpha.
|
|
32
|
+
"@dynamic-labs/logger": "0.19.0-alpha.14",
|
|
33
|
+
"@dynamic-labs/types": "0.19.0-alpha.14"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var sleep = require('./sleep/sleep.cjs');
|
|
|
31
31
|
var getOrMapViemChain = require('./getOrMapViemChain.cjs');
|
|
32
32
|
var bigIntToHex = require('./bigIntToHex/bigIntToHex.cjs');
|
|
33
33
|
var isBigInt = require('./isBigInt/isBigInt.cjs');
|
|
34
|
+
var retryableFn = require('./retryableFn.cjs');
|
|
34
35
|
|
|
35
36
|
|
|
36
37
|
|
|
@@ -76,3 +77,5 @@ exports.getOrMapViemChain = getOrMapViemChain.getOrMapViemChain;
|
|
|
76
77
|
exports.mapChain = getOrMapViemChain.mapChain;
|
|
77
78
|
exports.bigIntToHex = bigIntToHex.bigIntToHex;
|
|
78
79
|
exports.isBigInt = isBigInt.isBigInt;
|
|
80
|
+
exports.FALLBACK_UNDEFINED = retryableFn.FALLBACK_UNDEFINED;
|
|
81
|
+
exports.retryableFn = retryableFn.retryableFn;
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -27,3 +27,4 @@ export { sleep } from './sleep/sleep.js';
|
|
|
27
27
|
export { getChain, getOrMapViemChain, mapChain } from './getOrMapViemChain.js';
|
|
28
28
|
export { bigIntToHex } from './bigIntToHex/bigIntToHex.js';
|
|
29
29
|
export { isBigInt } from './isBigInt/isBigInt.js';
|
|
30
|
+
export { FALLBACK_UNDEFINED, retryableFn } from './retryableFn.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
6
|
+
|
|
7
|
+
const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
|
|
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;
|
|
10
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
reject(new Error('Timeout'));
|
|
13
|
+
}, timeoutMs);
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
const result = yield Promise.race([fn(), timeoutPromise]);
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
if (currentRetry >= maxRetries) {
|
|
21
|
+
if (fallbackValue instanceof Error) {
|
|
22
|
+
throw fallbackValue;
|
|
23
|
+
}
|
|
24
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return fallbackValue;
|
|
28
|
+
}
|
|
29
|
+
const isTimeout = err.message === 'Timeout';
|
|
30
|
+
const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
|
|
31
|
+
(retryStrategy === 'timeout-only' && isTimeout) ||
|
|
32
|
+
(retryStrategy === 'rejection-only' && !isTimeout);
|
|
33
|
+
if (!shouldRetry) {
|
|
34
|
+
if (fallbackValue instanceof Error) {
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return fallbackValue;
|
|
41
|
+
}
|
|
42
|
+
return retryableFn(fn, {
|
|
43
|
+
currentRetry: currentRetry + 1,
|
|
44
|
+
fallbackValue,
|
|
45
|
+
maxRetries,
|
|
46
|
+
retryStrategy,
|
|
47
|
+
timeoutMs,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
exports.FALLBACK_UNDEFINED = FALLBACK_UNDEFINED;
|
|
53
|
+
exports.retryableFn = retryableFn;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const FALLBACK_UNDEFINED = "FALLBACK_UNDEFINED";
|
|
2
|
+
export type RetryableFnOptions<T> = {
|
|
3
|
+
/** Maximum number of retry attempts before returning fallbackValue */
|
|
4
|
+
maxRetries?: number;
|
|
5
|
+
/** Internal only. Do not use */
|
|
6
|
+
currentRetry?: number;
|
|
7
|
+
/** Timeout in ms to wait before executing retryStrategy */
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
/** The value to fallback to when function rejects or times out */
|
|
10
|
+
fallbackValue?: T | Error | typeof FALLBACK_UNDEFINED;
|
|
11
|
+
/** Configure whether the fn should be retried only on timeout, only on rejection, or both */
|
|
12
|
+
retryStrategy?: 'timeout-only' | 'rejection-only' | 'timeout-and-rejection';
|
|
13
|
+
};
|
|
14
|
+
export declare const retryableFn: <T>(fn: () => Promise<T>, options?: RetryableFnOptions<T>) => Promise<T>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
2
|
+
|
|
3
|
+
const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
|
|
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;
|
|
6
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
7
|
+
setTimeout(() => {
|
|
8
|
+
reject(new Error('Timeout'));
|
|
9
|
+
}, timeoutMs);
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
const result = yield Promise.race([fn(), timeoutPromise]);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
if (currentRetry >= maxRetries) {
|
|
17
|
+
if (fallbackValue instanceof Error) {
|
|
18
|
+
throw fallbackValue;
|
|
19
|
+
}
|
|
20
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return fallbackValue;
|
|
24
|
+
}
|
|
25
|
+
const isTimeout = err.message === 'Timeout';
|
|
26
|
+
const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
|
|
27
|
+
(retryStrategy === 'timeout-only' && isTimeout) ||
|
|
28
|
+
(retryStrategy === 'rejection-only' && !isTimeout);
|
|
29
|
+
if (!shouldRetry) {
|
|
30
|
+
if (fallbackValue instanceof Error) {
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return fallbackValue;
|
|
37
|
+
}
|
|
38
|
+
return retryableFn(fn, {
|
|
39
|
+
currentRetry: currentRetry + 1,
|
|
40
|
+
fallbackValue,
|
|
41
|
+
maxRetries,
|
|
42
|
+
retryStrategy,
|
|
43
|
+
timeoutMs,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export { FALLBACK_UNDEFINED, retryableFn };
|