@abyss-project/reflex 5.2.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/service-task.api.d.ts +9 -0
- package/dist/api/service-task.api.js +24 -0
- package/dist/api/service-task.api.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/types/enum/index.d.ts +2 -0
- package/dist/types/enum/index.js +2 -0
- package/dist/types/enum/index.js.map +1 -1
- package/dist/types/enum/reflex-error-code.enum.d.ts +2 -1
- package/dist/types/enum/reflex-error-code.enum.js +1 -0
- package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
- package/dist/types/enum/schedule-sync-status.enum.d.ts +5 -0
- package/dist/types/enum/schedule-sync-status.enum.js +10 -0
- package/dist/types/enum/schedule-sync-status.enum.js.map +1 -0
- package/dist/types/enum/scheduled-run-origin.enum.d.ts +4 -0
- package/dist/types/enum/scheduled-run-origin.enum.js +9 -0
- package/dist/types/enum/scheduled-run-origin.enum.js.map +1 -0
- package/dist/types/interface/api/requests/function-run.request.d.ts +2 -0
- package/dist/types/interface/api/requests/function-test.request.d.ts +4 -0
- package/dist/types/interface/api/requests/index.d.ts +1 -0
- package/dist/types/interface/api/requests/index.js +1 -0
- package/dist/types/interface/api/requests/index.js.map +1 -1
- package/dist/types/interface/api/requests/service-task.request.d.ts +54 -0
- package/dist/types/interface/api/requests/service-task.request.js +3 -0
- package/dist/types/interface/api/requests/service-task.request.js.map +1 -0
- package/dist/types/interface/api/responses/index.d.ts +1 -0
- package/dist/types/interface/api/responses/index.js +1 -0
- package/dist/types/interface/api/responses/index.js.map +1 -1
- package/dist/types/interface/api/responses/service-task.response.d.ts +31 -0
- package/dist/types/interface/api/responses/service-task.response.js +3 -0
- package/dist/types/interface/api/responses/service-task.response.js.map +1 -0
- package/dist/types/interface/api/responses/service-version.response.d.ts +9 -1
- package/dist/types/interface/models/index.d.ts +1 -0
- package/dist/types/interface/models/index.js +1 -0
- package/dist/types/interface/models/index.js.map +1 -1
- package/dist/types/interface/models/reflex-run.model.d.ts +3 -1
- package/dist/types/interface/models/reflex-service-deployment.model.d.ts +4 -1
- package/dist/types/interface/models/reflex-service-version.model.d.ts +2 -0
- package/dist/types/interface/models/reflex-task.model.d.ts +35 -0
- package/dist/types/interface/models/reflex-task.model.js +15 -0
- package/dist/types/interface/models/reflex-task.model.js.map +1 -0
- package/package.json +1 -1
- package/src/api/function-access.api.ts +36 -36
- package/src/api/function-run.api.ts +38 -38
- package/src/api/function-settings.api.ts +59 -59
- package/src/api/function-test.api.ts +34 -34
- package/src/api/function-version.api.ts +48 -48
- package/src/api/function.api.test.ts +249 -249
- package/src/api/function.api.ts +62 -62
- package/src/api/health.api.ts +10 -10
- package/src/api/index.ts +14 -13
- package/src/api/service-configuration.api.ts +16 -16
- package/src/api/service-deployment.api.ts +79 -79
- package/src/api/service-discord.api.test.ts +170 -170
- package/src/api/service-discord.api.ts +203 -203
- package/src/api/service-route.api.ts +72 -72
- package/src/api/service-task.api.test.ts +124 -0
- package/src/api/service-task.api.ts +122 -0
- package/src/api/service-version.api.ts +54 -54
- package/src/api/service.api.test.ts +215 -215
- package/src/api/service.api.ts +55 -55
- package/src/index.ts +264 -237
- package/src/types/enum/index.ts +2 -0
- package/src/types/enum/reflex-error-code.enum.ts +2 -0
- package/src/types/enum/schedule-sync-status.enum.ts +6 -0
- package/src/types/enum/scheduled-run-origin.enum.ts +5 -0
- package/src/types/interface/api/requests/function-run.request.ts +4 -0
- package/src/types/interface/api/requests/function-test.request.ts +16 -1
- package/src/types/interface/api/requests/index.ts +1 -0
- package/src/types/interface/api/requests/service-task.request.ts +66 -0
- package/src/types/interface/api/requests/service-version.request.ts +24 -24
- package/src/types/interface/api/responses/index.ts +1 -0
- package/src/types/interface/api/responses/service-task.response.ts +48 -0
- package/src/types/interface/api/responses/service-version.response.ts +91 -73
- package/src/types/interface/models/index.ts +1 -0
- package/src/types/interface/models/reflex-run.model.ts +7 -1
- package/src/types/interface/models/reflex-service-deployment.model.ts +6 -0
- package/src/types/interface/models/reflex-service-version.model.ts +3 -0
- package/src/types/interface/models/reflex-task.model.ts +61 -0
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { AbyssReflexCore } from '..';
|
|
2
|
-
import type { IListServiceConfigurationParams, IListServiceConfigurationResponse } from '../types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* `GET .../configuration`: per key the functions of the Service read (draft and versions in service),
|
|
6
|
-
* and per environment of the application, where the Console vault gets its value from; never a value.
|
|
7
|
-
* Needs REFLEX_READ, and SECRET_READ on the project (Console re-checks it).
|
|
8
|
-
*/
|
|
9
|
-
export const listServiceConfiguration = async (
|
|
10
|
-
params: IListServiceConfigurationParams,
|
|
11
|
-
): Promise<IListServiceConfigurationResponse> =>
|
|
12
|
-
(
|
|
13
|
-
await AbyssReflexCore.axios.get<IListServiceConfigurationResponse>(
|
|
14
|
-
`api/service/${params.applicationId}/${params.serviceId}/configuration`,
|
|
15
|
-
)
|
|
16
|
-
).data;
|
|
1
|
+
import { AbyssReflexCore } from '..';
|
|
2
|
+
import type { IListServiceConfigurationParams, IListServiceConfigurationResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `GET .../configuration`: per key the functions of the Service read (draft and versions in service),
|
|
6
|
+
* and per environment of the application, where the Console vault gets its value from; never a value.
|
|
7
|
+
* Needs REFLEX_READ, and SECRET_READ on the project (Console re-checks it).
|
|
8
|
+
*/
|
|
9
|
+
export const listServiceConfiguration = async (
|
|
10
|
+
params: IListServiceConfigurationParams,
|
|
11
|
+
): Promise<IListServiceConfigurationResponse> =>
|
|
12
|
+
(
|
|
13
|
+
await AbyssReflexCore.axios.get<IListServiceConfigurationResponse>(
|
|
14
|
+
`api/service/${params.applicationId}/${params.serviceId}/configuration`,
|
|
15
|
+
)
|
|
16
|
+
).data;
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { AbyssReflexCore } from '..';
|
|
2
|
-
import type {
|
|
3
|
-
IGoLiveServiceBody,
|
|
4
|
-
IGoLiveServiceParams,
|
|
5
|
-
IGoLiveServiceResponse,
|
|
6
|
-
IListServiceDeploymentParams,
|
|
7
|
-
IListServiceDeploymentQuery,
|
|
8
|
-
IListServiceDeploymentResponse,
|
|
9
|
-
IPauseServiceBody,
|
|
10
|
-
IPauseServiceParams,
|
|
11
|
-
IPauseServiceResponse,
|
|
12
|
-
IResumeServiceBody,
|
|
13
|
-
IResumeServiceParams,
|
|
14
|
-
IResumeServiceResponse,
|
|
15
|
-
IRollbackServiceBody,
|
|
16
|
-
IRollbackServiceParams,
|
|
17
|
-
IRollbackServiceResponse,
|
|
18
|
-
} from '../types';
|
|
19
|
-
|
|
20
|
-
const deploymentUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
21
|
-
`api/service/${params.applicationId}/${params.serviceId}/deployment`;
|
|
22
|
-
|
|
23
|
-
/** `GET .../deployment`: the current deployment per environment and a page of the history. Needs REFLEX_READ. */
|
|
24
|
-
export const listServiceDeployment = async (
|
|
25
|
-
params: IListServiceDeploymentParams,
|
|
26
|
-
query: IListServiceDeploymentQuery = {},
|
|
27
|
-
): Promise<IListServiceDeploymentResponse> =>
|
|
28
|
-
(
|
|
29
|
-
await AbyssReflexCore.axios.get<IListServiceDeploymentResponse>(deploymentUrl(params), {
|
|
30
|
-
params: query,
|
|
31
|
-
})
|
|
32
|
-
).data;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* `POST .../deployment/go-live`: puts a version in service in an environment, in one transaction. Needs
|
|
36
|
-
* REFLEX_PUBLISH, and REFLEX_PUBLISH_PRODUCTION in a production environment.
|
|
37
|
-
*/
|
|
38
|
-
export const goLiveService = async (
|
|
39
|
-
params: IGoLiveServiceParams,
|
|
40
|
-
body: IGoLiveServiceBody,
|
|
41
|
-
): Promise<IGoLiveServiceResponse> =>
|
|
42
|
-
(
|
|
43
|
-
await AbyssReflexCore.axios.post<IGoLiveServiceResponse>(
|
|
44
|
-
`${deploymentUrl(params)}/go-live`,
|
|
45
|
-
body,
|
|
46
|
-
)
|
|
47
|
-
).data;
|
|
48
|
-
|
|
49
|
-
/** `POST .../deployment/rollback`: puts back the version of a deployment of the history. Rights as go-live. */
|
|
50
|
-
export const rollbackService = async (
|
|
51
|
-
params: IRollbackServiceParams,
|
|
52
|
-
body: IRollbackServiceBody,
|
|
53
|
-
): Promise<IRollbackServiceResponse> =>
|
|
54
|
-
(
|
|
55
|
-
await AbyssReflexCore.axios.post<IRollbackServiceResponse>(
|
|
56
|
-
`${deploymentUrl(params)}/rollback`,
|
|
57
|
-
body,
|
|
58
|
-
)
|
|
59
|
-
).data;
|
|
60
|
-
|
|
61
|
-
/** `POST .../deployment/pause`: every call answers `503 SERVICE_PAUSED`. Rights as go-live. */
|
|
62
|
-
export const pauseService = async (
|
|
63
|
-
params: IPauseServiceParams,
|
|
64
|
-
body: IPauseServiceBody,
|
|
65
|
-
): Promise<IPauseServiceResponse> =>
|
|
66
|
-
(await AbyssReflexCore.axios.post<IPauseServiceResponse>(`${deploymentUrl(params)}/pause`, body))
|
|
67
|
-
.data;
|
|
68
|
-
|
|
69
|
-
/** `POST .../deployment/resume`: the paused version answers again. Rights as go-live. */
|
|
70
|
-
export const resumeService = async (
|
|
71
|
-
params: IResumeServiceParams,
|
|
72
|
-
body: IResumeServiceBody,
|
|
73
|
-
): Promise<IResumeServiceResponse> =>
|
|
74
|
-
(
|
|
75
|
-
await AbyssReflexCore.axios.post<IResumeServiceResponse>(
|
|
76
|
-
`${deploymentUrl(params)}/resume`,
|
|
77
|
-
body,
|
|
78
|
-
)
|
|
79
|
-
).data;
|
|
1
|
+
import { AbyssReflexCore } from '..';
|
|
2
|
+
import type {
|
|
3
|
+
IGoLiveServiceBody,
|
|
4
|
+
IGoLiveServiceParams,
|
|
5
|
+
IGoLiveServiceResponse,
|
|
6
|
+
IListServiceDeploymentParams,
|
|
7
|
+
IListServiceDeploymentQuery,
|
|
8
|
+
IListServiceDeploymentResponse,
|
|
9
|
+
IPauseServiceBody,
|
|
10
|
+
IPauseServiceParams,
|
|
11
|
+
IPauseServiceResponse,
|
|
12
|
+
IResumeServiceBody,
|
|
13
|
+
IResumeServiceParams,
|
|
14
|
+
IResumeServiceResponse,
|
|
15
|
+
IRollbackServiceBody,
|
|
16
|
+
IRollbackServiceParams,
|
|
17
|
+
IRollbackServiceResponse,
|
|
18
|
+
} from '../types';
|
|
19
|
+
|
|
20
|
+
const deploymentUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
21
|
+
`api/service/${params.applicationId}/${params.serviceId}/deployment`;
|
|
22
|
+
|
|
23
|
+
/** `GET .../deployment`: the current deployment per environment and a page of the history. Needs REFLEX_READ. */
|
|
24
|
+
export const listServiceDeployment = async (
|
|
25
|
+
params: IListServiceDeploymentParams,
|
|
26
|
+
query: IListServiceDeploymentQuery = {},
|
|
27
|
+
): Promise<IListServiceDeploymentResponse> =>
|
|
28
|
+
(
|
|
29
|
+
await AbyssReflexCore.axios.get<IListServiceDeploymentResponse>(deploymentUrl(params), {
|
|
30
|
+
params: query,
|
|
31
|
+
})
|
|
32
|
+
).data;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* `POST .../deployment/go-live`: puts a version in service in an environment, in one transaction. Needs
|
|
36
|
+
* REFLEX_PUBLISH, and REFLEX_PUBLISH_PRODUCTION in a production environment.
|
|
37
|
+
*/
|
|
38
|
+
export const goLiveService = async (
|
|
39
|
+
params: IGoLiveServiceParams,
|
|
40
|
+
body: IGoLiveServiceBody,
|
|
41
|
+
): Promise<IGoLiveServiceResponse> =>
|
|
42
|
+
(
|
|
43
|
+
await AbyssReflexCore.axios.post<IGoLiveServiceResponse>(
|
|
44
|
+
`${deploymentUrl(params)}/go-live`,
|
|
45
|
+
body,
|
|
46
|
+
)
|
|
47
|
+
).data;
|
|
48
|
+
|
|
49
|
+
/** `POST .../deployment/rollback`: puts back the version of a deployment of the history. Rights as go-live. */
|
|
50
|
+
export const rollbackService = async (
|
|
51
|
+
params: IRollbackServiceParams,
|
|
52
|
+
body: IRollbackServiceBody,
|
|
53
|
+
): Promise<IRollbackServiceResponse> =>
|
|
54
|
+
(
|
|
55
|
+
await AbyssReflexCore.axios.post<IRollbackServiceResponse>(
|
|
56
|
+
`${deploymentUrl(params)}/rollback`,
|
|
57
|
+
body,
|
|
58
|
+
)
|
|
59
|
+
).data;
|
|
60
|
+
|
|
61
|
+
/** `POST .../deployment/pause`: every call answers `503 SERVICE_PAUSED`. Rights as go-live. */
|
|
62
|
+
export const pauseService = async (
|
|
63
|
+
params: IPauseServiceParams,
|
|
64
|
+
body: IPauseServiceBody,
|
|
65
|
+
): Promise<IPauseServiceResponse> =>
|
|
66
|
+
(await AbyssReflexCore.axios.post<IPauseServiceResponse>(`${deploymentUrl(params)}/pause`, body))
|
|
67
|
+
.data;
|
|
68
|
+
|
|
69
|
+
/** `POST .../deployment/resume`: the paused version answers again. Rights as go-live. */
|
|
70
|
+
export const resumeService = async (
|
|
71
|
+
params: IResumeServiceParams,
|
|
72
|
+
body: IResumeServiceBody,
|
|
73
|
+
): Promise<IResumeServiceResponse> =>
|
|
74
|
+
(
|
|
75
|
+
await AbyssReflexCore.axios.post<IResumeServiceResponse>(
|
|
76
|
+
`${deploymentUrl(params)}/resume`,
|
|
77
|
+
body,
|
|
78
|
+
)
|
|
79
|
+
).data;
|
|
@@ -1,170 +1,170 @@
|
|
|
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.check',
|
|
129
|
-
method: 'post',
|
|
130
|
-
url: `${BASE}/discord/connection/e-1/check`,
|
|
131
|
-
body: {},
|
|
132
|
-
run: () => discord().connection.check({ ...SERVICE, environmentId: 'e-1' }),
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
label: 'sync',
|
|
136
|
-
method: 'post',
|
|
137
|
-
url: `${BASE}/deployment/e-1/discord-sync`,
|
|
138
|
-
body: {},
|
|
139
|
-
run: () => discord().sync({ ...SERVICE, environmentId: 'e-1' }),
|
|
140
|
-
},
|
|
141
|
-
];
|
|
142
|
-
|
|
143
|
-
describe('AbyssReflexCore Discord bot routes', () => {
|
|
144
|
-
const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
|
|
145
|
-
async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
beforeAll(() => {
|
|
149
|
-
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
|
|
150
|
-
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
beforeEach(() => adapter.mockClear());
|
|
154
|
-
|
|
155
|
-
it.each(calls)('$label calls $method $url', async (call) => {
|
|
156
|
-
await call.run();
|
|
157
|
-
|
|
158
|
-
const config = adapter.mock.calls[0][0];
|
|
159
|
-
expect(config.method).toBe(call.method);
|
|
160
|
-
expect(config.url).toBe(call.url);
|
|
161
|
-
expect(config.baseURL).toBe('http://reflex.test/');
|
|
162
|
-
if (call.body !== undefined) {
|
|
163
|
-
expect(JSON.parse(config.data)).toEqual(call.body);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('exposes no route twice', () => {
|
|
168
|
-
expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
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.check',
|
|
129
|
+
method: 'post',
|
|
130
|
+
url: `${BASE}/discord/connection/e-1/check`,
|
|
131
|
+
body: {},
|
|
132
|
+
run: () => discord().connection.check({ ...SERVICE, environmentId: 'e-1' }),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
label: 'sync',
|
|
136
|
+
method: 'post',
|
|
137
|
+
url: `${BASE}/deployment/e-1/discord-sync`,
|
|
138
|
+
body: {},
|
|
139
|
+
run: () => discord().sync({ ...SERVICE, environmentId: 'e-1' }),
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
|
|
143
|
+
describe('AbyssReflexCore Discord bot routes', () => {
|
|
144
|
+
const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
|
|
145
|
+
async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
beforeAll(() => {
|
|
149
|
+
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
|
|
150
|
+
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
beforeEach(() => adapter.mockClear());
|
|
154
|
+
|
|
155
|
+
it.each(calls)('$label calls $method $url', async (call) => {
|
|
156
|
+
await call.run();
|
|
157
|
+
|
|
158
|
+
const config = adapter.mock.calls[0][0];
|
|
159
|
+
expect(config.method).toBe(call.method);
|
|
160
|
+
expect(config.url).toBe(call.url);
|
|
161
|
+
expect(config.baseURL).toBe('http://reflex.test/');
|
|
162
|
+
if (call.body !== undefined) {
|
|
163
|
+
expect(JSON.parse(config.data)).toEqual(call.body);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('exposes no route twice', () => {
|
|
168
|
+
expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
|
|
169
|
+
});
|
|
170
|
+
});
|