bkper-js 2.15.1 → 2.15.2

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,73 @@ 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
+ * @param filterHidden - If true, hidden properties (ending with "_") will not be set. Defaults to false.
3016
+ *
3017
+ * @returns This resource, for chaining
3018
+ */
3019
+ setProperties(properties: {
3020
+ [key: string]: string;
3021
+ }, filterHidden?: boolean): this;
3022
+ /**
3023
+ * Gets the property value for given keys. First property found will be retrieved.
3024
+ *
3025
+ * @param keys - The property keys to search for
3026
+ *
3027
+ * @returns The property value or undefined if not found
3028
+ */
3029
+ getProperty(...keys: string[]): string | undefined;
3030
+ /**
3031
+ * Sets a custom property in this resource.
3032
+ *
3033
+ * @param key - The property key
3034
+ * @param value - The property value, or null/undefined to clean it
3035
+ * @param filterHidden - If true, hidden properties (ending with "_") will not be set. Defaults to false.
3036
+ *
3037
+ * @returns This resource, for chaining
3038
+ */
3039
+ setProperty(key: string, value: string | null | undefined, filterHidden?: boolean): this;
3040
+ /**
3041
+ * Deletes a custom property.
3042
+ *
3043
+ * @param key - The property key
3044
+ *
3045
+ * @returns This resource, for chaining
3046
+ */
3047
+ deleteProperty(key: string): this;
3048
+ /**
3049
+ * Gets the custom properties keys stored in this resource.
3050
+ *
3051
+ * @returns Array of property keys sorted alphabetically
3052
+ */
3053
+ getPropertyKeys(): string[];
3054
+ }
3055
+
3245
3056
  /**
3246
3057
  * This class defines a Template.
3247
3058
  *
@@ -3311,7 +3122,7 @@ export declare class Template extends Resource<bkper.Template> {
3311
3122
  *
3312
3123
  * @public
3313
3124
  */
