A lightweight utility for centralizing and resolving affiliate links.
This project provides a simple way to define, retrieve, and manage affiliate links from a single source of truth. It is designed for publishers, content sites, newsletters, and applications that need consistent affiliate link handling without scattering raw URLs across templates, pages, or code.
It can be used as both a practical utility and a reference pattern for link management.
Affiliate links often end up spread across content files, templates, scripts, and CMS fields.
That creates avoidable problems. Links become hard to update, harder to audit, and easy to break. A program change, URL update, or tracking parameter adjustment can require editing content in many places.
Without a centralized approach:
- link maintenance becomes repetitive.
- mistakes are harder to detect.
- reporting and auditing are harder to perform.
- content becomes tightly coupled to affiliate URLs.
This project introduces a small management layer that keeps affiliate link definitions in one place and makes them easy to resolve consistently.
This package sits between your content and the final affiliate URL:
Content or app -> link key -> affiliate link manager -> resolved URL
Instead of hardcoding affiliate links everywhere, your system refers to stable keys and lets the manager return the correct destination.
- Link registry creation.
- Link lookup by key.
- Safe updates to existing entries.
- Category and tag filtering.
- Optional active/inactive status handling.
- Redirect-friendly URL resolution helpers.
- Example usage demonstrating integration.
- Test coverage for core link management behavior.
npm install affiliate-link-managerimport {
createAffiliateRegistry,
getAffiliateLink,
setAffiliateLink,
resolveAffiliateUrl
} from "affiliate-link-manager";
const registry = createAffiliateRegistry([
{
key: "booking",
name: "Booking.com",
url: "https://example.com/booking-affiliate",
category: "travel",
tags: ["hotels", "accommodation"],
active: true
}
]);
setAffiliateLink(registry, "worldnomads", {
name: "World Nomads",
url: "https://example.com/worldnomads-affiliate",
category: "insurance",
tags: ["travel", "insurance"],
active: true
});
const booking = getAffiliateLink(registry, "booking");
const bookingUrl = resolveAffiliateUrl(registry, "booking");
console.log(booking.name);
console.log(bookingUrl);Each link entry follows a consistent structure:
{
"key": "booking",
"name": "Booking.com",
"url": "https://example.com/booking-affiliate",
"category": "travel",
"tags": ["hotels", "accommodation"],
"active": true,
"meta": {
"createdAt": "2026-03-25T00:00:00.000Z",
"updatedAt": "2026-03-25T00:00:00.000Z"
}
}The package is intentionally simple. It focuses on a few essential operations:
- create a registry.
- add or update links.
- get a link by key.
- resolve a final URL by key.
- list links by category or tag.
- disable a link without deleting it.
This keeps the interface small and easy to adopt.
Centralizing affiliate links improves consistency across content systems.
When links are stored and resolved from one place, it becomes easier to update programs, rotate links, audit partner usage, and reduce broken links across sites or newsletters.
It also helps separate editorial content from monetization infrastructure. That makes systems cleaner and easier to maintain over time.
This project is intentionally minimal.
It defines a small link management layer rather than a full affiliate platform. The goal is to provide a stable and understandable utility that can be used across websites, scripts, and publishing workflows.
The design emphasizes:
- Simplicity over abstraction.
- Centralization over duplication.
- Consistency over ad hoc editing.
- Maintainability over feature sprawl.
This project does not attempt to:
- provide analytics dashboards.
- replace an affiliate network platform.
- manage payouts or reporting.
- enforce redirect infrastructure.
It focuses only on defining and resolving affiliate links in a consistent way.
This project is designed as a foundation for broader affiliate workflow tooling. Future extensions may include:
- JSON import and export helpers.
- CSV sync utilities.
- redirect map generation.
- validation rules for duplicate URLs or missing fields.
- click logging hooks.
- static site integration helpers.
This utility is useful in contexts such as:
- content sites with recurring affiliate references.
- newsletters that reuse the same partner links.
- static sites that want central link control.
- scripts that generate pages or product roundups.
- publishing systems that separate content from monetization logic.
MIT