ton-provider-system 0.2.0 → 0.2.2

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/dist/index.d.cts CHANGED
@@ -1032,6 +1032,9 @@ declare class HealthChecker {
1032
1032
  clearResults(): void;
1033
1033
  /**
1034
1034
  * Mark a provider as degraded (e.g., on 429 error)
1035
+ *
1036
+ * Providers marked as degraded have failed health checks (e.g., rate limit errors)
1037
+ * and should not be selected. The system will failover to the next available provider.
1035
1038
  */
1036
1039
  markDegraded(providerId: string, network: Network, error?: string): void;
1037
1040
  /**
@@ -1909,7 +1912,10 @@ declare class TatumProvider extends BaseProvider {
1909
1912
  * Documentation: https://documentation.onfinality.io/support/ton
1910
1913
  *
1911
1914
  * Endpoint format: https://ton-{network}.api.onfinality.io/public or /rpc
1912
- * API key: Optional, in apikey header (preferred) or query params
1915
+ * API key: Required for /rpc endpoint, passed as query parameter ?apikey=YOUR_API_KEY
1916
+ *
1917
+ * IMPORTANT: OnFinality uses query parameters for API key authentication, NOT headers.
1918
+ * The API key must be included in the URL as ?apikey=YOUR_API_KEY
1913
1919
  */
1914
1920
 
1915
1921
  declare class OnFinalityProvider extends BaseProvider {
package/dist/index.d.ts CHANGED
@@ -1032,6 +1032,9 @@ declare class HealthChecker {
1032
1032
  clearResults(): void;
1033
1033
  /**
1034
1034
  * Mark a provider as degraded (e.g., on 429 error)
1035
+ *
1036
+ * Providers marked as degraded have failed health checks (e.g., rate limit errors)
1037
+ * and should not be selected. The system will failover to the next available provider.
1035
1038
  */
1036
1039
  markDegraded(providerId: string, network: Network, error?: string): void;
1037
1040
  /**
@@ -1909,7 +1912,10 @@ declare class TatumProvider extends BaseProvider {
1909
1912
  * Documentation: https://documentation.onfinality.io/support/ton
1910
1913
  *
1911
1914
  * Endpoint format: https://ton-{network}.api.onfinality.io/public or /rpc
1912
- * API key: Optional, in apikey header (preferred) or query params
1915
+ * API key: Required for /rpc endpoint, passed as query parameter ?apikey=YOUR_API_KEY
1916
+ *
1917
+ * IMPORTANT: OnFinality uses query parameters for API key authentication, NOT headers.
1918
+ * The API key must be included in the URL as ?apikey=YOUR_API_KEY
1913
1919
  */
1914
1920
 
1915
1921
  declare class OnFinalityProvider extends BaseProvider {
package/dist/index.js CHANGED
@@ -750,17 +750,43 @@ var OnFinalityProvider = class extends BaseProvider {
750
750
  if (normalized.includes("onfinality.io")) {
751
751
  try {
752
752
  const url = new URL(normalized);
753
- const baseUrl = normalized.split("?")[0];
753
+ const hasQueryParams = normalized.includes("?");
754
+ const queryString = hasQueryParams ? normalized.split("?")[1] : "";
755
+ const hasApiKeyInQuery = queryString.includes("apikey=");
754
756
  if (!url.pathname || url.pathname === "/") {
755
757
  if (this.provider.apiKey) {
756
- return baseUrl.replace(/\/?$/, "/rpc");
758
+ const baseUrl2 = normalized.split("?")[0];
759
+ if (hasApiKeyInQuery) {
760
+ return normalized.replace(/\/?$/, "/rpc");
761
+ }
762
+ if (hasQueryParams) {
763
+ return `${baseUrl2.replace(/\/?$/, "/rpc")}?${queryString}&apikey=${encodeURIComponent(this.provider.apiKey)}`;
764
+ }
765
+ return `${baseUrl2.replace(/\/?$/, "/rpc")}?apikey=${encodeURIComponent(this.provider.apiKey)}`;
757
766
  }
767
+ const baseUrl = normalized.split("?")[0];
758
768
  return baseUrl.replace(/\/?$/, "/public");
759
769
  }
760
770
  if (url.pathname === "/rpc" || url.pathname === "/public") {
761
- return baseUrl;
771
+ if (url.pathname === "/rpc") {
772
+ if (hasApiKeyInQuery) {
773
+ return normalized;
774
+ }
775
+ if (this.provider.apiKey) {
776
+ const baseUrl = normalized.split("?")[0];
777
+ if (hasQueryParams) {
778
+ return `${baseUrl}?${queryString}&apikey=${encodeURIComponent(this.provider.apiKey)}`;
779
+ }
780
+ return `${baseUrl}?apikey=${encodeURIComponent(this.provider.apiKey)}`;
781
+ }
782
+ return normalized;
783
+ }
784
+ if (url.pathname === "/public") {
785
+ return normalized.split("?")[0];
786
+ }
787
+ return normalized;
762
788
  }
763
- return baseUrl;
789
+ return normalized;
764
790
  } catch {
765
791
  if (normalized.includes("{key}")) {
766
792
  return normalized.split("?")[0].replace(/\/?$/, "/public");
@@ -768,7 +794,7 @@ var OnFinalityProvider = class extends BaseProvider {
768
794
  if (!normalized.includes("/rpc") && !normalized.includes("/public")) {
769
795
  return normalized.split("?")[0] + "/public";
770
796
  }
771
- return normalized.split("?")[0];
797
+ return normalized;
772
798
  }
773
799
  }
774
800
  return normalized;
@@ -777,9 +803,6 @@ var OnFinalityProvider = class extends BaseProvider {
777
803
  const headers = {
778
804
  "Content-Type": "application/json"
779
805
  };
780
- if (this.provider.apiKey) {
781
- headers["apikey"] = this.provider.apiKey;
782
- }
783
806
  return headers;
784
807
  }
785
808
  parseResponse(data) {
@@ -1083,7 +1106,8 @@ var HealthChecker = class {
1083
1106
  } catch (error) {
1084
1107
  if (provider.type === "onfinality" && normalizedEndpoint.includes("/rpc") && provider.apiKey && error.message?.includes("backend error")) {
1085
1108
  this.logger.debug(`OnFinality /rpc failed, retrying with /public endpoint`);
1086
- const publicEndpoint = normalizedEndpoint.replace("/rpc", "/public");
1109
+ const baseUrl = normalizedEndpoint.split("?")[0];
1110
+ const publicEndpoint = baseUrl.replace("/rpc", "/public");
1087
1111
  const publicProvider = { ...provider, apiKey: void 0 };
1088
1112
  const publicProviderImpl = createProvider(publicProvider);
1089
1113
  info = await this.callGetMasterchainInfo(publicEndpoint, publicProvider, publicProviderImpl);
@@ -1232,14 +1256,17 @@ var HealthChecker = class {
1232
1256
  }
1233
1257
  /**
1234
1258
  * Mark a provider as degraded (e.g., on 429 error)
1259
+ *
1260
+ * Providers marked as degraded have failed health checks (e.g., rate limit errors)
1261
+ * and should not be selected. The system will failover to the next available provider.
1235
1262
  */
1236
1263
  markDegraded(providerId, network, error) {
1237
1264
  const key = this.getResultKey(providerId, network);
1238
1265
  const existing = this.results.get(key);
1239
1266
  const result = existing ? {
1240
1267
  ...existing,
1241
- success: true,
1242
- // Degraded providers are still usable, just slower/rate-limited
1268
+ success: false,
1269
+ // Degraded providers with errors should not be selected
1243
1270
  status: "degraded",
1244
1271
  error: error || "Marked as degraded",
1245
1272
  lastTested: /* @__PURE__ */ new Date(),
@@ -1247,8 +1274,8 @@ var HealthChecker = class {
1247
1274
  } : {
1248
1275
  id: providerId,
1249
1276
  network,
1250
- success: true,
1251
- // Degraded providers are still usable
1277
+ success: false,
1278
+ // Degraded providers with errors should not be selected
1252
1279
  status: "degraded",
1253
1280
  latencyMs: null,
1254
1281
  seqno: null,