bkper-js 1.15.0 → 1.16.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/index.d.ts CHANGED
@@ -755,6 +755,7 @@ export declare class Book {
755
755
 
756
756
 
757
757
 
758
+
758
759
  /**
759
760
  * Gets a [[Group]] object
760
761
  *
@@ -1630,6 +1631,10 @@ export declare class Transaction {
1630
1631
  * @returns True if transaction is in trash.
1631
1632
  */
1632
1633
  isTrashed(): boolean | undefined;
1634
+ /**
1635
+ * @returns True if a transaction is locked by the book lock/closing date
1636
+ */
1637
+ isLocked(): boolean;
1633
1638
  /**
1634
1639
  * @returns All #hashtags used on the transaction.
1635
1640
  */
package/lib/model/Book.js CHANGED
@@ -510,6 +510,26 @@ export class Book {
510
510
  this.idAccountMap.delete(account.getId() || '');
511
511
  }
512
512
  }
513
+ /** @internal */
514
+ getMostRecentLockDate_() {
515
+ const closingDate = this.getClosingDate();
516
+ const lockDate = this.getLockDate();
517
+ if (!closingDate && !lockDate) {
518
+ return null;
519
+ }
520
+ if (!closingDate && lockDate) {
521
+ return lockDate;
522
+ }
523
+ if (closingDate && !lockDate) {
524
+ return closingDate;
525
+ }
526
+ if (Utils.getIsoDateValue(closingDate) > Utils.getIsoDateValue(lockDate)) {
527
+ return closingDate;
528
+ }
529
+ else {
530
+ return lockDate;
531
+ }
532
+ }
513
533
  /**
514
534
  * Gets a [[Group]] object
515
535
  *
@@ -104,6 +104,14 @@ export class Transaction {
104
104
  isTrashed() {
105
105
  return this.payload.trashed;
106
106
  }
107
+ /**
108
+ * @returns True if a transaction is locked by the book lock/closing date
109
+ */
110
+ isLocked() {
111
+ const date = this.getDate() || Utils.formatDateISO(new Date(), this.book.getTimeZone());
112
+ const lockOrClosingDate = this.book.getMostRecentLockDate_();
113
+ return lockOrClosingDate != null && (Utils.getIsoDateValue(lockOrClosingDate) >= Utils.getIsoDateValue(date));
114
+ }
107
115
  /**
108
116
  * @returns All #hashtags used on the transaction.
109
117
  */
@@ -42,7 +42,7 @@ export class HttpApiRequest extends HttpRequest {
42
42
  if (errorResp.status == 404) {
43
43
  return { data: null };
44
44
  }
45
- else if (this.retry <= 3) {
45
+ else if (errorResp.status != 400 && this.retry <= 3) {
46
46
  this.retry++;
47
47
  if (HttpApiRequest.config.requestRetryHandler) {
48
48
  yield HttpApiRequest.config.requestRetryHandler(errorResp.status, errorResp.data, this.retry);
package/lib/utils.js CHANGED
@@ -119,6 +119,9 @@ export function formatDateISO(date, timeZone) {
119
119
  var formatedDate = DateTime.fromJSDate(date, { zone: timeZone }).toISODate();
120
120
  return formatedDate;
121
121
  }
122
+ export function getIsoDateValue(date) {
123
+ return +(date.replace(/-/g, ''));
124
+ }
122
125
  export function parseDate(date, pattern, timeZone) {
123
126
  if (!pattern) {
124
127
  pattern = 'yyyy-MM-dd';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.15.0",
3
+ "version": "1.16.1",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",