The Checkin Request Service receives a request from an API service or consumer and processes the implied action for a given hold request.
Once the service validates the request and saves it to its database instance, it sends a new request via NCIP to the Sierra ILS, processes the response from Sierra ILS and returns a successful response or an error response.
After these responsibilities are met, the contract ends and another service or consumer takes over or the request terminates in a response from this service.
This service works in tandem with the NYPL Checkout Request Service. The two services now are consumed by Cancel Request Consumer for canceling a hold on a ReCap item in Sierra. The way to perform the cancelling is to check out and check in the item right away.
This package is intended to be used as a Lambda-based Node.js/PHP Patron Service using the NYPL PHP Microservice Starter.
This package adheres to PSR-1, PSR-2, and PSR-4 (using the Composer autoloader).
- Node.js >=6.0
- PHP >=7.0
Homebrew is highly recommended for PHP:
brew install php71
- Clone the repo.
- Install required dependencies.
- Run
npm install
to install Node.js packages. - Run
composer install
to install PHP packages. - If you have not already installed
node-lambda
as a global package, runnpm install -g node-lambda
.
- Run
- Setup configuration files.
- Copy the
.env.sample
file to.env
. - Copy
config/var_env.sample
toconfig/var_development.env
.
- Copy the
- Replace sample values in
.env
andconfig/var_development.env
.
Various files are used to configure and deploy the Lambda.
.env
is used locally for two purposes:
- By
node-lambda
for deploying to and configuring Lambda in all environments.- You should use this file to configure the common settings for the Lambda (e.g. timeout, Node version).
- To set local environment variables so the Lambda can be run and tested in a local environment. These parameters are ultimately set by the var environment files when the Lambda is deployed.
Configures npm run
commands for each environment for deployment and testing. Deployment commands may also set
the proper AWS Lambda VPC, security group, and role.
"scripts": {
"deploy-development": "./node_modules/.bin/node-lambda deploy -e development -f config/var_development.env -S config/event_sources_development.json -o {AWS Role} -b {subnets} -g {security-groups} --profile {personal AWS account credentials for nypl-sandbox}",
"deploy-qa": "./node_modules/.bin/node-lambda deploy -e qa -f config/var_qa.env -S config/event_sources_qa.json -o {AWS Role} -b {subnets} -g {security-groups} --profile {personal AWS account credentials for nypl-digital-dev}",
"deploy-production": "./node_modules/.bin/node-lambda deploy -e production -f config/var_production.env -S config/event_sources_production.json -o {AWS Role} -b {subnets} -g {security-groups} --profile {personal AWS account credentials for nypl-digital-dev}"
},
Configures environment variables common to all environments. This is also the place that holds the environment variables you need for running the service locally.
Configures environment variables specific to each environment.
Configures Lambda event sources (triggers) specific to each environment.
Start local test postgres db:
docker-compose -f db/docker-compose-db.yml up -d
Invoke on arbitrary event:
sam local invoke --profile nypl-digital-dev -t sam.local.yml --docker-network host -e events/checkin-item.json
To connect to the local db:
docker exec -it checkin-service-postgres-db psql -U postgres checkin_requests
To use node-lambda
to process the sample API Gateway event in event.json
, run:
npm run test-checkin
To use the PHP internal web server, run:
php -S localhost:8888 -t . index.php
You can then make a request to the Lambda: http://localhost:8888/api/v0.1/patrons
.
Notice that you will need a running database assigned to the service. Please set the correct configurations for the database in config/var_app.
Create a Swagger route to generate Swagger specification documentation:
$service->get("/docs", SwaggerGenerator::class);
A successful response for checking in will return a status code of 202
. However, if you continue to check in the same item — even it has been checked in — the response will still be succesful but only with a status code of 208
.
Before deploying, ensure configuration files have been properly set up:
- Copy
config/var_env.sample
toconfig/dev.env
,config/var_qa.env
, andconfig/var_production.env
.- Verify environment variables are correct.
- Verify
.env
has correct settings for deployment. - Verify
package.json
has correct command-line options for security group, VPC, and role (if applicable). - Verify
config/event_sources_dev.json
,config/event_sources_qa.json
,config/event_sources_production.json
have proper event sources.
To deploy to an environment, run the corresponding command. For example:
npm run deploy-development
or simply git push the development
or master
branch. The branch will be deployed respectively with Travis.
development => CheckinRequestService-development (nypl-sandbox) qa => CheckinRequestService-qa (nypl-digital-dev) master => CheckinRequestService-production (nypl-digital-dev)