0.0.0-development • Published 2 years ago

eq-order v0.0.0-development

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Solace Template

App Status

Purpose

This project provides a working template for creating NextGen microservices.

Environment vars

This project uses the following environment variables:

NameDescriptionRequiredDefault ValueAccepted Values
NODE_ENVEnvironmentYesDEVDEV, TEST, PROD
PASSWORDPassword for solaceYes---
TEST_FILEFile to use when running PUBNotestFile.json
REFRESH_TOKENToken for Equinox API callYes
SESSION_IDSession ID for Equinox API callYes

Pre-requisites

Getting started

Follow these steps to create a new Serverless Lambda project using this template:

1. Clone this project to your local device and remove git control files

Note: We use 'my-project' as the name of your new project

git clone git@code.tls.nuskin.io:ns-am/templates/serverless-lambda.git <my-project>
cd <my-project>
rm -rf .git

2. Create a new blank project in GitLab

Create it in the correct location based on its domain, stack location and technology.

  1. In the appropriate sub-group select "New project"
  2. Name your project
  3. Select a project description (optional)
  4. Select "Create project"

3. Connect your local project to the gitlab remote project

You can copy and paste the section in the gitlab command line instructions of your new project into the command line of your local project. It will look like the following but will have your project specific details.

cd <your project folder if you are not already there>
git init
git remote add origin <your gitlab project url>
git add .
git commit -m "Initial commit"
git push -u origin master

4. Install npm modules for your project:

# use path from above
cd <my-project>
yarn

5. Application.yaml

The application.yaml file is used by the solace-sync cli tool for building out Solace resources needed by your application.

6. Customize your service

  1. In config/default.json`, update the following:
    • serviceName - the name of your service in eqService
    • solace.userName - the name of the solace user assigned to this service
    • solace.clientName - the name of the client associated with this service
  2. In ./transformer.js, build out your custom transformer

7. Create .env file # TODO: looks like this is only used by doPublish.js

This file is used for developing and running your application locally. Do not commit this file to your git repo.

NODE_ENV=dev
PASSWORD=<password>
REFRESH_TOKEN=<token>
SESSION_ID=<sessionid>
  1. Open .env file, and update variable values
  2. Build and run the project
yarn start

Project Structure

The folder structure of this app is explained below:

NameDescription
__mocks__Contains jest mocks
__tests__Contains jest tests
configApplication configuration including environment-specific configs
srcContains source code
helpersContains code to do a test publish
src/index.jsEntry point to the application
DockerfileFile used by docker to containerize application
.gitignoreList of files and directories for Git to ignore
jest.config.jsConfiguration options for Jest
.eslintrcConfiguration options for ES Lint
.prettierrcConfiguration options for prettier
package.jsonContains npm dependencies as well as build scripts
.prettierignoreList of files and directories for prettier to ignore
cx.configFile needed for common pipeline to pass
yarn.lockYarn state snapshot
.gitlab-ci.ymlCI pipeline configuration
node_modulesContains package dependencies

Building the project

Running the build

All the different build steps are orchestrated via yarn scripts. yarn scripts basically allow us to call (and chain) terminal commands via npm.

yarn ScriptDescription
startRuns node on src/index.js. Can be invoked with yarn start
pubSends test message. Can be invoked with yarn pub
testRuns tests with coverage using jest. Can be invoked with yarn test
lintRuns ESLint on project files. Can be invoked with yarn lint

Testing

The tests and assertions use Jest. Testing also utilizes eslint and prettier plugins.

"@jest/globals": "27.3.1",
"eslint": "8.2.0",
"eslint-plugin-jsdoc": "38.0.4",
"eslint-plugin-json": "3.1.0",
"jest": "28.1.0",
"jest-runner-eslint": "1.0.0",
"jest-runner-prettier": "1.0.0",
"jest-sonar-reporter": "2.0.0",
"prettier": "2.4.1"

Running tests using yarn Scripts

yarn test

ESLint

ESLint is a code linter that helps catch minor code quality and style issues.

ESLint rules

All rules are configured through .eslintrc.

Running ESLint

To run ESLint you can call the ESLint task.

yarn lint  // runs only ES lint

Common Issues