chore: Simplified payloads and endpoints

This commit is contained in:
Davidson Gomes
2024-06-07 13:00:35 -03:00
parent a578384e85
commit 8fd082ad80
25 changed files with 1329 additions and 1403 deletions

300
src/validate/chat.schema.ts Normal file
View File

@@ -0,0 +1,300 @@
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
import { v4 } from 'uuid';
import { isNotEmpty } from './validate.schema';
const numberDefinition: JSONSchema7Definition = {
type: 'string',
description: 'Invalid format',
};
export const whatsappNumberSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
numbers: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
description: '"numbers" must be an array of numeric strings',
},
},
},
};
export const readMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
read_messages: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
properties: {
id: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
remoteJid: { type: 'string' },
},
required: ['id', 'fromMe', 'remoteJid'],
...isNotEmpty('id', 'remoteJid'),
},
},
},
required: ['read_messages'],
};
export const archiveChatSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
chat: { type: 'string' },
lastMessage: {
type: 'object',
properties: {
key: {
type: 'object',
properties: {
id: { type: 'string' },
remoteJid: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
},
required: ['id', 'fromMe', 'remoteJid'],
...isNotEmpty('id', 'remoteJid'),
},
messageTimestamp: { type: 'integer', minLength: 1 },
},
required: ['key'],
...isNotEmpty('messageTimestamp'),
},
archive: { type: 'boolean', enum: [true, false] },
},
required: ['archive'],
};
export const markChatUnreadSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
chat: { type: 'string' },
lastMessage: {
type: 'object',
properties: {
key: {
type: 'object',
properties: {
id: { type: 'string' },
remoteJid: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
},
required: ['id', 'fromMe', 'remoteJid'],
...isNotEmpty('id', 'remoteJid'),
},
messageTimestamp: { type: 'integer', minLength: 1 },
},
required: ['key'],
...isNotEmpty('messageTimestamp'),
},
},
required: ['lastMessage'],
};
export const deleteMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
id: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
remoteJid: { type: 'string' },
participant: { type: 'string' },
},
required: ['id', 'fromMe', 'remoteJid'],
...isNotEmpty('id', 'remoteJid', 'participant'),
};
export const profilePictureSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { type: 'string' },
picture: { type: 'string' },
},
};
export const updateMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { type: 'string' },
text: { type: 'string' },
key: {
type: 'object',
properties: {
id: { type: 'string' },
remoteJid: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
},
required: ['id', 'fromMe', 'remoteJid'],
...isNotEmpty('id', 'remoteJid'),
},
},
...isNotEmpty('number', 'text', 'key'),
};
export const presenceSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
delay: { type: 'number' },
presence: {
type: 'string',
enum: ['unavailable', 'available', 'composing', 'recording', 'paused'],
},
},
required: ['number', 'presence', 'delay'],
};
export const blockUserSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { type: 'string' },
status: { type: 'string', enum: ['block', 'unblock'] },
},
required: ['number', 'status'],
...isNotEmpty('number', 'status'),
};
export const contactValidateSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
where: {
type: 'object',
properties: {
_id: { type: 'string', minLength: 1 },
pushName: { type: 'string', minLength: 1 },
id: { type: 'string', minLength: 1 },
},
...isNotEmpty('_id', 'id', 'pushName'),
},
},
};
export const messageValidateSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
where: {
type: 'object',
properties: {
_id: { type: 'string', minLength: 1 },
key: {
type: 'object',
if: {
propertyNames: {
enum: ['fromMe', 'remoteJid', 'id'],
},
},
then: {
properties: {
remoteJid: {
type: 'string',
minLength: 1,
description: 'The property cannot be empty',
},
id: {
type: 'string',
minLength: 1,
description: 'The property cannot be empty',
},
fromMe: { type: 'boolean', enum: [true, false] },
},
},
},
message: { type: 'object' },
},
...isNotEmpty('_id'),
},
limit: { type: 'integer' },
},
};
export const messageUpSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
where: {
type: 'object',
properties: {
_id: { type: 'string' },
remoteJid: { type: 'string' },
id: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
participant: { type: 'string' },
status: {
type: 'string',
enum: ['ERROR', 'PENDING', 'SERVER_ACK', 'DELIVERY_ACK', 'READ', 'PLAYED'],
},
},
...isNotEmpty('_id', 'remoteJid', 'id', 'status'),
},
limit: { type: 'integer' },
},
};
export const privacySettingsSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
readreceipts: { type: 'string', enum: ['all', 'none'] },
profile: {
type: 'string',
enum: ['all', 'contacts', 'contact_blacklist', 'none'],
},
status: {
type: 'string',
enum: ['all', 'contacts', 'contact_blacklist', 'none'],
},
online: { type: 'string', enum: ['all', 'match_last_seen'] },
last: { type: 'string', enum: ['all', 'contacts', 'contact_blacklist', 'none'] },
groupadd: {
type: 'string',
enum: ['all', 'contacts', 'contact_blacklist', 'none'],
},
},
required: ['readreceipts', 'profile', 'status', 'online', 'last', 'groupadd'],
...isNotEmpty('readreceipts', 'profile', 'status', 'online', 'last', 'groupadd'),
};
export const profileNameSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
name: { type: 'string' },
},
...isNotEmpty('name'),
};
export const profileStatusSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
status: { type: 'string' },
},
...isNotEmpty('status'),
};
export const profileSchema: JSONSchema7 = {
type: 'object',
properties: {
wuid: { type: 'string' },
name: { type: 'string' },
picture: { type: 'string' },
status: { type: 'string' },
isBusiness: { type: 'boolean' },
},
};

