Skip to content

Commit

Permalink
Basic project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumarct committed Oct 9, 2023
1 parent 610fe79 commit bc46ee7
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CI

on: [push]

jobs:
build-tax-calculator:
name: Build the application for tax-calculator
runs-on: ubuntu-latest
env:
CTP_CLIENT_ID: ${{ secrets.CTP_CLIENT_ID }}
CTP_CLIENT_SECRET: ${{ secrets.CTP_CLIENT_SECRET }}
CTP_PROJECT_KEY: ${{ secrets.CTP_PROJECT_KEY }}
CTP_SCOPE: ${{ secrets.CTP_SCOPE }}
CTP_REGION: ${{ secrets.CTP_REGION }}
defaults:
run:
working-directory: tax-calculator
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: '16.x'

- name: Install modules
run: npm ci

- name: Check the coding style
run: npm run lint && npm run prettier

build-order-syncer:
name: Build the application for order-syncer
runs-on: ubuntu-latest
env:
CTP_CLIENT_ID: ${{ secrets.CTP_CLIENT_ID }}
CTP_CLIENT_SECRET: ${{ secrets.CTP_CLIENT_SECRET }}
CTP_PROJECT_KEY: ${{ secrets.CTP_PROJECT_KEY }}
CTP_SCOPE: ${{ secrets.CTP_SCOPE }}
CTP_REGION: ${{ secrets.CTP_REGION }}
defaults:
run:
working-directory: order-syncer
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: '16.x'

- name: Install modules
run: npm ci

- name: Check the coding style
run: npm run lint && npm run prettier
38 changes: 38 additions & 0 deletions connect.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
deployAs:
- name: tax-calculator
applicationType: service
endpoint: /
scripts:
postDeploy: npm install
configuration:
standardConfiguration:
- key: CTP_REGION
description: region of commercetools composable commerce project
securedConfiguration:
- key: CTP_PROJECT_KEY
description: project key from commercetools composable commerce project
- key: CTP_CLIENT_ID
description: client id from commercetools composable commerce project
- key: CTP_CLIENT_SECRET
description: client secret from commercetools composable commerce project
- key: CTP_SCOPE
description: scope from commercetools composable commerce project
- name: order-syncer
applicationType: event
endpoint: /
scripts:
postDeploy: npm install && npm run connector:post-deploy
preUndeploy: npm install && npm run connector:pre-undeploy
configuration:
standardConfiguration:
- key: CTP_REGION
description: region of commercetools composable commerce project
securedConfiguration:
- key: CTP_PROJECT_KEY
description: project key from commercetools composable commerce project
- key: CTP_CLIENT_ID
description: client id from commercetools composable commerce project
- key: CTP_CLIENT_SECRET
description: client secret from commercetools composable commerce project
- key: CTP_SCOPE
description: scope from commercetools composable commerce project
36 changes: 36 additions & 0 deletions order-syncer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "order-syncher",
"version": "1.0.0",
"type": "module",
"main": "src/index.js",
"private": true,
"scripts": {
"start": "node src/index.js",
"start:dev": "node_modules/.bin/nodemon -q src/index.js",
"lint": "node_modules/.bin/eslint src --ext .js",
"prettier": "node_modules/.bin/prettier --write '**/*.{js,ts}'",
"test": "echo Comment: It is npm command dedicated for running test in connect service",
"test:ci": "node_modules/.bin/jest --config jest.config.cjs"
},
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"babel-jest": "^29.6.2",
"eslint": "^8.46.0",
"jest": "^29.6.2",
"nodemon": "^2.0.20",
"prettier": "^2.8.8"
},
"dependencies": {
"@commercetools-backend/loggers": "^21.19.0",
"@commercetools/platform-sdk": "^4.1.0",
"@commercetools/sdk-client-v2": "^2.2.0",
"body-parser": "^1.20.1",
"dotenv": "^16.0.3",
"express": "4.18.2",
"supertest": "^6.3.3",
"validator": "^13.11.0"
}
}
15 changes: 15 additions & 0 deletions order-syncer/src/controllers/sync.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { logger } from '../utils/logger.utils.js';

