@dynamic-labs/utils 0.0.0-exp20240808.0
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 +3746 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/_virtual/_tslib.cjs +51 -0
- package/_virtual/_tslib.js +45 -0
- package/package.json +37 -0
- package/src/CancellablePromise/CancellablePromise.cjs +136 -0
- package/src/CancellablePromise/CancellablePromise.d.ts +54 -0
- package/src/CancellablePromise/CancellablePromise.js +132 -0
- package/src/CancellablePromise/index.d.ts +1 -0
- package/src/DeferredPromise/DeferredPromise.cjs +22 -0
- package/src/DeferredPromise/DeferredPromise.d.ts +13 -0
- package/src/DeferredPromise/DeferredPromise.js +18 -0
- package/src/DeferredPromise/index.d.ts +1 -0
- package/src/bufferPolyfill.cjs +15 -0
- package/src/bufferPolyfill.d.ts +1 -0
- package/src/bufferPolyfill.js +13 -0
- package/src/bufferToBase64.cjs +15 -0
- package/src/bufferToBase64.d.ts +2 -0
- package/src/bufferToBase64.js +11 -0
- package/src/ceil/ceil.cjs +11 -0
- package/src/ceil/ceil.d.ts +1 -0
- package/src/ceil/ceil.js +7 -0
- package/src/ceil/index.d.ts +1 -0
- package/src/eip6963/eip6963Provider.cjs +40 -0
- package/src/eip6963/eip6963Provider.d.ts +34 -0
- package/src/eip6963/eip6963Provider.js +35 -0
- package/src/eip6963/index.d.ts +1 -0
- package/src/errors/AccessBlockedError.cjs +11 -0
- package/src/errors/AccessBlockedError.d.ts +3 -0
- package/src/errors/AccessBlockedError.js +7 -0
- package/src/errors/AccountExistsError.cjs +16 -0
- package/src/errors/AccountExistsError.d.ts +14 -0
- package/src/errors/AccountExistsError.js +12 -0
- package/src/errors/ChainalysisError.cjs +15 -0
- package/src/errors/ChainalysisError.d.ts +5 -0
- package/src/errors/ChainalysisError.js +11 -0
- package/src/errors/CookieInvalidError.cjs +14 -0
- package/src/errors/CookieInvalidError.d.ts +4 -0
- package/src/errors/CookieInvalidError.js +10 -0
- package/src/errors/CustomError.cjs +24 -0
- package/src/errors/CustomError.d.ts +11 -0
- package/src/errors/CustomError.js +20 -0
- package/src/errors/CustomFieldNotUniqueError.cjs +14 -0
- package/src/errors/CustomFieldNotUniqueError.d.ts +4 -0
- package/src/errors/CustomFieldNotUniqueError.js +10 -0
- package/src/errors/DynamicError.cjs +11 -0
- package/src/errors/DynamicError.d.ts +3 -0
- package/src/errors/DynamicError.js +7 -0
- package/src/errors/EmailAlreadyExistsError.cjs +14 -0
- package/src/errors/EmailAlreadyExistsError.d.ts +4 -0
- package/src/errors/EmailAlreadyExistsError.js +10 -0
- package/src/errors/EmailProviderError.cjs +14 -0
- package/src/errors/EmailProviderError.d.ts +4 -0
- package/src/errors/EmailProviderError.js +10 -0
- package/src/errors/EmailVerificationError.cjs +14 -0
- package/src/errors/EmailVerificationError.d.ts +4 -0
- package/src/errors/EmailVerificationError.js +10 -0
- package/src/errors/EmbeddedWalletException.cjs +14 -0
- package/src/errors/EmbeddedWalletException.d.ts +4 -0
- package/src/errors/EmbeddedWalletException.js +10 -0
- package/src/errors/ExternalAuthError.cjs +14 -0
- package/src/errors/ExternalAuthError.d.ts +4 -0
- package/src/errors/ExternalAuthError.js +10 -0
- package/src/errors/GateBlockedError.cjs +15 -0
- package/src/errors/GateBlockedError.d.ts +5 -0
- package/src/errors/GateBlockedError.js +11 -0
- package/src/errors/InsufficientFundsError.cjs +25 -0
- package/src/errors/InsufficientFundsError.d.ts +9 -0
- package/src/errors/InsufficientFundsError.js +21 -0
- package/src/errors/InvalidPhoneNumberError.cjs +14 -0
- package/src/errors/InvalidPhoneNumberError.d.ts +4 -0
- package/src/errors/InvalidPhoneNumberError.js +10 -0
- package/src/errors/MergeAccountsConfirmationError.cjs +16 -0
- package/src/errors/MergeAccountsConfirmationError.d.ts +12 -0
- package/src/errors/MergeAccountsConfirmationError.js +12 -0
- package/src/errors/MfaInvalidOtpError.cjs +14 -0
- package/src/errors/MfaInvalidOtpError.d.ts +4 -0
- package/src/errors/MfaInvalidOtpError.js +10 -0
- package/src/errors/MissingEnvironmentIdError.cjs +14 -0
- package/src/errors/MissingEnvironmentIdError.d.ts +4 -0
- package/src/errors/MissingEnvironmentIdError.js +10 -0
- package/src/errors/MissingPublicAddressError.cjs +14 -0
- package/src/errors/MissingPublicAddressError.d.ts +4 -0
- package/src/errors/MissingPublicAddressError.js +10 -0
- package/src/errors/NoAccessError.cjs +19 -0
- package/src/errors/NoAccessError.d.ts +15 -0
- package/src/errors/NoAccessError.js +15 -0
- package/src/errors/NotSupportedError.cjs +11 -0
- package/src/errors/NotSupportedError.d.ts +3 -0
- package/src/errors/NotSupportedError.js +7 -0
- package/src/errors/PasskeyError.d.ts +8 -0
- package/src/errors/SmsVerificationError.cjs +11 -0
- package/src/errors/SmsVerificationError.d.ts +3 -0
- package/src/errors/SmsVerificationError.js +7 -0
- package/src/errors/SocialAccountAlreadyExistsError.cjs +14 -0
- package/src/errors/SocialAccountAlreadyExistsError.d.ts +4 -0
- package/src/errors/SocialAccountAlreadyExistsError.js +10 -0
- package/src/errors/TooManyEmailVerificationsError.cjs +14 -0
- package/src/errors/TooManyEmailVerificationsError.d.ts +4 -0
- package/src/errors/TooManyEmailVerificationsError.js +10 -0
- package/src/errors/TransactionGasCannotBeSponsoredError.cjs +25 -0
- package/src/errors/TransactionGasCannotBeSponsoredError.d.ts +9 -0
- package/src/errors/TransactionGasCannotBeSponsoredError.js +21 -0
- package/src/errors/UserHasAccountWithEmailError.cjs +15 -0
- package/src/errors/UserHasAccountWithEmailError.d.ts +5 -0
- package/src/errors/UserHasAccountWithEmailError.js +11 -0
- package/src/errors/UserRejectedTransactionError.cjs +14 -0
- package/src/errors/UserRejectedTransactionError.d.ts +4 -0
- package/src/errors/UserRejectedTransactionError.js +10 -0
- package/src/errors/UsernameAlreadyExistsError.cjs +14 -0
- package/src/errors/UsernameAlreadyExistsError.d.ts +4 -0
- package/src/errors/UsernameAlreadyExistsError.js +10 -0
- package/src/errors/VerificationDataCollectionError.cjs +15 -0
- package/src/errors/VerificationDataCollectionError.d.ts +5 -0
- package/src/errors/VerificationDataCollectionError.js +11 -0
- package/src/errors/WalletAddressMismatchError.cjs +17 -0
- package/src/errors/WalletAddressMismatchError.d.ts +11 -0
- package/src/errors/WalletAddressMismatchError.js +13 -0
- package/src/errors/WalletNotDeployedError.cjs +14 -0
- package/src/errors/WalletNotDeployedError.d.ts +4 -0
- package/src/errors/WalletNotDeployedError.js +10 -0
- package/src/errors/WalletUsedError.cjs +14 -0
- package/src/errors/WalletUsedError.d.ts +4 -0
- package/src/errors/WalletUsedError.js +10 -0
- package/src/errors/index.d.ts +33 -0
- package/src/formatNumberText/formatNumberText.cjs +20 -0
- package/src/formatNumberText/formatNumberText.d.ts +5 -0
- package/src/formatNumberText/formatNumberText.js +16 -0
- package/src/formatNumberText/index.d.ts +1 -0
- package/src/get/get.cjs +24 -0
- package/src/get/get.d.ts +7 -0
- package/src/get/get.js +20 -0
- package/src/get/index.d.ts +1 -0
- package/src/getProvidersFromWindow.cjs +39 -0
- package/src/getProvidersFromWindow.d.ts +7 -0
- package/src/getProvidersFromWindow.js +35 -0
- package/src/getTLD/getTLD.cjs +12 -0
- package/src/getTLD/getTLD.d.ts +1 -0
- package/src/getTLD/getTLD.js +8 -0
- package/src/getTLD/index.d.ts +1 -0
- package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.cjs +20 -0
- package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.d.ts +4 -0
- package/src/handleMobileWalletRedirect/handleMobileWalletRedirect.js +16 -0
- package/src/handleMobileWalletRedirect/index.d.ts +1 -0
- package/src/hexToString/hexToString.cjs +32 -0
- package/src/hexToString/hexToString.d.ts +12 -0
- package/src/hexToString/hexToString.js +28 -0
- package/src/hexToString/index.d.ts +1 -0
- package/src/index.cjs +151 -0
- package/src/index.d.ts +32 -0
- package/src/index.js +66 -0
- package/src/isFunction/index.d.ts +1 -0
- package/src/isFunction/isFunction.cjs +9 -0
- package/src/isFunction/isFunction.d.ts +1 -0
- package/src/isFunction/isFunction.js +5 -0
- package/src/isHex/index.d.ts +1 -0
- package/src/isHex/isHex.cjs +20 -0
- package/src/isHex/isHex.d.ts +6 -0
- package/src/isHex/isHex.js +16 -0
- package/src/isLedgerAddressViaVerifiedCredentials.cjs +13 -0
- package/src/isLedgerAddressViaVerifiedCredentials.d.ts +2 -0
- package/src/isLedgerAddressViaVerifiedCredentials.js +9 -0
- package/src/isMobile.cjs +146 -0
- package/src/isMobile.d.ts +18 -0
- package/src/isMobile.js +133 -0
- package/src/last.cjs +22 -0
- package/src/last.d.ts +15 -0
- package/src/last.js +18 -0
- package/src/localStorageAsync.cjs +38 -0
- package/src/localStorageAsync.d.ts +3 -0
- package/src/localStorageAsync.js +32 -0
- package/src/logger/index.d.ts +1 -0
- package/src/logger/logger.cjs +10 -0
- package/src/logger/logger.d.ts +2 -0
- package/src/logger/logger.js +6 -0
- package/src/nativeMobileOauthStateParam.cjs +13 -0
- package/src/nativeMobileOauthStateParam.d.ts +14 -0
- package/src/nativeMobileOauthStateParam.js +9 -0
- package/src/parseChainId.cjs +8 -0
- package/src/parseChainId.d.ts +1 -0
- package/src/parseChainId.js +4 -0
- package/src/parseEvmNetworks.cjs +17 -0
- package/src/parseEvmNetworks.d.ts +2 -0
- package/src/parseEvmNetworks.js +13 -0
- package/src/pipe/index.d.ts +1 -0
- package/src/pipe/pipe.cjs +40 -0
- package/src/pipe/pipe.d.ts +27 -0
- package/src/pipe/pipe.js +36 -0
- package/src/retryableFn.cjs +73 -0
- package/src/retryableFn.d.ts +19 -0
- package/src/retryableFn.js +68 -0
- package/src/runSafe/index.d.ts +1 -0
- package/src/runSafe/runSafe.cjs +25 -0
- package/src/runSafe/runSafe.d.ts +8 -0
- package/src/runSafe/runSafe.js +21 -0
- package/src/services/FetchService/FetchService.cjs +29 -0
- package/src/services/FetchService/FetchService.d.ts +10 -0
- package/src/services/FetchService/FetchService.js +25 -0
- package/src/services/FetchService/index.d.ts +2 -0
- package/src/services/FetchService/types.d.ts +3 -0
- package/src/services/Oauth2Service/Oauth2Service.cjs +38 -0
- package/src/services/Oauth2Service/Oauth2Service.d.ts +34 -0
- package/src/services/Oauth2Service/Oauth2Service.js +34 -0
- package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.cjs +192 -0
- package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.d.ts +2 -0
- package/src/services/Oauth2Service/createWindowOauth2Service/createWindowOauth2Service.js +188 -0
- package/src/services/Oauth2Service/createWindowOauth2Service/index.d.ts +1 -0
- package/src/services/Oauth2Service/index.d.ts +2 -0
- package/src/services/PlatformService/PlatformService.cjs +40 -0
- package/src/services/PlatformService/PlatformService.d.ts +11 -0
- package/src/services/PlatformService/PlatformService.js +36 -0
- package/src/services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.cjs +30 -0
- package/src/services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.d.ts +2 -0
- package/src/services/PlatformService/createBrowserPlatformService/createBrowserPlatformService.js +26 -0
- package/src/services/PlatformService/createBrowserPlatformService/index.d.ts +1 -0
- package/src/services/PlatformService/index.d.ts +3 -0
- package/src/services/PlatformService/types.d.ts +25 -0
- package/src/sleep/index.d.ts +1 -0
- package/src/sleep/sleep.cjs +13 -0
- package/src/sleep/sleep.d.ts +11 -0
- package/src/sleep/sleep.js +9 -0
- package/src/template/index.d.ts +1 -0
- package/src/template/template.cjs +25 -0
- package/src/template/template.d.ts +18 -0
- package/src/template/template.js +21 -0
- package/src/trimEnd/index.d.ts +1 -0
- package/src/trimEnd/trimEnd.cjs +14 -0
- package/src/trimEnd/trimEnd.d.ts +1 -0
- package/src/trimEnd/trimEnd.js +10 -0
- package/src/uniq/index.d.ts +1 -0
- package/src/uniq/uniq.cjs +33 -0
- package/src/uniq/uniq.d.ts +17 -0
- package/src/uniq/uniq.js +29 -0
- package/src/wrapMethodWithCallback/index.d.ts +1 -0
- package/src/wrapMethodWithCallback/wrapMethodWithCallback.cjs +47 -0
- package/src/wrapMethodWithCallback/wrapMethodWithCallback.d.ts +36 -0
- package/src/wrapMethodWithCallback/wrapMethodWithCallback.js +43 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { parseChainId } from './parseChainId.js';
|
|
3
|
+
|
|
4
|
+
const parseEvmNetworks = (networks) => {
|
|
5
|
+
const clone = networks.slice();
|
|
6
|
+
return clone.map((network) => {
|
|
7
|
+
network.chainId = parseChainId(network.chainId);
|
|
8
|
+
network.networkId = parseChainId(network.networkId);
|
|
9
|
+
return network;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { parseEvmNetworks };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pipe } from './pipe';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a chainable function that allows adding additional transformations
|
|
8
|
+
* or operations via the `pipe` method, where each function in the chain
|
|
9
|
+
* can operate on the output type of the previous function.
|
|
10
|
+
* @param initialFunc The initial function to start the chain.
|
|
11
|
+
* @returns An object representing the chain of functions. The returned object
|
|
12
|
+
* has a `pipe` method to add more functions to the chain and can be invoked
|
|
13
|
+
* directly to execute the chain of functions with an input.
|
|
14
|
+
* @example
|
|
15
|
+
* ```
|
|
16
|
+
* // Define a function that increments its input
|
|
17
|
+
* const increment = (x: number) => x + 1;
|
|
18
|
+
* // Create a function chain starting with the increment function
|
|
19
|
+
* const chain = createFnPipe(increment)
|
|
20
|
+
* .pipe(x => x * 2) // After incrementing, multiply the result by 2
|
|
21
|
+
* .pipe(x => `Result: ${x}`); // Then, convert the number to a string with a prefix
|
|
22
|
+
*
|
|
23
|
+
* console.log(chain(3)); // Output: "Result: 8"
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
const pipe = (initialFunc) => {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
const funcs = [initialFunc];
|
|
29
|
+
const executeFn = (input) => funcs.reduce((acc, func) => func(acc), input);
|
|
30
|
+
const pipe = (newFunc) => {
|
|
31
|
+
funcs.push(newFunc);
|
|
32
|
+
// The type assertion to Func<T, V> is necessary to align with the evolving return type.
|
|
33
|
+
return Object.assign((input) => executeFn(input), {
|
|
34
|
+
pipe,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return Object.assign(executeFn, { pipe });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.pipe = pipe;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type Func<T, U> = (input: T) => U;
|
|
2
|
+
/**
|
|
3
|
+
* Creates a chainable function that allows adding additional transformations
|
|
4
|
+
* or operations via the `pipe` method, where each function in the chain
|
|
5
|
+
* can operate on the output type of the previous function.
|
|
6
|
+
* @param initialFunc The initial function to start the chain.
|
|
7
|
+
* @returns An object representing the chain of functions. The returned object
|
|
8
|
+
* has a `pipe` method to add more functions to the chain and can be invoked
|
|
9
|
+
* directly to execute the chain of functions with an input.
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* // Define a function that increments its input
|
|
13
|
+
* const increment = (x: number) => x + 1;
|
|
14
|
+
* // Create a function chain starting with the increment function
|
|
15
|
+
* const chain = createFnPipe(increment)
|
|
16
|
+
* .pipe(x => x * 2) // After incrementing, multiply the result by 2
|
|
17
|
+
* .pipe(x => `Result: ${x}`); // Then, convert the number to a string with a prefix
|
|
18
|
+
*
|
|
19
|
+
* console.log(chain(3)); // Output: "Result: 8"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const pipe: <T, U>(initialFunc: Func<T, U>) => Func<T, U> & {
|
|
23
|
+
pipe: <V>(newFunc: Func<U, V>) => Func<T, V> & {
|
|
24
|
+
pipe: any;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export {};
|
package/src/pipe/pipe.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/**
|
|
3
|
+
* Creates a chainable function that allows adding additional transformations
|
|
4
|
+
* or operations via the `pipe` method, where each function in the chain
|
|
5
|
+
* can operate on the output type of the previous function.
|
|
6
|
+
* @param initialFunc The initial function to start the chain.
|
|
7
|
+
* @returns An object representing the chain of functions. The returned object
|
|
8
|
+
* has a `pipe` method to add more functions to the chain and can be invoked
|
|
9
|
+
* directly to execute the chain of functions with an input.
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* // Define a function that increments its input
|
|
13
|
+
* const increment = (x: number) => x + 1;
|
|
14
|
+
* // Create a function chain starting with the increment function
|
|
15
|
+
* const chain = createFnPipe(increment)
|
|
16
|
+
* .pipe(x => x * 2) // After incrementing, multiply the result by 2
|
|
17
|
+
* .pipe(x => `Result: ${x}`); // Then, convert the number to a string with a prefix
|
|
18
|
+
*
|
|
19
|
+
* console.log(chain(3)); // Output: "Result: 8"
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const pipe = (initialFunc) => {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
const funcs = [initialFunc];
|
|
25
|
+
const executeFn = (input) => funcs.reduce((acc, func) => func(acc), input);
|
|
26
|
+
const pipe = (newFunc) => {
|
|
27
|
+
funcs.push(newFunc);
|
|
28
|
+
// The type assertion to Func<T, V> is necessary to align with the evolving return type.
|
|
29
|
+
return Object.assign((input) => executeFn(input), {
|
|
30
|
+
pipe,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
return Object.assign(executeFn, { pipe });
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { pipe };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../_virtual/_tslib.cjs');
|
|
7
|
+
var sleep = require('./sleep/sleep.cjs');
|
|
8
|
+
|
|
9
|
+
const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
|
|
10
|
+
const retryableFn = (fn_1, ...args_1) => _tslib.__awaiter(void 0, [fn_1, ...args_1], void 0, function* (fn, options = {}) {
|
|
11
|
+
const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', retryIntervalMs = 0, logger, } = options;
|
|
12
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('Configured retryableFn with options: ', {
|
|
13
|
+
currentRetry,
|
|
14
|
+
fallbackValue,
|
|
15
|
+
maxRetries,
|
|
16
|
+
retryStrategy,
|
|
17
|
+
timeoutMs,
|
|
18
|
+
});
|
|
19
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
reject(new Error('Timeout'));
|
|
22
|
+
}, timeoutMs);
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
const result = yield Promise.race([fn(), timeoutPromise]);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn caught error: ', err);
|
|
30
|
+
if (currentRetry >= maxRetries) {
|
|
31
|
+
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning/throwing fallback value', err, fallbackValue);
|
|
32
|
+
if (fallbackValue instanceof Error) {
|
|
33
|
+
throw fallbackValue;
|
|
34
|
+
}
|
|
35
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return fallbackValue;
|
|
39
|
+
}
|
|
40
|
+
const isTimeout = (err === null || err === void 0 ? void 0 : err.message) === 'Timeout';
|
|
41
|
+
const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
|
|
42
|
+
(retryStrategy === 'timeout-only' && isTimeout) ||
|
|
43
|
+
(retryStrategy === 'rejection-only' && !isTimeout);
|
|
44
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn shouldRetry: ', shouldRetry);
|
|
45
|
+
if (!shouldRetry) {
|
|
46
|
+
if (fallbackValue instanceof Error) {
|
|
47
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn throwing fallbackValue error: ', fallbackValue);
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
51
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning undefined');
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning fallbackValue: ', fallbackValue);
|
|
55
|
+
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning fallback value', err);
|
|
56
|
+
return fallbackValue;
|
|
57
|
+
}
|
|
58
|
+
if (retryIntervalMs)
|
|
59
|
+
yield sleep.sleep(retryIntervalMs);
|
|
60
|
+
return retryableFn(fn, {
|
|
61
|
+
currentRetry: currentRetry + 1,
|
|
62
|
+
fallbackValue,
|
|
63
|
+
logger,
|
|
64
|
+
maxRetries,
|
|
65
|
+
retryIntervalMs,
|
|
66
|
+
retryStrategy,
|
|
67
|
+
timeoutMs,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
exports.FALLBACK_UNDEFINED = FALLBACK_UNDEFINED;
|
|
73
|
+
exports.retryableFn = retryableFn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
2
|
+
export declare const FALLBACK_UNDEFINED = "FALLBACK_UNDEFINED";
|
|
3
|
+
export type RetryableFnOptions<T> = {
|
|
4
|
+
/** Maximum number of retry attempts before returning fallbackValue */
|
|
5
|
+
maxRetries?: number;
|
|
6
|
+
/** Internal only. Do not use */
|
|
7
|
+
currentRetry?: number;
|
|
8
|
+
/** Timeout in ms to wait before executing retryStrategy */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** The value to fallback to when function rejects or times out */
|
|
11
|
+
fallbackValue?: T | Error | typeof FALLBACK_UNDEFINED;
|
|
12
|
+
/** Configure whether the fn should be retried only on timeout, only on rejection, or both */
|
|
13
|
+
retryStrategy?: 'timeout-only' | 'rejection-only' | 'timeout-and-rejection';
|
|
14
|
+
/** Set the logger to be used */
|
|
15
|
+
logger?: Logger | typeof console;
|
|
16
|
+
/** Ms to wait before a retry */
|
|
17
|
+
retryIntervalMs?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare const retryableFn: <T>(fn: () => Promise<T>, options?: RetryableFnOptions<T>) => Promise<T>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
+
import { sleep } from './sleep/sleep.js';
|
|
4
|
+
|
|
5
|
+
const FALLBACK_UNDEFINED = 'FALLBACK_UNDEFINED';
|
|
6
|
+
const retryableFn = (fn_1, ...args_1) => __awaiter(void 0, [fn_1, ...args_1], void 0, function* (fn, options = {}) {
|
|
7
|
+
const { maxRetries = 3, currentRetry = 0, timeoutMs = 100, fallbackValue = new Error('Max retries reached'), retryStrategy = 'timeout-only', retryIntervalMs = 0, logger, } = options;
|
|
8
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('Configured retryableFn with options: ', {
|
|
9
|
+
currentRetry,
|
|
10
|
+
fallbackValue,
|
|
11
|
+
maxRetries,
|
|
12
|
+
retryStrategy,
|
|
13
|
+
timeoutMs,
|
|
14
|
+
});
|
|
15
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
reject(new Error('Timeout'));
|
|
18
|
+
}, timeoutMs);
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
const result = yield Promise.race([fn(), timeoutPromise]);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn caught error: ', err);
|
|
26
|
+
if (currentRetry >= maxRetries) {
|
|
27
|
+
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning/throwing fallback value', err, fallbackValue);
|
|
28
|
+
if (fallbackValue instanceof Error) {
|
|
29
|
+
throw fallbackValue;
|
|
30
|
+
}
|
|
31
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
return fallbackValue;
|
|
35
|
+
}
|
|
36
|
+
const isTimeout = (err === null || err === void 0 ? void 0 : err.message) === 'Timeout';
|
|
37
|
+
const shouldRetry = retryStrategy === 'timeout-and-rejection' ||
|
|
38
|
+
(retryStrategy === 'timeout-only' && isTimeout) ||
|
|
39
|
+
(retryStrategy === 'rejection-only' && !isTimeout);
|
|
40
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn shouldRetry: ', shouldRetry);
|
|
41
|
+
if (!shouldRetry) {
|
|
42
|
+
if (fallbackValue instanceof Error) {
|
|
43
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn throwing fallbackValue error: ', fallbackValue);
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
else if (fallbackValue === FALLBACK_UNDEFINED) {
|
|
47
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning undefined');
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
logger === null || logger === void 0 ? void 0 : logger.debug('retryableFn returning fallbackValue: ', fallbackValue);
|
|
51
|
+
logger === null || logger === void 0 ? void 0 : logger.error('Error while retrying function, returning fallback value', err);
|
|
52
|
+
return fallbackValue;
|
|
53
|
+
}
|
|
54
|
+
if (retryIntervalMs)
|
|
55
|
+
yield sleep(retryIntervalMs);
|
|
56
|
+
return retryableFn(fn, {
|
|
57
|
+
currentRetry: currentRetry + 1,
|
|
58
|
+
fallbackValue,
|
|
59
|
+
logger,
|
|
60
|
+
maxRetries,
|
|
61
|
+
retryIntervalMs,
|
|
62
|
+
retryStrategy,
|
|
63
|
+
timeoutMs,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export { FALLBACK_UNDEFINED, retryableFn };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { runSafe } from './runSafe';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Safely executes a callback function.
|
|
10
|
+
* @template T The type of the callback's return value.
|
|
11
|
+
* @template E The type of the error.
|
|
12
|
+
* @param {() => Promise<T> | T} callback A function that might throw an error.
|
|
13
|
+
* @returns {Promise<[T | undefined, E | undefined]>} A tuple with either the result or the error.
|
|
14
|
+
*/
|
|
15
|
+
const runSafe = (callback) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
const resolved = yield callback();
|
|
18
|
+
return [resolved, undefined];
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
return [undefined, error];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
exports.runSafe = runSafe;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safely executes a callback function.
|
|
3
|
+
* @template T The type of the callback's return value.
|
|
4
|
+
* @template E The type of the error.
|
|
5
|
+
* @param {() => Promise<T> | T} callback A function that might throw an error.
|
|
6
|
+
* @returns {Promise<[T | undefined, E | undefined]>} A tuple with either the result or the error.
|
|
7
|
+
*/
|
|
8
|
+
export declare const runSafe: <T, E>(callback: () => Promise<T> | T) => Promise<[T | undefined, E | undefined]>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Safely executes a callback function.
|
|
6
|
+
* @template T The type of the callback's return value.
|
|
7
|
+
* @template E The type of the error.
|
|
8
|
+
* @param {() => Promise<T> | T} callback A function that might throw an error.
|
|
9
|
+
* @returns {Promise<[T | undefined, E | undefined]>} A tuple with either the result or the error.
|
|
10
|
+
*/
|
|
11
|
+
const runSafe = (callback) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
try {
|
|
13
|
+
const resolved = yield callback();
|
|
14
|
+
return [resolved, undefined];
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return [undefined, error];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export { runSafe };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
|
|
8
|
+
var _a, _FetchService_implementation;
|
|
9
|
+
/**
|
|
10
|
+
* Class implementing the fetch service with a configurable fetch implementation.
|
|
11
|
+
*/
|
|
12
|
+
class FetchService {
|
|
13
|
+
static get implementation() {
|
|
14
|
+
if (!_tslib.__classPrivateFieldGet(_a, _a, "f", _FetchService_implementation)) {
|
|
15
|
+
return { fetch: window.fetch.bind(window) };
|
|
16
|
+
}
|
|
17
|
+
return _tslib.__classPrivateFieldGet(_a, _a, "f", _FetchService_implementation);
|
|
18
|
+
}
|
|
19
|
+
static set implementation(implementation) {
|
|
20
|
+
_tslib.__classPrivateFieldSet(_a, _a, implementation, "f", _FetchService_implementation);
|
|
21
|
+
}
|
|
22
|
+
static get fetch() {
|
|
23
|
+
return _a.implementation.fetch;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
_a = FetchService;
|
|
27
|
+
_FetchService_implementation = { value: void 0 };
|
|
28
|
+
|
|
29
|
+
exports.FetchService = FetchService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IFetchService } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Class implementing the fetch service with a configurable fetch implementation.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FetchService {
|
|
6
|
+
#private;
|
|
7
|
+
static get implementation(): IFetchService;
|
|
8
|
+
static set implementation(implementation: IFetchService);
|
|
9
|
+
static get fetch(): (input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from '../../../_virtual/_tslib.js';
|
|
3
|
+
|
|
4
|
+
var _a, _FetchService_implementation;
|
|
5
|
+
/**
|
|
6
|
+
* Class implementing the fetch service with a configurable fetch implementation.
|
|
7
|
+
*/
|
|
8
|
+
class FetchService {
|
|
9
|
+
static get implementation() {
|
|
10
|
+
if (!__classPrivateFieldGet(_a, _a, "f", _FetchService_implementation)) {
|
|
11
|
+
return { fetch: window.fetch.bind(window) };
|
|
12
|
+
}
|
|
13
|
+
return __classPrivateFieldGet(_a, _a, "f", _FetchService_implementation);
|
|
14
|
+
}
|
|
15
|
+
static set implementation(implementation) {
|
|
16
|
+
__classPrivateFieldSet(_a, _a, implementation, "f", _FetchService_implementation);
|
|
17
|
+
}
|
|
18
|
+
static get fetch() {
|
|
19
|
+
return _a.implementation.fetch;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
_a = FetchService;
|
|
23
|
+
_FetchService_implementation = { value: void 0 };
|
|
24
|
+
|
|
25
|
+
export { FetchService };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var types = require('@dynamic-labs/types');
|
|
8
|
+
var createWindowOauth2Service = require('./createWindowOauth2Service/createWindowOauth2Service.cjs');
|
|
9
|
+
|
|
10
|
+
var _a, _Oauth2Service_implementation;
|
|
11
|
+
/**
|
|
12
|
+
* Class implementing the fetch service with a configurable fetch implementation.
|
|
13
|
+
*/
|
|
14
|
+
class Oauth2Service {
|
|
15
|
+
static get implementation() {
|
|
16
|
+
if (!_tslib.__classPrivateFieldGet(_a, _a, "f", _Oauth2Service_implementation)) {
|
|
17
|
+
return createWindowOauth2Service.createWindowOauth2Service();
|
|
18
|
+
}
|
|
19
|
+
return _tslib.__classPrivateFieldGet(_a, _a, "f", _Oauth2Service_implementation);
|
|
20
|
+
}
|
|
21
|
+
static set implementation(implementation) {
|
|
22
|
+
_tslib.__classPrivateFieldSet(_a, _a, implementation, "f", _Oauth2Service_implementation);
|
|
23
|
+
}
|
|
24
|
+
static get getOauthCode() {
|
|
25
|
+
return _a.implementation.getOauthCode;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
_a = Oauth2Service;
|
|
29
|
+
_Oauth2Service_implementation = { value: void 0 };
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
Oauth2Service.isGetOauthCodeError = (error) => error === 'user-cancelled' ||
|
|
32
|
+
(typeof error === 'object' &&
|
|
33
|
+
'code' in error &&
|
|
34
|
+
Object.values(types.SocialOAuthErrorCode).includes(error.code) &&
|
|
35
|
+
'message' in error &&
|
|
36
|
+
typeof error.message === 'string');
|
|
37
|
+
|
|
38
|
+
exports.Oauth2Service = Oauth2Service;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OauthResultResponse, Provider, ProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
import { SocialOAuthErrorCode } from '@dynamic-labs/types';
|
|
3
|
+
export type GetOauthCodeProps = {
|
|
4
|
+
provider: ProviderEnum;
|
|
5
|
+
apiProvider: Provider | undefined;
|
|
6
|
+
setIsProcessing: (value: boolean) => void;
|
|
7
|
+
onSettled?: VoidFunction;
|
|
8
|
+
getOAuthResultFromApi: () => Promise<OauthResultResponse | undefined>;
|
|
9
|
+
state: string;
|
|
10
|
+
oauthLoginUrl: URL;
|
|
11
|
+
sessionTimeout: number;
|
|
12
|
+
/**
|
|
13
|
+
* Overrides the default redirectUrl coming from the DynamicContextProvider
|
|
14
|
+
*/
|
|
15
|
+
redirectUrl?: string;
|
|
16
|
+
isMobile?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type IOauth2Service = {
|
|
19
|
+
getOauthCode: (props: GetOauthCodeProps) => Promise<string>;
|
|
20
|
+
};
|
|
21
|
+
export type GetOauthCodeError = 'user-cancelled' | {
|
|
22
|
+
code: SocialOAuthErrorCode;
|
|
23
|
+
message: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Class implementing the fetch service with a configurable fetch implementation.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Oauth2Service {
|
|
29
|
+
#private;
|
|
30
|
+
static get implementation(): IOauth2Service;
|
|
31
|
+
static set implementation(implementation: IOauth2Service);
|
|
32
|
+
static get getOauthCode(): (props: GetOauthCodeProps) => Promise<string>;
|
|
33
|
+
static isGetOauthCodeError: (error: any) => error is GetOauthCodeError;
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { SocialOAuthErrorCode } from '@dynamic-labs/types';
|
|
4
|
+
import { createWindowOauth2Service } from './createWindowOauth2Service/createWindowOauth2Service.js';
|
|
5
|
+
|
|
6
|
+
var _a, _Oauth2Service_implementation;
|
|
7
|
+
/**
|
|
8
|
+
* Class implementing the fetch service with a configurable fetch implementation.
|
|
9
|
+
*/
|
|
10
|
+
class Oauth2Service {
|
|
11
|
+
static get implementation() {
|
|
12
|
+
if (!__classPrivateFieldGet(_a, _a, "f", _Oauth2Service_implementation)) {
|
|
13
|
+
return createWindowOauth2Service();
|
|
14
|
+
}
|
|
15
|
+
return __classPrivateFieldGet(_a, _a, "f", _Oauth2Service_implementation);
|
|
16
|
+
}
|
|
17
|
+
static set implementation(implementation) {
|
|
18
|
+
__classPrivateFieldSet(_a, _a, implementation, "f", _Oauth2Service_implementation);
|
|
19
|
+
}
|
|
20
|
+
static get getOauthCode() {
|
|
21
|
+
return _a.implementation.getOauthCode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
_a = Oauth2Service;
|
|
25
|
+
_Oauth2Service_implementation = { value: void 0 };
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
Oauth2Service.isGetOauthCodeError = (error) => error === 'user-cancelled' ||
|
|
28
|
+
(typeof error === 'object' &&
|
|
29
|
+
'code' in error &&
|
|
30
|
+
Object.values(SocialOAuthErrorCode).includes(error.code) &&
|
|
31
|
+
'message' in error &&
|
|
32
|
+
typeof error.message === 'string');
|
|
33
|
+
|
|
34
|
+
export { Oauth2Service };
|