Skip to content

Commit

Permalink
fix: Fetching cards by sequentialId fails due to incorrectly parsing …
Browse files Browse the repository at this point in the history
…the provided ID.
  • Loading branch information
adam-coster committed Oct 6, 2021
1 parent b91a187 commit 9005682
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/lib/BravoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export class BravoClient extends FavroClient {
// in multiple ways (as a URL, with a prefix, or plain)
if (typeof options?.cardSequentialId == 'string') {
options.cardSequentialId = stringToNumber(
options.cardSequentialId.replace(/^.*(\d+)$/, '$1'),
options.cardSequentialId.replace(/^.*?(\d+)$/, '$1'),
);
}
const res = (await this.requestWithReturnedEntities(
Expand Down
21 changes: 8 additions & 13 deletions src/lib/clientLib/FavroClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ export class FavroClient {

get requestStats() {
return {
total: this._requestsMade,
remaining: this._requestsRemaining,
totalRequests: this._requestsMade,
limitRemaining: this._requestsRemaining,
limit: this._requestsLimit,
limitResetsAt: this._limitResetsAt,
};
Expand Down Expand Up @@ -212,7 +212,9 @@ export class FavroClient {
headers, // Force it to assume no undefineds
body,
};
debugBasic(`sent ${method.toUpperCase()} ${url}`);
debugBasic(
`sent ${method.toUpperCase()} ${fullUrl.replace(/^.?\.com\b/, '')}`,
);
debugHeaders(`sent %O`, headers);
debugBodies(`sent %O`, body);
const rawResponse = await (customFetch || this._fetch)(fullUrl, reqOptions);
Expand All @@ -221,22 +223,15 @@ export class FavroClient {
this._limitResetsAt = res.limitResetsAt;
this._requestsLimit = res.limit;
this._requestsRemaining = res.requestsRemaining;
const requestStats = {
status: res.status,
remaining: this._requestsRemaining,
made: this._requestsMade,
limit: res.limit,
resetAt: this._limitResetsAt,
};
debugBasic(`got ${res.status} ${res.contentType} %o`, requestStats);
debugBasic(`got ${res.status} ${res.contentType} ${rawResponse.size}b`);
debugHeaders(`got %O`, headers);
debugBodies(`got %O`, body);
debugStats(`%O`, requestStats);
debugStats(`%O`, this.requestStats);
if (this._requestsRemaining < 1 || res.status == 429) {
// TODO: Set an interval before allowing requests to go through again, OR SOMETHING
Logger.warn(
`Favro API rate limit reached! ${JSON.stringify(
requestStats,
this.requestStats,
null,
2,
)}`,
Expand Down
4 changes: 3 additions & 1 deletion src/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,11 @@ describe('BravoClient', function () {
expect(foundCard!.equals(testCard)).to.be.true;

// Fetch it again via sequentialId
client.enableDebugLogging(['bravo:http:*', '-bravo:http:headers']);
const bySequentialId = await client.findCardInstancesBySequentialId(
foundCard.sequentialId,
foundCard.url,
);
client.disableDebugLogging();
expect(bySequentialId[0]!.equals(foundCard), 'can fetch by sequentialId')
.to.be.true;

Expand Down

0 comments on commit 9005682

Please sign in to comment.