@abyss-project/reflex 6.3.0 → 6.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.
Files changed (133) hide show
  1. package/.eslintrc.js +32 -32
  2. package/README.md +15 -15
  3. package/dist/api/function-run.api.d.ts +2 -1
  4. package/dist/api/function-run.api.js +3 -1
  5. package/dist/api/function-run.api.js.map +1 -1
  6. package/dist/api/function-settings.api.d.ts +3 -1
  7. package/dist/api/function-settings.api.js +7 -1
  8. package/dist/api/function-settings.api.js.map +1 -1
  9. package/dist/api/index.d.ts +1 -0
  10. package/dist/api/index.js +1 -0
  11. package/dist/api/index.js.map +1 -1
  12. package/dist/api/storage-surplus.admin.api.d.ts +5 -0
  13. package/dist/api/storage-surplus.admin.api.js +17 -0
  14. package/dist/api/storage-surplus.admin.api.js.map +1 -0
  15. package/dist/index.d.ts +16 -0
  16. package/dist/index.js +19 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/types/enum/reflex-error-code.enum.d.ts +4 -1
  19. package/dist/types/enum/reflex-error-code.enum.js +3 -0
  20. package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
  21. package/dist/types/interface/api/requests/application-run-settings.request.d.ts +1 -0
  22. package/dist/types/interface/api/requests/function-run.request.d.ts +8 -0
  23. package/dist/types/interface/api/requests/function-settings.request.d.ts +12 -0
  24. package/dist/types/interface/api/requests/index.d.ts +1 -0
  25. package/dist/types/interface/api/requests/index.js +1 -0
  26. package/dist/types/interface/api/requests/index.js.map +1 -1
  27. package/dist/types/interface/api/requests/service.request.d.ts +1 -0
  28. package/dist/types/interface/api/requests/storage-surplus.admin.request.d.ts +8 -0
  29. package/dist/types/interface/api/requests/storage-surplus.admin.request.js +3 -0
  30. package/dist/types/interface/api/requests/storage-surplus.admin.request.js.map +1 -0
  31. package/dist/types/interface/api/responses/function-run.response.d.ts +4 -0
  32. package/dist/types/interface/api/responses/function-settings.response.d.ts +5 -1
  33. package/dist/types/interface/api/responses/index.d.ts +1 -0
  34. package/dist/types/interface/api/responses/index.js +1 -0
  35. package/dist/types/interface/api/responses/index.js.map +1 -1
  36. package/dist/types/interface/api/responses/storage-surplus.admin.response.d.ts +8 -0
  37. package/dist/types/interface/api/responses/storage-surplus.admin.response.js +3 -0
  38. package/dist/types/interface/api/responses/storage-surplus.admin.response.js.map +1 -0
  39. package/dist/types/interface/models/index.d.ts +2 -0
  40. package/dist/types/interface/models/index.js +2 -0
  41. package/dist/types/interface/models/index.js.map +1 -1
  42. package/dist/types/interface/models/reflex-run-retention.model.d.ts +13 -0
  43. package/dist/types/interface/models/reflex-run-retention.model.js +8 -0
  44. package/dist/types/interface/models/reflex-run-retention.model.js.map +1 -0
  45. package/dist/types/interface/models/reflex-run-settings.model.d.ts +4 -0
  46. package/dist/types/interface/models/reflex-run.model.d.ts +5 -0
  47. package/dist/types/interface/models/reflex-service-deployment.model.d.ts +2 -2
  48. package/dist/types/interface/models/reflex-service.model.d.ts +1 -0
  49. package/dist/types/interface/models/reflex-storage-surplus.model.d.ts +11 -0
  50. package/dist/types/interface/models/reflex-storage-surplus.model.js +3 -0
  51. package/dist/types/interface/models/reflex-storage-surplus.model.js.map +1 -0
  52. package/jest.config.ts +11 -11
  53. package/package.json +1 -1
  54. package/src/api/alert-rule.api.test.ts +72 -72
  55. package/src/api/alert-rule.api.ts +57 -57
  56. package/src/api/application-insights.api.test.ts +42 -42
  57. package/src/api/application-insights.api.ts +38 -38
  58. package/src/api/application-run-settings.api.test.ts +11 -0
  59. package/src/api/application-run-settings.api.ts +30 -30
  60. package/src/api/function-access.api.ts +87 -87
  61. package/src/api/function-insights.api.test.ts +27 -27
  62. package/src/api/function-insights.api.ts +18 -18
  63. package/src/api/function-run.api.ts +15 -0
  64. package/src/api/function-settings.api.ts +22 -0
  65. package/src/api/function-template.api.test.ts +72 -72
  66. package/src/api/function-template.api.ts +52 -52
  67. package/src/api/function-test.api.ts +34 -34
  68. package/src/api/function-version.api.ts +66 -66
  69. package/src/api/function.api.test.ts +55 -0
  70. package/src/api/function.api.ts +62 -62
  71. package/src/api/health.api.ts +10 -10
  72. package/src/api/index.ts +27 -26
  73. package/src/api/route-stats.api.test.ts +45 -45
  74. package/src/api/route-stats.api.ts +36 -36
  75. package/src/api/service-completion-webhook.api.test.ts +97 -97
  76. package/src/api/service-completion-webhook.api.ts +39 -39
  77. package/src/api/service-configuration.api.ts +16 -16
  78. package/src/api/service-consumer.api.test.ts +104 -104
  79. package/src/api/service-consumer.api.ts +90 -90
  80. package/src/api/service-deployment.api.ts +79 -79
  81. package/src/api/service-discord-event.api.test.ts +106 -106
  82. package/src/api/service-discord-event.api.ts +78 -78
  83. package/src/api/service-discord.api.test.ts +178 -178
  84. package/src/api/service-discord.api.ts +222 -222
  85. package/src/api/service-insights.api.test.ts +36 -36
  86. package/src/api/service-insights.api.ts +42 -42
  87. package/src/api/service-limits.api.test.ts +100 -100
  88. package/src/api/service-limits.api.ts +37 -37
  89. package/src/api/service-openapi.api.test.ts +52 -52
  90. package/src/api/service-openapi.api.ts +21 -21
  91. package/src/api/service-route.api.ts +74 -74
  92. package/src/api/service-task.api.test.ts +140 -140
  93. package/src/api/service-task.api.ts +141 -141
  94. package/src/api/service-version.api.ts +54 -54
  95. package/src/api/service.api.test.ts +6 -1
  96. package/src/api/service.api.ts +55 -55
  97. package/src/api/storage-surplus.admin.api.test.ts +66 -0
  98. package/src/api/storage-surplus.admin.api.ts +45 -0
  99. package/src/discord/discord-event-filter-cases.ts +261 -261
  100. package/src/discord/discord-event-filters.test.ts +91 -91
  101. package/src/discord/discord-event-filters.ts +95 -95
  102. package/src/discord/discord-event-intents.test.ts +112 -112
  103. package/src/discord/discord-event-intents.ts +55 -55
  104. package/src/discord/index.ts +3 -3
  105. package/src/index.test.ts +104 -104
  106. package/src/index.ts +42 -0
  107. package/src/insights/index.ts +1 -1
  108. package/src/insights/percentiles.test.ts +75 -75
  109. package/src/insights/percentiles.ts +37 -37
  110. package/src/types/enum/discord-host-action.enum.ts +37 -37
  111. package/src/types/enum/reflex-error-code.enum.ts +16 -0
  112. package/src/types/interface/api/requests/application-run-settings.request.ts +2 -0
  113. package/src/types/interface/api/requests/function-run.request.ts +10 -0
  114. package/src/types/interface/api/requests/function-settings.request.ts +16 -0
  115. package/src/types/interface/api/requests/index.ts +1 -0
  116. package/src/types/interface/api/requests/service-discord.request.ts +155 -155
  117. package/src/types/interface/api/requests/service.request.ts +2 -0
  118. package/src/types/interface/api/requests/storage-surplus.admin.request.ts +12 -0
  119. package/src/types/interface/api/responses/function-run.response.ts +5 -0
  120. package/src/types/interface/api/responses/function-settings.response.ts +7 -0
  121. package/src/types/interface/api/responses/index.ts +1 -0
  122. package/src/types/interface/api/responses/storage-surplus.admin.response.ts +10 -0
  123. package/src/types/interface/models/index.ts +2 -0
  124. package/src/types/interface/models/reflex-discord.model.ts +208 -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 -0
  127. package/src/types/interface/models/reflex-run-settings.model.ts +11 -0
  128. package/src/types/interface/models/reflex-run.model.ts +10 -0
  129. package/src/types/interface/models/reflex-service-deployment.model.ts +4 -2
  130. package/src/types/interface/models/reflex-service.model.ts +2 -0
  131. package/src/types/interface/models/reflex-storage-surplus.model.ts +23 -0
  132. package/tsconfig.check.json +15 -15
  133. package/tsconfig.json +35 -35
