@@ -13,9 +13,14 @@ import wrap from '@adobe/helix-shared-wrap';
1313import { helixStatus } from '@adobe/helix-status' ;
1414import secrets from '@adobe/helix-shared-secrets' ;
1515import dataAccess from '@adobe/spacecat-shared-data-access' ;
16- import { sqsEventAdapter } from '@adobe/spacecat-shared-utils' ;
17- import { internalServerError , notFound , ok } from '@adobe/spacecat-shared-http-utils' ;
16+ import {
17+ internalServerError ,
18+ notFound ,
19+ ok ,
20+ badRequest ,
21+ } from '@adobe/spacecat-shared-http-utils' ;
1822import { imsClientWrapper } from '@adobe/spacecat-shared-ims-client' ;
23+ import { isNonEmptyObject , sqsEventAdapter } from '@adobe/spacecat-shared-utils' ;
1924
2025import { runOpportunityStatusProcessor as opportunityStatusProcessor } from './tasks/opportunity-status-processor/handler.js' ;
2126import { runDisableImportAuditProcessor as disableImportAuditProcessor } from './tasks/disable-import-audit-processor/handler.js' ;
@@ -31,7 +36,7 @@ const HANDLERS = {
3136 'agent-executor' : agentExecutor ,
3237 'slack-notify' : slackNotify ,
3338 'cwv-demo-suggestions-processor' : cwvDemoSuggestionsProcessor ,
34- dummy : ( message ) => ok ( message ) ,
39+ dummy : ( message ) => ok ( message ) , // for tests
3540} ;
3641
3742// Custom secret name resolver to use the correct secret path
@@ -98,10 +103,15 @@ function isSqsEvent(event) {
98103}
99104
100105export const main = async ( event , context ) => {
101- const { log } = context ;
102- // const isSQSEvent = Array.isArray(context.invocation?.event?.Records);
103- log . debug ( JSON . stringify ( event , null , 2 ) ) ;
104- log . debug ( JSON . stringify ( context , null , 2 ) ) ;
105- const handler = isSqsEvent ( event ) ? runSQS : runDirect ;
106- return handler ( event , context ) ;
106+ if ( isSqsEvent ( event ) ) {
107+ return runSQS ( event , context ) ;
108+ }
109+
110+ const payload = context ?. invocation ?. event ;
111+ if ( ! isNonEmptyObject ( payload ) ) {
112+ context ?. log ?. warn ?. ( 'Direct invocation missing payload' ) ;
113+ return badRequest ( 'Event does not contain a valid message body' ) ;
114+ }
115+
116+ return runDirect ( payload , context ) ;
107117} ;
0 commit comments