Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobussacchini committed May 28, 2024
0 parents commit a51e19f
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/develop-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: develop-release

on:
push:
branches:
- develop

jobs:
docker-release:
uses: smeup/devops/.github/workflows/docker-release.yaml@main
with:
docker-tag: latest
docker-repository-name: kokos-node-workshop
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
lib
.vscode
package-lock.json
docs
.env
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Build step
FROM node:18-slim AS builder

WORKDIR /app

COPY package*.json /app

# Install node dependencies and build
RUN npm install
COPY . .
RUN npm run build

# Run step
FROM node:18-slim AS server

WORKDIR /home/kokos

COPY package* ./

# Install node dependencies
RUN npm install
COPY --from=builder ./app/lib ./lib

# create kokos group
RUN addgroup kokos

RUN useradd -m -s /bin/bash -g kokos kokos

# set working dir permissions
RUN chown -R kokos:kokos /home/kokos

# run container as user kokos
USER kokos

EXPOSE 8011
CMD ["npm", "run", "start"]
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Micro Executor Node Workshop

This application is based on: [Kokos SDK Node](https://docs.smeup.cloud/en/CLS-SU/MURUNT/OPE/MURUNT_03/sdk-node).

## Development

```sh
git clone https://github.com/smeup/kokos-me-node-workshop.git
cd kokos-me-node-workshop
npm install
```
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "test-jsonapi",
"version": "1.0.0",
"description": "",
"main": "index.js",
"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/entrypoint/restapi/index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@sme.up/kokos-sdk-node": "^0.2.0-SNAPSHOT",
"axios": "^1.7.2"
}
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { startServer } from "@sme.up/kokos-sdk-node";

startServer("me-node-test");
30 changes: 30 additions & 0 deletions src/interfaces/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export interface Address {
street: string;
suite: string;
city: string;
zipcode: string;
geo: Geo;
}

export interface Geo {
lat: string;
lng: string;
}

export interface Company {
name: string;
catchPhrase: string;
bs: string;
}

export interface User {
id: number;
name: string;
username: string;
email: string;
address: Address;
phone: string;
website: string;
company: Company;
}

53 changes: 53 additions & 0 deletions src/services/JsonPlaceholderService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
ExecutionContext,
Fun,
KokosService,
SmeupDataStructureWriter,
User,
} from "@sme.up/kokos-sdk-node";

import axios from 'axios';

async function fetchUsers() {
try {
const response = await axios.get('https://jsonplaceholder.typicode.com/users');
return response.data;
} catch (error) {
console.error('Error fetching data from API:', error);
throw error;
}
}

const JsonPlaceholderService: KokosService = {
methods: {
"GET.TRE": getTree,
},
};

async function getTree(
_fun: Fun,
_context: ExecutionContext,
printer: SmeupDataStructureWriter
) {

const users: User[] = await fetchUsers();

users.forEach(el => {
printer.writeTreeNode({
children: [],
content: {
tipo: "",
parametro: "",
codice: "",
testo: el.username,
},
});

});




}

export default JsonPlaceholderService;
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"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"
]
}

0 comments on commit a51e19f

Please sign in to comment.