Skip to content

Commit c7c63d7

Browse files
committed
CCM-11025: add schemas package
1 parent 5df8b9f commit c7c63d7

32 files changed

+11205
-10414
lines changed

.github/workflows/stage-4-acceptance.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,26 @@ jobs:
7575
targetAccountGroup: nhs-notify-template-management-dev
7676
targetComponent: sandbox
7777
terraformAction: destroy
78+
79+
publish-test-package:
80+
name: Publish test package
81+
needs: sandbox-tear-down
82+
runs-on: ubuntu-latest
83+
84+
steps:
85+
- name: Checkout code
86+
uses: actions/checkout@v4
87+
88+
- name: Use Node.js 20
89+
uses: actions/setup-node@v4
90+
with:
91+
node-version: '20.18.2'
92+
registry-url: 'https://npm.pkg.github.com'
93+
94+
- name: Install dependencies
95+
run: npm install
96+
97+
- name: Publish to GitHub Packages
98+
run: npm publish --workspace packages/schemas
99+
env:
100+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package-lock.json

Lines changed: 10447 additions & 10414 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"lambdas/backend-client",
5656
"lambdas/download-authorizer",
5757
"lambdas/sftp-letters",
58+
"packages/schemas",
5859
"tests/accessibility",
5960
"tests/test-team",
6061
"utils/backend-config",

packages/schemas/LICENCE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT Licence
2+
3+
Copyright (c) 2025 Crown Copyright NHS England.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/schemas/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Template Management Schemas
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { $TemplateCompletedEvent } from '../../src/events/TemplateCompleted';
4+
5+
const examplesDir = path.resolve(
6+
__dirname,
7+
'../../sample-events/TemplateCompleted'
8+
);
9+
10+
describe('TemplateCompletedEvent schema', () => {
11+
it.each(fs.readdirSync(examplesDir))(
12+
'parses sample event %s without errors',
13+
(filename) => {
14+
const event = JSON.parse(
15+
fs.readFileSync(path.join(examplesDir, filename), 'utf8')
16+
);
17+
18+
const result = $TemplateCompletedEvent.safeParse(event);
19+
20+
if (!result.success) {
21+
console.log(result.error);
22+
}
23+
24+
expect(result.success).toBe(true);
25+
}
26+
);
27+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { $TemplateDeletedEvent } from '../../src/events/TemplateDeleted';
4+
5+
const examplesDir = path.resolve(
6+
__dirname,
7+
'../../sample-events/TemplateDeleted'
8+
);
9+
10+
describe('TemplateCompletedEvent schema', () => {
11+
it.each(fs.readdirSync(examplesDir))(
12+
'parses sample event %s without errors',
13+
(filename) => {
14+
const event = JSON.parse(
15+
fs.readFileSync(path.join(examplesDir, filename), 'utf8')
16+
);
17+
18+
const result = $TemplateDeletedEvent.safeParse(event);
19+
20+
if (!result.success) {
21+
console.log(result.error);
22+
}
23+
24+
expect(result.success).toBe(true);
25+
}
26+
);
27+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { $TemplateDraftedEvent } from '../../src/events/TemplateDrafted';
4+
5+
const examplesDir = path.resolve(
6+
__dirname,
7+
'../../sample-events/TemplateDrafted'
8+
);
9+
10+
describe('TemplateDraftedEvent schema', () => {
11+
it.each(fs.readdirSync(examplesDir))(
12+
'parses sample event %s without errors',
13+
(filename) => {
14+
const event = JSON.parse(
15+
fs.readFileSync(path.join(examplesDir, filename), 'utf8')
16+
);
17+
18+
const result = $TemplateDraftedEvent.safeParse(event);
19+
20+
if (!result.success) {
21+
console.log(result.error);
22+
}
23+
24+
expect(result.success).toBe(true);
25+
}
26+
);
27+
});

packages/schemas/jest.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Config } from 'jest';
2+
import { baseJestConfig } from 'nhs-notify-web-template-management-utils';
3+
4+
const config: Config = {
5+
...baseJestConfig,
6+
testEnvironment: 'node',
7+
};
8+
9+
export default config;

packages/schemas/package.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"author": "NHS Notify contributors",
3+
"description": "Zod validators, TypeScript type definitions and JSON Schemas for Template Management",
4+
"devDependencies": {
5+
"@swc/core": "^1.11.13",
6+
"@swc/jest": "^0.2.37",
7+
"@tsconfig/node20": "^20.1.5",
8+
"@types/jest": "^29.5.14",
9+
"jest": "^29.7.0",
10+
"tsx": "^4.19.3",
11+
"typescript": "^5.8.2",
12+
"zod": "^4.0.5"
13+
},
14+
"exports": {
15+
".": {
16+
"default": "./dist/index.js",
17+
"types": "./dist/index.d.ts"
18+
},
19+
"./event-schemas/*.json": {
20+
"default": "./dist/event-schemas/*.json"
21+
},
22+
"./sample-events/*.json": {
23+
"default": "./sample-events/*.json"
24+
}
25+
},
26+
"files": [
27+
"dist",
28+
"sample-events"
29+
],
30+
"license": "MIT",
31+
"main": "./dist/index.js",
32+
"name": "@nhsdigital/nhs-notify-templates-test-package",
33+
"peerDependencies": {
34+
"zod": "^4.0.5"
35+
},
36+
"publishConfig": {
37+
"access": "public",
38+
"registry": "https://npm.pkg.github.com"
39+
},
40+
"repository": {
41+
"type": "git",
42+
"url": "git+https://github.com/NHSDigital/nhs-notify-web-template-management.git"
43+
},
44+
"scripts": {
45+
"build": "npm run clean && tsc && tsx scripts/generate-json-schemas.ts",
46+
"clean": "rm -rf dist",
47+
"prepublishOnly": "npm run build",
48+
"test:unit": "jest"
49+
},
50+
"type": "commonjs",
51+
"types": "./dist/index.d.ts",
52+
"version": "1.0.0"
53+
}

0 commit comments

Comments
 (0)