lampamazaza-new-internal-utils 0.24.3

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 (216) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  3. package/dist/_virtual/rolldown_runtime.js +18 -0
  4. package/dist/config.cjs +82 -0
  5. package/dist/config.d.cts +42 -0
  6. package/dist/config.d.ts +42 -0
  7. package/dist/config.js +72 -0
  8. package/dist/errors/assert.cjs +11 -0
  9. package/dist/errors/assert.d.cts +11 -0
  10. package/dist/errors/assert.d.ts +11 -0
  11. package/dist/errors/assert.js +11 -0
  12. package/dist/errors/base.cjs +34 -0
  13. package/dist/errors/base.d.cts +21 -0
  14. package/dist/errors/base.d.ts +21 -0
  15. package/dist/errors/base.js +33 -0
  16. package/dist/errors/index.cjs +23 -0
  17. package/dist/errors/index.d.cts +11 -0
  18. package/dist/errors/index.d.ts +11 -0
  19. package/dist/errors/index.js +18 -0
  20. package/dist/errors/request.cjs +48 -0
  21. package/dist/errors/request.d.cts +61 -0
  22. package/dist/errors/request.d.ts +61 -0
  23. package/dist/errors/request.js +46 -0
  24. package/dist/errors/utils/isNetworkError.cjs +23 -0
  25. package/dist/errors/utils/isNetworkError.js +22 -0
  26. package/dist/errors/utils/toError.cjs +8 -0
  27. package/dist/errors/utils/toError.d.cts +4 -0
  28. package/dist/errors/utils/toError.d.ts +4 -0
  29. package/dist/errors/utils/toError.js +7 -0
  30. package/dist/index.cjs +125 -0
  31. package/dist/index.d.cts +30 -0
  32. package/dist/index.d.ts +30 -0
  33. package/dist/index.js +30 -0
  34. package/dist/logger.d.cts +11 -0
  35. package/dist/logger.d.ts +11 -0
  36. package/dist/nearClient.cjs +18 -0
  37. package/dist/nearClient.d.cts +8 -0
  38. package/dist/nearClient.d.ts +8 -0
  39. package/dist/nearClient.js +18 -0
  40. package/dist/poaBridge/constants/blockchains.cjs +57 -0
  41. package/dist/poaBridge/constants/blockchains.d.cts +86 -0
  42. package/dist/poaBridge/constants/blockchains.d.ts +86 -0
  43. package/dist/poaBridge/constants/blockchains.js +54 -0
  44. package/dist/poaBridge/errors/withdrawal.cjs +52 -0
  45. package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
  46. package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
  47. package/dist/poaBridge/errors/withdrawal.js +50 -0
  48. package/dist/poaBridge/getPendingDeposits.cjs +9 -0
  49. package/dist/poaBridge/getPendingDeposits.d.cts +12 -0
  50. package/dist/poaBridge/getPendingDeposits.d.ts +13 -0
  51. package/dist/poaBridge/getPendingDeposits.js +9 -0
  52. package/dist/poaBridge/index.cjs +23 -0
  53. package/dist/poaBridge/index.d.cts +11 -0
  54. package/dist/poaBridge/index.d.ts +11 -0
  55. package/dist/poaBridge/index.js +18 -0
  56. package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
  57. package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
  58. package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
  59. package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
  60. package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
  61. package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
  62. package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
  63. package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
  64. package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
  65. package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
  66. package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +161 -0
  67. package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +161 -0
  68. package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
  69. package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
  70. package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
  71. package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
  72. package/dist/services/blockchainBalanceService.cjs +40 -0
  73. package/dist/services/blockchainBalanceService.d.cts +21 -0
  74. package/dist/services/blockchainBalanceService.d.ts +21 -0
  75. package/dist/services/blockchainBalanceService.js +37 -0
  76. package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
  77. package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
  78. package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
  79. package/dist/solverRelay/errors/intentSettlement.js +20 -0
  80. package/dist/solverRelay/errors/quote.cjs +18 -0
  81. package/dist/solverRelay/errors/quote.d.cts +21 -0
  82. package/dist/solverRelay/errors/quote.d.ts +22 -0
  83. package/dist/solverRelay/errors/quote.js +18 -0
  84. package/dist/solverRelay/getQuote.cjs +49 -0
  85. package/dist/solverRelay/getQuote.d.cts +14 -0
  86. package/dist/solverRelay/getQuote.d.ts +14 -0
  87. package/dist/solverRelay/getQuote.js +49 -0
  88. package/dist/solverRelay/getStatus.cjs +26 -0
  89. package/dist/solverRelay/getStatus.d.cts +17 -0
  90. package/dist/solverRelay/getStatus.d.ts +18 -0
  91. package/dist/solverRelay/getStatus.js +26 -0
  92. package/dist/solverRelay/index.cjs +27 -0
  93. package/dist/solverRelay/index.d.cts +16 -0
  94. package/dist/solverRelay/index.d.ts +16 -0
  95. package/dist/solverRelay/index.js +22 -0
  96. package/dist/solverRelay/publishIntent.cjs +20 -0
  97. package/dist/solverRelay/publishIntent.d.cts +15 -0
  98. package/dist/solverRelay/publishIntent.d.ts +16 -0
  99. package/dist/solverRelay/publishIntent.js +20 -0
  100. package/dist/solverRelay/publishIntents.cjs +43 -0
  101. package/dist/solverRelay/publishIntents.d.cts +10 -0
  102. package/dist/solverRelay/publishIntents.d.ts +11 -0
  103. package/dist/solverRelay/publishIntents.js +42 -0
  104. package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
  105. package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
  106. package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
  107. package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
  108. package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
  109. package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
  110. package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
  111. package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
  112. package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
  113. package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
  114. package/dist/solverRelay/solverRelayHttpClient/types.d.cts +109 -0
  115. package/dist/solverRelay/solverRelayHttpClient/types.d.ts +109 -0
  116. package/dist/solverRelay/utils/parseFailedPublishError.cjs +40 -0
  117. package/dist/solverRelay/utils/parseFailedPublishError.d.cts +25 -0
  118. package/dist/solverRelay/utils/parseFailedPublishError.d.ts +26 -0
  119. package/dist/solverRelay/utils/parseFailedPublishError.js +39 -0
  120. package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
  121. package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
  122. package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
  123. package/dist/solverRelay/utils/quoteWithLog.js +21 -0
  124. package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
  125. package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
  126. package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
  127. package/dist/solverRelay/waitForIntentSettlement.js +52 -0
  128. package/dist/types/authHandle.cjs +22 -0
  129. package/dist/types/authHandle.d.cts +25 -0
  130. package/dist/types/authHandle.d.ts +25 -0
  131. package/dist/types/authHandle.js +16 -0
  132. package/dist/types/base.d.cts +45 -0
  133. package/dist/types/base.d.ts +45 -0
  134. package/dist/types/intentsUserId.d.cts +10 -0
  135. package/dist/types/intentsUserId.d.ts +10 -0
  136. package/dist/types/walletMessage.cjs +11 -0
  137. package/dist/types/walletMessage.d.cts +106 -0
  138. package/dist/types/walletMessage.d.ts +106 -0
  139. package/dist/types/walletMessage.js +5 -0
  140. package/dist/utils/abortSignal.cjs +19 -0
  141. package/dist/utils/abortSignal.js +18 -0
  142. package/dist/utils/appFee.cjs +20 -0
  143. package/dist/utils/appFee.d.cts +9 -0
  144. package/dist/utils/appFee.d.ts +9 -0
  145. package/dist/utils/appFee.js +15 -0
  146. package/dist/utils/assert.cjs +9 -0
  147. package/dist/utils/assert.d.cts +7 -0
  148. package/dist/utils/assert.d.ts +7 -0
  149. package/dist/utils/assert.js +9 -0
  150. package/dist/utils/authIdentity.cjs +56 -0
  151. package/dist/utils/authIdentity.d.cts +34 -0
  152. package/dist/utils/authIdentity.d.ts +34 -0
  153. package/dist/utils/authIdentity.js +50 -0
  154. package/dist/utils/failover.cjs +22 -0
  155. package/dist/utils/failover.d.cts +16 -0
  156. package/dist/utils/failover.d.ts +16 -0
  157. package/dist/utils/failover.js +20 -0
  158. package/dist/utils/handleRPCResponse.cjs +30 -0
  159. package/dist/utils/handleRPCResponse.js +28 -0
  160. package/dist/utils/index.cjs +55 -0
  161. package/dist/utils/index.d.cts +13 -0
  162. package/dist/utils/index.d.ts +13 -0
  163. package/dist/utils/index.js +50 -0
  164. package/dist/utils/messageFactory.cjs +137 -0
  165. package/dist/utils/messageFactory.d.cts +70 -0
  166. package/dist/utils/messageFactory.d.ts +70 -0
  167. package/dist/utils/messageFactory.js +132 -0
  168. package/dist/utils/multiPayload/webauthn.cjs +27 -0
  169. package/dist/utils/multiPayload/webauthn.js +26 -0
  170. package/dist/utils/near.cjs +58 -0
  171. package/dist/utils/near.d.cts +35 -0
  172. package/dist/utils/near.d.ts +35 -0
  173. package/dist/utils/near.js +53 -0
  174. package/dist/utils/poll.cjs +87 -0
  175. package/dist/utils/poll.d.cts +54 -0
  176. package/dist/utils/poll.d.ts +54 -0
  177. package/dist/utils/poll.js +85 -0
  178. package/dist/utils/prepareBroadcastRequest.cjs +98 -0
  179. package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
  180. package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
  181. package/dist/utils/prepareBroadcastRequest.js +90 -0
  182. package/dist/utils/promise/withTimeout.cjs +34 -0
  183. package/dist/utils/promise/withTimeout.d.cts +16 -0
  184. package/dist/utils/promise/withTimeout.d.ts +16 -0
  185. package/dist/utils/promise/withTimeout.js +34 -0
  186. package/dist/utils/request.cjs +100 -0
  187. package/dist/utils/request.d.cts +27 -0
  188. package/dist/utils/request.d.ts +27 -0
  189. package/dist/utils/request.js +99 -0
  190. package/dist/utils/requestShouldRetry.cjs +20 -0
  191. package/dist/utils/requestShouldRetry.js +20 -0
  192. package/dist/utils/retry.cjs +66 -0
  193. package/dist/utils/retry.d.cts +56 -0
  194. package/dist/utils/retry.d.ts +56 -0
  195. package/dist/utils/retry.js +64 -0
  196. package/dist/utils/serialize.cjs +82 -0
  197. package/dist/utils/serialize.d.cts +17 -0
  198. package/dist/utils/serialize.d.ts +17 -0
  199. package/dist/utils/serialize.js +81 -0
  200. package/dist/utils/stellarAddressToBytes.cjs +295 -0
  201. package/dist/utils/stellarAddressToBytes.js +294 -0
  202. package/dist/utils/token.cjs +8 -0
  203. package/dist/utils/token.js +7 -0
  204. package/dist/utils/tokenUtils.cjs +263 -0
  205. package/dist/utils/tokenUtils.d.cts +88 -0
  206. package/dist/utils/tokenUtils.d.ts +88 -0
  207. package/dist/utils/tokenUtils.js +238 -0
  208. package/dist/utils/tronAddressToHex.cjs +18 -0
  209. package/dist/utils/tronAddressToHex.js +17 -0
  210. package/dist/utils/uint8Array.cjs +15 -0
  211. package/dist/utils/uint8Array.d.cts +4 -0
  212. package/dist/utils/uint8Array.d.ts +4 -0
  213. package/dist/utils/uint8Array.js +14 -0
  214. package/dist/utils/webAuthn.cjs +91 -0
  215. package/dist/utils/webAuthn.js +89 -0
  216. package/package.json +56 -0
