@dynamic-labs/utils 0.19.0-alpha.9 → 1.0.0-alpha.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +299 -0
  2. package/package.json +7 -5
  3. package/src/CancellablePromise/CancellablePromise.cjs +126 -126
  4. package/src/CancellablePromise/CancellablePromise.d.ts +54 -54
  5. package/src/CancellablePromise/CancellablePromise.js +126 -126
  6. package/src/CancellablePromise/index.d.ts +1 -1
  7. package/src/bigIntToHex/bigIntToHex.cjs +15 -0
  8. package/src/bigIntToHex/bigIntToHex.d.ts +1 -0
  9. package/src/bigIntToHex/bigIntToHex.js +11 -0
  10. package/src/bigIntToHex/index.d.ts +1 -0
  11. package/src/bufferToBase64.cjs +5 -5
  12. package/src/bufferToBase64.d.ts +1 -1
  13. package/src/bufferToBase64.js +5 -5
  14. package/src/errors/AccountExistsError.cjs +6 -6
  15. package/src/errors/AccountExistsError.d.ts +13 -13
  16. package/src/errors/AccountExistsError.js +6 -6
  17. package/src/errors/ChainalysisError.cjs +5 -5
  18. package/src/errors/ChainalysisError.d.ts +5 -5
  19. package/src/errors/ChainalysisError.js +5 -5
  20. package/src/errors/CustomError.cjs +16 -16
  21. package/src/errors/CustomError.d.ts +11 -11
  22. package/src/errors/CustomError.js +16 -16
  23. package/src/errors/DynamicError.cjs +1 -1
  24. package/src/errors/DynamicError.d.ts +3 -3
  25. package/src/errors/DynamicError.js +1 -1
  26. package/src/errors/EmailAlreadyExistsError.cjs +4 -4
  27. package/src/errors/EmailAlreadyExistsError.d.ts +4 -4
  28. package/src/errors/EmailAlreadyExistsError.js +4 -4
  29. package/src/errors/EmailProviderError.cjs +4 -4
  30. package/src/errors/EmailProviderError.d.ts +4 -4
  31. package/src/errors/EmailProviderError.js +4 -4
  32. package/src/errors/EmailVerificationError.cjs +4 -4
  33. package/src/errors/EmailVerificationError.d.ts +4 -4
  34. package/src/errors/EmailVerificationError.js +4 -4
  35. package/src/errors/GateBlockedError.cjs +5 -5
  36. package/src/errors/GateBlockedError.d.ts +5 -5
  37. package/src/errors/GateBlockedError.js +5 -5
  38. package/src/errors/MissingEnvironmentIdError.cjs +4 -4
  39. package/src/errors/MissingEnvironmentIdError.d.ts +4 -4
  40. package/src/errors/MissingEnvironmentIdError.js +4 -4
  41. package/src/errors/NoAccessError.cjs +6 -6
  42. package/src/errors/NoAccessError.d.ts +9 -9
  43. package/src/errors/NoAccessError.js +6 -6
  44. package/src/errors/NotSupportedError.cjs +1 -1
  45. package/src/errors/NotSupportedError.d.ts +3 -3
  46. package/src/errors/NotSupportedError.js +1 -1
  47. package/src/errors/SocialAccountAlreadyExistsError.cjs +4 -4
  48. package/src/errors/SocialAccountAlreadyExistsError.d.ts +4 -4
  49. package/src/errors/SocialAccountAlreadyExistsError.js +4 -4
  50. package/src/errors/UserHasAccountWithEmailError.cjs +5 -5
  51. package/src/errors/UserHasAccountWithEmailError.d.ts +5 -5
  52. package/src/errors/UserHasAccountWithEmailError.js +5 -5
  53. package/src/errors/UsernameAlreadyExistsError.cjs +4 -4
  54. package/src/errors/UsernameAlreadyExistsError.d.ts +4 -4
  55. package/src/errors/UsernameAlreadyExistsError.js +4 -4
  56. package/src/errors/WalletNotDeployedError.cjs +4 -4
  57. package/src/errors/WalletNotDeployedError.d.ts +4 -4
  58. package/src/errors/WalletNotDeployedError.js +4 -4
  59. package/src/errors/WalletUsedError.cjs +4 -4
  60. package/src/errors/WalletUsedError.d.ts +4 -4
  61. package/src/errors/WalletUsedError.js +4 -4
  62. package/src/errors/index.d.ts +16 -16
  63. package/src/getOrMapViemChain.cjs +77 -0
  64. package/src/getOrMapViemChain.d.ts +11 -0
  65. package/src/getOrMapViemChain.js +51 -0
  66. package/src/{getPathFromObject.cjs → getProvidersFromWindow.cjs} +32 -28
  67. package/src/getProvidersFromWindow.d.ts +7 -0
  68. package/src/{getPathFromObject.js → getProvidersFromWindow.js} +32 -28
  69. package/src/index.cjs +17 -2
  70. package/src/index.d.ts +15 -10
  71. package/src/index.js +7 -2
  72. package/src/isBigInt/index.d.ts +1 -0
  73. package/src/isBigInt/isBigInt.cjs +7 -0
  74. package/src/isBigInt/isBigInt.d.ts +1 -0
  75. package/src/isBigInt/isBigInt.js +3 -0
  76. package/src/isFunction/index.d.ts +1 -1
  77. package/src/isFunction/isFunction.cjs +1 -1
  78. package/src/isFunction/isFunction.d.ts +1 -1
  79. package/src/isFunction/isFunction.js +1 -1
  80. package/src/isMobile.cjs +121 -110
  81. package/src/isMobile.d.ts +18 -16
  82. package/src/isMobile.js +120 -111
  83. package/src/last.cjs +14 -14
  84. package/src/last.d.ts +15 -15
  85. package/src/last.js +14 -14
  86. package/src/localStorageAsync.cjs +17 -17
  87. package/src/localStorageAsync.d.ts +3 -3
  88. package/src/localStorageAsync.js +17 -17
  89. package/src/logger/index.d.ts +1 -1
  90. package/src/logger/logger.d.ts +2 -2
  91. package/src/parseChainId.d.ts +1 -1
  92. package/src/parseEvmNetworks.cjs +6 -6
  93. package/src/parseEvmNetworks.d.ts +2 -2
  94. package/src/parseEvmNetworks.js +6 -6
  95. package/src/retryableFn.cjs +53 -0
  96. package/src/retryableFn.d.ts +14 -0
  97. package/src/retryableFn.js +48 -0
  98. package/src/sleep/index.d.ts +1 -0
  99. package/src/sleep/sleep.cjs +12 -0
  100. package/src/sleep/sleep.d.ts +11 -0
  101. package/src/sleep/sleep.js +8 -0
  102. package/src/getPathFromObject.d.ts +0 -8
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var chains = require('viem/chains');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n["default"] = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var chains__namespace = /*#__PURE__*/_interopNamespace(chains);
26
+
27
+ // eslint-disable-next-line import/no-namespace
28
+ /**
29
+ * Gets the chain object for the given chain id.
30
+ * @param chainId - Chain id of the target EVM chain.
31
+ * @returns Viem's chain object.
32
+ */
33
+ const getChain = (chainId) => {
34
+ for (const chain of Object.values(chains__namespace)) {
35
+ if ('id' in chain) {
36
+ if (chain.id === chainId) {
37
+ return chain;
38
+ }
39
+ }
40
+ }
41
+ throw new Error(`Chain with id ${chainId} not found`);
42
+ };
43
+ const mapChain = (network) => {
44
+ var _a;
45
+ return ({
46
+ blockExplorers: ((_a = network.blockExplorerUrls) === null || _a === void 0 ? void 0 : _a[0])
47
+ ? {
48
+ default: {
49
+ name: network.blockExplorerUrls[0],
50
+ url: network.blockExplorerUrls[0],
51
+ },
52
+ }
53
+ : undefined,
54
+ id: network.chainId,
55
+ name: network.vanityName || network.chainName,
56
+ nativeCurrency: network.nativeCurrency,
57
+ network: network.chainName,
58
+ rpcUrls: {
59
+ default: { http: network.rpcUrls },
60
+ public: { http: network.rpcUrls },
61
+ },
62
+ });
63
+ };
64
+ const getOrMapViemChain = (network) => {
65
+ let chain;
66
+ try {
67
+ chain = getChain(network.chainId);
68
+ }
69
+ catch (_a) {
70
+ chain = mapChain(network);
71
+ }
72
+ return chain;
73
+ };
74
+
75
+ exports.getChain = getChain;
76
+ exports.getOrMapViemChain = getOrMapViemChain;
77
+ exports.mapChain = mapChain;
@@ -0,0 +1,11 @@
1
+ import { Chain } from 'viem';
2
+ import * as chains from 'viem/chains';
3
+ import { EvmNetwork } from '@dynamic-labs/types';
4
+ /**
5
+ * Gets the chain object for the given chain id.
6
+ * @param chainId - Chain id of the target EVM chain.
7
+ * @returns Viem's chain object.
8
+ */
9
+ export declare const getChain: (chainId: number) => chains.Chain;
10
+ export declare const mapChain: (network: EvmNetwork) => Chain;
11
+ export declare const getOrMapViemChain: (network: EvmNetwork) => Chain;
@@ -0,0 +1,51 @@
1
+ import * as chains from 'viem/chains';
2
+
3
+ // eslint-disable-next-line import/no-namespace
4
+ /**
5
+ * Gets the chain object for the given chain id.
6
+ * @param chainId - Chain id of the target EVM chain.
7
+ * @returns Viem's chain object.
8
+ */
9
+ const getChain = (chainId) => {
10
+ for (const chain of Object.values(chains)) {
11
+ if ('id' in chain) {
12
+ if (chain.id === chainId) {
13
+ return chain;
14
+ }
15
+ }
16
+ }
17
+ throw new Error(`Chain with id ${chainId} not found`);
18
+ };
19
+ const mapChain = (network) => {
20
+ var _a;
21
+ return ({
22
+ blockExplorers: ((_a = network.blockExplorerUrls) === null || _a === void 0 ? void 0 : _a[0])
23
+ ? {
24
+ default: {
25
+ name: network.blockExplorerUrls[0],
26
+ url: network.blockExplorerUrls[0],
27
+ },
28
+ }
29
+ : undefined,
30
+ id: network.chainId,
31
+ name: network.vanityName || network.chainName,
32
+ nativeCurrency: network.nativeCurrency,
33
+ network: network.chainName,
34
+ rpcUrls: {
35
+ default: { http: network.rpcUrls },
36
+ public: { http: network.rpcUrls },
37
+ },
38
+ });
39
+ };
40
+ const getOrMapViemChain = (network) => {
41
+ let chain;
42
+ try {
43
+ chain = getChain(network.chainId);
44
+ }
45
+ catch (_a) {
46
+ chain = mapChain(network);
47
+ }
48
+ return chain;
49
+ };
50
+
51
+ export { getChain, getOrMapViemChain, mapChain };
@@ -2,33 +2,37 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- /**
6
- * return the destination (value)
7
- *
8
- * @param {object} obj - object to search for the item
9
- * @param {string} path - path in the obj to the item
10
- * @returns {T[]} - array of found items
11
- */
12
- const getPathFromObject = (obj, path) => {
13
- const splitPath = path.split('.');
14
- let result = obj;
15
- const foundProviders = [];
16
- for (const [index, p] of Object.entries(splitPath)) {
17
- result = result[p];
18
- if (typeof result !== 'object' || result === null) {
19
- return [];
20
- }
21
- // we need to check if we have hit the end of the requested path
22
- if (Number(index) === splitPath.length - 1) {
23
- if (Array.isArray(result)) {
24
- result.forEach((p) => foundProviders.push(p));
25
- }
26
- else {
27
- foundProviders.push(result);
28
- }
29
- }
30
- }
31
- return foundProviders;
5
+ /**
6
+ * return the destination (value)
7
+ *
8
+ * @param {string} path - path in the obj to the item
9
+ * @returns {T[]} - array of found items
10
+ */
11
+ const getProvidersFromWindow = (path) => {
12
+ const splitPath = path.split('.');
13
+ let result = window;
14
+ const foundProviders = [];
15
+ for (const [index, p] of Object.entries(splitPath)) {
16
+ result = result[p];
17
+ if (typeof result !== 'object' || result === null) {
18
+ return [];
19
+ }
20
+ // we need to check if we have hit the end of the requested path
21
+ if (Number(index) === splitPath.length - 1) {
22
+ if (Array.isArray(result)) {
23
+ result.forEach((p) => foundProviders.push(p));
24
+ }
25
+ else {
26
+ if (result.providers) {
27
+ result.providers.forEach((p) => foundProviders.push(p));
28
+ }
29
+ else {
30
+ foundProviders.push(result);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ return foundProviders;
32
36
  };
33
37
 
34
- exports.getPathFromObject = getPathFromObject;
38
+ exports.getProvidersFromWindow = getProvidersFromWindow;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * return the destination (value)
3
+ *
4
+ * @param {string} path - path in the obj to the item
5
+ * @returns {T[]} - array of found items
6
+ */
7
+ export declare const getProvidersFromWindow: <T>(path: string) => T[];
@@ -1,30 +1,34 @@
1
- /**
2
- * return the destination (value)
3
- *
4
- * @param {object} obj - object to search for the item
5
- * @param {string} path - path in the obj to the item
6
- * @returns {T[]} - array of found items
7
- */
8
- const getPathFromObject = (obj, path) => {
9
- const splitPath = path.split('.');
10
- let result = obj;
11
- const foundProviders = [];
12
- for (const [index, p] of Object.entries(splitPath)) {
13
- result = result[p];
14
- if (typeof result !== 'object' || result === null) {
15
- return [];
16
- }
17
- // we need to check if we have hit the end of the requested path
18
- if (Number(index) === splitPath.length - 1) {
19
- if (Array.isArray(result)) {
20
- result.forEach((p) => foundProviders.push(p));
21
- }
22
- else {
23
- foundProviders.push(result);
24
- }
25
- }
26
- }
27
- return foundProviders;
1
+ /**
2
+ * return the destination (value)
3
+ *
4
+ * @param {string} path - path in the obj to the item
5
+ * @returns {T[]} - array of found items
6
+ */
7
+ const getProvidersFromWindow = (path) => {
8
+ const splitPath = path.split('.');
9
+ let result = window;
10
+ const foundProviders = [];
11
+ for (const [index, p] of Object.entries(splitPath)) {
12
+ result = result[p];
13
+ if (typeof result !== 'object' || result === null) {
14
+ return [];
15
+ }
16
+ // we need to check if we have hit the end of the requested path
17
+ if (Number(index) === splitPath.length - 1) {
18
+ if (Array.isArray(result)) {
19
+ result.forEach((p) => foundProviders.push(p));
20
+ }
21
+ else {
22
+ if (result.providers) {
23
+ result.providers.forEach((p) => foundProviders.push(p));
24
+ }
25
+ else {
26
+ foundProviders.push(result);
27
+ }
28
+ }
29
+ }
30
+ }
31
+ return foundProviders;
28
32
  };
29
33
 
30
- export { getPathFromObject };
34
+ export { getProvidersFromWindow };
package/src/index.cjs CHANGED
@@ -26,7 +26,12 @@ var isMobile = require('./isMobile.cjs');
26
26
  var localStorageAsync = require('./localStorageAsync.cjs');
27
27
  var bufferToBase64 = require('./bufferToBase64.cjs');
28
28
  var last = require('./last.cjs');
29
- var getPathFromObject = require('./getPathFromObject.cjs');
29
+ var getProvidersFromWindow = require('./getProvidersFromWindow.cjs');
30
+ var sleep = require('./sleep/sleep.cjs');
31
+ var getOrMapViemChain = require('./getOrMapViemChain.cjs');
32
+ var bigIntToHex = require('./bigIntToHex/bigIntToHex.cjs');
33
+ var isBigInt = require('./isBigInt/isBigInt.cjs');
34
+ var retryableFn = require('./retryableFn.cjs');
30
35
 
31
36
 
32
37
 
@@ -50,6 +55,7 @@ exports.UserHasAccountWithEmailError = UserHasAccountWithEmailError.UserHasAccou
50
55
  exports.SocialAccountAlreadyExistsError = SocialAccountAlreadyExistsError.SocialAccountAlreadyExistsError;
51
56
  exports.CancellablePromise = CancellablePromise.CancellablePromise;
52
57
  exports.isFunction = isFunction.isFunction;
58
+ exports.getAndroidVersion = isMobile.getAndroidVersion;
53
59
  exports.isAndroid = isMobile.isAndroid;
54
60
  exports.isIOS = isMobile.isIOS;
55
61
  exports.isIPad = isMobile.isIPad;
@@ -58,9 +64,18 @@ exports.isIPhone8OrEarlier = isMobile.isIPhone8OrEarlier;
58
64
  exports.isLegacySafari = isMobile.isLegacySafari;
59
65
  exports.isMobile = isMobile.isMobile;
60
66
  exports.isSamsungBrowser = isMobile.isSamsungBrowser;
67
+ exports.isWindows = isMobile.isWindows;
61
68
  exports.getItemAsync = localStorageAsync.getItemAsync;
62
69
  exports.removeItemAsync = localStorageAsync.removeItemAsync;
63
70
  exports.setItemAsync = localStorageAsync.setItemAsync;
64
71
  exports.bufferToBase64 = bufferToBase64.bufferToBase64;
65
72
  exports.last = last.last;
66
- exports.getPathFromObject = getPathFromObject.getPathFromObject;
73
+ exports.getProvidersFromWindow = getProvidersFromWindow.getProvidersFromWindow;
74
+ exports.sleep = sleep.sleep;
75
+ exports.getChain = getOrMapViemChain.getChain;
76
+ exports.getOrMapViemChain = getOrMapViemChain.getOrMapViemChain;
77
+ exports.mapChain = getOrMapViemChain.mapChain;
78
+ exports.bigIntToHex = bigIntToHex.bigIntToHex;
79
+ exports.isBigInt = isBigInt.isBigInt;
80
+ exports.FALLBACK_UNDEFINED = retryableFn.FALLBACK_UNDEFINED;
81
+ exports.retryableFn = retryableFn.retryableFn;
package/src/index.d.ts CHANGED
@@ -1,10 +1,15 @@
1
- export * from './parseChainId';
2
- export * from './parseEvmNetworks';
3
- export * from './errors';
4
- export * from './CancellablePromise';
5
- export * from './isFunction';
6
- export * from './isMobile';
7
- export * from './localStorageAsync';
8
- export * from './bufferToBase64';
9
- export * from './last';
10
- export * from './getPathFromObject';
1
+ export * from './parseChainId';
2
+ export * from './parseEvmNetworks';
3
+ export * from './errors';
4
+ export * from './CancellablePromise';
5
+ export * from './isFunction';
6
+ export * from './isMobile';
7
+ export * from './localStorageAsync';
8
+ export * from './bufferToBase64';
9
+ export * from './last';
10
+ export * from './getProvidersFromWindow';
11
+ export * from './sleep';
12
+ export * from './getOrMapViemChain';
13
+ export * from './bigIntToHex';
14
+ export * from './isBigInt';
15
+ export * from './retryableFn';
package/src/index.js CHANGED
@@ -18,8 +18,13 @@ export { UserHasAccountWithEmailError } from './errors/UserHasAccountWithEmailEr
18
18
  export { SocialAccountAlreadyExistsError } from './errors/SocialAccountAlreadyExistsError.js';
19
19
  export { CancellablePromise } from './CancellablePromise/CancellablePromise.js';
20
20
  export { isFunction } from './isFunction/isFunction.js';
21
- export { isAndroid, isIOS, isIPad, isIPhone, isIPhone8OrEarlier, isLegacySafari, isMobile, isSamsungBrowser } from './isMobile.js';
21
+ export { getAndroidVersion, isAndroid, isIOS, isIPad, isIPhone, isIPhone8OrEarlier, isLegacySafari, isMobile, isSamsungBrowser, isWindows } from './isMobile.js';
22
22
  export { getItemAsync, removeItemAsync, setItemAsync } from './localStorageAsync.js';
23
23
  export { bufferToBase64 } from './bufferToBase64.js';
24
24
  export { last } from './last.js';
25
- export { getPathFromObject } from './getPathFromObject.js';
25
+ export { getProvidersFromWindow } from './getProvidersFromWindow.js';
26
+ export { sleep } from './sleep/sleep.js';
27
+ export { getChain, getOrMapViemChain, mapChain } from './getOrMapViemChain.js';
28
+ export { bigIntToHex } from './bigIntToHex/bigIntToHex.js';
29
+ export { isBigInt } from './isBigInt/isBigInt.js';
30
+ export { FALLBACK_UNDEFINED, retryableFn } from './retryableFn.js';
@@ -0,0 +1 @@
1
+ export { isBigInt } from './isBigInt';
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const isBigInt = (value) => typeof value === 'bigint';
6
+
7
+ exports.isBigInt = isBigInt;
@@ -0,0 +1 @@
1
+ export declare const isBigInt: (value: bigint | unknown) => value is bigint;
@@ -0,0 +1,3 @@
1
+ const isBigInt = (value) => typeof value === 'bigint';
2
+
3
+ export { isBigInt };
@@ -1 +1 @@
1
- export { isFunction } from './isFunction';
1
+ export { isFunction } from './isFunction';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- // eslint-disable-next-line @typescript-eslint/ban-types
5
+ // eslint-disable-next-line @typescript-eslint/ban-types
6
6
  const isFunction = (value) => typeof value === 'function';
7
7
 
8
8
  exports.isFunction = isFunction;
@@ -1 +1 @@
1
- export declare const isFunction: (value: Function | unknown) => value is Function;
1
+ export declare const isFunction: (value: Function | unknown) => value is Function;
@@ -1,4 +1,4 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-types
1
+ // eslint-disable-next-line @typescript-eslint/ban-types
2
2
  const isFunction = (value) => typeof value === 'function';
3
3
 
4
4
  export { isFunction };