Skip to content

Commit 2e3fed1

Browse files
authored
Release everything to prod (#137)
Merge pull request #137 from madfish-solutions/development
2 parents e24a9d1 + 04dc8fe commit 2e3fed1

File tree

13 files changed

+1245
-15
lines changed

13 files changed

+1245
-15
lines changed

.env.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ ALICE_BOB_PRIVATE_KEY=
88
THREE_ROUTE_API_URL=
99
THREE_ROUTE_API_AUTH_TOKEN=
1010
REDIS_URL=
11-
ADD_NOTIFICATION_USERNAME=
12-
ADD_NOTIFICATION_PASSWORD=
11+
ADMIN_USERNAME=
12+
ADMIN_PASSWORD=

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
"pino-http": "^5.5.0",
2626
"pino-pretty": "^4.7.1",
2727
"qs": "^6.10.3",
28-
"semaphore": "^1.1.0"
28+
"semaphore": "^1.1.0",
29+
"swagger-jsdoc": "^6.2.8",
30+
"swagger-ui-express": "^5.0.0",
31+
"yup": "^1.3.2"
2932
},
3033
"scripts": {
3134
"start": "cross-env NODE_ENV=development ts-node-dev --files --quiet src/index.ts",

src/advertising/slise.ts

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { redisClient } from '../redis';
2+
import { isDefined } from '../utils/helpers';
3+
4+
/** Style properties names that are likely to be unnecessary for banners are skipped */
5+
export const stylePropsNames = [
6+
'align-content',
7+
'align-items',
8+
'align-self',
9+
'alignment-baseline',
10+
'aspect-ratio',
11+
'background',
12+
'border-radius',
13+
'bottom',
14+
'box-shadow',
15+
'box-sizing',
16+
'display',
17+
'flex',
18+
'flex-basis',
19+
'flex-direction',
20+
'flex-flow',
21+
'flex-grow',
22+
'flex-shrink',
23+
'flex-wrap',
24+
'float',
25+
'height',
26+
'justify-content',
27+
'justify-items',
28+
'justify-self',
29+
'left',
30+
'margin',
31+
'margin-block',
32+
'margin-block-end',
33+
'margin-block-start',
34+
'margin-bottom',
35+
'margin-inline',
36+
'margin-inline-end',
37+
'margin-inline-start',
38+
'margin-left',
39+
'margin-right',
40+
'margin-top',
41+
'max-block-size',
42+
'max-height',
43+
'max-inline-size',
44+
'max-width',
45+
'min-block-size',
46+
'min-height',
47+
'min-inline-size',
48+
'min-width',
49+
'opacity',
50+
'overflow',
51+
'overflow-anchor',
52+
'overflow-wrap',
53+
'overflow-x',
54+
'overflow-y',
55+
'padding',
56+
'padding-block',
57+
'padding-block-end',
58+
'padding-block-start',
59+
'padding-bottom',
60+
'padding-inline',
61+
'padding-inline-end',
62+
'padding-inline-start',
63+
'padding-left',
64+
'padding-right',
65+
'padding-top',
66+
'position',
67+
'right',
68+
'text-align',
69+
'top',
70+
'visibility',
71+
'width',
72+
'z-index'
73+
];
74+
export type StylePropName = (typeof stylePropsNames)[number];
75+
76+
interface SliseAdStylesOverrides {
77+
parentDepth: number;
78+
style: Record<StylePropName, string>;
79+
}
80+
81+
export interface SliseAdPlacesRule {
82+
urlRegexes: string[];
83+
selector: {
84+
isMultiple: boolean;
85+
cssString: string;
86+
parentDepth: number;
87+
shouldUseDivWrapper: boolean;
88+
divWrapperStyle?: Record<StylePropName, string>;
89+
};
90+
stylesOverrides?: SliseAdStylesOverrides[];
91+
}
92+
93+
export interface SliseAdProvidersByDomainRule {
94+
urlRegexes: string[];
95+
providers: string[];
96+
}
97+
98+
const SLISE_AD_PLACES_RULES_KEY = 'slise_ad_places_rules';
99+
const SLISE_AD_PROVIDERS_BY_SITES_KEY = 'slise_ad_providers_by_sites';
100+
const SLISE_AD_PROVIDERS_ALL_SITES_KEY = 'slise_ad_providers_all_sites';
101+
const SLISE_AD_PROVIDERS_LIST_KEY = 'slise_ad_providers_list';
102+
103+
const objectStorageMethodsFactory = <V>(storageKey: string, fallbackValue: V) => ({
104+
getByKey: async (key: string): Promise<V> => {
105+
const value = await redisClient.hget(storageKey, key);
106+
107+
return isDefined(value) ? JSON.parse(value) : fallbackValue;
108+
},
109+
getAllValues: async (): Promise<Record<string, V>> => {
110+
const values = await redisClient.hgetall(storageKey);
111+
112+
const parsedValues: Record<string, V> = {};
113+
for (const key in values) {
114+
parsedValues[key] = JSON.parse(values[key]);
115+
}
116+
117+
return parsedValues;
118+
},
119+
upsertValues: (newValues: Record<string, V>) =>
120+
redisClient.hmset(
121+
storageKey,
122+
Object.fromEntries(Object.entries(newValues).map(([domain, value]) => [domain, JSON.stringify(value)]))
123+
),
124+
removeValues: (keys: string[]) => redisClient.hdel(storageKey, ...keys)
125+
});
126+
127+
export const {
128+
getByKey: getSliseAdPlacesRulesByDomain,
129+
getAllValues: getAllSliseAdPlacesRules,
130+
upsertValues: upsertSliseAdPlacesRules,
131+
removeValues: removeSliseAdPlacesRules
132+
} = objectStorageMethodsFactory<SliseAdPlacesRule[]>(SLISE_AD_PLACES_RULES_KEY, []);
133+
134+
export const {
135+
getByKey: getSliseAdProvidersByDomain,
136+
getAllValues: getAllSliseAdProvidersBySites,
137+
upsertValues: upsertSliseAdProvidersBySites,
138+
removeValues: removeSliseAdProvidersBySites
139+
} = objectStorageMethodsFactory<SliseAdProvidersByDomainRule[]>(SLISE_AD_PROVIDERS_BY_SITES_KEY, []);
140+
141+
export const {
142+
getByKey: getSelectorsByProviderId,
143+
getAllValues: getAllProviders,
144+
upsertValues: upsertProviders,
145+
removeValues: removeProviders
146+
} = objectStorageMethodsFactory<string[]>(SLISE_AD_PROVIDERS_LIST_KEY, []);
147+
148+
export const getSliseAdProvidersForAllSites = async () => redisClient.smembers(SLISE_AD_PROVIDERS_ALL_SITES_KEY);
149+
150+
export const addSliseAdProvidersForAllSites = async (providers: string[]) =>
151+
redisClient.sadd(SLISE_AD_PROVIDERS_ALL_SITES_KEY, ...providers);
152+
153+
export const removeSliseAdProvidersForAllSites = async (providers: string[]) =>
154+
redisClient.srem(SLISE_AD_PROVIDERS_ALL_SITES_KEY, ...providers);

src/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getEnv } from './utils/env';
22
import { isDefined } from './utils/helpers';
33

