JSPM

  • Created
  • Published
  • Downloads 21
  • Score
    100M100P100Q51362F
  • License MIT

It's an helpful Javascript Utility Framework to ease Javascript application development in SONATEL context.

Package Exports

  • osnds-juf
  • osnds-juf/dist/index.esm.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (osnds-juf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

JUF.js

Getting Started

Who is Mr JUF.js (Javascript Utility Framework) ?

It's an helpful Javascript Utility Framework to ease Java application development in SONATEL context. It's has three main modules :

  • Logging, Monitoring & Messaging module
  • Core module

What is JUF Logging & Monitoring?

This module helps to have a normalized logging format and also enrich logs with some additional fields (correlator.id, trace.id, span.id). It also allows to easily log audits based on format as defined by Security Department. It's highly customizable & activable/deactivable through a simple property.

Configure Logging

For better readability logging pattern is piped by default except in production (where it cannot be overridable)

  • example:

    Json format

{"@timestamp":"2020-05-07T21:48:24.048","log.level":"INFO ","service.name":"demoApp","logger":"LoggingAspect","message":{"event.type":"AUDIT","client.ip":"0:0:0:0:0:0:0:1","source.name":"localhost","user.name":"anonymoususer","event.category":"Enter","event.action":"Dividing two integers","http.request.body.content":"{\"leftOperand\":4,\"rightOperand\":2}","user_agent.original":"PostmanRuntime/7.24.0","url.path":"/api/calculator/v1/div/4/2","http.request.method":"GET","process.thread.id":"20"}}
{"@timestamp":"2020-05-07T21:48:24.117","log.level":"INFO ","service.name":"demoApp","logger":"LoggingAspect","message":{"event.type":"AUDIT","client.ip":"0:0:0:0:0:0:0:1","source.name":"localhost","user.name":"anonymoususer","event.category":"Exit","event.action":"Dividing two integers","user_agent.original":"PostmanRuntime/7.24.0","url.path":"/api/calculator/v1/div/4/2","http.request.method":"GET","http.response.status":"SUCCESS","http.response.status_code":"200","event.duration":"68","process.thread.id":"20"}}
Standard format (default one)
@timestamp:2020-05-07T21:54:54.673 | service.name:demoApp | event.type:AUDIT | client.ip:127.0.0.1 | source.name:localhost | user.name:anonymoususer |  event.category:Enter |  event.action:Dividing two integers | http.request.method:GET | http.request.body.content:{"leftOperand":4,"rightOperand":2} | url.path:/api/calculator/v1/div/4/2 | user_agent.original:PostmanRuntime/7.24.0 | process.thread.id:21 |
@timestamp:2020-05-07T21:54:54.741 | service.name:demoApp | event.type:AUDIT | client.ip:127.0.0.1 | source.name:localhost | user.name:anonymoususer |  event.category:Exit  |  event.action:Dividing two integers | http.request.method:GET | url.path:/api/calculator/v1/div/4/2 | user_agent.original:PostmanRuntime/7.24.0 | http.response.status:SUCCESS | http.response.status_code:200 | event.duration:66 | process.thread.id:21 |
Step 1: add dependencies (using starters)

With yarn

yarn add osnds-juf@latest

Or

npm i --save osnds-juf@latest
Step 2 : Create or add in your env variables
JUF_APIGEE_ON_PROD=true # Default false for sandbox
JUF_APIGEE_CLIENT_ID="<CLIENT_ID>"
JUF_APIGEE_CLIENT_SECRET="<CLIENT_SECRET>"

# If you're using APM services
JUF_ELK_APM_ENV_NAME="<APM_ENVIRONMENT_NAME>"
JUF_ELK_APM_SERVICE_NAME="<APM_SERVICE_NAME>"
JUF_ELK_APM_SECRET_TOKEN="<PASSWORD>"
JUF_ELK_APM_SERVER="<SERVER_URL>"
JUF_ELK_APM_LOG_LEVEL="<LOG_LEVEL>" // default is info
Step 3 : Configure the CODE !! 🎊
import { sendEmail, sendSMS } from "osnds-juf";

export const emailHandler = () => {
  // Your logic
  return sendEmail({
    subject: "Test JUF",
    to: "someone@juf.js",
    from: "testingout@juf.js",
    body: "Testing out this",
  });
};

export const smsHandler = () => {
  // Your logic
  return sendSMS({
    body: "JUST TESTING",
    senderName: "JUF JS",
    to: 771234567,
  });
};

It allows to automatically :

  • Connect to API Management through your provided creds
  • Either send SMS or Mail

Debug all services

You have access to all services by doing this

import { servicesDebug } from "osnds-juf";

console.log(servicesDebug());
// You'll have something like this

{
  "authenticationDebug": "on",
  "sendEmail": "on",
  "sendSMS": "on",
  "startAPM": "off",
  "writeLog": "on",
  "bootstrapDebug": "on",
  "servicesDebug": "on"
}

Incomming

For more details regarding the monitoring options please refer to the documentation