{"id":15662557,"url":"https://github.com/lmammino/not-one-link","last_synced_at":"2025-05-06T00:57:44.015Z","repository":{"id":138310954,"uuid":"289931357","full_name":"lmammino/not-one-link","owner":"lmammino","description":"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)","archived":false,"fork":false,"pushed_at":"2020-09-27T15:04:18.000Z","size":205,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-06T00:57:36.788Z","etag":null,"topics":["amazon","node-js","nodejs","one-link","onelink","redirect"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmammino.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-24T13:09:50.000Z","updated_at":"2023-09-08T18:11:41.000Z","dependencies_parsed_at":"2023-05-23T00:00:23.840Z","dependency_job_id":null,"html_url":"https://github.com/lmammino/not-one-link","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fnot-one-link","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fnot-one-link/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fnot-one-link/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fnot-one-link/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmammino","download_url":"https://codeload.github.com/lmammino/not-one-link/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252601694,"owners_count":21774661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon","node-js","nodejs","one-link","onelink","redirect"],"created_at":"2024-10-03T13:33:16.142Z","updated_at":"2025-05-06T00:57:43.999Z","avatar_url":"https://github.com/lmammino.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# not-one-link\n\n[![npm version](https://badge.fury.io/js/not-one-link.svg)](https://badge.fury.io/js/not-one-link)\n[![CI](https://github.com/lmammino/not-one-link/workflows/CI/badge.svg)](https://github.com/lmammino/not-one-link/actions?query=workflow%3ACI)\n[![codecov](https://codecov.io/gh/lmammino/not-one-link/branch/master/graph/badge.svg)](https://codecov.io/gh/lmammino/not-one-link)\n\nA simple Node.js library that allows you to re-map Amazon links from one country to another (Like Amazon OneLink™️ but simpler to use)\n\n\n## Rationale\n\nIf 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...\n\nAs far as I am aware the only viable option to do this today is Amazon OneLink™️.\n\nIf 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.\n\nThis library is born with the intent to help you to implement your own self-hosted Amazon OneLink™️ alternative.\n\n\n## Installation and usage\n\nInstall it using npm:\n\n```bash\nnpm install --save not-one-link\n```\n\nExample usage:\n\n```javascript\nconst rewriteUrl = require('not-one-link')\n\nrewriteUrl('https://www.amazon.com/dp/1839214112/', 'UK') // -\u003e https://www.amazon.co.uk/dp/1839214112/\n```\n\n\n## API\n\nThe `rewriteUrl` accepts the following parameters:\n\n - `url` the original Amazon URL you want to rewrite (generally a product url from amazon.com)\n - `userCountryCode` the detected country code of the user you want to redirect to an Amazon page (in [ISO 3166 alpha-2](https://www.iban.com/country-codes) format)\n - `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](#use-with-affiliate-tags))\n\n **NOTE**: if an invalid URL is passed, the function will throw a `TypeError`, make sure you handle this potential error in your code.\n\n\n## Use with affiliate tags\n\nIf 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.\n\nLet's see an example:\n\n```javascript\nconst rewriteUrl = require('not-one-link')\n\nconst tagsMap = {\n  'www.amazon.co.uk': 'myUKTag',\n  'www.amazon.es': 'myESTag',\n  'www.amazon.it': 'myITTag'\n}\n\nconst url = 'https://www.amazon.com/dp/1839214112/'\nrewriteUrl(url, 'UK', tagsMap) // -\u003e https://www.amazon.co.uk/dp/1839214112/?tag=myUKTag\nrewriteUrl(url, 'ES', tagsMap) // -\u003e https://www.amazon.es/dp/1839214112/?tag=myESTag\nrewriteUrl(url, 'IT', tagsMap) // -\u003e https://www.amazon.it/dp/1839214112/?tag=myITTag\n```\n\n\n## Detecting the user country\n\nThis 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.\n\nAnyway, a common way to detect a visitor country might be by IP address using something like GeoLite MaxMind DB and [mmdb-reader](https://npm.im/mmdb-reader). If you have a GeoLite database file you could detect a country for a given IP as follows:\n\n```javascript\nconst MMDBReader = require('mmdb-reader')\n\nconst reader = new MMDBReader('path/to/your/GeoLite2-Country.mmdb')\nconst res = reader.lookup('\u003cthe user ip here\u003e')\nconsole.log(res.country.iso_code)\n```\n\n\n## Running this code on a Lambda on AWS?\n\nIf you are thinking about doing something like this, this is totally doable, in fact, you can check out [`not-one-link-lambda`](https://github.com/lmammino/not-one-link-lambda).\n\n\n## Creating a URL rewriting web server\n\nIf 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:\n\n```javascript\nconst { createServer } = require('http')\nconst { URL } = require('url')\nconst rewriteUrl = require('not-one-link')\nconst MMDBReader = require('mmdb-reader')\n\nconst reader = new MMDBReader('path/to/your/GeoLite2-Country.mmdb')\nconst server = createServer((req, res) =\u003e {\n  const requestUrl = new URL(req.url, `http://${req.headers.host || 'localhost'}`);\n  const amazonUrl = requestUrl.searchParams.get('url')\n  if (!amazonUrl) {\n    res.statusCode = 400\n    return res.end('Invalid request, `url` querystring parameter not provided')\n  }\n\n  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress\n  const lookupRes = reader.lookup(ip)\n  if (!lookupRes) {\n    // if cannot find a match for the user ip returns the original url\n    res.statusCode = 302\n    res.setHeader('Location', amazonUrl)\n    return res.end()\n  }\n\n  const userCountry = lookupRes.country.iso_code\n\n  try {\n    const redirectUrl = rewriteUrl(amazonUrl, userCountry)\n    res.statusCode = 302\n    res.setHeader('Location', redirectUrl)\n    return res.end()\n  } catch (err) {\n    res.statusCode = 400\n    return res.end('Invalid `url` queryString provided')\n  }\n})\n\nserver.listen(8080)\n```\n\nNow you can use the URL https://yourwebsite:8080?url=https%3A%2F%2Fwww.amazon.com%2Fdp%2F1839214112%3Ftag%3Dloige0e-20\n\n\n## Contributing\n\nEveryone is very welcome to contribute to this project. You can contribute just by submitting bugs or\nsuggesting improvements by [opening an issue on GitHub](https://github.com/lmammino/not-one-link/issues).\n\nYou can also submit PRs as long as you adhere with the code standards and write tests for the proposed changes.\n\n## License\n\nLicensed under [MIT License](LICENSE). © Luciano Mammino.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fnot-one-link","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmammino%2Fnot-one-link","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fnot-one-link/lists"}