Skip to content

Commit 8cad59b

Browse files
committed
init
1 parent 089b325 commit 8cad59b

17 files changed

+99
-81
lines changed

internal/events/schemas/supplier-api.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ components:
4949
This indicates that a letter has been accepted for processing by a supplier.
5050
contentType: application/json
5151
payload:
52-
$ref: './events/letter.ACCEPTED.schema.json'
52+
$ref: './events/letter.accepted.schema.json'
5353
examples:
5454
- payload:
55-
$ref: './examples/letter.ACCEPTED.json'
55+
$ref: './examples/letter.accepted.json'
5656

5757
letter-cancelled:
5858
name: letter-cancelled
@@ -63,7 +63,7 @@ components:
6363
This indicates that a letter has been cancelled and will not be printed or dispatched.
6464
contentType: application/json
6565
payload:
66-
$ref: './events/letter.CANCELLED.schema.json'
66+
$ref: './events/letter.cancelled.schema.json'
6767

6868
letter-delivered:
6969
name: letter-delivered
@@ -74,7 +74,7 @@ components:
7474
This indicates that a letter has been delivered to the recipient.
7575
contentType: application/json
7676
payload:
77-
$ref: './events/letter.DELIVERED.schema.json'
77+
$ref: './events/letter.delivered.schema.json'
7878

7979
letter-dispatched:
8080
name: letter-dispatched
@@ -85,7 +85,7 @@ components:
8585
This indicates that a letter has been dispatched from the supplier to a down-stream access (DSA) provider.
8686
contentType: application/json
8787
payload:
88-
$ref: './events/letter.DISPATCHED.schema.json'
88+
$ref: './events/letter.dispatched.schema.json'
8989

9090
letter-enclosed:
9191
name: letter-enclosed
@@ -96,7 +96,7 @@ components:
9696
This indicates that a letter has been printed and packaged in an envelope.
9797
contentType: application/json
9898
payload:
99-
$ref: './events/letter.ENCLOSED.schema.json'
99+
$ref: './events/letter.enclosed.schema.json'
100100

101101
letter-failed:
102102
name: letter-failed
@@ -107,7 +107,7 @@ components:
107107
This indicates that a letter has failed to be processed by a supplier.
108108
contentType: application/json
109109
payload:
110-
$ref: './events/letter.FAILED.schema.json'
110+
$ref: './events/letter.failed.schema.json'
111111

112112
letter-forwarded:
113113
name: letter-forwarded
@@ -118,10 +118,10 @@ components:
118118
This indicates that a letter has been forwarded to another supplier for processing.
119119
contentType: application/json
120120
payload:
121-
$ref: './events/letter.FORWARDED.schema.json'
121+
$ref: './events/letter.forwarded.schema.json'
122122
examples:
123123
- payload:
124-
$ref: './examples/letter.FORWARDED.json'
124+
$ref: './examples/letter.forwarded.json'
125125

126126
letter-pending:
127127
name: letter-pending
@@ -132,7 +132,7 @@ components:
132132
This indicates that a letter has been queued for processing by a supplier.
133133
contentType: application/json
134134
payload:
135-
$ref: './events/letter.PENDING.schema.json'
135+
$ref: './events/letter.pending.schema.json'
136136

137137
letter-printed:
138138
name: letter-printed
@@ -143,7 +143,7 @@ components:
143143
This indicates that a letter has been printed by the supplier.
144144
contentType: application/json
145145
payload:
146-
$ref: './events/letter.PRINTED.schema.json'
146+
$ref: './events/letter.printed.schema.json'
147147

148148
letter-rejected:
149149
name: letter-rejected
@@ -154,7 +154,7 @@ components:
154154
This indicates that a letter has been rejected by the supplier and will not be processed.
155155
contentType: application/json
156156
payload:
157-
$ref: './events/letter.REJECTED.schema.json'
157+
$ref: './events/letter.rejected.schema.json'
158158

159159
letter-returned:
160160
name: letter-returned
@@ -165,10 +165,10 @@ components:
165165
This indicates that a letter has been returned to the supplier.
166166
contentType: application/json
167167
payload:
168-
$ref: './events/letter.RETURNED.schema.json'
168+
$ref: './events/letter.returned.schema.json'
169169
examples:
170170
- payload:
171-
$ref: './examples/letter.RETURNED.json'
171+
$ref: './examples/letter.returned.json'
172172

173173
letter-any:
174174
name: letter-any
@@ -188,7 +188,7 @@ components:
188188
This indicates that MI data has been submitted to the NHS Notify Supplier API.
189189
contentType: application/json
190190
payload:
191-
$ref: './events/mi.SUBMITTED.schema.json'
191+
$ref: './events/mi.submitted.schema.json'
192192

