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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 NEAR Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,43 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __exportAll = (all, symbols) => {
9
+ let target = {};
10
+ for (var name in all) {
11
+ __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ }
16
+ if (symbols) {
17
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
18
+ }
19
+ return target;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
+ key = keys[i];
25
+ if (!__hasOwnProp.call(to, key) && key !== except) {
26
+ __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ }
32
+ }
33
+ return to;
34
+ };
35
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
36
+ value: mod,
37
+ enumerable: true
38
+ }) : target, mod));
39
+
40
+ //#endregion
41
+
42
+ exports.__exportAll = __exportAll;
43
+ exports.__toESM = __toESM;
@@ -0,0 +1,18 @@
1
+ //#region rolldown:runtime
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __exportAll };
@@ -0,0 +1,82 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let valibot = require("valibot");
3
+ valibot = require_rolldown_runtime.__toESM(valibot);
4
+
5
+ //#region src/config.ts
6
+ const optionalUrlSchema = valibot.pipe(valibot.string(), valibot.check((value) => value === "" || URL.canParse(value), "must be a valid URL or empty string"));
7
+ const envConfigSchema = valibot.object({
8
+ contractID: valibot.pipe(valibot.string(), valibot.minLength(1, "contractID is required")),
9
+ poaTokenFactoryContractID: valibot.string(),
10
+ poaBridgeBaseURL: optionalUrlSchema,
11
+ solverRelayBaseURL: optionalUrlSchema,
12
+ managerConsoleBaseURL: optionalUrlSchema,
13
+ nearIntentsBaseURL: optionalUrlSchema
14
+ });
15
+ /**
16
+ * Resolves environment configuration from either a preset name or custom config.
17
+ * Defaults to "production" if no env is provided.
18
+ *
19
+ * @param env - Either "production"/"stage" preset name, or a custom EnvConfig object
20
+ * @returns Resolved EnvConfig
21
+ * @throws Error if custom config fails validation
22
+ */
23
+ function resolveEnvConfig(env) {
24
+ if (env === void 0) return configsByEnvironment.production;
25
+ if (typeof env === "string") return configsByEnvironment[env];
26
+ const result = valibot.safeParse(envConfigSchema, env);
27
+ if (!result.success) {
28
+ const issues = result.issues.map((issue) => `${issue.path?.map((p) => p.key).join(".")}: ${issue.message}`).join(", ");
29
+ throw new Error(`Invalid EnvConfig: ${issues}`);
30
+ }
31
+ return result.output;
32
+ }
33
+ const configsByEnvironment = {
34
+ production: {
35
+ contractID: "intents.near",
36
+ poaTokenFactoryContractID: "omft.near",
37
+ poaBridgeBaseURL: "https://bridge.chaindefuser.com",
38
+ solverRelayBaseURL: "https://solver-relay-v2.chaindefuser.com",
39
+ managerConsoleBaseURL: "https://api-mng-console.chaindefuser.com/api/",
40
+ nearIntentsBaseURL: "https://near-intents.org/api/"
41
+ },
42
+ stage: {
43
+ contractID: "staging-intents.near",
44
+ poaTokenFactoryContractID: "stft.near",
45
+ poaBridgeBaseURL: "https://poa-stage.intents-near.org",
46
+ solverRelayBaseURL: "https://solver-relay-stage.intents-near.org",
47
+ managerConsoleBaseURL: "https://mng-console-stage.intents-near.org/api/",
48
+ nearIntentsBaseURL: "https://stage.near-intents.org/api/"
49
+ }
50
+ };
51
+ let config = {
52
+ env: configsByEnvironment.production,
53
+ features: { hyperliquid: false }
54
+ };
55
+ function configureSDK({ env, features, environments }) {
56
+ if (environments) for (const [key, value] of Object.entries(environments)) configsByEnvironment[key] = {
57
+ ...configsByEnvironment[key],
58
+ ...value
59
+ };
60
+ if (env !== void 0) config = {
61
+ ...config,
62
+ env: resolveEnvConfig(env)
63
+ };
64
+ config = {
65
+ ...config,
66
+ features: {
67
+ ...config.features,
68
+ ...features
69
+ }
70
+ };
71
+ }
72
+
73
+ //#endregion
74
+ Object.defineProperty(exports, 'config', {
75
+ enumerable: true,
76
+ get: function () {
77
+ return config;
78
+ }
79
+ });
80
+ exports.configsByEnvironment = configsByEnvironment;
81
+ exports.configureSDK = configureSDK;
82
+ exports.resolveEnvConfig = resolveEnvConfig;
@@ -0,0 +1,42 @@
1
+ import { ILogger } from "./logger.cjs";
2
+
3
+ //#region src/config.d.ts
4
+ interface SDKConfig {
5
+ logger?: ILogger;
6
+ env: EnvConfig;
7
+ features: {
8
+ hyperliquid: boolean;
9
+ };
10
+ }
11
+ interface EnvConfig {
12
+ contractID: string;
13
+ poaTokenFactoryContractID: string;
14
+ poaBridgeBaseURL: string;
15
+ solverRelayBaseURL: string;
16
+ managerConsoleBaseURL: string;
17
+ nearIntentsBaseURL: string;
18
+ }
19
+ type NearIntentsEnv = "production" | "stage";
20
+ /**
21
+ * Resolves environment configuration from either a preset name or custom config.
22
+ * Defaults to "production" if no env is provided.
23
+ *
24
+ * @param env - Either "production"/"stage" preset name, or a custom EnvConfig object
25
+ * @returns Resolved EnvConfig
26
+ * @throws Error if custom config fails validation
27
+ */
28
+ declare function resolveEnvConfig(env: NearIntentsEnv | EnvConfig | undefined): EnvConfig;
29
+ declare const configsByEnvironment: Record<NearIntentsEnv, EnvConfig>;
30
+ declare let config: SDKConfig;
31
+ interface ConfigureSDKArgs {
32
+ env?: EnvConfig | NearIntentsEnv;
33
+ features?: { [K in keyof SDKConfig["features"]]?: boolean };
34
+ environments?: Record<NearIntentsEnv, Partial<EnvConfig>>;
35
+ }
36
+ declare function configureSDK({
37
+ env,
38
+ features,
39
+ environments
40
+ }: ConfigureSDKArgs): void;
41
+ //#endregion
42
+ export { EnvConfig, NearIntentsEnv, config, configsByEnvironment, configureSDK, resolveEnvConfig };
@@ -0,0 +1,42 @@
1
+ import { ILogger } from "./logger.js";
2
+
3
+ //#region src/config.d.ts
4
+ interface SDKConfig {
5
+ logger?: ILogger;
6
+ env: EnvConfig;
7
+ features: {
8
+ hyperliquid: boolean;
9
+ };
10
+ }
11
+ interface EnvConfig {
12
+ contractID: string;
13
+ poaTokenFactoryContractID: string;
14
+ poaBridgeBaseURL: string;
15
+ solverRelayBaseURL: string;
16
+ managerConsoleBaseURL: string;
17
+ nearIntentsBaseURL: string;
18
+ }
19
+ type NearIntentsEnv = "production" | "stage";
20
+ /**
21
+ * Resolves environment configuration from either a preset name or custom config.
22
+ * Defaults to "production" if no env is provided.
23
+ *
24
+ * @param env - Either "production"/"stage" preset name, or a custom EnvConfig object
25
+ * @returns Resolved EnvConfig
26
+ * @throws Error if custom config fails validation
27
+ */
28
+ declare function resolveEnvConfig(env: NearIntentsEnv | EnvConfig | undefined): EnvConfig;
29
+ declare const configsByEnvironment: Record<NearIntentsEnv, EnvConfig>;
30
+ declare let config: SDKConfig;
31
+ interface ConfigureSDKArgs {
32
+ env?: EnvConfig | NearIntentsEnv;
33
+ features?: { [K in keyof SDKConfig["features"]]?: boolean };
34
+ environments?: Record<NearIntentsEnv, Partial<EnvConfig>>;
35
+ }
36
+ declare function configureSDK({
37
+ env,
38
+ features,
39
+ environments
40
+ }: ConfigureSDKArgs): void;
41
+ //#endregion
42
+ export { EnvConfig, NearIntentsEnv, config, configsByEnvironment, configureSDK, resolveEnvConfig };
package/dist/config.js ADDED
@@ -0,0 +1,72 @@
1
+ import * as v from "valibot";
2
+
3
+ //#region src/config.ts
4
+ const optionalUrlSchema = v.pipe(v.string(), v.check((value) => value === "" || URL.canParse(value), "must be a valid URL or empty string"));
5
+ const envConfigSchema = v.object({
6
+ contractID: v.pipe(v.string(), v.minLength(1, "contractID is required")),
7
+ poaTokenFactoryContractID: v.string(),
8
+ poaBridgeBaseURL: optionalUrlSchema,
9
+ solverRelayBaseURL: optionalUrlSchema,
10
+ managerConsoleBaseURL: optionalUrlSchema,
11
+ nearIntentsBaseURL: optionalUrlSchema
12
+ });
13
+ /**
14
+ * Resolves environment configuration from either a preset name or custom config.
15
+ * Defaults to "production" if no env is provided.
16
+ *
17
+ * @param env - Either "production"/"stage" preset name, or a custom EnvConfig object
18
+ * @returns Resolved EnvConfig
19
+ * @throws Error if custom config fails validation
20
+ */
21
+ function resolveEnvConfig(env) {
22
+ if (env === void 0) return configsByEnvironment.production;
23
+ if (typeof env === "string") return configsByEnvironment[env];
24
+ const result = v.safeParse(envConfigSchema, env);
25
+ if (!result.success) {
26
+ const issues = result.issues.map((issue) => `${issue.path?.map((p) => p.key).join(".")}: ${issue.message}`).join(", ");
27
+ throw new Error(`Invalid EnvConfig: ${issues}`);
28
+ }
29
+ return result.output;
30
+ }
31
+ const configsByEnvironment = {
32
+ production: {
33
+ contractID: "intents.near",
34
+ poaTokenFactoryContractID: "omft.near",
35
+ poaBridgeBaseURL: "https://bridge.chaindefuser.com",
36
+ solverRelayBaseURL: "https://solver-relay-v2.chaindefuser.com",
37
+ managerConsoleBaseURL: "https://api-mng-console.chaindefuser.com/api/",
38
+ nearIntentsBaseURL: "https://near-intents.org/api/"
39
+ },
40
+ stage: {
41
+ contractID: "staging-intents.near",
42
+ poaTokenFactoryContractID: "stft.near",
43
+ poaBridgeBaseURL: "https://poa-stage.intents-near.org",
44
+ solverRelayBaseURL: "https://solver-relay-stage.intents-near.org",
45
+ managerConsoleBaseURL: "https://mng-console-stage.intents-near.org/api/",
46
+ nearIntentsBaseURL: "https://stage.near-intents.org/api/"
47
+ }
48
+ };
49
+ let config = {
50
+ env: configsByEnvironment.production,
51
+ features: { hyperliquid: false }
52
+ };
53
+ function configureSDK({ env, features, environments }) {
54
+ if (environments) for (const [key, value] of Object.entries(environments)) configsByEnvironment[key] = {
55
+ ...configsByEnvironment[key],
56
+ ...value
57
+ };
58
+ if (env !== void 0) config = {
59
+ ...config,
60
+ env: resolveEnvConfig(env)
61
+ };
62
+ config = {
63
+ ...config,
64
+ features: {
65
+ ...config.features,
66
+ ...features
67
+ }
68
+ };
69
+ }
70
+
71
+ //#endregion
72
+ export { config, configsByEnvironment, configureSDK, resolveEnvConfig };
@@ -0,0 +1,11 @@
1
+ const require_base = require('./base.cjs');
2
+
3
+ //#region src/errors/assert.ts
4
+ var AssertionError = class extends require_base.BaseError {
5
+ constructor(message) {
6
+ super(message || "Assertion failed", { name: "AssertionError" });
7
+ }
8
+ };
9
+
10
+ //#endregion
11
+ exports.AssertionError = AssertionError;
@@ -0,0 +1,11 @@
1
+ import { BaseError } from "./base.cjs";
2
+
3
+ //#region src/errors/assert.d.ts
4
+ type AssertionErrorType = AssertionError & {
5
+ name: "AssertionError";
6
+ };
7
+ declare class AssertionError extends BaseError {
8
+ constructor(message: string | undefined);
9
+ }
10
+ //#endregion
11
+ export { AssertionError, AssertionErrorType };
@@ -0,0 +1,11 @@
1
+ import { BaseError } from "./base.js";
2
+
3
+ //#region src/errors/assert.d.ts
4
+ type AssertionErrorType = AssertionError & {
5
+ name: "AssertionError";
6
+ };
7
+ declare class AssertionError extends BaseError {
8
+ constructor(message: string | undefined);
9
+ }
10
+ //#endregion
11
+ export { AssertionError, AssertionErrorType };
@@ -0,0 +1,11 @@
1
+ import { BaseError } from "./base.js";
2
+
3
+ //#region src/errors/assert.ts
4
+ var AssertionError = class extends BaseError {
5
+ constructor(message) {
6
+ super(message || "Assertion failed", { name: "AssertionError" });
7
+ }
8
+ };
9
+
10
+ //#endregion
11
+ export { AssertionError };
@@ -0,0 +1,34 @@
1
+
2
+ //#region src/errors/base.ts
3
+ var BaseError = class BaseError extends Error {
4
+ constructor(shortMessage, args = {}) {
5
+ const details = (() => {
6
+ if (args.cause instanceof BaseError) return args.cause.details;
7
+ if (args.cause != null && typeof args.cause === "object" && "message" in args.cause && typeof args.cause.message === "string") return args.cause.message;
8
+ return args.details ?? "";
9
+ })();
10
+ const message = [
11
+ shortMessage || "An error occurred.",
12
+ "",
13
+ ...args.metaMessages ? [...args.metaMessages, ""] : [],
14
+ ...details ? [`Details: ${details}`] : []
15
+ ].join("\n");
16
+ super(message, args.cause ? { cause: args.cause } : void 0);
17
+ this.name = "BaseError";
18
+ this.details = details;
19
+ this.metaMessages = args.metaMessages;
20
+ this.name = args.name ?? this.name;
21
+ this.shortMessage = shortMessage;
22
+ }
23
+ walk(fn) {
24
+ return walk(this, fn);
25
+ }
26
+ };
27
+ function walk(err, fn) {
28
+ if (fn?.(err)) return err;
29
+ if (err && typeof err === "object" && "cause" in err && err.cause !== void 0) return walk(err.cause, fn);
30
+ return fn ? null : err;
31
+ }
32
+
33
+ //#endregion
34
+ exports.BaseError = BaseError;
@@ -0,0 +1,21 @@
1
+ //#region src/errors/base.d.ts
2
+ type BaseErrorParameters = {
3
+ cause?: unknown;
4
+ details?: string | undefined;
5
+ metaMessages?: string[] | undefined;
6
+ name?: string | undefined;
7
+ };
8
+ type BaseErrorType = BaseError & {
9
+ name: "BaseError";
10
+ };
11
+ declare class BaseError extends Error {
12
+ details: string;
13
+ metaMessages?: string[] | undefined;
14
+ shortMessage: string;
15
+ name: string;
16
+ constructor(shortMessage: string, args?: BaseErrorParameters);
17
+ walk(): Error;
18
+ walk(fn: (err: unknown) => boolean): Error | null;
19
+ }
20
+ //#endregion
21
+ export { BaseError, BaseErrorType };
@@ -0,0 +1,21 @@
1
+ //#region src/errors/base.d.ts
2
+ type BaseErrorParameters = {
3
+ cause?: unknown;
4
+ details?: string | undefined;
5
+ metaMessages?: string[] | undefined;
6
+ name?: string | undefined;
7
+ };
8
+ type BaseErrorType = BaseError & {
9
+ name: "BaseError";
10
+ };
11
+ declare class BaseError extends Error {
12
+ details: string;
13
+ metaMessages?: string[] | undefined;
14
+ shortMessage: string;
15
+ name: string;
16
+ constructor(shortMessage: string, args?: BaseErrorParameters);
17
+ walk(): Error;
18
+ walk(fn: (err: unknown) => boolean): Error | null;
19
+ }
20
+ //#endregion
21
+ export { BaseError, BaseErrorType };
@@ -0,0 +1,33 @@
1
+ //#region src/errors/base.ts
2
+ var BaseError = class BaseError extends Error {
3
+ constructor(shortMessage, args = {}) {
4
+ const details = (() => {
5
+ if (args.cause instanceof BaseError) return args.cause.details;
6
+ if (args.cause != null && typeof args.cause === "object" && "message" in args.cause && typeof args.cause.message === "string") return args.cause.message;
7
+ return args.details ?? "";
8
+ })();
9
+ const message = [
10
+ shortMessage || "An error occurred.",
11
+ "",
12
+ ...args.metaMessages ? [...args.metaMessages, ""] : [],
13
+ ...details ? [`Details: ${details}`] : []
14
+ ].join("\n");
15
+ super(message, args.cause ? { cause: args.cause } : void 0);
16
+ this.name = "BaseError";
17
+ this.details = details;
18
+ this.metaMessages = args.metaMessages;
19
+ this.name = args.name ?? this.name;
20
+ this.shortMessage = shortMessage;
21
+ }
22
+ walk(fn) {
23
+ return walk(this, fn);
24
+ }
25
+ };
26
+ function walk(err, fn) {
27
+ if (fn?.(err)) return err;
28
+ if (err && typeof err === "object" && "cause" in err && err.cause !== void 0) return walk(err.cause, fn);
29
+ return fn ? null : err;
30
+ }
31
+
32
+ //#endregion
33
+ export { BaseError };
@@ -0,0 +1,23 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_base = require('./base.cjs');
3
+ const require_request = require('./request.cjs');
4
+ const require_toError = require('./utils/toError.cjs');
5
+ const require_assert = require('./assert.cjs');
6
+
7
+ //#region src/errors/index.ts
8
+ var errors_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
9
+ AssertionError: () => require_assert.AssertionError,
10
+ BaseError: () => require_base.BaseError,
11
+ HttpRequestError: () => require_request.HttpRequestError,
12
+ RpcRequestError: () => require_request.RpcRequestError,
13
+ TimeoutError: () => require_request.TimeoutError,
14
+ toError: () => require_toError.toError
15
+ });
16
+
17
+ //#endregion
18
+ Object.defineProperty(exports, 'errors_exports', {
19
+ enumerable: true,
20
+ get: function () {
21
+ return errors_exports;
22
+ }
23
+ });
@@ -0,0 +1,11 @@
1
+ import { BaseError, BaseErrorType } from "./base.cjs";
2
+ import { HttpRequestError, HttpRequestErrorType, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "./request.cjs";
3
+ import { AssertionError, AssertionErrorType } from "./assert.cjs";
4
+ import { toError } from "./utils/toError.cjs";
5
+
6
+ //#region src/errors/index.d.ts
7
+ declare namespace index_d_exports {
8
+ export { AssertionError, AssertionErrorType, BaseError, BaseErrorType, HttpRequestError, HttpRequestErrorType, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType, toError };
9
+ }
10
+ //#endregion
11
+ export { index_d_exports };
@@ -0,0 +1,11 @@
1
+ import { BaseError, BaseErrorType } from "./base.js";
2
+ import { HttpRequestError, HttpRequestErrorType, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType } from "./request.js";
3
+ import { AssertionError, AssertionErrorType } from "./assert.js";
4
+ import { toError } from "./utils/toError.js";
5
+
6
+ //#region src/errors/index.d.ts
7
+ declare namespace index_d_exports {
8
+ export { AssertionError, AssertionErrorType, BaseError, BaseErrorType, HttpRequestError, HttpRequestErrorType, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType, toError };
9
+ }
10
+ //#endregion
11
+ export { index_d_exports };
@@ -0,0 +1,18 @@
1
+ import { __exportAll } from "../_virtual/rolldown_runtime.js";
2
+ import { BaseError } from "./base.js";
3
+ import { HttpRequestError, RpcRequestError, TimeoutError } from "./request.js";
4
+ import { toError } from "./utils/toError.js";
5
+ import { AssertionError } from "./assert.js";
6
+
7
+ //#region src/errors/index.ts
8
+ var errors_exports = /* @__PURE__ */ __exportAll({
9
+ AssertionError: () => AssertionError,
10
+ BaseError: () => BaseError,
11
+ HttpRequestError: () => HttpRequestError,
12
+ RpcRequestError: () => RpcRequestError,
13
+ TimeoutError: () => TimeoutError,
14
+ toError: () => toError
15
+ });
16
+
17
+ //#endregion
18
+ export { errors_exports };
@@ -0,0 +1,48 @@
1
+ const require_serialize = require('../utils/serialize.cjs');
2
+ const require_base = require('./base.cjs');
3
+
4
+ //#region src/errors/request.ts
5
+ var HttpRequestError = class extends require_base.BaseError {
6
+ constructor({ body, cause, details, headers, status, url }) {
7
+ super("HTTP request failed.", {
8
+ cause,
9
+ details,
10
+ metaMessages: [
11
+ status && `Status: ${status}`,
12
+ `URL: ${url}`,
13
+ body && `Request body: ${require_serialize.serialize(body)}`
14
+ ].filter(Boolean),
15
+ name: "HttpRequestError"
16
+ });
17
+ this.body = body;
18
+ this.headers = headers;
19
+ this.status = status;
20
+ this.url = url;
21
+ }
22
+ };
23
+ var RpcRequestError = class extends require_base.BaseError {
24
+ constructor({ body, error, url }) {
25
+ super("RPC Request failed.", {
26
+ cause: error,
27
+ details: error.message,
28
+ metaMessages: [`URL: ${url}`, `Request body: ${require_serialize.serialize(body)}`],
29
+ name: "RpcRequestError"
30
+ });
31
+ this.code = error.code;
32
+ this.data = error.data;
33
+ }
34
+ };
35
+ var TimeoutError = class extends require_base.BaseError {
36
+ constructor({ body, url }) {
37
+ super("The request took too long to respond.", {
38
+ details: "The request timed out.",
39
+ metaMessages: [`URL: ${url}`, `Request body: ${require_serialize.serialize(body)}`],
40
+ name: "TimeoutError"
41
+ });
42
+ }
43
+ };
44
+
45
+ //#endregion
46
+ exports.HttpRequestError = HttpRequestError;
47
+ exports.RpcRequestError = RpcRequestError;
48
+ exports.TimeoutError = TimeoutError;
@@ -0,0 +1,61 @@
1
+ import { BaseError } from "./base.cjs";
2
+
3
+ //#region src/errors/request.d.ts
4
+ type HttpRequestErrorType = HttpRequestError & {
5
+ name: "HttpRequestError";
6
+ };
7
+ declare class HttpRequestError extends BaseError {
8
+ body?: unknown | undefined;
9
+ headers?: Headers | undefined;
10
+ status?: number | undefined;
11
+ url: string;
12
+ constructor({
13
+ body,
14
+ cause,
15
+ details,
16
+ headers,
17
+ status,
18
+ url
19
+ }: {
20
+ body?: unknown | undefined;
21
+ cause?: Error | undefined;
22
+ details?: string | undefined;
23
+ headers?: Headers | undefined;
24
+ status?: number | undefined;
25
+ url: string;
26
+ });
27
+ }
28
+ type RpcRequestErrorType = RpcRequestError & {
29
+ name: "RpcRequestError";
30
+ };
31
+ declare class RpcRequestError extends BaseError {
32
+ code: number;
33
+ data?: unknown;
34
+ constructor({
35
+ body,
36
+ error,
37
+ url
38
+ }: {
39
+ body: unknown;
40
+ error: {
41
+ code: number;
42
+ data?: unknown;
43
+ message: string;
44
+ };
45
+ url: string;
46
+ });
47
+ }
48
+ type TimeoutErrorType = TimeoutError & {
49
+ name: "TimeoutError";
50
+ };
51
+ declare class TimeoutError extends BaseError {
52
+ constructor({
53
+ body,
54
+ url
55
+ }: {
56
+ body: unknown;
57
+ url: string;
58
+ });
59
+ }
60
+ //#endregion
61
+ export { HttpRequestError, HttpRequestErrorType, RpcRequestError, RpcRequestErrorType, TimeoutError, TimeoutErrorType };