@fluxerjs/core 3.0.0 → 3.1.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/client.mjs CHANGED
@@ -424,6 +424,13 @@ function toSudoBody(options) {
424
424
  return body;
425
425
  }
426
426
 
427
+ // src/Helpers/AuditReason.ts
428
+ var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
429
+ function auditReasonHeaders(reason) {
430
+ if (reason == null || reason === "") return {};
431
+ return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
432
+ }
433
+
427
434
  // src/Helpers/MessageUtils/Body.ts
428
435
  import { AttachmentBuilder, EmbedBuilder, MessagePayload } from "@fluxerjs/builders";
429
436
  import { MessageAttachmentFlags, MessageReferenceType } from "@fluxerjs/types";
@@ -1071,6 +1078,67 @@ var CDN_URL = "https://fluxerusercontent.com";
1071
1078
  var STATIC_CDN_URL = "https://fluxerstatic.com";
1072
1079
 
1073
1080
  // src/Helpers/Cdn.ts
1081
+ var CDN_SIZE_LADDER = [
1082
+ 16,
1083
+ 20,
1084
+ 22,
1085
+ 24,
1086
+ 28,
1087
+ 32,
1088
+ 40,
1089
+ 44,
1090
+ 48,
1091
+ 56,
1092
+ 60,
1093
+ 64,
1094
+ 80,
1095
+ 96,
1096
+ 100,
1097
+ 128,
1098
+ 160,
1099
+ 240,
1100
+ 256,
1101
+ 300,
1102
+ 320,
1103
+ 480,
1104
+ 512,
1105
+ 600,
1106
+ 640,
1107
+ 1024,
1108
+ 1280,
1109
+ 1536,
1110
+ 2048,
1111
+ 3072,
1112
+ 4096,
1113
+ 8192,
1114
+ 16384
1115
+ ];
1116
+ var CDN_ASSET_CLASS_RANGE = {
1117
+ icon: { min: 128, max: 1024 },
1118
+ banner: { min: 480, max: 2400 },
1119
+ emoji: { min: 32, max: 512 },
1120
+ sticker: { min: 128, max: 512 }
1121
+ };
1122
+ function nearestSize(requested, candidates) {
1123
+ let best = candidates[0];
1124
+ let bestDist = Math.abs(requested - best);
1125
+ for (let i = 1; i < candidates.length; i++) {
1126
+ const step = candidates[i];
1127
+ const dist = Math.abs(requested - step);
1128
+ if (dist < bestDist || dist === bestDist && step > best) {
1129
+ best = step;
1130
+ bestDist = dist;
1131
+ }
1132
+ }
1133
+ return best;
1134
+ }
1135
+ function snapCdnSize(requested, assetClass) {
1136
+ const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
1137
+ const snapped = nearestSize(requested, CDN_SIZE_LADDER);
1138
+ const clamped = Math.min(max, Math.max(min, snapped));
1139
+ const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
1140
+ return nearestSize(clamped, allowed);
1141
+ }
1074
1142
  function mediaBase(options) {
1075
1143
  return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1076
1144
  }
@@ -1082,31 +1150,33 @@ function getExtension(hash, options) {
1082
1150
  if (hash?.startsWith("a_")) return "gif";
1083
1151
  return ext;
1084
1152
  }
1085
- function appendSize(options) {
1086
- return options?.size ? `?size=${options.size}` : "";
1153
+ function appendSize(options, assetClass) {
1154
+ const size = options?.size;
1155
+ if (size == null || !Number.isFinite(size) || size <= 0) return "";
1156
+ return `?size=${snapCdnSize(size, assetClass)}`;
1087
1157
  }
1088
1158
  function cdnAvatarURL(userId, avatarHash, options) {
1089
1159
  if (!avatarHash) return null;
1090
1160
  const ext = getExtension(avatarHash, options);
1091
- const size = appendSize(options);
1161
+ const size = appendSize(options, "icon");
1092
1162
  return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1093
1163
  }
1094
1164
  function cdnBannerURL(resourceId, bannerHash, options) {
1095
1165
  if (!bannerHash) return null;
1096
1166
  const ext = getExtension(bannerHash, options);
1097
- const size = appendSize(options);
1167
+ const size = appendSize(options, "banner");
1098
1168
  return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1099
1169
  }
1100
1170
  function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1101
1171
  if (!avatarHash) return null;
1102
1172
  const ext = getExtension(avatarHash, options);
1103
- const size = appendSize(options);
1173
+ const size = appendSize(options, "icon");
1104
1174
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1105
1175
  }
