Skip to content

Commit dd06c1a

Browse files
authored
Release 1.26.0 (#172)
Merge pull request #172 from madfish-solutions/development
2 parents afb5f3d + b369658 commit dd06c1a

File tree

13 files changed

+137
-45
lines changed

13 files changed

+137
-45
lines changed

.env.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ THREE_ROUTE_API_AUTH_TOKEN=
1010
REDIS_URL=
1111
ADMIN_USERNAME=
1212
ADMIN_PASSWORD=
13+
COVALENT_API_KEY=

.github/workflows/code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: macos-latest
1313
steps:
1414
- name: Clone repository
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v4
1616

1717
- name: Repository setup
1818
uses: ./.github/workflows/repository-setup

.github/workflows/repository-setup/action.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
name: Repository setup
22

3-
description: Setups Node 16.x & installs dependencies
3+
description: Setups Node.js & installs dependencies
44

55
runs:
66
using: 'composite'
77
steps:
8-
- name: Setup Node 16.x
9-
uses: actions/setup-node@v2
8+
- name: Setup Node 20.x
9+
uses: actions/setup-node@v4
1010
with:
11-
node-version: '16.x'
12-
13-
- name: Get branch name
14-
uses: EthanSK/git-branch-name-action@v1
11+
node-version: '20.x'
1512

1613
- name: Get yarn cache directory path
1714
id: yarn-cache-dir-path
1815
shell: bash
1916
run: echo "::set-output name=dir::$(yarn cache dir)"
2017

21-
- uses: actions/cache@v3
18+
- uses: actions/cache@v4
2219
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
2320
with:
2421
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ dist
100100
# DynamoDB Local files
101101
.dynamodb/
102102

103+
# Redis
104+
*.rdb
105+
103106
# TernJS port file
104107
.tern-port
105108

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:14
1+
FROM node:20-alpine3.18
22
WORKDIR /usr/src/app
33
COPY package.json yarn.lock ./
44
RUN yarn

src/advertising/external-ads.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ const PERMANENT_AD_PLACES_RULES_KEY = 'permanent_ad_places_rules';
175175
const PERMANENT_NATIVE_AD_PLACES_RULES_KEY = 'permanent_native_ad_places_rules';
176176
const REPLACE_ADS_URLS_BLACKLIST_KEY = 'replace_ads_urls_blacklist';
177177
const ELEMENTS_TO_HIDE_OR_REMOVE_KEY = 'elements_to_hide_or_remove';
178+
const AD_PROVIDERS_CATEGORIES_KEY = 'ad_providers_categories';
178179

179180
export const adPlacesRulesMethods = objectStorageMethodsFactory<AdPlacesRule[]>(AD_PLACES_RULES_KEY, []);
180181

@@ -205,6 +206,10 @@ export const elementsToHideOrRemoveMethods = objectStorageMethodsFactory<Element
205206
[]
206207
);
207208

209+
export const adProvidersCategoriesMethods = objectStorageMethodsFactory<string[]>(AD_PROVIDERS_CATEGORIES_KEY, [
210+
'crypto'
211+
]);
212+
208213
export const getAdProvidersForAllSites = async () => redisClient.smembers(AD_PROVIDERS_ALL_SITES_KEY);
209214

210215
export const addAdProvidersForAllSites = async (providers: string[]) =>

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ import { getAliceBobEstimationPayload } from './utils/alice-bob/get-alice-bob-es
3030
import { getAliceBobOrderInfo } from './utils/alice-bob/get-alice-bob-order-info';
3131
import { getAliceBobPairInfo } from './utils/alice-bob/get-alice-bob-pair-info';
3232
import { getAliceBobPairsInfo } from './utils/alice-bob/get-alice-bob-pairs-info';
33+
import { btcExchangeRateProvider, tezExchangeRateProvider } from './utils/coingecko';
3334
import { CodedError } from './utils/errors';
3435
import { coinGeckoTokens } from './utils/gecko-tokens';
3536
import { getExternalApiErrorPayload, isDefined, isNonEmptyString } from './utils/helpers';
3637
import logger from './utils/logger';
3738
import { getSignedMoonPayUrl } from './utils/moonpay/get-signed-moonpay-url';
3839
import { getSigningNonce } from './utils/signing-nonce';
3940
import SingleQueryDataProvider from './utils/SingleQueryDataProvider';
40-
import { tezExchangeRateProvider } from './utils/tezos';
4141
import { getExchangeRates } from './utils/tokens';
4242

