shardwire 0.2.0 → 1.0.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/README.md +127 -266
- package/dist/index.d.mts +262 -129
- package/dist/index.d.ts +262 -129
- package/dist/index.js +1615 -942
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1616 -930
- package/dist/index.mjs.map +1 -1
- package/package.json +22 -34
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Snowflake, APIEmbed, APIAllowedMentions } from 'discord-api-types/v10';
|
|
2
2
|
|
|
3
|
-
interface CommandSchema<Request = unknown, Response = unknown> {
|
|
4
|
-
request: Request;
|
|
5
|
-
response: Response;
|
|
6
|
-
}
|
|
7
|
-
type CommandMap = Record<string, unknown | CommandSchema>;
|
|
8
|
-
type EventMap = Record<string, unknown>;
|
|
9
|
-
interface SchemaValidationIssue {
|
|
10
|
-
path: string;
|
|
11
|
-
message: string;
|
|
12
|
-
}
|
|
13
|
-
interface RuntimeSchema<T = unknown> {
|
|
14
|
-
parse: (value: unknown) => T;
|
|
15
|
-
}
|
|
16
|
-
type CommandRequestOf<T> = T extends CommandSchema<infer Request, unknown> ? Request : T;
|
|
17
|
-
type CommandResponseOf<T> = T extends CommandSchema<unknown, infer Response> ? Response : unknown;
|
|
18
3
|
type Unsubscribe = () => void;
|
|
19
4
|
interface ShardwireLogger {
|
|
20
5
|
debug?: (message: string, meta?: Record<string, unknown>) => void;
|
|
@@ -22,86 +7,242 @@ interface ShardwireLogger {
|
|
|
22
7
|
warn?: (message: string, meta?: Record<string, unknown>) => void;
|
|
23
8
|
error?: (message: string, meta?: Record<string, unknown>) => void;
|
|
24
9
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
type BotIntentName = "Guilds" | "GuildMembers" | "GuildMessages" | "MessageContent";
|
|
11
|
+
interface BridgeUser {
|
|
12
|
+
id: Snowflake;
|
|
13
|
+
username: string;
|
|
14
|
+
discriminator: string;
|
|
15
|
+
globalName?: string | null;
|
|
16
|
+
avatarUrl?: string | null;
|
|
17
|
+
bot: boolean;
|
|
18
|
+
system: boolean;
|
|
31
19
|
}
|
|
32
|
-
interface
|
|
33
|
-
|
|
20
|
+
interface BridgeAttachment {
|
|
21
|
+
id: Snowflake;
|
|
22
|
+
name: string;
|
|
23
|
+
url: string;
|
|
24
|
+
contentType?: string | null;
|
|
25
|
+
size: number;
|
|
26
|
+
}
|
|
27
|
+
interface BridgeMessageReference {
|
|
28
|
+
messageId?: Snowflake;
|
|
29
|
+
channelId?: Snowflake;
|
|
30
|
+
guildId?: Snowflake;
|
|
31
|
+
}
|
|
32
|
+
interface BridgeGuildMember {
|
|
33
|
+
id: Snowflake;
|
|
34
|
+
guildId: Snowflake;
|
|
35
|
+
user?: BridgeUser;
|
|
36
|
+
displayName?: string;
|
|
37
|
+
nickname?: string | null;
|
|
38
|
+
roles: Snowflake[];
|
|
39
|
+
joinedAt?: string | null;
|
|
40
|
+
premiumSince?: string | null;
|
|
41
|
+
pending?: boolean;
|
|
42
|
+
communicationDisabledUntil?: string | null;
|
|
43
|
+
}
|
|
44
|
+
interface BridgeMessage {
|
|
45
|
+
id: Snowflake;
|
|
46
|
+
channelId: Snowflake;
|
|
47
|
+
guildId?: Snowflake;
|
|
48
|
+
author?: BridgeUser;
|
|
49
|
+
member?: BridgeGuildMember;
|
|
50
|
+
content?: string;
|
|
51
|
+
createdAt?: string;
|
|
52
|
+
editedAt?: string | null;
|
|
53
|
+
attachments: BridgeAttachment[];
|
|
54
|
+
embeds: APIEmbed[];
|
|
55
|
+
reference?: BridgeMessageReference;
|
|
56
|
+
}
|
|
57
|
+
interface BridgeDeletedMessage {
|
|
58
|
+
id: Snowflake;
|
|
59
|
+
channelId: Snowflake;
|
|
60
|
+
guildId?: Snowflake;
|
|
61
|
+
deletedAt: string;
|
|
62
|
+
}
|
|
63
|
+
type BridgeInteractionKind = "chatInput" | "contextMenu" | "button" | "stringSelect" | "userSelect" | "roleSelect" | "mentionableSelect" | "channelSelect" | "modalSubmit" | "unknown";
|
|
64
|
+
interface BridgeInteraction {
|
|
65
|
+
id: Snowflake;
|
|
66
|
+
applicationId: Snowflake;
|
|
67
|
+
kind: BridgeInteractionKind;
|
|
68
|
+
guildId?: Snowflake;
|
|
69
|
+
channelId?: Snowflake;
|
|
70
|
+
user: BridgeUser;
|
|
71
|
+
member?: BridgeGuildMember;
|
|
72
|
+
commandName?: string;
|
|
73
|
+
customId?: string;
|
|
74
|
+
options?: Record<string, unknown>;
|
|
75
|
+
values?: string[];
|
|
76
|
+
fields?: Record<string, string>;
|
|
77
|
+
message?: BridgeMessage;
|
|
78
|
+
}
|
|
79
|
+
interface EventEnvelopeBase {
|
|
34
80
|
receivedAt: number;
|
|
35
|
-
|
|
36
|
-
source?: string;
|
|
81
|
+
shardId?: number;
|
|
37
82
|
}
|
|
38
|
-
interface
|
|
39
|
-
|
|
40
|
-
source?: string;
|
|
83
|
+
interface ReadyEventPayload extends EventEnvelopeBase {
|
|
84
|
+
user: BridgeUser;
|
|
41
85
|
}
|
|
42
|
-
interface
|
|
43
|
-
|
|
44
|
-
requestId: string;
|
|
45
|
-
ts: number;
|
|
46
|
-
data: T;
|
|
86
|
+
interface InteractionCreateEventPayload extends EventEnvelopeBase {
|
|
87
|
+
interaction: BridgeInteraction;
|
|
47
88
|
}
|
|
48
|
-
interface
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
89
|
+
interface MessageCreateEventPayload extends EventEnvelopeBase {
|
|
90
|
+
message: BridgeMessage;
|
|
91
|
+
}
|
|
92
|
+
interface MessageUpdateEventPayload extends EventEnvelopeBase {
|
|
93
|
+
oldMessage?: BridgeMessage;
|
|
94
|
+
message: BridgeMessage;
|
|
95
|
+
}
|
|
96
|
+
interface MessageDeleteEventPayload extends EventEnvelopeBase {
|
|
97
|
+
message: BridgeDeletedMessage;
|
|
98
|
+
}
|
|
99
|
+
interface GuildMemberAddEventPayload extends EventEnvelopeBase {
|
|
100
|
+
member: BridgeGuildMember;
|
|
101
|
+
}
|
|
102
|
+
interface GuildMemberRemoveEventPayload extends EventEnvelopeBase {
|
|
103
|
+
member: BridgeGuildMember;
|
|
104
|
+
}
|
|
105
|
+
interface BotEventPayloadMap {
|
|
106
|
+
ready: ReadyEventPayload;
|
|
107
|
+
interactionCreate: InteractionCreateEventPayload;
|
|
108
|
+
messageCreate: MessageCreateEventPayload;
|
|
109
|
+
messageUpdate: MessageUpdateEventPayload;
|
|
110
|
+
messageDelete: MessageDeleteEventPayload;
|
|
111
|
+
guildMemberAdd: GuildMemberAddEventPayload;
|
|
112
|
+
guildMemberRemove: GuildMemberRemoveEventPayload;
|
|
113
|
+
}
|
|
114
|
+
type BotEventName = keyof BotEventPayloadMap;
|
|
115
|
+
interface BridgeMessageInput {
|
|
116
|
+
content?: string;
|
|
117
|
+
embeds?: APIEmbed[];
|
|
118
|
+
allowedMentions?: APIAllowedMentions;
|
|
119
|
+
}
|
|
120
|
+
interface SendMessageActionPayload extends BridgeMessageInput {
|
|
121
|
+
channelId: Snowflake;
|
|
122
|
+
}
|
|
123
|
+
interface EditMessageActionPayload extends BridgeMessageInput {
|
|
124
|
+
channelId: Snowflake;
|
|
125
|
+
messageId: Snowflake;
|
|
126
|
+
}
|
|
127
|
+
interface DeleteMessageActionPayload {
|
|
128
|
+
channelId: Snowflake;
|
|
129
|
+
messageId: Snowflake;
|
|
130
|
+
}
|
|
131
|
+
interface ReplyToInteractionActionPayload extends BridgeMessageInput {
|
|
132
|
+
interactionId: Snowflake;
|
|
133
|
+
ephemeral?: boolean;
|
|
134
|
+
}
|
|
135
|
+
interface DeferInteractionActionPayload {
|
|
136
|
+
interactionId: Snowflake;
|
|
137
|
+
ephemeral?: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface FollowUpInteractionActionPayload extends BridgeMessageInput {
|
|
140
|
+
interactionId: Snowflake;
|
|
141
|
+
ephemeral?: boolean;
|
|
142
|
+
}
|
|
143
|
+
interface BanMemberActionPayload {
|
|
144
|
+
guildId: Snowflake;
|
|
145
|
+
userId: Snowflake;
|
|
146
|
+
reason?: string;
|
|
147
|
+
deleteMessageSeconds?: number;
|
|
148
|
+
}
|
|
149
|
+
interface KickMemberActionPayload {
|
|
150
|
+
guildId: Snowflake;
|
|
151
|
+
userId: Snowflake;
|
|
152
|
+
reason?: string;
|
|
153
|
+
}
|
|
154
|
+
interface AddMemberRoleActionPayload {
|
|
155
|
+
guildId: Snowflake;
|
|
156
|
+
userId: Snowflake;
|
|
157
|
+
roleId: Snowflake;
|
|
158
|
+
reason?: string;
|
|
159
|
+
}
|
|
160
|
+
interface RemoveMemberRoleActionPayload {
|
|
161
|
+
guildId: Snowflake;
|
|
162
|
+
userId: Snowflake;
|
|
163
|
+
roleId: Snowflake;
|
|
164
|
+
reason?: string;
|
|
57
165
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
166
|
+
interface BotActionPayloadMap {
|
|
167
|
+
sendMessage: SendMessageActionPayload;
|
|
168
|
+
editMessage: EditMessageActionPayload;
|
|
169
|
+
deleteMessage: DeleteMessageActionPayload;
|
|
170
|
+
replyToInteraction: ReplyToInteractionActionPayload;
|
|
171
|
+
deferInteraction: DeferInteractionActionPayload;
|
|
172
|
+
followUpInteraction: FollowUpInteractionActionPayload;
|
|
173
|
+
banMember: BanMemberActionPayload;
|
|
174
|
+
kickMember: KickMemberActionPayload;
|
|
175
|
+
addMemberRole: AddMemberRoleActionPayload;
|
|
176
|
+
removeMemberRole: RemoveMemberRoleActionPayload;
|
|
177
|
+
}
|
|
178
|
+
interface DeleteMessageActionResult {
|
|
179
|
+
deleted: true;
|
|
180
|
+
channelId: Snowflake;
|
|
181
|
+
messageId: Snowflake;
|
|
182
|
+
}
|
|
183
|
+
interface DeferInteractionActionResult {
|
|
184
|
+
deferred: true;
|
|
185
|
+
interactionId: Snowflake;
|
|
186
|
+
}
|
|
187
|
+
interface MemberModerationActionResult {
|
|
188
|
+
guildId: Snowflake;
|
|
189
|
+
userId: Snowflake;
|
|
190
|
+
}
|
|
191
|
+
interface BotActionResultDataMap {
|
|
192
|
+
sendMessage: BridgeMessage;
|
|
193
|
+
editMessage: BridgeMessage;
|
|
194
|
+
deleteMessage: DeleteMessageActionResult;
|
|
195
|
+
replyToInteraction: BridgeMessage;
|
|
196
|
+
deferInteraction: DeferInteractionActionResult;
|
|
197
|
+
followUpInteraction: BridgeMessage;
|
|
198
|
+
banMember: MemberModerationActionResult;
|
|
199
|
+
kickMember: MemberModerationActionResult;
|
|
200
|
+
addMemberRole: BridgeGuildMember;
|
|
201
|
+
removeMemberRole: BridgeGuildMember;
|
|
202
|
+
}
|
|
203
|
+
type BotActionName = keyof BotActionPayloadMap;
|
|
204
|
+
interface BridgeCapabilities {
|
|
205
|
+
events: BotEventName[];
|
|
206
|
+
actions: BotActionName[];
|
|
207
|
+
}
|
|
208
|
+
interface EventSubscriptionFilter {
|
|
209
|
+
guildId?: Snowflake | readonly Snowflake[];
|
|
210
|
+
channelId?: Snowflake | readonly Snowflake[];
|
|
211
|
+
userId?: Snowflake | readonly Snowflake[];
|
|
212
|
+
commandName?: string | readonly string[];
|
|
213
|
+
}
|
|
214
|
+
interface EventSubscription<K extends BotEventName = BotEventName> {
|
|
215
|
+
name: K;
|
|
216
|
+
filter?: EventSubscriptionFilter;
|
|
217
|
+
}
|
|
218
|
+
interface SecretPermissions {
|
|
219
|
+
events?: "*" | readonly BotEventName[];
|
|
220
|
+
actions?: "*" | readonly BotActionName[];
|
|
221
|
+
}
|
|
222
|
+
interface ScopedSecretConfig {
|
|
223
|
+
id?: string;
|
|
224
|
+
value: string;
|
|
225
|
+
allow?: SecretPermissions;
|
|
226
|
+
}
|
|
227
|
+
type BotBridgeSecret = string | ScopedSecretConfig;
|
|
228
|
+
interface BotBridgeOptions {
|
|
229
|
+
token: string;
|
|
230
|
+
intents: readonly BotIntentName[];
|
|
62
231
|
server: {
|
|
63
232
|
port: number;
|
|
64
233
|
host?: string;
|
|
65
|
-
secrets: string[];
|
|
66
|
-
primarySecretId?: string;
|
|
67
234
|
path?: string;
|
|
68
235
|
heartbeatMs?: number;
|
|
69
|
-
commandTimeoutMs?: number;
|
|
70
236
|
maxPayloadBytes?: number;
|
|
71
|
-
|
|
72
|
-
};
|
|
73
|
-
validation?: {
|
|
74
|
-
commands?: Partial<{
|
|
75
|
-
[K in keyof C & string]: {
|
|
76
|
-
request?: RuntimeSchema<CommandRequestOf<C[K]>>;
|
|
77
|
-
response?: RuntimeSchema<CommandResponseOf<C[K]>>;
|
|
78
|
-
};
|
|
79
|
-
}>;
|
|
80
|
-
events?: Partial<{
|
|
81
|
-
[K in keyof E & string]: RuntimeSchema<E[K]>;
|
|
82
|
-
}>;
|
|
237
|
+
secrets: readonly BotBridgeSecret[];
|
|
83
238
|
};
|
|
84
|
-
name?: string;
|
|
85
239
|
logger?: ShardwireLogger;
|
|
86
240
|
}
|
|
87
|
-
interface
|
|
241
|
+
interface AppBridgeOptions {
|
|
88
242
|
url: string;
|
|
89
243
|
secret: string;
|
|
90
244
|
secretId?: string;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Allows plain `ws://` connections to non-loopback hosts.
|
|
94
|
-
*
|
|
95
|
-
* Keep this `false` unless you explicitly terminate TLS upstream and trust the network path.
|
|
96
|
-
*/
|
|
97
|
-
allowInsecureWs?: boolean;
|
|
98
|
-
webSocketFactory?: (url: string) => {
|
|
99
|
-
readyState: number;
|
|
100
|
-
send(data: string): void;
|
|
101
|
-
close(code?: number, reason?: string): void;
|
|
102
|
-
on(event: "open" | "message" | "close" | "error", listener: (...args: unknown[]) => void): void;
|
|
103
|
-
once(event: "close", listener: () => void): void;
|
|
104
|
-
};
|
|
245
|
+
appName?: string;
|
|
105
246
|
reconnect?: {
|
|
106
247
|
enabled?: boolean;
|
|
107
248
|
initialDelayMs?: number;
|
|
@@ -111,65 +252,57 @@ interface ConsumerOptions {
|
|
|
111
252
|
requestTimeoutMs?: number;
|
|
112
253
|
logger?: ShardwireLogger;
|
|
113
254
|
}
|
|
114
|
-
interface
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
broadcast<K extends keyof E & string>(name: K, payload: E[K]): void;
|
|
119
|
-
close(): Promise<void>;
|
|
255
|
+
interface ActionError {
|
|
256
|
+
code: "UNAUTHORIZED" | "TIMEOUT" | "DISCONNECTED" | "FORBIDDEN" | "NOT_FOUND" | "INVALID_REQUEST" | "INTERNAL_ERROR";
|
|
257
|
+
message: string;
|
|
258
|
+
details?: unknown;
|
|
120
259
|
}
|
|
121
|
-
interface
|
|
122
|
-
|
|
123
|
-
|
|
260
|
+
interface ActionSuccess<T> {
|
|
261
|
+
ok: true;
|
|
262
|
+
requestId: string;
|
|
263
|
+
ts: number;
|
|
264
|
+
data: T;
|
|
265
|
+
}
|
|
266
|
+
interface ActionFailure {
|
|
267
|
+
ok: false;
|
|
268
|
+
requestId: string;
|
|
269
|
+
ts: number;
|
|
270
|
+
error: ActionError;
|
|
271
|
+
}
|
|
272
|
+
type ActionResult<T> = ActionSuccess<T> | ActionFailure;
|
|
273
|
+
declare class BridgeCapabilityError extends Error {
|
|
274
|
+
readonly kind: "event" | "action";
|
|
275
|
+
readonly name: string;
|
|
276
|
+
constructor(kind: "event" | "action", name: string, message?: string);
|
|
277
|
+
}
|
|
278
|
+
type EventHandler<K extends BotEventName> = (payload: BotEventPayloadMap[K]) => void;
|
|
279
|
+
type AppBridgeActions = {
|
|
280
|
+
[K in BotActionName]: (payload: BotActionPayloadMap[K], options?: {
|
|
124
281
|
timeoutMs?: number;
|
|
125
282
|
requestId?: string;
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
onConnected(handler: (info: {
|
|
130
|
-
connectionId: string;
|
|
131
|
-
connectedAt: number;
|
|
132
|
-
}) => void): Unsubscribe;
|
|
133
|
-
onDisconnected(handler: (info: {
|
|
134
|
-
reason: string;
|
|
135
|
-
at: number;
|
|
136
|
-
willReconnect: boolean;
|
|
137
|
-
}) => void): Unsubscribe;
|
|
138
|
-
onReconnecting(handler: (info: {
|
|
139
|
-
attempt: number;
|
|
140
|
-
delayMs: number;
|
|
141
|
-
at: number;
|
|
142
|
-
}) => void): Unsubscribe;
|
|
283
|
+
}) => Promise<ActionResult<BotActionResultDataMap[K]>>;
|
|
284
|
+
};
|
|
285
|
+
interface BotBridge {
|
|
143
286
|
ready(): Promise<void>;
|
|
144
|
-
connected(): boolean;
|
|
145
|
-
connectionId(): string | null;
|
|
146
287
|
close(): Promise<void>;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
<C extends CommandMap = {}, E extends EventMap = {}>(options: ConsumerOptions): ConsumerShardwire<C, E>;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
interface SafeParseResultSuccess<T> {
|
|
154
|
-
success: true;
|
|
155
|
-
data: T;
|
|
156
|
-
}
|
|
157
|
-
interface SafeParseResultFailure {
|
|
158
|
-
success: false;
|
|
159
|
-
error: {
|
|
160
|
-
message: string;
|
|
161
|
-
issues?: SchemaValidationIssue[];
|
|
288
|
+
status(): {
|
|
289
|
+
ready: boolean;
|
|
290
|
+
connectionCount: number;
|
|
162
291
|
};
|
|
163
292
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
293
|
+
interface AppBridge {
|
|
294
|
+
actions: AppBridgeActions;
|
|
295
|
+
ready(): Promise<void>;
|
|
296
|
+
close(): Promise<void>;
|
|
297
|
+
connected(): boolean;
|
|
298
|
+
connectionId(): string | null;
|
|
299
|
+
capabilities(): BridgeCapabilities;
|
|
300
|
+
on<K extends BotEventName>(name: K, handler: EventHandler<K>, filter?: EventSubscriptionFilter): Unsubscribe;
|
|
301
|
+
off<K extends BotEventName>(name: K, handler: EventHandler<K>): void;
|
|
167
302
|
}
|
|
168
|
-
declare function fromSafeParseSchema<T>(schema: SafeParseSchema<T>): RuntimeSchema<T>;
|
|
169
303
|
|
|
170
|
-
declare function
|
|
304
|
+
declare function createBotBridge(options: BotBridgeOptions): BotBridge;
|
|
171
305
|
|
|
172
|
-
declare function
|
|
173
|
-
declare function createShardwire<C extends CommandMap = {}, E extends EventMap = {}>(options: ConsumerOptions): ConsumerShardwire<C, E>;
|
|
306
|
+
declare function connectBotBridge(options: AppBridgeOptions): AppBridge;
|
|
174
307
|
|
|
175
|
-
export { type
|
|
308
|
+
export { type ActionError, type ActionFailure, type ActionResult, type ActionSuccess, type AddMemberRoleActionPayload, type AppBridge, type AppBridgeActions, 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 BridgeGuildMember, type BridgeInteraction, type BridgeInteractionKind, type BridgeMessage, type BridgeMessageInput, type BridgeMessageReference, type BridgeUser, type DeferInteractionActionPayload, type DeleteMessageActionPayload, type EditMessageActionPayload, type EventEnvelopeBase, type EventHandler, type EventSubscription, type EventSubscriptionFilter, type FollowUpInteractionActionPayload, type GuildMemberAddEventPayload, type GuildMemberRemoveEventPayload, type InteractionCreateEventPayload, type KickMemberActionPayload, type MessageCreateEventPayload, type MessageDeleteEventPayload, type MessageUpdateEventPayload, type ReadyEventPayload, type RemoveMemberRoleActionPayload, type ReplyToInteractionActionPayload, type ScopedSecretConfig, type SecretPermissions, type SendMessageActionPayload, type ShardwireLogger, type Unsubscribe, connectBotBridge, createBotBridge };
|