Skip to content

Commit 0776a75

Browse files
authored
Release TW Mobile v1.28 (#161)
Merge pull request #161 from madfish-solutions/development
2 parents c53b637 + 05e6803 commit 0776a75

File tree

13 files changed

+375
-58
lines changed

13 files changed

+375
-58
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@types/express": "^4.17.17",
5454
"@types/express-jwt": "^7.4.2",
5555
"@types/express-unless": "^2.0.1",
56+
"@types/lodash": "^4.17.0",
5657
"@types/memoizee": "^0.4.5",
5758
"@types/node": "^18.14.6",
5859
"@types/pino": "^6.3.8",

src/advertising/external-ads.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ interface AdStylesOverrides {
8484
style: Record<StylePropName, string>;
8585
}
8686

87-
interface ExtVersionConstraints {
87+
export interface ExtVersionConstraints {
8888
extVersion: string;
8989
}
9090

@@ -132,18 +132,24 @@ export interface AdProvidersByDomainRule extends ExtVersionConstraints {
132132

133133
export interface AdProviderSelectorsRule extends ExtVersionConstraints {
134134
selectors: string[];
135+
parentDepth?: number;
135136
}
136137

137138
export interface AdProviderForAllSitesRule extends ExtVersionConstraints {
138139
providers: string[];
139140
}
140141

142+
export interface ReplaceAdsUrlsBlacklistEntry extends ExtVersionConstraints {
143+
regexes: string[];
144+
}
145+
141146
const AD_PLACES_RULES_KEY = 'ad_places_rules';
142147
const AD_PROVIDERS_BY_SITES_KEY = 'ad_providers_by_sites';
143148
const AD_PROVIDERS_ALL_SITES_KEY = 'ad_providers_all_sites';
144149
const AD_PROVIDERS_LIST_KEY = 'ad_providers_list';
145150
const PERMANENT_AD_PLACES_RULES_KEY = 'permanent_ad_places_rules';
146151
const PERMANENT_NATIVE_AD_PLACES_RULES_KEY = 'permanent_native_ad_places_rules';
152+
const REPLACE_ADS_URLS_BLACKLIST_KEY = 'replace_ads_urls_blacklist';
147153

148154
export const adPlacesRulesMethods = objectStorageMethodsFactory<AdPlacesRule[]>(AD_PLACES_RULES_KEY, []);
149155

@@ -164,6 +170,11 @@ export const permanentNativeAdPlacesMethods = objectStorageMethodsFactory<Perman
164170
[]
165171
);
166172

173+
export const replaceAdsUrlsBlacklistMethods = objectStorageMethodsFactory<ReplaceAdsUrlsBlacklistEntry[]>(
174+
REPLACE_ADS_URLS_BLACKLIST_KEY,
175+
[]
176+
);
177+
167178
export const getAdProvidersForAllSites = async () => redisClient.smembers(AD_PROVIDERS_ALL_SITES_KEY);
168179

169180
export const addAdProvidersForAllSites = async (providers: string[]) =>

src/getDAppsStats.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { dappList } from './utils/dapp-list-constants';
1+
import { DAPPS_LIST, IOS_DAPPS_LIST } from './utils/dapp-list-constants';
22
import logger from './utils/logger';
33

4-
const getDAppsStats = async () => {
4+
const getDAppsStats = (forIOs: boolean) => {
55
logger.info('Getting dApps list...');
66

77
return {
8-
dApps: dappList
8+
dApps: forIOs ? IOS_DAPPS_LIST : DAPPS_LIST
99
};
1010
};
1111

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ app.use(pinoHttp(PINO_LOGGER));
6666
app.use(cors());
6767
app.use(bodyParser.json());
6868

69-
const dAppsProvider = new SingleQueryDataProvider(15 * 60 * 1000, getDAppsStats);
70-
7169
const androidApp = firebaseAdmin.initializeApp(
7270
{
7371
projectId: 'templewallet-fa3b3'
@@ -162,7 +160,13 @@ app.post('/api/notifications', basicAuth, async (req, res) => {
162160
}
163161
});
164162

165-
app.get('/api/dapps', makeProviderDataRequestHandler(dAppsProvider));
163+
app.get('/api/dapps', (req, res) => {
164+
const platform = req.query.platform;
165+
166+
const data = getDAppsStats(platform === 'ios');
167+
168+
res.status(200).header('Cache-Control', 'public, max-age=300').send(data);
169+
});
166170

167171
app.get('/api/abtest', (_, res) => {
168172
const data = getABData();

src/routers/slise-ad-rules/ad-places.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
import { Router } from 'express';
1+
import { Request, Router } from 'express';
22

33
import {
44
filterByVersion,
55
permanentNativeAdPlacesMethods,
66
permanentAdPlacesMethods,
7-
adPlacesRulesMethods
7+
adPlacesRulesMethods,
8+
PermanentAdPlacesRule,
9+
AdPlacesRule,
10+
ExtVersionConstraints
811
} from '../../advertising/external-ads';
912
import { addObjectStorageMethodsToRouter } from '../../utils/express-helpers';
13+
import { transformValues } from '../../utils/helpers';
1014
import {
1115
hostnamesListSchema,
1216
permanentAdPlacesRulesDictionarySchema,
1317
adPlacesRulesDictionarySchema
1418
} from '../../utils/schemas';
1519

20+
const transformAdPlaces = <T extends ExtVersionConstraints>(value: T[], req: Request) =>
21+
filterByVersion(value, req.query.extVersion as string | undefined);
22+
const transformAdPlacesDictionary = <T extends ExtVersionConstraints>(rules: Record<string, T[]>, req: Request) =>
23+
transformValues(rules, value => transformAdPlaces(value, req));
24+
1625
/**
1726
* @swagger
1827
* tags:
@@ -68,13 +77,14 @@ import {
6877
* type: string
6978
* ExtVersionConstraints:
7079
* type: object
80+
* required:
81+
* - extVersion
7182
* properties:
7283
* extVersion:
7384
* type: string
7485
* description: >
7586
* A range of versions where the rule is applicable. If not specified, the rule is applicable
7687
* for all versions. See the [ranges format](https://www.npmjs.com/package/semver#ranges)
77-
* default: '*'
7888
* AdPlacesRule:
7989
* allOf:
8090
* - $ref: '#/components/schemas/ExtVersionConstraints'
@@ -420,14 +430,15 @@ export const adPlacesRulesRouter = Router();
420430
* '500':
421431
* $ref: '#/components/responses/ErrorResponse'
422432
*/
423-
addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
433+
addObjectStorageMethodsToRouter<PermanentAdPlacesRule[]>(adPlacesRulesRouter, {
424434
path: '/permanent-native',
425435
methods: permanentNativeAdPlacesMethods,
426436
keyName: 'domain',
427437
objectValidationSchema: permanentAdPlacesRulesDictionarySchema,
428438
keysArrayValidationSchema: hostnamesListSchema,
429439
successfulRemovalMessage: entriesCount => `${entriesCount} entries have been removed`,
430-
transformGotValueFn: (value, req) => filterByVersion(value, req.query.extVersion as string | undefined)
440+
valueTransformFn: transformAdPlaces,
441+
objectTransformFn: transformAdPlacesDictionary
431442
});
432443

433444
/**
@@ -569,14 +580,15 @@ addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
569580
* '500':
570581
* $ref: '#/components/responses/ErrorResponse'
571582
*/
572-
addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
583+
addObjectStorageMethodsToRouter<PermanentAdPlacesRule[]>(adPlacesRulesRouter, {
573584
path: '/permanent',
574585
methods: permanentAdPlacesMethods,
575586
keyName: 'domain',
576587
objectValidationSchema: permanentAdPlacesRulesDictionarySchema,
577588
keysArrayValidationSchema: hostnamesListSchema,
578589
successfulRemovalMessage: entriesCount => `${entriesCount} entries have been removed`,
579-
transformGotValueFn: (value, req) => filterByVersion(value, req.query.extVersion as string | undefined)
590+
valueTransformFn: transformAdPlaces,
591+
objectTransformFn: transformAdPlacesDictionary
580592
});
581593

582594
/**
@@ -718,12 +730,13 @@ addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
718730
* '500':
719731
* $ref: '#/components/responses/ErrorResponse'
720732
*/
721-
addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
733+
addObjectStorageMethodsToRouter<AdPlacesRule[]>(adPlacesRulesRouter, {
722734
path: '/',
723735
methods: adPlacesRulesMethods,
724736
keyName: 'domain',
725737
objectValidationSchema: adPlacesRulesDictionarySchema,
726738
keysArrayValidationSchema: hostnamesListSchema,
727739
successfulRemovalMessage: entriesCount => `${entriesCount} entries have been removed`,
728-
transformGotValueFn: (value, req) => filterByVersion(value, req.query.extVersion as string | undefined)
740+
valueTransformFn: transformAdPlaces,
741+
objectTransformFn: transformAdPlacesDictionary
729742
});

src/routers/slise-ad-rules/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Router } from 'express';
22

33
import { adPlacesRulesRouter } from './ad-places';
44
import { adProvidersRouter } from './providers';
5+
import { replaceUrlsBlacklistRouter } from './replace-urls-blacklist';
56

67
/**
78
* @swagger
@@ -41,3 +42,4 @@ export const adRulesRouter = Router();
4142

4243
adRulesRouter.use('/ad-places', adPlacesRulesRouter);
4344
adRulesRouter.use('/providers', adProvidersRouter);
45+
adRulesRouter.use('/replace-urls-blacklist', replaceUrlsBlacklistRouter);

src/routers/slise-ad-rules/providers.ts

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Router } from 'express';
1+
import { Request, Router } from 'express';
2+
import { identity } from 'lodash';
23

34
import {
45
addAdProvidersForAllSites,
@@ -7,12 +8,14 @@ import {
78
adProvidersMethods,
89
adProvidersByDomainRulesMethods,
910
AdProviderSelectorsRule,
10-
filterByVersion
11+
filterByVersion,
12+
AdProvidersByDomainRule
1113
} from '../../advertising/external-ads';
1214
import { basicAuth } from '../../middlewares/basic-auth.middleware';
1315
import { addObjectStorageMethodsToRouter, withBodyValidation, withExceptionHandler } from '../../utils/express-helpers';
16+
import { isDefined, transformValues } from '../../utils/helpers';
1417
import {
15-
adTypesListSchema,
18+
nonEmptyStringsListSchema,
1619
hostnamesListSchema,
1720
adProvidersByDomainsRulesDictionarySchema,
1821
adProvidersDictionarySchema
@@ -69,17 +72,36 @@ import {
6972
* type: array
7073
* items:
7174
* type: string
75+
* parentDepth:
76+
* type: integer
77+
* minimum: 0
78+
* default: 0
79+
* AdByProviderSelector:
80+
* oneOf:
81+
* - type: string
82+
* - type: object
83+
* required:
84+
* - selector
85+
* - parentDepth
86+
* properties:
87+
* selector:
88+
* type: string
89+
* parentDepth:
90+
* type: integer
7291
* AdProvidersDictionary:
7392
* type: object
7493
* additionalProperties:
7594
* type: array
7695
* items:
77-
* type: string
96+
* $ref: '#/components/schemas/AdByProviderSelector'
7897
* example:
7998
* google:
8099
* - '#Ads_google_bottom_wide'
81100
* - '.GoogleAdInfo'
82101
* - 'a[href^="https://googleads.g.doubleclick.net/pcs/click"]'
102+
* persona:
103+
* - selector: "a.persona-product"
104+
* parentDepth: 1
83105
* AdProvidersInputsDictionary:
84106
* type: object
85107
* additionalProperties:
@@ -178,7 +200,7 @@ adProvidersRouter
178200
.post(
179201
basicAuth,
180202
withExceptionHandler(
181-
withBodyValidation(adTypesListSchema, async (req, res) => {
203+
withBodyValidation(nonEmptyStringsListSchema, async (req, res) => {
182204
const providersAddedCount = await addAdProvidersForAllSites(req.body);
183205

184206
res.status(200).send({ message: `${providersAddedCount} providers have been added` });
@@ -188,7 +210,7 @@ adProvidersRouter
188210
.delete(
189211
basicAuth,
190212
withExceptionHandler(
191-
withBodyValidation(adTypesListSchema, async (req, res) => {
213+
withBodyValidation(nonEmptyStringsListSchema, async (req, res) => {
192214
const providersRemovedCount = await removeAdProvidersForAllSites(req.body);
193215

194216
res.status(200).send({ message: `${providersRemovedCount} providers have been removed` });
@@ -287,13 +309,15 @@ adProvidersRouter
287309
* '500':
288310
* $ref: '#/components/responses/ErrorResponse'
289311
*/
290-
addObjectStorageMethodsToRouter(adProvidersRouter, {
312+
addObjectStorageMethodsToRouter<AdProvidersByDomainRule[]>(adProvidersRouter, {
291313
path: '/by-sites',
292314
methods: adProvidersByDomainRulesMethods,
293315
keyName: 'domain',
294316
objectValidationSchema: adProvidersByDomainsRulesDictionarySchema,
295317
keysArrayValidationSchema: hostnamesListSchema,
296-
successfulRemovalMessage: entriesCount => `${entriesCount} entries have been removed`
318+
successfulRemovalMessage: entriesCount => `${entriesCount} entries have been removed`,
319+
valueTransformFn: identity,
320+
objectTransformFn: identity
297321
});
298322

299323
/**
@@ -361,11 +385,13 @@ addObjectStorageMethodsToRouter(adProvidersRouter, {
361385
* schema:
362386
* type: array
363387
* items:
364-
* type: string
388+
* $ref: '#/components/schemas/AdByProviderSelector'
365389
* example:
366390
* - '#Ads_google_bottom_wide'
367391
* - '.GoogleAdInfo'
368392
* - 'a[href^="https://googleads.g.doubleclick.net/pcs/click"]'
393+
* - selector: "a.persona-product"
394+
* parentDepth: 1
369395
* '500':
370396
* $ref: '#/components/responses/ErrorResponse'
371397
* /api/slise-ad-rules/providers:
@@ -437,19 +463,30 @@ addObjectStorageMethodsToRouter(adProvidersRouter, {
437463
* '500':
438464
* $ref: '#/components/responses/ErrorResponse'
439465
*/
440-
addObjectStorageMethodsToRouter<AdProviderSelectorsRule[], string[]>(adProvidersRouter, {
466+
const transformAdProviderSelectorsRules = (rules: AdProviderSelectorsRule[], req: Request) =>
467+
Array.from(
468+
new Set(
469+
filterByVersion(rules, req.query.extVersion as string | undefined)
470+
.map(({ selectors, parentDepth }) =>
471+
isDefined(parentDepth) && parentDepth > 0 ? { selector: selectors.join(', '), parentDepth } : selectors
472+
)
473+
.flat()
474+
)
475+
);
476+
477+
type AdByProviderSelector = string | { selector: string; parentDepth: number };
478+
479+
addObjectStorageMethodsToRouter<
480+
AdProviderSelectorsRule[],
481+
Record<string, AdByProviderSelector[]>,
482+
AdByProviderSelector[]
483+
>(adProvidersRouter, {
441484
path: '/',
442485
methods: adProvidersMethods,
443486
keyName: 'providerId',
444487
objectValidationSchema: adProvidersDictionarySchema,
445-
keysArrayValidationSchema: adTypesListSchema,
488+
keysArrayValidationSchema: nonEmptyStringsListSchema,
446489
successfulRemovalMessage: entriesCount => `${entriesCount} providers have been removed`,
447-
transformGotValueFn: (rules, req) =>
448-
Array.from(
449-
new Set(
450-
filterByVersion(rules, req.query.extVersion as string | undefined)
451-
.map(({ selectors }) => selectors)
452-
.flat()
453-
)
454-
)
490+
valueTransformFn: transformAdProviderSelectorsRules,
491+
objectTransformFn: (rules, req) => transformValues(rules, value => transformAdProviderSelectorsRules(value, req))
455492
});

0 commit comments

Comments
 (0)