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

@@ -60,3 +60,5 @@ export const OverwrittenMimeTypes = {
} as const satisfies Readonly<Record<string, string>>;
export const BurstHandlerMajorIdKey = 'burst';
export const AUTH_UUID_NAMESPACE = 'acc82a4c-f887-417b-a69c-f74096ff7e59';

View File

@@ -269,6 +269,19 @@ export interface RawFile {
name: string;
}
export interface AuthData {
/**
* The authorization prefix to use for this request, useful if you use this with bearer tokens
*
* @defaultValue `REST.options.authPrefix`
*/
prefix?: 'Bearer' | 'Bot';
/**
* The authorization token to use for this request
*/
token: string;
}
/**
* Represents possible data to be given to an endpoint
*/
@@ -278,17 +291,11 @@ export interface RequestData {
*/
appendToFormData?: boolean;
/**
* If this request needs the `Authorization` header
* Alternate authorization data to use for this request only, or `false` to disable the Authorization header
*
* @defaultValue `true`
*/
auth?: boolean;
/**
* The authorization prefix to use for this request, useful if you use this with bearer tokens
*
* @defaultValue `'Bot'`
*/
authPrefix?: 'Bearer' | 'Bot';
auth?: AuthData | boolean;
/**
* The body to send to this request.
* If providing as BodyInit, set `passThroughBody: true`
@@ -363,7 +370,9 @@ export interface InternalRequest extends RequestData {
method: RequestMethod;
}
export type HandlerRequestData = Pick<InternalRequest, 'auth' | 'body' | 'files' | 'signal'>;
export interface HandlerRequestData extends Pick<InternalRequest, 'body' | 'files' | 'signal'> {
auth: boolean | string;
}
/**
* Parsed route data for an endpoint