Socket
Socket
Sign inDemoInstall

@roast-cms/link-tool

Package Overview
Dependencies
10
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @roast-cms/link-tool

A Node.js API for managing affiliate links.


Version published
Maintainers
1
Created

Readme

Source

A Node.js API for managing affiliate links.

This project creates an API service which will return a link (most likely a URL) in response to a key (could be 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. This tools is currently in development -- see releases.

API:

GET /recommends/widget?locale=us
{
  "link": "https://shop.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"
    }
  ]
}

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 link-tool 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.link);
    } 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>
}

Installation:

After you've installed MongoDB (I recommend you also install MongoDB Compass) and Redis on your machine, create .env file in the root of this project folder and use .env.example as a template. For APPLICATION_SECRET, you'll need to create your own string of random numbers/letters (make sure to add your .env to .gitignore and not to share it publicly).

Then you can yarn dev to run the sample server.

To Do:

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

FAQs

Last updated on 31 Oct 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc