From 259fde09dbe8d1055dacdd32a45abaac8c577e73 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Wed, 13 Mar 2024 09:41:48 +0200 Subject: [PATCH] feat: add possibility to see differences for frontend API (#6528) --- package.json | 34 +++++++-- .../frontend-api/frontend-api-controller.ts | 23 +++++-- yarn.lock | 69 +++++++++++-------- 3 files changed, 85 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index b7b348b3644..0ad0137e5b6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,12 @@ "name": "unleash-server", "description": "Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.", "version": "5.10.0+main", - "keywords": ["unleash", "feature toggle", "feature", "toggle"], + "keywords": [ + "unleash", + "feature toggle", + "feature", + "toggle" + ], "files": [ "dist", "docs", @@ -75,11 +80,23 @@ "testTimeout": 10000, "globalSetup": "./scripts/jest-setup.js", "transform": { - "^.+\\.tsx?$": ["@swc/jest"] + "^.+\\.tsx?$": [ + "@swc/jest" + ] }, "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", - "testPathIgnorePatterns": ["/dist/", "/node_modules/", "/frontend/"], - "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json"], + "testPathIgnorePatterns": [ + "/dist/", + "/node_modules/", + "/frontend/" + ], + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json" + ], "coveragePathIgnorePatterns": [ "/node_modules/", "/dist/", @@ -117,6 +134,7 @@ "joi": "^17.3.0", "js-sha256": "^0.11.0", "js-yaml": "^4.1.0", + "json-diff": "^1.0.6", "json-schema-to-ts": "2.12.0", "json2csv": "^5.0.7", "knex": "^2.5.1", @@ -216,7 +234,11 @@ "tough-cookie": "4.1.3" }, "lint-staged": { - "*.{js,ts}": ["biome check --apply"], - "*.json": ["biome format --write --no-errors-on-unmatched"] + "*.{js,ts}": [ + "biome check --apply" + ], + "*.json": [ + "biome format --write --no-errors-on-unmatched" + ] } } diff --git a/src/lib/features/frontend-api/frontend-api-controller.ts b/src/lib/features/frontend-api/frontend-api-controller.ts index 64850508562..d30ab0fd690 100644 --- a/src/lib/features/frontend-api/frontend-api-controller.ts +++ b/src/lib/features/frontend-api/frontend-api-controller.ts @@ -22,6 +22,7 @@ import NotFoundError from '../../error/notfound-error'; import rateLimit from 'express-rate-limit'; import { minutesToMilliseconds } from 'date-fns'; import isEqual from 'lodash.isequal'; +import { diff } from 'json-diff'; interface ApiUserRequest< PARAM = any, @@ -188,14 +189,22 @@ export default class FrontendAPIController extends Controller { FrontendAPIController.createContext(req), ), ]); - if ( - !isEqual( - toggles.sort((a, b) => a.name.localeCompare(b.name)), - newToggles.sort((a, b) => a.name.localeCompare(b.name)), - ) - ) { + const sortedToggles = toggles.sort((a, b) => + a.name.localeCompare(b.name), + ); + const sortedNewToggles = newToggles.sort((a, b) => + a.name.localeCompare(b.name), + ); + if (!isEqual(sortedToggles, sortedNewToggles)) { this.logger.warn( - `old features and new features are different. Old count ${toggles.length}, new count ${newToggles.length}, projects ${req.user.projects}, environment ${req.user.environment}`, + `old features and new features are different. Old count ${ + toggles.length + }, new count ${newToggles.length}, projects ${ + req.user.projects + }, environment ${req.user.environment}, diff ${diff( + sortedToggles, + sortedNewToggles, + )}`, ); } } else { diff --git a/yarn.lock b/yarn.lock index 596cd0d66d4..cb222337a20 100644 --- a/yarn.lock +++ b/yarn.lock @@ -700,6 +700,13 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" +"@ewoudenberg/difflib@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@ewoudenberg/difflib/-/difflib-0.1.0.tgz#a2ae5d3321ffa7c1b47691cf0db189d1264aaaa4" + integrity sha512-OU5P5mJyD3OoWYMWY+yIgwvgNS9cFAU10f+DDuvtogcWQOoJIsQ4Hy2McSfUfhKjq8L0FuWVb4Rt7kgA+XK86A== + dependencies: + heap ">= 0.2.0" + "@exodus/schemasafe@^1.0.0-rc.2": version "1.3.0" resolved "https://registry.yarnpkg.com/@exodus/schemasafe/-/schemasafe-1.3.0.tgz#731656abe21e8e769a7f70a4d833e6312fe59b7f" @@ -2325,6 +2332,11 @@ colors@1.0.x: resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" integrity sha512-pFGrxThWcWQ2MsAz6RtgeWe4NK2kUE1WfsrvvlctdII745EW9I0yflqhe7++M5LEc7bV2c/9/5zc8sFcpL0Drw== +colors@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78" + integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== + combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6: version "1.0.8" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" @@ -2800,6 +2812,13 @@ drange@^1.0.2: resolved "https://registry.yarnpkg.com/drange/-/drange-1.1.1.tgz#b2aecec2aab82fcef11dbbd7b9e32b83f8f6c0b8" integrity sha512-pYxfDYpued//QpnLIm4Avk7rsNtAtQkUES2cwAYSvD/wd2pKD71gN2Ebj3e7klzXwjocvE8c5vx/1fxwpqmSxA== +dreamopt@~0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/dreamopt/-/dreamopt-0.8.0.tgz#5bcc80be7097e45fc489c342405ab68140a8c1d9" + integrity sha512-vyJTp8+mC+G+5dfgsY+r3ckxlz+QMX40VjPQsZc5gxVAxLmi64TBoVkP54A/pRAXMXsbu2GMMBrZPxNv23waMg== + dependencies: + wordwrap ">=0.0.2" + duplexer@~0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.2.tgz#3abe43aef3835f8ae077d136ddce0f276b0400e6" @@ -3602,6 +3621,11 @@ hasown@^2.0.0: dependencies: function-bind "^1.1.2" +"heap@>= 0.2.0": + version "0.2.7" + resolved "https://registry.yarnpkg.com/heap/-/heap-0.2.7.tgz#1e6adf711d3f27ce35a81fe3b7bd576c2260a8fc" + integrity sha512-2bsegYkkHO+h/9MGbn6KWcE45cHZgPANo5LXF7EvWdT0yT2EguSVO1nDgU5c8+ZOPwp2vMNa7YFsJhVcDR9Sdg== + helmet@^6.0.0: version "6.2.0" resolved "https://registry.yarnpkg.com/helmet/-/helmet-6.2.0.tgz#c29d62014be4c70b8ef092c9c5e54c8c26b8e16e" @@ -4471,6 +4495,15 @@ jsesc@^2.5.1: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-2.5.2.tgz#80564d2e483dacf6e8ef209650a67df3f0c283a4" integrity sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== +json-diff@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/json-diff/-/json-diff-1.0.6.tgz#63690f695469b6437efaed5bb3d51f011f7cac28" + integrity sha512-tcFIPRdlc35YkYdGxcamJjllUhXWv4n2rK9oJ2RsAzV4FBkuV4ojKEDgcZ+kpKxDmJKv+PFK65+1tVVOnSeEqA== + dependencies: + "@ewoudenberg/difflib" "0.1.0" + colors "^1.4.0" + dreamopt "~0.8.0" + json-parse-even-better-errors@^2.3.0: version "2.3.1" resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d" @@ -6674,16 +6707,7 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -6713,14 +6737,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -7315,7 +7332,12 @@ winston@2.x: isstream "0.1.x" stack-trace "0.0.x" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +wordwrap@>=0.0.2: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== + +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -7333,15 +7355,6 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"