Comparing version 1.3.0 to 1.4.1
@@ -58,7 +58,18 @@ "use strict"; | ||
onTokenRefresh: function (accessToken, refreshToken) { | ||
if (accessToken && refreshToken) { | ||
store.setAccessToken(accessToken); | ||
store.setRefreshToken(refreshToken); | ||
store.setFailedRefreshAttempts(0); | ||
return; | ||
} | ||
var failedRefreshAttempts = store.incrementFailedRefreshAttempts(); | ||
// If it failed less than 3 times, just print a warning | ||
if (failedRefreshAttempts < 3) { | ||
throw new Error("Impossible de rafraichir vos tokens...\nVeuillez réessayer plus tard ou relancez 'linky auth' avec de nouveaux tokens"); | ||
} | ||
// If it failed 3 times or more, reset tokens | ||
store.setAccessToken(accessToken); | ||
store.setRefreshToken(refreshToken); | ||
if (!refreshToken) { | ||
throw new Error("Vos tokens sont invalides et ont été supprimés\nRelancez 'linky auth' pour vous connecter"); | ||
} | ||
store.setFailedRefreshAttempts(0); | ||
throw new Error("Impossible de rafraichir vos tokens...\nVos tokens sont invalides et ont été supprimés\nRelancez 'linky auth' pour vous connecter"); | ||
}, | ||
@@ -65,0 +76,0 @@ }); |
@@ -31,2 +31,3 @@ #!/usr/bin/env node | ||
var update_notifier_1 = __importDefault(require("update-notifier")); | ||
var dayjs_1 = __importDefault(require("dayjs")); | ||
var pkg = __importStar(require("../package.json")); | ||
@@ -39,3 +40,3 @@ function exit(e) { | ||
} | ||
var mainHelp = "\n linky <commande> [options]\n \n Commandes:\n linky auth Cr\u00E9e une connexion \u00E0 un compte Enedis. Vous pouvez obtenir vos tokens sur https://conso.vercel.app\n linky daily R\u00E9cup\u00E8re la consommation quotidienne\n linky loadcurve R\u00E9cup\u00E8re la puissance moyenne consomm\u00E9e quotidiennement, sur un intervalle de 30 min\n linky maxpower R\u00E9cup\u00E8re la puissance maximale de consommation atteinte quotidiennement\n \n Options:\n linky auth:\n --access-token -a Access Token\n --refresh-token -r Refresh Token\n --usage-point-id -u Usage Point ID\n\n linky (daily|loadcurve|maxpower):\n --start -s Date de d\u00E9but (AAAA-MM-JJ)\n --end -e Date de d\u00E9but (AAAA-MM-JJ)\n --output -o Fichier .json de sortie. Optionnel\n \n Exemples:\n linky auth -a Kft3SIZrcq -r F3AR0K8eoC -u 225169\n linky daily --start 2020-08-01 --end 2020-08-15\n linky loadcurve -s 2020-09-01 -e 2020-09-02 -o data/ma_conso.json\n"; | ||
var mainHelp = "\n linky <commande> [options]\n \n Commandes:\n linky auth Cr\u00E9e une connexion \u00E0 un compte Enedis. Vous pouvez obtenir vos tokens sur https://conso.vercel.app\n linky daily R\u00E9cup\u00E8re la consommation quotidienne\n linky loadcurve R\u00E9cup\u00E8re la puissance moyenne consomm\u00E9e quotidiennement, sur un intervalle de 30 min\n linky maxpower R\u00E9cup\u00E8re la puissance maximale de consommation atteinte quotidiennement\n \n Options:\n linky auth:\n --access-token -a Access Token\n --refresh-token -r Refresh Token\n --usage-point-id -u Usage Point ID\n\n linky (daily|loadcurve|maxpower):\n --start -s Date de d\u00E9but (AAAA-MM-JJ). Par d\u00E9faut: hier\n --end -e Date de d\u00E9but (AAAA-MM-JJ). Par d\u00E9faut: aujourd'hui\n --output -o Fichier .json de sortie. Optionnel\n \n Exemples:\n linky auth -a Kft3SIZrcq -r F3AR0K8eoC -u 225169\n linky daily --start 2022-01-01 --end 2022-01-08\n linky maxpower --start 2021-08-01 --end 2021-08-15\n linky loadcurve -s 2022-01-01 -e 2022-01-08 -o data/ma_conso.json\n linky daily\n"; | ||
var authCommand = 'auth'; | ||
@@ -45,5 +46,4 @@ var dailyConsumptionCommand = 'daily'; | ||
var maxPowerCommand = 'maxpower'; | ||
var isMetering = function (flags, input) { | ||
return [dailyConsumptionCommand, loadCurveCommand, maxPowerCommand].indexOf(input[0]) > -1; | ||
}; | ||
var today = dayjs_1.default().format('YYYY-MM-DD'); | ||
var yesterday = dayjs_1.default().subtract(1, 'day').format('YYYY-MM-DD'); | ||
var cli; | ||
@@ -57,4 +57,4 @@ try { | ||
usagePointId: { type: 'string', alias: 'u' }, | ||
start: { type: 'string', alias: 's', isRequired: isMetering }, | ||
end: { type: 'string', alias: 'e', isRequired: isMetering }, | ||
start: { type: 'string', alias: 's', default: yesterday }, | ||
end: { type: 'string', alias: 'e', default: today }, | ||
output: { type: 'string', alias: 'o' }, | ||
@@ -70,4 +70,4 @@ sandbox: { type: 'boolean' }, | ||
var meteringFlags = { | ||
start: cli.flags.start || '', | ||
end: cli.flags.end || '', | ||
start: cli.flags.start, | ||
end: cli.flags.end, | ||
output: cli.flags.output || null, | ||
@@ -74,0 +74,0 @@ }; |
export declare const getAccessToken: () => string; | ||
export declare const getRefreshToken: () => string; | ||
export declare const getUsagePointID: () => string; | ||
export declare const getFailedRefreshAttempts: () => number; | ||
export declare const getSandbox: () => boolean; | ||
@@ -8,2 +9,4 @@ export declare const setAccessToken: (accessToken: string) => void; | ||
export declare const setUsagePointID: (usagePointID: string) => void; | ||
export declare const setFailedRefreshAttempts: (attempts: number) => void; | ||
export declare const incrementFailedRefreshAttempts: () => number; | ||
export declare const setSandbox: (sandbox: boolean) => void; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setSandbox = exports.setUsagePointID = exports.setRefreshToken = exports.setAccessToken = exports.getSandbox = exports.getUsagePointID = exports.getRefreshToken = exports.getAccessToken = void 0; | ||
exports.setSandbox = exports.incrementFailedRefreshAttempts = exports.setFailedRefreshAttempts = exports.setUsagePointID = exports.setRefreshToken = exports.setAccessToken = exports.getSandbox = exports.getFailedRefreshAttempts = exports.getUsagePointID = exports.getRefreshToken = exports.getAccessToken = void 0; | ||
var conf_1 = __importDefault(require("conf")); | ||
@@ -13,2 +13,3 @@ var store = new conf_1.default(); | ||
var usagePointIDStoreKey = 'linky/usagePointId'; | ||
var failedRefreshAttemptsKey = 'linky/failedRefreshAttempts'; | ||
var sandboxStoreKey = 'linky/sandbox'; | ||
@@ -18,2 +19,3 @@ exports.getAccessToken = function () { return store.get(accessTokenStoreKey, ''); }; | ||
exports.getUsagePointID = function () { return store.get(usagePointIDStoreKey, ''); }; | ||
exports.getFailedRefreshAttempts = function () { return store.get(failedRefreshAttemptsKey, 0); }; | ||
exports.getSandbox = function () { return Boolean(store.get(sandboxStoreKey, false)); }; | ||
@@ -23,2 +25,8 @@ exports.setAccessToken = function (accessToken) { return store.set(accessTokenStoreKey, accessToken); }; | ||
exports.setUsagePointID = function (usagePointID) { return store.set(usagePointIDStoreKey, usagePointID); }; | ||
exports.setFailedRefreshAttempts = function (attempts) { return store.set(failedRefreshAttemptsKey, attempts); }; | ||
exports.incrementFailedRefreshAttempts = function () { | ||
var attempts = exports.getFailedRefreshAttempts(); | ||
store.set(failedRefreshAttemptsKey, attempts + 1); | ||
return attempts + 1; | ||
}; | ||
exports.setSandbox = function (sandbox) { return store.set(sandboxStoreKey, sandbox); }; |
{ | ||
"name": "linky", | ||
"description": "Easily retrieve your Linky power consumption", | ||
"version": "1.3.0", | ||
"version": "1.4.1", | ||
"author": "bokub", | ||
"bugs": "https://github.com/bokub/linky/issues", | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"axios": "^0.21.4", | ||
"chalk": "^4.1.0", | ||
"conf": "^7.1.2", | ||
"dayjs": "^1.10.7", | ||
"meow": "^7.1.1", | ||
@@ -19,3 +20,3 @@ "mkdirp": "^1.0.4", | ||
"@ava/typescript": "^1.1.1", | ||
"@bokub/prettier-config": "^1.0.1", | ||
"@bokub/prettier-config": "^1.1.0", | ||
"@types/mkdirp": "^1.0.1", | ||
@@ -25,12 +26,10 @@ "@types/qs": "^6.9.4", | ||
"ava": "^3.12.1", | ||
"codecov": "^3.7.2", | ||
"husky": "^7.0.0", | ||
"nyc": "^15.1.0", | ||
"pkg": "^4.4.9", | ||
"prettier": "^2.1.1", | ||
"prettier": "^2.5.1", | ||
"pretty-quick": "^3.1.3", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.2" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"homepage": "https://github.com/bokub/linky", | ||
@@ -57,8 +56,9 @@ "keywords": [ | ||
"scripts": { | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov", | ||
"test": "nyc ava --timeout=1m", | ||
"prepare": "husky install", | ||
"prepublish": "npm run build", | ||
"build": "rm -fr ./dist && tsc", | ||
"pkg": "rm -fr ./pkg && pkg . --out-path pkg -t node12-linux-x64,node12-macos-x64,node12-win-x64", | ||
"prettier": "prettier --write **/*.{ts,md,json,yml,html}", | ||
"pkg": "rm -fr ./pkg && pkg . --out-path pkg -t node14-linux-x64,node14-macos-x64,node14-win-x64", | ||
"prettier": "prettier --write .", | ||
"deploy": "vercel --prod && vercel" | ||
@@ -65,0 +65,0 @@ }, |
{ | ||
"name": "linky", | ||
"description": "Easily retrieve your Linky power consumption", | ||
"version": "1.3.0", | ||
"version": "1.4.1", | ||
"author": "bokub", | ||
"bugs": "https://github.com/bokub/linky/issues", | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"axios": "^0.21.4", | ||
"chalk": "^4.1.0", | ||
"conf": "^7.1.2", | ||
"dayjs": "^1.10.7", | ||
"meow": "^7.1.1", | ||
@@ -19,3 +20,3 @@ "mkdirp": "^1.0.4", | ||
"@ava/typescript": "^1.1.1", | ||
"@bokub/prettier-config": "^1.0.1", | ||
"@bokub/prettier-config": "^1.1.0", | ||
"@types/mkdirp": "^1.0.1", | ||
@@ -25,12 +26,10 @@ "@types/qs": "^6.9.4", | ||
"ava": "^3.12.1", | ||
"codecov": "^3.7.2", | ||
"husky": "^7.0.0", | ||
"nyc": "^15.1.0", | ||
"pkg": "^4.4.9", | ||
"prettier": "^2.1.1", | ||
"prettier": "^2.5.1", | ||
"pretty-quick": "^3.1.3", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.2" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"homepage": "https://github.com/bokub/linky", | ||
@@ -57,8 +56,9 @@ "keywords": [ | ||
"scripts": { | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov", | ||
"test": "nyc ava --timeout=1m", | ||
"prepare": "husky install", | ||
"prepublish": "npm run build", | ||
"build": "rm -fr ./dist && tsc", | ||
"pkg": "rm -fr ./pkg && pkg . --out-path pkg -t node12-linux-x64,node12-macos-x64,node12-win-x64", | ||
"prettier": "prettier --write **/*.{ts,md,json,yml,html}", | ||
"pkg": "rm -fr ./pkg && pkg . --out-path pkg -t node14-linux-x64,node14-macos-x64,node14-win-x64", | ||
"prettier": "prettier --write .", | ||
"deploy": "vercel --prod && vercel" | ||
@@ -65,0 +65,0 @@ }, |
@@ -58,16 +58,29 @@ # Linky | ||
```bash | ||
# Récupère la consommation quotidienne du 1er au 7 septembre 2020 inclus | ||
linky daily --start 2020-09-01 --end 2020-09-08 | ||
# Récupère la consommation quotidienne du 1er au 7 janvier 2022 inclus | ||
linky daily --start 2022-01-01 --end 2022-01-08 | ||
# Récupère la puissance moyenne consommée le 1er septembre 2020, sur un intervalle de 30 min | ||
linky loadcurve --start 2020-09-01 --end 2020-09-02 | ||
# Récupère la puissance moyenne consommée le 31 décembre 2021, sur un intervalle de 30 min | ||
linky loadcurve --start 2021-12-31 --end 2022-01-01 | ||
# Récupère la puissance maximale de consommation atteinte quotidiennement du 24 au 31 août inclus | ||
linky maxpower --start 2020-08-24 --end 2020-09-01 | ||
# Récupère la puissance maximale de consommation atteinte quotidiennement du 1er au 7 janvier 2022 inclus | ||
linky maxpower --start 2022-01-01 --end 2022-01-08 | ||
``` | ||
En l'absence des paramètres `--start` et `--end`, vous récupérez la consommation / puissance de la veille. | ||
```bash | ||
# Récupère la consommation de la journée d'hier | ||
linky daily | ||
# Récupère la puissance moyenne consommée pendant la journée d'hier, sur un intervalle de 30 min | ||
linky loadcurve | ||
# Récupère la puissance maximale de consommation atteinte durant la journée d'hier | ||
linky maxpower | ||
``` | ||
Vous pouvez sauvegarder vos résultats dans un fichier JSON grâce à l'option `--output` | ||
```bash | ||
linky loadcurve --start 2020-09-01 --end 2020-09-02 --output data/ma_conso.json | ||
linky loadcurve --start 2021-12-31 --end 2022-01-01 --output data/ma_conso.json | ||
``` | ||
@@ -109,4 +122,4 @@ | ||
// Récupère la consommation quotidienne du 1er au 7 septembre 2020 inclus | ||
session.getDailyConsumption('2020-09-01', '2020-09-08').then((result) => { | ||
// Récupère la consommation quotidienne du 1er au 7 janvier 2022 inclus | ||
session.getDailyConsumption('2022-01-01', '2022-01-08').then((result) => { | ||
console.log(result); | ||
@@ -123,4 +136,4 @@ /* | ||
// Récupère la puissance moyenne consommée le 1er septembre 2020, sur un intervalle de 30 min | ||
session.getLoadCurve('2020-09-01', '2020-09-02').then((result) => { | ||
// Récupère la puissance moyenne consommée le 31 décembre 2021, sur un intervalle de 30 min | ||
session.getLoadCurve('2021-12-31', '2022-01-01').then((result) => { | ||
console.log(result); | ||
@@ -137,4 +150,4 @@ /* | ||
// Récupère la puissance maximale de consommation atteinte quotidiennement du 24 au 31 août inclus | ||
session.getMaxPower('2020-08-24', '2020-09-01').then((result) => { | ||
// Récupère la puissance maximale de consommation atteinte quotidiennement du 1er au 7 janvier 2022 inclus | ||
session.getMaxPower('2022-01-01', '2022-01-08').then((result) => { | ||
console.log(result); | ||
@@ -141,0 +154,0 @@ /* |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
70378
527
169
9
13
+ Addeddayjs@^1.10.7
+ Addeddayjs@1.11.13(transitive)
Updatedaxios@^0.21.4