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

@brd.com/partner-connector

v0.7.7

Published

Generic partner connector starting point

Downloads

61

Readme

@brd.com/partner-connector

The BRD Partner Connector module provides tools for creating and managing partner connector repos. These tools include:

  • An RPC Server

  • Actions Helpers (functions to help you create valid action objects)

  • Screens Helpers (functions to help you create valid screen objects)

Plain Node Partner Connectors

Start by creating a node-app shell:

npx @brd.com/node-app create <name> <directory>

or a Nuxt shell:

npx @brd.com/node-app create-nuxt <name> <directory>

Install partner-connector (may need to do this inside of docker):

npm i --save @brd.com/partner-connector

You now will have a server/index.js with very little functionality. Add a partner-connector RPC stack like so:

const express = require('express');
const app = express();

const RPC = require('@brd.com/partner-connector/rpc-server');

app.use('/example/rpc',RPC({
  middleware: [
    async function(next) {
      this.console.log(`rpc - ${this.method} changed to availability`);
      this.method = 'availability';

      return await next();
    },
  ],
  methods: {
    async availability(params) {
      this.result = { foo: this.params||'bar' };

      // or:

      return { foo: params || 'bar' };
    }
  }
}));

module.exports = app;

If you're using a Nuxt-based connector, you automatically get the /_close route, designed to be the onClose parameter fed to the _browser endpoint.

Middleware

In order to be able to build reasonable, functional JSON-RPC services, it's important to be able to abstract "steps" in the request handling pipeline. We've used a Koa-like mechanism for middleware. Every step in the middleware chain can do anything to the response, re-route it, cancel it, etc. Hand off "down-chain" by calling await next(), and you can manipulate output after that call by editing this.result or this.error.

Methods:

Methods in the JSON-RPC stack are what eventually handle all the calls. You can route calls using middleware, but eventually they're handled by name in the methods hash (in a complex connector, this should probably be in its own file). Return the result or set this.result to the result you wish to be sent down-wire. Params are the first argument passed to the function, or you can use this.params.

RPC Context Object

The RPC context object (this in middleware and methods) includes the following:

  • req: the express request object (from node-app)
  • res: the express response object
  • id,method,params: from the JSON-RPC request
  • $t: translation function if it is supported
  • result: the result that will be sent to the client
  • error: the error that will be sent to the client

Deployment

Partner connectors use a somewhat different deployment strategy, make sure you set up your ingress TLS secrets to match the ones we already are using for other partners:

// deploy/ingress.js:

module.exports = function(hash) {
  if(['deploy-prod','deploy-stage'].includes(process.env.CI_JOB_STAGE)) {
    hash.spec.tls[0].secretName = `${process.env.CI_ENVIRONMENT_SLUG}-tls`;
  } else {
    hash.spec.tls[0].secretName = `wildcard-partners-tls`;
  }

  return hash;
};

You may also want to make sure your review environment names are unique (example for coinberry):

// deploy-review
deploy-review:
  stage: deploy-review
  <<: *global
  image: $DEPLOYER_IMAGE
  environment:
    name: cbrry-$CI_BUILD_REF_NAME
    url: https://$CI_COMMIT_REF_SLUG.partner.brd.tools/coinberry
    on_stop: stop-review

// stop-review:
stop-review:
  stage: stop-review
  <<: *global
  image: $DEPLOYER_IMAGE
  when: manual
  environment:
    name: cbrry-$CI_BUILD_REF_NAME
    url: https://$CI_COMMIT_REF_SLUG.partner.brd.tools/coinberry
    action: stop

Changelog

List of breaking changes per-version:

0.4

  • Adapted the currencies object to be able to create high-precision fractional things - e.g. to represent 0.001 USD or 0.000000001 BTC (mostly for exchange rates).