4343
const PINO_LOGGER = {
@@ -175,6 +175,7 @@ app.get('/api/abtest', (_, res) => {
175175
});
176176

177177
app.get('/api/exchange-rates/tez', makeProviderDataRequestHandler(tezExchangeRateProvider));
178+
app.get('/api/exchange-rates/btc', makeProviderDataRequestHandler(btcExchangeRateProvider));
178179

179180
app.get('/api/exchange-rates', async (_req, res) => {
180181
const tokensExchangeRates = await getExchangeRates();

src/routers/slise-ad-rules/providers.ts

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
adProvidersByDomainRulesMethods,
1010
AdProviderSelectorsRule,
1111
filterRules,
12-
AdProvidersByDomainRule
12+
AdProvidersByDomainRule,
13+
adProvidersCategoriesMethods
1314
} from '../../advertising/external-ads';
1415
import { basicAuth } from '../../middlewares/basic-auth.middleware';
1516
import { addObjectStorageMethodsToRouter, withBodyValidation, withExceptionHandler } from '../../utils/express-helpers';
@@ -18,7 +19,8 @@ import {
1819
nonEmptyStringsListSchema,
1920
hostnamesListSchema,
2021
adProvidersByDomainsRulesDictionarySchema,
21-
adProvidersDictionarySchema
22+
adProvidersDictionarySchema,
23+
adProvidersCategoriesDictionarySchema
2224
} from '../../utils/schemas';
2325

2426
/**
@@ -116,6 +118,12 @@ import {
116118
* type: array
117119
* items:
118120
* $ref: '#/components/schemas/AdProvidersInputValue'
121+
* AdProvidersCategoriesDictionary:
122+
* type: object
123+
* additionalProperties:
124+
* type: array
125+
* items:
126+
* type: string
119127
*/
120128

121129
export const adProvidersRouter = Router();
@@ -328,6 +336,78 @@ addObjectStorageMethodsToRouter<AdProvidersByDomainRule[]>(adProvidersRouter, {
328336
objectTransformFn: identity
329337
});
330338

339+
/**
340+
* @swagger
341+
* /api/slise-ad-rules/providers/categories:
342+
* get:
343+
* summary: Get categories for providers
344+
* tags:
345+
* - Known ads providers
346+
* responses:
347+
* '200':
348+
* description: Provider - categories dictionary
349+
* content:
350+
* application/json:
351+
* schema:
352+
* $ref: '#/components/schemas/AdProvidersCategoriesDictionary'
353+
* '500':
354+
* $ref: '#/components/responses/ErrorResponse'
355+
* post:
356+
* summary: Upsert categories for providers
357+
* tags:
358+
* - Known ads providers
359+
* security:
360+
* - basicAuth: []
361+
* requestBody:
362+
* description: Provider - categories dictionary
363+
* content:
364+
* application/json:
365+
* schema:
366+
* $ref: '#/components/schemas/AdProvidersCategoriesDictionary'
367+
* responses:
368+
* '200':
369+
* $ref: '#/components/responses/SuccessResponse'
370+
* '400':
371+
* $ref: '#/components/responses/ErrorResponse'
372+
* '401':
373+
* $ref: '#/components/responses/UnauthorizedError'
374+
* '500':
375+
* $ref: '#/components/responses/ErrorResponse'
376+
* delete:
377+
* summary: Delete categories for providers
378+
* tags:
379+
* - Known ads providers
380+
* security:
381+
* - basicAuth: []
382+
* requestBody:
383+
* description: List of provider IDs for which categories should be deleted
384+
* content:
385+
* application/json:
386+
* schema:
387+
* type: array
388+
* items:
389+
* type: string
390+
* responses:
391+
* '200':
392+
* $ref: '#/components/responses/SuccessResponse'
393+
* '400':
394+
* $ref: '#/components/responses/ErrorResponse'
395+
* '401':
396+
* $ref: '#/components/responses/UnauthorizedError'
397+
* '500':
398+
* $ref: '#/components/responses/ErrorResponse'
399+
*/
400+
addObjectStorageMethodsToRouter<string[]>(adProvidersRouter, {
401+
path: '/categories',
402+
methods: adProvidersCategoriesMethods,
403+
keyName: 'providerId',
404+
objectValidationSchema: adProvidersCategoriesDictionarySchema,
405+
keysArrayValidationSchema: nonEmptyStringsListSchema,
406+
successfulRemovalMessage: entriesCount => `${entriesCount} entries have been removed`,
407+
valueTransformFn: identity,
408+
objectTransformFn: identity
409+
});
410+
331411
/**
332412
* @swagger
333413
* /api/slise-ad-rules/providers/negative-selectors:

src/utils/coingecko.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { range } from './helpers';
1+
import { AxiosError } from 'axios';
2+
3+
import { isDefined, range } from './helpers';
4+
import logger from './logger';
25
import { makeBuildQueryFn } from './makeBuildQueryFn';
36
import SingleQueryDataProvider from './SingleQueryDataProvider';
47

@@ -89,3 +92,29 @@ export const getMarketsBySymbols = async (symbols: string[]) => {
8992

9093
return chunks.flat();
9194
};
95+
96+
const createCoingeckoExchangeRateProvider = (tokenSymbol: string) =>
97+
new SingleQueryDataProvider(60000, async () => {
98+
try {
99+
const [market] = await getMarketsBySymbols([tokenSymbol]);
100+
101+
return market.current_price;
102+
} catch (e) {
103+
if (!(e instanceof AxiosError)) {
104+
logger.error(`Request for ${tokenSymbol} exchange rate failed with unknown error`);
105+
} else if (isDefined(e.response) && isDefined(e.response.data)) {
106+
logger.error(
107+
`Request for ${tokenSymbol} exchange rate failed with status ${e.response.status} and message ${e.response.data}`
108+
);
109+
} else if (isDefined(e.response) && isDefined(e.response.status)) {
110+
logger.error(`Request for ${tokenSymbol} exchange rate failed with status ${e.response.status}`);
111+
} else {
112+
logger.error(`Request for ${tokenSymbol} exchange rate failed without response`);
113+
}
114+
115+
throw e;
116+
}
117+
});
118+
119+
export const tezExchangeRateProvider = createCoingeckoExchangeRateProvider('xtz');
120+
export const btcExchangeRateProvider = createCoingeckoExchangeRateProvider('btc');

src/utils/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface CodedErrorForResponse {
88
type StatusCodeNumber = (typeof StatusCodes)[keyof typeof StatusCodes];
99

1010
export class CodedError extends Error {
11-
constructor(public code: StatusCodeNumber | number, message: string, public errorCode?: string) {
11+
constructor(public code: StatusCodeNumber, message: string, public errorCode?: string) {
1212
super(message);
1313
}
1414

0 commit comments

Comments
 (0)