Skip to content
Merged
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
758 changes: 355 additions & 403 deletions npm-shrinkwrap.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@
"jsonwebtoken": "^9.0.2",
"moment": "^2.30.1",
"mongodb": "^6.20.0",
"mongoose": "^8.18.2",
"pino": "^9.11.0",
"mongoose": "^8.19.0",
"pino": "^10.0.0",
"pino-pretty": "^13.1.1",
"swagger-ui-express": "^5.0.1",
"switcher-client": "^4.4.1",
"validator": "^13.15.15"
},
"devDependencies": {
"env-cmd": "^11.0.0",
"eslint": "^9.36.0",
"jest": "^30.1.3",
"eslint": "^9.37.0",
"jest": "^30.2.0",
"jest-sonar-reporter": "^2.0.0",
"node-notifier": "^10.0.1",
"nodemon": "^3.1.10",
Expand Down
4 changes: 2 additions & 2 deletions src/aggregator/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export const resolveConfigByKey = async (domain, key) => Config.findOne({ domain
export function resolveEnvValue(source, field, keys) {
const arrValue = [];

keys.forEach(k => {
for (const k of keys) {
arrValue.push({
env: k,
value: source[field][k]
});
});
}

return arrValue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/app-server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import https from 'https';
import http from 'http';
import fs from 'fs';
import https from 'node:https';
import http from 'node:http';
import fs from 'node:fs';
import Logger from './helpers/logger.js';

export const createServer = (app) => {
Expand Down
2 changes: 1 addition & 1 deletion src/external/switcher-api-facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function getRateLimit(key, component) {
}
}

return parseInt(process.env.MAX_REQUEST_PER_MINUTE || DEFAULT_RATE_LIMIT);
return Number.parseInt(process.env.MAX_REQUEST_PER_MINUTE || DEFAULT_RATE_LIMIT);
}

export async function checkHttpsAgent(value) {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/cache/worker-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export const STATUS_TYPE = {
};

export class CacheWorkerManager {
DEFAULT_INTERVAL = 5000;
#DEFAULT_INTERVAL = 5000;
worker = null;

constructor(eventHandlers, options) {
this.worker = null;
this.status = STATUS_TYPE.STOPPED;
this.onCacheUpdates = eventHandlers.onCacheUpdates;
this.onCacheDeletions = eventHandlers.onCacheDeletions;
Expand All @@ -40,7 +40,7 @@ export class CacheWorkerManager {
this.onError = eventHandlers.onError;

this.options = {
interval: this.DEFAULT_INTERVAL,
interval: this.#DEFAULT_INTERVAL,
...options
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function payloadReader(payload) {
return Object.keys(payloadRead)
.flatMap(field => [field, ...payloadReader(payload[field])
.map(nestedField => `${field}.${nestedField}`)])
.filter(field => isNaN(Number(field)))
.filter(field => Number.isNaN(Number(field)))
.reduce((acc, curr) => {
if (!acc.includes(curr)) {
acc.push(curr);
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ipcidr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default class IPCIDR {
}

ip4ToInt(ip) {
return ip.split('.').reduce((int, oct) => (int << 8) + parseInt(oct, 10), 0) >>> 0;
return ip.split('.').reduce((int, oct) => (int << 8) + Number.parseInt(oct, 10), 0) >>> 0;
}

isIp4InCidr(ip) {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/timed-match/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cp from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
import cp from 'node:child_process';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/limiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ERROR_MESSAGE = {

const getMaxRate = (rate_limit) => {
if (rate_limit === 0) {
return parseInt(DEFAULT_RATE_LIMIT);
return Number.parseInt(DEFAULT_RATE_LIMIT);
}

return rate_limit;
Expand All @@ -17,7 +17,7 @@ export const DEFAULT_RATE_LIMIT = 1000;

export const defaultLimiter = rateLimit({
windowMs: DEFAULT_WINDOWMS,
limit: getMaxRate(parseInt(process.env.MAX_REQUEST_PER_MINUTE)),
limit: getMaxRate(Number.parseInt(process.env.MAX_REQUEST_PER_MINUTE)),
standardHeaders: 'draft-7',
legacyHeaders: false,
message: ERROR_MESSAGE,
Expand Down
4 changes: 2 additions & 2 deletions src/middleware/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export async function checkConfig(req, res, next) {
}

export async function checkConfigComponent(req, res, next) {
const hasComponent = req.config.components.filter((c) =>
c.toString() === req.componentId.toString()).length > 0;
const hasComponent = req.config.components.some((c) =>
c.toString() === req.componentId.toString());

if (!hasComponent) {
return res.status(401).send({
Expand Down
14 changes: 5 additions & 9 deletions src/models/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import bcryptjs from 'bcryptjs';
import { randomUUID } from 'crypto';
import { randomUUID } from 'node:crypto';
import jwt from 'jsonwebtoken';
import Domain from './domain.js';

Expand Down Expand Up @@ -41,28 +41,24 @@ const componentSchema = new mongoose.Schema({
});

componentSchema.methods.generateApiKey = async function () {
const component = this;

const apiKey = randomUUID();
const hash = await bcryptjs.hash(apiKey, EncryptionSalts.COMPONENT);
component.apihash = hash;
await component.save();
this.apihash = hash;
await this.save();

return apiKey;
};

componentSchema.methods.generateAuthToken = async function (environment, rate_limit) {
const component = this;

const options = {
expiresIn: process.env.JWT_CLIENT_TOKEN_EXP_TIME
};

return jwt.sign(({
component: component._id,
component: this._id,
environment,
rate_limit,
vc: component.apihash.substring(50, component.apihash.length - 1)
vc: this.apihash.substring(50, this.apihash.length - 1)
}), process.env.JWT_SECRET, options);
};

Expand Down
2 changes: 1 addition & 1 deletion src/models/config-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function processPAYLOAD(operation, input, values) {
const keys = payloadReader(inputJson);
switch(operation) {
case OperationsType.HAS_ONE:
return keys.filter(key => values.includes(key)).length > 0;
return keys.some(key => values.includes(key));
case OperationsType.HAS_ALL:
return values.every(element => keys.includes(element));
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/relay.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import https from 'https';
import https from 'node:https';
import { StrategiesToRelayDataType, RelayMethods } from '../models/config.js';
import { checkHttpsAgent } from '../external/switcher-api-facade.js';
import Logger from '../helpers/logger.js';
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/db_api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mongoose from 'mongoose';
import bcryptjs from 'bcryptjs';
import { randomUUID } from 'crypto';
import { randomUUID } from 'node:crypto';
import jwt from 'jsonwebtoken';
import Admin from '../../src/models/admin';
import Domain from '../../src/models/domain';
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/db_client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose';
import jwt from 'jsonwebtoken';
import bcryptjs from 'bcryptjs';
import { randomUUID } from 'crypto';
import { randomUUID } from 'node:crypto';
import Admin from '../../src/models/admin';
import Domain from '../../src/models/domain';
import GroupConfig from '../../src/models/group-config';
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/db_client_payload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose from 'mongoose';
import jwt from 'jsonwebtoken';
import bcryptjs from 'bcryptjs';
import { randomUUID } from 'crypto';
import { randomUUID } from 'node:crypto';
import Admin from '../../src/models/admin';
import Domain from '../../src/models/domain';
import GroupConfig from '../../src/models/group-config';
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-test/switcher-api-facade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Testing Switcher API Facade', () => {
return getRateLimit(component1Key, component1);
};

await expect(call()).resolves.toBe(parseInt(process.env.MAX_REQUEST_PER_MINUTE));
await expect(call()).resolves.toBe(Number.parseInt(process.env.MAX_REQUEST_PER_MINUTE));
});

});