@abyss-project/reflex 5.9.0 → 5.11.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 (177) hide show
  1. package/.eslintrc.js +32 -32
  2. package/.prettierrc +5 -5
  3. package/README.md +15 -15
  4. package/dist/api/function-access.api.d.ts +5 -1
  5. package/dist/api/function-access.api.js +9 -1
  6. package/dist/api/function-access.api.js.map +1 -1
  7. package/dist/api/function-template.api.d.ts +5 -0
  8. package/dist/api/function-template.api.js +15 -0
  9. package/dist/api/function-template.api.js.map +1 -0
  10. package/dist/api/function-version.api.d.ts +3 -2
  11. package/dist/api/function-version.api.js +6 -2
  12. package/dist/api/function-version.api.js.map +1 -1
  13. package/dist/api/index.d.ts +1 -0
  14. package/dist/api/index.js +1 -0
  15. package/dist/api/index.js.map +1 -1
  16. package/dist/index.d.ts +12 -0
  17. package/dist/index.js +12 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/types/enum/access-request-status.enum.d.ts +5 -0
  20. package/dist/types/enum/access-request-status.enum.js +10 -0
  21. package/dist/types/enum/access-request-status.enum.js.map +1 -0
  22. package/dist/types/enum/index.d.ts +2 -0
  23. package/dist/types/enum/index.js +2 -0
  24. package/dist/types/enum/index.js.map +1 -1
  25. package/dist/types/enum/log-drop-cause.enum.d.ts +4 -0
  26. package/dist/types/enum/log-drop-cause.enum.js +9 -0
  27. package/dist/types/enum/log-drop-cause.enum.js.map +1 -0
  28. package/dist/types/interface/api/requests/function-access.request.d.ts +21 -0
  29. package/dist/types/interface/api/requests/function-template.request.d.ts +23 -0
  30. package/dist/types/interface/api/requests/function-template.request.js +3 -0
  31. package/dist/types/interface/api/requests/function-template.request.js.map +1 -0
  32. package/dist/types/interface/api/requests/function-version.request.d.ts +12 -0
  33. package/dist/types/interface/api/requests/index.d.ts +1 -0
  34. package/dist/types/interface/api/requests/index.js +1 -0
  35. package/dist/types/interface/api/requests/index.js.map +1 -1
  36. package/dist/types/interface/api/responses/function-access.response.d.ts +21 -1
  37. package/dist/types/interface/api/responses/function-settings.response.d.ts +1 -0
  38. package/dist/types/interface/api/responses/function-template.response.d.ts +16 -0
  39. package/dist/types/interface/api/responses/function-template.response.js +3 -0
  40. package/dist/types/interface/api/responses/function-template.response.js.map +1 -0
  41. package/dist/types/interface/api/responses/function-version.response.d.ts +7 -2
  42. package/dist/types/interface/api/responses/index.d.ts +1 -0
  43. package/dist/types/interface/api/responses/index.js +1 -0
  44. package/dist/types/interface/api/responses/index.js.map +1 -1
  45. package/dist/types/interface/models/index.d.ts +2 -0
  46. package/dist/types/interface/models/index.js +2 -0
  47. package/dist/types/interface/models/index.js.map +1 -1
  48. package/dist/types/interface/models/reflex-access-request.model.d.ts +13 -0
  49. package/dist/types/interface/models/reflex-access-request.model.js +3 -0
  50. package/dist/types/interface/models/reflex-access-request.model.js.map +1 -0
  51. package/dist/types/interface/models/reflex-function-template.model.d.ts +13 -0
  52. package/dist/types/interface/models/reflex-function-template.model.js +3 -0
  53. package/dist/types/interface/models/reflex-function-template.model.js.map +1 -0
  54. package/dist/types/interface/models/reflex-function-version.model.d.ts +3 -0
  55. package/dist/types/interface/models/reflex-function.model.d.ts +9 -0
  56. package/dist/types/interface/models/reflex-run.model.d.ts +2 -1
  57. package/dist/types/interface/models/reflex-run.model.js.map +1 -1
  58. package/jest.config.ts +11 -11
  59. package/package.json +10 -15
  60. package/src/api/alert-rule.api.test.ts +72 -72
  61. package/src/api/alert-rule.api.ts +57 -57
  62. package/src/api/application-insights.api.test.ts +42 -42
  63. package/src/api/application-insights.api.ts +38 -38
  64. package/src/api/application-run-settings.api.test.ts +51 -51
  65. package/src/api/application-run-settings.api.ts +30 -30
  66. package/src/api/function-access.api.ts +52 -1
  67. package/src/api/function-insights.api.test.ts +27 -27
  68. package/src/api/function-insights.api.ts +18 -18
  69. package/src/api/function-run.api.ts +38 -38
  70. package/src/api/function-settings.api.ts +74 -74
  71. package/src/api/function-template.api.test.ts +72 -0
  72. package/src/api/function-template.api.ts +52 -0
  73. package/src/api/function-test.api.ts +34 -34
  74. package/src/api/function-version.api.ts +20 -2
  75. package/src/api/function.api.test.ts +47 -6
  76. package/src/api/function.api.ts +62 -62
  77. package/src/api/health.api.ts +10 -10
  78. package/src/api/index.ts +1 -0
  79. package/src/api/route-stats.api.test.ts +45 -45
  80. package/src/api/route-stats.api.ts +36 -36
  81. package/src/api/service-configuration.api.ts +16 -16
  82. package/src/api/service-deployment.api.ts +79 -79
  83. package/src/api/service-discord-event.api.test.ts +106 -106
  84. package/src/api/service-discord-event.api.ts +78 -78
  85. package/src/api/service-discord.api.test.ts +197 -197
  86. package/src/api/service-discord.api.ts +241 -241
  87. package/src/api/service-insights.api.test.ts +36 -36
  88. package/src/api/service-insights.api.ts +42 -42
  89. package/src/api/service-route.api.ts +72 -72
  90. package/src/api/service-task.api.test.ts +140 -140
  91. package/src/api/service-task.api.ts +141 -141
  92. package/src/api/service-version.api.ts +54 -54
  93. package/src/api/service.api.test.ts +215 -215
  94. package/src/api/service.api.ts +55 -55
  95. package/src/discord/discord-event-filter-cases.ts +261 -261
  96. package/src/discord/discord-event-filters.test.ts +91 -91
  97. package/src/discord/discord-event-filters.ts +95 -95
  98. package/src/discord/discord-event-intents.test.ts +112 -112
  99. package/src/discord/discord-event-intents.ts +55 -55
  100. package/src/discord/index.ts +3 -3
  101. package/src/index.test.ts +87 -87
  102. package/src/index.ts +24 -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/access-grant-status.enum.ts +12 -12
  107. package/src/types/enum/access-kind.enum.ts +7 -7
  108. package/src/types/enum/access-request-status.enum.ts +11 -0
  109. package/src/types/enum/bot-event-block-reason.enum.ts +7 -7
  110. package/src/types/enum/configuration-read-as.enum.ts +5 -5
  111. package/src/types/enum/discord-activity-type.enum.ts +9 -9
  112. package/src/types/enum/discord-channel-type.enum.ts +11 -11
  113. package/src/types/enum/discord-component-kind.enum.ts +7 -7
  114. package/src/types/enum/discord-event-drop-reason.enum.ts +13 -13
  115. package/src/types/enum/discord-event-filter-name.enum.ts +11 -11
  116. package/src/types/enum/discord-event-status.enum.ts +13 -13
  117. package/src/types/enum/discord-event-type.enum.ts +7 -7
  118. package/src/types/enum/discord-gateway-failure-code.enum.ts +11 -11
  119. package/src/types/enum/discord-gateway-state.enum.ts +11 -11
  120. package/src/types/enum/discord-host-action.enum.ts +35 -35
  121. package/src/types/enum/discord-locale.enum.ts +35 -35
  122. package/src/types/enum/discord-option-type.enum.ts +12 -12
  123. package/src/types/enum/discord-presence-status.enum.ts +8 -8
  124. package/src/types/enum/discord-sync-status.enum.ts +6 -6
  125. package/src/types/enum/discord-token-state.enum.ts +11 -11
  126. package/src/types/enum/execution-mode.enum.ts +9 -9
  127. package/src/types/enum/execution-profile.enum.ts +20 -20
  128. package/src/types/enum/execution-settings-source.enum.ts +9 -9
  129. package/src/types/enum/health-status.enum.ts +4 -4
  130. package/src/types/enum/index.ts +2 -0
  131. package/src/types/enum/insights-period.enum.ts +8 -8
  132. package/src/types/enum/log-cap-mode.enum.ts +6 -6
  133. package/src/types/enum/log-drop-cause.enum.ts +8 -0
  134. package/src/types/enum/reflex-alert-metric.enum.ts +5 -5
  135. package/src/types/enum/reflex-alert-notification-state.enum.ts +6 -6
  136. package/src/types/enum/reflex-alert-scope.enum.ts +6 -6
  137. package/src/types/enum/reflex-error-code.enum.ts +43 -43
  138. package/src/types/enum/route-method.enum.ts +9 -9
  139. package/src/types/enum/run-log-level.enum.ts +6 -6
  140. package/src/types/enum/run-mode.enum.ts +11 -11
  141. package/src/types/enum/run-status.enum.ts +11 -11
  142. package/src/types/enum/run-step-status.enum.ts +7 -7
  143. package/src/types/enum/schedule-sync-status.enum.ts +6 -6
  144. package/src/types/enum/scheduled-run-failure-code.enum.ts +12 -12
  145. package/src/types/enum/scheduled-run-origin.enum.ts +5 -5
  146. package/src/types/enum/scheduled-run-status.enum.ts +17 -17
  147. package/src/types/enum/service-deployment-action.enum.ts +11 -11
  148. package/src/types/enum/service-deployment-status.enum.ts +5 -5
  149. package/src/types/enum/service-type.enum.ts +9 -9
  150. package/src/types/enum/service-version-change-kind.enum.ts +6 -6
  151. package/src/types/enum/trace-effect-type.enum.ts +12 -12
  152. package/src/types/enum/trigger-access-mode.enum.ts +12 -12
  153. package/src/types/enum/trigger-kind.enum.ts +8 -8
  154. package/src/types/enum/vault-value-source.enum.ts +12 -12
  155. package/src/types/enum/vault-visibility.enum.ts +5 -5
  156. package/src/types/index.ts +2 -2
  157. package/src/types/interface/api/index.ts +3 -3
  158. package/src/types/interface/api/requests/function-access.request.ts +26 -0
  159. package/src/types/interface/api/requests/function-template.request.ts +29 -0
  160. package/src/types/interface/api/requests/function-version.request.ts +18 -0
  161. package/src/types/interface/api/requests/index.ts +1 -0
  162. package/src/types/interface/api/response.ts +4 -4
  163. package/src/types/interface/api/responses/function-access.response.ts +29 -1
  164. package/src/types/interface/api/responses/function-settings.response.ts +2 -0
  165. package/src/types/interface/api/responses/function-template.response.ts +21 -0
  166. package/src/types/interface/api/responses/function-version.response.ts +12 -1
  167. package/src/types/interface/api/responses/index.ts +1 -0
  168. package/src/types/interface/health.response.ts +7 -7
  169. package/src/types/interface/index.ts +3 -3
  170. package/src/types/interface/models/index.ts +2 -0
  171. package/src/types/interface/models/reflex-access-request.model.ts +15 -0
  172. package/src/types/interface/models/reflex-function-template.model.ts +18 -0
  173. package/src/types/interface/models/reflex-function-version.model.ts +5 -0
  174. package/src/types/interface/models/reflex-function.model.ts +14 -0
  175. package/src/types/interface/models/reflex-run.model.ts +6 -3
  176. package/tsconfig.check.json +15 -15
  177. package/tsconfig.json +35 -35
