diff --git a/apps/meteor/client/hooks/useEndpointAction.ts b/apps/meteor/client/hooks/useEndpointAction.ts index 168e702433ad5..ac386480973cb 100644 --- a/apps/meteor/client/hooks/useEndpointAction.ts +++ b/apps/meteor/client/hooks/useEndpointAction.ts @@ -6,9 +6,7 @@ import { useCallback } from 'react'; export const useEndpointAction = >( method: TMethod, path: TPath, - params: Serialized>> = {} as Serialized< - OperationParams> - >, + params?: OperationParams>, successMessage?: string, ): (() => Promise>>>) => { const sendData = useEndpoint(method, path); @@ -16,7 +14,7 @@ export const useEndpointAction = { try { - const data = await sendData(params); + const data = await sendData(params as any); if (successMessage) { dispatchToastMessage({ type: 'success', message: successMessage }); diff --git a/apps/meteor/client/hooks/useEndpointActionExperimental.ts b/apps/meteor/client/hooks/useEndpointActionExperimental.ts index 45ed08906f712..f05144491c459 100644 --- a/apps/meteor/client/hooks/useEndpointActionExperimental.ts +++ b/apps/meteor/client/hooks/useEndpointActionExperimental.ts @@ -8,7 +8,7 @@ export const useEndpointActionExperimental = >>, + params: OperationParams>, ) => Promise>>>) => { const sendData = useEndpoint(method, path); const dispatchToastMessage = useToastMessageDispatch(); diff --git a/apps/meteor/client/hooks/useEndpointData.ts b/apps/meteor/client/hooks/useEndpointData.ts index 4c7a289da0298..f29eb2c161bf2 100644 --- a/apps/meteor/client/hooks/useEndpointData.ts +++ b/apps/meteor/client/hooks/useEndpointData.ts @@ -7,14 +7,7 @@ import { AsyncState, useAsyncState } from './useAsyncState'; export const useEndpointData = >( endpoint: TPath, - params: void extends OperationParams<'GET', MatchPathPattern> - ? void - : Serialized>> = undefined as void extends OperationParams< - 'GET', - MatchPathPattern - > - ? void - : Serialized>>, + params?: OperationParams<'GET', MatchPathPattern>, initialValue?: | Serialized>> | (() => Serialized>>), @@ -27,7 +20,7 @@ export const useEndpointData = >( const fetchData = useCallback(() => { reset(); - getData(params) + getData(params as any) .then(resolve) .catch((error) => { console.error(error); diff --git a/apps/meteor/client/providers/ServerProvider.tsx b/apps/meteor/client/providers/ServerProvider.tsx index 50d288d73ec11..8861acfbf501d 100644 --- a/apps/meteor/client/providers/ServerProvider.tsx +++ b/apps/meteor/client/providers/ServerProvider.tsx @@ -26,24 +26,27 @@ const callMethod = ( const callEndpoint = >( method: TMethod, path: TPath, - params: Serialized>>, + params: OperationParams>, ): Promise>>> => { switch (method) { case 'GET': - return APIClient.get(path as Parameters[0], params as any | undefined) as any; + return APIClient.get(path as any, params as any) as any; case 'POST': - return APIClient.post(path as Parameters[0], params as never) as ReturnType; + return APIClient.post(path as any, params as any) as any; + + case 'PUT': + return APIClient.put(path as any, params as any) as any; case 'DELETE': - return APIClient.delete(path as Parameters[0], params as never) as ReturnType; + return APIClient.delete(path as any, params as any) as any; default: throw new Error('Invalid HTTP method'); } }; -const uploadToEndpoint = (endpoint: PathFor<'POST'>, formData: any): Promise => APIClient.post(endpoint, formData as never); +const uploadToEndpoint = (endpoint: PathFor<'POST'>, formData: any): Promise => APIClient.post(endpoint as any, formData); const getStream = (streamName: string, options: {} = {}): ((eventName: string, callback: (data: T) => void) => () => void) => { const streamer = Meteor.StreamerCentral.instances[streamName] diff --git a/apps/meteor/client/stories/contexts/ServerContextMock.tsx b/apps/meteor/client/stories/contexts/ServerContextMock.tsx index bba776e442dfc..be29bb78172bb 100644 --- a/apps/meteor/client/stories/contexts/ServerContextMock.tsx +++ b/apps/meteor/client/stories/contexts/ServerContextMock.tsx @@ -91,7 +91,7 @@ const ServerContextMock = ({ return { match: (method: string, path: string): boolean => _method === method && pathRegexp.test(path[0] === '/' ? path : `/v1/${path}`), - handler, + handler: handler as any, }; }, ); @@ -99,7 +99,7 @@ const ServerContextMock = ({ const _callEndpoint: ServerContextValue['callEndpoint'] = async >( method: TMethod, path: TPath, - params: Serialized>>, + params: OperationParams>, ): Promise>>> => { const mockedEndpoint = mockedEndpoints.find((endpoint) => endpoint.match(method, path)); const handler = mockedEndpoint?.handler; diff --git a/apps/meteor/client/views/admin/apps/AppReleases.tsx b/apps/meteor/client/views/admin/apps/AppReleases.tsx index ac44fa93e3c1b..f11deb7a38be1 100644 --- a/apps/meteor/client/views/admin/apps/AppReleases.tsx +++ b/apps/meteor/client/views/admin/apps/AppReleases.tsx @@ -16,7 +16,7 @@ type release = { }; const AppReleases = ({ id }: { id: string }): JSX.Element => { - const { value, phase, error } = useEndpointData(`/apps/${id}/versions`); + const { value, phase, error } = useEndpointData(`/apps/${id}/versions`) as any; const [releases, setReleases] = useState([] as release[]); @@ -29,7 +29,7 @@ const AppReleases = ({ id }: { id: string }): JSX.Element => { const { apps } = value; setReleases( - apps.map((app) => ({ + apps.map((app: any) => ({ version: app.version, createdDate: app.createdDate, detailedChangelog: app.detailedChangelog, diff --git a/apps/meteor/client/views/admin/apps/hooks/useAppInfo.ts b/apps/meteor/client/views/admin/apps/hooks/useAppInfo.ts index f7450f408f1d0..435406d0301ea 100644 --- a/apps/meteor/client/views/admin/apps/hooks/useAppInfo.ts +++ b/apps/meteor/client/views/admin/apps/hooks/useAppInfo.ts @@ -1,5 +1,5 @@ import { App } from '@rocket.chat/core-typings'; -import { useEndpoint, EndpointFunction } from '@rocket.chat/ui-contexts'; +import { useEndpoint } from '@rocket.chat/ui-contexts'; import { useState, useEffect, useContext } from 'react'; import { ISettings } from '../../../../../app/apps/client/@types/IOrchestrator'; @@ -29,7 +29,7 @@ export const useAppInfo = (appId: string): AppInfo | undefined => { const getApis = useEndpoint('GET', `/apps/${appId}/apis`); // TODO: remove EndpointFunction<'GET', 'apps/:id'> - const getBundledIn = useEndpoint('GET', `/apps/${appId}`) as EndpointFunction<'GET', '/apps/:id'>; + const getBundledIn = useEndpoint('GET', `/apps/${appId}`) as any; useEffect(() => { const apps: App[] = []; @@ -70,7 +70,7 @@ export const useAppInfo = (appId: string): AppInfo | undefined => { update: 'true', appVersion: appId, }) - .then(({ app }) => { + .then(({ app }: any) => { appResult.tosLink = app.tosLink; appResult.privacyLink = app.privacyLink; return getBundledInApp(app); diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/channels/useChannelsList.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/channels/useChannelsList.ts index 819ac00c4fd9e..8406c1f4c01fb 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/channels/useChannelsList.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/channels/useChannelsList.ts @@ -19,8 +19,8 @@ export const useChannelsList = ({ period, offset, count }: UseChannelsListOption const { start, end } = getPeriodRange(period); const response = await getChannelsList({ - start: start.toISOString(), - end: end.toISOString(), + start, + end, offset, count, }); diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessageOrigins.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessageOrigins.ts index 49e0bee70db15..28354f4617497 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessageOrigins.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessageOrigins.ts @@ -15,8 +15,8 @@ export const useMessageOrigins = ({ period }: UseMessageOriginsOptions) => { const { start, end } = getPeriodRange(period); const response = await getMessageOrigins({ - start: start.toISOString(), - end: end.toISOString(), + start, + end, }); return response diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessagesSent.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessagesSent.ts index f5147fa7db033..427db46816b45 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessagesSent.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useMessagesSent.ts @@ -15,8 +15,8 @@ export const useMessagesSent = ({ period }: UseMessagesSentOptions) => { const { start, end } = getPeriodRange(period); const response = await getMessagesSent({ - start: start.toISOString(), - end: end.toISOString(), + start, + end, }); return response diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useTopFivePopularChannels.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useTopFivePopularChannels.ts index 1bf1c2db8827e..2672427c4aa52 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useTopFivePopularChannels.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/messages/useTopFivePopularChannels.ts @@ -15,8 +15,8 @@ export const useTopFivePopularChannels = ({ period }: UseTopFivePopularChannelsO const { start, end } = getPeriodRange(period); const response = await getTopFivePopularChannels({ - start: start.toISOString(), - end: end.toISOString(), + start, + end, }); return response diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useActiveUsers.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useActiveUsers.ts index 9482888c5e030..6e618a5d63f1c 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useActiveUsers.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useActiveUsers.ts @@ -16,8 +16,8 @@ export const useActiveUsers = ({ utc }: UseActiveUsersOptions) => { const { start, end } = getPeriodRange('last 30 days', utc); const response = await getActiveUsers({ - start: (utc ? moment.utc(start) : moment(start)).subtract(29, 'days').toISOString(), - end: end.toISOString(), + start: (utc ? moment.utc(start) : moment(start)).subtract(29, 'days').toDate(), + end, }); return response diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useHourlyChatActivity.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useHourlyChatActivity.ts index a79330cdb513f..84db37eb8b0de 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useHourlyChatActivity.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useHourlyChatActivity.ts @@ -17,7 +17,7 @@ export const useHourlyChatActivity = ({ displacement, utc }: UseHourlyChatActivi const day = (utc ? moment.utc().endOf('day') : moment().endOf('day')).subtract(displacement, 'days').toDate(); const response = await getHourlyChatActivity({ - start: day.toISOString(), + start: day, }); return response diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useNewUsers.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useNewUsers.ts index 1a40fe0ba9803..9e9294ed6c996 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useNewUsers.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useNewUsers.ts @@ -15,8 +15,8 @@ export const useNewUsers = ({ period, utc }: UseNewUsersOptions) => { const { start, end } = getPeriodRange(period, utc); const response = await getNewUsers({ - start: start.toISOString(), - end: end.toISOString(), + start, + end, }); return response diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useUsersByTimeOfTheDay.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useUsersByTimeOfTheDay.ts index 71a231c999d3c..16af4bde2a83b 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useUsersByTimeOfTheDay.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useUsersByTimeOfTheDay.ts @@ -15,8 +15,8 @@ export const useUsersByTimeOfTheDay = ({ period, utc }: UseUsersByTimeOfTheDayOp const { start, end } = getPeriodRange(period, utc); const response = await getUsersByTimeOfTheDay({ - start: start.toISOString(), - end: end.toISOString(), + start, + end, }); return response diff --git a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useWeeklyChatActivity.ts b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useWeeklyChatActivity.ts index 28415bc398e18..4851bb16cf953 100644 --- a/apps/meteor/ee/client/views/admin/engagementDashboard/users/useWeeklyChatActivity.ts +++ b/apps/meteor/ee/client/views/admin/engagementDashboard/users/useWeeklyChatActivity.ts @@ -17,7 +17,7 @@ export const useWeeklyChatActivity = ({ displacement, utc }: UseWeeklyChatActivi const day = (utc ? moment.utc().endOf('day') : moment().endOf('day')).subtract(displacement, 'weeks').toDate(); const response = await getWeeklyChatActivity({ - start: day.toISOString(), + start: day, }); return response diff --git a/packages/rest-typings/src/index.ts b/packages/rest-typings/src/index.ts index effe05d681f58..5a268a04413f4 100644 --- a/packages/rest-typings/src/index.ts +++ b/packages/rest-typings/src/index.ts @@ -170,11 +170,7 @@ export type JoinPathPattern; -type GetParams = TOperation extends (...args: any) => any - ? Parameters[0] extends void - ? void - : Parameters[0] - : never; +type GetParams = TOperation extends (...args: any) => any ? Parameters[0] : never; type GetResult = TOperation extends (...args: any) => any ? ReturnType : never; diff --git a/packages/ui-contexts/src/ServerContext/ServerContext.ts b/packages/ui-contexts/src/ServerContext/ServerContext.ts index 41fe3215f4e49..08455d79cbb98 100644 --- a/packages/ui-contexts/src/ServerContext/ServerContext.ts +++ b/packages/ui-contexts/src/ServerContext/ServerContext.ts @@ -20,7 +20,7 @@ export type ServerContextValue = { callEndpoint: >( method: TMethod, path: TPath, - params: Serialized>>, + params: OperationParams>, ) => Promise>>>; uploadToEndpoint: ( endpoint: PathFor<'POST'>, diff --git a/packages/ui-contexts/src/hooks/useEndpoint.ts b/packages/ui-contexts/src/hooks/useEndpoint.ts index 408e52828cb60..19dd00950bfe7 100644 --- a/packages/ui-contexts/src/hooks/useEndpoint.ts +++ b/packages/ui-contexts/src/hooks/useEndpoint.ts @@ -4,9 +4,12 @@ import { useCallback, useContext } from 'react'; import { ServerContext } from '../ServerContext'; -export type EndpointFunction = ( - params: Serialized>, -) => Promise>>; +export type EndpointFunction = undefined extends OperationParams< + TMethod, + TPathPattern +> + ? (params?: OperationParams) => Promise>> + : (params: OperationParams) => Promise>>; export const useEndpoint = >( method: TMethod, @@ -14,8 +17,5 @@ export const useEndpoint = > => { const { callEndpoint } = useContext(ServerContext); - return useCallback( - (params: Serialized>>) => callEndpoint(method, path, params), - [callEndpoint, path, method], - ); + return useCallback((params: any) => callEndpoint(method, path, params), [callEndpoint, path, method]); };