All Projects → lmammino → not-one-link

lmammino / not-one-link

Licence: MIT License
A simple Node.js library that allows you to re-map Amazon links from one country to another (Like Amazon OneLink™️ but simpler to use)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to not-one-link

aws-sqs-sns-client
AWS SNS SQS client UI
Stars: ✭ 26 (+36.84%)
Mutual labels:  amazon, node-js
kindle
No Kindle Highlights API? Take control with this CLI!
Stars: ✭ 88 (+363.16%)
Mutual labels:  amazon
Copycat-abstractive-opinion-summarizer
ACL 2020 Unsupervised Opinion Summarization as Copycat-Review Generation
Stars: ✭ 76 (+300%)
Mutual labels:  amazon
amazon-workmail-lambda-templates
Serverless applications for Amazon WorkMail.
Stars: ✭ 17 (-10.53%)
Mutual labels:  amazon
aws-lab-guide
Amazon Web Services Practice Lab Guide. Absolute beginners can try this lab practice guide.
Stars: ✭ 25 (+31.58%)
Mutual labels:  amazon
dankdomain
🏰 Ɗaɳƙ Ɗoɱaiɳ :: the return of Hack & Slash
Stars: ✭ 25 (+31.58%)
Mutual labels:  node-js
winston-telegram
A Telegram transport for winston
Stars: ✭ 28 (+47.37%)
Mutual labels:  node-js
SEO-Dashboard
SEO dashboard from Search console Data using the Google Search API, Mysql database , NodeJS RESTAPI( ExpressJS) and reactJs Dashboard
Stars: ✭ 39 (+105.26%)
Mutual labels:  node-js
josk
🏃🤖 Scheduler and manager for jobs and tasks in node.js on multi-server and clusters setup
Stars: ✭ 27 (+42.11%)
Mutual labels:  node-js
typescript-ddd-course
🔷🔖 TypeScript DDD Course: Learn Domain-Driven Design in TS lesson by lesson
Stars: ✭ 28 (+47.37%)
Mutual labels:  node-js
nodecmsguide
Your guide to Node.js content management systems
Stars: ✭ 25 (+31.58%)
Mutual labels:  node-js
liferay-connector
Liferay JSON WS wrapper for Node and Titanium SDK
Stars: ✭ 16 (-15.79%)
Mutual labels:  node-js
scripts.TermuxArch
scripts.TermuxArch https://termuxarch.github.io/scripts.TermuxArch/
Stars: ✭ 13 (-31.58%)
Mutual labels:  amazon
benji
📁 This library is a Scala reactive DSL for object storage (e.g. S3/Amazon, S3/CEPH, Google Cloud Storage).
Stars: ✭ 18 (-5.26%)
Mutual labels:  amazon
node-boilerplate
Node Typescript Boilerplate for Microservices. Skeleton for Node.js Apps written in TypeScript (with Setup Instructions for ESLint, Prettier, and Husky)
Stars: ✭ 92 (+384.21%)
Mutual labels:  node-js
node-openjtalk
Node.js TTS module using OpenJTalk
Stars: ✭ 47 (+147.37%)
Mutual labels:  node-js
selling-partner-api-sdk
A modularized SDK library for Amazon Selling Partner API (fully typed in TypeScript)
Stars: ✭ 13 (-31.58%)
Mutual labels:  amazon
github-readme-quotes
Dynamic quote generator for your GitHub readmes | Give a poetic touch to readmes
Stars: ✭ 128 (+573.68%)
Mutual labels:  node-js
custom-permalinks
Set custom permalinks on a per-post basis in WordPress
Stars: ✭ 17 (-10.53%)
Mutual labels:  redirect
cytrus-re
A multipurpose Discord bot!
Stars: ✭ 16 (-15.79%)
Mutual labels:  node-js

not-one-link

npm version CI codecov

A simple Node.js library that allows you to re-map Amazon links from one country to another (Like Amazon OneLink™️ but simpler to use)

Rationale

If you want to direct your users to a product page on Amazon and you have an international audience, chances are that you would like to send users from UK to amazon.co.uk, users from Italy to amazon.it and so on...

As far as I am aware the only viable option to do this today is Amazon OneLink™️.

If you have tried to setup Amazon OneLink™️, you have probably been frustrated with the long process and chances are that, in the end, it didn't work for you. Or if it did work for you, you probably already realised that your links won't work with a URL-shortner or in any external website like Twitter or YouTube.

