Skip to content

fix(hermes-client): ensure relative urls are built properly #2286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/hermes/client/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion apps/hermes/client/js/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
24 changes: 15 additions & 9 deletions apps/hermes/client/js/src/HermesClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class HermesClient {
query?: string;
filter?: string;
}): Promise<PriceFeedMetadata[]> {
const url = new URL("v2/price_feeds", this.baseURL);
const url = this.buildURL("price_feeds");
if (options) {
this.appendUrlSearchParams(url, options);
}
Expand All @@ -144,7 +144,7 @@ export class HermesClient {
encoding?: EncodingType;
parsed?: boolean;
}): Promise<PublisherCaps> {
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);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ export class HermesClient {
ignoreInvalidPriceIds?: boolean;
}
): Promise<PriceUpdate> {
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);
}
Expand Down Expand Up @@ -211,7 +211,7 @@ export class HermesClient {
ignoreInvalidPriceIds?: boolean;
}
): Promise<PriceUpdate> {
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);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ export class HermesClient {
ignoreInvalidPriceIds?: boolean;
}
): Promise<EventSource> {
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);
});
Expand Down Expand Up @@ -288,10 +288,7 @@ export class HermesClient {
ignoreInvalidPriceIds?: boolean;
}
): Promise<TwapsResponse> {
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);
}
Expand All @@ -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("/") ? "" : "/"}`
);
}
}
Loading