@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/cluster.js CHANGED
@@ -186,6 +186,7 @@ function toOverwriteWire(overwrite) {
186
186
  }
187
187
  function toChannelEditBody(options) {
188
188
  const body = {};
189
+ if (options.type !== void 0) body.type = options.type;
189
190
  if (options.name !== void 0) body.name = options.name;
190
191
  if (options.topic !== void 0) body.topic = options.topic;
191
192
  if (options.url !== void 0) body.url = options.url;
@@ -521,6 +522,13 @@ function toSudoBody(options) {
521
522
  return body;
522
523
  }
523
524
 
525
+ // src/Helpers/AuditReason.ts
526
+ var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
527
+ function auditReasonHeaders(reason) {
528
+ if (reason == null || reason === "") return {};
529
+ return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
530
+ }
531
+
524
532
  // src/Helpers/MessageUtils/Body.ts
525
533
  var import_builders = require("@fluxerjs/builders");
526
534
  var import_types = require("@fluxerjs/types");
@@ -1100,6 +1108,67 @@ var CDN_URL = "https://fluxerusercontent.com";
1100
1108
  var STATIC_CDN_URL = "https://fluxerstatic.com";
1101
1109
 
1102
1110
  // src/Helpers/Cdn.ts
1111
+ var CDN_SIZE_LADDER = [
1112
+ 16,
1113
+ 20,
1114
+ 22,
1115
+ 24,
1116
+ 28,
1117
+ 32,
1118
+ 40,
1119
+ 44,
1120
+ 48,
1121
+ 56,
1122
+ 60,
1123
+ 64,
1124
+ 80,
1125
+ 96,
1126
+ 100,
1127
+ 128,
1128
+ 160,
1129
+ 240,
1130
+ 256,
1131
+ 300,
1132
+ 320,
1133
+ 480,
1134
+ 512,
1135
+ 600,
1136
+ 640,
1137
+ 1024,
1138
+ 1280,
1139
+ 1536,
1140
+ 2048,
1141
+ 3072,
1142
+ 4096,
1143
+ 8192,
1144
+ 16384
1145
+ ];
1146
+ var CDN_ASSET_CLASS_RANGE = {
1147
+ icon: { min: 128, max: 1024 },
1148
+ banner: { min: 480, max: 2400 },
1149
+ emoji: { min: 32, max: 512 },
1150
+ sticker: { min: 128, max: 512 }
1151
+ };
1152
+ function nearestSize(requested, candidates) {
1153
+ let best = candidates[0];
1154
+ let bestDist = Math.abs(requested - best);
1155
+ for (let i = 1; i < candidates.length; i++) {
1156
+ const step = candidates[i];
1157
+ const dist = Math.abs(requested - step);
1158
+ if (dist < bestDist || dist === bestDist && step > best) {
1159
+ best = step;
1160
+ bestDist = dist;
1161
+ }
1162
+ }
1163
+ return best;
1164
+ }
1165
+ function snapCdnSize(requested, assetClass) {
1166
+ const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
1167
+ const snapped = nearestSize(requested, CDN_SIZE_LADDER);
1168
+ const clamped = Math.min(max, Math.max(min, snapped));
1169
+ const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
1170
+ return nearestSize(clamped, allowed);
1171
+ }
1103
1172
  function mediaBase(options) {
1104
1173
  return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1105
1174
  }
@@ -1111,31 +1180,33 @@ function getExtension(hash, options) {
1111
1180
  if (hash?.startsWith("a_")) return "gif";
1112
1181
  return ext;
1113
1182
  }
1114
- function appendSize(options) {
1115
- return options?.size ? `?size=${options.size}` : "";
1183
+ function appendSize(options, assetClass) {
1184
+ const size = options?.size;
1185
+ if (size == null || !Number.isFinite(size) || size <= 0) return "";
1186
+ return `?size=${snapCdnSize(size, assetClass)}`;
1116
1187
  }
1117
1188
  function cdnAvatarURL(userId, avatarHash, options) {
1118
1189
  if (!avatarHash) return null;
1119
1190
  const ext = getExtension(avatarHash, options);
1120
- const size = appendSize(options);
1191
+ const size = appendSize(options, "icon");
1121
1192
  return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1122
1193
  }
1123
1194
  function cdnBannerURL(resourceId, bannerHash, options) {
1124
1195
  if (!bannerHash) return null;
1125
1196
  const ext = getExtension(bannerHash, options);
1126
- const size = appendSize(options);
1197
+ const size = appendSize(options, "banner");
1127
1198
  return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1128
1199
  }
1129
1200
  function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1130
1201
  if (!avatarHash) return null;
1131
1202
  const ext = getExtension(avatarHash, options);
1132
- const size = appendSize(options);
1203
+ const size = appendSize(options, "icon");
1133
1204
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1134
1205
  }
1135
1206
  function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1136
1207
  if (!bannerHash) return null;
1137
1208
  const ext = getExtension(bannerHash, options);
1138
- const size = appendSize(options);
1209
+ const size = appendSize(options, "banner");
1139
1210
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1140
1211
  }
