@bprotsyk/aso-core 2.1.44 → 2.1.45
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.
|
@@ -71,13 +71,23 @@ async function createStreamForMatchingCampaigns(streamPayloads, campaignRegExp,
|
|
|
71
71
|
// Process each stream payload
|
|
72
72
|
for (const { payload, offerId } of streamPayloads) {
|
|
73
73
|
const identicalStream = streams.find(stream => stream.name.includes(offerId));
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
try {
|
|
75
|
+
if (identicalStream) {
|
|
76
|
+
await http_1.default.put(`streams/${identicalStream.id}`, {
|
|
77
|
+
campaign_id: matchingCampaign.id,
|
|
78
|
+
...payload
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
await http_1.default.post('streams', {
|
|
83
|
+
campaign_id: matchingCampaign.id,
|
|
84
|
+
...payload
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(`Error updating stream ${offerId} (${payload.name}) in campaign ${matchingCampaign.id} (${matchingCampaign.name}):`, error);
|
|
76
90
|
}
|
|
77
|
-
await http_1.default.post('streams', {
|
|
78
|
-
campaign_id: matchingCampaign.id,
|
|
79
|
-
...payload
|
|
80
|
-
});
|
|
81
91
|
}
|
|
82
92
|
}
|
|
83
93
|
}
|
package/package.json
CHANGED
|
@@ -75,8 +75,8 @@ async function updateCampaign(id: number, payload: Partial<IKeitaroCampaign>) {
|
|
|
75
75
|
async function createStreamForMatchingCampaigns(streamPayloads: { payload: any, offerId: string }[], campaignRegExp: RegExp, avoidGroup?: number) {
|
|
76
76
|
// Get all campaigns once
|
|
77
77
|
const allCampaigns = await getAllCampaigns();
|
|
78
|
-
const matchingCampaigns = allCampaigns.filter(campaign =>
|
|
79
|
-
(avoidGroup ? campaign.group_id != avoidGroup : true) &&
|
|
78
|
+
const matchingCampaigns = allCampaigns.filter(campaign =>
|
|
79
|
+
(avoidGroup ? campaign.group_id != avoidGroup : true) &&
|
|
80
80
|
campaignRegExp.exec(campaign.name)
|
|
81
81
|
);
|
|
82
82
|
|
|
@@ -94,14 +94,21 @@ async function createStreamForMatchingCampaigns(streamPayloads: { payload: any,
|
|
|
94
94
|
for (const { payload, offerId } of streamPayloads) {
|
|
95
95
|
const identicalStream = streams.find(stream => stream.name.includes(offerId));
|
|
96
96
|
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
try {
|
|
98
|
+
if (identicalStream) {
|
|
99
|
+
await keitaroApi.put(`streams/${identicalStream.id}`, {
|
|
100
|
+
campaign_id: matchingCampaign.id,
|
|
101
|
+
...payload
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
await keitaroApi.post('streams', {
|
|
105
|
+
campaign_id: matchingCampaign.id,
|
|
106
|
+
...payload
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(`Error updating stream ${offerId} (${payload.name}) in campaign ${matchingCampaign.id} (${matchingCampaign.name}):`, error);
|
|
99
111
|
}
|
|
100
|
-
|
|
101
|
-
await keitaroApi.post('streams', {
|
|
102
|
-
campaign_id: matchingCampaign.id,
|
|
103
|
-
...payload
|
|
104
|
-
});
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
114
|
}
|
|
@@ -157,15 +164,15 @@ function createStreamPartialPayload(keitaroOfferId: number, offerName: string, o
|
|
|
157
164
|
|
|
158
165
|
async function addOffersToKeitaro(offers: IOffer[], affiliateId: number, links: string[], avoidGroup?: number, groupId?: number) {
|
|
159
166
|
const allOffers = await getAllOffers();
|
|
160
|
-
|
|
167
|
+
|
|
161
168
|
const streamPayloads = [];
|
|
162
|
-
|
|
169
|
+
|
|
163
170
|
for (let i = 0; i < offers.length; i++) {
|
|
164
171
|
const offer = offers[i];
|
|
165
172
|
const link = links[i];
|
|
166
|
-
|
|
173
|
+
|
|
167
174
|
const identicalOffer = allOffers.find(o => o.name.includes(offer.name));
|
|
168
|
-
|
|
175
|
+
|
|
169
176
|
let keitaroOfferId;
|
|
170
177
|
if (identicalOffer) {
|
|
171
178
|
keitaroOfferId = identicalOffer.id;
|
|
@@ -181,11 +188,11 @@ async function addOffersToKeitaro(offers: IOffer[], affiliateId: number, links:
|
|
|
181
188
|
payout_auto: true,
|
|
182
189
|
payout_upsell: true,
|
|
183
190
|
};
|
|
184
|
-
|
|
191
|
+
|
|
185
192
|
const { data: keitaroOffer } = await keitaroApi.post('offers', offerPayload);
|
|
186
193
|
keitaroOfferId = keitaroOffer.id;
|
|
187
194
|
}
|
|
188
|
-
|
|
195
|
+
|
|
189
196
|
streamPayloads.push({
|
|
190
197
|
payload: createStreamPartialPayload(
|
|
191
198
|
keitaroOfferId,
|
|
@@ -196,7 +203,7 @@ async function addOffersToKeitaro(offers: IOffer[], affiliateId: number, links:
|
|
|
196
203
|
offerId: offer.name
|
|
197
204
|
});
|
|
198
205
|
}
|
|
199
|
-
|
|
206
|
+
|
|
200
207
|
await createStreamForMatchingCampaigns(streamPayloads, /◈/, avoidGroup);
|
|
201
208
|
}
|
|
202
209
|
|
|
@@ -366,7 +373,7 @@ async function getClicks(request: IKeitaroClicksRequest | KeitaroClicksInterval)
|
|
|
366
373
|
} : {
|
|
367
374
|
...request
|
|
368
375
|
};
|
|
369
|
-
|
|
376
|
+
|
|
370
377
|
const { data } = await keitaroApi.post('/clicks/log', defaultRequest);
|
|
371
378
|
return data.rows;
|
|
372
379
|
}
|