bkper-js 1.0.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.
@@ -0,0 +1,717 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.Book = void 0;
36
+ const AccountService = __importStar(require("../service/account-service"));
37
+ const GroupService = __importStar(require("../service/group-service"));
38
+ const BookService = __importStar(require("../service/book-service"));
39
+ const FileService = __importStar(require("../service/file-service"));
40
+ const TransactionService = __importStar(require("../service/transaction-service"));
41
+ const IntegrationService = __importStar(require("../service/integration-service"));
42
+ const Utils = __importStar(require("../utils"));
43
+ const utils_1 = require("../utils");
44
+ const Account_1 = require("./Account");
45
+ const Collection_1 = require("./Collection");
46
+ const File_1 = require("./File");
47
+ const Group_1 = require("./Group");
48
+ const Transaction_1 = require("./Transaction");
49
+ const TransactionIterator_1 = require("./TransactionIterator");
50
+ const Integration_1 = require("./Integration");
51
+ /**
52
+ *
53
+ * A Book represents [General Ledger](https://en.wikipedia.org/wiki/General_ledger) for a company or business, but can also represent a [Ledger](https://en.wikipedia.org/wiki/Ledger) for a project or department
54
+ *
55
+ * It contains all [[Accounts]] where [[Transactions]] are recorded/posted;
56
+ *
57
+ * @public
58
+ */
59
+ class Book {
60
+ constructor(json) {
61
+ this.wrapped = json;
62
+ }
63
+ /**
64
+ * @returns The wrapped plain json object
65
+ */
66
+ json() {
67
+ return this.wrapped;
68
+ }
69
+ /**
70
+ * Same as bookId param
71
+ */
72
+ getId() {
73
+ return this.wrapped.id;
74
+ }
75
+ /**
76
+ * @returns The name of this Book
77
+ */
78
+ getName() {
79
+ return this.wrapped.name;
80
+ }
81
+ /**
82
+ *
83
+ * Sets the name of the Book.
84
+ *
85
+ * @returns This Book, for chainning.
86
+ */
87
+ setName(name) {
88
+ this.wrapped.name = name;
89
+ return this;
90
+ }
91
+ /**
92
+ * @returns The number of fraction digits supported by this Book. Same as getDecimalPlaces
93
+ */
94
+ getFractionDigits() {
95
+ return this.wrapped.fractionDigits;
96
+ }
97
+ /**
98
+ * @returns The number of decimal places supported by this Book. Same as getFractionDigits
99
+ */
100
+ getDecimalPlaces() {
101
+ return this.getFractionDigits();
102
+ }
103
+ /**
104
+ *
105
+ * Sets the number of fraction digits (decimal places) supported by this Book
106
+ *
107
+ * @returns This Book, for chainning.
108
+ */
109
+ setFractionDigits(fractionDigits) {
110
+ this.wrapped.fractionDigits = fractionDigits;
111
+ return this;
112
+ }
113
+ /**
114
+ * @returns The period slice for balances visualization
115
+ */
116
+ getPeriod() {
117
+ return this.wrapped.period;
118
+ }
119
+ /**
120
+ * Sets the period slice for balances visualization
121
+ *
122
+ * @returns This Book, for chainning.
123
+ */
124
+ setPeriod(period) {
125
+ this.wrapped.period = period;
126
+ return this;
127
+ }
128
+ /**
129
+ * @returns The start month when YEAR period set
130
+ */
131
+ getPeriodStartMonth() {
132
+ return this.wrapped.periodStartMonth;
133
+ }
134
+ /**
135
+ * Sets the start month when YEAR period set
136
+ *
137
+ * @returns This Book, for chainning.
138
+ */
139
+ setPeriodStartMonth(month) {
140
+ this.wrapped.periodStartMonth = month;
141
+ return this;
142
+ }
143
+ /**
144
+ * @returns The transactions pagination page size
145
+ */
146
+ getPageSize() {
147
+ return this.wrapped.pageSize;
148
+ }
149
+ /**
150
+ * Sets the transactions pagination page size
151
+ *
152
+ * @returns This Book, for chainning.
153
+ */
154
+ setPageSize(pageSize) {
155
+ this.wrapped.pageSize = pageSize;
156
+ return this;
157
+ }
158
+ /**
159
+ * @returns The name of the owner of the Book
160
+ */
161
+ getOwnerName() {
162
+ return this.wrapped.ownerName;
163
+ }
164
+ /**
165
+ * @returns The permission for the current user
166
+ */
167
+ getPermission() {
168
+ return this.wrapped.permission;
169
+ }
170
+ /**
171
+ * @returns The collection of this book
172
+ */
173
+ getCollection() {
174
+ if (this.wrapped.collection != null && this.collection == null) {
175
+ this.collection = new Collection_1.Collection(this.wrapped.collection);
176
+ }
177
+ return this.collection;
178
+ }
179
+ /**
180
+ * @returns The date pattern of the Book. Current: dd/MM/yyyy | MM/dd/yyyy | yyyy/MM/dd
181
+ */
182
+ getDatePattern() {
183
+ return this.wrapped.datePattern;
184
+ }
185
+ /**
186
+ *
187
+ * Sets the date pattern of the Book. Current: dd/MM/yyyy | MM/dd/yyyy | yyyy/MM/dd
188
+ *
189
+ * @returns This Book, for chainning.
190
+ */
191
+ setDatePattern(datePattern) {
192
+ this.wrapped.datePattern = datePattern;
193
+ return this;
194
+ }
195
+ /**
196
+ * @returns The lock date of the Book in ISO format yyyy-MM-dd
197
+ */
198
+ getLockDate() {
199
+ return this.wrapped.lockDate;
200
+ }
201
+ /**
202
+ *
203
+ * Sets the lock date of the Book in ISO format yyyy-MM-dd.
204
+ *
205
+ * @returns This Book, for chainning.
206
+ */
207
+ setLockDate(lockDate) {
208
+ if (lockDate == null) {
209
+ lockDate = "1900-00-00";
210
+ }
211
+ this.wrapped.lockDate = lockDate;
212
+ return this;
213
+ }
214
+ /**
215
+ * @returns The closing date of the Book in ISO format yyyy-MM-dd
216
+ */
217
+ getClosingDate() {
218
+ return this.wrapped.closingDate;
219
+ }
220
+ /**
221
+ *
222
+ * Sets the closing date of the Book in ISO format yyyy-MM-dd.
223
+ *
224
+ * @returns This Book, for chainning.
225
+ */
226
+ setClosingDate(closingDate) {
227
+ if (closingDate == null) {
228
+ closingDate = "1900-00-00";
229
+ }
230
+ this.wrapped.closingDate = closingDate;
231
+ return this;
232
+ }
233
+ /**
234
+ * @returns The decimal separator of the Book
235
+ */
236
+ getDecimalSeparator() {
237
+ return this.wrapped.decimalSeparator;
238
+ }
239
+ /**
240
+ *
241
+ * Sets the decimal separator of the Book
242
+ *
243
+ * @returns This Book, for chainning.
244
+ */
245
+ setDecimalSeparator(decimalSeparator) {
246
+ this.wrapped.decimalSeparator = decimalSeparator;
247
+ return this;
248
+ }
249
+ /**
250
+ * @returns The time zone of the Book
251
+ */
252
+ getTimeZone() {
253
+ return this.wrapped.timeZone;
254
+ }
255
+ /**
256
+ *
257
+ * Sets the time zone of the Book
258
+ *
259
+ * @returns This Book, for chainning.
260
+ */
261
+ setTimeZone(timeZone) {
262
+ this.wrapped.timeZone = timeZone;
263
+ return this;
264
+ }
265
+ /**
266
+ * @returns The time zone offset of the book, in minutes
267
+ */
268
+ getTimeZoneOffset() {
269
+ return this.wrapped.timeZoneOffset;
270
+ }
271
+ /**
272
+ * @returns The last update date of the book, in in milliseconds
273
+ */
274
+ getLastUpdateMs() {
275
+ return +this.wrapped.lastUpdateMs;
276
+ }
277
+ /**
278
+ * Gets the custom properties stored in this Book
279
+ */
280
+ getProperties() {
281
+ return this.wrapped.properties != null ? Object.assign({}, this.wrapped.properties) : {};
282
+ }
283
+ /**
284
+ * Gets the property value for given keys. First property found will be retrieved
285
+ *
286
+ * @param keys - The property key
287
+ */
288
+ getProperty(...keys) {
289
+ for (let index = 0; index < keys.length; index++) {
290
+ const key = keys[index];
291
+ let value = this.wrapped.properties != null ? this.wrapped.properties[key] : null;
292
+ if (value != null && value.trim() != '') {
293
+ return value;
294
+ }
295
+ }
296
+ return null;
297
+ }
298
+ /**
299
+ * Sets the custom properties of the Book
300
+ *
301
+ * @param properties - Object with key/value pair properties
302
+ *
303
+ * @returns This Book, for chainning.
304
+ */
305
+ setProperties(properties) {
306
+ this.wrapped.properties = Object.assign({}, properties);
307
+ return this;
308
+ }
309
+ /**
310
+ * Sets a custom property in the Book.
311
+ *
312
+ * @param key - The property key
313
+ * @param value - The property value
314
+ *
315
+ * @returns This Book, for chainning.
316
+ */
317
+ setProperty(key, value) {
318
+ if (key == null || key.trim() == '') {
319
+ return this;
320
+ }
321
+ if (this.wrapped.properties == null) {
322
+ this.wrapped.properties = {};
323
+ }
324
+ this.wrapped.properties[key] = value;
325
+ return this;
326
+ }
327
+ /**
328
+ * Formats a date according to date pattern of the Book.
329
+ *
330
+ * @param date - The date to format as string.
331
+ * @param timeZone - The output timezone of the result. Default to script's timeZone
332
+ *
333
+ * @returns The date formated
334
+ */
335
+ formatDate(date, timeZone) {
336
+ if (timeZone == null || timeZone.trim() == "") {
337
+ timeZone = this.getTimeZone();
338
+ }
339
+ return Utils.formatDate(date, this.getDatePattern(), timeZone);
340
+ }
341
+ /**
342
+ * Parse a date string according to date pattern and timezone of the Book.
343
+ *
344
+ * Also parse ISO yyyy-mm-dd format.
345
+ */
346
+ parseDate(date) {
347
+ return Utils.parseDate(date, this.getDatePattern(), this.getTimeZone());
348
+ }
349
+ /**
350
+ * Formats a value according to [[DecimalSeparator]] and fraction digits of the Book.
351
+ *
352
+ * @param value - The value to be formatted.
353
+ *
354
+ * @returns The value formated
355
+ */
356
+ formatValue(value) {
357
+ if (!value) {
358
+ return '';
359
+ }
360
+ return Utils.formatValue(value, this.getDecimalSeparator(), this.getFractionDigits());
361
+ }
362
+ /**
363
+ * Parse a value string according to [[DecimalSeparator]] and fraction digits of the Book.
364
+ */
365
+ parseValue(value) {
366
+ return Utils.parseValue(value, this.getDecimalSeparator());
367
+ }
368
+ /**
369
+ * Rounds a value according to the number of fraction digits of the Book
370
+ *
371
+ * @param value - The value to be rounded
372
+ *
373
+ * @returns The value rounded
374
+ */
375
+ round(value) {
376
+ return Utils.round(value, this.getFractionDigits());
377
+ }
378
+ /**
379
+ * Create [[Transactions]] on the Book, in batch.
380
+ */
381
+ batchCreateTransactions(transactions) {
382
+ return __awaiter(this, void 0, void 0, function* () {
383
+ let transactionPayloads = [];
384
+ transactions.forEach(tx => transactionPayloads.push(tx.wrapped));
385
+ transactionPayloads = yield TransactionService.createTransactionsBatch(this.getId(), transactionPayloads);
386
+ transactions = Utils.wrapObjects(new Transaction_1.Transaction(), transactionPayloads);
387
+ this.configureTransactions_(transactions);
388
+ return transactions;
389
+ });
390
+ }
391
+ /**
392
+ * Trash [[Transactions]] on the Book, in batch.
393
+ */
394
+ batchTrashTransactions(transactions) {
395
+ return __awaiter(this, void 0, void 0, function* () {
396
+ let transactionPayloads = [];
397
+ transactions.forEach(tx => transactionPayloads.push(tx.wrapped));
398
+ yield TransactionService.trashTransactionsBatch(this.getId(), transactionPayloads);
399
+ });
400
+ }
401
+ /**
402
+ * Trigger [Balances Audit](https://help.bkper.com/en/articles/4412038-balances-audit) async process.
403
+ */
404
+ audit() {
405
+ BookService.audit(this.getId());
406
+ }
407
+ /**
408
+ * Gets the existing [[Integrations]] in the Book.
409
+ *
410
+ * @returns The existing Integration objects
411
+ */
412
+ getIntegrations() {
413
+ return __awaiter(this, void 0, void 0, function* () {
414
+ const integrationsPlain = yield IntegrationService.listIntegrations(this.getId());
415
+ const integrations = integrationsPlain.map(i => new Integration_1.Integration(i));
416
+ return integrations;
417
+ });
418
+ }
419
+ /**
420
+ * Creates a new [[Integration]] in the Book.
421
+ *
422
+ * @param integration - The Integration object or wrapped plain json
423
+ *
424
+ * @returns The created Integration object
425
+ */
426
+ createIntegration(integration) {
427
+ return __awaiter(this, void 0, void 0, function* () {
428
+ if (integration instanceof Integration_1.Integration) {
429
+ integration = yield IntegrationService.createIntegration(this.getId(), integration.json());
430
+ }
431
+ else {
432
+ integration = yield IntegrationService.createIntegration(this.getId(), integration);
433
+ }
434
+ return new Integration_1.Integration(integration);
435
+ });
436
+ }
437
+ /**
438
+ * Updates an existing [[Integration]] in the Book.
439
+ *
440
+ * @param integration - The Integration wrapped plain json
441
+ *
442
+ * @returns The updated Integration object
443
+ */
444
+ updateIntegration(integration) {
445
+ return __awaiter(this, void 0, void 0, function* () {
446
+ if (integration instanceof Integration_1.Integration) {
447
+ integration = yield IntegrationService.updateIntegration(this.getId(), integration.json());
448
+ }
449
+ else {
450
+ integration = yield IntegrationService.updateIntegration(this.getId(), integration);
451
+ }
452
+ return new Integration_1.Integration(integration);
453
+ });
454
+ }
455
+ /**
456
+ * Resumes a transaction iteration using a continuation token from a previous iterator.
457
+ *
458
+ * @param continuationToken - continuation token from a previous transaction iterator
459
+ *
460
+ * @returns a collection of transactions that remained in a previous iterator when the continuation token was generated
461
+ */
462
+ continueTransactionIterator(query, continuationToken) {
463
+ var transactionIterator = new TransactionIterator_1.TransactionIterator(this, query);
464
+ transactionIterator.setContinuationToken(continuationToken);
465
+ return transactionIterator;
466
+ }
467
+ configureTransactions_(transactions) {
468
+ for (var i = 0; i < transactions.length; i++) {
469
+ this.configureTransaction_(transactions[i]);
470
+ }
471
+ return transactions;
472
+ }
473
+ /** @internal */
474
+ configureTransaction_(transaction) {
475
+ transaction.book = this;
476
+ return transaction;
477
+ }
478
+ /**
479
+ * Instantiate a new [[Transaction]]
480
+ *
481
+ * Example:
482
+ *
483
+ * ```js
484
+ * var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
485
+ *
486
+ * book.newTransaction()
487
+ * .setDate('2013-01-25')
488
+ * .setDescription("Filling tank of my truck")
489
+ * .from('Credit Card')
490
+ * .to('Gas')
491
+ * .setAmount(126.50)
492
+ * .create();
493
+ *
494
+ * ```
495
+ *
496
+ */
497
+ newTransaction() {
498
+ let transaction = Utils.wrapObject(new Transaction_1.Transaction(), {});
499
+ this.configureTransaction_(transaction);
500
+ return transaction;
501
+ }
502
+ /**
503
+ * Instantiate a new [[Account]]
504
+ *
505
+ * Example:
506
+ * ```js
507
+ * var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
508
+ *
509
+ * book.newAccount()
510
+ * .setName('Some New Account')
511
+ * .setType('INCOMING')
512
+ * .addGroup('Revenue').addGroup('Salary')
513
+ * .setProperties({prop_a: 'A', prop_b: 'B'})
514
+ * .create();
515
+ * ```
516
+ */
517
+ newAccount() {
518
+ let account = Utils.wrapObject(new Account_1.Account(), {});
519
+ account.setArchived(false);
520
+ account.book = this;
521
+ return account;
522
+ }
523
+ /**
524
+ * Instantiate a new [[Group]]
525
+ *
526
+ * Example:
527
+ * ```js
528
+ * var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
529
+ *
530
+ * book.newGroup()
531
+ * .setName('Some New Group')
532
+ * .setProperty('key', 'value')
533
+ * .create();
534
+ * ```
535
+ */
536
+ newGroup() {
537
+ let group = Utils.wrapObject(new Group_1.Group(), {});
538
+ group.book = this;
539
+ return group;
540
+ }
541
+ /**
542
+ * Gets an [[Account]] object
543
+ *
544
+ * @param idOrName - The id or name of the Account
545
+ *
546
+ * @returns The matching Account object
547
+ */
548
+ getAccount(idOrName) {
549
+ return __awaiter(this, void 0, void 0, function* () {
550
+ if (idOrName == null) {
551
+ return null;
552
+ }
553
+ idOrName = idOrName + '';
554
+ const accountPlain = yield AccountService.getAccount(this.getId(), idOrName);
555
+ if (!accountPlain) {
556
+ return null;
557
+ }
558
+ const account = Utils.wrapObject(new Account_1.Account(), accountPlain);
559
+ account.book = this;
560
+ return account;
561
+ });
562
+ }
563
+ /** @internal */
564
+ updateGroupCache(group) {
565
+ group.book = this;
566
+ if (this.idGroupMap) {
567
+ this.idGroupMap.set(group.getId(), group);
568
+ this.nameGroupMap.set((0, utils_1.normalizeName)(group.getName()), group);
569
+ }
570
+ }
571
+ removeGroupCache(group) {
572
+ if (this.idGroupMap) {
573
+ this.idGroupMap.delete(group.getId());
574
+ this.nameGroupMap.delete((0, utils_1.normalizeName)(group.getName()));
575
+ }
576
+ }
577
+ /**
578
+ * Gets a [[Group]] object
579
+ *
580
+ * @param idOrName - The id or name of the Group
581
+ *
582
+ * @returns The matching Group object
583
+ */
584
+ getGroup(idOrName) {
585
+ return __awaiter(this, void 0, void 0, function* () {
586
+ if (idOrName == null) {
587
+ return null;
588
+ }
589
+ idOrName = idOrName + '';
590
+ if (this.idGroupMap) {
591
+ let group = this.idGroupMap.get(idOrName);
592
+ if (!group) {
593
+ group = this.nameGroupMap.get((0, utils_1.normalizeName)(idOrName));
594
+ }
595
+ if (group) {
596
+ return group;
597
+ }
598
+ }
599
+ const groupPlain = yield GroupService.getGroup(this.getId(), idOrName);
600
+ if (!groupPlain) {
601
+ return null;
602
+ }
603
+ let group = Utils.wrapObject(new Group_1.Group(), groupPlain);
604
+ this.updateGroupCache(group);
605
+ return group;
606
+ });
607
+ }
608
+ /**
609
+ * Gets all [[Groups]] of this Book
610
+ */
611
+ getGroups() {
612
+ return __awaiter(this, void 0, void 0, function* () {
613
+ if (this.idGroupMap) {
614
+ return Array.from(this.idGroupMap.values());
615
+ }
616
+ let groups = yield GroupService.getGroups(this.getId());
617
+ let groupsObj = Utils.wrapObjects(new Group_1.Group(), groups);
618
+ this.idGroupMap = new Map();
619
+ this.nameGroupMap = new Map();
620
+ for (var i = 0; i < groupsObj.length; i++) {
621
+ var group = groupsObj[i];
622
+ this.updateGroupCache(group);
623
+ }
624
+ return groupsObj;
625
+ });
626
+ }
627
+ /**
628
+ * Get the [[Groups]] of a given account.
629
+ */
630
+ getGroupsByAccount(accountIdOrName) {
631
+ return __awaiter(this, void 0, void 0, function* () {
632
+ let groups = yield GroupService.getGroupsByAccountId(this.getId(), accountIdOrName);
633
+ let groupsObj = Utils.wrapObjects(new Group_1.Group(), groups);
634
+ for (const group of groupsObj) {
635
+ group.book = this;
636
+ }
637
+ return groupsObj;
638
+ });
639
+ }
640
+ /**
641
+ * Get Book transactions based on a query.
642
+ *
643
+ * See [Query Guide](https://help.bkper.com/en/articles/2569178-search-query-guide) to learn more
644
+ *
645
+ * @param query - The query string.
646
+ *
647
+ * @returns The Transactions result as an iterator.
648
+ *
649
+ * Example:
650
+ *
651
+ * ```js
652
+ * var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
653
+ *
654
+ * var transactions = book.getTransactions("account:CreditCard after:28/01/2013 before:29/01/2013");
655
+ *
656
+ * while (transactions.hasNext()) {
657
+ * var transaction = transactions.next();
658
+ * Logger.log(transaction.getDescription());
659
+ * }
660
+ * ```
661
+ */
662
+ getTransactions(query) {
663
+ return new TransactionIterator_1.TransactionIterator(this, query);
664
+ }
665
+ /**
666
+ * Retrieve a transaction by id
667
+ */
668
+ getTransaction(id) {
669
+ return __awaiter(this, void 0, void 0, function* () {
670
+ let wrapped = yield TransactionService.getTransaction(this.getId(), id);
671
+ if (!wrapped) {
672
+ return null;
673
+ }
674
+ let transaction = Utils.wrapObject(new Transaction_1.Transaction(), wrapped);
675
+ this.configureTransaction_(transaction);
676
+ return transaction;
677
+ });
678
+ }
679
+ /**
680
+ * Instantiate a new [[BkperFile]]
681
+ *
682
+ * Example:
683
+ * ```js
684
+ * var book = BkperApp.getBook("agtzfmJrcGVyLWhyZHITCxIGTGVkZ2VyGICAgIDggqALDA");
685
+ *
686
+ * book.newFile()
687
+ * .setBlob(UrlFetchApp.fetch('https://bkper.com/images/index/integrations4.png').getBlob())
688
+ * .create();
689
+ * ```
690
+ */
691
+ newFile() {
692
+ let file = Utils.wrapObject(new File_1.File(), {});
693
+ file.book = this;
694
+ return file;
695
+ }
696
+ /**
697
+ * Retrieve a file by id
698
+ */
699
+ getFile(id) {
700
+ return __awaiter(this, void 0, void 0, function* () {
701
+ let wrapped = yield FileService.getFile(this.getId(), id);
702
+ let file = Utils.wrapObject(new File_1.File(), wrapped);
703
+ return file;
704
+ });
705
+ }
706
+ /**
707
+ * Perform update Book, applying pending changes.
708
+ */
709
+ update() {
710
+ return __awaiter(this, void 0, void 0, function* () {
711
+ this.wrapped = yield BookService.updateBook(this.getId(), this.wrapped);
712
+ return this;
713
+ });
714
+ }
715
+ }
716
+ exports.Book = Book;
717
+ //# sourceMappingURL=Book.js.map