Skip to content

Commit 4b769c4

Browse files
committed
CCM-12352: Bootstrap internal/events package
1 parent a098fa8 commit 4b769c4

File tree

26 files changed

+6039
-111
lines changed

26 files changed

+6039
-111
lines changed

internal/datastore/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"dependencies": {
33
"@aws-sdk/client-dynamodb": "^3.858.0",
44
"@aws-sdk/lib-dynamodb": "^3.858.0",
5+
"@internal/helpers": "*",
56
"pino": "^9.7.0",
67
"zod": "^4.0.14"
78
},
@@ -18,12 +19,11 @@
1819
"testcontainers": "^11.4.0",
1920
"ts-jest": "^29.4.0",
2021
"ts-node": "^10.9.2",
21-
"typescript": "^5.8.2",
22-
"zod-mermaid": "^1.0.9"
22+
"typescript": "^5.8.2"
2323
},
2424
"license": "MIT",
2525
"main": "src/index.ts",
26-
"name": "datastore",
26+
"name": "@internal/datastore",
2727
"private": true,
2828
"scripts": {
2929
"diagrams": "ts-node src/cli/diagrams.ts",

internal/datastore/src/cli/diagrams.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

internal/datastore/src/types.md

Lines changed: 0 additions & 46 deletions
This file was deleted.

internal/datastore/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod';
2-
import { idRef } from 'zod-mermaid';
2+
import { idRef } from '@internal/helpers';
33

44
export const SupplerStatus = z.enum(['ENABLED', 'DISABLED']);
55

internal/datastore/tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{
22
"compilerOptions": {
3-
"isolatedModules": true
3+
"baseUrl": ".",
4+
"isolatedModules": true,
5+
"paths": {
6+
"@internal/helpers": [
7+
"../helpers/src"
8+
]
9+
}
410
},
511
"extends": "@tsconfig/node22/tsconfig.json",
612
"include": [

internal/events/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# NHS Notify Schemas (Supplier API)
2+
3+
This package contains schema definitions and type interfaces for the NHS Notify Supplier API event system.
4+
5+
## Installation
6+
7+
```bash
8+
npm install --save nhs-notify-schemas-supplier-api
9+
```
10+
11+
## Usage
12+
13+
```typescript
14+
import { LetterStatusSchema, LetterStatusType } from 'nhs-notify-schemas-supplier-api';
15+
16+
// Validate an incoming event
17+
const result = LetterStatusSchema.safeParse(incomingData);
18+
if (!result.success) {
19+
console.error('Invalid letter status event:', result.error);
20+
return;
21+
}
22+
23+
// Use the validated data with full type safety
24+
const letterEvent: LetterStatusType = result.data;
25+
console.log(`Letter ${letterEvent.letterId} status: ${letterEvent.status}`);
26+
```
27+
28+
## Available Schemas
29+
30+
- `LetterStatusSchema`: For letter status update events
31+
- `LetterCreatedSchema`: For letter creation events
32+
33+
## Development
34+
35+
### Building
36+
37+
```bash
38+
npm run build
39+
```
40+
41+
### Testing
42+
43+
```bash
44+
npm test
45+
```
46+
47+
### Generating Schema Diagrams
48+
49+
```bash
50+
npm run generate-diagrams
51+
```

internal/events/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"dependencies": {
3+
"@internal/helpers": "*",
4+
"zod": "^4.0.14"
5+
},
6+
"description": "Schemas for NHS Notify Supplier API events",
7+
"devDependencies": {
8+
"@stylistic/eslint-plugin": "^3.1.0",
9+
"@tsconfig/node22": "^22.0.2",
10+
"@types/jest": "^29.5.14",
11+
"@typescript-eslint/eslint-plugin": "^8.27.0",
12+
"@typescript-eslint/parser": "^8.27.0",
13+
"eslint": "^9.27.0",
14+
"eslint-plugin-jest": "^29.0.1",
15+
"jest": "^29.7.0",
16+
"ts-jest": "^29.4.0",
17+
"ts-node": "^10.9.2",
18+
"typescript": "^5.8.2",
19+
"zod-mermaid": "^1.0.9"
20+
},
21+
"license": "MIT",
22+
"main": "dist/index.js",
23+
"name": "nhs-notify-schemas-supplier-api",
24+
"private": true,
25+
"scripts": {
26+
"build": "tsc",
27+
"generate-diagrams": "ts-node src/cli/generateDiagrams.ts",
28+
"lint": "eslint .",
29+
"lint:fix": "eslint . --fix",
30+
"test": "jest",
31+
"typecheck": "tsc --noEmit"
32+
},
33+
"types": "dist/index.d.ts",
34+
"version": "0.1.0"
35+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { z } from 'zod';
2+
3+
/**
4+
* Status values for letters in the NHS Notify system
5+
*/
6+
export const LetterStatus = z.enum([
7+
'PENDING', // Letter is waiting to be processed
8+
'PROCESSING', // Letter is being processed
9+
'PRINTED', // Letter has been printed
10+
'DISPATCHED', // Letter has been dispatched to delivery service
11+
'DELIVERED', // Letter has been delivered
12+
'FAILED', // Letter processing failed
13+
]);
14+
15+
export type LetterStatusEnum = z.infer<typeof LetterStatus>;
16+
17+
/**
18+
* Schema for letter status update events
19+
*/
20+
export const LetterStatusSchema = z.object({
21+
eventType: z.literal('LETTER_STATUS_UPDATE'),
22+
timestamp: z.string().datetime(),
23+
letterId: z.string().uuid(),
24+
groupId: z.string().optional(),
25+
specificationId: z.string().optional(),
26+
supplierId: z.string(),
27+
status: LetterStatus,
28+
metadata: z.record(z.string(), z.unknown()).optional(),
29+
});
30+
31+
export type LetterStatusType = z.infer<typeof LetterStatusSchema>;
32+
33+
/**
34+
* Schema for letter creation events
35+
*/
36+
export const LetterCreatedSchema = z.object({
37+
eventType: z.literal('LETTER_CREATED'),
38+
timestamp: z.string().datetime(),
39+
letterId: z.string().uuid(),
40+
groupId: z.string().optional(),
41+
specificationId: z.string().optional(),
42+
supplierId: z.string(),
43+
contentReference: z.string(),
44+
metadata: z.record(z.string(), z.unknown()).optional(),
45+
});
46+
47+
export type LetterCreatedType = z.infer<typeof LetterCreatedSchema>;

internal/events/tsconfig.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"declaration": true,
5+
"esModuleInterop": true,
6+
"forceConsistentCasingInFileNames": true,
7+
"isolatedModules": true,
8+
"outDir": "dist",
9+
"paths": {
10+
"@internal/helpers": [
11+
"../helpers/src"
12+
]
13+
},
14+
"skipLibCheck": true,
15+
"strict": true
16+
},
17+
"exclude": [
18+
"node_modules",
19+
"dist"
20+
],
21+
"extends": "@tsconfig/node22/tsconfig.json",
22+
"include": [
23+
"src/**/*",
24+
"jest.config.ts"
25+
]
26+
}

internal/helpers/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dependency directories
2+
node_modules/
3+
4+
# Built output
5+
dist/
6+
7+
# Coverage directory used by tools like istanbul
8+
coverage/
9+
10+
# Logs
11+
logs
12+
*.log
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
17+
# Editor directories and files
18+
.idea/
19+
.vscode/
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

0 commit comments

Comments
 (0)