@discordjs/rest 2.3.1-dev.1717114182-29a50bb47 → 2.4.0-dev.1717589083-346d1be72

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 CHANGED
@@ -511,9 +511,16 @@ declare class CDN {
511
511
  * @param options - Optional options for the avatar
512
512
  */
513
513
  avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
514
+ /**
515
+ * Generates a user avatar decoration preset URL.
516
+ *
517
+ * @param asset - The avatar decoration hash
518
+ */
519
+ avatarDecoration(asset: string): string;
514
520
  /**
515
521
  * Generates a user avatar decoration URL.
516
522
  *
523
+ * @deprecated This overload is deprecated. Pass a hash instead.
517
524
  * @param userId - The id of the user
518
525
  * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
519
526
  * @param options - Optional options for the avatar decoration
package/dist/index.d.ts CHANGED
@@ -511,9 +511,16 @@ declare class CDN {
511
511
  * @param options - Optional options for the avatar
512
512
  */
513
513
  avatar(id: string, avatarHash: string, options?: Readonly<ImageURLOptions>): string;
514
+ /**
515
+ * Generates a user avatar decoration preset URL.
516
+ *
517
+ * @param asset - The avatar decoration hash
518
+ */
519
+ avatarDecoration(asset: string): string;
514
520
  /**
515
521
  * Generates a user avatar decoration URL.
516
522
  *
523
+ * @deprecated This overload is deprecated. Pass a hash instead.
517
524
  * @param userId - The id of the user
518
525
  * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
519
526
  * @param options - Optional options for the avatar decoration
package/dist/index.js CHANGED
@@ -124,7 +124,7 @@ __name(resolveBody, "resolveBody");
124
124
  // src/lib/utils/constants.ts
125
125
  var import_util = require("@discordjs/util");
126
126
  var import_v10 = require("discord-api-types/v10");
127
- var DefaultUserAgent = `DiscordBot (https://discord.js.org, 2.3.1-dev.1717114182-29a50bb47)`;
127
+ var DefaultUserAgent = `DiscordBot (https://discord.js.org, 2.4.0-dev.1717589083-346d1be72)`;
128
128
  var DefaultUserAgentAppendix = (0, import_util.getUserAgentAppendix)();
129
129
  var DefaultRestOptions = {
130
130
  agent: null,
@@ -239,13 +239,11 @@ function serializeSearchParam(value) {
239
239
  case "boolean":
240
240
  return value.toString();
241
241
  case "object":
242
- if (value === null)
243
- return null;
242
+ if (value === null) return null;
244
243
  if (value instanceof Date) {
245
244
  return Number.isNaN(value.getTime()) ? null : value.toISOString();
246
245
  }
247
- if (typeof value.toString === "function" && value.toString !== Object.prototype.toString)
248
- return value.toString();
246
+ if (typeof value.toString === "function" && value.toString !== Object.prototype.toString) return value.toString();
249
247
  return null;
250
248
  default:
251
249
  return null;
@@ -254,12 +252,10 @@ function serializeSearchParam(value) {
254
252
  __name(serializeSearchParam, "serializeSearchParam");
255
253
  function makeURLSearchParams(options) {
256
254
  const params = new URLSearchParams();
257
- if (!options)
258
- return params;
255
+ if (!options) return params;
259
256
  for (const [key, value] of Object.entries(options)) {
260
257
  const serialized = serializeSearchParam(value);
261
- if (serialized !== null)
262
- params.append(key, serialized);
258
+ if (serialized !== null) params.append(key, serialized);
263
259
  }
264
260
  return params;
265
261
  }
@@ -273,10 +269,8 @@ async function parseResponse(res) {
273
269
  __name(parseResponse, "parseResponse");
274
270
  function hasSublimit(bucketRoute, body, method) {
275
271
  if (bucketRoute === "/channels/:id") {
276
- if (typeof body !== "object" || body === null)
277
- return false;
278
- if (method !== "PATCH" /* Patch */)
279
- return false;
272
+ if (typeof body !== "object" || body === null) return false;
273
+ if (method !== "PATCH" /* Patch */) return false;
280
274
  const castedBody = body;
281
275
  return ["name", "topic"].some((key) => Reflect.has(castedBody, key));
282
276
  }
@@ -284,15 +278,13 @@ function hasSublimit(bucketRoute, body, method) {
284
278
  }
285
279
  __name(hasSublimit, "hasSublimit");
286
280
  function shouldRetry(error) {
287
- if (error.name === "AbortError")
288
- return true;
281
+ if (error.name === "AbortError") return true;
289
282
  return "code" in error && error.code === "ECONNRESET" || error.message.includes("ECONNRESET");
290
283
  }
291
284
  __name(shouldRetry, "shouldRetry");
