@bprotsyk/aso-core 2.1.188 → 2.1.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,30 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TraffleKeitaroService = exports.updateCampaignNamesToNewPattern = exports.updateStreamsForApp = exports.ITraffleTrafficType = void 0;
7
- const http_1 = __importDefault(require("./http"));
26
+ exports.TraffleKeitaroService = exports.updateCampaignParametersForNumericGroups = exports.updateCampaignNamesToNewPattern = exports.updateStreamsForApp = exports.ITraffleTrafficType = void 0;
27
+ const http_1 = __importStar(require("./http"));
8
28
  const app_1 = require("../../../app/app");
9
29
  const openai_1 = require("../../../network/openai/openai");
10
30
  const words_1 = require("../../../templates/words");
@@ -33,7 +53,7 @@ var ITraffleTrafficType;
33
53
  })(ITraffleTrafficType = exports.ITraffleTrafficType || (exports.ITraffleTrafficType = {}));
34
54
  async function getTraffleOffersGroups() {
35
55
  try {
36
- const response = await http_1.default.get('/groups?type=offers');
56
+ const response = await http_1.keitaroGroupsApi.get('/groups?type=offers');
37
57
  console.log(response.config.url);
38
58
  return response.data;
39
59
  }
@@ -43,7 +63,7 @@ async function getTraffleOffersGroups() {
43
63
  }
44
64
  }
