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

Release everything to prod #150

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
52 changes: 27 additions & 25 deletions src/advertising/slise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const stylePropsNames = [
'alignment-baseline',
'aspect-ratio',
'background',
'border',
'border-radius',
'bottom',
'box-shadow',
Expand Down Expand Up @@ -66,9 +67,13 @@ export const stylePropsNames = [
'right',
'text-align',
'top',
'vertical-align',
'visibility',
'width',
'z-index'
'z-index',
'background-image',
'background-clip',
'background-color'
];
export type StylePropName = (typeof stylePropsNames)[number];

Expand All @@ -87,6 +92,7 @@ export interface SliseAdPlacesRule {
divWrapperStyle?: Record<StylePropName, string>;
};
stylesOverrides?: SliseAdStylesOverrides[];
shouldHideOriginal?: boolean;
}

export interface PermanentSliseAdPlacesRule {
Expand All @@ -106,6 +112,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 +129,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<SliseAdPlacesRule[]>(
SLISE_AD_PLACES_RULES_KEY,
[]
);

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

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

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

export const {
getByKey: getPermanentSliseAdPlacesRulesByDomain,
getAllValues: getAllPermanentSliseAdPlacesRules,
upsertValues: upsertPermanentSliseAdPlacesRules,
removeValues: removePermanentSliseAdPlacesRules
} = 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
132 changes: 112 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 @@ -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/?$'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}:
Expand Down Expand Up @@ -354,12 +456,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 +554,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
4 changes: 3 additions & 1 deletion src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down Expand Up @@ -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()),
Expand Down
Loading