@bprotsyk/aso-core 2.1.192 → 2.1.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.
@@ -1,853 +0,0 @@
1
- import { IKeitaroStream } from "../keitaro/keitaro-stream"
2
- import { EPlatform, IApp, PlugType, } from "../app/app"
3
- import { AppType } from "../app/app-type"
4
- import { IKeitaroCampaign, IKeitaroCampaignParameters } from "../keitaro/keitaro-campaign"
5
- import { IKeitaroDomain } from "../keitaro/keitaro-domain"
6
- import { KeitaroService } from "../network/keitaro/keitaro-service"
7
- import * as util from 'util';
8
- import axios from "axios"
9
- import { getTimestampsForTodayAndYesterday } from "../utils/general"
10
- import { KeitaroUtils } from "index"
11
- import { rename } from "fs"
12
- import { IKeitaroClicksRequest, KeitaroClicksInterval } from "../keitaro/keitaro-clicks"
13
- import { IKeitaroClicksRangeRequest } from "../keitaro/keitaro-clicks"
14
-
15
- const FLASH_REDIRECT_GROUP_ID = 82
16
- export const TRAFFIC_SOURCE_ID_FLASH_AI = 22
17
- export const TRAFFIC_SOURCE_ID_DIRECT_AI = 23
18
- const UNIQUENESS_METHOD = "ip_ua"
19
- const MAX_COOKIES_TTL = 8760
20
- const TYPE_POSITION = "position"
21
- const STATE_ACTIVE = "active"
22
- const COST_TYPE_CPC = "CPC"
23
- const COST_VALUE = 0
24
- const COST_CURRENCY_USD = "USD"
25
-
26
- // clear campaigns from unused / wrong streams
27
-
28
- // let sampleApp: IFlashApp = {
29
- // id: 96,
30
- // bundle: "com.dynastyof.desert",
31
- // name: "Room of Fortuna",
32
- // plugId: "https://pastebin.com/raw/AR2u7dSD",
33
- // plugType: PlugType.PASTEBIN,
34
- // plugContent: "",
35
- // plugStatus: FlashAppPlugStatus.DISABLED,
36
- // plugAccountId: 1,
37
- // reservePlugId: "none",
38
- // reservePlugType: PlugType.OTHER,
39
- // reservePlugContent: "",
40
- // reservePlugStatus: FlashAppPlugStatus.DISABLED,
41
- // reservePlugAccountId: 1,
42
- // type: FlashAppType.GAMBLING,
43
- // developerEmail: "bolly.dreams@yahoo.com",
44
- // developerName: "Serhii Bolsky",
45
- // developerOrganization: "S.I.B FOP",
46
- // onesignalAppId: "e66658af-91c3-44bc-8123-ec64b1969cbd",
47
- // onesignalRestApiKey: "MDk2NjZlNTMtMzBhYi00MjEzLTg0ZGItOWVmZWZhMTczMzI0",
48
-
49
- // generationOptions: {
50
- // splashActivityClassName: "SplashActivity",
51
- // mainActivityClassName: "YourActivity",
52
- // linkName: "likn",
53
- // savedName: "isOk",
54
- // paranoidSeed: 228143750
55
- // },
56
- // geos: "RU,UA,KZ,ES,BR,PT,CL,MX",
57
- // keitaroData: {
58
- // redirectCampaignId: 0,
59
- // redirectCampaignName: "",
60
- // redirectDomainId: 0,
61
- // redirectDomainName: "",
62
- // trackingCampaignId: 0,
63
- // trackingCampaignName: "",
64
- // trackingDomainId: 0,
65
- // trackingDomainName: "",
66
- // clickIdParameterName: "p",
67
- // offerIdParameterName: "i",
68
- // }
69
- // } as IFlashApp
70
-
71
- function sleep(ms: number): Promise<void> {
72
- return new Promise(resolve => setTimeout(resolve, ms));
73
- }``
74
-
75
- export let addGeosToAllRedirectCampaigns = async (geosToAdd: string) => {
76
- let allCampaigns = await KeitaroService.getAllCampaigns()
77
-
78
-
79
- let regexp = new RegExp(`^F #`)
80
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
81
- for (let campaign of matchingCampaigns) {
82
- console.log(campaign.name)
83
- console.log("––––––––––––––––––––––––")
84
- let streams = await KeitaroService.getStreamsByCampaignId(campaign.id)
85
- let botStream = streams[0]
86
- botStream.name = "Bot Protection"
87
- let owStream = streams.find(s => s.name == "OW")
88
-
89
- for (let stream of [owStream, botStream]) {
90
- if (!stream) continue
91
- console.log({
92
- name: stream.name,
93
- })
94
- let geos = stream?.filters[stream.type == "forced" ? 1 : 0]?.payload
95
- if (!geos) continue
96
- geosToAdd.split(" ").forEach((geo: string) => {
97
- let streamForGeo = streams.find((s) => s.name == geo)
98
- if (streamForGeo && stream) return
99
- if (!geos.includes(geo)) geos.push(geo)
100
- });
101
-
102
- stream.filters[stream.type == "forced" ? 1 : 0].payload = geos
103
-
104
- await KeitaroService.upsertStreamToCampaign(campaign, stream)
105
- await sleep(2000)
106
- }
107
- console.log("––––––––––––––––––––––––")
108
- }
109
- }
110
-
111
- // export let changeTrackingOfferGeo = async (appId: number, keitaroId: string, geo: string) => {
112
- // let allCampaigns = await KeitaroService.getAllCampaigns()
113
-
114
-
115
- // let regexp = new RegExp(`^FA #${appId} `)
116
- // let matchingCampaign = allCampaigns.find(campaign => regexp.exec(campaign.name))
117
- // if (!matchingCampaign) throw new Error(`No matching campaign got appId ${appId}`)
118
- // let streams = await KeitaroService.getStreamsByCampaignId(matchingCampaign.id)
119
- // letstream =
120
- // for (let campaign of matchingCampaigns) {
121
- // console.log(campaign.name)
122
- // console.log("––––––––––––––––––––––––")
123
- // let streams = await KeitaroService.getStreamsByCampaignId(campaign.id)
124
- // let botStream = streams[0]
125
- // botStream.name = "Bot Protection"
126
- // let owStream = streams.find(s => s.name == "OW")
127
-
128
- // for (let stream of [owStream, botStream]) {
129
- // if (!stream) continue
130
- // console.log({
131
- // name: stream.name,
132
- // })
133
- // let geos = stream?.filters[stream.type == "forced" ? 1 : 0]?.payload
134
- // if (!geos) continue
135
- // geosToAdd.split(" ").forEach((geo: string) => {
136
- // let streamForGeo = streams.find((s) => s.name == geo)
137
- // if (streamForGeo && stream) return
138
- // if (!geos.includes(geo)) geos.push(geo)
139
- // });
140
-
141
- // stream.filters[stream.type == "forced" ? 1 : 0].payload = geos
142
-
143
- // await KeitaroService.upsertStreamToCampaign(campaign, stream)
144
- // await sleep(2000)
145
- // }
146
- // console.log("––––––––––––––––––––––––")
147
- // }
148
- // }
149
-
150
- export let removeGeosFromAllRedirectCampaigns = async (geoToRemove: string) => {
151
- let allCampaigns = await KeitaroService.getAllCampaigns()
152
-
153
-
154
- let regexp = new RegExp(`^F #`)
155
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
156
- for (let campaign of matchingCampaigns) {
157
- console.log(campaign.name)
158
- console.log("––––––––––––––––––––––––")
159
- let streams = await KeitaroService.getStreamsByCampaignId(campaign.id)
160
- let botStream = streams[0]
161
- botStream.name = "Bot Protection"
162
- let owStream = streams.find(s => s.name == "OW")
163
-
164
- for (let stream of [owStream, botStream]) {
165
- if (!stream) continue
166
- let geos: string[] = stream?.filters[0]?.payload
167
-
168
- if (!geos) continue
169
- let index = geos.findIndex(geo => geo == geoToRemove)
170
- geos.splice(index, 1)
171
- let newGeos = stream.filters[0].payload = geos
172
- console.log({
173
- name: stream.name,
174
- geos: geos,
175
- geosToRemove: geoToRemove,
176
- newGeos: newGeos
177
- })
178
-
179
- await KeitaroService.upsertStreamToCampaign(campaign, stream)
180
- await sleep(1200)
181
- }
182
- console.log("––––––––––––––––––––––––")
183
- }
184
- }
185
-
186
- // export let createOrFindFlashRedirectCampaign = async (app: IApp): Promise<IKeitaroCampaign> => {
187
- // if (app.keitaroData && app.keitaroData?.redirectCampaignId && app.keitaroData?.redirectCampaignId != 0) {
188
- // console.log("Already exists! Fetching...")
189
- // let campaign = await KeitaroService.getCampaignById(app.keitaroData.redirectCampaignId)
190
- // return campaign
191
- // }
192
-
193
- // // Checking for already existing campaign
194
- // let allCampaigns = await KeitaroService.getAllCampaigns()
195
- // let regexp = new RegExp(`^F #${app.id}`)
196
- // const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
197
-
198
- // if (matchingCampaigns.length != 0) {
199
- // let campaign = matchingCampaigns[0]
200
- // // if (app.keitaroData) app.keitaroData.redirectCampaignId = campaign.id
201
-
202
- // console.log("Already exists!")
203
- // // await app.save()
204
- // return campaign
205
- // }
206
-
207
- // // Select domain for a campaign
208
- // let allDomains = await KeitaroService.getDomains(true)
209
- // if (!allDomains) {
210
- // throw Error(`Failed to get all domains list`)
211
- // }
212
-
213
- // const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
214
-
215
- // // Okay, now we have everything, let's create name for our campaign
216
- // const name = `F #${app.id} (${app.bundle})`
217
-
218
- // // And generate alias
219
- // const alias = Array.from({ length: 8 }, () => Math.floor(Math.random() * 36).toString(36)).join('');
220
-
221
- // // Here go the parameters for our campaign
222
- // let parameters = prepareRedirectCampaignParameters(app.id)
223
-
224
- // // Now let create a campaign object
225
- // let campaignData = prepareCampaignObject(name, alias, domain, parameters)
226
-
227
- // // And POST it to Keitaro!
228
-
229
- // let createdCampaign = await KeitaroService.createCampaign(campaignData)
230
-
231
- // console.log(`Done! Campaign data:`)
232
- // console.log(createdCampaign)
233
-
234
- // return createdCampaign
235
- // }
236
-
237
- let prepareCampaignObject = (name: string, alias: string, domain: IKeitaroDomain, parameters: IKeitaroCampaignParameters): Partial<IKeitaroCampaign> => {
238
- return {
239
- name: name,
240
- alias: alias,
241
- type: TYPE_POSITION,
242
- uniqueness_method: UNIQUENESS_METHOD,
243
- cookies_ttl: MAX_COOKIES_TTL,
244
- state: STATE_ACTIVE,
245
- cost_type: COST_TYPE_CPC,
246
- cost_value: COST_VALUE,
247
- cost_currency: COST_CURRENCY_USD,
248
- group_id: FLASH_REDIRECT_GROUP_ID,
249
- traffic_source_id: TRAFFIC_SOURCE_ID_FLASH_AI,
250
- domain_id: domain.id,
251
- parameters: parameters,
252
- uniqueness_use_cookies: true,
253
- traffic_loss: 0
254
- }
255
- }
256
-
257
- let prepareRedirectCampaignParameters = (appId: number): IKeitaroCampaignParameters => {
258
- return {
259
- "keyword": {
260
- "name": "keyword",
261
- "placeholder": "",
262
- "alias": "Ключевик"
263
- },
264
- "cost": {
265
- "name": "cost",
266
- "placeholder": "",
267
- "alias": "Расход"
268
- },
269
- "currency": {
270
- "name": "currency",
271
- "placeholder": "",
272
- "alias": "Валюта"
273
- },
274
- "external_id": {
275
- "name": "external_id",
276
- "placeholder": "",
277
- "alias": "External ID"
278
- },
279
- "creative_id": {
280
- "name": "creative_id",
281
- "placeholder": "",
282
- "alias": "Creative ID"
283
- },
284
- "ad_campaign_id": {
285
- "name": "ad_campaign_id",
286
- "placeholder": "",
287
- "alias": "Ad Campaign ID"
288
- },
289
- "source": {
290
- "name": "source",
291
- "placeholder": "",
292
- "alias": "Сайт"
293
- },
294
- "sub_id_7": {
295
- "name": "sub_id_7",
296
- "placeholder": "",
297
- "alias": "Sub id 7"
298
- },
299
- "sub_id_8": {
300
- "name": "session_id",
301
- "placeholder": "",
302
- "alias": "session_id"
303
- },
304
- "sub_id_9": {
305
- "name": "sub_id_9",
306
- "placeholder": "",
307
- "alias": "Sub id 9"
308
- },
309
- "sub_id_10": {
310
- "name": "sub_id_10",
311
- "placeholder": "",
312
- "alias": "Sub id 10"
313
- },
314
- "sub_id_11": {
315
- "name": "sub_id_11",
316
- "placeholder": "",
317
- "alias": "Sub id 11"
318
- },
319
- "platform": {
320
- "name": "platform",
321
- "placeholder": "",
322
- "alias": "platform"
323
- },
324
- "ad_partner": {
325
- "name": "ad_partner",
326
- "placeholder": "",
327
- "alias": "ad_partner"
328
- },
329
- "ad_traffic": {
330
- "name": "ad_traffic",
331
- "placeholder": "",
332
- "alias": "ad_traffic"
333
- },
334
- "offer_id": {
335
- "name": "offer_id",
336
- "placeholder": "",
337
- "alias": "offer_id"
338
- },
339
- "sub_id_16": {
340
- "name": "sub_id_16",
341
- "placeholder": "",
342
- "alias": "Sub id 16"
343
- },
344
- "sub_id_17": {
345
- "name": "sub_id_17",
346
- "placeholder": "",
347
- "alias": "Sub id 17"
348
- }
349
- }
350
- }
351
-
352
- export let prepareOWCampaignParameters = (app: IApp): IKeitaroCampaignParameters => {
353
- return {
354
- "keyword": {
355
- "name": "keyword",
356
- "placeholder": "",
357
- "alias": "Ключевик"
358
- },
359
- "cost": {
360
- "name": "cost",
361
- "placeholder": "",
362
- "alias": "Расход"
363
- },
364
- "currency": {
365
- "name": "currency",
366
- "placeholder": "",
367
- "alias": "Валюта"
368
- },
369
- "external_id": {
370
- "name": "external_id",
371
- "placeholder": "",
372
- "alias": "External ID"
373
- },
374
- "creative_id": {
375
- "name": "creative_id",
376
- "placeholder": "",
377
- "alias": "Creative ID"
378
- },
379
- "ad_campaign_id": {
380
- "name": "ad_campaign_id",
381
- "placeholder": "",
382
- "alias": "Ad Campaign ID"
383
- },
384
- "source": {
385
- "name": "source",
386
- "placeholder": "",
387
- "alias": "Сайт"
388
- },
389
- "sub_id_8": {
390
- "name": "session_id",
391
- "placeholder": "",
392
- "alias": "session_id"
393
- },
394
-
395
-
396
- "sub_id_12": {
397
- "name": "platform",
398
- "placeholder": "",
399
- "alias": "platform"
400
- },
401
- "sub_id_13": {
402
- "name": "ad_partner",
403
- "placeholder": "",
404
- "alias": "ad_partner"
405
- },
406
- "sub_id_14": {
407
- "name": "ad_traffic",
408
- "placeholder": "",
409
- "alias": "ad_traffic"
410
- },
411
- "sub_id_15": {
412
- "name": "offer_id",
413
- "placeholder": "",
414
- "alias": "offer_id"
415
- },
416
-
417
-
418
- }
419
- }
420
-
421
- // function createBPStreamPartialPayload(app: IApp): Partial<IKeitaroStream> {
422
- // return {
423
- // name: `Bot Protection`,
424
- // type: "forced",
425
- // action_type: "http",
426
- // action_payload: "https://tomain.com",
427
- // schema: "redirect",
428
- // filter_or: true,
429
- // collect_clicks: true,
430
- // weight: 0,
431
- // filters: [{
432
- // name: "country",
433
- // mode: "reject",
434
- // payload: app.geos.split(" ")
435
- // }, {
436
- // name: "bot",
437
- // mode: "accept",
438
- // payload: null,
439
- // }],
440
- // }
441
- // }
442
-
443
- function createDefenceMainStreamPartialPayload(app: IApp): Partial<IKeitaroStream> {
444
- return {
445
- name: "ALL",
446
- type: "regular",
447
- action_type: "http",
448
- action_payload: undefined, // directParams field removed from IApp
449
- schema: "redirect",
450
- filter_or: false,
451
- collect_clicks: true,
452
- weight: 100,
453
- }
454
- }
455
-
456
- // export function createOWStreamPartialPayload(app: IApp): Partial<IKeitaroStream> {
457
- // return {
458
- // name: `OW`,
459
- // type: "regular",
460
- // action_type: "http",
461
- // action_payload: "https://bprtsk-controlpanel.com/ow?appId={appId}&clickId={uid}&countryCode={country}",
462
- // schema: "redirect",
463
- // filter_or: false,
464
- // collect_clicks: true,
465
- // weight: 100,
466
- // filters: [{
467
- // name: "country",
468
- // mode: "accept",
469
- // payload: app.geos.split(" ")
470
- // }],
471
- // }
472
- // }
473
-
474
- export async function createDirectCampaign(app: IApp) {
475
- let campaign = await KeitaroService.cloneDCampaign(app)
476
-
477
- let stream = createDefenceMainStreamPartialPayload(app)
478
-
479
- await KeitaroService.upsertStreamToCampaign(campaign, stream)
480
-
481
- return campaign
482
- }
483
-
484
- export async function createOWCampaign(app: IApp, platform?: EPlatform) {
485
- let owCampaign = await KeitaroService.cloneOWCampaign(app, platform)
486
-
487
- return owCampaign
488
- }
489
-
490
-
491
- // TODO separate files for offers, campaigns etc.
492
-
493
- let removeBrokenDomain = async () => {
494
-
495
- let regexp = new RegExp(`^#`)
496
- let campaigns = (await KeitaroService.getAllCampaigns()).filter(campaign => regexp.exec(campaign.name) && campaign.domain == "https://slottibolt.com/");
497
- for (let campaign of campaigns) {
498
- console.log(campaign.name)
499
- }
500
- }
501
-
502
- let changeSourceForFA = async () => {
503
- let regexp = new RegExp(`^#`)
504
- let campaigns = (await KeitaroService.getAllCampaigns()).filter(campaign => regexp.exec(campaign.name));
505
- for (let campaign of campaigns) {
506
- console.log(campaign.name)
507
- await KeitaroService.updateCampaign(campaign.id, {
508
- traffic_source_id: 22
509
- })
510
- }
511
- }
512
-
513
- let replaceInOfferLink = async (old: string, replace: string, offerNameRegEx: RegExp) => {
514
- let offers = await KeitaroService.getAllOffers()
515
-
516
- offers = offers.filter((o) => offerNameRegEx.exec(o.name))
517
-
518
- for (let offer of offers) {
519
- console.log(offer.name)
520
- // offer.action_payload = offer.action_payload.replace(old, replace)
521
-
522
- await sleep(700)
523
- await KeitaroService.updateOffer(offer)
524
- }
525
- }
526
-
527
- // let gatherInfoForFlashApps = async () => {
528
- // console.log(__dirname)
529
- // const pasteMap: PasteMap = JSON.parse(await readFile('/Users/bprtsk/Documents/Work/ASO/AI Control Panel /AI Panel Core/src/utils/map-paste.json', 'utf8'));
530
- // const trackingMap: TrackingMap = JSON.parse(await readFile('/Users/bprtsk/Documents/Work/ASO/AI Control Panel /AI Panel Core/src/utils/map-tracking.json', 'utf8'));
531
- // const flashApps: { [key: string]: IFlashApp | undefined } = JSON.parse(await readFile('/Users/bprtsk/Documents/Work/ASO/AI Control Panel /AI Panel Core/src/utils/map-apps.json', 'utf8'));
532
-
533
- // let allCampaigns = await KeitaroService.getAllCampaigns()
534
- // let owCampaigns = allCampaigns.filter(c => new RegExp(`^FA #`).exec(c.name)).reduce((acc, obj) => ({ ...acc, [new RegExp(/#(.*) \(/g).exec(obj.name)?.[1] || obj.name]: obj }), {});
535
- // let redirectCampaigns = allCampaigns.filter(c => new RegExp(`^F #`).exec(c.name)).reduce((acc, obj) => ({ ...acc, [new RegExp(/#(.*) \(/g).exec(obj.name)?.[1] || obj.name]: obj }), {});
536
-
537
- // let result = []
538
- // for (let [id, paste] of Object.entries(pasteMap)) {
539
- // console.log(`- #${id}`)
540
- // // let ow = owCampaigns[id as keyof object] as IKeitaroCampaign | undefined
541
- // // let redirect = redirectCampaigns[id as keyof object] as IKeitaroCampaign | undefined
542
- // // let tracking = trackingMap[id as keyof object]
543
- // let app = flashApps[id as keyof object]
544
-
545
- // if (!app) {
546
- // console.log(`! No app for ${id}`)
547
- // continue
548
- // }
549
-
550
- // // if (paste.status == FlashAppPlugStatus.ENABLED) {
551
- // // if (!ow) console.log(`#${id}: no OW`)
552
-
553
- // // if (!redirect) console.log(`No redirect for #${id}`)
554
- // // else if (!paste.content.includes(redirect.domain)) console.log(`#${id}: Redirect domain (${redirect.domain}) differs from paste domain (${paste.content})`)
555
- // // else if (!paste.content.includes(redirect.alias)) console.log(`#${id}: Redirect campaign alias (${redirect.alias}) differs from paste id (${paste.content})`)
556
- // // }
557
-
558
- // // let appId
559
- // // for (let parameter of Object.values(redirect?.parameters || {})) {
560
- // // if (parameter.name == "appId") {
561
- // // appId = parameter.placeholder
562
- // // }
563
- // // }
564
- // // if (!appId && ow) console.log(`No app id for #${id}`)
565
- // // else if (appId != id && ow) console.log(`Wrong app id (${appId}) for #${id}`)
566
-
567
- // // let owDomain = ow?.domain?.split("/")[2]
568
- // // let owDomainId = ow?.domain_id
569
- // // let owCampaignId = ow?.id
570
- // // let owCampaignName = ow?.name
571
- // // let owCampaignAlias = ow?.alias
572
- // // let redirectDomain = redirect?.domain?.split("/")[2]
573
- // // let redirectDomainId = redirect?.domain_id
574
- // // let redirectCampaignId = redirect?.id
575
- // // let redirectCampaignName = redirect?.name
576
- // // let redirectCampaignAlias = redirect?.alias
577
-
578
- // // let clickIdParameterName = ow?.parameters?.sub_id_8?.name
579
- // // let offerIdParameterName = ow?.parameters?.sub_id_15?.name
580
- // // if (!clickIdParameterName && app && ow) console.log(`No click id parameter for #${id}`)
581
- // // if (!offerIdParameterName && app && ow) console.log(`No offer id parameter for #${id}`)
582
-
583
- // // let trackingLink = tracking?.trackingUrl
584
-
585
- // // app.plugStatus = paste.status
586
- // // app.plugContent = paste.content
587
- // // app.plugType = PlugType.PASTEBIN
588
- // // app.plugId = paste.paste_id
589
- // // app.reservePlugType = PlugType.PASTEBIN
590
- // // app.plugAccountId = parseInt(paste.accountId)
591
-
592
- // // app.keitaroData.redirectDomainName = redirectDomain || "none"
593
- // // app.keitaroData.redirectDomainId = redirectDomainId || 0
594
- // // app.keitaroData.redirectCampaignId = redirectCampaignId || 0
595
- // // app.keitaroData.redirectCampaignName = redirectCampaignName || "none"
596
- // // app.keitaroData.redirectCampaignAlias = redirectCampaignAlias || "none"
597
- // // app.keitaroData.trackingDomainId = owDomainId || 0
598
- // // app.keitaroData.trackingDomainName = owDomain || "none"
599
- // // app.keitaroData.trackingCampaignId = owCampaignId || 0
600
- // // app.keitaroData.trackingCampaignName = owCampaignName || "none"
601
- // // app.keitaroData.trackingCampaignAlias = owCampaignAlias || "none"
602
-
603
- // // if (clickIdParameterName) app.keitaroData.clickIdParameterName = clickIdParameterName
604
- // // if (offerIdParameterName) app.keitaroData.offerIdParameterName = offerIdParameterName
605
-
606
- // // if (trackingLink) app.trackingUrl = trackingLink
607
-
608
- // // if (!owCampaignName?.includes(app.bundle) && ow) {
609
- // // console.log(`OW: bundle differs (${app.bundle} in DB and ${owCampaignName})`)
610
- // // }
611
-
612
- // // if (!redirectCampaignName?.includes(app.bundle) && redirect) {
613
- // // console.log(`Redirect: bundle differs (${app.bundle} in DB and ${redirectCampaignName})`)
614
- // // }
615
-
616
- // result.push(app)
617
-
618
- // console.log("--------------------")
619
- // }
620
-
621
- // await axios.post(`https://aipanel-secondary.com/flash/batch-update`, result, {
622
- // headers: {
623
- // "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjg3Mjc2NjA0LCJleHAiOjE2ODc4ODE0MDR9.XesrnNGmWlK-yBBMs5TeKvTe07A8Sud7B4MyfZAOMag"
624
- // }
625
- // })
626
-
627
- // // console.log(result)
628
- // }
629
-
630
- let findBrokenOfferStreams = async () => {
631
- let allCampaigns = await KeitaroService.getAllCampaigns()
632
-
633
- let regexp = new RegExp(`^#`)
634
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
635
- for (let campaign of matchingCampaigns) {
636
- console.log(campaign.name)
637
- console.log("––––––––––––––––––––––––")
638
- let streams = await KeitaroService.getStreamsByCampaignId(campaign.id)
639
-
640
- for (let stream of streams) {
641
- if (stream.name == "Bot Protection") continue
642
-
643
- let idPayload = stream.filters.find(f => f.name == "sub_id_15")
644
-
645
- if (!idPayload) {
646
- console.log(`${stream.name}: id payload is missing, payload: ${stream.filters}`)
647
- }
648
- }
649
- }
650
- }
651
-
652
- let moveCampaignsToAnotherGroup = async () => {
653
- const appIds: number[] = [
654
- 460, 457, 459, 456, 421, 711, 451, 709, 712, 428, 455, 388, 458,
655
- 355, 341, 342, 334, 431, 403, 436, 365, 393, 801, 702, 448, 444,
656
- 437, 439, 447, 378, 412, 380, 402, 852, 438
657
- ]
658
-
659
- let allCampaigns = await KeitaroService.getAllCampaigns()
660
- let campaignIds = allCampaigns.filter(c => {
661
- for (let id of appIds) if (c.name.includes(`#${id}`)) return true
662
- return false
663
- }).map(c => c.id)
664
-
665
- let from = 2, to = 80
666
-
667
- await KeitaroService.changeCampaignsGroup(from, to, campaignIds)
668
- }
669
-
670
- let renameCampaigns = async () => {
671
- let allCampaigns = await KeitaroService.getAllCampaigns()
672
-
673
- let regexp = /^#(\d+)/;
674
-
675
- // Filter campaigns that match the regex
676
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.test(campaign.name) && campaign.group_id == 80);
677
- console.log(`Matching campaigns found: ${matchingCampaigns.length}`);
678
-
679
- for (let campaign of matchingCampaigns) {
680
- const match = regexp.exec(campaign.name);
681
- if (match && match[1]) {
682
- const appId = match[1]; // Extracted number after '#'
683
- await KeitaroService.updateCampaign(campaign.id, { name: `#${appId} [⛌]` })
684
- console.log(`Updated "${campaign.name}" to #${appId} [⛌]`)
685
- }
686
- }
687
- }
688
-
689
- // renameCampaigns()
690
-
691
- // moveCampaignsToAnotherGroup()
692
-
693
- // Getting campaign group ids
694
- // (async () => {
695
- // let campaigns = await KeitaroService.getAllCampaigns()
696
- // let normal = campaigns.find(c => c.id == 2684)
697
- // let archive = campaigns.find(c => c.id == 2679)
698
-
699
- // console.log([normal?.group_id, archive?.group_id])
700
- // })()
701
-
702
- // findBrokenOfferStreams()
703
-
704
- // removeBrokenDomain()
705
-
706
- // createFlashCampaigns(sampleApp)
707
- // changeSourceForFA()
708
- // addGeosToAllRedirectCam`paigns("GR")
709
- // removeGeosFromAllRedirectCampaigns("BE`")
710
-
711
- // gatherInfoForFlashApps()
712
-
713
- // replaceInOfferLink(`xmariorel.com`, `lalielynaualish.com`, /.*icecasino_huffson.*/g)
714
- // replaceInOfferLink(`lp=18`, `lp=00`, /.*icecasino_huffson.*/g)
715
- // let test = async () => console.log(await KeitaroService.getProfitForTodayAndYesterday())
716
- // test()
717
-
718
- async function fixLastThreeMonthsClickCosts(): Promise<void> {
719
- // Get current date
720
- const now = new Date();
721
-
722
- // Calculate date 3 months ago
723
- const threeMonthsAgo = new Date();
724
- threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
725
-
726
- // Format dates to required format "YYYY-MM-DD HH:MM"
727
- const startDate = threeMonthsAgo.toISOString().slice(0, 10) + " 00:00";
728
- const endDate = now.toISOString().slice(0, 10) + " 23:59";
729
-
730
- console.log(`Fixing click costs from ${startDate} to ${endDate}`);
731
-
732
- try {
733
- await KeitaroService.fixBrokenClickCosts(startDate, endDate);
734
- console.log("Successfully fixed click costs");
735
- } catch (error) {
736
- console.error("Failed to fix click costs:", error);
737
- throw error;
738
- }
739
- }
740
-
741
- // fixLastThreeMonthsClickCosts();
742
-
743
- async function disableAutoCost(): Promise<void> {
744
- try {
745
- // Get all campaigns
746
- const campaigns = await KeitaroService.getAllCampaigns();
747
- console.log(`Disabling auto cost for ${campaigns.length} campaigns...`);
748
-
749
- // Update each campaign
750
- for (const campaign of campaigns) {
751
- try {
752
- await KeitaroService.updateCampaign(campaign.id, { cost_auto: false });
753
- console.log(`Disabled auto cost for campaign: ${campaign.name} (ID: ${campaign.id})`);
754
-
755
- // Add a small delay to avoid overwhelming the API
756
- await sleep(500);
757
- } catch (error) {
758
- console.error(`Failed to update campaign ${campaign.name} (ID: ${campaign.id}):`, error);
759
- }
760
- }
761
-
762
- console.log('Successfully disabled auto cost for all campaigns');
763
- } catch (error) {
764
- console.error('Failed to disable auto cost:', error);
765
- throw error;
766
- }
767
- }
768
-
769
-
770
-
771
- async function getClicksByIp(ip: string, campaignId: number, interval: KeitaroClicksInterval = KeitaroClicksInterval.ONE_MONTH_AGO, limit: number = 100): Promise<any> {
772
- const request: IKeitaroClicksRequest = {
773
- range: {
774
- interval
775
- },
776
- columns: ['sub_id'],
777
- filters: [
778
- {
779
- name: 'ip',
780
- operator: 'BEGINS_WITH',
781
- expression: ip
782
- },
783
- {
784
- name: 'campaign_id',
785
- operator: 'EQUALS',
786
- expression: campaignId
787
- }
788
- ],
789
-
790
- limit
791
- };
792
-
793
- return KeitaroService.getClicks(request);
794
- }
795
-
796
- async function checkMultipleIPs() {
797
- const ips = [
798
- "88.155.31.196",
799
- "176.120.63.205"
800
- ];
801
- let subids = []
802
- for (const ip of ips) {
803
- // console.log(`\nChecking IP: ${ip}`);
804
- try {
805
- const clicks = await getClicksByIp(ip, 2832, KeitaroClicksInterval.SEVEN_DAYS_AGO);
806
- subids.push(clicks[clicks.length - 1].sub_id)
807
- } catch (error) { }
808
- await sleep(300); // Delay to avoid rate limiting
809
- }
810
-
811
- return subids
812
- }
813
-
814
-
815
- // disableAutoCost();
816
-
817
- type PostbackStatus = 'lead' | 'sale' | 'rejected';
818
-
819
- export async function sendPostbacks(subids: string[], status: PostbackStatus, payout?: number): Promise<void> {
820
- const baseUrl = 'https://aibprtsk.com/bab2832/postback';
821
-
822
- const sendPostback = async (subid: string) => {
823
- try {
824
- let url = `${baseUrl}?subid=${subid}&status=${status}`;
825
- if (payout !== undefined) {
826
- url += `&payout=${payout}`;
827
- }
828
-
829
- const response = await axios.get(url);
830
- if (response.status !== 200) {
831
- throw new Error(`HTTP error! status: ${response.status}`);
832
- }
833
-
834
- console.log(`Postback sent successfully for subid: ${subid}`);
835
- } catch (error) {
836
- console.error(`Failed to send postback for subid: ${subid}`, error);
837
- }
838
-
839
- // Add delay between requests to prevent overwhelming the server
840
- await sleep(300);
841
- };
842
-
843
- // Process postbacks sequentially to avoid rate limiting
844
- for (const subid of subids) {
845
- await sendPostback(subid);
846
- }
847
- }
848
-
849
-
850
- (async () => {
851
- let subids = await checkMultipleIPs();
852
- await sendPostbacks(subids, 'sale', 125)
853
- })();