Skip to content

Commit 9e46494

Browse files
CCM-17943: Add function Readme documentation (#608)
* first review pass * add information on how to run tests * increment version of internal/events/package.json * include information on setting the api key in main and for TestSupplier1 * correct the proxy_name format --------- Co-authored-by: Vlasis-Perdikidis <vlasis.perdikidis1@nhs.net>
1 parent b142808 commit 9e46494

25 files changed

Lines changed: 866 additions & 213 deletions

File tree

.env.template

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ PR_NUMBER=prxx # remove if needs to run against main
33
GITHUB_TOKEN=
44

55
# Apigee proxy name to be used for test execution
6-
# nhs-notify-supplier--internal-dev--nhs-notify-supplier-PR-XX
6+
# nhs-notify-supplier--internal-dev--nhs-notify-supplier-PR-xxx
77
PROXY_NAME=
88

99
# APIM env to run e2e tests against, other options are: ref, int, prod
@@ -25,18 +25,35 @@ TARGET_ENVIRONMENT=prxx
2525

2626
# API Keys
2727
# ========
28-
# In order to find out the value of an environments given API key, follow these steps
29-
# 1. Log in to Non-Prod
30-
# 2. Navigate to 'Publish' > 'Apps' and search for the app linked to authentication
31-
# 3. Copy the "key" from the Credentials related to the app
28+
# In order to find out and set the value of NON_PROD_API_KEY follow these steps
29+
# 1. Log in to the AWS NHS Notify Suppliers Dev account
30+
# 2. Open the paramenter store and search for the parameter /dev/e2e/keys/apim/pr (this key will use the supplier Supplier1)
31+
# a. to use the supplier TestSupplier1, search for the parameter /dev/e2e/keys/apim/pr/secondary
32+
# NOTE: this needs to be set to the NON_PROD_SECONDARY_API_KEY environment variable
33+
# b. If you want to run against main, search for the parameter /dev/e2e/keys/apim/main
34+
# 3. Copy the decrypted "value"
3235
# Note: For INT and higher environments use developer portal https://identity.prod.api.platform.nhs.uk/
3336
export NON_PROD_API_KEY=xxx
37+
export NON_PROD_SECONDARY_API_KEY=xxx
3438
export INTEGRATION_API_KEY=xxx
3539
export PRODUCTION_API_KEY=xxx
40+
41+
# Status Endpoint API Key
42+
# In order to find the value of the status endpoint API key, follow these steps:
43+
# 1. Log in to the AWS NHS Notify Suppliers Dev account
44+
# 2. Open the paramenter store and search for the parameter /dev/e2e/keys/apim/status
45+
# 3. Copy the decrypted "value"
3646
export STATUS_ENDPOINT_API_KEY=xxx
3747

3848
# Private Keys
3949
# ============
50+
# In order to set the NON_PROD_PRIVATE_KEY, follow these steps:
51+
# 1. Log in to the AWS NHS Notify Suppliers Dev account
52+
# 2. Open the paramenter store and search for the parameter /dev/e2e/keys/private
53+
# 3. Copy the decrypted "value"
54+
# 4. Create a .pem file and paste the value copied in step 3,
55+
# save the file and provide the path to the file as the value for NON_PROD_PRIVATE_KEY
56+
# for example /workspaces/nhs-notify-supplier-api/scripts/JWT/internal-dev-test-1.pem
4057
# private key path used to generate authentication for tests ran against the internal-dev and internal-qa
4158
export NON_PROD_PRIVATE_KEY=xxx
4259
# private key path used to generate authentication for tests ran against the int environment

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## Contributing to NHS Notify Supplier API
1+
<!-- vale off -->
2+
3+
# Contributing to NHS Notify Supplier API
24

35
## Feature Branches
46

@@ -45,3 +47,11 @@ GitHooks **must** be configured and run on commits before pushing to remote. Ref
4547
## Testing Your Branch
4648

4749
You can test your branch in a dynamic environment prior to merging to `main`. These are created as part of the `cicd-1-pull-request.yaml` workflow, triggered when a PR is created or updated.
50+
51+
## Function Documentation
52+
53+
Each Lambda and internal package has a `README.md` alongside the source describing its purpose, flow, integration points, and peculiarities. These are bundled into the docs site via `docs/generate-includes.sh`.
54+
55+
When making changes to a Lambda or internal package, check whether the corresponding README needs updating. Function documentation is not auto-generated and can become stale if not maintained alongside code changes.
56+
57+
<!-- vale on -->

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This repository documents the Supplier API specification and provides an SDK wit
2424
- [Packages](#packages)
2525
- [Documentation](#documentation)
2626
- [SDK Assets](#sdk-assets)
27-
- [Examples](#examples)
2827
- [API Developers](#api-developers)
2928
- [Setup](#setup)
3029
- [Prerequisites and Configuration](#prerequisites-and-configuration)
@@ -64,10 +63,6 @@ If packages are unavailable the latest SDKs can be downloaded directly from:
6463
- TypeScript `sdk-ts-[Version].zip`
6564
- CSharp `sdk-csharp-[Version].zip`
6665

67-
### Examples
68-
69-
TODO:CCM-11209 Links to example clients.
70-
7166
## API Developers
7267

7368
New developers of the NHS Notify Supplier API should understand the below.
@@ -153,6 +148,14 @@ by default they will be available at [http://localhost:3050](http://localhost:30
153148

154149
These are generated using [https://hub.docker.com/r/openapitools/openapi-generator-cli](https://hub.docker.com/r/openapitools/openapi-generator-cli)
155150

151+
### Unit Testing
152+
153+
Run unit tests from the repository root:
154+
155+
```bash
156+
npm run test:unit
157+
```
158+
156159
### Documentation
157160

158161
- You can preview the OAS locally by running `make serve-oas`

config/suppliers/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!-- vale off -->
2+
3+
# Supplier Configuration
4+
5+
## Purpose
6+
7+
Static JSON configuration files that define the supplier allocation rules for the Supplier API. These are loaded into DynamoDB by infrastructure tooling and are queried at runtime by the `supplier-allocator` Lambda. Check relevant repositories (nhs-notify-internal, nhs-notify-supplier-config) as they orchestrate supplier config data ingress depending on target account, environment, etc.
8+
9+
## Configuration Entities
10+
11+
| Entity | Directory | Description |
12+
| ----------------------- | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
13+
| **Supplier** | `supplier/` | Print supplier definitions with ID, name, channel type, daily capacity, and status (PROD/DRAFT) |
14+
| **Letter Variant** | `letter-variant/` | Letter type definitions with physical constraints (sheets, sides, ink coverage, delivery days), associated pack specification IDs, and volume group assignment |
15+
| **Volume Group** | `volume-group/` | Groupings of letter variants for allocation purposes, with status and date range validity |
16+
| **Supplier Allocation** | `supplier-allocation/` | Maps a supplier to a volume group with a target `allocationPercentage` and status |
17+
| **Pack Specification** | `pack-specification/` | Detailed print assembly specs (paper, envelope, print colour, duplex) with constraints and billing ID |
18+
| **Supplier Pack** | `supplier-pack/` | Links a supplier to a pack specification with approval status |
19+
20+
## Allocation Lookup Chain
21+
22+
When the `supplier-allocator` Lambda processes a `LetterRequestPreparedEvent`:
23+
24+
1. The event's `letterVariantId` identifies the **Letter Variant**.
25+
2. The variant's `volumeGroupId` identifies the **Volume Group** (must be `PROD` status and within date range).
26+
3. **Supplier Allocations** for that volume group determine which suppliers are eligible and their target allocation percentages (must sum to 100).
27+
4. The variant's `packSpecificationIds` are filtered by the letter's physical constraints.
28+
5. **Supplier Packs** confirm which eligible suppliers support the selected pack specification.
29+
6. The supplier with the lowest weighted allocation factor (furthest below their target share) is selected.
30+
31+
## Nuances and Peculiarities
32+
33+
- These files are the source of truth for the supplier config DynamoDB table (`SUPPLIER_CONFIG_TABLE_NAME`). Changes here flow into DynamoDB via infrastructure deployment.
34+
- Runtime persistence is event-driven: supplier-config events are routed through SQS to the `supplier-config-ingress` Lambda, which upserts records into the config table.
35+
- `status: "PROD"` is required at multiple levels (supplier, volume group, allocation) for an allocation to be active.
36+
- Volume groups have `startDate` (and optional `endDate`) fields. Allocations are only valid when the current date falls within this range (evaluated in London timezone).
37+
- Supplier `dailyCapacity` is tracked separately in `SUPPLIER_QUOTAS_TABLE` and resets at midnight London time. It is not stored in these config files.
38+
39+
<!-- vale on -->

0 commit comments

Comments
 (0)