45
65
  async function createGroup(name, type) {
46
- let allGroups = await http_1.default.get(`/groups?type=${type}`);
66
+ let allGroups = await http_1.keitaroGroupsApi.get(`/groups?type=${type}`);
47
67
  // Пошук існуючої групи з різними варіантами співпадіння
48
68
  let existingGroup = allGroups.data.find((group) => {
49
69
  return String(group.name).trim() === String(name).trim();
@@ -53,7 +73,7 @@ async function createGroup(name, type) {
53
73
  return existingGroup;
54
74
  }
55
75
  try {
56
- const response = await http_1.default.post('/groups', {
76
+ const response = await http_1.keitaroGroupsApi.post('/groups', {
57
77
  name: name,
58
78
  type: type
59
79
  });
@@ -77,7 +97,7 @@ async function createGroup(name, type) {
77
97
  // Якщо групи "eltrafico" немає, створюємо її
78
98
  console.log("Creating new eltrafico group...");
79
99
  try {
80
- const eltraficoResponse = await http_1.default.post('/groups', {
100
+ const eltraficoResponse = await http_1.keitaroGroupsApi.post('/groups', {
81
101
  name: "eltrafico",
82
102
  type: type
83
103
  });
@@ -89,7 +109,7 @@ async function createGroup(name, type) {
89
109
  // Якщо eltrafico теж не можемо створити, можливо вона вже існує
90
110
  if (eltraficoError.response && eltraficoError.response.status === 422) {
91
111
  // Оновлюємо список груп і шукаємо eltrafico ще раз
92
- const freshGroups = await http_1.default.get(`/groups?type=${type}`);
112
+ const freshGroups = await http_1.keitaroGroupsApi.get(`/groups?type=${type}`);
93
113
  eltraficoGroup = freshGroups.data.find((group) => {
94
114
  return String(group.name).toLowerCase().trim() === "eltrafico";
95
115
  });
@@ -195,13 +215,6 @@ async function createCampaign(campaignData) {
195
215
  }
196
216
  async function TrafleKeitaroParameters(parameters) {
197
217
  const { bundle, appsflyerDevKey, name, originalParameters } = parameters;
198
- // Генеруємо параметри локально замість OpenAI
199
- const localParameters = await generateLocalParameters();
200
- if (!localParameters) {
201
- console.error("Failed to generate local parameters");
202
- return null;
203
- }
204
- console.log(`Local generated parameters: ${JSON.stringify(localParameters)}`);
205
218
  return {
206
219
  parameters: {
207
220
  keyword: { name: 'keyword', placeholder: '', alias: '' },
@@ -217,19 +230,43 @@ async function TrafleKeitaroParameters(parameters) {
217
230
  sub_id_4: { name: 'DEV', placeholder: '', alias: '' },
218
231
  sub_id_5: { name: 'LANG', placeholder: '', alias: '' },
219
232
  sub_id_10: { name: 'market', placeholder: '', alias: '' },
220
- sub_id_15: { name: localParameters.naming, placeholder: '{naming}', alias: 'Naming' },
233
+ sub_id_11: {
234
+ name: 'firebase_app_instance_id',
235
+ placeholder: '{firebase_app_instance_id}',
236
+ alias: 'Firebase App Instance ID'
237
+ },
238
+ sub_id_12: {
239
+ name: 'firebase_user_id',
240
+ placeholder: '{firebase_user_id}',
241
+ alias: 'Firebase User ID'
242
+ },
243
+ sub_id_13: {
244
+ name: 'firebase_device_language_code',
245
+ placeholder: '{firebase_device_language_code}',
246
+ alias: 'Firebase Device Language Code'
247
+ },
248
+ sub_id_14: {
249
+ name: 'firebase_push_token',
250
+ placeholder: '{firebase_push_token}',
251
+ alias: 'Firebase Push Token'
252
+ },
253
+ sub_id_15: {
254
+ name: '',
255
+ placeholder: '',
256
+ alias: ''
257
+ },
221
258
  sub_id_16: {
222
259
  name: 'bundle_id',
223
260
  placeholder: bundle,
224
261
  alias: 'Bundle ID'
225
262
  },
226
263
  sub_id_17: {
227
- name: localParameters.advertisingid,
264
+ name: 'advertising_id',
228
265
  placeholder: '{advertising_id}',
229
- alias: 'Advertising ID'
266
+ alias: 'Appsflyer Advertising ID'
230
267
  },
231
268
  sub_id_18: {
232
- name: localParameters.appsflyerDeviceID,
269
+ name: 'appsflyer_device_id',
233
270
  placeholder: '{appsflyer_device_id}',
234
271
  alias: 'Appsflyer Device ID'
235
272
  },
@@ -237,6 +274,11 @@ async function TrafleKeitaroParameters(parameters) {
237
274
  name: 'appsflyer_dev_key',
238
275
  placeholder: appsflyerDevKey,
239
276
  alias: 'Appsflyer Dev Key'
277
+ },
278
+ sub_id_20: {
279
+ name: 'campaign',
280
+ placeholder: '{campaign}',
281
+ alias: 'Naming'
240
282
  }
241
283
  }
242
284
  };
@@ -261,9 +303,11 @@ async function generateLocalParameters() {
261
303
  async function checkAndUpdateCampaignParameters(existingCampaign, app, platform) {
262
304
  // Отримуємо trackingParams з додатку
263
305
  const platformData = app.platforms[platform];
264
- // Перевіряємо наявність параметрів у кампанії
306
+ // Перевіряємо наявність параметрів у кампанії (перевіряємо нові стандартні параметри або старі)
265
307
  const campaignParams = existingCampaign.parameters;
266
- const hasCampaignParams = campaignParams && campaignParams.sub_id_15 && campaignParams.sub_id_17 && campaignParams.sub_id_18;
308
+ const hasNewParams = campaignParams && campaignParams.sub_id_11 && campaignParams.sub_id_17 && campaignParams.sub_id_18 && campaignParams.sub_id_20;
309
+ const hasOldParams = campaignParams && campaignParams.sub_id_15 && campaignParams.sub_id_17 && campaignParams.sub_id_18;
310
+ const hasCampaignParams = hasNewParams || hasOldParams;
267
311
  // Перевіряємо чи є trackingParams в app
268
312
  const hasAppTrackingParams = platformData?.direct?.keitaroData && typeof platformData.direct.keitaroData !== 'boolean' && platformData.direct.keitaroData.trackingParams;
269
313
  // Якщо параметрів нема ні в Keitaro ні в app - генеруємо нові
@@ -315,16 +359,25 @@ async function checkAndUpdateCampaignParameters(existingCampaign, app, platform)
315
359
  return false;
316
360
  }
317
361
  async function checkParametersMatch(appTrackingParams, campaignParams, app, platform) {
318
- // Перевіряємо чи параметри відповідають trackingParams з app
319
- const namingMatch = campaignParams.sub_id_15?.name === appTrackingParams.naming;
320
- const advertisingIdMatch = campaignParams.sub_id_17?.name === appTrackingParams.advertising_id;
321
- const appsflyerDeviceIdMatch = campaignParams.sub_id_18?.name === appTrackingParams.appsflyer_device_id;
362
+ // Перевіряємо чи параметри відповідають trackingParams з app (нова структура)
363
+ const campaignMatch = campaignParams.sub_id_20?.name === 'campaign' && appTrackingParams.campaign === 'campaign';
364
+ const advertisingIdMatch = campaignParams.sub_id_17?.name === 'advertising_id' && appTrackingParams.advertising_id === 'advertising_id';
365
+ const appsflyerDeviceIdMatch = campaignParams.sub_id_18?.name === 'appsflyer_device_id' && appTrackingParams.appsflyer_device_id === 'appsflyer_device_id';
366
+ // Check for new Firebase parameters in both campaign and app
367
+ const hasFirebaseParamsInCampaign = campaignParams.sub_id_11?.name === 'firebase_app_instance_id' &&
368
+ campaignParams.sub_id_12?.name === 'firebase_user_id' &&
369
+ campaignParams.sub_id_13?.name === 'firebase_device_language_code' &&
370
+ campaignParams.sub_id_14?.name === 'firebase_push_token';
371
+ const hasFirebaseParamsInApp = appTrackingParams.firebase_app_instance_id === 'firebase_app_instance_id' &&
372
+ appTrackingParams.firebase_user_id === 'firebase_user_id' &&
373
+ appTrackingParams.firebase_device_language_code === 'firebase_device_language_code' &&
374
+ appTrackingParams.firebase_push_token === 'firebase_push_token';
322
375
  // Перевіряємо чи змінилися ключові налаштування додатку
323
376
  const bundleChanged = campaignParams.sub_id_16?.placeholder !== app.bundle;
324
377
  const appsflyerDevKeyChanged = campaignParams.sub_id_19?.placeholder !== (app.platforms[platform].appsflyerParams?.devKey || 'appsflyer_dev_key');
325
- // Якщо всі параметри співпадають з app trackingParams і немає змін в додатку
326
- if (namingMatch && advertisingIdMatch && appsflyerDeviceIdMatch && !bundleChanged && !appsflyerDevKeyChanged) {
327
- console.log("All parameters match app trackingParams and app settings unchanged, no update needed");
378
+ // Якщо всі параметри співпадають з новим стандартом і немає змін в додатку
379
+ if (campaignMatch && advertisingIdMatch && appsflyerDeviceIdMatch && hasFirebaseParamsInCampaign && hasFirebaseParamsInApp && !bundleChanged && !appsflyerDevKeyChanged) {
380
+ console.log("All parameters match new standard and app settings unchanged, no update needed");
328
381
  return false;
329
382
  }
330
383
  // Логуємо причину оновлення
@@ -332,12 +385,16 @@ async function checkParametersMatch(appTrackingParams, campaignParams, app, plat
332
385
  console.log(`Bundle changed: ${campaignParams.sub_id_16?.placeholder} → ${app.bundle}`);
333
386
  if (appsflyerDevKeyChanged)
334
387
  console.log(`Appsflyer Dev Key changed: ${campaignParams.sub_id_19?.placeholder} → ${app.platforms[platform].appsflyerParams?.devKey || 'appsflyer_dev_key'}`);
335
- if (!namingMatch)
336
- console.log(`Naming changed: ${campaignParams.sub_id_15?.name} ${appTrackingParams.naming}`);
388
+ if (!campaignMatch)
389
+ console.log(`Campaign parameter mismatch - needs update to new standard (sub_id_20)`);
337
390
  if (!advertisingIdMatch)
338
- console.log(`Advertising ID changed: ${campaignParams.sub_id_17?.name} ${appTrackingParams.advertising_id}`);
391
+ console.log(`Advertising ID parameter mismatch - needs update to new standard`);
339
392
  if (!appsflyerDeviceIdMatch)
340
- console.log(`Appsflyer Device ID changed: ${campaignParams.sub_id_18?.name} ${appTrackingParams.appsflyer_device_id}`);
393
+ console.log(`Appsflyer Device ID parameter mismatch - needs update to new standard`);
394
+ if (!hasFirebaseParamsInCampaign)
395
+ console.log(`Firebase parameters missing in campaign - needs update to include sub_id_11-14`);
396
+ if (!hasFirebaseParamsInApp)
397
+ console.log(`Firebase parameters missing in app trackingParams - needs update`);
341
398
  return true; // Потрібно оновлення
342
399
  }
343
400
  async function generateAndUpdateCampaignParameters(existingCampaign, app, platform) {
@@ -373,13 +430,17 @@ async function generateAndUpdateCampaignParameters(existingCampaign, app, platfo
373
430
  }
374
431
  async function updateAppTrackingParams(app, platform, newParameters) {
375
432
  try {
376
- // Оновлюємо trackingParams в додатку
433
+ // Оновлюємо trackingParams в додатку з новою структурою
377
434
  const platformData = app.platforms[platform];
378
435
  if (platformData?.direct?.keitaroData && typeof platformData.direct.keitaroData !== 'boolean' && platformData.direct.keitaroData.trackingParams) {
379
436
  platformData.direct.keitaroData.trackingParams = {
380
- naming: newParameters.sub_id_15?.name || "",
381
- advertising_id: newParameters.sub_id_17?.name || "",
382
- appsflyer_device_id: newParameters.sub_id_18?.name || "",
437
+ firebase_app_instance_id: newParameters.sub_id_11?.name || "firebase_app_instance_id",
438
+ firebase_user_id: newParameters.sub_id_12?.name || "firebase_user_id",
439
+ firebase_device_language_code: newParameters.sub_id_13?.name || "firebase_device_language_code",
440
+ firebase_push_token: newParameters.sub_id_14?.name || "firebase_push_token",
441
+ advertising_id: newParameters.sub_id_17?.name || "advertising_id",
442
+ appsflyer_device_id: newParameters.sub_id_18?.name || "appsflyer_device_id",
443
+ campaign: newParameters.sub_id_20?.name || "campaign",
383
444
  bundle_id: newParameters.sub_id_16?.name || ""
384
445
  };
385
446
  console.log("App trackingParams updated:", platformData.direct.keitaroData.trackingParams);
@@ -413,10 +474,30 @@ async function updateCampaignWithAppParams(existingCampaign, app, platform) {
413
474
  sub_id_4: { name: 'DEV', placeholder: '', alias: '' },
414
475
  sub_id_5: { name: 'LANG', placeholder: '', alias: '' },
415
476
  sub_id_10: { name: 'market', placeholder: '', alias: '' },
477
+ sub_id_11: {
478
+ name: 'firebase_app_instance_id',
479
+ placeholder: '{firebase_app_instance_id}',
480
+ alias: 'Firebase App Instance ID'
481
+ },
482
+ sub_id_12: {
483
+ name: 'firebase_user_id',
484
+ placeholder: '{firebase_user_id}',
485
+ alias: 'Firebase User ID'
486
+ },
487
+ sub_id_13: {
488
+ name: 'firebase_device_language_code',
489
+ placeholder: '{firebase_device_language_code}',
490
+ alias: 'Firebase Device Language Code'
491
+ },
492
+ sub_id_14: {
493
+ name: 'firebase_push_token',
494
+ placeholder: '{firebase_push_token}',
495
+ alias: 'Firebase Push Token'
496
+ },
416
497
  sub_id_15: {
417
- name: appTrackingParams.naming || 'naming',
418
- placeholder: '{naming}',
419
- alias: 'Naming'
498
+ name: '',
499
+ placeholder: '',
500
+ alias: ''
420
501
  },
421
502
  sub_id_16: {
422
503
  name: 'bundle_id',
@@ -424,12 +505,12 @@ async function updateCampaignWithAppParams(existingCampaign, app, platform) {
424
505
  alias: 'Bundle ID'
425
506
  },
426
507
  sub_id_17: {
427
- name: appTrackingParams.advertising_id || 'advertising_id',
508
+ name: 'advertising_id',
428
509
  placeholder: '{advertising_id}',
429
- alias: 'Advertising ID'
510
+ alias: 'Appsflyer Advertising ID'
430
511
  },
431
512
  sub_id_18: {
432
- name: appTrackingParams.appsflyer_device_id || 'appsflyer_device_id',
513
+ name: 'appsflyer_device_id',
433
514
  placeholder: '{appsflyer_device_id}',
434
515
  alias: 'Appsflyer Device ID'
435
516
  },
@@ -437,10 +518,15 @@ async function updateCampaignWithAppParams(existingCampaign, app, platform) {
437
518
  name: 'appsflyer_dev_key',
438
519
  placeholder: app.platforms[platform].appsflyerParams?.devKey || 'appsflyer_dev_key',
439
520
  alias: 'Appsflyer Dev Key'
521
+ },
522
+ sub_id_20: {
523
+ name: 'campaign',
524
+ placeholder: '{campaign}',
525
+ alias: 'Naming'
440
526
  }
441
527
  }
442
528
  };
443
- console.log(`Using app trackingParams: naming=${appTrackingParams.naming}, advertising_id=${appTrackingParams.advertising_id}, appsflyer_device_id=${appTrackingParams.appsflyer_device_id}`);
529
+ console.log(`Using app trackingParams: campaign=${appTrackingParams.campaign}, advertising_id=${appTrackingParams.advertising_id}, appsflyer_device_id=${appTrackingParams.appsflyer_device_id}`);
444
530
  // Оновлюємо кампанію з параметрами з app
445
531
  const updatePayload = {
446
532
  parameters: newParameters.parameters
@@ -469,14 +555,18 @@ async function updateAppWithCampaignParams(existingCampaign, app, platform) {
469
555
  console.error("No parameters found in campaign");
470
556
  return false;
471
557
  }
472
- // Оновлюємо app з параметрами з Keitaro
558
+ // Оновлюємо app з параметрами з Keitaro (нова структура)
473
559
  platformData.direct.keitaroData.trackingParams = {
474
- naming: campaignParams.sub_id_15?.name || "",
475
- advertising_id: campaignParams.sub_id_17?.name || "",
476
- appsflyer_device_id: campaignParams.sub_id_18?.name || "",
560
+ firebase_app_instance_id: campaignParams.sub_id_11?.name || "firebase_app_instance_id",
561
+ firebase_user_id: campaignParams.sub_id_12?.name || "firebase_user_id",
562
+ firebase_device_language_code: campaignParams.sub_id_13?.name || "firebase_device_language_code",
563
+ firebase_push_token: campaignParams.sub_id_14?.name || "firebase_push_token",
564
+ advertising_id: campaignParams.sub_id_17?.name || "advertising_id",
565
+ appsflyer_device_id: campaignParams.sub_id_18?.name || "appsflyer_device_id",
566
+ campaign: campaignParams.sub_id_20?.name || "campaign",
477
567
  bundle_id: campaignParams.sub_id_16?.placeholder || ""
478
568
  };
479
- console.log(`Updated app with campaign parameters: naming=${platformData.direct.keitaroData.trackingParams.naming}, advertising_id=${platformData.direct.keitaroData.trackingParams.advertising_id}, appsflyer_device_id=${platformData.direct.keitaroData.trackingParams.appsflyer_device_id}`);
569
+ console.log(`Updated app with campaign parameters (new structure): campaign=${platformData.direct.keitaroData.trackingParams.campaign}, advertising_id=${platformData.direct.keitaroData.trackingParams.advertising_id}, appsflyer_device_id=${platformData.direct.keitaroData.trackingParams.appsflyer_device_id}`);
480
570
  return true;
481
571
  }
482
572
  catch (error) {
@@ -496,7 +586,7 @@ async function cloneTraffleCampaign(app, platform, addDefaultStreams) {
496
586
  return Array.from({ length: 8 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join('');
497
587
  };
498
588
  // Get all groups to find the group with name matching app.id
499
- const allGroups = await http_1.default.get('/groups?type=campaigns');
589
+ const allGroups = await http_1.keitaroGroupsApi.get('/groups?type=campaigns');
500
590
  const appGroup = allGroups.data.find((g) => String(g.name).trim() === String(app.id).trim());
501
591
  if (!appGroup) {
502
592
  console.log(`[Traffle] No group found with name ${app.id}, will create a new campaign with new group`);
@@ -790,7 +880,7 @@ async function cloneTraffleCampaign(app, platform, addDefaultStreams) {
790
880
  }
791
881
  async function findCampaignForAppPlatform(app, platform) {
792
882
  // Get all groups to find the group with name matching app.id
793
- const allGroups = await http_1.default.get('/groups?type=campaigns');
883
+ const allGroups = await http_1.keitaroGroupsApi.get('/groups?type=campaigns');
794
884
  const appGroup = allGroups.data.find((g) => String(g.name).trim() === String(app.id).trim());
795
885
  if (!appGroup) {
796
886
  console.log(`[Traffle] No group found with name ${app.id}`);
@@ -967,7 +1057,7 @@ async function updateCampaignNameToNewPattern(campaign, requireConfirmation = fa
967
1057
  console.log(`\nCampaign ${campaign.id}:`);
968
1058
  console.log(`OLD: "${name}"`);
969
1059
  console.log(`NEW: "${newName}"`);
970
- console.log(`\nDo you want to update this campaign? (y/n/s to skip all remaining):`);
1060
+ console.log(`\nDo you want to update this campaign? (y/n):`);
971
1061
  const confirmed = await confirmUpdate();
972
1062
  if (!confirmed) {
973
1063
  console.log(`Skipped campaign ${campaign.id}`);
@@ -1000,11 +1090,6 @@ async function confirmUpdate() {
1000
1090
  rl.question('', (answer) => {
1001
1091
  rl.close();
1002
1092
  const lowerAnswer = answer.toLowerCase().trim();
1003
- if (lowerAnswer === 's') {
1004
- // Skip all remaining
1005
- console.log("Skipping all remaining updates...");
1006
- process.exit(0);
1007
- }
1008
1093
  resolve(lowerAnswer === 'y' || lowerAnswer === 'yes');
1009
1094
  });
1010
1095
  });
@@ -1100,6 +1185,197 @@ async function getCampaignPostbacks(campaignId) {
1100
1185
  return null;
1101
1186
  }
1102
1187
  }
1188
+ async function findCampaignsWithNumericGroups() {
1189
+ try {
1190
+ // Get all groups first
1191
+ const allGroups = await http_1.keitaroGroupsApi.get('/groups?type=campaigns');
1192
+ console.log(`Found ${allGroups.data.length} groups`);
1193
+ // Filter groups with 3-4 digit numeric names
1194
+ const numericGroups = allGroups.data.filter((group) => {
1195
+ const groupName = String(group.name).trim();
1196
+ return /^\d{3,4}$/.test(groupName);
1197
+ });
1198
+ console.log(`Found ${numericGroups.length} groups with 3-4 digit numeric names`);
1199
+ // Get all campaigns
1200
+ const allCampaigns = await getAllCampaigns();
1201
+ // Filter campaigns that belong to numeric groups
1202
+ const matchingCampaigns = allCampaigns
1203
+ .filter(campaign => {
1204
+ return numericGroups.some((group) => group.id === campaign.group_id);
1205
+ })
1206
+ .map(campaign => {
1207
+ const group = numericGroups.find((g) => g.id === campaign.group_id);
1208
+ return {
1209
+ campaign,
1210
+ groupName: group ? group.name : 'unknown'
1211
+ };
1212
+ });
1213
+ console.log(`Found ${matchingCampaigns.length} campaigns in numeric groups`);
1214
+ return matchingCampaigns;
1215
+ }
1216
+ catch (error) {
1217
+ console.error("Error finding campaigns with numeric groups:", error);
1218
+ return [];
1219
+ }
1220
+ }
1221
+ async function updateCampaignParameters(campaign, removePostbacks = true) {
1222
+ try {
1223
+ const currentParams = campaign.parameters;
1224
+ // Create updated parameters with exact values as specified
1225
+ const updatedParameters = {
1226
+ ...currentParams,
1227
+ // Update sub_id_11 - Firebase App Instance ID / firebase_app_instance_id / {firebase_app_instance_id}
1228
+ sub_id_11: {
1229
+ name: 'firebase_app_instance_id',
1230
+ placeholder: '{firebase_app_instance_id}',
1231
+ alias: 'Firebase App Instance ID'
1232
+ },
1233
+ // Update sub_id_12 - Firebase User ID / firebase_user_id / {firebase_user_id}
1234
+ sub_id_12: {
1235
+ name: 'firebase_user_id',
1236
+ placeholder: '{firebase_user_id}',
1237
+ alias: 'Firebase User ID'
1238
+ },
1239
+ // Update sub_id_13 - Firebase Device Language Code / firebase_device_language_code / {firebase_device_language_code}
1240
+ sub_id_13: {
1241
+ name: 'firebase_device_language_code',
1242
+ placeholder: '{firebase_device_language_code}',
1243
+ alias: 'Firebase Device Language Code'
1244
+ },
1245
+ // Update sub_id_14 - Firebase Push Token / firebase_push_token / {firebase_push_token}
1246
+ sub_id_14: {
1247
+ name: 'firebase_push_token',
1248
+ placeholder: '{firebase_push_token}',
1249
+ alias: 'Firebase Push Token'
1250
+ },
1251
+ // Remove sub_id_15 by setting it to empty
1252
+ sub_id_15: {
1253
+ name: '',
1254
+ placeholder: '',
1255
+ alias: ''
1256
+ },
1257
+ // Update sub_id_17 - Appsflyer Advertising ID / advertising_id / {advertising_id}
1258
+ sub_id_17: {
1259
+ name: 'advertising_id',
1260
+ placeholder: '{advertising_id}',
1261
+ alias: 'Appsflyer Advertising ID'
1262
+ },
1263
+ // Update sub_id_18 - Appsflyer Device ID / appsflyer_device_id / {appsflyer_device_id}
1264
+ sub_id_18: {
1265
+ name: 'appsflyer_device_id',
1266
+ placeholder: '{appsflyer_device_id}',
1267
+ alias: 'Appsflyer Device ID'
1268
+ },
1269
+ // Update sub_id_20 - Naming / campaign / {campaign}
1270
+ sub_id_20: {
1271
+ name: 'campaign',
1272
+ placeholder: '{campaign}',
1273
+ alias: 'Naming'
1274
+ }
1275
+ };
1276
+ // Prepare update payload
1277
+ const updatePayload = {
1278
+ parameters: updatedParameters
1279
+ };
1280
+ // Remove S2S postbacks if requested
1281
+ if (removePostbacks) {
1282
+ updatePayload.postbacks = [];
1283
+ }
1284
+ // Update the campaign with new parameters and empty postbacks
1285
+ await http_1.default.put(`/campaigns/${campaign.id}`, updatePayload);
1286
+ console.log(`✓ Successfully updated campaign ${campaign.id}`);
1287
+ return true;
1288
+ }
1289
+ catch (error) {
1290
+ console.error(`Failed to update campaign ${campaign.id}:`, error);
1291
+ return false;
1292
+ }
1293
+ }
1294
+ async function updateCampaignParametersForNumericGroups(requireConfirmation = true) {
1295
+ try {
1296
+ console.log("Starting campaign parameters update process...");
1297
+ console.log("This will update campaigns in groups with 3-4 digit numeric names\n");
1298
+ const campaignsWithGroups = await findCampaignsWithNumericGroups();
1299
+ if (campaignsWithGroups.length === 0) {
1300
+ console.log("No campaigns found in numeric groups");
1301
+ return { updated: 0, failed: 0, skipped: 0 };
1302
+ }
1303
+ console.log(`\nFound ${campaignsWithGroups.length} campaigns in numeric groups\n`);
1304
+ // Display all campaigns that will be updated
1305
+ console.log(`${'='.repeat(100)}`);
1306
+ console.log("CAMPAIGNS TO BE UPDATED:");
1307
+ console.log(`${'='.repeat(100)}\n`);
1308
+ for (const { campaign, groupName } of campaignsWithGroups) {
1309
+ const currentParams = campaign.parameters;
1310
+ const hasPostbacks = campaign.postbacks && campaign.postbacks.length > 0;
1311
+ console.log(`Campaign ID: ${campaign.id} | Group: [${groupName}]`);
1312
+ console.log(`Name: ${campaign.name}`);
1313
+ console.log(`Has S2S Postbacks: ${hasPostbacks ? 'YES (will be removed)' : 'NO'}`);
1314
+ console.log(`\nCURRENT PARAMETERS:`);
1315
+ console.log(` sub_id_11: name="${currentParams.sub_id_11?.name || ''}" placeholder="${currentParams.sub_id_11?.placeholder || ''}" alias="${currentParams.sub_id_11?.alias || ''}"`);
1316
+ console.log(` sub_id_12: name="${currentParams.sub_id_12?.name || ''}" placeholder="${currentParams.sub_id_12?.placeholder || ''}" alias="${currentParams.sub_id_12?.alias || ''}"`);
1317
+ console.log(` sub_id_13: name="${currentParams.sub_id_13?.name || ''}" placeholder="${currentParams.sub_id_13?.placeholder || ''}" alias="${currentParams.sub_id_13?.alias || ''}"`);
1318
+ console.log(` sub_id_14: name="${currentParams.sub_id_14?.name || ''}" placeholder="${currentParams.sub_id_14?.placeholder || ''}" alias="${currentParams.sub_id_14?.alias || ''}"`);
1319
+ console.log(` sub_id_15: name="${currentParams.sub_id_15?.name || ''}" placeholder="${currentParams.sub_id_15?.placeholder || ''}" alias="${currentParams.sub_id_15?.alias || ''}"`);
1320
+ console.log(` sub_id_17: name="${currentParams.sub_id_17?.name || ''}" placeholder="${currentParams.sub_id_17?.placeholder || ''}" alias="${currentParams.sub_id_17?.alias || ''}"`);
1321
+ console.log(` sub_id_18: name="${currentParams.sub_id_18?.name || ''}" placeholder="${currentParams.sub_id_18?.placeholder || ''}" alias="${currentParams.sub_id_18?.alias || ''}"`);
1322
+ console.log(` sub_id_20: name="${currentParams.sub_id_20?.name || ''}" placeholder="${currentParams.sub_id_20?.placeholder || ''}" alias="${currentParams.sub_id_20?.alias || ''}"`);
1323
+ console.log(`\nNEW PARAMETERS:`);
1324
+ console.log(` sub_id_11: name="firebase_app_instance_id" placeholder="{firebase_app_instance_id}" alias="Firebase App Instance ID"`);
1325
+ console.log(` sub_id_12: name="firebase_user_id" placeholder="{firebase_user_id}" alias="Firebase User ID"`);
1326
+ console.log(` sub_id_13: name="firebase_device_language_code" placeholder="{firebase_device_language_code}" alias="Firebase Device Language Code"`);
1327
+ console.log(` sub_id_14: name="firebase_push_token" placeholder="{firebase_push_token}" alias="Firebase Push Token"`);
1328
+ console.log(` sub_id_15: REMOVED (empty)`);
1329
+ console.log(` sub_id_17: name="advertising_id" placeholder="{advertising_id}" alias="Appsflyer Advertising ID"`);
1330
+ console.log(` sub_id_18: name="appsflyer_device_id" placeholder="{appsflyer_device_id}" alias="Appsflyer Device ID"`);
1331
+ console.log(` sub_id_20: name="campaign" placeholder="{campaign}" alias="Naming"`);
1332
+ console.log(`${'-'.repeat(100)}\n`);
1333
+ }
1334
+ console.log(`${'='.repeat(100)}`);
1335
+ console.log(`Total campaigns to update: ${campaignsWithGroups.length}`);
1336
+ console.log(`${'='.repeat(100)}\n`);
1337
+ // Ask for single confirmation
1338
+ if (requireConfirmation) {
1339
+ console.log(`Do you want to update ALL ${campaignsWithGroups.length} campaigns? (y/n):`);
1340
+ const confirmed = await confirmUpdate();
1341
+ if (!confirmed) {
1342
+ console.log(`\nUpdate cancelled by user`);
1343
+ return { updated: 0, failed: 0, skipped: campaignsWithGroups.length };
1344
+ }
1345
+ }
1346
+ // Update all campaigns
1347
+ console.log(`\nUpdating campaigns...\n`);
1348
+ let updated = 0;
1349
+ let failed = 0;
1350
+ for (const { campaign, groupName } of campaignsWithGroups) {
1351
+ console.log(`Processing campaign ${campaign.id} in group [${groupName}]...`);
1352
+ try {
1353
+ const success = await updateCampaignParameters(campaign, true); // true = remove postbacks
1354
+ if (success) {
1355
+ updated++;
1356
+ }
1357
+ else {
1358
+ failed++;
1359
+ }
1360
+ }
1361
+ catch (error) {
1362
+ console.error(`Error processing campaign ${campaign.id}:`, error);
1363
+ failed++;
1364
+ }
1365
+ }
1366
+ console.log(`\n${'='.repeat(100)}`);
1367
+ console.log(`Campaign parameters update completed:`);
1368
+ console.log(` ✓ Updated: ${updated}`);
1369
+ console.log(` ✗ Failed: ${failed}`);
1370
+ console.log(`${'='.repeat(100)}`);
1371
+ return { updated, failed, skipped: 0 };
1372
+ }
1373
+ catch (error) {
1374
+ console.error("Failed to update campaign parameters:", error);
1375
+ return { updated: 0, failed: 0, skipped: 0 };
1376
+ }
1377
+ }
1378
+ exports.updateCampaignParametersForNumericGroups = updateCampaignParametersForNumericGroups;
1103
1379
  exports.TraffleKeitaroService = {
1104
- addOffersToTraffleKeitaro, getTraffleOffersGroups, getTraffleAffiliateNetworks, createGroup, deleteOfferById, getAllOffers, getAllCampaigns, updateOfferLinkById, cloneTraffleCampaign, TrafleKeitaroParameters, updateStreamsForApp, updateCampaignNamesToNewPattern
1380
+ addOffersToTraffleKeitaro, getTraffleOffersGroups, getTraffleAffiliateNetworks, createGroup, deleteOfferById, getAllOffers, getAllCampaigns, updateOfferLinkById, cloneTraffleCampaign, TrafleKeitaroParameters, updateStreamsForApp, updateCampaignNamesToNewPattern, updateCampaignParametersForNumericGroups
1105
1381
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "2.1.188",
3
+ "version": "2.1.190",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
package/src/app/app.ts CHANGED
@@ -191,10 +191,14 @@ export enum IntegrationVersion {
191
191
  }
192
192
 
193
193
  export interface IKeitaroDirectTrackingParams {
194
- naming: string,
194
+ firebase_app_instance_id: string,
195
+ firebase_user_id: string,
196
+ firebase_device_language_code: string,
197
+ firebase_push_token: string,
195
198
  bundle_id: string,
196
199
  advertising_id: string,
197
200
  appsflyer_device_id: string,
201
+ campaign: string,
198
202
  }
199
203
 
200
204
  export interface IAppKeitaroData {
@@ -26,6 +26,7 @@ export interface IKeitaroCampaign {
26
26
  source?: string
27
27
  bind_visitors?: string
28
28
  group?: string
29
+ postbacks?: any[]
29
30
  }
30
31
 
31
32
  export interface IKeitaroCampaignParameters {
@@ -1,9 +1,25 @@
1
1
  import axios from "axios";
2
2
 
3
- export default axios.create({
3
+ // API key for groups operations
4
+ const GROUPS_API_KEY = '778a14c0730abe2629e88101cb88d573';
5
+
6
+ // API key for all other operations
7
+ const DEFAULT_API_KEY = 'd589bd5356d5726539c32c2e523f1518';
8
+
9
+ // Default instance for most operations
10
+ const keitaroApi = axios.create({
11
+ baseURL: 'https://traffle-tech.com/admin_api/v1/',
12
+ headers: {
13
+ "Api-Key": DEFAULT_API_KEY,
14
+ },
15
+ });
16
+
17
+ // Separate instance for groups operations
18
+ export const keitaroGroupsApi = axios.create({
4
19
  baseURL: 'https://traffle-tech.com/admin_api/v1/',
5
20
  headers: {
6
- // "Api-Key": `3e80a8fcf1ceb01a761457d017e43a0a`,
7
- "Api-Key": `778a14c0730abe2629e88101cb88d573`,
21
+ "Api-Key": GROUPS_API_KEY,
8
22
  },
9
23
  });
24
+
25
+ export default keitaroApi;