bkper-js 2.15.1 → 2.16.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
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * @public
17
17
  */
18
- export declare class Account extends Resource<bkper.Account> {
18
+ export declare class Account extends ResourceProperty<bkper.Account> {
19
19
 
20
20
  constructor(book: Book, payload?: bkper.Account);
21
21
 
@@ -65,49 +65,6 @@ export declare class Account extends Resource<bkper.Account> {
65
65
  * @returns This Account, for chaining
66
66
  */
67
67
  setType(type: AccountType): Account;
68
- /**
69
- * Gets the custom properties stored in this Account.
70
- *
71
- * @returns The custom properties object
72
- */
73
- getProperties(): {
74
- [key: string]: string;
75
- };
76
- /**
77
- * Sets the custom properties of the Account.
78
- *
79
- * @param properties - Object with key/value pair properties
80
- *
81
- * @returns This Account, for chaining
82
- */
83
- setProperties(properties: {
84
- [key: string]: string;
85
- }): Account;
86
- /**
87
- * Gets the property value for given keys. First property found will be retrieved.
88
- *
89
- * @param keys - The property key
90
- *
91
- * @returns The property value or undefined if not found
92
- */
93
- getProperty(...keys: string[]): string | undefined;
94
- /**
95
- * Sets a custom property in the Account.
96
- *
97
- * @param key - The property key
98
- * @param value - The property value, or null/undefined to clean it
99
- *
100
- * @returns This Account, for chaining
101
- */
102
- setProperty(key: string, value: string | null | undefined): Account;
103
- /**
104
- * Deletes a custom property.
105
- *
106
- * @param key - The property key
107
- *
108
- * @returns This Account, for chaining
109
- */
110
- deleteProperty(key: string): Account;
111
68
  /**
112
69
  * Tells if this Account is archived.
113
70
  *
@@ -1306,7 +1263,7 @@ export declare class Bkper {
1306
1263
  *
1307
1264
  * @public
1308
1265
  */
1309
- export declare class Book extends Resource<bkper.Book> {
1266
+ export declare class Book extends ResourceProperty<bkper.Book> {
1310
1267
  private config?;
1311
1268
  private allGroupsLoaded;
1312
1269
  private allAccountsLoaded;
@@ -1548,41 +1505,6 @@ export declare class Book extends Resource<bkper.Book> {
1548
1505
  * @returns This Book, for chaining
1549
1506
  */
1550
1507
  setVisibility(visibility: Visibility): Book;
1551
- /**
1552
- * Gets the custom properties stored in this Book.
1553
- *
1554
- * @returns The custom properties object
1555
- */
1556
- getProperties(): {
1557
- [key: string]: string;
1558
- };
1559
- /**
1560
- * Gets the property value for given keys. First property found will be retrieved.
1561
- *
1562
- * @param keys - The property keys to search for
1563
- *
1564
- * @returns The property value or undefined if not found
1565
- */
1566
- getProperty(...keys: string[]): string | undefined;
1567
- /**
1568
- * Sets the custom properties of the Book.
1569
- *
1570
- * @param properties - Object with key/value pair properties
1571
- *
1572
- * @returns This Book, for chaining
1573
- */
1574
- setProperties(properties: {
1575
- [key: string]: string;
1576
- }): Book;
1577
- /**
1578
- * Sets a custom property in the Book.
1579
- *
1580
- * @param key - The property key
1581
- * @param value - The property value, or null/undefined to clean it
1582
- *
1583
- * @returns This Book, for chaining
1584
- */
1585
- setProperty(key: string, value: string | null | undefined): Book;
1586
1508
  /**
1587
1509
  * Formats a date according to date pattern of the Book.
1588
1510
  *
@@ -2238,7 +2160,7 @@ export declare interface Config {
2238
2160
  *
2239
2161
  * @public
2240
2162
  */
2241
- export declare class Connection extends Resource<bkper.Connection> {
2163
+ export declare class Connection extends ResourceProperty<bkper.Connection> {
2242
2164
  private config?;
2243
2165
  constructor(payload?: bkper.Connection, config?: Config);
2244
2166
 
@@ -2322,59 +2244,10 @@ export declare class Connection extends Resource<bkper.Connection> {
2322
2244
  * @returns The Connection, for chaining
2323
2245
  */
2324
2246
  setType(type: "APP" | "BANK"): Connection;
2325
- /**
2326
- * Gets the custom properties stored in the Connection
2327
- *
2328
- * @returns Object with key/value pair properties
2329
- */
2330
- getProperties(): {
2331
- [key: string]: string;
2332
- };
2333
- /**
2334
- * Sets the custom properties of the Connection.
2335
- *
2336
- * @param properties - Object with key/value pair properties
2337
- *
2338
- * @returns The Connection, for chaining
2339
- */
2340
- setProperties(properties: {
2341
- [key: string]: string;
2342
- }): Connection;
2343
- /**
2344
- * Gets the property value for given keys. First property found will be retrieved.
2345
- *
2346
- * @param keys - The property key
2347
- *
2348
- * @returns The retrieved property value
2349
- */
2350
- getProperty(...keys: string[]): string | undefined;
2351
- /**
2352
- * Sets a custom property in the Connection.
2353
- *
2354
- * @param key - The property key
2355
- * @param value - The property value, or null/undefined to clean it
2356
- *
2357
- * @returns The Connection, for chaining
2358
- */
2359
- setProperty(key: string, value: string | null | undefined): Connection;
2360
- /**
2361
- * Deletes a custom property stored in the Connection.
2362
- *
2363
- * @param key - The property key
2364
- *
2365
- * @returns The Connection, for chaining
2366
- */
2367
- deleteProperty(key: string): Connection;
2368
2247
  /**
2369
2248
  * Cleans any token property stored in the Connection.
2370
2249
  */
2371
2250
  clearTokenProperties(): void;
2372
- /**
2373
- * Gets the custom properties keys stored in the Connection.
2374
- *
2375
- * @returns The retrieved property keys
2376
- */
2377
- getPropertyKeys(): string[];
2378
2251
  /**
2379
2252
  * Gets the existing [[Integrations]] on the Connection.
2380
2253
  *
@@ -2559,7 +2432,7 @@ export declare enum EventType {
2559
2432
  *
2560
2433
  * @public
2561
2434
  */
2562
- export declare class File extends Resource<bkper.File> {
2435
+ export declare class File extends ResourceProperty<bkper.File> {
2563
2436
 
2564
2437
  constructor(book: Book, payload?: bkper.File);
2565
2438
  /**
@@ -2629,49 +2502,6 @@ export declare class File extends Resource<bkper.File> {
2629
2502
  * @returns The file size in bytes
2630
2503
  */
2631
2504
  getSize(): number | undefined;
2632
- /**
2633
- * Gets the custom properties stored in this File.
2634
- *
2635
- * @returns The custom properties object
2636
- */
2637
- getProperties(): {
2638
- [key: string]: string;
2639
- };
2640
- /**
2641
- * Sets the custom properties of the File.
2642
- *
2643
- * @param properties - Object with key/value pair properties
2644
- *
2645
- * @returns This File, for chaining
2646
- */
2647
- setProperties(properties: {
2648
- [key: string]: string;
2649
- }): File;
2650
- /**
2651
- * Gets the property value for given keys. First property found will be retrieved.
2652
- *
2653
- * @param keys - The property key
2654
- *
2655
- * @returns The property value or undefined if not found
2656
- */
2657
- getProperty(...keys: string[]): string | undefined;
2658
- /**
2659
- * Sets a custom property in the File.
2660
- *
2661
- * @param key - The property key
2662
- * @param value - The property value, or null/undefined to clean it
2663
- *
2664
- * @returns This File, for chaining
2665
- */
2666
- setProperty(key: string, value: string | null | undefined): File;
2667
- /**
2668
- * Deletes a custom property.
2669
- *
2670
- * @param key - The property key
2671
- *
2672
- * @returns This File, for chaining
2673
- */
2674
- deleteProperty(key: string): File;
2675
2505
  /**
2676
2506
  * Perform create new File.
2677
2507
  *
@@ -2689,7 +2519,7 @@ export declare class File extends Resource<bkper.File> {
2689
2519
  *
2690
2520
  * @public
2691
2521
  */
2692
- export declare class Group extends Resource<bkper.Group> {
2522
+ export declare class Group extends ResourceProperty<bkper.Group> {
2693
2523
 
2694
2524
 
2695
2525
 
@@ -2756,49 +2586,6 @@ export declare class Group extends Resource<bkper.Group> {
2756
2586
  * @returns The type for of the accounts of this group. Null if mixed
2757
2587
  */
2758
2588
  getType(): AccountType;
2759
- /**
2760
- * Gets the custom properties stored in this Group.
2761
- *
2762
- * @returns The custom properties as a key/value object
2763
- */
2764
- getProperties(): {
2765
- [key: string]: string;
2766
- };
2767
- /**
2768
- * Sets the custom properties of the Group
2769
- *
2770
- * @param properties - Object with key/value pair properties
2771
- *
2772
- * @returns This Group, for chaining
2773
- */
2774
- setProperties(properties: {
2775
- [key: string]: string;
2776
- }): Group;
2777
- /**
2778
- * Gets the property value for given keys. First property found will be retrieved.
2779
- *
2780
- * @param keys - The property key
2781
- *
2782
- * @returns The property value, or undefined if not found
2783
- */
2784
- getProperty(...keys: string[]): string | undefined;
2785
- /**
2786
- * Sets a custom property in the Group.
2787
- *
2788
- * @param key - The property key
2789
- * @param value - The property value, or null/undefined to clean it
2790
- *
2791
- * @returns This Group, for chaining
2792
- */
2793
- setProperty(key: string, value: string | null | undefined): Group;
2794
- /**
2795
- * Delete a custom property
2796
- *
2797
- * @param key - The property key
2798
- *
2799
- * @returns This Group, for chaining
2800
- */
2801
- deleteProperty(key: string): Group;
2802
2589
  /**
2803
2590
  * Tells if the Group is hidden on main transactions menu.
2804
2591
  *
@@ -2941,7 +2728,7 @@ export declare class Group extends Resource<bkper.Group> {
2941
2728
  *
2942
2729
  * @public
2943
2730
  */
2944
- export declare class Integration extends Resource<bkper.Integration> {
2731
+ export declare class Integration extends ResourceProperty<bkper.Integration> {
2945
2732
  private config?;
2946
2733
  constructor(payload?: bkper.Integration, config?: Config);
2947
2734
 
@@ -3007,49 +2794,6 @@ export declare class Integration extends Resource<bkper.Integration> {
3007
2794
  * @returns The Integration last update date in milliseconds
3008
2795
  */
3009
2796
  getLastUpdateMs(): string | undefined;
3010
- /**
3011
- * Gets the custom properties stored in the Integration.
3012
- *
3013
- * @returns Object with key/value pair properties
3014
- */
3015
- getProperties(): {
3016
- [key: string]: string;
3017
- };
3018
- /**
3019
- * Sets the custom properties of the Integration.
3020
- *
3021
- * @param properties - Object with key/value pair properties
3022
- *
3023
- * @returns The Integration, for chaining
3024
- */
3025
- setProperties(properties: {
3026
- [key: string]: string;
3027
- }): Integration;
3028
- /**
3029
- * Gets the property value for given keys. First property found will be retrieved.
3030
- *
3031
- * @param keys - The property key
3032
- *
3033
- * @returns The retrieved property value
3034
- */
3035
- getProperty(...keys: string[]): string | undefined;
3036
- /**
3037
- * Sets a custom property in the Integration.
3038
- *
3039
- * @param key - The property key
3040
- * @param value - The property value, or null/undefined to clean it
3041
- *
3042
- * @returns The Integration, for chaining
3043
- */
3044
- setProperty(key: string, value: string | null | undefined): Integration;
3045
- /**
3046
- * Deletes a custom property stored in the Integration.
3047
- *
3048
- * @param key - The property key
3049
- *
3050
- * @returns The Integration, for chaining
3051
- */
3052
- deleteProperty(key: string): Integration;
3053
2797
  /**
3054
2798
  * Performs remove Integration.
3055
2799
  *
@@ -3242,6 +2986,101 @@ declare abstract class Resource<T = any> {
3242
2986
 
3243
2987
  }
3244
2988
 
2989
+ /**
2990
+ * Abstract base class for Bkper resources that support custom properties.
2991
+ *
2992
+ * Extends Resource<T> and adds property management methods for entities
2993
+ * that have a properties field in their payload.
2994
+ *
2995
+ * @public
2996
+ */
2997
+ declare abstract class ResourceProperty<T extends {
2998
+ properties?: {
2999
+ [key: string]: string;
3000
+ };
3001
+ }> extends Resource<T> {
3002
+
3003
+ /**
3004
+ * Gets the custom properties stored in this resource.
3005
+ *
3006
+ * @returns Object with key/value pair properties
3007
+ */
3008
+ getProperties(): {
3009
+ [key: string]: string;
3010
+ };
3011
+ /**
3012
+ * Sets the custom properties of this resource.
3013
+ *
3014
+ * @param properties - Object with key/value pair properties
3015
+ *
3016
+ * @returns This resource, for chaining
3017
+ */
3018
+ setProperties(properties: {
3019
+ [key: string]: string;
3020
+ }): this;
3021
+ /**
3022
+ * Gets the property value for given keys. First property found will be retrieved.
3023
+ *
3024
+ * @param keys - The property keys to search for
3025
+ *
3026
+ * @returns The property value or undefined if not found
3027
+ */
3028
+ getProperty(...keys: string[]): string | undefined;
3029
+ /**
3030
+ * Sets a custom property in this resource.
3031
+ *
3032
+ * @param key - The property key
3033
+ * @param value - The property value, or null/undefined to clean it
3034
+ *
3035
+ * @returns This resource, for chaining
3036
+ */
3037
+ setProperty(key: string, value: string | null | undefined): this;
3038
+ /**
3039
+ * Deletes a custom property.
3040
+ *
3041
+ * @param key - The property key
3042
+ *
3043
+ * @returns This resource, for chaining
3044
+ */
3045
+ deleteProperty(key: string): this;
3046
+ /**
3047
+ * Gets the custom properties keys stored in this resource.
3048
+ *
3049
+ * @returns Array of property keys sorted alphabetically
3050
+ */
3051
+ getPropertyKeys(): string[];
3052
+ /**
3053
+ * Sets a custom property in this resource, filtering out hidden properties.
3054
+ * Hidden properties are those whose keys end with an underscore "_".
3055
+ *
3056
+ * @param key - The property key
3057
+ * @param value - The property value, or null/undefined to clean it
3058
+ *
3059
+ * @returns This resource, for chaining
3060
+ */
3061
+ setVisibleProperty(key: string, value: string | null | undefined): this;
3062
+ /**
3063
+ * Sets the custom properties of this resource, filtering out hidden properties.
3064
+ * Hidden properties are those whose keys end with an underscore "_".
3065
+ *
3066
+ * @param properties - Object with key/value pair properties
3067
+ *
3068
+ * @returns This resource, for chaining
3069
+ */
3070
+ setVisibleProperties(properties: {
3071
+ [key: string]: string;
3072
+ }): this;
3073
+ /**
3074
+ * Gets the visible custom properties stored in this resource.
3075
+ * Hidden properties (those ending with "_") are excluded from the result.
3076
+ *
3077
+ * @returns Object with key/value pair properties, excluding hidden properties
3078
+ */
3079
+ getVisibleProperties(): {
3080
+ [key: string]: string;
3081
+ };
3082
+ }
3083
+
3245
3084
  /**
3246
3085
  * This class defines a Template.
3247
3086
  *
@@ -3311,7 +3150,7 @@ export declare class Template extends Resource<bkper.Template> {
3311
3150
  *
3312
3151
  * @public
3313
3152
  */
3314
- export declare class Transaction extends Resource<bkper.Transaction> {
3153
+ export declare class Transaction extends ResourceProperty<bkper.Transaction> {
3315
3154
 
3316
3155
 
3317
3156
  constructor(book: Book, payload?: bkper.Transaction);
@@ -3459,55 +3298,6 @@ export declare class Transaction extends Resource<bkper.Transaction> {
3459
3298
  * @returns True if the transaction has the specified tag
3460
3299
  */
3461
3300
  hasTag(tag: string): boolean;
3462
- /**
3463
- * Gets the custom properties stored in this Transaction.
3464
- *
3465
- * @returns Object with key/value pair properties
3466
- */
3467
- getProperties(): {
3468
- [key: string]: string;
3469
- };
3470
- /**
3471
- * Sets the custom properties of the Transaction
3472
- *
3473
- * @param properties - Object with key/value pair properties
3474
- *
3475
- * @returns This Transaction, for chaining
3476
- */
3477
- setProperties(properties: {
3478
- [key: string]: string;
3479
- }): Transaction;
3480
- /**
3481
- * Gets the property value for given keys. First property found will be retrieved
3482
- *
3483
- * @param keys - The property key
3484
- *
3485
- * @returns The property value or undefined if not found
3486
- */
3487
- getProperty(...keys: string[]): string | undefined;
3488
- /**
3489
- * Gets the custom properties keys stored in this Transaction.
3490
- *
3491
- * @returns Array of property keys
3492
- */
3493
- getPropertyKeys(): string[];
3494
- /**
3495
- * Sets a custom property in the Transaction.
3496
- *
3497
- * @param key - The property key
3498
- * @param value - The property value, or null/undefined to clean it
3499
- *
3500
- * @returns This Transaction, for chaining
3501
- */
3502
- setProperty(key: string, value: string | null | undefined): Transaction;
3503
- /**
3504
- * Delete a custom property
3505
- *
3506
- * @param key - The property key
3507
- *
3508
- * @returns This Transaction, for chaining
3509
- */
3510
- deleteProperty(key: string): Transaction;
3511
3301
  /**
3512
3302
  * Gets the credit account associated with this Transaction. Same as origin account
3513
3303
  *
@@ -11,7 +11,7 @@ import * as AccountService from "../service/account-service.js";
11
11
  import * as GroupService from "../service/group-service.js";
12
12
  import { Group } from "./Group.js";
13
13
  import { normalizeText } from "../utils.js";
14
- import { Resource } from "./Resource.js";
14
+ import { ResourceProperty } from "./ResourceProperty.js";
15
15
  /**
16
16
  * This class defines an [Account](https://en.wikipedia.org/wiki/Account_(bookkeeping)) of a [[Book]].
17
17
  *
@@ -21,7 +21,7 @@ import { Resource } from "./Resource.js";
21
21
  *
22
22
  * @public
23
23
  */
24
- export class Account extends Resource {
24
+ export class Account extends ResourceProperty {
25
25
  constructor(book, payload) {
26
26
  super(payload || { createdAt: `${Date.now()}` });
27
27
  this.book = book;
@@ -97,74 +97,6 @@ export class Account extends Resource {
97
97
  this.payload.type = type;
98
98
  return this;
99
99
  }
100
- /**
101
- * Gets the custom properties stored in this Account.
102
- *
103
- * @returns The custom properties object
104
- */
105
- getProperties() {
106
- return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
107
- }
108
- /**
109
- * Sets the custom properties of the Account.
110
- *
111
- * @param properties - Object with key/value pair properties
112
- *
113
- * @returns This Account, for chaining
114
- */
115
- setProperties(properties) {
116
- this.payload.properties = Object.assign({}, properties);
117
- return this;
118
- }
119
- /**
120
- * Gets the property value for given keys. First property found will be retrieved.
121
- *
122
- * @param keys - The property key
123
- *
124
- * @returns The property value or undefined if not found
125
- */
126
- getProperty(...keys) {
127
- for (let index = 0; index < keys.length; index++) {
128
- const key = keys[index];
129
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
130
- if (value != null && value.trim() != "") {
131
- return value;
132
- }
133
- }
134
- return undefined;
135
- }
136
- /**
137
- * Sets a custom property in the Account.
138
- *
139
- * @param key - The property key
140
- * @param value - The property value, or null/undefined to clean it
141
- *
142
- * @returns This Account, for chaining
143
- */
144
- setProperty(key, value) {
145
- if (key == null || key.trim() == "") {
146
- return this;
147
- }
148
- if (this.payload.properties == null) {
149
- this.payload.properties = {};
150
- }
151
- if (!value) {
152
- value = "";
153
- }
154
- this.payload.properties[key] = value;
155
- return this;
156
- }
157
- /**
158
- * Deletes a custom property.
159
- *
160
- * @param key - The property key
161
- *
162
- * @returns This Account, for chaining
163
- */
164
- deleteProperty(key) {
165
- this.setProperty(key, null);
166
- return this;
167
- }
168
100
  /**
169
101
  * Tells if this Account is archived.
170
102
  *
package/lib/model/Book.js CHANGED
@@ -18,7 +18,7 @@ import * as TransactionService from "../service/transaction-service.js";
18
18
  import * as EventService from "../service/event-service.js";
19
19
  import * as CollaboratorService from "../service/collaborator-service.js";
20
20
  import * as Utils from "../utils.js";
21
- import { Resource } from "./Resource.js";
21
+ import { ResourceProperty } from "./ResourceProperty.js";
22
22
  import { Account } from "./Account.js";
23
23
  import { Collaborator } from "./Collaborator.js";
24
24
  import { Collection } from "./Collection.js";
@@ -41,7 +41,7 @@ import { Backlog } from "./Backlog.js";
41
41
  *
42
42
  * @public
43
43
  */
44
- export class Book extends Resource {
44
+ export class Book extends ResourceProperty {
45
45
  constructor(payload, config) {
46
46
  super(payload);
47
47
  this.allGroupsLoaded = false;
@@ -379,64 +379,6 @@ export class Book extends Resource {
379
379
  this.payload.visibility = visibility;
380
380
  return this;
381
381
  }
382
- /**
383
- * Gets the custom properties stored in this Book.
384
- *
385
- * @returns The custom properties object
386
- */
387
- getProperties() {
388
- return this.payload.properties != null
389
- ? Object.assign({}, this.payload.properties) : {};
390
- }
391
- /**
392
- * Gets the property value for given keys. First property found will be retrieved.
393
- *
394
- * @param keys - The property keys to search for
395
- *
396
- * @returns The property value or undefined if not found
397
- */
398
- getProperty(...keys) {
399
- for (let index = 0; index < keys.length; index++) {
400
- const key = keys[index];
401
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
402
- if (value != null && value.trim() != "") {
403
- return value;
404
- }
405
- }
406
- return undefined;
407
- }
408
- /**
409
- * Sets the custom properties of the Book.
410
- *
411
- * @param properties - Object with key/value pair properties
412
- *
413
- * @returns This Book, for chaining
414
- */
415
- setProperties(properties) {
416
- this.payload.properties = Object.assign({}, properties);
417
- return this;
418
- }
419
- /**
420
- * Sets a custom property in the Book.
421
- *
422
- * @param key - The property key
423
- * @param value - The property value, or null/undefined to clean it
424
- *
425
- * @returns This Book, for chaining
426
- */
427
- setProperty(key, value) {
428
- if (key == null || key.trim() == "") {
429
- return this;
430
- }
431
- if (this.payload.properties == null) {
432
- this.payload.properties = {};
433
- }
434
- if (!value) {
435
- value = "";
436
- }
437
- this.payload.properties[key] = value;
438
- return this;
439
- }
440
382
  /**
441
383
  * Formats a date according to date pattern of the Book.
442
384
  *