bkper-js 1.46.0 → 1.47.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/lib/index.d.ts CHANGED
@@ -745,6 +745,8 @@ export declare class Book {
745
745
 
746
746
 
747
747
 
748
+
749
+
748
750
  constructor(payload?: bkper.Book);
749
751
  /**
750
752
  * @returns An immutable copy of the json payload
@@ -1094,6 +1096,10 @@ export declare class Book {
1094
1096
 
1095
1097
 
1096
1098
 
1099
+
1100
+
1101
+
1102
+
1097
1103
  /**
1098
1104
  * Gets a [[Group]] object
1099
1105
  *
@@ -2757,9 +2763,17 @@ export declare class Transaction {
2757
2763
  */
2758
2764
  getCreatedAt(): Date;
2759
2765
  /**
2760
- * @returns The date the transaction was created, formatted according to the date pattern of [[Book]].
2766
+ * @returns The date the transaction was created, formatted according to the date pattern of the [[Book]].
2761
2767
  */
2762
2768
  getCreatedAtFormatted(): string;
2769
+ /**
2770
+ * @returns The date the transaction was last updated.
2771
+ */
2772
+ getUpdatedAt(): Date;
2773
+ /**
2774
+ * @returns The date the transaction was last updated, formatted according to the date pattern of the [[Book]].
2775
+ */
2776
+ getUpdatedAtFormatted(): string;
2763
2777
 
2764
2778
 
2765
2779
  /**
package/lib/model/Book.js CHANGED
@@ -643,36 +643,75 @@ export class Book {
643
643
  if (!idOrName || idOrName.trim() == '') {
644
644
  return undefined;
645
645
  }
646
+ let account;
647
+ // Try to get account by id
646
648
  if (this.idAccountMap) {
647
- return this.idAccountMap.get(idOrName);
649
+ account = this.idAccountMap.get(idOrName);
648
650
  }
649
- else {
651
+ // Try to get account by name
652
+ if (!account && this.nameAccountMap) {
653
+ account = this.nameAccountMap.get(idOrName);
654
+ }
655
+ // Try to fetch account from server
656
+ if (!account) {
650
657
  const accountPayload = yield AccountService.getAccount(this.getId(), idOrName);
651
658
  if (accountPayload) {
652
- return new Account(this, accountPayload);
659
+ account = new Account(this, accountPayload);
653
660
  }
654
661
  }
655
- return undefined;
662
+ return account;
656
663
  });
657
664
  }
658
665
  /** @internal */
659
666
  updateGroupCache(group) {
667
+ this.updateGroupIdMap(group);
668
+ this.updateGroupNameMap(group);
669
+ if (this.idGroupMap) {
670
+ group.buildGroupTree(this.idGroupMap);
671
+ }
672
+ }
673
+ /** @internal */
674
+ updateGroupIdMap(group) {
660
675
  if (this.idGroupMap) {
661
676
  const id = group.getId();
662
677
  if (id) {
663
678
  this.idGroupMap.set(id, group);
664
679
  }
665
- group.buildGroupTree(this.idGroupMap);
680
+ }
681
+ }
682
+ /** @internal */
683
+ updateGroupNameMap(group) {
684
+ if (this.nameGroupMap) {
685
+ const normalizedName = group.getNormalizedName();
686
+ if (normalizedName) {
687
+ this.nameGroupMap.set(normalizedName, group);
688
+ }
666
689
  }
667
690
  }
668
691
  /** @internal */
669
692
  updateAccountCache(account) {
693
+ this.updateAccountIdMap(account);
694
+ this.updateAccountNameMap(account);
695
+ if (this.idAccountMap || this.nameAccountMap) {
696
+ this.linkAccountsAndGroups(account);
697
+ }
698
+ }
699
+ /** @internal */
700
+ updateAccountIdMap(account) {
670
701
  if (this.idAccountMap) {
671
702
  const id = account.getId();
672
703
  if (id) {
673
704
  this.idAccountMap.set(id, account);
674
705
  }
675
- this.linkAccountsAndGroups(account);
706
+ }
707
+ }
708
+ /** @internal */
709
+ updateAccountNameMap(account) {
710
+ if (this.nameAccountMap) {
711
+ const normalizedName = account.getNormalizedName();
712
+ if (normalizedName) {
713
+ this.nameAccountMap.set(normalizedName, account);
714
+ }
676
715
  }
677
716
  }
678
717
  /** @internal */
@@ -718,16 +757,23 @@ export class Book {
718
757
  if (!idOrName || idOrName.trim() == '') {
719
758
  return undefined;
720
759
  }
760
+ let group;
761
+ // Try to get group by id
721
762
  if (this.idGroupMap) {
722
- return this.idGroupMap.get(idOrName);
763
+ group = this.idGroupMap.get(idOrName);
723
764
  }
724
- else {
765
+ // Try to get group by name
766
+ if (!group && this.nameGroupMap) {
767
+ group = this.nameGroupMap.get(idOrName);
768
+ }
769
+ // Try to fetch group from server
770
+ if (!group) {
725
771
  const groupPayload = yield GroupService.getGroup(this.getId(), idOrName);
726
772
  if (groupPayload) {
727
- return new Group(this, groupPayload);
773
+ group = new Group(this, groupPayload);
728
774
  }
729
775
  }
730
- return undefined;
776
+ return group;
731
777
  });
732
778
  }
