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

@bloomingbox-ms/common

v1.0.22

Published

BloomingBox common package

Downloads

179

Readme

Description

This package include all the common things needed for each service

Installation

# Using NPM
npm install @bloomingbox-ms/common

# Using yarn (recommended)
yarn add @bloomingbox-ms/common

Features

  • permissions
  • auth middleware
  • cluster events handler
  • health check routes
  • timezone

How to get JWT token data

const {authMiddleware} = require('@bloomingbox-ms/common');

app.get(
  "/auth/me",
  authMiddleware,
  meController
);

meController.js


module.exports = async (req, res, next) => {
  const user = req.user;
  console.log({user})
};

console.log

  user: {
    _id: "6206a6c25e36716c181391cf",
    firstName: "isurindu",
    lastName: "***********",
    email: "*****@******.com",
    mobileNumber: "+971554573967",
    warehouse: [
      "6390d63a1eb4bc41e722d3a5",
      "6394363fb0486fdce0526ec5",
      "6390d6401eb4bc41e722d3a7"
    ],
    roles: [ "65597a978ee2584d4863194a" ]
  }

How to secure API

const {authMiddleware,authGuard} = require('@bloomingbox-ms/common');

app.get(
  "/auth/users",
  authMiddleware,
  authGuard.can(["user.view"]),
);

Insufficient Permissions Response - Status Code 403 Forbidden

module.exports = async (req, res, next) => {
  const user = req.user; //null or userObject
  console.log({user})
};

Guest Middleware provide user if exist otherwise null

const {guestMiddleware,authGuard} = require('@bloomingbox-ms/common');

app.get(
  "/auth/guest",
  guestMiddleware,
);

Insufficient Permissions Response - Status Code 403 Forbidden

{
    "success": false,
    "code": 403,
    "msg": "You do not have permission to perform this action!"
}

Health Check

const {healthRoutes} = require('@bloomingbox-ms/common');

app.use('/', healthRoutes);

Cluster events

how to dispatch a event

const {clusterEvent} = require('@bloomingbox-ms/common');

clusterEvent.dispatch("invoice.paid", {
    invoiceId: "123",
    amount: 100,
    currency: "USD",
});

how to listen to the event

const {clusterEvent} = require('@bloomingbox-ms/common');

clusterEvent.listen("payment-service", "invoice.paid", (payload) => {
    console.log("payment service pod 1", "invoice.paid");
});

Timezone

const { timezone } = require('@bloomingbox-ms/common');

const countryWithTimezone = timezone.availableCountries()
//{ ae: 'Asia/Dubai', sa: 'Asia/Riyadh' }

// Get current time in UTC format
const utcTime = timezone.getCurrentTimeUtc();

//Convert local time to UTC 
const convertLocalToUtc = timezone.convertLocalToUtc("2024-05-27","ae");

Get Country Code

const { countryCodeMiddleware } = require('@bloomingbox-ms/common');

app.use(countryCodeMiddleware);

Upgrade

npm install @bloomingbox-ms/common@latest

configure using .env

# JWT encryption key
KEY="" 

How to Use Translations

This package supports translations for multiple services, providing both English (en.json) and Arabic (ar.json) translation files for each service.

Available Services

  • cart-service
  • order-service
  • inventory-service
  • search-service
  • payment-service
  • slot-service
  • report-service
  • promo-service
  • auth-service
  • blog-service
  • cms-service
  • product-service
  • notification-service
  • azdan-service

Accessing Translations

To access translations, you can import the translations object from the package. Each service has its own translation files in English and Arabic.

const { translations } = require('@bloomingbox-ms/common');

// Access translations for cart-service
const cartServiceEn = translations['cart-service'].en;
const cartServiceAr = translations['cart-service'].ar;

console.log(cartServiceEn.welcome_message);  // Outputs: "Welcome to Cart Service"
console.log(cartServiceAr.welcome_message);  // Outputs: "مرحبًا بك في خدمة العربة"