@abyss-project/reflex 6.0.5 → 6.2.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/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +15 -15
- package/dist/api/function-run.api.d.ts +2 -1
- package/dist/api/function-run.api.js +3 -1
- package/dist/api/function-run.api.js.map +1 -1
- package/dist/api/function-settings.api.d.ts +3 -1
- package/dist/api/function-settings.api.js +7 -1
- package/dist/api/function-settings.api.js.map +1 -1
- 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/storage-surplus.admin.api.d.ts +5 -0
- package/dist/api/storage-surplus.admin.api.js +17 -0
- package/dist/api/storage-surplus.admin.api.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/types/enum/reflex-error-code.enum.d.ts +4 -1
- package/dist/types/enum/reflex-error-code.enum.js +3 -0
- package/dist/types/enum/reflex-error-code.enum.js.map +1 -1
- package/dist/types/interface/api/requests/application-run-settings.request.d.ts +1 -0
- package/dist/types/interface/api/requests/function-run.request.d.ts +8 -0
- package/dist/types/interface/api/requests/function-settings.request.d.ts +12 -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.request.d.ts +1 -0
- package/dist/types/interface/api/requests/storage-surplus.admin.request.d.ts +8 -0
- package/dist/types/interface/api/requests/storage-surplus.admin.request.js +3 -0
- package/dist/types/interface/api/requests/storage-surplus.admin.request.js.map +1 -0
- package/dist/types/interface/api/responses/function-run.response.d.ts +4 -0
- package/dist/types/interface/api/responses/function-settings.response.d.ts +5 -1
- 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/storage-surplus.admin.response.d.ts +8 -0
- package/dist/types/interface/api/responses/storage-surplus.admin.response.js +3 -0
- package/dist/types/interface/api/responses/storage-surplus.admin.response.js.map +1 -0
- package/dist/types/interface/models/index.d.ts +2 -0
- package/dist/types/interface/models/index.js +2 -0
- package/dist/types/interface/models/index.js.map +1 -1
- package/dist/types/interface/models/reflex-run-retention.model.d.ts +13 -0
- package/dist/types/interface/models/reflex-run-retention.model.js +8 -0
- package/dist/types/interface/models/reflex-run-retention.model.js.map +1 -0
- package/dist/types/interface/models/reflex-run-settings.model.d.ts +4 -0
- package/dist/types/interface/models/reflex-run.model.d.ts +5 -0
- package/dist/types/interface/models/reflex-service-deployment.model.d.ts +2 -2
- package/dist/types/interface/models/reflex-service.model.d.ts +1 -0
- package/dist/types/interface/models/reflex-storage-surplus.model.d.ts +11 -0
- package/dist/types/interface/models/reflex-storage-surplus.model.js +3 -0
- package/dist/types/interface/models/reflex-storage-surplus.model.js.map +1 -0
- package/jest.config.ts +11 -11
- package/package.json +10 -15
- package/src/api/alert-rule.api.test.ts +72 -72
- package/src/api/alert-rule.api.ts +57 -57
- package/src/api/application-insights.api.test.ts +42 -42
- package/src/api/application-insights.api.ts +38 -38
- package/src/api/application-run-settings.api.test.ts +11 -0
- package/src/api/application-run-settings.api.ts +30 -30
- package/src/api/function-access.api.ts +87 -87
- package/src/api/function-insights.api.test.ts +27 -27
- package/src/api/function-insights.api.ts +18 -18
- package/src/api/function-run.api.ts +15 -0
- package/src/api/function-settings.api.ts +22 -0
- package/src/api/function-template.api.test.ts +72 -72
- package/src/api/function-template.api.ts +52 -52
- package/src/api/function-test.api.ts +34 -34
- package/src/api/function-version.api.ts +66 -66
- package/src/api/function.api.test.ts +55 -0
- package/src/api/function.api.ts +62 -62
- package/src/api/health.api.ts +10 -10
- package/src/api/index.ts +27 -26
- package/src/api/route-stats.api.test.ts +45 -45
- package/src/api/route-stats.api.ts +36 -36
- package/src/api/service-completion-webhook.api.test.ts +97 -97
- package/src/api/service-completion-webhook.api.ts +39 -39
- package/src/api/service-configuration.api.ts +16 -16
- package/src/api/service-consumer.api.test.ts +104 -104
- package/src/api/service-consumer.api.ts +90 -90
- package/src/api/service-deployment.api.ts +79 -79
- package/src/api/service-discord-event.api.test.ts +106 -106
- package/src/api/service-discord-event.api.ts +78 -78
- package/src/api/service-discord.api.test.ts +178 -178
- package/src/api/service-discord.api.ts +222 -222
- package/src/api/service-insights.api.test.ts +36 -36
- package/src/api/service-insights.api.ts +42 -42
- package/src/api/service-limits.api.test.ts +100 -100
- package/src/api/service-limits.api.ts +37 -37
- package/src/api/service-openapi.api.test.ts +52 -52
- package/src/api/service-openapi.api.ts +21 -21
- package/src/api/service-route.api.ts +74 -74
- package/src/api/service-task.api.test.ts +140 -140
- package/src/api/service-task.api.ts +141 -141
- package/src/api/service-version.api.ts +54 -54
- package/src/api/service.api.test.ts +6 -1
- package/src/api/service.api.ts +55 -55
- package/src/api/storage-surplus.admin.api.test.ts +66 -0
- package/src/api/storage-surplus.admin.api.ts +45 -0
- package/src/discord/discord-event-filter-cases.ts +261 -261
- package/src/discord/discord-event-filters.test.ts +91 -91
- package/src/discord/discord-event-filters.ts +95 -95
- package/src/discord/discord-event-intents.test.ts +112 -112
- package/src/discord/discord-event-intents.ts +55 -55
- package/src/discord/index.ts +3 -3
- package/src/index.test.ts +104 -104
- package/src/index.ts +42 -0
- package/src/insights/index.ts +1 -1
- package/src/insights/percentiles.test.ts +75 -75
- package/src/insights/percentiles.ts +37 -37
- package/src/types/enum/reflex-error-code.enum.ts +16 -0
- package/src/types/interface/api/requests/application-run-settings.request.ts +2 -0
- package/src/types/interface/api/requests/function-run.request.ts +10 -0
- package/src/types/interface/api/requests/function-settings.request.ts +16 -0
- package/src/types/interface/api/requests/index.ts +1 -0
- package/src/types/interface/api/requests/service.request.ts +2 -0
- package/src/types/interface/api/requests/storage-surplus.admin.request.ts +12 -0
- package/src/types/interface/api/responses/function-run.response.ts +5 -0
- package/src/types/interface/api/responses/function-settings.response.ts +7 -0
- package/src/types/interface/api/responses/index.ts +1 -0
- package/src/types/interface/api/responses/storage-surplus.admin.response.ts +10 -0
- package/src/types/interface/models/index.ts +2 -0
- package/src/types/interface/models/reflex-run-retention.model.ts +24 -0
- package/src/types/interface/models/reflex-run-settings.model.ts +11 -0
- package/src/types/interface/models/reflex-run.model.ts +10 -0
- package/src/types/interface/models/reflex-service-deployment.model.ts +4 -2
- package/src/types/interface/models/reflex-service.model.ts +2 -0
- package/src/types/interface/models/reflex-storage-surplus.model.ts +23 -0
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +35 -35
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { DiscordEventType } from '../types/enum';
|
|
2
|
-
import type { IReflexDiscordEvent } from '../types/interface/models';
|
|
3
|
-
|
|
4
|
-
/** The Gateway intents the Discord events need, as Discord numbers their bits. */
|
|
5
|
-
export enum DiscordGatewayIntent {
|
|
6
|
-
/** Member arrival and departure. Privileged. */
|
|
7
|
-
GUILD_MEMBERS = 1 << 1,
|
|
8
|
-
GUILD_MESSAGES = 1 << 9,
|
|
9
|
-
GUILD_MESSAGE_REACTIONS = 1 << 10,
|
|
10
|
-
/** The content of a message. Privileged. */
|
|
11
|
-
MESSAGE_CONTENT = 1 << 15,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/** The intents Discord asks the bot owner to enable in the portal (and to have verified past 100 servers). */
|
|
15
|
-
export const PRIVILEGED_DISCORD_GATEWAY_INTENTS: readonly DiscordGatewayIntent[] = [
|
|
16
|
-
DiscordGatewayIntent.GUILD_MEMBERS,
|
|
17
|
-
DiscordGatewayIntent.MESSAGE_CONTENT,
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
/** The intent each event type needs by itself. `GUILDS` is never asked: the four events do not need its large packets. */
|
|
21
|
-
export const DISCORD_EVENT_BASE_INTENT: Record<DiscordEventType, DiscordGatewayIntent> = {
|
|
22
|
-
[DiscordEventType.GUILD_MEMBER_ADD]: DiscordGatewayIntent.GUILD_MEMBERS,
|
|
23
|
-
[DiscordEventType.GUILD_MEMBER_REMOVE]: DiscordGatewayIntent.GUILD_MEMBERS,
|
|
24
|
-
[DiscordEventType.MESSAGE_CREATE]: DiscordGatewayIntent.GUILD_MESSAGES,
|
|
25
|
-
[DiscordEventType.MESSAGE_REACTION_ADD]: DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type IntentSource = Pick<IReflexDiscordEvent, 'eventType' | 'filters' | 'includeContent'>;
|
|
29
|
-
|
|
30
|
-
/** True when the trigger reads the content of a message: it asks for it, or filters on a prefix. */
|
|
31
|
-
const needsMessageContent = (event: IntentSource): boolean =>
|
|
32
|
-
event.eventType === DiscordEventType.MESSAGE_CREATE &&
|
|
33
|
-
(event.includeContent || (event.filters.contentPrefix ?? '') !== '');
|
|
34
|
-
|
|
35
|
-
/** The intents one trigger needs. */
|
|
36
|
-
const intentListOf = (event: IntentSource): DiscordGatewayIntent[] => {
|
|
37
|
-
const intents = [DISCORD_EVENT_BASE_INTENT[event.eventType]];
|
|
38
|
-
if (needsMessageContent(event)) {
|
|
39
|
-
intents.push(DiscordGatewayIntent.MESSAGE_CONTENT);
|
|
40
|
-
}
|
|
41
|
-
return intents;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/** The `intents` of IDENTIFY for the triggers of a version: the union of their bits, 0 without a trigger. */
|
|
45
|
-
export const intentsOf = (events: readonly IntentSource[]): number =>
|
|
46
|
-
events.reduce(
|
|
47
|
-
(bits, event) => intentListOf(event).reduce((acc, intent) => acc | intent, bits),
|
|
48
|
-
0,
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
/** The privileged intents the triggers need, in bit order, without duplicates. */
|
|
52
|
-
export const privilegedIntentsOf = (events: readonly IntentSource[]): DiscordGatewayIntent[] => {
|
|
53
|
-
const bits = intentsOf(events);
|
|
54
|
-
return PRIVILEGED_DISCORD_GATEWAY_INTENTS.filter((intent) => (bits & intent) !== 0);
|
|
55
|
-
};
|
|
1
|
+
import { DiscordEventType } from '../types/enum';
|
|
2
|
+
import type { IReflexDiscordEvent } from '../types/interface/models';
|
|
3
|
+
|
|
4
|
+
/** The Gateway intents the Discord events need, as Discord numbers their bits. */
|
|
5
|
+
export enum DiscordGatewayIntent {
|
|
6
|
+
/** Member arrival and departure. Privileged. */
|
|
7
|
+
GUILD_MEMBERS = 1 << 1,
|
|
8
|
+
GUILD_MESSAGES = 1 << 9,
|
|
9
|
+
GUILD_MESSAGE_REACTIONS = 1 << 10,
|
|
10
|
+
/** The content of a message. Privileged. */
|
|
11
|
+
MESSAGE_CONTENT = 1 << 15,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** The intents Discord asks the bot owner to enable in the portal (and to have verified past 100 servers). */
|
|
15
|
+
export const PRIVILEGED_DISCORD_GATEWAY_INTENTS: readonly DiscordGatewayIntent[] = [
|
|
16
|
+
DiscordGatewayIntent.GUILD_MEMBERS,
|
|
17
|
+
DiscordGatewayIntent.MESSAGE_CONTENT,
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
/** The intent each event type needs by itself. `GUILDS` is never asked: the four events do not need its large packets. */
|
|
21
|
+
export const DISCORD_EVENT_BASE_INTENT: Record<DiscordEventType, DiscordGatewayIntent> = {
|
|
22
|
+
[DiscordEventType.GUILD_MEMBER_ADD]: DiscordGatewayIntent.GUILD_MEMBERS,
|
|
23
|
+
[DiscordEventType.GUILD_MEMBER_REMOVE]: DiscordGatewayIntent.GUILD_MEMBERS,
|
|
24
|
+
[DiscordEventType.MESSAGE_CREATE]: DiscordGatewayIntent.GUILD_MESSAGES,
|
|
25
|
+
[DiscordEventType.MESSAGE_REACTION_ADD]: DiscordGatewayIntent.GUILD_MESSAGE_REACTIONS,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type IntentSource = Pick<IReflexDiscordEvent, 'eventType' | 'filters' | 'includeContent'>;
|
|
29
|
+
|
|
30
|
+
/** True when the trigger reads the content of a message: it asks for it, or filters on a prefix. */
|
|
31
|
+
const needsMessageContent = (event: IntentSource): boolean =>
|
|
32
|
+
event.eventType === DiscordEventType.MESSAGE_CREATE &&
|
|
33
|
+
(event.includeContent || (event.filters.contentPrefix ?? '') !== '');
|
|
34
|
+
|
|
35
|
+
/** The intents one trigger needs. */
|
|
36
|
+
const intentListOf = (event: IntentSource): DiscordGatewayIntent[] => {
|
|
37
|
+
const intents = [DISCORD_EVENT_BASE_INTENT[event.eventType]];
|
|
38
|
+
if (needsMessageContent(event)) {
|
|
39
|
+
intents.push(DiscordGatewayIntent.MESSAGE_CONTENT);
|
|
40
|
+
}
|
|
41
|
+
return intents;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The `intents` of IDENTIFY for the triggers of a version: the union of their bits, 0 without a trigger. */
|
|
45
|
+
export const intentsOf = (events: readonly IntentSource[]): number =>
|
|
46
|
+
events.reduce(
|
|
47
|
+
(bits, event) => intentListOf(event).reduce((acc, intent) => acc | intent, bits),
|
|
48
|
+
0,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
/** The privileged intents the triggers need, in bit order, without duplicates. */
|
|
52
|
+
export const privilegedIntentsOf = (events: readonly IntentSource[]): DiscordGatewayIntent[] => {
|
|
53
|
+
const bits = intentsOf(events);
|
|
54
|
+
return PRIVILEGED_DISCORD_GATEWAY_INTENTS.filter((intent) => (bits & intent) !== 0);
|
|
55
|
+
};
|
package/src/discord/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './discord-event-intents';
|
|
2
|
-
export * from './discord-event-filters';
|
|
3
|
-
export * from './discord-event-filter-cases';
|
|
1
|
+
export * from './discord-event-intents';
|
|
2
|
+
export * from './discord-event-filters';
|
|
3
|
+
export * from './discord-event-filter-cases';
|
package/src/index.test.ts
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import { AxiosAdapter, AxiosError, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
AbyssReflexCore,
|
|
4
|
-
HealthStatus,
|
|
5
|
-
IHealthResponse,
|
|
6
|
-
intentsOf,
|
|
7
|
-
matchesEventFilters,
|
|
8
|
-
privilegedIntentsOf,
|
|
9
|
-
} from '.';
|
|
10
|
-
|
|
11
|
-
const answer =
|
|
12
|
-
(status: number, data: IHealthResponse): AxiosAdapter =>
|
|
13
|
-
async (config: InternalAxiosRequestConfig) => {
|
|
14
|
-
const response = { data, status, statusText: '', headers: {}, config };
|
|
15
|
-
if (status >= 400) {
|
|
16
|
-
throw new AxiosError('failed', 'ERR_BAD_RESPONSE', config, null, response);
|
|
17
|
-
}
|
|
18
|
-
return response;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
describe('AbyssReflexCore', () => {
|
|
22
|
-
it('points at the production API until setConfig says otherwise', () => {
|
|
23
|
-
expect(AbyssReflexCore.getConfig().baseURL).toBe('https://reflex-api.abyss-project.fr/');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('setConfig changes the base URL of the axios instance', () => {
|
|
27
|
-
AbyssReflexCore.setConfig({ baseURL: 'http://localhost:10141/' });
|
|
28
|
-
expect(AbyssReflexCore.axios.defaults.baseURL).toBe('http://localhost:10141/');
|
|
29
|
-
expect(AbyssReflexCore.getConfig().baseURL).toBe('http://localhost:10141/');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('health() calls GET /health on the configured URL and returns the typed body', async () => {
|
|
33
|
-
const adapter = jest.fn(answer(200, { database: HealthStatus.UP, redis: HealthStatus.UP }));
|
|
34
|
-
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/' });
|
|
35
|
-
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
36
|
-
|
|
37
|
-
const body = await AbyssReflexCore.sdk.health();
|
|
38
|
-
|
|
39
|
-
expect(body).toEqual({ database: 'up', redis: 'up' });
|
|
40
|
-
const config = adapter.mock.calls[0][0];
|
|
41
|
-
expect(config.method).toBe('get');
|
|
42
|
-
expect(config.url).toBe('health');
|
|
43
|
-
expect(config.baseURL).toBe('http://reflex.test/');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('health() rejects on a 503 and the error carries the component that is down', async () => {
|
|
47
|
-
AbyssReflexCore.axios.defaults.adapter = answer(503, {
|
|
48
|
-
database: HealthStatus.DOWN,
|
|
49
|
-
redis: HealthStatus.UP,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const error = await AbyssReflexCore.sdk.health().catch((e: AxiosError<IHealthResponse>) => e);
|
|
53
|
-
|
|
54
|
-
expect((error as AxiosError<IHealthResponse>).response?.status).toBe(503);
|
|
55
|
-
expect((error as AxiosError<IHealthResponse>).response?.data.database).toBe(HealthStatus.DOWN);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('AbyssReflexCore facade of the Discord events', () => {
|
|
60
|
-
it('exposes the pure event helpers of the SDK', () => {
|
|
61
|
-
expect(intentsOf([])).toBe(0);
|
|
62
|
-
expect(typeof matchesEventFilters).toBe('function');
|
|
63
|
-
expect(typeof privilegedIntentsOf).toBe('function');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('exposes the event, insights and bot limit routes under short names', () => {
|
|
67
|
-
const { service, function: fn } = AbyssReflexCore.sdk;
|
|
68
|
-
expect(Object.keys(service.discord.event)).toEqual(['list', 'create', 'update', 'delete']);
|
|
69
|
-
expect(Object.keys(service.discord.eventLog)).toEqual(['list']);
|
|
70
|
-
expect(Object.keys(service.insights)).toEqual(['get', 'events']);
|
|
71
|
-
expect(Object.keys(fn.insights)).toEqual(['get']);
|
|
72
|
-
expect(service.discord.connection.setAllocation).toBeInstanceOf(Function);
|
|
73
|
-
expect(Object.keys(service.discord.connection)).not.toContain('setBotSettings');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('AbyssReflexCore facade of the run understanding routes', () => {
|
|
78
|
-
it('exposes the application, route statistics and log cap routes under short names', () => {
|
|
79
|
-
const { application, service, function: fn } = AbyssReflexCore.sdk;
|
|
80
|
-
expect(Object.keys(application)).toEqual(['runSettings', 'insights', 'alertRule']);
|
|
81
|
-
expect(Object.keys(application.runSettings)).toEqual(['get', 'set']);
|
|
82
|
-
expect(Object.keys(application.insights)).toEqual(['get', 'calendar']);
|
|
83
|
-
expect(Object.keys(application.alertRule)).toEqual(['list', 'create', 'update', 'delete']);
|
|
84
|
-
expect(Object.keys(service.routeStats)).toEqual(['list', 'insights']);
|
|
85
|
-
expect(Object.keys(fn.logCap)).toEqual(['set']);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('AbyssReflexCore facade of the contract, the consumers and the limits', () => {
|
|
90
|
-
it('exposes the consumer, OpenAPI, limits and completion webhook routes under short names', () => {
|
|
91
|
-
const { service } = AbyssReflexCore.sdk;
|
|
92
|
-
expect(Object.keys(service.consumer)).toEqual([
|
|
93
|
-
'list',
|
|
94
|
-
'create',
|
|
95
|
-
'update',
|
|
96
|
-
'delete',
|
|
97
|
-
'createKey',
|
|
98
|
-
'revokeKey',
|
|
99
|
-
]);
|
|
100
|
-
expect(Object.keys(service.openapi)).toEqual(['get']);
|
|
101
|
-
expect(Object.keys(service.limits)).toEqual(['list', 'set']);
|
|
102
|
-
expect(Object.keys(service.completionWebhook)).toEqual(['get', 'rotateSecret']);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
1
|
+
import { AxiosAdapter, AxiosError, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import {
|
|
3
|
+
AbyssReflexCore,
|
|
4
|
+
HealthStatus,
|
|
5
|
+
IHealthResponse,
|
|
6
|
+
intentsOf,
|
|
7
|
+
matchesEventFilters,
|
|
8
|
+
privilegedIntentsOf,
|
|
9
|
+
} from '.';
|
|
10
|
+
|
|
11
|
+
const answer =
|
|
12
|
+
(status: number, data: IHealthResponse): AxiosAdapter =>
|
|
13
|
+
async (config: InternalAxiosRequestConfig) => {
|
|
14
|
+
const response = { data, status, statusText: '', headers: {}, config };
|
|
15
|
+
if (status >= 400) {
|
|
16
|
+
throw new AxiosError('failed', 'ERR_BAD_RESPONSE', config, null, response);
|
|
17
|
+
}
|
|
18
|
+
return response;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe('AbyssReflexCore', () => {
|
|
22
|
+
it('points at the production API until setConfig says otherwise', () => {
|
|
23
|
+
expect(AbyssReflexCore.getConfig().baseURL).toBe('https://reflex-api.abyss-project.fr/');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('setConfig changes the base URL of the axios instance', () => {
|
|
27
|
+
AbyssReflexCore.setConfig({ baseURL: 'http://localhost:10141/' });
|
|
28
|
+
expect(AbyssReflexCore.axios.defaults.baseURL).toBe('http://localhost:10141/');
|
|
29
|
+
expect(AbyssReflexCore.getConfig().baseURL).toBe('http://localhost:10141/');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('health() calls GET /health on the configured URL and returns the typed body', async () => {
|
|
33
|
+
const adapter = jest.fn(answer(200, { database: HealthStatus.UP, redis: HealthStatus.UP }));
|
|
34
|
+
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/' });
|
|
35
|
+
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
36
|
+
|
|
37
|
+
const body = await AbyssReflexCore.sdk.health();
|
|
38
|
+
|
|
39
|
+
expect(body).toEqual({ database: 'up', redis: 'up' });
|
|
40
|
+
const config = adapter.mock.calls[0][0];
|
|
41
|
+
expect(config.method).toBe('get');
|
|
42
|
+
expect(config.url).toBe('health');
|
|
43
|
+
expect(config.baseURL).toBe('http://reflex.test/');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('health() rejects on a 503 and the error carries the component that is down', async () => {
|
|
47
|
+
AbyssReflexCore.axios.defaults.adapter = answer(503, {
|
|
48
|
+
database: HealthStatus.DOWN,
|
|
49
|
+
redis: HealthStatus.UP,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const error = await AbyssReflexCore.sdk.health().catch((e: AxiosError<IHealthResponse>) => e);
|
|
53
|
+
|
|
54
|
+
expect((error as AxiosError<IHealthResponse>).response?.status).toBe(503);
|
|
55
|
+
expect((error as AxiosError<IHealthResponse>).response?.data.database).toBe(HealthStatus.DOWN);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('AbyssReflexCore facade of the Discord events', () => {
|
|
60
|
+
it('exposes the pure event helpers of the SDK', () => {
|
|
61
|
+
expect(intentsOf([])).toBe(0);
|
|
62
|
+
expect(typeof matchesEventFilters).toBe('function');
|
|
63
|
+
expect(typeof privilegedIntentsOf).toBe('function');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('exposes the event, insights and bot limit routes under short names', () => {
|
|
67
|
+
const { service, function: fn } = AbyssReflexCore.sdk;
|
|
68
|
+
expect(Object.keys(service.discord.event)).toEqual(['list', 'create', 'update', 'delete']);
|
|
69
|
+
expect(Object.keys(service.discord.eventLog)).toEqual(['list']);
|
|
70
|
+
expect(Object.keys(service.insights)).toEqual(['get', 'events']);
|
|
71
|
+
expect(Object.keys(fn.insights)).toEqual(['get']);
|
|
72
|
+
expect(service.discord.connection.setAllocation).toBeInstanceOf(Function);
|
|
73
|
+
expect(Object.keys(service.discord.connection)).not.toContain('setBotSettings');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('AbyssReflexCore facade of the run understanding routes', () => {
|
|
78
|
+
it('exposes the application, route statistics and log cap routes under short names', () => {
|
|
79
|
+
const { application, service, function: fn } = AbyssReflexCore.sdk;
|
|
80
|
+
expect(Object.keys(application)).toEqual(['runSettings', 'insights', 'alertRule']);
|
|
81
|
+
expect(Object.keys(application.runSettings)).toEqual(['get', 'set']);
|
|
82
|
+
expect(Object.keys(application.insights)).toEqual(['get', 'calendar']);
|
|
83
|
+
expect(Object.keys(application.alertRule)).toEqual(['list', 'create', 'update', 'delete']);
|
|
84
|
+
expect(Object.keys(service.routeStats)).toEqual(['list', 'insights']);
|
|
85
|
+
expect(Object.keys(fn.logCap)).toEqual(['set']);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('AbyssReflexCore facade of the contract, the consumers and the limits', () => {
|
|
90
|
+
it('exposes the consumer, OpenAPI, limits and completion webhook routes under short names', () => {
|
|
91
|
+
const { service } = AbyssReflexCore.sdk;
|
|
92
|
+
expect(Object.keys(service.consumer)).toEqual([
|
|
93
|
+
'list',
|
|
94
|
+
'create',
|
|
95
|
+
'update',
|
|
96
|
+
'delete',
|
|
97
|
+
'createKey',
|
|
98
|
+
'revokeKey',
|
|
99
|
+
]);
|
|
100
|
+
expect(Object.keys(service.openapi)).toEqual(['get']);
|
|
101
|
+
expect(Object.keys(service.limits)).toEqual(['list', 'set']);
|
|
102
|
+
expect(Object.keys(service.completionWebhook)).toEqual(['get', 'rotateSecret']);
|
|
103
|
+
});
|
|
104
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ import * as serviceConsumerApi from './api/service-consumer.api';
|
|
|
25
25
|
import * as serviceOpenApiApi from './api/service-openapi.api';
|
|
26
26
|
import * as serviceLimitsApi from './api/service-limits.api';
|
|
27
27
|
import * as serviceCompletionWebhookApi from './api/service-completion-webhook.api';
|
|
28
|
+
import * as storageSurplusAdminApi from './api/storage-surplus.admin.api';
|
|
28
29
|
|
|
29
30
|
export * from './api';
|
|
30
31
|
export * from './types';
|
|
@@ -33,10 +34,15 @@ export * from './insights';
|
|
|
33
34
|
|
|
34
35
|
const DEFAULT_BASE_URL = 'https://reflex-api.abyss-project.fr/';
|
|
35
36
|
|
|
37
|
+
/** The header of the service-to-service routes (`/storage-surplus/admin/*`): the admin token of the mesh. */
|
|
38
|
+
export const ADMIN_TOKEN_HEADER = 'abyss-admin-token';
|
|
39
|
+
|
|
36
40
|
type CoreConfig = {
|
|
37
41
|
baseURL?: string;
|
|
38
42
|
/** The session token of the member (`Authorization: Bearer`). Every route but `health` needs it. */
|
|
39
43
|
token?: string;
|
|
44
|
+
/** The admin token of the mesh (`abyss-admin-token`), for the routes abyss-main calls (`storageSurplus.admin`). */
|
|
45
|
+
adminToken?: string;
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
type AbyssReflexCoreSDK = {
|
|
@@ -71,6 +77,8 @@ type AbyssReflexCoreSDK = {
|
|
|
71
77
|
list: typeof functionRunApi.listFunctionRun;
|
|
72
78
|
get: typeof functionRunApi.getFunctionRun;
|
|
73
79
|
state: typeof functionRunApi.getFunctionRunState;
|
|
80
|
+
/** Marks a run as a favorite (never purged) or not. */
|
|
81
|
+
favorite: typeof functionRunApi.setFunctionRunFavorite;
|
|
74
82
|
};
|
|
75
83
|
/** The dashboard of the function: tiles, series, ranking. */
|
|
76
84
|
insights: {
|
|
@@ -86,6 +94,11 @@ type AbyssReflexCoreSDK = {
|
|
|
86
94
|
logCap: {
|
|
87
95
|
set: typeof functionSettingsApi.setFunctionLogCap;
|
|
88
96
|
};
|
|
97
|
+
/** The retention tier of the runs of the function and the number of versions kept. */
|
|
98
|
+
runRetention: {
|
|
99
|
+
get: typeof functionSettingsApi.getFunctionRunRetention;
|
|
100
|
+
set: typeof functionSettingsApi.setFunctionRunRetention;
|
|
101
|
+
};
|
|
89
102
|
};
|
|
90
103
|
/** Function templates of an application (`/api/function-template/:applicationId`). */
|
|
91
104
|
functionTemplate: {
|
|
@@ -229,6 +242,18 @@ type AbyssReflexCoreSDK = {
|
|
|
229
242
|
rotateSecret: typeof serviceCompletionWebhookApi.rotateServiceCompletionWebhookSecret;
|
|
230
243
|
};
|
|
231
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* The day-90 contract of abyss-main's storage surplus, service-to-service (admin token). AbyssReflex has nothing to
|
|
247
|
+
* archive for the ONLINE surplus: `listArchivable` is always empty; the archives of the runs are listed and deleted.
|
|
248
|
+
*/
|
|
249
|
+
storageSurplus: {
|
|
250
|
+
admin: {
|
|
251
|
+
listArchivable: typeof storageSurplusAdminApi.listArchivableStorageSurplusAdmin;
|
|
252
|
+
archive: typeof storageSurplusAdminApi.archiveStorageSurplusAdmin;
|
|
253
|
+
listArchives: typeof storageSurplusAdminApi.listArchivesStorageSurplusAdmin;
|
|
254
|
+
deleteArchives: typeof storageSurplusAdminApi.deleteArchivesStorageSurplusAdmin;
|
|
255
|
+
};
|
|
256
|
+
};
|
|
232
257
|
};
|
|
233
258
|
|
|
234
259
|
export class AbyssReflexCore {
|
|
@@ -274,6 +299,7 @@ export class AbyssReflexCore {
|
|
|
274
299
|
list: functionRunApi.listFunctionRun,
|
|
275
300
|
get: functionRunApi.getFunctionRun,
|
|
276
301
|
state: functionRunApi.getFunctionRunState,
|
|
302
|
+
favorite: functionRunApi.setFunctionRunFavorite,
|
|
277
303
|
},
|
|
278
304
|
insights: {
|
|
279
305
|
get: functionInsightsApi.getFunctionInsights,
|
|
@@ -287,6 +313,10 @@ export class AbyssReflexCore {
|
|
|
287
313
|
logCap: {
|
|
288
314
|
set: functionSettingsApi.setFunctionLogCap,
|
|
289
315
|
},
|
|
316
|
+
runRetention: {
|
|
317
|
+
get: functionSettingsApi.getFunctionRunRetention,
|
|
318
|
+
set: functionSettingsApi.setFunctionRunRetention,
|
|
319
|
+
},
|
|
290
320
|
},
|
|
291
321
|
functionTemplate: {
|
|
292
322
|
list: functionTemplateApi.listFunctionTemplate,
|
|
@@ -413,6 +443,14 @@ export class AbyssReflexCore {
|
|
|
413
443
|
rotateSecret: serviceCompletionWebhookApi.rotateServiceCompletionWebhookSecret,
|
|
414
444
|
},
|
|
415
445
|
},
|
|
446
|
+
storageSurplus: {
|
|
447
|
+
admin: {
|
|
448
|
+
listArchivable: storageSurplusAdminApi.listArchivableStorageSurplusAdmin,
|
|
449
|
+
archive: storageSurplusAdminApi.archiveStorageSurplusAdmin,
|
|
450
|
+
listArchives: storageSurplusAdminApi.listArchivesStorageSurplusAdmin,
|
|
451
|
+
deleteArchives: storageSurplusAdminApi.deleteArchivesStorageSurplusAdmin,
|
|
452
|
+
},
|
|
453
|
+
},
|
|
416
454
|
};
|
|
417
455
|
}
|
|
418
456
|
return AbyssReflexCore._sdk;
|
|
@@ -430,6 +468,10 @@ export class AbyssReflexCore {
|
|
|
430
468
|
if (config.token) {
|
|
431
469
|
AbyssReflexCore.axios.defaults.headers.common.Authorization = `Bearer ${config.token}`;
|
|
432
470
|
}
|
|
471
|
+
|
|
472
|
+
if (config.adminToken) {
|
|
473
|
+
AbyssReflexCore.axios.defaults.headers.common[ADMIN_TOKEN_HEADER] = config.adminToken;
|
|
474
|
+
}
|
|
433
475
|
}
|
|
434
476
|
|
|
435
477
|
public static getConfig(): CoreConfig {
|
package/src/insights/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './percentiles';
|
|
1
|
+
export * from './percentiles';
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { DURATION_HISTOGRAM_BOUNDS_MS } from '../types';
|
|
2
|
-
import { percentileOfHistogram } from './percentiles';
|
|
3
|
-
|
|
4
|
-
const emptyHistogram = (): number[] =>
|
|
5
|
-
new Array<number>(DURATION_HISTOGRAM_BOUNDS_MS.length + 1).fill(0);
|
|
6
|
-
|
|
7
|
-
describe('percentileOfHistogram', () => {
|
|
8
|
-
it('reads p50, p95 and p99 at the upper bound of the bucket holding them', () => {
|
|
9
|
-
const histogram = emptyHistogram();
|
|
10
|
-
histogram[2] = 50; // <= 50 ms
|
|
11
|
-
histogram[3] = 40; // <= 100 ms
|
|
12
|
-
histogram[6] = 9; // <= 500 ms
|
|
13
|
-
histogram[10] = 1; // <= 2500 ms
|
|
14
|
-
|
|
15
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toEqual({
|
|
16
|
-
upperBoundMs: 50,
|
|
17
|
-
open: false,
|
|
18
|
-
});
|
|
19
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.95)).toEqual({
|
|
20
|
-
upperBoundMs: 500,
|
|
21
|
-
open: false,
|
|
22
|
-
});
|
|
23
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.99)).toEqual({
|
|
24
|
-
upperBoundMs: 500,
|
|
25
|
-
open: false,
|
|
26
|
-
});
|
|
27
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 1)).toEqual({
|
|
28
|
-
upperBoundMs: 2500,
|
|
29
|
-
open: false,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('answers the last bound with open set when the percentile falls in the open bucket', () => {
|
|
34
|
-
const histogram = emptyHistogram();
|
|
35
|
-
histogram[0] = 90;
|
|
36
|
-
histogram[DURATION_HISTOGRAM_BOUNDS_MS.length] = 10;
|
|
37
|
-
|
|
38
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toEqual({
|
|
39
|
-
upperBoundMs: 10,
|
|
40
|
-
open: false,
|
|
41
|
-
});
|
|
42
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.95)).toEqual({
|
|
43
|
-
upperBoundMs: 30_000,
|
|
44
|
-
open: true,
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('answers null for an empty histogram', () => {
|
|
49
|
-
expect(percentileOfHistogram(emptyHistogram(), DURATION_HISTOGRAM_BOUNDS_MS, 0.95)).toBeNull();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('answers the bucket of a single run for every quantile', () => {
|
|
53
|
-
const histogram = emptyHistogram();
|
|
54
|
-
histogram[4] = 1;
|
|
55
|
-
|
|
56
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toEqual({
|
|
57
|
-
upperBoundMs: 200,
|
|
58
|
-
open: false,
|
|
59
|
-
});
|
|
60
|
-
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.99)).toEqual({
|
|
61
|
-
upperBoundMs: 200,
|
|
62
|
-
open: false,
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('rejects a histogram that does not match the bounds and a quantile out of range', () => {
|
|
67
|
-
expect(() => percentileOfHistogram([1, 2], DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toThrow();
|
|
68
|
-
expect(() =>
|
|
69
|
-
percentileOfHistogram(emptyHistogram(), DURATION_HISTOGRAM_BOUNDS_MS, 0),
|
|
70
|
-
).toThrow();
|
|
71
|
-
expect(() =>
|
|
72
|
-
percentileOfHistogram(emptyHistogram(), DURATION_HISTOGRAM_BOUNDS_MS, 1.5),
|
|
73
|
-
).toThrow();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
1
|
+
import { DURATION_HISTOGRAM_BOUNDS_MS } from '../types';
|
|
2
|
+
import { percentileOfHistogram } from './percentiles';
|
|
3
|
+
|
|
4
|
+
const emptyHistogram = (): number[] =>
|
|
5
|
+
new Array<number>(DURATION_HISTOGRAM_BOUNDS_MS.length + 1).fill(0);
|
|
6
|
+
|
|
7
|
+
describe('percentileOfHistogram', () => {
|
|
8
|
+
it('reads p50, p95 and p99 at the upper bound of the bucket holding them', () => {
|
|
9
|
+
const histogram = emptyHistogram();
|
|
10
|
+
histogram[2] = 50; // <= 50 ms
|
|
11
|
+
histogram[3] = 40; // <= 100 ms
|
|
12
|
+
histogram[6] = 9; // <= 500 ms
|
|
13
|
+
histogram[10] = 1; // <= 2500 ms
|
|
14
|
+
|
|
15
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toEqual({
|
|
16
|
+
upperBoundMs: 50,
|
|
17
|
+
open: false,
|
|
18
|
+
});
|
|
19
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.95)).toEqual({
|
|
20
|
+
upperBoundMs: 500,
|
|
21
|
+
open: false,
|
|
22
|
+
});
|
|
23
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.99)).toEqual({
|
|
24
|
+
upperBoundMs: 500,
|
|
25
|
+
open: false,
|
|
26
|
+
});
|
|
27
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 1)).toEqual({
|
|
28
|
+
upperBoundMs: 2500,
|
|
29
|
+
open: false,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('answers the last bound with open set when the percentile falls in the open bucket', () => {
|
|
34
|
+
const histogram = emptyHistogram();
|
|
35
|
+
histogram[0] = 90;
|
|
36
|
+
histogram[DURATION_HISTOGRAM_BOUNDS_MS.length] = 10;
|
|
37
|
+
|
|
38
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toEqual({
|
|
39
|
+
upperBoundMs: 10,
|
|
40
|
+
open: false,
|
|
41
|
+
});
|
|
42
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.95)).toEqual({
|
|
43
|
+
upperBoundMs: 30_000,
|
|
44
|
+
open: true,
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('answers null for an empty histogram', () => {
|
|
49
|
+
expect(percentileOfHistogram(emptyHistogram(), DURATION_HISTOGRAM_BOUNDS_MS, 0.95)).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('answers the bucket of a single run for every quantile', () => {
|
|
53
|
+
const histogram = emptyHistogram();
|
|
54
|
+
histogram[4] = 1;
|
|
55
|
+
|
|
56
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toEqual({
|
|
57
|
+
upperBoundMs: 200,
|
|
58
|
+
open: false,
|
|
59
|
+
});
|
|
60
|
+
expect(percentileOfHistogram(histogram, DURATION_HISTOGRAM_BOUNDS_MS, 0.99)).toEqual({
|
|
61
|
+
upperBoundMs: 200,
|
|
62
|
+
open: false,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('rejects a histogram that does not match the bounds and a quantile out of range', () => {
|
|
67
|
+
expect(() => percentileOfHistogram([1, 2], DURATION_HISTOGRAM_BOUNDS_MS, 0.5)).toThrow();
|
|
68
|
+
expect(() =>
|
|
69
|
+
percentileOfHistogram(emptyHistogram(), DURATION_HISTOGRAM_BOUNDS_MS, 0),
|
|
70
|
+
).toThrow();
|
|
71
|
+
expect(() =>
|
|
72
|
+
percentileOfHistogram(emptyHistogram(), DURATION_HISTOGRAM_BOUNDS_MS, 1.5),
|
|
73
|
+
).toThrow();
|
|
74
|
+
});
|
|
75
|
+
});
|