@abyss-project/runtime 3.4.0 → 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 +88 -88
- package/dist/discord/discord.types.d.ts +167 -4
- package/dist/discord/discord.types.js +48 -1
- package/dist/discord/discord.types.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/surface.test.ts +66 -66
- package/src/discord/__tests__/discord-event-input.test.ts +89 -89
- package/src/discord/discord.types.ts +639 -380
package/README.md
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
# @abyss-project/runtime
|
|
2
|
-
|
|
3
|
-
Abyss automation core: definitions, interpreter, execution protocol `abyss-runtime.v2` and
|
|
4
|
-
execution cost.
|
|
5
|
-
|
|
6
|
-
The package root (`@abyss-project/runtime`) is browser-compatible. Node-only code (the
|
|
7
|
-
`CodeRunnerSession` WebSocket client) lives under `@abyss-project/runtime/server`.
|
|
8
|
-
`@abyss-project/runtime/engine` exports `ENGINE_SOURCE`, the interpreter bundled into one
|
|
9
|
-
self-contained script for the code runner's isolate.
|
|
10
|
-
|
|
11
|
-
## Host globals
|
|
12
|
-
|
|
13
|
-
`ExecuteMessage.globals` gives the client code read-only globals: each top-level key becomes a
|
|
14
|
-
frozen global. Two keys are conventional: `secrets` (`{{ secrets.NAME }}` / `secrets.NAME`, masked
|
|
15
|
-
by the host) and `config` (`Record<string, string>`, the non-secret per-environment variables:
|
|
16
|
-
`{{ config.NAME }}` / `config.NAME`, not masked). A name the host did not send is `undefined`.
|
|
17
|
-
The host sends the names `collectGlobalReferences(definition, 'config')` finds.
|
|
18
|
-
|
|
19
|
-
## Discord helpers
|
|
20
|
-
|
|
21
|
-
A host that grants the `DiscordCapability` names (`discord.reply`, `discord.update`,
|
|
22
|
-
`discord.showModal`, `discord.followUp`, `discord.sendMessage`, `discord.editMessage`,
|
|
23
|
-
`discord.deleteMessage`, `discord.addRole`, `discord.removeRole`, `discord.sendDirectMessage`,
|
|
24
|
-
`discord.getMember`, `discord.getGuildRoles`, `discord.getChannel`, `discord.getGuild`) lets the
|
|
25
|
-
client code call `abyss.discord.<name>(...)`. Every helper always exists; one whose capability the
|
|
26
|
-
function does not declare rejects with an error naming the action to declare:
|
|
27
|
-
|
|
28
|
-
- `reply(message)`, `update(message)`, `followUp(message)`, `showModal({ customId, title, fields })`
|
|
29
|
-
- `sendMessage(channelId, message)`, `editMessage(channelId, messageId, message)`,
|
|
30
|
-
`deleteMessage(channelId, messageId)`, `sendDirectMessage(userId, message)`
|
|
31
|
-
- `addRole(guildId, userId, roleId)`, `removeRole(guildId, userId, roleId)`
|
|
32
|
-
- reads: `getMember(guildId, userId)` (a `DiscordMember`, or `null` when the user is not in the
|
|
33
|
-
server), `getGuildRoles(guildId)` (`DiscordRole[]`), `getChannel(channelId)` (`DiscordChannel`),
|
|
34
|
-
`getGuild(guildId)` (`DiscordGuild`). The shapes are Discord's in camelCase; permissions are
|
|
35
|
-
decimal strings, since they exceed 2^53.
|
|
36
|
-
|
|
37
|
-
`reply`, `update`, `showModal` and `followUp` need an interaction: in an execution no interaction
|
|
38
|
-
started (a task, a delayed run) the host rejects them with `NO_INTERACTION`.
|
|
39
|
-
|
|
40
|
-
`message` is a `DiscordMessage` (`{ content?, embeds?, components?, ephemeral?, allowedMentions? }`).
|
|
41
|
-
By default a message pings the users it mentions and nobody else: `@everyone`, `@here` and roles
|
|
42
|
-
stay plain text. `allowedMentions` (`DiscordAllowedMentions`: `parse` of `DiscordMentionType`
|
|
43
|
-
values, `users`, `roles`, `repliedUser`) replaces that default. The `args` of
|
|
44
|
-
each host `call` are the types `Discord*Args` (a `DiscordMessage` itself for `reply`, `update`,
|
|
45
|
-
`followUp`). A host failing a call with the message `<DiscordErrorCode>: <detail>` (or the bare
|
|
46
|
-
code) makes the helper throw an `Error` named `DiscordError` with `code` and `message` set; any
|
|
47
|
-
other failure is thrown unchanged. `DiscordInteractionInput` types the `input` of a function
|
|
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
|
-
|
|
50
|
-
## Schedule helpers
|
|
51
|
-
|
|
52
|
-
A host that grants the `ScheduleCapability` names (`schedule.after`, `schedule.at`,
|
|
53
|
-
`schedule.cancel`) lets the client code schedule a delayed run of a named task. Every helper always
|
|
54
|
-
exists; one whose capability the function does not declare rejects with an error naming the action
|
|
55
|
-
to declare:
|
|
56
|
-
|
|
57
|
-
- `after(seconds, taskName, payload?, { key? })` and `at(isoDate, taskName, payload?, { key? })`
|
|
58
|
-
(`isoDate` an ISO 8601 string, or a `Date`) resolve to a `ScheduleResult` (`{ id, deduplicated }`).
|
|
59
|
-
While a run with the same `key` is pending, scheduling again returns its `id` with
|
|
60
|
-
`deduplicated: true`.
|
|
61
|
-
- `cancel(idOrKey)` resolves to a `ScheduleCancelResult` (`{ cancelled }`).
|
|
62
|
-
|
|
63
|
-
The `args` of each host `call` are `ScheduleAfterArgs`, `ScheduleAtArgs` and `ScheduleCancelArgs`
|
|
64
|
-
(`payload` and `key` left out when not given). A host failing a call with the message
|
|
65
|
-
`<ScheduleErrorCode>: <detail>` (or the bare code) makes the helper throw an `Error` named
|
|
66
|
-
`ScheduleError` with `code` and `message` set; any other failure is thrown unchanged.
|
|
67
|
-
`ScheduledRunInput` (`{ kind, task: { id, name }, scheduledFor, firedAt, attempt, payload? }`, `kind`
|
|
68
|
-
a `ScheduledRunKind`: `SCHEDULE` for a cron tick, `DELAYED` for a delayed run) types the `input` of a
|
|
69
|
-
function started by a task.
|
|
70
|
-
|
|
71
|
-
## Installation
|
|
72
|
-
|
|
73
|
-
```bash
|
|
74
|
-
npm install @abyss-project/runtime
|
|
75
|
-
# or
|
|
76
|
-
pnpm add @abyss-project/runtime
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Liens
|
|
80
|
-
|
|
81
|
-
- **Documentation** : [https://docs.abyss-project.fr](https://docs.abyss-project.fr)
|
|
82
|
-
- **NPM** : [@abyss-project/runtime](https://www.npmjs.com/package/@abyss-project/runtime)
|
|
83
|
-
- **Application Abyss** : [app.abyss-project.fr](https://app.abyss-project.fr)
|
|
84
|
-
- **Statut des services** : [status.abyss-project.fr](https://status.abyss-project.fr)
|
|
85
|
-
|
|
86
|
-
## Support
|
|
87
|
-
|
|
88
|
-
Pour toute demande, ouvrir un ticket depuis [l'application Abyss](https://app.abyss-project.fr/dashboard/account/tickets/create).
|
|
1
|
+
# @abyss-project/runtime
|
|
2
|
+
|
|
3
|
+
Abyss automation core: definitions, interpreter, execution protocol `abyss-runtime.v2` and
|
|
4
|
+
execution cost.
|
|
5
|
+
|
|
6
|
+
The package root (`@abyss-project/runtime`) is browser-compatible. Node-only code (the
|
|
7
|
+
`CodeRunnerSession` WebSocket client) lives under `@abyss-project/runtime/server`.
|
|
8
|
+
`@abyss-project/runtime/engine` exports `ENGINE_SOURCE`, the interpreter bundled into one
|
|
9
|
+
self-contained script for the code runner's isolate.
|
|
10
|
+
|
|
11
|
+
## Host globals
|
|
12
|
+
|
|
13
|
+
`ExecuteMessage.globals` gives the client code read-only globals: each top-level key becomes a
|
|
14
|
+
frozen global. Two keys are conventional: `secrets` (`{{ secrets.NAME }}` / `secrets.NAME`, masked
|
|
15
|
+
by the host) and `config` (`Record<string, string>`, the non-secret per-environment variables:
|
|
16
|
+
`{{ config.NAME }}` / `config.NAME`, not masked). A name the host did not send is `undefined`.
|
|
17
|
+
The host sends the names `collectGlobalReferences(definition, 'config')` finds.
|
|
18
|
+
|
|
19
|
+
## Discord helpers
|
|
20
|
+
|
|
21
|
+
A host that grants the `DiscordCapability` names (`discord.reply`, `discord.update`,
|
|
22
|
+
`discord.showModal`, `discord.followUp`, `discord.sendMessage`, `discord.editMessage`,
|
|
23
|
+
`discord.deleteMessage`, `discord.addRole`, `discord.removeRole`, `discord.sendDirectMessage`,
|
|
24
|
+
`discord.getMember`, `discord.getGuildRoles`, `discord.getChannel`, `discord.getGuild`) lets the
|
|
25
|
+
client code call `abyss.discord.<name>(...)`. Every helper always exists; one whose capability the
|
|
26
|
+
function does not declare rejects with an error naming the action to declare:
|
|
27
|
+
|
|
28
|
+
- `reply(message)`, `update(message)`, `followUp(message)`, `showModal({ customId, title, fields })`
|
|
29
|
+
- `sendMessage(channelId, message)`, `editMessage(channelId, messageId, message)`,
|
|
30
|
+
`deleteMessage(channelId, messageId)`, `sendDirectMessage(userId, message)`
|
|
31
|
+
- `addRole(guildId, userId, roleId)`, `removeRole(guildId, userId, roleId)`
|
|
32
|
+
- reads: `getMember(guildId, userId)` (a `DiscordMember`, or `null` when the user is not in the
|
|
33
|
+
server), `getGuildRoles(guildId)` (`DiscordRole[]`), `getChannel(channelId)` (`DiscordChannel`),
|
|
34
|
+
`getGuild(guildId)` (`DiscordGuild`). The shapes are Discord's in camelCase; permissions are
|
|
35
|
+
decimal strings, since they exceed 2^53.
|
|
36
|
+
|
|
37
|
+
`reply`, `update`, `showModal` and `followUp` need an interaction: in an execution no interaction
|
|
38
|
+
started (a task, a delayed run) the host rejects them with `NO_INTERACTION`.
|
|
39
|
+
|
|
40
|
+
`message` is a `DiscordMessage` (`{ content?, embeds?, components?, ephemeral?, allowedMentions? }`).
|
|
41
|
+
By default a message pings the users it mentions and nobody else: `@everyone`, `@here` and roles
|
|
42
|
+
stay plain text. `allowedMentions` (`DiscordAllowedMentions`: `parse` of `DiscordMentionType`
|
|
43
|
+
values, `users`, `roles`, `repliedUser`) replaces that default. The `args` of
|
|
44
|
+
each host `call` are the types `Discord*Args` (a `DiscordMessage` itself for `reply`, `update`,
|
|
45
|
+
`followUp`). A host failing a call with the message `<DiscordErrorCode>: <detail>` (or the bare
|
|
46
|
+
code) makes the helper throw an `Error` named `DiscordError` with `code` and `message` set; any
|
|
47
|
+
other failure is thrown unchanged. `DiscordInteractionInput` types the `input` of a function
|
|
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
|
+
|
|
50
|
+
## Schedule helpers
|
|
51
|
+
|
|
52
|
+
A host that grants the `ScheduleCapability` names (`schedule.after`, `schedule.at`,
|
|
53
|
+
`schedule.cancel`) lets the client code schedule a delayed run of a named task. Every helper always
|
|
54
|
+
exists; one whose capability the function does not declare rejects with an error naming the action
|
|
55
|
+
to declare:
|
|
56
|
+
|
|
57
|
+
- `after(seconds, taskName, payload?, { key? })` and `at(isoDate, taskName, payload?, { key? })`
|
|
58
|
+
(`isoDate` an ISO 8601 string, or a `Date`) resolve to a `ScheduleResult` (`{ id, deduplicated }`).
|
|
59
|
+
While a run with the same `key` is pending, scheduling again returns its `id` with
|
|
60
|
+
`deduplicated: true`.
|
|
61
|
+
- `cancel(idOrKey)` resolves to a `ScheduleCancelResult` (`{ cancelled }`).
|
|
62
|
+
|
|
63
|
+
The `args` of each host `call` are `ScheduleAfterArgs`, `ScheduleAtArgs` and `ScheduleCancelArgs`
|
|
64
|
+
(`payload` and `key` left out when not given). A host failing a call with the message
|
|
65
|
+
`<ScheduleErrorCode>: <detail>` (or the bare code) makes the helper throw an `Error` named
|
|
66
|
+
`ScheduleError` with `code` and `message` set; any other failure is thrown unchanged.
|
|
67
|
+
`ScheduledRunInput` (`{ kind, task: { id, name }, scheduledFor, firedAt, attempt, payload? }`, `kind`
|
|
68
|
+
a `ScheduledRunKind`: `SCHEDULE` for a cron tick, `DELAYED` for a delayed run) types the `input` of a
|
|
69
|
+
function started by a task.
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
npm install @abyss-project/runtime
|
|
75
|
+
# or
|
|
76
|
+
pnpm add @abyss-project/runtime
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Liens
|
|
80
|
+
|
|
81
|
+
- **Documentation** : [https://docs.abyss-project.fr](https://docs.abyss-project.fr)
|
|
82
|
+
- **NPM** : [@abyss-project/runtime](https://www.npmjs.com/package/@abyss-project/runtime)
|
|
83
|
+
- **Application Abyss** : [app.abyss-project.fr](https://app.abyss-project.fr)
|
|
84
|
+
- **Statut des services** : [status.abyss-project.fr](https://status.abyss-project.fr)
|
|
85
|
+
|
|
86
|
+
## Support
|
|
87
|
+
|
|
88
|
+
Pour toute demande, ouvrir un ticket depuis [l'application Abyss](https://app.abyss-project.fr/dashboard/account/tickets/create).
|
|
@@ -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"
|
|
17
|
-
|
|
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"
|
|
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 {
|
|
128
|
+
guildId: string;
|
|
129
|
+
userId: string;
|
|
130
|
+
roleId: string;
|
|
131
|
+
}
|
|
132
|
+
export interface DiscordKickMemberArgs extends DiscordAuditReason {
|
|
80
133
|
guildId: string;
|
|
81
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;
|
|
82
212
|
roleId: string;
|
|
83
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDiscordEventInput = exports.DISCORD_EVENT_INPUT_KIND = exports.DiscordEventType = 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";
|
|
@@ -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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,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
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import { builtinModules } from 'module';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
|
|
5
|
-
import { DiscordEventType, isDiscordEventInput } from '../index';
|
|
6
|
-
const SRC_DIR = path.resolve(__dirname, '..');
|
|
7
|
-
const SERVER_DIR = path.join(SRC_DIR, 'server');
|
|
8
|
-
const TESTS_DIR = path.join(SRC_DIR, '__tests__');
|
|
9
|
-
|
|
10
|
-
// `ws` and every Node built-in module (`fs`, `net`, `http`, `node:*`...) are forbidden outside
|
|
11
|
-
// `src/server`, so that the package root stays usable in a browser.
|
|
12
|
-
const FORBIDDEN = new Set<string>(['ws', ...builtinModules]);
|
|
13
|
-
|
|
14
|
-
const walkTsFiles = (dir: string): string[] =>
|
|
15
|
-
fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
16
|
-
const full = path.join(dir, entry.name);
|
|
17
|
-
if (entry.isDirectory()) {
|
|
18
|
-
return full === SERVER_DIR || full === TESTS_DIR ? [] : walkTsFiles(full);
|
|
19
|
-
}
|
|
20
|
-
return entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts') ? [full] : [];
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const IMPORT_PATTERNS = [
|
|
24
|
-
/\bfrom\s*['"]([^'"]+)['"]/g,
|
|
25
|
-
/\bimport\s*['"]([^'"]+)['"]/g,
|
|
26
|
-
/\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
27
|
-
/\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
const importedSpecifiers = (text: string): string[] =>
|
|
31
|
-
IMPORT_PATTERNS.flatMap((pattern) => [...text.matchAll(pattern)].map((match) => match[1]));
|
|
32
|
-
|
|
33
|
-
const isForbidden = (specifier: string): boolean => {
|
|
34
|
-
const bare = specifier.startsWith('node:') ? specifier.slice('node:'.length) : specifier;
|
|
35
|
-
return FORBIDDEN.has(bare) || FORBIDDEN.has(bare.split('/')[0]);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
describe('browser-compatible package root', () => {
|
|
39
|
-
it('imports no Node built-in nor ws outside src/server', () => {
|
|
40
|
-
const offenders = walkTsFiles(SRC_DIR).flatMap((file) =>
|
|
41
|
-
importedSpecifiers(fs.readFileSync(file, 'utf8'))
|
|
42
|
-
.filter(isForbidden)
|
|
43
|
-
.map((specifier) => `${path.relative(SRC_DIR, file)} imports ${specifier}`),
|
|
44
|
-
);
|
|
45
|
-
expect(offenders).toEqual([]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('detects forbidden imports (guard sanity)', () => {
|
|
49
|
-
const source = "import { WebSocket } from 'ws';\nconst n = require('node:net');";
|
|
50
|
-
expect(importedSpecifiers(source)).toEqual(['ws', 'node:net']);
|
|
51
|
-
expect(['ws', 'node:net', 'fs/promises', 'http'].every(isForbidden)).toBe(true);
|
|
52
|
-
expect(['joi', './steps', '../access'].some(isForbidden)).toBe(false);
|
|
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
|
-
});
|
|
1
|
+
import { builtinModules } from 'module';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
import { DiscordEventType, isDiscordEventInput } from '../index';
|
|
6
|
+
const SRC_DIR = path.resolve(__dirname, '..');
|
|
7
|
+
const SERVER_DIR = path.join(SRC_DIR, 'server');
|
|
8
|
+
const TESTS_DIR = path.join(SRC_DIR, '__tests__');
|
|
9
|
+
|
|
10
|
+
// `ws` and every Node built-in module (`fs`, `net`, `http`, `node:*`...) are forbidden outside
|
|
11
|
+
// `src/server`, so that the package root stays usable in a browser.
|
|
12
|
+
const FORBIDDEN = new Set<string>(['ws', ...builtinModules]);
|
|
13
|
+
|
|
14
|
+
const walkTsFiles = (dir: string): string[] =>
|
|
15
|
+
fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
16
|
+
const full = path.join(dir, entry.name);
|
|
17
|
+
if (entry.isDirectory()) {
|
|
18
|
+
return full === SERVER_DIR || full === TESTS_DIR ? [] : walkTsFiles(full);
|
|
19
|
+
}
|
|
20
|
+
return entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts') ? [full] : [];
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const IMPORT_PATTERNS = [
|
|
24
|
+
/\bfrom\s*['"]([^'"]+)['"]/g,
|
|
25
|
+
/\bimport\s*['"]([^'"]+)['"]/g,
|
|
26
|
+
/\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
27
|
+
/\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const importedSpecifiers = (text: string): string[] =>
|
|
31
|
+
IMPORT_PATTERNS.flatMap((pattern) => [...text.matchAll(pattern)].map((match) => match[1]));
|
|
32
|
+
|
|
33
|
+
const isForbidden = (specifier: string): boolean => {
|
|
34
|
+
const bare = specifier.startsWith('node:') ? specifier.slice('node:'.length) : specifier;
|
|
35
|
+
return FORBIDDEN.has(bare) || FORBIDDEN.has(bare.split('/')[0]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
describe('browser-compatible package root', () => {
|
|
39
|
+
it('imports no Node built-in nor ws outside src/server', () => {
|
|
40
|
+
const offenders = walkTsFiles(SRC_DIR).flatMap((file) =>
|
|
41
|
+
importedSpecifiers(fs.readFileSync(file, 'utf8'))
|
|
42
|
+
.filter(isForbidden)
|
|
43
|
+
.map((specifier) => `${path.relative(SRC_DIR, file)} imports ${specifier}`),
|
|
44
|
+
);
|
|
45
|
+
expect(offenders).toEqual([]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('detects forbidden imports (guard sanity)', () => {
|
|
49
|
+
const source = "import { WebSocket } from 'ws';\nconst n = require('node:net');";
|
|
50
|
+
expect(importedSpecifiers(source)).toEqual(['ws', 'node:net']);
|
|
51
|
+
expect(['ws', 'node:net', 'fs/promises', 'http'].every(isForbidden)).toBe(true);
|
|
52
|
+
expect(['joi', './steps', '../access'].some(isForbidden)).toBe(false);
|
|
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
|
+
});
|