@abyss-project/reflex 6.4.0 → 6.6.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.
Files changed (133) hide show
  1. package/.eslintrc.js +32 -32
  2. package/.prettierrc +5 -5
  3. package/README.md +15 -15
  4. package/dist/api/function-run.api.d.ts +2 -1
  5. package/dist/api/function-run.api.js +3 -1
  6. package/dist/api/function-run.api.js.map +1 -1
  7. package/dist/discord/discord-command-tree.d.ts +5 -0
  8. package/dist/discord/discord-command-tree.js +38 -0
  9. package/dist/discord/discord-command-tree.js.map +1 -0
  10. package/dist/discord/discord-event-filter-cases.js +27 -11
  11. package/dist/discord/discord-event-filter-cases.js.map +1 -1
  12. package/dist/discord/discord-event-filters.js +7 -3
  13. package/dist/discord/discord-event-filters.js.map +1 -1
  14. package/dist/discord/discord-event-intents.d.ts +8 -2
  15. package/dist/discord/discord-event-intents.js +13 -2
  16. package/dist/discord/discord-event-intents.js.map +1 -1
  17. package/dist/discord/index.d.ts +1 -0
  18. package/dist/discord/index.js +1 -0
  19. package/dist/discord/index.js.map +1 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +1 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/types/enum/discord-command-node-type.enum.d.ts +5 -0
  24. package/dist/types/enum/discord-command-node-type.enum.js +10 -0
  25. package/dist/types/enum/discord-command-node-type.enum.js.map +1 -0
  26. package/dist/types/enum/discord-command-type.enum.d.ts +5 -0
  27. package/dist/types/enum/discord-command-type.enum.js +10 -0
  28. package/dist/types/enum/discord-command-type.enum.js.map +1 -0
  29. package/dist/types/enum/discord-event-type.enum.d.ts +3 -1
  30. package/dist/types/enum/discord-event-type.enum.js +2 -0
  31. package/dist/types/enum/discord-event-type.enum.js.map +1 -1
  32. package/dist/types/enum/index.d.ts +2 -0
  33. package/dist/types/enum/index.js +2 -0
  34. package/dist/types/enum/index.js.map +1 -1
  35. package/dist/types/enum/reflex-error-code.enum.d.ts +10 -0
  36. package/dist/types/enum/reflex-error-code.enum.js +10 -0
  37. package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
  38. package/dist/types/interface/api/requests/function-run.request.d.ts +8 -0
  39. package/dist/types/interface/api/requests/service-discord.request.d.ts +7 -3
  40. package/dist/types/interface/api/responses/function-run.response.d.ts +8 -0
  41. package/dist/types/interface/models/reflex-discord.model.d.ts +18 -2
  42. package/dist/types/interface/models/reflex-discord.model.js +4 -0
  43. package/dist/types/interface/models/reflex-discord.model.js.map +1 -1
  44. package/dist/types/interface/models/reflex-run.model.d.ts +4 -0
  45. package/dist/types/interface/models/reflex-run.model.js +4 -1
  46. package/dist/types/interface/models/reflex-run.model.js.map +1 -1
  47. package/jest.config.ts +11 -11
  48. package/package.json +1 -1
  49. package/src/api/alert-rule.api.test.ts +72 -72
  50. package/src/api/alert-rule.api.ts +57 -57
  51. package/src/api/application-insights.api.test.ts +42 -42
  52. package/src/api/application-insights.api.ts +38 -38
  53. package/src/api/application-run-settings.api.test.ts +62 -62
  54. package/src/api/application-run-settings.api.ts +30 -30
  55. package/src/api/function-access.api.ts +87 -87
  56. package/src/api/function-insights.api.test.ts +27 -27
  57. package/src/api/function-insights.api.ts +18 -18
  58. package/src/api/function-run.api.ts +19 -0
  59. package/src/api/function-settings.api.ts +96 -96
  60. package/src/api/function-template.api.test.ts +72 -72
  61. package/src/api/function-template.api.ts +52 -52
  62. package/src/api/function-test.api.ts +34 -34
  63. package/src/api/function-version.api.ts +66 -66
  64. package/src/api/function.api.test.ts +346 -346
  65. package/src/api/function.api.ts +62 -62
  66. package/src/api/health.api.ts +10 -10
  67. package/src/api/route-stats.api.test.ts +45 -45
  68. package/src/api/route-stats.api.ts +36 -36
  69. package/src/api/service-completion-webhook.api.test.ts +97 -97
  70. package/src/api/service-completion-webhook.api.ts +39 -39
  71. package/src/api/service-configuration.api.ts +16 -16
  72. package/src/api/service-consumer.api.test.ts +104 -104
  73. package/src/api/service-consumer.api.ts +90 -90
  74. package/src/api/service-deployment.api.ts +79 -79
  75. package/src/api/service-discord-event.api.test.ts +106 -106
  76. package/src/api/service-discord-event.api.ts +78 -78
  77. package/src/api/service-discord.api.test.ts +178 -178
  78. package/src/api/service-discord.api.ts +222 -222
  79. package/src/api/service-insights.api.test.ts +36 -36
  80. package/src/api/service-insights.api.ts +42 -42
  81. package/src/api/service-limits.api.test.ts +100 -100
  82. package/src/api/service-limits.api.ts +37 -37
  83. package/src/api/service-openapi.api.test.ts +52 -52
  84. package/src/api/service-openapi.api.ts +21 -21
  85. package/src/api/service-route.api.ts +74 -74
  86. package/src/api/service-task.api.test.ts +140 -140
  87. package/src/api/service-task.api.ts +141 -141
  88. package/src/api/service-version.api.ts +54 -54
  89. package/src/api/service.api.test.ts +220 -220
  90. package/src/api/service.api.ts +55 -55
  91. package/src/api/storage-surplus.admin.api.test.ts +66 -66
  92. package/src/api/storage-surplus.admin.api.ts +45 -45
  93. package/src/discord/discord-command-tree.test.ts +47 -0
  94. package/src/discord/discord-command-tree.ts +60 -0
  95. package/src/discord/discord-event-filter-cases.ts +299 -261
  96. package/src/discord/discord-event-filters.test.ts +120 -91
  97. package/src/discord/discord-event-filters.ts +103 -95
  98. package/src/discord/discord-event-intents.test.ts +139 -112
  99. package/src/discord/discord-event-intents.ts +80 -55
  100. package/src/discord/index.ts +4 -3
  101. package/src/index.test.ts +104 -104
  102. package/src/index.ts +2 -0
  103. package/src/insights/index.ts +1 -1
  104. package/src/insights/percentiles.test.ts +75 -75
  105. package/src/insights/percentiles.ts +37 -37
  106. package/src/types/enum/discord-command-node-type.enum.ts +10 -0
  107. package/src/types/enum/discord-command-type.enum.ts +9 -0
  108. package/src/types/enum/discord-event-type.enum.ts +4 -0
  109. package/src/types/enum/discord-host-action.enum.ts +37 -37
  110. package/src/types/enum/index.ts +2 -0
  111. package/src/types/enum/reflex-error-code.enum.ts +112 -89
  112. package/src/types/interface/api/requests/application-run-settings.request.ts +13 -13
  113. package/src/types/interface/api/requests/function-run.request.ts +53 -42
  114. package/src/types/interface/api/requests/function-settings.request.ts +50 -50
  115. package/src/types/interface/api/requests/index.ts +25 -25
  116. package/src/types/interface/api/requests/service-discord.request.ts +168 -155
  117. package/src/types/interface/api/requests/service.request.ts +48 -48
  118. package/src/types/interface/api/requests/storage-surplus.admin.request.ts +12 -12
  119. package/src/types/interface/api/responses/function-run.response.ts +35 -23
  120. package/src/types/interface/api/responses/function-settings.response.ts +57 -57
  121. package/src/types/interface/api/responses/index.ts +25 -25
  122. package/src/types/interface/api/responses/storage-surplus.admin.response.ts +10 -10
  123. package/src/types/interface/models/index.ts +29 -29
  124. package/src/types/interface/models/reflex-discord.model.ts +249 -208
  125. package/src/types/interface/models/reflex-price-list.model.ts +22 -22
  126. package/src/types/interface/models/reflex-run-retention.model.ts +24 -24
  127. package/src/types/interface/models/reflex-run-settings.model.ts +39 -39
  128. package/src/types/interface/models/reflex-run.model.ts +317 -309
  129. package/src/types/interface/models/reflex-service-deployment.model.ts +48 -48
  130. package/src/types/interface/models/reflex-service.model.ts +47 -47
  131. package/src/types/interface/models/reflex-storage-surplus.model.ts +23 -23
  132. package/tsconfig.check.json +15 -15
  133. package/tsconfig.json +35 -35
