diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 323376e..ab458b4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -9,7 +9,7 @@ "version": "1.0.1", "license": "MIT", "dependencies": { - "axios": "^1.9.0", + "axios": "^1.10.0", "bcryptjs": "^3.0.2", "cors": "^2.8.5", "express": "^5.1.0", @@ -23,7 +23,7 @@ "jsonwebtoken": "^9.0.2", "moment": "^2.30.1", "mongodb": "^6.17.0", - "mongoose": "^8.15.1", + "mongoose": "^8.15.2", "pino": "^9.7.0", "pino-pretty": "^13.0.0", "swagger-ui-express": "^5.0.1", @@ -32,12 +32,12 @@ }, "devDependencies": { "env-cmd": "^10.1.0", - "eslint": "^9.28.0", + "eslint": "^9.29.0", "jest": "^30.0.0", "jest-sonar-reporter": "^2.0.0", "node-notifier": "^10.0.1", "nodemon": "^3.1.10", - "sinon": "^20.0.0", + "sinon": "^21.0.0", "supertest": "^7.1.1" } }, @@ -690,9 +690,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.28.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.28.0.tgz", - "integrity": "sha512-fnqSjGWd/CoIp4EXIxWVK/sHA6DOHN4+8Ix2cX5ycOY7LG0UY8nHCU5pIp2eaE1Mc7Qd8kHspYNzYXT2ojPLzg==", + "version": "9.29.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.29.0.tgz", + "integrity": "sha512-3PIF4cBw/y+1u2EazflInpV+lYsSG0aByVIQzAgb1m1MhHFSbqTyNqtBKHgWf/9Ykud+DhILS9EGkmekVhbKoQ==", "dev": true, "license": "MIT", "engines": { @@ -1336,9 +1336,9 @@ } }, "node_modules/@mongodb-js/saslprep": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.2.2.tgz", - "integrity": "sha512-EB0O3SCSNRUFk66iRCpI+cXzIjdswfCs7F6nOC3RAGJ7xr5YhaicvsRwJ9eyzYvYRlCSDUO/c7g4yNulxKC1WA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.3.0.tgz", + "integrity": "sha512-zlayKCsIjYb7/IdfqxorK5+xUMyi4vOKcFy10wKJYc63NSdKI8mNME+uJqfatkPmOSMMUiojrL58IePKBm3gvQ==", "license": "MIT", "dependencies": { "sparse-bitfield": "^3.0.3" @@ -1412,9 +1412,9 @@ "license": "Apache-2.0" }, "node_modules/@sinclair/typebox": { - "version": "0.34.33", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.33.tgz", - "integrity": "sha512-5HAV9exOMcXRUxo+9iYB5n09XxzCXnfy4VTNW4xnDv+FgjzAGY989C28BIdljKqmF+ZltUwujE3aossvcVtq6g==", + "version": "0.34.35", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.34.35.tgz", + "integrity": "sha512-C6ypdODf2VZkgRT6sFM8E1F8vR+HcffniX0Kp8MsU8PIfrlXbNCBz0jzj17GjdmjTx1OtZzdH8+iALL21UjF5A==", "dev": true, "license": "MIT" }, @@ -2024,9 +2024,9 @@ } }, "node_modules/axios": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.9.0.tgz", - "integrity": "sha512-re4CqKTJaURpzbLHtIi6XpDv20/CnpXOtjRY5/CU32L8gU8ek9UIivcfvSWvmKEngmVbrUtPpdDwWDWL7DNHvg==", + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.10.0.tgz", + "integrity": "sha512-/1xYAC4MP/HEG+3duIhFr4ZQXR4sQXOIe+o6sdqzeykGLx6Upp/1p8MHqhINOvGeP7xyNHe7tsiJByc4SSVUxw==", "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", @@ -2347,9 +2347,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001722", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001722.tgz", - "integrity": "sha512-DCQHBBZtiK6JVkAGw7drvAMK0Q0POD/xZvEmDp6baiMMP6QXXk9HpD6mNYBZWhOPG6LvIDb82ITqtWjhDckHCA==", + "version": "1.0.30001723", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001723.tgz", + "integrity": "sha512-1R/elMjtehrFejxwmexeXAtae5UO9iSyFn6G/I806CYC/BLyyBk1EPhrKBkWhy6wM6Xnm47dSJQec+tLJ39WHw==", "dev": true, "funding": [ { @@ -2841,9 +2841,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.166", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.166.tgz", - "integrity": "sha512-QPWqHL0BglzPYyJJ1zSSmwFFL6MFXhbACOCcsCdUMCkzPdS9/OIBVxg516X/Ado2qwAq8k0nJJ7phQPCqiaFAw==", + "version": "1.5.167", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.167.tgz", + "integrity": "sha512-LxcRvnYO5ez2bMOFpbuuVuAI5QNeY1ncVytE/KXaL6ZNfzX1yPlAO0nSOyIHx2fVAuUprMqPs/TdVhUFZy7SIQ==", "dev": true, "license": "ISC" }, @@ -2987,19 +2987,19 @@ } }, "node_modules/eslint": { - "version": "9.28.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.28.0.tgz", - "integrity": "sha512-ocgh41VhRlf9+fVpe7QKzwLj9c92fDiqOj8Y3Sd4/ZmVA4Btx4PlUYPq4pp9JDyupkf1upbEXecxL2mwNV7jPQ==", + "version": "9.29.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.29.0.tgz", + "integrity": "sha512-GsGizj2Y1rCWDu6XoEekL3RLilp0voSePurjZIkxL3wlm5o5EC9VpgaP7lrCvjnkuLvzFBQWB3vWB3K5KQTveQ==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.12.1", - "@eslint/config-array": "^0.20.0", + "@eslint/config-array": "^0.20.1", "@eslint/config-helpers": "^0.2.1", "@eslint/core": "^0.14.0", "@eslint/eslintrc": "^3.3.1", - "@eslint/js": "9.28.0", + "@eslint/js": "9.29.0", "@eslint/plugin-kit": "^0.3.1", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", @@ -3011,9 +3011,9 @@ "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.3.0", - "eslint-visitor-keys": "^4.2.0", - "espree": "^10.3.0", + "eslint-scope": "^8.4.0", + "eslint-visitor-keys": "^4.2.1", + "espree": "^10.4.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -5384,9 +5384,9 @@ } }, "node_modules/mongoose": { - "version": "8.15.1", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.15.1.tgz", - "integrity": "sha512-RhQ4DzmBi5BNGcS0w4u1vdMRIKcteXTCNzDt1j7XRcdWYBz1MjMjulBhPaeC5jBCHOD1yinuOFTTSOWLLGexWw==", + "version": "8.15.2", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.15.2.tgz", + "integrity": "sha512-GLwghI2dS/n5BTBljspF4+FsCEBeHgnMQyX8GloYkLkl+MKljKkjcP9DhLr47Yod2RO1RCr4vZ3evUZAyuoILw==", "license": "MIT", "dependencies": { "bson": "^6.10.3", @@ -6529,9 +6529,9 @@ } }, "node_modules/sinon": { - "version": "20.0.0", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-20.0.0.tgz", - "integrity": "sha512-+FXOAbdnj94AQIxH0w1v8gzNxkawVvNqE3jUzRLptR71Oykeu2RrQXXl/VQjKay+Qnh73fDt/oDfMo6xMeDQbQ==", + "version": "21.0.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-21.0.0.tgz", + "integrity": "sha512-TOgRcwFPbfGtpqvZw+hyqJDvqfapr1qUlOizROIk4bBLjlsjlB00Pg6wMFXNtJRpu+eCZuVOaLatG7M8105kAw==", "dev": true, "license": "BSD-3-Clause", "dependencies": { diff --git a/package.json b/package.json index f7a2622..a1d5991 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ ], "license": "MIT", "dependencies": { - "axios": "^1.9.0", + "axios": "^1.10.0", "bcryptjs": "^3.0.2", "cors": "^2.8.5", "express": "^5.1.0", @@ -50,7 +50,7 @@ "jsonwebtoken": "^9.0.2", "moment": "^2.30.1", "mongodb": "^6.17.0", - "mongoose": "^8.15.1", + "mongoose": "^8.15.2", "pino": "^9.7.0", "pino-pretty": "^13.0.0", "swagger-ui-express": "^5.0.1", @@ -59,12 +59,12 @@ }, "devDependencies": { "env-cmd": "^10.1.0", - "eslint": "^9.28.0", + "eslint": "^9.29.0", "jest": "^30.0.0", "jest-sonar-reporter": "^2.0.0", "node-notifier": "^10.0.1", "nodemon": "^3.1.10", - "sinon": "^20.0.0", + "sinon": "^21.0.0", "supertest": "^7.1.1" }, "repository": { diff --git a/requests/Switcher Resolver Node.postman_collection.json b/requests/Switcher Resolver Node.postman_collection.json index b959209..3c2fd80 100644 --- a/requests/Switcher Resolver Node.postman_collection.json +++ b/requests/Switcher Resolver Node.postman_collection.json @@ -411,7 +411,7 @@ "body": { "mode": "graphql", "graphql": { - "query": "query Domain(\r\n $name: String, \r\n $environment: String, \r\n $_component: String) {\r\n domain(\r\n name: $name, \r\n environment: $environment,\r\n _component: $_component\r\n ) {\r\n name\r\n version\r\n description\r\n activated\r\n group {\r\n name\r\n description\r\n activated\r\n config {\r\n key\r\n description\r\n activated\r\n strategies {\r\n strategy\r\n activated\r\n operation\r\n values\r\n }\r\n relay {\r\n type\r\n method\r\n authPrefix\r\n verifiedByEnv { env value }\r\n authTokenByEnv { env value }\r\n statusByEnv { env value }\r\n endpointByEnv { env value }\r\n }\r\n components\r\n }\r\n }\r\n }\r\n}", + "query": "query Domain(\r\n $name: String, \r\n $environment: String, \r\n $_component: String) {\r\n domain(\r\n name: $name, \r\n environment: $environment,\r\n _component: $_component\r\n ) {\r\n name\r\n version\r\n description\r\n activated\r\n group {\r\n name\r\n description\r\n activated\r\n config {\r\n key\r\n description\r\n activated\r\n strategies {\r\n strategy\r\n activated\r\n operation\r\n values\r\n }\r\n relay {\r\n type\r\n method\r\n activated\r\n authPrefix\r\n verifiedByEnv { env value }\r\n authTokenByEnv { env value }\r\n statusByEnv { env value }\r\n endpointByEnv { env value }\r\n }\r\n components\r\n }\r\n }\r\n }\r\n}", "variables": "{\r\n \"name\": \"{{domain_name}}\",\r\n \"environment\": \"{{env_name}}\",\r\n \"_component\": \"{{component_name}}\"\r\n}" } }, diff --git a/src/client/configuration-type.js b/src/client/configuration-type.js index 2c28c1d..40faaa3 100644 --- a/src/client/configuration-type.js +++ b/src/client/configuration-type.js @@ -76,28 +76,34 @@ export const relayType = new GraphQLObjectType({ method: { type: GraphQLString, }, + activated: { + type: GraphQLBoolean, + resolve: (source, _args, { environment }) => { + return source.activated[`${environment}`]; + } + }, verifiedByEnv: { type: new GraphQLList(envValue), - resolve: (source, _args, context) => { - return resolveEnvValue(source, 'verified', Object.keys(source.verified), context.environment); + resolve: (source) => { + return resolveEnvValue(source, 'verified', Object.keys(source.verified)); } }, endpointByEnv: { type: new GraphQLList(envValue), - resolve: (source, _args, context) => { - return resolveEnvValue(source, 'endpoint', Object.keys(source.endpoint), context.environment); + resolve: (source) => { + return resolveEnvValue(source, 'endpoint', Object.keys(source.endpoint)); } }, statusByEnv: { type: new GraphQLList(envStatus), - resolve: (source, _args, context) => { - return resolveEnvValue(source, 'activated', Object.keys(source.activated), context.environment); + resolve: (source) => { + return resolveEnvValue(source, 'activated', Object.keys(source.activated)); } }, authTokenByEnv: { type: new GraphQLList(envValue), - resolve: (source, _args, context) => { - return resolveEnvValue(source, 'auth_token', Object.keys(source.auth_token), context.environment); + resolve: (source) => { + return resolveEnvValue(source, 'auth_token', Object.keys(source.auth_token)); } }, authPrefix: { diff --git a/src/client/resolvers.js b/src/client/resolvers.js index e7d5cb5..9481de4 100644 --- a/src/client/resolvers.js +++ b/src/client/resolvers.js @@ -11,7 +11,7 @@ import { isRelayVerified, isRelayValid } from '../services/config.js'; export const resolveConfigByKey = async (domain, key) => Config.findOne({ domain, key }, null, { lean: true }); -export function resolveEnvValue(source, field, keys, environment) { +export function resolveEnvValue(source, field, keys) { const arrValue = []; keys.forEach(k => { @@ -21,10 +21,6 @@ export function resolveEnvValue(source, field, keys, environment) { }); }); - if (environment) { - return arrValue.filter(e => e.env === environment); - } - return arrValue; } diff --git a/src/helpers/cache/query.js b/src/helpers/cache/query.js index 63df735..bbc2e47 100644 --- a/src/helpers/cache/query.js +++ b/src/helpers/cache/query.js @@ -2,51 +2,27 @@ export const domainQuery = (id) => ` query { domain(_id: "${id}") { version - statusByEnv { - env - value - } + statusByEnv { env value } group { - statusByEnv { - env - value - } + statusByEnv { env value } config { key components - statusByEnv { - env - value - } + statusByEnv { env value } strategies { strategy operation values - statusByEnv { - env - value - } + statusByEnv { env value } } relay { type method authPrefix - authTokenByEnv { - env - value - } - endpointByEnv { - env - value - } - statusByEnv { - env - value - } - verifiedByEnv { - env - value - } + authTokenByEnv { env value } + endpointByEnv { env value } + statusByEnv { env value } + verifiedByEnv { env value } } } } diff --git a/tests/graphql-utils/index.js b/tests/graphql-utils/index.js index afc0be9..41c9947 100644 --- a/tests/graphql-utils/index.js +++ b/tests/graphql-utils/index.js @@ -22,18 +22,10 @@ export const domainQuery = (where, group, config, strategy) => { relay { type method - endpointByEnv { - env - value - } - statusByEnv { - env - value - } - statusByEnv { - env - value - } + activated + endpointByEnv { env value } + statusByEnv { env value } + statusByEnv { env value } } components } @@ -175,6 +167,7 @@ export const expected102 = ` "relay": { "type": "NOTIFICATION", "method": "POST", + "activated": false, "endpointByEnv": [{ "env": "default", "value": "http://localhost:3000"