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

pulse-publisher

v10.0.2

Published

pulse-publisher

Downloads

145

Readme

Pulse Publisher

Build Status

A collection of utilities for interacting with Mozilla's Pulse.

Requirements

This is tested on and should run on any of node {7, 8, 10}.

Usage

The source-code contains additional comments for each method.

// Exchanges are typically declared in a file like exchanges.js
let Exchanges = require('pulse-publisher');

// Create a new set of exchanges
let exchanges = new Exchanges({
  name: 'myservice', // should match serviceName
  version: 'v1',
  title: 'Title for Exchanges Docs',
  description: [
    'Description in **markdown**.',
    'This will available in reference JSON',
  ].join(''),
});

// Declare an exchange
exchanges.declare({
  exchange: 'test-exchange', // Name-suffix for exchange on RabbitMQ
  name:     'testExchange',  // Name of exchange in reference JSON (used client libraries)
  title:    'Title for Exchange Docs',
  description: [
    'Description in **markdown**.',
    'This will available in reference JSON',
  ].join(''),
  schema:   'name-of-my-schema.yml',   // Schema for payload, a file in `schemas/<version>`
  messageBuilder: (message) => message, // Build message from arguments given to publisher.testExchange(...)
  routingKey: [
    // Declaration of elements that makes up the routing key
    {
      // First element should always be constant 'primary' to be able to identify
      // primary routingkey from CC'ed routing keys.
      name: 'routingKeyKind', // Identifier used in client libraries
      summary: 'Routing key kind hardcoded to primary in primary routing-key',
      constant: 'primary',
      required: true,
    }, {
      name: 'someId', // See routingKeyBuilder
      summary: 'Brief docs',
      required: true || false, // If false, the default value is '_'
      maxSize: 22,    // Max size is validated when sending
      multipleWords: true || false, // If true, the value can contain dots '.'
    }, {
      // Last element should always be multiple words (and labeled reserved)
      // The only way to match it is with a #, hence, we ensure that clients are
      // compatible with future routing-keys if add addtional entries in the future.
      name:             'reserved',
      summary:          'Space reserved for future use.',
      multipleWords:    true,
      maxSize:          1,
    }
  ],
  routingKeyBuilder: (message) => {
    // Build routingKey from arguments given to publisher.testExchange(...)
    // This can return either a string or an object with a key for each
    // required property specified in 'routingKey' above.
    return {
      someId: message.someIdentifier,
    };
  },
  CCBuilder: (message) => {
    // Construct CC'ed routingkeys as strings from arguments given to publisher.testExchanges(...)
    // By convention they should all be prefixed 'route.', so they don't interfer with the primary
    // routing key.
    return message.routes.map(r => 'route.' + r);
  },
});

// Note you can declare multiple exchanges, by calling exchanges.declare again.
// Nothing happens on AMQP before exchanges.connect() is called. This just declares
// the code in JS.

// Some where in your app, instantiate a publisher
let publisher = await exchanges.connect({
  rootUrl: ...,
  credentials: {
    hostname: ..,
    username: ..,
    password: ..,
    vhost: ..,
  },
  namespace: '...', // namespace for the pulse exchanges (e.g., `taskcluster-glurble`)
  expires: '1 day', // lifetime of the namespace
  validator: await schemaset.validator(rootUrl),
  monitor: undefined, // optional instance of taskcluster-lib-monitor
});

// Send a message to the declared testExchange
await publisher.testExchange({someIdentifier: '...', routes: [], ...});

Note that all four values for credentials must be included.

Alternately, if using taskcluster-lib-loader, create a loader component that calls setup, which will also publish the exchange reference:

  publisher: {
    requires: ['cfg', 'schemaset', 'monitor'],
    setup: ({cfg, validator, monitor}) => exchanges.setup({
      rootUrl:            cfg.taskcluster.rootUrl,
      credentials:        cfg.pulse,
      namespace:          cfg.pulse.namespace,
      expires:            cfg.pulse.expires,
      validator:          await schemaset.validator(cft.taskcluster.rootUrl),
      publish:            cfg.app.publishMetaData,
      aws:                cfg.aws,
      monitor:            monitor.prefix('publisher'),
    }),
  },

Docs can also be generated with exchange.reference(). See the source code docs for details.

Test Support

For testing, it is useful to be able to verify that messages were sent without requiring a real AMQP server.

Pass credentials: {fake: true} to connect or setup to get this behavior. No AMQP connection will be made, but each call to a message-publishing method will result in a "fakePublish" message emitted from the publisher with content {exchange, routingKey, payload, CCs}.

Testing

You'll need to fill a file called user-config.yml with valid keys. There is a user-config-example.yml you can copy over to see which keys are needed. Then it is just a matter of yarn install and yarn test.

License

Mozilla Public License Version 2.0