diff --git a/.env-cmdrc-template b/.env-cmdrc-template index 291f708..4f6ccae 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 1cda1e8..89b73cd 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 HISTORY_ACTIVATED: true JWT_ADMIN_TOKEN_RENEW_INTERVAL: 5m diff --git a/.github/workflows/re-release.yml b/.github/workflows/re-release.yml index c97b74f..5c736ae 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 HISTORY_ACTIVATED: true JWT_ADMIN_TOKEN_RENEW_INTERVAL: 5m diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fdfc926..196e367 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 HISTORY_ACTIVATED: true JWT_ADMIN_TOKEN_RENEW_INTERVAL: 5m 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/LICENSE b/LICENSE index 6f2b603..3db12de 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Roger Floriano (petruki) and Contributors +Copyright (c) 2019-present Roger Floriano (petruki) and Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal 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 b677fff..450b79f 100644 --- a/package.json +++ b/package.json @@ -3,22 +3,31 @@ "version": "1.2.8", "description": "Feature Flag/Toggle 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,21 +50,14 @@ "jsonwebtoken": "^9.0.2", "moment": "^2.30.1", "mongodb": "^6.5.0", - "mongoose": "^8.2.4", - "pino": "^8.19.0", + "mongoose": "^8.3.0", + "pino": "^8.20.0", "pino-pretty": "^11.0.0", "swagger-ui-express": "^5.0.0", "switcher-client": "^3.2.1", "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-admin.js b/src/api-docs/paths/path-admin.js index 0f70ff8..8386b00 100644 --- a/src/api-docs/paths/path-admin.js +++ b/src/api-docs/paths/path-admin.js @@ -1,6 +1,6 @@ -import { jwt } from '../schemas/admin'; -import { pathParameter, queryParameter } from '../schemas/common'; -import { commonSchemaContent } from './common'; +import { jwt } from '../schemas/admin.js'; +import { pathParameter, queryParameter } from '../schemas/common.js'; +import { commonSchemaContent } from './common.js'; export default { '/admin/signup': { diff --git a/src/api-docs/paths/path-client.js b/src/api-docs/paths/path-client.js index 9bf3c3e..3df491e 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/paths/path-component.js b/src/api-docs/paths/path-component.js index 0d17234..84fb4c9 100644 --- a/src/api-docs/paths/path-component.js +++ b/src/api-docs/paths/path-component.js @@ -1,5 +1,5 @@ -import { pagination, pathParameter, queryParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonSchemaContent } from './common'; +import { pagination, pathParameter, queryParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonSchemaContent } from './common.js'; export default { '/component/create': { diff --git a/src/api-docs/paths/path-config-strategy.js b/src/api-docs/paths/path-config-strategy.js index 2e77cfa..d9e6b1e 100644 --- a/src/api-docs/paths/path-config-strategy.js +++ b/src/api-docs/paths/path-config-strategy.js @@ -1,6 +1,6 @@ -import { OperationsType, StrategiesType } from '../../models/config-strategy'; -import { pagination, pathParameter, queryParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonSchemaContent } from './common'; +import { OperationsType, StrategiesType } from '../../models/config-strategy.js'; +import { pagination, pathParameter, queryParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonSchemaContent } from './common.js'; export default { '/configstrategy/create': { diff --git a/src/api-docs/paths/path-config.js b/src/api-docs/paths/path-config.js index b520300..990d8ca 100644 --- a/src/api-docs/paths/path-config.js +++ b/src/api-docs/paths/path-config.js @@ -1,5 +1,5 @@ -import { pagination, pathParameter, queryParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonOneOfSchemaContent, commonSchemaContent } from './common'; +import { pagination, pathParameter, queryParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonOneOfSchemaContent, commonSchemaContent } from './common.js'; export default { '/config/create': { diff --git a/src/api-docs/paths/path-domain.js b/src/api-docs/paths/path-domain.js index c9c1bc1..adaad9a 100644 --- a/src/api-docs/paths/path-domain.js +++ b/src/api-docs/paths/path-domain.js @@ -1,5 +1,5 @@ -import { pagination, pathParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonSchemaContent } from './common'; +import { pagination, pathParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonSchemaContent } from './common.js'; export default { '/domain/create': { diff --git a/src/api-docs/paths/path-environment.js b/src/api-docs/paths/path-environment.js index c5fad9c..2fe9411 100644 --- a/src/api-docs/paths/path-environment.js +++ b/src/api-docs/paths/path-environment.js @@ -1,5 +1,5 @@ -import { pagination, pathParameter, queryParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonSchemaContent } from './common'; +import { pagination, pathParameter, queryParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonSchemaContent } from './common.js'; export default { '/environment/create': { diff --git a/src/api-docs/paths/path-group-config.js b/src/api-docs/paths/path-group-config.js index 2e0c11f..682e329 100644 --- a/src/api-docs/paths/path-group-config.js +++ b/src/api-docs/paths/path-group-config.js @@ -1,5 +1,5 @@ -import { pagination, pathParameter, queryParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonSchemaContent } from './common'; +import { pagination, pathParameter, queryParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonSchemaContent } from './common.js'; export default { '/groupconfig/create': { diff --git a/src/api-docs/paths/path-metric.js b/src/api-docs/paths/path-metric.js index f259923..b70c467 100644 --- a/src/api-docs/paths/path-metric.js +++ b/src/api-docs/paths/path-metric.js @@ -1,5 +1,5 @@ -import { queryParameter } from '../schemas/common'; -import { commonSchemaContent } from './common'; +import { queryParameter } from '../schemas/common.js'; +import { commonSchemaContent } from './common.js'; export default { '/metric/data': { diff --git a/src/api-docs/paths/path-permission.js b/src/api-docs/paths/path-permission.js index f9798da..acd4d0b 100644 --- a/src/api-docs/paths/path-permission.js +++ b/src/api-docs/paths/path-permission.js @@ -1,6 +1,6 @@ -import { ActionTypes, RouterTypes } from '../../models/permission'; -import { pathParameter, queryParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonSchemaContent } from './common'; +import { ActionTypes, RouterTypes } from '../../models/permission.js'; +import { pathParameter, queryParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonSchemaContent } from './common.js'; export default { '/permission/create/{team}': { diff --git a/src/api-docs/paths/path-slack.js b/src/api-docs/paths/path-slack.js index 939a0b4..68e2183 100644 --- a/src/api-docs/paths/path-slack.js +++ b/src/api-docs/paths/path-slack.js @@ -1,5 +1,5 @@ -import { pathParameter, queryParameter } from '../schemas/common'; -import { commonSchemaContent } from './common'; +import { pathParameter, queryParameter } from '../schemas/common.js'; +import { commonSchemaContent } from './common.js'; export default { '/slack/v1/installation': { diff --git a/src/api-docs/paths/path-team.js b/src/api-docs/paths/path-team.js index 487bd25..f6dbeaf 100644 --- a/src/api-docs/paths/path-team.js +++ b/src/api-docs/paths/path-team.js @@ -1,5 +1,5 @@ -import { pagination, pathParameter, queryParameter } from '../schemas/common'; -import { commonArraySchemaContent, commonSchemaContent } from './common'; +import { pagination, pathParameter, queryParameter } from '../schemas/common.js'; +import { commonArraySchemaContent, commonSchemaContent } from './common.js'; export default { '/team/create': { diff --git a/src/api-docs/schemas/config-strategy.js b/src/api-docs/schemas/config-strategy.js index ff2e488..e13c28d 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/schemas/config.js b/src/api-docs/schemas/config.js index 7714476..2657a16 100644 --- a/src/api-docs/schemas/config.js +++ b/src/api-docs/schemas/config.js @@ -1,4 +1,4 @@ -import componentSchema from './component'; +import componentSchema from './component.js'; const configComponents = { type: 'array', diff --git a/src/api-docs/schemas/metric.js b/src/api-docs/schemas/metric.js index 0d74751..98f3882 100644 --- a/src/api-docs/schemas/metric.js +++ b/src/api-docs/schemas/metric.js @@ -1,4 +1,4 @@ -import { StrategiesType } from '../../models/config-strategy'; +import { StrategiesType } from '../../models/config-strategy.js'; const data = { type: 'object', diff --git a/src/api-docs/schemas/permission.js b/src/api-docs/schemas/permission.js index 3ec9115..d1847ab 100644 --- a/src/api-docs/schemas/permission.js +++ b/src/api-docs/schemas/permission.js @@ -1,4 +1,4 @@ -import { ActionTypes, KeyTypes, RouterTypes } from '../../models/permission'; +import { ActionTypes, KeyTypes, RouterTypes } from '../../models/permission.js'; const permission = { type: 'object', diff --git a/src/api-docs/schemas/slack.js b/src/api-docs/schemas/slack.js index 9de89fa..c5d8eac 100644 --- a/src/api-docs/schemas/slack.js +++ b/src/api-docs/schemas/slack.js @@ -1,4 +1,4 @@ -import { TicketStatusType } from '../../models/slack_ticket'; +import { TicketStatusType } from '../../models/slack_ticket.js'; const ticket = { type: 'object', diff --git a/src/api-docs/swagger-document.js b/src/api-docs/swagger-document.js index 4616b33..a9bc23c 100644 --- a/src/api-docs/swagger-document.js +++ b/src/api-docs/swagger-document.js @@ -1,29 +1,29 @@ -import pathAdmin from './paths/path-admin'; -import pathDomain from './paths/path-domain'; -import pathGroup from './paths/path-group-config'; -import pathConfig from './paths/path-config'; -import pathConfigStrategy from './paths/path-config-strategy'; -import pathEnvironment from './paths/path-environment'; -import pathComponent from './paths/path-component'; -import pathTeam from './paths/path-team'; -import pathPermission from './paths/path-permission'; -import pathMetric from './paths/path-metric'; -import pathSlack from './paths/path-slack'; -import pathClient from './paths/path-client'; +import pathAdmin from './paths/path-admin.js'; +import pathDomain from './paths/path-domain.js'; +import pathGroup from './paths/path-group-config.js'; +import pathConfig from './paths/path-config.js'; +import pathConfigStrategy from './paths/path-config-strategy.js'; +import pathEnvironment from './paths/path-environment.js'; +import pathComponent from './paths/path-component.js'; +import pathTeam from './paths/path-team.js'; +import pathPermission from './paths/path-permission.js'; +import pathMetric from './paths/path-metric.js'; +import pathSlack from './paths/path-slack.js'; +import pathClient from './paths/path-client.js'; -import { commonSchema } from './schemas/common'; -import adminSchema from './schemas/admin'; -import domainSchema from './schemas/domain'; -import groupSchema from './schemas/group-config'; -import configSchema from './schemas/config'; -import configStrategySchema from './schemas/config-strategy'; -import environmentSchema from './schemas/environment'; -import componentSchema from './schemas/component'; -import teamSchema from './schemas/team'; -import permissionSchema from './schemas/permission'; -import metricSchema from './schemas/metric'; -import slackSchema from './schemas/slack'; -import info from './swagger-info'; +import { commonSchema } from './schemas/common.js'; +import adminSchema from './schemas/admin.js'; +import domainSchema from './schemas/domain.js'; +import groupSchema from './schemas/group-config.js'; +import configSchema from './schemas/config.js'; +import configStrategySchema from './schemas/config-strategy.js'; +import environmentSchema from './schemas/environment.js'; +import componentSchema from './schemas/component.js'; +import teamSchema from './schemas/team.js'; +import permissionSchema from './schemas/permission.js'; +import metricSchema from './schemas/metric.js'; +import slackSchema from './schemas/slack.js'; +import info from './swagger-info.js'; export default { openapi: '3.0.1', 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 1684396..e7c367a 100644 --- a/src/app.js +++ b/src/app.js @@ -4,26 +4,26 @@ 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 adminRouter from './routers/admin'; -import environment from './routers/environment'; -import component from './routers/component'; -import domainRouter from './routers/domain'; -import groupConfigRouter from './routers/group-config'; -import configRouter from './routers/config'; -import configStrategyRouter from './routers/config-strategy'; -import metricRouter from './routers/metric'; -import teamRouter from './routers/team'; -import permissionRouter from './routers/permission'; -import slackRouter from './routers/slack'; -import schema from './client/schema'; -import { componentAuth, auth, resourcesAuth, slackAuth, gitopsAuth } 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 adminRouter from './routers/admin.js'; +import environment from './routers/environment.js'; +import component from './routers/component.js'; +import domainRouter from './routers/domain.js'; +import groupConfigRouter from './routers/group-config.js'; +import configRouter from './routers/config.js'; +import configStrategyRouter from './routers/config-strategy.js'; +import metricRouter from './routers/metric.js'; +import teamRouter from './routers/team.js'; +import permissionRouter from './routers/permission.js'; +import slackRouter from './routers/slack.js'; +import schema from './client/schema.js'; +import { componentAuth, auth, resourcesAuth, slackAuth, gitopsAuth } 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 4d64d9d..ebb8acb 100644 --- a/src/client/configuration-resolvers.js +++ b/src/client/configuration-resolvers.js @@ -1,12 +1,12 @@ -import { verifyOwnership } from '../helpers'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { getGroupConfigById, getGroupConfigs } from '../services/group-config'; -import { getConfigs } from '../services/config'; -import { getStrategies } from '../services/config-strategy'; -import { getEnvironments } from '../services/environment'; -import { getSlack } from '../services/slack'; -import { getDomainById } from '../services/domain'; -import { getComponents } from '../services/component'; +import { verifyOwnership } from '../helpers/index.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { getGroupConfigById, getGroupConfigs } from '../services/group-config.js'; +import { getConfigs } from '../services/config.js'; +import { getStrategies } from '../services/config-strategy.js'; +import { getEnvironments } from '../services/environment.js'; +import { getSlack } from '../services/slack.js'; +import { getDomainById } from '../services/domain.js'; +import { getComponents } from '../services/component.js'; async function resolveConfigByConfig(domainId, key, configId) { const config = await getConfigs({ diff --git a/src/client/configuration-type.js b/src/client/configuration-type.js index 1b96851..96fef6a 100644 --- a/src/client/configuration-type.js +++ b/src/client/configuration-type.js @@ -1,6 +1,6 @@ -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 { resolveFlatDomain, resolveFlatGroupConfig, @@ -8,7 +8,7 @@ import { resolveFlatConfigStrategy, resolveComponents, resolveFlatEnv -} 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/permission-resolvers.js b/src/client/permission-resolvers.js index b4169ec..3b33788 100644 --- a/src/client/permission-resolvers.js +++ b/src/client/permission-resolvers.js @@ -1,8 +1,8 @@ -import { verifyOwnership } from '../helpers'; -import { RouterTypes } from '../models/permission'; -import { getConfigs } from '../services/config'; -import { getGroupConfigs } from '../services/group-config'; -import { permissionCache } from '../helpers/cache'; +import { verifyOwnership } from '../helpers/index.js'; +import { RouterTypes } from '../models/permission.js'; +import { getConfigs } from '../services/config.js'; +import { getGroupConfigs } from '../services/group-config.js'; +import { permissionCache } from '../helpers/cache.js'; export async function resolvePermission(args, admin) { const cacheKey = permissionCache.permissionKey(admin._id, args.domain, args.parent, diff --git a/src/client/relay/index.js b/src/client/relay/index.js index 680087b..d96b5b5 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 452ab8d..b2a87bf 100644 --- a/src/client/resolvers.js +++ b/src/client/resolvers.js @@ -1,15 +1,15 @@ -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 { ActionTypes, RouterTypes } from '../models/permission'; -import { verifyOwnership } from '../helpers'; -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 { ActionTypes, RouterTypes } from '../models/permission.js'; +import { verifyOwnership } from '../helpers/index.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 bf0561e..2d6fb98 100644 --- a/src/client/schema.js +++ b/src/client/schema.js @@ -1,10 +1,10 @@ import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLList, GraphQLBoolean, GraphQLNonNull } from 'graphql'; -import { domainType, flatConfigurationType } from './configuration-type'; -import { strategyInputType, criteriaType } from './criteria-type'; -import { resolveConfigByKey, resolveDomain } from './resolvers'; -import { resolveConfiguration } from './configuration-resolvers'; -import { permissionType } from './permission-type'; -import { resolvePermission } from './permission-resolvers'; +import { domainType, flatConfigurationType } from './configuration-type.js'; +import { strategyInputType, criteriaType } from './criteria-type.js'; +import { resolveConfigByKey, resolveDomain } from './resolvers.js'; +import { resolveConfiguration } from './configuration-resolvers.js'; +import { permissionType } from './permission-type.js'; +import { resolvePermission } from './permission-resolvers.js'; const queryType = new GraphQLObjectType({ name: 'Query', diff --git a/src/exceptions/index.js b/src/exceptions/index.js index 1437d42..6766614 100644 --- a/src/exceptions/index.js +++ b/src/exceptions/index.js @@ -1,5 +1,5 @@ import { Switcher } from 'switcher-client'; -import Logger from '../helpers/logger'; +import Logger from '../helpers/logger.js'; export class NotFoundError extends Error { constructor(message) { diff --git a/src/external/switcher-api-facade.js b/src/external/switcher-api-facade.js index d314cac..814dde9 100644 --- a/src/external/switcher-api-facade.js +++ b/src/external/switcher-api-facade.js @@ -1,13 +1,13 @@ import { Switcher, checkValue, checkPayload, checkRegex } from 'switcher-client'; -import { EnvType } from '../models/environment'; -import { FeatureUnavailableError } from '../exceptions'; -import { getDomainById, getTotalDomainsByOwner } from '../services/domain'; -import { getTotalGroupsByDomainId } from '../services/group-config'; -import { getTotalConfigsByDomainId } from '../services/config'; -import { getTotalComponentsByDomainId } from '../services/component'; -import { getTotalEnvByDomainId } from '../services/environment'; -import { getTotalTeamsByDomainId } from '../services/team'; -import { DEFAULT_RATE_LIMIT } from '../middleware/limiter'; +import { EnvType } from '../models/environment.js'; +import { FeatureUnavailableError } from '../exceptions/index.js'; +import { getDomainById, getTotalDomainsByOwner } from '../services/domain.js'; +import { getTotalGroupsByDomainId } from '../services/group-config.js'; +import { getTotalConfigsByDomainId } from '../services/config.js'; +import { getTotalComponentsByDomainId } from '../services/component.js'; +import { getTotalEnvByDomainId } from '../services/environment.js'; +import { getTotalTeamsByDomainId } from '../services/team.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/cache.js b/src/helpers/cache.js index 7ea2fce..ee9d585 100644 --- a/src/helpers/cache.js +++ b/src/helpers/cache.js @@ -1,4 +1,4 @@ -import { ActionTypes } from '../models/permission'; +import { ActionTypes } from '../models/permission.js'; class Cache { constructor() { diff --git a/src/helpers/index.js b/src/helpers/index.js index d5615e3..534883c 100644 --- a/src/helpers/index.js +++ b/src/helpers/index.js @@ -1,9 +1,9 @@ -import { BadRequestError, PermissionError } from '../exceptions'; -import { EnvType } from '../models/environment'; -import { getDomainById } from '../services/domain'; -import { getEnvironments } from '../services/environment'; -import { getTeams } from '../services/team'; -import { verifyPermissions, verifyPermissionsCascade } from './permission'; +import { BadRequestError, PermissionError } from '../exceptions/index.js'; +import { EnvType } from '../models/environment.js'; +import { getDomainById } from '../services/domain.js'; +import { getEnvironments } from '../services/environment.js'; +import { getTeams } from '../services/team.js'; +import { verifyPermissions, verifyPermissionsCascade } from './permission.js'; const PATTERN_ALPHANUMERIC_SPACE = /^[a-zA-Z0-9_\- ]*$/; const PATTERN_ALPHANUMERIC = /^[a-zA-Z0-9_-]*$/; 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/permission.js b/src/helpers/permission.js index 84e6016..0dbbf45 100644 --- a/src/helpers/permission.js +++ b/src/helpers/permission.js @@ -1,5 +1,5 @@ -import { ActionTypes, RouterTypes } from '../models/permission'; -import { getPermission, getPermissions } from '../services/permission'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { getPermission, getPermissions } from '../services/permission.js'; export async function verifyPermissions(team, element, actions, routerType, environment) { actions.push(ActionTypes.ALL); 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 fb3c123..642d79a 100644 --- a/src/middleware/auth.js +++ b/src/middleware/auth.js @@ -1,12 +1,12 @@ import basicAuth from 'express-basic-auth'; import jwt from 'jsonwebtoken'; -import { getAdmin, getAdminById } from '../services/admin'; -import { getComponentById } from '../services/component'; -import Admin from '../models/admin'; -import Component from '../models/component'; -import { getRateLimit } from '../external/switcher-api-facade'; -import { responseExceptionSilent } from '../exceptions'; -import { EnvType } from '../models/environment'; +import { getAdmin, getAdminById } from '../services/admin.js'; +import { getComponentById } from '../services/component.js'; +import Admin from '../models/admin.js'; +import Component from '../models/component.js'; +import { getRateLimit } from '../external/switcher-api-facade.js'; +import { responseExceptionSilent } from '../exceptions/index.js'; +import { EnvType } from '../models/environment.js'; export async function auth(req, res, next) { try { diff --git a/src/middleware/validators.js b/src/middleware/validators.js index 0672d03..54ed5ca 100644 --- a/src/middleware/validators.js +++ b/src/middleware/validators.js @@ -1,7 +1,7 @@ import { validationResult } from 'express-validator'; -import { BadRequestError, responseException } from '../exceptions'; -import { getConfig } from '../services/config'; -import { getEnvironments } from '../services/environment'; +import { BadRequestError, responseException } from '../exceptions/index.js'; +import { getConfig } from '../services/config.js'; +import { getEnvironments } from '../services/environment.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/admin.js b/src/models/admin.js index c8bd07c..f1971ae 100644 --- a/src/models/admin.js +++ b/src/models/admin.js @@ -3,9 +3,9 @@ import moment from 'moment'; import bcryptjs from 'bcryptjs'; import crypto from 'crypto'; import jwt from 'jsonwebtoken'; -import { Team } from './team'; -import { notifyAcCreation, notifyAcDeletion } from '../external/switcher-api-facade'; -import { EncryptionSalts } from './common'; +import { Team } from './team.js'; +import { notifyAcCreation, notifyAcDeletion } from '../external/switcher-api-facade.js'; +import { EncryptionSalts } from './common/index.js'; const adminSchema = new mongoose.Schema({ name: { diff --git a/src/models/common/index.js b/src/models/common/index.js index c9777f0..abc3990 100644 --- a/src/models/common/index.js +++ b/src/models/common/index.js @@ -1,5 +1,5 @@ -import History from '../history'; -import { checkHistory } from '../../external/switcher-api-facade'; +import History from '../history.js'; +import { checkHistory } from '../../external/switcher-api-facade.js'; export const EncryptionSalts = Object.freeze({ ADMIN: 8, diff --git a/src/models/component.js b/src/models/component.js index a2a2e60..aa48d93 100644 --- a/src/models/component.js +++ b/src/models/component.js @@ -3,9 +3,9 @@ import moment from 'moment'; import bcryptjs from 'bcryptjs'; import { randomUUID } from 'crypto'; import jwt from 'jsonwebtoken'; -import { Config } from './config'; -import Domain from './domain'; -import { EncryptionSalts } from './common'; +import { Config } from './config.js'; +import Domain from './domain.js'; +import { EncryptionSalts } from './common/index.js'; const componentSchema = new mongoose.Schema({ name: { diff --git a/src/models/config-strategy.js b/src/models/config-strategy.js index 88ce180..a1dbdd0 100644 --- a/src/models/config-strategy.js +++ b/src/models/config-strategy.js @@ -1,11 +1,11 @@ import mongoose from 'mongoose'; -import History from './history'; -import { recordHistory } from './common/index'; import moment from 'moment'; -import { NotFoundError } from '../exceptions'; -import { parseJSON, payloadReader } from '../helpers'; -import IPCIDR from '../helpers/ipcidr'; -import TimedMatch from '../helpers/timed-match/'; +import History from './history.js'; +import { recordHistory } from './common/index.js'; +import { NotFoundError } from '../exceptions/index.js'; +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 88d60cc..d0ab087 100644 --- a/src/models/config.js +++ b/src/models/config.js @@ -1,10 +1,10 @@ import mongoose from 'mongoose'; import moment from 'moment'; -import History from './history'; -import { ConfigStrategy } from './config-strategy'; -import { EnvType } from './environment'; -import { recordHistory } from './common/index'; -import { checkMetrics } from '../external/switcher-api-facade'; +import History from './history.js'; +import { ConfigStrategy } from './config-strategy.js'; +import { EnvType } from './environment.js'; +import { recordHistory } from './common/index.js'; +import { checkMetrics } from '../external/switcher-api-facade.js'; export const RelayMethods = Object.freeze({ POST: 'POST', diff --git a/src/models/domain.js b/src/models/domain.js index 50dd5d6..52e3f79 100644 --- a/src/models/domain.js +++ b/src/models/domain.js @@ -1,12 +1,12 @@ import mongoose from 'mongoose'; import moment from 'moment'; -import Component from './component'; -import GroupConfig from './group-config'; -import History from './history'; -import { Metric } from './metric'; -import { Team } from './team'; -import { EnvType, Environment } from './environment'; -import { recordHistory } from './common/index'; +import Component from './component.js'; +import GroupConfig from './group-config.js'; +import History from './history.js'; +import { Metric } from './metric.js'; +import { Team } from './team.js'; +import { EnvType, Environment } from './environment.js'; +import { recordHistory } from './common/index.js'; const domainSchema = new mongoose.Schema({ name: { diff --git a/src/models/group-config.js b/src/models/group-config.js index 2a12c7e..f219acd 100644 --- a/src/models/group-config.js +++ b/src/models/group-config.js @@ -1,9 +1,9 @@ import mongoose from 'mongoose'; import moment from 'moment'; -import { Config } from './config'; -import History from './history'; -import { EnvType } from '../models/environment'; -import { recordHistory } from './common/index'; +import { Config } from './config.js'; +import History from './history.js'; +import { EnvType } from '../models/environment.js'; +import { recordHistory } from './common/index.js'; const groupConfigSchema = new mongoose.Schema({ name: { diff --git a/src/models/slack.js b/src/models/slack.js index 47b3649..845a185 100644 --- a/src/models/slack.js +++ b/src/models/slack.js @@ -1,6 +1,6 @@ import mongoose from 'mongoose'; import moment from 'moment'; -import { slackTicketSchema, TicketStatusType } from './slack_ticket'; +import { slackTicketSchema, TicketStatusType } from './slack_ticket.js'; const slackSchema = new mongoose.Schema({ user_id: { diff --git a/src/models/team.js b/src/models/team.js index b44cf31..8e4a565 100644 --- a/src/models/team.js +++ b/src/models/team.js @@ -1,6 +1,6 @@ import mongoose from 'mongoose'; -import { Permission, RouterTypes } from './permission'; -import Admin from './admin'; +import { Permission, RouterTypes } from './permission.js'; +import Admin from './admin.js'; const teamSchema = new mongoose.Schema({ name: { diff --git a/src/routers/admin.js b/src/routers/admin.js index cd62187..1269d3c 100644 --- a/src/routers/admin.js +++ b/src/routers/admin.js @@ -1,13 +1,13 @@ import express from 'express'; -import { auth, authRefreshToken } from '../middleware/auth'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; import { check } from 'express-validator'; -import { verifyOwnership } from '../helpers'; -import { permissionCache } from '../helpers/cache'; -import { responseException } from '../exceptions'; -import * as Services from '../services/admin'; -import { SwitcherKeys } from '../external/switcher-api-facade'; -import { checkActionType } from '../models/permission'; +import { auth, authRefreshToken } from '../middleware/auth.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import { verifyOwnership } from '../helpers/index.js'; +import { permissionCache } from '../helpers/cache.js'; +import { responseException } from '../exceptions/index.js'; +import * as Services from '../services/admin.js'; +import { SwitcherKeys } from '../external/switcher-api-facade.js'; +import { checkActionType } from '../models/permission.js'; const router = new express.Router(); diff --git a/src/routers/client-api.js b/src/routers/client-api.js index 66908f7..853ffea 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 { componentAuth, 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 { componentAuth, 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/routers/component.js b/src/routers/component.js index 69e6fb9..4e77c69 100644 --- a/src/routers/component.js +++ b/src/routers/component.js @@ -1,10 +1,10 @@ import express from 'express'; -import { auth } from '../middleware/auth'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; import { check, query } from 'express-validator'; -import * as Services from '../services/component'; -import { responseException } from '../exceptions'; -import { SwitcherKeys } from '../external/switcher-api-facade'; +import { auth } from '../middleware/auth.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import * as Services from '../services/component.js'; +import { responseException } from '../exceptions/index.js'; +import { SwitcherKeys } from '../external/switcher-api-facade.js'; const router = new express.Router(); diff --git a/src/routers/config-strategy.js b/src/routers/config-strategy.js index 10d61a9..0c5d84d 100644 --- a/src/routers/config-strategy.js +++ b/src/routers/config-strategy.js @@ -1,15 +1,15 @@ import express from 'express'; import { check, query } from 'express-validator'; -import { EnvType } from '../models/environment'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; -import { strategyRequirements, StrategiesType } from '../models/config-strategy'; -import { auth } from '../middleware/auth'; -import { verifyOwnership, sortBy } from '../helpers'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { getConfigById } from '../services/config'; -import { getHistory, deleteHistory } from '../services/history'; -import * as Services from '../services/config-strategy'; -import { responseException } from '../exceptions'; +import { EnvType } from '../models/environment.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import { strategyRequirements, StrategiesType } from '../models/config-strategy.js'; +import { auth } from '../middleware/auth.js'; +import { verifyOwnership, sortBy } from '../helpers/index.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { getConfigById } from '../services/config.js'; +import { getHistory, deleteHistory } from '../services/history.js'; +import * as Services from '../services/config-strategy.js'; +import { responseException } from '../exceptions/index.js'; const router = new express.Router(); diff --git a/src/routers/config.js b/src/routers/config.js index 4bd1fb6..e72b49c 100644 --- a/src/routers/config.js +++ b/src/routers/config.js @@ -1,18 +1,18 @@ import express from 'express'; import { check, query } from 'express-validator'; -import { relayOptions } from '../models/config'; -import { auth } from '../middleware/auth'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { responseException } from '../exceptions'; +import { relayOptions } from '../models/config.js'; +import { auth } from '../middleware/auth.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { responseException } from '../exceptions/index.js'; import { validate, - verifyInputUpdateParameters } from '../middleware/validators'; -import { sortBy, verifyOwnership } from '../helpers'; -import * as Services from '../services/config'; -import { getHistory, deleteHistory } from '../services/history'; -import { getGroupConfigById } from '../services/group-config'; -import { SwitcherKeys } from '../external/switcher-api-facade'; -import { getFields } from './common'; + verifyInputUpdateParameters } from '../middleware/validators.js'; +import { sortBy, verifyOwnership } from '../helpers/index.js'; +import * as Services from '../services/config.js'; +import { getHistory, deleteHistory } from '../services/history.js'; +import { getGroupConfigById } from '../services/group-config.js'; +import { SwitcherKeys } from '../external/switcher-api-facade.js'; +import { getFields } from './common/index.js'; const router = new express.Router(); diff --git a/src/routers/domain.js b/src/routers/domain.js index 4ec66f6..820d628 100644 --- a/src/routers/domain.js +++ b/src/routers/domain.js @@ -1,13 +1,13 @@ import express from 'express'; -import { auth } from '../middleware/auth'; import { check } from 'express-validator'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; -import { verifyOwnership, sortBy } from '../helpers'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { checkDomain, SwitcherKeys } from '../external/switcher-api-facade'; -import * as Services from '../services/domain'; -import { getHistory } from '../services/history'; -import { responseException } from '../exceptions'; +import { auth } from '../middleware/auth.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import { verifyOwnership, sortBy } from '../helpers/index.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { checkDomain, SwitcherKeys } from '../external/switcher-api-facade.js'; +import * as Services from '../services/domain.js'; +import { getHistory } from '../services/history.js'; +import { responseException } from '../exceptions/index.js'; const router = new express.Router(); diff --git a/src/routers/environment.js b/src/routers/environment.js index 28033ce..87c4f4a 100644 --- a/src/routers/environment.js +++ b/src/routers/environment.js @@ -1,10 +1,10 @@ import express from 'express'; import { check, query } from 'express-validator'; -import { auth } from '../middleware/auth'; -import { responseException } from '../exceptions'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; -import * as Services from '../services/environment'; -import { SwitcherKeys } from '../external/switcher-api-facade'; +import { auth } from '../middleware/auth.js'; +import { responseException } from '../exceptions/index.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import * as Services from '../services/environment.js'; +import { SwitcherKeys } from '../external/switcher-api-facade.js'; const router = new express.Router(); diff --git a/src/routers/group-config.js b/src/routers/group-config.js index a8fb72a..d5b6044 100644 --- a/src/routers/group-config.js +++ b/src/routers/group-config.js @@ -1,14 +1,14 @@ import express from 'express'; import { check, query } from 'express-validator'; -import { auth } from '../middleware/auth'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; -import { sortBy, verifyOwnership } from '../helpers'; -import { responseException } from '../exceptions'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import * as Services from '../services/group-config'; -import { getHistory, deleteHistory } from '../services/history'; -import { getDomainById } from '../services/domain'; -import { SwitcherKeys } from '../external/switcher-api-facade'; +import { auth } from '../middleware/auth.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import { sortBy, verifyOwnership } from '../helpers/index.js'; +import { responseException } from '../exceptions/index.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import * as Services from '../services/group-config.js'; +import { getHistory, deleteHistory } from '../services/history.js'; +import { getDomainById } from '../services/domain.js'; +import { SwitcherKeys } from '../external/switcher-api-facade.js'; const router = new express.Router(); diff --git a/src/routers/metric.js b/src/routers/metric.js index 4526223..e3ab2c6 100644 --- a/src/routers/metric.js +++ b/src/routers/metric.js @@ -1,13 +1,13 @@ import express from 'express'; import { check, query } from 'express-validator'; -import { auth } from '../middleware/auth'; -import { responseException } from '../exceptions'; +import { auth } from '../middleware/auth.js'; +import { responseException } from '../exceptions/index.js'; import { deleteMetrics, getData, getStatistics -} from '../services/metric'; -import { validate } from '../middleware/validators'; +} from '../services/metric.js'; +import { validate } from '../middleware/validators.js'; const router = new express.Router(); diff --git a/src/routers/permission.js b/src/routers/permission.js index f1458e7..34fef27 100644 --- a/src/routers/permission.js +++ b/src/routers/permission.js @@ -1,12 +1,12 @@ import express from 'express'; -import { auth } from '../middleware/auth'; -import { RouterTypes, ActionTypes, getKeysByRouter } from '../models/permission'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; -import { verifyOwnership } from '../helpers'; -import { responseException } from '../exceptions'; import { body, check, query } from 'express-validator'; -import * as Services from '../services/permission'; -import { getTeamById } from '../services/team'; +import { auth } from '../middleware/auth.js'; +import { RouterTypes, ActionTypes, getKeysByRouter } from '../models/permission.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import { verifyOwnership } from '../helpers/index.js'; +import { responseException } from '../exceptions/index.js'; +import * as Services from '../services/permission.js'; +import { getTeamById } from '../services/team.js'; const router = new express.Router(); diff --git a/src/routers/slack.js b/src/routers/slack.js index cc228a9..9a8403c 100644 --- a/src/routers/slack.js +++ b/src/routers/slack.js @@ -1,12 +1,12 @@ import express from 'express'; import { check, query } from 'express-validator'; -import { NotFoundError, responseException } from '../exceptions'; -import { auth, slackAuth } from '../middleware/auth'; -import { validate } from '../middleware/validators'; -import { TicketStatusType } from '../models/slack_ticket'; -import { SwitcherKeys } from '../external/switcher-api-facade'; -import { getDomainById } from '../services/domain'; -import * as Services from '../services/slack'; +import { NotFoundError, responseException } from '../exceptions/index.js'; +import { auth, slackAuth } from '../middleware/auth.js'; +import { validate } from '../middleware/validators.js'; +import { TicketStatusType } from '../models/slack_ticket.js'; +import { SwitcherKeys } from '../external/switcher-api-facade.js'; +import { getDomainById } from '../services/domain.js'; +import * as Services from '../services/slack.js'; const router = new express.Router(); diff --git a/src/routers/team.js b/src/routers/team.js index 5ba4e79..c6ae7cb 100644 --- a/src/routers/team.js +++ b/src/routers/team.js @@ -1,13 +1,13 @@ import express from 'express'; -import { auth } from '../middleware/auth'; +import { auth } from '../middleware/auth.js'; import { check, query } from 'express-validator'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { validate, verifyInputUpdateParameters } from '../middleware/validators'; -import { verifyOwnership } from '../helpers'; -import { responseException } from '../exceptions'; -import * as Services from '../services/team'; -import { getDomainById } from '../services/domain'; -import { SwitcherKeys } from '../external/switcher-api-facade'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { validate, verifyInputUpdateParameters } from '../middleware/validators.js'; +import { verifyOwnership } from '../helpers/index.js'; +import { responseException } from '../exceptions/index.js'; +import * as Services from '../services/team.js'; +import { getDomainById } from '../services/domain.js'; +import { SwitcherKeys } from '../external/switcher-api-facade.js'; const router = new express.Router(); diff --git a/src/services/admin.js b/src/services/admin.js index 48229bd..92f8225 100644 --- a/src/services/admin.js +++ b/src/services/admin.js @@ -1,13 +1,13 @@ -import { BadRequestError, NotFoundError } from '../exceptions'; -import { validate_token } from '../external/google-recaptcha'; -import { getBitBucketToken, getBitBucketUserInfo } from '../external/oauth-bitbucket'; -import { getGitToken, getGitUserInfo } from '../external/oauth-git'; -import { sendAccountRecoveryCode, sendAuthCode } from '../external/sendgrid'; -import { checkAdmin } from '../external/switcher-api-facade'; -import Admin from '../models/admin'; -import Domain from '../models/domain'; -import { response } from './common'; -import { getTeams } from './team'; +import { BadRequestError, NotFoundError } from '../exceptions/index.js'; +import { validate_token } from '../external/google-recaptcha.js'; +import { getBitBucketToken, getBitBucketUserInfo } from '../external/oauth-bitbucket.js'; +import { getGitToken, getGitUserInfo } from '../external/oauth-git.js'; +import { sendAccountRecoveryCode, sendAuthCode } from '../external/sendgrid.js'; +import { checkAdmin } from '../external/switcher-api-facade.js'; +import Admin from '../models/admin.js'; +import Domain from '../models/domain.js'; +import { response } from './common.js'; +import { getTeams } from './team.js'; export async function getAdminById(id) { let admin = await Admin.findById(id).exec(); diff --git a/src/services/common.js b/src/services/common.js index 8de20a0..b7c647f 100644 --- a/src/services/common.js +++ b/src/services/common.js @@ -1,4 +1,4 @@ -import { NotFoundError } from '../exceptions'; +import { NotFoundError } from '../exceptions/index.js'; export function response(element, onErrorMessage) { if (!element) throw new NotFoundError(onErrorMessage); diff --git a/src/services/component.js b/src/services/component.js index 85dd96d..85d762e 100644 --- a/src/services/component.js +++ b/src/services/component.js @@ -1,9 +1,9 @@ -import { checkComponent } from '../external/switcher-api-facade'; -import Component from '../models/component'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { formatInput, verifyOwnership } from '../helpers'; -import { permissionCache } from '../helpers/cache'; -import { response } from './common'; +import { checkComponent } from '../external/switcher-api-facade.js'; +import Component from '../models/component.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { formatInput, verifyOwnership } from '../helpers/index.js'; +import { permissionCache } from '../helpers/cache.js'; +import { response } from './common.js'; export async function getComponentById(id) { let component = await Component.findById(id).exec(); diff --git a/src/services/config-strategy.js b/src/services/config-strategy.js index 6fde681..52c046a 100644 --- a/src/services/config-strategy.js +++ b/src/services/config-strategy.js @@ -1,13 +1,13 @@ -import { response } from './common'; -import { ConfigStrategy } from '../models/config-strategy'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { verifyOwnership } from '../helpers'; -import { permissionCache } from '../helpers/cache'; -import { updateDomainVersion } from './domain'; -import { getConfigById } from './config'; -import { BadRequestError } from '../exceptions'; -import { checkEnvironmentStatusChange } from '../middleware/validators'; -import { getEnvironment } from './environment'; +import { response } from './common.js'; +import { ConfigStrategy } from '../models/config-strategy.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { verifyOwnership } from '../helpers/index.js'; +import { permissionCache } from '../helpers/cache.js'; +import { updateDomainVersion } from './domain.js'; +import { getConfigById } from './config.js'; +import { BadRequestError } from '../exceptions/index.js'; +import { checkEnvironmentStatusChange } from '../middleware/validators.js'; +import { getEnvironment } from './environment.js'; async function verifyStrategyValueInput(strategyId, value) { const configStrategy = await getStrategyById(strategyId); diff --git a/src/services/config.js b/src/services/config.js index f283624..1d80c21 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -1,15 +1,15 @@ -import { response } from './common'; -import { Config } from '../models/config'; -import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { getDomainById, updateDomainVersion } from './domain'; -import { getGroupConfigById } from './group-config'; -import { checkSwitcher } from '../external/switcher-api-facade'; -import { BadRequestError, NotFoundError } from '../exceptions'; -import { checkEnvironmentStatusChange } from '../middleware/validators'; -import { getComponentById, getComponents } from './component'; -import { resolveVerification } from '../client/relay'; -import { permissionCache } from '../helpers/cache'; +import { response } from './common.js'; +import { Config } from '../models/config.js'; +import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers/index.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { getDomainById, updateDomainVersion } from './domain.js'; +import { getGroupConfigById } from './group-config.js'; +import { checkSwitcher } from '../external/switcher-api-facade.js'; +import { BadRequestError, NotFoundError } from '../exceptions/index.js'; +import { checkEnvironmentStatusChange } from '../middleware/validators.js'; +import { getComponentById, getComponents } from './component.js'; +import { resolveVerification } from '../client/relay/index.js'; +import { permissionCache } from '../helpers/cache.js'; async function verifyAddComponentInput(configId, admin) { const config = await getConfigById(configId); diff --git a/src/services/domain.js b/src/services/domain.js index 32f0e2a..be94b11 100644 --- a/src/services/domain.js +++ b/src/services/domain.js @@ -1,16 +1,16 @@ import { randomUUID } from 'crypto'; -import { checkEnvironmentStatusChange } from '../middleware/validators'; -import Component from '../models/component'; -import { Config } from '../models/config'; -import { ConfigStrategy } from '../models/config-strategy'; -import Domain from '../models/domain'; -import { Environment } from '../models/environment'; -import GroupConfig from '../models/group-config'; -import History from '../models/history'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers'; -import { permissionCache } from '../helpers/cache'; -import { response } from './common'; +import { checkEnvironmentStatusChange } from '../middleware/validators.js'; +import Component from '../models/component.js'; +import { Config } from '../models/config.js'; +import { ConfigStrategy } from '../models/config-strategy.js'; +import Domain from '../models/domain.js'; +import { Environment } from '../models/environment.js'; +import GroupConfig from '../models/group-config.js'; +import History from '../models/history.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers/index.js'; +import { permissionCache } from '../helpers/cache.js'; +import { response } from './common.js'; export async function removeDomainStatus(domain, environmentName) { try { diff --git a/src/services/environment.js b/src/services/environment.js index dcf8bb3..3065578 100644 --- a/src/services/environment.js +++ b/src/services/environment.js @@ -1,14 +1,14 @@ -import { BadRequestError } from '../exceptions'; -import { checkEnvironment } from '../external/switcher-api-facade'; -import { ConfigStrategy } from '../models/config-strategy'; -import { Environment, EnvType } from '../models/environment'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { formatInput, verifyOwnership } from '../helpers'; -import { permissionCache } from '../helpers/cache'; -import { response } from './common'; -import { getConfigs, removeConfigStatus } from './config'; -import { getDomainById, removeDomainStatus } from './domain'; -import { getGroupConfigs, removeGroupStatus } from './group-config'; +import { BadRequestError } from '../exceptions/index.js'; +import { checkEnvironment } from '../external/switcher-api-facade.js'; +import { ConfigStrategy } from '../models/config-strategy.js'; +import { Environment, EnvType } from '../models/environment.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { formatInput, verifyOwnership } from '../helpers/index.js'; +import { permissionCache } from '../helpers/cache.js'; +import { response } from './common.js'; +import { getConfigs, removeConfigStatus } from './config.js'; +import { getDomainById, removeDomainStatus } from './domain.js'; +import { getGroupConfigs, removeGroupStatus } from './group-config.js'; async function removeEnvironmentFromElements(environment) { await ConfigStrategy.deleteMany({ domain: environment.domain, $or: [ diff --git a/src/services/group-config.js b/src/services/group-config.js index 59fcd23..e5b4558 100644 --- a/src/services/group-config.js +++ b/src/services/group-config.js @@ -1,12 +1,12 @@ -import { response } from './common'; -import GroupConfig from '../models/group-config'; -import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers'; -import { BadRequestError } from '../exceptions'; -import { checkGroup } from '../external/switcher-api-facade'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { getDomainById, updateDomainVersion } from './domain'; -import { checkEnvironmentStatusChange } from '../middleware/validators'; -import { permissionCache } from '../helpers/cache'; +import { response } from './common.js'; +import GroupConfig from '../models/group-config.js'; +import { formatInput, verifyOwnership, checkEnvironmentStatusRemoval } from '../helpers/index.js'; +import { BadRequestError } from '../exceptions/index.js'; +import { checkGroup } from '../external/switcher-api-facade.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { getDomainById, updateDomainVersion } from './domain.js'; +import { checkEnvironmentStatusChange } from '../middleware/validators.js'; +import { permissionCache } from '../helpers/cache.js'; export async function getGroupConfigById(id, lean = false, populateAdmin = false) { let group = await GroupConfig.findById(id, null, { lean }).exec(); diff --git a/src/services/history.js b/src/services/history.js index 80b9e82..fd305e4 100644 --- a/src/services/history.js +++ b/src/services/history.js @@ -1,6 +1,6 @@ -import History from '../models/history'; -import { sortBy, validatePagingArgs } from '../helpers'; -import { BadRequestError } from '../exceptions'; +import History from '../models/history.js'; +import { sortBy, validatePagingArgs } from '../helpers/index.js'; +import { BadRequestError } from '../exceptions/index.js'; export async function getHistory(query, domainId, elementId, pagingArgs = {}) { if (!validatePagingArgs(pagingArgs)) diff --git a/src/services/metric.js b/src/services/metric.js index a4b7242..fae12d3 100644 --- a/src/services/metric.js +++ b/src/services/metric.js @@ -1,10 +1,10 @@ import moment from 'moment'; -import { NotFoundError } from '../exceptions'; -import { verifyOwnership } from '../helpers'; -import { EnvType } from '../models/environment'; -import { Metric } from '../models/metric'; -import { ActionTypes, RouterTypes } from '../models/permission'; -import { getConfig } from './config'; +import { NotFoundError } from '../exceptions/index.js'; +import { verifyOwnership } from '../helpers/index.js'; +import { EnvType } from '../models/environment.js'; +import { Metric } from '../models/metric.js'; +import { ActionTypes, RouterTypes } from '../models/permission.js'; +import { getConfig } from './config.js'; export async function getData(req, page) { const { args } = buildMetricsFilter(req); diff --git a/src/services/permission.js b/src/services/permission.js index bcdf1c1..1fcb211 100644 --- a/src/services/permission.js +++ b/src/services/permission.js @@ -1,9 +1,9 @@ -import { BadRequestError, NotFoundError } from '../exceptions'; -import { ActionTypes, Permission, RouterTypes } from '../models/permission'; -import { verifyOwnership } from '../helpers'; -import { response } from './common'; -import { getTeam, getTeams, verifyRequestedTeam } from './team'; -import { permissionCache } from '../helpers/cache'; +import { BadRequestError, NotFoundError } from '../exceptions/index.js'; +import { ActionTypes, Permission, RouterTypes } from '../models/permission.js'; +import { verifyOwnership } from '../helpers/index.js'; +import { response } from './common.js'; +import { getTeam, getTeams, verifyRequestedTeam } from './team.js'; +import { permissionCache } from '../helpers/cache.js'; async function verifyRequestedTeamByPermission(permissionId, admin, action) { let team = await getTeam({ permissions: permissionId }); diff --git a/src/services/slack.js b/src/services/slack.js index 4256447..d8e2a35 100644 --- a/src/services/slack.js +++ b/src/services/slack.js @@ -1,12 +1,12 @@ -import Slack from '../models/slack'; -import { TicketStatusType, SLACK_SUB, TicketValidationType } from '../models/slack_ticket'; -import { BadRequestError, NotFoundError, PermissionError } from '../exceptions'; -import { checkSlackIntegration } from '../external/switcher-api-facade'; -import { getConfig } from './config'; -import { getDomainById, updateDomainVersion } from './domain'; -import { getEnvironment } from './environment'; -import { getGroupConfig } from './group-config'; -import { containsValue } from '../helpers'; +import Slack from '../models/slack.js'; +import { TicketStatusType, SLACK_SUB, TicketValidationType } from '../models/slack_ticket.js'; +import { BadRequestError, NotFoundError, PermissionError } from '../exceptions/index.js'; +import { checkSlackIntegration } from '../external/switcher-api-facade.js'; +import { getConfig } from './config.js'; +import { getDomainById, updateDomainVersion } from './domain.js'; +import { getEnvironment } from './environment.js'; +import { getGroupConfig } from './group-config.js'; +import { containsValue } from '../helpers/index.js'; /** * Validates if ticket already exists, if so, return it. diff --git a/src/services/team.js b/src/services/team.js index 379611a..d75c4e5 100644 --- a/src/services/team.js +++ b/src/services/team.js @@ -1,11 +1,11 @@ -import { BadRequestError, NotFoundError } from '../exceptions'; -import { checkTeam } from '../external/switcher-api-facade'; -import Admin from '../models/admin'; -import { ActionTypes, checkActionType, Permission, RouterTypes } from '../models/permission'; -import { addDefaultPermission, Team } from '../models/team'; -import TeamInvite from '../models/team-invite'; -import { verifyOwnership } from '../helpers'; -import { response } from './common'; +import { BadRequestError, NotFoundError } from '../exceptions/index.js'; +import { checkTeam } from '../external/switcher-api-facade.js'; +import Admin from '../models/admin.js'; +import { ActionTypes, checkActionType, Permission, RouterTypes } from '../models/permission.js'; +import { addDefaultPermission, Team } from '../models/team.js'; +import TeamInvite from '../models/team-invite.js'; +import { verifyOwnership } from '../helpers/index.js'; +import { response } from './common.js'; async function addMemberToTeam(admin, team) { if (!admin) { 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/common-index.test.js b/tests/model/common-index.test.js index 4b2ef72..19aea6b 100644 --- a/tests/model/common-index.test.js +++ b/tests/model/common-index.test.js @@ -1,4 +1,4 @@ -require('../../src/db/mongoose'); +import '../../src/db/mongoose'; import mongoose from 'mongoose'; import { recordHistory } from '../../src/models/common/index'; diff --git a/tests/model/component.test.js b/tests/model/component.test.js index 3b07309..fff535f 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/services/history.test.js b/tests/services/history.test.js index 6e32922..39de948 100644 --- a/tests/services/history.test.js +++ b/tests/services/history.test.js @@ -1,4 +1,4 @@ -require('../../src/db/mongoose'); +import '../../src/db/mongoose'; import mongoose from 'mongoose'; import { getHistory, deleteHistory } from '../../src/services/history'; 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(() => {