diff --git a/package.json b/package.json index 02b5443..cdb0977 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "@socialgouv/matomo-next": "^1.2.2", "@types/mdx": "^2.0.10", "chart.js": "^4.4.2", - "data-forge": "^1.10.2", "date-fns": "^3.0.6", "fs": "^0.0.1-security", "fs-extra": "^11.2.0", @@ -19,7 +18,6 @@ "next": "13.1.6", "next-compose-plugins": "^2.2.1", "next-mdx-remote": "^4.4.1", - "node-fetch": "^3.3.2", "react": "18.2.0", "react-device-detect": "^2.2.3", "react-dom": "18.2.0", diff --git a/pages/api/metabase.js b/pages/api/metabase.js deleted file mode 100644 index 7d816b9..0000000 --- a/pages/api/metabase.js +++ /dev/null @@ -1,67 +0,0 @@ -import { DataFrame } from "data-forge" -import fetch from "node-fetch" - -export default async function metabase(req, res) { - try { - const questionIndex = req.query.question - const sessionResponse = await fetch( - "https://metabase-ozensemble.fabrique.social.gouv.fr/api/session", - { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - username: process.env.METABASE_ACCOUNT, - password: process.env.METABASE_PASSWORD, - }), - } - ) - - if (!sessionResponse.ok) { - throw new Error("Failed to authenticate with Metabase") - } - - const { id: session_id } = await sessionResponse.json() - const headers = { "X-Metabase-Session": session_id } - - const cardResponse = await fetch( - "https://metabase-ozensemble.fabrique.social.gouv.fr/api/card", - { - headers, - } - ) - - if (!cardResponse.ok) { - throw new Error("Failed to fetch cards from Metabase") - } - - const cardData = await cardResponse.json() - const questions = cardData.filter((q) => q.public_uuid) - - if (questionIndex < 0 || questionIndex >= questions.length) { - throw new Error("Invalid question index") - } - - const uuid = questions[questionIndex].public_uuid - - const queryResponse = await fetch( - `https://metabase-ozensemble.fabrique.social.gouv.fr/api/public/card/${uuid}/query`, - { - headers, - } - ) - - if (!queryResponse.ok) { - throw new Error("Failed to fetch query result from Metabase") - } - - const { - data: { rows }, - } = await queryResponse.json() - const df = new DataFrame(rows) - - res.status(200).json({ result: df.toJSON() }) - } catch (error) { - console.error(error) - res.status(500).json({ error: "Internal Server Error" }) - } -} diff --git a/pages/stats.js b/pages/stats.js index 47fb6bc..46e5b54 100644 --- a/pages/stats.js +++ b/pages/stats.js @@ -22,13 +22,17 @@ const Stats = () => { useEffect(() => { const fetchData = async () => { try { - const response = await fetch("/api/metabase?question=0") + const response = await fetch( + "http://localhost:3615/public/metabase?question=0" + ) const responseData = await response.json() const data = JSON.parse(responseData.result) setResult(data) - const response2 = await fetch("/api/metabase?question=1") + const response2 = await fetch( + "http://localhost:3615/public/metabase?question=1" + ) const responseData2 = await response2.json() const data2 = JSON.parse(responseData2.result) @@ -159,7 +163,7 @@ const Stats = () => { Date - Value + Nombre d'utilisateurs @@ -212,7 +216,7 @@ const Stats = () => { Date - Value + Nombre d'utilisateurs diff --git a/yarn.lock b/yarn.lock index de4d932..4a3129d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -463,13 +463,6 @@ __metadata: languageName: node linkType: hard -"@data-forge/serialization@npm:^1.0.0": - version: 1.0.1 - resolution: "@data-forge/serialization@npm:1.0.1" - checksum: d0fa79a20aa4ff6bfbf6fc3beb3ae7b09b12a4a28dad10418992c65fed0a7c7d601a11361589735ff78b96159168d78f5134aafd8beb1f8e78d0e310df54c0f7 - languageName: node - linkType: hard - "@emotion/babel-plugin@npm:^11.10.5": version: 11.10.5 resolution: "@emotion/babel-plugin@npm:11.10.5" @@ -2720,28 +2713,6 @@ __metadata: languageName: node linkType: hard -"data-forge@npm:^1.10.2": - version: 1.10.2 - resolution: "data-forge@npm:1.10.2" - dependencies: - "@data-forge/serialization": ^1.0.0 - dayjs: ^1.8.12 - easy-table: 1.1.0 - json5: ^2.1.0 - numeral: ^2.0.6 - papaparse: 5.2.0 - typy: ^3.0.1 - checksum: e4a86ef79aa7c2db99a44e453c033cc64a2d4911b10e0283e6744048071619c87b4b17b0fa70c9d7340cfbe4da20d01a652111356cc598394a61a42b3eea9239 - languageName: node - linkType: hard - -"data-uri-to-buffer@npm:^4.0.0": - version: 4.0.1 - resolution: "data-uri-to-buffer@npm:4.0.1" - checksum: 0d0790b67ffec5302f204c2ccca4494f70b4e2d940fea3d36b09f0bb2b8539c2e86690429eb1f1dc4bcc9e4df0644193073e63d9ee48ac9fce79ec1506e4aa4c - languageName: node - linkType: hard - "data-urls@npm:^2.0.0": version: 2.0.0 resolution: "data-urls@npm:2.0.0" @@ -2760,13 +2731,6 @@ __metadata: languageName: node linkType: hard -"dayjs@npm:^1.8.12": - version: 1.11.10 - resolution: "dayjs@npm:1.11.10" - checksum: a6b5a3813b8884f5cd557e2e6b7fa569f4c5d0c97aca9558e38534af4f2d60daafd3ff8c2000fed3435cfcec9e805bcebd99f90130c6d1c5ef524084ced588c4 - languageName: node - linkType: hard - "debug@npm:4, debug@npm:^4.0.0, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.4": version: 4.3.4 resolution: "debug@npm:4.3.4" @@ -3009,18 +2973,6 @@ __metadata: languageName: node linkType: hard -"easy-table@npm:1.1.0": - version: 1.1.0 - resolution: "easy-table@npm:1.1.0" - dependencies: - wcwidth: ">=1.0.1" - dependenciesMeta: - wcwidth: - optional: true - checksum: 49b960fefe5670076773824386f22070dce185ebc0a99542035496700cc39a0b9346f65fd4307f5fe3dbbe7e6d9c4b59966e77e32f915e0fe71de71c3d0efcf7 - languageName: node - linkType: hard - "electron-to-chromium@npm:^1.4.251": version: 1.4.284 resolution: "electron-to-chromium@npm:1.4.284" @@ -3821,16 +3773,6 @@ __metadata: languageName: node linkType: hard -"fetch-blob@npm:^3.1.2, fetch-blob@npm:^3.1.4": - version: 3.2.0 - resolution: "fetch-blob@npm:3.2.0" - dependencies: - node-domexception: ^1.0.0 - web-streams-polyfill: ^3.0.3 - checksum: f19bc28a2a0b9626e69fd7cf3a05798706db7f6c7548da657cbf5026a570945f5eeaedff52007ea35c8bcd3d237c58a20bf1543bc568ab2422411d762dd3d5bf - languageName: node - linkType: hard - "file-entry-cache@npm:^6.0.1": version: 6.0.1 resolution: "file-entry-cache@npm:6.0.1" @@ -3932,15 +3874,6 @@ __metadata: languageName: node linkType: hard -"formdata-polyfill@npm:^4.0.10": - version: 4.0.10 - resolution: "formdata-polyfill@npm:4.0.10" - dependencies: - fetch-blob: ^3.1.2 - checksum: 82a34df292afadd82b43d4a740ce387bc08541e0a534358425193017bf9fb3567875dc5f69564984b1da979979b70703aa73dee715a17b6c229752ae736dd9db - languageName: node - linkType: hard - "fraction.js@npm:^4.2.0": version: 4.2.0 resolution: "fraction.js@npm:4.2.0" @@ -5820,7 +5753,7 @@ __metadata: languageName: node linkType: hard -"json5@npm:^2.1.0, json5@npm:^2.2.2": +"json5@npm:^2.2.2": version: 2.2.3 resolution: "json5@npm:2.2.3" bin: @@ -7004,24 +6937,6 @@ __metadata: languageName: node linkType: hard -"node-domexception@npm:^1.0.0": - version: 1.0.0 - resolution: "node-domexception@npm:1.0.0" - checksum: ee1d37dd2a4eb26a8a92cd6b64dfc29caec72bff5e1ed9aba80c294f57a31ba4895a60fd48347cf17dd6e766da0ae87d75657dfd1f384ebfa60462c2283f5c7f - languageName: node - linkType: hard - -"node-fetch@npm:^3.3.2": - version: 3.3.2 - resolution: "node-fetch@npm:3.3.2" - dependencies: - data-uri-to-buffer: ^4.0.0 - fetch-blob: ^3.1.4 - formdata-polyfill: ^4.0.10 - checksum: 06a04095a2ddf05b0830a0d5302699704d59bda3102894ea64c7b9d4c865ecdff2d90fd042df7f5bc40337266961cb6183dcc808ea4f3000d024f422b462da92 - languageName: node - linkType: hard - "node-gyp@npm:latest": version: 10.0.1 resolution: "node-gyp@npm:10.0.1" @@ -7134,13 +7049,6 @@ __metadata: languageName: node linkType: hard -"numeral@npm:^2.0.6": - version: 2.0.6 - resolution: "numeral@npm:2.0.6" - checksum: 89f011116539692bf53fde380adeb0579623d00f782703c71c0062d4a8686770c404a041ff4eef454de53925a9f75bba1fa52726057b13d40473f707730b07c2 - languageName: node - linkType: hard - "nwsapi@npm:^2.2.0": version: 2.2.2 resolution: "nwsapi@npm:2.2.2" @@ -7336,7 +7244,6 @@ __metadata: "@types/mdx": ^2.0.10 autoprefixer: ^10.4.13 chart.js: ^4.4.2 - data-forge: ^1.10.2 date-fns: ^3.0.6 eslint: ^7.32.0 fs: ^0.0.1-security @@ -7346,7 +7253,6 @@ __metadata: next: 13.1.6 next-compose-plugins: ^2.2.1 next-mdx-remote: ^4.4.1 - node-fetch: ^3.3.2 postcss: ^8.4.21 prettier: ^2.4.1 react: 18.2.0 @@ -7407,13 +7313,6 @@ __metadata: languageName: node linkType: hard -"papaparse@npm:5.2.0": - version: 5.2.0 - resolution: "papaparse@npm:5.2.0" - checksum: eda69fae5bd0fb05d01bdccd2cc5f38b668a32b2cc75d9d3c7a41cf5a39434dab85dfe5784ba29fdc212b12c626a47c729feba92393867fbd0f109b16d802bf0 - languageName: node - linkType: hard - "parent-module@npm:^1.0.0": version: 1.0.1 resolution: "parent-module@npm:1.0.1" @@ -9212,13 +9111,6 @@ __metadata: languageName: node linkType: hard -"typy@npm:^3.0.1": - version: 3.3.0 - resolution: "typy@npm:3.3.0" - checksum: 409529672989a6281a56810f5a0be3256ceccb8e73166a9344da53713b935ad036ca10fe702240e55ff0265e2e1a09c19d74b5dd10ce2366759027d24fa0089b - languageName: node - linkType: hard - "ua-parser-js@npm:^1.0.33": version: 1.0.37 resolution: "ua-parser-js@npm:1.0.37" @@ -9640,7 +9532,7 @@ __metadata: languageName: node linkType: hard -"wcwidth@npm:>=1.0.1, wcwidth@npm:^1.0.1": +"wcwidth@npm:^1.0.1": version: 1.0.1 resolution: "wcwidth@npm:1.0.1" dependencies: @@ -9656,13 +9548,6 @@ __metadata: languageName: node linkType: hard -"web-streams-polyfill@npm:^3.0.3": - version: 3.3.3 - resolution: "web-streams-polyfill@npm:3.3.3" - checksum: 21ab5ea08a730a2ef8023736afe16713b4f2023ec1c7085c16c8e293ee17ed085dff63a0ad8722da30c99c4ccbd4ccd1b2e79c861829f7ef2963d7de7004c2cb - languageName: node - linkType: hard - "webidl-conversions@npm:^5.0.0": version: 5.0.0 resolution: "webidl-conversions@npm:5.0.0"