@bprotsyk/aso-core 2.1.130 → 2.1.132
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.
|
@@ -16,14 +16,6 @@ export interface IGeoSyncSummary {
|
|
|
16
16
|
totalApps: number;
|
|
17
17
|
appsNeedingUpdate: number;
|
|
18
18
|
updates: IGeoUpdateData[];
|
|
19
|
-
appsNeedingEnable: number;
|
|
20
|
-
appsNeedingDisable: number;
|
|
21
|
-
enablementChecks: {
|
|
22
|
-
appId: number;
|
|
23
|
-
platform: string;
|
|
24
|
-
mustBeEnabled: boolean;
|
|
25
|
-
mustBeDisabled: boolean;
|
|
26
|
-
}[];
|
|
27
19
|
errors: string[];
|
|
28
20
|
}
|
|
29
21
|
/**
|
|
@@ -5,6 +5,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.KeitaroCLOGeosService = exports.getAppsNeedingGeoUpdate = exports.getAppGeoSyncDetails = exports.syncKeitaroCLOGeosWithApps = void 0;
|
|
7
7
|
const http_1 = __importDefault(require("../network/keitaro/traffle/http"));
|
|
8
|
+
// Хелпер для нормалізації списку гео
|
|
9
|
+
function normalizeGeos(geos) {
|
|
10
|
+
if (!Array.isArray(geos))
|
|
11
|
+
return [];
|
|
12
|
+
const unique = new Set();
|
|
13
|
+
for (const raw of geos) {
|
|
14
|
+
if (typeof raw !== 'string')
|
|
15
|
+
continue;
|
|
16
|
+
const val = raw.trim().toUpperCase();
|
|
17
|
+
if (!val)
|
|
18
|
+
continue;
|
|
19
|
+
unique.add(val);
|
|
20
|
+
}
|
|
21
|
+
return Array.from(unique).sort();
|
|
22
|
+
}
|
|
8
23
|
/**
|
|
9
24
|
* Отримує всі кампанії з Keitaro
|
|
10
25
|
*/
|
|
@@ -119,9 +134,6 @@ async function syncKeitaroCLOGeosWithApps(apps) {
|
|
|
119
134
|
totalApps: apps.length,
|
|
120
135
|
appsNeedingUpdate: 0,
|
|
121
136
|
updates: [],
|
|
122
|
-
appsNeedingEnable: 0,
|
|
123
|
-
appsNeedingDisable: 0,
|
|
124
|
-
enablementChecks: [],
|
|
125
137
|
errors: []
|
|
126
138
|
};
|
|
127
139
|
try {
|
|
@@ -194,42 +206,17 @@ async function syncKeitaroCLOGeosWithApps(apps) {
|
|
|
194
206
|
console.log(` Визначена платформа: ${platform}`);
|
|
195
207
|
// Отримуємо гео з CLO потоку кампанії
|
|
196
208
|
console.log(` Отримуємо гео з CLO потоку...`);
|
|
197
|
-
const
|
|
209
|
+
const keitaroGeosRaw = await getCLOGeosFromCampaign(campaign.id);
|
|
210
|
+
const keitaroGeos = normalizeGeos(keitaroGeosRaw);
|
|
198
211
|
console.log(` Keitaro CLO гео: ${keitaroGeos.join(', ')}`);
|
|
199
212
|
// Отримуємо гео з додатку для конкретної платформи
|
|
200
213
|
const platformData = app.platforms[platform];
|
|
201
|
-
const appGeos = platformData?.geo
|
|
214
|
+
const appGeos = normalizeGeos(platformData?.geo);
|
|
202
215
|
console.log(` App гео для платформи ${platform}: ${appGeos.join(', ')}`);
|
|
203
|
-
// Перевіряємо статус CLO потоку в Keitaro
|
|
204
|
-
const streams = await getStreamsByCampaignId(campaign.id);
|
|
205
|
-
const cloStream = streams.find(stream => stream.name === "CLO");
|
|
206
|
-
const keitaroCLOEnabled = cloStream?.state === 'active' || false;
|
|
207
|
-
console.log(` CLO потік в Keitaro: ${keitaroCLOEnabled ? 'включений' : 'вимкнений'}`);
|
|
208
|
-
// Перевіряємо чи включена платформа в додатку
|
|
209
|
-
const appPlatformEnabled = platformData?.enabled || false;
|
|
210
|
-
console.log(` Платформа ${platform} в додатку: ${appPlatformEnabled ? 'включена' : 'вимкнена'}`);
|
|
211
|
-
// Визначаємо чи потрібно включити/вимкнути додаток
|
|
212
|
-
const mustBeEnabled = keitaroCLOEnabled && !appPlatformEnabled;
|
|
213
|
-
const mustBeDisabled = !keitaroCLOEnabled && appPlatformEnabled;
|
|
214
|
-
if (mustBeEnabled) {
|
|
215
|
-
summary.appsNeedingEnable++;
|
|
216
|
-
console.log(` ✅ Потребує включення`);
|
|
217
|
-
}
|
|
218
|
-
else if (mustBeDisabled) {
|
|
219
|
-
summary.appsNeedingDisable++;
|
|
220
|
-
console.log(` ❌ Потребує вимкнення`);
|
|
221
|
-
}
|
|
222
|
-
// Додаємо до перевірок включення
|
|
223
|
-
summary.enablementChecks.push({
|
|
224
|
-
appId: parseInt(group),
|
|
225
|
-
platform: platform,
|
|
226
|
-
mustBeEnabled: mustBeEnabled,
|
|
227
|
-
mustBeDisabled: mustBeDisabled
|
|
228
|
-
});
|
|
229
216
|
// Порівнюємо гео
|
|
230
217
|
const missingGeos = keitaroGeos.filter(geo => !appGeos.includes(geo));
|
|
231
|
-
const
|
|
232
|
-
|
|
218
|
+
const extraGeos = appGeos.filter(geo => !keitaroGeos.includes(geo));
|
|
219
|
+
const needsUpdate = missingGeos.length > 0 || extraGeos.length > 0;
|
|
233
220
|
console.log(` Відсутні гео в app: ${missingGeos.join(', ')}`);
|
|
234
221
|
console.log(` Потребує оновлення: ${needsUpdate}`);
|
|
235
222
|
if (needsUpdate) {
|
|
@@ -246,6 +233,7 @@ async function syncKeitaroCLOGeosWithApps(apps) {
|
|
|
246
233
|
console.log(` Keitaro гео: ${keitaroGeos.join(', ')}`);
|
|
247
234
|
console.log(` App гео: ${appGeos.join(', ')}`);
|
|
248
235
|
console.log(` Відсутні гео в app: ${missingGeos.join(', ')}`);
|
|
236
|
+
console.log(` Зайві гео в app: ${extraGeos.join(', ')}`);
|
|
249
237
|
console.log(` Нові гео (з Keitaro): ${updateData.newGeos.join(', ')}`);
|
|
250
238
|
}
|
|
251
239
|
else {
|
|
@@ -258,7 +246,7 @@ async function syncKeitaroCLOGeosWithApps(apps) {
|
|
|
258
246
|
summary.errors.push(errorMsg);
|
|
259
247
|
}
|
|
260
248
|
}
|
|
261
|
-
console.log(`\nСинхронізація завершена. ${summary.appsNeedingUpdate} додатків потребують оновлення
|
|
249
|
+
console.log(`\nСинхронізація завершена. ${summary.appsNeedingUpdate} додатків потребують оновлення гео.`);
|
|
262
250
|
}
|
|
263
251
|
catch (error) {
|
|
264
252
|
const errorMsg = `Критична помилка синхронізації: ${error}`;
|
package/package.json
CHANGED
|
@@ -3,6 +3,19 @@ import { IKeitaroCampaign } from "./keitaro-campaign";
|
|
|
3
3
|
import { IKeitaroStream } from "./keitaro-stream";
|
|
4
4
|
import { IApp, IPlatformParams, EPlatform } from "../app/app";
|
|
5
5
|
|
|
6
|
+
// Хелпер для нормалізації списку гео
|
|
7
|
+
function normalizeGeos(geos: string[] | undefined | null): string[] {
|
|
8
|
+
if (!Array.isArray(geos)) return [];
|
|
9
|
+
const unique = new Set<string>();
|
|
10
|
+
for (const raw of geos) {
|
|
11
|
+
if (typeof raw !== 'string') continue;
|
|
12
|
+
const val = raw.trim().toUpperCase();
|
|
13
|
+
if (!val) continue;
|
|
14
|
+
unique.add(val);
|
|
15
|
+
}
|
|
16
|
+
return Array.from(unique).sort();
|
|
17
|
+
}
|
|
18
|
+
|
|
6
19
|
// Інтерфейс для результату синхронізації гео
|
|
7
20
|
export interface IGeoSyncResult {
|
|
8
21
|
appId: number;
|
|
@@ -25,18 +38,9 @@ export interface IGeoSyncSummary {
|
|
|
25
38
|
totalApps: number;
|
|
26
39
|
appsNeedingUpdate: number;
|
|
27
40
|
updates: IGeoUpdateData[];
|
|
28
|
-
appsNeedingEnable: number;
|
|
29
|
-
appsNeedingDisable: number;
|
|
30
|
-
enablementChecks: {
|
|
31
|
-
appId: number;
|
|
32
|
-
platform: string;
|
|
33
|
-
mustBeEnabled: boolean;
|
|
34
|
-
mustBeDisabled: boolean;
|
|
35
|
-
}[];
|
|
36
41
|
errors: string[];
|
|
37
42
|
}
|
|
38
43
|
|
|
39
|
-
|
|
40
44
|
/**
|
|
41
45
|
* Отримує всі кампанії з Keitaro
|
|
42
46
|
*/
|
|
@@ -155,9 +159,6 @@ export async function syncKeitaroCLOGeosWithApps(apps: IApp[]): Promise<IGeoSync
|
|
|
155
159
|
totalApps: apps.length,
|
|
156
160
|
appsNeedingUpdate: 0,
|
|
157
161
|
updates: [],
|
|
158
|
-
appsNeedingEnable: 0,
|
|
159
|
-
appsNeedingDisable: 0,
|
|
160
|
-
enablementChecks: [],
|
|
161
162
|
errors: []
|
|
162
163
|
};
|
|
163
164
|
|
|
@@ -254,48 +255,19 @@ export async function syncKeitaroCLOGeosWithApps(apps: IApp[]): Promise<IGeoSync
|
|
|
254
255
|
|
|
255
256
|
// Отримуємо гео з CLO потоку кампанії
|
|
256
257
|
console.log(` Отримуємо гео з CLO потоку...`);
|
|
257
|
-
const
|
|
258
|
+
const keitaroGeosRaw = await getCLOGeosFromCampaign(campaign.id);
|
|
259
|
+
const keitaroGeos = normalizeGeos(keitaroGeosRaw);
|
|
258
260
|
console.log(` Keitaro CLO гео: ${keitaroGeos.join(', ')}`);
|
|
259
261
|
|
|
260
262
|
// Отримуємо гео з додатку для конкретної платформи
|
|
261
263
|
const platformData = app.platforms[platform as EPlatform];
|
|
262
|
-
const appGeos = platformData?.geo
|
|
264
|
+
const appGeos = normalizeGeos(platformData?.geo);
|
|
263
265
|
console.log(` App гео для платформи ${platform}: ${appGeos.join(', ')}`);
|
|
264
266
|
|
|
265
|
-
// Перевіряємо статус CLO потоку в Keitaro
|
|
266
|
-
const streams = await getStreamsByCampaignId(campaign.id);
|
|
267
|
-
const cloStream = streams.find(stream => stream.name === "CLO");
|
|
268
|
-
const keitaroCLOEnabled = cloStream?.state === 'active' || false;
|
|
269
|
-
console.log(` CLO потік в Keitaro: ${keitaroCLOEnabled ? 'включений' : 'вимкнений'}`);
|
|
270
|
-
|
|
271
|
-
// Перевіряємо чи включена платформа в додатку
|
|
272
|
-
const appPlatformEnabled = platformData?.enabled || false;
|
|
273
|
-
console.log(` Платформа ${platform} в додатку: ${appPlatformEnabled ? 'включена' : 'вимкнена'}`);
|
|
274
|
-
|
|
275
|
-
// Визначаємо чи потрібно включити/вимкнути додаток
|
|
276
|
-
const mustBeEnabled = keitaroCLOEnabled && !appPlatformEnabled;
|
|
277
|
-
const mustBeDisabled = !keitaroCLOEnabled && appPlatformEnabled;
|
|
278
|
-
|
|
279
|
-
if (mustBeEnabled) {
|
|
280
|
-
summary.appsNeedingEnable++;
|
|
281
|
-
console.log(` ✅ Потребує включення`);
|
|
282
|
-
} else if (mustBeDisabled) {
|
|
283
|
-
summary.appsNeedingDisable++;
|
|
284
|
-
console.log(` ❌ Потребує вимкнення`);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Додаємо до перевірок включення
|
|
288
|
-
summary.enablementChecks.push({
|
|
289
|
-
appId: parseInt(group),
|
|
290
|
-
platform: platform,
|
|
291
|
-
mustBeEnabled: mustBeEnabled,
|
|
292
|
-
mustBeDisabled: mustBeDisabled
|
|
293
|
-
});
|
|
294
|
-
|
|
295
267
|
// Порівнюємо гео
|
|
296
268
|
const missingGeos = keitaroGeos.filter(geo => !appGeos.includes(geo));
|
|
297
|
-
const
|
|
298
|
-
|
|
269
|
+
const extraGeos = appGeos.filter(geo => !keitaroGeos.includes(geo));
|
|
270
|
+
const needsUpdate = missingGeos.length > 0 || extraGeos.length > 0;
|
|
299
271
|
|
|
300
272
|
console.log(` Відсутні гео в app: ${missingGeos.join(', ')}`);
|
|
301
273
|
console.log(` Потребує оновлення: ${needsUpdate}`);
|
|
@@ -317,6 +289,7 @@ export async function syncKeitaroCLOGeosWithApps(apps: IApp[]): Promise<IGeoSync
|
|
|
317
289
|
console.log(` Keitaro гео: ${keitaroGeos.join(', ')}`);
|
|
318
290
|
console.log(` App гео: ${appGeos.join(', ')}`);
|
|
319
291
|
console.log(` Відсутні гео в app: ${missingGeos.join(', ')}`);
|
|
292
|
+
console.log(` Зайві гео в app: ${extraGeos.join(', ')}`);
|
|
320
293
|
console.log(` Нові гео (з Keitaro): ${updateData.newGeos.join(', ')}`);
|
|
321
294
|
} else {
|
|
322
295
|
console.log(`✅ Додаток ${group} (${platform}) не потребує оновлення гео - гео ідентичні`);
|
|
@@ -329,7 +302,7 @@ export async function syncKeitaroCLOGeosWithApps(apps: IApp[]): Promise<IGeoSync
|
|
|
329
302
|
}
|
|
330
303
|
}
|
|
331
304
|
|
|
332
|
-
console.log(`\nСинхронізація завершена. ${summary.appsNeedingUpdate} додатків потребують оновлення
|
|
305
|
+
console.log(`\nСинхронізація завершена. ${summary.appsNeedingUpdate} додатків потребують оновлення гео.`);
|
|
333
306
|
|
|
334
307
|
} catch (error) {
|
|
335
308
|
const errorMsg = `Критична помилка синхронізації: ${error}`;
|
|
@@ -406,7 +379,6 @@ export async function getAppsNeedingGeoUpdate(apps: IApp[]): Promise<IGeoUpdateD
|
|
|
406
379
|
return summary.updates;
|
|
407
380
|
}
|
|
408
381
|
|
|
409
|
-
|
|
410
382
|
/**
|
|
411
383
|
* Експортуємо основні функції
|
|
412
384
|
*/
|