@discordjs/rest 3.0.0-dev.1736727183-101bef1c5 → 3.0.0-dev.1736769922-18ab0cf62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +19 -10
- package/dist/index.d.ts +19 -10
- package/dist/index.js +26 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -11
- package/dist/index.mjs.map +1 -1
- package/dist/web.d.mts +19 -10
- package/dist/web.d.ts +19 -10
- package/dist/web.js +26 -11
- package/dist/web.js.map +1 -1
- package/dist/web.mjs +25 -11
- package/dist/web.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.d.mts
CHANGED
|
@@ -282,6 +282,18 @@ interface RawFile {
|
|
|
282
282
|
*/
|
|
283
283
|
name: string;
|
|
284
284
|
}
|
|
285
|
+
interface AuthData {
|
|
286
|
+
/**
|
|
287
|
+
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
|
288
|
+
*
|
|
289
|
+
* @defaultValue `REST.options.authPrefix`
|
|
290
|
+
*/
|
|
291
|
+
prefix?: 'Bearer' | 'Bot';
|
|
292
|
+
/**
|
|
293
|
+
* The authorization token to use for this request
|
|
294
|
+
*/
|
|
295
|
+
token: string;
|
|
296
|
+
}
|
|
285
297
|
/**
|
|
286
298
|
* Represents possible data to be given to an endpoint
|
|
287
299
|
*/
|
|
@@ -291,17 +303,11 @@ interface RequestData {
|
|
|
291
303
|
*/
|
|
292
304
|
appendToFormData?: boolean;
|
|
293
305
|
/**
|
|
294
|
-
*
|
|
306
|
+
* Alternate authorization data to use for this request only, or `false` to disable the Authorization header
|
|
295
307
|
*
|
|
296
308
|
* @defaultValue `true`
|
|
297
309
|
*/
|
|
298
|
-
auth?: boolean;
|
|
299
|
-
/**
|
|
300
|
-
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
|
301
|
-
*
|
|
302
|
-
* @defaultValue `'Bot'`
|
|
303
|
-
*/
|
|
304
|
-
authPrefix?: 'Bearer' | 'Bot';
|
|
310
|
+
auth?: AuthData | boolean;
|
|
305
311
|
/**
|
|
306
312
|
* The body to send to this request.
|
|
307
313
|
* If providing as BodyInit, set `passThroughBody: true`
|
|
@@ -371,7 +377,9 @@ interface InternalRequest extends RequestData {
|
|
|
371
377
|
fullRoute: RouteLike;
|
|
372
378
|
method: RequestMethod;
|
|
373
379
|
}
|
|
374
|
-
|
|
380
|
+
interface HandlerRequestData extends Pick<InternalRequest, 'body' | 'files' | 'signal'> {
|
|
381
|
+
auth: boolean | string;
|
|
382
|
+
}
|
|
375
383
|
/**
|
|
376
384
|
* Parsed route data for an endpoint
|
|
377
385
|
*
|
|
@@ -438,6 +446,7 @@ declare const OverwrittenMimeTypes: {
|
|
|
438
446
|
readonly 'image/apng': "image/png";
|
|
439
447
|
};
|
|
440
448
|
declare const BurstHandlerMajorIdKey = "burst";
|
|
449
|
+
declare const AUTH_UUID_NAMESPACE = "acc82a4c-f887-417b-a69c-f74096ff7e59";
|
|
441
450
|
|
|
442
451
|
/**
|
|
443
452
|
* The options used for image URLs
|
|
@@ -900,4 +909,4 @@ declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
|
|
900
909
|
*/
|
|
901
910
|
declare const version: string;
|
|
902
911
|
|
|
903
|
-
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
|
912
|
+
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, AUTH_UUID_NAMESPACE, type AuthData, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
package/dist/index.d.ts
CHANGED
|
@@ -282,6 +282,18 @@ interface RawFile {
|
|
|
282
282
|
*/
|
|
283
283
|
name: string;
|
|
284
284
|
}
|
|
285
|
+
interface AuthData {
|
|
286
|
+
/**
|
|
287
|
+
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
|
288
|
+
*
|
|
289
|
+
* @defaultValue `REST.options.authPrefix`
|
|
290
|
+
*/
|
|
291
|
+
prefix?: 'Bearer' | 'Bot';
|
|
292
|
+
/**
|
|
293
|
+
* The authorization token to use for this request
|
|
294
|
+
*/
|
|
295
|
+
token: string;
|
|
296
|
+
}
|
|
285
297
|
/**
|
|
286
298
|
* Represents possible data to be given to an endpoint
|
|
287
299
|
*/
|
|
@@ -291,17 +303,11 @@ interface RequestData {
|
|
|
291
303
|
*/
|
|
292
304
|
appendToFormData?: boolean;
|
|
293
305
|
/**
|
|
294
|
-
*
|
|
306
|
+
* Alternate authorization data to use for this request only, or `false` to disable the Authorization header
|
|
295
307
|
*
|
|
296
308
|
* @defaultValue `true`
|
|
297
309
|
*/
|
|
298
|
-
auth?: boolean;
|
|
299
|
-
/**
|
|
300
|
-
* The authorization prefix to use for this request, useful if you use this with bearer tokens
|
|
301
|
-
*
|
|
302
|
-
* @defaultValue `'Bot'`
|
|
303
|
-
*/
|
|
304
|
-
authPrefix?: 'Bearer' | 'Bot';
|
|
310
|
+
auth?: AuthData | boolean;
|
|
305
311
|
/**
|
|
306
312
|
* The body to send to this request.
|
|
307
313
|
* If providing as BodyInit, set `passThroughBody: true`
|
|
@@ -371,7 +377,9 @@ interface InternalRequest extends RequestData {
|
|
|
371
377
|
fullRoute: RouteLike;
|
|
372
378
|
method: RequestMethod;
|
|
373
379
|
}
|
|
374
|
-
|
|
380
|
+
interface HandlerRequestData extends Pick<InternalRequest, 'body' | 'files' | 'signal'> {
|
|
381
|
+
auth: boolean | string;
|
|
382
|
+
}
|
|
375
383
|
/**
|
|
376
384
|
* Parsed route data for an endpoint
|
|
377
385
|
*
|
|
@@ -438,6 +446,7 @@ declare const OverwrittenMimeTypes: {
|
|
|
438
446
|
readonly 'image/apng': "image/png";
|
|
439
447
|
};
|
|
440
448
|
declare const BurstHandlerMajorIdKey = "burst";
|
|
449
|
+
declare const AUTH_UUID_NAMESPACE = "acc82a4c-f887-417b-a69c-f74096ff7e59";
|
|
441
450
|
|
|
442
451
|
/**
|
|
443
452
|
* The options used for image URLs
|
|
@@ -900,4 +909,4 @@ declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
|
|
900
909
|
*/
|
|
901
910
|
declare const version: string;
|
|
902
911
|
|
|
903
|
-
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
|
912
|
+
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, AUTH_UUID_NAMESPACE, type AuthData, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN, DefaultRestOptions, DefaultUserAgent, DefaultUserAgentAppendix, DiscordAPIError, type DiscordErrorData, type GetRateLimitOffsetFunction, HTTPError, type HandlerRequestData, type HashData, type ImageExtension, type ImageSize, type ImageURLOptions, type InternalRequest, type InvalidRequestWarningData, type MakeURLOptions, type OAuthErrorData, OverwrittenMimeTypes, REST, RESTEvents, type RESTOptions, type RateLimitData, RateLimitError, type RateLimitQueueFilter, type RawFile, type RequestBody, type RequestData, type RequestHeaders, RequestMethod, type ResponseLike, type RestEvents, type RestEventsMap, type RouteData, type RouteLike, type StickerExtension, calculateUserDefaultAvatarIndex, makeURLSearchParams, parseResponse, version };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(index_exports, {
|
|
|
24
24
|
ALLOWED_EXTENSIONS: () => ALLOWED_EXTENSIONS,
|
|
25
25
|
ALLOWED_SIZES: () => ALLOWED_SIZES,
|
|
26
26
|
ALLOWED_STICKER_EXTENSIONS: () => ALLOWED_STICKER_EXTENSIONS,
|
|
27
|
+
AUTH_UUID_NAMESPACE: () => AUTH_UUID_NAMESPACE,
|
|
27
28
|
BurstHandlerMajorIdKey: () => BurstHandlerMajorIdKey,
|
|
28
29
|
CDN: () => CDN,
|
|
29
30
|
DefaultRestOptions: () => DefaultRestOptions,
|
|
@@ -123,7 +124,7 @@ __name(resolveBody, "resolveBody");
|
|
|
123
124
|
// src/lib/utils/constants.ts
|
|
124
125
|
var import_util = require("@discordjs/util");
|
|
125
126
|
var import_v10 = require("discord-api-types/v10");
|
|
126
|
-
var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.
|
|
127
|
+
var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1736769922-18ab0cf62)`;
|
|
127
128
|
var DefaultUserAgentAppendix = (0, import_util.getUserAgentAppendix)();
|
|
128
129
|
var DefaultRestOptions = {
|
|
129
130
|
agent: null,
|
|
@@ -167,6 +168,7 @@ var OverwrittenMimeTypes = {
|
|
|
167
168
|
"image/apng": "image/png"
|
|
168
169
|
};
|
|
169
170
|
var BurstHandlerMajorIdKey = "burst";
|
|
171
|
+
var AUTH_UUID_NAMESPACE = "acc82a4c-f887-417b-a69c-f74096ff7e59";
|
|
170
172
|
|
|
171
173
|
// src/lib/CDN.ts
|
|
172
174
|
var CDN = class {
|
|
@@ -546,6 +548,7 @@ var import_collection = require("@discordjs/collection");
|
|
|
546
548
|
var import_snowflake = require("@sapphire/snowflake");
|
|
547
549
|
var import_async_event_emitter = require("@vladfrangu/async_event_emitter");
|
|
548
550
|
var import_magic_bytes = require("magic-bytes.js");
|
|
551
|
+
var import_uuid = require("uuid");
|
|
549
552
|
|
|
550
553
|
// src/lib/utils/types.ts
|
|
551
554
|
var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => {
|
|
@@ -705,7 +708,7 @@ async function handleErrors(manager, res, method, url, requestData, retries) {
|
|
|
705
708
|
throw new HTTPError(status, res.statusText, method, url, requestData);
|
|
706
709
|
} else {
|
|
707
710
|
if (status >= 400 && status < 500) {
|
|
708
|
-
if (status === 401 && requestData.auth) {
|
|
711
|
+
if (status === 401 && requestData.auth === true) {
|
|
709
712
|
manager.setToken(null);
|
|
710
713
|
}
|
|
711
714
|
const data = await parseResponse(res);
|
|
@@ -1029,9 +1032,14 @@ var SequentialHandler = class {
|
|
|
1029
1032
|
if (retry) retryAfter = Number(retry) * 1e3 + offset;
|
|
1030
1033
|
if (hash && hash !== this.hash) {
|
|
1031
1034
|
this.debug(["Received bucket hash update", ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join("\n"));
|
|
1032
|
-
this.manager.hashes.set(
|
|
1035
|
+
this.manager.hashes.set(
|
|
1036
|
+
`${method}:${routeId.bucketRoute}${typeof requestData.auth === "string" ? `:${requestData.auth}` : ""}`,
|
|
1037
|
+
{ value: hash, lastAccess: Date.now() }
|
|
1038
|
+
);
|
|
1033
1039
|
} else if (hash) {
|
|
1034
|
-
const hashData = this.manager.hashes.get(
|
|
1040
|
+
const hashData = this.manager.hashes.get(
|
|
1041
|
+
`${method}:${routeId.bucketRoute}${typeof requestData.auth === "string" ? `:${requestData.auth}` : ""}`
|
|
1042
|
+
);
|
|
1035
1043
|
if (hashData) {
|
|
1036
1044
|
hashData.lastAccess = Date.now();
|
|
1037
1045
|
}
|
|
@@ -1283,8 +1291,10 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
|
|
|
1283
1291
|
*/
|
|
1284
1292
|
async queueRequest(request2) {
|
|
1285
1293
|
const routeId = _REST.generateRouteData(request2.fullRoute, request2.method);
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1294
|
+
const customAuth = typeof request2.auth === "object" && request2.auth.token !== this.#token;
|
|
1295
|
+
const auth = customAuth ? (0, import_uuid.v5)(request2.auth.token, AUTH_UUID_NAMESPACE) : request2.auth !== false;
|
|
1296
|
+
const hash = this.hashes.get(`${request2.method}:${routeId.bucketRoute}${customAuth ? `:${auth}` : ""}`) ?? {
|
|
1297
|
+
value: `Global(${request2.method}:${routeId.bucketRoute}${customAuth ? `:${auth}` : ""})`,
|
|
1288
1298
|
lastAccess: -1
|
|
1289
1299
|
};
|
|
1290
1300
|
const handler = this.handlers.get(`${hash.value}:${routeId.majorParameter}`) ?? this.createHandler(hash.value, routeId.majorParameter);
|
|
@@ -1292,7 +1302,7 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
|
|
|
1292
1302
|
return handler.queueRequest(routeId, url, fetchOptions, {
|
|
1293
1303
|
body: request2.body,
|
|
1294
1304
|
files: request2.files,
|
|
1295
|
-
auth
|
|
1305
|
+
auth,
|
|
1296
1306
|
signal: request2.signal
|
|
1297
1307
|
});
|
|
1298
1308
|
}
|
|
@@ -1327,10 +1337,14 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
|
|
|
1327
1337
|
"User-Agent": `${DefaultUserAgent} ${options.userAgentAppendix}`.trim()
|
|
1328
1338
|
};
|
|
1329
1339
|
if (request2.auth !== false) {
|
|
1330
|
-
if (
|
|
1331
|
-
|
|
1340
|
+
if (typeof request2.auth === "object") {
|
|
1341
|
+
headers.Authorization = `${request2.auth.prefix ?? this.options.authPrefix} ${request2.auth.token}`;
|
|
1342
|
+
} else {
|
|
1343
|
+
if (!this.#token) {
|
|
1344
|
+
throw new Error("Expected token to be set for this request, but none was present");
|
|
1345
|
+
}
|
|
1346
|
+
headers.Authorization = `${this.options.authPrefix} ${this.#token}`;
|
|
1332
1347
|
}
|
|
1333
|
-
headers.Authorization = `${request2.authPrefix ?? this.options.authPrefix} ${this.#token}`;
|
|
1334
1348
|
}
|
|
1335
1349
|
if (request2.reason?.length) {
|
|
1336
1350
|
headers["X-Audit-Log-Reason"] = encodeURIComponent(request2.reason);
|
|
@@ -1433,7 +1447,7 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
|
|
|
1433
1447
|
};
|
|
1434
1448
|
|
|
1435
1449
|
// src/shared.ts
|
|
1436
|
-
var version = "3.0.0-dev.
|
|
1450
|
+
var version = "3.0.0-dev.1736769922-18ab0cf62";
|
|
1437
1451
|
|
|
1438
1452
|
// src/index.ts
|
|
1439
1453
|
globalThis.FormData ??= import_undici2.FormData;
|
|
@@ -1444,6 +1458,7 @@ setDefaultStrategy((0, import_util2.shouldUseGlobalFetchAndWebSocket)() ? fetch
|
|
|
1444
1458
|
ALLOWED_EXTENSIONS,
|
|
1445
1459
|
ALLOWED_SIZES,
|
|
1446
1460
|
ALLOWED_STICKER_EXTENSIONS,
|
|
1461
|
+
AUTH_UUID_NAMESPACE,
|
|
1447
1462
|
BurstHandlerMajorIdKey,
|
|
1448
1463
|
CDN,
|
|
1449
1464
|
DefaultRestOptions,
|