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": "commonjs",
"scripts": {
"clean": "rimraf lib",
"build": "npm run clean && tsc",
"start": "NODE_ENV=PRODUCTION node ./lib/index.js",
"dev": "nodemon --watch src --ext ts --exec ts-node ./src/index.ts",
"test": "jest"
},
...
}
Create tsconfig.json file:
tsconfig.json
{
"extends": "./node_modules/@sme.up/kokos-sdk-node/tsconfig.json",
"include": ["src/**/*"],
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
}
}
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
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": ""
}
}
}