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

jambonz-db-helpers

v0.3.4

Published

Downloads

3

Readme

jambonz-db-helpers Build Status

A set of helper functions to access data in the jambones database.

This module exposes a function that should be called with mysql configuration options and, optionally, a pino logger function. It then returns an object containing various useful functions for accessing and updating the database.

const mySqlOpts = {
  "host": "localhost",
  "user": "jambones_test",
  "database": "jambones_test",
  "password": "jambones_test"
};
const logger = require('pino')();
const {lookupAuthHook} = require('jambonz-db-helpers')(mySqlOpts, logger);
// now invoke lookupAuthHook per below

Functions

  • lookupAuthHook - retrieves the http authentication callback for a given sip realm/domain
  • lookupSipGatewayBySignalingAddress - retrieves the sip gateway associated with a given ipv4 dot-decimal address and sip port
  • performLcr - given a called number returns a preference-ordered list of carriers to use to complete the call

lookupAuthHook

lookupAuthHook(sip_realm) returns Promise

Retrieves the http authentication callback info for a given sip realm/domain, or null if no information is found for that domain.

HTTP authentication callbacks are configured in the accounts table (accounts.sip_realm). Furthermore if no exact match is found in the accounts table for a given sip realm, then a callback can be configured for the root domain in the service_providers.root_domain column.

This function is used by telephony apps that need to challenge incoming SIP requests, and therefore need to select the correct customer callback hook to delegate authentication to.

const obj = await lookupAuthHook('sip.example.com');
if (obj) {
  console.dir(obj);
  // {url: 'http://mycallback.com:3000, auth: {username: 'foo', password: 'bar}}
  // where obj.url is the callback url
  // and obj.auth is optional - if provided it means the url is protected using http basic auth
  // and the user/pass provided should be used when invoking it.
}

lookupSipGatewayBySignalingAddress

lookupSipGatewayBySignalingAddress(ipv4, port) returns Promise

Retrieves the sip gateway associated with a given ipv4 dot-decimal address and sip port. The function returns a Promise that resolves to sip gateway object, or null if no gateway exists at that ip:port.

const gateway = await lookupSipGatewayBySignalingAddress('192.168.1.100', 5060);
if (!gateway) logger.info('no gateway found at that address/port');

performLcr

performLcr(calledNumber) returns Promise throws Error if no match is found

Selects an ordered list of carriers to use to complete a call to the specified number. The function returns a Promise that resolves to an array of carriers.

The function throws Error('no configured lcr routes') if the database has no configured lcr routes, and Error('no matching lcr route') if none of the configured routes match.

try {
  const carriers = await performLcr('44928300633');
} catch (err) {
  // handle no routes match or found at all here..
}