@abyss-project/runtime 3.3.1 → 3.5.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 +1 -1
- package/dist/discord/discord.types.d.ts +243 -3
- package/dist/discord/discord.types.js +75 -1
- package/dist/discord/discord.types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/surface.test.ts +13 -0
- package/src/discord/__tests__/discord-event-input.test.ts +89 -0
- package/src/discord/discord.types.ts +365 -5
- package/src/schedule/schedule.types.ts +100 -100
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ each host `call` are the types `Discord*Args` (a `DiscordMessage` itself for `re
|
|
|
45
45
|
`followUp`). A host failing a call with the message `<DiscordErrorCode>: <detail>` (or the bare
|
|
46
46
|
code) makes the helper throw an `Error` named `DiscordError` with `code` and `message` set; any
|
|
47
47
|
other failure is thrown unchanged. `DiscordInteractionInput` types the `input` of a function
|
|
48
|
-
triggered by a Discord interaction.
|
|
48
|
+
triggered by a Discord interaction; `DiscordEventInput` (`kind: 'DISCORD_EVENT'`, `event`, `guildId`, `receivedAt`, `firedAt`, `attempt`, `data`) types the `input` of one triggered by a Gateway event (`DiscordEventType`), and `isDiscordEventInput` tells it from the other inputs.
|
|
49
49
|
|
|
50
50
|
## Schedule helpers
|
|
51
51
|
|
|
@@ -13,8 +13,42 @@ export declare enum DiscordCapability {
|
|
|
13
13
|
GET_MEMBER = "discord.getMember",
|
|
14
14
|
GET_GUILD_ROLES = "discord.getGuildRoles",
|
|
15
15
|
GET_CHANNEL = "discord.getChannel",
|
|
16
|
-
GET_GUILD = "discord.getGuild"
|
|
16
|
+
GET_GUILD = "discord.getGuild",
|
|
17
|
+
KICK_MEMBER = "discord.kickMember",
|
|
18
|
+
BAN_MEMBER = "discord.banMember",
|
|
19
|
+
UNBAN_MEMBER = "discord.unbanMember",
|
|
20
|
+
TIMEOUT_MEMBER = "discord.timeoutMember",
|
|
21
|
+
BULK_DELETE_MESSAGES = "discord.bulkDeleteMessages",
|
|
22
|
+
ADD_REACTION = "discord.addReaction",
|
|
23
|
+
REMOVE_REACTION = "discord.removeReaction",
|
|
24
|
+
CREATE_CHANNEL = "discord.createChannel",
|
|
25
|
+
DELETE_CHANNEL = "discord.deleteChannel",
|
|
26
|
+
SET_CHANNEL_PERMISSION = "discord.setChannelPermission",
|
|
27
|
+
REMOVE_CHANNEL_PERMISSION = "discord.removeChannelPermission",
|
|
28
|
+
CREATE_ROLE = "discord.createRole",
|
|
29
|
+
DELETE_ROLE = "discord.deleteRole",
|
|
30
|
+
CREATE_THREAD = "discord.createThread",
|
|
31
|
+
END_POLL = "discord.endPoll"
|
|
17
32
|
}
|
|
33
|
+
export declare const DISCORD_CAPABILITY_LIMITS: {
|
|
34
|
+
readonly auditReasonMaxLength: 512;
|
|
35
|
+
readonly timeoutMaxDays: 28;
|
|
36
|
+
readonly banDeleteMessageSecondsMax: 604800;
|
|
37
|
+
readonly bulkDeleteMin: 2;
|
|
38
|
+
readonly bulkDeleteMax: 100;
|
|
39
|
+
readonly channelNameMaxLength: 100;
|
|
40
|
+
readonly channelTopicMaxLength: 1024;
|
|
41
|
+
readonly permissionOverwritesMax: 100;
|
|
42
|
+
readonly roleNameMaxLength: 100;
|
|
43
|
+
readonly roleColorMax: 16777215;
|
|
44
|
+
readonly threadNameMaxLength: 100;
|
|
45
|
+
readonly threadAutoArchiveMinutes: readonly [60, 1440, 4320, 10080];
|
|
46
|
+
readonly pollQuestionMaxLength: 300;
|
|
47
|
+
readonly pollAnswersMax: 10;
|
|
48
|
+
readonly pollAnswerTextMaxLength: 55;
|
|
49
|
+
readonly pollDurationHoursMax: 768;
|
|
50
|
+
readonly pollDurationHoursDefault: 24;
|
|
51
|
+
};
|
|
18
52
|
export declare enum DiscordErrorCode {
|
|
19
53
|
MODAL_TOO_LATE = "MODAL_TOO_LATE",
|
|
20
54
|
DISCORD_TOKEN_INVALID = "DISCORD_TOKEN_INVALID",
|
|
@@ -37,12 +71,23 @@ export interface DiscordAllowedMentions {
|
|
|
37
71
|
roles?: string[];
|
|
38
72
|
repliedUser?: boolean;
|
|
39
73
|
}
|
|
74
|
+
export interface DiscordPollAnswer {
|
|
75
|
+
text: string;
|
|
76
|
+
emoji?: string;
|
|
77
|
+
}
|
|
78
|
+
export interface DiscordPoll {
|
|
79
|
+
question: string;
|
|
80
|
+
answers: DiscordPollAnswer[];
|
|
81
|
+
durationHours?: number;
|
|
82
|
+
allowMultiselect?: boolean;
|
|
83
|
+
}
|
|
40
84
|
export interface DiscordMessage {
|
|
41
85
|
content?: string;
|
|
42
86
|
embeds?: DiscordJsonObject[];
|
|
43
87
|
components?: DiscordJsonObject[];
|
|
44
88
|
ephemeral?: boolean;
|
|
45
89
|
allowedMentions?: DiscordAllowedMentions;
|
|
90
|
+
poll?: DiscordPoll;
|
|
46
91
|
}
|
|
47
92
|
export declare enum DiscordModalFieldStyle {
|
|
48
93
|
SHORT = "SHORT",
|
|
@@ -72,15 +117,111 @@ export interface DiscordEditMessageArgs {
|
|
|
72
117
|
messageId: string;
|
|
73
118
|
message: DiscordMessage;
|
|
74
119
|
}
|
|
75
|
-
export interface
|
|
120
|
+
export interface DiscordAuditReason {
|
|
121
|
+
reason?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface DiscordDeleteMessageArgs extends DiscordAuditReason {
|
|
76
124
|
channelId: string;
|
|
77
125
|
messageId: string;
|
|
78
126
|
}
|
|
79
|
-
export interface DiscordRoleArgs {
|
|
127
|
+
export interface DiscordRoleArgs extends DiscordAuditReason {
|
|
80
128
|
guildId: string;
|
|
81
129
|
userId: string;
|
|
82
130
|
roleId: string;
|
|
83
131
|
}
|
|
132
|
+
export interface DiscordKickMemberArgs extends DiscordAuditReason {
|
|
133
|
+
guildId: string;
|
|
134
|
+
userId: string;
|
|
135
|
+
}
|
|
136
|
+
export interface DiscordBanMemberArgs extends DiscordAuditReason {
|
|
137
|
+
guildId: string;
|
|
138
|
+
userId: string;
|
|
139
|
+
deleteMessageSeconds?: number;
|
|
140
|
+
}
|
|
141
|
+
export interface DiscordUnbanMemberArgs extends DiscordAuditReason {
|
|
142
|
+
guildId: string;
|
|
143
|
+
userId: string;
|
|
144
|
+
}
|
|
145
|
+
export interface DiscordTimeoutMemberArgs extends DiscordAuditReason {
|
|
146
|
+
guildId: string;
|
|
147
|
+
userId: string;
|
|
148
|
+
until: string | null;
|
|
149
|
+
}
|
|
150
|
+
export interface DiscordBulkDeleteMessagesArgs extends DiscordAuditReason {
|
|
151
|
+
channelId: string;
|
|
152
|
+
messageIds: string[];
|
|
153
|
+
}
|
|
154
|
+
export interface DiscordReactionArgs {
|
|
155
|
+
channelId: string;
|
|
156
|
+
messageId: string;
|
|
157
|
+
emoji: string;
|
|
158
|
+
}
|
|
159
|
+
export interface DiscordRemoveReactionArgs extends DiscordReactionArgs {
|
|
160
|
+
userId?: string;
|
|
161
|
+
}
|
|
162
|
+
export declare enum DiscordChannelType {
|
|
163
|
+
TEXT = 0,
|
|
164
|
+
VOICE = 2,
|
|
165
|
+
CATEGORY = 4,
|
|
166
|
+
ANNOUNCEMENT = 5,
|
|
167
|
+
FORUM = 15
|
|
168
|
+
}
|
|
169
|
+
export declare enum DiscordPermissionTargetType {
|
|
170
|
+
ROLE = "ROLE",
|
|
171
|
+
MEMBER = "MEMBER"
|
|
172
|
+
}
|
|
173
|
+
export interface DiscordPermissionOverwrite {
|
|
174
|
+
id: string;
|
|
175
|
+
type: DiscordPermissionTargetType;
|
|
176
|
+
allow?: string;
|
|
177
|
+
deny?: string;
|
|
178
|
+
}
|
|
179
|
+
export interface DiscordCreateChannelArgs extends DiscordAuditReason {
|
|
180
|
+
guildId: string;
|
|
181
|
+
name: string;
|
|
182
|
+
type: DiscordChannelType;
|
|
183
|
+
parentId?: string;
|
|
184
|
+
topic?: string;
|
|
185
|
+
nsfw?: boolean;
|
|
186
|
+
permissionOverwrites?: DiscordPermissionOverwrite[];
|
|
187
|
+
}
|
|
188
|
+
export interface DiscordDeleteChannelArgs extends DiscordAuditReason {
|
|
189
|
+
channelId: string;
|
|
190
|
+
}
|
|
191
|
+
export interface DiscordSetChannelPermissionArgs extends DiscordAuditReason {
|
|
192
|
+
channelId: string;
|
|
193
|
+
targetId: string;
|
|
194
|
+
targetType: DiscordPermissionTargetType;
|
|
195
|
+
allow?: string;
|
|
196
|
+
deny?: string;
|
|
197
|
+
}
|
|
198
|
+
export interface DiscordRemoveChannelPermissionArgs extends DiscordAuditReason {
|
|
199
|
+
channelId: string;
|
|
200
|
+
targetId: string;
|
|
201
|
+
}
|
|
202
|
+
export interface DiscordCreateRoleArgs extends DiscordAuditReason {
|
|
203
|
+
guildId: string;
|
|
204
|
+
name: string;
|
|
205
|
+
permissions?: string;
|
|
206
|
+
color?: number;
|
|
207
|
+
hoist?: boolean;
|
|
208
|
+
mentionable?: boolean;
|
|
209
|
+
}
|
|
210
|
+
export interface DiscordDeleteRoleArgs extends DiscordAuditReason {
|
|
211
|
+
guildId: string;
|
|
212
|
+
roleId: string;
|
|
213
|
+
}
|
|
214
|
+
export interface DiscordCreateThreadArgs extends DiscordAuditReason {
|
|
215
|
+
channelId: string;
|
|
216
|
+
name: string;
|
|
217
|
+
messageId?: string;
|
|
218
|
+
private?: boolean;
|
|
219
|
+
autoArchiveMinutes?: number;
|
|
220
|
+
}
|
|
221
|
+
export interface DiscordEndPollArgs {
|
|
222
|
+
channelId: string;
|
|
223
|
+
messageId: string;
|
|
224
|
+
}
|
|
84
225
|
export interface DiscordSendDirectMessageArgs {
|
|
85
226
|
userId: string;
|
|
86
227
|
message: DiscordMessage;
|
|
@@ -165,15 +306,37 @@ export declare enum DiscordCallbackType {
|
|
|
165
306
|
MODAL = 9
|
|
166
307
|
}
|
|
167
308
|
export declare const EPHEMERAL_FLAG = 64;
|
|
309
|
+
export interface DiscordResolvedMember {
|
|
310
|
+
nick: string | null;
|
|
311
|
+
roles: string[];
|
|
312
|
+
joinedAt: string | null;
|
|
313
|
+
permissions: string | null;
|
|
314
|
+
}
|
|
315
|
+
export interface DiscordAttachment {
|
|
316
|
+
id: string;
|
|
317
|
+
filename: string;
|
|
318
|
+
size: number;
|
|
319
|
+
url: string;
|
|
320
|
+
contentType: string | null;
|
|
321
|
+
}
|
|
322
|
+
export interface DiscordResolved {
|
|
323
|
+
users?: Record<string, DiscordUser>;
|
|
324
|
+
members?: Record<string, DiscordResolvedMember>;
|
|
325
|
+
roles?: Record<string, DiscordRole>;
|
|
326
|
+
channels?: Record<string, DiscordChannel>;
|
|
327
|
+
attachments?: Record<string, DiscordAttachment>;
|
|
328
|
+
}
|
|
168
329
|
export interface DiscordInteractionInput {
|
|
169
330
|
kind: DiscordInteractionKind;
|
|
170
331
|
command?: {
|
|
171
332
|
name: string;
|
|
172
333
|
options: Record<string, string | number | boolean>;
|
|
334
|
+
resolved?: DiscordResolved;
|
|
173
335
|
};
|
|
174
336
|
component?: {
|
|
175
337
|
customId: string;
|
|
176
338
|
values?: string[];
|
|
339
|
+
resolved?: DiscordResolved;
|
|
177
340
|
};
|
|
178
341
|
modal?: {
|
|
179
342
|
customId: string;
|
|
@@ -198,3 +361,80 @@ export interface DiscordInteractionInput {
|
|
|
198
361
|
data: JSONValue;
|
|
199
362
|
};
|
|
200
363
|
}
|
|
364
|
+
export declare enum DiscordEventType {
|
|
365
|
+
GUILD_MEMBER_ADD = "GUILD_MEMBER_ADD",
|
|
366
|
+
GUILD_MEMBER_REMOVE = "GUILD_MEMBER_REMOVE",
|
|
367
|
+
MESSAGE_CREATE = "MESSAGE_CREATE",
|
|
368
|
+
MESSAGE_REACTION_ADD = "MESSAGE_REACTION_ADD"
|
|
369
|
+
}
|
|
370
|
+
export interface DiscordMemberAddData {
|
|
371
|
+
user: {
|
|
372
|
+
id: string;
|
|
373
|
+
username: string;
|
|
374
|
+
globalName: string | null;
|
|
375
|
+
bot: boolean;
|
|
376
|
+
avatar: string | null;
|
|
377
|
+
};
|
|
378
|
+
roles: string[];
|
|
379
|
+
joinedAt: string | null;
|
|
380
|
+
pending: boolean;
|
|
381
|
+
}
|
|
382
|
+
export interface DiscordMemberRemoveData {
|
|
383
|
+
user: {
|
|
384
|
+
id: string;
|
|
385
|
+
username: string;
|
|
386
|
+
globalName: string | null;
|
|
387
|
+
bot: boolean;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
export interface DiscordMessageCreateData {
|
|
391
|
+
id: string;
|
|
392
|
+
channelId: string;
|
|
393
|
+
author: {
|
|
394
|
+
id: string;
|
|
395
|
+
username: string;
|
|
396
|
+
globalName: string | null;
|
|
397
|
+
bot: boolean;
|
|
398
|
+
};
|
|
399
|
+
member: {
|
|
400
|
+
roles: string[];
|
|
401
|
+
nick: string | null;
|
|
402
|
+
} | null;
|
|
403
|
+
mentions: string[];
|
|
404
|
+
referencedMessageId: string | null;
|
|
405
|
+
attachmentCount: number;
|
|
406
|
+
createdAt: string;
|
|
407
|
+
content?: string;
|
|
408
|
+
}
|
|
409
|
+
export interface DiscordReactionAddData {
|
|
410
|
+
userId: string;
|
|
411
|
+
channelId: string;
|
|
412
|
+
messageId: string;
|
|
413
|
+
messageAuthorId: string | null;
|
|
414
|
+
member: {
|
|
415
|
+
roles: string[];
|
|
416
|
+
} | null;
|
|
417
|
+
emoji: {
|
|
418
|
+
id: string | null;
|
|
419
|
+
name: string | null;
|
|
420
|
+
animated: boolean;
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
export declare const DISCORD_EVENT_INPUT_KIND = "DISCORD_EVENT";
|
|
424
|
+
export interface DiscordEventInput {
|
|
425
|
+
kind: typeof DISCORD_EVENT_INPUT_KIND;
|
|
426
|
+
event: {
|
|
427
|
+
id: string;
|
|
428
|
+
type: DiscordEventType;
|
|
429
|
+
trigger: {
|
|
430
|
+
id: string;
|
|
431
|
+
name: string;
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
guildId: string;
|
|
435
|
+
receivedAt: string;
|
|
436
|
+
firedAt: string;
|
|
437
|
+
attempt: number;
|
|
438
|
+
data: DiscordMemberAddData | DiscordMemberRemoveData | DiscordMessageCreateData | DiscordReactionAddData;
|
|
439
|
+
}
|
|
440
|
+
export declare const isDiscordEventInput: (value: unknown) => value is DiscordEventInput;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EPHEMERAL_FLAG = exports.DiscordCallbackType = exports.DiscordInteractionType = exports.DiscordInteractionKind = exports.DiscordModalFieldStyle = exports.DiscordMentionType = exports.DiscordErrorCode = exports.DiscordCapability = void 0;
|
|
3
|
+
exports.isDiscordEventInput = exports.DISCORD_EVENT_INPUT_KIND = exports.DiscordEventType = exports.EPHEMERAL_FLAG = exports.DiscordCallbackType = exports.DiscordInteractionType = exports.DiscordInteractionKind = exports.DiscordPermissionTargetType = exports.DiscordChannelType = exports.DiscordModalFieldStyle = exports.DiscordMentionType = exports.DiscordErrorCode = exports.DISCORD_CAPABILITY_LIMITS = exports.DiscordCapability = void 0;
|
|
4
4
|
var DiscordCapability;
|
|
5
5
|
(function (DiscordCapability) {
|
|
6
6
|
DiscordCapability["REPLY"] = "discord.reply";
|
|
@@ -17,7 +17,41 @@ var DiscordCapability;
|
|
|
17
17
|
DiscordCapability["GET_GUILD_ROLES"] = "discord.getGuildRoles";
|
|
18
18
|
DiscordCapability["GET_CHANNEL"] = "discord.getChannel";
|
|
19
19
|
DiscordCapability["GET_GUILD"] = "discord.getGuild";
|
|
20
|
+
DiscordCapability["KICK_MEMBER"] = "discord.kickMember";
|
|
21
|
+
DiscordCapability["BAN_MEMBER"] = "discord.banMember";
|
|
22
|
+
DiscordCapability["UNBAN_MEMBER"] = "discord.unbanMember";
|
|
23
|
+
DiscordCapability["TIMEOUT_MEMBER"] = "discord.timeoutMember";
|
|
24
|
+
DiscordCapability["BULK_DELETE_MESSAGES"] = "discord.bulkDeleteMessages";
|
|
25
|
+
DiscordCapability["ADD_REACTION"] = "discord.addReaction";
|
|
26
|
+
DiscordCapability["REMOVE_REACTION"] = "discord.removeReaction";
|
|
27
|
+
DiscordCapability["CREATE_CHANNEL"] = "discord.createChannel";
|
|
28
|
+
DiscordCapability["DELETE_CHANNEL"] = "discord.deleteChannel";
|
|
29
|
+
DiscordCapability["SET_CHANNEL_PERMISSION"] = "discord.setChannelPermission";
|
|
30
|
+
DiscordCapability["REMOVE_CHANNEL_PERMISSION"] = "discord.removeChannelPermission";
|
|
31
|
+
DiscordCapability["CREATE_ROLE"] = "discord.createRole";
|
|
32
|
+
DiscordCapability["DELETE_ROLE"] = "discord.deleteRole";
|
|
33
|
+
DiscordCapability["CREATE_THREAD"] = "discord.createThread";
|
|
34
|
+
DiscordCapability["END_POLL"] = "discord.endPoll";
|
|
20
35
|
})(DiscordCapability || (exports.DiscordCapability = DiscordCapability = {}));
|
|
36
|
+
exports.DISCORD_CAPABILITY_LIMITS = {
|
|
37
|
+
auditReasonMaxLength: 512,
|
|
38
|
+
timeoutMaxDays: 28,
|
|
39
|
+
banDeleteMessageSecondsMax: 604_800,
|
|
40
|
+
bulkDeleteMin: 2,
|
|
41
|
+
bulkDeleteMax: 100,
|
|
42
|
+
channelNameMaxLength: 100,
|
|
43
|
+
channelTopicMaxLength: 1024,
|
|
44
|
+
permissionOverwritesMax: 100,
|
|
45
|
+
roleNameMaxLength: 100,
|
|
46
|
+
roleColorMax: 0xffffff,
|
|
47
|
+
threadNameMaxLength: 100,
|
|
48
|
+
threadAutoArchiveMinutes: [60, 1440, 4320, 10080],
|
|
49
|
+
pollQuestionMaxLength: 300,
|
|
50
|
+
pollAnswersMax: 10,
|
|
51
|
+
pollAnswerTextMaxLength: 55,
|
|
52
|
+
pollDurationHoursMax: 768,
|
|
53
|
+
pollDurationHoursDefault: 24,
|
|
54
|
+
};
|
|
21
55
|
var DiscordErrorCode;
|
|
22
56
|
(function (DiscordErrorCode) {
|
|
23
57
|
DiscordErrorCode["MODAL_TOO_LATE"] = "MODAL_TOO_LATE";
|
|
@@ -38,6 +72,19 @@ var DiscordModalFieldStyle;
|
|
|
38
72
|
DiscordModalFieldStyle["SHORT"] = "SHORT";
|
|
39
73
|
DiscordModalFieldStyle["PARAGRAPH"] = "PARAGRAPH";
|
|
40
74
|
})(DiscordModalFieldStyle || (exports.DiscordModalFieldStyle = DiscordModalFieldStyle = {}));
|
|
75
|
+
var DiscordChannelType;
|
|
76
|
+
(function (DiscordChannelType) {
|
|
77
|
+
DiscordChannelType[DiscordChannelType["TEXT"] = 0] = "TEXT";
|
|
78
|
+
DiscordChannelType[DiscordChannelType["VOICE"] = 2] = "VOICE";
|
|
79
|
+
DiscordChannelType[DiscordChannelType["CATEGORY"] = 4] = "CATEGORY";
|
|
80
|
+
DiscordChannelType[DiscordChannelType["ANNOUNCEMENT"] = 5] = "ANNOUNCEMENT";
|
|
81
|
+
DiscordChannelType[DiscordChannelType["FORUM"] = 15] = "FORUM";
|
|
82
|
+
})(DiscordChannelType || (exports.DiscordChannelType = DiscordChannelType = {}));
|
|
83
|
+
var DiscordPermissionTargetType;
|
|
84
|
+
(function (DiscordPermissionTargetType) {
|
|
85
|
+
DiscordPermissionTargetType["ROLE"] = "ROLE";
|
|
86
|
+
DiscordPermissionTargetType["MEMBER"] = "MEMBER";
|
|
87
|
+
})(DiscordPermissionTargetType || (exports.DiscordPermissionTargetType = DiscordPermissionTargetType = {}));
|
|
41
88
|
var DiscordInteractionKind;
|
|
42
89
|
(function (DiscordInteractionKind) {
|
|
43
90
|
DiscordInteractionKind["COMMAND"] = "COMMAND";
|
|
@@ -61,4 +108,31 @@ var DiscordCallbackType;
|
|
|
61
108
|
DiscordCallbackType[DiscordCallbackType["MODAL"] = 9] = "MODAL";
|
|
62
109
|
})(DiscordCallbackType || (exports.DiscordCallbackType = DiscordCallbackType = {}));
|
|
63
110
|
exports.EPHEMERAL_FLAG = 64;
|
|
111
|
+
var DiscordEventType;
|
|
112
|
+
(function (DiscordEventType) {
|
|
113
|
+
DiscordEventType["GUILD_MEMBER_ADD"] = "GUILD_MEMBER_ADD";
|
|
114
|
+
DiscordEventType["GUILD_MEMBER_REMOVE"] = "GUILD_MEMBER_REMOVE";
|
|
115
|
+
DiscordEventType["MESSAGE_CREATE"] = "MESSAGE_CREATE";
|
|
116
|
+
DiscordEventType["MESSAGE_REACTION_ADD"] = "MESSAGE_REACTION_ADD";
|
|
117
|
+
})(DiscordEventType || (exports.DiscordEventType = DiscordEventType = {}));
|
|
118
|
+
exports.DISCORD_EVENT_INPUT_KIND = 'DISCORD_EVENT';
|
|
119
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
120
|
+
const isDiscordEventInput = (value) => {
|
|
121
|
+
if (!isRecord(value) || value.kind !== exports.DISCORD_EVENT_INPUT_KIND) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
const { event } = value;
|
|
125
|
+
return (isRecord(event) &&
|
|
126
|
+
typeof event.id === 'string' &&
|
|
127
|
+
Object.values(DiscordEventType).includes(event.type) &&
|
|
128
|
+
isRecord(event.trigger) &&
|
|
129
|
+
typeof event.trigger.id === 'string' &&
|
|
130
|
+
typeof event.trigger.name === 'string' &&
|
|
131
|
+
typeof value.guildId === 'string' &&
|
|
132
|
+
typeof value.receivedAt === 'string' &&
|
|
133
|
+
typeof value.firedAt === 'string' &&
|
|
134
|
+
typeof value.attempt === 'number' &&
|
|
135
|
+
isRecord(value.data));
|
|
136
|
+
};
|
|
137
|
+
exports.isDiscordEventInput = isDiscordEventInput;
|
|
64
138
|
//# sourceMappingURL=discord.types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discord.types.js","sourceRoot":"","sources":["../../src/discord/discord.types.ts"],"names":[],"mappings":";;;AAOA,IAAY,
|
|
1
|
+
{"version":3,"file":"discord.types.js","sourceRoot":"","sources":["../../src/discord/discord.types.ts"],"names":[],"mappings":";;;AAOA,IAAY,iBA2DX;AA3DD,WAAY,iBAAiB;IAE3B,4CAAuB,CAAA;IAEvB,8CAAyB,CAAA;IAEzB,qDAAgC,CAAA;IAEhC,mDAA8B,CAAA;IAE9B,yDAAoC,CAAA;IAEpC,yDAAoC,CAAA;IAEpC,6DAAwC,CAAA;IAExC,iDAA4B,CAAA;IAE5B,uDAAkC,CAAA;IAElC,sEAAiD,CAAA;IAEjD,qDAAgC,CAAA;IAEhC,8DAAyC,CAAA;IAEzC,uDAAkC,CAAA;IAElC,mDAA8B,CAAA;IAE9B,uDAAkC,CAAA;IAElC,qDAAgC,CAAA;IAEhC,yDAAoC,CAAA;IAEpC,6DAAwC,CAAA;IAExC,wEAAmD,CAAA;IAEnD,yDAAoC,CAAA;IAEpC,+DAA0C,CAAA;IAE1C,6DAAwC,CAAA;IAExC,6DAAwC,CAAA;IAExC,4EAAuD,CAAA;IAEvD,kFAA6D,CAAA;IAE7D,uDAAkC,CAAA;IAElC,uDAAkC,CAAA;IAElC,2DAAsC,CAAA;IAEtC,iDAA4B,CAAA;AAC9B,CAAC,EA3DW,iBAAiB,iCAAjB,iBAAiB,QA2D5B;AAMY,QAAA,yBAAyB,GAAG;IAEvC,oBAAoB,EAAE,GAAG;IAEzB,cAAc,EAAE,EAAE;IAElB,0BAA0B,EAAE,OAAO;IACnC,aAAa,EAAE,CAAC;IAChB,aAAa,EAAE,GAAG;IAClB,oBAAoB,EAAE,GAAG;IACzB,qBAAqB,EAAE,IAAI;IAC3B,uBAAuB,EAAE,GAAG;IAC5B,iBAAiB,EAAE,GAAG;IACtB,YAAY,EAAE,QAAQ;IACtB,mBAAmB,EAAE,GAAG;IAExB,wBAAwB,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC;IACjD,qBAAqB,EAAE,GAAG;IAC1B,cAAc,EAAE,EAAE;IAClB,uBAAuB,EAAE,EAAE;IAE3B,oBAAoB,EAAE,GAAG;IACzB,wBAAwB,EAAE,EAAE;CACpB,CAAC;AAOX,IAAY,gBAgBX;AAhBD,WAAY,gBAAgB;IAE1B,qDAAiC,CAAA;IAEjC,mEAA+C,CAAA;IAE/C,2DAAuC,CAAA;IAEvC,2DAAuC,CAAA;IAEvC,iEAA6C,CAAA;IAK7C,qDAAiC,CAAA;AACnC,CAAC,EAhBW,gBAAgB,gCAAhB,gBAAgB,QAgB3B;AASD,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,qCAAe,CAAA;IACf,qCAAe,CAAA;IACf,2CAAqB,CAAA;AACvB,CAAC,EAJW,kBAAkB,kCAAlB,kBAAkB,QAI7B;AAiDD,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,iDAAuB,CAAA;AACzB,CAAC,EAHW,sBAAsB,sCAAtB,sBAAsB,QAGjC;AA4FD,IAAY,kBAMX;AAND,WAAY,kBAAkB;IAC5B,2DAAQ,CAAA;IACR,6DAAS,CAAA;IACT,mEAAY,CAAA;IACZ,2EAAgB,CAAA;IAChB,8DAAU,CAAA;AACZ,CAAC,EANW,kBAAkB,kCAAlB,kBAAkB,QAM7B;AAGD,IAAY,2BAGX;AAHD,WAAY,2BAA2B;IACrC,4CAAa,CAAA;IACb,gDAAiB,CAAA;AACnB,CAAC,EAHW,2BAA2B,2CAA3B,2BAA2B,QAGtC;AAwKD,IAAY,sBAIX;AAJD,WAAY,sBAAsB;IAChC,6CAAmB,CAAA;IACnB,iDAAuB,CAAA;IACvB,yCAAe,CAAA;AACjB,CAAC,EAJW,sBAAsB,sCAAtB,sBAAsB,QAIjC;AAGD,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAChC,mEAAQ,CAAA;IACR,iGAAuB,CAAA;IACvB,6FAAqB,CAAA;IACrB,mFAAgB,CAAA;AAClB,CAAC,EALW,sBAAsB,sCAAtB,sBAAsB,QAKjC;AAGD,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,6DAAQ,CAAA;IACR,2GAA+B,CAAA;IAC/B,6HAAwC,CAAA;IACxC,mGAA2B,CAAA;IAC3B,iFAAkB,CAAA;IAClB,+DAAS,CAAA;AACX,CAAC,EAPW,mBAAmB,mCAAnB,mBAAmB,QAO9B;AAGY,QAAA,cAAc,GAAG,EAAE,CAAC;AA4DjC,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,yDAAqC,CAAA;IACrC,+DAA2C,CAAA;IAC3C,qDAAiC,CAAA;IACjC,iEAA6C,CAAA;AAC/C,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAkDY,QAAA,wBAAwB,GAAG,eAAe,CAAC;AAkBxD,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAMhE,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAA8B,EAAE;IAChF,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,gCAAwB,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACxB,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ;QAC5B,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAwB,CAAC;QACxE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;QACvB,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,QAAQ;QACpC,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,QAAQ;QACtC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ;QACpC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CACrB,CAAC;AACJ,CAAC,CAAC;AAlBW,QAAA,mBAAmB,uBAkB9B"}
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { builtinModules } from 'module';
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as path from 'path';
|
|
4
4
|
|
|
5
|
+
import { DiscordEventType, isDiscordEventInput } from '../index';
|
|
5
6
|
const SRC_DIR = path.resolve(__dirname, '..');
|
|
6
7
|
const SERVER_DIR = path.join(SRC_DIR, 'server');
|
|
7
8
|
const TESTS_DIR = path.join(SRC_DIR, '__tests__');
|
|
@@ -51,3 +52,15 @@ describe('browser-compatible package root', () => {
|
|
|
51
52
|
expect(['joi', './steps', '../access'].some(isForbidden)).toBe(false);
|
|
52
53
|
});
|
|
53
54
|
});
|
|
55
|
+
|
|
56
|
+
describe('public surface of the package root', () => {
|
|
57
|
+
it('exports the Discord event input contract', () => {
|
|
58
|
+
expect(Object.values(DiscordEventType)).toEqual([
|
|
59
|
+
'GUILD_MEMBER_ADD',
|
|
60
|
+
'GUILD_MEMBER_REMOVE',
|
|
61
|
+
'MESSAGE_CREATE',
|
|
62
|
+
'MESSAGE_REACTION_ADD',
|
|
63
|
+
]);
|
|
64
|
+
expect(typeof isDiscordEventInput).toBe('function');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { DiscordEventInput, DiscordEventType, isDiscordEventInput } from '../discord.types';
|
|
2
|
+
import { ScheduledRunKind } from '../../schedule/schedule.types';
|
|
3
|
+
|
|
4
|
+
const DATA_BY_TYPE: Record<DiscordEventType, DiscordEventInput['data']> = {
|
|
5
|
+
[DiscordEventType.GUILD_MEMBER_ADD]: {
|
|
6
|
+
user: { id: 'u1', username: 'ann', globalName: null, bot: false, avatar: null },
|
|
7
|
+
roles: [],
|
|
8
|
+
joinedAt: '2026-11-21T10:00:00.000Z',
|
|
9
|
+
pending: false,
|
|
10
|
+
},
|
|
11
|
+
[DiscordEventType.GUILD_MEMBER_REMOVE]: {
|
|
12
|
+
user: { id: 'u1', username: 'ann', globalName: 'Ann', bot: false },
|
|
13
|
+
},
|
|
14
|
+
[DiscordEventType.MESSAGE_CREATE]: {
|
|
15
|
+
id: 'm1',
|
|
16
|
+
channelId: 'c1',
|
|
17
|
+
author: { id: 'u1', username: 'ann', globalName: null, bot: false },
|
|
18
|
+
member: { roles: ['r1'], nick: null },
|
|
19
|
+
mentions: [],
|
|
20
|
+
referencedMessageId: null,
|
|
21
|
+
attachmentCount: 0,
|
|
22
|
+
createdAt: '2026-11-21T10:00:00.000Z',
|
|
23
|
+
},
|
|
24
|
+
[DiscordEventType.MESSAGE_REACTION_ADD]: {
|
|
25
|
+
userId: 'u1',
|
|
26
|
+
channelId: 'c1',
|
|
27
|
+
messageId: 'm1',
|
|
28
|
+
messageAuthorId: 'u2',
|
|
29
|
+
member: { roles: [] },
|
|
30
|
+
emoji: { id: null, name: '👍', animated: false },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const inputOf = (type: DiscordEventType): DiscordEventInput => ({
|
|
35
|
+
kind: 'DISCORD_EVENT',
|
|
36
|
+
event: { id: 'e1', type, trigger: { id: 't1', name: 'welcome' } },
|
|
37
|
+
guildId: 'g1',
|
|
38
|
+
receivedAt: '2026-11-21T10:00:00.000Z',
|
|
39
|
+
firedAt: '2026-11-21T10:00:01.000Z',
|
|
40
|
+
attempt: 1,
|
|
41
|
+
data: DATA_BY_TYPE[type],
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('isDiscordEventInput', () => {
|
|
45
|
+
it.each(Object.values(DiscordEventType))('is true for a %s input', (type) => {
|
|
46
|
+
expect(isDiscordEventInput(inputOf(type))).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('is false for an interaction input', () => {
|
|
50
|
+
expect(
|
|
51
|
+
isDiscordEventInput({
|
|
52
|
+
kind: 'COMMAND',
|
|
53
|
+
command: { name: 'ping', options: {} },
|
|
54
|
+
user: { id: 'u1', username: 'ann', globalName: null },
|
|
55
|
+
locale: 'en-US',
|
|
56
|
+
interaction: { id: 'i1', applicationId: 'a1', type: 2, data: null },
|
|
57
|
+
}),
|
|
58
|
+
).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('is false for a scheduled run input', () => {
|
|
62
|
+
expect(
|
|
63
|
+
isDiscordEventInput({
|
|
64
|
+
kind: ScheduledRunKind.SCHEDULE,
|
|
65
|
+
task: { id: 't1', name: 'daily' },
|
|
66
|
+
scheduledFor: '2026-11-21T10:00:00.000Z',
|
|
67
|
+
firedAt: '2026-11-21T10:00:01.000Z',
|
|
68
|
+
attempt: 1,
|
|
69
|
+
}),
|
|
70
|
+
).toBe(false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('is false for an unknown event type, a missing envelope field and non-objects', () => {
|
|
74
|
+
expect(
|
|
75
|
+
isDiscordEventInput({
|
|
76
|
+
...inputOf(DiscordEventType.MESSAGE_CREATE),
|
|
77
|
+
event: { id: 'e1', type: 'X', trigger: { id: 't', name: 'n' } },
|
|
78
|
+
}),
|
|
79
|
+
).toBe(false);
|
|
80
|
+
expect(
|
|
81
|
+
isDiscordEventInput({ ...inputOf(DiscordEventType.MESSAGE_CREATE), guildId: undefined }),
|
|
82
|
+
).toBe(false);
|
|
83
|
+
expect(isDiscordEventInput({ ...inputOf(DiscordEventType.MESSAGE_CREATE), data: null })).toBe(
|
|
84
|
+
false,
|
|
85
|
+
);
|
|
86
|
+
expect(isDiscordEventInput(null)).toBe(false);
|
|
87
|
+
expect(isDiscordEventInput('DISCORD_EVENT')).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -34,8 +34,67 @@ export enum DiscordCapability {
|
|
|
34
34
|
GET_CHANNEL = 'discord.getChannel',
|
|
35
35
|
/** Reads a server. Arguments: `DiscordGetGuildArgs`; result: `DiscordGuild`. */
|
|
36
36
|
GET_GUILD = 'discord.getGuild',
|
|
37
|
+
/** Removes a member from a server. Arguments: `DiscordKickMemberArgs`. */
|
|
38
|
+
KICK_MEMBER = 'discord.kickMember',
|
|
39
|
+
/** Bans a user from a server. Arguments: `DiscordBanMemberArgs`. */
|
|
40
|
+
BAN_MEMBER = 'discord.banMember',
|
|
41
|
+
/** Lifts the ban of a user. Arguments: `DiscordUnbanMemberArgs`. */
|
|
42
|
+
UNBAN_MEMBER = 'discord.unbanMember',
|
|
43
|
+
/** Times a member out, or lifts the timeout. Arguments: `DiscordTimeoutMemberArgs`. */
|
|
44
|
+
TIMEOUT_MEMBER = 'discord.timeoutMember',
|
|
45
|
+
/** Deletes 2 to 100 messages of a channel in one call. Arguments: `DiscordBulkDeleteMessagesArgs`. */
|
|
46
|
+
BULK_DELETE_MESSAGES = 'discord.bulkDeleteMessages',
|
|
47
|
+
/** Adds the bot's reaction to a message. Arguments: `DiscordReactionArgs`. */
|
|
48
|
+
ADD_REACTION = 'discord.addReaction',
|
|
49
|
+
/** Removes the bot's reaction, or a user's. Arguments: `DiscordRemoveReactionArgs`. */
|
|
50
|
+
REMOVE_REACTION = 'discord.removeReaction',
|
|
51
|
+
/** Creates a channel in a server. Arguments: `DiscordCreateChannelArgs`; result: `DiscordChannel`. */
|
|
52
|
+
CREATE_CHANNEL = 'discord.createChannel',
|
|
53
|
+
/** Deletes a channel or a thread. Arguments: `DiscordDeleteChannelArgs`. */
|
|
54
|
+
DELETE_CHANNEL = 'discord.deleteChannel',
|
|
55
|
+
/** Sets what a role or a member may do in a channel. Arguments: `DiscordSetChannelPermissionArgs`. */
|
|
56
|
+
SET_CHANNEL_PERMISSION = 'discord.setChannelPermission',
|
|
57
|
+
/** Removes what a channel sets for a role or a member. Arguments: `DiscordRemoveChannelPermissionArgs`. */
|
|
58
|
+
REMOVE_CHANNEL_PERMISSION = 'discord.removeChannelPermission',
|
|
59
|
+
/** Creates a role in a server. Arguments: `DiscordCreateRoleArgs`; result: `DiscordRole`. */
|
|
60
|
+
CREATE_ROLE = 'discord.createRole',
|
|
61
|
+
/** Deletes a role of a server. Arguments: `DiscordDeleteRoleArgs`. */
|
|
62
|
+
DELETE_ROLE = 'discord.deleteRole',
|
|
63
|
+
/** Starts a thread, from a message or not. Arguments: `DiscordCreateThreadArgs`; result: `DiscordChannel`. */
|
|
64
|
+
CREATE_THREAD = 'discord.createThread',
|
|
65
|
+
/** Ends a poll of the bot before its time. Arguments: `DiscordEndPollArgs`. */
|
|
66
|
+
END_POLL = 'discord.endPoll',
|
|
37
67
|
}
|
|
38
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Bounds the host applies to the arguments of `abyss.discord.*` before any call to Discord: a call
|
|
71
|
+
* outside them fails with an argument error and costs nothing.
|
|
72
|
+
*/
|
|
73
|
+
export const DISCORD_CAPABILITY_LIMITS = {
|
|
74
|
+
/** `reason` of an action, sent as Discord's audit log reason. */
|
|
75
|
+
auditReasonMaxLength: 512,
|
|
76
|
+
/** Longest timeout Discord allows, from now. */
|
|
77
|
+
timeoutMaxDays: 28,
|
|
78
|
+
/** Messages a ban may delete, in seconds back from now (7 days). */
|
|
79
|
+
banDeleteMessageSecondsMax: 604_800,
|
|
80
|
+
bulkDeleteMin: 2,
|
|
81
|
+
bulkDeleteMax: 100,
|
|
82
|
+
channelNameMaxLength: 100,
|
|
83
|
+
channelTopicMaxLength: 1024,
|
|
84
|
+
permissionOverwritesMax: 100,
|
|
85
|
+
roleNameMaxLength: 100,
|
|
86
|
+
roleColorMax: 0xffffff,
|
|
87
|
+
threadNameMaxLength: 100,
|
|
88
|
+
/** Auto-archive durations Discord accepts, in minutes. */
|
|
89
|
+
threadAutoArchiveMinutes: [60, 1440, 4320, 10080],
|
|
90
|
+
pollQuestionMaxLength: 300,
|
|
91
|
+
pollAnswersMax: 10,
|
|
92
|
+
pollAnswerTextMaxLength: 55,
|
|
93
|
+
/** 32 days. */
|
|
94
|
+
pollDurationHoursMax: 768,
|
|
95
|
+
pollDurationHoursDefault: 24,
|
|
96
|
+
} as const;
|
|
97
|
+
|
|
39
98
|
/**
|
|
40
99
|
* Codes of the errors `abyss.discord.*` throws. The host fails the call with the message
|
|
41
100
|
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `DiscordError`
|
|
@@ -86,6 +145,26 @@ export interface DiscordAllowedMentions {
|
|
|
86
145
|
repliedUser?: boolean;
|
|
87
146
|
}
|
|
88
147
|
|
|
148
|
+
/** An answer of a poll. `emoji` is a unicode emoji or a server emoji `name:id`. */
|
|
149
|
+
export interface DiscordPollAnswer {
|
|
150
|
+
text: string;
|
|
151
|
+
emoji?: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A native Discord poll attached to a new message. Discord never edits a poll: `editMessage` and
|
|
156
|
+
* `update` refuse a message that carries one.
|
|
157
|
+
*/
|
|
158
|
+
export interface DiscordPoll {
|
|
159
|
+
/** 1 to 300 characters. */
|
|
160
|
+
question: string;
|
|
161
|
+
/** 1 to 10 answers. */
|
|
162
|
+
answers: DiscordPollAnswer[];
|
|
163
|
+
/** 1 to 768 hours (32 days), 24 by default. */
|
|
164
|
+
durationHours?: number;
|
|
165
|
+
allowMultiselect?: boolean;
|
|
166
|
+
}
|
|
167
|
+
|
|
89
168
|
export interface DiscordMessage {
|
|
90
169
|
content?: string;
|
|
91
170
|
embeds?: DiscordJsonObject[];
|
|
@@ -94,6 +173,8 @@ export interface DiscordMessage {
|
|
|
94
173
|
ephemeral?: boolean;
|
|
95
174
|
/** Who the message may notify; by default the mentioned users only (see `DiscordAllowedMentions`). */
|
|
96
175
|
allowedMentions?: DiscordAllowedMentions;
|
|
176
|
+
/** A poll; only on a new message (`sendMessage`, `sendDirectMessage`, `reply`, `followUp`). */
|
|
177
|
+
poll?: DiscordPoll;
|
|
97
178
|
}
|
|
98
179
|
|
|
99
180
|
/** Text input style of a modal field. */
|
|
@@ -130,17 +211,157 @@ export interface DiscordEditMessageArgs {
|
|
|
130
211
|
message: DiscordMessage;
|
|
131
212
|
}
|
|
132
213
|
|
|
133
|
-
|
|
214
|
+
/**
|
|
215
|
+
* The audit log reason an action may carry: 1 to 512 characters, shown in the server's audit log
|
|
216
|
+
* (Discord's `X-Audit-Log-Reason`).
|
|
217
|
+
*/
|
|
218
|
+
export interface DiscordAuditReason {
|
|
219
|
+
reason?: string;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface DiscordDeleteMessageArgs extends DiscordAuditReason {
|
|
134
223
|
channelId: string;
|
|
135
224
|
messageId: string;
|
|
136
225
|
}
|
|
137
226
|
|
|
138
|
-
export interface DiscordRoleArgs {
|
|
227
|
+
export interface DiscordRoleArgs extends DiscordAuditReason {
|
|
228
|
+
guildId: string;
|
|
229
|
+
userId: string;
|
|
230
|
+
roleId: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface DiscordKickMemberArgs extends DiscordAuditReason {
|
|
234
|
+
guildId: string;
|
|
235
|
+
userId: string;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface DiscordBanMemberArgs extends DiscordAuditReason {
|
|
239
|
+
guildId: string;
|
|
240
|
+
userId: string;
|
|
241
|
+
/** Deletes the user's messages of that many seconds back, 0 to 604 800 (7 days); 0 by default. */
|
|
242
|
+
deleteMessageSeconds?: number;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface DiscordUnbanMemberArgs extends DiscordAuditReason {
|
|
246
|
+
guildId: string;
|
|
247
|
+
userId: string;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface DiscordTimeoutMemberArgs extends DiscordAuditReason {
|
|
139
251
|
guildId: string;
|
|
140
252
|
userId: string;
|
|
253
|
+
/** End of the timeout, ISO 8601, in the future and at most 28 days away; null lifts it. */
|
|
254
|
+
until: string | null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface DiscordBulkDeleteMessagesArgs extends DiscordAuditReason {
|
|
258
|
+
channelId: string;
|
|
259
|
+
/** 2 to 100 distinct ids; Discord refuses a message older than 14 days. */
|
|
260
|
+
messageIds: string[];
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** `emoji` is a unicode emoji or a server emoji `name:id`. */
|
|
264
|
+
export interface DiscordReactionArgs {
|
|
265
|
+
channelId: string;
|
|
266
|
+
messageId: string;
|
|
267
|
+
emoji: string;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface DiscordRemoveReactionArgs extends DiscordReactionArgs {
|
|
271
|
+
/** Whose reaction to remove; the bot's own without it. */
|
|
272
|
+
userId?: string;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Discord's channel types a bot can create (`type` of `DiscordChannel` holds Discord's number). */
|
|
276
|
+
export enum DiscordChannelType {
|
|
277
|
+
TEXT = 0,
|
|
278
|
+
VOICE = 2,
|
|
279
|
+
CATEGORY = 4,
|
|
280
|
+
ANNOUNCEMENT = 5,
|
|
281
|
+
FORUM = 15,
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** What a channel permission applies to. */
|
|
285
|
+
export enum DiscordPermissionTargetType {
|
|
286
|
+
ROLE = 'ROLE',
|
|
287
|
+
MEMBER = 'MEMBER',
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Permissions a channel allows or denies to one role or member; bits as decimal strings. */
|
|
291
|
+
export interface DiscordPermissionOverwrite {
|
|
292
|
+
/** The role or member id. */
|
|
293
|
+
id: string;
|
|
294
|
+
type: DiscordPermissionTargetType;
|
|
295
|
+
allow?: string;
|
|
296
|
+
deny?: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export interface DiscordCreateChannelArgs extends DiscordAuditReason {
|
|
300
|
+
guildId: string;
|
|
301
|
+
/** 1 to 100 characters. */
|
|
302
|
+
name: string;
|
|
303
|
+
type: DiscordChannelType;
|
|
304
|
+
/** The category the channel goes in. */
|
|
305
|
+
parentId?: string;
|
|
306
|
+
/** Up to 1024 characters. */
|
|
307
|
+
topic?: string;
|
|
308
|
+
nsfw?: boolean;
|
|
309
|
+
/** 100 at most. */
|
|
310
|
+
permissionOverwrites?: DiscordPermissionOverwrite[];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface DiscordDeleteChannelArgs extends DiscordAuditReason {
|
|
314
|
+
channelId: string;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export interface DiscordSetChannelPermissionArgs extends DiscordAuditReason {
|
|
318
|
+
channelId: string;
|
|
319
|
+
targetId: string;
|
|
320
|
+
targetType: DiscordPermissionTargetType;
|
|
321
|
+
/** Permission bits as a decimal string; none by default. */
|
|
322
|
+
allow?: string;
|
|
323
|
+
deny?: string;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface DiscordRemoveChannelPermissionArgs extends DiscordAuditReason {
|
|
327
|
+
channelId: string;
|
|
328
|
+
targetId: string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface DiscordCreateRoleArgs extends DiscordAuditReason {
|
|
332
|
+
guildId: string;
|
|
333
|
+
/** 1 to 100 characters. */
|
|
334
|
+
name: string;
|
|
335
|
+
/** Permission bits as a decimal string; Discord's default without it. */
|
|
336
|
+
permissions?: string;
|
|
337
|
+
/** RGB color as an integer, 0 to 0xFFFFFF. */
|
|
338
|
+
color?: number;
|
|
339
|
+
hoist?: boolean;
|
|
340
|
+
mentionable?: boolean;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface DiscordDeleteRoleArgs extends DiscordAuditReason {
|
|
344
|
+
guildId: string;
|
|
141
345
|
roleId: string;
|
|
142
346
|
}
|
|
143
347
|
|
|
348
|
+
export interface DiscordCreateThreadArgs extends DiscordAuditReason {
|
|
349
|
+
channelId: string;
|
|
350
|
+
/** 1 to 100 characters. */
|
|
351
|
+
name: string;
|
|
352
|
+
/** Starts the thread from this message; without it the thread stands alone. */
|
|
353
|
+
messageId?: string;
|
|
354
|
+
/** A private thread; only without `messageId`. */
|
|
355
|
+
private?: boolean;
|
|
356
|
+
/** 60, 1440, 4320 or 10080. */
|
|
357
|
+
autoArchiveMinutes?: number;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export interface DiscordEndPollArgs {
|
|
361
|
+
channelId: string;
|
|
362
|
+
messageId: string;
|
|
363
|
+
}
|
|
364
|
+
|
|
144
365
|
export interface DiscordSendDirectMessageArgs {
|
|
145
366
|
userId: string;
|
|
146
367
|
message: DiscordMessage;
|
|
@@ -263,11 +484,49 @@ export const EPHEMERAL_FLAG = 64;
|
|
|
263
484
|
* The `input` of a function triggered by a Discord interaction. The interaction token never
|
|
264
485
|
* appears here: it stays in the edge.
|
|
265
486
|
*/
|
|
487
|
+
/** A member as an interaction resolves it: partial, without its user (see `DiscordResolved.users`). */
|
|
488
|
+
export interface DiscordResolvedMember {
|
|
489
|
+
nick: string | null;
|
|
490
|
+
/** Role ids. */
|
|
491
|
+
roles: string[];
|
|
492
|
+
joinedAt: string | null;
|
|
493
|
+
/** The member's permissions in the channel, decimal string; null when Discord does not give them. */
|
|
494
|
+
permissions: string | null;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** A file a user attached to an ATTACHMENT option. */
|
|
498
|
+
export interface DiscordAttachment {
|
|
499
|
+
id: string;
|
|
500
|
+
filename: string;
|
|
501
|
+
/** Bytes. */
|
|
502
|
+
size: number;
|
|
503
|
+
url: string;
|
|
504
|
+
contentType: string | null;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* The users, members, roles, channels and files an interaction names, by id, as Discord resolves
|
|
509
|
+
* them for its options and typed select menus. A key is absent when Discord resolved none of its kind.
|
|
510
|
+
*/
|
|
511
|
+
export interface DiscordResolved {
|
|
512
|
+
users?: Record<string, DiscordUser>;
|
|
513
|
+
members?: Record<string, DiscordResolvedMember>;
|
|
514
|
+
roles?: Record<string, DiscordRole>;
|
|
515
|
+
/** Partial channels: what Discord gives in an interaction. */
|
|
516
|
+
channels?: Record<string, DiscordChannel>;
|
|
517
|
+
attachments?: Record<string, DiscordAttachment>;
|
|
518
|
+
}
|
|
519
|
+
|
|
266
520
|
export interface DiscordInteractionInput {
|
|
267
521
|
kind: DiscordInteractionKind;
|
|
268
|
-
/** Resolved option values, by option name. */
|
|
269
|
-
command?: {
|
|
270
|
-
|
|
522
|
+
/** Resolved option values, by option name; `resolved` details the ids they hold, when there are some. */
|
|
523
|
+
command?: {
|
|
524
|
+
name: string;
|
|
525
|
+
options: Record<string, string | number | boolean>;
|
|
526
|
+
resolved?: DiscordResolved;
|
|
527
|
+
};
|
|
528
|
+
/** `values` of a select menu; `resolved` details them for a user, role, channel or mentionable menu. */
|
|
529
|
+
component?: { customId: string; values?: string[]; resolved?: DiscordResolved };
|
|
271
530
|
modal?: { customId: string; fields: Record<string, string> };
|
|
272
531
|
user: { id: string; username: string; globalName: string | null };
|
|
273
532
|
member?: { roles: string[]; permissions: string };
|
|
@@ -277,3 +536,104 @@ export interface DiscordInteractionInput {
|
|
|
277
536
|
/** Discord's payload, without the interaction token. */
|
|
278
537
|
interaction: { id: string; applicationId: string; type: number; data: JSONValue };
|
|
279
538
|
}
|
|
539
|
+
|
|
540
|
+
/** The Gateway events a bot's function can be triggered by. */
|
|
541
|
+
export enum DiscordEventType {
|
|
542
|
+
GUILD_MEMBER_ADD = 'GUILD_MEMBER_ADD',
|
|
543
|
+
GUILD_MEMBER_REMOVE = 'GUILD_MEMBER_REMOVE',
|
|
544
|
+
MESSAGE_CREATE = 'MESSAGE_CREATE',
|
|
545
|
+
MESSAGE_REACTION_ADD = 'MESSAGE_REACTION_ADD',
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** `data` of a `GUILD_MEMBER_ADD` event. */
|
|
549
|
+
export interface DiscordMemberAddData {
|
|
550
|
+
user: {
|
|
551
|
+
id: string;
|
|
552
|
+
username: string;
|
|
553
|
+
globalName: string | null;
|
|
554
|
+
bot: boolean;
|
|
555
|
+
avatar: string | null;
|
|
556
|
+
};
|
|
557
|
+
/** Role ids. */
|
|
558
|
+
roles: string[];
|
|
559
|
+
joinedAt: string | null;
|
|
560
|
+
/** True while the member has not passed the server's membership screening. */
|
|
561
|
+
pending: boolean;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/** `data` of a `GUILD_MEMBER_REMOVE` event. */
|
|
565
|
+
export interface DiscordMemberRemoveData {
|
|
566
|
+
user: { id: string; username: string; globalName: string | null; bot: boolean };
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/** `data` of a `MESSAGE_CREATE` event. */
|
|
570
|
+
export interface DiscordMessageCreateData {
|
|
571
|
+
id: string;
|
|
572
|
+
channelId: string;
|
|
573
|
+
author: { id: string; username: string; globalName: string | null; bot: boolean };
|
|
574
|
+
member: { roles: string[]; nick: string | null } | null;
|
|
575
|
+
/** Ids of the mentioned users. */
|
|
576
|
+
mentions: string[];
|
|
577
|
+
referencedMessageId: string | null;
|
|
578
|
+
attachmentCount: number;
|
|
579
|
+
/** ISO 8601. */
|
|
580
|
+
createdAt: string;
|
|
581
|
+
/** Present only when the trigger asks for the content (`includeContent`). */
|
|
582
|
+
content?: string;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** `data` of a `MESSAGE_REACTION_ADD` event. */
|
|
586
|
+
export interface DiscordReactionAddData {
|
|
587
|
+
userId: string;
|
|
588
|
+
channelId: string;
|
|
589
|
+
messageId: string;
|
|
590
|
+
messageAuthorId: string | null;
|
|
591
|
+
member: { roles: string[] } | null;
|
|
592
|
+
emoji: { id: string | null; name: string | null; animated: boolean };
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** The `kind` of a `DiscordEventInput`. */
|
|
596
|
+
export const DISCORD_EVENT_INPUT_KIND = 'DISCORD_EVENT';
|
|
597
|
+
|
|
598
|
+
/** The `input` of a function triggered by a Discord Gateway event. */
|
|
599
|
+
export interface DiscordEventInput {
|
|
600
|
+
kind: typeof DISCORD_EVENT_INPUT_KIND;
|
|
601
|
+
event: { id: string; type: DiscordEventType; trigger: { id: string; name: string } };
|
|
602
|
+
guildId: string;
|
|
603
|
+
/** When the Gateway received it, ISO 8601. */
|
|
604
|
+
receivedAt: string;
|
|
605
|
+
firedAt: string;
|
|
606
|
+
attempt: number;
|
|
607
|
+
data:
|
|
608
|
+
| DiscordMemberAddData
|
|
609
|
+
| DiscordMemberRemoveData
|
|
610
|
+
| DiscordMessageCreateData
|
|
611
|
+
| DiscordReactionAddData;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
615
|
+
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Tells a `DiscordEventInput` from the other inputs of a function (interaction, scheduled run). It
|
|
619
|
+
* checks the envelope (`kind`, event, guild, dates, attempt, `data` object), not the shape of `data`.
|
|
620
|
+
*/
|
|
621
|
+
export const isDiscordEventInput = (value: unknown): value is DiscordEventInput => {
|
|
622
|
+
if (!isRecord(value) || value.kind !== DISCORD_EVENT_INPUT_KIND) {
|
|
623
|
+
return false;
|
|
624
|
+
}
|
|
625
|
+
const { event } = value;
|
|
626
|
+
return (
|
|
627
|
+
isRecord(event) &&
|
|
628
|
+
typeof event.id === 'string' &&
|
|
629
|
+
Object.values(DiscordEventType).includes(event.type as DiscordEventType) &&
|
|
630
|
+
isRecord(event.trigger) &&
|
|
631
|
+
typeof event.trigger.id === 'string' &&
|
|
632
|
+
typeof event.trigger.name === 'string' &&
|
|
633
|
+
typeof value.guildId === 'string' &&
|
|
634
|
+
typeof value.receivedAt === 'string' &&
|
|
635
|
+
typeof value.firedAt === 'string' &&
|
|
636
|
+
typeof value.attempt === 'number' &&
|
|
637
|
+
isRecord(value.data)
|
|
638
|
+
);
|
|
639
|
+
};
|
|
@@ -1,100 +1,100 @@
|
|
|
1
|
-
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Host capabilities of the delayed runs of a Service. The host declares them in the execution's
|
|
5
|
-
* capabilities; client code reaches them through `abyss.schedule.<name>(...)`; every helper
|
|
6
|
-
* exists, and one whose capability is not granted rejects with an error naming the action to
|
|
7
|
-
* declare. The argument shapes below are the `args` of the `call`.
|
|
8
|
-
*/
|
|
9
|
-
export enum ScheduleCapability {
|
|
10
|
-
/** Schedules a run of a task after a delay. Arguments: `ScheduleAfterArgs`; result: `ScheduleResult`. */
|
|
11
|
-
SCHEDULE_AFTER = 'schedule.after',
|
|
12
|
-
/** Schedules a run of a task at a date. Arguments: `ScheduleAtArgs`; result: `ScheduleResult`. */
|
|
13
|
-
SCHEDULE_AT = 'schedule.at',
|
|
14
|
-
/** Cancels a pending delayed run. Arguments: `ScheduleCancelArgs`; result: `ScheduleCancelResult`. */
|
|
15
|
-
SCHEDULE_CANCEL = 'schedule.cancel',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Codes of the errors `abyss.schedule.*` throws. The host fails the call with the message
|
|
20
|
-
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `ScheduleError`
|
|
21
|
-
* whose `code` is the code and whose `message` is the detail.
|
|
22
|
-
*/
|
|
23
|
-
export enum ScheduleErrorCode {
|
|
24
|
-
/** No task of that name in the version in service. */
|
|
25
|
-
SCHEDULE_TASK_UNKNOWN = 'SCHEDULE_TASK_UNKNOWN',
|
|
26
|
-
/** The due date is less than the minimal delay away, or beyond the horizon. */
|
|
27
|
-
SCHEDULE_HORIZON_EXCEEDED = 'SCHEDULE_HORIZON_EXCEEDED',
|
|
28
|
-
/** The Service already has as many pending delayed runs in this environment as its plan allows. */
|
|
29
|
-
SCHEDULE_LIMIT_REACHED = 'SCHEDULE_LIMIT_REACHED',
|
|
30
|
-
/** The attached payload is longer than allowed once serialized to JSON. */
|
|
31
|
-
SCHEDULE_PAYLOAD_TOO_LARGE = 'SCHEDULE_PAYLOAD_TOO_LARGE',
|
|
32
|
-
/** The arguments are malformed (delay not a number, date not ISO 8601, empty key...). */
|
|
33
|
-
SCHEDULE_INVALID = 'SCHEDULE_INVALID',
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Options shared by `abyss.schedule.after` and `abyss.schedule.at`. */
|
|
37
|
-
export interface ScheduleOptions {
|
|
38
|
-
/**
|
|
39
|
-
* Deduplication key: while a delayed run of the same task with the same key is pending in the
|
|
40
|
-
* environment, scheduling again returns that run's id with `deduplicated: true`.
|
|
41
|
-
* `abyss.schedule.cancel(key)` cancels the pending runs with that key across every task of the
|
|
42
|
-
* Service in the environment.
|
|
43
|
-
*/
|
|
44
|
-
key?: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ScheduleAfterArgs extends ScheduleOptions {
|
|
48
|
-
/** Delay before the run, in seconds. */
|
|
49
|
-
seconds: number;
|
|
50
|
-
/** Name of the task of the Service to run. */
|
|
51
|
-
taskName: string;
|
|
52
|
-
/** Data handed to the run as `input.payload`. */
|
|
53
|
-
payload?: JSONValue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface ScheduleAtArgs extends ScheduleOptions {
|
|
57
|
-
/** Due date, ISO 8601. */
|
|
58
|
-
at: string;
|
|
59
|
-
/** Name of the task of the Service to run. */
|
|
60
|
-
taskName: string;
|
|
61
|
-
/** Data handed to the run as `input.payload`. */
|
|
62
|
-
payload?: JSONValue;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface ScheduleCancelArgs {
|
|
66
|
-
/** The id `schedule.after` or `schedule.at` returned, or the deduplication key of the run. */
|
|
67
|
-
idOrKey: string;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface ScheduleResult {
|
|
71
|
-
/** Id of the delayed run. */
|
|
72
|
-
id: string;
|
|
73
|
-
/** True when a pending run with the same key already existed: its id is returned, nothing is added. */
|
|
74
|
-
deduplicated: boolean;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface ScheduleCancelResult {
|
|
78
|
-
/** False when no pending run matched (unknown, already run or already cancelled). */
|
|
79
|
-
cancelled: boolean;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** What started a scheduled run: a tick of the task's cron, or a delayed run. */
|
|
83
|
-
export enum ScheduledRunKind {
|
|
84
|
-
SCHEDULE = 'SCHEDULE',
|
|
85
|
-
DELAYED = 'DELAYED',
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** The `input` of a function started by a task: a cron tick or a delayed run. */
|
|
89
|
-
export interface ScheduledRunInput {
|
|
90
|
-
kind: ScheduledRunKind;
|
|
91
|
-
task: { id: string; name: string };
|
|
92
|
-
/** When the run was due, ISO 8601. */
|
|
93
|
-
scheduledFor: string;
|
|
94
|
-
/** When this attempt started, ISO 8601. */
|
|
95
|
-
firedAt: string;
|
|
96
|
-
/** Attempt number, from 1. */
|
|
97
|
-
attempt: number;
|
|
98
|
-
/** The payload of a delayed run, when it has one. */
|
|
99
|
-
payload?: JSONValue;
|
|
100
|
-
}
|
|
1
|
+
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Host capabilities of the delayed runs of a Service. The host declares them in the execution's
|
|
5
|
+
* capabilities; client code reaches them through `abyss.schedule.<name>(...)`; every helper
|
|
6
|
+
* exists, and one whose capability is not granted rejects with an error naming the action to
|
|
7
|
+
* declare. The argument shapes below are the `args` of the `call`.
|
|
8
|
+
*/
|
|
9
|
+
export enum ScheduleCapability {
|
|
10
|
+
/** Schedules a run of a task after a delay. Arguments: `ScheduleAfterArgs`; result: `ScheduleResult`. */
|
|
11
|
+
SCHEDULE_AFTER = 'schedule.after',
|
|
12
|
+
/** Schedules a run of a task at a date. Arguments: `ScheduleAtArgs`; result: `ScheduleResult`. */
|
|
13
|
+
SCHEDULE_AT = 'schedule.at',
|
|
14
|
+
/** Cancels a pending delayed run. Arguments: `ScheduleCancelArgs`; result: `ScheduleCancelResult`. */
|
|
15
|
+
SCHEDULE_CANCEL = 'schedule.cancel',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Codes of the errors `abyss.schedule.*` throws. The host fails the call with the message
|
|
20
|
+
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `ScheduleError`
|
|
21
|
+
* whose `code` is the code and whose `message` is the detail.
|
|
22
|
+
*/
|
|
23
|
+
export enum ScheduleErrorCode {
|
|
24
|
+
/** No task of that name in the version in service. */
|
|
25
|
+
SCHEDULE_TASK_UNKNOWN = 'SCHEDULE_TASK_UNKNOWN',
|
|
26
|
+
/** The due date is less than the minimal delay away, or beyond the horizon. */
|
|
27
|
+
SCHEDULE_HORIZON_EXCEEDED = 'SCHEDULE_HORIZON_EXCEEDED',
|
|
28
|
+
/** The Service already has as many pending delayed runs in this environment as its plan allows. */
|
|
29
|
+
SCHEDULE_LIMIT_REACHED = 'SCHEDULE_LIMIT_REACHED',
|
|
30
|
+
/** The attached payload is longer than allowed once serialized to JSON. */
|
|
31
|
+
SCHEDULE_PAYLOAD_TOO_LARGE = 'SCHEDULE_PAYLOAD_TOO_LARGE',
|
|
32
|
+
/** The arguments are malformed (delay not a number, date not ISO 8601, empty key...). */
|
|
33
|
+
SCHEDULE_INVALID = 'SCHEDULE_INVALID',
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Options shared by `abyss.schedule.after` and `abyss.schedule.at`. */
|
|
37
|
+
export interface ScheduleOptions {
|
|
38
|
+
/**
|
|
39
|
+
* Deduplication key: while a delayed run of the same task with the same key is pending in the
|
|
40
|
+
* environment, scheduling again returns that run's id with `deduplicated: true`.
|
|
41
|
+
* `abyss.schedule.cancel(key)` cancels the pending runs with that key across every task of the
|
|
42
|
+
* Service in the environment.
|
|
43
|
+
*/
|
|
44
|
+
key?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ScheduleAfterArgs extends ScheduleOptions {
|
|
48
|
+
/** Delay before the run, in seconds. */
|
|
49
|
+
seconds: number;
|
|
50
|
+
/** Name of the task of the Service to run. */
|
|
51
|
+
taskName: string;
|
|
52
|
+
/** Data handed to the run as `input.payload`. */
|
|
53
|
+
payload?: JSONValue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface ScheduleAtArgs extends ScheduleOptions {
|
|
57
|
+
/** Due date, ISO 8601. */
|
|
58
|
+
at: string;
|
|
59
|
+
/** Name of the task of the Service to run. */
|
|
60
|
+
taskName: string;
|
|
61
|
+
/** Data handed to the run as `input.payload`. */
|
|
62
|
+
payload?: JSONValue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ScheduleCancelArgs {
|
|
66
|
+
/** The id `schedule.after` or `schedule.at` returned, or the deduplication key of the run. */
|
|
67
|
+
idOrKey: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ScheduleResult {
|
|
71
|
+
/** Id of the delayed run. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** True when a pending run with the same key already existed: its id is returned, nothing is added. */
|
|
74
|
+
deduplicated: boolean;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ScheduleCancelResult {
|
|
78
|
+
/** False when no pending run matched (unknown, already run or already cancelled). */
|
|
79
|
+
cancelled: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** What started a scheduled run: a tick of the task's cron, or a delayed run. */
|
|
83
|
+
export enum ScheduledRunKind {
|
|
84
|
+
SCHEDULE = 'SCHEDULE',
|
|
85
|
+
DELAYED = 'DELAYED',
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The `input` of a function started by a task: a cron tick or a delayed run. */
|
|
89
|
+
export interface ScheduledRunInput {
|
|
90
|
+
kind: ScheduledRunKind;
|
|
91
|
+
task: { id: string; name: string };
|
|
92
|
+
/** When the run was due, ISO 8601. */
|
|
93
|
+
scheduledFor: string;
|
|
94
|
+
/** When this attempt started, ISO 8601. */
|
|
95
|
+
firedAt: string;
|
|
96
|
+
/** Attempt number, from 1. */
|
|
97
|
+
attempt: number;
|
|
98
|
+
/** The payload of a delayed run, when it has one. */
|
|
99
|
+
payload?: JSONValue;
|
|
100
|
+
}
|