Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@roast-cms/link-tool

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@roast-cms/link-tool

A Node.js API for managing affiliate links.

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 31 Oct 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc