diff --git a/angular.json b/angular.json index 310a3fb..b7b164a 100644 --- a/angular.json +++ b/angular.json @@ -28,6 +28,11 @@ "glob": "**/*", "input": "public" }, + { + "glob": "mockServiceWorker.js", + "input": "src/mocks", + "output": "./" + }, "src/assets" ], "styles": ["src/styles.scss"], @@ -87,6 +92,11 @@ { "glob": "**/*", "input": "public" + }, + { + "glob": "mockServiceWorker.js", + "input": "src/mocks", + "output": "./" } ], "styles": ["src/styles.scss"], diff --git a/eslint.config.js b/eslint.config.js index e232f51..71776df 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -185,6 +185,12 @@ export default [ from: ['features', 'service', 'models'], allow: [['model', { context: 'auth' }]], }, + // Mock module may only import models + { + from: ['mock'], + disallow: [['*', { context: '!model' }]], + message: 'Mock modules can only import models', + }, ], }, ], @@ -254,6 +260,11 @@ export default [ mode: 'folder', capture: ['context'], }, + { + type: 'mock', + mode: 'folder', + pattern: 'src/mocks', + }, ], }, }, diff --git a/package.json b/package.json index afd319e..e013883 100644 --- a/package.json +++ b/package.json @@ -62,11 +62,17 @@ "karma-coverage": "~2.2.1", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.1.0", + "msw": "^2.6.6", "postcss": "^8.4.49", "prettier": "3.3.3", "prettier-plugin-tailwindcss": "^0.6.9", "tailwindcss": "^3.4.16", "typescript": "~5.6.3", "typescript-eslint": "^8.17.0" + }, + "msw": { + "workerDirectory": [ + "src/mocks" + ] } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ddd133b..abe9ba4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -129,6 +129,9 @@ importers: karma-jasmine-html-reporter: specifier: ~2.1.0 version: 2.1.0(jasmine-core@5.4.0)(karma-jasmine@5.1.0(karma@6.4.4))(karma@6.4.4) + msw: + specifier: ^2.6.6 + version: 2.6.6(@types/node@22.10.1)(typescript@5.6.3) postcss: specifier: ^8.4.49 version: 8.4.49 @@ -414,8 +417,8 @@ packages: resolution: {integrity: sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==} engines: {node: '>=6.9.0'} - '@babel/compat-data@7.26.2': - resolution: {integrity: sha512-Z0WgzSEa+aUcdiJuCIqgujCshpMWgUpgOxXotrYPSA53hA3qopNaqcJpyr0hVb1FeWdnqFA35/fUtXgBK8srQg==} + '@babel/compat-data@7.26.3': + resolution: {integrity: sha512-nHIxvKPniQXpmQLb0vhY3VaFb3S0YrTAwpOWJZh1wn3oJPjJk9Asva204PsBdmAE8vpzfHudT8DB0scYvy9q0g==} engines: {node: '>=6.9.0'} '@babel/core@7.25.8': @@ -430,12 +433,12 @@ packages: resolution: {integrity: sha512-zevQbhbau95nkoxSq3f/DC/SC+EEOUZd3DYqfSkMhY2/wfSeaHV1Ew4vk8e+x8lja31IbyuUa2uQ3JONqKbysw==} engines: {node: '>=6.9.0'} - '@babel/helper-annotate-as-pure@7.25.9': - resolution: {integrity: sha512-gv7320KBUFJz1RnylIg5WWYPRXKZ884AGkYpgpWW02TH66Dl+HaC1t1CKd0z3R4b6hdYEcmrNZHUmfCP+1u3/g==} + '@babel/generator@7.26.3': + resolution: {integrity: sha512-6FF/urZvD0sTeO7k6/B15pMLC4CHUv1426lzr3N01aHJTl046uCAh9LXW/fzeXXjPNCJ6iABW5XaWOsIZB93aQ==} engines: {node: '>=6.9.0'} - '@babel/helper-builder-binary-assignment-operator-visitor@7.25.9': - resolution: {integrity: sha512-C47lC7LIDCnz0h4vai/tpNOI95tCd5ZT3iBt/DBH5lXKHZsyNQv18yf1wIIg2ntiQNgmAvA+DgZ82iW8Qdym8g==} + '@babel/helper-annotate-as-pure@7.25.9': + resolution: {integrity: sha512-gv7320KBUFJz1RnylIg5WWYPRXKZ884AGkYpgpWW02TH66Dl+HaC1t1CKd0z3R4b6hdYEcmrNZHUmfCP+1u3/g==} engines: {node: '>=6.9.0'} '@babel/helper-compilation-targets@7.25.9': @@ -448,8 +451,8 @@ packages: peerDependencies: '@babel/core': ^7.0.0 - '@babel/helper-create-regexp-features-plugin@7.25.9': - resolution: {integrity: sha512-ORPNZ3h6ZRkOyAa/SaHU+XsLZr0UQzRwuDQ0cczIA17nAzZ+85G5cVkOJIj7QavLZGSe8QXUmNFxSZzjcZF9bw==} + '@babel/helper-create-regexp-features-plugin@7.26.3': + resolution: {integrity: sha512-G7ZRb40uUgdKOQqPLjfD12ZmGA54PzqDFUv2BKImnC9QIfGhIHKvVML0oN8IUiDq4iRqpq74ABpvOaerfWdong==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0 @@ -493,10 +496,6 @@ packages: peerDependencies: '@babel/core': ^7.0.0 - '@babel/helper-simple-access@7.25.9': - resolution: {integrity: sha512-c6WHXuiaRsJTyHYLJV75t9IqsmTbItYfdj99PnzYGQZkYKvan5/2jKJ7gu31J3/BJ/A18grImSPModuyG/Eo0Q==} - engines: {node: '>=6.9.0'} - '@babel/helper-skip-transparent-expression-wrappers@7.25.9': resolution: {integrity: sha512-K4Du3BFa3gvyhzgPcntrkDgZzQaq6uozzcpGbOO1OEJaI+EJdqWIMTLgFgQf6lrfiDFo5FU+BxKepI9RmZqahA==} engines: {node: '>=6.9.0'} @@ -525,8 +524,8 @@ packages: resolution: {integrity: sha512-tbhNuIxNcVb21pInl3ZSjksLCvgdZy9KwJ8brv993QtIVKJBBkYXz4q4ZbAv31GdnC+R90np23L5FbEBlthAEw==} engines: {node: '>=6.9.0'} - '@babel/parser@7.26.2': - resolution: {integrity: sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==} + '@babel/parser@7.26.3': + resolution: {integrity: sha512-WJ/CvmY8Mea8iDXo6a7RK2wbmJITT5fN3BEkRuFlxVyNx8jOKIIhmC4fSkTcPcf8JyavbBwIe6OpiCOBXt/IcA==} engines: {node: '>=6.0.0'} hasBin: true @@ -668,8 +667,8 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 - '@babel/plugin-transform-exponentiation-operator@7.25.9': - resolution: {integrity: sha512-KRhdhlVk2nObA5AYa7QMgTMTVJdfHprfpAk4DjZVtllqRg9qarilstTKEhpVjyt+Npi8ThRyiV8176Am3CodPA==} + '@babel/plugin-transform-exponentiation-operator@7.26.3': + resolution: {integrity: sha512-7CAHcQ58z2chuXPWblnn1K6rLDnDWieghSOEmqQsrBenH0P9InCUtOJYD89pvngljmZlJcz3fcmgYsXFNGa1ZQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 @@ -722,8 +721,8 @@ packages: peerDependencies: '@babel/core': ^7.0.0-0 - '@babel/plugin-transform-modules-commonjs@7.25.9': - resolution: {integrity: sha512-dwh2Ol1jWwL2MgkCzUSOvfmKElqQcuswAZypBSUsScMXvgdT8Ekq5YA6TtqpTVWH+4903NmboMuH1o9i8Rxlyg==} + '@babel/plugin-transform-modules-commonjs@7.26.3': + resolution: {integrity: sha512-MgR55l4q9KddUDITEzEFYn5ZsGDXMSsU9E+kh7fjRXTIC3RHqfCo8RPRbyReYJh44HQ/yomFkqbOFohXvDCiIQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 @@ -921,14 +920,23 @@ packages: resolution: {integrity: sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==} engines: {node: '>=6.9.0'} - '@babel/traverse@7.25.9': - resolution: {integrity: sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==} + '@babel/traverse@7.26.3': + resolution: {integrity: sha512-yTmc8J+Sj8yLzwr4PD5Xb/WF3bOYu2C2OoSZPzbuqRm4n98XirsbzaX+GloeO376UnSYIYJ4NCanwV5/ugZkwA==} engines: {node: '>=6.9.0'} - '@babel/types@7.26.0': - resolution: {integrity: sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA==} + '@babel/types@7.26.3': + resolution: {integrity: sha512-vN5p+1kl59GVKMvTHt55NzzmYVxprfJD+ql7U9NFIfKCBkYE55LYtS+WtPlaYOyzydrKI8Nezd+aZextrd+FMA==} engines: {node: '>=6.9.0'} + '@bundled-es-modules/cookie@2.0.1': + resolution: {integrity: sha512-8o+5fRPLNbjbdGRRmJj3h6Hh1AQJf2dk3qQ/5ZFb+PXkRNiSoMGGUKlsgLfrxneb72axVJyIYji64E2+nNfYyw==} + + '@bundled-es-modules/statuses@1.0.1': + resolution: {integrity: sha512-yn7BklA5acgcBr+7w064fGV+SGIFySjCKpqjcWgBAIfrAkY+4GQTJJHQMeT3V/sgz23VTEVV8TtOmkvJAhFVfg==} + + '@bundled-es-modules/tough-cookie@0.1.6': + resolution: {integrity: sha512-dvMHbL464C0zI+Yqxbz6kZ5TOEp7GLW+pry/RWndAR8MJQAXZ2rPmIs8tziTZjeIyhSNZgZbCePtfSbdWqStJw==} + '@colors/colors@1.5.0': resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==} engines: {node: '>=0.1.90'} @@ -1503,6 +1511,10 @@ packages: cpu: [x64] os: [win32] + '@mswjs/interceptors@0.37.3': + resolution: {integrity: sha512-USvgCL/uOGFtVa6SVyRrC8kIAedzRohxIXN5LISlg5C5vLZCn7dgMFVSNhSF9cuBEFrm/O2spDWEZeMnw4ZXYg==} + engines: {node: '>=18'} + '@napi-rs/nice-android-arm-eabi@1.0.1': resolution: {integrity: sha512-5qpvOu5IGwDo7MEKVqqyAxF90I6aLj4n07OzpARdgDRfz8UbBztTByBp0RC59r3J1Ij8uzYi6jI7r5Lws7nn6w==} engines: {node: '>= 10'} @@ -1672,6 +1684,15 @@ packages: resolution: {integrity: sha512-q9C0uHrb6B6cm3qXVM32UmpqTKuFGbtP23O2K5sLvPMz2hilKd0ptqGXSpuunOuOmPQb/aT5F/kCXFc1P2gO/A==} engines: {node: ^18.17.0 || >=20.5.0} + '@open-draft/deferred-promise@2.2.0': + resolution: {integrity: sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==} + + '@open-draft/logger@0.3.0': + resolution: {integrity: sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ==} + + '@open-draft/until@2.1.0': + resolution: {integrity: sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==} + '@parcel/watcher-android-arm64@2.5.0': resolution: {integrity: sha512-qlX4eS28bUcQCdribHkg/herLe+0A9RyYC+mm2PXpncit8z5b3nSqGVzMNR3CmtAOgRutiZ02eIJJgP/b1iEFQ==} engines: {node: '>= 10.0.0'} @@ -1925,6 +1946,9 @@ packages: '@types/cookie@0.4.1': resolution: {integrity: sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==} + '@types/cookie@0.6.0': + resolution: {integrity: sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==} + '@types/cors@2.8.17': resolution: {integrity: sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==} @@ -1997,6 +2021,12 @@ packages: '@types/sockjs@0.3.36': resolution: {integrity: sha512-MK9V6NzAS1+Ud7JV9lJLFqW85VbC9dq3LmwZCuBe4wBDgKC0Kj/jd8Xl+nSviU+Qc3+m7umHHyHg//2KSa0a0Q==} + '@types/statuses@2.0.5': + resolution: {integrity: sha512-jmIUGWrAiwu3dZpxntxieC+1n/5c3mjrImkmOSQ2NC5uP6cYO4aAZDdSmRcI5C1oiTmqlZGHC+/NmJrKogbP5A==} + + '@types/tough-cookie@4.0.5': + resolution: {integrity: sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==} + '@types/unist@3.0.3': resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} @@ -3240,6 +3270,10 @@ packages: graphemer@1.4.0: resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} + graphql@16.9.0: + resolution: {integrity: sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==} + engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0} + hammerjs@2.0.8: resolution: {integrity: sha512-tSQXBXS/MWQOn/RKckawJ61vvsDpCom87JgxiYdGwHdOa0ht0vzUWDlfioofFCRU0L+6NGDt6XzbgoJvZkMeRQ==} engines: {node: '>=0.8.0'} @@ -3271,6 +3305,9 @@ packages: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} engines: {node: '>= 0.4'} + headers-polyfill@4.0.3: + resolution: {integrity: sha512-IScLbePpkvO846sIwOtOTDjutRMWdXdJmXdMvk6gCBHxFO8d+QKOQedyZSxFTTFYRSmlgSTDtXqqq4pcenBXLQ==} + hosted-git-info@8.0.2: resolution: {integrity: sha512-sYKnA7eGln5ov8T8gnYlkSOxFJvywzEx9BueN6xo/GKO8PGiI6uK6xx+DIGe45T3bdVjLAQDQW1aicT8z8JwQg==} engines: {node: ^18.17.0 || >=20.5.0} @@ -3491,6 +3528,9 @@ packages: resolution: {integrity: sha512-tUdRRAnhT+OtCZR/LxZelH/C7QtjtFrTu5tXCA8pl55eTUElUHT+GPYV8MBMBvea/j+NxQqVt3LbWMRir7Gx9g==} engines: {node: '>=16'} + is-node-process@1.2.0: + resolution: {integrity: sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==} + is-number@7.0.0: resolution: {integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==} engines: {node: '>=0.12.0'} @@ -4118,6 +4158,16 @@ packages: msgpackr@1.11.2: resolution: {integrity: sha512-F9UngXRlPyWCDEASDpTf6c9uNhGPTqnTeLVt7bN+bU1eajoR/8V9ys2BRaV5C/e5ihE6sJ9uPIKaYt6bFuO32g==} + msw@2.6.6: + resolution: {integrity: sha512-npfIIVRHKQX3Lw4aLWX4wBh+lQwpqdZNyJYB5K/+ktK8NhtkdsTxGK7WDrgknozcVyRI7TOqY6yBS9j2FTR+YQ==} + engines: {node: '>=18'} + hasBin: true + peerDependencies: + typescript: '>= 4.8.x' + peerDependenciesMeta: + typescript: + optional: true + multicast-dns@7.2.5: resolution: {integrity: sha512-2eznPJP8z2BFLX50tf0LuODrpINqP1RVIm/CObbTcBRITQgmC/TjcREF1NeTBzIcR5XO/ukWo+YHOjBbFwIupg==} hasBin: true @@ -4312,6 +4362,9 @@ packages: resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} engines: {node: '>=0.10.0'} + outvariant@1.4.3: + resolution: {integrity: sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA==} + p-limit@2.3.0: resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==} engines: {node: '>=6'} @@ -4425,6 +4478,9 @@ packages: path-to-regexp@0.1.10: resolution: {integrity: sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==} + path-to-regexp@6.3.0: + resolution: {integrity: sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==} + path-type@5.0.0: resolution: {integrity: sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==} engines: {node: '>=12'} @@ -4660,6 +4716,9 @@ packages: prr@1.0.1: resolution: {integrity: sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw==} + psl@1.15.0: + resolution: {integrity: sha512-JZd3gMVBAVQkSs6HdNZo9Sdo0LNcQeMNP3CozBJb3JYC/QUYZTnKxP+f8oWRX4rHP5EurWxqAHTSwUCjlNKa1w==} + pump@3.0.2: resolution: {integrity: sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw==} @@ -4683,6 +4742,9 @@ packages: resolution: {integrity: sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==} engines: {node: '>=0.6'} + querystringify@2.2.0: + resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} + queue-microtask@1.2.3: resolution: {integrity: sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==} @@ -5066,6 +5128,9 @@ packages: resolution: {integrity: sha512-KFxaM7XT+irxvdqSP1LGLgNWbYN7ay5owZ3r/8t77p+EtSUAfUgtl7be3xtqtOmGUl9K9YPO2ca8133RlTjvKw==} engines: {node: '>=8.0'} + strict-event-emitter@0.5.1: + resolution: {integrity: sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==} + string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} @@ -5208,6 +5273,10 @@ packages: resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} engines: {node: '>=0.6'} + tough-cookie@4.1.4: + resolution: {integrity: sha512-Loo5UUvLD9ScZ6jh8beX1T6sO1w2/MpCRpEP7V280GKMVUQ0Jzar2U3UJPsrdbziLEMMhu3Ujnq//rhiFuIeag==} + engines: {node: '>=6'} + tree-dump@1.0.2: resolution: {integrity: sha512-dpev9ABuLWdEubk+cIaI9cHwRNNDjkBBLXTwI4UCUFdQ5xXKqNXoK4FEciw/vxf+NQ7Cb7sGUyeUtORvHIdRXQ==} engines: {node: '>=10.0'} @@ -5245,6 +5314,10 @@ packages: resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} engines: {node: '>=10'} + type-fest@4.30.0: + resolution: {integrity: sha512-G6zXWS1dLj6eagy6sVhOMQiLtJdxQBHIA9Z6HFUNLOlr6MFOgzV8wvmidtPONfPtEUv0uZsy77XJNzTAfwPDaA==} + engines: {node: '>=16'} + type-is@1.6.18: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} @@ -5331,6 +5404,10 @@ packages: resolution: {integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==} engines: {node: '>= 4.0.0'} + universalify@0.2.0: + resolution: {integrity: sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==} + engines: {node: '>= 4.0.0'} + universalify@2.0.1: resolution: {integrity: sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==} engines: {node: '>= 10.0.0'} @@ -5351,6 +5428,9 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} + url-parse@1.5.10: + resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==} + util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} @@ -6008,20 +6088,20 @@ snapshots: js-tokens: 4.0.0 picocolors: 1.1.1 - '@babel/compat-data@7.26.2': {} + '@babel/compat-data@7.26.3': {} '@babel/core@7.25.8': dependencies: '@ampproject/remapping': 2.3.0 '@babel/code-frame': 7.26.2 - '@babel/generator': 7.26.2 + '@babel/generator': 7.26.3 '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-module-transforms': 7.26.0(@babel/core@7.25.8) '@babel/helpers': 7.26.0 - '@babel/parser': 7.26.2 + '@babel/parser': 7.26.3 '@babel/template': 7.25.9 - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 + '@babel/traverse': 7.26.3 + '@babel/types': 7.26.3 convert-source-map: 2.0.0 debug: 4.3.7 gensync: 1.0.0-beta.2 @@ -6038,10 +6118,10 @@ snapshots: '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-module-transforms': 7.26.0(@babel/core@7.26.0) '@babel/helpers': 7.26.0 - '@babel/parser': 7.26.2 + '@babel/parser': 7.26.3 '@babel/template': 7.25.9 - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 + '@babel/traverse': 7.26.3 + '@babel/types': 7.26.3 convert-source-map: 2.0.0 debug: 4.3.7 gensync: 1.0.0-beta.2 @@ -6052,26 +6132,27 @@ snapshots: '@babel/generator@7.26.2': dependencies: - '@babel/parser': 7.26.2 - '@babel/types': 7.26.0 + '@babel/parser': 7.26.3 + '@babel/types': 7.26.3 '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 jsesc: 3.0.2 - '@babel/helper-annotate-as-pure@7.25.9': + '@babel/generator@7.26.3': dependencies: - '@babel/types': 7.26.0 + '@babel/parser': 7.26.3 + '@babel/types': 7.26.3 + '@jridgewell/gen-mapping': 0.3.5 + '@jridgewell/trace-mapping': 0.3.25 + jsesc: 3.0.2 - '@babel/helper-builder-binary-assignment-operator-visitor@7.25.9': + '@babel/helper-annotate-as-pure@7.25.9': dependencies: - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 - transitivePeerDependencies: - - supports-color + '@babel/types': 7.26.3 '@babel/helper-compilation-targets@7.25.9': dependencies: - '@babel/compat-data': 7.26.2 + '@babel/compat-data': 7.26.3 '@babel/helper-validator-option': 7.25.9 browserslist: 4.24.2 lru-cache: 5.1.1 @@ -6085,7 +6166,7 @@ snapshots: '@babel/helper-optimise-call-expression': 7.25.9 '@babel/helper-replace-supers': 7.25.9(@babel/core@7.25.8) '@babel/helper-skip-transparent-expression-wrappers': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 semver: 6.3.1 transitivePeerDependencies: - supports-color @@ -6098,19 +6179,19 @@ snapshots: '@babel/helper-optimise-call-expression': 7.25.9 '@babel/helper-replace-supers': 7.25.9(@babel/core@7.26.0) '@babel/helper-skip-transparent-expression-wrappers': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 semver: 6.3.1 transitivePeerDependencies: - supports-color - '@babel/helper-create-regexp-features-plugin@7.25.9(@babel/core@7.25.8)': + '@babel/helper-create-regexp-features-plugin@7.26.3(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 '@babel/helper-annotate-as-pure': 7.25.9 regexpu-core: 6.2.0 semver: 6.3.1 - '@babel/helper-create-regexp-features-plugin@7.25.9(@babel/core@7.26.0)': + '@babel/helper-create-regexp-features-plugin@7.26.3(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 '@babel/helper-annotate-as-pure': 7.25.9 @@ -6141,15 +6222,15 @@ snapshots: '@babel/helper-member-expression-to-functions@7.25.9': dependencies: - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 + '@babel/traverse': 7.26.3 + '@babel/types': 7.26.3 transitivePeerDependencies: - supports-color '@babel/helper-module-imports@7.25.9': dependencies: - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 + '@babel/traverse': 7.26.3 + '@babel/types': 7.26.3 transitivePeerDependencies: - supports-color @@ -6158,7 +6239,7 @@ snapshots: '@babel/core': 7.25.8 '@babel/helper-module-imports': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6167,13 +6248,13 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-module-imports': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color '@babel/helper-optimise-call-expression@7.25.9': dependencies: - '@babel/types': 7.26.0 + '@babel/types': 7.26.3 '@babel/helper-plugin-utils@7.25.9': {} @@ -6182,7 +6263,7 @@ snapshots: '@babel/core': 7.25.8 '@babel/helper-annotate-as-pure': 7.25.9 '@babel/helper-wrap-function': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6191,7 +6272,7 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-annotate-as-pure': 7.25.9 '@babel/helper-wrap-function': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6200,7 +6281,7 @@ snapshots: '@babel/core': 7.25.8 '@babel/helper-member-expression-to-functions': 7.25.9 '@babel/helper-optimise-call-expression': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6209,27 +6290,20 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-member-expression-to-functions': 7.25.9 '@babel/helper-optimise-call-expression': 7.25.9 - '@babel/traverse': 7.25.9 - transitivePeerDependencies: - - supports-color - - '@babel/helper-simple-access@7.25.9': - dependencies: - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color '@babel/helper-skip-transparent-expression-wrappers@7.25.9': dependencies: - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 + '@babel/traverse': 7.26.3 + '@babel/types': 7.26.3 transitivePeerDependencies: - supports-color '@babel/helper-split-export-declaration@7.24.7': dependencies: - '@babel/types': 7.26.0 + '@babel/types': 7.26.3 '@babel/helper-string-parser@7.25.9': {} @@ -6240,25 +6314,25 @@ snapshots: '@babel/helper-wrap-function@7.25.9': dependencies: '@babel/template': 7.25.9 - '@babel/traverse': 7.25.9 - '@babel/types': 7.26.0 + '@babel/traverse': 7.26.3 + '@babel/types': 7.26.3 transitivePeerDependencies: - supports-color '@babel/helpers@7.26.0': dependencies: '@babel/template': 7.25.9 - '@babel/types': 7.26.0 + '@babel/types': 7.26.3 - '@babel/parser@7.26.2': + '@babel/parser@7.26.3': dependencies: - '@babel/types': 7.26.0 + '@babel/types': 7.26.3 '@babel/plugin-bugfix-firefox-class-in-computed-class-key@7.25.9(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 '@babel/helper-plugin-utils': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6266,7 +6340,7 @@ snapshots: dependencies: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6312,7 +6386,7 @@ snapshots: dependencies: '@babel/core': 7.25.8 '@babel/helper-plugin-utils': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6320,7 +6394,7 @@ snapshots: dependencies: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6355,13 +6429,13 @@ snapshots: '@babel/plugin-syntax-unicode-sets-regex@7.18.6(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.25.8) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-syntax-unicode-sets-regex@7.18.6(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-arrow-functions@7.25.9(@babel/core@7.25.8)': @@ -6379,7 +6453,7 @@ snapshots: '@babel/core': 7.25.8 '@babel/helper-plugin-utils': 7.25.9 '@babel/helper-remap-async-to-generator': 7.25.9(@babel/core@7.25.8) - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6388,7 +6462,7 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 '@babel/helper-remap-async-to-generator': 7.25.9(@babel/core@7.26.0) - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6469,7 +6543,7 @@ snapshots: '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 '@babel/helper-replace-supers': 7.25.9(@babel/core@7.25.8) - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 globals: 11.12.0 transitivePeerDependencies: - supports-color @@ -6481,7 +6555,7 @@ snapshots: '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 '@babel/helper-replace-supers': 7.25.9(@babel/core@7.26.0) - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 globals: 11.12.0 transitivePeerDependencies: - supports-color @@ -6511,13 +6585,13 @@ snapshots: '@babel/plugin-transform-dotall-regex@7.25.9(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.25.8) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-dotall-regex@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-duplicate-keys@7.25.9(@babel/core@7.25.8)': @@ -6533,13 +6607,13 @@ snapshots: '@babel/plugin-transform-duplicate-named-capturing-groups-regex@7.25.9(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.25.8) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-duplicate-named-capturing-groups-regex@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-dynamic-import@7.25.9(@babel/core@7.25.8)': @@ -6552,21 +6626,15 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 - '@babel/plugin-transform-exponentiation-operator@7.25.9(@babel/core@7.25.8)': + '@babel/plugin-transform-exponentiation-operator@7.26.3(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-builder-binary-assignment-operator-visitor': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 - transitivePeerDependencies: - - supports-color - '@babel/plugin-transform-exponentiation-operator@7.25.9(@babel/core@7.26.0)': + '@babel/plugin-transform-exponentiation-operator@7.26.3(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-builder-binary-assignment-operator-visitor': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 - transitivePeerDependencies: - - supports-color '@babel/plugin-transform-export-namespace-from@7.25.9(@babel/core@7.25.8)': dependencies: @@ -6599,7 +6667,7 @@ snapshots: '@babel/core': 7.25.8 '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6608,7 +6676,7 @@ snapshots: '@babel/core': 7.26.0 '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6668,21 +6736,19 @@ snapshots: transitivePeerDependencies: - supports-color - '@babel/plugin-transform-modules-commonjs@7.25.9(@babel/core@7.25.8)': + '@babel/plugin-transform-modules-commonjs@7.26.3(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 '@babel/helper-module-transforms': 7.26.0(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 - '@babel/helper-simple-access': 7.25.9 transitivePeerDependencies: - supports-color - '@babel/plugin-transform-modules-commonjs@7.25.9(@babel/core@7.26.0)': + '@babel/plugin-transform-modules-commonjs@7.26.3(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 '@babel/helper-module-transforms': 7.26.0(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 - '@babel/helper-simple-access': 7.25.9 transitivePeerDependencies: - supports-color @@ -6692,7 +6758,7 @@ snapshots: '@babel/helper-module-transforms': 7.26.0(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6702,7 +6768,7 @@ snapshots: '@babel/helper-module-transforms': 7.26.0(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 - '@babel/traverse': 7.25.9 + '@babel/traverse': 7.26.3 transitivePeerDependencies: - supports-color @@ -6725,13 +6791,13 @@ snapshots: '@babel/plugin-transform-named-capturing-groups-regex@7.25.9(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.25.8) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-named-capturing-groups-regex@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-new-target@7.25.9(@babel/core@7.25.8)': @@ -6889,7 +6955,7 @@ snapshots: '@babel/plugin-transform-regexp-modifiers@7.26.0(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-reserved-words@7.25.9(@babel/core@7.25.8)': @@ -6983,42 +7049,42 @@ snapshots: '@babel/plugin-transform-unicode-property-regex@7.25.9(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.25.8) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-unicode-property-regex@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-unicode-regex@7.25.9(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.25.8) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-unicode-regex@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-unicode-sets-regex@7.25.9(@babel/core@7.25.8)': dependencies: '@babel/core': 7.25.8 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.25.8) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.25.8) '@babel/helper-plugin-utils': 7.25.9 '@babel/plugin-transform-unicode-sets-regex@7.25.9(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 - '@babel/helper-create-regexp-features-plugin': 7.25.9(@babel/core@7.26.0) + '@babel/helper-create-regexp-features-plugin': 7.26.3(@babel/core@7.26.0) '@babel/helper-plugin-utils': 7.25.9 '@babel/preset-env@7.25.8(@babel/core@7.25.8)': dependencies: - '@babel/compat-data': 7.26.2 + '@babel/compat-data': 7.26.3 '@babel/core': 7.25.8 '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 @@ -7046,7 +7112,7 @@ snapshots: '@babel/plugin-transform-duplicate-keys': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-duplicate-named-capturing-groups-regex': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-dynamic-import': 7.25.9(@babel/core@7.25.8) - '@babel/plugin-transform-exponentiation-operator': 7.25.9(@babel/core@7.25.8) + '@babel/plugin-transform-exponentiation-operator': 7.26.3(@babel/core@7.25.8) '@babel/plugin-transform-export-namespace-from': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-for-of': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-function-name': 7.25.9(@babel/core@7.25.8) @@ -7055,7 +7121,7 @@ snapshots: '@babel/plugin-transform-logical-assignment-operators': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-member-expression-literals': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-modules-amd': 7.25.9(@babel/core@7.25.8) - '@babel/plugin-transform-modules-commonjs': 7.25.9(@babel/core@7.25.8) + '@babel/plugin-transform-modules-commonjs': 7.26.3(@babel/core@7.25.8) '@babel/plugin-transform-modules-systemjs': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-modules-umd': 7.25.9(@babel/core@7.25.8) '@babel/plugin-transform-named-capturing-groups-regex': 7.25.9(@babel/core@7.25.8) @@ -7092,7 +7158,7 @@ snapshots: '@babel/preset-env@7.26.0(@babel/core@7.26.0)': dependencies: - '@babel/compat-data': 7.26.2 + '@babel/compat-data': 7.26.3 '@babel/core': 7.26.0 '@babel/helper-compilation-targets': 7.25.9 '@babel/helper-plugin-utils': 7.25.9 @@ -7120,7 +7186,7 @@ snapshots: '@babel/plugin-transform-duplicate-keys': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-duplicate-named-capturing-groups-regex': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-dynamic-import': 7.25.9(@babel/core@7.26.0) - '@babel/plugin-transform-exponentiation-operator': 7.25.9(@babel/core@7.26.0) + '@babel/plugin-transform-exponentiation-operator': 7.26.3(@babel/core@7.26.0) '@babel/plugin-transform-export-namespace-from': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-for-of': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-function-name': 7.25.9(@babel/core@7.26.0) @@ -7129,7 +7195,7 @@ snapshots: '@babel/plugin-transform-logical-assignment-operators': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-member-expression-literals': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-modules-amd': 7.25.9(@babel/core@7.26.0) - '@babel/plugin-transform-modules-commonjs': 7.25.9(@babel/core@7.26.0) + '@babel/plugin-transform-modules-commonjs': 7.26.3(@babel/core@7.26.0) '@babel/plugin-transform-modules-systemjs': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-modules-umd': 7.25.9(@babel/core@7.26.0) '@babel/plugin-transform-named-capturing-groups-regex': 7.25.9(@babel/core@7.26.0) @@ -7169,14 +7235,14 @@ snapshots: dependencies: '@babel/core': 7.25.8 '@babel/helper-plugin-utils': 7.25.9 - '@babel/types': 7.26.0 + '@babel/types': 7.26.3 esutils: 2.0.3 '@babel/preset-modules@0.1.6-no-external-plugins(@babel/core@7.26.0)': dependencies: '@babel/core': 7.26.0 '@babel/helper-plugin-utils': 7.25.9 - '@babel/types': 7.26.0 + '@babel/types': 7.26.3 esutils: 2.0.3 '@babel/runtime@7.26.0': @@ -7186,26 +7252,39 @@ snapshots: '@babel/template@7.25.9': dependencies: '@babel/code-frame': 7.26.2 - '@babel/parser': 7.26.2 - '@babel/types': 7.26.0 + '@babel/parser': 7.26.3 + '@babel/types': 7.26.3 - '@babel/traverse@7.25.9': + '@babel/traverse@7.26.3': dependencies: '@babel/code-frame': 7.26.2 - '@babel/generator': 7.26.2 - '@babel/parser': 7.26.2 + '@babel/generator': 7.26.3 + '@babel/parser': 7.26.3 '@babel/template': 7.25.9 - '@babel/types': 7.26.0 + '@babel/types': 7.26.3 debug: 4.3.7 globals: 11.12.0 transitivePeerDependencies: - supports-color - '@babel/types@7.26.0': + '@babel/types@7.26.3': dependencies: '@babel/helper-string-parser': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 + '@bundled-es-modules/cookie@2.0.1': + dependencies: + cookie: 0.7.2 + + '@bundled-es-modules/statuses@1.0.1': + dependencies: + statuses: 2.0.1 + + '@bundled-es-modules/tough-cookie@0.1.6': + dependencies: + '@types/tough-cookie': 4.0.5 + tough-cookie: 4.1.4 + '@colors/colors@1.5.0': {} '@compodoc/compodoc@1.1.26(typescript@5.6.3)': @@ -7701,6 +7780,15 @@ snapshots: '@msgpackr-extract/msgpackr-extract-win32-x64@3.0.3': optional: true + '@mswjs/interceptors@0.37.3': + dependencies: + '@open-draft/deferred-promise': 2.2.0 + '@open-draft/logger': 0.3.0 + '@open-draft/until': 2.1.0 + is-node-process: 1.2.0 + outvariant: 1.4.3 + strict-event-emitter: 0.5.1 + '@napi-rs/nice-android-arm-eabi@1.0.1': optional: true @@ -7868,6 +7956,15 @@ snapshots: - bluebird - supports-color + '@open-draft/deferred-promise@2.2.0': {} + + '@open-draft/logger@0.3.0': + dependencies: + is-node-process: 1.2.0 + outvariant: 1.4.3 + + '@open-draft/until@2.1.0': {} + '@parcel/watcher-android-arm64@2.5.0': optional: true @@ -8073,6 +8170,8 @@ snapshots: '@types/cookie@0.4.1': {} + '@types/cookie@0.6.0': {} + '@types/cors@2.8.17': dependencies: '@types/node': 22.10.1 @@ -8165,6 +8264,10 @@ snapshots: dependencies: '@types/node': 22.10.1 + '@types/statuses@2.0.5': {} + + '@types/tough-cookie@4.0.5': {} + '@types/unist@3.0.3': {} '@types/ws@8.5.13': @@ -8489,7 +8592,7 @@ snapshots: babel-plugin-polyfill-corejs2@0.4.12(@babel/core@7.25.8): dependencies: - '@babel/compat-data': 7.26.2 + '@babel/compat-data': 7.26.3 '@babel/core': 7.25.8 '@babel/helper-define-polyfill-provider': 0.6.3(@babel/core@7.25.8) semver: 6.3.1 @@ -8498,7 +8601,7 @@ snapshots: babel-plugin-polyfill-corejs2@0.4.12(@babel/core@7.26.0): dependencies: - '@babel/compat-data': 7.26.2 + '@babel/compat-data': 7.26.3 '@babel/core': 7.26.0 '@babel/helper-define-polyfill-provider': 0.6.3(@babel/core@7.26.0) semver: 6.3.1 @@ -9616,6 +9719,8 @@ snapshots: graphemer@1.4.0: {} + graphql@16.9.0: {} + hammerjs@2.0.8: {} handle-thing@2.0.1: {} @@ -9645,6 +9750,8 @@ snapshots: dependencies: function-bind: 1.1.2 + headers-polyfill@4.0.3: {} + hosted-git-info@8.0.2: dependencies: lru-cache: 10.4.3 @@ -9857,6 +9964,8 @@ snapshots: is-network-error@1.1.0: {} + is-node-process@1.2.0: {} + is-number@7.0.0: {} is-plain-obj@3.0.0: {} @@ -9896,7 +10005,7 @@ snapshots: istanbul-lib-instrument@5.2.1: dependencies: '@babel/core': 7.26.0 - '@babel/parser': 7.26.2 + '@babel/parser': 7.26.3 '@istanbuljs/schema': 0.1.3 istanbul-lib-coverage: 3.2.2 semver: 6.3.1 @@ -9906,7 +10015,7 @@ snapshots: istanbul-lib-instrument@6.0.3: dependencies: '@babel/core': 7.26.0 - '@babel/parser': 7.26.2 + '@babel/parser': 7.26.3 '@istanbuljs/schema': 0.1.3 istanbul-lib-coverage: 3.2.2 semver: 7.6.3 @@ -10703,6 +10812,31 @@ snapshots: msgpackr-extract: 3.0.3 optional: true + msw@2.6.6(@types/node@22.10.1)(typescript@5.6.3): + dependencies: + '@bundled-es-modules/cookie': 2.0.1 + '@bundled-es-modules/statuses': 1.0.1 + '@bundled-es-modules/tough-cookie': 0.1.6 + '@inquirer/confirm': 5.0.2(@types/node@22.10.1) + '@mswjs/interceptors': 0.37.3 + '@open-draft/deferred-promise': 2.2.0 + '@open-draft/until': 2.1.0 + '@types/cookie': 0.6.0 + '@types/statuses': 2.0.5 + chalk: 4.1.2 + graphql: 16.9.0 + headers-polyfill: 4.0.3 + is-node-process: 1.2.0 + outvariant: 1.4.3 + path-to-regexp: 6.3.0 + strict-event-emitter: 0.5.1 + type-fest: 4.30.0 + yargs: 17.7.2 + optionalDependencies: + typescript: 5.6.3 + transitivePeerDependencies: + - '@types/node' + multicast-dns@7.2.5: dependencies: dns-packet: 5.6.1 @@ -10911,6 +11045,8 @@ snapshots: os-tmpdir@1.0.2: {} + outvariant@1.4.3: {} + p-limit@2.3.0: dependencies: p-try: 2.2.0 @@ -11037,6 +11173,8 @@ snapshots: path-to-regexp@0.1.10: {} + path-to-regexp@6.3.0: {} + path-type@5.0.0: {} pause-stream@0.0.11: @@ -11183,6 +11321,10 @@ snapshots: prr@1.0.1: optional: true + psl@1.15.0: + dependencies: + punycode: 2.3.1 + pump@3.0.2: dependencies: end-of-stream: 1.4.4 @@ -11204,6 +11346,8 @@ snapshots: dependencies: side-channel: 1.0.6 + querystringify@2.2.0: {} + queue-microtask@1.2.3: {} randombytes@2.1.0: @@ -11677,6 +11821,8 @@ snapshots: transitivePeerDependencies: - supports-color + strict-event-emitter@0.5.1: {} + string-width@4.2.3: dependencies: emoji-regex: 8.0.0 @@ -11844,6 +11990,13 @@ snapshots: toidentifier@1.0.1: {} + tough-cookie@4.1.4: + dependencies: + psl: 1.15.0 + punycode: 2.3.1 + universalify: 0.2.0 + url-parse: 1.5.10 + tree-dump@1.0.2(tslib@2.8.1): dependencies: tslib: 2.8.1 @@ -11877,6 +12030,8 @@ snapshots: type-fest@0.21.3: {} + type-fest@4.30.0: {} + type-is@1.6.18: dependencies: media-typer: 0.3.0 @@ -11954,6 +12109,8 @@ snapshots: universalify@0.1.2: {} + universalify@0.2.0: {} + universalify@2.0.1: {} unix-crypt-td-js@1.1.4: {} @@ -11970,6 +12127,11 @@ snapshots: dependencies: punycode: 2.3.1 + url-parse@1.5.10: + dependencies: + querystringify: 2.2.0 + requires-port: 1.0.0 + util-deprecate@1.0.2: {} utils-merge@1.0.1: {} diff --git a/src/app/portal/features/home-page/home-page.component.html b/src/app/portal/features/home-page/home-page.component.html index 68c39d9..32b1792 100644 --- a/src/app/portal/features/home-page/home-page.component.html +++ b/src/app/portal/features/home-page/home-page.component.html @@ -15,3 +15,7 @@ Infrastructure initiative (NFDI) and by the contributing institutions.
More at www.ghga.de.

