diff --git a/.env-cmdrc-template b/.env-cmdrc-template index df29b55..6234f13 100644 --- a/.env-cmdrc-template +++ b/.env-cmdrc-template @@ -1,5 +1,6 @@ { "test": { + "NODE_OPTIONS": "--experimental-vm-modules", "ENV": "TEST", "PORT": "3000", "SSL_CERT": "", diff --git a/.eslintrc.json b/.eslintrc.json index 348f5ff..ce0cb1e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,7 @@ { "env": { "node": true, - "commonjs": true, + "commonjs": false, "es6": true, "jest": true }, diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 93a30ad..ed75c59 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -38,6 +38,7 @@ jobs: - name: Run tests run: npm test env: + NODE_OPTIONS: "--experimental-vm-modules" MONGODB_URI: mongodb://127.0.0.1:27017/switcher-api-test JWT_CLIENT_TOKEN_EXP_TIME: 5m JWT_SECRET: ${{ secrets.JWT_SECRET }} diff --git a/.github/workflows/re-release.yml b/.github/workflows/re-release.yml index a55be2a..6bfc673 100644 --- a/.github/workflows/re-release.yml +++ b/.github/workflows/re-release.yml @@ -39,6 +39,7 @@ jobs: - name: Run tests run: npm test env: + NODE_OPTIONS: "--experimental-vm-modules" MONGODB_URI: mongodb://127.0.0.1:27017/switcher-api-test JWT_CLIENT_TOKEN_EXP_TIME: 5m JWT_SECRET: ${{ secrets.JWT_SECRET }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b889b9..5b50ef3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,7 @@ jobs: - name: Run tests run: npm test env: + NODE_OPTIONS: "--experimental-vm-modules" MONGODB_URI: mongodb://127.0.0.1:27017/switcher-api-test JWT_CLIENT_TOKEN_EXP_TIME: 5m JWT_SECRET: ${{ secrets.JWT_SECRET }} diff --git a/Dockerfile b/Dockerfile index 60a18d1..d94f7ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,21 +6,21 @@ WORKDIR /app # ---------- Builder ---------- FROM base AS builder -COPY package*.json babel.config.js ./ +COPY package*.json ./ RUN npm install COPY ./src ./src -RUN npm run build && \ - npm prune --production +RUN npm prune --production # ---------- Release ---------- FROM base AS release COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/build ./dist +COPY --from=builder /app/package*.json ./ +COPY --from=builder /app/src ./dist USER node -CMD ["node", "./dist/index.js"] \ No newline at end of file +CMD ["node", "./dist/start.js"] \ No newline at end of file diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index 04ffe27..0000000 --- a/babel.config.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - presets: [ - [ - '@babel/preset-env', - { - targets: { - node: 'current', - }, - }, - ], - ], -}; \ No newline at end of file diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 7d39b51..0000000 --- a/jest.config.js +++ /dev/null @@ -1,194 +0,0 @@ -// For a detailed explanation regarding each configuration property, visit: -// https://jestjs.io/docs/en/configuration.html - -module.exports = { - // All imported modules in your tests should be mocked automatically - // automock: false, - - // Stop running tests after `n` failures - // bail: 0, - - // Respect "browser" field in package.json when resolving modules - // browser: false, - - // The directory where Jest should store its cached dependency information - // cacheDirectory: "F:\\Cache\\TEMP\\jest", - - // Automatically clear mock calls and instances between every test - clearMocks: true, - - // Indicates whether the coverage information should be collected while executing the test - // collectCoverage: true, - - // An array of glob patterns indicating a set of files for which coverage information should be collected - // collectCoverageFrom: [ - // "**/*.{js,jsx}", - // "!**/node_modules/**", - // "!**/vendor/**" - // ], - - // The directory where Jest should output its coverage files - // coverageDirectory: "coverage", - - // An array of regexp pattern strings used to skip coverage collection - coveragePathIgnorePatterns: [ - '/node_modules/', - '/src/api-docs/', - '/src/app-server.js' - ], - - // A list of reporter names that Jest uses when writing coverage reports - // coverageReporters: [ - // "json", - // "text", - // "lcov", - // "clover" - // ], - - // An object that configures minimum threshold enforcement for coverage results - // coverageThreshold: null, - - // A path to a custom dependency extractor - // dependencyExtractor: null, - - // Make calling deprecated APIs throw helpful error messages - // errorOnDeprecated: false, - - // Force coverage collection from ignored files using an array of glob patterns - // forceCoverageMatch: [], - - // A path to a module which exports an async function that is triggered once before all test suites - // globalSetup: null, - - // A path to a module which exports an async function that is triggered once after all test suites - // globalTeardown: null, - - // A set of global variables that need to be available in all test environments - // globals: {}, - - // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers. - // maxWorkers: "50%", - - // An array of directory names to be searched recursively up from the requiring module's location - // moduleDirectories: [ - // "node_modules" - // ], - - // An array of file extensions your modules use - // moduleFileExtensions: [ - // "js", - // "json", - // "jsx", - // "ts", - // "tsx", - // "node" - // ], - - // A map from regular expressions to module names that allow to stub out resources with a single module - // moduleNameMapper: {}, - - // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader - // modulePathIgnorePatterns: [], - - // Activates notifications for test results - // notify: false, - - // An enum that specifies notification mode. Requires { notify: true } - // notifyMode: "failure-change", - - // A preset that is used as a base for Jest's configuration - // preset: null, - - // Run tests from one or more projects - // projects: null, - - // Use this configuration option to add custom reporters to Jest - // reporters: undefined, - - // Automatically reset mock state between every test - // resetMocks: false, - - // Reset the module registry before running each individual test - // resetModules: false, - - // A path to a custom resolver - // resolver: null, - - // Automatically restore mock state between every test - // restoreMocks: false, - - // The root directory that Jest should scan for tests and modules within - // rootDir: null, - - // A list of paths to directories that Jest should use to search for files in - // roots: [ - // "" - // ], - - // Allows you to use a custom runner instead of Jest's default test runner - // runner: "jest-runner", - - // The paths to modules that run some code to configure or set up the testing environment before each test - // setupFiles: [], - - // A list of paths to modules that run some code to configure or set up the testing framework before each test - // setupFilesAfterEnv: [], - - // A list of paths to snapshot serializer modules Jest should use for snapshot testing - // snapshotSerializers: [], - - // The test environment that will be used for testing - testEnvironment: 'node', - - // Options that will be passed to the testEnvironment - // testEnvironmentOptions: {}, - - // Adds a location field to test results - // testLocationInResults: false, - - // The glob patterns Jest uses to detect test files - // testMatch: [ - // "**/__tests__/**/*.[jt]s?(x)", - // "**/?(*.)+(spec|test).[tj]s?(x)" - // ], - - // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped - // testPathIgnorePatterns: [ - // "\\\\node_modules\\\\" - // ], - - // The regexp pattern or array of patterns that Jest uses to detect test files - // testRegex: [], - - // This option allows the use of a custom results processor - testResultsProcessor: 'jest-sonar-reporter', - - // This option allows use of a custom test runner - // testRunner: "jasmine2", - - // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href - // testURL: "http://localhost", - - // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" - // timers: "real", - - // A map from regular expressions to paths to transformers - // transform: null, - - // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation - // transformIgnorePatterns: [ - // "\\\\node_modules\\\\" - // ], - - // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them - // unmockedModulePathPatterns: undefined, - - // Indicates whether each individual test should be reported during the run - // verbose: null, - - // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode - // watchPathIgnorePatterns: [], - - // Whether to use watchman for file crawling - // watchman: true, -}; diff --git a/package.json b/package.json index 1ca9eff..90f1174 100644 --- a/package.json +++ b/package.json @@ -3,22 +3,31 @@ "version": "1.0.0", "description": "Resolver API to be used with Switcher API", "main": "start.js", + "type": "module", "author": { "name": "Roger Floriano", "email": "switcher.project@gmail.com" }, "scripts": { - "build": "npm run clean && npm run build-babel", - "start": "npm run build && node ./build/index.js", - "build-babel": "babel -d ./build ./src -s", - "clean": "rm -rf build && mkdir build", + "start": "node ./src/start.js", "dev": "env-cmd -e dev nodemon ./src/start.js", "prod": "env-cmd -e prod nodemon ./src/start.js", - "lint": "eslint src", + "lint": "eslint ./src/**/*.js", "test": "jest --runInBand --collect-coverage", "test-local": "env-cmd -e test jest --runInBand --collect-coverage", "snyk": "snyk test --strict-out-of-sync=false" }, + "jest": { + "transform": {}, + "clearMocks": true, + "testEnvironment": "node", + "testResultsProcessor": "jest-sonar-reporter", + "coveragePathIgnorePatterns": [ + "/node_modules/", + "/src/api-docs/", + "/src/app-server.js" + ] + }, "keywords": [ "feature", "flag", @@ -41,7 +50,7 @@ "jsonwebtoken": "^9.0.2", "moment": "^2.30.1", "mongodb": "^6.5.0", - "mongoose": "^8.2.4", + "mongoose": "^8.3.0", "pino": "^8.19.0", "pino-pretty": "^11.0.0", "swagger-ui-express": "^5.0.0", @@ -49,13 +58,6 @@ "validator": "^13.11.0" }, "devDependencies": { - "@babel/cli": "^7.24.1", - "@babel/core": "^7.24.3", - "@babel/node": "^7.23.9", - "@babel/preset-env": "^7.24.3", - "@babel/register": "^7.23.7", - "babel-jest": "^29.7.0", - "babel-polyfill": "^6.26.0", "env-cmd": "^10.1.0", "eslint": "^8.57.0", "jest": "^29.7.0", diff --git a/src/api-docs/paths/path-client.js b/src/api-docs/paths/path-client.js index 2fc3548..eaf41d1 100644 --- a/src/api-docs/paths/path-client.js +++ b/src/api-docs/paths/path-client.js @@ -1,6 +1,6 @@ -import { StrategiesType } from '../../models/config-strategy'; -import { pathParameter, queryParameter } from '../schemas/common'; -import configStrategy from '../schemas/config-strategy'; +import { StrategiesType } from '../../models/config-strategy.js'; +import { pathParameter, queryParameter } from '../schemas/common.js'; +import configStrategy from '../schemas/config-strategy.js'; export default { '/criteria': { diff --git a/src/api-docs/schemas/config-strategy.js b/src/api-docs/schemas/config-strategy.js index 70e6cbd..b6d0f30 100644 --- a/src/api-docs/schemas/config-strategy.js +++ b/src/api-docs/schemas/config-strategy.js @@ -1,4 +1,4 @@ -import { OperationsType, StrategiesType } from '../../models/config-strategy'; +import { OperationsType, StrategiesType } from '../../models/config-strategy.js'; const configStrategy = { type: 'object', diff --git a/src/api-docs/swagger-document.js b/src/api-docs/swagger-document.js index 90e4f55..10685fd 100644 --- a/src/api-docs/swagger-document.js +++ b/src/api-docs/swagger-document.js @@ -1,7 +1,6 @@ -import pathClient from './paths/path-client'; +import pathClient from './paths/path-client.js'; -import { commonSchema } from './schemas/common'; -import info from './swagger-info'; +import info from './swagger-info.js'; export default { openapi: '3.0.1', @@ -27,9 +26,6 @@ export default { in: 'header', name: 'switcher-api-key' } - }, - schemas: { - ...commonSchema } }, paths: { diff --git a/src/app-server.js b/src/app-server.js index c014fe1..f9371ee 100644 --- a/src/app-server.js +++ b/src/app-server.js @@ -1,7 +1,7 @@ import https from 'https'; import http from 'http'; import fs from 'fs'; -import Logger from './helpers/logger'; +import Logger from './helpers/logger.js'; export const createServer = (app) => { if (process.env.SSL_CERT && process.env.SSL_KEY) { diff --git a/src/app.js b/src/app.js index 3a68978..4fba4f3 100644 --- a/src/app.js +++ b/src/app.js @@ -4,15 +4,15 @@ import { createHandler } from 'graphql-http/lib/use/express'; import cors from 'cors'; import helmet from 'helmet'; -require('./db/mongoose'); +import './db/mongoose.js'; import mongoose from 'mongoose'; -import swaggerDocument from './api-docs/swagger-document'; -import clientApiRouter from './routers/client-api'; -import schema from './client/schema'; -import { appAuth, resourcesAuth } from './middleware/auth'; -import { clientLimiter, defaultLimiter } from './middleware/limiter'; -import { createServer } from './app-server'; +import swaggerDocument from './api-docs/swagger-document.js'; +import clientApiRouter from './routers/client-api.js'; +import schema from './client/schema.js'; +import { appAuth, resourcesAuth } from './middleware/auth.js'; +import { clientLimiter, defaultLimiter } from './middleware/limiter.js'; +import { createServer } from './app-server.js'; const app = express(); app.use(express.json()); diff --git a/src/client/configuration-resolvers.js b/src/client/configuration-resolvers.js index 217fbb7..73cf35d 100644 --- a/src/client/configuration-resolvers.js +++ b/src/client/configuration-resolvers.js @@ -1,4 +1,4 @@ -import { getComponents } from '../services/component'; +import { getComponents } from '../services/component.js'; export async function resolveComponents(source) { const components = await getComponents({ _id: { $in: source.components } }); diff --git a/src/client/configuration-type.js b/src/client/configuration-type.js index 0d4106a..b643e9b 100644 --- a/src/client/configuration-type.js +++ b/src/client/configuration-type.js @@ -1,9 +1,9 @@ -import { resolveConfigStrategy, resolveConfig, resolveGroupConfig, resolveEnvStatus } from './resolvers'; import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean, GraphQLFloat } from 'graphql'; -import { EnvType } from '../models/environment'; +import { resolveConfigStrategy, resolveConfig, resolveGroupConfig, resolveEnvStatus } from './resolvers.js'; +import { EnvType } from '../models/environment.js'; import { resolveComponents, -} from './configuration-resolvers'; +} from './configuration-resolvers.js'; const envStatus = new GraphQLObjectType({ name: 'EnvStatus', diff --git a/src/client/criteria-type.js b/src/client/criteria-type.js index ff75eab..3a31cdf 100644 --- a/src/client/criteria-type.js +++ b/src/client/criteria-type.js @@ -1,7 +1,7 @@ -import { domainType, groupConfigType, strategyType } from './configuration-type'; -import { EnvType } from '../models/environment'; -import { resolveCriteria } from './resolvers'; import { GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean, GraphQLNonNull, GraphQLInputObjectType } from 'graphql'; +import { domainType, groupConfigType, strategyType } from './configuration-type.js'; +import { EnvType } from '../models/environment.js'; +import { resolveCriteria } from './resolvers.js'; export const strategyInputType = new GraphQLInputObjectType({ name: 'StrategyInput', diff --git a/src/client/relay/index.js b/src/client/relay/index.js index 81a7434..21898d0 100644 --- a/src/client/relay/index.js +++ b/src/client/relay/index.js @@ -1,7 +1,7 @@ import axios from 'axios'; import https from 'https'; -import { StrategiesToRelayDataType, RelayMethods } from '../../models/config'; -import { checkHttpsAgent } from '../../external/switcher-api-facade'; +import { StrategiesToRelayDataType, RelayMethods } from '../../models/config.js'; +import { checkHttpsAgent } from '../../external/switcher-api-facade.js'; const agent = async (url) => { const rejectUnauthorized = !(await checkHttpsAgent(url)); diff --git a/src/client/resolvers.js b/src/client/resolvers.js index e161aaa..bf843ea 100644 --- a/src/client/resolvers.js +++ b/src/client/resolvers.js @@ -1,13 +1,13 @@ -import { EnvType } from '../models/environment'; -import Domain from '../models/domain'; -import GroupConfig from '../models/group-config'; -import { Config, RelayTypes} from '../models/config'; -import { addMetrics } from '../models/metric'; -import { ConfigStrategy, processOperation } from '../models/config-strategy'; -import { resolveNotification, resolveValidation } from './relay/index'; -import Component from '../models/component'; -import Logger from '../helpers/logger'; -import { isRelayVerified, isRelayValid } from '../services/config'; +import { EnvType } from '../models/environment.js'; +import Domain from '../models/domain.js'; +import GroupConfig from '../models/group-config.js'; +import { Config, RelayTypes} from '../models/config.js'; +import { addMetrics } from '../models/metric.js'; +import { ConfigStrategy, processOperation } from '../models/config-strategy.js'; +import { resolveNotification, resolveValidation } from './relay/index.js'; +import Component from '../models/component.js'; +import Logger from '../helpers/logger.js'; +import { isRelayVerified, isRelayValid } from '../services/config.js'; export const resolveConfigByKey = async (domain, key) => Config.findOne({ domain, key }, null, { lean: true }); diff --git a/src/client/schema.js b/src/client/schema.js index 7545982..1a5d4c3 100644 --- a/src/client/schema.js +++ b/src/client/schema.js @@ -1,7 +1,7 @@ import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean, GraphQLNonNull } from 'graphql'; -import { domainType } from './configuration-type'; -import { strategyInputType, criteriaType } from './criteria-type'; -import { resolveConfigByKey, resolveDomain } from './resolvers'; +import { domainType } from './configuration-type.js'; +import { strategyInputType, criteriaType } from './criteria-type.js'; +import { resolveConfigByKey, resolveDomain } from './resolvers.js'; const queryType = new GraphQLObjectType({ name: 'Query', diff --git a/src/exceptions/index.js b/src/exceptions/index.js index 308819d..b7d9c1d 100644 --- a/src/exceptions/index.js +++ b/src/exceptions/index.js @@ -1,4 +1,4 @@ -import Logger from '../helpers/logger'; +import Logger from '../helpers/logger.js'; export class BadRequestError extends Error { constructor(message) { diff --git a/src/external/switcher-api-facade.js b/src/external/switcher-api-facade.js index 4a0a310..8b170c1 100644 --- a/src/external/switcher-api-facade.js +++ b/src/external/switcher-api-facade.js @@ -1,6 +1,6 @@ import { Switcher, checkValue, checkRegex } from 'switcher-client'; -import { getDomainById } from '../services/domain'; -import { DEFAULT_RATE_LIMIT } from '../middleware/limiter'; +import { getDomainById } from '../services/domain.js'; +import { DEFAULT_RATE_LIMIT } from '../middleware/limiter.js'; const apiKey = process.env.SWITCHER_API_KEY; const environment = process.env.SWITCHER_API_ENVIRONMENT; diff --git a/src/helpers/ipcidr.js b/src/helpers/ipcidr.js index 94453d0..0d392c4 100644 --- a/src/helpers/ipcidr.js +++ b/src/helpers/ipcidr.js @@ -1,4 +1,4 @@ -class IPCIDR { +export default class IPCIDR { constructor(cidr) { this.cidr = cidr; } @@ -12,6 +12,4 @@ class IPCIDR { const mask = ~(2 ** (32 - Number(bits)) - 1); return (this.ip4ToInt(ip) & mask) === (this.ip4ToInt(range) & mask); } -} - -module.exports = IPCIDR; \ No newline at end of file +} \ No newline at end of file diff --git a/src/helpers/timed-match/index.js b/src/helpers/timed-match/index.js index a99a017..fa3a877 100644 --- a/src/helpers/timed-match/index.js +++ b/src/helpers/timed-match/index.js @@ -1,11 +1,16 @@ -const cp = require('child_process'); +import cp from 'child_process'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); /** * This class will run a match operation using a child process. * Workers should be killed given a specified (3000 ms default) time limit. * Blacklist caching is available to prevent sequence of matching failures and resource usage. */ -class TimedMatch { +export default class TimedMatch { static _worker = this._createChildProcess(); static _blacklisted = []; static _maxBlackListed = process.env.REGEX_MAX_BLACKLIST || 50; @@ -101,6 +106,4 @@ class TimedMatch { match_proc.channel.unref(); return match_proc; } -} - -module.exports = TimedMatch; \ No newline at end of file +} \ No newline at end of file diff --git a/src/index.js b/src/index.js index 7fca4dd..e72dd58 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import app from './app'; +import app from './app.js'; const port = process.env.PORT; diff --git a/src/middleware/auth.js b/src/middleware/auth.js index 4843f92..bd2b767 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -1,9 +1,9 @@ import basicAuth from 'express-basic-auth'; import jwt from 'jsonwebtoken'; -import { getComponentById } from '../services/component'; -import { responseExceptionSilent } from '../exceptions'; -import Component from '../models/component'; -import { getRateLimit } from '../external/switcher-api-facade'; +import { getComponentById } from '../services/component.js'; +import { responseExceptionSilent } from '../exceptions/index.js'; +import Component from '../models/component.js'; +import { getRateLimit } from '../external/switcher-api-facade.js'; export function resourcesAuth() { return basicAuth({ diff --git a/src/middleware/validators.js b/src/middleware/validators.js index f7921c3..f26618b 100644 --- a/src/middleware/validators.js +++ b/src/middleware/validators.js @@ -1,5 +1,5 @@ import { validationResult } from 'express-validator'; -import { getConfig } from '../services/config'; +import { getConfig } from '../services/config.js'; export async function checkConfig(req, res, next) { const config = await getConfig({ domain: req.domain, key: String(req.query.key) }, true); diff --git a/src/models/component.js b/src/models/component.js index 3b87353..559a3d4 100644 --- a/src/models/component.js +++ b/src/models/component.js @@ -2,7 +2,7 @@ import mongoose from 'mongoose'; import bcryptjs from 'bcryptjs'; import { randomUUID } from 'crypto'; import jwt from 'jsonwebtoken'; -import Domain from './domain'; +import Domain from './domain.js'; export const EncryptionSalts = Object.freeze({ COMPONENT: 8 diff --git a/src/models/config-strategy.js b/src/models/config-strategy.js index 0bd8c54..3c38673 100644 --- a/src/models/config-strategy.js +++ b/src/models/config-strategy.js @@ -1,8 +1,8 @@ import mongoose from 'mongoose'; import moment from 'moment'; -import { parseJSON, payloadReader } from '../helpers'; -import IPCIDR from '../helpers/ipcidr'; -import TimedMatch from '../helpers/timed-match/'; +import { parseJSON, payloadReader } from '../helpers/index.js'; +import IPCIDR from '../helpers/ipcidr.js'; +import TimedMatch from '../helpers/timed-match/index.js'; export const StrategiesType = Object.freeze({ NETWORK: 'NETWORK_VALIDATION', diff --git a/src/models/config.js b/src/models/config.js index e4e7693..f5e2192 100644 --- a/src/models/config.js +++ b/src/models/config.js @@ -1,5 +1,5 @@ import mongoose from 'mongoose'; -import { EnvType } from './environment'; +import { EnvType } from './environment.js'; export const RelayMethods = Object.freeze({ POST: 'POST', diff --git a/src/models/domain.js b/src/models/domain.js index 2aa6305..413f67e 100644 --- a/src/models/domain.js +++ b/src/models/domain.js @@ -1,5 +1,5 @@ import mongoose from 'mongoose'; -import { EnvType } from './environment'; +import { EnvType } from './environment.js'; const domainSchema = new mongoose.Schema({ name: { diff --git a/src/models/group-config.js b/src/models/group-config.js index dee6422..8b66bab 100644 --- a/src/models/group-config.js +++ b/src/models/group-config.js @@ -1,5 +1,5 @@ import mongoose from 'mongoose'; -import { EnvType } from '../models/environment'; +import { EnvType } from '../models/environment.js'; const groupConfigSchema = new mongoose.Schema({ name: { diff --git a/src/routers/client-api.js b/src/routers/client-api.js index f4d620f..22d01c4 100644 --- a/src/routers/client-api.js +++ b/src/routers/client-api.js @@ -1,12 +1,12 @@ import express from 'express'; -import jwt from 'jsonwebtoken'; -import { checkConfig, checkConfigComponent, validate } from '../middleware/validators'; -import { appAuth, appGenerateCredentials } from '../middleware/auth'; -import { resolveCriteria, checkDomain } from '../client/resolvers'; -import { getConfigs } from '../services/config'; import { body, check, query } from 'express-validator'; -import { clientLimiter } from '../middleware/limiter'; -import { StrategiesType } from '../models/config-strategy'; +import jwt from 'jsonwebtoken'; +import { checkConfig, checkConfigComponent, validate } from '../middleware/validators.js'; +import { appAuth, appGenerateCredentials } from '../middleware/auth.js'; +import { resolveCriteria, checkDomain } from '../client/resolvers.js'; +import { getConfigs } from '../services/config.js'; +import { clientLimiter } from '../middleware/limiter.js'; +import { StrategiesType } from '../models/config-strategy.js'; const router = new express.Router(); diff --git a/src/services/component.js b/src/services/component.js index 5aa0049..343cf42 100644 --- a/src/services/component.js +++ b/src/services/component.js @@ -1,4 +1,4 @@ -import Component from '../models/component'; +import Component from '../models/component.js'; export async function getComponentById(id) { return Component.findById(id).exec(); diff --git a/src/services/config.js b/src/services/config.js index fa4567d..8e744a0 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -1,5 +1,5 @@ -import { Config } from '../models/config'; -import { BadRequestError } from '../exceptions'; +import { Config } from '../models/config.js'; +import { BadRequestError } from '../exceptions/index.js'; export async function getConfig(where, lean = false) { const query = Config.findOne(); diff --git a/src/services/domain.js b/src/services/domain.js index 204b4a2..93bfac9 100644 --- a/src/services/domain.js +++ b/src/services/domain.js @@ -1,4 +1,4 @@ -import Domain from '../models/domain'; +import Domain from '../models/domain.js'; export async function getDomainById(id) { return Domain.findById(id).exec(); diff --git a/src/start.js b/src/start.js index 601e03a..833b6a2 100644 --- a/src/start.js +++ b/src/start.js @@ -1,7 +1 @@ -require('@babel/register') ({ - presets: ['@babel/preset-env'] -}); -require('babel-polyfill'); - -// Import the rest of our application. -module.exports = require('./index.js'); \ No newline at end of file +export * from './index.js'; \ No newline at end of file diff --git a/tests/model/component.test.js b/tests/model/component.test.js index 6e8468d..c5b8134 100644 --- a/tests/model/component.test.js +++ b/tests/model/component.test.js @@ -1,4 +1,4 @@ -require('../../src/db/mongoose'); +import '../../src/db/mongoose'; import { randomBytes } from 'crypto'; import bcryptjs from 'bcryptjs'; diff --git a/tests/unit-test/helpers/logger.test.js b/tests/unit-test/helpers/logger.test.js index c56b078..c976668 100644 --- a/tests/unit-test/helpers/logger.test.js +++ b/tests/unit-test/helpers/logger.test.js @@ -1,4 +1,5 @@ import Logger from '../../../src/helpers/logger'; +import { jest } from '@jest/globals'; describe('Helper: Logger', () => { beforeAll(() => { diff --git a/tests/unit-test/switcher-api-facade.test.js b/tests/unit-test/switcher-api-facade.test.js index 6f96e8e..b248b3c 100644 --- a/tests/unit-test/switcher-api-facade.test.js +++ b/tests/unit-test/switcher-api-facade.test.js @@ -12,7 +12,7 @@ import { import { Switcher, checkValue } from 'switcher-client'; import ExecutionLogger from 'switcher-client/src/lib/utils/executionLogger'; -require('../../src/db/mongoose'); +import '../../src/db/mongoose'; afterAll(async () => { await new Promise(resolve => setTimeout(resolve, 1000));