
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
wildlink-js-client
Advanced tools
A simple JavaScript client library for the Wildlink API (DEPRECATED)
JavaScript Client Library for working with Wildfire/Wildlink APIs client side. Convert product and brand links into affiliate versions to generate revenue. Learn more at https://www.wildlink.me/.
THIS PROJECT IS DEPRECATED AND NO LONGER PUBLICLY SUPPORTED
With Yarn:
yarn add wildlink-js-client
// 1. Load
const { WildlinkClient } = require('wildlink-js-client');
// 2. Create instance of WildlinkClient
const WLClient = new WildlinkClient(SECRET, APP_ID);
// 3. Initialize (create new device)
WLClient.init().then(() => {
// device should be persisted after creation for client reinitialization so all reporting data maps back to the same device
const newDevice = WLClient.getDevice();
const { DeviceID, DeviceToken, DeviceKey } = newDevice;
// deviceId is used for referencing the device in reporting data
const deviceId = WLClient.getDeviceId();
// 4. Make API requests (see below)
});
// 5. Reinitialize (recreate device)
// device should be pulled from persistent storage
const device = {
DeviceID: DEVICE_ID,
DeviceToken: DEVICE_TOKEN,
DeviceKey: DEVICE_KEY,
}
WLClient.init(device).then(() => {
// consume client
}
To obtain a SECRET
and APP_ID
, please contact support@wildlink.me for more information.
The getDomains
function fetches all domains that we support and are wildlink-able. These are in the context of the authenticated device that made the call. We can let the browser handle the caching for this call since the domains are served off a CDN.
Here is an example implementation that matches a url to a Supported Merchant Domain
WLClient.getDomains().then((domains) => {
console.log(domains);
});
[
{
ID: 1991737,
Domain: "target.com",
Merchant: {
ID: 5482877,
Name: "Target",
DefaultRate: {
Kind: "PERCENTAGE",
Amount: "0.5",
},
DerivedRate: {
Kind: "PERCENTAGE",
Amount: "0.75",
},
MaxRate: {
Kind: "PERCENTAGE",
Amount: "0.5",
}
}
},
{
ID: 5834,
Domain: "verizon.com",
Merchant: {
ID: 7000,
Name: "Verizon Business Markets",
DefaultRate: {
Kind: "FLAT",
Amount: "15",
Currency: "USD",
},
DerivedRate: null,
MaxRate: {
Kind: "FLAT",
Amount: "15",
Currency: "USD",
},
}
},
...
]
WLClient.getMerchants().then((merchants) => {
// consume array of merchants
});
enum MerchantImageKind {
Logo = 'LOGO',
Featured = 'FEATURED',
}
interface MerchantImage {
ID: number;
Kind: MerchantImageKind;
Ordinal: number;
ImageID: number;
URL: string;
Width: number;
Height: number;
}
interface Merchant {
ID: number;
Name: string;
Images: MerchantImage[];
}
WLClient.getMerchantRateDetails().then((merchantRateDetails) => {
// consume map of merchantRateDetails
});
type RateKindMap = {
[PERCENTAGE]: undefined;
[FLAT]: string;
};
interface RateDetail<K extends keyof RateKindMap> {
ID: number;
Name: string;
Kind: K;
Currency: RateKindMap[K];
Amount: string;
}
interface MerchantRateDetail {
[MerchantID: string]: (
| RateDetail<typeof PERCENTAGE>
| RateDetail<typeof FLAT>)[];
}
The generateVanity
function converts a URL from a product page or listing on a supported domain into a wild.link
URL with embedded tracking for the given device.
const url =
'https://johnnycupcakes.com/collections/all/products/rainbow-sprinkles-pullover?variant=32313522421846';
// See example below of how to get the URL's domain object
const domain = {
ID: 5520356,
Domain: 'johnnycupcakes.com',
Merchant: {
ID: 6941,
Name: 'Johnny Cupcakes',
DefaultRate: {
Kind: 'PERCENTAGE',
Amount: '6.5',
},
DerivedRate: null,
MaxRate: {
Kind: 'PERCENTAGE',
Amount: '6.5',
},
},
};
// Pass in the URL and the domain object
WLClient.generateVanity(url, domain).then((vanity) => {
console.log(vanity);
});
{
OriginalURL: 'https://johnnycupcakes.com/collections/all/products/rainbow-sprinkles-pullover?variant=32313522421846',
VanityURL: 'https://wild.link/johnnycupcakes/AP7siwE'
}
For another example, take a look at our application that matches a url to a domain
// https://www.npmjs.com/package/parse-domain
const { parseDomain, fromUrl } = require('parse-domain');
const { WildlinkClient } = require('wildlink-js-client');
const WLClient = new WildlinkClient(SECRET, APP_ID);
const productUrl =
'https://johnnycupcakes.com/collections/all/products/rainbow-sprinkles-pullover?variant=32313522421846';
// helper function for parsing the url
const parseUrl = (url) => {
const { domain, topLevelDomains: tld } = parseDomain(fromUrl(url));
return `${domain}.${tld}`; // johnnycupcakes.com
};
WLClient.init().then(() => {
WLClient.getDomains()
.then((domains) => {
// Find the Active Domain object whose Domain property matches the parsed url
for (let i = 0; i < domains.length; i++) {
if (parseUrl(productUrl) === domains[i].Domain) {
return domains[i];
}
}
return null;
})
.then((activeDomain) => {
if (!activeDomain) {
throw 'Not an eligible domain';
} else {
WLClient.generateVanity(productUrl, activeDomain).then((vanity) => {
console.log(vanity);
});
}
})
.catch((e) => console.error(e));
});
Error/Rejection reasons are in the following format and include application or network level errors:
Name | Type | Description |
---|---|---|
status | number | undefined | HTTP status |
body | string | The raw response string |
result | * | The JSON-parsed result. false if not parse-able. |
const APP_ID = 0;
const WLClient = new WildlinkClient(SECRET, APP_ID);
WLClient.init().then(() => {
WLClient.generateVanity('https://www.target.com', domain)
.then((vanity) => {
// no vanity generated
})
.catch((reason) => {
// "Missing application ID"
console.log(reason.body);
});
});
// WLClient initialized correctly
try {
const vanity = await WLClient.generateVanity('https://www.target.com');
} catch (error) {
// "No ActiveDomain provided"
console.log(error.body);
}
Check out examples for implementation details.
Browser Extension Clipboard Monitor
Matching a URL to an Active Domain
FAQs
A simple JavaScript client library for the Wildlink API (DEPRECATED)
The npm package wildlink-js-client receives a total of 1,029 weekly downloads. As such, wildlink-js-client popularity was classified as popular.
We found that wildlink-js-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 15 open source maintainers collaborating on the project.
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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.