diff --git a/src/advertising/slise.ts b/src/advertising/slise.ts index 89a6398..d94b614 100644 --- a/src/advertising/slise.ts +++ b/src/advertising/slise.ts @@ -66,6 +66,7 @@ export const stylePropsNames = [ 'right', 'text-align', 'top', + 'vertical-align', 'visibility', 'width', 'z-index' @@ -87,6 +88,7 @@ export interface SliseAdPlacesRule { divWrapperStyle?: Record; }; stylesOverrides?: SliseAdStylesOverrides[]; + shouldHideOriginal?: boolean; } export interface PermanentSliseAdPlacesRule { @@ -106,6 +108,7 @@ export interface PermanentSliseAdPlacesRule { insertAfterSelector?: string; insertionsCount?: number; shouldUseDivWrapper: boolean; + elementStyle?: Record; divWrapperStyle?: Record; elementToMeasureSelector?: string; stylesOverrides?: SliseAdStylesOverrides[]; @@ -122,34 +125,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 sliseAdPlacesRulesMethods = objectStorageMethodsFactory( + SLISE_AD_PLACES_RULES_KEY, + [] +); -export const { - getByKey: getSliseAdPlacesRulesByDomain, - getAllValues: getAllSliseAdPlacesRules, - upsertValues: upsertSliseAdPlacesRules, - removeValues: removeSliseAdPlacesRules -} = objectStorageMethodsFactory(SLISE_AD_PLACES_RULES_KEY, []); +export const sliseAdProvidersByDomainRulesMethods = objectStorageMethodsFactory( + SLISE_AD_PROVIDERS_BY_SITES_KEY, + [] +); -export const { - getByKey: getSliseAdProvidersByDomain, - getAllValues: getAllSliseAdProvidersBySites, - upsertValues: upsertSliseAdProvidersBySites, - removeValues: removeSliseAdProvidersBySites -} = objectStorageMethodsFactory(SLISE_AD_PROVIDERS_BY_SITES_KEY, []); +export const sliseAdProvidersMethods = objectStorageMethodsFactory(SLISE_AD_PROVIDERS_LIST_KEY, []); -export const { - getByKey: getSelectorsByProviderId, - getAllValues: getAllProviders, - upsertValues: upsertProviders, - removeValues: removeProviders -} = objectStorageMethodsFactory(SLISE_AD_PROVIDERS_LIST_KEY, []); +export const permanentSliseAdPlacesMethods = objectStorageMethodsFactory( + PERMANENT_SLISE_AD_PLACES_RULES_KEY, + [] +); -export const { - getByKey: getPermanentSliseAdPlacesRulesByDomain, - getAllValues: getAllPermanentSliseAdPlacesRules, - upsertValues: upsertPermanentSliseAdPlacesRules, - removeValues: removePermanentSliseAdPlacesRules -} = objectStorageMethodsFactory(PERMANENT_SLISE_AD_PLACES_RULES_KEY, []); +export const permanentNativeAdPlacesMethods = objectStorageMethodsFactory( + PERMANENT_NATIVE_AD_PLACES_RULES_KEY, + [] +); export const getSliseAdProvidersForAllSites = async () => redisClient.smembers(SLISE_AD_PROVIDERS_ALL_SITES_KEY); diff --git a/src/routers/slise-ad-rules/ad-places.ts b/src/routers/slise-ad-rules/ad-places.ts index e8d2f95..c3803b8 100644 --- a/src/routers/slise-ad-rules/ad-places.ts +++ b/src/routers/slise-ad-rules/ad-places.ts @@ -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 { @@ -87,6 +82,10 @@ import { * type: array * items: * $ref: '#/components/schemas/SliseAdStylesOverrides' + * shouldHideOriginal: + * type: boolean + * description: Whether original ads banners should be hidden but not removed + * default: false * example: * urlRegexes: * - '^https://goerli\.etherscan\.io/?$' @@ -210,6 +209,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 @@ -263,6 +267,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}: @@ -354,12 +456,7 @@ export const sliseAdPlacesRulesRouter = Router(); addObjectStorageMethodsToRouter( sliseAdPlacesRulesRouter, '/permanent', - { - getByKey: getPermanentSliseAdPlacesRulesByDomain, - getAllValues: getAllPermanentSliseAdPlacesRules, - upsertValues: upsertPermanentSliseAdPlacesRules, - removeValues: removePermanentSliseAdPlacesRules - }, + permanentSliseAdPlacesMethods, 'domain', permanentSliseAdPlacesRulesDictionarySchema, hostnamesListSchema, @@ -457,12 +554,7 @@ addObjectStorageMethodsToRouter( addObjectStorageMethodsToRouter( sliseAdPlacesRulesRouter, '/', - { - getByKey: getSliseAdPlacesRulesByDomain, - getAllValues: getAllSliseAdPlacesRules, - upsertValues: upsertSliseAdPlacesRules, - removeValues: removeSliseAdPlacesRules - }, + sliseAdPlacesRulesMethods, 'domain', sliseAdPlacesRulesDictionarySchema, hostnamesListSchema, diff --git a/src/routers/slise-ad-rules/providers.ts b/src/routers/slise-ad-rules/providers.ts index 19f8978..67129e7 100644 --- a/src/routers/slise-ad-rules/providers.ts +++ b/src/routers/slise-ad-rules/providers.ts @@ -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'; @@ -277,12 +271,7 @@ sliseAdProvidersRouter addObjectStorageMethodsToRouter( sliseAdProvidersRouter, '/by-sites', - { - getAllValues: getAllSliseAdProvidersBySites, - getByKey: getSliseAdProvidersByDomain, - upsertValues: upsertSliseAdProvidersBySites, - removeValues: removeSliseAdProvidersBySites - }, + sliseAdProvidersByDomainRulesMethods, 'domain', sliseAdProvidersByDomainsRulesDictionarySchema, hostnamesListSchema, @@ -383,12 +372,7 @@ addObjectStorageMethodsToRouter( addObjectStorageMethodsToRouter( sliseAdProvidersRouter, '/', - { - getAllValues: getAllProviders, - getByKey: getSelectorsByProviderId, - upsertValues: upsertProviders, - removeValues: removeProviders - }, + sliseAdProvidersMethods, 'providerId', sliseAdProvidersDictionarySchema, adTypesListSchema, diff --git a/src/utils/schemas.ts b/src/utils/schemas.ts index 5497f1b..d8bff7e 100644 --- a/src/utils/schemas.ts +++ b/src/utils/schemas.ts @@ -115,7 +115,8 @@ const sliseAdPlacesRulesSchema = arraySchema() divWrapperStyle: styleSchema }) .required(), - stylesOverrides: arraySchema().of(sliseAdStylesOverridesSchema.clone().required()) + stylesOverrides: arraySchema().of(sliseAdStylesOverridesSchema.clone().required()), + shouldHideOriginal: booleanSchema().default(false) }) .required() ) @@ -148,6 +149,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()),