@abyss-project/runtime 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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.
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).
@@ -198,3 +198,80 @@ export interface DiscordInteractionInput {
198
198
  data: JSONValue;
199
199
  };
200
200
  }
201
+ export declare enum DiscordEventType {
202
+ GUILD_MEMBER_ADD = "GUILD_MEMBER_ADD",
203
+ GUILD_MEMBER_REMOVE = "GUILD_MEMBER_REMOVE",
204
+ MESSAGE_CREATE = "MESSAGE_CREATE",
205
+ MESSAGE_REACTION_ADD = "MESSAGE_REACTION_ADD"
206
+ }
207
+ export interface DiscordMemberAddData {
208
+ user: {
209
+ id: string;
210
+ username: string;
211
+ globalName: string | null;
212
+ bot: boolean;
213
+ avatar: string | null;
214
+ };
215
+ roles: string[];
216
+ joinedAt: string | null;
217
+ pending: boolean;
218
+ }
219
+ export interface DiscordMemberRemoveData {
220
+ user: {
221
+ id: string;
222
+ username: string;
223
+ globalName: string | null;
224
+ bot: boolean;
225
+ };
226
+ }
227
+ export interface DiscordMessageCreateData {
228
+ id: string;
229
+ channelId: string;
230
+ author: {
231
+ id: string;
232
+ username: string;
233
+ globalName: string | null;
234
+ bot: boolean;
235
+ };
236
+ member: {
237
+ roles: string[];
238
+ nick: string | null;
239
+ } | null;
240
+ mentions: string[];
241
+ referencedMessageId: string | null;
242
+ attachmentCount: number;
243
+ createdAt: string;
244
+ content?: string;
245
+ }
246
+ export interface DiscordReactionAddData {
247
+ userId: string;
248
+ channelId: string;
249
+ messageId: string;
250
+ messageAuthorId: string | null;
251
+ member: {
252
+ roles: string[];
253
+ } | null;
254
+ emoji: {
255
+ id: string | null;
256
+ name: string | null;
257
+ animated: boolean;
258
+ };
259
+ }
260
+ export declare const DISCORD_EVENT_INPUT_KIND = "DISCORD_EVENT";
261
+ export interface DiscordEventInput {
262
+ kind: typeof DISCORD_EVENT_INPUT_KIND;
263
+ event: {
264
+ id: string;
265
+ type: DiscordEventType;
266
+ trigger: {
267
+ id: string;
268
+ name: string;
269
+ };
270
+ };
271
+ guildId: string;
272
+ receivedAt: string;
273
+ firedAt: string;
274
+ attempt: number;
275
+ data: DiscordMemberAddData | DiscordMemberRemoveData | DiscordMessageCreateData | DiscordReactionAddData;
276
+ }
277
+ 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.DiscordModalFieldStyle = exports.DiscordMentionType = exports.DiscordErrorCode = exports.DiscordCapability = void 0;
4
4
  var DiscordCapability;
5
5
  (function (DiscordCapability) {
6
6
  DiscordCapability["REPLY"] = "discord.reply";
@@ -61,4 +61,31 @@ var DiscordCallbackType;
61
61
  DiscordCallbackType[DiscordCallbackType["MODAL"] = 9] = "MODAL";
62
62
  })(DiscordCallbackType || (exports.DiscordCallbackType = DiscordCallbackType = {}));
63
63
  exports.EPHEMERAL_FLAG = 64;
64
+ var DiscordEventType;
65
+ (function (DiscordEventType) {
66
+ DiscordEventType["GUILD_MEMBER_ADD"] = "GUILD_MEMBER_ADD";
67
+ DiscordEventType["GUILD_MEMBER_REMOVE"] = "GUILD_MEMBER_REMOVE";
68
+ DiscordEventType["MESSAGE_CREATE"] = "MESSAGE_CREATE";
69
+ DiscordEventType["MESSAGE_REACTION_ADD"] = "MESSAGE_REACTION_ADD";
70
+ })(DiscordEventType || (exports.DiscordEventType = DiscordEventType = {}));
71
+ exports.DISCORD_EVENT_INPUT_KIND = 'DISCORD_EVENT';
72
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
73
+ const isDiscordEventInput = (value) => {
74
+ if (!isRecord(value) || value.kind !== exports.DISCORD_EVENT_INPUT_KIND) {
75
+ return false;
76
+ }
77
+ const { event } = value;
78
+ return (isRecord(event) &&
79
+ typeof event.id === 'string' &&
80
+ Object.values(DiscordEventType).includes(event.type) &&
81
+ isRecord(event.trigger) &&
82
+ typeof event.trigger.id === 'string' &&
83
+ typeof event.trigger.name === 'string' &&
84
+ typeof value.guildId === 'string' &&
85
+ typeof value.receivedAt === 'string' &&
86
+ typeof value.firedAt === 'string' &&
87
+ typeof value.attempt === 'number' &&
88
+ isRecord(value.data));
89
+ };
90
+ exports.isDiscordEventInput = isDiscordEventInput;
64
91
  //# 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,iBA6BX;AA7BD,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;AAChC,CAAC,EA7BW,iBAAiB,iCAAjB,iBAAiB,QA6B5B;AAOD,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;AA2BD,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,iDAAuB,CAAA;AACz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,CAAA;IAEvD,sEAAiD,CAAA;IAEjD,8EAAyD,CAAA;IAEzD,0DAAqC,CAAA;AACvC,CAAC,EAXW,iBAAiB,iCAAjB,iBAAiB,QAW5B;AA+CD,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;IACrB,uCAAmB,CAAA;AACrB,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B"}
