npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

osnds-juf

v0.4.2

Published

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

Downloads

514

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
  • Payment 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: "[email protected]",
    from: "[email protected]",
    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": "on",
  "apmMiddleware": "on",
  "writeLog": "on",
  "bootstrapDebug": "on",
  "servicesDebug": "on",
  "prepareOMPayCheckout": "on",
  "generateQR": "on",
}

Available services

  • sendEmail
import { sendEmail } from 'osnds-juf'

export const emailHandler = () => {
  // Your logic
  return sendEmail({
    subject: "Test JUF",
    to: "[email protected]",
    from: "[email protected]",
    body: "Testing out this",
  });
};
  • sendSMS
import { sendSMS } from 'osnds-juf'

export const smsHandler = () => {
  // Your logic
  return sendSMS({
    body: "JUST TESTING",
    senderName: "JUF JS",
    to: 771234567,
  });
};
  • startAPM
import express from 'express';
import { startAPM } from 'osnds-juf'

const app = express();

startAPM();

// Your Express app routes...

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
  • apmMiddleware
import express from 'express';
import { apmMiddleware, startAPM } from 'osnds-juf'

const app = express();

startAPM();

app.use(apmMiddleware)

// Your Express app routes...

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
  • writeLog
import express from 'express';
import { writeLog } from 'osnds-juf';

const app = express();

app.use((req, res, next) => {
  // Log request details
  writeLog({
    crypt: ['client_id', 'client_secret'], // Specify sensitive keys to replace
    appName: 'your-app-name',
    req,
    res,
    manualLog: { // this overrides the default req, res logging keys retrieval to specify your own
      logFrom: req.ip,
      userIp: req?.socket?.remoteAddress,
      method: req.method,
      payload: JSON.stringify(req.body),
      headers: JSON.stringify(req.headers),
      logTarget: req.originalUrl,
      userAgent: req.headers['user-agent'],
      logStatus: res.statusCode,
      logStatusCode: res?.statusMessage?.toUpperCase(),
    },
    logLevel: 'INFO', // default log level
    action: 'INCOMING REQUEST',
    logConsole: false, // it displays logs directly on console instead of writing it on file
    constantFileName: false // is at default false but can be set to true if you want the same file name all the time
  });
  next();
});

// Your Express app routes...

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
  • prepareOMPayCheckout
import { prepareOMPayCheckout } from 'osnds-juf';

export const omPayHandler = async () => {
  // Your logic
  return prepareOMPayCheckout({
    merchant_code: 123456,
    sitename: 'Juf.js',
    reference: 12,
    amount: 10,
    urls: {
      callbackUrl: 'https://example.com',
      successUrl: 'https://example.com',
      failedUrl: 'https://example.com',
      cancelUrl: 'https://example.com'
    }
  })
};
  • generateQR
import { generateQR } from 'osnds-juf';

export const qrHandler = async () => {
  // Your logic
  return generateQR({
    amount: 10,
    merchant_code: 467652,
    site_name: 'JUF.js',
    urls: {
      successUrl: 'https://example.com',
      cancelUrl: 'https://example.com'
    },
    metadata: {},
    validity: 10
  })
};
  • decodeQr (Needs special authorization)
import { decodeQr } from 'osnds-juf';

export const qrDecodeHandler = async () => {
  // Your logic
  return decodeQr({
    qrCodeId: 'azezaeazeaAZEAZ'
  })
};
  • generateTestNumbers
import { generateTestNumbers } from 'osnds-juf';

export const generateTestNumbersHandler = async () => {
  // Your logic
  return generateTestNumbers({ 
    nbCustomers: 1, 
    nbMerchants: 1, 
    nbRetailers: 1 
  })
};