@bprotsyk/aso-core 2.0.47 → 2.0.49

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