export const syncHandler = async (request, response) => {
try {

// TODO: implement
} catch (err) {
logger.error(err);
if (err.statusCode) return response.status(err.statusCode).send(err);
return response.status(500).send(err);
}

// Return the response for the client
return response.status(200).send();
};
28 changes: 28 additions & 0 deletions order-syncer/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'dotenv/config';

import express from 'express';
import bodyParser from 'body-parser';

// Import routes
import SyncRoutes from './routes/sync.route.js';
import { logger } from './utils/logger.utils.js';

const PORT = 8080;

// Create the express app
const app = express();

// Define configurations
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Define routes
// TODO: Give a specific route name
app.use('/', SyncRoutes);

// Listen the application
const server = app.listen(PORT, () => {
logger.info(`⚡️ Event application listening on port ${PORT}`);
});

export default server;
10 changes: 10 additions & 0 deletions order-syncer/src/routes/sync.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from 'express';

import { syncHandler } from '../controllers/sync.controller.js';

const syncRouter = Router();

// TODO: Give a specific route name
syncRouter.post('/', syncHandler);

export default syncRouter;
3 changes: 3 additions & 0 deletions order-syncer/src/utils/logger.utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createApplicationLogger } from '@commercetools-backend/loggers';

export const logger = createApplicationLogger();
37 changes: 37 additions & 0 deletions tax-calculator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "tax-calculator",
"version": "1.0.0",
"type": "module",
"main": "src/index.js",
"private": true,
"scripts": {
"start": "node src/index.js",
"start:dev": "node_modules/.bin/nodemon -q src/index.js",
"lint": "node_modules/.bin/eslint src --ext .js",
"prettier": "node_modules/.bin/prettier --write '**/*.{js,ts}'",
"test": "echo Comment: It is npm command dedicated for running test in connect service",
"test:ci": "node_modules/.bin/jest --config jest.config.cjs"
},
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"babel-jest": "^29.6.2",
"eslint": "^8.46.0",
"jest": "^29.6.2",
"nodemon": "^2.0.20",
"prettier": "^2.8.8"
},
"dependencies": {
"@commercetools-backend/loggers": "^21.19.0",
"@commercetools/platform-sdk": "^4.1.0",
"@commercetools/sdk-client-v2": "^2.2.0",
"body-parser": "^1.20.1",
"dotenv": "^16.0.3",
"express": "4.18.2",
"supertest": "^6.3.3",
"validator": "^13.11.0"
}
}

15 changes: 15 additions & 0 deletions tax-calculator/src/controllers/tax.calculator.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { logger } from '../utils/logger.utils.js';

export const taxHandler = async (request, response) => {
try {

// TODO: implement
} catch (err) {
logger.error(err);
if (err.statusCode) return response.status(err.statusCode).send(err);
return response.status(500).send(err);
}

// Return the response for the client
return response.status(200).send();
};
27 changes: 27 additions & 0 deletions tax-calculator/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dotenv/config';

import express from 'express';
import bodyParser from 'body-parser';

// Import routes
import SyncRoutes from './routes/tax.calculator.route.js';
import { logger } from './utils/logger.utils.js';

const PORT = 8080;

// Create the express app
const app = express();

// Define configurations
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Define routes
app.use('/', SyncRoutes);

// Listen the application
const server = app.listen(PORT, () => {
logger.info(`⚡️ Event application listening on port ${PORT}`);
});

export default server;
10 changes: 10 additions & 0 deletions tax-calculator/src/routes/tax.calculator.route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Router } from 'express';

import {taxHandler} from '../controllers/tax.calculator.controller.js';

const syncRouter = Router();

// TODO: Give a specific route name
syncRouter.post('/', taxHandler);

export default syncRouter;
3 changes: 3 additions & 0 deletions tax-calculator/src/utils/logger.utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createApplicationLogger } from '@commercetools-backend/loggers';

export const logger = createApplicationLogger();

0 comments on commit bc46ee7

Please sign in to comment.