@xelis/sdk 0.5.0 → 0.5.1

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/lib/rpc.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { RPCResponse } from './types';
2
2
  export declare class RPC {
3
3
  endpoint: string;
4
+ timeout: number;
4
5
  constructor(endpoint: string);
5
6
  post<T>(method: string, params?: any): Promise<RPCResponse<T>>;
6
7
  }
package/lib/rpc.js CHANGED
@@ -1,11 +1,21 @@
1
1
  export class RPC {
2
2
  constructor(endpoint) {
3
3
  this.endpoint = endpoint;
4
+ this.timeout = 3000;
4
5
  }
5
6
  async post(method, params) {
6
7
  try {
8
+ const controller = new AbortController();
7
9
  const body = JSON.stringify({ id: 1, jsonrpc: '2.0', method: method, params });
8
- const res = await fetch(this.endpoint, { method: `POST`, body });
10
+ const timeoutId = setTimeout(() => {
11
+ controller.abort();
12
+ }, this.timeout);
13
+ const res = await fetch(this.endpoint, {
14
+ method: `POST`,
15
+ body,
16
+ signal: controller.signal
17
+ });
18
+ clearTimeout(timeoutId);
9
19
  if (res.ok) {
10
20
  const data = await res.json();
11
21
  if (data.error) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.0",
2
+ "version": "0.5.1",
3
3
  "name": "@xelis/sdk",
4
4
  "description": "Xelis software development kit for JS",
5
5
  "repository": {