1106
1176
  function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1107
1177
  if (!bannerHash) return null;
1108
1178
  const ext = getExtension(bannerHash, options);
1109
- const size = appendSize(options);
1179
+ const size = appendSize(options, "banner");
1110
1180
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1111
1181
  }
1112
1182
  function cdnDefaultAvatarURL(userIdOrIndex, options) {
@@ -1115,16 +1185,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1115
1185
  }
1116
1186
  function cdnGuildAssetURL(kind, id, hash, options) {
1117
1187
  if (!hash) return null;
1118
- const size = options?.size ? `?size=${options.size}` : "";
1188
+ const assetClass = kind === "icons" ? "icon" : "banner";
1189
+ const size = appendSize(options, assetClass);
1119
1190
  return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1120
1191
  }
1121
1192
  function cdnEmojiURL(emojiId, animated, options) {
1122
1193
  const ext = animated ? "gif" : "png";
1123
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1194
+ const size = appendSize(options, "emoji");
1195
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
1124
1196
  }
1125
1197
  function cdnStickerURL(stickerId, animated, options) {
1126
1198
  const ext = animated ? "gif" : "png";
1127
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1199
+ const size = appendSize(options, "sticker");
1200
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
1128
1201
  }
1129
1202
 
1130
1203
  // src/Domain/Message/MessageSticker.ts
@@ -1352,6 +1425,8 @@ var Message = class _Message extends Base {
1352
1425
  mentionRoles;
1353
1426
  /** Client-side nonce for deduplication. */
1354
1427
  nonce;
1428
+ /** IDs of custom emojis in the message classified as explicit. */
1429
+ nsfwEmojis;
1355
1430
  /**
1356
1431
  * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1357
1432
  * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
@@ -1426,6 +1501,7 @@ var Message = class _Message extends Base {
1426
1501
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1427
1502
  this.mentionRoles = data.mention_roles ?? [];
1428
1503
  this.nonce = data.nonce ?? null;
1504
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1429
1505
  }
1430
1506
  /**
1431
1507
  * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
@@ -1458,6 +1534,7 @@ var Message = class _Message extends Base {
1458
1534
  this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1459
1535
  this.mentionRoles = data.mention_roles ?? [];
1460
1536
  this.nonce = data.nonce ?? null;
1537
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1461
1538
  }
1462
1539
  /**
1463
1540
  * Send a standalone message in this channel (not a reply).
@@ -1541,8 +1618,10 @@ var Message = class _Message extends Base {
1541
1618
  return this.client.channels.fetchMessage(this.channelId, this.id);
1542
1619
  }
1543
1620
  /** Delete this message. */
1544
- async delete() {
1545
- await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id));
1621
+ async delete(reason) {
1622
+ await this.client.rest.delete(Routes4.channelMessage(this.channelId, this.id), {
1623
+ ...auditReasonHeaders(reason)
1624
+ });
1546
1625
  this.client._removeMessageFromCache(this.channelId, this.id);
1547
1626
  }
1548
1627
  /** Delete a specific attachment from this message. */
