@abyss-project/reflex 6.3.0 → 6.4.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/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 +1 -1
- 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/discord-host-action.enum.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-discord.request.ts +155 -155
- 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-discord.model.ts +208 -208
- package/src/types/interface/models/reflex-price-list.model.ts +22 -22
- 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,100 +1,100 @@
|
|
|
1
|
-
import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
-
import {
|
|
3
|
-
AbyssReflexCore,
|
|
4
|
-
REFLEX_BOT_LIMITS,
|
|
5
|
-
REFLEX_SERVICE_SPEND_LIMITS,
|
|
6
|
-
ReflexErrorCode,
|
|
7
|
-
ScheduledRunFailureCode,
|
|
8
|
-
ServiceBlockReason,
|
|
9
|
-
} from '..';
|
|
10
|
-
|
|
11
|
-
const APP = 'app-1';
|
|
12
|
-
const SVC = 'svc-1';
|
|
13
|
-
const BASE = `api/service/${APP}/${SVC}`;
|
|
14
|
-
const SERVICE = { applicationId: APP, serviceId: SVC };
|
|
15
|
-
|
|
16
|
-
interface Call {
|
|
17
|
-
label: string;
|
|
18
|
-
method: string;
|
|
19
|
-
url: string;
|
|
20
|
-
body?: unknown;
|
|
21
|
-
run: () => Promise<unknown>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const limits = () => AbyssReflexCore.sdk.service.limits;
|
|
25
|
-
|
|
26
|
-
const settings = {
|
|
27
|
-
creditOverageEnabled: true,
|
|
28
|
-
monthlySpendCapCents: 2000,
|
|
29
|
-
alerts: { monthlySpendCap: { thresholds: [50, 100], email: false } },
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const calls: Call[] = [
|
|
33
|
-
{
|
|
34
|
-
label: 'list',
|
|
35
|
-
method: 'get',
|
|
36
|
-
url: `${BASE}/limits`,
|
|
37
|
-
run: () => limits().list(SERVICE),
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
label: 'set',
|
|
41
|
-
method: 'put',
|
|
42
|
-
url: `${BASE}/limits/e-1`,
|
|
43
|
-
body: settings,
|
|
44
|
-
run: () => limits().set({ ...SERVICE, environmentId: 'e-1' }, settings),
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
|
|
48
|
-
describe('AbyssReflexCore limits routes', () => {
|
|
49
|
-
const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
|
|
50
|
-
async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
beforeAll(() => {
|
|
54
|
-
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
|
|
55
|
-
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
beforeEach(() => adapter.mockClear());
|
|
59
|
-
|
|
60
|
-
it.each(calls)('$label calls $method $url', async (call) => {
|
|
61
|
-
await call.run();
|
|
62
|
-
|
|
63
|
-
const config = adapter.mock.calls[0][0];
|
|
64
|
-
expect(config.method).toBe(call.method);
|
|
65
|
-
expect(config.url).toBe(call.url);
|
|
66
|
-
expect(config.baseURL).toBe('http://reflex.test/');
|
|
67
|
-
if (call.body !== undefined) {
|
|
68
|
-
expect(JSON.parse(config.data)).toEqual(call.body);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('exposes no route twice', () => {
|
|
73
|
-
expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('gives a bot the spend bounds of every Service', () => {
|
|
77
|
-
expect(REFLEX_SERVICE_SPEND_LIMITS).toEqual({
|
|
78
|
-
monthlySpendCapDefaultCents: 1000,
|
|
79
|
-
monthlySpendCapMinCents: 100,
|
|
80
|
-
monthlySpendCapMaxCents: 50000,
|
|
81
|
-
alertThresholdsMax: 5,
|
|
82
|
-
alertThresholdMin: 1,
|
|
83
|
-
alertThresholdMax: 100,
|
|
84
|
-
spendCapDefaultThresholds: [80, 100],
|
|
85
|
-
});
|
|
86
|
-
expect(REFLEX_BOT_LIMITS).toMatchObject(REFLEX_SERVICE_SPEND_LIMITS);
|
|
87
|
-
expect(REFLEX_BOT_LIMITS).toMatchObject({
|
|
88
|
-
eventsPerMinutePerLot: 500,
|
|
89
|
-
rateAlertDefaultMinutes: 5,
|
|
90
|
-
rateAlertDefaultPercent: 80,
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('names the stops of a Service the same at the edge and in the task history', () => {
|
|
95
|
-
expect(Object.values(ServiceBlockReason)).toEqual(['CREDITS_EXHAUSTED', 'BUDGET_REACHED']);
|
|
96
|
-
expect(ReflexErrorCode.CREDITS_EXHAUSTED).toBe(ServiceBlockReason.CREDITS_EXHAUSTED);
|
|
97
|
-
expect(ReflexErrorCode.BUDGET_REACHED).toBe(ServiceBlockReason.BUDGET_REACHED);
|
|
98
|
-
expect(ScheduledRunFailureCode.BUDGET_REACHED).toBe(ServiceBlockReason.BUDGET_REACHED);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
1
|
+
import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import {
|
|
3
|
+
AbyssReflexCore,
|
|
4
|
+
REFLEX_BOT_LIMITS,
|
|
5
|
+
REFLEX_SERVICE_SPEND_LIMITS,
|
|
6
|
+
ReflexErrorCode,
|
|
7
|
+
ScheduledRunFailureCode,
|
|
8
|
+
ServiceBlockReason,
|
|
9
|
+
} from '..';
|
|
10
|
+
|
|
11
|
+
const APP = 'app-1';
|
|
12
|
+
const SVC = 'svc-1';
|
|
13
|
+
const BASE = `api/service/${APP}/${SVC}`;
|
|
14
|
+
const SERVICE = { applicationId: APP, serviceId: SVC };
|
|
15
|
+
|
|
16
|
+
interface Call {
|
|
17
|
+
label: string;
|
|
18
|
+
method: string;
|
|
19
|
+
url: string;
|
|
20
|
+
body?: unknown;
|
|
21
|
+
run: () => Promise<unknown>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const limits = () => AbyssReflexCore.sdk.service.limits;
|
|
25
|
+
|
|
26
|
+
const settings = {
|
|
27
|
+
creditOverageEnabled: true,
|
|
28
|
+
monthlySpendCapCents: 2000,
|
|
29
|
+
alerts: { monthlySpendCap: { thresholds: [50, 100], email: false } },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const calls: Call[] = [
|
|
33
|
+
{
|
|
34
|
+
label: 'list',
|
|
35
|
+
method: 'get',
|
|
36
|
+
url: `${BASE}/limits`,
|
|
37
|
+
run: () => limits().list(SERVICE),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: 'set',
|
|
41
|
+
method: 'put',
|
|
42
|
+
url: `${BASE}/limits/e-1`,
|
|
43
|
+
body: settings,
|
|
44
|
+
run: () => limits().set({ ...SERVICE, environmentId: 'e-1' }, settings),
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
describe('AbyssReflexCore limits routes', () => {
|
|
49
|
+
const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
|
|
50
|
+
async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
beforeAll(() => {
|
|
54
|
+
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
|
|
55
|
+
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
beforeEach(() => adapter.mockClear());
|
|
59
|
+
|
|
60
|
+
it.each(calls)('$label calls $method $url', async (call) => {
|
|
61
|
+
await call.run();
|
|
62
|
+
|
|
63
|
+
const config = adapter.mock.calls[0][0];
|
|
64
|
+
expect(config.method).toBe(call.method);
|
|
65
|
+
expect(config.url).toBe(call.url);
|
|
66
|
+
expect(config.baseURL).toBe('http://reflex.test/');
|
|
67
|
+
if (call.body !== undefined) {
|
|
68
|
+
expect(JSON.parse(config.data)).toEqual(call.body);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('exposes no route twice', () => {
|
|
73
|
+
expect(new Set(calls.map((call) => `${call.method} ${call.url}`)).size).toBe(calls.length);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('gives a bot the spend bounds of every Service', () => {
|
|
77
|
+
expect(REFLEX_SERVICE_SPEND_LIMITS).toEqual({
|
|
78
|
+
monthlySpendCapDefaultCents: 1000,
|
|
79
|
+
monthlySpendCapMinCents: 100,
|
|
80
|
+
monthlySpendCapMaxCents: 50000,
|
|
81
|
+
alertThresholdsMax: 5,
|
|
82
|
+
alertThresholdMin: 1,
|
|
83
|
+
alertThresholdMax: 100,
|
|
84
|
+
spendCapDefaultThresholds: [80, 100],
|
|
85
|
+
});
|
|
86
|
+
expect(REFLEX_BOT_LIMITS).toMatchObject(REFLEX_SERVICE_SPEND_LIMITS);
|
|
87
|
+
expect(REFLEX_BOT_LIMITS).toMatchObject({
|
|
88
|
+
eventsPerMinutePerLot: 500,
|
|
89
|
+
rateAlertDefaultMinutes: 5,
|
|
90
|
+
rateAlertDefaultPercent: 80,
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('names the stops of a Service the same at the edge and in the task history', () => {
|
|
95
|
+
expect(Object.values(ServiceBlockReason)).toEqual(['CREDITS_EXHAUSTED', 'BUDGET_REACHED']);
|
|
96
|
+
expect(ReflexErrorCode.CREDITS_EXHAUSTED).toBe(ServiceBlockReason.CREDITS_EXHAUSTED);
|
|
97
|
+
expect(ReflexErrorCode.BUDGET_REACHED).toBe(ServiceBlockReason.BUDGET_REACHED);
|
|
98
|
+
expect(ScheduledRunFailureCode.BUDGET_REACHED).toBe(ServiceBlockReason.BUDGET_REACHED);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { AbyssReflexCore } from '..';
|
|
2
|
-
import type {
|
|
3
|
-
IListServiceLimitsParams,
|
|
4
|
-
IListServiceLimitsResponse,
|
|
5
|
-
ISetServiceLimitsBody,
|
|
6
|
-
ISetServiceLimitsParams,
|
|
7
|
-
ISetServiceLimitsResponse,
|
|
8
|
-
} from '../types';
|
|
9
|
-
|
|
10
|
-
const limitsUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
11
|
-
`api/service/${params.applicationId}/${params.serviceId}/limits`;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* `GET .../limits`: the credits of the month, the monthly spend cap, the alerts and the stop of the Service in
|
|
15
|
-
* each environment. Needs REFLEX_READ.
|
|
16
|
-
*/
|
|
17
|
-
export const listServiceLimits = async (
|
|
18
|
-
params: IListServiceLimitsParams,
|
|
19
|
-
): Promise<IListServiceLimitsResponse> =>
|
|
20
|
-
(await AbyssReflexCore.axios.get<IListServiceLimitsResponse>(limitsUrl(params))).data;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* `PUT .../limits/:environmentId`: the credit overage, the monthly spend cap and the alerts of the Service in
|
|
24
|
-
* one environment; a stop the change lifts is lifted at the next computation. `409 CREDIT_OVERAGE_NOT_ALLOWED`
|
|
25
|
-
* when the organization does not allow overage. Needs REFLEX_PUBLISH for an HTTP Service, REFLEX_BOT_MANAGE for
|
|
26
|
-
* a bot.
|
|
27
|
-
*/
|
|
28
|
-
export const setServiceLimits = async (
|
|
29
|
-
params: ISetServiceLimitsParams,
|
|
30
|
-
body: ISetServiceLimitsBody,
|
|
31
|
-
): Promise<ISetServiceLimitsResponse> =>
|
|
32
|
-
(
|
|
33
|
-
await AbyssReflexCore.axios.put<ISetServiceLimitsResponse>(
|
|
34
|
-
`${limitsUrl(params)}/${params.environmentId}`,
|
|
35
|
-
body,
|
|
36
|
-
)
|
|
37
|
-
).data;
|
|
1
|
+
import { AbyssReflexCore } from '..';
|
|
2
|
+
import type {
|
|
3
|
+
IListServiceLimitsParams,
|
|
4
|
+
IListServiceLimitsResponse,
|
|
5
|
+
ISetServiceLimitsBody,
|
|
6
|
+
ISetServiceLimitsParams,
|
|
7
|
+
ISetServiceLimitsResponse,
|
|
8
|
+
} from '../types';
|
|
9
|
+
|
|
10
|
+
const limitsUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
11
|
+
`api/service/${params.applicationId}/${params.serviceId}/limits`;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* `GET .../limits`: the credits of the month, the monthly spend cap, the alerts and the stop of the Service in
|
|
15
|
+
* each environment. Needs REFLEX_READ.
|
|
16
|
+
*/
|
|
17
|
+
export const listServiceLimits = async (
|
|
18
|
+
params: IListServiceLimitsParams,
|
|
19
|
+
): Promise<IListServiceLimitsResponse> =>
|
|
20
|
+
(await AbyssReflexCore.axios.get<IListServiceLimitsResponse>(limitsUrl(params))).data;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* `PUT .../limits/:environmentId`: the credit overage, the monthly spend cap and the alerts of the Service in
|
|
24
|
+
* one environment; a stop the change lifts is lifted at the next computation. `409 CREDIT_OVERAGE_NOT_ALLOWED`
|
|
25
|
+
* when the organization does not allow overage. Needs REFLEX_PUBLISH for an HTTP Service, REFLEX_BOT_MANAGE for
|
|
26
|
+
* a bot.
|
|
27
|
+
*/
|
|
28
|
+
export const setServiceLimits = async (
|
|
29
|
+
params: ISetServiceLimitsParams,
|
|
30
|
+
body: ISetServiceLimitsBody,
|
|
31
|
+
): Promise<ISetServiceLimitsResponse> =>
|
|
32
|
+
(
|
|
33
|
+
await AbyssReflexCore.axios.put<ISetServiceLimitsResponse>(
|
|
34
|
+
`${limitsUrl(params)}/${params.environmentId}`,
|
|
35
|
+
body,
|
|
36
|
+
)
|
|
37
|
+
).data;
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
-
import { AbyssReflexCore, REFLEX_CONTRACT_LIMITS, ReflexErrorCode } from '..';
|
|
3
|
-
|
|
4
|
-
const APP = 'app-1';
|
|
5
|
-
const SVC = 'svc-1';
|
|
6
|
-
const SERVICE = { applicationId: APP, serviceId: SVC };
|
|
7
|
-
|
|
8
|
-
describe('AbyssReflexCore OpenAPI route', () => {
|
|
9
|
-
const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
|
|
10
|
-
async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
|
|
15
|
-
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
beforeEach(() => adapter.mockClear());
|
|
19
|
-
|
|
20
|
-
it('get calls GET .../openapi with the environment and the version', async () => {
|
|
21
|
-
await AbyssReflexCore.sdk.service.openapi.get(SERVICE, {
|
|
22
|
-
environmentId: 'e-1',
|
|
23
|
-
versionId: 'v-1',
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
const config = adapter.mock.calls[0][0];
|
|
27
|
-
expect(config.method).toBe('get');
|
|
28
|
-
expect(config.url).toBe(`api/service/${APP}/${SVC}/openapi`);
|
|
29
|
-
expect(config.baseURL).toBe('http://reflex.test/');
|
|
30
|
-
expect(config.params).toEqual({ environmentId: 'e-1', versionId: 'v-1' });
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('asks for the draft when no version is named', async () => {
|
|
34
|
-
await AbyssReflexCore.sdk.service.openapi.get(SERVICE, { environmentId: 'e-1' });
|
|
35
|
-
|
|
36
|
-
expect(adapter.mock.calls[0][0].params).toEqual({ environmentId: 'e-1' });
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('carries the bounds of a contract and its error codes', () => {
|
|
40
|
-
expect(REFLEX_CONTRACT_LIMITS).toEqual({
|
|
41
|
-
maxBytes: 32_768,
|
|
42
|
-
maxDepth: 32,
|
|
43
|
-
patternMaxLength: 256,
|
|
44
|
-
descriptionMaxLength: 500,
|
|
45
|
-
maxErrors: 20,
|
|
46
|
-
statusMin: 100,
|
|
47
|
-
statusMax: 599,
|
|
48
|
-
});
|
|
49
|
-
expect(ReflexErrorCode.CONTRACT_INVALID).toBe('CONTRACT_INVALID');
|
|
50
|
-
expect(ReflexErrorCode.REQUEST_INVALID).toBe('REQUEST_INVALID');
|
|
51
|
-
});
|
|
52
|
-
});
|
|
1
|
+
import { AxiosAdapter, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { AbyssReflexCore, REFLEX_CONTRACT_LIMITS, ReflexErrorCode } from '..';
|
|
3
|
+
|
|
4
|
+
const APP = 'app-1';
|
|
5
|
+
const SVC = 'svc-1';
|
|
6
|
+
const SERVICE = { applicationId: APP, serviceId: SVC };
|
|
7
|
+
|
|
8
|
+
describe('AbyssReflexCore OpenAPI route', () => {
|
|
9
|
+
const adapter = jest.fn<ReturnType<AxiosAdapter>, [InternalAxiosRequestConfig]>(
|
|
10
|
+
async (config) => ({ data: { data: {} }, status: 200, statusText: '', headers: {}, config }),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
AbyssReflexCore.setConfig({ baseURL: 'http://reflex.test/', token: 'session-token' });
|
|
15
|
+
AbyssReflexCore.axios.defaults.adapter = adapter;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
beforeEach(() => adapter.mockClear());
|
|
19
|
+
|
|
20
|
+
it('get calls GET .../openapi with the environment and the version', async () => {
|
|
21
|
+
await AbyssReflexCore.sdk.service.openapi.get(SERVICE, {
|
|
22
|
+
environmentId: 'e-1',
|
|
23
|
+
versionId: 'v-1',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const config = adapter.mock.calls[0][0];
|
|
27
|
+
expect(config.method).toBe('get');
|
|
28
|
+
expect(config.url).toBe(`api/service/${APP}/${SVC}/openapi`);
|
|
29
|
+
expect(config.baseURL).toBe('http://reflex.test/');
|
|
30
|
+
expect(config.params).toEqual({ environmentId: 'e-1', versionId: 'v-1' });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('asks for the draft when no version is named', async () => {
|
|
34
|
+
await AbyssReflexCore.sdk.service.openapi.get(SERVICE, { environmentId: 'e-1' });
|
|
35
|
+
|
|
36
|
+
expect(adapter.mock.calls[0][0].params).toEqual({ environmentId: 'e-1' });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('carries the bounds of a contract and its error codes', () => {
|
|
40
|
+
expect(REFLEX_CONTRACT_LIMITS).toEqual({
|
|
41
|
+
maxBytes: 32_768,
|
|
42
|
+
maxDepth: 32,
|
|
43
|
+
patternMaxLength: 256,
|
|
44
|
+
descriptionMaxLength: 500,
|
|
45
|
+
maxErrors: 20,
|
|
46
|
+
statusMin: 100,
|
|
47
|
+
statusMax: 599,
|
|
48
|
+
});
|
|
49
|
+
expect(ReflexErrorCode.CONTRACT_INVALID).toBe('CONTRACT_INVALID');
|
|
50
|
+
expect(ReflexErrorCode.REQUEST_INVALID).toBe('REQUEST_INVALID');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { AbyssReflexCore } from '..';
|
|
2
|
-
import type {
|
|
3
|
-
IGetServiceOpenApiParams,
|
|
4
|
-
IGetServiceOpenApiQuery,
|
|
5
|
-
IGetServiceOpenApiResponse,
|
|
6
|
-
} from '../types';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `GET .../openapi?environmentId=&versionId=`: the OpenAPI 3.1 document of the routes of a version of the
|
|
10
|
-
* Service, or of its draft without `versionId`, served by the edge of the environment. Needs REFLEX_READ.
|
|
11
|
-
*/
|
|
12
|
-
export const getServiceOpenApi = async (
|
|
13
|
-
params: IGetServiceOpenApiParams,
|
|
14
|
-
query: IGetServiceOpenApiQuery,
|
|
15
|
-
): Promise<IGetServiceOpenApiResponse> =>
|
|
16
|
-
(
|
|
17
|
-
await AbyssReflexCore.axios.get<IGetServiceOpenApiResponse>(
|
|
18
|
-
`api/service/${params.applicationId}/${params.serviceId}/openapi`,
|
|
19
|
-
{ params: query },
|
|
20
|
-
)
|
|
21
|
-
).data;
|
|
1
|
+
import { AbyssReflexCore } from '..';
|
|
2
|
+
import type {
|
|
3
|
+
IGetServiceOpenApiParams,
|
|
4
|
+
IGetServiceOpenApiQuery,
|
|
5
|
+
IGetServiceOpenApiResponse,
|
|
6
|
+
} from '../types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `GET .../openapi?environmentId=&versionId=`: the OpenAPI 3.1 document of the routes of a version of the
|
|
10
|
+
* Service, or of its draft without `versionId`, served by the edge of the environment. Needs REFLEX_READ.
|
|
11
|
+
*/
|
|
12
|
+
export const getServiceOpenApi = async (
|
|
13
|
+
params: IGetServiceOpenApiParams,
|
|
14
|
+
query: IGetServiceOpenApiQuery,
|
|
15
|
+
): Promise<IGetServiceOpenApiResponse> =>
|
|
16
|
+
(
|
|
17
|
+
await AbyssReflexCore.axios.get<IGetServiceOpenApiResponse>(
|
|
18
|
+
`api/service/${params.applicationId}/${params.serviceId}/openapi`,
|
|
19
|
+
{ params: query },
|
|
20
|
+
)
|
|
21
|
+
).data;
|
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { AbyssReflexCore } from '..';
|
|
2
|
-
import type {
|
|
3
|
-
ICreateServiceRouteBody,
|
|
4
|
-
ICreateServiceRouteParams,
|
|
5
|
-
ICreateServiceRouteResponse,
|
|
6
|
-
IDeleteServiceRouteParams,
|
|
7
|
-
IDeleteServiceRouteResponse,
|
|
8
|
-
IListServiceRouteParams,
|
|
9
|
-
IListServiceRouteResponse,
|
|
10
|
-
IRotateServiceRouteParams,
|
|
11
|
-
IRotateServiceRouteResponse,
|
|
12
|
-
IUpdateServiceRouteBody,
|
|
13
|
-
IUpdateServiceRouteParams,
|
|
14
|
-
IUpdateServiceRouteResponse,
|
|
15
|
-
} from '../types';
|
|
16
|
-
|
|
17
|
-
const routeUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
18
|
-
`api/service/${params.applicationId}/${params.serviceId}/route`;
|
|
19
|
-
|
|
20
|
-
/** `GET .../route`: the routes of the draft, by path then method. Needs REFLEX_READ. */
|
|
21
|
-
export const listServiceRoute = async (
|
|
22
|
-
params: IListServiceRouteParams,
|
|
23
|
-
): Promise<IListServiceRouteResponse> =>
|
|
24
|
-
(await AbyssReflexCore.axios.get<IListServiceRouteResponse>(routeUrl(params))).data;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* `POST .../route`: a route of the draft, served once a version holding it is in service. The signing
|
|
28
|
-
* secret of a SIGNATURE route comes back once; an API_KEY route is called with the keys of the consumers.
|
|
29
|
-
* `409 ROUTE_CONFLICT` when it would hide another route, `400 ROUTE_SEGMENT_RESERVED` for a path that starts
|
|
30
|
-
* with `_`, `400 CONTRACT_INVALID` for a contract that is not valid. Needs REFLEX_FUNCTION_UPDATE.
|
|
31
|
-
*/
|
|
32
|
-
export const createServiceRoute = async (
|
|
33
|
-
params: ICreateServiceRouteParams,
|
|
34
|
-
body: ICreateServiceRouteBody,
|
|
35
|
-
): Promise<ICreateServiceRouteResponse> =>
|
|
36
|
-
(await AbyssReflexCore.axios.post<ICreateServiceRouteResponse>(routeUrl(params), body)).data;
|
|
37
|
-
|
|
38
|
-
/** `PATCH .../route/:routeId`: changes the route in the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
39
|
-
export const updateServiceRoute = async (
|
|
40
|
-
params: IUpdateServiceRouteParams,
|
|
41
|
-
body: IUpdateServiceRouteBody,
|
|
42
|
-
): Promise<IUpdateServiceRouteResponse> =>
|
|
43
|
-
(
|
|
44
|
-
await AbyssReflexCore.axios.patch<IUpdateServiceRouteResponse>(
|
|
45
|
-
`${routeUrl(params)}/${params.routeId}`,
|
|
46
|
-
body,
|
|
47
|
-
)
|
|
48
|
-
).data;
|
|
49
|
-
|
|
50
|
-
/** `DELETE .../route/:routeId`: takes the route out of the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
51
|
-
export const deleteServiceRoute = async (
|
|
52
|
-
params: IDeleteServiceRouteParams,
|
|
53
|
-
): Promise<IDeleteServiceRouteResponse> =>
|
|
54
|
-
(
|
|
55
|
-
await AbyssReflexCore.axios.delete<IDeleteServiceRouteResponse>(
|
|
56
|
-
`${routeUrl(params)}/${params.routeId}`,
|
|
57
|
-
)
|
|
58
|
-
).data;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* `POST .../route/:routeId/rotate`: a new signing secret of a SIGNATURE route, shown once, served at once
|
|
62
|
-
* wherever the route is in service; `400` for any other route (the key of an API_KEY route is rotated by a new
|
|
63
|
-
* key of its consumer, then the revocation of the old one). Needs REFLEX_PUBLISH, and REFLEX_PUBLISH_PRODUCTION
|
|
64
|
-
* when a production environment serves the route.
|
|
65
|
-
*/
|
|
66
|
-
export const rotateServiceRoute = async (
|
|
67
|
-
params: IRotateServiceRouteParams,
|
|
68
|
-
): Promise<IRotateServiceRouteResponse> =>
|
|
69
|
-
(
|
|
70
|
-
await AbyssReflexCore.axios.post<IRotateServiceRouteResponse>(
|
|
71
|
-
`${routeUrl(params)}/${params.routeId}/rotate`,
|
|
72
|
-
{},
|
|
73
|
-
)
|
|
74
|
-
).data;
|
|
1
|
+
import { AbyssReflexCore } from '..';
|
|
2
|
+
import type {
|
|
3
|
+
ICreateServiceRouteBody,
|
|
4
|
+
ICreateServiceRouteParams,
|
|
5
|
+
ICreateServiceRouteResponse,
|
|
6
|
+
IDeleteServiceRouteParams,
|
|
7
|
+
IDeleteServiceRouteResponse,
|
|
8
|
+
IListServiceRouteParams,
|
|
9
|
+
IListServiceRouteResponse,
|
|
10
|
+
IRotateServiceRouteParams,
|
|
11
|
+
IRotateServiceRouteResponse,
|
|
12
|
+
IUpdateServiceRouteBody,
|
|
13
|
+
IUpdateServiceRouteParams,
|
|
14
|
+
IUpdateServiceRouteResponse,
|
|
15
|
+
} from '../types';
|
|
16
|
+
|
|
17
|
+
const routeUrl = (params: { applicationId: string; serviceId: string }): string =>
|
|
18
|
+
`api/service/${params.applicationId}/${params.serviceId}/route`;
|
|
19
|
+
|
|
20
|
+
/** `GET .../route`: the routes of the draft, by path then method. Needs REFLEX_READ. */
|
|
21
|
+
export const listServiceRoute = async (
|
|
22
|
+
params: IListServiceRouteParams,
|
|
23
|
+
): Promise<IListServiceRouteResponse> =>
|
|
24
|
+
(await AbyssReflexCore.axios.get<IListServiceRouteResponse>(routeUrl(params))).data;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `POST .../route`: a route of the draft, served once a version holding it is in service. The signing
|
|
28
|
+
* secret of a SIGNATURE route comes back once; an API_KEY route is called with the keys of the consumers.
|
|
29
|
+
* `409 ROUTE_CONFLICT` when it would hide another route, `400 ROUTE_SEGMENT_RESERVED` for a path that starts
|
|
30
|
+
* with `_`, `400 CONTRACT_INVALID` for a contract that is not valid. Needs REFLEX_FUNCTION_UPDATE.
|
|
31
|
+
*/
|
|
32
|
+
export const createServiceRoute = async (
|
|
33
|
+
params: ICreateServiceRouteParams,
|
|
34
|
+
body: ICreateServiceRouteBody,
|
|
35
|
+
): Promise<ICreateServiceRouteResponse> =>
|
|
36
|
+
(await AbyssReflexCore.axios.post<ICreateServiceRouteResponse>(routeUrl(params), body)).data;
|
|
37
|
+
|
|
38
|
+
/** `PATCH .../route/:routeId`: changes the route in the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
39
|
+
export const updateServiceRoute = async (
|
|
40
|
+
params: IUpdateServiceRouteParams,
|
|
41
|
+
body: IUpdateServiceRouteBody,
|
|
42
|
+
): Promise<IUpdateServiceRouteResponse> =>
|
|
43
|
+
(
|
|
44
|
+
await AbyssReflexCore.axios.patch<IUpdateServiceRouteResponse>(
|
|
45
|
+
`${routeUrl(params)}/${params.routeId}`,
|
|
46
|
+
body,
|
|
47
|
+
)
|
|
48
|
+
).data;
|
|
49
|
+
|
|
50
|
+
/** `DELETE .../route/:routeId`: takes the route out of the draft. Needs REFLEX_FUNCTION_UPDATE. */
|
|
51
|
+
export const deleteServiceRoute = async (
|
|
52
|
+
params: IDeleteServiceRouteParams,
|
|
53
|
+
): Promise<IDeleteServiceRouteResponse> =>
|
|
54
|
+
(
|
|
55
|
+
await AbyssReflexCore.axios.delete<IDeleteServiceRouteResponse>(
|
|
56
|
+
`${routeUrl(params)}/${params.routeId}`,
|
|
57
|
+
)
|
|
58
|
+
).data;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* `POST .../route/:routeId/rotate`: a new signing secret of a SIGNATURE route, shown once, served at once
|
|
62
|
+
* wherever the route is in service; `400` for any other route (the key of an API_KEY route is rotated by a new
|
|
63
|
+
* key of its consumer, then the revocation of the old one). Needs REFLEX_PUBLISH, and REFLEX_PUBLISH_PRODUCTION
|
|
64
|
+
* when a production environment serves the route.
|
|
65
|
+
*/
|
|
66
|
+
export const rotateServiceRoute = async (
|
|
67
|
+
params: IRotateServiceRouteParams,
|
|
68
|
+
): Promise<IRotateServiceRouteResponse> =>
|
|
69
|
+
(
|
|
70
|
+
await AbyssReflexCore.axios.post<IRotateServiceRouteResponse>(
|
|
71
|
+
`${routeUrl(params)}/${params.routeId}/rotate`,
|
|
72
|
+
{},
|
|
73
|
+
)
|
|
74
|
+
).data;
|