@@ -1,51 +1,51 @@
1
- import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
- import { AbyssReflexCore, LogCapMode } from '..';
3
-
4
- const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(async (config) => ({
5
- data: { data: {} },
6
- status: 200,
7
- statusText: '',
8
- headers: {},
9
- config,
10
- }));
11
-
12
- beforeAll(() => {
13
- AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
14
- AbyssReflexCore.axios.defaults.adapter = adapter;
15
- });
16
-
17
- beforeEach(() => adapter.mockClear());
18
-
19
- describe('AbyssReflexCore application run settings routes', () => {
20
- it('runSettings.get calls GET .../run-settings', async () => {
21
- await AbyssReflexCore.sdk.application.runSettings.get({ applicationId: 'app-1' });
22
-
23
- const config = adapter.mock.calls[0][0];
24
- expect(config.method).toBe('get');
25
- expect(config.url).toBe('api/application/app-1/run-settings');
26
- });
27
-
28
- it('runSettings.set calls PUT .../run-settings with the cap', async () => {
29
- await AbyssReflexCore.sdk.application.runSettings.set(
30
- { applicationId: 'app-1' },
31
- { maxLogLinesPerRun: 500 },
32
- );
33
-
34
- const config = adapter.mock.calls[0][0];
35
- expect(config.method).toBe('put');
36
- expect(config.url).toBe('api/application/app-1/run-settings');
37
- expect(JSON.parse(config.data)).toEqual({ maxLogLinesPerRun: 500 });
38
- });
39
-
40
- it('logCap.set calls PUT .../log-cap of the function', async () => {
41
- await AbyssReflexCore.sdk.function.logCap.set(
42
- { applicationId: 'app-1', functionId: 'fn-1' },
43
- { mode: LogCapMode.LIMIT, lines: 50 },
44
- );
45
-
46
- const config = adapter.mock.calls[0][0];
47
- expect(config.method).toBe('put');
48
- expect(config.url).toBe('api/function/app-1/fn-1/log-cap');
49
- expect(JSON.parse(config.data)).toEqual({ mode: 'LIMIT', lines: 50 });
50
- });
51
- });
1
+ import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
+ import { AbyssReflexCore, LogCapMode } from '..';
3
+
4
+ const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(async (config) => ({
5
+ data: { data: {} },
6
+ status: 200,
7
+ statusText: '',
8
+ headers: {},
9
+ config,
10
+ }));
11
+
12
+ beforeAll(() => {
13
+ AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
14
+ AbyssReflexCore.axios.defaults.adapter = adapter;
15
+ });
16
+
17
+ beforeEach(() => adapter.mockClear());
18
+
19
+ describe('AbyssReflexCore application run settings routes', () => {
20
+ it('runSettings.get calls GET .../run-settings', async () => {
21
+ await AbyssReflexCore.sdk.application.runSettings.get({ applicationId: 'app-1' });
22
+
23
+ const config = adapter.mock.calls[0][0];
24
+ expect(config.method).toBe('get');
25
+ expect(config.url).toBe('api/application/app-1/run-settings');
26
+ });
27
+
28
+ it('runSettings.set calls PUT .../run-settings with the cap', async () => {
29
+ await AbyssReflexCore.sdk.application.runSettings.set(
30
+ { applicationId: 'app-1' },
31
+ { maxLogLinesPerRun: 500 },
32
+ );
33
+
34
+ const config = adapter.mock.calls[0][0];
35
+ expect(config.method).toBe('put');
36
+ expect(config.url).toBe('api/application/app-1/run-settings');
37
+ expect(JSON.parse(config.data)).toEqual({ maxLogLinesPerRun: 500 });
38
+ });
39
+
40
+ it('logCap.set calls PUT .../log-cap of the function', async () => {
41
+ await AbyssReflexCore.sdk.function.logCap.set(
42
+ { applicationId: 'app-1', functionId: 'fn-1' },
43
+ { mode: LogCapMode.LIMIT, lines: 50 },
44
+ );
45
+
46
+ const config = adapter.mock.calls[0][0];
47
+ expect(config.method).toBe('put');
48
+ expect(config.url).toBe('api/function/app-1/fn-1/log-cap');
49
+ expect(JSON.parse(config.data)).toEqual({ mode: 'LIMIT', lines: 50 });
50
+ });
51
+ });
@@ -1,30 +1,30 @@
1
- import { AbyssReflexCore } from '..';
2
- import type {
3
- IGetApplicationRunSettingsParams,
4
- IGetApplicationRunSettingsResponse,
5
- ISetApplicationRunSettingsBody,
6
- ISetApplicationRunSettingsParams,
7
- ISetApplicationRunSettingsResponse,
8
- } from '../types';
9
-
10
- const runSettingsUrl = (params: { applicationId: string }): string =>
11
- `api/application/${params.applicationId}/run-settings`;
12
-
13
- /** `GET .../run-settings`: the log cap, the effective retention and whether Monitor is activated. Needs REFLEX_READ. */
14
- export const getApplicationRunSettings = async (
15
- params: IGetApplicationRunSettingsParams,
16
- ): Promise<IGetApplicationRunSettingsResponse> =>
17
- (await AbyssReflexCore.axios.get<IGetApplicationRunSettingsResponse>(runSettingsUrl(params)))
18
- .data;
19
-
20
- /** `PUT .../run-settings`: sets the log cap of the application. Needs REFLEX_FUNCTION_UPDATE. */
21
- export const setApplicationRunSettings = async (
22
- params: ISetApplicationRunSettingsParams,
23
- body: ISetApplicationRunSettingsBody,
24
- ): Promise<ISetApplicationRunSettingsResponse> =>
25
- (
26
- await AbyssReflexCore.axios.put<ISetApplicationRunSettingsResponse>(
27
- runSettingsUrl(params),
28
- body,
29
- )
30
- ).data;
1
+ import { AbyssReflexCore } from '..';
2
+ import type {
3
+ IGetApplicationRunSettingsParams,
4
+ IGetApplicationRunSettingsResponse,
5
+ ISetApplicationRunSettingsBody,
6
+ ISetApplicationRunSettingsParams,
7
+ ISetApplicationRunSettingsResponse,
8
+ } from '../types';
9
+
10
+ const runSettingsUrl = (params: { applicationId: string }): string =>
11
+ `api/application/${params.applicationId}/run-settings`;
12
+
13
+ /** `GET .../run-settings`: the log cap, the effective retention and whether Monitor is activated. Needs REFLEX_READ. */
14
+ export const getApplicationRunSettings = async (
15
+ params: IGetApplicationRunSettingsParams,
16
+ ): Promise<IGetApplicationRunSettingsResponse> =>
17
+ (await AbyssReflexCore.axios.get<IGetApplicationRunSettingsResponse>(runSettingsUrl(params)))
18
+ .data;
19
+
20
+ /** `PUT .../run-settings`: sets the log cap of the application. Needs REFLEX_FUNCTION_UPDATE. */
21
+ export const setApplicationRunSettings = async (
22
+ params: ISetApplicationRunSettingsParams,
23
+ body: ISetApplicationRunSettingsBody,
24
+ ): Promise<ISetApplicationRunSettingsResponse> =>
25
+ (
26
+ await AbyssReflexCore.axios.put<ISetApplicationRunSettingsResponse>(
27
+ runSettingsUrl(params),
28
+ body,
29
+ )
30
+ ).data;
@@ -1,5 +1,14 @@
1
1
  import { AbyssReflexCore } from '..';
