Skip to content

CCM-22997: Shared utilities - #249

Open
rhyscoxnhs wants to merge 8 commits into
mainfrom
feature/CCM-22997
Open

CCM-22997: Shared utilities#249
rhyscoxnhs wants to merge 8 commits into
mainfrom
feature/CCM-22997

Conversation

@rhyscoxnhs

@rhyscoxnhs rhyscoxnhs commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Description

Introduces a new publishable package, @nhsdigital/nhs-notify-shared-utils, in a new
packages/ workspace. It holds generic, technical-only utilities for reuse across NHS
Notify bounded contexts.

Each module is a subpath export, so a consumer imports only what it needs and Lambda
bundles never pull in unused code:

  • ./logger — a generic pino-backed Logger. Redaction is fully opt-in: the class
    declares no redact paths of its own; each bounded context supplies its own via
    redactPaths.
  • ./lambda-utilsparseEnv / EnvValidationError, a pure formatZodIssues
    formatter, and SQS string-attribute readers. parseEnv validates process.env (or a
    supplied source) against a Zod object schema, so callers get coercion (numbers,
    booleans, etc.) and format assertions rather than every variable being read as an
    untyped string; issues are thrown as a single formatted EnvValidationError. Neither
    helper takes a hard dependency on Zod — EnvSchema<T> and FormattableZodIssue
    declare the minimal structural shape needed, so any Zod schema/error is accepted
    without coupling the package to a Zod version. No AWS SDK dependency.
  • ./s3-json — a get-JSON-from-S3-and-optionally-validate helper.

Integration test-support helpers (AWS client factories, polling primitives, event-factory
fixtures) were deliberately not included — they're boilerplate enough to copy into
each repo's tests rather than maintain as a shared dependency, per review feedback.

Dependency and build contract:

  • pino and @aws-sdk/client-s3 are peer dependencies (the S3 client optional),
    preventing duplicate copies in consumer bundles.
  • CommonJS build via tsc with a split tooling/build tsconfig; files restricted to
    dist. Every module ships a README with usage.

Workspace and release wiring:

  • Adds the packages/* workspace glob, aws and runtime pnpm catalogs, a
    cache-correct turbo build task, and ESLint coverage for the new package.
  • Adds a tag-driven publish workflow (publish-packages.yaml) to GitHub Packages under
    @nhsdigital, triggered only by shared-utils-v* tags and decoupled from the
    Terraform module release. It fails unless the pushed tag version matches package.json
    version. Least-privilege permissions (contents: read, packages: write),
    GITHUB_TOKEN auth only.
  • Adds a tag-shared-utils-release.yaml workflow that automatically creates and pushes
    the shared-utils-vX.Y.Z tag once the main CI/CD pipeline completes successfully on
    main, reading the version straight from package.json. This removes the manual,
    error-prone step of a developer creating a tag that must match the package version by
    hand — bumping version in a merged PR is now the only manual step required to
    release.
  • Updates existing tsconfigs to resolve typecheck / unit test failures due to missing
    jest entry in types and use of deprecated baseUrl properties.
  • 100% unit-test coverage; lint, typecheck, tests and build are green.

Context

The app-response and client-callbacks bounded contexts independently built
near-identical technical utilities — structured logging, environment-variable
validation, and error formatting. Maintaining two copies causes drift and doubled
effort. This extracts the generic, technical-only utilities into a single versioned
package so bounded contexts can depend on one shared implementation, keeping the
dependency one-way (bounded context → shared) and leaving all domain logic in its own
context. Integration test-support helpers were intentionally left out of the shared
package — they're low-risk boilerplate best copied per repo rather than centrally
maintained. Consumers adopt the package on their own cadence in follow-up work; this
change only introduces the package in the host repository.

Ref: CCM-22997.

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

@rhyscoxnhs
rhyscoxnhs requested a review from a team as a code owner August 19, 2026 10:46
@rhyscoxnhs
rhyscoxnhs force-pushed the feature/CCM-22997 branch 2 times, most recently from 7c9b84c to 829fcaf Compare August 19, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant