From c7f4ac5173732da222acdd0b18820bf062c9903e Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Mon, 23 May 2022 09:13:46 -0300 Subject: [PATCH 01/18] chore: add Ajv to banners.ts (work in progress) --- packages/rest-typings/src/v1/banners.ts | 83 +++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/packages/rest-typings/src/v1/banners.ts b/packages/rest-typings/src/v1/banners.ts index 2af16f69620d..3d8a930f1f71 100644 --- a/packages/rest-typings/src/v1/banners.ts +++ b/packages/rest-typings/src/v1/banners.ts @@ -1,26 +1,101 @@ +import Ajv, { JSONSchemaType } from 'ajv'; import type { BannerPlatform, IBanner } from '@rocket.chat/core-typings'; +const ajv = new Ajv(); + +type BannersGetNew = { + platform: BannerPlatform; + bid: IBanner['_id']; +}; + +const BannersGetNewSchema: JSONSchemaType = { + type: 'object', + properties: { + platform: { + type: 'string', + }, + bid: { + type: 'string', + }, + }, + required: ['platform', 'bid'], + additionalProperties: false, +}; + +export const isBannersGetNew = ajv.compile(BannersGetNewSchema); + +type BannersId = { + platform: BannerPlatform; +}; + +const BannersIdSchema: JSONSchemaType = { + type: 'object', + properties: { + platform: { + type: 'string', + }, + }, + required: ['platform'], + additionalProperties: false, +}; + +export const isBannersId = ajv.compile(BannersIdSchema); + +type Banners = { + platform: BannerPlatform; +}; + +const BannersSchema: JSONSchemaType = { + type: 'object', + properties: { + platform: { + type: 'string', + }, + }, + required: ['platform'], + additionalProperties: false, +}; + +export const isBanners = ajv.compile(BannersSchema); + +type BannersDismiss = { + bannerId: string; +}; + +const BannersDismissSchema: JSONSchemaType = { + type: 'object', + properties: { + bannerId: { + type: 'string', + }, + }, + required: ['bannerId'], + additionalProperties: false, +}; + +export const isBannersDismiss = ajv.compile(BannersDismissSchema); + export type BannersEndpoints = { /* @deprecated */ 'banners.getNew': { - GET: (params: { platform: BannerPlatform; bid: IBanner['_id'] }) => { + GET: (params: BannersGetNew) => { banners: IBanner[]; }; }; 'banners/:id': { - GET: (params: { platform: BannerPlatform }) => { + GET: (params: BannersId) => { banners: IBanner[]; }; }; 'banners': { - GET: (params: { platform: BannerPlatform }) => { + GET: (params: Banners) => { banners: IBanner[]; }; }; 'banners.dismiss': { - POST: (params: { bannerId: string }) => void; + POST: (params: BannersDismiss) => void; }; }; From ae1de996ae08fc1ae507bdf810d5ac288871e536 Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 25 May 2022 07:42:58 -0300 Subject: [PATCH 02/18] fix banners.ts and chat.ts JSON Schemas --- packages/rest-typings/src/v1/banners.ts | 8 +- packages/rest-typings/src/v1/chat.ts | 418 +++++++++++++++++++++++- 2 files changed, 405 insertions(+), 21 deletions(-) diff --git a/packages/rest-typings/src/v1/banners.ts b/packages/rest-typings/src/v1/banners.ts index 3d8a930f1f71..0715591e5241 100644 --- a/packages/rest-typings/src/v1/banners.ts +++ b/packages/rest-typings/src/v1/banners.ts @@ -22,7 +22,7 @@ const BannersGetNewSchema: JSONSchemaType = { additionalProperties: false, }; -export const isBannersGetNew = ajv.compile(BannersGetNewSchema); +export const isBannersGetNewProps = ajv.compile(BannersGetNewSchema); type BannersId = { platform: BannerPlatform; @@ -39,7 +39,7 @@ const BannersIdSchema: JSONSchemaType = { additionalProperties: false, }; -export const isBannersId = ajv.compile(BannersIdSchema); +export const isBannersIdProps = ajv.compile(BannersIdSchema); type Banners = { platform: BannerPlatform; @@ -56,7 +56,7 @@ const BannersSchema: JSONSchemaType = { additionalProperties: false, }; -export const isBanners = ajv.compile(BannersSchema); +export const isBannersProps = ajv.compile(BannersSchema); type BannersDismiss = { bannerId: string; @@ -73,7 +73,7 @@ const BannersDismissSchema: JSONSchemaType = { additionalProperties: false, }; -export const isBannersDismiss = ajv.compile(BannersDismissSchema); +export const isBannersDismissProps = ajv.compile(BannersDismissSchema); export type BannersEndpoints = { /* @deprecated */ diff --git a/packages/rest-typings/src/v1/chat.ts b/packages/rest-typings/src/v1/chat.ts index e22ab320c99f..11fc907f6b3b 100644 --- a/packages/rest-typings/src/v1/chat.ts +++ b/packages/rest-typings/src/v1/chat.ts @@ -1,46 +1,430 @@ import type { IMessage, IRoom, ReadReceipt } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; + +const ajv = new Ajv(); + +type ChatFollowMessage = { + mid: IMessage['_id']; +}; + +const chatFollowMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + mid: { + type: 'string', + }, + }, + required: ['mid'], + additionalProperties: false, +}; + +export const isChatFollowMessageProps = ajv.compile(chatFollowMessageSchema); + +type ChatUnfollowMessage = { + mid: IMessage['_id']; +}; + +const chatUnfollowMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + mid: { + type: 'string', + }, + }, + required: ['mid'], + additionalProperties: false, +}; + +export const isChatUnfollowMessageProps = ajv.compile(chatUnfollowMessageSchema); + +type ChatGetMessage = { + msgId: IMessage['_id']; +}; + +const ChatGetMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + msgId: { + type: 'string', + }, + }, + required: ['msgId'], + additionalProperties: false, +}; + +export const isChatGetMessageProps = ajv.compile(ChatGetMessageSchema); + +type ChatStarMessage = { + msgId: IMessage['_id']; +}; + +const ChatStarMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + msgId: { + type: 'string', + }, + }, + required: ['msgId'], + additionalProperties: false, +}; + +export const isChatStarMessageProps = ajv.compile(ChatStarMessageSchema); + +type ChatUnstarMessage = { + msgId: IMessage['_id']; +}; + +const ChatUnstarMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + msgId: { + type: 'string', + }, + }, + required: ['msgId'], + additionalProperties: false, +}; + +export const isChatUnstarMessageProps = ajv.compile(ChatUnstarMessageSchema); + +type ChatPinMessage = { + msgId: IMessage['_id']; +}; + +const ChatPinMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + msgId: { + type: 'string', + }, + }, + required: ['msgId'], + additionalProperties: false, +}; + +export const isChatPinMessageProps = ajv.compile(ChatPinMessageSchema); + +type ChatUnpinMessage = { + messageId: IMessage['_id']; +}; + +const ChatUnpinMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + messageId: { + type: 'string', + }, + }, + required: ['messageId'], + additionalProperties: false, +}; + +export const isChatUnpinMessageProps = ajv.compile(ChatUnpinMessageSchema); + +type ChatGetDiscussions = { + roomId: IRoom['_id']; + text?: string; + offset: number; + count: number; +}; + +const ChatGetDiscussionsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + text: { + type: 'string', + nullable: true, + }, + offset: { + type: 'number', + }, + count: { + type: 'number', + }, + }, + required: ['roomId', 'offset', 'count'], + additionalProperties: false, +}; + +export const isChatGetDiscussionsProps = ajv.compile(ChatGetDiscussionsSchema); + +type ChatReportMessage = { + messageId: IMessage['_id']; + description: string; +}; + +const ChatReportMessageSchema: JSONSchemaType = { + type: 'object', + properties: { + messageId: { + type: 'string', + }, + description: { + type: 'string', + }, + }, + required: ['messageId', 'description'], + additionalProperties: false, +}; + +export const isChatReportMessageProps = ajv.compile(ChatReportMessageSchema); + +type ChatGetThreadsList = { + rid: IRoom['_id']; + type: 'unread' | 'following' | 'all'; + text?: string; + offset: number; + count: number; +}; + +const ChatGetThreadsListSchema: JSONSchemaType = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + type: { + type: 'string', + }, + text: { + type: 'string', + nullable: true, + }, + offset: { + type: 'number', + }, + count: { + type: 'number', + }, + }, + required: ['rid', 'type', 'offset', 'count'], + additionalProperties: false, +}; + +export const isChatGetThreadsListProps = ajv.compile(ChatGetThreadsListSchema); + +type ChatSyncThreadsList = { + rid: IRoom['_id']; + updatedSince: string; +}; + +const ChatSyncThreadsListSchema: JSONSchemaType = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + updatedSince: { + type: 'string', + }, + }, + required: ['rid', 'updatedSince'], + additionalProperties: false, +}; + +export const isChatSyncThreadsListProps = ajv.compile(ChatSyncThreadsListSchema); + +type ChatDelete = { + msgId: IMessage['_id']; + roomId: IRoom['_id']; +}; + +const ChatDeleteSchema: JSONSchemaType = { + type: 'object', + properties: { + msgId: { + type: 'string', + }, + roomId: { + type: 'string', + }, + }, + required: ['msgId', 'roomId'], + additionalProperties: false, +}; + +export const isChatDeleteProps = ajv.compile(ChatDeleteSchema); + +type ChatReact = { emoji: string; messageId: IMessage['_id'] } | { reaction: string; messageId: IMessage['_id'] }; + +const ChatReactSchema = { + oneOf: [ + { + type: 'object', + properties: { + emoji: { + type: 'string', + }, + messageId: { + type: 'string', + }, + }, + required: ['emoji', 'messageId'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + reaction: { + type: 'string', + }, + messageId: { + type: 'string', + }, + }, + required: ['reaction', 'messageId'], + additionalProperties: false, + }, + ], +}; + +export const isChatReactProps = ajv.compile(ChatReactSchema); + +/** + * The param `ignore` cannot be boolean, since this is a GET method. Use strings 'true' or 'false' instead. + * @param {string} ignore + */ +type ChatIgnoreUser = { + rid: string; + userId: string; + ignore: string; +}; + +const ChatIgnoreUserSchema = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + userId: { + type: 'string', + }, + ignore: { + type: 'string', + }, + }, + required: ['rid', 'userId', 'ignore'], + additionalProperties: false, +}; + +export const isChatIgnoreUserProps = ajv.compile(ChatIgnoreUserSchema); + +type ChatSearch = { + roomId: IRoom['_id']; + searchText: string; + count: number; + offset: number; +}; + +const ChatSearchSchema = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + searchText: { + type: 'string', + }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + }, + required: ['roomId', 'searchText', 'count', 'offset'], + additionalProperties: false, +}; + +export const isChatSearchProps = ajv.compile(ChatSearchSchema); + +type ChatUpdate = { + roomId: IRoom['_id']; + msgId: string; + text: string; +}; + +const ChatUpdateSchema = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + msgId: { + type: 'string', + }, + text: { + type: 'string', + }, + }, + required: ['roomId', 'msgId', 'text'], + additionalProperties: false, +}; + +export const isChatUpdateProps = ajv.compile(ChatUpdateSchema); + +type ChatGetMessageReadReceipts = { + messageId: IMessage['_id']; +}; + +const ChatGetMessageReadReceiptsSchema: JSONSchemaType = { + type: 'object', + properties: { + messageId: { + type: 'string', + }, + }, + required: ['messageId'], + additionalProperties: false, +}; + +export const isChatGetMessageReadReceiptsProps = ajv.compile(ChatGetMessageReadReceiptsSchema); export type ChatEndpoints = { 'chat.getMessage': { - GET: (params: { msgId: IMessage['_id'] }) => { + GET: (params: ChatGetMessage) => { message: IMessage; }; }; 'chat.followMessage': { - POST: (params: { mid: IMessage['_id'] }) => void; + POST: (params: ChatFollowMessage) => void; }; 'chat.unfollowMessage': { - POST: (params: { mid: IMessage['_id'] }) => void; + POST: (params: ChatUnfollowMessage) => void; }; 'chat.starMessage': { - POST: (params: { messageId: IMessage['_id'] }) => void; + POST: (params: ChatStarMessage) => void; }; 'chat.unStarMessage': { - POST: (params: { messageId: IMessage['_id'] }) => void; + POST: (params: ChatUnstarMessage) => void; }; 'chat.pinMessage': { - POST: (params: { messageId: IMessage['_id'] }) => void; + POST: (params: ChatPinMessage) => void; }; 'chat.unPinMessage': { - POST: (params: { messageId: IMessage['_id'] }) => void; + POST: (params: ChatUnpinMessage) => void; }; 'chat.reportMessage': { - POST: (params: { messageId: IMessage['_id']; description: string }) => void; + POST: (params: ChatReportMessage) => void; }; 'chat.getDiscussions': { - GET: (params: { roomId: IRoom['_id']; text?: string; offset: number; count: number }) => { + GET: (params: ChatGetDiscussions) => { messages: IMessage[]; total: number; }; }; 'chat.getThreadsList': { - GET: (params: { rid: IRoom['_id']; type: 'unread' | 'following' | 'all'; text?: string; offset: number; count: number }) => { + GET: (params: ChatGetThreadsList) => { threads: IMessage[]; total: number; }; }; 'chat.syncThreadsList': { - GET: (params: { rid: IRoom['_id']; updatedSince: string }) => { + GET: (params: ChatSyncThreadsList) => { threads: { update: IMessage[]; remove: IMessage[]; @@ -48,29 +432,29 @@ export type ChatEndpoints = { }; }; 'chat.delete': { - POST: (params: { msgId: string; roomId: string }) => { + POST: (params: ChatDelete) => { _id: string; ts: string; message: Pick; }; }; 'chat.react': { - POST: (params: { emoji: string; messageId: string } | { reaction: string; messageId: string }) => void; + POST: (params: ChatReact) => void; }; 'chat.ignoreUser': { - GET: (params: { rid: string; userId: string; ignore: boolean }) => {}; + GET: (params: ChatIgnoreUser) => {}; }; 'chat.search': { - GET: (params: { roomId: IRoom['_id']; searchText: string; count: number; offset: number }) => { + GET: (params: ChatSearch) => { messages: IMessage[]; }; }; 'chat.update': { - POST: (params: { roomId: IRoom['_id']; msgId: string; text: string }) => { + POST: (params: ChatUpdate) => { messages: IMessage; }; }; 'chat.getMessageReadReceipts': { - GET: (params: { messageId: string }) => { receipts: ReadReceipt[] }; + GET: (params: ChatGetMessageReadReceipts) => { receipts: ReadReceipt[] }; }; }; From 3019f4041a7df6dad471ac520aea68731c3a251f Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 25 May 2022 08:08:41 -0300 Subject: [PATCH 03/18] add cloud.ts and directory.ts json schemas --- packages/rest-typings/src/v1/cloud.ts | 69 ++++++++++++++++++++++- packages/rest-typings/src/v1/directory.ts | 39 +++++++++++-- 2 files changed, 99 insertions(+), 9 deletions(-) diff --git a/packages/rest-typings/src/v1/cloud.ts b/packages/rest-typings/src/v1/cloud.ts index c5f56e26f097..e0539f77253c 100644 --- a/packages/rest-typings/src/v1/cloud.ts +++ b/packages/rest-typings/src/v1/cloud.ts @@ -1,16 +1,79 @@ import type { CloudRegistrationIntentData, CloudConfirmationPollData, CloudRegistrationStatus } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; + +const ajv = new Ajv(); + +type CloudManualRegister = { + cloudBlob: string; +}; + +const CloudManualRegisterSchema: JSONSchemaType = { + type: 'object', + properties: { + cloudBlob: { + type: 'string', + }, + }, + required: ['cloudBlob'], + additionalProperties: false, +}; + +export const isCloudManualRegisterProps = ajv.compile(CloudManualRegisterSchema); + +type CloudCreateRegistrationIntent = { + resend: boolean; + email: string; +}; + +const CloudCreateRegistrationIntentSchema: JSONSchemaType = { + type: 'object', + properties: { + resend: { + type: 'boolean', + }, + email: { + type: 'string', + }, + }, + required: ['resend', 'email'], + additionalProperties: false, +}; + +export const isCloudCreateRegistrationIntentProps = ajv.compile(CloudCreateRegistrationIntentSchema); + +type CloudConfirmationPoll = { + deviceCode: string; + resend?: string; +}; + +const CloudConfirmationPollSchema: JSONSchemaType = { + type: 'object', + properties: { + deviceCode: { + type: 'string', + }, + resend: { + type: 'string', + nullable: true, + }, + }, + required: ['deviceCode'], + additionalProperties: false, +}; + +export const isCloudConfirmationPollProps = ajv.compile(CloudConfirmationPollSchema); export type CloudEndpoints = { 'cloud.manualRegister': { - POST: (params: { cloudBlob: string }) => void; + POST: (params: CloudManualRegister) => void; }; 'cloud.createRegistrationIntent': { - POST: (params: { resend: boolean; email: string }) => { + POST: (params: CloudCreateRegistrationIntent) => { intentData: CloudRegistrationIntentData; }; }; 'cloud.confirmationPoll': { - GET: (params: { deviceCode: string; resend?: boolean }) => { + GET: (params: CloudConfirmationPoll) => { pollData: CloudConfirmationPollData; }; }; diff --git a/packages/rest-typings/src/v1/directory.ts b/packages/rest-typings/src/v1/directory.ts index fda67ddf9810..1fd1c20b55eb 100644 --- a/packages/rest-typings/src/v1/directory.ts +++ b/packages/rest-typings/src/v1/directory.ts @@ -1,14 +1,41 @@ import type { IRoom } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv(); + +type DirectoryProps = { + query: { [key: string]: string }; + count: number; + offset: number; + sort: { [key: string]: number }; +}; + +const DirectorySchema: JSONSchemaType = { + type: 'object', + properties: { + query: { + type: 'object', + }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'object', + }, + }, + required: ['query', 'count', 'offset', 'sort'], + additionalProperties: false, +}; + +export const isDirectoryProps = ajv.compile(DirectorySchema); + export type DirectoryEndpoint = { directory: { - GET: (params: { - query: { [key: string]: string }; - count: number; - offset: number; - sort: { [key: string]: number }; - }) => PaginatedResult<{ result: IRoom[] }>; + GET: (params: DirectoryProps) => PaginatedResult<{ result: IRoom[] }>; }; }; From ec2000ab042f4d4b0eff1d8b6ee201396e9b500d Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 25 May 2022 09:26:34 -0300 Subject: [PATCH 04/18] add more schemas --- packages/rest-typings/src/v1/chat.ts | 2 +- packages/rest-typings/src/v1/directory.ts | 10 +- packages/rest-typings/src/v1/dm.ts | 48 ++- packages/rest-typings/src/v1/dns.ts | 42 ++- packages/rest-typings/src/v1/emojiCustom.ts | 41 ++- packages/rest-typings/src/v1/groups.ts | 338 ++++++++++++++++++-- 6 files changed, 438 insertions(+), 43 deletions(-) diff --git a/packages/rest-typings/src/v1/chat.ts b/packages/rest-typings/src/v1/chat.ts index 11fc907f6b3b..c3b2448a2d34 100644 --- a/packages/rest-typings/src/v1/chat.ts +++ b/packages/rest-typings/src/v1/chat.ts @@ -251,7 +251,7 @@ export const isChatDeleteProps = ajv.compile(ChatDeleteSchema); type ChatReact = { emoji: string; messageId: IMessage['_id'] } | { reaction: string; messageId: IMessage['_id'] }; -const ChatReactSchema = { +const ChatReactSchema: JSONSchemaType = { oneOf: [ { type: 'object', diff --git a/packages/rest-typings/src/v1/directory.ts b/packages/rest-typings/src/v1/directory.ts index 1fd1c20b55eb..6902fd70a968 100644 --- a/packages/rest-typings/src/v1/directory.ts +++ b/packages/rest-typings/src/v1/directory.ts @@ -6,10 +6,10 @@ import type { PaginatedResult } from '../helpers/PaginatedResult'; const ajv = new Ajv(); type DirectoryProps = { - query: { [key: string]: string }; + query: {}; // { [key: string]: number } count: number; offset: number; - sort: { [key: string]: number }; + sort: {}; // { [key: string]: number } }; const DirectorySchema: JSONSchemaType = { @@ -17,6 +17,9 @@ const DirectorySchema: JSONSchemaType = { properties: { query: { type: 'object', + properties: { + type: 'number', + }, }, count: { type: 'number', @@ -26,6 +29,9 @@ const DirectorySchema: JSONSchemaType = { }, sort: { type: 'object', + properties: { + type: 'number', + }, }, }, required: ['query', 'count', 'offset', 'sort'], diff --git a/packages/rest-typings/src/v1/dm.ts b/packages/rest-typings/src/v1/dm.ts index 44f796bbd594..07aa1ae5eed5 100644 --- a/packages/rest-typings/src/v1/dm.ts +++ b/packages/rest-typings/src/v1/dm.ts @@ -1,16 +1,48 @@ import type { IRoom, IUser } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; + +const ajv = new Ajv(); + +type DmCreateProps = + | { + username: Exclude; + } + | { + usernames: string[]; + }; + +const DmCreatePropsSchema: JSONSchemaType = { + oneOf: [ + { + type: 'object', + properties: { + username: { + type: 'string', + }, + }, + required: ['username'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + usernames: { + type: 'array', + items: { type: 'string' }, + }, + }, + required: ['usernames'], + additionalProperties: false, + }, + ], +}; + +export const isDmCreateProps = ajv.compile(DmCreatePropsSchema); export type DmEndpoints = { 'dm.create': { POST: ( - params: ( - | { - username: Exclude; - } - | { - usernames: string; - } - ) & { + params: DmCreateProps & { excludeSelf?: boolean; }, ) => { diff --git a/packages/rest-typings/src/v1/dns.ts b/packages/rest-typings/src/v1/dns.ts index b2d553e036f2..8c9c768227c4 100644 --- a/packages/rest-typings/src/v1/dns.ts +++ b/packages/rest-typings/src/v1/dns.ts @@ -1,11 +1,49 @@ +import Ajv, { JSONSchemaType } from 'ajv'; + +const ajv = new Ajv(); + +type DnsResolveTxtProps = { + url: string; +}; + +const dnsResolveTxtPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + url: { + type: 'string', + }, + }, + required: ['url'], + additionalProperties: false, +}; + +export const isDnsResolveTxtProps = ajv.compile(dnsResolveTxtPropsSchema); + +type DnsResolveSrvProps = { + url: string; +}; + +const DnsResolveSrvSchema: JSONSchemaType = { + type: 'object', + properties: { + url: { + type: 'string', + }, + }, + required: ['url'], + additionalProperties: false, +}; + +export const isDnsResolveSrvProps = ajv.compile(DnsResolveSrvSchema); + export type DnsEndpoints = { 'dns.resolve.srv': { - GET: (params: { url: string }) => { + GET: (params: DnsResolveSrvProps) => { resolved: Record; }; }; 'dns.resolve.txt': { - POST: (params: { url: string }) => { + POST: (params: DnsResolveTxtProps) => { resolved: string; // resolved: Record; }; diff --git a/packages/rest-typings/src/v1/emojiCustom.ts b/packages/rest-typings/src/v1/emojiCustom.ts index 0a52dddc940e..126097595d4c 100644 --- a/packages/rest-typings/src/v1/emojiCustom.ts +++ b/packages/rest-typings/src/v1/emojiCustom.ts @@ -1,8 +1,45 @@ import type { ICustomEmojiDescriptor } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv(); + +type emojiCustomDeleteProps = { + emojiId: ICustomEmojiDescriptor['_id']; +}; + +const emojiCustomDeletePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + emojiId: { + type: 'string', + }, + }, + required: ['emojiId'], + additionalProperties: false, +}; + +export const isEmojiCustomDelete = ajv.compile(emojiCustomDeletePropsSchema); + +type emojiCustomList = { + query: string; +}; + +const emojiCustomListSchema: JSONSchemaType = { + type: 'object', + properties: { + query: { + type: 'string', + }, + }, + required: ['query'], + additionalProperties: false, +}; + +export const isemojiCustomList = ajv.compile(emojiCustomListSchema); + export type EmojiCustomEndpoints = { 'emoji-custom.all': { GET: (params: PaginatedRequest<{ query: string }, 'name'>) => { @@ -10,13 +47,13 @@ export type EmojiCustomEndpoints = { } & PaginatedResult; }; 'emoji-custom.list': { - GET: (params: { query: string }) => { + GET: (params: emojiCustomList) => { emojis?: { update: ICustomEmojiDescriptor[]; }; }; }; 'emoji-custom.delete': { - POST: (params: { emojiId: ICustomEmojiDescriptor['_id'] }) => void; + POST: (params: emojiCustomDeleteProps) => void; }; }; diff --git a/packages/rest-typings/src/v1/groups.ts b/packages/rest-typings/src/v1/groups.ts index 3f5229a16534..f46ac175f393 100644 --- a/packages/rest-typings/src/v1/groups.ts +++ b/packages/rest-typings/src/v1/groups.ts @@ -1,17 +1,313 @@ import type { IMessage, IRoom, ITeam, IGetRoomRoles, IUser } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv(); + +type GroupsFilesProps = { + roomId: IRoom['_id']; + count: number; + sort: string; + query: string; +}; + +const GroupsFilesPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + count: { + type: 'number', + }, + sort: { + type: 'string', + }, + query: { + type: 'string', + }, + }, + required: ['roomId', 'count', 'sort', 'query'], + additionalProperties: false, +}; + +export const isGroupsFilesProps = ajv.compile(GroupsFilesPropsSchema); + +type GroupsMembersProps = { + roomId: IRoom['_id']; + offset?: number; + count?: number; + filter?: string; + status?: string[]; +}; + +const GroupsMembersPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + offset: { + type: 'number', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + filter: { + type: 'string', + nullable: true, + }, + status: { + type: 'array', + items: { type: 'string' }, + nullable: true, + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsMembersProps = ajv.compile(GroupsMembersPropsSchema); + +type GroupsArchiveProps = { + roomId: IRoom['_id']; +}; + +const GroupsArchivePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsArchiveProps = ajv.compile(GroupsArchivePropsSchema); + +type GroupsUnarchiveProps = { + roomId: IRoom['_id']; +}; + +const GroupsUnarchivePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsUnarchiveProps = ajv.compile(GroupsUnarchivePropsSchema); + +type GroupsCreateProps = { + name: string; + members: string[]; + readOnly: boolean; + extraData: { + broadcast: boolean; + encrypted: boolean; + teamId?: string; + }; +}; + +const GroupsCreatePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + name: { + type: 'string', + }, + members: { + type: 'array', + items: { type: 'string' }, + }, + readOnly: { + type: 'boolean', + }, + extraData: { + type: 'object', + properties: { + broadcast: { + type: 'boolean', + }, + encrypted: { + type: 'boolean', + }, + teamId: { + type: 'string', + nullable: true, + }, + }, + required: ['broadcast', 'encrypted'], + additionalProperties: false, + }, + }, + required: ['name', 'members', 'readOnly', 'extraData'], + additionalProperties: false, +}; + +export const isGroupsCreateProps = ajv.compile(GroupsCreatePropsSchema); + +type GroupsConvertToTeamProps = { + roomId: string; + roomName: string; +}; + +const GroupsConvertToTeamPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + roomName: { + type: 'string', + }, + }, + required: ['roomId', 'roomName'], + additionalProperties: false, +}; + +export const isGroupsConvertToTeamProps = ajv.compile(GroupsConvertToTeamPropsSchema); + +type GroupsCountersProps = { + roomId: string; +}; + +const GroupsCountersPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsCountersProps = ajv.compile(GroupsCountersPropsSchema); + +type GroupsCloseProps = { + roomId: string; +}; + +const GroupsClosePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsCloseProps = ajv.compile(GroupsClosePropsSchema); + +type GroupsDeleteProps = { + roomId: string; +}; + +const GroupsDeletePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsDeleteProps = ajv.compile(GroupsDeletePropsSchema); + +type GroupsLeaveProps = { + roomId: string; +}; + +const GroupsLeavePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsLeaveProps = ajv.compile(GroupsLeavePropsSchema); + +type GroupsRolesProps = { + roomId: string; +}; + +const GroupsRolesPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsRolesProps = ajv.compile(GroupsRolesPropsSchema); + +type GroupsKickProps = { + roomId: string; + userId: string; +}; + +const GroupsKickPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + userId: { + type: 'string', + }, + }, + required: ['roomId', 'userId'], + additionalProperties: false, +}; + +export const isGroupsKickProps = ajv.compile(GroupsKickPropsSchema); + +type GroupsMessageProps = { + roomId: IRoom['_id']; +}; + +const GroupsMessagePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isGroupsMessageProps = ajv.compile(GroupsMessagePropsSchema); + export type GroupsEndpoints = { 'groups.files': { - GET: (params: { roomId: IRoom['_id']; count: number; sort: string; query: string }) => { + GET: (params: GroupsFilesProps) => { files: IMessage[]; total: number; }; }; 'groups.members': { - GET: (params: { roomId: IRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => { + GET: (params: GroupsMembersProps) => { count: number; offset: number; members: IUser[]; @@ -24,30 +320,21 @@ export type GroupsEndpoints = { }>; }; 'groups.archive': { - POST: (params: { roomId: string }) => void; + POST: (params: GroupsArchiveProps) => void; }; 'groups.unarchive': { - POST: (params: { roomId: string }) => void; + POST: (params: GroupsUnarchiveProps) => void; }; 'groups.create': { - POST: (params: { - name: string; - members: string[]; - readOnly: boolean; - extraData: { - broadcast: boolean; - encrypted: boolean; - teamId?: string; - }; - }) => { + POST: (params: GroupsCreateProps) => { group: Partial; }; }; 'groups.convertToTeam': { - POST: (params: { roomId: string; roomName: string }) => { team: ITeam }; + POST: (params: GroupsConvertToTeamProps) => { team: ITeam }; }; 'groups.counters': { - GET: (params: { roomId: string }) => { + GET: (params: GroupsCountersProps) => { joined: boolean; members: number; unreads: number; @@ -58,28 +345,23 @@ export type GroupsEndpoints = { }; }; 'groups.close': { - POST: (params: { roomId: string }) => {}; + POST: (params: GroupsCloseProps) => {}; }; 'groups.kick': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: GroupsKickProps) => {}; }; 'groups.delete': { - POST: (params: { roomId: string }) => {}; + POST: (params: GroupsDeleteProps) => {}; }; 'groups.leave': { - POST: (params: { roomId: string }) => {}; + POST: (params: GroupsLeaveProps) => {}; }; 'groups.roles': { - GET: (params: { roomId: string }) => { roles: IGetRoomRoles[] }; + GET: (params: GroupsRolesProps) => { roles: IGetRoomRoles[] }; }; 'groups.messages': { - GET: (params: { - roomId: IRoom['_id']; - query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean }; - offset: number; - sort: { ts: number }; - }) => { + GET: (params: PaginatedRequest) => PaginatedResult<{ messages: IMessage[]; - }; + }>; }; }; From bb6c62d006b91fa1e634111c5b451098cae4cecb Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 25 May 2022 09:50:49 -0300 Subject: [PATCH 05/18] add invites, ldap, licenses.ts json schemas --- packages/rest-typings/src/v1/im.ts | 206 ++++++++++++++-- packages/rest-typings/src/v1/invites.ts | 41 +++- packages/rest-typings/src/v1/ldap.ts | 23 +- packages/rest-typings/src/v1/licenses.ts | 22 +- packages/rest-typings/src/v1/omnichannel.ts | 254 +++++++++++++++++++- 5 files changed, 516 insertions(+), 30 deletions(-) diff --git a/packages/rest-typings/src/v1/im.ts b/packages/rest-typings/src/v1/im.ts index 3d7937ab6b96..59de05dc8edf 100644 --- a/packages/rest-typings/src/v1/im.ts +++ b/packages/rest-typings/src/v1/im.ts @@ -1,6 +1,189 @@ import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; +import type { PaginatedResult } from '../helpers/PaginatedResult'; + +const ajv = new Ajv(); + +// Should it be made with PaginatedRequest<> to remove count, sort and query? +type ImFilesProps = { + roomId: IRoom['_id']; + count: number; + sort: string; + query: string; +}; + +const ImFilesPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + count: { + type: 'number', + }, + sort: { + type: 'string', + }, + query: { + type: 'string', + }, + }, + required: ['roomId', 'count', 'sort', 'query'], + additionalProperties: false, +}; + +export const isImFilesProps = ajv.compile(ImFilesPropsSchema); + +type ImMembersProps = { + roomId: IRoom['_id']; + offset?: number; + count?: number; + filter?: string; + status?: string[]; +}; + +const ImMembersPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + offset: { + type: 'number', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + filter: { + type: 'string', + nullable: true, + }, + status: { + type: 'array', + items: { type: 'string' }, + nullable: true, + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isImMembersProps = ajv.compile(ImMembersPropsSchema); + +type ImHistoryProps = { + roomId: string; + latest?: string; +}; + +const ImHistoryPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + latest: { + type: 'string', + nullable: true, + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isImHistoryProps = ajv.compile(ImHistoryPropsSchema); + +type ImCloseProps = { + roomId: string; +}; + +const ImClosePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isImCloseProps = ajv.compile(ImClosePropsSchema); + +type ImDeleteProps = { + roomId: string; +}; + +const ImDeletePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isImDeleteProps = ajv.compile(ImDeletePropsSchema); + +type ImLeaveProps = { + roomId: string; +}; + +const ImLeavePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isImLeaveProps = ajv.compile(ImLeavePropsSchema); + +type ImKickProps = { + roomId: string; + userId: string; +}; + +const ImKickPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + userId: { + type: 'string', + }, + }, + required: ['roomId', 'userId'], + additionalProperties: false, +}; + +export const isImKickProps = ajv.compile(ImKickPropsSchema); + +type ImMessagesProps = { + roomId: string; +}; + +const ImMessagesPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isImMessagesProps = ajv.compile(ImMessagesPropsSchema); export type ImEndpoints = { 'im.create': { @@ -20,13 +203,13 @@ export type ImEndpoints = { }; }; 'im.files': { - GET: (params: { roomId: IRoom['_id']; count: number; sort: string; query: string }) => { + GET: (params: ImFilesProps) => { files: IMessage[]; total: number; }; }; 'im.members': { - GET: (params: { roomId: IRoom['_id']; offset?: number; count?: number; filter?: string; status?: string[] }) => { + GET: (params: ImMembersProps) => { count: number; offset: number; members: IUser[]; @@ -34,30 +217,25 @@ export type ImEndpoints = { }; }; 'im.history': { - GET: (params: PaginatedRequest<{ roomId: string; latest?: string }>) => PaginatedRequest<{ + GET: (params: PaginatedRequest) => PaginatedRequest<{ messages: IMessage[]; }>; }; 'im.close': { - POST: (params: { roomId: string }) => {}; + POST: (params: ImCloseProps) => {}; }; 'im.kick': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: ImKickProps) => {}; }; 'im.delete': { - POST: (params: { roomId: string }) => {}; + POST: (params: ImDeleteProps) => {}; }; 'im.leave': { - POST: (params: { roomId: string }) => {}; + POST: (params: ImLeaveProps) => {}; }; 'im.messages': { - GET: (params: { - roomId: IRoom['_id']; - query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean }; - offset: number; - sort: { ts: number }; - }) => { + GET: (params: PaginatedRequest) => PaginatedResult<{ messages: IMessage[]; - }; + }>; }; }; diff --git a/packages/rest-typings/src/v1/invites.ts b/packages/rest-typings/src/v1/invites.ts index 200302c99711..da67399c0d22 100644 --- a/packages/rest-typings/src/v1/invites.ts +++ b/packages/rest-typings/src/v1/invites.ts @@ -1,4 +1,41 @@ import type { IInvite, IRoom } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; + +const ajv = new Ajv(); + +type v1UseInviteTokenProps = { + token: string; +}; + +const v1UseInviteTokenPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + token: { + type: 'string', + }, + }, + required: ['token'], + additionalProperties: false, +}; + +export const isV1UseInviteTokenProps = ajv.compile(v1UseInviteTokenPropsSchema); + +type v1ValidateInviteTokenProps = { + token: string; +}; + +const v1ValidateInviteTokenPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + token: { + type: 'string', + }, + }, + required: ['token'], + additionalProperties: false, +}; + +export const isV1ValidateInviteTokenProps = ajv.compile(v1ValidateInviteTokenPropsSchema); export type InvitesEndpoints = { 'listInvites': { @@ -8,7 +45,7 @@ export type InvitesEndpoints = { DELETE: () => void; }; '/v1/useInviteToken': { - POST: (params: { token: string }) => { + POST: (params: v1UseInviteTokenProps) => { room: { rid: IRoom['_id']; prid: IRoom['prid']; @@ -19,6 +56,6 @@ export type InvitesEndpoints = { }; }; '/v1/validateInviteToken': { - POST: (params: { token: string }) => { valid: boolean }; + POST: (params: v1ValidateInviteTokenProps) => { valid: boolean }; }; }; diff --git a/packages/rest-typings/src/v1/ldap.ts b/packages/rest-typings/src/v1/ldap.ts index 45c482c0957d..91926f032709 100644 --- a/packages/rest-typings/src/v1/ldap.ts +++ b/packages/rest-typings/src/v1/ldap.ts @@ -1,3 +1,24 @@ +import Ajv, { JSONSchemaType } from 'ajv'; + +const ajv = new Ajv(); + +type ldapTestSearchProps = { + username: string; +}; + +const ldapTestSearchPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + username: { + type: 'string', + }, + }, + required: ['username'], + additionalProperties: false, +}; + +export const isLdapTestSearch = ajv.compile(ldapTestSearchPropsSchema); + export type LDAPEndpoints = { 'ldap.testConnection': { POST: () => { @@ -5,7 +26,7 @@ export type LDAPEndpoints = { }; }; 'ldap.testSearch': { - POST: (params: { username: string }) => { + POST: (params: ldapTestSearchProps) => { message: string; }; }; diff --git a/packages/rest-typings/src/v1/licenses.ts b/packages/rest-typings/src/v1/licenses.ts index f1bb124a956b..93595aa9f6fe 100644 --- a/packages/rest-typings/src/v1/licenses.ts +++ b/packages/rest-typings/src/v1/licenses.ts @@ -1,11 +1,31 @@ import type { ILicense } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; + +const ajv = new Ajv(); + +type licensesAddProps = { + license: string; +}; + +const licensesAddPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + license: { + type: 'string', + }, + }, + required: ['license'], + additionalProperties: false, +}; + +export const isLicensesAddProps = ajv.compile(licensesAddPropsSchema); export type LicensesEndpoints = { 'licenses.get': { GET: () => { licenses: Array }; }; 'licenses.add': { - POST: (params: { license: string }) => void; + POST: (params: licensesAddProps) => void; }; 'licenses.maxActiveUsers': { GET: () => { maxActiveUsers: number | null; activeUsers: number }; diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index 95e97d5118c6..683e61b3c604 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -13,12 +13,227 @@ import type { IRoom, ISetting, } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; type booleanString = 'true' | 'false'; +const ajv = new Ajv(); + +type LivechatVisitorsInfo = { + visitorId: string; +}; + +const LivechatVisitorsInfoSchema: JSONSchemaType = { + type: 'object', + properties: { + visitorId: { + type: 'string', + }, + }, + required: ['visitorId'], + additionalProperties: false, +}; + +export const isLivechatVisitorsInfoProps = ajv.compile(LivechatVisitorsInfoSchema); + +type LivechatRoomOnHold = { + roomId: IRoom['_id']; +}; + +const LivechatRoomOnHoldSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isLivechatRoomOnHoldProps = ajv.compile(LivechatRoomOnHoldSchema); + +type LivechatDepartmentId = { + onlyMyDepartments?: booleanString; + includeAgents?: booleanString; +}; + +const LivechatDepartmentIdSchema: JSONSchemaType = { + type: 'object', + properties: { + onlyMyDepartments: { + type: 'string', + nullable: true, + }, + includeAgents: { + type: 'string', + nullable: true, + }, + }, + additionalProperties: false, +}; + +export const isLivechatDepartmentIdProps = ajv.compile(LivechatDepartmentIdSchema); + +type LivechatDepartmentAutocomplete = { + selector: string; + onlyMyDepartments: booleanString; +}; + +const LivechatDepartmentAutocompleteSchema: JSONSchemaType = { + type: 'object', + properties: { + selector: { + type: 'string', + }, + onlyMyDepartments: { + type: 'string', + }, + }, + required: ['selector', 'onlyMyDepartments'], + additionalProperties: false, +}; + +export const isLivechatDepartmentAutocompleteProps = ajv.compile(LivechatDepartmentAutocompleteSchema); + +type livechatDepartmentDepartmentIdAgentsGET = { + sort: string; +}; + +const livechatDepartmentDepartmentIdAgentsGETSchema: JSONSchemaType = { + type: 'object', + properties: { + sort: { + type: 'string', + }, + }, + required: ['sort'], + additionalProperties: false, +}; + +export const islivechatDepartmentDepartmentIdAgentsGETProps = ajv.compile(livechatDepartmentDepartmentIdAgentsGETSchema); + +type LivechatVisitorTokenGet = { + token: string; +}; + +const LivechatVisitorTokenGetSchema: JSONSchemaType = { + type: 'object', + properties: { + token: { + type: 'string', + }, + }, + required: ['token'], + additionalProperties: false, +}; + +export const isLivechatVisitorTokenGetProps = ajv.compile(LivechatVisitorTokenGetSchema); + +type LivechatVisitorTokenDelete = { + token: string; +}; + +const LivechatVisitorTokenDeleteSchema: JSONSchemaType = { + type: 'object', + properties: { + token: { + type: 'string', + }, + }, + required: ['token'], + additionalProperties: false, +}; + +export const isLivechatVisitorTokenDeleteProps = ajv.compile(LivechatVisitorTokenDeleteSchema); + +type LivechatVisitorTokenRoom = { + token: string; +}; + +const LivechatVisitorTokenRoomSchema: JSONSchemaType = { + type: 'object', + properties: { + token: { + type: 'string', + }, + }, + required: ['token'], + additionalProperties: false, +}; + +export const isLivechatVisitorTokenRoomProps = ajv.compile(LivechatVisitorTokenRoomSchema); + +type LivechatVisitorCallStatus = { + token: string; + callStatus: string; + rid: string; + callId: string; +}; + +const LivechatVisitorCallStatusSchema: JSONSchemaType = { + type: 'object', + properties: { + token: { + type: 'string', + }, + callStatus: { + type: 'string', + }, + rid: { + type: 'string', + }, + callId: { + type: 'string', + }, + }, + required: ['token', 'callStatus', 'rid', 'callId'], + additionalProperties: false, +}; + +export const isLivechatVisitorCallStatusProps = ajv.compile(LivechatVisitorCallStatusSchema); + +type LivechatVisitorStatus = { + token: string; + status: string; +}; + +const LivechatVisitorStatusSchema: JSONSchemaType = { + type: 'object', + properties: { + token: { + type: 'string', + }, + status: { + type: 'string', + }, + }, + required: ['token', 'status'], + additionalProperties: false, +}; + +export const isLivechatVisitorStatusProps = ajv.compile(LivechatVisitorStatusSchema); + +type LiveChatRoomJoin = { + roomId: string; +}; + +const LiveChatRoomJoinSchema: JSONSchemaType = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isLiveChatRoomJoinProps = ajv.compile(LiveChatRoomJoinSchema); + export type OmnichannelEndpoints = { 'livechat/appearance': { GET: () => { @@ -26,7 +241,7 @@ export type OmnichannelEndpoints = { }; }; 'livechat/visitors.info': { - GET: (params: { visitorId: string }) => { + GET: (params: LivechatVisitorsInfo) => { visitor: { visitorEmails: Array<{ address: string; @@ -35,23 +250,26 @@ export type OmnichannelEndpoints = { }; }; 'livechat/room.onHold': { - POST: (params: { roomId: IRoom['_id'] }) => void; + POST: (params: LivechatRoomOnHold) => void; }; 'livechat/room.join': { - GET: (params: { roomId: IRoom['_id'] }) => { success: boolean }; + GET: (params: LiveChatRoomJoin) => { success: boolean }; }; 'livechat/monitors.list': { + // TO-DO GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ monitors: ILivechatMonitor[]; }>; }; 'livechat/tags.list': { + // TO-DO GET: (params: PaginatedRequest<{ text: string }, 'name'>) => PaginatedResult<{ tags: ILivechatTag[]; }>; }; 'livechat/department': { GET: ( + // TO-DO params: PaginatedRequest<{ text: string; onlyMyDepartments?: booleanString; @@ -67,7 +285,7 @@ export type OmnichannelEndpoints = { }; }; 'livechat/department/:_id': { - GET: (params: { onlyMyDepartments?: booleanString; includeAgents?: booleanString }) => { + GET: (params: LivechatDepartmentId) => { department: ILivechatDepartmentRecord | null; agents?: ILivechatDepartmentAgents[]; }; @@ -78,38 +296,43 @@ export type OmnichannelEndpoints = { DELETE: () => void; }; 'livechat/department.autocomplete': { - GET: (params: { selector: string; onlyMyDepartments: booleanString }) => { + GET: (params: LivechatDepartmentAutocomplete) => { items: ILivechatDepartment[]; }; }; 'livechat/department/:departmentId/agents': { - GET: (params: { sort: string }) => PaginatedResult<{ agents: ILivechatDepartmentAgents[] }>; - POST: (params: { upsert: string[]; remove: string[] }) => void; + GET: (params: livechatDepartmentDepartmentIdAgentsGET) => PaginatedResult<{ agents: ILivechatDepartmentAgents[] }>; + POST: (params: { upsert: string[]; remove: string[] }) => void; // TO-DO }; 'livechat/departments.available-by-unit/:id': { + // TO-DO GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ departments: ILivechatDepartment[]; }>; }; 'livechat/departments.by-unit/': { + // TO-DO GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ departments: ILivechatDepartment[]; }>; }; 'livechat/departments.by-unit/:id': { + // TO-DO GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ departments: ILivechatDepartment[]; }>; }; 'livechat/department.listByIds': { + // TO-DO GET: (params: { ids: string[]; fields?: Record }) => { departments: ILivechatDepartment[]; }; }; 'livechat/custom-fields': { + // TO-DO GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ customFields: [ { @@ -120,6 +343,7 @@ export type OmnichannelEndpoints = { }>; }; 'livechat/rooms': { + // TO-DO GET: (params: { guest: string; fname: string; @@ -137,11 +361,13 @@ export type OmnichannelEndpoints = { }>; }; 'livechat/:rid/messages': { + // TO-DO GET: (params: PaginatedRequest<{ query: string }>) => PaginatedResult<{ messages: IMessage[]; }>; }; 'livechat/users/agent': { + // TO-DO GET: (params: PaginatedRequest<{ text?: string }>) => PaginatedResult<{ users: { _id: string; @@ -165,6 +391,7 @@ export type OmnichannelEndpoints = { }; 'livechat/users/manager': { + // TO-DO GET: (params: PaginatedRequest<{ text?: string }>) => PaginatedResult<{ users: ILivechatAgent[]; }>; @@ -172,31 +399,32 @@ export type OmnichannelEndpoints = { }; 'livechat/visitor': { + // TO-DO POST: (params: { visitor: ILivechatVisitorDTO }) => { visitor: ILivechatVisitor; }; }; 'livechat/visitor/:token': { - GET: (params: { token: string }) => { visitor: ILivechatVisitor }; - DELETE: (params: { token: string }) => { + GET: (params: LivechatVisitorTokenGet) => { visitor: ILivechatVisitor }; + DELETE: (params: LivechatVisitorTokenDelete) => { visitor: { _id: string; ts: string }; }; }; 'livechat/visitor/:token/room': { - GET: (params: { token: string }) => { rooms: IOmnichannelRoom[] }; + GET: (params: LivechatVisitorTokenRoom) => { rooms: IOmnichannelRoom[] }; }; 'livechat/visitor.callStatus': { - POST: (params: { token: string; callStatus: string; rid: string; callId: string }) => { + POST: (params: LivechatVisitorCallStatus) => { token: string; callStatus: string; }; }; 'livechat/visitor.status': { - POST: (params: { token: string; status: string }) => { + POST: (params: LivechatVisitorStatus) => { token: string; status: string; }; @@ -204,6 +432,7 @@ export type OmnichannelEndpoints = { 'livechat/queue': { GET: (params: { + // TO-DO agentId?: ILivechatAgent['_id']; includeOfflineAgents?: boolean; departmentId?: ILivechatAgent['_id']; @@ -227,6 +456,7 @@ export type OmnichannelEndpoints = { 'canned-responses': { GET: ( + // TO-DO params: PaginatedRequest<{ scope?: string; departmentId?: string; From c187396f95689418074d5106ddcef9050bf167ce Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 25 May 2022 10:00:06 -0300 Subject: [PATCH 06/18] fix omnichannel.ts json schema (work in progress) --- packages/rest-typings/src/v1/omnichannel.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index 683e61b3c604..b49b3f8fd444 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -234,6 +234,23 @@ const LiveChatRoomJoinSchema: JSONSchemaType = { export const isLiveChatRoomJoinProps = ajv.compile(LiveChatRoomJoinSchema); +type LivechatMonitorsListProps = { + text: string; +}; + +const LivechatMonitorsListSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatMonitorsListProps = ajv.compile(LivechatMonitorsListSchema); + export type OmnichannelEndpoints = { 'livechat/appearance': { GET: () => { @@ -256,8 +273,7 @@ export type OmnichannelEndpoints = { GET: (params: LiveChatRoomJoin) => { success: boolean }; }; 'livechat/monitors.list': { - // TO-DO - GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ + GET: (params: PaginatedRequest) => PaginatedResult<{ monitors: ILivechatMonitor[]; }>; }; From 8f9379820807ac736df9df5315731be23763b781 Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 25 May 2022 11:23:44 -0300 Subject: [PATCH 07/18] fix more omnichannel.ts json schemas (work in progress) --- packages/rest-typings/src/v1/directory.ts | 27 +- packages/rest-typings/src/v1/omnichannel.ts | 458 +++++++++++++++++--- 2 files changed, 418 insertions(+), 67 deletions(-) diff --git a/packages/rest-typings/src/v1/directory.ts b/packages/rest-typings/src/v1/directory.ts index 6902fd70a968..e897fd318b89 100644 --- a/packages/rest-typings/src/v1/directory.ts +++ b/packages/rest-typings/src/v1/directory.ts @@ -1,40 +1,33 @@ import type { IRoom } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; +import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; const ajv = new Ajv(); -type DirectoryProps = { - query: {}; // { [key: string]: number } - count: number; - offset: number; - sort: {}; // { [key: string]: number } -}; +type DirectoryProps = PaginatedRequest<{}>; -const DirectorySchema: JSONSchemaType = { +const DirectorySchema = { type: 'object', properties: { query: { - type: 'object', - properties: { - type: 'number', - }, + type: 'string', + nullable: true, }, count: { type: 'number', + nullable: true, }, offset: { type: 'number', + nullable: true, }, sort: { - type: 'object', - properties: { - type: 'number', - }, + type: 'string', + nullable: true, }, }, - required: ['query', 'count', 'offset', 'sort'], additionalProperties: false, }; diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index b49b3f8fd444..d17110457c61 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -99,11 +99,11 @@ const LivechatDepartmentAutocompleteSchema: JSONSchemaType = { +const LivechatDepartmentDepartmentIdAgentsGETSchema: JSONSchemaType = { type: 'object', properties: { sort: { @@ -114,7 +114,34 @@ const livechatDepartmentDepartmentIdAgentsGETSchema: JSONSchemaType = { + type: 'object', + properties: { + upsert: { + type: 'array', + items: { + type: 'string', + }, + }, + remove: { + type: 'array', + items: { + type: 'string', + }, + }, + }, + required: ['upsert', 'remove'], + additionalProperties: false, +}; + +export const isLivechatDepartmentDepartmentIdAgentsPOSTProps = ajv.compile(LivechatDepartmentDepartmentIdAgentsPOSTSchema); type LivechatVisitorTokenGet = { token: string; @@ -234,9 +261,7 @@ const LiveChatRoomJoinSchema: JSONSchemaType = { export const isLiveChatRoomJoinProps = ajv.compile(LiveChatRoomJoinSchema); -type LivechatMonitorsListProps = { - text: string; -}; +type LivechatMonitorsListProps = PaginatedRequest<{ text: string }>; const LivechatMonitorsListSchema: JSONSchemaType = { type: 'object', @@ -244,6 +269,22 @@ const LivechatMonitorsListSchema: JSONSchemaType = { text: { type: 'string', }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, }, required: ['text'], additionalProperties: false, @@ -251,6 +292,354 @@ const LivechatMonitorsListSchema: JSONSchemaType = { export const isLivechatMonitorsListProps = ajv.compile(LivechatMonitorsListSchema); +type LivechatTagsListProps = PaginatedRequest<{ text: string }, 'name'>; + +const LivechatTagsListSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatTagsListProps = ajv.compile(LivechatTagsListSchema); + +type LivechatDepartmentProps = PaginatedRequest<{ + text: string; + onlyMyDepartments?: booleanString; + enabled?: booleanString; + excludeDepartmentId?: string; +}>; + +const LivechatDepartmentSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + onlyMyDepartments: { + type: 'string', + nullable: true, + }, + enabled: { + type: 'string', + nullable: true, + }, + excludeDepartmentId: { + type: 'string', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatDepartmentProps = ajv.compile(LivechatDepartmentSchema); + +type LivechatDepartmentsAvailableByUnitIdProps = PaginatedRequest<{ text: string }>; + +const LivechatDepartmentsAvailableByUnitIdSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatDepartmentsAvailableByUnitIdProps = ajv.compile(LivechatDepartmentsAvailableByUnitIdSchema); + +type LivechatDepartmentsByUnitProps = PaginatedRequest<{ text: string }>; + +const LivechatDepartmentsByUnitSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatDepartmentsByUnitProps = ajv.compile(LivechatDepartmentsByUnitSchema); + +type LivechatDepartmentsByUnitIdProps = PaginatedRequest<{ text: string }>; + +const LivechatDepartmentsByUnitIdSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatDepartmentsByUnitIdProps = ajv.compile(LivechatDepartmentsByUnitIdSchema); + +type LivechatUsersManagerGETProps = PaginatedRequest<{ text: string }>; + +const LivechatUsersManagerGETSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatUsersManagerGETProps = ajv.compile(LivechatUsersManagerGETSchema); + +type LivechatUsersManagerPOSTProps = PaginatedRequest<{ username: string }>; + +const LivechatUsersManagerPOSTSchema: JSONSchemaType = { + type: 'object', + properties: { + username: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['username'], + additionalProperties: false, +}; + +export const isLivechatUsersManagerPOSTProps = ajv.compile(LivechatUsersManagerPOSTSchema); + +type LivechatQueueProps = { + agentId?: string; + includeOfflineAgents?: booleanString; + departmentId?: string; + offset: number; + count: number; + sort: string; +}; + +const LivechatQueuePropsSchema: JSONSchemaType = { + type: 'object', + properties: { + agentId: { + type: 'string', + nullable: true, + }, + includeOfflineAgents: { + type: 'string', + nullable: true, + }, + departmentId: { + type: 'string', + nullable: true, + }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', + }, + }, + required: ['count', 'offset', 'sort'], + additionalProperties: false, +}; + +export const isLivechatQueueProps = ajv.compile(LivechatQueuePropsSchema); + +type CannedResponsesProps = PaginatedRequest<{ + scope?: string; + departmentId?: string; + text?: string; +}>; + +const CannedResponsesPropsSchema: JSONSchemaType = { + type: 'object', + properties: { + scope: { + type: 'string', + nullable: true, + }, + departmentId: { + type: 'string', + nullable: true, + }, + text: { + type: 'string', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + additionalProperties: false, +}; + +export const isCannedResponsesProps = ajv.compile(CannedResponsesPropsSchema); + +type LivechatCustomFieldsProps = PaginatedRequest<{ text: string }>; + +const LivechatCustomFieldsSchema: JSONSchemaType = { + type: 'object', + properties: { + text: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['text'], + additionalProperties: false, +}; + +export const isLivechatCustomFieldsProps = ajv.compile(LivechatCustomFieldsSchema); + export type OmnichannelEndpoints = { 'livechat/appearance': { GET: () => { @@ -273,26 +662,17 @@ export type OmnichannelEndpoints = { GET: (params: LiveChatRoomJoin) => { success: boolean }; }; 'livechat/monitors.list': { - GET: (params: PaginatedRequest) => PaginatedResult<{ + GET: (params: LivechatMonitorsListProps) => PaginatedResult<{ monitors: ILivechatMonitor[]; }>; }; 'livechat/tags.list': { - // TO-DO - GET: (params: PaginatedRequest<{ text: string }, 'name'>) => PaginatedResult<{ + GET: (params: LivechatTagsListProps) => PaginatedResult<{ tags: ILivechatTag[]; }>; }; 'livechat/department': { - GET: ( - // TO-DO - params: PaginatedRequest<{ - text: string; - onlyMyDepartments?: booleanString; - enabled?: boolean; - excludeDepartmentId?: string; - }>, - ) => PaginatedResult<{ + GET: (params: LivechatDepartmentProps) => PaginatedResult<{ departments: ILivechatDepartment[]; }>; POST: (params: { department: Partial; agents: string[] }) => { @@ -317,39 +697,34 @@ export type OmnichannelEndpoints = { }; }; 'livechat/department/:departmentId/agents': { - GET: (params: livechatDepartmentDepartmentIdAgentsGET) => PaginatedResult<{ agents: ILivechatDepartmentAgents[] }>; - POST: (params: { upsert: string[]; remove: string[] }) => void; // TO-DO + GET: (params: LivechatDepartmentDepartmentIdAgentsGET) => PaginatedResult<{ agents: ILivechatDepartmentAgents[] }>; + POST: (params: LivechatDepartmentDepartmentIdAgentsPOST) => void; }; 'livechat/departments.available-by-unit/:id': { - // TO-DO - GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ + GET: (params: LivechatDepartmentsAvailableByUnitIdProps) => PaginatedResult<{ departments: ILivechatDepartment[]; }>; }; 'livechat/departments.by-unit/': { - // TO-DO - GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ + GET: (params: LivechatDepartmentsByUnitProps) => PaginatedResult<{ departments: ILivechatDepartment[]; }>; }; 'livechat/departments.by-unit/:id': { - // TO-DO - GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ + GET: (params: LivechatDepartmentsByUnitIdProps) => PaginatedResult<{ departments: ILivechatDepartment[]; }>; }; 'livechat/department.listByIds': { - // TO-DO GET: (params: { ids: string[]; fields?: Record }) => { departments: ILivechatDepartment[]; }; }; 'livechat/custom-fields': { - // TO-DO - GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{ + GET: (params: LivechatCustomFieldsProps) => PaginatedResult<{ customFields: [ { _id: string; @@ -407,15 +782,13 @@ export type OmnichannelEndpoints = { }; 'livechat/users/manager': { - // TO-DO - GET: (params: PaginatedRequest<{ text?: string }>) => PaginatedResult<{ + GET: (params: LivechatUsersManagerGETProps) => PaginatedResult<{ users: ILivechatAgent[]; }>; - POST: (params: { username: string }) => { success: boolean }; + POST: (params: LivechatUsersManagerPOSTProps) => { success: boolean }; }; 'livechat/visitor': { - // TO-DO POST: (params: { visitor: ILivechatVisitorDTO }) => { visitor: ILivechatVisitor; }; @@ -447,15 +820,7 @@ export type OmnichannelEndpoints = { }; 'livechat/queue': { - GET: (params: { - // TO-DO - agentId?: ILivechatAgent['_id']; - includeOfflineAgents?: boolean; - departmentId?: ILivechatAgent['_id']; - offset: number; - count: number; - sort: string; - }) => { + GET: (params: LivechatQueueProps) => { queue: { chats: number; department: { _id: string; name: string }; @@ -471,14 +836,7 @@ export type OmnichannelEndpoints = { }; 'canned-responses': { - GET: ( - // TO-DO - params: PaginatedRequest<{ - scope?: string; - departmentId?: string; - text?: string; - }>, - ) => PaginatedResult<{ + GET: (params: CannedResponsesProps) => PaginatedResult<{ cannedResponses: IOmnichannelCannedResponse[]; }>; }; From b4d774500f14818be6e7691fecd53554f671612e Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Thu, 26 May 2022 22:48:08 -0300 Subject: [PATCH 08/18] chore: remove JSONSchemaType (work in progress) --- packages/rest-typings/src/v1/banners.ts | 10 +- packages/rest-typings/src/v1/chat.ts | 30 +-- packages/rest-typings/src/v1/cloud.ts | 8 +- packages/rest-typings/src/v1/customSounds.ts | 33 ++- .../rest-typings/src/v1/customUserStatus.ts | 32 ++- packages/rest-typings/src/v1/dm.ts | 4 +- packages/rest-typings/src/v1/dns.ts | 6 +- packages/rest-typings/src/v1/e2e.ts | 94 ++++++++- packages/rest-typings/src/v1/email-inbox.ts | 179 +++++++++++++--- packages/rest-typings/src/v1/emojiCustom.ts | 6 +- packages/rest-typings/src/v1/omnichannel.ts | 192 ++++++++++++++---- packages/rest-typings/src/v1/permissions.ts | 24 ++- 12 files changed, 510 insertions(+), 108 deletions(-) diff --git a/packages/rest-typings/src/v1/banners.ts b/packages/rest-typings/src/v1/banners.ts index 0715591e5241..40233404d408 100644 --- a/packages/rest-typings/src/v1/banners.ts +++ b/packages/rest-typings/src/v1/banners.ts @@ -1,4 +1,4 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; import type { BannerPlatform, IBanner } from '@rocket.chat/core-typings'; const ajv = new Ajv(); @@ -8,7 +8,7 @@ type BannersGetNew = { bid: IBanner['_id']; }; -const BannersGetNewSchema: JSONSchemaType = { +const BannersGetNewSchema = { type: 'object', properties: { platform: { @@ -28,7 +28,7 @@ type BannersId = { platform: BannerPlatform; }; -const BannersIdSchema: JSONSchemaType = { +const BannersIdSchema = { type: 'object', properties: { platform: { @@ -45,7 +45,7 @@ type Banners = { platform: BannerPlatform; }; -const BannersSchema: JSONSchemaType = { +const BannersSchema = { type: 'object', properties: { platform: { @@ -62,7 +62,7 @@ type BannersDismiss = { bannerId: string; }; -const BannersDismissSchema: JSONSchemaType = { +const BannersDismissSchema = { type: 'object', properties: { bannerId: { diff --git a/packages/rest-typings/src/v1/chat.ts b/packages/rest-typings/src/v1/chat.ts index c3b2448a2d34..5a7fcc398749 100644 --- a/packages/rest-typings/src/v1/chat.ts +++ b/packages/rest-typings/src/v1/chat.ts @@ -1,5 +1,5 @@ import type { IMessage, IRoom, ReadReceipt } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; const ajv = new Ajv(); @@ -7,7 +7,7 @@ type ChatFollowMessage = { mid: IMessage['_id']; }; -const chatFollowMessageSchema: JSONSchemaType = { +const chatFollowMessageSchema = { type: 'object', properties: { mid: { @@ -24,7 +24,7 @@ type ChatUnfollowMessage = { mid: IMessage['_id']; }; -const chatUnfollowMessageSchema: JSONSchemaType = { +const chatUnfollowMessageSchema = { type: 'object', properties: { mid: { @@ -41,7 +41,7 @@ type ChatGetMessage = { msgId: IMessage['_id']; }; -const ChatGetMessageSchema: JSONSchemaType = { +const ChatGetMessageSchema = { type: 'object', properties: { msgId: { @@ -58,7 +58,7 @@ type ChatStarMessage = { msgId: IMessage['_id']; }; -const ChatStarMessageSchema: JSONSchemaType = { +const ChatStarMessageSchema = { type: 'object', properties: { msgId: { @@ -75,7 +75,7 @@ type ChatUnstarMessage = { msgId: IMessage['_id']; }; -const ChatUnstarMessageSchema: JSONSchemaType = { +const ChatUnstarMessageSchema = { type: 'object', properties: { msgId: { @@ -92,7 +92,7 @@ type ChatPinMessage = { msgId: IMessage['_id']; }; -const ChatPinMessageSchema: JSONSchemaType = { +const ChatPinMessageSchema = { type: 'object', properties: { msgId: { @@ -109,7 +109,7 @@ type ChatUnpinMessage = { messageId: IMessage['_id']; }; -const ChatUnpinMessageSchema: JSONSchemaType = { +const ChatUnpinMessageSchema = { type: 'object', properties: { messageId: { @@ -129,7 +129,7 @@ type ChatGetDiscussions = { count: number; }; -const ChatGetDiscussionsSchema: JSONSchemaType = { +const ChatGetDiscussionsSchema = { type: 'object', properties: { roomId: { @@ -157,7 +157,7 @@ type ChatReportMessage = { description: string; }; -const ChatReportMessageSchema: JSONSchemaType = { +const ChatReportMessageSchema = { type: 'object', properties: { messageId: { @@ -181,7 +181,7 @@ type ChatGetThreadsList = { count: number; }; -const ChatGetThreadsListSchema: JSONSchemaType = { +const ChatGetThreadsListSchema = { type: 'object', properties: { rid: { @@ -212,7 +212,7 @@ type ChatSyncThreadsList = { updatedSince: string; }; -const ChatSyncThreadsListSchema: JSONSchemaType = { +const ChatSyncThreadsListSchema = { type: 'object', properties: { rid: { @@ -233,7 +233,7 @@ type ChatDelete = { roomId: IRoom['_id']; }; -const ChatDeleteSchema: JSONSchemaType = { +const ChatDeleteSchema = { type: 'object', properties: { msgId: { @@ -251,7 +251,7 @@ export const isChatDeleteProps = ajv.compile(ChatDeleteSchema); type ChatReact = { emoji: string; messageId: IMessage['_id'] } | { reaction: string; messageId: IMessage['_id'] }; -const ChatReactSchema: JSONSchemaType = { +const ChatReactSchema = { oneOf: [ { type: 'object', @@ -371,7 +371,7 @@ type ChatGetMessageReadReceipts = { messageId: IMessage['_id']; }; -const ChatGetMessageReadReceiptsSchema: JSONSchemaType = { +const ChatGetMessageReadReceiptsSchema = { type: 'object', properties: { messageId: { diff --git a/packages/rest-typings/src/v1/cloud.ts b/packages/rest-typings/src/v1/cloud.ts index e0539f77253c..9f0b8fc415f9 100644 --- a/packages/rest-typings/src/v1/cloud.ts +++ b/packages/rest-typings/src/v1/cloud.ts @@ -1,5 +1,5 @@ import type { CloudRegistrationIntentData, CloudConfirmationPollData, CloudRegistrationStatus } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; const ajv = new Ajv(); @@ -7,7 +7,7 @@ type CloudManualRegister = { cloudBlob: string; }; -const CloudManualRegisterSchema: JSONSchemaType = { +const CloudManualRegisterSchema = { type: 'object', properties: { cloudBlob: { @@ -25,7 +25,7 @@ type CloudCreateRegistrationIntent = { email: string; }; -const CloudCreateRegistrationIntentSchema: JSONSchemaType = { +const CloudCreateRegistrationIntentSchema = { type: 'object', properties: { resend: { @@ -46,7 +46,7 @@ type CloudConfirmationPoll = { resend?: string; }; -const CloudConfirmationPollSchema: JSONSchemaType = { +const CloudConfirmationPollSchema = { type: 'object', properties: { deviceCode: { diff --git a/packages/rest-typings/src/v1/customSounds.ts b/packages/rest-typings/src/v1/customSounds.ts index 4a8f75a68089..8b33503d37ed 100644 --- a/packages/rest-typings/src/v1/customSounds.ts +++ b/packages/rest-typings/src/v1/customSounds.ts @@ -1,9 +1,40 @@ +import Ajv from 'ajv'; + import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv(); + +type CustomSoundsList = PaginatedRequest<{ query: string }>; + +const CustomSoundsListSchema = { + type: 'object', + properties: { + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + }, + }, + required: ['query'], + additionalProperties: false, +}; + +export const isCustomSoundsListProps = ajv.compile(CustomSoundsListSchema); + export type CustomSoundEndpoint = { 'custom-sounds.list': { - GET: (params: PaginatedRequest<{ query: string }>) => PaginatedResult<{ + GET: (params: CustomSoundsList) => PaginatedResult<{ sounds: { _id: string; name: string; diff --git a/packages/rest-typings/src/v1/customUserStatus.ts b/packages/rest-typings/src/v1/customUserStatus.ts index 9f9f8350180f..f410a64a165e 100644 --- a/packages/rest-typings/src/v1/customUserStatus.ts +++ b/packages/rest-typings/src/v1/customUserStatus.ts @@ -1,11 +1,41 @@ import type { IUserStatus } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv(); + +type CustomUserStatusListProps = PaginatedRequest<{ query: string }>; + +const CustomUserStatusListSchema = { + type: 'object', + properties: { + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + }, + }, + required: ['query'], + additionalProperties: false, +}; + +export const isCustomUserStatusListProps = ajv.compile(CustomUserStatusListSchema); + export type CustomUserStatusEndpoints = { 'custom-user-status.list': { - GET: (params: PaginatedRequest<{ query: string }>) => PaginatedResult<{ + GET: (params: CustomUserStatusListProps) => PaginatedResult<{ statuses: IUserStatus[]; }>; }; diff --git a/packages/rest-typings/src/v1/dm.ts b/packages/rest-typings/src/v1/dm.ts index 07aa1ae5eed5..3d6a91e8ba30 100644 --- a/packages/rest-typings/src/v1/dm.ts +++ b/packages/rest-typings/src/v1/dm.ts @@ -1,5 +1,5 @@ import type { IRoom, IUser } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; const ajv = new Ajv(); @@ -11,7 +11,7 @@ type DmCreateProps = usernames: string[]; }; -const DmCreatePropsSchema: JSONSchemaType = { +const DmCreatePropsSchema = { oneOf: [ { type: 'object', diff --git a/packages/rest-typings/src/v1/dns.ts b/packages/rest-typings/src/v1/dns.ts index 8c9c768227c4..7b263f153f8b 100644 --- a/packages/rest-typings/src/v1/dns.ts +++ b/packages/rest-typings/src/v1/dns.ts @@ -1,4 +1,4 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; const ajv = new Ajv(); @@ -6,7 +6,7 @@ type DnsResolveTxtProps = { url: string; }; -const dnsResolveTxtPropsSchema: JSONSchemaType = { +const dnsResolveTxtPropsSchema = { type: 'object', properties: { url: { @@ -23,7 +23,7 @@ type DnsResolveSrvProps = { url: string; }; -const DnsResolveSrvSchema: JSONSchemaType = { +const DnsResolveSrvSchema = { type: 'object', properties: { url: { diff --git a/packages/rest-typings/src/v1/e2e.ts b/packages/rest-typings/src/v1/e2e.ts index d8bf5f77312c..80fc7b0e7b99 100644 --- a/packages/rest-typings/src/v1/e2e.ts +++ b/packages/rest-typings/src/v1/e2e.ts @@ -1,19 +1,105 @@ +/* eslint-disable @typescript-eslint/camelcase */ import type { IUser } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; + +const ajv = new Ajv(); + +type E2eSetUserPublicAndPrivateKeysProps = { + public_key: string; + private_key: string; +}; + +const E2eSetUserPublicAndPrivateKeysSchema = { + type: 'object', + properties: { + public_key: { + type: 'string', + }, + private_key: { + type: 'string', + }, + }, + required: ['public_key', 'private_key'], + additionalProperties: false, +}; + +export const isE2eSetUserPublicAndPrivateKeysProps = ajv.compile(E2eSetUserPublicAndPrivateKeysSchema); + +type E2eGetUsersOfRoomWithoutKeyProps = { rid: string }; + +const E2eGetUsersOfRoomWithoutKeySchema = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + }, + required: ['rid'], + additionalProperties: false, +}; + +export const isE2eGetUsersOfRoomWithoutKeyProps = ajv.compile(E2eGetUsersOfRoomWithoutKeySchema); + +type E2eUpdateGroupKeyProps = { + uid: string; + rid: string; + key: string; +}; + +const E2eUpdateGroupKeySchema = { + type: 'object', + properties: { + uid: { + type: 'string', + }, + rid: { + type: 'string', + }, + key: { + type: 'string', + }, + }, + required: ['uid', 'rid', 'key'], + additionalProperties: false, +}; + +export const isE2eUpdateGroupKeyProps = ajv.compile(E2eUpdateGroupKeySchema); + +type E2eSetRoomKeyIdProps = { + rid: string; + keyID: string; +}; + +const E2eSetRoomKeyIdSchema = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + keyID: { + type: 'string', + }, + }, + required: ['rid', 'keyID'], + additionalProperties: false, +}; + +export const isE2eSetRoomKeyIdProps = ajv.compile(E2eSetRoomKeyIdSchema); export type E2eEndpoints = { 'e2e.setUserPublicAndPrivateKeys': { - POST: (params: { public_key: string; private_key: string }) => void; + POST: (params: E2eSetUserPublicAndPrivateKeysProps) => void; }; 'e2e.getUsersOfRoomWithoutKey': { - GET: (params: { rid: string }) => { + GET: (params: E2eGetUsersOfRoomWithoutKeyProps) => { users: Pick[]; }; }; 'e2e.updateGroupKey': { - POST: (params: { uid: string; rid: string; key: string }) => {}; + POST: (params: E2eUpdateGroupKeyProps) => {}; }; 'e2e.setRoomKeyID': { - POST: (params: { rid: string; keyID: string }) => {}; + POST: (params: E2eSetRoomKeyIdProps) => {}; }; 'e2e.fetchMyKeys': { GET: () => { public_key: string; private_key: string }; diff --git a/packages/rest-typings/src/v1/email-inbox.ts b/packages/rest-typings/src/v1/email-inbox.ts index afa4745ed86d..7b0c524bdac3 100644 --- a/packages/rest-typings/src/v1/email-inbox.ts +++ b/packages/rest-typings/src/v1/email-inbox.ts @@ -1,43 +1,172 @@ import type { IEmailInbox } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv(); + +type EmailInboxListProps = PaginatedRequest<{ query?: string }>; + +const EmailInboxListPropsSchema = { + type: 'object', + properties: { + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isEmailInboxList = ajv.compile(EmailInboxListPropsSchema); + +type EmailInboxProps = { + _id?: string; + name: string; + email: string; + active: boolean; // POST method + description: string; + senderInfo: string; + department: string; + smtp: { + password: string; + port: number; + secure: boolean; + server: string; + username: string; + }; + imap: { + password: string; + port: number; + secure: boolean; + server: string; + username: string; + }; +}; + +const EmailInboxPropsSchema = { + type: 'object', + properties: { + _id: { + type: 'string', + nullable: true, + }, + name: { + type: 'string', + }, + email: { + type: 'string', + }, + active: { + type: 'boolean', + }, + description: { + type: 'string', + }, + senderInfo: { + type: 'string', + }, + department: { + type: 'string', + }, + + smtp: { + type: 'object', + properties: { + password: { + type: 'string', + }, + port: { + type: 'number', + }, + secure: { + type: 'boolean', + }, + server: { + type: 'string', + }, + username: { + type: 'string', + }, + }, + required: ['password', 'port', 'secure', 'server', 'username'], + additionalProperties: false, + }, + + imap: { + type: 'object', + properties: { + password: { + type: 'string', + }, + port: { + type: 'number', + }, + secure: { + type: 'boolean', + }, + server: { + type: 'string', + }, + username: { + type: 'string', + }, + }, + required: ['password', 'port', 'secure', 'server', 'username'], + additionalProperties: false, + }, + }, + + required: ['name', 'email', 'active', 'description', 'senderInfo', 'department', 'smtp', 'imap'], + additionalProperties: false, +}; + +export const isEmailInbox = ajv.compile(EmailInboxPropsSchema); + +type EmailInboxSearchProps = { + email: string; +}; + +const EmailInboxSearchPropsSchema = { + type: 'object', + properties: { + email: { + type: 'string', + }, + }, + required: ['email'], + additionalProperties: false, +}; + +export const isEmailInboxSearch = ajv.compile(EmailInboxSearchPropsSchema); + export type EmailInboxEndpoints = { 'email-inbox.list': { - GET: (params: PaginatedRequest<{ query?: string }>) => PaginatedResult<{ emailInboxes: IEmailInbox[] }>; + GET: (params: EmailInboxListProps) => PaginatedResult<{ emailInboxes: IEmailInbox[] }>; }; 'email-inbox': { - POST: (params: { - _id?: string; - name: string; - email: string; - active: boolean; - description: string; - senderInfo: string; - department: string; - smtp: { - password: string; - port: number; - secure: boolean; - server: string; - username: string; - }; - imap: { - password: string; - port: number; - secure: boolean; - server: string; - username: string; - }; - }) => { _id: string }; + POST: (params: EmailInboxProps) => { _id: string }; }; 'email-inbox/:_id': { GET: (params: void) => IEmailInbox | null; DELETE: (params: void) => { _id: string }; }; 'email-inbox.search': { - GET: (params: { email: string }) => { emailInbox: IEmailInbox | null }; + GET: (params: EmailInboxSearchProps) => { emailInbox: IEmailInbox | null }; }; 'email-inbox.send-test/:_id': { POST: (params: void) => { _id: string }; diff --git a/packages/rest-typings/src/v1/emojiCustom.ts b/packages/rest-typings/src/v1/emojiCustom.ts index 126097595d4c..c4ce2fb5792c 100644 --- a/packages/rest-typings/src/v1/emojiCustom.ts +++ b/packages/rest-typings/src/v1/emojiCustom.ts @@ -1,5 +1,5 @@ import type { ICustomEmojiDescriptor } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; @@ -10,7 +10,7 @@ type emojiCustomDeleteProps = { emojiId: ICustomEmojiDescriptor['_id']; }; -const emojiCustomDeletePropsSchema: JSONSchemaType = { +const emojiCustomDeletePropsSchema = { type: 'object', properties: { emojiId: { @@ -27,7 +27,7 @@ type emojiCustomList = { query: string; }; -const emojiCustomListSchema: JSONSchemaType = { +const emojiCustomListSchema = { type: 'object', properties: { query: { diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index d17110457c61..7f34649ca2d4 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -13,7 +13,7 @@ import type { IRoom, ISetting, } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; @@ -26,7 +26,7 @@ type LivechatVisitorsInfo = { visitorId: string; }; -const LivechatVisitorsInfoSchema: JSONSchemaType = { +const LivechatVisitorsInfoSchema = { type: 'object', properties: { visitorId: { @@ -43,7 +43,7 @@ type LivechatRoomOnHold = { roomId: IRoom['_id']; }; -const LivechatRoomOnHoldSchema: JSONSchemaType = { +const LivechatRoomOnHoldSchema = { type: 'object', properties: { roomId: { @@ -61,7 +61,7 @@ type LivechatDepartmentId = { includeAgents?: booleanString; }; -const LivechatDepartmentIdSchema: JSONSchemaType = { +const LivechatDepartmentIdSchema = { type: 'object', properties: { onlyMyDepartments: { @@ -83,7 +83,7 @@ type LivechatDepartmentAutocomplete = { onlyMyDepartments: booleanString; }; -const LivechatDepartmentAutocompleteSchema: JSONSchemaType = { +const LivechatDepartmentAutocompleteSchema = { type: 'object', properties: { selector: { @@ -103,7 +103,7 @@ type LivechatDepartmentDepartmentIdAgentsGET = { sort: string; }; -const LivechatDepartmentDepartmentIdAgentsGETSchema: JSONSchemaType = { +const LivechatDepartmentDepartmentIdAgentsGETSchema = { type: 'object', properties: { sort: { @@ -121,7 +121,7 @@ type LivechatDepartmentDepartmentIdAgentsPOST = { remove: string[]; }; -const LivechatDepartmentDepartmentIdAgentsPOSTSchema: JSONSchemaType = { +const LivechatDepartmentDepartmentIdAgentsPOSTSchema = { type: 'object', properties: { upsert: { @@ -147,7 +147,7 @@ type LivechatVisitorTokenGet = { token: string; }; -const LivechatVisitorTokenGetSchema: JSONSchemaType = { +const LivechatVisitorTokenGetSchema = { type: 'object', properties: { token: { @@ -164,7 +164,7 @@ type LivechatVisitorTokenDelete = { token: string; }; -const LivechatVisitorTokenDeleteSchema: JSONSchemaType = { +const LivechatVisitorTokenDeleteSchema = { type: 'object', properties: { token: { @@ -181,7 +181,7 @@ type LivechatVisitorTokenRoom = { token: string; }; -const LivechatVisitorTokenRoomSchema: JSONSchemaType = { +const LivechatVisitorTokenRoomSchema = { type: 'object', properties: { token: { @@ -201,7 +201,7 @@ type LivechatVisitorCallStatus = { callId: string; }; -const LivechatVisitorCallStatusSchema: JSONSchemaType = { +const LivechatVisitorCallStatusSchema = { type: 'object', properties: { token: { @@ -228,7 +228,7 @@ type LivechatVisitorStatus = { status: string; }; -const LivechatVisitorStatusSchema: JSONSchemaType = { +const LivechatVisitorStatusSchema = { type: 'object', properties: { token: { @@ -248,7 +248,7 @@ type LiveChatRoomJoin = { roomId: string; }; -const LiveChatRoomJoinSchema: JSONSchemaType = { +const LiveChatRoomJoinSchema = { type: 'object', properties: { roomId: { @@ -263,7 +263,7 @@ export const isLiveChatRoomJoinProps = ajv.compile(LiveChatRoomJoinSchema); type LivechatMonitorsListProps = PaginatedRequest<{ text: string }>; -const LivechatMonitorsListSchema: JSONSchemaType = { +const LivechatMonitorsListSchema = { type: 'object', properties: { text: { @@ -294,7 +294,7 @@ export const isLivechatMonitorsListProps = ajv.compile(LivechatMonitorsListSchem type LivechatTagsListProps = PaginatedRequest<{ text: string }, 'name'>; -const LivechatTagsListSchema: JSONSchemaType = { +const LivechatTagsListSchema = { type: 'object', properties: { text: { @@ -330,7 +330,7 @@ type LivechatDepartmentProps = PaginatedRequest<{ excludeDepartmentId?: string; }>; -const LivechatDepartmentSchema: JSONSchemaType = { +const LivechatDepartmentSchema = { type: 'object', properties: { text: { @@ -373,7 +373,7 @@ export const isLivechatDepartmentProps = ajv.compile(LivechatDepartmentSchema); type LivechatDepartmentsAvailableByUnitIdProps = PaginatedRequest<{ text: string }>; -const LivechatDepartmentsAvailableByUnitIdSchema: JSONSchemaType = { +const LivechatDepartmentsAvailableByUnitIdSchema = { type: 'object', properties: { text: { @@ -404,7 +404,7 @@ export const isLivechatDepartmentsAvailableByUnitIdProps = ajv.compile(LivechatD type LivechatDepartmentsByUnitProps = PaginatedRequest<{ text: string }>; -const LivechatDepartmentsByUnitSchema: JSONSchemaType = { +const LivechatDepartmentsByUnitSchema = { type: 'object', properties: { text: { @@ -435,7 +435,7 @@ export const isLivechatDepartmentsByUnitProps = ajv.compile(LivechatDepartmentsB type LivechatDepartmentsByUnitIdProps = PaginatedRequest<{ text: string }>; -const LivechatDepartmentsByUnitIdSchema: JSONSchemaType = { +const LivechatDepartmentsByUnitIdSchema = { type: 'object', properties: { text: { @@ -466,7 +466,7 @@ export const isLivechatDepartmentsByUnitIdProps = ajv.compile(LivechatDepartment type LivechatUsersManagerGETProps = PaginatedRequest<{ text: string }>; -const LivechatUsersManagerGETSchema: JSONSchemaType = { +const LivechatUsersManagerGETSchema = { type: 'object', properties: { text: { @@ -497,7 +497,7 @@ export const isLivechatUsersManagerGETProps = ajv.compile(LivechatUsersManagerGE type LivechatUsersManagerPOSTProps = PaginatedRequest<{ username: string }>; -const LivechatUsersManagerPOSTSchema: JSONSchemaType = { +const LivechatUsersManagerPOSTSchema = { type: 'object', properties: { username: { @@ -535,7 +535,7 @@ type LivechatQueueProps = { sort: string; }; -const LivechatQueuePropsSchema: JSONSchemaType = { +const LivechatQueuePropsSchema = { type: 'object', properties: { agentId: { @@ -572,7 +572,7 @@ type CannedResponsesProps = PaginatedRequest<{ text?: string; }>; -const CannedResponsesPropsSchema: JSONSchemaType = { +const CannedResponsesPropsSchema = { type: 'object', properties: { scope: { @@ -611,7 +611,7 @@ export const isCannedResponsesProps = ajv.compile(CannedResponsesPropsSchema); type LivechatCustomFieldsProps = PaginatedRequest<{ text: string }>; -const LivechatCustomFieldsSchema: JSONSchemaType = { +const LivechatCustomFieldsSchema = { type: 'object', properties: { text: { @@ -640,6 +640,129 @@ const LivechatCustomFieldsSchema: JSONSchemaType = { export const isLivechatCustomFieldsProps = ajv.compile(LivechatCustomFieldsSchema); +type LivechatRoomsProps = { + guest: string; + fname: string; + servedBy: string[]; + status: string; + department: string; + from: string; + to: string; + customFields: any; + current: number; + itemsPerPage: number; + tags: string[]; +}; + +const LivechatRoomsSchema = { + type: 'object', + properties: { + guest: { + type: 'string', + }, + fname: { + type: 'string', + }, + servedBy: { + type: 'array', + items: { + type: 'string', + }, + }, + status: { + type: 'string', + }, + department: { + type: 'string', + }, + from: { + type: 'string', + }, + to: { + type: 'string', + }, + customFields: { + type: 'object', + nullable: true, + }, + current: { + type: 'number', + }, + itemsPerPage: { + type: 'number', + }, + tags: { + type: 'array', + items: { + type: 'string', + }, + }, + }, + required: ['guest', 'fname', 'servedBy', 'status', 'department', 'from', 'to', 'current', 'itemsPerPage'], + additionalProperties: false, +}; + +export const isLivechatRoomsProps = ajv.compile(LivechatRoomsSchema); + +type LivechatRidMessagesProps = PaginatedRequest<{ query: string }>; + +const LivechatRidMessagesSchema = { + type: 'object', + properties: { + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + }, + }, + required: ['query'], + additionalProperties: false, +}; + +export const isLivechatRidMessagesProps = ajv.compile(LivechatRidMessagesSchema); + +type LivechatUsersAgentProps = PaginatedRequest<{ text?: string }>; + +const LivechatUsersAgentSchema = { + type: 'object', + properties: { + text: { + type: 'string', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isLivechatUsersAgentProps = ajv.compile(LivechatUsersAgentSchema); + export type OmnichannelEndpoints = { 'livechat/appearance': { GET: () => { @@ -734,32 +857,17 @@ export type OmnichannelEndpoints = { }>; }; 'livechat/rooms': { - // TO-DO - GET: (params: { - guest: string; - fname: string; - servedBy: string[]; - status: string; - department: string; - from: string; - to: string; - customFields: any; - current: number; - itemsPerPage: number; - tags: string[]; - }) => PaginatedResult<{ + GET: (params: LivechatRoomsProps) => PaginatedResult<{ rooms: IOmnichannelRoom[]; }>; }; 'livechat/:rid/messages': { - // TO-DO - GET: (params: PaginatedRequest<{ query: string }>) => PaginatedResult<{ + GET: (params: LivechatRidMessagesProps) => PaginatedResult<{ messages: IMessage[]; }>; }; 'livechat/users/agent': { - // TO-DO - GET: (params: PaginatedRequest<{ text?: string }>) => PaginatedResult<{ + GET: (params: LivechatUsersAgentProps) => PaginatedResult<{ users: { _id: string; emails: { diff --git a/packages/rest-typings/src/v1/permissions.ts b/packages/rest-typings/src/v1/permissions.ts index 85506bf1aff8..6518ea317e86 100644 --- a/packages/rest-typings/src/v1/permissions.ts +++ b/packages/rest-typings/src/v1/permissions.ts @@ -1,13 +1,31 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; import type { IPermission } from '@rocket.chat/core-typings'; const ajv = new Ajv(); +type PermissionsListAllProps = { + updatedSince?: string; +}; + +const permissionListAllSchema = { + type: 'object', + properties: { + updatedSince: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isPermissionsListAll = ajv.compile(permissionListAllSchema); + type PermissionsUpdateProps = { permissions: { _id: string; roles: string[] }[]; }; -const permissionUpdatePropsSchema: JSONSchemaType = { +const permissionUpdatePropsSchema = { type: 'object', properties: { permissions: { @@ -35,7 +53,7 @@ export const isBodyParamsValidPermissionUpdate = ajv.compile(permissionUpdatePro export type PermissionsEndpoints = { 'permissions.listAll': { - GET: (params: { updatedSince?: string }) => { + GET: (params: PermissionsListAllProps) => { update: IPermission[]; remove: IPermission[]; }; From 1f833381c657ad210e2b23b2ab4df94f7ce63c1e Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Fri, 27 May 2022 19:54:07 -0300 Subject: [PATCH 09/18] add JSON Schema to more files --- packages/rest-typings/src/v1/groups.ts | 50 ++- packages/rest-typings/src/v1/im.ts | 62 ++- packages/rest-typings/src/v1/invites.ts | 6 +- packages/rest-typings/src/v1/ldap.ts | 4 +- packages/rest-typings/src/v1/licenses.ts | 4 +- packages/rest-typings/src/v1/push.ts | 54 ++- packages/rest-typings/src/v1/roles.ts | 54 ++- packages/rest-typings/src/v1/rooms.ts | 443 ++++++++++++++++++--- packages/rest-typings/src/v1/statistics.ts | 57 ++- 9 files changed, 633 insertions(+), 101 deletions(-) diff --git a/packages/rest-typings/src/v1/groups.ts b/packages/rest-typings/src/v1/groups.ts index f46ac175f393..1aa1ad4c547b 100644 --- a/packages/rest-typings/src/v1/groups.ts +++ b/packages/rest-typings/src/v1/groups.ts @@ -1,5 +1,5 @@ import type { IMessage, IRoom, ITeam, IGetRoomRoles, IUser } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; @@ -13,7 +13,7 @@ type GroupsFilesProps = { query: string; }; -const GroupsFilesPropsSchema: JSONSchemaType = { +const GroupsFilesPropsSchema = { type: 'object', properties: { roomId: { @@ -43,7 +43,7 @@ type GroupsMembersProps = { status?: string[]; }; -const GroupsMembersPropsSchema: JSONSchemaType = { +const GroupsMembersPropsSchema = { type: 'object', properties: { roomId: { @@ -77,7 +77,7 @@ type GroupsArchiveProps = { roomId: IRoom['_id']; }; -const GroupsArchivePropsSchema: JSONSchemaType = { +const GroupsArchivePropsSchema = { type: 'object', properties: { roomId: { @@ -94,7 +94,7 @@ type GroupsUnarchiveProps = { roomId: IRoom['_id']; }; -const GroupsUnarchivePropsSchema: JSONSchemaType = { +const GroupsUnarchivePropsSchema = { type: 'object', properties: { roomId: { @@ -118,7 +118,7 @@ type GroupsCreateProps = { }; }; -const GroupsCreatePropsSchema: JSONSchemaType = { +const GroupsCreatePropsSchema = { type: 'object', properties: { name: { @@ -160,7 +160,7 @@ type GroupsConvertToTeamProps = { roomName: string; }; -const GroupsConvertToTeamPropsSchema: JSONSchemaType = { +const GroupsConvertToTeamPropsSchema = { type: 'object', properties: { roomId: { @@ -180,7 +180,7 @@ type GroupsCountersProps = { roomId: string; }; -const GroupsCountersPropsSchema: JSONSchemaType = { +const GroupsCountersPropsSchema = { type: 'object', properties: { roomId: { @@ -197,7 +197,7 @@ type GroupsCloseProps = { roomId: string; }; -const GroupsClosePropsSchema: JSONSchemaType = { +const GroupsClosePropsSchema = { type: 'object', properties: { roomId: { @@ -214,7 +214,7 @@ type GroupsDeleteProps = { roomId: string; }; -const GroupsDeletePropsSchema: JSONSchemaType = { +const GroupsDeletePropsSchema = { type: 'object', properties: { roomId: { @@ -231,7 +231,7 @@ type GroupsLeaveProps = { roomId: string; }; -const GroupsLeavePropsSchema: JSONSchemaType = { +const GroupsLeavePropsSchema = { type: 'object', properties: { roomId: { @@ -248,7 +248,7 @@ type GroupsRolesProps = { roomId: string; }; -const GroupsRolesPropsSchema: JSONSchemaType = { +const GroupsRolesPropsSchema = { type: 'object', properties: { roomId: { @@ -266,7 +266,7 @@ type GroupsKickProps = { userId: string; }; -const GroupsKickPropsSchema: JSONSchemaType = { +const GroupsKickPropsSchema = { type: 'object', properties: { roomId: { @@ -282,16 +282,32 @@ const GroupsKickPropsSchema: JSONSchemaType = { export const isGroupsKickProps = ajv.compile(GroupsKickPropsSchema); -type GroupsMessageProps = { +type GroupsMessageProps = PaginatedRequest<{ roomId: IRoom['_id']; -}; +}>; -const GroupsMessagePropsSchema: JSONSchemaType = { +const GroupsMessagePropsSchema = { type: 'object', properties: { roomId: { type: 'string', }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, }, required: ['roomId'], additionalProperties: false, @@ -360,7 +376,7 @@ export type GroupsEndpoints = { GET: (params: GroupsRolesProps) => { roles: IGetRoomRoles[] }; }; 'groups.messages': { - GET: (params: PaginatedRequest) => PaginatedResult<{ + GET: (params: GroupsMessageProps) => PaginatedResult<{ messages: IMessage[]; }>; }; diff --git a/packages/rest-typings/src/v1/im.ts b/packages/rest-typings/src/v1/im.ts index 59de05dc8edf..014c1e6388d3 100644 --- a/packages/rest-typings/src/v1/im.ts +++ b/packages/rest-typings/src/v1/im.ts @@ -1,5 +1,5 @@ import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; @@ -14,7 +14,7 @@ type ImFilesProps = { query: string; }; -const ImFilesPropsSchema: JSONSchemaType = { +const ImFilesPropsSchema = { type: 'object', properties: { roomId: { @@ -44,7 +44,7 @@ type ImMembersProps = { status?: string[]; }; -const ImMembersPropsSchema: JSONSchemaType = { +const ImMembersPropsSchema = { type: 'object', properties: { roomId: { @@ -74,12 +74,12 @@ const ImMembersPropsSchema: JSONSchemaType = { export const isImMembersProps = ajv.compile(ImMembersPropsSchema); -type ImHistoryProps = { +type ImHistoryProps = PaginatedRequest<{ roomId: string; latest?: string; -}; +}>; -const ImHistoryPropsSchema: JSONSchemaType = { +const ImHistoryPropsSchema = { type: 'object', properties: { roomId: { @@ -89,6 +89,22 @@ const ImHistoryPropsSchema: JSONSchemaType = { type: 'string', nullable: true, }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, }, required: ['roomId'], additionalProperties: false, @@ -100,7 +116,7 @@ type ImCloseProps = { roomId: string; }; -const ImClosePropsSchema: JSONSchemaType = { +const ImClosePropsSchema = { type: 'object', properties: { roomId: { @@ -117,7 +133,7 @@ type ImDeleteProps = { roomId: string; }; -const ImDeletePropsSchema: JSONSchemaType = { +const ImDeletePropsSchema = { type: 'object', properties: { roomId: { @@ -134,7 +150,7 @@ type ImLeaveProps = { roomId: string; }; -const ImLeavePropsSchema: JSONSchemaType = { +const ImLeavePropsSchema = { type: 'object', properties: { roomId: { @@ -152,7 +168,7 @@ type ImKickProps = { userId: string; }; -const ImKickPropsSchema: JSONSchemaType = { +const ImKickPropsSchema = { type: 'object', properties: { roomId: { @@ -168,16 +184,32 @@ const ImKickPropsSchema: JSONSchemaType = { export const isImKickProps = ajv.compile(ImKickPropsSchema); -type ImMessagesProps = { +type ImMessagesProps = PaginatedRequest<{ roomId: string; -}; +}>; -const ImMessagesPropsSchema: JSONSchemaType = { +const ImMessagesPropsSchema = { type: 'object', properties: { roomId: { type: 'string', }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, }, required: ['roomId'], additionalProperties: false, @@ -217,7 +249,7 @@ export type ImEndpoints = { }; }; 'im.history': { - GET: (params: PaginatedRequest) => PaginatedRequest<{ + GET: (params: ImHistoryProps) => PaginatedRequest<{ messages: IMessage[]; }>; }; @@ -234,7 +266,7 @@ export type ImEndpoints = { POST: (params: ImLeaveProps) => {}; }; 'im.messages': { - GET: (params: PaginatedRequest) => PaginatedResult<{ + GET: (params: ImMessagesProps) => PaginatedResult<{ messages: IMessage[]; }>; }; diff --git a/packages/rest-typings/src/v1/invites.ts b/packages/rest-typings/src/v1/invites.ts index da67399c0d22..0ebae2a6e48b 100644 --- a/packages/rest-typings/src/v1/invites.ts +++ b/packages/rest-typings/src/v1/invites.ts @@ -1,5 +1,5 @@ import type { IInvite, IRoom } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; const ajv = new Ajv(); @@ -7,7 +7,7 @@ type v1UseInviteTokenProps = { token: string; }; -const v1UseInviteTokenPropsSchema: JSONSchemaType = { +const v1UseInviteTokenPropsSchema = { type: 'object', properties: { token: { @@ -24,7 +24,7 @@ type v1ValidateInviteTokenProps = { token: string; }; -const v1ValidateInviteTokenPropsSchema: JSONSchemaType = { +const v1ValidateInviteTokenPropsSchema = { type: 'object', properties: { token: { diff --git a/packages/rest-typings/src/v1/ldap.ts b/packages/rest-typings/src/v1/ldap.ts index 91926f032709..36ee55ceb8a3 100644 --- a/packages/rest-typings/src/v1/ldap.ts +++ b/packages/rest-typings/src/v1/ldap.ts @@ -1,4 +1,4 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; const ajv = new Ajv(); @@ -6,7 +6,7 @@ type ldapTestSearchProps = { username: string; }; -const ldapTestSearchPropsSchema: JSONSchemaType = { +const ldapTestSearchPropsSchema = { type: 'object', properties: { username: { diff --git a/packages/rest-typings/src/v1/licenses.ts b/packages/rest-typings/src/v1/licenses.ts index 93595aa9f6fe..763a6ac6184f 100644 --- a/packages/rest-typings/src/v1/licenses.ts +++ b/packages/rest-typings/src/v1/licenses.ts @@ -1,5 +1,5 @@ import type { ILicense } from '@rocket.chat/core-typings'; -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; const ajv = new Ajv(); @@ -7,7 +7,7 @@ type licensesAddProps = { license: string; }; -const licensesAddPropsSchema: JSONSchemaType = { +const licensesAddPropsSchema = { type: 'object', properties: { license: { diff --git a/packages/rest-typings/src/v1/push.ts b/packages/rest-typings/src/v1/push.ts index d0b07c6afbca..25830fc67e23 100644 --- a/packages/rest-typings/src/v1/push.ts +++ b/packages/rest-typings/src/v1/push.ts @@ -1,12 +1,62 @@ import type { IMessage, IPushNotificationConfig, IPushTokenTypes, IPushToken } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; + +const ajv = new Ajv(); + +type PushTokenProps = { + id?: string; + type: IPushTokenTypes; + value: string; + appName: string; +}; + +const PushTokenPropsSchema = { + type: 'object', + properties: { + id: { + type: 'string', + nullable: true, + }, + type: { + type: 'string', + }, + value: { + type: 'string', + }, + appName: { + type: 'string', + }, + }, + required: ['type', 'value', 'appName'], + additionalProperties: false, +}; + +export const isPushTokenProps = ajv.compile(PushTokenPropsSchema); + +type PushGetProps = { + id: string; +}; + +const PushGetPropsSchema = { + type: 'object', + properties: { + id: { + type: 'string', + }, + }, + required: ['id'], + additionalProperties: false, +}; + +export const isPushGetProps = ajv.compile(PushGetPropsSchema); export type PushEndpoints = { 'push.token': { - POST: (payload: { id?: string; type: IPushTokenTypes; value: string; appName: string }) => { result: IPushToken }; + POST: (payload: PushTokenProps) => { result: IPushToken }; DELETE: (payload: { token: string }) => void; }; 'push.get': { - GET: (params: { id: string }) => { + GET: (params: PushGetProps) => { data: { message: IMessage; notification: IPushNotificationConfig; diff --git a/packages/rest-typings/src/v1/roles.ts b/packages/rest-typings/src/v1/roles.ts index 6e3d729a0222..03023ae0376a 100644 --- a/packages/rest-typings/src/v1/roles.ts +++ b/packages/rest-typings/src/v1/roles.ts @@ -1,11 +1,13 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; import type { RocketChatRecordDeleted, IRole, IUserInRole } from '@rocket.chat/core-typings'; +import type { PaginatedRequest } from '../helpers/PaginatedRequest'; + const ajv = new Ajv(); type RoleCreateProps = Pick & Partial>; -const roleCreatePropsSchema: JSONSchemaType = { +const roleCreatePropsSchema = { type: 'object', properties: { name: { @@ -36,7 +38,7 @@ type RoleUpdateProps = { name: IRole['name']; } & Partial; -const roleUpdatePropsSchema: JSONSchemaType = { +const roleUpdatePropsSchema = { type: 'object', properties: { roleId: { @@ -67,7 +69,7 @@ export const isRoleUpdateProps = ajv.compile(roleUpdatePropsSchema); type RoleDeleteProps = { roleId: IRole['_id'] }; -const roleDeletePropsSchema: JSONSchemaType = { +const roleDeletePropsSchema = { type: 'object', properties: { roleId: { @@ -88,7 +90,7 @@ type RoleAddUserToRoleProps = { roomId?: string; }; -const roleAddUserToRolePropsSchema: JSONSchemaType = { +const roleAddUserToRolePropsSchema = { type: 'object', properties: { username: { @@ -122,7 +124,7 @@ type RoleRemoveUserFromRoleProps = { scope?: string; }; -const roleRemoveUserFromRolePropsSchema: JSONSchemaType = { +const roleRemoveUserFromRolePropsSchema = { type: 'object', properties: { username: { @@ -151,6 +153,44 @@ const roleRemoveUserFromRolePropsSchema: JSONSchemaType; + +const RolesGetUsersInRolePropsSchema = { + type: 'object', + properties: { + roomId: { + type: 'string', + nullable: true, + }, + role: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['role'], + additionalProperties: false, +}; + +export const isRolesGetUsersInRoleProps = ajv.compile(RolesGetUsersInRolePropsSchema); + type RoleSyncProps = { updatedSince?: string; }; @@ -182,7 +222,7 @@ export type RolesEndpoints = { }; 'roles.getUsersInRole': { - GET: (params: { roomId?: string; role: string; offset?: number; count?: number }) => { + GET: (params: RolesGetUsersInRoleProps) => { users: IUserInRole[]; total: number; }; diff --git a/packages/rest-typings/src/v1/rooms.ts b/packages/rest-typings/src/v1/rooms.ts index 647127c4b469..adfc8d5d6f53 100644 --- a/packages/rest-typings/src/v1/rooms.ts +++ b/packages/rest-typings/src/v1/rooms.ts @@ -1,16 +1,398 @@ +/* eslint-disable @typescript-eslint/camelcase */ import type { IMessage, IRoom, IUser, RoomAdminFieldsType } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv(); + +type RoomsAutoCompleteChannelAndPrivateProps = { selector: string }; + +const RoomsAutoCompleteChannelAndPrivateSchema = { + type: 'object', + properties: { + selector: { + type: 'string', + }, + }, + required: ['selector'], + additionalProperties: false, +}; + +export const isRoomsAutoCompleteChannelAndPrivateProps = ajv.compile(RoomsAutoCompleteChannelAndPrivateSchema); + +type RoomsAutocompleteChannelAndPrivateWithPaginationProps = PaginatedRequest<{ selector: string }>; + +const RoomsAutocompleteChannelAndPrivateWithPaginationSchema = { + type: 'object', + properties: { + selector: { + type: 'string', + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: ['selector'], + additionalProperties: false, +}; + +export const isRoomsAutocompleteChannelAndPrivateWithPaginationProps = ajv.compile(RoomsAutocompleteChannelAndPrivateWithPaginationSchema); + +type RoomsAutocompleteAvailableForTeamsProps = { name: string }; + +const RoomsAutocompleteAvailableForTeamsSchema = { + type: 'object', + properties: { + name: { + type: 'string', + }, + }, + required: ['name'], + additionalProperties: false, +}; + +export const isRoomsAutocompleteAvailableForTeamsProps = ajv.compile(RoomsAutocompleteAvailableForTeamsSchema); + +type RoomsInfoProps = { roomId: string } | { roomName: string }; + +const RoomsInfoSchema = { + oneOf: [ + { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + roomName: { + type: 'string', + }, + }, + required: ['roomName'], + additionalProperties: false, + }, + ], +}; + +export const isRoomsInfoProps = ajv.compile(RoomsInfoSchema); + +type RoomsCreateDiscussionProps = { + prid: IRoom['_id']; + pmid?: IMessage['_id']; + t_name: string; // IRoom['fname'] + users?: IUser['username'][]; + encrypted?: boolean; + reply?: string; +}; + +const RoomsCreateDiscussionSchema = { + type: 'object', + properties: { + prid: { + type: 'string', + }, + pmid: { + type: 'string', + nullable: true, + }, + t_name: { + type: 'string', + nullable: true, + }, + users: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + encrypted: { + type: 'boolean', + nullable: true, + }, + reply: { + type: 'string', + nullable: true, + }, + }, + required: ['prid', 't_name'], + additionalProperties: false, +}; + +export const isRoomsCreateDiscussionProps = ajv.compile(RoomsCreateDiscussionSchema); + +type RoomsExportProps = { + rid: IRoom['_id']; + type: 'email' | 'file'; + toUsers?: IUser['username'][]; + toEmails?: string[]; + additionalEmails?: string; + subject?: string; + messages?: IMessage['_id'][]; + dateFrom?: string; + dateTo?: string; + format?: 'html' | 'json'; +}; + +const RoomsExportSchema = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + type: { + type: 'string', + nullable: true, + }, + toUsers: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + toEmails: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + additionalEmails: { + type: 'string', + nullable: true, + }, + subject: { + type: 'string', + nullable: true, + }, + messages: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + dateFrom: { + type: 'string', + nullable: true, + }, + dateTo: { + type: 'string', + nullable: true, + }, + format: { + type: 'string', + nullable: true, + }, + }, + required: ['rid'], + additionalProperties: false, +}; + +export const isRoomsExportProps = ajv.compile(RoomsExportSchema); + +type RoomsAdminRoomsProps = PaginatedRequest<{ + filter?: string; + types?: string[]; +}>; + +const RoomsAdminRoomsSchema = { + type: 'object', + properties: { + filter: { + type: 'string', + nullable: true, + }, + types: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isRoomsAdminRoomsProps = ajv.compile(RoomsAdminRoomsSchema); + +type RoomsAdminRoomsGetRoomProps = { rid?: string }; + +const RoomsAdminRoomsGetRoomSchema = { + type: 'object', + properties: { + rid: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isRoomsAdminRoomsGetRoomProps = ajv.compile(RoomsAdminRoomsGetRoomSchema); + +type RoomsChangeArchivationStateProps = { rid: string; action?: string }; + +const RoomsChangeArchivationStateSchema = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + action: { + type: 'string', + nullable: true, + }, + }, + required: ['rid'], + additionalProperties: false, +}; + +export const isRoomsChangeArchivationStateProps = ajv.compile(RoomsChangeArchivationStateSchema); + +type RoomsSaveRoomSettingsProps = { + rid: string; + roomAvatar?: string; + featured?: boolean; + roomName?: string; + roomTopic?: string; + roomAnnouncement?: string; + roomDescription?: string; + roomType?: IRoom['t']; + readOnly?: boolean; + reactWhenReadOnly?: boolean; + default?: boolean; + tokenpass?: string; + encrypted?: boolean; + favorite?: { + defaultValue?: boolean; + favorite?: boolean; + }; +}; + +const RoomsSaveRoomSettingsSchema = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + roomAvatar: { + type: 'string', + nullable: true, + }, + featured: { + type: 'boolean', + nullable: true, + }, + roomName: { + type: 'string', + nullable: true, + }, + roomTopic: { + type: 'string', + nullable: true, + }, + roomAnnouncement: { + type: 'string', + nullable: true, + }, + roomDescription: { + type: 'string', + nullable: true, + }, + roomType: { + type: 'string', + nullable: true, + }, + readOnly: { + type: 'boolean', + nullable: true, + }, + reactWhenReadOnly: { + type: 'boolean', + nullable: true, + }, + default: { + type: 'boolean', + nullable: true, + }, + tokenpass: { + type: 'string', + nullable: true, + }, + encrypted: { + type: 'boolean', + nullable: true, + }, + favorite: { + type: 'object', + properties: { + defaultValue: { + type: 'boolean', + nullable: true, + }, + favorite: { + type: 'boolean', + nullable: true, + }, + }, + nullable: true, + }, + }, + required: ['rid'], + additionalProperties: false, +}; + +export const isRoomsSaveRoomSettingsProps = ajv.compile(RoomsSaveRoomSettingsSchema); + export type RoomsEndpoints = { 'rooms.autocomplete.channelAndPrivate': { - GET: (params: { selector: string }) => { + GET: (params: RoomsAutoCompleteChannelAndPrivateProps) => { items: IRoom[]; }; }; 'rooms.autocomplete.channelAndPrivate.withPagination': { - GET: (params: { selector: string; offset?: number; count?: number; sort?: string }) => { + GET: (params: RoomsAutocompleteChannelAndPrivateWithPaginationProps) => { items: IRoom[]; count: number; offset: number; @@ -18,81 +400,40 @@ export type RoomsEndpoints = { }; }; 'rooms.autocomplete.availableForTeams': { - GET: (params: { name: string }) => { + GET: (params: RoomsAutocompleteAvailableForTeamsProps) => { items: IRoom[]; }; }; 'rooms.info': { - GET: (params: { roomId: string } | { roomName: string }) => { + GET: (params: RoomsInfoProps) => { room: IRoom; }; }; 'rooms.createDiscussion': { - POST: (params: { - prid: IRoom['_id']; - pmid?: IMessage['_id']; - t_name: IRoom['fname']; - users?: IUser['username'][]; - encrypted?: boolean; - reply?: string; - }) => { + POST: (params: RoomsCreateDiscussionProps) => { discussion: IRoom; }; }; 'rooms.export': { - POST: (params: { - rid: IRoom['_id']; - type: 'email' | 'file'; - toUsers?: IUser['username'][]; - toEmails?: string[]; - additionalEmails?: string; - subject?: string; - messages?: IMessage['_id'][]; - dateFrom?: string; - dateTo?: string; - format?: 'html' | 'json'; - }) => { + POST: (params: RoomsExportProps) => { missing?: []; success: boolean; }; }; 'rooms.adminRooms': { - GET: ( - params: PaginatedRequest<{ - filter?: string; - types?: string[]; - }>, - ) => PaginatedResult<{ rooms: Pick[] }>; + GET: (params: RoomsAdminRoomsProps) => PaginatedResult<{ rooms: Pick[] }>; }; 'rooms.adminRooms.getRoom': { - GET: (params: { rid?: string }) => Pick; + GET: (params: RoomsAdminRoomsGetRoomProps) => Pick; }; 'rooms.saveRoomSettings': { - POST: (params: { - rid: string; - roomAvatar?: string; - featured?: boolean; - roomName?: string; - roomTopic?: string; - roomAnnouncement?: string; - roomDescription?: string; - roomType?: IRoom['t']; - readOnly?: boolean; - reactWhenReadOnly?: boolean; - default?: boolean; - tokenpass?: string; - encrypted?: boolean; - favorite?: { - defaultValue?: boolean; - favorite?: boolean; - }; - }) => { + POST: (params: RoomsSaveRoomSettingsProps) => { success: boolean; rid: string; }; }; 'rooms.changeArchivationState': { - POST: (params: { rid: string; action?: string }) => { + POST: (params: RoomsChangeArchivationStateProps) => { success: boolean; }; }; diff --git a/packages/rest-typings/src/v1/statistics.ts b/packages/rest-typings/src/v1/statistics.ts index b3fd2fb723c3..aa1c7da43671 100644 --- a/packages/rest-typings/src/v1/statistics.ts +++ b/packages/rest-typings/src/v1/statistics.ts @@ -1,4 +1,7 @@ import type { IStats } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; + +import type { PaginatedRequest } from '../helpers/PaginatedRequest'; type OTREnded = { rid: string }; @@ -18,12 +21,62 @@ export type TelemetryPayload = { params: Param[]; }; +const ajv = new Ajv(); + +type StatisticsProps = { refresh?: 'true' | 'false' }; + +const StatisticsSchema = { + type: 'object', + properties: { + refresh: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isStatisticsProps = ajv.compile(StatisticsSchema); + +type StatisticsListProps = PaginatedRequest<{ fields?: string }>; + +const StatisticsListSchema = { + type: 'object', + properties: { + fields: { + type: 'string', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isStatisticsListProps = ajv.compile(StatisticsListSchema); + export type StatisticsEndpoints = { 'statistics': { - GET: (params: { refresh?: 'true' | 'false' }) => IStats; + GET: (params: StatisticsProps) => IStats; }; 'statistics.list': { - GET: (params: { offset?: number; count?: number; sort?: string; fields?: string; query?: string }) => { + GET: (params: StatisticsListProps) => { statistics: IStats[]; count: number; offset: number; From b360fb3b7e5a84fe2755be3c987709cfc3bbf0ce Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Mon, 30 May 2022 09:25:44 -0300 Subject: [PATCH 10/18] lint --- packages/rest-typings/src/v1/dm/DmCloseProps.ts | 1 - packages/rest-typings/src/v1/dm/DmHistoryProps.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/rest-typings/src/v1/dm/DmCloseProps.ts b/packages/rest-typings/src/v1/dm/DmCloseProps.ts index cc573d9d95c0..1a1ea759680a 100644 --- a/packages/rest-typings/src/v1/dm/DmCloseProps.ts +++ b/packages/rest-typings/src/v1/dm/DmCloseProps.ts @@ -1,4 +1,3 @@ -import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings'; import Ajv, { JSONSchemaType } from 'ajv'; const ajv = new Ajv(); diff --git a/packages/rest-typings/src/v1/dm/DmHistoryProps.ts b/packages/rest-typings/src/v1/dm/DmHistoryProps.ts index e74ed87445e0..784bd6c25d3c 100644 --- a/packages/rest-typings/src/v1/dm/DmHistoryProps.ts +++ b/packages/rest-typings/src/v1/dm/DmHistoryProps.ts @@ -1,4 +1,3 @@ -import type { IMessage, IRoom, IUser } from '@rocket.chat/core-typings'; import Ajv, { JSONSchemaType } from 'ajv'; const ajv = new Ajv(); From f21aa9a849fa35e720d3876d36fbd1352dd52f3b Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 1 Jun 2022 11:36:58 -0300 Subject: [PATCH 11/18] add compile types to Ajv (work in progress) --- packages/rest-typings/src/v1/banners.ts | 12 ++++--- packages/rest-typings/src/v1/chat.ts | 38 ++++++++++---------- packages/rest-typings/src/v1/cloud.ts | 10 +++--- packages/rest-typings/src/v1/customSounds.ts | 6 ++-- 4 files changed, 37 insertions(+), 29 deletions(-) diff --git a/packages/rest-typings/src/v1/banners.ts b/packages/rest-typings/src/v1/banners.ts index 40233404d408..50d56d1d0850 100644 --- a/packages/rest-typings/src/v1/banners.ts +++ b/packages/rest-typings/src/v1/banners.ts @@ -1,7 +1,9 @@ import Ajv from 'ajv'; import type { BannerPlatform, IBanner } from '@rocket.chat/core-typings'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type BannersGetNew = { platform: BannerPlatform; @@ -22,7 +24,7 @@ const BannersGetNewSchema = { additionalProperties: false, }; -export const isBannersGetNewProps = ajv.compile(BannersGetNewSchema); +export const isBannersGetNewProps = ajv.compile(BannersGetNewSchema); type BannersId = { platform: BannerPlatform; @@ -39,7 +41,7 @@ const BannersIdSchema = { additionalProperties: false, }; -export const isBannersIdProps = ajv.compile(BannersIdSchema); +export const isBannersIdProps = ajv.compile(BannersIdSchema); type Banners = { platform: BannerPlatform; @@ -56,7 +58,7 @@ const BannersSchema = { additionalProperties: false, }; -export const isBannersProps = ajv.compile(BannersSchema); +export const isBannersProps = ajv.compile(BannersSchema); type BannersDismiss = { bannerId: string; @@ -73,7 +75,7 @@ const BannersDismissSchema = { additionalProperties: false, }; -export const isBannersDismissProps = ajv.compile(BannersDismissSchema); +export const isBannersDismissProps = ajv.compile(BannersDismissSchema); export type BannersEndpoints = { /* @deprecated */ diff --git a/packages/rest-typings/src/v1/chat.ts b/packages/rest-typings/src/v1/chat.ts index 5a7fcc398749..1754c302f5a9 100644 --- a/packages/rest-typings/src/v1/chat.ts +++ b/packages/rest-typings/src/v1/chat.ts @@ -1,7 +1,9 @@ import type { IMessage, IRoom, ReadReceipt } from '@rocket.chat/core-typings'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type ChatFollowMessage = { mid: IMessage['_id']; @@ -18,7 +20,7 @@ const chatFollowMessageSchema = { additionalProperties: false, }; -export const isChatFollowMessageProps = ajv.compile(chatFollowMessageSchema); +export const isChatFollowMessageProps = ajv.compile(chatFollowMessageSchema); type ChatUnfollowMessage = { mid: IMessage['_id']; @@ -35,7 +37,7 @@ const chatUnfollowMessageSchema = { additionalProperties: false, }; -export const isChatUnfollowMessageProps = ajv.compile(chatUnfollowMessageSchema); +export const isChatUnfollowMessageProps = ajv.compile(chatUnfollowMessageSchema); type ChatGetMessage = { msgId: IMessage['_id']; @@ -52,7 +54,7 @@ const ChatGetMessageSchema = { additionalProperties: false, }; -export const isChatGetMessageProps = ajv.compile(ChatGetMessageSchema); +export const isChatGetMessageProps = ajv.compile(ChatGetMessageSchema); type ChatStarMessage = { msgId: IMessage['_id']; @@ -69,7 +71,7 @@ const ChatStarMessageSchema = { additionalProperties: false, }; -export const isChatStarMessageProps = ajv.compile(ChatStarMessageSchema); +export const isChatStarMessageProps = ajv.compile(ChatStarMessageSchema); type ChatUnstarMessage = { msgId: IMessage['_id']; @@ -86,7 +88,7 @@ const ChatUnstarMessageSchema = { additionalProperties: false, }; -export const isChatUnstarMessageProps = ajv.compile(ChatUnstarMessageSchema); +export const isChatUnstarMessageProps = ajv.compile(ChatUnstarMessageSchema); type ChatPinMessage = { msgId: IMessage['_id']; @@ -103,7 +105,7 @@ const ChatPinMessageSchema = { additionalProperties: false, }; -export const isChatPinMessageProps = ajv.compile(ChatPinMessageSchema); +export const isChatPinMessageProps = ajv.compile(ChatPinMessageSchema); type ChatUnpinMessage = { messageId: IMessage['_id']; @@ -120,7 +122,7 @@ const ChatUnpinMessageSchema = { additionalProperties: false, }; -export const isChatUnpinMessageProps = ajv.compile(ChatUnpinMessageSchema); +export const isChatUnpinMessageProps = ajv.compile(ChatUnpinMessageSchema); type ChatGetDiscussions = { roomId: IRoom['_id']; @@ -150,7 +152,7 @@ const ChatGetDiscussionsSchema = { additionalProperties: false, }; -export const isChatGetDiscussionsProps = ajv.compile(ChatGetDiscussionsSchema); +export const isChatGetDiscussionsProps = ajv.compile(ChatGetDiscussionsSchema); type ChatReportMessage = { messageId: IMessage['_id']; @@ -171,7 +173,7 @@ const ChatReportMessageSchema = { additionalProperties: false, }; -export const isChatReportMessageProps = ajv.compile(ChatReportMessageSchema); +export const isChatReportMessageProps = ajv.compile(ChatReportMessageSchema); type ChatGetThreadsList = { rid: IRoom['_id']; @@ -205,7 +207,7 @@ const ChatGetThreadsListSchema = { additionalProperties: false, }; -export const isChatGetThreadsListProps = ajv.compile(ChatGetThreadsListSchema); +export const isChatGetThreadsListProps = ajv.compile(ChatGetThreadsListSchema); type ChatSyncThreadsList = { rid: IRoom['_id']; @@ -226,7 +228,7 @@ const ChatSyncThreadsListSchema = { additionalProperties: false, }; -export const isChatSyncThreadsListProps = ajv.compile(ChatSyncThreadsListSchema); +export const isChatSyncThreadsListProps = ajv.compile(ChatSyncThreadsListSchema); type ChatDelete = { msgId: IMessage['_id']; @@ -247,7 +249,7 @@ const ChatDeleteSchema = { additionalProperties: false, }; -export const isChatDeleteProps = ajv.compile(ChatDeleteSchema); +export const isChatDeleteProps = ajv.compile(ChatDeleteSchema); type ChatReact = { emoji: string; messageId: IMessage['_id'] } | { reaction: string; messageId: IMessage['_id'] }; @@ -282,7 +284,7 @@ const ChatReactSchema = { ], }; -export const isChatReactProps = ajv.compile(ChatReactSchema); +export const isChatReactProps = ajv.compile(ChatReactSchema); /** * The param `ignore` cannot be boolean, since this is a GET method. Use strings 'true' or 'false' instead. @@ -311,7 +313,7 @@ const ChatIgnoreUserSchema = { additionalProperties: false, }; -export const isChatIgnoreUserProps = ajv.compile(ChatIgnoreUserSchema); +export const isChatIgnoreUserProps = ajv.compile(ChatIgnoreUserSchema); type ChatSearch = { roomId: IRoom['_id']; @@ -340,7 +342,7 @@ const ChatSearchSchema = { additionalProperties: false, }; -export const isChatSearchProps = ajv.compile(ChatSearchSchema); +export const isChatSearchProps = ajv.compile(ChatSearchSchema); type ChatUpdate = { roomId: IRoom['_id']; @@ -365,7 +367,7 @@ const ChatUpdateSchema = { additionalProperties: false, }; -export const isChatUpdateProps = ajv.compile(ChatUpdateSchema); +export const isChatUpdateProps = ajv.compile(ChatUpdateSchema); type ChatGetMessageReadReceipts = { messageId: IMessage['_id']; @@ -382,7 +384,7 @@ const ChatGetMessageReadReceiptsSchema = { additionalProperties: false, }; -export const isChatGetMessageReadReceiptsProps = ajv.compile(ChatGetMessageReadReceiptsSchema); +export const isChatGetMessageReadReceiptsProps = ajv.compile(ChatGetMessageReadReceiptsSchema); export type ChatEndpoints = { 'chat.getMessage': { diff --git a/packages/rest-typings/src/v1/cloud.ts b/packages/rest-typings/src/v1/cloud.ts index 9f0b8fc415f9..59d1986700d6 100644 --- a/packages/rest-typings/src/v1/cloud.ts +++ b/packages/rest-typings/src/v1/cloud.ts @@ -1,7 +1,9 @@ import type { CloudRegistrationIntentData, CloudConfirmationPollData, CloudRegistrationStatus } from '@rocket.chat/core-typings'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type CloudManualRegister = { cloudBlob: string; @@ -18,7 +20,7 @@ const CloudManualRegisterSchema = { additionalProperties: false, }; -export const isCloudManualRegisterProps = ajv.compile(CloudManualRegisterSchema); +export const isCloudManualRegisterProps = ajv.compile(CloudManualRegisterSchema); type CloudCreateRegistrationIntent = { resend: boolean; @@ -39,7 +41,7 @@ const CloudCreateRegistrationIntentSchema = { additionalProperties: false, }; -export const isCloudCreateRegistrationIntentProps = ajv.compile(CloudCreateRegistrationIntentSchema); +export const isCloudCreateRegistrationIntentProps = ajv.compile(CloudCreateRegistrationIntentSchema); type CloudConfirmationPoll = { deviceCode: string; @@ -61,7 +63,7 @@ const CloudConfirmationPollSchema = { additionalProperties: false, }; -export const isCloudConfirmationPollProps = ajv.compile(CloudConfirmationPollSchema); +export const isCloudConfirmationPollProps = ajv.compile(CloudConfirmationPollSchema); export type CloudEndpoints = { 'cloud.manualRegister': { diff --git a/packages/rest-typings/src/v1/customSounds.ts b/packages/rest-typings/src/v1/customSounds.ts index 8b33503d37ed..7285180f5a26 100644 --- a/packages/rest-typings/src/v1/customSounds.ts +++ b/packages/rest-typings/src/v1/customSounds.ts @@ -3,7 +3,9 @@ import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type CustomSoundsList = PaginatedRequest<{ query: string }>; @@ -30,7 +32,7 @@ const CustomSoundsListSchema = { additionalProperties: false, }; -export const isCustomSoundsListProps = ajv.compile(CustomSoundsListSchema); +export const isCustomSoundsListProps = ajv.compile(CustomSoundsListSchema); export type CustomSoundEndpoint = { 'custom-sounds.list': { From 3ba3bf50539bc5e6cbadd9dbfb8293fd2bdab827 Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 1 Jun 2022 21:23:29 -0300 Subject: [PATCH 12/18] add more Ajv compile types --- .../rest-typings/src/v1/customUserStatus.ts | 6 +- packages/rest-typings/src/v1/directory.ts | 6 +- packages/rest-typings/src/v1/dns.ts | 8 +- packages/rest-typings/src/v1/e2e.ts | 12 +- packages/rest-typings/src/v1/email-inbox.ts | 10 +- packages/rest-typings/src/v1/emojiCustom.ts | 8 +- packages/rest-typings/src/v1/groups.ts | 30 +++-- packages/rest-typings/src/v1/invites.ts | 8 +- packages/rest-typings/src/v1/ldap.ts | 6 +- packages/rest-typings/src/v1/licenses.ts | 6 +- packages/rest-typings/src/v1/oauthapps.ts | 4 +- packages/rest-typings/src/v1/omnichannel.ts | 62 +++++---- packages/rest-typings/src/v1/permissions.ts | 8 +- packages/rest-typings/src/v1/push.ts | 8 +- packages/rest-typings/src/v1/roles.ts | 16 ++- packages/rest-typings/src/v1/rooms.ts | 30 +++-- packages/rest-typings/src/v1/statistics.ts | 8 +- packages/rest-typings/src/v1/users.ts | 126 +++++++++++++++++- .../rest-typings/src/v1/videoConference.ts | 28 +++- 19 files changed, 288 insertions(+), 102 deletions(-) diff --git a/packages/rest-typings/src/v1/customUserStatus.ts b/packages/rest-typings/src/v1/customUserStatus.ts index f410a64a165e..46c056c1e4f2 100644 --- a/packages/rest-typings/src/v1/customUserStatus.ts +++ b/packages/rest-typings/src/v1/customUserStatus.ts @@ -4,7 +4,9 @@ import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type CustomUserStatusListProps = PaginatedRequest<{ query: string }>; @@ -31,7 +33,7 @@ const CustomUserStatusListSchema = { additionalProperties: false, }; -export const isCustomUserStatusListProps = ajv.compile(CustomUserStatusListSchema); +export const isCustomUserStatusListProps = ajv.compile(CustomUserStatusListSchema); export type CustomUserStatusEndpoints = { 'custom-user-status.list': { diff --git a/packages/rest-typings/src/v1/directory.ts b/packages/rest-typings/src/v1/directory.ts index e897fd318b89..af0ad5be6d8d 100644 --- a/packages/rest-typings/src/v1/directory.ts +++ b/packages/rest-typings/src/v1/directory.ts @@ -4,7 +4,9 @@ import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type DirectoryProps = PaginatedRequest<{}>; @@ -31,7 +33,7 @@ const DirectorySchema = { additionalProperties: false, }; -export const isDirectoryProps = ajv.compile(DirectorySchema); +export const isDirectoryProps = ajv.compile(DirectorySchema); export type DirectoryEndpoint = { directory: { diff --git a/packages/rest-typings/src/v1/dns.ts b/packages/rest-typings/src/v1/dns.ts index 7b263f153f8b..28a630ea3352 100644 --- a/packages/rest-typings/src/v1/dns.ts +++ b/packages/rest-typings/src/v1/dns.ts @@ -1,6 +1,8 @@ import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type DnsResolveTxtProps = { url: string; @@ -17,7 +19,7 @@ const dnsResolveTxtPropsSchema = { additionalProperties: false, }; -export const isDnsResolveTxtProps = ajv.compile(dnsResolveTxtPropsSchema); +export const isDnsResolveTxtProps = ajv.compile(dnsResolveTxtPropsSchema); type DnsResolveSrvProps = { url: string; @@ -34,7 +36,7 @@ const DnsResolveSrvSchema = { additionalProperties: false, }; -export const isDnsResolveSrvProps = ajv.compile(DnsResolveSrvSchema); +export const isDnsResolveSrvProps = ajv.compile(DnsResolveSrvSchema); export type DnsEndpoints = { 'dns.resolve.srv': { diff --git a/packages/rest-typings/src/v1/e2e.ts b/packages/rest-typings/src/v1/e2e.ts index 80fc7b0e7b99..62ce4110ddbb 100644 --- a/packages/rest-typings/src/v1/e2e.ts +++ b/packages/rest-typings/src/v1/e2e.ts @@ -2,7 +2,9 @@ import type { IUser } from '@rocket.chat/core-typings'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type E2eSetUserPublicAndPrivateKeysProps = { public_key: string; @@ -23,7 +25,7 @@ const E2eSetUserPublicAndPrivateKeysSchema = { additionalProperties: false, }; -export const isE2eSetUserPublicAndPrivateKeysProps = ajv.compile(E2eSetUserPublicAndPrivateKeysSchema); +export const isE2eSetUserPublicAndPrivateKeysProps = ajv.compile(E2eSetUserPublicAndPrivateKeysSchema); type E2eGetUsersOfRoomWithoutKeyProps = { rid: string }; @@ -38,7 +40,7 @@ const E2eGetUsersOfRoomWithoutKeySchema = { additionalProperties: false, }; -export const isE2eGetUsersOfRoomWithoutKeyProps = ajv.compile(E2eGetUsersOfRoomWithoutKeySchema); +export const isE2eGetUsersOfRoomWithoutKeyProps = ajv.compile(E2eGetUsersOfRoomWithoutKeySchema); type E2eUpdateGroupKeyProps = { uid: string; @@ -63,7 +65,7 @@ const E2eUpdateGroupKeySchema = { additionalProperties: false, }; -export const isE2eUpdateGroupKeyProps = ajv.compile(E2eUpdateGroupKeySchema); +export const isE2eUpdateGroupKeyProps = ajv.compile(E2eUpdateGroupKeySchema); type E2eSetRoomKeyIdProps = { rid: string; @@ -84,7 +86,7 @@ const E2eSetRoomKeyIdSchema = { additionalProperties: false, }; -export const isE2eSetRoomKeyIdProps = ajv.compile(E2eSetRoomKeyIdSchema); +export const isE2eSetRoomKeyIdProps = ajv.compile(E2eSetRoomKeyIdSchema); export type E2eEndpoints = { 'e2e.setUserPublicAndPrivateKeys': { diff --git a/packages/rest-typings/src/v1/email-inbox.ts b/packages/rest-typings/src/v1/email-inbox.ts index 7b0c524bdac3..d0347fe7e829 100644 --- a/packages/rest-typings/src/v1/email-inbox.ts +++ b/packages/rest-typings/src/v1/email-inbox.ts @@ -4,7 +4,9 @@ import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type EmailInboxListProps = PaginatedRequest<{ query?: string }>; @@ -32,7 +34,7 @@ const EmailInboxListPropsSchema = { additionalProperties: false, }; -export const isEmailInboxList = ajv.compile(EmailInboxListPropsSchema); +export const isEmailInboxList = ajv.compile(EmailInboxListPropsSchema); type EmailInboxProps = { _id?: string; @@ -135,7 +137,7 @@ const EmailInboxPropsSchema = { additionalProperties: false, }; -export const isEmailInbox = ajv.compile(EmailInboxPropsSchema); +export const isEmailInbox = ajv.compile(EmailInboxPropsSchema); type EmailInboxSearchProps = { email: string; @@ -152,7 +154,7 @@ const EmailInboxSearchPropsSchema = { additionalProperties: false, }; -export const isEmailInboxSearch = ajv.compile(EmailInboxSearchPropsSchema); +export const isEmailInboxSearch = ajv.compile(EmailInboxSearchPropsSchema); export type EmailInboxEndpoints = { 'email-inbox.list': { diff --git a/packages/rest-typings/src/v1/emojiCustom.ts b/packages/rest-typings/src/v1/emojiCustom.ts index c4ce2fb5792c..2532879dd9a9 100644 --- a/packages/rest-typings/src/v1/emojiCustom.ts +++ b/packages/rest-typings/src/v1/emojiCustom.ts @@ -4,7 +4,9 @@ import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type emojiCustomDeleteProps = { emojiId: ICustomEmojiDescriptor['_id']; @@ -21,7 +23,7 @@ const emojiCustomDeletePropsSchema = { additionalProperties: false, }; -export const isEmojiCustomDelete = ajv.compile(emojiCustomDeletePropsSchema); +export const isEmojiCustomDelete = ajv.compile(emojiCustomDeletePropsSchema); type emojiCustomList = { query: string; @@ -38,7 +40,7 @@ const emojiCustomListSchema = { additionalProperties: false, }; -export const isemojiCustomList = ajv.compile(emojiCustomListSchema); +export const isemojiCustomList = ajv.compile(emojiCustomListSchema); export type EmojiCustomEndpoints = { 'emoji-custom.all': { diff --git a/packages/rest-typings/src/v1/groups.ts b/packages/rest-typings/src/v1/groups.ts index 543037af2df6..10540a3ecd62 100644 --- a/packages/rest-typings/src/v1/groups.ts +++ b/packages/rest-typings/src/v1/groups.ts @@ -4,7 +4,9 @@ import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type GroupsFilesProps = { roomId: IRoom['_id']; @@ -33,7 +35,7 @@ const GroupsFilesPropsSchema = { additionalProperties: false, }; -export const isGroupsFilesProps = ajv.compile(GroupsFilesPropsSchema); +export const isGroupsFilesProps = ajv.compile(GroupsFilesPropsSchema); type GroupsMembersProps = { roomId: IRoom['_id']; @@ -71,7 +73,7 @@ const GroupsMembersPropsSchema = { additionalProperties: false, }; -export const isGroupsMembersProps = ajv.compile(GroupsMembersPropsSchema); +export const isGroupsMembersProps = ajv.compile(GroupsMembersPropsSchema); type GroupsArchiveProps = { roomId: IRoom['_id']; @@ -88,7 +90,7 @@ const GroupsArchivePropsSchema = { additionalProperties: false, }; -export const isGroupsArchiveProps = ajv.compile(GroupsArchivePropsSchema); +export const isGroupsArchiveProps = ajv.compile(GroupsArchivePropsSchema); type GroupsUnarchiveProps = { roomId: IRoom['_id']; @@ -105,7 +107,7 @@ const GroupsUnarchivePropsSchema = { additionalProperties: false, }; -export const isGroupsUnarchiveProps = ajv.compile(GroupsUnarchivePropsSchema); +export const isGroupsUnarchiveProps = ajv.compile(GroupsUnarchivePropsSchema); type GroupsCreateProps = { name: string; @@ -153,7 +155,7 @@ const GroupsCreatePropsSchema = { additionalProperties: false, }; -export const isGroupsCreateProps = ajv.compile(GroupsCreatePropsSchema); +export const isGroupsCreateProps = ajv.compile(GroupsCreatePropsSchema); type GroupsConvertToTeamProps = { roomId: string; @@ -174,7 +176,7 @@ const GroupsConvertToTeamPropsSchema = { additionalProperties: false, }; -export const isGroupsConvertToTeamProps = ajv.compile(GroupsConvertToTeamPropsSchema); +export const isGroupsConvertToTeamProps = ajv.compile(GroupsConvertToTeamPropsSchema); type GroupsCountersProps = { roomId: string; @@ -191,7 +193,7 @@ const GroupsCountersPropsSchema = { additionalProperties: false, }; -export const isGroupsCountersProps = ajv.compile(GroupsCountersPropsSchema); +export const isGroupsCountersProps = ajv.compile(GroupsCountersPropsSchema); type GroupsCloseProps = { roomId: string; @@ -208,7 +210,7 @@ const GroupsClosePropsSchema = { additionalProperties: false, }; -export const isGroupsCloseProps = ajv.compile(GroupsClosePropsSchema); +export const isGroupsCloseProps = ajv.compile(GroupsClosePropsSchema); type GroupsDeleteProps = { roomId: string; @@ -225,7 +227,7 @@ const GroupsDeletePropsSchema = { additionalProperties: false, }; -export const isGroupsDeleteProps = ajv.compile(GroupsDeletePropsSchema); +export const isGroupsDeleteProps = ajv.compile(GroupsDeletePropsSchema); type GroupsLeaveProps = { roomId: string; @@ -242,7 +244,7 @@ const GroupsLeavePropsSchema = { additionalProperties: false, }; -export const isGroupsLeaveProps = ajv.compile(GroupsLeavePropsSchema); +export const isGroupsLeaveProps = ajv.compile(GroupsLeavePropsSchema); type GroupsRolesProps = { roomId: string; @@ -259,7 +261,7 @@ const GroupsRolesPropsSchema = { additionalProperties: false, }; -export const isGroupsRolesProps = ajv.compile(GroupsRolesPropsSchema); +export const isGroupsRolesProps = ajv.compile(GroupsRolesPropsSchema); type GroupsKickProps = { roomId: string; @@ -280,7 +282,7 @@ const GroupsKickPropsSchema = { additionalProperties: false, }; -export const isGroupsKickProps = ajv.compile(GroupsKickPropsSchema); +export const isGroupsKickProps = ajv.compile(GroupsKickPropsSchema); type GroupsMessageProps = PaginatedRequest<{ roomId: IRoom['_id']; @@ -313,7 +315,7 @@ const GroupsMessagePropsSchema = { additionalProperties: false, }; -export const isGroupsMessageProps = ajv.compile(GroupsMessagePropsSchema); +export const isGroupsMessageProps = ajv.compile(GroupsMessagePropsSchema); export type GroupsEndpoints = { 'groups.files': { diff --git a/packages/rest-typings/src/v1/invites.ts b/packages/rest-typings/src/v1/invites.ts index 0ebae2a6e48b..fda658af2267 100644 --- a/packages/rest-typings/src/v1/invites.ts +++ b/packages/rest-typings/src/v1/invites.ts @@ -1,7 +1,9 @@ import type { IInvite, IRoom } from '@rocket.chat/core-typings'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type v1UseInviteTokenProps = { token: string; @@ -18,7 +20,7 @@ const v1UseInviteTokenPropsSchema = { additionalProperties: false, }; -export const isV1UseInviteTokenProps = ajv.compile(v1UseInviteTokenPropsSchema); +export const isV1UseInviteTokenProps = ajv.compile(v1UseInviteTokenPropsSchema); type v1ValidateInviteTokenProps = { token: string; @@ -35,7 +37,7 @@ const v1ValidateInviteTokenPropsSchema = { additionalProperties: false, }; -export const isV1ValidateInviteTokenProps = ajv.compile(v1ValidateInviteTokenPropsSchema); +export const isV1ValidateInviteTokenProps = ajv.compile(v1ValidateInviteTokenPropsSchema); export type InvitesEndpoints = { 'listInvites': { diff --git a/packages/rest-typings/src/v1/ldap.ts b/packages/rest-typings/src/v1/ldap.ts index 36ee55ceb8a3..3fd343cf4c03 100644 --- a/packages/rest-typings/src/v1/ldap.ts +++ b/packages/rest-typings/src/v1/ldap.ts @@ -1,6 +1,8 @@ import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type ldapTestSearchProps = { username: string; @@ -17,7 +19,7 @@ const ldapTestSearchPropsSchema = { additionalProperties: false, }; -export const isLdapTestSearch = ajv.compile(ldapTestSearchPropsSchema); +export const isLdapTestSearch = ajv.compile(ldapTestSearchPropsSchema); export type LDAPEndpoints = { 'ldap.testConnection': { diff --git a/packages/rest-typings/src/v1/licenses.ts b/packages/rest-typings/src/v1/licenses.ts index 763a6ac6184f..de477d37a813 100644 --- a/packages/rest-typings/src/v1/licenses.ts +++ b/packages/rest-typings/src/v1/licenses.ts @@ -1,7 +1,9 @@ import type { ILicense } from '@rocket.chat/core-typings'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type licensesAddProps = { license: string; @@ -18,7 +20,7 @@ const licensesAddPropsSchema = { additionalProperties: false, }; -export const isLicensesAddProps = ajv.compile(licensesAddPropsSchema); +export const isLicensesAddProps = ajv.compile(licensesAddPropsSchema); export type LicensesEndpoints = { 'licenses.get': { diff --git a/packages/rest-typings/src/v1/oauthapps.ts b/packages/rest-typings/src/v1/oauthapps.ts index 89f993d50b21..4928257efd1e 100644 --- a/packages/rest-typings/src/v1/oauthapps.ts +++ b/packages/rest-typings/src/v1/oauthapps.ts @@ -1,7 +1,9 @@ import type { IOAuthApps, IUser } from '@rocket.chat/core-typings'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); export type OauthAppsGetParams = { clientId: string } | { appId: string }; diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index c983fbef250b..93598fd978a1 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -20,7 +20,9 @@ import type { PaginatedResult } from '../helpers/PaginatedResult'; type booleanString = 'true' | 'false'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type LivechatVisitorsInfo = { visitorId: string; @@ -37,7 +39,7 @@ const LivechatVisitorsInfoSchema = { additionalProperties: false, }; -export const isLivechatVisitorsInfoProps = ajv.compile(LivechatVisitorsInfoSchema); +export const isLivechatVisitorsInfoProps = ajv.compile(LivechatVisitorsInfoSchema); type LivechatRoomOnHold = { roomId: IRoom['_id']; @@ -54,7 +56,7 @@ const LivechatRoomOnHoldSchema = { additionalProperties: false, }; -export const isLivechatRoomOnHoldProps = ajv.compile(LivechatRoomOnHoldSchema); +export const isLivechatRoomOnHoldProps = ajv.compile(LivechatRoomOnHoldSchema); type LivechatDepartmentId = { onlyMyDepartments?: booleanString; @@ -76,7 +78,7 @@ const LivechatDepartmentIdSchema = { additionalProperties: false, }; -export const isLivechatDepartmentIdProps = ajv.compile(LivechatDepartmentIdSchema); +export const isLivechatDepartmentIdProps = ajv.compile(LivechatDepartmentIdSchema); type LivechatDepartmentAutocomplete = { selector: string; @@ -97,7 +99,7 @@ const LivechatDepartmentAutocompleteSchema = { additionalProperties: false, }; -export const isLivechatDepartmentAutocompleteProps = ajv.compile(LivechatDepartmentAutocompleteSchema); +export const isLivechatDepartmentAutocompleteProps = ajv.compile(LivechatDepartmentAutocompleteSchema); type LivechatDepartmentDepartmentIdAgentsGET = { sort: string; @@ -114,7 +116,9 @@ const LivechatDepartmentDepartmentIdAgentsGETSchema = { additionalProperties: false, }; -export const isLivechatDepartmentDepartmentIdAgentsGETProps = ajv.compile(LivechatDepartmentDepartmentIdAgentsGETSchema); +export const isLivechatDepartmentDepartmentIdAgentsGETProps = ajv.compile( + LivechatDepartmentDepartmentIdAgentsGETSchema, +); type LivechatDepartmentDepartmentIdAgentsPOST = { upsert: string[]; @@ -141,7 +145,9 @@ const LivechatDepartmentDepartmentIdAgentsPOSTSchema = { additionalProperties: false, }; -export const isLivechatDepartmentDepartmentIdAgentsPOSTProps = ajv.compile(LivechatDepartmentDepartmentIdAgentsPOSTSchema); +export const isLivechatDepartmentDepartmentIdAgentsPOSTProps = ajv.compile( + LivechatDepartmentDepartmentIdAgentsPOSTSchema, +); type LivechatVisitorTokenGet = { token: string; @@ -158,7 +164,7 @@ const LivechatVisitorTokenGetSchema = { additionalProperties: false, }; -export const isLivechatVisitorTokenGetProps = ajv.compile(LivechatVisitorTokenGetSchema); +export const isLivechatVisitorTokenGetProps = ajv.compile(LivechatVisitorTokenGetSchema); type LivechatVisitorTokenDelete = { token: string; @@ -175,7 +181,7 @@ const LivechatVisitorTokenDeleteSchema = { additionalProperties: false, }; -export const isLivechatVisitorTokenDeleteProps = ajv.compile(LivechatVisitorTokenDeleteSchema); +export const isLivechatVisitorTokenDeleteProps = ajv.compile(LivechatVisitorTokenDeleteSchema); type LivechatVisitorTokenRoom = { token: string; @@ -192,7 +198,7 @@ const LivechatVisitorTokenRoomSchema = { additionalProperties: false, }; -export const isLivechatVisitorTokenRoomProps = ajv.compile(LivechatVisitorTokenRoomSchema); +export const isLivechatVisitorTokenRoomProps = ajv.compile(LivechatVisitorTokenRoomSchema); type LivechatVisitorCallStatus = { token: string; @@ -221,7 +227,7 @@ const LivechatVisitorCallStatusSchema = { additionalProperties: false, }; -export const isLivechatVisitorCallStatusProps = ajv.compile(LivechatVisitorCallStatusSchema); +export const isLivechatVisitorCallStatusProps = ajv.compile(LivechatVisitorCallStatusSchema); type LivechatVisitorStatus = { token: string; @@ -242,7 +248,7 @@ const LivechatVisitorStatusSchema = { additionalProperties: false, }; -export const isLivechatVisitorStatusProps = ajv.compile(LivechatVisitorStatusSchema); +export const isLivechatVisitorStatusProps = ajv.compile(LivechatVisitorStatusSchema); type LiveChatRoomJoin = { roomId: string; @@ -259,7 +265,7 @@ const LiveChatRoomJoinSchema = { additionalProperties: false, }; -export const isLiveChatRoomJoinProps = ajv.compile(LiveChatRoomJoinSchema); +export const isLiveChatRoomJoinProps = ajv.compile(LiveChatRoomJoinSchema); type LivechatMonitorsListProps = PaginatedRequest<{ text: string }>; @@ -290,7 +296,7 @@ const LivechatMonitorsListSchema = { additionalProperties: false, }; -export const isLivechatMonitorsListProps = ajv.compile(LivechatMonitorsListSchema); +export const isLivechatMonitorsListProps = ajv.compile(LivechatMonitorsListSchema); type LivechatTagsListProps = PaginatedRequest<{ text: string }, 'name'>; @@ -321,7 +327,7 @@ const LivechatTagsListSchema = { additionalProperties: false, }; -export const isLivechatTagsListProps = ajv.compile(LivechatTagsListSchema); +export const isLivechatTagsListProps = ajv.compile(LivechatTagsListSchema); type LivechatDepartmentProps = PaginatedRequest<{ text: string; @@ -369,7 +375,7 @@ const LivechatDepartmentSchema = { additionalProperties: false, }; -export const isLivechatDepartmentProps = ajv.compile(LivechatDepartmentSchema); +export const isLivechatDepartmentProps = ajv.compile(LivechatDepartmentSchema); type LivechatDepartmentsAvailableByUnitIdProps = PaginatedRequest<{ text: string }>; @@ -400,7 +406,9 @@ const LivechatDepartmentsAvailableByUnitIdSchema = { additionalProperties: false, }; -export const isLivechatDepartmentsAvailableByUnitIdProps = ajv.compile(LivechatDepartmentsAvailableByUnitIdSchema); +export const isLivechatDepartmentsAvailableByUnitIdProps = ajv.compile( + LivechatDepartmentsAvailableByUnitIdSchema, +); type LivechatDepartmentsByUnitProps = PaginatedRequest<{ text: string }>; @@ -431,7 +439,7 @@ const LivechatDepartmentsByUnitSchema = { additionalProperties: false, }; -export const isLivechatDepartmentsByUnitProps = ajv.compile(LivechatDepartmentsByUnitSchema); +export const isLivechatDepartmentsByUnitProps = ajv.compile(LivechatDepartmentsByUnitSchema); type LivechatDepartmentsByUnitIdProps = PaginatedRequest<{ text: string }>; @@ -462,7 +470,7 @@ const LivechatDepartmentsByUnitIdSchema = { additionalProperties: false, }; -export const isLivechatDepartmentsByUnitIdProps = ajv.compile(LivechatDepartmentsByUnitIdSchema); +export const isLivechatDepartmentsByUnitIdProps = ajv.compile(LivechatDepartmentsByUnitIdSchema); type LivechatUsersManagerGETProps = PaginatedRequest<{ text?: string }>; @@ -494,7 +502,7 @@ const LivechatUsersManagerGETSchema = { additionalProperties: false, }; -export const isLivechatUsersManagerGETProps = ajv.compile(LivechatUsersManagerGETSchema); +export const isLivechatUsersManagerGETProps = ajv.compile(LivechatUsersManagerGETSchema); type LivechatUsersManagerPOSTProps = PaginatedRequest<{ username: string }>; @@ -525,7 +533,7 @@ const LivechatUsersManagerPOSTSchema = { additionalProperties: false, }; -export const isLivechatUsersManagerPOSTProps = ajv.compile(LivechatUsersManagerPOSTSchema); +export const isLivechatUsersManagerPOSTProps = ajv.compile(LivechatUsersManagerPOSTSchema); type LivechatQueueProps = { agentId?: string; @@ -565,7 +573,7 @@ const LivechatQueuePropsSchema = { additionalProperties: false, }; -export const isLivechatQueueProps = ajv.compile(LivechatQueuePropsSchema); +export const isLivechatQueueProps = ajv.compile(LivechatQueuePropsSchema); type CannedResponsesProps = PaginatedRequest<{ scope?: string; @@ -608,7 +616,7 @@ const CannedResponsesPropsSchema = { additionalProperties: false, }; -export const isCannedResponsesProps = ajv.compile(CannedResponsesPropsSchema); +export const isCannedResponsesProps = ajv.compile(CannedResponsesPropsSchema); type LivechatCustomFieldsProps = PaginatedRequest<{ text: string }>; @@ -639,7 +647,7 @@ const LivechatCustomFieldsSchema = { additionalProperties: false, }; -export const isLivechatCustomFieldsProps = ajv.compile(LivechatCustomFieldsSchema); +export const isLivechatCustomFieldsProps = ajv.compile(LivechatCustomFieldsSchema); type LivechatRoomsProps = { guest: string; @@ -703,7 +711,7 @@ const LivechatRoomsSchema = { additionalProperties: false, }; -export const isLivechatRoomsProps = ajv.compile(LivechatRoomsSchema); +export const isLivechatRoomsProps = ajv.compile(LivechatRoomsSchema); type LivechatRidMessagesProps = PaginatedRequest<{ query: string }>; @@ -730,7 +738,7 @@ const LivechatRidMessagesSchema = { additionalProperties: false, }; -export const isLivechatRidMessagesProps = ajv.compile(LivechatRidMessagesSchema); +export const isLivechatRidMessagesProps = ajv.compile(LivechatRidMessagesSchema); type LivechatUsersAgentProps = PaginatedRequest<{ text?: string }>; @@ -762,7 +770,7 @@ const LivechatUsersAgentSchema = { additionalProperties: false, }; -export const isLivechatUsersAgentProps = ajv.compile(LivechatUsersAgentSchema); +export const isLivechatUsersAgentProps = ajv.compile(LivechatUsersAgentSchema); export type OmnichannelEndpoints = { 'livechat/appearance': { diff --git a/packages/rest-typings/src/v1/permissions.ts b/packages/rest-typings/src/v1/permissions.ts index 6518ea317e86..3128db4ec259 100644 --- a/packages/rest-typings/src/v1/permissions.ts +++ b/packages/rest-typings/src/v1/permissions.ts @@ -1,7 +1,9 @@ import Ajv from 'ajv'; import type { IPermission } from '@rocket.chat/core-typings'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type PermissionsListAllProps = { updatedSince?: string; @@ -19,7 +21,7 @@ const permissionListAllSchema = { additionalProperties: false, }; -export const isPermissionsListAll = ajv.compile(permissionListAllSchema); +export const isPermissionsListAll = ajv.compile(permissionListAllSchema); type PermissionsUpdateProps = { permissions: { _id: string; roles: string[] }[]; @@ -49,7 +51,7 @@ const permissionUpdatePropsSchema = { additionalProperties: false, }; -export const isBodyParamsValidPermissionUpdate = ajv.compile(permissionUpdatePropsSchema); +export const isBodyParamsValidPermissionUpdate = ajv.compile(permissionUpdatePropsSchema); export type PermissionsEndpoints = { 'permissions.listAll': { diff --git a/packages/rest-typings/src/v1/push.ts b/packages/rest-typings/src/v1/push.ts index 25830fc67e23..54568328bc42 100644 --- a/packages/rest-typings/src/v1/push.ts +++ b/packages/rest-typings/src/v1/push.ts @@ -1,7 +1,9 @@ import type { IMessage, IPushNotificationConfig, IPushTokenTypes, IPushToken } from '@rocket.chat/core-typings'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type PushTokenProps = { id?: string; @@ -31,7 +33,7 @@ const PushTokenPropsSchema = { additionalProperties: false, }; -export const isPushTokenProps = ajv.compile(PushTokenPropsSchema); +export const isPushTokenProps = ajv.compile(PushTokenPropsSchema); type PushGetProps = { id: string; @@ -48,7 +50,7 @@ const PushGetPropsSchema = { additionalProperties: false, }; -export const isPushGetProps = ajv.compile(PushGetPropsSchema); +export const isPushGetProps = ajv.compile(PushGetPropsSchema); export type PushEndpoints = { 'push.token': { diff --git a/packages/rest-typings/src/v1/roles.ts b/packages/rest-typings/src/v1/roles.ts index 03023ae0376a..8c4135fc4b5b 100644 --- a/packages/rest-typings/src/v1/roles.ts +++ b/packages/rest-typings/src/v1/roles.ts @@ -3,7 +3,9 @@ import type { RocketChatRecordDeleted, IRole, IUserInRole } from '@rocket.chat/c import type { PaginatedRequest } from '../helpers/PaginatedRequest'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type RoleCreateProps = Pick & Partial>; @@ -31,7 +33,7 @@ const roleCreatePropsSchema = { additionalProperties: false, }; -export const isRoleCreateProps = ajv.compile(roleCreatePropsSchema); +export const isRoleCreateProps = ajv.compile(roleCreatePropsSchema); type RoleUpdateProps = { roleId: IRole['_id']; @@ -65,7 +67,7 @@ const roleUpdatePropsSchema = { additionalProperties: false, }; -export const isRoleUpdateProps = ajv.compile(roleUpdatePropsSchema); +export const isRoleUpdateProps = ajv.compile(roleUpdatePropsSchema); type RoleDeleteProps = { roleId: IRole['_id'] }; @@ -80,7 +82,7 @@ const roleDeletePropsSchema = { additionalProperties: false, }; -export const isRoleDeleteProps = ajv.compile(roleDeletePropsSchema); +export const isRoleDeleteProps = ajv.compile(roleDeletePropsSchema); type RoleAddUserToRoleProps = { username: string; @@ -113,7 +115,7 @@ const roleAddUserToRolePropsSchema = { additionalProperties: false, }; -export const isRoleAddUserToRoleProps = ajv.compile(roleAddUserToRolePropsSchema); +export const isRoleAddUserToRoleProps = ajv.compile(roleAddUserToRolePropsSchema); type RoleRemoveUserFromRoleProps = { username: string; @@ -151,7 +153,7 @@ const roleRemoveUserFromRolePropsSchema = { additionalProperties: false, }; -export const isRoleRemoveUserFromRoleProps = ajv.compile(roleRemoveUserFromRolePropsSchema); +export const isRoleRemoveUserFromRoleProps = ajv.compile(roleRemoveUserFromRolePropsSchema); type RolesGetUsersInRoleProps = PaginatedRequest<{ roomId?: string; @@ -189,7 +191,7 @@ const RolesGetUsersInRolePropsSchema = { additionalProperties: false, }; -export const isRolesGetUsersInRoleProps = ajv.compile(RolesGetUsersInRolePropsSchema); +export const isRolesGetUsersInRoleProps = ajv.compile(RolesGetUsersInRolePropsSchema); type RoleSyncProps = { updatedSince?: string; diff --git a/packages/rest-typings/src/v1/rooms.ts b/packages/rest-typings/src/v1/rooms.ts index adfc8d5d6f53..aca408dc1109 100644 --- a/packages/rest-typings/src/v1/rooms.ts +++ b/packages/rest-typings/src/v1/rooms.ts @@ -5,7 +5,9 @@ import Ajv from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type RoomsAutoCompleteChannelAndPrivateProps = { selector: string }; @@ -20,7 +22,9 @@ const RoomsAutoCompleteChannelAndPrivateSchema = { additionalProperties: false, }; -export const isRoomsAutoCompleteChannelAndPrivateProps = ajv.compile(RoomsAutoCompleteChannelAndPrivateSchema); +export const isRoomsAutoCompleteChannelAndPrivateProps = ajv.compile( + RoomsAutoCompleteChannelAndPrivateSchema, +); type RoomsAutocompleteChannelAndPrivateWithPaginationProps = PaginatedRequest<{ selector: string }>; @@ -51,7 +55,9 @@ const RoomsAutocompleteChannelAndPrivateWithPaginationSchema = { additionalProperties: false, }; -export const isRoomsAutocompleteChannelAndPrivateWithPaginationProps = ajv.compile(RoomsAutocompleteChannelAndPrivateWithPaginationSchema); +export const isRoomsAutocompleteChannelAndPrivateWithPaginationProps = ajv.compile( + RoomsAutocompleteChannelAndPrivateWithPaginationSchema, +); type RoomsAutocompleteAvailableForTeamsProps = { name: string }; @@ -66,7 +72,9 @@ const RoomsAutocompleteAvailableForTeamsSchema = { additionalProperties: false, }; -export const isRoomsAutocompleteAvailableForTeamsProps = ajv.compile(RoomsAutocompleteAvailableForTeamsSchema); +export const isRoomsAutocompleteAvailableForTeamsProps = ajv.compile( + RoomsAutocompleteAvailableForTeamsSchema, +); type RoomsInfoProps = { roomId: string } | { roomName: string }; @@ -95,7 +103,7 @@ const RoomsInfoSchema = { ], }; -export const isRoomsInfoProps = ajv.compile(RoomsInfoSchema); +export const isRoomsInfoProps = ajv.compile(RoomsInfoSchema); type RoomsCreateDiscussionProps = { prid: IRoom['_id']; @@ -140,7 +148,7 @@ const RoomsCreateDiscussionSchema = { additionalProperties: false, }; -export const isRoomsCreateDiscussionProps = ajv.compile(RoomsCreateDiscussionSchema); +export const isRoomsCreateDiscussionProps = ajv.compile(RoomsCreateDiscussionSchema); type RoomsExportProps = { rid: IRoom['_id']; @@ -211,7 +219,7 @@ const RoomsExportSchema = { additionalProperties: false, }; -export const isRoomsExportProps = ajv.compile(RoomsExportSchema); +export const isRoomsExportProps = ajv.compile(RoomsExportSchema); type RoomsAdminRoomsProps = PaginatedRequest<{ filter?: string; @@ -253,7 +261,7 @@ const RoomsAdminRoomsSchema = { additionalProperties: false, }; -export const isRoomsAdminRoomsProps = ajv.compile(RoomsAdminRoomsSchema); +export const isRoomsAdminRoomsProps = ajv.compile(RoomsAdminRoomsSchema); type RoomsAdminRoomsGetRoomProps = { rid?: string }; @@ -269,7 +277,7 @@ const RoomsAdminRoomsGetRoomSchema = { additionalProperties: false, }; -export const isRoomsAdminRoomsGetRoomProps = ajv.compile(RoomsAdminRoomsGetRoomSchema); +export const isRoomsAdminRoomsGetRoomProps = ajv.compile(RoomsAdminRoomsGetRoomSchema); type RoomsChangeArchivationStateProps = { rid: string; action?: string }; @@ -288,7 +296,7 @@ const RoomsChangeArchivationStateSchema = { additionalProperties: false, }; -export const isRoomsChangeArchivationStateProps = ajv.compile(RoomsChangeArchivationStateSchema); +export const isRoomsChangeArchivationStateProps = ajv.compile(RoomsChangeArchivationStateSchema); type RoomsSaveRoomSettingsProps = { rid: string; @@ -383,7 +391,7 @@ const RoomsSaveRoomSettingsSchema = { additionalProperties: false, }; -export const isRoomsSaveRoomSettingsProps = ajv.compile(RoomsSaveRoomSettingsSchema); +export const isRoomsSaveRoomSettingsProps = ajv.compile(RoomsSaveRoomSettingsSchema); export type RoomsEndpoints = { 'rooms.autocomplete.channelAndPrivate': { diff --git a/packages/rest-typings/src/v1/statistics.ts b/packages/rest-typings/src/v1/statistics.ts index aa1c7da43671..837bbf1afa0e 100644 --- a/packages/rest-typings/src/v1/statistics.ts +++ b/packages/rest-typings/src/v1/statistics.ts @@ -21,7 +21,9 @@ export type TelemetryPayload = { params: Param[]; }; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type StatisticsProps = { refresh?: 'true' | 'false' }; @@ -37,7 +39,7 @@ const StatisticsSchema = { additionalProperties: false, }; -export const isStatisticsProps = ajv.compile(StatisticsSchema); +export const isStatisticsProps = ajv.compile(StatisticsSchema); type StatisticsListProps = PaginatedRequest<{ fields?: string }>; @@ -69,7 +71,7 @@ const StatisticsListSchema = { additionalProperties: false, }; -export const isStatisticsListProps = ajv.compile(StatisticsListSchema); +export const isStatisticsListProps = ajv.compile(StatisticsListSchema); export type StatisticsEndpoints = { 'statistics': { diff --git a/packages/rest-typings/src/v1/users.ts b/packages/rest-typings/src/v1/users.ts index 0f9951f4dfec..4b311d1af3d2 100644 --- a/packages/rest-typings/src/v1/users.ts +++ b/packages/rest-typings/src/v1/users.ts @@ -1,26 +1,140 @@ import type { ITeam, IUser } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; + +const ajv = new Ajv({ + coerceTypes: true, +}); + +type UsersInfo = { userId?: IUser['_id']; userName?: IUser['username'] }; + +const UsersInfoSchema = { + type: 'object', + properties: { + userId: { + type: 'string', + nullable: true, + }, + userName: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isUsersInfoProps = ajv.compile(UsersInfoSchema); + +type Users2faSendEmailCode = { emailOrUsername: string }; + +const Users2faSendEmailCodeSchema = { + type: 'object', + properties: { + emailOrUsername: { + type: 'string', + }, + }, + required: ['emailOrUsername'], + additionalProperties: false, +}; + +export const isUsers2faSendEmailCodeProps = ajv.compile(Users2faSendEmailCodeSchema); + +type UsersAutocomplete = { selector: string }; + +const UsersAutocompleteSchema = { + type: 'object', + properties: { + selector: { + type: 'string', + }, + }, + required: ['selector'], + additionalProperties: false, +}; + +export const isUsersAutocompleteProps = ajv.compile(UsersAutocompleteSchema); + +type UsersListTeams = { userId: IUser['_id'] }; + +const UsersListTeamsSchema = { + type: 'object', + properties: { + userId: { + type: 'string', + }, + }, + required: ['userId'], + additionalProperties: false, +}; + +export const isUsersListTeamsProps = ajv.compile(UsersListTeamsSchema); + +type UsersSetAvatar = { userId?: IUser['_id']; username?: IUser['username']; avatarUrl?: string }; + +const UsersSetAvatarSchema = { + type: 'object', + properties: { + userId: { + type: 'string', + nullable: true, + }, + username: { + type: 'string', + nullable: true, + }, + avatarUrl: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isUsersSetAvatarProps = ajv.compile(UsersSetAvatarSchema); + +type UsersResetAvatar = { userId?: IUser['_id']; username?: IUser['username'] }; + +const UsersResetAvatarSchema = { + type: 'object', + properties: { + userId: { + type: 'string', + nullable: true, + }, + username: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isUsersResetAvatarProps = ajv.compile(UsersResetAvatarSchema); export type UsersEndpoints = { 'users.info': { - GET: (params: { userId?: IUser['_id']; userName?: IUser['username'] }) => { + GET: (params: UsersInfo) => { user: IUser; }; }; 'users.2fa.sendEmailCode': { - POST: (params: { emailOrUsername: string }) => void; + POST: (params: Users2faSendEmailCode) => void; }; 'users.autocomplete': { - GET: (params: { selector: string }) => { + GET: (params: UsersAutocomplete) => { items: Required>[]; }; }; 'users.listTeams': { - GET: (params: { userId: IUser['_id'] }) => { teams: Array }; + GET: (params: UsersListTeams) => { teams: Array }; }; 'users.setAvatar': { - POST: (params: { userId?: IUser['_id']; username?: IUser['username']; avatarUrl?: string }) => void; + POST: (params: UsersSetAvatar) => void; }; 'users.resetAvatar': { - POST: (params: { userId?: IUser['_id']; username?: IUser['username'] }) => void; + POST: (params: UsersResetAvatar) => void; }; }; diff --git a/packages/rest-typings/src/v1/videoConference.ts b/packages/rest-typings/src/v1/videoConference.ts index 4030043e2f02..c314e43deb6c 100644 --- a/packages/rest-typings/src/v1/videoConference.ts +++ b/packages/rest-typings/src/v1/videoConference.ts @@ -1,8 +1,34 @@ import type { IRoom } from '@rocket.chat/core-typings'; +import Ajv from 'ajv'; + +const ajv = new Ajv({ + coerceTypes: true, +}); + +type VideoConferenceJitsiUpdateTimeout = { roomId: IRoom['_id']; joiningNow?: boolean }; + +const VideoConferenceJitsiUpdateTimeoutSchema = { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + joiningNow: { + type: 'boolean', + nullable: true, + }, + }, + required: ['roomId'], + additionalProperties: false, +}; + +export const isVideoConferenceJitsiUpdateTimeoutProps = ajv.compile( + VideoConferenceJitsiUpdateTimeoutSchema, +); export type VideoConferenceEndpoints = { 'video-conference/jitsi.update-timeout': { - POST: (params: { roomId: IRoom['_id']; joiningNow?: boolean }) => { + POST: (params: VideoConferenceJitsiUpdateTimeout) => { jitsiTimeout: number; }; }; From cbe65a9432c9a944ec42e16007fad9d03b6cd1ee Mon Sep 17 00:00:00 2001 From: Felipe <84182706+felipe-rod123@users.noreply.github.com> Date: Wed, 1 Jun 2022 22:05:11 -0300 Subject: [PATCH 13/18] add voip.ts endpoint validations --- packages/rest-typings/src/v1/voip.ts | 520 +++++++++++++++++++++++++-- 1 file changed, 492 insertions(+), 28 deletions(-) diff --git a/packages/rest-typings/src/v1/voip.ts b/packages/rest-typings/src/v1/voip.ts index 5398586927a3..5abd3e26b9e8 100644 --- a/packages/rest-typings/src/v1/voip.ts +++ b/packages/rest-typings/src/v1/voip.ts @@ -8,72 +8,536 @@ import type { IVoipExtensionWithAgentInfo, IManagementServerConnectionStatus, IRegistrationInfo, - VoipClientEvents, + // VoipClientEvents, } from '@rocket.chat/core-typings'; +import { VoipClientEvents } from '@rocket.chat/core-typings'; +import Ajv, { JSONSchemaType } from 'ajv'; import type { PaginatedRequest } from '../helpers/PaginatedRequest'; import type { PaginatedResult } from '../helpers/PaginatedResult'; +const ajv = new Ajv({ + coerceTypes: true, +}); + +/** *************************************************/ +type CustomSoundsList = PaginatedRequest<{ query: string }>; + +const CustomSoundsListSchema: JSONSchemaType = { + type: 'object', + properties: { + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isCustomSoundsListProps = ajv.compile(CustomSoundsListSchema); +/** *************************************************/ + +type ConnectorExtensionGetRegistrationInfoByUserId = { id: string }; + +const ConnectorExtensionGetRegistrationInfoByUserIdSchema: JSONSchemaType = { + type: 'object', + properties: { + id: { + type: 'string', + }, + }, + required: ['id'], + additionalProperties: false, +}; + +export const isConnectorExtensionGetRegistrationInfoByUserIdProps = ajv.compile( + ConnectorExtensionGetRegistrationInfoByUserIdSchema, +); + +type VoipQueuesGetQueuedCallsForThisExtension = { extension: string }; + +const VoipQueuesGetQueuedCallsForThisExtensionSchema: JSONSchemaType = { + type: 'object', + properties: { + extension: { + type: 'string', + }, + }, + required: ['extension'], + additionalProperties: false, +}; + +export const isVoipQueuesGetQueuedCallsForThisExtensionProps = ajv.compile( + VoipQueuesGetQueuedCallsForThisExtensionSchema, +); + +type VoipQueuesGetMembershipSubscription = { extension: string }; + +const VoipQueuesGetMembershipSubscriptionSchema: JSONSchemaType = { + type: 'object', + properties: { + extension: { + type: 'string', + }, + }, + required: ['extension'], + additionalProperties: false, +}; + +export const isVoipQueuesGetMembershipSubscriptionProps = ajv.compile( + VoipQueuesGetMembershipSubscriptionSchema, +); + +type OmnichannelExtensions = PaginatedRequest<{ + status?: string; + agentId?: string; + queues?: string[]; + extension?: string; +}>; + +const OmnichannelExtensionsSchema: JSONSchemaType = { + type: 'object', + properties: { + status: { + type: 'string', + nullable: true, + }, + agentId: { + type: 'string', + nullable: true, + }, + queues: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + extension: { + type: 'string', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isOmnichannelExtensionsProps = ajv.compile(OmnichannelExtensionsSchema); + +type OmnichannelExtension = + | { + userId: string; + type: 'free' | 'allocated' | 'available'; + } + | { + username: string; + type: 'free' | 'allocated' | 'available'; + }; + +const OmnichannelExtensionSchema: JSONSchemaType = { + oneOf: [ + { + type: 'object', + properties: { + userId: { + type: 'string', + }, + type: { + type: 'string', + enum: ['free', 'allocated', 'available'], + }, + }, + required: ['userId', 'type'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + username: { + type: 'string', + }, + type: { + type: 'string', + enum: ['free', 'allocated', 'available'], + }, + }, + required: ['username', 'type'], + additionalProperties: false, + }, + ], +}; + +export const isOmnichannelExtensionProps = ajv.compile(OmnichannelExtensionSchema); + +type OmnichannelAgentExtensionGET = { username: string }; + +const OmnichannelAgentExtensionGETSchema: JSONSchemaType = { + type: 'object', + properties: { + username: { + type: 'string', + }, + }, + required: ['username'], + additionalProperties: false, +}; + +export const isOmnichannelAgentExtensionGETProps = ajv.compile(OmnichannelAgentExtensionGETSchema); + +type OmnichannelAgentExtensionPOST = { userId: string; extension: string } | { username: string; extension: string }; + +const OmnichannelAgentExtensionPOSTSchema: JSONSchemaType = { + oneOf: [ + { + type: 'object', + properties: { + userId: { + type: 'string', + }, + extension: { + type: 'string', + }, + }, + required: ['userId', 'extension'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + username: { + type: 'string', + }, + extension: { + type: 'string', + }, + }, + required: ['username', 'extension'], + additionalProperties: false, + }, + ], +}; + +export const isOmnichannelAgentExtensionPOSTProps = ajv.compile(OmnichannelAgentExtensionPOSTSchema); + +type OmnichannelAgentExtensionDELETE = { username: string }; + +const OmnichannelAgentExtensionDELETESchema: JSONSchemaType = { + type: 'object', + properties: { + username: { + type: 'string', + }, + }, + required: ['username'], + additionalProperties: false, +}; + +export const isOmnichannelAgentExtensionDELETEProps = ajv.compile(OmnichannelAgentExtensionDELETESchema); + +type OmnichannelAgentsAvailable = PaginatedRequest<{ text?: string; includeExtension?: string }>; + +const OmnichannelAgentsAvailableSchema: JSONSchemaType = { + type: 'object', + properties: { + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, + text: { + type: 'string', + nullable: true, + }, + includeExtension: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isOmnichannelAgentsAvailableProps = ajv.compile(OmnichannelAgentsAvailableSchema); + +type VoipEvents = { event: VoipClientEvents; rid: string; comment?: string }; + +const VoipEventsSchema: JSONSchemaType = { + type: 'object', + properties: { + event: { + type: 'string', + enum: Object.values(VoipClientEvents), + }, + rid: { + type: 'string', + }, + comment: { + type: 'string', + nullable: true, + }, + }, + required: ['event', 'rid'], + additionalProperties: false, +}; + +export const isVoipEventsProps = ajv.compile(VoipEventsSchema); + +type VoipRoom = { token: string; agentId: ILivechatAgent['_id'] } | { rid: string; token: string }; + +const VoipRoomSchema: JSONSchemaType = { + oneOf: [ + { + type: 'object', + properties: { + token: { + type: 'string', + }, + agentId: { + type: 'string', + }, + }, + required: ['token', 'agentId'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + rid: { + type: 'string', + }, + token: { + type: 'string', + }, + }, + required: ['rid', 'token'], + additionalProperties: false, + }, + ], +}; + +export const isVoipRoomProps = ajv.compile(VoipRoomSchema); + +type VoipManagementServerCheckConnection = { host: string; port: string; username: string; password: string }; + +const VoipManagementServerCheckConnectionSchema: JSONSchemaType = { + type: 'object', + properties: { + host: { + type: 'string', + }, + port: { + type: 'string', + }, + username: { + type: 'string', + }, + password: { + type: 'string', + }, + }, + required: ['host', 'port', 'username', 'password'], + additionalProperties: false, +}; + +export const isVoipManagementServerCheckConnectionProps = ajv.compile( + VoipManagementServerCheckConnectionSchema, +); + +type VoipCallServerCheckConnection = { websocketUrl: string; host: string; port: string; path: string }; + +const VoipCallServerCheckConnectionSchema: JSONSchemaType = { + type: 'object', + properties: { + websocketUrl: { + type: 'string', + }, + host: { + type: 'string', + }, + port: { + type: 'string', + }, + path: { + type: 'string', + }, + }, + required: ['websocketUrl', 'host', 'port', 'path'], + additionalProperties: false, +}; + +export const isVoipCallServerCheckConnectionProps = ajv.compile(VoipCallServerCheckConnectionSchema); + +type VoipRooms = { + agents?: string[]; + open?: 'true' | 'false'; + createdAt?: string; + closedAt?: string; + tags?: string[]; + queue?: string; + visitorId?: string; +}; + +const VoipRoomsSchema: JSONSchemaType = { + type: 'object', + properties: { + agents: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + open: { + type: 'string', + enum: ['true', 'false'], + nullable: true, + }, + createdAt: { + type: 'string', + nullable: true, + }, + closedAt: { + type: 'string', + nullable: true, + }, + tags: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + queue: { + type: 'string', + nullable: true, + }, + visitorId: { + type: 'string', + nullable: true, + }, + }, + required: [], + additionalProperties: false, +}; + +export const isVoipRoomsProps = ajv.compile(VoipRoomsSchema); + +type VoipRoomClose = { rid: string; token: string; comment: string; tags?: string[] }; + +const VoipRoomCloseSchema: JSONSchemaType = { + type: 'object', + properties: { + rid: { + type: 'string', + }, + token: { + type: 'string', + }, + comment: { + type: 'string', + }, + tags: { + type: 'array', + items: { + type: 'string', + }, + nullable: true, + }, + }, + required: ['rid', 'token', 'comment'], + additionalProperties: false, +}; + +export const isVoipRoomCloseProps = ajv.compile(VoipRoomCloseSchema); + export type VoipEndpoints = { 'connector.extension.getRegistrationInfoByUserId': { - GET: (params: { id: string }) => IRegistrationInfo | { result: string }; + GET: (params: ConnectorExtensionGetRegistrationInfoByUserId) => IRegistrationInfo | { result: string }; }; 'voip/queues.getSummary': { GET: () => { summary: IQueueSummary[] }; }; 'voip/queues.getQueuedCallsForThisExtension': { - GET: (params: { extension: string }) => IQueueMembershipDetails; + GET: (params: VoipQueuesGetQueuedCallsForThisExtension) => IQueueMembershipDetails; }; 'voip/queues.getMembershipSubscription': { - GET: (params: { extension: string }) => IQueueMembershipSubscription; + GET: (params: VoipQueuesGetMembershipSubscription) => IQueueMembershipSubscription; }; 'omnichannel/extensions': { - GET: ( - params: PaginatedRequest<{ status?: string; agentId?: string; queues?: string[]; extension?: string }>, - ) => PaginatedResult<{ extensions: IVoipExtensionWithAgentInfo[] }>; + GET: (params: OmnichannelExtensions) => PaginatedResult<{ extensions: IVoipExtensionWithAgentInfo[] }>; }; 'omnichannel/extension': { - GET: ( - params: { userId: string; type: 'free' | 'allocated' | 'available' } | { username: string; type: 'free' | 'allocated' | 'available' }, - ) => { + GET: (params: OmnichannelExtension) => { extensions: string[]; }; }; 'omnichannel/agent/extension': { - GET: (params: { username: string }) => { extension: Pick }; - POST: (params: { userId: string; extension: string } | { username: string; extension: string }) => void; - DELETE: (params: { username: string }) => void; + GET: (params: OmnichannelAgentExtensionGET) => { extension: Pick }; + POST: (params: OmnichannelAgentExtensionPOST) => void; + DELETE: (params: OmnichannelAgentExtensionDELETE) => void; }; 'omnichannel/agents/available': { - GET: (params: PaginatedRequest<{ text?: string; includeExtension?: string }>) => PaginatedResult<{ agents: ILivechatAgent[] }>; + GET: (params: OmnichannelAgentsAvailable) => PaginatedResult<{ agents: ILivechatAgent[] }>; }; 'voip/events': { - POST: (params: { event: VoipClientEvents; rid: string; comment?: string }) => void; + POST: (params: VoipEvents) => void; }; 'voip/room': { - GET: (params: { token: string; agentId: ILivechatAgent['_id'] } | { rid: string; token: string }) => { + GET: (params: VoipRoom) => { room: IVoipRoom; newRoom: boolean; }; }; 'voip/managementServer/checkConnection': { - GET: (params: { host: string; port: string; username: string; password: string }) => IManagementServerConnectionStatus; + GET: (params: VoipManagementServerCheckConnection) => IManagementServerConnectionStatus; }; 'voip/callServer/checkConnection': { - GET: (params: { websocketUrl: string; host: string; port: string; path: string }) => IManagementServerConnectionStatus; + GET: (params: VoipCallServerCheckConnection) => IManagementServerConnectionStatus; }; 'voip/rooms': { - GET: (params: { - agents?: string[]; - open?: boolean; - createdAt?: string; - closedAt?: string; - tags?: string[]; - queue?: string; - visitorId?: string; - }) => PaginatedResult<{ rooms: IVoipRoom[] }>; + GET: (params: VoipRooms) => PaginatedResult<{ rooms: IVoipRoom[] }>; }; 'voip/room.close': { - POST: (params: { rid: string; token: string; comment: string; tags?: string[] }) => { rid: string }; + POST: (params: VoipRoomClose) => { rid: string }; }; }; From 48c8c163520d8cd405d1a08d6a91b28073640a5f Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 3 Jun 2022 01:57:42 -0300 Subject: [PATCH 14/18] Lint --- apps/meteor/app/api/server/v1/im.ts | 11 ++++- .../imports/server/rest/departments.ts | 7 +-- .../Omnichannel/hooks/useDepartmentsList.ts | 5 +-- .../omnichannel/directory/calls/CallTable.tsx | 4 +- .../omnichannel/queueList/hooks/useQuery.ts | 6 +-- apps/meteor/package.json | 2 +- packages/rest-typings/src/index.ts | 3 ++ .../rest-typings/src/v1/dm/DmHistoryProps.ts | 43 ++++++++++++++++--- packages/rest-typings/src/v1/dm/im.ts | 6 +-- 9 files changed, 64 insertions(+), 23 deletions(-) diff --git a/apps/meteor/app/api/server/v1/im.ts b/apps/meteor/app/api/server/v1/im.ts index 76542f1e5582..5795f9601ac2 100644 --- a/apps/meteor/app/api/server/v1/im.ts +++ b/apps/meteor/app/api/server/v1/im.ts @@ -2,7 +2,14 @@ * Docs: https://github.com/RocketChat/developer-docs/blob/master/reference/api/rest-api/endpoints/team-collaboration-endpoints/im-endpoints */ import type { IMessage, IRoom, ISetting, ISubscription, IUpload, IUser } from '@rocket.chat/core-typings'; -import { isDmDeleteProps, isDmFileProps, isDmMemberProps, isDmMessagesProps, isDmCreateProps } from '@rocket.chat/rest-typings'; +import { + isDmDeleteProps, + isDmFileProps, + isDmMemberProps, + isDmMessagesProps, + isDmCreateProps, + isDmHistoryProps, +} from '@rocket.chat/rest-typings'; import { Meteor } from 'meteor/meteor'; import { Match, check } from 'meteor/check'; @@ -240,7 +247,7 @@ API.v1.addRoute( API.v1.addRoute( ['dm.history', 'im.history'], - { authRequired: true }, + { authRequired: true, validateParams: isDmHistoryProps }, { async get() { const { offset = 0, count = 20 } = this.getPaginationItems(); diff --git a/apps/meteor/app/livechat/imports/server/rest/departments.ts b/apps/meteor/app/livechat/imports/server/rest/departments.ts index ab8ee8a66e42..e501782744d4 100644 --- a/apps/meteor/app/livechat/imports/server/rest/departments.ts +++ b/apps/meteor/app/livechat/imports/server/rest/departments.ts @@ -1,3 +1,4 @@ +import { isLivechatDepartmentProps } from '@rocket.chat/rest-typings'; import { Match, check } from 'meteor/check'; import { API } from '../../../../api/server'; @@ -14,9 +15,9 @@ import { API.v1.addRoute( 'livechat/department', - { authRequired: true }, + { authRequired: true, validateParams: isLivechatDepartmentProps }, { - get() { + async get() { const { offset, count } = this.getPaginationItems(); const { sort } = this.parseJsonQuery(); @@ -26,7 +27,7 @@ API.v1.addRoute( findDepartments({ userId: this.userId, text, - enabled, + enabled: enabled === 'true', onlyMyDepartments: onlyMyDepartments === 'true', excludeDepartmentId, pagination: { diff --git a/apps/meteor/client/components/Omnichannel/hooks/useDepartmentsList.ts b/apps/meteor/client/components/Omnichannel/hooks/useDepartmentsList.ts index a80ea72447ab..1d87a9f6e6da 100644 --- a/apps/meteor/client/components/Omnichannel/hooks/useDepartmentsList.ts +++ b/apps/meteor/client/components/Omnichannel/hooks/useDepartmentsList.ts @@ -27,9 +27,8 @@ export const useDepartmentsList = ( const t = useTranslation(); const [itemsList, setItemsList] = useState(() => new RecordList()); const reload = useCallback(() => setItemsList(new RecordList()), []); - const endpoint = 'livechat/department'; - const getDepartments = useEndpoint('GET', endpoint); + const getDepartments = useEndpoint('GET', 'livechat/department'); useComponentDidUpdate(() => { options && reload(); @@ -44,7 +43,7 @@ export const useDepartmentsList = ( count: end + start, sort: `{ "name": 1 }`, excludeDepartmentId: options.excludeDepartmentId, - enabled: options.enabled, + enabled: options.enabled ? 'true' : 'false', }); const items = departments diff --git a/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx b/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx index 2c9485b74e4d..7d964af4c16a 100644 --- a/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx +++ b/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx @@ -22,7 +22,7 @@ const useQuery = ( userIdLoggedIn: string | null, ): { sort: string; - open: boolean; + open: 'false'; roomName: string; agents: string[]; count?: number; @@ -31,7 +31,7 @@ const useQuery = ( useMemo( () => ({ sort: JSON.stringify({ [column]: direction === 'asc' ? 1 : -1 }), - open: false, + open: 'false', roomName: text || '', agents: userIdLoggedIn ? [userIdLoggedIn] : [], ...(itemsPerPage && { count: itemsPerPage }), diff --git a/apps/meteor/client/views/omnichannel/queueList/hooks/useQuery.ts b/apps/meteor/client/views/omnichannel/queueList/hooks/useQuery.ts index 880c157455d4..76a5fe26dfcb 100644 --- a/apps/meteor/client/views/omnichannel/queueList/hooks/useQuery.ts +++ b/apps/meteor/client/views/omnichannel/queueList/hooks/useQuery.ts @@ -12,7 +12,7 @@ type useQueryType = ( debouncedSort: [string, 'asc' | 'desc'], ) => { agentId?: ILivechatAgent['_id']; - includeOfflineAgents?: boolean; + includeOfflineAgents?: 'true' | 'false'; departmentId?: ILivechatAgent['_id']; offset: number; count: number; @@ -25,7 +25,7 @@ export const useQuery: useQueryType = ({ servedBy, status, departmentId, itemsPe useMemo(() => { const query: { agentId?: string; - includeOflineAgents?: boolean; + includeOflineAgents?: 'true' | 'false'; departmentId?: string; sort: string; count: number; @@ -39,7 +39,7 @@ export const useQuery: useQueryType = ({ servedBy, status, departmentId, itemsPe }; if (status !== 'online') { - query.includeOflineAgents = true; + query.includeOflineAgents = 'true'; } if (servedBy) { query.agentId = servedBy; diff --git a/apps/meteor/package.json b/apps/meteor/package.json index 7aa3c80937be..30d3bca1d4bf 100644 --- a/apps/meteor/package.json +++ b/apps/meteor/package.json @@ -28,7 +28,7 @@ "obj:dev": "TEST_MODE=true yarn dev", "stylelint": "stylelint \"app/**/*.css\" \"client/**/*.css\" \"app/**/*.less\" \"client/**/*.less\" \"ee/**/*.less\"", "stylelint:fix": "stylelint --fix \"app/**/*.css\" \"client/**/*.css\" \"app/**/*.less\" \"client/**/*.less\" \"ee/**/*.less\"", - "typecheck": "cross-env NODE_OPTIONS=\"--max-old-space-size=4092\" tsc --noEmit --skipLibCheck", + "typecheck": "cross-env NODE_OPTIONS=\"--max-old-space-size=8184\" tsc --noEmit --skipLibCheck", "deploy": "npm run build && pm2 startOrRestart pm2.json", "coverage": "nyc -r html mocha --config ./.mocharc.js", "testci": "node .scripts/start.js", diff --git a/packages/rest-typings/src/index.ts b/packages/rest-typings/src/index.ts index 04b4a05c0b4a..663f95ce3bae 100644 --- a/packages/rest-typings/src/index.ts +++ b/packages/rest-typings/src/index.ts @@ -155,7 +155,10 @@ export * from './v1/channels/ChannelsConvertToTeamProps'; export * from './v1/channels/ChannelsSetReadOnlyProps'; export * from './v1/channels/ChannelsDeleteProps'; export * from './v1/dm'; +export * from './v1/dm/DmHistoryProps'; + export * from './v1/integrations'; +export * from './v1/omnichannel'; export * from './v1/oauthapps'; export * from './helpers/PaginatedRequest'; export * from './helpers/PaginatedResult'; diff --git a/packages/rest-typings/src/v1/dm/DmHistoryProps.ts b/packages/rest-typings/src/v1/dm/DmHistoryProps.ts index 784bd6c25d3c..0a836961f366 100644 --- a/packages/rest-typings/src/v1/dm/DmHistoryProps.ts +++ b/packages/rest-typings/src/v1/dm/DmHistoryProps.ts @@ -1,25 +1,56 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import type { PaginatedRequest } from '@rocket.chat/rest-typings/src/helpers/PaginatedRequest'; +import Ajv from 'ajv'; const ajv = new Ajv(); -export type DmHistoryProps = { +export type DmHistoryProps = PaginatedRequest<{ roomId: string; latest?: string; -}; + oldest?: string; + inclusive?: 'false' | 'true'; + unreads?: 'true' | 'false'; + showThreadMessages?: 'false' | 'true'; +}>; -const DmHistoryPropsSchema: JSONSchemaType = { +const DmHistoryPropsSchema = { type: 'object', properties: { roomId: { type: 'string', + minLength: 1, }, latest: { type: 'string', - nullable: true, + minLength: 1, + }, + showThreadMessages: { + type: 'string', + enum: ['false', 'true'], + }, + oldest: { + type: 'string', + minLength: 1, + }, + inclusive: { + type: 'string', + enum: ['false', 'true'], + }, + unreads: { + type: 'string', + enum: ['true', 'false'], + }, + count: { + type: 'number', + }, + offset: { + type: 'number', + }, + sort: { + type: 'string', }, }, required: ['roomId'], additionalProperties: false, }; -export const isDmHistoryProps = ajv.compile(DmHistoryPropsSchema); +export const isDmHistoryProps = ajv.compile(DmHistoryPropsSchema); diff --git a/packages/rest-typings/src/v1/dm/im.ts b/packages/rest-typings/src/v1/dm/im.ts index 69657135619a..87c4adfe4fa7 100644 --- a/packages/rest-typings/src/v1/dm/im.ts +++ b/packages/rest-typings/src/v1/dm/im.ts @@ -21,13 +21,13 @@ export type ImEndpoints = { POST: (params: DmDeleteProps) => void; }; 'im.close': { - POST: (params: DmCloseProps) => {}; + POST: (params: DmCloseProps) => void; }; 'im.kick': { - POST: (params: DmCloseProps) => {}; + POST: (params: DmCloseProps) => void; }; 'im.leave': { - POST: (params: DmLeaveProps) => {}; + POST: (params: DmLeaveProps) => void; }; 'im.counters': { GET: (params: { roomId: string; userId?: string }) => { From 25eeb053f2711f24ed8dfc7bacd9e3ffcd38e866 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 3 Jun 2022 09:49:32 -0300 Subject: [PATCH 15/18] Fix '/im.history' test --- apps/meteor/tests/end-to-end/api/04-direct-message.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/meteor/tests/end-to-end/api/04-direct-message.js b/apps/meteor/tests/end-to-end/api/04-direct-message.js index d1f6e82dc75e..9eb450539ab9 100644 --- a/apps/meteor/tests/end-to-end/api/04-direct-message.js +++ b/apps/meteor/tests/end-to-end/api/04-direct-message.js @@ -170,7 +170,6 @@ describe('[Direct Messages]', function () { .set(credentials) .query({ roomId: directMessage._id, - userId: 'rocket.cat', }) .expect('Content-Type', 'application/json') .expect(200) From cfdecd931d2ba7c2f5e7227e822e235de465351f Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 3 Jun 2022 11:47:19 -0300 Subject: [PATCH 16/18] fix ominchannel departments --- packages/rest-typings/src/v1/omnichannel.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index 93598fd978a1..26acf71b0880 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -344,6 +344,7 @@ const LivechatDepartmentSchema = { }, onlyMyDepartments: { type: 'string', + enum: ['true', 'false'], nullable: true, }, enabled: { @@ -370,8 +371,12 @@ const LivechatDepartmentSchema = { type: 'string', nullable: true, }, + fields: { + type: 'string', + nullable: true, + }, }, - required: ['text'], + required: [], additionalProperties: false, }; From 5096876438099a7a527f64b141059760e536aa30 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 3 Jun 2022 16:10:18 -0300 Subject: [PATCH 17/18] Apply suggestions from code review Co-authored-by: Pierre Lehnen <55164754+pierre-lehnen-rc@users.noreply.github.com> --- .yarnrc.yml | 2 -- packages/rest-typings/src/index.ts | 1 - 2 files changed, 3 deletions(-) diff --git a/.yarnrc.yml b/.yarnrc.yml index 8abafc3d6310..404765a22773 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -11,5 +11,3 @@ plugins: spec: '@yarnpkg/plugin-typescript' yarnPath: .yarn/releases/yarn-3.2.0.cjs - -checksumBehavior: 'update' diff --git a/packages/rest-typings/src/index.ts b/packages/rest-typings/src/index.ts index 663f95ce3bae..49573302bed7 100644 --- a/packages/rest-typings/src/index.ts +++ b/packages/rest-typings/src/index.ts @@ -156,7 +156,6 @@ export * from './v1/channels/ChannelsSetReadOnlyProps'; export * from './v1/channels/ChannelsDeleteProps'; export * from './v1/dm'; export * from './v1/dm/DmHistoryProps'; - export * from './v1/integrations'; export * from './v1/omnichannel'; export * from './v1/oauthapps'; From f8287c2021dd2ec076aaa640fb9e31afda892dab Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 3 Jun 2022 16:28:09 -0300 Subject: [PATCH 18/18] Fix review --- packages/rest-typings/src/v1/banners.ts | 1 + packages/rest-typings/src/v1/cloud.ts | 1 + packages/rest-typings/src/v1/omnichannel.ts | 2 +- packages/rest-typings/src/v1/voip.ts | 2 -- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/rest-typings/src/v1/banners.ts b/packages/rest-typings/src/v1/banners.ts index 50d56d1d0850..7045e2383a14 100644 --- a/packages/rest-typings/src/v1/banners.ts +++ b/packages/rest-typings/src/v1/banners.ts @@ -15,6 +15,7 @@ const BannersGetNewSchema = { properties: { platform: { type: 'string', + enum: ['1', '2'], }, bid: { type: 'string', diff --git a/packages/rest-typings/src/v1/cloud.ts b/packages/rest-typings/src/v1/cloud.ts index 59d1986700d6..e27289566711 100644 --- a/packages/rest-typings/src/v1/cloud.ts +++ b/packages/rest-typings/src/v1/cloud.ts @@ -60,6 +60,7 @@ const CloudConfirmationPollSchema = { }, }, required: ['deviceCode'], + optionalProperties: ['resend'], additionalProperties: false, }; diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index 26acf71b0880..fc2ab9e23fd9 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -341,6 +341,7 @@ const LivechatDepartmentSchema = { properties: { text: { type: 'string', + nullable: true, }, onlyMyDepartments: { type: 'string', @@ -376,7 +377,6 @@ const LivechatDepartmentSchema = { nullable: true, }, }, - required: [], additionalProperties: false, }; diff --git a/packages/rest-typings/src/v1/voip.ts b/packages/rest-typings/src/v1/voip.ts index 5abd3e26b9e8..fbdeafc23fef 100644 --- a/packages/rest-typings/src/v1/voip.ts +++ b/packages/rest-typings/src/v1/voip.ts @@ -8,7 +8,6 @@ import type { IVoipExtensionWithAgentInfo, IManagementServerConnectionStatus, IRegistrationInfo, - // VoipClientEvents, } from '@rocket.chat/core-typings'; import { VoipClientEvents } from '@rocket.chat/core-typings'; import Ajv, { JSONSchemaType } from 'ajv'; @@ -48,7 +47,6 @@ const CustomSoundsListSchema: JSONSchemaType = { }; export const isCustomSoundsListProps = ajv.compile(CustomSoundsListSchema); -/** *************************************************/ type ConnectorExtensionGetRegistrationInfoByUserId = { id: string };