File size: 1,259 Bytes
5e518ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';

import { EventController } from '../event.controller';
const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
  const properties = {};
  propertyNames.forEach(
    (property) =>
      (properties[property] = {
        minLength: 1,
        description: `The "${property}" cannot be empty`,
      }),
  );
  return {
    if: {
      propertyNames: {
        enum: [...propertyNames],
      },
    },
    then: { properties },
  };
};
export const pusherSchema: JSONSchema7 = {
  $id: v4(),
  type: 'object',
  properties: {
    pusher: {
      type: 'object',
      properties: {
        enabled: { type: 'boolean' },
        appId: { type: 'string' },
        key: { type: 'string' },
        secret: { type: 'string' },
        cluster: { type: 'string' },
        useTLS: { type: 'boolean' },
        events: {
          type: 'array',
          minItems: 0,
          items: {
            type: 'string',
            enum: EventController.events,
          },
        },
      },
      required: ['enabled', 'appId', 'key', 'secret', 'cluster', 'useTLS'],
      ...isNotEmpty('enabled', 'appId', 'key', 'secret', 'cluster', 'useTLS'),
    },
  },
  required: ['pusher'],
};