-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathintegrations.ts
More file actions
48 lines (43 loc) · 1.72 KB
/
integrations.ts
File metadata and controls
48 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import type { ISetting } from '@rocket.chat/core-typings';
import { schemas } from '@rocket.chat/core-typings';
import { ajv, validateForbiddenErrorResponse, validateUnauthorizedErrorResponse } from '@rocket.chat/rest-typings';
import { API } from '../../../../api/server';
import type { ExtractRoutesFromAPI } from '../../../../api/server/ApiClass';
import { findIntegrationSettings } from '../../../server/api/lib/integrations';
// Register ISetting schema for $ref resolution (livechat loads before api/server/ajv.ts)
const iSettingSchema = schemas.components?.schemas?.ISetting;
if (iSettingSchema && !ajv.getSchema('#/components/schemas/ISetting')) {
ajv.addSchema(iSettingSchema, '#/components/schemas/ISetting');
}
const livechatIntegrationsEndpoints = API.v1.get(
'livechat/integrations.settings',
{
authRequired: true,
permissionsRequired: ['view-livechat-manager'],
query: undefined,
response: {
401: validateUnauthorizedErrorResponse,
403: validateForbiddenErrorResponse,
200: ajv.compile<{ settings: ISetting[]; success: boolean }>({
type: 'object',
properties: {
settings: {
type: 'array',
items: { $ref: '#/components/schemas/ISetting' },
},
success: { type: 'boolean', enum: [true] },
},
required: ['settings', 'success'],
additionalProperties: false,
}),
},
},
async function action() {
return API.v1.success(await findIntegrationSettings());
},
);
type LivechatIntegrationsEndpoints = ExtractRoutesFromAPI<typeof livechatIntegrationsEndpoints>;
declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
interface Endpoints extends LivechatIntegrationsEndpoints {}
}