Skip to content

Commit ed74d28

Browse files
committed
Address re-review comments
1 parent 24b6dad commit ed74d28

File tree

14 files changed

+68
-23
lines changed

14 files changed

+68
-23
lines changed

internal/events/src/domain/letter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ The identifier will be included as the origin domain in the subject of any corre
7676
examples: ["1y3q9v1zzzz"],
7777
}),
7878

79+
supplierId: z.string().meta({
80+
title: "Supplier ID",
81+
description: "Supplier ID allocated to the letter during creation.",
82+
examples: ["supplier-1"],
83+
}),
84+
7985
groupId: z.string().meta({
8086
title: "Group ID",
8187
description:

internal/events/src/events/__tests__/testData/letter.ACCEPTED-with-invalid-major-version.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"subject": "client/00f3b388-bbe9-41c9-9e76-052d37ee8988/letter-request/0o5Fs0EELR0fUjHjbCnEtdUwQe4_0o5Fs0EELR0fUjHjbCnEtdUwQe5"
1010
},
1111
"specificationId": "1y3q9v1zzzz",
12-
"status": "ACCEPTED"
12+
"status": "ACCEPTED",
13+
"supplierId": "supplier1"
1314
},
1415
"datacontenttype": "application/json",
1516
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.ACCEPTED.0.1.0.schema.json",

internal/events/src/events/__tests__/testData/letter.ACCEPTED-with-missing-fields.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"source": "/data-plane/letter-rendering/prod/render-pdf"
99
},
1010
"specificationId": "1y3q9v1zzzz",
11-
"status": "ACCEPTED"
11+
"status": "ACCEPTED",
12+
"supplierId": "supplier1"
1213
},
1314
"datacontenttype": "application/json",
1415
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.ACCEPTED.1.0.0.schema.json",

internal/events/src/events/__tests__/testData/letter.ACCEPTED.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"subject": "client/00f3b388-bbe9-41c9-9e76-052d37ee8988/letter-request/0o5Fs0EELR0fUjHjbCnEtdUwQe4_0o5Fs0EELR0fUjHjbCnEtdUwQe5"
1010
},
1111
"specificationId": "1y3q9v1zzzz",
12-
"status": "ACCEPTED"
12+
"status": "ACCEPTED",
13+
"supplierId": "supplier1"
1314
},
1415
"datacontenttype": "application/json",
1516
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.ACCEPTED.1.0.0.schema.json",

internal/events/src/events/__tests__/testData/letter.FORWARDED.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"reasonCode": "RNIB",
1212
"reasonText": "RNIB",
1313
"specificationId": "1y3q9v1zzzz",
14-
"status": "FORWARDED"
14+
"status": "FORWARDED",
15+
"supplierId": "supplier1"
1516
},
1617
"datacontenttype": "application/json",
1718
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.FORWARDED.1.0.0.schema.json",

internal/events/src/events/__tests__/testData/letter.RETURNED.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"reasonCode": "R07",
1212
"reasonText": "No such address",
1313
"specificationId": "1y3q9v1zzzz",
14-
"status": "RETURNED"
14+
"status": "RETURNED",
15+
"supplierId": "supplier1"
1516
},
1617
"datacontenttype": "application/json",
1718
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.RETURNED.1.0.0.schema.json",

lambdas/letter-updates-transformer/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"@aws-sdk/client-sns": "^3.943.0",
44
"@aws-sdk/util-dynamodb": "^3.943.0",
55
"@internal/datastore": "^0.1.0",
6+
"@internal/helpers": "^0.1.0",
67
"@nhsdigital/nhs-notify-event-schemas-supplier-api": "*",
78
"aws-lambda": "^1.0.7",
89
"esbuild": "^0.24.0",
9-
"pino": "^10.1.0"
10+
"pino": "^10.1.0",
11+
"zod": "^4.1.13"
1012
},
1113
"devDependencies": {
1214
"@tsconfig/node22": "^22.0.2",

lambdas/letter-updates-transformer/src/__tests__/letter-updates-transformer.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Deps } from "../deps";
1313
import { EnvVars } from "../env";
1414
import mapLetterToCloudEvent from "../mappers/letter-mapper";
1515
import { LetterStatus } from "../../../api-handler/src/contracts/letters";
16+
import { LetterWithSupplierId } from "../types";
1617