+ +
+  {{ stats() }}
+
diff --git a/src/app/portal/features/home-page/home-page.component.ts b/src/app/portal/features/home-page/home-page.component.ts index 0362110..f52ca97 100644 --- a/src/app/portal/features/home-page/home-page.component.ts +++ b/src/app/portal/features/home-page/home-page.component.ts @@ -1,4 +1,5 @@ -import { Component } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Component, inject, signal } from '@angular/core'; /** * This is the home page component @@ -8,4 +9,15 @@ import { Component } from '@angular/core'; imports: [], templateUrl: './home-page.component.html', }) -export class HomePageComponent {} +export class HomePageComponent { + // TODO: this is just for testing MSW, remove it later + #http = inject(HttpClient); + stats = signal({}); + + constructor() { + // TODO: this is just for testing MSW, remove it later + this.#http.get('api/metldata/stats').subscribe((data) => { + this.stats.set(JSON.stringify(data)); + }); + } +} diff --git a/src/main.ts b/src/main.ts index 17447a5..f98cbbd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,22 @@ +/** + * The main module + */ + +import { isDevMode } from '@angular/core'; import { bootstrapApplication } from '@angular/platform-browser'; -import { appConfig } from './app/app.config'; import { AppComponent } from './app/app.component'; +import { appConfig } from './app/app.config'; + +/** + * Start the application + */ +async function startApp() { + if (isDevMode()) { + const { worker } = await import('./mocks/setup'); + await worker.start({ waitUntilReady: true }); + } +} -bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err)); +startApp().then(() => + bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err)), +); diff --git a/src/mocks/data.ts b/src/mocks/data.ts new file mode 100644 index 0000000..81f8b9d --- /dev/null +++ b/src/mocks/data.ts @@ -0,0 +1,112 @@ +/** + * Mock data to be used in MSW responses + */ + +/** TODO: Add type annotations using the models that are also used in the application code. */ + +/** + * Metldata API + */ + +export const metadataGlobalSummary = { + resource_stats: { + SequencingProcessFile: { + count: 532, + stats: { + format: [ + { value: 'fastq', count: 124 }, + { value: 'bam', count: 408 }, + ], + }, + }, + Individual: { + count: 5432, + stats: { + sex: [ + { value: 'Female', count: 1935 }, + { value: 'Male', count: 2358 }, + ], + }, + }, + ExperimentMethod: { + count: 1400, + stats: { + instrument_model: [ + { + value: 'Ilumina_test', + count: 700, + }, + { + value: 'HiSeq_test', + count: 700, + }, + ], + }, + }, + Dataset: { + count: 252, + stats: {}, + }, + }, +}; + +/** + * MASS API + */ + +export const searchResults = { + facets: [ + { + key: 'studies.type', + name: 'Study Type', + options: [ + { value: 'Option 1', count: 62 }, + { value: 'Option 2', count: 37 }, + ], + }, + { + key: 'type', + name: 'Dataset Type', + options: [ + { value: 'Test dataset type 1', count: 12 }, + { value: 'Test dataset type 2', count: 87 }, + ], + }, + ], + count: 25, // just to test the paginator + hits: [ + { + id_: 'GHGAD588887987', + content: { + accession: 'GHGAD588887987', + ega_accession: 'EGAD588887987', + title: 'Test dataset for details', + description: + 'Test dataset for Metadata Repository get dataset details call. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel risus commodo viverra maecenas accumsan lacus vel. Sit amet risus nullam eget felis eget nunc lobortis mattis. Iaculis at erat pellentesque adipiscing commodo. Volutpat consequat mauris nunc congue. At lectus urna duis convallis convallis tellus id interdum velit. Gravida cum sociis natoque penatibus et. Mauris in aliquam sem fringilla ut morbi. Ultrices gravida dictum fusce ut. At consectetur lorem donec massa sapien faucibus et molestie.', + types: ['Test dataset type 1'], + }, + }, + { + id_: 'GHGAD588887988', + content: { + accession: 'GHGAD588887988', + ega_accession: 'EGAD588887988', + title: 'Test dataset for details', + description: + 'Test dataset for Metadata Repository get dataset details call. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel risus commodo viverra maecenas accumsan lacus vel. Sit amet risus nullam eget felis eget nunc lobortis mattis. Iaculis at erat pellentesque adipiscing commodo. Volutpat consequat mauris nunc congue. At lectus urna duis convallis convallis tellus id interdum velit. Gravida cum sociis natoque penatibus et. Mauris in aliquam sem fringilla ut morbi. Ultrices gravida dictum fusce ut. At consectetur lorem donec massa sapien faucibus et molestie.', + types: ['Test dataset type 1'], + }, + }, + { + id_: 'GHGAD588887989', + content: { + accession: 'GHGAD588887989', + ega_accession: 'EGAD588887989', + title: 'Test dataset for details', + description: + 'Test dataset for Metadata Repository get dataset details call. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vel risus commodo viverra maecenas accumsan lacus vel. Sit amet risus nullam eget felis eget nunc lobortis mattis. Iaculis at erat pellentesque adipiscing commodo. Volutpat consequat mauris nunc congue. At lectus urna duis convallis convallis tellus id interdum velit. Gravida cum sociis natoque penatibus et. Mauris in aliquam sem fringilla ut morbi. Ultrices gravida dictum fusce ut. At consectetur lorem donec massa sapien faucibus et molestie.', + types: ['Test dataset type 1'], + }, + }, + ], +}; diff --git a/src/mocks/handlers.ts b/src/mocks/handlers.ts new file mode 100644 index 0000000..ed33e12 --- /dev/null +++ b/src/mocks/handlers.ts @@ -0,0 +1,124 @@ +/** + * Create response handlers for MSW + * + * This module takes a list of static responses for different endpoints and + * converts it into a list of response handlers that can be used to* setup MSW. + */ + +import { http, HttpResponse, RequestHandler } from 'msw'; +import { responses, ResponseValue } from './responses'; + +/** + * List of handlers for REST endpoints + */ +export const handlers: RequestHandler[] = []; + +type ResponseMap = { [params: string]: ResponseValue }; + +const groupedResponses: { [endpoint: string]: ResponseMap } = {}; + +/** + * Collect responses with different query parameters for the same endpoint + */ +Object.keys(responses).forEach((endpoint) => { + let method, url, params; + [method, url] = endpoint.split(' '); + method = method.toLowerCase(); + if (!/^(get|post|patch|put|delete)$/.test(method)) { + console.error('Invalid endpoint in fake data:', endpoint); + return; + } + [url, params] = url.split('?'); + let bareEndpoint = `${method} ${url}`; + let responseMap = groupedResponses[bareEndpoint]; + if (!responseMap) { + groupedResponses[bareEndpoint] = responseMap = {}; + } + responseMap[params || '*'] = responses[endpoint]; +}); + +/** + Find the response with the most matching parameters + @param request - the request that should be matched + @param responseMap - the map of responses to choose from + @returns the query string that matches the most parameters + */ +async function getMatchingParamString(request: Request, responseMap: ResponseMap) { + const paramStrings = Object.keys(responseMap); + if (paramStrings.length < 2) { + return paramStrings[0]; + } + // combine parameters from query string and body + const requestParams = new URL(request.url).searchParams; + const method = request.method.toLowerCase(); + if (/post|patch|put|delete/.test(method)) { + try { + const bodyParams = await request.json(); + Object.entries(bodyParams).forEach(([key, value]) => { + const paramValue = typeof value === 'string' ? value : JSON.stringify(value); + requestParams.set(key, paramValue); + }); + } catch {} + } + // find the response with the most matching parameters + let bestParamString: string | null = null; + let bestNumParams = 0; + let bestStringLen = 0; + Object.keys(responseMap).forEach((paramString) => { + const params = new URLSearchParams(paramString); + const numParams = Array.from(requestParams.keys()).reduce( + (num, param) => num + (params.get(param) === requestParams.get(param) ? 1 : 0), + 0, + ); + if ( + bestParamString === null || + numParams > bestNumParams || + (numParams === bestNumParams && paramString.length < bestStringLen) + ) { + bestParamString = paramString; + bestNumParams = numParams; + bestStringLen = paramString.length; + } + }); + return bestParamString; +} + +// create request handlers for the different endpoints +Object.keys(groupedResponses).forEach((endpoint) => { + let method, url; + [method, url] = endpoint.split(' '); + const responseMap = groupedResponses[endpoint]; + /** + * Resolver for the given endpoint + * @param options - an options object containing the request + * @param options.request - the request object + * @returns - a response + */ + const resolver = async ({ request }: { request: Request }) => { + const paramString = await getMatchingParamString(request, responseMap); + let response = responseMap[paramString || '*']; + if (response === undefined) { + console.debug('Not mocking', url); + return; + } + if (Object.keys(responseMap).length > 1) { + console.debug('Using mock data for params', paramString); + } + let status = 200; + if (typeof response === 'number') { + status = response; + response = undefined; + } else if (/post/.test(method)) { + status = 201; + } else if (/patch|put|delete/.test(method)) { + status = 204; + } + return HttpResponse.json(response || undefined, { status }); + }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const handler = (http as any)[method]; + if (!handler) { + console.error('Unsupported method:', method); + } + handlers.push(handler.call(http, url, resolver)); +}); diff --git a/src/mocks/mockServiceWorker.js b/src/mocks/mockServiceWorker.js new file mode 100644 index 0000000..fead0b3 --- /dev/null +++ b/src/mocks/mockServiceWorker.js @@ -0,0 +1,295 @@ +/* eslint-disable */ +/* tslint:disable */ + +/** + * Mock Service Worker. + * @see https://github.com/mswjs/msw + * - Please do NOT modify this file. + * - Please do NOT serve this file on production. + */ + +const PACKAGE_VERSION = '2.6.6' +const INTEGRITY_CHECKSUM = 'ca7800994cc8bfb5eb961e037c877074' +const IS_MOCKED_RESPONSE = Symbol('isMockedResponse') +const activeClientIds = new Set() + +self.addEventListener('install', function () { + self.skipWaiting() +}) + +self.addEventListener('activate', function (event) { + event.waitUntil(self.clients.claim()) +}) + +self.addEventListener('message', async function (event) { + const clientId = event.source.id + + if (!clientId || !self.clients) { + return + } + + const client = await self.clients.get(clientId) + + if (!client) { + return + } + + const allClients = await self.clients.matchAll({ + type: 'window', + }) + + switch (event.data) { + case 'KEEPALIVE_REQUEST': { + sendToClient(client, { + type: 'KEEPALIVE_RESPONSE', + }) + break + } + + case 'INTEGRITY_CHECK_REQUEST': { + sendToClient(client, { + type: 'INTEGRITY_CHECK_RESPONSE', + payload: { + packageVersion: PACKAGE_VERSION, + checksum: INTEGRITY_CHECKSUM, + }, + }) + break + } + + case 'MOCK_ACTIVATE': { + activeClientIds.add(clientId) + + sendToClient(client, { + type: 'MOCKING_ENABLED', + payload: { + client: { + id: client.id, + frameType: client.frameType, + }, + }, + }) + break + } + + case 'MOCK_DEACTIVATE': { + activeClientIds.delete(clientId) + break + } + + case 'CLIENT_CLOSED': { + activeClientIds.delete(clientId) + + const remainingClients = allClients.filter((client) => { + return client.id !== clientId + }) + + // Unregister itself when there are no more clients + if (remainingClients.length === 0) { + self.registration.unregister() + } + + break + } + } +}) + +self.addEventListener('fetch', function (event) { + const { request } = event + + // Bypass navigation requests. + if (request.mode === 'navigate') { + return + } + + // Opening the DevTools triggers the "only-if-cached" request + // that cannot be handled by the worker. Bypass such requests. + if (request.cache === 'only-if-cached' && request.mode !== 'same-origin') { + return + } + + // Bypass all requests when there are no active clients. + // Prevents the self-unregistered worked from handling requests + // after it's been deleted (still remains active until the next reload). + if (activeClientIds.size === 0) { + return + } + + // Generate unique request ID. + const requestId = crypto.randomUUID() + event.respondWith(handleRequest(event, requestId)) +}) + +async function handleRequest(event, requestId) { + const client = await resolveMainClient(event) + const response = await getResponse(event, client, requestId) + + // Send back the response clone for the "response:*" life-cycle events. + // Ensure MSW is active and ready to handle the message, otherwise + // this message will pend indefinitely. + if (client && activeClientIds.has(client.id)) { + ;(async function () { + const responseClone = response.clone() + + sendToClient( + client, + { + type: 'RESPONSE', + payload: { + requestId, + isMockedResponse: IS_MOCKED_RESPONSE in response, + type: responseClone.type, + status: responseClone.status, + statusText: responseClone.statusText, + body: responseClone.body, + headers: Object.fromEntries(responseClone.headers.entries()), + }, + }, + [responseClone.body], + ) + })() + } + + return response +} + +// Resolve the main client for the given event. +// Client that issues a request doesn't necessarily equal the client +// that registered the worker. It's with the latter the worker should +// communicate with during the response resolving phase. +async function resolveMainClient(event) { + const client = await self.clients.get(event.clientId) + + if (activeClientIds.has(event.clientId)) { + return client + } + + if (client?.frameType === 'top-level') { + return client + } + + const allClients = await self.clients.matchAll({ + type: 'window', + }) + + return allClients + .filter((client) => { + // Get only those clients that are currently visible. + return client.visibilityState === 'visible' + }) + .find((client) => { + // Find the client ID that's recorded in the + // set of clients that have registered the worker. + return activeClientIds.has(client.id) + }) +} + +async function getResponse(event, client, requestId) { + const { request } = event + + // Clone the request because it might've been already used + // (i.e. its body has been read and sent to the client). + const requestClone = request.clone() + + function passthrough() { + // Cast the request headers to a new Headers instance + // so the headers can be manipulated with. + const headers = new Headers(requestClone.headers) + + // Remove the "accept" header value that marked this request as passthrough. + // This prevents request alteration and also keeps it compliant with the + // user-defined CORS policies. + headers.delete('accept', 'msw/passthrough') + + return fetch(requestClone, { headers }) + } + + // Bypass mocking when the client is not active. + if (!client) { + return passthrough() + } + + // Bypass initial page load requests (i.e. static assets). + // The absence of the immediate/parent client in the map of the active clients + // means that MSW hasn't dispatched the "MOCK_ACTIVATE" event yet + // and is not ready to handle requests. + if (!activeClientIds.has(client.id)) { + return passthrough() + } + + // Notify the client that a request has been intercepted. + const requestBuffer = await request.arrayBuffer() + const clientMessage = await sendToClient( + client, + { + type: 'REQUEST', + payload: { + id: requestId, + url: request.url, + mode: request.mode, + method: request.method, + headers: Object.fromEntries(request.headers.entries()), + cache: request.cache, + credentials: request.credentials, + destination: request.destination, + integrity: request.integrity, + redirect: request.redirect, + referrer: request.referrer, + referrerPolicy: request.referrerPolicy, + body: requestBuffer, + keepalive: request.keepalive, + }, + }, + [requestBuffer], + ) + + switch (clientMessage.type) { + case 'MOCK_RESPONSE': { + return respondWithMock(clientMessage.data) + } + + case 'PASSTHROUGH': { + return passthrough() + } + } + + return passthrough() +} + +function sendToClient(client, message, transferrables = []) { + return new Promise((resolve, reject) => { + const channel = new MessageChannel() + + channel.port1.onmessage = (event) => { + if (event.data && event.data.error) { + return reject(event.data.error) + } + + resolve(event.data) + } + + client.postMessage( + message, + [channel.port2].concat(transferrables.filter(Boolean)), + ) + }) +} + +async function respondWithMock(response) { + // Setting response status code to 0 is a no-op. + // However, when responding with a "Response.error()", the produced Response + // instance will have status code set to 0. Since it's not possible to create + // a Response instance with status code 0, handle that use-case separately. + if (response.status === 0) { + return Response.error() + } + + const mockedResponse = new Response(response.body, response) + + Reflect.defineProperty(mockedResponse, IS_MOCKED_RESPONSE, { + value: true, + enumerable: true, + }) + + return mockedResponse +} diff --git a/src/mocks/responses.ts b/src/mocks/responses.ts new file mode 100644 index 0000000..ef64b07 --- /dev/null +++ b/src/mocks/responses.ts @@ -0,0 +1,34 @@ +import { searchResults } from './data'; + +/** + * MSW responses to be returned for various endpoints. + * + * The property names must contain a method and a URL separated by a space + * and the values can be undefined (do not mock this endpoint) + * a number (use it as response status), or an object (return it as JSON). + * + * The responses are automatically converted into + * + */ + +import { metadataGlobalSummary } from './data'; + +export type ResponseValue = undefined | number | object; + +export const responses: { [endpoint: string]: ResponseValue } = { + /** + * Metldata API + */ + + 'GET /api/metldata/stats': metadataGlobalSummary, + + /** + * MASS API + */ + + 'GET /api/mass/search*': { + facets: searchResults.facets, + count: searchResults.count, + hits: searchResults.hits, + }, +}; diff --git a/src/mocks/setup.ts b/src/mocks/setup.ts new file mode 100644 index 0000000..daccc5e --- /dev/null +++ b/src/mocks/setup.ts @@ -0,0 +1,10 @@ +/** + * Create a mock service worker for the web browser + * + * The mock service worker is used to create mock responses for local testing. + */ + +import { setupWorker } from 'msw/browser'; +import { handlers } from './handlers'; + +export const worker = setupWorker(...handlers);