@@ -1,112 +1,139 @@
1
- import { DiscordEventType } from '../types/enum';
2
- import type { IReflexDiscordEventFilters } from '../types/interface/models';
3
- import { DiscordGatewayIntent, intentsOf, privilegedIntentsOf } from './discord-event-intents';
4
-
5
- const trigger = (
6
- eventType: DiscordEventType,
7
- options: { filters?: IReflexDiscordEventFilters; includeContent?: boolean } = {},
8
- ) => ({
9
- eventType,
10
- filters: options.filters ?? {},
11
- includeContent: options.includeContent ?? false,
12
- });
13
-
14
- describe('intentsOf', () => {
15
- it('has the Discord bit of each intent', () => {
16
- expect(DiscordGatewayIntent.GUILD_MEMBERS).toBe(2);
17
- expect(DiscordGatewayIntent.GUILD_MESSAGES).toBe(512);
18
- expect(DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS).toBe(1024);
19
- expect(DiscordGatewayIntent.MESSAGE_CONTENT).toBe(32768);
20
- });
21
-
22
- it('is 0 without a trigger, so the bot keeps identifying with no intent', () => {
23
- expect(intentsOf([])).toBe(0);
24
- expect(privilegedIntentsOf([])).toEqual([]);
25
- });
26
-
27
- it.each([
28
- [DiscordEventType.GUILD_MEMBER_ADD, DiscordGatewayIntent.GUILD_MEMBERS],
29
- [DiscordEventType.GUILD_MEMBER_REMOVE, DiscordGatewayIntent.GUILD_MEMBERS],
30
- [DiscordEventType.MESSAGE_CREATE, DiscordGatewayIntent.GUILD_MESSAGES],
31
- [DiscordEventType.MESSAGE_REACTION_ADD, DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS],
32
- ])('%s asks for its one intent and never GUILDS', (eventType, intent) => {
33
- expect(intentsOf([trigger(eventType)])).toBe(intent);
34
- });
35
-
36
- it('adds MESSAGE_CONTENT to MESSAGE_CREATE with includeContent', () => {
37
- expect(intentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true })])).toBe(
38
- DiscordGatewayIntent.GUILD_MESSAGES | DiscordGatewayIntent.MESSAGE_CONTENT,
39
- );
40
- });
41
-
42
- it('adds MESSAGE_CONTENT to MESSAGE_CREATE with a prefix filter', () => {
43
- expect(
44
- intentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { filters: { contentPrefix: '!' } })]),
45
- ).toBe(DiscordGatewayIntent.GUILD_MESSAGES | DiscordGatewayIntent.MESSAGE_CONTENT);
46
- });
47
-
48
- it('does not add MESSAGE_CONTENT for an empty prefix', () => {
49
- expect(
50
- intentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { filters: { contentPrefix: '' } })]),
51
- ).toBe(DiscordGatewayIntent.GUILD_MESSAGES);
52
- });
53
-
54
- it('does not add MESSAGE_CONTENT to a reaction, whatever it carries', () => {
55
- expect(
56
- intentsOf([
57
- trigger(DiscordEventType.MESSAGE_REACTION_ADD, {
58
- filters: { contentPrefix: '!' },
59
- includeContent: true,
60
- }),
61
- ]),
62
- ).toBe(DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS);
63
- });
64
-
65
- it('unions the bits of several triggers', () => {
66
- const events = [
67
- trigger(DiscordEventType.GUILD_MEMBER_ADD),
68
- trigger(DiscordEventType.GUILD_MEMBER_REMOVE),
69
- trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true }),
70
- trigger(DiscordEventType.MESSAGE_REACTION_ADD),
71
- ];
72
- expect(intentsOf(events)).toBe(2 | 512 | 1024 | 32768);
73
- });
74
- });
75
-
76
- describe('privilegedIntentsOf', () => {
77
- it('names GUILD_MEMBERS for a member event', () => {
78
- expect(privilegedIntentsOf([trigger(DiscordEventType.GUILD_MEMBER_ADD)])).toEqual([
79
- DiscordGatewayIntent.GUILD_MEMBERS,
80
- ]);
81
- });
82
-
83
- it('names nothing for messages without content and for reactions', () => {
84
- expect(
85
- privilegedIntentsOf([
86
- trigger(DiscordEventType.MESSAGE_CREATE),
87
- trigger(DiscordEventType.MESSAGE_REACTION_ADD),
88
- ]),
89
- ).toEqual([]);
90
- });
91
-
92
- it('names MESSAGE_CONTENT for a message with content or a prefix', () => {
93
- expect(
94
- privilegedIntentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true })]),
95
- ).toEqual([DiscordGatewayIntent.MESSAGE_CONTENT]);
96
- expect(
97
- privilegedIntentsOf([
98
- trigger(DiscordEventType.MESSAGE_CREATE, { filters: { contentPrefix: '!' } }),
99
- ]),
100
- ).toEqual([DiscordGatewayIntent.MESSAGE_CONTENT]);
101
- });
102
-
103
- it('lists each privileged intent once, in bit order', () => {
104
- expect(
105
- privilegedIntentsOf([
106
- trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true }),
107
- trigger(DiscordEventType.GUILD_MEMBER_ADD),
108
- trigger(DiscordEventType.GUILD_MEMBER_REMOVE),
109
- ]),
110
- ).toEqual([DiscordGatewayIntent.GUILD_MEMBERS, DiscordGatewayIntent.MESSAGE_CONTENT]);
111
- });
112
- });
1
+ import { DiscordEventType } from '../types/enum';
2
+ import type { IReflexDiscordEventFilters } from '../types/interface/models';
3
+ import { DiscordGatewayIntent, intentsOf, privilegedIntentsOf } from './discord-event-intents';
4
+
5
+ const trigger = (
6
+ eventType: DiscordEventType,
7
+ options: { filters?: IReflexDiscordEventFilters; includeContent?: boolean } = {},
8
+ ) => ({
9
+ eventType,
10
+ filters: options.filters ?? {},
11
+ includeContent: options.includeContent ?? false,
12
+ });
13
+
14
+ describe('intentsOf', () => {
15
+ it('has the Discord bit of each intent', () => {
16
+ expect(DiscordGatewayIntent.GUILD_MEMBERS).toBe(2);
17
+ expect(DiscordGatewayIntent.GUILD_MESSAGES).toBe(512);
18
+ expect(DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS).toBe(1024);
19
+ expect(DiscordGatewayIntent.MESSAGE_CONTENT).toBe(32768);
20
+ expect(DiscordGatewayIntent.GUILD_MESSAGE_POLLS).toBe(16777216);
21
+ });
22
+
23
+ it.each([DiscordEventType.MESSAGE_POLL_VOTE_ADD, DiscordEventType.MESSAGE_POLL_VOTE_REMOVE])(
24
+ '%s asks for GUILD_MESSAGE_POLLS only when the bot turned poll votes on',
25
+ (eventType) => {
26
+ expect(intentsOf([trigger(eventType)])).toBe(0);
27
+ expect(intentsOf([trigger(eventType)], { pollVotesEnabled: false })).toBe(0);
28
+ expect(intentsOf([trigger(eventType)], { pollVotesEnabled: true })).toBe(
29
+ DiscordGatewayIntent.GUILD_MESSAGE_POLLS,
30
+ );
31
+ },
32
+ );
33
+
34
+ it('asks for no poll intent when poll votes are on but no trigger is a poll vote', () => {
35
+ expect(intentsOf([trigger(DiscordEventType.MESSAGE_CREATE)], { pollVotesEnabled: true })).toBe(
36
+ DiscordGatewayIntent.GUILD_MESSAGES,
37
+ );
38
+ });
39
+
40
+ it('keeps the other triggers when poll votes are off', () => {
41
+ expect(
42
+ intentsOf([
43
+ trigger(DiscordEventType.MESSAGE_REACTION_ADD),
44
+ trigger(DiscordEventType.MESSAGE_POLL_VOTE_ADD),
45
+ ]),
46
+ ).toBe(DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS);
47
+ });
48
+
49
+ it('is 0 without a trigger, so the bot keeps identifying with no intent', () => {
50
+ expect(intentsOf([])).toBe(0);
51
+ expect(privilegedIntentsOf([])).toEqual([]);
52
+ });
53
+
54
+ it.each([
55
+ [DiscordEventType.GUILD_MEMBER_ADD, DiscordGatewayIntent.GUILD_MEMBERS],
56
+ [DiscordEventType.GUILD_MEMBER_REMOVE, DiscordGatewayIntent.GUILD_MEMBERS],
57
+ [DiscordEventType.MESSAGE_CREATE, DiscordGatewayIntent.GUILD_MESSAGES],
58
+ [DiscordEventType.MESSAGE_REACTION_ADD, DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS],
59
+ ])('%s asks for its one intent and never GUILDS', (eventType, intent) => {
60
+ expect(intentsOf([trigger(eventType)])).toBe(intent);
61
+ });
62
+
63
+ it('adds MESSAGE_CONTENT to MESSAGE_CREATE with includeContent', () => {
64
+ expect(intentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true })])).toBe(
65
+ DiscordGatewayIntent.GUILD_MESSAGES | DiscordGatewayIntent.MESSAGE_CONTENT,
66
+ );
67
+ });
68
+
69
+ it('adds MESSAGE_CONTENT to MESSAGE_CREATE with a prefix filter', () => {
70
+ expect(
71
+ intentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { filters: { contentPrefix: '!' } })]),
72
+ ).toBe(DiscordGatewayIntent.GUILD_MESSAGES | DiscordGatewayIntent.MESSAGE_CONTENT);
73
+ });
74
+
75
+ it('does not add MESSAGE_CONTENT for an empty prefix', () => {
76
+ expect(
77
+ intentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { filters: { contentPrefix: '' } })]),
78
+ ).toBe(DiscordGatewayIntent.GUILD_MESSAGES);
79
+ });
80
+
81
+ it('does not add MESSAGE_CONTENT to a reaction, whatever it carries', () => {
82
+ expect(
83
+ intentsOf([
84
+ trigger(DiscordEventType.MESSAGE_REACTION_ADD, {
85
+ filters: { contentPrefix: '!' },
86
+ includeContent: true,
87
+ }),
88
+ ]),
89
+ ).toBe(DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS);
90
+ });
91
+
92
+ it('unions the bits of several triggers', () => {
93
+ const events = [
94
+ trigger(DiscordEventType.GUILD_MEMBER_ADD),
95
+ trigger(DiscordEventType.GUILD_MEMBER_REMOVE),
96
+ trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true }),
97
+ trigger(DiscordEventType.MESSAGE_REACTION_ADD),
98
+ ];
99
+ expect(intentsOf(events)).toBe(2 | 512 | 1024 | 32768);
100
+ });
101
+ });
102
+
103
+ describe('privilegedIntentsOf', () => {
104
+ it('names GUILD_MEMBERS for a member event', () => {
105
+ expect(privilegedIntentsOf([trigger(DiscordEventType.GUILD_MEMBER_ADD)])).toEqual([
106
+ DiscordGatewayIntent.GUILD_MEMBERS,
107
+ ]);
108
+ });
109
+
110
+ it('names nothing for messages without content and for reactions', () => {
111
+ expect(
112
+ privilegedIntentsOf([
113
+ trigger(DiscordEventType.MESSAGE_CREATE),
114
+ trigger(DiscordEventType.MESSAGE_REACTION_ADD),
115
+ ]),
116
+ ).toEqual([]);
117
+ });
118
+
119
+ it('names MESSAGE_CONTENT for a message with content or a prefix', () => {
120
+ expect(
121
+ privilegedIntentsOf([trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true })]),
122
+ ).toEqual([DiscordGatewayIntent.MESSAGE_CONTENT]);
123
+ expect(
124
+ privilegedIntentsOf([
125
+ trigger(DiscordEventType.MESSAGE_CREATE, { filters: { contentPrefix: '!' } }),
126
+ ]),
127
+ ).toEqual([DiscordGatewayIntent.MESSAGE_CONTENT]);
128
+ });
129
+
130
+ it('lists each privileged intent once, in bit order', () => {
131
+ expect(
132
+ privilegedIntentsOf([
133
+ trigger(DiscordEventType.MESSAGE_CREATE, { includeContent: true }),
134
+ trigger(DiscordEventType.GUILD_MEMBER_ADD),
135
+ trigger(DiscordEventType.GUILD_MEMBER_REMOVE),
136
+ ]),
137
+ ).toEqual([DiscordGatewayIntent.GUILD_MEMBERS, DiscordGatewayIntent.MESSAGE_CONTENT]);
138
+ });
139
+ });
@@ -1,55 +1,80 @@
1
- import { DiscordEventType } from '../types/enum';
2
- import type { IReflexDiscordEvent } from '../types/interface/models';
3
-
4
- /** The Gateway intents the Discord events need, as Discord numbers their bits. */
5
- export enum DiscordGatewayIntent {
6
- /** Member arrival and departure. Privileged. */
7
- GUILD_MEMBERS = 1 << 1,
8
- GUILD_MESSAGES = 1 << 9,
9
- GUILD_MESSAGE_REACTIONS = 1 << 10,
10
- /** The content of a message. Privileged. */
11
- MESSAGE_CONTENT = 1 << 15,
12
- }
13
-
14
- /** The intents Discord asks the bot owner to enable in the portal (and to have verified past 100 servers). */
15
- export const PRIVILEGED_DISCORD_GATEWAY_INTENTS: readonly DiscordGatewayIntent[] = [
16
- DiscordGatewayIntent.GUILD_MEMBERS,
17
- DiscordGatewayIntent.MESSAGE_CONTENT,
18
- ];
19
-
20
- /** The intent each event type needs by itself. `GUILDS` is never asked: the four events do not need its large packets. */
21
- export const DISCORD_EVENT_BASE_INTENT: Record<DiscordEventType, DiscordGatewayIntent> = {
22
- [DiscordEventType.GUILD_MEMBER_ADD]: DiscordGatewayIntent.GUILD_MEMBERS,
23
- [DiscordEventType.GUILD_MEMBER_REMOVE]: DiscordGatewayIntent.GUILD_MEMBERS,
24
- [DiscordEventType.MESSAGE_CREATE]: DiscordGatewayIntent.GUILD_MESSAGES,
25
- [DiscordEventType.MESSAGE_REACTION_ADD]: DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS,
26
- };
27
-
28
- type IntentSource = Pick<IReflexDiscordEvent, 'eventType' | 'filters' | 'includeContent'>;
29
-
30
- /** True when the trigger reads the content of a message: it asks for it, or filters on a prefix. */
31
- const needsMessageContent = (event: IntentSource): boolean =>
32
- event.eventType === DiscordEventType.MESSAGE_CREATE &&
33
- (event.includeContent || (event.filters.contentPrefix ?? '') !== '');
34
-
35
- /** The intents one trigger needs. */
36
- const intentListOf = (event: IntentSource): DiscordGatewayIntent[] => {
37
- const intents = [DISCORD_EVENT_BASE_INTENT[event.eventType]];
38
- if (needsMessageContent(event)) {
39
- intents.push(DiscordGatewayIntent.MESSAGE_CONTENT);
40
- }
41
- return intents;
42
- };
43
-
44
- /** The `intents` of IDENTIFY for the triggers of a version: the union of their bits, 0 without a trigger. */
45
- export const intentsOf = (events: readonly IntentSource[]): number =>
46
- events.reduce(
47
- (bits, event) => intentListOf(event).reduce((acc, intent) => acc | intent, bits),
48
- 0,
49
- );
50
-
51
- /** The privileged intents the triggers need, in bit order, without duplicates. */
52
- export const privilegedIntentsOf = (events: readonly IntentSource[]): DiscordGatewayIntent[] => {
53
- const bits = intentsOf(events);
54
- return PRIVILEGED_DISCORD_GATEWAY_INTENTS.filter((intent) => (bits & intent) !== 0);
55
- };
1
+ import { DiscordEventType } from '../types/enum';
2
+ import type { IReflexDiscordEvent } from '../types/interface/models';
3
+
4
+ /** The Gateway intents the Discord events need, as Discord numbers their bits. */
5
+ export enum DiscordGatewayIntent {
6
+ /** Member arrival and departure. Privileged. */
7
+ GUILD_MEMBERS = 1 << 1,
8
+ GUILD_MESSAGES = 1 << 9,
9
+ GUILD_MESSAGE_REACTIONS = 1 << 10,
10
+ /** The content of a message. Privileged. */
11
+ MESSAGE_CONTENT = 1 << 15,
12
+ /** Poll votes in a server. Not privileged, but asked only when the bot turns poll votes on (card 943). */
13
+ GUILD_MESSAGE_POLLS = 1 << 24,
14
+ }
15
+
16
+ /** The intents Discord asks the bot owner to enable in the portal (and to have verified past 100 servers). */
17
+ export const PRIVILEGED_DISCORD_GATEWAY_INTENTS: readonly DiscordGatewayIntent[] = [
18
+ DiscordGatewayIntent.GUILD_MEMBERS,
19
+ DiscordGatewayIntent.MESSAGE_CONTENT,
20
+ ];
21
+
22
+ /** The intent each event type needs by itself. `GUILDS` is never asked: the four events do not need its large packets. */
23
+ export const DISCORD_EVENT_BASE_INTENT: Record<DiscordEventType, DiscordGatewayIntent> = {
24
+ [DiscordEventType.GUILD_MEMBER_ADD]: DiscordGatewayIntent.GUILD_MEMBERS,
25
+ [DiscordEventType.GUILD_MEMBER_REMOVE]: DiscordGatewayIntent.GUILD_MEMBERS,
26
+ [DiscordEventType.MESSAGE_CREATE]: DiscordGatewayIntent.GUILD_MESSAGES,
27
+ [DiscordEventType.MESSAGE_REACTION_ADD]: DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS,
28
+ [DiscordEventType.MESSAGE_POLL_VOTE_ADD]: DiscordGatewayIntent.GUILD_MESSAGE_POLLS,
29
+ [DiscordEventType.MESSAGE_POLL_VOTE_REMOVE]: DiscordGatewayIntent.GUILD_MESSAGE_POLLS,
30
+ };
31
+
32
+ /** The event types of poll votes: their intent is asked only when the bot turns poll votes on. */
33
+ export const DISCORD_POLL_VOTE_EVENT_TYPES: readonly DiscordEventType[] = [
34
+ DiscordEventType.MESSAGE_POLL_VOTE_ADD,
35
+ DiscordEventType.MESSAGE_POLL_VOTE_REMOVE,
36
+ ];
37
+
38
+ /** True for a poll vote event type. */
39
+ export const isPollVoteEventType = (eventType: DiscordEventType): boolean =>
40
+ DISCORD_POLL_VOTE_EVENT_TYPES.includes(eventType);
41
+
42
+ /** What the bot of an environment allows beyond its triggers. */
43
+ export interface DiscordIntentOptions {
44
+ /** The bot turned poll votes on; false by default: a poll trigger then asks for nothing. */
45
+ pollVotesEnabled?: boolean;
46
+ }
47
+
48
+ type IntentSource = Pick<IReflexDiscordEvent, 'eventType' | 'filters' | 'includeContent'>;
49
+
50
+ /** True when the trigger reads the content of a message: it asks for it, or filters on a prefix. */
51
+ const needsMessageContent = (event: IntentSource): boolean =>
52
+ event.eventType === DiscordEventType.MESSAGE_CREATE &&
53
+ (event.includeContent || (event.filters.contentPrefix ?? '') !== '');
54
+
55
+ /** The intents one trigger needs. */
56
+ const intentListOf = (event: IntentSource): DiscordGatewayIntent[] => {
57
+ const intents = [DISCORD_EVENT_BASE_INTENT[event.eventType]];
58
+ if (needsMessageContent(event)) {
59
+ intents.push(DiscordGatewayIntent.MESSAGE_CONTENT);
60
+ }
61
+ return intents;
62
+ };
63
+
64
+ /**
65
+ * The `intents` of IDENTIFY for the triggers of a version: the union of their bits, 0 without a trigger. A poll
66
+ * vote trigger counts only when the bot turned poll votes on.
67
+ */
68
+ export const intentsOf = (
69
+ events: readonly IntentSource[],
70
+ options: DiscordIntentOptions = {},
71
+ ): number =>
72
+ events
73
+ .filter((event) => options.pollVotesEnabled === true || !isPollVoteEventType(event.eventType))
74
+ .reduce((bits, event) => intentListOf(event).reduce((acc, intent) => acc | intent, bits), 0);
75
+
76
+ /** The privileged intents the triggers need, in bit order, without duplicates. */
77
+ export const privilegedIntentsOf = (events: readonly IntentSource[]): DiscordGatewayIntent[] => {
78
+ const bits = intentsOf(events);
79
+ return PRIVILEGED_DISCORD_GATEWAY_INTENTS.filter((intent) => (bits & intent) !== 0);
80
+ };
@@ -1,3 +1,4 @@
1
- export * from './discord-event-intents';
2
- export * from './discord-event-filters';
3
- export * from './discord-event-filter-cases';
1
+ export * from './discord-event-intents';
2
+ export * from './discord-command-tree';
3
+ export * from './discord-event-filters';
4
+ export * from './discord-event-filter-cases';
package/src/index.test.ts CHANGED
@@ -1,104 +1,104 @@
1
- import { AxiosAdapter, AxiosError, InternalAxiosRequestConfig } from 'axios';
2
- import {
3
- AbyssReflexCore,
4
- HealthStatus,
5
- IHealthResponse,
6
- intentsOf,
7
- matchesEventFilters,
8
- privilegedIntentsOf,
9
- } from '.';
10
-
11
- const answer =
12
- (status: number, data: IHealthResponse): AxiosAdapter =>
13
- async (config: InternalAxiosRequestConfig) => {
14
- const response = { data, status, statusText: '', headers: {}, config };
15
- if (status >= 400) {
16
- throw new AxiosError('failed', 'ERR_BAD_RESPONSE', config, null, response);
17
- }
18
- return response;
19
- };
20
-
21
- describe('AbyssReflexCore', () => {
22
- it('points at the production API until setConfig says otherwise', () => {
23
- expect(AbyssReflexCore.getConfig().baseURL).toBe('https://reflex-api.abyss-project.fr/');
24
- });
25
-
26
- it('setConfig changes the base URL of the axios instance', () => {
27
- AbyssReflexCore.setConfig({ baseURL: 'http://localhost:10141/' });
28
- expect(AbyssReflexCore.axios.defaults.baseURL).toBe('http://localhost:10141/');
29
- expect(AbyssReflexCore.getConfig().baseURL).toBe('http://localhost:10141/');
30
- });
31
-
32
- it('health() calls GET /health on the configured URL and returns the typed body', async () => {
33
- const adapter = jest.fn(answer(200, { database: HealthStatus.UP, redis: HealthStatus.UP }));
34
- AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/' });
35
- AbyssReflexCore.axios.defaults.adapter = adapter;
36
-
37
- const body = await AbyssReflexCore.sdk.health();
38
-
39
- expect(body).toEqual({ database: 'up', redis: 'up' });
40
- const config = adapter.mock.calls[0][0];
41
- expect(config.method).toBe('get');
42
- expect(config.url).toBe('health');
43
- expect(config.baseURL).toBe('http://reflex.test/');
44
- });
45
-
46
- it('health() rejects on a 503 and the error carries the component that is down', async () => {
47
- AbyssReflexCore.axios.defaults.adapter = answer(503, {
48
- database: HealthStatus.DOWN,
49
- redis: HealthStatus.UP,
50
- });
51
-
52
- const error = await AbyssReflexCore.sdk.health().catch((e: AxiosError<IHealthResponse>) => e);
53
-
54
- expect((error as AxiosError<IHealthResponse>).response?.status).toBe(503);
55
- expect((error as AxiosError<IHealthResponse>).response?.data.database).toBe(HealthStatus.DOWN);
56
- });
57
- });
58
-
59
- describe('AbyssReflexCore facade of the Discord events', () => {
60
- it('exposes the pure event helpers of the SDK', () => {
61
- expect(intentsOf([])).toBe(0);
62
- expect(typeof matchesEventFilters).toBe('function');
63
- expect(typeof privilegedIntentsOf).toBe('function');
64
- });
65
-
66
- it('exposes the event, insights and bot limit routes under short names', () => {
67
- const { service, function: fn } = AbyssReflexCore.sdk;
68
- expect(Object.keys(service.discord.event)).toEqual(['list', 'create', 'update', 'delete']);
69
- expect(Object.keys(service.discord.eventLog)).toEqual(['list']);
70
- expect(Object.keys(service.insights)).toEqual(['get', 'events']);
71
- expect(Object.keys(fn.insights)).toEqual(['get']);
72
- expect(service.discord.connection.setAllocation).toBeInstanceOf(Function);
73
- expect(Object.keys(service.discord.connection)).not.toContain('setBotSettings');
74
- });
75
- });
76
-
77
- describe('AbyssReflexCore facade of the run understanding routes', () => {
78
- it('exposes the application, route statistics and log cap routes under short names', () => {
79
- const { application, service, function: fn } = AbyssReflexCore.sdk;
80
- expect(Object.keys(application)).toEqual(['runSettings', 'insights', 'alertRule']);
81
- expect(Object.keys(application.runSettings)).toEqual(['get', 'set']);
82
- expect(Object.keys(application.insights)).toEqual(['get', 'calendar']);
83
- expect(Object.keys(application.alertRule)).toEqual(['list', 'create', 'update', 'delete']);
84
- expect(Object.keys(service.routeStats)).toEqual(['list', 'insights']);
85
- expect(Object.keys(fn.logCap)).toEqual(['set']);
86
- });
87
- });
88
-
89
- describe('AbyssReflexCore facade of the contract, the consumers and the limits', () => {
90
- it('exposes the consumer, OpenAPI, limits and completion webhook routes under short names', () => {
91
- const { service } = AbyssReflexCore.sdk;
92
- expect(Object.keys(service.consumer)).toEqual([
93
- 'list',
94
- 'create',
95
- 'update',
96
- 'delete',
97
- 'createKey',
98
- 'revokeKey',
99
- ]);
100
- expect(Object.keys(service.openapi)).toEqual(['get']);
101
- expect(Object.keys(service.limits)).toEqual(['list', 'set']);
102
- expect(Object.keys(service.completionWebhook)).toEqual(['get', 'rotateSecret']);
103
- });
104
- });
1
+ import { AxiosAdapter, AxiosError, InternalAxiosRequestConfig } from 'axios';
2
+ import {
3
+ AbyssReflexCore,
4
+ HealthStatus,
5
+ IHealthResponse,
6
+ intentsOf,
7
+ matchesEventFilters,
8
+ privilegedIntentsOf,
9
+ } from '.';
10
+
11
+ const answer =
12
+ (status: number, data: IHealthResponse): AxiosAdapter =>
13
+ async (config: InternalAxiosRequestConfig) => {
14
+ const response = { data, status, statusText: '', headers: {}, config };
15
+ if (status >= 400) {
16
+ throw new AxiosError('failed', 'ERR_BAD_RESPONSE', config, null, response);
17
+ }
18
+ return response;
19
+ };
20
+
21
+ describe('AbyssReflexCore', () => {
22
+ it('points at the production API until setConfig says otherwise', () => {
23
+ expect(AbyssReflexCore.getConfig().baseURL).toBe('https://reflex-api.abyss-project.fr/');
24
+ });
25
+
26
+ it('setConfig changes the base URL of the axios instance', () => {
27
+ AbyssReflexCore.setConfig({ baseURL: 'http://localhost:10141/' });
28
+ expect(AbyssReflexCore.axios.defaults.baseURL).toBe('http://localhost:10141/');
29
+ expect(AbyssReflexCore.getConfig().baseURL).toBe('http://localhost:10141/');
30
+ });
31
+
32
+ it('health() calls GET /health on the configured URL and returns the typed body', async () => {
33
+ const adapter = jest.fn(answer(200, { database: HealthStatus.UP, redis: HealthStatus.UP }));
34
+ AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/' });
35
+ AbyssReflexCore.axios.defaults.adapter = adapter;
36
+
37
+ const body = await AbyssReflexCore.sdk.health();
38
+
39
+ expect(body).toEqual({ database: 'up', redis: 'up' });
40
+ const config = adapter.mock.calls[0][0];
41
+ expect(config.method).toBe('get');
42
+ expect(config.url).toBe('health');
43
+ expect(config.baseURL).toBe('http://reflex.test/');
44
+ });
45
+
46
+ it('health() rejects on a 503 and the error carries the component that is down', async () => {
47
+ AbyssReflexCore.axios.defaults.adapter = answer(503, {
48
+ database: HealthStatus.DOWN,
49
+ redis: HealthStatus.UP,
50
+ });
51
+
52
+ const error = await AbyssReflexCore.sdk.health().catch((e: AxiosError<IHealthResponse>) => e);
53
+
54
+ expect((error as AxiosError<IHealthResponse>).response?.status).toBe(503);
55
+ expect((error as AxiosError<IHealthResponse>).response?.data.database).toBe(HealthStatus.DOWN);
56
+ });
57
+ });
58
+
59
+ describe('AbyssReflexCore facade of the Discord events', () => {
60
+ it('exposes the pure event helpers of the SDK', () => {
61
+ expect(intentsOf([])).toBe(0);
62
+ expect(typeof matchesEventFilters).toBe('function');
63
+ expect(typeof privilegedIntentsOf).toBe('function');
64
+ });
65
+
66
+ it('exposes the event, insights and bot limit routes under short names', () => {
67
+ const { service, function: fn } = AbyssReflexCore.sdk;
68
+ expect(Object.keys(service.discord.event)).toEqual(['list', 'create', 'update', 'delete']);
69
+ expect(Object.keys(service.discord.eventLog)).toEqual(['list']);
70
+ expect(Object.keys(service.insights)).toEqual(['get', 'events']);
71
+ expect(Object.keys(fn.insights)).toEqual(['get']);
72
+ expect(service.discord.connection.setAllocation).toBeInstanceOf(Function);
73
+ expect(Object.keys(service.discord.connection)).not.toContain('setBotSettings');
74
+ });
75
+ });
76
+
77
+ describe('AbyssReflexCore facade of the run understanding routes', () => {
78
+ it('exposes the application, route statistics and log cap routes under short names', () => {
79
+ const { application, service, function: fn } = AbyssReflexCore.sdk;
80
+ expect(Object.keys(application)).toEqual(['runSettings', 'insights', 'alertRule']);
81
+ expect(Object.keys(application.runSettings)).toEqual(['get', 'set']);
82
+ expect(Object.keys(application.insights)).toEqual(['get', 'calendar']);
83
+ expect(Object.keys(application.alertRule)).toEqual(['list', 'create', 'update', 'delete']);
84
+ expect(Object.keys(service.routeStats)).toEqual(['list', 'insights']);
85
+ expect(Object.keys(fn.logCap)).toEqual(['set']);
86
+ });
87
+ });
88
+
89
+ describe('AbyssReflexCore facade of the contract, the consumers and the limits', () => {
90
+ it('exposes the consumer, OpenAPI, limits and completion webhook routes under short names', () => {
91
+ const { service } = AbyssReflexCore.sdk;
92
+ expect(Object.keys(service.consumer)).toEqual([
93
+ 'list',
94
+ 'create',
95
+ 'update',
96
+ 'delete',
97
+ 'createKey',
98
+ 'revokeKey',
99
+ ]);
100
+ expect(Object.keys(service.openapi)).toEqual(['get']);
101
+ expect(Object.keys(service.limits)).toEqual(['list', 'set']);
102
+ expect(Object.keys(service.completionWebhook)).toEqual(['get', 'rotateSecret']);
103
+ });
104
+ });
package/src/index.ts CHANGED
@@ -77,6 +77,7 @@ type AbyssReflexCoreSDK = {
77
77
  list: typeof functionRunApi.listFunctionRun;
78
78
  get: typeof functionRunApi.getFunctionRun;
79
79
  state: typeof functionRunApi.getFunctionRunState;
80
+ replay: typeof functionRunApi.replayFunctionRun;
80
81
  /** Marks a run as a favorite (never purged) or not. */
81
82
  favorite: typeof functionRunApi.setFunctionRunFavorite;
82
83
  };
@@ -299,6 +300,7 @@ export class AbyssReflexCore {
299
300
  list: functionRunApi.listFunctionRun,
300
301
  get: functionRunApi.getFunctionRun,
301
302
  state: functionRunApi.getFunctionRunState,
303
+ replay: functionRunApi.replayFunctionRun,
302
304
  favorite: functionRunApi.setFunctionRunFavorite,
303
305
  },
304
306
  insights: {
@@ -1 +1 @@
1
- export * from './percentiles';
1
+ export * from './percentiles';