View File

@@ -0,0 +1,176 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
import { isNotEmpty } from './validate.schema';
export const createGroupSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
subject: { type: 'string' },
description: { type: 'string' },
profilePicture: { type: 'string' },
promoteParticipants: { type: 'boolean', enum: [true, false] },
participants: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
minLength: 10,
pattern: '\\d+',
description: '"participants" must be an array of numeric strings',
},
},
},
required: ['subject', 'participants'],
...isNotEmpty('subject', 'description', 'profilePicture'),
};
export const groupJidSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string', pattern: '^[\\d-]+@g.us$' },
},
required: ['groupJid'],
...isNotEmpty('groupJid'),
};
export const getParticipantsSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
getParticipants: { type: 'string', enum: ['true', 'false'] },
},
required: ['getParticipants'],
...isNotEmpty('getParticipants'),
};
export const groupSendInviteSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
description: { type: 'string' },
numbers: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
minLength: 10,
pattern: '\\d+',
description: '"numbers" must be an array of numeric strings',
},
},
},
required: ['groupJid', 'description', 'numbers'],
...isNotEmpty('groupJid', 'description', 'numbers'),
};
export const groupInviteSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
inviteCode: { type: 'string', pattern: '^[a-zA-Z0-9]{22}$' },
},
required: ['inviteCode'],
...isNotEmpty('inviteCode'),
};
export const AcceptGroupInviteSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
inviteCode: { type: 'string', pattern: '^[a-zA-Z0-9]{22}$' },
},
required: ['inviteCode'],
...isNotEmpty('inviteCode'),
};
export const updateParticipantsSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
action: {
type: 'string',
enum: ['add', 'remove', 'promote', 'demote'],
},
participants: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
minLength: 10,
pattern: '\\d+',
description: '"participants" must be an array of numeric strings',
},
},
},
required: ['groupJid', 'action', 'participants'],
...isNotEmpty('groupJid', 'action'),
};
export const updateSettingsSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
action: {
type: 'string',
enum: ['announcement', 'not_announcement', 'locked', 'unlocked'],
},
},
required: ['groupJid', 'action'],
...isNotEmpty('groupJid', 'action'),
};
export const toggleEphemeralSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
expiration: {
type: 'number',
enum: [0, 86400, 604800, 7776000],
},
},
required: ['groupJid', 'expiration'],
...isNotEmpty('groupJid', 'expiration'),
};
export const updateGroupPictureSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
image: { type: 'string' },
},
required: ['groupJid', 'image'],
...isNotEmpty('groupJid', 'image'),
};
export const updateGroupSubjectSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
subject: { type: 'string' },
},
required: ['groupJid', 'subject'],
...isNotEmpty('groupJid', 'subject'),
};
export const updateGroupDescriptionSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
groupJid: { type: 'string' },
description: { type: 'string' },
},
required: ['groupJid', 'description'],
...isNotEmpty('groupJid', 'description'),
};

View File

