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

@macksterino/ts-credentials

v1.0.20

Published

Module used for easy handling of credentials

Downloads

2

Readme

@macksterino/ts-credentials

Purpose

Handling credentials individually or within an organization/company CAN be something that is managed very differently, which can create inconsistency. It is also something that can take up a fair amount of time, needing to write functionality to fetch credential files, create interfaces or types if desired. The goal with this module is to simply speed up this process and offer good ol' intellisense along with it.

Usage

Installation

$ npm install --save-dev @macksterino/ts-credentials

Credentials file

Requirements:

  • File format needs to be JSON.
  • The first environment needs to be your development/test environment and the second environment needs to be your production environment, although you can name them whatever you want.
  • All the module names and its information needs to be the same on both your development and production environment.

Example

{
	"development": {
		"SQL": {
			"server": "my development sql server",
			"database": "my development sql database",
			"username": "my development sql username",
			"password": "my development sql password"
		},
		"LDAP": {
			"url": "ldap://127.0.0.1:1389",
			"dn": "my development ldap username",
			"password": "my development ldap password"
		}
	},
	"production": {
		"SQL": {
			"server": "my production sql server",
			"database": "my production sql database",
			"username": "my production sql username",
			"password": "my production sql password"
		},
		"LDAP": {
			"url": "ldap://127.0.0.1:1389",
			"dn": "my production ldap username",
			"password": "my production ldap password"
		}
	}
}

Module

Parameters and functions

Parameters

The path to your credentials file.

  • path: string

The name of your global environment variable. If it is not defined or if it does not exist it will default to your test environment.

  • environmentVariableName?: string
Functions

Retrieves all the credentials. If an environment is not defined it will default to your test environment.

Note: If an environment is defined here it will be prioritized over your environment variable, if that is defined.

  • getCredentials(environment?: string): Credentials

Examples

Example 1
import { CredentialsHandler } from '@macksterino/ts-credentials';

const credentials = new CredentialsHandler({ path: './private/credentials.json' });

const config = credentials.getCredentials();

Note: At this point you will have to compile and run your code to generate your credential files and be able to get intellisense.

You might also need to refresh your editor/IDE or navigate to node_modules/@macksterino/ts-credentials/dist/credentials/types.d.ts for intellisense to update. This is something I'm currently working on.

Thereafter:

import { CredentialsHandler } from '@macksterino/ts-credentials';

const credentials = new CredentialsHandler({ path: './private/credentials.json' });

const config = credentials.getCredentials();
console.log(config.SQL);
console.log(config.LDAP);
Example 2
import { CredentialsHandler, CredentialsHandlerConfig } from '@macksterino/ts-credentials';

const credentialsConfig: CredentialsHandlerConfig = {
	path: './private/credentials.json'
};

const credentials = new CredentialsHandler(credentialsConfig);

const config = credentials.getCredentials();
console.log(config.SQL);
console.log(config.LDAP);
Examples with environments
import { CredentialsHandler, CredentialsHandlerConfig } from '@macksterino/ts-credentials';

const credentialsConfig: CredentialsHandlerConfig = {
	path: './private/credentials.json',
	environmentVariableName: 'ENVIRONMENT'
};

const credentials = new CredentialsHandler(credentialsConfig);

const config = credentials.getCredentials();
console.log(config.SQL);
console.log(config.LDAP);

If your environment variable exists, the module will read its value and see if it equals to the production environment value you specified inside your credentials file. If it does not exist or if it the values don't match it will automatically default to your test environment.

If your environment variable exists and the values match but you specify an environment inside the getCredentials() function, the environment specified within the function will ultimately be the environment that is used.

Another example
import { CredentialsHandler } from '@macksterino/ts-credentials';

const credentials = new CredentialsHandler({ path: './private/credentials.json', environmentVariableName: 'ENVIRONMENT' });

const config = credentials.getCredentials('production');
console.log(config.SQL);
console.log(config.LDAP);
Recommended example
import { CredentialsHandler } from '@macksterino/ts-credentials';

const credentials = new CredentialsHandler({ path: './private/credentials.json', environmentVariableName: 'ENVIRONMENT' });

const config = credentials.getCredentials();
console.log(config.SQL);
console.log(config.LDAP);