Skip to content

Microservice integrating with SmartCar API to fetch data for connected vehicles and store in DynamoDB.

Notifications You must be signed in to change notification settings

asednev/smartcar-integration-webapp

Repository files navigation

Nest framework TypeScript starter repository.

Getting Started

Installation

$ npm install

Configuration

1. Create environment variable NODE_ENV

$ export NODE_ENV=dev

2. Create a .env config file matching your environment name (e.g . dev.env)

SmartCar.CLIENT_ID="[...]"
SmartCar.CLIENT_SECRET="[...]"
SmartCar.REDIRECT_URL="https://....ngrok.io/smartcar/exchange"
SmartCar.TestMode=true

AWS.Region="us-west-1"

This config is used by config.service.ts and loaded in config.module.ts

3. Create tables in DynamoDB

Table Hash Key Sort Key Notes
odo-vehicle vehicleId (string) N/A see vehicle.entity.ts for details
odo-odometerHistory vehicleId (string) date (number) see odometer-history.entity.ts for details

How SmartCar integration works

Smart Car SDK requires client id, client secret, and redirect url for callbacks. These can be obtained from Smart Car dashboard when creating an application.

For debuging purposes, use ngrok to open access for Smart Car backend to your local web server.

How AWS is configured

This package relies on AWS CLI credentials stored in the profile

$ cat ~/.aws/credentials

Named Profiles are supported in .env configuration file with option

AWS.Profile = profile_name

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Connecting to Smart Car

  1. Run the app
  2. Open http://localhost:3000/smartcar/auth
  3. Follow prompts in SmartCar interface
  4. Redirected back to https://xxxxxx.ngrok.io/smartcar/exchange?code=xxxxxxxxxx
  5. Check vehicle linked http://localhost:3000/debug/vehicles
  6. Run the batch http://localhost:3000/smartcar/updateBatch

Gotchas

400 Unauthorized redirect_uri: https://xxxxxxx.ngrok.io/smartcar/exchange

Smart Car requires whitelisting redirect URL in the dashboard. Login to the Smart Car and enter redirect URL under Credentials menu. The URL needs to match SmartCar.REDIRECT_URL in *.env config file.

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Powered By

Nest Logo NPM Version

About

Microservice integrating with SmartCar API to fetch data for connected vehicles and store in DynamoDB.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published