feat(rest)!: allow passing tokens per request (#10682)

BREAKING CHANGE: `RequestData.authPrefix` has been removed in favor of `RequestData.auth.prefix`
This commit is contained in:
ckohen
2025-01-12 21:36:05 -08:00
committed by GitHub
parent 11438c230b
commit ae0265eefc
8 changed files with 71 additions and 22 deletions

View File

@@ -304,11 +304,16 @@ export class SequentialHandler implements IHandler {
// Let library users know when rate limit buckets have been updated
this.debug(['Received bucket hash update', ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join('\n'));
// This queue will eventually be eliminated via attrition
this.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() });
this.manager.hashes.set(
`${method}:${routeId.bucketRoute}${typeof requestData.auth === 'string' ? `:${requestData.auth}` : ''}`,
{ value: hash, lastAccess: Date.now() },
);
} else if (hash) {
// Handle the case where hash value doesn't change
// Fetch the hash data from the manager
const hashData = this.manager.hashes.get(`${method}:${routeId.bucketRoute}`);
const hashData = this.manager.hashes.get(
`${method}:${routeId.bucketRoute}${typeof requestData.auth === 'string' ? `:${requestData.auth}` : ''}`,
);
// When fetched, update the last access of the hash
if (hashData) {

View File

@@ -138,7 +138,7 @@ export async function handleErrors(
// Handle possible malformed requests
if (status >= 400 && status < 500) {
// If we receive this status code, it means the token we had is no longer valid.
if (status === 401 && requestData.auth) {
if (status === 401 && requestData.auth === true) {
manager.setToken(null!);
}