3314
- export declare class Transaction extends Resource<bkper.Transaction> {
3125
+ export declare class Transaction extends ResourceProperty<bkper.Transaction> {
3315
3126
 
3316
3127
 
3317
3128
  constructor(book: Book, payload?: bkper.Transaction);
@@ -3459,55 +3270,6 @@ export declare class Transaction extends Resource<bkper.Transaction> {
3459
3270
  * @returns True if the transaction has the specified tag
3460
3271
  */
3461
3272
  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
3273
  /**
3512
3274
  * Gets the credit account associated with this Transaction. Same as origin account
3513
3275
  *
@@ -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
  *
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Resource } from "./Resource.js";
10
+ import { ResourceProperty } from "./ResourceProperty.js";
11
11
  import { Bkper } from "./Bkper.js";
12
12
  import * as ConnectionService from "../service/connection-service.js";
13
13
  import { Integration } from "./Integration.js";
@@ -16,7 +16,7 @@ import { Integration } from "./Integration.js";
16
16
  *
17
17
  * @public
18
18
  */
19
- export class Connection extends Resource {
19
+ export class Connection extends ResourceProperty {
20
20
  constructor(payload, config) {
21
21
  super(payload);
22
22
  this.config = config;
@@ -133,75 +133,6 @@ export class Connection extends Resource {
133
133
  this.payload.type = type;
134
134
  return this;
135
135
  }
136
- /**
137
- * Gets the custom properties stored in the Connection
138
- *
139
- * @returns Object with key/value pair properties
140
- */
141
- getProperties() {
142
- return this.payload.properties != null
143
- ? Object.assign({}, this.payload.properties) : {};
144
- }
145
- /**
146
- * Sets the custom properties of the Connection.
147
- *
148
- * @param properties - Object with key/value pair properties
149
- *
150
- * @returns The Connection, for chaining
151
- */
152
- setProperties(properties) {
153
- this.payload.properties = Object.assign({}, properties);
154
- return this;
155
- }
156
- /**
157
- * Gets the property value for given keys. First property found will be retrieved.
158
- *
159
- * @param keys - The property key
160
- *
161
- * @returns The retrieved property value
162
- */
163
- getProperty(...keys) {
164
- for (let index = 0; index < keys.length; index++) {
165
- const key = keys[index];
166
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
167
- if (value != null && value.trim() != "") {
168
- return value;
169
- }
170
- }
171
- return undefined;
172
- }
173
- /**
174
- * Sets a custom property in the Connection.
175
- *
176
- * @param key - The property key
177
- * @param value - The property value, or null/undefined to clean it
178
- *
179
- * @returns The Connection, for chaining
180
- */
181
- setProperty(key, value) {
182
- if (key == null || key.trim() == "") {
183
- return this;
184
- }
185
- if (this.payload.properties == null) {
186
- this.payload.properties = {};
187
- }
188
- if (!value) {
189
- value = "";
190
- }
191
- this.payload.properties[key] = value;
192
- return this;
193
- }
194
- /**
195
- * Deletes a custom property stored in the Connection.
196
- *
197
- * @param key - The property key
198
- *
199
- * @returns The Connection, for chaining
200
- */
201
- deleteProperty(key) {
202
- this.setProperty(key, null);
203
- return this;
204
- }
205
136
  /**
206
137
  * Cleans any token property stored in the Connection.
207
138
  */
@@ -210,24 +141,6 @@ export class Connection extends Resource {
210
141
  .filter((key) => key.includes("token"))
211
142
  .forEach((key) => this.deleteProperty(key));
212
143
  }
213
- /**
214
- * Gets the custom properties keys stored in the Connection.
215
- *
216
- * @returns The retrieved property keys
217
- */
218
- getPropertyKeys() {
219
- let properties = this.getProperties();
220
- let propertyKeys = [];
221
- if (properties) {
222
- for (var key in properties) {
223
- if (Object.prototype.hasOwnProperty.call(properties, key)) {
224
- propertyKeys.push(key);
225
- }
226
- }
227
- }
228
- propertyKeys = propertyKeys.sort();
229
- return propertyKeys;
230
- }
231
144
  /**
232
145
  * Gets the existing [[Integrations]] on the Connection.
233
146
  *
package/lib/model/File.js CHANGED
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import * as FileService from "../service/file-service.js";
11
- import { Resource } from "./Resource.js";
11
+ import { ResourceProperty } from "./ResourceProperty.js";
12
12
  /**
13
13
  *
14
14
  * This class defines a File uploaded to a [[Book]].
@@ -17,7 +17,7 @@ import { Resource } from "./Resource.js";
17
17
  *
18
18
  * @public
19
19
  */
20
- export class File extends Resource {
20
+ export class File extends ResourceProperty {
21
21
  constructor(book, payload) {
22
22
  super(payload || { createdAt: `${Date.now()}` });
23
23
  this.book = book;
@@ -124,75 +124,6 @@ export class File extends Resource {
124
124
  getSize() {
125
125
  return this.payload.size;
126
126
  }
127
- /**
128
- * Gets the custom properties stored in this File.
129
- *
130
- * @returns The custom properties object
131
- */
132
- getProperties() {
133
- return this.payload.properties != null
134
- ? Object.assign({}, this.payload.properties) : {};
135
- }
136
- /**
137
- * Sets the custom properties of the File.
138
- *
139
- * @param properties - Object with key/value pair properties
140
- *
141
- * @returns This File, for chaining
142
- */
143
- setProperties(properties) {
144
- this.payload.properties = Object.assign({}, properties);
145
- return this;
146
- }
147
- /**
148
- * Gets the property value for given keys. First property found will be retrieved.
149
- *
150
- * @param keys - The property key
151
- *
152
- * @returns The property value or undefined if not found
153
- */
154
- getProperty(...keys) {
155
- for (let index = 0; index < keys.length; index++) {
156
- const key = keys[index];
157
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
158
- if (value != null && value.trim() != "") {
159
- return value;
160
- }
161
- }
162
- return undefined;
163
- }
164
- /**
165
- * Sets a custom property in the File.
166
- *
167
- * @param key - The property key
168
- * @param value - The property value, or null/undefined to clean it
169
- *
170
- * @returns This File, for chaining
171
- */
172
- setProperty(key, value) {
173
- if (key == null || key.trim() == "") {
174
- return this;
175
- }
176
- if (this.payload.properties == null) {
177
- this.payload.properties = {};
178
- }
179
- if (!value) {
180
- value = "";
181
- }
182
- this.payload.properties[key] = value;
183
- return this;
184
- }
185
- /**
186
- * Deletes a custom property.
187
- *
188
- * @param key - The property key
189
- *
190
- * @returns This File, for chaining
191
- */
192
- deleteProperty(key) {
193
- this.setProperty(key, null);
194
- return this;
195
- }
196
127
  /**
197
128
  * Perform create new File.
198
129
  *
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as GroupService from "../service/group-service.js";
11
11
  import { normalizeText } from "../utils.js";
12
12
  import { Account } from "./Account.js";
13
- import { Resource } from "./Resource.js";
13
+ import { ResourceProperty } from "./ResourceProperty.js";
14
14
  /**
15
15
  * This class defines a Group of [[Accounts]].
16
16
  *
@@ -20,7 +20,7 @@ import { Resource } from "./Resource.js";
20
20
  *
21
21
  * @public
22
22
  */
23
- export class Group extends Resource {
23
+ export class Group extends ResourceProperty {
24
24
  constructor(book, payload) {
25
25
  super(payload || { createdAt: `${Date.now()}` });
26
26
  /** @internal */
@@ -139,75 +139,6 @@ export class Group extends Resource {
139
139
  getType() {
140
140
  return this.payload.type;
141
141
  }
142
- /**
143
- * Gets the custom properties stored in this Group.
144
- *
145
- * @returns The custom properties as a key/value object
146
- */
147
- getProperties() {
148
- return this.payload.properties != null
149
- ? Object.assign({}, this.payload.properties) : {};
150
- }
151
- /**
152
- * Sets the custom properties of the Group
153
- *
154
- * @param properties - Object with key/value pair properties
155
- *
156
- * @returns This Group, for chaining
157
- */
158
- setProperties(properties) {
159
- this.payload.properties = Object.assign({}, properties);
160
- return this;
161
- }
162
- /**
163
- * Gets the property value for given keys. First property found will be retrieved.
164
- *
165
- * @param keys - The property key
166
- *
167
- * @returns The property value, or undefined if not found
168
- */
169
- getProperty(...keys) {
170
- for (let index = 0; index < keys.length; index++) {
171
- const key = keys[index];
172
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
173
- if (value != null && value.trim() != "") {
174
- return value;
175
- }
176
- }
177
- return undefined;
178
- }
179
- /**
180
- * Sets a custom property in the Group.
181
- *
182
- * @param key - The property key
183
- * @param value - The property value, or null/undefined to clean it
184
- *
185
- * @returns This Group, for chaining
186
- */
187
- setProperty(key, value) {
188
- if (key == null || key.trim() == "") {
189
- return this;
190
- }
191
- if (this.payload.properties == null) {
192
- this.payload.properties = {};
193
- }
194
- if (!value) {
195
- value = "";
196
- }
197
- this.payload.properties[key] = value;
198
- return this;
199
- }
200
- /**
201
- * Delete a custom property
202
- *
203
- * @param key - The property key
204
- *
205
- * @returns This Group, for chaining
206
- */
207
- deleteProperty(key) {
208
- this.setProperty(key, null);
209
- return this;
210
- }
211
142
  /**
212
143
  * Tells if the Group is hidden on main transactions menu.
213
144
  *
@@ -8,14 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import * as IntegrationService from "../service/integration-service.js";
11
- import { Resource } from "./Resource.js";
11
+ import { ResourceProperty } from "./ResourceProperty.js";
12
12
  import { Bkper } from "./Bkper.js";
13
13
  /**
14
14
  * This class defines a Integration from an [[User]] to an external service.
15
15
  *
16
16
  * @public
17
17
  */
18
- export class Integration extends Resource {
18
+ export class Integration extends ResourceProperty {
19
19
  constructor(payload, config) {
20
20
  super(payload || {});
21
21
  this.config = config;
@@ -106,75 +106,6 @@ export class Integration extends Resource {
106
106
  getLastUpdateMs() {
107
107
  return this.payload.lastUpdateMs;
108
108
  }
109
- /**
110
- * Gets the custom properties stored in the Integration.
111
- *
112
- * @returns Object with key/value pair properties
113
- */
114
- getProperties() {
115
- return this.payload.properties != null
116
- ? Object.assign({}, this.payload.properties) : {};
117
- }
118
- /**
119
- * Sets the custom properties of the Integration.
120
- *
121
- * @param properties - Object with key/value pair properties
122
- *
123
- * @returns The Integration, for chaining
124
- */
125
- setProperties(properties) {
126
- this.payload.properties = Object.assign({}, properties);
127
- return this;
128
- }
129
- /**
130
- * Gets the property value for given keys. First property found will be retrieved.
131
- *
132
- * @param keys - The property key
133
- *
134
- * @returns The retrieved property value
135
- */
136
- getProperty(...keys) {
137
- for (let index = 0; index < keys.length; index++) {
138
- const key = keys[index];
139
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
140
- if (value != null && value.trim() != "") {
141
- return value;
142
- }
143
- }
144
- return undefined;
145
- }
146
- /**
147
- * Sets a custom property in the Integration.
148
- *
149
- * @param key - The property key
150
- * @param value - The property value, or null/undefined to clean it
151
- *
152
- * @returns The Integration, for chaining
153
- */
154
- setProperty(key, value) {
155
- if (key == null || key.trim() == "") {
156
- return this;
157
- }
158
- if (this.payload.properties == null) {
159
- this.payload.properties = {};
160
- }
161
- if (!value) {
162
- value = "";
163
- }
164
- this.payload.properties[key] = value;
165
- return this;
166
- }
167
- /**
168
- * Deletes a custom property stored in the Integration.
169
- *
170
- * @param key - The property key
171
- *
172
- * @returns The Integration, for chaining
173
- */
174
- deleteProperty(key) {
175
- this.setProperty(key, null);
176
- return this;
177
- }
178
109
  /**
179
110
  * Performs remove Integration.
180
111
  *
@@ -0,0 +1,130 @@
1
+ import { Resource } from "./Resource.js";
2
+ /**
3
+ * Abstract base class for Bkper resources that support custom properties.
4
+ *
5
+ * Extends Resource<T> and adds property management methods for entities
6
+ * that have a properties field in their payload.
7
+ *
8
+ * @public
9
+ */
10
+ export class ResourceProperty extends Resource {
11
+ /**
12
+ * Checks if a property key represents a hidden property.
13
+ * Hidden properties are those whose keys end with an underscore "_".
14
+ *
15
+ * @param key - The property key to check
16
+ * @returns True if the property is hidden, false otherwise
17
+ *
18
+ * @internal
19
+ */
20
+ isHiddenProperty(key) {
21
+ return key.endsWith('_');
22
+ }
23
+ /**
24
+ * Gets the custom properties stored in this resource.
25
+ *
26
+ * @returns Object with key/value pair properties
27
+ */
28
+ getProperties() {
29
+ return this.payload.properties != null
30
+ ? Object.assign({}, this.payload.properties) : {};
31
+ }
32
+ /**
33
+ * Sets the custom properties of this resource.
34
+ *
35
+ * @param properties - Object with key/value pair properties
36
+ * @param filterHidden - If true, hidden properties (ending with "_") will not be set. Defaults to false.
37
+ *
38
+ * @returns This resource, for chaining
39
+ */
40
+ setProperties(properties, filterHidden = false) {
41
+ if (!filterHidden) {
42
+ this.payload.properties = Object.assign({}, properties);
43
+ return this;
44
+ }
45
+ const filteredProperties = {};
46
+ for (const key in properties) {
47
+ if (Object.prototype.hasOwnProperty.call(properties, key)) {
48
+ if (!this.isHiddenProperty(key)) {
49
+ filteredProperties[key] = properties[key];
50
+ }
51
+ }
52
+ }
53
+ this.payload.properties = Object.assign({}, filteredProperties);
54
+ return this;
55
+ }
56
+ /**
57
+ * Gets the property value for given keys. First property found will be retrieved.
58
+ *
59
+ * @param keys - The property keys to search for
60
+ *
61
+ * @returns The property value or undefined if not found
62
+ */
63
+ getProperty(...keys) {
64
+ for (let index = 0; index < keys.length; index++) {
65
+ const key = keys[index];
66
+ let value = this.payload.properties != null
67
+ ? this.payload.properties[key]
68
+ : null;
69
+ if (value != null && value.trim() != "") {
70
+ return value;
71
+ }
72
+ }
73
+ return undefined;
74
+ }
75
+ /**
76
+ * Sets a custom property in this resource.
77
+ *
78
+ * @param key - The property key
79
+ * @param value - The property value, or null/undefined to clean it
80
+ * @param filterHidden - If true, hidden properties (ending with "_") will not be set. Defaults to false.
81
+ *
82
+ * @returns This resource, for chaining
83
+ */
84
+ setProperty(key, value, filterHidden = false) {
85
+ if (key == null || key.trim() == "") {
86
+ return this;
87
+ }
88
+ if (filterHidden && this.isHiddenProperty(key)) {
89
+ return this;
90
+ }
91
+ if (this.payload.properties == null) {
92
+ this.payload.properties = {};
93
+ }
94
+ if (!value) {
95
+ value = "";
96
+ }
97
+ this.payload.properties[key] = value;
98
+ return this;
99
+ }
100
+ /**
101
+ * Deletes a custom property.
102
+ *
103
+ * @param key - The property key
104
+ *
105
+ * @returns This resource, for chaining
106
+ */
107
+ deleteProperty(key) {
108
+ this.setProperty(key, null);
109
+ return this;
110
+ }
111
+ /**
112
+ * Gets the custom properties keys stored in this resource.
113
+ *
114
+ * @returns Array of property keys sorted alphabetically
115
+ */
116
+ getPropertyKeys() {
117
+ let properties = this.getProperties();
118
+ let propertyKeys = [];
119
+ if (properties) {
120
+ for (var key in properties) {
121
+ if (Object.prototype.hasOwnProperty.call(properties, key)) {
122
+ propertyKeys.push(key);
123
+ }
124
+ }
125
+ }
126
+ propertyKeys = propertyKeys.sort();
127
+ return propertyKeys;
128
+ }
129
+ }
130
+ //# sourceMappingURL=ResourceProperty.js.map
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { File } from "./File.js";
11
11
  import { Account } from "./Account.js";
12
- import { Resource } from "./Resource.js";
12
+ import { ResourceProperty } from "./ResourceProperty.js";
13
13
  import * as TransactionService from "../service/transaction-service.js";
14
14
  import * as Utils from "../utils.js";
15
15
  import { Amount } from "./Amount.js";
@@ -22,7 +22,7 @@ import { v4 as uuidv4 } from "uuid";
22
22
  *
23
23
  * @public
24
24
  */
25
- export class Transaction extends Resource {
25
+ export class Transaction extends ResourceProperty {
26
26
  constructor(book, payload) {
27
27
  super(payload || { createdAt: `${Date.now()}` });
28
28
  /** @internal */
@@ -277,7 +277,7 @@ export class Transaction extends Resource {
277
277
  // Create all pending files in parallel
278
278
  const promises = Array.from(this.pendingFiles.entries()).map((_a) => __awaiter(this, [_a], void 0, function* ([fileId, file]) {
279
279
  file.book = this.book;
280
- file.setProperty('upload_method_', 'attachment');
280
+ file.setProperty('upload_method', 'attachment');
281
281
  const createdFile = yield file.create();
282
282
  return { fileId, createdFile };
283
283
  }));
@@ -312,93 +312,6 @@ export class Transaction extends Resource {
312
312
  }
313
313
  return false;
314
314
  }
315
- /**
316
- * Gets the custom properties stored in this Transaction.
317
- *
318
- * @returns Object with key/value pair properties
319
- */
320
- getProperties() {
321
- return this.payload.properties != null
322
- ? Object.assign({}, this.payload.properties) : {};
323
- }
324
- /**
325
- * Sets the custom properties of the Transaction
326
- *
327
- * @param properties - Object with key/value pair properties
328
- *
329
- * @returns This Transaction, for chaining
330
- */
331
- setProperties(properties) {
332
- this.payload.properties = Object.assign({}, properties);
333
- return this;
334
- }
335
- /**
336
- * Gets the property value for given keys. First property found will be retrieved
337
- *
338
- * @param keys - The property key
339
- *
340
- * @returns The property value or undefined if not found
341
- */
342
- getProperty(...keys) {
343
- for (let index = 0; index < keys.length; index++) {
344
- const key = keys[index];
345
- let value = this.payload.properties != null ? this.payload.properties[key] : null;
346
- if (value != null && value.trim() != "") {
347
- return value;
348
- }
349
- }
350
- return undefined;
351
- }
352
- /**
353
- * Gets the custom properties keys stored in this Transaction.
354
- *
355
- * @returns Array of property keys
356
- */
357
- getPropertyKeys() {
358
- let properties = this.getProperties();
359
- let propertyKeys = [];
360
- if (properties) {
361
- for (var key in properties) {
362
- if (Object.prototype.hasOwnProperty.call(properties, key)) {
363
- propertyKeys.push(key);
364
- }
365
- }
366
- }
367
- propertyKeys = propertyKeys.sort();
368
- return propertyKeys;
369
- }
370
- /**
371
- * Sets a custom property in the Transaction.
372
- *
373
- * @param key - The property key
374
- * @param value - The property value, or null/undefined to clean it
375
- *
376
- * @returns This Transaction, for chaining
377
- */
378
- setProperty(key, value) {
379
- if (key == null || key.trim() == "") {
380
- return this;
381
- }
382
- if (this.payload.properties == null) {
383
- this.payload.properties = {};
384
- }
385
- if (!value) {
386
- value = "";
387
- }
388
- this.payload.properties[key] = value;
389
- return this;
390
- }
391
- /**
392
- * Delete a custom property
393
- *
394
- * @param key - The property key
395
- *
396
- * @returns This Transaction, for chaining
397
- */
398
- deleteProperty(key) {
399
- this.setProperty(key, null);
400
- return this;
401
- }
402
315
  /**
403
316
  * Gets the credit account associated with this Transaction. Same as origin account
404
317
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bkper-js",
3
- "version": "2.15.1",
3
+ "version": "2.15.2",
4
4
  "description": "Javascript client for Bkper REST API",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",