@fluxerjs/core 3.0.0 → 3.2.0

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.mjs CHANGED
@@ -276,6 +276,7 @@ function toOverwriteWire(overwrite) {
276
276
  }
277
277
  function toChannelEditBody(options) {
278
278
  const body = {};
279
+ if (options.type !== void 0) body.type = options.type;
279
280
  if (options.name !== void 0) body.name = options.name;
280
281
  if (options.topic !== void 0) body.topic = options.topic;
281
282
  if (options.url !== void 0) body.url = options.url;
@@ -611,6 +612,13 @@ function toSudoBody(options) {
611
612
  return body;
612
613
  }
613
614
 
615
+ // src/Helpers/AuditReason.ts
616
+ var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
617
+ function auditReasonHeaders(reason) {
618
+ if (reason == null || reason === "") return {};
619
+ return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
620
+ }
621
+
614
622
  // src/Helpers/MessageUtils/Body.ts
615
623
  import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
616
624
  import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
@@ -1265,6 +1273,67 @@ var CDN_URL = "https://fluxerusercontent.com";
1265
1273
  var STATIC_CDN_URL = "https://fluxerstatic.com";
1266
1274
 
1267
1275
  // src/Helpers/Cdn.ts
1276
+ var CDN_SIZE_LADDER = [
1277
+ 16,
1278
+ 20,
1279
+ 22,
1280
+ 24,
1281
+ 28,
1282
+ 32,
1283
+ 40,
1284
+ 44,
1285
+ 48,
1286
+ 56,
1287
+ 60,
1288
+ 64,
1289
+ 80,
1290
+ 96,
1291
+ 100,
1292
+ 128,
1293
+ 160,
1294
+ 240,
1295
+ 256,
1296
+ 300,
1297
+ 320,
1298
+ 480,
1299
+ 512,
1300
+ 600,
1301
+ 640,
1302
+ 1024,
1303
+ 1280,
1304
+ 1536,
1305
+ 2048,
1306
+ 3072,
1307
+ 4096,
1308
+ 8192,
1309
+ 16384
1310
+ ];
1311
+ var CDN_ASSET_CLASS_RANGE = {
1312
+ icon: { min: 128, max: 1024 },
1313
+ banner: { min: 480, max: 2400 },
1314
+ emoji: { min: 32, max: 512 },
1315
+ sticker: { min: 128, max: 512 }
1316
+ };
1317
+ function nearestSize(requested, candidates) {
1318
+ let best = candidates[0];
1319
+ let bestDist = Math.abs(requested - best);
1320
+ for (let i = 1; i < candidates.length; i++) {
1321
+ const step = candidates[i];
1322
+ const dist = Math.abs(requested - step);
1323
+ if (dist < bestDist || dist === bestDist && step > best) {
1324
+ best = step;
1325
+ bestDist = dist;
1326
+ }
1327
+ }
1328
+ return best;
1329
+ }
1330
+ function snapCdnSize(requested, assetClass) {
1331
+ const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
1332
+ const snapped = nearestSize(requested, CDN_SIZE_LADDER);
1333
+ const clamped = Math.min(max, Math.max(min, snapped));
1334
+ const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
1335
+ return nearestSize(clamped, allowed);
1336
+ }
1268
1337
  function mediaBase(options) {
1269
1338
  return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1270
1339
  }
@@ -1276,13 +1345,15 @@ function getExtension(hash, options) {
1276
1345
  if (hash?.startsWith("a_")) return "gif";
1277
1346
  return ext;
1278
1347
  }
1279
- function appendSize(options) {
1280
- return options?.size ? `?size=${options.size}` : "";
1348
+ function appendSize(options, assetClass) {
1349
+ const size = options?.size;
1350
+ if (size == null || !Number.isFinite(size) || size <= 0) return "";
1351
+ return `?size=${snapCdnSize(size, assetClass)}`;
1281
1352
  }
1282
1353
  function cdnAvatarURL(userId, avatarHash, options) {
1283
1354
  if (!avatarHash) return null;
1284
1355
  const ext = getExtension(avatarHash, options);
1285
- const size = appendSize(options);
1356
+ const size = appendSize(options, "icon");
1286
1357
  return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1287
1358
  }
1288
1359
  function cdnDisplayAvatarURL(userId, avatarHash, options) {
@@ -1291,19 +1362,19 @@ function cdnDisplayAvatarURL(userId, avatarHash, options) {
1291
1362
  function cdnBannerURL(resourceId, bannerHash, options) {
1292
1363
  if (!bannerHash) return null;
1293
1364
  const ext = getExtension(bannerHash, options);
1294
- const size = appendSize(options);
1365
+ const size = appendSize(options, "banner");
1295
1366
  return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1296
1367
  }
1297
1368
  function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1298
1369
  if (!avatarHash) return null;
1299
1370
  const ext = getExtension(avatarHash, options);
1300
- const size = appendSize(options);
1371
+ const size = appendSize(options, "icon");
1301
1372
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1302
1373
  }
1303
1374
  function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1304
1375
  if (!bannerHash) return null;
1305
1376
  const ext = getExtension(bannerHash, options);
1306
- const size = appendSize(options);
1377
+ const size = appendSize(options, "banner");
1307
1378
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1308
1379
  }
1309
1380
  function cdnDefaultAvatarURL(userIdOrIndex, options) {
@@ -1312,16 +1383,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1312
1383
  }
1313
1384
  function cdnGuildAssetURL(kind, id, hash, options) {
1314
1385
  if (!hash) return null;
1315
- const size = options?.size ? `?size=${options.size}` : "";
1386
+ const assetClass = kind === "icons" ? "icon" : "banner";
1387
+ const size = appendSize(options, assetClass);
1316
1388
  return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1317
1389
  }
1318
1390
  function cdnEmojiURL(emojiId, animated, options) {
1319
1391
  const ext = animated ? "gif" : "png";
1320
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1392
+ const size = appendSize(options, "emoji");
1393
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
1321
1394
  }
1322
1395
  function cdnStickerURL(stickerId, animated, options) {
1323
1396
  const ext = animated ? "gif" : "png";
1324
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1397
+ const size = appendSize(options, "sticker");
1398
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
1325
1399
  }
1326
1400
 
1327
1401
  // src/Domain/Message/MessageSticker.ts
@@ -1549,6 +1623,8 @@ var Message = class _Message extends Base {
1549
1623
  mentionRoles;
1550
1624
  /** Client-side nonce for deduplication. */
1551
1625
  nonce;
1626
+ /** IDs of custom emojis in the message classified as explicit. */
1627
+ nsfwEmojis;
1552
1628
  /**
1553
1629
  * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1554
1630
  * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
@@ -1623,6 +1699,7 @@ var Message = class _Message extends Base {
1623
1699
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1624
1700
  this.mentionRoles = data.mention_roles ?? [];
1625
1701
  this.nonce = data.nonce ?? null;
1702
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1626
1703
  }
1627
1704
  /**
1628
1705
  * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
@@ -1655,6 +1732,7 @@ var Message = class _Message extends Base {
1655
1732
  this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1656
1733
  this.mentionRoles = data.mention_roles ?? [];
1657
1734
  this.nonce = data.nonce ?? null;
1735
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1658
1736
  }
1659
1737
  /**
1660
1738
  * Send a standalone message in this channel (not a reply).
@@ -1738,8 +1816,10 @@ var Message = class _Message extends Base {
1738
1816
  return this.client.channels.fetchMessage(this.channelId, this.id);
1739
1817
  }
1740
1818
  /** Delete this message. */
1741
- async delete() {
1742
- await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id));
1819
+ async delete(reason) {
1820
+ await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
1821
+ ...auditReasonHeaders(reason)
1822
+ });
1743
1823
  this.client._removeMessageFromCache(this.channelId, this.id);
1744
1824
  }
