@abyss-project/reflex 6.3.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 (123) hide show
  1. package/.prettierrc +5 -5
  2. package/dist/api/function-run.api.d.ts +3 -1
  3. package/dist/api/function-run.api.js +5 -1
  4. package/dist/api/function-run.api.js.map +1 -1
  5. package/dist/api/function-settings.api.d.ts +3 -1
  6. package/dist/api/function-settings.api.js +7 -1
  7. package/dist/api/function-settings.api.js.map +1 -1
  8. package/dist/api/index.d.ts +1 -0
  9. package/dist/api/index.js +1 -0
  10. package/dist/api/index.js.map +1 -1
  11. package/dist/api/storage-surplus.admin.api.d.ts +5 -0
  12. package/dist/api/storage-surplus.admin.api.js +17 -0
  13. package/dist/api/storage-surplus.admin.api.js.map +1 -0
  14. package/dist/discord/discord-command-tree.d.ts +5 -0
  15. package/dist/discord/discord-command-tree.js +38 -0
  16. package/dist/discord/discord-command-tree.js.map +1 -0
  17. package/dist/discord/discord-event-filter-cases.js +27 -11
  18. package/dist/discord/discord-event-filter-cases.js.map +1 -1
  19. package/dist/discord/discord-event-filters.js +7 -3
  20. package/dist/discord/discord-event-filters.js.map +1 -1
  21. package/dist/discord/discord-event-intents.d.ts +8 -2
  22. package/dist/discord/discord-event-intents.js +13 -2
  23. package/dist/discord/discord-event-intents.js.map +1 -1
  24. package/dist/discord/index.d.ts +1 -0
  25. package/dist/discord/index.js +1 -0
  26. package/dist/discord/index.js.map +1 -1
  27. package/dist/index.d.ts +17 -0
  28. package/dist/index.js +20 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/types/enum/discord-command-node-type.enum.d.ts +5 -0
  31. package/dist/types/enum/discord-command-node-type.enum.js +10 -0
  32. package/dist/types/enum/discord-command-node-type.enum.js.map +1 -0
  33. package/dist/types/enum/discord-command-type.enum.d.ts +5 -0
  34. package/dist/types/enum/discord-command-type.enum.js +10 -0
  35. package/dist/types/enum/discord-command-type.enum.js.map +1 -0
  36. package/dist/types/enum/discord-event-type.enum.d.ts +3 -1
  37. package/dist/types/enum/discord-event-type.enum.js +2 -0
  38. package/dist/types/enum/discord-event-type.enum.js.map +1 -1
  39. package/dist/types/enum/index.d.ts +2 -0
  40. package/dist/types/enum/index.js +2 -0
  41. package/dist/types/enum/index.js.map +1 -1
  42. package/dist/types/enum/reflex-error-code.enum.d.ts +14 -1
  43. package/dist/types/enum/reflex-error-code.enum.js +13 -0
  44. package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
  45. package/dist/types/interface/api/requests/application-run-settings.request.d.ts +1 -0
  46. package/dist/types/interface/api/requests/function-run.request.d.ts +16 -0
  47. package/dist/types/interface/api/requests/function-settings.request.d.ts +12 -0
  48. package/dist/types/interface/api/requests/index.d.ts +1 -0
  49. package/dist/types/interface/api/requests/index.js +1 -0
  50. package/dist/types/interface/api/requests/index.js.map +1 -1
  51. package/dist/types/interface/api/requests/service-discord.request.d.ts +7 -3
  52. package/dist/types/interface/api/requests/service.request.d.ts +1 -0
  53. package/dist/types/interface/api/requests/storage-surplus.admin.request.d.ts +8 -0
  54. package/dist/types/interface/api/requests/storage-surplus.admin.request.js +3 -0
  55. package/dist/types/interface/api/requests/storage-surplus.admin.request.js.map +1 -0
  56. package/dist/types/interface/api/responses/function-run.response.d.ts +12 -0
  57. package/dist/types/interface/api/responses/function-settings.response.d.ts +5 -1
  58. package/dist/types/interface/api/responses/index.d.ts +1 -0
  59. package/dist/types/interface/api/responses/index.js +1 -0
  60. package/dist/types/interface/api/responses/index.js.map +1 -1
  61. package/dist/types/interface/api/responses/storage-surplus.admin.response.d.ts +8 -0
  62. package/dist/types/interface/api/responses/storage-surplus.admin.response.js +3 -0
  63. package/dist/types/interface/api/responses/storage-surplus.admin.response.js.map +1 -0
  64. package/dist/types/interface/models/index.d.ts +2 -0
  65. package/dist/types/interface/models/index.js +2 -0
  66. package/dist/types/interface/models/index.js.map +1 -1
  67. package/dist/types/interface/models/reflex-discord.model.d.ts +18 -2
  68. package/dist/types/interface/models/reflex-discord.model.js +4 -0
  69. package/dist/types/interface/models/reflex-discord.model.js.map +1 -1
  70. package/dist/types/interface/models/reflex-run-retention.model.d.ts +13 -0
  71. package/dist/types/interface/models/reflex-run-retention.model.js +8 -0
  72. package/dist/types/interface/models/reflex-run-retention.model.js.map +1 -0
  73. package/dist/types/interface/models/reflex-run-settings.model.d.ts +4 -0
  74. package/dist/types/interface/models/reflex-run.model.d.ts +9 -0
  75. package/dist/types/interface/models/reflex-run.model.js +4 -1
  76. package/dist/types/interface/models/reflex-run.model.js.map +1 -1
  77. package/dist/types/interface/models/reflex-service-deployment.model.d.ts +2 -2
  78. package/dist/types/interface/models/reflex-service.model.d.ts +1 -0
  79. package/dist/types/interface/models/reflex-storage-surplus.model.d.ts +11 -0
  80. package/dist/types/interface/models/reflex-storage-surplus.model.js +3 -0
  81. package/dist/types/interface/models/reflex-storage-surplus.model.js.map +1 -0
  82. package/package.json +1 -1
  83. package/src/api/application-run-settings.api.test.ts +62 -51
  84. package/src/api/function-run.api.ts +34 -0
  85. package/src/api/function-settings.api.ts +96 -74
  86. package/src/api/function.api.test.ts +346 -291
  87. package/src/api/index.ts +27 -26
  88. package/src/api/service.api.test.ts +220 -215
  89. package/src/api/storage-surplus.admin.api.test.ts +66 -0
  90. package/src/api/storage-surplus.admin.api.ts +45 -0
  91. package/src/discord/discord-command-tree.test.ts +47 -0
  92. package/src/discord/discord-command-tree.ts +60 -0
  93. package/src/discord/discord-event-filter-cases.ts +54 -16
  94. package/src/discord/discord-event-filters.test.ts +33 -4
  95. package/src/discord/discord-event-filters.ts +13 -5
  96. package/src/discord/discord-event-intents.test.ts +27 -0
  97. package/src/discord/discord-event-intents.ts +31 -6
  98. package/src/discord/index.ts +1 -0
  99. package/src/index.ts +44 -0
  100. package/src/types/enum/discord-command-node-type.enum.ts +10 -0
  101. package/src/types/enum/discord-command-type.enum.ts +9 -0
  102. package/src/types/enum/discord-event-type.enum.ts +4 -0
  103. package/src/types/enum/index.ts +2 -0
  104. package/src/types/enum/reflex-error-code.enum.ts +112 -73
  105. package/src/types/interface/api/requests/application-run-settings.request.ts +13 -11
  106. package/src/types/interface/api/requests/function-run.request.ts +53 -32
  107. package/src/types/interface/api/requests/function-settings.request.ts +50 -34
  108. package/src/types/interface/api/requests/index.ts +25 -24
  109. package/src/types/interface/api/requests/service-discord.request.ts +19 -6
  110. package/src/types/interface/api/requests/service.request.ts +48 -46
  111. package/src/types/interface/api/requests/storage-surplus.admin.request.ts +12 -0
  112. package/src/types/interface/api/responses/function-run.response.ts +35 -18
  113. package/src/types/interface/api/responses/function-settings.response.ts +57 -50
  114. package/src/types/interface/api/responses/index.ts +25 -24
  115. package/src/types/interface/api/responses/storage-surplus.admin.response.ts +10 -0
  116. package/src/types/interface/models/index.ts +29 -27
  117. package/src/types/interface/models/reflex-discord.model.ts +45 -4
  118. package/src/types/interface/models/reflex-run-retention.model.ts +24 -0
  119. package/src/types/interface/models/reflex-run-settings.model.ts +39 -28
  120. package/src/types/interface/models/reflex-run.model.ts +317 -299
  121. package/src/types/interface/models/reflex-service-deployment.model.ts +48 -46
  122. package/src/types/interface/models/reflex-service.model.ts +47 -45
  123. package/src/types/interface/models/reflex-storage-surplus.model.ts +23 -0
