Skip to content

Commit

Permalink
Add uid in resquests, update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bokub committed Nov 2, 2022
1 parent 77fadf8 commit 04473a7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "linky",
"description": "Easily retrieve your Linky power consumption",
"version": "1.6.0",
"version": "1.7.0",
"author": "bokub",
"license": "GPL-3.0-or-later",
"main": "dist/src/index.js",
Expand All @@ -19,7 +19,7 @@
"coverage": "c8 report --reporter=text-lcov > coverage.lcov",
"test": "c8 ava --timeout=1m",
"prepare": "husky install",
"prepublish": "npm run build",
"prepublishOnly": "npm run build",
"build": "rm -fr ./dist && tsc",
"pkg": "rm -fr ./pkg && pkg . --out-path pkg -t node16-linux-x64,node16-macos-x64,node16-win-x64",
"lint": "prettier --check --ignore-path .gitignore .",
Expand Down
23 changes: 4 additions & 19 deletions server/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@
"redirects": [
{
"source": "/api/refresh",
"has": [{ "type": "query", "key": "token", "value": "75OxzdDV2Y8I1gAeOWx9jHTRH33UM36ILfpvHVPZn2QhXT" }],
"destination": "https://pastebin.com/raw/T6tHEygU"
"has": [{ "type": "query", "key": "token", "value": "7L1oV2LUJsavwbCLIuVOZP1tOkVC3cbws2AyIor7sa45pO" }],
"destination": "https://pastebin.com/raw/sL5Hzt6a"
},
{
"source": "/api/refresh",
"has": [{ "type": "query", "key": "token", "value": "GnL5ReToBSUCn4SwDeeYiGXtjTTBWcrhiV2mIdJjYHATaN" }],
"destination": "https://pastebin.com/raw/YvjYNyuD"
},
{
"source": "/api/refresh",
"has": [{ "type": "query", "key": "token", "value": "U4M0jxyUcIYJKAQISq7CXUFeuAYVKXSvB69pvcyBc5gFfs" }],
"destination": "https://pastebin.com/raw/YvjYNyuD"
},
{
"source": "/api/refresh",
"has": [{ "type": "query", "key": "token", "value": "5tyWWlVetWpzCi5NgcC6NUF3ZWbpOxXb2r8J5YCGh94OYJ" }],
"destination": "https://pastebin.com/raw/YvjYNyuD"
},
{
"source": "/api/refresh",
"has": [{ "type": "query", "key": "token", "value": "aAz0bYPjp4430lBfwrXXbrd7Nr6g8z44kyBj01czcrghNa" }],
"destination": "https://pastebin.com/raw/YvjYNyuD"
"has": [{ "type": "query", "key": "token", "value": "GMEaJNdrMrU8oCMeXMBNystNPBTGimotZj3PU8GMchxdgn" }],
"destination": "https://pastebin.com/raw/sL5Hzt6a"
}
]
}
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from 'axios';
import qs from 'qs';
import { createHash } from 'crypto';

export type SessionConfig = {
accessToken: string;
Expand Down Expand Up @@ -66,11 +67,13 @@ export type TokenRefreshCallback = (accessToken: string, refreshToken: string) =
export class Session {
private config: SessionConfig;
private baseURL: string;
private uid: string;
private onTokenRefresh?: TokenRefreshCallback;

constructor(config: SessionConfig) {
this.config = config;
this.baseURL = config.sandbox ? 'https://gw.hml.api.enedis.fr' : 'https://gw.prd.api.enedis.fr';
this.uid = createHash('sha256').update(config.usagePointId).digest('hex').slice(-7);
if (config.onTokenRefresh) {
this.onTokenRefresh = config.onTokenRefresh;
}
Expand Down Expand Up @@ -145,7 +148,7 @@ export class Session {

private refreshToken() {
const host = this.config.sandbox ? 'linky.bokub.vercel.app' : 'conso.vercel.app';
const url = `https://${host}/api/refresh?token=${this.config.refreshToken}`;
const url = `https://${host}/api/refresh?token=${this.config.refreshToken}&uid=${this.uid}`;
return axios
.get<RefreshTokenResponse>(url)
.then((res) => {
Expand Down

0 comments on commit 04473a7

Please sign in to comment.