From ea89511ecddca9ced3c7fa191b6572c20dfb378c Mon Sep 17 00:00:00 2001 From: Andy Low <42089621+AndyLow91@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:06:16 +0000 Subject: [PATCH 1/8] Using Cookies --- package-lock.json | 199 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 3 + src/index.ts | 49 ++++++++++-- 3 files changed, 233 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32d19f8..8f7fd21 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,10 @@ "license": "MIT", "dependencies": { "axios": "^1.6.8", + "axios-cookiejar-support": "^5.0.0", "axios-mock-adapter": "^1.22.0", "node-cron": "3.0.3", + "tough-cookie": "^4.1.3", "winston": "^3.13.0" }, "devDependencies": { @@ -19,6 +21,7 @@ "@types/jest": "^29.5.12", "@types/node": "^20.11.30", "@types/node-cron": "^3.0.11", + "@types/tough-cookie": "^4.0.5", "@typescript-eslint/eslint-plugin": "^7.4.0", "@typescript-eslint/parser": "^7.4.0", "eslint": "^8.57.0", @@ -1442,6 +1445,12 @@ "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "node_modules/@types/tough-cookie": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", + "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==", + "dev": true + }, "node_modules/@types/triple-beam": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", @@ -1712,6 +1721,17 @@ "node": ">=0.4.0" } }, + "node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -1833,6 +1853,24 @@ "proxy-from-env": "^1.1.0" } }, + "node_modules/axios-cookiejar-support": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/axios-cookiejar-support/-/axios-cookiejar-support-5.0.0.tgz", + "integrity": "sha512-4zdO95qgsKp0OX+LUwD0MRWdD0r5YsQBpTi3ULHLL87qU58QZl3O3UQF58fZTzcdGtxYPtcotyXT7sNWDE37ug==", + "dependencies": { + "http-cookie-agent": "^6.0.1" + }, + "engines": { + "node": ">=18.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/3846masa" + }, + "peerDependencies": { + "axios": ">=0.20.0", + "tough-cookie": ">=4.0.0" + } + }, "node_modules/axios-mock-adapter": { "version": "1.22.0", "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", @@ -2256,7 +2294,6 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -2964,6 +3001,33 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "node_modules/http-cookie-agent": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/http-cookie-agent/-/http-cookie-agent-6.0.1.tgz", + "integrity": "sha512-AhPCqG7i3K8OVWORyuULoP7/Xv90wf14jBAKyLqjKpaJyGjutiwryYV+Lj1jqPYnQtbQFimwSaeY7NXw22TckQ==", + "dependencies": { + "agent-base": "^7.1.0" + }, + "engines": { + "node": ">=18.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/3846masa" + }, + "peerDependencies": { + "deasync": "^0.1.26", + "tough-cookie": "^4.0.0", + "undici": "^5.11.0 || ^6.0.0" + }, + "peerDependenciesMeta": { + "deasync": { + "optional": true + }, + "undici": { + "optional": true + } + } + }, "node_modules/human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -4413,11 +4477,15 @@ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, + "node_modules/psl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" + }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true, "engines": { "node": ">=6" } @@ -4438,6 +4506,11 @@ } ] }, + "node_modules/querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -4486,6 +4559,11 @@ "node": ">=0.10.0" } }, + "node_modules/requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" + }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -4618,9 +4696,9 @@ } }, "node_modules/semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", "dev": true, "dependencies": { "lru-cache": "^6.0.0" @@ -4889,6 +4967,20 @@ "node": ">=8.0" } }, + "node_modules/tough-cookie": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", + "dependencies": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/triple-beam": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", @@ -5047,6 +5139,14 @@ "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "dev": true }, + "node_modules/universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==", + "engines": { + "node": ">= 4.0.0" + } + }, "node_modules/update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", @@ -5086,6 +5186,15 @@ "punycode": "^2.1.0" } }, + "node_modules/url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dependencies": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -6408,6 +6517,12 @@ "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", "dev": true }, + "@types/tough-cookie": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", + "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==", + "dev": true + }, "@types/triple-beam": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.5.tgz", @@ -6574,6 +6689,14 @@ "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", "dev": true }, + "agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "requires": { + "debug": "^4.3.4" + } + }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -6666,6 +6789,14 @@ "proxy-from-env": "^1.1.0" } }, + "axios-cookiejar-support": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/axios-cookiejar-support/-/axios-cookiejar-support-5.0.0.tgz", + "integrity": "sha512-4zdO95qgsKp0OX+LUwD0MRWdD0r5YsQBpTi3ULHLL87qU58QZl3O3UQF58fZTzcdGtxYPtcotyXT7sNWDE37ug==", + "requires": { + "http-cookie-agent": "^6.0.1" + } + }, "axios-mock-adapter": { "version": "1.22.0", "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", @@ -6987,7 +7118,6 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, "requires": { "ms": "2.1.2" } @@ -7500,6 +7630,14 @@ "integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==", "dev": true }, + "http-cookie-agent": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/http-cookie-agent/-/http-cookie-agent-6.0.1.tgz", + "integrity": "sha512-AhPCqG7i3K8OVWORyuULoP7/Xv90wf14jBAKyLqjKpaJyGjutiwryYV+Lj1jqPYnQtbQFimwSaeY7NXw22TckQ==", + "requires": { + "agent-base": "^7.1.0" + } + }, "human-signals": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", @@ -8584,11 +8722,15 @@ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, + "psl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" + }, "punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", - "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "dev": true + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==" }, "pure-rand": { "version": "6.1.0", @@ -8596,6 +8738,11 @@ "integrity": "sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==", "dev": true }, + "querystringify": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + }, "queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -8624,6 +8771,11 @@ "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "dev": true }, + "requires-port": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" + }, "resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -8699,9 +8851,9 @@ "integrity": "sha512-e2bDA2WJT0wxseVd4lsDP4+3ONX6HpMXQa1ZhFQ7SU+GjvORCmShbCMltrtIDfkYhVHrOcPtj+KhmDBdPdZD1g==" }, "semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", "dev": true, "requires": { "lru-cache": "^6.0.0" @@ -8906,6 +9058,17 @@ "is-number": "^7.0.0" } }, + "tough-cookie": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.1.3.tgz", + "integrity": "sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==", + "requires": { + "psl": "^1.1.33", + "punycode": "^2.1.1", + "universalify": "^0.2.0", + "url-parse": "^1.5.3" + } + }, "triple-beam": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.4.1.tgz", @@ -8988,6 +9151,11 @@ "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "dev": true }, + "universalify": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.2.0.tgz", + "integrity": "sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==" + }, "update-browserslist-db": { "version": "1.0.13", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", @@ -9007,6 +9175,15 @@ "punycode": "^2.1.0" } }, + "url-parse": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", + "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "requires": { + "querystringify": "^2.1.1", + "requires-port": "^1.0.0" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index cd32373..98e8fc0 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,10 @@ "homepage": "https://github.com/timoschlueter/nightscout-librelink-up#readme", "dependencies": { "axios": "^1.6.8", + "axios-cookiejar-support": "^5.0.0", "axios-mock-adapter": "^1.22.0", "node-cron": "3.0.3", + "tough-cookie": "^4.1.3", "winston": "^3.13.0" }, "devDependencies": { @@ -45,6 +47,7 @@ "@types/jest": "^29.5.12", "@types/node": "^20.11.30", "@types/node-cron": "^3.0.11", + "@types/tough-cookie": "^4.0.5", "@typescript-eslint/eslint-plugin": "^7.4.0", "@typescript-eslint/parser": "^7.4.0", "eslint": "^8.57.0", diff --git a/src/index.ts b/src/index.ts index 318b5d6..010087f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,6 +18,14 @@ import {Client as ClientV1} from "./nightscout/apiv1"; import {Client as ClientV3} from "./nightscout/apiv3"; import {Entry} from "./nightscout/interface"; import readConfig from "./config"; +import { wrapper as axiosCookieJarSupport } from 'axios-cookiejar-support'; +import { CookieJar } from 'tough-cookie'; + +// Enable cookiejar support for Axios +axiosCookieJarSupport(axios); + +// Create a new cookie jar instance +const cookieJar = new CookieJar(); const config = readConfig(); @@ -54,7 +62,7 @@ axios.interceptors.response.use(response => return error; }); -const USER_AGENT = "FreeStyle LibreLink Up NightScout Uploader"; +const USER_AGENT = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1"; /** * LibreLink Up Credentials @@ -86,14 +94,25 @@ let authTicket: AuthTicket = {duration: 0, expires: 0, token: ""}; const libreLinkUpHttpHeaders: LibreLinkUpHttpHeaders = { "User-Agent": USER_AGENT, - "Content-Type": "application/json", + "Content-Type": "application/json;charset=UTF-8", "version": LIBRE_LINK_UP_VERSION, "product": LIBRE_LINK_UP_PRODUCT, "Accept-Encoding": "gzip, deflate, br", "Connection": "keep-alive", "Pragma": "no-cache", "Cache-Control": "no-cache", - "Authorization": undefined + "Authorization": undefined, + "accept": "application/json, text/plain, */*", + "accept-language": "en-US,en;q=0.9", + "newyu-lv-web-version": "3.16.19", + "origin": "https://www.libreview.com", + "referer": "https://www.libreview.com/", + "sec-ch-ua": "'Google Chrome';v='123', 'Not:A-Brand';v='8', 'Chromium';v='123'", + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": "'macOS'", + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "cross-site" } if (process.env.SINGLE_SHOT === "true") @@ -148,9 +167,15 @@ export async function login(): Promise password: LINK_UP_PASSWORD, }, { - headers: libreLinkUpHttpHeaders + headers: libreLinkUpHttpHeaders, + jar: cookieJar, // Attach the cookie jar + withCredentials: true, // Enable automatic cookie handling }); + // Log cookies after a request + console.log(await cookieJar.getCookies(url)); + + try { if (response.data.status !== 0) { @@ -192,9 +217,14 @@ export async function getGlucoseMeasurements(): Promise const response: {data: GraphResponse} = await axios.get( url, { - headers: getLluAuthHeaders() + headers: getLluAuthHeaders(), + jar: cookieJar, // Attach the cookie jar + withCredentials: true, // Enable automatic cookie handling }); + // Log cookies after a request + console.log(await cookieJar.getCookies(url)); + return response.data.data; } catch (error) { @@ -212,9 +242,14 @@ export async function getLibreLinkUpConnection(): Promise const response: {data: ConnectionsResponse} = await axios.get( url, { - headers: getLluAuthHeaders() + headers: getLluAuthHeaders(), + jar: cookieJar, // Attach the cookie jar + withCredentials: true, // Enable automatic cookie handling }); + // Log cookies after a request + console.log(await cookieJar.getCookies(url)); + const connectionData = response.data.data; if (connectionData.length === 0) @@ -368,4 +403,4 @@ function hasValidAuthentication(): boolean logger.info("no authTicket.expires"); return false; -} +} \ No newline at end of file From 5735f9d81dba71aa4df1606dcb47a6e8e1651892 Mon Sep 17 00:00:00 2001 From: Andy Low <42089621+AndyLow91@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:40:32 +0000 Subject: [PATCH 2/8] Update Dockerfile updated node version fixes cloudflare issue --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c96d397..69d2248 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18-bullseye +FROM node:16.16.0-bullseye LABEL description="Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout" # Create app directory From 4763b92530544ad085a005ca38a5c796a59434dd Mon Sep 17 00:00:00 2001 From: Andy Low <42089621+AndyLow91@users.noreply.github.com> Date: Sat, 30 Mar 2024 23:15:46 +0000 Subject: [PATCH 3/8] removed unnecessary logging --- src/index.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 010087f..ecd3f9d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -172,10 +172,6 @@ export async function login(): Promise withCredentials: true, // Enable automatic cookie handling }); - // Log cookies after a request - console.log(await cookieJar.getCookies(url)); - - try { if (response.data.status !== 0) { @@ -222,9 +218,6 @@ export async function getGlucoseMeasurements(): Promise withCredentials: true, // Enable automatic cookie handling }); - // Log cookies after a request - console.log(await cookieJar.getCookies(url)); - return response.data.data; } catch (error) { @@ -247,9 +240,6 @@ export async function getLibreLinkUpConnection(): Promise withCredentials: true, // Enable automatic cookie handling }); - // Log cookies after a request - console.log(await cookieJar.getCookies(url)); - const connectionData = response.data.data; if (connectionData.length === 0) From a6b059cfce155483538b6a05118d202cf5d5ed84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Schl=C3=BCter?= Date: Mon, 1 Apr 2024 12:52:47 +0200 Subject: [PATCH 4/8] Release 2.5.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 32d19f8..c806195 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nightscout-librelink-up", - "version": "2.5.0", + "version": "2.5.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "nightscout-librelink-up", - "version": "2.5.0", + "version": "2.5.1", "license": "MIT", "dependencies": { "axios": "^1.6.8", diff --git a/package.json b/package.json index cd32373..2c21d47 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nightscout-librelink-up", - "version": "2.5.0", + "version": "2.5.1", "description": "Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout", "main": "dist/index.js", "scripts": { From 8d173e8f48c56f218926f5e1f2d0bc57f2e16dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Schl=C3=BCter?= Date: Tue, 2 Apr 2024 12:53:12 +0200 Subject: [PATCH 5/8] Added Cloudflare DDOS protection bypass --- Dockerfile | 2 +- package-lock.json | 258 +++++++++++++++++++++------------------------- package.json | 36 +++---- src/index.ts | 87 ++++++++-------- tsconfig.json | 10 +- 5 files changed, 186 insertions(+), 207 deletions(-) diff --git a/Dockerfile b/Dockerfile index 69d2248..dc9a651 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16.16.0-bullseye +FROM node:20-alpine LABEL description="Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout" # Create app directory diff --git a/package-lock.json b/package-lock.json index e2dacd5..b5d5050 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,26 +9,26 @@ "version": "2.5.1", "license": "MIT", "dependencies": { - "axios": "^1.6.8", - "axios-cookiejar-support": "^5.0.0", - "axios-mock-adapter": "^1.22.0", - "node-cron": "3.0.3", - "tough-cookie": "^4.1.3", - "winston": "^3.13.0" + "axios": "~1.6.8", + "axios-mock-adapter": "~1.22.0", + "http-cookie-agent": "~6.0.1", + "node-cron": "~3.0.3", + "tough-cookie": "~4.1.3", + "winston": "~3.13.0" }, "devDependencies": { - "@tsconfig/node18": "^18.2.3", - "@types/jest": "^29.5.12", - "@types/node": "^20.11.30", - "@types/node-cron": "^3.0.11", - "@types/tough-cookie": "^4.0.5", - "@typescript-eslint/eslint-plugin": "^7.4.0", - "@typescript-eslint/parser": "^7.4.0", - "eslint": "^8.57.0", - "jest": "^29.7.0", - "ts-jest": "^29.1.2", - "ts-node": "^10.9.2", - "typescript": "^5.4.3" + "@tsconfig/node20": "~20.1.4", + "@types/jest": "~29.5.12", + "@types/node": "~20.12.2", + "@types/node-cron": "~3.0.11", + "@types/tough-cookie": "~4.0.5", + "@typescript-eslint/eslint-plugin": "~7.5.0", + "@typescript-eslint/parser": "~7.5.0", + "eslint": "~8.57.0", + "jest": "~29.7.0", + "ts-jest": "~29.1.2", + "ts-node": "~10.9.2", + "typescript": "~5.4.3" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -1322,10 +1322,10 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, - "node_modules/@tsconfig/node18": { - "version": "18.2.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node18/-/node18-18.2.3.tgz", - "integrity": "sha512-5GKTU9bfn4L37G9IdK8wcHfvyMijzw1uKNCd2Rs75V7fZK/l2OjGJ8Aa2myqNnESjekm/udpCnFH9qR9yPCtmw==", + "node_modules/@tsconfig/node20": { + "version": "20.1.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node20/-/node20-20.1.4.tgz", + "integrity": "sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==", "dev": true }, "node_modules/@types/babel__core": { @@ -1419,9 +1419,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.11.30", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.30.tgz", - "integrity": "sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==", + "version": "20.12.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.2.tgz", + "integrity": "sha512-zQ0NYO87hyN6Xrclcqp7f8ZbXNbRfoGWNcMvHTPQp9UUrwI0mI7XBz+cu7/W6/VClYo2g63B0cjull/srU7LgQ==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -1472,16 +1472,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.4.0.tgz", - "integrity": "sha512-yHMQ/oFaM7HZdVrVm/M2WHaNPgyuJH4WelkSVEWSSsir34kxW2kDJCxlXRhhGWEsMN0WAW/vLpKfKVcm8k+MPw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.5.0.tgz", + "integrity": "sha512-HpqNTH8Du34nLxbKgVMGljZMG0rJd2O9ecvr2QLYp+7512ty1j42KnsFwspPXg1Vh8an9YImf6CokUBltisZFQ==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "7.4.0", - "@typescript-eslint/type-utils": "7.4.0", - "@typescript-eslint/utils": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0", + "@typescript-eslint/scope-manager": "7.5.0", + "@typescript-eslint/type-utils": "7.5.0", + "@typescript-eslint/utils": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -1507,15 +1507,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.4.0.tgz", - "integrity": "sha512-ZvKHxHLusweEUVwrGRXXUVzFgnWhigo4JurEj0dGF1tbcGh6buL+ejDdjxOQxv6ytcY1uhun1p2sm8iWStlgLQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.5.0.tgz", + "integrity": "sha512-cj+XGhNujfD2/wzR1tabNsidnYRaFfEkcULdcIyVBYcXjBvBKOes+mpMBP7hMpOyk+gBcfXsrg4NBGAStQyxjQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "7.4.0", - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/typescript-estree": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0", + "@typescript-eslint/scope-manager": "7.5.0", + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/typescript-estree": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0", "debug": "^4.3.4" }, "engines": { @@ -1535,13 +1535,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.4.0.tgz", - "integrity": "sha512-68VqENG5HK27ypafqLVs8qO+RkNc7TezCduYrx8YJpXq2QGZ30vmNZGJJJC48+MVn4G2dCV8m5ZTVnzRexTVtw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.5.0.tgz", + "integrity": "sha512-Z1r7uJY0MDeUlql9XJ6kRVgk/sP11sr3HKXn268HZyqL7i4cEfrdFuSSY/0tUqT37l5zT0tJOsuDP16kio85iA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0" + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -1552,13 +1552,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.4.0.tgz", - "integrity": "sha512-247ETeHgr9WTRMqHbbQdzwzhuyaJ8dPTuyuUEMANqzMRB1rj/9qFIuIXK7l0FX9i9FXbHeBQl/4uz6mYuCE7Aw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.5.0.tgz", + "integrity": "sha512-A021Rj33+G8mx2Dqh0nMO9GyjjIBK3MqgVgZ2qlKf6CJy51wY/lkkFqq3TqqnH34XyAHUkq27IjlUkWlQRpLHw==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "7.4.0", - "@typescript-eslint/utils": "7.4.0", + "@typescript-eslint/typescript-estree": "7.5.0", + "@typescript-eslint/utils": "7.5.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -1579,9 +1579,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.4.0.tgz", - "integrity": "sha512-mjQopsbffzJskos5B4HmbsadSJQWaRK0UxqQ7GuNA9Ga4bEKeiO6b2DnB6cM6bpc8lemaPseh0H9B/wyg+J7rw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.5.0.tgz", + "integrity": "sha512-tv5B4IHeAdhR7uS4+bf8Ov3k793VEVHd45viRRkehIUZxm0WF82VPiLgHzA/Xl4TGPg1ZD49vfxBKFPecD5/mg==", "dev": true, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -1592,13 +1592,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.4.0.tgz", - "integrity": "sha512-A99j5AYoME/UBQ1ucEbbMEmGkN7SE0BvZFreSnTd1luq7yulcHdyGamZKizU7canpGDWGJ+Q6ZA9SyQobipePg==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.5.0.tgz", + "integrity": "sha512-YklQQfe0Rv2PZEueLTUffiQGKQneiIEKKnfIqPIOxgM9lKSZFCjT5Ad4VqRKj/U4+kQE3fa8YQpskViL7WjdPQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0", + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1644,17 +1644,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.4.0.tgz", - "integrity": "sha512-NQt9QLM4Tt8qrlBVY9lkMYzfYtNz8/6qwZg8pI3cMGlPnj6mOpRxxAm7BMJN9K0AiY+1BwJ5lVC650YJqYOuNg==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.5.0.tgz", + "integrity": "sha512-3vZl9u0R+/FLQcpy2EHyRGNqAS/ofJ3Ji8aebilfJe+fobK8+LbIFmrHciLVDxjDoONmufDcnVSF38KwMEOjzw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "7.4.0", - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/typescript-estree": "7.4.0", + "@typescript-eslint/scope-manager": "7.5.0", + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/typescript-estree": "7.5.0", "semver": "^7.5.4" }, "engines": { @@ -1669,12 +1669,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.4.0.tgz", - "integrity": "sha512-0zkC7YM0iX5Y41homUUeW1CHtZR01K3ybjM1l6QczoMuay0XKtrb93kv95AxUGwdjGr64nNqnOCwmEl616N8CA==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.5.0.tgz", + "integrity": "sha512-mcuHM/QircmA6O7fy6nn2w/3ditQkj+SgtOc8DW3uQ10Yfj42amm2i+6F2K4YAOPNNTmE6iM1ynM6lrSwdendA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.4.0", + "@typescript-eslint/types": "7.5.0", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -1853,24 +1853,6 @@ "proxy-from-env": "^1.1.0" } }, - "node_modules/axios-cookiejar-support": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/axios-cookiejar-support/-/axios-cookiejar-support-5.0.0.tgz", - "integrity": "sha512-4zdO95qgsKp0OX+LUwD0MRWdD0r5YsQBpTi3ULHLL87qU58QZl3O3UQF58fZTzcdGtxYPtcotyXT7sNWDE37ug==", - "dependencies": { - "http-cookie-agent": "^6.0.1" - }, - "engines": { - "node": ">=18.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/3846masa" - }, - "peerDependencies": { - "axios": ">=0.20.0", - "tough-cookie": ">=4.0.0" - } - }, "node_modules/axios-mock-adapter": { "version": "1.22.0", "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", @@ -6394,10 +6376,10 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, - "@tsconfig/node18": { - "version": "18.2.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node18/-/node18-18.2.3.tgz", - "integrity": "sha512-5GKTU9bfn4L37G9IdK8wcHfvyMijzw1uKNCd2Rs75V7fZK/l2OjGJ8Aa2myqNnESjekm/udpCnFH9qR9yPCtmw==", + "@tsconfig/node20": { + "version": "20.1.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node20/-/node20-20.1.4.tgz", + "integrity": "sha512-sqgsT69YFeLWf5NtJ4Xq/xAF8p4ZQHlmGW74Nu2tD4+g5fAsposc4ZfaaPixVu4y01BEiDCWLRDCvDM5JOsRxg==", "dev": true }, "@types/babel__core": { @@ -6491,9 +6473,9 @@ "dev": true }, "@types/node": { - "version": "20.11.30", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.30.tgz", - "integrity": "sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==", + "version": "20.12.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.2.tgz", + "integrity": "sha512-zQ0NYO87hyN6Xrclcqp7f8ZbXNbRfoGWNcMvHTPQp9UUrwI0mI7XBz+cu7/W6/VClYo2g63B0cjull/srU7LgQ==", "dev": true, "requires": { "undici-types": "~5.26.4" @@ -6544,16 +6526,16 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.4.0.tgz", - "integrity": "sha512-yHMQ/oFaM7HZdVrVm/M2WHaNPgyuJH4WelkSVEWSSsir34kxW2kDJCxlXRhhGWEsMN0WAW/vLpKfKVcm8k+MPw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.5.0.tgz", + "integrity": "sha512-HpqNTH8Du34nLxbKgVMGljZMG0rJd2O9ecvr2QLYp+7512ty1j42KnsFwspPXg1Vh8an9YImf6CokUBltisZFQ==", "dev": true, "requires": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "7.4.0", - "@typescript-eslint/type-utils": "7.4.0", - "@typescript-eslint/utils": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0", + "@typescript-eslint/scope-manager": "7.5.0", + "@typescript-eslint/type-utils": "7.5.0", + "@typescript-eslint/utils": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -6563,54 +6545,54 @@ } }, "@typescript-eslint/parser": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.4.0.tgz", - "integrity": "sha512-ZvKHxHLusweEUVwrGRXXUVzFgnWhigo4JurEj0dGF1tbcGh6buL+ejDdjxOQxv6ytcY1uhun1p2sm8iWStlgLQ==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.5.0.tgz", + "integrity": "sha512-cj+XGhNujfD2/wzR1tabNsidnYRaFfEkcULdcIyVBYcXjBvBKOes+mpMBP7hMpOyk+gBcfXsrg4NBGAStQyxjQ==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "7.4.0", - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/typescript-estree": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0", + "@typescript-eslint/scope-manager": "7.5.0", + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/typescript-estree": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0", "debug": "^4.3.4" } }, "@typescript-eslint/scope-manager": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.4.0.tgz", - "integrity": "sha512-68VqENG5HK27ypafqLVs8qO+RkNc7TezCduYrx8YJpXq2QGZ30vmNZGJJJC48+MVn4G2dCV8m5ZTVnzRexTVtw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.5.0.tgz", + "integrity": "sha512-Z1r7uJY0MDeUlql9XJ6kRVgk/sP11sr3HKXn268HZyqL7i4cEfrdFuSSY/0tUqT37l5zT0tJOsuDP16kio85iA==", "dev": true, "requires": { - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0" + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0" } }, "@typescript-eslint/type-utils": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.4.0.tgz", - "integrity": "sha512-247ETeHgr9WTRMqHbbQdzwzhuyaJ8dPTuyuUEMANqzMRB1rj/9qFIuIXK7l0FX9i9FXbHeBQl/4uz6mYuCE7Aw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.5.0.tgz", + "integrity": "sha512-A021Rj33+G8mx2Dqh0nMO9GyjjIBK3MqgVgZ2qlKf6CJy51wY/lkkFqq3TqqnH34XyAHUkq27IjlUkWlQRpLHw==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "7.4.0", - "@typescript-eslint/utils": "7.4.0", + "@typescript-eslint/typescript-estree": "7.5.0", + "@typescript-eslint/utils": "7.5.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" } }, "@typescript-eslint/types": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.4.0.tgz", - "integrity": "sha512-mjQopsbffzJskos5B4HmbsadSJQWaRK0UxqQ7GuNA9Ga4bEKeiO6b2DnB6cM6bpc8lemaPseh0H9B/wyg+J7rw==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.5.0.tgz", + "integrity": "sha512-tv5B4IHeAdhR7uS4+bf8Ov3k793VEVHd45viRRkehIUZxm0WF82VPiLgHzA/Xl4TGPg1ZD49vfxBKFPecD5/mg==", "dev": true }, "@typescript-eslint/typescript-estree": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.4.0.tgz", - "integrity": "sha512-A99j5AYoME/UBQ1ucEbbMEmGkN7SE0BvZFreSnTd1luq7yulcHdyGamZKizU7canpGDWGJ+Q6ZA9SyQobipePg==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.5.0.tgz", + "integrity": "sha512-YklQQfe0Rv2PZEueLTUffiQGKQneiIEKKnfIqPIOxgM9lKSZFCjT5Ad4VqRKj/U4+kQE3fa8YQpskViL7WjdPQ==", "dev": true, "requires": { - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/visitor-keys": "7.4.0", + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/visitor-keys": "7.5.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -6640,27 +6622,27 @@ } }, "@typescript-eslint/utils": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.4.0.tgz", - "integrity": "sha512-NQt9QLM4Tt8qrlBVY9lkMYzfYtNz8/6qwZg8pI3cMGlPnj6mOpRxxAm7BMJN9K0AiY+1BwJ5lVC650YJqYOuNg==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.5.0.tgz", + "integrity": "sha512-3vZl9u0R+/FLQcpy2EHyRGNqAS/ofJ3Ji8aebilfJe+fobK8+LbIFmrHciLVDxjDoONmufDcnVSF38KwMEOjzw==", "dev": true, "requires": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "7.4.0", - "@typescript-eslint/types": "7.4.0", - "@typescript-eslint/typescript-estree": "7.4.0", + "@typescript-eslint/scope-manager": "7.5.0", + "@typescript-eslint/types": "7.5.0", + "@typescript-eslint/typescript-estree": "7.5.0", "semver": "^7.5.4" } }, "@typescript-eslint/visitor-keys": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.4.0.tgz", - "integrity": "sha512-0zkC7YM0iX5Y41homUUeW1CHtZR01K3ybjM1l6QczoMuay0XKtrb93kv95AxUGwdjGr64nNqnOCwmEl616N8CA==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.5.0.tgz", + "integrity": "sha512-mcuHM/QircmA6O7fy6nn2w/3ditQkj+SgtOc8DW3uQ10Yfj42amm2i+6F2K4YAOPNNTmE6iM1ynM6lrSwdendA==", "dev": true, "requires": { - "@typescript-eslint/types": "7.4.0", + "@typescript-eslint/types": "7.5.0", "eslint-visitor-keys": "^3.4.1" } }, @@ -6789,14 +6771,6 @@ "proxy-from-env": "^1.1.0" } }, - "axios-cookiejar-support": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/axios-cookiejar-support/-/axios-cookiejar-support-5.0.0.tgz", - "integrity": "sha512-4zdO95qgsKp0OX+LUwD0MRWdD0r5YsQBpTi3ULHLL87qU58QZl3O3UQF58fZTzcdGtxYPtcotyXT7sNWDE37ug==", - "requires": { - "http-cookie-agent": "^6.0.1" - } - }, "axios-mock-adapter": { "version": "1.22.0", "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", diff --git a/package.json b/package.json index 016eed1..b5306fe 100644 --- a/package.json +++ b/package.json @@ -35,25 +35,25 @@ }, "homepage": "https://github.com/timoschlueter/nightscout-librelink-up#readme", "dependencies": { - "axios": "^1.6.8", - "axios-cookiejar-support": "^5.0.0", - "axios-mock-adapter": "^1.22.0", - "node-cron": "3.0.3", - "tough-cookie": "^4.1.3", - "winston": "^3.13.0" + "axios": "~1.6.8", + "axios-mock-adapter": "~1.22.0", + "http-cookie-agent": "~6.0.1", + "node-cron": "~3.0.3", + "tough-cookie": "~4.1.3", + "winston": "~3.13.0" }, "devDependencies": { - "@tsconfig/node18": "^18.2.3", - "@types/jest": "^29.5.12", - "@types/node": "^20.11.30", - "@types/node-cron": "^3.0.11", - "@types/tough-cookie": "^4.0.5", - "@typescript-eslint/eslint-plugin": "^7.4.0", - "@typescript-eslint/parser": "^7.4.0", - "eslint": "^8.57.0", - "jest": "^29.7.0", - "ts-jest": "^29.1.2", - "ts-node": "^10.9.2", - "typescript": "^5.4.3" + "@tsconfig/node20": "~20.1.4", + "@types/jest": "~29.5.12", + "@types/node": "~20.12.2", + "@types/node-cron": "~3.0.11", + "@types/tough-cookie": "~4.0.5", + "@typescript-eslint/eslint-plugin": "~7.5.0", + "@typescript-eslint/parser": "~7.5.0", + "eslint": "~8.57.0", + "jest": "~29.7.0", + "ts-jest": "~29.1.2", + "ts-node": "~10.9.2", + "typescript": "~5.4.3" } } diff --git a/src/index.ts b/src/index.ts index ecd3f9d..253601d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,9 @@ * SPDX-License-Identifier: MIT */ import {LLU_API_ENDPOINTS} from "./constants/llu-api-endpoints"; -import cron from "node-cron"; +import * as cron from "node-cron"; import axios from "axios"; -import {createLogger, transports, format} from "winston"; +import {createLogger, format, transports} from "winston"; import {LoginResponse} from "./interfaces/librelink/login-response"; import {ConnectionsResponse} from "./interfaces/librelink/connections-response"; import {GraphData, GraphResponse} from "./interfaces/librelink/graph-response"; @@ -18,14 +18,23 @@ import {Client as ClientV1} from "./nightscout/apiv1"; import {Client as ClientV3} from "./nightscout/apiv3"; import {Entry} from "./nightscout/interface"; import readConfig from "./config"; -import { wrapper as axiosCookieJarSupport } from 'axios-cookiejar-support'; -import { CookieJar } from 'tough-cookie'; - -// Enable cookiejar support for Axios -axiosCookieJarSupport(axios); +import {CookieJar} from "tough-cookie"; +import {HttpCookieAgent} from "http-cookie-agent/http"; +import {Agent as HttpAgent} from "node:http"; +import {Agent as HttpsAgent} from "node:https"; +import * as crypto from "crypto"; + +// Generate new Cyphers for stealth mode in order to bypass SSL fingerprinting used by Cloudflare. +// The new Cyphers are then used in the HTTPS Agent for Axios. +const defaultCyphers: Array = crypto.constants.defaultCipherList.split(":"); +const stealthCyphers: Array = defaultCyphers.slice(0, 3); +const stealthHttpsAgent: HttpsAgent = new HttpsAgent({ + ciphers: stealthCyphers.join(":") +}); -// Create a new cookie jar instance -const cookieJar = new CookieJar(); +// Create a new CookieJar and HttpCookieAgent for Axios to handle cookies. +const jar: CookieJar = new CookieJar(); +const cookieAgent: HttpAgent = new HttpCookieAgent({cookies: {jar}}) const config = readConfig(); @@ -96,23 +105,7 @@ const libreLinkUpHttpHeaders: LibreLinkUpHttpHeaders = { "User-Agent": USER_AGENT, "Content-Type": "application/json;charset=UTF-8", "version": LIBRE_LINK_UP_VERSION, - "product": LIBRE_LINK_UP_PRODUCT, - "Accept-Encoding": "gzip, deflate, br", - "Connection": "keep-alive", - "Pragma": "no-cache", - "Cache-Control": "no-cache", - "Authorization": undefined, - "accept": "application/json, text/plain, */*", - "accept-language": "en-US,en;q=0.9", - "newyu-lv-web-version": "3.16.19", - "origin": "https://www.libreview.com", - "referer": "https://www.libreview.com/", - "sec-ch-ua": "'Google Chrome';v='123', 'Not:A-Brand';v='8', 'Chromium';v='123'", - "sec-ch-ua-mobile": "?0", - "sec-ch-ua-platform": "'macOS'", - "sec-fetch-dest": "empty", - "sec-fetch-mode": "cors", - "sec-fetch-site": "cross-site" + "product": LIBRE_LINK_UP_PRODUCT } if (process.env.SINGLE_SHOT === "true") @@ -160,7 +153,7 @@ export async function login(): Promise try { const url = "https://" + LIBRE_LINK_UP_URL + "/llu/auth/login" - const response: {data: LoginResponse} = await axios.post( + const response: { data: LoginResponse } = await axios.post( url, { email: LINK_UP_USERNAME, @@ -168,17 +161,20 @@ export async function login(): Promise }, { headers: libreLinkUpHttpHeaders, - jar: cookieJar, // Attach the cookie jar withCredentials: true, // Enable automatic cookie handling + httpAgent: cookieAgent, + httpsAgent: stealthHttpsAgent }); - + try { - if (response.data.status !== 0) { + if (response.data.status !== 0) + { logger.error(`LibreLink Up - Non-zero status code: ${JSON.stringify(response.data)}`) return null; } - if (response.data.data.redirect === true && response.data.data.region) { + if (response.data.data.redirect === true && response.data.data.region) + { const correctRegion = response.data.data.region.toUpperCase(); logger.error( `LibreLink Up - Logged in to the wrong region. Switch to '${correctRegion}' region.` @@ -210,12 +206,13 @@ export async function getGlucoseMeasurements(): Promise } const url = "https://" + LIBRE_LINK_UP_URL + "/llu/connections/" + connectionId + "/graph" - const response: {data: GraphResponse} = await axios.get( + const response: { data: GraphResponse } = await axios.get( url, { headers: getLluAuthHeaders(), - jar: cookieJar, // Attach the cookie jar withCredentials: true, // Enable automatic cookie handling + httpAgent: cookieAgent, + httpsAgent: stealthHttpsAgent, }); return response.data.data; @@ -232,12 +229,13 @@ export async function getLibreLinkUpConnection(): Promise try { const url = "https://" + LIBRE_LINK_UP_URL + "/llu/connections" - const response: {data: ConnectionsResponse} = await axios.get( + const response: { data: ConnectionsResponse } = await axios.get( url, { headers: getLluAuthHeaders(), - jar: cookieJar, // Attach the cookie jar withCredentials: true, // Enable automatic cookie handling + httpAgent: cookieAgent, + httpsAgent: stealthHttpsAgent, }); const connectionData = response.data.data; @@ -282,17 +280,19 @@ export async function getLibreLinkUpConnection(): Promise } const nightscoutClient = config.nightscoutApiV3 - ? new ClientV3(config) - : new ClientV1(config); + ? new ClientV3(config) + : new ClientV1(config); -export async function createFormattedMeasurements(measurementData: GraphData): Promise { +export async function createFormattedMeasurements(measurementData: GraphData): Promise +{ const formattedMeasurements: Entry[] = []; const glucoseMeasurement = measurementData.connection.glucoseMeasurement; const measurementDate = getUtcDateFromString(glucoseMeasurement.FactoryTimestamp); const lastEntry = await nightscoutClient.lastEntry(); // Add the most recent measurement first - if (lastEntry === null || measurementDate > lastEntry.date) { + if (lastEntry === null || measurementDate > lastEntry.date) + { formattedMeasurements.push({ date: measurementDate, direction: mapTrendArrow(glucoseMeasurement.TrendArrow), @@ -300,9 +300,11 @@ export async function createFormattedMeasurements(measurementData: GraphData): P }); } - measurementData.graphData.forEach((glucoseMeasurementHistoryEntry: GlucoseItem) => { + measurementData.graphData.forEach((glucoseMeasurementHistoryEntry: GlucoseItem) => + { const entryDate = getUtcDateFromString(glucoseMeasurementHistoryEntry.FactoryTimestamp); - if (lastEntry === null || entryDate > lastEntry.date) { + if (lastEntry === null || entryDate > lastEntry.date) + { formattedMeasurements.push({ date: entryDate, sgv: glucoseMeasurementHistoryEntry.ValueInMgPerDl, @@ -351,7 +353,6 @@ function logPickedUpConnection(connection: Connection): void connection.patientId + ")"); } - function getLluAuthHeaders(): LibreLinkUpHttpHeaders { const authenticatedHttpHeaders = libreLinkUpHttpHeaders; @@ -393,4 +394,4 @@ function hasValidAuthentication(): boolean logger.info("no authTicket.expires"); return false; -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index 0024464..957edcb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,14 @@ { - "extends": "@tsconfig/node18/tsconfig.json", + "extends": "@tsconfig/node20/tsconfig.json", "compilerOptions": { "outDir": "dist", "strict": true, "resolveJsonModule": true }, - "include": ["src"], - "exclude": ["node_modules"] + "include": [ + "src" + ], + "exclude": [ + "node_modules" + ] } From 7984488779807c9cec45d2d326d796683ee2f7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Schl=C3=BCter?= Date: Tue, 2 Apr 2024 13:22:06 +0200 Subject: [PATCH 6/8] Switched back to Debian based Docker image --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index dc9a651..a34f964 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-bookworm LABEL description="Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout" # Create app directory From ed66bac8fcd396c836e60f38de2a6143f2b2002e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Schl=C3=BCter?= Date: Tue, 2 Apr 2024 13:51:23 +0200 Subject: [PATCH 7/8] Update GitHub workflow --- .github/workflows/docker-image.yml | 28 +++++++++++----------------- Dockerfile | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index f2de0ce..e699926 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -9,36 +9,30 @@ jobs: main: runs-on: ubuntu-latest steps: - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Docker Hub - uses: docker/login-action@v2 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - - - name: Docker Build and Push (Dev) + - name: Docker Build and Push (Dev) id: docker_build_dev - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: push: true platforms: linux/amd64,linux/arm64,linux/arm/v7 tags: timoschlueter/nightscout-librelink-up:dev - - - name: Docker Build and Push (Tagged) + - name: Docker Build and Push (Tagged) if: startsWith(github.ref, 'refs/tags/') id: docker_build_tagged - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: push: true platforms: linux/amd64,linux/arm64,linux/arm/v7 tags: timoschlueter/nightscout-librelink-up:${{github.ref_name}},timoschlueter/nightscout-librelink-up:latest - - - name: Docker Image digest + - name: Docker Image digest if: startsWith(github.ref, 'refs/tags/') run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile index a34f964..dc9a651 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-bookworm +FROM node:20-alpine LABEL description="Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout" # Create app directory From c786f9a3e942b2bc7386194ae4da451c5c7f108b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Schl=C3=BCter?= Date: Tue, 2 Apr 2024 13:57:51 +0200 Subject: [PATCH 8/8] Back to debian again. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index dc9a651..a34f964 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-bookworm LABEL description="Script written in TypeScript that uploads CGM readings from LibreLink Up to Nightscout" # Create app directory