This library is born with the intent to help you to implement your own self-hosted Amazon OneLink™️ alternative.

Installation and usage

Install it using npm:

npm install --save not-one-link

Example usage:

const rewriteUrl = require('not-one-link')

rewriteUrl('https://www.amazon.com/dp/1839214112/', 'UK') // -> https://www.amazon.co.uk/dp/1839214112/

API

The rewriteUrl accepts the following parameters:

  • url the original Amazon URL you want to rewrite (generally a product url from amazon.com)
  • userCountryCode the detected country code of the user you want to redirect to an Amazon page (in ISO 3166 alpha-2 format)
  • tagsMap (optional) a map of amazon domains and Amazon affiliate tags. If used it will rewrite the URL by replacing/inserting the correct affiliate tag for the destination website. (See an example below)

NOTE: if an invalid URL is passed, the function will throw a TypeError, make sure you handle this potential error in your code.

Use with affiliate tags

If you are using Amazon affiliates, most likely you have created affilaited tags for different countries (unfortunately, as of today you can't have the same tag on different Amazon websites). If you provide the map of your tags per amazon domain, the library will automatically insert/replace the tags for you.

Let's see an example:

const rewriteUrl = require('not-one-link')

const tagsMap = {
  'www.amazon.co.uk': 'myUKTag',
  'www.amazon.es': 'myESTag',
  'www.amazon.it': 'myITTag'
}

const url = 'https://www.amazon.com/dp/1839214112/'
rewriteUrl(url, 'UK', tagsMap) // -> https://www.amazon.co.uk/dp/1839214112/?tag=myUKTag
rewriteUrl(url, 'ES', tagsMap) // -> https://www.amazon.es/dp/1839214112/?tag=myESTag
rewriteUrl(url, 'IT', tagsMap) // -> https://www.amazon.it/dp/1839214112/?tag=myITTag

Detecting the user country

This library does not make any assumption on how you want to detect the user country. For instance you might have registered users and the user themselves might have provided their preferred country. Providing this business logic is entirely left to you based on your use cases.

Anyway, a common way to detect a visitor country might be by IP address using something like GeoLite MaxMind DB and mmdb-reader. If you have a GeoLite database file you could detect a country for a given IP as follows:

const MMDBReader = require('mmdb-reader')

const reader = new MMDBReader('path/to/your/GeoLite2-Country.mmdb')
const res = reader.lookup('<the user ip here>')
console.log(res.country.iso_code)

Running this code on a Lambda on AWS?

If you are thinking about doing something like this, this is totally doable, in fact, you can check out not-one-link-lambda.

Creating a URL rewriting web server

If you want to create a webserver that you can use as a proxy to redirect people to their nearest amazon store you could write something like this:

const { createServer } = require('http')
const { URL } = require('url')
const rewriteUrl = require('not-one-link')
const MMDBReader = require('mmdb-reader')

const reader = new MMDBReader('path/to/your/GeoLite2-Country.mmdb')
const server = createServer((req, res) => {
  const requestUrl = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
  const amazonUrl = requestUrl.searchParams.get('url')
  if (!amazonUrl) {
    res.statusCode = 400
    return res.end('Invalid request, `url` querystring parameter not provided')
  }

  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress
  const lookupRes = reader.lookup(ip)
  if (!lookupRes) {
    // if cannot find a match for the user ip returns the original url
    res.statusCode = 302
    res.setHeader('Location', amazonUrl)
    return res.end()
  }

  const userCountry = lookupRes.country.iso_code

  try {
    const redirectUrl = rewriteUrl(amazonUrl, userCountry)
    res.statusCode = 302
    res.setHeader('Location', redirectUrl)
    return res.end()
  } catch (err) {
    res.statusCode = 400
    return res.end('Invalid `url` queryString provided')
  }
})

server.listen(8080)

Now you can use the URL https://yourwebsite:8080?url=https%3A%2F%2Fwww.amazon.com%2Fdp%2F1839214112%3Ftag%3Dloige0e-20

Contributing

Everyone is very welcome to contribute to this project. You can contribute just by submitting bugs or suggesting improvements by opening an issue on GitHub.

You can also submit PRs as long as you adhere with the code standards and write tests for the proposed changes.

License

Licensed under MIT License. © Luciano Mammino.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].