Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1290 Add an entrypoint for native ads #144

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 21 additions & 24 deletions src/advertising/slise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const stylePropsNames = [
'right',
'text-align',
'top',
'vertical-align',
'visibility',
'width',
'z-index'
Expand Down Expand Up @@ -106,6 +107,7 @@ export interface PermanentSliseAdPlacesRule {
insertAfterSelector?: string;
insertionsCount?: number;
shouldUseDivWrapper: boolean;
elementStyle?: Record<StylePropName, string>;
divWrapperStyle?: Record<StylePropName, string>;
elementToMeasureSelector?: string;
stylesOverrides?: SliseAdStylesOverrides[];
Expand All @@ -122,34 +124,29 @@ const SLISE_AD_PROVIDERS_BY_SITES_KEY = 'slise_ad_providers_by_sites';
const SLISE_AD_PROVIDERS_ALL_SITES_KEY = 'slise_ad_providers_all_sites';
const SLISE_AD_PROVIDERS_LIST_KEY = 'slise_ad_providers_list';
const PERMANENT_SLISE_AD_PLACES_RULES_KEY = 'permanent_slise_ad_places_rules';
const PERMANENT_NATIVE_AD_PLACES_RULES_KEY = 'permanent_native_ad_places_rules';

export const {
getByKey: getSliseAdPlacesRulesByDomain,
getAllValues: getAllSliseAdPlacesRules,
upsertValues: upsertSliseAdPlacesRules,
removeValues: removeSliseAdPlacesRules
} = objectStorageMethodsFactory<SliseAdPlacesRule[]>(SLISE_AD_PLACES_RULES_KEY, []);
export const sliseAdPlacesRulesMethods = objectStorageMethodsFactory<SliseAdPlacesRule[]>(
SLISE_AD_PLACES_RULES_KEY,
[]
);

export const {
getByKey: getSliseAdProvidersByDomain,
getAllValues: getAllSliseAdProvidersBySites,
upsertValues: upsertSliseAdProvidersBySites,
removeValues: removeSliseAdProvidersBySites
} = objectStorageMethodsFactory<SliseAdProvidersByDomainRule[]>(SLISE_AD_PROVIDERS_BY_SITES_KEY, []);
export const sliseAdProvidersByDomainRulesMethods = objectStorageMethodsFactory<SliseAdProvidersByDomainRule[]>(
SLISE_AD_PROVIDERS_BY_SITES_KEY,
[]
);

export const {
getByKey: getSelectorsByProviderId,
getAllValues: getAllProviders,
upsertValues: upsertProviders,
removeValues: removeProviders
} = objectStorageMethodsFactory<string[]>(SLISE_AD_PROVIDERS_LIST_KEY, []);
export const sliseAdProvidersMethods = objectStorageMethodsFactory<string[]>(SLISE_AD_PROVIDERS_LIST_KEY, []);

export const {
getByKey: getPermanentSliseAdPlacesRulesByDomain,
getAllValues: getAllPermanentSliseAdPlacesRules,
upsertValues: upsertPermanentSliseAdPlacesRules,
removeValues: removePermanentSliseAdPlacesRules
} = objectStorageMethodsFactory<PermanentSliseAdPlacesRule[]>(PERMANENT_SLISE_AD_PLACES_RULES_KEY, []);
export const permanentSliseAdPlacesMethods = objectStorageMethodsFactory<PermanentSliseAdPlacesRule[]>(
PERMANENT_SLISE_AD_PLACES_RULES_KEY,
[]
);

export const permanentNativeAdPlacesMethods = objectStorageMethodsFactory<PermanentSliseAdPlacesRule[]>(
PERMANENT_NATIVE_AD_PLACES_RULES_KEY,
[]
);

export const getSliseAdProvidersForAllSites = async () => redisClient.smembers(SLISE_AD_PROVIDERS_ALL_SITES_KEY);

Expand Down
128 changes: 108 additions & 20 deletions src/routers/slise-ad-rules/ad-places.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { Router } from 'express';

import {
getAllPermanentSliseAdPlacesRules,
getAllSliseAdPlacesRules,
getPermanentSliseAdPlacesRulesByDomain,
getSliseAdPlacesRulesByDomain,
removePermanentSliseAdPlacesRules,
removeSliseAdPlacesRules,
upsertPermanentSliseAdPlacesRules,
upsertSliseAdPlacesRules
permanentNativeAdPlacesMethods,
permanentSliseAdPlacesMethods,
sliseAdPlacesRulesMethods
} from '../../advertising/slise';
import { addObjectStorageMethodsToRouter } from '../../utils/express-helpers';
import {
Expand Down Expand Up @@ -210,6 +205,11 @@ import {
* shouldUseDivWrapper:
* type: boolean
* description: Whether the Slise ads banner should be wrapped in a div
* elementStyle:
* type: object
* description: Style of the new ad banner
* additionalProperties:
* type: string
* divWrapperStyle:
* type: object
* description: Style of the div wrapper
Expand Down Expand Up @@ -263,6 +263,104 @@ import {

export const sliseAdPlacesRulesRouter = Router();

/**
* @swagger
* /api/slise-ad-rules/ad-places/permanent-native/{domain}:
* get:
* summary: Get rules for permanent native ads places for the specified domain
* tags:
* - Slise ad places
* parameters:
* - in: path
* name: domain
* required: true
* schema:
* type: string
* format: hostname
* example: 'etherscan.io'
* responses:
* '200':
* description: Rules list
* content:
* application/json:
* schema:
* type: array
* items:
* $ref: '#/components/schemas/PermanentSliseAdPlacesRule'
* '500':
* $ref: '#/components/responses/ErrorResponse'
* /api/slise-ad-rules/ad-places/permanent-native:
* get:
* summary: Get all rules for permanent native ads places
* tags:
* - Slise ad places
* responses:
* '200':
* description: Domain - rules list dictionary
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/PermanentSliseAdPlacesRulesDictionary'
* '500':
* $ref: '#/components/responses/ErrorResponse'
* post:
* summary: Add rules for permanent ads places. If rules for a domain already exist, they will be overwritten
* tags:
* - Slise ad places
* security:
* - basicAuth: []
* requestBody:
* description: Domain - rules list dictionary
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/PermanentSliseAdPlacesRulesDictionary'
* responses:
* '200':
* $ref: '#/components/responses/SuccessResponse'
* '400':
* $ref: '#/components/responses/ErrorResponse'
* '401':
* $ref: '#/components/responses/UnauthorizedError'
* '500':
* $ref: '#/components/responses/ErrorResponse'
* delete:
* summary: Remove rules for permanent ads places
* tags:
* - Slise ad places
* security:
* - basicAuth: []
* requestBody:
* description: List of domain names to remove rules for
* content:
* application/json:
* schema:
* type: array
* items:
* type: string
* format: hostname
* example:
* - 'etherscan.io'
* responses:
* '200':
* $ref: '#/components/responses/SuccessResponse'
* '400':
* $ref: '#/components/responses/ErrorResponse'
* '401':
* $ref: '#/components/responses/UnauthorizedError'
* '500':
* $ref: '#/components/responses/ErrorResponse'
*/
addObjectStorageMethodsToRouter(
sliseAdPlacesRulesRouter,
'/permanent-native',
permanentNativeAdPlacesMethods,
'domain',
permanentSliseAdPlacesRulesDictionarySchema,
hostnamesListSchema,
entriesCount => `${entriesCount} entries have been removed`
);

/**
* @swagger
* /api/slise-ad-rules/ad-places/permanent/{domain}:
Expand Down Expand Up @@ -354,12 +452,7 @@ export const sliseAdPlacesRulesRouter = Router();
addObjectStorageMethodsToRouter(
sliseAdPlacesRulesRouter,
'/permanent',
{
getByKey: getPermanentSliseAdPlacesRulesByDomain,
getAllValues: getAllPermanentSliseAdPlacesRules,
upsertValues: upsertPermanentSliseAdPlacesRules,
removeValues: removePermanentSliseAdPlacesRules
},
permanentSliseAdPlacesMethods,
'domain',
permanentSliseAdPlacesRulesDictionarySchema,
hostnamesListSchema,
Expand Down Expand Up @@ -457,12 +550,7 @@ addObjectStorageMethodsToRouter(
addObjectStorageMethodsToRouter(
sliseAdPlacesRulesRouter,
'/',
{
getByKey: getSliseAdPlacesRulesByDomain,
getAllValues: getAllSliseAdPlacesRules,
upsertValues: upsertSliseAdPlacesRules,
removeValues: removeSliseAdPlacesRules
},
sliseAdPlacesRulesMethods,
'domain',
sliseAdPlacesRulesDictionarySchema,
hostnamesListSchema,
Expand Down
24 changes: 4 additions & 20 deletions src/routers/slise-ad-rules/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ import { Router } from 'express';

import {
addSliseAdProvidersForAllSites,
getAllProviders,
getAllSliseAdProvidersBySites,
getSelectorsByProviderId,
getSliseAdProvidersByDomain,
getSliseAdProvidersForAllSites,
removeProviders,
removeSliseAdProvidersBySites,
removeSliseAdProvidersForAllSites,
upsertProviders,
upsertSliseAdProvidersBySites
sliseAdProvidersMethods,
sliseAdProvidersByDomainRulesMethods
} from '../../advertising/slise';
import { basicAuth } from '../../middlewares/basic-auth.middleware';
import { addObjectStorageMethodsToRouter, withBodyValidation, withExceptionHandler } from '../../utils/express-helpers';
Expand Down Expand Up @@ -277,12 +271,7 @@ sliseAdProvidersRouter
addObjectStorageMethodsToRouter(
sliseAdProvidersRouter,
'/by-sites',
{
getAllValues: getAllSliseAdProvidersBySites,
getByKey: getSliseAdProvidersByDomain,
upsertValues: upsertSliseAdProvidersBySites,
removeValues: removeSliseAdProvidersBySites
},
sliseAdProvidersByDomainRulesMethods,
'domain',
sliseAdProvidersByDomainsRulesDictionarySchema,
hostnamesListSchema,
Expand Down Expand Up @@ -383,12 +372,7 @@ addObjectStorageMethodsToRouter(
addObjectStorageMethodsToRouter(
sliseAdProvidersRouter,
'/',
{
getAllValues: getAllProviders,
getByKey: getSelectorsByProviderId,
upsertValues: upsertProviders,
removeValues: removeProviders
},
sliseAdProvidersMethods,
'providerId',
sliseAdProvidersDictionarySchema,
adTypesListSchema,
Expand Down
1 change: 1 addition & 0 deletions src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const permanentSliseAdPlacesRulesSchema = arraySchema()
insertAfterSelector: cssSelectorSchema,
insertionsCount: numberSchema().integer().min(1).default(1),
shouldUseDivWrapper: booleanSchema().required(),
elementStyle: styleSchema,
divWrapperStyle: styleSchema,
elementToMeasureSelector: cssSelectorSchema,
stylesOverrides: arraySchema().of(sliseAdStylesOverridesSchema.clone().required()),
Expand Down
Loading