@abyss-project/reflex 4.0.0 → 5.0.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-discord.api.d.ts +14 -0
- package/dist/api/service-discord.api.js +38 -0
- package/dist/api/service-discord.api.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/types/enum/discord-component-kind.enum.d.ts +4 -0
- package/dist/types/enum/discord-component-kind.enum.js +9 -0
- package/dist/types/enum/discord-component-kind.enum.js.map +1 -0
- package/dist/types/enum/discord-option-type.enum.d.ts +11 -0
- package/dist/types/enum/discord-option-type.enum.js +16 -0
- package/dist/types/enum/discord-option-type.enum.js.map +1 -0
- package/dist/types/enum/discord-sync-status.enum.d.ts +5 -0
- package/dist/types/enum/discord-sync-status.enum.js +10 -0
- package/dist/types/enum/discord-sync-status.enum.js.map +1 -0
- package/dist/types/enum/discord-token-state.enum.d.ts +6 -0
- package/dist/types/enum/discord-token-state.enum.js +11 -0
- package/dist/types/enum/discord-token-state.enum.js.map +1 -0
- package/dist/types/enum/index.d.ts +4 -0
- package/dist/types/enum/index.js +4 -0
- package/dist/types/enum/index.js.map +1 -1
- package/dist/types/enum/reflex-error-code.enum.d.ts +7 -1
- package/dist/types/enum/reflex-error-code.enum.js +6 -0
- package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
- package/dist/types/enum/service-type.enum.d.ts +2 -1
- package/dist/types/enum/service-type.enum.js +1 -0
- package/dist/types/enum/service-type.enum.js.map +1 -1
- 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-discord.request.d.ts +94 -0
- package/dist/types/interface/api/requests/service-discord.request.js +3 -0
- package/dist/types/interface/api/requests/service-discord.request.js.map +1 -0
- package/dist/types/interface/api/requests/service.request.d.ts +2 -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-discord.response.d.ts +50 -0
- package/dist/types/interface/api/responses/service-discord.response.js +3 -0
- package/dist/types/interface/api/responses/service-discord.response.js.map +1 -0
- package/dist/types/interface/api/responses/service-version.response.d.ts +15 -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-discord.model.d.ts +69 -0
- package/dist/types/interface/models/reflex-discord.model.js +13 -0
- package/dist/types/interface/models/reflex-discord.model.js.map +1 -0
- package/dist/types/interface/models/reflex-run.model.d.ts +3 -0
- package/dist/types/interface/models/reflex-service-deployment.model.d.ts +5 -1
- package/dist/types/interface/models/reflex-service-version.model.d.ts +6 -0
- package/dist/types/interface/models/reflex-service.model.d.ts +1 -0
- package/package.json +1 -1
- package/src/api/index.ts +13 -12
- package/src/api/service-configuration.api.ts +16 -16
- package/src/api/service-discord.api.test.ts +170 -0
- package/src/api/service-discord.api.ts +203 -0
- package/src/index.ts +235 -190
- package/src/types/enum/configuration-read-as.enum.ts +5 -5
- package/src/types/enum/discord-component-kind.enum.ts +7 -0
- package/src/types/enum/discord-option-type.enum.ts +12 -0
- package/src/types/enum/discord-sync-status.enum.ts +6 -0
- package/src/types/enum/discord-token-state.enum.ts +11 -0
- package/src/types/enum/index.ts +25 -21
- package/src/types/enum/reflex-error-code.enum.ts +12 -0
- package/src/types/enum/service-type.enum.ts +2 -0
- package/src/types/enum/vault-value-source.enum.ts +12 -12
- package/src/types/enum/vault-visibility.enum.ts +5 -5
- package/src/types/interface/api/requests/index.ts +12 -11
- package/src/types/interface/api/requests/service-configuration.request.ts +4 -4
- package/src/types/interface/api/requests/service-discord.request.ts +118 -0
- package/src/types/interface/api/requests/service.request.ts +8 -1
- package/src/types/interface/api/responses/index.ts +12 -11
- package/src/types/interface/api/responses/service-configuration.response.ts +8 -8
- package/src/types/interface/api/responses/service-discord.response.ts +72 -0
- package/src/types/interface/api/responses/service-version.response.ts +62 -33
- package/src/types/interface/models/index.ts +14 -13
- package/src/types/interface/models/reflex-discord.model.ts +117 -0
- package/src/types/interface/models/reflex-run.model.ts +173 -164
- package/src/types/interface/models/reflex-service-configuration.model.ts +22 -22
- package/src/types/interface/models/reflex-service-deployment.model.ts +12 -1
- package/src/types/interface/models/reflex-service-version.model.ts +12 -0
- package/src/types/interface/models/reflex-service.model.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/types/interface/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,0DAAwC;AACxC,kEAAgD;AAChD,8DAA4C;AAC5C,qDAAmC;AACnC,oEAAkD;AAClD,4DAA0C;AAC1C,4DAA0C;AAC1C,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,oEAAkD;AAClD,uEAAqD"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/types/interface/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,0DAAwC;AACxC,kEAAgD;AAChD,8DAA4C;AAC5C,qDAAmC;AACnC,oEAAkD;AAClD,4DAA0C;AAC1C,4DAA0C;AAC1C,yDAAuC;AACvC,uDAAqC;AACrC,iEAA+C;AAC/C,oEAAkD;AAClD,uEAAqD;AACrD,yDAAuC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { DiscordComponentKind, DiscordOptionType, DiscordTokenState } from '../../enum';
|
|
2
|
+
export declare const REFLEX_DISCORD_LIMITS: {
|
|
3
|
+
readonly commandNamePattern: RegExp;
|
|
4
|
+
readonly commandDescriptionMaxLength: 100;
|
|
5
|
+
readonly commandsPerServiceMax: 100;
|
|
6
|
+
readonly optionsPerCommandMax: 25;
|
|
7
|
+
readonly choicesPerOptionMax: 25;
|
|
8
|
+
readonly componentPrefixPattern: RegExp;
|
|
9
|
+
readonly syncErrorMaxLength: 500;
|
|
10
|
+
};
|
|
11
|
+
export interface IReflexDiscordOptionChoice {
|
|
12
|
+
name: string;
|
|
13
|
+
value: string | number;
|
|
14
|
+
}
|
|
15
|
+
export interface IReflexDiscordCommandOption {
|
|
16
|
+
type: DiscordOptionType;
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
required: boolean;
|
|
20
|
+
choices?: IReflexDiscordOptionChoice[];
|
|
21
|
+
}
|
|
22
|
+
export interface IReflexDiscordCommand {
|
|
23
|
+
id: string;
|
|
24
|
+
serviceId: string;
|
|
25
|
+
functionId: string;
|
|
26
|
+
name: string;
|
|
27
|
+
description: string;
|
|
28
|
+
options: IReflexDiscordCommandOption[];
|
|
29
|
+
defaultMemberPermissions: string | null;
|
|
30
|
+
allowedInDirectMessages: boolean;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
updatedAt: Date;
|
|
33
|
+
}
|
|
34
|
+
export interface IReflexDiscordComponent {
|
|
35
|
+
id: string;
|
|
36
|
+
serviceId: string;
|
|
37
|
+
functionId: string;
|
|
38
|
+
customIdPrefix: string;
|
|
39
|
+
kind: DiscordComponentKind;
|
|
40
|
+
createdAt: Date;
|
|
41
|
+
updatedAt: Date;
|
|
42
|
+
}
|
|
43
|
+
export type IReflexDiscordCommandSnapshot = Pick<IReflexDiscordCommand, 'id' | 'functionId' | 'name' | 'description' | 'options' | 'defaultMemberPermissions' | 'allowedInDirectMessages'>;
|
|
44
|
+
export type IReflexDiscordComponentSnapshot = Pick<IReflexDiscordComponent, 'id' | 'functionId' | 'customIdPrefix' | 'kind'>;
|
|
45
|
+
export interface IReflexDiscordEnvironmentSettings {
|
|
46
|
+
id: string;
|
|
47
|
+
serviceId: string;
|
|
48
|
+
environmentId: string;
|
|
49
|
+
testGuildId: string | null;
|
|
50
|
+
invitePermissions: string;
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
updatedAt: Date;
|
|
53
|
+
}
|
|
54
|
+
export interface IReflexDiscordEnvironmentConnection {
|
|
55
|
+
environmentId: string;
|
|
56
|
+
applicationId: string | null;
|
|
57
|
+
publicKey: string | null;
|
|
58
|
+
botName: string | null;
|
|
59
|
+
botAvatarUrl: string | null;
|
|
60
|
+
tokenState: DiscordTokenState;
|
|
61
|
+
testGuildId: string | null;
|
|
62
|
+
invitePermissions: string;
|
|
63
|
+
interactionsUrl: string;
|
|
64
|
+
inviteUrl: string | null;
|
|
65
|
+
}
|
|
66
|
+
export interface IReflexDiscordConnection {
|
|
67
|
+
discordTokenSecretId: string | null;
|
|
68
|
+
environments: IReflexDiscordEnvironmentConnection[];
|
|
69
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFLEX_DISCORD_LIMITS = void 0;
|
|
4
|
+
exports.REFLEX_DISCORD_LIMITS = {
|
|
5
|
+
commandNamePattern: /^[-_a-z0-9]{1,32}$/,
|
|
6
|
+
commandDescriptionMaxLength: 100,
|
|
7
|
+
commandsPerServiceMax: 100,
|
|
8
|
+
optionsPerCommandMax: 25,
|
|
9
|
+
choicesPerOptionMax: 25,
|
|
10
|
+
componentPrefixPattern: /^[a-z0-9_-]{1,40}$/,
|
|
11
|
+
syncErrorMaxLength: 500,
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=reflex-discord.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reflex-discord.model.js","sourceRoot":"","sources":["../../../../src/types/interface/models/reflex-discord.model.ts"],"names":[],"mappings":";;;AAGa,QAAA,qBAAqB,GAAG;IAEnC,kBAAkB,EAAE,oBAAoB;IACxC,2BAA2B,EAAE,GAAG;IAChC,qBAAqB,EAAE,GAAG;IAC1B,oBAAoB,EAAE,EAAE;IACxB,mBAAmB,EAAE,EAAE;IAEvB,sBAAsB,EAAE,oBAAoB;IAC5C,kBAAkB,EAAE,GAAG;CACf,CAAC"}
|
|
@@ -39,6 +39,9 @@ export interface IReflexRun {
|
|
|
39
39
|
durationMs: number;
|
|
40
40
|
trace: IReflexRunTrace | null;
|
|
41
41
|
routeId: string | null;
|
|
42
|
+
commandId: string | null;
|
|
43
|
+
componentId: string | null;
|
|
44
|
+
originLabel: string | null;
|
|
42
45
|
httpStatus: number | null;
|
|
43
46
|
errorCode: string | null;
|
|
44
47
|
executionMode: ExecutionMode | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ServiceDeploymentAction, ServiceDeploymentStatus } from '../../enum';
|
|
1
|
+
import type { DiscordSyncStatus, ServiceDeploymentAction, ServiceDeploymentStatus } from '../../enum';
|
|
2
2
|
import type { IReflexAccessDeclaration } from './reflex-definition.model';
|
|
3
3
|
export interface IReflexServiceDeploymentGrant {
|
|
4
4
|
functionId: string;
|
|
@@ -14,6 +14,10 @@ export interface IReflexServiceDeployment {
|
|
|
14
14
|
action: ServiceDeploymentAction;
|
|
15
15
|
status: ServiceDeploymentStatus;
|
|
16
16
|
grants: IReflexServiceDeploymentGrant[];
|
|
17
|
+
discordSync: DiscordSyncStatus | null;
|
|
18
|
+
discordSyncError: string | null;
|
|
19
|
+
discordSyncedAt: Date | null;
|
|
20
|
+
pausedForQuota: boolean;
|
|
17
21
|
isCurrent: boolean;
|
|
18
22
|
byUserId: string;
|
|
19
23
|
at: Date;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RouteMethod, TriggerAccessMode } from '../../enum';
|
|
2
|
+
import type { IReflexDiscordCommandSnapshot, IReflexDiscordComponentSnapshot } from './reflex-discord.model';
|
|
2
3
|
import type { IReflexServiceCors } from './reflex-service.model';
|
|
3
4
|
export interface IReflexServiceVersionRoute {
|
|
4
5
|
routeId: string;
|
|
@@ -12,11 +13,16 @@ export interface IReflexServiceVersionFunction {
|
|
|
12
13
|
functionVersionId: string;
|
|
13
14
|
functionVersionNumber: number;
|
|
14
15
|
}
|
|
16
|
+
export interface IReflexServiceVersionDiscord {
|
|
17
|
+
commands: IReflexDiscordCommandSnapshot[];
|
|
18
|
+
components: IReflexDiscordComponentSnapshot[];
|
|
19
|
+
}
|
|
15
20
|
export interface IReflexServiceVersionSnapshot {
|
|
16
21
|
routes: IReflexServiceVersionRoute[];
|
|
17
22
|
functions: IReflexServiceVersionFunction[];
|
|
18
23
|
cors: IReflexServiceCors;
|
|
19
24
|
rateLimitPerIpPerMinute: number;
|
|
25
|
+
discord?: IReflexServiceVersionDiscord;
|
|
20
26
|
}
|
|
21
27
|
export interface IReflexServiceVersion {
|
|
22
28
|
id: string;
|
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
export * from './health.api';
|
|
2
|
-
export * from './function.api';
|
|
3
|
-
export * from './function-access.api';
|
|
4
|
-
export * from './function-test.api';
|
|
5
|
-
export * from './function-version.api';
|
|
6
|
-
export * from './function-run.api';
|
|
7
|
-
export * from './function-settings.api';
|
|
8
|
-
export * from './service.api';
|
|
9
|
-
export * from './service-route.api';
|
|
10
|
-
export * from './service-version.api';
|
|
11
|
-
export * from './service-deployment.api';
|
|
12
|
-
export * from './service-configuration.api';
|
|
1
|
+
export * from './health.api';
|
|
2
|
+
export * from './function.api';
|
|
3
|
+
export * from './function-access.api';
|
|
4
|
+
export * from './function-test.api';
|
|
5
|
+
export * from './function-version.api';
|
|
6
|
+
export * from './function-run.api';
|
|
7
|
+
export * from './function-settings.api';
|
|
8
|
+
export * from './service.api';
|
|
9
|
+
export * from './service-route.api';
|
|
10
|
+
export * from './service-version.api';
|
|
11
|
+
export * from './service-deployment.api';
|
|
12
|
+
export * from './service-configuration.api';
|
|
13
|
+
export * from './service-discord.api';
|
|
@@ -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;
|
|
@@ -0,0 +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
|
+
});
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { AbyssReflexCore } from '..';
|
|
2
|
+
import type {
|
|
3
|
+
ICheckServiceDiscordConnectionParams,
|
|
4
|
+
ICheckServiceDiscordConnectionResponse,
|
|
5
|
+
ICreateServiceDiscordCommandBody,
|
|
6
|
+
ICreateServiceDiscordCommandParams,
|
|
7
|
+
ICreateServiceDiscordCommandResponse,
|
|
8
|
+
ICreateServiceDiscordComponentBody,
|
|
9
|
+
ICreateServiceDiscordComponentParams,
|
|
10
|
+
ICreateServiceDiscordComponentResponse,
|
|
11
|
+
IDeleteServiceDiscordCommandParams,
|
|
12
|
+
IDeleteServiceDiscordCommandResponse,
|
|
13
|
+
IDeleteServiceDiscordComponentParams,
|
|
14
|
+
IDeleteServiceDiscordComponentResponse,
|
|
15
|
+
IGetServiceDiscordConnectionParams,
|
|
16
|
+
IGetServiceDiscordConnectionResponse,
|
|
17
|
+
IListServiceDiscordCommandParams,
|
|
18
|
+
IListServiceDiscordCommandResponse,
|
|
19
|
+
IListServiceDiscordComponentParams,
|
|
20
|
+
IListServiceDiscordComponentResponse,
|
|
21
|
+
IRetryServiceDiscordSyncParams,
|
|
22
|
+
IRetryServiceDiscordSyncResponse,
|
|
23
|
+
ISetServiceDiscordEnvironmentBody,
|
|
24
|
+
ISetServiceDiscordEnvironmentParams,
|
|
25
|
+
ISetServiceDiscordEnvironmentResponse,
|
|
26
|
+
ISetServiceDiscordTokenSecretBody,
|
|
27
|
+
ISetServiceDiscordTokenSecretParams,
|
|
28
|
+
ISetServiceDiscordTokenSecretResponse,
|
|
29
|
+
IUpdateServiceDiscordCommandBody,
|
|
30
|
+
IUpdateServiceDiscordCommandParams,
|
|
31
|
+
IUpdateServiceDiscordCommandResponse,
|
|
32
|
+
IUpdateServiceDiscordComponentBody,
|
|
33
|
+
IUpdateServiceDiscordComponentParams,
|
|
34
|
+
IUpdateServiceDiscordComponentResponse,
|
|
35
|
+
} from '../types';
|
|
36
|
+
|
|
37
|
+
const serviceUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
38
|
+
`api/service/${params.applicationId}/${params.serviceId}`;
|
|
39
|
+
|
|
40
|
+
const commandUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
41
|
+
`${serviceUrl(params)}/discord/command`;
|
|
42
|
+
|
|
43
|
+
const componentUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
44
|
+
`${serviceUrl(params)}/discord/component`;
|
|
45
|
+
|
|
46
|
+
const connectionUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
47
|
+
`${serviceUrl(params)}/discord/connection`;
|
|
48
|
+
|
|
49
|
+
/** `GET .../discord/command`: the commands of the draft of a Discord bot, by name. Needs REFLEX_READ. */
|
|
50
|
+
export const listServiceDiscordCommand = async (
|
|
51
|
+
params: IListServiceDiscordCommandParams,
|
|
52
|
+
): Promise<IListServiceDiscordCommandResponse> =>
|
|
53
|
+
(await AbyssReflexCore.axios.get<IListServiceDiscordCommandResponse>(commandUrl(params))).data;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* `POST .../discord/command`: a command of the draft, pushed to Discord once a version holding it is in
|
|
57
|
+
* service. `409 DISCORD_COMMAND_CONFLICT` when the name is taken. Needs REFLEX_FUNCTION_UPDATE.
|
|
58
|
+
*/
|
|
59
|
+
export const createServiceDiscordCommand = async (
|
|
60
|
+
params: ICreateServiceDiscordCommandParams,
|
|
61
|
+
body: ICreateServiceDiscordCommandBody,
|
|
62
|
+
): Promise<ICreateServiceDiscordCommandResponse> =>
|
|
63
|
+
(await AbyssReflexCore.axios.post<ICreateServiceDiscordCommandResponse>(commandUrl(params), body))
|
|
64
|
+
.data;
|
|
65
|
+
|
|
66
|
+
/** `PATCH .../discord/command/:commandId`: changes the command in the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
67
|
+
export const updateServiceDiscordCommand = async (
|
|
68
|
+
params: IUpdateServiceDiscordCommandParams,
|
|
69
|
+
body: IUpdateServiceDiscordCommandBody,
|
|
70
|
+
): Promise<IUpdateServiceDiscordCommandResponse> =>
|
|
71
|
+
(
|
|
72
|
+
await AbyssReflexCore.axios.patch<IUpdateServiceDiscordCommandResponse>(
|
|
73
|
+
`${commandUrl(params)}/${params.commandId}`,
|
|
74
|
+
body,
|
|
75
|
+
)
|
|
76
|
+
).data;
|
|
77
|
+
|
|
78
|
+
/** `DELETE .../discord/command/:commandId`: takes the command out of the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
79
|
+
export const deleteServiceDiscordCommand = async (
|
|
80
|
+
params: IDeleteServiceDiscordCommandParams,
|
|
81
|
+
): Promise<IDeleteServiceDiscordCommandResponse> =>
|
|
82
|
+
(
|
|
83
|
+
await AbyssReflexCore.axios.delete<IDeleteServiceDiscordCommandResponse>(
|
|
84
|
+
`${commandUrl(params)}/${params.commandId}`,
|
|
85
|
+
)
|
|
86
|
+
).data;
|
|
87
|
+
|
|
88
|
+
/** `GET .../discord/component`: the components of the draft of a Discord bot, by prefix. Needs REFLEX_READ. */
|
|
89
|
+
export const listServiceDiscordComponent = async (
|
|
90
|
+
params: IListServiceDiscordComponentParams,
|
|
91
|
+
): Promise<IListServiceDiscordComponentResponse> =>
|
|
92
|
+
(await AbyssReflexCore.axios.get<IListServiceDiscordComponentResponse>(componentUrl(params)))
|
|
93
|
+
.data;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* `POST .../discord/component`: a button, menu or form prefix of the draft. `409
|
|
97
|
+
* DISCORD_COMPONENT_PREFIX_CONFLICT` when it equals, starts or is started by another prefix. Needs
|
|
98
|
+
* REFLEX_FUNCTION_UPDATE.
|
|
99
|
+
*/
|
|
100
|
+
export const createServiceDiscordComponent = async (
|
|
101
|
+
params: ICreateServiceDiscordComponentParams,
|
|
102
|
+
body: ICreateServiceDiscordComponentBody,
|
|
103
|
+
): Promise<ICreateServiceDiscordComponentResponse> =>
|
|
104
|
+
(
|
|
105
|
+
await AbyssReflexCore.axios.post<ICreateServiceDiscordComponentResponse>(
|
|
106
|
+
componentUrl(params),
|
|
107
|
+
body,
|
|
108
|
+
)
|
|
109
|
+
).data;
|
|
110
|
+
|
|
111
|
+
/** `PATCH .../discord/component/:componentId`: changes the component in the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
112
|
+
export const updateServiceDiscordComponent = async (
|
|
113
|
+
params: IUpdateServiceDiscordComponentParams,
|
|
114
|
+
body: IUpdateServiceDiscordComponentBody,
|
|
115
|
+
): Promise<IUpdateServiceDiscordComponentResponse> =>
|
|
116
|
+
(
|
|
117
|
+
await AbyssReflexCore.axios.patch<IUpdateServiceDiscordComponentResponse>(
|
|
118
|
+
`${componentUrl(params)}/${params.componentId}`,
|
|
119
|
+
body,
|
|
120
|
+
)
|
|
121
|
+
).data;
|
|
122
|
+
|
|
123
|
+
/** `DELETE .../discord/component/:componentId`: takes the component out of the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
124
|
+
export const deleteServiceDiscordComponent = async (
|
|
125
|
+
params: IDeleteServiceDiscordComponentParams,
|
|
126
|
+
): Promise<IDeleteServiceDiscordComponentResponse> =>
|
|
127
|
+
(
|
|
128
|
+
await AbyssReflexCore.axios.delete<IDeleteServiceDiscordComponentResponse>(
|
|
129
|
+
`${componentUrl(params)}/${params.componentId}`,
|
|
130
|
+
)
|
|
131
|
+
).data;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* `GET .../discord/connection`: the Vault entry of the token and, per environment of the application,
|
|
135
|
+
* the bot as last checked, the state of its token, the test server, the interactions address and the
|
|
136
|
+
* invitation link. Never the token. Needs REFLEX_READ.
|
|
137
|
+
*/
|
|
138
|
+
export const getServiceDiscordConnection = async (
|
|
139
|
+
params: IGetServiceDiscordConnectionParams,
|
|
140
|
+
): Promise<IGetServiceDiscordConnectionResponse> =>
|
|
141
|
+
(await AbyssReflexCore.axios.get<IGetServiceDiscordConnectionResponse>(connectionUrl(params)))
|
|
142
|
+
.data;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `PUT .../discord/connection`: chooses the Vault entry that holds the bot token. The environments in
|
|
146
|
+
* service read it again at once. Needs REFLEX_BOT_MANAGE.
|
|
147
|
+
*/
|
|
148
|
+
export const setServiceDiscordTokenSecret = async (
|
|
149
|
+
params: ISetServiceDiscordTokenSecretParams,
|
|
150
|
+
body: ISetServiceDiscordTokenSecretBody,
|
|
151
|
+
): Promise<ISetServiceDiscordTokenSecretResponse> =>
|
|
152
|
+
(
|
|
153
|
+
await AbyssReflexCore.axios.put<ISetServiceDiscordTokenSecretResponse>(
|
|
154
|
+
connectionUrl(params),
|
|
155
|
+
body,
|
|
156
|
+
)
|
|
157
|
+
).data;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* `PUT .../discord/connection/:environmentId`: the test server and the invitation permissions of one
|
|
161
|
+
* environment. A new test server is pushed at once where the bot is in service. Needs
|
|
162
|
+
* REFLEX_BOT_MANAGE.
|
|
163
|
+
*/
|
|
164
|
+
export const setServiceDiscordEnvironment = async (
|
|
165
|
+
params: ISetServiceDiscordEnvironmentParams,
|
|
166
|
+
body: ISetServiceDiscordEnvironmentBody,
|
|
167
|
+
): Promise<ISetServiceDiscordEnvironmentResponse> =>
|
|
168
|
+
(
|
|
169
|
+
await AbyssReflexCore.axios.put<ISetServiceDiscordEnvironmentResponse>(
|
|
170
|
+
`${connectionUrl(params)}/${params.environmentId}`,
|
|
171
|
+
body,
|
|
172
|
+
)
|
|
173
|
+
).data;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* `POST .../discord/connection/:environmentId/check`: reads the token of the environment from the Vault
|
|
177
|
+
* and asks Discord about it; answers the environment row, whatever the state of the token (`VALID`,
|
|
178
|
+
* `REJECTED`, `MISSING`). Needs REFLEX_BOT_MANAGE.
|
|
179
|
+
*/
|
|
180
|
+
export const checkServiceDiscordConnection = async (
|
|
181
|
+
params: ICheckServiceDiscordConnectionParams,
|
|
182
|
+
): Promise<ICheckServiceDiscordConnectionResponse> =>
|
|
183
|
+
(
|
|
184
|
+
await AbyssReflexCore.axios.post<ICheckServiceDiscordConnectionResponse>(
|
|
185
|
+
`${connectionUrl(params)}/${params.environmentId}/check`,
|
|
186
|
+
{},
|
|
187
|
+
)
|
|
188
|
+
).data;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* `POST .../deployment/:environmentId/discord-sync`: pushes the interactions address and the commands to
|
|
192
|
+
* Discord again for the version in service, without a new version. Needs REFLEX_PUBLISH, and
|
|
193
|
+
* REFLEX_PUBLISH_PRODUCTION in a production environment.
|
|
194
|
+
*/
|
|
195
|
+
export const retryServiceDiscordSync = async (
|
|
196
|
+
params: IRetryServiceDiscordSyncParams,
|
|
197
|
+
): Promise<IRetryServiceDiscordSyncResponse> =>
|
|
198
|
+
(
|
|
199
|
+
await AbyssReflexCore.axios.post<IRetryServiceDiscordSyncResponse>(
|
|
200
|
+
`${serviceUrl(params)}/deployment/${params.environmentId}/discord-sync`,
|
|
201
|
+
{},
|
|
202
|
+
)
|
|
203
|
+
).data;
|