193193
schemas:
194194
letter:

internal/events/src/domain/letter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ The identifier will be included as the origin domain in the subject of any corre
107107
"Optional human-readable reason for the status change, if applicable.",
108108
examples: ["Undeliverable", "Recipient moved"],
109109
}),
110+
111+
supplierId: z
112+
.string()
113+
.optional()
114+
.meta({
115+
title: "Supplier ID",
116+
description:
117+
"Optional identifier for the supplier handling this letter, if applicable.",
118+
examples: ["supplier-12345"],
119+
}),
110120
})
111121
.meta({
112122
title: "Letter",

internal/events/src/events/__tests__/event-envelope.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ describe("EventEnvelope schema validation", () => {
77

88
const baseValidEnvelope: Envelope = {
99
dataschema:
10-
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/order.READ.1.0.0.schema.json",
10+
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/order.read.1.0.0.schema.json",
1111
specversion: "1.0",
1212
id: "6f1c2a53-3d54-4a0a-9a0b-0e9ae2d4c111",
1313
source: "/data-plane/supplier-api/ordering",
1414
subject: "order/769acdd4",
15-
type: "uk.nhs.notify.supplier-api.order.READ.v1",
15+
type: "uk.nhs.notify.supplier-api.order.read.v1",
1616
time: "2025-10-01T10:15:30.000Z",
1717
data: {
1818
"notify-payload": {
@@ -230,7 +230,7 @@ describe("EventEnvelope schema validation", () => {
230230

231231
describe("subject prefix validation", () => {
232232
const $EnvelopeWithPrefix = EventEnvelope(
233-
"letter.CREATED",
233+
"letter.created",
234234
"letter",
235235
z.any(),
236236
["CREATED"],
@@ -240,9 +240,9 @@ describe("EventEnvelope schema validation", () => {
240240
const baseLetterEnvelope = {
241241
specversion: "1.0" as const,
242242
id: "6f1c2a53-3d54-4a0a-9a0b-0e02b2c3d479",
243-
type: "uk.nhs.notify.supplier-api.letter.CREATED.v1" as const,
243+
type: "uk.nhs.notify.supplier-api.letter.created.v1" as const,
244244
dataschema:
245-
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.CREATED.1.0.0.schema.json",
245+
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.created.1.0.0.schema.json",
246246
source: "/data-plane/supplier-api/letters",
247247
time: "2025-10-01T10:15:30.000Z",
248248
data: { status: "CREATED" },
@@ -286,16 +286,16 @@ describe("EventEnvelope schema validation", () => {
286286
});
287287

288288
it("should accept subject without prefix when no prefix is specified", () => {
289-
const $EnvelopeNoPrefix = EventEnvelope("order.READ", "order", z.any(), [
289+
const $EnvelopeNoPrefix = EventEnvelope("order.read", "order", z.any(), [
290290
"READ",
291291
]);
292292

293293
const envelope = {
294294
specversion: "1.0" as const,
295295
id: "6f1c2a53-3d54-4a0a-9a0b-0e9ae2d4c111",
296-
type: "uk.nhs.notify.supplier-api.order.READ.v1" as const,
296+
type: "uk.nhs.notify.supplier-api.order.read.v1" as const,
297297
dataschema:
298-
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/order.READ.1.0.0.schema.json",
298+
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/order.read.1.0.0.schema.json",
299299
source: "/data-plane/supplier-api/ordering",
300300
subject: "order/769acdd4",
301301
time: "2025-10-01T10:15:30.000Z",
@@ -313,7 +313,7 @@ describe("EventEnvelope schema validation", () => {
313313

314314
it("should accept various prefix formats", () => {
315315
const $EnvelopeMultiSegmentPrefix = EventEnvelope(
316-
"letter.CREATED",
316+
"letter.created",
317317
"letter",
318318
z.any(),
319319
["CREATED"],

internal/events/src/events/__tests__/letter-status-change-events.test.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ describe("LetterStatus event validations", () => {
1212
it.each(["ACCEPTED", "FORWARDED", "RETURNED"])(
1313
"should parse %s letter statuses successfully",
1414
(status) => {
15-
const json = readJson(`letter.${status}.json`);
15+
const statusLower = status.toLowerCase();
16+
17+
const json = readJson(`letter.${statusLower}.json`);
1618

1719
const { data: event, error } =
18-
letterEventMap[`letter.${status}`].safeParse(json);
20+
letterEventMap[`letter.${statusLower}`].safeParse(json);
21+
1922
expect(error).toBeUndefined();
2023
expect(event).toBeDefined();
2124
expect(event).toEqual(
2225
expect.objectContaining({
23-
type: `uk.nhs.notify.supplier-api.letter.${status}.v1`,
26+
type: `uk.nhs.notify.supplier-api.letter.${statusLower}.v1`,
2427
specversion: "1.0",
2528
source: "/data-plane/supplier-api/prod/update-status",
2629
id: "23f1f09c-a555-4d9b-8405-0b33490bc920",
2730
time: "2025-08-28T08:45:00.000Z",
2831
datacontenttype: "application/json",
29-
dataschema: `https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.${status}.1.0.0.schema.json`,
32+
dataschema: `https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.${statusLower}.1.0.0.schema.json`,
3033
subject:
3134
"letter-origin/letter-rendering/letter/f47ac10b-58cc-4372-a567-0e02b2c3d479",
3235
data: expect.objectContaining({
@@ -46,9 +49,10 @@ describe("LetterStatus event validations", () => {
4649
);
4750

4851
it("should parse reason code and text correctly for returned mail", () => {
49-
const json = readJson("letter.RETURNED.json");
52+
const json = readJson("letter.returned.json");
53+
54+
const event = letterEventMap["letter.returned"].parse(json);
5055

51-
const event = letterEventMap["letter.RETURNED"].parse(json);
5256
expect(event).toBeDefined();
5357
expect(event.data).toEqual(
5458
expect.objectContaining({
@@ -59,9 +63,10 @@ describe("LetterStatus event validations", () => {
5963
});
6064

6165
it("should parse reason code and text correctly for forwarded mail", () => {
62-
const json = readJson("letter.FORWARDED.json");
66+
const json = readJson("letter.forwarded.json");
67+
68+
const event = letterEventMap["letter.forwarded"].parse(json);
6369

64-
const event = letterEventMap["letter.FORWARDED"].parse(json);
6570
expect(event).toBeDefined();
6671
expect(event.data).toEqual(
6772
expect.objectContaining({
@@ -71,18 +76,18 @@ describe("LetterStatus event validations", () => {
7176
);
7277
});
7378

74-
it("should throw error for letter.ACCEPTED event with missing sourceSubject", () => {
75-
const json = readJson("letter.ACCEPTED-with-missing-fields.json");
79+
it("should throw error for letter.accepted event with missing sourceSubject", () => {
80+
const json = readJson("letter.accepted-with-missing-fields.json");
7681

77-
expect(() => letterEventMap["letter.ACCEPTED"].parse(json)).toThrow(
82+
expect(() => letterEventMap["letter.accepted"].parse(json)).toThrow(
7883
"subject",
7984
);
8085
});
8186

82-
it("should throw error for letter.ACCEPTED event with invalid major schema version", () => {
83-
const json = readJson("letter.ACCEPTED-with-invalid-major-version.json");
87+
it("should throw error for letter.accepted event with invalid major schema version", () => {
88+
const json = readJson("letter.accepted-with-invalid-major-version.json");
8489

85-
expect(() => letterEventMap["letter.ACCEPTED"].parse(json)).toThrow(
90+
expect(() => letterEventMap["letter.accepted"].parse(json)).toThrow(
8691
"dataschema",
8792
);
8893
});

internal/events/src/events/__tests__/mi-events.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ function readJson(filename: string): unknown {
99
}
1010

1111
describe("MI event validations", () => {
12-
it("should parse mi.SUBMITTED event successfully", () => {
13-
const json = readJson("mi.SUBMITTED.json");
12+
it("should parse mi.submitted event successfully", () => {
13+
const json = readJson("mi.submitted.json");
1414

1515
const { data: event, error } = $MISubmittedEvent.safeParse(json);
1616
expect(error).toBeUndefined();
1717
expect(event).toBeDefined();
1818
expect(event).toEqual(
1919
expect.objectContaining({
20-
type: "uk.nhs.notify.supplier-api.mi.SUBMITTED.v1",
20+
type: "uk.nhs.notify.supplier-api.mi.submitted.v1",
2121
specversion: "1.0",
2222
source: "/data-plane/supplier-api/prod/submit-mi",
2323
id: "8f2c3b44-4e65-5b1b-a678-1f0bf3d4d222",
2424
time: "2025-11-16T10:30:00.000Z",
2525
datacontenttype: "application/json",
2626
dataschema:
27-
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/mi.SUBMITTED.1.0.0.schema.json",
27+
"https://notify.nhs.uk/cloudevents/schemas/supplier-api/mi.submitted.1.0.0.schema.json",
2828
subject: "mi/mi-test-001",
2929
data: expect.objectContaining({
3030
id: "mi-test-001",
@@ -40,8 +40,8 @@ describe("MI event validations", () => {
4040
);
4141
});
4242

43-
it("should parse minimal mi.SUBMITTED event successfully", () => {
44-
const json = readJson("mi.SUBMITTED-minimal.json");
43+
it("should parse minimal mi.submitted event successfully", () => {
44+
const json = readJson("mi.submitted-minimal.json");
4545

4646
const event = $MISubmittedEvent.parse(json);
4747
expect(event).toBeDefined();
@@ -59,7 +59,7 @@ describe("MI event validations", () => {
5959
});
6060

6161
it("should parse MI data fields correctly", () => {
62-
const json = readJson("mi.SUBMITTED.json");
62+
const json = readJson("mi.submitted.json");
6363

6464
const event = $MISubmittedEvent.parse(json);
6565
expect(event).toBeDefined();
@@ -72,14 +72,14 @@ describe("MI event validations", () => {
7272
expect(event.data.groupId).toBe("group-456");
7373
});
7474

75-
it("should throw error for mi.SUBMITTED event with missing subject", () => {
76-
const json = readJson("mi.SUBMITTED-with-missing-subject.json");
75+
it("should throw error for mi.submitted event with missing subject", () => {
76+
const json = readJson("mi.submitted-with-missing-subject.json");
7777

7878
expect(() => $MISubmittedEvent.parse(json)).toThrow("subject");
7979
});
8080

81-
it("should throw error for mi.SUBMITTED event with invalid major schema version", () => {
82-
const json = readJson("mi.SUBMITTED-with-invalid-major-version.json");
81+
it("should throw error for mi.submitted event with invalid major schema version", () => {
82+
const json = readJson("mi.submitted-with-invalid-major-version.json");
8383

8484
expect(() => $MISubmittedEvent.parse(json)).toThrow("dataschema");
8585
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"origin": {
66
"domain": "letter-rendering",
77
"event": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
8-
"source": "/data-plane/letter-rendering/prod/render-pdf",
8+
"source": "/data-plane/letter-rendering/prod/letter-renderer",
99
"subject": "client/00f3b388-bbe9-41c9-9e76-052d37ee8988/letter-request/0o5Fs0EELR0fUjHjbCnEtdUwQe4_0o5Fs0EELR0fUjHjbCnEtdUwQe5"
1010
},
1111
"specificationId": "1y3q9v1zzzz",
1212
"status": "ACCEPTED"
1313
},
1414
"datacontenttype": "application/json",
15-
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.ACCEPTED.0.1.0.schema.json",
15+
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.accepted.0.1.0.schema.json",
1616
"id": "23f1f09c-a555-4d9b-8405-0b33490bc920",
1717
"recordedtime": "2025-08-28T08:45:00.000Z",
1818
"severitynumber": 2,
@@ -22,5 +22,5 @@
2222
"subject": "letter-origin/letter-rendering/letter/f47ac10b-58cc-4372-a567-0e02b2c3d479",
2323
"time": "2025-08-28T08:45:00.000Z",
2424
"traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
25-
"type": "uk.nhs.notify.supplier-api.letter.ACCEPTED.v1"
25+
"type": "uk.nhs.notify.supplier-api.letter.accepted.v1"
2626
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"origin": {
66
"domain": "letter-rendering",
77
"event": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
8-
"source": "/data-plane/letter-rendering/prod/render-pdf"
8+
"source": "/data-plane/letter-rendering/prod/letter-renderer"
99
},
1010
"specificationId": "1y3q9v1zzzz",
1111
"status": "ACCEPTED"
1212
},
1313
"datacontenttype": "application/json",
14-
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.ACCEPTED.1.0.0.schema.json",
14+
"dataschema": "https://notify.nhs.uk/cloudevents/schemas/supplier-api/letter.accepted.1.0.0.schema.json",
1515
"id": "23f1f09c-a555-4d9b-8405-0b33490bc920",
1616
"recordedtime": "2025-08-28T08:45:00.000Z",
1717
"severitynumber": 2,
@@ -21,5 +21,5 @@
2121
"subject": "letter-origin/letter-rendering/letter/f47ac10b-58cc-4372-a567-0e02b2c3d479",
2222
"time": "2025-08-28T08:45:00.000Z",
2323
"traceparent": "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01",
24-
"type": "uk.nhs.notify.supplier-api.letter.ACCEPTED.v1"
24+
"type": "uk.nhs.notify.supplier-api.letter.accepted.v1"
2525
}

0 commit comments

Comments
 (0)