make-traffic-integration-core
is a task management library designed for traffic exchange systems.
It provides an interface to handle campaigns, process tasks, and manage event subscriptions. A single instance should be created globally.
Check Github repository for more examples.
npm install make-traffic-integration-core
import {TaskManagerApp} from "make-traffic-integration-core";
const config = {
apiUrl: 'https://api.example.com',
appKey: 'your-app-key'
};
const taskManager = new TaskManagerApp(config);
await taskManager.init();
Initializes the task manager. Should be run once before using other methods.
Fetches the list of campaigns available for the specified user.
Processes the specified campaign task.
Claims the specified campaign task for the user.
Subscribes to a specific event related to campaign tasks.
Unsubscribes from a previously subscribed event.
Triggered when a campaign is successfully claimed.
Triggered when claiming a campaign fails.
Triggered when a campaign has been successfully processed.
const onCampaignClaimed = (task: Campaign) => {
console.log('Campaign claimed:', task);
};
taskManager.subscribe(Events.CampaignClaimSucceed, onCampaignClaimed);
taskManager.getCampaigns('user123').then(campaigns => {
if (campaigns.length > 0) {
taskManager.claimProcess('user123', campaigns[0]);
}
});
MIT