eq-order v0.0.0-development
Solace Template
Purpose
This project provides a working template for creating NextGen microservices.
Environment vars
This project uses the following environment variables:
Name | Description | Required | Default Value | Accepted Values |
---|---|---|---|---|
NODE_ENV | Environment | Yes | DEV | DEV, TEST, PROD |
PASSWORD | Password for solace | Yes | --- | |
TEST_FILE | File to use when running PUB | No | testFile.json | |
REFRESH_TOKEN | Token for Equinox API call | Yes | ||
SESSION_ID | Session ID for Equinox API call | Yes |
Pre-requisites
- Node 14 or greater
- Access to the NextGen NPM Artifact Repository
- Configure a helm chart for your application.
- Add application to the Kubernetes environments
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.
- In the appropriate sub-group select "New project"
- Name your project
- Select a project description (optional)
- 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
- In
config/default.json`
, update the following:
serviceName
- the name of your service in eqServicesolace.userName
- the name of the solace user assigned to this servicesolace.clientName
- the name of the client associated with this service
- 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>
- Open .env file, and update variable values
- Build and run the project
yarn start
Project Structure
The folder structure of this app is explained below:
Name | Description |
---|---|
__mocks__ | Contains jest mocks |
__tests__ | Contains jest tests |
config | Application configuration including environment-specific configs |
src | Contains source code |
helpers | Contains code to do a test publish |
src/index.js | Entry point to the application |
Dockerfile | File used by docker to containerize application |
.gitignore | List of files and directories for Git to ignore |
jest.config.js | Configuration options for Jest |
.eslintrc | Configuration options for ES Lint |
.prettierrc | Configuration options for prettier |
package.json | Contains npm dependencies as well as build scripts |
.prettierignore | List of files and directories for prettier to ignore |
cx.config | File needed for common pipeline to pass |
yarn.lock | Yarn state snapshot |
.gitlab-ci.yml | CI pipeline configuration |
node_modules | Contains 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 Script | Description |
---|---|
start | Runs node on src/index.js. Can be invoked with yarn start |
pub | Sends test message. Can be invoked with yarn pub |
test | Runs tests with coverage using jest. Can be invoked with yarn test |
lint | Runs 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
2 years ago