myenergi-api 2.2.0 → 2.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ export declare class Digest {
3
3
  private _baseUrl;
4
4
  private _maxRedirectCount;
5
5
  private _maxRetryCount;
6
+ private _etags;
6
7
  constructor(baseUrl: string, username: string, password: string);
7
8
  private request;
8
9
  get(requestUrl: URL, data?: unknown): Promise<string>;
@@ -28,6 +28,7 @@ const https = __importStar(require("https"));
28
28
  const AuthDigest_1 = require("./AuthDigest");
29
29
  class Digest {
30
30
  constructor(baseUrl, username, password) {
31
+ this._etags = {};
31
32
  this._maxRedirectCount = 3;
32
33
  this._maxRetryCount = 2;
33
34
  this._baseUrl = new URL(baseUrl);
@@ -42,9 +43,13 @@ class Digest {
42
43
  if (!options.headers)
43
44
  options.headers = {};
44
45
  options.headers.Authorization = (_a = this._authDigest) === null || _a === void 0 ? void 0 : _a.getAuthorization(options.method, options.path);
46
+ const etag = this._etags[options.path];
47
+ if (etag)
48
+ options.headers["If-None-Match"] = etag;
45
49
  const req = https.request(options, (res) => {
46
50
  var _a, _b;
47
51
  if (res.statusCode == 401) {
52
+ this._etags[options.path] = res.headers.etag;
48
53
  const myenergiAsn = res.headers["x_myenergi-asn"];
49
54
  if (myenergiAsn && myenergiAsn !== "undefined" && myenergiAsn !== this._baseUrl.host) {
50
55
  if (redirectCount > this._maxRedirectCount) {
@@ -115,6 +120,10 @@ class Digest {
115
120
  });
116
121
  }
117
122
  else if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400) {
123
+ if (res.statusCode == 304) {
124
+ resolve("{}");
125
+ return;
126
+ }
118
127
  if (redirectCount > this._maxRedirectCount) {
119
128
  reject(`Too many redirects: ${res.headers["location"]}`);
120
129
  return;
@@ -134,13 +143,11 @@ class Digest {
134
143
  });
135
144
  }
136
145
  else {
137
- console.error("status code failed!!");
138
146
  reject("status code failed!!");
139
147
  return;
140
148
  }
141
149
  });
142
150
  req.on("error", (e) => {
143
- console.error(`problem with request: ${e.message}`);
144
151
  reject(e);
145
152
  });
146
153
  if (data) {
@@ -1,3 +1,4 @@
1
+ import { AppKeyValues } from './models/AppKeyValues';
1
2
  import { Eddi } from "./models/Eddi";
2
3
  import { Harvi } from "./models/Harvi";
3
4
  import { KeyValue } from './models/KeyValue';
@@ -19,6 +20,7 @@ export declare class MyEnergi {
19
20
  setEddiBoost(serialNo: string, boost: EddiBoost, minutes?: number): Promise<any>;
20
21
  getStatusHarviAll(): Promise<Harvi[]>;
21
22
  getStatusHarvi(serialNumber: string): Promise<Harvi | null>;
23
+ getAppKeyFull(key: string): Promise<AppKeyValues | null>;
22
24
  getAppKey(key: string): Promise<KeyValue[] | null>;
23
25
  setAppKey(key: string, val: string): Promise<KeyValue[] | null>;
24
26
  }
@@ -228,6 +228,22 @@ class MyEnergi {
228
228
  }
229
229
  });
230
230
  }
231
+ getAppKeyFull(key) {
232
+ return __awaiter(this, void 0, void 0, function* () {
233
+ try {
234
+ const data = yield this._digest.get(new URL(`${this._config.get_app_key_url}-${key}`, this._config.base_url));
235
+ const jsonData = JSON.parse(data);
236
+ if (jsonData) {
237
+ const result = Object.assign({}, jsonData);
238
+ return result;
239
+ }
240
+ }
241
+ catch (error) {
242
+ return null;
243
+ }
244
+ return null;
245
+ });
246
+ }
231
247
  getAppKey(key) {
232
248
  return __awaiter(this, void 0, void 0, function* () {
233
249
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "myenergi-api",
3
- "version": "2.2.0",
3
+ "version": "2.4.0-beta.0",
4
4
  "description": "NodeJS implementation of MyEnergi API for controlling Zappi, Eddi and other MyEnergi products",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",