From c01c96aa1a76b1af904745356554430915c92e88 Mon Sep 17 00:00:00 2001 From: Korey Sedaghatian Date: Sat, 4 May 2024 15:46:28 -0400 Subject: [PATCH] Added reset method Added way to know if accounts request received 401 Enabled storage of token only when checkbox is checked. --- README.md | 2 +- package.json | 8 +++-- src/App.tsx | 17 +++++---- src/lib/apiService.ts | 27 +++++++++----- yarn.lock | 84 ++++++++++++++++++++++++++++++++++++++----- 5 files changed, 111 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b676ca3..08127d6 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ Note: These instructions are for a docker installation but should hopefully be c 9. Browse to the application: `https:///ofx` and you should be prompted to input a token. 10. (Optional) You can bookmark or add this URL to whatever dashboard you are using for future use. 11. Enter you PAT into the text box and hit the tab key.\ - Note: Right now the checkbox below the input field does not work but a future version will allow you not to store the token locally (i.e. you would have to enter the token each time you use the app if you do not save it). + Note: If you do not want to enter your PAT each time, make sure to check `Store token for next time`. 12. You should be ready to drop an OFX file and get importing. diff --git a/package.json b/package.json index c8affb1..b11fb69 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ff3-ofx", - "version": "0.4.2", + "version": "0.5.0", "homepage": "./", "private": true, "licenses": [ @@ -19,8 +19,10 @@ "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^13.0.0", "@testing-library/user-event": "^13.2.1", + "axios": "^1.6.8", + "moment": "^2.30.1", "mui-file-dropzone": "^4.0.2", - "ofx-data-extractor": "^1.3.4", + "node-ofx-parser": "^0.5.1", "prop-types": "^15.8.1", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -34,7 +36,7 @@ "package": "yarn compile && yarn dist", "test": "react-scripts test", "eject": "react-scripts eject", - "clean": "rm -rf ./node_modules ./build/*" + "clean": "rm -rf ./node_modules ./build" }, "eslintConfig": { "extends": [ diff --git a/src/App.tsx b/src/App.tsx index 1f13528..d9bcdb4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -51,15 +51,18 @@ function App() { setAccounts(accntResponse); // If we got accounts back, then store the token if (currentToken && currentToken.value) { - localStorage.setItem('token', JSON.stringify(currentToken)); + if ((document.getElementById('chkStoreToken') as HTMLInputElement)?.checked) { // Only store the token if user requested + localStorage.setItem('token', JSON.stringify(currentToken)); + } setToken(currentToken); } - } else { + } else if (accntResponse === null) { // If the response is null, that means we got an unauthorized response // Delete localstorage - // localStorage.removeItem('token'); - // if (currentToken && (!token || !token.value)) { - // setToken(undefined); - // } + localStorage.removeItem('token'); + if (currentToken && (!token || !token.value)) { + setToken(undefined); + } + ApiService.reset(); } }).catch(e => { console.log('could not get accounts', e); @@ -385,7 +388,7 @@ function App() { }} />
- } label="Store Token for next time" /> + } label="Store Token for next time" /> diff --git a/src/lib/apiService.ts b/src/lib/apiService.ts index ba091d3..6856b2a 100644 --- a/src/lib/apiService.ts +++ b/src/lib/apiService.ts @@ -13,6 +13,10 @@ const exceptionHandling = { let myHttpClient: AxiosInstance | undefined; +const reset = () => { + myHttpClient = undefined; +} + const getHttp = (token?: string| null) => { if (token === null) { myHttpClient = undefined; @@ -31,9 +35,11 @@ const getHttp = (token?: string| null) => { return myHttpClient; } -const getAccounts = async(currentToken?: string): Promise[]> => { - // This is useful for debugging request/response - // http.interceptors.request.use( +const getAccounts = async(currentToken?: string): Promise[] | null> => { + const http = getHttp(currentToken); + + // // This is useful for debugging request/response + // http?.interceptors.request.use( // request => { // console.log('Starting Request', JSON.stringify(request, null, 2)); // return request; @@ -43,7 +49,7 @@ const getAccounts = async(currentToken?: string): Promise // return Promise.reject(error); // }, // ); - // http.interceptors.response.use( + // http?.interceptors.response.use( // response => { // console.log('Receiving Response', JSON.stringify(response, null, 2)); // return response; @@ -53,11 +59,15 @@ const getAccounts = async(currentToken?: string): Promise // return Promise.reject(error); // }, // ); - const http = getHttp(currentToken); + const response = await http?.get('/accounts', exceptionHandling); - if (response && response.status === 200 && response.data.data) { - return response.data.data; - } + if (response && response.status) { + if (response.status === 200 && response.data.data) { + return response.data.data; + } else if (response.status === 401) { + return null; + } + } // Return an empty array otherwise return []; @@ -121,6 +131,7 @@ const addTransaction = async (txn: FF3AddTransactionWrapper }; const ApiService = { + reset, getHttp, getAccounts, getAccount, diff --git a/yarn.lock b/yarn.lock index f067c3b..3f83ec9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4339,6 +4339,17 @@ __metadata: languageName: node linkType: hard +"axios@npm:^1.6.8": + version: 1.6.8 + resolution: "axios@npm:1.6.8" + dependencies: + follow-redirects: "npm:^1.15.6" + form-data: "npm:^4.0.0" + proxy-from-env: "npm:^1.1.0" + checksum: 10c0/0f22da6f490335479a89878bc7d5a1419484fbb437b564a80c34888fc36759ae4f56ea28d55a191695e5ed327f0bad56e7ff60fb6770c14d1be6501505d47ab9 + languageName: node + linkType: hard + "axobject-query@npm:^3.2.1": version: 3.2.1 resolution: "axobject-query@npm:3.2.1" @@ -6737,6 +6748,17 @@ __metadata: languageName: node linkType: hard +"fast-xml-parser@npm:^3.18.0": + version: 3.21.1 + resolution: "fast-xml-parser@npm:3.21.1" + dependencies: + strnum: "npm:^1.0.4" + bin: + xml2js: cli.js + checksum: 10c0/26ed57fd3cb86434959cffa6852ab63231850ff5be6836aef7744b1abc8013fa5696c05179e422965677e116606611242d91ceebf246d91a5247e262d8b59996 + languageName: node + linkType: hard + "fastq@npm:^1.6.0": version: 1.17.0 resolution: "fastq@npm:1.17.0" @@ -6778,9 +6800,11 @@ __metadata: "@testing-library/jest-dom": "npm:^5.14.1" "@testing-library/react": "npm:^13.0.0" "@testing-library/user-event": "npm:^13.2.1" + axios: "npm:^1.6.8" eslint: "npm:^8.18.0" + moment: "npm:^2.30.1" mui-file-dropzone: "npm:^4.0.2" - ofx-data-extractor: "npm:^1.3.4" + node-ofx-parser: "npm:^0.5.1" prop-types: "npm:^15.8.1" react: "npm:^18.2.0" react-dom: "npm:^18.2.0" @@ -6935,6 +6959,16 @@ __metadata: languageName: node linkType: hard +"follow-redirects@npm:^1.15.6": + version: 1.15.6 + resolution: "follow-redirects@npm:1.15.6" + peerDependenciesMeta: + debug: + optional: true + checksum: 10c0/9ff767f0d7be6aa6870c82ac79cf0368cd73e01bbc00e9eb1c2a16fbb198ec105e3c9b6628bb98e9f3ac66fe29a957b9645bcb9a490bb7aa0d35f908b6b85071 + languageName: node + linkType: hard + "for-each@npm:^0.3.3": version: 0.3.3 resolution: "for-each@npm:0.3.3" @@ -6996,6 +7030,17 @@ __metadata: languageName: node linkType: hard +"form-data@npm:^4.0.0": + version: 4.0.0 + resolution: "form-data@npm:4.0.0" + dependencies: + asynckit: "npm:^0.4.0" + combined-stream: "npm:^1.0.8" + mime-types: "npm:^2.1.12" + checksum: 10c0/cb6f3ac49180be03ff07ba3ff125f9eba2ff0b277fb33c7fc47569fc5e616882c5b1c69b9904c4c4187e97dd0419dd03b134174756f296dec62041e6527e2c6e + languageName: node + linkType: hard + "forwarded@npm:0.2.0": version: 0.2.0 resolution: "forwarded@npm:0.2.0" @@ -9666,6 +9711,13 @@ __metadata: languageName: node linkType: hard +"moment@npm:^2.30.1": + version: 2.30.1 + resolution: "moment@npm:2.30.1" + checksum: 10c0/865e4279418c6de666fca7786607705fd0189d8a7b7624e2e56be99290ac846f90878a6f602e34b4e0455c549b85385b1baf9966845962b313699e7cb847543a + languageName: node + linkType: hard + "ms@npm:2.0.0": version: 2.0.0 resolution: "ms@npm:2.0.0" @@ -9808,6 +9860,15 @@ __metadata: languageName: node linkType: hard +"node-ofx-parser@npm:^0.5.1": + version: 0.5.1 + resolution: "node-ofx-parser@npm:0.5.1" + dependencies: + fast-xml-parser: "npm:^3.18.0" + checksum: 10c0/96a8427bdc3895c03e928341d572ff2eb26a7389fa92b6fe250d0a63dc1d178fbff3f4dff94cf5bddf5a28ead8e109b0c79ecba47152295a69a4df77a0e5dd91 + languageName: node + linkType: hard + "node-releases@npm:^2.0.14": version: 2.0.14 resolution: "node-releases@npm:2.0.14" @@ -10006,13 +10067,6 @@ __metadata: languageName: node linkType: hard -"ofx-data-extractor@npm:^1.3.4": - version: 1.3.4 - resolution: "ofx-data-extractor@npm:1.3.4" - checksum: 10c0/7acc4bc5bb734c280fd86b43e2cc2c471c306f5cc02a3e39c50eb701eca0a7d01122911df90144c606d56dcedc9b6ca4dc7ede157d67ad5a80c53b458f9f81f5 - languageName: node - linkType: hard - "on-finished@npm:2.4.1": version: 2.4.1 resolution: "on-finished@npm:2.4.1" @@ -11301,6 +11355,13 @@ __metadata: languageName: node linkType: hard +"proxy-from-env@npm:^1.1.0": + version: 1.1.0 + resolution: "proxy-from-env@npm:1.1.0" + checksum: 10c0/fe7dd8b1bdbbbea18d1459107729c3e4a2243ca870d26d34c2c1bcd3e4425b7bcc5112362df2d93cc7fb9746f6142b5e272fd1cc5c86ddf8580175186f6ad42b + languageName: node + linkType: hard + "psl@npm:^1.1.33": version: 1.9.0 resolution: "psl@npm:1.9.0" @@ -12715,6 +12776,13 @@ __metadata: languageName: node linkType: hard +"strnum@npm:^1.0.4": + version: 1.0.5 + resolution: "strnum@npm:1.0.5" + checksum: 10c0/64fb8cc2effbd585a6821faa73ad97d4b553c8927e49086a162ffd2cc818787643390b89d567460a8e74300148d11ac052e21c921ef2049f2987f4b1b89a7ff1 + languageName: node + linkType: hard + "style-loader@npm:^3.3.1": version: 3.3.4 resolution: "style-loader@npm:3.3.4"