292
285
  async function onRateLimit(manager, rateLimitData) {
293
286
  const { options } = manager;
294
- if (!options.rejectOnRateLimit)
295
- return;
287
+ if (!options.rejectOnRateLimit) return;
296
288
  const shouldThrow = typeof options.rejectOnRateLimit === "function" ? await options.rejectOnRateLimit(rateLimitData) : options.rejectOnRateLimit.some((route) => rateLimitData.route.startsWith(route.toLowerCase()));
297
289
  if (shouldThrow) {
298
290
  throw new RateLimitError(rateLimitData);
@@ -369,15 +361,11 @@ var CDN = class {
369
361
  avatar(id, avatarHash, options) {
370
362
  return this.dynamicMakeURL(`/avatars/${id}/${avatarHash}`, avatarHash, options);
371
363
  }
372
- /**
373
- * Generates a user avatar decoration URL.
374
- *
375
- * @param userId - The id of the user
376
- * @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
377
- * @param options - Optional options for the avatar decoration
378
- */
379
- avatarDecoration(userId, userAvatarDecoration, options) {
380
- return this.makeURL(`/avatar-decorations/${userId}/${userAvatarDecoration}`, options);
364
+ avatarDecoration(userIdOrAsset, userAvatarDecoration, options) {
365
+ if (userAvatarDecoration) {
366
+ return this.makeURL(`/avatar-decorations/${userIdOrAsset}/${userAvatarDecoration}`, options);
367
+ }
368
+ return this.makeURL(`/avatar-decoration-presets/${userIdOrAsset}`, { extension: "png" });
381
369
  }
382
370
  /**
383
371
  * Generates a banner URL, e.g. for a user or a guild.
@@ -679,17 +667,14 @@ async function makeNetworkRequest(manager, routeId, url, options, requestData, r
679
667
  const controller = new AbortController();
680
668
  const timeout = setTimeout(() => controller.abort(), manager.options.timeout);
681
669
  if (requestData.signal) {
682
- if (requestData.signal.aborted)
683
- controller.abort();
684
- else
685
- requestData.signal.addEventListener("abort", () => controller.abort());
670
+ if (requestData.signal.aborted) controller.abort();
671
+ else requestData.signal.addEventListener("abort", () => controller.abort());
686
672
  }
687
673
  let res;
688
674
  try {
689
675
  res = await manager.options.makeRequest(url, { ...options, signal: controller.signal });
690
676
  } catch (error) {
691
- if (!(error instanceof Error))
692
- throw error;
677
+ if (!(error instanceof Error)) throw error;
693
678
  if (shouldRetry(error) && retries !== manager.options.retries) {
694
679
  return null;
695
680
  }
@@ -791,8 +776,7 @@ var BurstHandler = class {
791
776
  let retryAfter = 0;
792
777
  const retry = res.headers.get("Retry-After");
793
778
  const offset = normalizeRateLimitOffset(this.manager.options.offset, routeId.bucketRoute);
794
- if (retry)
795
- retryAfter = Number(retry) * 1e3 + offset;
779
+ if (retry) retryAfter = Number(retry) * 1e3 + offset;
796
780
  if (status === 401 || status === 403 || status === 429) {
797
781
  incrementInvalidCount(this.manager);
798
782
  }
@@ -1045,8 +1029,7 @@ var SequentialHandler = class {
1045
1029
  this.limit = limit ? Number(limit) : Number.POSITIVE_INFINITY;
1046
1030
  this.remaining = remaining ? Number(remaining) : 1;
1047
1031
  this.reset = reset ? Number(reset) * 1e3 + Date.now() + offset : Date.now();
1048
- if (retry)
1049
- retryAfter = Number(retry) * 1e3 + offset;
1032
+ if (retry) retryAfter = Number(retry) * 1e3 + offset;
1050
1033
  if (hash && hash !== this.hash) {
1051
1034
  this.debug(["Received bucket hash update", ` Old Hash : ${this.hash}`, ` New Hash : ${hash}`].join("\n"));
1052
1035
  this.manager.hashes.set(`${method}:${routeId.bucketRoute}`, { value: hash, lastAccess: Date.now() });
@@ -1194,8 +1177,7 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
1194
1177
  const sweptHashes = new import_collection.Collection();
1195
1178
  const currentDate = Date.now();
1196
1179
  this.hashes.sweep((val, key) => {
1197
- if (val.lastAccess === -1)
1198
- return false;
1180
+ if (val.lastAccess === -1) return false;
1199
1181
  const shouldSweep = Math.floor(currentDate - val.lastAccess) > this.options.hashLifetime;
1200
1182
  if (shouldSweep) {
1201
1183
  sweptHashes.set(key, val);
@@ -1454,7 +1436,7 @@ var REST = class _REST extends import_async_event_emitter.AsyncEventEmitter {
1454
1436
  };
1455
1437
 
1456
1438
  // src/shared.ts
1457
- var version = "2.3.1-dev.1717114182-29a50bb47";
1439
+ var version = "2.4.0-dev.1717589083-346d1be72";
1458
1440
 
1459
1441
  // src/index.ts
1460
1442
  globalThis.FormData ??= import_undici2.FormData;