diff --git a/apps/meteor/app/api/server/definition.ts b/apps/meteor/app/api/server/definition.ts index 1b4271ab56ea4..69e2736e5abd0 100644 --- a/apps/meteor/app/api/server/definition.ts +++ b/apps/meteor/app/api/server/definition.ts @@ -150,9 +150,11 @@ export type PartialThis = { readonly queryOperations?: string[]; readonly queryFields?: string[]; readonly logger: Logger; + readonly route: string; }; type ActionThis = { + route: string; readonly requestIp: string; urlParams: UrlParams; readonly response: Response; diff --git a/apps/meteor/app/api/server/helpers/parseJsonQuery.ts b/apps/meteor/app/api/server/helpers/parseJsonQuery.ts index 9879f1cb4f9bc..ea307c9f59844 100644 --- a/apps/meteor/app/api/server/helpers/parseJsonQuery.ts +++ b/apps/meteor/app/api/server/helpers/parseJsonQuery.ts @@ -24,7 +24,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ */ query: Record; }> { - const { userId, queryParams: params, logger, queryFields, queryOperations, response, path } = api; + const { userId, queryParams: params, logger, queryFields, queryOperations, response, route } = api; let sort; if (params.sort) { @@ -52,7 +52,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ let fields: Record | undefined; if (params.fields && isUnsafeQueryParamsAllowed) { try { - apiDeprecationLogger.parameter(api.path, 'fields', '8.0.0', response, messageGenerator); + apiDeprecationLogger.parameter(route, 'fields', '8.0.0', response, messageGenerator); fields = JSON.parse(params.fields) as Record; Object.entries(fields).forEach(([key, value]) => { if (value !== 1 && value !== 0) { @@ -72,7 +72,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ // Verify the user's selected fields only contains ones which their role allows if (typeof fields === 'object') { let nonSelectableFields = Object.keys(API.v1.defaultFieldsToExclude); - if (path.includes('/v1/users.')) { + if (route.includes('/v1/users.')) { nonSelectableFields = nonSelectableFields.concat( Object.keys( (await hasPermissionAsync(userId, 'view-full-other-user-info')) @@ -91,7 +91,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ // Limit the fields by default fields = Object.assign({}, fields, API.v1.defaultFieldsToExclude); - if (path.includes('/v1/users.')) { + if (route.includes('/v1/users.')) { if (await hasPermissionAsync(userId, 'view-full-other-user-info')) { fields = Object.assign(fields, API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser); } else { @@ -101,7 +101,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ let query: Record = {}; if (params.query && isUnsafeQueryParamsAllowed) { - apiDeprecationLogger.parameter(api.path, 'query', '8.0.0', response, messageGenerator); + apiDeprecationLogger.parameter(route, 'query', '8.0.0', response, messageGenerator); try { query = ejson.parse(params.query); query = clean(query, pathAllowConf.def); @@ -117,7 +117,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ if (typeof query === 'object') { let nonQueryableFields = Object.keys(API.v1.defaultFieldsToExclude); - if (api.path.includes('/v1/users.')) { + if (route.includes('/v1/users.')) { if (await hasPermissionAsync(userId, 'view-full-other-user-info')) { nonQueryableFields = nonQueryableFields.concat(Object.keys(API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser)); } else { diff --git a/apps/meteor/app/api/server/router.ts b/apps/meteor/app/api/server/router.ts index 86e1274322389..c37100c18b223 100644 --- a/apps/meteor/app/api/server/router.ts +++ b/apps/meteor/app/api/server/router.ts @@ -59,12 +59,6 @@ declare module 'hono' { } } -declare global { - interface Request { - route: string; - } -} - export class Router< TBasePath extends string, TOperations extends { @@ -190,7 +184,6 @@ export class Router< this.innerRouter[method.toLowerCase() as Lowercase](`/${subpath}`.replace('//', '/'), ...middlewares, async (c) => { const { req, res } = c; - req.raw.route = `${c.var.route ?? ''}${subpath}`; const queryParams = this.parseQueryParams(req); @@ -224,6 +217,8 @@ export class Router< } } + const request = req.raw.clone(); + const { body, statusCode = 200, @@ -234,11 +229,12 @@ export class Router< urlParams: req.param(), queryParams, bodyParams, - request: req.raw.clone(), + request, path: req.path, response: res, + route: req.routePath, } as any, - [req.raw.clone()], + [request], ); if (process.env.NODE_ENV === 'test' || process.env.TEST_MODE) { const responseValidatorFn = options?.response?.[statusCode]; @@ -376,15 +372,9 @@ export class Router< router.use( this.base, honoAdapter( - hono - .use(`${this.base}/*`, (c, next) => { - c.set('route', `${c.var.route || ''}${this.base}`); - return next(); - }) - .route(this.base, this.innerRouter) - .options('*', (c) => { - return c.body('OK'); - }), + hono.route(this.base, this.innerRouter).options('*', (c) => { + return c.body('OK'); + }), ), ); return router; diff --git a/apps/meteor/app/api/server/v1/oauthapps.ts b/apps/meteor/app/api/server/v1/oauthapps.ts index fbdaf37ac2313..78ab03e19621c 100644 --- a/apps/meteor/app/api/server/v1/oauthapps.ts +++ b/apps/meteor/app/api/server/v1/oauthapps.ts @@ -37,7 +37,7 @@ API.v1.addRoute( } if ('appId' in this.queryParams) { - apiDeprecationLogger.parameter(this.request.route, 'appId', '7.0.0', this.response); + apiDeprecationLogger.parameter(this.route, 'appId', '7.0.0', this.response); } return API.v1.success({ diff --git a/apps/meteor/app/api/server/v1/roles.ts b/apps/meteor/app/api/server/v1/roles.ts index ac559d3ed1320..fc17ed4656221 100644 --- a/apps/meteor/app/api/server/v1/roles.ts +++ b/apps/meteor/app/api/server/v1/roles.ts @@ -70,7 +70,7 @@ API.v1.addRoute( return API.v1.failure('error-invalid-role-properties'); } - apiDeprecationLogger.parameter(this.request.route, 'roleName', '7.0.0', this.response); + apiDeprecationLogger.parameter(this.route, 'roleName', '7.0.0', this.response); } const role = roleId ? await Roles.findOneById(roleId) : await Roles.findOneByIdOrName(roleName as string); @@ -124,7 +124,7 @@ API.v1.addRoute( } apiDeprecationLogger.deprecatedParameterUsage( - this.request.route, + this.route, 'role', '7.0.0', this.response, @@ -197,7 +197,7 @@ API.v1.addRoute( return API.v1.failure('error-invalid-role-properties'); } - apiDeprecationLogger.parameter(this.request.route, 'roleName', '7.0.0', this.response); + apiDeprecationLogger.parameter(this.route, 'roleName', '7.0.0', this.response); } const user = await Users.findOneByUsername(username); diff --git a/apps/meteor/ee/server/api/engagementDashboard/channels.ts b/apps/meteor/ee/server/api/engagementDashboard/channels.ts index ebd0924fb2d8a..9b224c63bb1ab 100644 --- a/apps/meteor/ee/server/api/engagementDashboard/channels.ts +++ b/apps/meteor/ee/server/api/engagementDashboard/channels.ts @@ -58,7 +58,7 @@ API.v1.addRoute( if (hideRoomsWithNoActivity === undefined) { apiDeprecationLogger.deprecatedParameterUsage( - this.request.route, + this.route, 'hideRoomsWithNoActivity', '7.0.0', this.response, diff --git a/apps/meteor/ee/server/apps/communication/rest.ts b/apps/meteor/ee/server/apps/communication/rest.ts index 8af2aefe6be6d..664e7da39308a 100644 --- a/apps/meteor/ee/server/apps/communication/rest.ts +++ b/apps/meteor/ee/server/apps/communication/rest.ts @@ -229,7 +229,7 @@ export class AppsRestApi { // Gets the Apps from the marketplace if ('marketplace' in this.queryParams && this.queryParams.marketplace) { - apiDeprecationLogger.endpoint(this.request.route, '7.0.0', this.response, 'Use /apps/marketplace to get the apps list.'); + apiDeprecationLogger.endpoint(this.route, '7.0.0', this.response, 'Use /apps/marketplace to get the apps list.'); try { const apps = await fetchMarketplaceApps(); @@ -253,7 +253,7 @@ export class AppsRestApi { } if ('categories' in this.queryParams && this.queryParams.categories) { - apiDeprecationLogger.endpoint(this.request.route, '7.0.0', this.response, 'Use /apps/categories to get the categories list.'); + apiDeprecationLogger.endpoint(this.route, '7.0.0', this.response, 'Use /apps/categories to get the categories list.'); try { const categories = await fetchMarketplaceCategories(); return API.v1.success(categories); @@ -282,7 +282,7 @@ export class AppsRestApi { this.queryParams.buildExternalUrl && this.queryParams.appId ) { - apiDeprecationLogger.endpoint(this.request.route, '7.0.0', this.response, 'Use /apps/buildExternalUrl to get the modal URLs.'); + apiDeprecationLogger.endpoint(this.route, '7.0.0', this.response, 'Use /apps/buildExternalUrl to get the modal URLs.'); const workspaceId = settings.get('Cloud_Workspace_Id'); if (!this.queryParams.purchaseType || !purchaseTypes.has(this.queryParams.purchaseType)) { @@ -304,7 +304,7 @@ export class AppsRestApi { }?workspaceId=${workspaceId}&token=${token.token}&seats=${seats}`, }); } - apiDeprecationLogger.endpoint(this.request.route, '7.0.0', this.response, 'Use /apps/installed to get the installed apps list.'); + apiDeprecationLogger.endpoint(this.route, '7.0.0', this.response, 'Use /apps/installed to get the installed apps list.'); const proxiedApps = await manager.get(); const apps = await Promise.all(proxiedApps.map((app) => formatAppInstanceForRest(app)));