From f612da9035602239089fc5bc171224175fb49596 Mon Sep 17 00:00:00 2001 From: Lukasz Ostrowski Date: Mon, 12 Dec 2022 11:47:23 +0100 Subject: [PATCH] Add authenticated fetch (#138) * Add authenticated fetch * Add tests * Update vitest * setup node-fetch * update lockfle * change to global.fetch * add mock fetch * Change window.fetch to global.fetch --- package.json | 9 +- pnpm-lock.yaml | 455 +++++++++++++++++++++++++++-------- src/app-bridge/fetch.test.ts | 68 ++++++ src/app-bridge/fetch.ts | 38 +++ src/app-bridge/index.ts | 1 + src/setup-tests.ts | 1 + 6 files changed, 472 insertions(+), 100 deletions(-) create mode 100644 src/app-bridge/fetch.test.ts create mode 100644 src/app-bridge/fetch.ts diff --git a/package.json b/package.json index 4fab9be7..8af879cc 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,8 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-simple-import-sort": "^8.0.0", "husky": "^8.0.1", - "jsdom": "^20.0.0", + "jsdom": "^20.0.3", + "lint-staged": "^13.0.3", "next": "^12.3.0", "node-mocks-http": "^1.11.0", "prettier": "2.7.1", @@ -68,9 +69,9 @@ "tsm": "^2.2.2", "tsup": "^6.2.3", "typescript": "^4.8.2", - "vite": "^3.1.0", - "vitest": "^0.23.1", - "lint-staged": "^13.0.3" + "vi-fetch": "^0.8.0", + "vite": "^3.2.5", + "vitest": "^0.25.6" }, "lint-staged": { "*.{js,ts,tsx}": "eslint --cache --fix", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ac842000..4b5bc9cd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,7 +28,7 @@ specifiers: graphql: ^16.6.0 husky: ^8.0.1 jose: ^4.9.2 - jsdom: ^20.0.0 + jsdom: ^20.0.3 lint-staged: ^13.0.3 next: ^12.3.0 node-fetch: ^2.6.7 @@ -43,8 +43,9 @@ specifiers: tsup: ^6.2.3 typescript: ^4.8.2 uuid: ^8.3.2 - vite: ^3.1.0 - vitest: ^0.23.1 + vi-fetch: ^0.8.0 + vite: ^3.2.5 + vitest: ^0.25.6 dependencies: debug: 4.3.4 @@ -67,8 +68,8 @@ devDependencies: '@types/uuid': 8.3.4 '@typescript-eslint/eslint-plugin': 5.36.1_lbwfnm54o3pmr3ypeqp3btnera '@typescript-eslint/parser': 5.36.1_yqf6kl63nyoq5megxukfnom5rm - '@vitejs/plugin-react': 2.1.0_vite@3.1.0 - '@vitest/coverage-c8': 0.23.2_jsdom@20.0.0 + '@vitejs/plugin-react': 2.1.0_vite@3.2.5 + '@vitest/coverage-c8': 0.23.2_jsdom@20.0.3 clean-publish: 4.0.1 eslint: 8.23.0 eslint-config-airbnb: 19.0.4_iatlp42xxmbmk7uus7gwkorlju @@ -80,7 +81,7 @@ devDependencies: eslint-plugin-react-hooks: 4.6.0_eslint@8.23.0 eslint-plugin-simple-import-sort: 8.0.0_eslint@8.23.0 husky: 8.0.1 - jsdom: 20.0.0 + jsdom: 20.0.3 lint-staged: 13.0.3 next: 12.3.0_biqbaboplfbrettd7655fr4n2y node-mocks-http: 1.11.0 @@ -91,8 +92,9 @@ devDependencies: tsm: 2.2.2 tsup: 6.2.3_typescript@4.8.2 typescript: 4.8.2 - vite: 3.1.0 - vitest: 0.23.1_jsdom@20.0.0 + vi-fetch: 0.8.0 + vite: 3.2.5_@types+node@18.7.15 + vitest: 0.25.6_jsdom@20.0.3 packages: @@ -382,6 +384,15 @@ packages: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} dev: true + /@esbuild/android-arm/0.15.18: + resolution: {integrity: sha512-5GT+kcs2WVGjVs7+boataCkO5Fg0y4kCjzkB5bAip7H4jfnOS3dA6KPiww9W1OEKTKeAcUVhdZGvgI65OXmUnw==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-loong64/0.14.54: resolution: {integrity: sha512-bZBrLAIX1kpWelV0XemxBZllyRmM6vgFQQG2GdNb+r3Fkp0FOh1NJSvekXDs7jq70k4euu1cryLMfU+mTXlEpw==} engines: {node: '>=12'} @@ -391,6 +402,15 @@ packages: dev: true optional: true + /@esbuild/linux-loong64/0.15.18: + resolution: {integrity: sha512-L4jVKS82XVhw2nvzLg/19ClLWg0y27ulRwuP7lcyL6AbUWB5aPglXY3M21mauDQMDfRLs8cQmeT03r/+X3cZYQ==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /@esbuild/linux-loong64/0.15.7: resolution: {integrity: sha512-IKznSJOsVUuyt7cDzzSZyqBEcZe+7WlBqTVXiF1OXP/4Nm387ToaXZ0fyLwI1iBlI/bzpxVq411QE2/Bt2XWWw==} engines: {node: '>=12'} @@ -1055,7 +1075,7 @@ packages: eslint-visitor-keys: 3.3.0 dev: true - /@vitejs/plugin-react/2.1.0_vite@3.1.0: + /@vitejs/plugin-react/2.1.0_vite@3.2.5: resolution: {integrity: sha512-am6rPyyU3LzUYne3Gd9oj9c4Rzbq5hQnuGXSMT6Gujq45Il/+bunwq3lrB7wghLkiF45ygMwft37vgJ/NE8IAA==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: @@ -1068,16 +1088,16 @@ packages: '@babel/plugin-transform-react-jsx-source': 7.18.6_@babel+core@7.18.13 magic-string: 0.26.3 react-refresh: 0.14.0 - vite: 3.1.0 + vite: 3.2.5_@types+node@18.7.15 transitivePeerDependencies: - supports-color dev: true - /@vitest/coverage-c8/0.23.2_jsdom@20.0.0: + /@vitest/coverage-c8/0.23.2_jsdom@20.0.3: resolution: {integrity: sha512-VWT6zGj9iXEZCimnRLAUhf3siYVGIG9VryyMoo7B8zMOd+bnAbH8/7PhqvmjedVwa9wh61nkxqgG7/3Y/mzofQ==} dependencies: c8: 7.12.0 - vitest: 0.23.2_jsdom@20.0.0 + vitest: 0.23.2_jsdom@20.0.3 transitivePeerDependencies: - '@edge-runtime/vm' - '@vitest/browser' @@ -1087,6 +1107,7 @@ packages: - less - sass - stylus + - sugarss - supports-color - terser dev: true @@ -1103,24 +1124,19 @@ packages: negotiator: 0.6.3 dev: true - /acorn-globals/6.0.0: - resolution: {integrity: sha512-ZQl7LOWaF5ePqqcX4hLuv/bLXYQNfNWw2c0/yX/TsPRKamzHcTGQnlCjHT3TsmkOUVEPS3crCxiPfdzE/Trlhg==} + /acorn-globals/7.0.1: + resolution: {integrity: sha512-umOSDSDrfHbTNPuNpC2NSnnA3LUrqpevPb4T9jRx4MagXNS0rs+gwiTcAvqCRmsD6utzsrzNt+ebm00SNWiC3Q==} dependencies: - acorn: 7.4.1 - acorn-walk: 7.2.0 + acorn: 8.8.1 + acorn-walk: 8.2.0 dev: true - /acorn-jsx/5.3.2_acorn@8.8.0: + /acorn-jsx/5.3.2_acorn@8.8.1: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: - acorn: 8.8.0 - dev: true - - /acorn-walk/7.2.0: - resolution: {integrity: sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA==} - engines: {node: '>=0.4.0'} + acorn: 8.8.1 dev: true /acorn-walk/8.2.0: @@ -1128,14 +1144,14 @@ packages: engines: {node: '>=0.4.0'} dev: true - /acorn/7.4.1: - resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==} + /acorn/8.8.0: + resolution: {integrity: sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==} engines: {node: '>=0.4.0'} hasBin: true dev: true - /acorn/8.8.0: - resolution: {integrity: sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==} + /acorn/8.8.1: + resolution: {integrity: sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==} engines: {node: '>=0.4.0'} hasBin: true dev: true @@ -1323,7 +1339,7 @@ packages: dev: true /asynckit/0.4.0: - resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/asynckit/-/asynckit-0.4.0.tgz} + resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} dev: true /axe-core/4.4.3: @@ -1387,10 +1403,6 @@ packages: dependencies: fill-range: 7.0.1 - /browser-process-hrtime/1.0.0: - resolution: {integrity: sha512-9o5UecI3GhkpM6DrXr69PblIuWxPKk9Y0jHBRhdocZ2y7YECBFCsHm79Pr3OyR2AvjhDkabFJaDJMYRazHgsow==} - dev: true - /browserslist/4.21.3: resolution: {integrity: sha512-898rgRXLAyRkM1GryrrBHGkqA5hlpkV5MhtZwg9QXeiyLUYs2k00Un05aX5l2/yJIOObYKOpS2JNo8nJDE7fWQ==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -1661,7 +1673,7 @@ packages: dev: true /combined-stream/1.0.8: - resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/combined-stream/-/combined-stream-1.0.8.tgz} + resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} dependencies: delayed-stream: 1.0.0 @@ -1827,8 +1839,13 @@ packages: dependencies: ms: 2.1.2 - /decimal.js/10.4.0: - resolution: {integrity: sha512-Nv6ENEzyPQ6AItkGwLE2PGKinZZ9g59vSh2BeH6NqPu0OTKZ5ruJsVqh/orbAnqXc9pBbgXAIrc2EyaCj8NpGg==} + /decimal.js/10.4.3: + resolution: {integrity: sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==} + dev: true + + /decode-uri-component/0.2.2: + resolution: {integrity: sha512-FqUYQ+8o158GyGTrMFJms9qh3CqTKvAqgqsTnkLI8sKu0028orqBhxNMFkFen0zGyg6epACD32pjVk58ngIErQ==} + engines: {node: '>=0.10'} dev: true /decompress-response/6.0.0: @@ -1889,7 +1906,7 @@ packages: dev: true /delayed-stream/1.0.0: - resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/delayed-stream/-/delayed-stream-1.0.0.tgz} + resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} engines: {node: '>=0.4.0'} dev: true @@ -2056,6 +2073,15 @@ packages: dev: true optional: true + /esbuild-android-64/0.15.18: + resolution: {integrity: sha512-wnpt3OXRhcjfIDSZu9bnzT4/TNTDsOUvip0foZOUBG7QbSt//w3QV4FInVJxNhKc/ErhUxc5z4QjHtMi7/TbgA==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + /esbuild-android-64/0.15.7: resolution: {integrity: sha512-p7rCvdsldhxQr3YHxptf1Jcd86dlhvc3EQmQJaZzzuAxefO9PvcI0GLOa5nCWem1AJ8iMRu9w0r5TG8pHmbi9w==} engines: {node: '>=12'} @@ -2074,6 +2100,15 @@ packages: dev: true optional: true + /esbuild-android-arm64/0.15.18: + resolution: {integrity: sha512-G4xu89B8FCzav9XU8EjsXacCKSG2FT7wW9J6hOc18soEHJdtWu03L3TQDGf0geNxfLTtxENKBzMSq9LlbjS8OQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + /esbuild-android-arm64/0.15.7: resolution: {integrity: sha512-L775l9ynJT7rVqRM5vo+9w5g2ysbOCfsdLV4CWanTZ1k/9Jb3IYlQ06VCI1edhcosTYJRECQFJa3eAvkx72eyQ==} engines: {node: '>=12'} @@ -2092,6 +2127,15 @@ packages: dev: true optional: true + /esbuild-darwin-64/0.15.18: + resolution: {integrity: sha512-2WAvs95uPnVJPuYKP0Eqx+Dl/jaYseZEUUT1sjg97TJa4oBtbAKnPnl3b5M9l51/nbx7+QAEtuummJZW0sBEmg==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-64/0.15.7: resolution: {integrity: sha512-KGPt3r1c9ww009t2xLB6Vk0YyNOXh7hbjZ3EecHoVDxgtbUlYstMPDaReimKe6eOEfyY4hBEEeTvKwPsiH5WZg==} engines: {node: '>=12'} @@ -2110,6 +2154,15 @@ packages: dev: true optional: true + /esbuild-darwin-arm64/0.15.18: + resolution: {integrity: sha512-tKPSxcTJ5OmNb1btVikATJ8NftlyNlc8BVNtyT/UAr62JFOhwHlnoPrhYWz09akBLHI9nElFVfWSTSRsrZiDUA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + /esbuild-darwin-arm64/0.15.7: resolution: {integrity: sha512-kBIHvtVqbSGajN88lYMnR3aIleH3ABZLLFLxwL2stiuIGAjGlQW741NxVTpUHQXUmPzxi6POqc9npkXa8AcSZQ==} engines: {node: '>=12'} @@ -2128,6 +2181,15 @@ packages: dev: true optional: true + /esbuild-freebsd-64/0.15.18: + resolution: {integrity: sha512-TT3uBUxkteAjR1QbsmvSsjpKjOX6UkCstr8nMr+q7zi3NuZ1oIpa8U41Y8I8dJH2fJgdC3Dj3CXO5biLQpfdZA==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-64/0.15.7: resolution: {integrity: sha512-hESZB91qDLV5MEwNxzMxPfbjAhOmtfsr9Wnuci7pY6TtEh4UDuevmGmkUIjX/b+e/k4tcNBMf7SRQ2mdNuK/HQ==} engines: {node: '>=12'} @@ -2146,6 +2208,15 @@ packages: dev: true optional: true + /esbuild-freebsd-arm64/0.15.18: + resolution: {integrity: sha512-R/oVr+X3Tkh+S0+tL41wRMbdWtpWB8hEAMsOXDumSSa6qJR89U0S/PpLXrGF7Wk/JykfpWNokERUpCeHDl47wA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + /esbuild-freebsd-arm64/0.15.7: resolution: {integrity: sha512-dLFR0ChH5t+b3J8w0fVKGvtwSLWCv7GYT2Y2jFGulF1L5HftQLzVGN+6pi1SivuiVSmTh28FwUhi9PwQicXI6Q==} engines: {node: '>=12'} @@ -2164,6 +2235,15 @@ packages: dev: true optional: true + /esbuild-linux-32/0.15.18: + resolution: {integrity: sha512-lphF3HiCSYtaa9p1DtXndiQEeQDKPl9eN/XNoBf2amEghugNuqXNZA/ZovthNE2aa4EN43WroO0B85xVSjYkbg==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-32/0.15.7: resolution: {integrity: sha512-v3gT/LsONGUZcjbt2swrMjwxo32NJzk+7sAgtxhGx1+ZmOFaTRXBAi1PPfgpeo/J//Un2jIKm/I+qqeo4caJvg==} engines: {node: '>=12'} @@ -2182,6 +2262,15 @@ packages: dev: true optional: true + /esbuild-linux-64/0.15.18: + resolution: {integrity: sha512-hNSeP97IviD7oxLKFuii5sDPJ+QHeiFTFLoLm7NZQligur8poNOWGIgpQ7Qf8Balb69hptMZzyOBIPtY09GZYw==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-64/0.15.7: resolution: {integrity: sha512-LxXEfLAKwOVmm1yecpMmWERBshl+Kv5YJ/1KnyAr6HRHFW8cxOEsEfisD3sVl/RvHyW//lhYUVSuy9jGEfIRAQ==} engines: {node: '>=12'} @@ -2200,6 +2289,15 @@ packages: dev: true optional: true + /esbuild-linux-arm/0.15.18: + resolution: {integrity: sha512-UH779gstRblS4aoS2qpMl3wjg7U0j+ygu3GjIeTonCcN79ZvpPee12Qun3vcdxX+37O5LFxz39XeW2I9bybMVA==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm/0.15.7: resolution: {integrity: sha512-JKgAHtMR5f75wJTeuNQbyznZZa+pjiUHV7sRZp42UNdyXC6TiUYMW/8z8yIBAr2Fpad8hM1royZKQisqPABPvQ==} engines: {node: '>=12'} @@ -2218,6 +2316,15 @@ packages: dev: true optional: true + /esbuild-linux-arm64/0.15.18: + resolution: {integrity: sha512-54qr8kg/6ilcxd+0V3h9rjT4qmjc0CccMVWrjOEM/pEcUzt8X62HfBSeZfT2ECpM7104mk4yfQXkosY8Quptug==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-arm64/0.15.7: resolution: {integrity: sha512-P3cfhudpzWDkglutWgXcT2S7Ft7o2e3YDMrP1n0z2dlbUZghUkKCyaWw0zhp4KxEEzt/E7lmrtRu/pGWnwb9vw==} engines: {node: '>=12'} @@ -2236,6 +2343,15 @@ packages: dev: true optional: true + /esbuild-linux-mips64le/0.15.18: + resolution: {integrity: sha512-Mk6Ppwzzz3YbMl/ZZL2P0q1tnYqh/trYZ1VfNP47C31yT0K8t9s7Z077QrDA/guU60tGNp2GOwCQnp+DYv7bxQ==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-mips64le/0.15.7: resolution: {integrity: sha512-T7XKuxl0VpeFLCJXub6U+iybiqh0kM/bWOTb4qcPyDDwNVhLUiPcGdG2/0S7F93czUZOKP57YiLV8YQewgLHKw==} engines: {node: '>=12'} @@ -2254,6 +2370,15 @@ packages: dev: true optional: true + /esbuild-linux-ppc64le/0.15.18: + resolution: {integrity: sha512-b0XkN4pL9WUulPTa/VKHx2wLCgvIAbgwABGnKMY19WhKZPT+8BxhZdqz6EgkqCLld7X5qiCY2F/bfpUUlnFZ9w==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-ppc64le/0.15.7: resolution: {integrity: sha512-6mGuC19WpFN7NYbecMIJjeQgvDb5aMuvyk0PDYBJrqAEMkTwg3Z98kEKuCm6THHRnrgsdr7bp4SruSAxEM4eJw==} engines: {node: '>=12'} @@ -2272,6 +2397,15 @@ packages: dev: true optional: true + /esbuild-linux-riscv64/0.15.18: + resolution: {integrity: sha512-ba2COaoF5wL6VLZWn04k+ACZjZ6NYniMSQStodFKH/Pu6RxzQqzsmjR1t9QC89VYJxBeyVPTaHuBMCejl3O/xg==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-riscv64/0.15.7: resolution: {integrity: sha512-uUJsezbswAYo/X7OU/P+PuL/EI9WzxsEQXDekfwpQ23uGiooxqoLFAPmXPcRAt941vjlY9jtITEEikWMBr+F/g==} engines: {node: '>=12'} @@ -2290,6 +2424,15 @@ packages: dev: true optional: true + /esbuild-linux-s390x/0.15.18: + resolution: {integrity: sha512-VbpGuXEl5FCs1wDVp93O8UIzl3ZrglgnSQ+Hu79g7hZu6te6/YHgVJxCM2SqfIila0J3k0csfnf8VD2W7u2kzQ==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + /esbuild-linux-s390x/0.15.7: resolution: {integrity: sha512-+tO+xOyTNMc34rXlSxK7aCwJgvQyffqEM5MMdNDEeMU3ss0S6wKvbBOQfgd5jRPblfwJ6b+bKiz0g5nABpY0QQ==} engines: {node: '>=12'} @@ -2308,6 +2451,15 @@ packages: dev: true optional: true + /esbuild-netbsd-64/0.15.18: + resolution: {integrity: sha512-98ukeCdvdX7wr1vUYQzKo4kQ0N2p27H7I11maINv73fVEXt2kyh4K4m9f35U1K43Xc2QGXlzAw0K9yoU7JUjOg==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-netbsd-64/0.15.7: resolution: {integrity: sha512-yVc4Wz+Pu3cP5hzm5kIygNPrjar/v5WCSoRmIjCPWfBVJkZNb5brEGKUlf+0Y759D48BCWa0WHrWXaNy0DULTQ==} engines: {node: '>=12'} @@ -2326,6 +2478,15 @@ packages: dev: true optional: true + /esbuild-openbsd-64/0.15.18: + resolution: {integrity: sha512-yK5NCcH31Uae076AyQAXeJzt/vxIo9+omZRKj1pauhk3ITuADzuOx5N2fdHrAKPxN+zH3w96uFKlY7yIn490xQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + /esbuild-openbsd-64/0.15.7: resolution: {integrity: sha512-GsimbwC4FSR4lN3wf8XmTQ+r8/0YSQo21rWDL0XFFhLHKlzEA4SsT1Tl8bPYu00IU6UWSJ+b3fG/8SB69rcuEQ==} engines: {node: '>=12'} @@ -2344,6 +2505,15 @@ packages: dev: true optional: true + /esbuild-sunos-64/0.15.18: + resolution: {integrity: sha512-On22LLFlBeLNj/YF3FT+cXcyKPEI263nflYlAhz5crxtp3yRG1Ugfr7ITyxmCmjm4vbN/dGrb/B7w7U8yJR9yw==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + /esbuild-sunos-64/0.15.7: resolution: {integrity: sha512-8CDI1aL/ts0mDGbWzjEOGKXnU7p3rDzggHSBtVryQzkSOsjCHRVe0iFYUuhczlxU1R3LN/E7HgUO4NXzGGP/Ag==} engines: {node: '>=12'} @@ -2362,6 +2532,15 @@ packages: dev: true optional: true + /esbuild-windows-32/0.15.18: + resolution: {integrity: sha512-o+eyLu2MjVny/nt+E0uPnBxYuJHBvho8vWsC2lV61A7wwTWC3jkN2w36jtA+yv1UgYkHRihPuQsL23hsCYGcOQ==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-32/0.15.7: resolution: {integrity: sha512-cOnKXUEPS8EGCzRSFa1x6NQjGhGsFlVgjhqGEbLTPsA7x4RRYiy2RKoArNUU4iR2vHmzqS5Gr84MEumO/wxYKA==} engines: {node: '>=12'} @@ -2380,6 +2559,15 @@ packages: dev: true optional: true + /esbuild-windows-64/0.15.18: + resolution: {integrity: sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-64/0.15.7: resolution: {integrity: sha512-7MI08Ec2sTIDv+zH6StNBKO+2hGUYIT42GmFyW6MBBWWtJhTcQLinKS6ldIN1d52MXIbiJ6nXyCJ+LpL4jBm3Q==} engines: {node: '>=12'} @@ -2398,6 +2586,15 @@ packages: dev: true optional: true + /esbuild-windows-arm64/0.15.18: + resolution: {integrity: sha512-q9bsYzegpZcLziq0zgUi5KqGVtfhjxGbnksaBFYmWLxeV/S1fK4OLdq2DFYnXcLMjlZw2L0jLsk1eGoB522WXQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /esbuild-windows-arm64/0.15.7: resolution: {integrity: sha512-R06nmqBlWjKHddhRJYlqDd3Fabx9LFdKcjoOy08YLimwmsswlFBJV4rXzZCxz/b7ZJXvrZgj8DDv1ewE9+StMw==} engines: {node: '>=12'} @@ -2436,6 +2633,36 @@ packages: esbuild-windows-arm64: 0.14.54 dev: true + /esbuild/0.15.18: + resolution: {integrity: sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/android-arm': 0.15.18 + '@esbuild/linux-loong64': 0.15.18 + esbuild-android-64: 0.15.18 + esbuild-android-arm64: 0.15.18 + esbuild-darwin-64: 0.15.18 + esbuild-darwin-arm64: 0.15.18 + esbuild-freebsd-64: 0.15.18 + esbuild-freebsd-arm64: 0.15.18 + esbuild-linux-32: 0.15.18 + esbuild-linux-64: 0.15.18 + esbuild-linux-arm: 0.15.18 + esbuild-linux-arm64: 0.15.18 + esbuild-linux-mips64le: 0.15.18 + esbuild-linux-ppc64le: 0.15.18 + esbuild-linux-riscv64: 0.15.18 + esbuild-linux-s390x: 0.15.18 + esbuild-netbsd-64: 0.15.18 + esbuild-openbsd-64: 0.15.18 + esbuild-sunos-64: 0.15.18 + esbuild-windows-32: 0.15.18 + esbuild-windows-64: 0.15.18 + esbuild-windows-arm64: 0.15.18 + dev: true + /esbuild/0.15.7: resolution: {integrity: sha512-7V8tzllIbAQV1M4QoE52ImKu8hT/NLGlGXkiDsbEU5PS6K8Mn09ZnYoS+dcmHxOS9CRsV4IRAMdT3I67IyUNXw==} engines: {node: '>=12'} @@ -2800,8 +3027,8 @@ packages: resolution: {integrity: sha512-DQmnRpLj7f6TgN/NYb0MTzJXL+vJF9h3pHy4JhCIs3zwcgez8xmGg3sXHcEO97BrmO2OSvCwMdfdlyl+E9KjOw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - acorn: 8.8.0 - acorn-jsx: 5.3.2_acorn@8.8.0 + acorn: 8.8.1 + acorn-jsx: 5.3.2_acorn@8.8.1 eslint-visitor-keys: 3.3.0 dev: true @@ -2940,6 +3167,11 @@ packages: dependencies: to-regex-range: 5.0.1 + /filter-obj/1.1.0: + resolution: {integrity: sha512-8rXg1ZnX7xzy2NGDVkBVaAy+lSlPNwad13BtgSlLuxfIslyt5Vg64U7tFcCt4WS1R0hvtnQybT/IyCkGZ3DpXQ==} + engines: {node: '>=0.10.0'} + dev: true + /find-up/5.0.0: resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==} engines: {node: '>=10'} @@ -3757,8 +3989,8 @@ packages: argparse: 2.0.1 dev: true - /jsdom/20.0.0: - resolution: {integrity: sha512-x4a6CKCgx00uCmP+QakBDFXwjAJ69IkkIWHmtmjd3wvXPcdOS44hfX2vqkOQrVrq8l9DhNNADZRXaCEWvgXtVA==} + /jsdom/20.0.3: + resolution: {integrity: sha512-SYhBvTh89tTfCD/CRdSOm13mOBa42iTaTyfyEWBdKcGdPxPtLFBXuHR8XHb33YNYaP+lLbmSvBTsnoesCNJEsQ==} engines: {node: '>=14'} peerDependencies: canvas: ^2.5.0 @@ -3767,12 +3999,12 @@ packages: optional: true dependencies: abab: 2.0.6 - acorn: 8.8.0 - acorn-globals: 6.0.0 + acorn: 8.8.1 + acorn-globals: 7.0.1 cssom: 0.5.0 cssstyle: 2.3.0 data-urls: 3.0.2 - decimal.js: 10.4.0 + decimal.js: 10.4.3 domexception: 4.0.0 escodegen: 2.0.0 form-data: 4.0.0 @@ -3785,13 +4017,12 @@ packages: saxes: 6.0.0 symbol-tree: 3.2.4 tough-cookie: 4.1.2 - w3c-hr-time: 1.0.2 - w3c-xmlserializer: 3.0.0 + w3c-xmlserializer: 4.0.0 webidl-conversions: 7.0.0 whatwg-encoding: 2.0.0 whatwg-mimetype: 3.0.0 whatwg-url: 11.0.0 - ws: 8.8.1 + ws: 8.11.0 xml-name-validator: 4.0.0 transitivePeerDependencies: - bufferutil @@ -4613,8 +4844,8 @@ packages: source-map-js: 1.0.2 dev: true - /postcss/8.4.16: - resolution: {integrity: sha512-ipHE1XBvKzm5xI7hiHCZJCSugxvsdq2mPnsq5+UF+VHCjiBvtDrlxJfMBToWaP9D5XlgNmcFGqoHmUn0EYEaRQ==} + /postcss/8.4.19: + resolution: {integrity: sha512-h+pbPsyhlYj6N2ozBmHhHrs9DzGmbaarbLvWipMRO7RLS+v4onj26MPFXA5OBYFxyqYhUJK456SwDcY9H2/zsA==} engines: {node: ^10 || ^12 || >=14} dependencies: nanoid: 3.3.4 @@ -4718,6 +4949,16 @@ packages: escape-goat: 4.0.0 dev: true + /query-string/7.1.3: + resolution: {integrity: sha512-hh2WYhq4fi8+b+/2Kg9CEge4fDPvHS534aOOvOZeQ3+Vf2mCFsaFBYj0i+iXcAq6I9Vzp5fjMFBlONvayDC1qg==} + engines: {node: '>=6'} + dependencies: + decode-uri-component: 0.2.2 + filter-obj: 1.1.0 + split-on-first: 1.1.0 + strict-uri-encode: 2.0.0 + dev: true + /querystringify/2.2.0: resolution: {integrity: sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==} dev: true @@ -4975,16 +5216,16 @@ packages: glob: 7.2.3 dev: true - /rollup/2.78.1: - resolution: {integrity: sha512-VeeCgtGi4P+o9hIg+xz4qQpRl6R401LWEXBmxYKOV4zlF82lyhgh2hTZnheFUbANE8l2A41F458iwj2vEYaXJg==} + /rollup/2.79.0: + resolution: {integrity: sha512-x4KsrCgwQ7ZJPcFA/SUu6QVcYlO7uRLfLAy0DSA4NS2eG8japdbpM50ToH7z4iObodRYOJ0soneF0iaQRJ6zhA==} engines: {node: '>=10.0.0'} hasBin: true optionalDependencies: fsevents: 2.3.2 dev: true - /rollup/2.79.0: - resolution: {integrity: sha512-x4KsrCgwQ7ZJPcFA/SUu6QVcYlO7uRLfLAy0DSA4NS2eG8japdbpM50ToH7z4iObodRYOJ0soneF0iaQRJ6zhA==} + /rollup/2.79.1: + resolution: {integrity: sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==} engines: {node: '>=10.0.0'} hasBin: true optionalDependencies: @@ -5158,7 +5399,6 @@ packages: engines: {node: '>=0.10.0'} requiresBuild: true dev: true - optional: true /source-map/0.8.0-beta.0: resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} @@ -5171,6 +5411,11 @@ packages: resolution: {integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==} dev: true + /split-on-first/1.1.0: + resolution: {integrity: sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==} + engines: {node: '>=6'} + dev: true + /statuses/2.0.1: resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} engines: {node: '>= 0.8'} @@ -5180,6 +5425,11 @@ packages: engines: {node: '>=10.0.0'} dev: false + /strict-uri-encode/2.0.0: + resolution: {integrity: sha512-QwiXZgpRcKkhTj2Scnn++4PKtWsH0kpzZ62L2R6c/LUVYv7hVnZqcg2+sMuT6R7Jusu1vviK/MFsu6kNJfWlEQ==} + engines: {node: '>=4'} + dev: true + /string-argv/0.3.1: resolution: {integrity: sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==} engines: {node: '>=0.6.19'} @@ -5284,7 +5534,13 @@ packages: /strip-literal/0.4.0: resolution: {integrity: sha512-ql/sBDoJOybTKSIOWrrh8kgUEMjXMwRAkZTD0EwiwxQH/6tTPkZvMIEjp0CRlpi6V5FMiJyvxeRkEi1KrGISoA==} dependencies: - acorn: 8.8.0 + acorn: 8.8.1 + dev: true + + /strip-literal/1.0.0: + resolution: {integrity: sha512-5o4LsH1lzBzO9UFH63AJ2ad2/S2AVx6NtjOcaz+VTT2h1RiRvbipW72z8M/lxEhcPHDBQwpDrnTF7sXy/7OwCQ==} + dependencies: + acorn: 8.8.1 dev: true /styled-jsx/5.0.6_react@18.2.0: @@ -5389,18 +5645,12 @@ packages: globrex: 0.1.2 dev: true - /tinybench/2.1.4: - resolution: {integrity: sha512-NFWIw2Gg7EUPdeE8nL1Dc7AMVlk7sOr2PmSNKVuQrZ0YwTOFoshPQ+hcLrgnhK8dTP3FWMCJaf4N+/hXp6lKPw==} - engines: {node: '>=16.0.0'} - dev: true - /tinybench/2.1.5: resolution: {integrity: sha512-ak+PZZEuH3mw6CCFOgf5S90YH0MARnZNhxjhjguAmoJimEMAJuNip/rJRd6/wyylHItomVpKTzZk9zrhTrQCoQ==} dev: true - /tinypool/0.2.4: - resolution: {integrity: sha512-Vs3rhkUH6Qq1t5bqtb816oT+HeJTXfwt2cbPH17sWHIYKTotQIFPk3tf2fgqRrVyMDVOc1EnPgzIxfIulXVzwQ==} - engines: {node: '>=14.0.0'} + /tinybench/2.3.1: + resolution: {integrity: sha512-hGYWYBMPr7p4g5IarQE7XhlyWveh1EKhy4wUBS1LrHXCKYgvz+4/jCqgmJqZxxldesn05vccrtME2RLLZNW7iA==} dev: true /tinypool/0.3.0: @@ -5446,10 +5696,10 @@ packages: dev: true /tr46/0.0.3: - resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/tr46/-/tr46-0.0.3.tgz} + resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} /tr46/1.0.1: - resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/tr46/-/tr46-1.0.1.tgz} + resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} dependencies: punycode: 2.1.1 dev: true @@ -5709,35 +5959,49 @@ packages: convert-source-map: 1.8.0 dev: true - /vite/3.1.0: - resolution: {integrity: sha512-YBg3dUicDpDWFCGttmvMbVyS9ydjntwEjwXRj2KBFwSB8SxmGcudo1yb8FW5+M/G86aS8x828ujnzUVdsLjs9g==} + /vi-fetch/0.8.0: + resolution: {integrity: sha512-uvEgEBTacSnlxRcoA56Drwkc2LbTvRNOdSx5MVayBfEsHAgQJAu+LwePlUOkidFsqQMcQxcb+LlC9qZ9v1yXiw==} + dependencies: + query-string: 7.1.3 + tinyspy: 1.0.2 + dev: true + + /vite/3.2.5_@types+node@18.7.15: + resolution: {integrity: sha512-4mVEpXpSOgrssFZAOmGIr85wPHKvaDAcXqxVxVRZhljkJOMZi1ibLibzjLHzJvcok8BMguLc7g1W6W/GqZbLdQ==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true peerDependencies: + '@types/node': '>= 14' less: '*' sass: '*' stylus: '*' + sugarss: '*' terser: ^5.4.0 peerDependenciesMeta: + '@types/node': + optional: true less: optional: true sass: optional: true stylus: optional: true + sugarss: + optional: true terser: optional: true dependencies: - esbuild: 0.15.7 - postcss: 8.4.16 + '@types/node': 18.7.15 + esbuild: 0.15.18 + postcss: 8.4.19 resolve: 1.22.1 - rollup: 2.78.1 + rollup: 2.79.1 optionalDependencies: fsevents: 2.3.2 dev: true - /vitest/0.23.1_jsdom@20.0.0: - resolution: {integrity: sha512-kn9pG+h6VA3yj/xRvwgLKEd33rOlzMqJEg3tl5HSm3WUPlkY1Lr1FK8RN1uIqVKvFxmz6HGU3EQW+xW2kazRkQ==} + /vitest/0.23.2_jsdom@20.0.3: + resolution: {integrity: sha512-kTBKp3ROPDkYC+x2zWt4znkDtnT08W1FQ6ngRFuqxpBGNuNVS+eWZKfffr8y2JGvEzZ9EzMAOcNaiqMj/FZqMw==} engines: {node: '>=v14.16.0'} hasBin: true peerDependencies: @@ -5763,23 +6027,24 @@ packages: '@types/node': 18.7.15 chai: 4.3.6 debug: 4.3.4 - jsdom: 20.0.0 + jsdom: 20.0.3 local-pkg: 0.4.2 strip-literal: 0.4.0 - tinybench: 2.1.4 - tinypool: 0.2.4 + tinybench: 2.1.5 + tinypool: 0.3.0 tinyspy: 1.0.2 - vite: 3.1.0 + vite: 3.2.5_@types+node@18.7.15 transitivePeerDependencies: - less - sass - stylus + - sugarss - supports-color - terser dev: true - /vitest/0.23.2_jsdom@20.0.0: - resolution: {integrity: sha512-kTBKp3ROPDkYC+x2zWt4znkDtnT08W1FQ6ngRFuqxpBGNuNVS+eWZKfffr8y2JGvEzZ9EzMAOcNaiqMj/FZqMw==} + /vitest/0.25.6_jsdom@20.0.3: + resolution: {integrity: sha512-jdPgmZ7BcDnm1+hmMPIl9BZjSy+b8Y8V0tQMsv7ECO90Qic7EZ5/+traILXLpsXgqK5KgVrUJmchevAUuKL/1w==} engines: {node: '>=v14.16.0'} hasBin: true peerDependencies: @@ -5803,19 +6068,23 @@ packages: '@types/chai': 4.3.3 '@types/chai-subset': 1.3.3 '@types/node': 18.7.15 + acorn: 8.8.0 + acorn-walk: 8.2.0 chai: 4.3.6 debug: 4.3.4 - jsdom: 20.0.0 + jsdom: 20.0.3 local-pkg: 0.4.2 - strip-literal: 0.4.0 - tinybench: 2.1.5 + source-map: 0.6.1 + strip-literal: 1.0.0 + tinybench: 2.3.1 tinypool: 0.3.0 tinyspy: 1.0.2 - vite: 3.1.0 + vite: 3.2.5_@types+node@18.7.15 transitivePeerDependencies: - less - sass - stylus + - sugarss - supports-color - terser dev: true @@ -5825,19 +6094,13 @@ packages: engines: {node: '>=6.0'} hasBin: true dependencies: - acorn: 8.8.0 + acorn: 8.8.1 acorn-walk: 8.2.0 dev: true - /w3c-hr-time/1.0.2: - resolution: {integrity: sha512-z8P5DvDNjKDoFIHK7q8r8lackT6l+jo/Ye3HOle7l9nICP9lf1Ci25fy9vHd0JOWewkIFzXIEig3TdKT7JQ5fQ==} - dependencies: - browser-process-hrtime: 1.0.0 - dev: true - - /w3c-xmlserializer/3.0.0: - resolution: {integrity: sha512-3WFqGEgSXIyGhOmAFtlicJNMjEps8b1MG31NCA0/vOF9+nKMUW1ckhi9cnNHmf88Rzw5V+dwIwsm2C7X8k9aQg==} - engines: {node: '>=12'} + /w3c-xmlserializer/4.0.0: + resolution: {integrity: sha512-d+BFHzbiCx6zGfz0HyQ6Rg69w9k19nviJspaj4yNscGjrHu94sVP+aRm75yEbCh+r2/yR+7q6hux9LVtbuTGBw==} + engines: {node: '>=14'} dependencies: xml-name-validator: 4.0.0 dev: true @@ -5854,10 +6117,10 @@ packages: dev: true /webidl-conversions/3.0.1: - resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz} + resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} /webidl-conversions/4.0.2: - resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz} + resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} dev: true /webidl-conversions/7.0.0: @@ -5892,7 +6155,7 @@ packages: webidl-conversions: 3.0.1 /whatwg-url/7.1.0: - resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.com/whatwg-url/-/whatwg-url-7.1.0.tgz} + resolution: {integrity: sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==} dependencies: lodash.sortby: 4.7.0 tr46: 1.0.1 @@ -5980,8 +6243,8 @@ packages: typedarray-to-buffer: 3.1.5 dev: true - /ws/8.8.1: - resolution: {integrity: sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==} + /ws/8.11.0: + resolution: {integrity: sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==} engines: {node: '>=10.0.0'} peerDependencies: bufferutil: ^4.0.1 diff --git a/src/app-bridge/fetch.test.ts b/src/app-bridge/fetch.test.ts new file mode 100644 index 00000000..16aac979 --- /dev/null +++ b/src/app-bridge/fetch.test.ts @@ -0,0 +1,68 @@ +import { describe, expect, it, vi } from "vitest"; + +import { SALEOR_AUTHORIZATION_BEARER_HEADER, SALEOR_DOMAIN_HEADER } from "../const"; +import { AppBridge } from "./app-bridge"; +import { AppBridgeState } from "./app-bridge-state"; +import { createAuthenticatedFetch } from "./fetch"; + +describe("createAuthenticatedFetch", () => { + const mockedAppBridge: Pick = { + getState(): AppBridgeState { + return { + domain: "master.staging.saleor.cloud", + token: "XXX_YYY", + locale: "pl", + path: "/", + ready: true, + theme: "light", + saleorApiUrl: "https://master.staging.saleor.cloud/graphql/", + id: "xyz1234", + }; + }, + }; + + it("Decorates request headers with AppBridge headers", async () => { + const spiedFetch = vi.spyOn(global, "fetch"); + + const fetchFn = createAuthenticatedFetch(mockedAppBridge); + + try { + await fetchFn("/api/test"); + } catch (e) { + // ignore + } + + const fetchCallArguments = spiedFetch.mock.lastCall; + const fetchCallHeaders = fetchCallArguments![1]?.headers; + + expect((fetchCallHeaders as Headers).get(SALEOR_DOMAIN_HEADER)).toBe( + "master.staging.saleor.cloud" + ); + expect((fetchCallHeaders as Headers).get(SALEOR_AUTHORIZATION_BEARER_HEADER)).toBe("XXX_YYY"); + }); + + it("Extends existing fetch config", async () => { + const spiedFetch = vi.spyOn(global, "fetch"); + + const fetchFn = createAuthenticatedFetch(mockedAppBridge); + + try { + await fetchFn("/api/test", { + headers: { + foo: "bar", + }, + }); + } catch (e) { + // ignore + } + + const fetchCallArguments = spiedFetch.mock.lastCall; + const fetchCallHeaders = fetchCallArguments![1]?.headers; + + expect((fetchCallHeaders as Headers).get(SALEOR_DOMAIN_HEADER)).toBe( + "master.staging.saleor.cloud" + ); + expect((fetchCallHeaders as Headers).get(SALEOR_AUTHORIZATION_BEARER_HEADER)).toBe("XXX_YYY"); + expect((fetchCallHeaders as Headers).get("foo")).toBe("bar"); + }); +}); diff --git a/src/app-bridge/fetch.ts b/src/app-bridge/fetch.ts new file mode 100644 index 00000000..b2763b05 --- /dev/null +++ b/src/app-bridge/fetch.ts @@ -0,0 +1,38 @@ +import { SALEOR_AUTHORIZATION_BEARER_HEADER, SALEOR_DOMAIN_HEADER } from "../const"; +import { AppBridge } from "./app-bridge"; +import { useAppBridge } from "./app-bridge-provider"; + +type HasAppBridgeState = Pick; + +/** + * Created decorated window.fetch with headers required by app-sdk Next api handlers utilities + */ +export const createAuthenticatedFetch = + (appBridge: HasAppBridgeState, fetch = global.fetch): typeof global.fetch => + (input, init) => { + const { token, domain } = appBridge.getState(); + + const headers = new Headers(init?.headers); + headers.set(SALEOR_DOMAIN_HEADER, domain); + headers.set(SALEOR_AUTHORIZATION_BEARER_HEADER, token ?? ""); + + const clonedInit: RequestInit = { + ...(init ?? {}), + headers, + }; + + return fetch(input, clonedInit); + }; + +/** + * Hook working only in browser context. Ensure parent component is dynamic() and mounted in the browser. + */ +export const useAuthenticatedFetch = (fetch = global.fetch) => { + const { appBridge } = useAppBridge(); + + if (!appBridge) { + throw new Error("useAuthenticatedFetch can be used only in browser context"); + } + + return createAuthenticatedFetch(appBridge, fetch); +}; diff --git a/src/app-bridge/index.ts b/src/app-bridge/index.ts index 33b69255..c3a1e013 100644 --- a/src/app-bridge/index.ts +++ b/src/app-bridge/index.ts @@ -6,6 +6,7 @@ export * from "./actions"; export * from "./app-bridge-provider"; export * from "./app-iframe-params"; export * from "./events"; +export * from "./fetch"; export * from "./types"; export * from "./use-dashboard-token"; export * from "./with-authorization"; diff --git a/src/setup-tests.ts b/src/setup-tests.ts index e69de29b..e6976ed9 100644 --- a/src/setup-tests.ts +++ b/src/setup-tests.ts @@ -0,0 +1 @@ +import "vi-fetch/setup";