1141
1212
  function cdnDefaultAvatarURL(userIdOrIndex, options) {
@@ -1144,16 +1215,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1144
1215
  }
1145
1216
  function cdnGuildAssetURL(kind, id, hash, options) {
1146
1217
  if (!hash) return null;
1147
- const size = options?.size ? `?size=${options.size}` : "";
1218
+ const assetClass = kind === "icons" ? "icon" : "banner";
1219
+ const size = appendSize(options, assetClass);
1148
1220
  return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1149
1221
  }
1150
1222
  function cdnEmojiURL(emojiId, animated, options) {
1151
1223
  const ext = animated ? "gif" : "png";
1152
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1224
+ const size = appendSize(options, "emoji");
1225
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
1153
1226
  }
1154
1227
  function cdnStickerURL(stickerId, animated, options) {
1155
1228
  const ext = animated ? "gif" : "png";
1156
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1229
+ const size = appendSize(options, "sticker");
1230
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
1157
1231
  }
1158
1232
 
1159
1233
  // src/Domain/Message/MessageSticker.ts
@@ -1381,6 +1455,8 @@ var Message = class _Message extends Base {
1381
1455
  mentionRoles;
1382
1456
  /** Client-side nonce for deduplication. */
1383
1457
  nonce;
1458
+ /** IDs of custom emojis in the message classified as explicit. */
1459
+ nsfwEmojis;
1384
1460
  /**
1385
1461
  * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1386
1462
  * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
@@ -1455,6 +1531,7 @@ var Message = class _Message extends Base {
1455
1531
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1456
1532
  this.mentionRoles = data.mention_roles ?? [];
1457
1533
  this.nonce = data.nonce ?? null;
1534
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1458
1535
  }
1459
1536
  /**
1460
1537
  * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
@@ -1487,6 +1564,7 @@ var Message = class _Message extends Base {
1487
1564
  this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1488
1565
  this.mentionRoles = data.mention_roles ?? [];
1489
1566
  this.nonce = data.nonce ?? null;
1567
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1490
1568
  }
1491
1569
  /**
1492
1570
  * Send a standalone message in this channel (not a reply).
@@ -1570,8 +1648,10 @@ var Message = class _Message extends Base {
1570
1648
  return this.client.channels.fetchMessage(this.channelId, this.id);
1571
1649
  }
1572
1650
  /** Delete this message. */
1573
- async delete() {
1574
- await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id));
1651
+ async delete(reason) {
1652
+ await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id), {
1653
+ ...auditReasonHeaders(reason)
1654
+ });
1575
1655
  this.client._removeMessageFromCache(this.channelId, this.id);
1576
1656
  }
1577
1657
  /** Delete a specific attachment from this message. */
@@ -1885,6 +1965,29 @@ var MessageCollector = class _MessageCollector extends import_node_events2.Event
1885
1965
 
1886
1966
  // src/Domain/Channel/Attachments.ts
1887
1967
  var import_types7 = require("@fluxerjs/types");
