chia-agent 13.2.0 → 14.0.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.
package/config/index.js CHANGED
@@ -43,7 +43,7 @@ function getConfig(configFilePath) {
43
43
  exports.getConfig = getConfig;
44
44
  function buildConfigObj(config, currentPath = [], product = {}) {
45
45
  for (const propName in config) {
46
- if (!config.hasOwnProperty(propName)) {
46
+ if (!Object.prototype.hasOwnProperty.call(config, propName)) {
47
47
  continue;
48
48
  }
49
49
  const value = config[propName];
package/daemon/index.js CHANGED
@@ -119,7 +119,6 @@ class Daemon {
119
119
  reject("Not connected");
120
120
  return;
121
121
  }
122
- let timer = null;
123
122
  const message = this.createMessageTemplate(command, destination, data || {});
124
123
  const reqId = message.request_id;
125
124
  this._responseQueue[reqId] = resolve;
@@ -262,7 +261,7 @@ class Daemon {
262
261
  }
263
262
  this._messageEventListeners.forEach(l => l(event));
264
263
  for (const o in this._messageListeners) {
265
- if (!this._messageListeners.hasOwnProperty(o)) {
264
+ if (!Object.prototype.hasOwnProperty.call(this._messageListeners, o)) {
266
265
  continue;
267
266
  }
268
267
  const listeners = this._messageListeners[o];
@@ -283,7 +282,7 @@ class Daemon {
283
282
  this._subscriptions = [];
284
283
  this._closeEventListeners.forEach(l => l(event));
285
284
  this.clearAllEventListeners();
286
- logger_1.getLogger().info(`Closed ws connection`);
285
+ logger_1.getLogger().info("Closed ws connection");
287
286
  if (this._onClosePromise) {
288
287
  this._onClosePromise();
289
288
  this._onClosePromise = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chia-agent",
3
- "version": "13.2.0",
3
+ "version": "14.0.0-beta.0",
4
4
  "author": "ChiaMineJP <admin@chiamine.jp>",
5
5
  "description": "chia rpc/websocket client library",
6
6
  "license": "MIT",
package/rpc/index.d.ts CHANGED
@@ -32,10 +32,6 @@ export declare type TRPCAgentProps = {
32
32
  configPath?: string;
33
33
  skip_hostname_verification?: boolean;
34
34
  };
35
- export declare type ErrorResponse = {
36
- error: string;
37
- success: false;
38
- };
39
35
  export declare class RPCAgent {
40
36
  protected _protocol: "http" | "https";
41
37
  protected _hostname: string;
@@ -52,7 +48,7 @@ export declare class RPCAgent {
52
48
  clientKey: Buffer;
53
49
  caCert: Buffer;
54
50
  };
55
- sendMessage<M extends unknown>(destination: string, command: string, data?: Record<string, unknown>): Promise<M | ErrorResponse>;
51
+ sendMessage<M extends unknown>(destination: string, command: string, data?: Record<string, unknown>): Promise<M>;
56
52
  request<R>(method: string, path: string, data?: any): Promise<R>;
57
53
  }
58
54
  export declare type TRPCAgent = InstanceType<typeof RPCAgent>;
package/rpc/index.js CHANGED
@@ -198,7 +198,7 @@ class RPCAgent {
198
198
  }
199
199
  p += "?";
200
200
  for (const key in data) {
201
- if (data.hasOwnProperty(key)) {
201
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
202
202
  p += `${key}=${data[key]}`;
203
203
  }
204
204
  }
@@ -228,7 +228,21 @@ class RPCAgent {
228
228
  res.on("end", () => {
229
229
  try {
230
230
  if (chunks.length > 0) {
231
- const d = JSONbig.parse(Buffer.concat(chunks).toString());
231
+ const entireChunks = Buffer.concat(chunks);
232
+ const serializedData = entireChunks.toString();
233
+ const d = JSONbig.parse(serializedData);
234
+ if (typeof d !== "object" || !d) {
235
+ logger_1.getLogger().error(`Response is expected to be an object but received: ${serializedData}`);
236
+ return reject(new Error(`Unexpected response format: ${serializedData}`));
237
+ }
238
+ else if (!Object.prototype.hasOwnProperty.call(d, "success")) {
239
+ logger_1.getLogger().error("Response has no 'success' property");
240
+ return reject(new Error(`Response has no 'success' property: ${serializedData}`));
241
+ }
242
+ if (!d.success) {
243
+ logger_1.getLogger().error(`API failure: ${d.error}`);
244
+ return reject(d);
245
+ }
232
246
  return resolve(d);
233
247
  }
234
248
  // RPC Server should return response like