@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.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  AllowedMentions: () => AllowedMentions,
24
+ AnnouncementChannel: () => AnnouncementChannel,
24
25
  AttachmentBuilder: () => import_builders5.AttachmentBuilder,
25
26
  AttachmentMeta: () => import_builders5.AttachmentMeta,
26
27
  AuditLogActionType: () => import_types40.AuditLogActionType,
@@ -58,6 +59,7 @@ __export(src_exports, {
58
59
  GuildOperations: () => import_types40.GuildOperations,
59
60
  GuildRoleManager: () => GuildRoleManager,
60
61
  GuildSticker: () => GuildSticker,
62
+ INSTANCE_DISCOVERY_PATH: () => INSTANCE_DISCOVERY_PATH,
61
63
  Invite: () => Invite,
62
64
  InviteType: () => import_types40.InviteType,
63
65
  LinkChannel: () => LinkChannel,
@@ -106,6 +108,7 @@ __export(src_exports, {
106
108
  cdnMemberBannerURL: () => cdnMemberBannerURL,
107
109
  cdnStickerURL: () => cdnStickerURL,
108
110
  createLogger: () => import_util27.createLogger,
111
+ instanceDiscoveryUrl: () => instanceDiscoveryUrl,
109
112
  inviteUrl: () => inviteUrl,
110
113
  normalizeApiOrigin: () => normalizeApiOrigin,
111
114
  normalizeCacheLimit: () => normalizeCacheLimit,
@@ -356,6 +359,7 @@ function toOverwriteWire(overwrite) {
356
359
  }
357
360
  function toChannelEditBody(options) {
358
361
  const body = {};
362
+ if (options.type !== void 0) body.type = options.type;
359
363
  if (options.name !== void 0) body.name = options.name;
360
364
  if (options.topic !== void 0) body.topic = options.topic;
361
365
  if (options.url !== void 0) body.url = options.url;
@@ -691,6 +695,13 @@ function toSudoBody(options) {
691
695
  return body;
692
696
  }
693
697
 
698
+ // src/Helpers/AuditReason.ts
699
+ var AUDIT_LOG_REASON_HEADER = "X-Audit-Log-Reason";
700
+ function auditReasonHeaders(reason) {
701
+ if (reason == null || reason === "") return {};
702
+ return { headers: { [AUDIT_LOG_REASON_HEADER]: encodeURIComponent(reason) } };
703
+ }
704
+
694
705
  // src/Helpers/MessageUtils/Body.ts
695
706
  var import_builders = require("@fluxerjs/builders");
696
707
  var import_types = require("@fluxerjs/types");
@@ -1345,6 +1356,67 @@ var CDN_URL = "https://fluxerusercontent.com";
1345
1356
  var STATIC_CDN_URL = "https://fluxerstatic.com";
1346
1357
 
1347
1358
  // src/Helpers/Cdn.ts
1359
+ var CDN_SIZE_LADDER = [
1360
+ 16,
1361
+ 20,
1362
+ 22,
1363
+ 24,
1364
+ 28,
1365
+ 32,
1366
+ 40,
1367
+ 44,
1368
+ 48,
1369
+ 56,
1370
+ 60,
1371
+ 64,
1372
+ 80,
1373
+ 96,
1374
+ 100,
1375
+ 128,
1376
+ 160,
1377
+ 240,
1378
+ 256,
1379
+ 300,
1380
+ 320,
1381
+ 480,
1382
+ 512,
1383
+ 600,
1384
+ 640,
1385
+ 1024,
1386
+ 1280,
1387
+ 1536,
1388
+ 2048,
1389
+ 3072,
1390
+ 4096,
1391
+ 8192,
1392
+ 16384
1393
+ ];
1394
+ var CDN_ASSET_CLASS_RANGE = {
1395
+ icon: { min: 128, max: 1024 },
1396
+ banner: { min: 480, max: 2400 },
1397
+ emoji: { min: 32, max: 512 },
1398
+ sticker: { min: 128, max: 512 }
1399
+ };
1400
+ function nearestSize(requested, candidates) {
1401
+ let best = candidates[0];
1402
+ let bestDist = Math.abs(requested - best);
1403
+ for (let i = 1; i < candidates.length; i++) {
1404
+ const step = candidates[i];
1405
+ const dist = Math.abs(requested - step);
1406
+ if (dist < bestDist || dist === bestDist && step > best) {
1407
+ best = step;
1408
+ bestDist = dist;
1409
+ }
1410
+ }
1411
+ return best;
1412
+ }
1413
+ function snapCdnSize(requested, assetClass) {
1414
+ const { min, max } = CDN_ASSET_CLASS_RANGE[assetClass];
1415
+ const snapped = nearestSize(requested, CDN_SIZE_LADDER);
1416
+ const clamped = Math.min(max, Math.max(min, snapped));
1417
+ const allowed = CDN_SIZE_LADDER.filter((step) => step >= min && step <= max);
1418
+ return nearestSize(clamped, allowed);
1419
+ }
1348
1420
  function mediaBase(options) {
1349
1421
  return (options?.mediaBase ?? CDN_URL).replace(/\/+$/, "");
1350
1422
  }
@@ -1356,13 +1428,15 @@ function getExtension(hash, options) {
1356
1428
  if (hash?.startsWith("a_")) return "gif";
1357
1429
  return ext;
1358
1430
  }
1359
- function appendSize(options) {
1360
- return options?.size ? `?size=${options.size}` : "";
1431
+ function appendSize(options, assetClass) {
1432
+ const size = options?.size;
1433
+ if (size == null || !Number.isFinite(size) || size <= 0) return "";
1434
+ return `?size=${snapCdnSize(size, assetClass)}`;
1361
1435
  }
1362
1436
  function cdnAvatarURL(userId, avatarHash, options) {
1363
1437
  if (!avatarHash) return null;
1364
1438
  const ext = getExtension(avatarHash, options);
1365
- const size = appendSize(options);
1439
+ const size = appendSize(options, "icon");
1366
1440
  return `${mediaBase(options)}/avatars/${userId}/${avatarHash}.${ext}${size}`;
1367
1441
  }
1368
1442
  function cdnDisplayAvatarURL(userId, avatarHash, options) {
@@ -1371,19 +1445,19 @@ function cdnDisplayAvatarURL(userId, avatarHash, options) {
1371
1445
  function cdnBannerURL(resourceId, bannerHash, options) {
1372
1446
  if (!bannerHash) return null;
1373
1447
  const ext = getExtension(bannerHash, options);
1374
- const size = appendSize(options);
1448
+ const size = appendSize(options, "banner");
1375
1449
  return `${mediaBase(options)}/banners/${resourceId}/${bannerHash}.${ext}${size}`;
1376
1450
  }
1377
1451
  function cdnMemberAvatarURL(guildId, userId, avatarHash, options) {
1378
1452
  if (!avatarHash) return null;
1379
1453
  const ext = getExtension(avatarHash, options);
1380
- const size = appendSize(options);
1454
+ const size = appendSize(options, "icon");
1381
1455
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/avatars/${avatarHash}.${ext}${size}`;
1382
1456
  }
1383
1457
  function cdnMemberBannerURL(guildId, userId, bannerHash, options) {
1384
1458
  if (!bannerHash) return null;
1385
1459
  const ext = getExtension(bannerHash, options);
1386
- const size = appendSize(options);
1460
+ const size = appendSize(options, "banner");
1387
1461
  return `${mediaBase(options)}/guilds/${guildId}/users/${userId}/banners/${bannerHash}.${ext}${size}`;
1388
1462
  }
1389
1463
  function cdnDefaultAvatarURL(userIdOrIndex, options) {
@@ -1392,16 +1466,19 @@ function cdnDefaultAvatarURL(userIdOrIndex, options) {
1392
1466
  }
1393
1467
  function cdnGuildAssetURL(kind, id, hash, options) {
1394
1468
  if (!hash) return null;
1395
- const size = options?.size ? `?size=${options.size}` : "";
1469
+ const assetClass = kind === "icons" ? "icon" : "banner";
1470
+ const size = appendSize(options, assetClass);
1396
1471
  return `${mediaBase(options)}/${kind}/${id}/${hash}.png${size}`;
1397
1472
  }
1398
1473
  function cdnEmojiURL(emojiId, animated, options) {
1399
1474
  const ext = animated ? "gif" : "png";
1400
- return `${mediaBase(options)}/emojis/${emojiId}.${ext}`;
1475
+ const size = appendSize(options, "emoji");
1476
+ return `${mediaBase(options)}/emojis/${emojiId}.${ext}${size}`;
1401
1477
  }
1402
1478
  function cdnStickerURL(stickerId, animated, options) {
1403
1479
  const ext = animated ? "gif" : "png";
1404
- return `${mediaBase(options)}/stickers/${stickerId}.${ext}`;
1480
+ const size = appendSize(options, "sticker");
1481
+ return `${mediaBase(options)}/stickers/${stickerId}.${ext}${size}`;
1405
1482
  }
1406
1483
 
1407
1484
  // src/Domain/Message/MessageSticker.ts
@@ -1629,6 +1706,8 @@ var Message = class _Message extends Base {
1629
1706
  mentionRoles;
1630
1707
  /** Client-side nonce for deduplication. */
1631
1708
  nonce;
1709
+ /** IDs of custom emojis in the message classified as explicit. */
1710
+ nsfwEmojis;
1632
1711
  /**
1633
1712
  * Cached text-capable channel (guild text, guild voice, or DM), or null if uncached / not text-based.
1634
1713
  * Narrowed type has {@link Channel.send} and {@link Channel.delete}.
@@ -1703,6 +1782,7 @@ var Message = class _Message extends Base {
1703
1782
  this.mentions = (data.mentions ?? []).map((u) => client.getOrCreateUser(u));
1704
1783
  this.mentionRoles = data.mention_roles ?? [];
1705
1784
  this.nonce = data.nonce ?? null;
1785
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1706
1786
  }
1707
1787
  /**
1708
1788
  * Apply an API message payload in place (cache identity / MESSAGE_UPDATE).
@@ -1735,6 +1815,7 @@ var Message = class _Message extends Base {
1735
1815
  this.mentions = (data.mentions ?? []).map((u) => this.client.getOrCreateUser(u));
1736
1816
  this.mentionRoles = data.mention_roles ?? [];
1737
1817
  this.nonce = data.nonce ?? null;
1818
+ this.nsfwEmojis = data.nsfw_emojis ?? [];
1738
1819
  }
1739
1820
  /**
1740
1821
  * Send a standalone message in this channel (not a reply).
@@ -1818,8 +1899,10 @@ var Message = class _Message extends Base {
1818
1899
  return this.client.channels.fetchMessage(this.channelId, this.id);
1819
1900
  }
1820
1901
  /** Delete this message. */
1821
- async delete() {
1822
- await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id));
1902
+ async delete(reason) {
1903
+ await this.client.rest.delete(import_types5.Routes.channelMessage(this.channelId, this.id), {
1904
+ ...auditReasonHeaders(reason)
1905
+ });
1823
1906
  this.client._removeMessageFromCache(this.channelId, this.id);
1824
1907
  }
1825
1908
  /** Delete a specific attachment from this message. */
@@ -2123,6 +2206,29 @@ var MessageCollector = class _MessageCollector extends import_node_events2.Event
2123
2206
 
2124
2207
  // src/Domain/Channel/Attachments.ts
2125
2208
  var import_types7 = require("@fluxerjs/types");
2209
+ var BOT_ATTACHMENT_MAX_BYTES = 50 * 1024 * 1024;
2210
+ var ATTACHMENT_MULTIPART_THRESHOLD_BYTES = 10 * 1024 * 1024;
2211
+ function instanceLimitOverridesSnapshot(client) {
2212
+ const rules = client.instance.discovery?.limits?.rules;
2213
+ if (!rules?.length) return null;
2214
+ const snapshot = {};
2215
+ for (const rule of rules) {
2216
+ Object.assign(snapshot, rule.overrides);
2217
+ }
2218
+ return Object.keys(snapshot).length ? snapshot : null;
2219
+ }
2220
+ function assertBotAttachmentLimits(client, files) {
2221
+ const snapshot = instanceLimitOverridesSnapshot(client);
2222
+ for (const file of files) {
2223
+ const size = file.data.byteLength;
2224
+ if (size <= BOT_ATTACHMENT_MAX_BYTES) continue;
2225
+ const snapshotNote = snapshot ? ` Instance limit overrides: ${JSON.stringify(snapshot)}.` : "";
2226
+ throw new import_util4.FluxerError(
2227
+ `Bot attachments are limited to 50 MiB (${BOT_ATTACHMENT_MAX_BYTES} bytes); "${file.filename}" is ${size} bytes.${snapshotNote}`,
2228
+ { code: import_util3.ErrorCodes.AttachmentTooLarge }
2229
+ );
2230
+ }
2231
+ }
2126
2232
  function asBytes(data) {
2127
2233
  const src = data instanceof ArrayBuffer ? new Uint8Array(data) : new Uint8Array(data);
2128
2234
  const out = new Uint8Array(src.byteLength);
@@ -2142,6 +2248,7 @@ async function putBlob(url, body, contentType) {
2142
2248
  }
2143
2249
  }
2144
2250
  async function uploadAttachmentsForSend(client, channelId, files) {
2251
+ assertBotAttachmentLimits(client, files);
2145
2252
  const plan = await client.rest.post(
2146
2253
  import_types7.Routes.channelAttachments(channelId),
2147
2254
  {
@@ -2254,20 +2361,24 @@ var Channel = class extends Base {
2254
2361
  throw new Error("Channel.createDM not initialized");
2255
2362
  }
2256
2363
  /**
2257
- * Whether this channel type can carry messages (text, voice, DM, group DM, notes).
2364
+ * Whether this channel type can carry messages (text, announcement, voice, DM, group DM, notes).
2258
2365
  * Checks {@link ChannelType}, not whether `send` exists on the instance.
2259
2366
  */
2260
2367
  isTextBased() {
2261
- 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;
2368
+ 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;
2262
2369
  }
2263
- /** Check if this is a guild channel (text, voice, category, or link). */
2370
+ /** Check if this is a guild channel (text, announcement, voice, category, or link). */
2264
2371
  isGuild() {
2265
- 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;
2372
+ 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;
2266
2373
  }
2267
2374
  /** Check if this is a guild text channel. */
2268
2375
  isText() {
2269
2376
  return this.type === import_types8.ChannelType.GuildText;
2270
2377
  }
2378
+ /** Check if this is a guild announcement channel. */
2379
+ isAnnouncement() {
2380
+ return this.type === import_types8.ChannelType.GuildAnnouncement;
2381
+ }
2271
2382
  /** Check if this is a category channel. */
2272
2383
  isCategory() {
2273
2384
  return this.type === import_types8.ChannelType.GuildCategory;
@@ -2438,11 +2549,12 @@ var Channel = class extends Base {
2438
2549
  if (options?.silent) params.set("silent", "true");
2439
2550
  if (options?.deleteMessages) params.set("delete_messages", "true");
2440
2551
  const qs2 = params.toString();
2441
- const { silent: _s, deleteMessages: _d, ...sudo } = options ?? {};
2552
+ const { silent: _s, deleteMessages: _d, reason: _reason, ...sudo } = options ?? {};
2442
2553
  const body = Object.keys(sudo).length ? toSudoBody(sudo) : void 0;
2443
2554
  await this.client.rest.delete(import_types8.Routes.channel(this.id) + (qs2 ? `?${qs2}` : ""), {
2444
2555
  body,
2445
- auth: true
2556
+ auth: true,
2557
+ ...auditReasonHeaders(_reason)
2446
2558
  });
2447
2559
  this.client.channels.delete(this.id);
2448
2560
  this.client._clearMessageCache(this.id);
@@ -2602,7 +2714,7 @@ var import_types11 = require("@fluxerjs/types");
2602
2714
  // src/Helpers/Instance.ts
2603
2715
  var import_util9 = require("@fluxerjs/util");
2604
2716
  var DEFAULT_INSTANCE_ENDPOINTS = Object.freeze({
2605
- api: "https://api.fluxer.app",
2717
+ api: "https://web.fluxer.app/api",
2606
2718
  api_client: "https://web.fluxer.app/api",
2607
2719
  api_public: "https://api.fluxer.app",
2608
2720
  gateway: "wss://gateway.fluxer.app",
@@ -2636,6 +2748,10 @@ function requireString(obj, key, path) {
2636
2748
  }
2637
2749
  return value;
2638
2750
  }
2751
+ var INSTANCE_DISCOVERY_PATH = "/.well-known/fluxer";
2752
+ function instanceDiscoveryUrl(origin) {
2753
+ return `${normalizeApiOrigin(origin)}${INSTANCE_DISCOVERY_PATH}`;
2754
+ }
2639
2755
  function normalizeApiOrigin(api) {
2640
2756
  const trimmed = api.trim().replace(/\/+$/, "");
2641
2757
  return trimmed.replace(/\/v\d+$/i, "");
@@ -2664,6 +2780,8 @@ function parseInstanceDiscovery(raw) {
2664
2780
  endpoints[key] = requireString(raw.endpoints, key, "endpoints");
2665
2781
  }
2666
2782
  endpoints.api = normalizeApiOrigin(endpoints.api);
2783
+ endpoints.api_client = normalizeApiOrigin(endpoints.api_client);
2784
+ endpoints.api_public = normalizeApiOrigin(endpoints.api_public);
2667
2785
  endpoints.invite = normalizeInviteBase(endpoints.invite);
2668
2786
  endpoints.media = endpoints.media.replace(/\/+$/, "");
2669
2787
  endpoints.static_cdn = endpoints.static_cdn.replace(/\/+$/, "");
@@ -2741,6 +2859,11 @@ function resolveInstanceEndpoints(input) {
2741
2859
  }
2742
2860
  }
2743
2861
  merged.api = normalizeApiOrigin(merged.api);
2862
+ merged.api_client = normalizeApiOrigin(merged.api_client);
2863
+ merged.api_public = normalizeApiOrigin(merged.api_public);
2864
+ if (typeof partial.api === "string" && partial.api.length > 0 && (typeof partial.api_public !== "string" || partial.api_public.length === 0)) {
2865
+ merged.api_public = merged.api;
2866
+ }
2744
2867
  merged.invite = normalizeInviteBase(merged.invite);
2745
2868
  merged.media = merged.media.replace(/\/+$/, "");
2746
2869
  merged.static_cdn = merged.static_cdn.replace(/\/+$/, "");
@@ -2749,13 +2872,13 @@ function resolveInstanceEndpoints(input) {
2749
2872
  discovery: null
2750
2873
  });
2751
2874
  }
2752
- function resolveRestApi(instanceApi, restApi) {
2753
- const fromInstance = normalizeApiOrigin(instanceApi);
2875
+ function resolveRestApi(instanceApiPublic, restApi) {
2876
+ const fromInstance = normalizeApiOrigin(instanceApiPublic);
2754
2877
  if (restApi === void 0) return fromInstance;
2755
2878
  const fromRest = normalizeApiOrigin(restApi);
2756
2879
  if (fromRest !== fromInstance) {
2757
2880
  throw new import_util4.FluxerError(
2758
- `Conflicting API hosts: instance.api (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2881
+ `Conflicting API hosts: instance.api_public (${fromInstance}) vs rest.api (${fromRest}). Prefer ClientOptions.instance.`,
2759
2882
  { code: import_util3.ErrorCodes.ConflictingInstanceConfig }
2760
2883
  );
2761
2884
  }
@@ -3235,7 +3358,8 @@ var GuildChannel = class extends Channel {
3235
3358
  async edit(options) {
3236
3359
  const data = await this.client.rest.patch(import_types14.Routes.channel(this.id), {
3237
3360
  body: toChannelEditBody(options),
3238
- auth: true
3361
+ auth: true,
3362
+ ...auditReasonHeaders(options.reason)
3239
3363
  });
3240
3364
  this.name = data.name ?? this.name;
3241
3365
  this.parentId = data.parent_id ?? this.parentId;
@@ -3294,6 +3418,8 @@ var TextChannel = class extends TextCapable(GuildChannel) {
3294
3418
  }
3295
3419
  }
3296
3420
  };
3421
+ var AnnouncementChannel = class extends TextChannel {
3422
+ };
3297
3423
  var CategoryChannel = class extends GuildChannel {
3298
3424
  };
3299
3425
  var VoiceChannel = class extends TextCapable(GuildChannel) {
@@ -3376,6 +3502,7 @@ var LinkChannel = class extends GuildChannel {
3376
3502
  var import_types15 = require("@fluxerjs/types");
3377
3503
  var GUILD_FACTORIES = {
3378
3504
  [import_types15.ChannelType.GuildText]: (c, d) => new TextChannel(c, d),
3505
+ [import_types15.ChannelType.GuildAnnouncement]: (c, d) => new AnnouncementChannel(c, d),
3379
3506
  [import_types15.ChannelType.GuildCategory]: (c, d) => new CategoryChannel(c, d),
3380
3507
  [import_types15.ChannelType.GuildVoice]: (c, d) => new VoiceChannel(c, d),
3381
3508
  [import_types15.ChannelType.GuildLink]: (c, d) => new LinkChannel(c, d)
@@ -3450,9 +3577,10 @@ var GuildEmoji = class extends Base {
3450
3577
  return `<${this.animated ? "a" : ""}:${this.name}:${this.id}>`;
3451
3578
  }
3452
3579
  /** Delete this emoji. Requires Manage Emojis and Stickers permission. */
3453
- async delete() {
3580
+ async delete(reason) {
3454
3581
  await this.client.rest.delete(import_types16.Routes.guildEmoji(this.guildId, this.id), {
3455
- auth: true
3582
+ auth: true,
3583
+ ...auditReasonHeaders(reason)
3456
3584
  });
3457
3585
  const guild = this.client.guilds.get(this.guildId);
3458
3586
  if (guild) guild.emojis.delete(this.id);
@@ -3462,9 +3590,11 @@ var GuildEmoji = class extends Base {
3462
3590
  * Requires Manage Emojis and Stickers permission.
3463
3591
  */
3464
3592
  async edit(options) {
3593
+ const { reason, name } = options;
3465
3594
  const data = await this.client.rest.patch(import_types16.Routes.guildEmoji(this.guildId, this.id), {
3466
- body: options,
3467
- auth: true
3595
+ body: { name },
3596
+ auth: true,
3597
+ ...auditReasonHeaders(reason)
3468
3598
  });
3469
3599
  this.name = data.name;
3470
3600
  return this;
@@ -3480,6 +3610,9 @@ var import_types17 = require("@fluxerjs/types");
3480
3610
  var import_util15 = require("@fluxerjs/util");
3481
3611
  function computePermissions(basePermissions, overwrites, memberRoles, memberId, isOwner) {
3482
3612
  if (isOwner) return import_util15.ALL_PERMISSIONS_BIGINT;
3613
+ if ((basePermissions & import_util15.PermissionFlags.Administrator) !== 0n) {
3614
+ return import_util15.ALL_PERMISSIONS_BIGINT;
3615
+ }
3483
3616
  let perms = basePermissions;
3484
3617
  for (const overwrite of overwrites ?? []) {
3485
3618
  const applies = overwrite.type === import_types17.OverwriteType.Role && memberRoles.includes(overwrite.id) || overwrite.type === import_types17.OverwriteType.Member && overwrite.id === memberId;
@@ -3488,7 +3621,7 @@ function computePermissions(basePermissions, overwrites, memberRoles, memberId,
3488
3621
  const deny = BigInt(overwrite.deny || "0");
3489
3622
  perms = perms & ~deny | allow;
3490
3623
  }
3491
- return (perms & import_util15.PermissionFlags.Administrator) !== 0n ? import_util15.ALL_PERMISSIONS_BIGINT : perms;
3624
+ return perms;
3492
3625
  }
3493
3626
 
3494
3627
  // src/Domain/Guild/GuildMemberRoleManager.ts
@@ -3694,7 +3827,8 @@ var GuildMember = class _GuildMember extends Base {
3694
3827
  const route = isMe ? import_types19.Routes.guildMemberMe(this.guild.id) : import_types19.Routes.guildMember(this.guild.id, this.id);
3695
3828
  const data = await this.client.rest.patch(route, {
3696
3829
  body: toMemberEditBody(options),
3697
- auth: true
3830
+ auth: true,
3831
+ ...auditReasonHeaders(options.reason ?? options.timeoutReason)
3698
3832
  });
3699
3833
  this._patch(data);
3700
3834
  if (options.bio !== void 0) this.bio = options.bio;
@@ -3728,8 +3862,8 @@ var GuildMember = class _GuildMember extends Base {
3728
3862
  await this.edit({ channelId, connectionId });
3729
3863
  }
3730
3864
  /** Kick this member. Requires Kick Members. */
3731
- async kick() {
3732
- await this.guild.kick(this.id);
3865
+ async kick(reason) {
3866
+ await this.guild.kick(this.id, reason);
3733
3867
  }
3734
3868
  /** Ban this member. Requires Ban Members. */
3735
3869
  async ban(options) {
@@ -3853,9 +3987,10 @@ var GuildSticker = class extends Base {
3853
3987
  return import_util17.SnowflakeUtil.dateFromSnowflake(this.id);
3854
3988
  }
3855
3989
  /** Delete this sticker. Requires Manage Emojis and Stickers permission. */
3856
- async delete() {
3990
+ async delete(reason) {
3857
3991
  await this.client.rest.delete(import_types20.Routes.guildSticker(this.guildId, this.id), {
3858
- auth: true
3992
+ auth: true,
3993
+ ...auditReasonHeaders(reason)
3859
3994
  });
3860
3995
  const guild = this.client.guilds.get(this.guildId);
3861
3996
  if (guild) guild.stickers.delete(this.id);
@@ -3865,9 +4000,11 @@ var GuildSticker = class extends Base {
3865
4000
  * Requires Manage Emojis and Stickers permission.
3866
4001
  */
3867
4002
  async edit(options) {
4003
+ const { reason, ...body } = options;
3868
4004
  const data = await this.client.rest.patch(import_types20.Routes.guildSticker(this.guildId, this.id), {
3869
- body: options,
3870
- auth: true
4005
+ body,
4006
+ auth: true,
4007
+ ...auditReasonHeaders(reason)
3871
4008
  });
3872
4009
  const s = data;
3873
4010
  this.name = s.name;
@@ -3989,16 +4126,21 @@ var Role = class _Role extends Base {
3989
4126
  const body = toRoleEditBody(options);
3990
4127
  const data = await this.client.rest.patch(import_types21.Routes.guildRole(this.guildId, this.id), {
3991
4128
  body: Object.keys(body).length ? body : void 0,
3992
- auth: true
4129
+ auth: true,
4130
+ ...auditReasonHeaders(options.reason)
3993
4131
  });
3994
4132
  this._patch(data);
3995
4133
  return this;
3996
4134
  }
3997
4135
  /**
3998
4136
  * DELETE role. Requires Manage Roles.
4137
+ * @param reason - Audit log reason (`X-Audit-Log-Reason`)
3999
4138
  */
4000
- async delete() {
4001
- await this.client.rest.delete(import_types21.Routes.guildRole(this.guildId, this.id), { auth: true });
4139
+ async delete(reason) {
4140
+ await this.client.rest.delete(import_types21.Routes.guildRole(this.guildId, this.id), {
4141
+ auth: true,
4142
+ ...auditReasonHeaders(reason)
4143
+ });
4002
4144
  this.client.guilds.get(this.guildId)?.roles.delete(this.id);
4003
4145
  }
4004
4146
  };
@@ -4431,7 +4573,10 @@ async function resolveClientEmoji(client, emoji, guildId) {
4431
4573
  return parsed.name;
4432
4574
  }
4433
4575
  async function fetchInstance(client) {
4434
- const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), { auth: false });
4576
+ const raw = await client.rest.get(import_types24.Routes.instanceDiscovery(), {
4577
+ auth: false,
4578
+ unversioned: true
4579
+ });
4435
4580
  return parseInstanceDiscovery(raw);
4436
4581
  }
4437
4582
  function fetchGatewayInfo(client) {
@@ -4810,9 +4955,11 @@ async function fetchEmoji(guild, emojiId) {
4810
4955
  }
4811
4956
  }
4812
4957
  async function createEmoji(guild, options) {
4958
+ const { reason, ...body } = options;
4813
4959
  const data = await guild.client.rest.post(import_types28.Routes.guildEmojis(guild.id), {
4814
- body: options,
4815
- auth: true
4960
+ body,
4961
+ auth: true,
4962
+ ...auditReasonHeaders(reason)
4816
4963
  });
4817
4964
  return cacheEmoji(guild, data);
4818
4965
  }
@@ -4831,6 +4978,19 @@ async function createEmojisBulk(guild, emojis) {
4831
4978
  return { success: data.success.map((e) => cacheEmoji(guild, e)), failed: data.failed };
4832
4979
  }
4833
4980
 
4981
+ // src/Domain/Guild/GuildRoleManager.ts
4982
+ var import_collection11 = require("@fluxerjs/collection");
4983
+ var GuildRoleManager = class extends import_collection11.LimitedCollection {
4984
+ constructor(guildId, options) {
4985
+ super(options);
4986
+ this.guildId = guildId;
4987
+ }
4988
+ /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4989
+ get everyone() {
4990
+ return this.get(this.guildId);
4991
+ }
4992
+ };
4993
+
4834
4994
  // src/Domain/Guild/MemberHttp.ts
4835
4995
  var import_types29 = require("@fluxerjs/types");
4836
4996
  async function fetchMember(guild, userId) {
@@ -4887,9 +5047,10 @@ var GuildBan = class extends Base {
4887
5047
  * Remove this ban (unban the user).
4888
5048
  * Requires Ban Members permission.
4889
5049
  */
4890
- async unban() {
5050
+ async unban(reason) {
4891
5051
  await this.client.rest.delete(import_types30.Routes.guildBan(this.guildId, this.user.id), {
4892
- auth: true
5052
+ auth: true,
5053
+ ...auditReasonHeaders(reason)
4893
5054
  });
4894
5055
  }
4895
5056
  };
@@ -4899,33 +5060,27 @@ async function ban(guild, userId, options) {
4899
5060
  const body = options ? toGuildBanBody(options) : {};
4900
5061
  await guild.client.rest.put(import_types31.Routes.guildBan(guild.id, userId), {
4901
5062
  body: Object.keys(body).length ? body : void 0,
4902
- auth: true
5063
+ auth: true,
5064
+ ...auditReasonHeaders(options?.reason)
4903
5065
  });
4904
5066
  }
4905
5067
  async function fetchBans(guild) {
4906
5068
  const data = await guild.client.rest.get(import_types31.Routes.guildBans(guild.id));
4907
5069
  return data.map((b) => new GuildBan(guild.client, { ...b, guild_id: guild.id }, guild.id));
4908
5070
  }
4909
- async function unban(guild, userId) {
4910
- await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), { auth: true });
5071
+ async function unban(guild, userId, reason) {
5072
+ await guild.client.rest.delete(import_types31.Routes.guildBan(guild.id, userId), {
5073
+ auth: true,
5074
+ ...auditReasonHeaders(reason)
5075
+ });
4911
5076
  }
4912
- async function kick(guild, userId) {
4913
- await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), { auth: true });
5077
+ async function kick(guild, userId, reason) {
5078
+ await guild.client.rest.delete(import_types31.Routes.guildMember(guild.id, userId), {
5079
+ auth: true,
5080
+ ...auditReasonHeaders(reason)
5081
+ });
4914
5082
  }
4915
5083
 
4916
- // src/Domain/Guild/GuildRoleManager.ts
4917
- var import_collection11 = require("@fluxerjs/collection");
4918
- var GuildRoleManager = class extends import_collection11.LimitedCollection {
4919
- constructor(guildId, options) {
4920
- super(options);
4921
- this.guildId = guildId;
4922
- }
4923
- /** The @everyone role (`id === guild.id`), or undefined if uncached. */
4924
- get everyone() {
4925
- return this.get(this.guildId);
4926
- }
4927
- };
4928
-
4929
5084
  // src/Domain/Guild/Roles.ts
4930
5085
  var import_types32 = require("@fluxerjs/types");
4931
5086
  var import_util21 = require("@fluxerjs/util");
@@ -4933,7 +5088,8 @@ async function createRole(guild, options = {}) {
4933
5088
  const body = toRoleCreateBody(options);
4934
5089
  const data = await guild.client.rest.post(import_types32.Routes.guildRoles(guild.id), {
4935
5090
  body: Object.keys(body).length ? body : void 0,
4936
- auth: true
5091
+ auth: true,
5092
+ ...auditReasonHeaders(options.reason)
4937
5093
  });
4938
5094
  return cacheRole(guild, data);
4939
5095
  }
@@ -4999,9 +5155,11 @@ async function resetRoleHoistPositions(guild) {
4999
5155
  // src/Domain/Guild/Stickers.ts
5000
5156
  var import_types33 = require("@fluxerjs/types");
5001
5157
  async function createSticker(guild, options) {
5158
+ const { reason, ...body } = options;
5002
5159
  const data = await guild.client.rest.post(import_types33.Routes.guildStickers(guild.id), {
5003
- body: options,
5004
- auth: true
5160
+ body,
5161
+ auth: true,
5162
+ ...auditReasonHeaders(reason)
5005
5163
  });
5006
5164
  return cacheSticker(guild, data);
5007
5165
  }
@@ -5331,12 +5489,12 @@ var Guild = class extends Base {
5331
5489
  return fetchBans(this);
5332
5490
  }
5333
5491
  /** Unban a user from the guild. Requires Ban Members. */
5334
- unban(userId) {
5335
- return unban(this, userId);
5492
+ unban(userId, reason) {
5493
+ return unban(this, userId, reason);
5336
5494
  }
5337
5495
  /** Kick a user from the guild. Requires Kick Members. */
5338
- kick(userId) {
5339
- return kick(this, userId);
5496
+ kick(userId, reason) {
5497
+ return kick(this, userId, reason);
5340
5498
  }
5341
5499
  /** Fetch all emojis in this guild from the API. */
5342
5500
  fetchEmojis() {
@@ -5786,7 +5944,14 @@ function markGuildUnavailable(client, id) {
5786
5944
  guild.available = false;
5787
5945
  client.emit(Events.GuildUnavailable, guild);
5788
5946
  }
5947
+ function isStartupGuildHydration(client) {
5948
+ return client._guildStreamSettleTimeout !== null;
5949
+ }
5789
5950
  var guildHandlers = {
5951
+ /**
5952
+ * Available snapshots: {@link Events.GuildAvailable} for READY stubs / outage recovery,
5953
+ * {@link Events.GuildCreate} for real joins (unless {@link ClientOptions.emitGuildCreateOnStartup}).
5954
+ */
5790
5955
  GUILD_CREATE(client, d) {
5791
5956
  const raw = d;
5792
5957
  if (raw.unavailable === true) {
@@ -5799,11 +5964,32 @@ var guildHandlers = {
5799
5964
  }
5800
5965
  return;
5801
5966
  }
5967
+ const startupHydration = isStartupGuildHydration(client);
5968
+ if (startupHydration) {
5969
+ resetGuildStreamSettle(client);
5970
+ }
5802
5971
  const result = applyGuildSnapshotFromGateway(client, d);
5803
5972
  if (!result) return;
5804
5973
  const { guild, recovered } = result;
5805
- if (recovered) guild.available = true;
5806
- client.emit(recovered ? Events.GuildAvailable : Events.GuildCreate, guild);
5974
+ const legacyStartup = client.options.emitGuildCreateOnStartup === true;
5975
+ const wasReadyStub = client._readyStubGuildIds.delete(guild.id);
5976
+ const isStartupBackfill = wasReadyStub || startupHydration;
5977
+ if (recovered) {
5978
+ guild.available = true;
5979
+ if (legacyStartup && isStartupBackfill) {
5980
+ client.emit(Events.GuildCreate, guild);
5981
+ } else {
5982
+ client.emit(Events.GuildAvailable, guild);
5983
+ }
5984
+ } else if (startupHydration) {
5985
+ if (legacyStartup) {
5986
+ client.emit(Events.GuildCreate, guild);
5987
+ } else {
5988
+ client.emit(Events.GuildAvailable, guild);
5989
+ }
5990
+ } else {
5991
+ client.emit(Events.GuildCreate, guild);
5992
+ }
5807
5993
  client._onGuildReceived(guild.id);
5808
5994
  },
5809
5995
  GUILD_UPDATE(client, d) {
@@ -5842,6 +6028,7 @@ var guildHandlers = {
5842
6028
  markGuildUnavailable(client, id);
5843
6029
  return;
5844
6030
  }
6031
+ client._readyStubGuildIds.delete(id);
5845
6032
  const guild = client.guilds.get(id);
5846
6033
  if (!guild) return;
5847
6034
  client.guilds.delete(id);
@@ -6357,10 +6544,15 @@ function hydrateReadyGuilds(client, guilds, waitForGuilds) {
6357
6544
  for (const g of guilds ?? []) {
6358
6545
  if (g.unavailable === true) {
6359
6546
  if (typeof g.id === "string") {
6360
- const existing = client.guilds.get(g.id);
6361
- if (existing && existing.available !== false) {
6362
- existing.available = false;
6547
+ let guild = client.guilds.get(g.id);
6548
+ if (!guild) {
6549
+ guild = new Guild(client, { id: g.id });
6550
+ guild.available = false;
6551
+ client.guilds.set(g.id, guild);
6552
+ } else if (guild.available !== false) {
6553
+ guild.available = false;
6363
6554
  }
6555
+ client._readyStubGuildIds.add(g.id);
6364
6556
  if (pending !== null) pending.add(g.id);
6365
6557
  }
6366
6558
  continue;
@@ -6388,6 +6580,13 @@ function clearGuildStreamSettle(client) {
6388
6580
  clearTimeout(client._guildStreamSettleTimeout);
6389
6581
  client._guildStreamSettleTimeout = null;
6390
6582
  }
6583
+ function resetGuildStreamSettle(client) {
6584
+ clearGuildStreamSettle(client);
6585
+ client._guildStreamSettleTimeout = setTimeout(() => {
6586
+ client._guildStreamSettleTimeout = null;
6587
+ if (client.readyAt === null) finalizeClientReady(client);
6588
+ }, GUILD_STREAM_SETTLE_MS);
6589
+ }
6391
6590
  function handleReadyPayload(client, data) {
6392
6591
  client.user = new ClientUser(client, data.user);
6393
6592
  const waitForGuilds = client.options.waitForGuilds === true;
@@ -6407,14 +6606,9 @@ function handleReadyPayload(client, data) {
6407
6606
  client._pendingGuildIds = existing;
6408
6607
  return;
6409
6608
  }
6410
- if (waitForGuilds && guilds.length === 0) {
6411
- if (client._guildStreamSettleTimeout === null) {
6412
- client._guildStreamSettleTimeout = setTimeout(() => {
6413
- client._guildStreamSettleTimeout = null;
6414
- if (client.readyAt === null) finalizeClientReady(client);
6415
- }, GUILD_STREAM_SETTLE_MS);
6416
- }
6417
- return;
6609
+ if (guilds.length === 0) {
6610
+ resetGuildStreamSettle(client);
6611
+ if (waitForGuilds) return;
6418
6612
  }
6419
6613
  finalizeClientReady(client);
6420
6614
  }
@@ -6747,7 +6941,12 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6747
6941
  _ws = null;
6748
6942
  /** When waitForGuilds, guild IDs still expected via GUILD_CREATE. */
6749
6943
  _pendingGuildIds = null;
6750
- /** @internal Timeout when READY has no guilds but waitForGuilds is set. */
6944
+ /** Guild IDs inserted as unavailable stubs from READY (startup / reconnect backfill). */
6945
+ _readyStubGuildIds = /* @__PURE__ */ new Set();
6946
+ /**
6947
+ * @internal Empty-READY guild stream window.
6948
+ * Classifies incoming GUILD_CREATE as startup hydration. Also delays Ready when waitForGuilds.
6949
+ */
6751
6950
  _guildStreamSettleTimeout = null;
6752
6951
  /** @internal Dispatches queued until Ready when waitForGuilds delays Ready. */
6753
6952
  _deferredGatewayDispatches = [];
@@ -6778,7 +6977,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6778
6977
  const restApi = options.rest?.api;
6779
6978
  if (options.instance !== void 0) {
6780
6979
  this.instance = resolveInstanceEndpoints(options.instance);
6781
- resolveRestApi(this.instance.endpoints.api, restApi);
6980
+ resolveRestApi(this.instance.endpoints.api_public, restApi);
6782
6981
  } else {
6783
6982
  this.instance = resolveInstanceEndpoints(
6784
6983
  restApi !== void 0 ? { api: restApi } : void 0
@@ -6791,27 +6990,31 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6791
6990
  }
6792
6991
  this.rest = new import_rest3.REST({
6793
6992
  ...this.options.rest,
6794
- api: this.instance.endpoints.api,
6795
- version: this.options.rest?.version ?? "1"
6993
+ api: this.instance.endpoints.api_public,
6994
+ version: this.options.rest?.version ?? "1",
6995
+ locale: this.options.locale ?? this.options.rest?.locale
6796
6996
  });
6797
6997
  }
6798
6998
  /**
6799
6999
  * Create a client from instance discovery (`GET /.well-known/fluxer`).
6800
- * Does not log in — call {@link login} with a token afterward.
7000
+ * Fetches the unversioned well-known document from the given origin (not `{api}/v1/.well-known/fluxer`).
7001
+ * Wires REST from `endpoints.api_public`. `endpoints.api` / `api_client` stay on the instance for inspection.
7002
+ * Does not log in. Call {@link login} with a token afterward.
6801
7003
  *
6802
- * @param origin - API origin used only to fetch discovery (e.g. `https://api.example.com`)
6803
- * @param options - Client options (must not conflict with discovered `endpoints.api`)
7004
+ * @param origin - Origin used only to fetch discovery (e.g. `https://fluxer.app` or `https://my.instance`)
7005
+ * @param options - Client options (must not conflict with discovered `endpoints.api_public`)
6804
7006
  * @param connectOptions - Optional abort signal for the discovery request
6805
7007
  */
6806
7008
  static async fromDiscovery(origin, options = {}, connectOptions) {
6807
- const bootstrapApi = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
7009
+ const bootstrapOrigin = typeof origin === "string" ? normalizeApiOrigin(origin) : normalizeApiOrigin(origin.api);
6808
7010
  const version = typeof origin === "string" ? options.rest?.version ?? "1" : origin.version ?? options.rest?.version ?? "1";
6809
7011
  const bootstrap = new import_rest3.REST({
6810
7012
  ...options.rest ?? {},
6811
- api: bootstrapApi,
6812
- version
7013
+ api: bootstrapOrigin,
7014
+ version,
7015
+ locale: options.locale ?? options.rest?.locale
6813
7016
  });
6814
- const raw = await bootstrap.get(import_types39.Routes.instanceDiscovery(), {
7017
+ const raw = await bootstrap.get(instanceDiscoveryUrl(bootstrapOrigin), {
6815
7018
  auth: false,
6816
7019
  ...connectOptions?.signal ? { signal: connectOptions.signal } : {}
6817
7020
  });
@@ -6819,7 +7022,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6819
7022
  const { rest, ...restOptions } = options;
6820
7023
  return new _Client({
6821
7024
  ...restOptions,
6822
- // Drop rest.api so discovered endpoints.api owns the host; keep other REST opts.
7025
+ // Drop rest.api so discovered endpoints.api_public owns the REST host; keep other REST opts.
6823
7026
  ...rest ? { rest: { ...rest, api: void 0 } } : {},
6824
7027
  instance: discovery
6825
7028
  });
@@ -6846,7 +7049,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
6846
7049
  return resolveClientEmoji(this, emoji, guildId);
6847
7050
  }
6848
7051
  /**
6849
- * Fetch instance discovery document (`/.well-known/fluxer`).
7052
+ * Fetch instance discovery document (unversioned `GET /.well-known/fluxer` on the REST host).
6850
7053
  * @returns Instance configuration (endpoints, features, metadata)
6851
7054
  */
6852
7055
  fetchInstance() {
@@ -7115,6 +7318,7 @@ var Client = class _Client extends import_node_events3.EventEmitter {
7115
7318
  this.user = null;
7116
7319
  this.readyAt = null;
7117
7320
  this._pendingGuildIds = null;
7321
+ this._readyStubGuildIds.clear();
7118
7322
  this.guilds.clear();
7119
7323
  this.channels.clear();
7120
7324
  this.users.clear();
@@ -7497,6 +7701,7 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
7497
7701
  // Annotate the CommonJS export names for ESM import in node:
7498
7702
  0 && (module.exports = {
7499
7703
  AllowedMentions,
7704
+ AnnouncementChannel,
7500
7705
  AttachmentBuilder,
7501
7706
  AttachmentMeta,
7502
7707
  AuditLogActionType,
@@ -7534,6 +7739,7 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
7534
7739
  GuildOperations,
7535
7740
  GuildRoleManager,
7536
7741
  GuildSticker,
7742
+ INSTANCE_DISCOVERY_PATH,
7537
7743
  Invite,
7538
7744
  InviteType,
7539
7745
  LinkChannel,
@@ -7582,6 +7788,7 @@ var ClientCluster = class extends import_node_events4.EventEmitter {
7582
7788
  cdnMemberBannerURL,
7583
7789
  cdnStickerURL,
7584
7790
  createLogger,
7791
+ instanceDiscoveryUrl,
7585
7792
  inviteUrl,
7586
7793
  normalizeApiOrigin,
7587
7794
  normalizeCacheLimit,