@dynamic-labs/utils 1.1.0-alpha.13 → 1.1.0-alpha.15
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 +2 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/parseEvmNetworks.cjs +1 -0
- package/src/parseEvmNetworks.js +1 -0
- package/src/retryableFn.cjs +16 -1
- package/src/retryableFn.d.ts +3 -0
- package/src/retryableFn.js +16 -1
- package/src/uniq/index.d.ts +1 -0
- package/src/uniq/uniq.cjs +32 -0
- package/src/uniq/uniq.d.ts +17 -0
- package/src/uniq/uniq.js +28 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
|
|
2
|
+
## [1.1.0-alpha.15](https://github.com/dynamic-labs/DynamicAuth/compare/v1.1.0-alpha.14...v1.1.0-alpha.15) (2024-01-28)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add wallet group override to wallet book ([#4488](https://github.com/dynamic-labs/DynamicAuth/issues/4488)) ([cb19ad3](https://github.com/dynamic-labs/DynamicAuth/commit/cb19ad3ea82de488752ceceeaf0e1458a388df6e))
|
|
8
|
+
* enable solana embedded wallets ([#4457](https://github.com/dynamic-labs/DynamicAuth/issues/4457)) ([b0c47f4](https://github.com/dynamic-labs/DynamicAuth/commit/b0c47f4475baa12f52076da46ef993c13bd2c243))
|
|
9
|
+
* group ArgentX wallets ([#4495](https://github.com/dynamic-labs/DynamicAuth/issues/4495)) ([b10d79a](https://github.com/dynamic-labs/DynamicAuth/commit/b10d79a668efecedca37ddb358e6adf95319650d))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* add support for newest backpack extension ([#4468](https://github.com/dynamic-labs/DynamicAuth/issues/4468)) ([a219f32](https://github.com/dynamic-labs/DynamicAuth/commit/a219f325be672599e50b07f6751234a7fc98286e))
|
|
15
|
+
* bump timeout for slower connections ([#4475](https://github.com/dynamic-labs/DynamicAuth/issues/4475)) ([7a07ff5](https://github.com/dynamic-labs/DynamicAuth/commit/7a07ff589eaaf3b28a94d277df3eedabbca60702))
|
|
16
|
+
* change out getWalletBookWallet for findWalletBookWallet to avoid throwing during lookup ([#4477](https://github.com/dynamic-labs/DynamicAuth/issues/4477)) ([4648040](https://github.com/dynamic-labs/DynamicAuth/commit/4648040c166e73dd2c31b0e27897713339436c2f))
|
|
17
|
+
* connect to wallet with wallet connect even if network is not supported ([#4465](https://github.com/dynamic-labs/DynamicAuth/issues/4465)) ([9dbca3e](https://github.com/dynamic-labs/DynamicAuth/commit/9dbca3eb4d4990ee4be642677c1604170b425dc3))
|
|
18
|
+
* pass id to wagmi chain override ([#4512](https://github.com/dynamic-labs/DynamicAuth/issues/4512)) ([2bf2f04](https://github.com/dynamic-labs/DynamicAuth/commit/2bf2f0487f5b1be936dd279107c11fe5d2b42666))
|
|
19
|
+
* switching wallet in extension caused connected flag to be false temporarily ([#4454](https://github.com/dynamic-labs/DynamicAuth/issues/4454)) ([3650f6e](https://github.com/dynamic-labs/DynamicAuth/commit/3650f6ec471a7c779f4d304ab94c9350dd55055b))
|
|
20
|
+
|
|
21
|
+
## [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)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
### Features
|
|
25
|
+
|
|
26
|
+
* add wallet-book retryable ([#4462](https://github.com/dynamic-labs/DynamicAuth/issues/4462)) ([513b1a6](https://github.com/dynamic-labs/DynamicAuth/commit/513b1a67d6c49624398ad4b0cdca4f5618c9583f))
|
|
27
|
+
|
|
2
28
|
## [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
29
|
|
|
4
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/utils",
|
|
3
|
-
"version": "1.1.0-alpha.
|
|
3
|
+
"version": "1.1.0-alpha.15",
|
|
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.
|
|
33
|
-
"@dynamic-labs/types": "1.1.0-alpha.
|
|
32
|
+
"@dynamic-labs/logger": "1.1.0-alpha.15",
|
|
33
|
+
"@dynamic-labs/types": "1.1.0-alpha.15"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ var retryableFn = require('./retryableFn.cjs');
|
|
|
36
36
|
var wrapMethodWithCallback = require('./wrapMethodWithCallback/wrapMethodWithCallback.cjs');
|
|
37
37
|
var DeferredPromise = require('./DeferredPromise/DeferredPromise.cjs');
|
|
38
38
|
var handleMobileWalletRedirect = require('./handleMobileWalletRedirect/handleMobileWalletRedirect.cjs');
|
|
39
|
+
var uniq = require('./uniq/uniq.cjs');
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
|
|
@@ -87,3 +88,4 @@ exports.retryableFn = retryableFn.retryableFn;
|
|
|
87
88
|
exports.wrapMethodWithCallback = wrapMethodWithCallback.wrapMethodWithCallback;
|
|
88
89
|
exports.DeferredPromise = DeferredPromise.DeferredPromise;
|
|
89
90
|
exports.handleMobileWalletRedirect = handleMobileWalletRedirect.handleMobileWalletRedirect;
|
|
91
|
+
exports.uniq = uniq.uniq;
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -32,3 +32,4 @@ export { FALLBACK_UNDEFINED, retryableFn } from './retryableFn.js';
|
|
|
32
32
|
export { wrapMethodWithCallback } from './wrapMethodWithCallback/wrapMethodWithCallback.js';
|
|
33
33
|
export { DeferredPromise } from './DeferredPromise/DeferredPromise.js';
|
|
34
34
|
export { handleMobileWalletRedirect } from './handleMobileWalletRedirect/handleMobileWalletRedirect.js';
|
|
35
|
+
export { uniq } from './uniq/uniq.js';
|
package/src/parseEvmNetworks.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const parseEvmNetworks = (networks) => {
|
|
|
8
8
|
const clone = networks.slice();
|
|
9
9
|
return clone.map((network) => {
|
|
10
10
|
network.chainId = parseChainId.parseChainId(network.chainId);
|
|
11
|
+
network.networkId = parseChainId.parseChainId(network.networkId);
|
|
11
12
|
return network;
|
|
12
13
|
});
|
|
13
14
|
};
|
package/src/parseEvmNetworks.js
CHANGED
package/src/retryableFn.cjs
CHANGED
|
@@ -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,
|
package/src/retryableFn.d.ts
CHANGED
|
@@ -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>;
|
package/src/retryableFn.js
CHANGED
|
@@ -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,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { uniq } from './uniq';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Removes duplicate elements from an array.
|
|
7
|
+
*
|
|
8
|
+
* @param {T[]} array - The array to filter for unique elements.
|
|
9
|
+
* @template T - The type of elements in the array.
|
|
10
|
+
* @returns {T[]} A new array containing only the unique elements of the given array.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // returns [1, 2, 3, 4, 5]
|
|
14
|
+
* uniq([1, 2, 2, 3, 4, 4, 5]);
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // returns ['apple', 'banana', 'orange']
|
|
18
|
+
* uniq(['apple', 'banana', 'apple', 'orange']);
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
const uniq = (array) => {
|
|
22
|
+
const seen = new Set();
|
|
23
|
+
return array.filter((item) => {
|
|
24
|
+
if (seen.has(item)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
seen.add(item);
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.uniq = uniq;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicate elements from an array.
|
|
3
|
+
*
|
|
4
|
+
* @param {T[]} array - The array to filter for unique elements.
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @returns {T[]} A new array containing only the unique elements of the given array.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // returns [1, 2, 3, 4, 5]
|
|
10
|
+
* uniq([1, 2, 2, 3, 4, 4, 5]);
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // returns ['apple', 'banana', 'orange']
|
|
14
|
+
* uniq(['apple', 'banana', 'apple', 'orange']);
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare const uniq: <T>(array: T[]) => T[];
|
package/src/uniq/uniq.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicate elements from an array.
|
|
3
|
+
*
|
|
4
|
+
* @param {T[]} array - The array to filter for unique elements.
|
|
5
|
+
* @template T - The type of elements in the array.
|
|
6
|
+
* @returns {T[]} A new array containing only the unique elements of the given array.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // returns [1, 2, 3, 4, 5]
|
|
10
|
+
* uniq([1, 2, 2, 3, 4, 4, 5]);
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // returns ['apple', 'banana', 'orange']
|
|
14
|
+
* uniq(['apple', 'banana', 'apple', 'orange']);
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
const uniq = (array) => {
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
return array.filter((item) => {
|
|
20
|
+
if (seen.has(item)) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
seen.add(item);
|
|
24
|
+
return true;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { uniq };
|