@@ -0,0 +1,99 @@
1
+ import { HttpRequestError, TimeoutError } from "../errors/request.js";
2
+ import { isNetworkError } from "../errors/utils/isNetworkError.js";
3
+ import { toError } from "../errors/utils/toError.js";
4
+ import { mergeAbortSignals } from "./abortSignal.js";
5
+ import { withTimeout } from "./promise/withTimeout.js";
6
+ import { requestShouldRetry } from "./requestShouldRetry.js";
7
+ import { retry } from "@lifeomic/attempt";
8
+
9
+ //#region src/utils/request.ts
10
+ async function request({ retryOptions = { maxAttempts: 1 }, logger, ...params }) {
11
+ const overallStartTime = performance.now();
12
+ let totalNetworkTime = 0;
13
+ let attemptCount = 0;
14
+ const response = await retry(async (ctx) => {
15
+ attemptCount = ctx.attemptNum + 1;
16
+ const attemptStartTime = performance.now();
17
+ logger?.debug("Sending HTTP request", {
18
+ url: params.url.toString(),
19
+ method: params.fetchOptions?.method || "GET",
20
+ body: JSON.stringify(params.body),
21
+ attempt: ctx.attemptNum
22
+ });
23
+ const response$1 = await request_(params);
24
+ const attemptDuration = performance.now() - attemptStartTime;
25
+ totalNetworkTime += attemptDuration;
26
+ logger?.debug("HTTP request attempt completed", {
27
+ attempt: ctx.attemptNum,
28
+ attemptDuration: Math.floor(attemptDuration),
29
+ statusCode: response$1.status,
30
+ success: response$1.ok,
31
+ responseSize: response$1.headers.get("content-length")
32
+ });
33
+ return response$1;
34
+ }, {
35
+ ...retryOptions,
36
+ handleError: (err, context) => {
37
+ logger?.error("HTTP request attempt failed", {
38
+ attempt: context.attemptNum,
39
+ errorMessage: toError(err).message
40
+ });
41
+ if (!requestShouldRetry(err) || params.fetchOptions?.signal?.reason === err) context.abort();
42
+ }
43
+ });
44
+ const overallDuration = performance.now() - overallStartTime;
45
+ const retryOverhead = overallDuration - totalNetworkTime;
46
+ logger?.[attemptCount > 1 ? "info" : "debug"]("HTTP request completed", {
47
+ statusCode: response.status,
48
+ success: response.ok,
49
+ totalDuration: Math.floor(overallDuration),
50
+ networkTime: Math.floor(totalNetworkTime),
51
+ retryOverhead: Math.floor(retryOverhead),
52
+ attempts: attemptCount,
53
+ responseSize: response.headers.get("content-length")
54
+ });
55
+ return response;
56
+ }
57
+ async function request_({ url, body, timeout = 1e4, fetchOptions }) {
58
+ const { headers: customHeaders, method, signal: signal_ } = fetchOptions ?? {};
59
+ try {
60
+ const headers = new Headers(customHeaders);
61
+ headers.set("Content-Type", "application/json");
62
+ const response = await withTimeout(({ signal }) => {
63
+ return fetch(url, {
64
+ ...fetchOptions,
65
+ method,
66
+ headers,
67
+ body: JSON.stringify(body),
68
+ signal: mergeAbortSignals([signal_, timeout > 0 ? signal : null].filter(Boolean))
69
+ });
70
+ }, {
71
+ errorInstance: new TimeoutError({
72
+ body,
73
+ url: url.toString()
74
+ }),
75
+ timeout,
76
+ signal: true
77
+ });
78
+ if (!response.ok) throw new HttpRequestError({
79
+ body,
80
+ details: response.statusText,
81
+ headers: response.headers,
82
+ status: response.status,
83
+ url: url.toString()
84
+ });
85
+ return response;
86
+ } catch (err) {
87
+ if (err instanceof HttpRequestError) throw err;
88
+ if (err instanceof TimeoutError) throw err;
89
+ if (isNetworkError(err)) throw new HttpRequestError({
90
+ body,
91
+ cause: err,
92
+ url: url.toString()
93
+ });
94
+ throw err;
95
+ }
96
+ }
97
+
98
+ //#endregion
99
+ export { request };
@@ -0,0 +1,20 @@
1
+ const require_request = require('../errors/request.cjs');
2
+
3
+ //#region src/utils/requestShouldRetry.ts
4
+ function requestShouldRetry(error) {
5
+ if (error instanceof require_request.HttpRequestError && error.status != null) {
6
+ if (error.status === 403) return true;
7
+ if (error.status === 408) return true;
8
+ if (error.status === 413) return true;
9
+ if (error.status === 429) return true;
10
+ if (error.status === 500) return true;
11
+ if (error.status === 502) return true;
12
+ if (error.status === 503) return true;
13
+ if (error.status === 504) return true;
14
+ return false;
15
+ }
16
+ return true;
17
+ }
18
+
19
+ //#endregion
20
+ exports.requestShouldRetry = requestShouldRetry;
@@ -0,0 +1,20 @@
1
+ import { HttpRequestError } from "../errors/request.js";
2
+
3
+ //#region src/utils/requestShouldRetry.ts
4
+ function requestShouldRetry(error) {
5
+ if (error instanceof HttpRequestError && error.status != null) {
6
+ if (error.status === 403) return true;
7
+ if (error.status === 408) return true;
8
+ if (error.status === 413) return true;
9
+ if (error.status === 429) return true;
10
+ if (error.status === 500) return true;
11
+ if (error.status === 502) return true;
12
+ if (error.status === 503) return true;
13
+ if (error.status === 504) return true;
14
+ return false;
15
+ }
16
+ return true;
17
+ }
18
+
19
+ //#endregion
20
+ export { requestShouldRetry };
@@ -0,0 +1,66 @@
1
+
2
+ //#region src/utils/retry.ts
3
+ const RETRY_CONFIGS = {
4
+ THIRTY_SECS_AGGRESSIVE: {
5
+ delay: 500,
6
+ minDelay: 500,
7
+ factor: 2,
8
+ maxAttempts: 6,
9
+ jitter: true
10
+ },
11
+ ONE_MIN_MODERATE: {
12
+ delay: 1e3,
13
+ minDelay: 1e3,
14
+ factor: 1.5,
15
+ maxAttempts: 8,
16
+ jitter: true
17
+ },
18
+ TWO_MINS_GRADUAL: {
19
+ delay: 500,
20
+ minDelay: 500,
21
+ factor: 1.5,
22
+ maxAttempts: 12,
23
+ jitter: true
24
+ },
25
+ FIVE_MINS_STEADY: {
26
+ delay: 2e3,
27
+ minDelay: 2e3,
28
+ factor: 1.4,
29
+ maxAttempts: 12,
30
+ jitter: true
31
+ },
32
+ THIRTY_MINS_PATIENT: {
33
+ delay: 5e3,
34
+ minDelay: 5e3,
35
+ factor: 1.3,
36
+ maxAttempts: 18,
37
+ jitter: true
38
+ },
39
+ TWO_HOURS_PERSISTENT: {
40
+ delay: 1e4,
41
+ minDelay: 1e4,
42
+ factor: 1.2,
43
+ maxAttempts: 27,
44
+ jitter: true
45
+ }
46
+ };
47
+ /**
48
+ * Calculates how many attempts fit within a timeout budget.
49
+ *
50
+ * @returns number of attempts that fit within the timeout
51
+ */
52
+ function calculateMaxAttempts(timeout, delay, factor) {
53
+ let totalDelay = 0;
54
+ let currentDelay = delay;
55
+ let attempts = 1;
56
+ while (totalDelay + currentDelay <= timeout) {
57
+ totalDelay += currentDelay;
58
+ attempts++;
59
+ currentDelay *= factor;
60
+ }
61
+ return Math.max(1, attempts);
62
+ }
63
+
64
+ //#endregion
65
+ exports.RETRY_CONFIGS = RETRY_CONFIGS;
66
+ exports.calculateMaxAttempts = calculateMaxAttempts;
@@ -0,0 +1,56 @@
1
+ import { AttemptOptions } from "@lifeomic/attempt";
2
+
3
+ //#region src/utils/retry.d.ts
4
+ type RetryOptions = Partial<Pick<AttemptOptions<unknown>, "delay" | "initialDelay" | "minDelay" | "maxDelay" | "factor" | "maxAttempts" | "timeout" | "jitter" | "initialJitter">>;
5
+ declare const RETRY_CONFIGS: {
6
+ THIRTY_SECS_AGGRESSIVE: {
7
+ delay: number;
8
+ minDelay: number;
9
+ factor: number;
10
+ maxAttempts: number;
11
+ jitter: boolean;
12
+ };
13
+ ONE_MIN_MODERATE: {
14
+ delay: number;
15
+ minDelay: number;
16
+ factor: number;
17
+ maxAttempts: number;
18
+ jitter: boolean;
19
+ };
20
+ TWO_MINS_GRADUAL: {
21
+ delay: number;
22
+ minDelay: number;
23
+ factor: number;
24
+ maxAttempts: number;
25
+ jitter: boolean;
26
+ };
27
+ FIVE_MINS_STEADY: {
28
+ delay: number;
29
+ minDelay: number;
30
+ factor: number;
31
+ maxAttempts: number;
32
+ jitter: boolean;
33
+ };
34
+ THIRTY_MINS_PATIENT: {
35
+ delay: number;
36
+ minDelay: number;
37
+ factor: number;
38
+ maxAttempts: number;
39
+ jitter: boolean;
40
+ };
41
+ TWO_HOURS_PERSISTENT: {
42
+ delay: number;
43
+ minDelay: number;
44
+ factor: number;
45
+ maxAttempts: number;
46
+ jitter: boolean;
47
+ };
48
+ };
49
+ /**
50
+ * Calculates how many attempts fit within a timeout budget.
51
+ *
52
+ * @returns number of attempts that fit within the timeout
53
+ */
54
+ declare function calculateMaxAttempts(timeout: number, delay: number, factor: number): number;
55
+ //#endregion
56
+ export { RETRY_CONFIGS, RetryOptions, calculateMaxAttempts };
@@ -0,0 +1,56 @@
1
+ import { AttemptOptions } from "@lifeomic/attempt";
2
+
3
+ //#region src/utils/retry.d.ts
4
+ type RetryOptions = Partial<Pick<AttemptOptions<unknown>, "delay" | "initialDelay" | "minDelay" | "maxDelay" | "factor" | "maxAttempts" | "timeout" | "jitter" | "initialJitter">>;
5
+ declare const RETRY_CONFIGS: {
6
+ THIRTY_SECS_AGGRESSIVE: {
7
+ delay: number;
8
+ minDelay: number;
9
+ factor: number;
10
+ maxAttempts: number;
11
+ jitter: boolean;
12
+ };
13
+ ONE_MIN_MODERATE: {
14
+ delay: number;
15
+ minDelay: number;
16
+ factor: number;
17
+ maxAttempts: number;
18
+ jitter: boolean;
19
+ };
20
+ TWO_MINS_GRADUAL: {
21
+ delay: number;
22
+ minDelay: number;
23
+ factor: number;
24
+ maxAttempts: number;
25
+ jitter: boolean;
26
+ };
27
+ FIVE_MINS_STEADY: {
28
+ delay: number;
29
+ minDelay: number;
30
+ factor: number;
31
+ maxAttempts: number;
32
+ jitter: boolean;
33
+ };
34
+ THIRTY_MINS_PATIENT: {
35
+ delay: number;
36
+ minDelay: number;
37
+ factor: number;
38
+ maxAttempts: number;
39
+ jitter: boolean;
40
+ };
41
+ TWO_HOURS_PERSISTENT: {
42
+ delay: number;
43
+ minDelay: number;
44
+ factor: number;
45
+ maxAttempts: number;
46
+ jitter: boolean;
47
+ };
48
+ };
49
+ /**
50
+ * Calculates how many attempts fit within a timeout budget.
51
+ *
52
+ * @returns number of attempts that fit within the timeout
53
+ */
54
+ declare function calculateMaxAttempts(timeout: number, delay: number, factor: number): number;
55
+ //#endregion
56
+ export { RETRY_CONFIGS, RetryOptions, calculateMaxAttempts };
@@ -0,0 +1,64 @@
1
+ //#region src/utils/retry.ts
2
+ const RETRY_CONFIGS = {
3
+ THIRTY_SECS_AGGRESSIVE: {
4
+ delay: 500,
5
+ minDelay: 500,
6
+ factor: 2,
7
+ maxAttempts: 6,
8
+ jitter: true
9
+ },
10
+ ONE_MIN_MODERATE: {
11
+ delay: 1e3,
12
+ minDelay: 1e3,
13
+ factor: 1.5,
14
+ maxAttempts: 8,
15
+ jitter: true
16
+ },
17
+ TWO_MINS_GRADUAL: {
18
+ delay: 500,
19
+ minDelay: 500,
20
+ factor: 1.5,
21
+ maxAttempts: 12,
22
+ jitter: true
23
+ },
24
+ FIVE_MINS_STEADY: {
25
+ delay: 2e3,
26
+ minDelay: 2e3,
27
+ factor: 1.4,
28
+ maxAttempts: 12,
29
+ jitter: true
30
+ },
31
+ THIRTY_MINS_PATIENT: {
32
+ delay: 5e3,
33
+ minDelay: 5e3,
34
+ factor: 1.3,
35
+ maxAttempts: 18,
36
+ jitter: true
37
+ },
38
+ TWO_HOURS_PERSISTENT: {
39
+ delay: 1e4,
40
+ minDelay: 1e4,
41
+ factor: 1.2,
42
+ maxAttempts: 27,
43
+ jitter: true
44
+ }
45
+ };
46
+ /**
47
+ * Calculates how many attempts fit within a timeout budget.
48
+ *
49
+ * @returns number of attempts that fit within the timeout
50
+ */
51
+ function calculateMaxAttempts(timeout, delay, factor) {
52
+ let totalDelay = 0;
53
+ let currentDelay = delay;
54
+ let attempts = 1;
55
+ while (totalDelay + currentDelay <= timeout) {
56
+ totalDelay += currentDelay;
57
+ attempts++;
58
+ currentDelay *= factor;
59
+ }
60
+ return Math.max(1, attempts);
61
+ }
62
+
63
+ //#endregion
64
+ export { RETRY_CONFIGS, calculateMaxAttempts };
@@ -0,0 +1,82 @@
1
+
2
+ //#region src/utils/serialize.ts
3
+ /**
4
+ * Get the reference key for the circular value
5
+ *
6
+ * @param keys the keys to build the reference key from
7
+ * @param cutoff the maximum number of keys to include
8
+ * @returns the reference key
9
+ */
10
+ function getReferenceKey(keys, cutoff) {
11
+ return keys.slice(0, cutoff).join(".") || ".";
12
+ }
13
+ /**
14
+ * Faster `Array.prototype.indexOf` implementation build for slicing / splicing
15
+ *
16
+ * @param array the array to match the value in
17
+ * @param value the value to match
18
+ * @returns the matching index, or -1
19
+ */
20
+ function getCutoff(array, value) {
21
+ const { length } = array;
22
+ for (let index = 0; index < length; ++index) if (array[index] === value) return index + 1;
23
+ return 0;
24
+ }
25
+ /**
26
+ * Create a replacer method that handles circular values
27
+ *
28
+ * @param [replacer] a custom replacer to use for non-circular values
29
+ * @param [circularReplacer] a custom replacer to use for circular methods
30
+ * @returns the value to stringify
31
+ */
32
+ function createReplacer(replacer, circularReplacer) {
33
+ const hasReplacer = typeof replacer === "function";
34
+ const hasCircularReplacer = typeof circularReplacer === "function";
35
+ const cache = [];
36
+ const keys = [];
37
+ return function replace(key, value) {
38
+ if (typeof value === "object") if (cache.length) {
39
+ const thisCutoff = getCutoff(cache, this);
40
+ if (thisCutoff === 0) cache[cache.length] = this;
41
+ else {
42
+ cache.splice(thisCutoff);
43
+ keys.splice(thisCutoff);
44
+ }
45
+ keys[keys.length] = key;
46
+ const valueCutoff = getCutoff(cache, value);
47
+ if (valueCutoff !== 0) return hasCircularReplacer ? circularReplacer.call(this, key, value, getReferenceKey(keys, valueCutoff)) : `[ref=${getReferenceKey(keys, valueCutoff)}]`;
48
+ } else {
49
+ cache[0] = value;
50
+ keys[0] = key;
51
+ }
52
+ return hasReplacer ? replacer.call(this, key, value) : value;
53
+ };
54
+ }
55
+ /**
56
+ * Stringifier that handles circular values
57
+ *
58
+ * Forked from https://github.com/planttheidea/fast-stringify
59
+ *
60
+ * @param value to stringify
61
+ * @param [replacer] a custom replacer function for handling standard values
62
+ * @param [indent] the number of spaces to indent the output by
63
+ * @param [circularReplacer] a custom replacer function for handling circular values
64
+ * @returns the stringified output
65
+ */
66
+ function serialize(value, replacer, indent, circularReplacer) {
67
+ return JSON.stringify(value, createReplacer((key, value_) => {
68
+ let value$1 = value_;
69
+ if (typeof value$1 === "bigint") value$1 = {
70
+ __type: "bigint",
71
+ value: value_.toString()
72
+ };
73
+ if (value$1 instanceof Map) value$1 = {
74
+ __type: "Map",
75
+ value: Array.from(value_.entries())
76
+ };
77
+ return replacer?.(key, value$1) ?? value$1;
78
+ }, circularReplacer), indent ?? void 0);
79
+ }
80
+
81
+ //#endregion
82
+ exports.serialize = serialize;
@@ -0,0 +1,17 @@
1
+ //#region src/utils/serialize.d.ts
2
+ type StandardReplacer = (key: string, value: any) => any;
3
+ type CircularReplacer = (key: string, value: any, referenceKey: string) => any;
4
+ /**
5
+ * Stringifier that handles circular values
6
+ *
7
+ * Forked from https://github.com/planttheidea/fast-stringify
8
+ *
9
+ * @param value to stringify
10
+ * @param [replacer] a custom replacer function for handling standard values
11
+ * @param [indent] the number of spaces to indent the output by
12
+ * @param [circularReplacer] a custom replacer function for handling circular values
13
+ * @returns the stringified output
14
+ */
15
+ declare function serialize(value: any, replacer?: StandardReplacer | null | undefined, indent?: number | null | undefined, circularReplacer?: CircularReplacer | null | undefined): string;
16
+ //#endregion
17
+ export { serialize };
@@ -0,0 +1,17 @@
1
+ //#region src/utils/serialize.d.ts
2
+ type StandardReplacer = (key: string, value: any) => any;
3
+ type CircularReplacer = (key: string, value: any, referenceKey: string) => any;
4
+ /**
5
+ * Stringifier that handles circular values
6
+ *
7
+ * Forked from https://github.com/planttheidea/fast-stringify
8
+ *
9
+ * @param value to stringify
10
+ * @param [replacer] a custom replacer function for handling standard values
11
+ * @param [indent] the number of spaces to indent the output by
12
+ * @param [circularReplacer] a custom replacer function for handling circular values
13
+ * @returns the stringified output
14
+ */
15
+ declare function serialize(value: any, replacer?: StandardReplacer | null | undefined, indent?: number | null | undefined, circularReplacer?: CircularReplacer | null | undefined): string;
16
+ //#endregion
17
+ export { serialize };
@@ -0,0 +1,81 @@
1
+ //#region src/utils/serialize.ts
2
+ /**
3
+ * Get the reference key for the circular value
4
+ *
5
+ * @param keys the keys to build the reference key from
6
+ * @param cutoff the maximum number of keys to include
7
+ * @returns the reference key
8
+ */
9
+ function getReferenceKey(keys, cutoff) {
10
+ return keys.slice(0, cutoff).join(".") || ".";
11
+ }
12
+ /**
13
+ * Faster `Array.prototype.indexOf` implementation build for slicing / splicing
14
+ *
15
+ * @param array the array to match the value in
16
+ * @param value the value to match
17
+ * @returns the matching index, or -1
18
+ */
19
+ function getCutoff(array, value) {
20
+ const { length } = array;
21
+ for (let index = 0; index < length; ++index) if (array[index] === value) return index + 1;
22
+ return 0;
23
+ }
24
+ /**
25
+ * Create a replacer method that handles circular values
26
+ *
27
+ * @param [replacer] a custom replacer to use for non-circular values
28
+ * @param [circularReplacer] a custom replacer to use for circular methods
29
+ * @returns the value to stringify
30
+ */
31
+ function createReplacer(replacer, circularReplacer) {
32
+ const hasReplacer = typeof replacer === "function";
33
+ const hasCircularReplacer = typeof circularReplacer === "function";
34
+ const cache = [];
35
+ const keys = [];
36
+ return function replace(key, value) {
37
+ if (typeof value === "object") if (cache.length) {
38
+ const thisCutoff = getCutoff(cache, this);
39
+ if (thisCutoff === 0) cache[cache.length] = this;
40
+ else {
41
+ cache.splice(thisCutoff);
42
+ keys.splice(thisCutoff);
43
+ }
44
+ keys[keys.length] = key;
45
+ const valueCutoff = getCutoff(cache, value);
46
+ if (valueCutoff !== 0) return hasCircularReplacer ? circularReplacer.call(this, key, value, getReferenceKey(keys, valueCutoff)) : `[ref=${getReferenceKey(keys, valueCutoff)}]`;
47
+ } else {
48
+ cache[0] = value;
49
+ keys[0] = key;
50
+ }
51
+ return hasReplacer ? replacer.call(this, key, value) : value;
52
+ };
53
+ }
54
+ /**
55
+ * Stringifier that handles circular values
56
+ *
57
+ * Forked from https://github.com/planttheidea/fast-stringify
58
+ *
59
+ * @param value to stringify
60
+ * @param [replacer] a custom replacer function for handling standard values
61
+ * @param [indent] the number of spaces to indent the output by
62
+ * @param [circularReplacer] a custom replacer function for handling circular values
63
+ * @returns the stringified output
64
+ */
65
+ function serialize(value, replacer, indent, circularReplacer) {
66
+ return JSON.stringify(value, createReplacer((key, value_) => {
67
+ let value$1 = value_;
68
+ if (typeof value$1 === "bigint") value$1 = {
69
+ __type: "bigint",
70
+ value: value_.toString()
71
+ };
72
+ if (value$1 instanceof Map) value$1 = {
73
+ __type: "Map",
74
+ value: Array.from(value_.entries())
75
+ };
76
+ return replacer?.(key, value$1) ?? value$1;
77
+ }, circularReplacer), indent ?? void 0);
78
+ }
79
+
80
+ //#endregion
81
+ export { serialize };