bkper-js 1.2.3 → 1.2.5

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.
@@ -16,7 +16,7 @@ export function createAccount(bookId, account) {
16
16
  }
17
17
  export function updateAccount(bookId, account) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
- var payload = JSON.stringify(account);
19
+ var payload = account;
20
20
  var response = yield new HttpBooksApiV5Request(`${bookId}/accounts`).setMethod('PUT').setPayload(payload).fetch();
21
21
  return response.data;
22
22
  });
@@ -27,37 +27,65 @@ export class HttpApiRequest extends HttpRequest {
27
27
  if (resp.status >= 200 && resp.status < 300) {
28
28
  return resp;
29
29
  }
30
- else if (resp.status == 404) {
31
- return { data: null };
30
+ else {
31
+ throw this.handleError(resp);
32
32
  }
33
- else if (this.retry <= 3) {
34
- this.retry++;
35
- if (HttpApiRequest.config.requestRetryHandler) {
36
- yield HttpApiRequest.config.requestRetryHandler(resp.status, resp.data, this.retry);
33
+ }
34
+ catch (error) {
35
+ if (error.response) {
36
+ let errorResp = error.response;
37
+ // The request was made and the server responded with a status code
38
+ // that falls out of the range of 2xx
39
+ // console.log(error.response.data);
40
+ // console.log(error.response.status);
41
+ // console.log(error.response.headers);
42
+ if (errorResp.status == 404) {
43
+ return { data: null };
37
44
  }
38
- else {
39
- console.log(`${resp.data} - Retrying... `);
45
+ else if (this.retry <= 3) {
46
+ this.retry++;
47
+ if (HttpApiRequest.config.requestRetryHandler) {
48
+ yield HttpApiRequest.config.requestRetryHandler(errorResp.status, errorResp.data, this.retry);
49
+ }
50
+ else {
51
+ console.log(`${JSON.stringify(errorResp.data)} - Retrying... `);
52
+ }
53
+ return yield this.fetch();
54
+ }
55
+ throw this.handleError(errorResp);
56
+ }
57
+ else if (error.request) {
58
+ // The request was made but no response was received
59
+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
60
+ // http.ClientRequest in node.js
61
+ if (this.retry <= 3) {
62
+ this.retry++;
63
+ if (HttpApiRequest.config.requestRetryHandler) {
64
+ yield HttpApiRequest.config.requestRetryHandler(520, undefined, this.retry);
65
+ }
66
+ else {
67
+ console.log(`No response received - Retrying... `);
68
+ }
69
+ return yield this.fetch();
40
70
  }
41
- return yield this.fetch();
42
71
  }
43
72
  else {
44
- throw this.handleError(resp.data);
73
+ // Something happened in setting up the request that triggered an Error
74
+ console.log('Error', error.message);
45
75
  }
46
- }
47
- catch (err) {
48
- throw this.handleError(err.toJSON ? err.toJSON() : err);
76
+ throw this.handleError(error.toJSON ? error.toJSON() : error);
49
77
  }
50
78
  });
51
79
  }
52
80
  handleError(err) {
53
- var _a, _b;
81
+ var _a, _b, _c;
54
82
  const customError = HttpApiRequest.config.requestErrorHandler ? HttpApiRequest.config.requestErrorHandler(err) : undefined;
55
83
  if (customError) {
56
84
  return customError;
57
85
  }
58
86
  else {
59
87
  //Default error handler
60
- let error = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error;
88
+ let error = ((_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error) || ((_c = err.data) === null || _c === void 0 ? void 0 : _c.error) || err.error;
61
89
  if (error) {
62
90
  return error.message;
63
91
  }
@@ -19,7 +19,7 @@ export function createTransactionsBatch(bookId, transactions) {
19
19
  let transactionList = {
20
20
  items: transactions
21
21
  };
22
- var payload = JSON.stringify(transactionList);
22
+ var payload = transactionList;
23
23
  let response = yield new HttpBooksApiV5Request(`${bookId}/transactions/batch`)
24
24
  .setMethod('POST')
25
25
  .setPayload(payload)
@@ -33,7 +33,7 @@ export function trashTransactionsBatch(bookId, transactions) {
33
33
  let transactionList = {
34
34
  items: transactions
35
35
  };
36
- var payload = JSON.stringify(transactionList);
36
+ var payload = transactionList;
37
37
  let response = yield new HttpBooksApiV5Request(`${bookId}/transactions/trash/batch`)
38
38
  .setMethod('PATCH')
39
39
  .setPayload(payload)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -25,7 +25,7 @@
25
25
  "build:cleanup": "rimraf lib/**/*.map lib/*.map lib/**/*.d.ts lib/*.d.ts",
26
26
  "build:dts": "cp dist/bkper-js-public.d.ts lib/index.d.ts",
27
27
  "build:clean-dist": "rimraf dist",
28
- "watch": "tsc -w",
28
+ "dev": "tsc -w",
29
29
  "upgrade:api": "bun update @bkper/bkper-api-types --latest",
30
30
  "patch": "yarn version --patch",
31
31
  "minor": "yarn version --minor",