import 'source-map-support/register' ; import { init , getUnsubscribeList , sendEmailAndUpdateUnsubscribers , } from './unsubscribe' ; import * as Sentry from '@sentry/node' ; import config from './config' ; import { getCronitor } from './utils/cronitor' ; const cronitor = getCronitor ( ) ; Sentry . init ( { dsn : config . get ( 'sentryDsn' ) , environment : config . get ( 'env' ) , } ) ; Sentry . configureScope ( ( scope ) => { const functionName = process . env . AWS_LAMBDA_FUNCTION_NAME || `unsubscribe-digest-${ config . get ( 'env' ) }` ; scope . setTag ( 'lambda-function-name' , functionName ) ; } ) ; const handler = async ( ) : Promise < { statusCode : number ; } > => { try { await cronitor ?. run ( ) ; await init ( ) ; const unsubscribeDigests = await getUnsubscribeList ( ) ; for ( const userDigest of unsubscribeDigests ) { await sendEmailAndUpdateUnsubscribers ( userDigest ) ; } await cronitor ?. complete ( ) ; } catch ( err ) { console . error ( err ) ; Sentry . captureException ( err ) ; await Sentry . flush ( 2000 ) ; await cronitor ?. fail ( err . message ) ; throw err ; } return { statusCode : 200 , } ; } ; export { handler } ;