shardwire 1.2.0 → 1.4.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.d.ts CHANGED
@@ -59,6 +59,14 @@ interface BridgeThread {
59
59
  archived?: boolean;
60
60
  locked?: boolean;
61
61
  }
62
+ /** Normalized non-thread channel snapshot for channel lifecycle events. */
63
+ interface BridgeChannel {
64
+ id: Snowflake;
65
+ type: number;
66
+ name?: string | null;
67
+ guildId?: Snowflake;
68
+ parentId?: Snowflake | null;
69
+ }
62
70
  interface BridgeMessage {
63
71
  id: Snowflake;
64
72
  channelId: Snowflake;
@@ -73,12 +81,18 @@ interface BridgeMessage {
73
81
  /** Message component rows (JSON-serializable API shape). */
74
82
  components?: APIActionRowComponent<APIComponentInMessageActionRow>[];
75
83
  reference?: BridgeMessageReference;
84
+ /** Discord `ChannelType` when the runtime could resolve `message.channel`. */
85
+ channelType?: number;
86
+ /** Parent category (guild text channels) or parent text/forum (threads), when known. */
87
+ parentChannelId?: Snowflake;
76
88
  }
77
89
  interface BridgeDeletedMessage {
78
90
  id: Snowflake;
79
91
  channelId: Snowflake;
80
92
  guildId?: Snowflake;
81
93
  deletedAt: string;
94
+ channelType?: number;
95
+ parentChannelId?: Snowflake;
82
96
  }
83
97
  interface BridgeReactionEmoji {
84
98
  id?: Snowflake;
@@ -92,13 +106,17 @@ interface BridgeMessageReaction {
92
106
  user?: BridgeUser;
93
107
  emoji: BridgeReactionEmoji;
94
108
  }
95
- type BridgeInteractionKind = "chatInput" | "contextMenu" | "button" | "stringSelect" | "userSelect" | "roleSelect" | "mentionableSelect" | "channelSelect" | "modalSubmit" | "unknown";
109
+ type BridgeInteractionKind = 'chatInput' | 'contextMenu' | 'button' | 'stringSelect' | 'userSelect' | 'roleSelect' | 'mentionableSelect' | 'channelSelect' | 'modalSubmit' | 'unknown';
96
110
  interface BridgeInteraction {
97
111
  id: Snowflake;
98
112
  applicationId: Snowflake;
99
113
  kind: BridgeInteractionKind;
100
114
  guildId?: Snowflake;
101
115
  channelId?: Snowflake;
116
+ /** Discord `ChannelType` for `channelId` when the runtime resolved the channel. */
117
+ channelType?: number;
118
+ /** Parent category or parent text/forum for thread channels, when known. */
119
+ parentChannelId?: Snowflake;
102
120
  user: BridgeUser;
103
121
  member?: BridgeGuildMember;
104
122
  commandName?: string;
@@ -161,12 +179,32 @@ interface MessageReactionAddEventPayload extends EventEnvelopeBase {
161
179
  interface MessageReactionRemoveEventPayload extends EventEnvelopeBase {
162
180
  reaction: BridgeMessageReaction;
163
181
  }
182
+ interface ChannelCreateEventPayload extends EventEnvelopeBase {
183
+ channel: BridgeChannel;
184
+ }
185
+ interface ChannelUpdateEventPayload extends EventEnvelopeBase {
186
+ oldChannel?: BridgeChannel;
187
+ channel: BridgeChannel;
188
+ }
189
+ interface ChannelDeleteEventPayload extends EventEnvelopeBase {
190
+ channel: BridgeChannel;
191
+ }
192
+ interface MessageBulkDeleteEventPayload extends EventEnvelopeBase {
193
+ channelId: Snowflake;
194
+ guildId: Snowflake;
195
+ messageIds: Snowflake[];
196
+ /** Discord `ChannelType` for `channelId` when known. */
197
+ channelType?: number;
198
+ /** Parent category or forum/text parent when the channel reports one. */
199
+ parentChannelId?: Snowflake;
200
+ }
164
201
  interface BotEventPayloadMap {
165
202
  ready: ReadyEventPayload;
166
203
  interactionCreate: InteractionCreateEventPayload;
167
204
  messageCreate: MessageCreateEventPayload;
168
205
  messageUpdate: MessageUpdateEventPayload;
169
206
  messageDelete: MessageDeleteEventPayload;
207
+ messageBulkDelete: MessageBulkDeleteEventPayload;
170
208
  messageReactionAdd: MessageReactionAddEventPayload;
171
209
  messageReactionRemove: MessageReactionRemoveEventPayload;
172
210
  guildCreate: GuildCreateEventPayload;
@@ -177,6 +215,9 @@ interface BotEventPayloadMap {
177
215
  threadCreate: ThreadCreateEventPayload;
178
216
  threadUpdate: ThreadUpdateEventPayload;
179
217
  threadDelete: ThreadDeleteEventPayload;
218
+ channelCreate: ChannelCreateEventPayload;
219
+ channelUpdate: ChannelUpdateEventPayload;
220
+ channelDelete: ChannelDeleteEventPayload;
180
221
  }
181
222
  type BotEventName = keyof BotEventPayloadMap;
182
223
  interface BridgeMessageInput {
@@ -270,6 +311,53 @@ interface RemoveOwnMessageReactionActionPayload {
270
311
  messageId: Snowflake;
271
312
  emoji: string;
272
313
  }
314
+ interface TimeoutMemberActionPayload {
315
+ guildId: Snowflake;
316
+ userId: Snowflake;
317
+ /** Duration in milliseconds (Discord allows up to 28 days). */
318
+ durationMs: number;
319
+ reason?: string;
320
+ }
321
+ interface RemoveMemberTimeoutActionPayload {
322
+ guildId: Snowflake;
323
+ userId: Snowflake;
324
+ reason?: string;
325
+ }
326
+ interface CreateChannelActionPayload {
327
+ guildId: Snowflake;
328
+ name: string;
329
+ /** Discord `ChannelType` (default: `0` guild text). */
330
+ type?: number;
331
+ parentId?: Snowflake;
332
+ topic?: string;
333
+ reason?: string;
334
+ }
335
+ interface EditChannelActionPayload {
336
+ channelId: Snowflake;
337
+ name?: string | null;
338
+ parentId?: Snowflake | null;
339
+ topic?: string | null;
340
+ reason?: string;
341
+ }
342
+ interface DeleteChannelActionPayload {
343
+ channelId: Snowflake;
344
+ reason?: string;
345
+ }
346
+ /** `autoArchiveDuration` is in minutes (Discord-supported values). */
347
+ interface CreateThreadActionPayload {
348
+ parentChannelId: Snowflake;
349
+ name: string;
350
+ /** When set, starts a thread on this message (requires a text-based parent). */
351
+ messageId?: Snowflake;
352
+ type?: 'public' | 'private';
353
+ autoArchiveDuration?: 60 | 1440 | 4320 | 10080;
354
+ reason?: string;
355
+ }
356
+ interface ArchiveThreadActionPayload {
357
+ threadId: Snowflake;
358
+ archived?: boolean;
359
+ reason?: string;
360
+ }
273
361
  interface BotActionPayloadMap {
274
362
  sendMessage: SendMessageActionPayload;
275
363
  editMessage: EditMessageActionPayload;
@@ -290,6 +378,13 @@ interface BotActionPayloadMap {
290
378
  removeMemberRole: RemoveMemberRoleActionPayload;
291
379
  addMessageReaction: AddMessageReactionActionPayload;
292
380
  removeOwnMessageReaction: RemoveOwnMessageReactionActionPayload;
381
+ timeoutMember: TimeoutMemberActionPayload;
382
+ removeMemberTimeout: RemoveMemberTimeoutActionPayload;
383
+ createChannel: CreateChannelActionPayload;
384
+ editChannel: EditChannelActionPayload;
385
+ deleteChannel: DeleteChannelActionPayload;
386
+ createThread: CreateThreadActionPayload;
387
+ archiveThread: ArchiveThreadActionPayload;
293
388
  }
294
389
  interface DeleteMessageActionResult {
295
390
  deleted: true;
@@ -321,6 +416,10 @@ interface MessageReactionActionResult {
321
416
  channelId: Snowflake;
322
417
  emoji: string;
323
418
  }
419
+ interface DeleteChannelActionResult {
420
+ deleted: true;
421
+ channelId: Snowflake;
422
+ }
324
423
  interface BotActionResultDataMap {
325
424
  sendMessage: BridgeMessage;
326
425
  editMessage: BridgeMessage;
@@ -341,6 +440,13 @@ interface BotActionResultDataMap {
341
440
  removeMemberRole: BridgeGuildMember;
342
441
  addMessageReaction: MessageReactionActionResult;
343
442
  removeOwnMessageReaction: MessageReactionActionResult;
443
+ timeoutMember: MemberModerationActionResult;
444
+ removeMemberTimeout: BridgeGuildMember;
445
+ createChannel: BridgeChannel;
446
+ editChannel: BridgeChannel;
447
+ deleteChannel: DeleteChannelActionResult;
448
+ createThread: BridgeThread;
449
+ archiveThread: BridgeThread;
344
450
  }
345
451
  type BotActionName = keyof BotActionPayloadMap;
346
452
  interface BridgeCapabilities {
@@ -356,14 +462,20 @@ interface EventSubscriptionFilter {
356
462
  customId?: string | readonly string[];
357
463
  /** Matches `BridgeInteraction.kind`. */
358
464
  interactionKind?: BridgeInteractionKind | readonly BridgeInteractionKind[];
465
+ /** Matches Discord `ChannelType` when present on the payload (messages, interactions, bulk delete). */
466
+ channelType?: number | readonly number[];
467
+ /** Matches `BridgeMessage.parentChannelId` / thread parent / channel parent when present. */
468
+ parentChannelId?: Snowflake | readonly Snowflake[];
469
+ /** Matches guild thread channels only: same as message `channelId` when `channelType` is a guild thread. */
470
+ threadId?: Snowflake | readonly Snowflake[];
359
471
  }
360
472
  interface EventSubscription<K extends BotEventName = BotEventName> {
361
473
  name: K;
362
474
  filter?: EventSubscriptionFilter;
363
475
  }
364
476
  interface SecretPermissions {
365
- events?: "*" | readonly BotEventName[];
366
- actions?: "*" | readonly BotActionName[];
477
+ events?: '*' | readonly BotEventName[];
478
+ actions?: '*' | readonly BotActionName[];
367
479
  }
368
480
  interface ScopedSecretConfig {
369
481
  id?: string;
@@ -377,6 +489,8 @@ interface ActionErrorDetails {
377
489
  discordCode?: number;
378
490
  /** When true, callers may retry with backoff (e.g. rate limits). */
379
491
  retryable?: boolean;
492
+ /** Suggested wait derived from Discord `retry_after` (milliseconds), when available. */
493
+ retryAfterMs?: number;
380
494
  [key: string]: unknown;
381
495
  }
382
496
  interface BotBridgeOptions {
@@ -395,6 +509,14 @@ interface BotBridgeOptions {
395
509
  maxConcurrentActions?: number;
396
510
  /** When the queue is full, fail fast with `SERVICE_UNAVAILABLE` (default: 5000). */
397
511
  actionQueueTimeoutMs?: number;
512
+ /**
513
+ * Where `idempotencyKey` deduplication is scoped (default: `connection`).
514
+ * - `connection`: same WebSocket connection only (reconnect uses a new scope).
515
+ * - `secret`: same configured secret id across connections (useful for retries after reconnect).
516
+ */
517
+ idempotencyScope?: 'connection' | 'secret';
518
+ /** TTL for idempotency cache entries in ms (default: 120000). */
519
+ idempotencyTtlMs?: number;
398
520
  };
399
521
  logger?: ShardwireLogger;
400
522
  }
@@ -405,6 +527,10 @@ interface AppBridgeMetricsHooks {
405
527
  durationMs: number;
406
528
  ok: boolean;
407
529
  errorCode?: string;
530
+ /** Present when Discord returned HTTP 429 or similar retryable signals. */
531
+ retryAfterMs?: number;
532
+ discordStatus?: number;
533
+ discordCode?: number;
408
534
  }) => void;
409
535
  }
410
536
  interface AppBridgeOptions {
@@ -423,7 +549,7 @@ interface AppBridgeOptions {
423
549
  metrics?: AppBridgeMetricsHooks;
424
550
  }
425
551
  interface ActionError {
426
- code: "UNAUTHORIZED" | "TIMEOUT" | "DISCONNECTED" | "FORBIDDEN" | "NOT_FOUND" | "INVALID_REQUEST" | "INTERNAL_ERROR" | "SERVICE_UNAVAILABLE";
552
+ code: 'UNAUTHORIZED' | 'TIMEOUT' | 'DISCONNECTED' | 'FORBIDDEN' | 'NOT_FOUND' | 'INVALID_REQUEST' | 'INTERNAL_ERROR' | 'SERVICE_UNAVAILABLE';
427
553
  message: string;
428
554
  details?: ActionErrorDetails | unknown;
429
555
  }
@@ -441,9 +567,9 @@ interface ActionFailure {
441
567
  }
442
568
  type ActionResult<T> = ActionSuccess<T> | ActionFailure;
443
569
  declare class BridgeCapabilityError extends Error {
444
- readonly kind: "event" | "action";
570
+ readonly kind: 'event' | 'action';
445
571
  readonly name: string;
446
- constructor(kind: "event" | "action", name: string, message?: string);
572
+ constructor(kind: 'event' | 'action', name: string, message?: string);
447
573
  }
448
574
  type EventHandler<K extends BotEventName> = (payload: BotEventPayloadMap[K]) => void;
449
575
  type AppBridgeActionInvokeOptions = {
@@ -478,4 +604,4 @@ declare function createBotBridge(options: BotBridgeOptions): BotBridge;
478
604
 
479
605
  declare function connectBotBridge(options: AppBridgeOptions): AppBridge;
480
606
 
481
- export { type ActionError, type ActionErrorDetails, type ActionFailure, type ActionResult, type ActionSuccess, type AddMemberRoleActionPayload, type AddMessageReactionActionPayload, type AppBridge, type AppBridgeActionInvokeOptions, type AppBridgeActions, type AppBridgeMetricsHooks, type AppBridgeOptions, type BanMemberActionPayload, type BotActionName, type BotActionPayloadMap, type BotActionResultDataMap, type BotBridge, type BotBridgeOptions, type BotBridgeSecret, type BotEventName, type BotEventPayloadMap, type BotIntentName, type BridgeAttachment, type BridgeCapabilities, BridgeCapabilityError, type BridgeDeletedMessage, type BridgeGuild, type BridgeGuildMember, type BridgeInteraction, type BridgeInteractionKind, type BridgeMessage, type BridgeMessageInput, type BridgeMessageReaction, type BridgeMessageReference, type BridgeReactionEmoji, type BridgeThread, type BridgeUser, type DeferInteractionActionPayload, type DeferInteractionActionResult, type DeferUpdateInteractionActionPayload, type DeferUpdateInteractionActionResult, type DeleteInteractionReplyActionPayload, type DeleteInteractionReplyActionResult, type DeleteMessageActionPayload, type DeleteMessageActionResult, type EditInteractionReplyActionPayload, type EditMessageActionPayload, type EventEnvelopeBase, type EventHandler, type EventSubscription, type EventSubscriptionFilter, type FetchMemberActionPayload, type FetchMessageActionPayload, type FollowUpInteractionActionPayload, type GuildCreateEventPayload, type GuildDeleteEventPayload, type GuildMemberAddEventPayload, type GuildMemberRemoveEventPayload, type GuildMemberUpdateEventPayload, type InteractionCreateEventPayload, type KickMemberActionPayload, type MemberModerationActionResult, type MessageCreateEventPayload, type MessageDeleteEventPayload, type MessageReactionActionResult, type MessageReactionAddEventPayload, type MessageReactionRemoveEventPayload, type MessageUpdateEventPayload, type ReadyEventPayload, type RemoveMemberRoleActionPayload, type RemoveOwnMessageReactionActionPayload, type ReplyToInteractionActionPayload, type ScopedSecretConfig, type SecretPermissions, type SendMessageActionPayload, type ShardwireLogger, type ShowModalActionPayload, type ShowModalActionResult, type ThreadCreateEventPayload, type ThreadDeleteEventPayload, type ThreadUpdateEventPayload, type Unsubscribe, type UpdateInteractionActionPayload, connectBotBridge, createBotBridge };
607
+ export { type ActionError, type ActionErrorDetails, type ActionFailure, type ActionResult, type ActionSuccess, type AddMemberRoleActionPayload, type AddMessageReactionActionPayload, type AppBridge, type AppBridgeActionInvokeOptions, type AppBridgeActions, type AppBridgeMetricsHooks, type AppBridgeOptions, type ArchiveThreadActionPayload, type BanMemberActionPayload, type BotActionName, type BotActionPayloadMap, type BotActionResultDataMap, type BotBridge, type BotBridgeOptions, type BotBridgeSecret, type BotEventName, type BotEventPayloadMap, type BotIntentName, type BridgeAttachment, type BridgeCapabilities, BridgeCapabilityError, type BridgeChannel, type BridgeDeletedMessage, type BridgeGuild, type BridgeGuildMember, type BridgeInteraction, type BridgeInteractionKind, type BridgeMessage, type BridgeMessageInput, type BridgeMessageReaction, type BridgeMessageReference, type BridgeReactionEmoji, type BridgeThread, type BridgeUser, type ChannelCreateEventPayload, type ChannelDeleteEventPayload, type ChannelUpdateEventPayload, type CreateChannelActionPayload, type CreateThreadActionPayload, type DeferInteractionActionPayload, type DeferInteractionActionResult, type DeferUpdateInteractionActionPayload, type DeferUpdateInteractionActionResult, type DeleteChannelActionPayload, type DeleteChannelActionResult, type DeleteInteractionReplyActionPayload, type DeleteInteractionReplyActionResult, type DeleteMessageActionPayload, type DeleteMessageActionResult, type EditChannelActionPayload, type EditInteractionReplyActionPayload, type EditMessageActionPayload, type EventEnvelopeBase, type EventHandler, type EventSubscription, type EventSubscriptionFilter, type FetchMemberActionPayload, type FetchMessageActionPayload, type FollowUpInteractionActionPayload, type GuildCreateEventPayload, type GuildDeleteEventPayload, type GuildMemberAddEventPayload, type GuildMemberRemoveEventPayload, type GuildMemberUpdateEventPayload, type InteractionCreateEventPayload, type KickMemberActionPayload, type MemberModerationActionResult, type MessageBulkDeleteEventPayload, type MessageCreateEventPayload, type MessageDeleteEventPayload, type MessageReactionActionResult, type MessageReactionAddEventPayload, type MessageReactionRemoveEventPayload, type MessageUpdateEventPayload, type ReadyEventPayload, type RemoveMemberRoleActionPayload, type RemoveMemberTimeoutActionPayload, type RemoveOwnMessageReactionActionPayload, type ReplyToInteractionActionPayload, type ScopedSecretConfig, type SecretPermissions, type SendMessageActionPayload, type ShardwireLogger, type ShowModalActionPayload, type ShowModalActionResult, type ThreadCreateEventPayload, type ThreadDeleteEventPayload, type ThreadUpdateEventPayload, type TimeoutMemberActionPayload, type Unsubscribe, type UpdateInteractionActionPayload, connectBotBridge, createBotBridge };