1968
+ var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
1969
+ var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
1970
+ function instanceLimitOverridesSnapshot(client) {
1971
+ const rules = client.instance.discovery?.limits?.rules;
1972
+ if (!rules?.length) return null;
1973
+ const snapshot = {};
1974
+ for (const rule of rules) {
1975
+ Object.assign(snapshot, rule.overrides);
1976
+ }
1977
+ return Object.keys(snapshot).length ? snapshot : null;
1978
+ }
1979
+ function assertBotAttachmentLimits(client, files) {
1980
+ const snapshot = instanceLimitOverridesSnapshot(client);
1981
+ for (const file of files) {
1982
+ const size = file.data.byteLength;
1983
+ if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
1984
+ const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
1985
+ throw new import_util2.FluxerError(
1986
+ `Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
1987
+ { code: import_util.ErrorCodes.AttachmentTooLarge }
1988
+ );
1989
+ }
1990
+ }
1888
1991
  function asBytes(data) {
1889
1992
  const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
1890
1993
  const out = new Uint8Array(src.byteLength);
@@ -1904,6 +2007,7 @@ async function putBlob(url, body, contentType) {
1904
2007
  }
1905
2008
  }
1906
2009
  async function uploadAttachmentsForSend(client, channelId, files) {
2010
+ assertBotAttachmentLimits(client, files);
1907
2011
  const plan = await client.rest.post(
1908
2012
  import_types7.Routes.channelAttachments(channelId),
1909
2013
  {
@@ -2016,20 +2120,24 @@ var Channel = class extends Base {
2016
2120
  throw new Error("Channel.createDM not initialized");
2017
2121
  }
2018
2122
  /**
2019
- * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
2123
+ * Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
2020
2124
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
2021
2125
  */
2022
2126
  isTextBased() {
2023
- return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
2127
+ return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildAnnouncement || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.DM || this.type === import_types8.ChannelType.GroupDM || this.type === import_types8.ChannelType.DMPersonalNotes;
2024
2128
  }
2025
- /** Check if this is a guild channel (text, voice, category, or link). */
2129
+ /** Check if this is a guild channel (text, announcement, voice, category, or link). */
2026
2130
  isGuild() {
2027
- return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.GuildCategory || this.type === import_types8.ChannelType.GuildLink;
2131
+ return this.type === import_types8.ChannelType.GuildText || this.type === import_types8.ChannelType.GuildAnnouncement || this.type === import_types8.ChannelType.GuildVoice || this.type === import_types8.ChannelType.GuildCategory || this.type === import_types8.ChannelType.GuildLink;
2028
2132
  }
2029
2133
  /** Check if this is a guild text channel. */
2030
2134
  isText() {
2031
2135
  return this.type === import_types8.ChannelType.GuildText;
2032
2136
  }
2137
+ /** Check if this is a guild announcement channel. */
2138
+ isAnnouncement() {
2139
+ return this.type === import_types8.ChannelType.GuildAnnouncement;
2140
+ }
2033
2141
  /** Check if this is a category channel. */
2034
2142
  isCategory() {
2035
2143
  return this.type === import_types8.ChannelType.GuildCategory;
@@ -2200,11 +2308,12 @@ var Channel = class extends Base {
2200
2308
  if (options?.silent) params.set("silent", "true");
2201
2309
  if (options?.deleteMessages) params.set("delete_messages", "true");
2202
2310
  const qs2 = params.toString();
2203
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2311
+ const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
2204
2312
  const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2205
2313
  await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2206
2314
  body,
2207
- auth: true
2315
+ auth: true,
2316
+ ...auditReasonHeaders(_reason)
2208
2317
  });
2209
2318
  this.client.channels.delete(this.id);
2210
2319
  this.client._clearMessageCache(this.id);
@@ -2364,7 +2473,7 @@ var import_types11 = require("@fluxerjs/types");
2364
2473
  // src/Helpers/Instance.ts
2365
2474
  var import_util9 = require("@fluxerjs/util");
2366
2475
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2367
- api: "https://api.fluxer.app",
2476
+ api: "https://web.fluxer.app/api",
2368
2477
  api_client: "https://web.fluxer.app/api",
2369
2478
  api_public: "https://api.fluxer.app",
2370
2479
  gateway: "wss://gateway.fluxer.app",
@@ -2398,6 +2507,10 @@ function requireString(obj, key, path) {
2398
2507
  }
2399
2508
  return value;
2400
2509
  }
2510
+ var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
2511
+ function instanceDiscoveryUrl(origin) {
2512
+ return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
2513
+ }
2401
2514
  function normalizeApiOrigin(api) {
2402
2515
  const trimmed = api.trim().replace(/\/+$/, "");
2403
2516
  return trimmed.replace(/\/v\d+$/i, "");
@@ -2426,6 +2539,8 @@ function parseInstanceDiscovery(raw) {
2426
2539
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2427
2540
  }
2428
2541
  endpoints.api = normalizeApiOrigin(endpoints.api);
2542
+ endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2543
+ endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
2429
2544
  endpoints.invite = normalizeInviteBase(endpoints.invite);
2430
2545
  endpoints.media = endpoints.media.replace(/\/+$/, "");
2431
2546
  endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
@@ -2503,6 +2618,11 @@ function resolveInstanceEndpoints(input) {
2503
2618
  }
2504
2619
  }
2505
2620
  merged.api = normalizeApiOrigin(merged.api);
2621
+ merged.api_client = normalizeApiOrigin(merged.api_client);
2622
+ merged.api_public = normalizeApiOrigin(merged.api_public);
2623
+ if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
2624
+ merged.api_public = merged.api;
2625
+ }
2506
2626
  merged.invite = normalizeInviteBase(merged.invite);
2507
2627
  merged.media = merged.media.replace(/\/+$/, "");
2508
2628
  merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
@@ -2511,13 +2631,13 @@ function resolveInstanceEndpoints(input) {
2511
2631
  discovery: null
2512
2632
  });
2513
2633
  }
2514
- function resolveRestApi(instanceApi, restApi) {
2515
- const fromInstance = normalizeApiOrigin(instanceApi);
2634
+ function resolveRestApi(instanceApiPublic, restApi) {
2635
+ const fromInstance = normalizeApiOrigin(instanceApiPublic);
2516
2636
  if (restApi === void 0) return fromInstance;
2517
2637
  const fromRest = normalizeApiOrigin(restApi);
2518
2638
  if (fromRest !== fromInstance) {
2519
2639
  throw new import_util2.FluxerError(
2520
- `Conflicting API hosts: instance.api (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2640
+ `Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2521
2641
  { code: import_util.ErrorCodes.ConflictingInstanceConfig }
2522
2642
  );
2523
2643
  }
@@ -2997,7 +3117,8 @@ var GuildChannel = class extends Channel {
2997
3117
  async edit(options) {
2998
3118
  const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
2999
3119
  body: toChannelEditBody(options),
3000
- auth: true
3120
+ auth: true,
3121
+ ...auditReasonHeaders(options.reason)
3001
3122
  });
3002
3123
  this.name = data.name ?? this.name;
3003
3124
  this.parentId = data.parent_id ?? this.parentId;
@@ -3056,6 +3177,8 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3056
3177
  }
3057
3178
  }
3058
3179
  };
3180
+ var AnnouncementChannel = class extends TextChannel {
3181
+ };
3059
3182
  var CategoryChannel = class extends GuildChannel {
3060
3183
  };
3061
3184
  var VoiceChannel = class extends TextCapable(GuildChannel) {
@@ -3138,6 +3261,7 @@ var LinkChannel = class extends GuildChannel {
3138
3261
  var import_types15 = require("@fluxerjs/types");
3139
3262
  var GUILD_FACTORIES = {
3140
3263
  [import_types15.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
3264
+ [import_types15.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
3141
3265
  [import_types15.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3142
3266
  [import_types15.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
3143
3267
  [import_types15.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
@@ -3529,9 +3653,10 @@ var GuildEmoji = class extends Base {
3529
3653
  return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
3530
3654
  }
3531
3655
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
3532
- async delete() {
3656
+ async delete(reason) {
3533
3657
  await this.client.rest.delete(import_types17.Routes.guildEmoji(this.guildId, this.id), {
3534
- auth: true
3658
+ auth: true,
3659
+ ...auditReasonHeaders(reason)
3535
3660
  });
3536
3661
  const guild = this.client.guilds.get(this.guildId);
3537
3662
  if (guild) guild.emojis.delete(this.id);
@@ -3541,9 +3666,11 @@ var GuildEmoji = class extends Base {
3541
3666
  * Requires Manage Emojis and Stickers permission.
3542
3667
  */
3543
3668
  async edit(options) {
3669
+ const { reason, name } = options;
3544
3670
  const data = await this.client.rest.patch(import_types17.Routes.guildEmoji(this.guildId, this.id), {
3545
- body: options,
3546
- auth: true
3671
+ body: { name },
3672
+ auth: true,
3673
+ ...auditReasonHeaders(reason)
3547
3674
  });
3548
3675
  this.name = data.name;
3549
3676
  return this;
@@ -3559,6 +3686,9 @@ var import_types18 = require("@fluxerjs/types");
3559
3686
  var import_util16 = require("@fluxerjs/util");
3560
3687
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
3561
3688
  if (isOwner) return import_util16.ALL_PERMISSIONS_BIGINT;
3689
+ if ((basePermissions & import_util16.PermissionFlags.Administrator) !== 0n) {
3690
+ return import_util16.ALL_PERMISSIONS_BIGINT;
3691
+ }
3562
3692
  let perms = basePermissions;
3563
3693
  for (const overwrite of overwrites ?? []) {
3564
3694
  const applies = overwrite.type === import_types18.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types18.OverwriteType.Member && overwrite.id === memberId;
@@ -3567,7 +3697,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
3567
3697
  const deny = BigInt(overwrite.deny || "0");
3568
3698
  perms = perms & ~deny | allow;
3569
3699
  }
3570
- return (perms & import_util16.PermissionFlags.Administrator) !== 0n ? import_util16.ALL_PERMISSIONS_BIGINT : perms;
3700
+ return perms;
3571
3701
  }
3572
3702
 
3573
3703
  // src/Domain/Guild/GuildMemberRoleManager.ts
@@ -3773,7 +3903,8 @@ var GuildMember = class _GuildMember extends Base {
3773
3903
  const route = isMe ? import_types20.Routes.guildMemberMe(this.guild.id) : import_types20.Routes.guildMember(this.guild.id, this.id);
3774
3904
  const data = await this.client.rest.patch(route, {
3775
3905
  body: toMemberEditBody(options),
3776
- auth: true
3906
+ auth: true,
3907
+ ...auditReasonHeaders(options.reason ?? options.timeoutReason)
3777
3908
  });
3778
3909
  this._patch(data);
3779
3910
  if (options.bio !== void 0) this.bio = options.bio;
@@ -3807,8 +3938,8 @@ var GuildMember = class _GuildMember extends Base {
3807
3938
  await this.edit({ channelId, connectionId });
3808
3939
  }
3809
3940
  /** Kick this member. Requires Kick Members. */
3810
- async kick() {
3811
- await this.guild.kick(this.id);
3941
+ async kick(reason) {
3942
+ await this.guild.kick(this.id, reason);
3812
3943
  }
3813
3944
  /** Ban this member. Requires Ban Members. */
3814
3945
  async ban(options) {
@@ -3932,9 +4063,10 @@ var GuildSticker = class extends Base {
3932
4063
  return import_util18.SnowflakeUtil.dateFromSnowflake(this.id);
3933
4064
  }
3934
4065
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3935
- async delete() {
4066
+ async delete(reason) {
3936
4067
  await this.client.rest.delete(import_types21.Routes.guildSticker(this.guildId, this.id), {
3937
- auth: true
4068
+ auth: true,
4069
+ ...auditReasonHeaders(reason)
3938
4070
  });
3939
4071
  const guild = this.client.guilds.get(this.guildId);
3940
4072
  if (guild) guild.stickers.delete(this.id);
@@ -3944,9 +4076,11 @@ var GuildSticker = class extends Base {
3944
4076
  * Requires Manage Emojis and Stickers permission.
3945
4077
  */
3946
4078
  async edit(options) {
4079
+ const { reason, ...body } = options;
3947
4080
  const data = await this.client.rest.patch(import_types21.Routes.guildSticker(this.guildId, this.id), {
3948
- body: options,
3949
- auth: true
4081
+ body,
4082
+ auth: true,
4083
+ ...auditReasonHeaders(reason)
3950
4084
  });
3951
4085
  const s = data;
3952
4086
  this.name = s.name;
@@ -4068,16 +4202,21 @@ var Role = class _Role extends Base {
4068
4202
  const body = toRoleEditBody(options);
4069
4203
  const data = await this.client.rest.patch(import_types22.Routes.guildRole(this.guildId, this.id), {
4070
4204
  body: Object.keys(body).length ? body : void 0,
4071
- auth: true
4205
+ auth: true,
4206
+ ...auditReasonHeaders(options.reason)
4072
4207
  });
4073
4208
  this._patch(data);
4074
4209
  return this;
4075
4210
  }
4076
4211
  /**
4077
4212
  * DELETE role. Requires Manage Roles.
4213
+ * @param reason - Audit log reason (`X-Audit-Log-Reason`)
4078
4214
  */
4079
- async delete() {
4080
- await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), { auth: true });
4215
+ async delete(reason) {
4216
+ await this.client.rest.delete(import_types22.Routes.guildRole(this.guildId, this.id), {
4217
+ auth: true,
4218
+ ...auditReasonHeaders(reason)
4219
+ });
4081
4220
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
4082
4221
  }
4083
4222
  };
@@ -4328,7 +4467,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
4328
4467
  return parsed.name;
4329
4468
  }
4330
4469
  async function fetchInstance(client) {
4331
- const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), { auth: false });
4470
+ const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
4471
+ auth: false,
4472
+ unversioned: true
4473
+ });
4332
4474
  return parseInstanceDiscovery(raw);
4333
4475
  }
4334
4476
  function fetchGatewayInfo(client) {
@@ -4707,9 +4849,11 @@ async function fetchEmoji(guild, emojiId) {
4707
4849
  }
4708
4850
  }
4709
4851
  async function createEmoji(guild, options) {
4852
+ const { reason, ...body } = options;
4710
4853
  const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
4711
- body: options,
4712
- auth: true
4854
+ body,
4855
+ auth: true,
4856
+ ...auditReasonHeaders(reason)
4713
4857
  });
4714
4858
  return cacheEmoji(guild, data);
4715
4859
  }
@@ -4728,6 +4872,19 @@ async function createEmojisBulk(guild, emojis) {
4728
4872
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
4729
4873
  }
4730
4874
 
4875
+ // src/Domain/Guild/GuildRoleManager.ts
4876
+ var import_collection11 = require("@fluxerjs/collection");
4877
+ var GuildRoleManager = class extends import_collection11.LimitedCollection {
4878
+ constructor(guildId, options) {
4879
+ super(options);
4880
+ this.guildId = guildId;
4881
+ }
4882
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4883
+ get everyone() {
4884
+ return this.get(this.guildId);
4885
+ }
4886
+ };
4887
+
4731
4888
  // src/Domain/Guild/MemberHttp.ts
4732
4889
  var import_types29 = require("@fluxerjs/types");
4733
4890
  async function fetchMember(guild, userId) {
@@ -4784,9 +4941,10 @@ var GuildBan = class extends Base {
4784
4941
  * Remove this ban (unban the user).
4785
4942
  * Requires Ban Members permission.
4786
4943
  */
4787
- async unban() {
4944
+ async unban(reason) {
4788
4945
  await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
4789
- auth: true
4946
+ auth: true,
4947
+ ...auditReasonHeaders(reason)
4790
4948
  });
4791
4949
  }
4792
4950
  };
@@ -4796,33 +4954,27 @@ async function ban(guild, userId, options) {
4796
4954
  const body = options ? toGuildBanBody(options) : {};
4797
4955
  await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
4798
4956
  body: Object.keys(body).length ? body : void 0,
4799
- auth: true
4957
+ auth: true,
4958
+ ...auditReasonHeaders(options?.reason)
4800
4959
  });
4801
4960
  }
4802
4961
  async function fetchBans(guild) {
4803
4962
  const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
4804
4963
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
4805
4964
  }
4806
- async function unban(guild, userId) {
4807
- await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), { auth: true });
4965
+ async function unban(guild, userId, reason) {
4966
+ await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
4967
+ auth: true,
4968
+ ...auditReasonHeaders(reason)
4969
+ });
4808
4970
  }
4809
- async function kick(guild, userId) {
4810
- await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), { auth: true });
4971
+ async function kick(guild, userId, reason) {
4972
+ await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
4973
+ auth: true,
4974
+ ...auditReasonHeaders(reason)
4975
+ });
4811
4976
  }
4812
4977
 
4813
- // src/Domain/Guild/GuildRoleManager.ts
4814
- var import_collection11 = require("@fluxerjs/collection");
4815
- var GuildRoleManager = class extends import_collection11.LimitedCollection {
4816
- constructor(guildId, options) {
4817
- super(options);
4818
- this.guildId = guildId;
4819
- }
4820
- /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4821
- get everyone() {
4822
- return this.get(this.guildId);
4823
- }
4824
- };
4825
-
4826
4978
  // src/Domain/Guild/Roles.ts
4827
4979
  var import_types32 = require("@fluxerjs/types");
4828
4980
  var import_util21 = require("@fluxerjs/util");
@@ -4830,7 +4982,8 @@ async function createRole(guild, options = {}) {
4830
4982
  const body = toRoleCreateBody(options);
4831
4983
  const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
4832
4984
  body: Object.keys(body).length ? body : void 0,
4833
- auth: true
4985
+ auth: true,
4986
+ ...auditReasonHeaders(options.reason)
4834
4987
  });
4835
4988
  return cacheRole(guild, data);
4836
4989
  }
@@ -4896,9 +5049,11 @@ async function resetRoleHoistPositions(guild) {
4896
5049
  // src/Domain/Guild/Stickers.ts
4897
5050
  var import_types33 = require("@fluxerjs/types");
4898
5051
  async function createSticker(guild, options) {
5052
+ const { reason, ...body } = options;
4899
5053
  const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
4900
- body: options,
4901
- auth: true
5054
+ body,
5055
+ auth: true,
5056
+ ...auditReasonHeaders(reason)
4902
5057
  });
4903
5058
  return cacheSticker(guild, data);
4904
5059
  }
@@ -5228,12 +5383,12 @@ var Guild = class extends Base {
5228
5383
  return fetchBans(this);
5229
5384
  }
5230
5385
  /** Unban a user from the guild. Requires Ban Members. */
5231
- unban(userId) {
5232
- return unban(this, userId);
5386
+ unban(userId, reason) {
5387
+ return unban(this, userId, reason);
5233
5388
  }
5234
5389
  /** Kick a user from the guild. Requires Kick Members. */
5235
- kick(userId) {
5236
- return kick(this, userId);
5390
+ kick(userId, reason) {
5391
+ return kick(this, userId, reason);
5237
5392
  }
5238
5393
  /** Fetch all emojis in this guild from the API. */
5239
5394
  fetchEmojis() {
@@ -5683,7 +5838,14 @@ function markGuildUnavailable(client, id) {
5683
5838
  guild.available = false;
5684
5839
  client.emit(Events.GuildUnavailable, guild);
5685
5840
  }
5841
+ function isStartupGuildHydration(client) {
5842
+ return client._guildStreamSettleTimeout !== null;
5843
+ }
5686
5844
  var guildHandlers = {
5845
+ /**
5846
+ * Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
5847
+ * {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
5848
+ */
5687
5849
  GUILD_CREATE(client, d) {
5688
5850
  const raw = d;
5689
5851
  if (raw.unavailable === true) {
@@ -5696,11 +5858,32 @@ var guildHandlers = {
5696
5858
  }
5697
5859
  return;
5698
5860
  }
5861
+ const startupHydration = isStartupGuildHydration(client);
5862
+ if (startupHydration) {
5863
+ resetGuildStreamSettle(client);
5864
+ }
5699
5865
  const result = applyGuildSnapshotFromGateway(client, d);
5700
5866
  if (!result) return;
5701
5867
  const { guild, recovered } = result;
5702
- if (recovered) guild.available = true;
5703
- client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
5868
+ const legacyStartup = client.options.emitGuildCreateOnStartup === true;
5869
+ const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
5870
+ const isStartupBackfill = wasReadyStub || startupHydration;
5871
+ if (recovered) {
5872
+ guild.available = true;
5873
+ if (legacyStartup && isStartupBackfill) {
5874
+ client.emit(Events.GuildCreate, guild);
5875
+ } else {
5876
+ client.emit(Events.GuildAvailable, guild);
5877
+ }
5878
+ } else if (startupHydration) {
5879
+ if (legacyStartup) {
5880
+ client.emit(Events.GuildCreate, guild);
5881
+ } else {
5882
+ client.emit(Events.GuildAvailable, guild);
5883
+ }
5884
+ } else {
5885
+ client.emit(Events.GuildCreate, guild);
5886
+ }
5704
5887
  client._onGuildReceived(guild.id);
5705
5888
  },
5706
5889
  GUILD_UPDATE(client, d) {
@@ -5739,6 +5922,7 @@ var guildHandlers = {
5739
5922
  markGuildUnavailable(client, id);
5740
5923
  return;
5741
5924
  }
5925
+ client._readyStubGuildIds.delete(id);
5742
5926
  const guild = client.guilds.get(id);
5743
5927
  if (!guild) return;
5744
5928
  client.guilds.delete(id);
@@ -6254,10 +6438,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
6254
6438
  for (const g of guilds ?? []) {
6255
6439
  if (g.unavailable === true) {
6256
6440
  if (typeof g.id === "string") {
6257
- const existing = client.guilds.get(g.id);
6258
- if (existing && existing.available !== false) {
6259
- existing.available = false;
6441
+ let guild = client.guilds.get(g.id);
6442
+ if (!guild) {
6443
+ guild = new Guild(client, { id: g.id });
6444
+ guild.available = false;
6445
+ client.guilds.set(g.id, guild);
6446
+ } else if (guild.available !== false) {
6447
+ guild.available = false;
6260
6448
  }
6449
+ client._readyStubGuildIds.add(g.id);
6261
6450
  if (pending !== null) pending.add(g.id);
6262
6451
  }
6263
6452
  continue;
@@ -6285,6 +6474,13 @@ function clearGuildStreamSettle(client) {
6285
6474
  clearTimeout(client._guildStreamSettleTimeout);
6286
6475
  client._guildStreamSettleTimeout = null;
6287
6476
  }
6477
+ function resetGuildStreamSettle(client) {
6478
+ clearGuildStreamSettle(client);
6479
+ client._guildStreamSettleTimeout = setTimeout(() => {
6480
+ client._guildStreamSettleTimeout = null;
6481
+ if (client.readyAt === null) finalizeClientReady(client);
6482
+ }, GUILD_STREAM_SETTLE_MS);
6483
+ }
6288
6484
  function handleReadyPayload(client, data) {
6289
6485
  client.user = new ClientUser(client, data.user);
6290
6486
  const waitForGuilds = client.options.waitForGuilds === true;
@@ -6304,14 +6500,9 @@ function handleReadyPayload(client, data) {
6304
6500
  client._pendingGuildIds = existing;
6305
6501
  return;
6306
6502
  }
6307
- if (waitForGuilds && guilds.length === 0) {
6308
- if (client._guildStreamSettleTimeout === null) {
6309
- client._guildStreamSettleTimeout = setTimeout(() => {
6310
- client._guildStreamSettleTimeout = null;
6311
- if (client.readyAt === null) finalizeClientReady(client);
6312
- }, GUILD_STREAM_SETTLE_MS);
6313
- }
6314
- return;
6503
+ if (guilds.length === 0) {
6504
+ resetGuildStreamSettle(client);
6505
+ if (waitForGuilds) return;
6315
6506
  }
6316
6507
  finalizeClientReady(client);
6317
6508
  }
@@ -6644,7 +6835,12 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6644
6835
  _ws = null;
6645
6836
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
6646
6837
  _pendingGuildIds = null;
6647
- /** @internal Timeout when READY has no guilds but waitForGuilds is set. */
6838
+ /** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
6839
+ _readyStubGuildIds = /* @__PURE__ */ new Set();
6840
+ /**
6841
+ * @internal Empty-READY guild stream window.
6842
+ * Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
6843
+ */
6648
6844
  _guildStreamSettleTimeout = null;
6649
6845
  /** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
6650
6846
  _deferredGatewayDispatches = [];
@@ -6675,7 +6871,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6675
6871
  const restApi = options.rest?.api;
6676
6872
  if (options.instance !== void 0) {
6677
6873
  this.instance = resolveInstanceEndpoints(options.instance);
6678
- resolveRestApi(this.instance.endpoints.api, restApi);
6874
+ resolveRestApi(this.instance.endpoints.api_public, restApi);
6679
6875
  } else {
6680
6876
  this.instance = resolveInstanceEndpoints(
6681
6877
  restApi !== void 0 ? { api: restApi } : void 0
@@ -6688,27 +6884,31 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6688
6884
  }
6689
6885
  this.rest = new import_rest3.REST({
6690
6886
  ...this.options.rest,
6691
- api: this.instance.endpoints.api,
6692
- version: this.options.rest?.version ?? "1"
6887
+ api: this.instance.endpoints.api_public,
6888
+ version: this.options.rest?.version ?? "1",
6889
+ locale: this.options.locale ?? this.options.rest?.locale
6693
6890
  });
6694
6891
  }
6695
6892
  /**
6696
6893
  * Create a client from instance discovery (`GET /.well-known/fluxer`).
6697
- * Does not log in — call {@link login} with a token afterward.
6894
+ * Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
6895
+ * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
6896
+ * Does not log in. Call {@link login} with a token afterward.
6698
6897
  *
6699
- * @param origin - API origin used only to fetch discovery (e.g. `https://api.example.com`)
6700
- * @param options - Client options (must not conflict with discovered `endpoints.api`)
6898
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
6899
+ * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
6701
6900
  * @param connectOptions - Optional abort signal for the discovery request
6702
6901
  */
6703
6902
  static async fromDiscovery(origin, options = {}, connectOptions) {
6704
- const bootstrapApi = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
6903
+ const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
6705
6904
  const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
6706
6905
  const bootstrap = new import_rest3.REST({
6707
6906
  ...options.rest ?? {},
6708
- api: bootstrapApi,
6709
- version
6907
+ api: bootstrapOrigin,
6908
+ version,
6909
+ locale: options.locale ?? options.rest?.locale
6710
6910
  });
6711
- const raw = await bootstrap.get(import_types39.Routes.instanceDiscovery(), {
6911
+ const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
6712
6912
  auth: false,
6713
6913
  ...connectOptions?.signal ? { signal: connectOptions.signal } : {}
6714
6914
  });
@@ -6716,7 +6916,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6716
6916
  const { rest, ...restOptions } = options;
6717
6917
  return new _Client({
6718
6918
  ...restOptions,
6719
- // Drop rest.api so discovered endpoints.api owns the host; keep other REST opts.
6919
+ // Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
6720
6920
  ...rest ? { rest: { ...rest, api: void 0 } } : {},
6721
6921
  instance: discovery
6722
6922
  });
@@ -6743,7 +6943,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6743
6943
  return resolveClientEmoji(this, emoji, guildId);
6744
6944
  }
6745
6945
  /**
6746
- * Fetch instance discovery document (`/.well-known/fluxer`).
6946
+ * Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
6747
6947
  * @returns Instance configuration (endpoints, features, metadata)
6748
6948
  */
6749
6949
  fetchInstance() {
@@ -7012,6 +7212,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7012
7212
  this.user = null;
7013
7213
  this.readyAt = null;
7014
7214
  this._pendingGuildIds = null;
7215
+ this._readyStubGuildIds.clear();
7015
7216
  this.guilds.clear();
7016
7217
  this.channels.clear();
7017
7218
  this.users.clear();