@bprotsyk/aso-core 2.1.51 → 2.1.53
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/keitaro/keitaro-campaign.d.ts +5 -0
- package/lib/network/keitaro/keitaro-service.d.ts +1 -1
- package/lib/network/keitaro/keitaro-service.js +61 -30
- package/lib/utils/keitaro-utils.d.ts +1 -1
- package/lib/utils/keitaro-utils.js +2 -2
- package/package.json +1 -1
- package/src/keitaro/keitaro-campaign.ts +6 -0
- package/src/network/keitaro/keitaro-service.ts +72 -21
- package/src/utils/keitaro-utils.ts +2 -2
- package/test-keitaro.js +12 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export interface IKeitaroCampaign {
|
|
2
|
+
position: number[] | any;
|
|
2
3
|
id: number;
|
|
3
4
|
alias: string;
|
|
4
5
|
name: string;
|
|
@@ -18,6 +19,10 @@ export interface IKeitaroCampaign {
|
|
|
18
19
|
uniqueness_use_cookies: boolean;
|
|
19
20
|
traffic_loss: number;
|
|
20
21
|
parameters: IKeitaroCampaignParameters;
|
|
22
|
+
uniqueness_period?: any;
|
|
23
|
+
notes?: any;
|
|
24
|
+
collect_clicks?: any;
|
|
25
|
+
uniqueness_type?: any;
|
|
21
26
|
}
|
|
22
27
|
export interface IKeitaroCampaignParameters {
|
|
23
28
|
[key: string]: IKeitaroCampaignParameter;
|
|
@@ -22,7 +22,7 @@ declare function addOffersToKeitaro(offers: IOffer[], affiliateId: number, links
|
|
|
22
22
|
declare function createCampaign(campaignData: Partial<IKeitaroCampaign>): Promise<IKeitaroCampaign>;
|
|
23
23
|
declare function getCampaignById(id: number): Promise<IKeitaroCampaign>;
|
|
24
24
|
export declare function upsertStreamToCampaign(campaign: IKeitaroCampaign, stream: Partial<IKeitaroStream>): Promise<void>;
|
|
25
|
-
declare function cloneOWCampaign(app: IApp): Promise<IKeitaroCampaign>;
|
|
25
|
+
declare function cloneOWCampaign(app: IApp): Promise<IKeitaroCampaign | any>;
|
|
26
26
|
declare function cloneDCampaign(app: IApp): Promise<IKeitaroCampaign>;
|
|
27
27
|
declare function changeCampaignsGroup(fromId: number, toId: number, exceptForCampaignIds: number[], onlyForCampaignIds?: number[]): Promise<void>;
|
|
28
28
|
declare function getDomains(onlyActive?: boolean): Promise<IKeitaroDomain[]>;
|
|
@@ -192,39 +192,70 @@ async function upsertStreamToCampaign(campaign, stream) {
|
|
|
192
192
|
}
|
|
193
193
|
exports.upsertStreamToCampaign = upsertStreamToCampaign;
|
|
194
194
|
async function cloneOWCampaign(app) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
|
|
211
|
-
let payload = {
|
|
212
|
-
name: name,
|
|
213
|
-
traffic_source_id: keitaro_utils_1.TRAFFIC_SOURCE_ID_FLASH_AI,
|
|
214
|
-
domain_id: domain.id,
|
|
215
|
-
parameters: (0, keitaro_utils_1.prepareOWCampaignParameters)(app)
|
|
216
|
-
};
|
|
217
|
-
const { data: campaign } = await http_1.default.put(`/campaigns/${clonedCampaign.id}`, payload);
|
|
218
|
-
return campaign;
|
|
195
|
+
let name = `#${app.id} [◈]`;
|
|
196
|
+
const generateAlias = () => {
|
|
197
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
198
|
+
return Array.from({ length: 8 }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join('');
|
|
199
|
+
};
|
|
200
|
+
let allCampaigns = await getAllCampaigns();
|
|
201
|
+
let matchingCampaign = allCampaigns.filter((c) => new RegExp(`#${app.id}.*◈`).test(c.name));
|
|
202
|
+
if (matchingCampaign.length > 0)
|
|
203
|
+
return matchingCampaign[0];
|
|
204
|
+
const originalCampaign = await getCampaignById(2673);
|
|
205
|
+
const maxPosition = Math.max(...allCampaigns.map(c => c.position || 0));
|
|
206
|
+
const originalStreams = await getStreamsByCampaignId(2673);
|
|
207
|
+
let allDomains = await exports.KeitaroService.getDomains(true);
|
|
208
|
+
if (!allDomains) {
|
|
209
|
+
throw Error(`Failed to get all domains list`);
|
|
219
210
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
211
|
+
const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
|
|
212
|
+
const maxGroupId = Math.max(...allCampaigns.map(c => c.group_id || 0));
|
|
213
|
+
let alias = generateAlias();
|
|
214
|
+
let payload = {
|
|
215
|
+
// Унікальні поля
|
|
216
|
+
name: name,
|
|
217
|
+
alias: alias,
|
|
218
|
+
domain_id: domain.id,
|
|
219
|
+
position: [maxPosition + 100],
|
|
220
|
+
group_id: maxGroupId + 1,
|
|
221
|
+
traffic_source_id: keitaro_utils_1.TRAFFIC_SOURCE_ID_FLASH_AI,
|
|
222
|
+
parameters: (0, keitaro_utils_1.prepareOWCampaignParameters)(app),
|
|
223
|
+
// Неунікальні поля з оригінальної кампанії
|
|
224
|
+
type: originalCampaign.type,
|
|
225
|
+
state: originalCampaign.state,
|
|
226
|
+
cost_type: originalCampaign.cost_type,
|
|
227
|
+
cost_value: originalCampaign.cost_value,
|
|
228
|
+
cost_currency: originalCampaign.cost_currency,
|
|
229
|
+
uniqueness_period: originalCampaign.uniqueness_period,
|
|
230
|
+
cookies_ttl: originalCampaign.cookies_ttl,
|
|
231
|
+
notes: originalCampaign.notes,
|
|
232
|
+
collect_clicks: originalCampaign.collect_clicks,
|
|
233
|
+
uniqueness_type: originalCampaign.uniqueness_type, // тип унікальності (IP і user-agent)
|
|
234
|
+
};
|
|
235
|
+
const newCampaign = await createCampaign(payload);
|
|
236
|
+
for (const stream of originalStreams) {
|
|
237
|
+
await http_1.default.post('streams', {
|
|
238
|
+
name: stream.name,
|
|
239
|
+
campaign_id: newCampaign.id,
|
|
240
|
+
schema: stream.schema,
|
|
241
|
+
type: stream.type,
|
|
242
|
+
action_type: stream.action_type,
|
|
243
|
+
weight: stream.weight,
|
|
244
|
+
offers: stream.offers.map((offer) => ({
|
|
245
|
+
offer_id: offer.offer_id,
|
|
246
|
+
share: offer.share,
|
|
247
|
+
state: offer.state
|
|
248
|
+
})),
|
|
249
|
+
filters: stream.filters.map((filter) => ({
|
|
250
|
+
name: filter.name,
|
|
251
|
+
mode: filter.mode,
|
|
252
|
+
payload: filter.payload
|
|
253
|
+
})),
|
|
254
|
+
position: stream.position,
|
|
255
|
+
state: stream.state
|
|
225
256
|
});
|
|
226
|
-
throw error;
|
|
227
257
|
}
|
|
258
|
+
return newCampaign;
|
|
228
259
|
}
|
|
229
260
|
async function cloneDCampaign(app) {
|
|
230
261
|
let name = `D #${app.id} (${app.bundle})`;
|
|
@@ -7,7 +7,7 @@ export declare let removeGeosFromAllRedirectCampaigns: (geoToRemove: string) =>
|
|
|
7
7
|
export declare let prepareOWCampaignParameters: (app: IApp) => IKeitaroCampaignParameters;
|
|
8
8
|
export declare function createOWStreamPartialPayload(app: IApp): Partial<IKeitaroStream>;
|
|
9
9
|
export declare function createDirectCampaign(app: IApp): Promise<IKeitaroCampaign>;
|
|
10
|
-
export declare function createOWCampaign(app: IApp): Promise<
|
|
10
|
+
export declare function createOWCampaign(app: IApp): Promise<any>;
|
|
11
11
|
type PostbackStatus = 'lead' | 'sale' | 'rejected';
|
|
12
12
|
export declare function sendPostbacks(subids: string[], status: PostbackStatus, payout?: number): Promise<void>;
|
|
13
13
|
export {};
|
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export interface IKeitaroCampaign {
|
|
2
|
+
position: number[] | any
|
|
2
3
|
id: number
|
|
3
4
|
alias: string,
|
|
4
5
|
name: string
|
|
@@ -18,6 +19,11 @@ export interface IKeitaroCampaign {
|
|
|
18
19
|
uniqueness_use_cookies: boolean
|
|
19
20
|
traffic_loss: number
|
|
20
21
|
parameters: IKeitaroCampaignParameters
|
|
22
|
+
uniqueness_period?: any
|
|
23
|
+
notes?: any
|
|
24
|
+
collect_clicks?: any
|
|
25
|
+
uniqueness_type?: any
|
|
26
|
+
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
export interface IKeitaroCampaignParameters {
|
|
@@ -237,49 +237,100 @@ export async function upsertStreamToCampaign(campaign: IKeitaroCampaign, stream:
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
async function cloneOWCampaign(app: IApp): Promise<IKeitaroCampaign> {
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
async function cloneOWCampaign(app: IApp): Promise<IKeitaroCampaign | any> {
|
|
241
|
+
let name = `#${app.id} [◈]`
|
|
242
|
+
const generateAlias = () => {
|
|
243
|
+
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
244
|
+
return Array.from(
|
|
245
|
+
{ length: 8 },
|
|
246
|
+
() => chars.charAt(Math.floor(Math.random() * chars.length))
|
|
247
|
+
).join('');
|
|
248
|
+
};
|
|
243
249
|
|
|
244
250
|
let allCampaigns = await getAllCampaigns()
|
|
245
|
-
let matchingCampaign = allCampaigns.filter((c) =>
|
|
251
|
+
let matchingCampaign = allCampaigns.filter((c) => new RegExp(`#${app.id}.*◈`).test(c.name))
|
|
246
252
|
if (matchingCampaign.length > 0) return matchingCampaign[0]
|
|
247
253
|
|
|
248
|
-
|
|
254
|
+
const originalCampaign : IKeitaroCampaign = await getCampaignById(2673)
|
|
255
|
+
const maxPosition = Math.max(...allCampaigns.map(c => c.position || 0));
|
|
256
|
+
const originalStreams = await getStreamsByCampaignId(2673)
|
|
249
257
|
|
|
258
|
+
|
|
250
259
|
|
|
251
|
-
|
|
260
|
+
|
|
252
261
|
|
|
253
|
-
let clonedCampaign: IKeitaroCampaign = campaigns[0]
|
|
254
262
|
|
|
255
263
|
let allDomains = await KeitaroService.getDomains(true)
|
|
256
264
|
if (!allDomains) {
|
|
257
265
|
throw Error(`Failed to get all domains list`)
|
|
258
266
|
}
|
|
259
|
-
console.log("clonedCampaign", clonedCampaign)
|
|
260
267
|
|
|
261
268
|
const domain = allDomains[Math.floor(Math.random() * allDomains.length)];
|
|
269
|
+
const maxGroupId = Math.max(...allCampaigns.map(c => c.group_id || 0));
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
let alias = generateAlias()
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
262
276
|
|
|
263
277
|
let payload: Partial<IKeitaroCampaign> = {
|
|
278
|
+
// Унікальні поля
|
|
264
279
|
name: name,
|
|
265
|
-
|
|
280
|
+
alias: alias,
|
|
266
281
|
domain_id: domain.id,
|
|
267
|
-
|
|
282
|
+
position: [maxPosition + 100],
|
|
283
|
+
group_id: maxGroupId + 1,
|
|
284
|
+
traffic_source_id: TRAFFIC_SOURCE_ID_FLASH_AI,
|
|
285
|
+
parameters: prepareOWCampaignParameters(app),
|
|
286
|
+
|
|
287
|
+
// Неунікальні поля з оригінальної кампанії
|
|
288
|
+
type: originalCampaign.type, // тип (position)
|
|
289
|
+
state: originalCampaign.state, // стан (active)
|
|
290
|
+
cost_type: originalCampaign.cost_type, // тип оплати (CPS)
|
|
291
|
+
cost_value: originalCampaign.cost_value, // вартість
|
|
292
|
+
cost_currency: originalCampaign.cost_currency, // валюта (USD)
|
|
293
|
+
uniqueness_period: originalCampaign.uniqueness_period, // період унікальності (8760 годин)
|
|
294
|
+
cookies_ttl: originalCampaign.cookies_ttl, // термін дії cookies
|
|
295
|
+
notes: originalCampaign.notes, // нотатки
|
|
296
|
+
collect_clicks: originalCampaign.collect_clicks, // збір кліків
|
|
297
|
+
uniqueness_type: originalCampaign.uniqueness_type, // тип унікальності (IP і user-agent)
|
|
268
298
|
}
|
|
269
299
|
|
|
270
|
-
|
|
300
|
+
|
|
271
301
|
|
|
272
|
-
|
|
273
|
-
}
|
|
302
|
+
|
|
274
303
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
304
|
+
|
|
305
|
+
const newCampaign : IKeitaroCampaign = await createCampaign(payload)
|
|
306
|
+
|
|
307
|
+
for (const stream of originalStreams) {
|
|
308
|
+
await keitaroApi.post('streams', {
|
|
309
|
+
name: stream.name,
|
|
310
|
+
campaign_id: newCampaign.id,
|
|
311
|
+
schema: stream.schema,
|
|
312
|
+
type: stream.type,
|
|
313
|
+
action_type: stream.action_type,
|
|
314
|
+
weight: stream.weight,
|
|
315
|
+
offers: stream.offers.map((offer) => ({
|
|
316
|
+
offer_id: offer.offer_id,
|
|
317
|
+
share: offer.share,
|
|
318
|
+
state: offer.state
|
|
319
|
+
})),
|
|
320
|
+
filters: stream.filters.map((filter) => ({
|
|
321
|
+
name: filter.name,
|
|
322
|
+
mode: filter.mode,
|
|
323
|
+
payload: filter.payload
|
|
324
|
+
})),
|
|
325
|
+
position: stream.position,
|
|
326
|
+
state: stream.state
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
return newCampaign
|
|
283
334
|
}
|
|
284
335
|
|
|
285
336
|
async function cloneDCampaign(app: IApp): Promise<IKeitaroCampaign> {
|
|
@@ -339,8 +339,8 @@ export let prepareOWCampaignParameters = (app: IApp): IKeitaroCampaignParameters
|
|
|
339
339
|
},
|
|
340
340
|
sub_id_15: {
|
|
341
341
|
"name": "offer_id",
|
|
342
|
-
"placeholder": "{
|
|
343
|
-
"alias": "
|
|
342
|
+
"placeholder": "{offer_id}",
|
|
343
|
+
"alias": "offer_id"
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
}
|
package/test-keitaro.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { KeitaroService } = require('./lib/network/keitaro/keitaro-service');
|
|
2
|
+
|
|
3
|
+
async function testClone() {
|
|
4
|
+
try {
|
|
5
|
+
const result = await KeitaroService.cloneOWCampaign({ id: 480 });
|
|
6
|
+
console.log('Cloned campaign:', result);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
console.error('Error:', error);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
testClone();
|