@@ -1856,6 +1935,29 @@ var MessageCollector = class _MessageCollector extends EventEmitter2 {
1856
1935
 
1857
1936
  // src/Domain/Channel/Attachments.ts
1858
1937
  import { Routes as Routes6 } from "@fluxerjs/types";
1938
+ var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
1939
+ var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
1940
+ function instanceLimitOverridesSnapshot(client) {
1941
+ const rules = client.instance.discovery?.limits?.rules;
1942
+ if (!rules?.length) return null;
1943
+ const snapshot = {};
1944
+ for (const rule of rules) {
1945
+ Object.assign(snapshot, rule.overrides);
1946
+ }
1947
+ return Object.keys(snapshot).length ? snapshot : null;
1948
+ }
1949
+ function assertBotAttachmentLimits(client, files) {
1950
+ const snapshot = instanceLimitOverridesSnapshot(client);
1951
+ for (const file of files) {
1952
+ const size = file.data.byteLength;
1953
+ if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
1954
+ const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
1955
+ throw new FluxerError(
1956
+ `Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
1957
+ { code: ErrorCodes.AttachmentTooLarge }
1958
+ );
1959
+ }
1960
+ }
1859
1961
  function asBytes(data) {
1860
1962
  const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
1861
1963
  const out = new Uint8Array(src.byteLength);
@@ -1875,6 +1977,7 @@ async function putBlob(url, body, contentType) {
1875
1977
  }
1876
1978
  }
1877
1979
  async function uploadAttachmentsForSend(client, channelId, files) {
1980
+ assertBotAttachmentLimits(client, files);
1878
1981
  const plan = await client.rest.post(
1879
1982
  Routes6.channelAttachments(channelId),
1880
1983
  {
@@ -2171,11 +2274,12 @@ var Channel = class extends Base {
2171
2274
  if (options?.silent) params.set("silent", "true");
2172
2275
  if (options?.deleteMessages) params.set("delete_messages", "true");
2173
2276
  const qs2 = params.toString();
2174
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2277
+ const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
2175
2278
  const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2176
2279
  await this.client.rest.delete(Routes7.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2177
2280
  body,
2178
- auth: true
2281
+ auth: true,
2282
+ ...auditReasonHeaders(_reason)
2179
2283
  });
2180
2284
  this.client.channels.delete(this.id);
2181
2285
  this.client._clearMessageCache(this.id);
@@ -2340,7 +2444,7 @@ import {
2340
2444
  // src/Helpers/Instance.ts
2341
2445
  import { isRecord } from "@fluxerjs/util";
2342
2446
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2343
- api: "https://api.fluxer.app",
2447
+ api: "https://web.fluxer.app/api",
2344
2448
  api_client: "https://web.fluxer.app/api",
2345
2449
  api_public: "https://api.fluxer.app",
2346
2450
  gateway: "wss://gateway.fluxer.app",
@@ -2374,6 +2478,10 @@ function requireString(obj, key, path) {
2374
2478
  }
2375
2479
  return value;
2376
2480
  }
2481
+ var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
2482
+ function instanceDiscoveryUrl(origin) {
2483
+ return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
2484
+ }
2377
2485
  function normalizeApiOrigin(api) {
2378
2486
  const trimmed = api.trim().replace(/\/+$/, "");
2379
2487
  return trimmed.replace(/\/v\d+$/i, "");
@@ -2402,6 +2510,8 @@ function parseInstanceDiscovery(raw) {
2402
2510
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2403
2511
  }
2404
2512
  endpoints.api = normalizeApiOrigin(endpoints.api);
2513
+ endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2514
+ endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
2405
2515
  endpoints.invite = normalizeInviteBase(endpoints.invite);
2406
2516
  endpoints.media = endpoints.media.replace(/\/+$/, "");
2407
2517
  endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
@@ -2479,6 +2589,11 @@ function resolveInstanceEndpoints(input) {
2479
2589
  }
2480
2590
  }
2481
2591
  merged.api = normalizeApiOrigin(merged.api);
2592
+ merged.api_client = normalizeApiOrigin(merged.api_client);
2593
+ merged.api_public = normalizeApiOrigin(merged.api_public);
2594
+ if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
2595
+ merged.api_public = merged.api;
2596
+ }
2482
2597
  merged.invite = normalizeInviteBase(merged.invite);
2483
2598
  merged.media = merged.media.replace(/\/+$/, "");
2484
2599
  merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
@@ -2487,13 +2602,13 @@ function resolveInstanceEndpoints(input) {
2487
2602
  discovery: null
2488
2603
  });
2489
2604
  }
2490
- function resolveRestApi(instanceApi, restApi) {
2491
- const fromInstance = normalizeApiOrigin(instanceApi);
2605
+ function resolveRestApi(instanceApiPublic, restApi) {
2606
+ const fromInstance = normalizeApiOrigin(instanceApiPublic);
2492
2607
  if (restApi === void 0) return fromInstance;
2493
2608
  const fromRest = normalizeApiOrigin(restApi);
2494
2609
  if (fromRest !== fromInstance) {
2495
2610
  throw new FluxerError(
2496
- `Conflicting API hosts: instance.api (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2611
+ `Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2497
2612
  { code: ErrorCodes.ConflictingInstanceConfig }
2498
2613
  );
2499
2614
  }
@@ -2975,7 +3090,8 @@ var GuildChannel = class extends Channel {
2975
3090
  async edit(options) {
2976
3091
  const data = await this.client.rest.patch(Routes13.channel(this.id), {
2977
3092
  body: toChannelEditBody(options),
2978
- auth: true
3093
+ auth: true,
3094
+ ...auditReasonHeaders(options.reason)
2979
3095
  });
2980
3096
  this.name = data.name ?? this.name;
2981
3097
  this.parentId = data.parent_id ?? this.parentId;
@@ -3507,9 +3623,10 @@ var GuildEmoji = class extends Base {
3507
3623
  return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
3508
3624
  }
3509
3625
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
3510
- async delete() {
3626
+ async delete(reason) {
3511
3627
  await this.client.rest.delete(Routes15.guildEmoji(this.guildId, this.id), {
3512
- auth: true
3628
+ auth: true,
3629
+ ...auditReasonHeaders(reason)
3513
3630
  });
3514
3631
  const guild = this.client.guilds.get(this.guildId);
3515
3632
  if (guild) guild.emojis.delete(this.id);
@@ -3519,9 +3636,11 @@ var GuildEmoji = class extends Base {
3519
3636
  * Requires Manage Emojis and Stickers permission.
3520
3637
  */
3521
3638
  async edit(options) {
3639
+ const { reason, name } = options;
3522
3640
  const data = await this.client.rest.patch(Routes15.guildEmoji(this.guildId, this.id), {
3523
- body: options,
3524
- auth: true
3641
+ body: { name },
3642
+ auth: true,
3643
+ ...auditReasonHeaders(reason)
3525
3644
  });
3526
3645
  this.name = data.name;
3527
3646
  return this;
@@ -3537,6 +3656,9 @@ import { OverwriteType } from "@fluxerjs/types";
3537
3656
  import { ALL_PERMISSIONS_BIGINT, PermissionFlags as PermissionFlags2 } from "@fluxerjs/util";
3538
3657
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
3539
3658
  if (isOwner) return ALL_PERMISSIONS_BIGINT;
3659
+ if ((basePermissions & PermissionFlags2.Administrator) !== 0n) {
3660
+ return ALL_PERMISSIONS_BIGINT;
3661
+ }
3540
3662
  let perms = basePermissions;
3541
3663
  for (const overwrite of overwrites ?? []) {
3542
3664
  const applies = overwrite.type === OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === OverwriteType.Member && overwrite.id === memberId;
@@ -3545,7 +3667,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
3545
3667
  const deny = BigInt(overwrite.deny || "0");
3546
3668
  perms = perms & ~deny | allow;
3547
3669
  }
3548
- return (perms & PermissionFlags2.Administrator) !== 0n ? ALL_PERMISSIONS_BIGINT : perms;
3670
+ return perms;
3549
3671
  }
3550
3672
 
3551
3673
  // src/Domain/Guild/GuildMemberRoleManager.ts
@@ -3751,7 +3873,8 @@ var GuildMember = class _GuildMember extends Base {
3751
3873
  const route = isMe ? Routes17.guildMemberMe(this.guild.id) : Routes17.guildMember(this.guild.id, this.id);
3752
3874
  const data = await this.client.rest.patch(route, {
3753
3875
  body: toMemberEditBody(options),
3754
- auth: true
3876
+ auth: true,
3877
+ ...auditReasonHeaders(options.reason ?? options.timeoutReason)
3755
3878
  });
3756
3879
  this._patch(data);
3757
3880
  if (options.bio !== void 0) this.bio = options.bio;
@@ -3785,8 +3908,8 @@ var GuildMember = class _GuildMember extends Base {
3785
3908
  await this.edit({ channelId, connectionId });
3786
3909
  }
3787
3910
  /** Kick this member. Requires Kick Members. */
3788
- async kick() {
3789
- await this.guild.kick(this.id);
3911
+ async kick(reason) {
3912
+ await this.guild.kick(this.id, reason);
3790
3913
  }
3791
3914
  /** Ban this member. Requires Ban Members. */
3792
3915
  async ban(options) {
@@ -3910,9 +4033,10 @@ var GuildSticker = class extends Base {
3910
4033
  return SnowflakeUtil7.dateFromSnowflake(this.id);
3911
4034
  }
3912
4035
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3913
- async delete() {
4036
+ async delete(reason) {
3914
4037
  await this.client.rest.delete(Routes18.guildSticker(this.guildId, this.id), {
3915
- auth: true
4038
+ auth: true,
4039
+ ...auditReasonHeaders(reason)
3916
4040
  });
3917
4041
  const guild = this.client.guilds.get(this.guildId);
3918
4042
  if (guild) guild.stickers.delete(this.id);
@@ -3922,9 +4046,11 @@ var GuildSticker = class extends Base {
3922
4046
  * Requires Manage Emojis and Stickers permission.
3923
4047
  */
3924
4048
  async edit(options) {
4049
+ const { reason, ...body } = options;
3925
4050
  const data = await this.client.rest.patch(Routes18.guildSticker(this.guildId, this.id), {
3926
- body: options,
3927
- auth: true
4051
+ body,
4052
+ auth: true,
4053
+ ...auditReasonHeaders(reason)
3928
4054
  });
3929
4055
  const s = data;
3930
4056
  this.name = s.name;
@@ -4051,16 +4177,21 @@ var Role = class _Role extends Base {
4051
4177
  const body = toRoleEditBody(options);
4052
4178
  const data = await this.client.rest.patch(Routes19.guildRole(this.guildId, this.id), {
4053
4179
  body: Object.keys(body).length ? body : void 0,
4054
- auth: true
4180
+ auth: true,
4181
+ ...auditReasonHeaders(options.reason)
4055
4182
  });
4056
4183
  this._patch(data);
4057
4184
  return this;
4058
4185
  }
4059
4186
  /**
4060
4187
  * DELETE role. Requires Manage Roles.
4188
+ * @param reason - Audit log reason (`X-Audit-Log-Reason`)
4061
4189
  */
4062
- async delete() {
4063
- await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), { auth: true });
4190
+ async delete(reason) {
4191
+ await this.client.rest.delete(Routes19.guildRole(this.guildId, this.id), {
4192
+ auth: true,
4193
+ ...auditReasonHeaders(reason)
4194
+ });
4064
4195
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
4065
4196
  }
4066
4197
  };
@@ -4311,7 +4442,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
4311
4442
  return parsed.name;
4312
4443
  }
4313
4444
  async function fetchInstance(client) {
4314
- const raw = await client.rest.get(Routes21.instanceDiscovery(), { auth: false });
4445
+ const raw = await client.rest.get(Routes21.instanceDiscovery(), {
4446
+ auth: false,
4447
+ unversioned: true
4448
+ });
4315
4449
  return parseInstanceDiscovery(raw);
4316
4450
  }
4317
4451
  function fetchGatewayInfo(client) {
@@ -4690,9 +4824,11 @@ async function fetchEmoji(guild, emojiId) {
4690
4824
  }
4691
4825
  }
4692
4826
  async function createEmoji(guild, options) {
4827
+ const { reason, ...body } = options;
4693
4828
  const data = await guild.client.rest.post(Routes25.guildEmojis(guild.id), {
4694
- body: options,
4695
- auth: true
4829
+ body,
4830
+ auth: true,
4831
+ ...auditReasonHeaders(reason)
4696
4832
  });
4697
4833
  return cacheEmoji(guild, data);
4698
4834
  }
@@ -4711,6 +4847,19 @@ async function createEmojisBulk(guild, emojis) {
4711
4847
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
4712
4848
  }
4713
4849
 
4850
+ // src/Domain/Guild/GuildRoleManager.ts
4851
+ import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4852
+ var GuildRoleManager = class extends LimitedCollection3 {
4853
+ constructor(guildId, options) {
4854
+ super(options);
4855
+ this.guildId = guildId;
4856
+ }
4857
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4858
+ get everyone() {
4859
+ return this.get(this.guildId);
4860
+ }
4861
+ };
4862
+
4714
4863
  // src/Domain/Guild/MemberHttp.ts
4715
4864
  import { Routes as Routes26 } from "@fluxerjs/types";
4716
4865
  async function fetchMember(guild, userId) {
@@ -4767,9 +4916,10 @@ var GuildBan = class extends Base {
4767
4916
  * Remove this ban (unban the user).
4768
4917
  * Requires Ban Members permission.
4769
4918
  */
4770
- async unban() {
4919
+ async unban(reason) {
4771
4920
  await this.client.rest.delete(Routes27.guildBan(this.guildId, this.user.id), {
4772
- auth: true
4921
+ auth: true,
4922
+ ...auditReasonHeaders(reason)
4773
4923
  });
4774
4924
  }
4775
4925
  };
@@ -4779,33 +4929,27 @@ async function ban(guild, userId, options) {
4779
4929
  const body = options ? toGuildBanBody(options) : {};
4780
4930
  await guild.client.rest.put(Routes28.guildBan(guild.id, userId), {
4781
4931
  body: Object.keys(body).length ? body : void 0,
4782
- auth: true
4932
+ auth: true,
4933
+ ...auditReasonHeaders(options?.reason)
4783
4934
  });
4784
4935
  }
4785
4936
  async function fetchBans(guild) {
4786
4937
  const data = await guild.client.rest.get(Routes28.guildBans(guild.id));
4787
4938
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
4788
4939
  }
4789
- async function unban(guild, userId) {
4790
- await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), { auth: true });
4940
+ async function unban(guild, userId, reason) {
4941
+ await guild.client.rest.delete(Routes28.guildBan(guild.id, userId), {
4942
+ auth: true,
4943
+ ...auditReasonHeaders(reason)
4944
+ });
4791
4945
  }
4792
- async function kick(guild, userId) {
4793
- await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), { auth: true });
4946
+ async function kick(guild, userId, reason) {
4947
+ await guild.client.rest.delete(Routes28.guildMember(guild.id, userId), {
4948
+ auth: true,
4949
+ ...auditReasonHeaders(reason)
4950
+ });
4794
4951
  }
4795
4952
 
4796
- // src/Domain/Guild/GuildRoleManager.ts
4797
- import { LimitedCollection as LimitedCollection3 } from "@fluxerjs/collection";
4798
- var GuildRoleManager = class extends LimitedCollection3 {
4799
- constructor(guildId, options) {
4800
- super(options);
4801
- this.guildId = guildId;
4802
- }
4803
- /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4804
- get everyone() {
4805
- return this.get(this.guildId);
4806
- }
4807
- };
4808
-
4809
4953
  // src/Domain/Guild/Roles.ts
4810
4954
  import { Routes as Routes29 } from "@fluxerjs/types";
4811
4955
  import { parseRoleMention } from "@fluxerjs/util";
@@ -4813,7 +4957,8 @@ async function createRole(guild, options = {}) {
4813
4957
  const body = toRoleCreateBody(options);
4814
4958
  const data = await guild.client.rest.post(Routes29.guildRoles(guild.id), {
4815
4959
  body: Object.keys(body).length ? body : void 0,
4816
- auth: true
4960
+ auth: true,
4961
+ ...auditReasonHeaders(options.reason)
4817
4962
  });
4818
4963
  return cacheRole(guild, data);
4819
4964
  }
@@ -4879,9 +5024,11 @@ async function resetRoleHoistPositions(guild) {
4879
5024
  // src/Domain/Guild/Stickers.ts
4880
5025
  import { Routes as Routes30 } from "@fluxerjs/types";
4881
5026
  async function createSticker(guild, options) {
5027
+ const { reason, ...body } = options;
4882
5028
  const data = await guild.client.rest.post(Routes30.guildStickers(guild.id), {
4883
- body: options,
4884
- auth: true
5029
+ body,
5030
+ auth: true,
5031
+ ...auditReasonHeaders(reason)
4885
5032
  });
4886
5033
  return cacheSticker(guild, data);
4887
5034
  }
@@ -5211,12 +5358,12 @@ var Guild = class extends Base {
5211
5358
  return fetchBans(this);
5212
5359
  }
5213
5360
  /** Unban a user from the guild. Requires Ban Members. */
5214
- unban(userId) {
5215
- return unban(this, userId);
5361
+ unban(userId, reason) {
5362
+ return unban(this, userId, reason);
5216
5363
  }
5217
5364
  /** Kick a user from the guild. Requires Kick Members. */
5218
- kick(userId) {
5219
- return kick(this, userId);
5365
+ kick(userId, reason) {
5366
+ return kick(this, userId, reason);
5220
5367
  }
5221
5368
  /** Fetch all emojis in this guild from the API. */
5222
5369
  fetchEmojis() {
@@ -5666,7 +5813,14 @@ function markGuildUnavailable(client, id) {
5666
5813
  guild.available = false;
5667
5814
  client.emit(Events.GuildUnavailable, guild);
5668
5815
  }
5816
+ function isStartupGuildHydration(client) {
5817
+ return client._guildStreamSettleTimeout !== null;
5818
+ }
5669
5819
  var guildHandlers = {
5820
+ /**
5821
+ * Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
5822
+ * {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
5823
+ */
5670
5824
  GUILD_CREATE(client, d) {
5671
5825
  const raw = d;
5672
5826
  if (raw.unavailable === true) {
@@ -5679,11 +5833,32 @@ var guildHandlers = {
5679
5833
  }
5680
5834
  return;
5681
5835
  }
5836
+ const startupHydration = isStartupGuildHydration(client);
5837
+ if (startupHydration) {
5838
+ resetGuildStreamSettle(client);
5839
+ }
5682
5840
  const result = applyGuildSnapshotFromGateway(client, d);
5683
5841
  if (!result) return;
5684
5842
  const { guild, recovered } = result;
5685
- if (recovered) guild.available = true;
5686
- client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
5843
+ const legacyStartup = client.options.emitGuildCreateOnStartup === true;
5844
+ const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
5845
+ const isStartupBackfill = wasReadyStub || startupHydration;
5846
+ if (recovered) {
5847
+ guild.available = true;
5848
+ if (legacyStartup && isStartupBackfill) {
5849
+ client.emit(Events.GuildCreate, guild);
5850
+ } else {
5851
+ client.emit(Events.GuildAvailable, guild);
5852
+ }
5853
+ } else if (startupHydration) {
5854
+ if (legacyStartup) {
5855
+ client.emit(Events.GuildCreate, guild);
5856
+ } else {
5857
+ client.emit(Events.GuildAvailable, guild);
5858
+ }
5859
+ } else {
5860
+ client.emit(Events.GuildCreate, guild);
5861
+ }
5687
5862
  client._onGuildReceived(guild.id);
5688
5863
  },
5689
5864
  GUILD_UPDATE(client, d) {
@@ -5722,6 +5897,7 @@ var guildHandlers = {
5722
5897
  markGuildUnavailable(client, id);
5723
5898
  return;
5724
5899
  }
5900
+ client._readyStubGuildIds.delete(id);
5725
5901
  const guild = client.guilds.get(id);
5726
5902
  if (!guild) return;
5727
5903
  client.guilds.delete(id);
@@ -6240,10 +6416,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
6240
6416
  for (const g of guilds ?? []) {
6241
6417
  if (g.unavailable === true) {
6242
6418
  if (typeof g.id === "string") {
6243
- const existing = client.guilds.get(g.id);
6244
- if (existing && existing.available !== false) {
6245
- existing.available = false;
6419
+ let guild = client.guilds.get(g.id);
6420
+ if (!guild) {
6421
+ guild = new Guild(client, { id: g.id });
6422
+ guild.available = false;
6423
+ client.guilds.set(g.id, guild);
6424
+ } else if (guild.available !== false) {
6425
+ guild.available = false;
6246
6426
  }
6427
+ client._readyStubGuildIds.add(g.id);
6247
6428
  if (pending !== null) pending.add(g.id);
6248
6429
  }
6249
6430
  continue;
@@ -6271,6 +6452,13 @@ function clearGuildStreamSettle(client) {
6271
6452
  clearTimeout(client._guildStreamSettleTimeout);
6272
6453
  client._guildStreamSettleTimeout = null;
6273
6454
  }
6455
+ function resetGuildStreamSettle(client) {
6456
+ clearGuildStreamSettle(client);
6457
+ client._guildStreamSettleTimeout = setTimeout(() => {
6458
+ client._guildStreamSettleTimeout = null;
6459
+ if (client.readyAt === null) finalizeClientReady(client);
6460
+ }, GUILD_STREAM_SETTLE_MS);
6461
+ }
6274
6462
  function handleReadyPayload(client, data) {
6275
6463
  client.user = new ClientUser(client, data.user);
6276
6464
  const waitForGuilds = client.options.waitForGuilds === true;
@@ -6290,14 +6478,9 @@ function handleReadyPayload(client, data) {
6290
6478
  client._pendingGuildIds = existing;
6291
6479
  return;
6292
6480
  }
6293
- if (waitForGuilds && guilds.length === 0) {
6294
- if (client._guildStreamSettleTimeout === null) {
6295
- client._guildStreamSettleTimeout = setTimeout(() => {
6296
- client._guildStreamSettleTimeout = null;
6297
- if (client.readyAt === null) finalizeClientReady(client);
6298
- }, GUILD_STREAM_SETTLE_MS);
6299
- }
6300
- return;
6481
+ if (guilds.length === 0) {
6482
+ resetGuildStreamSettle(client);
6483
+ if (waitForGuilds) return;
6301
6484
  }
6302
6485
  finalizeClientReady(client);
6303
6486
  }
@@ -6632,7 +6815,12 @@ var Client = class _Client extends EventEmitter3 {
6632
6815
  _ws = null;
6633
6816
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
6634
6817
  _pendingGuildIds = null;
6635
- /** @internal Timeout when READY has no guilds but waitForGuilds is set. */
6818
+ /** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
6819
+ _readyStubGuildIds = /* @__PURE__ */ new Set();
6820
+ /**
6821
+ * @internal Empty-READY guild stream window.
6822
+ * Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
6823
+ */
6636
6824
  _guildStreamSettleTimeout = null;
6637
6825
  /** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
6638
6826
  _deferredGatewayDispatches = [];
@@ -6663,7 +6851,7 @@ var Client = class _Client extends EventEmitter3 {
6663
6851
  const restApi = options.rest?.api;
6664
6852
  if (options.instance !== void 0) {
6665
6853
  this.instance = resolveInstanceEndpoints(options.instance);
6666
- resolveRestApi(this.instance.endpoints.api, restApi);
6854
+ resolveRestApi(this.instance.endpoints.api_public, restApi);
6667
6855
  } else {
6668
6856
  this.instance = resolveInstanceEndpoints(
6669
6857
  restApi !== void 0 ? { api: restApi } : void 0
@@ -6676,27 +6864,31 @@ var Client = class _Client extends EventEmitter3 {
6676
6864
  }
6677
6865
  this.rest = new REST({
6678
6866
  ...this.options.rest,
6679
- api: this.instance.endpoints.api,
6680
- version: this.options.rest?.version ?? "1"
6867
+ api: this.instance.endpoints.api_public,
6868
+ version: this.options.rest?.version ?? "1",
6869
+ locale: this.options.locale ?? this.options.rest?.locale
6681
6870
  });
6682
6871
  }
6683
6872
  /**
6684
6873
  * Create a client from instance discovery (`GET /.well-known/fluxer`).
6685
- * Does not log in — call {@link login} with a token afterward.
6874
+ * Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
6875
+ * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
6876
+ * Does not log in. Call {@link login} with a token afterward.
6686
6877
  *
6687
- * @param origin - API origin used only to fetch discovery (e.g. `https://api.example.com`)
6688
- * @param options - Client options (must not conflict with discovered `endpoints.api`)
6878
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
6879
+ * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
6689
6880
  * @param connectOptions - Optional abort signal for the discovery request
6690
6881
  */
6691
6882
  static async fromDiscovery(origin, options = {}, connectOptions) {
6692
- const bootstrapApi = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
6883
+ const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
6693
6884
  const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
6694
6885
  const bootstrap = new REST({
6695
6886
  ...options.rest ?? {},
6696
- api: bootstrapApi,
6697
- version
6887
+ api: bootstrapOrigin,
6888
+ version,
6889
+ locale: options.locale ?? options.rest?.locale
6698
6890
  });
6699
- const raw = await bootstrap.get(Routes34.instanceDiscovery(), {
6891
+ const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
6700
6892
  auth: false,
6701
6893
  ...connectOptions?.signal ? { signal: connectOptions.signal } : {}
6702
6894
  });
@@ -6704,7 +6896,7 @@ var Client = class _Client extends EventEmitter3 {
6704
6896
  const { rest, ...restOptions } = options;
6705
6897
  return new _Client({
6706
6898
  ...restOptions,
6707
- // Drop rest.api so discovered endpoints.api owns the host; keep other REST opts.
6899
+ // Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
6708
6900
  ...rest ? { rest: { ...rest, api: void 0 } } : {},
6709
6901
  instance: discovery
6710
6902
  });
@@ -6731,7 +6923,7 @@ var Client = class _Client extends EventEmitter3 {
6731
6923
  return resolveClientEmoji(this, emoji, guildId);
6732
6924
  }
6733
6925
  /**
6734
- * Fetch instance discovery document (`/.well-known/fluxer`).
6926
+ * Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
6735
6927
  * @returns Instance configuration (endpoints, features, metadata)
6736
6928
  */
6737
6929
  fetchInstance() {
@@ -7000,6 +7192,7 @@ var Client = class _Client extends EventEmitter3 {
7000
7192
  this.user = null;
7001
7193
  this.readyAt = null;
7002
7194
  this._pendingGuildIds = null;
7195
+ this._readyStubGuildIds.clear();
7003
7196
  this.guilds.clear();
7004
7197
  this.channels.clear();
7005
7198
  this.users.clear();