Skip to content

Commit

Permalink
TW-1364 Remove migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
keshan3262 committed Apr 11, 2024
1 parent 16c25e3 commit 7e0139b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 67 deletions.
21 changes: 9 additions & 12 deletions src/advertising/external-ads.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { satisfies as versionSatisfiesRange } from 'semver';

import { objectStorageMethodsFactory, redisClient } from '../redis';
import { isDefined } from '../utils/helpers';

/** Style properties names that are likely to be unnecessary for banners are skipped */
export const stylePropsNames = [
Expand Down Expand Up @@ -86,7 +85,7 @@ interface AdStylesOverrides {
}

interface ExtVersionConstraints {
extVersion?: string;
extVersion: string;
}

export interface AdPlacesRule extends ExtVersionConstraints {
Expand Down Expand Up @@ -139,12 +138,11 @@ export interface AdProviderForAllSitesRule extends ExtVersionConstraints {
providers: string[];
}

const AD_PLACES_RULES_KEY = 'slise_ad_places_rules';
const AD_PROVIDERS_BY_SITES_KEY = 'slise_ad_providers_by_sites';
const AD_PROVIDERS_ALL_SITES_KEY = 'slise_ad_providers_all_sites';
const SLISE_AD_PROVIDERS_LIST_KEY = 'slise_ad_providers_list';
const AD_PLACES_RULES_KEY = 'ad_places_rules';
const AD_PROVIDERS_BY_SITES_KEY = 'ad_providers_by_sites';
const AD_PROVIDERS_ALL_SITES_KEY = 'ad_providers_all_sites';
const AD_PROVIDERS_LIST_KEY = 'ad_providers_list';
const PERMANENT_AD_PLACES_RULES_KEY = 'permanent_slise_ad_places_rules';
const PERMANENT_AD_PLACES_RULES_KEY = 'permanent_ad_places_rules';
const PERMANENT_NATIVE_AD_PLACES_RULES_KEY = 'permanent_native_ad_places_rules';

export const adPlacesRulesMethods = objectStorageMethodsFactory<AdPlacesRule[]>(AD_PLACES_RULES_KEY, []);
Expand All @@ -154,9 +152,6 @@ export const adProvidersByDomainRulesMethods = objectStorageMethodsFactory<AdPro
[]
);

/** @deprecated */
export const adProvidersMethodsLegacy = objectStorageMethodsFactory<string[]>(SLISE_AD_PROVIDERS_LIST_KEY, []);

export const adProvidersMethods = objectStorageMethodsFactory<AdProviderSelectorsRule[]>(AD_PROVIDERS_LIST_KEY, []);

export const permanentAdPlacesMethods = objectStorageMethodsFactory<PermanentAdPlacesRule[]>(
Expand All @@ -177,5 +172,7 @@ export const addAdProvidersForAllSites = async (providers: string[]) =>
export const removeAdProvidersForAllSites = async (providers: string[]) =>
redisClient.srem(AD_PROVIDERS_ALL_SITES_KEY, ...providers);

export const filterByVersion = <T extends ExtVersionConstraints>(rules: T[], version = '1.20.1') =>
rules.filter(({ extVersion }) => !isDefined(extVersion) || versionSatisfiesRange(version, extVersion));
const FALLBACK_VERSION = '0.0.0';

export const filterByVersion = <T extends ExtVersionConstraints>(rules: T[], version?: string) =>
rules.filter(({ extVersion }) => versionSatisfiesRange(version ?? FALLBACK_VERSION, extVersion));
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { CodedError } from './utils/errors';
import { coinGeckoTokens } from './utils/gecko-tokens';
import { getExternalApiErrorPayload, isDefined, isNonEmptyString } from './utils/helpers';
import logger from './utils/logger';
import { doMigrations } from './utils/migrations';
import { getSignedMoonPayUrl } from './utils/moonpay/get-signed-moonpay-url';
import { getSigningNonce } from './utils/signing-nonce';
import SingleQueryDataProvider from './utils/SingleQueryDataProvider';
Expand Down Expand Up @@ -103,11 +102,6 @@ const makeProviderDataRequestHandler = <T, U>(provider: SingleQueryDataProvider<
};
};

doMigrations().catch(error => {
console.error(error);
process.exit(1);
});

app.get('/api/top-coins', (_req, res) => {
res.status(200).send(coinGeckoTokens);
});
Expand Down
13 changes: 7 additions & 6 deletions src/routers/slise-ad-rules/ad-places.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
* description: >
* A range of versions where the rule is applicable. If not specified, the rule is applicable
* for all versions. See the [ranges format](https://www.npmjs.com/package/semver#ranges)
* default: '*'
* AdPlacesRule:
* allOf:
* - $ref: '#/components/schemas/ExtVersionConstraints'
Expand Down Expand Up @@ -337,7 +338,7 @@ export const adPlacesRulesRouter = Router();
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand All @@ -360,7 +361,7 @@ export const adPlacesRulesRouter = Router();
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand Down Expand Up @@ -486,7 +487,7 @@ addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand All @@ -509,7 +510,7 @@ addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand Down Expand Up @@ -635,7 +636,7 @@ addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand All @@ -658,7 +659,7 @@ addObjectStorageMethodsToRouter(adPlacesRulesRouter, {
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand Down
4 changes: 2 additions & 2 deletions src/routers/slise-ad-rules/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ addObjectStorageMethodsToRouter(adProvidersRouter, {
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand All @@ -378,7 +378,7 @@ addObjectStorageMethodsToRouter(adProvidersRouter, {
* name: extVersion
* schema:
* type: string
* default: '1.20.1'
* default: '0.0.0'
* description: The extension version for which the rules should be returned
* responses:
* '200':
Expand Down
1 change: 1 addition & 0 deletions src/utils/express-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const withBodyValidation =
<T>(schema: Schema<T>, handler: TypedBodyRequestHandler<T>): RequestHandler =>
async (req, res, next) => {
try {
console.log('oy vey 1', JSON.stringify(req.body), JSON.stringify(await schema.validate(req.body)));
req.body = await schema.validate(req.body);
} catch (error) {
if (error instanceof ValidationError) {
Expand Down
34 changes: 0 additions & 34 deletions src/utils/migrations.ts

This file was deleted.

14 changes: 7 additions & 7 deletions src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ const adPlacesRulesSchema = arraySchema()
})
.required(),
stylesOverrides: arraySchema().of(adStylesOverridesSchema.clone().required()),
shouldHideOriginal: booleanSchema().default(false),
extVersion: versionRangeSchema
shouldHideOriginal: booleanSchema(),
extVersion: versionRangeSchema.clone().required()
})
.required()
)
Expand Down Expand Up @@ -156,14 +156,14 @@ const permanentAdPlacesRulesSchema = arraySchema()
insertionIndex: numberSchema().integer(),
insertBeforeSelector: cssSelectorSchema,
insertAfterSelector: cssSelectorSchema,
insertionsCount: numberSchema().integer().min(1).default(1),
insertionsCount: numberSchema().integer().min(1),
shouldUseDivWrapper: booleanSchema().required(),
elementStyle: styleSchema,
divWrapperStyle: styleSchema,
elementToMeasureSelector: cssSelectorSchema,
stylesOverrides: arraySchema().of(adStylesOverridesSchema.clone().required()),
shouldHideOriginal: booleanSchema().default(false),
extVersion: versionRangeSchema
shouldHideOriginal: booleanSchema(),
extVersion: versionRangeSchema.clone().required()
})
.test('insertion-place-specified', (value: PermanentAdPlacesRule | undefined) => {
if (!value) {
Expand Down Expand Up @@ -194,7 +194,7 @@ const adProvidersByDomainRulesSchema = arraySchema()
.shape({
urlRegexes: arraySchema().of(regexStringSchema.clone().required()).required(),
providers: arraySchema().of(stringSchema().required()).required(),
extVersion: versionRangeSchema
extVersion: versionRangeSchema.clone().required()
})
.required()
)
Expand All @@ -205,7 +205,7 @@ export const adProvidersByDomainsRulesDictionarySchema: IObjectSchema<Record<str

const adProvidersSelectorsRuleSchema = objectSchema().shape({
selectors: cssSelectorsListSchema.clone().required(),
extVersion: versionRangeSchema
extVersion: versionRangeSchema.clone().required()
});

export const adProvidersDictionarySchema: IObjectSchema<Record<string, AdProviderSelectorsRule[]>> =
Expand Down

0 comments on commit 7e0139b

Please sign in to comment.