@@ -1,78 +1,78 @@
1
- import { AbyssReflexCore } from '..';
2
- import type {
3
- ICreateServiceDiscordEventBody,
4
- ICreateServiceDiscordEventParams,
5
- ICreateServiceDiscordEventResponse,
6
- IDeleteServiceDiscordEventParams,
7
- IDeleteServiceDiscordEventResponse,
8
- IListServiceDiscordEventLogParams,
9
- IListServiceDiscordEventLogQuery,
10
- IListServiceDiscordEventLogResponse,
11
- IListServiceDiscordEventParams,
12
- IListServiceDiscordEventResponse,
13
- IUpdateServiceDiscordEventBody,
14
- IUpdateServiceDiscordEventParams,
15
- IUpdateServiceDiscordEventResponse,
16
- } from '../types';
17
-
18
- const serviceUrl = (params: { applicationId: string; serviceId: string }): string =>
19
- `api/service/${params.applicationId}/${params.serviceId}`;
20
-
21
- const eventUrl = (params: { applicationId: string; serviceId: string }): string =>
22
- `${serviceUrl(params)}/discord-event`;
23
-
24
- /** `GET .../discord-event`: the event triggers of the draft of a Discord bot, by name. Needs REFLEX_READ. */
25
- export const listServiceDiscordEvent = async (
26
- params: IListServiceDiscordEventParams,
27
- ): Promise<IListServiceDiscordEventResponse> =>
28
- (await AbyssReflexCore.axios.get<IListServiceDiscordEventResponse>(eventUrl(params))).data;
29
-
30
- /**
31
- * `POST .../discord-event`: an event trigger of the draft (25 at most per Service), live once a version
32
- * holding it is in service. `409 DISCORD_EVENT_CONFLICT` when the name is taken. Needs
33
- * REFLEX_FUNCTION_UPDATE.
34
- */
35
- export const createServiceDiscordEvent = async (
36
- params: ICreateServiceDiscordEventParams,
37
- body: ICreateServiceDiscordEventBody,
38
- ): Promise<ICreateServiceDiscordEventResponse> =>
39
- (await AbyssReflexCore.axios.post<ICreateServiceDiscordEventResponse>(eventUrl(params), body))
40
- .data;
41
-
42
- /** `PATCH .../discord-event/:eventId`: changes the trigger in the draft. Needs REFLEX_FUNCTION_UPDATE. */
43
- export const updateServiceDiscordEvent = async (
44
- params: IUpdateServiceDiscordEventParams,
45
- body: IUpdateServiceDiscordEventBody,
46
- ): Promise<IUpdateServiceDiscordEventResponse> =>
47
- (
48
- await AbyssReflexCore.axios.patch<IUpdateServiceDiscordEventResponse>(
49
- `${eventUrl(params)}/${params.eventId}`,
50
- body,
51
- )
52
- ).data;
53
-
54
- /** `DELETE .../discord-event/:eventId`: takes the trigger out of the draft. Needs REFLEX_FUNCTION_UPDATE. */
55
- export const deleteServiceDiscordEvent = async (
56
- params: IDeleteServiceDiscordEventParams,
57
- ): Promise<IDeleteServiceDiscordEventResponse> =>
58
- (
59
- await AbyssReflexCore.axios.delete<IDeleteServiceDiscordEventResponse>(
60
- `${eventUrl(params)}/${params.eventId}`,
61
- )
62
- ).data;
63
-
64
- /**
65
- * `GET .../discord-event-log`: the events of the bot in one environment, newest first, paged by cursor: the
66
- * retained ones (inbox) and a sample of the dropped ones with their reason. Carries `intentsRefused` instead
67
- * of events while Discord refuses the intents. Needs REFLEX_LOG_READ.
68
- */
69
- export const listServiceDiscordEventLog = async (
70
- params: IListServiceDiscordEventLogParams,
71
- query: IListServiceDiscordEventLogQuery,
72
- ): Promise<IListServiceDiscordEventLogResponse> =>
73
- (
74
- await AbyssReflexCore.axios.get<IListServiceDiscordEventLogResponse>(
75
- `${serviceUrl(params)}/discord-event-log`,
76
- { params: query },
77
- )
78
- ).data;
1
+ import { AbyssReflexCore } from '..';
2
+ import type {
3
+ ICreateServiceDiscordEventBody,
4
+ ICreateServiceDiscordEventParams,
5
+ ICreateServiceDiscordEventResponse,
6
+ IDeleteServiceDiscordEventParams,
7
+ IDeleteServiceDiscordEventResponse,
8
+ IListServiceDiscordEventLogParams,
9
+ IListServiceDiscordEventLogQuery,
10
+ IListServiceDiscordEventLogResponse,
11
+ IListServiceDiscordEventParams,
12
+ IListServiceDiscordEventResponse,
13
+ IUpdateServiceDiscordEventBody,
14
+ IUpdateServiceDiscordEventParams,
15
+ IUpdateServiceDiscordEventResponse,
16
+ } from '../types';
17
+
18
+ const serviceUrl = (params: { applicationId: string; serviceId: string }): string =>
19
+ `api/service/${params.applicationId}/${params.serviceId}`;
20
+
21
+ const eventUrl = (params: { applicationId: string; serviceId: string }): string =>
22
+ `${serviceUrl(params)}/discord-event`;
23
+
24
+ /** `GET .../discord-event`: the event triggers of the draft of a Discord bot, by name. Needs REFLEX_READ. */
25
+ export const listServiceDiscordEvent = async (
26
+ params: IListServiceDiscordEventParams,
27
+ ): Promise<IListServiceDiscordEventResponse> =>
28
+ (await AbyssReflexCore.axios.get<IListServiceDiscordEventResponse>(eventUrl(params))).data;
29
+
30
+ /**
31
+ * `POST .../discord-event`: an event trigger of the draft (25 at most per Service), live once a version
32
+ * holding it is in service. `409 DISCORD_EVENT_CONFLICT` when the name is taken. Needs
33
+ * REFLEX_FUNCTION_UPDATE.
34
+ */
35
+ export const createServiceDiscordEvent = async (
36
+ params: ICreateServiceDiscordEventParams,
37
+ body: ICreateServiceDiscordEventBody,
38
+ ): Promise<ICreateServiceDiscordEventResponse> =>
39
+ (await AbyssReflexCore.axios.post<ICreateServiceDiscordEventResponse>(eventUrl(params), body))
40
+ .data;
41
+
42
+ /** `PATCH .../discord-event/:eventId`: changes the trigger in the draft. Needs REFLEX_FUNCTION_UPDATE. */
43
+ export const updateServiceDiscordEvent = async (
44
+ params: IUpdateServiceDiscordEventParams,
45
+ body: IUpdateServiceDiscordEventBody,
46
+ ): Promise<IUpdateServiceDiscordEventResponse> =>
47
+ (
48
+ await AbyssReflexCore.axios.patch<IUpdateServiceDiscordEventResponse>(
49
+ `${eventUrl(params)}/${params.eventId}`,
50
+ body,
51
+ )
52
+ ).data;
53
+
54
+ /** `DELETE .../discord-event/:eventId`: takes the trigger out of the draft. Needs REFLEX_FUNCTION_UPDATE. */
55
+ export const deleteServiceDiscordEvent = async (
56
+ params: IDeleteServiceDiscordEventParams,
57
+ ): Promise<IDeleteServiceDiscordEventResponse> =>
58
+ (
59
+ await AbyssReflexCore.axios.delete<IDeleteServiceDiscordEventResponse>(
60
+ `${eventUrl(params)}/${params.eventId}`,
61
+ )
62
+ ).data;
63
+
64
+ /**
65
+ * `GET .../discord-event-log`: the events of the bot in one environment, newest first, paged by cursor: the
66
+ * retained ones (inbox) and a sample of the dropped ones with their reason. Carries `intentsRefused` instead
67
+ * of events while Discord refuses the intents. Needs REFLEX_LOG_READ.
68
+ */
69
+ export const listServiceDiscordEventLog = async (
70
+ params: IListServiceDiscordEventLogParams,
71
+ query: IListServiceDiscordEventLogQuery,
72
+ ): Promise<IListServiceDiscordEventLogResponse> =>
73
+ (
74
+ await AbyssReflexCore.axios.get<IListServiceDiscordEventLogResponse>(
75
+ `${serviceUrl(params)}/discord-event-log`,
76
+ { params: query },
77
+ )
78
+ ).data;
@@ -1,178 +1,178 @@
1
- import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
- import { AbyssReflexCore, DiscordComponentKind, DiscordOptionType } from '..';
3
-
4
- const APP = 'app-1';
5
- const SVC = 'svc-1';
6
- const BASE = `api/service/${APP}/${SVC}`;
7
- const SERVICE = { applicationId: APP, serviceId: SVC };
8
-
9
- interface Call {
10
- label: string;
11
- method: string;
12
- url: string;
13
- body?: unknown;
14
- run: () => Promise<unknown>;
15
- }
16
-
17
- const discord = () => AbyssReflexCore.sdk.service.discord;
18
-
19
- const command = {
20
- name: 'ping',
21
- description: 'Answers pong',
22
- options: [
23
- {
24
- type: DiscordOptionType.STRING,
25
- name: 'word',
26
- description: 'A word',
27
- required: true,
28
- },
29
- ],
30
- functionId: 'fn-1',
31
- };
32
-
33
- const calls: Call[] = [
34
- {
35
- label: 'command.list',
36
- method: 'get',
37
- url: `${BASE}/discord/command`,
38
- run: () => discord().command.list(SERVICE),
39
- },
40
- {
41
- label: 'command.create',
42
- method: 'post',
43
- url: `${BASE}/discord/command`,
44
- body: command,
45
- run: () => discord().command.create(SERVICE, command),
46
- },
47
- {
48
- label: 'command.update',
49
- method: 'patch',
50
- url: `${BASE}/discord/command/c-1`,
51
- body: { description: 'Answers pong again' },
52
- run: () =>
53
- discord().command.update(
54
- { ...SERVICE, commandId: 'c-1' },
55
- { description: 'Answers pong again' },
56
- ),
57
- },
58
- {
59
- label: 'command.delete',
60
- method: 'delete',
61
- url: `${BASE}/discord/command/c-1`,
62
- run: () => discord().command.delete({ ...SERVICE, commandId: 'c-1' }),
63
- },
64
- {
65
- label: 'component.list',
66
- method: 'get',
67
- url: `${BASE}/discord/component`,
68
- run: () => discord().component.list(SERVICE),
69
- },
70
- {
71
- label: 'component.create',
72
- method: 'post',
73
- url: `${BASE}/discord/component`,
74
- body: {
75
- customIdPrefix: 'confirm',
76
- kind: DiscordComponentKind.BUTTON_OR_SELECT,
77
- functionId: 'fn-1',
78
- },
79
- run: () =>
80
- discord().component.create(SERVICE, {
81
- customIdPrefix: 'confirm',
82
- kind: DiscordComponentKind.BUTTON_OR_SELECT,
83
- functionId: 'fn-1',
84
- }),
85
- },
86
- {
87
- label: 'component.update',
88
- method: 'patch',
89
- url: `${BASE}/discord/component/k-1`,
90
- body: { kind: DiscordComponentKind.MODAL },
91
- run: () =>
92
- discord().component.update(
93
- { ...SERVICE, componentId: 'k-1' },
94
- { kind: DiscordComponentKind.MODAL },
95
- ),
96
- },
97
- {
98
- label: 'component.delete',
99
- method: 'delete',
100
- url: `${BASE}/discord/component/k-1`,
101
- run: () => discord().component.delete({ ...SERVICE, componentId: 'k-1' }),
102
- },
103
- {
104
- label: 'connection.get',
105
- method: 'get',
106
- url: `${BASE}/discord/connection`,
107
- run: () => discord().connection.get(SERVICE),
108
- },
109
- {
110
- label: 'connection.setTokenSecret',
111
- method: 'put',
112
- url: `${BASE}/discord/connection`,
113
- body: { discordTokenSecretId: 'secret-1' },
114
- run: () => discord().connection.setTokenSecret(SERVICE, { discordTokenSecretId: 'secret-1' }),
115
- },
116
- {
117
- label: 'connection.setEnvironment',
118
- method: 'put',
119
- url: `${BASE}/discord/connection/e-1`,
120
- body: { testGuildId: '123456789012345678', invitePermissions: '2048' },
121
- run: () =>
122
- discord().connection.setEnvironment(
123
- { ...SERVICE, environmentId: 'e-1' },
124
- { testGuildId: '123456789012345678', invitePermissions: '2048' },
125
- ),
126
- },
127
- {
128
- label: 'connection.setAllocation',
129
- method: 'put',
130
- url: `${BASE}/discord/connection/e-1/allocation`,
131
- body: { lots: 3 },
132
- run: () =>
133
- discord().connection.setAllocation({ ...SERVICE, environmentId: 'e-1' }, { lots: 3 }),
134
- },
135
- {
136
- label: 'connection.check',
137
- method: 'post',
138
- url: `${BASE}/discord/connection/e-1/check`,
139
- body: {},
140
- run: () => discord().connection.check({ ...SERVICE, environmentId: 'e-1' }),
141
- },
142
- {
143
- label: 'sync',
144
- method: 'post',
145
- url: `${BASE}/deployment/e-1/discord-sync`,
146
- body: {},
147
- run: () => discord().sync({ ...SERVICE, environmentId: 'e-1' }),
148
- },
149
- ];
150
-
151
- describe('AbyssReflexCore Discord bot routes', () => {
152
- const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
153
- async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
154
- );
155
-
156
- beforeAll(() => {
157
- AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
158
- AbyssReflexCore.axios.defaults.adapter = adapter;
159
- });
160
-
161
- beforeEach(() => adapter.mockClear());
162
-
163
- it.each(calls)('$label calls $method $url', async (call) => {
164
- await call.run();
165
-
166
- const config = adapter.mock.calls[0][0];
167
- expect(config.method).toBe(call.method);
168
- expect(config.url).toBe(call.url);
169
- expect(config.baseURL).toBe('http://reflex.test/');
170
- if (call.body !== undefined) {
171
- expect(JSON.parse(config.data)).toEqual(call.body);
172
- }
173
- });
174
-
175
- it('exposes no route twice', () => {
176
- expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
177
- });
178
- });
1
+ import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
+ import { AbyssReflexCore, DiscordComponentKind, DiscordOptionType } from '..';
3
+
4
+ const APP = 'app-1';
5
+ const SVC = 'svc-1';
6
+ const BASE = `api/service/${APP}/${SVC}`;
7
+ const SERVICE = { applicationId: APP, serviceId: SVC };
8
+
9
+ interface Call {
10
+ label: string;
11
+ method: string;
12
+ url: string;
13
+ body?: unknown;
14
+ run: () => Promise<unknown>;
15
+ }
16
+
17
+ const discord = () => AbyssReflexCore.sdk.service.discord;
18
+
19
+ const command = {
20
+ name: 'ping',
21
+ description: 'Answers pong',
22
+ options: [
23
+ {
24
+ type: DiscordOptionType.STRING,
25
+ name: 'word',
26
+ description: 'A word',
27
+ required: true,
28
+ },
29
+ ],
30
+ functionId: 'fn-1',
31
+ };
32
+
33
+ const calls: Call[] = [
34
+ {
35
+ label: 'command.list',
36
+ method: 'get',
37
+ url: `${BASE}/discord/command`,
38
+ run: () => discord().command.list(SERVICE),
39
+ },
40
+ {
41
+ label: 'command.create',
42
+ method: 'post',
43
+ url: `${BASE}/discord/command`,
44
+ body: command,
45
+ run: () => discord().command.create(SERVICE, command),
46
+ },
47
+ {
48
+ label: 'command.update',
49
+ method: 'patch',
50
+ url: `${BASE}/discord/command/c-1`,
51
+ body: { description: 'Answers pong again' },
52
+ run: () =>
53
+ discord().command.update(
54
+ { ...SERVICE, commandId: 'c-1' },
55
+ { description: 'Answers pong again' },
56
+ ),
57
+ },
58
+ {
59
+ label: 'command.delete',
60
+ method: 'delete',
61
+ url: `${BASE}/discord/command/c-1`,
62
+ run: () => discord().command.delete({ ...SERVICE, commandId: 'c-1' }),
63
+ },
64
+ {
65
+ label: 'component.list',
66
+ method: 'get',
67
+ url: `${BASE}/discord/component`,
68
+ run: () => discord().component.list(SERVICE),
69
+ },
70
+ {
71
+ label: 'component.create',
72
+ method: 'post',
73
+ url: `${BASE}/discord/component`,
74
+ body: {
75
+ customIdPrefix: 'confirm',
76
+ kind: DiscordComponentKind.BUTTON_OR_SELECT,
77
+ functionId: 'fn-1',
78
+ },
79
+ run: () =>
80
+ discord().component.create(SERVICE, {
81
+ customIdPrefix: 'confirm',
82
+ kind: DiscordComponentKind.BUTTON_OR_SELECT,
83
+ functionId: 'fn-1',
84
+ }),
85
+ },
86
+ {
87
+ label: 'component.update',
88
+ method: 'patch',
89
+ url: `${BASE}/discord/component/k-1`,
90
+ body: { kind: DiscordComponentKind.MODAL },
91
+ run: () =>
92
+ discord().component.update(
93
+ { ...SERVICE, componentId: 'k-1' },
94
+ { kind: DiscordComponentKind.MODAL },
95
+ ),
96
+ },
97
+ {
98
+ label: 'component.delete',
99
+ method: 'delete',
100
+ url: `${BASE}/discord/component/k-1`,
101
+ run: () => discord().component.delete({ ...SERVICE, componentId: 'k-1' }),
102
+ },
103
+ {
104
+ label: 'connection.get',
105
+ method: 'get',
106
+ url: `${BASE}/discord/connection`,
107
+ run: () => discord().connection.get(SERVICE),
108
+ },
109
+ {
110
+ label: 'connection.setTokenSecret',
111
+ method: 'put',
112
+ url: `${BASE}/discord/connection`,
113
+ body: { discordTokenSecretId: 'secret-1' },
114
+ run: () => discord().connection.setTokenSecret(SERVICE, { discordTokenSecretId: 'secret-1' }),
115
+ },
116
+ {
117
+ label: 'connection.setEnvironment',
118
+ method: 'put',
119
+ url: `${BASE}/discord/connection/e-1`,
120
+ body: { testGuildId: '123456789012345678', invitePermissions: '2048' },
121
+ run: () =>
122
+ discord().connection.setEnvironment(
123
+ { ...SERVICE, environmentId: 'e-1' },
124
+ { testGuildId: '123456789012345678', invitePermissions: '2048' },
125
+ ),
126
+ },
127
+ {
128
+ label: 'connection.setAllocation',
129
+ method: 'put',
130
+ url: `${BASE}/discord/connection/e-1/allocation`,
131
+ body: { lots: 3 },
132
+ run: () =>
133
+ discord().connection.setAllocation({ ...SERVICE, environmentId: 'e-1' }, { lots: 3 }),
134
+ },
135
+ {
136
+ label: 'connection.check',
137
+ method: 'post',
138
+ url: `${BASE}/discord/connection/e-1/check`,
139
+ body: {},
140
+ run: () => discord().connection.check({ ...SERVICE, environmentId: 'e-1' }),
141
+ },
142
+ {
143
+ label: 'sync',
144
+ method: 'post',
145
+ url: `${BASE}/deployment/e-1/discord-sync`,
146
+ body: {},
147
+ run: () => discord().sync({ ...SERVICE, environmentId: 'e-1' }),
148
+ },
149
+ ];
150
+
151
+ describe('AbyssReflexCore Discord bot routes', () => {
152
+ const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
153
+ async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
154
+ );
155
+
156
+ beforeAll(() => {
157
+ AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
158
+ AbyssReflexCore.axios.defaults.adapter = adapter;
159
+ });
160
+
161
+ beforeEach(() => adapter.mockClear());
162
+
163
+ it.each(calls)('$label calls $method $url', async (call) => {
164
+ await call.run();
165
+
166
+ const config = adapter.mock.calls[0][0];
167
+ expect(config.method).toBe(call.method);
168
+ expect(config.url).toBe(call.url);
169
+ expect(config.baseURL).toBe('http://reflex.test/');
170
+ if (call.body !== undefined) {
171
+ expect(JSON.parse(config.data)).toEqual(call.body);
172
+ }
173
+ });
174
+
175
+ it('exposes no route twice', () => {
176
+ expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
177
+ });
178
+ });