Skip to content

Commit 9019638

Browse files
authored
CCM-12869: Add initial schemas and events for supplier configuration (#37)
* Feature: Add initial schemas and events for supplier configuration * Fix: dependencies * Remove domain prefix from subject in event envelope * Remove documentation examples + fix event-builder tests * Remove generated files from git * Add contract events * Remove stray readme * Add supplier model events * Refactor contract references to volume group in schemas and events * Add volume group events and update JSON generation * Refactor status handling to use $EnvironmentStatus across configurations * Update tests * Add approval status validation and update enums in specifications * Update deliverySLA to deliveryDays and change status references to PROD * Refactor colour property to restrict to WHITE and update description * Add DISABLED status to various entities and update related schemas * Add optional description to PackSpecification and update tests * Add duplex field validation to PackSpecification and update tests * Add ATTACHMENT type to PackSpecification $Insert schema * Add constraints validation to PackSpecification and related tests * Rename specification-supplier.test.ts to supplier-pack.test.ts * Enhance constraint validation by adding GREATER_THAN_OR_EQUAL and LESS_THAN_OR_EQUAL options; update billingId metadata in PackSpecification
1 parent 60ef36f commit 9019638

63 files changed

Lines changed: 3010 additions & 5213 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/event-builder/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"dependencies": {
3-
"@nhsdigital/nhs-notify-supplier-config-schemas": "1.0.0",
3+
"@nhsdigital/nhs-notify-event-schemas-supplier-config": "1.0.0",
44
"csv-parse": "^5.6.0",
5-
"zod": "^4.0.17"
5+
"zod": "^4.1.12"
66
},
77
"devDependencies": {
88
"@swc/core": "^1.11.13",
@@ -12,7 +12,7 @@
1212
"esbuild": "^0.25.9",
1313
"jest": "^29.7.0",
1414
"jest-mock-extended": "^3.0.7",
15-
"typescript": "^5.8.2"
15+
"typescript": "^5.9.3"
1616
},
1717
"name": "nhs-notify-supplier-config-event-builder",
1818
"private": true,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import packageJson from "@nhsdigital/nhs-notify-event-schemas-supplier-config/package.json";
2+
import { Config, buildEventSource, configFromEnv } from "../config";
3+
4+
describe("config.ts", () => {
5+
const originalEnv = process.env;
6+
7+
beforeEach(() => {
8+
jest.resetModules();
9+
process.env = { ...originalEnv }; // shallow copy
10+
delete process.env.EVENT_ENV;
11+
delete process.env.EVENT_SERVICE;
12+
delete process.env.EVENT_DATASCHEMAVERSION;
13+
});
14+
15+
afterAll(() => {
16+
process.env = originalEnv; // restore
17+
});
18+
19+
it("returns defaults when env vars are not set", () => {
20+
const cfg = configFromEnv();
21+
expect(cfg.EVENT_ENV).toBe("dev");
22+
expect(cfg.EVENT_SERVICE).toBe("events");
23+
expect(cfg.EVENT_DATASCHEMAVERSION).toBe(packageJson.version);
24+
});
25+
26+
it("applies overrides from environment variables", () => {
27+
process.env.EVENT_ENV = "prod";
28+
process.env.EVENT_SERVICE = "supplier";
29+
process.env.EVENT_DATASCHEMAVERSION = "9.9.9";
30+
const cfg = configFromEnv();
31+
expect(cfg.EVENT_ENV).toBe("prod");
32+
expect(cfg.EVENT_SERVICE).toBe("supplier");
33+
expect(cfg.EVENT_DATASCHEMAVERSION).toBe("9.9.9");
34+
});
35+
36+
it("buildEventSource constructs expected path", () => {
37+
const cfg: Config = {
38+
EVENT_ENV: "int",
39+
EVENT_SERVICE: "allocations",
40+
EVENT_DATASCHEMAVERSION: packageJson.version,
41+
};
42+
const src = buildEventSource(cfg);
43+
expect(src).toBe("/control-plane/supplier-config/int/allocations");
44+
});
45+
});
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { z } from "zod";
2+
import packageJson from "@nhsdigital/nhs-notify-event-schemas-supplier-config/package.json";
3+
4+
const dataschemaversion = packageJson.version;
25

36
const $Config = z.object({
4-
EVENT_SOURCE: z.string(),
7+
EVENT_ENV: z.string().default("dev"),
8+
EVENT_SERVICE: z.string().default("events"),
9+
EVENT_DATASCHEMAVERSION: z.string().default(dataschemaversion),
510
});
11+
export type Config = z.infer<typeof $Config>;
612

7-
export const loadConfig = () => {
13+
export const configFromEnv = () => {
814
return $Config.parse(process.env);
915
};
1016

11-
export const eventSource =
12-
"//notify.nhs.uk/app/nhs-notify-supplier-config-dev/main";
17+
export const buildEventSource = (config: Config) => {
18+
const { EVENT_ENV, EVENT_SERVICE } = config;
19+
return `/control-plane/supplier-config/${EVENT_ENV}/${EVENT_SERVICE}`;
20+
};

packages/event-builder/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": "./src/"
3+
"baseUrl": "./src/",
4+
"isolatedModules": true,
5+
"resolveJsonModule": true
46
},
57
"exclude": [
68
"node_modules"

packages/events/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
output/

packages/events/.spectral.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends: ["spectral:oas", "spectral:asyncapi", "spectral:arazzo"]

packages/events/jest.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
4+
// Automatically clear mock calls, instances, contexts and results before every test
5+
clearMocks: true,
6+
7+
// Indicates whether the coverage information should be collected while executing the test
8+
collectCoverage: true,
9+
10+
// The directory where Jest should output its coverage files
11+
coverageDirectory: './.reports/unit/coverage',
12+
13+
// Indicates which provider should be used to instrument code for coverage
14+
coverageProvider: 'babel',
15+
16+
coverageThreshold: {
17+
global: {
18+
branches: 100,
19+
functions: 100,
20+
lines: 100,
21+
statements: -10,
22+
},
23+
},
24+
25+
coveragePathIgnorePatterns: ['/__tests__/'],
26+
27+
// Use this configuration option to add custom reporters to Jest
28+
reporters: [
29+
'default',
30+
[
31+
'jest-html-reporter',
32+
{
33+
pageTitle: 'Test Report',
34+
outputPath: './.reports/unit/test-report.html',
35+
includeFailureMsg: true,
36+
},
37+
],
38+
],
39+
40+
testEnvironment: 'node',
41+
testMatch: ['**/__tests__/**/*test.ts'],
42+
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
43+
};
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11
{
22
"author": "",
33
"dependencies": {
4-
"zod": "^4.0.5"
4+
"zod": "^4.1.12"
55
},
66
"description": "Schemas for NHS Notify configuration",
77
"devDependencies": {
8-
"@types/jest": "^30.0.0",
8+
"@types/jest": "^29.5.14",
99
"@types/node": "^22.13.4",
10-
"jest": "^30.0.4",
10+
"jest": "^29.7.0",
1111
"ts-jest": "^29.4.0",
1212
"ts-node": "^10.9.2",
13-
"typescript": "^5.7.3"
13+
"typescript": "^5.9.3",
14+
"zod-mermaid": "^1.3.0"
1415
},
15-
"main": "src/index.ts",
16-
"name": "@nhsdigital/nhs-notify-supplier-config-schemas",
16+
"main": "dist/index.js",
17+
"name": "@nhsdigital/nhs-notify-event-schemas-supplier-config",
1718
"publishConfig": {
1819
"registry": "https://npm.pkg.github.com"
1920
},
2021
"repository": "git@github.com:NHSDigital/nhs-notify-supplier-config.git",
2122
"scripts": {
22-
"build": "tsc",
23+
"build": "tsc -p ./tsconfig.build.json",
2324
"dev": "ts-node src/index.ts",
24-
"json": "ts-node src/cli/generate-json.ts",
25+
"examples": "ts-node src/examples/specification-examples.ts",
26+
"gen:erd": "ts-node src/cli/generate-erd.ts",
27+
"gen:json": "ts-node src/cli/generate-json.ts",
28+
"prepare": "npm run build",
2529
"start": "node dist/index.js",
2630
"test": "jest",
2731
"test:unit": "jest"
2832
},
33+
"types": "dist/index.d.ts",
2934
"version": "1.0.0"
3035
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.schema.json

0 commit comments

Comments
 (0)