Getting Started
Your business logic can be written in many languages. One of them is Javascript or Typescript using the Node.js ecosystem.
To simplify the creation of a micro-executor based on node.js, an SDK is available that contains everything necessary.
Prerequisites
Before jumping into development, make sure you have the following tools at your disposal:
Getting Started
Create a new Node.js project using NPM.
# Create project folder
mkdir [PROJECT_FOLDER]
# Positioning inside project folder
cd [PROJECT_FOLDER]
# Init Node.js project
npm init
Install SDK:
npm i @sme.up/kokos-sdk-node
Now open the project with your favorite IDE.
Update package.json
, add the following config:
package.json
{
...
"type": "module",
"scripts": {
"clean": "rimraf lib",
"build": "npm run clean && tsc",
"test": "NODE_ENV=test jest",
"dev": "NODE_ENV=development nodemon --watch './**/*.ts' --exec node --experimental-specifier-resolution=node --loader ts-node/esm ./src/index.ts",
"start": "NODE_ENV=production node ./lib/index.js",
"test:win": "SET NODE_ENV=test&&jest",
"dev:win": "SET NODE_ENV=development&&nodemon --watch . -e ts --exec \"node --experimental-specifier-resolution=node --loader ts-node/esm ./src/index.ts\"",
"start:win": "SET NODE_ENV=production&&node ./lib/index.js",
...
}
NB: [command]:win
identifies the command for Windows.
Create tsconfig.json
file:
tsconfig.json
{
"compilerOptions": {
"module": "ESNext",
"target": "ESNext",
"outDir": "./lib",
"baseUrl": "./src",
"rootDir": "./src",
"moduleResolution": "node",
"alwaysStrict": true,
"strict": true,
"noImplicitAny": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"declaration": true,
"sourceMap": true
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "lib", "**/*.test.ts"]
}
Create src/index.ts
file:
import { startServer } from "@sme.up/kokos-sdk-node";
startServer(MICRO_EXECUTOR_ID);
MICRO_EXECUTOR_ID
is the unique ID of your micro-executor.
The naming convention should be: "me-{language}-{company}-{usecase}"
, with -{usecase}
being optional.
For example, a micro-executor written in Node.js for the company Smeup that handles billing should be called "me-node-smeup-billing"
Create a sample KokosService in src/services/HELLO_WORLD.ts
:
import {
ExecutionContext,
Fun,
KokosService,
SmeupDataStructureWriter,
} from "@sme.up/kokos-sdk-node";
const HELLO_WORLD: KokosService = {
methods: {
"HLL.WRL": helloWorld,
},
};
async function helloWorld(
_fun: Fun,
_context: ExecutionContext,
printer: SmeupDataStructureWriter
) {
printer.writeDataNode({
children: [],
obj: {
t: "",
p: "",
k: "",
},
value: "Hello World",
});
}
export default HELLO_WORLD;
Run application:
# Linux
npm run dev
# Windows
npm run dev:win
Try to execute FUN using swagger execute fun api (http://localhost:8011/swagger/#/execution/ExecuteFun
)
Add the following payload:
{
"fun": {
"component": "TRE",
"service": "HELLO_WORLD",
"function": "HLL.WRL"
},
"context": {
"user": {
"sessionId": "",
"username": "",
"environment": "",
"device": ""
}
}
}