{"id":23066847,"url":"https://github.com/dvsa/hvt-atf-availability","last_synced_at":"2025-04-03T09:13:31.706Z","repository":{"id":43434039,"uuid":"339002670","full_name":"dvsa/hvt-atf-availability","owner":"dvsa","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-24T07:34:50.000Z","size":3388,"stargazers_count":0,"open_issues_count":22,"forks_count":1,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-24T08:35:09.069Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dvsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-15T07:50:48.000Z","updated_at":"2024-05-22T14:07:22.000Z","dependencies_parsed_at":"2023-01-30T18:00:40.582Z","dependency_job_id":"9f6a22d3-9d15-4196-948b-6231c2fdf282","html_url":"https://github.com/dvsa/hvt-atf-availability","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fhvt-atf-availability","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fhvt-atf-availability/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fhvt-atf-availability/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fhvt-atf-availability/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvsa","download_url":"https://codeload.github.com/dvsa/hvt-atf-availability/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246970323,"owners_count":20862509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T05:15:08.805Z","updated_at":"2025-04-03T09:13:31.687Z","avatar_url":"https://github.com/dvsa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hvt-atf-availability\n\nA Serverless Node Express lambda (AtfAvailabilityFunction) for updating ATF availability.\n\n## Requirements\n\n- [node v18.16.0](https://nodejs.org/en/download/releases/)\n- [Docker](https://www.docker.com/get-started)\n- [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)\n\n\n## Run Locally\n\n1. Follow build steps in [hvt-data](https://gitlab.motdev.org.uk/hvtesting/hvt-data/) to prepare local dataset and to generate the `KMS_KEY_ID` and an encrypted `JWT_SECRET`\n2. [hvt-read-api](https://github.com/dvsa/hvt-read-api/) and [hvt-write-api](https://github.com/dvsa/hvt-write-api/)  must be running\n3. Follow build steps in [hvt-token-generator](https://gitlab.motdev.org.uk/hvtesting/hvt-data/) to generate ATF tokens\n4. `npm i`\n5. `cp .env.development .env` (be sure to add the `KMS_KEY_ID` and `JWT_SECRET` variables - they can be created in `hvt-data`)\n6. `npm run build:dev`\n7. `npm run start:dev`\n8. Go to `http://localhost:3002/update?token=\u003cTOKEN_GENERATED_FROM_hvt-token-generator\u003e` on browser\n    - unique tokens for ATFs can be found on the DB\n\n\n## Debug Locally (VS Code only)\n\n1. Run lambdas in debug mode: `npm run start:dev -- -d 5858`\n2. Add a breakpoint to the lambda being tested (`src/controllers/index.controller.ts`)\n3. Run the debug config from VS Code that corresponds to lambda being tested (`AtfAvailabilityFunction`)\n4. Go to `http://localhost:3002/update?token=\u003cTOKEN_GENERATED_FROM_HVT-TOKEN-GENERATOR\u003e` on browser\n    - unique tokens for ATFs can be found on the DB\n\n\n## Tests\n\n- The [Jest](https://jestjs.io/) framework is used to run tests and collect code coverage\n- To run the tests, run the following command within the root directory of the project: `npm test`\n- Coverage results will be displayed on terminal and stored in the `coverage` directory\n    - The coverage requirements can be set in `jest.config.js`\n\n\n## Build for Production\n\n1. `npm i`\n2. Add environment variables to `.env`\n3. `npm run build:prod`\n4. Zip file and minified assets and can be found in `./dist/`\n\n\n## Logging\n\nBy using a utility wrapper (`src/util/logger`) surrounding `console.log`, the `awsRequestId` and a \"correlation ID\" is output with every debug/info/warn/error message.\n\nFor this pattern to work, every service/lambda must forward their correlation ID to subsequent services via a header e.g. `X-Correlation-Id`. \n\nIn practice, the first lambda invoked by an initial request will not have received the `X-Correlation-Id` header, so its `correlationId` gets defaulted to its `lambdaRequestId`.\nThis `correlationId` should then be used when invoking subsequent lambdas via the `X-Correlation-Id` header.\nEvery lambda called subsequently will then check for that `X-Correlation-Id` header and inject it into their logs.\n\nThis shows an example of what the log looks like from the first invoked lambda:\n```\n2020-09-10T17:03:04.891Z\t5ff37fce-5ace-114c-9120-a1406cc8d11d\tINFO\t{\"apiRequestId\":\"c6af9ac6-7b61-11e6-9a41-93e8deadbeef\",\"correlationId\":\"5ff37fce-5ace-114c-9120-a1406cc8d11d\",\"message\":\"Here's a gnarly info message from lambda 1 - notice how my correlationId has been set to my lambdaRequestId?\"}\n```\nThis shows an example of what the logs look like from the second invoked lambda (called via the first lambda):\n```\n2020-09-10T17:05:31.627Z\t32ff455b-057d-1dd7-98b8-7034bf182dc8\tINFO\t{\"apiRequestId\":\"d9222e0a-6bd9-49e0-84dd-ffe0680bd141\",\"correlationId\":\"5ff37fce-5ace-114c-9120-a1406cc8d11d\",\"message\":\"Here's a gnarly info message from lambda 2 - notice how my correlationId is the same as the lambda 1\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvsa%2Fhvt-atf-availability","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvsa%2Fhvt-atf-availability","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvsa%2Fhvt-atf-availability/lists"}