diff --git a/apps/hermes/client/js/README.md b/apps/hermes/client/js/README.md index c6a850a72a..1b0130cb39 100644 --- a/apps/hermes/client/js/README.md +++ b/apps/hermes/client/js/README.md @@ -32,7 +32,10 @@ const priceIds = [ ]; // Get price feeds -const priceFeeds = await connection.getPriceFeeds("btc", "crypto"); +const priceFeeds = await connection.getPriceFeeds({ + query: "btc", + filter: "crypto", +}); console.log(priceFeeds); // Latest price updates diff --git a/apps/hermes/client/js/package.json b/apps/hermes/client/js/package.json index 3686b8d034..98073c5d21 100644 --- a/apps/hermes/client/js/package.json +++ b/apps/hermes/client/js/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/hermes-client", - "version": "1.3.0", + "version": "1.3.1", "description": "Pyth Hermes Client", "author": { "name": "Pyth Data Association" diff --git a/apps/hermes/client/js/src/HermesClient.ts b/apps/hermes/client/js/src/HermesClient.ts index 79635b0e5e..576f71784b 100644 --- a/apps/hermes/client/js/src/HermesClient.ts +++ b/apps/hermes/client/js/src/HermesClient.ts @@ -119,7 +119,7 @@ export class HermesClient { query?: string; filter?: string; }): Promise { - const url = new URL("v2/price_feeds", this.baseURL); + const url = this.buildURL("price_feeds"); if (options) { this.appendUrlSearchParams(url, options); } @@ -144,7 +144,7 @@ export class HermesClient { encoding?: EncodingType; parsed?: boolean; }): Promise { - const url = new URL("v2/updates/publisher_stake_caps/latest", this.baseURL); + const url = this.buildURL("updates/publisher_stake_caps/latest"); if (options) { this.appendUrlSearchParams(url, options); } @@ -175,7 +175,7 @@ export class HermesClient { ignoreInvalidPriceIds?: boolean; } ): Promise { - const url = new URL("v2/updates/price/latest", this.baseURL); + const url = this.buildURL("updates/price/latest"); for (const id of ids) { url.searchParams.append("ids[]", id); } @@ -211,7 +211,7 @@ export class HermesClient { ignoreInvalidPriceIds?: boolean; } ): Promise { - const url = new URL(`v2/updates/price/${publishTime}`, this.baseURL); + const url = this.buildURL(`updates/price/${publishTime}`); for (const id of ids) { url.searchParams.append("ids[]", id); } @@ -251,7 +251,7 @@ export class HermesClient { ignoreInvalidPriceIds?: boolean; } ): Promise { - const url = new URL("v2/updates/price/stream", this.baseURL); + const url = this.buildURL("updates/price/stream"); ids.forEach((id) => { url.searchParams.append("ids[]", id); }); @@ -288,10 +288,7 @@ export class HermesClient { ignoreInvalidPriceIds?: boolean; } ): Promise { - const url = new URL( - `v2/updates/twap/${window_seconds}/latest`, - this.baseURL - ); + const url = this.buildURL(`updates/twap/${window_seconds}/latest`); for (const id of ids) { url.searchParams.append("ids[]", id); } @@ -314,4 +311,13 @@ export class HermesClient { } }); } + + private buildURL(endpoint: string) { + return new URL( + `./v2/${endpoint}`, + // We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the + // path relative to the parent. + `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}` + ); + } }