Skip to content

Commit cdaf99e

Browse files
authored
Merge pull request #2286 from pyth-network/cprussin/fix-hermes-client
fix(hermes-client): ensure relative urls are built properly
2 parents 4e034a6 + 741a8bd commit cdaf99e

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

apps/hermes/client/js/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ const priceIds = [
3232
];
3333

3434
// Get price feeds
35-
const priceFeeds = await connection.getPriceFeeds("btc", "crypto");
35+
const priceFeeds = await connection.getPriceFeeds({
36+
query: "btc",
37+
filter: "crypto",
38+
});
3639
console.log(priceFeeds);
3740

3841
// Latest price updates

apps/hermes/client/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/hermes-client",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Pyth Hermes Client",
55
"author": {
66
"name": "Pyth Data Association"

apps/hermes/client/js/src/HermesClient.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class HermesClient {
119119
query?: string;
120120
filter?: string;
121121
}): Promise<PriceFeedMetadata[]> {
122-
const url = new URL("v2/price_feeds", this.baseURL);
122+
const url = this.buildURL("price_feeds");
123123
if (options) {
124124
this.appendUrlSearchParams(url, options);
125125
}
@@ -144,7 +144,7 @@ export class HermesClient {
144144
encoding?: EncodingType;
145145
parsed?: boolean;
146146
}): Promise<PublisherCaps> {
147-
const url = new URL("v2/updates/publisher_stake_caps/latest", this.baseURL);
147+
const url = this.buildURL("updates/publisher_stake_caps/latest");
148148
if (options) {
149149
this.appendUrlSearchParams(url, options);
150150
}
@@ -175,7 +175,7 @@ export class HermesClient {
175175
ignoreInvalidPriceIds?: boolean;
176176
}
177177
): Promise<PriceUpdate> {
178-
const url = new URL("v2/updates/price/latest", this.baseURL);
178+
const url = this.buildURL("updates/price/latest");
179179
for (const id of ids) {
180180
url.searchParams.append("ids[]", id);
181181
}
@@ -211,7 +211,7 @@ export class HermesClient {
211211
ignoreInvalidPriceIds?: boolean;
212212
}
213213
): Promise<PriceUpdate> {
214-
const url = new URL(`v2/updates/price/${publishTime}`, this.baseURL);
214+
const url = this.buildURL(`updates/price/${publishTime}`);
215215
for (const id of ids) {
216216
url.searchParams.append("ids[]", id);
217217
}
@@ -251,7 +251,7 @@ export class HermesClient {
251251
ignoreInvalidPriceIds?: boolean;
252252
}
253253
): Promise<EventSource> {
254-
const url = new URL("v2/updates/price/stream", this.baseURL);
254+
const url = this.buildURL("updates/price/stream");
255255
ids.forEach((id) => {
256256
url.searchParams.append("ids[]", id);
257257
});
@@ -288,10 +288,7 @@ export class HermesClient {
288288
ignoreInvalidPriceIds?: boolean;
289289
}
290290
): Promise<TwapsResponse> {
291-
const url = new URL(
292-
`v2/updates/twap/${window_seconds}/latest`,
293-
this.baseURL
294-
);
291+
const url = this.buildURL(`updates/twap/${window_seconds}/latest`);
295292
for (const id of ids) {
296293
url.searchParams.append("ids[]", id);
297294
}
@@ -314,4 +311,13 @@ export class HermesClient {
314311
}
315312
});
316313
}
314+
315+
private buildURL(endpoint: string) {
316+
return new URL(
317+
`./v2/${endpoint}`,
318+
// We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the
319+
// path relative to the parent.
320+
`${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}`
321+
);
322+
}
317323
}

0 commit comments

Comments
 (0)