4-
export const MIN_IOS_APP_VERSION = '1.10.445';
5-
export const MIN_ANDROID_APP_VERSION = '1.10.445';
4+
export const MIN_IOS_APP_VERSION = '1.20.1027';
5+
export const MIN_ANDROID_APP_VERSION = '1.20.1027';
66

77
export const EnvVars = {
88
MOONPAY_SECRET_KEY: getEnv('MOONPAY_SECRET_KEY'),
@@ -11,8 +11,8 @@ export const EnvVars = {
1111
THREE_ROUTE_API_URL: getEnv('THREE_ROUTE_API_URL'),
1212
THREE_ROUTE_API_AUTH_TOKEN: getEnv('THREE_ROUTE_API_AUTH_TOKEN'),
1313
REDIS_URL: getEnv('REDIS_URL'),
14-
ADD_NOTIFICATION_USERNAME: getEnv('ADD_NOTIFICATION_USERNAME'),
15-
ADD_NOTIFICATION_PASSWORD: getEnv('ADD_NOTIFICATION_PASSWORD')
14+
ADMIN_USERNAME: getEnv('ADMIN_USERNAME'),
15+
ADMIN_PASSWORD: getEnv('ADMIN_PASSWORD')
1616
};
1717

1818
for (const name in EnvVars) {

src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import express, { Request, Response } from 'express';
66
import firebaseAdmin from 'firebase-admin';
77
import { stdSerializers } from 'pino';
88
import pinoHttp from 'pino-http';
9+
import swaggerJSDoc from 'swagger-jsdoc';
10+
import swaggerUi from 'swagger-ui-express';
911

1012
import { getAdvertisingInfo } from './advertising/advertising';
1113
import { MIN_ANDROID_APP_VERSION, MIN_IOS_APP_VERSION } from './config';
@@ -17,6 +19,7 @@ import { getNotifications } from './notifications/utils/get-notifications.util';
1719
import { getParsedContent } from './notifications/utils/get-parsed-content.util';
1820
import { getPlatforms } from './notifications/utils/get-platforms.util';
1921
import { redisClient } from './redis';
22+
import { sliseRulesRouter } from './routers/slise-ad-rules';
2023
import { getABData } from './utils/ab-test';
2124
import { cancelAliceBobOrder } from './utils/alice-bob/cancel-alice-bob-order';
2225
import { createAliceBobOrder } from './utils/alice-bob/create-alice-bob-order';
@@ -322,6 +325,21 @@ app.get('/api/advertising-info', (_req, res) => {
322325
}
323326
});
324327

328+
app.use('/api/slise-ad-rules', sliseRulesRouter);
329+
330+
const swaggerOptions = {
331+
swaggerDefinition: {
332+
openapi: '3.0.0',
333+
info: {
334+
title: 'Temple Wallet backend',
335+
version: '1.0.0'
336+
}
337+
},
338+
apis: ['./src/index.ts', './src/routers/**/*.ts']
339+
};
340+
const swaggerSpec = swaggerJSDoc(swaggerOptions);
341+
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
342+
325343
// start the server listening for requests
326344
const port = Boolean(process.env.PORT) ? process.env.PORT : 3000;
327345
app.listen(port, () => console.info(`Server is running on port ${port}...`));

src/middlewares/basic-auth.middleware.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ import { Request, Response, NextFunction } from 'express';
33
import { EnvVars } from '../config';
44
import { isDefined } from '../utils/helpers';
55

6+
const credentials = {
7+
username: EnvVars.ADMIN_USERNAME,
8+
password: EnvVars.ADMIN_PASSWORD
9+
};
10+
611
export const basicAuth = (req: Request, res: Response, next: NextFunction) => {
712
const base64EncodedCredentials = req.get('Authorization');
813

914
if (isDefined(base64EncodedCredentials)) {
1015
const [username, password] = Buffer.from(base64EncodedCredentials.split(' ')[1], 'base64').toString().split(':');
16+
const { username: correctUsername, password: correctPassword } = credentials;
1117

12-
if (!(username === EnvVars.ADD_NOTIFICATION_USERNAME && password === EnvVars.ADD_NOTIFICATION_PASSWORD)) {
18+
if (!(username === correctUsername && password === correctPassword)) {
1319
handleNotAuthenticated(res, next);
1420
}
1521
next();

0 commit comments

Comments
 (0)