make-traffic-integration-core
TypeScript icon, indicating that this package has built-in type declarations

0.0.19 • Public • Published

TaskManagerApp

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.

Installation

npm install make-traffic-integration-core

Usage

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();

Methods

async init(): Promise<void>

Initializes the task manager. Should be run once before using other methods.

async getCampaigns(userID: string): Promise<CampaignList>

Fetches the list of campaigns available for the specified user.

async goProcess(userID: string, task: Campaign): Promise<void>

Processes the specified campaign task.

async claimProcess(userID: string, task: Campaign): Promise<void>

Claims the specified campaign task for the user.

subscribe(event: Events, callback: (task: Campaign) => void): void

Subscribes to a specific event related to campaign tasks.

unsubscribe(event: Events, callback: (task: Campaign) => void): void

Unsubscribes from a previously subscribed event.

Events

Events.CampaignClaimSucceed

Triggered when a campaign is successfully claimed.

Events.CampaignClaimFailed

Triggered when claiming a campaign fails.

Events.CampaignProcessed

Triggered when a campaign has been successfully processed.

Example

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]);
    }
});

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i make-traffic-integration-core

Weekly Downloads

35

Version

0.0.19

License

ISC

Unpacked Size

57.8 kB

Total Files

26

Last publish

Collaborators

  • koltsoviv