@bprotsyk/aso-core 2.1.59 → 2.1.61

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.
@@ -23,6 +23,7 @@ declare function createCampaign(campaignData: Partial<IKeitaroCampaign>): Promis
23
23
  declare function getCampaignById(id: number): Promise<IKeitaroCampaign>;
24
24
  export declare function upsertStreamToCampaign(campaign: IKeitaroCampaign, stream: Partial<IKeitaroStream>): Promise<void>;
25
25
  declare function cloneOWCampaign(app: IApp, platform?: EPlatform): Promise<IKeitaroCampaign | any>;
26
+ declare function cloneDirectCampaign(app: IApp, platform?: EPlatform): Promise<IKeitaroCampaign | any>;
26
27
  declare function cloneDCampaign(app: IApp): Promise<IKeitaroCampaign>;
27
28
  declare function changeCampaignsGroup(fromId: number, toId: number, exceptForCampaignIds: number[], onlyForCampaignIds?: number[]): Promise<void>;
28
29
  declare function getDomains(onlyActive?: boolean): Promise<IKeitaroDomain[]>;
@@ -49,5 +50,6 @@ export declare const KeitaroService: {
49
50
  cloneDCampaign: typeof cloneDCampaign;
50
51
  findKeitaroOffers: typeof findKeitaroOffers;
51
52
  fixBrokenClickCosts: typeof fixBrokenClickCosts;
53
+ cloneDirectCampaign: typeof cloneDirectCampaign;
52
54
  };
53
55
  export {};
@@ -272,6 +272,90 @@ async function cloneOWCampaign(app, platform) {
272
272
  const updatedCampaign = await getCampaignById(newCampaign.id);
273
273
  return updatedCampaign;
274
274
  }
