From 3a801dc2666846fa721fce3c5bd343fc84a3818f Mon Sep 17 00:00:00 2001 From: eldarlandman Date: Sun, 16 Jun 2024 11:53:02 +0300 Subject: [PATCH] Customize activity lambda and align it along with the documentation --- src/PXActivities.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/PXActivities.ts b/src/PXActivities.ts index 204f5c7..6ae8029 100644 --- a/src/PXActivities.ts +++ b/src/PXActivities.ts @@ -1,12 +1,11 @@ -import { CloudFrontResponseEvent, CloudFrontRequestEvent, CloudFrontResponseResult, Context, CloudFrontResponseHandler } from 'aws-lambda'; -import { createHumanActivitiesHandler } from './px/humansecurity'; +import { CloudFrontResponseEvent, CloudFrontResponseResult, Context, CloudFrontResponseHandler } from 'aws-lambda'; +import { HumanSecurityPostEnforcer } from './px/humansecurity'; import { getConfigAsync } from './custom/config'; // define a handler -let activitiesHandler: (event:CloudFrontResponseEvent, context: Context)=> - Promise; +let activitiesHandler: HumanSecurityPostEnforcer export async function handler( event: CloudFrontResponseEvent, context: Context @@ -14,8 +13,14 @@ export async function handler( if (!activitiesHandler){ const config = await getConfigAsync(); - activitiesHandler = createHumanActivitiesHandler(config); //(event: CloudFrontResponseEvent, context: Context) => Promise; + activitiesHandler = HumanSecurityPostEnforcer.initialize(config); //(event: CloudFrontResponseEvent, context: Context) => Promise; } + const request = event.Records[0].cf.request + const response = event.Records[0].cf.response - return activitiesHandler(event,context); + // call and await the postEnforce() function + await activitiesHandler.postEnforce(request,response); + + // return the response + return response; }