@ -7,21 +7,13 @@ import Filter from '../../models/Filter';
import HookLog from '../../models/HookLog' ;
import HookLog from '../../models/HookLog' ;
import { HookLogType } from 'nocodb-sdk' ;
import { HookLogType } from 'nocodb-sdk' ;
export function parseBody (
export function parseBody ( template : string , data : any ) : string {
template : string ,
user : any ,
data : any ,
payload : any
) : string {
if ( ! template ) {
if ( ! template ) {
return template ;
return template ;
}
}
return Handlebars . compile ( template , { noEscape : true } ) ( {
return Handlebars . compile ( template , { noEscape : true } ) ( {
data ,
data
user ,
payload ,
env : process.env
} ) ;
} ) ;
}
}
@ -121,28 +113,24 @@ export async function handleHttpWebHook(apiMeta, user, data) {
// }
// }
}
}
export function axiosRequestMake ( _apiMeta , user , data ) {
export function axiosRequestMake ( _apiMeta , _ user, data ) {
const apiMeta = { . . . _apiMeta } ;
const apiMeta = { . . . _apiMeta } ;
if ( apiMeta . body ) {
if ( apiMeta . body ) {
try {
try {
apiMeta . body = JSON . parse ( apiMeta . body , ( _key , value ) = > {
apiMeta . body = JSON . parse ( apiMeta . body , ( _key , value ) = > {
return typeof value === 'string'
return typeof value === 'string' ? parseBody ( value , data ) : value ;
? parseBody ( value , user , data , apiMeta )
: value ;
} ) ;
} ) ;
} catch ( e ) {
} catch ( e ) {
apiMeta . body = parseBody ( apiMeta . body , user , data , apiMe ta ) ;
apiMeta . body = parseBody ( apiMeta . body , data ) ;
}
}
}
}
if ( apiMeta . auth ) {
if ( apiMeta . auth ) {
try {
try {
apiMeta . auth = JSON . parse ( apiMeta . auth , ( _key , value ) = > {
apiMeta . auth = JSON . parse ( apiMeta . auth , ( _key , value ) = > {
return typeof value === 'string'
return typeof value === 'string' ? parseBody ( value , data ) : value ;
? parseBody ( value , user , data , apiMeta )
: value ;
} ) ;
} ) ;
} catch ( e ) {
} catch ( e ) {
apiMeta . auth = parseBody ( apiMeta . auth , user , data , apiMe ta ) ;
apiMeta . auth = parseBody ( apiMeta . auth , data ) ;
}
}
}
}
apiMeta . response = { } ;
apiMeta . response = { } ;
@ -150,23 +138,18 @@ export function axiosRequestMake(_apiMeta, user, data) {
params : apiMeta.parameters
params : apiMeta.parameters
? apiMeta . parameters . reduce ( ( paramsObj , param ) = > {
? apiMeta . parameters . reduce ( ( paramsObj , param ) = > {
if ( param . name && param . enabled ) {
if ( param . name && param . enabled ) {
paramsObj [ param . name ] = parseBody ( param . value , user , data , apiMe ta ) ;
paramsObj [ param . name ] = parseBody ( param . value , data ) ;
}
}
return paramsObj ;
return paramsObj ;
} , { } )
} , { } )
: { } ,
: { } ,
url : parseBody ( apiMeta . path , user , data , apiMe ta ) ,
url : parseBody ( apiMeta . path , data ) ,
method : apiMeta.method ,
method : apiMeta.method ,
data : apiMeta.body ,
data : apiMeta.body ,
headers : apiMeta.headers
headers : apiMeta.headers
? apiMeta . headers . reduce ( ( headersObj , header ) = > {
? apiMeta . headers . reduce ( ( headersObj , header ) = > {
if ( header . name && header . enabled ) {
if ( header . name && header . enabled ) {
headersObj [ header . name ] = parseBody (
headersObj [ header . name ] = parseBody ( header . value , data ) ;
header . value ,
user ,
data ,
apiMeta
) ;
}
}
return headersObj ;
return headersObj ;
} , { } )
} , { } )
@ -208,24 +191,9 @@ export async function invokeWebhook(
case 'Email' :
case 'Email' :
{
{
const res = await ( await NcPluginMgrv2 . emailAdapter ( ) ) ? . mailSend ( {
const res = await ( await NcPluginMgrv2 . emailAdapter ( ) ) ? . mailSend ( {
to : parseBody (
to : parseBody ( notification ? . payload ? . to , data ) ,
notification ? . payload ? . to ,
subject : parseBody ( notification ? . payload ? . subject , data ) ,
user ,
html : parseBody ( notification ? . payload ? . body , data )
data ,
notification ? . payload
) ,
subject : parseBody (
notification ? . payload ? . subject ,
user ,
data ,
notification ? . payload
) ,
html : parseBody (
notification ? . payload ? . body ,
user ,
data ,
notification ? . payload
)
} ) ;
} ) ;
hookLog = {
hookLog = {
. . . hook ,
. . . hook ,
@ -258,16 +226,9 @@ export async function invokeWebhook(
const res = await (
const res = await (
await NcPluginMgrv2 . webhookNotificationAdapters ( notification . type )
await NcPluginMgrv2 . webhookNotificationAdapters ( notification . type )
) . sendMessage (
) . sendMessage (
parseBody (
parseBody ( notification ? . payload ? . body , data ) ,
notification ? . payload ? . body ,
user ,
data ,
notification ? . payload
) ,
JSON . parse ( JSON . stringify ( notification ? . payload ) , ( _key , value ) = > {
JSON . parse ( JSON . stringify ( notification ? . payload ) , ( _key , value ) = > {
return typeof value === 'string'
return typeof value === 'string' ? parseBody ( value , data ) : value ;
? parseBody ( value , user , data , notification ? . payload )
: value ;
} )
} )
) ;
) ;