@bprotsyk/aso-core 1.2.194 → 1.2.195
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/network/keitaro/keitaro-service.d.ts +4 -0
- package/lib/network/keitaro/keitaro-service.js +24 -1
- package/lib/utils/general.d.ts +11 -0
- package/lib/utils/general.js +43 -0
- package/lib/utils/keitaro-utils.js +11 -0
- package/package.json +1 -1
- package/src/network/keitaro/keitaro-service.ts +30 -2
- package/src/utils/general.ts +44 -0
- package/src/utils/keitaro-utils.ts +15 -6
|
@@ -17,6 +17,8 @@ export declare function upsertStreamToCampaign(campaign: IKeitaroCampaign, strea
|
|
|
17
17
|
declare function cloneOWCampaign(app: IFlashApp): Promise<IKeitaroCampaign>;
|
|
18
18
|
declare function changeCampaignsGroup(fromId: number, toId: number, exceptForCampaignIds: number[]): Promise<void>;
|
|
19
19
|
declare function getDomains(onlyActive?: boolean): Promise<IKeitaroDomain[]>;
|
|
20
|
+
declare function getProfitForTimeRange(from: number, to: number): Promise<number>;
|
|
21
|
+
declare function getProfitForTodayAndYesterday(): Promise<any>;
|
|
20
22
|
export declare const KeitaroService: {
|
|
21
23
|
getStreamsByCampaignId: typeof getStreamsByCampaignId;
|
|
22
24
|
updateCampaign: typeof updateCampaign;
|
|
@@ -32,5 +34,7 @@ export declare const KeitaroService: {
|
|
|
32
34
|
cloneOWCampaign: typeof cloneOWCampaign;
|
|
33
35
|
updateOffer: typeof updateOffer;
|
|
34
36
|
changeCampaignsGroup: typeof changeCampaignsGroup;
|
|
37
|
+
getProfitForTimeRange: typeof getProfitForTimeRange;
|
|
38
|
+
getProfitForTodayAndYesterday: typeof getProfitForTodayAndYesterday;
|
|
35
39
|
};
|
|
36
40
|
export {};
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.KeitaroService = exports.upsertStreamToCampaign = void 0;
|
|
7
7
|
const http_1 = __importDefault(require("./http"));
|
|
8
8
|
const keitaro_utils_1 = require("../../utils/keitaro-utils");
|
|
9
|
+
const general_1 = require("../../utils/general");
|
|
9
10
|
async function getStreamsByCampaignId(campaignId) {
|
|
10
11
|
const { data: streams } = await http_1.default.get(`campaigns/${campaignId}/streams`);
|
|
11
12
|
return streams;
|
|
@@ -197,7 +198,29 @@ async function getDomains(onlyActive) {
|
|
|
197
198
|
const { data: domains } = await http_1.default.get(`/domains`);
|
|
198
199
|
return onlyActive ? domains.filter((d) => d.network_status == "active") : domains;
|
|
199
200
|
}
|
|
201
|
+
async function getProfitForTimeRange(from, to) {
|
|
202
|
+
let fromString = (0, general_1.convertMillisToDate)(from);
|
|
203
|
+
let toString = (0, general_1.convertMillisToDate)(to);
|
|
204
|
+
let { data: data } = await http_1.default.post(`/report/build`, {
|
|
205
|
+
range: {
|
|
206
|
+
from: fromString,
|
|
207
|
+
to: toString,
|
|
208
|
+
timezone: 'Europe/Madrid'
|
|
209
|
+
},
|
|
210
|
+
metrics: ['profit']
|
|
211
|
+
});
|
|
212
|
+
return data.rows[0].profit;
|
|
213
|
+
}
|
|
214
|
+
async function getProfitForTodayAndYesterday() {
|
|
215
|
+
let timestamps = (0, general_1.getTimestampsForTodayAndYesterday)();
|
|
216
|
+
let today = await exports.KeitaroService.getProfitForTimeRange(timestamps.today.start, timestamps.today.end);
|
|
217
|
+
let yeterday = await exports.KeitaroService.getProfitForTimeRange(timestamps.yesterday.start, timestamps.yesterday.end);
|
|
218
|
+
return {
|
|
219
|
+
today: today,
|
|
220
|
+
yesterday: yeterday
|
|
221
|
+
};
|
|
222
|
+
}
|
|
200
223
|
exports.KeitaroService = {
|
|
201
224
|
getStreamsByCampaignId, updateCampaign, getAllCampaigns, getAllOffers, cloneStreams, addOfferToKeitaro, getOfferByKeitaroId, getDomains, createCampaign, getCampaignById, upsertStreamToCampaign, cloneOWCampaign,
|
|
202
|
-
updateOffer, changeCampaignsGroup
|
|
225
|
+
updateOffer, changeCampaignsGroup, getProfitForTimeRange, getProfitForTodayAndYesterday
|
|
203
226
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTimestampsForTodayAndYesterday = exports.convertMillisToDate = void 0;
|
|
4
|
+
function convertMillisToDate(millis) {
|
|
5
|
+
const date = new Date(millis);
|
|
6
|
+
const year = date.getFullYear();
|
|
7
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
8
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
9
|
+
return `${year}-${month}-${day}`;
|
|
10
|
+
}
|
|
11
|
+
exports.convertMillisToDate = convertMillisToDate;
|
|
12
|
+
function getTimestampsForTodayAndYesterday() {
|
|
13
|
+
const now = new Date();
|
|
14
|
+
// Today's Start (00:00:00)
|
|
15
|
+
const todayStart = new Date(now);
|
|
16
|
+
todayStart.setHours(0, 0, 0, 0);
|
|
17
|
+
const todayStartTimestamp = todayStart.getTime();
|
|
18
|
+
// Today's End (23:59:59.999)
|
|
19
|
+
const todayEnd = new Date(now);
|
|
20
|
+
todayEnd.setHours(23, 59, 59, 999);
|
|
21
|
+
const todayEndTimestamp = todayEnd.getTime();
|
|
22
|
+
// Yesterday's Start (00:00:00)
|
|
23
|
+
const yesterdayStart = new Date(now);
|
|
24
|
+
yesterdayStart.setDate(now.getDate() - 1);
|
|
25
|
+
yesterdayStart.setHours(0, 0, 0, 0);
|
|
26
|
+
const yesterdayStartTimestamp = yesterdayStart.getTime();
|
|
27
|
+
// Yesterday's End (23:59:59.999)
|
|
28
|
+
const yesterdayEnd = new Date(now);
|
|
29
|
+
yesterdayEnd.setDate(now.getDate() - 1);
|
|
30
|
+
yesterdayEnd.setHours(23, 59, 59, 999);
|
|
31
|
+
const yesterdayEndTimestamp = yesterdayEnd.getTime();
|
|
32
|
+
return {
|
|
33
|
+
today: {
|
|
34
|
+
start: todayStartTimestamp,
|
|
35
|
+
end: todayEndTimestamp,
|
|
36
|
+
},
|
|
37
|
+
yesterday: {
|
|
38
|
+
start: yesterdayStartTimestamp,
|
|
39
|
+
end: yesterdayEndTimestamp,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.getTimestampsForTodayAndYesterday = getTimestampsForTodayAndYesterday;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createOWCampaign = exports.createFlashCampaigns = exports.createOWStreamPartialPayload = exports.prepareOWCampaignParameters = exports.createOrFindFlashRedirectCampaign = exports.removeGeosFromAllRedirectCampaigns = exports.addGeosToAllRedirectCampaigns = exports.TRAFFIC_SOURCE_ID_FLASH_AI = void 0;
|
|
7
7
|
const keitaro_service_1 = require("../network/keitaro/keitaro-service");
|
|
8
8
|
const sleep_promise_1 = __importDefault(require("sleep-promise"));
|
|
9
|
+
const general_1 = require("../utils/general");
|
|
9
10
|
const FLASH_REDIRECT_GROUP_ID = 82;
|
|
10
11
|
exports.TRAFFIC_SOURCE_ID_FLASH_AI = 22;
|
|
11
12
|
const UNIQUENESS_METHOD = "ip_ua";
|
|
@@ -490,3 +491,13 @@ let moveCampaignsToAnotherGroup = async () => {
|
|
|
490
491
|
// gatherInfoForFlashApps()
|
|
491
492
|
// replaceInOfferLink(`xmariorel.com`, `lalielynaualish.com`, /.*icecasino_huffson.*/g)
|
|
492
493
|
// replaceInOfferLink(`lp=18`, `lp=00`, /.*icecasino_huffson.*/g)
|
|
494
|
+
(async () => {
|
|
495
|
+
try {
|
|
496
|
+
let timestamps = (0, general_1.getTimestampsForTodayAndYesterday)();
|
|
497
|
+
let response = await keitaro_service_1.KeitaroService.getProfitForTimeRange(timestamps.today.start, timestamps.today.end);
|
|
498
|
+
console.log(response);
|
|
499
|
+
}
|
|
500
|
+
catch (e) {
|
|
501
|
+
console.log(e);
|
|
502
|
+
}
|
|
503
|
+
})();
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import { IKeitaroCampaign } from "../../keitaro/keitaro-campaign";
|
|
|
5
5
|
import { IKeitaroDomain } from "../../keitaro/keitaro-domain";
|
|
6
6
|
import { IFlashApp } from "../../flash/flash-app";
|
|
7
7
|
import { TRAFFIC_SOURCE_ID_FLASH_AI, prepareOWCampaignParameters } from "../../utils/keitaro-utils";
|
|
8
|
+
import { convertMillisToDate, getTimestampsForTodayAndYesterday } from "../../utils/general";
|
|
8
9
|
|
|
9
10
|
async function getStreamsByCampaignId(campaignId: number): Promise<IKeitaroStream[]> {
|
|
10
11
|
const { data: streams } = await keitaroApi.get<IKeitaroStream[]>(`campaigns/${campaignId}/streams`);
|
|
@@ -130,7 +131,7 @@ function createStreamPartialPayload(keitaroOfferId: number, offerName: string, o
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
async function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string,campaignGroupId?: number, groupId?: number) {
|
|
134
|
+
async function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string, campaignGroupId?: number, groupId?: number) {
|
|
134
135
|
// TODO look if offer already exists by offer.name
|
|
135
136
|
let allOffers = await getAllOffers()
|
|
136
137
|
let identicalOffer = allOffers.find((o) => { return o.name.includes(offer.name) })
|
|
@@ -238,7 +239,34 @@ async function getDomains(onlyActive?: boolean): Promise<IKeitaroDomain[]> {
|
|
|
238
239
|
return onlyActive ? domains.filter((d) => d.network_status == "active") : domains
|
|
239
240
|
}
|
|
240
241
|
|
|
242
|
+
async function getProfitForTimeRange(from: number, to: number): Promise<number> {
|
|
243
|
+
let fromString = convertMillisToDate(from)
|
|
244
|
+
let toString = convertMillisToDate(to)
|
|
245
|
+
|
|
246
|
+
let { data: data } = await keitaroApi.post(`/report/build`, {
|
|
247
|
+
range: {
|
|
248
|
+
from: fromString,
|
|
249
|
+
to: toString,
|
|
250
|
+
timezone: 'Europe/Madrid'
|
|
251
|
+
},
|
|
252
|
+
metrics: ['profit']
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
return data.rows[0].profit
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function getProfitForTodayAndYesterday(): Promise<any> {
|
|
259
|
+
let timestamps = getTimestampsForTodayAndYesterday()
|
|
260
|
+
let today = await KeitaroService.getProfitForTimeRange(timestamps.today.start, timestamps.today.end)
|
|
261
|
+
let yeterday = await KeitaroService.getProfitForTimeRange(timestamps.yesterday.start, timestamps.yesterday.end)
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
today: today,
|
|
265
|
+
yesterday: yeterday
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
241
269
|
export const KeitaroService = {
|
|
242
270
|
getStreamsByCampaignId, updateCampaign, getAllCampaigns, getAllOffers, cloneStreams, addOfferToKeitaro, getOfferByKeitaroId, getDomains, createCampaign, getCampaignById, upsertStreamToCampaign, cloneOWCampaign,
|
|
243
|
-
updateOffer, changeCampaignsGroup
|
|
271
|
+
updateOffer, changeCampaignsGroup, getProfitForTimeRange, getProfitForTodayAndYesterday
|
|
244
272
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function convertMillisToDate(millis: number): string {
|
|
2
|
+
const date = new Date(millis);
|
|
3
|
+
const year = date.getFullYear();
|
|
4
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
5
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
6
|
+
return `${year}-${month}-${day}`;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getTimestampsForTodayAndYesterday() {
|
|
10
|
+
const now = new Date();
|
|
11
|
+
|
|
12
|
+
// Today's Start (00:00:00)
|
|
13
|
+
const todayStart = new Date(now);
|
|
14
|
+
todayStart.setHours(0, 0, 0, 0);
|
|
15
|
+
const todayStartTimestamp = todayStart.getTime();
|
|
16
|
+
|
|
17
|
+
// Today's End (23:59:59.999)
|
|
18
|
+
const todayEnd = new Date(now);
|
|
19
|
+
todayEnd.setHours(23, 59, 59, 999);
|
|
20
|
+
const todayEndTimestamp = todayEnd.getTime();
|
|
21
|
+
|
|
22
|
+
// Yesterday's Start (00:00:00)
|
|
23
|
+
const yesterdayStart = new Date(now);
|
|
24
|
+
yesterdayStart.setDate(now.getDate() - 1);
|
|
25
|
+
yesterdayStart.setHours(0, 0, 0, 0);
|
|
26
|
+
const yesterdayStartTimestamp = yesterdayStart.getTime();
|
|
27
|
+
|
|
28
|
+
// Yesterday's End (23:59:59.999)
|
|
29
|
+
const yesterdayEnd = new Date(now);
|
|
30
|
+
yesterdayEnd.setDate(now.getDate() - 1);
|
|
31
|
+
yesterdayEnd.setHours(23, 59, 59, 999);
|
|
32
|
+
const yesterdayEndTimestamp = yesterdayEnd.getTime();
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
today: {
|
|
36
|
+
start: todayStartTimestamp,
|
|
37
|
+
end: todayEndTimestamp,
|
|
38
|
+
},
|
|
39
|
+
yesterday: {
|
|
40
|
+
start: yesterdayStartTimestamp,
|
|
41
|
+
end: yesterdayEndTimestamp,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IKeitaroStream } from "../keitaro/keitaro-stream"
|
|
2
|
-
import {
|
|
2
|
+
import { IFlashApp, PlugType, } from "../flash/flash-app"
|
|
3
3
|
import { FlashAppType } from "../flash/flash-app-type"
|
|
4
4
|
import { IKeitaroCampaign, IKeitaroCampaignParameters } from "../keitaro/keitaro-campaign"
|
|
5
5
|
import { IKeitaroDomain } from "../keitaro/keitaro-domain"
|
|
6
6
|
import { KeitaroService } from "../network/keitaro/keitaro-service"
|
|
7
7
|
import sleep from 'sleep-promise';
|
|
8
8
|
import * as util from 'util';
|
|
9
|
-
import { PasteMap, TrackingMap } from "utils/app-gathering-utils"
|
|
10
9
|
import axios from "axios"
|
|
10
|
+
import { getTimestampsForTodayAndYesterday } from "../utils/general"
|
|
11
11
|
|
|
12
12
|
const FLASH_REDIRECT_GROUP_ID = 82
|
|
13
13
|
export const TRAFFIC_SOURCE_ID_FLASH_AI = 22
|
|
@@ -394,7 +394,7 @@ let changeSourceForFA = async () => {
|
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
let replaceInOfferLink = async (old: string, replace: string, offerNameRegEx: RegExp)=> {
|
|
397
|
+
let replaceInOfferLink = async (old: string, replace: string, offerNameRegEx: RegExp) => {
|
|
398
398
|
let offers = await KeitaroService.getAllOffers()
|
|
399
399
|
|
|
400
400
|
offers = offers.filter((o) => offerNameRegEx.exec(o.name))
|
|
@@ -530,14 +530,14 @@ let findBrokenOfferStreams = async () => {
|
|
|
530
530
|
console.log(`${stream.name}: id payload is missing, payload: ${stream.filters}`)
|
|
531
531
|
}
|
|
532
532
|
}
|
|
533
|
-
}
|
|
533
|
+
}
|
|
534
534
|
}
|
|
535
535
|
|
|
536
536
|
let moveCampaignsToAnotherGroup = async () => {
|
|
537
537
|
let from = 2, to = 80, exceptFor = [2684, 2686, 2673, 2670, 2687, 2689, 2529, 2688, 2551, 2517, 2691, 2588, 2643, 2563, 2598, 2624, 2584, 2553, 2683, 2618, 2499, 2594, 2545, 2682, 2569, 2527, 2681, 2677, 2610, 2608]
|
|
538
|
-
|
|
538
|
+
|
|
539
539
|
await KeitaroService.changeCampaignsGroup(from, to, exceptFor)
|
|
540
|
-
}
|
|
540
|
+
}
|
|
541
541
|
|
|
542
542
|
// moveCampaignsToAnotherGroup()
|
|
543
543
|
|
|
@@ -564,3 +564,12 @@ let moveCampaignsToAnotherGroup = async () => {
|
|
|
564
564
|
// replaceInOfferLink(`xmariorel.com`, `lalielynaualish.com`, /.*icecasino_huffson.*/g)
|
|
565
565
|
// replaceInOfferLink(`lp=18`, `lp=00`, /.*icecasino_huffson.*/g)
|
|
566
566
|
|
|
567
|
+
(async () => {
|
|
568
|
+
try {
|
|
569
|
+
let timestamps = getTimestampsForTodayAndYesterday()
|
|
570
|
+
let response = await KeitaroService.getProfitForTimeRange(timestamps.today.start, timestamps.today.end)
|
|
571
|
+
console.log(response)
|
|
572
|
+
} catch (e) {
|
|
573
|
+
console.log(e)
|
|
574
|
+
}
|
|
575
|
+
})()
|