@bprotsyk/aso-core 2.1.37 → 2.1.39

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.
Files changed (105) hide show
  1. package/README.md +1 -1
  2. package/lib/app/app-integration.d.ts +53 -53
  3. package/lib/app/app-integration.js +63 -63
  4. package/lib/app/app-list-item.d.ts +5 -5
  5. package/lib/app/app-list-item.js +2 -2
  6. package/lib/app/app-type.d.ts +4 -4
  7. package/lib/app/app-type.js +8 -8
  8. package/lib/app/app.d.ts +208 -290
  9. package/lib/app/app.js +156 -156
  10. package/lib/general/cloudflare-domain.d.ts +42 -42
  11. package/lib/general/cloudflare-domain.js +12 -12
  12. package/lib/general/domain.d.ts +110 -169
  13. package/lib/general/domain.js +62 -62
  14. package/lib/general/namecheap-domain.d.ts +85 -132
  15. package/lib/general/namecheap-domain.js +14 -14
  16. package/lib/general/push.d.ts +6 -6
  17. package/lib/general/push.js +2 -2
  18. package/lib/general/queue.d.ts +2 -2
  19. package/lib/general/queue.js +1 -1
  20. package/lib/general/shape.d.ts +18 -18
  21. package/lib/general/shape.js +36 -36
  22. package/lib/index.d.ts +26 -26
  23. package/lib/index.js +69 -69
  24. package/lib/keitaro/keitaro-campaign.d.ts +31 -31
  25. package/lib/keitaro/keitaro-campaign.js +5 -5
  26. package/lib/keitaro/keitaro-domain.d.ts +6 -6
  27. package/lib/keitaro/keitaro-domain.js +2 -2
  28. package/lib/keitaro/keitaro-offer.d.ts +7 -7
  29. package/lib/keitaro/keitaro-offer.js +2 -2
  30. package/lib/keitaro/keitaro-stream.d.ts +20 -20
  31. package/lib/keitaro/keitaro-stream.js +2 -2
  32. package/lib/network/keitaro/http.d.ts +2 -2
  33. package/lib/network/keitaro/http.js +12 -12
  34. package/lib/network/keitaro/keitaro-service.d.ts +50 -48
  35. package/lib/network/keitaro/keitaro-service.js +283 -293
  36. package/lib/offers/list.d.ts +42 -435
  37. package/lib/offers/list.js +12 -12
  38. package/lib/offers/offer.d.ts +91 -152
  39. package/lib/offers/offer.js +42 -42
  40. package/lib/offers/offerwall/offerwall-home-dialog-data.d.ts +6 -6
  41. package/lib/offers/offerwall/offerwall-home-dialog-data.js +2 -2
  42. package/lib/offers/offerwall/offerwall-offer.d.ts +12 -12
  43. package/lib/offers/offerwall/offerwall-offer.js +2 -2
  44. package/lib/offers/offerwall/offerwall-response.d.ts +6 -6
  45. package/lib/offers/offerwall/offerwall-response.js +2 -2
  46. package/lib/offers/offerwall/offerwall-section.d.ts +6 -6
  47. package/lib/offers/offerwall/offerwall-section.js +2 -2
  48. package/lib/offers/section.d.ts +47 -60
  49. package/lib/offers/section.js +20 -20
  50. package/lib/panel/app/upsert-flash-app-request.d.ts +31 -31
  51. package/lib/panel/app/upsert-flash-app-request.js +2 -2
  52. package/lib/panel/auth.d.ts +9 -9
  53. package/lib/panel/auth.js +2 -2
  54. package/lib/panel/flash/upsert-flash-app-request.d.ts +31 -31
  55. package/lib/panel/flash/upsert-flash-app-request.js +2 -2
  56. package/lib/panel/user.d.ts +46 -59
  57. package/lib/panel/user.js +28 -28
  58. package/lib/templates/nginx-template.conf +35 -35
  59. package/lib/templates/nginx-template.d.ts +1 -1
  60. package/lib/templates/nginx-template.js +39 -39
  61. package/lib/templates/nginx-template.ts +35 -35
  62. package/lib/utils/general.d.ts +11 -11
  63. package/lib/utils/general.js +40 -40
  64. package/lib/utils/huawei/converter.d.ts +2 -2
  65. package/lib/utils/huawei/converter.js +53 -53
  66. package/lib/utils/keitaro-utils.d.ts +13 -13
  67. package/lib/utils/keitaro-utils.js +614 -569
  68. package/lib/utils/server-util.js +303 -303
  69. package/package.json +51 -51
  70. package/src/app/app-integration.ts +66 -66
  71. package/src/app/app-list-item.ts +4 -4
  72. package/src/app/app-type.ts +3 -3
  73. package/src/app/app.ts +317 -317
  74. package/src/general/cloudflare-domain.ts +44 -44
  75. package/src/general/domain.ts +106 -106
  76. package/src/general/namecheap-domain.ts +63 -63
  77. package/src/general/push.ts +5 -5
  78. package/src/general/queue.ts +4 -4
  79. package/src/general/shape.tsx +55 -55
  80. package/src/index.ts +32 -32
  81. package/src/keitaro/keitaro-campaign.ts +35 -35
  82. package/src/keitaro/keitaro-domain.ts +5 -5
  83. package/src/keitaro/keitaro-offer.ts +6 -6
  84. package/src/keitaro/keitaro-stream.ts +19 -19
  85. package/src/network/keitaro/http.ts +8 -8
  86. package/src/network/keitaro/keitaro-service.ts +348 -364
  87. package/src/offers/list.ts +22 -19
  88. package/src/offers/offer.ts +80 -80
  89. package/src/offers/offerwall/offerwall-home-dialog-data.ts +6 -6
  90. package/src/offers/offerwall/offerwall-offer.ts +12 -12
  91. package/src/offers/offerwall/offerwall-response.ts +7 -7
  92. package/src/offers/offerwall/offerwall-section.ts +7 -7
  93. package/src/offers/section.ts +29 -29
  94. package/src/panel/app/upsert-flash-app-request.ts +39 -39
  95. package/src/panel/auth.ts +9 -9
  96. package/src/panel/user.ts +38 -38
  97. package/src/templates/nginx-template.ts +35 -35
  98. package/src/utils/data.csv +65 -65
  99. package/src/utils/general.ts +36 -36
  100. package/src/utils/huawei/converter.ts +55 -55
  101. package/src/utils/keitaro-utils.ts +717 -664
  102. package/src/utils/map-apps.json +4747 -4747
  103. package/src/utils/server-util.ts +368 -368
  104. package/src/utils/update-postbacks.js +27 -27
  105. package/tsconfig.json +20 -20