1745
1825
  /** Delete a specific attachment from this message. */
@@ -2043,6 +2123,29 @@ var MessageCollector = class _MessageCollector extends EventEmitter2 {
2043
2123
 
2044
2124
  // src/Domain/Channel/Attachments.ts
2045
2125
  import { Routes as Routes6 } from "@fluxerjs/types";
2126
+ var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
2127
+ var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
2128
+ function instanceLimitOverridesSnapshot(client) {
2129
+ const rules = client.instance.discovery?.limits?.rules;
2130
+ if (!rules?.length) return null;
2131
+ const snapshot = {};
2132
+ for (const rule of rules) {
2133
+ Object.assign(snapshot, rule.overrides);
2134
+ }
2135
+ return Object.keys(snapshot).length ? snapshot : null;
2136
+ }
2137
+ function assertBotAttachmentLimits(client, files) {
2138
+ const snapshot = instanceLimitOverridesSnapshot(client);
2139
+ for (const file of files) {
2140
+ const size = file.data.byteLength;
2141
+ if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
2142
+ const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
2143
+ throw new FluxerError(
2144
+ `Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
2145
+ { code: ErrorCodes.AttachmentTooLarge }
2146
+ );
2147
+ }
2148
+ }
2046
2149
  function asBytes(data) {
2047
2150
  const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
2048
2151
  const out = new Uint8Array(src.byteLength);
@@ -2062,6 +2165,7 @@ async function putBlob(url, body, contentType) {
2062
2165
  }
2063
2166
  }
2064
2167
  async function uploadAttachmentsForSend(client, channelId, files) {
2168
+ assertBotAttachmentLimits(client, files);
2065
2169
  const plan = await client.rest.post(
2066
2170
  Routes6.channelAttachments(channelId),
2067
2171
  {
@@ -2174,20 +2278,24 @@ var Channel = class extends Base {
2174
2278
  throw new Error("Channel.createDM not initialized");
2175
2279
  }
2176
2280
  /**
2177
- * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
2281
+ * Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
2178
2282
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
2179
2283
  */
2180
2284
  isTextBased() {
2181
- return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
2285
+ return this.type === ChannelType.GuildText || this.type === ChannelType.GuildAnnouncement || this.type === ChannelType.GuildVoice || this.type === ChannelType.DM || this.type === ChannelType.GroupDM || this.type === ChannelType.DMPersonalNotes;
2182
2286
  }
2183
- /** Check if this is a guild channel (text, voice, category, or link). */
2287
+ /** Check if this is a guild channel (text, announcement, voice, category, or link). */
2184
2288
  isGuild() {
2185
- return this.type === ChannelType.GuildText || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
2289
+ return this.type === ChannelType.GuildText || this.type === ChannelType.GuildAnnouncement || this.type === ChannelType.GuildVoice || this.type === ChannelType.GuildCategory || this.type === ChannelType.GuildLink;
2186
2290
  }
2187
2291
  /** Check if this is a guild text channel. */
2188
2292
  isText() {
2189
2293
  return this.type === ChannelType.GuildText;
2190
2294
  }
2295
+ /** Check if this is a guild announcement channel. */
2296
+ isAnnouncement() {
2297
+ return this.type === ChannelType.GuildAnnouncement;
2298
+ }
2191
2299
  /** Check if this is a category channel. */
2192
2300
  isCategory() {
2193
2301
  return this.type === ChannelType.GuildCategory;
@@ -2358,11 +2466,12 @@ var Channel = class extends Base {
2358
2466
  if (options?.silent) params.set("silent", "true");
2359
2467
  if (options?.deleteMessages) params.set("delete_messages", "true");
2360
2468
  const qs2 = params.toString();
2361
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2469
+ const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
2362
2470
  const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2363
2471
  await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2364
2472
  body,
2365
- auth: true
2473
+ auth: true,
2474
+ ...auditReasonHeaders(_reason)
2366
2475
  });
2367
2476
  this.client.channels.delete(this.id);
2368
2477
  this.client._clearMessageCache(this.id);
@@ -2527,7 +2636,7 @@ import {
2527
2636
  // src/Helpers/Instance.ts
2528
2637
  import { isRecord } from "@fluxerjs/util";
2529
2638
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2530
- api: "https://api.fluxer.app",
2639
+ api: "https://web.fluxer.app/api",
2531
2640
  api_client: "https://web.fluxer.app/api",
2532
2641
  api_public: "https://api.fluxer.app",
2533
2642
  gateway: "wss://gateway.fluxer.app",
@@ -2561,6 +2670,10 @@ function requireString(obj, key, path) {
2561
2670
  }
2562
2671
  return value;
2563
2672
  }
2673
+ var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
2674
+ function instanceDiscoveryUrl(origin) {
2675
+ return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
2676
+ }
2564
2677
  function normalizeApiOrigin(api) {
2565
2678
  const trimmed = api.trim().replace(/\/+$/, "");
2566
2679
  return trimmed.replace(/\/v\d+$/i, "");
@@ -2589,6 +2702,8 @@ function parseInstanceDiscovery(raw) {
2589
2702
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2590
2703
  }
2591
2704
  endpoints.api = normalizeApiOrigin(endpoints.api);
2705
+ endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2706
+ endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
2592
2707
  endpoints.invite = normalizeInviteBase(endpoints.invite);
2593
2708
  endpoints.media = endpoints.media.replace(/\/+$/, "");
2594
2709
  endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
@@ -2666,6 +2781,11 @@ function resolveInstanceEndpoints(input) {
2666
2781
  }
2667
2782
  }
2668
2783
  merged.api = normalizeApiOrigin(merged.api);
2784
+ merged.api_client = normalizeApiOrigin(merged.api_client);
2785
+ merged.api_public = normalizeApiOrigin(merged.api_public);
2786
+ if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
2787
+ merged.api_public = merged.api;
2788
+ }
2669
2789
  merged.invite = normalizeInviteBase(merged.invite);
2670
2790
  merged.media = merged.media.replace(/\/+$/, "");
2671
2791
  merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
@@ -2674,13 +2794,13 @@ function resolveInstanceEndpoints(input) {
2674
2794
  discovery: null
2675
2795
  });
2676
2796
  }
2677
- function resolveRestApi(instanceApi, restApi) {
2678
- const fromInstance = normalizeApiOrigin(instanceApi);
2797
+ function resolveRestApi(instanceApiPublic, restApi) {
2798
+ const fromInstance = normalizeApiOrigin(instanceApiPublic);
2679
2799
  if (restApi === void 0) return fromInstance;
2680
2800
  const fromRest = normalizeApiOrigin(restApi);
2681
2801
  if (fromRest !== fromInstance) {
2682
2802
  throw new FluxerError(
2683
- `Conflicting API hosts: instance.api (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2803
+ `Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2684
2804
  { code: ErrorCodes.ConflictingInstanceConfig }
2685
2805
  );
2686
2806
  }
@@ -3162,7 +3282,8 @@ var GuildChannel = class extends Channel {
3162
3282
  async edit(options) {
3163
3283
  const data = await this.client.rest.patch(Routes13.channel(this.id), {
3164
3284
  body: toChannelEditBody(options),
3165
- auth: true
3285
+ auth: true,
3286
+ ...auditReasonHeaders(options.reason)
3166
3287
  });
3167
3288
  this.name = data.name ?? this.name;
3168
3289
  this.parentId = data.parent_id ?? this.parentId;
@@ -3221,6 +3342,8 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3221
3342
  }
3222
3343
  }
3223
3344
  };
3345
+ var AnnouncementChannel = class extends TextChannel {
3346
+ };
3224
3347
  var CategoryChannel = class extends GuildChannel {
3225
3348
  };
3226
3349
  var VoiceChannel = class extends TextCapable(GuildChannel) {
@@ -3303,6 +3426,7 @@ var LinkChannel = class extends GuildChannel {
3303
3426
  import { ChannelType as ChannelType3 } from "@fluxerjs/types";
3304
3427
  var GUILD_FACTORIES = {
3305
3428
  [ChannelType3.GuildText]: (c, d) => new TextChannel(c, d),
3429
+ [ChannelType3.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
3306
3430
  [ChannelType3.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3307
3431
  [ChannelType3.GuildVoice]: (c, d) => new VoiceChannel(c, d),
3308
3432
  [ChannelType3.GuildLink]: (c, d) => new LinkChannel(c, d)
@@ -3377,9 +3501,10 @@ var GuildEmoji = class extends Base {
3377
3501
  return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
3378
3502
  }
3379
3503
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
3380
- async delete() {
3504
+ async delete(reason) {
3381
3505
  await this.client.rest.delete(Routes14.guildEmoji(this.guildId, this.id), {
3382
- auth: true
3506
+ auth: true,
3507
+ ...auditReasonHeaders(reason)
3383
3508
  });
3384
3509
  const guild = this.client.guilds.get(this.guildId);
3385
3510
  if (guild) guild.emojis.delete(this.id);
@@ -3389,9 +3514,11 @@ var GuildEmoji = class extends Base {
3389
3514
  * Requires Manage Emojis and Stickers permission.
3390
3515
  */
3391
3516
  async edit(options) {
3517
+ const { reason, name } = options;
3392
3518
  const data = await this.client.rest.patch(Routes14.guildEmoji(this.guildId, this.id), {
3393
- body: options,
3394
- auth: true
3519
+ body: { name },
3520
+ auth: true,
3521
+ ...auditReasonHeaders(reason)
3395
3522
  });
3396
3523
  this.name = data.name;
3397
3524
  return this;
@@ -3407,6 +3534,9 @@ import { OverwriteType } from "@fluxerjs/types";
3407
3534
  import { ALL_PERMISSIONS_BIGINT, PermissionFlags as PermissionFlags2 } from "@fluxerjs/util";
3408
3535
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
3409
3536
  if (isOwner) return ALL_PERMISSIONS_BIGINT;
3537
+ if ((basePermissions & PermissionFlags2.Administrator) !== 0n) {
3538
+ return ALL_PERMISSIONS_BIGINT;
3539
+ }
3410
3540
  let perms = basePermissions;
3411
3541
  for (const overwrite of overwrites ?? []) {
3412
3542
  const applies = overwrite.type === OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === OverwriteType.Member && overwrite.id === memberId;
@@ -3415,7 +3545,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
3415
3545
  const deny = BigInt(overwrite.deny || "0");
3416
3546
  perms = perms & ~deny | allow;
3417
3547
  }
3418
- return (perms & PermissionFlags2.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT : perms;
3548
+ return perms;
3419
3549
  }
3420
3550
 
3421
3551
  // src/Domain/Guild/GuildMemberRoleManager.ts
@@ -3621,7 +3751,8 @@ var GuildMember = class _GuildMember extends Base {
3621
3751
  const route = isMe ? Routes16.guildMemberMe(this.guild.id) : Routes16.guildMember(this.guild.id, this.id);
3622
3752
  const data = await this.client.rest.patch(route, {
3623
3753
  body: toMemberEditBody(options),
3624
- auth: true
3754
+ auth: true,
3755
+ ...auditReasonHeaders(options.reason ?? options.timeoutReason)
3625
3756
  });
3626
3757
  this._patch(data);
3627
3758
  if (options.bio !== void 0) this.bio = options.bio;
@@ -3655,8 +3786,8 @@ var GuildMember = class _GuildMember extends Base {
3655
3786
  await this.edit({ channelId, connectionId });
3656
3787
  }
3657
3788
  /** Kick this member. Requires Kick Members. */
3658
- async kick() {
3659
- await this.guild.kick(this.id);
3789
+ async kick(reason) {
3790
+ await this.guild.kick(this.id, reason);
3660
3791
  }
3661
3792
  /** Ban this member. Requires Ban Members. */
3662
3793
  async ban(options) {
@@ -3780,9 +3911,10 @@ var GuildSticker = class extends Base {
3780
3911
  return SnowflakeUtil6.dateFromSnowflake(this.id);
3781
3912
  }
3782
3913
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3783
- async delete() {
3914
+ async delete(reason) {
3784
3915
  await this.client.rest.delete(Routes17.guildSticker(this.guildId, this.id), {
3785
- auth: true
3916
+ auth: true,
3917
+ ...auditReasonHeaders(reason)
3786
3918
  });
3787
3919
  const guild = this.client.guilds.get(this.guildId);
3788
3920
  if (guild) guild.stickers.delete(this.id);
@@ -3792,9 +3924,11 @@ var GuildSticker = class extends Base {
3792
3924
  * Requires Manage Emojis and Stickers permission.
3793
3925
  */
3794
3926
  async edit(options) {
3927
+ const { reason, ...body } = options;
3795
3928
  const data = await this.client.rest.patch(Routes17.guildSticker(this.guildId, this.id), {
3796
- body: options,
3797
- auth: true
3929
+ body,
3930
+ auth: true,
3931
+ ...auditReasonHeaders(reason)
3798
3932
  });
3799
3933
  const s = data;
3800
3934
  this.name = s.name;
@@ -3921,16 +4055,21 @@ var Role = class _Role extends Base {
3921
4055
  const body = toRoleEditBody(options);
3922
4056
  const data = await this.client.rest.patch(Routes18.guildRole(this.guildId, this.id), {
3923
4057
  body: Object.keys(body).length ? body : void 0,
3924
- auth: true
4058
+ auth: true,
4059
+ ...auditReasonHeaders(options.reason)
3925
4060
  });
3926
4061
  this._patch(data);
3927
4062
  return this;
3928
4063
  }
3929
4064
  /**
3930
4065
  * DELETE role. Requires Manage Roles.
4066
+ * @param reason - Audit log reason (`X-Audit-Log-Reason`)
3931
4067
  */
3932
- async delete() {
3933
- await this.client.rest.delete(Routes18.guildRole(this.guildId, this.id), { auth: true });
4068
+ async delete(reason) {
4069
+ await this.client.rest.delete(Routes18.guildRole(this.guildId, this.id), {
4070
+ auth: true,
4071
+ ...auditReasonHeaders(reason)
4072
+ });
3934
4073
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
3935
4074
  }
3936
4075
  };
@@ -4363,7 +4502,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
4363
4502
  return parsed.name;
4364
4503
  }
4365
4504
  async function fetchInstance(client) {
4366
- const raw = await client.rest.get(Routes21.instanceDiscovery(), { auth: false });
4505
+ const raw = await client.rest.get(Routes21.instanceDiscovery(), {
4506
+ auth: false,
4507
+ unversioned: true
4508
+ });
4367
4509
  return parseInstanceDiscovery(raw);
4368
4510
  }
4369
4511
  function fetchGatewayInfo(client) {
@@ -4742,9 +4884,11 @@ async function fetchEmoji(guild, emojiId) {
4742
4884
  }
4743
4885
  }
4744
4886
  async function createEmoji(guild, options) {
4887
+ const { reason, ...body } = options;
4745
4888
  const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
4746
- body: options,
4747
- auth: true
4889
+ body,
4890
+ auth: true,
4891
+ ...auditReasonHeaders(reason)
4748
4892
  });
4749
4893
  return cacheEmoji(guild, data);
4750
4894
  }
@@ -4763,6 +4907,19 @@ async function createEmojisBulk(guild, emojis) {
4763
4907
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
4764
4908
  }
4765
4909
 
4910
+ // src/Domain/Guild/GuildRoleManager.ts
4911
+ import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4912
+ var GuildRoleManager = class extends LimitedCollection3 {
4913
+ constructor(guildId, options) {
4914
+ super(options);
4915
+ this.guildId = guildId;
4916
+ }
4917
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4918
+ get everyone() {
4919
+ return this.get(this.guildId);
4920
+ }
4921
+ };
4922
+
4766
4923
  // src/Domain/Guild/MemberHttp.ts
4767
4924
  import { Routes as Routes26 } from "@fluxerjs/types";
4768
4925
  async function fetchMember(guild, userId) {
@@ -4819,9 +4976,10 @@ var GuildBan = class extends Base {
4819
4976
  * Remove this ban (unban the user).
4820
4977
  * Requires Ban Members permission.
4821
4978
  */
4822
- async unban() {
4979
+ async unban(reason) {
4823
4980
  await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
4824
- auth: true
4981
+ auth: true,
4982
+ ...auditReasonHeaders(reason)
4825
4983
  });
4826
4984
  }
4827
4985
  };
@@ -4831,33 +4989,27 @@ async function ban(guild, userId, options) {
4831
4989
  const body = options ? toGuildBanBody(options) : {};
4832
4990
  await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
4833
4991
  body: Object.keys(body).length ? body : void 0,
4834
- auth: true
4992
+ auth: true,
4993
+ ...auditReasonHeaders(options?.reason)
4835
4994
  });
4836
4995
  }
4837
4996
  async function fetchBans(guild) {
4838
4997
  const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
4839
4998
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
4840
4999
  }
4841
- async function unban(guild, userId) {
4842
- await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), { auth: true });
5000
+ async function unban(guild, userId, reason) {
5001
+ await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
5002
+ auth: true,
5003
+ ...auditReasonHeaders(reason)
5004
+ });
4843
5005
  }
4844
- async function kick(guild, userId) {
4845
- await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), { auth: true });
5006
+ async function kick(guild, userId, reason) {
5007
+ await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
5008
+ auth: true,
5009
+ ...auditReasonHeaders(reason)
5010
+ });
4846
5011
  }
4847
5012
 
4848
- // src/Domain/Guild/GuildRoleManager.ts
4849
- import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4850
- var GuildRoleManager = class extends LimitedCollection3 {
4851
- constructor(guildId, options) {
4852
- super(options);
4853
- this.guildId = guildId;
4854
- }
4855
- /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4856
- get everyone() {
4857
- return this.get(this.guildId);
4858
- }
4859
- };
4860
-
4861
5013
  // src/Domain/Guild/Roles.ts
4862
5014
  import { Routes as Routes29 } from "@fluxerjs/types";
4863
5015
  import { parseRoleMention } from "@fluxerjs/util";
@@ -4865,7 +5017,8 @@ async function createRole(guild, options = {}) {
4865
5017
  const body = toRoleCreateBody(options);
4866
5018
  const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
4867
5019
  body: Object.keys(body).length ? body : void 0,
4868
- auth: true
5020
+ auth: true,
5021
+ ...auditReasonHeaders(options.reason)
4869
5022
  });
4870
5023
  return cacheRole(guild, data);
4871
5024
  }
@@ -4931,9 +5084,11 @@ async function resetRoleHoistPositions(guild) {
4931
5084
  // src/Domain/Guild/Stickers.ts
4932
5085
  import { Routes as Routes30 } from "@fluxerjs/types";
4933
5086
  async function createSticker(guild, options) {
5087
+ const { reason, ...body } = options;
4934
5088
  const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
4935
- body: options,
4936
- auth: true
5089
+ body,
5090
+ auth: true,
5091
+ ...auditReasonHeaders(reason)
4937
5092
  });
4938
5093
  return cacheSticker(guild, data);
4939
5094
  }
@@ -5263,12 +5418,12 @@ var Guild = class extends Base {
5263
5418
  return fetchBans(this);
5264
5419
  }
5265
5420
  /** Unban a user from the guild. Requires Ban Members. */
5266
- unban(userId) {
5267
- return unban(this, userId);
5421
+ unban(userId, reason) {
5422
+ return unban(this, userId, reason);
5268
5423
  }
5269
5424
  /** Kick a user from the guild. Requires Kick Members. */
5270
- kick(userId) {
5271
- return kick(this, userId);
5425
+ kick(userId, reason) {
5426
+ return kick(this, userId, reason);
5272
5427
  }
5273
5428
  /** Fetch all emojis in this guild from the API. */
5274
5429
  fetchEmojis() {
@@ -5718,7 +5873,14 @@ function markGuildUnavailable(client, id) {
5718
5873
  guild.available = false;
5719
5874
  client.emit(Events.GuildUnavailable, guild);
5720
5875
  }
5876
+ function isStartupGuildHydration(client) {
5877
+ return client._guildStreamSettleTimeout !== null;
5878
+ }
5721
5879
  var guildHandlers = {
5880
+ /**
5881
+ * Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
5882
+ * {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
5883
+ */
5722
5884
  GUILD_CREATE(client, d) {
5723
5885
  const raw = d;
5724
5886
  if (raw.unavailable === true) {
@@ -5731,11 +5893,32 @@ var guildHandlers = {
5731
5893
  }
5732
5894
  return;
5733
5895
  }
5896
+ const startupHydration = isStartupGuildHydration(client);
5897
+ if (startupHydration) {
5898
+ resetGuildStreamSettle(client);
5899
+ }
5734
5900
  const result = applyGuildSnapshotFromGateway(client, d);
5735
5901
  if (!result) return;
5736
5902
  const { guild, recovered } = result;
5737
- if (recovered) guild.available = true;
5738
- client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
5903
+ const legacyStartup = client.options.emitGuildCreateOnStartup === true;
5904
+ const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
5905
+ const isStartupBackfill = wasReadyStub || startupHydration;
5906
+ if (recovered) {
5907
+ guild.available = true;
5908
+ if (legacyStartup && isStartupBackfill) {
5909
+ client.emit(Events.GuildCreate, guild);
5910
+ } else {
5911
+ client.emit(Events.GuildAvailable, guild);
5912
+ }
5913
+ } else if (startupHydration) {
5914
+ if (legacyStartup) {
5915
+ client.emit(Events.GuildCreate, guild);
5916
+ } else {
5917
+ client.emit(Events.GuildAvailable, guild);
5918
+ }
5919
+ } else {
5920
+ client.emit(Events.GuildCreate, guild);
5921
+ }
5739
5922
  client._onGuildReceived(guild.id);
5740
5923
  },
5741
5924
  GUILD_UPDATE(client, d) {
@@ -5774,6 +5957,7 @@ var guildHandlers = {
5774
5957
  markGuildUnavailable(client, id);
5775
5958
  return;
5776
5959
  }
5960
+ client._readyStubGuildIds.delete(id);
5777
5961
  const guild = client.guilds.get(id);
5778
5962
  if (!guild) return;
5779
5963
  client.guilds.delete(id);
@@ -6292,10 +6476,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
6292
6476
  for (const g of guilds ?? []) {
6293
6477
  if (g.unavailable === true) {
6294
6478
  if (typeof g.id === "string") {
6295
- const existing = client.guilds.get(g.id);
6296
- if (existing && existing.available !== false) {
6297
- existing.available = false;
6479
+ let guild = client.guilds.get(g.id);
6480
+ if (!guild) {
6481
+ guild = new Guild(client, { id: g.id });
6482
+ guild.available = false;
6483
+ client.guilds.set(g.id, guild);
6484
+ } else if (guild.available !== false) {
6485
+ guild.available = false;
6298
6486
  }
6487
+ client._readyStubGuildIds.add(g.id);
6299
6488
  if (pending !== null) pending.add(g.id);
6300
6489
  }
6301
6490
  continue;
@@ -6323,6 +6512,13 @@ function clearGuildStreamSettle(client) {
6323
6512
  clearTimeout(client._guildStreamSettleTimeout);
6324
6513
  client._guildStreamSettleTimeout = null;
6325
6514
  }
6515
+ function resetGuildStreamSettle(client) {
6516
+ clearGuildStreamSettle(client);
6517
+ client._guildStreamSettleTimeout = setTimeout(() => {
6518
+ client._guildStreamSettleTimeout = null;
6519
+ if (client.readyAt === null) finalizeClientReady(client);
6520
+ }, GUILD_STREAM_SETTLE_MS);
6521
+ }
6326
6522
  function handleReadyPayload(client, data) {
6327
6523
  client.user = new ClientUser(client, data.user);
6328
6524
  const waitForGuilds = client.options.waitForGuilds === true;
@@ -6342,14 +6538,9 @@ function handleReadyPayload(client, data) {
6342
6538
  client._pendingGuildIds = existing;
6343
6539
  return;
6344
6540
  }
6345
- if (waitForGuilds && guilds.length === 0) {
6346
- if (client._guildStreamSettleTimeout === null) {
6347
- client._guildStreamSettleTimeout = setTimeout(() => {
6348
- client._guildStreamSettleTimeout = null;
6349
- if (client.readyAt === null) finalizeClientReady(client);
6350
- }, GUILD_STREAM_SETTLE_MS);
6351
- }
6352
- return;
6541
+ if (guilds.length === 0) {
6542
+ resetGuildStreamSettle(client);
6543
+ if (waitForGuilds) return;
6353
6544
  }
6354
6545
  finalizeClientReady(client);
6355
6546
  }
@@ -6684,7 +6875,12 @@ var Client = class _Client extends EventEmitter3 {
6684
6875
  _ws = null;
6685
6876
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
6686
6877
  _pendingGuildIds = null;
6687
- /** @internal Timeout when READY has no guilds but waitForGuilds is set. */
6878
+ /** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
6879
+ _readyStubGuildIds = /* @__PURE__ */ new Set();
6880
+ /**
6881
+ * @internal Empty-READY guild stream window.
6882
+ * Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
6883
+ */
6688
6884
  _guildStreamSettleTimeout = null;
6689
6885
  /** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
6690
6886
  _deferredGatewayDispatches = [];
@@ -6715,7 +6911,7 @@ var Client = class _Client extends EventEmitter3 {
6715
6911
  const restApi = options.rest?.api;
6716
6912
  if (options.instance !== void 0) {
6717
6913
  this.instance = resolveInstanceEndpoints(options.instance);
6718
- resolveRestApi(this.instance.endpoints.api, restApi);
6914
+ resolveRestApi(this.instance.endpoints.api_public, restApi);
6719
6915
  } else {
6720
6916
  this.instance = resolveInstanceEndpoints(
6721
6917
  restApi !== void 0 ? { api: restApi } : void 0
@@ -6728,27 +6924,31 @@ var Client = class _Client extends EventEmitter3 {
6728
6924
  }
6729
6925
  this.rest = new REST({
6730
6926
  ...this.options.rest,
6731
- api: this.instance.endpoints.api,
6732
- version: this.options.rest?.version ?? "1"
6927
+ api: this.instance.endpoints.api_public,
6928
+ version: this.options.rest?.version ?? "1",
6929
+ locale: this.options.locale ?? this.options.rest?.locale
6733
6930
  });
6734
6931
  }
6735
6932
  /**
6736
6933
  * Create a client from instance discovery (`GET /.well-known/fluxer`).
6737
- * Does not log in — call {@link login} with a token afterward.
6934
+ * Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
6935
+ * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
6936
+ * Does not log in. Call {@link login} with a token afterward.
6738
6937
  *
6739
- * @param origin - API origin used only to fetch discovery (e.g. `https://api.example.com`)
6740
- * @param options - Client options (must not conflict with discovered `endpoints.api`)
6938
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
6939
+ * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
6741
6940
  * @param connectOptions - Optional abort signal for the discovery request
6742
6941
  */
6743
6942
  static async fromDiscovery(origin, options = {}, connectOptions) {
6744
- const bootstrapApi = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
6943
+ const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
6745
6944
  const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
6746
6945
  const bootstrap = new REST({
6747
6946
  ...options.rest ?? {},
6748
- api: bootstrapApi,
6749
- version
6947
+ api: bootstrapOrigin,
6948
+ version,
6949
+ locale: options.locale ?? options.rest?.locale
6750
6950
  });
6751
- const raw = await bootstrap.get(Routes34.instanceDiscovery(), {
6951
+ const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
6752
6952
  auth: false,
6753
6953
  ...connectOptions?.signal ? { signal: connectOptions.signal } : {}
6754
6954
  });
@@ -6756,7 +6956,7 @@ var Client = class _Client extends EventEmitter3 {
6756
6956
  const { rest, ...restOptions } = options;
6757
6957
  return new _Client({
6758
6958
  ...restOptions,
6759
- // Drop rest.api so discovered endpoints.api owns the host; keep other REST opts.
6959
+ // Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
6760
6960
  ...rest ? { rest: { ...rest, api: void 0 } } : {},
6761
6961
  instance: discovery
6762
6962
  });
@@ -6783,7 +6983,7 @@ var Client = class _Client extends EventEmitter3 {
6783
6983
  return resolveClientEmoji(this, emoji, guildId);
6784
6984
  }
6785
6985
  /**
6786
- * Fetch instance discovery document (`/.well-known/fluxer`).
6986
+ * Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
6787
6987
  * @returns Instance configuration (endpoints, features, metadata)
6788
6988
  */
6789
6989
  fetchInstance() {
@@ -7052,6 +7252,7 @@ var Client = class _Client extends EventEmitter3 {
7052
7252
  this.user = null;
7053
7253
  this.readyAt = null;
7054
7254
  this._pendingGuildIds = null;
7255
+ this._readyStubGuildIds.clear();
7055
7256
  this.guilds.clear();
7056
7257
  this.channels.clear();
7057
7258
  this.users.clear();
@@ -7433,6 +7634,7 @@ var ClientCluster = class extends EventEmitter4 {
7433
7634
  };
7434
7635
  export {
7435
7636
  AllowedMentions,
7637
+ AnnouncementChannel,
7436
7638
  AttachmentBuilder2 as AttachmentBuilder,
7437
7639
  AttachmentMeta,
7438
7640
  AuditLogActionType,
@@ -7470,6 +7672,7 @@ export {
7470
7672
  GuildOperations,
7471
7673
  GuildRoleManager,
7472
7674
  GuildSticker,
7675
+ INSTANCE_DISCOVERY_PATH,
7473
7676
  Invite,
7474
7677
  InviteType3 as InviteType,
7475
7678
  LinkChannel,
@@ -7518,6 +7721,7 @@ export {
7518
7721
  cdnMemberBannerURL,
7519
7722
  cdnStickerURL,
7520
7723
  createLogger2 as createLogger,
7724
+ instanceDiscoveryUrl,
7521
7725
  inviteUrl,
7522
7726
  normalizeApiOrigin,
7523
7727
  normalizeCacheLimit,