1718
// Make crypto return consistent values, since we"re calling it in both prod and test code and comparing the values
1819
const realCrypto = jest.requireActual("crypto");
@@ -147,7 +148,7 @@ describe("letter-updates-transformer Lambda", () => {
147148
it("does not publish invalid letter data", async () => {
148149
const handler = createHandler(mockedDeps);
149150
const oldLetter = generateLetter("ACCEPTED");
150-
const newLetter = { id: oldLetter.id } as LetterBase;
151+
const newLetter = { id: oldLetter.id } as LetterWithSupplierId;
151152

152153
const testData = generateKinesisEvent([
153154
generateModifyRecord(oldLetter, newLetter),
@@ -252,27 +253,28 @@ describe("letter-updates-transformer Lambda", () => {
252253
});
253254

254255

255-
function generateLetter(status: LetterStatus, id?: string): LetterBase {
256+
function generateLetter(status: LetterStatus, id?: string): LetterWithSupplierId {
256257
return {
257258
id: id || "1",
258259
status,
259260
specificationId: "spec1",
261+
supplierId: "supplier1",
260262
groupId: "group1",
261263
};
262264
}
263265

264266
function generateLetters(
265267
numLetters: number,
266268
status: LetterStatus,
267-
): LetterBase[] {
269+
): LetterWithSupplierId[] {
268270
return [...new Array(numLetters).keys()].map((i) =>
269271
generateLetter(status, String(i + 1)),
270272
);
271273
}
272274

273275
function generateModifyRecord(
274-
oldLetter: LetterBase,
275-
newLetter: LetterBase,
276+
oldLetter: LetterWithSupplierId,
277+
newLetter: LetterWithSupplierId,
276278
): DynamoDBRecord {
277279
const oldImage = Object.fromEntries(
278280
Object.entries(oldLetter).map(([key, value]) => [key, { S: value }]),

lambdas/letter-updates-transformer/src/letter-updates-transformer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
PublishBatchRequestEntry,
1111
} from "@aws-sdk/client-sns";
1212
import { LetterEvent } from "@nhsdigital/nhs-notify-event-schemas-supplier-api/src";
13-
import { LetterBase, LetterSchemaBase } from "@internal/datastore";
1413
import mapLetterToCloudEvent from "./mappers/letter-mapper";
1514
import { Deps } from "./deps";
15+
import { LetterSchemaWithSupplierId, LetterWithSupplierId } from "./types";
1616

1717
// SNS PublishBatchCommand supports up to 10 messages per batch
1818
const BATCH_SIZE = 10;
@@ -62,9 +62,9 @@ function isChanged(record: DynamoDBRecord, property: string): boolean {
6262
return oldValue?.S !== newValue?.S;
6363
}
6464

65-
function extractNewLetter(record: DynamoDBRecord): LetterBase {
65+
function extractNewLetter(record: DynamoDBRecord): LetterWithSupplierId {
6666
const newImage = record.dynamodb?.NewImage!;
67-
return LetterSchemaBase.parse(unmarshall(newImage as any));
67+
return LetterSchemaWithSupplierId.parse(unmarshall(newImage as any));
6868
}
6969

7070
function* generateBatches(events: LetterEvent[]) {

lambdas/letter-updates-transformer/src/mappers/__tests__/letter-mapper.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { $LetterEvent } from "@nhsdigital/nhs-notify-event-schemas-supplier-api/src";
2-
import { LetterBase } from "@internal/datastore";
2+
import { Letter } from "@internal/datastore";
33
import mapLetterToCloudEvent from "../letter-mapper";
44

55
describe("letter-mapper", () => {
66
it("maps a letter to a letter event", async () => {
7-
const letter: LetterBase = {
7+
const letter = {
88
id: "id1",
99
specificationId: "spec1",
10+
supplierId: "supplier1",
1011
groupId: "group1",
1112
status: "PRINTED",
1213
reasonCode: "R02",
1314
reasonText: "Reason text",
14-
};
15+
} as Letter;
1516
jest.useFakeTimers().setSystemTime(new Date("2025-11-24T15:55:18Z"));
1617

1718
const event = mapLetterToCloudEvent(letter);
@@ -20,16 +21,17 @@ describe("letter-mapper", () => {
2021
$LetterEvent.parse(event);
2122
expect(event.type).toBe("uk.nhs.notify.supplier-api.letter.printed.v1");
2223
expect(event.dataschema).toBe(
23-
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.printed.1.1.5.schema.json",
24+
`https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.printed.${event.dataschemaversion}.schema.json`,
2425
);
25-
expect(event.dataschemaversion).toBe("1.1.5");
26+
expect(event.dataschemaversion).toBe("1.0.4");
2627
expect(event.subject).toBe("letter-origin/supplier-api/letter/id1");
2728
expect(event.time).toBe("2025-11-24T15:55:18.000Z");
2829
expect(event.recordedtime).toBe("2025-11-24T15:55:18.000Z");
2930
expect(event.data).toEqual({
3031
domainId: "id1",
3132
status: "PRINTED",
3233
specificationId: "spec1",
34+
supplierId: "supplier1",
3335
groupId: "group1",
3436
reasonCode: "R02",
3537
reasonText: "Reason text",

0 commit comments

Comments
 (0)