ton-provider-system 0.2.1 → 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.cjs +33 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/rpc.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -753,17 +753,43 @@ var OnFinalityProvider = class extends BaseProvider {
|
|
|
753
753
|
if (normalized.includes("onfinality.io")) {
|
|
754
754
|
try {
|
|
755
755
|
const url = new URL(normalized);
|
|
756
|
-
const
|
|
756
|
+
const hasQueryParams = normalized.includes("?");
|
|
757
|
+
const queryString = hasQueryParams ? normalized.split("?")[1] : "";
|
|
758
|
+
const hasApiKeyInQuery = queryString.includes("apikey=");
|
|
757
759
|
if (!url.pathname || url.pathname === "/") {
|
|
758
760
|
if (this.provider.apiKey) {
|
|
759
|
-
|
|
761
|
+
const baseUrl2 = normalized.split("?")[0];
|
|
762
|
+
if (hasApiKeyInQuery) {
|
|
763
|
+
return normalized.replace(/\/?$/, "/rpc");
|
|
764
|
+
}
|
|
765
|
+
if (hasQueryParams) {
|
|
766
|
+
return `${baseUrl2.replace(/\/?$/, "/rpc")}?${queryString}&apikey=${encodeURIComponent(this.provider.apiKey)}`;
|
|
767
|
+
}
|
|
768
|
+
return `${baseUrl2.replace(/\/?$/, "/rpc")}?apikey=${encodeURIComponent(this.provider.apiKey)}`;
|
|
760
769
|
}
|
|
770
|
+
const baseUrl = normalized.split("?")[0];
|
|
761
771
|
return baseUrl.replace(/\/?$/, "/public");
|
|
762
772
|
}
|
|
763
773
|
if (url.pathname === "/rpc" || url.pathname === "/public") {
|
|
764
|
-
|
|
774
|
+
if (url.pathname === "/rpc") {
|
|
775
|
+
if (hasApiKeyInQuery) {
|
|
776
|
+
return normalized;
|
|
777
|
+
}
|
|
778
|
+
if (this.provider.apiKey) {
|
|
779
|
+
const baseUrl = normalized.split("?")[0];
|
|
780
|
+
if (hasQueryParams) {
|
|
781
|
+
return `${baseUrl}?${queryString}&apikey=${encodeURIComponent(this.provider.apiKey)}`;
|
|
782
|
+
}
|
|
783
|
+
return `${baseUrl}?apikey=${encodeURIComponent(this.provider.apiKey)}`;
|
|
784
|
+
}
|
|
785
|
+
return normalized;
|
|
786
|
+
}
|
|
787
|
+
if (url.pathname === "/public") {
|
|
788
|
+
return normalized.split("?")[0];
|
|
789
|
+
}
|
|
790
|
+
return normalized;
|
|
765
791
|
}
|
|
766
|
-
return
|
|
792
|
+
return normalized;
|
|
767
793
|
} catch {
|
|
768
794
|
if (normalized.includes("{key}")) {
|
|
769
795
|
return normalized.split("?")[0].replace(/\/?$/, "/public");
|
|
@@ -771,7 +797,7 @@ var OnFinalityProvider = class extends BaseProvider {
|
|
|
771
797
|
if (!normalized.includes("/rpc") && !normalized.includes("/public")) {
|
|
772
798
|
return normalized.split("?")[0] + "/public";
|
|
773
799
|
}
|
|
774
|
-
return normalized
|
|
800
|
+
return normalized;
|
|
775
801
|
}
|
|
776
802
|
}
|
|
777
803
|
return normalized;
|
|
@@ -780,9 +806,6 @@ var OnFinalityProvider = class extends BaseProvider {
|
|
|
780
806
|
const headers = {
|
|
781
807
|
"Content-Type": "application/json"
|
|
782
808
|
};
|
|
783
|
-
if (this.provider.apiKey) {
|
|
784
|
-
headers["apikey"] = this.provider.apiKey;
|
|
785
|
-
}
|
|
786
809
|
return headers;
|
|
787
810
|
}
|
|
788
811
|
parseResponse(data) {
|
|
@@ -1086,7 +1109,8 @@ var HealthChecker = class {
|
|
|
1086
1109
|
} catch (error) {
|
|
1087
1110
|
if (provider.type === "onfinality" && normalizedEndpoint.includes("/rpc") && provider.apiKey && error.message?.includes("backend error")) {
|
|
1088
1111
|
this.logger.debug(`OnFinality /rpc failed, retrying with /public endpoint`);
|
|
1089
|
-
const
|
|
1112
|
+
const baseUrl = normalizedEndpoint.split("?")[0];
|
|
1113
|
+
const publicEndpoint = baseUrl.replace("/rpc", "/public");
|
|
1090
1114
|
const publicProvider = { ...provider, apiKey: void 0 };
|
|
1091
1115
|
const publicProviderImpl = createProvider(publicProvider);
|
|
1092
1116
|
info = await this.callGetMasterchainInfo(publicEndpoint, publicProvider, publicProviderImpl);
|