@@ -0,0 +1,100 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
import { Integration } from '../api/types/wa.types';
import { Events, isNotEmpty } from './validate.schema';
export const instanceSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
// Instance
instanceName: { type: 'string' },
token: { type: 'string' },
number: { type: 'string', pattern: '^\\d+[\\.@\\w-]+' },
qrcode: { type: 'boolean' },
Integration: {
type: 'string',
enum: Object.values(Integration),
},
// Settings
rejectCall: { type: 'boolean' },
msgCall: { type: 'string' },
groupsIgnore: { type: 'boolean' },
alwaysOnline: { type: 'boolean' },
readMessages: { type: 'boolean' },
readStatus: { type: 'boolean' },
syncFullHistory: { type: 'boolean' },
// Proxy
proxyHost: { type: 'string' },
proxyPort: { type: 'string' },
proxyProtocol: { type: 'string' },
proxyUsername: { type: 'string' },
proxyPassword: { type: 'string' },
// Webhook
webhookUrl: { type: 'string' },
webhookByEvents: { type: 'boolean' },
webhookBase64: { type: 'boolean' },
webhookEvents: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: Events,
},
},
// RabbitMQ
rabbitmqEnabled: { type: 'boolean' },
rabbitmqEvents: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: Events,
},
},
// SQS
sqsEnabled: { type: 'boolean' },
sqsEvents: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: Events,
},
},
// Chatwoot
chatwootAccountId: { type: 'string' },
chatwootToken: { type: 'string' },
chatwootUrl: { type: 'string' },
chatwootSignMsg: { type: 'boolean' },
chatwootReopenConversation: { type: 'boolean' },
chatwootConversationPending: { type: 'boolean' },
chatwootImportContacts: { type: 'boolean' },
chatwootNameInbox: { type: 'string' },
chatwootMergeBrazilContacts: { type: 'boolean' },
chatwootImportMessages: { type: 'boolean' },
chatwootDaysLimitImportMessages: { type: 'number' },
// Typebot
typebotUrl: { type: 'string' },
typebot: { type: 'boolean' },
typebotExpire: { type: 'number' },
typebotKeywordFinish: { type: 'string' },
typebotDelayMessage: { type: 'number' },
typebotUnknownMessage: { type: 'string' },
typebotListeningFromMe: { type: 'boolean' },
},
...isNotEmpty('instanceName'),
};
export const presenceOnlySchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
presence: {
type: 'string',
enum: ['unavailable', 'available', 'composing', 'recording', 'paused'],
},
},
required: ['presence'],
};

View File

@@ -0,0 +1,21 @@
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
import { v4 } from 'uuid';
import { isNotEmpty } from './validate.schema';
const numberDefinition: JSONSchema7Definition = {
type: 'string',
description: 'Invalid format',
};
export const handleLabelSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
labelId: { type: 'string' },
action: { type: 'string', enum: ['add', 'remove'] },
},
required: ['number', 'labelId', 'action'],
...isNotEmpty('number', 'labelId', 'action'),
};

View File

