11import { PSUDataItem } from "@PrescriptionStatusUpdate_common/commonTypes"
2+ import AWS from "aws-sdk"
23
3- function getEnvList ( name : string ) : Set < string > {
4- const raw = process . env [ name ] ?? ""
5- return new Set ( raw
6- . split ( "," )
7- . map ( ( s ) => s . trim ( ) . toLowerCase ( ) )
8- . filter ( Boolean ) // Remove empty entries
4+ const ssm = new AWS . SSM ( )
5+
6+ /**
7+ * Fetches the comma-delimited StringList from SSM, normalizes & returns a Set<string>.
8+ */
9+ async function fetchListFromSSM ( paramNameEnvVar : string ) : Promise < Set < string > > {
10+ const paramName = process . env [ paramNameEnvVar ]
11+ if ( ! paramName ) {
12+ throw new Error ( `Missing required env-var ${ paramNameEnvVar } ` )
13+ }
14+ const resp = await ssm
15+ . getParameter ( { Name : paramName , WithDecryption : false } )
16+ . promise ( )
17+
18+ const raw = resp . Parameter ?. Value ?? ""
19+ return new Set (
20+ raw
21+ . split ( "," )
22+ . map ( ( s ) => s . trim ( ) . toLowerCase ( ) )
23+ . filter ( Boolean )
924 )
1025}
1126
12- const enabledSiteODSCodes = getEnvList ( "ENABLED_SITE_ODS_CODES" )
13- const enabledSystems = getEnvList ( "ENABLED_SYSTEMS" )
14- const blockedSiteODSCodes = getEnvList ( "BLOCKED_SITE_ODS_CODES" )
27+ const listsReady : Promise < {
28+ enabledSiteODSCodes : Set < string > ;
29+ enabledSystems : Set < string > ;
30+ blockedSiteODSCodes : Set < string > ;
31+ } > = ( async ( ) => {
32+ const [ enabledSiteODSCodes , enabledSystems , blockedSiteODSCodes ] =
33+ await Promise . all ( [
34+ fetchListFromSSM ( "ENABLED_SITE_ODS_CODES" ) ,
35+ fetchListFromSSM ( "ENABLED_SYSTEMS" ) ,
36+ fetchListFromSSM ( "BLOCKED_SITE_ODS_CODES" )
37+ ] )
38+ return { enabledSiteODSCodes, enabledSystems, blockedSiteODSCodes}
39+ } ) ( )
1540
1641/**
1742 * Given an array of PSUDataItem, only returns those which:
@@ -21,9 +46,15 @@ const blockedSiteODSCodes = getEnvList("BLOCKED_SITE_ODS_CODES")
2146 * @param data - Array of PSUDataItem to be processed
2247 * @returns - the filtered array
2348 */
24- export function checkSiteOrSystemIsNotifyEnabled (
49+ export async function checkSiteOrSystemIsNotifyEnabled (
2550 data : Array < PSUDataItem >
26- ) : Array < PSUDataItem > {
51+ ) : Promise < Array < PSUDataItem > > {
52+ const {
53+ enabledSiteODSCodes,
54+ enabledSystems,
55+ blockedSiteODSCodes
56+ } = await listsReady
57+
2758 return data . filter ( ( item ) => {
2859 const appName = item . ApplicationName . toLowerCase ( )
2960 const odsCode = item . PharmacyODSCode . toLowerCase ( )
0 commit comments