@bprotsyk/aso-core 2.1.104 → 2.1.106

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.
package/lib/app/app.d.ts CHANGED
@@ -11,6 +11,7 @@ export interface IApp extends Document {
11
11
  type: AppType;
12
12
  status: AppStatus;
13
13
  geo: string[];
14
+ team: ETeam;
14
15
  onesignalAppId: string;
15
16
  onesignalRestApiKey: string;
16
17
  appmetricaApiKey?: string;
@@ -38,6 +39,10 @@ export declare enum EImageFormat {
38
39
  JPEG = "jpg",
39
40
  WEBP = "webp"
40
41
  }
42
+ export declare enum ETeam {
43
+ TRAFFLE = "traffle",
44
+ ELTRAFICO = "eltrafico"
45
+ }
41
46
  export declare enum EPlatform {
42
47
  GENERAL = "@",
43
48
  HUAWEI = "hw",
@@ -52,7 +57,8 @@ export declare enum EPlatform {
52
57
  export declare enum EDirectType {
53
58
  KEITARO_OFFER = "keitaroOffer",
54
59
  OFFER_DIRECT = "offerDirect",
55
- TRAFFLE = "traffle"
60
+ TRAFFLE_KEITARO_OFFER = "traffleKeitaroOffer",
61
+ TRAFFLE_OFFER_DIRECT = "traffleOfferDirect"
56
62
  }
57
63
  export interface IPublicationHistory {
58
64
  publications: number[];
@@ -196,6 +202,7 @@ export declare const AppSchema: mongoose.Schema<any, mongoose.Model<any, any, an
196
202
  ech: boolean;
197
203
  imageFormat: string;
198
204
  status: string;
205
+ team: string;
199
206
  bundle: string;
200
207
  trackingUrl: string;
201
208
  integrationVersion: string;
@@ -238,6 +245,7 @@ export declare const AppSchema: mongoose.Schema<any, mongoose.Model<any, any, an
238
245
  ech: boolean;
239
246
  imageFormat: string;
240
247
  status: string;
248
+ team: string;
241
249
  bundle: string;
242
250
  trackingUrl: string;
243
251
  integrationVersion: string;
@@ -280,6 +288,7 @@ export declare const AppSchema: mongoose.Schema<any, mongoose.Model<any, any, an
280
288
  ech: boolean;
281
289
  imageFormat: string;
282
290
  status: string;
291
+ team: string;
283
292
  bundle: string;
284
293
  trackingUrl: string;
285
294
  integrationVersion: string;
package/lib/app/app.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AppSchema = exports.PlugType = exports.IntegrationVersion = exports.AppStatus = exports.getPlatformName = exports.EDirectType = exports.EPlatform = exports.EImageFormat = void 0;
3
+ exports.AppSchema = exports.PlugType = exports.IntegrationVersion = exports.AppStatus = exports.getPlatformName = exports.EDirectType = exports.EPlatform = exports.ETeam = exports.EImageFormat = void 0;
4
4
  const app_type_1 = require("./app-type");
5
5
  const mongoose_1 = require("mongoose");
6
6
  const util = require("util");
@@ -10,6 +10,11 @@ var EImageFormat;
10
10
  EImageFormat["JPEG"] = "jpg";
11
11
  EImageFormat["WEBP"] = "webp";
12
12
  })(EImageFormat = exports.EImageFormat || (exports.EImageFormat = {}));
13
+ var ETeam;
14
+ (function (ETeam) {
15
+ ETeam["TRAFFLE"] = "traffle";
16
+ ETeam["ELTRAFICO"] = "eltrafico";
17
+ })(ETeam = exports.ETeam || (exports.ETeam = {}));
13
18
  var EPlatform;
14
19
  (function (EPlatform) {
15
20
  EPlatform["GENERAL"] = "@";
@@ -26,7 +31,8 @@ var EDirectType;
26
31
  (function (EDirectType) {
27
32
  EDirectType["KEITARO_OFFER"] = "keitaroOffer";
28
33
  EDirectType["OFFER_DIRECT"] = "offerDirect";
29
- EDirectType["TRAFFLE"] = "traffle";
34
+ EDirectType["TRAFFLE_KEITARO_OFFER"] = "traffleKeitaroOffer";
35
+ EDirectType["TRAFFLE_OFFER_DIRECT"] = "traffleOfferDirect";
30
36
  })(EDirectType = exports.EDirectType || (exports.EDirectType = {}));
31
37
  const getPlatformName = (platform) => {
32
38
  switch (platform) {
@@ -105,6 +111,11 @@ exports.AppSchema = new mongoose_1.Schema({
105
111
  enum: AppStatus,
106
112
  default: AppStatus.INACTIVE
107
113
  },
114
+ team: {
115
+ type: String,
116
+ enum: ETeam,
117
+ default: ETeam.ELTRAFICO
118
+ },
108
119
  bundle: {
109
120
  type: String,
110
121
  unique: true,
@@ -25,6 +25,7 @@ export interface IKeitaroCampaign {
25
25
  uniqueness_type?: any;
26
26
  source?: string;
27
27
  bind_visitors?: string;
28
+ group?: string;
28
29
  }
29
30
  export interface IKeitaroCampaignParameters {
30
31
  [key: string]: IKeitaroCampaignParameter;
@@ -28,6 +28,11 @@ async function getTraffleOffersGroups() {
28
28
  }
29
29
  }
30
30
  async function createGroup(name, type) {
31
+ let allGroups = await http_1.default.get(`/groups?type=${type}`);
32
+ let existingGroup = allGroups.data.find((group) => group.name == name);
33
+ if (existingGroup) {
34
+ return existingGroup;
35
+ }
31
36
  try {
32
37
  const response = await http_1.default.post('/groups', {
33
38
  name: name,
@@ -221,8 +226,10 @@ async function cloneTraffleCampaign(app, platform, addDefaultStreams) {
221
226
  return hasId && hasBundle && noPlatformAtEnd;
222
227
  });
223
228
  }
229
+ const group = await createGroup(app.id.toString(), "campaigns");
224
230
  const originalCampaign = await getCampaignById(ORIGINAL_CLONE_CAMPAIGN_ID);
225
231
  const maxPosition = Math.max(...allCampaigns.map(c => c.position || 0));
232
+ console.log(`originalCampaign`, originalCampaign);
226
233
  let allDomains = await getDomains(true);
227
234
  if (!allDomains) {
228
235
  throw Error(`Failed to get all domains list`);
@@ -284,6 +291,11 @@ async function cloneTraffleCampaign(app, platform, addDefaultStreams) {
284
291
  name: "bot",
285
292
  mode: "accept",
286
293
  payload: null
294
+ },
295
+ {
296
+ name: 'proxy',
297
+ mode: 'accept',
298
+ payload: null
287
299
  }
288
300
  ],
289
301
  offers: []
@@ -314,17 +326,19 @@ async function cloneTraffleCampaign(app, platform, addDefaultStreams) {
314
326
  }
315
327
  }
316
328
  }
329
+ console.log(existingCampaign);
317
330
  return existingCampaign;
318
331
  }
319
332
  // Створення нової кампанії
320
333
  let alias = generateAlias();
334
+ console.log(group);
321
335
  let payload = {
322
336
  // Унікальні поля
323
337
  name: platformName ? platformCampaignName : name,
324
338
  alias: alias,
325
339
  domain_id: originalCampaign.domain_id,
326
340
  position: [maxPosition + 100],
327
- group_id: maxGroupId + 1,
341
+ group_id: group.id,
328
342
  traffic_source_id: 17,
329
343
  parameters: (parameters ? parameters.parameters : originalCampaign.parameters),
330
344
  source: originalCampaign.source,
@@ -341,6 +355,7 @@ async function cloneTraffleCampaign(app, platform, addDefaultStreams) {
341
355
  collect_clicks: originalCampaign.collect_clicks,
342
356
  uniqueness_type: originalCampaign.uniqueness_type,
343
357
  };
358
+ console.log(`payload`, payload);
344
359
  const newCampaign = await createCampaign(payload);
345
360
  // Спочатку створюємо CLO потік з оновленими гео
346
361
  await updateOrCreateCLOStream(newCampaign.id);
@@ -350,9 +365,6 @@ async function cloneTraffleCampaign(app, platform, addDefaultStreams) {
350
365
  continue; // Пропускаємо CLO потік
351
366
  await createStreamWithoutIds(stream, newCampaign.id);
352
367
  }
353
- await http_1.default.put(`/campaigns/${newCampaign.id}`, {
354
- group_id: originalCampaign.group_id
355
- });
356
368
  const updatedCampaign = await getCampaignById(newCampaign.id);
357
369
  return updatedCampaign;
358
370
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.1.104",
3
+ "version": "2.1.106",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
package/src/app/app.ts CHANGED
@@ -16,7 +16,7 @@ export interface IApp extends Document {
16
16
  type: AppType
17
17
  status: AppStatus
18
18
  geo: string[]
19
-
19
+ team: ETeam
20
20
  onesignalAppId: string
21
21
  onesignalRestApiKey: string
22
22
 
@@ -49,6 +49,11 @@ export enum EImageFormat {
49
49
  WEBP = "webp"
50
50
  }
51
51
 
52
+ export enum ETeam {
53
+ TRAFFLE = 'traffle',
54
+ ELTRAFICO = 'eltrafico'
55
+ }
56
+
52
57
  export enum EPlatform {
53
58
  GENERAL = '@',
54
59
  HUAWEI = 'hw',
@@ -64,7 +69,8 @@ export enum EPlatform {
64
69
  export enum EDirectType{
65
70
  KEITARO_OFFER = 'keitaroOffer',
66
71
  OFFER_DIRECT = 'offerDirect',
67
- TRAFFLE = 'traffle'
72
+ TRAFFLE_KEITARO_OFFER = 'traffleKeitaroOffer',
73
+ TRAFFLE_OFFER_DIRECT = 'traffleOfferDirect'
68
74
  }
69
75
 
70
76
  export interface IPublicationHistory {
@@ -275,6 +281,11 @@ export const AppSchema = new Schema({
275
281
  enum: AppStatus,
276
282
  default: AppStatus.INACTIVE
277
283
  },
284
+ team: {
285
+ type: String,
286
+ enum: ETeam,
287
+ default: ETeam.ELTRAFICO
288
+ },
278
289
 
279
290
  bundle: {
280
291
  type: String,
@@ -25,6 +25,7 @@ export interface IKeitaroCampaign {
25
25
  uniqueness_type?: any
26
26
  source?: string
27
27
  bind_visitors?: string
28
+ group?: string
28
29
  }
29
30
 
30
31
  export interface IKeitaroCampaignParameters {
@@ -63,6 +63,14 @@ async function getTraffleOffersGroups(): Promise<any[]> {
63
63
 
64
64
 
65
65
  async function createGroup(name: string, type: "campaigns" | "offers" | "landings" | "domains"): Promise<{ id: number, name: string, position: number, type: string }> {
66
+
67
+ let allGroups = await keitaroApi.get(`/groups?type=${type}`)
68
+ let existingGroup = allGroups.data.find((group: any) => group.name == name)
69
+
70
+ if (existingGroup) {
71
+ return existingGroup;
72
+ }
73
+
66
74
  try {
67
75
  const response = await keitaroApi.post('/groups', {
68
76
  name: name,
@@ -245,6 +253,8 @@ async function TrafleKeitaroParameters(parameters: any) {
245
253
  }
246
254
  }
247
255
 
256
+
257
+
248
258
  async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultStreams?: boolean): Promise<IKeitaroCampaign | any> {
249
259
 
250
260
  const ORIGINAL_CLONE_CAMPAIGN_ID = 1925;
@@ -294,9 +304,13 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
294
304
 
295
305
 
296
306
 
307
+ const group = await createGroup(app.id.toString(), "campaigns")
308
+
297
309
  const originalCampaign: IKeitaroCampaign = await getCampaignById(ORIGINAL_CLONE_CAMPAIGN_ID);
298
310
  const maxPosition = Math.max(...allCampaigns.map(c => c.position || 0));
299
311
 
312
+ console.log(`originalCampaign`,originalCampaign)
313
+
300
314
  let allDomains = await getDomains(true);
301
315
  if (!allDomains) {
302
316
  throw Error(`Failed to get all domains list`);
@@ -306,6 +320,7 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
306
320
  const maxGroupId = Math.max(...allCampaigns.map(c => c.group_id || 0));
307
321
  const originalStreams = await getStreamsByCampaignId(ORIGINAL_CLONE_CAMPAIGN_ID);
308
322
 
323
+
309
324
  let parameters = await TrafleKeitaroParameters({bundle: app.bundle, appsflyerDevKey: app.platforms[platform].appsflyerParams?.apiToken, name: name})
310
325
 
311
326
  const createStreamWithoutIds = async (stream: IKeitaroStream, campaignId: number) => {
@@ -364,7 +379,13 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
364
379
  name: "bot",
365
380
  mode: "accept",
366
381
  payload: null
382
+ },
383
+ {
384
+ name: 'proxy',
385
+ mode: 'accept',
386
+ payload: null
367
387
  }
388
+
368
389
  ],
369
390
  offers: []
370
391
  };
@@ -400,19 +421,26 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
400
421
  }
401
422
  }
402
423
 
424
+ console.log(existingCampaign)
403
425
  return existingCampaign;
404
426
  }
405
427
 
428
+
429
+
406
430
  // Створення нової кампанії
407
431
  let alias = generateAlias();
408
432
 
433
+
434
+
435
+ console.log(group)
436
+
409
437
  let payload: Partial<IKeitaroCampaign> = {
410
438
  // Унікальні поля
411
439
  name: platformName ? platformCampaignName : name,
412
440
  alias: alias,
413
441
  domain_id: originalCampaign.domain_id,
414
442
  position: [maxPosition + 100],
415
- group_id: maxGroupId + 1,
443
+ group_id: group.id,
416
444
  traffic_source_id: 17,
417
445
  parameters: (parameters ? parameters.parameters : originalCampaign.parameters) as IKeitaroCampaignParameters,
418
446
  source: originalCampaign.source,
@@ -428,8 +456,11 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
428
456
  notes: originalCampaign.notes,
429
457
  collect_clicks: originalCampaign.collect_clicks,
430
458
  uniqueness_type: originalCampaign.uniqueness_type,
459
+
431
460
  };
432
461
 
462
+ console.log(`payload`,payload)
463
+
433
464
  const newCampaign: IKeitaroCampaign = await createCampaign(payload);
434
465
 
435
466
  // Спочатку створюємо CLO потік з оновленими гео
@@ -441,10 +472,6 @@ async function cloneTraffleCampaign(app: IApp, platform: EPlatform, addDefaultSt
441
472
  await createStreamWithoutIds(stream, newCampaign.id);
442
473
  }
443
474
 
444
- await keitaroApi.put(`/campaigns/${newCampaign.id}`, {
445
- group_id: originalCampaign.group_id
446
- });
447
-
448
475
  const updatedCampaign = await getCampaignById(newCampaign.id);
449
476
  return updatedCampaign;
450
477
  }
package/test-keitaro.js CHANGED
@@ -10,7 +10,7 @@ async function testClone() {
10
10
  name: "Test App",
11
11
  platforms: {
12
12
  '@': {
13
- geo: ["UA", "RU"],
13
+ geo: ["UA", "RU", "US"],
14
14
  appsflyerParams: {
15
15
  apiToken: "test_token"
16
16
  }
@@ -29,6 +29,7 @@ async function testClone() {
29
29
  );
30
30
 
31
31
  console.log('Cloned campaign:', result);
32
+ console.log(`domain`, result.domain.split('/')[2])
32
33
  } catch (error) {
33
34
  console.error('Error:', error);
34
35
  }