1
+ {"version":3,"file":"schedule.types.js","sourceRoot":"","sources":["../../src/schedule/schedule.types.ts"],"names":[],"mappings":";;;AAQA,IAAY,kBAOX;AAPD,WAAY,kBAAkB;IAE5B,uDAAiC,CAAA;IAEjC,iDAA2B,CAAA;IAE3B,yDAAmC,CAAA;AACrC,CAAC,EAPW,kBAAkB,kCAAlB,kBAAkB,QAO7B;AAOD,IAAY,iBAWX;AAXD,WAAY,iBAAiB;IAE3B,oEAA+C,CAAA;IAE/C,4EAAuD,CAAA;IAEvD,sEAAiD,CAAA;IAEjD,8EAAyD,CAAA;IAEzD,0DAAqC,CAAA;AACvC,CAAC,EAXW,iBAAiB,iCAAjB,iBAAiB,QAW5B;AAiDD,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,yCAAqB,CAAA;IACrB,uCAAmB,CAAA;AACrB,CAAC,EAHW,gBAAgB,gCAAhB,gBAAgB,QAG3B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abyss-project/runtime",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Abyss automation core: definitions, interpreter, runner protocol",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,53 +1,66 @@
1
- import { builtinModules } from 'module';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
4
-
5
- const SRC_DIR = path.resolve(__dirname, '..');
6
- const SERVER_DIR = path.join(SRC_DIR, 'server');
7
- const TESTS_DIR = path.join(SRC_DIR, '__tests__');
8
-
9
- // `ws` and every Node built-in module (`fs`, `net`, `http`, `node:*`...) are forbidden outside
10
- // `src/server`, so that the package root stays usable in a browser.
11
- const FORBIDDEN = new Set<string>(['ws', ...builtinModules]);
12
-
13
- const walkTsFiles = (dir: string): string[] =>
14
- fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
15
- const full = path.join(dir, entry.name);
16
- if (entry.isDirectory()) {
17
- return full === SERVER_DIR || full === TESTS_DIR ? [] : walkTsFiles(full);
18
- }
19
- return entry.name.endsWith('.ts') && !entry.name.endsWith('.d.ts') ? [full] : [];
20
- });
21
-
22
- const IMPORT_PATTERNS = [
23
- /\bfrom\s*['"]([^'"]+)['"]/g,
24
- /\bimport\s*['"]([^'"]+)['"]/g,
25
- /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
26
- /\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
27
- ];
28
-
29
- const importedSpecifiers = (text: string): string[] =>
30
- IMPORT_PATTERNS.flatMap((pattern) => [...text.matchAll(pattern)].map((match) => match[1]));
31
-
32
- const isForbidden = (specifier: string): boolean => {
33
- const bare = specifier.startsWith('node:') ? specifier.slice('node:'.length) : specifier;
34
- return FORBIDDEN.has(bare) || FORBIDDEN.has(bare.split('/')[0]);
35
- };
36
-
37
- describe('browser-compatible package root', () => {
38
- it('imports no Node built-in nor ws outside src/server', () => {
39
- const offenders = walkTsFiles(SRC_DIR).flatMap((file) =>
40
- importedSpecifiers(fs.readFileSync(file, 'utf8'))
41
- .filter(isForbidden)
42
- .map((specifier) => `${path.relative(SRC_DIR, file)} imports ${specifier}`),
43
- );
44
- expect(offenders).toEqual([]);
45
- });
46
-
47
- it('detects forbidden imports (guard sanity)', () => {
48
- const source = "import { WebSocket } from 'ws';\nconst n = require('node:net');";
49
- expect(importedSpecifiers(source)).toEqual(['ws', 'node:net']);
50
- expect(['ws', 'node:net', 'fs/promises', 'http'].every(isForbidden)).toBe(true);
51
- expect(['joi', './steps', '../access'].some(isForbidden)).toBe(false);
52
- });
53
- });
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
+ });
@@ -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
+ });