@bprotsyk/aso-core 2.1.58 → 2.1.60

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.
@@ -337,6 +337,111 @@ async function cloneOWCampaign(app: IApp, platform?: EPlatform): Promise<IKeitar
337
337
  return updatedCampaign;
338
338
  }
339
339
 
340
+ async function cloneDirectCampaign(app: IApp, platform?: EPlatform): Promise<IKeitaroCampaign | any> {
341
+ let name = `#${app.id} [✦]`
342
+ let platformName = platform ? getPlatformName(platform) : null;
343
+ const platformCampaignName = `#${app.id} [✦] (${platformName})`;
344
+ const generateAlias = () => {
345
+ const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
346
+ return Array.from(
347
+ { length: 8 },
348
+ () => chars.charAt(Math.floor(Math.random() * chars.length))
349
+ ).join('');
350
+ };
351
+
352
+ let allCampaigns = await getAllCampaigns();
353
+
354
+ let matchingCampaign: IKeitaroCampaign[] = [];
355
+
356
+ if (platform && platform !== EPlatform.GENERAL) {
357
+ // Шукаємо кампанію з платформою
358
+ matchingCampaign = allCampaigns.filter((c) =>
359
+ c.name.includes(`#${app.id}`) &&
360
+ c.name.includes(`[✦]`) &&
361
+ c.name.includes(`(${platformName})`)
362
+ );
363
+ } else {
364
+ // Шукаємо кампанію без платформи або з суфіксом
365
+ matchingCampaign = allCampaigns.filter((c) =>
366
+ c.name.includes(`#${app.id}`) &&
367
+ c.name.includes(`[✦]`) &&
368
+ !c.name.includes('(')
369
+ );
370
+ }
371
+
372
+ if (matchingCampaign.length > 0) return matchingCampaign[0];
373
+
374
+ const originalCampaign: IKeitaroCampaign = await getCampaignById(3175);
375
+ const maxPosition = Math.max(...allCampaigns.map(c => c.position || 0));
376
+ const originalStreams = await getStreamsByCampaignId(3175);
377
+
378
+ let allDomains = await KeitaroService.getDomains(true);
379
+ if (!allDomains) {
380
+ throw Error(`Failed to get all domains list`);
381
+ }
382
+
383
+ const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
384
+ const maxGroupId = Math.max(...allCampaigns.map(c => c.group_id || 0));
385
+
386
+ let alias = generateAlias();
387
+
388
+ let payload: Partial<IKeitaroCampaign> = {
389
+ // Унікальні поля
390
+ name: platformName ? platformCampaignName : name,
391
+ alias: alias,
392
+ domain_id: domain.id,
393
+ position: [maxPosition + 100],
394
+ group_id: maxGroupId + 1,
395
+ traffic_source_id: TRAFFIC_SOURCE_ID_FLASH_AI,
396
+ parameters: prepareOWCampaignParameters(app),
397
+
398
+ // Неунікальні поля з оригінальної кампанії
399
+ type: originalCampaign.type,
400
+ state: originalCampaign.state,
401
+ cost_type: originalCampaign.cost_type,
402
+ cost_value: originalCampaign.cost_value,
403
+ cost_currency: originalCampaign.cost_currency,
404
+ uniqueness_period: originalCampaign.uniqueness_period,
405
+ cookies_ttl: originalCampaign.cookies_ttl,
406
+ notes: originalCampaign.notes,
407
+ collect_clicks: originalCampaign.collect_clicks,
408
+ uniqueness_type: originalCampaign.uniqueness_type,
409
+ };
410
+
411
+ const newCampaign: IKeitaroCampaign = await createCampaign(payload);
412
+
413
+ for (const stream of originalStreams) {
414
+ await keitaroApi.post('streams', {
415
+ name: stream.name,
416
+ campaign_id: newCampaign.id,
417
+ schema: stream.schema,
418
+ type: stream.type,
419
+ action_type: stream.action_type,
420
+ weight: stream.weight,
421
+ offers: stream.offers.map((offer) => ({
422
+ offer_id: offer.offer_id,
423
+ share: offer.share,
424
+ state: offer.state
425
+ })),
426
+ filters: stream.filters.map((filter) => ({
427
+ name: filter.name,
428
+ mode: filter.mode,
429
+ payload: filter.payload
430
+ })),
431
+ position: stream.position,
432
+ state: stream.state
433
+ });
434
+ }
435
+ await keitaroApi.put(`/campaigns/${newCampaign.id}`, {
436
+ group_id: originalCampaign.group_id
437
+ });
438
+
439
+ const updatedCampaign = await getCampaignById(newCampaign.id);
440
+
441
+ return updatedCampaign;
442
+
443
+ }
444
+
340
445
  async function cloneDCampaign(app: IApp): Promise<IKeitaroCampaign> {
341
446
  let name = `D #${app.id} (${app.bundle})`
342
447
 
@@ -451,5 +556,5 @@ export const KeitaroService = {
451
556
  getStreamsByCampaignId, updateCampaign, getAllCampaigns, getAllOffers, cloneStreams, addOffersToKeitaro, getOfferByKeitaroId, getDomains, createCampaign, getCampaignById, upsertStreamToCampaign, cloneOWCampaign,
452
557
  updateOffer, changeCampaignsGroup, getProfitForTimeRange, getClicks,
453
558
  // getProfitForTodayAndYesterday,
454
- cloneDCampaign, findKeitaroOffers, fixBrokenClickCosts
559
+ cloneDCampaign, findKeitaroOffers, fixBrokenClickCosts, cloneDirectCampaign
455
560
  }
package/src/panel/user.ts CHANGED
@@ -14,7 +14,9 @@ export enum PanelUserAccessScope {
14
14
  OFFERWALL_RO,
15
15
  OFFERWALL_RW,
16
16
 
17
- ASO_LOGS
17
+ ASO_LOGS,
18
+
19
+ MANAGER
18
20
  }
19
21
 
20
22
  export interface IPanelUser extends Document {
package/test-keitaro.js CHANGED
@@ -2,7 +2,7 @@ const { KeitaroService } = require('./lib/network/keitaro/keitaro-service');
2
2
 
3
3
  async function testClone() {
4
4
  try {
5
- const result = await KeitaroService.cloneOWCampaign({ id: 999 }, 'sm' );
5
+ const result = await KeitaroService.cloneDirectCampaign({ id: 901} );
6
6
  console.log('Cloned campaign:', result);
7
7
  } catch (error) {
8
8
  console.error('Error:', error);