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

@mobicoop/configuration-module

v8.2.0

Published

Mobicoop V3 configuration module

Downloads

281

Readme

Mobicoop V3 - Configuration package

NPM package used to get / set configuration items for Mobicoop V3 services into a Redis database.

Requirements

  • a running Redis server

Installation

npm install --save @mobicoop/configuration-module

Usage

Add the module in the imports section of the parent module, for example, using NestJs ConfigModule to inject values from .env:

...
import {
  ConfigurationModule,
  ConfigurationModuleOptions,
} from '@mobicoop/configuration-module';
import { ConfigModule, ConfigService } from '@nestjs/config';
...
imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    ConfigurationModule.forRootAsync({
        imports: [ConfigModule],
        inject: [ConfigService],
        useFactory: async (
        configService: ConfigService,
        ): Promise<ConfigurationModuleOptions> => ({
            host: configService.get<string>('REDIS_HOST'),
            password: configService.get<string>('REDIS_PASSWORD'),
            port: configService.get<number>('REDIS_PORT'),
        }),
    }),
],
...

You need to set the following options :

  • host : the redis hostname
  • password : the redis password
  • port : the redis port

Then you need to inject the ConfigurationRepository in a service with the appropriate port (GetConfigurationRepositoryPort to get a value, SetConfigurationRepositoryPort to set a value) :

...
import {
  ConfigurationDomain,
  ConfigurationType,
  ConfigurationValue,
  GetConfigurationRepositoryPort,
} from '@mobicoop/configuration-module';
...
constructor(
    @Inject(CONFIGURATION_REPOSITORY)
    private readonly configurationRepository: GetConfigurationRepositoryPort,
  ) {}
...
const myValue: ConfigurationValue = await this.configurationRepository.get(
    {
    domain: ConfigurationDomain.CARPOOL,
    key: 'seatsProposed',
    type: ConfigurationType.INT,
    },
);
...

The get methods requires an identifier (a domain and a key) as well as as a return type : the value will automatically be casted from string (as Redis stores values as strings) to the required type.

The mget can return many items but for a single domain. It requires the domain and a list of keys with their return type. It returns a Configurator object, that contains the list of configuration items (consisting in the domain, a key, and the value associated casted to the required type), as well as a get method to get a configuration value by its key. If one of the identifiers is not found, the whole methods throws.

The set methods requires an identifier (a domain and a key) and a value. The value will be casted to string (as Redis stores values as strings).

Available domains

  • AUTH : authentication & authorization related configuration items (eg. default password encryption algorithm)
  • CARPOOL : carpool related configuration items (eg. default number of seats proposed as a driver)
  • GEOGRAPHY : geographic related configuration items (eg. georouter settings)
  • MATCH : matching related configuration items (eg. default algorithm type)
  • PAGINATION : pagination related configuration items (eg. default number of results per page)

New domains will be added in the future depending on the needs !

Available types

As Redis stores values as strings, we need to cast these values when we get them. The available types are :

  • BOOLEAN
  • INT
  • FLOAT
  • JSON
  • JSON_ARRAY
  • STRING
  • STRING_ARRAY (stored in redis as a comma-separated string)
  • INT_ARRAY (stored in redis as a comma-separated string)
  • FLOAT_ARRAY (stored in redis as a comma-separated string)