{"id":23067023,"url":"https://github.com/dvsa/ftts-booking-compensation-processor","last_synced_at":"2025-04-03T09:13:58.837Z","repository":{"id":44051598,"uuid":"480780692","full_name":"dvsa/ftts-booking-compensation-processor","owner":"dvsa","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-01T16:19:09.000Z","size":181,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-08T22:28:35.302Z","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":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-12T11:28:33.000Z","updated_at":"2024-01-03T09:22:07.000Z","dependencies_parsed_at":"2023-01-31T23:45:49.138Z","dependency_job_id":null,"html_url":"https://github.com/dvsa/ftts-booking-compensation-processor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fftts-booking-compensation-processor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fftts-booking-compensation-processor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fftts-booking-compensation-processor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvsa%2Fftts-booking-compensation-processor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvsa","download_url":"https://codeload.github.com/dvsa/ftts-booking-compensation-processor/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:56.736Z","updated_at":"2025-04-03T09:13:58.819Z","avatar_url":"https://github.com/dvsa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Booking Compensation Processor\n\nThis function helps to identify any bookings that need to be compensated due to a specific fault that affects multiple bookings. Any bookings that need to be compensated get flagged for follow up and then get dealt with accordingly.\n\n## Functions\n\nAll function definitions are housed under their own folder in the root of this project. As an example, see the `bookingCompensationProcessor` folder. The code that this function follows can be found in `src/bookingCompensationProcessor`.\n\n## Creating the local.settings.json\n\nFor this component, we use a `local.settings.json` file to store all environment variables to run the project locally.\n\nYou can create this file by running `npm run copy-config`\n\nLocally `CRM_CLIENT_ID` and `CRM_CLIENT_SECRET` are required for CRM authentication. `USER_ASSIGNED_ENTITY_CLIENT_ID` is not needed (only used deployed).\n\n## Building the project\n\nInstall node modules\n\n```bash\nnpm install\n```\n\nRun the build process\n\n```bash\nnpm run build\n```\n\n## Running the project locally\n\n- Run `npm run copy-config` and fill in the missing configuration in your local.settings.json. Set connection strings as below, pointing to deployed/local storage.\n- Run `npm start`. Running this start script triggers the `prestart` script which will automatically run the build process. The function will start on port `7071` by default. This can be configured within the `package.json` directly via the script.\n- The function will run as per the cron schedule specified. Or you can invoke the function manually via HTTP as explained below.\n\n### Pointing to deployed storage\n\nSet `AzureWebJobsStorage` and `BCP_FILE_STORAGE` as per the connection strings in the deployed configuration.\n\n### Pointing to locally emulated storage via Azurite\n\nSet `AzureWebJobsStorage` and `BCP_FILE_STORAGE` to `UseDevelopmentStorage=true`. Install Azurite eg. via the VSCode extension and then Start Blob Service.\n\n### Debugging\n\nDebug locally using the `.vscode/launch.json` 'Attach to Node Functions' config. Note the function will run on the default port `7071`.\n\n## Tests\n\nAll tests can be found in the `tests` folder.\n\nTo run all tests:\n\n```bash\nnpm test\n```\n\nTo run the tests in watch mode:\n\n```bash\nnpm run test:watch\n```\n\nTo run test coverage:\n\n```bash\nnpm run test:coverage\n```\n\nSee the generated coverage report in the `coverage` folder created after running the tests.\n\n### Integration tests\n\nThere are integration tests for both the CRM client and the BCP function itself.\n\nEnsure the .env file is in place with the correct environment variable values, an example can be found in .env.example\n\nRunning against local BCP instance (with Azurite) - set the connection strings to `UseDevelopmentStorage=true` accordingly. Function host and master key are not needed (defaults to localhost).\n\nRunning against deployed BCP instance - set the connection strings and function host (eg. \u003chttps://dsuksdvbcpfnc003.azurewebsites.net\u003e) per the deployed environment. Also set the function master key - you can retrieve this via the az-cli: `az functionapp keys list -n \u003cfunctionAppName\u003e -g \u003cresourceGroupName\u003e --query masterKey -o tsv`.\n\nTo run the integration tests:\n\n```bash\nnpm run test:int // All integration tests\nnpm run test:int-crm // CRM integration tests\nnpm run test:int-bcp // BCP function integration tests\n```\n\n## Linter\n\nWe use custom lint rules with `eslint` to enforce coding style for this project.\n\nTo run the linter:\n\n```bash\nnpm run lint\n```\n\nTo run the lint and fix any issues that can be resolved automatically:\n\n```bash\nnpm run lint:fix\n```\n\n## Invoking timer triggers manually\n\nIf you need to invoke a timer trigger for testing purposes but don't want to wait for the duration of the cron timer, you can use an Azure admin\nendpoint.\n\n- In Postman, make a `POST` request to the endpoint `/admin/functions/\u003cyour-function-name\u003e`.\n- Add the following to the body of the request:\n\n```json\n{\n    \"input\": \"test\"\n}\n```\n\n- If you are invoking the trigger to a deployed API on an environment, you need to add the `x-functions-key` header\nusing the master key from the function app. More information on this can be found [here](https://docs.microsoft.com/en-us/azure/azure-functions/functions-manually-run-non-http).\n\n- Send the request to invoke the timer trigger manually.\n\n## Function disabled\n\nNote in all envs other than PP and PR, the function is disabled by default when you deploy. This is to stop the function automatically running and processing bookings unintentionally. To enable the function, set the `AzureWebJobs.booking-compensation-processor.Disabled` env var to false. The default cron schedule is every 30 mins.\n\n## Function timeout\n\nOn Azure consumption plan the function will timeout after up to 10 minutes of execution (configurable via `functionTimeout` setting). To prevent destructive operations (such as cancelling bookings) starting before they can be guaranteed to be completed, a timeout check is implemented to make sure there is enough time left before the function timeout. Processing will be stopped (via a thrown exception) if:\n\n```javascript\nfunctionElapsedTime \u003e= (functionTimeout - functionTimeoutBuffer)\n```\n\nThe `functionTimeoutBuffer` can be adjusted via the FUNCTION_TIMEOUT_BUFFER_SECONDS env var.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvsa%2Fftts-booking-compensation-processor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvsa%2Fftts-booking-compensation-processor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvsa%2Fftts-booking-compensation-processor/lists"}