From f6c5485909f62376006bce70bbe2279a3f66e574 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 24 Jun 2025 09:05:40 +0000 Subject: [PATCH 1/5] Update access bloc --- packages/specification/eps-prescription-status-update-api.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/specification/eps-prescription-status-update-api.yaml b/packages/specification/eps-prescription-status-update-api.yaml index 60dd5d7d6d..94ecc2fad2 100755 --- a/packages/specification/eps-prescription-status-update-api.yaml +++ b/packages/specification/eps-prescription-status-update-api.yaml @@ -442,6 +442,9 @@ x-nhsd-apim: - title: Application Restricted grants: app-level3: [] + - title: API Key Restricted + grants: + app-level0: [] target: type: external healthcheck: /_status From 0e43859b60e3502507a27fe198a99cdae89a2d5a Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 24 Jun 2025 09:09:47 +0000 Subject: [PATCH 2/5] Fix docker container --- .devcontainer/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0a6457962a..0281353ef8 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update \ jq apt-transport-https ca-certificates gnupg-agent \ software-properties-common bash-completion python3-pip make libbz2-dev \ libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev \ - xz-utils tk-dev liblzma-dev netcat libyaml-dev + xz-utils tk-dev liblzma-dev netcat-traditional libyaml-dev # install aws stuff RUN wget -O /tmp/awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" && \ From 2a6fadb7a5df2566a5a06e1f010421c7b01f8393 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Tue, 24 Jun 2025 10:26:56 +0000 Subject: [PATCH 3/5] Add app-level0 to the security bloc --- packages/specification/eps-prescription-status-update-api.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/specification/eps-prescription-status-update-api.yaml b/packages/specification/eps-prescription-status-update-api.yaml index 94ecc2fad2..a3eac1a977 100755 --- a/packages/specification/eps-prescription-status-update-api.yaml +++ b/packages/specification/eps-prescription-status-update-api.yaml @@ -435,6 +435,7 @@ components: $ref: schemas/resources/CheckPrescriptionStatusUpdates.yaml security: - app-level3: [] + - app-level0: [] x-nhsd-apim: temporary: false monitoring: true From bce0faa9fa513599eb63327cbc15651be11f50b9 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Wed, 25 Jun 2025 10:32:19 +0000 Subject: [PATCH 4/5] Update logging levels and content --- .../nhsNotifyLambda/src/nhsNotifyLambda.ts | 12 ++++++------ packages/nhsNotifyLambda/src/utils.ts | 19 +++++++++++++------ .../nhsNotifyLambda/tests/testUtils.test.ts | 19 ------------------- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/packages/nhsNotifyLambda/src/nhsNotifyLambda.ts b/packages/nhsNotifyLambda/src/nhsNotifyLambda.ts index df0634877a..641fce3007 100644 --- a/packages/nhsNotifyLambda/src/nhsNotifyLambda.ts +++ b/packages/nhsNotifyLambda/src/nhsNotifyLambda.ts @@ -28,7 +28,6 @@ async function processBatch( routingId: string ): Promise { if (messages.length === 0) { - console.log("No messages to process") logger.info("No messages to process") return } @@ -57,8 +56,10 @@ async function processBatch( } if (processed.length) { - await addPrescriptionMessagesToNotificationStateStore(logger, processed) - await removeSQSMessages(logger, processed) + await Promise.all([ + addPrescriptionMessagesToNotificationStateStore(logger, processed), + removeSQSMessages(logger, processed) + ]) } } @@ -87,7 +88,6 @@ async function drainAndProcess(routingId: string): Promise { while (!empty) { const {messages, isEmpty} = await drainQueue(logger, 100) empty = isEmpty - console.log(messages) await processBatch(messages, routingId) } } @@ -106,9 +106,9 @@ export const lambdaHandler = async ( throw new Error("No Routing Plan ID found") } - logger.info("NHS Notify lambda triggered by scheduler", {event}) - logger.info("Routing Plan ID:", {routingId}) + logger.info("NHS Notify lambda triggered by scheduler", {event, routingId}) + // Done sequentially so that the queue report is accurate. await reportQueueStatus(logger) await drainAndProcess(routingId) } diff --git a/packages/nhsNotifyLambda/src/utils.ts b/packages/nhsNotifyLambda/src/utils.ts index ba9563c674..7f6ee701ed 100644 --- a/packages/nhsNotifyLambda/src/utils.ts +++ b/packages/nhsNotifyLambda/src/utils.ts @@ -357,14 +357,19 @@ export async function checkCooldownForUpdate( TableName: dynamoTable, Key: { NHSNumber: update.PatientNHSNumber, - ODSCode: update.PharmacyODSCode + ODSCode: update.PharmacyODSCode, + requestID: update.RequestID } }) const {Item} = await docClient.send(getCmd) // If no previous record, we're okay to send a notification if (!Item?.LastNotificationRequestTimestamp) { - logger.info("No previous notification state found. Notification allowed.") + logger.debug("No previous notification state found. Notification allowed.", { + NHSNumber: update.PatientNHSNumber, + ODSCode: update.PharmacyODSCode, + requestID: update.RequestID + }) return true } @@ -374,19 +379,21 @@ export async function checkCooldownForUpdate( const secondsSince = Math.floor((nowTs - lastTs) / 1000) if (secondsSince > cooldownPeriod) { - logger.info("Cooldown period has passed. Notification allowed.", { + logger.debug("Cooldown period has passed. Notification allowed.", { NHSNumber: update.PatientNHSNumber, ODSCode: update.PharmacyODSCode, cooldownPeriod, - secondsSince + secondsSince, + requestID: update.RequestID }) return true } else { - logger.info("Within cooldown period. Notification suppressed.", { + logger.debug("Within cooldown period. Notification suppressed.", { NHSNumber: update.PatientNHSNumber, ODSCode: update.PharmacyODSCode, cooldownPeriod, - secondsSince + secondsSince, + requestID: update.RequestID }) return false } diff --git a/packages/nhsNotifyLambda/tests/testUtils.test.ts b/packages/nhsNotifyLambda/tests/testUtils.test.ts index 604e136e8b..2dec620426 100644 --- a/packages/nhsNotifyLambda/tests/testUtils.test.ts +++ b/packages/nhsNotifyLambda/tests/testUtils.test.ts @@ -377,9 +377,6 @@ describe("NHS notify lambda helper functions", () => { const result = await checkCooldownForUpdate(logger, update, 900) expect(sendSpy).toHaveBeenCalledWith(expect.any(GetCommand)) - expect(infoSpy).toHaveBeenCalledWith( - "No previous notification state found. Notification allowed." - ) expect(result).toBe(true) }) @@ -392,10 +389,6 @@ describe("NHS notify lambda helper functions", () => { const update = constructPSUDataItemMessage().PSUDataItem const result = await checkCooldownForUpdate(logger, update, 900) - expect(infoSpy).toHaveBeenCalledWith( - "Cooldown period has passed. Notification allowed.", - expect.objectContaining({secondsSince: expect.any(Number)}) - ) expect(result).toBe(true) }) @@ -408,10 +401,6 @@ describe("NHS notify lambda helper functions", () => { const update = constructPSUDataItemMessage().PSUDataItem const result = await checkCooldownForUpdate(logger, update, 900) - expect(infoSpy).toHaveBeenCalledWith( - "Within cooldown period. Notification suppressed.", - expect.objectContaining({secondsSince: expect.any(Number)}) - ) expect(result).toBe(false) }) @@ -425,10 +414,6 @@ describe("NHS notify lambda helper functions", () => { const update = constructPSUDataItemMessage().PSUDataItem const result = await checkCooldownForUpdate(logger, update, 60) - expect(infoSpy).toHaveBeenCalledWith( - "Within cooldown period. Notification suppressed.", - expect.objectContaining({secondsSince: expect.any(Number)}) - ) expect(result).toBe(false) }) @@ -438,10 +423,6 @@ describe("NHS notify lambda helper functions", () => { const update = constructPSUDataItemMessage().PSUDataItem await expect(checkCooldownForUpdate(logger, update)).rejects.toThrow("DDB failure") - expect(errorSpy).toHaveBeenCalledWith( - "Error checking cooldown state", - expect.objectContaining({error: awsErr}) - ) }) it("does nothing when passed an empty array", async () => { From 8049336380000cad032bb4ebeb4c7f6d4bf91a56 Mon Sep 17 00:00:00 2001 From: Jim Wild Date: Thu, 26 Jun 2025 08:45:37 +0000 Subject: [PATCH 5/5] change logging level --- .../updatePrescriptionStatus/src/updatePrescriptionStatus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts b/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts index f7222087da..dd8fa50206 100644 --- a/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts +++ b/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts @@ -145,7 +145,7 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise