@bprotsyk/aso-core 1.2.27 → 1.2.28

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.
@@ -36,6 +36,28 @@ export interface IFlashApp {
36
36
  onesignalRestApiKey: string;
37
37
  generationOptions: IAppGenerationOptions;
38
38
  }
39
+ export interface IFlashAppUpdated {
40
+ id: number;
41
+ name: string;
42
+ trackingUrl?: string;
43
+ bundle: string;
44
+ pushesEnabled?: boolean;
45
+ plugUrl: string;
46
+ reservePlugUrl?: string;
47
+ policyUrl?: string;
48
+ onesignalAppId: string;
49
+ onesignalRestApiKey: string;
50
+ developerName?: string;
51
+ developerEmail?: string;
52
+ generationOptions: IAppGenerationOptionsUpdated;
53
+ }
54
+ export interface IAppGenerationOptionsUpdated {
55
+ splashActivityClassName: string;
56
+ mainActivityClassName: string;
57
+ linkName: string;
58
+ savedName: string;
59
+ paranoidSeed: number;
60
+ }
39
61
  export interface IAppGenerationOptions {
40
62
  splashActivityClassName: string;
41
63
  mainActivityClassName: string;
@@ -76,3 +98,26 @@ export declare const FlashAppSchema: Schema<any, Model<any, any, any, any, any>,
76
98
  keyPassword: string;
77
99
  } | undefined;
78
100
  }>;
101
+ export declare const FlashAppSchemaUpdated: Schema<any, Model<any, any, any, any, any>, {}, {}, {}, {}, import("mongoose").DefaultSchemaOptions, {
102
+ email: string;
103
+ id: number;
104
+ bundle: string;
105
+ trackingUrl: string;
106
+ onesignalAppId: string;
107
+ onesignalRestApiKey: string;
108
+ plugUrl: string;
109
+ reservePlugUrl: string;
110
+ developerName: string;
111
+ developerEmail: string;
112
+ name?: string | undefined;
113
+ pushesEnabled?: boolean | undefined;
114
+ policyUrl?: string | undefined;
115
+ generationOptions?: {
116
+ splashActivityClassName: string;
117
+ mainActivityClassName: string;
118
+ linkName: string;
119
+ savedName: string;
120
+ paranoidSeed: number;
121
+ } | undefined;
122
+ }>;
123
+ export declare function updateSchemaAndMoveValue(model: Model<IFlashAppUpdated>): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlashAppSchema = void 0;
3
+ exports.updateSchemaAndMoveValue = exports.FlashAppSchemaUpdated = exports.FlashAppSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
5
  exports.FlashAppSchema = new mongoose_1.Schema({
6
6
  id: {
@@ -94,3 +94,137 @@ exports.FlashAppSchema = new mongoose_1.Schema({
94
94
  },
95
95
  }
96
96
  });
97
+ exports.FlashAppSchemaUpdated = new mongoose_1.Schema({
98
+ id: {
99
+ type: Number,
100
+ unique: true,
101
+ required: true
102
+ },
103
+ bundle: {
104
+ type: String,
105
+ unique: true,
106
+ required: true
107
+ },
108
+ name: String,
109
+ trackingUrl: {
110
+ type: String,
111
+ default: null
112
+ },
113
+ email: {
114
+ type: String,
115
+ default: null
116
+ },
117
+ pushesEnabled: Boolean,
118
+ plugUrl: {
119
+ type: String,
120
+ unique: true,
121
+ required: true
122
+ },
123
+ reservePlugUrl: {
124
+ type: String,
125
+ unique: true,
126
+ required: true
127
+ },
128
+ policyUrl: {
129
+ type: String,
130
+ unique: true,
131
+ required: false
132
+ },
133
+ onesignalAppId: {
134
+ type: String,
135
+ unique: true,
136
+ required: true
137
+ },
138
+ onesignalRestApiKey: {
139
+ type: String,
140
+ unique: true,
141
+ required: true
142
+ },
143
+ developerName: {
144
+ type: String,
145
+ unique: true,
146
+ required: true
147
+ },
148
+ developerEmail: {
149
+ type: String,
150
+ unique: true,
151
+ required: true
152
+ },
153
+ generationOptions: {
154
+ splashActivityClassName: {
155
+ type: String,
156
+ required: true
157
+ },
158
+ mainActivityClassName: {
159
+ type: String,
160
+ required: true
161
+ },
162
+ linkName: {
163
+ type: String,
164
+ required: true
165
+ },
166
+ savedName: {
167
+ type: String,
168
+ required: true
169
+ },
170
+ paranoidSeed: {
171
+ type: Number,
172
+ required: true,
173
+ unique: true
174
+ },
175
+ }
176
+ });
177
+ async function updateSchemaAndMoveValue(model) {
178
+ const aggregationPipeline = [
179
+ {
180
+ $project: {
181
+ pastebinUrl: 0,
182
+ email: 0,
183
+ onesignalAppId: { $toString: '$onesignalAppId' },
184
+ onesignalRestApiKey: { $toString: '$onesignalRestApiKey' },
185
+ generationOptions: {
186
+ keyFileName: 0,
187
+ keyDeveloperName: 0,
188
+ keyDeveloperOrganization: 0,
189
+ keyCountryCode: 0,
190
+ keyCity: 0,
191
+ keyAlias: 0,
192
+ keyPassword: 0
193
+ }
194
+ }
195
+ },
196
+ {
197
+ $addFields: {
198
+ plugUrl: `$pastebinUrl`,
199
+ reservePlugUrl: null,
200
+ developerName: '$email',
201
+ }
202
+ }
203
+ ];
204
+ // Define the update operation to apply the new schema with the updated field
205
+ const updateOperation = {
206
+ $set: {
207
+ plugUrl: '$pastebinUrl',
208
+ reservePlugUrl: null,
209
+ policyUrl: null,
210
+ developerName: '$generationOptions.keyDeveloperName',
211
+ developerEmail: '$email',
212
+ },
213
+ $unset: {
214
+ 'email': true,
215
+ 'pastebinUrl': true,
216
+ 'generationOptions.keyFileName': true,
217
+ 'generationOptions.keyDeveloperName': true,
218
+ 'generationOptions.keyDeveloperOrganization': true,
219
+ 'generationOptions.keyCountryCode': true,
220
+ 'generationOptions.keyCity': true,
221
+ 'generationOptions.keyAlias': 0,
222
+ 'generationOptions.keyPassword': 0
223
+ }
224
+ };
225
+ await model.updateMany({}, [
226
+ ...aggregationPipeline,
227
+ updateOperation
228
+ ]);
229
+ }
230
+ exports.updateSchemaAndMoveValue = updateSchemaAndMoveValue;
package/lib/index.d.ts CHANGED
@@ -16,7 +16,7 @@ export { IOfferWallSection } from "./aso/offerwall/offerwall-section";
16
16
  export { IOfferWallOffer } from "./aso/offerwall/offerwall-offer";
17
17
  export { IOfferWallResponse } from "./aso/offerwall/offerwall-response";
18
18
  export { IOfferWallHomeDialogData } from "./aso/offerwall/offerwall-home-dialog-data";
19
- export { IFlashApp, FlashAppSchema } from "./flash/flash-app";
19
+ export { IFlashApp as IFlashAppOld, IFlashAppUpdated as IFlashApp, FlashAppSchema as FlashAppSchemaOld, FlashAppSchemaUpdated as FlashAppSchema, updateSchemaAndMoveValue } from "./flash/flash-app";
20
20
  export { IFlashAppListItem } from "./flash/flash-app-list-item";
21
21
  export * as ASOConfigFetch from "./aso/usage-logs/aso-config-fetch-entry";
22
22
  export { IPanelUser, PanelUserAccessScope, PanelUserSchema } from "./panel/user";
@@ -28,3 +28,4 @@ export { IOfferWallAuthConfig } from "./aso/offerwall/auth/offerwall-auth-config
28
28
  export { IOfferWallAuthLocalization } from "./aso/offerwall/auth/offerwall-auth-localization";
29
29
  export { IOfferWallAuthSubmitRequest } from "./aso/offerwall/auth/offerwall-auth-submit-request";
30
30
  export { IOfferWallAuthSubmitResponse } from "./aso/offerwall/auth/offerwall-auth-submit-response";
31
+ export { KeitaroService } from "./network/keitaro/keitaro-service";
package/lib/index.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ColoredText = exports.ShapeDiv = exports.PanelUserSchema = exports.PanelUserAccessScope = exports.ASOConfigFetch = exports.FlashAppSchema = exports.ASO_v5 = exports.ASO_v4 = exports.ASO_v3 = exports.ASO_v2 = exports.ASO_v1 = exports.ASO_v0 = void 0;
26
+ exports.KeitaroService = exports.ColoredText = exports.ShapeDiv = exports.PanelUserSchema = exports.PanelUserAccessScope = exports.ASOConfigFetch = exports.updateSchemaAndMoveValue = exports.FlashAppSchema = exports.FlashAppSchemaOld = exports.ASO_v5 = exports.ASO_v4 = exports.ASO_v3 = exports.ASO_v2 = exports.ASO_v1 = exports.ASO_v0 = void 0;
27
27
  exports.ASO_v0 = __importStar(require("./aso/config/aso-config-v0"));
28
28
  exports.ASO_v1 = __importStar(require("./aso/config/aso-config-v1"));
29
29
  exports.ASO_v2 = __importStar(require("./aso/config/aso-config-v2"));
@@ -31,7 +31,9 @@ exports.ASO_v3 = __importStar(require("./aso/config/aso-config-v3"));
31
31
  exports.ASO_v4 = __importStar(require("./aso/config/aso-config-v4"));
32
32
  exports.ASO_v5 = __importStar(require("./aso/config/aso-config-v5"));
33
33
  var flash_app_1 = require("./flash/flash-app");
34
- Object.defineProperty(exports, "FlashAppSchema", { enumerable: true, get: function () { return flash_app_1.FlashAppSchema; } });
34
+ Object.defineProperty(exports, "FlashAppSchemaOld", { enumerable: true, get: function () { return flash_app_1.FlashAppSchema; } });
35
+ Object.defineProperty(exports, "FlashAppSchema", { enumerable: true, get: function () { return flash_app_1.FlashAppSchemaUpdated; } });
36
+ Object.defineProperty(exports, "updateSchemaAndMoveValue", { enumerable: true, get: function () { return flash_app_1.updateSchemaAndMoveValue; } });
35
37
  exports.ASOConfigFetch = __importStar(require("./aso/usage-logs/aso-config-fetch-entry"));
36
38
  var user_1 = require("./panel/user");
37
39
  Object.defineProperty(exports, "PanelUserAccessScope", { enumerable: true, get: function () { return user_1.PanelUserAccessScope; } });
@@ -40,3 +42,5 @@ var shape_1 = require("./shared/shape");
40
42
  Object.defineProperty(exports, "ShapeDiv", { enumerable: true, get: function () { return shape_1.ShapeDiv; } });
41
43
  var colored_text_1 = require("./shared/colored-text");
42
44
  Object.defineProperty(exports, "ColoredText", { enumerable: true, get: function () { return colored_text_1.ColoredText; } });
45
+ var keitaro_service_1 = require("./network/keitaro/keitaro-service");
46
+ Object.defineProperty(exports, "KeitaroService", { enumerable: true, get: function () { return keitaro_service_1.KeitaroService; } });
@@ -0,0 +1,3 @@
1
+ import axios from "axios";
2
+ declare const _default: axios.AxiosInstance;
3
+ export default _default;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const axios_1 = __importDefault(require("axios"));
7
+ exports.default = axios_1.default.create({
8
+ baseURL: 'https://aibprtsk.com/admin_api/v1/',
9
+ headers: {
10
+ "Api-Key": `a5369b1016aa6bd6453751a393b157b4`,
11
+ },
12
+ });
@@ -0,0 +1,36 @@
1
+ import { IOffer } from "../../shared/offer";
2
+ export interface IKeitaroStream {
3
+ id: number;
4
+ name: string;
5
+ campaign_id: number;
6
+ offer_id: number;
7
+ url: string;
8
+ redirect_url: string;
9
+ traffic_type: string;
10
+ state: string;
11
+ filters: any[];
12
+ position: number;
13
+ offers: any[];
14
+ schema: string;
15
+ type: string;
16
+ action_type: string;
17
+ }
18
+ export interface IKeitaroCampaign {
19
+ id: number;
20
+ name: string;
21
+ }
22
+ declare function getStreamsByCampaignId(campaignId: number): Promise<IKeitaroStream[]>;
23
+ declare function getAllCampaigns(): Promise<IKeitaroCampaign[]>;
24
+ declare function cloneStreams(originalCampaignId: number, streamPositionsToClone: number[], campaignRegExp: RegExp): Promise<void>;
25
+ declare function getAllOffers(): Promise<any[]>;
26
+ declare function getOfferByKeitaroId(id: number): Promise<any>;
27
+ declare function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string, groupId?: number): Promise<void>;
28
+ export declare const KeitaroService: {
29
+ getStreamsByCampaignId: typeof getStreamsByCampaignId;
30
+ getAllCampaigns: typeof getAllCampaigns;
31
+ getAllOffers: typeof getAllOffers;
32
+ cloneStreams: typeof cloneStreams;
33
+ addOfferToKeitaro: typeof addOfferToKeitaro;
34
+ getOfferByKeitaroId: typeof getOfferByKeitaroId;
35
+ };
36
+ export {};
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KeitaroService = void 0;
7
+ const http_1 = __importDefault(require("./http"));
8
+ async function getStreamsByCampaignId(campaignId) {
9
+ const { data: streams } = await http_1.default.get(`campaigns/${campaignId}/streams`);
10
+ return streams;
11
+ }
12
+ async function getAllCampaigns() {
13
+ const { data: campaigns } = await http_1.default.get('campaigns');
14
+ ``;
15
+ return campaigns;
16
+ }
17
+ async function cloneStreams(originalCampaignId, streamPositionsToClone, campaignRegExp) {
18
+ // Get the original campaign's streams
19
+ const originalStreams = await getStreamsByCampaignId(originalCampaignId);
20
+ // Filter the original streams by the given stream positions to clone
21
+ const streamsToClone = originalStreams.filter(stream => streamPositionsToClone.includes(stream.position));
22
+ // Get a list of all campaigns
23
+ const allCampaigns = await getAllCampaigns();
24
+ // Filter the campaigns by the given RegExp
25
+ const matchingCampaigns = allCampaigns.filter(campaign => campaignRegExp.exec(campaign.name) && campaign.id != originalCampaignId);
26
+ // console.log(matchingCampaigns)
27
+ // For each matching campaign, clone the streams
28
+ for (const matchingCampaign of matchingCampaigns) {
29
+ for (const streamToClone of streamsToClone) {
30
+ await http_1.default.post('streams', {
31
+ name: streamToClone.name,
32
+ campaign_id: matchingCampaign.id,
33
+ schema: streamToClone.schema,
34
+ type: streamToClone.type,
35
+ action_type: streamToClone.action_type,
36
+ weight: 100,
37
+ offers: streamToClone.offers.map((offer) => {
38
+ return {
39
+ offer_id: offer.offer_id,
40
+ share: 100
41
+ };
42
+ }),
43
+ filters: streamToClone.filters.map((filter) => {
44
+ return {
45
+ name: filter.name,
46
+ mode: filter.mode,
47
+ payload: filter.payload
48
+ };
49
+ }),
50
+ });
51
+ }
52
+ }
53
+ }
54
+ async function createStreamForMatchingCampaigns(streamPartialPayload, offerId, campaignRegExp) {
55
+ // Get a list of all campaigns
56
+ const allCampaigns = await getAllCampaigns();
57
+ // Filter the campaigns by the given RegExp
58
+ const matchingCampaigns = allCampaigns.filter(campaign => campaignRegExp.exec(campaign.name));
59
+ // console.log(matchingCampaigns)
60
+ // For each matching campaign, clone the streams
61
+ for (const matchingCampaign of matchingCampaigns) {
62
+ let streams = await getStreamsByCampaignId(matchingCampaign.id);
63
+ let identicalStream = streams.find((stream) => stream.name.includes(offerId));
64
+ if (identicalStream) {
65
+ await http_1.default.put(`streams/${identicalStream.id}`, {
66
+ campaign_id: matchingCampaign.id,
67
+ ...streamPartialPayload
68
+ });
69
+ }
70
+ else {
71
+ await http_1.default.post('streams', {
72
+ campaign_id: matchingCampaign.id,
73
+ ...streamPartialPayload
74
+ });
75
+ }
76
+ }
77
+ }
78
+ async function getAllOffers() {
79
+ const { data: offers } = await http_1.default.get('offers');
80
+ return offers;
81
+ }
82
+ async function getOfferByKeitaroId(id) {
83
+ const { data: offer } = await http_1.default.get(`offers/${id}`);
84
+ return offer;
85
+ }
86
+ function createStreamPartialPayload(keitaroOfferId, offerName, offerId, offerGeo) {
87
+ return {
88
+ name: `${offerName} ${offerGeo} (${offerId})`,
89
+ schema: "landings",
90
+ type: "regular",
91
+ action_type: "http",
92
+ weight: 100,
93
+ offers: [{
94
+ offer_id: keitaroOfferId,
95
+ share: 100,
96
+ state: "active"
97
+ }],
98
+ filters: [{
99
+ name: "sub_id_15",
100
+ mode: "accept",
101
+ payload: [offerId]
102
+ }],
103
+ };
104
+ }
105
+ async function addOfferToKeitaro(offer, affiliateId, link, groupId) {
106
+ // TODO look if offer already exists by offer.name
107
+ let allOffers = await getAllOffers();
108
+ let identicalOffer = allOffers.find((o) => { return o.name.includes(offer.name); });
109
+ let keitaroOfferId;
110
+ if (identicalOffer) {
111
+ keitaroOfferId = identicalOffer.id;
112
+ }
113
+ else {
114
+ let offerPayload = {
115
+ name: `${offer.caption} ${offer.geo} (${offer.name})`,
116
+ group_id: groupId || 1,
117
+ action_payload: link,
118
+ affiliate_network_id: affiliateId,
119
+ country: [offer.geo],
120
+ action_type: "http",
121
+ offer_type: "external",
122
+ payout_auto: true,
123
+ payout_upsell: true,
124
+ };
125
+ const { data: keitaroOffer } = await http_1.default.post(`offers`, offerPayload);
126
+ keitaroOfferId = keitaroOffer.id;
127
+ }
128
+ let streamPartialPayload = createStreamPartialPayload(keitaroOfferId, offer.caption, offer.name, offer.geo);
129
+ await createStreamForMatchingCampaigns(streamPartialPayload, offer.name, /^(FA #|A #)/);
130
+ }
131
+ exports.KeitaroService = {
132
+ getStreamsByCampaignId, getAllCampaigns, getAllOffers, cloneStreams, addOfferToKeitaro, getOfferByKeitaroId
133
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bprotsyk/aso-core",
3
- "version": "1.2.27",
3
+ "version": "1.2.28",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "scripts": {
@@ -20,9 +20,11 @@
20
20
  "homepage": "https://bitbucket.org/bprtsk/aso-core#readme",
21
21
  "description": "",
22
22
  "dependencies": {
23
+ "@types/axios": "^0.14.0",
23
24
  "@types/module-alias": "^2.0.1",
24
25
  "@types/mongoose": "^5.11.97",
25
26
  "@types/styled-components": "^5.1.26",
27
+ "axios": "^1.4.0",
26
28
  "module-alias": "^2.2.2",
27
29
  "mongoose": "^6.8.3",
28
30
  "react": "^18.2.0",
@@ -1,4 +1,4 @@
1
- import { Model, model, Schema } from "mongoose";
1
+ import { Model, model, Schema, UpdateQuery } from "mongoose";
2
2
 
3
3
  // TODO add date of policy in case we need to recreate it
4
4
  // and all data necessary. test
@@ -18,10 +18,37 @@ export interface IFlashApp {
18
18
  generationOptions: IAppGenerationOptions
19
19
  }
20
20
 
21
+ export interface IFlashAppUpdated {
22
+ id: number
23
+ name: string
24
+ trackingUrl?: string
25
+ bundle: string
26
+
27
+ pushesEnabled?: boolean
28
+ plugUrl: string
29
+ reservePlugUrl?: string
30
+ policyUrl?: string
31
+
32
+ onesignalAppId: string
33
+ onesignalRestApiKey: string
34
+
35
+ developerName?: string
36
+ developerEmail?: string
37
+ generationOptions: IAppGenerationOptionsUpdated
38
+ }
39
+
40
+ export interface IAppGenerationOptionsUpdated {
41
+ splashActivityClassName: string
42
+ mainActivityClassName: string
43
+ linkName: string
44
+ savedName: string
45
+ paranoidSeed: number
46
+ }
47
+
21
48
  export interface IAppGenerationOptions {
22
49
  splashActivityClassName: string
23
50
  mainActivityClassName: string
24
- linkName: string,
51
+ linkName: string
25
52
  savedName: string
26
53
 
27
54
  paranoidSeed: number
@@ -130,3 +157,143 @@ export const FlashAppSchema = new Schema({
130
157
  }
131
158
  })
132
159
 
160
+ export const FlashAppSchemaUpdated = new Schema({
161
+ id: {
162
+ type: Number,
163
+ unique: true,
164
+ required: true
165
+ },
166
+ bundle: {
167
+ type: String,
168
+ unique: true,
169
+ required: true
170
+ },
171
+ name: String,
172
+ trackingUrl: {
173
+ type: String,
174
+ default: null
175
+ },
176
+ email: {
177
+ type: String,
178
+ default: null
179
+ },
180
+
181
+ pushesEnabled: Boolean,
182
+ plugUrl: {
183
+ type: String,
184
+ unique: true,
185
+ required: true
186
+ },
187
+ reservePlugUrl: {
188
+ type: String,
189
+ unique: true,
190
+ required: true
191
+ },
192
+ policyUrl: {
193
+ type: String,
194
+ unique: true,
195
+ required: false
196
+ },
197
+
198
+ onesignalAppId: {
199
+ type: String,
200
+ unique: true,
201
+ required: true
202
+ },
203
+ onesignalRestApiKey: {
204
+ type: String,
205
+ unique: true,
206
+ required: true
207
+ },
208
+
209
+ developerName: {
210
+ type: String,
211
+ unique: true,
212
+ required: true
213
+ },
214
+ developerEmail: {
215
+ type: String,
216
+ unique: true,
217
+ required: true
218
+ },
219
+
220
+ generationOptions: {
221
+ splashActivityClassName: {
222
+ type: String,
223
+ required: true
224
+ },
225
+ mainActivityClassName: {
226
+ type: String,
227
+ required: true
228
+ },
229
+ linkName: {
230
+ type: String,
231
+ required: true
232
+ },
233
+ savedName: {
234
+ type: String,
235
+ required: true
236
+ },
237
+ paranoidSeed: {
238
+ type: Number,
239
+ required: true,
240
+ unique: true
241
+ },
242
+ }
243
+ })
244
+
245
+ export async function updateSchemaAndMoveValue(model: Model<IFlashAppUpdated>): Promise<void> {
246
+ const aggregationPipeline = [
247
+ {
248
+ $project: {
249
+ pastebinUrl: 0,
250
+ email: 0,
251
+ onesignalAppId: { $toString: '$onesignalAppId' },
252
+ onesignalRestApiKey: { $toString: '$onesignalRestApiKey' },
253
+ generationOptions: {
254
+ keyFileName: 0,
255
+ keyDeveloperName: 0,
256
+ keyDeveloperOrganization: 0,
257
+ keyCountryCode: 0,
258
+ keyCity: 0,
259
+ keyAlias: 0,
260
+ keyPassword: 0
261
+ }
262
+ }
263
+ },
264
+ {
265
+ $addFields: {
266
+ plugUrl: `$pastebinUrl`,
267
+ reservePlugUrl: null,
268
+ developerName: '$email',
269
+ }
270
+ }
271
+ ];
272
+
273
+ // Define the update operation to apply the new schema with the updated field
274
+ const updateOperation: UpdateQuery<IFlashAppUpdated> = {
275
+ $set: {
276
+ plugUrl: '$pastebinUrl',
277
+ reservePlugUrl: null,
278
+ policyUrl: null,
279
+ developerName: '$generationOptions.keyDeveloperName',
280
+ developerEmail: '$email',
281
+ },
282
+ $unset: {
283
+ 'email': true,
284
+ 'pastebinUrl': true,
285
+ 'generationOptions.keyFileName': true,
286
+ 'generationOptions.keyDeveloperName': true,
287
+ 'generationOptions.keyDeveloperOrganization': true,
288
+ 'generationOptions.keyCountryCode': true,
289
+ 'generationOptions.keyCity': true,
290
+ 'generationOptions.keyAlias': 0,
291
+ 'generationOptions.keyPassword': 0
292
+ }
293
+ };
294
+
295
+ await model.updateMany({}, [
296
+ ...aggregationPipeline,
297
+ updateOperation
298
+ ]);
299
+ }
package/src/index.ts CHANGED
@@ -19,7 +19,7 @@ export { IOfferWallOffer } from "./aso/offerwall/offerwall-offer"
19
19
  export { IOfferWallResponse } from "./aso/offerwall/offerwall-response"
20
20
  export { IOfferWallHomeDialogData } from "./aso/offerwall/offerwall-home-dialog-data"
21
21
 
22
- export { IFlashApp, FlashAppSchema } from "./flash/flash-app"
22
+ export { IFlashApp as IFlashAppOld, IFlashAppUpdated as IFlashApp, FlashAppSchema as FlashAppSchemaOld, FlashAppSchemaUpdated as FlashAppSchema, updateSchemaAndMoveValue } from "./flash/flash-app"
23
23
  export { IFlashAppListItem } from "./flash/flash-app-list-item"
24
24
 
25
25
  export * as ASOConfigFetch from "./aso/usage-logs/aso-config-fetch-entry"
@@ -28,9 +28,10 @@ export { IPanelUser, PanelUserAccessScope, PanelUserSchema } from "./panel/user"
28
28
  export { IAuthToken } from "./panel/auth"
29
29
  export { IUpsertFlashAppRequest, IUpsertFlashAppResponse } from "./panel/flash/create-flash-app-request"
30
30
 
31
- export {IGradient, IStroke, IShape, ShapeDiv} from "./shared/shape"
32
- export {ColoredText, IColoredTextProps} from "./shared/colored-text"
33
- export {IOfferWallAuthConfig} from "./aso/offerwall/auth/offerwall-auth-config"
34
- export {IOfferWallAuthLocalization} from "./aso/offerwall/auth/offerwall-auth-localization"
35
- export {IOfferWallAuthSubmitRequest} from "./aso/offerwall/auth/offerwall-auth-submit-request"
36
- export {IOfferWallAuthSubmitResponse} from "./aso/offerwall/auth/offerwall-auth-submit-response"
31
+ export { IGradient, IStroke, IShape, ShapeDiv } from "./shared/shape"
32
+ export { ColoredText, IColoredTextProps } from "./shared/colored-text"
33
+ export { IOfferWallAuthConfig } from "./aso/offerwall/auth/offerwall-auth-config"
34
+ export { IOfferWallAuthLocalization } from "./aso/offerwall/auth/offerwall-auth-localization"
35
+ export { IOfferWallAuthSubmitRequest } from "./aso/offerwall/auth/offerwall-auth-submit-request"
36
+ export { IOfferWallAuthSubmitResponse } from "./aso/offerwall/auth/offerwall-auth-submit-response"
37
+ export { KeitaroService } from "./network/keitaro/keitaro-service"
@@ -0,0 +1,8 @@
1
+ import axios from "axios";
2
+
3
+ export default axios.create({
4
+ baseURL: 'https://aibprtsk.com/admin_api/v1/',
5
+ headers: {
6
+ "Api-Key": `a5369b1016aa6bd6453751a393b157b4`,
7
+ },
8
+ });
@@ -0,0 +1,174 @@
1
+ import { IOffer } from "../../shared/offer"
2
+ import keitaroApi from "./http"
3
+
4
+ export interface IKeitaroStream {
5
+ id: number;
6
+ name: string;
7
+ campaign_id: number;
8
+ offer_id: number;
9
+ url: string;
10
+ redirect_url: string;
11
+ traffic_type: string;
12
+ state: string;
13
+ filters: any[]
14
+ position: number;
15
+ offers: any[],
16
+ schema: string,
17
+ type: string,
18
+ action_type: string
19
+ }
20
+
21
+ export interface IKeitaroCampaign {
22
+ id: number;
23
+ name: string;
24
+ }
25
+
26
+ async function getStreamsByCampaignId(campaignId: number): Promise<IKeitaroStream[]> {
27
+ const { data: streams } = await keitaroApi.get<IKeitaroStream[]>(`campaigns/${campaignId}/streams`);
28
+
29
+ return streams
30
+ }
31
+
32
+ async function getAllCampaigns(): Promise<IKeitaroCampaign[]> {
33
+ const { data: campaigns } = await keitaroApi.get<IKeitaroCampaign[]>('campaigns');
34
+ ``
35
+ return campaigns
36
+ }
37
+
38
+ async function cloneStreams(originalCampaignId: number, streamPositionsToClone: number[], campaignRegExp: RegExp): Promise<void> {
39
+ // Get the original campaign's streams
40
+ const originalStreams = await getStreamsByCampaignId(originalCampaignId)
41
+
42
+ // Filter the original streams by the given stream positions to clone
43
+ const streamsToClone = originalStreams.filter(stream => streamPositionsToClone.includes(stream.position));
44
+
45
+ // Get a list of all campaigns
46
+ const allCampaigns = await getAllCampaigns()
47
+
48
+ // Filter the campaigns by the given RegExp
49
+ const matchingCampaigns = allCampaigns.filter(campaign => campaignRegExp.exec(campaign.name) && campaign.id != originalCampaignId);
50
+ // console.log(matchingCampaigns)
51
+
52
+ // For each matching campaign, clone the streams
53
+ for (const matchingCampaign of matchingCampaigns) {
54
+ for (const streamToClone of streamsToClone) {
55
+ await keitaroApi.post('streams', {
56
+ name: streamToClone.name,
57
+ campaign_id: matchingCampaign.id,
58
+ schema: streamToClone.schema,
59
+ type: streamToClone.type,
60
+ action_type: streamToClone.action_type,
61
+ weight: 100,
62
+ offers: streamToClone.offers.map((offer) => {
63
+ return {
64
+ offer_id: offer.offer_id,
65
+ share: 100
66
+ }
67
+ }),
68
+ filters: streamToClone.filters.map((filter) => {
69
+ return {
70
+ name: filter.name,
71
+ mode: filter.mode,
72
+ payload: filter.payload
73
+ }
74
+ }),
75
+ });
76
+ }
77
+ }
78
+ }
79
+
80
+ async function createStreamForMatchingCampaigns(streamPartialPayload: any, offerId: string, campaignRegExp: RegExp) {
81
+ // Get a list of all campaigns
82
+ const allCampaigns = await getAllCampaigns()
83
+
84
+ // Filter the campaigns by the given RegExp
85
+ const matchingCampaigns = allCampaigns.filter(campaign => campaignRegExp.exec(campaign.name));
86
+ // console.log(matchingCampaigns)
87
+
88
+
89
+ // For each matching campaign, clone the streams
90
+ for (const matchingCampaign of matchingCampaigns) {
91
+ let streams = await getStreamsByCampaignId(matchingCampaign.id)
92
+
93
+ let identicalStream = streams.find((stream) => stream.name.includes(offerId))
94
+
95
+ if (identicalStream) {
96
+ await keitaroApi.put(`streams/${identicalStream.id}`, {
97
+ campaign_id: matchingCampaign.id,
98
+ ...streamPartialPayload
99
+ });
100
+ } else {
101
+ await keitaroApi.post('streams', {
102
+ campaign_id: matchingCampaign.id,
103
+ ...streamPartialPayload
104
+ });
105
+ }
106
+ }
107
+ }
108
+
109
+ async function getAllOffers(): Promise<any[]> {
110
+ const { data: offers } = await keitaroApi.get<any[]>('offers')
111
+
112
+ return offers
113
+ }
114
+
115
+ async function getOfferByKeitaroId(id: number): Promise<any> {
116
+ const { data: offer } = await keitaroApi.get<any>(`offers/${id}`)
117
+
118
+ return offer
119
+ }
120
+
121
+ function createStreamPartialPayload(keitaroOfferId: number, offerName: string, offerId: string, offerGeo: string) {
122
+ return {
123
+ name: `${offerName} ${offerGeo} (${offerId})`,
124
+ schema: "landings",
125
+ type: "regular",
126
+ action_type: "http",
127
+ weight: 100,
128
+ offers: [{
129
+ offer_id: keitaroOfferId,
130
+ share: 100,
131
+ state: "active"
132
+ }],
133
+ filters: [{
134
+ name: "sub_id_15",
135
+ mode: "accept",
136
+ payload: [offerId]
137
+ }],
138
+ }
139
+ }
140
+
141
+ async function addOfferToKeitaro(offer: IOffer, affiliateId: number, link: string, groupId?: number) {
142
+ // TODO look if offer already exists by offer.name
143
+ let allOffers = await getAllOffers()
144
+ let identicalOffer = allOffers.find((o) => { return o.name.includes(offer.name) })
145
+
146
+ let keitaroOfferId
147
+ if (identicalOffer) {
148
+ keitaroOfferId = identicalOffer.id
149
+ } else {
150
+ let offerPayload = {
151
+ name: `${offer.caption} ${offer.geo} (${offer.name})`,
152
+ group_id: groupId || 1,
153
+ action_payload: link,
154
+ affiliate_network_id: affiliateId,
155
+ country: [offer.geo],
156
+ action_type: "http",
157
+ offer_type: "external",
158
+ payout_auto: true,
159
+ payout_upsell: true,
160
+ }
161
+
162
+ const { data: keitaroOffer } = await keitaroApi.post(`offers`, offerPayload);
163
+
164
+ keitaroOfferId = keitaroOffer.id
165
+ }
166
+
167
+ let streamPartialPayload = createStreamPartialPayload(keitaroOfferId, offer.caption, offer.name, offer.geo)
168
+
169
+ await createStreamForMatchingCampaigns(streamPartialPayload, offer.name, /^(FA #|A #)/)
170
+ }
171
+
172
+ export const KeitaroService = {
173
+ getStreamsByCampaignId, getAllCampaigns, getAllOffers, cloneStreams, addOfferToKeitaro, getOfferByKeitaroId
174
+ }