An AWS Lambda written in Node JS, responsible for listening to a stream of Hold Requests and sending all valid data to the appropriate Provider. See this writeup and this diagram for more context. The app essentially listens for newly created hold-requests broadcast by the HoldRequest service and performs the necessary work depending on the type of hold request:
- If the hold-request was placed in RC for an item in ReCAP, the app will hit the SCSB API
- If the hold-request was placed in RC for an on-site item, the app will hit the OnSiteHoldRequestService
- Requirements
- Getting Started
- Dependencies
v1.0
Install all Node dependencies via NPM
$ npm install
All deployment configuration is versioned in ./config/
. However..
The app expects one secret configuration param - SLACK_WEBHOOK_URL
- to be plaintext. For the purpose of putting all configuration in source control, we've gone ahead and encrypted it as SLACK_WEBHOOK_URL_ENCRYPTED
. The actual deployed variable remains plaintext and named SLACK_WEBHOOK_URL
. Thus, Travis can safely deploy to any environment without overwriting the real param. We should correct this situtation in the future by modifying the app to decrypt SLACK_WEBHOOK_URL
. (Update: Note that SLACK_WEBHOOK_URL is no longer used in deployed code, so we may consider retiring this feature.)
When HTC changes the SCSB endpoint, apply changes to the relevant environment file in config/
. SCSB_API_BASE_URL
should be plain text. SCSB_API_KEY
should be encrypted. Merging should deploy changes.
To develop and run your Lambda locally you must ensure to complete Step 1
and Step 2
of the Setup process.
Note: Your ./config/local.env
MUST be configured in order for the next step to work.
This will execute the sample event in event.json
:
$ npm run run-local
There are three more sample events in the events
folder:
- DiscoveryEvent.json, simulating a hold request from Discovery UI
- RecapEvent.json, simulating a hold request from Recap UI
- EddEvent.json, simulating an edd request from Discovery UI.
For details about how each of these events will be processed, see the github repo for the HoldRequestService: https://github.com/NYPL/hold-request-service. As documented there, only the edd request will be passed to the HoldRequestResult stream, and the others will be filtered out. Be aware that if you modify the events they may not be handled as expected by downstream processes since the HoldRequestResultConsumer relies on holds existing in the database.
Travis is configured to deploy automatically on updates to origin/development, origin/qa, and origin/main (i.e. production).
Deployments (AWS account nypl-digital-dev
):
- Production: Lambda > Functions > HoldRequestConsumer-production
- QA: Lambda > Functions > HoldRequestConsumer-qa
To manually deploy:
npm run deploy-[development|qa|production]
Istanbul is currently used in conjunction with Mocha to report coverage of all unit tests.
Simply run:
$ npm run coverage-report
Executing this NPM command will create a ./coverage/
folder with an interactive UI reporting the coverage analysis, now you can open up ./coverage/index.html
in your browser to view an enhanced report.
Unit tests are written using Mocha, Chai and Sinon. All tests can be found under the ./test
directory. Mocha configurations are set and can be modified in ./test/mocha.opts
.
To run test, use the following NPM script found in
package.json
.
$ npm run test // Will run all tests found in the ./test/ path
$ npm run test [filename].test.js // Will run a specific test for the given filename
This codebase currently aspires to use Standard JS as the JavaScript linter. (Ed. note: Semi-colons abound.)
To lint files use the following NPM command:
$ npm run lint // Will lint all files except those listed in package.json under standard->ignore
$ npm run lint [filename].js // Will lint the specific JS file
This repo follows a common Development-QA-Main git workflow (without tagging or CHANGELOG):
- Cut feature branch from
development
- After approval, merge into
development
- Merge
development
>qa
- Merge
qa
>main