README
Vendor Enquiry API Microservice
This is a microservice that allows you to create and retrieve vendor enquiries.
Description
Posting an enquiry to this API:
- Saves the submissions to a PostgreSQL database
- Sends an email to the recipient agent (Using Email API)
- Sends a confirmation email to the submitter (Using Email API)
- Sends an SMS to the recipient agent (Using Twilio)
Note:
Recently the API has been updated to use uuids
rather than numbers
for Enquiry Ids. These are now named enquiryId(s)
in the params and enquiryId
in the response bodies.
Up and running instructions
To install and configure the application, run:
git clone git@github.com:domain-group/vendor-enquiry-api.git
cd vendor-enquiry-api
yarn
make local-development.js
and local-test.js
and then enter with the following contents:
module.exports = { encryptionKey: 'XXXX', auth: { secret: 'XXXX', }, sql: { password: 'XXXX', }, twilio: { token: 'XXXX', }, KINESIS_ACCESS_KEY_SECRET: 'XXXX', };
Please get these values from someone who has them already or you can get it from LastPass.
You are now good to run the app!
yarn start
Release Process
We're using Semantic Release in this project. See:
https://github.com/domain-group/fe-semantic-release-config https://www.conventionalcommits.org/en/v1.0.0/ https://semantic-release.gitbook.io/semantic-release/ To see latest changelog:
git checkout master # be on master ./node_modules/.bin/semantic-release --dry-run If unsure how to format your commit messages, just run git commit for a guided process.
Deployments
Deploying to UAT
- Every commit to a feature branch will be automatically built by Jenkins
- The channel
#vendor-enquiryapi-ops
will list all builds - Click the
deploy to UAT
button to deploy - BASE_URL:
https://u-fe-server-vendor-enquiry-api.domain.com.au/swagger/
Deploying to Staging
- Announce deployment in
#sellers
channel - Merge feature branch into master branch
- This will automatically build master branch and push to staging
- Check monitoring on staging using one of the below urls:
[Dashboard]
https://b9574efa70674d6ea5a9cd39a9e16aff.ap-southeast-2.aws.found.io:9243/s/nova-team/app/kibana#/dashboard/3356b910-bfec-11ea-bc6c-09d4f4f4f7e6?_g
[APM] https://b9574efa70674d6ea5a9cd39a9e16aff.ap-southeast-2.aws.found.io:9243/s/nova-team/app/apm#/services/vendor-enquiry-api/transactions?rangeFrom=now-15m&rangeTo=now&refreshPaused=true&refreshInterval=0&environment=staging&transactionType=request
[Discover] https://b9574efa70674d6ea5a9cd39a9e16aff.ap-southeast-2.aws.found.io:9243/s/nova-team/app/kibana#/discover?_g=(refreshInterval:(pause:!f,value:10000),time:(from:now-15m,to:now))&_a=(columns:!(_source),index:'78bbb780-6002-11e9-8f25-9b328dfd68e3',interval:auto,query:(language:kuery,query:vendor-enquiry-api),sort:!(!('@timestamp',desc)))
Deploying to Production
- Ensure
master
is green in jenkins. Also ensure that the team has tested staging extensively. - Announce deployment in
#sellers
channel - Click on "Tag for Production Release" in the
#vendor-enquiryapi-ops
channel for the version want to release (latest version of master). - This will trigger a staging build thats tagged.
- When complete the "Deploy to production" button will appear on
#vendor-enquiryapi-ops
for the build. - Click it to deploy to prod if you have completely tested staging
- Check production when complete.
- Check monitoring for atleast an hour using one of the below urls:
[Dashboard]
https://6f8d2b03da5e435dbffdb0a3af40df40.ap-southeast-2.aws.found.io:9243/s/nova-team/app/kibana#/dashboard/4c850890-bfee-11ea-ad24-f7dd0823d8aa?_g
[APM] https://6f8d2b03da5e435dbffdb0a3af40df40.ap-southeast-2.aws.found.io:9243/s/nova-team/app/apm#/services/vendor-enquiry-api/transactions?rangeFrom=now-15m&rangeTo=now&refreshPaused=true&refreshInterval=0&environment=production&transactionType=request
[Discover] https://6f8d2b03da5e435dbffdb0a3af40df40.ap-southeast-2.aws.found.io:9243/s/nova-team/app/kibana#/discover?_g=()&_a=(columns:!(_source),index:aee8e280-b11c-11ea-86f8-d99330156a60,interval:auto,query:(language:kuery,query:'Application:%22vendor-enquiry-api%22%20OR%20service.name:%22vendor-enquiry-api%22'),sort:!(!('@timestamp',desc)))
Notes
The endpoints require the client to have the scope send-enquiry
.
The documentation is available on https://www.domain.com.au/vendor-enquiry-api/swagger/
.
Note: This service does not send SMS in development or stage, it will only send them in production.
Links
Api
- Production URL: https://www.domain.com.au/vendor-enquiry-api
- Staging URL: https://stage.domain.com.au/vendor-enquiry-api
- Uat URL: https://u-fe-server-vendor-enquiry-api.domain.com.au
- Local URL: http://localhost:3000
Swagger
- Production Swagger Docs: https://p-fe-server-vendor-enquiry-api.domain.com.au/swagger
- Staging Swagger Docs: https://s-fe-server-vendor-enquiry-api.domain.com.au/swagger
- Uat Swagger Docs: https://u-fe-server-vendor-enquiry-api.domain.com.au/swagger
- Local Swagger Docs: http://localhost:3000/swagger
Health
- Production Health Endpoint: https://www.domain.com.au/vendor-enquiry-api/health
- Staging Health Endpoint: https://stage.domain.com.au/vendor-enquiry-api/health
- Uat Health Endpoint: https://u-fe-server-vendor-enquiry-api.domain.com.au/health
- Local Health Endpoint: http://localhost:3000/health
Ping
- Production Ping Endpoint: https://www.domain.com.au/vendor-enquiry-api/ping
- Staging Ping Endpoint: https://stage.domain.com.au/vendor-enquiry-api/ping
- Uat Ping Endpoint: https://u-fe-server-vendor-enquiry-api.domain.com.au/ping
- Local Ping Endpoint: http://localhost:3000/ping
Swagger
- To test Swagger in local: http://localhost:3000/swagger, you need to select
version
andappPrefix
in the Swagger UI. - To
create an enquiry without phone
, removephone
from the request body. It would fail if the value is an empty string.
Authentication
- auth scopes:
read-enquiry
andsend-enquiry
Builds can be monitored in Jenkins: https://jenkins.domain.com.au/job/Domain/job/vendor-enquiry-api
Database
The command-line tool sequelize cli
has a feature migrations
, which is used to modify/revert the changes made on the database. See more details in https://sequelize.org/master/manual/migrations.html
To make a change on the database VendorEnquiryApi
, e.g. add a column to the table Enquiries
,
database/migrations
1. create a js file following the stucture as belows in foldermodule.exports = {
up: (queryInterface, Sequelize) => queryInterface.addColumn(
'Enquiries',
'userId',
{ type: Sequelize.STRING },
),
down: (queryInterface, Sequelize) => queryInterface.removeColumn(
'Enquiries',
'userId',
),
}
2. run the command as belows
// staging
NODE_ENV=staging SQL_DATABASE_PASSWORD=pwd_staging npx sequelize db:migrate
// production
NODE_ENV=production SQL_DATABASE_PASSWORD=pwd_prod npx sequelize db:migrate
database/migrations/20200430153400-add-user-id-to-enquiries-table.js as an example.
3. to revert a change, takeImportant: without --name will revert all files under the migrations folder, which would delete all tables and data
// staging
NODE_ENV=staging SQL_DATABASE_PASSWORD=pwd_staging npx sequelize db:migrate:undo --name 20200430153400-add-user-id-to-enquiries-table
// production
NODE_ENV=production SQL_DATABASE_PASSWORD=pwd_prod npx sequelize db:migrate:undo --name 20200430153400-add-user-id-to-enquiries-table
4. to check the migrations status
// staging
NODE_ENV=staging npx sequelize db:migrate:status
// You would see something like the follows: "up" means the change has been made, "down" means the change has been made but reverted.
// Sequelize CLI [Node: 10.19.0, CLI: 5.5.1, ORM: 4.43.0]
// Loaded configuration file "database/configuration.js".
// up 20180118010139-create-enquiries-table.js
// down 20200430153400-add-user-id-to-enquiries-table.js