2
2
  import type {
3
+ IDismissFunctionAccessRequestParams,
4
+ IDismissFunctionAccessRequestResponse,
5
+ IGrantAllFunctionAccessParams,
6
+ IGrantAllFunctionAccessResponse,
7
+ IGrantFunctionAccessRequestParams,
8
+ IGrantFunctionAccessRequestResponse,
9
+ IRequestFunctionAccessBody,
10
+ IRequestFunctionAccessParams,
11
+ IRequestFunctionAccessResponse,
3
12
  IGrantFunctionAccessBody,
4
13
  IGrantFunctionAccessParams,
5
14
  IGrantFunctionAccessResponse,
@@ -12,7 +21,7 @@ import type {
12
21
  const accessUrl = (params: { applicationId: string; functionId: string }): string =>
13
22
  `api/function/${params.applicationId}/${params.functionId}/access`;
14
23
 
15
- /** `GET .../access`: every access granted to the function, revoked ones included (the journal). Needs REFLEX_READ. */
24
+ /** `GET .../access`: every access granted to the function, revoked ones included (the journal), its requests and the declaration keys the caller may grant. Needs REFLEX_READ. */
16
25
  export const listFunctionAccess = async (
17
26
  params: IListFunctionAccessParams,
18
27
  ): Promise<IListFunctionAccessResponse> =>
@@ -34,3 +43,45 @@ export const revokeFunctionAccess = async (
34
43
  `${accessUrl(params)}/${params.grantId}`,
35
44
  )
36
45
  ).data;
46
+
47
+ /** `POST .../access/grant-all`: grants every declaration of the saved draft the caller may grant and files a pending request for the rest. Needs REFLEX_READ; each grant needs the right of its declaration. */
48
+ export const grantAllFunctionAccess = async (
49
+ params: IGrantAllFunctionAccessParams,
50
+ ): Promise<IGrantAllFunctionAccessResponse> =>
51
+ (
52
+ await AbyssReflexCore.axios.post<IGrantAllFunctionAccessResponse>(
53
+ `${accessUrl(params)}/grant-all`,
54
+ )
55
+ ).data;
56
+
57
+ /** `POST .../access/request`: asks for an access the saved draft declares (`409 ACCESS_NOT_DECLARED` otherwise). Needs REFLEX_READ. */
58
+ export const requestFunctionAccess = async (
59
+ params: IRequestFunctionAccessParams,
60
+ body: IRequestFunctionAccessBody,
61
+ ): Promise<IRequestFunctionAccessResponse> =>
62
+ (
63
+ await AbyssReflexCore.axios.post<IRequestFunctionAccessResponse>(
64
+ `${accessUrl(params)}/request`,
65
+ body,
66
+ )
67
+ ).data;
68
+
69
+ /** `POST .../access/request/:requestId/grant`: grants the access of a pending request. The caller must hold the right the access needs. */
70
+ export const grantFunctionAccessRequest = async (
71
+ params: IGrantFunctionAccessRequestParams,
72
+ ): Promise<IGrantFunctionAccessRequestResponse> =>
73
+ (
74
+ await AbyssReflexCore.axios.post<IGrantFunctionAccessRequestResponse>(
75
+ `${accessUrl(params)}/request/${params.requestId}/grant`,
76
+ )
77
+ ).data;
78
+
79
+ /** `POST .../access/request/:requestId/dismiss`: sets a pending request aside. The caller must hold the right the access needs. */
80
+ export const dismissFunctionAccessRequest = async (
81
+ params: IDismissFunctionAccessRequestParams,
82
+ ): Promise<IDismissFunctionAccessRequestResponse> =>
83
+ (
84
+ await AbyssReflexCore.axios.post<IDismissFunctionAccessRequestResponse>(
85
+ `${accessUrl(params)}/request/${params.requestId}/dismiss`,
86
+ )
87
+ ).data;
@@ -1,27 +1,27 @@
1
- import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
- import { AbyssReflexCore, InsightsPeriod } from '..';
3
-
4
- describe('AbyssReflexCore function insights route', () => {
5
- const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
6
- async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
7
- );
8
-
9
- beforeAll(() => {
10
- AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
11
- AbyssReflexCore.axios.defaults.adapter = adapter;
12
- });
13
-
14
- beforeEach(() => adapter.mockClear());
15
-
16
- it('insights.get calls GET /api/function/:applicationId/:functionId/insights', async () => {
17
- await AbyssReflexCore.sdk.function.insights.get(
18
- { applicationId: 'app-1', functionId: 'fn-1' },
19
- { environmentId: 'e-1', period: InsightsPeriod.HOURS_24 },
20
- );
21
-
22
- const config = adapter.mock.calls[0][0];
23
- expect(config.method).toBe('get');
24
- expect(config.url).toBe('api/function/app-1/fn-1/insights');
25
- expect(config.params).toEqual({ environmentId: 'e-1', period: '24h' });
26
- });
27
- });
1
+ import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
+ import { AbyssReflexCore, InsightsPeriod } from '..';
3
+
4
+ describe('AbyssReflexCore function insights route', () => {
5
+ const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
6
+ async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
7
+ );
8
+
9
+ beforeAll(() => {
10
+ AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
11
+ AbyssReflexCore.axios.defaults.adapter = adapter;
12
+ });
13
+
14
+ beforeEach(() => adapter.mockClear());
15
+
16
+ it('insights.get calls GET /api/function/:applicationId/:functionId/insights', async () => {
17
+ await AbyssReflexCore.sdk.function.insights.get(
18
+ { applicationId: 'app-1', functionId: 'fn-1' },
19
+ { environmentId: 'e-1', period: InsightsPeriod.HOURS_24 },
20
+ );
21
+
22
+ const config = adapter.mock.calls[0][0];
23
+ expect(config.method).toBe('get');
24
+ expect(config.url).toBe('api/function/app-1/fn-1/insights');
25
+ expect(config.params).toEqual({ environmentId: 'e-1', period: '24h' });
26
+ });
27
+ });
@@ -1,18 +1,18 @@
1
- import { AbyssReflexCore } from '..';
2
- import type {
3
- IGetFunctionInsightsParams,
4
- IGetFunctionInsightsQuery,
5
- IGetFunctionInsightsResponse,
6
- } from '../types';
7
-
8
- /** `GET .../function/:applicationId/:functionId/insights`: the dashboard of a function, same shape as a Service's. Needs REFLEX_LOG_READ. */
9
- export const getFunctionInsights = async (
10
- params: IGetFunctionInsightsParams,
11
- query: IGetFunctionInsightsQuery,
12
- ): Promise<IGetFunctionInsightsResponse> =>
13
- (
14
- await AbyssReflexCore.axios.get<IGetFunctionInsightsResponse>(
15
- `api/function/${params.applicationId}/${params.functionId}/insights`,
16
- { params: query },
17
- )
18
- ).data;
1
+ import { AbyssReflexCore } from '..';
2
+ import type {
3
+ IGetFunctionInsightsParams,
4
+ IGetFunctionInsightsQuery,
5
+ IGetFunctionInsightsResponse,
6
+ } from '../types';
7
+
8
+ /** `GET .../function/:applicationId/:functionId/insights`: the dashboard of a function, same shape as a Service's. Needs REFLEX_LOG_READ. */
9
+ export const getFunctionInsights = async (
10
+ params: IGetFunctionInsightsParams,
11
+ query: IGetFunctionInsightsQuery,
12
+ ): Promise<IGetFunctionInsightsResponse> =>
13
+ (
14
+ await AbyssReflexCore.axios.get<IGetFunctionInsightsResponse>(
15
+ `api/function/${params.applicationId}/${params.functionId}/insights`,
16
+ { params: query },
17
+ )
18
+ ).data;
@@ -1,38 +1,38 @@
1
- import { AbyssReflexCore } from '..';
2
- import type {
3
- IGetFunctionRunParams,
4
- IGetFunctionRunResponse,
5
- IGetFunctionRunStateParams,
6
- IGetFunctionRunStateResponse,
7
- IListFunctionRunParams,
8
- IListFunctionRunQuery,
9
- IListFunctionRunResponse,
10
- } from '../types';
11
-
12
- const runUrl = (params: { applicationId: string; functionId: string }): string =>
13
- `api/function/${params.applicationId}/${params.functionId}/run`;
14
-
15
- /** `GET .../run`: the test runs (kept: the last 10, then 7 days) and the live executions of the edge (7 days), merged, newest first, paged by `limit`/`offset`. Needs REFLEX_LOG_READ. */
16
- export const listFunctionRun = async (
17
- params: IListFunctionRunParams,
18
- query: IListFunctionRunQuery = {},
19
- ): Promise<IListFunctionRunResponse> =>
20
- (await AbyssReflexCore.axios.get<IListFunctionRunResponse>(runUrl(params), { params: query }))
21
- .data;
22
-
23
- /** `GET .../run/:runId`: one run; a live one with its measures and its steps. Needs REFLEX_LOG_READ. */
24
- export const getFunctionRun = async (
25
- params: IGetFunctionRunParams,
26
- ): Promise<IGetFunctionRunResponse> =>
27
- (await AbyssReflexCore.axios.get<IGetFunctionRunResponse>(`${runUrl(params)}/${params.runId}`))
28
- .data;
29
-
30
- /** `GET .../run/:runId/state`: the state of a live execution, the one an async route answered with. Needs REFLEX_LOG_READ. */
31
- export const getFunctionRunState = async (
32
- params: IGetFunctionRunStateParams,
33
- ): Promise<IGetFunctionRunStateResponse> =>
34
- (
35
- await AbyssReflexCore.axios.get<IGetFunctionRunStateResponse>(
36
- `${runUrl(params)}/${params.runId}/state`,
37
- )
38
- ).data;
1
+ import { AbyssReflexCore } from '..';
2
+ import type {
3
+ IGetFunctionRunParams,
4
+ IGetFunctionRunResponse,
5
+ IGetFunctionRunStateParams,
6
+ IGetFunctionRunStateResponse,
7
+ IListFunctionRunParams,
8
+ IListFunctionRunQuery,
9
+ IListFunctionRunResponse,
10
+ } from '../types';
11
+
12
+ const runUrl = (params: { applicationId: string; functionId: string }): string =>
13
+ `api/function/${params.applicationId}/${params.functionId}/run`;
14
+
15
+ /** `GET .../run`: the test runs (kept: the last 10, then 7 days) and the live executions of the edge (7 days), merged, newest first, paged by `limit`/`offset`. Needs REFLEX_LOG_READ. */
16
+ export const listFunctionRun = async (
17
+ params: IListFunctionRunParams,
18
+ query: IListFunctionRunQuery = {},
19
+ ): Promise<IListFunctionRunResponse> =>
20
+ (await AbyssReflexCore.axios.get<IListFunctionRunResponse>(runUrl(params), { params: query }))
21
+ .data;
22
+
23
+ /** `GET .../run/:runId`: one run; a live one with its measures and its steps. Needs REFLEX_LOG_READ. */
24
+ export const getFunctionRun = async (
25
+ params: IGetFunctionRunParams,
26
+ ): Promise<IGetFunctionRunResponse> =>
27
+ (await AbyssReflexCore.axios.get<IGetFunctionRunResponse>(`${runUrl(params)}/${params.runId}`))
28
+ .data;
29
+
30
+ /** `GET .../run/:runId/state`: the state of a live execution, the one an async route answered with. Needs REFLEX_LOG_READ. */
31
+ export const getFunctionRunState = async (
32
+ params: IGetFunctionRunStateParams,
33
+ ): Promise<IGetFunctionRunStateResponse> =>
34
+ (
35
+ await AbyssReflexCore.axios.get<IGetFunctionRunStateResponse>(
36
+ `${runUrl(params)}/${params.runId}/state`,
37
+ )
38
+ ).data;
@@ -1,74 +1,74 @@
1
- import { AbyssReflexCore } from '..';
2
- import type {
3
- IGetFunctionSettingsParams,
4
- IGetFunctionSettingsResponse,
5
- IRemoveFunctionEnvironmentSettingsParams,
6
- IRemoveFunctionEnvironmentSettingsResponse,
7
- ISetFunctionDefaultSettingsBody,
8
- ISetFunctionDefaultSettingsParams,
9
- ISetFunctionDefaultSettingsResponse,
10
- ISetFunctionEnvironmentSettingsBody,
11
- ISetFunctionEnvironmentSettingsParams,
12
- ISetFunctionEnvironmentSettingsResponse,
13
- ISetFunctionLogCapBody,
14
- ISetFunctionLogCapParams,
15
- ISetFunctionLogCapResponse,
16
- } from '../types';
17
-
18
- const settingsUrl = (params: { applicationId: string; functionId: string }): string =>
19
- `api/function/${params.applicationId}/${params.functionId}/settings`;
20
-
21
- /** `GET .../settings`: the default, the overrides, and what each environment runs with. Needs REFLEX_READ. */
22
- export const getFunctionSettings = async (
23
- params: IGetFunctionSettingsParams,
24
- ): Promise<IGetFunctionSettingsResponse> =>
25
- (await AbyssReflexCore.axios.get<IGetFunctionSettingsResponse>(settingsUrl(params))).data;
26
-
27
- /**
28
- * `PUT .../settings`: sets the default of every environment without an override, applied at once where the
29
- * function runs. Needs REFLEX_FUNCTION_UPDATE, and REFLEX_PUBLISH_PRODUCTION when the default applies to a
30
- * production environment where the function runs.
31
- */
32
- export const setFunctionDefaultSettings = async (
33
- params: ISetFunctionDefaultSettingsParams,
34
- body: ISetFunctionDefaultSettingsBody,
35
- ): Promise<ISetFunctionDefaultSettingsResponse> =>
36
- (await AbyssReflexCore.axios.put<ISetFunctionDefaultSettingsResponse>(settingsUrl(params), body))
37
- .data;
38
-
39
- /**
40
- * `PUT .../settings/:environmentId`: sets the override of one environment. Needs REFLEX_FUNCTION_UPDATE, and
41
- * REFLEX_PUBLISH_PRODUCTION for a production environment.
42
- */
43
- export const setFunctionEnvironmentSettings = async (
44
- params: ISetFunctionEnvironmentSettingsParams,
45
- body: ISetFunctionEnvironmentSettingsBody,
46
- ): Promise<ISetFunctionEnvironmentSettingsResponse> =>
47
- (
48
- await AbyssReflexCore.axios.put<ISetFunctionEnvironmentSettingsResponse>(
49
- `${settingsUrl(params)}/${params.environmentId}`,
50
- body,
51
- )
52
- ).data;
53
-
54
- /** `DELETE .../settings/:environmentId`: the environment falls back on the default. Same rights as setting it. */
55
- export const removeFunctionEnvironmentSettings = async (
56
- params: IRemoveFunctionEnvironmentSettingsParams,
57
- ): Promise<IRemoveFunctionEnvironmentSettingsResponse> =>
58
- (
59
- await AbyssReflexCore.axios.delete<IRemoveFunctionEnvironmentSettingsResponse>(
60
- `${settingsUrl(params)}/${params.environmentId}`,
61
- )
62
- ).data;
63
-
64
- /** `PUT .../log-cap`: sets the log cap of the function (inherit, none, or a number of lines). Needs REFLEX_FUNCTION_UPDATE. */
65
- export const setFunctionLogCap = async (
66
- params: ISetFunctionLogCapParams,
67
- body: ISetFunctionLogCapBody,
68
- ): Promise<ISetFunctionLogCapResponse> =>
69
- (
70
- await AbyssReflexCore.axios.put<ISetFunctionLogCapResponse>(
71
- `api/function/${params.applicationId}/${params.functionId}/log-cap`,
72
- body,
73
- )
74
- ).data;
1
+ import { AbyssReflexCore } from '..';
2
+ import type {
3
+ IGetFunctionSettingsParams,
4
+ IGetFunctionSettingsResponse,
5
+ IRemoveFunctionEnvironmentSettingsParams,
6
+ IRemoveFunctionEnvironmentSettingsResponse,
7
+ ISetFunctionDefaultSettingsBody,
8
+ ISetFunctionDefaultSettingsParams,
9
+ ISetFunctionDefaultSettingsResponse,
10
+ ISetFunctionEnvironmentSettingsBody,
11
+ ISetFunctionEnvironmentSettingsParams,
12
+ ISetFunctionEnvironmentSettingsResponse,
13
+ ISetFunctionLogCapBody,
14
+ ISetFunctionLogCapParams,
15
+ ISetFunctionLogCapResponse,
16
+ } from '../types';
17
+
18
+ const settingsUrl = (params: { applicationId: string; functionId: string }): string =>
19
+ `api/function/${params.applicationId}/${params.functionId}/settings`;
20
+
21
+ /** `GET .../settings`: the default, the overrides, and what each environment runs with. Needs REFLEX_READ. */
22
+ export const getFunctionSettings = async (
23
+ params: IGetFunctionSettingsParams,
24
+ ): Promise<IGetFunctionSettingsResponse> =>
25
+ (await AbyssReflexCore.axios.get<IGetFunctionSettingsResponse>(settingsUrl(params))).data;
26
+
27
+ /**
28
+ * `PUT .../settings`: sets the default of every environment without an override, applied at once where the
29
+ * function runs. Needs REFLEX_FUNCTION_UPDATE, and REFLEX_PUBLISH_PRODUCTION when the default applies to a
30
+ * production environment where the function runs.
31
+ */
32
+ export const setFunctionDefaultSettings = async (
33
+ params: ISetFunctionDefaultSettingsParams,
34
+ body: ISetFunctionDefaultSettingsBody,
35
+ ): Promise<ISetFunctionDefaultSettingsResponse> =>
36
+ (await AbyssReflexCore.axios.put<ISetFunctionDefaultSettingsResponse>(settingsUrl(params), body))
37
+ .data;
38
+
39
+ /**
40
+ * `PUT .../settings/:environmentId`: sets the override of one environment. Needs REFLEX_FUNCTION_UPDATE, and
41
+ * REFLEX_PUBLISH_PRODUCTION for a production environment.
42
+ */
43
+ export const setFunctionEnvironmentSettings = async (
44
+ params: ISetFunctionEnvironmentSettingsParams,
45
+ body: ISetFunctionEnvironmentSettingsBody,
46
+ ): Promise<ISetFunctionEnvironmentSettingsResponse> =>
47
+ (
48
+ await AbyssReflexCore.axios.put<ISetFunctionEnvironmentSettingsResponse>(
49
+ `${settingsUrl(params)}/${params.environmentId}`,
50
+ body,
51
+ )
52
+ ).data;
53
+
54
+ /** `DELETE .../settings/:environmentId`: the environment falls back on the default. Same rights as setting it. */
55
+ export const removeFunctionEnvironmentSettings = async (
56
+ params: IRemoveFunctionEnvironmentSettingsParams,
57
+ ): Promise<IRemoveFunctionEnvironmentSettingsResponse> =>
58
+ (
59
+ await AbyssReflexCore.axios.delete<IRemoveFunctionEnvironmentSettingsResponse>(
60
+ `${settingsUrl(params)}/${params.environmentId}`,
61
+ )
62
+ ).data;
63
+
64
+ /** `PUT .../log-cap`: sets the log cap of the function (inherit, none, or a number of lines). Needs REFLEX_FUNCTION_UPDATE. */
65
+ export const setFunctionLogCap = async (
66
+ params: ISetFunctionLogCapParams,
67
+ body: ISetFunctionLogCapBody,
68
+ ): Promise<ISetFunctionLogCapResponse> =>
69
+ (
70
+ await AbyssReflexCore.axios.put<ISetFunctionLogCapResponse>(
71
+ `api/function/${params.applicationId}/${params.functionId}/log-cap`,
72
+ body,
73
+ )
74
+ ).data;
@@ -0,0 +1,72 @@
1
+ import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
2
+ import { AbyssReflexCore } from '..';
3
+
4
+ const APP = 'app-1';
5
+ const BASE = `api/function-template/${APP}`;
6
+
7
+ interface Call {
8
+ label: string;
9
+ method: string;
10
+ url: string;
11
+ body?: unknown;
12
+ run: () => Promise<unknown>;
13
+ }
14
+
15
+ const sdk = () => AbyssReflexCore.sdk.functionTemplate;
16
+
17
+ const calls: Call[] = [
18
+ { label: 'list', method: 'get', url: BASE, run: () => sdk().list({ applicationId: APP }) },
19
+ {
20
+ label: 'create',
21
+ method: 'post',
22
+ url: BASE,
23
+ body: { name: 'Hook', description: 'A webhook', functionId: 'fn-1' },
24
+ run: () =>
25
+ sdk().create(
26
+ { applicationId: APP },
27
+ { name: 'Hook', description: 'A webhook', functionId: 'fn-1' },
28
+ ),
29
+ },
30
+ {
31
+ label: 'update',
32
+ method: 'patch',
33
+ url: `${BASE}/t-1`,
34
+ body: { name: 'Renamed' },
35
+ run: () => sdk().update({ applicationId: APP, templateId: 't-1' }, { name: 'Renamed' }),
36
+ },
37
+ {
38
+ label: 'delete',
39
+ method: 'delete',
40
+ url: `${BASE}/t-1`,
41
+ run: () => sdk().delete({ applicationId: APP, templateId: 't-1' }),
42
+ },
43
+ ];
44
+
45
+ describe('AbyssReflexCore function template routes', () => {
46
+ const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
47
+ async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
48
+ );
49
+
50
+ beforeAll(() => {
51
+ AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
52
+ AbyssReflexCore.axios.defaults.adapter = adapter;
53
+ });
54
+
55
+ beforeEach(() => adapter.mockClear());
56
+
57
+ it.each(calls)('$label calls $method $url', async (call) => {
58
+ await call.run();
59
+
60
+ const config = adapter.mock.calls[0][0];
61
+ expect(config.method).toBe(call.method);
62
+ expect(config.url).toBe(call.url);
63
+ expect(config.baseURL).toBe('http://reflex.test/');
64
+ if (call.body !== undefined) {
65
+ expect(JSON.parse(config.data)).toEqual(call.body);
66
+ }
67
+ });
68
+
69
+ it('exposes no route twice', () => {
70
+ expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
71
+ });
72
+ });