@bprotsyk/aso-core 1.2.194 → 1.2.196

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.
@@ -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,30 @@ 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
+ console.log(data.rows);
213
+ return data.rows[0].profit;
214
+ }
215
+ async function getProfitForTodayAndYesterday() {
216
+ let timestamps = (0, general_1.getTimestampsForTodayAndYesterday)();
217
+ let today = await exports.KeitaroService.getProfitForTimeRange(timestamps.today.start, timestamps.today.end);
218
+ let yesterday = await exports.KeitaroService.getProfitForTimeRange(timestamps.yesterday.start, timestamps.yesterday.end);
219
+ return {
220
+ today: today,
221
+ yesterday: yesterday
222
+ };
223
+ }
200
224
  exports.KeitaroService = {
201
225
  getStreamsByCampaignId, updateCampaign, getAllCampaigns, getAllOffers, cloneStreams, addOfferToKeitaro, getOfferByKeitaroId, getDomains, createCampaign, getCampaignById, upsertStreamToCampaign, cloneOWCampaign,
202
- updateOffer, changeCampaignsGroup
226
+ updateOffer, changeCampaignsGroup, getProfitForTimeRange, getProfitForTodayAndYesterday
203
227
  };
@@ -0,0 +1,11 @@
1
+ export declare function convertMillisToDate(millis: number): string;
2
+ export declare function getTimestampsForTodayAndYesterday(): {
3
+ today: {
4
+ start: number;
5
+ end: number;
6
+ };
7
+ yesterday: {
8
+ start: number;
9
+ end: number;
10
+ };
11
+ };
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "1.2.194",
3
+ "version": "1.2.196",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -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,36 @@ 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
+ console.log(data.rows)
256
+
257
+ return data.rows[0].profit
258
+ }
259
+
260
+ async function getProfitForTodayAndYesterday(): Promise<any> {
261
+ let timestamps = getTimestampsForTodayAndYesterday()
262
+ let today = await KeitaroService.getProfitForTimeRange(timestamps.today.start, timestamps.today.end)
263
+ let yesterday = await KeitaroService.getProfitForTimeRange(timestamps.yesterday.start, timestamps.yesterday.end)
264
+
265
+ return {
266
+ today: today,
267
+ yesterday: yesterday
268
+ }
269
+ }
270
+
241
271
  export const KeitaroService = {
242
272
  getStreamsByCampaignId, updateCampaign, getAllCampaigns, getAllOffers, cloneStreams, addOfferToKeitaro, getOfferByKeitaroId, getDomains, createCampaign, getCampaignById, upsertStreamToCampaign, cloneOWCampaign,
243
- updateOffer, changeCampaignsGroup
273
+ updateOffer, changeCampaignsGroup, getProfitForTimeRange, getProfitForTodayAndYesterday
244
274
  }
@@ -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 { IFlashApp, PlugType, } from "../flash/flash-app"
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
 
@@ -562,5 +562,4 @@ let moveCampaignsToAnotherGroup = async () => {
562
562
  // gatherInfoForFlashApps()
563
563
 
564
564
  // replaceInOfferLink(`xmariorel.com`, `lalielynaualish.com`, /.*icecasino_huffson.*/g)
565
- // replaceInOfferLink(`lp=18`, `lp=00`, /.*icecasino_huffson.*/g)
566
-
565
+ // replaceInOfferLink(`lp=18`, `lp=00`, /.*icecasino_huffson.*/g)