@@ -1,569 +1,614 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createOWCampaign = exports.createDirectCampaign = exports.createFlashCampaigns = exports.createOWStreamPartialPayload = exports.prepareOWCampaignParameters = exports.removeGeosFromAllRedirectCampaigns = exports.addGeosToAllRedirectCampaigns = exports.TRAFFIC_SOURCE_ID_FLASH_AI = void 0;
4
- const keitaro_service_1 = require("../network/keitaro/keitaro-service");
5
- const sleep = require('sleep-promise');
6
- const FLASH_REDIRECT_GROUP_ID = 82;
7
- exports.TRAFFIC_SOURCE_ID_FLASH_AI = 22;
8
- const UNIQUENESS_METHOD = "ip_ua";
9
- const MAX_COOKIES_TTL = 8760;
10
- const TYPE_POSITION = "position";
11
- const STATE_ACTIVE = "active";
12
- const COST_TYPE_CPC = "CPC";
13
- const COST_VALUE = 0;
14
- const COST_CURRENCY_USD = "USD";
15
- // clear campaigns from unused / wrong streams
16
- // let sampleApp: IFlashApp = {
17
- // id: 96,
18
- // bundle: "com.dynastyof.desert",
19
- // name: "Room of Fortuna",
20
- // plugId: "https://pastebin.com/raw/AR2u7dSD",
21
- // plugType: PlugType.PASTEBIN,
22
- // plugContent: "",
23
- // plugStatus: FlashAppPlugStatus.DISABLED,
24
- // plugAccountId: 1,
25
- // reservePlugId: "none",
26
- // reservePlugType: PlugType.OTHER,
27
- // reservePlugContent: "",
28
- // reservePlugStatus: FlashAppPlugStatus.DISABLED,
29
- // reservePlugAccountId: 1,
30
- // type: FlashAppType.GAMBLING,
31
- // developerEmail: "bolly.dreams@yahoo.com",
32
- // developerName: "Serhii Bolsky",
33
- // developerOrganization: "S.I.B FOP",
34
- // onesignalAppId: "e66658af-91c3-44bc-8123-ec64b1969cbd",
35
- // onesignalRestApiKey: "MDk2NjZlNTMtMzBhYi00MjEzLTg0ZGItOWVmZWZhMTczMzI0",
36
- // generationOptions: {
37
- // splashActivityClassName: "SplashActivity",
38
- // mainActivityClassName: "YourActivity",
39
- // linkName: "likn",
40
- // savedName: "isOk",
41
- // paranoidSeed: 228143750
42
- // },
43
- // geos: "RU,UA,KZ,ES,BR,PT,CL,MX",
44
- // keitaroData: {
45
- // redirectCampaignId: 0,
46
- // redirectCampaignName: "",
47
- // redirectDomainId: 0,
48
- // redirectDomainName: "",
49
- // trackingCampaignId: 0,
50
- // trackingCampaignName: "",
51
- // trackingDomainId: 0,
52
- // trackingDomainName: "",
53
- // clickIdParameterName: "p",
54
- // offerIdParameterName: "i",
55
- // }
56
- // } as IFlashApp
57
- let addGeosToAllRedirectCampaigns = async (geosToAdd) => {
58
- let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
59
- let regexp = new RegExp(`^F #`);
60
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
61
- for (let campaign of matchingCampaigns) {
62
- console.log(campaign.name);
63
- console.log("––––––––––––––––––––––––");
64
- let streams = await keitaro_service_1.KeitaroService.getStreamsByCampaignId(campaign.id);
65
- let botStream = streams[0];
66
- botStream.name = "Bot Protection";
67
- let owStream = streams.find(s => s.name == "OW");
68
- for (let stream of [owStream, botStream]) {
69
- if (!stream)
70
- continue;
71
- console.log({
72
- name: stream.name,
73
- });
74
- let geos = stream?.filters[stream.type == "forced" ? 1 : 0]?.payload;
75
- if (!geos)
76
- continue;
77
- geosToAdd.split(" ").forEach((geo) => {
78
- let streamForGeo = streams.find((s) => s.name == geo);
79
- if (streamForGeo && stream)
80
- return;
81
- if (!geos.includes(geo))
82
- geos.push(geo);
83
- });
84
- stream.filters[stream.type == "forced" ? 1 : 0].payload = geos;
85
- await keitaro_service_1.KeitaroService.upsertStreamToCampaign(campaign, stream);
86
- await sleep(2000);
87
- }
88
- console.log("––––––––––––––––––––––––");
89
- }
90
- };
91
- exports.addGeosToAllRedirectCampaigns = addGeosToAllRedirectCampaigns;
92
- // export let changeTrackingOfferGeo = async (appId: number, keitaroId: string, geo: string) => {
93
- // let allCampaigns = await KeitaroService.getAllCampaigns()
94
- // let regexp = new RegExp(`^FA #${appId} `)
95
- // let matchingCampaign = allCampaigns.find(campaign => regexp.exec(campaign.name))
96
- // if (!matchingCampaign) throw new Error(`No matching campaign got appId ${appId}`)
97
- // let streams = await KeitaroService.getStreamsByCampaignId(matchingCampaign.id)
98
- // letstream =
99
- // for (let campaign of matchingCampaigns) {
100
- // console.log(campaign.name)
101
- // console.log("––––––––––––––––––––––––")
102
- // let streams = await KeitaroService.getStreamsByCampaignId(campaign.id)
103
- // let botStream = streams[0]
104
- // botStream.name = "Bot Protection"
105
- // let owStream = streams.find(s => s.name == "OW")
106
- // for (let stream of [owStream, botStream]) {
107
- // if (!stream) continue
108
- // console.log({
109
- // name: stream.name,
110
- // })
111
- // let geos = stream?.filters[stream.type == "forced" ? 1 : 0]?.payload
112
- // if (!geos) continue
113
- // geosToAdd.split(" ").forEach((geo: string) => {
114
- // let streamForGeo = streams.find((s) => s.name == geo)
115
- // if (streamForGeo && stream) return
116
- // if (!geos.includes(geo)) geos.push(geo)
117
- // });
118
- // stream.filters[stream.type == "forced" ? 1 : 0].payload = geos
119
- // await KeitaroService.upsertStreamToCampaign(campaign, stream)
120
- // await sleep(2000)
121
- // }
122
- // console.log("––––––––––––––––––––––––")
123
- // }
124
- // }
125
- let removeGeosFromAllRedirectCampaigns = async (geoToRemove) => {
126
- let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
127
- let regexp = new RegExp(`^F #`);
128
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
129
- for (let campaign of matchingCampaigns) {
130
- console.log(campaign.name);
131
- console.log("––––––––––––––––––––––––");
132
- let streams = await keitaro_service_1.KeitaroService.getStreamsByCampaignId(campaign.id);
133
- let botStream = streams[0];
134
- botStream.name = "Bot Protection";
135
- let owStream = streams.find(s => s.name == "OW");
136
- for (let stream of [owStream, botStream]) {
137
- if (!stream)
138
- continue;
139
- let geos = stream?.filters[0]?.payload;
140
- if (!geos)
141
- continue;
142
- let index = geos.findIndex(geo => geo == geoToRemove);
143
- geos.splice(index, 1);
144
- let newGeos = stream.filters[0].payload = geos;
145
- console.log({
146
- name: stream.name,
147
- geos: geos,
148
- geosToRemove: geoToRemove,
149
- newGeos: newGeos
150
- });
151
- await keitaro_service_1.KeitaroService.upsertStreamToCampaign(campaign, stream);
152
- await sleep(1200);
153
- }
154
- console.log("––––––––––––––––––––––––");
155
- }
156
- };
157
- exports.removeGeosFromAllRedirectCampaigns = removeGeosFromAllRedirectCampaigns;
158
- // export let createOrFindFlashRedirectCampaign = async (app: IApp): Promise<IKeitaroCampaign> => {
159
- // if (app.keitaroData && app.keitaroData?.redirectCampaignId && app.keitaroData?.redirectCampaignId != 0) {
160
- // console.log("Already exists! Fetching...")
161
- // let campaign = await KeitaroService.getCampaignById(app.keitaroData.redirectCampaignId)
162
- // return campaign
163
- // }
164
- // // Checking for already existing campaign
165
- // let allCampaigns = await KeitaroService.getAllCampaigns()
166
- // let regexp = new RegExp(`^F #${app.id}`)
167
- // const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
168
- // if (matchingCampaigns.length != 0) {
169
- // let campaign = matchingCampaigns[0]
170
- // // if (app.keitaroData) app.keitaroData.redirectCampaignId = campaign.id
171
- // console.log("Already exists!")
172
- // // await app.save()
173
- // return campaign
174
- // }
175
- // // Select domain for a campaign
176
- // let allDomains = await KeitaroService.getDomains(true)
177
- // if (!allDomains) {
178
- // throw Error(`Failed to get all domains list`)
179
- // }
180
- // const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
181
- // // Okay, now we have everything, let's create name for our campaign
182
- // const name = `F #${app.id} (${app.bundle})`
183
- // // And generate alias
184
- // const alias = Array.from({ length: 8 }, () => Math.floor(Math.random() * 36).toString(36)).join('');
185
- // // Here go the parameters for our campaign
186
- // let parameters = prepareRedirectCampaignParameters(app.id)
187
- // // Now let create a campaign object
188
- // let campaignData = prepareCampaignObject(name, alias, domain, parameters)
189
- // // And POST it to Keitaro!
190
- // let createdCampaign = await KeitaroService.createCampaign(campaignData)
191
- // console.log(`Done! Campaign data:`)
192
- // console.log(createdCampaign)
193
- // return createdCampaign
194
- // }
195
- let prepareCampaignObject = (name, alias, domain, parameters) => {
196
- return {
197
- name: name,
198
- alias: alias,
199
- type: TYPE_POSITION,
200
- uniqueness_method: UNIQUENESS_METHOD,
201
- cookies_ttl: MAX_COOKIES_TTL,
202
- state: STATE_ACTIVE,
203
- cost_type: COST_TYPE_CPC,
204
- cost_value: COST_VALUE,
205
- cost_currency: COST_CURRENCY_USD,
206
- group_id: FLASH_REDIRECT_GROUP_ID,
207
- traffic_source_id: exports.TRAFFIC_SOURCE_ID_FLASH_AI,
208
- domain_id: domain.id,
209
- parameters: parameters,
210
- uniqueness_use_cookies: true,
211
- traffic_loss: 0
212
- };
213
- };
214
- let prepareRedirectCampaignParameters = (appId) => {
215
- return {
216
- "keyword": {
217
- "name": "keyword",
218
- "placeholder": "",
219
- "alias": ""
220
- },
221
- "cost": {
222
- "name": "cost",
223
- "placeholder": "",
224
- "alias": ""
225
- },
226
- "currency": {
227
- "name": "currency",
228
- "placeholder": "",
229
- "alias": ""
230
- },
231
- "external_id": {
232
- "name": "external_id",
233
- "placeholder": "",
234
- "alias": ""
235
- },
236
- "creative_id": {
237
- "name": "creative_id",
238
- "placeholder": "",
239
- "alias": ""
240
- },
241
- "ad_campaign_id": {
242
- "name": "ad_campaign_id",
243
- "placeholder": "",
244
- "alias": ""
245
- },
246
- "source": {
247
- "name": "source",
248
- "placeholder": "",
249
- "alias": ""
250
- },
251
- sub_id_1: {
252
- name: "appId",
253
- placeholder: `${appId}`,
254
- alias: ""
255
- }
256
- };
257
- };
258
- let prepareOWCampaignParameters = (app) => {
259
- return {
260
- "keyword": {
261
- "name": "keyword",
262
- "placeholder": "",
263
- "alias": ""
264
- },
265
- "cost": {
266
- "name": "cost",
267
- "placeholder": "",
268
- "alias": ""
269
- },
270
- "currency": {
271
- "name": "currency",
272
- "placeholder": "",
273
- "alias": ""
274
- },
275
- "external_id": {
276
- "name": "external_id",
277
- "placeholder": "",
278
- "alias": ""
279
- },
280
- "creative_id": {
281
- "name": "creative_id",
282
- "placeholder": "",
283
- "alias": ""
284
- },
285
- "ad_campaign_id": {
286
- "name": "ad_campaign_id",
287
- "placeholder": "",
288
- "alias": ""
289
- },
290
- "source": {
291
- "name": "source",
292
- "placeholder": "",
293
- "alias": ""
294
- },
295
- sub_id_8: {
296
- "name": "click_id",
297
- "placeholder": "{click_id}",
298
- "alias": "click_id"
299
- },
300
- sub_id_15: {
301
- "name": "offer_id",
302
- "placeholder": "{offer_custom_id}",
303
- "alias": "offer_custom_id"
304
- }
305
- };
306
- };
307
- exports.prepareOWCampaignParameters = prepareOWCampaignParameters;
308
- function createBPStreamPartialPayload(app) {
309
- return {
310
- name: `Bot Protection`,
311
- type: "forced",
312
- action_type: "http",
313
- action_payload: "https://tomain.com",
314
- schema: "redirect",
315
- filter_or: true,
316
- collect_clicks: true,
317
- weight: 0,
318
- filters: [{
319
- name: "country",
320
- mode: "reject",
321
- payload: app.geos.split(" ")
322
- }, {
323
- name: "bot",
324
- mode: "accept",
325
- payload: null,
326
- }],
327
- };
328
- }
329
- function createDefenceMainStreamPartialPayload(app) {
330
- return {
331
- name: "ALL",
332
- type: "regular",
333
- action_type: "http",
334
- action_payload: app.directParams?.path,
335
- schema: "redirect",
336
- filter_or: false,
337
- collect_clicks: true,
338
- weight: 100,
339
- };
340
- }
341
- function createOWStreamPartialPayload(app) {
342
- return {
343
- name: `OW`,
344
- type: "regular",
345
- action_type: "http",
346
- action_payload: "https://bprtsk-controlpanel.com/ow?appId={appId}&clickId={uid}&countryCode={country}",
347
- schema: "redirect",
348
- filter_or: false,
349
- collect_clicks: true,
350
- weight: 100,
351
- filters: [{
352
- name: "country",
353
- mode: "accept",
354
- payload: app.geos.split(" ")
355
- }],
356
- };
357
- }
358
- exports.createOWStreamPartialPayload = createOWStreamPartialPayload;
359
- async function createFlashCampaigns(app) {
360
- // Upserting Flash Redirect campaign
361
- // let redirectCampaign = await createOrFindFlashRedirectCampaign(app)
362
- // console.log(`Redirect campaign name:`)
363
- // console.log(`${redirectCampaign.domain}/${redirectCampaign.alias}?uid=`)
364
- // Upserting necessary streams
365
- // let botProtectionStream = createBPStreamPartialPayload(app)
366
- // let owStream = createOWStreamPartialPayload(app)
367
- // for (let stream of [botProtectionStream, owStream]) {
368
- // await KeitaroService.upsertStreamToCampaign(redirectCampaign, stream)
369
- // }
370
- // Upserting OW campaign
371
- let owCampaign = await keitaro_service_1.KeitaroService.cloneOWCampaign(app);
372
- return {
373
- tracking: owCampaign,
374
- // redirect: redirectCampaign
375
- };
376
- }
377
- exports.createFlashCampaigns = createFlashCampaigns;
378
- async function createDirectCampaign(app) {
379
- let campaign = await keitaro_service_1.KeitaroService.cloneDCampaign(app);
380
- let stream = createDefenceMainStreamPartialPayload(app);
381
- await keitaro_service_1.KeitaroService.upsertStreamToCampaign(campaign, stream);
382
- return campaign;
383
- }
384
- exports.createDirectCampaign = createDirectCampaign;
385
- async function createOWCampaign(app) {
386
- let owCampaign = await keitaro_service_1.KeitaroService.cloneOWCampaign(app);
387
- return owCampaign;
388
- }
389
- exports.createOWCampaign = createOWCampaign;
390
- // TODO separate files for offers, campaigns etc.
391
- let removeBrokenDomain = async () => {
392
- let regexp = new RegExp(`^#`);
393
- let campaigns = (await keitaro_service_1.KeitaroService.getAllCampaigns()).filter(campaign => regexp.exec(campaign.name) && campaign.domain == "https://slottibolt.com/");
394
- for (let campaign of campaigns) {
395
- console.log(campaign.name);
396
- }
397
- };
398
- let changeSourceForFA = async () => {
399
- let regexp = new RegExp(`^#`);
400
- let campaigns = (await keitaro_service_1.KeitaroService.getAllCampaigns()).filter(campaign => regexp.exec(campaign.name));
401
- for (let campaign of campaigns) {
402
- console.log(campaign.name);
403
- await keitaro_service_1.KeitaroService.updateCampaign(campaign.id, {
404
- traffic_source_id: 22
405
- });
406
- }
407
- };
408
- let replaceInOfferLink = async (old, replace, offerNameRegEx) => {
409
- let offers = await keitaro_service_1.KeitaroService.getAllOffers();
410
- offers = offers.filter((o) => offerNameRegEx.exec(o.name));
411
- for (let offer of offers) {
412
- console.log(offer.name);
413
- // offer.action_payload = offer.action_payload.replace(old, replace)
414
- await sleep(700);
415
- await keitaro_service_1.KeitaroService.updateOffer(offer);
416
- }
417
- };
418
- // let gatherInfoForFlashApps = async () => {
419
- // console.log(__dirname)
420
- // const pasteMap: PasteMap = JSON.parse(await readFile('/Users/bprtsk/Documents/Work/ASO/AI Control Panel /AI Panel Core/src/utils/map-paste.json', 'utf8'));
421
- // const trackingMap: TrackingMap = JSON.parse(await readFile('/Users/bprtsk/Documents/Work/ASO/AI Control Panel /AI Panel Core/src/utils/map-tracking.json', 'utf8'));
422
- // 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'));
423
- // let allCampaigns = await KeitaroService.getAllCampaigns()
424
- // 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 }), {});
425
- // 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 }), {});
426
- // let result = []
427
- // for (let [id, paste] of Object.entries(pasteMap)) {
428
- // console.log(`- #${id}`)
429
- // // let ow = owCampaigns[id as keyof object] as IKeitaroCampaign | undefined
430
- // // let redirect = redirectCampaigns[id as keyof object] as IKeitaroCampaign | undefined
431
- // // let tracking = trackingMap[id as keyof object]
432
- // let app = flashApps[id as keyof object]
433
- // if (!app) {
434
- // console.log(`! No app for ${id}`)
435
- // continue
436
- // }
437
- // // if (paste.status == FlashAppPlugStatus.ENABLED) {
438
- // // if (!ow) console.log(`#${id}: no OW`)
439
- // // if (!redirect) console.log(`No redirect for #${id}`)
440
- // // else if (!paste.content.includes(redirect.domain)) console.log(`#${id}: Redirect domain (${redirect.domain}) differs from paste domain (${paste.content})`)
441
- // // else if (!paste.content.includes(redirect.alias)) console.log(`#${id}: Redirect campaign alias (${redirect.alias}) differs from paste id (${paste.content})`)
442
- // // }
443
- // // let appId
444
- // // for (let parameter of Object.values(redirect?.parameters || {})) {
445
- // // if (parameter.name == "appId") {
446
- // // appId = parameter.placeholder
447
- // // }
448
- // // }
449
- // // if (!appId && ow) console.log(`No app id for #${id}`)
450
- // // else if (appId != id && ow) console.log(`Wrong app id (${appId}) for #${id}`)
451
- // // let owDomain = ow?.domain?.split("/")[2]
452
- // // let owDomainId = ow?.domain_id
453
- // // let owCampaignId = ow?.id
454
- // // let owCampaignName = ow?.name
455
- // // let owCampaignAlias = ow?.alias
456
- // // let redirectDomain = redirect?.domain?.split("/")[2]
457
- // // let redirectDomainId = redirect?.domain_id
458
- // // let redirectCampaignId = redirect?.id
459
- // // let redirectCampaignName = redirect?.name
460
- // // let redirectCampaignAlias = redirect?.alias
461
- // // let clickIdParameterName = ow?.parameters?.sub_id_8?.name
462
- // // let offerIdParameterName = ow?.parameters?.sub_id_15?.name
463
- // // if (!clickIdParameterName && app && ow) console.log(`No click id parameter for #${id}`)
464
- // // if (!offerIdParameterName && app && ow) console.log(`No offer id parameter for #${id}`)
465
- // // let trackingLink = tracking?.trackingUrl
466
- // // app.plugStatus = paste.status
467
- // // app.plugContent = paste.content
468
- // // app.plugType = PlugType.PASTEBIN
469
- // // app.plugId = paste.paste_id
470
- // // app.reservePlugType = PlugType.PASTEBIN
471
- // // app.plugAccountId = parseInt(paste.accountId)
472
- // // app.keitaroData.redirectDomainName = redirectDomain || "none"
473
- // // app.keitaroData.redirectDomainId = redirectDomainId || 0
474
- // // app.keitaroData.redirectCampaignId = redirectCampaignId || 0
475
- // // app.keitaroData.redirectCampaignName = redirectCampaignName || "none"
476
- // // app.keitaroData.redirectCampaignAlias = redirectCampaignAlias || "none"
477
- // // app.keitaroData.trackingDomainId = owDomainId || 0
478
- // // app.keitaroData.trackingDomainName = owDomain || "none"
479
- // // app.keitaroData.trackingCampaignId = owCampaignId || 0
480
- // // app.keitaroData.trackingCampaignName = owCampaignName || "none"
481
- // // app.keitaroData.trackingCampaignAlias = owCampaignAlias || "none"
482
- // // if (clickIdParameterName) app.keitaroData.clickIdParameterName = clickIdParameterName
483
- // // if (offerIdParameterName) app.keitaroData.offerIdParameterName = offerIdParameterName
484
- // // if (trackingLink) app.trackingUrl = trackingLink
485
- // // if (!owCampaignName?.includes(app.bundle) && ow) {
486
- // // console.log(`OW: bundle differs (${app.bundle} in DB and ${owCampaignName})`)
487
- // // }
488
- // // if (!redirectCampaignName?.includes(app.bundle) && redirect) {
489
- // // console.log(`Redirect: bundle differs (${app.bundle} in DB and ${redirectCampaignName})`)
490
- // // }
491
- // result.push(app)
492
- // console.log("--------------------")
493
- // }
494
- // await axios.post(`https://aipanel-secondary.com/flash/batch-update`, result, {
495
- // headers: {
496
- // "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjg3Mjc2NjA0LCJleHAiOjE2ODc4ODE0MDR9.XesrnNGmWlK-yBBMs5TeKvTe07A8Sud7B4MyfZAOMag"
497
- // }
498
- // })
499
- // // console.log(result)
500
- // }
501
- let findBrokenOfferStreams = async () => {
502
- let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
503
- let regexp = new RegExp(`^#`);
504
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
505
- for (let campaign of matchingCampaigns) {
506
- console.log(campaign.name);
507
- console.log("––––––––––––––––––––––––");
508
- let streams = await keitaro_service_1.KeitaroService.getStreamsByCampaignId(campaign.id);
509
- for (let stream of streams) {
510
- if (stream.name == "Bot Protection")
511
- continue;
512
- let idPayload = stream.filters.find(f => f.name == "sub_id_15");
513
- if (!idPayload) {
514
- console.log(`${stream.name}: id payload is missing, payload: ${stream.filters}`);
515
- }
516
- }
517
- }
518
- };
519
- let moveCampaignsToAnotherGroup = async () => {
520
- const appIds = [
521
- 460, 457, 459, 456, 421, 711, 451, 709, 712, 428, 455, 388, 458,
522
- 355, 341, 342, 334, 431, 403, 436, 365, 393, 801, 702, 448, 444,
523
- 437, 439, 447, 378, 412, 380, 402, 852, 438
524
- ];
525
- let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
526
- let campaignIds = allCampaigns.filter(c => {
527
- for (let id of appIds)
528
- if (c.name.includes(`#${id}`))
529
- return true;
530
- return false;
531
- }).map(c => c.id);
532
- let from = 2, to = 80;
533
- await keitaro_service_1.KeitaroService.changeCampaignsGroup(from, to, campaignIds);
534
- };
535
- let renameCampaigns = async () => {
536
- let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
537
- let regexp = /^#(\d+)/;
538
- // Filter campaigns that match the regex
539
- const matchingCampaigns = allCampaigns.filter(campaign => regexp.test(campaign.name) && campaign.group_id == 80);
540
- console.log(`Matching campaigns found: ${matchingCampaigns.length}`);
541
- for (let campaign of matchingCampaigns) {
542
- const match = regexp.exec(campaign.name);
543
- if (match && match[1]) {
544
- const appId = match[1]; // Extracted number after '#'
545
- await keitaro_service_1.KeitaroService.updateCampaign(campaign.id, { name: `#${appId} [⛌]` });
546
- console.log(`Updated "${campaign.name}" to #${appId} [⛌]`);
547
- }
548
- }
549
- };
550
- // renameCampaigns()
551
- // moveCampaignsToAnotherGroup()
552
- // Getting campaign group ids
553
- // (async () => {
554
- // let campaigns = await KeitaroService.getAllCampaigns()
555
- // let normal = campaigns.find(c => c.id == 2684)
556
- // let archive = campaigns.find(c => c.id == 2679)
557
- // console.log([normal?.group_id, archive?.group_id])
558
- // })()
559
- // findBrokenOfferStreams()
560
- // removeBrokenDomain()
561
- // createFlashCampaigns(sampleApp)
562
- // changeSourceForFA()
563
- // addGeosToAllRedirectCam`paigns("GR")
564
- // removeGeosFromAllRedirectCampaigns("BE`")
565
- // gatherInfoForFlashApps()
566
- // replaceInOfferLink(`xmariorel.com`, `lalielynaualish.com`, /.*icecasino_huffson.*/g)
567
- // replaceInOfferLink(`lp=18`, `lp=00`, /.*icecasino_huffson.*/g)
568
- // let test = async () => console.log(await KeitaroService.getProfitForTodayAndYesterday())
569
- // test()
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createOWCampaign = exports.createDirectCampaign = exports.createFlashCampaigns = exports.createOWStreamPartialPayload = exports.prepareOWCampaignParameters = exports.removeGeosFromAllRedirectCampaigns = exports.addGeosToAllRedirectCampaigns = exports.TRAFFIC_SOURCE_ID_FLASH_AI = void 0;
4
+ const keitaro_service_1 = require("../network/keitaro/keitaro-service");
5
+ const sleep = require('sleep-promise');
6
+ const FLASH_REDIRECT_GROUP_ID = 82;
7
+ exports.TRAFFIC_SOURCE_ID_FLASH_AI = 22;
8
+ const UNIQUENESS_METHOD = "ip_ua";
9
+ const MAX_COOKIES_TTL = 8760;
10
+ const TYPE_POSITION = "position";
11
+ const STATE_ACTIVE = "active";
12
+ const COST_TYPE_CPC = "CPC";
13
+ const COST_VALUE = 0;
14
+ const COST_CURRENCY_USD = "USD";
15
+ // clear campaigns from unused / wrong streams
16
+ // let sampleApp: IFlashApp = {
17
+ // id: 96,
18
+ // bundle: "com.dynastyof.desert",
19
+ // name: "Room of Fortuna",
20
+ // plugId: "https://pastebin.com/raw/AR2u7dSD",
21
+ // plugType: PlugType.PASTEBIN,
22
+ // plugContent: "",
23
+ // plugStatus: FlashAppPlugStatus.DISABLED,
24
+ // plugAccountId: 1,
25
+ // reservePlugId: "none",
26
+ // reservePlugType: PlugType.OTHER,
27
+ // reservePlugContent: "",
28
+ // reservePlugStatus: FlashAppPlugStatus.DISABLED,
29
+ // reservePlugAccountId: 1,
30
+ // type: FlashAppType.GAMBLING,
31
+ // developerEmail: "bolly.dreams@yahoo.com",
32
+ // developerName: "Serhii Bolsky",
33
+ // developerOrganization: "S.I.B FOP",
34
+ // onesignalAppId: "e66658af-91c3-44bc-8123-ec64b1969cbd",
35
+ // onesignalRestApiKey: "MDk2NjZlNTMtMzBhYi00MjEzLTg0ZGItOWVmZWZhMTczMzI0",
36
+ // generationOptions: {
37
+ // splashActivityClassName: "SplashActivity",
38
+ // mainActivityClassName: "YourActivity",
39
+ // linkName: "likn",
40
+ // savedName: "isOk",
41
+ // paranoidSeed: 228143750
42
+ // },
43
+ // geos: "RU,UA,KZ,ES,BR,PT,CL,MX",
44
+ // keitaroData: {
45
+ // redirectCampaignId: 0,
46
+ // redirectCampaignName: "",
47
+ // redirectDomainId: 0,
48
+ // redirectDomainName: "",
49
+ // trackingCampaignId: 0,
50
+ // trackingCampaignName: "",
51
+ // trackingDomainId: 0,
52
+ // trackingDomainName: "",
53
+ // clickIdParameterName: "p",
54
+ // offerIdParameterName: "i",
55
+ // }
56
+ // } as IFlashApp
57
+ let addGeosToAllRedirectCampaigns = async (geosToAdd) => {
58
+ let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
59
+ let regexp = new RegExp(`^F #`);
60
+ const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
61
+ for (let campaign of matchingCampaigns) {
62
+ console.log(campaign.name);
63
+ console.log("––––––––––––––––––––––––");
64
+ let streams = await keitaro_service_1.KeitaroService.getStreamsByCampaignId(campaign.id);
65
+ let botStream = streams[0];
66
+ botStream.name = "Bot Protection";
67
+ let owStream = streams.find(s => s.name == "OW");
68
+ for (let stream of [owStream, botStream]) {
69
+ if (!stream)
70
+ continue;
71
+ console.log({
72
+ name: stream.name,
73
+ });
74
+ let geos = stream?.filters[stream.type == "forced" ? 1 : 0]?.payload;
75
+ if (!geos)
76
+ continue;
77
+ geosToAdd.split(" ").forEach((geo) => {
78
+ let streamForGeo = streams.find((s) => s.name == geo);
79
+ if (streamForGeo && stream)
80
+ return;
81
+ if (!geos.includes(geo))
82
+ geos.push(geo);
83
+ });
84
+ stream.filters[stream.type == "forced" ? 1 : 0].payload = geos;
85
+ await keitaro_service_1.KeitaroService.upsertStreamToCampaign(campaign, stream);
86
+ await sleep(2000);
87
+ }
88
+ console.log("––––––––––––––––––––––––");
89
+ }
90
+ };
91
+ exports.addGeosToAllRedirectCampaigns = addGeosToAllRedirectCampaigns;
92
+ // export let changeTrackingOfferGeo = async (appId: number, keitaroId: string, geo: string) => {
93
+ // let allCampaigns = await KeitaroService.getAllCampaigns()
94
+ // let regexp = new RegExp(`^FA #${appId} `)
95
+ // let matchingCampaign = allCampaigns.find(campaign => regexp.exec(campaign.name))
96
+ // if (!matchingCampaign) throw new Error(`No matching campaign got appId ${appId}`)
97
+ // let streams = await KeitaroService.getStreamsByCampaignId(matchingCampaign.id)
98
+ // letstream =
99
+ // for (let campaign of matchingCampaigns) {
100
+ // console.log(campaign.name)
101
+ // console.log("––––––––––––––––––––––––")
102
+ // let streams = await KeitaroService.getStreamsByCampaignId(campaign.id)
103
+ // let botStream = streams[0]
104
+ // botStream.name = "Bot Protection"
105
+ // let owStream = streams.find(s => s.name == "OW")
106
+ // for (let stream of [owStream, botStream]) {
107
+ // if (!stream) continue
108
+ // console.log({
109
+ // name: stream.name,
110
+ // })
111
+ // let geos = stream?.filters[stream.type == "forced" ? 1 : 0]?.payload
112
+ // if (!geos) continue
113
+ // geosToAdd.split(" ").forEach((geo: string) => {
114
+ // let streamForGeo = streams.find((s) => s.name == geo)
115
+ // if (streamForGeo && stream) return
116
+ // if (!geos.includes(geo)) geos.push(geo)
117
+ // });
118
+ // stream.filters[stream.type == "forced" ? 1 : 0].payload = geos
119
+ // await KeitaroService.upsertStreamToCampaign(campaign, stream)
120
+ // await sleep(2000)
121
+ // }
122
+ // console.log("––––––––––––––––––––––––")
123
+ // }
124
+ // }
125
+ let removeGeosFromAllRedirectCampaigns = async (geoToRemove) => {
126
+ let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
127
+ let regexp = new RegExp(`^F #`);
128
+ const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
129
+ for (let campaign of matchingCampaigns) {
130
+ console.log(campaign.name);
131
+ console.log("––––––––––––––––––––––––");
132
+ let streams = await keitaro_service_1.KeitaroService.getStreamsByCampaignId(campaign.id);
133
+ let botStream = streams[0];
134
+ botStream.name = "Bot Protection";
135
+ let owStream = streams.find(s => s.name == "OW");
136
+ for (let stream of [owStream, botStream]) {
137
+ if (!stream)
138
+ continue;
139
+ let geos = stream?.filters[0]?.payload;
140
+ if (!geos)
141
+ continue;
142
+ let index = geos.findIndex(geo => geo == geoToRemove);
143
+ geos.splice(index, 1);
144
+ let newGeos = stream.filters[0].payload = geos;
145
+ console.log({
146
+ name: stream.name,
147
+ geos: geos,
148
+ geosToRemove: geoToRemove,
149
+ newGeos: newGeos
150
+ });
151
+ await keitaro_service_1.KeitaroService.upsertStreamToCampaign(campaign, stream);
152
+ await sleep(1200);
153
+ }
154
+ console.log("––––––––––––––––––––––––");
155
+ }
156
+ };
157
+ exports.removeGeosFromAllRedirectCampaigns = removeGeosFromAllRedirectCampaigns;
158
+ // export let createOrFindFlashRedirectCampaign = async (app: IApp): Promise<IKeitaroCampaign> => {
159
+ // if (app.keitaroData && app.keitaroData?.redirectCampaignId && app.keitaroData?.redirectCampaignId != 0) {
160
+ // console.log("Already exists! Fetching...")
161
+ // let campaign = await KeitaroService.getCampaignById(app.keitaroData.redirectCampaignId)
162
+ // return campaign
163
+ // }
164
+ // // Checking for already existing campaign
165
+ // let allCampaigns = await KeitaroService.getAllCampaigns()
166
+ // let regexp = new RegExp(`^F #${app.id}`)
167
+ // const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
168
+ // if (matchingCampaigns.length != 0) {
169
+ // let campaign = matchingCampaigns[0]
170
+ // // if (app.keitaroData) app.keitaroData.redirectCampaignId = campaign.id
171
+ // console.log("Already exists!")
172
+ // // await app.save()
173
+ // return campaign
174
+ // }
175
+ // // Select domain for a campaign
176
+ // let allDomains = await KeitaroService.getDomains(true)
177
+ // if (!allDomains) {
178
+ // throw Error(`Failed to get all domains list`)
179
+ // }
180
+ // const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
181
+ // // Okay, now we have everything, let's create name for our campaign
182
+ // const name = `F #${app.id} (${app.bundle})`
183
+ // // And generate alias
184
+ // const alias = Array.from({ length: 8 }, () => Math.floor(Math.random() * 36).toString(36)).join('');
185
+ // // Here go the parameters for our campaign
186
+ // let parameters = prepareRedirectCampaignParameters(app.id)
187
+ // // Now let create a campaign object
188
+ // let campaignData = prepareCampaignObject(name, alias, domain, parameters)
189
+ // // And POST it to Keitaro!
190
+ // let createdCampaign = await KeitaroService.createCampaign(campaignData)
191
+ // console.log(`Done! Campaign data:`)
192
+ // console.log(createdCampaign)
193
+ // return createdCampaign
194
+ // }
195
+ let prepareCampaignObject = (name, alias, domain, parameters) => {
196
+ return {
197
+ name: name,
198
+ alias: alias,
199
+ type: TYPE_POSITION,
200
+ uniqueness_method: UNIQUENESS_METHOD,
201
+ cookies_ttl: MAX_COOKIES_TTL,
202
+ state: STATE_ACTIVE,
203
+ cost_type: COST_TYPE_CPC,
204
+ cost_value: COST_VALUE,
205
+ cost_currency: COST_CURRENCY_USD,
206
+ group_id: FLASH_REDIRECT_GROUP_ID,
207
+ traffic_source_id: exports.TRAFFIC_SOURCE_ID_FLASH_AI,
208
+ domain_id: domain.id,
209
+ parameters: parameters,
210
+ uniqueness_use_cookies: true,
211
+ traffic_loss: 0
212
+ };
213
+ };
214
+ let prepareRedirectCampaignParameters = (appId) => {
215
+ return {
216
+ "keyword": {
217
+ "name": "keyword",
218
+ "placeholder": "",
219
+ "alias": ""
220
+ },
221
+ "cost": {
222
+ "name": "cost",
223
+ "placeholder": "",
224
+ "alias": ""
225
+ },
226
+ "currency": {
227
+ "name": "currency",
228
+ "placeholder": "",
229
+ "alias": ""
230
+ },
231
+ "external_id": {
232
+ "name": "external_id",
233
+ "placeholder": "",
234
+ "alias": ""
235
+ },
236
+ "creative_id": {
237
+ "name": "creative_id",
238
+ "placeholder": "",
239
+ "alias": ""
240
+ },
241
+ "ad_campaign_id": {
242
+ "name": "ad_campaign_id",
243
+ "placeholder": "",
244
+ "alias": ""
245
+ },
246
+ "source": {
247
+ "name": "source",
248
+ "placeholder": "",
249
+ "alias": ""
250
+ },
251
+ sub_id_1: {
252
+ name: "appId",
253
+ placeholder: `${appId}`,
254
+ alias: ""
255
+ }
256
+ };
257
+ };
258
+ let prepareOWCampaignParameters = (app) => {
259
+ return {
260
+ "keyword": {
261
+ "name": "keyword",
262
+ "placeholder": "",
263
+ "alias": ""
264
+ },
265
+ "cost": {
266
+ "name": "cost",
267
+ "placeholder": "",
268
+ "alias": ""
269
+ },
270
+ "currency": {
271
+ "name": "currency",
272
+ "placeholder": "",
273
+ "alias": ""
274
+ },
275
+ "external_id": {
276
+ "name": "external_id",
277
+ "placeholder": "",
278
+ "alias": ""
279
+ },
280
+ "creative_id": {
281
+ "name": "creative_id",
282
+ "placeholder": "",
283
+ "alias": ""
284
+ },
285
+ "ad_campaign_id": {
286
+ "name": "ad_campaign_id",
287
+ "placeholder": "",
288
+ "alias": ""
289
+ },
290
+ "source": {
291
+ "name": "source",
292
+ "placeholder": "",
293
+ "alias": ""
294
+ },
295
+ sub_id_8: {
296
+ "name": "click_id",
297
+ "placeholder": "{click_id}",
298
+ "alias": "click_id"
299
+ },
300
+ sub_id_15: {
301
+ "name": "offer_id",
302
+ "placeholder": "{offer_custom_id}",
303
+ "alias": "offer_custom_id"
304
+ }
305
+ };
306
+ };
307
+ exports.prepareOWCampaignParameters = prepareOWCampaignParameters;
308
+ function createBPStreamPartialPayload(app) {
309
+ return {
310
+ name: `Bot Protection`,
311
+ type: "forced",
312
+ action_type: "http",
313
+ action_payload: "https://tomain.com",
314
+ schema: "redirect",
315
+ filter_or: true,
316
+ collect_clicks: true,
317
+ weight: 0,
318
+ filters: [{
319
+ name: "country",
320
+ mode: "reject",
321
+ payload: app.geos.split(" ")
322
+ }, {
323
+ name: "bot",
324
+ mode: "accept",
325
+ payload: null,
326
+ }],
327
+ };
328
+ }
329
+ function createDefenceMainStreamPartialPayload(app) {
330
+ return {
331
+ name: "ALL",
332
+ type: "regular",
333
+ action_type: "http",
334
+ action_payload: app.directParams?.path,
335
+ schema: "redirect",
336
+ filter_or: false,
337
+ collect_clicks: true,
338
+ weight: 100,
339
+ };
340
+ }
341
+ function createOWStreamPartialPayload(app) {
342
+ return {
343
+ name: `OW`,
344
+ type: "regular",
345
+ action_type: "http",
346
+ action_payload: "https://bprtsk-controlpanel.com/ow?appId={appId}&clickId={uid}&countryCode={country}",
347
+ schema: "redirect",
348
+ filter_or: false,
349
+ collect_clicks: true,
350
+ weight: 100,
351
+ filters: [{
352
+ name: "country",
353
+ mode: "accept",
354
+ payload: app.geos.split(" ")
355
+ }],
356
+ };
357
+ }
358
+ exports.createOWStreamPartialPayload = createOWStreamPartialPayload;
359
+ async function createFlashCampaigns(app) {
360
+ // Upserting Flash Redirect campaign
361
+ // let redirectCampaign = await createOrFindFlashRedirectCampaign(app)
362
+ // console.log(`Redirect campaign name:`)
363
+ // console.log(`${redirectCampaign.domain}/${redirectCampaign.alias}?uid=`)
364
+ // Upserting necessary streams
365
+ // let botProtectionStream = createBPStreamPartialPayload(app)
366
+ // let owStream = createOWStreamPartialPayload(app)
367
+ // for (let stream of [botProtectionStream, owStream]) {
368
+ // await KeitaroService.upsertStreamToCampaign(redirectCampaign, stream)
369
+ // }
370
+ // Upserting OW campaign
371
+ let owCampaign = await keitaro_service_1.KeitaroService.cloneOWCampaign(app);
372
+ return {
373
+ tracking: owCampaign,
374
+ // redirect: redirectCampaign
375
+ };
376
+ }
377
+ exports.createFlashCampaigns = createFlashCampaigns;
378
+ async function createDirectCampaign(app) {
379
+ let campaign = await keitaro_service_1.KeitaroService.cloneDCampaign(app);
380
+ let stream = createDefenceMainStreamPartialPayload(app);
381
+ await keitaro_service_1.KeitaroService.upsertStreamToCampaign(campaign, stream);
382
+ return campaign;
383
+ }
384
+ exports.createDirectCampaign = createDirectCampaign;
385
+ async function createOWCampaign(app) {
386
+ let owCampaign = await keitaro_service_1.KeitaroService.cloneOWCampaign(app);
387
+ return owCampaign;
388
+ }
389
+ exports.createOWCampaign = createOWCampaign;
390
+ // TODO separate files for offers, campaigns etc.
391
+ let removeBrokenDomain = async () => {
392
+ let regexp = new RegExp(`^#`);
393
+ let campaigns = (await keitaro_service_1.KeitaroService.getAllCampaigns()).filter(campaign => regexp.exec(campaign.name) && campaign.domain == "https://slottibolt.com/");
394
+ for (let campaign of campaigns) {
395
+ console.log(campaign.name);
396
+ }
397
+ };
398
+ let changeSourceForFA = async () => {
399
+ let regexp = new RegExp(`^#`);
400
+ let campaigns = (await keitaro_service_1.KeitaroService.getAllCampaigns()).filter(campaign => regexp.exec(campaign.name));
401
+ for (let campaign of campaigns) {
402
+ console.log(campaign.name);
403
+ await keitaro_service_1.KeitaroService.updateCampaign(campaign.id, {
404
+ traffic_source_id: 22
405
+ });
406
+ }
407
+ };
408
+ let replaceInOfferLink = async (old, replace, offerNameRegEx) => {
409
+ let offers = await keitaro_service_1.KeitaroService.getAllOffers();
410
+ offers = offers.filter((o) => offerNameRegEx.exec(o.name));
411
+ for (let offer of offers) {
412
+ console.log(offer.name);
413
+ // offer.action_payload = offer.action_payload.replace(old, replace)
414
+ await sleep(700);
415
+ await keitaro_service_1.KeitaroService.updateOffer(offer);
416
+ }
417
+ };
418
+ // let gatherInfoForFlashApps = async () => {
419
+ // console.log(__dirname)
420
+ // const pasteMap: PasteMap = JSON.parse(await readFile('/Users/bprtsk/Documents/Work/ASO/AI Control Panel /AI Panel Core/src/utils/map-paste.json', 'utf8'));
421
+ // const trackingMap: TrackingMap = JSON.parse(await readFile('/Users/bprtsk/Documents/Work/ASO/AI Control Panel /AI Panel Core/src/utils/map-tracking.json', 'utf8'));
422
+ // 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'));
423
+ // let allCampaigns = await KeitaroService.getAllCampaigns()
424
+ // 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 }), {});
425
+ // 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 }), {});
426
+ // let result = []
427
+ // for (let [id, paste] of Object.entries(pasteMap)) {
428
+ // console.log(`- #${id}`)
429
+ // // let ow = owCampaigns[id as keyof object] as IKeitaroCampaign | undefined
430
+ // // let redirect = redirectCampaigns[id as keyof object] as IKeitaroCampaign | undefined
431
+ // // let tracking = trackingMap[id as keyof object]
432
+ // let app = flashApps[id as keyof object]
433
+ // if (!app) {
434
+ // console.log(`! No app for ${id}`)
435
+ // continue
436
+ // }
437
+ // // if (paste.status == FlashAppPlugStatus.ENABLED) {
438
+ // // if (!ow) console.log(`#${id}: no OW`)
439
+ // // if (!redirect) console.log(`No redirect for #${id}`)
440
+ // // else if (!paste.content.includes(redirect.domain)) console.log(`#${id}: Redirect domain (${redirect.domain}) differs from paste domain (${paste.content})`)
441
+ // // else if (!paste.content.includes(redirect.alias)) console.log(`#${id}: Redirect campaign alias (${redirect.alias}) differs from paste id (${paste.content})`)
442
+ // // }
443
+ // // let appId
444
+ // // for (let parameter of Object.values(redirect?.parameters || {})) {
445
+ // // if (parameter.name == "appId") {
446
+ // // appId = parameter.placeholder
447
+ // // }
448
+ // // }
449
+ // // if (!appId && ow) console.log(`No app id for #${id}`)
450
+ // // else if (appId != id && ow) console.log(`Wrong app id (${appId}) for #${id}`)
451
+ // // let owDomain = ow?.domain?.split("/")[2]
452
+ // // let owDomainId = ow?.domain_id
453
+ // // let owCampaignId = ow?.id
454
+ // // let owCampaignName = ow?.name
455
+ // // let owCampaignAlias = ow?.alias
456
+ // // let redirectDomain = redirect?.domain?.split("/")[2]
457
+ // // let redirectDomainId = redirect?.domain_id
458
+ // // let redirectCampaignId = redirect?.id
459
+ // // let redirectCampaignName = redirect?.name
460
+ // // let redirectCampaignAlias = redirect?.alias
461
+ // // let clickIdParameterName = ow?.parameters?.sub_id_8?.name
462
+ // // let offerIdParameterName = ow?.parameters?.sub_id_15?.name
463
+ // // if (!clickIdParameterName && app && ow) console.log(`No click id parameter for #${id}`)
464
+ // // if (!offerIdParameterName && app && ow) console.log(`No offer id parameter for #${id}`)
465
+ // // let trackingLink = tracking?.trackingUrl
466
+ // // app.plugStatus = paste.status
467
+ // // app.plugContent = paste.content
468
+ // // app.plugType = PlugType.PASTEBIN
469
+ // // app.plugId = paste.paste_id
470
+ // // app.reservePlugType = PlugType.PASTEBIN
471
+ // // app.plugAccountId = parseInt(paste.accountId)
472
+ // // app.keitaroData.redirectDomainName = redirectDomain || "none"
473
+ // // app.keitaroData.redirectDomainId = redirectDomainId || 0
474
+ // // app.keitaroData.redirectCampaignId = redirectCampaignId || 0
475
+ // // app.keitaroData.redirectCampaignName = redirectCampaignName || "none"
476
+ // // app.keitaroData.redirectCampaignAlias = redirectCampaignAlias || "none"
477
+ // // app.keitaroData.trackingDomainId = owDomainId || 0
478
+ // // app.keitaroData.trackingDomainName = owDomain || "none"
479
+ // // app.keitaroData.trackingCampaignId = owCampaignId || 0
480
+ // // app.keitaroData.trackingCampaignName = owCampaignName || "none"
481
+ // // app.keitaroData.trackingCampaignAlias = owCampaignAlias || "none"
482
+ // // if (clickIdParameterName) app.keitaroData.clickIdParameterName = clickIdParameterName
483
+ // // if (offerIdParameterName) app.keitaroData.offerIdParameterName = offerIdParameterName
484
+ // // if (trackingLink) app.trackingUrl = trackingLink
485
+ // // if (!owCampaignName?.includes(app.bundle) && ow) {
486
+ // // console.log(`OW: bundle differs (${app.bundle} in DB and ${owCampaignName})`)
487
+ // // }
488
+ // // if (!redirectCampaignName?.includes(app.bundle) && redirect) {
489
+ // // console.log(`Redirect: bundle differs (${app.bundle} in DB and ${redirectCampaignName})`)
490
+ // // }
491
+ // result.push(app)
492
+ // console.log("--------------------")
493
+ // }
494
+ // await axios.post(`https://aipanel-secondary.com/flash/batch-update`, result, {
495
+ // headers: {
496
+ // "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiaWF0IjoxNjg3Mjc2NjA0LCJleHAiOjE2ODc4ODE0MDR9.XesrnNGmWlK-yBBMs5TeKvTe07A8Sud7B4MyfZAOMag"
497
+ // }
498
+ // })
499
+ // // console.log(result)
500
+ // }
501
+ let findBrokenOfferStreams = async () => {
502
+ let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
503
+ let regexp = new RegExp(`^#`);
504
+ const matchingCampaigns = allCampaigns.filter(campaign => regexp.exec(campaign.name));
505
+ for (let campaign of matchingCampaigns) {
506
+ console.log(campaign.name);
507
+ console.log("––––––––––––––––––––––––");
508
+ let streams = await keitaro_service_1.KeitaroService.getStreamsByCampaignId(campaign.id);
509
+ for (let stream of streams) {
510
+ if (stream.name == "Bot Protection")
511
+ continue;
512
+ let idPayload = stream.filters.find(f => f.name == "sub_id_15");
513
+ if (!idPayload) {
514
+ console.log(`${stream.name}: id payload is missing, payload: ${stream.filters}`);
515
+ }
516
+ }
517
+ }
518
+ };
519
+ let moveCampaignsToAnotherGroup = async () => {
520
+ const appIds = [
521
+ 460, 457, 459, 456, 421, 711, 451, 709, 712, 428, 455, 388, 458,
522
+ 355, 341, 342, 334, 431, 403, 436, 365, 393, 801, 702, 448, 444,
523
+ 437, 439, 447, 378, 412, 380, 402, 852, 438
524
+ ];
525
+ let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
526
+ let campaignIds = allCampaigns.filter(c => {
527
+ for (let id of appIds)
528
+ if (c.name.includes(`#${id}`))
529
+ return true;
530
+ return false;
531
+ }).map(c => c.id);
532
+ let from = 2, to = 80;
533
+ await keitaro_service_1.KeitaroService.changeCampaignsGroup(from, to, campaignIds);
534
+ };
535
+ let renameCampaigns = async () => {
536
+ let allCampaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
537
+ let regexp = /^#(\d+)/;
538
+ // Filter campaigns that match the regex
539
+ const matchingCampaigns = allCampaigns.filter(campaign => regexp.test(campaign.name) && campaign.group_id == 80);
540
+ console.log(`Matching campaigns found: ${matchingCampaigns.length}`);
541
+ for (let campaign of matchingCampaigns) {
542
+ const match = regexp.exec(campaign.name);
543
+ if (match && match[1]) {
544
+ const appId = match[1]; // Extracted number after '#'
545
+ await keitaro_service_1.KeitaroService.updateCampaign(campaign.id, { name: `#${appId} [⛌]` });
546
+ console.log(`Updated "${campaign.name}" to #${appId} [⛌]`);
547
+ }
548
+ }
549
+ };
550
+ // renameCampaigns()
551
+ // moveCampaignsToAnotherGroup()
552
+ // Getting campaign group ids
553
+ // (async () => {
554
+ // let campaigns = await KeitaroService.getAllCampaigns()
555
+ // let normal = campaigns.find(c => c.id == 2684)
556
+ // let archive = campaigns.find(c => c.id == 2679)
557
+ // console.log([normal?.group_id, archive?.group_id])
558
+ // })()
559
+ // findBrokenOfferStreams()
560
+ // removeBrokenDomain()
561
+ // createFlashCampaigns(sampleApp)
562
+ // changeSourceForFA()
563
+ // addGeosToAllRedirectCam`paigns("GR")
564
+ // removeGeosFromAllRedirectCampaigns("BE`")
565
+ // gatherInfoForFlashApps()
566
+ // replaceInOfferLink(`xmariorel.com`, `lalielynaualish.com`, /.*icecasino_huffson.*/g)
567
+ // replaceInOfferLink(`lp=18`, `lp=00`, /.*icecasino_huffson.*/g)
568
+ // let test = async () => console.log(await KeitaroService.getProfitForTodayAndYesterday())
569
+ // test()
570
+ async function fixLastThreeMonthsClickCosts() {
571
+ // Get current date
572
+ const now = new Date();
573
+ // Calculate date 3 months ago
574
+ const threeMonthsAgo = new Date();
575
+ threeMonthsAgo.setMonth(threeMonthsAgo.getMonth() - 3);
576
+ // Format dates to required format "YYYY-MM-DD HH:MM"
577
+ const startDate = threeMonthsAgo.toISOString().slice(0, 10) + " 00:00";
578
+ const endDate = now.toISOString().slice(0, 10) + " 23:59";
579
+ console.log(`Fixing click costs from ${startDate} to ${endDate}`);
580
+ try {
581
+ await keitaro_service_1.KeitaroService.fixBrokenClickCosts(startDate, endDate);
582
+ console.log("Successfully fixed click costs");
583
+ }
584
+ catch (error) {
585
+ console.error("Failed to fix click costs:", error);
586
+ throw error;
587
+ }
588
+ }
589
+ // fixLastThreeMonthsClickCosts();
590
+ async function disableAutoCost() {
591
+ try {
592
+ // Get all campaigns
593
+ const campaigns = await keitaro_service_1.KeitaroService.getAllCampaigns();
594
+ console.log(`Disabling auto cost for ${campaigns.length} campaigns...`);
595
+ // Update each campaign
596
+ for (const campaign of campaigns) {
597
+ try {
598
+ await keitaro_service_1.KeitaroService.updateCampaign(campaign.id, { cost_auto: false });
599
+ console.log(`Disabled auto cost for campaign: ${campaign.name} (ID: ${campaign.id})`);
600
+ // Add a small delay to avoid overwhelming the API
601
+ await sleep(500);
602
+ }
603
+ catch (error) {
604
+ console.error(`Failed to update campaign ${campaign.name} (ID: ${campaign.id}):`, error);
605
+ }
606
+ }
607
+ console.log('Successfully disabled auto cost for all campaigns');
608
+ }
609
+ catch (error) {
610
+ console.error('Failed to disable auto cost:', error);
611
+ throw error;
612
+ }
613
+ }
614
+ // disableAutoCost();