@bprotsyk/aso-core 2.1.44 → 2.1.46
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
|
}
|
|
@@ -187,7 +197,9 @@ async function cloneOWCampaign(app) {
|
|
|
187
197
|
let matchingCampaign = allCampaigns.filter((c) => new RegExp(`#${app.id}.*◈`).test(c.name));
|
|
188
198
|
if (matchingCampaign.length > 0)
|
|
189
199
|
return matchingCampaign[0];
|
|
190
|
-
const { data: campaigns } = await http_1.default.post(`/campaigns/2673/clone
|
|
200
|
+
const { data: campaigns } = await http_1.default.post(`/campaigns/2673/clone`, {
|
|
201
|
+
name: name
|
|
202
|
+
});
|
|
191
203
|
if (campaigns.length == 0)
|
|
192
204
|
throw Error("Campaign cloning falied");
|
|
193
205
|
let clonedCampaign = campaigns[0];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bprotsyk/aso-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.46",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/mustache": "^4.2.5",
|
|
44
44
|
"@types/node": "^20.14.12",
|
|
45
|
-
"@types/react": "^18.3.
|
|
45
|
+
"@types/react": "^18.3.18",
|
|
46
46
|
"@types/react-dom": "^18.3.0",
|
|
47
47
|
"copyfiles": "^2.4.1",
|
|
48
48
|
"typedoc": "^0.23.28",
|
|
@@ -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
|
|
|
@@ -237,7 +244,9 @@ async function cloneOWCampaign(app: IApp): Promise<IKeitaroCampaign> {
|
|
|
237
244
|
let matchingCampaign = allCampaigns.filter((c) => new RegExp(`#${app.id}.*◈`).test(c.name))
|
|
238
245
|
if (matchingCampaign.length > 0) return matchingCampaign[0]
|
|
239
246
|
|
|
240
|
-
const { data: campaigns } = await keitaroApi.post(`/campaigns/2673/clone
|
|
247
|
+
const { data: campaigns } = await keitaroApi.post(`/campaigns/2673/clone`, {
|
|
248
|
+
name: name
|
|
249
|
+
});
|
|
241
250
|
|
|
242
251
|
if (campaigns.length == 0) throw Error("Campaign cloning falied")
|
|
243
252
|
|
|
@@ -366,7 +375,7 @@ async function getClicks(request: IKeitaroClicksRequest | KeitaroClicksInterval)
|
|
|
366
375
|
} : {
|
|
367
376
|
...request
|
|
368
377
|
};
|
|
369
|
-
|
|
378
|
+
|
|
370
379
|
const { data } = await keitaroApi.post('/clicks/log', defaultRequest);
|
|
371
380
|
return data.rows;
|
|
372
381
|
}
|