bkper-js 1.8.1 → 1.9.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/model/File.js CHANGED
@@ -17,28 +17,30 @@ import * as FileService from '../service/file-service.js';
17
17
  * @public
18
18
  */
19
19
  export class File {
20
- constructor(book, json) {
20
+ constructor(book, payload) {
21
21
  this.book = book;
22
- this.wrapped = json || {};
22
+ this.payload = payload || {
23
+ createdAt: `${Date.now()}`
24
+ };
25
+ ;
23
26
  }
24
27
  /**
25
- *
26
- * @returns The wrapped plain json object
28
+ * @returns An immutable copy of the json payload
27
29
  */
28
30
  json() {
29
- return this.wrapped;
31
+ return Object.assign({}, this.payload);
30
32
  }
31
33
  /**
32
34
  * Gets the File id
33
35
  */
34
36
  getId() {
35
- return this.wrapped.id;
37
+ return this.payload.id;
36
38
  }
37
39
  /**
38
40
  * Gets the File name
39
41
  */
40
42
  getName() {
41
- return this.wrapped.name;
43
+ return this.payload.name;
42
44
  }
43
45
  /**
44
46
  *
@@ -47,14 +49,14 @@ export class File {
47
49
  * @returns This File, for chainning.
48
50
  */
49
51
  setName(name) {
50
- this.wrapped.name = name;
52
+ this.payload.name = name;
51
53
  return this;
52
54
  }
53
55
  /**
54
56
  * Gets the File content type
55
57
  */
56
58
  getContentType() {
57
- return this.wrapped.contentType;
59
+ return this.payload.contentType;
58
60
  }
59
61
  /**
60
62
  *
@@ -63,7 +65,7 @@ export class File {
63
65
  * @returns This File, for chainning.
64
66
  */
65
67
  setContentType(contentType) {
66
- this.wrapped.contentType = contentType;
68
+ this.payload.contentType = contentType;
67
69
  return this;
68
70
  }
69
71
  /**
@@ -72,10 +74,10 @@ export class File {
72
74
  getContent() {
73
75
  return __awaiter(this, void 0, void 0, function* () {
74
76
  const id = this.getId();
75
- if (this.getId() != null && (this.wrapped == null || this.wrapped.content == null) && this.book && id) {
76
- this.wrapped = yield FileService.getFile(this.book.getId(), id);
77
+ if (this.getId() != null && (this.payload == null || this.payload.content == null) && this.book && id) {
78
+ this.payload = yield FileService.getFile(this.book.getId(), id);
77
79
  }
78
- return this.wrapped.content;
80
+ return this.payload.content;
79
81
  });
80
82
  }
81
83
  /**
@@ -85,20 +87,20 @@ export class File {
85
87
  * @returns This File, for chainning.
86
88
  */
87
89
  setContent(content) {
88
- this.wrapped.content = content;
90
+ this.payload.content = content;
89
91
  return this;
90
92
  }
91
93
  /**
92
94
  * Gets the file serving url for accessing via browser
93
95
  */
94
96
  getUrl() {
95
- return this.wrapped.url;
97
+ return this.payload.url;
96
98
  }
97
99
  /**
98
100
  * Gets the file size in bytes
99
101
  */
100
102
  getSize() {
101
- return this.wrapped.size;
103
+ return this.payload.size;
102
104
  }
103
105
  /**
104
106
  * Perform create new File.
@@ -106,7 +108,7 @@ export class File {
106
108
  create() {
107
109
  return __awaiter(this, void 0, void 0, function* () {
108
110
  if (this.book) {
109
- this.wrapped = yield FileService.createFile(this.book.getId(), this.wrapped);
111
+ this.payload = yield FileService.createFile(this.book.getId(), this.payload);
110
112
  }
111
113
  return this;
112
114
  });
@@ -20,30 +20,31 @@ import { Account } from './Account.js';
20
20
  * @public
21
21
  */
22
22
  export class Group {
23
- constructor(book, json) {
23
+ constructor(book, payload) {
24
24
  this.book = book;
25
- this.wrapped = json || {};
25
+ this.payload = payload || {
26
+ createdAt: `${Date.now()}`
27
+ };
26
28
  }
27
29
  /**
28
- *
29
- * @returns The wrapped plain json object
30
+ * @returns An immutable copy of the json payload
30
31
  */
31
32
  json() {
32
- return this.wrapped;
33
+ return Object.assign({}, this.payload);
33
34
  }
34
35
  /**
35
36
  * @returns The id of this Group
36
37
  */
37
38
  getId() {
38
- return this.wrapped.id;
39
+ return this.payload.id;
39
40
  }
40
41
  /**
41
42
  * @returns The parent Group
42
43
  */
43
44
  getParent() {
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
- if (this.wrapped.parent) {
46
- return yield this.book.getGroup(this.wrapped.parent.id);
46
+ if (this.payload.parent) {
47
+ return yield this.book.getGroup(this.payload.parent.id);
47
48
  }
48
49
  else {
49
50
  return undefined;
@@ -57,10 +58,10 @@ export class Group {
57
58
  */
58
59
  setParent(group) {
59
60
  if (group) {
60
- this.wrapped.parent = { id: group.getId(), name: group.getName(), normalizedName: group.getNormalizedName() };
61
+ this.payload.parent = { id: group.getId(), name: group.getName(), normalizedName: group.getNormalizedName() };
61
62
  }
62
63
  else {
63
- this.wrapped.parent = undefined;
64
+ this.payload.parent = undefined;
64
65
  }
65
66
  return this;
66
67
  }
@@ -68,7 +69,7 @@ export class Group {
68
69
  * @returns The name of this Group
69
70
  */
70
71
  getName() {
71
- return this.wrapped.name;
72
+ return this.payload.name;
72
73
  }
73
74
  /**
74
75
  * Sets the name of the Group.
@@ -76,15 +77,15 @@ export class Group {
76
77
  * @returns This Group, for chainning.
77
78
  */
78
79
  setName(name) {
79
- this.wrapped.name = name;
80
+ this.payload.name = name;
80
81
  return this;
81
82
  }
82
83
  /**
83
84
  * @returns The name of this group without spaces and special characters
84
85
  */
85
86
  getNormalizedName() {
86
- if (this.wrapped.normalizedName) {
87
- return this.wrapped.normalizedName;
87
+ if (this.payload.normalizedName) {
88
+ return this.payload.normalizedName;
88
89
  }
89
90
  else {
90
91
  return normalizeText(this.getName());
@@ -107,19 +108,19 @@ export class Group {
107
108
  * @returns True if this group has any account in it
108
109
  */
109
110
  hasAccounts() {
110
- return this.wrapped.hasAccounts;
111
+ return this.payload.hasAccounts;
111
112
  }
112
113
  /**
113
114
  * @returns The type for of the accounts of this group. Null if mixed
114
115
  */
115
116
  getType() {
116
- return this.wrapped.type;
117
+ return this.payload.type;
117
118
  }
118
119
  /**
119
120
  * Gets the custom properties stored in this Group
120
121
  */
121
122
  getProperties() {
122
- return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
123
+ return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
123
124
  }
124
125
  /**
125
126
  * Sets the custom properties of the Group
@@ -129,7 +130,7 @@ export class Group {
129
130
  * @returns This Group, for chainning.
130
131
  */
131
132
  setProperties(properties) {
132
- this.wrapped.properties = Object.assign({}, properties);
133
+ this.payload.properties = Object.assign({}, properties);
133
134
  return this;
134
135
  }
135
136
  /**
@@ -140,7 +141,7 @@ export class Group {
140
141
  getProperty(...keys) {
141
142
  for (let index = 0; index < keys.length; index++) {
142
143
  const key = keys[index];
143
- let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
144
+ let value = this.payload.properties != null ? this.payload.properties[key] : null;
144
145
  if (value != null && value.trim() != '') {
145
146
  return value;
146
147
  }
@@ -157,13 +158,13 @@ export class Group {
157
158
  if (key == null || key.trim() == '') {
158
159
  return this;
159
160
  }
160
- if (this.wrapped.properties == null) {
161
- this.wrapped.properties = {};
161
+ if (this.payload.properties == null) {
162
+ this.payload.properties = {};
162
163
  }
163
164
  if (!value) {
164
165
  value = '';
165
166
  }
166
- this.wrapped.properties[key] = value;
167
+ this.payload.properties[key] = value;
167
168
  return this;
168
169
  }
169
170
  /**
@@ -181,13 +182,13 @@ export class Group {
181
182
  * Tell if the Group is hidden on main transactions menu
182
183
  */
183
184
  isHidden() {
184
- return this.wrapped.hidden;
185
+ return this.payload.hidden;
185
186
  }
186
187
  /**
187
188
  * Hide/Show group on main menu.
188
189
  */
189
190
  setHidden(hidden) {
190
- this.wrapped.hidden = hidden;
191
+ this.payload.hidden = hidden;
191
192
  return this;
192
193
  }
193
194
  /**
@@ -195,7 +196,7 @@ export class Group {
195
196
  */
196
197
  create() {
197
198
  return __awaiter(this, void 0, void 0, function* () {
198
- this.wrapped = yield GroupService.createGroup(this.book.getId(), this.wrapped);
199
+ this.payload = yield GroupService.createGroup(this.book.getId(), this.payload);
199
200
  this.book.updateGroupCache(this);
200
201
  return this;
201
202
  });
@@ -205,7 +206,7 @@ export class Group {
205
206
  */
206
207
  update() {
207
208
  return __awaiter(this, void 0, void 0, function* () {
208
- this.wrapped = yield GroupService.updateGroup(this.book.getId(), this.wrapped);
209
+ this.payload = yield GroupService.updateGroup(this.book.getId(), this.payload);
209
210
  this.book.updateGroupCache(this);
210
211
  return this;
211
212
  });
@@ -215,7 +216,7 @@ export class Group {
215
216
  */
216
217
  remove() {
217
218
  return __awaiter(this, void 0, void 0, function* () {
218
- this.wrapped = yield GroupService.deleteGroup(this.book.getId(), this.wrapped);
219
+ this.payload = yield GroupService.deleteGroup(this.book.getId(), this.payload);
219
220
  this.book.removeGroupCache(this);
220
221
  return this;
221
222
  });
@@ -4,16 +4,14 @@
4
4
  * @public
5
5
  */
6
6
  export class Integration {
7
- constructor(json) {
8
- this.wrapped = json || {};
7
+ constructor(payload) {
8
+ this.payload = payload || {};
9
9
  }
10
10
  /**
11
- * Gets the wrapped plain json object of the Integration.
12
- *
13
- * @returns The Integration wrapped plain json object
11
+ * @returns An immutable copy of the json payload
14
12
  */
15
13
  json() {
16
- return this.wrapped;
14
+ return Object.assign({}, this.payload);
17
15
  }
18
16
  /**
19
17
  * Gets the [[Book]] id of the Integration.
@@ -21,7 +19,7 @@ export class Integration {
21
19
  * @returns The Integration's Book id
22
20
  */
23
21
  getBookId() {
24
- return this.wrapped.bookId;
22
+ return this.payload.bookId;
25
23
  }
26
24
  /**
27
25
  * Gets the id of the Integration.
@@ -29,7 +27,7 @@ export class Integration {
29
27
  * @returns This Integration's id
30
28
  */
31
29
  getId() {
32
- return this.wrapped.id;
30
+ return this.payload.id;
33
31
  }
34
32
  /**
35
33
  * Gets the name of the Integration.
@@ -37,7 +35,7 @@ export class Integration {
37
35
  * @returns The Integration's name
38
36
  */
39
37
  getName() {
40
- return this.wrapped.name;
38
+ return this.payload.name;
41
39
  }
42
40
  /**
43
41
  * Gets the custom properties stored in the Integration.
@@ -45,7 +43,7 @@ export class Integration {
45
43
  * @returns Object with key/value pair properties
46
44
  */
47
45
  getProperties() {
48
- return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
46
+ return this.payload.properties != null ? Object.assign({}, this.payload.properties) : {};
49
47
  }
50
48
  /**
51
49
  * Sets the custom properties of the Integration.
@@ -55,7 +53,7 @@ export class Integration {
55
53
  * @returns The Integration, for chainning
56
54
  */
57
55
  setProperties(properties) {
58
- this.wrapped.properties = Object.assign({}, properties);
56
+ this.payload.properties = Object.assign({}, properties);
59
57
  return this;
60
58
  }
61
59
  /**
@@ -68,7 +66,7 @@ export class Integration {
68
66
  getProperty(...keys) {
69
67
  for (let index = 0; index < keys.length; index++) {
70
68
  const key = keys[index];
71
- let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
69
+ let value = this.payload.properties != null ? this.payload.properties[key] : null;
72
70
  if (value != null && value.trim() != '') {
73
71
  return value;
74
72
  }
@@ -87,13 +85,13 @@ export class Integration {
87
85
  if (key == null || key.trim() == '') {
88
86
  return this;
89
87
  }
90
- if (this.wrapped.properties == null) {
91
- this.wrapped.properties = {};
88
+ if (this.payload.properties == null) {
89
+ this.payload.properties = {};
92
90
  }
93
91
  if (!value) {
94
92
  value = '';
95
93
  }
96
- this.wrapped.properties[key] = value;
94
+ this.payload.properties[key] = value;
97
95
  return this;
98
96
  }
99
97
  /**
@@ -7,7 +7,13 @@
7
7
  */
8
8
  export class Template {
9
9
  constructor(json) {
10
- this.wrapped = json || {};
10
+ this.payload = json || {};
11
+ }
12
+ /**
13
+ * @returns An immutable copy of the json payload
14
+ */
15
+ json() {
16
+ return Object.assign({}, this.payload);
11
17
  }
12
18
  /**
13
19
  * Gets the name of the Template.
@@ -15,7 +21,7 @@ export class Template {
15
21
  * @returns The Template's name
16
22
  */
17
23
  getName() {
18
- return this.wrapped.name;
24
+ return this.payload.name;
19
25
  }
20
26
  /**
21
27
  * Gets the description of the Template.
@@ -23,7 +29,7 @@ export class Template {
23
29
  * @returns The Template's description
24
30
  */
25
31
  getDescription() {
26
- return this.wrapped.description;
32
+ return this.payload.description;
27
33
  }
28
34
  /**
29
35
  * Gets the url of the image of the Template.
@@ -31,7 +37,7 @@ export class Template {
31
37
  * @returns The url of the Template's image
32
38
  */
33
39
  getImageUrl() {
34
- return this.wrapped.imageUrl;
40
+ return this.payload.imageUrl;
35
41
  }
36
42
  /**
37
43
  * Gets the category of the Template.
@@ -39,7 +45,7 @@ export class Template {
39
45
  * @returns The Template's category. Example: "PERSONAL", "BUSINESS", etc
40
46
  */
41
47
  getCategory() {
42
- return this.wrapped.category;
48
+ return this.payload.category;
43
49
  }
44
50
  /**
45
51
  * Gets the times the Template has been used.
@@ -47,7 +53,7 @@ export class Template {
47
53
  * @returns The number of times the Template has been used
48
54
  */
49
55
  getTimesUsed() {
50
- return this.wrapped.timesUsed || 0;
56
+ return this.payload.timesUsed || 0;
51
57
  }
52
58
  /**
53
59
  * Gets the bookId of the [[Book]] associated with the Template.
@@ -55,7 +61,7 @@ export class Template {
55
61
  * @returns The bookId of the Book associated with the Template
56
62
  */
57
63
  getBookId() {
58
- return this.wrapped.bookId;
64
+ return this.payload.bookId;
59
65
  }
60
66
  /**
61
67
  * Gets the link of the [[Book]] associated with the Template.
@@ -63,7 +69,7 @@ export class Template {
63
69
  * @returns The link of the Book associated with the Template
64
70
  */
65
71
  getBookLink() {
66
- return this.wrapped.bookLink;
72
+ return this.payload.bookLink;
67
73
  }
68
74
  /**
69
75
  * Gets the link of the Google Sheets spreadsheet associated with the Template.
@@ -71,15 +77,7 @@ export class Template {
71
77
  * @returns The link of the Google Sheets spreadsheet associated with the Template
72
78
  */
73
79
  getSheetsLink() {
74
- return this.wrapped.sheetsLink;
75
- }
76
- /**
77
- * Gets the wrapped plain json object of the Template.
78
- *
79
- * @returns The Template wrapped plain json object
80
- */
81
- json() {
82
- return this.wrapped;
80
+ return this.payload.sheetsLink;
83
81
  }
84
82
  }
85
83
  //# sourceMappingURL=Template.js.map