275
+ async function cloneDirectCampaign(app, platform) {
276
+ let name = `#${app.id} [✦]`;
277
+ let platformName = platform ? (0, app_1.getPlatformName)(platform) : null;
278
+ const platformCampaignName = `#${app.id} [✦] (${platformName})`;
279
+ const generateAlias = () => {
280
+ const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
281
+ return Array.from({ length: 8 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join('');
282
+ };
283
+ let allCampaigns = await getAllCampaigns();
284
+ let matchingCampaign = [];
285
+ if (platform && platform !== app_1.EPlatform.GENERAL) {
286
+ // Шукаємо кампанію з платформою
287
+ matchingCampaign = allCampaigns.filter((c) => c.name.includes(`#${app.id}`) &&
288
+ c.name.includes(`[✦]`) &&
289
+ c.name.includes(`(${platformName})`));
290
+ }
291
+ else {
292
+ // Шукаємо кампанію без платформи або з суфіксом
293
+ matchingCampaign = allCampaigns.filter((c) => c.name.includes(`#${app.id}`) &&
294
+ c.name.includes(`[✦]`) &&
295
+ !c.name.includes('('));
296
+ }
297
+ if (matchingCampaign.length > 0)
298
+ return matchingCampaign[0];
299
+ const originalCampaign = await getCampaignById(3175);
300
+ const maxPosition = Math.max(...allCampaigns.map(c => c.position || 0));
301
+ const originalStreams = await getStreamsByCampaignId(3175);
302
+ let allDomains = await exports.KeitaroService.getDomains(true);
303
+ if (!allDomains) {
304
+ throw Error(`Failed to get all domains list`);
305
+ }
306
+ const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
307
+ const maxGroupId = Math.max(...allCampaigns.map(c => c.group_id || 0));
308
+ let alias = generateAlias();
309
+ let payload = {
310
+ // Унікальні поля
311
+ name: platformName ? platformCampaignName : name,
312
+ alias: alias,
313
+ domain_id: domain.id,
314
+ position: [maxPosition + 100],
315
+ group_id: maxGroupId + 1,
316
+ traffic_source_id: keitaro_utils_1.TRAFFIC_SOURCE_ID_FLASH_AI,
317
+ parameters: (0, keitaro_utils_1.prepareOWCampaignParameters)(app),
318
+ // Неунікальні поля з оригінальної кампанії
319
+ type: originalCampaign.type,
320
+ state: originalCampaign.state,
321
+ cost_type: originalCampaign.cost_type,
322
+ cost_value: originalCampaign.cost_value,
323
+ cost_currency: originalCampaign.cost_currency,
324
+ uniqueness_period: originalCampaign.uniqueness_period,
325
+ cookies_ttl: originalCampaign.cookies_ttl,
326
+ notes: originalCampaign.notes,
327
+ collect_clicks: originalCampaign.collect_clicks,
328
+ uniqueness_type: originalCampaign.uniqueness_type,
329
+ };
330
+ const newCampaign = await createCampaign(payload);
331
+ for (const stream of originalStreams) {
332
+ await http_1.default.post('streams', {
333
+ name: stream.name,
334
+ campaign_id: newCampaign.id,
335
+ schema: stream.schema,
336
+ type: stream.type,
337
+ action_type: stream.action_type,
338
+ weight: stream.weight,
339
+ offers: stream.offers.map((offer) => ({
340
+ offer_id: offer.offer_id,
341
+ share: offer.share,
342
+ state: offer.state
343
+ })),
344
+ filters: stream.filters.map((filter) => ({
345
+ name: filter.name,
346
+ mode: filter.mode,
347
+ payload: filter.payload
348
+ })),
349
+ position: stream.position,
350
+ state: stream.state
351
+ });
352
+ }
353
+ await http_1.default.put(`/campaigns/${newCampaign.id}`, {
354
+ group_id: originalCampaign.group_id
355
+ });
356
+ const updatedCampaign = await getCampaignById(newCampaign.id);
357
+ return updatedCampaign;
358
+ }
275
359
  async function cloneDCampaign(app) {
276
360
  let name = `D #${app.id} (${app.bundle})`;
277
361
  let allCampaigns = await getAllCampaigns();
@@ -364,5 +448,5 @@ exports.KeitaroService = {
364
448
  getStreamsByCampaignId, updateCampaign, getAllCampaigns, getAllOffers, cloneStreams, addOffersToKeitaro, getOfferByKeitaroId, getDomains, createCampaign, getCampaignById, upsertStreamToCampaign, cloneOWCampaign,
365
449
  updateOffer, changeCampaignsGroup, getProfitForTimeRange, getClicks,
366
450
  // getProfitForTodayAndYesterday,
367
- cloneDCampaign, findKeitaroOffers, fixBrokenClickCosts
451
+ cloneDCampaign, findKeitaroOffers, fixBrokenClickCosts, cloneDirectCampaign
368
452
  };
@@ -1,11 +1,9 @@
1
- import { IKeitaroStream } from "../keitaro/keitaro-stream";
2
1
  import { EPlatform, IApp } from "../app/app";
3
2
  import { IKeitaroCampaign, IKeitaroCampaignParameters } from "../keitaro/keitaro-campaign";
4
3
  export declare const TRAFFIC_SOURCE_ID_FLASH_AI = 22;
5
4
  export declare let addGeosToAllRedirectCampaigns: (geosToAdd: string) => Promise<void>;
6
5
  export declare let removeGeosFromAllRedirectCampaigns: (geoToRemove: string) => Promise<void>;
7
6
  export declare let prepareOWCampaignParameters: (app: IApp) => IKeitaroCampaignParameters;
8
- export declare function createOWStreamPartialPayload(app: IApp): Partial<IKeitaroStream>;
9
7
  export declare function createDirectCampaign(app: IApp): Promise<IKeitaroCampaign>;
10
8
  export declare function createOWCampaign(app: IApp, platform?: EPlatform): Promise<any>;
11
9
  type PostbackStatus = 'lead' | 'sale' | 'rejected';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sendPostbacks = exports.createOWCampaign = exports.createDirectCampaign = exports.createOWStreamPartialPayload = exports.prepareOWCampaignParameters = exports.removeGeosFromAllRedirectCampaigns = exports.addGeosToAllRedirectCampaigns = exports.TRAFFIC_SOURCE_ID_FLASH_AI = void 0;
6
+ exports.sendPostbacks = exports.createOWCampaign = exports.createDirectCampaign = exports.prepareOWCampaignParameters = exports.removeGeosFromAllRedirectCampaigns = exports.addGeosToAllRedirectCampaigns = exports.TRAFFIC_SOURCE_ID_FLASH_AI = void 0;
7
7
  const keitaro_service_1 = require("../network/keitaro/keitaro-service");
8
8
  const sleep = require('sleep-promise');
9
9
  const axios_1 = __importDefault(require("axios"));
@@ -310,27 +310,27 @@ let prepareOWCampaignParameters = (app) => {
310
310
  };
311
311
  };
312
312
  exports.prepareOWCampaignParameters = prepareOWCampaignParameters;
313
- function createBPStreamPartialPayload(app) {
314
- return {
315
- name: `Bot Protection`,
316
- type: "forced",
317
- action_type: "http",
318
- action_payload: "https://tomain.com",
319
- schema: "redirect",
320
- filter_or: true,
321
- collect_clicks: true,
322
- weight: 0,
323
- filters: [{
324
- name: "country",
325
- mode: "reject",
326
- payload: app.geos.split(" ")
327
- }, {
328
- name: "bot",
329
- mode: "accept",
330
- payload: null,
331
- }],
332
- };
333
- }
313
+ // function createBPStreamPartialPayload(app: IApp): Partial<IKeitaroStream> {
314
+ // return {
315
+ // name: `Bot Protection`,
316
+ // type: "forced",
317
+ // action_type: "http",
318
+ // action_payload: "https://tomain.com",
319
+ // schema: "redirect",
320
+ // filter_or: true,
321
+ // collect_clicks: true,
322
+ // weight: 0,
323
+ // filters: [{
324
+ // name: "country",
325
+ // mode: "reject",
326
+ // payload: app.geos.split(" ")
327
+ // }, {
328
+ // name: "bot",
329
+ // mode: "accept",
330
+ // payload: null,
331
+ // }],
332
+ // }
333
+ // }
334
334
  function createDefenceMainStreamPartialPayload(app) {
335
335
  return {
336
336
  name: "ALL",
@@ -343,24 +343,23 @@ function createDefenceMainStreamPartialPayload(app) {
343
343
  weight: 100,
344
344
  };
345
345
  }
346
- function createOWStreamPartialPayload(app) {
347
- return {
348
- name: `OW`,
349
- type: "regular",
350
- action_type: "http",
351
- action_payload: "https://bprtsk-controlpanel.com/ow?appId={appId}&clickId={uid}&countryCode={country}",
352
- schema: "redirect",
353
- filter_or: false,
354
- collect_clicks: true,
355
- weight: 100,
356
- filters: [{
357
- name: "country",
358
- mode: "accept",
359
- payload: app.geos.split(" ")
360
- }],
361
- };
362
- }
363
- exports.createOWStreamPartialPayload = createOWStreamPartialPayload;
346
+ // export function createOWStreamPartialPayload(app: IApp): Partial<IKeitaroStream> {
347
+ // return {
348
+ // name: `OW`,
349
+ // type: "regular",
350
+ // action_type: "http",
351
+ // action_payload: "https://bprtsk-controlpanel.com/ow?appId={appId}&clickId={uid}&countryCode={country}",
352
+ // schema: "redirect",
353
+ // filter_or: false,
354
+ // collect_clicks: true,
355
+ // weight: 100,
356
+ // filters: [{
357
+ // name: "country",
358
+ // mode: "accept",
359
+ // payload: app.geos.split(" ")
360
+ // }],
361
+ // }
362
+ // }
364
363
  async function createDirectCampaign(app) {
365
364
  let campaign = await keitaro_service_1.KeitaroService.cloneDCampaign(app);
366
365
  let stream = createDefenceMainStreamPartialPayload(app);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.1.59",
3
+ "version": "2.1.61",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
package/src/app/app.ts CHANGED
@@ -14,8 +14,7 @@ export interface IApp extends Document {
14
14
  pushesEnabled?: boolean
15
15
  policyUrl?: string
16
16
  type: AppType
17
- geos: string
18
- geo: string[] // new one, actual
17
+ geo: string[]
19
18
 
20
19
  onesignalAppId: string
21
20
  onesignalRestApiKey: string
@@ -25,7 +24,6 @@ export interface IApp extends Document {
25
24
 
26
25
  webInterfaceName: string
27
26
 
28
- generationOptions: IAppGenerationOptions
29
27
  keitaroData: IAppKeitaroData | null
30
28
  integrationVersion: IntegrationVersion
31
29
 
@@ -86,12 +84,15 @@ export const getPlatformName = (platform: EPlatform | undefined): string | false
86
84
  export interface IPlatformParams {
87
85
  enabled: boolean,
88
86
  geo: string[],
89
- customCampaignData?: IAppKeitaroData,
90
87
  trackingUrl?: string,
91
88
  adjustParams?: {
92
89
  appId: string,
93
90
  eventIds: IAdjustEventIds,
94
91
  },
92
+ direct: {
93
+ enabled: boolean,
94
+ keitaroData: IAppKeitaroData | boolean
95
+ },
95
96
  metricaParams?: {
96
97
  appId: number,
97
98
  postApiKey: string,
@@ -176,37 +177,12 @@ export enum IntegrationVersion {
176
177
  NONE = "MVVM",
177
178
  POLICY = "POLICY",
178
179
  OFFER_STUB = "OFFER_STUB",
179
- DIRECT = "DIRECT",
180
180
  WEB = "WEB",
181
181
  WEB_DIRECT = "WEB_DIRECT",
182
182
  BANNER = "BANNER",
183
183
  PWA = "PWA"
184
184
  }
185
185
 
186
- export interface IntegrationAlterations {
187
- networkTool: AlternativeNetworkTool, // Network
188
- logicType: AlternativeLogicType, // Logic
189
- navigation: AlternativeNavigation, // Navigation
190
- storageType: AlternativeStorageType, // Storage
191
- sourceType: AlternativeSourceType, // Source
192
- onBackPressed: AlternativeOnBackPressed,
193
- onActivityResult: AlternativeOnActivityResult,
194
- layoutType: AlternativeLayoutType,
195
- fullscreen: AlternativeFullscreen
196
- }
197
-
198
- export interface IAppGenerationOptions {
199
- splashName: string
200
- webViewName: string
201
- linkName: string,
202
- }
203
-
204
- export interface IDeveloperParams {
205
- name: string
206
- email: string
207
- organization: string
208
- }
209
-
210
186
  export interface IAppKeitaroData {
211
187
  trackingCampaignId: number
212
188
  trackingCampaignName: string
@@ -265,10 +241,6 @@ export const AppSchema = new Schema({
265
241
  enum: AppType,
266
242
  default: AppType.GAMBLING
267
243
  },
268
- geos: {
269
- type: String,
270
- required: true
271
- },
272
244
  geo: {
273
245
  type: [String]
274
246
  },
package/src/index.ts CHANGED
@@ -4,7 +4,7 @@ export { IOffer, IPartner, IOfferType } from "./offers/offer"
4
4
  export { IOffersSection, OffersSectionSchema, DefaultSectionId } from "./offers/section"
5
5
  export { IAppOffersSection, ISectionsList, SectionsListSchema, IOfferState } from "./offers/list"
6
6
 
7
- export { IntegrationAlterations, IAdjustEventIds, IntegrationVersion, IApp, AppSchema, PlugType, IAppKeitaroData, IExternalParams, IPlatformParams, EPlatform } from "./app/app"
7
+ export { IAdjustEventIds, IntegrationVersion, IApp, AppSchema, PlugType, IAppKeitaroData, IExternalParams, IPlatformParams, EPlatform } from "./app/app"
8
8
  export { IAppListItem } from "./app/app-list-item"
9
9
  export { AppType } from "./app/app-type"
10
10
  export { AlternativeLayoutType, AlternativeSourceType, AlternativeLogicType, AlternativeNetworkTool, AlternativeStorageType, AlternativeNavigation, AlternativeOnBackPressed, AlternativeOnActivityResult, IAppIntegration as IFlashIntegration } from "./app/app-integration"