@abyss-project/runtime 3.0.0 → 3.1.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 +27 -0
- package/dist/discord/discord.types.d.ts +123 -0
- package/dist/discord/discord.types.js +53 -0
- package/dist/discord/discord.types.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runner-protocol/execution-protocol.types.js.map +1 -1
- package/package.json +1 -1
- package/scripts/build-engine.cjs +70 -70
- package/src/__tests__/engine-bundle.test.ts +121 -121
- package/src/cost/__tests__/execution-cost.test.ts +196 -196
- package/src/cost/execution-cost.ts +186 -186
- package/src/definition/__tests__/validate-definition.test.ts +354 -354
- package/src/definition/definition.limits.ts +9 -9
- package/src/definition/definition.schema.ts +172 -172
- package/src/definition/definition.types.ts +171 -171
- package/src/discord/discord.types.ts +155 -0
- package/src/engine/__tests__/run-in-isolate.test.ts +468 -468
- package/src/engine/engine-entry.ts +3 -3
- package/src/engine/engine-global.ts +2 -2
- package/src/engine/run-in-isolate.ts +404 -404
- package/src/errors/runtime-error-code.enum.ts +37 -37
- package/src/index.ts +31 -30
- package/src/interpreter/__tests__/interpreter.test.ts +854 -854
- package/src/interpreter/__tests__/log-respond-resume.test.ts +223 -223
- package/src/interpreter/interpreter.ts +461 -461
- package/src/interpreter/interpreter.types.ts +192 -192
- package/src/interpreter/test-host.ts +85 -85
- package/src/runner-protocol/evaluation.types.ts +21 -21
- package/src/runner-protocol/execution-protocol.types.ts +231 -225
- package/src/server/__tests__/code-runner-session.test.ts +311 -311
- package/src/server/code-runner-error.ts +12 -12
- package/src/server/code-runner-session.ts +310 -310
- package/src/server/index.ts +11 -11
- package/src/steps/__tests__/global-references.test.ts +133 -113
- package/src/steps/execute-step.ts +186 -186
- package/src/steps/global-references.ts +48 -48
- package/src/steps/step-access.ts +56 -56
- package/src/steps/step-fields.ts +87 -87
- package/src/steps/value-source.ts +69 -69
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import type { ObjectSchema } from 'joi';
|
|
2
|
-
import type { AccessDeclaration } from '../access/access.types';
|
|
3
|
-
|
|
4
|
-
export const CURRENT_FORMAT_VERSION = 1;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A full JavaScript expression, evaluated by the code runner. Any other string may embed
|
|
8
|
-
* `{{ … }}` templates; an object whose only key is `$expression` is an expression.
|
|
9
|
-
*/
|
|
10
|
-
export interface ExpressionValue {
|
|
11
|
-
$expression: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type ValueSource =
|
|
15
|
-
| string
|
|
16
|
-
| number
|
|
17
|
-
| boolean
|
|
18
|
-
| null
|
|
19
|
-
| ExpressionValue
|
|
20
|
-
| ValueSource[]
|
|
21
|
-
| { [key: string]: ValueSource };
|
|
22
|
-
|
|
23
|
-
export enum StepType {
|
|
24
|
-
CONDITION = 'CONDITION',
|
|
25
|
-
SWITCH = 'SWITCH',
|
|
26
|
-
WAIT = 'WAIT',
|
|
27
|
-
SET = 'SET',
|
|
28
|
-
CODE = 'CODE',
|
|
29
|
-
HTTP = 'HTTP',
|
|
30
|
-
HOST = 'HOST',
|
|
31
|
-
/** Writes a log line kept with the run, through the host capability `log.write`. */
|
|
32
|
-
LOG = 'LOG',
|
|
33
|
-
/** Sends the HTTP response to the caller now, through `http.respond`; the run goes on. */
|
|
34
|
-
RESPOND = 'RESPOND',
|
|
35
|
-
STOP = 'STOP',
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export enum LogLevel {
|
|
39
|
-
INFO = 'info',
|
|
40
|
-
WARN = 'warn',
|
|
41
|
-
ERROR = 'error',
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export enum HttpMethod {
|
|
45
|
-
GET = 'GET',
|
|
46
|
-
POST = 'POST',
|
|
47
|
-
PUT = 'PUT',
|
|
48
|
-
PATCH = 'PATCH',
|
|
49
|
-
DELETE = 'DELETE',
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export enum StopStatus {
|
|
53
|
-
SUCCEEDED = 'SUCCEEDED',
|
|
54
|
-
FAILED = 'FAILED',
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface StepBase {
|
|
58
|
-
/** Stable, unique in the definition; outputs are read as `steps.<id>.output`. */
|
|
59
|
-
id: string;
|
|
60
|
-
name?: string;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export interface ConditionStep extends StepBase {
|
|
64
|
-
type: StepType.CONDITION;
|
|
65
|
-
if: ValueSource;
|
|
66
|
-
then: Step[];
|
|
67
|
-
else?: Step[];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface SwitchCase {
|
|
71
|
-
match: ValueSource;
|
|
72
|
-
steps: Step[];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface SwitchStep extends StepBase {
|
|
76
|
-
type: StepType.SWITCH;
|
|
77
|
-
value: ValueSource;
|
|
78
|
-
cases: SwitchCase[];
|
|
79
|
-
default?: Step[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Exactly one of `durationMs` and `until` (an ISO 8601 date); the host schedules the wake-up. */
|
|
83
|
-
export interface WaitStep extends StepBase {
|
|
84
|
-
type: StepType.WAIT;
|
|
85
|
-
durationMs?: ValueSource;
|
|
86
|
-
until?: ValueSource;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface SetStep extends StepBase {
|
|
90
|
-
type: StepType.SET;
|
|
91
|
-
/** Read back as `vars.<variable>`. */
|
|
92
|
-
variable: string;
|
|
93
|
-
value: ValueSource;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** JavaScript statements; the value of their `return` becomes the step's output. */
|
|
97
|
-
export interface CodeStep extends StepBase {
|
|
98
|
-
type: StepType.CODE;
|
|
99
|
-
source: string;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface HttpStep extends StepBase {
|
|
103
|
-
type: StepType.HTTP;
|
|
104
|
-
method: HttpMethod;
|
|
105
|
-
url: ValueSource;
|
|
106
|
-
headers?: Record<string, ValueSource>;
|
|
107
|
-
body?: ValueSource;
|
|
108
|
-
timeoutMs?: number;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export interface HostStep extends StepBase {
|
|
112
|
-
type: StepType.HOST;
|
|
113
|
-
action: string;
|
|
114
|
-
input: Record<string, ValueSource>;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface LogStep extends StepBase {
|
|
118
|
-
type: StepType.LOG;
|
|
119
|
-
level: LogLevel;
|
|
120
|
-
/** Resolved to a string; a non-string value is written as its JSON. */
|
|
121
|
-
message: ValueSource;
|
|
122
|
-
data?: ValueSource;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export interface RespondStep extends StepBase {
|
|
126
|
-
type: StepType.RESPOND;
|
|
127
|
-
/** Resolved to an integer HTTP status, 100 to 599. */
|
|
128
|
-
status: ValueSource;
|
|
129
|
-
headers?: Record<string, ValueSource>;
|
|
130
|
-
body?: ValueSource;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export interface StopStep extends StepBase {
|
|
134
|
-
type: StepType.STOP;
|
|
135
|
-
status: StopStatus;
|
|
136
|
-
output?: ValueSource;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export type Step =
|
|
140
|
-
| ConditionStep
|
|
141
|
-
| SwitchStep
|
|
142
|
-
| WaitStep
|
|
143
|
-
| SetStep
|
|
144
|
-
| CodeStep
|
|
145
|
-
| HttpStep
|
|
146
|
-
| HostStep
|
|
147
|
-
| LogStep
|
|
148
|
-
| RespondStep
|
|
149
|
-
| StopStep;
|
|
150
|
-
|
|
151
|
-
export interface RuntimeDefinition {
|
|
152
|
-
formatVersion: typeof CURRENT_FORMAT_VERSION;
|
|
153
|
-
accesses: AccessDeclaration[];
|
|
154
|
-
steps: Step[];
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** One action a product offers to its definitions (e-mail for Flow, Discord for Reflex…). */
|
|
158
|
-
export interface HostActionDefinition {
|
|
159
|
-
name: string;
|
|
160
|
-
/** Validates the input once every expression in it is resolved. */
|
|
161
|
-
inputSchema: ObjectSchema;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/** Supplied by each product; the core knows no Abyss service. */
|
|
165
|
-
export type HostActionCatalog = ReadonlyMap<string, HostActionDefinition>;
|
|
166
|
-
|
|
167
|
-
export interface DefinitionError {
|
|
168
|
-
/** JSON path of the offending node, e.g. `steps[2].then[0].action`. */
|
|
169
|
-
path: string;
|
|
170
|
-
message: string;
|
|
171
|
-
}
|
|
1
|
+
import type { ObjectSchema } from 'joi';
|
|
2
|
+
import type { AccessDeclaration } from '../access/access.types';
|
|
3
|
+
|
|
4
|
+
export const CURRENT_FORMAT_VERSION = 1;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A full JavaScript expression, evaluated by the code runner. Any other string may embed
|
|
8
|
+
* `{{ … }}` templates; an object whose only key is `$expression` is an expression.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExpressionValue {
|
|
11
|
+
$expression: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ValueSource =
|
|
15
|
+
| string
|
|
16
|
+
| number
|
|
17
|
+
| boolean
|
|
18
|
+
| null
|
|
19
|
+
| ExpressionValue
|
|
20
|
+
| ValueSource[]
|
|
21
|
+
| { [key: string]: ValueSource };
|
|
22
|
+
|
|
23
|
+
export enum StepType {
|
|
24
|
+
CONDITION = 'CONDITION',
|
|
25
|
+
SWITCH = 'SWITCH',
|
|
26
|
+
WAIT = 'WAIT',
|
|
27
|
+
SET = 'SET',
|
|
28
|
+
CODE = 'CODE',
|
|
29
|
+
HTTP = 'HTTP',
|
|
30
|
+
HOST = 'HOST',
|
|
31
|
+
/** Writes a log line kept with the run, through the host capability `log.write`. */
|
|
32
|
+
LOG = 'LOG',
|
|
33
|
+
/** Sends the HTTP response to the caller now, through `http.respond`; the run goes on. */
|
|
34
|
+
RESPOND = 'RESPOND',
|
|
35
|
+
STOP = 'STOP',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export enum LogLevel {
|
|
39
|
+
INFO = 'info',
|
|
40
|
+
WARN = 'warn',
|
|
41
|
+
ERROR = 'error',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export enum HttpMethod {
|
|
45
|
+
GET = 'GET',
|
|
46
|
+
POST = 'POST',
|
|
47
|
+
PUT = 'PUT',
|
|
48
|
+
PATCH = 'PATCH',
|
|
49
|
+
DELETE = 'DELETE',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export enum StopStatus {
|
|
53
|
+
SUCCEEDED = 'SUCCEEDED',
|
|
54
|
+
FAILED = 'FAILED',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
interface StepBase {
|
|
58
|
+
/** Stable, unique in the definition; outputs are read as `steps.<id>.output`. */
|
|
59
|
+
id: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ConditionStep extends StepBase {
|
|
64
|
+
type: StepType.CONDITION;
|
|
65
|
+
if: ValueSource;
|
|
66
|
+
then: Step[];
|
|
67
|
+
else?: Step[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SwitchCase {
|
|
71
|
+
match: ValueSource;
|
|
72
|
+
steps: Step[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface SwitchStep extends StepBase {
|
|
76
|
+
type: StepType.SWITCH;
|
|
77
|
+
value: ValueSource;
|
|
78
|
+
cases: SwitchCase[];
|
|
79
|
+
default?: Step[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Exactly one of `durationMs` and `until` (an ISO 8601 date); the host schedules the wake-up. */
|
|
83
|
+
export interface WaitStep extends StepBase {
|
|
84
|
+
type: StepType.WAIT;
|
|
85
|
+
durationMs?: ValueSource;
|
|
86
|
+
until?: ValueSource;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface SetStep extends StepBase {
|
|
90
|
+
type: StepType.SET;
|
|
91
|
+
/** Read back as `vars.<variable>`. */
|
|
92
|
+
variable: string;
|
|
93
|
+
value: ValueSource;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** JavaScript statements; the value of their `return` becomes the step's output. */
|
|
97
|
+
export interface CodeStep extends StepBase {
|
|
98
|
+
type: StepType.CODE;
|
|
99
|
+
source: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface HttpStep extends StepBase {
|
|
103
|
+
type: StepType.HTTP;
|
|
104
|
+
method: HttpMethod;
|
|
105
|
+
url: ValueSource;
|
|
106
|
+
headers?: Record<string, ValueSource>;
|
|
107
|
+
body?: ValueSource;
|
|
108
|
+
timeoutMs?: number;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface HostStep extends StepBase {
|
|
112
|
+
type: StepType.HOST;
|
|
113
|
+
action: string;
|
|
114
|
+
input: Record<string, ValueSource>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface LogStep extends StepBase {
|
|
118
|
+
type: StepType.LOG;
|
|
119
|
+
level: LogLevel;
|
|
120
|
+
/** Resolved to a string; a non-string value is written as its JSON. */
|
|
121
|
+
message: ValueSource;
|
|
122
|
+
data?: ValueSource;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface RespondStep extends StepBase {
|
|
126
|
+
type: StepType.RESPOND;
|
|
127
|
+
/** Resolved to an integer HTTP status, 100 to 599. */
|
|
128
|
+
status: ValueSource;
|
|
129
|
+
headers?: Record<string, ValueSource>;
|
|
130
|
+
body?: ValueSource;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface StopStep extends StepBase {
|
|
134
|
+
type: StepType.STOP;
|
|
135
|
+
status: StopStatus;
|
|
136
|
+
output?: ValueSource;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export type Step =
|
|
140
|
+
| ConditionStep
|
|
141
|
+
| SwitchStep
|
|
142
|
+
| WaitStep
|
|
143
|
+
| SetStep
|
|
144
|
+
| CodeStep
|
|
145
|
+
| HttpStep
|
|
146
|
+
| HostStep
|
|
147
|
+
| LogStep
|
|
148
|
+
| RespondStep
|
|
149
|
+
| StopStep;
|
|
150
|
+
|
|
151
|
+
export interface RuntimeDefinition {
|
|
152
|
+
formatVersion: typeof CURRENT_FORMAT_VERSION;
|
|
153
|
+
accesses: AccessDeclaration[];
|
|
154
|
+
steps: Step[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** One action a product offers to its definitions (e-mail for Flow, Discord for Reflex…). */
|
|
158
|
+
export interface HostActionDefinition {
|
|
159
|
+
name: string;
|
|
160
|
+
/** Validates the input once every expression in it is resolved. */
|
|
161
|
+
inputSchema: ObjectSchema;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Supplied by each product; the core knows no Abyss service. */
|
|
165
|
+
export type HostActionCatalog = ReadonlyMap<string, HostActionDefinition>;
|
|
166
|
+
|
|
167
|
+
export interface DefinitionError {
|
|
168
|
+
/** JSON path of the offending node, e.g. `steps[2].then[0].action`. */
|
|
169
|
+
path: string;
|
|
170
|
+
message: string;
|
|
171
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { JSONValue } from '../runner-protocol/execution-protocol.types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Host capabilities of a Discord bot Service. The host declares them in the execution's
|
|
5
|
+
* capabilities; client code reaches them through `abyss.discord.<name>(...)`, each helper existing
|
|
6
|
+
* only when its capability is granted. The argument shapes below are the `args` of the `call`.
|
|
7
|
+
*/
|
|
8
|
+
export enum DiscordCapability {
|
|
9
|
+
/** Answers the interaction. Arguments: a `DiscordMessage`. */
|
|
10
|
+
REPLY = 'discord.reply',
|
|
11
|
+
/** Edits the message a component interaction came from. Arguments: a `DiscordMessage`. */
|
|
12
|
+
UPDATE = 'discord.update',
|
|
13
|
+
/** Opens a modal, before the interaction is acknowledged. Arguments: `DiscordShowModalArgs`. */
|
|
14
|
+
SHOW_MODAL = 'discord.showModal',
|
|
15
|
+
/** Sends an additional message for the interaction. Arguments: a `DiscordMessage`. */
|
|
16
|
+
FOLLOW_UP = 'discord.followUp',
|
|
17
|
+
/** Posts a message in a channel as the bot. Arguments: `DiscordSendMessageArgs`. */
|
|
18
|
+
SEND_MESSAGE = 'discord.sendMessage',
|
|
19
|
+
/** Edits a message of the bot. Arguments: `DiscordEditMessageArgs`. */
|
|
20
|
+
EDIT_MESSAGE = 'discord.editMessage',
|
|
21
|
+
/** Deletes a message. Arguments: `DiscordDeleteMessageArgs`. */
|
|
22
|
+
DELETE_MESSAGE = 'discord.deleteMessage',
|
|
23
|
+
/** Gives a role to a member. Arguments: `DiscordRoleArgs`. */
|
|
24
|
+
ADD_ROLE = 'discord.addRole',
|
|
25
|
+
/** Takes a role from a member. Arguments: `DiscordRoleArgs`. */
|
|
26
|
+
REMOVE_ROLE = 'discord.removeRole',
|
|
27
|
+
/** Sends a direct message to a user. Arguments: `DiscordSendDirectMessageArgs`. */
|
|
28
|
+
SEND_DIRECT_MESSAGE = 'discord.sendDirectMessage',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Codes of the errors `abyss.discord.*` throws. The host fails the call with the message
|
|
33
|
+
* `<code>: <detail>` (or the bare code); the helper rethrows an `Error` named `DiscordError`
|
|
34
|
+
* whose `code` is the code and whose `message` is the detail.
|
|
35
|
+
*/
|
|
36
|
+
export enum DiscordErrorCode {
|
|
37
|
+
/** `showModal` after the interaction was acknowledged (more than 2.5 s after it arrived). */
|
|
38
|
+
MODAL_TOO_LATE = 'MODAL_TOO_LATE',
|
|
39
|
+
/** The bot's token is refused (circuit breaker open): no call was made to Discord. */
|
|
40
|
+
DISCORD_TOKEN_INVALID = 'DISCORD_TOKEN_INVALID',
|
|
41
|
+
/** Discord answered 403. */
|
|
42
|
+
DISCORD_FORBIDDEN = 'DISCORD_FORBIDDEN',
|
|
43
|
+
/** Discord answered 404. */
|
|
44
|
+
DISCORD_NOT_FOUND = 'DISCORD_NOT_FOUND',
|
|
45
|
+
/** Discord answered 429. */
|
|
46
|
+
DISCORD_RATE_LIMITED = 'DISCORD_RATE_LIMITED',
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Embed and component payloads are Discord's own JSON, relayed as is. */
|
|
50
|
+
export type DiscordJsonObject = { [key: string]: JSONValue };
|
|
51
|
+
|
|
52
|
+
export interface DiscordMessage {
|
|
53
|
+
content?: string;
|
|
54
|
+
embeds?: DiscordJsonObject[];
|
|
55
|
+
components?: DiscordJsonObject[];
|
|
56
|
+
/** Only the reply to an interaction can be ephemeral. */
|
|
57
|
+
ephemeral?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Text input style of a modal field. */
|
|
61
|
+
export enum DiscordModalFieldStyle {
|
|
62
|
+
SHORT = 'SHORT',
|
|
63
|
+
PARAGRAPH = 'PARAGRAPH',
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface DiscordModalField {
|
|
67
|
+
customId: string;
|
|
68
|
+
label: string;
|
|
69
|
+
style?: DiscordModalFieldStyle;
|
|
70
|
+
required?: boolean;
|
|
71
|
+
placeholder?: string;
|
|
72
|
+
value?: string;
|
|
73
|
+
minLength?: number;
|
|
74
|
+
maxLength?: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface DiscordShowModalArgs {
|
|
78
|
+
customId: string;
|
|
79
|
+
title: string;
|
|
80
|
+
fields: DiscordModalField[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface DiscordSendMessageArgs {
|
|
84
|
+
channelId: string;
|
|
85
|
+
message: DiscordMessage;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface DiscordEditMessageArgs {
|
|
89
|
+
channelId: string;
|
|
90
|
+
messageId: string;
|
|
91
|
+
message: DiscordMessage;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface DiscordDeleteMessageArgs {
|
|
95
|
+
channelId: string;
|
|
96
|
+
messageId: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface DiscordRoleArgs {
|
|
100
|
+
guildId: string;
|
|
101
|
+
userId: string;
|
|
102
|
+
roleId: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface DiscordSendDirectMessageArgs {
|
|
106
|
+
userId: string;
|
|
107
|
+
message: DiscordMessage;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The kind of interaction a function was started by. */
|
|
111
|
+
export enum DiscordInteractionKind {
|
|
112
|
+
COMMAND = 'COMMAND',
|
|
113
|
+
COMPONENT = 'COMPONENT',
|
|
114
|
+
MODAL = 'MODAL',
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Discord's interaction types (`type` of the payload) a bot's edge serves. */
|
|
118
|
+
export enum DiscordInteractionType {
|
|
119
|
+
PING = 1,
|
|
120
|
+
APPLICATION_COMMAND = 2,
|
|
121
|
+
MESSAGE_COMPONENT = 3,
|
|
122
|
+
MODAL_SUBMIT = 5,
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Discord's interaction callback types the edge answers with. */
|
|
126
|
+
export enum DiscordCallbackType {
|
|
127
|
+
PONG = 1,
|
|
128
|
+
CHANNEL_MESSAGE_WITH_SOURCE = 4,
|
|
129
|
+
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE = 5,
|
|
130
|
+
DEFERRED_UPDATE_MESSAGE = 6,
|
|
131
|
+
UPDATE_MESSAGE = 7,
|
|
132
|
+
MODAL = 9,
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Discord's message flag that makes a message visible to its recipient only. */
|
|
136
|
+
export const EPHEMERAL_FLAG = 64;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The `input` of a function triggered by a Discord interaction. The interaction token never
|
|
140
|
+
* appears here: it stays in the edge.
|
|
141
|
+
*/
|
|
142
|
+
export interface DiscordInteractionInput {
|
|
143
|
+
kind: DiscordInteractionKind;
|
|
144
|
+
/** Resolved option values, by option name. */
|
|
145
|
+
command?: { name: string; options: Record<string, string | number | boolean> };
|
|
146
|
+
component?: { customId: string; values?: string[] };
|
|
147
|
+
modal?: { customId: string; fields: Record<string, string> };
|
|
148
|
+
user: { id: string; username: string; globalName: string | null };
|
|
149
|
+
member?: { roles: string[]; permissions: string };
|
|
150
|
+
guildId?: string;
|
|
151
|
+
channelId?: string;
|
|
152
|
+
locale: string;
|
|
153
|
+
/** Discord's payload, without the interaction token. */
|
|
154
|
+
interaction: { id: string; applicationId: string; type: number; data: JSONValue };
|
|
155
|
+
}
|