@@ -1,291 +1,346 @@
1
- import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
- import {
3
- AbyssReflexCore,
4
- DEFAULT_REFLEX_EXECUTION_SETTINGS,
5
- EXECUTION_PROFILE_MEMORY_MB,
6
- ExecutionMode,
7
- ExecutionProfile,
8
- REFLEX_EXECUTION_SETTINGS_LIMITS,
9
- RESPOND_STATUS_MAX,
10
- RESPOND_STATUS_MIN,
11
- } from '..';
12
-
13
- const APP = 'app-1';
14
- const FN = 'fn-1';
15
- const BASE = `api/function/${APP}/${FN}`;
16
- const SETTINGS = {
17
- profile: ExecutionProfile.L,
18
- responseTimeoutMs: 10_000,
19
- maxDurationMs: 600_000,
20
- mode: ExecutionMode.ASYNC,
21
- };
22
-
23
- interface Call {
24
- label: string;
25
- method: string;
26
- url: string;
27
- body?: unknown;
28
- params?: unknown;
29
- run: () => Promise<unknown>;
30
- }
31
-
32
- const sdk = () => AbyssReflexCore.sdk.function;
33
-
34
- const calls: Call[] = [
35
- {
36
- label: 'list',
37
- method: 'get',
38
- url: `api/function/${APP}`,
39
- run: () => sdk().list({ applicationId: APP }),
40
- },
41
- {
42
- label: 'create',
43
- method: 'post',
44
- url: `api/function/${APP}`,
45
- body: { name: 'hello', serviceId: 's-1' },
46
- run: () => sdk().create({ applicationId: APP }, { name: 'hello', serviceId: 's-1' }),
47
- },
48
- {
49
- label: 'get',
50
- method: 'get',
51
- url: BASE,
52
- run: () => sdk().get({ applicationId: APP, functionId: FN }),
53
- },
54
- {
55
- label: 'update',
56
- method: 'put',
57
- url: BASE,
58
- body: { name: 'renamed' },
59
- run: () => sdk().update({ applicationId: APP, functionId: FN }, { name: 'renamed' }),
60
- },
61
- {
62
- label: 'delete',
63
- method: 'delete',
64
- url: BASE,
65
- run: () => sdk().delete({ applicationId: APP, functionId: FN }),
66
- },
67
- {
68
- label: 'access.list',
69
- method: 'get',
70
- url: `${BASE}/access`,
71
- run: () => sdk().access.list({ applicationId: APP, functionId: FN }),
72
- },
73
- {
74
- label: 'access.grant',
75
- method: 'post',
76
- url: `${BASE}/access`,
77
- body: { declaration: { kind: 'HOST_ACTION', action: 'store.get' } },
78
- run: () =>
79
- sdk().access.grant(
80
- { applicationId: APP, functionId: FN },
81
- { declaration: { kind: 'HOST_ACTION', action: 'store.get' } as never },
82
- ),
83
- },
84
- {
85
- label: 'access.revoke',
86
- method: 'delete',
87
- url: `${BASE}/access/g-1`,
88
- run: () => sdk().access.revoke({ applicationId: APP, functionId: FN, grantId: 'g-1' }),
89
- },
90
- {
91
- label: 'access.grantAll',
92
- method: 'post',
93
- url: `${BASE}/access/grant-all`,
94
- run: () => sdk().access.grantAll({ applicationId: APP, functionId: FN }),
95
- },
96
- {
97
- label: 'access.request',
98
- method: 'post',
99
- url: `${BASE}/access/request`,
100
- body: { declaration: { kind: 'HOST_ACTION', action: 'store.get' } },
101
- run: () =>
102
- sdk().access.request(
103
- { applicationId: APP, functionId: FN },
104
- { declaration: { kind: 'HOST_ACTION', action: 'store.get' } as never },
105
- ),
106
- },
107
- {
108
- label: 'access.grantRequest',
109
- method: 'post',
110
- url: `${BASE}/access/request/q-1/grant`,
111
- run: () => sdk().access.grantRequest({ applicationId: APP, functionId: FN, requestId: 'q-1' }),
112
- },
113
- {
114
- label: 'access.dismissRequest',
115
- method: 'post',
116
- url: `${BASE}/access/request/q-1/dismiss`,
117
- run: () =>
118
- sdk().access.dismissRequest({ applicationId: APP, functionId: FN, requestId: 'q-1' }),
119
- },
120
- {
121
- label: 'version.list',
122
- method: 'get',
123
- url: `${BASE}/version`,
124
- params: { page: 2, limit: 20, number: 3, publishedByUserId: 'u-1', deployed: true },
125
- run: () =>
126
- sdk().version.list(
127
- { applicationId: APP, functionId: FN },
128
- { page: 2, limit: 20, number: 3, publishedByUserId: 'u-1', deployed: true },
129
- ),
130
- },
131
- {
132
- label: 'version.open',
133
- method: 'post',
134
- url: `${BASE}/version/v-1/open`,
135
- run: () => sdk().version.open({ applicationId: APP, functionId: FN, versionId: 'v-1' }),
136
- },
137
- {
138
- label: 'test.simulate',
139
- method: 'post',
140
- url: `${BASE}/test/simulate`,
141
- body: { environmentId: 'e-1', input: { a: 1 } },
142
- run: () =>
143
- sdk().test.simulate(
144
- { applicationId: APP, functionId: FN },
145
- { environmentId: 'e-1', input: { a: 1 } },
146
- ),
147
- },
148
- {
149
- label: 'test.dryRun',
150
- method: 'post',
151
- url: `${BASE}/test/dry-run`,
152
- body: { environmentId: 'e-1' },
153
- run: () => sdk().test.dryRun({ applicationId: APP, functionId: FN }, { environmentId: 'e-1' }),
154
- },
155
- {
156
- label: 'version.get',
157
- method: 'get',
158
- url: `${BASE}/version/v-1`,
159
- run: () => sdk().version.get({ applicationId: APP, functionId: FN, versionId: 'v-1' }),
160
- },
161
- {
162
- label: 'run.list',
163
- method: 'get',
164
- url: `${BASE}/run`,
165
- params: { limit: 5 },
166
- run: () => sdk().run.list({ applicationId: APP, functionId: FN }, { limit: 5 }),
167
- },
168
- {
169
- label: 'run.get',
170
- method: 'get',
171
- url: `${BASE}/run/r-1`,
172
- run: () => sdk().run.get({ applicationId: APP, functionId: FN, runId: 'r-1' }),
173
- },
174
- {
175
- label: 'run.state',
176
- method: 'get',
177
- url: `${BASE}/run/r-1/state`,
178
- run: () => sdk().run.state({ applicationId: APP, functionId: FN, runId: 'r-1' }),
179
- },
180
- {
181
- label: 'version.stepStats',
182
- method: 'get',
183
- url: `${BASE}/version/v-1/step-stats`,
184
- params: { environmentId: 'e-1' },
185
- run: () =>
186
- sdk().version.stepStats(
187
- { applicationId: APP, functionId: FN, versionId: 'v-1' },
188
- { environmentId: 'e-1' },
189
- ),
190
- },
191
- {
192
- label: 'settings.get',
193
- method: 'get',
194
- url: `${BASE}/settings`,
195
- run: () => sdk().settings.get({ applicationId: APP, functionId: FN }),
196
- },
197
- {
198
- label: 'settings.setDefault',
199
- method: 'put',
200
- url: `${BASE}/settings`,
201
- body: SETTINGS,
202
- run: () => sdk().settings.setDefault({ applicationId: APP, functionId: FN }, SETTINGS),
203
- },
204
- {
205
- label: 'settings.setEnvironment',
206
- method: 'put',
207
- url: `${BASE}/settings/e-1`,
208
- body: SETTINGS,
209
- run: () =>
210
- sdk().settings.setEnvironment(
211
- { applicationId: APP, functionId: FN, environmentId: 'e-1' },
212
- SETTINGS,
213
- ),
214
- },
215
- {
216
- label: 'settings.removeEnvironment',
217
- method: 'delete',
218
- url: `${BASE}/settings/e-1`,
219
- run: () =>
220
- sdk().settings.removeEnvironment({
221
- applicationId: APP,
222
- functionId: FN,
223
- environmentId: 'e-1',
224
- }),
225
- },
226
- ];
227
-
228
- describe('AbyssReflexCore function routes', () => {
229
- const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
230
- async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
231
- );
232
-
233
- beforeAll(() => {
234
- AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
235
- AbyssReflexCore.axios.defaults.adapter = adapter;
236
- });
237
-
238
- beforeEach(() => adapter.mockClear());
239
-
240
- it.each(calls)('$label calls $method $url', async (call) => {
241
- await call.run();
242
-
243
- const config = adapter.mock.calls[0][0];
244
- expect(config.method).toBe(call.method);
245
- expect(config.url).toBe(call.url);
246
- expect(config.baseURL).toBe('http://reflex.test/');
247
- expect(config.params).toEqual(call.params);
248
- if (call.body !== undefined) {
249
- expect(JSON.parse(config.data)).toEqual(call.body);
250
- }
251
- });
252
-
253
- it('sends the session token of the member as a bearer token', async () => {
254
- await calls[0].run();
255
-
256
- expect(adapter.mock.calls[0][0].headers.get('Authorization')).toBe('Bearer session-token');
257
- });
258
-
259
- it('exposes no route twice', () => {
260
- expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
261
- });
262
- });
263
-
264
- describe('execution settings constants', () => {
265
- it('give each profile its memory, S to XXL doubling from 128 MB', () => {
266
- expect(Object.values(ExecutionProfile)).toEqual(['S', 'M', 'L', 'XL', 'XXL']);
267
- expect(Object.values(ExecutionProfile).map((p) => EXECUTION_PROFILE_MEMORY_MB[p])).toEqual([
268
- 128, 256, 512, 1024, 2048,
269
- ]);
270
- });
271
-
272
- it('default to S, 30 s, 30 s, SYNC and no completion webhook, within the bounds', () => {
273
- expect(DEFAULT_REFLEX_EXECUTION_SETTINGS).toEqual({
274
- profile: ExecutionProfile.S,
275
- responseTimeoutMs: 30_000,
276
- maxDurationMs: 30_000,
277
- mode: ExecutionMode.SYNC,
278
- completionWebhookUrl: null,
279
- });
280
- expect(REFLEX_EXECUTION_SETTINGS_LIMITS).toEqual({
281
- responseTimeoutMs: { min: 1_000, max: 100_000 },
282
- maxDurationMs: { min: 1_000, max: 3_600_000 },
283
- });
284
- });
285
- });
286
-
287
- describe('respond status bounds', () => {
288
- it('are 200 to 599, the bounds of the runtime', () => {
289
- expect([RESPOND_STATUS_MIN, RESPOND_STATUS_MAX]).toEqual([200, 599]);
290
- });
291
- });
1
+ import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
+ import {
3
+ AbyssReflexCore,
4
+ DEFAULT_REFLEX_EXECUTION_SETTINGS,
5
+ EXECUTION_PROFILE_MEMORY_MB,
6
+ ExecutionMode,
7
+ ExecutionProfile,
8
+ REFLEX_EXECUTION_SETTINGS_LIMITS,
9
+ RESPOND_STATUS_MAX,
10
+ RESPOND_STATUS_MIN,
11
+ REFLEX_RUN_ARCHIVE_AFTER_DAYS,
12
+ REFLEX_RUN_ARCHIVE_MIN_TIER_DAYS,
13
+ REFLEX_RUN_RETENTION_TIER_DAYS,
14
+ REFLEX_VERSIONS_KEPT,
15
+ ReflexErrorCode,
16
+ } from '..';
17
+
18
+ const APP = 'app-1';
19
+ const FN = 'fn-1';
20
+ const BASE = `api/function/${APP}/${FN}`;
21
+ const SETTINGS = {
22
+ profile: ExecutionProfile.L,
23
+ responseTimeoutMs: 10_000,
24
+ maxDurationMs: 600_000,
25
+ mode: ExecutionMode.ASYNC,
26
+ };
27
+
28
+ interface Call {
29
+ label: string;
30
+ method: string;
31
+ url: string;
32
+ body?: unknown;
33
+ params?: unknown;
34
+ run: () => Promise<unknown>;
35
+ }
36
+
37
+ const sdk = () => AbyssReflexCore.sdk.function;
38
+
39
+ const calls: Call[] = [
40
+ {
41
+ label: 'list',
42
+ method: 'get',
43
+ url: `api/function/${APP}`,
44
+ run: () => sdk().list({ applicationId: APP }),
45
+ },
46
+ {
47
+ label: 'create',
48
+ method: 'post',
49
+ url: `api/function/${APP}`,
50
+ body: { name: 'hello', serviceId: 's-1' },
51
+ run: () => sdk().create({ applicationId: APP }, { name: 'hello', serviceId: 's-1' }),
52
+ },
53
+ {
54
+ label: 'get',
55
+ method: 'get',
56
+ url: BASE,
57
+ run: () => sdk().get({ applicationId: APP, functionId: FN }),
58
+ },
59
+ {
60
+ label: 'update',
61
+ method: 'put',
62
+ url: BASE,
63
+ body: { name: 'renamed' },
64
+ run: () => sdk().update({ applicationId: APP, functionId: FN }, { name: 'renamed' }),
65
+ },
66
+ {
67
+ label: 'delete',
68
+ method: 'delete',
69
+ url: BASE,
70
+ run: () => sdk().delete({ applicationId: APP, functionId: FN }),
71
+ },
72
+ {
73
+ label: 'access.list',
74
+ method: 'get',
75
+ url: `${BASE}/access`,
76
+ run: () => sdk().access.list({ applicationId: APP, functionId: FN }),
77
+ },
78
+ {
79
+ label: 'access.grant',
80
+ method: 'post',
81
+ url: `${BASE}/access`,
82
+ body: { declaration: { kind: 'HOST_ACTION', action: 'store.get' } },
83
+ run: () =>
84
+ sdk().access.grant(
85
+ { applicationId: APP, functionId: FN },
86
+ { declaration: { kind: 'HOST_ACTION', action: 'store.get' } as never },
87
+ ),
88
+ },
89
+ {
90
+ label: 'access.revoke',
91
+ method: 'delete',
92
+ url: `${BASE}/access/g-1`,
93
+ run: () => sdk().access.revoke({ applicationId: APP, functionId: FN, grantId: 'g-1' }),
94
+ },
95
+ {
96
+ label: 'access.grantAll',
97
+ method: 'post',
98
+ url: `${BASE}/access/grant-all`,
99
+ run: () => sdk().access.grantAll({ applicationId: APP, functionId: FN }),
100
+ },
101
+ {
102
+ label: 'access.request',
103
+ method: 'post',
104
+ url: `${BASE}/access/request`,
105
+ body: { declaration: { kind: 'HOST_ACTION', action: 'store.get' } },
106
+ run: () =>
107
+ sdk().access.request(
108
+ { applicationId: APP, functionId: FN },
109
+ { declaration: { kind: 'HOST_ACTION', action: 'store.get' } as never },
110
+ ),
111
+ },
112
+ {
113
+ label: 'access.grantRequest',
114
+ method: 'post',
115
+ url: `${BASE}/access/request/q-1/grant`,
116
+ run: () => sdk().access.grantRequest({ applicationId: APP, functionId: FN, requestId: 'q-1' }),
117
+ },
118
+ {
119
+ label: 'access.dismissRequest',
120
+ method: 'post',
121
+ url: `${BASE}/access/request/q-1/dismiss`,
122
+ run: () =>
123
+ sdk().access.dismissRequest({ applicationId: APP, functionId: FN, requestId: 'q-1' }),
124
+ },
125
+ {
126
+ label: 'version.list',
127
+ method: 'get',
128
+ url: `${BASE}/version`,
129
+ params: { page: 2, limit: 20, number: 3, publishedByUserId: 'u-1', deployed: true },
130
+ run: () =>
131
+ sdk().version.list(
132
+ { applicationId: APP, functionId: FN },
133
+ { page: 2, limit: 20, number: 3, publishedByUserId: 'u-1', deployed: true },
134
+ ),
135
+ },
136
+ {
137
+ label: 'version.open',
138
+ method: 'post',
139
+ url: `${BASE}/version/v-1/open`,
140
+ run: () => sdk().version.open({ applicationId: APP, functionId: FN, versionId: 'v-1' }),
141
+ },
142
+ {
143
+ label: 'test.simulate',
144
+ method: 'post',
145
+ url: `${BASE}/test/simulate`,
146
+ body: { environmentId: 'e-1', input: { a: 1 } },
147
+ run: () =>
148
+ sdk().test.simulate(
149
+ { applicationId: APP, functionId: FN },
150
+ { environmentId: 'e-1', input: { a: 1 } },
151
+ ),
152
+ },
153
+ {
154
+ label: 'test.dryRun',
155
+ method: 'post',
156
+ url: `${BASE}/test/dry-run`,
157
+ body: { environmentId: 'e-1' },
158
+ run: () => sdk().test.dryRun({ applicationId: APP, functionId: FN }, { environmentId: 'e-1' }),
159
+ },
160
+ {
161
+ label: 'version.get',
162
+ method: 'get',
163
+ url: `${BASE}/version/v-1`,
164
+ run: () => sdk().version.get({ applicationId: APP, functionId: FN, versionId: 'v-1' }),
165
+ },
166
+ {
167
+ label: 'run.list',
168
+ method: 'get',
169
+ url: `${BASE}/run`,
170
+ params: { limit: 5 },
171
+ run: () => sdk().run.list({ applicationId: APP, functionId: FN }, { limit: 5 }),
172
+ },
173
+ {
174
+ label: 'run.get',
175
+ method: 'get',
176
+ url: `${BASE}/run/r-1`,
177
+ run: () => sdk().run.get({ applicationId: APP, functionId: FN, runId: 'r-1' }),
178
+ },
179
+ {
180
+ label: 'run.state',
181
+ method: 'get',
182
+ url: `${BASE}/run/r-1/state`,
183
+ run: () => sdk().run.state({ applicationId: APP, functionId: FN, runId: 'r-1' }),
184
+ },
185
+ {
186
+ label: 'run.favorite',
187
+ method: 'put',
188
+ url: `${BASE}/run/r-1/favorite`,
189
+ body: { isFavorite: true },
190
+ run: () =>
191
+ sdk().run.favorite(
192
+ { applicationId: APP, functionId: FN, runId: 'r-1' },
193
+ { isFavorite: true },
194
+ ),
195
+ },
196
+ {
197
+ label: 'runRetention.get',
198
+ method: 'get',
199
+ url: `${BASE}/run-retention`,
200
+ run: () => sdk().runRetention.get({ applicationId: APP, functionId: FN }),
201
+ },
202
+ {
203
+ label: 'runRetention.set',
204
+ method: 'put',
205
+ url: `${BASE}/run-retention`,
206
+ body: { runRetentionDays: 90, versionsKept: 30 },
207
+ run: () =>
208
+ sdk().runRetention.set(
209
+ { applicationId: APP, functionId: FN },
210
+ { runRetentionDays: 90, versionsKept: 30 },
211
+ ),
212
+ },
213
+ {
214
+ label: 'version.stepStats',
215
+ method: 'get',
216
+ url: `${BASE}/version/v-1/step-stats`,
217
+ params: { environmentId: 'e-1' },
218
+ run: () =>
219
+ sdk().version.stepStats(
220
+ { applicationId: APP, functionId: FN, versionId: 'v-1' },
221
+ { environmentId: 'e-1' },
222
+ ),
223
+ },
224
+ {
225
+ label: 'settings.get',
226
+ method: 'get',
227
+ url: `${BASE}/settings`,
228
+ run: () => sdk().settings.get({ applicationId: APP, functionId: FN }),
229
+ },
230
+ {
231
+ label: 'settings.setDefault',
232
+ method: 'put',
233
+ url: `${BASE}/settings`,
234
+ body: SETTINGS,
235
+ run: () => sdk().settings.setDefault({ applicationId: APP, functionId: FN }, SETTINGS),
236
+ },
237
+ {
238
+ label: 'settings.setEnvironment',
239
+ method: 'put',
240
+ url: `${BASE}/settings/e-1`,
241
+ body: SETTINGS,
242
+ run: () =>
243
+ sdk().settings.setEnvironment(
244
+ { applicationId: APP, functionId: FN, environmentId: 'e-1' },
245
+ SETTINGS,
246
+ ),
247
+ },
248
+ {
249
+ label: 'settings.removeEnvironment',
250
+ method: 'delete',
251
+ url: `${BASE}/settings/e-1`,
252
+ run: () =>
253
+ sdk().settings.removeEnvironment({
254
+ applicationId: APP,
255
+ functionId: FN,
256
+ environmentId: 'e-1',
257
+ }),
258
+ },
259
+ ];
260
+
261
+ describe('AbyssReflexCore function routes', () => {
262
+ const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
263
+ async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
264
+ );
265
+
266
+ beforeAll(() => {
267
+ AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
268
+ AbyssReflexCore.axios.defaults.adapter = adapter;
269
+ });
270
+
271
+ beforeEach(() => adapter.mockClear());
272
+
273
+ it.each(calls)('$label calls $method $url', async (call) => {
274
+ await call.run();
275
+
276
+ const config = adapter.mock.calls[0][0];
277
+ expect(config.method).toBe(call.method);
278
+ expect(config.url).toBe(call.url);
279
+ expect(config.baseURL).toBe('http://reflex.test/');
280
+ expect(config.params).toEqual(call.params);
281
+ if (call.body !== undefined) {
282
+ expect(JSON.parse(config.data)).toEqual(call.body);
283
+ }
284
+ });
285
+
286
+ it('sends the session token of the member as a bearer token', async () => {
287
+ await calls[0].run();
288
+
289
+ expect(adapter.mock.calls[0][0].headers.get('Authorization')).toBe('Bearer session-token');
290
+ });
291
+
292
+ it('exposes no route twice', () => {
293
+ expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
294
+ });
295
+ });
296
+
297
+ describe('execution settings constants', () => {
298
+ it('give each profile its memory, S to XXL doubling from 128 MB', () => {
299
+ expect(Object.values(ExecutionProfile)).toEqual(['S', 'M', 'L', 'XL', 'XXL']);
300
+ expect(Object.values(ExecutionProfile).map((p) => EXECUTION_PROFILE_MEMORY_MB[p])).toEqual([
301
+ 128, 256, 512, 1024, 2048,
302
+ ]);
303
+ });
304
+
305
+ it('default to S, 30 s, 30 s, SYNC and no completion webhook, within the bounds', () => {
306
+ expect(DEFAULT_REFLEX_EXECUTION_SETTINGS).toEqual({
307
+ profile: ExecutionProfile.S,
308
+ responseTimeoutMs: 30_000,
309
+ maxDurationMs: 30_000,
310
+ mode: ExecutionMode.SYNC,
311
+ completionWebhookUrl: null,
312
+ });
313
+ expect(REFLEX_EXECUTION_SETTINGS_LIMITS).toEqual({
314
+ responseTimeoutMs: { min: 1_000, max: 100_000 },
315
+ maxDurationMs: { min: 1_000, max: 3_600_000 },
316
+ });
317
+ });
318
+ });
319
+
320
+ describe('respond status bounds', () => {
321
+ it('are 200 to 599, the bounds of the runtime', () => {
322
+ expect([RESPOND_STATUS_MIN, RESPOND_STATUS_MAX]).toEqual([200, 599]);
323
+ });
324
+ });
325
+
326
+ describe('run retention constants (L3a)', () => {
327
+ it('list the seven tiers the database accepts', () => {
328
+ expect(REFLEX_RUN_RETENTION_TIER_DAYS).toEqual([3, 7, 15, 30, 90, 180, 365]);
329
+ });
330
+
331
+ it('bound the versions kept to 5 to 100, 20 by default', () => {
332
+ expect(REFLEX_VERSIONS_KEPT).toEqual({ default: 20, min: 5, max: 100 });
333
+ });
334
+
335
+ it('archive the detail past 30 days, for the tiers of 90 days and more', () => {
336
+ expect(REFLEX_RUN_ARCHIVE_AFTER_DAYS).toBe(30);
337
+ expect(REFLEX_RUN_ARCHIVE_MIN_TIER_DAYS).toBe(90);
338
+ expect(
339
+ REFLEX_RUN_RETENTION_TIER_DAYS.filter((d) => d >= REFLEX_RUN_ARCHIVE_MIN_TIER_DAYS),
340
+ ).toEqual([90, 180, 365]);
341
+ });
342
+
343
+ it('name the error of an archive that cannot be read', () => {
344
+ expect(ReflexErrorCode.ARCHIVE_UNAVAILABLE).toBe('ARCHIVE_UNAVAILABLE');
345
+ });
346
+ });