Skip to content

Commit

Permalink
TW-1489: Smarty Ads integration (#170)
Browse files Browse the repository at this point in the history
* TW-1464 Prepare backend for new native ads

* TW-1464 Update API documentation

* TW-1464 Enable adding native ads in replace-only mode

* TW-1492 Add some properties for ads definitions

* TW-1492 Prepare the backend to additional fixtures for Mises

* TW-1492 Add an entrypoint for elements to hide or remove

* TW-1489 Add an entrypoints for categories of original ads providers
  • Loading branch information
keshan3262 authored Aug 27, 2024
1 parent acc023c commit b369658
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/advertising/external-ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const PERMANENT_AD_PLACES_RULES_KEY = 'permanent_ad_places_rules';
const PERMANENT_NATIVE_AD_PLACES_RULES_KEY = 'permanent_native_ad_places_rules';
const REPLACE_ADS_URLS_BLACKLIST_KEY = 'replace_ads_urls_blacklist';
const ELEMENTS_TO_HIDE_OR_REMOVE_KEY = 'elements_to_hide_or_remove';
const AD_PROVIDERS_CATEGORIES_KEY = 'ad_providers_categories';

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

Expand Down Expand Up @@ -205,6 +206,10 @@ export const elementsToHideOrRemoveMethods = objectStorageMethodsFactory<Element
[]
);

export const adProvidersCategoriesMethods = objectStorageMethodsFactory<string[]>(AD_PROVIDERS_CATEGORIES_KEY, [
'crypto'
]);

export const getAdProvidersForAllSites = async () => redisClient.smembers(AD_PROVIDERS_ALL_SITES_KEY);

export const addAdProvidersForAllSites = async (providers: string[]) =>
Expand Down
84 changes: 82 additions & 2 deletions src/routers/slise-ad-rules/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
adProvidersByDomainRulesMethods,
AdProviderSelectorsRule,
filterRules,
AdProvidersByDomainRule
AdProvidersByDomainRule,
adProvidersCategoriesMethods
} from '../../advertising/external-ads';
import { basicAuth } from '../../middlewares/basic-auth.middleware';
import { addObjectStorageMethodsToRouter, withBodyValidation, withExceptionHandler } from '../../utils/express-helpers';
Expand All @@ -18,7 +19,8 @@ import {
nonEmptyStringsListSchema,
hostnamesListSchema,
adProvidersByDomainsRulesDictionarySchema,
adProvidersDictionarySchema
adProvidersDictionarySchema,
adProvidersCategoriesDictionarySchema
} from '../../utils/schemas';

/**
Expand Down Expand Up @@ -116,6 +118,12 @@ import {
* type: array
* items:
* $ref: '#/components/schemas/AdProvidersInputValue'
* AdProvidersCategoriesDictionary:
* type: object
* additionalProperties:
* type: array
* items:
* type: string
*/

export const adProvidersRouter = Router();
Expand Down Expand Up @@ -328,6 +336,78 @@ addObjectStorageMethodsToRouter<AdProvidersByDomainRule[]>(adProvidersRouter, {
objectTransformFn: identity
});

/**
* @swagger
* /api/slise-ad-rules/providers/categories:
* get:
* summary: Get categories for providers
* tags:
* - Known ads providers
* responses:
* '200':
* description: Provider - categories dictionary
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/AdProvidersCategoriesDictionary'
* '500':
* $ref: '#/components/responses/ErrorResponse'
* post:
* summary: Upsert categories for providers
* tags:
* - Known ads providers
* security:
* - basicAuth: []
* requestBody:
* description: Provider - categories dictionary
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/AdProvidersCategoriesDictionary'
* responses:
* '200':
* $ref: '#/components/responses/SuccessResponse'
* '400':
* $ref: '#/components/responses/ErrorResponse'
* '401':
* $ref: '#/components/responses/UnauthorizedError'
* '500':
* $ref: '#/components/responses/ErrorResponse'
* delete:
* summary: Delete categories for providers
* tags:
* - Known ads providers
* security:
* - basicAuth: []
* requestBody:
* description: List of provider IDs for which categories should be deleted
* content:
* application/json:
* schema:
* type: array
* items:
* type: string
* responses:
* '200':
* $ref: '#/components/responses/SuccessResponse'
* '400':
* $ref: '#/components/responses/ErrorResponse'
* '401':
* $ref: '#/components/responses/UnauthorizedError'
* '500':
* $ref: '#/components/responses/ErrorResponse'
*/
addObjectStorageMethodsToRouter<string[]>(adProvidersRouter, {
path: '/categories',
methods: adProvidersCategoriesMethods,
keyName: 'providerId',
objectValidationSchema: adProvidersCategoriesDictionarySchema,
keysArrayValidationSchema: nonEmptyStringsListSchema,
successfulRemovalMessage: entriesCount => `${entriesCount} entries have been removed`,
valueTransformFn: identity,
objectTransformFn: identity
});

/**
* @swagger
* /api/slise-ad-rules/providers/negative-selectors:
Expand Down
5 changes: 5 additions & 0 deletions src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,8 @@ export const elementsToHideOrRemoveDictionarySchema = makeDictionarySchema<Eleme
hostnameSchema.clone().required(),
arraySchema().of(elementsToHideOrRemoveEntrySchema.clone().required()).required()
).required();

export const adProvidersCategoriesDictionarySchema = makeDictionarySchema<string[]>(
nonEmptyStringSchema.clone().required(),
arraySchema().of(nonEmptyStringSchema.clone().required()).required()
).required();

0 comments on commit b369658

Please sign in to comment.