@@ -9,10 +9,11 @@ import type { RateLimiterOptionsToCheck } from 'meteor/rate-limit';
99import { WebApp } from 'meteor/webapp' ;
1010import _ from 'underscore' ;
1111
12+ import { isPlainObject } from '../../../../lib/utils/isPlainObject' ;
1213import { APIClass } from '../../../api/server/ApiClass' ;
1314import type { RateLimiterOptions } from '../../../api/server/api' ;
1415import { API , defaultRateLimiterOptions } from '../../../api/server/api' ;
15- import type { FailureResult , PartialThis , SuccessResult , UnavailableResult } from '../../../api/server/definition' ;
16+ import type { FailureResult , GenericRouteExecutionContext , SuccessResult , UnavailableResult } from '../../../api/server/definition' ;
1617import type { WebhookResponseItem } from '../../../lib/server/functions/processWebhookMessage' ;
1718import { processWebhookMessage } from '../../../lib/server/functions/processWebhookMessage' ;
1819import { settings } from '../../../settings/server' ;
@@ -39,11 +40,10 @@ type IntegrationOptions = {
3940 } ;
4041} ;
4142
42- type IntegrationThis = Omit < PartialThis , 'user' > & {
43+ type IntegrationThis = GenericRouteExecutionContext & {
4344 request : Request & {
4445 integration : IIncomingIntegration ;
4546 } ;
46- urlParams : Record < string , string > ;
4747 user : IUser & { username : RequiredField < IUser , 'username' > } ;
4848} ;
4949
@@ -138,8 +138,8 @@ async function executeIntegrationRest(
138138
139139 const scriptEngine = getEngine ( this . request . integration ) ;
140140
141- let { bodyParams } = this ;
142- const separateResponse = this . bodyParams ? .separateResponse === true ;
141+ let bodyParams = isPlainObject ( this . bodyParams ) ? this . bodyParams : { } ;
142+ const separateResponse = bodyParams . separateResponse === true ;
143143 let scriptResponse : Record < string , any > | undefined ;
144144
145145 if ( scriptEngine . integrationHasValidScript ( this . request . integration ) && this . request . body ) {
@@ -152,21 +152,22 @@ async function executeIntegrationRest(
152152 const contentRaw = Buffer . concat ( buffers ) . toString ( 'utf8' ) ;
153153 const protocol = `${ this . request . headers . get ( 'x-forwarded-proto' ) } :` || 'http:' ;
154154 const url = new URL ( this . request . url , `${ protocol } //${ this . request . headers . get ( 'host' ) } ` ) ;
155+ const query = isPlainObject ( this . queryParams ) ? this . queryParams : { } ;
155156
156157 const request = {
157158 url : {
159+ query,
158160 hash : url . hash ,
159161 search : url . search ,
160- query : this . queryParams ,
161162 pathname : url . pathname ,
162163 path : this . request . url ,
163164 } ,
164165 url_raw : this . request . url ,
165166 url_params : this . urlParams ,
166- content : this . bodyParams ,
167+ content : bodyParams ,
167168 content_raw : contentRaw ,
168169 headers : Object . fromEntries ( this . request . headers . entries ( ) ) ,
169- body : this . bodyParams ,
170+ body : bodyParams ,
170171 user : {
171172 _id : this . user . _id ,
172173 name : this . user . name || '' ,
@@ -191,7 +192,7 @@ async function executeIntegrationRest(
191192 return API . v1 . failure ( result . error ) ;
192193 }
193194
194- bodyParams = result && result . content ;
195+ bodyParams = result ? .content ;
195196
196197 if ( ! ( 'separateResponse' in bodyParams ) ) {
197198 bodyParams . separateResponse = separateResponse ;
@@ -312,8 +313,8 @@ function integrationInfoRest(): { statusCode: number; body: { success: boolean }
312313}
313314
314315class WebHookAPI extends APIClass < '/hooks' > {
315- override async authenticatedRoute ( this : IntegrationThis ) : Promise < IUser | null > {
316- const { integrationId, token } = this . urlParams ;
316+ override async authenticatedRoute ( routeContext : IntegrationThis ) : Promise < IUser | null > {
317+ const { integrationId, token } = routeContext . urlParams ;
317318 const integration = await Integrations . findOneByIdAndToken < IIncomingIntegration > ( integrationId , decodeURIComponent ( token ) ) ;
318319
319320 if ( ! integration ) {
@@ -322,9 +323,9 @@ class WebHookAPI extends APIClass<'/hooks'> {
322323 throw new Error ( 'Invalid integration id or token provided.' ) ;
323324 }
324325
325- this . request . integration = integration ;
326+ routeContext . request . integration = integration ;
326327
327- return Users . findOneById ( this . request . integration . userId ) ;
328+ return Users . findOneById ( routeContext . request . integration . userId ) ;
328329 }
329330
330331 override shouldAddRateLimitToRoute ( options : { rateLimiterOptions ?: RateLimiterOptions | boolean } ) : boolean {
0 commit comments