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

@roast-cms/links

v0.5.6

Published

A Node.js API for managing affiliate links.

Downloads

5

Readme

links

An Express.js server middleware for managing affiliate links.

This project creates an API service which will return a link URL in response to a keyword (or another URL) and parameters (like locale). You can use the returned URL to either create redirects (link cloaking) or to simply manage links the HTML of your blog, website, or a tool.

Installation:

Prerequisites:

  • Express.js server.
  • MongoDB database.
  • Redis server.
  • A secret .env file in your root dir with a random APPLICATION_SECRET string & connection URIs (see .env.example).

yarn add @roast-cms/links

Implementation example:

import links from "@roast-cms/links";

app.use(
  links({
    // OPTIONAL path name for the `links` API on local Express router
    pathName: "/recommends",
  })
);

Complete example can be found in ./example-server.ts and can be run with yarn dev:example from this repo.

API:

GET /recommends/widget

{
  "link": "widget",
  "status": 200,
  "vendor": {
    "name": "eBay",
    "url": "https://ebay.com/us/widget?referral=you"
  }
}

For this example to work, MongoDB collection links should have the following document (vendors[].locale is optional):

{
  "link": "widget",
  "vendors": [
    {
      "url": "https://shop.com/us/widget?referral=you",
      "value": 1,
      "locale": "us",
      "name": "eBay"
    }
  ]
}
Parameters:
  • locale - Not implemented but planned. Would prioritize local vendors.
  • vendors - Select vendor groups. Currently implemented: "ALL", which lists all vendors for the link.

GET /recommends/group?tag=cameras

Returns all links for a given tag param.

GET /recommends/bulk?links=widget,toy,fancy-garmet

Returns all links (including all vendors) from array inferred from links param (uses array.split(",")). Limit of 10.

Usage (with React):

This an example using React framework, however, the idea would be the same in any kind of project (both on server and on the browser):

  1. Make an XHR (or fetch) request to links service with the key (must be a string) as a URL path and any parameters sent as a query.
  2. Wait for response.
  3. Use the response to create link in the returned HTML (though this could be any language your app is built in).
export const MyPage = () => {
  // manage state of the app (React-specific)
  const [myLink, setMyLink] = useState("#default-link");

  // send fetch request on page load and update state
  useEffect(() => {
    try {
      const linkResponse = await fetch("/recommends/widget?locale=us");
      const linkResponseJson = await linkResponse.json();
      setMyLink(linkResponseJson.vendor.url);
    } catch(error) {
      console.log(error);
    }
  },[]);

  // return page HTML
  return <div>This is my example text, oh, and look: an affiliate <a href={myLink}>link</link>!</div>
}

See example for authenticated implementation with an option to edit and archive links

To Do:

  • [x] Initialize project in Node.js with Mongoose (MongoDB)
  • [x] TypeScript and Jest
  • [ ] Add locale selection logic
  • [x] Allow link disabling/archiving