diff --git a/apps/meteor/app/api/server/v1/channels.ts b/apps/meteor/app/api/server/v1/channels.ts index e1ab4da8e8d9371e4f67f7ecc6b563f61dbcd4e0..484c2a0770811192e8e13963a49694ada3ac8344 100644 --- a/apps/meteor/app/api/server/v1/channels.ts +++ b/apps/meteor/app/api/server/v1/channels.ts @@ -129,9 +129,9 @@ API.v1.addRoute( }, { get() { - const { roomId, unreads, oldest, latest, showThreadMessages, inclusive } = this.queryParams; + const { unreads, oldest, latest, showThreadMessages, inclusive, ...params } = this.queryParams; const findResult = findChannelByIdOrName({ - params: { roomId }, + params, checkedArchived: false, }); @@ -184,13 +184,13 @@ API.v1.addRoute( }, { post() { - const { roomId, joinCode } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const { joinCode, ...params } = this.bodyParams; + const findResult = findChannelByIdOrName({ params }); Meteor.call('joinRoom', findResult._id, joinCode); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params, userId: this.userId }), }); }, }, @@ -204,15 +204,15 @@ API.v1.addRoute( }, { post() { - const { roomId /* userId */ } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const { ...params /* userId */ } = this.bodyParams; + const findResult = findChannelByIdOrName({ params }); const user = this.getUserFromParams(); Meteor.call('removeUserFromRoom', { rid: findResult._id, username: user.username }); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params, userId: this.userId }), }); }, }, @@ -226,15 +226,15 @@ API.v1.addRoute( }, { post() { - const { roomId } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const { ...params } = this.bodyParams; + const findResult = findChannelByIdOrName({ params }); Meteor.runAsUser(this.userId, () => { Meteor.call('leaveRoom', findResult._id); }); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params, userId: this.userId }), }); }, }, @@ -297,10 +297,10 @@ API.v1.addRoute( }, { post() { - const { roomId } = this.bodyParams; + const { ...params } = this.bodyParams; const findResult = findChannelByIdOrName({ - params: { roomId }, + params, checkedArchived: false, }); @@ -329,9 +329,7 @@ API.v1.addRoute( }, { post() { - const { roomId } = this.bodyParams; - - const findResult = findChannelByIdOrName({ params: { roomId } }); + const findResult = findChannelByIdOrName({ params: this.bodyParams }); if (findResult.ro === this.bodyParams.readOnly) { return API.v1.failure('The channel read only setting is the same as what it would be changed to.'); @@ -340,7 +338,7 @@ API.v1.addRoute( Meteor.call('saveRoomSettings', findResult._id, 'readOnly', this.bodyParams.readOnly); return API.v1.success({ - channel: findChannelByIdOrName({ params: { roomId }, userId: this.userId }), + channel: findChannelByIdOrName({ params: this.bodyParams, userId: this.userId }), }); }, }, @@ -354,9 +352,9 @@ API.v1.addRoute( }, { post() { - const { roomId, announcement } = this.bodyParams; + const { announcement, ...params } = this.bodyParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const findResult = findChannelByIdOrName({ params }); Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', announcement); @@ -379,23 +377,19 @@ API.v1.addRoute( const { offset, count } = this.getPaginationItems(); const { sort } = this.parseJsonQuery(); - const mentions = Meteor.runAsUser(this.userId, () => - Meteor.call('getUserMentionsByChannel', { - roomId, - options: { - sort: sort || { ts: 1 }, - skip: offset, - limit: count, - }, - }), - ); - - const allMentions = Meteor.runAsUser(this.userId, () => - Meteor.call('getUserMentionsByChannel', { - roomId, - options: {}, - }), - ); + const mentions = Meteor.call('getUserMentionsByChannel', { + roomId, + options: { + sort: sort || { ts: 1 }, + skip: offset, + limit: count, + }, + }); + + const allMentions = Meteor.call('getUserMentionsByChannel', { + roomId, + options: {}, + }); return API.v1.success({ mentions, @@ -415,9 +409,9 @@ API.v1.addRoute( }, { get() { - const { roomId } = this.queryParams; + const { ...params } = this.queryParams; - const findResult = findChannelByIdOrName({ params: { roomId } }); + const findResult = findChannelByIdOrName({ params }); const moderators = Subscriptions.findByRoomIdAndRoles(findResult._id, ['moderator'], { fields: { u: 1 }, diff --git a/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts b/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts index 8797fbf57a1317fb529c87667dc69eb383670fa7..b022674974d5d2302d8a557b8b214d0bfa7b30b8 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsGetAllUserMentionsByChannelProps.ts @@ -9,11 +9,25 @@ export type ChannelsGetAllUserMentionsByChannelProps = PaginatedRequest<{ roomId const channelsGetAllUserMentionsByChannelPropsSchema = { type: 'object', properties: { - roomId: { type: 'string' }, - offset: { type: 'number' }, - count: { type: 'number' }, - sort: { type: 'string' }, - query: { type: 'string' }, + roomId: { + type: 'string', + }, + offset: { + type: 'number', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + query: { + type: 'string', + nullable: true, + }, }, required: ['roomId'], diff --git a/packages/rest-typings/src/v1/channels/ChannelsHistoryProps.ts b/packages/rest-typings/src/v1/channels/ChannelsHistoryProps.ts index 3cf656e8db06ecfca8b3b9bdbbf1d023f94e956b..fc34e2f3b7ec3da3da068e58cdbed228d0e6e22b 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsHistoryProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsHistoryProps.ts @@ -1,55 +1,117 @@ import Ajv from 'ajv'; -const ajv = new Ajv({ coerceTypes: true }); +import type { PaginatedRequest } from '../../helpers/PaginatedRequest'; -export type ChannelsHistoryProps = { - roomId: string; - latest?: string; - showThreadMessages?: 'false' | 'true'; - oldest?: string; - unreads?: 'true' | 'false'; - inclusive?: 'false' | 'true'; -}; +const ajv = new Ajv({ coerceTypes: true }); +export type ChannelsHistoryProps = PaginatedRequest< + ({ roomId: string } | { roomName: string }) & { + latest?: string; + showThreadMessages?: 'false' | 'true'; + oldest?: string; + unreads?: 'true' | 'false'; + inclusive?: 'false' | 'true'; + } +>; const channelsHistoryPropsSchema = { - type: 'object', - properties: { - roomId: { - type: 'string', - minLength: 1, - }, - latest: { - type: 'string', - 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', + oneOf: [ + { + type: 'object', + properties: { + roomId: { + type: 'string', + minLength: 1, + }, + latest: { + type: 'string', + minLength: 1, + nullable: true, + }, + showThreadMessages: { + type: 'string', + enum: ['false', 'true'], + nullable: true, + }, + oldest: { + type: 'string', + minLength: 1, + nullable: true, + }, + inclusive: { + type: 'string', + enum: ['false', 'true'], + nullable: true, + }, + unreads: { + type: 'string', + enum: ['true', 'false'], + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + }, + required: ['roomId'], + additionalProperties: false, }, - sort: { - type: 'string', + { + type: 'object', + properties: { + roomName: { + type: 'string', + minLength: 1, + }, + latest: { + type: 'string', + minLength: 1, + nullable: true, + }, + showThreadMessages: { + type: 'string', + enum: ['false', 'true'], + nullable: true, + }, + oldest: { + type: 'string', + minLength: 1, + nullable: true, + }, + inclusive: { + type: 'string', + enum: ['false', 'true'], + nullable: true, + }, + unreads: { + type: 'string', + enum: ['true', 'false'], + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, + sort: { + type: 'string', + nullable: true, + }, + }, + required: ['roomName'], + additionalProperties: false, }, - }, - required: ['roomId'], - additionalProperties: false, + ], }; export const isChannelsHistoryProps = ajv.compile<ChannelsHistoryProps>(channelsHistoryPropsSchema); diff --git a/packages/rest-typings/src/v1/channels/ChannelsJoinProps.ts b/packages/rest-typings/src/v1/channels/ChannelsJoinProps.ts index 24ba1c4fab2a3c3a62d77f7cbe8c95fc5c5f3cc2..50fb56fc4a6e8bf4ea38fedc3a9c8ad1bf5cffa4 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsJoinProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsJoinProps.ts @@ -2,21 +2,39 @@ import Ajv from 'ajv'; const ajv = new Ajv(); -export type ChannelsJoinProps = { roomId: string; joinCode?: string }; +export type ChannelsJoinProps = { roomId: string; joinCode?: string } | { roomName: string; joinCode?: string }; const channelsJoinPropsSchema = { - type: 'object', - properties: { - roomId: { - type: 'string', + oneOf: [ + { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + joinCode: { + type: 'string', + nullable: true, + }, + }, + required: ['roomId'], + additionalProperties: false, }, - joinCode: { - type: 'string', - nullable: true, + { + type: 'object', + properties: { + roomName: { + type: 'string', + }, + joinCode: { + type: 'string', + nullable: true, + }, + }, + required: ['roomName'], + additionalProperties: false, }, - }, - required: ['roomId'], - additionalProperties: false, + ], }; export const isChannelsJoinProps = ajv.compile<ChannelsJoinProps>(channelsJoinPropsSchema); diff --git a/packages/rest-typings/src/v1/channels/ChannelsKickProps.ts b/packages/rest-typings/src/v1/channels/ChannelsKickProps.ts index d1c99063281bf0f5a91017cce3ca261d085d7816..c6e71bf7aa2debe79bd8cbc05b6449d1ae2bd627 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsKickProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsKickProps.ts @@ -2,20 +2,37 @@ import Ajv from 'ajv'; const ajv = new Ajv(); -export type ChannelsKickProps = { roomId: string; userId: string }; +export type ChannelsKickProps = { roomId: string; userId: string } | { roomName: string; userId: string }; const channelsKickPropsSchema = { - type: 'object', - properties: { - roomId: { - type: 'string', + oneOf: [ + { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + userId: { + type: 'string', + }, + }, + required: ['roomId', 'userId'], + additionalProperties: false, }, - userId: { - type: 'string', + { + type: 'object', + properties: { + roomName: { + type: 'string', + }, + userId: { + type: 'string', + }, + }, + required: ['roomName', 'userId'], + additionalProperties: false, }, - }, - required: ['roomId', 'userId'], - additionalProperties: false, + ], }; export const isChannelsKickProps = ajv.compile<ChannelsKickProps>(channelsKickPropsSchema); diff --git a/packages/rest-typings/src/v1/channels/ChannelsLeaveProps.ts b/packages/rest-typings/src/v1/channels/ChannelsLeaveProps.ts index 52e0c48a0d887132f3cf1e59b2ec25cdc9f06bb3..418a004dad1d17e55d996695a12c02cabe4bce94 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsLeaveProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsLeaveProps.ts @@ -2,17 +2,31 @@ import Ajv from 'ajv'; const ajv = new Ajv(); -export type ChannelsLeaveProps = { roomId: string }; +export type ChannelsLeaveProps = { roomId: string } | { roomName: string }; const channelsLeavePropsSchema = { - type: 'object', - properties: { - roomId: { - type: 'string', + oneOf: [ + { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, }, - }, - required: ['roomId'], - additionalProperties: false, + { + type: 'object', + properties: { + roomName: { + type: 'string', + }, + }, + required: ['roomName'], + additionalProperties: false, + }, + ], }; export const isChannelsLeaveProps = ajv.compile<ChannelsLeaveProps>(channelsLeavePropsSchema); diff --git a/packages/rest-typings/src/v1/channels/ChannelsMessagesProps.ts b/packages/rest-typings/src/v1/channels/ChannelsMessagesProps.ts index 959b9a3ef3573d316df5ca3f35760b26dae4da70..e385f74d00af8ec27f5d274101c44ae88d69b46c 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsMessagesProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsMessagesProps.ts @@ -5,23 +5,30 @@ import type { PaginatedRequest } from '../../helpers/PaginatedRequest'; const ajv = new Ajv({ coerceTypes: true }); -export type ChannelsMessagesProps = PaginatedRequest< - { - roomId: IRoom['_id']; - // query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean }; - }, - 'ts' ->; +// query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean }; +export type ChannelsMessagesProps = PaginatedRequest<{ roomId: IRoom['_id'] }, 'ts'>; const channelsMessagesPropsSchema = { type: 'object', properties: { - roomId: { type: 'string' }, - query: { type: 'string' }, - count: { type: 'number' }, - offset: { type: 'number' }, + roomId: { + type: 'string', + }, + query: { + type: 'string', + nullable: true, + }, + count: { + type: 'number', + nullable: true, + }, + offset: { + type: 'number', + nullable: true, + }, sort: { type: 'string', + nullable: true, }, }, diff --git a/packages/rest-typings/src/v1/channels/ChannelsModeratorsProps.ts b/packages/rest-typings/src/v1/channels/ChannelsModeratorsProps.ts index 8f04f1ab46a9b076f585d0dbc0801900fb399f39..4dabaece8106d36920193f738b3db3a1b6596be8 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsModeratorsProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsModeratorsProps.ts @@ -2,16 +2,29 @@ import Ajv from 'ajv'; const ajv = new Ajv(); -export type ChannelsModeratorsProps = { roomId: string }; +export type ChannelsModeratorsProps = { roomId: string } | { roomName: string }; const channelsModeratorsPropsSchema = { - type: 'object', - properties: { - roomId: { type: 'string' }, - }, - required: ['roomId'], + oneOf: [ + { + type: 'object', + properties: { + roomId: { type: 'string' }, + }, + required: ['roomId'], - additionalProperties: false, + additionalProperties: false, + }, + { + type: 'object', + properties: { + roomName: { type: 'string' }, + }, + required: ['roomName'], + + additionalProperties: false, + }, + ], }; export const isChannelsModeratorsProps = ajv.compile<ChannelsModeratorsProps>(channelsModeratorsPropsSchema); diff --git a/packages/rest-typings/src/v1/channels/ChannelsOpenProps.ts b/packages/rest-typings/src/v1/channels/ChannelsOpenProps.ts index 7e1d9521e183225b51138b3e9058de0110dfa562..1150b8536a3bbc54797667e6bc21faa3f9299307 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsOpenProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsOpenProps.ts @@ -2,28 +2,77 @@ import Ajv from 'ajv'; const ajv = new Ajv(); -export type ChannelsOpenProps = { - roomId: string; - query?: string; // { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean }; - sort?: { ts: 1 | -1 }; -}; +export type ChannelsOpenProps = + | { + roomId: string; + query?: string; // { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean }; + sort?: { ts: 1 | -1 }; + } + | { + roomName: string; + query?: string; + sort?: { ts: 1 | -1 }; + }; const channelsOpenPropsSchema = { - type: 'object', - properties: { - roomId: { type: 'string' }, - query: { type: 'string' }, - sort: { + oneOf: [ + { type: 'object', properties: { - ts: { type: 'number' }, + roomId: { + type: 'string', + }, + query: { + type: 'string', + nullable: true, + }, + sort: { + type: 'object', + properties: { + ts: { + type: 'number', + enum: [1, -1], + }, + }, + required: ['ts'], + + additionalProperties: false, + nullable: true, + }, }, - required: ['ts'], + + required: ['roomId'], + additionalProperties: false, }, - }, + { + type: 'object', + properties: { + roomName: { + type: 'string', + }, + query: { + type: 'string', + nullable: true, + }, + sort: { + type: 'object', + properties: { + ts: { + type: 'number', + enum: [1, -1], + }, + }, + required: ['ts'], + + additionalProperties: false, + nullable: true, + }, + }, - required: ['roomId'], - additionalProperties: false, + required: ['roomName'], + additionalProperties: false, + }, + ], }; export const isChannelsOpenProps = ajv.compile<ChannelsOpenProps>(channelsOpenPropsSchema); diff --git a/packages/rest-typings/src/v1/channels/ChannelsSetAnnouncementProps.ts b/packages/rest-typings/src/v1/channels/ChannelsSetAnnouncementProps.ts index d073cb06d55349a9c861347515e5b242a5587317..5bd1ed535e80cfbb39fd8e19e4dc0614ba0e2847 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsSetAnnouncementProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsSetAnnouncementProps.ts @@ -2,20 +2,37 @@ import Ajv from 'ajv'; const ajv = new Ajv(); -export type ChannelsSetAnnouncementProps = { roomId: string; announcement: string }; +export type ChannelsSetAnnouncementProps = { roomId: string; announcement: string } | { roomName: string; announcement: string }; const channelsSetAnnouncementPropsSchema = { - type: 'object', - properties: { - roomId: { - type: 'string', + oneOf: [ + { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + announcement: { + type: 'string', + }, + }, + required: ['roomId', 'announcement'], + additionalProperties: false, }, - announcement: { - type: 'string', + { + type: 'object', + properties: { + roomName: { + type: 'string', + }, + announcement: { + type: 'string', + }, + }, + required: ['roomName', 'announcement'], + additionalProperties: false, }, - }, - required: ['roomId', 'announcement'], - additionalProperties: false, + ], }; export const isChannelsSetAnnouncementProps = ajv.compile<ChannelsSetAnnouncementProps>(channelsSetAnnouncementPropsSchema); diff --git a/packages/rest-typings/src/v1/channels/ChannelsSetReadOnlyProps.ts b/packages/rest-typings/src/v1/channels/ChannelsSetReadOnlyProps.ts index e526e0aba647986b4936cad68351562141f5c24b..c8475bc4c8c9b20d960b7f6e0525b61304fd7fb5 100644 --- a/packages/rest-typings/src/v1/channels/ChannelsSetReadOnlyProps.ts +++ b/packages/rest-typings/src/v1/channels/ChannelsSetReadOnlyProps.ts @@ -2,16 +2,29 @@ import Ajv from 'ajv'; const ajv = new Ajv(); -export type ChannelsSetReadOnlyProps = { roomId: string; readOnly: boolean }; +export type ChannelsSetReadOnlyProps = { roomId: string; readOnly: boolean } | { roomName: string; readOnly: boolean }; const channelsSetReadOnlyPropsSchema = { - type: 'object', - properties: { - roomId: { type: 'string' }, - readOnly: { type: 'boolean' }, - }, - required: ['roomId', 'readOnly'], - additionalProperties: false, + oneOf: [ + { + type: 'object', + properties: { + roomId: { type: 'string' }, + readOnly: { type: 'boolean' }, + }, + required: ['roomId', 'readOnly'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + roomName: { type: 'string' }, + readOnly: { type: 'boolean' }, + }, + required: ['roomName', 'readOnly'], + additionalProperties: false, + }, + ], }; export const isChannelsSetReadOnlyProps = ajv.compile<ChannelsSetReadOnlyProps>(channelsSetReadOnlyPropsSchema); diff --git a/packages/rest-typings/src/v1/channels/channels.ts b/packages/rest-typings/src/v1/channels/channels.ts index dd336117224418ea463692a9cd104d652f34d0e3..eb1ab118a02b8547e15b9f505b8bed45b10c95c0 100644 --- a/packages/rest-typings/src/v1/channels/channels.ts +++ b/packages/rest-typings/src/v1/channels/channels.ts @@ -6,6 +6,7 @@ import type { ChannelsAddAllProps } from './ChannelsAddAllProps'; import type { ChannelsArchiveProps } from './ChannelsArchiveProps'; import type { ChannelsDeleteProps } from './ChannelsDeleteProps'; import type { ChannelsGetAllUserMentionsByChannelProps } from './ChannelsGetAllUserMentionsByChannelProps'; +import type { ChannelsHistoryProps } from './ChannelsHistoryProps'; import type { ChannelsMessagesProps } from './ChannelsMessagesProps'; import type { ChannelsOpenProps } from './ChannelsOpenProps'; import type { ChannelsSetAnnouncementProps } from './ChannelsSetAnnouncementProps'; @@ -13,25 +14,21 @@ import type { ChannelsUnarchiveProps } from './ChannelsUnarchiveProps'; export type ChannelsEndpoints = { '/v1/channels.files': { - GET: (params: PaginatedRequest<{ roomId: IRoom['_id'] }>) => PaginatedResult<{ + GET: (params: PaginatedRequest<{ roomId: string } | { roomName: string }>) => PaginatedResult<{ files: IUpload[]; }>; }; '/v1/channels.members': { - GET: (params: PaginatedRequest<{ roomId: IRoom['_id']; filter?: string; status?: string[] }>) => PaginatedResult<{ + GET: ( + params: PaginatedRequest< + { roomId: string; filter?: string; status?: string[] } | { roomName: string; filter?: string; status?: string[] } + >, + ) => PaginatedResult<{ members: IUser[]; }>; }; '/v1/channels.history': { - GET: ( - params: PaginatedRequest<{ - roomId: string; - latest?: string; - showThreadMessages?: 'false' | 'true'; - oldest?: string; - inclusive?: 'false' | 'true'; - }>, - ) => PaginatedResult<{ + GET: (params: ChannelsHistoryProps) => PaginatedResult<{ messages: IMessage[]; }>; }; @@ -61,10 +58,10 @@ export type ChannelsEndpoints = { }; }; '/v1/channels.info': { - GET: (params: { roomId: string }) => { channel: IRoom }; + GET: (params: { roomId: string } | { roomName: string }) => { channel: IRoom }; }; '/v1/channels.counters': { - GET: (params: { roomId: string }) => { + GET: (params: { roomId: string } | { roomName: string }) => { joined: boolean; members: number; unreads: number; @@ -75,42 +72,42 @@ export type ChannelsEndpoints = { }; }; '/v1/channels.join': { - POST: (params: { roomId: string; joinCode?: string }) => { + POST: (params: { roomId: string; joinCode?: string } | { roomName: string; joinCode?: string }) => { channel: IRoom; }; }; '/v1/channels.close': { - POST: (params: { roomId: string }) => {}; + POST: (params: { roomId: string } | { roomName: string }) => {}; }; '/v1/channels.kick': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.delete': { POST: (params: ChannelsDeleteProps) => void; }; '/v1/channels.leave': { - POST: (params: { roomId: string }) => {}; + POST: (params: { roomId: string } | { roomName: string }) => {}; }; '/v1/channels.addModerator': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.removeModerator': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.addOwner': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.removeOwner': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.addLeader': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.removeLeader': { - POST: (params: { roomId: string; userId: string }) => {}; + POST: (params: { roomId: string; userId: string } | { roomName: string; userId: string }) => {}; }; '/v1/channels.roles': { - GET: (params: { roomId: string }) => { roles: IGetRoomRoles[] }; + GET: (params: { roomId: string } | { roomName: string }) => { roles: IGetRoomRoles[] }; }; '/v1/channels.messages': { GET: (params: ChannelsMessagesProps) => PaginatedResult<{ @@ -121,7 +118,7 @@ export type ChannelsEndpoints = { POST: (params: ChannelsOpenProps) => void; }; '/v1/channels.setReadOnly': { - POST: (params: { roomId: string; readOnly: boolean }) => { + POST: (params: { roomId: string; readOnly: boolean } | { roomName: string; readOnly: boolean }) => { channel: IRoom; }; }; @@ -144,6 +141,6 @@ export type ChannelsEndpoints = { }>; }; '/v1/channels.moderators': { - GET: (params: { roomId: string }) => { moderators: Pick<IUser, '_id' | 'name' | 'username'>[] }; + GET: (params: { roomId: string } | { roomName: string }) => { moderators: Pick<IUser, '_id' | 'name' | 'username'>[] }; }; }; diff --git a/packages/rest-typings/src/v1/dm/DmCloseProps.ts b/packages/rest-typings/src/v1/dm/DmCloseProps.ts index 1a1ea759680ac5b0bd54504bb730be50732d93d2..4a2d186896f1e33d436c34f01129e4b60a87208c 100644 --- a/packages/rest-typings/src/v1/dm/DmCloseProps.ts +++ b/packages/rest-typings/src/v1/dm/DmCloseProps.ts @@ -1,12 +1,14 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); export type DmCloseProps = { roomId: string; }; -const DmClosePropsSchema: JSONSchemaType<DmCloseProps> = { +const DmClosePropsSchema = { type: 'object', properties: { roomId: { @@ -17,4 +19,4 @@ const DmClosePropsSchema: JSONSchemaType<DmCloseProps> = { additionalProperties: false, }; -export const isDmCloseProps = ajv.compile(DmClosePropsSchema); +export const isDmCloseProps = ajv.compile<DmCloseProps>(DmClosePropsSchema); diff --git a/packages/rest-typings/src/v1/dm/DmCreateProps.ts b/packages/rest-typings/src/v1/dm/DmCreateProps.ts index 3b15bbe2863f10926e189b723a69e5e236d578ae..48903925ea13b8afc762f6b91e63d12eaa6ba43f 100644 --- a/packages/rest-typings/src/v1/dm/DmCreateProps.ts +++ b/packages/rest-typings/src/v1/dm/DmCreateProps.ts @@ -1,6 +1,8 @@ import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); export type DmCreateProps = ( | { diff --git a/packages/rest-typings/src/v1/dm/DmDeleteProps.ts b/packages/rest-typings/src/v1/dm/DmDeleteProps.ts index a0d801300773aea2aa3bbe7711568592f26d17c4..7c96ce9668e3a5f2f8996efe8ef75a873b756bd7 100644 --- a/packages/rest-typings/src/v1/dm/DmDeleteProps.ts +++ b/packages/rest-typings/src/v1/dm/DmDeleteProps.ts @@ -1,6 +1,8 @@ import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); export type DmDeleteProps = | { diff --git a/packages/rest-typings/src/v1/dm/DmHistoryProps.ts b/packages/rest-typings/src/v1/dm/DmHistoryProps.ts index 0a836961f3665519dc42588c66fcf2b934c8e38d..dc8d46f4341df9115d978682e77adc8487e1dc1d 100644 --- a/packages/rest-typings/src/v1/dm/DmHistoryProps.ts +++ b/packages/rest-typings/src/v1/dm/DmHistoryProps.ts @@ -1,7 +1,9 @@ import type { PaginatedRequest } from '@rocket.chat/rest-typings/src/helpers/PaginatedRequest'; import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); export type DmHistoryProps = PaginatedRequest<{ roomId: string; diff --git a/packages/rest-typings/src/v1/dm/DmKickProps.ts b/packages/rest-typings/src/v1/dm/DmKickProps.ts index beca20ef5dc80077df3a4e868f1b7abdbac285ab..eb56b52a3cd6ff263e280ca06d5264b093dc7ace 100644 --- a/packages/rest-typings/src/v1/dm/DmKickProps.ts +++ b/packages/rest-typings/src/v1/dm/DmKickProps.ts @@ -1,6 +1,8 @@ import Ajv, { JSONSchemaType } from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); type DmKickProps = { roomId: string; diff --git a/packages/rest-typings/src/v1/dm/DmLeaveProps.ts b/packages/rest-typings/src/v1/dm/DmLeaveProps.ts index a91ee8ba9a910c2c17aa01ee9bf6f052898cb047..384455a124ae041d8bdc0db61595d7680d906e4c 100644 --- a/packages/rest-typings/src/v1/dm/DmLeaveProps.ts +++ b/packages/rest-typings/src/v1/dm/DmLeaveProps.ts @@ -1,20 +1,38 @@ -import Ajv, { JSONSchemaType } from 'ajv'; +import Ajv from 'ajv'; -const ajv = new Ajv(); +const ajv = new Ajv({ + coerceTypes: true, +}); -export type DmLeaveProps = { - roomId: string; -}; +export type DmLeaveProps = + | { + roomId: string; + } + | { roomName: string }; -const DmLeavePropsSchema: JSONSchemaType<DmLeaveProps> = { - type: 'object', - properties: { - roomId: { - type: 'string', +const DmLeavePropsSchema = { + oneOf: [ + { + type: 'object', + properties: { + roomId: { + type: 'string', + }, + }, + required: ['roomId'], + additionalProperties: false, + }, + { + type: 'object', + properties: { + roomName: { + type: 'string', + }, + }, + required: ['roomName'], + additionalProperties: false, }, - }, - required: ['roomId'], - additionalProperties: false, + ], }; -export const isDmLeaveProps = ajv.compile(DmLeavePropsSchema); +export const isDmLeaveProps = ajv.compile<DmLeaveProps>(DmLeavePropsSchema);