vendor-enquiry-api

Microservice to handle vendor enquiries.

Usage no npm install needed!

<script type="module">
  import vendorEnquiryApi from 'https://cdn.skypack.dev/vendor-enquiry-api';
</script>

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

  1. Every commit to a feature branch will be automatically built by Jenkins
  2. The channel #vendor-enquiryapi-ops will list all builds
  3. Click the deploy to UAT button to deploy
  4. BASE_URL: https://u-fe-server-vendor-enquiry-api.domain.com.au/swagger/

Deploying to Staging

  1. Announce deployment in #sellers channel
  2. Merge feature branch into master branch
  3. This will automatically build master branch and push to staging
  4. 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

  1. Ensure master is green in jenkins. Also ensure that the team has tested staging extensively.
  2. Announce deployment in #sellers channel
  3. Click on "Tag for Production Release" in the #vendor-enquiryapi-ops channel for the version want to release (latest version of master).
  4. This will trigger a staging build thats tagged.
  5. When complete the "Deploy to production" button will appear on #vendor-enquiryapi-ops for the build.
  6. Click it to deploy to prod if you have completely tested staging
  7. Check production when complete.
  8. 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

Swagger

Health

Ping

Swagger

  • To test Swagger in local: http://localhost:3000/swagger, you need to select version and appPrefix in the Swagger UI.
  • To create an enquiry without phone, remove phone from the request body. It would fail if the value is an empty string.

Authentication

  • auth scopes: read-enquiry and send-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,

1. create a js file following the stucture as belows in folder database/migrations

module.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

3. to revert a change, take database/migrations/20200430153400-add-user-id-to-enquiries-table.js as an example.

Important: 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