Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "make-traffic-integration-core",
"version": "0.2.7",
"version": "0.3.4",
"description": "Core Library for Make Traffic task manager",
"scripts": {
"build": "webpack"
},
"exports": {
".": "./dist/bundle.esm.js"
},
"types": "dist/index.d.ts",
"types": "dist/src/index.d.ts",
"type": "module",
"files": [
"dist/"
Expand Down
13 changes: 6 additions & 7 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
export * from "./types/index";
import {Config, EventPayloadMap} from "./types";
import {HttpClient, TaskFilters} from "./services/HttpClient";
import { HttpClient, TaskFilters} from "./services/HttpClient";
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent import formatting: there's an extra space after the opening brace. The import should be import {HttpClient, TaskFilters} from "./services/HttpClient"; to match the style of other imports in this file.

Suggested change
import { HttpClient, TaskFilters} from "./services/HttpClient";
import {HttpClient, TaskFilters} from "./services/HttpClient";

Copilot uses AI. Check for mistakes.
import {EventRegister} from "./services/EventRegister";
import {TaskProcessor} from "./services/TaskProcessor";
import {Task, TasksList, Events} from "./types";
import {Config, EventPayloadMap, Task, TasksList, Events, ProcessMethodOptions, ClaimOptions} from "./types";
import {PluginsManager} from "./services/PluginsManager";

export class TaskManagerApp {
Expand All @@ -27,12 +26,12 @@ export class TaskManagerApp {
return this.httpClient.getTasks(userID, filters);
}

goProcess = async (userID: string, task: Task) => {
return this.taskProcessor.goProcess(userID, task);
goProcess = async (userID: string, task: Task, options?: ProcessMethodOptions) => {
return this.taskProcessor.goProcess(userID, task, options);
}

claimProcess = async (userID: string, task: Task) => {
return this.taskProcessor.claimProcess(userID, task);
claimProcess = async (userID: string, task: Task, options?: ClaimOptions) => {
return this.taskProcessor.claimProcess(userID, task, options);
}

subscribe = <K extends Events>(
Expand Down
18 changes: 15 additions & 3 deletions packages/core/src/services/HttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import {Task, TasksList, Plugin, PaginationResponseType} from "../types";
import {
Task,
TasksList,
Plugin,
PaginationResponseType,
ClaimOptions,
DefaultAuthProvider,
TrackOptions
} from "../types";
import { version as LIB_VERSION } from '../../package.json';

export class HttpError extends Error {
Expand All @@ -17,6 +25,7 @@ export interface TaskFilters {
categories?: string[]; // e.g., ['default','partners']
page?: number;
pageSize?: number;
authProvider?: string;
}

export class HttpClient {
Expand Down Expand Up @@ -71,6 +80,7 @@ export class HttpClient {
}
params.set("pageSize", String(filters?.pageSize ?? 100));
params.set("currentPage", String(filters?.page ?? 1));
params.set("auth_provider", filters?.authProvider || DefaultAuthProvider);

const url = `${this.apiUrl}/v1/tasks?${params.toString()}`;
const response = await this.request(url);
Expand All @@ -91,22 +101,24 @@ export class HttpClient {
return await response.json();
}

trackEvent = async (event: string, taskID: string, userID: string) => {
trackEvent = async (event: string, taskID: string, userID: string, options?: TrackOptions) => {
const url = this.buildUrl("/v1/track-task-action", {
action: event,
task_id: taskID,
user_id: userID,
auth_provider: options?.authProvider || DefaultAuthProvider,
});
const response = await this.request(url);
if (!response.ok) {
return Promise.reject(new HttpError(`Failed to track event: ${response.statusText}`, response.status));
}
}

claimProcess = async (appKey: string, userID: string, task: Task) => {
claimProcess = async (appKey: string, userID: string, task: Task, options?: ClaimOptions) => {
const url = this.buildUrl("/v1/action/claim", {
task_id: task.id,
user_id: userID,
auth_provider: options?.authProvider || DefaultAuthProvider,
});
const response = await this.request(url);
if (!response.ok && response.status === 409) {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/services/PluginsManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {PluginProcessMethod, Plugin} from "../types";
import {Plugin, PluginProcessMethod, PluginVerifyMethod} from "../types";
import {HttpClient} from "./HttpClient";


Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line added. This introduces unnecessary whitespace that's not consistent with the rest of the file structure.

Copilot uses AI. Check for mistakes.
export class PluginsManager {
private isScriptsUploaded = false;
private userPlugins: Plugin[] = [];
Expand Down Expand Up @@ -122,7 +123,7 @@ export class PluginsManager {
return !!plugin.scriptVerifyEndpoint;
}

getVerifyEndpointByID = (id: number): PluginProcessMethod => {
getVerifyEndpointByID = (id: number): PluginVerifyMethod => {
const plugin = this.userPlugins.find(one => one.id === id);
if (!plugin) {
throw new Error(`Plugin ${id} is not found`);
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/services/TaskProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Task, Events} from "../types";
import {Task, Events, ProcessMethodOptions, ClaimOptions} from "../types";
import {PluginsManager} from "./PluginsManager";
import {EventRegister} from "./EventRegister";
import {HttpClient} from "./HttpClient";
import { HttpClient} from "./HttpClient";
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent import formatting: there's an extra space after the opening brace. Compare with line 1 which doesn't have this spacing. The import should be import {HttpClient} from "./HttpClient"; to match the style of other imports.

Suggested change
import { HttpClient} from "./HttpClient";
import {HttpClient} from "./HttpClient";

Copilot uses AI. Check for mistakes.

export class TaskProcessor {
constructor(
Expand All @@ -12,17 +12,17 @@ export class TaskProcessor {
) {
}

goProcess = async (userID: string, task: Task) => {
goProcess = async (userID: string, task: Task, options?: ProcessMethodOptions) => {
const processMethod = this.pluginsManager.getProcessEndpointByID(task.plugin.id);
return processMethod(this.appKey, userID, task)
return processMethod(this.appKey, userID, task, options)
}

claimProcess = async (userID: string, task: Task) => {
claimProcess = async (userID: string, task: Task, options?: ClaimOptions) => {
const run = this.pluginsManager.hasVerifyEndpointByID(task.plugin.id)
? this.pluginsManager.getVerifyEndpointByID(task.plugin.id)
: this.httpClient.claimProcess.bind(this.httpClient);

return run(this.appKey, userID, task).then(
return run(this.appKey, userID, task, options).then(
() => this.eventRegister.emit(Events.TaskClaimSucceed, task),
).catch((err) => {
if (err.name === 'HttpError' && err.statusCode === 409) {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export * from "./plugin";
export * from "./plugins/custom";
export * from "./plugins/redirect-timeout";
export * from "./plugins/action-based";
export * from "./plugins/interfaces";
export * from "./plugins/interfaces";
export * from "./options"
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon at the end of the export statement. All other export statements in this file end with semicolons, so this should be consistent.

Suggested change
export * from "./options"
export * from "./options";

Copilot uses AI. Check for mistakes.
13 changes: 13 additions & 0 deletions packages/core/src/types/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const DefaultAuthProvider = 'telegram';

export type TrackOptions = {
authProvider?: string;
}

export type ProcessMethodOptions = {
authProvider?: string;
}

export interface ClaimOptions {
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent type definitions: TrackOptions and ProcessMethodOptions use type while ClaimOptions uses interface. Since all three types have the same structure (a single optional authProvider field), they should use the same declaration style for consistency. Consider using type for all three or interface for all three.

Suggested change
export interface ClaimOptions {
export type ClaimOptions = {

Copilot uses AI. Check for mistakes.
authProvider?: string;
}
4 changes: 3 additions & 1 deletion packages/core/src/types/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Task} from "./task";
import {ClaimOptions, ProcessMethodOptions} from './options';

export interface Plugin {
id: number
Expand All @@ -11,4 +12,5 @@ export interface Plugin {
scriptVerifyEndpoint?: string
}

export type PluginProcessMethod = (appKey: string, userID: string, task: Task) => Promise<object | void>;
export type PluginProcessMethod = (appKey: string, userID: string, task: Task, options?: ProcessMethodOptions) => Promise<object | void>;
export type PluginVerifyMethod = (appKey: string, userID: string, task: Task, options?: ClaimOptions) => Promise<object | void>;