bkper-js 2.15.0 → 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.
@@ -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