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

pg-insights

v0.2.4

Published

Reusable insight-system built with Postgres and Hapi.

Downloads

22

Readme

Insights

Build Status codecov

Pre-requisites:

  • Create an insights and insights_test database:
    CREATE DATABASE insights;
    CREATE DATABASE insights_test

This plugin exposes the following functions on the request.server.methods.pg.insights object:

getById(insightId, cb)

function to return the details of a specific insight, where insightId is the ID of the insight to retrieve.

The insight details take the following format:

[{
  id: 1,
  date: 2016-12-23T11:27:41.760Z,
  title: 'Insight Number 1',
  url: 'https://....',
  active: true,
  tags: [
  {
    tag_id: 8,
    tag_name: 'Agriculture'
  }, {
    tag_id: 22,
    tag_name: 'Telecommunications'
  }, {
  ...
}]

edit(insightObj, cb)

function to add a new insight, where insightObj takes the form:

{
  title: 'Insight Title',
  url: 'www.ce100-insight-url.com',
  doctype: '.pdf',
  author: 'EMF',
  org_id: null,
  creator_id: 1,
  resource: true
}

On the successful save, the new insight's ID (generated by postgres) is returned.

add(insightObj, cb)

function to add a new insight, where insightObj takes the form:

{
  title: 'Insight Title',
  url: 'www.ce100-insight-url.com',
  type: 'REPORT',
  author: 'EMF',
  org_id: null,
  creator_id: 1,
  resource: true,
  active: true
}

On the successful save, the new insight's ID (generated by postgres) is returned.

browse(activeOnly, filterTag, cb)

function to browse all active (and inactive) insights, with the option to filter by a certain tag id. The parameters take the following values respectively:

  • activeOnly = Boolean.
    • true to return active insights only.
    • false to return all active and inactive insights.
  • filterTag:
    • Integer if we want to filter by a tag id
    • false if we do not want to filter

If a tag id is given, returns:

{ filter: { id: 69, name: 'Design for disassembly' },
  insights:
  [{
    id: 1,
    date: 2016-12-23T11:27:41.760Z,
    title: 'Insight Number 1',
    url: 'https://....',
    active: true,
    tags: [
    {
      tag_id: 8,
      tag_name: 'Agriculture'
    }, {
      tag_id: 22,
      tag_name: 'Telecommunications'
    }, {
  ...
  }]
}

If false is given, returns the same shape, but with

filter_tag: undefined

toggle(insightId, cb)

function to set an existing insight to be active or inactive. insightId specifies the ID of the insight to toggle.

getResources(activeOnly, cb)

function to return the details of active and inactive resources. The activeOnly parameter is a Boolean. Set it to:

  • true to return active insights only.
  • false to return all active and inactive insights.

The resources take the following format:

[{
  id: 1,
  title: 'Insight Number 1',
  url: 'https://....',
  author: 'Kamala Khan',
  type: 'REPORT',
  active: true
  }, {
  ...
}]

Note that the active field is not returned when activeOnly === true, as all resources returned will be active.