@@ -0,0 +1,343 @@
import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
import { v4 } from 'uuid';
import { isNotEmpty } from './validate.schema';
const numberDefinition: JSONSchema7Definition = {
type: 'string',
description: 'Invalid format',
};
export const templateMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
name: { type: 'string' },
language: { type: 'string' },
components: { type: 'array' },
},
required: ['name', 'language'],
};
const quotedOptionsSchema: JSONSchema7 = {
properties: {
key: {
type: 'object',
properties: {
id: { type: 'string' },
remoteJid: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
},
required: ['id'],
...isNotEmpty('id'),
},
message: { type: 'object' },
},
};
export const textMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
text: { type: 'string' },
linkPreview: { type: 'boolean' },
delay: {
type: 'integer',
description: 'Enter a value in milliseconds',
},
quoted: { ...quotedOptionsSchema },
everyOne: { type: 'boolean', enum: [true, false] },
mentioned: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"mentioned" must be an array of numeric strings',
},
},
},
required: ['number', 'text'],
};
export const mediaMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
mediatype: { type: 'string', enum: ['image', 'document', 'video', 'audio'] },
mimetype: { type: 'string' },
media: { type: 'string' },
fileName: { type: 'string' },
caption: { type: 'string' },
delay: {
type: 'integer',
description: 'Enter a value in milliseconds',
},
quoted: { ...quotedOptionsSchema },
everyOne: { type: 'boolean', enum: [true, false] },
mentioned: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"mentioned" must be an array of numeric strings',
},
},
},
required: ['number', 'mediatype', 'media'],
};
export const audioMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
audio: { type: 'string' },
delay: {
type: 'integer',
description: 'Enter a value in milliseconds',
},
quoted: { ...quotedOptionsSchema },
everyOne: { type: 'boolean', enum: [true, false] },
mentioned: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"mentioned" must be an array of numeric strings',
},
},
},
required: ['number', 'audio'],
};
export const statusMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
type: { type: 'string', enum: ['text', 'image', 'audio', 'video'] },
content: { type: 'string' },
caption: { type: 'string' },
backgroundColor: { type: 'string' },
font: { type: 'integer', minimum: 0, maximum: 5 },
statusJidList: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"statusJidList" must be an array of numeric strings',
},
},
allContacts: { type: 'boolean', enum: [true, false] },
},
required: ['type', 'content'],
};
export const stickerMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
sticker: { type: 'string' },
delay: {
type: 'integer',
description: 'Enter a value in milliseconds',
},
quoted: { ...quotedOptionsSchema },
everyOne: { type: 'boolean', enum: [true, false] },
mentioned: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"mentioned" must be an array of numeric strings',
},
},
},
required: ['number', 'sticker'],
};
export const locationMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
latitude: { type: 'number' },
longitude: { type: 'number' },
name: { type: 'string' },
address: { type: 'string' },
delay: {
type: 'integer',
description: 'Enter a value in milliseconds',
},
quoted: { ...quotedOptionsSchema },
everyOne: { type: 'boolean', enum: [true, false] },
mentioned: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"mentioned" must be an array of numeric strings',
},
},
},
required: ['number', 'latitude', 'longitude', 'name', 'address'],
};
export const contactMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
contact: {
type: 'array',
items: {
type: 'object',
properties: {
fullName: { type: 'string' },
wuid: {
type: 'string',
minLength: 10,
pattern: '\\d+',
description: '"wuid" must be a numeric string',
},
phoneNumber: { type: 'string', minLength: 10 },
organization: { type: 'string' },
email: { type: 'string' },
url: { type: 'string' },
},
required: ['fullName', 'phoneNumber'],
...isNotEmpty('fullName'),
},
minItems: 1,
uniqueItems: true,
},
},
required: ['number', 'contact'],
};
export const reactionMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
key: {
type: 'object',
properties: {
id: { type: 'string' },
remoteJid: { type: 'string' },
fromMe: { type: 'boolean', enum: [true, false] },
},
required: ['id', 'remoteJid', 'fromMe'],
...isNotEmpty('id', 'remoteJid'),
},
reaction: { type: 'string' },
},
required: ['key', 'reaction'],
};
export const pollMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
name: { type: 'string' },
selectableCount: { type: 'integer', minimum: 0, maximum: 10 },
values: {
type: 'array',
minItems: 2,
maxItems: 10,
uniqueItems: true,
items: {
type: 'string',
},
},
delay: {
type: 'integer',
description: 'Enter a value in milliseconds',
},
quoted: { ...quotedOptionsSchema },
everyOne: { type: 'boolean', enum: [true, false] },
mentioned: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"mentioned" must be an array of numeric strings',
},
},
},
required: ['number', 'name', 'selectableCount', 'values'],
};
export const listMessageSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
number: { ...numberDefinition },
title: { type: 'string' },
description: { type: 'string' },
footerText: { type: 'string' },
buttonText: { type: 'string' },
sections: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'object',
properties: {
title: { type: 'string' },
rows: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'object',
properties: {
title: { type: 'string' },
description: { type: 'string' },
rowId: { type: 'string' },
},
required: ['title', 'rowId'],
...isNotEmpty('title', 'description', 'rowId'),
},
},
},
required: ['title', 'rows'],
...isNotEmpty('title'),
},
},
delay: {
type: 'integer',
description: 'Enter a value in milliseconds',
},
quoted: { ...quotedOptionsSchema },
everyOne: { type: 'boolean', enum: [true, false] },
mentioned: {
type: 'array',
minItems: 1,
uniqueItems: true,
items: {
type: 'string',
pattern: '^\\d+',
description: '"mentioned" must be an array of numeric strings',
},
},
},
required: ['number', 'title', 'footerText', 'buttonText', 'sections'],
};

View File

@@ -0,0 +1,19 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
import { isNotEmpty } from './validate.schema';
export const proxySchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
host: { type: 'string' },
port: { type: 'string' },
protocol: { type: 'string' },
username: { type: 'string' },
password: { type: 'string' },
},
required: ['enabled', 'host', 'port', 'protocol'],
...isNotEmpty('enabled', 'host', 'port', 'protocol'),
};

View File

@@ -0,0 +1,20 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
import { isNotEmpty } from './validate.schema';
export const settingsSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
rejectCall: { type: 'boolean' },
msgCall: { type: 'string' },
groupsIgnore: { type: 'boolean' },
alwaysOnline: { type: 'boolean' },
readMessages: { type: 'boolean' },
readStatus: { type: 'boolean' },
syncFullHistory: { type: 'boolean' },
},
required: ['rejectCall', 'groupsIgnore', 'alwaysOnline', 'readMessages', 'readStatus', 'syncFullHistory'],
...isNotEmpty('rejectCall', 'groupsIgnore', 'alwaysOnline', 'readMessages', 'readStatus', 'syncFullHistory'),
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
import { Events, isNotEmpty } from './validate.schema';
export const webhookSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean' },
url: { type: 'string' },
webhookByEvents: { type: 'boolean' },
webhookBase64: { type: 'boolean' },
events: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: Events,
},
},
},
required: ['enabled', 'url'],
...isNotEmpty('enabled', 'url'),
};

View File

@@ -0,0 +1,22 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';
import { Events, isNotEmpty } from './validate.schema';
export const websocketSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
events: {
type: 'array',
minItems: 0,
items: {
type: 'string',
enum: Events,
},
},
},
required: ['enabled'],
...isNotEmpty('enabled'),
};