/
main.ts
54 lines (52 loc) · 1.19 KB
/
main.ts
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
49
50
51
52
53
54
import type { JWT } from '@becomes/purple-cheetah-mod-jwt/types';
import type {
HTTPError,
Logger,
ObjectSchema,
} from '@becomes/purple-cheetah/types';
import type { Request } from 'express';
import type { BCMSApiKey } from '../../api';
import type { BCMSUserCustomPool } from '../../user';
export interface BCMSFunctionConfig {
/**
* Will be converted to lowercase without
* special characters and spaces will be
* replaced with "-".
*/
name: string;
/**
* If set to "true", anyone can call this
* function. Defaults to "false".
*/
public?: boolean;
}
export const BCMSFunctionConfigSchema: ObjectSchema = {
name: {
__type: 'string',
__required: true,
},
public: {
__type: 'boolean',
__required: false,
},
};
export interface BCMSFunction<Result> {
config: BCMSFunctionConfig;
handler(data: {
request: Request;
errorHandler: HTTPError;
logger: Logger;
auth: BCMSApiKey | JWT<BCMSUserCustomPool>;
}): Promise<Result>;
}
export const BCMSFunctionSchema: ObjectSchema = {
config: {
__type: 'object',
__required: true,
__child: BCMSFunctionConfigSchema,
},
handler: {
__type: 'function',
__required: true,
},
};