@discordjs/rest 3.0.0-dev.1733443982-00dceb32b → 3.0.0-dev.1733745920-310563ba0
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 +2 -25
- package/dist/index.d.ts +2 -25
- package/dist/index.js +161 -177
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -176
- package/dist/index.mjs.map +1 -1
- package/dist/web.d.mts +2 -25
- package/dist/web.d.ts +2 -25
- package/dist/web.js +161 -177
- package/dist/web.js.map +1 -1
- package/dist/web.mjs +161 -176
- package/dist/web.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -438,12 +438,6 @@ declare const OverwrittenMimeTypes: {
|
|
|
438
438
|
readonly 'image/apng': "image/png";
|
|
439
439
|
};
|
|
440
440
|
declare const BurstHandlerMajorIdKey = "burst";
|
|
441
|
-
/**
|
|
442
|
-
* Prefix for deprecation warnings.
|
|
443
|
-
*
|
|
444
|
-
* @internal
|
|
445
|
-
*/
|
|
446
|
-
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
|
|
447
441
|
|
|
448
442
|
/**
|
|
449
443
|
* The options used for image URLs
|
|
@@ -531,15 +525,6 @@ declare class CDN {
|
|
|
531
525
|
* @param asset - The avatar decoration hash
|
|
532
526
|
*/
|
|
533
527
|
avatarDecoration(asset: string): string;
|
|
534
|
-
/**
|
|
535
|
-
* Generates a user avatar decoration URL.
|
|
536
|
-
*
|
|
537
|
-
* @deprecated This overload is deprecated. Pass a hash instead.
|
|
538
|
-
* @param userId - The id of the user
|
|
539
|
-
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
|
540
|
-
* @param options - Optional options for the avatar decoration
|
|
541
|
-
*/
|
|
542
|
-
avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string;
|
|
543
528
|
/**
|
|
544
529
|
* Generates a banner URL, e.g. for a user or a guild.
|
|
545
530
|
*
|
|
@@ -574,20 +559,12 @@ declare class CDN {
|
|
|
574
559
|
*/
|
|
575
560
|
discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
|
576
561
|
/**
|
|
577
|
-
* Generates an emoji's URL
|
|
562
|
+
* Generates an emoji's URL.
|
|
578
563
|
*
|
|
579
564
|
* @param emojiId - The emoji id
|
|
580
565
|
* @param options - Optional options for the emoji
|
|
581
566
|
*/
|
|
582
567
|
emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;
|
|
583
|
-
/**
|
|
584
|
-
* Generates an emoji's URL for an emoji.
|
|
585
|
-
*
|
|
586
|
-
* @param emojiId - The emoji id
|
|
587
|
-
* @param extension - The extension of the emoji
|
|
588
|
-
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
|
|
589
|
-
*/
|
|
590
|
-
emoji(emojiId: string, extension?: ImageExtension): string;
|
|
591
568
|
/**
|
|
592
569
|
* Generates a guild member avatar URL.
|
|
593
570
|
*
|
|
@@ -923,4 +900,4 @@ declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
|
|
923
900
|
*/
|
|
924
901
|
declare const version: string;
|
|
925
902
|
|
|
926
|
-
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN,
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -438,12 +438,6 @@ declare const OverwrittenMimeTypes: {
|
|
|
438
438
|
readonly 'image/apng': "image/png";
|
|
439
439
|
};
|
|
440
440
|
declare const BurstHandlerMajorIdKey = "burst";
|
|
441
|
-
/**
|
|
442
|
-
* Prefix for deprecation warnings.
|
|
443
|
-
*
|
|
444
|
-
* @internal
|
|
445
|
-
*/
|
|
446
|
-
declare const DEPRECATION_WARNING_PREFIX: "DeprecationWarning";
|
|
447
441
|
|
|
448
442
|
/**
|
|
449
443
|
* The options used for image URLs
|
|
@@ -531,15 +525,6 @@ declare class CDN {
|
|
|
531
525
|
* @param asset - The avatar decoration hash
|
|
532
526
|
*/
|
|
533
527
|
avatarDecoration(asset: string): string;
|
|
534
|
-
/**
|
|
535
|
-
* Generates a user avatar decoration URL.
|
|
536
|
-
*
|
|
537
|
-
* @deprecated This overload is deprecated. Pass a hash instead.
|
|
538
|
-
* @param userId - The id of the user
|
|
539
|
-
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
|
540
|
-
* @param options - Optional options for the avatar decoration
|
|
541
|
-
*/
|
|
542
|
-
avatarDecoration(userId: string, userAvatarDecoration: string, options?: Readonly<BaseImageURLOptions>): string;
|
|
543
528
|
/**
|
|
544
529
|
* Generates a banner URL, e.g. for a user or a guild.
|
|
545
530
|
*
|
|
@@ -574,20 +559,12 @@ declare class CDN {
|
|
|
574
559
|
*/
|
|
575
560
|
discoverySplash(guildId: string, splashHash: string, options?: Readonly<BaseImageURLOptions>): string;
|
|
576
561
|
/**
|
|
577
|
-
* Generates an emoji's URL
|
|
562
|
+
* Generates an emoji's URL.
|
|
578
563
|
*
|
|
579
564
|
* @param emojiId - The emoji id
|
|
580
565
|
* @param options - Optional options for the emoji
|
|
581
566
|
*/
|
|
582
567
|
emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;
|
|
583
|
-
/**
|
|
584
|
-
* Generates an emoji's URL for an emoji.
|
|
585
|
-
*
|
|
586
|
-
* @param emojiId - The emoji id
|
|
587
|
-
* @param extension - The extension of the emoji
|
|
588
|
-
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
|
|
589
|
-
*/
|
|
590
|
-
emoji(emojiId: string, extension?: ImageExtension): string;
|
|
591
568
|
/**
|
|
592
569
|
* Generates a guild member avatar URL.
|
|
593
570
|
*
|
|
@@ -923,4 +900,4 @@ declare function calculateUserDefaultAvatarIndex(userId: Snowflake): number;
|
|
|
923
900
|
*/
|
|
924
901
|
declare const version: string;
|
|
925
902
|
|
|
926
|
-
export { ALLOWED_EXTENSIONS, ALLOWED_SIZES, ALLOWED_STICKER_EXTENSIONS, type APIRequest, type BaseImageURLOptions, BurstHandlerMajorIdKey, CDN,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,6 @@ __export(src_exports, {
|
|
|
26
26
|
ALLOWED_STICKER_EXTENSIONS: () => ALLOWED_STICKER_EXTENSIONS,
|
|
27
27
|
BurstHandlerMajorIdKey: () => BurstHandlerMajorIdKey,
|
|
28
28
|
CDN: () => CDN,
|
|
29
|
-
DEPRECATION_WARNING_PREFIX: () => DEPRECATION_WARNING_PREFIX,
|
|
30
29
|
DefaultRestOptions: () => DefaultRestOptions,
|
|
31
30
|
DefaultUserAgent: () => DefaultUserAgent,
|
|
32
31
|
DefaultUserAgentAppendix: () => DefaultUserAgentAppendix,
|
|
@@ -124,7 +123,7 @@ __name(resolveBody, "resolveBody");
|
|
|
124
123
|
// src/lib/utils/constants.ts
|
|
125
124
|
var import_util = require("@discordjs/util");
|
|
126
125
|
var import_v10 = require("discord-api-types/v10");
|
|
127
|
-
var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.
|
|
126
|
+
var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1733745920-310563ba0)`;
|
|
128
127
|
var DefaultUserAgentAppendix = (0, import_util.getUserAgentAppendix)();
|
|
129
128
|
var DefaultRestOptions = {
|
|
130
129
|
agent: null,
|
|
@@ -168,163 +167,8 @@ var OverwrittenMimeTypes = {
|
|
|
168
167
|
"image/apng": "image/png"
|
|
169
168
|
};
|
|
170
169
|
var BurstHandlerMajorIdKey = "burst";
|
|
171
|
-
var DEPRECATION_WARNING_PREFIX = "DeprecationWarning";
|
|
172
|
-
|
|
173
|
-
// src/lib/errors/RateLimitError.ts
|
|
174
|
-
var RateLimitError = class _RateLimitError extends Error {
|
|
175
|
-
static {
|
|
176
|
-
__name(this, "RateLimitError");
|
|
177
|
-
}
|
|
178
|
-
timeToReset;
|
|
179
|
-
limit;
|
|
180
|
-
method;
|
|
181
|
-
hash;
|
|
182
|
-
url;
|
|
183
|
-
route;
|
|
184
|
-
majorParameter;
|
|
185
|
-
global;
|
|
186
|
-
retryAfter;
|
|
187
|
-
sublimitTimeout;
|
|
188
|
-
scope;
|
|
189
|
-
constructor({
|
|
190
|
-
timeToReset,
|
|
191
|
-
limit,
|
|
192
|
-
method,
|
|
193
|
-
hash,
|
|
194
|
-
url,
|
|
195
|
-
route,
|
|
196
|
-
majorParameter,
|
|
197
|
-
global,
|
|
198
|
-
retryAfter,
|
|
199
|
-
sublimitTimeout,
|
|
200
|
-
scope
|
|
201
|
-
}) {
|
|
202
|
-
super();
|
|
203
|
-
this.timeToReset = timeToReset;
|
|
204
|
-
this.limit = limit;
|
|
205
|
-
this.method = method;
|
|
206
|
-
this.hash = hash;
|
|
207
|
-
this.url = url;
|
|
208
|
-
this.route = route;
|
|
209
|
-
this.majorParameter = majorParameter;
|
|
210
|
-
this.global = global;
|
|
211
|
-
this.retryAfter = retryAfter;
|
|
212
|
-
this.sublimitTimeout = sublimitTimeout;
|
|
213
|
-
this.scope = scope;
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* The name of the error
|
|
217
|
-
*/
|
|
218
|
-
get name() {
|
|
219
|
-
return `${_RateLimitError.name}[${this.route}]`;
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
// src/lib/utils/types.ts
|
|
224
|
-
var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => {
|
|
225
|
-
RequestMethod2["Delete"] = "DELETE";
|
|
226
|
-
RequestMethod2["Get"] = "GET";
|
|
227
|
-
RequestMethod2["Patch"] = "PATCH";
|
|
228
|
-
RequestMethod2["Post"] = "POST";
|
|
229
|
-
RequestMethod2["Put"] = "PUT";
|
|
230
|
-
return RequestMethod2;
|
|
231
|
-
})(RequestMethod || {});
|
|
232
|
-
|
|
233
|
-
// src/lib/utils/utils.ts
|
|
234
|
-
function serializeSearchParam(value) {
|
|
235
|
-
switch (typeof value) {
|
|
236
|
-
case "string":
|
|
237
|
-
return value;
|
|
238
|
-
case "number":
|
|
239
|
-
case "bigint":
|
|
240
|
-
case "boolean":
|
|
241
|
-
return value.toString();
|
|
242
|
-
case "object":
|
|
243
|
-
if (value === null) return null;
|
|
244
|
-
if (value instanceof Date) {
|
|
245
|
-
return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
246
|
-
}
|
|
247
|
-
if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) return value.toString();
|
|
248
|
-
return null;
|
|
249
|
-
default:
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
__name(serializeSearchParam, "serializeSearchParam");
|
|
254
|
-
function makeURLSearchParams(options) {
|
|
255
|
-
const params = new URLSearchParams();
|
|
256
|
-
if (!options) return params;
|
|
257
|
-
for (const [key, value] of Object.entries(options)) {
|
|
258
|
-
const serialized = serializeSearchParam(value);
|
|
259
|
-
if (serialized !== null) params.append(key, serialized);
|
|
260
|
-
}
|
|
261
|
-
return params;
|
|
262
|
-
}
|
|
263
|
-
__name(makeURLSearchParams, "makeURLSearchParams");
|
|
264
|
-
async function parseResponse(res) {
|
|
265
|
-
if (res.headers.get("Content-Type")?.startsWith("application/json")) {
|
|
266
|
-
return res.json();
|
|
267
|
-
}
|
|
268
|
-
return res.arrayBuffer();
|
|
269
|
-
}
|
|
270
|
-
__name(parseResponse, "parseResponse");
|
|
271
|
-
function hasSublimit(bucketRoute, body, method) {
|
|
272
|
-
if (bucketRoute === "/channels/:id") {
|
|
273
|
-
if (typeof body !== "object" || body === null) return false;
|
|
274
|
-
if (method !== "PATCH" /* Patch */) return false;
|
|
275
|
-
const castedBody = body;
|
|
276
|
-
return ["name", "topic"].some((key) => Reflect.has(castedBody, key));
|
|
277
|
-
}
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
280
|
-
__name(hasSublimit, "hasSublimit");
|
|
281
|
-
function shouldRetry(error) {
|
|
282
|
-
if (error.name === "AbortError") return true;
|
|
283
|
-
return "code" in error && error.code === "ECONNRESET" || error.message.includes("ECONNRESET");
|
|
284
|
-
}
|
|
285
|
-
__name(shouldRetry, "shouldRetry");
|
|
286
|
-
async function onRateLimit(manager, rateLimitData) {
|
|
287
|
-
const { options } = manager;
|
|
288
|
-
if (!options.rejectOnRateLimit) return;
|
|
289
|
-
const shouldThrow = typeof options.rejectOnRateLimit === "function" ? await options.rejectOnRateLimit(rateLimitData) : options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));
|
|
290
|
-
if (shouldThrow) {
|
|
291
|
-
throw new RateLimitError(rateLimitData);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
__name(onRateLimit, "onRateLimit");
|
|
295
|
-
function calculateUserDefaultAvatarIndex(userId) {
|
|
296
|
-
return Number(BigInt(userId) >> 22n) % 6;
|
|
297
|
-
}
|
|
298
|
-
__name(calculateUserDefaultAvatarIndex, "calculateUserDefaultAvatarIndex");
|
|
299
|
-
async function sleep(ms) {
|
|
300
|
-
return new Promise((resolve) => {
|
|
301
|
-
setTimeout(() => resolve(), ms);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
__name(sleep, "sleep");
|
|
305
|
-
function isBufferLike(value) {
|
|
306
|
-
return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;
|
|
307
|
-
}
|
|
308
|
-
__name(isBufferLike, "isBufferLike");
|
|
309
|
-
function deprecationWarning(message) {
|
|
310
|
-
if (typeof globalThis.process === "undefined") {
|
|
311
|
-
console.warn(`${DEPRECATION_WARNING_PREFIX}: ${message}`);
|
|
312
|
-
} else {
|
|
313
|
-
process.emitWarning(message, DEPRECATION_WARNING_PREFIX);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
__name(deprecationWarning, "deprecationWarning");
|
|
317
|
-
function normalizeRateLimitOffset(offset, route) {
|
|
318
|
-
if (typeof offset === "number") {
|
|
319
|
-
return Math.max(0, offset);
|
|
320
|
-
}
|
|
321
|
-
const result = offset(route);
|
|
322
|
-
return Math.max(0, result);
|
|
323
|
-
}
|
|
324
|
-
__name(normalizeRateLimitOffset, "normalizeRateLimitOffset");
|
|
325
170
|
|
|
326
171
|
// src/lib/CDN.ts
|
|
327
|
-
var deprecationEmittedForEmoji = false;
|
|
328
172
|
var CDN = class {
|
|
329
173
|
constructor(cdn = DefaultRestOptions.cdn, mediaProxy = DefaultRestOptions.mediaProxy) {
|
|
330
174
|
this.cdn = cdn;
|
|
@@ -363,11 +207,13 @@ var CDN = class {
|
|
|
363
207
|
avatar(id, avatarHash, options) {
|
|
364
208
|
return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);
|
|
365
209
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
210
|
+
/**
|
|
211
|
+
* Generates a user avatar decoration preset URL.
|
|
212
|
+
*
|
|
213
|
+
* @param asset - The avatar decoration hash
|
|
214
|
+
*/
|
|
215
|
+
avatarDecoration(asset) {
|
|
216
|
+
return this.makeURL(`/avatar-decoration-presets/${asset}`, { extension: "png" });
|
|
371
217
|
}
|
|
372
218
|
/**
|
|
373
219
|
* Generates a banner URL, e.g. for a user or a guild.
|
|
@@ -410,20 +256,14 @@ var CDN = class {
|
|
|
410
256
|
discoverySplash(guildId, splashHash, options) {
|
|
411
257
|
return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);
|
|
412
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* Generates an emoji's URL.
|
|
261
|
+
*
|
|
262
|
+
* @param emojiId - The emoji id
|
|
263
|
+
* @param options - Optional options for the emoji
|
|
264
|
+
*/
|
|
413
265
|
emoji(emojiId, options) {
|
|
414
|
-
|
|
415
|
-
if (typeof options === "string") {
|
|
416
|
-
if (!deprecationEmittedForEmoji) {
|
|
417
|
-
deprecationWarning(
|
|
418
|
-
"Passing a string for the second parameter of CDN#emoji() is deprecated. Use an object instead."
|
|
419
|
-
);
|
|
420
|
-
deprecationEmittedForEmoji = true;
|
|
421
|
-
}
|
|
422
|
-
resolvedOptions = { extension: options };
|
|
423
|
-
} else {
|
|
424
|
-
resolvedOptions = options;
|
|
425
|
-
}
|
|
426
|
-
return this.makeURL(`/emojis/${emojiId}`, resolvedOptions);
|
|
266
|
+
return this.makeURL(`/emojis/${emojiId}`, options);
|
|
427
267
|
}
|
|
428
268
|
/**
|
|
429
269
|
* Generates a guild member avatar URL.
|
|
@@ -651,12 +491,157 @@ var HTTPError = class _HTTPError extends Error {
|
|
|
651
491
|
name = _HTTPError.name;
|
|
652
492
|
};
|
|
653
493
|
|
|
494
|
+
// src/lib/errors/RateLimitError.ts
|
|
495
|
+
var RateLimitError = class _RateLimitError extends Error {
|
|
496
|
+
static {
|
|
497
|
+
__name(this, "RateLimitError");
|
|
498
|
+
}
|
|
499
|
+
timeToReset;
|
|
500
|
+
limit;
|
|
501
|
+
method;
|
|
502
|
+
hash;
|
|
503
|
+
url;
|
|
504
|
+
route;
|
|
505
|
+
majorParameter;
|
|
506
|
+
global;
|
|
507
|
+
retryAfter;
|
|
508
|
+
sublimitTimeout;
|
|
509
|
+
scope;
|
|
510
|
+
constructor({
|
|
511
|
+
timeToReset,
|
|
512
|
+
limit,
|
|
513
|
+
method,
|
|
514
|
+
hash,
|
|
515
|
+
url,
|
|
516
|
+
route,
|
|
517
|
+
majorParameter,
|
|
518
|
+
global,
|
|
519
|
+
retryAfter,
|
|
520
|
+
sublimitTimeout,
|
|
521
|
+
scope
|
|
522
|
+
}) {
|
|
523
|
+
super();
|
|
524
|
+
this.timeToReset = timeToReset;
|
|
525
|
+
this.limit = limit;
|
|
526
|
+
this.method = method;
|
|
527
|
+
this.hash = hash;
|
|
528
|
+
this.url = url;
|
|
529
|
+
this.route = route;
|
|
530
|
+
this.majorParameter = majorParameter;
|
|
531
|
+
this.global = global;
|
|
532
|
+
this.retryAfter = retryAfter;
|
|
533
|
+
this.sublimitTimeout = sublimitTimeout;
|
|
534
|
+
this.scope = scope;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* The name of the error
|
|
538
|
+
*/
|
|
539
|
+
get name() {
|
|
540
|
+
return `${_RateLimitError.name}[${this.route}]`;
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
|
|
654
544
|
// src/lib/REST.ts
|
|
655
545
|
var import_collection = require("@discordjs/collection");
|
|
656
546
|
var import_snowflake = require("@sapphire/snowflake");
|
|
657
547
|
var import_async_event_emitter = require("@vladfrangu/async_event_emitter");
|
|
658
548
|
var import_magic_bytes = require("magic-bytes.js");
|
|
659
549
|
|
|
550
|
+
// src/lib/utils/types.ts
|
|
551
|
+
var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => {
|
|
552
|
+
RequestMethod2["Delete"] = "DELETE";
|
|
553
|
+
RequestMethod2["Get"] = "GET";
|
|
554
|
+
RequestMethod2["Patch"] = "PATCH";
|
|
555
|
+
RequestMethod2["Post"] = "POST";
|
|
556
|
+
RequestMethod2["Put"] = "PUT";
|
|
557
|
+
return RequestMethod2;
|
|
558
|
+
})(RequestMethod || {});
|
|
559
|
+
|
|
560
|
+
// src/lib/utils/utils.ts
|
|
561
|
+
function serializeSearchParam(value) {
|
|
562
|
+
switch (typeof value) {
|
|
563
|
+
case "string":
|
|
564
|
+
return value;
|
|
565
|
+
case "number":
|
|
566
|
+
case "bigint":
|
|
567
|
+
case "boolean":
|
|
568
|
+
return value.toString();
|
|
569
|
+
case "object":
|
|
570
|
+
if (value === null) return null;
|
|
571
|
+
if (value instanceof Date) {
|
|
572
|
+
return Number.isNaN(value.getTime()) ? null : value.toISOString();
|
|
573
|
+
}
|
|
574
|
+
if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) return value.toString();
|
|
575
|
+
return null;
|
|
576
|
+
default:
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
__name(serializeSearchParam, "serializeSearchParam");
|
|
581
|
+
function makeURLSearchParams(options) {
|
|
582
|
+
const params = new URLSearchParams();
|
|
583
|
+
if (!options) return params;
|
|
584
|
+
for (const [key, value] of Object.entries(options)) {
|
|
585
|
+
const serialized = serializeSearchParam(value);
|
|
586
|
+
if (serialized !== null) params.append(key, serialized);
|
|
587
|
+
}
|
|
588
|
+
return params;
|
|
589
|
+
}
|
|
590
|
+
__name(makeURLSearchParams, "makeURLSearchParams");
|
|
591
|
+
async function parseResponse(res) {
|
|
592
|
+
if (res.headers.get("Content-Type")?.startsWith("application/json")) {
|
|
593
|
+
return res.json();
|
|
594
|
+
}
|
|
595
|
+
return res.arrayBuffer();
|
|
596
|
+
}
|
|
597
|
+
__name(parseResponse, "parseResponse");
|
|
598
|
+
function hasSublimit(bucketRoute, body, method) {
|
|
599
|
+
if (bucketRoute === "/channels/:id") {
|
|
600
|
+
if (typeof body !== "object" || body === null) return false;
|
|
601
|
+
if (method !== "PATCH" /* Patch */) return false;
|
|
602
|
+
const castedBody = body;
|
|
603
|
+
return ["name", "topic"].some((key) => Reflect.has(castedBody, key));
|
|
604
|
+
}
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
__name(hasSublimit, "hasSublimit");
|
|
608
|
+
function shouldRetry(error) {
|
|
609
|
+
if (error.name === "AbortError") return true;
|
|
610
|
+
return "code" in error && error.code === "ECONNRESET" || error.message.includes("ECONNRESET");
|
|
611
|
+
}
|
|
612
|
+
__name(shouldRetry, "shouldRetry");
|
|
613
|
+
async function onRateLimit(manager, rateLimitData) {
|
|
614
|
+
const { options } = manager;
|
|
615
|
+
if (!options.rejectOnRateLimit) return;
|
|
616
|
+
const shouldThrow = typeof options.rejectOnRateLimit === "function" ? await options.rejectOnRateLimit(rateLimitData) : options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));
|
|
617
|
+
if (shouldThrow) {
|
|
618
|
+
throw new RateLimitError(rateLimitData);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
__name(onRateLimit, "onRateLimit");
|
|
622
|
+
function calculateUserDefaultAvatarIndex(userId) {
|
|
623
|
+
return Number(BigInt(userId) >> 22n) % 6;
|
|
624
|
+
}
|
|
625
|
+
__name(calculateUserDefaultAvatarIndex, "calculateUserDefaultAvatarIndex");
|
|
626
|
+
async function sleep(ms) {
|
|
627
|
+
return new Promise((resolve) => {
|
|
628
|
+
setTimeout(() => resolve(), ms);
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
__name(sleep, "sleep");
|
|
632
|
+
function isBufferLike(value) {
|
|
633
|
+
return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;
|
|
634
|
+
}
|
|
635
|
+
__name(isBufferLike, "isBufferLike");
|
|
636
|
+
function normalizeRateLimitOffset(offset, route) {
|
|
637
|
+
if (typeof offset === "number") {
|
|
638
|
+
return Math.max(0, offset);
|
|
639
|
+
}
|
|
640
|
+
const result = offset(route);
|
|
641
|
+
return Math.max(0, result);
|
|
642
|
+
}
|
|
643
|
+
__name(normalizeRateLimitOffset, "normalizeRateLimitOffset");
|
|
644
|
+
|
|
660
645
|
// src/lib/handlers/Shared.ts
|
|
661
646
|
var invalidCount = 0;
|
|
662
647
|
var invalidCountResetTime = null;
|
|
@@ -1448,7 +1433,7 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
|
|
|
1448
1433
|
};
|
|
1449
1434
|
|
|
1450
1435
|
// src/shared.ts
|
|
1451
|
-
var version = "3.0.0-dev.
|
|
1436
|
+
var version = "3.0.0-dev.1733745920-310563ba0";
|
|
1452
1437
|
|
|
1453
1438
|
// src/index.ts
|
|
1454
1439
|
globalThis.FormData ??= import_undici2.FormData;
|
|
@@ -1461,7 +1446,6 @@ setDefaultStrategy((0, import_util2.shouldUseGlobalFetchAndWebSocket)() ? fetch
|
|
|
1461
1446
|
ALLOWED_STICKER_EXTENSIONS,
|
|
1462
1447
|
BurstHandlerMajorIdKey,
|
|
1463
1448
|
CDN,
|
|
1464
|
-
DEPRECATION_WARNING_PREFIX,
|
|
1465
1449
|
DefaultRestOptions,
|
|
1466
1450
|
DefaultUserAgent,
|
|
1467
1451
|
DefaultUserAgentAppendix,
|