733
779
  /**
@@ -751,6 +797,7 @@ export class Book {
751
797
  }
752
798
  let groupsObj = groups.map(group => new Group(this, group));
753
799
  this.idGroupMap = new Map();
800
+ this.nameGroupMap = new Map();
754
801
  for (const group of groupsObj) {
755
802
  this.updateGroupCache(group);
756
803
  }
@@ -780,6 +827,7 @@ export class Book {
780
827
  }
781
828
  let accountsObj = accounts.map(account => new Account(this, account));
782
829
  this.idAccountMap = new Map();
830
+ this.nameAccountMap = new Map();
783
831
  for (const account of accountsObj) {
784
832
  this.updateAccountCache(account);
785
833
  }
@@ -804,10 +852,12 @@ export class Book {
804
852
  /** @internal */
805
853
  clearGroupCache() {
806
854
  this.idGroupMap = undefined;
855
+ this.nameGroupMap = undefined;
807
856
  }
808
857
  /** @internal */
809
858
  clearAccountCache() {
810
859
  this.idAccountMap = undefined;
860
+ this.nameAccountMap = undefined;
811
861
  }
812
862
  /** @internal */
813
863
  setAccount(account, remove) {
@@ -343,12 +343,12 @@ export class Group {
343
343
  }
344
344
  }
345
345
  /** @internal */
346
- buildGroupTree(groupsMap) {
346
+ buildGroupTree(idGroupMap) {
347
347
  this.parent = undefined;
348
348
  this.depth = undefined;
349
349
  this.root = undefined;
350
350
  if (this.payload.parent) {
351
- const parentGroup = groupsMap.get(this.payload.parent.id || "");
351
+ const parentGroup = idGroupMap.get(this.payload.parent.id || "");
352
352
  if (parentGroup) {
353
353
  this.parent = parentGroup;
354
354
  parentGroup.addChild(this);
@@ -617,11 +617,23 @@ export class Transaction {
617
617
  return new Date(new Number(this.payload.createdAt).valueOf());
618
618
  }
619
619
  /**
620
- * @returns The date the transaction was created, formatted according to the date pattern of [[Book]].
620
+ * @returns The date the transaction was created, formatted according to the date pattern of the [[Book]].
621
621
  */
622
622
  getCreatedAtFormatted() {
623
623
  return Utils.formatDate(this.getCreatedAt(), this.book.getTimeZone(), this.book.getDatePattern() + " HH:mm:ss");
624
624
  }
625
+ /**
626
+ * @returns The date the transaction was last updated.
627
+ */
628
+ getUpdatedAt() {
629
+ return new Date(new Number(this.payload.updatedAt).valueOf());
630
+ }
631
+ /**
632
+ * @returns The date the transaction was last updated, formatted according to the date pattern of the [[Book]].
633
+ */
634
+ getUpdatedAtFormatted() {
635
+ return Utils.formatDate(this.getUpdatedAt(), this.book.getTimeZone(), this.book.getDatePattern() + " HH:mm:ss");
636
+ }
625
637
  //EVOLVED BALANCES
626
638
  /** @internal */
627
639
  getCaEvolvedBalance_() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "1.46.0",
3
+ "version": "1.47.0",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -34,7 +34,7 @@
34
34
  "postversion": "git push --tags && yarn publish --new-version $npm_package_version && git push && echo \"Successfully released version $npm_package_version!\""
35
35
  },
36
36
  "peerDependencies": {
37
- "@bkper/bkper-api-types": "^5.21.0"
37
+ "@bkper/bkper-api-types": "^5.22.0"
38
38
  },
39
39
  "dependencies": {
40
40
  "@google-cloud/local-auth": "^3.0.1",